From 157d20d191e16c6d0937bb47386270e38f5feaf4 Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Thu, 30 May 2024 19:06:35 +0200 Subject: [PATCH] Applied formatting patch 1 --- apps/decoder.c | 165 +- apps/encoder.c | 6 +- apps/renderer.c | 88 +- lib_com/ACcontextMapping_fx.c | 33 +- lib_com/ari_fx.c | 14 +- lib_com/ari_hm.c | 121 +- lib_com/ari_hm_fx.c | 205 +- lib_com/arith_coder.c | 4 +- lib_com/arith_coder_fx.c | 346 +- lib_com/basop32.c | 887 +- lib_com/basop32.h | 100 +- lib_com/basop_tcx_utils.c | 16 +- lib_com/basop_util.c | 2808 ++-- lib_com/basop_util.h | 282 +- lib_com/bitalloc_fx.c | 773 +- lib_com/bitallocsum_fx.c | 60 +- lib_com/bits_alloc.c | 20 +- lib_com/bits_alloc_fx.c | 722 +- lib_com/bitstream.c | 883 +- lib_com/bitstream_fx.c | 4610 +++--- lib_com/cb_shape_fx.c | 91 +- lib_com/cldfb.c | 605 +- lib_com/cldfb_evs.c | 1552 +- lib_com/cng_exc_fx.c | 1205 +- lib_com/codec_tcx_common.c | 684 +- lib_com/common_api_types.h | 15 +- lib_com/complex_basop.c | 860 +- lib_com/complex_basop.h | 93 +- lib_com/control.c | 466 +- lib_com/control.h | 199 +- lib_com/core_com_config.c | 2297 +-- lib_com/count.c | 1698 ++- lib_com/count.h | 598 +- lib_com/deemph.c | 152 +- lib_com/delay_comp.c | 128 +- lib_com/dlpc_bfi_fx.c | 40 +- lib_com/edct_fx.c | 433 +- lib_com/enh1632.c | 459 +- lib_com/enh1632.h | 234 +- lib_com/enh32.c | 284 +- lib_com/enh32.h | 32 +- lib_com/enh64.c | 1112 +- lib_com/enh64.h | 110 +- lib_com/enhUL32.c | 188 +- lib_com/enhUL32.h | 54 +- lib_com/enhancer_fx.c | 656 +- lib_com/enr_1_az.c | 152 +- lib_com/env_adj.c | 261 +- lib_com/env_stab.c | 318 +- lib_com/env_stab_trans.c | 112 +- lib_com/est_tilt_fx.c | 337 +- lib_com/fd_cng_com.c | 98 +- lib_com/fd_cng_com_fx.c | 1374 +- lib_com/fft.c | 2 +- lib_com/fft_cldfb_fx.c | 1223 +- lib_com/fft_evs.c | 3383 +++-- lib_com/fft_fx.c | 704 +- lib_com/fft_fx_evs.c | 3771 ++--- lib_com/fft_rel.c | 403 +- lib_com/fft_rel_fx.c | 370 +- lib_com/fill_spectrum.c | 505 +- lib_com/findpulse.c | 164 +- lib_com/fine_gain_bits_fx.c | 60 +- lib_com/float_to_fix_ops.c | 136 +- lib_com/frame_ener.c | 274 +- lib_com/gain_inov_fx.c | 37 +- lib_com/get_gain.c | 139 +- lib_com/gs_bitallocation_fx.c | 570 +- lib_com/gs_bitallocation_ivas_fx.c | 648 +- lib_com/gs_gains_fx.c | 604 +- lib_com/gs_inact_switching_fx.c | 189 +- lib_com/gs_noisefill_fx.c | 1104 +- lib_com/gs_preech.c | 192 +- lib_com/guided_plc_util.c | 2 +- lib_com/guided_plc_util_fx.c | 177 +- lib_com/hp50.c | 582 +- lib_com/hq2_bit_alloc.c | 4 +- lib_com/hq2_bit_alloc_fx.c | 1757 ++- lib_com/hq2_core_com_fx.c | 1323 +- lib_com/hq2_noise_inject.c | 2 - lib_com/hq2_noise_inject_fx.c | 1229 +- lib_com/hq_bit_allocation_fx.c | 214 +- lib_com/hq_conf.c | 410 +- lib_com/hq_conf_fx.c | 112 +- lib_com/hq_tools_fx.c | 4302 +++--- lib_com/hvq_pvq_bitalloc_fx.c | 120 +- lib_com/ifft_rel.c | 728 +- lib_com/igf_base.c | 6 +- lib_com/igf_base_fx.c | 1864 +-- lib_com/index_pvq_opt_fx.c | 925 +- lib_com/int_lsp.c | 216 +- lib_com/interleave_spectrum.c | 307 +- lib_com/interpol.c | 110 +- lib_com/isf_dec_amr_wb_fx.c | 564 +- lib_com/ivas_agc_com.c | 1 - lib_com/ivas_agc_com_fx.c | 18 +- lib_com/ivas_dirac_com.c | 275 +- lib_com/ivas_entropy_coder_common.c | 154 +- lib_com/ivas_fb_mixer.c | 194 +- lib_com/ivas_filters.c | 121 +- lib_com/ivas_ism_com.c | 184 +- lib_com/ivas_lfe_com.c | 15 +- lib_com/ivas_masa_com.c | 71 +- lib_com/ivas_mc_com.c | 32 +- lib_com/ivas_mc_param_com.c | 48 +- lib_com/ivas_mct_com.c | 8 +- lib_com/ivas_mdct_imdct_fx.c | 106 +- lib_com/ivas_mdft_imdft.c | 36 +- lib_com/ivas_omasa_com.c | 32 +- lib_com/ivas_pca_tools.c | 297 +- lib_com/ivas_prot_fx.h | 826 +- lib_com/ivas_qmetadata_com.c | 22 +- lib_com/ivas_qspherical_com.c | 33 +- lib_com/ivas_rom_com.c | 2498 ++-- lib_com/ivas_rom_com.h | 6 +- lib_com/ivas_rom_com_fx.c | 714 +- lib_com/ivas_rom_com_fx.h | 18 +- lib_com/ivas_sba_config.c | 20 +- lib_com/ivas_sns_com_fx.c | 16 +- lib_com/ivas_spar_com.c | 1883 +-- lib_com/ivas_spar_com_quant_util.c | 139 +- lib_com/ivas_stat_com.h | 83 +- lib_com/ivas_stereo_mdct_bands_com.c | 2 +- lib_com/ivas_stereo_mdct_stereo_com.c | 4 +- lib_com/ivas_stereo_psychlpc_com.c | 12 +- lib_com/ivas_stereo_td_bit_alloc.c | 93 +- lib_com/ivas_tools.c | 186 +- lib_com/ivas_transient_det.c | 189 +- lib_com/lag_wind.c | 234 +- lib_com/lerp.c | 488 +- lib_com/limit_t0_fx.c | 156 +- lib_com/log2.c | 302 +- lib_com/log2.h | 32 +- lib_com/logqnorm_fx.c | 338 +- lib_com/longarith.c | 29 +- lib_com/low_rate_band_att_fx.c | 161 +- lib_com/lpc_tools.c | 51 +- lib_com/lpc_tools_fx.c | 1192 +- lib_com/lsf_dec_bfi_fx.c | 247 +- lib_com/lsf_msvq_ma_fx.c | 79 +- lib_com/lsf_tools.c | 25 +- lib_com/lsf_tools_fx.c | 6002 ++++---- lib_com/lsp_conv_poly_fx.c | 2 +- lib_com/math_32.h | 6 +- lib_com/math_op.c | 258 +- lib_com/math_op.h | 60 +- lib_com/modif_fs.c | 24 +- lib_com/modif_fs_fx.c | 1027 +- lib_com/move.h | 7 +- lib_com/mslvq_com.c | 8 +- lib_com/mslvq_com_fx.c | 1572 +- lib_com/nelp_fx.c | 324 +- lib_com/oper_32b.c | 141 +- lib_com/oper_32b.h | 22 +- lib_com/options.h | 2 +- lib_com/parameter_bitmaping_fx.c | 4 +- lib_com/phase_dispersion_fx.c | 110 +- lib_com/ppp_fx.c | 181 +- lib_com/pred_lt4_fx.c | 109 +- lib_com/preemph.c | 2 +- lib_com/preemph_fx.c | 106 +- lib_com/prot.h | 337 +- lib_com/prot_fx1.h | 297 +- lib_com/prot_fx2.h | 13054 ++++++++--------- lib_com/pvq_com.c | 8 +- lib_com/pvq_com_fx.c | 656 +- lib_com/range_com_fx.c | 45 +- lib_com/re8_ppv_fx.c | 96 +- lib_com/re8_util_fx.c | 200 +- lib_com/recovernorm_fx.c | 57 +- lib_com/reordvct_fx.c | 84 +- lib_com/residu_fx.c | 152 +- lib_com/rom_basic_math.c | 88 +- lib_com/rom_basic_math.h | 8 +- lib_com/rom_basop_util.c | 2145 ++- lib_com/rom_basop_util.h | 6 +- lib_com/rom_com.c | 7709 +++++++--- lib_com/rom_com.h | 385 +- lib_com/rom_com_fx.c | 6916 ++++++++- lib_com/rom_com_fx.h | 8 +- lib_com/scale_mem_fx.c | 611 +- lib_com/stab_est_fx.c | 150 +- lib_com/stat_com.h | 245 +- lib_com/stat_noise_uv_mod_fx.c | 318 +- lib_com/stl.h | 2 +- lib_com/swb_bwe_com_fx.c | 5422 +++---- lib_com/swb_bwe_com_hr_fx.c | 144 +- lib_com/swb_bwe_com_lr_fx.c | 6192 ++++---- lib_com/swb_tbe_com.c | 160 +- lib_com/swb_tbe_com_fx.c | 4179 +++--- lib_com/syn_12k8_fx.c | 32 +- lib_com/syn_filt_fx.c | 401 +- lib_com/tcq_position_arith.c | 2 +- lib_com/tcq_position_arith_fx.c | 1791 ++- lib_com/tcx_ltp.c | 4 +- lib_com/tcx_ltp_fx.c | 808 +- lib_com/tcx_mdct_fx.c | 174 +- lib_com/tcx_mdct_window.c | 525 +- lib_com/tcx_utils_fx.c | 1441 +- lib_com/tec_com.c | 976 +- lib_com/tns_base.c | 783 +- lib_com/tns_base_flt.c | 148 +- lib_com/tools.c | 100 +- lib_com/tools_fx.c | 2213 ++- lib_com/trans_direct_fx.c | 146 +- lib_com/trans_inv_fx.c | 689 +- lib_com/typedef.h | 12 +- lib_com/typedefs.h | 71 +- lib_com/vlpc_2st_com_fx.c | 30 +- lib_com/weight_a_fx.c | 107 +- lib_com/weight_fx.c | 206 +- lib_com/wi_fx.c | 3530 +++-- lib_com/window_fx.c | 74 +- lib_com/window_ola_fx.c | 738 +- lib_com/wtda.c | 289 +- lib_com/wtda_fx.c | 403 +- lib_dec/ACcontextMapping_dec.c | 2 +- lib_dec/ACcontextMapping_dec_fx.c | 253 +- lib_dec/FEC_HQ_core.c | 11 +- lib_dec/FEC_HQ_core_fx.c | 2319 ++- lib_dec/FEC_HQ_phase_ecu.c | 2 +- lib_dec/FEC_HQ_phase_ecu_fx.c | 2506 ++-- lib_dec/FEC_adapt_codebook.c | 2 +- lib_dec/FEC_adapt_codebook_fx.c | 357 +- lib_dec/FEC_clas_estim.c | 2 +- lib_dec/FEC_clas_estim_fx.c | 691 +- lib_dec/FEC_fx.c | 488 +- lib_dec/FEC_lsf_estim_fx.c | 30 +- lib_dec/FEC_pitch_estim_fx.c | 76 +- lib_dec/FEC_scale_syn.c | 2 +- lib_dec/FEC_scale_syn_fx.c | 450 +- lib_dec/LD_music_post_filter.c | 62 +- lib_dec/LD_music_post_filter_fx.c | 667 +- lib_dec/TonalComponentDetection.c | 10 +- lib_dec/TonalComponentDetection_fx.c | 661 +- lib_dec/acelp_core_dec.c | 4 +- lib_dec/acelp_core_dec_fx.c | 1048 +- lib_dec/acelp_core_dec_ivas_fx.c | 1991 +-- lib_dec/acelp_core_switch_dec.c | 2 +- lib_dec/acelp_core_switch_dec_fx.c | 633 +- lib_dec/amr_wb_dec.c | 2 +- lib_dec/amr_wb_dec_fx.c | 487 +- lib_dec/ari_dec.c | 19 +- lib_dec/ari_dec_fx.c | 348 +- lib_dec/ari_hm_dec.c | 88 +- lib_dec/arith_coder_dec.c | 52 +- lib_dec/arith_coder_dec_fx.c | 137 +- lib_dec/avq_dec.c | 4 +- lib_dec/avq_dec_fx.c | 75 +- lib_dec/bass_psfilter.c | 12 +- lib_dec/bass_psfilter_fx.c | 729 +- lib_dec/cng_dec.c | 128 +- lib_dec/cng_dec_fx.c | 1001 +- lib_dec/core_dec_init.c | 1224 +- lib_dec/core_dec_init_fx.c | 627 +- lib_dec/core_dec_reconf.c | 4 +- lib_dec/core_dec_reconf_fx.c | 106 +- lib_dec/core_dec_switch.c | 330 +- lib_dec/core_dec_switch_fx.c | 154 +- lib_dec/core_switching_dec.c | 1612 +- lib_dec/core_switching_dec_fx.c | 936 +- lib_dec/d_gain2p_fx.c | 283 +- lib_dec/dec2t32_fx.c | 50 +- lib_dec/dec4t64.c | 2 +- lib_dec/dec4t64_fx.c | 890 +- lib_dec/dec_LPD.c | 8 +- lib_dec/dec_LPD_fx.c | 551 +- lib_dec/dec_ace.c | 8 +- lib_dec/dec_ace_fx.c | 377 +- lib_dec/dec_acelp.c | 2 +- lib_dec/dec_acelp_fx.c | 313 +- lib_dec/dec_acelp_tcx_main.c | 366 +- lib_dec/dec_acelp_tcx_main_fx.c | 239 +- lib_dec/dec_amr_wb_fx.c | 101 +- lib_dec/dec_gen_voic_fx.c | 647 +- lib_dec/dec_higher_acelp_fx.c | 217 +- lib_dec/dec_nelp_fx.c | 48 +- lib_dec/dec_pit_exc_fx.c | 678 +- lib_dec/dec_post.c | 6 +- lib_dec/dec_post_fx.c | 1035 +- lib_dec/dec_ppp_fx.c | 57 +- lib_dec/dec_prm.c | 68 +- lib_dec/dec_prm_fx.c | 605 +- lib_dec/dec_tcx.c | 185 +- lib_dec/dec_tcx_fx.c | 2298 ++- lib_dec/dec_tran_fx.c | 130 +- lib_dec/dec_uv.c | 2 +- lib_dec/dec_uv_fx.c | 302 +- lib_dec/decision_matrix_dec.c | 2 +- lib_dec/decision_matrix_dec_fx.c | 179 +- lib_dec/dlpc_avq.c | 2 +- lib_dec/dlpc_avq_fx.c | 192 +- lib_dec/dlpc_stoch.c | 2 +- lib_dec/dlpc_stoch_fx.c | 68 +- lib_dec/er_dec_acelp.c | 14 +- lib_dec/er_dec_acelp_fx.c | 790 +- lib_dec/er_dec_tcx.c | 8 +- lib_dec/er_dec_tcx_fx.c | 1648 +-- lib_dec/er_scale_syn.c | 2 +- lib_dec/er_scale_syn_fx.c | 107 +- lib_dec/er_sync_exc.c | 2 +- lib_dec/er_sync_exc_fx.c | 478 +- lib_dec/er_util.c | 2 +- lib_dec/er_util_fx.c | 398 +- lib_dec/evs_dec_fx.c | 817 +- lib_dec/fd_cng_dec.c | 1081 +- lib_dec/fd_cng_dec_fx.c | 2442 ++- lib_dec/gain_dec_fx.c | 940 +- lib_dec/gaus_dec_fx.c | 196 +- lib_dec/gs_dec.c | 2 +- lib_dec/gs_dec_amr_wb_fx.c | 378 +- lib_dec/gs_dec_fx.c | 1028 +- lib_dec/hdecnrm_fx.c | 301 +- lib_dec/hf_synth_fx.c | 1388 +- lib_dec/hq_classifier_dec_fx.c | 39 +- lib_dec/hq_conf_fec.c | 2 +- lib_dec/hq_conf_fec_fx.c | 14 +- lib_dec/hq_core_dec.c | 134 +- lib_dec/hq_core_dec_fx.c | 494 +- lib_dec/hq_env_dec_fx.c | 120 +- lib_dec/hq_hr_dec_fx.c | 172 +- lib_dec/hq_lr_dec.c | 2 +- lib_dec/hq_lr_dec_fx.c | 954 +- lib_dec/igf_dec.c | 32 +- lib_dec/igf_dec_fx.c | 1663 ++- lib_dec/igf_scf_dec.c | 6 +- lib_dec/igf_scf_dec_fx.c | 210 +- lib_dec/init_dec.c | 4 +- lib_dec/init_dec_fx.c | 367 +- lib_dec/inov_dec.c | 2 +- lib_dec/inov_dec_fx.c | 107 +- lib_dec/ivas_binRenderer_internal.c | 764 +- lib_dec/ivas_core_dec.c | 559 +- lib_dec/ivas_corecoder_dec_reconfig.c | 56 +- lib_dec/ivas_cpe_dec.c | 2 - lib_dec/ivas_cpe_dec_fx.c | 212 +- lib_dec/ivas_decision_matrix_dec.c | 194 +- lib_dec/ivas_dirac_dec.c | 1039 +- lib_dec/ivas_dirac_output_synthesis_cov.c | 673 +- lib_dec/ivas_entropy_decoder.c | 4 +- lib_dec/ivas_init_dec.c | 1071 +- lib_dec/ivas_init_dec_fx.c | 2 +- lib_dec/ivas_ism_dec.c | 556 +- lib_dec/ivas_ism_dtx_dec.c | 58 +- lib_dec/ivas_ism_param_dec.c | 484 +- lib_dec/ivas_ism_renderer.c | 169 +- lib_dec/ivas_jbm_dec.c | 730 +- lib_dec/ivas_lfe_dec.c | 2 +- lib_dec/ivas_lfe_plc.c | 2 +- lib_dec/ivas_lfe_plc_fx.c | 4 +- lib_dec/ivas_ls_custom_dec.c | 6 +- lib_dec/ivas_masa_dec.c | 32 +- lib_dec/ivas_mc_param_dec.c | 692 +- lib_dec/ivas_mc_param_dec_fx.c | 2 +- lib_dec/ivas_mc_paramupmix_dec.c | 1822 ++- lib_dec/ivas_mcmasa_dec.c | 10 +- lib_dec/ivas_mct_core_dec.c | 38 +- lib_dec/ivas_mct_dec.c | 865 +- lib_dec/ivas_mct_dec_mct.c | 1 - lib_dec/ivas_mct_dec_mct_fx.c | 10 +- lib_dec/ivas_mdct_core_dec.c | 310 +- lib_dec/ivas_objectRenderer_internal.c | 27 +- lib_dec/ivas_omasa_dec.c | 181 +- lib_dec/ivas_osba_dec.c | 39 +- lib_dec/ivas_out_setup_conversion.c | 172 +- lib_dec/ivas_output_config.c | 237 +- lib_dec/ivas_pca_dec.c | 2 +- lib_dec/ivas_pca_dec_fx.c | 18 +- lib_dec/ivas_post_proc.c | 35 +- lib_dec/ivas_qmetadata_dec.c | 26 +- lib_dec/ivas_qspherical_dec.c | 2 +- lib_dec/ivas_range_uni_dec.c | 28 +- lib_dec/ivas_rom_dec.h | 1 - lib_dec/ivas_sba_dec.c | 260 +- lib_dec/ivas_sba_dirac_stereo_dec.c | 8 +- lib_dec/ivas_sba_dirac_stereo_dec_fx.c | 744 +- lib_dec/ivas_sba_rendering_internal.c | 204 +- lib_dec/ivas_sce_dec.c | 37 +- lib_dec/ivas_sce_dec_fx.c | 29 +- lib_dec/ivas_spar_decoder.c | 393 +- lib_dec/ivas_spar_md_dec.c | 2273 ++- lib_dec/ivas_stat_dec.h | 164 +- lib_dec/ivas_stereo_adapt_GR_dec.c | 2 +- lib_dec/ivas_stereo_cng_dec.c | 378 +- lib_dec/ivas_stereo_dft_dec.c | 49 +- lib_dec/ivas_stereo_dft_dec_dmx.c | 180 +- lib_dec/ivas_stereo_dft_dec_fx.c | 1469 +- lib_dec/ivas_stereo_dft_plc_fx.c | 14 +- lib_dec/ivas_stereo_ica_dec.c | 325 +- lib_dec/ivas_stereo_icbwe_dec.c | 26 +- lib_dec/ivas_stereo_mdct_core_dec.c | 32 +- lib_dec/ivas_stereo_mdct_core_dec_fx.c | 183 +- lib_dec/ivas_stereo_mdct_stereo_dec.c | 73 +- lib_dec/ivas_stereo_switching_dec.c | 798 +- lib_dec/ivas_stereo_td_dec.c | 8 +- lib_dec/ivas_svd_dec.c | 552 +- lib_dec/ivas_tcx_core_dec.c | 31 +- lib_dec/ivas_td_low_rate_dec.c | 156 +- lib_dec/jbm_jb4_circularbuffer.c | 90 +- lib_dec/jbm_jb4_circularbuffer.h | 1 - lib_dec/jbm_jb4_inputbuffer.c | 50 +- lib_dec/jbm_jb4_jmf.c | 34 +- lib_dec/jbm_jb4sb.c | 282 +- lib_dec/jbm_pcmdsp_apa.c | 535 +- lib_dec/jbm_pcmdsp_similarityestimation.c | 115 +- lib_dec/jbm_pcmdsp_similarityestimation.h | 32 +- lib_dec/jbm_pcmdsp_window.c | 152 +- lib_dec/jbm_pcmdsp_window.h | 13 +- lib_dec/lead_deindexing_fx.c | 184 +- lib_dec/lib_dec.c | 68 +- lib_dec/lib_dec.h | 3 - lib_dec/lib_dec_fx.c | 625 +- lib_dec/lp_exc_d_fx.c | 51 +- lib_dec/lsf_dec.c | 28 +- lib_dec/lsf_dec_fx.c | 438 +- lib_dec/lsf_msvq_ma_dec.c | 8 +- lib_dec/lsf_msvq_ma_dec_fx.c | 151 +- lib_dec/nelp_dec.c | 2 +- lib_dec/nelp_dec_fx.c | 315 +- lib_dec/peak_vq_dec_fx.c | 345 +- lib_dec/pit_dec_fx.c | 616 +- lib_dec/pitch_extr_fx.c | 312 +- lib_dec/post_dec_fx.c | 463 +- lib_dec/ppp_dec_fx.c | 320 +- lib_dec/pvq_core_dec_fx.c | 473 +- lib_dec/pvq_decode_fx.c | 86 +- lib_dec/range_dec_fx.c | 160 +- lib_dec/re8_dec_fx.c | 36 +- lib_dec/rom_dec.c | 172 +- lib_dec/rst_dec_fx.c | 46 +- lib_dec/stat_dec.h | 3252 ++-- lib_dec/stat_noise_uv_dec_fx.c | 52 +- lib_dec/swb_bwe_dec.c | 1143 +- lib_dec/swb_bwe_dec_fx.c | 727 +- lib_dec/swb_bwe_dec_hr_fx.c | 987 +- lib_dec/swb_bwe_dec_lr.c | 6 +- lib_dec/swb_bwe_dec_lr_fx.c | 202 +- lib_dec/swb_tbe_dec.c | 378 +- lib_dec/swb_tbe_dec_fx.c | 2550 ++-- lib_dec/syn_outp_fx.c | 70 +- lib_dec/tcq_core_dec_fx.c | 217 +- lib_dec/tcx_utils_dec_fx.c | 209 +- lib_dec/tns_base_dec_fx.c | 91 +- lib_dec/tonalMDCTconcealment.c | 33 +- lib_dec/tonalMDCTconcealment_fx.c | 2057 +-- lib_dec/transition_dec_fx.c | 507 +- lib_dec/updt_dec_fx.c | 726 +- lib_dec/vlpc_1st_dec_fx.c | 13 +- lib_dec/vlpc_2st_dec_fx.c | 26 +- lib_dec/voiced_dec.c | 2 +- lib_dec/voiced_dec_fx.c | 266 +- lib_dec/waveadjust_fec_dec.c | 2 +- lib_dec/waveadjust_fec_dec_fx.c | 1237 +- lib_enc/ACcontextMapping_enc_fx.c | 726 +- lib_enc/FEC_enc_fx.c | 142 +- lib_enc/SNR_calc_fx.c | 974 +- lib_enc/acelp_core_enc.c | 24 +- lib_enc/acelp_core_enc_fx.c | 423 +- lib_enc/acelp_core_switch_enc_fx.c | 479 +- lib_enc/acelp_enc_util_fx.c | 218 +- lib_enc/amr_wb_enc.c | 3 +- lib_enc/amr_wb_enc_fx.c | 294 +- lib_enc/analy_lp_fx.c | 115 +- lib_enc/analy_sp_fx.c | 373 +- lib_enc/ari_enc_fx.c | 192 +- lib_enc/ari_hm_enc_fx.c | 587 +- lib_enc/arith_coder_enc.c | 4 +- lib_enc/arith_coder_enc_fx.c | 601 +- lib_enc/avq_cod_fx.c | 516 +- lib_enc/bass_psfilter_enc_fx.c | 365 +- lib_enc/bw_detect_fx.c | 694 +- lib_enc/cng_enc_fx.c | 1117 +- lib_enc/cod2t32_fx.c | 264 +- lib_enc/cod4t64.c | 8 +- lib_enc/cod4t64_fx.c | 1295 +- lib_enc/cod_ace.c | 4 +- lib_enc/cod_ace_fx.c | 293 +- lib_enc/cod_tcx.c | 40 +- lib_enc/cod_tcx_fx.c | 2009 ++- lib_enc/cod_uv_fx.c | 79 +- lib_enc/comvad_decision_fx.c | 463 +- lib_enc/cor_shif_fx.c | 36 +- lib_enc/core_enc_2div_fx.c | 242 +- lib_enc/core_enc_init_fx.c | 421 +- lib_enc/core_enc_ol.c | 8 +- lib_enc/core_enc_ol_fx.c | 1091 +- lib_enc/core_enc_reconf_fx.c | 168 +- lib_enc/core_enc_switch.c | 2 +- lib_enc/core_enc_switch_fx.c | 126 +- lib_enc/core_enc_updt_fx.c | 135 +- lib_enc/core_switching_enc_fx.c | 492 +- lib_enc/corr_xh_fx.c | 52 +- lib_enc/decision_matrix_enc_fx.c | 350 +- lib_enc/detect_transient_fx.c | 670 +- lib_enc/diffcod_fx.c | 89 +- lib_enc/dtx_fx.c | 729 +- lib_enc/enc_acelp_fx.c | 1374 +- lib_enc/enc_acelp_tcx_main_fx.c | 52 +- lib_enc/enc_acelpx_fx.c | 332 +- lib_enc/enc_amr_wb_fx.c | 188 +- lib_enc/enc_gain_fx.c | 225 +- lib_enc/enc_gen_voic_fx.c | 261 +- lib_enc/enc_gen_voic_rf.c | 6 +- lib_enc/enc_gen_voic_rf_fx.c | 366 +- lib_enc/enc_higher_acelp_fx.c | 363 +- lib_enc/enc_nelp.c | 2 +- lib_enc/enc_nelp_fx.c | 81 +- lib_enc/enc_pit_exc_fx.c | 396 +- lib_enc/enc_ppp_fx.c | 121 +- lib_enc/enc_prm_fx.c | 463 +- lib_enc/enc_tran_fx.c | 258 +- lib_enc/enc_uv_fx.c | 169 +- lib_enc/energy_fx.c | 357 +- lib_enc/eval_pit_contr_fx.c | 276 +- lib_enc/evs_enc.c | 2 +- lib_enc/evs_enc_fx.c | 373 +- lib_enc/ext_sig_ana.c | 2 +- lib_enc/ext_sig_ana_fx.c | 495 +- lib_enc/fd_cng_enc.c | 14 +- lib_enc/fd_cng_enc_fx.c | 1043 +- lib_enc/find_tar_fx.c | 169 +- lib_enc/find_tilt_fx.c | 228 +- lib_enc/find_uv_fx.c | 426 +- lib_enc/find_wsp_fx.c | 33 +- lib_enc/frame_spec_dif_cor_rate_fx.c | 95 +- lib_enc/gain_enc_fx.c | 1539 +- lib_enc/gaus_enc_fx.c | 537 +- lib_enc/gp_clip_fx.c | 681 +- lib_enc/gs_enc_fx.c | 395 +- lib_enc/guided_plc_enc_fx.c | 237 +- lib_enc/hf_cod_amrwb_fx.c | 199 +- lib_enc/hq_classifier_enc_fx.c | 483 +- lib_enc/hq_core_enc_fx.c | 199 +- lib_enc/hq_env_enc_fx.c | 207 +- lib_enc/hq_hr_enc_fx.c | 149 +- lib_enc/hq_lr_enc_fx.c | 1387 +- lib_enc/hvq_enc.c | 4 +- lib_enc/hvq_enc_fx.c | 181 +- lib_enc/igf_enc.c | 2 +- lib_enc/igf_enc_fx.c | 1231 +- lib_enc/igf_scf_enc_fx.c | 303 +- lib_enc/init_enc.c | 1462 +- lib_enc/init_enc_fx.c | 459 +- lib_enc/inov_enc_fx.c | 248 +- lib_enc/isf_enc_amr_wb_fx.c | 941 +- lib_enc/ivas_agc_enc.c | 28 +- lib_enc/ivas_core_enc.c | 1 - lib_enc/ivas_core_pre_proc_front.c | 2 +- lib_enc/ivas_corecoder_enc_reconfig.c | 1 - lib_enc/ivas_cpe_enc.c | 420 +- lib_enc/ivas_enc.c | 71 +- lib_enc/ivas_entropy_coder.c | 96 +- lib_enc/ivas_front_vad.c | 84 +- lib_enc/ivas_init_enc.c | 936 +- lib_enc/ivas_ism_enc.c | 1 - lib_enc/ivas_lfe_enc.c | 23 +- lib_enc/ivas_masa_enc.c | 2 - lib_enc/ivas_mct_core_enc.c | 1 - lib_enc/ivas_mct_enc_mct.c | 1 - lib_enc/ivas_mdct_core_enc.c | 4 +- lib_enc/ivas_qmetadata_enc.c | 7 +- lib_enc/ivas_sce_enc.c | 28 +- lib_enc/ivas_spar_encoder.c | 326 +- lib_enc/ivas_spar_md_enc.c | 236 +- lib_enc/ivas_stat_enc.h | 148 +- lib_enc/ivas_stereo_classifier.c | 124 +- lib_enc/ivas_stereo_cng_enc.c | 8 +- lib_enc/ivas_stereo_dft_enc.c | 550 +- lib_enc/ivas_stereo_dft_enc_itd.c | 9 +- lib_enc/ivas_stereo_dft_td_itd.c | 10 +- lib_enc/ivas_stereo_dmx_evs.c | 4 +- lib_enc/ivas_stereo_ica_enc.c | 86 +- lib_enc/ivas_stereo_icbwe_enc.c | 64 +- lib_enc/ivas_stereo_mdct_core_enc.c | 2 +- lib_enc/ivas_stereo_mdct_stereo_enc.c | 159 +- lib_enc/ivas_stereo_switching_enc.c | 2 +- lib_enc/ivas_stereo_td_enc.c | 156 +- lib_enc/ivas_tcx_core_enc.c | 4 +- lib_enc/lead_indexing_fx.c | 107 +- lib_enc/lib_enc.c | 920 +- lib_enc/long_enr_fx.c | 67 +- lib_enc/lp_exc_e_fx.c | 244 +- lib_enc/lsf_enc.c | 14 +- lib_enc/lsf_enc_fx.c | 1490 +- lib_enc/lsf_msvq_ma_enc.c | 6 +- lib_enc/lsf_msvq_ma_enc_fx.c | 458 +- lib_enc/ltd_stable_fx.c | 430 +- lib_enc/mdct_classifier.c | 2 +- lib_enc/mdct_classifier_fx.c | 404 +- lib_enc/mdct_selector.c | 2 +- lib_enc/mdct_selector_fx.c | 258 +- lib_enc/mslvq_enc_fx.c | 540 +- lib_enc/multi_harm_fx.c | 262 +- lib_enc/nelp_enc_fx.c | 1754 ++- lib_enc/nois_est_fx.c | 1293 +- lib_enc/noise_adjust_fx.c | 50 +- lib_enc/normalizecoefs_fx.c | 47 +- lib_enc/peak_vq_enc.c | 4 +- lib_enc/peak_vq_enc_fx.c | 481 +- lib_enc/pit_enc_fx.c | 803 +- lib_enc/pitch_ol2_fx.c | 330 +- lib_enc/pitch_ol_fx.c | 964 +- lib_enc/plc_enc_ext_fx.c | 54 +- lib_enc/ppp_enc_fx.c | 635 +- lib_enc/pre_proc.c | 18 +- lib_enc/pre_proc_fx.c | 671 +- lib_enc/prot_fx_enc.h | 4212 +++--- lib_enc/pvq_core_enc_fx.c | 542 +- lib_enc/pvq_encode_fx.c | 333 +- lib_enc/q_gain2p_fx.c | 491 +- lib_enc/qlpc_avq_fx.c | 244 +- lib_enc/qlpc_stoch_fx.c | 231 +- lib_enc/range_enc_fx.c | 197 +- lib_enc/re8_cod_fx.c | 24 +- lib_enc/reordernorm_fx.c | 38 +- lib_enc/rom_enc.c | 144 +- lib_enc/rom_enc.h | 14 +- lib_enc/rst_enc_fx.c | 41 +- lib_enc/scale_enc_fx.c | 271 +- lib_enc/set_impulse_fx.c | 274 +- lib_enc/setmodeindex_fx.c | 34 +- lib_enc/sig_clas_fx.c | 358 +- lib_enc/spec_center_fx.c | 311 +- lib_enc/spec_flatness_fx.c | 335 +- lib_enc/speech_music_classif.c | 2 +- lib_enc/speech_music_classif_fx.c | 2248 +-- lib_enc/stat_enc.h | 2087 +-- lib_enc/stat_noise_uv_enc_fx.c | 58 +- lib_enc/subband_fft_fx.c | 313 +- lib_enc/swb_bwe_enc_fx.c | 2142 ++- lib_enc/swb_bwe_enc_hr_fx.c | 510 +- lib_enc/swb_bwe_enc_lr_fx.c | 1996 ++- lib_enc/swb_pre_proc_fx.c | 224 +- lib_enc/swb_tbe_enc.c | 2 +- lib_enc/swb_tbe_enc_fx.c | 1915 ++- lib_enc/tcq_core_enc_fx.c | 281 +- lib_enc/tcx_ltp_enc.c | 2 +- lib_enc/tcx_ltp_enc_fx.c | 420 +- lib_enc/tcx_utils_enc_fx.c | 1464 +- lib_enc/tfa_enc_fx.c | 91 +- lib_enc/tns_base_enc.c | 4 +- lib_enc/tns_base_enc_fx.c | 284 +- lib_enc/transient_detection.c | 12 +- lib_enc/transient_detection_fx.c | 579 +- lib_enc/transition_enc_fx.c | 680 +- lib_enc/update_decision_fx.c | 262 +- lib_enc/updt_enc_fx.c | 313 +- lib_enc/updt_tar_fx.c | 54 +- lib_enc/vad_basop.h | 40 +- lib_enc/vad_basop_fx.c | 98 +- lib_enc/vad_fx.c | 1159 +- lib_enc/vad_param_updt_fx.c | 109 +- lib_enc/vad_proc_fx.c | 263 +- lib_enc/vbr_average_rate_fx.c | 125 +- lib_enc/vlpc_1st_cod_fx.c | 106 +- lib_enc/vlpc_2st_cod_fx.c | 114 +- lib_enc/voiced_enc_fx.c | 1129 +- lib_enc/waveadjust_fec_cod_fx.c | 72 +- lib_rend/ivas_allrad_dec.c | 10 +- lib_rend/ivas_crend.c | 489 +- lib_rend/ivas_dirac_ana.c | 5 +- lib_rend/ivas_dirac_dec_binaural_functions.c | 137 +- lib_rend/ivas_dirac_decorr_dec.c | 280 +- lib_rend/ivas_dirac_onsets_dec.c | 156 +- lib_rend/ivas_dirac_output_synthesis_dec.c | 1147 +- lib_rend/ivas_dirac_rend.c | 1223 +- lib_rend/ivas_efap.c | 356 +- lib_rend/ivas_limiter.c | 322 +- lib_rend/ivas_masa_merge.c | 197 +- lib_rend/ivas_mcmasa_ana.c | 631 +- lib_rend/ivas_objectRenderer.c | 344 +- lib_rend/ivas_objectRenderer_hrFilt.c | 16 +- lib_rend/ivas_objectRenderer_mix.c | 121 +- lib_rend/ivas_objectRenderer_sfx.c | 24 +- lib_rend/ivas_objectRenderer_sources.c | 330 +- lib_rend/ivas_objectRenderer_vec.c | 52 +- lib_rend/ivas_omasa_ana.c | 276 +- lib_rend/ivas_orient_trk.c | 100 +- lib_rend/ivas_output_init.c | 64 +- lib_rend/ivas_output_init_fx.c | 4 +- lib_rend/ivas_reflections.c | 201 +- lib_rend/ivas_render_config.c | 6 +- lib_rend/ivas_reverb.c | 877 +- lib_rend/ivas_reverb_delay_line.c | 82 +- lib_rend/ivas_reverb_fft_filter.c | 31 +- lib_rend/ivas_reverb_filter_design.c | 1571 +- lib_rend/ivas_reverb_iir_filter.c | 38 +- lib_rend/ivas_reverb_utils.c | 94 +- lib_rend/ivas_rom_TdBinauralRenderer.h | 28 +- lib_rend/ivas_rom_rend.h | 4 +- lib_rend/ivas_rotation.c | 137 +- lib_rend/ivas_sba_rendering.c | 278 +- lib_rend/ivas_shoebox.c | 61 +- lib_rend/ivas_stat_rend.h | 285 +- lib_rend/ivas_td_decorr.c | 4 +- lib_rend/ivas_vbap.c | 726 +- lib_rend/lib_rend.c | 699 +- lib_rend/lib_rend.h | 4 +- lib_util/audio_file_reader.c | 2 +- lib_util/hrtf_file_reader.c | 70 +- lib_util/ism_file_reader.c | 10 +- lib_util/masa_file_reader.c | 4 +- lib_util/render_config_reader.c | 21 +- lib_util/rotation_file_reader.c | 14 +- lib_util/test_fft.h | 2 +- lib_util/test_mdct.c | 265 +- 706 files changed, 166606 insertions(+), 156834 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index 5c2c1e9ce..38d513d86 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -130,8 +130,8 @@ static bool parseCmdlIVAS_dec( int16_t argc, char **argv, DecArguments *arg ); static void usage_dec( void ); static ivas_error decodeG192( DecArguments arg, BS_READER_HANDLE hBsReader, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, IVAS_DEC_HANDLE hIvasDec, int16_t *pcmBuf ); static ivas_error decodeVoIP( DecArguments arg, BS_READER_HANDLE hBsReader, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, IVAS_DEC_HANDLE hIvasDec ); -void run_fft_unit_test(void); -void run_mdct_unit_test(void); +void run_fft_unit_test( void ); +void run_mdct_unit_test( void ); /*------------------------------------------------------------------------------------------* * main() @@ -176,11 +176,11 @@ int main( IVAS_DEC_PrintDisclaimer(); - if (run_unit_tests) + if ( run_unit_tests ) { - run_fft_unit_test(); - run_mdct_unit_test(); - return 0; + run_fft_unit_test(); + run_mdct_unit_test(); + return 0; } if ( !parseCmdlIVAS_dec( (int16_t) argc, argv, &arg ) ) @@ -256,8 +256,7 @@ int main( if ( arg.enableHeadRotation ) { /* sanity check */ - if ( arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB - ) + if ( arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) { fprintf( stderr, "\nError: Head-rotation file file cannot be used in this output configuration.\n\n" ); goto cleanup; @@ -357,8 +356,7 @@ int main( if ( arg.renderConfigEnabled ) { /* sanity check */ - if ( arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB - ) + if ( arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) { fprintf( stderr, "\nError: Renderer configuration file cannot be used in this output configuration.\n\n" ); goto cleanup; @@ -452,7 +450,7 @@ int main( { renderConfig.directivity_fx[i * 3] = (Word16) ( renderConfig.directivity[i * 3] * ( 1u << 6 ) ); renderConfig.directivity_fx[i * 3 + 1] = (Word16) ( renderConfig.directivity[i * 3 + 1] * ( 1u << 6 ) ); - renderConfig.directivity_fx[i * 3 + 2] = (Word16) ( renderConfig.directivity[i * 3 + 2] * ( (1u << 15)-1 ) ); + renderConfig.directivity_fx[i * 3 + 2] = (Word16) ( renderConfig.directivity[i * 3 + 2] * ( ( 1u << 15 ) - 1 ) ); } #endif // IVAS_FLOAT_FIXED @@ -616,9 +614,9 @@ cleanup: #ifndef DONT_COUNT /* end of WMOPS counting */ BASOP_end - BASOP_end_noprint + BASOP_end_noprint #endif - free( pcmBuf ); + free( pcmBuf ); if ( arg.hrtfReaderEnabled ) { @@ -630,7 +628,7 @@ cleanup: destroy_SetOfHRTF( hSetOfHRTF ); } - IVAS_DEC_Close( &hIvasDec ); + IVAS_DEC_Close( &hIvasDec ); CustomLsReader_close( &hLsCustomReader ); hrtfFileReader_close( &hrtfReader ); RotationFileReader_close( &headRotReader ); @@ -1313,7 +1311,6 @@ static void usage_dec( void ) } - /*---------------------------------------------------------------------* * initOnFirstGoodFrame() * @@ -1321,10 +1318,10 @@ static void usage_dec( void ) *---------------------------------------------------------------------*/ static ivas_error initOnFirstGoodFrame( - IVAS_DEC_HANDLE hIvasDec, /* i/o: */ - const DecArguments arg, /* i : */ - const int16_t numInitialBadFrames, /* i : */ - const uint16_t numOutSamples, /* i : */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: */ + const DecArguments arg, /* i : */ + const int16_t numInitialBadFrames, /* i : */ + const uint16_t numOutSamples, /* i : */ int16_t *pFullDelayNumSamples, /* o : */ int16_t *pRemainingDelayNumSamples, /* o : */ int32_t *delayTimeScale, /* o : */ @@ -1333,7 +1330,7 @@ static ivas_error initOnFirstGoodFrame( MasaFileWriter **ppMasaWriter, /* o : */ IsmFileWriter *ismWriters[IVAS_MAX_NUM_OBJECTS], /* o : */ int16_t *pNumOutChannels, /* o : */ - uint16_t *pNumObj /* o : */ + uint16_t *pNumObj /* o : */ ) { ivas_error error = IVAS_ERR_UNKNOWN; @@ -1366,12 +1363,12 @@ static ivas_error initOnFirstGoodFrame( return error; } - /* Open audio writer and write all previously skipped bad frames now that frame size is known */ - if ( ( error = AudioFileWriter_open( ppAfWriter, arg.outputWavFilename, arg.output_Fs, *pNumOutChannels ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nUnable to open output file %s\n", arg.outputWavFilename ); - return error; - } + /* Open audio writer and write all previously skipped bad frames now that frame size is known */ + if ( ( error = AudioFileWriter_open( ppAfWriter, arg.outputWavFilename, arg.output_Fs, *pNumOutChannels ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nUnable to open output file %s\n", arg.outputWavFilename ); + return error; + } int16_t *zeroBuf = malloc( pcmFrameSize * sizeof( int16_t ) ); memset( zeroBuf, 0, pcmFrameSize * sizeof( int16_t ) ); @@ -1380,18 +1377,18 @@ static ivas_error initOnFirstGoodFrame( { if ( *pRemainingDelayNumSamples < numOutSamples ) - { + { if ( ( error = AudioFileWriter_write( *ppAfWriter, zeroBuf, numOutSamples * *pNumOutChannels - ( *pRemainingDelayNumSamples * *pNumOutChannels ) ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nOutput audio file writer error\n" ); - return error; - } - *pRemainingDelayNumSamples = 0; - } - else { - *pRemainingDelayNumSamples -= numOutSamples; + fprintf( stderr, "\nOutput audio file writer error\n" ); + return error; } + *pRemainingDelayNumSamples = 0; + } + else + { + *pRemainingDelayNumSamples -= numOutSamples; + } } free( zeroBuf ); @@ -1519,9 +1516,15 @@ static ivas_error decodeG192( int16_t nSamplesRendered, nSamplesRendered_loop, nSamplesToRender; IsmFileWriter *ismWriters[IVAS_MAX_NUM_OBJECTS]; #ifdef IVAS_FLOAT_FIXED - IVAS_VECTOR3 Pos[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES] = { { 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0,0 }, { 0, 0, 0, 0, 0, 0, 0 } }; + IVAS_VECTOR3 Pos[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES] = { { 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0 } }; #else - IVAS_VECTOR3 Pos[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES] = { { 0, 0, 0 }, { 0, 0, 0, }, { 0, 0,0 }, { 0, 0, 0 } }; + IVAS_VECTOR3 Pos[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES] = { { 0, 0, 0 }, { + 0, + 0, + 0, + }, + { 0, 0, 0 }, + { 0, 0, 0 } }; #endif int16_t vec_pos_update, vec_pos_len; @@ -1622,14 +1625,14 @@ static ivas_error decodeG192( { IVAS_QUATERNION Quaternions[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES]; - for ( i = 0; i < num_subframes; i++ ) + for ( i = 0; i < num_subframes; i++ ) + { + if ( ( error = HeadRotationFileReading( headRotReader, &Quaternions[i], &Pos[i] ) ) != IVAS_ERR_OK ) { - if ( ( error = HeadRotationFileReading( headRotReader, &Quaternions[i], &Pos[i] ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nError %s while reading head orientation from %s\n", IVAS_DEC_GetErrorMessage( error ), RotationFileReader_getFilePath( headRotReader ) ); - goto cleanup; - } + fprintf( stderr, "\nError %s while reading head orientation from %s\n", IVAS_DEC_GetErrorMessage( error ), RotationFileReader_getFilePath( headRotReader ) ); + goto cleanup; } + } for ( i = 0; i < num_subframes; i++ ) { @@ -1693,12 +1696,12 @@ static ivas_error decodeG192( } if ( ( error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, ( pcmBuf + nOutChannels * nSamplesRendered ), &nSamplesRendered_loop, &needNewFrame ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nError in IVAS_DEC_GetSamples: %s\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; - } - nSamplesRendered += nSamplesRendered_loop; - nSamplesToRender -= nSamplesRendered_loop; + { + fprintf( stderr, "\nError in IVAS_DEC_GetSamples: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + nSamplesRendered += nSamplesRendered_loop; + nSamplesToRender -= nSamplesRendered_loop; if ( needNewFrame ) { @@ -1743,19 +1746,19 @@ static ivas_error decodeG192( /* Write current frame */ if ( decodedGoodFrame ) { - if ( delayNumSamples < nOutSamples ) - { - if ( ( error = AudioFileWriter_write( afWriter, &pcmBuf[delayNumSamples * nOutChannels], nOutSamples * nOutChannels - ( delayNumSamples * nOutChannels ) ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nOutput audio file writer error\n" ); - goto cleanup; - } - delayNumSamples = 0; - } - else + if ( delayNumSamples < nOutSamples ) + { + if ( ( error = AudioFileWriter_write( afWriter, &pcmBuf[delayNumSamples * nOutChannels], nOutSamples * nOutChannels - ( delayNumSamples * nOutChannels ) ) ) != IVAS_ERR_OK ) { - delayNumSamples -= nOutSamples; + fprintf( stderr, "\nOutput audio file writer error\n" ); + goto cleanup; } + delayNumSamples = 0; + } + else + { + delayNumSamples -= nOutSamples; + } } /* Write ISm metadata to external file(s) */ @@ -1821,7 +1824,7 @@ static ivas_error decodeG192( /* update WMPOS counting (end of frame) */ BASOP_frame_update(); } - + #endif #endif } @@ -1996,11 +1999,11 @@ static ivas_error decodeG192( *------------------------------------------------------------------------------------------*/ memset( pcmBuf, 0, delayNumSamples_orig[0] * nOutChannels * sizeof( int16_t ) ); - if ( ( error = AudioFileWriter_write( afWriter, pcmBuf, delayNumSamples_orig[0] * nOutChannels ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nError writing output file: %s\n", ivas_error_to_string( error ) ); - goto cleanup; - } + if ( ( error = AudioFileWriter_write( afWriter, pcmBuf, delayNumSamples_orig[0] * nOutChannels ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError writing output file: %s\n", ivas_error_to_string( error ) ); + goto cleanup; + } /*------------------------------------------------------------------------------------------* * Close files and deallocate resources @@ -2090,9 +2093,15 @@ static ivas_error decodeVoIP( IVAS_DEC_BS_FORMAT bsFormat = IVAS_DEC_BS_UNKOWN; IsmFileWriter *ismWriters[IVAS_MAX_NUM_OBJECTS]; #ifdef IVAS_FLOAT_FIXED - IVAS_VECTOR3 Pos[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES] = { { 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0,0 }, { 0, 0, 0, 0, 0, 0, 0 } }; + IVAS_VECTOR3 Pos[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES] = { { 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0 } }; #else - IVAS_VECTOR3 Pos[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES] = { { 0, 0, 0 }, { 0, 0, 0, }, { 0, 0,0 }, { 0, 0, 0 } }; + IVAS_VECTOR3 Pos[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES] = { { 0, 0, 0 }, { + 0, + 0, + 0, + }, + { 0, 0, 0 }, + { 0, 0, 0 } }; #endif int16_t vec_pos_update, vec_pos_len; int16_t nOutSamples = 0; @@ -2260,20 +2269,19 @@ static ivas_error decodeVoIP( { IVAS_QUATERNION Quaternions[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES]; - for ( i = 0; i < num_subframes; i++ ) + for ( i = 0; i < num_subframes; i++ ) + { + if ( ( error = HeadRotationFileReading( headRotReader, &Quaternions[i], &Pos[i] ) ) != IVAS_ERR_OK ) { - if ( ( error = HeadRotationFileReading( headRotReader, &Quaternions[i], &Pos[i] ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nError %s while reading head orientation from %s\n", IVAS_DEC_GetErrorMessage( error ), - RotationFileReader_getFilePath( headRotReader ) ); - goto cleanup; - } + fprintf( stderr, "\nError %s while reading head orientation from %s\n", IVAS_DEC_GetErrorMessage( error ), + RotationFileReader_getFilePath( headRotReader ) ); + goto cleanup; } + } for ( i = 0; i < num_subframes; i++ ) { - if ( ( error = IVAS_DEC_FeedHeadTrackData( hIvasDec, Quaternions[i], Pos[i], i - ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_FeedHeadTrackData( hIvasDec, Quaternions[i], Pos[i], i ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nIVAS_DEC_FeedHeadTrackData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; @@ -2483,7 +2491,7 @@ static ivas_error decodeVoIP( fprintf( stdout, "%-8d\b\b\b\b\b\b\b\b", frame ); } vec_pos_update = ( vec_pos_update + 1 ) % vec_pos_len; - //frame++; + // frame++; systemTime_ms += systemTimeInc_ms; #ifdef WMOPS #ifndef DONT_COUNT @@ -2570,5 +2578,4 @@ cleanup: } - #undef WMC_TOOL_SKIP diff --git a/apps/encoder.c b/apps/encoder.c index 3e0a9a900..c8e6f32d6 100644 --- a/apps/encoder.c +++ b/apps/encoder.c @@ -191,10 +191,10 @@ int main( * Open and initialize IVAS encoder *------------------------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED - if ((error = IVAS_ENC_Open_fx(&hIvasEnc)) != IVAS_ERR_OK) + if ( ( error = IVAS_ENC_Open_fx( &hIvasEnc ) ) != IVAS_ERR_OK ) { - fprintf(stderr, "Opening IVAS encoder failed: %s\n", IVAS_ENC_GetErrorMessage(error)); - goto cleanup; + fprintf( stderr, "Opening IVAS encoder failed: %s\n", IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; } #else if ( ( error = IVAS_ENC_Open( &hIvasEnc ) ) != IVAS_ERR_OK ) diff --git a/apps/renderer.c b/apps/renderer.c index dc4091ece..5f39dc4e6 100644 --- a/apps/renderer.c +++ b/apps/renderer.c @@ -65,8 +65,8 @@ #define IVAS_MAX16B_FLT 32767.0f #define IVAS_MIN16B_FLT ( -32768.0f ) -#define IVAS_MAX16B_FX 32767 -#define IVAS_MIN16B_FX ( -32768 ) +#define IVAS_MAX16B_FX 32767 +#define IVAS_MIN16B_FX ( -32768 ) #if !defined( WMOPS ) static #endif @@ -165,7 +165,7 @@ typedef struct bool sceneDescriptionInput; float inputGainGlobal; /* Linear gain (not in dB) */ bool lfePanningEnabled; - float lfeConfigGain; /* Linear gain (not in dB) */ + float lfeConfigGain; /* Linear gain (not in dB) */ float lfeConfigAzimuth; float lfeConfigElevation; bool lfeCustomRoutingEnabled; @@ -409,8 +409,8 @@ static void convertInputBuffer( const int16_t *intBuffer, const int16_t numIntSa static void convertOutputBuffer( const float *floatBuffer, const int16_t numSamplesPerChannel, const int16_t numChannels, int16_t *intBuffer ); #ifdef IVAS_FLOAT_FIXED -static void convertOutputBuffer_fx( const Word32 *Word32Buffer, const Word16 numSamplesPerChannel, const Word16 numChannels, Word16 *intBuffer,Word16 q_factor ); -static void convertInputBuffer_fx( const Word16 *intBuffer, const Word16 numIntSamplesPerChannel, const Word16 numFloatSamplesPerChannel, const Word16 numChannels, Word32 *Int32Buffer,Word16 in_q_factor ); +static void convertOutputBuffer_fx( const Word32 *Word32Buffer, const Word16 numSamplesPerChannel, const Word16 numChannels, Word16 *intBuffer, Word16 q_factor ); +static void convertInputBuffer_fx( const Word16 *intBuffer, const Word16 numIntSamplesPerChannel, const Word16 numFloatSamplesPerChannel, const Word16 numChannels, Word32 *Int32Buffer, Word16 in_q_factor ); #endif @@ -831,14 +831,15 @@ int main( const int16_t frameSize_smpls = (int16_t) ( ( args.render_framesize ) * args.sampleRate * 5 / ( 1000 ) ); #ifdef IVAS_FLOAT_FIXED - Word32 nonDiegeticPanGain_fx = (args.nonDiegeticPanGain ==1.0f)? ONE_IN_Q31: (args.nonDiegeticPanGain == -1.0f)? L_negate(ONE_IN_Q31):(Word32)(args.nonDiegeticPanGain*(1LL<< Q31 )); + Word32 nonDiegeticPanGain_fx = ( args.nonDiegeticPanGain == 1.0f ) ? ONE_IN_Q31 : ( args.nonDiegeticPanGain == -1.0f ) ? L_negate( ONE_IN_Q31 ) + : (Word32) ( args.nonDiegeticPanGain * ( 1LL << Q31 ) ); IF( ( error = IVAS_REND_Open( &hIvasRend, args.sampleRate, args.outConfig.audioConfig, args.nonDiegeticPan, nonDiegeticPanGain_fx, (int16_t) args.render_framesize ) ) != IVAS_ERR_OK ) { fprintf( stderr, "Error opening renderer handle: %s\n", ivas_error_to_string( error ) ); exit( -1 ); } #else - IF ( ( error = IVAS_REND_Open( &hIvasRend, args.sampleRate, args.outConfig.audioConfig, args.nonDiegeticPan, args.nonDiegeticPanGain, (int16_t) args.render_framesize ) ) != IVAS_ERR_OK ) + IF( ( error = IVAS_REND_Open( &hIvasRend, args.sampleRate, args.outConfig.audioConfig, args.nonDiegeticPan, args.nonDiegeticPanGain, (int16_t) args.render_framesize ) ) != IVAS_ERR_OK ) { fprintf( stderr, "Error opening renderer handle: %s\n", ivas_error_to_string( error ) ); exit( -1 ); @@ -938,11 +939,11 @@ int main( exit( -1 ); } #ifdef IVAS_FLOAT_FIXED - Word32 var1 = (Word32)(args.syncMdDelay); - IF((error = IVAS_REND_SetIsmMetadataDelay(hIvasRend, var1)) != IVAS_ERR_OK) + Word32 var1 = (Word32) ( args.syncMdDelay ); + IF( ( error = IVAS_REND_SetIsmMetadataDelay( hIvasRend, var1 ) ) != IVAS_ERR_OK ) { - fprintf(stderr, "Error in IVAS_REND_SetIsmMetadataDelay(): %s\n", ivas_error_to_string(error)); - exit(-1); + fprintf( stderr, "Error in IVAS_REND_SetIsmMetadataDelay(): %s\n", ivas_error_to_string( error ) ); + exit( -1 ); } #else if ( ( error = IVAS_REND_SetIsmMetadataDelay( hIvasRend, args.syncMdDelay ) ) != IVAS_ERR_OK ) @@ -998,7 +999,7 @@ int main( exit( -1 ); } - if ((error = IVAS_REND_SetInputGain(hIvasRend, mcIds[i], args.inputGainGlobal * dBToLin(args.inConfig.multiChannelBuses[i].gain_dB))) != IVAS_ERR_OK) + if ( ( error = IVAS_REND_SetInputGain( hIvasRend, mcIds[i], args.inputGainGlobal * dBToLin( args.inConfig.multiChannelBuses[i].gain_dB ) ) ) != IVAS_ERR_OK ) { fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) ); exit( -1 ); @@ -1012,7 +1013,7 @@ int main( gain_fx = (Word32) ( ( args.inputGainGlobal * dBToLin( args.inConfig.multiChannelBuses[i].gain_dB ) ) * ( 1u << 30 ) ); - IF ((error = IVAS_REND_SetInputGain_fx(hIvasRend, mcIds[i], gain_fx)) != IVAS_ERR_OK) + IF( ( error = IVAS_REND_SetInputGain_fx( hIvasRend, mcIds[i], gain_fx ) ) != IVAS_ERR_OK ) { fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) ); exit( -1 ); @@ -1043,7 +1044,7 @@ int main( ( *lfePanMatrix_fx )[k] = (Word32) ( ( *lfePanMatrix )[k] * ( 1u << 31 ) ); } - IF ( ( error = IVAS_REND_SetInputLfeMtx_fx( hIvasRend, mcIds[i], (const IVAS_REND_LfePanMtx_fx *) &lfePanMatrix_fx ) ) != IVAS_ERR_OK ) + IF( ( error = IVAS_REND_SetInputLfeMtx_fx( hIvasRend, mcIds[i], (const IVAS_REND_LfePanMtx_fx *) &lfePanMatrix_fx ) ) != IVAS_ERR_OK ) #else if ( ( error = IVAS_REND_SetInputLfeMtx( hIvasRend, mcIds[i], (const IVAS_REND_LfePanMtx *) &lfePanMatrix ) ) != IVAS_ERR_OK ) #endif // IVAS_FLOAT_FIXED @@ -1165,7 +1166,7 @@ int main( } } #else - FOR ( i = 0; i < args.inConfig.numAudioObjects; ++i ) + FOR( i = 0; i < args.inConfig.numAudioObjects; ++i ) { IF( ( error = IVAS_REND_AddInput_fx( hIvasRend, IVAS_AUDIO_CONFIG_OBA, &ismIds[i] ) ) != IVAS_ERR_OK ) { @@ -1174,20 +1175,20 @@ int main( } gain_fx = (Word32) ( args.inputGainGlobal * dBToLin( args.inConfig.audioObjects[i].gain_dB ) * ( 1u << 30 ) ); - IF( ( error = IVAS_REND_SetInputGain_fx( hIvasRend, ismIds[i], gain_fx) ) != IVAS_ERR_OK ) + IF( ( error = IVAS_REND_SetInputGain_fx( hIvasRend, ismIds[i], gain_fx ) ) != IVAS_ERR_OK ) { fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) ); exit( -1 ); } /* With MASA output, all objects are handled at once, so add only one input having all objects in it */ - IF ( EQ_32(args.outConfig.audioConfig, IVAS_AUDIO_CONFIG_MASA1) || EQ_32(args.outConfig.audioConfig, IVAS_AUDIO_CONFIG_MASA2) ) + IF( EQ_32( args.outConfig.audioConfig, IVAS_AUDIO_CONFIG_MASA1 ) || EQ_32( args.outConfig.audioConfig, IVAS_AUDIO_CONFIG_MASA2 ) ) { BREAK; } } - FOR ( i = 0; i < args.inConfig.numAmbisonicsBuses; ++i ) + FOR( i = 0; i < args.inConfig.numAmbisonicsBuses; ++i ) { IF( ( error = IVAS_REND_AddInput_fx( hIvasRend, args.inConfig.ambisonicsBuses[i].audioConfig, &sbaIds[i] ) ) != IVAS_ERR_OK ) { @@ -1196,14 +1197,14 @@ int main( } gain_fx = (Word32) ( args.inputGainGlobal * dBToLin( args.inConfig.ambisonicsBuses[i].gain_dB ) * ( 1u << 30 ) ); - IF ( ( error = IVAS_REND_SetInputGain_fx( hIvasRend, sbaIds[i], gain_fx ) ) != IVAS_ERR_OK ) + IF( ( error = IVAS_REND_SetInputGain_fx( hIvasRend, sbaIds[i], gain_fx ) ) != IVAS_ERR_OK ) { fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) ); exit( -1 ); } } - FOR ( i = 0; i < args.inConfig.numMasaBuses; ++i ) + FOR( i = 0; i < args.inConfig.numMasaBuses; ++i ) { IF( ( error = IVAS_REND_AddInput_fx( hIvasRend, args.inConfig.masaBuses[i].audioConfig, &masaIds[i] ) ) != IVAS_ERR_OK ) { @@ -1212,7 +1213,7 @@ int main( } gain_fx = (Word32) ( ( args.inputGainGlobal * dBToLin( args.inConfig.masaBuses[i].gain_dB ) ) * ( 1u << 30 ) ); - IF ( ( error = IVAS_REND_SetInputGain_fx( hIvasRend, masaIds[i], gain_fx) ) != IVAS_ERR_OK ) + IF( ( error = IVAS_REND_SetInputGain_fx( hIvasRend, masaIds[i], gain_fx ) ) != IVAS_ERR_OK ) { fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) ); exit( -1 ); @@ -1316,7 +1317,7 @@ int main( /* Convert from int to float and from interleaved to packed */ convertInputBuffer( inpInt16Buffer, numSamplesRead, inBuffer.config.numSamplesPerChannel, num_in_channels, inFloatBuffer ); #ifdef IVAS_FLOAT_FIXED - *outBuffer.pq_fact = 16 - ( gd_bits); + *outBuffer.pq_fact = 16 - ( gd_bits ); convertInputBuffer_fx( inpInt16Buffer, numSamplesRead, inBuffer.config.numSamplesPerChannel, num_in_channels, inInt32Buffer, *outBuffer.pq_fact ); #endif int16_t num_subframes, sf_idx; @@ -1443,7 +1444,6 @@ int main( fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) ); exit( -1 ); } - } for ( i = 0; i < args.inConfig.numAudioObjects; ++i ) @@ -1478,7 +1478,7 @@ int main( #else if ( ( error = IVAS_REND_FeedInputAudio( hIvasRend, ismIds[i], tmpBuffer ) ) != IVAS_ERR_OK ) #endif - { + { fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) ); exit( -1 ); } @@ -2559,11 +2559,11 @@ void getMetadataFromFileReader( exit( -1 ); } #ifdef IVAS_FLOAT_FIXED - objectMetadataBuffer->positions[objIdx].azimuth_fx = (Word32)(ismMetadata.azimuth * (1<<22)); - objectMetadataBuffer->positions[objIdx].elevation_fx = (Word32)(ismMetadata.elevation * (1 << 22)); - objectMetadataBuffer->positions[objIdx].radius_fx = (Word16)(ismMetadata.radius * (1 << 9)); - objectMetadataBuffer->positions[objIdx].yaw_fx = (Word32)(ismMetadata.yaw * (1 << 22)); - objectMetadataBuffer->positions[objIdx].pitch_fx = (Word32)(ismMetadata.pitch * (1 << 22)); + objectMetadataBuffer->positions[objIdx].azimuth_fx = (Word32) ( ismMetadata.azimuth * ( 1 << 22 ) ); + objectMetadataBuffer->positions[objIdx].elevation_fx = (Word32) ( ismMetadata.elevation * ( 1 << 22 ) ); + objectMetadataBuffer->positions[objIdx].radius_fx = (Word16) ( ismMetadata.radius * ( 1 << 9 ) ); + objectMetadataBuffer->positions[objIdx].yaw_fx = (Word32) ( ismMetadata.yaw * ( 1 << 22 ) ); + objectMetadataBuffer->positions[objIdx].pitch_fx = (Word32) ( ismMetadata.pitch * ( 1 << 22 ) ); #endif // DEBUG objectMetadataBuffer->positions[objIdx].azimuth = ismMetadata.azimuth; @@ -2652,8 +2652,8 @@ static void IsmPositionProvider_getNextFrame( /* Clamp elevation to lie within [-90, 90] range (can't be wrapped easily) */ objectMetadataBuffer->positions[objIdx].elevation = min( max( objectMetadataBuffer->positions[objIdx].elevation, -90 ), 90 ); #ifdef IVAS_FLOAT_FIXED - objectMetadataBuffer->positions[objIdx].azimuth_fx = (Word32)(objectMetadataBuffer->positions[objIdx].azimuth * (1 << 22)); - objectMetadataBuffer->positions[objIdx].elevation_fx = (Word32)(objectMetadataBuffer->positions[objIdx].elevation * (1 << 22)); + objectMetadataBuffer->positions[objIdx].azimuth_fx = (Word32) ( objectMetadataBuffer->positions[objIdx].azimuth * ( 1 << 22 ) ); + objectMetadataBuffer->positions[objIdx].elevation_fx = (Word32) ( objectMetadataBuffer->positions[objIdx].elevation * ( 1 << 22 ) ); #endif // IVAS_FLOAT_FIXED /* Wrap yaw to lie within (-180, 180] range */ while ( objectMetadataBuffer->positions[objIdx].yaw < 0.0f ) @@ -2668,8 +2668,8 @@ static void IsmPositionProvider_getNextFrame( /* Clamp pitch to lie within [-90, 90] range (can't be wrapped easily) */ objectMetadataBuffer->positions[objIdx].pitch = min( max( objectMetadataBuffer->positions[objIdx].pitch, -90 ), 90 ); #ifdef IVAS_FLOAT_FIXED - objectMetadataBuffer->positions[objIdx].yaw_fx = (Word32)objectMetadataBuffer->positions[objIdx].yaw * (1 << Q22); - objectMetadataBuffer->positions[objIdx].pitch_fx = (Word32)objectMetadataBuffer->positions[objIdx].pitch * (1 << Q22); + objectMetadataBuffer->positions[objIdx].yaw_fx = (Word32) objectMetadataBuffer->positions[objIdx].yaw * ( 1 << Q22 ); + objectMetadataBuffer->positions[objIdx].pitch_fx = (Word32) objectMetadataBuffer->positions[objIdx].pitch * ( 1 << Q22 ); #endif } @@ -2978,8 +2978,8 @@ static void parseObjectPosition( position->azimuth = meta_prm[0]; position->elevation = meta_prm[1]; #ifdef IVAS_FLOAT_FIXED - position->azimuth_fx = (Word32)(meta_prm[0] * (1 << 22)); - position->elevation_fx = (Word32)(meta_prm[1] * (1 << 22)); + position->azimuth_fx = (Word32) ( meta_prm[0] * ( 1 << 22 ) ); + position->elevation_fx = (Word32) ( meta_prm[1] * ( 1 << 22 ) ); #endif // IVAS_FLOAT_FIXED position->radius = meta_prm[2]; position->yaw = meta_prm[5]; @@ -3520,17 +3520,17 @@ static void convertInputBuffer_fx( const Word16 numFloatSamplesPerChannel, const Word16 numChannels, Word32 *Word32Buffer, - Word16 in_q_factor) + Word16 in_q_factor ) { Word16 chnl, smpl, i; i = 0; - FOR ( smpl = 0; smpl < numFloatSamplesPerChannel; ++smpl ) + FOR( smpl = 0; smpl < numFloatSamplesPerChannel; ++smpl ) { - FOR ( chnl = 0; chnl < numChannels; ++chnl ) + FOR( chnl = 0; chnl < numChannels; ++chnl ) { - IF ( i < numIntSamplesPerChannel ) + IF( i < numIntSamplesPerChannel ) { Word32Buffer[chnl * numFloatSamplesPerChannel + smpl] = L_shl( (Word32) intBuffer[i], in_q_factor ); } @@ -3563,17 +3563,17 @@ static void convertOutputBuffer_fx( Word32 temp_fx1; i = 0; - FOR ( smpl = 0; smpl < numSamplesPerChannel; ++smpl ) + FOR( smpl = 0; smpl < numSamplesPerChannel; ++smpl ) { - FOR ( chnl = 0; chnl < numChannels; ++chnl ) + FOR( chnl = 0; chnl < numChannels; ++chnl ) { temp_fx = L_add( Word32Buffer[chnl * numSamplesPerChannel + smpl], lshl( 1, ( out_q - 1 ) ) ); - temp_fx1 = L_shr(temp_fx , out_q); - IF (GT_32( temp_fx1, IVAS_MAX16B_FX )) + temp_fx1 = L_shr( temp_fx, out_q ); + IF( GT_32( temp_fx1, IVAS_MAX16B_FX ) ) { temp_fx1 = IVAS_MAX16B_FX; } - ELSE IF ( LT_32(temp_fx1 , IVAS_MIN16B_FX )) + ELSE IF( LT_32( temp_fx1, IVAS_MIN16B_FX ) ) { temp_fx1 = IVAS_MIN16B_FX; } diff --git a/lib_com/ACcontextMapping_fx.c b/lib_com/ACcontextMapping_fx.c index 4aec73347..6cf368a46 100644 --- a/lib_com/ACcontextMapping_fx.c +++ b/lib_com/ACcontextMapping_fx.c @@ -20,13 +20,13 @@ Word16 get_next_coeff_mapped( { Word16 p; - p = s_and(sub(ii[1], hm_cfg->numPeakIndices), sub(hm_cfg->indexBuffer[ii[1]], hm_cfg->indexBuffer[ii[0]])); - if (p > 0) + p = s_and( sub( ii[1], hm_cfg->numPeakIndices ), sub( hm_cfg->indexBuffer[ii[1]], hm_cfg->indexBuffer[ii[0]] ) ); + if ( p > 0 ) { p = 0; move16(); } - if (p < 0) + if ( p < 0 ) { p = 1; move16(); @@ -35,7 +35,7 @@ Word16 get_next_coeff_mapped( move16(); *idx = ii[p]; move16(); - ii[p] = add(ii[p], 1); + ii[p] = add( ii[p], 1 ); move16(); return hm_cfg->indexBuffer[*idx]; } @@ -48,31 +48,30 @@ Word16 get_next_coeff_unmapped( CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ ) { - (void)pp; - (void)hm_cfg; + (void) pp; + (void) hm_cfg; *idx = ii[0]; move16(); - ii[0] = add(ii[0], 1); + ii[0] = add( ii[0], 1 ); move16(); return *idx; } -Word16 update_mixed_context(Word16 ctx, Word16 a) +Word16 update_mixed_context( Word16 ctx, Word16 a ) { Word32 t32; - Word16 t=0; /* initialize just to avoid compiler warning */ + Word16 t = 0; /* initialize just to avoid compiler warning */ - t32 = L_mac0(1-13, s_and(a, ~1), add(shr(a, 2), 1)); - if (t32 <= 0) + t32 = L_mac0( 1 - 13, s_and( a, ~1 ), add( shr( a, 2 ), 1 ) ); + if ( t32 <= 0 ) { - t = extract_l(t32); + t = extract_l( t32 ); } - a = shr(a, 3); - if (t32 > 0) + a = shr( a, 3 ); + if ( t32 > 0 ) { - t = s_min(a, 2); + t = s_min( a, 2 ); } - return add(shl(s_and(ctx, 0xf), 4), add(t, 13)); + return add( shl( s_and( ctx, 0xf ), 4 ), add( t, 13 ) ); } - diff --git a/lib_com/ari_fx.c b/lib_com/ari_fx.c index d8c17c7e7..a16885a62 100644 --- a/lib_com/ari_fx.c +++ b/lib_com/ari_fx.c @@ -18,12 +18,12 @@ * * \return x*y */ -Word32 L_multi31x16_X2(Word16 xh, Word16 xl, Word16 y) +Word32 L_multi31x16_X2( Word16 xh, Word16 xl, Word16 y ) { Word32 z; - z = L_shl(L_mult0(xh,y),15); - z = L_mac0(z,xl,y); + z = L_shl( L_mult0( xh, y ), 15 ); + z = L_mac0( z, xl, y ); return z; } @@ -40,7 +40,7 @@ Word32 L_multi31x16_X2(Word16 xh, Word16 xl, Word16 y) * * \return r*c */ -Word32 mul_sbc_14bits(Word32 r, Word16 c) +Word32 mul_sbc_14bits( Word32 r, Word16 c ) { Word32 ret; @@ -48,10 +48,10 @@ Word32 mul_sbc_14bits(Word32 r, Word16 c) /* temp = (((int32) r)*((int32) c))>>stat_bitsnew; */ - assert(stat_bitsnew == 14); - ret = Mpy_32_16_1(L_shl(r,15-stat_bitsnew), c); + assert( stat_bitsnew == 14 ); + ret = Mpy_32_16_1( L_shl( r, 15 - stat_bitsnew ), c ); /*assert( (((int) r)*((int) c))>>stat_bitsnew == ret);*/ - return (ret); + return ( ret ); } diff --git a/lib_com/ari_hm.c b/lib_com/ari_hm.c index be2fc2568..a072974d9 100644 --- a/lib_com/ari_hm.c +++ b/lib_com/ari_hm.c @@ -102,65 +102,66 @@ void UnmapIndex_ivas( void UnmapIndex_fx( const Word16 PeriodicityIndex, - const Word16 Bandwidth, + const Word16 Bandwidth, const Word16 LtpPitchLag, - const Word8 SmallerLags, + const Word8 SmallerLags, Word16 *FractionalResolution, - Word32 *Lag -) + Word32 *Lag ) { Word16 LtpPitchIndex, Multiplier; Word16 Lag16; test(); - IF ((LtpPitchLag > 0) && (s_and(PeriodicityIndex, kLtpHmFlag) != 0)) + IF( ( LtpPitchLag > 0 ) && ( s_and( PeriodicityIndex, kLtpHmFlag ) != 0 ) ) { - LtpPitchIndex = shr(PeriodicityIndex, 9); - Multiplier = s_and(PeriodicityIndex, 0xff); + LtpPitchIndex = shr( PeriodicityIndex, 9 ); + Multiplier = s_and( PeriodicityIndex, 0xff ); - assert(0 <= LtpPitchIndex && LtpPitchIndex <= 16); - assert(1 <= Multiplier && Multiplier <= (1 << NumRatioBits[Bandwidth][LtpPitchIndex])); + assert( 0 <= LtpPitchIndex && LtpPitchIndex <= 16 ); + assert( 1 <= Multiplier && Multiplier <= ( 1 << NumRatioBits[Bandwidth][LtpPitchIndex] ) ); *FractionalResolution = kLtpHmFractionalResolution; move16(); - *Lag = L_shr(L_mult0(LtpPitchLag, Ratios_fx[Bandwidth][LtpPitchIndex][Multiplier-1]), 8); + *Lag = L_shr( L_mult0( LtpPitchLag, Ratios_fx[Bandwidth][LtpPitchIndex][Multiplier - 1] ), 8 ); move32(); } ELSE { - IF (LT_16(PeriodicityIndex, 16)) + IF( LT_16( PeriodicityIndex, 16 ) ) { *FractionalResolution = 3; move16(); - Lag16 = add(PeriodicityIndex, GET_ADJ2(0, 6, 3)); + Lag16 = add( PeriodicityIndex, GET_ADJ2( 0, 6, 3 ) ); } - ELSE IF (LT_16(PeriodicityIndex, 80)) + ELSE IF( LT_16( PeriodicityIndex, 80 ) ) { *FractionalResolution = 4; move16(); - Lag16 = add(PeriodicityIndex, GET_ADJ2(16, 8, 4)); + Lag16 = add( PeriodicityIndex, GET_ADJ2( 16, 8, 4 ) ); } - ELSE IF (LT_16(PeriodicityIndex, 208)) + ELSE IF( LT_16( PeriodicityIndex, 208 ) ) { *FractionalResolution = 3; move16(); - Lag16 = add(PeriodicityIndex, GET_ADJ2(80, 12, 3)); + Lag16 = add( PeriodicityIndex, GET_ADJ2( 80, 12, 3 ) ); } - ELSE { + ELSE + { test(); - IF (LT_16(PeriodicityIndex, 224)||SmallerLags!=0) + IF( LT_16( PeriodicityIndex, 224 ) || SmallerLags != 0 ) { *FractionalResolution = 1; move16(); - Lag16 = add(PeriodicityIndex, GET_ADJ2(208, 28, 1)); + Lag16 = add( PeriodicityIndex, GET_ADJ2( 208, 28, 1 ) ); } - ELSE { + ELSE + { *FractionalResolution = 0; move16(); - Lag16 = add(PeriodicityIndex, GET_ADJ2(224, 188, 0)); + Lag16 = add( PeriodicityIndex, GET_ADJ2( 224, 188, 0 ) ); } } - *Lag = L_deposit_l(Lag16); + *Lag = L_deposit_l( Lag16 ); } } @@ -262,17 +263,16 @@ int16_t CountIndexBits_ivas( Word16 CountIndexBits_fx( Word16 Bandwidth, - Word16 PeriodicityIndex -) + Word16 PeriodicityIndex ) { Word16 result; Word16 PeriodicityIndexS; result = 8; move16(); - PeriodicityIndexS = shr(PeriodicityIndex, 9); + PeriodicityIndexS = shr( PeriodicityIndex, 9 ); - if (s_and(PeriodicityIndex, kLtpHmFlag) != 0) + if ( s_and( PeriodicityIndex, kLtpHmFlag ) != 0 ) { result = NumRatioBits[Bandwidth][PeriodicityIndexS]; move16(); @@ -352,45 +352,45 @@ Word32 tcx_hm_render_fx( Word32 f0, tmp32; /* Set up overall shape */ - f0 = L_shl(lag, sub(15, fract_res)); /* Q31 */ + f0 = L_shl( lag, sub( 15, fract_res ) ); /* Q31 */ - tmp32 = Mpy_32_16_1(f0, -26474); - tmp32 = L_shr_r(BASOP_Util_InvLog2(L_shl(tmp32, 7)), 2); - tmp32 = L_sub(603979776L, tmp32); - tmp32 = L_add(L_add(tmp32, tmp32), Mpy_32_16_1(tmp32, 26214)); - height = round_fx(tmp32); /* Q13 */ + tmp32 = Mpy_32_16_1( f0, -26474 ); + tmp32 = L_shr_r( BASOP_Util_InvLog2( L_shl( tmp32, 7 ) ), 2 ); + tmp32 = L_sub( 603979776L, tmp32 ); + tmp32 = L_add( L_add( tmp32, tmp32 ), Mpy_32_16_1( tmp32, 26214 ) ); + height = round_fx( tmp32 ); /* Q13 */ - tmp32 = Mpy_32_16_1(f0, -18910); - tmp32 = L_shr_r(BASOP_Util_InvLog2(L_shl(tmp32, 7)), 2); - tmp32 = L_sub(1395864371L, tmp32); - PeakDeviation = round_fx(tmp32); /* Q14 */ + tmp32 = Mpy_32_16_1( f0, -18910 ); + tmp32 = L_shr_r( BASOP_Util_InvLog2( L_shl( tmp32, 7 ) ), 2 ); + tmp32 = L_sub( 1395864371L, tmp32 ); + PeakDeviation = round_fx( tmp32 ); /* Q14 */ - IF( GT_16(13915,PeakDeviation)) + IF( GT_16( 13915, PeakDeviation ) ) { /* A bit error was encountered */ return 1; } ELSE { - tmp = div_s(13915, PeakDeviation); - tmp = mult_r(tmp, tmp); /* Q15 */ + tmp = div_s( 13915, PeakDeviation ); + tmp = mult_r( tmp, tmp ); /* Q15 */ } - tmp = div_s(13915, PeakDeviation); - tmp = mult_r(tmp, tmp); /* Q15 */ + tmp = div_s( 13915, PeakDeviation ); + tmp = mult_r( tmp, tmp ); /* Q15 */ /* Render the prototype peak */ p[kTcxHmParabolaHalfWidth] = height; move16(); - FOR (k=1; k<=kTcxHmParabolaHalfWidth; ++k) + FOR( k = 1; k <= kTcxHmParabolaHalfWidth; ++k ) { - p[kTcxHmParabolaHalfWidth+k] = round_fx(Mpy_32_16_1(BASOP_Util_InvLog2(L_shl(L_mult0(i_mult2(negate(k),k), tmp),10)), height)); + p[kTcxHmParabolaHalfWidth + k] = round_fx( Mpy_32_16_1( BASOP_Util_InvLog2( L_shl( L_mult0( i_mult2( negate( k ), k ), tmp ), 10 ) ), height ) ); } /* Mirror */ - FOR (k=-kTcxHmParabolaHalfWidth; k<0; ++k) + FOR( k = -kTcxHmParabolaHalfWidth; k < 0; ++k ) { - p[kTcxHmParabolaHalfWidth+k] = p[kTcxHmParabolaHalfWidth-k]; + p[kTcxHmParabolaHalfWidth + k] = p[kTcxHmParabolaHalfWidth - k]; move16(); } @@ -451,42 +451,41 @@ void tcx_hm_modify_envelope_fx( const Word16 L_frame /* i: number of spectral lines Q0 */ ) { - Word16 k, h, x, l1,l2, L_frame_m1, L_frame_for_loop; - Word16 inv_shape[2*kTcxHmParabolaHalfWidth+1]; + Word16 k, h, x, l1, l2, L_frame_m1, L_frame_for_loop; + Word16 inv_shape[2 * kTcxHmParabolaHalfWidth + 1]; - IF ( gain == 0 ) + IF( gain == 0 ) { return; } - FOR (k=0; k<2*kTcxHmParabolaHalfWidth+1; ++k) + FOR( k = 0; k < 2 * kTcxHmParabolaHalfWidth + 1; ++k ) { /* Q24 = Q11 * Q13; 512 = 1.0 in Q24 format */ - inv_shape[k] = div_s(512, add(512, mult_r(gain, p[k]))); + inv_shape[k] = div_s( 512, add( 512, mult_r( gain, p[k] ) ) ); move16(); } h = 1; move16(); - k = extract_l(L_shr(lag,fract_res)); + k = extract_l( L_shr( lag, fract_res ) ); - L_frame_m1 = sub(L_frame,1); - L_frame_for_loop = add(L_frame,kTcxHmParabolaHalfWidth - 1); + L_frame_m1 = sub( L_frame, 1 ); + L_frame_for_loop = add( L_frame, kTcxHmParabolaHalfWidth - 1 ); - WHILE ( LE_16(k,L_frame_for_loop)) + WHILE( LE_16( k, L_frame_for_loop ) ) { - l1 = s_max(0, sub(k,kTcxHmParabolaHalfWidth)); - l2 = s_min(add(k,kTcxHmParabolaHalfWidth), L_frame_m1); - FOR (x=l1; x<=l2; ++x) + l1 = s_max( 0, sub( k, kTcxHmParabolaHalfWidth ) ); + l2 = s_min( add( k, kTcxHmParabolaHalfWidth ), L_frame_m1 ); + FOR( x = l1; x <= l2; ++x ) { - env[x] = Mpy_32_16_1(env[x], inv_shape[x-k+kTcxHmParabolaHalfWidth]); + env[x] = Mpy_32_16_1( env[x], inv_shape[x - k + kTcxHmParabolaHalfWidth] ); move32(); } - h = add(h,1); - k = extract_l(L_shr(imult3216(lag,h),fract_res)); + h = add( h, 1 ); + k = extract_l( L_shr( imult3216( lag, h ), fract_res ) ); } - } diff --git a/lib_com/ari_hm_fx.c b/lib_com/ari_hm_fx.c index 10dce353a..e7032468b 100644 --- a/lib_com/ari_hm_fx.c +++ b/lib_com/ari_hm_fx.c @@ -12,89 +12,90 @@ #include "prot_fx1.h" #include "prot_fx2.h" -#define GET_ADJ2(T,L,F) (((L) << (F)) - (T)) +#define GET_ADJ2( T, L, F ) ( ( ( L ) << ( F ) ) - ( T ) ) void UnmapIndex( const Word16 PeriodicityIndex, - const Word16 Bandwidth, + const Word16 Bandwidth, const Word16 LtpPitchLag, - const Word16 SmallerLags, + const Word16 SmallerLags, Word16 *FractionalResolution, - Word32 *Lag -) + Word32 *Lag ) { Word16 LtpPitchIndex, Multiplier; Word16 Lag16; test(); - IF ((LtpPitchLag > 0) && (s_and(PeriodicityIndex, kLtpHmFlag) != 0)) + IF( ( LtpPitchLag > 0 ) && ( s_and( PeriodicityIndex, kLtpHmFlag ) != 0 ) ) { - LtpPitchIndex = shr(PeriodicityIndex, 9); - Multiplier = s_and(PeriodicityIndex, 0xff); + LtpPitchIndex = shr( PeriodicityIndex, 9 ); + Multiplier = s_and( PeriodicityIndex, 0xff ); - assert(0 <= LtpPitchIndex && LtpPitchIndex <= 16); - assert(1 <= Multiplier && Multiplier <= (1 << NumRatioBits[Bandwidth][LtpPitchIndex])); + assert( 0 <= LtpPitchIndex && LtpPitchIndex <= 16 ); + assert( 1 <= Multiplier && Multiplier <= ( 1 << NumRatioBits[Bandwidth][LtpPitchIndex] ) ); *FractionalResolution = kLtpHmFractionalResolution; move16(); - *Lag = L_shr(L_mult0(LtpPitchLag, Ratios_fx[Bandwidth][LtpPitchIndex][Multiplier-1]), 8); + *Lag = L_shr( L_mult0( LtpPitchLag, Ratios_fx[Bandwidth][LtpPitchIndex][Multiplier - 1] ), 8 ); move32(); } ELSE { - IF (LT_16(PeriodicityIndex, 16)) + IF( LT_16( PeriodicityIndex, 16 ) ) { *FractionalResolution = 3; move16(); - Lag16 = add(PeriodicityIndex, GET_ADJ2(0, 6, 3)); + Lag16 = add( PeriodicityIndex, GET_ADJ2( 0, 6, 3 ) ); } - ELSE IF (LT_16(PeriodicityIndex, 80)) + ELSE IF( LT_16( PeriodicityIndex, 80 ) ) { *FractionalResolution = 4; move16(); - Lag16 = add(PeriodicityIndex, GET_ADJ2(16, 8, 4)); + Lag16 = add( PeriodicityIndex, GET_ADJ2( 16, 8, 4 ) ); } - ELSE IF (LT_16(PeriodicityIndex, 208)) + ELSE IF( LT_16( PeriodicityIndex, 208 ) ) { *FractionalResolution = 3; move16(); - Lag16 = add(PeriodicityIndex, GET_ADJ2(80, 12, 3)); + Lag16 = add( PeriodicityIndex, GET_ADJ2( 80, 12, 3 ) ); } - ELSE { + ELSE + { test(); - IF (LT_16(PeriodicityIndex, 224)||SmallerLags!=0) + IF( LT_16( PeriodicityIndex, 224 ) || SmallerLags != 0 ) { *FractionalResolution = 1; move16(); - Lag16 = add(PeriodicityIndex, GET_ADJ2(208, 28, 1)); + Lag16 = add( PeriodicityIndex, GET_ADJ2( 208, 28, 1 ) ); } - ELSE { + ELSE + { *FractionalResolution = 0; move16(); - Lag16 = add(PeriodicityIndex, GET_ADJ2(224, 188, 0)); + Lag16 = add( PeriodicityIndex, GET_ADJ2( 224, 188, 0 ) ); } } - *Lag = L_deposit_l(Lag16); + *Lag = L_deposit_l( Lag16 ); } } void ConfigureContextHm( - const Word16 NumCoeffs, /* (I) Number of coefficients */ - const Word16 TargetBits, /* (I) Target bit budget (excl. Done flag) */ - const Word16 PeriodicityIndex, /* (I) Pitch related index */ - const Word16 LtpPitchLag, /* (I) TCX-LTP pitch in F.D. */ - CONTEXT_HM_CONFIG *hm_cfg /* (O) Context-based harmonic model configuration */ + const Word16 NumCoeffs, /* (I) Number of coefficients */ + const Word16 TargetBits, /* (I) Target bit budget (excl. Done flag) */ + const Word16 PeriodicityIndex, /* (I) Pitch related index */ + const Word16 LtpPitchLag, /* (I) TCX-LTP pitch in F.D. */ + CONTEXT_HM_CONFIG *hm_cfg /* (O) Context-based harmonic model configuration */ ) { - Word8 Bandwidth, SmallerLags; - Word32 i, Limit, Lag; - Word16 j, Index, FractionalResolution; - Word16 *tmp; + Word8 Bandwidth, SmallerLags; + Word32 i, Limit, Lag; + Word16 j, Index, FractionalResolution; + Word16 *tmp; Bandwidth = 0; move16(); - IF (GE_16(NumCoeffs, 256)) + IF( GE_16( NumCoeffs, 256 ) ) { Bandwidth = 1; move16(); @@ -103,81 +104,79 @@ void ConfigureContextHm( SmallerLags = 0; move16(); test(); - IF ((LE_16(TargetBits, kSmallerLagsTargetBitsThreshold))||(Bandwidth==0)) + IF( ( LE_16( TargetBits, kSmallerLagsTargetBitsThreshold ) ) || ( Bandwidth == 0 ) ) { SmallerLags = 1; move16(); } - UnmapIndex(PeriodicityIndex, - Bandwidth, - LtpPitchLag, - SmallerLags, - &FractionalResolution, &Lag); + UnmapIndex( PeriodicityIndex, + Bandwidth, + LtpPitchLag, + SmallerLags, + &FractionalResolution, &Lag ); /* Set up and fill peakIndices */ hm_cfg->peakIndices = hm_cfg->indexBuffer; tmp = hm_cfg->peakIndices; - Limit = L_shl(L_deposit_l(sub(NumCoeffs, 1)), FractionalResolution); - IF (LT_32(Lag, Limit)) + Limit = L_shl( L_deposit_l( sub( NumCoeffs, 1 ) ), FractionalResolution ); + IF( LT_32( Lag, Limit ) ) { - FOR (i=Lag; inumPeakIndices = (Word16)(tmp - hm_cfg->indexBuffer); + hm_cfg->numPeakIndices = (Word16) ( tmp - hm_cfg->indexBuffer ); /* Set up and fill holeIndices */ hm_cfg->holeIndices = hm_cfg->indexBuffer + hm_cfg->numPeakIndices; tmp = hm_cfg->holeIndices; Index = 0; move16(); - IF (hm_cfg->numPeakIndices > 0) + IF( hm_cfg->numPeakIndices > 0 ) { - FOR (j=0; jnumPeakIndices; j+=3) + FOR( j = 0; j < hm_cfg->numPeakIndices; j += 3 ) { - FOR (; IndexpeakIndices[j]; ++Index) + FOR( ; Index < hm_cfg->peakIndices[j]; ++Index ) { *tmp++ = Index; move16(); } - Index = add(Index, 3); /* Skip the peak */ + Index = add( Index, 3 ); /* Skip the peak */ } } - IF (LT_16(Index, NumCoeffs)) + IF( LT_16( Index, NumCoeffs ) ) { - FOR (; IndexnumHoleIndices = (Word16)(tmp - hm_cfg->holeIndices); + hm_cfg->numHoleIndices = (Word16) ( tmp - hm_cfg->holeIndices ); *tmp++ = NumCoeffs; move16(); /* Add extremal element signaling the end of the buffer */ - } Word16 CountIndexBits( Word16 Bandwidth, - Word16 PeriodicityIndex -) + Word16 PeriodicityIndex ) { Word16 result; Word16 PeriodicityIndexS; result = 8; move16(); - PeriodicityIndexS = shr(PeriodicityIndex, 9); + PeriodicityIndexS = shr( PeriodicityIndex, 9 ); - if (s_and(PeriodicityIndex, kLtpHmFlag) != 0) + if ( s_and( PeriodicityIndex, kLtpHmFlag ) != 0 ) { result = NumRatioBits[Bandwidth][PeriodicityIndexS]; move16(); @@ -187,11 +186,10 @@ Word16 CountIndexBits( } - int tcx_hm_render( - Word32 lag, /* i: pitch lag Q0 */ - Word16 fract_res, /* i: fractional resolution of the lag Q0 */ - Word16 p[] /* o: harmonic model Q13 */ + Word32 lag, /* i: pitch lag Q0 */ + Word16 fract_res, /* i: fractional resolution of the lag Q0 */ + Word16 p[] /* o: harmonic model Q13 */ ) { Word16 k, tmp, height; @@ -199,45 +197,45 @@ int tcx_hm_render( Word32 f0, tmp32; /* Set up overall shape */ - f0 = L_shl(lag, sub(15, fract_res)); /* Q31 */ + f0 = L_shl( lag, sub( 15, fract_res ) ); /* Q31 */ - tmp32 = Mpy_32_16_1(f0, -26474); - tmp32 = L_shr_r(BASOP_Util_InvLog2(L_shl(tmp32, 7)), 2); - tmp32 = L_sub(603979776L, tmp32); - tmp32 = L_add(L_add(tmp32, tmp32), Mpy_32_16_1(tmp32, 26214)); - height = round_fx(tmp32); /* Q13 */ + tmp32 = Mpy_32_16_1( f0, -26474 ); + tmp32 = L_shr_r( BASOP_Util_InvLog2( L_shl( tmp32, 7 ) ), 2 ); + tmp32 = L_sub( 603979776L, tmp32 ); + tmp32 = L_add( L_add( tmp32, tmp32 ), Mpy_32_16_1( tmp32, 26214 ) ); + height = round_fx( tmp32 ); /* Q13 */ - tmp32 = Mpy_32_16_1(f0, -18910); - tmp32 = L_shr_r(BASOP_Util_InvLog2(L_shl(tmp32, 7)), 2); - tmp32 = L_sub(1395864371L, tmp32); - PeakDeviation = round_fx(tmp32); /* Q14 */ + tmp32 = Mpy_32_16_1( f0, -18910 ); + tmp32 = L_shr_r( BASOP_Util_InvLog2( L_shl( tmp32, 7 ) ), 2 ); + tmp32 = L_sub( 1395864371L, tmp32 ); + PeakDeviation = round_fx( tmp32 ); /* Q14 */ - IF( GT_16(13915,PeakDeviation)) + IF( GT_16( 13915, PeakDeviation ) ) { /* A bit error was encountered */ return 1; } ELSE { - tmp = div_s(13915, PeakDeviation); - tmp = mult_r(tmp, tmp); /* Q15 */ + tmp = div_s( 13915, PeakDeviation ); + tmp = mult_r( tmp, tmp ); /* Q15 */ } - tmp = div_s(13915, PeakDeviation); - tmp = mult_r(tmp, tmp); /* Q15 */ + tmp = div_s( 13915, PeakDeviation ); + tmp = mult_r( tmp, tmp ); /* Q15 */ /* Render the prototype peak */ p[kTcxHmParabolaHalfWidth] = height; move16(); - FOR (k=1; k<=kTcxHmParabolaHalfWidth; ++k) + FOR( k = 1; k <= kTcxHmParabolaHalfWidth; ++k ) { - p[kTcxHmParabolaHalfWidth+k] = round_fx(Mpy_32_16_1(BASOP_Util_InvLog2(L_shl(L_mult0(i_mult2(negate(k),k), tmp),10)), height)); + p[kTcxHmParabolaHalfWidth + k] = round_fx( Mpy_32_16_1( BASOP_Util_InvLog2( L_shl( L_mult0( i_mult2( negate( k ), k ), tmp ), 10 ) ), height ) ); } /* Mirror */ - FOR (k=-kTcxHmParabolaHalfWidth; k<0; ++k) + FOR( k = -kTcxHmParabolaHalfWidth; k < 0; ++k ) { - p[kTcxHmParabolaHalfWidth+k] = p[kTcxHmParabolaHalfWidth-k]; + p[kTcxHmParabolaHalfWidth + k] = p[kTcxHmParabolaHalfWidth - k]; move16(); } @@ -245,50 +243,47 @@ int tcx_hm_render( } void tcx_hm_modify_envelope( - Word16 gain, /* i: HM gain Q11 */ - Word32 lag, /* i: pitch lag Q0 */ - Word16 fract_res, /* i: fractional resolution of the lag Q0 */ - Word16 p[], /* i: harmonic model Q13 */ - Word32 env[], /* i/o: envelope Q16 */ - Word16 L_frame /* i: number of spectral lines Q0 */ + Word16 gain, /* i: HM gain Q11 */ + Word32 lag, /* i: pitch lag Q0 */ + Word16 fract_res, /* i: fractional resolution of the lag Q0 */ + Word16 p[], /* i: harmonic model Q13 */ + Word32 env[], /* i/o: envelope Q16 */ + Word16 L_frame /* i: number of spectral lines Q0 */ ) { - Word16 k, h, x, l1,l2, L_frame_m1, L_frame_for_loop; - Word16 inv_shape[2*kTcxHmParabolaHalfWidth+1]; + Word16 k, h, x, l1, l2, L_frame_m1, L_frame_for_loop; + Word16 inv_shape[2 * kTcxHmParabolaHalfWidth + 1]; - IF ( gain == 0 ) + IF( gain == 0 ) { return; } - FOR (k=0; k<2*kTcxHmParabolaHalfWidth+1; ++k) + FOR( k = 0; k < 2 * kTcxHmParabolaHalfWidth + 1; ++k ) { /* Q24 = Q11 * Q13; 512 = 1.0 in Q24 format */ - inv_shape[k] = div_s(512, add(512, mult_r(gain, p[k]))); + inv_shape[k] = div_s( 512, add( 512, mult_r( gain, p[k] ) ) ); move16(); } h = 1; move16(); - k = extract_l(L_shr(lag,fract_res)); + k = extract_l( L_shr( lag, fract_res ) ); - L_frame_m1 = sub(L_frame,1); - L_frame_for_loop = add(L_frame,kTcxHmParabolaHalfWidth - 1); + L_frame_m1 = sub( L_frame, 1 ); + L_frame_for_loop = add( L_frame, kTcxHmParabolaHalfWidth - 1 ); - WHILE ( LE_16(k,L_frame_for_loop)) + WHILE( LE_16( k, L_frame_for_loop ) ) { - l1 = s_max(0, sub(k,kTcxHmParabolaHalfWidth)); - l2 = s_min(add(k,kTcxHmParabolaHalfWidth), L_frame_m1); - FOR (x=l1; x<=l2; ++x) + l1 = s_max( 0, sub( k, kTcxHmParabolaHalfWidth ) ); + l2 = s_min( add( k, kTcxHmParabolaHalfWidth ), L_frame_m1 ); + FOR( x = l1; x <= l2; ++x ) { - env[x] = Mpy_32_16_1(env[x], inv_shape[x-k+kTcxHmParabolaHalfWidth]); + env[x] = Mpy_32_16_1( env[x], inv_shape[x - k + kTcxHmParabolaHalfWidth] ); move32(); } - h = add(h,1); - k = extract_l(L_shr(imult3216(lag,h),fract_res)); + h = add( h, 1 ); + k = extract_l( L_shr( imult3216( lag, h ), fract_res ) ); } - } - - diff --git a/lib_com/arith_coder.c b/lib_com/arith_coder.c index 56ffb1d35..58729a004 100644 --- a/lib_com/arith_coder.c +++ b/lib_com/arith_coder.c @@ -253,8 +253,8 @@ void tcx_arith_scale_envelope_flt( /* Boosting to account for expected spectrum truncation (kMax) */ /* target_bits = (int16_t)(target_bits * (1.2f - 0.00045f * target_bits + 0.00000025f * target_bits * target_bits)); */ L_tmp = L_shr( Mpy_32_16_1( L_mult0( target_bits, target_bits ), 17180 ), 6 ); /* Q15; 17180 -> 0.00000025f (Q36) */ - L_tmp = L_sub( L_tmp, L_shr( L_mult0( target_bits, 30199 ), 11 ) ); /* Q15; 30199 -> 0.00045f (Q26) */ - L_tmp = L_add( L_tmp, 39322 ); /* Q15; 39322 -> 1.2f (Q15) */ + L_tmp = L_sub( L_tmp, L_shr( L_mult0( target_bits, 30199 ), 11 ) ); /* Q15; 30199 -> 0.00045f (Q26) */ + L_tmp = L_add( L_tmp, 39322 ); /* Q15; 39322 -> 1.2f (Q15) */ L_tmp = Mpy_32_16_1( L_tmp, target_bits ); /* Q0 */ assert( L_tmp < 32768 ); target_bits = extract_l( L_tmp ); diff --git a/lib_com/arith_coder_fx.c b/lib_com/arith_coder_fx.c index e3cf6f5e8..69d646406 100644 --- a/lib_com/arith_coder_fx.c +++ b/lib_com/arith_coder_fx.c @@ -11,25 +11,25 @@ #include "cnst.h" /* Fixed point implementation of exp(negate()) */ -Word32 expfp( /* o: Q31 */ - const Word16 x, /* i: mantissa Q-e */ - const Word16 x_e) /* i: exponent Q0 */ +Word32 expfp( /* o: Q31 */ + const Word16 x, /* i: mantissa Q-e */ + const Word16 x_e ) /* i: exponent Q0 */ { Word16 xi, xf, tmp; Word16 b0, b1, b2, b3; Word32 y, L_tmp; - assert(x > 0); + assert( x > 0 ); - L_tmp = L_shl(L_deposit_h(x), x_e); + L_tmp = L_shl( L_deposit_h( x ), x_e ); /* split into integer and fractional parts */ - xi = round_fx(L_tmp); - xf = extract_l(L_tmp); + xi = round_fx( L_tmp ); + xf = extract_l( L_tmp ); BASOP_SATURATE_WARNING_OFF_EVS; - xf = negate(xf); + xf = negate( xf ); BASOP_SATURATE_WARNING_ON_EVS; /* Fractional part */ @@ -38,48 +38,48 @@ Word32 expfp( /* o: Q31 */ + ((xf*xf) / (2*65536)) + ((((((xf*xf) / (2*65536))*xf) / 65536)*65536/3) / 65536) + ((((((((xf*xf) / (2*65536))*xf) / 65536)*65536/3) / 65536)*xf) / (4*65536)); */ - y = L_mac0(65536, xf, 1); - tmp = shr(mult(xf, xf), 2); - y = L_mac0(y, tmp, 1); - tmp = shr(mult(shr(mult(tmp, xf), 1), 65536/3), 1); - y = L_mac0(y, tmp, 1); - tmp = shr(mult(tmp, xf), 3); - y = L_mac0(y, tmp, 1); + y = L_mac0( 65536, xf, 1 ); + tmp = shr( mult( xf, xf ), 2 ); + y = L_mac0( y, tmp, 1 ); + tmp = shr( mult( shr( mult( tmp, xf ), 1 ), 65536 / 3 ), 1 ); + y = L_mac0( y, tmp, 1 ); + tmp = shr( mult( tmp, xf ), 3 ); + y = L_mac0( y, tmp, 1 ); /* Integer part */ - b0 = s_and(xi, 1); - b1 = s_and(xi, 2); - b2 = s_and(xi, 4); - b3 = s_and(xi, 8); + b0 = s_and( xi, 1 ); + b1 = s_and( xi, 2 ); + b2 = s_and( xi, 4 ); + b3 = s_and( xi, 8 ); - if (b0 != 0) + if ( b0 != 0 ) { - y = Mpy_32_16_1(y, 24109); /* exp(-1) in -1Q16 */ + y = Mpy_32_16_1( y, 24109 ); /* exp(-1) in -1Q16 */ } - if (b1 != 0) + if ( b1 != 0 ) { - y = Mpy_32_16_1(y, 17739); /* exp(-2) in -2Q17 */ + y = Mpy_32_16_1( y, 17739 ); /* exp(-2) in -2Q17 */ } - if (b2 != 0) + if ( b2 != 0 ) { - y = Mpy_32_16_1(y, 19205); /* exp(-4) in -5Q20 */ + y = Mpy_32_16_1( y, 19205 ); /* exp(-4) in -5Q20 */ } - if (b3 != 0) + if ( b3 != 0 ) { - y = Mpy_32_16_1(y, 22513); /* exp(-8) in -11Q26 */ + y = Mpy_32_16_1( y, 22513 ); /* exp(-8) in -11Q26 */ } /* scaling: -1*b0 - 2*b1 -5*b2 -11*b3 */ - y = L_shr(y, add(add(xi, shr(xi, 2)), shr(b3, 3))); + y = L_shr( y, add( add( xi, shr( xi, 2 ) ), shr( b3, 3 ) ) ); /* zero for xi >= 16 */ - if (shr(xi, 4) > 0) + if ( shr( xi, 4 ) > 0 ) { - y = L_deposit_l(0); + y = L_deposit_l( 0 ); } - return L_shl(y, 15); + return L_shl( y, 15 ); } /* Fixed point implementation of pow(), where base is fixed point (16/16) and exponent a small *odd* integer @@ -89,64 +89,64 @@ Word32 expfp( /* o: Q31 */ * * NOTE: This function must be in sync with ari_decode_14bits_pow_fx() */ void powfp_odd2( - const Word16 base, /* Q15 */ - const Word16 exp, /* Q0 */ - Word16 *pout1, /* Q15 */ - Word16 *pout2 /* Q15 */ + const Word16 base, /* Q15 */ + const Word16 exp, /* Q0 */ + Word16 *pout1, /* Q15 */ + Word16 *pout2 /* Q15 */ ) { /* this version is in sync with ari_enc_14bits_pow() * that is, we have to start multiplication from the largest power-of-two, in order to * get the rounding errors to appear at the same places */ - Word16 pows[12]; /* powers of two exponents*/ + Word16 pows[12]; /* powers of two exponents*/ Word16 exp2; Word16 out, out2; Word16 k, h, maxk; - assert(exp >= 0); + assert( exp >= 0 ); out = base; move16(); out2 = 0x7FFF; move16(); - IF (exp != 0) + IF( exp != 0 ) { - exp2 = sub(exp, 1); - maxk = sub(15, norm_s(exp)); - assert(maxk < 12); + exp2 = sub( exp, 1 ); + maxk = sub( 15, norm_s( exp ) ); + assert( maxk < 12 ); pows[0] = base; move16(); - FOR (k = 0; k < maxk; k++) + FOR( k = 0; k < maxk; k++ ) { - pows[k+1] = mult_r(pows[k], pows[k]); + pows[k + 1] = mult_r( pows[k], pows[k] ); move16(); } - k = sub(k, 1); - h = shl(1, k); /* highest bit of exp2 */ + k = sub( k, 1 ); + h = shl( 1, k ); /* highest bit of exp2 */ out2 = base; move16(); - out = mult_r(out, pows[k+1]); /* we already know that "exp" has the highest bit set to one since we calculated .. */ + out = mult_r( out, pows[k + 1] ); /* we already know that "exp" has the highest bit set to one since we calculated .. */ /* .. the effective length of "exp" earlier on, thus we omit the branch for out2 */ - if (s_and(exp2, h) != 0) + if ( s_and( exp2, h ) != 0 ) { - out2 = mult_r(out2, pows[k+1]); + out2 = mult_r( out2, pows[k + 1] ); } - h = shr(h, 1); - FOR (k = sub(k, 1); k >= 0; k--) + h = shr( h, 1 ); + FOR( k = sub( k, 1 ); k >= 0; k-- ) { - if (s_and(exp, h) != 0) + if ( s_and( exp, h ) != 0 ) { - out = mult_r(out, pows[k+1]); + out = mult_r( out, pows[k + 1] ); } - if (s_and(exp2, h) != 0) + if ( s_and( exp2, h ) != 0 ) { - out2 = mult_r(out2, pows[k+1]); + out2 = mult_r( out2, pows[k + 1] ); } - h = shr(h, 1); + h = shr( h, 1 ); } } @@ -154,7 +154,6 @@ void powfp_odd2( move16(); *pout2 = out; move16(); - } /*------------------------------------------------------------------------ @@ -179,13 +178,13 @@ void powfp_odd2( * and decoder remain synchronized. *-------------------------------------------------------------------------*/ void tcx_arith_scale_envelope( - const Word16 L_spec_core, /* i: number of lines to scale Q0 */ - Word16 L_frame, /* i: number of lines Q0 */ - const Word32 env[], /* i: unscaled envelope Q16 */ - Word16 target_bits, /* i: number of available bits Q0 */ - const Word16 low_complexity,/* i: low-complexity flag Q0 */ - Word16 s_env[], /* o: scaled envelope Q15-e */ - Word16 *s_env_e /* o: scaled envelope exponent Q0 */ + const Word16 L_spec_core, /* i: number of lines to scale Q0 */ + Word16 L_frame, /* i: number of lines Q0 */ + const Word32 env[], /* i: unscaled envelope Q16 */ + Word16 target_bits, /* i: number of available bits Q0 */ + const Word16 low_complexity, /* i: low-complexity flag Q0 */ + Word16 s_env[], /* o: scaled envelope Q15-e */ + Word16 *s_env_e /* o: scaled envelope exponent Q0 */ ) { Word32 ienv[N_MAX_ARI]; @@ -200,7 +199,6 @@ void tcx_arith_scale_envelope( #endif - lob_bits = 0; move16(); hib_bits = 0; @@ -208,39 +206,40 @@ void tcx_arith_scale_envelope( /* Boosting to account for expected spectrum truncation (kMax) */ /* target_bits = (int)(target_bits * (1.2f - 0.00045f * target_bits + 0.00000025f * target_bits * target_bits)); */ - L_tmp = L_shr(Mpy_32_16_1(L_mult0(target_bits, target_bits), 17180), 6); /* Q15; 17180 -> 0.00000025f (Q36) */ - L_tmp = L_sub(L_tmp, L_shr(L_mult0(target_bits, 30199), 11)); /* Q15; 30199 -> 0.00045f (Q26) */ - L_tmp = L_add(L_tmp, 39322); /* Q15; 39322 -> 1.2f (Q15) */ - L_tmp = Mpy_32_16_1(L_tmp, target_bits); /* Q0 */ - assert(L_tmp < 32768); - target_bits = extract_l(L_tmp); + L_tmp = L_shr( Mpy_32_16_1( L_mult0( target_bits, target_bits ), 17180 ), 6 ); /* Q15; 17180 -> 0.00000025f (Q36) */ + L_tmp = L_sub( L_tmp, L_shr( L_mult0( target_bits, 30199 ), 11 ) ); /* Q15; 30199 -> 0.00045f (Q26) */ + L_tmp = L_add( L_tmp, 39322 ); /* Q15; 39322 -> 1.2f (Q15) */ + L_tmp = Mpy_32_16_1( L_tmp, target_bits ); /* Q0 */ + assert( L_tmp < 32768 ); + target_bits = extract_l( L_tmp ); /* Calculate inverse envelope and find initial scale guess based on mean */ - mean = L_deposit_l(0); - FOR (k = 0; k < L_frame; k++) + mean = L_deposit_l( 0 ); + FOR( k = 0; k < L_frame; k++ ) { /* ienv[k] = 1.0f / env[k]; mean += ienv[k]; */ - tmp = norm_l(env[k]); - tmp2 = sub(15, tmp); + tmp = norm_l( env[k] ); + tmp2 = sub( 15, tmp ); #ifdef BASOP_NOGLOB - tmp = Inv16(round_fx_o(L_shl_o(env[k], tmp, &Overflow), &Overflow), &tmp2); + tmp = Inv16( round_fx_o( L_shl_o( env[k], tmp, &Overflow ), &Overflow ), &tmp2 ); #else - tmp = Inv16(round_fx(L_shl(env[k], tmp)), &tmp2); + tmp = Inv16( round_fx( L_shl( env[k], tmp ) ), &tmp2 ); #endif - ienv[k] = L_shl(L_deposit_h(tmp), sub(tmp2, 15)); /* Q16 */ move32(); - mean = L_add(mean, ienv[k]); + ienv[k] = L_shl( L_deposit_h( tmp ), sub( tmp2, 15 ) ); /* Q16 */ + move32(); + mean = L_add( mean, ienv[k] ); } - tmp = norm_s(L_frame); - tmp = shl(div_s(8192, shl(L_frame, tmp)), sub(tmp, 7)); - mean = L_shr(Mpy_32_16_1(mean, tmp), 6); /* Q16 */ + tmp = norm_s( L_frame ); + tmp = shl( div_s( 8192, shl( L_frame, tmp ) ), sub( tmp, 7 ) ); + mean = L_shr( Mpy_32_16_1( mean, tmp ), 6 ); /* Q16 */ /* Rate dependent compensation to get closer to the target on average */ /* mean = (float)pow(mean, (float)L_frame / (float)target_bits * 0.357f); */ - tmp = BASOP_Util_Divide1616_Scale(L_frame, target_bits, &tmp2); - tmp = mult_r(tmp, 11698/*0.357f Q15*/); - mean = BASOP_Util_fPow(mean, 15, L_deposit_h(tmp), tmp2, &mean_e); + tmp = BASOP_Util_Divide1616_Scale( L_frame, target_bits, &tmp2 ); + tmp = mult_r( tmp, 11698 /*0.357f Q15*/ ); + mean = BASOP_Util_fPow( mean, 15, L_deposit_h( tmp ), tmp2, &mean_e ); /* Find first-guess scaling coefficient "scale" such that if "mean" is the * mean of the envelope, then the mean bit-consumption is approximately @@ -248,42 +247,42 @@ void tcx_arith_scale_envelope( * log2(2*e*mean*scale + 0.15 + 0.035/(mean*scale)) * L_frame = target_bits */ /* a = 2*2.71828183f*mean*mean; */ - tmp = round_fx(mean); - a = L_mult(mult_r(tmp, 22268/*2.71828183f Q13*/), tmp); - a_e = add(shl(mean_e, 1), 3); + tmp = round_fx( mean ); + a = L_mult( mult_r( tmp, 22268 /*2.71828183f Q13*/ ), tmp ); + a_e = add( shl( mean_e, 1 ), 3 ); /* b = (0.15f - (float)pow(2.0f, target_bits/(float)L_frame)) * mean; */ - tmp = BASOP_Util_Divide1616_Scale(target_bits, L_frame, &tmp2); - tmp = round_fx(BASOP_util_Pow2(L_deposit_h(tmp), tmp2, &tmp2)); - b_e = BASOP_Util_Add_MantExp(4915/*0.15f Q15*/, 0, negate(tmp), tmp2, &b); - b = mult_r(b, round_fx(mean)); - b_e = add(b_e, mean_e); + tmp = BASOP_Util_Divide1616_Scale( target_bits, L_frame, &tmp2 ); + tmp = round_fx( BASOP_util_Pow2( L_deposit_h( tmp ), tmp2, &tmp2 ) ); + b_e = BASOP_Util_Add_MantExp( 4915 /*0.15f Q15*/, 0, negate( tmp ), tmp2, &b ); + b = mult_r( b, round_fx( mean ) ); + b_e = add( b_e, mean_e ); /* scale = (-b + (float)sqrt(b*b - 4.0f*a*0.035f)) / (2.0f * a); */ - tmp = round_fx_o(BASOP_Util_Add_Mant32Exp(L_mult(b, b), shl(b_e, 1), Mpy_32_16_1(a, -4588/*-4.0f*0.035f Q15*/), a_e, &tmp2), &Overflow); + tmp = round_fx_o( BASOP_Util_Add_Mant32Exp( L_mult( b, b ), shl( b_e, 1 ), Mpy_32_16_1( a, -4588 /*-4.0f*0.035f Q15*/ ), a_e, &tmp2 ), &Overflow ); IF( tmp <= 0 ) { tmp = 0; - set16_fx(s_env, 0, L_frame); + set16_fx( s_env, 0, L_frame ); } ELSE { - tmp = Sqrt16(tmp, &tmp2); + tmp = Sqrt16( tmp, &tmp2 ); } - tmp2 = BASOP_Util_Add_MantExp(negate(b), b_e, tmp, tmp2, &scale); - scale = BASOP_Util_Divide1616_Scale(scale, round_fx(a), &tmp); + tmp2 = BASOP_Util_Add_MantExp( negate( b ), b_e, tmp, tmp2, &scale ); + scale = BASOP_Util_Divide1616_Scale( scale, round_fx( a ), &tmp ); #ifdef BASOP_NOGLOB - scale = shl_o(scale, sub(sub(add(tmp, tmp2), a_e), 1), &Overflow); /* Q15 */ + scale = shl_o( scale, sub( sub( add( tmp, tmp2 ), a_e ), 1 ), &Overflow ); /* Q15 */ #else - scale = shl(scale, sub(sub(add(tmp, tmp2), a_e), 1)); /* Q15 */ + scale = shl( scale, sub( sub( add( tmp, tmp2 ), a_e ), 1 ) ); /* Q15 */ #endif /* iscale = 1.0f / scale; */ iscale_e = 0; move16(); - iscale = Inv16(s_max(1, scale), &iscale_e); + iscale = Inv16( s_max( 1, scale ), &iscale_e ); lob = 0; move16(); @@ -292,96 +291,97 @@ void tcx_arith_scale_envelope( max_iter = 2; move16(); - if(low_complexity) + if ( low_complexity ) { max_iter = 1; move16(); } - FOR (iter = 0; iter < max_iter; iter++) + FOR( iter = 0; iter < max_iter; iter++ ) { statesi = 0x7FFF; move16(); bits = 0; move16(); - FOR (k = 0; k < L_frame; k++) + FOR( k = 0; k < L_frame; k++ ) { - s = Mpy_32_16_1(ienv[k], scale); /* Q16 */ + s = Mpy_32_16_1( ienv[k], scale ); /* Q16 */ - IF (LE_32(s, 5243l/*0.08f Q16*/)) + IF( LE_32( s, 5243l /*0.08f Q16*/ ) ) { /* If s = 0.08, the expected bit-consumption is log2(1.0224). Below 0.08, the bit-consumption estimate function becomes inaccurate, so use log2(1.0224) for all values below 0.08. */ /* round(state * 1.0224 * 32768) */ - statesi = mult_r(statesi, 16751/*1.0224 Q14*/); - tmp = norm_s(statesi); - statesi = shl(statesi, tmp); - bits = add(bits, sub(1, tmp)); + statesi = mult_r( statesi, 16751 /*1.0224 Q14*/ ); + tmp = norm_s( statesi ); + statesi = shl( statesi, tmp ); + bits = add( bits, sub( 1, tmp ) ); } - ELSE IF (LE_32(s, 16711680l/*255.0 Q16*/)) + ELSE IF( LE_32( s, 16711680l /*255.0 Q16*/ ) ) { /* a = 5.436564f * s + 0.15f + 0.035f * env[k] * iscale; */ - L_tmp = L_shl(Mpy_32_16_1(s, 22268/*5.436564f Q12*/), 3); - L_tmp = L_add(L_tmp, 9830l/*0.15f Q16*/); - L_tmp = L_add(L_tmp, L_shl(Mpy_32_16_1(env[k], mult_r(1147/*0.035f Q15*/, iscale)), iscale_e)); + L_tmp = L_shl( Mpy_32_16_1( s, 22268 /*5.436564f Q12*/ ), 3 ); + L_tmp = L_add( L_tmp, 9830l /*0.15f Q16*/ ); + L_tmp = L_add( L_tmp, L_shl( Mpy_32_16_1( env[k], mult_r( 1147 /*0.035f Q15*/, iscale ) ), iscale_e ) ); - tmp = norm_l(L_tmp); + tmp = norm_l( L_tmp ); #ifdef BASOP_NOGLOB - statesi = mult_r(statesi, round_fx_o(L_shl_o(L_tmp, tmp, &Overflow), &Overflow)); + statesi = mult_r( statesi, round_fx_o( L_shl_o( L_tmp, tmp, &Overflow ), &Overflow ) ); #else - statesi = mult_r(statesi, round_fx(L_shl(L_tmp, tmp))); + statesi = mult_r( statesi, round_fx( L_shl( L_tmp, tmp ) ) ); #endif - bits = add(bits, sub(15, tmp)); + bits = add( bits, sub( 15, tmp ) ); - tmp = norm_s(statesi); - statesi = shl(statesi, tmp); - bits = sub(bits, tmp); + tmp = norm_s( statesi ); + statesi = shl( statesi, tmp ); + bits = sub( bits, tmp ); } ELSE { /* for large envelope values, s > 255, bit consumption is approx log2(2*e*s) * further, we use round(log2(x)) = floor(log2(x)+0.5) = floor(log2(x*sqrt(2))) */ /* a = 5.436564f * s; */ - L_tmp = Mpy_32_16_1(s, 31492/*5.436564f * 1.4142f Q12*/); /* Q13 */ - bits = add(bits, sub(17, norm_l(L_tmp))); + L_tmp = Mpy_32_16_1( s, 31492 /*5.436564f * 1.4142f Q12*/ ); /* Q13 */ + bits = add( bits, sub( 17, norm_l( L_tmp ) ) ); } } - IF (LE_16(bits, target_bits)) /* Bits leftover => scale is too small */ + IF( LE_16( bits, target_bits ) ) /* Bits leftover => scale is too small */ { - lob = scale; + lob = scale; move16(); lob_bits = bits; move16(); - IF (hib > 0) /* Bisection search */ + IF( hib > 0 ) /* Bisection search */ { - adjust = div_s(sub(hib_bits, target_bits), sub(hib_bits, lob_bits)); - scale = add(mult_r(sub(lob, hib), adjust), hib); + adjust = div_s( sub( hib_bits, target_bits ), sub( hib_bits, lob_bits ) ); + scale = add( mult_r( sub( lob, hib ), adjust ), hib ); } - ELSE /* Initial scale adaptation */ + ELSE /* Initial scale adaptation */ { /* adjust = 1.05f * target_bits / (float)bits; scale *= adjust; */ - adjust = mult_r(17203/*1.05f Q14*/, target_bits); - adjust = BASOP_Util_Divide1616_Scale(adjust, bits, &tmp); - scale = shl(mult_r(scale, adjust), add(1, tmp)); + adjust = mult_r( 17203 /*1.05f Q14*/, target_bits ); + adjust = BASOP_Util_Divide1616_Scale( adjust, bits, &tmp ); + scale = shl( mult_r( scale, adjust ), add( 1, tmp ) ); } } - ELSE /* Ran out of bits => scale is too large */ + ELSE /* Ran out of bits => scale is too large */ { - hib = scale; + hib = scale; move16(); hib_bits = bits; move16(); - IF (lob > 0) /* Bisection search */ + IF( lob > 0 ) /* Bisection search */ { - adjust = div_s(sub(hib_bits, target_bits), sub(hib_bits, lob_bits)); - scale = add(mult_r(sub(lob, hib), adjust), hib); + adjust = div_s( sub( hib_bits, target_bits ), sub( hib_bits, lob_bits ) ); + scale = add( mult_r( sub( lob, hib ), adjust ), hib ); } - ELSE { /* Initial scale adaptation */ + ELSE + { /* Initial scale adaptation */ test(); IF( target_bits <= 0 || bits <= 0 ) /* safety check in case of bit errors */ { @@ -391,15 +391,15 @@ void tcx_arith_scale_envelope( } ELSE { - adjust = div_s(mult_r(31130/*0.95f Q15*/, target_bits), bits); + adjust = div_s( mult_r( 31130 /*0.95f Q15*/, target_bits ), bits ); } - scale = mult_r(scale, adjust); + scale = mult_r( scale, adjust ); } } iscale_e = 0; move16(); - IF( scale == 0 ) /* safety check in case of bit errors */ + IF( scale == 0 ) /* safety check in case of bit errors */ { iscale = 0; move16(); @@ -407,30 +407,29 @@ void tcx_arith_scale_envelope( } ELSE { - iscale = Inv16(scale, &iscale_e); + iscale = Inv16( scale, &iscale_e ); } } L_frame = L_spec_core; move16(); - tmp = getScaleFactor32(env, L_frame); - *s_env_e = sub(add(15, iscale_e), tmp); + tmp = getScaleFactor32( env, L_frame ); + *s_env_e = sub( add( 15, iscale_e ), tmp ); move16(); BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB - a = L_shl_o(1265000, sub(15, *s_env_e), &Overflow); + a = L_shl_o( 1265000, sub( 15, *s_env_e ), &Overflow ); #else /* BASOP_NOGLOB */ - a = L_shl(1265000, sub(15, *s_env_e)); + a = L_shl( 1265000, sub( 15, *s_env_e ) ); #endif BASOP_SATURATE_WARNING_ON_EVS; - FOR (k = 0; k < L_frame; k++) + FOR( k = 0; k < L_frame; k++ ) { - L_tmp = Mpy_32_16_1(L_shl(env[k], tmp), iscale); - L_tmp = L_min(L_tmp, a); - s_env[k] = round_fx(L_tmp); + L_tmp = Mpy_32_16_1( L_shl( env[k], tmp ), iscale ); + L_tmp = L_min( L_tmp, a ); + s_env[k] = round_fx( L_tmp ); } - } /*------------------------------------------------------------------------ @@ -446,56 +445,53 @@ void tcx_arith_scale_envelope( * and decoder remain synchronized. *-------------------------------------------------------------------------*/ void tcx_arith_render_envelope( - const Word16 A_ind[], /* i: LPC coefficients of signal envelope */ - const Word16 L_frame, /* i: number of spectral lines */ + const Word16 A_ind[], /* i: LPC coefficients of signal envelope */ + const Word16 L_frame, /* i: number of spectral lines */ const Word16 L_spec, - const Word16 preemph_fac, /* i: pre-emphasis factor */ - const Word16 gamma_w, /* i: A_ind -> weighted envelope factor */ - const Word16 gamma_uw, /* i: A_ind -> non-weighted envelope factor */ - Word32 env[] /* o: shaped signal envelope */ + const Word16 preemph_fac, /* i: pre-emphasis factor */ + const Word16 gamma_w, /* i: A_ind -> weighted envelope factor */ + const Word16 gamma_uw, /* i: A_ind -> non-weighted envelope factor */ + Word32 env[] /* o: shaped signal envelope */ ) { Word16 k; - Word16 tmpA[M+2]; + Word16 tmpA[M + 2]; Word16 signal_env[FDNS_NPTS], signal_env_e[FDNS_NPTS]; Word16 gainlpc[FDNS_NPTS], gainlpc_e[FDNS_NPTS]; - /* Compute perceptual LPC envelope, transform it into freq.-domain gains */ weight_a_fx( A_ind, tmpA, gamma_w, M ); - lpc2mdct( tmpA, M, NULL, NULL, gainlpc, gainlpc_e, FDNS_NPTS, 0); + lpc2mdct( tmpA, M, NULL, NULL, gainlpc, gainlpc_e, FDNS_NPTS, 0 ); /* Add pre-emphasis tilt to LPC envelope, transform LPC into MDCT gains */ - E_LPC_a_weight_inv(A_ind, signal_env, gamma_uw, M); - E_LPC_a_add_tilt(signal_env, tmpA, preemph_fac, M); - lpc2mdct(tmpA, M+1, signal_env, signal_env_e, NULL, NULL, FDNS_NPTS, 0); + E_LPC_a_weight_inv( A_ind, signal_env, gamma_uw, M ); + E_LPC_a_add_tilt( signal_env, tmpA, preemph_fac, M ); + lpc2mdct( tmpA, M + 1, signal_env, signal_env_e, NULL, NULL, FDNS_NPTS, 0 ); /* Compute weighted signal envelope in perceptual domain */ - FOR (k = 0; k < FDNS_NPTS; k++) + FOR( k = 0; k < FDNS_NPTS; k++ ) { - signal_env[k] = mult_r(signal_env[k], gainlpc[k]); + signal_env[k] = mult_r( signal_env[k], gainlpc[k] ); move16(); - signal_env_e[k] = add(signal_env_e[k], gainlpc_e[k]); + signal_env_e[k] = add( signal_env_e[k], gainlpc_e[k] ); move16(); } /* Adaptive low frequency emphasis */ - set32_fx(env, 0x10000, L_frame); + set32_fx( env, 0x10000, L_frame ); - AdaptLowFreqDeemph(env, 15, - 1, - gainlpc, gainlpc_e, - L_frame, NULL); + AdaptLowFreqDeemph( env, 15, + 1, + gainlpc, gainlpc_e, + L_frame, NULL ); /* Scale from FDNS_NPTS to L_frame and multiply LFE gains */ - mdct_noiseShaping_interp(env, L_frame, signal_env, signal_env_e); + mdct_noiseShaping_interp( env, L_frame, signal_env, signal_env_e ); - FOR (k=L_frame; k -#if defined(__unix__) || defined(__unix) || defined(__APPLE__) +#if defined( __unix__ ) || defined( __unix ) || defined( __APPLE__ ) #include /* Using macro instead of function here to avoid pushing new frames onto the stack */ -#define PRINT_STACK() \ - do { \ - void *call_stack[200]; \ - int i; \ - int num_frames; \ - char **strings; \ - \ - num_frames = backtrace(call_stack, 200); \ - strings = backtrace_symbols(call_stack, num_frames); \ - for (i = 0; i < num_frames; ++i) { \ - printf("[BASOP] %s\n", strings[i]); \ - } \ - free(strings); \ - } while (0) +#define PRINT_STACK() \ + do \ + { \ + void *call_stack[200]; \ + int i; \ + int num_frames; \ + char **strings; \ + \ + num_frames = backtrace( call_stack, 200 ); \ + strings = backtrace_symbols( call_stack, num_frames ); \ + for ( i = 0; i < num_frames; ++i ) \ + { \ + printf( "[BASOP] %s\n", strings[i] ); \ + } \ + free( strings ); \ + } while ( 0 ) #elif defined _WIN32 || defined _WIN64 #include #include -#pragma comment(lib, "Dbghelp.lib") +#pragma comment( lib, "Dbghelp.lib" ) /* Using macro instead of function here to avoid pushing new frames onto the stack */ -#define PRINT_STACK() \ - do { \ - void *call_stack[200]; \ - int i; \ - int num_frames; \ - DWORD64 offset; \ - SYMBOL_INFO *symbol; \ - IMAGEHLP_MODULE module; \ - HANDLE process; \ - \ - process = GetCurrentProcess(); \ - SymInitialize(process, NULL, TRUE); \ - symbol = \ - (SYMBOL_INFO *)calloc(sizeof(SYMBOL_INFO) + 256 * sizeof(char), 1); \ - symbol->MaxNameLen = 255; \ - symbol->SizeOfStruct = sizeof(SYMBOL_INFO); \ - module.SizeOfStruct = sizeof(IMAGEHLP_MODULE64); \ - \ - IMAGEHLP_LINE *line_info = \ - (IMAGEHLP_LINE *)calloc(sizeof(IMAGEHLP_LINE), 1); \ - line_info->SizeOfStruct = sizeof(IMAGEHLP_LINE); \ - \ - num_frames = CaptureStackBackTrace(0, 200, call_stack, NULL); \ - for (i = 0; i < num_frames; ++i) { \ - DWORD dwLineDisplacement; \ - SymFromAddr(process, (DWORD64)(call_stack[i]), &offset, symbol); \ - SymGetModuleInfo(process, (DWORD)symbol->ModBase, &module); \ - if (SymGetLineFromAddr(process, (DWORD64)(call_stack[i]), \ - &dwLineDisplacement, line_info)) { \ - printf("[BASOP] %i\t%s(%s+0x%llX) [0x%llX] %s:%d\n", i, \ - module.ModuleName, symbol->Name, offset, symbol->Address, \ - line_info->FileName, line_info->LineNumber); \ - } else { \ - printf("[BASOP] %i\t%s(%s+0x%llX) [0x%llX]\n", i, module.ModuleName, \ - symbol->Name, offset, symbol->Address); \ - } \ - } \ - free(line_info); \ - free(symbol); \ - } while (0) +#define PRINT_STACK() \ + do \ + { \ + void *call_stack[200]; \ + int i; \ + int num_frames; \ + DWORD64 offset; \ + SYMBOL_INFO *symbol; \ + IMAGEHLP_MODULE module; \ + HANDLE process; \ + \ + process = GetCurrentProcess(); \ + SymInitialize( process, NULL, TRUE ); \ + symbol = \ + (SYMBOL_INFO *) calloc( sizeof( SYMBOL_INFO ) + 256 * sizeof( char ), 1 ); \ + symbol->MaxNameLen = 255; \ + symbol->SizeOfStruct = sizeof( SYMBOL_INFO ); \ + module.SizeOfStruct = sizeof( IMAGEHLP_MODULE64 ); \ + \ + IMAGEHLP_LINE *line_info = \ + (IMAGEHLP_LINE *) calloc( sizeof( IMAGEHLP_LINE ), 1 ); \ + line_info->SizeOfStruct = sizeof( IMAGEHLP_LINE ); \ + \ + num_frames = CaptureStackBackTrace( 0, 200, call_stack, NULL ); \ + for ( i = 0; i < num_frames; ++i ) \ + { \ + DWORD dwLineDisplacement; \ + SymFromAddr( process, (DWORD64) ( call_stack[i] ), &offset, symbol ); \ + SymGetModuleInfo( process, (DWORD) symbol->ModBase, &module ); \ + if ( SymGetLineFromAddr( process, (DWORD64) ( call_stack[i] ), \ + &dwLineDisplacement, line_info ) ) \ + { \ + printf( "[BASOP] %i\t%s(%s+0x%llX) [0x%llX] %s:%d\n", i, \ + module.ModuleName, symbol->Name, offset, symbol->Address, \ + line_info->FileName, line_info->LineNumber ); \ + } \ + else \ + { \ + printf( "[BASOP] %i\t%s(%s+0x%llX) [0x%llX]\n", i, module.ModuleName, \ + symbol->Name, offset, symbol->Address ); \ + } \ + } \ + free( line_info ); \ + free( symbol ); \ + } while ( 0 ) #else -#define PRINT_STACK() \ - do { \ - printf("[BASOP] - printing call stack is not " \ - "supported on this platform\n"); \ - } while (0) +#define PRINT_STACK() \ + do \ + { \ + printf( "[BASOP] - printing call stack is not " \ + "supported on this platform\n" ); \ + } while ( 0 ) #endif /* Using macro instead of function here to avoid pushing new frames onto the stack */ -#define PRINT_BASOP_NOGLOB_WARNING() \ - do { \ - printf("[BASOP] Overflow occured. Call stack:\n"); \ - PRINT_STACK(); \ - } while (0) +#define PRINT_BASOP_NOGLOB_WARNING() \ + do \ + { \ + printf( "[BASOP] Overflow occured. Call stack:\n" ); \ + PRINT_STACK(); \ + } while ( 0 ) /* Using macro instead of function here to avoid pushing new frames onto the stack */ -#define PRINT_BASOP_NOGLOB_ERROR() \ - do { \ - printf("[BASOP] Overflow error occured. Call stack:\n"); \ - PRINT_STACK(); \ - } while (0) +#define PRINT_BASOP_NOGLOB_ERROR() \ + do \ + { \ + printf( "[BASOP] Overflow error occured. Call stack:\n" ); \ + PRINT_STACK(); \ + } while ( 0 ) #endif /* BASOP_PRINT_ON_WARNING */ #if defined BASOP_PRINT_ON_WARNING || defined BASOP_ABORT_ON_WARNING @@ -287,33 +297,120 @@ int BASOP_warnings_as_errors = 0; #endif #ifdef BASOP_PRINT_ON_WARNING -#define B_HELPER_PRINT_WARNING() do { if (BASOP_saturation_warning_enable) { if(BASOP_warnings_as_errors) { PRINT_BASOP_NOGLOB_ERROR(); } else { PRINT_BASOP_NOGLOB_WARNING(); } } } while(0) +#define B_HELPER_PRINT_WARNING() \ + do \ + { \ + if ( BASOP_saturation_warning_enable ) \ + { \ + if ( BASOP_warnings_as_errors ) \ + { \ + PRINT_BASOP_NOGLOB_ERROR(); \ + } \ + else \ + { \ + PRINT_BASOP_NOGLOB_WARNING(); \ + } \ + } \ + } while ( 0 ) #else -#define B_HELPER_PRINT_WARNING() do { (void)0; } while(0) /* no-op */ +#define B_HELPER_PRINT_WARNING() \ + do \ + { \ + (void) 0; \ + } while ( 0 ) /* no-op */ #endif #ifdef BASOP_ABORT_ON_WARNING -#define B_HELPER_ABORT() do { if (BASOP_saturation_warning_enable) { assert(0); } } while(0) +#define B_HELPER_ABORT() \ + do \ + { \ + if ( BASOP_saturation_warning_enable ) \ + { \ + assert( 0 ); \ + } \ + } while ( 0 ) #else -#define B_HELPER_ABORT() do { (void)0; } while(0) /* no-op */ +#define B_HELPER_ABORT() \ + do \ + { \ + (void) 0; \ + } while ( 0 ) /* no-op */ #endif #ifdef BASOP_NOGLOB_DEV_USE_GLOBALS Flag Overflow = 0; Flag Carry = 0; -#define B_HELPER_SET_GLOBAL(global_flag, value) do { (global_flag) = (value); } while (0) -#define B_HELPER_GET_GLOBAL(global_flag) (global_flag) +#define B_HELPER_SET_GLOBAL( global_flag, value ) \ + do \ + { \ + ( global_flag ) = ( value ); \ + } while ( 0 ) +#define B_HELPER_GET_GLOBAL( global_flag ) ( global_flag ) #else -#define B_HELPER_SET_GLOBAL(global_flag, value) do { (void)0; } while(0) /* no-op */ -#define B_HELPER_GET_GLOBAL(global_flag) 0 /* Default to 0 */ +#define B_HELPER_SET_GLOBAL( global_flag, value ) \ + do \ + { \ + (void) 0; \ + } while ( 0 ) /* no-op */ +#define B_HELPER_GET_GLOBAL( global_flag ) 0 /* Default to 0 */ #endif -void set_overflow(Flag *overflow) { if (overflow) *overflow = 1; else { B_HELPER_PRINT_WARNING(); B_HELPER_ABORT(); B_HELPER_SET_GLOBAL(Overflow, 1); } } -void unset_overflow(Flag* overflow) { if (overflow) *overflow = 0; else { B_HELPER_PRINT_WARNING(); B_HELPER_ABORT(); B_HELPER_SET_GLOBAL(Overflow, 0); } } -void set_carry(Flag *carry) { if (carry) *carry = 1; else { B_HELPER_PRINT_WARNING(); B_HELPER_ABORT(); B_HELPER_SET_GLOBAL(Carry, 1); } } -void unset_carry(Flag* carry) { if (carry) *carry = 0; else { B_HELPER_PRINT_WARNING(); B_HELPER_ABORT(); B_HELPER_SET_GLOBAL(Carry, 0); } } -Flag get_carry(const Flag* carry) { if (carry) return *carry; else { B_HELPER_PRINT_WARNING(); B_HELPER_ABORT(); } return B_HELPER_GET_GLOBAL(Carry); } +void set_overflow( Flag *overflow ) +{ + if ( overflow ) + *overflow = 1; + else + { + B_HELPER_PRINT_WARNING(); + B_HELPER_ABORT(); + B_HELPER_SET_GLOBAL( Overflow, 1 ); + } +} +void unset_overflow( Flag *overflow ) +{ + if ( overflow ) + *overflow = 0; + else + { + B_HELPER_PRINT_WARNING(); + B_HELPER_ABORT(); + B_HELPER_SET_GLOBAL( Overflow, 0 ); + } +} +void set_carry( Flag *carry ) +{ + if ( carry ) + *carry = 1; + else + { + B_HELPER_PRINT_WARNING(); + B_HELPER_ABORT(); + B_HELPER_SET_GLOBAL( Carry, 1 ); + } +} +void unset_carry( Flag *carry ) +{ + if ( carry ) + *carry = 0; + else + { + B_HELPER_PRINT_WARNING(); + B_HELPER_ABORT(); + B_HELPER_SET_GLOBAL( Carry, 0 ); + } +} +Flag get_carry( const Flag *carry ) +{ + if ( carry ) + return *carry; + else + { + B_HELPER_PRINT_WARNING(); + B_HELPER_ABORT(); + } + return B_HELPER_GET_GLOBAL( Carry ); +} /* Undef helper macros - these should only be used in functions above */ #undef B_HELPER_PRINT_WARNING @@ -321,7 +418,7 @@ Flag get_carry(const Flag* carry) { if (carry) return *carry; else { B_HELPER_PR #undef B_HELPER_SET_GLOBAL #undef B_HELPER_GET_GLOBAL -#else /* BASOP_NOGLOB */ +#else /* BASOP_NOGLOB */ Flag Overflow = 0; Flag Carry = 0; #endif /* BASOP_NOGLOB */ @@ -492,9 +589,10 @@ Word16 add( Word16 var1, Word16 var2 ) return ( var_out ); } #ifdef BASOP_NOGLOB -Word16 add_sat(Word16 var1, Word16 var2) { - Flag Overflow; - return add_o(var1, var2, &Overflow); +Word16 add_sat( Word16 var1, Word16 var2 ) +{ + Flag Overflow; + return add_o( var1, var2, &Overflow ); } #endif /*___________________________________________________________________________ @@ -560,9 +658,10 @@ Word16 sub( Word16 var1, Word16 var2 ) return ( var_out ); } #ifdef BASOP_NOGLOB -Word16 sub_sat(Word16 var1, Word16 var2) { - Flag Overflow; - return sub_o(var1, var2, &Overflow); +Word16 sub_sat( Word16 var1, Word16 var2 ) +{ + Flag Overflow; + return sub_o( var1, var2, &Overflow ); } #endif /*___________________________________________________________________________ @@ -754,9 +853,10 @@ Word16 shl( Word16 var1, Word16 var2 ) return ( var_out ); } -Word16 shl_sat(Word16 var1, Word16 var2) { - Flag Overflow; - return shl_o(var1, var2, &Overflow); +Word16 shl_sat( Word16 var1, Word16 var2 ) +{ + Flag Overflow; + return shl_o( var1, var2, &Overflow ); } #endif /* BASOP_NOGLOB */ @@ -795,39 +895,47 @@ Word16 shl_sat(Word16 var1, Word16 var2) { |___________________________________________________________________________| */ #ifdef BASOP_NOGLOB -Word16 shr_o(Word16 var1, Word16 var2, Flag *Overflow) { -#else /* BASOP_NOGLOB */ -Word16 shr(Word16 var1, Word16 var2) { +Word16 shr_o( Word16 var1, Word16 var2, Flag *Overflow ) +{ +#else /* BASOP_NOGLOB */ +Word16 shr( Word16 var1, Word16 var2 ) +{ #endif /* BASOP_NOGLOB */ - Word16 var_out; + Word16 var_out; - if (var2 < 0) { - if (var2 < -16) - var2 = -16; - var2 = -var2; + if ( var2 < 0 ) + { + if ( var2 < -16 ) + var2 = -16; + var2 = -var2; #ifdef BASOP_NOGLOB - var_out = shl_o(var1, var2, Overflow); -#else /* BASOP_NOGLOB */ - var_out = shl(var1, var2); + var_out = shl_o( var1, var2, Overflow ); +#else /* BASOP_NOGLOB */ + var_out = shl( var1, var2 ); #endif /* BASOP_NOGLOB */ -#if (WMOPS) - multiCounter[currCounter].shl--; +#if ( WMOPS ) + multiCounter[currCounter].shl--; #endif - } - else { - if (var2 >= 15) { - var_out = (var1 < 0) ? -1 : 0; } - else { - if (var1 < 0) { - var_out = ~((~var1) >> var2); - } - else { - var_out = var1 >> var2; - } + else + { + if ( var2 >= 15 ) + { + var_out = ( var1 < 0 ) ? -1 : 0; + } + else + { + if ( var1 < 0 ) + { + var_out = ~( ( ~var1 ) >> var2 ); + } + else + { + var_out = var1 >> var2; + } + } } - } #ifdef WMOPS multiCounter[currCounter].shr++; @@ -835,16 +943,18 @@ Word16 shr(Word16 var1, Word16 var2) { BASOP_CHECK(); - return (var_out); + return ( var_out ); } #ifdef BASOP_NOGLOB -Word16 shr(Word16 var1, Word16 var2) { - return shr_o(var1, var2, NULL); +Word16 shr( Word16 var1, Word16 var2 ) +{ + return shr_o( var1, var2, NULL ); } -Word16 shr_sat(Word16 var1, Word16 var2) { - Flag Overflow; - return shr_o(var1, var2, &Overflow); +Word16 shr_sat( Word16 var1, Word16 var2 ) +{ + Flag Overflow; + return shr_o( var1, var2, &Overflow ); } #endif /* BASOP_NOGLOB */ @@ -884,32 +994,34 @@ Word16 shr_sat(Word16 var1, Word16 var2) { |___________________________________________________________________________| */ #ifdef BASOP_NOGLOB -Word16 mult_o(Word16 var1, Word16 var2, Flag *Overflow) { -#else /* BASOP_NOGLOB */ -Word16 mult(Word16 var1, Word16 var2) { +Word16 mult_o( Word16 var1, Word16 var2, Flag *Overflow ) +{ +#else /* BASOP_NOGLOB */ +Word16 mult( Word16 var1, Word16 var2 ) +{ #endif /* BASOP_NOGLOB */ - Word16 var_out; - Word32 L_product; + Word16 var_out; + Word32 L_product; - L_product = (Word32)var1 *(Word32)var2; + L_product = (Word32) var1 * (Word32) var2; - L_product = (L_product & (Word32)0xffff8000L) >> 15; + L_product = ( L_product & (Word32) 0xffff8000L ) >> 15; - if (L_product & (Word32)0x00010000L) - L_product = L_product | (Word32)0xffff0000L; + if ( L_product & (Word32) 0x00010000L ) + L_product = L_product | (Word32) 0xffff0000L; #ifdef BASOP_NOGLOB - var_out = saturate_o(L_product, Overflow); -#else /* BASOP_NOGLOB */ - var_out = saturate(L_product); + var_out = saturate_o( L_product, Overflow ); +#else /* BASOP_NOGLOB */ + var_out = saturate( L_product ); #endif /* BASOP_NOGLOB */ #ifdef WMOPS multiCounter[currCounter].mult++; #endif - BASOP_CHECK(); - return (var_out); + BASOP_CHECK(); + return ( var_out ); } #ifdef BASOP_NOGLOB Word16 mult( Word16 var1, Word16 var2 ) @@ -932,9 +1044,10 @@ Word16 mult( Word16 var1, Word16 var2 ) return ( var_out ); } -Word16 mult_sat(Word16 var1, Word16 var2) { - Flag Overflow; - return mult_o(var1, var2, &Overflow); +Word16 mult_sat( Word16 var1, Word16 var2 ) +{ + Flag Overflow; + return mult_o( var1, var2, &Overflow ); } #endif @@ -1032,9 +1145,10 @@ Word32 L_mult( Word16 var1, Word16 var2 ) return ( L_var_out ); } -Word32 L_mult_sat(Word16 var1, Word16 var2) { - Flag Overflow; - return L_mult_o(var1, var2, &Overflow); +Word32 L_mult_sat( Word16 var1, Word16 var2 ) +{ + Flag Overflow; + return L_mult_o( var1, var2, &Overflow ); } #endif /* BASOP_NOGLOB */ @@ -1245,9 +1359,10 @@ Word16 round_fx( Word32 L_var1 ) return ( var_out ); } #ifdef BASOP_NOGLOB -Word16 round_fx_sat(Word32 L_var1) { - Flag Overflow; - return round_fx_o(L_var1, &Overflow); +Word16 round_fx_sat( Word32 L_var1 ) +{ + Flag Overflow; + return round_fx_o( L_var1, &Overflow ); } #endif /*___________________________________________________________________________ @@ -1323,9 +1438,10 @@ Word32 L_mac( Word32 L_var3, Word16 var1, Word16 var2 ) return ( L_var_out ); } #ifdef BASOP_NOGLOB -Word32 L_mac_sat(Word32 L_var3, Word16 var1, Word16 var2) { - Flag Overflow; - return L_mac_o(L_var3, var1, var2, &Overflow); +Word32 L_mac_sat( Word32 L_var3, Word16 var1, Word16 var2 ) +{ + Flag Overflow; + return L_mac_o( L_var3, var1, var2, &Overflow ); } #endif /*___________________________________________________________________________ @@ -1401,9 +1517,10 @@ Word32 L_msu( Word32 L_var3, Word16 var1, Word16 var2 ) return ( L_var_out ); } #ifdef BASOP_NOGLOB -Word32 L_msu_sat(Word32 L_var3, Word16 var1, Word16 var2) { - Flag Overflow; - return L_msu_o(L_var3, var1, var2, &Overflow); +Word32 L_msu_sat( Word32 L_var3, Word16 var1, Word16 var2 ) +{ + Flag Overflow; + return L_msu_o( L_var3, var1, var2, &Overflow ); } #endif /*___________________________________________________________________________ @@ -1471,28 +1588,32 @@ Word32 DEPR_L_macNs( Word32 L_var3, Word16 var1, Word16 var2, Flag *Carry ) } #endif #ifdef BASOP_NOGLOB -Word32 L_macNs_co(Word32 L_var3, Word16 var1, Word16 var2, Flag *Carry, Flag *Overflow) { -#else /* BASOP_NOGLOB */ -Word32 L_macNs(Word32 L_var3, Word16 var1, Word16 var2) { +Word32 L_macNs_co( Word32 L_var3, Word16 var1, Word16 var2, Flag *Carry, Flag *Overflow ) +{ +#else /* BASOP_NOGLOB */ +Word32 L_macNs( Word32 L_var3, Word16 var1, Word16 var2 ) +{ #endif /* BASOP_NOGLOB */ - Word32 L_var_out; + Word32 L_var_out; #ifdef BASOP_NOGLOB - L_var_out = L_mult_o(var1, var2, Overflow); - L_var_out = L_add_co(L_var3, L_var_out, Carry, Overflow); -#else /* BASOP_NOGLOB */ - L_var_out = L_mult(var1, var2); - L_var_out = L_add_c(L_var3, L_var_out); + L_var_out = L_mult_o( var1, var2, Overflow ); + L_var_out = L_add_co( L_var3, L_var_out, Carry, Overflow ); +#else /* BASOP_NOGLOB */ + L_var_out = L_mult( var1, var2 ); + L_var_out = L_add_c( L_var3, L_var_out ); #endif /* BASOP_NOGLOB */ - return (L_var_out); + return ( L_var_out ); } #ifdef BASOP_NOGLOB -Word32 L_macNs(Word32 L_var3, Word16 var1, Word16 var2) { - return L_macNs_co(L_var3, var1, var2, NULL, NULL); +Word32 L_macNs( Word32 L_var3, Word16 var1, Word16 var2 ) +{ + return L_macNs_co( L_var3, var1, var2, NULL, NULL ); } -Word32 L_macNs_sat(Word32 L_var3, Word16 var1, Word16 var2) { - Flag Carry, Overflow; - return L_macNs_co(L_var3, var1, var2, &Carry, &Overflow); +Word32 L_macNs_sat( Word32 L_var3, Word16 var1, Word16 var2 ) +{ + Flag Carry, Overflow; + return L_macNs_co( L_var3, var1, var2, &Carry, &Overflow ); } #endif /*___________________________________________________________________________ @@ -1568,22 +1689,25 @@ Word32 DEPR_L_msuNs( Word32 L_var3, Word16 var1, Word16 var2, Flag *Carry ) } #ifdef BASOP_NOGLOB -Word32 L_msuNs_co(Word32 L_var3, Word16 var1, Word16 var2, Flag *Carry, Flag *Overflow) { - Word32 L_var_out; +Word32 L_msuNs_co( Word32 L_var3, Word16 var1, Word16 var2, Flag *Carry, Flag *Overflow ) +{ + Word32 L_var_out; - L_var_out = L_mult(var1, var2); - L_var_out = L_sub_co(L_var3, L_var_out, Carry, Overflow); + L_var_out = L_mult( var1, var2 ); + L_var_out = L_sub_co( L_var3, L_var_out, Carry, Overflow ); - return (L_var_out); + return ( L_var_out ); } -Word32 L_msuNs(Word32 L_var3, Word16 var1, Word16 var2) { - return L_msuNs_co(L_var3, var1, var2, NULL, NULL); +Word32 L_msuNs( Word32 L_var3, Word16 var1, Word16 var2 ) +{ + return L_msuNs_co( L_var3, var1, var2, NULL, NULL ); } -Word32 L_msuNs_sat(Word32 L_var3, Word16 var1, Word16 var2) { - Flag Carry, Overflow; - return L_msuNs_co(L_var3, var1, var2, &Carry, &Overflow); +Word32 L_msuNs_sat( Word32 L_var3, Word16 var1, Word16 var2 ) +{ + Flag Carry, Overflow; + return L_msuNs_co( L_var3, var1, var2, &Carry, &Overflow ); } #endif /*___________________________________________________________________________ @@ -1671,9 +1795,10 @@ Word32 L_add( Word32 L_var1, Word32 L_var2 ) #endif return ( L_var_out ); } -Word32 L_add_sat(Word32 L_var1, Word32 L_var2) { - Flag Overflow; - return L_add_o(L_var1, L_var2, &Overflow); +Word32 L_add_sat( Word32 L_var1, Word32 L_var2 ) +{ + Flag Overflow; + return L_add_o( L_var1, L_var2, &Overflow ); } #endif /* BASOP_NOGLOB */ @@ -1763,9 +1888,10 @@ Word32 L_sub( Word32 L_var1, Word32 L_var2 ) return ( L_var_out ); } -Word32 L_sub_sat(Word32 L_var1, Word32 L_var2) { - Flag Overflow; - return L_sub_o(L_var1, L_var2, &Overflow); +Word32 L_sub_sat( Word32 L_var1, Word32 L_var2 ) +{ + Flag Overflow; + return L_sub_o( L_var1, L_var2, &Overflow ); } #endif /* BASOP_NOGLOB */ @@ -1931,64 +2057,80 @@ Word32 DEPR_L_add_c( Word32 L_var1, Word32 L_var2, Flag *Carry ) return ( L_var_out ); } #ifdef BASOP_NOGLOB -Word32 L_add_co(Word32 L_var1, Word32 L_var2, Flag *Carry, Flag *Overflow) { - Word32 L_var_out; - Word32 L_test; - Flag carry_int = 0; - - L_var_out = L_var1 + L_var2 + get_carry(Carry); - - L_test = L_var1 + L_var2; - - if ((L_var1 > 0) && (L_var2 > 0) && (L_test < 0)) { - set_overflow(Overflow); - carry_int = 0; - } - else { - if ((L_var1 < 0) && (L_var2 < 0)) { - if (L_test >= 0) { - set_overflow(Overflow); - carry_int = 1; - } - else { - unset_overflow(Overflow); - carry_int = 1; - } - } - else { - if (((L_var1 ^ L_var2) < 0) && (L_test >= 0)) { - unset_overflow(Overflow); - carry_int = 1; - } - else { - unset_overflow(Overflow); +Word32 L_add_co( Word32 L_var1, Word32 L_var2, Flag *Carry, Flag *Overflow ) +{ + Word32 L_var_out; + Word32 L_test; + Flag carry_int = 0; + + L_var_out = L_var1 + L_var2 + get_carry( Carry ); + + L_test = L_var1 + L_var2; + + if ( ( L_var1 > 0 ) && ( L_var2 > 0 ) && ( L_test < 0 ) ) + { + set_overflow( Overflow ); carry_int = 0; - } } - } + else + { + if ( ( L_var1 < 0 ) && ( L_var2 < 0 ) ) + { + if ( L_test >= 0 ) + { + set_overflow( Overflow ); + carry_int = 1; + } + else + { + unset_overflow( Overflow ); + carry_int = 1; + } + } + else + { + if ( ( ( L_var1 ^ L_var2 ) < 0 ) && ( L_test >= 0 ) ) + { + unset_overflow( Overflow ); + carry_int = 1; + } + else + { + unset_overflow( Overflow ); + carry_int = 0; + } + } + } - if (get_carry(Carry)) { - if (L_test == MAX_32) { - set_overflow(Overflow); - carry_int ? set_carry(Carry) : unset_carry(Carry); + if ( get_carry( Carry ) ) + { + if ( L_test == MAX_32 ) + { + set_overflow( Overflow ); + carry_int ? set_carry( Carry ) : unset_carry( Carry ); + } + else + { + if ( L_test == (Word32) 0xFFFFFFFFL ) + { + set_carry( Carry ); + } + else + { + carry_int ? set_carry( Carry ) : unset_carry( Carry ); + } + } } - else { - if (L_test == (Word32)0xFFFFFFFFL) { - set_carry(Carry); - } - else { - carry_int ? set_carry(Carry) : unset_carry(Carry); - } + else + { + carry_int ? set_carry( Carry ) : unset_carry( Carry ); } - } - else { - carry_int ? set_carry(Carry) : unset_carry(Carry); - } - return (L_var_out); + return ( L_var_out ); } -Word32 L_add_c(Word32 L_var1, Word32 L_var2) { - return L_add_co(L_var1, L_var2, NULL, NULL); +Word32 L_add_c( Word32 L_var1, Word32 L_var2 ) +{ + return L_add_co( L_var1, L_var2, NULL, NULL ); } #endif /*___________________________________________________________________________ @@ -2137,48 +2279,60 @@ Word32 DEPR_L_sub_c( Word32 L_var1, Word32 L_var2, Flag *Carry ) return ( L_var_out ); } #ifdef BASOP_NOGLOB -Word32 L_sub_co(Word32 L_var1, Word32 L_var2, Flag *Carry, Flag *Overflow) { - Word32 L_var_out; - Word32 L_test; - Flag carry_int = 0; +Word32 L_sub_co( Word32 L_var1, Word32 L_var2, Flag *Carry, Flag *Overflow ) +{ + Word32 L_var_out; + Word32 L_test; + Flag carry_int = 0; - if (get_carry(Carry)) { - unset_carry(Carry); - if (L_var2 != MIN_32) { - L_var_out = L_add_co(L_var1, -L_var2, Carry, Overflow); - } - else { - L_var_out = L_var1 - L_var2; - if (L_var1 > 0L) { - unset_carry(Carry); - } + if ( get_carry( Carry ) ) + { + unset_carry( Carry ); + if ( L_var2 != MIN_32 ) + { + L_var_out = L_add_co( L_var1, -L_var2, Carry, Overflow ); + } + else + { + L_var_out = L_var1 - L_var2; + if ( L_var1 > 0L ) + { + unset_carry( Carry ); + } + } } - } - else { - L_var_out = L_var1 - L_var2 - (Word32)0X00000001L; - L_test = L_var1 - L_var2; + else + { + L_var_out = L_var1 - L_var2 - (Word32) 0X00000001L; + L_test = L_var1 - L_var2; - if ((L_test < 0) && (L_var1 > 0) && (L_var2 < 0)) { - carry_int = 0; - } - else if ((L_test > 0) && (L_var1 < 0) && (L_var2 > 0)) { - carry_int = 1; - } - else if ((L_test > 0) && ((L_var1 ^ L_var2) > 0)) { - carry_int = 1; - } - if (L_test == MIN_32) { - carry_int ? set_carry(Carry) : unset_carry(Carry); - } - else { - carry_int ? set_carry(Carry) : unset_carry(Carry); + if ( ( L_test < 0 ) && ( L_var1 > 0 ) && ( L_var2 < 0 ) ) + { + carry_int = 0; + } + else if ( ( L_test > 0 ) && ( L_var1 < 0 ) && ( L_var2 > 0 ) ) + { + carry_int = 1; + } + else if ( ( L_test > 0 ) && ( ( L_var1 ^ L_var2 ) > 0 ) ) + { + carry_int = 1; + } + if ( L_test == MIN_32 ) + { + carry_int ? set_carry( Carry ) : unset_carry( Carry ); + } + else + { + carry_int ? set_carry( Carry ) : unset_carry( Carry ); + } } - } - return (L_var_out); + return ( L_var_out ); } -Word32 L_sub_c(Word32 L_var1, Word32 L_var2) { - return L_sub_co(L_var1, L_var2, NULL, NULL); +Word32 L_sub_c( Word32 L_var1, Word32 L_var2 ) +{ + return L_sub_co( L_var1, L_var2, NULL, NULL ); } #endif /*___________________________________________________________________________ @@ -2306,9 +2460,10 @@ Word16 mult_r( Word16 var1, Word16 var2 ) } #ifdef BASOP_NOGLOB -Word16 mult_r_sat(Word16 var1, Word16 var2) { - Flag Overflow; - return mult_ro(var1, var2, &Overflow); +Word16 mult_r_sat( Word16 var1, Word16 var2 ) +{ + Flag Overflow; + return mult_ro( var1, var2, &Overflow ); } #endif /*___________________________________________________________________________ @@ -2454,9 +2609,10 @@ Word32 L_shl( Word32 L_var1, Word16 var2 ) return ( L_var_out ); } -Word32 L_shl_sat(Word32 L_var1, Word16 var2) { - Flag Overflow; - return L_shl_o(L_var1, var2, &Overflow); +Word32 L_shl_sat( Word32 L_var1, Word16 var2 ) +{ + Flag Overflow; + return L_shl_o( L_var1, var2, &Overflow ); } #endif /* BASOP_NOGLOB */ @@ -2580,9 +2736,10 @@ Word32 L_shr( Word32 L_var1, Word16 var2 ) return ( L_var_out ); } #ifdef BASOP_NOGLOB -Word32 L_shr_sat(Word32 L_var1, Word16 var2) { - Flag Overflow; - return L_shr_o(L_var1, var2, &Overflow); +Word32 L_shr_sat( Word32 L_var1, Word16 var2 ) +{ + Flag Overflow; + return L_shr_o( L_var1, var2, &Overflow ); } #endif /*___________________________________________________________________________ @@ -2659,26 +2816,32 @@ Word16 shr_r( Word16 var1, Word16 var2 ) return ( var_out ); } #ifdef BASOP_NOGLOB -Word16 shr_ro(Word16 var1, Word16 var2, Flag* Overflow) { - Word16 var_out; +Word16 shr_ro( Word16 var1, Word16 var2, Flag *Overflow ) +{ + Word16 var_out; - if (var2 > 15) { - var_out = 0; - } - else { - var_out = shr_o(var1, var2, Overflow); + if ( var2 > 15 ) + { + var_out = 0; + } + else + { + var_out = shr_o( var1, var2, Overflow ); - if (var2 > 0) { - if ((var1 & ((Word16)1 << (var2 - 1))) != 0) { - var_out++; - } + if ( var2 > 0 ) + { + if ( ( var1 & ( (Word16) 1 << ( var2 - 1 ) ) ) != 0 ) + { + var_out++; + } + } } - } - return (var_out); + return ( var_out ); } -Word16 shr_r_sat(Word16 var1, Word16 var2) { - Flag Overflow; - return shr_ro(var1, var2, &Overflow); +Word16 shr_r_sat( Word16 var1, Word16 var2 ) +{ + Flag Overflow; + return shr_ro( var1, var2, &Overflow ); } #endif /*___________________________________________________________________________ @@ -2763,9 +2926,10 @@ Word16 mac_r( Word32 L_var3, Word16 var1, Word16 var2 ) return ( var_out ); } #ifdef BASOP_NOGLOB -Word16 mac_r_sat(Word32 L_var3, Word16 var1, Word16 var2) { - Flag Overflow; - return mac_ro(L_var3, var1, var2, &Overflow); +Word16 mac_r_sat( Word32 L_var3, Word16 var1, Word16 var2 ) +{ + Flag Overflow; + return mac_ro( L_var3, var1, var2, &Overflow ); } #endif /*___________________________________________________________________________ @@ -2846,9 +3010,10 @@ Word16 msu_r( Word32 L_var3, Word16 var1, Word16 var2 ) return ( var_out ); } #ifdef BASOP_NOGLOB -Word16 msu_r_sat(Word32 L_var3, Word16 var1, Word16 var2) { - Flag Overflow; - return msu_ro(L_var3, var1, var2, &Overflow); +Word16 msu_r_sat( Word32 L_var3, Word16 var1, Word16 var2 ) +{ + Flag Overflow; + return msu_ro( L_var3, var1, var2, &Overflow ); } #endif /*___________________________________________________________________________ @@ -3016,26 +3181,32 @@ Word32 L_shr_r( Word32 L_var1, Word16 var2 ) return ( L_var_out ); } #ifdef BASOP_NOGLOB -Word32 L_shr_ro(Word32 L_var1, Word16 var2, Flag * Overflow) { - Word32 L_var_out; +Word32 L_shr_ro( Word32 L_var1, Word16 var2, Flag *Overflow ) +{ + Word32 L_var_out; - if (var2 > 31) { - L_var_out = 0; - } - else { - L_var_out = L_shr_o(L_var1, var2, Overflow); - if (var2 > 0) { - if ((L_var1 & ((Word32)1 << (var2 - 1))) != 0) { - L_var_out++; - } + if ( var2 > 31 ) + { + L_var_out = 0; } - } - return (L_var_out); + else + { + L_var_out = L_shr_o( L_var1, var2, Overflow ); + if ( var2 > 0 ) + { + if ( ( L_var1 & ( (Word32) 1 << ( var2 - 1 ) ) ) != 0 ) + { + L_var_out++; + } + } + } + return ( L_var_out ); } -Word32 L_shr_r_sat(Word32 L_var1, Word16 var2) { - Flag Overflow = 0; - return L_shr_ro(L_var1, var2, &Overflow); +Word32 L_shr_r_sat( Word32 L_var1, Word16 var2 ) +{ + Flag Overflow = 0; + return L_shr_ro( L_var1, var2, &Overflow ); } #endif /*___________________________________________________________________________ @@ -3165,27 +3336,31 @@ Word32 DEPR_L_sat_co( Word32 L_var1, Flag Overflow, Flag Carry ) return ( L_var_out ); } #ifdef BASOP_NOGLOB -Word32 L_sat_co(Word32 L_var1, Flag Carry, Flag Overflow) { - Word32 L_var_out; +Word32 L_sat_co( Word32 L_var1, Flag Carry, Flag Overflow ) +{ + Word32 L_var_out; - L_var_out = L_var1; + L_var_out = L_var1; - if (Overflow) { + if ( Overflow ) + { - if (Carry) { - L_var_out = MIN_32; - } - else { - L_var_out = MAX_32; + if ( Carry ) + { + L_var_out = MIN_32; + } + else + { + L_var_out = MAX_32; + } } - - } - return (L_var_out); + return ( L_var_out ); } -Word32 L_sat(Word32 L_var1) { - assert(0); /* Overflow and Carry are no longer global, must be passed as parameters */ - return L_sat_co(L_var1, 0, 0); +Word32 L_sat( Word32 L_var1 ) +{ + assert( 0 ); /* Overflow and Carry are no longer global, must be passed as parameters */ + return L_sat_co( L_var1, 0, 0 ); } #endif /*___________________________________________________________________________ @@ -3521,9 +3696,10 @@ Word32 L_mls( Word32 Lv, Word16 v ) return Temp; } #ifdef BASOP_NOGLOB -Word32 L_mls_sat(Word32 Lv, Word16 v) { - Flag Overflow; - return L_mls_o(Lv, v, &Overflow); +Word32 L_mls_sat( Word32 Lv, Word16 v ) +{ + Flag Overflow; + return L_mls_o( Lv, v, &Overflow ); } #endif @@ -3681,20 +3857,23 @@ Word16 DEPR_i_mult( Word16 a, Word16 b ) } #ifdef BASOP_NOGLOB -Word16 i_mult_o(Word16 a, Word16 b, Flag* Overflow) { +Word16 i_mult_o( Word16 a, Word16 b, Flag *Overflow ) +{ #ifdef ORIGINAL_G7231 - return a * b; + return a * b; #else - register Word32 c = a * b; - return saturate_o(c, Overflow); + register Word32 c = a * b; + return saturate_o( c, Overflow ); #endif } -Word16 i_mult(Word16 a, Word16 b) { - return i_mult_o(a, b, NULL); +Word16 i_mult( Word16 a, Word16 b ) +{ + return i_mult_o( a, b, NULL ); } -Word16 i_mult_sat(Word16 a, Word16 b) { - Flag Overflow; - return i_mult_o(a, b, &Overflow); +Word16 i_mult_sat( Word16 a, Word16 b ) +{ + Flag Overflow; + return i_mult_o( a, b, &Overflow ); } #endif /* @@ -3817,9 +3996,10 @@ Word32 L_mac0( Word32 L_var3, Word16 var1, Word16 var2 ) return ( L_var_out ); } #ifdef BASOP_NOGLOB -Word32 L_mac0_sat(Word32 L_var3, Word16 var1, Word16 var2) { - Flag Overflow; - return L_mac0_o(L_var3, var1, var2, &Overflow); +Word32 L_mac0_sat( Word32 L_var3, Word16 var1, Word16 var2 ) +{ + Flag Overflow; + return L_mac0_o( L_var3, var1, var2, &Overflow ); } #endif /*___________________________________________________________________________ @@ -3893,9 +4073,10 @@ Word32 L_msu0( Word32 L_var3, Word16 var1, Word16 var2 ) return ( L_var_out ); } #ifdef BASOP_NOGLOB -Word32 L_msu0_sat(Word32 L_var3, Word16 var1, Word16 var2) { - Flag Overflow; - return L_msu0_o(L_var3, var1, var2, &Overflow); +Word32 L_msu0_sat( Word32 L_var3, Word16 var1, Word16 var2 ) +{ + Flag Overflow; + return L_msu0_o( L_var3, var1, var2, &Overflow ); } #endif diff --git a/lib_com/basop32.h b/lib_com/basop32.h index 535b08d09..785a4bf56 100644 --- a/lib_com/basop32.h +++ b/lib_com/basop32.h @@ -115,11 +115,11 @@ extern Flag BASOP_Carry; #define MAX_16 (Word16) 0x7fff #define MIN_16 (Word16) 0x8000 #ifdef BASOP_NOGLOB -void set_overflow(Flag *overflow); -void unset_overflow(Flag* overflow); -void set_carry(Flag *carry); -void unset_carry(Flag* carry); -Flag get_carry(const Flag* carry); +void set_overflow( Flag *overflow ); +void unset_overflow( Flag *overflow ); +void set_carry( Flag *carry ); +void unset_carry( Flag *carry ); +Flag get_carry( const Flag *carry ); #endif /* BASOP_NOGLOB */ /*___________________________________________________________________________ | | @@ -159,14 +159,14 @@ Word32 L_mac( Word32 L_var3, Word16 var1, Word16 var2 ); /* Word32 L_msu( Word32 L_var3, Word16 var1, Word16 var2 ); /* Msu, 1 */ Word32 DEPR_L_macNs( Word32 L_var3, Word16 var1, Word16 var2, Flag *Carry ); /* Mac without sat, 1 */ -Word32 L_macNs(Word32 L_var3, Word16 var1, Word16 var2); /* Mac without sat, 1 */ -Word32 L_msuNs(Word32 L_var3, Word16 var1, Word16 var2); /* Msu without sat, 1 */ -Word32 L_add_co(Word32 L_var1, Word32 L_var2, Flag * Carry, Flag *Overflow); -Word32 L_sub_co(Word32 L_var1, Word32 L_var2, Flag * Carry, Flag *Overflow); -Word32 L_add_c(Word32 L_var1, Word32 L_var2); /* Long add with c, 2 */ -Word32 L_sub_c(Word32 L_var1, Word32 L_var2); /* Long sub with c, 2 */ +Word32 L_macNs( Word32 L_var3, Word16 var1, Word16 var2 ); /* Mac without sat, 1 */ +Word32 L_msuNs( Word32 L_var3, Word16 var1, Word16 var2 ); /* Msu without sat, 1 */ +Word32 L_add_co( Word32 L_var1, Word32 L_var2, Flag *Carry, Flag *Overflow ); +Word32 L_sub_co( Word32 L_var1, Word32 L_var2, Flag *Carry, Flag *Overflow ); +Word32 L_add_c( Word32 L_var1, Word32 L_var2 ); /* Long add with c, 2 */ +Word32 L_sub_c( Word32 L_var1, Word32 L_var2 ); /* Long sub with c, 2 */ -#endif /* BASOP_NOGLOB */ +#endif /* BASOP_NOGLOB */ #ifndef BASOP_NOGLOB Word32 L_msuNs( Word32 L_var3, Word16 var1, Word16 var2 ); /* Msu without @@ -239,9 +239,9 @@ Word32 L_abs( Word32 L_var1 ); /* Word32 DEPR_L_sat_co( Word32 L_var1, Flag Overflow, Flag Carry ); /* Long saturation, 4 */ Word16 norm_s( Word16 var1 ); /* Short norm, 1 */ Word16 div_s( Word16 var1, Word16 var2 ); /* Short division, 18 */ -Word32 div_w(Word32 L_num, Word32 L_den); -Word16 norm_l( Word32 L_var1 ); /* Long norm, 1 */ -Word32 L_sat(Word32 L_var1); /* Long saturation, 4 */ +Word32 div_w( Word32 L_num, Word32 L_den ); +Word16 norm_l( Word32 L_var1 ); /* Long norm, 1 */ +Word32 L_sat( Word32 L_var1 ); /* Long saturation, 4 */ #endif /* BASOP_NOGLOB */ @@ -253,10 +253,10 @@ Word32 L_mls( Word32, Word16 ); /* Weight FFS; currently assigned 5 */ Word16 div_l( Word32, Word16 ); /* Weight FFS; currently assigned 32 */ Word16 i_mult( Word16 a, Word16 b ); /* Weight FFS; currently assigned 3 */ #else /* BASOP_NOGLOB */ -Word32 L_mls( Word32, Word16 ); /* Weight FFS; currently assigned 5 */ -Word16 div_l( Word32, Word16 ); /* Weight FFS; currently assigned 32 */ -Word16 i_mult(Word16 a, Word16 b); /* Weight FFS; currently assigned 3 */ -Word16 DEPR_i_mult( Word16 a, Word16 b ); /* Weight FFS; currently assigned 3 */ +Word32 L_mls( Word32, Word16 ); /* Weight FFS; currently assigned 5 */ +Word16 div_l( Word32, Word16 ); /* Weight FFS; currently assigned 32 */ +Word16 i_mult( Word16 a, Word16 b ); /* Weight FFS; currently assigned 3 */ +Word16 DEPR_i_mult( Word16 a, Word16 b ); /* Weight FFS; currently assigned 3 */ #endif /* BASOP_NOGLOB */ /* @@ -270,12 +270,12 @@ Word32 L_msu0( Word32 L_v3, Word16 v1, Word16 v2 ); /* 32-bit Msu w/o shift 1 * /* * Overflowing operators */ -Word16 i_mult_o(Word16 a, Word16 b, Flag* Overflow); +Word16 i_mult_o( Word16 a, Word16 b, Flag *Overflow ); Word16 add_o( Word16 var1, Word16 var2, Flag *Overflow ); Word16 sub_o( Word16 var1, Word16 var2, Flag *Overflow ); Word16 shl_o( Word16 var1, Word16 var2, Flag *Overflow ); -Word16 shr_o(Word16 var1, Word16 var2, Flag * Overflow); -Word16 shr_ro(Word16 var1, Word16 var2, Flag* Overflow); +Word16 shr_o( Word16 var1, Word16 var2, Flag *Overflow ); +Word16 shr_ro( Word16 var1, Word16 var2, Flag *Overflow ); Word16 mult_o( Word16 var1, Word16 var2, Flag *Overflow ); Word32 L_mult_o( Word16 var1, Word16 var2, Flag *Overflow ); Word16 round_fx_o( Word32 L_var1, Flag *Overflow ); @@ -291,40 +291,40 @@ Word32 L_msu0_o( Word32 L_var3, Word16 var1, Word16 var2, Flag *Overflow ); Word16 mult_ro( Word16 var1, Word16 var2, Flag *Overflow ); Word16 mac_ro( Word32 L_var3, Word16 var1, Word16 var2, Flag *Overflow ); Word16 msu_ro( Word32 L_var3, Word16 var1, Word16 var2, Flag *Overflow ); -Word32 L_sat_co(Word32 L_var1, Flag Carry, Flag Overflow); -Word32 L_shr_ro(Word32 L_var1, Word16 var2, Flag* Overflow); -Word32 L_macNs_co(Word32 L_var3, Word16 var1, Word16 var2, Flag * Carry, Flag* Overflow); -Word32 L_msuNs_co(Word32 L_var3, Word16 var1, Word16 var2, Flag * Carry, Flag* Overflow); +Word32 L_sat_co( Word32 L_var1, Flag Carry, Flag Overflow ); +Word32 L_shr_ro( Word32 L_var1, Word16 var2, Flag *Overflow ); +Word32 L_macNs_co( Word32 L_var3, Word16 var1, Word16 var2, Flag *Carry, Flag *Overflow ); +Word32 L_msuNs_co( Word32 L_var3, Word16 var1, Word16 var2, Flag *Carry, Flag *Overflow ); #endif /* BASOP_NOGLOB */ /* * Saturating operators */ -Word16 i_mult_sat(Word16 a, Word16 b); -Word16 add_sat(Word16 var1, Word16 var2); -Word16 sub_sat(Word16 var1, Word16 var2); -Word16 shl_sat(Word16 var1, Word16 var2); -Word16 shr_sat(Word16 var1, Word16 var2); -Word16 shr_r_sat(Word16 var1, Word16 var2); -Word16 mult_sat(Word16 var1, Word16 var2); -Word32 L_mult_sat(Word16 var1, Word16 var2); -Word16 round_fx_sat(Word32 L_var1); -Word32 L_mac_sat(Word32 L_var3, Word16 var1, Word16 var2); -Word32 L_msu_sat(Word32 L_var3, Word16 var1, Word16 var2); -Word32 L_macNs_sat(Word32 L_var3, Word16 var1, Word16 var2); -Word32 L_msuNs_sat(Word32 L_var3, Word16 var1, Word16 var2); -Word32 L_add_sat(Word32 L_var1, Word32 L_var2); -Word32 L_sub_sat(Word32 L_var1, Word32 L_var2); -Word32 L_shr_sat(Word32 L_var1, Word16 var2); -Word32 L_shl_sat(Word32 L_var1, Word16 var2); -Word32 L_mls_sat(Word32 Lv, Word16 v); -Word32 L_mac0_sat(Word32 L_var3, Word16 var1, Word16 var2); -Word32 L_msu0_sat(Word32 L_var3, Word16 var1, Word16 var2); -Word16 mult_r_sat(Word16 var1, Word16 var2); -Word16 mac_r_sat(Word32 L_var3, Word16 var1, Word16 var2); -Word16 msu_r_sat(Word32 L_var3, Word16 var1, Word16 var2); -Word32 L_shr_r_sat(Word32 L_var1, Word16 var2); +Word16 i_mult_sat( Word16 a, Word16 b ); +Word16 add_sat( Word16 var1, Word16 var2 ); +Word16 sub_sat( Word16 var1, Word16 var2 ); +Word16 shl_sat( Word16 var1, Word16 var2 ); +Word16 shr_sat( Word16 var1, Word16 var2 ); +Word16 shr_r_sat( Word16 var1, Word16 var2 ); +Word16 mult_sat( Word16 var1, Word16 var2 ); +Word32 L_mult_sat( Word16 var1, Word16 var2 ); +Word16 round_fx_sat( Word32 L_var1 ); +Word32 L_mac_sat( Word32 L_var3, Word16 var1, Word16 var2 ); +Word32 L_msu_sat( Word32 L_var3, Word16 var1, Word16 var2 ); +Word32 L_macNs_sat( Word32 L_var3, Word16 var1, Word16 var2 ); +Word32 L_msuNs_sat( Word32 L_var3, Word16 var1, Word16 var2 ); +Word32 L_add_sat( Word32 L_var1, Word32 L_var2 ); +Word32 L_sub_sat( Word32 L_var1, Word32 L_var2 ); +Word32 L_shr_sat( Word32 L_var1, Word16 var2 ); +Word32 L_shl_sat( Word32 L_var1, Word16 var2 ); +Word32 L_mls_sat( Word32 Lv, Word16 v ); +Word32 L_mac0_sat( Word32 L_var3, Word16 var1, Word16 var2 ); +Word32 L_msu0_sat( Word32 L_var3, Word16 var1, Word16 var2 ); +Word16 mult_r_sat( Word16 var1, Word16 var2 ); +Word16 mac_r_sat( Word32 L_var3, Word16 var1, Word16 var2 ); +Word16 msu_r_sat( Word32 L_var3, Word16 var1, Word16 var2 ); +Word32 L_shr_r_sat( Word32 L_var1, Word16 var2 ); #endif /* ifndef _BASIC_OP_H */ diff --git a/lib_com/basop_tcx_utils.c b/lib_com/basop_tcx_utils.c index 88a2a7bb4..f189a5752 100644 --- a/lib_com/basop_tcx_utils.c +++ b/lib_com/basop_tcx_utils.c @@ -47,18 +47,18 @@ /* compare two positive normalized 16 bit mantissa/exponent values */ /* return value: positive if first value greater, negative if second value greater, zero if equal */ -//static Word16 compMantExp16Unorm( Word16 m1, Word16 e1, Word16 m2, Word16 e2 ) +// static Word16 compMantExp16Unorm( Word16 m1, Word16 e1, Word16 m2, Word16 e2 ) //{ -// Word16 tmp; +// Word16 tmp; // -// assert( ( m1 >= 0x4000 ) && ( m2 >= 0x4000 ) ); /* comparisons below work only for normalized mantissas */ +// assert( ( m1 >= 0x4000 ) && ( m2 >= 0x4000 ) ); /* comparisons below work only for normalized mantissas */ // -// tmp = sub( e1, e2 ); -// if ( tmp == 0 ) -// tmp = sub( m1, m2 ); +// tmp = sub( e1, e2 ); +// if ( tmp == 0 ) +// tmp = sub( m1, m2 ); // -// return tmp; -//} +// return tmp; +// } void basop_lpc2mdct( Word16 *lpcCoeffs, Word16 lpcOrder, Word16 *mdct_gains, Word16 *mdct_gains_exp, Word16 *mdct_inv_gains, Word16 *mdct_inv_gains_exp ) { diff --git a/lib_com/basop_util.c b/lib_com/basop_util.c index 2760f4feb..4044484d3 100644 --- a/lib_com/basop_util.c +++ b/lib_com/basop_util.c @@ -58,634 +58,632 @@ extern const Word16 ISqrtDiffTable[32]; extern const Word32 InvTable[32]; extern const Word16 InvDiffTable[32]; -Word32 BASOP_Util_Log2(Word32 x) +Word32 BASOP_Util_Log2( Word32 x ) { - Word32 exp; - Word16 exp_e; - Word16 nIn; - Word16 accuSqr; - Word32 accuRes; + Word32 exp; + Word16 exp_e; + Word16 nIn; + Word16 accuSqr; + Word32 accuRes; + assert( x >= 0 ); - assert(x >= 0); - - if (x == 0) - { + if ( x == 0 ) + { - return ((Word32)MIN_32); - } + return ( (Word32) MIN_32 ); + } - /* normalize input, calculate integer part */ - exp_e = norm_l(x); - x = L_shl(x, exp_e); - exp = L_deposit_l(exp_e); + /* normalize input, calculate integer part */ + exp_e = norm_l( x ); + x = L_shl( x, exp_e ); + exp = L_deposit_l( exp_e ); - /* calculate (1-normalized_input) */ - nIn = extract_h(L_sub(MAX_32, x)); + /* calculate (1-normalized_input) */ + nIn = extract_h( L_sub( MAX_32, x ) ); - /* approximate ln() for fractional part (nIn *c0 + nIn^2*c1 + nIn^3*c2 + ... + nIn^8 *c7) */ + /* approximate ln() for fractional part (nIn *c0 + nIn^2*c1 + nIn^3*c2 + ... + nIn^8 *c7) */ - /* iteration 1, no need for accumulation */ - accuRes = L_mult(nIn, ldCoeff[0]); /* nIn^i * coeff[0] */ - accuSqr = mult(nIn, nIn); /* nIn^2, nIn^3 .... */ + /* iteration 1, no need for accumulation */ + accuRes = L_mult( nIn, ldCoeff[0] ); /* nIn^i * coeff[0] */ + accuSqr = mult( nIn, nIn ); /* nIn^2, nIn^3 .... */ - /* iteration 2 */ - accuRes = L_mac(accuRes, accuSqr, ldCoeff[1]); /* nIn^i * coeff[1] */ - accuSqr = mult(accuSqr, nIn); /* nIn^2, nIn^3 .... */ + /* iteration 2 */ + accuRes = L_mac( accuRes, accuSqr, ldCoeff[1] ); /* nIn^i * coeff[1] */ + accuSqr = mult( accuSqr, nIn ); /* nIn^2, nIn^3 .... */ - /* iteration 3 */ - accuRes = L_mac(accuRes, accuSqr, ldCoeff[2]); /* nIn^i * coeff[2] */ - accuSqr = mult(accuSqr, nIn); /* nIn^2, nIn^3 .... */ + /* iteration 3 */ + accuRes = L_mac( accuRes, accuSqr, ldCoeff[2] ); /* nIn^i * coeff[2] */ + accuSqr = mult( accuSqr, nIn ); /* nIn^2, nIn^3 .... */ - /* iteration 4 */ - accuRes = L_mac(accuRes, accuSqr, ldCoeff[3]); /* nIn^i * coeff[3] */ - accuSqr = mult(accuSqr, nIn); /* nIn^2, nIn^3 .... */ + /* iteration 4 */ + accuRes = L_mac( accuRes, accuSqr, ldCoeff[3] ); /* nIn^i * coeff[3] */ + accuSqr = mult( accuSqr, nIn ); /* nIn^2, nIn^3 .... */ - /* iteration 5 */ - accuRes = L_mac(accuRes, accuSqr, ldCoeff[4]); /* nIn^i * coeff[4] */ - accuSqr = mult(accuSqr, nIn); /* nIn^2, nIn^3 .... */ + /* iteration 5 */ + accuRes = L_mac( accuRes, accuSqr, ldCoeff[4] ); /* nIn^i * coeff[4] */ + accuSqr = mult( accuSqr, nIn ); /* nIn^2, nIn^3 .... */ - /* iteration 6 */ - accuRes = L_mac(accuRes, accuSqr, ldCoeff[5]); /* nIn^i * coeff[5] */ - accuSqr = mult(accuSqr, nIn); /* nIn^2, nIn^3 .... */ + /* iteration 6 */ + accuRes = L_mac( accuRes, accuSqr, ldCoeff[5] ); /* nIn^i * coeff[5] */ + accuSqr = mult( accuSqr, nIn ); /* nIn^2, nIn^3 .... */ - /* iteration 7, no need to calculate accuSqr any more */ - accuRes = L_mac(accuRes, accuSqr, ldCoeff[6]); /* nIn^i * coeff[6] */ + /* iteration 7, no need to calculate accuSqr any more */ + accuRes = L_mac( accuRes, accuSqr, ldCoeff[6] ); /* nIn^i * coeff[6] */ - /* ld(fractional part) = ln(fractional part)/ln(2), 1/ln(2) = (1 + 0.44269504) */ - accuRes = L_mac0(L_shr(accuRes, 1), extract_h(accuRes), 14506); + /* ld(fractional part) = ln(fractional part)/ln(2), 1/ln(2) = (1 + 0.44269504) */ + accuRes = L_mac0( L_shr( accuRes, 1 ), extract_h( accuRes ), 14506 ); - accuRes = L_shr(accuRes, LD_DATA_SCALE - 1); /* fractional part/LD_DATA_SCALE */ - exp = L_shl(exp, (31 - LD_DATA_SCALE)); /* integer part/LD_DATA_SCALE */ - accuRes = L_sub(accuRes, exp); /* result = integer part + fractional part */ + accuRes = L_shr( accuRes, LD_DATA_SCALE - 1 ); /* fractional part/LD_DATA_SCALE */ + exp = L_shl( exp, ( 31 - LD_DATA_SCALE ) ); /* integer part/LD_DATA_SCALE */ + accuRes = L_sub( accuRes, exp ); /* result = integer part + fractional part */ - return (accuRes); + return ( accuRes ); } -Word32 BASOP_Util_InvLog2(Word32 x) +Word32 BASOP_Util_InvLog2( Word32 x ) { - Word16 frac; - Word16 exp; - Word32 retVal; - UWord32 index3; - UWord32 index2; - UWord32 index1; - UWord32 lookup3f; - UWord32 lookup12; - UWord32 lookup; - + Word16 frac; + Word16 exp; + Word32 retVal; + UWord32 index3; + UWord32 index2; + UWord32 index1; + UWord32 lookup3f; + UWord32 lookup12; + UWord32 lookup; - if (x < -1040187392l/*-31.0/64.0 Q31*/) - { + if ( x < -1040187392l /*-31.0/64.0 Q31*/ ) + { - return 0; - } - test(); - if ((GE_32(x, 1040187392l/*31.0/64.0 Q31*/)) || (x == 0)) - { + return 0; + } + test(); + if ( ( GE_32( x, 1040187392l /*31.0/64.0 Q31*/ ) ) || ( x == 0 ) ) + { - return 0x7FFFFFFF; - } + return 0x7FFFFFFF; + } - frac = extract_l(L_and(x, 0x3FF)); + frac = extract_l( L_and( x, 0x3FF ) ); - index3 = L_and(L_shr(x, 10), 0x1F); - index2 = L_and(L_shr(x, 15), 0x1F); - index1 = L_and(L_shr(x, 20), 0x1F); + index3 = L_and( L_shr( x, 10 ), 0x1F ); + index2 = L_and( L_shr( x, 15 ), 0x1F ); + index1 = L_and( L_shr( x, 20 ), 0x1F ); - exp = extract_l(L_shr(x, 25)); - if (x > 0) - { - exp = sub(31, exp); - } - if (x < 0) - { - exp = negate(exp); - } + exp = extract_l( L_shr( x, 25 ) ); + if ( x > 0 ) + { + exp = sub( 31, exp ); + } + if ( x < 0 ) + { + exp = negate( exp ); + } - lookup3f = L_add(exp2x_tab_long[index3], L_shr(Mpy_32_16_1(0x0016302F, frac), 1)); - lookup12 = Mpy_32_32(exp2_tab_long[index1], exp2w_tab_long[index2]); - lookup = Mpy_32_32(lookup12, lookup3f); + lookup3f = L_add( exp2x_tab_long[index3], L_shr( Mpy_32_16_1( 0x0016302F, frac ), 1 ) ); + lookup12 = Mpy_32_32( exp2_tab_long[index1], exp2w_tab_long[index2] ); + lookup = Mpy_32_32( lookup12, lookup3f ); - retVal = L_shr(lookup, sub(exp, 3)); + retVal = L_shr( lookup, sub( exp, 3 ) ); - return retVal; + return retVal; } -Word16 BASOP_Util_Add_MantExp /*!< Exponent of result */ -(Word16 a_m, /*!< Mantissa of 1st operand a */ - Word16 a_e, /*!< Exponent of 1st operand a */ - Word16 b_m, /*!< Mantissa of 2nd operand b */ - Word16 b_e, /*!< Exponent of 2nd operand b */ - Word16 *ptrSum_m) /*!< Mantissa of result */ +Word16 BASOP_Util_Add_MantExp /*!< Exponent of result */ + ( Word16 a_m, /*!< Mantissa of 1st operand a */ + Word16 a_e, /*!< Exponent of 1st operand a */ + Word16 b_m, /*!< Mantissa of 2nd operand b */ + Word16 b_e, /*!< Exponent of 2nd operand b */ + Word16 *ptrSum_m ) /*!< Mantissa of result */ { - Word32 L_lm, L_hm; - Word16 shift; + Word32 L_lm, L_hm; + Word16 shift; + /* Compare exponents: the difference is limited to +/- 15 + The Word16 mantissa of the operand with higher exponent is moved into the low + part of a Word32 and shifted left by the exponent difference. Then, the + unshifted mantissa of the operand with the lower exponent is added to the lower + 16 bits. The addition result is normalized and the upper Word16 of the result represents + the mantissa to return. The returned exponent takes into account all shift operations + including the final 16-bit extraction. + Note: The resulting mantissa may be inaccurate in the case, where the mantissa of the operand + with higher exponent is not really left-aligned, while the mantissa of the operand with + lower exponent is so. If in such a case, the difference in exponents is more than 15, + an inaccuracy is introduced. + Example: + A: a_e = 20, a_m = 0x0001 + B: b_e = 0, b_m = 0x4000 + correct: A+B=1*2^20+1*2^14=0x0010.0000+0x0000.4000=0x0010.4000=0x4100*2^6 + previously: A+B=1*2^20+1*2^14=0x0001+0x0000=0x0001*2^20 + this version: A+B=1*2^20+1*2^14=0x0000.8000+0x0000.4000=0x6000*2^6 + */ - /* Compare exponents: the difference is limited to +/- 15 - The Word16 mantissa of the operand with higher exponent is moved into the low - part of a Word32 and shifted left by the exponent difference. Then, the - unshifted mantissa of the operand with the lower exponent is added to the lower - 16 bits. The addition result is normalized and the upper Word16 of the result represents - the mantissa to return. The returned exponent takes into account all shift operations - including the final 16-bit extraction. - Note: The resulting mantissa may be inaccurate in the case, where the mantissa of the operand - with higher exponent is not really left-aligned, while the mantissa of the operand with - lower exponent is so. If in such a case, the difference in exponents is more than 15, - an inaccuracy is introduced. - Example: - A: a_e = 20, a_m = 0x0001 - B: b_e = 0, b_m = 0x4000 - correct: A+B=1*2^20+1*2^14=0x0010.0000+0x0000.4000=0x0010.4000=0x4100*2^6 - previously: A+B=1*2^20+1*2^14=0x0001+0x0000=0x0001*2^20 - this version: A+B=1*2^20+1*2^14=0x0000.8000+0x0000.4000=0x6000*2^6 - */ + shift = sub( a_e, b_e ); + if ( shift >= 0 ) + shift = s_min( 15, shift ); - shift = sub(a_e, b_e); - if (shift >= 0) - shift = s_min(15, shift); + if ( shift < 0 ) + shift = s_max( -15, shift ); + a_e = s_max( a_e, b_e ); + L_hm = L_deposit_l( a_m ); /* mantissa belonging to higher exponent */ + L_lm = L_deposit_l( a_m ); /* mantissa belonging to lower exponent */ + if ( shift >= 0 ) + L_lm = L_deposit_l( b_m ); + if ( shift < 0 ) + L_hm = L_deposit_l( b_m ); - if (shift < 0) - shift = s_max(-15, shift); - a_e = s_max(a_e, b_e); - L_hm = L_deposit_l(a_m); /* mantissa belonging to higher exponent */ - L_lm = L_deposit_l(a_m); /* mantissa belonging to lower exponent */ - if (shift >= 0) - L_lm = L_deposit_l(b_m); - if (shift < 0) - L_hm = L_deposit_l(b_m); - - if (shift > 0) - shift = negate(shift); - - L_hm = L_shr(L_hm, shift); /* shift left due to negative shift parameter */ - a_e = add(a_e, shift); - L_hm = L_add(L_hm, L_lm); - shift = norm_l(L_hm); - L_hm = L_shl(L_hm, shift); - *ptrSum_m = extract_h(L_hm); - move16(); - - a_e = sub(a_e, shift); - if (L_hm) - a_e = add(a_e, 16); - return (a_e); -} - - -void BASOP_Util_Divide_MantExp(Word16 a_m, /*!< Mantissa of dividend a */ - Word16 a_e, /*!< Exponent of dividend a */ - Word16 b_m, /*!< Mantissa of divisor b */ - Word16 b_e, /*!< Exponent of divisor b */ - Word16 *ptrResult_m, /*!< Mantissa of quotient a/b */ - Word16 *ptrResult_e /*!< Exponent of quotient a/b */ + if ( shift > 0 ) + shift = negate( shift ); + + L_hm = L_shr( L_hm, shift ); /* shift left due to negative shift parameter */ + a_e = add( a_e, shift ); + L_hm = L_add( L_hm, L_lm ); + shift = norm_l( L_hm ); + L_hm = L_shl( L_hm, shift ); + *ptrSum_m = extract_h( L_hm ); + move16(); + + a_e = sub( a_e, shift ); + if ( L_hm ) + a_e = add( a_e, 16 ); + return ( a_e ); +} + + +void BASOP_Util_Divide_MantExp( Word16 a_m, /*!< Mantissa of dividend a */ + Word16 a_e, /*!< Exponent of dividend a */ + Word16 b_m, /*!< Mantissa of divisor b */ + Word16 b_e, /*!< Exponent of divisor b */ + Word16 *ptrResult_m, /*!< Mantissa of quotient a/b */ + Word16 *ptrResult_e /*!< Exponent of quotient a/b */ ) { - Word16 index, frac; - Word16 preShift, postShift; - Word16 m; - Word32 m32; + Word16 index, frac; + Word16 preShift, postShift; + Word16 m; + Word32 m32; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; + Flag Overflow = 0; #endif + assert( b_m != 0 ); - assert(b_m != 0); - - /* normalize b */ - preShift = norm_s(b_m); - m = shl(b_m, preShift); + /* normalize b */ + preShift = norm_s( b_m ); + m = shl( b_m, preShift ); - /* make b positive */ - BASOP_SATURATE_WARNING_OFF_EVS; - if (m < 0) m = negate(m); - BASOP_SATURATE_WARNING_ON_EVS; + /* make b positive */ + BASOP_SATURATE_WARNING_OFF_EVS; + if ( m < 0 ) + m = negate( m ); + BASOP_SATURATE_WARNING_ON_EVS; - /* get table index (upper 6 bits minus 16) */ - /* index = (m >> 9) - 32; */ - index = mac_r(-32768 - (32 << 16), m, 1 << 6); + /* get table index (upper 6 bits minus 16) */ + /* index = (m >> 9) - 32; */ + index = mac_r( -32768 - ( 32 << 16 ), m, 1 << 6 ); - /* get fractional part for interpolation (lower 9 bits) */ - frac = shl(s_and(m, 0x1FF), 1); /* Q10 */ + /* get fractional part for interpolation (lower 9 bits) */ + frac = shl( s_and( m, 0x1FF ), 1 ); /* Q10 */ - /* interpolate 1/b */ - m = msu_r(InvTable[index], InvDiffTable[index], frac); + /* interpolate 1/b */ + m = msu_r( InvTable[index], InvDiffTable[index], frac ); - /* restore sign */ - if (b_m < 0) m = negate(m); + /* restore sign */ + if ( b_m < 0 ) + m = negate( m ); - /* multiply with a */ - m32 = L_mult(a_m, m); + /* multiply with a */ + m32 = L_mult( a_m, m ); - /* normalize result */ - postShift = norm_l(m32); + /* normalize result */ + postShift = norm_l( m32 ); #ifdef BASOP_NOGLOB - m = round_fx_o(L_shl(m32, postShift), &Overflow); + m = round_fx_o( L_shl( m32, postShift ), &Overflow ); #else - m = round_fx(L_shl(m32, postShift)); + m = round_fx( L_shl( m32, postShift ) ); #endif - /* exponent */ - *ptrResult_e = sub(add(add(a_e, sub(1, b_e)), preShift), postShift); - move16(); - - *ptrResult_m = m; - move16(); + /* exponent */ + *ptrResult_e = sub( add( add( a_e, sub( 1, b_e ) ), preShift ), postShift ); + move16(); + *ptrResult_m = m; + move16(); } - /* local function for Sqrt16 */ -static Word16 Sqrt16_common(Word16 m, - Word16 e) +static Word16 Sqrt16_common( Word16 m, + Word16 e ) { - Word16 index, frac; + Word16 index, frac; #ifdef BASOP_NOGLOB - Flag Overflow; + Flag Overflow; #endif - assert((m >= 0x4000) || (m == 0)); + assert( ( m >= 0x4000 ) || ( m == 0 ) ); - /* get table index (upper 6 bits minus 32) */ - /* index = (m >> 9) - 32; */ - index = mac_r(-32768 - (32 << 16), m, 1 << 6); + /* get table index (upper 6 bits minus 32) */ + /* index = (m >> 9) - 32; */ + index = mac_r( -32768 - ( 32 << 16 ), m, 1 << 6 ); - /* get fractional part for interpolation (lower 9 bits) */ - frac = s_and(m, 0x1FF); /* Q9 */ + /* get fractional part for interpolation (lower 9 bits) */ + frac = s_and( m, 0x1FF ); /* Q9 */ - /* interpolate */ - if (m != 0) - { - BASOP_SATURATE_WARNING_OFF_EVS; + /* interpolate */ + if ( m != 0 ) + { + BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB - m = mac_ro(SqrtTable[index], SqrtDiffTable[index], frac, &Overflow); + m = mac_ro( SqrtTable[index], SqrtDiffTable[index], frac, &Overflow ); #else - m = mac_r(SqrtTable[index], SqrtDiffTable[index], frac); + m = mac_r( SqrtTable[index], SqrtDiffTable[index], frac ); #endif - BASOP_SATURATE_WARNING_ON_EVS; - } + BASOP_SATURATE_WARNING_ON_EVS; + } - /* handle odd exponents */ - if (s_and(e, 1) != 0) m = mult_r(m, 0x5a82); + /* handle odd exponents */ + if ( s_and( e, 1 ) != 0 ) + m = mult_r( m, 0x5a82 ); - return m; + return m; } /* local function for Sqrt32 and Sqrt32norm */ -static Word32 Sqrt32_common(Word32 m, - Word16 e) +static Word32 Sqrt32_common( Word32 m, + Word16 e ) { - Word16 m16, index, frac; + Word16 m16, index, frac; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; + Flag Overflow = 0; #endif - assert((m >= 0x40000000) || (m == 0)); + assert( ( m >= 0x40000000 ) || ( m == 0 ) ); #ifdef BASOP_NOGLOB - m16 = round_fx_o(m, &Overflow); -#else /* BASOP_NOGLOB */ - m16 = round_fx(m); + m16 = round_fx_o( m, &Overflow ); +#else /* BASOP_NOGLOB */ + m16 = round_fx( m ); #endif /* BASOP_NOGLOB */ - /* get table index (upper 6 bits minus 32) */ - /* index = (m16 >> 9) - 32; */ - index = mac_r(-32768 - (32 << 16), m16, 1 << 6); + /* get table index (upper 6 bits minus 32) */ + /* index = (m16 >> 9) - 32; */ + index = mac_r( -32768 - ( 32 << 16 ), m16, 1 << 6 ); - /* get fractional part for interpolation (lower 9 bits) */ - frac = s_and(m16, 0x1FF); /* Q9 */ + /* get fractional part for interpolation (lower 9 bits) */ + frac = s_and( m16, 0x1FF ); /* Q9 */ - /* interpolate */ - if (m != 0) - { - BASOP_SATURATE_WARNING_OFF_EVS; + /* interpolate */ + if ( m != 0 ) + { + BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB - m = L_mac_sat( SqrtTable[index], SqrtDiffTable[index], frac ); + m = L_mac_sat( SqrtTable[index], SqrtDiffTable[index], frac ); #else - m = L_mac(SqrtTable[index], SqrtDiffTable[index], frac); + m = L_mac( SqrtTable[index], SqrtDiffTable[index], frac ); #endif - BASOP_SATURATE_WARNING_ON_EVS; - } + BASOP_SATURATE_WARNING_ON_EVS; + } - /* handle odd exponents */ - if (s_and(e, 1) != 0) m = Mpy_32_16_1(m, 0x5a82); + /* handle odd exponents */ + if ( s_and( e, 1 ) != 0 ) + m = Mpy_32_16_1( m, 0x5a82 ); - return m; + return m; } /* local function for ISqrt16 and ISqrt16norm */ -static Word16 ISqrt16_common(Word16 m, - Word16 e) +static Word16 ISqrt16_common( Word16 m, + Word16 e ) { - Word16 index, frac; + Word16 index, frac; - assert(m >= 0x4000); + assert( m >= 0x4000 ); - /* get table index (upper 6 bits minus 32) */ - /* index = (m >> 9) - 32; */ - index = mac_r(-32768 - (32 << 16), m, 1 << 6); + /* get table index (upper 6 bits minus 32) */ + /* index = (m >> 9) - 32; */ + index = mac_r( -32768 - ( 32 << 16 ), m, 1 << 6 ); - /* get fractional part for interpolation (lower 9 bits) */ - frac = s_and(m, 0x1FF); /* Q9 */ + /* get fractional part for interpolation (lower 9 bits) */ + frac = s_and( m, 0x1FF ); /* Q9 */ - /* interpolate */ - m = msu_r(ISqrtTable[index], ISqrtDiffTable[index], frac); + /* interpolate */ + m = msu_r( ISqrtTable[index], ISqrtDiffTable[index], frac ); - /* handle even exponents */ - if (s_and(e, 1) == 0) m = mult_r(m, 0x5a82); + /* handle even exponents */ + if ( s_and( e, 1 ) == 0 ) + m = mult_r( m, 0x5a82 ); - return m; + return m; } /* local function for ISqrt32 and ISqrt32norm */ -static Word32 ISqrt32_common(Word32 m, - Word16 e) +static Word32 ISqrt32_common( Word32 m, + Word16 e ) { - Word16 m16, index, frac; + Word16 m16, index, frac; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; + Flag Overflow = 0; #endif - assert(m >= 0x40000000); + assert( m >= 0x40000000 ); #ifdef BASOP_NOGLOB - m16 = round_fx_o(m, &Overflow); + m16 = round_fx_o( m, &Overflow ); #else - m16 = round_fx(m); + m16 = round_fx( m ); #endif - /* get table index (upper 6 bits minus 32) */ - /* index = (m16 >> 25) - 32; */ - index = mac_r(-32768 - (32 << 16), m16, 1 << 6); + /* get table index (upper 6 bits minus 32) */ + /* index = (m16 >> 25) - 32; */ + index = mac_r( -32768 - ( 32 << 16 ), m16, 1 << 6 ); - /* get fractional part for interpolation (lower 9 bits) */ - frac = s_and(m16, 0x1FF); /* Q9 */ + /* get fractional part for interpolation (lower 9 bits) */ + frac = s_and( m16, 0x1FF ); /* Q9 */ - /* interpolate */ - m = L_msu(ISqrtTable[index], ISqrtDiffTable[index], frac); + /* interpolate */ + m = L_msu( ISqrtTable[index], ISqrtDiffTable[index], frac ); - /* handle even exponents */ - if (s_and(e, 1) == 0) m = Mpy_32_16_1(m, 0x5a82); + /* handle even exponents */ + if ( s_and( e, 1 ) == 0 ) + m = Mpy_32_16_1( m, 0x5a82 ); - return m; + return m; } Word16 Sqrt16( /*!< output mantissa */ - Word16 mantissa, /*!< input mantissa */ - Word16 *exponent /*!< pointer to exponent */ + Word16 mantissa, /*!< input mantissa */ + Word16 *exponent /*!< pointer to exponent */ ) { - Word16 preShift, e; + Word16 preShift, e; - assert(mantissa >= 0); + assert( mantissa >= 0 ); - /* normalize */ - preShift = norm_s(mantissa); + /* normalize */ + preShift = norm_s( mantissa ); - e = sub(*exponent, preShift); - mantissa = shl(mantissa, preShift); + e = sub( *exponent, preShift ); + mantissa = shl( mantissa, preShift ); - /* calc mantissa */ - mantissa = Sqrt16_common(mantissa, e); + /* calc mantissa */ + mantissa = Sqrt16_common( mantissa, e ); - /* e = (e + 1) >> 1 */ - *exponent = mult_r(e, 1 << 14); - move16(); + /* e = (e + 1) >> 1 */ + *exponent = mult_r( e, 1 << 14 ); + move16(); - return mantissa; + return mantissa; } - -Word16 Sqrt16norm( /*!< output mantissa */ - Word16 mantissa, /*!< normalized input mantissa */ - Word16 *exponent /*!< pointer to exponent */ +Word16 Sqrt16norm( /*!< output mantissa */ + Word16 mantissa, /*!< normalized input mantissa */ + Word16 *exponent /*!< pointer to exponent */ ) { - assert((mantissa >= 0x4000) || (mantissa == 0)); + assert( ( mantissa >= 0x4000 ) || ( mantissa == 0 ) ); - /* calc mantissa */ - mantissa = Sqrt16_common(mantissa, *exponent); + /* calc mantissa */ + mantissa = Sqrt16_common( mantissa, *exponent ); - /* e = (e + 1) >> 1 */ - *exponent = mult_r(*exponent, 1 << 14); - move16(); + /* e = (e + 1) >> 1 */ + *exponent = mult_r( *exponent, 1 << 14 ); + move16(); - return mantissa; + return mantissa; } - Word16 ISqrt16( /*!< output mantissa */ - Word16 mantissa, /*!< input mantissa */ - Word16 *exponent /*!< pointer to exponent */ + Word16 mantissa, /*!< input mantissa */ + Word16 *exponent /*!< pointer to exponent */ ) { - Word16 preShift, e; + Word16 preShift, e; - assert(mantissa > 0); + assert( mantissa > 0 ); - /* normalize */ - preShift = norm_s(mantissa); + /* normalize */ + preShift = norm_s( mantissa ); - e = sub(*exponent, preShift); - mantissa = shl(mantissa, preShift); + e = sub( *exponent, preShift ); + mantissa = shl( mantissa, preShift ); - /* calc mantissa */ - mantissa = ISqrt16_common(mantissa, e); + /* calc mantissa */ + mantissa = ISqrt16_common( mantissa, e ); - /* e = (2 - e) >> 1 */ - *exponent = msu_r(1L << 15, e, 1 << 14); - move16(); + /* e = (2 - e) >> 1 */ + *exponent = msu_r( 1L << 15, e, 1 << 14 ); + move16(); - return mantissa; + return mantissa; } Word32 Sqrt32( /*!< output mantissa */ - Word32 mantissa, /*!< input mantissa */ - Word16 *exponent /*!< pointer to exponent */ + Word32 mantissa, /*!< input mantissa */ + Word16 *exponent /*!< pointer to exponent */ ) { - Word16 preShift, e; + Word16 preShift, e; - assert(mantissa >= 0); + assert( mantissa >= 0 ); - /* normalize */ - preShift = norm_l(mantissa); + /* normalize */ + preShift = norm_l( mantissa ); - e = sub(*exponent, preShift); - mantissa = L_shl(mantissa, preShift); + e = sub( *exponent, preShift ); + mantissa = L_shl( mantissa, preShift ); - /* calc mantissa */ - mantissa = Sqrt32_common(mantissa, e); + /* calc mantissa */ + mantissa = Sqrt32_common( mantissa, e ); - /* e = (e + 1) >> 1 */ - *exponent = mult_r(e, 1 << 14); - move16(); + /* e = (e + 1) >> 1 */ + *exponent = mult_r( e, 1 << 14 ); + move16(); - return mantissa; + return mantissa; } Word32 ISqrt32( /*!< output mantissa */ - Word32 mantissa, /*!< input mantissa */ - Word16 *exponent /*!< pointer to exponent */ + Word32 mantissa, /*!< input mantissa */ + Word16 *exponent /*!< pointer to exponent */ ) { - Word16 preShift, e; + Word16 preShift, e; - assert(mantissa > 0); + assert( mantissa > 0 ); - /* normalize */ - preShift = norm_l(mantissa); + /* normalize */ + preShift = norm_l( mantissa ); - e = sub(*exponent, preShift); - mantissa = L_shl(mantissa, preShift); + e = sub( *exponent, preShift ); + mantissa = L_shl( mantissa, preShift ); - /* calc mantissa */ - mantissa = ISqrt32_common(mantissa, e); + /* calc mantissa */ + mantissa = ISqrt32_common( mantissa, e ); - /* e = (2 - e) >> 1 */ - *exponent = msu_r(1L << 15, e, 1 << 14); - move16(); + /* e = (2 - e) >> 1 */ + *exponent = msu_r( 1L << 15, e, 1 << 14 ); + move16(); - return mantissa; + return mantissa; } -Word32 ISqrt32norm( /*!< output mantissa */ - Word32 mantissa, /*!< normalized input mantissa */ - Word16 *exponent /*!< pointer to exponent */ +Word32 ISqrt32norm( /*!< output mantissa */ + Word32 mantissa, /*!< normalized input mantissa */ + Word16 *exponent /*!< pointer to exponent */ ) { - assert(mantissa >= 0x40000000); + assert( mantissa >= 0x40000000 ); - /* calc mantissa */ - mantissa = ISqrt32_common(mantissa, *exponent); + /* calc mantissa */ + mantissa = ISqrt32_common( mantissa, *exponent ); - /* e = (2 - e) >> 1 */ - *exponent = msu_r(1L << 15, *exponent, 1 << 14); - move16(); + /* e = (2 - e) >> 1 */ + *exponent = msu_r( 1L << 15, *exponent, 1 << 14 ); + move16(); - return mantissa; + return mantissa; } Word16 Inv16( /*!< output mantissa */ - Word16 mantissa, /*!< input mantissa */ - Word16 *exponent /*!< pointer to exponent */ + Word16 mantissa, /*!< input mantissa */ + Word16 *exponent /*!< pointer to exponent */ ) { - Word16 index, frac; - Word16 preShift; - Word16 m, e; + Word16 index, frac; + Word16 preShift; + Word16 m, e; + assert( mantissa != 0 ); - assert(mantissa != 0); - - /* absolute */ - BASOP_SATURATE_WARNING_OFF_EVS; - m = abs_s(mantissa); - BASOP_SATURATE_WARNING_ON_EVS; + /* absolute */ + BASOP_SATURATE_WARNING_OFF_EVS; + m = abs_s( mantissa ); + BASOP_SATURATE_WARNING_ON_EVS; - /* normalize */ - preShift = norm_s(m); + /* normalize */ + preShift = norm_s( m ); - e = sub(*exponent, preShift); - m = shl(m, preShift); + e = sub( *exponent, preShift ); + m = shl( m, preShift ); - /* get table index (upper 6 bits minus 32) */ - /* index = (m >> 9) - 32; */ - index = mac_r(-32768 - (32 << 16), m, 1 << 6); + /* get table index (upper 6 bits minus 32) */ + /* index = (m >> 9) - 32; */ + index = mac_r( -32768 - ( 32 << 16 ), m, 1 << 6 ); - /* get fractional part for interpolation (lower 9 bits) */ - frac = shl(s_and(m, 0x1FF), 1); /* Q10 */ + /* get fractional part for interpolation (lower 9 bits) */ + frac = shl( s_and( m, 0x1FF ), 1 ); /* Q10 */ - /* interpolate */ - m = msu_r(InvTable[index], InvDiffTable[index], frac); + /* interpolate */ + m = msu_r( InvTable[index], InvDiffTable[index], frac ); - /* restore sign */ - if (mantissa < 0) m = negate(m); + /* restore sign */ + if ( mantissa < 0 ) + m = negate( m ); - /* e = 1 - e */ - *exponent = sub(1, e); - move16(); + /* e = 1 - e */ + *exponent = sub( 1, e ); + move16(); - return m; + return m; } -void BASOP_Util_Sqrt_InvSqrt_MantExp(Word16 mantissa, /*!< mantissa */ - Word16 exponent, /*!< expoinent */ - Word16 *sqrt_mant, /*!< Pointer to sqrt mantissa */ - Word16 *sqrt_exp, /*!< Pointer to sqrt exponent */ - Word16 *isqrt_mant, /*!< Pointer to 1/sqrt mantissa */ - Word16 *isqrt_exp /*!< Pointer to 1/sqrt exponent */ +void BASOP_Util_Sqrt_InvSqrt_MantExp( Word16 mantissa, /*!< mantissa */ + Word16 exponent, /*!< expoinent */ + Word16 *sqrt_mant, /*!< Pointer to sqrt mantissa */ + Word16 *sqrt_exp, /*!< Pointer to sqrt exponent */ + Word16 *isqrt_mant, /*!< Pointer to 1/sqrt mantissa */ + Word16 *isqrt_exp /*!< Pointer to 1/sqrt exponent */ ) { - Word16 index, frac; - Word16 preShift; - Word16 m, mi, e_odd; - + Word16 index, frac; + Word16 preShift; + Word16 m, mi, e_odd; - assert(mantissa > 0); + assert( mantissa > 0 ); - /* normalize */ - preShift = norm_s(mantissa); + /* normalize */ + preShift = norm_s( mantissa ); - exponent = sub(exponent, preShift); - mantissa = shl(mantissa, preShift); + exponent = sub( exponent, preShift ); + mantissa = shl( mantissa, preShift ); - /* get table index (upper 6 bits minus 32) */ - /* index = (m >> 9) - 32; */ - index = mac_r(-32768 - (32 << 16), mantissa, 1 << 6); + /* get table index (upper 6 bits minus 32) */ + /* index = (m >> 9) - 32; */ + index = mac_r( -32768 - ( 32 << 16 ), mantissa, 1 << 6 ); - /* get fractional part for interpolation (lower 9 bits) */ - frac = s_and(mantissa, 0x1FF); /* Q9 */ + /* get fractional part for interpolation (lower 9 bits) */ + frac = s_and( mantissa, 0x1FF ); /* Q9 */ - /* interpolate */ - BASOP_SATURATE_WARNING_OFF_EVS; + /* interpolate */ + BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB - m = mac_r_sat( SqrtTable[index], SqrtDiffTable[index], frac ); - mi = msu_r_sat(ISqrtTable[index], ISqrtDiffTable[index], frac); + m = mac_r_sat( SqrtTable[index], SqrtDiffTable[index], frac ); + mi = msu_r_sat( ISqrtTable[index], ISqrtDiffTable[index], frac ); #else - m = mac_r(SqrtTable[index], SqrtDiffTable[index], frac); - mi = msu_r(ISqrtTable[index], ISqrtDiffTable[index], frac); + m = mac_r( SqrtTable[index], SqrtDiffTable[index], frac ); + mi = msu_r( ISqrtTable[index], ISqrtDiffTable[index], frac ); #endif - BASOP_SATURATE_WARNING_ON_EVS; - - /* handle even/odd exponents */ - e_odd = s_and(exponent, 1); - if (e_odd != 0) m = mult_r(m, 0x5a82); - if (e_odd == 0) mi = mult_r(mi, 0x5a82); + BASOP_SATURATE_WARNING_ON_EVS; - /* e = (e + 1) >> 1 */ - *sqrt_exp = mult_r(exponent, 1 << 14); - move16(); + /* handle even/odd exponents */ + e_odd = s_and( exponent, 1 ); + if ( e_odd != 0 ) + m = mult_r( m, 0x5a82 ); + if ( e_odd == 0 ) + mi = mult_r( mi, 0x5a82 ); - /* e = (2 - e) >> 1 */ - *isqrt_exp = msu_r(1L << 15, exponent, 1 << 14); - move16(); + /* e = (e + 1) >> 1 */ + *sqrt_exp = mult_r( exponent, 1 << 14 ); + move16(); - /* Write result */ - *sqrt_mant = m; - move16(); - *isqrt_mant = mi; - move16(); + /* e = (2 - e) >> 1 */ + *isqrt_exp = msu_r( 1L << 15, exponent, 1 << 14 ); + move16(); + /* Write result */ + *sqrt_mant = m; + move16(); + *isqrt_mant = mi; + move16(); } @@ -699,42 +697,41 @@ void BASOP_Util_Sqrt_InvSqrt_MantExp(Word16 mantissa, /*!< mantissa */ and -32768 <= x <= -16384 for negative x */ -Word16 getScaleFactor16( /* o: measured headroom in range [0..15], 0 if all x[i] == 0 */ - const Word16 *x, /* i: array containing 16-bit data */ - const Word16 len_x) /* i: length of the array to scan */ +Word16 getScaleFactor16( /* o: measured headroom in range [0..15], 0 if all x[i] == 0 */ + const Word16 *x, /* i: array containing 16-bit data */ + const Word16 len_x ) /* i: length of the array to scan */ { - Word16 i, i_min, i_max; - Word16 x_min, x_max; - + Word16 i, i_min, i_max; + Word16 x_min, x_max; - x_max = 0; - move16(); - x_min = 0; - move16(); - FOR(i = 0; i < len_x; i++) - { - if (x[i] >= 0) - x_max = s_max(x_max, x[i]); - if (x[i] < 0) - x_min = s_min(x_min, x[i]); - } + x_max = 0; + move16(); + x_min = 0; + move16(); + FOR( i = 0; i < len_x; i++ ) + { + if ( x[i] >= 0 ) + x_max = s_max( x_max, x[i] ); + if ( x[i] < 0 ) + x_min = s_min( x_min, x[i] ); + } - i_max = 0x10; - move16(); - i_min = 0x10; - move16(); + i_max = 0x10; + move16(); + i_min = 0x10; + move16(); - if (x_max != 0) - i_max = norm_s(x_max); + if ( x_max != 0 ) + i_max = norm_s( x_max ); - if (x_min != 0) - i_min = norm_s(x_min); + if ( x_min != 0 ) + i_min = norm_s( x_min ); - i = s_and(s_min(i_max, i_min), 0xF); + i = s_and( s_min( i_max, i_min ), 0xF ); - return i; + return i; } @@ -748,189 +745,189 @@ Word16 getScaleFactor16( /* o: measured headroom in range [0..15 and -2147483648 <= x <= -1073741824 for negative x */ -Word16 getScaleFactor32( /* o: measured headroom in range [0..31], 0 if all x[i] == 0 */ - const Word32 *x, /* i: array containing 32-bit data */ - const Word16 len_x) /* i: length of the array to scan */ +Word16 getScaleFactor32( /* o: measured headroom in range [0..31], 0 if all x[i] == 0 */ + const Word32 *x, /* i: array containing 32-bit data */ + const Word16 len_x ) /* i: length of the array to scan */ { - Word16 i, i_min, i_max; - Word32 x_min, x_max; - + Word16 i, i_min, i_max; + Word32 x_min, x_max; - x_max = 0; move32(); - x_min = 0; move32(); - FOR(i = 0; i < len_x; i++) - { - if (x[i] >= 0) - x_max = L_max(x_max, x[i]); - if (x[i] < 0) - x_min = L_min(x_min, x[i]); - } + x_max = 0; + move32(); + x_min = 0; + move32(); + FOR( i = 0; i < len_x; i++ ) + { + if ( x[i] >= 0 ) + x_max = L_max( x_max, x[i] ); + if ( x[i] < 0 ) + x_min = L_min( x_min, x[i] ); + } - i_max = 0x20; - move16(); - i_min = 0x20; - move16(); + i_max = 0x20; + move16(); + i_min = 0x20; + move16(); - if (x_max != 0) - i_max = norm_l(x_max); + if ( x_max != 0 ) + i_max = norm_l( x_max ); - if (x_min != 0) - i_min = norm_l(x_min); + if ( x_min != 0 ) + i_min = norm_l( x_min ); - i = s_and(s_min(i_max, i_min), 0x1F); + i = s_and( s_min( i_max, i_min ), 0x1F ); - return i; + return i; } -Word16 normalize16(Word16 mantissa, Word16 *pexponent) +Word16 normalize16( Word16 mantissa, Word16 *pexponent ) { - Word16 tmp; + Word16 tmp; - tmp = norm_s(mantissa); - mantissa = shl(mantissa, tmp); - move16(); - *pexponent = sub(*pexponent, tmp); + tmp = norm_s( mantissa ); + mantissa = shl( mantissa, tmp ); + move16(); + *pexponent = sub( *pexponent, tmp ); - return mantissa; + return mantissa; } -Word16 divide3216(Word32 x, Word16 y) +Word16 divide3216( Word32 x, Word16 y ) { - Word16 z; + Word16 z; - z = 0; - move16(); - if (0 == y) - { - return 0x7fff; - } + z = 0; + move16(); + if ( 0 == y ) + { + return 0x7fff; + } - IF(x != 0) - { - Word16 den, sign; - Word32 num; - num = L_abs(x); - den = abs_s(y); + IF( x != 0 ) + { + Word16 den, sign; + Word32 num; + num = L_abs( x ); + den = abs_s( y ); - sign = s_and(s_xor(extract_h(x), y), -32768 /* 0x8000 */); + sign = s_and( s_xor( extract_h( x ), y ), -32768 /* 0x8000 */ ); - z = div_l(num, den); - if (0 != sign) - { - z = negate(z); + z = div_l( num, den ); + if ( 0 != sign ) + { + z = negate( z ); + } } - } - return z; + return z; } -Word16 divide1616(Word16 x, Word16 y) +Word16 divide1616( Word16 x, Word16 y ) { - Word16 z, num, den, sign; + Word16 z, num, den, sign; - num = abs_s(x); - den = abs_s(y); + num = abs_s( x ); + den = abs_s( y ); - sign = s_and(s_xor(x, y), -32768 /* 0x8000 */); + sign = s_and( s_xor( x, y ), -32768 /* 0x8000 */ ); - move16(); - z = 0x7fff; - if (LT_16(num, den)) - z = div_s(num, den); + move16(); + z = 0x7fff; + if ( LT_16( num, den ) ) + z = div_s( num, den ); - if (0 != sign) - { - z = negate(z); - } + if ( 0 != sign ) + { + z = negate( z ); + } - return z; + return z; } -Word16 divide3232(Word32 L_num, Word32 L_denom) +Word16 divide3232( Word32 L_num, Word32 L_denom ) { - Word16 z; - Word32 sign; + Word16 z; + Word32 sign; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; + Flag Overflow = 0; #endif - sign = L_and(L_xor(L_num, L_denom), 0x80000000); + sign = L_and( L_xor( L_num, L_denom ), 0x80000000 ); - L_num = L_abs(L_num); - L_denom = L_abs(L_denom); + L_num = L_abs( L_num ); + L_denom = L_abs( L_denom ); - /* limit the range of denominator to Word16 */ - z = s_min(norm_l(L_num), norm_l(L_denom)); - L_num = L_shl(L_num, z); - L_denom = L_shl(L_denom, z); + /* limit the range of denominator to Word16 */ + z = s_min( norm_l( L_num ), norm_l( L_denom ) ); + L_num = L_shl( L_num, z ); + L_denom = L_shl( L_denom, z ); - /* round_fx instead of extract_h improves spectral distortion in E_UTIL_lev_dur (schur version). */ + /* round_fx instead of extract_h improves spectral distortion in E_UTIL_lev_dur (schur version). */ #ifdef BASOP_NOGLOB - z = div_l(L_num, round_fx_o(L_denom, &Overflow)); + z = div_l( L_num, round_fx_o( L_denom, &Overflow ) ); #else - z = div_l(L_num, round_fx(L_denom)); + z = div_l( L_num, round_fx( L_denom ) ); #endif - if (0 != sign) - { - z = negate(z); - } + if ( 0 != sign ) + { + z = negate( z ); + } - return z; + return z; } -Word16 BASOP_Util_Divide3232_uu_1616_Scale(Word32 x, Word32 y, Word16 *s) +Word16 BASOP_Util_Divide3232_uu_1616_Scale( Word32 x, Word32 y, Word16 *s ) { - Word16 z; - Word16 sx; - Word16 sy; - Word16 x16; - Word16 y16; - + Word16 z; + Word16 sx; + Word16 sy; + Word16 x16; + Word16 y16; - assert(x >= 0); - assert(y > 0); + assert( x >= 0 ); + assert( y > 0 ); - if (x == 0) - { - *s = 0; - move16(); + if ( x == 0 ) + { + *s = 0; + move16(); - return (0); - } + return ( 0 ); + } - sx = norm_l(x); - sy = norm_l(y); + sx = norm_l( x ); + sy = norm_l( y ); - x16 = extract_h(L_shl(x, sx)); - y16 = extract_h(L_shl(y, sy)); + x16 = extract_h( L_shl( x, sx ) ); + y16 = extract_h( L_shl( y, sy ) ); - if (GT_16(x16, y16)) - { - sx = sub(sx, 1); - } + if ( GT_16( x16, y16 ) ) + { + sx = sub( sx, 1 ); + } - if (LT_16(y16, x16)) - { - x16 = mult_r(x16, 0x4000); - } + if ( LT_16( y16, x16 ) ) + { + x16 = mult_r( x16, 0x4000 ); + } - z = div_s(x16, y16); - move16(); - *s = sub(sy, sx); + z = div_s( x16, y16 ); + move16(); + *s = sub( sy, sx ); - return (z); + return ( z ); } Word32 div_w( Word32 L_num, Word32 L_den ) @@ -1031,85 +1028,83 @@ Word32 BASOP_Util_Divide3232_Scale_cadence( Word32 x, Word32 y, Word16 *s ) return z; } -Word16 BASOP_Util_Divide3232_Scale(Word32 x, Word32 y, Word16 *s) +Word16 BASOP_Util_Divide3232_Scale( Word32 x, Word32 y, Word16 *s ) { - Word16 z; - Word16 sy; - + Word16 z; + Word16 sy; - sy = norm_l(y); - if (sy > 0) - { - sy = sub(sy, 1); - } - y = L_shl(y, sy); + sy = norm_l( y ); + if ( sy > 0 ) + { + sy = sub( sy, 1 ); + } + y = L_shl( y, sy ); - z = BASOP_Util_Divide3216_Scale(x, extract_h(y), s); - move16(); - *s = add(*s, sy); + z = BASOP_Util_Divide3216_Scale( x, extract_h( y ), s ); + move16(); + *s = add( *s, sy ); - return (z); + return ( z ); } -Word16 BASOP_Util_Divide1616_Scale(Word16 x, Word16 y, Word16 *s) +Word16 BASOP_Util_Divide1616_Scale( Word16 x, Word16 y, Word16 *s ) { - Word16 z; - Word16 sx; - Word16 sy; - Word16 sign; - + Word16 z; + Word16 sx; + Word16 sy; + Word16 sign; - /* assert (x >= (Word16)0); */ - assert(y != (Word16)0); + /* assert (x >= (Word16)0); */ + assert( y != (Word16) 0 ); - sign = 0; - move16(); + sign = 0; + move16(); - IF(x < 0) - { - x = negate(x); - sign = s_xor(sign, 1); - } + IF( x < 0 ) + { + x = negate( x ); + sign = s_xor( sign, 1 ); + } - IF(y < 0) - { - y = negate(y); - sign = s_xor(sign, 1); - } + IF( y < 0 ) + { + y = negate( y ); + sign = s_xor( sign, 1 ); + } - IF(x == (Word16)0) - { - move16(); - *s = 0; + IF( x == (Word16) 0 ) + { + move16(); + *s = 0; - return ((Word16)0); - } + return ( (Word16) 0 ); + } - sx = norm_s(x); - x = shl(x, sx); - x = shr(x, 1); - move16(); - *s = sub(1, sx); + sx = norm_s( x ); + x = shl( x, sx ); + x = shr( x, 1 ); + move16(); + *s = sub( 1, sx ); - sy = norm_s(y); - y = shl(y, sy); - move16(); - *s = add(*s, sy); + sy = norm_s( y ); + y = shl( y, sy ); + move16(); + *s = add( *s, sy ); - z = div_s(x, y); + z = div_s( x, y ); - if (sign != 0) - { - z = negate(z); - } + if ( sign != 0 ) + { + z = negate( z ); + } - return z; + return z; } @@ -1156,87 +1151,83 @@ Word16 mult0( return extract_l( L_mult0( x, y ) ); } -void copyWord8(const Word8 *src, Word8 *dst, const Word32 n) +void copyWord8( const Word8 *src, Word8 *dst, const Word32 n ) { - Word32 i; - + Word32 i; - FOR(i = 0; i < n; i++) - { - dst[i] = src[i]; - move16(); - } + FOR( i = 0; i < n; i++ ) + { + dst[i] = src[i]; + move16(); + } } - -void set_zero_Word8(Word8 X[], Word32 n) +void set_zero_Word8( Word8 X[], Word32 n ) { - Word32 i; - + Word32 i; - FOR(i = 0; i < n; i++) - { - X[i] = 0; - move16(); - } + FOR( i = 0; i < n; i++ ) + { + X[i] = 0; + move16(); + } } -Word32 L_mult0_3216(Word32 x, Word16 y) +Word32 L_mult0_3216( Word32 x, Word16 y ) { - UWord16 mpy_low16; - Word32 mpy_high32; + UWord16 mpy_low16; + Word32 mpy_high32; - Mpy_32_16_ss(x, y, &mpy_high32, &mpy_low16); + Mpy_32_16_ss( x, y, &mpy_high32, &mpy_low16 ); - mpy_high32 = L_add(L_shl(mpy_high32, 15), L_lshr(L_deposit_h(mpy_low16), 17)); + mpy_high32 = L_add( L_shl( mpy_high32, 15 ), L_lshr( L_deposit_h( mpy_low16 ), 17 ) ); - return mpy_high32; + return mpy_high32; } -Word16 BASOP_util_norm_l_dim2_cplx(const Word32 * const *re, /*!< Real part of 32 Bit input */ - const Word32 * const *im, /*!< Imag part if 32 Bit input */ - Word16 startBand, /*!< start band of cplx data */ - Word16 stopBand, /*!< stop band of cplx data */ - Word16 startSlot, /*!< start slot of cplx data */ - Word16 stopSlot /*!< stop slot of cplx data */ +Word16 BASOP_util_norm_l_dim2_cplx( const Word32 *const *re, /*!< Real part of 32 Bit input */ + const Word32 *const *im, /*!< Imag part if 32 Bit input */ + Word16 startBand, /*!< start band of cplx data */ + Word16 stopBand, /*!< stop band of cplx data */ + Word16 startSlot, /*!< start slot of cplx data */ + Word16 stopSlot /*!< stop slot of cplx data */ ) { - Word16 col; - Word16 band; - Word16 maxShift; - Word32 maxVal; - + Word16 col; + Word16 band; + Word16 maxShift; + Word32 maxVal; - maxVal = L_deposit_l(1); + maxVal = L_deposit_l( 1 ); - FOR(col = startSlot; col < stopSlot; col++) - { - FOR(band = startBand; band < stopBand; band++) + FOR( col = startSlot; col < stopSlot; col++ ) { - maxVal = L_max(maxVal, L_abs(re[col][band])); - maxVal = L_max(maxVal, L_abs(im[col][band])); + FOR( band = startBand; band < stopBand; band++ ) + { + maxVal = L_max( maxVal, L_abs( re[col][band] ) ); + maxVal = L_max( maxVal, L_abs( im[col][band] ) ); + } } - } - maxShift = norm_l(maxVal); + maxShift = norm_l( maxVal ); - return (maxShift); + return ( maxShift ); } -Word16 BASOP_util_norm_s_bands2shift(Word16 x) +Word16 BASOP_util_norm_s_bands2shift( Word16 x ) { - Word16 shift; + Word16 shift; - shift = sub(WORD16_BITS - 1, norm_s(negate(x))); + shift = sub( WORD16_BITS - 1, norm_s( negate( x ) ) ); - return (shift); + return ( shift ); } #define SINETAB SineTable512_fx @@ -1330,47 +1321,47 @@ static Word16 fixp_sin_cos_residual_16( return residual; } -Word16 getCosWord16(Word16 theta) +Word16 getCosWord16( Word16 theta ) { - Word16 result, residual, sine, cosine; + Word16 result, residual, sine, cosine; - residual = fixp_sin_cos_residual_16(theta, 2, &sine, &cosine, 0); - /* This negation prevents the subsequent addition from overflow */ - /* The negation cannot overflow, sine is in range [0x0..0x7FFF] */ - sine = negate(sine); - result = mac_r(L_mult0(sine, residual), cosine, 16384); + residual = fixp_sin_cos_residual_16( theta, 2, &sine, &cosine, 0 ); + /* This negation prevents the subsequent addition from overflow */ + /* The negation cannot overflow, sine is in range [0x0..0x7FFF] */ + sine = negate( sine ); + result = mac_r( L_mult0( sine, residual ), cosine, 16384 ); - return result; + return result; } -Word16 getSinWord16(Word16 theta) +Word16 getSinWord16( Word16 theta ) { - Word16 sine; - Word32 theta_new = L_sub(EVS_PI_BY_2_FX, theta); - Word16 l_theta; - IF(GT_32(theta_new, EVS_PI_FX)) - { - l_theta = extract_l(L_sub(L_sub(theta_new, EVS_PI_FX), EVS_PI_FX )); - } - ELSE IF(LT_32(theta_new, -EVS_PI_FX)) - { - l_theta = extract_l(L_add(L_add(theta_new, EVS_PI_FX), EVS_PI_FX)); - } - ELSE - { - l_theta = extract_l(theta_new); - } - sine = getCosWord16(l_theta); - IF (EQ_16(sine, ONE_IN_Q14)) - { - sine = MAX_16; - } - ELSE - { - sine = shl(sine, 1); - } - return sine; + Word16 sine; + Word32 theta_new = L_sub( EVS_PI_BY_2_FX, theta ); + Word16 l_theta; + IF( GT_32( theta_new, EVS_PI_FX ) ) + { + l_theta = extract_l( L_sub( L_sub( theta_new, EVS_PI_FX ), EVS_PI_FX ) ); + } + ELSE IF( LT_32( theta_new, -EVS_PI_FX ) ) + { + l_theta = extract_l( L_add( L_add( theta_new, EVS_PI_FX ), EVS_PI_FX ) ); + } + ELSE + { + l_theta = extract_l( theta_new ); + } + sine = getCosWord16( l_theta ); + IF( EQ_16( sine, ONE_IN_Q14 ) ) + { + sine = MAX_16; + } + ELSE + { + sine = shl( sine, 1 ); + } + return sine; } Word16 getCosWord16R2( @@ -1397,11 +1388,11 @@ Word16 getCosWord16R2( Word16 getSineWord16R2( Word16 theta ) { - IF ( EQ_16( theta, (Word16) 0 ) ) + IF( EQ_16( theta, (Word16) 0 ) ) { return 0; } - ELSE IF ( LT_16( theta, (Word16) -24576 ) ) + ELSE IF( LT_16( theta, (Word16) -24576 ) ) { theta = add( add( theta, (Word16) 32767 ), (Word16) 1 ); } @@ -1419,108 +1410,107 @@ Word16 getSineWord16R2( Word16 theta ) * * Complexity: Worst=31Clks, Best=27Clks */ -Word16 getSqrtWord32(Word32 val) +Word16 getSqrtWord32( Word32 val ) { - Word32 L_temp, L_temp2; - Word16 temp, temp2; - Word16 exp, exp2; + Word32 L_temp, L_temp2; + Word16 temp, temp2; + Word16 exp, exp2; - /* Calc Approximation */ - exp2 = norm_l(val); - L_temp2 = L_shl(val, exp2); - exp = sub(31 - 32, exp2); - L_temp = Isqrt_lc(L_temp2, &exp); /* 12 clks */ + /* Calc Approximation */ + exp2 = norm_l( val ); + L_temp2 = L_shl( val, exp2 ); + exp = sub( 31 - 32, exp2 ); + L_temp = Isqrt_lc( L_temp2, &exp ); /* 12 clks */ #ifdef BASOP_NOGLOB - temp = round_fx_sat(L_temp); + temp = round_fx_sat( L_temp ); #else - temp = round_fx(L_temp); + temp = round_fx( L_temp ); #endif - L_temp = Mpy_32_16_1(L_temp2, temp); /* 2 clks */ - - L_temp = L_shl(L_temp, sub(exp, exp2)); - - /* The Approximation Error Range is -1..+7, so Too Low by 1 or Up to Too High by 7 */ - temp = round_fx(L_temp); - - /* Too High? */ - if (L_msu0(val, temp, temp) < 0) - { - /* Reduce by 2 */ - temp = sub(temp, 2); - } - /* Too High? */ - if (L_msu0(val, temp, temp) < 0) - { - /* Reduce by 2 */ - temp = sub(temp, 2); - } - /* Too High? */ - if (L_msu0(val, temp, temp) < 0) - { - /* Reduce by 2 */ - temp = sub(temp, 2); - } - /* Too High? */ - if (L_msu0(val, temp, temp) < 0) - { - /* Reduce by 1 */ - temp = sub(temp, 1); - } - - /* Try +1 */ - temp2 = add(temp, 1); - /* It fits? */ - if (L_msu0(val, temp2, temp2) >= 0) - { - /* Yes */ - temp = temp2; - move16(); - } - return temp; + L_temp = Mpy_32_16_1( L_temp2, temp ); /* 2 clks */ + + L_temp = L_shl( L_temp, sub( exp, exp2 ) ); + + /* The Approximation Error Range is -1..+7, so Too Low by 1 or Up to Too High by 7 */ + temp = round_fx( L_temp ); + + /* Too High? */ + if ( L_msu0( val, temp, temp ) < 0 ) + { + /* Reduce by 2 */ + temp = sub( temp, 2 ); + } + /* Too High? */ + if ( L_msu0( val, temp, temp ) < 0 ) + { + /* Reduce by 2 */ + temp = sub( temp, 2 ); + } + /* Too High? */ + if ( L_msu0( val, temp, temp ) < 0 ) + { + /* Reduce by 2 */ + temp = sub( temp, 2 ); + } + /* Too High? */ + if ( L_msu0( val, temp, temp ) < 0 ) + { + /* Reduce by 1 */ + temp = sub( temp, 1 ); + } + + /* Try +1 */ + temp2 = add( temp, 1 ); + /* It fits? */ + if ( L_msu0( val, temp2, temp2 ) >= 0 ) + { + /* Yes */ + temp = temp2; + move16(); + } + return temp; } -Word16 findIndexOfMinWord32(Word32 *x, const Word16 len) +Word16 findIndexOfMinWord32( Word32 *x, const Word16 len ) { - Word16 i, indx; + Word16 i, indx; - indx = 0; - move16(); - FOR(i = 1; i < len; i++) - { - if (LT_32(x[i], x[indx])) + indx = 0; + move16(); + FOR( i = 1; i < len; i++ ) { - indx = i; - move16(); + if ( LT_32( x[i], x[indx] ) ) + { + indx = i; + move16(); + } } - } - return indx; + return indx; } -Word16 imult1616(Word16 x, Word16 y) +Word16 imult1616( Word16 x, Word16 y ) { - assert((int)x * (int)y < 32768 && (int)x * (int)y >= -32768); - return extract_l(L_mult0(x, y)); + assert( (int) x * (int) y < 32768 && (int) x * (int) y >= -32768 ); + return extract_l( L_mult0( x, y ) ); } -Word32 imult3216(Word32 x, Word16 y) +Word32 imult3216( Word32 x, Word16 y ) { - Word32 mh; - UWord16 ml; + Word32 mh; + UWord16 ml; - Mpy_32_16_ss(x, y, &mh, &ml); + Mpy_32_16_ss( x, y, &mh, &ml ); - mh = L_shl(mh, 15); - ml = lshr(ml, 1); + mh = L_shl( mh, 15 ); + ml = lshr( ml, 1 ); - return L_or(mh, L_deposit_l(ml)); + return L_or( mh, L_deposit_l( ml ) ); } - Word16 idiv1616U_IVAS( Word16 x, Word16 y ) @@ -1542,345 +1532,349 @@ Word16 idiv1616U_IVAS( return y; } -Word16 idiv1616U(Word16 x, Word16 y) +Word16 idiv1616U( Word16 x, Word16 y ) { - Word16 sx, sy; + Word16 sx, sy; - /* make y > x to meet the requirements for div_s parameters */ - sx = norm_s(x); - sy = norm_s(y); - x = shl(x, sx); - y = shl(y, sy); + /* make y > x to meet the requirements for div_s parameters */ + sx = norm_s( x ); + sy = norm_s( y ); + x = shl( x, sx ); + y = shl( y, sy ); - if (x >= y) - { - x = shr(x, 1); - sx = sub(sx, 1); - } + if ( x >= y ) + { + x = shr( x, 1 ); + sx = sub( sx, 1 ); + } - /* divide and shift */ - y = shr(div_s(x, y), sub(15, sub(sy, sx))); + /* divide and shift */ + y = shr( div_s( x, y ), sub( 15, sub( sy, sx ) ) ); - return y; + return y; } -Word16 idiv1616(Word16 x, Word16 y) +Word16 idiv1616( Word16 x, Word16 y ) { - Word16 s, num, den, sign; + Word16 s, num, den, sign; - num = abs_s(x); - den = abs_s(y); + num = abs_s( x ); + den = abs_s( y ); - sign = s_and(s_xor(x, y), -32768 /* 0x8000 */); + sign = s_and( s_xor( x, y ), -32768 /* 0x8000 */ ); - /* make num > den */ - s = add(sub(norm_s(den), norm_s(num)), 1); - s = s_max(s, 0); + /* make num > den */ + s = add( sub( norm_s( den ), norm_s( num ) ), 1 ); + s = s_max( s, 0 ); - den = shl(den, s); + den = shl( den, s ); - /* divide and shift */ - y = shr(div_s(num, den), sub(15, s)); + /* divide and shift */ + y = shr( div_s( num, den ), sub( 15, s ) ); - if (0 != sign) - { - y = negate(y); - } + if ( 0 != sign ) + { + y = negate( y ); + } - return y; + return y; } -Word32 norm_llQ31( /* o : normalized result Q31 */ - Word32 L_c, /* i : upper bits of accu Q-1 */ - Word32 L_sum, /* i : lower bits of accu, unsigned Q31 */ - Word16 * exp /* o : exponent of result in [-32,31] Q0 */ +Word32 norm_llQ31( /* o : normalized result Q31 */ + Word32 L_c, /* i : upper bits of accu Q-1 */ + Word32 L_sum, /* i : lower bits of accu, unsigned Q31 */ + Word16 *exp /* o : exponent of result in [-32,31] Q0 */ ) { - Word16 i; - Word32 L_tmp; + Word16 i; + Word32 L_tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; - Flag Carry = 0; + Flag Overflow = 0; + Flag Carry = 0; #endif /* BASOP_NOGLOB */ - /* Move MSBit of L_sum into L_c */ - Carry = 0; + /* Move MSBit of L_sum into L_c */ + Carry = 0; #ifdef BASOP_NOGLOB - L_tmp = L_add_co(L_sum, L_sum, &Carry, &Overflow); /* L_tmp = L_sum << 1 */ - L_c = L_add_co(L_c, L_c, &Carry, &Overflow); + L_tmp = L_add_co( L_sum, L_sum, &Carry, &Overflow ); /* L_tmp = L_sum << 1 */ + L_c = L_add_co( L_c, L_c, &Carry, &Overflow ); #else /* BASOP_NOGLOB */ - L_tmp = L_add_c(L_sum, L_sum); /* L_tmp = L_sum << 1 */ - L_c = L_add_c(L_c, L_c); + L_tmp = L_add_c( L_sum, L_sum ); /* L_tmp = L_sum << 1 */ + L_c = L_add_c( L_c, L_c ); #endif - L_add(0, 0); - test(); - IF((L_c != (Word32)0L) && (L_c != (Word32)0xFFFFFFFFL)) - { - i = norm_l(L_c); - L_c = L_shl(L_c, i); - i = sub(31, i); /* positive exponent */ - L_sum = L_lshr(L_tmp, 1); /* L_sum with MSBit=0 */ - L_sum = L_lshr(L_sum, i); - L_sum = L_add(L_c, L_sum); - } - ELSE - { - i = -32; - move16(); /* default exponent, if total sum=0 */ - IF(L_sum) - { - i = norm_l(L_sum); - L_sum = L_shl(L_sum,i); - i = negate(i); /* negative or zero exponent */ - } - } - *exp = i; - move16(); - return L_sum; -} - -Word32 w_norm_llQ31(Word64 L_sum, Word16 * exp); -Word32 w_norm_llQ31( /* o : normalized result Q31 */ - Word64 L_sum, /* i : upper and lower bits of accu, unsigned Q31 */ - Word16 * exp /* o : exponent of result in [-32,31] Q0 */ + L_add( 0, 0 ); + test(); + IF( ( L_c != (Word32) 0L ) && ( L_c != (Word32) 0xFFFFFFFFL ) ) + { + i = norm_l( L_c ); + L_c = L_shl( L_c, i ); + i = sub( 31, i ); /* positive exponent */ + L_sum = L_lshr( L_tmp, 1 ); /* L_sum with MSBit=0 */ + L_sum = L_lshr( L_sum, i ); + L_sum = L_add( L_c, L_sum ); + } + ELSE + { + i = -32; + move16(); /* default exponent, if total sum=0 */ + IF( L_sum ) + { + i = norm_l( L_sum ); + L_sum = L_shl( L_sum, i ); + i = negate( i ); /* negative or zero exponent */ + } + } + *exp = i; + move16(); + return L_sum; +} + +Word32 w_norm_llQ31( Word64 L_sum, Word16 *exp ); +Word32 w_norm_llQ31( /* o : normalized result Q31 */ + Word64 L_sum, /* i : upper and lower bits of accu, unsigned Q31 */ + Word16 *exp /* o : exponent of result in [-32,31] Q0 */ ) { - Word32 L_tmp; - Word16 exp_val; - Word64 L64_inp64 = L_sum; move64(); - - L64_inp64 = W_shl(L64_inp64, 1); - exp_val = W_norm(L64_inp64); - L64_inp64 = W_shl(L64_inp64, exp_val); - exp_val = sub(31, exp_val); - if (EQ_64(L_sum, 0)) - { - exp_val = -32; move16(); - } - *exp = exp_val; move16(); - - L_tmp = W_extract_h(L64_inp64); - return L_tmp; -} - -Word32 Dot_product16HQ( /* o : normalized result Q31 */ - const Word32 L_off, /* i : initial sum value Qn */ - const Word16 x[], /* i : x vector Qn */ - const Word16 y[], /* i : y vector Qn */ - const Word16 lg, /* i : vector length, range [0..7FFF] Q0 */ - Word16 * exp /* o : exponent of result in [-32,31] Q0 */ + Word32 L_tmp; + Word16 exp_val; + Word64 L64_inp64 = L_sum; + move64(); + + L64_inp64 = W_shl( L64_inp64, 1 ); + exp_val = W_norm( L64_inp64 ); + L64_inp64 = W_shl( L64_inp64, exp_val ); + exp_val = sub( 31, exp_val ); + if ( EQ_64( L_sum, 0 ) ) + { + exp_val = -32; + move16(); + } + *exp = exp_val; + move16(); + + L_tmp = W_extract_h( L64_inp64 ); + return L_tmp; +} + +Word32 Dot_product16HQ( /* o : normalized result Q31 */ + const Word32 L_off, /* i : initial sum value Qn */ + const Word16 x[], /* i : x vector Qn */ + const Word16 y[], /* i : y vector Qn */ + const Word16 lg, /* i : vector length, range [0..7FFF] Q0 */ + Word16 *exp /* o : exponent of result in [-32,31] Q0 */ ) { - Word16 i; - Word32 L_sum; - Word64 L_sum64; + Word16 i; + Word32 L_sum; + Word64 L_sum64; - L_sum64 = W_deposit32_l(L_off); + L_sum64 = W_deposit32_l( L_off ); - FOR(i = 0; i < lg; i++) - { - L_sum64 = W_mac_16_16(L_sum64, x[i], y[i]); - } + FOR( i = 0; i < lg; i++ ) + { + L_sum64 = W_mac_16_16( L_sum64, x[i], y[i] ); + } - L_sum = w_norm_llQ31(L_sum64, exp); - return L_sum; + L_sum = w_norm_llQ31( L_sum64, exp ); + return L_sum; } -Word32 Norm32Norm(const Word32 *x, const Word16 headroom, const Word16 length, Word16 *result_e) +Word32 Norm32Norm( const Word32 *x, const Word16 headroom, const Word16 length, Word16 *result_e ) { - Word32 L_tmp, L_tmp2; - Word16 i, shift, tmp; + Word32 L_tmp, L_tmp2; + Word16 i, shift, tmp; - move16(); - shift = headroom; + move16(); + shift = headroom; - L_tmp = L_deposit_l(0); + L_tmp = L_deposit_l( 0 ); - FOR(i = 0; i < length; i++) - { - L_tmp2 = L_sub(L_tmp, 0x40000000); - if (L_tmp2 >= 0) shift = sub(shift, 1); - if (L_tmp2 >= 0) L_tmp = L_shr(L_tmp, 2); + FOR( i = 0; i < length; i++ ) + { + L_tmp2 = L_sub( L_tmp, 0x40000000 ); + if ( L_tmp2 >= 0 ) + shift = sub( shift, 1 ); + if ( L_tmp2 >= 0 ) + L_tmp = L_shr( L_tmp, 2 ); #ifdef BASOP_NOGLOB - tmp = round_fx_sat(L_shl_sat(x[i], shift)); - L_tmp = L_mac0_sat(L_tmp, tmp, tmp); /* exponent = (1-shift*2) , Q(30+shift*2) */ + tmp = round_fx_sat( L_shl_sat( x[i], shift ) ); + L_tmp = L_mac0_sat( L_tmp, tmp, tmp ); /* exponent = (1-shift*2) , Q(30+shift*2) */ #else - tmp = round_fx(L_shl(x[i], shift)); - L_tmp = L_mac0(L_tmp, tmp, tmp); /* exponent = (1-shift*2) , Q(30+shift*2) */ + tmp = round_fx( L_shl( x[i], shift ) ); + L_tmp = L_mac0( L_tmp, tmp, tmp ); /* exponent = (1-shift*2) , Q(30+shift*2) */ #endif - } + } - move16(); - *result_e = sub(1, shl(shift, 1)); + move16(); + *result_e = sub( 1, shl( shift, 1 ) ); - return L_tmp; + return L_tmp; } -Word32 Dot_productSq16HQ( /* o : normalized result Q31 */ - const Word32 L_off, /* i : initial sum value Qn */ - const Word16 x[], /* i : x vector Qn */ - const Word16 lg, /* i : vector length, range [0..7FFF] Q0 */ - Word16 * exp /* o : exponent of result in [-32,31] Q0 */ +Word32 Dot_productSq16HQ( /* o : normalized result Q31 */ + const Word32 L_off, /* i : initial sum value Qn */ + const Word16 x[], /* i : x vector Qn */ + const Word16 lg, /* i : vector length, range [0..7FFF] Q0 */ + Word16 *exp /* o : exponent of result in [-32,31] Q0 */ ) { - Word16 i; - Word32 L_sum; - Word64 L_sum64; + Word16 i; + Word32 L_sum; + Word64 L_sum64; - L_sum64 = W_deposit32_l(L_off); + L_sum64 = W_deposit32_l( L_off ); - FOR(i = 0; i < lg; i++) - { - L_sum64 = W_mac_16_16(L_sum64, x[i], x[i]); - } - L_sum = w_norm_llQ31(L_sum64, exp); + FOR( i = 0; i < lg; i++ ) + { + L_sum64 = W_mac_16_16( L_sum64, x[i], x[i] ); + } + L_sum = w_norm_llQ31( L_sum64, exp ); - return L_sum; + return L_sum; } -Word32 dotp_s_fx(const Word16 *x, const Word16 *y, const Word16 n, Word16 s) +Word32 dotp_s_fx( const Word16 *x, const Word16 *y, const Word16 n, Word16 s ) { - Word16 i; - Word16 n2; - Word32 L_tmp; - Word32 L_sum; + Word16 i; + Word16 n2; + Word32 L_tmp; + Word32 L_sum; - L_sum = 0; - move32(); + L_sum = 0; + move32(); - n2 = shr(n, 1); + n2 = shr( n, 1 ); - s = sub(s, 1); + s = sub( s, 1 ); - FOR(i = 0; i < n2; i++) - { - L_tmp = L_mult0(x[2 * i], y[2 * i]); - L_tmp = L_mac0(L_tmp, x[2 * i + 1], y[2 * i + 1]); - L_sum = L_add(L_sum, L_shr(L_tmp, s)); - } + FOR( i = 0; i < n2; i++ ) + { + L_tmp = L_mult0( x[2 * i], y[2 * i] ); + L_tmp = L_mac0( L_tmp, x[2 * i + 1], y[2 * i + 1] ); + L_sum = L_add( L_sum, L_shr( L_tmp, s ) ); + } - IF(s_and(n, 1)) - { - L_tmp = L_mult0(x[n - 1], y[n - 1]); - L_sum = L_add(L_sum, L_shr(L_tmp, s)); - } + IF( s_and( n, 1 ) ) + { + L_tmp = L_mult0( x[n - 1], y[n - 1] ); + L_sum = L_add( L_sum, L_shr( L_tmp, s ) ); + } - return L_sum; + return L_sum; } Word32 BASOP_util_Pow2( - const Word32 exp_m, const Word16 exp_e, - Word16 *result_e -) + const Word32 exp_m, + const Word16 exp_e, + Word16 *result_e ) { - static const Word16 pow2Coeff[8] = - { - 22713/*0.693147180559945309417232121458177 Q15*/, /* ln(2)^1 /1! */ - 7872/*0.240226506959100712333551263163332 Q15*/, /* ln(2)^2 /2! */ - 1819/*0.0555041086648215799531422637686218 Q15*/, /* ln(2)^3 /3! */ - 315/*0.00961812910762847716197907157365887 Q15*/, /* ln(2)^4 /4! */ - 44/*0.00133335581464284434234122219879962 Q15*/, /* ln(2)^5 /5! */ - 5/*1.54035303933816099544370973327423e-4 Q15*/, /* ln(2)^6 /6! */ - 0/*1.52527338040598402800254390120096e-5 Q15*/, /* ln(2)^7 /7! */ - 0/*1.32154867901443094884037582282884e-6 Q15*/ /* ln(2)^8 /8! */ - }; - - Word32 frac_part, tmp_frac, result_m; - Word16 int_part; - - int_part = 0; /* to avoid compilation warnings */ - frac_part = 0; /* to avoid compilation warnings */ - - IF(exp_e > 0) - { - /* "+ 1" compensates L_shr(,1) of the polynomial evaluation at the loop end. */ - - int_part = add(1, extract_l(L_shr(exp_m, sub(31, exp_e)))); - frac_part = L_lshl(exp_m, exp_e); - frac_part = L_and(0x7FFFFFFF, frac_part); - } - if (exp_e <= 0) - frac_part = L_shl(exp_m, exp_e); - if (exp_e <= 0) - { - int_part = 1; - move16(); - } - - /* Best accuracy is around 0, so try to get there with the fractional part. */ - IF((tmp_frac = L_sub(frac_part, 1073741824l/*0.5 Q31*/)) >= 0) - { - int_part = add(int_part, 1); - frac_part = L_sub(tmp_frac, 1073741824l/*0.5 Q31*/); - } - ELSE IF((tmp_frac = L_add(frac_part, 1073741824l/*0.5 Q31*/)) < 0) - { - int_part = sub(int_part, 1); - frac_part = L_add(tmp_frac, 1073741824l/*0.5 Q31*/); - } - - /* Evaluate taylor polynomial which approximates 2^x */ - { - Word32 p; - Word16 i; + static const Word16 pow2Coeff[8] = { + 22713 /*0.693147180559945309417232121458177 Q15*/, /* ln(2)^1 /1! */ + 7872 /*0.240226506959100712333551263163332 Q15*/, /* ln(2)^2 /2! */ + 1819 /*0.0555041086648215799531422637686218 Q15*/, /* ln(2)^3 /3! */ + 315 /*0.00961812910762847716197907157365887 Q15*/, /* ln(2)^4 /4! */ + 44 /*0.00133335581464284434234122219879962 Q15*/, /* ln(2)^5 /5! */ + 5 /*1.54035303933816099544370973327423e-4 Q15*/, /* ln(2)^6 /6! */ + 0 /*1.52527338040598402800254390120096e-5 Q15*/, /* ln(2)^7 /7! */ + 0 /*1.32154867901443094884037582282884e-6 Q15*/ /* ln(2)^8 /8! */ + }; + + Word32 frac_part, tmp_frac, result_m; + Word16 int_part; + + int_part = 0; /* to avoid compilation warnings */ + frac_part = 0; /* to avoid compilation warnings */ + + IF( exp_e > 0 ) + { + /* "+ 1" compensates L_shr(,1) of the polynomial evaluation at the loop end. */ + int_part = add( 1, extract_l( L_shr( exp_m, sub( 31, exp_e ) ) ) ); + frac_part = L_lshl( exp_m, exp_e ); + frac_part = L_and( 0x7FFFFFFF, frac_part ); + } + if ( exp_e <= 0 ) + frac_part = L_shl( exp_m, exp_e ); + if ( exp_e <= 0 ) + { + int_part = 1; + move16(); + } + + /* Best accuracy is around 0, so try to get there with the fractional part. */ + IF( ( tmp_frac = L_sub( frac_part, 1073741824l /*0.5 Q31*/ ) ) >= 0 ) + { + int_part = add( int_part, 1 ); + frac_part = L_sub( tmp_frac, 1073741824l /*0.5 Q31*/ ); + } + ELSE IF( ( tmp_frac = L_add( frac_part, 1073741824l /*0.5 Q31*/ ) ) < 0 ) + { + int_part = sub( int_part, 1 ); + frac_part = L_add( tmp_frac, 1073741824l /*0.5 Q31*/ ); + } - /* First taylor series coefficient a_0 = 1.0, scaled by 0.5 due to L_shr(,1). */ - result_m = L_add(1073741824l/*1.0/2.0 Q31*/, L_shr(Mpy_32_16_1(frac_part, pow2Coeff[0]), 1)); - p = Mpy_32_32(frac_part, frac_part); - FOR(i = 1; i < 7; i++) + /* Evaluate taylor polynomial which approximates 2^x */ { - /* next taylor series term: a_i * x^i, x=0 */ - result_m = L_add(result_m, L_shr(Mpy_32_16_1(p, pow2Coeff[i]), 1)); - p = Mpy_32_32(p, frac_part); + Word32 p; + Word16 i; + + + /* First taylor series coefficient a_0 = 1.0, scaled by 0.5 due to L_shr(,1). */ + result_m = L_add( 1073741824l /*1.0/2.0 Q31*/, L_shr( Mpy_32_16_1( frac_part, pow2Coeff[0] ), 1 ) ); + p = Mpy_32_32( frac_part, frac_part ); + FOR( i = 1; i < 7; i++ ) + { + /* next taylor series term: a_i * x^i, x=0 */ + result_m = L_add( result_m, L_shr( Mpy_32_16_1( p, pow2Coeff[i] ), 1 ) ); + p = Mpy_32_32( p, frac_part ); + } + result_m = L_add( result_m, L_shr( Mpy_32_16_1( p, pow2Coeff[i] ), 1 ) ); } - result_m = L_add(result_m, L_shr(Mpy_32_16_1(p, pow2Coeff[i]), 1)); - } - *result_e = int_part; - move16(); - return result_m; + *result_e = int_part; + move16(); + return result_m; } -Word16 findIndexOfMaxWord32(Word32 *x, const Word16 len) +Word16 findIndexOfMaxWord32( Word32 *x, const Word16 len ) { - Word16 i, indx; + Word16 i, indx; - indx = 0; - move16(); - FOR(i = 1; i < len; i++) - { - if (GT_32(x[i], x[indx])) + indx = 0; + move16(); + FOR( i = 1; i < len; i++ ) { - indx = i; - move16(); + if ( GT_32( x[i], x[indx] ) ) + { + indx = i; + move16(); + } } - } - return indx; + return indx; } -Word16 getNormReciprocalWord16(Word16 x) +Word16 getNormReciprocalWord16( Word16 x ) { - assert(x < (Word16)(sizeof(BASOP_util_normReciprocal) / sizeof(BASOP_util_normReciprocal[0]))); + assert( x < (Word16) ( sizeof( BASOP_util_normReciprocal ) / sizeof( BASOP_util_normReciprocal[0] ) ) ); - return extract_h(BASOP_util_normReciprocal[x]); + return extract_h( BASOP_util_normReciprocal[x] ); } -Word16 getNormReciprocalWord16Scale(Word16 x, Word16 s) +Word16 getNormReciprocalWord16Scale( Word16 x, Word16 s ) { - assert(x < (Word16)(sizeof(BASOP_util_normReciprocal) / sizeof(BASOP_util_normReciprocal[0]))); + assert( x < (Word16) ( sizeof( BASOP_util_normReciprocal ) / sizeof( BASOP_util_normReciprocal[0] ) ) ); - return round_fx(L_shl(BASOP_util_normReciprocal[x], s)); + return round_fx( L_shl( BASOP_util_normReciprocal[x], s ) ); } @@ -2014,187 +2008,186 @@ Word32 BASOP_Util_fPow( | dot_product = L_off + sum(x[i]*y[i]) i=0..N-1 | |___________________________________________________________________________| */ -Word32 Dot_product12_offs( /* (o) Q31: normalized result (1 < val <= -1) */ - const Word16 x[], /* (i) 12bits: x vector */ - const Word16 y[], /* (i) 12bits: y vector */ - const Word16 lg, /* (i) : vector length in range [1..256] */ - Word16 * exp, /* (o) : exponent of result (0..+30) */ - Word32 L_off /* (i) initial summation offset / 2 */ +Word32 Dot_product12_offs( /* (o) Q31: normalized result (1 < val <= -1) */ + const Word16 x[], /* (i) 12bits: x vector */ + const Word16 y[], /* (i) 12bits: y vector */ + const Word16 lg, /* (i) : vector length in range [1..256] */ + Word16 *exp, /* (o) : exponent of result (0..+30) */ + Word32 L_off /* (i) initial summation offset / 2 */ ) { - Word16 i, sft; - Word32 L_sum; + Word16 i, sft; + Word32 L_sum; - Word64 L_sum64; + Word64 L_sum64; - L_sum64 = W_deposit32_l(L_off); - FOR(i = 0; i < lg; i++) - { - L_sum64 = W_mac0_16_16(L_sum64, x[i], y[i]); - } - L_sum = W_sat_l(L_sum64); + L_sum64 = W_deposit32_l( L_off ); + FOR( i = 0; i < lg; i++ ) + { + L_sum64 = W_mac0_16_16( L_sum64, x[i], y[i] ); + } + L_sum = W_sat_l( L_sum64 ); - /* Normalize acc in Q31 */ + /* Normalize acc in Q31 */ - sft = norm_l(L_sum); - if (exp != NULL) - { - L_sum = L_shl(L_sum, sft); - } + sft = norm_l( L_sum ); + if ( exp != NULL ) + { + L_sum = L_shl( L_sum, sft ); + } - /* exponent = 0..30, when L_sum != 0 */ - if (L_sum != 0) - { - sft = sub(31, sft); - } + /* exponent = 0..30, when L_sum != 0 */ + if ( L_sum != 0 ) + { + sft = sub( 31, sft ); + } - if (exp != NULL) - { - *exp = sft; - move16(); - } + if ( exp != NULL ) + { + *exp = sft; + move16(); + } - return L_sum; + return L_sum; } -Word32 Dot_product15_offs( /* (o) Q31: normalized result (1 < val <= -1) */ - const Word16 x[], /* (i) 15bits: x vector */ - const Word16 y[], /* (i) 15bits: y vector */ - const Word16 lg, /* (i) : vector length in range [1..256] */ - Word16 *exp, /* (o) : exponent of result (0..+30) */ - Word32 L_off /* (i) initial summation offset */ +Word32 Dot_product15_offs( /* (o) Q31: normalized result (1 < val <= -1) */ + const Word16 x[], /* (i) 15bits: x vector */ + const Word16 y[], /* (i) 15bits: y vector */ + const Word16 lg, /* (i) : vector length in range [1..256] */ + Word16 *exp, /* (o) : exponent of result (0..+30) */ + Word32 L_off /* (i) initial summation offset */ ) { - Word16 i, sft, fac, ld; - Word32 L_sum; + Word16 i, sft, fac, ld; + Word32 L_sum; - ld = sub(14, norm_s(lg)); - fac = shr(-32768, ld); - L_sum = L_shr(L_off, ld); + ld = sub( 14, norm_s( lg ) ); + fac = shr( -32768, ld ); + L_sum = L_shr( L_off, ld ); - FOR(i = 0; i < lg; i++) - { - L_sum = L_add(L_sum, Mpy_32_16_1(L_msu(0, y[i], fac), x[i])); - } + FOR( i = 0; i < lg; i++ ) + { + L_sum = L_add( L_sum, Mpy_32_16_1( L_msu( 0, y[i], fac ), x[i] ) ); + } - /* Avoid returning 0 */ - if (L_sum == 0) - { - L_sum = L_add(L_sum, 1); - } + /* Avoid returning 0 */ + if ( L_sum == 0 ) + { + L_sum = L_add( L_sum, 1 ); + } - /* Normalize acc in Q31 */ - sft = norm_l(L_sum); - L_sum = L_shl(L_sum, sft); + /* Normalize acc in Q31 */ + sft = norm_l( L_sum ); + L_sum = L_shl( L_sum, sft ); - /* exponent = 0..30, when L_sum != 0 */ - if (L_sum != 0) - { - sft = add(ld, sub(30, sft)); - } + /* exponent = 0..30, when L_sum != 0 */ + if ( L_sum != 0 ) + { + sft = add( ld, sub( 30, sft ) ); + } - *exp = sft; - move16(); + *exp = sft; + move16(); - return L_sum; + return L_sum; } -Word16 BASOP_Util_Cmp_Mant32Exp /*!< o: flag: result of comparison */ -/* 0, if a == b */ -/* 1, if a > b */ -/* -1, if a < b */ -(Word32 a_m, /*!< i: Mantissa of 1st operand a */ - Word16 a_e, /*!< i: Exponent of 1st operand a */ - Word32 b_m, /*!< i: Mantissa of 2nd operand b */ - Word16 b_e) /*!< i: Exponent of 2nd operand b */ +Word16 BASOP_Util_Cmp_Mant32Exp /*!< o: flag: result of comparison */ + /* 0, if a == b */ + /* 1, if a > b */ + /* -1, if a < b */ + ( Word32 a_m, /*!< i: Mantissa of 1st operand a */ + Word16 a_e, /*!< i: Exponent of 1st operand a */ + Word32 b_m, /*!< i: Mantissa of 2nd operand b */ + Word16 b_e ) /*!< i: Exponent of 2nd operand b */ { - Word32 diff_m; - Word16 diff_e, shift, result; + Word32 diff_m; + Word16 diff_e, shift, result; + /* + This function compares two input parameters, both represented by a 32-bit mantissa and a 16-bit exponent. + If both values are identical, 0 is returned. + If a is greater b, 1 is returned. + If a is less than b, -1 is returned. + */ - /* - This function compares two input parameters, both represented by a 32-bit mantissa and a 16-bit exponent. - If both values are identical, 0 is returned. - If a is greater b, 1 is returned. - If a is less than b, -1 is returned. - */ - - /* Check, if both mantissa and exponents are identical, when normalized: return 0 */ - shift = norm_l(a_m); - if (shift) - a_m = L_shl(a_m, shift); - if (shift) - a_e = sub(a_e, shift); + /* Check, if both mantissa and exponents are identical, when normalized: return 0 */ + shift = norm_l( a_m ); + if ( shift ) + a_m = L_shl( a_m, shift ); + if ( shift ) + a_e = sub( a_e, shift ); - shift = norm_l(b_m); - if (shift) - b_m = L_shl(b_m, shift); - if (shift) - b_e = sub(b_e, shift); + shift = norm_l( b_m ); + if ( shift ) + b_m = L_shl( b_m, shift ); + if ( shift ) + b_e = sub( b_e, shift ); - /* align exponent, if any mantissa is zero */ - if (!a_m) - { - a_e = b_e; - move16(); - } - if (!b_m) - { - b_e = a_e; - move16(); - } + /* align exponent, if any mantissa is zero */ + if ( !a_m ) + { + a_e = b_e; + move16(); + } + if ( !b_m ) + { + b_e = a_e; + move16(); + } - BASOP_SATURATE_WARNING_OFF_EVS + BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB - diff_m = L_sub_sat( a_m, b_m ); + diff_m = L_sub_sat( a_m, b_m ); #else - diff_m = L_sub(a_m, b_m); + diff_m = L_sub( a_m, b_m ); #endif - BASOP_SATURATE_WARNING_ON_EVS - diff_e = sub(a_e, b_e); + BASOP_SATURATE_WARNING_ON_EVS + diff_e = sub( a_e, b_e ); - test(); - IF(diff_m == 0 && diff_e == 0) - { - return 0; - } - - /* Check sign, exponent and mantissa to identify, whether a is greater b or not */ - result = sub(0, 1); - - IF(a_m >= 0) - { - /* a is positive */ - if (b_m < 0) + test(); + IF( diff_m == 0 && diff_e == 0 ) { - result = 1; - move16(); + return 0; } - test(); - test(); - test(); - if ((b_m >= 0) && ((diff_e > 0) || (diff_e == 0 && diff_m > 0))) + /* Check sign, exponent and mantissa to identify, whether a is greater b or not */ + result = sub( 0, 1 ); + + IF( a_m >= 0 ) { - result = 1; - move16(); + /* a is positive */ + if ( b_m < 0 ) + { + result = 1; + move16(); + } + + test(); + test(); + test(); + if ( ( b_m >= 0 ) && ( ( diff_e > 0 ) || ( diff_e == 0 && diff_m > 0 ) ) ) + { + result = 1; + move16(); + } } - } - ELSE - { - /* a is negative */ - test(); - test(); - test(); - if ((b_m < 0) && ((diff_e < 0) || (diff_e == 0 && diff_m > 0))) + ELSE { - result = 1; - move16(); + /* a is negative */ + test(); + test(); + test(); + if ( ( b_m < 0 ) && ( ( diff_e < 0 ) || ( diff_e == 0 && diff_m > 0 ) ) ) + { + result = 1; + move16(); + } } - } - return result; + return result; } /* @@ -2295,351 +2288,350 @@ Word32 Isqrt_lc1( } - void bufferCopyFx( - Word16* src, /*old_exc, exc_buf, st->old_exc_len);*/ - tmp_16 = sub(sub(Qf_src, Qf_dest), sub(Q_src, Q_dest)); - IF(tmp_16 > 0) /*if value will be shifted right, do a multiplication with rounding ->preserves more accuracy*/ - { - tmp_16 = shl(1, sub(15, tmp_16)); - FOR(i = 0; i < length; i++) + /*Copy( st->old_exc, exc_buf, st->old_exc_len);*/ + tmp_16 = sub( sub( Qf_src, Qf_dest ), sub( Q_src, Q_dest ) ); + IF( tmp_16 > 0 ) /*if value will be shifted right, do a multiplication with rounding ->preserves more accuracy*/ { - *(dest + i) = mult_r(*(src + i), tmp_16); - move16(); + tmp_16 = shl( 1, sub( 15, tmp_16 ) ); + FOR( i = 0; i < length; i++ ) + { + *( dest + i ) = mult_r( *( src + i ), tmp_16 ); + move16(); + } } - } - ELSE IF(tmp_16 < 0)/*leftshift - no accuracy preservation needed*/ - { - FOR(i = 0; i < length; i++) + ELSE IF( tmp_16 < 0 ) /*leftshift - no accuracy preservation needed*/ { + FOR( i = 0; i < length; i++ ) + { #ifdef BASOP_NOGLOB - *(dest + i) = shr_sat(*(src + i), tmp_16); + *( dest + i ) = shr_sat( *( src + i ), tmp_16 ); #else - *(dest + i) = shr(*(src + i), tmp_16); + *( dest + i ) = shr( *( src + i ), tmp_16 ); #endif - move16(); + move16(); + } + } + ELSE /*no shift, simply copy*/ + { + FOR( i = 0; i < length; i++ ) + { + *( dest + i ) = *( src + i ); + move16(); + } } - } - ELSE /*no shift, simply copy*/ - { - FOR(i = 0; i < length; i++) - { - *(dest + i) = *(src + i); - move16(); - } - } } -Word32 dotWord32_16_Mant32Exp(const Word32 *bufX32,/* i: 32-bit buffer with unknown headroom */ - Word16 bufX32_exp, /* i: exponent of buffer bufX32 */ - const Word16 *bufY16,/* i: 16-bit buffer quite right-aligned */ - Word16 bufY16_exp, /* i: exponent of buffer bufY16 */ - Word16 len, /* i: buffer len to process */ - Word16 *exp) /* o: result exponent */ +Word32 dotWord32_16_Mant32Exp( const Word32 *bufX32, /* i: 32-bit buffer with unknown headroom */ + Word16 bufX32_exp, /* i: exponent of buffer bufX32 */ + const Word16 *bufY16, /* i: 16-bit buffer quite right-aligned */ + Word16 bufY16_exp, /* i: exponent of buffer bufY16 */ + Word16 len, /* i: buffer len to process */ + Word16 *exp ) /* o: result exponent */ { - Word32 L_sum; - Word16 shift, shift1, i; - + Word32 L_sum; + Word16 shift, shift1, i; - shift = getScaleFactor32(bufX32, len); /* current available headroom */ - shift = sub(shift, sub(14, norm_s(len))); /* reduced required headroom */ - L_sum = 0; /* Clear accu */ - move32(); - FOR(i = 0; i < len; i++) - { - L_sum = L_mac0(L_sum, round_fx(L_shl(bufX32[i], shift)), bufY16[i]); - } - shift1 = norm_l(L_sum); - L_sum = L_shl(L_sum, shift1); /* return value */ - - shift = sub(add(bufX32_exp, bufY16_exp), add(shift, shift1)); - shift = add(shift, 1); /* compensate for factor of 2 introduced by L_mac0 */ - /* In case of NULL result, we want to have a 0 exponent too */ - if (L_sum == 0) - shift = 0; - *exp = shift; - move16(); - + shift = getScaleFactor32( bufX32, len ); /* current available headroom */ + shift = sub( shift, sub( 14, norm_s( len ) ) ); /* reduced required headroom */ + L_sum = 0; /* Clear accu */ + move32(); + FOR( i = 0; i < len; i++ ) + { + L_sum = L_mac0( L_sum, round_fx( L_shl( bufX32[i], shift ) ), bufY16[i] ); + } + shift1 = norm_l( L_sum ); + L_sum = L_shl( L_sum, shift1 ); /* return value */ + + shift = sub( add( bufX32_exp, bufY16_exp ), add( shift, shift1 ) ); + shift = add( shift, 1 ); /* compensate for factor of 2 introduced by L_mac0 */ + /* In case of NULL result, we want to have a 0 exponent too */ + if ( L_sum == 0 ) + shift = 0; + *exp = shift; + move16(); - return L_sum; + return L_sum; } -Word16 BASOP_Util_lin2dB(Word32 x, Word16 x_e, Word16 fEnergy) +Word16 BASOP_Util_lin2dB( Word32 x, Word16 x_e, Word16 fEnergy ) { - assert(x >= 0); + assert( x >= 0 ); - /* log2 */ - x = L_shr(BASOP_Util_Log2(x), 25 - 16); /* Q16 */ + /* log2 */ + x = L_shr( BASOP_Util_Log2( x ), 25 - 16 ); /* Q16 */ - /* add exponent */ - x = L_msu(x, x_e, -32768 /* 0x8000 */); + /* add exponent */ + x = L_msu( x, x_e, -32768 /* 0x8000 */ ); - /* convert log2 to 20*log10 */ - x = Mpy_32_16_1(x, 24660/*6.0206f Q12*/); /* Q13 */ + /* convert log2 to 20*log10 */ + x = Mpy_32_16_1( x, 24660 /*6.0206f Q12*/ ); /* Q13 */ - /* if energy divide by 2 (->10*log10) */ - if (fEnergy != 0) x = L_shr(x, 1); + /* if energy divide by 2 (->10*log10) */ + if ( fEnergy != 0 ) + x = L_shr( x, 1 ); - /* return dB as 7Q8 */ - return round_fx(L_shl(x, 8 - 13 + 16)); /* Q8 */ + /* return dB as 7Q8 */ + return round_fx( L_shl( x, 8 - 13 + 16 ) ); /* Q8 */ } /* --- fixp_atan() ---- */ -#define Q_ATANINP (25) /* Input in q25, Output in q14 */ -#define Q_ATANOUT (14) -#define ATI_SF ((32-1)-Q_ATANINP) /* 6 */ -#define ATO_SF ((16-1)-Q_ATANOUT) /* 1 ] -pi/2 .. pi/2 [ */ +#define Q_ATANINP ( 25 ) /* Input in q25, Output in q14 */ +#define Q_ATANOUT ( 14 ) +#define ATI_SF ( ( 32 - 1 ) - Q_ATANINP ) /* 6 */ +#define ATO_SF ( ( 16 - 1 ) - Q_ATANOUT ) /* 1 ] -pi/2 .. pi/2 [ */ /* --- fixp_atan2() --- */ -#define Q_ATAN2OUT (13) -#define AT2O_SF ((16-1)-Q_ATAN2OUT) /* 2 ] -pi .. pi ] */ +#define Q_ATAN2OUT ( 13 ) +#define AT2O_SF ( ( 16 - 1 ) - Q_ATAN2OUT ) /* 2 ] -pi .. pi ] */ -Word16 BASOP_util_atan2( /* o: atan2(y,x) [-pi,pi] Q13 */ - Word32 y, /* i: */ - Word32 x, /* i: */ - Word16 e /* i: exponent difference (exp_y - exp_x) */ +Word16 BASOP_util_atan2( /* o: atan2(y,x) [-pi,pi] Q13 */ + Word32 y, /* i: */ + Word32 x, /* i: */ + Word16 e /* i: exponent difference (exp_y - exp_x) */ ) { - Word16 q; - Word32 at; - Word16 ret = -32768/*-1.0f Q15*/; - Word16 sf, sfo, stf; - Word32 L_sign; + Word16 q; + Word32 at; + Word16 ret = -32768 /*-1.0f Q15*/; + Word16 sf, sfo, stf; + Word32 L_sign; - if (L_or(y, x) == 0) - { - return 0; - } - - IF(x == 0) - { - ret = 12868/*+EVS_PI/2 Q13*/; - move16(); - if (y < 0) + if ( L_or( y, x ) == 0 ) { - ret = negate(ret); + return 0; } - return ret; - } + IF( x == 0 ) + { + ret = 12868 /*+EVS_PI/2 Q13*/; + move16(); + if ( y < 0 ) + { + ret = negate( ret ); + } - /* --- division */ - L_sign = L_and(L_xor(x, y), 0x80000000); + return ret; + } + + /* --- division */ + L_sign = L_and( L_xor( x, y ), 0x80000000 ); - q = 32767/*1.0f Q15*/; /* y/x = neg/zero = -Inf */ - sf = 0; - BASOP_SATURATE_WARNING_OFF_EVS - q = BASOP_Util_Divide3232_uu_1616_Scale(L_abs(y), L_abs(x), &sf); - BASOP_SATURATE_WARNING_ON_EVS + q = 32767 /*1.0f Q15*/; /* y/x = neg/zero = -Inf */ + sf = 0; + BASOP_SATURATE_WARNING_OFF_EVS + q = BASOP_Util_Divide3232_uu_1616_Scale( L_abs( y ), L_abs( x ), &sf ); + BASOP_SATURATE_WARNING_ON_EVS BASOP_SATURATE_WARNING_OFF_EVS - if (L_sign < 0) - q = negate(q); - BASOP_SATURATE_WARNING_ON_EVS + if ( L_sign < 0 ) + q = negate( q ); + BASOP_SATURATE_WARNING_ON_EVS - sfo = add(sf, e); + sfo = add( sf, e ); - /* --- atan() */ - IF(GT_16(sfo, ATI_SF)) - { - /* --- could not calc fixp_atan() here bec of input data out of range - ==> therefore give back boundary values */ + /* --- atan() */ + IF( GT_16( sfo, ATI_SF ) ) + { + /* --- could not calc fixp_atan() here bec of input data out of range + ==> therefore give back boundary values */ - sfo = s_min(sfo, MAXSFTAB); + sfo = s_min( sfo, MAXSFTAB ); - /*q = FL2WORD16( 0.0f ); move16();*/ + /*q = FL2WORD16( 0.0f ); move16();*/ - if (q > 0) - { - move16(); - q = +f_atan_expand_range[sfo - ATI_SF - 1]; + if ( q > 0 ) + { + move16(); + q = +f_atan_expand_range[sfo - ATI_SF - 1]; + } + if ( q < 0 ) + { + move16(); + q = -f_atan_expand_range[sfo - ATI_SF - 1]; + } } - if (q < 0) + ELSE { - move16(); - q = -f_atan_expand_range[sfo - ATI_SF - 1]; - } - } - ELSE - { - /* --- calc of fixp_atan() is possible; input data within range - ==> set q on fixed scale level as desired from fixp_atan() */ - stf = sub(sfo, ATI_SF); + /* --- calc of fixp_atan() is possible; input data within range + ==> set q on fixed scale level as desired from fixp_atan() */ + stf = sub( sfo, ATI_SF ); - at = L_deposit_h(q); - if (stf < 0) at = L_shl(at,stf); + at = L_deposit_h( q ); + if ( stf < 0 ) + at = L_shl( at, stf ); - q = BASOP_util_atan(at); /* ATO_SF*/ - } + q = BASOP_util_atan( at ); /* ATO_SF*/ + } /* --- atan2() */ - ret = shr(q, (AT2O_SF - ATO_SF)); /* now AT2O_SF for atan2 */ - IF(x < 0) - { - if (y >= 0) - { - ret = add(ret, 25736/*EVS_PI Q13*/); - } - if (y < 0) + ret = shr( q, ( AT2O_SF - ATO_SF ) ); /* now AT2O_SF for atan2 */ + IF( x < 0 ) { - ret = sub(ret, 25736/* EVS_PI Q13*/); + if ( y >= 0 ) + { + ret = add( ret, 25736 /*EVS_PI Q13*/ ); + } + if ( y < 0 ) + { + ret = sub( ret, 25736 /* EVS_PI Q13*/ ); + } } - } - return ret; + return ret; } /* SNR of fixp_atan() = 56 dB*/ -#define ONEBY3P56 0x26800000 /* 1.0/3.56 in q31*/ -#define P281 0x00026000 /* 0.281 in q19*/ -#define ONEP571 0x6487 /* 1.571 in q14*/ +#define ONEBY3P56 0x26800000 /* 1.0/3.56 in q31*/ +#define P281 0x00026000 /* 0.281 in q19*/ +#define ONEP571 0x6487 /* 1.571 in q14*/ -Word16 BASOP_util_atan( /* o: atan(x) [-pi/2;pi/2] 1Q14 */ - Word32 x /* i: input data (-64;64) 6Q25 */ +Word16 BASOP_util_atan( /* o: atan(x) [-pi/2;pi/2] 1Q14 */ + Word32 x /* i: input data (-64;64) 6Q25 */ ) { - Word16 sign, result, exp; - Word16 res_e; - Word16 tmp, xx; - + Word16 sign, result, exp; + Word16 res_e; + Word16 tmp, xx; - sign = 0; - move16(); - if (x < 0) - { - sign = 1; - move16(); - } - x = L_abs(x); - - /* calc of arctan */ - IF(LT_32(x, 1509950l/*0.045f/64.0f Q31*/)) - { - result = round_fx(L_shl(x, 5)); /*Q14*/ - /*BASOP_util_atan_16(0.0444059968): max error 0.0000567511, mean 0.000017, abs mean 0.000017*/ - } - ELSE - IF(LT_32(x, (L_shl(1, Q_ATANINP) - 8482560l/*0.00395 Q31*/))) - { - xx = round_fx(L_shl(x, 6)); - tmp = mult_r(xx, xx); /* q15 * q15 - (16-1) = q15*/ - tmp = mult_r(tmp, 0x1340); /* 15 * (ONEBY3P56) q14 - (16-1) = q14*/ - tmp = add(tmp, 0x4000); /*L_shl(1,14) = 524288*/ /* q14 + q14 = q14 */ - res_e = Q_ATANOUT - 15 + 14 - 16 + 1; + sign = 0; move16(); - if (GT_16(xx, tmp)) + if ( x < 0 ) { - res_e = add(res_e, 1); + sign = 1; + move16(); } - if (GT_16(xx, tmp)) + x = L_abs( x ); + + /* calc of arctan */ + IF( LT_32( x, 1509950l /*0.045f/64.0f Q31*/ ) ) { - xx = shr(xx, 1); + result = round_fx( L_shl( x, 5 ) ); /*Q14*/ + /*BASOP_util_atan_16(0.0444059968): max error 0.0000567511, mean 0.000017, abs mean 0.000017*/ } - result = div_s(xx, tmp); - result = msu_r(0, result, shl(-32768, res_e)); - /*BASOP_util_atan_16(0.7471138239): max error 0.0020029545, mean 0.000715, abs mean 0.000715*/ - } - ELSE IF(LT_32(x, 42949673l/*1.28/64.0 Q31*/)) - { - Word16 delta_fix; - Word32 PI_BY_4 = 1686629684l/*3.1415926/4.0 Q31*/ / 2; /* pi/4 in q30 */ + ELSE + IF( LT_32( x, ( L_shl( 1, Q_ATANINP ) - 8482560l /*0.00395 Q31*/ ) ) ) + { + xx = round_fx( L_shl( x, 6 ) ); + tmp = mult_r( xx, xx ); /* q15 * q15 - (16-1) = q15*/ + tmp = mult_r( tmp, 0x1340 ); /* 15 * (ONEBY3P56) q14 - (16-1) = q14*/ + tmp = add( tmp, 0x4000 ); /*L_shl(1,14) = 524288*/ /* q14 + q14 = q14 */ + res_e = Q_ATANOUT - 15 + 14 - 16 + 1; + move16(); + if ( GT_16( xx, tmp ) ) + { + res_e = add( res_e, 1 ); + } + if ( GT_16( xx, tmp ) ) + { + xx = shr( xx, 1 ); + } + result = div_s( xx, tmp ); + result = msu_r( 0, result, shl( -32768, res_e ) ); + /*BASOP_util_atan_16(0.7471138239): max error 0.0020029545, mean 0.000715, abs mean 0.000715*/ + } + ELSE IF( LT_32( x, 42949673l /*1.28/64.0 Q31*/ ) ) + { + Word16 delta_fix; + Word32 PI_BY_4 = 1686629684l /*3.1415926/4.0 Q31*/ / 2; /* pi/4 in q30 */ - delta_fix = round_fx(L_shl(L_sub(x, 33554432l/*1.0/64.0 Q31*/), 5)); /* q30 */ - result = round_fx(L_sub(L_add(PI_BY_4, L_msu(0, delta_fix, -16384)), (L_mult0(delta_fix, delta_fix)))); - /* BASOP_Util_fPow(0.7472000122): max error 0.0020237688, mean 0.000026, abs mean 0.000520 */ - } - ELSE - { - exp = sub(norm_l(x),1); - xx = round_fx(L_shl(x,exp)); - /* q25+exp * q25+exp - (16-1) = q19+2*exp*/ - tmp = mac_r(L_shl(P281,shl(exp,1)),xx, xx); /* q19+2*exp + q19+2*exp = q19+2*exp*/ - res_e = norm_s(tmp); - result = div_s(xx, shl(tmp,res_e)); - result = shl(result, add(add(Q_ATANOUT - Q_ATANINP/*-exp*/ + 19/*+2*exp*/ - 16 + 1, res_e),exp)); - result = sub(ONEP571,result); /* q14 + q14 = q14*/ - /*BASOP_Util_fPow(1.2799999714): max error 0.0020168927, mean 0.000066, abs mean 0.000072*/ - } + delta_fix = round_fx( L_shl( L_sub( x, 33554432l /*1.0/64.0 Q31*/ ), 5 ) ); /* q30 */ + result = round_fx( L_sub( L_add( PI_BY_4, L_msu( 0, delta_fix, -16384 ) ), ( L_mult0( delta_fix, delta_fix ) ) ) ); + /* BASOP_Util_fPow(0.7472000122): max error 0.0020237688, mean 0.000026, abs mean 0.000520 */ + } + ELSE + { + exp = sub( norm_l( x ), 1 ); + xx = round_fx( L_shl( x, exp ) ); + /* q25+exp * q25+exp - (16-1) = q19+2*exp*/ + tmp = mac_r( L_shl( P281, shl( exp, 1 ) ), xx, xx ); /* q19+2*exp + q19+2*exp = q19+2*exp*/ + res_e = norm_s( tmp ); + result = div_s( xx, shl( tmp, res_e ) ); + result = shl( result, add( add( Q_ATANOUT - Q_ATANINP /*-exp*/ + 19 /*+2*exp*/ - 16 + 1, res_e ), exp ) ); + result = sub( ONEP571, result ); /* q14 + q14 = q14*/ + /*BASOP_Util_fPow(1.2799999714): max error 0.0020168927, mean 0.000066, abs mean 0.000072*/ + } - if (sign) + if ( sign ) { - result = negate(result); + result = negate( result ); } - return(result); + return ( result ); } /* compare two positive normalized 16 bit mantissa/exponent values */ /* return value: positive if first value greater, negative if second value greater, zero if equal */ -Word16 compMantExp16Unorm(Word16 m1, Word16 e1, Word16 m2, Word16 e2) +Word16 compMantExp16Unorm( Word16 m1, Word16 e1, Word16 m2, Word16 e2 ) { - Word16 tmp; + Word16 tmp; - assert((m1 >= 0x4000) && (m2 >= 0x4000)); /* comparisons below work only for normalized mantissas */ + assert( ( m1 >= 0x4000 ) && ( m2 >= 0x4000 ) ); /* comparisons below work only for normalized mantissas */ - tmp = sub(e1, e2); - if (tmp == 0) tmp = sub(m1, m2); + tmp = sub( e1, e2 ); + if ( tmp == 0 ) + tmp = sub( m1, m2 ); - return tmp; + return tmp; } -cmplx CL_scale_t(cmplx x, Word16 y) +cmplx CL_scale_t( cmplx x, Word16 y ) { - cmplx result; - result.re = Mpy_32_16_1(x.re, y); - result.im = Mpy_32_16_1(x.im, y); -#if (WMOPS) - multiCounter[currCounter].Mpy_32_16_1--; - multiCounter[currCounter].Mpy_32_16_1--; - multiCounter[currCounter].CL_scale++; + cmplx result; + result.re = Mpy_32_16_1( x.re, y ); + result.im = Mpy_32_16_1( x.im, y ); +#if ( WMOPS ) + multiCounter[currCounter].Mpy_32_16_1--; + multiCounter[currCounter].Mpy_32_16_1--; + multiCounter[currCounter].CL_scale++; +#endif + return ( result ); +} + +cmplx CL_dscale_t( cmplx x, Word16 y1, Word16 y2 ) +{ + cmplx result; + result.re = Mpy_32_16_1( x.re, y1 ); + result.im = Mpy_32_16_1( x.im, y2 ); +#if ( WMOPS ) + multiCounter[currCounter].Mpy_32_16_1--; + multiCounter[currCounter].Mpy_32_16_1--; + multiCounter[currCounter].CL_dscale++; +#endif /* #if (WMOPS) */ + return ( result ); +} + +cmplx CL_mult_32x16( cmplx input, cmplx_s coeff ) +{ + cmplx result; + result.re = L_sub( Mpy_32_16_1( input.re, coeff.re ), Mpy_32_16_1( input.im, coeff.im ) ); + result.im = L_add( Mpy_32_16_1( input.re, coeff.im ), Mpy_32_16_1( input.im, coeff.re ) ); +#if ( WMOPS ) + multiCounter[currCounter].CL_multr_32x16++; + multiCounter[currCounter].Mpy_32_16_1--; + multiCounter[currCounter].Mpy_32_16_1--; + multiCounter[currCounter].Mpy_32_16_1--; + multiCounter[currCounter].Mpy_32_16_1--; + multiCounter[currCounter].L_sub--; + multiCounter[currCounter].L_add--; #endif - return (result); -} - -cmplx CL_dscale_t(cmplx x, Word16 y1, Word16 y2) -{ - cmplx result; - result.re = Mpy_32_16_1(x.re, y1); - result.im = Mpy_32_16_1(x.im, y2); -#if (WMOPS) - multiCounter[currCounter].Mpy_32_16_1--; - multiCounter[currCounter].Mpy_32_16_1--; - multiCounter[currCounter].CL_dscale++; -#endif/* #if (WMOPS) */ - return (result); -} - -cmplx CL_mult_32x16(cmplx input, cmplx_s coeff) -{ - cmplx result; - result.re = L_sub(Mpy_32_16_1(input.re, coeff.re), Mpy_32_16_1(input.im, coeff.im)); - result.im = L_add(Mpy_32_16_1(input.re, coeff.im), Mpy_32_16_1(input.im, coeff.re)); -#if (WMOPS) - multiCounter[currCounter].CL_multr_32x16++; - multiCounter[currCounter].Mpy_32_16_1--; - multiCounter[currCounter].Mpy_32_16_1--; - multiCounter[currCounter].Mpy_32_16_1--; - multiCounter[currCounter].Mpy_32_16_1--; - multiCounter[currCounter].L_sub--; - multiCounter[currCounter].L_add--; -#endif - return result; + return result; } diff --git a/lib_com/basop_util.h b/lib_com/basop_util.h index 988fb937c..380c8316b 100644 --- a/lib_com/basop_util.h +++ b/lib_com/basop_util.h @@ -52,8 +52,8 @@ #define modDiv2( x ) sub( x, shl( shr( x, 1 ), 1 ) ) #define modDiv8( x ) L_sub( x, L_shl( L_shr( x, 3 ), 3 ) ) -//basop_mpy.h -#define MUL_F(A,B) Mpy_32_16_1((A),(B)) +// basop_mpy.h +#define MUL_F( A, B ) Mpy_32_16_1( ( A ), ( B ) ) #ifndef CHEAP_NORM_SIZE #define CHEAP_NORM_SIZE 161 @@ -104,12 +104,12 @@ Word16 BASOP_Util_Add_MantExp /*!< Exponent of result */ For performance reasons, the division is based on a table lookup which limits accuracy. */ -void BASOP_Util_Divide_MantExp(Word16 a_m, /*!< Mantissa of dividend a */ - Word16 a_e, /*!< Exponent of dividend a */ - Word16 b_m, /*!< Mantissa of divisor b */ - Word16 b_e, /*!< Exponent of divisor b */ - Word16 *ptrResult_m, /*!< Mantissa of quotient a/b */ - Word16 *ptrResult_e /*!< Exponent of quotient a/b */ +void BASOP_Util_Divide_MantExp( Word16 a_m, /*!< Mantissa of dividend a */ + Word16 a_e, /*!< Exponent of dividend a */ + Word16 b_m, /*!< Mantissa of divisor b */ + Word16 b_e, /*!< Exponent of divisor b */ + Word16 *ptrResult_m, /*!< Mantissa of quotient a/b */ + Word16 *ptrResult_e /*!< Exponent of quotient a/b */ ); /************************************************************************/ @@ -126,25 +126,25 @@ Word16 Sqrt16( /*!< output mantissa */ Word16 *exponent /*!< pointer to exponent */ ); -Word16 Sqrt16norm( /*!< output mantissa */ - Word16 mantissa, /*!< normalized input mantissa */ - Word16 *exponent /*!< pointer to exponent */ +Word16 Sqrt16norm( /*!< output mantissa */ + Word16 mantissa, /*!< normalized input mantissa */ + Word16 *exponent /*!< pointer to exponent */ ); Word32 Sqrt32( /*!< output mantissa */ - Word32 mantissa, /*!< input mantissa */ - Word16 *exponent /*!< pointer to exponent */ + Word32 mantissa, /*!< input mantissa */ + Word16 *exponent /*!< pointer to exponent */ ); /* deprecated, use Sqrt16! */ -void BASOP_Util_Sqrt_MantExp(Word16 *mantissa, /*!< Pointer to mantissa */ - Word16 *exponent /*!< Pointer to exponent */ +void BASOP_Util_Sqrt_MantExp( Word16 *mantissa, /*!< Pointer to mantissa */ + Word16 *exponent /*!< Pointer to exponent */ ); /* deprecated, use Sqrt16norm! */ -void BASOP_Util_Sqrt_MantExpNorm(Word16 *mantissa, /*!< Pointer to normalized mantissa */ - Word16 *exponent /*!< Pointer to exponent */ +void BASOP_Util_Sqrt_MantExpNorm( Word16 *mantissa, /*!< Pointer to normalized mantissa */ + Word16 *exponent /*!< Pointer to exponent */ ); /****************************************************************************/ @@ -157,23 +157,23 @@ void BASOP_Util_Sqrt_MantExpNorm(Word16 *mantissa, /*!< Pointer to normalized The exponent is addressed via pointers and will be overwritten with the result. */ Word16 ISqrt16( /*!< output mantissa */ - Word16 mantissa, /*!< input mantissa */ - Word16 *exponent /*!< pointer to exponent */ + Word16 mantissa, /*!< input mantissa */ + Word16 *exponent /*!< pointer to exponent */ ); Word32 ISqrt32( /*!< output mantissa */ - Word32 mantissa, /*!< input mantissa */ - Word16 *exponent /*!< pointer to exponent */ + Word32 mantissa, /*!< input mantissa */ + Word16 *exponent /*!< pointer to exponent */ ); -Word32 ISqrt32norm( /*!< output mantissa */ - Word32 mantissa, /*!< normalized input mantissa */ - Word16 *exponent /*!< pointer to exponent */ +Word32 ISqrt32norm( /*!< output mantissa */ + Word32 mantissa, /*!< normalized input mantissa */ + Word16 *exponent /*!< pointer to exponent */ ); /* deprecated, use ISqrt16! */ -void BASOP_Util_InvSqrt_MantExp(Word16 *mantissa, /*!< Pointer to mantissa */ - Word16 *exponent /*!< Pointer to exponent */ +void BASOP_Util_InvSqrt_MantExp( Word16 *mantissa, /*!< Pointer to mantissa */ + Word16 *exponent /*!< Pointer to exponent */ ); /*****************************************************************************/ @@ -216,9 +216,9 @@ void BASOP_Util_Sqrt_InvSqrt_MantExp( Word16 mantissa, /*!< mantissa */ and -32768 <= x <= -16384 for negative x */ -Word16 getScaleFactor16( /* o: measured headroom in range [0..15], 0 if all x[i] == 0 */ - const Word16 *x, /* i: array containing 16-bit data */ - const Word16 len_x); /* i: length of the array to scan */ +Word16 getScaleFactor16( /* o: measured headroom in range [0..15], 0 if all x[i] == 0 */ + const Word16 *x, /* i: array containing 16-bit data */ + const Word16 len_x ); /* i: length of the array to scan */ /********************************************************************/ /*! @@ -242,7 +242,7 @@ Word16 getScaleFactor32( * \param pexponent pointer to the exponent. * \return the normalized mantissa. */ -Word16 normalize16(Word16 mantissa, Word16 *pexponent); +Word16 normalize16( Word16 mantissa, Word16 *pexponent ); /****************************************************************************/ /*! \brief Does fractional integer division of Word32 arg1 by Word16 arg2 @@ -252,8 +252,8 @@ Word16 normalize16(Word16 mantissa, Word16 *pexponent); \return fractional integer Word16 result of arg1/arg2 */ -Word16 divide3216(Word32 x, /*!< Numerator*/ - Word16 y); /*!< Denominator*/ +Word16 divide3216( Word32 x, /*!< Numerator*/ + Word16 y ); /*!< Denominator*/ /****************************************************************************/ @@ -265,8 +265,8 @@ Word16 divide3216(Word32 x, /*!< Numerator*/ \return fractional integer Word16 result of arg1/arg2 */ -Word16 divide1616(Word16 x, /*!< Numerator*/ - Word16 y); /*!< Denominator*/ +Word16 divide1616( Word16 x, /*!< Numerator*/ + Word16 y ); /*!< Denominator*/ /****************************************************************************/ @@ -281,8 +281,8 @@ Word16 divide1616(Word16 x, /*!< Numerator*/ \return fractional Word16 integer z = arg1(32bits)/arg2(32bits) */ -Word16 divide3232(Word32 x, /*!< Numerator*/ - Word32 y); /*!< Denominator*/ +Word16 divide3232( Word32 x, /*!< Numerator*/ + Word32 y ); /*!< Denominator*/ /****************************************************************************/ @@ -301,9 +301,9 @@ Word16 divide3232(Word32 x, /*!< Numerator*/ \return fractional Word16 integer z = arg1(32bits)/arg2(32bits) */ -Word16 BASOP_Util_Divide3232_uu_1616_Scale(Word32 x, /*!< i : Numerator*/ - Word32 y, /*!< i : Denominator*/ - Word16 *s); /*!< o : Additional scalefactor difference*/ +Word16 BASOP_Util_Divide3232_uu_1616_Scale( Word32 x, /*!< i : Numerator*/ + Word32 y, /*!< i : Denominator*/ + Word16 *s ); /*!< o : Additional scalefactor difference*/ /****************************************************************************/ @@ -321,13 +321,13 @@ Word16 BASOP_Util_Divide3232_uu_1616_Scale(Word32 x, /*!< i : Numerator*/ \return fractional Word16 integer z = arg1(32bits)/arg2(32bits) */ -Word16 BASOP_Util_Divide3232_Scale(Word32 x, /*!< i : Numerator*/ - Word32 y, /*!< i : Denominator*/ - Word16 *s); /*!< o : Additional scalefactor difference*/ +Word16 BASOP_Util_Divide3232_Scale( Word32 x, /*!< i : Numerator*/ + Word32 y, /*!< i : Denominator*/ + Word16 *s ); /*!< o : Additional scalefactor difference*/ -Word32 BASOP_Util_Divide3232_Scale_cadence(Word32 x, /*!< i : Numerator*/ - Word32 y, /*!< i : Denominator*/ - Word16 *s); /*!< o : Additional scalefactor difference*/ +Word32 BASOP_Util_Divide3232_Scale_cadence( Word32 x, /*!< i : Numerator*/ + Word32 y, /*!< i : Denominator*/ + Word16 *s ); /*!< o : Additional scalefactor difference*/ /************************************************************************/ @@ -417,7 +417,7 @@ Word32 BASOP_Util_log2_i5( Word32 val ); /************************************************************************/ Word32 BASOP_Util_InvLog2( Word32 x ); -Word16 BASOP_util_norm_s_bands2shift(Word16 x); +Word16 BASOP_util_norm_s_bands2shift( Word16 x ); /***********************************************************************/ @@ -426,28 +426,28 @@ Word16 BASOP_util_norm_s_bands2shift(Word16 x); \return number of headroom bits */ -Word16 BASOP_util_norm_l_dim2_cplx(const Word32 * const *re, /*!< Real part of 32 Bit input */ - const Word32 * const *im, /*!< Imag part if 32 Bit input */ - Word16 startBand, /*!< start band of cplx data */ - Word16 stopBand, /*!< stop band of cplx data */ - Word16 startSlot, /*!< start slot of cplx data */ - Word16 stopSlot /*!< stop slot of cplx data */ +Word16 BASOP_util_norm_l_dim2_cplx( const Word32 *const *re, /*!< Real part of 32 Bit input */ + const Word32 *const *im, /*!< Imag part if 32 Bit input */ + Word16 startBand, /*!< start band of cplx data */ + Word16 stopBand, /*!< stop band of cplx data */ + Word16 startSlot, /*!< start slot of cplx data */ + Word16 stopSlot /*!< stop slot of cplx data */ ); /****************************************************************************/ /*! \brief Does a data copy of Word8 *arg1 to Word8 *arg2 with Word16 arg3 number of moves */ -void copyWord8(const Word8 *src, /*!< i : Source address */ - Word8 *dst, /*!< i : Destination address */ - const Word32 n); /*!< i : Number of elements to copy */ +void copyWord8( const Word8 *src, /*!< i : Source address */ + Word8 *dst, /*!< i : Destination address */ + const Word32 n ); /*!< i : Number of elements to copy */ /****************************************************************************/ /*! \brief Sets Word8 array arg1[] to zero for a length of Word16 arg2 elements */ -void set_zero_Word8(Word8 X[], /*!< i : Address of array */ - Word32 n); /*!< i : Number of elements to set to zero */ +void set_zero_Word8( Word8 X[], /*!< i : Address of array */ + Word32 n ); /*!< i : Number of elements to set to zero */ /****************************************************************************/ /*! @@ -455,13 +455,13 @@ void set_zero_Word8(Word8 X[], /*!< i : Address of array \return z32 = x32 * y16 */ -Word32 L_mult0_3216(Word32 x, /*!< : Multiplier */ - Word16 y); /*!< : Multiplicand */ +Word32 L_mult0_3216( Word32 x, /*!< : Multiplier */ + Word16 y ); /*!< : Multiplicand */ /* Calculate sin/cos. Angle in 2Q13 format, result has exponent = 1 */ -Word16 getCosWord16(Word16 theta); -Word16 getSinWord16(Word16 theta); -Word32 getCosWord32(Word32 theta); +Word16 getCosWord16( Word16 theta ); +Word16 getSinWord16( Word16 theta ); +Word32 getCosWord32( Word32 theta ); /** * \brief calculate cosine of angle. Tuned for ISF domain. * \param theta Angle normalized to radix 2, theta = (angle in radians)*2.0/pi @@ -509,7 +509,7 @@ Word16 getCosWord16R2( Word16 theta ); \return integer sqrt(x) */ -Word16 getSqrtWord32(Word32 x); +Word16 getSqrtWord32( Word32 x ); /****************************************************************************/ /*! @@ -517,7 +517,7 @@ Word16 getSqrtWord32(Word32 x); \return index of min Word16 */ -Word16 findIndexOfMinWord16(Word16 *x, const Word16 len); +Word16 findIndexOfMinWord16( Word16 *x, const Word16 len ); /****************************************************************************/ /*! @@ -525,7 +525,7 @@ Word16 findIndexOfMinWord16(Word16 *x, const Word16 len); \return index of min Word32 */ -Word16 findIndexOfMinWord32(Word32 *x, const Word16 len); +Word16 findIndexOfMinWord32( Word32 *x, const Word16 len ); /****************************************************************************/ /*! @@ -533,7 +533,7 @@ Word16 findIndexOfMinWord32(Word32 *x, const Word16 len); \return index of max Word16 */ -Word16 findIndexOfMaxWord16(Word16 *x, const Word16 len); +Word16 findIndexOfMaxWord16( Word16 *x, const Word16 len ); /****************************************************************************/ /*! @@ -541,7 +541,7 @@ Word16 findIndexOfMaxWord16(Word16 *x, const Word16 len); \return index of max Word32 */ -Word16 findIndexOfMaxWord32(Word32 *x, const Word16 len); +Word16 findIndexOfMaxWord32( Word32 *x, const Word16 len ); /****************************************************************************/ /*! @@ -549,7 +549,7 @@ Word16 findIndexOfMaxWord32(Word32 *x, const Word16 len); \return 16x16->16 integer */ -Word16 imult1616(Word16 x, Word16 y); +Word16 imult1616( Word16 x, Word16 y ); /****************************************************************************/ /*! @@ -557,7 +557,7 @@ Word16 imult1616(Word16 x, Word16 y); \return 32x16->32 integer */ -Word32 imult3216(Word32 x, Word16 y); +Word32 imult3216( Word32 x, Word16 y ); /****************************************************************************/ /*! @@ -569,7 +569,7 @@ Word32 imult3216(Word32 x, Word16 y); */ Word16 idiv1616U_IVAS( Word16 x, Word16 y ); -Word16 idiv1616U(Word16 x, Word16 y); +Word16 idiv1616U( Word16 x, Word16 y ); /****************************************************************************/ /*! @@ -580,7 +580,7 @@ Word16 idiv1616U(Word16 x, Word16 y); \return 16/16->16 integer */ -Word16 idiv1616(Word16 x, Word16 y); +Word16 idiv1616( Word16 x, Word16 y ); /*------------------------------------------------------------------* * Dot_product16HQ: @@ -591,12 +591,12 @@ Word16 idiv1616(Word16 x, Word16 y); * Note: In contrast to dotWord32, no headroom is required for data * in x[] and y[], means, they may have any format Qn *------------------------------------------------------------------*/ -Word32 Dot_product16HQ( /* ************************************************************************/ -Word16 BASOP_Util_Cmp_Mant32Exp /*!< o: flag: result of comparison */ -(Word32 a_m, /*!< i: Mantissa of 1st operand a */ - Word16 a_e, /*!< i: Exponent of 1st operand a */ - Word32 b_m, /*!< i: Mantissa of 2nd operand b */ - Word16 b_e); /*!< i: Exponent of 2nd operand b */ +Word16 BASOP_Util_Cmp_Mant32Exp /*!< o: flag: result of comparison */ + ( Word32 a_m, /*!< i: Mantissa of 1st operand a */ + Word16 a_e, /*!< i: Exponent of 1st operand a */ + Word32 b_m, /*!< i: Mantissa of 2nd operand b */ + Word16 b_e ); /*!< i: Exponent of 2nd operand b */ /******************************************************************** * bufferCopyFx * * \brief copies buffer while preserving Format of destination buffer -********************************************************************* -*/ + ********************************************************************* + */ void bufferCopyFx( - Word16* src, /* ************************************************************************/ -Word16 BASOP_Util_lin2dB( /*!< o: dB value (7Q8) */ - Word32 x, /*!< i: mantissa */ - Word16 x_e, /*!< i: exponent */ - Word16 fEnergy); /*!< i: flag indicating if x is energy */ +Word16 BASOP_Util_lin2dB( /*!< o: dB value (7Q8) */ + Word32 x, /*!< i: mantissa */ + Word16 x_e, /*!< i: exponent */ + Word16 fEnergy ); /*!< i: flag indicating if x is energy */ /*!********************************************************************** \brief Calculates atan(x). ************************************************************************/ -Word16 BASOP_util_atan( /*!< o: atan(x) [-pi/2;pi/2] 1Q14 */ - Word32 x /*!< i: input data (-64;64) 6Q25 */ +Word16 BASOP_util_atan( /*!< o: atan(x) [-pi/2;pi/2] 1Q14 */ + Word32 x /*!< i: input data (-64;64) 6Q25 */ ); /*!********************************************************************** \brief Calculates atan2(y,x). ************************************************************************/ -Word16 BASOP_util_atan2( /*!< o: atan2(y,x) [-pi,pi] Q13 */ - Word32 y, /*!< i: */ - Word32 x, /*!< i: */ - Word16 e /*!< i: exponent difference (exp_y - exp_x) */ +Word16 BASOP_util_atan2( /*!< o: atan2(y,x) [-pi,pi] Q13 */ + Word32 y, /*!< i: */ + Word32 x, /*!< i: */ + Word16 e /*!< i: exponent difference (exp_y - exp_x) */ ); /****************************************************************************/ @@ -859,11 +859,11 @@ Word16 BASOP_util_atan2( /*!< o: atan2(y,x) [-pi,pi] Q13 */ Word32 dotWord32_16_guards( const Word32 *X, const Word16 *Y, Word16 n, Word16 hr, Word16 *shift ); -//function defined in basop_util commented from basop_tcx_utils.c -Word16 compMantExp16Unorm(Word16 m1, Word16 e1, Word16 m2, Word16 e2); +// function defined in basop_util commented from basop_tcx_utils.c +Word16 compMantExp16Unorm( Word16 m1, Word16 e1, Word16 m2, Word16 e2 ); -cmplx CL_scale_t(cmplx x, Word16 y); -cmplx CL_dscale_t(cmplx x, Word16 y1, Word16 y2); -cmplx CL_mult_32x16(cmplx input, cmplx_s coeff); +cmplx CL_scale_t( cmplx x, Word16 y ); +cmplx CL_dscale_t( cmplx x, Word16 y1, Word16 y2 ); +cmplx CL_mult_32x16( cmplx input, cmplx_s coeff ); #endif /* __BASOP_UTIL_H__ */ diff --git a/lib_com/bitalloc_fx.c b/lib_com/bitalloc_fx.c index 8cb434f72..8ae8a674f 100644 --- a/lib_com/bitalloc_fx.c +++ b/lib_com/bitalloc_fx.c @@ -3,21 +3,21 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ - -void bitalloc_fx ( - Word16 *y, /* i : reordered norm of sub-vectors Q0 */ - Word16 *idx, /* i : reordered sub-vector indices Q0 */ - Word16 sum, /* i : number of available bits Q0 */ - Word16 N, /* i : number of norms Q0 */ - Word16 K, /* i : maximum number of bits per dimension Q0 */ - Word16 *r, /* o : bit-allacation vector Q0 */ - const Word16 *sfmsize, /* i : band length Q0 */ - const Word16 hqswb_clas /* i : signal classification flag Q0 */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ + +void bitalloc_fx( + Word16 *y, /* i : reordered norm of sub-vectors Q0 */ + Word16 *idx, /* i : reordered sub-vector indices Q0 */ + Word16 sum, /* i : number of available bits Q0 */ + Word16 N, /* i : number of norms Q0 */ + Word16 K, /* i : maximum number of bits per dimension Q0 */ + Word16 *r, /* o : bit-allacation vector Q0 */ + const Word16 *sfmsize, /* i : band length Q0 */ + const Word16 hqswb_clas /* i : signal classification flag Q0 */ ) { Word16 i, j, k, n, m, v, im; @@ -30,9 +30,9 @@ void bitalloc_fx ( Word16 SFM_thr = SFM_G1G2; move16(); - N = sub(N, 1); + N = sub( N, 1 ); - if ( EQ_16(hqswb_clas, HQ_HARMONIC)) + if ( EQ_16( hqswb_clas, HQ_HARMONIC ) ) { SFM_thr = 22; move16(); @@ -40,26 +40,26 @@ void bitalloc_fx ( fac = 3; move16(); - K = sub(K,2); + K = sub( K, 2 ); im = 1; move16(); diff = sum; move16(); - n = shr(sum,3); - FOR ( i=0; iHQ switching. */ + IF( ( LT_16( sum, sfmsize[SFM_G1 - 1] ) ) || ( EQ_16( diff, sum ) ) ) /* sfmsize[SFM_G1-1] matches WID_G1, but also allows for extended BWs used in ACELP->HQ switching. */ { BREAK; } diff = sum; move16(); - v = sub(N, 1); + v = sub( N, 1 ); - IF ( GT_16(k, v)) + IF( GT_16( k, v ) ) { - FOR ( ii=0; ii<=N; ii++ ) + FOR( ii = 0; ii <= N; ii++ ) { - IF ( GT_16(y[ii], -32768)) + IF( GT_16( y[ii], -32768 ) ) { - if ( LT_16(ii, N)) + if ( LT_16( ii, N ) ) { - im = add(ii, 1); + im = add( ii, 1 ); } BREAK; } @@ -134,20 +134,20 @@ void bitalloc_fx ( } - IF ( GE_16(sum, sfmsize[SFM_G1])) /* sfmsize[SFM_G1] matches WID_G2, but also allows for extended BWs used in ACELP->HQ switching. */ + IF( GE_16( sum, sfmsize[SFM_G1] ) ) /* sfmsize[SFM_G1] matches WID_G2, but also allows for extended BWs used in ACELP->HQ switching. */ { - FOR (i=0; i<=N; i++) + FOR( i = 0; i <= N; i++ ) { j = idx[i]; move16(); test(); test(); - IF ( GE_16(j, SFM_G1)&<_16(j,SFM_thr)&&r[j]==0) + IF( GE_16( j, SFM_G1 ) && LT_16( j, SFM_thr ) && r[j] == 0 ) { r[j] = 1; move16(); - sum = sub(sum, sfmsize[j]); - IF (LT_16(sum, sfmsize[SFM_G1])) + sum = sub( sum, sfmsize[j] ); + IF( LT_16( sum, sfmsize[SFM_G1] ) ) { BREAK; } @@ -155,20 +155,20 @@ void bitalloc_fx ( } } - IF ( GE_16(sum, sfmsize[SFM_G1])) + IF( GE_16( sum, sfmsize[SFM_G1] ) ) { - FOR (i=0; i<=N; i++) + FOR( i = 0; i <= N; i++ ) { j = idx[i]; move16(); test(); test(); - IF ( GE_16(j,SFM_G1)&<_16(j,SFM_thr)&&EQ_16(r[j],1)) + IF( GE_16( j, SFM_G1 ) && LT_16( j, SFM_thr ) && EQ_16( r[j], 1 ) ) { r[j] = 2; move16(); - sum = sub(sum, sfmsize[j]); - IF ( LT_16(sum, sfmsize[SFM_G1])) + sum = sub( sum, sfmsize[j] ); + IF( LT_16( sum, sfmsize[SFM_G1] ) ) { BREAK; } @@ -176,19 +176,19 @@ void bitalloc_fx ( } } - IF ( GE_16(sum, sfmsize[SFM_G1-1])) + IF( GE_16( sum, sfmsize[SFM_G1 - 1] ) ) { - FOR (i=0; i<=N; i++) + FOR( i = 0; i <= N; i++ ) { j = idx[i]; move16(); test(); - IF ( LT_16(j, SFM_G1)&&r[j]==0) + IF( LT_16( j, SFM_G1 ) && r[j] == 0 ) { r[j] = 1; move16(); - sum = sub(sum, sfmsize[j]); - IF ( LT_16(sum, sfmsize[SFM_G1-1])) + sum = sub( sum, sfmsize[j] ); + IF( LT_16( sum, sfmsize[SFM_G1 - 1] ) ) { BREAK; } @@ -196,19 +196,19 @@ void bitalloc_fx ( } } - IF ( GE_16(sum, sfmsize[SFM_G1-1])) + IF( GE_16( sum, sfmsize[SFM_G1 - 1] ) ) { - FOR (i=0; i<=N; i++) + FOR( i = 0; i <= N; i++ ) { j = idx[i]; move16(); test(); - IF ( LT_16(j, SFM_G1)&&EQ_16(r[j],1)) + IF( LT_16( j, SFM_G1 ) && EQ_16( r[j], 1 ) ) { r[j] = 2; move16(); - sum = sub(sum, sfmsize[j]); - IF ( LT_16(sum, sfmsize[SFM_G1-1])) + sum = sub( sum, sfmsize[j] ); + IF( LT_16( sum, sfmsize[SFM_G1 - 1] ) ) { BREAK; } @@ -225,15 +225,16 @@ void bitalloc_fx ( * Fractional bit allocation *-------------------------------------------------------------------*/ -Word16 BitAllocF_fx ( - Word16 *y, /* i : norm of sub-vectors :Q0 */ - Word32 bit_rate, /* i : bitrate :Q0 */ - Word16 B, /* i : number of available bits :Q0 */ - Word16 N, /* i : number of sub-vectors :Q0 */ - Word16 *R, /* o : bit-allocation indicator :Q0 */ - Word16 *Rsubband_fx /* o : sub-band bit-allocation vector :Q3 */ - ,const Word16 hqswb_clas, /* i : hq swb class :Q0 */ - const Word16 num_env_bands/* i : Number sub bands to be encoded for HF GNERIC :Q0 */ +Word16 BitAllocF_fx( + Word16 *y, /* i : norm of sub-vectors :Q0 */ + Word32 bit_rate, /* i : bitrate :Q0 */ + Word16 B, /* i : number of available bits :Q0 */ + Word16 N, /* i : number of sub-vectors :Q0 */ + Word16 *R, /* o : bit-allocation indicator :Q0 */ + Word16 *Rsubband_fx /* o : sub-band bit-allocation vector :Q3 */ + , + const Word16 hqswb_clas, /* i : hq swb class :Q0 */ + const Word16 num_env_bands /* i : Number sub bands to be encoded for HF GNERIC :Q0 */ ) { Word16 fac; @@ -243,18 +244,18 @@ Word16 BitAllocF_fx ( Word32 t_fx, B_fx; Word32 L_tmp1, L_tmp2, L_tmp3; Word16 tmp, exp1, exp2; - Word32 Rsubband_w32_fx[NB_SFM]; /* Q15 */ + Word32 Rsubband_w32_fx[NB_SFM]; /* Q15 */ Word16 B_w16_fx; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - set32_fx( Rsubband_w32_fx, 0, NB_SFM); + set32_fx( Rsubband_w32_fx, 0, NB_SFM ); fac = 3; move16(); - IF (LT_32(bit_rate, 32000)) + IF( LT_32( bit_rate, 32000 ) ) { bs = 2; move16(); @@ -269,7 +270,7 @@ Word16 BitAllocF_fx ( Nmin = N; move16(); - if ( GT_16(Nmin,SFM_N)) + if ( GT_16( Nmin, SFM_N ) ) { Nmin = SFM_N; move16(); @@ -277,46 +278,46 @@ Word16 BitAllocF_fx ( /* Initial bits distribution */ test(); - IF (EQ_16(hqswb_clas , HQ_GEN_SWB)||EQ_16(hqswb_clas,HQ_GEN_FB)) + IF( EQ_16( hqswb_clas, HQ_GEN_SWB ) || EQ_16( hqswb_clas, HQ_GEN_FB ) ) { /* Initial bits distribution */ L_tmp1 = 0; move16(); m_fx = 0; move16(); - FOR ( i = 0; i < num_env_bands ; i++) + FOR( i = 0; i < num_env_bands; i++ ) { - L_tmp1 = L_mac0(L_tmp1, Nb[i], y[i]); + L_tmp1 = L_mac0( L_tmp1, Nb[i], y[i] ); } - L_tmp1 = L_msu0(L_tmp1, fac, B); + L_tmp1 = L_msu0( L_tmp1, fac, B ); - t_fx = L_deposit_l(0); + t_fx = L_deposit_l( 0 ); n = 0; move16(); - tmp = add(band_end_HQ[num_env_bands-1], shl(band_end_HQ[num_env_bands-1], 1)); - exp1 = norm_s(tmp); - tmp = div_s(16384, shl(tmp, exp1));/*15 + 14 - exp1*/ - exp2 = norm_s(tmp); - tmp = shl(tmp, exp2); - exp1 = add(29, sub(exp2, exp1)); - - FOR ( i = 0; i < N; i++) + tmp = add( band_end_HQ[num_env_bands - 1], shl( band_end_HQ[num_env_bands - 1], 1 ) ); + exp1 = norm_s( tmp ); + tmp = div_s( 16384, shl( tmp, exp1 ) ); /*15 + 14 - exp1*/ + exp2 = norm_s( tmp ); + tmp = shl( tmp, exp2 ); + exp1 = add( 29, sub( exp2, exp1 ) ); + + FOR( i = 0; i < N; i++ ) { - L_tmp2 = L_sub(L_mult0(y[i], band_end_HQ[num_env_bands-1]), L_tmp1); - Rsubband_w32_fx[i] = L_mult0(extract_l(L_tmp2), Nb[i]); - move32();/*Q0*/ - IF (Rsubband_w32_fx[i] > 0) + L_tmp2 = L_sub( L_mult0( y[i], band_end_HQ[num_env_bands - 1] ), L_tmp1 ); + Rsubband_w32_fx[i] = L_mult0( extract_l( L_tmp2 ), Nb[i] ); + move32(); /*Q0*/ + IF( Rsubband_w32_fx[i] > 0 ) { - n = add(n,Nb[i]); - Rsubband_w32_fx[i] = Mult_32_16(Rsubband_w32_fx[i], tmp); - move32();/*exp1 - 15*/ - Rsubband_w32_fx[i] = L_shl(Rsubband_w32_fx[i], sub(30, exp1));/*Q15*/ + n = add( n, Nb[i] ); + Rsubband_w32_fx[i] = Mult_32_16( Rsubband_w32_fx[i], tmp ); + move32(); /*exp1 - 15*/ + Rsubband_w32_fx[i] = L_shl( Rsubband_w32_fx[i], sub( 30, exp1 ) ); /*Q15*/ - t_fx = L_add(t_fx, Rsubband_w32_fx[i]);/*Q0*/ + t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); /*Q0*/ } ELSE { - Rsubband_w32_fx[i] = L_deposit_l(0); + Rsubband_w32_fx[i] = L_deposit_l( 0 ); } } } @@ -327,74 +328,75 @@ Word16 BitAllocF_fx ( move16(); m_fx = 0; move16(); - FOR ( i = 0; i < N ; i++) + FOR( i = 0; i < N; i++ ) { - L_tmp1 = L_mac0(L_tmp1, Nb[i], y[i]); + L_tmp1 = L_mac0( L_tmp1, Nb[i], y[i] ); } - L_tmp1 = L_msu0(L_tmp1, fac, B); + L_tmp1 = L_msu0( L_tmp1, fac, B ); - t_fx = L_deposit_l(0); + t_fx = L_deposit_l( 0 ); n = 0; move16(); - tmp = add(band_end_HQ[N-1], shl(band_end_HQ[N-1], 1)); - exp1 = norm_s(tmp); - tmp = div_s(16384, shl(tmp, exp1));/*15 + 14 - exp1*/ - exp2 = norm_s(tmp); - tmp = shl(tmp, exp2); - exp1 = add(29, sub(exp2, exp1)); - FOR ( i = 0; i < N; i++) + tmp = add( band_end_HQ[N - 1], shl( band_end_HQ[N - 1], 1 ) ); + exp1 = norm_s( tmp ); + tmp = div_s( 16384, shl( tmp, exp1 ) ); /*15 + 14 - exp1*/ + exp2 = norm_s( tmp ); + tmp = shl( tmp, exp2 ); + exp1 = add( 29, sub( exp2, exp1 ) ); + FOR( i = 0; i < N; i++ ) { - L_tmp2 = L_sub(L_mult0(y[i], band_end_HQ[N-1]), L_tmp1); - Rsubband_w32_fx[i] = L_mult0(extract_l(L_tmp2), Nb[i]); - move32();/*Q0*/ - IF (Rsubband_w32_fx[i] > 0) + L_tmp2 = L_sub( L_mult0( y[i], band_end_HQ[N - 1] ), L_tmp1 ); + Rsubband_w32_fx[i] = L_mult0( extract_l( L_tmp2 ), Nb[i] ); + move32(); /*Q0*/ + IF( Rsubband_w32_fx[i] > 0 ) { - n = add(n,Nb[i]); - L_tmp3 = Mult_32_16(Rsubband_w32_fx[i], tmp); /*exp1 - 15*/ - Rsubband_w32_fx[i] = L_shl(L_tmp3, sub(30, exp1)); /*Q15*/ move32(); + n = add( n, Nb[i] ); + L_tmp3 = Mult_32_16( Rsubband_w32_fx[i], tmp ); /*exp1 - 15*/ + Rsubband_w32_fx[i] = L_shl( L_tmp3, sub( 30, exp1 ) ); /*Q15*/ + move32(); - t_fx = L_add(t_fx, Rsubband_w32_fx[i]);/*Q0*/ + t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); /*Q0*/ } ELSE { - Rsubband_w32_fx[i] = L_deposit_l(0); + Rsubband_w32_fx[i] = L_deposit_l( 0 ); } } } /* Distribute the remaining bits to subbands with non-zero bits */ - B_fx = L_shl(B, 15); - WHILE (NE_32(L_shr(L_add(t_fx, 16384), 15) , B)) + B_fx = L_shl( B, 15 ); + WHILE( NE_32( L_shr( L_add( t_fx, 16384 ), 15 ), B ) ) { - L_tmp1 = L_sub(t_fx, B_fx); - exp1 = sub(norm_l(L_tmp1), 1); - exp2 = norm_s(n); - tmp = div_s(extract_h(L_shl(L_tmp1, exp1)), shl(n, exp2));/*15 + 15 + exp1 - 16 - exp2*/ + L_tmp1 = L_sub( t_fx, B_fx ); + exp1 = sub( norm_l( L_tmp1 ), 1 ); + exp2 = norm_s( n ); + tmp = div_s( extract_h( L_shl( L_tmp1, exp1 ) ), shl( n, exp2 ) ); /*15 + 15 + exp1 - 16 - exp2*/ #ifdef BASOP_NOGLOB m_fx = shl_sat( tmp, sub( exp2, exp1 ) ); /*Q14*/ #else - m_fx = shl( tmp, sub( exp2, exp1 ) ); /*Q14*/ + m_fx = shl( tmp, sub( exp2, exp1 ) ); /*Q14*/ #endif - t_fx = L_deposit_l(0); + t_fx = L_deposit_l( 0 ); n = 0; move16(); - FOR ( i = 0; i < N; i++) + FOR( i = 0; i < N; i++ ) { - IF (Rsubband_w32_fx[i] > 0) + IF( Rsubband_w32_fx[i] > 0 ) { - Rsubband_w32_fx[i] = L_msu(Rsubband_w32_fx[i], m_fx, Nb[i]); + Rsubband_w32_fx[i] = L_msu( Rsubband_w32_fx[i], m_fx, Nb[i] ); move32(); - IF (Rsubband_w32_fx[i] > 0) + IF( Rsubband_w32_fx[i] > 0 ) { - n = add(n,Nb[i]); + n = add( n, Nb[i] ); - t_fx = L_add(t_fx, Rsubband_w32_fx[i]); + t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); } ELSE { - Rsubband_w32_fx[i] = L_deposit_l(0); + Rsubband_w32_fx[i] = L_deposit_l( 0 ); } } } @@ -403,88 +405,88 @@ Word16 BitAllocF_fx ( move16(); /* Impose bit-constraints to subbands with less than minimum bits*/ - t_fx = L_deposit_l(0); + t_fx = L_deposit_l( 0 ); n = 0; move16(); - FOR ( i = 0; i < N; i++) + FOR( i = 0; i < N; i++ ) { - IF (Rsubband_w32_fx[i] > 0) + IF( Rsubband_w32_fx[i] > 0 ) { test(); - IF ((LT_32(Rsubband_w32_fx[i] , L_shl(add(bs, LNb[i]), 15)))&&(EQ_16(low_rate,1))) + IF( ( LT_32( Rsubband_w32_fx[i], L_shl( add( bs, LNb[i] ), 15 ) ) ) && ( EQ_16( low_rate, 1 ) ) ) { - Rsubband_w32_fx[i] = L_deposit_l(0); + Rsubband_w32_fx[i] = L_deposit_l( 0 ); } - ELSE IF ( LE_32(Rsubband_w32_fx[i] , L_shl(Nb[i], 15))) + ELSE IF( LE_32( Rsubband_w32_fx[i], L_shl( Nb[i], 15 ) ) ) { - B = sub(B,Nb[i]); - Rsubband_w32_fx[i] = L_shl(Nb[i], 15); + B = sub( B, Nb[i] ); + Rsubband_w32_fx[i] = L_shl( Nb[i], 15 ); move32(); } ELSE { - n = add(n,Nb[i]); - t_fx = L_add(t_fx, Rsubband_w32_fx[i]); + n = add( n, Nb[i] ); + t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); } } } /* Distribute the remaining bits to subbands with more than 1-bit per sample */ - WHILE (NE_32(L_shr(L_add(t_fx, 16384), 15) ,B)) + WHILE( NE_32( L_shr( L_add( t_fx, 16384 ), 15 ), B ) ) { - L_tmp1 = L_sub(t_fx, L_shl(B, 15)); - L_tmp2 = L_abs(L_tmp1); + L_tmp1 = L_sub( t_fx, L_shl( B, 15 ) ); + L_tmp2 = L_abs( L_tmp1 ); - if (n>0) + if ( n > 0 ) { - exp1 = sub(norm_l(L_tmp2), 1); - exp2 = norm_s(n); - tmp = div_s(extract_h(L_shl(L_tmp2, exp1)), shl(n, exp2));/*15 + 15 + exp1 - 16 - exp2*/ + exp1 = sub( norm_l( L_tmp2 ), 1 ); + exp2 = norm_s( n ); + tmp = div_s( extract_h( L_shl( L_tmp2, exp1 ) ), shl( n, exp2 ) ); /*15 + 15 + exp1 - 16 - exp2*/ #ifdef BASOP_NOGLOB - m_fx = shl_o(tmp, sub(exp2, exp1), &Overflow);/*Q14*/ + m_fx = shl_o( tmp, sub( exp2, exp1 ), &Overflow ); /*Q14*/ #else - m_fx = shl(tmp, sub(exp2, exp1));/*Q14*/ + m_fx = shl( tmp, sub( exp2, exp1 ) ); /*Q14*/ #endif - if (L_tmp1 < 0) + if ( L_tmp1 < 0 ) { - m_fx = negate(m_fx); + m_fx = negate( m_fx ); } - t_fx = L_deposit_l(0); + t_fx = L_deposit_l( 0 ); n = 0; move16(); - FOR( i = 0; i < N; i++) + FOR( i = 0; i < N; i++ ) { - IF (GT_32(Rsubband_w32_fx[i] , L_shl(Nb[i], 15))) + IF( GT_32( Rsubband_w32_fx[i], L_shl( Nb[i], 15 ) ) ) { - Rsubband_w32_fx[i] = L_msu(Rsubband_w32_fx[i], m_fx, Nb[i]); + Rsubband_w32_fx[i] = L_msu( Rsubband_w32_fx[i], m_fx, Nb[i] ); move32(); - IF (GT_32(Rsubband_w32_fx[i] ,L_shl(Nb[i], 15))) + IF( GT_32( Rsubband_w32_fx[i], L_shl( Nb[i], 15 ) ) ) { - n = add(n,Nb[i]); + n = add( n, Nb[i] ); - t_fx = L_add(t_fx, Rsubband_w32_fx[i]); + t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); } ELSE { - B = sub(B,Nb[i]); + B = sub( B, Nb[i] ); - Rsubband_w32_fx[i] = L_shl(Nb[i], 15); + Rsubband_w32_fx[i] = L_shl( Nb[i], 15 ); move32(); } } } } /*In case no subband has enough bits more than 1-bit per sample, take bits off the higher subbands */ - IF (t_fx == 0) + IF( t_fx == 0 ) { - FOR ( i = N-1; i >= 0; i--) + FOR( i = N - 1; i >= 0; i-- ) { - IF (Rsubband_w32_fx[i] > 0) + IF( Rsubband_w32_fx[i] > 0 ) { B = add( B, Nb[i] ); - Rsubband_w32_fx[i] = L_deposit_l(0); - IF ( B >= 0) + Rsubband_w32_fx[i] = L_deposit_l( 0 ); + IF( B >= 0 ) { BREAK; } @@ -497,22 +499,22 @@ Word16 BitAllocF_fx ( /* fine redistribution of over-allocated or under-allocated bits */ tmp = 0; move16(); - FOR ( i = 0; i < N; i++) + FOR( i = 0; i < N; i++ ) { - Rsubband_fx[i] = extract_l(L_shr(Rsubband_w32_fx[i], 12)); - tmp = add(tmp, Rsubband_fx[i]); + Rsubband_fx[i] = extract_l( L_shr( Rsubband_w32_fx[i], 12 ) ); + tmp = add( tmp, Rsubband_fx[i] ); } B = Bits; - B_w16_fx = shl(B, 3); - IF (GT_16(tmp ,B_w16_fx)) + B_w16_fx = shl( B, 3 ); + IF( GT_16( tmp, B_w16_fx ) ) { - tmp = sub(tmp, B_w16_fx); - FOR ( i = 0; i < N; i++) + tmp = sub( tmp, B_w16_fx ); + FOR( i = 0; i < N; i++ ) { - IF (GE_16(Rsubband_fx[i], add(shl(Nb[i], 3), tmp))) + IF( GE_16( Rsubband_fx[i], add( shl( Nb[i], 3 ), tmp ) ) ) { - Rsubband_fx[i] = sub(Rsubband_fx[i], tmp); + Rsubband_fx[i] = sub( Rsubband_fx[i], tmp ); move16(); BREAK; } @@ -520,12 +522,12 @@ Word16 BitAllocF_fx ( } ELSE { - tmp = sub(tmp, B_w16_fx); - FOR ( i = 0; i < N; i++) + tmp = sub( tmp, B_w16_fx ); + FOR( i = 0; i < N; i++ ) { - IF (Rsubband_fx[i] > 0) + IF( Rsubband_fx[i] > 0 ) { - Rsubband_fx[i] = sub(Rsubband_fx[i], tmp); + Rsubband_fx[i] = sub( Rsubband_fx[i], tmp ); move16(); BREAK; } @@ -535,99 +537,98 @@ Word16 BitAllocF_fx ( /* Calcuate total used bits and initialize R to be used for Noise Filling */ tmp = 0; move16(); - FOR ( i = 0; i < N; i++) + FOR( i = 0; i < N; i++ ) { - tmp = add(tmp, Rsubband_fx[i]); - R[i] = shr(Rsubband_fx[i], 3); + tmp = add( tmp, Rsubband_fx[i] ); + R[i] = shr( Rsubband_fx[i], 3 ); move16(); } - return shr(tmp, 3); + return shr( tmp, 3 ); } /*-------------------------------------------------------------------* * Bit_group() * * bit allocation in group *-------------------------------------------------------------------*/ -static -void Bit_group_fx ( - Word16 *y, /* i : norm of sub-band Q0*/ - Word16 start_band, /* i : start band indices Q0*/ - Word16 end_band, /* i : end band indices Q0*/ - Word16 Bits, /* i : number of allocation bits in group Q0*/ - Word16 thr, /* i : smallest bit number for allocation in group Q0*/ - Word32 *Rsubband_fx, /* o : bit allocation of sub-band Q21*/ - Word16 *fac_fx /* i : weight factor for norm of sub-band Q13*/ +static void Bit_group_fx( + Word16 *y, /* i : norm of sub-band Q0*/ + Word16 start_band, /* i : start band indices Q0*/ + Word16 end_band, /* i : end band indices Q0*/ + Word16 Bits, /* i : number of allocation bits in group Q0*/ + Word16 thr, /* i : smallest bit number for allocation in group Q0*/ + Word32 *Rsubband_fx, /* o : bit allocation of sub-band Q21*/ + Word16 *fac_fx /* i : weight factor for norm of sub-band Q13*/ ) { Word16 i, j, k, m, y_index[16], index[16], bit_band, band_num, norm_sum; - Word16 tmp,exp; + Word16 tmp, exp; Word16 factor_fx; Word32 R_temp_fx[16], R_sum_fx = 0, R_sum_org_fx = 0, Bits_avg_fx = 0; Word32 L_tmp; /* initialization for bit allocation in one group*/ tmp = 6554; - move16(); /*Q15 1/5 */ - if(EQ_16(thr,5)) + move16(); /*Q15 1/5 */ + if ( EQ_16( thr, 5 ) ) { tmp = 6554; - move16(); /*Q15 1/5 */ + move16(); /*Q15 1/5 */ } - if(EQ_16(thr,6)) + if ( EQ_16( thr, 6 ) ) { tmp = 5462; - move16();/*Q15 1/6 */ + move16(); /*Q15 1/6 */ } - if(EQ_16(thr,7)) + if ( EQ_16( thr, 7 ) ) { tmp = 4682; - move16();/*Q15 1/7 */ + move16(); /*Q15 1/7 */ } - bit_band = mult(tmp, Bits); /*0+15-15=0, Q0 */ - band_num = sub(end_band,start_band); + bit_band = mult( tmp, Bits ); /*0+15-15=0, Q0 */ + band_num = sub( end_band, start_band ); FOR( i = 0; i < band_num; i++ ) { - y_index[i] = y[add(i,start_band)]; + y_index[i] = y[add( i, start_band )]; move16(); index[i] = i; move16(); } /* Rearrange norm vector in decreasing order */ - reordvct_fx(y_index, band_num, index); + reordvct_fx( y_index, band_num, index ); /* norm vector modification */ - factor_fx = div_s(1, band_num);/*Q15 */ - IF ( GT_16(thr,5)) + factor_fx = div_s( 1, band_num ); /*Q15 */ + IF( GT_16( thr, 5 ) ) { - FOR ( i = 0; i < band_num; i++ ) + FOR( i = 0; i < band_num; i++ ) { - L_tmp = L_mult(i,factor_fx);/*Q16 */ - tmp = extract_h(L_shl(L_tmp, 13)); /*Q13 */ - tmp = sub(fac_fx[1],tmp);/*Q13 */ - L_tmp = L_mult(y_index[i],tmp);/*Q14 */ - y_index[i] = extract_h(L_shl(L_tmp, 2));/*Q0 */ + L_tmp = L_mult( i, factor_fx ); /*Q16 */ + tmp = extract_h( L_shl( L_tmp, 13 ) ); /*Q13 */ + tmp = sub( fac_fx[1], tmp ); /*Q13 */ + L_tmp = L_mult( y_index[i], tmp ); /*Q14 */ + y_index[i] = extract_h( L_shl( L_tmp, 2 ) ); /*Q0 */ } } ELSE { - FOR ( i = 0; i < band_num; i++ ) + FOR( i = 0; i < band_num; i++ ) { - L_tmp = L_mult(i,factor_fx);/*Q16 */ - tmp = extract_h(L_shl(L_tmp, 13)); /*Q13 */ - tmp = sub(fac_fx[0],tmp);/*Q13 */ - L_tmp = L_mult(y_index[i],tmp);/*Q14 */ - y_index[i] = extract_h(L_shl(L_tmp, 2));/*Q0 */ + L_tmp = L_mult( i, factor_fx ); /*Q16 */ + tmp = extract_h( L_shl( L_tmp, 13 ) ); /*Q13 */ + tmp = sub( fac_fx[0], tmp ); /*Q13 */ + L_tmp = L_mult( y_index[i], tmp ); /*Q14 */ + y_index[i] = extract_h( L_shl( L_tmp, 2 ) ); /*Q0 */ } } /* bit allocation based on modified norm */ - L_tmp = L_mult(band_num,24576);/*Q16 */ - tmp = extract_h(L_shl(L_tmp,7));/*Q7 */ - IF ( GE_16(shl(bit_band,7),tmp)) + L_tmp = L_mult( band_num, 24576 ); /*Q16 */ + tmp = extract_h( L_shl( L_tmp, 7 ) ); /*Q7 */ + IF( GE_16( shl( bit_band, 7 ), tmp ) ) { - FOR ( j = 0; j < band_num; j++) + FOR( j = 0; j < band_num; j++ ) { if ( y_index[j] < 0 ) { @@ -635,47 +636,47 @@ void Bit_group_fx ( move16(); } R_temp_fx[j] = 2097152; - move16();/*Q21 = 1 move16(); */ + move16(); /*Q21 = 1 move16(); */ } - i = sub(band_num,1); - norm_sum = 0;/*Q0 */ - FOR (k = 0; k <= i; k++) + i = sub( band_num, 1 ); + norm_sum = 0; /*Q0 */ + FOR( k = 0; k <= i; k++ ) { - norm_sum = add(norm_sum,y_index[k]); + norm_sum = add( norm_sum, y_index[k] ); } - FOR (j = 0; j < band_num; j++) + FOR( j = 0; j < band_num; j++ ) { - IF(norm_sum == 0) + IF( norm_sum == 0 ) { - FOR (k = 0; k <= i; k++) + FOR( k = 0; k <= i; k++ ) { - R_temp_fx[k] = L_deposit_h(0);/*Q21 */ + R_temp_fx[k] = L_deposit_h( 0 ); /*Q21 */ } } ELSE { - exp = norm_s(norm_sum); - tmp = shl(norm_sum, exp);/*Q(exp) */ - tmp = div_s(16384,tmp); /*Q(15+14-exp) */ - Bits_avg_fx = L_mult(tmp, Bits);/*Q(30-exp) */ + exp = norm_s( norm_sum ); + tmp = shl( norm_sum, exp ); /*Q(exp) */ + tmp = div_s( 16384, tmp ); /*Q(15+14-exp) */ + Bits_avg_fx = L_mult( tmp, Bits ); /*Q(30-exp) */ - FOR (k = 0; k <= i; k++) + FOR( k = 0; k <= i; k++ ) { - L_tmp = L_shl(L_deposit_l(y_index[k]),24); - L_tmp = Mult_32_32(Bits_avg_fx,L_tmp);/*Q(23-exp) */ + L_tmp = L_shl( L_deposit_l( y_index[k] ), 24 ); + L_tmp = Mult_32_32( Bits_avg_fx, L_tmp ); /*Q(23-exp) */ - R_temp_fx[k] = L_shl(L_tmp,sub(exp,2)); - move32();/*Q21 */ + R_temp_fx[k] = L_shl( L_tmp, sub( exp, 2 ) ); + move32(); /*Q21 */ } } - L_tmp = L_shl(L_deposit_l(thr),21);/*Q21 */ - IF ( LT_32(R_temp_fx[i],L_tmp)) + L_tmp = L_shl( L_deposit_l( thr ), 21 ); /*Q21 */ + IF( LT_32( R_temp_fx[i], L_tmp ) ) { - R_temp_fx[i] = L_deposit_h(0); - norm_sum = sub(norm_sum,y_index[i]); + R_temp_fx[i] = L_deposit_h( 0 ); + norm_sum = sub( norm_sum, y_index[i] ); i--; } ELSE @@ -686,7 +687,7 @@ void Bit_group_fx ( } ELSE { - FOR ( j = 0; j < bit_band; j++ ) + FOR( j = 0; j < bit_band; j++ ) { if ( y_index[j] < 0 ) { @@ -694,65 +695,65 @@ void Bit_group_fx ( move16(); } R_temp_fx[j] = 2097152; - move32();/*Q21 = 1 */ + move32(); /*Q21 = 1 */ } - FOR ( j = bit_band; j < band_num; j++ ) + FOR( j = bit_band; j < band_num; j++ ) { - R_temp_fx[j] = L_deposit_l(0); + R_temp_fx[j] = L_deposit_l( 0 ); } norm_sum = 0; - FOR (k = 0; k < bit_band; k++) + FOR( k = 0; k < bit_band; k++ ) { - norm_sum = add(norm_sum,y_index[k]); + norm_sum = add( norm_sum, y_index[k] ); } i = bit_band; - FOR (j = 0; j < bit_band; j++) + FOR( j = 0; j < bit_band; j++ ) { - IF(norm_sum == 0) + IF( norm_sum == 0 ) { - FOR (k = 0; k < i; k++) + FOR( k = 0; k < i; k++ ) { - R_temp_fx[k] = L_deposit_l(0); /*Q21 */ + R_temp_fx[k] = L_deposit_l( 0 ); /*Q21 */ } } ELSE { - exp = norm_s(norm_sum); - tmp = shl(norm_sum, exp);/*Q(exp) */ - tmp = div_s(16384,tmp); /*Q(15+14-exp) */ - Bits_avg_fx = L_mult(tmp, Bits);/*Q(30-exp) */ - FOR (k = 0; k < i; k++) + exp = norm_s( norm_sum ); + tmp = shl( norm_sum, exp ); /*Q(exp) */ + tmp = div_s( 16384, tmp ); /*Q(15+14-exp) */ + Bits_avg_fx = L_mult( tmp, Bits ); /*Q(30-exp) */ + FOR( k = 0; k < i; k++ ) { - L_tmp = L_shl(L_deposit_l(y_index[k]),24); - L_tmp = Mult_32_32(Bits_avg_fx,L_tmp);/*Q(23-exp) */ + L_tmp = L_shl( L_deposit_l( y_index[k] ), 24 ); + L_tmp = Mult_32_32( Bits_avg_fx, L_tmp ); /*Q(23-exp) */ - R_temp_fx[k] = L_shl(L_tmp,sub(exp,2)); - move32();/*Q21 */ + R_temp_fx[k] = L_shl( L_tmp, sub( exp, 2 ) ); + move32(); /*Q21 */ } } R_sum_fx = 0; - L_tmp = L_shl(L_deposit_l(thr),21);/*Q21 */ - FOR (k = 0; k < i; k++) + L_tmp = L_shl( L_deposit_l( thr ), 21 ); /*Q21 */ + FOR( k = 0; k < i; k++ ) { - IF (LT_32(R_temp_fx[k],L_tmp)) + IF( LT_32( R_temp_fx[k], L_tmp ) ) { - FOR(m = k; m < i; m++) + FOR( m = k; m < i; m++ ) { - norm_sum = sub(norm_sum,y_index[m]); - R_temp_fx[m] = L_deposit_l(0); /*Q21 */ + norm_sum = sub( norm_sum, y_index[m] ); + R_temp_fx[m] = L_deposit_l( 0 ); /*Q21 */ } i = k; BREAK; } ELSE { - R_sum_fx = L_add(R_sum_fx,R_temp_fx[k]); + R_sum_fx = L_add( R_sum_fx, R_temp_fx[k] ); } } - IF (EQ_32(R_sum_fx,R_sum_org_fx)) + IF( EQ_32( R_sum_fx, R_sum_org_fx ) ) { BREAK; } @@ -762,16 +763,15 @@ void Bit_group_fx ( } /* index comeback */ - FOR ( k = 0 ; k < band_num; k++ ) + FOR( k = 0; k < band_num; k++ ) { j = index[k]; move16(); - Rsubband_fx[add(j,start_band)] = R_temp_fx[k]; + Rsubband_fx[add( j, start_band )] = R_temp_fx[k]; move32(); } return; - } /*-------------------------------------------------------------------* @@ -780,106 +780,106 @@ void Bit_group_fx ( * WB bit allocation *-------------------------------------------------------------------*/ -Word16 BitAllocWB_fx( /* o : t Q0*/ - Word16 *y, /* i : norm of sub-vectors Q0*/ - Word16 B, /* i : number of available bits Q0*/ - Word16 N, /* i : number of sub-vectors Q0*/ - Word16 *R, /* o : bit-allocation indicator Q0*/ - Word16 *Rsubband_fx /* o : sub-band bit-allocation vector Q3*/ +Word16 BitAllocWB_fx( /* o : t Q0*/ + Word16 *y, /* i : norm of sub-vectors Q0*/ + Word16 B, /* i : number of available bits Q0*/ + Word16 N, /* i : number of sub-vectors Q0*/ + Word16 *R, /* o : bit-allocation indicator Q0*/ + Word16 *Rsubband_fx /* o : sub-band bit-allocation vector Q3*/ ) { Word16 t_fx; Word16 i, j, k, B1, B2, B3, B_saved; Word16 Rsum_fx, Rsum_sub_fx[3]; Word32 Ravg_sub_32_fx[3], R_diff_32_fx[2]; - Word16 factor_fx[2];/*Q13 */ + Word16 factor_fx[2]; /*Q13 */ Word16 BANDS; - Word16 tmp,exp; - Word16 Rsum_sub_fx_tmp=0; /* initialize just to avoid compiler warning */ - Word32 L_tmp,L_tmp1; + Word16 tmp, exp; + Word16 Rsum_sub_fx_tmp = 0; /* initialize just to avoid compiler warning */ + Word32 L_tmp, L_tmp1; Word32 Rsubband_buf[NB_SFM]; BANDS = N; move16(); - if( GT_16(BANDS,SFM_N)) + if ( GT_16( BANDS, SFM_N ) ) { BANDS = SFM_N; move16(); } /* Init Rsubband to non-zero values for bands to be allocated bits */ - FOR (k = 0; k < BANDS; k++) + FOR( k = 0; k < BANDS; k++ ) { Rsubband_buf[k] = 2097152; - move32();/*Q21 */ + move32(); /*Q21 */ } /* Calculate the norm sum and average of sub-band */ Rsum_sub_fx[0] = 0; move16(); - FOR ( j = 0; j < SFM_G1; j++ ) + FOR( j = 0; j < SFM_G1; j++ ) { if ( y[j] > 0 ) { - Rsum_sub_fx_tmp = add(Rsum_sub_fx[0],y[j]); /*Q0 */ + Rsum_sub_fx_tmp = add( Rsum_sub_fx[0], y[j] ); /*Q0 */ } - if (y[j] > 0) + if ( y[j] > 0 ) { Rsum_sub_fx[0] = Rsum_sub_fx_tmp; - move16(); /*Q0 */ + move16(); /*Q0 */ } } - Ravg_sub_32_fx[0] = L_mult(Rsum_sub_fx[0], 2048); - move32();/*Q16 0+15+1 //q15 1/16 =2048 */ + Ravg_sub_32_fx[0] = L_mult( Rsum_sub_fx[0], 2048 ); + move32(); /*Q16 0+15+1 //q15 1/16 =2048 */ Rsum_sub_fx[1] = 0; move16(); - FOR ( j = SFM_G1; j < SFM_G1G2; j++ ) + FOR( j = SFM_G1; j < SFM_G1G2; j++ ) { if ( y[j] > 0 ) { - Rsum_sub_fx_tmp = add(Rsum_sub_fx[1],y[j]); /*Q0 */ + Rsum_sub_fx_tmp = add( Rsum_sub_fx[1], y[j] ); /*Q0 */ } if ( y[j] > 0 ) { Rsum_sub_fx[1] = Rsum_sub_fx_tmp; - move16();/*Q0 */ + move16(); /*Q0 */ } } - Ravg_sub_32_fx[1] = L_mult(Rsum_sub_fx[1], 4096); /*16 0+15+1 //q15 1/8 =4096 */ + Ravg_sub_32_fx[1] = L_mult( Rsum_sub_fx[1], 4096 ); /*16 0+15+1 //q15 1/8 =4096 */ Rsum_sub_fx[2] = 0; move16(); - FOR ( j = SFM_G1G2; j < BANDS; j++ ) + FOR( j = SFM_G1G2; j < BANDS; j++ ) { if ( y[j] > 0 ) { - Rsum_sub_fx_tmp = add(Rsum_sub_fx[2],y[j]); /*Q0 */ + Rsum_sub_fx_tmp = add( Rsum_sub_fx[2], y[j] ); /*Q0 */ } if ( y[j] > 0 ) { Rsum_sub_fx[2] = Rsum_sub_fx_tmp; - move16();/*Q0 */ + move16(); /*Q0 */ } } - tmp = div_s(1, BANDS-SFM_G1G2); /*Q15 */ - Ravg_sub_32_fx[2] = L_mult(Rsum_sub_fx[2], tmp); - move32();/*Q16 */ + tmp = div_s( 1, BANDS - SFM_G1G2 ); /*Q15 */ + Ravg_sub_32_fx[2] = L_mult( Rsum_sub_fx[2], tmp ); + move32(); /*Q16 */ /* Bit allocation for every group */ - tmp = add(Rsum_sub_fx[0],Rsum_sub_fx[1]); - Rsum_fx = add(tmp,Rsum_sub_fx[2]);/*Q0 */ + tmp = add( Rsum_sub_fx[0], Rsum_sub_fx[1] ); + Rsum_fx = add( tmp, Rsum_sub_fx[2] ); /*Q0 */ - factor_fx[0] = 16384;/*Q13 move16(); */ - factor_fx[1] = 24576;/*Q13 move16(); */ + factor_fx[0] = 16384; /*Q13 move16(); */ + factor_fx[1] = 24576; /*Q13 move16(); */ { - R_diff_32_fx[0] = L_sub(Ravg_sub_32_fx[0], Ravg_sub_32_fx[1]); - move32();/*Q16 */ - R_diff_32_fx[1] = L_sub(Ravg_sub_32_fx[1], Ravg_sub_32_fx[2]); - move32();/*Q16 */ + R_diff_32_fx[0] = L_sub( Ravg_sub_32_fx[0], Ravg_sub_32_fx[1] ); + move32(); /*Q16 */ + R_diff_32_fx[1] = L_sub( Ravg_sub_32_fx[1], Ravg_sub_32_fx[2] ); + move32(); /*Q16 */ test(); - IF ( LT_32(R_diff_32_fx[0],393216)&<_32(R_diff_32_fx[1],245760)) + IF( LT_32( R_diff_32_fx[0], 393216 ) && LT_32( R_diff_32_fx[1], 245760 ) ) { - IF(Rsum_fx == 0) + IF( Rsum_fx == 0 ) { B1 = 0; move16(); @@ -890,96 +890,96 @@ Word16 BitAllocWB_fx( /* o : t } ELSE { - exp = norm_s(Rsum_fx); - tmp = shl(Rsum_fx,exp);/*Q(exp) */ - tmp = div_s(16384,tmp);/*Q(15+14-exp) */ - L_tmp1 = L_mult(B,Rsum_sub_fx[0]);/*Q1 */ - L_tmp = Mult_32_16(L_tmp1,tmp);/*Q(15-exp) */ - B1 = extract_h(L_shl(L_tmp,add(exp,1)));/*Q0 */ + exp = norm_s( Rsum_fx ); + tmp = shl( Rsum_fx, exp ); /*Q(exp) */ + tmp = div_s( 16384, tmp ); /*Q(15+14-exp) */ + L_tmp1 = L_mult( B, Rsum_sub_fx[0] ); /*Q1 */ + L_tmp = Mult_32_16( L_tmp1, tmp ); /*Q(15-exp) */ + B1 = extract_h( L_shl( L_tmp, add( exp, 1 ) ) ); /*Q0 */ test(); - if(GT_32(L_tmp1,L_mult(B1,Rsum_fx))&&GE_32(L_tmp1,L_mult(add(B1,1),Rsum_fx))) + if ( GT_32( L_tmp1, L_mult( B1, Rsum_fx ) ) && GE_32( L_tmp1, L_mult( add( B1, 1 ), Rsum_fx ) ) ) { - B1 = add(B1,1); + B1 = add( B1, 1 ); } - L_tmp1 = L_mult(B,Rsum_sub_fx[1]);/*Q1 */ - L_tmp = Mult_32_16(L_tmp1,tmp);/*Q(15-exp) */ - B2 = extract_h(L_shl(L_tmp,add(exp,1)));/*Q0 */ + L_tmp1 = L_mult( B, Rsum_sub_fx[1] ); /*Q1 */ + L_tmp = Mult_32_16( L_tmp1, tmp ); /*Q(15-exp) */ + B2 = extract_h( L_shl( L_tmp, add( exp, 1 ) ) ); /*Q0 */ test(); - if(GT_32(L_tmp1,L_mult(B2,Rsum_fx))&&GE_32(L_tmp1,L_mult(add(B2,1),Rsum_fx))) + if ( GT_32( L_tmp1, L_mult( B2, Rsum_fx ) ) && GE_32( L_tmp1, L_mult( add( B2, 1 ), Rsum_fx ) ) ) { - B2 = add(B2,1); + B2 = add( B2, 1 ); } - L_tmp1 = L_mult(B,Rsum_sub_fx[2]);/*Q1 */ - L_tmp = Mult_32_16(L_tmp1,tmp);/*Q(15-exp) */ - B3 = extract_h(L_shl(L_tmp,add(exp,1)));/*Q0 */ + L_tmp1 = L_mult( B, Rsum_sub_fx[2] ); /*Q1 */ + L_tmp = Mult_32_16( L_tmp1, tmp ); /*Q(15-exp) */ + B3 = extract_h( L_shl( L_tmp, add( exp, 1 ) ) ); /*Q0 */ test(); - if(GT_32(L_tmp1,L_mult(B3,Rsum_fx))&&GE_32(L_tmp1,L_mult(add(B3,1),Rsum_fx))) + if ( GT_32( L_tmp1, L_mult( B3, Rsum_fx ) ) && GE_32( L_tmp1, L_mult( add( B3, 1 ), Rsum_fx ) ) ) { - B3 = add(B3,1); + B3 = add( B3, 1 ); } } - IF ( GT_32(Ravg_sub_32_fx[2],786432)) + IF( GT_32( Ravg_sub_32_fx[2], 786432 ) ) { B_saved = 0; move16(); - IF ( GT_16(B1,288)) + IF( GT_16( B1, 288 ) ) { - B_saved = sub(B1,288); + B_saved = sub( B1, 288 ); B1 = 288; move16(); } - IF ( GT_16(B2,256)) + IF( GT_16( B2, 256 ) ) { - tmp = sub(B2,256); - B_saved = add(B_saved,tmp); + tmp = sub( B2, 256 ); + B_saved = add( B_saved, tmp ); B2 = 256; move16(); } - IF ( GT_16(B3,96)) + IF( GT_16( B3, 96 ) ) { - tmp = sub(B3,96); - B_saved = add(B_saved,tmp); + tmp = sub( B3, 96 ); + B_saved = add( B_saved, tmp ); B3 = 96; move16(); } - IF ( B_saved > 0 ) + IF( B_saved > 0 ) { - IF ( EQ_16(B1,288)) + IF( EQ_16( B1, 288 ) ) { - tmp = shr(B_saved,1); - B2 = add(B2,tmp); - tmp = sub(B,B1); - B3 = sub(tmp,B2); + tmp = shr( B_saved, 1 ); + B2 = add( B2, tmp ); + tmp = sub( B, B1 ); + B3 = sub( tmp, B2 ); } ELSE { - tmp = shr(B_saved,1); - B1 = add(B1,tmp); - IF ( EQ_16(B2,256)) + tmp = shr( B_saved, 1 ); + B1 = add( B1, tmp ); + IF( EQ_16( B2, 256 ) ) { - tmp = sub(B,B1); - B3 = sub(tmp,B2); + tmp = sub( B, B1 ); + B3 = sub( tmp, B2 ); } ELSE { - tmp = sub(B,B1); - B2 = sub(tmp,B3); + tmp = sub( B, B1 ); + B2 = sub( tmp, B3 ); } } } } factor_fx[0] = 16384; - move16();/*Q13 */ + move16(); /*Q13 */ factor_fx[1] = 12288; - move16();/*Q13 */ + move16(); /*Q13 */ } ELSE { - IF(Rsum_fx == 0) + IF( Rsum_fx == 0 ) { B1 = 0; move16(); @@ -990,57 +990,56 @@ Word16 BitAllocWB_fx( /* o : t } ELSE { - exp = norm_s(Rsum_fx); - tmp = shl(Rsum_fx,exp);/*Q(exp) */ - tmp = div_s(16384,tmp);/*Q(15+14-exp) */ - L_tmp1 = L_mult(B,Rsum_sub_fx[0]);/*Q1 */ - L_tmp = Mult_32_16(L_tmp1,tmp);/*Q(15-exp) */ - B1 = extract_h(L_shl(L_tmp,add(exp,1)));/*Q0 */ + exp = norm_s( Rsum_fx ); + tmp = shl( Rsum_fx, exp ); /*Q(exp) */ + tmp = div_s( 16384, tmp ); /*Q(15+14-exp) */ + L_tmp1 = L_mult( B, Rsum_sub_fx[0] ); /*Q1 */ + L_tmp = Mult_32_16( L_tmp1, tmp ); /*Q(15-exp) */ + B1 = extract_h( L_shl( L_tmp, add( exp, 1 ) ) ); /*Q0 */ test(); - if(GT_32(L_tmp1,L_mult(B1,Rsum_fx))&&GE_32(L_tmp1,L_mult(add(B1,1),Rsum_fx))) + if ( GT_32( L_tmp1, L_mult( B1, Rsum_fx ) ) && GE_32( L_tmp1, L_mult( add( B1, 1 ), Rsum_fx ) ) ) { - B1 = add(B1,1); + B1 = add( B1, 1 ); } - L_tmp1 = Mult_32_16(1975684956,shl(B,5));/*Q(31+5-15=21) */ - L_tmp1 = Mult_32_16(L_tmp1,shl(Rsum_sub_fx[1],7));/*Q(21+7-15=13) */ - L_tmp = Mult_32_16(L_tmp1,tmp);/*Q(27-exp) */ - B2 = extract_h(L_shl(L_tmp,sub(exp,11)));/*Q0 */ + L_tmp1 = Mult_32_16( 1975684956, shl( B, 5 ) ); /*Q(31+5-15=21) */ + L_tmp1 = Mult_32_16( L_tmp1, shl( Rsum_sub_fx[1], 7 ) ); /*Q(21+7-15=13) */ + L_tmp = Mult_32_16( L_tmp1, tmp ); /*Q(27-exp) */ + B2 = extract_h( L_shl( L_tmp, sub( exp, 11 ) ) ); /*Q0 */ test(); - if(GT_32(L_tmp1,L_shl(L_mult(B2,Rsum_fx),12))&&GE_32(L_add(L_tmp1,2),L_shl(L_mult(add(B2,1),Rsum_fx),12))) + if ( GT_32( L_tmp1, L_shl( L_mult( B2, Rsum_fx ), 12 ) ) && GE_32( L_add( L_tmp1, 2 ), L_shl( L_mult( add( B2, 1 ), Rsum_fx ), 12 ) ) ) { - B2 = add(B2,1); + B2 = add( B2, 1 ); } - tmp = sub(B,B1); - B3 = sub(tmp,B2); + tmp = sub( B, B1 ); + B3 = sub( tmp, B2 ); } } } - IF ( LT_16(Rsum_sub_fx[2],3)) + IF( LT_16( Rsum_sub_fx[2], 3 ) ) { - B2 = add(B2,B3); + B2 = add( B2, B3 ); B3 = 0; move16(); } /* Bit allocation in group */ - Bit_group_fx( y, 0, SFM_G1, B1, 5, Rsubband_buf, factor_fx); - Bit_group_fx( y, SFM_G1, SFM_G1G2, B2, 6, Rsubband_buf, factor_fx); - Bit_group_fx( y, SFM_G1G2, BANDS, B3, 7, Rsubband_buf, factor_fx); - FOR (i = 0; i < BANDS; i++) + Bit_group_fx( y, 0, SFM_G1, B1, 5, Rsubband_buf, factor_fx ); + Bit_group_fx( y, SFM_G1, SFM_G1G2, B2, 6, Rsubband_buf, factor_fx ); + Bit_group_fx( y, SFM_G1G2, BANDS, B3, 7, Rsubband_buf, factor_fx ); + FOR( i = 0; i < BANDS; i++ ) { - Rsubband_fx[i] = extract_l(L_shr(Rsubband_buf[i], 18)); + Rsubband_fx[i] = extract_l( L_shr( Rsubband_buf[i], 18 ) ); } /* Calcuate total used bits and initialize R to be used for Noise Filling */ - L_tmp = L_deposit_l(0); - FOR( i = 0; i < N; i++) + L_tmp = L_deposit_l( 0 ); + FOR( i = 0; i < N; i++ ) { - L_tmp = L_add(L_tmp,Rsubband_buf[i]);/*Q21 */ - R[i] = extract_h(L_shr(Rsubband_buf[i],5));/*Q0 */ + L_tmp = L_add( L_tmp, Rsubband_buf[i] ); /*Q21 */ + R[i] = extract_h( L_shr( Rsubband_buf[i], 5 ) ); /*Q0 */ } - t_fx = extract_h(L_shr(L_tmp, 5)); /*Q0 */ - - return (Word16)t_fx; + t_fx = extract_h( L_shr( L_tmp, 5 ) ); /*Q0 */ + return (Word16) t_fx; } diff --git a/lib_com/bitallocsum_fx.c b/lib_com/bitallocsum_fx.c index 73dd2ef74..fd34a0c1d 100644 --- a/lib_com/bitallocsum_fx.c +++ b/lib_com/bitallocsum_fx.c @@ -2,59 +2,59 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ +#include "options.h" /* Compilation switches */ #include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ /*-------------------------------------------------------------------------- - * bitallocsum_fx() - * - * Calculate the total number of bits allocated over frame - *--------------------------------------------------------------------------*/ + * bitallocsum_fx() + * + * Calculate the total number of bits allocated over frame + *--------------------------------------------------------------------------*/ void bitallocsum_fx( - Word16 *R, /* i : bit-allocation vector Q0 */ - const Word16 nb_sfm, /* i : number of sub-vectors Q0 */ - Word16 *sum, /* o : total number of bits allocated Q0 */ - Word16 *Rsubband, /* o : rate per subband Q3 */ - const Word16 num_bits,/* i : number of bits Q0 */ - const Word16 length, /* i : length of spectrum (32 or 48 kHz samplerate) Q0 */ - const Word16 *sfmsize /* i : band length Q0 */ + Word16 *R, /* i : bit-allocation vector Q0 */ + const Word16 nb_sfm, /* i : number of sub-vectors Q0 */ + Word16 *sum, /* o : total number of bits allocated Q0 */ + Word16 *Rsubband, /* o : rate per subband Q3 */ + const Word16 num_bits, /* i : number of bits Q0 */ + const Word16 length, /* i : length of spectrum (32 or 48 kHz samplerate) Q0 */ + const Word16 *sfmsize /* i : band length Q0 */ ) { Word16 i; Word16 total, tmp; Word16 diff; - total = (Word16)0; + total = (Word16) 0; move16(); - FOR (i = 0; i < nb_sfm; i++) + FOR( i = 0; i < nb_sfm; i++ ) { - tmp = extract_l(L_mult0(R[i], sfmsize[i])); - Rsubband[i] = shl(tmp, 3); + tmp = extract_l( L_mult0( R[i], sfmsize[i] ) ); + Rsubband[i] = shl( tmp, 3 ); move16(); - total = add(total, tmp); + total = add( total, tmp ); } *sum = total; - IF ( LE_16(length, L_FRAME32k)) + IF( LE_16( length, L_FRAME32k ) ) { - diff = sub(num_bits, *sum); - i = (Word16)0; + diff = sub( num_bits, *sum ); + i = (Word16) 0; move16(); - WHILE ( diff > 0 ) + WHILE( diff > 0 ) { - IF ( R[i] > 0 ) + IF( R[i] > 0 ) { - Rsubband[i] = add(Rsubband[i], 8); + Rsubband[i] = add( Rsubband[i], 8 ); move16(); - diff = sub(diff, 1); - *sum = add(*sum, 1); + diff = sub( diff, 1 ); + *sum = add( *sum, 1 ); } - i = add(i, 1); - if ( GE_16(i, nb_sfm)) + i = add( i, 1 ); + if ( GE_16( i, nb_sfm ) ) { - i = (Word16)0; + i = (Word16) 0; move16(); } } diff --git a/lib_com/bits_alloc.c b/lib_com/bits_alloc.c index 0be46047b..3bec92ac8 100644 --- a/lib_com/bits_alloc.c +++ b/lib_com/bits_alloc.c @@ -571,12 +571,10 @@ ivas_error config_acelp1_IVAS( if ( L_frame == L_FRAME ) { nb_subfr = NB_SUBFR; - } else /* L_frame == L_FRAME16k */ { nb_subfr = NB_SUBFR16k; - } coder_type_sw = coder_type; @@ -999,7 +997,7 @@ ivas_error config_acelp1_IVAS( } acelp_cfg->fcb_mode = 1; - if ( bits >= 16 ) + if ( bits >= 16 ) { acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, 2, 2 * L_SUBFR, GENERIC, -1, 0 ); } @@ -1440,14 +1438,14 @@ int16_t set_ACELP_flag_IVAS( const int16_t cng_type /* i : CNG type */ ) { - IF ( EQ_16(element_mode, IVAS_CPE_DFT) && EQ_16(idchan, 0) && LE_32(total_brate, SID_2k40) && EQ_16(bwidth, WB) && EQ_16(cng_type, LP_CNG )) + IF( EQ_16( element_mode, IVAS_CPE_DFT ) && EQ_16( idchan, 0 ) && LE_32( total_brate, SID_2k40 ) && EQ_16( bwidth, WB ) && EQ_16( cng_type, LP_CNG ) ) { return 1; } - ELSE IF (EQ_16(element_mode, IVAS_CPE_TD )) + ELSE IF( EQ_16( element_mode, IVAS_CPE_TD ) ) { - IF ( GE_32(element_brate, IVAS_24k4) && EQ_16(idchan, 0) && (EQ_16(tdm_LRTD_flag, 0 )|| GT_32(element_brate, IVAS_24k4 )) ) + IF( GE_32( element_brate, IVAS_24k4 ) && EQ_16( idchan, 0 ) && ( EQ_16( tdm_LRTD_flag, 0 ) || GT_32( element_brate, IVAS_24k4 ) ) ) { return 1; } @@ -1456,9 +1454,9 @@ int16_t set_ACELP_flag_IVAS( return 0; } } - ELSE IF (EQ_16(element_mode, IVAS_CPE_DFT )) + ELSE IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) { - IF (GE_32(element_brate, IVAS_24k4) ) + IF( GE_32( element_brate, IVAS_24k4 ) ) { return 1; } @@ -1467,9 +1465,9 @@ int16_t set_ACELP_flag_IVAS( return 0; } } - ELSE IF (EQ_16(element_mode, IVAS_SCE )) + ELSE IF( EQ_16( element_mode, IVAS_SCE ) ) { - IF (GE_32(element_brate, SCE_CORE_16k_LOW_LIMIT )) + IF( GE_32( element_brate, SCE_CORE_16k_LOW_LIMIT ) ) { return 1; } @@ -1478,7 +1476,7 @@ int16_t set_ACELP_flag_IVAS( return 0; } } - ELSE IF (GE_32(total_brate, ACELP_16k_LOW_LIMIT) ) /* EVS_MONO */ + ELSE IF( GE_32( total_brate, ACELP_16k_LOW_LIMIT ) ) /* EVS_MONO */ { return 1; } diff --git a/lib_com/bits_alloc_fx.c b/lib_com/bits_alloc_fx.c index 6f31adeef..514a9f894 100644 --- a/lib_com/bits_alloc_fx.c +++ b/lib_com/bits_alloc_fx.c @@ -21,12 +21,12 @@ ( b ) = tempr; \ } #endif - /*-------------------------------------------------------------------* - * Local function prototypes - *--------------------------------------------------------------------*/ -static Word16 BITS_ALLOC_adjust_acelp_fixed_cdk(const Word16 bits_frame, Word16* fixed_cdk_index, const Word16 nb_subfr ); -static Word16 BITS_ALLOC_adjust_generic(const Word16 bits_frame, Word16* fixed_cdk_index, const Word16 nb_subfr, const Word16* pulseconfigbits, const Word16 pulseconfig_size); -static Word16 allocate_unused(const Word32 core_brate, const Word16 coder_type, const Word16 unused_bits, const Word16 nb_prm, const Word16 subfr, const Word16 prm_type, Word16* prm_bit_mode); +/*-------------------------------------------------------------------* + * Local function prototypes + *--------------------------------------------------------------------*/ +static Word16 BITS_ALLOC_adjust_acelp_fixed_cdk( const Word16 bits_frame, Word16 *fixed_cdk_index, const Word16 nb_subfr ); +static Word16 BITS_ALLOC_adjust_generic( const Word16 bits_frame, Word16 *fixed_cdk_index, const Word16 nb_subfr, const Word16 *pulseconfigbits, const Word16 pulseconfig_size ); +static Word16 allocate_unused( const Word32 core_brate, const Word16 coder_type, const Word16 unused_bits, const Word16 nb_prm, const Word16 subfr, const Word16 prm_type, Word16 *prm_bit_mode ); typedef enum { @@ -47,7 +47,7 @@ void BITS_ALLOC_init_config_acelp( const Word32 bit_rate, const Word16 narrowBand, const Word16 nb_subfr, - ACELP_config *pConfigAcelp /*o: configuration structure of ACELP*/ + ACELP_config *pConfigAcelp /*o: configuration structure of ACELP*/ ) { Word8 rate_mode_index; @@ -56,9 +56,9 @@ void BITS_ALLOC_init_config_acelp( move16(); move16(); move16(); - rate_mode_index = (Word8)GT_32( bit_rate, ACELP_9k60 ); + rate_mode_index = (Word8) GT_32( bit_rate, ACELP_9k60 ); - pConfigAcelp->mode_index=rate_mode_index; + pConfigAcelp->mode_index = rate_mode_index; /*LPC: midLpc should be swithced off?*/ @@ -99,7 +99,7 @@ void BITS_ALLOC_init_config_acelp( } /*Wide band @ 16kHz*/ - IF ( EQ_16(nb_subfr,NB_SUBFR16k)) + IF( EQ_16( nb_subfr, NB_SUBFR16k ) ) { move16(); move16(); @@ -114,7 +114,6 @@ void BITS_ALLOC_init_config_acelp( pConfigAcelp->formant_tilt = 0; pConfigAcelp->voice_tilt = 2; } - } @@ -126,11 +125,11 @@ void BITS_ALLOC_init_config_acelp( * return: bit demand */ Word16 BITS_ALLOC_config_acelp( - const Word16 bits_frame, /* i: remaining bit budget for the frame*/ - const Word16 coder_type, /* i: acelp coder type*/ - ACELP_config *pConfigAcelp, /* i/o: configuration structure of ACELP*/ - const Word16 narrowBand, /* i : narrowband flag */ - const Word16 nb_subfr /* i : number of subframes */ + const Word16 bits_frame, /* i: remaining bit budget for the frame*/ + const Word16 coder_type, /* i: acelp coder type*/ + ACELP_config *pConfigAcelp, /* i/o: configuration structure of ACELP*/ + const Word16 narrowBand, /* i : narrowband flag */ + const Word16 nb_subfr /* i : number of subframes */ ) { Word16 mode_index; @@ -139,28 +138,27 @@ Word16 BITS_ALLOC_config_acelp( Word16 remaining_bits, bits; - move16(); move16(); move16(); mode_index = pConfigAcelp->mode_index; - band_index = (narrowBand==0); - bits=0; + band_index = ( narrowBand == 0 ); + bits = 0; - IF ( band_index==0 ) + IF( band_index == 0 ) { move16(); pConfigAcelp->formant_enh = 1; - if(EQ_16(coder_type,INACTIVE)) + if ( EQ_16( coder_type, INACTIVE ) ) { move16(); pConfigAcelp->formant_enh = 0; } } - IF ( s_and((Word16)EQ_16(band_index,1),(Word16)EQ_16(nb_subfr,4))) + IF( s_and( (Word16) EQ_16( band_index, 1 ), (Word16) EQ_16( nb_subfr, 4 ) ) ) { - IF(EQ_16(coder_type,INACTIVE)) + IF( EQ_16( coder_type, INACTIVE ) ) { pConfigAcelp->pre_emphasis = 0; move16(); @@ -187,9 +185,9 @@ Word16 BITS_ALLOC_config_acelp( move16(); } } - IF (EQ_16(coder_type,UNVOICED)) + IF( EQ_16( coder_type, UNVOICED ) ) { - IF(EQ_16(ACELP_GAINS_MODE[mode_index][band_index][coder_type], 6)) + IF( EQ_16( ACELP_GAINS_MODE[mode_index][band_index][coder_type], 6 ) ) { pConfigAcelp->pitch_sharpening = 0; move16(); @@ -212,7 +210,7 @@ Word16 BITS_ALLOC_config_acelp( move16(); } - IF(GT_16(coder_type,ACELP_MODE_MAX)) /* keep pitch sharpening for RF_ALLPRED mode */ + IF( GT_16( coder_type, ACELP_MODE_MAX ) ) /* keep pitch sharpening for RF_ALLPRED mode */ { pConfigAcelp->pitch_sharpening = 0; pConfigAcelp->phase_scrambling = 0; @@ -220,34 +218,34 @@ Word16 BITS_ALLOC_config_acelp( /*Allocate bits and different modes*/ move16(); - pConfigAcelp->bpf_mode=ACELP_BPF_MODE[mode_index][band_index][coder_type]; - bits = add(bits, ACELP_BPF_BITS[pConfigAcelp->bpf_mode]); + pConfigAcelp->bpf_mode = ACELP_BPF_MODE[mode_index][band_index][coder_type]; + bits = add( bits, ACELP_BPF_BITS[pConfigAcelp->bpf_mode] ); move16(); move16(); - pConfigAcelp->nrg_mode=ACELP_NRG_MODE[mode_index][band_index][coder_type]; - pConfigAcelp->nrg_bits=ACELP_NRG_BITS[pConfigAcelp->nrg_mode]; - bits = add(bits, pConfigAcelp->nrg_bits); + pConfigAcelp->nrg_mode = ACELP_NRG_MODE[mode_index][band_index][coder_type]; + pConfigAcelp->nrg_bits = ACELP_NRG_BITS[pConfigAcelp->nrg_mode]; + bits = add( bits, pConfigAcelp->nrg_bits ); move16(); - pConfigAcelp->ltp_mode=ACELP_LTP_MODE[mode_index][band_index][coder_type]; + pConfigAcelp->ltp_mode = ACELP_LTP_MODE[mode_index][band_index][coder_type]; move16(); - pConfigAcelp->ltp_bits=0; + pConfigAcelp->ltp_bits = 0; move16(); - pConfigAcelp->ltf_mode=ACELP_LTF_MODE[mode_index][band_index][coder_type]; + pConfigAcelp->ltf_mode = ACELP_LTF_MODE[mode_index][band_index][coder_type]; move16(); - pConfigAcelp->ltf_bits=ACELP_LTF_BITS[pConfigAcelp->ltf_mode]; - if ( s_and((Word16)EQ_16(nb_subfr,5),(Word16)EQ_16(pConfigAcelp->ltf_bits,4))) + pConfigAcelp->ltf_bits = ACELP_LTF_BITS[pConfigAcelp->ltf_mode]; + if ( s_and( (Word16) EQ_16( nb_subfr, 5 ), (Word16) EQ_16( pConfigAcelp->ltf_bits, 4 ) ) ) { - pConfigAcelp->ltf_bits = add(pConfigAcelp->ltf_bits,1); + pConfigAcelp->ltf_bits = add( pConfigAcelp->ltf_bits, 1 ); } - bits = add(bits,pConfigAcelp->ltf_bits); + bits = add( bits, pConfigAcelp->ltf_bits ); - FOR ( i=0; igains_mode[i] = ACELP_GAINS_MODE[mode_index][band_index][coder_type]; move16(); @@ -255,60 +253,60 @@ Word16 BITS_ALLOC_config_acelp( /* skip subframe 1, 3 gain encoding, and use from subframe 0, and 3, respectively */ test(); test(); - IF(GE_16(coder_type,ACELP_MODE_MAX)&&(EQ_16(i,1)||EQ_16(i,3))) + IF( GE_16( coder_type, ACELP_MODE_MAX ) && ( EQ_16( i, 1 ) || EQ_16( i, 3 ) ) ) { pConfigAcelp->gains_mode[i] = 0; } - bits = add(bits, ACELP_GAINS_BITS[pConfigAcelp->gains_mode[i]]); + bits = add( bits, ACELP_GAINS_BITS[pConfigAcelp->gains_mode[i]] ); move16(); - bits = add(bits, ACELP_LTP_BITS_SFR[pConfigAcelp->ltp_mode][i]); - pConfigAcelp->ltp_bits= add( pConfigAcelp->ltp_bits,ACELP_LTP_BITS_SFR[pConfigAcelp->ltp_mode][i]); + bits = add( bits, ACELP_LTP_BITS_SFR[pConfigAcelp->ltp_mode][i] ); + pConfigAcelp->ltp_bits = add( pConfigAcelp->ltp_bits, ACELP_LTP_BITS_SFR[pConfigAcelp->ltp_mode][i] ); } /*Innovation*/ - if ( LT_16(bits_frame,bits)) + if ( LT_16( bits_frame, bits ) ) { - printf("Warning: bits per frame too low\n"); + printf( "Warning: bits per frame too low\n" ); return -1; } - IF( EQ_16(coder_type,RF_ALLPRED)) + IF( EQ_16( coder_type, RF_ALLPRED ) ) { - set16_fx(pConfigAcelp->fixed_cdk_index, -1, nb_subfr); + set16_fx( pConfigAcelp->fixed_cdk_index, -1, nb_subfr ); } - ELSE IF ( EQ_16(coder_type,RF_GENPRED)) + ELSE IF( EQ_16( coder_type, RF_GENPRED ) ) { - pConfigAcelp->fixed_cdk_index[0] = 0; /* 7 bits */ + pConfigAcelp->fixed_cdk_index[0] = 0; /* 7 bits */ pConfigAcelp->fixed_cdk_index[1] = -1; - pConfigAcelp->fixed_cdk_index[2] = 0; /* 7 bits */ + pConfigAcelp->fixed_cdk_index[2] = 0; /* 7 bits */ pConfigAcelp->fixed_cdk_index[3] = -1; pConfigAcelp->fixed_cdk_index[4] = -1; - bits = add(bits,14); + bits = add( bits, 14 ); } - ELSE IF( EQ_16(coder_type,RF_NOPRED)) + ELSE IF( EQ_16( coder_type, RF_NOPRED ) ) { - set16_fx(pConfigAcelp->fixed_cdk_index, 0, nb_subfr); - bits = add(bits,28); + set16_fx( pConfigAcelp->fixed_cdk_index, 0, nb_subfr ); + bits = add( bits, 28 ); } ELSE { - bits = add(bits, BITS_ALLOC_adjust_acelp_fixed_cdk(sub(bits_frame,bits), pConfigAcelp->fixed_cdk_index, nb_subfr )); + bits = add( bits, BITS_ALLOC_adjust_acelp_fixed_cdk( sub( bits_frame, bits ), pConfigAcelp->fixed_cdk_index, nb_subfr ) ); } - remaining_bits = sub(bits_frame, bits); + remaining_bits = sub( bits_frame, bits ); /*Sanity check*/ - if (remaining_bits<0) + if ( remaining_bits < 0 ) { move16(); bits = -1; } - return(bits); + return ( bits ); } @@ -317,65 +315,64 @@ static Word16 BITS_ALLOC_adjust_generic( Word16 *fixed_cdk_index, const Word16 nb_subfr, const Word16 *pulseconfigbits, - const Word16 pulseconfig_size -) + const Word16 pulseconfig_size ) { Word16 bits_subframe2, inb_subfr; Word16 sfr, k, bitsused, bits_currsubframe; bits_subframe2 = bits_frame; move16(); - inb_subfr = 8192/*1.0f/NB_SUBFR Q15*/; + inb_subfr = 8192 /*1.0f/NB_SUBFR Q15*/; move16(); - if ( EQ_16(nb_subfr,NB_SUBFR16k)) + if ( EQ_16( nb_subfr, NB_SUBFR16k ) ) { - inb_subfr = 6554/*1.0f/NB_SUBFR16k Q15*/; + inb_subfr = 6554 /*1.0f/NB_SUBFR16k Q15*/; move16(); } - IF ( LT_16(bits_subframe2, i_mult2(pulseconfigbits[0], nb_subfr))) /* not in final code - not instrumented */ + IF( LT_16( bits_subframe2, i_mult2( pulseconfigbits[0], nb_subfr ) ) ) /* not in final code - not instrumented */ { - return add(bits_frame,1); /* Not enough bits for lowest mode. -> trigger alarm*/ + return add( bits_frame, 1 ); /* Not enough bits for lowest mode. -> trigger alarm*/ } /* search cdk-index for first subframe */ - FOR (k=0; k bits_subframe2) + IF( i_mult2( pulseconfigbits[k], nb_subfr ) > bits_subframe2 ) { - k = sub(k,1); /* previous mode did not exceed bit-budget */ + k = sub( k, 1 ); /* previous mode did not exceed bit-budget */ BREAK; } } - if (i_mult2(pulseconfigbits[k], nb_subfr) > bits_subframe2) + if ( i_mult2( pulseconfigbits[k], nb_subfr ) > bits_subframe2 ) { - k = sub(k,1); /* previous mode did not exceed bit-budget */ + k = sub( k, 1 ); /* previous mode did not exceed bit-budget */ } move16(); fixed_cdk_index[0] = k; - bitsused = i_mult2(pulseconfigbits[k], nb_subfr); + bitsused = i_mult2( pulseconfigbits[k], nb_subfr ); - FOR (sfr=1; sfr < nb_subfr; sfr++) + FOR( sfr = 1; sfr < nb_subfr; sfr++ ) { /*bits_currsubframe = (int)(((float)sfr+1.0f)*bits_subframe) - bitsused;*/ - bits_currsubframe = sub(add(i_mult2(sfr, bits_subframe2), bits_subframe2), bitsused); + bits_currsubframe = sub( add( i_mult2( sfr, bits_subframe2 ), bits_subframe2 ), bitsused ); /* try increasing mode while below threshold */ - WHILE ( (LT_16(k, pulseconfig_size-1))&&(LE_16(i_mult2(pulseconfigbits[add(k,1)],nb_subfr),bits_currsubframe))) + WHILE( ( LT_16( k, pulseconfig_size - 1 ) ) && ( LE_16( i_mult2( pulseconfigbits[add( k, 1 )], nb_subfr ), bits_currsubframe ) ) ) { test(); - k = add(k,1); + k = add( k, 1 ); } /* try decreasing mode until below threshold */ - WHILE (i_mult2(pulseconfigbits[k], nb_subfr) > bits_currsubframe) + WHILE( i_mult2( pulseconfigbits[k], nb_subfr ) > bits_currsubframe ) { - k = sub(k,1); + k = sub( k, 1 ); - IF (k == 0) + IF( k == 0 ) { BREAK; } @@ -384,22 +381,21 @@ static Word16 BITS_ALLOC_adjust_generic( /* store mode */ move16(); fixed_cdk_index[sfr] = k; - bitsused = add(bitsused, i_mult2(pulseconfigbits[k], nb_subfr)); + bitsused = add( bitsused, i_mult2( pulseconfigbits[k], nb_subfr ) ); } - return mult_r(bitsused, inb_subfr); + return mult_r( bitsused, inb_subfr ); } static Word16 BITS_ALLOC_adjust_acelp_fixed_cdk( const Word16 bits_frame, /*i: bit budget*/ Word16 *fixed_cdk_index, - const Word16 nb_subfr -) + const Word16 nb_subfr ) { Word16 bitsused; - bitsused = BITS_ALLOC_adjust_generic(bits_frame, fixed_cdk_index, nb_subfr, ACELP_CDK_BITS, ACELP_FIXED_CDK_NB); + bitsused = BITS_ALLOC_adjust_generic( bits_frame, fixed_cdk_index, nb_subfr, ACELP_CDK_BITS, ACELP_FIXED_CDK_NB ); return bitsused; @@ -414,18 +410,18 @@ static Word16 BITS_ALLOC_adjust_acelp_fixed_cdk( static Word16 fcb_table( const Word16 n, - const Word16 L_subfr) + const Word16 L_subfr ) { Word16 out; - //PMT("Not floating point computation, but fixed point operator are still missing ") + // PMT("Not floating point computation, but fixed point operator are still missing ") out = PulseConfTable[n].bits; - if (L_subfr > L_SUBFR) + if ( L_subfr > L_SUBFR ) { out = fast_FCB_bits_2sfr[n]; } - return (out); + return ( out ); } /*-------------------------------------------------------------------* @@ -435,7 +431,7 @@ static Word16 fcb_table( *--------------------------------------------------------------------*/ static ivas_error acelp_FCB_allocator( - Word16* nBits, /* i/o: available bit-budget */ + Word16 *nBits, /* i/o: available bit-budget */ Word16 fixed_cdk_index[], /* o : codebook index */ Word16 nb_subfr, /* i : number of subframes */ const Word16 L_subfr, /* i : subframe length */ @@ -446,10 +442,10 @@ static ivas_error acelp_FCB_allocator( { Word16 cdbk, sfr, step; Word16 nBits_tmp; - Word16* p_fixed_cdk_index; + Word16 *p_fixed_cdk_index; Word16 max_n; ivas_error error; - //PMT("Not floating point computation, but fixed point operator are still missing ") + // PMT("Not floating point computation, but fixed point operator are still missing ") error = IVAS_ERR_OK; @@ -458,29 +454,29 @@ static ivas_error acelp_FCB_allocator( p_fixed_cdk_index = fixed_cdk_index; /* TRANSITION coding: first subframe bit-budget was already fixed, glottal pulse not in the first subframe */ - if (tc_subfr >= L_SUBFR && fix_first) + if ( tc_subfr >= L_SUBFR && fix_first ) { Word16 i; - for (i = 0; i < nb_subfr; i++) + for ( i = 0; i < nb_subfr; i++ ) { - *nBits -= ACELP_FIXED_CDK_BITS(fixed_cdk_index[i]); + *nBits -= ACELP_FIXED_CDK_BITS( fixed_cdk_index[i] ); } return error; } /* TRANSITION coding: first subframe bit-budget was already fixed, glottal pulse in the first subframe */ sfr = 0; - if (fix_first) + if ( fix_first ) { - *nBits -= ACELP_FIXED_CDK_BITS(fixed_cdk_index[0]); + *nBits -= ACELP_FIXED_CDK_BITS( fixed_cdk_index[0] ); sfr = 1; p_fixed_cdk_index++; nb_subfr = 3; } /* distribute the bit-budget equally between subframes */ - if (L_subfr > L_SUBFR) /* access fast_FCB_bits_2sfr */ + if ( L_subfr > L_SUBFR ) /* access fast_FCB_bits_2sfr */ { max_n = 6; } @@ -488,31 +484,31 @@ static ivas_error acelp_FCB_allocator( { max_n = ACELP_FIXED_CDK_NB; } - for (cdbk = 0; cdbk < max_n; cdbk++) + for ( cdbk = 0; cdbk < max_n; cdbk++ ) { - if (fcb_table(cdbk, L_subfr) * nb_subfr > *nBits) + if ( fcb_table( cdbk, L_subfr ) * nb_subfr > *nBits ) { break; } } cdbk--; -#if defined DEBUGGING - if (cdbk < 0 && coder_type != TRANSITION) +#if defined DEBUGGING + if ( cdbk < 0 && coder_type != TRANSITION ) { - return IVAS_ERROR(IVAS_ERR_INTERNAL_FATAL, "Error: Too low bit-budget for fixed innovation codebook (frame = %d). Exiting! \n"); + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error: Too low bit-budget for fixed innovation codebook (frame = %d). Exiting! \n" ); } - if ((L_subfr == L_SUBFR && cdbk >= ACELP_FIXED_CDK_NB) || (L_subfr == 2 * L_SUBFR && fcb_table(cdbk, L_subfr) == 128 /*stop value*/)) + if ( ( L_subfr == L_SUBFR && cdbk >= ACELP_FIXED_CDK_NB ) || ( L_subfr == 2 * L_SUBFR && fcb_table( cdbk, L_subfr ) == 128 /*stop value*/ ) ) { - return IVAS_ERROR(IVAS_ERR_INTERNAL_FATAL, "Error: Too high bit-budget for fixed innovation codebook (frame = %d). Exiting! \n"); + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error: Too high bit-budget for fixed innovation codebook (frame = %d). Exiting! \n" ); } #endif - set16_fx(p_fixed_cdk_index, cdbk, nb_subfr); + set16_fx( p_fixed_cdk_index, cdbk, nb_subfr ); nBits_tmp = 0; - if (cdbk >= 0) + if ( cdbk >= 0 ) { - nBits_tmp = fcb_table(cdbk, L_subfr); + nBits_tmp = fcb_table( cdbk, L_subfr ); } else { @@ -521,24 +517,24 @@ static ivas_error acelp_FCB_allocator( *nBits -= nBits_tmp * nb_subfr; /* try to increase the FCB bit-budget of the first subframe(s) */ - if (cdbk < ACELP_FIXED_CDK_NB - 1) + if ( cdbk < ACELP_FIXED_CDK_NB - 1 ) { - step = fcb_table(cdbk + 1, L_subfr) - nBits_tmp; - while (*nBits >= step) + step = fcb_table( cdbk + 1, L_subfr ) - nBits_tmp; + while ( *nBits >= step ) { - (*p_fixed_cdk_index)++; + ( *p_fixed_cdk_index )++; *nBits -= step; p_fixed_cdk_index++; } /* try to increase the FCB of the first subframe in cases when the next step is lower than the current step */ - step = fcb_table(fixed_cdk_index[sfr] + 1, L_subfr) - fcb_table(fixed_cdk_index[sfr], L_subfr); - if (*nBits >= step && cdbk >= 0) + step = fcb_table( fixed_cdk_index[sfr] + 1, L_subfr ) - fcb_table( fixed_cdk_index[sfr], L_subfr ); + if ( *nBits >= step && cdbk >= 0 ) { fixed_cdk_index[sfr]++; *nBits -= step; - if (*nBits >= step && fixed_cdk_index[sfr + 1] == fixed_cdk_index[sfr] - 1) + if ( *nBits >= step && fixed_cdk_index[sfr + 1] == fixed_cdk_index[sfr] - 1 ) { sfr++; fixed_cdk_index[sfr]++; @@ -547,24 +543,24 @@ static ivas_error acelp_FCB_allocator( } } /* TRANSITION coding: allocate highest FCBQ bit-budget to the subframe with the glottal-shape codebook */ - if (tc_subfr >= L_SUBFR) + if ( tc_subfr >= L_SUBFR ) { Word16 tempr; - SWAP(fixed_cdk_index[0], fixed_cdk_index[tc_subfr / L_SUBFR]); + SWAP( fixed_cdk_index[0], fixed_cdk_index[tc_subfr / L_SUBFR] ); /* TRANSITION coding: allocate second highest FCBQ bit-budget to the last subframe */ - if (tc_subfr / L_SUBFR < nb_subfr - 1) + if ( tc_subfr / L_SUBFR < nb_subfr - 1 ) { - SWAP(fixed_cdk_index[(tc_subfr - L_SUBFR) / L_SUBFR], fixed_cdk_index[nb_subfr - 1]); + SWAP( fixed_cdk_index[( tc_subfr - L_SUBFR ) / L_SUBFR], fixed_cdk_index[nb_subfr - 1] ); } } /* when subframe length > L_SUBFR, number of bits instead of codebook index is signalled */ - if (L_subfr > L_SUBFR) + if ( L_subfr > L_SUBFR ) { Word16 i, j; - for (i = 0; i < nb_subfr; i++) + for ( i = 0; i < nb_subfr; i++ ) { j = fixed_cdk_index[i]; fixed_cdk_index[i] = fast_FCB_bits_2sfr[j]; @@ -592,15 +588,15 @@ ivas_error config_acelp1( const Word32 extl_brate, /* i : extension layer bitrate */ const Word16 L_frame, /* i : frame length at internal Fs */ const Word16 GSC_noisy_speech, /* i : GSC on SWB noisy speech flag */ - ACELP_config* acelp_cfg, /* i : ACELP bit-allocation */ + ACELP_config *acelp_cfg, /* i : ACELP bit-allocation */ const Word16 signalling_bits, /* i : number of signalling bits */ const Word16 coder_type, /* i : coder type */ const Word16 tc_subfr, /* i : TC subfr ID */ const Word16 tc_call, /* i : TC call number (0,1,2,3,5(DEC)) */ - Word16* nBits_es_Pred, /* o : number of bits for Es_pred Q */ - Word16* unbits, /* o : number of unused bits */ + Word16 *nBits_es_Pred, /* o : number of bits for Es_pred Q */ + Word16 *unbits, /* o : number of unused bits */ const Word16 element_mode, /* i : element mode */ - Word16* uc_two_stage_flag, /* o : flag undicating two-stage UC */ + Word16 *uc_two_stage_flag, /* o : flag undicating two-stage UC */ const Word16 tdm_lp_reuse_flag, /* i : LPC reuse flag (can be 1 only with secondary channel */ const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag */ const Word16 idchan, /* i : stereo channel ID */ @@ -610,7 +606,7 @@ ivas_error config_acelp1( const Word16 GSC_IVAS_mode /* i : GSC IVAS mode */ ) { - UNUSED_PARAM(active_cnt); + UNUSED_PARAM( active_cnt ); Word16 i, bits, nb_subfr; Word16 flag_hardcoded, coder_type_sw, fix_first; @@ -618,21 +614,21 @@ ivas_error config_acelp1( #ifdef DEBUGGING Word32 core_brate_inpI = core_brate_inp; #ifdef REMOVE_IVAS_UNUSED_PARAMETERS_WARNING - (void)active_cnt; + (void) active_cnt; #endif #endif ivas_error error; error = IVAS_ERR_OK; - //PMT("Not floating point computation, but fixed point operator are still missing ") + // PMT("Not floating point computation, but fixed point operator are still missing ") /*-----------------------------------------------------------------* * Set the flag indicating two-stage Unvoiced (UC) frame *-----------------------------------------------------------------*/ *uc_two_stage_flag = 0; - if (coder_type == UNVOICED) + if ( coder_type == UNVOICED ) { - if (total_brate >= MIN_UNVOICED_TWO_STAGE_BRATE && element_mode > EVS_MONO && (idchan == 0 || ((total_brate >= 8500 || extl_brate == 0) && tdm_LRTD_flag == 1))) + if ( total_brate >= MIN_UNVOICED_TWO_STAGE_BRATE && element_mode > EVS_MONO && ( idchan == 0 || ( ( total_brate >= 8500 || extl_brate == 0 ) && tdm_LRTD_flag == 1 ) ) ) { *uc_two_stage_flag = 1; } @@ -642,19 +638,19 @@ ivas_error config_acelp1( * Set the number of subframes *-----------------------------------------------------------------*/ - if (L_frame == L_FRAME) + if ( L_frame == L_FRAME ) { nb_subfr = NB_SUBFR; -#if defined DEBUGGING - if (((core_brate_inp < 5900 && coder_type > UNVOICED) && !(core_brate_inp < MIN_TC_BRATE && coder_type == TRANSITION)) && !(idchan > 0 && element_mode == IVAS_CPE_TD) && !(element_mode == IVAS_SCE && tdm_low_rate_mode)) +#if defined DEBUGGING + if ( ( ( core_brate_inp < 5900 && coder_type > UNVOICED ) && !( core_brate_inp < MIN_TC_BRATE && coder_type == TRANSITION ) ) && !( idchan > 0 && element_mode == IVAS_CPE_TD ) && !( element_mode == IVAS_SCE && tdm_low_rate_mode ) ) { - return IVAS_ERROR(IVAS_ERR_INTERNAL_FATAL, "Error: Too low bitrate (%d bps) for ACELP@12k8 in frame %d. Exiting!\n", core_brate_inpI); + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error: Too low bitrate (%d bps) for ACELP@12k8 in frame %d. Exiting!\n", core_brate_inpI ); } - if (core_brate_inp > ACELP_12k8_HIGH_LIMIT && core == ACELP_CORE) + if ( core_brate_inp > ACELP_12k8_HIGH_LIMIT && core == ACELP_CORE ) { - return IVAS_ERROR(IVAS_ERR_INTERNAL_FATAL, "Error: Too high bitrate (%d bps) for ACELP@12k8 in frame %d. Exiting!\n", core_brate_inpI); + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error: Too high bitrate (%d bps) for ACELP@12k8 in frame %d. Exiting!\n", core_brate_inpI ); } #endif } @@ -662,20 +658,20 @@ ivas_error config_acelp1( { nb_subfr = NB_SUBFR16k; -#if defined DEBUGGING - if (core_brate_inp < ACELP_16k_LOW_LIMIT && core == ACELP_CORE) +#if defined DEBUGGING + if ( core_brate_inp < ACELP_16k_LOW_LIMIT && core == ACELP_CORE ) { - return IVAS_ERROR(IVAS_ERR_INTERNAL_FATAL, "Error: Too low bitrate (%d bps) for ACELP@16k in frame %d. Exiting!\n", core_brate_inpI); + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error: Too low bitrate (%d bps) for ACELP@16k in frame %d. Exiting!\n", core_brate_inpI ); } #endif } coder_type_sw = coder_type; - if (core != ACELP_CORE) + if ( core != ACELP_CORE ) { /* used in acelp_core_switch_enc() */ nb_subfr = 1; - if (L_frame == L_FRAME) + if ( L_frame == L_FRAME ) { coder_type_sw = TRANSITION; } @@ -688,15 +684,15 @@ ivas_error config_acelp1( flag_hardcoded = 0; i = 0; - while (i < SIZE_BRATE_INTERMED_TBL) + while ( i < SIZE_BRATE_INTERMED_TBL ) { - if (core_brate_inp == brate_intermed_tbl[i]) + if ( core_brate_inp == brate_intermed_tbl[i] ) { flag_hardcoded = 1; break; } - if (core_brate_inp < brate_intermed_tbl[i]) + if ( core_brate_inp < brate_intermed_tbl[i] ) { flag_hardcoded = 0; break; @@ -705,20 +701,20 @@ ivas_error config_acelp1( i++; } - if (element_mode == IVAS_CPE_TD && coder_type == AUDIO && - core_brate_inp <= STEREO_GSC_BIT_RATE_ALLOC && brate_intermed_tbl[i] == ACELP_9k60) /* Bit allocation should be mapped to 8 kb/s instead of 9.6 kb/s in this case */ + if ( element_mode == IVAS_CPE_TD && coder_type == AUDIO && + core_brate_inp <= STEREO_GSC_BIT_RATE_ALLOC && brate_intermed_tbl[i] == ACELP_9k60 ) /* Bit allocation should be mapped to 8 kb/s instead of 9.6 kb/s in this case */ { i--; } core_brate = brate_intermed_tbl[i]; - if (element_mode > EVS_MONO) + if ( element_mode > EVS_MONO ) { flag_hardcoded = 0; /* use automatic and flexible ACELP bit-budget allocation */ } - if (core != ACELP_CORE && element_mode == EVS_MONO) /* needed for mode1 core switching in EVS mono */ + if ( core != ACELP_CORE && element_mode == EVS_MONO ) /* needed for mode1 core switching in EVS mono */ { flag_hardcoded = 1; } @@ -727,28 +723,28 @@ ivas_error config_acelp1( * ACELP bit allocation *-----------------------------------------------------------------*/ - if (!(coder_type == TRANSITION && tc_subfr != -1) || enc_dec == DEC) + if ( !( coder_type == TRANSITION && tc_subfr != -1 ) || enc_dec == DEC ) { /* Set the bit-budget */ - bits = (Word16)(core_brate_inp / FRAMES_PER_SEC); + bits = (Word16) ( core_brate_inp / FRAMES_PER_SEC ); - if (coder_type == TRANSITION && enc_dec == DEC && tc_call == 1) + if ( coder_type == TRANSITION && enc_dec == DEC && tc_call == 1 ) { bits += *nBits_es_Pred; /* equalize for 4th signaling bit estimated at the encoder in TC_0_192 */ } /* Subtract signalling bits */ - if (enc_dec == DEC && idchan == 1 && element_mode > EVS_MONO) + if ( enc_dec == DEC && idchan == 1 && element_mode > EVS_MONO ) { bits -= TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS; - if (tdm_LRTD_flag == 1) + if ( tdm_LRTD_flag == 1 ) { bits += STEREO_BITS_TCA; } /* subtract TBE/BWE flag */ - if (extl_brate > 0 && (extl == WB_TBE || extl == SWB_TBE || extl == FB_TBE || extl == WB_BWE || extl == SWB_BWE || extl == FB_BWE)) + if ( extl_brate > 0 && ( extl == WB_TBE || extl == SWB_TBE || extl == FB_TBE || extl == WB_BWE || extl == SWB_BWE || extl == FB_BWE ) ) { bits--; } @@ -759,7 +755,7 @@ ivas_error config_acelp1( bits -= signalling_bits; } - if (extl_brate > 0 && (extl == WB_TBE || extl == SWB_TBE || extl == FB_TBE || extl == WB_BWE || extl == SWB_BWE || extl == FB_BWE)) + if ( extl_brate > 0 && ( extl == WB_TBE || extl == SWB_TBE || extl == FB_TBE || extl == WB_BWE || extl == SWB_BWE || extl == FB_BWE ) ) { /* extension layer signalling bit is counted in the extension layer bitbudget */ bits++; @@ -769,37 +765,37 @@ ivas_error config_acelp1( * LSF Q bit-budget *-----------------------------------------------------------------*/ - if (!tdm_lp_reuse_flag || idchan == 0) + if ( !tdm_lp_reuse_flag || idchan == 0 ) { /* LSF Q bit-budget */ - acelp_cfg->lsf_bits = LSF_bits_tbl[LSF_BIT_ALLOC_IDX_fx(core_brate, coder_type)]; + acelp_cfg->lsf_bits = LSF_bits_tbl[LSF_BIT_ALLOC_IDX_fx( core_brate, coder_type )]; - if (!flag_hardcoded) + if ( !flag_hardcoded ) { - if (L_frame == L_FRAME) + if ( L_frame == L_FRAME ) { - if (element_mode == IVAS_SCE && tdm_low_rate_mode) + if ( element_mode == IVAS_SCE && tdm_low_rate_mode ) { - acelp_cfg->lsf_bits = LSF_bits_tbl[LSF_BIT_ALLOC_IDX_fx(core_brate, coder_type)]; + acelp_cfg->lsf_bits = LSF_bits_tbl[LSF_BIT_ALLOC_IDX_fx( core_brate, coder_type )]; } - else if ((total_brate < 7200 || coder_type == INACTIVE || coder_type == AUDIO) && idchan == 1) + else if ( ( total_brate < 7200 || coder_type == INACTIVE || coder_type == AUDIO ) && idchan == 1 ) { /* TD stereo, secondary channel: do nothing */ - acelp_cfg->lsf_bits = LSF_bits_tbl[LSF_BIT_ALLOC_IDX_fx(core_brate, coder_type)]; + acelp_cfg->lsf_bits = LSF_bits_tbl[LSF_BIT_ALLOC_IDX_fx( core_brate, coder_type )]; } - else if (element_mode > EVS_MONO && coder_type == AUDIO && brate_intermed_tbl[i] < ACELP_9k60) + else if ( element_mode > EVS_MONO && coder_type == AUDIO && brate_intermed_tbl[i] < ACELP_9k60 ) { /* primary channel: do nothing */ } - else if (element_mode > EVS_MONO && coder_type == AUDIO /*&& brate_intermed_tbl[i] >= ACELP_9k60*/) + else if ( element_mode > EVS_MONO && coder_type == AUDIO /*&& brate_intermed_tbl[i] >= ACELP_9k60*/ ) { acelp_cfg->lsf_bits = 42; } - else if (total_brate <= 9600 || coder_type == UNVOICED) + else if ( total_brate <= 9600 || coder_type == UNVOICED ) { acelp_cfg->lsf_bits = 31; } - else if (total_brate <= 20000) + else if ( total_brate <= 20000 ) { acelp_cfg->lsf_bits = 36; } @@ -810,16 +806,16 @@ ivas_error config_acelp1( } else /* L_frame == L_FRAME16k */ { - acelp_cfg->lsf_bits = 41; + acelp_cfg->lsf_bits = 41; } } bits -= acelp_cfg->lsf_bits; /* mid-LSF Q bit-budget */ - acelp_cfg->mid_lsf_bits = mid_LSF_bits_tbl[LSF_BIT_ALLOC_IDX_fx(core_brate, coder_type)]; + acelp_cfg->mid_lsf_bits = mid_LSF_bits_tbl[LSF_BIT_ALLOC_IDX_fx( core_brate, coder_type )]; - if (element_mode > EVS_MONO && coder_type == AUDIO /*&& brate_intermed_tbl[i] < ACELP_9k60*/) + if ( element_mode > EVS_MONO && coder_type == AUDIO /*&& brate_intermed_tbl[i] < ACELP_9k60*/ ) { acelp_cfg->mid_lsf_bits = 5; /* primary channel: do nothing */ @@ -828,18 +824,18 @@ ivas_error config_acelp1( bits -= acelp_cfg->mid_lsf_bits; } #ifdef LSF_RE_USE_SECONDARY_CHANNEL - else if (tdm_lp_reuse_flag == 1 && idchan == 1 && active_cnt != 1 ) + else if ( tdm_lp_reuse_flag == 1 && idchan == 1 && active_cnt != 1 ) { bits -= TDM_IC_LSF_PRED_BITS; } #endif /* gain Q bit-budget - part 1 */ - if ((coder_type != UNVOICED && coder_type != AUDIO && coder_type != INACTIVE && !(core_brate <= ACELP_8k00 && coder_type != TRANSITION)) || (coder_type == INACTIVE && total_brate > MAX_GSC_INACTIVE_BRATE)) + if ( ( coder_type != UNVOICED && coder_type != AUDIO && coder_type != INACTIVE && !( core_brate <= ACELP_8k00 && coder_type != TRANSITION ) ) || ( coder_type == INACTIVE && total_brate > MAX_GSC_INACTIVE_BRATE ) ) { - *nBits_es_Pred = Es_pred_bits_tbl[BIT_ALLOC_IDX_fx(core_brate, coder_type, -1, -1)]; + *nBits_es_Pred = Es_pred_bits_tbl[BIT_ALLOC_IDX_fx( core_brate, coder_type, -1, -1 )]; bits -= *nBits_es_Pred; } - else if (*uc_two_stage_flag) + else if ( *uc_two_stage_flag ) { *nBits_es_Pred = 4; bits -= *nBits_es_Pred; @@ -850,7 +846,7 @@ ivas_error config_acelp1( bits = *unbits; } - if (coder_type == TRANSITION && tc_call == 0) + if ( coder_type == TRANSITION && tc_call == 0 ) { *unbits = bits; return error; @@ -860,7 +856,7 @@ ivas_error config_acelp1( * Low-rate mode - bits are allocated in tdm_low_rate_enc() *-----------------------------------------------------------------*/ - if (element_mode == IVAS_SCE && tdm_low_rate_mode) + if ( element_mode == IVAS_SCE && tdm_low_rate_mode ) { acelp_cfg->FEC_mode = 0; acelp_cfg->ltf_mode = FULL_BAND; @@ -876,32 +872,32 @@ ivas_error config_acelp1( *-----------------------------------------------------------------*/ acelp_cfg->FEC_mode = 0; - if (core_brate >= ACELP_11k60 && (idchan == 0 || element_mode == EVS_MONO)) + if ( core_brate >= ACELP_11k60 && ( idchan == 0 || element_mode == EVS_MONO ) ) { acelp_cfg->FEC_mode = 1; - if (coder_type > UNVOICED && coder_type < AUDIO && coder_type != VOICED) + if ( coder_type > UNVOICED && coder_type < AUDIO && coder_type != VOICED ) { bits -= FEC_BITS_CLS; } - if (coder_type != TRANSITION) + if ( coder_type != TRANSITION ) { - if (total_brate >= ACELP_16k40) + if ( total_brate >= ACELP_16k40 ) { acelp_cfg->FEC_mode = 2; - if (coder_type > UNVOICED && coder_type < AUDIO) + if ( coder_type > UNVOICED && coder_type < AUDIO ) { bits -= FEC_BITS_ENR; } } - if (total_brate >= ACELP_32k) + if ( total_brate >= ACELP_32k ) { acelp_cfg->FEC_mode = 3; - if (coder_type > UNVOICED && coder_type < AUDIO) + if ( coder_type > UNVOICED && coder_type < AUDIO ) { bits -= FEC_BITS_POS; } @@ -913,28 +909,28 @@ ivas_error config_acelp1( * LP filtering of the adaptive excitation *-----------------------------------------------------------------*/ - if (idchan > 0 && element_mode > EVS_MONO) + if ( idchan > 0 && element_mode > EVS_MONO ) { acelp_cfg->ltf_mode = FULL_BAND; } - else if (coder_type == UNVOICED) + else if ( coder_type == UNVOICED ) { acelp_cfg->ltf_mode = FULL_BAND; } - else if ((coder_type == GENERIC || coder_type == TRANSITION) && core_brate < ACELP_11k60) + else if ( ( coder_type == GENERIC || coder_type == TRANSITION ) && core_brate < ACELP_11k60 ) { acelp_cfg->ltf_mode = LOW_PASS; } - else if (core_brate >= ACELP_11k60 && (coder_type != AUDIO && !(coder_type == INACTIVE && L_frame == L_FRAME))) + else if ( core_brate >= ACELP_11k60 && ( coder_type != AUDIO && !( coder_type == INACTIVE && L_frame == L_FRAME ) ) ) { - if (coder_type == INACTIVE && L_frame == L_FRAME16k && total_brate <= MAX_GSC_INACTIVE_BRATE) /* GSC Inactive @16kHz */ + if ( coder_type == INACTIVE && L_frame == L_FRAME16k && total_brate <= MAX_GSC_INACTIVE_BRATE ) /* GSC Inactive @16kHz */ { acelp_cfg->ltf_mode = FULL_BAND; } else { acelp_cfg->ltf_mode = NORMAL_OPERATION; - if (coder_type != TRANSITION) + if ( coder_type != TRANSITION ) { bits -= nb_subfr; } @@ -949,13 +945,13 @@ ivas_error config_acelp1( * UC bit-budget *-----------------------------------------------------------------*/ - if (((coder_type == UNVOICED && !(*uc_two_stage_flag)) || (coder_type == INACTIVE && core_brate <= ACELP_9k60)) && (idchan == 0 || element_mode == EVS_MONO)) + if ( ( ( coder_type == UNVOICED && !( *uc_two_stage_flag ) ) || ( coder_type == INACTIVE && core_brate <= ACELP_9k60 ) ) && ( idchan == 0 || element_mode == EVS_MONO ) ) { bits -= NBITS_NOISENESS; /* noiseness */ } - if (coder_type == UNVOICED && !(*uc_two_stage_flag)) + if ( coder_type == UNVOICED && !( *uc_two_stage_flag ) ) { - bits -= (3 * NB_SUBFR); /* tilt factor */ + bits -= ( 3 * NB_SUBFR ); /* tilt factor */ } /*-----------------------------------------------------------------* @@ -963,94 +959,94 @@ ivas_error config_acelp1( *-----------------------------------------------------------------*/ fix_first = 0; - if (coder_type == TRANSITION) + if ( coder_type == TRANSITION ) { - if (tc_call == 2) + if ( tc_call == 2 ) { fix_first = 1; } /* TC signalling */ - if (L_frame == L_FRAME) + if ( L_frame == L_FRAME ) { - if (tc_subfr == TC_0_0) + if ( tc_subfr == TC_0_0 ) { - if (enc_dec == ENC) + if ( enc_dec == ENC ) { bits -= 1; /* TC signalling */ } - if (acelp_cfg->ltf_mode == NORMAL_OPERATION) + if ( acelp_cfg->ltf_mode == NORMAL_OPERATION ) { bits -= 3; /* LP filtering flag */ } } - else if (tc_subfr == TC_0_64) + else if ( tc_subfr == TC_0_64 ) { - if (enc_dec == ENC) + if ( enc_dec == ENC ) { bits -= 4; /* TC signalling */ } - if (acelp_cfg->ltf_mode == NORMAL_OPERATION) + if ( acelp_cfg->ltf_mode == NORMAL_OPERATION ) { bits -= 3; /* LP filtering flag */ } } - else if (tc_subfr == TC_0_128) + else if ( tc_subfr == TC_0_128 ) { - if (enc_dec == ENC) + if ( enc_dec == ENC ) { bits -= 4; /* TC signalling */ } - if (acelp_cfg->ltf_mode == NORMAL_OPERATION) + if ( acelp_cfg->ltf_mode == NORMAL_OPERATION ) { bits -= 2; /* LP filtering flag */ } } - else if (tc_subfr == TC_0_192) + else if ( tc_subfr == TC_0_192 ) { - if (enc_dec == ENC) + if ( enc_dec == ENC ) { bits -= 3; /* TC signalling */ } - if (acelp_cfg->ltf_mode == NORMAL_OPERATION) + if ( acelp_cfg->ltf_mode == NORMAL_OPERATION ) { bits -= 1; /* LP filtering flag */ } } - else if (tc_subfr == L_SUBFR) + else if ( tc_subfr == L_SUBFR ) { - if (enc_dec == ENC) + if ( enc_dec == ENC ) { bits -= 3; /* TC signalling */ } - if (acelp_cfg->ltf_mode == NORMAL_OPERATION) + if ( acelp_cfg->ltf_mode == NORMAL_OPERATION ) { - bits -= (L_FRAME - tc_subfr - L_SUBFR) / L_SUBFR; /* LP filtering flag */ + bits -= ( L_FRAME - tc_subfr - L_SUBFR ) / L_SUBFR; /* LP filtering flag */ } } else { - if (enc_dec == ENC) + if ( enc_dec == ENC ) { bits -= 4; /* TC signalling */ } - if (acelp_cfg->ltf_mode == NORMAL_OPERATION) + if ( acelp_cfg->ltf_mode == NORMAL_OPERATION ) { - bits -= (L_FRAME - tc_subfr - L_SUBFR) / L_SUBFR; /* LP filtering flag */ + bits -= ( L_FRAME - tc_subfr - L_SUBFR ) / L_SUBFR; /* LP filtering flag */ } } } else /* L_frame == L_FRAME16k */ { - if (enc_dec == ENC) + if ( enc_dec == ENC ) { - if (tc_subfr <= 2 * L_SUBFR) + if ( tc_subfr <= 2 * L_SUBFR ) { bits -= 2; /* TC signalling */ } @@ -1060,11 +1056,11 @@ ivas_error config_acelp1( } } - bits -= (L_FRAME16k - tc_subfr - L_SUBFR) / L_SUBFR; /* LP filtering flag */ + bits -= ( L_FRAME16k - tc_subfr - L_SUBFR ) / L_SUBFR; /* LP filtering flag */ } /* glottal-shape codebook bits */ - bits -= (3 + 6 + 1 + 3); + bits -= ( 3 + 6 + 1 + 3 ); } /*-----------------------------------------------------------------* @@ -1073,83 +1069,83 @@ ivas_error config_acelp1( acelp_cfg->fcb_mode = 0; - if (element_mode == IVAS_CPE_TD && tdm_low_rate_mode == 1 && coder_type != INACTIVE && coder_type != UNVOICED) /* GENERIC low rate mode for secondary channel */ + if ( element_mode == IVAS_CPE_TD && tdm_low_rate_mode == 1 && coder_type != INACTIVE && coder_type != UNVOICED ) /* GENERIC low rate mode for secondary channel */ { - set16_fx(acelp_cfg->pitch_bits, 0, NB_SUBFR16k); - set16_fx(acelp_cfg->gains_mode, 0, NB_SUBFR16k); + set16_fx( acelp_cfg->pitch_bits, 0, NB_SUBFR16k ); + set16_fx( acelp_cfg->gains_mode, 0, NB_SUBFR16k ); - for (i = 0; i < 2; i++) + for ( i = 0; i < 2; i++ ) { acelp_cfg->pitch_bits[i] = 0; - if (tdm_Pitch_reuse_flag == 0) + if ( tdm_Pitch_reuse_flag == 0 ) { - acelp_cfg->pitch_bits[i] = ACB_bits_tbl[BIT_ALLOC_IDX_fx(ACELP_7k20, GENERIC, 2 * i * L_SUBFR, TC_SUBFR2IDX_fx(tc_subfr))]; + acelp_cfg->pitch_bits[i] = ACB_bits_tbl[BIT_ALLOC_IDX_fx( ACELP_7k20, GENERIC, 2 * i * L_SUBFR, TC_SUBFR2IDX_fx( tc_subfr ) )]; bits -= acelp_cfg->pitch_bits[i]; } - acelp_cfg->gains_mode[i] = gain_bits_tbl[BIT_ALLOC_IDX_fx(ACELP_7k20, GENERIC, i * L_SUBFR, TC_SUBFR2IDX_fx(tc_subfr))]; + acelp_cfg->gains_mode[i] = gain_bits_tbl[BIT_ALLOC_IDX_fx( ACELP_7k20, GENERIC, i * L_SUBFR, TC_SUBFR2IDX_fx( tc_subfr ) )]; bits -= acelp_cfg->gains_mode[i]; } acelp_cfg->fcb_mode = 1; #ifdef DEBUGGING - if (bits >= 55) + if ( bits >= 55 ) { - printf("too much bits -> %d, LPC = %d and pitch = %d\n", bits, tdm_lp_reuse_flag, tdm_Pitch_reuse_flag); - acelp_FCB_allocator(&bits, acelp_cfg->fixed_cdk_index, 2, 2 * L_SUBFR, GENERIC, -1, 0); + printf( "too much bits -> %d, LPC = %d and pitch = %d\n", bits, tdm_lp_reuse_flag, tdm_Pitch_reuse_flag ); + acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, 2, 2 * L_SUBFR, GENERIC, -1, 0 ); } else #endif - if (bits >= 16) - { - acelp_FCB_allocator(&bits, acelp_cfg->fixed_cdk_index, 2, 2 * L_SUBFR, GENERIC, -1, 0); - } - else - { - acelp_FCB_allocator(&bits, acelp_cfg->fixed_cdk_index, 2, 2 * L_SUBFR, GENERIC, -1, 0); - acelp_cfg->fixed_cdk_index[1] = -1; - } + if ( bits >= 16 ) + { + acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, 2, 2 * L_SUBFR, GENERIC, -1, 0 ); + } + else + { + acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, 2, 2 * L_SUBFR, GENERIC, -1, 0 ); + acelp_cfg->fixed_cdk_index[1] = -1; + } acelp_cfg->fixed_cdk_index[2] = -1; acelp_cfg->fixed_cdk_index[3] = -1; } - else if ((coder_type != INACTIVE && nb_subfr == NB_SUBFR && coder_type != AUDIO) || (nb_subfr == NB_SUBFR16k && (total_brate > MAX_GSC_INACTIVE_BRATE || coder_type != INACTIVE)) || core == HQ_CORE) + else if ( ( coder_type != INACTIVE && nb_subfr == NB_SUBFR && coder_type != AUDIO ) || ( nb_subfr == NB_SUBFR16k && ( total_brate > MAX_GSC_INACTIVE_BRATE || coder_type != INACTIVE ) ) || core == HQ_CORE ) { /* pitch Q & gain Q bit-budget - part 2*/ - for (i = 0; i < nb_subfr; i++) + for ( i = 0; i < nb_subfr; i++ ) { - if (L_frame == L_FRAME) + if ( L_frame == L_FRAME ) { - if (tdm_Pitch_reuse_flag == 1 && idchan == 1) + if ( tdm_Pitch_reuse_flag == 1 && idchan == 1 ) { acelp_cfg->pitch_bits[i] = 0; } else { - acelp_cfg->pitch_bits[i] = ACB_bits_tbl[BIT_ALLOC_IDX_fx(core_brate, coder_type, i * L_SUBFR, TC_SUBFR2IDX_fx(tc_subfr))]; + acelp_cfg->pitch_bits[i] = ACB_bits_tbl[BIT_ALLOC_IDX_fx( core_brate, coder_type, i * L_SUBFR, TC_SUBFR2IDX_fx( tc_subfr ) )]; } - acelp_cfg->gains_mode[i] = gain_bits_tbl[BIT_ALLOC_IDX_fx(core_brate, coder_type_sw, i * L_SUBFR, TC_SUBFR2IDX_fx(tc_subfr))]; + acelp_cfg->gains_mode[i] = gain_bits_tbl[BIT_ALLOC_IDX_fx( core_brate, coder_type_sw, i * L_SUBFR, TC_SUBFR2IDX_fx( tc_subfr ) )]; } else /* L_frame == L_FRAME16k */ { - if (tdm_Pitch_reuse_flag == 1 && idchan == 1) + if ( tdm_Pitch_reuse_flag == 1 && idchan == 1 ) { acelp_cfg->pitch_bits[i] = 0; } else { - acelp_cfg->pitch_bits[i] = ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(core_brate, coder_type, i * L_SUBFR, TC_SUBFR2IDX_16KHZ_fx(tc_subfr))]; + acelp_cfg->pitch_bits[i] = ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx( core_brate, coder_type, i * L_SUBFR, TC_SUBFR2IDX_16KHZ_fx( tc_subfr ) )]; } - acelp_cfg->gains_mode[i] = gain_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(core_brate, coder_type_sw, i * L_SUBFR, TC_SUBFR2IDX_16KHZ_fx(tc_subfr))]; + acelp_cfg->gains_mode[i] = gain_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx( core_brate, coder_type_sw, i * L_SUBFR, TC_SUBFR2IDX_16KHZ_fx( tc_subfr ) )]; } bits -= acelp_cfg->pitch_bits[i]; - if (coder_type == INACTIVE && acelp_cfg->gains_mode[i] == 6 /* VQ vs. SQ threshold @32 kbps */) + if ( coder_type == INACTIVE && acelp_cfg->gains_mode[i] == 6 /* VQ vs. SQ threshold @32 kbps */ ) { bits -= 5; } else { - if (*uc_two_stage_flag == 1) + if ( *uc_two_stage_flag == 1 ) { acelp_cfg->gains_mode[i] = 7; } @@ -1159,64 +1155,64 @@ ivas_error config_acelp1( } /* algebraic codebook bit-budget */ - if (flag_hardcoded || (core_brate_inp >= MIN_BRATE_AVQ_EXC && coder_type != INACTIVE) || (total_brate > MAX_GSC_INACTIVE_BRATE && coder_type == INACTIVE)) + if ( flag_hardcoded || ( core_brate_inp >= MIN_BRATE_AVQ_EXC && coder_type != INACTIVE ) || ( total_brate > MAX_GSC_INACTIVE_BRATE && coder_type == INACTIVE ) ) { - for (i = 0; i < nb_subfr; i++) + for ( i = 0; i < nb_subfr; i++ ) { - if (L_frame == L_FRAME) + if ( L_frame == L_FRAME ) { - acelp_cfg->fixed_cdk_index[i] = FCB_bits_tbl[BIT_ALLOC_IDX_fx(core_brate, coder_type, i * L_SUBFR, TC_SUBFR2IDX_fx(tc_subfr))]; + acelp_cfg->fixed_cdk_index[i] = FCB_bits_tbl[BIT_ALLOC_IDX_fx( core_brate, coder_type, i * L_SUBFR, TC_SUBFR2IDX_fx( tc_subfr ) )]; } else /* L_frame == L_FRAME16k */ { - acelp_cfg->fixed_cdk_index[i] = FCB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(core_brate, coder_type, i * L_SUBFR, TC_SUBFR2IDX_16KHZ_fx(tc_subfr))]; + acelp_cfg->fixed_cdk_index[i] = FCB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx( core_brate, coder_type, i * L_SUBFR, TC_SUBFR2IDX_16KHZ_fx( tc_subfr ) )]; } bits -= acelp_cfg->fixed_cdk_index[i]; } } - else if (!(coder_type == UNVOICED && tdm_low_rate_mode == 1 && element_mode == IVAS_CPE_TD)) + else if ( !( coder_type == UNVOICED && tdm_low_rate_mode == 1 && element_mode == IVAS_CPE_TD ) ) { - if (coder_type == UNVOICED && !(*uc_two_stage_flag)) + if ( coder_type == UNVOICED && !( *uc_two_stage_flag ) ) { i = bits / NB_SUBFR; - if (i % 2 == 0) + if ( i % 2 == 0 ) { i--; /* must be odd */ } - i = s_min(i, 13); + i = s_min( i, 13 ); #ifdef DEBUG_MODE_TD - if (i < 0) - IVAS_ERROR(IVAS_ERR_INTERNAL, "ERROR::: UC negative index should not happen at frame %d\n"); + if ( i < 0 ) + IVAS_ERROR( IVAS_ERR_INTERNAL, "ERROR::: UC negative index should not happen at frame %d\n" ); #endif - i = s_max(i, 0); /* If i == 0-> random noise generator will be used as FCB */ - set16_fx(acelp_cfg->fixed_cdk_index, i, NB_SUBFR); - bits -= (i * NB_SUBFR); + i = s_max( i, 0 ); /* If i == 0-> random noise generator will be used as FCB */ + set16_fx( acelp_cfg->fixed_cdk_index, i, NB_SUBFR ); + bits -= ( i * NB_SUBFR ); } else { acelp_cfg->fcb_mode = 1; - if (element_mode == IVAS_CPE_TD) + if ( element_mode == IVAS_CPE_TD ) { - if (bits >= ACELP_FIXED_CDK_BITS(0) * (nb_subfr)) /* enough bits for all fcb */ + if ( bits >= ACELP_FIXED_CDK_BITS( 0 ) * ( nb_subfr ) ) /* enough bits for all fcb */ { - acelp_FCB_allocator(&bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first); + acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first ); } - else if (bits >= ACELP_FIXED_CDK_BITS(0) * (nb_subfr - 1)) + else if ( bits >= ACELP_FIXED_CDK_BITS( 0 ) * ( nb_subfr - 1 ) ) { - acelp_FCB_allocator(&bits, acelp_cfg->fixed_cdk_index, nb_subfr - 1, L_SUBFR, coder_type, tc_subfr, fix_first); + acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, nb_subfr - 1, L_SUBFR, coder_type, tc_subfr, fix_first ); acelp_cfg->fixed_cdk_index[3] = -1; } - else if (bits >= ACELP_FIXED_CDK_BITS(0) * (nb_subfr - 2)) + else if ( bits >= ACELP_FIXED_CDK_BITS( 0 ) * ( nb_subfr - 2 ) ) { - acelp_FCB_allocator(&bits, acelp_cfg->fixed_cdk_index, nb_subfr - 2, L_SUBFR, coder_type, tc_subfr, fix_first); + acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, nb_subfr - 2, L_SUBFR, coder_type, tc_subfr, fix_first ); acelp_cfg->fixed_cdk_index[2] = acelp_cfg->fixed_cdk_index[1]; acelp_cfg->fixed_cdk_index[1] = -1; acelp_cfg->fixed_cdk_index[3] = -1; } - else if (bits >= ACELP_FIXED_CDK_BITS(0)) + else if ( bits >= ACELP_FIXED_CDK_BITS( 0 ) ) { - acelp_FCB_allocator(&bits, acelp_cfg->fixed_cdk_index, 1, L_SUBFR, coder_type, tc_subfr, fix_first); + acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, 1, L_SUBFR, coder_type, tc_subfr, fix_first ); acelp_cfg->fixed_cdk_index[1] = acelp_cfg->fixed_cdk_index[0]; acelp_cfg->fixed_cdk_index[0] = -1; acelp_cfg->fixed_cdk_index[2] = -1; @@ -1224,8 +1220,8 @@ ivas_error config_acelp1( } else /* No FCB */ { -#if defined DEBUGGING - IVAS_ERROR(IVAS_ERR_INTERNAL, "WARNING!!!, No bit allocated to FCB, check frame %d\n"); +#if defined DEBUGGING + IVAS_ERROR( IVAS_ERR_INTERNAL, "WARNING!!!, No bit allocated to FCB, check frame %d\n" ); #endif acelp_cfg->fixed_cdk_index[0] = -1; acelp_cfg->fixed_cdk_index[1] = -1; @@ -1233,26 +1229,26 @@ ivas_error config_acelp1( acelp_cfg->fixed_cdk_index[3] = -1; } } - else if (element_mode != IVAS_CPE_TD && GSC_IVAS_mode > 0 && L_frame == L_FRAME16k) + else if ( element_mode != IVAS_CPE_TD && GSC_IVAS_mode > 0 && L_frame == L_FRAME16k ) { bits = 100; /* 9 kbps for fcb */ - acelp_FCB_allocator(&bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first); + acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first ); } else { - acelp_FCB_allocator(&bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first); + acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first ); } } } /* AVQ codebook */ - if ((core_brate_inp >= MIN_BRATE_AVQ_EXC && coder_type != INACTIVE) || (total_brate > MAX_GSC_INACTIVE_BRATE && coder_type == INACTIVE)) + if ( ( core_brate_inp >= MIN_BRATE_AVQ_EXC && coder_type != INACTIVE ) || ( total_brate > MAX_GSC_INACTIVE_BRATE && coder_type == INACTIVE ) ) { - for (i = 0; i < nb_subfr; i++) + for ( i = 0; i < nb_subfr; i++ ) { - if (flag_hardcoded) + if ( flag_hardcoded ) { - acelp_cfg->AVQ_cdk_bits[i] = AVQ_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(core_brate, coder_type, i * L_SUBFR, TC_SUBFR2IDX_16KHZ_fx(tc_subfr))]; + acelp_cfg->AVQ_cdk_bits[i] = AVQ_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx( core_brate, coder_type, i * L_SUBFR, TC_SUBFR2IDX_16KHZ_fx( tc_subfr ) )]; { bits -= acelp_cfg->AVQ_cdk_bits[i]; } @@ -1261,18 +1257,18 @@ ivas_error config_acelp1( bits -= G_AVQ_BITS; } - if (core_brate_inp >= MIN_BRATE_AVQ_EXC && core_brate_inp <= MAX_BRATE_AVQ_EXC_TD && coder_type == GENERIC) + if ( core_brate_inp >= MIN_BRATE_AVQ_EXC && core_brate_inp <= MAX_BRATE_AVQ_EXC_TD && coder_type == GENERIC ) { /* harm. flag ACELP AVQ */ bits--; } - if (!flag_hardcoded) + if ( !flag_hardcoded ) { Word16 bit_tmp; bit_tmp = bits / nb_subfr; - set16_fx(acelp_cfg->AVQ_cdk_bits, bit_tmp, nb_subfr); + set16_fx( acelp_cfg->AVQ_cdk_bits, bit_tmp, nb_subfr ); bits -= bit_tmp * nb_subfr; bit_tmp = bits % nb_subfr; @@ -1281,33 +1277,33 @@ ivas_error config_acelp1( } } } - else if ((coder_type == UNVOICED && tdm_low_rate_mode == 1 && element_mode == IVAS_CPE_TD) || ((coder_type == INACTIVE || coder_type == AUDIO) && nb_subfr == NB_SUBFR) || (coder_type == INACTIVE && total_brate <= MAX_GSC_INACTIVE_BRATE)) + else if ( ( coder_type == UNVOICED && tdm_low_rate_mode == 1 && element_mode == IVAS_CPE_TD ) || ( ( coder_type == INACTIVE || coder_type == AUDIO ) && nb_subfr == NB_SUBFR ) || ( coder_type == INACTIVE && total_brate <= MAX_GSC_INACTIVE_BRATE ) ) { Word32 Local_BR, Pitch_BR; Word16 Pitch_CT; /* as defined at the beginning of [enc,dec]_pit_exc() */ - if (GSC_IVAS_mode > 0 && (GSC_noisy_speech || core_brate > GSC_H_RATE_STG)) + if ( GSC_IVAS_mode > 0 && ( GSC_noisy_speech || core_brate > GSC_H_RATE_STG ) ) { Local_BR = ACELP_8k00; Pitch_CT = GENERIC; Pitch_BR = ACELP_8k00; - if (L_frame == L_FRAME16k) + if ( L_frame == L_FRAME16k ) { Local_BR = ACELP_14k80; - if (GSC_IVAS_mode > 0 && core_brate < IVAS_24k4) + if ( GSC_IVAS_mode > 0 && core_brate < IVAS_24k4 ) { Local_BR = ACELP_9k60; } Pitch_BR = core_brate; } } - else if (GSC_noisy_speech) + else if ( GSC_noisy_speech ) { Local_BR = ACELP_7k20; Pitch_CT = GENERIC; Pitch_BR = ACELP_7k20; - if (L_frame == L_FRAME16k) + if ( L_frame == L_FRAME16k ) { Pitch_BR = core_brate; } @@ -1318,30 +1314,30 @@ ivas_error config_acelp1( Pitch_CT = AUDIO; Pitch_BR = core_brate; - if (L_frame == L_FRAME16k) + if ( L_frame == L_FRAME16k ) { Local_BR = ACELP_13k20; Pitch_CT = GENERIC; } } - for (i = 0; i < nb_subfr; i++) + for ( i = 0; i < nb_subfr; i++ ) { - if (L_frame == L_FRAME16k) + if ( L_frame == L_FRAME16k ) { - acelp_cfg->pitch_bits[i] = ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(Pitch_BR, Pitch_CT, i * L_SUBFR, 0)]; - acelp_cfg->fixed_cdk_index[i] = FCB_bits_tbl[BIT_ALLOC_IDX_fx(Local_BR, LOCAL_CT, i * L_SUBFR, 0)]; + acelp_cfg->pitch_bits[i] = ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx( Pitch_BR, Pitch_CT, i * L_SUBFR, 0 )]; + acelp_cfg->fixed_cdk_index[i] = FCB_bits_tbl[BIT_ALLOC_IDX_fx( Local_BR, LOCAL_CT, i * L_SUBFR, 0 )]; } else { - acelp_cfg->pitch_bits[i] = ACB_bits_tbl[BIT_ALLOC_IDX_fx(Pitch_BR, Pitch_CT, i * L_SUBFR, 0)]; - acelp_cfg->fixed_cdk_index[i] = FCB_bits_tbl[BIT_ALLOC_IDX_fx(Local_BR, LOCAL_CT, i * L_SUBFR, 0)]; - acelp_cfg->gains_mode[i] = gain_bits_tbl[BIT_ALLOC_IDX_fx(ACELP_7k20, LOCAL_CT, i * L_SUBFR, 0)]; + acelp_cfg->pitch_bits[i] = ACB_bits_tbl[BIT_ALLOC_IDX_fx( Pitch_BR, Pitch_CT, i * L_SUBFR, 0 )]; + acelp_cfg->fixed_cdk_index[i] = FCB_bits_tbl[BIT_ALLOC_IDX_fx( Local_BR, LOCAL_CT, i * L_SUBFR, 0 )]; + acelp_cfg->gains_mode[i] = gain_bits_tbl[BIT_ALLOC_IDX_fx( ACELP_7k20, LOCAL_CT, i * L_SUBFR, 0 )]; } } } - if (coder_type == TRANSITION && (tc_call == 1 && tc_subfr == 0 && L_frame == L_FRAME)) + if ( coder_type == TRANSITION && ( tc_call == 1 && tc_subfr == 0 && L_frame == L_FRAME ) ) { return error; } @@ -1352,16 +1348,16 @@ ivas_error config_acelp1( acelp_cfg->ubits = 0; /* these bits could be reused for something else */ - if (flag_hardcoded && core_brate != PPP_NELP_2k80) + if ( flag_hardcoded && core_brate != PPP_NELP_2k80 ) { /* unused bits */ - if (coder_type == AUDIO || (coder_type == INACTIVE && core_brate <= ACELP_24k40)) + if ( coder_type == AUDIO || ( coder_type == INACTIVE && core_brate <= ACELP_24k40 ) ) { acelp_cfg->ubits = 0; } - else if (L_frame == L_FRAME) + else if ( L_frame == L_FRAME ) { - acelp_cfg->ubits = reserved_bits_tbl[BIT_ALLOC_IDX_fx(core_brate, coder_type, -1, TC_SUBFR2IDX_fx(tc_subfr))]; + acelp_cfg->ubits = reserved_bits_tbl[BIT_ALLOC_IDX_fx( core_brate, coder_type, -1, TC_SUBFR2IDX_fx( tc_subfr ) )]; } else { @@ -1372,24 +1368,24 @@ ivas_error config_acelp1( } /* sanity check */ - if ((coder_type != INACTIVE && nb_subfr == NB_SUBFR && coder_type != AUDIO) || nb_subfr == NB_SUBFR16k) + if ( ( coder_type != INACTIVE && nb_subfr == NB_SUBFR && coder_type != AUDIO ) || nb_subfr == NB_SUBFR16k ) { - if ((L_frame == L_FRAME16k && coder_type == INACTIVE && total_brate <= MAX_GSC_INACTIVE_BRATE) || (GSC_IVAS_mode > 0 && L_frame == L_FRAME16k)) /* GSC Inactive @16kHz */ + if ( ( L_frame == L_FRAME16k && coder_type == INACTIVE && total_brate <= MAX_GSC_INACTIVE_BRATE ) || ( GSC_IVAS_mode > 0 && L_frame == L_FRAME16k ) ) /* GSC Inactive @16kHz */ { acelp_cfg->ubits = 0; } - else if (flag_hardcoded && core == ACELP_CORE && bits != 0) + else if ( flag_hardcoded && core == ACELP_CORE && bits != 0 ) { -#if defined DEBUGGING - IVAS_ERROR(IVAS_ERR_INTERNAL, "ERROR: bit-budget incorrect (%d bits) in frame %d.\n", (Word32)bits); +#if defined DEBUGGING + IVAS_ERROR( IVAS_ERR_INTERNAL, "ERROR: bit-budget incorrect (%d bits) in frame %d.\n", (Word32) bits ); #endif } - else if (bits > 0 && !(coder_type == UNVOICED && tdm_low_rate_mode == 1 && element_mode == IVAS_CPE_TD)) + else if ( bits > 0 && !( coder_type == UNVOICED && tdm_low_rate_mode == 1 && element_mode == IVAS_CPE_TD ) ) { - if (idchan > 0 && element_mode == IVAS_CPE_TD) + if ( idchan > 0 && element_mode == IVAS_CPE_TD ) { -#ifdef LSF_RE_USE_SECONDARY_CHANNEL - if (!tdm_lp_reuse_flag) +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + if ( !tdm_lp_reuse_flag ) { acelp_cfg->lsf_bits += bits; /* increase LSF Q bits */ bits = 0; @@ -1397,71 +1393,71 @@ ivas_error config_acelp1( else { Word16 nb_prm = 4; - if (tdm_low_rate_mode == 1) + if ( tdm_low_rate_mode == 1 ) { nb_prm = 2; } /* First add remaining bits on gains */ - bits -= allocate_unused(core_brate, coder_type, bits, nb_prm, 0, GAINSPRM, acelp_cfg->gains_mode); + bits -= allocate_unused( core_brate, coder_type, bits, nb_prm, 0, GAINSPRM, acelp_cfg->gains_mode ); /* Then, Increase pitch bit budget */ - if (tdm_Pitch_reuse_flag == 0 && bits > 0) + if ( tdm_Pitch_reuse_flag == 0 && bits > 0 ) { - bits -= allocate_unused(core_brate, coder_type, bits, nb_prm, 0, PITCHPRM, acelp_cfg->pitch_bits); + bits -= allocate_unused( core_brate, coder_type, bits, nb_prm, 0, PITCHPRM, acelp_cfg->pitch_bits ); } /* Increase mid-lsf bit budget */ - if (tdm_lp_reuse_flag == 0 && bits > 0) + if ( tdm_lp_reuse_flag == 0 && bits > 0 ) { - bits -= allocate_unused(core_brate, coder_type, bits, 1, 0, MID_LSFSPRM, &acelp_cfg->mid_lsf_bits); - bits -= allocate_unused(core_brate, coder_type, bits, 1, 0, LSFPRM, &acelp_cfg->lsf_bits); + bits -= allocate_unused( core_brate, coder_type, bits, 1, 0, MID_LSFSPRM, &acelp_cfg->mid_lsf_bits ); + bits -= allocate_unused( core_brate, coder_type, bits, 1, 0, LSFPRM, &acelp_cfg->lsf_bits ); } } #else Word16 nb_prm = 4; - if (tdm_low_rate_mode == 1) + if ( tdm_low_rate_mode == 1 ) { nb_prm = 2; } /* First add remaining bits on gains */ - if (!(*uc_two_stage_flag)) + if ( !( *uc_two_stage_flag ) ) { - bits -= allocate_unused(core_brate, coder_type, bits, nb_prm, 0, GAINSPRM, acelp_cfg->gains_mode); + bits -= allocate_unused( core_brate, coder_type, bits, nb_prm, 0, GAINSPRM, acelp_cfg->gains_mode ); } /* Then, Increase pitch bit budget */ - if (tdm_Pitch_reuse_flag == 0 && bits > 0) + if ( tdm_Pitch_reuse_flag == 0 && bits > 0 ) { - bits -= allocate_unused(core_brate, coder_type, bits, nb_prm, 0, PITCHPRM, acelp_cfg->pitch_bits); + bits -= allocate_unused( core_brate, coder_type, bits, nb_prm, 0, PITCHPRM, acelp_cfg->pitch_bits ); } /* Increase mid-lsf bit budget */ - if (tdm_lp_reuse_flag == 0 && bits > 0) + if ( tdm_lp_reuse_flag == 0 && bits > 0 ) { - bits -= allocate_unused(core_brate, coder_type, bits, 1, 0, MID_LSFSPRM, &acelp_cfg->mid_lsf_bits); - bits -= allocate_unused(core_brate, coder_type, bits, 1, 0, LSFPRM, &acelp_cfg->lsf_bits); + bits -= allocate_unused( core_brate, coder_type, bits, 1, 0, MID_LSFSPRM, &acelp_cfg->mid_lsf_bits ); + bits -= allocate_unused( core_brate, coder_type, bits, 1, 0, LSFPRM, &acelp_cfg->lsf_bits ); } #endif -#if defined DEBUGGING - if (idchan > 0 && bits > 0 && (coder_type > UNVOICED || tdm_low_rate_mode == 0)) +#if defined DEBUGGING + if ( idchan > 0 && bits > 0 && ( coder_type > UNVOICED || tdm_low_rate_mode == 0 ) ) { - IVAS_ERROR(IVAS_ERR_INTERNAL, "WARNING !! Unused bits in secondary channel at frame %d\n"); + IVAS_ERROR( IVAS_ERR_INTERNAL, "WARNING !! Unused bits in secondary channel at frame %d\n" ); } #endif } - else if (core == ACELP_CORE && coder_type >= UNVOICED && coder_type <= GENERIC && L_frame == L_FRAME) + else if ( core == ACELP_CORE && coder_type >= UNVOICED && coder_type <= GENERIC && L_frame == L_FRAME ) { acelp_cfg->lsf_bits += bits; /* increase LSF Q bits */ - if (acelp_cfg->lsf_bits > 46) + if ( acelp_cfg->lsf_bits > 46 ) { acelp_cfg->ubits = acelp_cfg->lsf_bits - 46; acelp_cfg->lsf_bits = 46; } - else if (acelp_cfg->lsf_bits > 42 && L_frame == L_FRAME) + else if ( acelp_cfg->lsf_bits > 42 && L_frame == L_FRAME ) { acelp_cfg->ubits = acelp_cfg->lsf_bits - 42; acelp_cfg->lsf_bits = 42; @@ -1472,10 +1468,10 @@ ivas_error config_acelp1( acelp_cfg->ubits = bits; } } - else if (bits < 0 && !(coder_type == UNVOICED && tdm_low_rate_mode == 1 && element_mode == IVAS_CPE_TD)) + else if ( bits < 0 && !( coder_type == UNVOICED && tdm_low_rate_mode == 1 && element_mode == IVAS_CPE_TD ) ) { -#if defined DEBUGGING - IVAS_ERROR(IVAS_ERR_INTERNAL, "ERROR: bit-budget incorrect (%d bits) in frame %d.\n", (Word32)bits); +#if defined DEBUGGING + IVAS_ERROR( IVAS_ERR_INTERNAL, "ERROR: bit-budget incorrect (%d bits) in frame %d.\n", (Word32) bits ); #endif } } @@ -1496,75 +1492,75 @@ static Word16 allocate_unused( const Word16 nb_prm, const Word16 subfr, const Word16 prm_type, - Word16* prm_bit_mode) + Word16 *prm_bit_mode ) { Word16 max_bit_per_pos = 0, bit_added = 0; - //PMT("Not floating point computation, but fixed point operator are still missing ") + // PMT("Not floating point computation, but fixed point operator are still missing ") - if (prm_type == GAINSPRM) + if ( prm_type == GAINSPRM ) { max_bit_per_pos = 6; - if (core_brate > ACELP_8k00) + if ( core_brate > ACELP_8k00 ) { max_bit_per_pos = 7; } - else if (coder_type != UNVOICED) + else if ( coder_type != UNVOICED ) { - if (subfr >= 1) + if ( subfr >= 1 ) { max_bit_per_pos = 7; } - else if (subfr == 0) + else if ( subfr == 0 ) { max_bit_per_pos = 8; } } - else if (coder_type == UNVOICED) + else if ( coder_type == UNVOICED ) { max_bit_per_pos = 9; /* No real limit on UC gain bit budget of the secondary channel */ } } - else if (prm_type == PITCHPRM) + else if ( prm_type == PITCHPRM ) { max_bit_per_pos = 6; - if (subfr == 0 || subfr == 2 || nb_prm == 2) + if ( subfr == 0 || subfr == 2 || nb_prm == 2 ) { max_bit_per_pos = 10; } - if (coder_type == UNVOICED) + if ( coder_type == UNVOICED ) { max_bit_per_pos = 0; /* Should not allocate bits in case of unvoiced coder type */ } } - else if (prm_type == MID_LSFSPRM) + else if ( prm_type == MID_LSFSPRM ) { max_bit_per_pos = 5; } - else if (prm_type == LSFPRM) + else if ( prm_type == LSFPRM ) { max_bit_per_pos = 42; } else { #ifdef DEBUG_MODE_TD - IVAS_ERROR(IVAS_ERR_WRONG_MODE, "unknown mode in bit_alloc.c"); + IVAS_ERROR( IVAS_ERR_WRONG_MODE, "unknown mode in bit_alloc.c" ); #endif } - max_bit_per_pos = s_min(unused_bits, max_bit_per_pos - prm_bit_mode[subfr]); - if (max_bit_per_pos < 0) + max_bit_per_pos = s_min( unused_bits, max_bit_per_pos - prm_bit_mode[subfr] ); + if ( max_bit_per_pos < 0 ) { return 0; } - else if (max_bit_per_pos >= 0 && subfr == (nb_prm - 1)) + else if ( max_bit_per_pos >= 0 && subfr == ( nb_prm - 1 ) ) { prm_bit_mode[subfr] += max_bit_per_pos; } else { prm_bit_mode[subfr] += max_bit_per_pos; - bit_added += allocate_unused(core_brate, coder_type, unused_bits - max_bit_per_pos, nb_prm, subfr + 1, prm_type, &prm_bit_mode[0]); + bit_added += allocate_unused( core_brate, coder_type, unused_bits - max_bit_per_pos, nb_prm, subfr + 1, prm_type, &prm_bit_mode[0] ); } return bit_added + max_bit_per_pos; @@ -1577,7 +1573,7 @@ static Word16 allocate_unused( * set ACELP@16kHz flag *--------------------------------------------------------------------*/ - /*! r: ACELP16k flag */ +/*! r: ACELP16k flag */ #ifdef IVAS_FLOAT_FIXED Word16 set_ACELP_flag( const Word16 element_mode, /* i : element mode */ @@ -1654,15 +1650,15 @@ Word16 set_ACELP_flag( const Word16 cng_type /* i : CNG type */ ) { - //PMT("Not floating point computation, but fixed point operator are still missing ") - if (element_mode == IVAS_CPE_DFT && idchan == 0 && total_brate <= SID_2k40 && bwidth == WB && cng_type == LP_CNG) + // PMT("Not floating point computation, but fixed point operator are still missing ") + if ( element_mode == IVAS_CPE_DFT && idchan == 0 && total_brate <= SID_2k40 && bwidth == WB && cng_type == LP_CNG ) { return 1; } - else if (element_mode == IVAS_CPE_TD) + else if ( element_mode == IVAS_CPE_TD ) { - if (element_brate >= IVAS_24k4 && idchan == 0 && (tdm_LRTD_flag == 0 || element_brate > IVAS_24k4)) + if ( element_brate >= IVAS_24k4 && idchan == 0 && ( tdm_LRTD_flag == 0 || element_brate > IVAS_24k4 ) ) { return 1; } @@ -1671,9 +1667,9 @@ Word16 set_ACELP_flag( return 0; } } - else if (element_mode == IVAS_CPE_DFT) + else if ( element_mode == IVAS_CPE_DFT ) { - if (element_brate >= IVAS_24k4) + if ( element_brate >= IVAS_24k4 ) { return 1; } @@ -1682,9 +1678,9 @@ Word16 set_ACELP_flag( return 0; } } - else if (element_mode == IVAS_SCE) + else if ( element_mode == IVAS_SCE ) { - if (element_brate >= SCE_CORE_16k_LOW_LIMIT) + if ( element_brate >= SCE_CORE_16k_LOW_LIMIT ) { return 1; } @@ -1693,7 +1689,7 @@ Word16 set_ACELP_flag( return 0; } } - else if (total_brate >= ACELP_16k_LOW_LIMIT) /* EVS_MONO */ + else if ( total_brate >= ACELP_16k_LOW_LIMIT ) /* EVS_MONO */ { return 1; } @@ -1710,7 +1706,7 @@ Word16 set_ACELP_flag( * set ACELP@16kHz flag *--------------------------------------------------------------------*/ - /*! r: ACELP16k flag */ +/*! r: ACELP16k flag */ #ifdef IVAS_FLOAT_FIXED Word16 set_ACELP_flag_IVAS( const Word16 element_mode, /* i : element mode */ @@ -1776,4 +1772,4 @@ Word16 set_ACELP_flag_IVAS( } } #endif -/*#endif IVAS_CODE*/ \ No newline at end of file +/*#endif IVAS_CODE*/ diff --git a/lib_com/bitstream.c b/lib_com/bitstream.c index 0998a71ff..47c30f497 100644 --- a/lib_com/bitstream.c +++ b/lib_com/bitstream.c @@ -561,273 +561,273 @@ int16_t get_ivas_max_num_indices( } Word16 get_ivas_max_num_indices_fx( - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const Word32 ivas_total_brate /* i : IVAS total bitrate */ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const Word32 ivas_total_brate /* i : IVAS total bitrate */ ) { - IF(EQ_16(ivas_format, STEREO_FORMAT)) - { - IF(LE_32(ivas_total_brate, IVAS_16k4)) - { - return 300; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_24k4)) - { - return 400; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_32k)) - { - return 450; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_48k)) - { - return 650; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_80k)) - { - return 750; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_128k)) - { - return 850; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_192k)) - { - return 950; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_256k)) - { - return 1350; - } - ELSE - { - return 1650; - } - } - ELSE IF(EQ_16(ivas_format, ISM_FORMAT) || EQ_16(ivas_format, MONO_FORMAT)) - { - IF(LE_32(ivas_total_brate, IVAS_16k4)) - { - return 250; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_24k4)) - { - return 350; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_32k)) - { - return 450; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_48k)) - { - return 550; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_64k)) - { - return 620; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_80k)) - { - return 670; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_96k)) - { - return 780; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_128k)) - { - return 880; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_192k)) - { - return 950; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_256k)) - { - return 1100; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_384k)) - { - return 1300; - } - ELSE - { - return 1650; - } - } - ELSE IF(EQ_16(ivas_format, SBA_FORMAT) || EQ_16(ivas_format, SBA_ISM_FORMAT)) - { - IF(LE_32(ivas_total_brate, IVAS_16k4)) - { - return 250; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_24k4)) - { - return 350; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_32k)) - { - return 400; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_48k)) - { - return 650; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_80k)) - { - return 750; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_128k)) - { - return 1020; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_160k)) - { - return 1160; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_192k)) - { - return 1220; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_256k)) - { - return 1300; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_384k)) - { - return 1720; - } - ELSE - { - return 2000; - } - } - ELSE IF(EQ_16(ivas_format, MASA_FORMAT)) - { - IF(LE_32(ivas_total_brate, IVAS_16k4)) - { - return 300; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_32k)) - { - return 400; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_48k)) - { - return 650; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_80k)) - { - return 750; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_160k)) - { - return 850; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_192k)) - { - return 950; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_256k)) - { - return 1150; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_384k)) - { - return 1450; - } - ELSE - { - return 1650; - } - } - ELSE IF(EQ_16(ivas_format, MASA_ISM_FORMAT)) - { - IF(LE_32(ivas_total_brate, IVAS_16k4)) - { - return 300; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_32k)) - { - return 400; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_48k)) - { - return 650; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_80k)) - { - return 750; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_160k)) - { - return 1150; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_192k)) - { - return 1250; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_256k)) - { - return 1400; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_384k)) - { - return 1650; - } - ELSE - { - return 1850; - } - } - ELSE IF(EQ_16(ivas_format, MC_FORMAT)) - { - IF(LE_32(ivas_total_brate, IVAS_16k4)) - { - return 250; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_24k4)) - { - return 350; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_32k)) - { - return 400; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_48k)) - { - return 650; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_64k)) - { - return 750; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_80k)) - { - return 850; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_128k)) - { - return 1150; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_160k)) - { - return 1420; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_256k)) - { - return 2120; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_384k)) - { - return 2250; - } - ELSE - { - return 2450; - } - } - + IF( EQ_16( ivas_format, STEREO_FORMAT ) ) + { + IF( LE_32( ivas_total_brate, IVAS_16k4 ) ) + { + return 300; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_24k4 ) ) + { + return 400; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_32k ) ) + { + return 450; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_48k ) ) + { + return 650; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_80k ) ) + { + return 750; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_128k ) ) + { + return 850; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_192k ) ) + { + return 950; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_256k ) ) + { + return 1350; + } + ELSE + { + return 1650; + } + } + ELSE IF( EQ_16( ivas_format, ISM_FORMAT ) || EQ_16( ivas_format, MONO_FORMAT ) ) + { + IF( LE_32( ivas_total_brate, IVAS_16k4 ) ) + { + return 250; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_24k4 ) ) + { + return 350; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_32k ) ) + { + return 450; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_48k ) ) + { + return 550; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_64k ) ) + { + return 620; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_80k ) ) + { + return 670; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_96k ) ) + { + return 780; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_128k ) ) + { + return 880; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_192k ) ) + { + return 950; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_256k ) ) + { + return 1100; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_384k ) ) + { + return 1300; + } + ELSE + { + return 1650; + } + } + ELSE IF( EQ_16( ivas_format, SBA_FORMAT ) || EQ_16( ivas_format, SBA_ISM_FORMAT ) ) + { + IF( LE_32( ivas_total_brate, IVAS_16k4 ) ) + { + return 250; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_24k4 ) ) + { + return 350; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_32k ) ) + { + return 400; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_48k ) ) + { + return 650; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_80k ) ) + { + return 750; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_128k ) ) + { + return 1020; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_160k ) ) + { + return 1160; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_192k ) ) + { + return 1220; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_256k ) ) + { + return 1300; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_384k ) ) + { + return 1720; + } + ELSE + { + return 2000; + } + } + ELSE IF( EQ_16( ivas_format, MASA_FORMAT ) ) + { + IF( LE_32( ivas_total_brate, IVAS_16k4 ) ) + { + return 300; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_32k ) ) + { + return 400; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_48k ) ) + { + return 650; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_80k ) ) + { + return 750; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_160k ) ) + { + return 850; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_192k ) ) + { + return 950; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_256k ) ) + { + return 1150; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_384k ) ) + { + return 1450; + } + ELSE + { + return 1650; + } + } + ELSE IF( EQ_16( ivas_format, MASA_ISM_FORMAT ) ) + { + IF( LE_32( ivas_total_brate, IVAS_16k4 ) ) + { + return 300; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_32k ) ) + { + return 400; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_48k ) ) + { + return 650; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_80k ) ) + { + return 750; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_160k ) ) + { + return 1150; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_192k ) ) + { + return 1250; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_256k ) ) + { + return 1400; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_384k ) ) + { + return 1650; + } + ELSE + { + return 1850; + } + } + ELSE IF( EQ_16( ivas_format, MC_FORMAT ) ) + { + IF( LE_32( ivas_total_brate, IVAS_16k4 ) ) + { + return 250; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_24k4 ) ) + { + return 350; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_32k ) ) + { + return 400; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_48k ) ) + { + return 650; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_64k ) ) + { + return 750; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_80k ) ) + { + return 850; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_128k ) ) + { + return 1150; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_160k ) ) + { + return 1420; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_256k ) ) + { + return 2120; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_384k ) ) + { + return 2250; + } + ELSE + { + return 2450; + } + } + return 2450; } /*-----------------------------------------------------------------------* @@ -1041,183 +1041,183 @@ int16_t get_ivas_max_num_indices_metadata( } Word16 get_ivas_max_num_indices_metadata_fx( - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const Word32 ivas_total_brate /* i : IVAS total bitrate */ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const Word32 ivas_total_brate /* i : IVAS total bitrate */ ) { - /* set the maximum required number of metadata indices */ - IF(EQ_16(ivas_format, MONO_FORMAT)) - { - return 0; - } - ELSE IF(EQ_16(ivas_format, STEREO_FORMAT)) - { - IF(LE_32(ivas_total_brate, IVAS_16k4)) - { - return 60; - } - ELSE - { - return 80; - } - } - ELSE IF(EQ_16(ivas_format, ISM_FORMAT)) - { - IF(LE_32(ivas_total_brate, IVAS_16k4)) - { - return 20; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_32k)) - { - return 65; - } - ELSE - { - return 80; - } - } - ELSE IF(EQ_16(ivas_format, SBA_FORMAT) || EQ_16(ivas_format, SBA_ISM_FORMAT)) - { - IF(LE_32(ivas_total_brate, IVAS_16k4)) - { - return 100; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_24k4)) - { - return 200; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_32k)) - { - return 300; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_192k)) - { - return 500; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_256k)) - { - return 1050; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_384k)) - { - return 2000; - } - ELSE - { - return 2500; - } - } - ELSE IF(EQ_16(ivas_format, MASA_FORMAT)) - { - IF(LE_32(ivas_total_brate, IVAS_16k4)) - { - return 80; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_32k)) - { - return 125; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_48k)) - { - return 205; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_96k)) - { - return 240; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_128k)) - { - return 305; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_160k)) - { - return 425; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_192k)) - { - return 630; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_256k)) - { - return 850; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_384k)) - { - return 1000; - } - ELSE - { - return 1750; - } - } - ELSE IF(EQ_16(ivas_format, MASA_ISM_FORMAT)) - { - IF(LE_32(ivas_total_brate, IVAS_16k4)) - { - return 80; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_32k)) - { - return 125 + 100; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_48k)) - { - return 205 + 100; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_96k)) - { - return 240 + 150; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_128k)) - { - return 305 + 30; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_160k)) - { - return 425 + 30; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_192k)) - { - return 630 + 30; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_256k)) - { - return 850 + 30; - } - ELSE IF(LE_32(ivas_total_brate, IVAS_384k)) + /* set the maximum required number of metadata indices */ + IF( EQ_16( ivas_format, MONO_FORMAT ) ) { - return 1000 + 30; + return 0; } - ELSE + ELSE IF( EQ_16( ivas_format, STEREO_FORMAT ) ) { - return 1750 + 30; + IF( LE_32( ivas_total_brate, IVAS_16k4 ) ) + { + return 60; + } + ELSE + { + return 80; + } } - } - ELSE IF(EQ_16(ivas_format, MC_FORMAT)) - { - IF(LE_32(ivas_total_brate, IVAS_13k2)) + ELSE IF( EQ_16( ivas_format, ISM_FORMAT ) ) { - return 80; + IF( LE_32( ivas_total_brate, IVAS_16k4 ) ) + { + return 20; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_32k ) ) + { + return 65; + } + ELSE + { + return 80; + } } - ELSE IF(LE_32(ivas_total_brate, IVAS_24k4)) + ELSE IF( EQ_16( ivas_format, SBA_FORMAT ) || EQ_16( ivas_format, SBA_ISM_FORMAT ) ) { - return 100; + IF( LE_32( ivas_total_brate, IVAS_16k4 ) ) + { + return 100; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_24k4 ) ) + { + return 200; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_32k ) ) + { + return 300; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_192k ) ) + { + return 500; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_256k ) ) + { + return 1050; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_384k ) ) + { + return 2000; + } + ELSE + { + return 2500; + } } - ELSE IF(LE_32(ivas_total_brate, IVAS_64k)) + ELSE IF( EQ_16( ivas_format, MASA_FORMAT ) ) { - return 210; + IF( LE_32( ivas_total_brate, IVAS_16k4 ) ) + { + return 80; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_32k ) ) + { + return 125; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_48k ) ) + { + return 205; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_96k ) ) + { + return 240; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_128k ) ) + { + return 305; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_160k ) ) + { + return 425; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_192k ) ) + { + return 630; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_256k ) ) + { + return 850; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_384k ) ) + { + return 1000; + } + ELSE + { + return 1750; + } } - ELSE IF(LE_32(ivas_total_brate, IVAS_96k)) + ELSE IF( EQ_16( ivas_format, MASA_ISM_FORMAT ) ) { - return 220; + IF( LE_32( ivas_total_brate, IVAS_16k4 ) ) + { + return 80; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_32k ) ) + { + return 125 + 100; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_48k ) ) + { + return 205 + 100; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_96k ) ) + { + return 240 + 150; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_128k ) ) + { + return 305 + 30; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_160k ) ) + { + return 425 + 30; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_192k ) ) + { + return 630 + 30; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_256k ) ) + { + return 850 + 30; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_384k ) ) + { + return 1000 + 30; + } + ELSE + { + return 1750 + 30; + } } - ELSE + ELSE IF( EQ_16( ivas_format, MC_FORMAT ) ) { - return 300; + IF( LE_32( ivas_total_brate, IVAS_13k2 ) ) + { + return 80; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_24k4 ) ) + { + return 100; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_64k ) ) + { + return 210; + } + ELSE IF( LE_32( ivas_total_brate, IVAS_96k ) ) + { + return 220; + } + ELSE + { + return 300; + } } - } - return 50; + return 50; } /*-------------------------------------------------------------------* * move_indices() @@ -1760,7 +1760,7 @@ uint16_t get_indice_1( *-------------------------------------------------------------------*/ void reset_indices_enc( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word16 max_num_indices /* i : max number of indices */ ) { @@ -1769,7 +1769,7 @@ void reset_indices_enc( hBstr->nb_bits_tot = 0; hBstr->nb_ind_tot = 0; - FOR ( i = 0; i < max_num_indices; i++ ) + FOR( i = 0; i < max_num_indices; i++ ) { hBstr->ind_list[i].nb_bits = -1; } @@ -1927,14 +1927,14 @@ static ivas_error write_indices_element( pt_stream_loc += nb_bits_tot_metadata - 1; pt_stream_end = pt_stream_loc + 1; - write_indices_to_stream( ind_list_metadata, &pt_stream_loc, -1, - nb_ind_tot_metadata ); + write_indices_to_stream( ind_list_metadata, &pt_stream_loc, -1, + nb_ind_tot_metadata ); /* restore previous pointer position */ pt_stream_loc = pt_stream_backup; } - write_indices_to_stream( sts[n]->hBstr->ind_list, &pt_stream_loc, 1, - sts[n]->hBstr->nb_ind_tot ); + write_indices_to_stream( sts[n]->hBstr->ind_list, &pt_stream_loc, 1, + sts[n]->hBstr->nb_ind_tot ); if ( pt_stream_loc > pt_stream_end ) { @@ -2429,9 +2429,6 @@ void mdct_switching_dec( } - - - /*-------------------------------------------------------------------* * reset_elements() * @@ -2446,7 +2443,7 @@ Decoder_State **reset_elements( Word16 k, n; Decoder_State **sts = NULL; /* to avoid compilation warning */ - FOR ( k = 0; k < st_ivas->nSCE; k++ ) + FOR( k = 0; k < st_ivas->nSCE; k++ ) { sts = st_ivas->hSCE[k]->hCoreCoder; @@ -2455,23 +2452,29 @@ Decoder_State **reset_elements( sts[0]->mdct_sw_enable = 0; sts[0]->mdct_sw = 0; - move16(); move16(); move16(); move16(); + move16(); + move16(); + move16(); + move16(); reset_indices_dec( sts[0] ); } - FOR ( k = 0; k < st_ivas->nCPE; k++ ) + FOR( k = 0; k < st_ivas->nCPE; k++ ) { sts = st_ivas->hCPE[k]->hCoreCoder; - FOR ( n = 0; n < CPE_CHANNELS; n++ ) + FOR( n = 0; n < CPE_CHANNELS; n++ ) { sts[n]->bfi = 0; sts[n]->BER_detect = 0; sts[n]->mdct_sw_enable = 0; sts[n]->mdct_sw = 0; - move16(); move16(); move16(); move16(); + move16(); + move16(); + move16(); + move16(); reset_indices_dec( sts[n] ); } @@ -2553,8 +2556,6 @@ void ivas_set_bitstream_pointers( } - - /*-------------------------------------------------------------------* * read_indices() * diff --git a/lib_com/bitstream_fx.c b/lib_com/bitstream_fx.c index 5b70971d3..2fca67ff9 100644 --- a/lib_com/bitstream_fx.c +++ b/lib_com/bitstream_fx.c @@ -31,227 +31,227 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include #include #include #include "options.h" -#include "ivas_cnst.h" /* Common constants */ -#include "prot_fx2.h" /* Function prototypes */ +#include "ivas_cnst.h" /* Common constants */ +#include "prot_fx2.h" /* Function prototypes */ #include "ivas_prot_fx.h" #include "basop_util.h" #include "rom_com.h" #include "mime.h" #ifdef DEBUGGING - /*-------------------------------------------------------------------* - * Global variables - *--------------------------------------------------------------------*/ +/*-------------------------------------------------------------------* + * Global variables + *--------------------------------------------------------------------*/ int16_t FEC_seed = 12558; /* Seed for random FEC generator */ -FILE* FEC_pattern = NULL; /* FEC pattern file (for simulation of FEC) */ +FILE *FEC_pattern = NULL; /* FEC pattern file (for simulation of FEC) */ #ifndef IVAS_CODE -float FEC_random = 0; /* FEC rate in percent (for simulation of FEC) */ +float FEC_random = 0; /* FEC rate in percent (for simulation of FEC) */ /*-------------------------------------------------------------------* * file_read_FECpattern() * * Simulate packet losses by reading FEC pattern from external file *-------------------------------------------------------------------*/ -static int16_t file_read_FECpattern(void) +static int16_t file_read_FECpattern( void ) { - int16_t bfi = 0; - - /* FEC pattern file provided */ - if (FEC_pattern != NULL) - { - int16_t tmp = 0; - if (fread(&tmp, sizeof(int16_t), 1, FEC_pattern) != 1) - { - if (feof(FEC_pattern) != 0) - { - tmp = 0; - fseek(FEC_pattern, 0L, SEEK_SET); - } - else - { - fprintf(stderr, "\nError reading the FEC pattern file !"); - exit(-1); - } - } - - if (tmp == 2609 || tmp == 1 || tmp == SYNC_BAD_FRAME) - { - bfi = 1; - } - else - { - bfi = 0; - } - } - - /* random FEC simulation requested */ - else if (FEC_random > 0) - { - float ftmp = (float)/*own_random*/Random(&FEC_seed) + 32768.0f; - if (ftmp <= FEC_random / 100.0f * 65535.0f) - { - bfi = 1; - } - else - { - bfi = 0; - } - } - - return bfi; + int16_t bfi = 0; + + /* FEC pattern file provided */ + if ( FEC_pattern != NULL ) + { + int16_t tmp = 0; + if ( fread( &tmp, sizeof( int16_t ), 1, FEC_pattern ) != 1 ) + { + if ( feof( FEC_pattern ) != 0 ) + { + tmp = 0; + fseek( FEC_pattern, 0L, SEEK_SET ); + } + else + { + fprintf( stderr, "\nError reading the FEC pattern file !" ); + exit( -1 ); + } + } + + if ( tmp == 2609 || tmp == 1 || tmp == SYNC_BAD_FRAME ) + { + bfi = 1; + } + else + { + bfi = 0; + } + } + + /* random FEC simulation requested */ + else if ( FEC_random > 0 ) + { + float ftmp = (float) /*own_random*/ Random( &FEC_seed ) + 32768.0f; + if ( ftmp <= FEC_random / 100.0f * 65535.0f ) + { + bfi = 1; + } + else + { + bfi = 0; + } + } + + return bfi; } #endif #endif /*-------------------------------------------------------------------* -* pack_bit() -* -* insert a bit into packed octet -*-------------------------------------------------------------------*/ + * pack_bit() + * + * insert a bit into packed octet + *-------------------------------------------------------------------*/ static void pack_bit( - const Word16 bit, /* i: bit to be packed */ - UWord8 **pt, /* i/o: pointer to octet array into which bit will be placed */ - UWord8 *omask /* i/o: output mask to indicate where in the octet the bit is to be written */ + const Word16 bit, /* i: bit to be packed */ + UWord8 **pt, /* i/o: pointer to octet array into which bit will be placed */ + UWord8 *omask /* i/o: output mask to indicate where in the octet the bit is to be written */ ) { - if (*omask == 0x80) - { - **pt = 0; - } - if (bit != 0) - { - **pt = **pt | *omask; - } - *omask >>= 1; - if (*omask == 0) - { - *omask = 0x80; - (*pt)++; - } - - return; + if ( *omask == 0x80 ) + { + **pt = 0; + } + if ( bit != 0 ) + { + **pt = **pt | *omask; + } + *omask >>= 1; + if ( *omask == 0 ) + { + *omask = 0x80; + ( *pt )++; + } + + return; } /*-------------------------------------------------------------------* -* unpack_bit() -* -* unpack a bit from packed octet -*-------------------------------------------------------------------*/ + * unpack_bit() + * + * unpack a bit from packed octet + *-------------------------------------------------------------------*/ static Word16 unpack_bit( - UWord8 **pt, /* i/o: pointer to octet array from which bit will be read */ - UWord8 *mask /* i/o: mask to indicate the bit in the octet */ + UWord8 **pt, /* i/o: pointer to octet array from which bit will be read */ + UWord8 *mask /* i/o: mask to indicate the bit in the octet */ ) { - Word16 bit; - - bit = (**pt & *mask) != 0; - *mask >>= 1; - if (*mask == 0) - { - *mask = 0x80; - (*pt)++; - } - return bit; + Word16 bit; + + bit = ( **pt & *mask ) != 0; + *mask >>= 1; + if ( *mask == 0 ) + { + *mask = 0x80; + ( *pt )++; + } + return bit; } /*-------------------------------------------------------------------* -* rate2AMRWB_IOmode() -* -* lookup AMRWB IO mode -*-------------------------------------------------------------------*/ + * rate2AMRWB_IOmode() + * + * lookup AMRWB IO mode + *-------------------------------------------------------------------*/ static Word16 rate2AMRWB_IOmode( - Word32 brate /* i: bitrate */ + Word32 brate /* i: bitrate */ ) { - switch (brate) - { - /* EVS AMR-WB IO modes */ - case SID_1k75: - return AMRWB_IO_SID; - case ACELP_6k60: - return AMRWB_IO_6600; - case ACELP_8k85: - return AMRWB_IO_8850; - case ACELP_12k65: - return AMRWB_IO_1265; - case ACELP_14k25: - return AMRWB_IO_1425; - case ACELP_15k85: - return AMRWB_IO_1585; - case ACELP_18k25: - return AMRWB_IO_1825; - case ACELP_19k85: - return AMRWB_IO_1985; - case ACELP_23k05: - return AMRWB_IO_2305; - case ACELP_23k85: - return AMRWB_IO_2385; - default: - break; - } - return -1; + switch ( brate ) + { + /* EVS AMR-WB IO modes */ + case SID_1k75: + return AMRWB_IO_SID; + case ACELP_6k60: + return AMRWB_IO_6600; + case ACELP_8k85: + return AMRWB_IO_8850; + case ACELP_12k65: + return AMRWB_IO_1265; + case ACELP_14k25: + return AMRWB_IO_1425; + case ACELP_15k85: + return AMRWB_IO_1585; + case ACELP_18k25: + return AMRWB_IO_1825; + case ACELP_19k85: + return AMRWB_IO_1985; + case ACELP_23k05: + return AMRWB_IO_2305; + case ACELP_23k85: + return AMRWB_IO_2385; + default: + break; + } + return -1; } /*-------------------------------------------------------------------* -* rate2EVSmode() -* -* lookup EVS mode -*-------------------------------------------------------------------*/ + * rate2EVSmode() + * + * lookup EVS mode + *-------------------------------------------------------------------*/ Word16 rate2EVSmode( - const Word32 brate, /* i: bitrate */ - Word16* is_amr_wb /* o : (flag) does the bitrate belong to AMR-WB? Can be NULL */ + const Word32 brate, /* i: bitrate */ + Word16 *is_amr_wb /* o : (flag) does the bitrate belong to AMR-WB? Can be NULL */ ) { - if (is_amr_wb != NULL) - { - *is_amr_wb = 0; - } - switch (brate) - { - /* EVS Primary modes */ - case FRAME_NO_DATA: - return NO_DATA_TYPE; - case SID_2k40: - return PRIMARY_SID; - case PPP_NELP_2k80: - return PRIMARY_2800; - case ACELP_7k20: - return PRIMARY_7200; - case ACELP_8k00: - return PRIMARY_8000; - case ACELP_9k60: - return PRIMARY_9600; - case ACELP_13k20: - return PRIMARY_13200; - case ACELP_16k40: - return PRIMARY_16400; - case ACELP_24k40: - return PRIMARY_24400; - case ACELP_32k: - return PRIMARY_32000; - case ACELP_48k: - return PRIMARY_48000; - case ACELP_64k: - return PRIMARY_64000; - case HQ_96k: - return PRIMARY_96000; - case HQ_128k: - return PRIMARY_128000; - default: - break; - } - if (is_amr_wb != NULL) - { - *is_amr_wb = 1; - } - return rate2AMRWB_IOmode(brate); + if ( is_amr_wb != NULL ) + { + *is_amr_wb = 0; + } + switch ( brate ) + { + /* EVS Primary modes */ + case FRAME_NO_DATA: + return NO_DATA_TYPE; + case SID_2k40: + return PRIMARY_SID; + case PPP_NELP_2k80: + return PRIMARY_2800; + case ACELP_7k20: + return PRIMARY_7200; + case ACELP_8k00: + return PRIMARY_8000; + case ACELP_9k60: + return PRIMARY_9600; + case ACELP_13k20: + return PRIMARY_13200; + case ACELP_16k40: + return PRIMARY_16400; + case ACELP_24k40: + return PRIMARY_24400; + case ACELP_32k: + return PRIMARY_32000; + case ACELP_48k: + return PRIMARY_48000; + case ACELP_64k: + return PRIMARY_64000; + case HQ_96k: + return PRIMARY_96000; + case HQ_128k: + return PRIMARY_128000; + default: + break; + } + if ( is_amr_wb != NULL ) + { + *is_amr_wb = 1; + } + return rate2AMRWB_IOmode( brate ); } /*-------------------------------------------------------------------* @@ -261,44 +261,44 @@ Word16 rate2EVSmode( *-------------------------------------------------------------------*/ void push_indice_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder state structure */ - Word16 id, /* i : ID of the indice */ - UWord16 value, /* i : value of the quantized indice */ - Word16 nb_bits /* i : number of bits used to quantize the indice */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder state structure */ + Word16 id, /* i : ID of the indice */ + UWord16 value, /* i : value of the quantized indice */ + Word16 nb_bits /* i : number of bits used to quantize the indice */ ) { - Word16 i; - - - IF(EQ_16(hBstr->last_ind_fx, id)) - { - /* indice with the same name as the previous one */ - i = hBstr->next_ind_fx; - } - ELSE - { - /* new indice - find an empty slot in the list */ - i = id; - move16(); - WHILE(NE_16(hBstr->ind_list_fx[i].nb_bits, -1)) - { - i = add(i, 1); - } - } - - /* store the values in the list */ - hBstr->ind_list_fx[i].value = value; - move16(); - hBstr->ind_list_fx[i].nb_bits = nb_bits; - move16(); - - /* updates */ - hBstr->next_ind_fx = add(i, 1); - hBstr->last_ind_fx = id; - move16(); - hBstr->nb_bits_tot_fx = add(hBstr->nb_bits_tot_fx, nb_bits); - - return; + Word16 i; + + + IF( EQ_16( hBstr->last_ind_fx, id ) ) + { + /* indice with the same name as the previous one */ + i = hBstr->next_ind_fx; + } + ELSE + { + /* new indice - find an empty slot in the list */ + i = id; + move16(); + WHILE( NE_16( hBstr->ind_list_fx[i].nb_bits, -1 ) ) + { + i = add( i, 1 ); + } + } + + /* store the values in the list */ + hBstr->ind_list_fx[i].value = value; + move16(); + hBstr->ind_list_fx[i].nb_bits = nb_bits; + move16(); + + /* updates */ + hBstr->next_ind_fx = add( i, 1 ); + hBstr->last_ind_fx = id; + move16(); + hBstr->nb_bits_tot_fx = add( hBstr->nb_bits_tot_fx, nb_bits ); + + return; } /*-------------------------------------------------------------------* @@ -307,24 +307,24 @@ void push_indice_fx( *-------------------------------------------------------------------*/ void push_next_indice_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder state structure */ - UWord16 value, /* i : value of the quantized indice */ - Word16 nb_bits /* i : number of bits used to quantize the indice */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder state structure */ + UWord16 value, /* i : value of the quantized indice */ + Word16 nb_bits /* i : number of bits used to quantize the indice */ ) { - /* store the values in the list */ - hBstr->ind_list_fx[hBstr->next_ind_fx].value = value; - move16(); - hBstr->ind_list_fx[hBstr->next_ind_fx].nb_bits = nb_bits; - move16(); - hBstr->next_ind_fx = add(hBstr->next_ind_fx, 1); + /* store the values in the list */ + hBstr->ind_list_fx[hBstr->next_ind_fx].value = value; + move16(); + hBstr->ind_list_fx[hBstr->next_ind_fx].nb_bits = nb_bits; + move16(); + hBstr->next_ind_fx = add( hBstr->next_ind_fx, 1 ); - /* update the total number of bits already written */ - hBstr->nb_bits_tot_fx = add(hBstr->nb_bits_tot_fx, nb_bits); + /* update the total number of bits already written */ + hBstr->nb_bits_tot_fx = add( hBstr->nb_bits_tot_fx, nb_bits ); - return; + return; } @@ -334,48 +334,48 @@ void push_next_indice_fx( *-------------------------------------------------------------------*/ void push_next_bits_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder state structure */ - Word16 bits[], /* i : bit buffer to pack, sequence of single bits */ - Word16 nb_bits /* i : number of bits to pack */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder state structure */ + Word16 bits[], /* i : bit buffer to pack, sequence of single bits */ + Word16 nb_bits /* i : number of bits to pack */ ) { - UWord16 code; - Word16 i, nb_bits_m15; - Indice *ptr; - - ptr = &hBstr->ind_list_fx[hBstr->next_ind_fx]; - nb_bits_m15 = sub(nb_bits, 15); - i = 0; - move16(); - IF(nb_bits_m15 > 0) - { - FOR(; i < nb_bits_m15; i += 16) - { - code = s_or(lshl(bits[i], 15), s_or(lshl(bits[i + 1], 14), s_or(lshl(bits[i + 2], 13), s_or(lshl(bits[i + 3], 12), - s_or(lshl(bits[i + 4], 11), s_or(lshl(bits[i + 5], 10), s_or(lshl(bits[i + 6], 9), s_or(lshl(bits[i + 7], 8), - s_or(lshl(bits[i + 8], 7), s_or(lshl(bits[i + 9], 6), s_or(lshl(bits[i + 10], 5), s_or(lshl(bits[i + 11], 4), - s_or(lshl(bits[i + 12], 3), s_or(lshl(bits[i + 13], 2), s_or(lshl(bits[i + 14], 1), bits[i + 15]))))))))))))))); - - ptr->value = code; - move16(); - ptr->nb_bits = 16; - move16(); - ++ptr; - } - } - IF(LT_16(i, nb_bits)) - { - FOR(; i < nb_bits; ++i) - { - ptr->value = bits[i]; - move16(); - ptr->nb_bits = 1; - move16(); - ++ptr; - } - } - hBstr->next_ind_fx = (Word16)(ptr - hBstr->ind_list_fx); - hBstr->nb_bits_tot_fx = add(hBstr->nb_bits_tot_fx, nb_bits); + UWord16 code; + Word16 i, nb_bits_m15; + Indice *ptr; + + ptr = &hBstr->ind_list_fx[hBstr->next_ind_fx]; + nb_bits_m15 = sub( nb_bits, 15 ); + i = 0; + move16(); + IF( nb_bits_m15 > 0 ) + { + FOR( ; i < nb_bits_m15; i += 16 ) + { + code = s_or( lshl( bits[i], 15 ), s_or( lshl( bits[i + 1], 14 ), s_or( lshl( bits[i + 2], 13 ), s_or( lshl( bits[i + 3], 12 ), + s_or( lshl( bits[i + 4], 11 ), s_or( lshl( bits[i + 5], 10 ), s_or( lshl( bits[i + 6], 9 ), s_or( lshl( bits[i + 7], 8 ), + s_or( lshl( bits[i + 8], 7 ), s_or( lshl( bits[i + 9], 6 ), s_or( lshl( bits[i + 10], 5 ), s_or( lshl( bits[i + 11], 4 ), + s_or( lshl( bits[i + 12], 3 ), s_or( lshl( bits[i + 13], 2 ), s_or( lshl( bits[i + 14], 1 ), bits[i + 15] ) ) ) ) ) ) ) ) ) ) ) ) ) ) ); + + ptr->value = code; + move16(); + ptr->nb_bits = 16; + move16(); + ++ptr; + } + } + IF( LT_16( i, nb_bits ) ) + { + FOR( ; i < nb_bits; ++i ) + { + ptr->value = bits[i]; + move16(); + ptr->nb_bits = 1; + move16(); + ++ptr; + } + } + hBstr->next_ind_fx = (Word16) ( ptr - hBstr->ind_list_fx ); + hBstr->nb_bits_tot_fx = add( hBstr->nb_bits_tot_fx, nb_bits ); } /*-------------------------------------------------------------------* @@ -384,37 +384,37 @@ void push_next_bits_fx( * Get the next indice from the buffer *-------------------------------------------------------------------*/ -UWord16 get_next_indice_fx( /* o : value of the indice */ - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 nb_bits /* i : number of bits that were used to quantize the indice */ +UWord16 get_next_indice_fx( /* o : value of the indice */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 nb_bits /* i : number of bits that were used to quantize the indice */ ) { - UWord16 value; - Word16 i; - Word16 nbits_total; - - assert(nb_bits <= 16); - value = 0; - move16(); - - nbits_total = (Word16)(st_fx->total_brate / FRAMES_PER_SEC); - /* detect corrupted bitstream */ - IF(GT_16(add(st_fx->next_bit_pos, nb_bits), nbits_total)) - { - st_fx->BER_detect = 1; - move16(); - return(0); - } - - FOR(i = 0; i < nb_bits; i++) - { - value = lshl(value, 1); - value = add(value, st_fx->bit_stream[st_fx->next_bit_pos + i]); - } - - /* update the position in the bitstream */ - st_fx->next_bit_pos = add(st_fx->next_bit_pos, nb_bits); - return value; + UWord16 value; + Word16 i; + Word16 nbits_total; + + assert( nb_bits <= 16 ); + value = 0; + move16(); + + nbits_total = (Word16) ( st_fx->total_brate / FRAMES_PER_SEC ); + /* detect corrupted bitstream */ + IF( GT_16( add( st_fx->next_bit_pos, nb_bits ), nbits_total ) ) + { + st_fx->BER_detect = 1; + move16(); + return ( 0 ); + } + + FOR( i = 0; i < nb_bits; i++ ) + { + value = lshl( value, 1 ); + value = add( value, st_fx->bit_stream[st_fx->next_bit_pos + i] ); + } + + /* update the position in the bitstream */ + st_fx->next_bit_pos = add( st_fx->next_bit_pos, nb_bits ); + return value; } /*-------------------------------------------------------------------* @@ -423,26 +423,26 @@ UWord16 get_next_indice_fx( /* o : value of the indice */ * Get the next 1-bit indice from the buffer *-------------------------------------------------------------------*/ -UWord16 get_next_indice_1_fx( /* o : value of the indice */ - Decoder_State *st_fx /* i/o: decoder state structure */ +UWord16 get_next_indice_1_fx( /* o : value of the indice */ + Decoder_State *st_fx /* i/o: decoder state structure */ ) { - Word16 nbits_total; - nbits_total = (Word16)(st_fx->total_brate / FRAMES_PER_SEC); - /* detect corrupted bitstream */ - test(); - test(); - test(); - IF((GT_16(add(st_fx->next_bit_pos, 1), nbits_total) && EQ_16(st_fx->codec_mode, MODE1)) || - (GT_16(add(st_fx->next_bit_pos, 1), add(nbits_total, 2 * 8)) && EQ_16(st_fx->codec_mode, MODE2)) /* add two zero bytes for arithmetic coder flush */ - ) - { - st_fx->BER_detect = 1; - move16(); - return(0); - } - - return st_fx->bit_stream[st_fx->next_bit_pos++]; + Word16 nbits_total; + nbits_total = (Word16) ( st_fx->total_brate / FRAMES_PER_SEC ); + /* detect corrupted bitstream */ + test(); + test(); + test(); + IF( ( GT_16( add( st_fx->next_bit_pos, 1 ), nbits_total ) && EQ_16( st_fx->codec_mode, MODE1 ) ) || + ( GT_16( add( st_fx->next_bit_pos, 1 ), add( nbits_total, 2 * 8 ) ) && EQ_16( st_fx->codec_mode, MODE2 ) ) /* add two zero bytes for arithmetic coder flush */ + ) + { + st_fx->BER_detect = 1; + move16(); + return ( 0 ); + } + + return st_fx->bit_stream[st_fx->next_bit_pos++]; } /*-------------------------------------------------------------------* @@ -452,12 +452,12 @@ UWord16 get_next_indice_1_fx( /* o : value of the indice */ *-------------------------------------------------------------------*/ void get_next_indice_tmp_fx( - Decoder_State *st_fx, /* o : decoder state structure */ - Word16 nb_bits /* i : number of bits that were used to quantize the indice */ + Decoder_State *st_fx, /* o : decoder state structure */ + Word16 nb_bits /* i : number of bits that were used to quantize the indice */ ) { - /* update the position in the bitstream */ - st_fx->next_bit_pos = add(st_fx->next_bit_pos, nb_bits); + /* update the position in the bitstream */ + st_fx->next_bit_pos = add( st_fx->next_bit_pos, nb_bits ); } /*-------------------------------------------------------------------* @@ -466,34 +466,34 @@ void get_next_indice_tmp_fx( * Get indice at specific position in the buffer *-------------------------------------------------------------------*/ -UWord16 get_indice_fx( /* o : value of the indice */ - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 pos, /* i : absolute position in the bitstream (update after the read) */ - Word16 nb_bits /* i : number of bits that were used to quantize the indice */ +UWord16 get_indice_fx( /* o : value of the indice */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 pos, /* i : absolute position in the bitstream (update after the read) */ + Word16 nb_bits /* i : number of bits that were used to quantize the indice */ ) { - UWord16 value; - Word16 i; - - assert(nb_bits <= 16); - - /* detect corrupted bitstream */ - IF(GT_16(add(pos, nb_bits), st_fx->total_num_bits)) - { - st_fx->BER_detect = 1; - move16(); - return(0); - } - - value = 0; - move16(); - FOR(i = 0; i < nb_bits; i++) - { - value = lshl(value, 1); - value = add(value, st_fx->bit_stream[pos + i]); - } - - return value; + UWord16 value; + Word16 i; + + assert( nb_bits <= 16 ); + + /* detect corrupted bitstream */ + IF( GT_16( add( pos, nb_bits ), st_fx->total_num_bits ) ) + { + st_fx->BER_detect = 1; + move16(); + return ( 0 ); + } + + value = 0; + move16(); + FOR( i = 0; i < nb_bits; i++ ) + { + value = lshl( value, 1 ); + value = add( value, st_fx->bit_stream[pos + i] ); + } + + return value; } /*-------------------------------------------------------------------* @@ -502,22 +502,22 @@ UWord16 get_indice_fx( /* o : value of the indice */ * Get a 1-bit indice at specific position in the buffer *-------------------------------------------------------------------*/ -UWord16 get_indice_1_fx( /* o : value of the indice */ - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 pos /* i : absolute position in the bitstream (update after the read) */ +UWord16 get_indice_1_fx( /* o : value of the indice */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 pos /* i : absolute position in the bitstream (update after the read) */ ) { - Word16 nbits_total; - nbits_total = (Word16)(st_fx->total_brate / FRAMES_PER_SEC); - /* detect corrupted bitstream */ - IF(GT_16(add(pos, 1), nbits_total)) - { - st_fx->BER_detect = 1; - move16(); - return(0); - } - - return st_fx->bit_stream[pos]; + Word16 nbits_total; + nbits_total = (Word16) ( st_fx->total_brate / FRAMES_PER_SEC ); + /* detect corrupted bitstream */ + IF( GT_16( add( pos, 1 ), nbits_total ) ) + { + st_fx->BER_detect = 1; + move16(); + return ( 0 ); + } + + return st_fx->bit_stream[pos]; } /*-------------------------------------------------------------------* @@ -527,41 +527,40 @@ UWord16 get_indice_1_fx( /* o : value of the indice */ *-------------------------------------------------------------------*/ void reset_indices_enc_fx( - BSTR_ENC_HANDLE hBstr /* i/o: encoder state structure */ + BSTR_ENC_HANDLE hBstr /* i/o: encoder state structure */ ) { - Word16 i; - - hBstr->nb_bits_tot_fx = 0; - move16(); - hBstr->next_ind_fx = 0; - move16(); - hBstr->last_ind_fx = -1; - move16(); - - FOR(i = 0; i < MAX_NUM_INDICES; i++) - { - hBstr->ind_list_fx[i].nb_bits = -1; - move16(); - } - - return; + Word16 i; + + hBstr->nb_bits_tot_fx = 0; + move16(); + hBstr->next_ind_fx = 0; + move16(); + hBstr->last_ind_fx = -1; + move16(); + + FOR( i = 0; i < MAX_NUM_INDICES; i++ ) + { + hBstr->ind_list_fx[i].nb_bits = -1; + move16(); + } + + return; } /*-------------------------------------------------------------------* - * reset_indices_dec_fx() - * - * Reset the buffer of decoder indices - *-------------------------------------------------------------------*/ + * reset_indices_dec_fx() + * + * Reset the buffer of decoder indices + *-------------------------------------------------------------------*/ void reset_indices_dec_fx( - Decoder_State *st_fx -) + Decoder_State *st_fx ) { - st_fx->next_bit_pos = 0; - move16(); + st_fx->next_bit_pos = 0; + move16(); - return; + return; } @@ -572,91 +571,91 @@ void reset_indices_dec_fx( *-------------------------------------------------------------------*/ void write_indices_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - BSTR_ENC_HANDLE hBstr, /* i/o: encoder state structure */ - FILE *file /* i : output bitstream file */ - , UWord8 *pFrame, /* i: byte array with bit packet and byte aligned coded speech data */ - Word16 pFrame_size /* i: size of the binary encoded access unit [bits] */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder state structure */ + FILE *file /* i : output bitstream file */ + , + UWord8 *pFrame, /* i: byte array with bit packet and byte aligned coded speech data */ + Word16 pFrame_size /* i: size of the binary encoded access unit [bits] */ ) { - Word16 i, k; - Word16 stream[2 + MAX_BITS_PER_FRAME], *pt_stream; - Word32 mask; - UWord8 header; - Word16 isAmrWb = 0; - - if (st_fx->bitstreamformat == G192) - { - /*-----------------------------------------------------------------* - * Encode Sync Header and Frame Length - *-----------------------------------------------------------------*/ - pt_stream = stream; - for (i = 0; i < (2 + MAX_BITS_PER_FRAME); ++i) - { - stream[i] = 0; - } - *pt_stream++ = (Word16)SYNC_GOOD_FRAME; - *pt_stream++ = hBstr->nb_bits_tot_fx; - - /*----------------------------------------------------------------* - * Bitstream packing (conversion of individual indices into a serial stream) - * Writing the serial stream into file - *----------------------------------------------------------------*/ - - for (i = 0; i < MAX_NUM_INDICES; i++) - { - if (hBstr->ind_list_fx[i].nb_bits != -1) - { - /* mask from MSB to LSB */ - mask = 1 << (hBstr->ind_list_fx[i].nb_bits - 1); - - /* write bit by bit */ - for (k = 0; k < hBstr->ind_list_fx[i].nb_bits; k++) - { - if (hBstr->ind_list_fx[i].value & mask) - { - *pt_stream++ = G192_BIN1; - } - else - { - *pt_stream++ = G192_BIN0; - } - - mask >>= 1; - } - } - } - - } - else - { - /* Create and write ToC header */ - /* qbit always set to 1 on encoder side for AMRWBIO , no qbit in use for EVS, but set to 0(bad) */ - header = (UWord8)(st_fx->Opt_AMR_WB << 5 | st_fx->Opt_AMR_WB << 4 | rate2EVSmode(hBstr->nb_bits_tot_fx * 50, &isAmrWb)); - fwrite(&header, sizeof(UWord8), 1, file); - /* Write speech bits */ - fwrite(pFrame, sizeof(UWord8), (pFrame_size + 7) >> 3, file); - } - - /* Clearing of indices */ - FOR(i = 0; i < MAX_NUM_INDICES; i++) - { - hBstr->ind_list_fx[i].nb_bits = -1; - move16(); - } - - - if (st_fx->bitstreamformat == G192) - { - /* write the serial stream into file */ - fwrite(stream, sizeof(unsigned short), 2 + stream[1], file); - } - /* reset index pointers */ - hBstr->nb_bits_tot_fx = 0; - hBstr->next_ind_fx = 0; - hBstr->last_ind_fx = -1; - - return; + Word16 i, k; + Word16 stream[2 + MAX_BITS_PER_FRAME], *pt_stream; + Word32 mask; + UWord8 header; + Word16 isAmrWb = 0; + + if ( st_fx->bitstreamformat == G192 ) + { + /*-----------------------------------------------------------------* + * Encode Sync Header and Frame Length + *-----------------------------------------------------------------*/ + pt_stream = stream; + for ( i = 0; i < ( 2 + MAX_BITS_PER_FRAME ); ++i ) + { + stream[i] = 0; + } + *pt_stream++ = (Word16) SYNC_GOOD_FRAME; + *pt_stream++ = hBstr->nb_bits_tot_fx; + + /*----------------------------------------------------------------* + * Bitstream packing (conversion of individual indices into a serial stream) + * Writing the serial stream into file + *----------------------------------------------------------------*/ + + for ( i = 0; i < MAX_NUM_INDICES; i++ ) + { + if ( hBstr->ind_list_fx[i].nb_bits != -1 ) + { + /* mask from MSB to LSB */ + mask = 1 << ( hBstr->ind_list_fx[i].nb_bits - 1 ); + + /* write bit by bit */ + for ( k = 0; k < hBstr->ind_list_fx[i].nb_bits; k++ ) + { + if ( hBstr->ind_list_fx[i].value & mask ) + { + *pt_stream++ = G192_BIN1; + } + else + { + *pt_stream++ = G192_BIN0; + } + + mask >>= 1; + } + } + } + } + else + { + /* Create and write ToC header */ + /* qbit always set to 1 on encoder side for AMRWBIO , no qbit in use for EVS, but set to 0(bad) */ + header = (UWord8) ( st_fx->Opt_AMR_WB << 5 | st_fx->Opt_AMR_WB << 4 | rate2EVSmode( hBstr->nb_bits_tot_fx * 50, &isAmrWb ) ); + fwrite( &header, sizeof( UWord8 ), 1, file ); + /* Write speech bits */ + fwrite( pFrame, sizeof( UWord8 ), ( pFrame_size + 7 ) >> 3, file ); + } + + /* Clearing of indices */ + FOR( i = 0; i < MAX_NUM_INDICES; i++ ) + { + hBstr->ind_list_fx[i].nb_bits = -1; + move16(); + } + + + if ( st_fx->bitstreamformat == G192 ) + { + /* write the serial stream into file */ + fwrite( stream, sizeof( unsigned short ), 2 + stream[1], file ); + } + /* reset index pointers */ + hBstr->nb_bits_tot_fx = 0; + hBstr->next_ind_fx = 0; + hBstr->last_ind_fx = -1; + + return; } /*-------------------------------------------------------------------* @@ -770,82 +769,82 @@ void write_indices_buf_fx( *-------------------------------------------------------------------*/ void indices_to_serial( - const Encoder_State *st_fx, /* i: encoder state structure */ - BSTR_ENC_HANDLE hBstr, /* i/o: encoder state structure */ - UWord8 *pFrame, /* o: byte array with bit packet and byte aligned coded speech data */ - Word16 *pFrame_size /* o: size of the binary encoded access unit [bits] */ + const Encoder_State *st_fx, /* i: encoder state structure */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder state structure */ + UWord8 *pFrame, /* o: byte array with bit packet and byte aligned coded speech data */ + Word16 *pFrame_size /* o: size of the binary encoded access unit [bits] */ ) { - Word16 i, k, j; - Word16 cmi = 0, core_mode = 0; - Word32 mask; - Word16 amrwb_bits[(ACELP_23k85 / 50)]; - UWord8 omask = 0x80; - UWord8 *pt_pFrame = pFrame; - Word16 isAmrWb = 0; - - if (st_fx->Opt_AMR_WB) - { - cmi = rate2EVSmode(st_fx->total_brate, &isAmrWb); - core_mode = rate2EVSmode(hBstr->nb_bits_tot_fx * 50, &isAmrWb); - - j = 0; - for (i = 0; i < MAX_NUM_INDICES; i++) - { - if (hBstr->ind_list_fx[i].nb_bits != -1) - { - /* mask from MSB to LSB */ - mask = 1 << (hBstr->ind_list_fx[i].nb_bits - 1); - - /* temporarily save bit */ - for (k = 0; k < hBstr->ind_list_fx[i].nb_bits; k++) - { - amrwb_bits[j++] = (hBstr->ind_list_fx[i].value & mask) > 0; - mask >>= 1; - } - } - } - } - - *pFrame_size = hBstr->nb_bits_tot_fx; - - /*----------------------------------------------------------------* - * Bitstream packing (conversion of individual indices into a serial stream) - *----------------------------------------------------------------*/ - j = 0; - for (i = 0; i < MAX_NUM_INDICES; i++) - { - if (hBstr->ind_list_fx[i].nb_bits != -1) - { - /* mask from MSB to LSB */ - mask = 1 << (hBstr->ind_list_fx[i].nb_bits - 1); - - /* write bit by bit */ - for (k = 0; k < hBstr->ind_list_fx[i].nb_bits; k++) - { - if (st_fx->Opt_AMR_WB) - { - pack_bit(amrwb_bits[sort_ptr[core_mode][j++]], &pt_pFrame, &omask); - } - else - { - pack_bit(hBstr->ind_list_fx[i].value & mask, &pt_pFrame, &omask); - j++; - } - mask >>= 1; - } - } - } - - if (st_fx->Opt_AMR_WB && core_mode == AMRWB_IO_SID) /* SID UPD frame always written now .... */ - { - /* insert STI bit and CMI */ - pack_bit(1, &pt_pFrame, &omask); - for (mask = 0x08; mask > 0; mask >>= 1) - { - pack_bit(cmi & mask, &pt_pFrame, &omask); - } - } + Word16 i, k, j; + Word16 cmi = 0, core_mode = 0; + Word32 mask; + Word16 amrwb_bits[( ACELP_23k85 / 50 )]; + UWord8 omask = 0x80; + UWord8 *pt_pFrame = pFrame; + Word16 isAmrWb = 0; + + if ( st_fx->Opt_AMR_WB ) + { + cmi = rate2EVSmode( st_fx->total_brate, &isAmrWb ); + core_mode = rate2EVSmode( hBstr->nb_bits_tot_fx * 50, &isAmrWb ); + + j = 0; + for ( i = 0; i < MAX_NUM_INDICES; i++ ) + { + if ( hBstr->ind_list_fx[i].nb_bits != -1 ) + { + /* mask from MSB to LSB */ + mask = 1 << ( hBstr->ind_list_fx[i].nb_bits - 1 ); + + /* temporarily save bit */ + for ( k = 0; k < hBstr->ind_list_fx[i].nb_bits; k++ ) + { + amrwb_bits[j++] = ( hBstr->ind_list_fx[i].value & mask ) > 0; + mask >>= 1; + } + } + } + } + + *pFrame_size = hBstr->nb_bits_tot_fx; + + /*----------------------------------------------------------------* + * Bitstream packing (conversion of individual indices into a serial stream) + *----------------------------------------------------------------*/ + j = 0; + for ( i = 0; i < MAX_NUM_INDICES; i++ ) + { + if ( hBstr->ind_list_fx[i].nb_bits != -1 ) + { + /* mask from MSB to LSB */ + mask = 1 << ( hBstr->ind_list_fx[i].nb_bits - 1 ); + + /* write bit by bit */ + for ( k = 0; k < hBstr->ind_list_fx[i].nb_bits; k++ ) + { + if ( st_fx->Opt_AMR_WB ) + { + pack_bit( amrwb_bits[sort_ptr[core_mode][j++]], &pt_pFrame, &omask ); + } + else + { + pack_bit( hBstr->ind_list_fx[i].value & mask, &pt_pFrame, &omask ); + j++; + } + mask >>= 1; + } + } + } + + if ( st_fx->Opt_AMR_WB && core_mode == AMRWB_IO_SID ) /* SID UPD frame always written now .... */ + { + /* insert STI bit and CMI */ + pack_bit( 1, &pt_pFrame, &omask ); + for ( mask = 0x08; mask > 0; mask >>= 1 ) + { + pack_bit( cmi & mask, &pt_pFrame, &omask ); + } + } } @@ -856,1658 +855,1643 @@ void indices_to_serial( *-------------------------------------------------------------------*/ void indices_to_serial_generic( - const Indice *ind_list, /* i: indices list */ - const Word16 num_indices, /* i: number of indices to write */ - UWord8 *pFrame, /* o: byte array with bit packet and byte aligned coded speech data */ - Word16 *pFrame_size /* i/o: number of bits in the binary encoded access unit [bits] */ + const Indice *ind_list, /* i: indices list */ + const Word16 num_indices, /* i: number of indices to write */ + UWord8 *pFrame, /* o: byte array with bit packet and byte aligned coded speech data */ + Word16 *pFrame_size /* i/o: number of bits in the binary encoded access unit [bits] */ ) { - Word16 i, k, j; - Word32 mask; - UWord8 omask; - UWord8 *pt_pFrame = pFrame; - Word16 nb_bits_tot; - - nb_bits_tot = 0; - move16(); - omask = (0x80 >> (*pFrame_size & 0x7)); - pt_pFrame += shr(*pFrame_size, 3); - - /*----------------------------------------------------------------* - * Bitstream packing (conversion of individual indices into a serial stream) - *----------------------------------------------------------------*/ - j = 0; - move16(); - for (i = 0; i < num_indices; i++) - { - if (ind_list[i].nb_bits != -1) - { - /* mask from MSB to LSB */ - mask = 1 << (ind_list[i].nb_bits - 1); - - /* write bit by bit */ - for (k = 0; k < ind_list[i].nb_bits; k++) - { - pack_bit(ind_list[i].value & mask, &pt_pFrame, &omask); - j++; - mask >>= 1; - } - nb_bits_tot = add(nb_bits_tot, ind_list[i].nb_bits); - } - } - - *pFrame_size = add(*pFrame_size, nb_bits_tot); - - return; + Word16 i, k, j; + Word32 mask; + UWord8 omask; + UWord8 *pt_pFrame = pFrame; + Word16 nb_bits_tot; + + nb_bits_tot = 0; + move16(); + omask = ( 0x80 >> ( *pFrame_size & 0x7 ) ); + pt_pFrame += shr( *pFrame_size, 3 ); + + /*----------------------------------------------------------------* + * Bitstream packing (conversion of individual indices into a serial stream) + *----------------------------------------------------------------*/ + j = 0; + move16(); + for ( i = 0; i < num_indices; i++ ) + { + if ( ind_list[i].nb_bits != -1 ) + { + /* mask from MSB to LSB */ + mask = 1 << ( ind_list[i].nb_bits - 1 ); + + /* write bit by bit */ + for ( k = 0; k < ind_list[i].nb_bits; k++ ) + { + pack_bit( ind_list[i].value & mask, &pt_pFrame, &omask ); + j++; + mask >>= 1; + } + nb_bits_tot = add( nb_bits_tot, ind_list[i].nb_bits ); + } + } + + *pFrame_size = add( *pFrame_size, nb_bits_tot ); + + return; } static void decoder_selectCodec( - Decoder_State *st, /* i/o: decoder state structure */ - const Word32 total_brate, /* i : total bitrate */ - const Word16 bit0 -) + Decoder_State *st, /* i/o: decoder state structure */ + const Word32 total_brate, /* i : total bitrate */ + const Word16 bit0 ) { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - /* check if we are in AMR-WB IO mode */ - IF(EQ_32(total_brate, SID_1k75) || - EQ_32(total_brate, ACELP_6k60) || EQ_32(total_brate, ACELP_8k85) || EQ_32(total_brate, ACELP_12k65) || - EQ_32(total_brate, ACELP_14k25) || EQ_32(total_brate, ACELP_15k85) || EQ_32(total_brate, ACELP_18k25) || - EQ_32(total_brate, ACELP_19k85) || EQ_32(total_brate, ACELP_23k05) || EQ_32(total_brate, ACELP_23k85)) - { - st->Opt_AMR_WB = 1; - move16(); - } - ELSE IF(NE_32(total_brate, FRAME_NO_DATA)) - { - st->Opt_AMR_WB = 0; - move16(); - } - - /* select MODE1 or MODE2 */ - IF(st->Opt_AMR_WB) - { - st->codec_mode = MODE1; - move16();/**/ - } - ELSE - { - SWITCH(total_brate) - { - case 0: - st->codec_mode = st->last_codec_mode; - move16(); - BREAK; - case 2400: - st->codec_mode = st->last_codec_mode; - move16(); - BREAK; - case 2800: - st->codec_mode = MODE1; - move16(); - BREAK; - case 7200: - st->codec_mode = MODE1; - move16(); - BREAK; - case 8000: - st->codec_mode = MODE1; - move16(); - BREAK; - case 9600: - st->codec_mode = MODE2; - move16(); - BREAK; - case 13200: - st->codec_mode = MODE1; - move16(); - BREAK; - case 16400: - st->codec_mode = MODE2; - move16(); - BREAK; - case 24400: - st->codec_mode = MODE2; - move16(); - BREAK; - case 32000: - st->codec_mode = MODE1; - move16(); - BREAK; - case 48000: - st->codec_mode = MODE2; - move16(); - BREAK; - case 64000: - st->codec_mode = MODE1; - move16(); - BREAK; - case 96000: - st->codec_mode = MODE2; - move16(); - BREAK; - case 128000: - st->codec_mode = MODE2; - move16(); - BREAK; - default: - /* validate that total_brate (derived from RTP packet or a file header) is one of the defined bit rates */ - st->codec_mode = st->last_codec_mode; - st->bfi = 1; - move16(); - move16(); - BREAK; - } - } - - IF(st->ini_frame == 0) - { - IF(EQ_16(st->codec_mode, -1)) - { - st->codec_mode = MODE1; - move16(); - } - st->last_codec_mode = st->codec_mode; - move16(); - } - - /* set SID/CNG type */ - IF(EQ_32(total_brate, SID_2k40)) - { - IF(bit0 == G192_BIN0) - { - st->cng_type = LP_CNG; - move16(); - - /* force MODE1 when selecting LP_CNG */ - st->codec_mode = MODE1; - move16(); - } - ELSE - { - st->cng_type = FD_CNG; - test(); - if (EQ_16(st->last_codec_mode, MODE2) && EQ_32(st->last_total_brate,13200)) - { - st->codec_mode = MODE1; - move16(); - } - } - st->hTdCngDec->last_cng_type_fx = st->cng_type; /* CNG type switching at the first correctly received SID frame */ - } - - - return; -} + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + /* check if we are in AMR-WB IO mode */ + IF( EQ_32( total_brate, SID_1k75 ) || + EQ_32( total_brate, ACELP_6k60 ) || EQ_32( total_brate, ACELP_8k85 ) || EQ_32( total_brate, ACELP_12k65 ) || + EQ_32( total_brate, ACELP_14k25 ) || EQ_32( total_brate, ACELP_15k85 ) || EQ_32( total_brate, ACELP_18k25 ) || + EQ_32( total_brate, ACELP_19k85 ) || EQ_32( total_brate, ACELP_23k05 ) || EQ_32( total_brate, ACELP_23k85 ) ) + { + st->Opt_AMR_WB = 1; + move16(); + } + ELSE IF( NE_32( total_brate, FRAME_NO_DATA ) ) + { + st->Opt_AMR_WB = 0; + move16(); + } + /* select MODE1 or MODE2 */ + IF( st->Opt_AMR_WB ) + { + st->codec_mode = MODE1; + move16(); /**/ + } + ELSE + { + SWITCH( total_brate ) + { + case 0: + st->codec_mode = st->last_codec_mode; + move16(); + BREAK; + case 2400: + st->codec_mode = st->last_codec_mode; + move16(); + BREAK; + case 2800: + st->codec_mode = MODE1; + move16(); + BREAK; + case 7200: + st->codec_mode = MODE1; + move16(); + BREAK; + case 8000: + st->codec_mode = MODE1; + move16(); + BREAK; + case 9600: + st->codec_mode = MODE2; + move16(); + BREAK; + case 13200: + st->codec_mode = MODE1; + move16(); + BREAK; + case 16400: + st->codec_mode = MODE2; + move16(); + BREAK; + case 24400: + st->codec_mode = MODE2; + move16(); + BREAK; + case 32000: + st->codec_mode = MODE1; + move16(); + BREAK; + case 48000: + st->codec_mode = MODE2; + move16(); + BREAK; + case 64000: + st->codec_mode = MODE1; + move16(); + BREAK; + case 96000: + st->codec_mode = MODE2; + move16(); + BREAK; + case 128000: + st->codec_mode = MODE2; + move16(); + BREAK; + default: + /* validate that total_brate (derived from RTP packet or a file header) is one of the defined bit rates */ + st->codec_mode = st->last_codec_mode; + st->bfi = 1; + move16(); + move16(); + BREAK; + } + } + IF( st->ini_frame == 0 ) + { + IF( EQ_16( st->codec_mode, -1 ) ) + { + st->codec_mode = MODE1; + move16(); + } + st->last_codec_mode = st->codec_mode; + move16(); + } + /* set SID/CNG type */ + IF( EQ_32( total_brate, SID_2k40 ) ) + { + IF( bit0 == G192_BIN0 ) + { + st->cng_type = LP_CNG; + move16(); + + /* force MODE1 when selecting LP_CNG */ + st->codec_mode = MODE1; + move16(); + } + ELSE + { + st->cng_type = FD_CNG; + test(); + if ( EQ_16( st->last_codec_mode, MODE2 ) && EQ_32( st->last_total_brate, 13200 ) ) + { + st->codec_mode = MODE1; + move16(); + } + } + st->hTdCngDec->last_cng_type_fx = st->cng_type; /* CNG type switching at the first correctly received SID frame */ + } + + + return; +} + + +void dec_prm_core( Decoder_State *st ) +{ + Word16 n, frame_size_index, num_bits; + UWord16 lsb; + Word32 L_tmp; + + frame_size_index = -1; + move16(); + st->core = -1; + move16(); + + IF( EQ_32( st->total_brate, FRAME_NO_DATA ) ) + { + st->m_frame_type = ZERO_FRAME; + move16(); + } + ELSE IF( EQ_32( st->total_brate, SID_2k40 ) ) + { + st->m_frame_type = SID_FRAME; + move16(); + } + ELSE + { + st->m_frame_type = ACTIVE_FRAME; + move16(); + Mpy_32_16_ss( st->total_brate, 5243, &L_tmp, &lsb ); /* 5243 is 1/50 in Q18. (0+18-15=3) */ + num_bits = extract_l( L_shr( L_tmp, 3 ) ); /* Q0 */ + assert( num_bits == st->total_brate / 50 ); + FOR( n = 0; n < FRAME_SIZE_NB; ++n ) + { + IF( EQ_16( FrameSizeConfig[n].frame_bits, num_bits ) ) + { + frame_size_index = n; + move16(); + BREAK; + } + } + + /* Get bandwidth mode */ + st->bwidth = get_next_indice( st, FrameSizeConfig[frame_size_index].bandwidth_bits ); + + st->bwidth = add( st->bwidth, FrameSizeConfig[frame_size_index].bandwidth_min ); + + if ( GT_16( st->bwidth, FB ) ) + { + st->bwidth = FB; + move16(); + st->BER_detect = 1; + move16(); + } + + if ( GT_16( st->bwidth, SWB ) && LT_32( st->total_brate, ACELP_16k40 ) ) + { + st->bwidth = SWB; + move16(); + st->BER_detect = 1; + move16(); + } + + /* Skip reserved bit */ + get_next_indice_tmp_fx( st, FrameSizeConfig[frame_size_index].reserved_bits ); + + IF( get_next_indice_1( st ) != 0 ) /* TCX */ + { + st->core = TCX_20_CORE; + move16(); + if ( get_next_indice_1( st ) != 0 ) + { + st->core = HQ_CORE; + move16(); + } + } + ELSE /* ACELP */ + { + st->core = ACELP_CORE; + move16(); + } + } +} + +/*-----------------------------------------------------------------* + * decision_matrix_core_dec() + * + * Read core mode signalling bits from the bitstream + * Set st->core, and st->bwidth if signalled together with the core. + *-----------------------------------------------------------------*/ + +void decision_matrix_core_dec( + Decoder_State *st /* i/o: decoder state structure */ +) +{ + Word16 start_idx; + Word32 ind; + Word16 nBits; + + assert( st->bfi != 1 ); + + st->core = -1; + move16(); + st->bwidth = -1; + move16(); + + test(); + IF( EQ_32( st->total_brate, FRAME_NO_DATA ) || EQ_32( st->total_brate, SID_2k40 ) ) + { + st->core = ACELP_CORE; + move16(); + } + /* SC-VBR */ + ELSE IF( st->total_brate == PPP_NELP_2k80 ) + { + st->core = ACELP_CORE; + move16(); + return; + } + + /*---------------------------------------------------------------------* + * ACELP/HQ core selection + *---------------------------------------------------------------------*/ + + test(); + IF( LT_32( st->total_brate, ACELP_24k40 ) ) + { + st->core = ACELP_CORE; + move16(); + } + ELSE IF( GE_32( st->total_brate, ACELP_24k40 ) && LE_32( st->total_brate, ACELP_64k ) ) + { + /* read the ACELP/HQ core selection bit */ + st->core = imult1616( get_next_indice( st, 1 ), HQ_CORE ); + } + ELSE + { + st->core = HQ_CORE; + move16(); + } + + /*-----------------------------------------------------------------* + * Read ACELP signalling bits from the bitstream + *-----------------------------------------------------------------*/ + + IF( EQ_16( st->core, ACELP_CORE ) ) + { + /* find the section in the ACELP signalling table corresponding to bitrate */ + start_idx = 0; + move16(); + WHILE( NE_32( acelp_sig_tbl[start_idx], st->total_brate ) ) + { + start_idx = add( start_idx, 1 ); + } + + /* skip the bitrate */ + start_idx = add( start_idx, 1 ); + + /* retrieve the number of bits */ + nBits = extract_l( acelp_sig_tbl[start_idx] ); + start_idx = add( start_idx, 1 ); + + /* retrieve the signalling indice */ + ind = acelp_sig_tbl[add( start_idx, get_next_indice( st, nBits ) )]; + st->bwidth = extract_l( L_and( L_shr( ind, 3 ), 0x7 ) ); + + /* convert signalling indice into signalling information */ + if ( EQ_32( L_and( ind, 0x7 ), LR_MDCT ) ) + { + st->core = HQ_CORE; + move16(); + } + } + + /*-----------------------------------------------------------------* + * Read HQ signalling bits from the bitstream + * Set HQ core type + *-----------------------------------------------------------------*/ + + IF( EQ_16( st->core, HQ_CORE ) ) + { + /* read the HQ/TCX core switching flag */ + if ( get_next_indice( st, 1 ) != 0 ) + { + st->core = TCX_20_CORE; + move16(); + } + + /* For TCX: read/set band-width (needed for different I/O sampling rate support) */ + test(); + IF( EQ_16( st->core, TCX_20_CORE ) && GT_32( st->total_brate, ACELP_16k40 ) ) + { + ind = get_next_indice( st, 2 ); + + IF( ind == 0 ) + { + st->bwidth = NB; + move16(); + } + ELSE IF( EQ_32( ind, 1 ) ) + { + st->bwidth = WB; + move16(); + } + ELSE IF( EQ_32( ind, 2 ) ) + { + st->bwidth = SWB; + move16(); + } + ELSE + { + st->bwidth = FB; + move16(); + } + } + } + + return; +} + +/*-------------------------------------------------------------------* + * mdct_switching_dec() + * + * Set up MDCT core switching if indicated in the bit stream + *-------------------------------------------------------------------*/ + +static void mdct_switching_dec( + Decoder_State *st /* i/o: decoder state structure */ +) +{ + IF( st->Opt_AMR_WB != 0 ) + { + return; + } + + test(); + test(); + IF( EQ_32( st->total_brate, ACELP_13k20 ) || EQ_32( st->total_brate, ACELP_32k ) ) + { + st->mdct_sw_enable = MODE1; + move16(); + } + ELSE IF( LE_32( ACELP_16k40, st->total_brate ) && LE_32( st->total_brate, ACELP_24k40 ) ) + { + st->mdct_sw_enable = MODE2; + move16(); + } + + test(); + test(); + IF( EQ_16( st->codec_mode, MODE1 ) && EQ_16( st->mdct_sw_enable, MODE1 ) ) + { + /* Read ahead core mode signaling */ + Word16 next_bit_pos_save; + Word16 core_save; + Word16 bwidth_save; + + next_bit_pos_save = st->next_bit_pos; + move16(); + core_save = st->core; + move16(); + bwidth_save = st->bwidth; + move16(); + + decision_matrix_core_dec( st ); /* sets st->core */ + + IF( EQ_16( st->core, TCX_20_CORE ) ) + { + /* Trigger TCX */ + st->codec_mode = MODE2; + move16(); + st->mdct_sw = MODE1; + move16(); + } + ELSE + { + /* Rewind bitstream */ + st->next_bit_pos = next_bit_pos_save; + move16(); + IF( st->bfi != 0 ) + { + st->core = core_save; + move16(); + st->bwidth = bwidth_save; + move16(); + } + } + } + ELSE IF( EQ_16( st->codec_mode, MODE2 ) && EQ_16( st->mdct_sw_enable, MODE2 ) ) + { + /* Read ahead core mode signaling */ + Word16 next_bit_pos_save; + Word16 core_save; + Word16 bwidth_save; + + next_bit_pos_save = st->next_bit_pos; + move16(); + core_save = st->core; + move16(); + bwidth_save = st->bwidth; + move16(); + + dec_prm_core( st ); /* sets st->core */ + + IF( EQ_16( st->core, HQ_CORE ) ) + { + /* Trigger HQ_CORE */ + st->codec_mode = MODE1; + move16(); + st->mdct_sw = MODE2; + move16(); + } + ELSE + { + /* Rewind bitstream */ + st->next_bit_pos = next_bit_pos_save; + move16(); + IF( st->bfi != 0 ) + { + st->core = core_save; + move16(); + } + /* always reset bwidth, to not interfere with BER logic */ + st->bwidth = bwidth_save; + move16(); + } + } +} + +/*-------------------------------------------------------------------* + * BRATE2IDX_fx() + * + * Convert Bitrate to Index Value + *-------------------------------------------------------------------*/ + +Word16 BRATE2IDX_fx( Word32 brate ) +{ + + Word32 L_temp; + Word32 L_idx; +#define START 9 + extern const Word16 bit_rates_div50[]; + + /* This is a Fast Bit Rate Value to Index Value Binary Search */ + L_temp = L_msu0( brate, bit_rates_div50[START], 50 ); + L_temp = L_min( 6, L_max( -6, L_temp ) ); + L_idx = L_add( L_temp, START ); + L_temp = L_msu0( brate, bit_rates_div50[L_idx], 50 ); + L_temp = L_min( 3, L_max( -3, L_temp ) ); + L_idx = L_add( L_temp, L_idx ); + L_temp = L_msu0( brate, bit_rates_div50[L_idx], 50 ); + L_temp = L_min( 1, L_max( -2, L_temp ) ); + L_idx = L_add( L_temp, L_idx ); + L_temp = L_msu0( brate, bit_rates_div50[L_idx], 50 ); + if ( L_temp != 0 ) + L_idx = L_add( L_idx, 1 ); + return (Word16) L_idx; +} + + +/*-------------------------------------------------------------------* + * BRATE2IDX16k_fx() + * + * Convert Bitrate to Index Value + *-------------------------------------------------------------------*/ + +Word16 BRATE2IDX16k_fx( Word32 brate ) +{ + Word32 L_temp, L_idx; +#define START_16K 5 + extern const Word16 bit_rates_16k_div50[]; + + if ( EQ_32( brate, ACELP_16k40 ) ) + { + brate = ACELP_14k80; + } + + /* This is a Fast Bit Rate Value to Index Value Binary Search */ + L_temp = L_msu0( brate, bit_rates_16k_div50[START_16K], 50 ); + L_temp = L_min( 3, L_max( -3, L_temp ) ); + L_idx = L_add( L_temp, START_16K ); + L_temp = L_msu0( brate, bit_rates_16k_div50[L_idx], 50 ); + L_temp = L_min( 2, L_max( -2, L_temp ) ); + L_idx = L_add( L_temp, L_idx ); + L_temp = L_msu0( brate, bit_rates_16k_div50[L_idx], 50 ); + L_temp = L_min( 1, L_max( -1, L_temp ) ); + L_idx = L_add( L_temp, L_idx ); + + return (Word16) L_idx; +} + +/*-------------------------------------------------------------------* + * BIT_ALLOC_IDX_fx() + *-------------------------------------------------------------------*/ + +Word32 BIT_ALLOC_IDX_fx( Word32 brate, Word16 ctype, Word16 sfrm, Word16 tc ) +{ + Word32 L_temp; + Word16 temp; + if ( ctype == INACTIVE ) /* no sub(ctype, INACTIVE) because it is '0' */ + ctype = GENERIC; + move16(); + L_temp = L_mac0( -1l * 256, 1 * 256, ctype ); + + temp = BRATE2IDX_fx( brate ); + L_temp = L_mac0( L_temp, 4 * 256, temp ); + if ( tc >= 0 ) + L_temp = L_mac0( L_temp, ( 10 - 4 ) * 256, temp ); + /* So either 'temp' x 4 when 'tc < 0', 'temp' x 10 otherwise */ + + L_temp = L_mac0( L_temp, 1 * 256, s_max( 0, tc ) ); + + L_temp = L_mac0( L_temp, s_max( 0, sfrm ), 1 ); + if ( sfrm < 0 ) + L_temp = L_shr( L_temp, 2 ); + L_temp = L_shr( L_temp, 6 ); + + return L_temp; +} + +/*-------------------------------------------------------------------* + * BIT_ALLOC_IDX_16KHZ_fx() + *-------------------------------------------------------------------*/ + +Word32 BIT_ALLOC_IDX_16KHZ_fx( Word32 brate, Word16 ctype, Word16 sfrm, Word16 tc ) +{ + Word32 L_temp; + Word16 temp; + /* 'ctype' = + TRANSITION => 2 + GENERIC => 1 + ALL Other => 0 + */ + L_temp = L_and( shr( 0x0240l, shl( ctype, 1 ) ), 3 ); + + temp = BRATE2IDX16k_fx( brate ); + L_temp = L_mac0( L_temp, 3, temp ); + if ( tc >= 0 ) + L_temp = L_mac0( L_temp, ( 7 - 3 ), temp ); + /* So either 'temp' x 3 when 'tc < 0', 'temp' x 7 otherwise */ + + L_temp = L_mac0( L_temp, 1, s_max( 0, tc ) ); + + IF( sfrm >= 0 ) + { + /* Mult by 5 */ + L_temp = L_add( L_temp, L_shl( L_temp, 2 ) ); + L_temp = L_mac0( L_temp, shr( sfrm, 6 ), 1 ); + } + + return L_temp; +} + + +/*-------------------------------------------------------------------* + * read_indices_fx() + * + * Read indices from an ITU-T G.192 bitstream to the buffer + * Simulate packet losses by inserting frame erasures + *-------------------------------------------------------------------*/ + +Word16 read_indices_fx( /* o : 1 = reading OK, 0 = problem */ + Decoder_State *st, /* i/o: decoder state structure */ + FILE *file, /* i : bitstream file */ + Word16 rew_flag /* i : rewind flag (rewind file after reading)*/ +) +{ + Word16 k; + UWord16 utmp, stream[2 + MAX_BITS_PER_FRAME], *pt_stream, *bit_stream_ptr; + Word16 num_bits; + Word32 total_brate; + Word32 L_tmp; + Word16 curr_ft_good_sp, curr_ft_bad_sp; + Word16 g192_sid_first, sid_upd_bad, sid_update; + Word16 speech_bad, speech_lost; + Word16 num_bits_read; + + st->bfi = 0; + st->BER_detect = 0; + st->mdct_sw_enable = 0; + st->mdct_sw = 0; + reset_indices_dec_fx( st ); + + /* read the Sync Header field from the bitstream */ + /* in case rew_flag is set, read until first good frame is encountered */ + do + { + /* read the Sync header */ + if ( fread( &utmp, sizeof( unsigned short ), 1, file ) != 1 ) + { + if ( ferror( file ) ) + { + /* error during reading */ + fprintf( stderr, "\nError reading the bitstream !" ); + exit( -1 ); + } + else + { + /* end of file reached */ + return 0; + } + } + + /* set the BFI indicator according the value of Sync Header */ + if ( EQ_16( utmp, SYNC_BAD_FRAME ) ) + { + st->bfi = 1; + } + + + else + { + st->bfi = 0; + } + + /* read the Frame Length field from the bitstream */ + if ( fread( &num_bits, sizeof( unsigned short ), 1, file ) != 1 ) + { + if ( ferror( file ) ) + { + /* error during reading */ + fprintf( stderr, "\nError reading the bitstream !" ); + exit( -1 ); + } + else + { + /* end of file reached */ + return 0; + } + } + /* convert the frame length to total bitrate */ + total_brate = (long) ( num_bits * 50 ); + + /* read ITU-T G.192 serial stream of indices from file to the local buffer */ + /* Validate that the G.192 length is within the defined bit rate range + to not allow writing past the end of the "stream" buffer */ + if ( num_bits > MAX_BITS_PER_FRAME ) + { + fprintf( stderr, "\nError, too large G.192 frame (size(%d))! Exiting ! \n", num_bits ); + exit( -1 ); + } + + /* verify that a valid num bits value is present in the G.192 file */ + /* only AMRWB or EVS bit rates or 0(NO DATA) are allowed in G.192 file frame reading */ + if ( rate2EVSmode( total_brate, NULL ) < 0 ) /* negative value means that a valid rate was not found */ + { + fprintf( stderr, "\nError, illegal bit rate (%d) in the G.192 frame ! Exiting ! \n", total_brate ); + exit( -1 ); + } + pt_stream = stream; + + num_bits_read = (Word16) fread( pt_stream, sizeof( unsigned short ), num_bits, file ); + + if ( num_bits_read != num_bits ) + { + fprintf( stderr, "\nError, invalid number of bits read ! Exiting ! \n" ); + exit( -1 ); + } + + } while ( rew_flag && ( st->bfi || LT_32( total_brate, 2800 ) ) ); + + /* G.192 RX DTX handler*/ + if ( !rew_flag ) + { + /* handle SID_FIRST, SID_BAD, SPEECH_LOST, NO_DATA as properly as possible for the ITU-T G.192 format */ + + /* (total_brate, bfi , st_CNG) = rx_handler(received frame type, [previous frame type], past CNG state, past core) */ + curr_ft_good_sp = 0; + curr_ft_bad_sp = 0; + + if ( total_brate > SID_2k40 ) + { + if ( st->bfi == 0 ) + { + curr_ft_good_sp = 1; + } + else + { + curr_ft_bad_sp = 1; + } + } + sid_update = 0; + sid_upd_bad = 0; + + if ( total_brate == SID_1k75 || total_brate == SID_2k40 ) + { + if ( st->bfi == 0 ) + { + sid_update = 1; + } + else + { + sid_upd_bad = 1; /* may happen in CS , corrupt but detected sid frame */ + } + } + + /* all zero indeces/bits iSP AMRWB SID_update results in a valid LP filter with extremely high LP-filter-gain */ + /* all zero indeces/bits may be a result of CS bit errors and/or erroneously injected by gateways or by a bad dejitter handlers */ + if ( total_brate == SID_1k75 && sid_update == 1 ) + { + /* valid sid_update received, check for very risky but formally valid content */ + Word16 sum = 0; + for ( k = 0; k < num_bits; ++k ) + { + sum += ( pt_stream[k] == G192_BIN1 ); /* check of 35 zeroes, 35 ones */ + } + if ( sum == 0 ) + { /* all zeros */ + sid_upd_bad = 1; /* initial signal as corrupt (BER likley) */ + } + } + + /* AMRWB 26.173 G.192 file reader (read_serial) does not declare/use SID_BAD ft, + it declares every bad synch marked frame initially as a lost_speech frame, + and then the RXDTX handler CNG state decides the decoding mode CNG/SPEECH. + While In the AMRWB ETSI/3GPP format eid a CRC error in a detected SID_UPDATE frame triggers SID_UPD_BAD. + + Here we inhibit use of the SID-length info, even though it is available in the G.192 file format after STL/EID-XOR . + */ + if ( sid_upd_bad ) + { + sid_upd_bad = 0; + total_brate = FRAME_NO_DATA; /* treat SID_BAD as a stolen signaling frame --> SPEECH LOST */ + } + + g192_sid_first = 0; + if ( st->core == AMR_WB_CORE && st->prev_ft_speech_fx && total_brate == FRAME_NO_DATA && st->bfi == 0 ) + { + g192_sid_first = 1; /* SID_FIRST detected for previous AMRWB/AMRWBIO active frames only */ + /* + It is not possible to perfectly simulate rate switching conditions EVS->AMRWBIO where: + the very first SID_FIRST detection is based on a past EVS active frame + and a good length 0 "SID_FIRST"(NO_DATA) frame is sent in AMRWBIO, + , due to the one frame state memory in the AMRWB legacy G.192 SID_FIRST encoding + */ + } + + speech_bad = 0; + if ( total_brate > SID_2k40 && st->bfi != 0 ) /* CS-type of CRC failure frame */ + { + speech_bad = 1; /* initial assumption, CNG_state decides what to do */ + } + + speech_lost = 0; + if ( total_brate == 0 && st->bfi != 0 ) /* unsent NO_DATA or stolen NO_DATA/signaling frame */ + { + speech_lost = 1; /* initial assumption, CNG_state decides what to do */ + } + + /* Do not allow decoder to enter CNG-synthesis for any instantly received GOOD+LENGTH==0 frame + as this frame was never transmitted, one can not know it is good and has a a length of zero ) */ + + if ( st->CNG_fx != 0 ) + { + /* We were in CNG synthesis */ + if ( curr_ft_good_sp != 0 ) + { + /* only a good speech frame makes you leave CNG synthesis */ + st->CNG_fx = 0; + } + } + else + { + /* We were in SPEECH synthesis */ + /* only a received SID frame can make the decoder enter into CNG synthsis */ + if ( g192_sid_first || sid_update || sid_upd_bad ) + { + st->CNG_fx = 1; + } + } + + /* handle the g.192 _simulated_ untransmitted frame, setting for decoder SPEECH synthesis */ + if ( ( st->CNG_fx == 0 ) && ( total_brate == 0 && st->bfi == 0 ) ) + { + st->bfi = 1; + move16(); /* SPEECH PLC code will now become active as in a real system */ + /* total_brate= 0 */ + } + + /* handle bad speech frame(and bad sid frame) in the decoders CNG synthesis settings pair (total_brate, bfi) */ + if ( ( ( st->CNG_fx != 0 ) && ( ( speech_bad != 0 ) || ( speech_lost != 0 ) ) ) || /* SP_BAD or SPEECH_LOST) --> stay in CNG */ + ( sid_upd_bad != 0 ) ) /* SID_UPD_BAD --> start CNG */ + { + st->bfi = 0; + total_brate = 0; + } + /* update for next frame's G.192 file format's SID_FIRST detection (primarily for AMRWBIO) */ + st->prev_ft_speech_fx = ( ( curr_ft_good_sp != 0 ) || ( curr_ft_bad_sp != 0 ) ); + + /* st->total brate= total_brate ; updated in a good frame below */ + } /* rew_flag */ + + /* get total bit-rate */ +#ifdef DEBUGGING + st->bfi |= file_read_FECpattern(); +#endif + if ( st->bfi == 0 && !rew_flag ) + { + /* select MODE1 or MODE2 */ + decoder_selectCodec( st, total_brate, *pt_stream ); + } + + Mpy_32_16_ss( total_brate, 5243, &L_tmp, &utmp ); /* 5243 is 1/50 in Q18. (0+18-15=3) */ + st->total_num_bits = extract_l( L_shr( L_tmp, 3 ) ); /* Q0 */ + + /* in case rew_flag is set, rewind the file and return */ + /* (used in io_enc() to print out info about technologies and to initialize the codec) */ + if ( rew_flag ) + { + rewind( file ); + st->total_brate = total_brate; + move16(); + return 1; + } + + /* GOOD frame */ + if ( st->bfi == 0 ) + { + /* GOOD frame - convert ITU-T G.192 words to short values */ + bit_stream_ptr = st->bit_stream; + + for ( k = 0; k < num_bits; ++k ) + { + *bit_stream_ptr++ = ( *pt_stream++ == G192_BIN1 ); + } + + /*add two zero bytes for arithmetic coder flush*/ + for ( k = 0; k < 2 * 8; ++k ) + { + *bit_stream_ptr++ = 0; + } + /*a change of the total bitrate should not be + known to the decoder, if the received frame was lost*/ + st->total_brate = total_brate; + + mdct_switching_dec( st ); + } +#ifdef DEBUGGING + else + { + bit_stream_ptr = st->bit_stream; + + for ( k = 0; k < num_bits + 2 * 8; ++k ) + { + *bit_stream_ptr++ = 0; + } + } +#endif + return 1; +} + + +/*-------------------------------------------------------------------* + * read_indices_mime_handle_dtx() + * + * Handle DTX for MIME and RTP_DUMP decoding. + * Returns the actual total_brate. + *-------------------------------------------------------------------*/ + +static Word32 read_indices_mime_handle_dtx( + Decoder_State *st, + Word16 isAMRWB_IOmode, + Word16 core_mode, + Word32 total_brate, + Word16 sti, + Word16 speech_lost, + Word16 no_data ) +{ + Word16 curr_ft_good_sp = 0; + Word16 speech_bad = 0; + Word16 sid_upd_bad = 0, sid_update = 0; + Word16 amrwb_sid_first = 0; /* derived from sti SID_FIRST indicator in AMRWB payload */ + + /* keep st->CNG , st_bfi and total_brate updated for proper synthesis in DTX and FER */ + if ( GT_32( total_brate, SID_2k40 ) ) + { + if ( st->bfi != 1 ) /* so far derived from q bit in AMRWB/AMRWBIO cases */ + { + curr_ft_good_sp = 1; + } + } + + /* handle q_bit and lost_sp clash , assume worst case */ + if ( speech_lost != 0 ) /* overrides a good q_bit */ + { + curr_ft_good_sp = 0; + st->bfi = 1; /* override qbit */ + } + + /* now_bfi_fx has been set based on q_bit and ToC fields */ + + + /* SID_UPDATE check */ + if ( total_brate == SID_1k75 || total_brate == SID_2k40 ) + { + if ( st->bfi == 0 ) + { + /* typically from q bit */ + sid_update = 1; + } + else + { + sid_upd_bad = 1; /* may happen in saving from e.g. a CS-connection */ + } + } + + if ( isAMRWB_IOmode && total_brate == 0 && sti == 0 ) + { + if ( st->bfi ) + { + sid_upd_bad = 1; /* corrupt sid_first, signaled as bad sid */ + } + else + { + amrwb_sid_first = 1; /* 1-sti */ + } + } + + if ( sid_upd_bad != 0 && ( ( isAMRWB_IOmode != 0 && st->Opt_AMR_WB == 0 ) || /* switch to AMRWBIO */ + ( isAMRWB_IOmode != 1 && st->Opt_AMR_WB == 1 ) /* switch from AMRWBIO */ + ) ) + { + /* do not allow a normal start of CNG synthesis if this SID(with BER or FER) is a switch to/from AMRWBIO */ + sid_upd_bad = 0; /* revert this detection due to AMRWBIO/EVS mode switch */ + total_brate = 0; + no_data = 1; + assert( st->bfi == 1 ); /* bfi stays 1 */ + } + + if ( GT_32( total_brate, SID_2k40 ) && st->bfi == 1 ) /* typically from q bit */ + { + speech_bad = 1; /* initial assumption, CNG synt state decides what to actually do */ + } + /* all frame types decoded */ + + /* update CNG synthesis state */ + /* Decoder can only enter CNG-synthesis for CNG frame types (sid_upd, sid_bad, sid_first) */ + if ( st->CNG_fx != 0 ) + { + /* We were in CNG synthesis */ + if ( curr_ft_good_sp != 0 ) + { + /* only a good speech frame makes decoder leave CNG synthesis */ + st->CNG_fx = 0; + } + } + else + { + /* We were in SPEECH synthesis */ + /* only a received SID frame can make the decoder enter into CNG synthesis */ + if ( amrwb_sid_first || sid_update || sid_upd_bad ) + { + st->CNG_fx = 1; + } + } + + /* Now modify bfi flag for the decoder's SPEECH/CNG synthesis logic */ + /* in SPEECH synthesis, make sure to activate speech plc for a received no_data frame, + no_data frames may be injected by the network or by the dejitter buffer */ + /* modify bfi_flag to stay/move into the correct decoder PLC section */ + if ( ( st->CNG_fx == 0 ) && ( no_data != 0 ) ) + { + /* treat no_data received in speech synthesis as SP_LOST frames, SPEECH PLC code will now become active */ + st->bfi = 1; + /* total_brate= 0; always zero for no_data */ + } + + /* in CNG */ + /* handle bad speech frame(and bad sid frame) in the decoders CNG synthesis settings pair (total_brate, bfi) */ + if ( ( st->CNG_fx != 0 && ( speech_bad || speech_lost || no_data ) ) || /* SP_BAD or SPEECH_LOST) --> stay in CNG */ + sid_upd_bad ) /* SID_UPD_BAD --> start/stay CNG */ + { + st->bfi = 0; /* mark as good to not start speech PLC */ + total_brate = 0; /* this zeroing needed for speech_bad, sid_bad frames */ + } + + + /* now bfi, total_brate are set by RX-DTX handler:: + bfi==0, total_brate!=0 cng or speech pending bitrate + bfi==0, total_brate==0 cng will continue or start(sid_first, sid_bad) + bfi==1, total_brate!=0 speech plc + bfi==1, total_brate==0 , speech plc + */ + + + /* handle available AMRWB/AMRWBIO MIME header ToC rate-info at startup */ + if ( ( st->bfi == 1 && st->ini_frame == 0 ) && + ( ( st->amrwb_rfc4867_flag != 0 ) || ( st->amrwb_rfc4867_flag == 0 && isAMRWB_IOmode != 0 ) ) ) /*AMRWB ToC */ + { + Word32 init_rate; + + init_rate = total_brate; /* default , may have been modified from original ToC value */ + if ( speech_lost != 0 || no_data != 0 ) + { + init_rate = ACELP_12k65; /* make sure the decoder starts up in a selected AMRWB mode */ + } + else if ( speech_bad != 0 ) + { + init_rate = AMRWB_IOmode2rate[core_mode]; /* read from from ToC */ + } + st->total_brate = init_rate; /* not updated on bfi as decoderSelectCodec is not called below */ + st->core_brate = init_rate; + } + + return total_brate; +} + + +/*-------------------------------------------------------------------* + * read_indices_mime_handle_sti_and_all_zero_bits() + * + * Handle STI and frames with all zero bits for MIME and RTP_DUMP decoding. + *-------------------------------------------------------------------*/ + +static void read_indices_mime_handle_sti_and_all_zero_bits( + Decoder_State *st, + Word32 *total_brate, + Word16 sti ) +{ + Word16 k; + + if ( sti == 0 ) + { + *total_brate = 0; /* signal received SID_FIRST as a good frame with no bits */ + for ( k = 0; k < 35; k++ ) + { + st->bfi |= st->bit_stream[k]; /* partity check of 35 zeroes, any single 1 gives BFI */ + } + } + /* all zero bit SID_update results in a valid LP filter with extremely high LP-filter-gain */ + /* all zero bits signal may be a result of CS bit errors or erronesouly injected by gateways or bad dejitter handlers */ + if ( sti == 1 ) + { /*sid_update received */ + Word16 sum = 0; + for ( k = 0; k < 35; k++ ) + { + sum += st->bit_stream[k]; /* check of 35 zeroes */ + } + + if ( sum == 0 ) + { + st->bfi = 1; /* eventually becomes SID_UPD_BAD */ + } + } +} + + +/*------------------------------------------------------------------------------------------* + * read_indices_mime() + * + * Read indices from MIME formatted bitstream to the buffer + * The magic word and number of channnels should be consumed before calling this function + *-------------------------------------------------------------------------------------------*/ + +Word16 read_indices_mime( /* o : 1 = reading OK, 0 = problem */ + Decoder_State *st, /* i/o: decoder state structure */ + FILE *file, /* i : bitstream file */ + Word16 rew_flag /* i : rewind flag (rewind file after reading) */ +) +{ + Word16 k, isAMRWB_IOmode, cmi, core_mode = -1, qbit, sti; + UWord8 header; + UWord8 pFrame[( MAX_BITS_PER_FRAME + 7 ) >> 3]; + UWord8 mask = 0x80, *pt_pFrame = pFrame; + UWord16 *bit_stream_ptr; + Word16 num_bits; + Word32 total_brate; + UWord16 utmp; + Word32 L_tmp; + Word16 speech_lost = 0, no_data = 0; + Word16 num_bytes_read; + + st->BER_detect = 0; + st->bfi = 0; + st->mdct_sw_enable = 0; + st->mdct_sw = 0; + reset_indices_dec_fx( st ); + + /* read the FT Header field from the bitstream */ + if ( fread( &header, sizeof( UWord8 ), 1, file ) != 1 ) + { + if ( ferror( file ) ) + { + /* error during reading */ + fprintf( stderr, "\nError reading the bitstream !" ); + exit( -1 ); + } + else + { + /* end of file reached */ + return 0; + } + } + + /* init local RXDTX flags */ + sti = -1; + + if ( st->amrwb_rfc4867_flag != 0 ) + { + /* RFC 4867 + 5.3 .... + Each stored speech frame starts with a one-octet frame header with + the following format: + 0 1 2 3 4 5 6 7 + +-+-+-+-+-+-+-+-+ + |P| FT |Q|P|P| + +-+-+-+-+-+-+-+-+ + The FT field and the Q bit are defined in the same way as in + Section 4.3.2. The P bits are padding and MUST be set to 0, and MUST be ignored. */ + + isAMRWB_IOmode = 1; + qbit = ( header >> 2 ) & 0x01; /* b2 bit (b7 is the F bit ) */ + st->bfi = !qbit; + core_mode = ( ( header >> 3 ) & 0x0F ); /* b6..b3 */ + total_brate = AMRWB_IOmode2rate[core_mode]; /* get the frame length from the header */ + } + else + { + /*0 1 2 3 4 5 6 7 MS-bit ---> LS-bit + +-+-+-+-+-+-+-+-+ + |H|F|E|x| brate | + +-+-+-+-+-+-+-+-+ + where : + "E|x| brate " is the 6 bit "FT" -field + x is unused if E=0, (should be 0 ) + x is the q-bit if E=1, q==1(good), Q==0(bad, maybe bit errors in payload ) + H,F always 0 in RTP format. + */ + isAMRWB_IOmode = ( header & 0x20 ) > 0; /* get EVS mode-from header */ /* b2 */ + core_mode = ( header & 0x0F ); /* b4,b5,b6,b7 */ + + if ( isAMRWB_IOmode ) + { + qbit = ( header & 0x10 ) > 0; /* get Q bit, valid for IO rates */ /* b3 */ + total_brate = AMRWB_IOmode2rate[core_mode]; + } + else + { + qbit = 1; /* assume good q_bit for the unused EVS-mode bit, complete ToC validity checked later */ + total_brate = PRIMARYmode2rate[core_mode]; + } + st->bfi = !qbit; + } -void dec_prm_core(Decoder_State *st) -{ - Word16 n, frame_size_index, num_bits; - UWord16 lsb; - Word32 L_tmp; - - frame_size_index = -1; - move16(); - st->core = -1; - move16(); - - IF(EQ_32(st->total_brate, FRAME_NO_DATA)) - { - st->m_frame_type = ZERO_FRAME; - move16(); - } - ELSE IF(EQ_32(st->total_brate, SID_2k40)) - { - st->m_frame_type = SID_FRAME; - move16(); - } - ELSE - { - st->m_frame_type = ACTIVE_FRAME; - move16(); - Mpy_32_16_ss(st->total_brate, 5243, &L_tmp, &lsb); /* 5243 is 1/50 in Q18. (0+18-15=3) */ - num_bits = extract_l(L_shr(L_tmp, 3)); /* Q0 */ - assert(num_bits == st->total_brate / 50); - FOR(n = 0; n < FRAME_SIZE_NB; ++n) - { - IF(EQ_16(FrameSizeConfig[n].frame_bits, num_bits)) - { - frame_size_index = n; - move16(); - BREAK; - } - } - - /* Get bandwidth mode */ - st->bwidth = get_next_indice(st, FrameSizeConfig[frame_size_index].bandwidth_bits); - - st->bwidth = add(st->bwidth, FrameSizeConfig[frame_size_index].bandwidth_min); - - if (GT_16(st->bwidth, FB)) - { - st->bwidth = FB; - move16(); - st->BER_detect = 1; - move16(); - } - - if (GT_16(st->bwidth, SWB) && LT_32(st->total_brate,ACELP_16k40)) - { - st->bwidth = SWB; - move16(); - st->BER_detect = 1; - move16(); - } - - /* Skip reserved bit */ - get_next_indice_tmp_fx(st, FrameSizeConfig[frame_size_index].reserved_bits); - - IF(get_next_indice_1(st) != 0) /* TCX */ - { - st->core = TCX_20_CORE; - move16(); - if (get_next_indice_1(st) != 0) - { - st->core = HQ_CORE; - move16(); - } - } - ELSE /* ACELP */ - { - st->core = ACELP_CORE; - move16(); - } - } -} -/*-----------------------------------------------------------------* - * decision_matrix_core_dec() - * - * Read core mode signalling bits from the bitstream - * Set st->core, and st->bwidth if signalled together with the core. - *-----------------------------------------------------------------*/ + /* set up RX-DTX-handler input */ + if ( core_mode == 14 ) + { + /* SP_LOST */ + speech_lost = 1; + } + if ( core_mode == 15 ) + { + /* NO_DATA unsent CNG frame OR any frame marked or injected as no_data by e.g a signaling layer or dejitter buffer */ + no_data = 1; + } -void decision_matrix_core_dec( - Decoder_State *st /* i/o: decoder state structure */ -) -{ - Word16 start_idx; - Word32 ind; - Word16 nBits; - - assert(st->bfi != 1); - - st->core = -1; - move16(); - st->bwidth = -1; - move16(); - - test(); - IF(EQ_32(st->total_brate, FRAME_NO_DATA) || EQ_32(st->total_brate, SID_2k40)) - { - st->core = ACELP_CORE; - move16(); - } - /* SC-VBR */ - ELSE IF(st->total_brate == PPP_NELP_2k80) - { - st->core = ACELP_CORE; - move16(); - return; - } - - /*---------------------------------------------------------------------* - * ACELP/HQ core selection - *---------------------------------------------------------------------*/ - - test(); - IF(LT_32(st->total_brate, ACELP_24k40)) - { - st->core = ACELP_CORE; - move16(); - } - ELSE IF(GE_32(st->total_brate, ACELP_24k40) && LE_32(st->total_brate, ACELP_64k)) - { - /* read the ACELP/HQ core selection bit */ - st->core = imult1616(get_next_indice(st, 1), HQ_CORE); - } - ELSE - { - st->core = HQ_CORE; - move16(); - } - - /*-----------------------------------------------------------------* - * Read ACELP signalling bits from the bitstream - *-----------------------------------------------------------------*/ - - IF(EQ_16(st->core, ACELP_CORE)) - { - /* find the section in the ACELP signalling table corresponding to bitrate */ - start_idx = 0; - move16(); - WHILE(NE_32(acelp_sig_tbl[start_idx], st->total_brate)) - { - start_idx = add(start_idx, 1); - } - - /* skip the bitrate */ - start_idx = add(start_idx, 1); - - /* retrieve the number of bits */ - nBits = extract_l(acelp_sig_tbl[start_idx]); - start_idx = add(start_idx, 1); - - /* retrieve the signalling indice */ - ind = acelp_sig_tbl[add(start_idx, get_next_indice(st, nBits))]; - st->bwidth = extract_l(L_and(L_shr(ind, 3), 0x7)); - - /* convert signalling indice into signalling information */ - if (EQ_32(L_and(ind, 0x7), LR_MDCT)) - { - st->core = HQ_CORE; - move16(); - } - } - - /*-----------------------------------------------------------------* - * Read HQ signalling bits from the bitstream - * Set HQ core type - *-----------------------------------------------------------------*/ - - IF(EQ_16(st->core, HQ_CORE)) - { - /* read the HQ/TCX core switching flag */ - if (get_next_indice(st, 1) != 0) - { - st->core = TCX_20_CORE; - move16(); - } - - /* For TCX: read/set band-width (needed for different I/O sampling rate support) */ - test(); - IF(EQ_16(st->core, TCX_20_CORE) && GT_32(st->total_brate, ACELP_16k40)) - { - ind = get_next_indice(st, 2); - - IF(ind == 0) - { - st->bwidth = NB; - move16(); - } - ELSE IF(EQ_32(ind, 1)) - { - st->bwidth = WB; - move16(); - } - ELSE IF(EQ_32(ind, 2)) - { - st->bwidth = SWB; - move16(); - } - ELSE - { - st->bwidth = FB; - move16(); - } - } - } - - return; -} + Mpy_32_16_ss( total_brate, 5243, &L_tmp, &utmp ); /* 5243 is 1/50 in Q18. (0+18-15=3) */ + num_bits = extract_l( L_shr( L_tmp, 3 ) ); /* Q0 */ + st->total_num_bits = num_bits; -/*-------------------------------------------------------------------* - * mdct_switching_dec() - * - * Set up MDCT core switching if indicated in the bit stream - *-------------------------------------------------------------------*/ + if ( total_brate < 0 ) + { + /* validate that total_brate (derived from RTP packet or a file header) is one of the defined bit rates */ + fprintf( stderr, "\n Error. Illegal total bit rate (= %d) in MIME ToC header \n", total_brate ); + /* num_bits = -1; not needed as BASOP multiplication preserves sign */ + } -static void mdct_switching_dec( - Decoder_State *st /* i/o: decoder state structure */ -) -{ - IF(st->Opt_AMR_WB != 0) - { - return; - } - - test(); - test(); - IF(EQ_32(st->total_brate, ACELP_13k20) || EQ_32(st->total_brate, ACELP_32k)) - { - st->mdct_sw_enable = MODE1; - move16(); - } - ELSE IF(LE_32(ACELP_16k40, st->total_brate) && LE_32(st->total_brate, ACELP_24k40)) - { - st->mdct_sw_enable = MODE2; - move16(); - } - - test(); - test(); - IF(EQ_16(st->codec_mode, MODE1) && EQ_16(st->mdct_sw_enable, MODE1)) - { - /* Read ahead core mode signaling */ - Word16 next_bit_pos_save; - Word16 core_save; - Word16 bwidth_save; - - next_bit_pos_save = st->next_bit_pos; - move16(); - core_save = st->core; - move16(); - bwidth_save = st->bwidth; - move16(); - - decision_matrix_core_dec(st); /* sets st->core */ - - IF(EQ_16(st->core, TCX_20_CORE)) - { - /* Trigger TCX */ - st->codec_mode = MODE2; - move16(); - st->mdct_sw = MODE1; - move16(); - } - ELSE - { - /* Rewind bitstream */ - st->next_bit_pos = next_bit_pos_save; - move16(); - IF(st->bfi != 0) - { - st->core = core_save; - move16(); - st->bwidth = bwidth_save; - move16(); - } - } - } - ELSE IF(EQ_16(st->codec_mode, MODE2) && EQ_16(st->mdct_sw_enable, MODE2)) - { - /* Read ahead core mode signaling */ - Word16 next_bit_pos_save; - Word16 core_save; - Word16 bwidth_save; - - next_bit_pos_save = st->next_bit_pos; - move16(); - core_save = st->core; - move16(); - bwidth_save = st->bwidth; - move16(); - - dec_prm_core(st); /* sets st->core */ - - IF(EQ_16(st->core, HQ_CORE)) - { - /* Trigger HQ_CORE */ - st->codec_mode = MODE1; - move16(); - st->mdct_sw = MODE2; - move16(); - } - ELSE - { - /* Rewind bitstream */ - st->next_bit_pos = next_bit_pos_save; - move16(); - IF(st->bfi != 0) - { - st->core = core_save; - move16(); - } - /* always reset bwidth, to not interfere with BER logic */ - st->bwidth = bwidth_save; - move16(); - } - } -} + /* Check correctness of ToC headers */ + if ( st->amrwb_rfc4867_flag == 0 ) + { + /* EVS ToC header (FT field(b2-b7), H bit (b0), F bit (b1) , (EVS-modebit(b2)=0 unused(Qbit)(b3)==0) */ + if ( ( isAMRWB_IOmode == 0 ) && ( ( num_bits < 0 ) || ( ( header & 0x80 ) > 0 ) || ( ( header & 0x40 ) > 0 ) || ( header & 0x30 ) != 0x00 ) ) + { + /* incorrect FT header */ + fprintf( stderr, "\nError in EVS FT ToC header(%02x) ! ", header ); + exit( -1 ); + } + else if ( ( isAMRWB_IOmode != 0 ) && ( ( num_bits < 0 ) || ( ( header & 0x80 ) > 0 ) || ( ( header & 0x40 ) > 0 ) ) ) /* AMRWBIO */ + { + /* incorrect IO FT header */ + fprintf( stderr, "\nError in EVS(AMRWBIO) FT ToC header(%02x) ! ", header ); + exit( -1 ); + } + } + else + { + /* legacy AMRWB ToC, is only using Padding bits which MUST be ignored */ + if ( num_bits < 0 ) + { + /* incorrect FT header */ + fprintf( stderr, "\nError in AMRWB RFC4867 Toc(FT) header(%02x) !", header ); + exit( -1 ); + } + } -/*-------------------------------------------------------------------* - * BRATE2IDX_fx() - * - * Convert Bitrate to Index Value - *-------------------------------------------------------------------*/ + /* read serial stream of indices from file to the local buffer */ + num_bytes_read = (Word16) fread( pFrame, sizeof( UWord8 ), ( num_bits + 7 ) >> 3, file ); + if ( num_bytes_read != ( num_bits + 7 ) >> 3 ) + { + fprintf( stderr, "\nError, invalid number of bytes read ! Exiting ! \n" ); + exit( -1 ); + } -Word16 BRATE2IDX_fx(Word32 brate) -{ + /* in case rew_flag is set, rewind the file and return */ + /* (used in io_dec() to attempt print out info about technologies and to initialize the codec ) */ + if ( rew_flag ) + { + st->total_brate = total_brate; /* used for the codec banner output */ + if ( st->bfi == 0 && speech_lost == 0 && no_data == 0 ) + { + decoder_selectCodec( st, total_brate, unpack_bit( &pt_pFrame, &mask ) ? G192_BIN1 : G192_BIN0 ); + } + return 1; + } - Word32 L_temp; - Word32 L_idx; -#define START 9 - extern const Word16 bit_rates_div50[]; - - /* This is a Fast Bit Rate Value to Index Value Binary Search */ - L_temp = L_msu0(brate, bit_rates_div50[START], 50); - L_temp = L_min(6, L_max(-6, L_temp)); - L_idx = L_add(L_temp, START); - L_temp = L_msu0(brate, bit_rates_div50[L_idx], 50); - L_temp = L_min(3, L_max(-3, L_temp)); - L_idx = L_add(L_temp, L_idx); - L_temp = L_msu0(brate, bit_rates_div50[L_idx], 50); - L_temp = L_min(1, L_max(-2, L_temp)); - L_idx = L_add(L_temp, L_idx); - L_temp = L_msu0(brate, bit_rates_div50[L_idx], 50); - if (L_temp != 0) L_idx = L_add(L_idx, 1); - return (Word16)L_idx; -} + /* unpack speech data */ + bit_stream_ptr = st->bit_stream; + for ( k = 0; k < num_bits; k++ ) + { + if ( isAMRWB_IOmode ) + { + st->bit_stream[sort_ptr[core_mode][k]] = unpack_bit( &pt_pFrame, &mask ); + bit_stream_ptr++; + } + else + { + *bit_stream_ptr++ = unpack_bit( &pt_pFrame, &mask ); + } + } -/*-------------------------------------------------------------------* - * BRATE2IDX16k_fx() - * - * Convert Bitrate to Index Value - *-------------------------------------------------------------------*/ + /* unpack auxiliary bits */ + /* Note: the cmi bits are unpacked for demo purposes; */ + if ( isAMRWB_IOmode && total_brate == SID_1k75 ) + { + sti = unpack_bit( &pt_pFrame, &mask ); + cmi = unpack_bit( &pt_pFrame, &mask ) << 3; + cmi |= unpack_bit( &pt_pFrame, &mask ) << 2; + cmi |= unpack_bit( &pt_pFrame, &mask ) << 1; + cmi |= unpack_bit( &pt_pFrame, &mask ); -Word16 BRATE2IDX16k_fx(Word32 brate) -{ - Word32 L_temp, L_idx; -#define START_16K 5 - extern const Word16 bit_rates_16k_div50[]; - - if (EQ_32(brate, ACELP_16k40)) - { - brate = ACELP_14k80; - } - - /* This is a Fast Bit Rate Value to Index Value Binary Search */ - L_temp = L_msu0(brate, bit_rates_16k_div50[START_16K], 50); - L_temp = L_min(3, L_max(-3, L_temp)); - L_idx = L_add(L_temp, START_16K); - L_temp = L_msu0(brate, bit_rates_16k_div50[L_idx], 50); - L_temp = L_min(2, L_max(-2, L_temp)); - L_idx = L_add(L_temp, L_idx); - L_temp = L_msu0(brate, bit_rates_16k_div50[L_idx], 50); - L_temp = L_min(1, L_max(-1, L_temp)); - L_idx = L_add(L_temp, L_idx); - - return (Word16)L_idx; -} + read_indices_mime_handle_sti_and_all_zero_bits( st, &total_brate, sti ); + } -/*-------------------------------------------------------------------* - * BIT_ALLOC_IDX_fx() - *-------------------------------------------------------------------*/ + /*add two zero bytes for arithmetic coder flush*/ + for ( k = 0; k < 2 * 8; ++k ) + { + *bit_stream_ptr++ = 0; + } -Word32 BIT_ALLOC_IDX_fx(Word32 brate, Word16 ctype, Word16 sfrm, Word16 tc) -{ - Word32 L_temp; - Word16 temp; - if (ctype == INACTIVE) /* no sub(ctype, INACTIVE) because it is '0' */ - ctype = GENERIC; - move16(); - L_temp = L_mac0(-1l * 256, 1 * 256, ctype); - - temp = BRATE2IDX_fx(brate); - L_temp = L_mac0(L_temp, 4 * 256, temp); - if (tc >= 0) - L_temp = L_mac0(L_temp, (10 - 4) * 256, temp); - /* So either 'temp' x 4 when 'tc < 0', 'temp' x 10 otherwise */ - - L_temp = L_mac0(L_temp, 1 * 256, s_max(0, tc)); - - L_temp = L_mac0(L_temp, s_max(0, sfrm), 1); - if (sfrm < 0) - L_temp = L_shr(L_temp, 2); - L_temp = L_shr(L_temp, 6); - - return L_temp; -} + /* MIME RX_DTX handler */ + if ( !rew_flag ) + { + total_brate = read_indices_mime_handle_dtx( st, isAMRWB_IOmode, core_mode, total_brate, sti, speech_lost, no_data ); + } -/*-------------------------------------------------------------------* - * BIT_ALLOC_IDX_16KHZ_fx() - *-------------------------------------------------------------------*/ + if ( st->bfi == 0 ) + { + /* select MODE1 or MODE2 in MIME */ + decoder_selectCodec( st, total_brate, *st->bit_stream ? G192_BIN1 : G192_BIN0 ); -Word32 BIT_ALLOC_IDX_16KHZ_fx(Word32 brate, Word16 ctype, Word16 sfrm, Word16 tc) -{ - Word32 L_temp; - Word16 temp; - /* 'ctype' = - TRANSITION => 2 - GENERIC => 1 - ALL Other => 0 - */ - L_temp = L_and(shr(0x0240l, shl(ctype, 1)), 3); - - temp = BRATE2IDX16k_fx(brate); - L_temp = L_mac0(L_temp, 3, temp); - if (tc >= 0) - L_temp = L_mac0(L_temp, (7 - 3), temp); - /* So either 'temp' x 3 when 'tc < 0', 'temp' x 7 otherwise */ - - L_temp = L_mac0(L_temp, 1, s_max(0, tc)); - - IF(sfrm >= 0) - { - /* Mult by 5 */ - L_temp = L_add(L_temp, L_shl(L_temp, 2)); - L_temp = L_mac0(L_temp, shr(sfrm, 6), 1); - } - - return L_temp; -} + /* a change of the total bitrate should not be known to the decoder, if the received frame was truly lost */ + st->total_brate = total_brate; + mdct_switching_dec( st ); + } + /* else{ bfi stay in past synthesis mode(SP,CNG) } */ + return 1; +} /*-------------------------------------------------------------------* - * read_indices_fx() + * berCheck() * - * Read indices from an ITU-T G.192 bitstream to the buffer - * Simulate packet losses by inserting frame erasures + * Check for bit errors in channel aware signalling. *-------------------------------------------------------------------*/ -Word16 read_indices_fx( /* o : 1 = reading OK, 0 = problem */ - Decoder_State *st, /* i/o: decoder state structure */ - FILE *file, /* i : bitstream file */ - Word16 rew_flag /* i : rewind flag (rewind file after reading)*/ +static void berCheck( + Decoder_State *st, /* i/o: decoder state structure */ + Word16 *coder_type /* i/o: coder type */ ) { - Word16 k; - UWord16 utmp, stream[2 + MAX_BITS_PER_FRAME], *pt_stream, *bit_stream_ptr; - Word16 num_bits; - Word32 total_brate; - Word32 L_tmp; - Word16 curr_ft_good_sp, curr_ft_bad_sp; - Word16 g192_sid_first, sid_upd_bad, sid_update; - Word16 speech_bad, speech_lost; - Word16 num_bits_read; - - st->bfi = 0; - st->BER_detect = 0; - st->mdct_sw_enable = 0; - st->mdct_sw = 0; - reset_indices_dec_fx(st); - - /* read the Sync Header field from the bitstream */ - /* in case rew_flag is set, read until first good frame is encountered */ - do - { - /* read the Sync header */ - if (fread(&utmp, sizeof(unsigned short), 1, file) != 1) - { - if (ferror(file)) - { - /* error during reading */ - fprintf(stderr, "\nError reading the bitstream !"); - exit(-1); - } - else - { - /* end of file reached */ - return 0; - } - } - - /* set the BFI indicator according the value of Sync Header */ - if (EQ_16(utmp, SYNC_BAD_FRAME)) - { - st->bfi = 1; - } - - - else - { - st->bfi = 0; - } - - /* read the Frame Length field from the bitstream */ - if (fread(&num_bits, sizeof(unsigned short), 1, file) != 1) - { - if (ferror(file)) - { - /* error during reading */ - fprintf(stderr, "\nError reading the bitstream !"); - exit(-1); - } - else - { - /* end of file reached */ - return 0; - } - } - /* convert the frame length to total bitrate */ - total_brate = (long)(num_bits * 50); - - /* read ITU-T G.192 serial stream of indices from file to the local buffer */ - /* Validate that the G.192 length is within the defined bit rate range - to not allow writing past the end of the "stream" buffer */ - if (num_bits > MAX_BITS_PER_FRAME) - { - fprintf(stderr, "\nError, too large G.192 frame (size(%d))! Exiting ! \n", num_bits); - exit(-1); - } - - /* verify that a valid num bits value is present in the G.192 file */ - /* only AMRWB or EVS bit rates or 0(NO DATA) are allowed in G.192 file frame reading */ - if (rate2EVSmode(total_brate, NULL) < 0) /* negative value means that a valid rate was not found */ - { - fprintf(stderr, "\nError, illegal bit rate (%d) in the G.192 frame ! Exiting ! \n", total_brate); - exit(-1); - } - pt_stream = stream; - - num_bits_read = (Word16)fread(pt_stream, sizeof(unsigned short), num_bits, file); - - if (num_bits_read != num_bits) - { - fprintf(stderr, "\nError, invalid number of bits read ! Exiting ! \n"); - exit(-1); - } - - } while (rew_flag && (st->bfi || LT_32(total_brate, 2800))); - - /* G.192 RX DTX handler*/ - if (!rew_flag) - { - /* handle SID_FIRST, SID_BAD, SPEECH_LOST, NO_DATA as properly as possible for the ITU-T G.192 format */ - - /* (total_brate, bfi , st_CNG) = rx_handler(received frame type, [previous frame type], past CNG state, past core) */ - curr_ft_good_sp = 0; - curr_ft_bad_sp = 0; - - if (total_brate > SID_2k40) - { - if (st->bfi == 0) - { - curr_ft_good_sp = 1; - } - else - { - curr_ft_bad_sp = 1; - } - } - sid_update = 0; - sid_upd_bad = 0; - - if (total_brate == SID_1k75 || total_brate == SID_2k40) - { - if (st->bfi == 0) - { - sid_update = 1; - } - else - { - sid_upd_bad = 1; /* may happen in CS , corrupt but detected sid frame */ - } - } - - /* all zero indeces/bits iSP AMRWB SID_update results in a valid LP filter with extremely high LP-filter-gain */ - /* all zero indeces/bits may be a result of CS bit errors and/or erroneously injected by gateways or by a bad dejitter handlers */ - if (total_brate == SID_1k75 && sid_update == 1) - { - /* valid sid_update received, check for very risky but formally valid content */ - Word16 sum = 0; - for (k = 0; k < num_bits; ++k) - { - sum += (pt_stream[k] == G192_BIN1);/* check of 35 zeroes, 35 ones */ - } - if (sum == 0) - { /* all zeros */ - sid_upd_bad = 1; /* initial signal as corrupt (BER likley) */ - } - } - - /* AMRWB 26.173 G.192 file reader (read_serial) does not declare/use SID_BAD ft, - it declares every bad synch marked frame initially as a lost_speech frame, - and then the RXDTX handler CNG state decides the decoding mode CNG/SPEECH. - While In the AMRWB ETSI/3GPP format eid a CRC error in a detected SID_UPDATE frame triggers SID_UPD_BAD. - - Here we inhibit use of the SID-length info, even though it is available in the G.192 file format after STL/EID-XOR . - */ - if (sid_upd_bad) - { - sid_upd_bad = 0; - total_brate = FRAME_NO_DATA; /* treat SID_BAD as a stolen signaling frame --> SPEECH LOST */ - - } - - g192_sid_first = 0; - if (st->core == AMR_WB_CORE && st->prev_ft_speech_fx && total_brate == FRAME_NO_DATA && st->bfi == 0) - { - g192_sid_first = 1; /* SID_FIRST detected for previous AMRWB/AMRWBIO active frames only */ - /* - It is not possible to perfectly simulate rate switching conditions EVS->AMRWBIO where: - the very first SID_FIRST detection is based on a past EVS active frame - and a good length 0 "SID_FIRST"(NO_DATA) frame is sent in AMRWBIO, - , due to the one frame state memory in the AMRWB legacy G.192 SID_FIRST encoding - */ - } - - speech_bad = 0; - if (total_brate > SID_2k40 && st->bfi != 0) /* CS-type of CRC failure frame */ - { - speech_bad = 1; /* initial assumption, CNG_state decides what to do */ - } - - speech_lost = 0; - if (total_brate == 0 && st->bfi != 0) /* unsent NO_DATA or stolen NO_DATA/signaling frame */ - { - speech_lost = 1; /* initial assumption, CNG_state decides what to do */ - } - - /* Do not allow decoder to enter CNG-synthesis for any instantly received GOOD+LENGTH==0 frame - as this frame was never transmitted, one can not know it is good and has a a length of zero ) */ - - if (st->CNG_fx != 0) - { - /* We were in CNG synthesis */ - if (curr_ft_good_sp != 0) - { - /* only a good speech frame makes you leave CNG synthesis */ - st->CNG_fx = 0; - } - } - else - { - /* We were in SPEECH synthesis */ - /* only a received SID frame can make the decoder enter into CNG synthsis */ - if (g192_sid_first || sid_update || sid_upd_bad) - { - st->CNG_fx = 1; - } - } - - /* handle the g.192 _simulated_ untransmitted frame, setting for decoder SPEECH synthesis */ - if ((st->CNG_fx == 0) && (total_brate == 0 && st->bfi == 0)) - { - st->bfi = 1; - move16(); /* SPEECH PLC code will now become active as in a real system */ - /* total_brate= 0 */ - } - - /* handle bad speech frame(and bad sid frame) in the decoders CNG synthesis settings pair (total_brate, bfi) */ - if (((st->CNG_fx != 0) && ((speech_bad != 0) || (speech_lost != 0))) || /* SP_BAD or SPEECH_LOST) --> stay in CNG */ - (sid_upd_bad != 0)) /* SID_UPD_BAD --> start CNG */ - { - st->bfi = 0; - total_brate = 0; - } - /* update for next frame's G.192 file format's SID_FIRST detection (primarily for AMRWBIO) */ - st->prev_ft_speech_fx = ((curr_ft_good_sp != 0) || (curr_ft_bad_sp != 0)); - - /* st->total brate= total_brate ; updated in a good frame below */ - } /* rew_flag */ - - /* get total bit-rate */ -#ifdef DEBUGGING - st->bfi |= file_read_FECpattern(); -#endif - if (st->bfi == 0 && !rew_flag) - { - /* select MODE1 or MODE2 */ - decoder_selectCodec(st, total_brate, *pt_stream); - } - - Mpy_32_16_ss(total_brate, 5243, &L_tmp, &utmp); /* 5243 is 1/50 in Q18. (0+18-15=3) */ - st->total_num_bits = extract_l(L_shr(L_tmp, 3)); /* Q0 */ - - /* in case rew_flag is set, rewind the file and return */ - /* (used in io_enc() to print out info about technologies and to initialize the codec) */ - if (rew_flag) - { - rewind(file); - st->total_brate = total_brate; - move16(); - return 1; - } - - /* GOOD frame */ - if (st->bfi == 0) - { - /* GOOD frame - convert ITU-T G.192 words to short values */ - bit_stream_ptr = st->bit_stream; - - for (k = 0; k < num_bits; ++k) - { - *bit_stream_ptr++ = (*pt_stream++ == G192_BIN1); - } - - /*add two zero bytes for arithmetic coder flush*/ - for (k = 0; k < 2 * 8; ++k) - { - *bit_stream_ptr++ = 0; - } - /*a change of the total bitrate should not be - known to the decoder, if the received frame was lost*/ - st->total_brate = total_brate; - - mdct_switching_dec(st); - } -#ifdef DEBUGGING - else - { - bit_stream_ptr = st->bit_stream; + /* In case of RF flag = 1, and valid RF packet with primary and partial copy */ + if ( ( EQ_16( st->bwidth, NB ) || EQ_16( st->bwidth, FB ) ) || ( GE_16( *coder_type, TRANSITION ) ) ) + { + if ( EQ_16( st->use_partial_copy, 1 ) ) + { + st->use_partial_copy = 0; + move16(); + } - for (k = 0; k < num_bits + 2 * 8; ++k) - { - *bit_stream_ptr++ = 0; - } + st->bfi = 1; + move16(); + st->bwidth = st->last_bwidth; + move16(); + st->BER_detect = 1; + move16(); + *coder_type = GENERIC; + move16(); + } - } -#endif - return 1; + return; } - /*-------------------------------------------------------------------* - * read_indices_mime_handle_dtx() + * getPartialCopyInfo() * - * Handle DTX for MIME and RTP_DUMP decoding. - * Returns the actual total_brate. + * Check if the frame includes a partial copy for channel aware processing. *-------------------------------------------------------------------*/ -static Word32 read_indices_mime_handle_dtx( - Decoder_State *st, - Word16 isAMRWB_IOmode, - Word16 core_mode, - Word32 total_brate, - Word16 sti, - Word16 speech_lost, - Word16 no_data -) +void getPartialCopyInfo( + Decoder_State *st, /* i/o: decoder state structure */ + Word16 *coder_type, + Word16 *sharpFlag ) { - Word16 curr_ft_good_sp = 0; - Word16 speech_bad = 0; - Word16 sid_upd_bad = 0, sid_update = 0; - Word16 amrwb_sid_first = 0; /* derived from sti SID_FIRST indicator in AMRWB payload */ - - /* keep st->CNG , st_bfi and total_brate updated for proper synthesis in DTX and FER */ - if (GT_32(total_brate, SID_2k40)) - { - if (st->bfi != 1) /* so far derived from q bit in AMRWB/AMRWBIO cases */ - { - curr_ft_good_sp = 1; - } - } - - /* handle q_bit and lost_sp clash , assume worst case */ - if (speech_lost != 0) /* overrides a good q_bit */ - { - curr_ft_good_sp = 0; - st->bfi = 1; /* override qbit */ - } - - /* now_bfi_fx has been set based on q_bit and ToC fields */ - - - /* SID_UPDATE check */ - if (total_brate == SID_1k75 || total_brate == SID_2k40) - { - if (st->bfi == 0) - { - /* typically from q bit */ - sid_update = 1; - } - else - { - sid_upd_bad = 1; /* may happen in saving from e.g. a CS-connection */ - } - } - - if (isAMRWB_IOmode && total_brate == 0 && sti == 0) - { - if (st->bfi) - { - sid_upd_bad = 1; /* corrupt sid_first, signaled as bad sid */ - } - else - { - amrwb_sid_first = 1; /* 1-sti */ - } - } - - if (sid_upd_bad != 0 && ( - (isAMRWB_IOmode != 0 && st->Opt_AMR_WB == 0) || /* switch to AMRWBIO */ - (isAMRWB_IOmode != 1 && st->Opt_AMR_WB == 1) /* switch from AMRWBIO */ - )) - { - /* do not allow a normal start of CNG synthesis if this SID(with BER or FER) is a switch to/from AMRWBIO */ - sid_upd_bad = 0; /* revert this detection due to AMRWBIO/EVS mode switch */ - total_brate = 0; - no_data = 1; - assert(st->bfi == 1); /* bfi stays 1 */ - } - - if (GT_32(total_brate, SID_2k40) && st->bfi == 1) /* typically from q bit */ - { - speech_bad = 1; /* initial assumption, CNG synt state decides what to actually do */ - } - /* all frame types decoded */ - - /* update CNG synthesis state */ - /* Decoder can only enter CNG-synthesis for CNG frame types (sid_upd, sid_bad, sid_first) */ - if (st->CNG_fx != 0) - { - /* We were in CNG synthesis */ - if (curr_ft_good_sp != 0) - { - /* only a good speech frame makes decoder leave CNG synthesis */ - st->CNG_fx = 0; - } - } - else - { - /* We were in SPEECH synthesis */ - /* only a received SID frame can make the decoder enter into CNG synthesis */ - if (amrwb_sid_first || sid_update || sid_upd_bad) - { - st->CNG_fx = 1; - } - } - - /* Now modify bfi flag for the decoder's SPEECH/CNG synthesis logic */ - /* in SPEECH synthesis, make sure to activate speech plc for a received no_data frame, - no_data frames may be injected by the network or by the dejitter buffer */ - /* modify bfi_flag to stay/move into the correct decoder PLC section */ - if ((st->CNG_fx == 0) && (no_data != 0)) - { - /* treat no_data received in speech synthesis as SP_LOST frames, SPEECH PLC code will now become active */ - st->bfi = 1; - /* total_brate= 0; always zero for no_data */ - } - - /* in CNG */ - /* handle bad speech frame(and bad sid frame) in the decoders CNG synthesis settings pair (total_brate, bfi) */ - if ((st->CNG_fx != 0 && (speech_bad || speech_lost || no_data)) || /* SP_BAD or SPEECH_LOST) --> stay in CNG */ - sid_upd_bad) /* SID_UPD_BAD --> start/stay CNG */ - { - st->bfi = 0; /* mark as good to not start speech PLC */ - total_brate = 0; /* this zeroing needed for speech_bad, sid_bad frames */ - } - - - /* now bfi, total_brate are set by RX-DTX handler:: - bfi==0, total_brate!=0 cng or speech pending bitrate - bfi==0, total_brate==0 cng will continue or start(sid_first, sid_bad) - bfi==1, total_brate!=0 speech plc - bfi==1, total_brate==0 , speech plc - */ - - - /* handle available AMRWB/AMRWBIO MIME header ToC rate-info at startup */ - if ((st->bfi == 1 && st->ini_frame == 0) && - ((st->amrwb_rfc4867_flag != 0) || (st->amrwb_rfc4867_flag == 0 && isAMRWB_IOmode != 0))) /*AMRWB ToC */ - { - Word32 init_rate; - - init_rate = total_brate; /* default , may have been modified from original ToC value */ - if (speech_lost != 0 || no_data != 0) - { - init_rate = ACELP_12k65; /* make sure the decoder starts up in a selected AMRWB mode */ - } - else if (speech_bad != 0) - { - init_rate = AMRWB_IOmode2rate[core_mode]; /* read from from ToC */ - } - st->total_brate = init_rate; /* not updated on bfi as decoderSelectCodec is not called below */ - st->core_brate = init_rate; - } - - return total_brate; -} + Word16 nBits; + Word16 ind; + /* check the rf flag in the packet */ + get_rfFlag( st, &( st->rf_flag ), &nBits, &ind ); + + /* get rf frame type info */ + get_rfFrameType( st, &( st->rf_frame_type ) ); + /* Get the FEC offset info */ + get_rf_fec_offset( st, &( st->rf_fec_offset ) ); + + /* reset number of target bits in case of rate switching */ + st->rf_target_bits = 0; + + /* Get the number of bits used for RF*/ + IF( EQ_16( st->rf_flag, 1 ) ) + { + *coder_type = s_and( ind, 0x7 ); + st->bwidth = s_and( shr( ind, 3 ), 0x7 ); + *sharpFlag = s_and( shr( ind, 6 ), 0x1 ); + st->codec_mode = MODE2; + move16(); + get_rfTargetBits( st->rf_frame_type, &( st->rf_target_bits ) ); + + IF( EQ_16( st->bfi, FRAMEMODE_FUTURE ) ) + { + st->use_partial_copy = 1; + /* now set the frame mode to normal mode */ + test(); + IF( GE_16( st->rf_frame_type, RF_TCXFD ) && LE_16( st->rf_frame_type, RF_TCXTD2 ) ) + { + st->bfi = 1; + st->core = 1; + } + ELSE + { + st->bfi = FRAMEMODE_NORMAL; + st->core = 0; + } + } + /* check for bit errors */ + berCheck( st, coder_type ); + + get_next_indice_tmp_fx( st, nBits ); + } +} /*-------------------------------------------------------------------* - * read_indices_mime_handle_sti_and_all_zero_bits() + * get_rfFlag() * - * Handle STI and frames with all zero bits for MIME and RTP_DUMP decoding. + * Check if rf flag is present in the bitstream *-------------------------------------------------------------------*/ -static void read_indices_mime_handle_sti_and_all_zero_bits( - Decoder_State *st, - Word32 *total_brate, - Word16 sti -) +void get_rfFlag( + Decoder_State *st, /* i: decoder state structure */ + Word16 *rf_flag, /* o : check for the RF flag */ + Word16 *nBits, + Word16 *ind ) { - Word16 k; - - if (sti == 0) - { - *total_brate = 0; /* signal received SID_FIRST as a good frame with no bits */ - for (k = 0; k < 35; k++) - { - st->bfi |= st->bit_stream[k]; /* partity check of 35 zeroes, any single 1 gives BFI */ - } - } - /* all zero bit SID_update results in a valid LP filter with extremely high LP-filter-gain */ - /* all zero bits signal may be a result of CS bit errors or erronesouly injected by gateways or bad dejitter handlers */ - if (sti == 1) - { /*sid_update received */ - Word16 sum = 0; - for (k = 0; k < 35; k++) - { - sum += st->bit_stream[k]; /* check of 35 zeroes */ - } - - if (sum == 0) - { - st->bfi = 1; /* eventually becomes SID_UPD_BAD */ - } - } -} + Word16 start_idx, nBits_tmp; + Word16 ind_tmp; + /* Init */ + *rf_flag = 0; -/*------------------------------------------------------------------------------------------* -* read_indices_mime() -* -* Read indices from MIME formatted bitstream to the buffer -* The magic word and number of channnels should be consumed before calling this function -*-------------------------------------------------------------------------------------------*/ - -Word16 read_indices_mime( /* o : 1 = reading OK, 0 = problem */ - Decoder_State *st, /* i/o: decoder state structure */ - FILE *file, /* i : bitstream file */ - Word16 rew_flag /* i : rewind flag (rewind file after reading) */ -) -{ - Word16 k, isAMRWB_IOmode, cmi, core_mode = -1, qbit, sti; - UWord8 header; - UWord8 pFrame[(MAX_BITS_PER_FRAME + 7) >> 3]; - UWord8 mask = 0x80, *pt_pFrame = pFrame; - UWord16 *bit_stream_ptr; - Word16 num_bits; - Word32 total_brate; - UWord16 utmp; - Word32 L_tmp; - Word16 speech_lost = 0, no_data = 0; - Word16 num_bytes_read; - - st->BER_detect = 0; - st->bfi = 0; - st->mdct_sw_enable = 0; - st->mdct_sw = 0; - reset_indices_dec_fx(st); - - /* read the FT Header field from the bitstream */ - if (fread(&header, sizeof(UWord8), 1, file) != 1) - { - if (ferror(file)) - { - /* error during reading */ - fprintf(stderr, "\nError reading the bitstream !"); - exit(-1); - } - else - { - /* end of file reached */ - return 0; - } - } - - /* init local RXDTX flags */ - sti = -1; - - if (st->amrwb_rfc4867_flag != 0) - { - /* RFC 4867 - 5.3 .... - Each stored speech frame starts with a one-octet frame header with - the following format: - 0 1 2 3 4 5 6 7 - +-+-+-+-+-+-+-+-+ - |P| FT |Q|P|P| - +-+-+-+-+-+-+-+-+ - The FT field and the Q bit are defined in the same way as in - Section 4.3.2. The P bits are padding and MUST be set to 0, and MUST be ignored. */ - - isAMRWB_IOmode = 1; - qbit = (header >> 2) & 0x01; /* b2 bit (b7 is the F bit ) */ - st->bfi = !qbit; - core_mode = ((header >> 3) & 0x0F); /* b6..b3 */ - total_brate = AMRWB_IOmode2rate[core_mode]; /* get the frame length from the header */ - } - else - { - /*0 1 2 3 4 5 6 7 MS-bit ---> LS-bit - +-+-+-+-+-+-+-+-+ - |H|F|E|x| brate | - +-+-+-+-+-+-+-+-+ - where : - "E|x| brate " is the 6 bit "FT" -field - x is unused if E=0, (should be 0 ) - x is the q-bit if E=1, q==1(good), Q==0(bad, maybe bit errors in payload ) - H,F always 0 in RTP format. - */ - isAMRWB_IOmode = (header & 0x20) > 0; /* get EVS mode-from header */ /* b2 */ - core_mode = (header & 0x0F); /* b4,b5,b6,b7 */ - - if (isAMRWB_IOmode) - { - qbit = (header & 0x10) > 0; /* get Q bit, valid for IO rates */ /* b3 */ - total_brate = AMRWB_IOmode2rate[core_mode]; - } - else - { - qbit = 1; /* assume good q_bit for the unused EVS-mode bit, complete ToC validity checked later */ - total_brate = PRIMARYmode2rate[core_mode]; - } - st->bfi = !qbit; - } - - - - - /* set up RX-DTX-handler input */ - if (core_mode == 14) - { - /* SP_LOST */ - speech_lost = 1; - } - if (core_mode == 15) - { - /* NO_DATA unsent CNG frame OR any frame marked or injected as no_data by e.g a signaling layer or dejitter buffer */ - no_data = 1; - } - - Mpy_32_16_ss(total_brate, 5243, &L_tmp, &utmp); /* 5243 is 1/50 in Q18. (0+18-15=3) */ - num_bits = extract_l(L_shr(L_tmp, 3)); /* Q0 */ - st->total_num_bits = num_bits; - - if (total_brate < 0) - { - /* validate that total_brate (derived from RTP packet or a file header) is one of the defined bit rates */ - fprintf(stderr, "\n Error. Illegal total bit rate (= %d) in MIME ToC header \n", total_brate); - /* num_bits = -1; not needed as BASOP multiplication preserves sign */ - } - - /* Check correctness of ToC headers */ - if (st->amrwb_rfc4867_flag == 0) - { - /* EVS ToC header (FT field(b2-b7), H bit (b0), F bit (b1) , (EVS-modebit(b2)=0 unused(Qbit)(b3)==0) */ - if ((isAMRWB_IOmode == 0) && ((num_bits < 0) || ((header & 0x80) > 0) || ((header & 0x40) > 0) || (header & 0x30) != 0x00)) - { - /* incorrect FT header */ - fprintf(stderr, "\nError in EVS FT ToC header(%02x) ! ", header); - exit(-1); - } - else if ((isAMRWB_IOmode != 0) && ((num_bits < 0) || ((header & 0x80) > 0) || ((header & 0x40) > 0))) /* AMRWBIO */ - { - /* incorrect IO FT header */ - fprintf(stderr, "\nError in EVS(AMRWBIO) FT ToC header(%02x) ! ", header); - exit(-1); - } - } - else - { - /* legacy AMRWB ToC, is only using Padding bits which MUST be ignored */ - if (num_bits < 0) - { - /* incorrect FT header */ - fprintf(stderr, "\nError in AMRWB RFC4867 Toc(FT) header(%02x) !", header); - exit(-1); - } - } - - /* read serial stream of indices from file to the local buffer */ - num_bytes_read = (Word16)fread(pFrame, sizeof(UWord8), (num_bits + 7) >> 3, file); - if (num_bytes_read != (num_bits + 7) >> 3) - { - fprintf(stderr, "\nError, invalid number of bytes read ! Exiting ! \n"); - exit(-1); - } - - /* in case rew_flag is set, rewind the file and return */ - /* (used in io_dec() to attempt print out info about technologies and to initialize the codec ) */ - if (rew_flag) - { - st->total_brate = total_brate; /* used for the codec banner output */ - if (st->bfi == 0 && speech_lost == 0 && no_data == 0) - { - decoder_selectCodec(st, total_brate, unpack_bit(&pt_pFrame, &mask) ? G192_BIN1 : G192_BIN0); - } - return 1; - } - - - - /* unpack speech data */ - bit_stream_ptr = st->bit_stream; - for (k = 0; k < num_bits; k++) - { - if (isAMRWB_IOmode) - { - st->bit_stream[sort_ptr[core_mode][k]] = unpack_bit(&pt_pFrame, &mask); - bit_stream_ptr++; - } - else - { - *bit_stream_ptr++ = unpack_bit(&pt_pFrame, &mask); - } - } - - /* unpack auxiliary bits */ - /* Note: the cmi bits are unpacked for demo purposes; */ - if (isAMRWB_IOmode && total_brate == SID_1k75) - { - sti = unpack_bit(&pt_pFrame, &mask); - cmi = unpack_bit(&pt_pFrame, &mask) << 3; - cmi |= unpack_bit(&pt_pFrame, &mask) << 2; - cmi |= unpack_bit(&pt_pFrame, &mask) << 1; - cmi |= unpack_bit(&pt_pFrame, &mask); - - read_indices_mime_handle_sti_and_all_zero_bits(st, &total_brate, sti); - } - - /*add two zero bytes for arithmetic coder flush*/ - for (k = 0; k < 2 * 8; ++k) - { - *bit_stream_ptr++ = 0; - } - - /* MIME RX_DTX handler */ - if (!rew_flag) - { - total_brate = read_indices_mime_handle_dtx(st, isAMRWB_IOmode, core_mode, total_brate, sti, speech_lost, no_data); - } - - if (st->bfi == 0) - { - /* select MODE1 or MODE2 in MIME */ - decoder_selectCodec(st, total_brate, *st->bit_stream ? G192_BIN1 : G192_BIN0); - - /* a change of the total bitrate should not be known to the decoder, if the received frame was truly lost */ - st->total_brate = total_brate; - mdct_switching_dec(st); - } - /* else{ bfi stay in past synthesis mode(SP,CNG) } */ - - return 1; -} + /* check for rf_flag in the packet and extract the rf_frame_type and rf_fec_offset */ + test(); + test(); + IF( EQ_32( st->total_brate, ACELP_13k20 ) && ( EQ_16( st->bfi, FRAMEMODE_NORMAL ) || EQ_16( st->bfi, FRAMEMODE_FUTURE ) ) ) + { + /* find the section in the ACELP signalling table corresponding to bitrate */ + start_idx = 0; + WHILE( NE_32( acelp_sig_tbl[start_idx], st->total_brate ) ) + { + start_idx++; + assert( ( start_idx < MAX_ACELP_SIG ) && "ERROR: start_idx larger than acelp_sig_tbl[].\n" ); + } -/*-------------------------------------------------------------------* -* berCheck() -* -* Check for bit errors in channel aware signalling. -*-------------------------------------------------------------------*/ + /* skip the bitrate */ + start_idx = add( start_idx, 1 ); -static void berCheck( - Decoder_State *st, /* i/o: decoder state structure */ - Word16 *coder_type /* i/o: coder type */ -) -{ - /* In case of RF flag = 1, and valid RF packet with primary and partial copy */ - if ((EQ_16(st->bwidth, NB) || EQ_16(st->bwidth, FB)) - || (GE_16(*coder_type, TRANSITION)) - ) - { - if (EQ_16(st->use_partial_copy, 1)) - { - st->use_partial_copy = 0; - move16(); - } - - st->bfi = 1; - move16(); - st->bwidth = st->last_bwidth; - move16(); - st->BER_detect = 1; - move16(); - *coder_type = GENERIC; - move16(); - } - - return; -} + /* retrieve the number of bits */ + nBits_tmp = (Word16) acelp_sig_tbl[start_idx++]; -/*-------------------------------------------------------------------* -* getPartialCopyInfo() -* -* Check if the frame includes a partial copy for channel aware processing. -*-------------------------------------------------------------------*/ + /* retrieve the signalling indice */ + ind_tmp = (Word16) acelp_sig_tbl[start_idx + get_indice( st, 0, nBits_tmp )]; -void getPartialCopyInfo( - Decoder_State *st, /* i/o: decoder state structure */ - Word16 *coder_type, - Word16 *sharpFlag -) -{ - Word16 nBits; - Word16 ind; - /* check the rf flag in the packet */ - get_rfFlag(st, &(st->rf_flag), &nBits, &ind); - - /* get rf frame type info */ - get_rfFrameType(st, &(st->rf_frame_type)); - - /* Get the FEC offset info */ - get_rf_fec_offset(st, &(st->rf_fec_offset)); - - /* reset number of target bits in case of rate switching */ - st->rf_target_bits = 0; - - /* Get the number of bits used for RF*/ - IF(EQ_16(st->rf_flag, 1)) - { - *coder_type = s_and(ind, 0x7); - st->bwidth = s_and(shr(ind, 3), 0x7); - *sharpFlag = s_and(shr(ind, 6), 0x1); - st->codec_mode = MODE2; - move16(); - get_rfTargetBits(st->rf_frame_type, &(st->rf_target_bits)); - - IF(EQ_16(st->bfi, FRAMEMODE_FUTURE)) - { - st->use_partial_copy = 1; - /* now set the frame mode to normal mode */ - test(); - IF(GE_16(st->rf_frame_type, RF_TCXFD) && LE_16(st->rf_frame_type, RF_TCXTD2)) - { - st->bfi = 1; - st->core = 1; - } - ELSE - { - st->bfi = FRAMEMODE_NORMAL; - st->core = 0; - } - } - /* check for bit errors */ - berCheck(st, coder_type); - - get_next_indice_tmp_fx(st, nBits); - - } -} + /* convert signalling indice into RF flag. */ + *rf_flag = s_and( shr( ind_tmp, 7 ), 0x1 ); -/*-------------------------------------------------------------------* -* get_rfFlag() -* -* Check if rf flag is present in the bitstream -*-------------------------------------------------------------------*/ + if ( ind ) + { + *ind = ind_tmp; + } -void get_rfFlag( - Decoder_State *st, /* i: decoder state structure */ - Word16 *rf_flag, /* o : check for the RF flag */ - Word16 *nBits, - Word16 *ind -) -{ - Word16 start_idx, nBits_tmp; - Word16 ind_tmp; - - /* Init */ - *rf_flag = 0; - - /* check for rf_flag in the packet and extract the rf_frame_type and rf_fec_offset */ - test(); - test(); - IF(EQ_32(st->total_brate, ACELP_13k20) && (EQ_16(st->bfi, FRAMEMODE_NORMAL) || EQ_16(st->bfi, FRAMEMODE_FUTURE))) - { - /* find the section in the ACELP signalling table corresponding to bitrate */ - start_idx = 0; - WHILE(NE_32(acelp_sig_tbl[start_idx], st->total_brate)) - { - start_idx++; - assert((start_idx < MAX_ACELP_SIG) && "ERROR: start_idx larger than acelp_sig_tbl[].\n"); - } - - /* skip the bitrate */ - start_idx = add(start_idx, 1); - - /* retrieve the number of bits */ - nBits_tmp = (Word16)acelp_sig_tbl[start_idx++]; - - /* retrieve the signalling indice */ - ind_tmp = (Word16)acelp_sig_tbl[start_idx + get_indice(st, 0, nBits_tmp)]; - - /* convert signalling indice into RF flag. */ - *rf_flag = s_and(shr(ind_tmp, 7), 0x1); - - if (ind) - { - *ind = ind_tmp; - } - - if (nBits) - { - *nBits = nBits_tmp; - } - } + if ( nBits ) + { + *nBits = nBits_tmp; + } + } } /*-------------------------------------------------------------------* -* get_rfFrameType() -* -* Extract the rf frame type -*-------------------------------------------------------------------*/ + * get_rfFrameType() + * + * Extract the rf frame type + *-------------------------------------------------------------------*/ void get_rfFrameType( - Decoder_State *st, /* i : decoder state structure */ - Word16 *rf_frame_type /* o : RF frame type */ + Decoder_State *st, /* i : decoder state structure */ + Word16 *rf_frame_type /* o : RF frame type */ ) { - Word16 num_bits = 0; - - IF(EQ_16(st->rf_flag, 1)) - { - /*num_bits = st->total_brate/50;*/ - if (EQ_32(st->total_brate, ACELP_13k20)) - { - num_bits = 264; - move16(); /* @13.2kbps */ - } - else - { - UWord16 lsb; - Word32 L_tmp; - Mpy_32_16_ss(st->total_brate, 5243, &L_tmp, &lsb); /* 5243 is 1/50 in Q18. (0+18-15=3) */ - num_bits = extract_l(L_shr(L_tmp, 3)); /* Q0 */ - } - - /* the last three bits in a packet is the RF frame type */ - *rf_frame_type = get_indice(st, num_bits - 3, 3); - } - ELSE - { - *rf_frame_type = 0; - } + Word16 num_bits = 0; + + IF( EQ_16( st->rf_flag, 1 ) ) + { + /*num_bits = st->total_brate/50;*/ + if ( EQ_32( st->total_brate, ACELP_13k20 ) ) + { + num_bits = 264; + move16(); /* @13.2kbps */ + } + else + { + UWord16 lsb; + Word32 L_tmp; + Mpy_32_16_ss( st->total_brate, 5243, &L_tmp, &lsb ); /* 5243 is 1/50 in Q18. (0+18-15=3) */ + num_bits = extract_l( L_shr( L_tmp, 3 ) ); /* Q0 */ + } + + /* the last three bits in a packet is the RF frame type */ + *rf_frame_type = get_indice( st, num_bits - 3, 3 ); + } + ELSE + { + *rf_frame_type = 0; + } } /*-------------------------------------------------------------------* -* get_rf_fec_offset() -* -* Extract the FEC offset -*-------------------------------------------------------------------*/ + * get_rf_fec_offset() + * + * Extract the FEC offset + *-------------------------------------------------------------------*/ void get_rf_fec_offset( - Decoder_State *st, /* i : decoder state structure */ - Word16 *rf_fec_offset /* o : RF fec offset */ + Decoder_State *st, /* i : decoder state structure */ + Word16 *rf_fec_offset /* o : RF fec offset */ ) { - Word16 num_bits, tmp; - - IF(EQ_16(st->rf_flag, 1)) - { - /*num_bits = st->total_brate/50;*/ - if (EQ_32(st->total_brate, ACELP_13k20)) - { - num_bits = 264; - move16(); /* @13.2kbps */ - } - else - { - UWord16 lsb; - Word32 L_tmp; - Mpy_32_16_ss(st->total_brate, 5243, &L_tmp, &lsb); /* 5243 is 1/50 in Q18. (0+18-15=3) */ - num_bits = extract_l(L_shr(L_tmp, 3)); /* Q0 */ - } - - /* the two bits before the rf frame type contain the fec offset */ - tmp = get_indice(st, num_bits - 5, 2); - - if (tmp == 0) - { - *rf_fec_offset = 2; - move16(); - } - else - { - *rf_fec_offset = add(shl(tmp, 1), 1); - } - } - ELSE - { - *rf_fec_offset = 0; - move16(); - } + Word16 num_bits, tmp; + + IF( EQ_16( st->rf_flag, 1 ) ) + { + /*num_bits = st->total_brate/50;*/ + if ( EQ_32( st->total_brate, ACELP_13k20 ) ) + { + num_bits = 264; + move16(); /* @13.2kbps */ + } + else + { + UWord16 lsb; + Word32 L_tmp; + Mpy_32_16_ss( st->total_brate, 5243, &L_tmp, &lsb ); /* 5243 is 1/50 in Q18. (0+18-15=3) */ + num_bits = extract_l( L_shr( L_tmp, 3 ) ); /* Q0 */ + } + + /* the two bits before the rf frame type contain the fec offset */ + tmp = get_indice( st, num_bits - 5, 2 ); + + if ( tmp == 0 ) + { + *rf_fec_offset = 2; + move16(); + } + else + { + *rf_fec_offset = add( shl( tmp, 1 ), 1 ); + } + } + ELSE + { + *rf_fec_offset = 0; + move16(); + } } /*-------------------------------------------------------------------* -* get_rfTargetBits() -* -* Return the number of RF target bits -*-------------------------------------------------------------------*/ + * get_rfTargetBits() + * + * Return the number of RF target bits + *-------------------------------------------------------------------*/ void get_rfTargetBits( - Word16 rf_frame_type, /* i : RF frame type */ - Word16 *rf_target_bits /* o : Number of RF target bits */ + Word16 rf_frame_type, /* i : RF frame type */ + Word16 *rf_target_bits /* o : Number of RF target bits */ ) { - /* Number of RF bits for different RF coder types */ - - SWITCH(rf_frame_type) - { - case RF_NO_DATA: - *rf_target_bits = 5; - BREAK; - case RF_TCXFD: - *rf_target_bits = 27; - BREAK; - case RF_TCXTD1: - *rf_target_bits = 16; - BREAK; - case RF_TCXTD2: - *rf_target_bits = 16; - BREAK; - case RF_ALLPRED: - /* Es_pred bits 3 bits, LTF: 1, pitch: 8,5,5,5, FCB: 0, gain: 7,0,7,0, Diff GFr: 4*/ - *rf_target_bits = 63; - BREAK; - case RF_NOPRED: - /* Es_pred bits 3 bits, LTF: 0, pitch: 0, FCB: 7,7,7,7, gain: 6,0,6,0, Diff GFr: 2*/ - *rf_target_bits = 66; - BREAK; - case RF_GENPRED: - /* Es_pred bits 3 bits, LTF: 1, pitch: 8,0,8,0, FCB: 6,7,5,5, gain: 5,0,5,0, Diff GFr: 0*/ - *rf_target_bits = 70; - BREAK; - case RF_NELP: - /* gain: 19, Diff GFr: 5 */ - *rf_target_bits = 45; - BREAK; - } + /* Number of RF bits for different RF coder types */ + + SWITCH( rf_frame_type ) + { + case RF_NO_DATA: + *rf_target_bits = 5; + BREAK; + case RF_TCXFD: + *rf_target_bits = 27; + BREAK; + case RF_TCXTD1: + *rf_target_bits = 16; + BREAK; + case RF_TCXTD2: + *rf_target_bits = 16; + BREAK; + case RF_ALLPRED: + /* Es_pred bits 3 bits, LTF: 1, pitch: 8,5,5,5, FCB: 0, gain: 7,0,7,0, Diff GFr: 4*/ + *rf_target_bits = 63; + BREAK; + case RF_NOPRED: + /* Es_pred bits 3 bits, LTF: 0, pitch: 0, FCB: 7,7,7,7, gain: 6,0,6,0, Diff GFr: 2*/ + *rf_target_bits = 66; + BREAK; + case RF_GENPRED: + /* Es_pred bits 3 bits, LTF: 1, pitch: 8,0,8,0, FCB: 6,7,5,5, gain: 5,0,5,0, Diff GFr: 0*/ + *rf_target_bits = 70; + BREAK; + case RF_NELP: + /* gain: 19, Diff GFr: 5 */ + *rf_target_bits = 45; + BREAK; + } } @@ -2518,41 +2502,41 @@ void get_rfTargetBits( *-------------------------------------------------------------------*/ void get_NextCoderType_fx( - UWord8 *bitsteam, /* i : bitstream */ - Word16 *next_coder_type /* o : next coder type */ + UWord8 *bitsteam, /* i : bitstream */ + Word16 *next_coder_type /* o : next coder type */ ) { - Word16 k; - Word16 start_idx; - Word16 nBits_tmp; - Word8 bit_stream[ACELP_13k20 / 50]; - UWord16 tmp; - - - FOR(k = 0; k < ACELP_13k20 / 50; k++) - { - bit_stream[k] = (bitsteam[k / 8] >> (7 - (k % 8))) & 0x1; - } - start_idx = 0; - WHILE(NE_32(acelp_sig_tbl[start_idx], ACELP_13k20)) - { - start_idx = add(start_idx, 1); - assert((start_idx < MAX_ACELP_SIG) && "ERROR: start_idx larger than acelp_sig_tbl[].\n"); - } - - /* skip the bitrate */ - start_idx = add(start_idx, 1); - - tmp = 0; - move16(); - nBits_tmp = (Word16)acelp_sig_tbl[start_idx++]; - FOR(k = 0; k < nBits_tmp; k++) - { - tmp = lshl(tmp, 1); - tmp = add(tmp, bit_stream[k]); - } - /* retrieve the signalling indice */ - *next_coder_type = s_and((Word16)acelp_sig_tbl[start_idx + tmp], 0x7); + Word16 k; + Word16 start_idx; + Word16 nBits_tmp; + Word8 bit_stream[ACELP_13k20 / 50]; + UWord16 tmp; + + + FOR( k = 0; k < ACELP_13k20 / 50; k++ ) + { + bit_stream[k] = ( bitsteam[k / 8] >> ( 7 - ( k % 8 ) ) ) & 0x1; + } + start_idx = 0; + WHILE( NE_32( acelp_sig_tbl[start_idx], ACELP_13k20 ) ) + { + start_idx = add( start_idx, 1 ); + assert( ( start_idx < MAX_ACELP_SIG ) && "ERROR: start_idx larger than acelp_sig_tbl[].\n" ); + } + + /* skip the bitrate */ + start_idx = add( start_idx, 1 ); + + tmp = 0; + move16(); + nBits_tmp = (Word16) acelp_sig_tbl[start_idx++]; + FOR( k = 0; k < nBits_tmp; k++ ) + { + tmp = lshl( tmp, 1 ); + tmp = add( tmp, bit_stream[k] ); + } + /* retrieve the signalling indice */ + *next_coder_type = s_and( (Word16) acelp_sig_tbl[start_idx + tmp], 0x7 ); } /*-------------------------------------------------------------------* @@ -2562,108 +2546,106 @@ void get_NextCoderType_fx( *-------------------------------------------------------------------*/ void read_indices_from_djb_fx( - Decoder_State *st, /* i/o: decoder state structure */ - UWord8 *pt_stream, /* i : bitstream file */ - Word16 num_bits, /* i : input frame length in bits */ - Word16 isAMRWB_IOmode, - Word16 core_mode, - Word16 qbit, - Word16 partialframe, /* i : partial frame information */ - Word16 next_coder_type /* i : next coder type information */ + Decoder_State *st, /* i/o: decoder state structure */ + UWord8 *pt_stream, /* i : bitstream file */ + Word16 num_bits, /* i : input frame length in bits */ + Word16 isAMRWB_IOmode, + Word16 core_mode, + Word16 qbit, + Word16 partialframe, /* i : partial frame information */ + Word16 next_coder_type /* i : next coder type information */ ) { - Word16 k; - UWord8 mask = 0x80; - Word16 no_data = 0; - Word16 sti = -1; - UWord16 *bit_stream_ptr; - Word32 total_brate; - Word16 speech_lost = 0; - - st->bfi = 0; - st->BER_detect = 0; - st->mdct_sw_enable = 0; - st->mdct_sw = 0; - reset_indices_dec_fx(st); - - st->bfi = !qbit; - total_brate = (Word32)(num_bits) * 50; - st->total_num_bits = num_bits; - - if (num_bits == 0) /* guess type of missing frame for SP_LOST and NO_DATA */ - { - speech_lost = st->CNG_fx == 0; - no_data = st->CNG_fx != 0; - } - - if (partialframe || st->prev_use_partial_copy) - { - st->next_coder_type = next_coder_type; - } - else - { - st->next_coder_type = INACTIVE; - } - - if (partialframe == 1) - { - st->bfi = 2; - } - - /* unpack speech data */ - bit_stream_ptr = st->bit_stream; - /* convert bitstream from compact bytes to short values and store it in decoder state */ - for (k = 0; k < num_bits; k++) - { - if (st->bitstreamformat == VOIP_RTPDUMP && isAMRWB_IOmode) - { - st->bit_stream[sort_ptr[core_mode][k]] = unpack_bit(&pt_stream, &mask); - bit_stream_ptr++; - } - else - { - *bit_stream_ptr++ = unpack_bit(&pt_stream, &mask); - } - } - - /* unpack auxiliary bits */ - if (isAMRWB_IOmode && total_brate == SID_1k75) - { - if (st->bitstreamformat == VOIP_RTPDUMP) - { - /* A.2.2.1.3: AMR-WB SID_1k75 frame is followed by STI bit and CMI bits */ - sti = unpack_bit(&pt_stream, &mask); - } - else - { - /* VOIP_G192_RTP does not contain STI and CMI */ - sti = 1; - } - read_indices_mime_handle_sti_and_all_zero_bits(st, &total_brate, sti); - - } - - /* add two zero bytes for arithmetic coder flush */ - for (k = 0; k < 8 * 2; ++k) - { - *bit_stream_ptr++ = 0; - } - - total_brate = read_indices_mime_handle_dtx(st, isAMRWB_IOmode, core_mode, total_brate, sti, speech_lost, no_data); - /* st->CNG_fx set inside */ - - if (st->bfi != 1) - { - /* select Mode 1 or Mode 2 */ - decoder_selectCodec(st, total_brate, *st->bit_stream ? G192_BIN1 : G192_BIN0); - - /* a change of the total bitrate should not be known to the decoder, if the received frame was truly lost */ - st->total_brate = total_brate; - - mdct_switching_dec(st); - } -} + Word16 k; + UWord8 mask = 0x80; + Word16 no_data = 0; + Word16 sti = -1; + UWord16 *bit_stream_ptr; + Word32 total_brate; + Word16 speech_lost = 0; + + st->bfi = 0; + st->BER_detect = 0; + st->mdct_sw_enable = 0; + st->mdct_sw = 0; + reset_indices_dec_fx( st ); + + st->bfi = !qbit; + total_brate = (Word32) (num_bits) *50; + st->total_num_bits = num_bits; + + if ( num_bits == 0 ) /* guess type of missing frame for SP_LOST and NO_DATA */ + { + speech_lost = st->CNG_fx == 0; + no_data = st->CNG_fx != 0; + } + + if ( partialframe || st->prev_use_partial_copy ) + { + st->next_coder_type = next_coder_type; + } + else + { + st->next_coder_type = INACTIVE; + } + + if ( partialframe == 1 ) + { + st->bfi = 2; + } + + /* unpack speech data */ + bit_stream_ptr = st->bit_stream; + /* convert bitstream from compact bytes to short values and store it in decoder state */ + for ( k = 0; k < num_bits; k++ ) + { + if ( st->bitstreamformat == VOIP_RTPDUMP && isAMRWB_IOmode ) + { + st->bit_stream[sort_ptr[core_mode][k]] = unpack_bit( &pt_stream, &mask ); + bit_stream_ptr++; + } + else + { + *bit_stream_ptr++ = unpack_bit( &pt_stream, &mask ); + } + } + + /* unpack auxiliary bits */ + if ( isAMRWB_IOmode && total_brate == SID_1k75 ) + { + if ( st->bitstreamformat == VOIP_RTPDUMP ) + { + /* A.2.2.1.3: AMR-WB SID_1k75 frame is followed by STI bit and CMI bits */ + sti = unpack_bit( &pt_stream, &mask ); + } + else + { + /* VOIP_G192_RTP does not contain STI and CMI */ + sti = 1; + } + read_indices_mime_handle_sti_and_all_zero_bits( st, &total_brate, sti ); + } + + /* add two zero bytes for arithmetic coder flush */ + for ( k = 0; k < 8 * 2; ++k ) + { + *bit_stream_ptr++ = 0; + } + total_brate = read_indices_mime_handle_dtx( st, isAMRWB_IOmode, core_mode, total_brate, sti, speech_lost, no_data ); + /* st->CNG_fx set inside */ + + if ( st->bfi != 1 ) + { + /* select Mode 1 or Mode 2 */ + decoder_selectCodec( st, total_brate, *st->bit_stream ? G192_BIN1 : G192_BIN0 ); + + /* a change of the total bitrate should not be known to the decoder, if the received frame was truly lost */ + st->total_brate = total_brate; + + mdct_switching_dec( st ); + } +} /*-------------------------------------------------------------------* @@ -2672,32 +2654,31 @@ void read_indices_from_djb_fx( * Indices preview to parse for the presence of partial copy *-------------------------------------------------------------------*/ static UWord16 get_indice_preview( - UWord8 *bitstream, - Word16 bitstreamSize, - Word16 pos, - Word16 nb_bits -) + UWord8 *bitstream, + Word16 bitstreamSize, + Word16 pos, + Word16 nb_bits ) { - UWord16 value; - Word16 i; - UWord16 bitstreamShort[MAX_BITS_PER_FRAME + 16]; - UWord16 *bitstreamShortPtr; - - /* convert bitstream from compact bytes to short values */ - bitstreamShortPtr = bitstreamShort; - FOR(i = 0; i < bitstreamSize; i++) - { - *bitstreamShortPtr++ = (bitstream[i / 8] >> (7 - (i % 8))) & 0x1; - } - - assert(nb_bits <= 16); - value = 0; - FOR(i = 0; i < nb_bits; i++) - { - value = shl(value, 1); - value = add(value, bitstreamShort[pos + i]); - } - return value; + UWord16 value; + Word16 i; + UWord16 bitstreamShort[MAX_BITS_PER_FRAME + 16]; + UWord16 *bitstreamShortPtr; + + /* convert bitstream from compact bytes to short values */ + bitstreamShortPtr = bitstreamShort; + FOR( i = 0; i < bitstreamSize; i++ ) + { + *bitstreamShortPtr++ = ( bitstream[i / 8] >> ( 7 - ( i % 8 ) ) ) & 0x1; + } + + assert( nb_bits <= 16 ); + value = 0; + FOR( i = 0; i < nb_bits; i++ ) + { + value = shl( value, 1 ); + value = add( value, bitstreamShort[pos + i] ); + } + return value; } /*-------------------------------------------------------------------* @@ -2706,56 +2687,55 @@ static UWord16 get_indice_preview( * Signalling index preview *-------------------------------------------------------------------*/ void evs_dec_previewFrame( - UWord8 *bitstream, - Word16 bitstreamSize, - Word16 *partialCopyFrameType, - Word16 *partialCopyOffset -) + UWord8 *bitstream, + Word16 bitstreamSize, + Word16 *partialCopyFrameType, + Word16 *partialCopyOffset ) { - Word32 total_brate; - Word16 start_idx, nBits; - Word32 ind; - Word16 rf_flag; - - rf_flag = 0; - *partialCopyFrameType = 0; - *partialCopyOffset = 0; - total_brate = bitstreamSize * 50; - - IF(EQ_32(total_brate, ACELP_13k20)) - { - /* find the section in the ACELP signalling table corresponding to bitrate */ - start_idx = 0; - WHILE(NE_32(acelp_sig_tbl[start_idx], total_brate)) - { - start_idx = add(start_idx, 1); - assert((start_idx < MAX_ACELP_SIG) && "ERROR: start_idx larger than acelp_sig_tbl[].\n"); - } - - /* skip the bitrate */ - start_idx = add(start_idx, 1); - /* retrieve the number of bits */ - nBits = (Word16)acelp_sig_tbl[start_idx++]; - - /* retrieve the signalling indice */ - ind = acelp_sig_tbl[start_idx + get_indice_preview(bitstream, bitstreamSize, 0, nBits)]; - - /* convert signalling indice into RF flag. */ - rf_flag = s_and(extract_l(L_shr(ind, 7)), 0x1); - assert(rf_flag == ((ind >> 7) & 0x1)); - IF(rf_flag != 0) - { - /* read the fec offset at which the partial copy is received */ - ind = get_indice_preview(bitstream, bitstreamSize, (bitstreamSize - 5), 2); - IF(ind == 0) *partialCopyOffset = 2; - ELSE IF(EQ_32(ind, 1))*partialCopyOffset = 3; - ELSE IF(EQ_32(ind, 2))*partialCopyOffset = 5; - ELSE IF(EQ_32(ind, 3))*partialCopyOffset = 7; - - /* the last three bits in a packet is the RF frame type */ - *partialCopyFrameType = get_indice_preview(bitstream, bitstreamSize, bitstreamSize - 3, 3); - } - } + Word32 total_brate; + Word16 start_idx, nBits; + Word32 ind; + Word16 rf_flag; + + rf_flag = 0; + *partialCopyFrameType = 0; + *partialCopyOffset = 0; + total_brate = bitstreamSize * 50; + + IF( EQ_32( total_brate, ACELP_13k20 ) ) + { + /* find the section in the ACELP signalling table corresponding to bitrate */ + start_idx = 0; + WHILE( NE_32( acelp_sig_tbl[start_idx], total_brate ) ) + { + start_idx = add( start_idx, 1 ); + assert( ( start_idx < MAX_ACELP_SIG ) && "ERROR: start_idx larger than acelp_sig_tbl[].\n" ); + } + + /* skip the bitrate */ + start_idx = add( start_idx, 1 ); + /* retrieve the number of bits */ + nBits = (Word16) acelp_sig_tbl[start_idx++]; + + /* retrieve the signalling indice */ + ind = acelp_sig_tbl[start_idx + get_indice_preview( bitstream, bitstreamSize, 0, nBits )]; + + /* convert signalling indice into RF flag. */ + rf_flag = s_and( extract_l( L_shr( ind, 7 ) ), 0x1 ); + assert( rf_flag == ( ( ind >> 7 ) & 0x1 ) ); + IF( rf_flag != 0 ) + { + /* read the fec offset at which the partial copy is received */ + ind = get_indice_preview( bitstream, bitstreamSize, ( bitstreamSize - 5 ), 2 ); + IF( ind == 0 ) *partialCopyOffset = 2; + ELSE IF( EQ_32( ind, 1 ) ) *partialCopyOffset = 3; + ELSE IF( EQ_32( ind, 2 ) ) *partialCopyOffset = 5; + ELSE IF( EQ_32( ind, 3 ) ) *partialCopyOffset = 7; + + /* the last three bits in a packet is the RF frame type */ + *partialCopyFrameType = get_indice_preview( bitstream, bitstreamSize, bitstreamSize - 3, 3 ); + } + } } void dtx_read_padding_bits_fx( diff --git a/lib_com/cb_shape_fx.c b/lib_com/cb_shape_fx.c index 293d15ca5..d8dec57d6 100644 --- a/lib_com/cb_shape_fx.c +++ b/lib_com/cb_shape_fx.c @@ -2,11 +2,11 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "rom_com.h" /* */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "rom_com.h" /* */ /* * E_GAIN_f_pitch_sharpening @@ -22,47 +22,47 @@ * Returns: * void */ -static void E_GAIN_f_pitch_sharpening(Word16 *x, Word16 pit_lag, Word16 L_subfr) +static void E_GAIN_f_pitch_sharpening( Word16 *x, Word16 pit_lag, Word16 L_subfr ) { Word16 i, tmp; - FOR (i = pit_lag; i < L_subfr; i++) + FOR( i = pit_lag; i < L_subfr; i++ ) { /*x[i] += x[i - pit_lag] * F_PIT_SHARP;*/ - tmp = mult_r(x[i - pit_lag], 27853/*F_PIT_SHARP Q15*/); - x[i] = add(x[i],tmp); + tmp = mult_r( x[i - pit_lag], 27853 /*F_PIT_SHARP Q15*/ ); + x[i] = add( x[i], tmp ); move16(); } return; } /*-------------------------------------------------------------------* - * cb_shape() - * - * pre-emphasis, pitch sharpening and formant sharpening of the algebraic codebook - *-------------------------------------------------------------------*/ + * cb_shape() + * + * pre-emphasis, pitch sharpening and formant sharpening of the algebraic codebook + *-------------------------------------------------------------------*/ void cb_shape_fx( - const Word16 preemphFlag, /* i : flag for pre-emphasis */ - const Word16 pitchFlag, /* i : flag for pitch sharpening */ - const Word16 scramblingFlag, /* i : flag for phase scrambling */ - const Word16 sharpFlag, /* i : flag for formant sharpening */ - const Word16 formantTiltFlag, /* i : flag for formant tilt */ - const Word16 g1, /* i : formant sharpening numerator weighting */ - const Word16 g2, /* i : formant sharpening denominator weighting */ - const Word16 *p_Aq, /* i : LP filter coefficients */ - Word16 *code, /* i/o: signal to shape */ - const Word16 tilt_code, /* i : tilt of code */ - const Word16 pt_pitch, /* i : pointer to current subframe fractional pitch */ + const Word16 preemphFlag, /* i : flag for pre-emphasis */ + const Word16 pitchFlag, /* i : flag for pitch sharpening */ + const Word16 scramblingFlag, /* i : flag for phase scrambling */ + const Word16 sharpFlag, /* i : flag for formant sharpening */ + const Word16 formantTiltFlag, /* i : flag for formant tilt */ + const Word16 g1, /* i : formant sharpening numerator weighting */ + const Word16 g2, /* i : formant sharpening denominator weighting */ + const Word16 *p_Aq, /* i : LP filter coefficients */ + Word16 *code, /* i/o: signal to shape */ + const Word16 tilt_code, /* i : tilt of code */ + const Word16 pt_pitch, /* i : pointer to current subframe fractional pitch */ const Word16 shift, - const Word16 L_subfr /* i : subframe lenght */ + const Word16 L_subfr /* i : subframe lenght */ ) { - Word16 tmp, buff[2*L_SUBFR + M], A_num[M + 1], A_den[M + 1]; + Word16 tmp, buff[2 * L_SUBFR + M], A_num[M + 1], A_den[M + 1]; Word16 i; Word32 L_tmp; Word16 tilt, mu; - + tmp = 0; move16(); @@ -70,13 +70,13 @@ void cb_shape_fx( /* Pre-emphasis */ IF( preemphFlag ) { - preemph_copy_fx(code, code, tilt_code, L_subfr, &tmp); + preemph_copy_fx( code, code, tilt_code, L_subfr, &tmp ); } /* pitch sharpening */ IF( pitchFlag ) { - E_GAIN_f_pitch_sharpening( code, pt_pitch, L_subfr); + E_GAIN_f_pitch_sharpening( code, pt_pitch, L_subfr ); } /* phase scrambling filter */ @@ -84,52 +84,51 @@ void cb_shape_fx( { buff[0] = code[0]; move16(); - FOR (i = 1; i < L_subfr; i++) + FOR( i = 1; i < L_subfr; i++ ) { - buff[i]=code[i]; + buff[i] = code[i]; move16(); /*code[i] = 0.7f*buff[i] + buff[i-1] - 0.7f*code[i-1]; */ - L_tmp = L_mult(22938, buff[i]); - tmp = mac_r(L_tmp,-22938, code[i-1]); - code[i] = add(tmp,buff[i-1]); + L_tmp = L_mult( 22938, buff[i] ); + tmp = mac_r( L_tmp, -22938, code[i - 1] ); + code[i] = add( tmp, buff[i - 1] ); move16(); } } test(); - IF ( sharpFlag || formantTiltFlag ) + IF( sharpFlag || formantTiltFlag ) { weight_a_fx( p_Aq, A_num, g1, M ); weight_a_fx( p_Aq, A_den, g2, M ); - set16_fx(buff, 0, M+ L_subfr); - IF( formantTiltFlag ) + set16_fx( buff, 0, M + L_subfr ); + IF( formantTiltFlag ) { - Copy(A_num, buff+M, M+1); + Copy( A_num, buff + M, M + 1 ); - E_UTIL_synthesis(1, A_den, buff+M, buff+M, L_subfr, buff, 0, M); + E_UTIL_synthesis( 1, A_den, buff + M, buff + M, L_subfr, buff, 0, M ); /*Compute tilt of formant enhancement*/ - tilt = extract_l(L_shr(get_gain(buff+M+1, buff+M, L_subfr -1),1)); + tilt = extract_l( L_shr( get_gain( buff + M + 1, buff + M, L_subfr - 1 ), 1 ) ); /*Combine tilt of code and fe*/ tmp = 0; move16(); /*mu = 0.5f*tilt_code-0.25f*tilt;*/ - mu = sub(shr(tilt_code,1),shr(tilt,2)); - preemph_copy_fx(code, code, mu, L_subfr, &tmp); + mu = sub( shr( tilt_code, 1 ), shr( tilt, 2 ) ); + preemph_copy_fx( code, code, mu, L_subfr, &tmp ); } ELSE { - Copy( code, buff, L_subfr); + Copy( code, buff, L_subfr ); move16(); - Residu3_lc_fx(A_num, M, buff, code, L_subfr, shift); + Residu3_lc_fx( A_num, M, buff, code, L_subfr, shift ); { - syn_filt_s_lc_fx(shift, A_den, code, code, L_subfr); + syn_filt_s_lc_fx( shift, A_den, code, code, L_subfr ); } } } return; } - diff --git a/lib_com/cldfb.c b/lib_com/cldfb.c index 63a4dd34f..f7c03a8f9 100644 --- a/lib_com/cldfb.c +++ b/lib_com/cldfb.c @@ -689,13 +689,15 @@ void cldfbAnalysis_ts_ivas( #ifdef IVAS_FLOAT_FIXED void cldfbAnalysis_ts_fx( - const Word32 *timeIn_fx, /* i : time buffer */ // q - Word32 realBuffer_fx[CLDFB_NO_CHANNELS_MAX], /* o : real value buffer */ // q - 5 - Word32 imagBuffer_fx[CLDFB_NO_CHANNELS_MAX], /* o : imag value buffer */ // q - 5 - const Word16 samplesToProcess, /* i : samples to process */ - HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i : filterbank state */ - Word16* q_cldfb -) + const Word32 *timeIn_fx, + /* i : time buffer */ // q + Word32 realBuffer_fx[CLDFB_NO_CHANNELS_MAX], + /* o : real value buffer */ // q - 5 + Word32 imagBuffer_fx[CLDFB_NO_CHANNELS_MAX], + /* o : imag value buffer */ // q - 5 + const Word16 samplesToProcess, /* i : samples to process */ + HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i : filterbank state */ + Word16 *q_cldfb ) { Word16 i, k; Word16 L2, M1, M2, M4; @@ -750,8 +752,8 @@ void cldfbAnalysis_ts_fx( M4 += 1; } - rot_vctr_re_fx = h_cldfb->rot_vec_ana_re_fx; // q = 29 - rot_vctr_im_fx = h_cldfb->rot_vec_ana_im_fx; // q = 29 + rot_vctr_re_fx = h_cldfb->rot_vec_ana_re_fx; // q = 29 + rot_vctr_im_fx = h_cldfb->rot_vec_ana_im_fx; // q = 29 rot_vctr_delay_re_fx = h_cldfb->rot_vec_ana_delay_re_fx; // q = 31 rot_vctr_delay_im_fx = h_cldfb->rot_vec_ana_delay_im_fx; // q = 31 @@ -763,108 +765,110 @@ void cldfbAnalysis_ts_fx( for ( k = 0; k < M4; k++ ) { /* prototype filter */ - r1_fx = L_sub(0, Mpy_32_16_1(timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 0 * L2 )])); // q - r1_fx = L_sub(r1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )])); // q - r1_fx = L_sub(r1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )])); // q - r1_fx = L_sub(r1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )])); // q - r1_fx = L_sub(r1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )])); // q - - r2_fx = L_sub(0, Mpy_32_16_1(timeBuffer_fx[L2 - M2 + ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 0 * L2 )])); // q - r2_fx = L_sub(r2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 + ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 1 * L2 )])); // q - r2_fx = L_sub(r2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 + ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 2 * L2 )])); // q - r2_fx = L_sub(r2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 + ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 3 * L2 )])); // q - r2_fx = L_sub(r2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 + ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 4 * L2 )])); // q - - i1_fx = L_sub(0, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 0 * L2 )])); // q - i1_fx = L_sub(i1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 1 * L2 )])); // q - i1_fx = L_sub(i1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 2 * L2 )])); // q - i1_fx = L_sub(i1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 3 * L2 )])); // q - i1_fx = L_sub(i1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 4 * L2 )])); // q - - i2_fx = L_sub(0, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 - 1 - ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 0 * L2 )])); // q - i2_fx = L_sub(i2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 - 1 - ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 1 * L2 )])); // q - i2_fx = L_sub(i2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 - 1 - ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 2 * L2 )])); // q - i2_fx = L_sub(i2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 - 1 - ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 3 * L2 )])); // q - i2_fx = L_sub(i2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 - 1 - ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 4 * L2 )])); // q - - r1_fx = Mpy_32_16_1(r1_fx, ptr_pf_sf); // q - 1 - r2_fx = Mpy_32_16_1(r2_fx, ptr_pf_sf); // q - 1 - i1_fx = Mpy_32_16_1(i1_fx, ptr_pf_sf); // q - 1 - i2_fx = Mpy_32_16_1(i2_fx, ptr_pf_sf); // q - 1 + r1_fx = L_sub( 0, Mpy_32_16_1( timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 0 * L2 )] ) ); // q + r1_fx = L_sub( r1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )] ) ); // q + r1_fx = L_sub( r1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )] ) ); // q + r1_fx = L_sub( r1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )] ) ); // q + r1_fx = L_sub( r1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )] ) ); // q + + r2_fx = L_sub( 0, Mpy_32_16_1( timeBuffer_fx[L2 - M2 + ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 0 * L2 )] ) ); // q + r2_fx = L_sub( r2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 + ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 1 * L2 )] ) ); // q + r2_fx = L_sub( r2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 + ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 2 * L2 )] ) ); // q + r2_fx = L_sub( r2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 + ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 3 * L2 )] ) ); // q + r2_fx = L_sub( r2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 + ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 4 * L2 )] ) ); // q + + i1_fx = L_sub( 0, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 0 * L2 )] ) ); // q + i1_fx = L_sub( i1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 1 * L2 )] ) ); // q + i1_fx = L_sub( i1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 2 * L2 )] ) ); // q + i1_fx = L_sub( i1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 3 * L2 )] ) ); // q + i1_fx = L_sub( i1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 4 * L2 )] ) ); // q + + i2_fx = L_sub( 0, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 - 1 - ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 0 * L2 )] ) ); // q + i2_fx = L_sub( i2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 - 1 - ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 1 * L2 )] ) ); // q + i2_fx = L_sub( i2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 - 1 - ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 2 * L2 )] ) ); // q + i2_fx = L_sub( i2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 - 1 - ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 3 * L2 )] ) ); // q + i2_fx = L_sub( i2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 - 1 - ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 4 * L2 )] ) ); // q + + r1_fx = Mpy_32_16_1( r1_fx, ptr_pf_sf ); // q - 1 + r2_fx = Mpy_32_16_1( r2_fx, ptr_pf_sf ); // q - 1 + i1_fx = Mpy_32_16_1( i1_fx, ptr_pf_sf ); // q - 1 + i2_fx = Mpy_32_16_1( i2_fx, ptr_pf_sf ); // q - 1 /* folding + pre modulation of DST IV */ - rr12_fx = L_sub( r1_fx, r2_fx ); // q -1 + rr12_fx = L_sub( r1_fx, r2_fx ); // q -1 ri12_fx = L_negate( L_add( i1_fx, i2_fx ) ); // q - 1 /*cplxMult(&rBuffer[2*k],&rBuffer[2*k+1],rr12,ri12,rot_vctr_re[k],rot_vctr_im[k]);*/ - rBuffer_fx[2 * k] = L_sub(Mpy_32_32(rr12_fx, rot_vctr_re_fx[k]), Mpy_32_32(ri12_fx, rot_vctr_im_fx[k])); // q - 3 - rBuffer_fx[2 * k + 1] = L_add(Mpy_32_32(rr12_fx, rot_vctr_im_fx[k]), Mpy_32_32(ri12_fx, rot_vctr_re_fx[k])); // q - 3 + rBuffer_fx[2 * k] = L_sub( Mpy_32_32( rr12_fx, rot_vctr_re_fx[k] ), Mpy_32_32( ri12_fx, rot_vctr_im_fx[k] ) ); // q - 3 + rBuffer_fx[2 * k + 1] = L_add( Mpy_32_32( rr12_fx, rot_vctr_im_fx[k] ), Mpy_32_32( ri12_fx, rot_vctr_re_fx[k] ) ); // q - 3 ///* folding + pre modulation of DCT IV */ - ir12_fx = L_add(r1_fx, r2_fx); // q - 1 - ii12_fx = L_sub(i1_fx, i2_fx); // q - 1 + ir12_fx = L_add( r1_fx, r2_fx ); // q - 1 + ii12_fx = L_sub( i1_fx, i2_fx ); // q - 1 /*cplxMult(&iBuffer[2*k],&iBuffer[2*k+1],ir12,ii12,rot_vctr_re[k],rot_vctr_im[k]);*/ - iBuffer_fx[2 * k] = L_sub(Mpy_32_32(ir12_fx, rot_vctr_re_fx[k]), Mpy_32_32(ii12_fx, rot_vctr_im_fx[k])); // q - 3 - iBuffer_fx[2 * k + 1] = L_add(Mpy_32_32(ir12_fx, rot_vctr_im_fx[k]), Mpy_32_32(ii12_fx, rot_vctr_re_fx[k])); // q - 3 + iBuffer_fx[2 * k] = L_sub( Mpy_32_32( ir12_fx, rot_vctr_re_fx[k] ), Mpy_32_32( ii12_fx, rot_vctr_im_fx[k] ) ); // q - 3 + iBuffer_fx[2 * k + 1] = L_add( Mpy_32_32( ir12_fx, rot_vctr_im_fx[k] ), Mpy_32_32( ii12_fx, rot_vctr_re_fx[k] ) ); // q - 3 } for ( k = M4; k < M2; k++ ) { /* prototype filter */ - r1_fx = L_sub(0, Mpy_32_16_1(timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 0 * L2 )])); // q - r1_fx = L_sub(r1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )])); // q - r1_fx = L_sub(r1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )])); // q - r1_fx = L_sub(r1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )])); // q - r1_fx = L_sub(r1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )])); // q - - r2_fx = L_sub(0, Mpy_32_16_1(timeBuffer_fx[L2 - 5 * M2 + ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 0 * L2 )])); // q - r2_fx = L_sub(r2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 5 * M2 + ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 1 * L2 )])); // q - r2_fx = L_sub(r2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 5 * M2 + ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 2 * L2 )])); // q - r2_fx = L_sub(r2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 5 * M2 + ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 3 * L2 )])); // q - r2_fx = L_sub(r2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 5 * M2 + ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 4 * L2 )])); // q - - i1_fx = L_sub(0, Mpy_32_16_1(timeBuffer_fx[L2 + M2 - 1 - ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 0 * L2 )])); // q - i1_fx = L_sub(i1_fx, Mpy_32_16_1(timeBuffer_fx[L2 + M2 - 1 - ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 1 * L2 )])); // q - i1_fx = L_sub(i1_fx, Mpy_32_16_1(timeBuffer_fx[L2 + M2 - 1 - ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 2 * L2 )])); // q - i1_fx = L_sub(i1_fx, Mpy_32_16_1(timeBuffer_fx[L2 + M2 - 1 - ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 3 * L2 )])); // q - i1_fx = L_sub(i1_fx, Mpy_32_16_1(timeBuffer_fx[L2 + M2 - 1 - ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 4 * L2 )])); // q - - i2_fx = L_sub(0, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 0 * L2 )])); // q - i2_fx = L_sub(i2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 1 * L2 )])); // q - i2_fx = L_sub(i2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 2 * L2 )])); // q - i2_fx = L_sub(i2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 3 * L2 )])); // q - i2_fx = L_sub(i2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 4 * L2 )])); // q - - r1_fx = Mpy_32_16_1(r1_fx, ptr_pf_sf); // q - 1 - r2_fx = Mpy_32_16_1(r2_fx, ptr_pf_sf); // q - 1 - i1_fx = Mpy_32_16_1(i1_fx, ptr_pf_sf); // q - 1 - i2_fx = Mpy_32_16_1(i2_fx, ptr_pf_sf); // q - 1 + r1_fx = L_sub( 0, Mpy_32_16_1( timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 0 * L2 )] ) ); // q + r1_fx = L_sub( r1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )] ) ); // q + r1_fx = L_sub( r1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )] ) ); // q + r1_fx = L_sub( r1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )] ) ); // q + r1_fx = L_sub( r1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )] ) ); // q + + r2_fx = L_sub( 0, Mpy_32_16_1( timeBuffer_fx[L2 - 5 * M2 + ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 0 * L2 )] ) ); // q + r2_fx = L_sub( r2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 5 * M2 + ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 1 * L2 )] ) ); // q + r2_fx = L_sub( r2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 5 * M2 + ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 2 * L2 )] ) ); // q + r2_fx = L_sub( r2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 5 * M2 + ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 3 * L2 )] ) ); // q + r2_fx = L_sub( r2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 5 * M2 + ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 4 * L2 )] ) ); // q + + i1_fx = L_sub( 0, Mpy_32_16_1( timeBuffer_fx[L2 + M2 - 1 - ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 0 * L2 )] ) ); // q + i1_fx = L_sub( i1_fx, Mpy_32_16_1( timeBuffer_fx[L2 + M2 - 1 - ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 1 * L2 )] ) ); // q + i1_fx = L_sub( i1_fx, Mpy_32_16_1( timeBuffer_fx[L2 + M2 - 1 - ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 2 * L2 )] ) ); // q + i1_fx = L_sub( i1_fx, Mpy_32_16_1( timeBuffer_fx[L2 + M2 - 1 - ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 3 * L2 )] ) ); // q + i1_fx = L_sub( i1_fx, Mpy_32_16_1( timeBuffer_fx[L2 + M2 - 1 - ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 4 * L2 )] ) ); // q + + i2_fx = L_sub( 0, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 0 * L2 )] ) ); // q + i2_fx = L_sub( i2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 1 * L2 )] ) ); // q + i2_fx = L_sub( i2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 2 * L2 )] ) ); // q + i2_fx = L_sub( i2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 3 * L2 )] ) ); // q + i2_fx = L_sub( i2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 4 * L2 )] ) ); // q + + r1_fx = Mpy_32_16_1( r1_fx, ptr_pf_sf ); // q - 1 + r2_fx = Mpy_32_16_1( r2_fx, ptr_pf_sf ); // q - 1 + i1_fx = Mpy_32_16_1( i1_fx, ptr_pf_sf ); // q - 1 + i2_fx = Mpy_32_16_1( i2_fx, ptr_pf_sf ); // q - 1 /* folding + pre modulation of DST IV */ - rr12_fx = L_add(r1_fx, r2_fx); // q - 1 - ri12_fx = L_sub(i1_fx, i2_fx); // q - 1 + rr12_fx = L_add( r1_fx, r2_fx ); // q - 1 + ri12_fx = L_sub( i1_fx, i2_fx ); // q - 1 /*cplxMult(&rBuffer[2*k],&rBuffer[2*k+1],rr12,ri12,rot_vctr_re[k],rot_vctr_im[k]);*/ - rBuffer_fx[2 * k] = L_sub(Mpy_32_32(rr12_fx, rot_vctr_re_fx[k]), Mpy_32_32(ri12_fx, rot_vctr_im_fx[k])); // q - 3 - rBuffer_fx[2 * k + 1] = L_add(Mpy_32_32(rr12_fx, rot_vctr_im_fx[k]), Mpy_32_32(ri12_fx, rot_vctr_re_fx[k])); // q - 3 + rBuffer_fx[2 * k] = L_sub( Mpy_32_32( rr12_fx, rot_vctr_re_fx[k] ), Mpy_32_32( ri12_fx, rot_vctr_im_fx[k] ) ); // q - 3 + rBuffer_fx[2 * k + 1] = L_add( Mpy_32_32( rr12_fx, rot_vctr_im_fx[k] ), Mpy_32_32( ri12_fx, rot_vctr_re_fx[k] ) ); // q - 3 /* folding + pre modulation of DCT IV */ - ir12_fx = L_sub(r1_fx, r2_fx); // q - 1 - ii12_fx = L_add(i1_fx, i2_fx); // q - 1 + ir12_fx = L_sub( r1_fx, r2_fx ); // q - 1 + ii12_fx = L_add( i1_fx, i2_fx ); // q - 1 /*cplxMult(&iBuffer[2*k],&iBuffer[2*k+1],ir12,ii12,rot_vctr_re[k],rot_vctr_im[k]);*/ - iBuffer_fx[2 * k] = L_sub(Mpy_32_32(ir12_fx, rot_vctr_re_fx[k]), Mpy_32_32(ii12_fx, rot_vctr_im_fx[k])); // q - 3 - iBuffer_fx[2 * k + 1] = L_add(Mpy_32_32(ir12_fx, rot_vctr_im_fx[k]), Mpy_32_32(ii12_fx, rot_vctr_re_fx[k])); // q - 3 + iBuffer_fx[2 * k] = L_sub( Mpy_32_32( ir12_fx, rot_vctr_re_fx[k] ), Mpy_32_32( ii12_fx, rot_vctr_im_fx[k] ) ); // q - 3 + iBuffer_fx[2 * k + 1] = L_add( Mpy_32_32( ir12_fx, rot_vctr_im_fx[k] ), Mpy_32_32( ii12_fx, rot_vctr_re_fx[k] ) ); // q - 3 } - - *q_cldfb = sub(*q_cldfb, 3); + + *q_cldfb = sub( *q_cldfb, 3 ); /* FFT of DST IV */ Word16 q_shift; - q_shift = sub(s_min(getScaleFactor32(rBuffer_fx, 2 * M2), getScaleFactor32(iBuffer_fx, 2 * M2)), find_guarded_bits_fx(M2)); - *q_cldfb = add(*q_cldfb, q_shift); - for (Word16 ind = 0; ind < 2 * M2; ind++) { - rBuffer_fx[ind] = L_shl(rBuffer_fx[ind], q_shift); + q_shift = sub( s_min( getScaleFactor32( rBuffer_fx, 2 * M2 ), getScaleFactor32( iBuffer_fx, 2 * M2 ) ), find_guarded_bits_fx( M2 ) ); + *q_cldfb = add( *q_cldfb, q_shift ); + for ( Word16 ind = 0; ind < 2 * M2; ind++ ) + { + rBuffer_fx[ind] = L_shl( rBuffer_fx[ind], q_shift ); } - for (Word16 ind = 0; ind < 2 * M2; ind++) { - iBuffer_fx[ind] = L_shl(iBuffer_fx[ind], q_shift); + for ( Word16 ind = 0; ind < 2 * M2; ind++ ) + { + iBuffer_fx[ind] = L_shl( iBuffer_fx[ind], q_shift ); } fft_cldfb_fx( rBuffer_fx, M2 ); @@ -872,21 +876,23 @@ void cldfbAnalysis_ts_fx( for ( k = 0; k < M2; k++ ) { /*cplxMult(&realBuffer[M1-1-(2*k)],&realBuffer[2*k],rBuffer[2*k],rBuffer[2*k+1],rot_vctr_re[k],rot_vctr_im[k]);*/ - realBuffer_fx[M1 - 1 - ( 2 * k )] = L_sub(Mpy_32_32(rBuffer_fx[2 * k], rot_vctr_re_fx[k]), Mpy_32_32(rBuffer_fx[2 * k + 1], rot_vctr_im_fx[k])); // q - 5 - realBuffer_fx[2 * k] = L_add(Mpy_32_32(rBuffer_fx[2 * k], rot_vctr_im_fx[k]), Mpy_32_32(rBuffer_fx[2 * k + 1], rot_vctr_re_fx[k])); // q - 5 + realBuffer_fx[M1 - 1 - ( 2 * k )] = L_sub( Mpy_32_32( rBuffer_fx[2 * k], rot_vctr_re_fx[k] ), Mpy_32_32( rBuffer_fx[2 * k + 1], rot_vctr_im_fx[k] ) ); // q - 5 + realBuffer_fx[2 * k] = L_add( Mpy_32_32( rBuffer_fx[2 * k], rot_vctr_im_fx[k] ), Mpy_32_32( rBuffer_fx[2 * k + 1], rot_vctr_re_fx[k] ) ); // q - 5 } - *q_cldfb = sub(*q_cldfb, 2); + *q_cldfb = sub( *q_cldfb, 2 ); /* FFT of DCT IV */ fft_cldfb_fx( iBuffer_fx, M2 ); - q_shift = s_min(getScaleFactor32(rBuffer_fx, 2 * M2), getScaleFactor32(iBuffer_fx, 2 * M2)); - *q_cldfb = add(*q_cldfb, q_shift); - for (Word16 ind = 0; ind < 2 * M2; ind++) { - rBuffer_fx[ind] = L_shl(rBuffer_fx[ind], q_shift); + q_shift = s_min( getScaleFactor32( rBuffer_fx, 2 * M2 ), getScaleFactor32( iBuffer_fx, 2 * M2 ) ); + *q_cldfb = add( *q_cldfb, q_shift ); + for ( Word16 ind = 0; ind < 2 * M2; ind++ ) + { + rBuffer_fx[ind] = L_shl( rBuffer_fx[ind], q_shift ); } - for (Word16 ind = 0; ind < 2 * M2; ind++) { - iBuffer_fx[ind] = L_shl(iBuffer_fx[ind], q_shift); + for ( Word16 ind = 0; ind < 2 * M2; ind++ ) + { + iBuffer_fx[ind] = L_shl( iBuffer_fx[ind], q_shift ); } /* post modulation of DCT IV */ @@ -894,8 +900,8 @@ void cldfbAnalysis_ts_fx( { /* do it inplace */ /*cplxMult(&imagBuffer[2*k],&imagBuffer[M1-1-(2*k)],iBuffer[2*k],iBuffer[2*k+1],rot_vctr_re[k],rot_vctr_im[k]);*/ - imagBuffer_fx[2 * k] = L_sub(Mpy_32_32(iBuffer_fx[2 * k], rot_vctr_re_fx[k]), Mpy_32_32(iBuffer_fx[2 * k + 1], rot_vctr_im_fx[k])); // q - 5 - imagBuffer_fx[M1 - 1 - ( 2 * k )] = L_add(Mpy_32_32(iBuffer_fx[2 * k], rot_vctr_im_fx[k]), Mpy_32_32(iBuffer_fx[2 * k + 1], rot_vctr_re_fx[k])); // q - 5 + imagBuffer_fx[2 * k] = L_sub( Mpy_32_32( iBuffer_fx[2 * k], rot_vctr_re_fx[k] ), Mpy_32_32( iBuffer_fx[2 * k + 1], rot_vctr_im_fx[k] ) ); // q - 5 + imagBuffer_fx[M1 - 1 - ( 2 * k )] = L_add( Mpy_32_32( iBuffer_fx[2 * k], rot_vctr_im_fx[k] ), Mpy_32_32( iBuffer_fx[2 * k + 1], rot_vctr_re_fx[k] ) ); // q - 5 } if ( h_cldfb->prototype == CLDFB_PROTOTYPE_5_00MS ) @@ -914,8 +920,8 @@ void cldfbAnalysis_ts_fx( /*cplxMult(&realBuffer[k], &imagBuffer[k], realBuffer[k], imagBuffer[k], rot_vctr_delay_re[k], rot_vctr_delay_im[k]);*/ /*realBuffer[k] = rBuffer[k]; imagBuffer[k] = iBuffer[k];*/ - cplx_aux_fx = L_sub(Mpy_32_32(realBuffer_fx[k], rot_vctr_delay_re_fx[k]), Mpy_32_32(imagBuffer_fx[k], rot_vctr_delay_im_fx[k])); // q - 5 - imagBuffer_fx[k] = L_add(Mpy_32_32(realBuffer_fx[k], rot_vctr_delay_im_fx[k]), Mpy_32_32(imagBuffer_fx[k], rot_vctr_delay_re_fx[k])); // q - 5 + cplx_aux_fx = L_sub( Mpy_32_32( realBuffer_fx[k], rot_vctr_delay_re_fx[k] ), Mpy_32_32( imagBuffer_fx[k], rot_vctr_delay_im_fx[k] ) ); // q - 5 + imagBuffer_fx[k] = L_add( Mpy_32_32( realBuffer_fx[k], rot_vctr_delay_im_fx[k] ), Mpy_32_32( imagBuffer_fx[k], rot_vctr_delay_re_fx[k] ) ); // q - 5 realBuffer_fx[k] = cplx_aux_fx; } } @@ -939,13 +945,15 @@ void cldfbAnalysis_ts_fx( } void cldfbAnalysis_ts_fx_fixed_q( - const Word32 *timeIn_fx, /* i : time buffer */ // q - Word32 realBuffer_fx[CLDFB_NO_CHANNELS_MAX], /* o : real value buffer */ // q - 5 - Word32 imagBuffer_fx[CLDFB_NO_CHANNELS_MAX], /* o : imag value buffer */ // q - 5 - const Word16 samplesToProcess, /* i : samples to process */ - HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i : filterbank state */ - Word16* q_cldfb -) + const Word32 *timeIn_fx, + /* i : time buffer */ // q + Word32 realBuffer_fx[CLDFB_NO_CHANNELS_MAX], + /* o : real value buffer */ // q - 5 + Word32 imagBuffer_fx[CLDFB_NO_CHANNELS_MAX], + /* o : imag value buffer */ // q - 5 + const Word16 samplesToProcess, /* i : samples to process */ + HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i : filterbank state */ + Word16 *q_cldfb ) { Word16 i, k; Word16 L2, M1, M2, M4; @@ -999,8 +1007,8 @@ void cldfbAnalysis_ts_fx_fixed_q( M4 += 1; } - rot_vctr_re_fx = h_cldfb->rot_vec_ana_re_fx; // q = 29 - rot_vctr_im_fx = h_cldfb->rot_vec_ana_im_fx; // q = 29 + rot_vctr_re_fx = h_cldfb->rot_vec_ana_re_fx; // q = 29 + rot_vctr_im_fx = h_cldfb->rot_vec_ana_im_fx; // q = 29 rot_vctr_delay_re_fx = h_cldfb->rot_vec_ana_delay_re_fx; // q = 31 rot_vctr_delay_im_fx = h_cldfb->rot_vec_ana_delay_im_fx; // q = 31 @@ -1012,98 +1020,98 @@ void cldfbAnalysis_ts_fx_fixed_q( for ( k = 0; k < M4; k++ ) { /* prototype filter */ - r1_fx = L_sub(0, Mpy_32_16_1(timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 0 * L2 )])); // q - r1_fx = L_sub(r1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )])); // q - r1_fx = L_sub(r1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )])); // q - r1_fx = L_sub(r1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )])); // q - r1_fx = L_sub(r1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )])); // q - - r2_fx = L_sub(0, Mpy_32_16_1(timeBuffer_fx[L2 - M2 + ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 0 * L2 )])); // q - r2_fx = L_sub(r2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 + ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 1 * L2 )])); // q - r2_fx = L_sub(r2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 + ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 2 * L2 )])); // q - r2_fx = L_sub(r2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 + ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 3 * L2 )])); // q - r2_fx = L_sub(r2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 + ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 4 * L2 )])); // q - - i1_fx = L_sub(0, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 0 * L2 )])); // q - i1_fx = L_sub(i1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 1 * L2 )])); // q - i1_fx = L_sub(i1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 2 * L2 )])); // q - i1_fx = L_sub(i1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 3 * L2 )])); // q - i1_fx = L_sub(i1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 4 * L2 )])); // q - - i2_fx = L_sub(0, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 - 1 - ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 0 * L2 )])); // q - i2_fx = L_sub(i2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 - 1 - ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 1 * L2 )])); // q - i2_fx = L_sub(i2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 - 1 - ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 2 * L2 )])); // q - i2_fx = L_sub(i2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 - 1 - ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 3 * L2 )])); // q - i2_fx = L_sub(i2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 - 1 - ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 4 * L2 )])); // q - - r1_fx = Mpy_32_16_1(r1_fx, ptr_pf_sf); // q - 1 - r2_fx = Mpy_32_16_1(r2_fx, ptr_pf_sf); // q - 1 - i1_fx = Mpy_32_16_1(i1_fx, ptr_pf_sf); // q - 1 - i2_fx = Mpy_32_16_1(i2_fx, ptr_pf_sf); // q - 1 + r1_fx = L_sub( 0, Mpy_32_16_1( timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 0 * L2 )] ) ); // q + r1_fx = L_sub( r1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )] ) ); // q + r1_fx = L_sub( r1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )] ) ); // q + r1_fx = L_sub( r1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )] ) ); // q + r1_fx = L_sub( r1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )] ) ); // q + + r2_fx = L_sub( 0, Mpy_32_16_1( timeBuffer_fx[L2 - M2 + ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 0 * L2 )] ) ); // q + r2_fx = L_sub( r2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 + ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 1 * L2 )] ) ); // q + r2_fx = L_sub( r2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 + ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 2 * L2 )] ) ); // q + r2_fx = L_sub( r2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 + ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 3 * L2 )] ) ); // q + r2_fx = L_sub( r2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 + ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 4 * L2 )] ) ); // q + + i1_fx = L_sub( 0, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 0 * L2 )] ) ); // q + i1_fx = L_sub( i1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 1 * L2 )] ) ); // q + i1_fx = L_sub( i1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 2 * L2 )] ) ); // q + i1_fx = L_sub( i1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 3 * L2 )] ) ); // q + i1_fx = L_sub( i1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 4 * L2 )] ) ); // q + + i2_fx = L_sub( 0, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 - 1 - ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 0 * L2 )] ) ); // q + i2_fx = L_sub( i2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 - 1 - ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 1 * L2 )] ) ); // q + i2_fx = L_sub( i2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 - 1 - ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 2 * L2 )] ) ); // q + i2_fx = L_sub( i2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 - 1 - ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 3 * L2 )] ) ); // q + i2_fx = L_sub( i2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 - 1 - ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 4 * L2 )] ) ); // q + + r1_fx = Mpy_32_16_1( r1_fx, ptr_pf_sf ); // q - 1 + r2_fx = Mpy_32_16_1( r2_fx, ptr_pf_sf ); // q - 1 + i1_fx = Mpy_32_16_1( i1_fx, ptr_pf_sf ); // q - 1 + i2_fx = Mpy_32_16_1( i2_fx, ptr_pf_sf ); // q - 1 /* folding + pre modulation of DST IV */ - rr12_fx = L_sub( r1_fx, r2_fx ); // q -1 + rr12_fx = L_sub( r1_fx, r2_fx ); // q -1 ri12_fx = L_negate( L_add( i1_fx, i2_fx ) ); // q - 1 /*cplxMult(&rBuffer[2*k],&rBuffer[2*k+1],rr12,ri12,rot_vctr_re[k],rot_vctr_im[k]);*/ - rBuffer_fx[2 * k] = L_sub(Mpy_32_32(rr12_fx, rot_vctr_re_fx[k]), Mpy_32_32(ri12_fx, rot_vctr_im_fx[k])); // q - 3 - rBuffer_fx[2 * k + 1] = L_add(Mpy_32_32(rr12_fx, rot_vctr_im_fx[k]), Mpy_32_32(ri12_fx, rot_vctr_re_fx[k])); // q - 3 + rBuffer_fx[2 * k] = L_sub( Mpy_32_32( rr12_fx, rot_vctr_re_fx[k] ), Mpy_32_32( ri12_fx, rot_vctr_im_fx[k] ) ); // q - 3 + rBuffer_fx[2 * k + 1] = L_add( Mpy_32_32( rr12_fx, rot_vctr_im_fx[k] ), Mpy_32_32( ri12_fx, rot_vctr_re_fx[k] ) ); // q - 3 ///* folding + pre modulation of DCT IV */ - ir12_fx = L_add(r1_fx, r2_fx); // q - 1 - ii12_fx = L_sub(i1_fx, i2_fx); // q - 1 + ir12_fx = L_add( r1_fx, r2_fx ); // q - 1 + ii12_fx = L_sub( i1_fx, i2_fx ); // q - 1 /*cplxMult(&iBuffer[2*k],&iBuffer[2*k+1],ir12,ii12,rot_vctr_re[k],rot_vctr_im[k]);*/ - iBuffer_fx[2 * k] = L_sub(Mpy_32_32(ir12_fx, rot_vctr_re_fx[k]), Mpy_32_32(ii12_fx, rot_vctr_im_fx[k])); // q - 3 - iBuffer_fx[2 * k + 1] = L_add(Mpy_32_32(ir12_fx, rot_vctr_im_fx[k]), Mpy_32_32(ii12_fx, rot_vctr_re_fx[k])); // q - 3 + iBuffer_fx[2 * k] = L_sub( Mpy_32_32( ir12_fx, rot_vctr_re_fx[k] ), Mpy_32_32( ii12_fx, rot_vctr_im_fx[k] ) ); // q - 3 + iBuffer_fx[2 * k + 1] = L_add( Mpy_32_32( ir12_fx, rot_vctr_im_fx[k] ), Mpy_32_32( ii12_fx, rot_vctr_re_fx[k] ) ); // q - 3 } for ( k = M4; k < M2; k++ ) { /* prototype filter */ - r1_fx = L_sub(0, Mpy_32_16_1(timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 0 * L2 )])); // q - r1_fx = L_sub(r1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )])); // q - r1_fx = L_sub(r1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )])); // q - r1_fx = L_sub(r1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )])); // q - r1_fx = L_sub(r1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )])); // q - - r2_fx = L_sub(0, Mpy_32_16_1(timeBuffer_fx[L2 - 5 * M2 + ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 0 * L2 )])); // q - r2_fx = L_sub(r2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 5 * M2 + ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 1 * L2 )])); // q - r2_fx = L_sub(r2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 5 * M2 + ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 2 * L2 )])); // q - r2_fx = L_sub(r2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 5 * M2 + ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 3 * L2 )])); // q - r2_fx = L_sub(r2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 5 * M2 + ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 4 * L2 )])); // q - - i1_fx = L_sub(0, Mpy_32_16_1(timeBuffer_fx[L2 + M2 - 1 - ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 0 * L2 )])); // q - i1_fx = L_sub(i1_fx, Mpy_32_16_1(timeBuffer_fx[L2 + M2 - 1 - ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 1 * L2 )])); // q - i1_fx = L_sub(i1_fx, Mpy_32_16_1(timeBuffer_fx[L2 + M2 - 1 - ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 2 * L2 )])); // q - i1_fx = L_sub(i1_fx, Mpy_32_16_1(timeBuffer_fx[L2 + M2 - 1 - ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 3 * L2 )])); // q - i1_fx = L_sub(i1_fx, Mpy_32_16_1(timeBuffer_fx[L2 + M2 - 1 - ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 4 * L2 )])); // q - - i2_fx = L_sub(0, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 0 * L2 )])); // q - i2_fx = L_sub(i2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 1 * L2 )])); // q - i2_fx = L_sub(i2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 2 * L2 )])); // q - i2_fx = L_sub(i2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 3 * L2 )])); // q - i2_fx = L_sub(i2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 4 * L2 )])); // q - - r1_fx = Mpy_32_16_1(r1_fx, ptr_pf_sf); // q - 1 - r2_fx = Mpy_32_16_1(r2_fx, ptr_pf_sf); // q - 1 - i1_fx = Mpy_32_16_1(i1_fx, ptr_pf_sf); // q - 1 - i2_fx = Mpy_32_16_1(i2_fx, ptr_pf_sf); // q - 1 + r1_fx = L_sub( 0, Mpy_32_16_1( timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 0 * L2 )] ) ); // q + r1_fx = L_sub( r1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )] ) ); // q + r1_fx = L_sub( r1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )] ) ); // q + r1_fx = L_sub( r1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )] ) ); // q + r1_fx = L_sub( r1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )] ) ); // q + + r2_fx = L_sub( 0, Mpy_32_16_1( timeBuffer_fx[L2 - 5 * M2 + ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 0 * L2 )] ) ); // q + r2_fx = L_sub( r2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 5 * M2 + ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 1 * L2 )] ) ); // q + r2_fx = L_sub( r2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 5 * M2 + ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 2 * L2 )] ) ); // q + r2_fx = L_sub( r2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 5 * M2 + ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 3 * L2 )] ) ); // q + r2_fx = L_sub( r2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 5 * M2 + ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 4 * L2 )] ) ); // q + + i1_fx = L_sub( 0, Mpy_32_16_1( timeBuffer_fx[L2 + M2 - 1 - ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 0 * L2 )] ) ); // q + i1_fx = L_sub( i1_fx, Mpy_32_16_1( timeBuffer_fx[L2 + M2 - 1 - ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 1 * L2 )] ) ); // q + i1_fx = L_sub( i1_fx, Mpy_32_16_1( timeBuffer_fx[L2 + M2 - 1 - ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 2 * L2 )] ) ); // q + i1_fx = L_sub( i1_fx, Mpy_32_16_1( timeBuffer_fx[L2 + M2 - 1 - ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 3 * L2 )] ) ); // q + i1_fx = L_sub( i1_fx, Mpy_32_16_1( timeBuffer_fx[L2 + M2 - 1 - ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 4 * L2 )] ) ); // q + + i2_fx = L_sub( 0, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 0 * L2 )] ) ); // q + i2_fx = L_sub( i2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 1 * L2 )] ) ); // q + i2_fx = L_sub( i2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 2 * L2 )] ) ); // q + i2_fx = L_sub( i2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 3 * L2 )] ) ); // q + i2_fx = L_sub( i2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 4 * L2 )] ) ); // q + + r1_fx = Mpy_32_16_1( r1_fx, ptr_pf_sf ); // q - 1 + r2_fx = Mpy_32_16_1( r2_fx, ptr_pf_sf ); // q - 1 + i1_fx = Mpy_32_16_1( i1_fx, ptr_pf_sf ); // q - 1 + i2_fx = Mpy_32_16_1( i2_fx, ptr_pf_sf ); // q - 1 /* folding + pre modulation of DST IV */ - rr12_fx = L_add(r1_fx, r2_fx); // q - 1 - ri12_fx = L_sub(i1_fx, i2_fx); // q - 1 + rr12_fx = L_add( r1_fx, r2_fx ); // q - 1 + ri12_fx = L_sub( i1_fx, i2_fx ); // q - 1 /*cplxMult(&rBuffer[2*k],&rBuffer[2*k+1],rr12,ri12,rot_vctr_re[k],rot_vctr_im[k]);*/ - rBuffer_fx[2 * k] = L_sub(Mpy_32_32(rr12_fx, rot_vctr_re_fx[k]), Mpy_32_32(ri12_fx, rot_vctr_im_fx[k])); // q - 3 - rBuffer_fx[2 * k + 1] = L_add(Mpy_32_32(rr12_fx, rot_vctr_im_fx[k]), Mpy_32_32(ri12_fx, rot_vctr_re_fx[k])); // q - 3 + rBuffer_fx[2 * k] = L_sub( Mpy_32_32( rr12_fx, rot_vctr_re_fx[k] ), Mpy_32_32( ri12_fx, rot_vctr_im_fx[k] ) ); // q - 3 + rBuffer_fx[2 * k + 1] = L_add( Mpy_32_32( rr12_fx, rot_vctr_im_fx[k] ), Mpy_32_32( ri12_fx, rot_vctr_re_fx[k] ) ); // q - 3 /* folding + pre modulation of DCT IV */ - ir12_fx = L_sub(r1_fx, r2_fx); // q - 1 - ii12_fx = L_add(i1_fx, i2_fx); // q - 1 + ir12_fx = L_sub( r1_fx, r2_fx ); // q - 1 + ii12_fx = L_add( i1_fx, i2_fx ); // q - 1 /*cplxMult(&iBuffer[2*k],&iBuffer[2*k+1],ir12,ii12,rot_vctr_re[k],rot_vctr_im[k]);*/ - iBuffer_fx[2 * k] = L_sub(Mpy_32_32(ir12_fx, rot_vctr_re_fx[k]), Mpy_32_32(ii12_fx, rot_vctr_im_fx[k])); // q - 3 - iBuffer_fx[2 * k + 1] = L_add(Mpy_32_32(ir12_fx, rot_vctr_im_fx[k]), Mpy_32_32(ii12_fx, rot_vctr_re_fx[k])); // q - 3 + iBuffer_fx[2 * k] = L_sub( Mpy_32_32( ir12_fx, rot_vctr_re_fx[k] ), Mpy_32_32( ii12_fx, rot_vctr_im_fx[k] ) ); // q - 3 + iBuffer_fx[2 * k + 1] = L_add( Mpy_32_32( ir12_fx, rot_vctr_im_fx[k] ), Mpy_32_32( ii12_fx, rot_vctr_re_fx[k] ) ); // q - 3 } - *q_cldfb = sub(*q_cldfb, 3); + *q_cldfb = sub( *q_cldfb, 3 ); /* FFT of DST IV */ fft_cldfb_fx( rBuffer_fx, M2 ); @@ -1112,10 +1120,10 @@ void cldfbAnalysis_ts_fx_fixed_q( for ( k = 0; k < M2; k++ ) { /*cplxMult(&realBuffer[M1-1-(2*k)],&realBuffer[2*k],rBuffer[2*k],rBuffer[2*k+1],rot_vctr_re[k],rot_vctr_im[k]);*/ - realBuffer_fx[M1 - 1 - ( 2 * k )] = L_sub(Mpy_32_32(rBuffer_fx[2 * k], rot_vctr_re_fx[k]), Mpy_32_32(rBuffer_fx[2 * k + 1], rot_vctr_im_fx[k])); // q - 5 - realBuffer_fx[2 * k] = L_add(Mpy_32_32(rBuffer_fx[2 * k], rot_vctr_im_fx[k]), Mpy_32_32(rBuffer_fx[2 * k + 1], rot_vctr_re_fx[k])); // q - 5 + realBuffer_fx[M1 - 1 - ( 2 * k )] = L_sub( Mpy_32_32( rBuffer_fx[2 * k], rot_vctr_re_fx[k] ), Mpy_32_32( rBuffer_fx[2 * k + 1], rot_vctr_im_fx[k] ) ); // q - 5 + realBuffer_fx[2 * k] = L_add( Mpy_32_32( rBuffer_fx[2 * k], rot_vctr_im_fx[k] ), Mpy_32_32( rBuffer_fx[2 * k + 1], rot_vctr_re_fx[k] ) ); // q - 5 } - *q_cldfb = sub(*q_cldfb, 2); + *q_cldfb = sub( *q_cldfb, 2 ); /* FFT of DCT IV */ fft_cldfb_fx( iBuffer_fx, M2 ); @@ -1125,8 +1133,8 @@ void cldfbAnalysis_ts_fx_fixed_q( { /* do it inplace */ /*cplxMult(&imagBuffer[2*k],&imagBuffer[M1-1-(2*k)],iBuffer[2*k],iBuffer[2*k+1],rot_vctr_re[k],rot_vctr_im[k]);*/ - imagBuffer_fx[2 * k] = L_sub(Mpy_32_32(iBuffer_fx[2 * k], rot_vctr_re_fx[k]), Mpy_32_32(iBuffer_fx[2 * k + 1], rot_vctr_im_fx[k])); // q - 5 - imagBuffer_fx[M1 - 1 - ( 2 * k )] = L_add(Mpy_32_32(iBuffer_fx[2 * k], rot_vctr_im_fx[k]), Mpy_32_32(iBuffer_fx[2 * k + 1], rot_vctr_re_fx[k])); // q - 5 + imagBuffer_fx[2 * k] = L_sub( Mpy_32_32( iBuffer_fx[2 * k], rot_vctr_re_fx[k] ), Mpy_32_32( iBuffer_fx[2 * k + 1], rot_vctr_im_fx[k] ) ); // q - 5 + imagBuffer_fx[M1 - 1 - ( 2 * k )] = L_add( Mpy_32_32( iBuffer_fx[2 * k], rot_vctr_im_fx[k] ), Mpy_32_32( iBuffer_fx[2 * k + 1], rot_vctr_re_fx[k] ) ); // q - 5 } if ( h_cldfb->prototype == CLDFB_PROTOTYPE_5_00MS ) @@ -1145,8 +1153,8 @@ void cldfbAnalysis_ts_fx_fixed_q( /*cplxMult(&realBuffer[k], &imagBuffer[k], realBuffer[k], imagBuffer[k], rot_vctr_delay_re[k], rot_vctr_delay_im[k]);*/ /*realBuffer[k] = rBuffer[k]; imagBuffer[k] = iBuffer[k];*/ - cplx_aux_fx = L_sub(Mpy_32_32(realBuffer_fx[k], rot_vctr_delay_re_fx[k]), Mpy_32_32(imagBuffer_fx[k], rot_vctr_delay_im_fx[k])); // q - 5 - imagBuffer_fx[k] = L_add(Mpy_32_32(realBuffer_fx[k], rot_vctr_delay_im_fx[k]), Mpy_32_32(imagBuffer_fx[k], rot_vctr_delay_re_fx[k])); // q - 5 + cplx_aux_fx = L_sub( Mpy_32_32( realBuffer_fx[k], rot_vctr_delay_re_fx[k] ), Mpy_32_32( imagBuffer_fx[k], rot_vctr_delay_im_fx[k] ) ); // q - 5 + imagBuffer_fx[k] = L_add( Mpy_32_32( realBuffer_fx[k], rot_vctr_delay_im_fx[k] ), Mpy_32_32( imagBuffer_fx[k], rot_vctr_delay_re_fx[k] ) ); // q - 5 realBuffer_fx[k] = cplx_aux_fx; } } @@ -1591,7 +1599,7 @@ void configureCldfb_ivas( #ifdef IVAS_FLOAT_FIXED void configureCldfb_ivas_fx( HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i/o: filter bank handle */ - const Word32 sampling_rate /* i : sampling rate */ + const Word32 sampling_rate /* i : sampling rate */ ) { @@ -1601,7 +1609,7 @@ void configureCldfb_ivas_fx( // h_cldfb->no_channels = (int16_t) ( sampling_rate * INV_CLDFB_BANDWIDTH + 0.5f ); Word32 n_sampling_rate = sampling_rate * 2; - Word32 val = L_add( Mpy_32_16_1( n_sampling_rate, 41 /* INV_CLDFB_BANDWIDTH in Q15 */), 1 ); + Word32 val = L_add( Mpy_32_16_1( n_sampling_rate, 41 /* INV_CLDFB_BANDWIDTH in Q15 */ ), 1 ); val = L_shr( val, 1 ); h_cldfb->no_channels = extract_l( val ); @@ -1659,9 +1667,9 @@ ivas_error openCldfb_ivas( { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB" ); } - hs->cldfb_state_length = buf_len;//Temporarily added to store the length of buffer - hs->cldfb_size = buf_len; /*for having original size at intermediatery conversion, will be removed on removing conversion*/ - set32_fx(hs->cldfb_state_fx, 0, buf_len); + hs->cldfb_state_length = buf_len; // Temporarily added to store the length of buffer + hs->cldfb_size = buf_len; /*for having original size at intermediatery conversion, will be removed on removing conversion*/ + set32_fx( hs->cldfb_state_fx, 0, buf_len ); hs->Q_cldfb_state = Q11; #endif // IVAS_FLOAT_FIXED @@ -1672,60 +1680,60 @@ ivas_error openCldfb_ivas( } #else ivas_error openCldfb_ivas( - HANDLE_CLDFB_FILTER_BANK *h_cldfb, /* i/o: filter bank handle */ - CLDFB_TYPE type, /* i : analysis or synthesis */ - const int32_t sampling_rate, /* i : sampling rate */ - CLDFB_PROTOTYPE prototype /* i : CLDFB version (1.25ms/5ms delay) */ + HANDLE_CLDFB_FILTER_BANK *h_cldfb, /* i/o: filter bank handle */ + CLDFB_TYPE type, /* i : analysis or synthesis */ + const int32_t sampling_rate, /* i : sampling rate */ + CLDFB_PROTOTYPE prototype /* i : CLDFB version (1.25ms/5ms delay) */ ) { - HANDLE_CLDFB_FILTER_BANK hs; - int16_t buf_len; + HANDLE_CLDFB_FILTER_BANK hs; + int16_t buf_len; - if ((hs = (HANDLE_CLDFB_FILTER_BANK)malloc(sizeof(CLDFB_FILTER_BANK))) == NULL) - { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB"); - } + if ( ( hs = (HANDLE_CLDFB_FILTER_BANK) malloc( sizeof( CLDFB_FILTER_BANK ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB" ); + } - hs->type = type; - hs->prototype = prototype; + hs->type = type; + hs->prototype = prototype; - configureCldfb_ivas(hs, sampling_rate); - hs->memory_flt = NULL; - hs->memory_length = 0; + configureCldfb_ivas( hs, sampling_rate ); + hs->memory_flt = NULL; + hs->memory_length = 0; - if (type == CLDFB_ANALYSIS) - { - buf_len = hs->p_filter_length - hs->no_channels; - } - else - { - buf_len = hs->p_filter_length; - } + if ( type == CLDFB_ANALYSIS ) + { + buf_len = hs->p_filter_length - hs->no_channels; + } + else + { + buf_len = hs->p_filter_length; + } - if ((hs->cldfb_state = (float *)malloc(buf_len * sizeof(float))) == NULL) - { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB"); - } + if ( ( hs->cldfb_state = (float *) malloc( buf_len * sizeof( float ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB" ); + } - set_f(hs->cldfb_state, 0.0f, buf_len); + set_f( hs->cldfb_state, 0.0f, buf_len ); - *h_cldfb = hs; + *h_cldfb = hs; - return IVAS_ERR_OK; + return IVAS_ERR_OK; } #endif #ifdef IVAS_FLOAT_FIXED ivas_error openCldfb_ivas_fx( HANDLE_CLDFB_FILTER_BANK *h_cldfb, /* i/o: filter bank handle */ CLDFB_TYPE type, /* i : analysis or synthesis */ - const Word32 sampling_rate, /* i : sampling rate */ + const Word32 sampling_rate, /* i : sampling rate */ CLDFB_PROTOTYPE prototype /* i : CLDFB version (1.25ms/5ms delay) */ ) { HANDLE_CLDFB_FILTER_BANK hs; Word16 buf_len; - IF ( ( hs = (HANDLE_CLDFB_FILTER_BANK) malloc( sizeof( CLDFB_FILTER_BANK ) ) ) == NULL ) + IF( ( hs = (HANDLE_CLDFB_FILTER_BANK) malloc( sizeof( CLDFB_FILTER_BANK ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB" ); } @@ -1735,13 +1743,13 @@ ivas_error openCldfb_ivas_fx( hs->prototype = prototype; move16(); - //configureCldfb_ivas( hs, sampling_rate ); + // configureCldfb_ivas( hs, sampling_rate ); configureCldfb_ivas_fx( hs, sampling_rate ); hs->memory_flt = NULL; hs->memory_length = 0; move16(); - IF ( EQ_32( type, CLDFB_ANALYSIS ) ) + IF( EQ_32( type, CLDFB_ANALYSIS ) ) { buf_len = sub( hs->p_filter_length, hs->no_channels ); } @@ -1751,18 +1759,18 @@ ivas_error openCldfb_ivas_fx( move16(); } - IF ( ( hs->cldfb_state_fx = (Word32 *) malloc( buf_len * sizeof( Word32 ) ) ) == NULL ) + IF( ( hs->cldfb_state_fx = (Word32 *) malloc( buf_len * sizeof( Word32 ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB" ); } hs->cldfb_state_length = buf_len; // Temporarily added to store the length of buffer - hs->cldfb_size = buf_len; /*for having original size at intermediatery conversion, will be removed on removing conversion*/ - set32_fx(hs->cldfb_state_fx, 0, buf_len); + hs->cldfb_size = buf_len; /*for having original size at intermediatery conversion, will be removed on removing conversion*/ + set32_fx( hs->cldfb_state_fx, 0, buf_len ); hs->Q_cldfb_state = Q11; /* TODO: remove the floating point dependency */ - IF ( ( hs->cldfb_state = (float *) malloc( buf_len * sizeof( float ) ) ) == NULL ) + IF( ( hs->cldfb_state = (float *) malloc( buf_len * sizeof( float ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB" ); } @@ -1804,18 +1812,17 @@ void resampleCldfb_ivas( #ifdef IVAS_FLOAT_FIXED void resampleCldfb_ivas_fx( HANDLE_CLDFB_FILTER_BANK hs, /* i/o: filter bank handle */ - const Word32 newSamplerate -) + const Word32 newSamplerate ) { Word16 timeOffset; /* keep old parameters before switching*/ - Word16 timeOffsetold = sub(hs->p_filter_length, hs->no_channels); + Word16 timeOffsetold = sub( hs->p_filter_length, hs->no_channels ); /* new settings */ configureCldfb_ivas_fx( hs, newSamplerate ); - timeOffset = sub(hs->p_filter_length, hs->no_channels); + timeOffset = sub( hs->p_filter_length, hs->no_channels ); /*low complexity-resampling only stored previous samples that are needed for next frame modulation */ L_lerp_fx_q11( hs->cldfb_state_fx, hs->cldfb_state_fx, timeOffset, timeOffsetold ); @@ -1894,7 +1901,7 @@ static float GetEnergyCldfb_ivas( tempEnergyValuesArry[j] = &energyValues[j][0]; } - calcHiEnvLoBuff( numberCols, freqTable, 1, tempEnergyValuesArry, hTecEnc->loBuffer_flt, hTecEnc->hiTempEnv_flt); + calcHiEnvLoBuff( numberCols, freqTable, 1, tempEnergyValuesArry, hTecEnc->loBuffer_flt, hTecEnc->hiTempEnv_flt ); } for ( j = 0; j < numberBands; j++ ) @@ -1942,12 +1949,12 @@ void deleteCldfb_ivas( { HANDLE_CLDFB_FILTER_BANK hs = *h_cldfb; - IF ( h_cldfb == NULL || *h_cldfb == NULL ) + IF( h_cldfb == NULL || *h_cldfb == NULL ) { return; } - IF ( hs->cldfb_state ) + IF( hs->cldfb_state ) { free( hs->cldfb_state ); } @@ -1971,17 +1978,17 @@ void deleteCldfb_ivas_fx( { HANDLE_CLDFB_FILTER_BANK hs = *h_cldfb; - IF ( h_cldfb == NULL || *h_cldfb == NULL ) + IF( h_cldfb == NULL || *h_cldfb == NULL ) { return; } - IF ( hs->cldfb_state_fx ) + IF( hs->cldfb_state_fx ) { free( hs->cldfb_state_fx ); } #ifdef IVAS_FLOAT_FIXED // TODO : Will be removed later - IF ( hs->cldfb_state ) + IF( hs->cldfb_state ) { free( hs->cldfb_state ); } @@ -2036,8 +2043,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = NULL; hs->p_filter_sf = (Word16) 17036; hs->p_filter = CLDFB80_10_fx; - hs->q_scale = norm_s((Word16)CLDFB80_10_SCALE); - hs->scale = (Word16)(CLDFB80_10_SCALE*(1<q_scale)); + hs->q_scale = norm_s( (Word16) CLDFB80_10_SCALE ); + hs->scale = (Word16) ( CLDFB80_10_SCALE * ( 1 << hs->q_scale ) ); #endif } else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) @@ -2057,8 +2064,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; hs->p_filter_sf = (Word16) 15388; hs->p_filter = LDQMF_10_fx; - hs->q_scale = norm_s((Word16)LDQMF_10_SCALE); - hs->scale = (Word16)(LDQMF_10_SCALE*(1 << hs->q_scale)); + hs->q_scale = norm_s( (Word16) LDQMF_10_SCALE ); + hs->scale = (Word16) ( LDQMF_10_SCALE * ( 1 << hs->q_scale ) ); #endif } break; @@ -2091,8 +2098,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = NULL; hs->p_filter_sf = (Word16) 17051; hs->p_filter = CLDFB80_16_fx; - hs->q_scale = norm_s((Word16)CLDFB80_16_SCALE); - hs->scale = (Word16)(CLDFB80_16_SCALE*(1 << hs->q_scale)); + hs->q_scale = norm_s( (Word16) CLDFB80_16_SCALE ); + hs->scale = (Word16) ( CLDFB80_16_SCALE * ( 1 << hs->q_scale ) ); #endif } else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) @@ -2112,8 +2119,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; hs->p_filter_sf = (Word16) 15388; hs->p_filter = LDQMF_16_fx; - hs->q_scale = norm_s((Word16)LDQMF_16_SCALE); - hs->scale = (Word16)(LDQMF_16_SCALE*(1 << hs->q_scale)); + hs->q_scale = norm_s( (Word16) LDQMF_16_SCALE ); + hs->scale = (Word16) ( LDQMF_16_SCALE * ( 1 << hs->q_scale ) ); #endif } break; @@ -2146,8 +2153,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = NULL; hs->p_filter_sf = (Word16) 17050; hs->p_filter = CLDFB80_20_fx; - hs->q_scale = norm_s((Word16)CLDFB80_20_SCALE); - hs->scale = (Word16)(CLDFB80_20_SCALE*(1 << hs->q_scale)); + hs->q_scale = norm_s( (Word16) CLDFB80_20_SCALE ); + hs->scale = (Word16) ( CLDFB80_20_SCALE * ( 1 << hs->q_scale ) ); #endif } else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) @@ -2167,8 +2174,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; hs->p_filter_sf = (Word16) 15390; hs->p_filter = LDQMF_20_fx; - hs->q_scale = norm_s((Word16)LDQMF_20_SCALE); - hs->scale = (Word16)(LDQMF_20_SCALE*(1 << hs->q_scale)); + hs->q_scale = norm_s( (Word16) LDQMF_20_SCALE ); + hs->scale = (Word16) ( LDQMF_20_SCALE * ( 1 << hs->q_scale ) ); #endif } break; @@ -2201,8 +2208,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = NULL; hs->p_filter_sf = (Word16) 17051; hs->p_filter = CLDFB80_30_fx; - hs->q_scale = norm_s((Word16)CLDFB80_30_SCALE); - hs->scale = (Word16)(CLDFB80_30_SCALE*(1 << hs->q_scale)); + hs->q_scale = norm_s( (Word16) CLDFB80_30_SCALE ); + hs->scale = (Word16) ( CLDFB80_30_SCALE * ( 1 << hs->q_scale ) ); #endif } else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) @@ -2222,8 +2229,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; hs->p_filter_sf = (Word16) 15388; hs->p_filter = LDQMF_30_fx; - hs->q_scale = norm_s((Word16)LDQMF_30_SCALE); - hs->scale = (Word16)(LDQMF_30_SCALE*(1 << hs->q_scale)); + hs->q_scale = norm_s( (Word16) LDQMF_30_SCALE ); + hs->scale = (Word16) ( LDQMF_30_SCALE * ( 1 << hs->q_scale ) ); #endif } break; @@ -2256,8 +2263,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = NULL; hs->p_filter_sf = (Word16) 17050; hs->p_filter = CLDFB80_32_fx; - hs->q_scale = norm_s((Word16)CLDFB80_32_SCALE); - hs->scale = (Word16)(CLDFB80_32_SCALE*(1 << hs->q_scale)); + hs->q_scale = norm_s( (Word16) CLDFB80_32_SCALE ); + hs->scale = (Word16) ( CLDFB80_32_SCALE * ( 1 << hs->q_scale ) ); #endif } else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) @@ -2277,8 +2284,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; hs->p_filter_sf = (Word16) 15392; hs->p_filter = LDQMF_32_fx; - hs->q_scale = norm_s((Word16)LDQMF_32_SCALE); - hs->scale = (Word16)(LDQMF_32_SCALE*(1 << hs->q_scale)); + hs->q_scale = norm_s( (Word16) LDQMF_32_SCALE ); + hs->scale = (Word16) ( LDQMF_32_SCALE * ( 1 << hs->q_scale ) ); #endif } break; @@ -2311,8 +2318,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = NULL; hs->p_filter_sf = (Word16) 17051; hs->p_filter = CLDFB80_40_fx; - hs->q_scale = norm_s((Word16)CLDFB80_40_SCALE); - hs->scale = (Word16)(CLDFB80_40_SCALE*(1 << hs->q_scale)); + hs->q_scale = norm_s( (Word16) CLDFB80_40_SCALE ); + hs->scale = (Word16) ( CLDFB80_40_SCALE * ( 1 << hs->q_scale ) ); #endif } else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) @@ -2332,8 +2339,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; hs->p_filter_sf = (Word16) 15391; hs->p_filter = LDQMF_40_fx; - hs->q_scale = norm_s((Word16)LDQMF_40_SCALE); - hs->scale = (Word16)(LDQMF_40_SCALE*(1 << hs->q_scale)); + hs->q_scale = norm_s( (Word16) LDQMF_40_SCALE ); + hs->scale = (Word16) ( LDQMF_40_SCALE * ( 1 << hs->q_scale ) ); #endif } break; @@ -2366,8 +2373,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_im_fx = NULL; hs->p_filter_sf = (Word16) 17051; hs->p_filter = CLDFB80_60_fx; - hs->q_scale = norm_s((Word16)CLDFB80_60_SCALE); - hs->scale = (Word16)(CLDFB80_60_SCALE*(1 << hs->q_scale)); + hs->q_scale = norm_s( (Word16) CLDFB80_60_SCALE ); + hs->scale = (Word16) ( CLDFB80_60_SCALE * ( 1 << hs->q_scale ) ); #endif } else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) @@ -2387,8 +2394,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; hs->p_filter_sf = (Word16) 15391; hs->p_filter = LDQMF_60_fx; - hs->q_scale = norm_s((Word16)LDQMF_60_SCALE); - hs->scale = (Word16)(LDQMF_60_SCALE*(1 << hs->q_scale)); + hs->q_scale = norm_s( (Word16) LDQMF_60_SCALE ); + hs->scale = (Word16) ( LDQMF_60_SCALE * ( 1 << hs->q_scale ) ); #endif } break; @@ -2408,15 +2415,15 @@ ivas_error cldfb_save_memory_ivas_fx( HANDLE_CLDFB_FILTER_BANK hs /* i/o: filter bank handle */ ) { - UWord16 offset = sub(hs->p_filter_length , hs->no_channels); + UWord16 offset = sub( hs->p_filter_length, hs->no_channels ); - IF ( hs->memory_flt != NULL || NE_16(hs->memory_length , 0) ) + IF( hs->memory_flt != NULL || NE_16( hs->memory_length, 0 ) ) { /* memory already stored; Free memory first */ return IVAS_ERR_OK; } - IF ( EQ_16(hs->type , CLDFB_ANALYSIS) ) + IF( EQ_16( hs->type, CLDFB_ANALYSIS ) ) { hs->memory_length = offset; move16(); @@ -2426,13 +2433,13 @@ ivas_error cldfb_save_memory_ivas_fx( hs->memory_length = hs->p_filter_length; move16(); } -#if 1/*Floating point memory allocation: To be removed later*/ - IF ( ( hs->memory_flt = (float *) malloc( hs->memory_length * sizeof( float ) ) ) == NULL ) +#if 1 /*Floating point memory allocation: To be removed later*/ + IF( ( hs->memory_flt = (float *) malloc( hs->memory_length * sizeof( float ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CLDFB\n" ); } #endif - IF ( ( hs->memory32 = (Word32 *) malloc( hs->memory_length * sizeof(Word32) ) ) == NULL ) + IF( ( hs->memory32 = (Word32 *) malloc( hs->memory_length * sizeof( Word32 ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CLDFB\n" ); } @@ -2486,15 +2493,15 @@ void cldfb_restore_memory_ivas_fx( HANDLE_CLDFB_FILTER_BANK hs /* i/o: filter bank handle */ ) { - UWord16 offset = sub(hs->p_filter_length , hs->no_channels); + UWord16 offset = sub( hs->p_filter_length, hs->no_channels ); UWord16 size; - IF ( hs->memory_flt == NULL || EQ_16(hs->memory_length , 0) ) + IF( hs->memory_flt == NULL || EQ_16( hs->memory_length, 0 ) ) { /* memory not allocated */ return; } - IF ( EQ_16(hs->type , CLDFB_ANALYSIS) ) + IF( EQ_16( hs->type, CLDFB_ANALYSIS ) ) { size = offset; move16(); @@ -2509,14 +2516,14 @@ void cldfb_restore_memory_ivas_fx( Copy32( hs->memory32, hs->cldfb_state_fx, hs->memory_length ); /* adjust sample rate if it was changed in the meanwhile */ - IF ( NE_16(hs->memory_length , size) ) + IF( NE_16( hs->memory_length, size ) ) { - L_lerp_fx_q11( hs->cldfb_state_fx, hs->cldfb_state_fx, size, hs->memory_length); + L_lerp_fx_q11( hs->cldfb_state_fx, hs->cldfb_state_fx, size, hs->memory_length ); } hs->cldfb_state_length = size; hs->memory_length = 0; -#if 1 //Remove later - free(hs->memory_flt); +#if 1 // Remove later + free( hs->memory_flt ); hs->memory_flt = NULL; #endif free( hs->memory32 ); @@ -2594,24 +2601,24 @@ void cldfb_reset_memory_ivas( } #ifdef IVAS_FLOAT_FIXED void cldfb_reset_memory_fx( - HANDLE_CLDFB_FILTER_BANK hs /* i/o: filter bank handle */ + HANDLE_CLDFB_FILTER_BANK hs /* i/o: filter bank handle */ ) { - Word16 memory_length; - UWord16 offset = sub(hs->p_filter_length, hs->no_channels); - - IF (hs->type == CLDFB_ANALYSIS) - { - memory_length = offset; - } - ELSE - { - memory_length = hs->p_filter_length; - } - - hs->cldfb_state_length = memory_length; - /* save the memory */ - set32_fx(hs->cldfb_state_fx, 0, memory_length); + Word16 memory_length; + UWord16 offset = sub( hs->p_filter_length, hs->no_channels ); + + IF( hs->type == CLDFB_ANALYSIS ) + { + memory_length = offset; + } + ELSE + { + memory_length = hs->p_filter_length; + } + + hs->cldfb_state_length = memory_length; + /* save the memory */ + set32_fx( hs->cldfb_state_fx, 0, memory_length ); hs->Q_cldfb_state = Q11; return; diff --git a/lib_com/cldfb_evs.c b/lib_com/cldfb_evs.c index ee87b7c14..59c8df221 100644 --- a/lib_com/cldfb_evs.c +++ b/lib_com/cldfb_evs.c @@ -24,175 +24,161 @@ #include "prot_fx2.h" #include -#define STATE_BUFFER_SIZE ( 9+16 ) +#define STATE_BUFFER_SIZE ( 9 + 16 ) -#define CLDFB_NO_POLY ( 5 ) -#define SYN_FILTER_HEADROOM ( 1 ) +#define CLDFB_NO_POLY ( 5 ) +#define SYN_FILTER_HEADROOM ( 1 ) -#define CLDFB_LDCLDFB_PFT_SCALE ( 0 ) -#define CLDFB_CLDFB80_O24_PFT_SCALE ( 1 ) -#define CLDFB_CLDFB80_O5_PFT_SCALE ( 1 ) -#define CLDFB_CLDFB80_PFT_SCALE ( 1 ) +#define CLDFB_LDCLDFB_PFT_SCALE ( 0 ) +#define CLDFB_CLDFB80_O24_PFT_SCALE ( 1 ) +#define CLDFB_CLDFB80_O5_PFT_SCALE ( 1 ) +#define CLDFB_CLDFB80_PFT_SCALE ( 1 ) +#define SYN_FILTER_HEADROOM_1MS ( 2 ) +#define SYN_FILTER_HEADROOM_2MS ( 2 ) +#define SYN_FILTER_HEADROOM_2_5MS ( 2 ) +#define SYN_FILTER_HEADROOM_8MS ( 1 ) -#define SYN_FILTER_HEADROOM_1MS ( 2 ) -#define SYN_FILTER_HEADROOM_2MS ( 2 ) -#define SYN_FILTER_HEADROOM_2_5MS ( 2 ) -#define SYN_FILTER_HEADROOM_8MS ( 1 ) - -#define N8 ( 4 ) -#define N10 ( 5 ) -#define N16 ( 8 ) -#define N20 ( 10 ) -#define N30 ( 15 ) -#define N32 ( 16 ) -#define N40 ( 20 ) -#define N60 ( 30 ) +#define N8 ( 4 ) +#define N10 ( 5 ) +#define N16 ( 8 ) +#define N20 ( 10 ) +#define N30 ( 15 ) +#define N32 ( 16 ) +#define N40 ( 20 ) +#define N60 ( 30 ) static void -cldfb_init_proto_and_twiddles(HANDLE_CLDFB_FILTER_BANK hs); - -#define cplxMpyS(yr,yi,xr,xi,cr,ci,syr,syi,sxr,sxi,CL_x,CL_z,C_c) CL_x = CL_form( *xr, *xi ); \ - C_c = C_form( *cr, *ci ); \ - CL_z = CL_mult_32x16( CL_x, C_c ); \ - *yr = CL_Extract_real( CL_z ); \ - *yi = CL_Extract_imag( CL_z ); \ - yr+=syr, yi+=syi, xr+=sxr, xi+=sxi, cr++, ci++ - -#define cplxMpy(ryr,ryi,iyr,iyi,rxr,rxi,ixr,ixi,cr,ci,g,sx,sr,CL_x,CL_ry,CL_iy,C_c) CL_x = CL_form( *rxr, *rxi ); \ - C_c = C_form( *cr, *ci ); \ - CL_ry = CL_mult_32x16( CL_x, C_c ); \ - CL_x = CL_form( *ixr, *ixi ); \ - CL_iy = CL_mult_32x16( CL_x, C_c ); \ - CL_ry = CL_scale_t( CL_ry, g ); \ - CL_iy = CL_scale_t( CL_iy, g ); \ - ryr = CL_Extract_real( CL_ry ); \ - ryi = CL_Extract_imag( CL_ry ); \ - iyr = CL_Extract_real( CL_iy ); \ - iyi = CL_Extract_imag( CL_iy ); \ - rxr+=sx, rxi+=sx, ixr+=sx, ixi+=sx, cr+=sr, ci+=sr +cldfb_init_proto_and_twiddles( HANDLE_CLDFB_FILTER_BANK hs ); + +#define cplxMpyS( yr, yi, xr, xi, cr, ci, syr, syi, sxr, sxi, CL_x, CL_z, C_c ) \ + CL_x = CL_form( *xr, *xi ); \ + C_c = C_form( *cr, *ci ); \ + CL_z = CL_mult_32x16( CL_x, C_c ); \ + *yr = CL_Extract_real( CL_z ); \ + *yi = CL_Extract_imag( CL_z ); \ + yr += syr, yi += syi, xr += sxr, xi += sxi, cr++, ci++ + +#define cplxMpy( ryr, ryi, iyr, iyi, rxr, rxi, ixr, ixi, cr, ci, g, sx, sr, CL_x, CL_ry, CL_iy, C_c ) \ + CL_x = CL_form( *rxr, *rxi ); \ + C_c = C_form( *cr, *ci ); \ + CL_ry = CL_mult_32x16( CL_x, C_c ); \ + CL_x = CL_form( *ixr, *ixi ); \ + CL_iy = CL_mult_32x16( CL_x, C_c ); \ + CL_ry = CL_scale_t( CL_ry, g ); \ + CL_iy = CL_scale_t( CL_iy, g ); \ + ryr = CL_Extract_real( CL_ry ); \ + ryi = CL_Extract_imag( CL_ry ); \ + iyr = CL_Extract_real( CL_iy ); \ + iyi = CL_Extract_imag( CL_iy ); \ + rxr += sx, rxi += sx, ixr += sx, ixi += sx, cr += sr, ci += sr #ifdef BASOP_NOGLOB -#define add1(y1,y2,y3,y4,rr12,ri12,ir12,ii12,s) *y1 = round_fx_sat(L_shl_sat(L_negate(L_add_sat(rr12,ii12)),s)); \ - *y2 = round_fx_sat(L_shl_sat(L_negate(L_add_sat(ri12,ir12)),s)); \ - *y3 = round_fx_sat(L_shl_sat(L_sub_sat(rr12,ii12),s)); \ - *y4 = round_fx_sat(L_shl_sat(L_sub_sat(ir12,ri12),s)); \ - y1+=2, y2-=2, y3-=2, y4+=2 +#define add1( y1, y2, y3, y4, rr12, ri12, ir12, ii12, s ) \ + *y1 = round_fx_sat( L_shl_sat( L_negate( L_add_sat( rr12, ii12 ) ), s ) ); \ + *y2 = round_fx_sat( L_shl_sat( L_negate( L_add_sat( ri12, ir12 ) ), s ) ); \ + *y3 = round_fx_sat( L_shl_sat( L_sub_sat( rr12, ii12 ), s ) ); \ + *y4 = round_fx_sat( L_shl_sat( L_sub_sat( ir12, ri12 ), s ) ); \ + y1 += 2, y2 -= 2, y3 -= 2, y4 += 2 -#define add2(y1,y2,y3,y4,rr12,ri12,ir12,ii12,s) *y1 = round_fx_sat(L_shl_sat(L_add_sat(ri12,ir12),s)); \ - *y2 = round_fx_sat(L_shl_sat(L_add_sat(rr12,ii12),s)); \ - *y3 = round_fx_sat(L_shl_sat(L_sub_sat(ir12,ri12),s)); \ - *y4 = round_fx_sat(L_shl_sat(L_sub_sat(rr12,ii12),s)); \ - y1+=2, y2-=2, y3-=2, y4+=2 +#define add2( y1, y2, y3, y4, rr12, ri12, ir12, ii12, s ) \ + *y1 = round_fx_sat( L_shl_sat( L_add_sat( ri12, ir12 ), s ) ); \ + *y2 = round_fx_sat( L_shl_sat( L_add_sat( rr12, ii12 ), s ) ); \ + *y3 = round_fx_sat( L_shl_sat( L_sub_sat( ir12, ri12 ), s ) ); \ + *y4 = round_fx_sat( L_shl_sat( L_sub_sat( rr12, ii12 ), s ) ); \ + y1 += 2, y2 -= 2, y3 -= 2, y4 += 2 #else -#define add1(y1,y2,y3,y4,rr12,ri12,ir12,ii12,s) *y1 = round_fx(L_shl(L_negate(L_add(rr12,ii12)),s)); \ - *y2 = round_fx(L_shl(L_negate(L_add(ri12,ir12)),s)); \ - *y3 = round_fx(L_shl(L_sub(rr12,ii12),s)); \ - *y4 = round_fx(L_shl(L_sub(ir12,ri12),s)); \ - y1+=2, y2-=2, y3-=2, y4+=2 - -#define add2(y1,y2,y3,y4,rr12,ri12,ir12,ii12,s) *y1 = round_fx(L_shl(L_add(ri12,ir12),s)); \ - *y2 = round_fx(L_shl(L_add(rr12,ii12),s)); \ - *y3 = round_fx(L_shl(L_sub(ir12,ri12),s)); \ - *y4 = round_fx(L_shl(L_sub(rr12,ii12),s)); \ - y1+=2, y2-=2, y3-=2, y4+=2 +#define add1( y1, y2, y3, y4, rr12, ri12, ir12, ii12, s ) \ + *y1 = round_fx( L_shl( L_negate( L_add( rr12, ii12 ) ), s ) ); \ + *y2 = round_fx( L_shl( L_negate( L_add( ri12, ir12 ) ), s ) ); \ + *y3 = round_fx( L_shl( L_sub( rr12, ii12 ), s ) ); \ + *y4 = round_fx( L_shl( L_sub( ir12, ri12 ), s ) ); \ + y1 += 2, y2 -= 2, y3 -= 2, y4 += 2 + +#define add2( y1, y2, y3, y4, rr12, ri12, ir12, ii12, s ) \ + *y1 = round_fx( L_shl( L_add( ri12, ir12 ), s ) ); \ + *y2 = round_fx( L_shl( L_add( rr12, ii12 ), s ) ); \ + *y3 = round_fx( L_shl( L_sub( ir12, ri12 ), s ) ); \ + *y4 = round_fx( L_shl( L_sub( rr12, ii12 ), s ) ); \ + y1 += 2, y2 -= 2, y3 -= 2, y4 += 2 #endif -#define ptrUpdate16(y11,y12,y13,y14,r11,x11,x12,x13,x14,r12,y21,y22,y23,y24,r21,x21,x22,x23,x24,r22) \ - y11 += 2*N8, y12 -= 2*N8, y13 -= 2*N8, y14 += 2*N8, r11 -= 1*N8; \ - x11 -= 2*N8, x12 -= 2*N8, x13 -= 2*N8, x14 -= 2*N8, r12 -= 1*N8; \ - y21 += 2*N8, y22 -= 2*N8, y23 -= 2*N8, y24 += 2*N8, r21 += 1*N8; \ - x21 += 2*N8, x22 += 2*N8, x23 += 2*N8, x24 += 2*N8, r22 += 1*N8 - -#define ptrUpdate20(y11,y12,y13,y14,r11,x11,x12,x13,x14,r12,y21,y22,y23,y24,r21,x21,x22,x23,x24,r22) \ - y11 += 2*N10, y12 -= 2*N10, y13 -= 2*N10, y14 += 2*N10, r11 -= 1*N10; \ - x11 -= 2*N10, x12 -= 2*N10, x13 -= 2*N10, x14 -= 2*N10, r12 -= 1*N10; \ - y21 += 2*N10, y22 -= 2*N10, y23 -= 2*N10, y24 += 2*N10, r21 += 1*N10; \ - x21 += 2*N10, x22 += 2*N10, x23 += 2*N10, x24 += 2*N10, r22 += 1*N10 +#define ptrUpdate16( y11, y12, y13, y14, r11, x11, x12, x13, x14, r12, y21, y22, y23, y24, r21, x21, x22, x23, x24, r22 ) \ + y11 += 2 * N8, y12 -= 2 * N8, y13 -= 2 * N8, y14 += 2 * N8, r11 -= 1 * N8; \ + x11 -= 2 * N8, x12 -= 2 * N8, x13 -= 2 * N8, x14 -= 2 * N8, r12 -= 1 * N8; \ + y21 += 2 * N8, y22 -= 2 * N8, y23 -= 2 * N8, y24 += 2 * N8, r21 += 1 * N8; \ + x21 += 2 * N8, x22 += 2 * N8, x23 += 2 * N8, x24 += 2 * N8, r22 += 1 * N8 +#define ptrUpdate20( y11, y12, y13, y14, r11, x11, x12, x13, x14, r12, y21, y22, y23, y24, r21, x21, x22, x23, x24, r22 ) \ + y11 += 2 * N10, y12 -= 2 * N10, y13 -= 2 * N10, y14 += 2 * N10, r11 -= 1 * N10; \ + x11 -= 2 * N10, x12 -= 2 * N10, x13 -= 2 * N10, x14 -= 2 * N10, r12 -= 1 * N10; \ + y21 += 2 * N10, y22 -= 2 * N10, y23 -= 2 * N10, y24 += 2 * N10, r21 += 1 * N10; \ + x21 += 2 * N10, x22 += 2 * N10, x23 += 2 * N10, x24 += 2 * N10, r22 += 1 * N10 - -static void cplxMultAdd10_1(Word16 *rY1, Word16 *rY2, Word16 *rY3, Word16 *rY4, - Word32 *rXR, Word32 *rXI, Word32 *iXR, Word32 *iXI, - const Word16 *cr, const Word16 *ci, Word16 gv, Word16 s, - Word16 sx, Word16 sr) +static void cplxMultAdd10_1( Word16 *rY1, Word16 *rY2, Word16 *rY3, Word16 *rY4, Word32 *rXR, Word32 *rXI, Word32 *iXR, Word32 *iXI, const Word16 *cr, const Word16 *ci, Word16 gv, Word16 s, Word16 sx, Word16 sr ) { Word32 rr12, ri12, ir12, ii12; - cmplx CL_x,CL_ry, CL_iy; - cmplx_s C_c; - - cplxMpy(rr12, ri12, ir12, ii12, rXR, rXI, iXR, iXI, cr, ci, gv, sx, sr,CL_x,CL_ry, CL_iy,C_c); - add1(rY1, rY2, rY3, rY4, rr12, ri12, ir12, ii12, s); - cplxMpy(rr12, ri12, ir12, ii12, rXR, rXI, iXR, iXI, cr, ci, gv, sx, sr,CL_x,CL_ry, CL_iy,C_c); - add1(rY1, rY2, rY3, rY4, rr12, ri12, ir12, ii12, s); + cmplx CL_x, CL_ry, CL_iy; + cmplx_s C_c; + cplxMpy( rr12, ri12, ir12, ii12, rXR, rXI, iXR, iXI, cr, ci, gv, sx, sr, CL_x, CL_ry, CL_iy, C_c ); + add1( rY1, rY2, rY3, rY4, rr12, ri12, ir12, ii12, s ); + cplxMpy( rr12, ri12, ir12, ii12, rXR, rXI, iXR, iXI, cr, ci, gv, sx, sr, CL_x, CL_ry, CL_iy, C_c ); + add1( rY1, rY2, rY3, rY4, rr12, ri12, ir12, ii12, s ); } -static void cplxMultAdd10_2(Word16 *rY1, Word16 *rY2, Word16 *rY3, Word16 *rY4, - Word32 *rXR, Word32 *rXI, Word32 *iXR, Word32 *iXI, - const Word16 *cr, const Word16 *ci, Word16 gv, Word16 s, - Word16 sx, Word16 sr) +static void cplxMultAdd10_2( Word16 *rY1, Word16 *rY2, Word16 *rY3, Word16 *rY4, Word32 *rXR, Word32 *rXI, Word32 *iXR, Word32 *iXI, const Word16 *cr, const Word16 *ci, Word16 gv, Word16 s, Word16 sx, Word16 sr ) { Word32 rr12, ri12, ir12, ii12; - cmplx CL_x,CL_ry, CL_iy; - cmplx_s C_c; - - cplxMpy(rr12, ri12, ir12, ii12, rXR, rXI, iXR, iXI, cr, ci, gv, sx, sr, CL_x, CL_ry, CL_iy, C_c); - add2(rY1, rY2, rY3, rY4, rr12, ri12, ir12, ii12, s); - cplxMpy(rr12, ri12, ir12, ii12, rXR, rXI, iXR, iXI, cr, ci, gv, sx, sr, CL_x, CL_ry, CL_iy, C_c); - add2(rY1, rY2, rY3, rY4, rr12, ri12, ir12, ii12, s); - cplxMpy(rr12, ri12, ir12, ii12, rXR, rXI, iXR, iXI, cr, ci, gv, sx, sr, CL_x, CL_ry, CL_iy, C_c); - add2(rY1, rY2, rY3, rY4, rr12, ri12, ir12, ii12, s); - + cmplx CL_x, CL_ry, CL_iy; + cmplx_s C_c; + + cplxMpy( rr12, ri12, ir12, ii12, rXR, rXI, iXR, iXI, cr, ci, gv, sx, sr, CL_x, CL_ry, CL_iy, C_c ); + add2( rY1, rY2, rY3, rY4, rr12, ri12, ir12, ii12, s ); + cplxMpy( rr12, ri12, ir12, ii12, rXR, rXI, iXR, iXI, cr, ci, gv, sx, sr, CL_x, CL_ry, CL_iy, C_c ); + add2( rY1, rY2, rY3, rY4, rr12, ri12, ir12, ii12, s ); + cplxMpy( rr12, ri12, ir12, ii12, rXR, rXI, iXR, iXI, cr, ci, gv, sx, sr, CL_x, CL_ry, CL_iy, C_c ); + add2( rY1, rY2, rY3, rY4, rr12, ri12, ir12, ii12, s ); } -static void cplxMultAdd20_1(Word16 *rY1, Word16 *rY2, Word16 *rY3, Word16 *rY4, - Word32 *rXR, Word32 *rXI, Word32 *iXR, Word32 *iXI, - const Word16 *cr, const Word16 *ci, Word16 gv, Word16 s, - Word16 sx, Word16 sr) +static void cplxMultAdd20_1( Word16 *rY1, Word16 *rY2, Word16 *rY3, Word16 *rY4, Word32 *rXR, Word32 *rXI, Word32 *iXR, Word32 *iXI, const Word16 *cr, const Word16 *ci, Word16 gv, Word16 s, Word16 sx, Word16 sr ) { Word32 rr12, ri12, ir12, ii12; - cmplx CL_x,CL_ry, CL_iy; - cmplx_s C_c; - - cplxMpy(rr12, ri12, ir12, ii12, rXR, rXI, iXR, iXI, cr, ci, gv, sx, sr, CL_x, CL_ry, CL_iy, C_c); - add1(rY1, rY2, rY3, rY4, rr12, ri12, ir12, ii12, s); - cplxMpy(rr12, ri12, ir12, ii12, rXR, rXI, iXR, iXI, cr, ci, gv, sx, sr, CL_x, CL_ry, CL_iy, C_c); - add1(rY1, rY2, rY3, rY4, rr12, ri12, ir12, ii12, s); - cplxMpy(rr12, ri12, ir12, ii12, rXR, rXI, iXR, iXI, cr, ci, gv, sx, sr, CL_x, CL_ry, CL_iy, C_c); - add1(rY1, rY2, rY3, rY4, rr12, ri12, ir12, ii12, s); - cplxMpy(rr12, ri12, ir12, ii12, rXR, rXI, iXR, iXI, cr, ci, gv, sx, sr, CL_x, CL_ry, CL_iy, C_c); - add1(rY1, rY2, rY3, rY4, rr12, ri12, ir12, ii12, s); - cplxMpy(rr12, ri12, ir12, ii12, rXR, rXI, iXR, iXI, cr, ci, gv, sx, sr, CL_x, CL_ry, CL_iy, C_c); - add1(rY1, rY2, rY3, rY4, rr12, ri12, ir12, ii12, s); - - + cmplx CL_x, CL_ry, CL_iy; + cmplx_s C_c; + + cplxMpy( rr12, ri12, ir12, ii12, rXR, rXI, iXR, iXI, cr, ci, gv, sx, sr, CL_x, CL_ry, CL_iy, C_c ); + add1( rY1, rY2, rY3, rY4, rr12, ri12, ir12, ii12, s ); + cplxMpy( rr12, ri12, ir12, ii12, rXR, rXI, iXR, iXI, cr, ci, gv, sx, sr, CL_x, CL_ry, CL_iy, C_c ); + add1( rY1, rY2, rY3, rY4, rr12, ri12, ir12, ii12, s ); + cplxMpy( rr12, ri12, ir12, ii12, rXR, rXI, iXR, iXI, cr, ci, gv, sx, sr, CL_x, CL_ry, CL_iy, C_c ); + add1( rY1, rY2, rY3, rY4, rr12, ri12, ir12, ii12, s ); + cplxMpy( rr12, ri12, ir12, ii12, rXR, rXI, iXR, iXI, cr, ci, gv, sx, sr, CL_x, CL_ry, CL_iy, C_c ); + add1( rY1, rY2, rY3, rY4, rr12, ri12, ir12, ii12, s ); + cplxMpy( rr12, ri12, ir12, ii12, rXR, rXI, iXR, iXI, cr, ci, gv, sx, sr, CL_x, CL_ry, CL_iy, C_c ); + add1( rY1, rY2, rY3, rY4, rr12, ri12, ir12, ii12, s ); } -static void cplxMultAdd20_2(Word16 *rY1, Word16 *rY2, Word16 *rY3, Word16 *rY4, - Word32 *rXR, Word32 *rXI, Word32 *iXR, Word32 *iXI, - const Word16 *cr, const Word16 *ci, Word16 gv, Word16 s, - Word16 sx, Word16 sr) +static void cplxMultAdd20_2( Word16 *rY1, Word16 *rY2, Word16 *rY3, Word16 *rY4, Word32 *rXR, Word32 *rXI, Word32 *iXR, Word32 *iXI, const Word16 *cr, const Word16 *ci, Word16 gv, Word16 s, Word16 sx, Word16 sr ) { Word32 rr12, ri12, ir12, ii12; - cmplx CL_x,CL_ry, CL_iy; - cmplx_s C_c; - - cplxMpy(rr12, ri12, ir12, ii12, rXR, rXI, iXR, iXI, cr, ci, gv, sx, sr, CL_x, CL_ry, CL_iy, C_c); - add2(rY1, rY2, rY3, rY4, rr12, ri12, ir12, ii12, s); - cplxMpy(rr12, ri12, ir12, ii12, rXR, rXI, iXR, iXI, cr, ci, gv, sx, sr, CL_x, CL_ry, CL_iy, C_c); - add2(rY1, rY2, rY3, rY4, rr12, ri12, ir12, ii12, s); - cplxMpy(rr12, ri12, ir12, ii12, rXR, rXI, iXR, iXI, cr, ci, gv, sx, sr, CL_x, CL_ry, CL_iy, C_c); - add2(rY1, rY2, rY3, rY4, rr12, ri12, ir12, ii12, s); - cplxMpy(rr12, ri12, ir12, ii12, rXR, rXI, iXR, iXI, cr, ci, gv, sx, sr, CL_x, CL_ry, CL_iy, C_c); - add2(rY1, rY2, rY3, rY4, rr12, ri12, ir12, ii12, s); - cplxMpy(rr12, ri12, ir12, ii12, rXR, rXI, iXR, iXI, cr, ci, gv, sx, sr, CL_x, CL_ry, CL_iy, C_c); - add2(rY1, rY2, rY3, rY4, rr12, ri12, ir12, ii12, s); - + cmplx CL_x, CL_ry, CL_iy; + cmplx_s C_c; + + cplxMpy( rr12, ri12, ir12, ii12, rXR, rXI, iXR, iXI, cr, ci, gv, sx, sr, CL_x, CL_ry, CL_iy, C_c ); + add2( rY1, rY2, rY3, rY4, rr12, ri12, ir12, ii12, s ); + cplxMpy( rr12, ri12, ir12, ii12, rXR, rXI, iXR, iXI, cr, ci, gv, sx, sr, CL_x, CL_ry, CL_iy, C_c ); + add2( rY1, rY2, rY3, rY4, rr12, ri12, ir12, ii12, s ); + cplxMpy( rr12, ri12, ir12, ii12, rXR, rXI, iXR, iXI, cr, ci, gv, sx, sr, CL_x, CL_ry, CL_iy, C_c ); + add2( rY1, rY2, rY3, rY4, rr12, ri12, ir12, ii12, s ); + cplxMpy( rr12, ri12, ir12, ii12, rXR, rXI, iXR, iXI, cr, ci, gv, sx, sr, CL_x, CL_ry, CL_iy, C_c ); + add2( rY1, rY2, rY3, rY4, rr12, ri12, ir12, ii12, s ); + cplxMpy( rr12, ri12, ir12, ii12, rXR, rXI, iXR, iXI, cr, ci, gv, sx, sr, CL_x, CL_ry, CL_iy, C_c ); + add2( rY1, rY2, rY3, rY4, rr12, ri12, ir12, ii12, s ); } /* calcModulation @@ -226,48 +212,53 @@ static void calcModulation( Word32 *rYR, Word32 *rYI, Word32 *rXR, Word32 *rXI, - Word16 srYR, - Word16 srYI, - Word16 srXR, - Word16 srXI, + Word16 srYR, + Word16 srYI, + Word16 srXR, + Word16 srXI, Word32 *iYR, Word32 *iYI, Word32 *iXR, Word32 *iXI, - Word16 siYR, - Word16 siYI, - Word16 siXR, - Word16 siXI, + Word16 siYR, + Word16 siYI, + Word16 siXR, + Word16 siXI, const Word16 *rRotVctr, const Word16 *iRotVctr, - Word16 m - ) + Word16 m ) { - cmplx CL_x,CL_z; - cmplx_s C_c; - int i; - int lc = m >> 1; + cmplx CL_x, CL_z; + cmplx_s C_c; + int i; + int lc = m >> 1; const Word16 *cr = rRotVctr; const Word16 *ci = iRotVctr; - for(i=0;ino_channels; + stride = 1; /* constant */ + m = cldfbBank->no_channels; move16(); - L2 = shl(m,1); - m2 = shr(m,1); - M4 = shr(m,2); - M4 = sub(m2,M4); + L2 = shl( m, 1 ); + m2 = shr( m, 1 ); + M4 = shr( m, 2 ); + M4 = sub( m2, M4 ); - L3 = sub(L2,m2); - L4 = add(L2,m2); + L3 = sub( L2, m2 ); + L4 = add( L2, m2 ); - M0M2 = sub(0,m2); - M2M1 = sub(m2,1); - L3M1 = sub(L3,1); - L4M1 = sub(L4,1); + M0M2 = sub( 0, m2 ); + M2M1 = sub( m2, 1 ); + L3M1 = sub( L3, 1 ); + L4M1 = sub( L4, 1 ); - rBuffer = &pWorkBuffer[0]; - iBuffer = &pWorkBuffer[m]; + rBuffer = &pWorkBuffer[0]; + iBuffer = &pWorkBuffer[m]; rRotVctr = cldfbBank->rRotVctr; iRotVctr = cldfbBank->iRotVctr; - pStates = cldfbBank->FilterStates; + pStates = cldfbBank->FilterStates; pStates1 = &pStates[L3M1]; pStates2 = &pStates[L3]; pStates3 = &pStates[m2]; @@ -460,175 +446,175 @@ void cldfbAnalysisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, pStates6 = &pStates[M0M2]; p_stride = CLDFB_NO_POLY; - pFilter = &cldfbBank->p_filter[p_stride - CLDFB_NO_POLY]; - pFilter1 = &pFilter[p_stride*L3M1]; - pFilter2 = &pFilter[p_stride*L3]; - pFilter3 = &pFilter[p_stride*m2]; - pFilter4 = &pFilter[p_stride*M2M1]; - pFilter5 = &pFilter[p_stride*L4M1]; - pFilter6 = &pFilter[p_stride*M0M2]; - - nSamples = i_mult(nTimeSlots, cldfbBank->no_channels); - nSamplesUpd = i_mult(cldfbBank->no_col, cldfbBank->no_channels); - offset = sub(sub(cldfbBank->p_filter_length, cldfbBank->no_channels),cldfbBank->zeros); + pFilter = &cldfbBank->p_filter[p_stride - CLDFB_NO_POLY]; + pFilter1 = &pFilter[p_stride * L3M1]; + pFilter2 = &pFilter[p_stride * L3]; + pFilter3 = &pFilter[p_stride * m2]; + pFilter4 = &pFilter[p_stride * M2M1]; + pFilter5 = &pFilter[p_stride * L4M1]; + pFilter6 = &pFilter[p_stride * M0M2]; + + nSamples = i_mult( nTimeSlots, cldfbBank->no_channels ); + nSamplesUpd = i_mult( cldfbBank->no_col, cldfbBank->no_channels ); + offset = sub( sub( cldfbBank->p_filter_length, cldfbBank->no_channels ), cldfbBank->zeros ); /* Determine states scale */ scale = -15; move16(); k = 0; move16(); - FOR (i=0; ino_channels) + FOR( i = 0; i < offset; i += cldfbBank->no_channels ) { - cldfbBank->FilterStates_e[k] = cldfbBank->FilterStates_e[k+cldfbBank->no_col]; + cldfbBank->FilterStates_e[k] = cldfbBank->FilterStates_e[k + cldfbBank->no_col]; move16(); - assert((size_t)k < sizeof(cldfbBank->FilterStates_e)/sizeof(cldfbBank->FilterStates_e[0])); - scale = s_max(scale, cldfbBank->FilterStates_e[k]); - k = add(k,1); + assert( (size_t) k < sizeof( cldfbBank->FilterStates_e ) / sizeof( cldfbBank->FilterStates_e[0] ) ); + scale = s_max( scale, cldfbBank->FilterStates_e[k] ); + k = add( k, 1 ); } - FOR (i=0; ino_channels) + FOR( i = 0; i < nSamples; i += cldfbBank->no_channels ) { cldfbBank->FilterStates_e[k] = timeIn_e; move16(); - assert((size_t)k < sizeof(cldfbBank->FilterStates_e)/sizeof(cldfbBank->FilterStates_e[0])); - scale = s_max(scale, cldfbBank->FilterStates_e[k]); - k = add(k,1); + assert( (size_t) k < sizeof( cldfbBank->FilterStates_e ) / sizeof( cldfbBank->FilterStates_e[0] ) ); + scale = s_max( scale, cldfbBank->FilterStates_e[k] ); + k = add( k, 1 ); } - i = s_max(scale, timeIn_e); - scale = sub(cldfbBank->FilterStates_eg, i); + i = s_max( scale, timeIn_e ); + scale = sub( cldfbBank->FilterStates_eg, i ); cldfbBank->FilterStates_eg = i; move16(); /* if nTimeSlots==0, make sure we have a value. */ - scaleFactor->lb_scale = add(cldfbBank->anaScalefactor, add(cldfbBank->FilterStates_eg, 5)); + scaleFactor->lb_scale = add( cldfbBank->anaScalefactor, add( cldfbBank->FilterStates_eg, 5 ) ); move16(); /* move and scale filter states */ - FOR (i=0; iFilterStates_eg); - FOR (i=0; iFilterStates_eg ); + FOR( i = 0; i < nSamples; i++ ) { #ifdef BASOP_NOGLOB pStates[offset + i] = shl_sat( *timeIn, scale ); #else - pStates[offset+i] = shl(*timeIn, scale); + pStates[offset + i] = shl( *timeIn, scale ); #endif move16(); timeIn = timeIn + stride; } - FOR (k=0; k < nTimeSlots; k++) + FOR( k = 0; k < nTimeSlots; k++ ) { - FOR (i=0; i < M4; i++) + FOR( i = 0; i < M4; i++ ) { /* prototype filter */ - r1 = L_msu0(0 , pFilter1[0 - p_stride * 2 * i], pStates1[0 * L2 - 2 * i]); - r1 = L_msu0(r1, pFilter1[1 - p_stride * 2 * i], pStates1[1 * L2 - 2 * i]); - r1 = L_msu0(r1, pFilter1[2 - p_stride * 2 * i], pStates1[2 * L2 - 2 * i]); - r1 = L_msu0(r1, pFilter1[3 - p_stride * 2 * i], pStates1[3 * L2 - 2 * i]); - r1 = L_msu0(r1, pFilter1[4 - p_stride * 2 * i], pStates1[4 * L2 - 2 * i]); - - r2 = L_msu0(0 , pFilter2[0 + p_stride * 2 * i], pStates2[0 * L2 + 2 * i]); - r2 = L_msu0(r2, pFilter2[1 + p_stride * 2 * i], pStates2[1 * L2 + 2 * i]); - r2 = L_msu0(r2, pFilter2[2 + p_stride * 2 * i], pStates2[2 * L2 + 2 * i]); - r2 = L_msu0(r2, pFilter2[3 + p_stride * 2 * i], pStates2[3 * L2 + 2 * i]); - r2 = L_msu0(r2, pFilter2[4 + p_stride * 2 * i], pStates2[4 * L2 + 2 * i]); - - i1 = L_msu0(0 , pFilter3[0 + p_stride * 2 * i], pStates3[0 * L2 + 2 * i]); - i1 = L_msu0(i1, pFilter3[1 + p_stride * 2 * i], pStates3[1 * L2 + 2 * i]); - i1 = L_msu0(i1, pFilter3[2 + p_stride * 2 * i], pStates3[2 * L2 + 2 * i]); - i1 = L_msu0(i1, pFilter3[3 + p_stride * 2 * i], pStates3[3 * L2 + 2 * i]); - i1 = L_msu0(i1, pFilter3[4 + p_stride * 2 * i], pStates3[4 * L2 + 2 * i]); - - i2 = L_msu0(0 , pFilter4[0 - p_stride * 2 * i], pStates4[0 * L2 - 2 * i]); - i2 = L_msu0(i2, pFilter4[1 - p_stride * 2 * i], pStates4[1 * L2 - 2 * i]); - i2 = L_msu0(i2, pFilter4[2 - p_stride * 2 * i], pStates4[2 * L2 - 2 * i]); - i2 = L_msu0(i2, pFilter4[3 - p_stride * 2 * i], pStates4[3 * L2 - 2 * i]); - i2 = L_msu0(i2, pFilter4[4 - p_stride * 2 * i], pStates4[4 * L2 - 2 * i]); + r1 = L_msu0( 0, pFilter1[0 - p_stride * 2 * i], pStates1[0 * L2 - 2 * i] ); + r1 = L_msu0( r1, pFilter1[1 - p_stride * 2 * i], pStates1[1 * L2 - 2 * i] ); + r1 = L_msu0( r1, pFilter1[2 - p_stride * 2 * i], pStates1[2 * L2 - 2 * i] ); + r1 = L_msu0( r1, pFilter1[3 - p_stride * 2 * i], pStates1[3 * L2 - 2 * i] ); + r1 = L_msu0( r1, pFilter1[4 - p_stride * 2 * i], pStates1[4 * L2 - 2 * i] ); + + r2 = L_msu0( 0, pFilter2[0 + p_stride * 2 * i], pStates2[0 * L2 + 2 * i] ); + r2 = L_msu0( r2, pFilter2[1 + p_stride * 2 * i], pStates2[1 * L2 + 2 * i] ); + r2 = L_msu0( r2, pFilter2[2 + p_stride * 2 * i], pStates2[2 * L2 + 2 * i] ); + r2 = L_msu0( r2, pFilter2[3 + p_stride * 2 * i], pStates2[3 * L2 + 2 * i] ); + r2 = L_msu0( r2, pFilter2[4 + p_stride * 2 * i], pStates2[4 * L2 + 2 * i] ); + + i1 = L_msu0( 0, pFilter3[0 + p_stride * 2 * i], pStates3[0 * L2 + 2 * i] ); + i1 = L_msu0( i1, pFilter3[1 + p_stride * 2 * i], pStates3[1 * L2 + 2 * i] ); + i1 = L_msu0( i1, pFilter3[2 + p_stride * 2 * i], pStates3[2 * L2 + 2 * i] ); + i1 = L_msu0( i1, pFilter3[3 + p_stride * 2 * i], pStates3[3 * L2 + 2 * i] ); + i1 = L_msu0( i1, pFilter3[4 + p_stride * 2 * i], pStates3[4 * L2 + 2 * i] ); + + i2 = L_msu0( 0, pFilter4[0 - p_stride * 2 * i], pStates4[0 * L2 - 2 * i] ); + i2 = L_msu0( i2, pFilter4[1 - p_stride * 2 * i], pStates4[1 * L2 - 2 * i] ); + i2 = L_msu0( i2, pFilter4[2 - p_stride * 2 * i], pStates4[2 * L2 - 2 * i] ); + i2 = L_msu0( i2, pFilter4[3 - p_stride * 2 * i], pStates4[3 * L2 - 2 * i] ); + i2 = L_msu0( i2, pFilter4[4 - p_stride * 2 * i], pStates4[4 * L2 - 2 * i] ); /* folding */ - rBuffer[2*i] = L_sub(r1,r2); + rBuffer[2 * i] = L_sub( r1, r2 ); move32(); - rBuffer[2*i+1] = L_negate(L_add(i1,i2)); + rBuffer[2 * i + 1] = L_negate( L_add( i1, i2 ) ); move32(); /* folding */ - iBuffer[2*i] = L_add(r1,r2); + iBuffer[2 * i] = L_add( r1, r2 ); move32(); - iBuffer[2*i+1] = L_sub(i1,i2); + iBuffer[2 * i + 1] = L_sub( i1, i2 ); move32(); } - FOR (i=M4; i < m2; i++) + FOR( i = M4; i < m2; i++ ) { /* prototype filter */ - r1 = L_msu0(0 , pFilter1[0 - p_stride * 2 * i], pStates1[0 * L2 - 2 * i]); - r1 = L_msu0(r1, pFilter1[1 - p_stride * 2 * i], pStates1[1 * L2 - 2 * i]); - r1 = L_msu0(r1, pFilter1[2 - p_stride * 2 * i], pStates1[2 * L2 - 2 * i]); - r1 = L_msu0(r1, pFilter1[3 - p_stride * 2 * i], pStates1[3 * L2 - 2 * i]); - r1 = L_msu0(r1, pFilter1[4 - p_stride * 2 * i], pStates1[4 * L2 - 2 * i]); - - r2 = L_msu0(0 , pFilter6[0 + p_stride * 2 * i], pStates6[0 * L2 + 2 * i]); - r2 = L_msu0(r2, pFilter6[1 + p_stride * 2 * i], pStates6[1 * L2 + 2 * i]); - r2 = L_msu0(r2, pFilter6[2 + p_stride * 2 * i], pStates6[2 * L2 + 2 * i]); - r2 = L_msu0(r2, pFilter6[3 + p_stride * 2 * i], pStates6[3 * L2 + 2 * i]); - r2 = L_msu0(r2, pFilter6[4 + p_stride * 2 * i], pStates6[4 * L2 + 2 * i]); - - i1 = L_msu0(0 , pFilter5[0 - p_stride * 2 * i], pStates5[0 * L2 - 2 * i]); - i1 = L_msu0(i1, pFilter5[1 - p_stride * 2 * i], pStates5[1 * L2 - 2 * i]); - i1 = L_msu0(i1, pFilter5[2 - p_stride * 2 * i], pStates5[2 * L2 - 2 * i]); - i1 = L_msu0(i1, pFilter5[3 - p_stride * 2 * i], pStates5[3 * L2 - 2 * i]); - i1 = L_msu0(i1, pFilter5[4 - p_stride * 2 * i], pStates5[4 * L2 - 2 * i]); - - i2 = L_msu0(0 , pFilter3[0 + p_stride * 2 * i], pStates3[0 * L2 + 2 * i]); - i2 = L_msu0(i2, pFilter3[1 + p_stride * 2 * i], pStates3[1 * L2 + 2 * i]); - i2 = L_msu0(i2, pFilter3[2 + p_stride * 2 * i], pStates3[2 * L2 + 2 * i]); - i2 = L_msu0(i2, pFilter3[3 + p_stride * 2 * i], pStates3[3 * L2 + 2 * i]); - i2 = L_msu0(i2, pFilter3[4 + p_stride * 2 * i], pStates3[4 * L2 + 2 * i]); + r1 = L_msu0( 0, pFilter1[0 - p_stride * 2 * i], pStates1[0 * L2 - 2 * i] ); + r1 = L_msu0( r1, pFilter1[1 - p_stride * 2 * i], pStates1[1 * L2 - 2 * i] ); + r1 = L_msu0( r1, pFilter1[2 - p_stride * 2 * i], pStates1[2 * L2 - 2 * i] ); + r1 = L_msu0( r1, pFilter1[3 - p_stride * 2 * i], pStates1[3 * L2 - 2 * i] ); + r1 = L_msu0( r1, pFilter1[4 - p_stride * 2 * i], pStates1[4 * L2 - 2 * i] ); + + r2 = L_msu0( 0, pFilter6[0 + p_stride * 2 * i], pStates6[0 * L2 + 2 * i] ); + r2 = L_msu0( r2, pFilter6[1 + p_stride * 2 * i], pStates6[1 * L2 + 2 * i] ); + r2 = L_msu0( r2, pFilter6[2 + p_stride * 2 * i], pStates6[2 * L2 + 2 * i] ); + r2 = L_msu0( r2, pFilter6[3 + p_stride * 2 * i], pStates6[3 * L2 + 2 * i] ); + r2 = L_msu0( r2, pFilter6[4 + p_stride * 2 * i], pStates6[4 * L2 + 2 * i] ); + + i1 = L_msu0( 0, pFilter5[0 - p_stride * 2 * i], pStates5[0 * L2 - 2 * i] ); + i1 = L_msu0( i1, pFilter5[1 - p_stride * 2 * i], pStates5[1 * L2 - 2 * i] ); + i1 = L_msu0( i1, pFilter5[2 - p_stride * 2 * i], pStates5[2 * L2 - 2 * i] ); + i1 = L_msu0( i1, pFilter5[3 - p_stride * 2 * i], pStates5[3 * L2 - 2 * i] ); + i1 = L_msu0( i1, pFilter5[4 - p_stride * 2 * i], pStates5[4 * L2 - 2 * i] ); + + i2 = L_msu0( 0, pFilter3[0 + p_stride * 2 * i], pStates3[0 * L2 + 2 * i] ); + i2 = L_msu0( i2, pFilter3[1 + p_stride * 2 * i], pStates3[1 * L2 + 2 * i] ); + i2 = L_msu0( i2, pFilter3[2 + p_stride * 2 * i], pStates3[2 * L2 + 2 * i] ); + i2 = L_msu0( i2, pFilter3[3 + p_stride * 2 * i], pStates3[3 * L2 + 2 * i] ); + i2 = L_msu0( i2, pFilter3[4 + p_stride * 2 * i], pStates3[4 * L2 + 2 * i] ); /* folding */ - rBuffer[2*i] = L_add(r1,r2); + rBuffer[2 * i] = L_add( r1, r2 ); move32(); - rBuffer[2*i+1] = L_sub(i1,i2); + rBuffer[2 * i + 1] = L_sub( i1, i2 ); move32(); /* folding */ - iBuffer[2*i] = L_sub(r1,r2); + iBuffer[2 * i] = L_sub( r1, r2 ); move32(); - iBuffer[2*i+1] = L_add(i1,i2); + iBuffer[2 * i + 1] = L_add( i1, i2 ); move32(); } /* pre modulation of DST IV and DCT IV */ - calcModulation(&rBuffer[0], &rBuffer[1], &rBuffer[0], &rBuffer[1], 2, 2, 2, 2, - &iBuffer[0], &iBuffer[1], &iBuffer[0], &iBuffer[1], 2, 2, 2, 2, - rRotVctr, iRotVctr, m); + calcModulation( &rBuffer[0], &rBuffer[1], &rBuffer[0], &rBuffer[1], 2, 2, 2, 2, + &iBuffer[0], &iBuffer[1], &iBuffer[0], &iBuffer[1], 2, 2, 2, 2, + rRotVctr, iRotVctr, m ); /* FFT of DST IV */ scale = 0; move16(); - BASOP_cfft((cmplx *)rBuffer, m2, &scale, workBuffer); + BASOP_cfft( (cmplx *) rBuffer, m2, &scale, workBuffer ); /* store analysis scalefactor for cldfb */ - scaleFactor->lb_scale = add(cldfbBank->anaScalefactor, add(cldfbBank->FilterStates_eg, scale)); + scaleFactor->lb_scale = add( cldfbBank->anaScalefactor, add( cldfbBank->FilterStates_eg, scale ) ); move16(); /* FFT of DCT IV */ - BASOP_cfft((cmplx *)iBuffer, m2, &scale, workBuffer); + BASOP_cfft( (cmplx *) iBuffer, m2, &scale, workBuffer ); /* post modulation of DST IV and DCT IV */ - calcModulation(&rAnalysis[k][m-1], &rAnalysis[k][0], &rBuffer[0], &rBuffer[1],-2, 2, 2, 2, - &iAnalysis[k][0], &iAnalysis[k][m-1], &iBuffer[0], &iBuffer[1], 2,-2, 2, 2, - rRotVctr, iRotVctr, m); + calcModulation( &rAnalysis[k][m - 1], &rAnalysis[k][0], &rBuffer[0], &rBuffer[1], -2, 2, 2, 2, + &iAnalysis[k][0], &iAnalysis[k][m - 1], &iBuffer[0], &iBuffer[1], 2, -2, 2, 2, + rRotVctr, iRotVctr, m ); /* update states pointer */ @@ -639,7 +625,6 @@ void cldfbAnalysisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, pStates4 = &pStates4[cldfbBank->no_channels]; pStates6 = &pStates6[cldfbBank->no_channels]; } - } @@ -662,40 +647,38 @@ void cldfbAnalysisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, Returns: void */ -void -cldfbSynthesisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, - Word32 **rAnalysis, - Word32 **iAnalysis, - const CLDFB_SCALE_FACTOR *scaleFactor, - Word16 *timeOut, - const Word16 timeOut_e, - const Word16 nTimeSlots, - Word32 *pWorkBuffer - ) +void cldfbSynthesisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, + Word32 **rAnalysis, + Word32 **iAnalysis, + const CLDFB_SCALE_FACTOR *scaleFactor, + Word16 *timeOut, + const Word16 timeOut_e, + const Word16 nTimeSlots, + Word32 *pWorkBuffer ) { - Word16 i; - Word16 k; - Word16 L2; - Word16 m; - Word16 m2; - Word16 Lz; - Word16 Mz; - Word32 acc; - Word16 offset1; - Word16 offset2; - Word16 channels0; - Word16 channels1; - Word16 channels2; - Word16 channels3; - Word16 channels4; - Word16 statesSizeM1; - Word16 statesSizeM2; - Word16 stride; - - Word16 scale, scaleMod; - Word16 outScale; - Word16 scaleLB; - Word16 scaleHB; + Word16 i; + Word16 k; + Word16 L2; + Word16 m; + Word16 m2; + Word16 Lz; + Word16 Mz; + Word32 acc; + Word16 offset1; + Word16 offset2; + Word16 channels0; + Word16 channels1; + Word16 channels2; + Word16 channels3; + Word16 channels4; + Word16 statesSizeM1; + Word16 statesSizeM2; + Word16 stride; + + Word16 scale, scaleMod; + Word16 outScale; + Word16 scaleLB; + Word16 scaleHB; Word32 *rAnalysisS; Word32 *iAnalysisS; @@ -713,237 +696,236 @@ cldfbSynthesisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, const Word16 *rRotVctr; const Word16 *iRotVctr; - Word32 workBuffer[2*BASOP_CFFT_MAX_LENGTH]; + Word32 workBuffer[2 * BASOP_CFFT_MAX_LENGTH]; - m = cldfbBank->no_channels; + m = cldfbBank->no_channels; move16(); - L2 = shl(m,1); - m2 = shr(m,1); - Lz = s_min(cldfbBank->lsb, sub(m,cldfbBank->bandsToZero)); - Mz = s_min(cldfbBank->usb, sub(m,cldfbBank->bandsToZero)); - stride = 1; /* constant */ + L2 = shl( m, 1 ); + m2 = shr( m, 1 ); + Lz = s_min( cldfbBank->lsb, sub( m, cldfbBank->bandsToZero ) ); + Mz = s_min( cldfbBank->usb, sub( m, cldfbBank->bandsToZero ) ); + stride = 1; /* constant */ - channels0 = sub(m,cldfbBank->zeros); - channels1 = sub(m,1); - channels2 = shl(m,1); - channels3 = add(m,channels2); - channels4 = shl(channels2,1); + channels0 = sub( m, cldfbBank->zeros ); + channels1 = sub( m, 1 ); + channels2 = shl( m, 1 ); + channels3 = add( m, channels2 ); + channels4 = shl( channels2, 1 ); - statesSizeM1 = sub(shl(cldfbBank->p_filter_length,1),m); - statesSizeM2 = sub(statesSizeM1,m); + statesSizeM1 = sub( shl( cldfbBank->p_filter_length, 1 ), m ); + statesSizeM2 = sub( statesSizeM1, m ); - offset1 = sub(channels1,cldfbBank->zeros); - offset2 = add(offset1,cldfbBank->no_channels); + offset1 = sub( channels1, cldfbBank->zeros ); + offset2 = add( offset1, cldfbBank->no_channels ); rBuffer = &pWorkBuffer[0]; iBuffer = &pWorkBuffer[m]; - nBuffer = (Word16*)(&pWorkBuffer[L2]); + nBuffer = (Word16 *) ( &pWorkBuffer[L2] ); - rAnalysisS = &pWorkBuffer[3*m]; - iAnalysisS = &pWorkBuffer[4*m]; + rAnalysisS = &pWorkBuffer[3 * m]; + iAnalysisS = &pWorkBuffer[4 * m]; rRotVctr = cldfbBank->rRotVctr; iRotVctr = cldfbBank->iRotVctr; scale = scaleFactor->lb_scale; move16(); - if ( NE_16(Lz, Mz)) + if ( NE_16( Lz, Mz ) ) { - scale = s_max(scale, scaleFactor->hb_scale); + scale = s_max( scale, scaleFactor->hb_scale ); } - scaleLB = limitScale32(sub(scale, scaleFactor->lb_scale)); - scaleHB = limitScale32(sub(scale, scaleFactor->hb_scale)); + scaleLB = limitScale32( sub( scale, scaleFactor->lb_scale ) ); + scaleHB = limitScale32( sub( scale, scaleFactor->hb_scale ) ); outScale = cldfbBank->synFilterHeadroom; move16(); - scaleMod = sub(add(scale, cldfbBank->outScalefactor), outScale); + scaleMod = sub( add( scale, cldfbBank->outScalefactor ), outScale ); /* Increase CLDFB synthesis states for low level signals */ - IF ( LT_16(scale, 8)) + IF( LT_16( scale, 8 ) ) { - scaleMod = add(scaleMod, 2); - outScale = sub(outScale, 2); + scaleMod = add( scaleMod, 2 ); + outScale = sub( outScale, 2 ); } - scaleMod = sub(scaleMod, timeOut_e); - scale = add(outScale, timeOut_e); - IF ( NE_16(scale, cldfbBank->FilterStates_eg)) + scaleMod = sub( scaleMod, timeOut_e ); + scale = add( outScale, timeOut_e ); + IF( NE_16( scale, cldfbBank->FilterStates_eg ) ) { - Scale_sig(cldfbBank->FilterStates, statesSizeM2, sub(cldfbBank->FilterStates_eg, scale)); + Scale_sig( cldfbBank->FilterStates, statesSizeM2, sub( cldfbBank->FilterStates_eg, scale ) ); cldfbBank->FilterStates_eg = scale; move16(); } - FOR (k=0; k < nTimeSlots; k++) + FOR( k = 0; k < nTimeSlots; k++ ) { { - FOR (i=0; i < Lz; i+=2) + FOR( i = 0; i < Lz; i += 2 ) { - rAnalysisS[i] = L_shr(rAnalysis[k][i],scaleLB); + rAnalysisS[i] = L_shr( rAnalysis[k][i], scaleLB ); move32(); - iAnalysisS[i] = L_negate(L_shr(iAnalysis[k][i],scaleLB)); + iAnalysisS[i] = L_negate( L_shr( iAnalysis[k][i], scaleLB ) ); move32(); } - IF ( LT_16(i,Mz)) + IF( LT_16( i, Mz ) ) { - FOR ( ; i < Mz; i+=2) + FOR( ; i < Mz; i += 2 ) { - rAnalysisS[i] = L_shr(rAnalysis[k][i],scaleHB); + rAnalysisS[i] = L_shr( rAnalysis[k][i], scaleHB ); move32(); - iAnalysisS[i] = L_negate(L_shr(iAnalysis[k][i],scaleHB)); + iAnalysisS[i] = L_negate( L_shr( iAnalysis[k][i], scaleHB ) ); move32(); } } - IF ( LT_16(i,m)) + IF( LT_16( i, m ) ) { - FOR ( ; i < m; i+=2) + FOR( ; i < m; i += 2 ) { - rAnalysisS[i] = L_deposit_l(0); - iAnalysisS[i] = L_deposit_l(0); + rAnalysisS[i] = L_deposit_l( 0 ); + iAnalysisS[i] = L_deposit_l( 0 ); } } - FOR (i=1; i < Lz; i+=2) + FOR( i = 1; i < Lz; i += 2 ) { - rAnalysisS[i] = L_shr(rAnalysis[k][i],scaleLB); + rAnalysisS[i] = L_shr( rAnalysis[k][i], scaleLB ); move32(); - iAnalysisS[i] = L_shr(iAnalysis[k][i],scaleLB); + iAnalysisS[i] = L_shr( iAnalysis[k][i], scaleLB ); move32(); } - IF ( LT_16(i,Mz)) + IF( LT_16( i, Mz ) ) { - FOR ( ; i < Mz; i+=2) + FOR( ; i < Mz; i += 2 ) { - rAnalysisS[i] = L_shr(rAnalysis[k][i],scaleHB); + rAnalysisS[i] = L_shr( rAnalysis[k][i], scaleHB ); move32(); - iAnalysisS[i] = L_shr(iAnalysis[k][i],scaleHB); + iAnalysisS[i] = L_shr( iAnalysis[k][i], scaleHB ); move32(); } } - IF ( LT_16(i,m)) + IF( LT_16( i, m ) ) { - FOR ( ; i < m; i+=2) + FOR( ; i < m; i += 2 ) { - rAnalysisS[i] = L_deposit_l(0); - iAnalysisS[i] = L_deposit_l(0); + rAnalysisS[i] = L_deposit_l( 0 ); + iAnalysisS[i] = L_deposit_l( 0 ); } } } /* pre modulation */ - calcModulation(&rBuffer[0], &rBuffer[1], &rAnalysisS[0], &rAnalysisS[m-1], 2, 2, 2,-2, - &iBuffer[0], &iBuffer[1], &iAnalysisS[0], &iAnalysisS[m-1], 2, 2, 2,-2, - rRotVctr, iRotVctr, m); + calcModulation( &rBuffer[0], &rBuffer[1], &rAnalysisS[0], &rAnalysisS[m - 1], 2, 2, 2, -2, + &iBuffer[0], &iBuffer[1], &iAnalysisS[0], &iAnalysisS[m - 1], 2, 2, 2, -2, + rRotVctr, iRotVctr, m ); /* FFT of DST IV */ scale = 0; move16(); - BASOP_cfft((cmplx *)rBuffer, m2, &scale, workBuffer); + BASOP_cfft( (cmplx *) rBuffer, m2, &scale, workBuffer ); /* FFT of DCT IV */ scale = scaleMod; move16(); - BASOP_cfft((cmplx *)iBuffer, m2, &scale, workBuffer); + BASOP_cfft( (cmplx *) iBuffer, m2, &scale, workBuffer ); /* post modulation and folding */ - calcModulationAndFolding(nBuffer, rBuffer, iBuffer, rRotVctr, iRotVctr, cldfbBank->synGain, scale, m, m2); + calcModulationAndFolding( nBuffer, rBuffer, iBuffer, rRotVctr, iRotVctr, cldfbBank->synGain, scale, m, m2 ); /* prototype filter */ - pStates = &cldfbBank->FilterStates[k*L2]; + pStates = &cldfbBank->FilterStates[k * L2]; pFilterS = &cldfbBank->p_filter[0]; - pFilterM = &cldfbBank->p_filter[shr(cldfbBank->p_filter_length,1)]; + pFilterM = &cldfbBank->p_filter[shr( cldfbBank->p_filter_length, 1 )]; - FOR (i=0; i < channels0; i++) + FOR( i = 0; i < channels0; i++ ) { pStatesI = &pStates[i]; - pStatesR = &pStates[i+channels3]; + pStatesR = &pStates[i + channels3]; - acc = L_mult( *pStatesI, *pFilterS++); - acc = L_mac(acc, *pStatesR, *pFilterM++); + acc = L_mult( *pStatesI, *pFilterS++ ); + acc = L_mac( acc, *pStatesR, *pFilterM++ ); pStatesR += channels4; pStatesI += channels4; - acc = L_mac(acc, *pStatesI, *pFilterS++); - acc = L_mac(acc, *pStatesR, *pFilterM++); + acc = L_mac( acc, *pStatesI, *pFilterS++ ); + acc = L_mac( acc, *pStatesR, *pFilterM++ ); pStatesR += channels4; pStatesI += channels4; - acc = L_mac(acc, *pStatesI, *pFilterS++); - acc = L_mac(acc, *pStatesR, *pFilterM++); + acc = L_mac( acc, *pStatesI, *pFilterS++ ); + acc = L_mac( acc, *pStatesR, *pFilterM++ ); pStatesR += channels4; pStatesI += channels4; - acc = L_mac(acc, *pStatesI, *pFilterS++); - acc = L_mac(acc, *pStatesR, *pFilterM++); + acc = L_mac( acc, *pStatesI, *pFilterS++ ); + acc = L_mac( acc, *pStatesR, *pFilterM++ ); pStatesI += channels4; - acc = L_mac(acc, *pStatesI, *pFilterS++); - acc = L_mac(acc, nBuffer[channels1-i], *pFilterM++); + acc = L_mac( acc, *pStatesI, *pFilterS++ ); + acc = L_mac( acc, nBuffer[channels1 - i], *pFilterM++ ); BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB - timeOut[(offset1-i)*stride] = round_fx_sat(L_shl_sat(acc,outScale)); + timeOut[( offset1 - i ) * stride] = round_fx_sat( L_shl_sat( acc, outScale ) ); #else - timeOut[(offset1-i)*stride] = round_fx(L_shl(acc,outScale)); + timeOut[( offset1 - i ) * stride] = round_fx( L_shl( acc, outScale ) ); #endif BASOP_SATURATE_WARNING_ON_EVS } - FOR ( ; ino_channels; i++) + FOR( ; i < cldfbBank->no_channels; i++ ) { - pStatesI = &pStates[i+channels2]; - pStatesR = &pStates[i+channels2+channels3]; + pStatesI = &pStates[i + channels2]; + pStatesR = &pStates[i + channels2 + channels3]; - acc = L_mult( *pStatesI, *pFilterS++); - acc = L_mac(acc, *pStatesR, *pFilterM++); + acc = L_mult( *pStatesI, *pFilterS++ ); + acc = L_mac( acc, *pStatesR, *pFilterM++ ); pStatesR += channels4; pStatesI += channels4; - acc = L_mac(acc, *pStatesI, *pFilterS++); - acc = L_mac(acc, *pStatesR, *pFilterM++); + acc = L_mac( acc, *pStatesI, *pFilterS++ ); + acc = L_mac( acc, *pStatesR, *pFilterM++ ); pStatesR += channels4; pStatesI += channels4; - acc = L_mac(acc, *pStatesI, *pFilterS++); - acc = L_mac(acc, *pStatesR, *pFilterM++); + acc = L_mac( acc, *pStatesI, *pFilterS++ ); + acc = L_mac( acc, *pStatesR, *pFilterM++ ); pStatesR += channels4; pStatesI += channels4; - acc = L_mac(acc, *pStatesI, *pFilterS++); - acc = L_mac(acc, *pStatesR, *pFilterM++); + acc = L_mac( acc, *pStatesI, *pFilterS++ ); + acc = L_mac( acc, *pStatesR, *pFilterM++ ); - acc = L_mac(acc, nBuffer[channels1+m-i], *pFilterS++); + acc = L_mac( acc, nBuffer[channels1 + m - i], *pFilterS++ ); pFilterM++; BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB - timeOut[(offset2-i)*stride] = round_fx_sat(L_shl_sat(acc,outScale)); + timeOut[( offset2 - i ) * stride] = round_fx_sat( L_shl_sat( acc, outScale ) ); #else - timeOut[(offset2-i)*stride] = round_fx(L_shl(acc,outScale)); + timeOut[( offset2 - i ) * stride] = round_fx( L_shl( acc, outScale ) ); #endif BASOP_SATURATE_WARNING_ON_EVS } - FOR (i=0; ino_channels; i++) + FOR( i = 0; i < cldfbBank->no_channels; i++ ) { - pStates[statesSizeM1+i] = nBuffer[channels1-i]; + pStates[statesSizeM1 + i] = nBuffer[channels1 - i]; move16(); - pStates[statesSizeM2+i] = nBuffer[channels1+m-i]; + pStates[statesSizeM2 + i] = nBuffer[channels1 + m - i]; move16(); } - timeOut = &timeOut[m*stride]; + timeOut = &timeOut[m * stride]; } /* move filter states */ - Copy(&cldfbBank->FilterStates[i_mult(nTimeSlots,L2)], cldfbBank->FilterStates, statesSizeM2); - set16_fx(&cldfbBank->FilterStates[statesSizeM2],0,L2); - + Copy( &cldfbBank->FilterStates[i_mult( nTimeSlots, L2 )], cldfbBank->FilterStates, statesSizeM2 ); + set16_fx( &cldfbBank->FilterStates[statesSizeM2], 0, L2 ); } @@ -953,16 +935,16 @@ cldfbSynthesisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, * configures a CLDFB handle *--------------------------------------------------------------------*/ -void configureCldfb ( HANDLE_CLDFB_FILTER_BANK h_cldfb, /*!< Returns handle */ - const Word16 no_channels, /*!< Number of channels (bands) */ - const Word16 frameSize /*!< FrameSize */ - ) +void configureCldfb( HANDLE_CLDFB_FILTER_BANK h_cldfb, /*!< Returns handle */ + const Word16 no_channels, /*!< Number of channels (bands) */ + const Word16 frameSize /*!< FrameSize */ +) { h_cldfb->no_channels = no_channels; move16(); - assert(h_cldfb->no_channels >= 10); - h_cldfb->no_col = div_l(frameSize,shr(h_cldfb->no_channels,1)); + assert( h_cldfb->no_channels >= 10 ); + h_cldfb->no_col = div_l( frameSize, shr( h_cldfb->no_channels, 1 ) ); /* was cldfbInitFilterBank()*/ h_cldfb->anaScalefactor = 0; @@ -978,10 +960,10 @@ void configureCldfb ( HANDLE_CLDFB_FILTER_BANK h_cldfb, /*!< Returns han h_cldfb->memory_length = 0; move16(); - h_cldfb->p_filter_length = i_mult(10,h_cldfb->no_channels); + h_cldfb->p_filter_length = i_mult( 10, h_cldfb->no_channels ); move16(); - h_cldfb->flags = s_or(h_cldfb->flags,CLDFB_FLAG_2_5MS_SETUP); + h_cldfb->flags = s_or( h_cldfb->flags, CLDFB_FLAG_2_5MS_SETUP ); h_cldfb->filterScale = CLDFB_CLDFB80_PFT_SCALE; move16(); @@ -990,13 +972,14 @@ void configureCldfb ( HANDLE_CLDFB_FILTER_BANK h_cldfb, /*!< Returns han h_cldfb->synFilterHeadroom = SYN_FILTER_HEADROOM_2_5MS; move16(); - cldfb_init_proto_and_twiddles (h_cldfb); + cldfb_init_proto_and_twiddles( h_cldfb ); h_cldfb->lsb = no_channels; move16(); - h_cldfb->usb = s_min(no_channels, h_cldfb->no_channels); /* Does this make any sense? in the previous implemenatation lsb, usb and no_channels are all maxCldfbBands */ move16(); + h_cldfb->usb = s_min( no_channels, h_cldfb->no_channels ); /* Does this make any sense? in the previous implemenatation lsb, usb and no_channels are all maxCldfbBands */ + move16(); - h_cldfb->FilterStates = (void*)h_cldfb->FilterStates; + h_cldfb->FilterStates = (void *) h_cldfb->FilterStates; h_cldfb->outScalefactor = h_cldfb->synScalefactor; move16(); @@ -1008,22 +991,23 @@ void configureCldfb ( HANDLE_CLDFB_FILTER_BANK h_cldfb, /*!< Returns han * * open and configures a CLDFB handle *--------------------------------------------------------------------*/ -ivas_error openCldfb ( - HANDLE_CLDFB_FILTER_BANK *h_cldfb, /*!< Returns handle */ - const Word16 type, /*!< analysis or synthesis */ - const Word16 maxCldfbBands, /*!< number of cldfb bands */ - const Word16 frameSize /*!< FrameSize */ +ivas_error openCldfb( + HANDLE_CLDFB_FILTER_BANK *h_cldfb, /*!< Returns handle */ + const Word16 type, /*!< analysis or synthesis */ + const Word16 maxCldfbBands, /*!< number of cldfb bands */ + const Word16 frameSize /*!< FrameSize */ #ifdef ADD_IVAS_CLDFB - ,CLDFB_PROTOTYPE prototype /* i : CLDFB version (1.25ms/5ms delay) */ + , + CLDFB_PROTOTYPE prototype /* i : CLDFB version (1.25ms/5ms delay) */ #endif ) { HANDLE_CLDFB_FILTER_BANK hs; - hs = (HANDLE_CLDFB_FILTER_BANK)count_malloc(sizeof (CLDFB_FILTER_BANK)); - if (hs == NULL) + hs = (HANDLE_CLDFB_FILTER_BANK) count_malloc( sizeof( CLDFB_FILTER_BANK ) ); + if ( hs == NULL ) { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB"); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB" ); } hs->type = type; @@ -1032,52 +1016,52 @@ ivas_error openCldfb ( #endif move16(); - IF (type == CLDFB_ANALYSIS) + IF( type == CLDFB_ANALYSIS ) { - hs->FilterStates = (Word16 *)count_malloc(STATE_BUFFER_SIZE*maxCldfbBands* sizeof (Word16)); + hs->FilterStates = (Word16 *) count_malloc( STATE_BUFFER_SIZE * maxCldfbBands * sizeof( Word16 ) ); } ELSE { - hs->FilterStates = (Word16 *)count_malloc( 2 * STATE_BUFFER_SIZE * maxCldfbBands* sizeof (Word16)); + hs->FilterStates = (Word16 *) count_malloc( 2 * STATE_BUFFER_SIZE * maxCldfbBands * sizeof( Word16 ) ); } - if (hs->FilterStates == NULL) + if ( hs->FilterStates == NULL ) { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB"); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB" ); } hs->flags &= ~CLDFB_FLAG_KEEP_STATES; - configureCldfb (hs, maxCldfbBands, frameSize ); + configureCldfb( hs, maxCldfbBands, frameSize ); hs->memory = NULL; hs->memory_length = 0; move16(); - IF( hs->type == CLDFB_ANALYSIS) + IF( hs->type == CLDFB_ANALYSIS ) { test(); - IF ( (s_and(hs->flags,CLDFB_FLAG_KEEP_STATES) == 0) && (hs->FilterStates != 0) ) + IF( ( s_and( hs->flags, CLDFB_FLAG_KEEP_STATES ) == 0 ) && ( hs->FilterStates != 0 ) ) { - set16_fx(hs->FilterStates, 0, i_mult(STATE_BUFFER_SIZE,hs->no_channels)); - set16_fx(hs->FilterStates_e, 0, sizeof(hs->FilterStates_e)/sizeof(hs->FilterStates_e[0])); + set16_fx( hs->FilterStates, 0, i_mult( STATE_BUFFER_SIZE, hs->no_channels ) ); + set16_fx( hs->FilterStates_e, 0, sizeof( hs->FilterStates_e ) / sizeof( hs->FilterStates_e[0] ) ); hs->FilterStates_eg = 0; move16(); } } - ELSE IF (hs->type == CLDFB_SYNTHESIS ) + ELSE IF( hs->type == CLDFB_SYNTHESIS ) { - IF ( hs->FilterStates != 0 ) + IF( hs->FilterStates != 0 ) { - IF ( s_and(hs->flags,CLDFB_FLAG_KEEP_STATES) == 0 ) + IF( s_and( hs->flags, CLDFB_FLAG_KEEP_STATES ) == 0 ) { - set16_fx(hs->FilterStates, 0, i_mult( shl(STATE_BUFFER_SIZE,1), hs->no_channels)); + set16_fx( hs->FilterStates, 0, i_mult( shl( STATE_BUFFER_SIZE, 1 ), hs->no_channels ) ); } } hs->FilterStates_eg = 0; move16(); } - if (h_cldfb != NULL) + if ( h_cldfb != NULL ) { *h_cldfb = hs; } @@ -1087,15 +1071,14 @@ ivas_error openCldfb ( /*-------------------------------------------------------------------* -* resampleCldfb() -* -* Change sample rate of filter bank -*--------------------------------------------------------------------*/ -void resampleCldfb (HANDLE_CLDFB_FILTER_BANK hs, + * resampleCldfb() + * + * Change sample rate of filter bank + *--------------------------------------------------------------------*/ +void resampleCldfb( HANDLE_CLDFB_FILTER_BANK hs, const Word16 newCldfbBands, const Word16 frameSize, - const Word8 firstFrame - ) + const Word8 firstFrame ) { Word16 timeOffset; @@ -1104,23 +1087,23 @@ void resampleCldfb (HANDLE_CLDFB_FILTER_BANK hs, noChannelsOld = hs->no_channels; move16(); - timeOffsetOld = sub(sub(hs->p_filter_length,hs->no_channels),hs->zeros); + timeOffsetOld = sub( sub( hs->p_filter_length, hs->no_channels ), hs->zeros ); /* change all CLDFB bank parameters that depend on the no of channels */ - hs->flags = s_or(hs->flags,CLDFB_FLAG_KEEP_STATES); + hs->flags = s_or( hs->flags, CLDFB_FLAG_KEEP_STATES ); move16(); /* new settings */ - configureCldfb (hs, newCldfbBands, frameSize); + configureCldfb( hs, newCldfbBands, frameSize ); /* resample cldfb state buffer */ - timeOffset = sub(sub(hs->p_filter_length,hs->no_channels),hs->zeros); + timeOffset = sub( sub( hs->p_filter_length, hs->no_channels ), hs->zeros ); IF( firstFrame == 0 ) { /*low complexity-resampling only stored previous samples that are needed for next frame modulation */ - lerp(hs->FilterStates+(noChannelsOld*hs->no_col), hs->FilterStates+(noChannelsOld*hs->no_col), timeOffset, timeOffsetOld); - Copy(hs->FilterStates+(noChannelsOld*hs->no_col), hs->FilterStates+frameSize, timeOffset); + lerp( hs->FilterStates + ( noChannelsOld * hs->no_col ), hs->FilterStates + ( noChannelsOld * hs->no_col ), timeOffset, timeOffsetOld ); + Copy( hs->FilterStates + ( noChannelsOld * hs->no_col ), hs->FilterStates + frameSize, timeOffset ); } return; @@ -1144,44 +1127,42 @@ void resampleCldfb (HANDLE_CLDFB_FILTER_BANK hs, headroom */ Word16 -AnalysisPostSpectrumScaling_Fx (HANDLE_CLDFB_FILTER_BANK cldfbBank, /*!< Handle of cldfbBank */ - Word32 **rSubband32, /*!< Real bands */ - Word32 **iSubband32, /*!< Imaginary bands */ - Word16 **rSubband16, /*!< Real bands */ - Word16 **iSubband16, /*!< Imaginary bands */ - Word16 *cldfbScale /*!< CLDFB lowband scalefactor */ - ) +AnalysisPostSpectrumScaling_Fx( HANDLE_CLDFB_FILTER_BANK cldfbBank, /*!< Handle of cldfbBank */ + Word32 **rSubband32, /*!< Real bands */ + Word32 **iSubband32, /*!< Imaginary bands */ + Word16 **rSubband16, /*!< Real bands */ + Word16 **iSubband16, /*!< Imaginary bands */ + Word16 *cldfbScale /*!< CLDFB lowband scalefactor */ +) { Word16 i; Word16 j; Word16 headRoom; + headRoom = BASOP_util_norm_l_dim2_cplx( + (const Word32 *const *) rSubband32, + (const Word32 *const *) iSubband32, + 0, + cldfbBank->no_channels, + 0, + cldfbBank->no_col ); - headRoom = BASOP_util_norm_l_dim2_cplx ( - (const Word32 * const*) rSubband32, - (const Word32 * const*) iSubband32, - 0, - cldfbBank->no_channels, - 0, - cldfbBank->no_col - ); - - FOR (i=0; i < cldfbBank->no_col; i++) + FOR( i = 0; i < cldfbBank->no_col; i++ ) { - FOR (j=0; j < cldfbBank->no_channels; j++) + FOR( j = 0; j < cldfbBank->no_channels; j++ ) { #ifdef BASOP_NOGLOB rSubband16[i][j] = round_fx_sat( L_shl_sat( rSubband32[i][j], headRoom ) ); - iSubband16[i][j] = round_fx_sat(L_shl_sat(iSubband32[i][j], headRoom)); + iSubband16[i][j] = round_fx_sat( L_shl_sat( iSubband32[i][j], headRoom ) ); #else - rSubband16[i][j] = round_fx(L_shl(rSubband32[i][j], headRoom)); - iSubband16[i][j] = round_fx(L_shl(iSubband32[i][j], headRoom)); + rSubband16[i][j] = round_fx( L_shl( rSubband32[i][j], headRoom ) ); + iSubband16[i][j] = round_fx( L_shl( iSubband32[i][j], headRoom ) ); #endif } } - *cldfbScale = add(*cldfbScale,headRoom); + *cldfbScale = add( *cldfbScale, headRoom ); move16(); @@ -1190,13 +1171,13 @@ AnalysisPostSpectrumScaling_Fx (HANDLE_CLDFB_FILTER_BANK cldfbBank, /*!< Handle /*-------------------------------------------------------------------* -* analysisCLDFBEncoder() -* -* Encoder CLDFB analysis + energy stage -*--------------------------------------------------------------------*/ + * analysisCLDFBEncoder() + * + * Encoder CLDFB analysis + energy stage + *--------------------------------------------------------------------*/ void analysisCldfbEncoder_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ + Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 *timeIn, Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], @@ -1204,8 +1185,7 @@ void analysisCldfbEncoder_fx( Word16 imagBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], Word32 enerBuffSum[CLDFB_NO_CHANNELS_MAX], Word16 *enerBuffSum_exp, - CLDFB_SCALE_FACTOR * scale -) + CLDFB_SCALE_FACTOR *scale ) { Word16 i; CLDFB_SCALE_FACTOR enerScale; @@ -1216,7 +1196,7 @@ void analysisCldfbEncoder_fx( Word32 workBuffer[256]; Word16 num_slots = 1; - FOR (i=0; icldfbAnaEnc, ppBuf_Real, ppBuf_Imag, @@ -1233,21 +1213,19 @@ void analysisCldfbEncoder_fx( timeIn, 0, CLDFB_NO_COL_MAX, - workBuffer - ); + workBuffer ); - enerScale.lb_scale = negate(scale->lb_scale); - enerScale.lb_scale16 = negate(scale->lb_scale); + enerScale.lb_scale = negate( scale->lb_scale ); + enerScale.lb_scale16 = negate( scale->lb_scale ); /* get 16bit respresentation */ - AnalysisPostSpectrumScaling_Fx ( + AnalysisPostSpectrumScaling_Fx( st_fx->cldfbAnaEnc, ppBuf_Real, ppBuf_Imag, ppBuf_Real16, ppBuf_Imag16, - &enerScale.lb_scale16 - ); + &enerScale.lb_scale16 ); /* get the energy */ GetEnergyCldfb( &st_fx->energyCoreLookahead_Fx, @@ -1262,27 +1240,24 @@ void analysisCldfbEncoder_fx( &st_fx->currEnergyHF_e_fx, enerBuffSum, enerBuffSum_exp, - st_fx->hTECEnc - ); + st_fx->hTECEnc ); return; } -void -GetEnergyCldfb( Word32 *energyLookahead, /*!< o: Q(*sf_energyLookahead) | pointer to the result in the core look-ahead slot */ - Word16 *sf_energyLookahead, /*!< o: pointer to the scalefactor of the result in the core look-ahead slot */ - const Word16 numLookahead, /*!< i: Q0 the number of look-ahead time-slots */ - Word16 **realValues, /*!< i: Q(sf_Values) | the real part of the CLDFB subsamples */ - Word16 **imagValues, /*!< i: Q(sf_Values) | the imaginary part of the CLDFB subsamples */ - Word16 sf_Values, /*!< i: scalefactor of the CLDFB subcamples - apply as a negated Exponent */ - Word16 numberBands, /*!< i: Q0 | number of CLDFB bands */ - Word16 numberCols, /*!< i: Q0 | number of CLDFB subsamples */ - Word32 *energyHF, /*!< o: Q31 | pointer to HF energy */ - Word16 *energyHF_Exp, /*!< o: pointer to exponent of HF energy */ - Word32 *energyValuesSum, /*!< o: Q(2*sf_Values-4) | pointer to sum array of energy values, not initialized*/ - Word16 *energyValuesSum_Exp,/*!< o: pointer to exponents of energyValuesSum, not initialized */ - TEC_ENC_HANDLE hTecEnc - ) +void GetEnergyCldfb( Word32 *energyLookahead, /*!< o: Q(*sf_energyLookahead) | pointer to the result in the core look-ahead slot */ + Word16 *sf_energyLookahead, /*!< o: pointer to the scalefactor of the result in the core look-ahead slot */ + const Word16 numLookahead, /*!< i: Q0 the number of look-ahead time-slots */ + Word16 **realValues, /*!< i: Q(sf_Values) | the real part of the CLDFB subsamples */ + Word16 **imagValues, /*!< i: Q(sf_Values) | the imaginary part of the CLDFB subsamples */ + Word16 sf_Values, /*!< i: scalefactor of the CLDFB subcamples - apply as a negated Exponent */ + Word16 numberBands, /*!< i: Q0 | number of CLDFB bands */ + Word16 numberCols, /*!< i: Q0 | number of CLDFB subsamples */ + Word32 *energyHF, /*!< o: Q31 | pointer to HF energy */ + Word16 *energyHF_Exp, /*!< o: pointer to exponent of HF energy */ + Word32 *energyValuesSum, /*!< o: Q(2*sf_Values-4) | pointer to sum array of energy values, not initialized*/ + Word16 *energyValuesSum_Exp, /*!< o: pointer to exponents of energyValuesSum, not initialized */ + TEC_ENC_HANDLE hTecEnc ) { Word16 j; Word16 k; @@ -1294,34 +1269,34 @@ GetEnergyCldfb( Word32 *energyLookahead, /*!< o: Q(*sf_energyLookahead) | p Word16 numberBandsM20; Word32 energyValues[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; Word16 energyValuesSumE[CLDFB_NO_CHANNELS_MAX]; - //Word16 freqTable[2] = {20, 40}; + // Word16 freqTable[2] = {20, 40}; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - FOR (k=0; kloBuffer, hTecEnc->hiTempEnv, - ScaleX2 - ); + ScaleX2 ); } - FOR (j=0; j< numberBands; j++) + FOR( j = 0; j < numberBands; j++ ) { - energyValuesSum[j] = L_deposit_l(0); + energyValuesSum[j] = L_deposit_l( 0 ); energyValuesSumE[j] = 31; move16(); - FOR (k=0; k value 0x40000000, scale 44 */ #ifdef BASOP_NOGLOB *energyLookahead = L_add_sat( L_shr_sat( nrg, sub( s, sm ) ), - L_shr_sat(0x40000000, s_max(-31, s_min(31, sub(44, sm))))); + L_shr_sat( 0x40000000, s_max( -31, s_min( 31, sub( 44, sm ) ) ) ) ); #else - *energyLookahead = L_add(L_shr(nrg, sub(s, sm)), - L_shr(0x40000000, s_max(-31, s_min(31, sub(44, sm))))); + *energyLookahead = L_add( L_shr( nrg, sub( s, sm ) ), + L_shr( 0x40000000, s_max( -31, s_min( 31, sub( 44, sm ) ) ) ) ); #endif move32(); BASOP_SATURATE_WARNING_ON_EVS @@ -1433,299 +1407,291 @@ GetEnergyCldfb( Word32 *energyLookahead, /*!< o: Q(*sf_energyLookahead) | p } - *energyHF = 0x40000000; move32(); *energyHF_Exp = 17; move16(); - - } Word16 -CLDFB_getNumChannels(Word32 sampleRate) +CLDFB_getNumChannels( Word32 sampleRate ) { Word16 nChannels = 0; - SWITCH (sampleRate) + SWITCH( sampleRate ) { - case 48000: - move16(); - nChannels = 60; - BREAK; - case 32000: - move16(); - nChannels = 40; - BREAK; - case 25600: - move16(); - nChannels = 32; - BREAK; - case 16000: - move16(); - nChannels = 20; - BREAK; - case 12800: - move16(); - nChannels = 16; - BREAK; - case 8000: - move16(); - nChannels = 10; - BREAK; + case 48000: + move16(); + nChannels = 60; + BREAK; + case 32000: + move16(); + nChannels = 40; + BREAK; + case 25600: + move16(); + nChannels = 32; + BREAK; + case 16000: + move16(); + nChannels = 20; + BREAK; + case 12800: + move16(); + nChannels = 16; + BREAK; + case 8000: + move16(); + nChannels = 10; + BREAK; } - return (nChannels); + return ( nChannels ); } /*-------------------------------------------------------------------* -* cldfb_get_memory_length() -* -* Return length of filter state for recovery -*--------------------------------------------------------------------*/ + * cldfb_get_memory_length() + * + * Return length of filter state for recovery + *--------------------------------------------------------------------*/ static Word16 -cldfb_get_memory_length (HANDLE_CLDFB_FILTER_BANK hs) +cldfb_get_memory_length( HANDLE_CLDFB_FILTER_BANK hs ) { - IF (EQ_16(hs->type,CLDFB_ANALYSIS)) + IF( EQ_16( hs->type, CLDFB_ANALYSIS ) ) { - return (i_mult(hs->no_channels,STATE_BUFFER_SIZE)); + return ( i_mult( hs->no_channels, STATE_BUFFER_SIZE ) ); } ELSE { - return (i_mult(hs->no_channels,(9*2)) ); + return ( i_mult( hs->no_channels, ( 9 * 2 ) ) ); } } /*-------------------------------------------------------------------* -* GetEnergyCldfb() -* -* Remove handle -*--------------------------------------------------------------------*/ -void -deleteCldfb (HANDLE_CLDFB_FILTER_BANK * h_cldfb) /* i: cldfb handle */ + * GetEnergyCldfb() + * + * Remove handle + *--------------------------------------------------------------------*/ +void deleteCldfb( HANDLE_CLDFB_FILTER_BANK *h_cldfb ) /* i: cldfb handle */ { - IF ( *h_cldfb != NULL ) + IF( *h_cldfb != NULL ) { - IF ( (*h_cldfb)->FilterStates != NULL ) + IF( ( *h_cldfb )->FilterStates != NULL ) { - count_free((*h_cldfb)->FilterStates); + count_free( ( *h_cldfb )->FilterStates ); } - count_free(*h_cldfb); + count_free( *h_cldfb ); } *h_cldfb = NULL; } /*-------------------------------------------------------------------* -* cldfb_init_proto_and_twiddles() -* -* Initializes rom pointer -*--------------------------------------------------------------------*/ + * cldfb_init_proto_and_twiddles() + * + * Initializes rom pointer + *--------------------------------------------------------------------*/ static void -cldfb_init_proto_and_twiddles(HANDLE_CLDFB_FILTER_BANK hs) /* i: cldfb handle */ +cldfb_init_proto_and_twiddles( HANDLE_CLDFB_FILTER_BANK hs ) /* i: cldfb handle */ { /*find appropriate set of rotVecs*/ - SWITCH(hs->no_channels) + SWITCH( hs->no_channels ) { - case 10: + case 10: - hs->rRotVctr = rRotVectr_10; - hs->iRotVctr = iRotVectr_10; - hs->synGain = cldfb_synGain[0]; - move16(); - hs->p_filter = cldfb_protoFilter_2_5ms[0]; - hs->scale = cldfb_scale_2_5ms[0]; - move16(); - IF (hs->type == CLDFB_SYNTHESIS ) - { - hs->synScalefactor = add(cldfb_synScale[0],hs->filterScale); + hs->rRotVctr = rRotVectr_10; + hs->iRotVctr = iRotVectr_10; + hs->synGain = cldfb_synGain[0]; move16(); - } - ELSE - { - hs->anaScalefactor = add(cldfb_anaScale[0],hs->filterScale); + hs->p_filter = cldfb_protoFilter_2_5ms[0]; + hs->scale = cldfb_scale_2_5ms[0]; move16(); - } - break; + IF( hs->type == CLDFB_SYNTHESIS ) + { + hs->synScalefactor = add( cldfb_synScale[0], hs->filterScale ); + move16(); + } + ELSE + { + hs->anaScalefactor = add( cldfb_anaScale[0], hs->filterScale ); + move16(); + } + break; - case 16: - hs->rRotVctr = rRotVectr_16; - hs->iRotVctr = iRotVectr_16; - hs->synGain = cldfb_synGain[1]; - move16(); - hs->p_filter = cldfb_protoFilter_2_5ms[1]; - hs->scale = cldfb_scale_2_5ms[1]; - move16(); - { - hs->anaScalefactor = add(cldfb_anaScale[1],hs->filterScale); + case 16: + hs->rRotVctr = rRotVectr_16; + hs->iRotVctr = iRotVectr_16; + hs->synGain = cldfb_synGain[1]; move16(); - } - break; + hs->p_filter = cldfb_protoFilter_2_5ms[1]; + hs->scale = cldfb_scale_2_5ms[1]; + move16(); + { + hs->anaScalefactor = add( cldfb_anaScale[1], hs->filterScale ); + move16(); + } + break; - case 20: - hs->rRotVctr = rRotVectr_20; - hs->iRotVctr = iRotVectr_20; - hs->synGain = cldfb_synGain[2]; - move16(); - hs->p_filter = cldfb_protoFilter_2_5ms[2]; - hs->scale = cldfb_scale_2_5ms[2]; - move16(); - IF (hs->type == CLDFB_SYNTHESIS ) - { - hs->synScalefactor = add(cldfb_synScale[2],hs->filterScale); + case 20: + hs->rRotVctr = rRotVectr_20; + hs->iRotVctr = iRotVectr_20; + hs->synGain = cldfb_synGain[2]; move16(); - } - ELSE - { - hs->anaScalefactor = add(cldfb_anaScale[2],hs->filterScale); + hs->p_filter = cldfb_protoFilter_2_5ms[2]; + hs->scale = cldfb_scale_2_5ms[2]; move16(); - } - break; + IF( hs->type == CLDFB_SYNTHESIS ) + { + hs->synScalefactor = add( cldfb_synScale[2], hs->filterScale ); + move16(); + } + ELSE + { + hs->anaScalefactor = add( cldfb_anaScale[2], hs->filterScale ); + move16(); + } + break; - case 32: - hs->rRotVctr = rRotVectr_32; - hs->iRotVctr = iRotVectr_32; - hs->synGain = cldfb_synGain[3]; - move16(); - hs->p_filter = cldfb_protoFilter_2_5ms[3]; - hs->scale = cldfb_scale_2_5ms[3]; - move16(); - { - hs->anaScalefactor = add(cldfb_anaScale[3],hs->filterScale); + case 32: + hs->rRotVctr = rRotVectr_32; + hs->iRotVctr = iRotVectr_32; + hs->synGain = cldfb_synGain[3]; move16(); - } - break; + hs->p_filter = cldfb_protoFilter_2_5ms[3]; + hs->scale = cldfb_scale_2_5ms[3]; + move16(); + { + hs->anaScalefactor = add( cldfb_anaScale[3], hs->filterScale ); + move16(); + } + break; - case 40: - hs->rRotVctr = rRotVectr_40; - hs->iRotVctr = iRotVectr_40; - hs->synGain = cldfb_synGain[4]; - move16(); - hs->p_filter = cldfb_protoFilter_2_5ms[4]; - hs->scale = cldfb_scale_2_5ms[4]; - move16(); - IF (hs->type == CLDFB_SYNTHESIS ) - { - hs->synScalefactor = add(cldfb_synScale[4],hs->filterScale); + case 40: + hs->rRotVctr = rRotVectr_40; + hs->iRotVctr = iRotVectr_40; + hs->synGain = cldfb_synGain[4]; move16(); - } - ELSE - { - hs->anaScalefactor = add(cldfb_anaScale[4],hs->filterScale); + hs->p_filter = cldfb_protoFilter_2_5ms[4]; + hs->scale = cldfb_scale_2_5ms[4]; move16(); - } - break; + IF( hs->type == CLDFB_SYNTHESIS ) + { + hs->synScalefactor = add( cldfb_synScale[4], hs->filterScale ); + move16(); + } + ELSE + { + hs->anaScalefactor = add( cldfb_anaScale[4], hs->filterScale ); + move16(); + } + break; - case 60: - hs->rRotVctr = rRotVectr_60; - hs->iRotVctr = iRotVectr_60; - hs->synGain = cldfb_synGain[5]; - move16(); - hs->p_filter = cldfb_protoFilter_2_5ms[5]; - hs->scale = cldfb_scale_2_5ms[5]; - move16(); - IF (hs->type == CLDFB_SYNTHESIS ) - { - hs->synScalefactor = add(cldfb_synScale[5],hs->filterScale); + case 60: + hs->rRotVctr = rRotVectr_60; + hs->iRotVctr = iRotVectr_60; + hs->synGain = cldfb_synGain[5]; move16(); - } - ELSE - { - hs->anaScalefactor = add(cldfb_anaScale[5],hs->filterScale); + hs->p_filter = cldfb_protoFilter_2_5ms[5]; + hs->scale = cldfb_scale_2_5ms[5]; move16(); - } - break; - + IF( hs->type == CLDFB_SYNTHESIS ) + { + hs->synScalefactor = add( cldfb_synScale[5], hs->filterScale ); + move16(); + } + ELSE + { + hs->anaScalefactor = add( cldfb_anaScale[5], hs->filterScale ); + move16(); + } + break; } } -#define CLDFB_MEM_EXPONENTS (CLDFB_NO_COL_MAX+9) +#define CLDFB_MEM_EXPONENTS ( CLDFB_NO_COL_MAX + 9 ) /*-------------------------------------------------------------------* -* cldfb_save_memory() -* -* Save the memory of filter; to be restored with cldfb_restore_memory() -*--------------------------------------------------------------------*/ + * cldfb_save_memory() + * + * Save the memory of filter; to be restored with cldfb_restore_memory() + *--------------------------------------------------------------------*/ ivas_error -cldfb_save_memory (HANDLE_CLDFB_FILTER_BANK hs) /* i: cldfb handle */ +cldfb_save_memory( HANDLE_CLDFB_FILTER_BANK hs ) /* i: cldfb handle */ { - if (hs->memory != NULL || hs->memory_length != 0) + if ( hs->memory != NULL || hs->memory_length != 0 ) { /* memory already stored; Free memory first */ return IVAS_ERR_OK; } - hs->memory_length = cldfb_get_memory_length(hs); - hs->memory = (Word16 *) calloc( hs->memory_length + CLDFB_MEM_EXPONENTS + 1, sizeof (Word16)); + hs->memory_length = cldfb_get_memory_length( hs ); + hs->memory = (Word16 *) calloc( hs->memory_length + CLDFB_MEM_EXPONENTS + 1, sizeof( Word16 ) ); /* save the memory */ - Copy (hs->FilterStates, hs->memory, hs->memory_length); - Copy (hs->FilterStates_e, hs->memory+hs->memory_length, CLDFB_MEM_EXPONENTS); - hs->memory[hs->memory_length+CLDFB_MEM_EXPONENTS] = hs->FilterStates_eg; + Copy( hs->FilterStates, hs->memory, hs->memory_length ); + Copy( hs->FilterStates_e, hs->memory + hs->memory_length, CLDFB_MEM_EXPONENTS ); + hs->memory[hs->memory_length + CLDFB_MEM_EXPONENTS] = hs->FilterStates_eg; move16(); - if (hs->memory == NULL) + if ( hs->memory == NULL ) { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CLDFB\n"); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CLDFB\n" ); } return IVAS_ERR_OK; } /*-------------------------------------------------------------------* -* cldfb_restore_memory() -* -* Restores the memory of filter; memory to be save by cldfb_save_memory() -*--------------------------------------------------------------------*/ -void -cldfb_restore_memory (HANDLE_CLDFB_FILTER_BANK hs) /* i/o: cldfb handle */ + * cldfb_restore_memory() + * + * Restores the memory of filter; memory to be save by cldfb_save_memory() + *--------------------------------------------------------------------*/ +void cldfb_restore_memory( HANDLE_CLDFB_FILTER_BANK hs ) /* i/o: cldfb handle */ { Word16 size; - size = cldfb_get_memory_length(hs); + size = cldfb_get_memory_length( hs ); /* read the memory */ - Copy (hs->memory, hs->FilterStates, hs->memory_length); - Copy (hs->memory+hs->memory_length, hs->FilterStates_e, CLDFB_MEM_EXPONENTS); - hs->FilterStates_eg = hs->memory[hs->memory_length+CLDFB_MEM_EXPONENTS]; + Copy( hs->memory, hs->FilterStates, hs->memory_length ); + Copy( hs->memory + hs->memory_length, hs->FilterStates_e, CLDFB_MEM_EXPONENTS ); + hs->FilterStates_eg = hs->memory[hs->memory_length + CLDFB_MEM_EXPONENTS]; move16(); /* adjust sample rate if it was changed in the meanwhile */ - IF (NE_16 (hs->memory_length,size)) + IF( NE_16( hs->memory_length, size ) ) { - lerp(hs->FilterStates, hs->FilterStates, size, hs->memory_length); + lerp( hs->FilterStates, hs->FilterStates, size, hs->memory_length ); } hs->memory_length = 0; - count_free(hs->memory); + count_free( hs->memory ); hs->memory = NULL; return; } /*-------------------------------------------------------------------* -* cldfb_reset_memory() -* -* Resets the memory of filter. -*--------------------------------------------------------------------*/ -void -cldfb_reset_memory (HANDLE_CLDFB_FILTER_BANK hs) /* i/o: cldfb handle */ + * cldfb_reset_memory() + * + * Resets the memory of filter. + *--------------------------------------------------------------------*/ +void cldfb_reset_memory( HANDLE_CLDFB_FILTER_BANK hs ) /* i/o: cldfb handle */ { Word16 length; - length = cldfb_get_memory_length(hs); + length = cldfb_get_memory_length( hs ); /* erase the memory */ - set16_fx (hs->FilterStates, 0, length); - set16_fx (hs->FilterStates_e, 0, sizeof(hs->FilterStates_e)/sizeof(hs->FilterStates_e[0])); + set16_fx( hs->FilterStates, 0, length ); + set16_fx( hs->FilterStates_e, 0, sizeof( hs->FilterStates_e ) / sizeof( hs->FilterStates_e[0] ) ); hs->FilterStates_eg = 0; move16(); return; } - diff --git a/lib_com/cng_exc_fx.c b/lib_com/cng_exc_fx.c index 42c28af9e..e8e69432f 100644 --- a/lib_com/cng_exc_fx.c +++ b/lib_com/cng_exc_fx.c @@ -2,18 +2,18 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ #include "rom_com.h" #include "ivas_rom_com_fx.h" /*---------------------------------------------------------------------* * Local constants *---------------------------------------------------------------------*/ -#define A2 6554 -#define OmA2 (32768-A2) +#define A2 6554 +#define OmA2 ( 32768 - A2 ) #define GAIN_VAR 11811 /* in Q31 divided by 2 (Q30) */ const Word16 att_pow_tbl[SIZE_SCALE_TABLE_STEREO + 1] = { 9234, 10361, 13044, 16422, 22669, 31292, 32767, 26634, 28212, 20674, 16422, 27254, 30934, 32767 }; /*-------------------------------------------------------* @@ -23,22 +23,22 @@ const Word16 att_pow_tbl[SIZE_SCALE_TABLE_STEREO + 1] = { 9234, 10361, 13044, 16 *-------------------------------------------------------*/ void CNG_exc_fx( - const Word32 core_brate, /* i : core bitrate */ - const Word16 L_frame, /* i : length of the frame */ - Word32 *Enew, /* i/o: decoded SID energy Q6 */ - Word16 *seed, /* i/o: random generator seed */ - Word16 exc[], /* o : current non-enhanced excitation Q_new */ - Word16 exc2[], /* o : current enhanced excitation Q_new */ - Word32 *lp_ener, /* i/o: LP filtered E */ - const Word32 last_core_brate,/* i : previous frame core bitrate */ - Word16 *first_CNG, /* i/o: first CNG frame flag for energy init. */ - Word16 *cng_ener_seed, /* i/o: random generator seed for CNG energy */ - Word16 bwe_exc[], /* o : excitation for SWB TBE */ - const Word16 allow_cn_step, /* i : allow CN step */ - Word16 *last_allow_cn_step, /* i/o: last allow step */ - const Word16 OldQ_exc, /* i : Old excitation scaling */ - const Word16 Q_exc, /* i : excitation scaling */ - const Word16 num_ho, /* i : number of selected hangover frames */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 L_frame, /* i : length of the frame */ + Word32 *Enew, /* i/o: decoded SID energy Q6 */ + Word16 *seed, /* i/o: random generator seed */ + Word16 exc[], /* o : current non-enhanced excitation Q_new */ + Word16 exc2[], /* o : current enhanced excitation Q_new */ + Word32 *lp_ener, /* i/o: LP filtered E */ + const Word32 last_core_brate, /* i : previous frame core bitrate */ + Word16 *first_CNG, /* i/o: first CNG frame flag for energy init. */ + Word16 *cng_ener_seed, /* i/o: random generator seed for CNG energy */ + Word16 bwe_exc[], /* o : excitation for SWB TBE */ + const Word16 allow_cn_step, /* i : allow CN step */ + Word16 *last_allow_cn_step, /* i/o: last allow step */ + const Word16 OldQ_exc, /* i : Old excitation scaling */ + const Word16 Q_exc, /* i : excitation scaling */ + const Word16 num_ho, /* i : number of selected hangover frames */ Word32 q_env[], Word32 *lp_env, Word32 *old_env, @@ -55,8 +55,8 @@ void CNG_exc_fx( Word32 L_tmp_ener, L_tmp; Word16 i_subfr; Word16 pit_max; - Word16 ftmp,j; - Word16 *ptR,*ptI; + Word16 ftmp, j; + Word16 *ptR, *ptI; Word16 fft_io[L_FRAME16k]; Word32 itmp[129]; Word32 env[NUM_ENV_CNG]; @@ -74,7 +74,7 @@ void CNG_exc_fx( pit_max = PIT16k_MAX; move16(); - if( EQ_16(L_frame,L_FRAME)) + if ( EQ_16( L_frame, L_FRAME ) ) { pit_max = PIT_MAX; move16(); @@ -84,25 +84,25 @@ void CNG_exc_fx( * Initialization of CNG energy for the first CNG frame *---------------------------------------------------------------------*/ - IF(*first_CNG == 0 ) + IF( *first_CNG == 0 ) { - IF(EQ_32(core_brate,FRAME_NO_DATA)) + IF( EQ_32( core_brate, FRAME_NO_DATA ) ) { /* needed only in decoder when the very first SID frame was erased and this frame is FRAME_NO_DATA frame */ /*fenew = dotp( fexc, fexc, pit_max )/pit_max;*/ - L_tmp_ener = Calc_Energy_Autoscaled(exc-pit_max, OldQ_exc, pit_max, &Q_ener); - L_tmp_ener = Mult_32_16(L_tmp_ener, 9079); /* divide by PIT_MAX (in Q15 + Q6 to get output in Q6)*/ - L_tmp_ener = L_shr(L_tmp_ener, Q_ener); /* -> If we want ener in Q6 */ + L_tmp_ener = Calc_Energy_Autoscaled( exc - pit_max, OldQ_exc, pit_max, &Q_ener ); + L_tmp_ener = Mult_32_16( L_tmp_ener, 9079 ); /* divide by PIT_MAX (in Q15 + Q6 to get output in Q6)*/ + L_tmp_ener = L_shr( L_tmp_ener, Q_ener ); /* -> If we want ener in Q6 */ - if(EQ_16(L_frame, L_FRAME16k)) + if ( EQ_16( L_frame, L_FRAME16k ) ) { - L_tmp_ener = Mult_32_16(L_tmp_ener, 26214); /* Compensate for 16kHz */ + L_tmp_ener = Mult_32_16( L_tmp_ener, 26214 ); /* Compensate for 16kHz */ } *Enew = L_tmp_ener; move32(); } - if (EQ_16(element_mode, EVS_MONO)) + if ( EQ_16( element_mode, EVS_MONO ) ) { *lp_ener = *Enew; move32(); @@ -114,532 +114,528 @@ void CNG_exc_fx( *---------------------------------------------------------------------*/ test(); test(); - IF( NE_32(last_core_brate,SID_1k75)&&NE_32(last_core_brate,FRAME_NO_DATA)&&NE_32(last_core_brate,SID_2k40)) + IF( NE_32( last_core_brate, SID_1k75 ) && NE_32( last_core_brate, FRAME_NO_DATA ) && NE_32( last_core_brate, SID_2k40 ) ) { /* Partially reset CNG energy after active speech period */ test(); - IF ( allow_cn_step == 0 && *last_allow_cn_step == 0 ) + IF( allow_cn_step == 0 && *last_allow_cn_step == 0 ) { test(); - IF( LT_16(num_ho,3)||LT_32(Mult_32_16(*Enew,21845/*1/1.5f, Q15*/),*lp_ener)) + IF( LT_16( num_ho, 3 ) || LT_32( Mult_32_16( *Enew, 21845 /*1/1.5f, Q15*/ ), *lp_ener ) ) { /**lp_ener = 0.8f * *lp_ener + 0.2f * *Enew;*/ - L_tmp_ener = Mult_32_16(*lp_ener, 26214); - L_tmp_ener = Madd_32_16(L_tmp_ener, *Enew, 6554); - + L_tmp_ener = Mult_32_16( *lp_ener, 26214 ); + L_tmp_ener = Madd_32_16( L_tmp_ener, *Enew, 6554 ); } ELSE { /**lp_ener = 0.95f * *lp_ener + 0.05f * *Enew;*/ - L_tmp_ener = Mult_32_16(*lp_ener, 31130); - L_tmp_ener = Madd_32_16(L_tmp_ener, *Enew, 1638); + L_tmp_ener = Mult_32_16( *lp_ener, 31130 ); + L_tmp_ener = Madd_32_16( L_tmp_ener, *Enew, 1638 ); } } ELSE { L_tmp_ener = *Enew; - move32(); + move32(); *last_allow_cn_step = 0; move16(); } } - ELSE - { + ELSE{ /* normal CNG update */ - IF ( *last_allow_cn_step == 0 ) - { + IF( *last_allow_cn_step == 0 ){ /**lp_ener = (float)(A2 * *Enew + (1-A2) * *lp_ener);*/ - L_tmp_ener = Mult_32_16(*Enew, A2); - L_tmp_ener = Madd_32_16(L_tmp_ener, *lp_ener, OmA2); - } - ELSE - { - test(); - if ( EQ_32(core_brate,SID_1k75)||EQ_32(core_brate,SID_2k40)) - { - *last_allow_cn_step = 0; - move16(); - } - - L_tmp_ener = *Enew; - move32(); - - } - } - *lp_ener = L_max(L_tmp_ener,1); - move32(); /*To avoid / per 0*/ - - if ( EQ_16(allow_cn_step,1)) + L_tmp_ener = Mult_32_16( *Enew, A2 ); + L_tmp_ener = Madd_32_16( L_tmp_ener, *lp_ener, OmA2 ); +} +ELSE +{ + test(); + if ( EQ_32( core_brate, SID_1k75 ) || EQ_32( core_brate, SID_2k40 ) ) { - *last_allow_cn_step = 1; + *last_allow_cn_step = 0; move16(); } - /* If not mono, skip CNG here */ - if (GT_16(element_mode, IVAS_SCE)) - { - return; - } - /*---------------------------------------------------------------------* - * Generate white noise vector - *---------------------------------------------------------------------*/ - /*for ( i=0; i Q_exc +16 */ + FOR( i = 0; i < L_SUBFR; i++ ) + { + /* exc2[i] *= enr */ + L_tmp = L_mult( exc2[i_subfr + i], tmp ); /* Q-4 * Q_exc+19 -> Q_exc +16 */ #ifdef BASOP_NOGLOB - exc2[i_subfr+i] = round_fx_sat(L_shl_sat(L_tmp, exp)); + exc2[i_subfr + i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); #else - exc2[i_subfr+i] = round_fx(L_shl(L_tmp, exp)); + exc2[i_subfr + i] = round_fx( L_shl( L_tmp, exp ) ); #endif - } } - IF ( NE_16(Opt_AMR_WB,1)) - { - Copy( exc2, exc3, L_FRAME16k); +} +IF( NE_16( Opt_AMR_WB, 1 ) ) +{ + Copy( exc2, exc3, L_FRAME16k ); - /* enr1 = (float)log10( *Enew*L_frame + 0.1f ) / (float)log10( 2.0f ); */ - exp = norm_l(*Enew); - L_tmp = L_shl(*Enew,exp); /* Q(exp+6) */ - L_tmp = Mult_32_16(L_tmp,shl(L_frame,5)); /* Q(exp+6+5-15=exp-4) */ + /* enr1 = (float)log10( *Enew*L_frame + 0.1f ) / (float)log10( 2.0f ); */ + exp = norm_l( *Enew ); + L_tmp = L_shl( *Enew, exp ); /* Q(exp+6) */ + L_tmp = Mult_32_16( L_tmp, shl( L_frame, 5 ) ); /* Q(exp+6+5-15=exp-4) */ #ifdef BASOP_NOGLOB - L_tmp = L_shr_sat( L_tmp, sub( exp, 10 ) ); /* Q6 */ + L_tmp = L_shr_sat( L_tmp, sub( exp, 10 ) ); /* Q6 */ #else - L_tmp = L_shr( L_tmp, sub( exp, 10 ) ); /* Q6 */ + L_tmp = L_shr( L_tmp, sub( exp, 10 ) ); /* Q6 */ #endif - exp = norm_l(L_tmp); - fra = Log2_norm_lc(L_shl(L_tmp,exp)); - exp = sub(sub(30,exp),6); - L_tmp = L_Comp(exp,fra); - /* enr1 = round_fx(L_shl(L_tmp,8)); */ /*Q8 */ - enr1 = L_shr(L_tmp,10);/* Q6 */ + exp = norm_l( L_tmp ); + fra = Log2_norm_lc( L_shl( L_tmp, exp ) ); + exp = sub( sub( 30, exp ), 6 ); + L_tmp = L_Comp( exp, fra ); + /* enr1 = round_fx(L_shl(L_tmp,8)); */ /*Q8 */ + enr1 = L_shr( L_tmp, 10 ); /* Q6 */ - IF ( EQ_32(core_brate,SID_2k40)) + IF( EQ_32( core_brate, SID_2k40 ) ) + { + IF( *sid_bw == 0 ) { - IF ( *sid_bw == 0 ) - { - FOR ( i=0; i @@ -16,213 +16,214 @@ #define inv_int InvIntTable Word16 tcxGetNoiseFillingTilt( - const Word16 A[], - const Word16 lpcorder, - const Word16 L_frame, - const Word16 mode, - Word16 *noiseTiltFactor -) + const Word16 A[], + const Word16 lpcorder, + const Word16 L_frame, + const Word16 mode, + Word16 *noiseTiltFactor ) { - Word16 firstLine; - Word32 tmp; - Word16 As[M + 1]; - - - IF(mode != 0) - { - firstLine = idiv1616U(L_frame, 6); - *noiseTiltFactor = 18432/*0.5625f Q15*/; - move16(); - } - ELSE - { - firstLine = shr(L_frame, 3); - - Copy_Scale_sig(A, As, lpcorder + 1, sub(norm_s(A[0]),2)); - tmp = get_gain(As + 1, As, lpcorder); - BASOP_SATURATE_WARNING_OFF_EVS; + Word16 firstLine; + Word32 tmp; + Word16 As[M + 1]; + + + IF( mode != 0 ) + { + firstLine = idiv1616U( L_frame, 6 ); + *noiseTiltFactor = 18432 /*0.5625f Q15*/; + move16(); + } + ELSE + { + firstLine = shr( L_frame, 3 ); + + Copy_Scale_sig( A, As, lpcorder + 1, sub( norm_s( A[0] ), 2 ) ); + tmp = get_gain( As + 1, As, lpcorder ); + BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB *noiseTiltFactor = add_sat( round_fx_sat( L_shl_sat( tmp, 15 ) ), 3072 /*0.09375f Q15*/ ); #else - *noiseTiltFactor = add(round_fx(L_shl(tmp, 15)), 3072/*0.09375f Q15*/); + *noiseTiltFactor = add( round_fx( L_shl( tmp, 15 ) ), 3072 /*0.09375f Q15*/ ); #endif - move16(); - BASOP_SATURATE_WARNING_ON_EVS; - } + move16(); + BASOP_SATURATE_WARNING_ON_EVS; + } - return firstLine; + return firstLine; } void tcxFormantEnhancement( - Word16 xn_buf[], - const Word16 gainlpc[], - const Word16 gainlpc_e[], - Word32 spectrum[], - Word16 *spectrum_e, - const Word16 L_frame, - const Word16 L_frameTCX -) + Word16 xn_buf[], + const Word16 gainlpc[], + const Word16 gainlpc_e[], + Word32 spectrum[], + Word16 *spectrum_e, + const Word16 L_frame, + const Word16 L_frameTCX ) { - Word16 i, j, k, l, n; - Word16 fac, fac0, fac1, fac_e, d, tmp; - Word16 xn_buf_e, xn_one, m, e; + Word16 i, j, k, l, n; + Word16 fac, fac0, fac1, fac_e, d, tmp; + Word16 xn_buf_e, xn_one, m, e; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; + Flag Overflow = 0; #endif - k = shr(L_frame, 6); /* FDNS_NPTS = 64 */ - l = 0; - move16(); - - /* get exponent */ - xn_buf_e = 0; - move16(); - FOR(i = 0; i < FDNS_NPTS; i++) - { - xn_buf_e = s_max(xn_buf_e, gainlpc_e[i]); - } - xn_buf_e = shr(add(xn_buf_e, 1), 1); /* max exponent after sqrt */ - xn_one = shr(0x4000, sub(xn_buf_e, 1)); /* 1.0 scaled to xn_buf_e */ - - /* Formant enhancement via square root of the LPC gains */ - e = gainlpc_e[0]; - move16(); - m = Sqrt16(gainlpc[0], &e); - xn_buf[0] = shl(m, sub(e, xn_buf_e)); - move16(); - - e = gainlpc_e[1]; - move16(); - m = Sqrt16(gainlpc[1], &e); - xn_buf[1] = shl(m, sub(e, xn_buf_e)); - move16(); - - fac0 = s_min(xn_buf[0], xn_buf[1]); - fac_e = xn_buf_e; - move16(); - fac0 = Inv16(fac0, &fac_e); - - FOR(i = 1; i < FDNS_NPTS - 1; i++) - { - e = gainlpc_e[i + 1]; - move16(); - m = Sqrt16(gainlpc[i + 1], &e); - xn_buf[i + 1] = shl(m, sub(e, xn_buf_e)); - move16(); - - test(); - IF((LE_16(xn_buf[i - 1], xn_buf[i])) && (LE_16(xn_buf[i + 1], xn_buf[i]))) - { - m = s_max(xn_buf[i - 1], xn_buf[i + 1]); - e = xn_buf_e; - move16(); - m = Inv16(m, &e); - - fac1 = m; - move16(); - tmp = sub(e, fac_e); - - if (tmp > 0) fac0 = shr(fac0, tmp); - if (tmp < 0) fac1 = shl(fac1, tmp); - - if (tmp > 0) - { - fac_e = e; - move16(); - } - - d = sub(fac1, fac0); - n = sub(i, l); - assert(n <= 64); - - xn_buf[l] = xn_one; - move16(); - FOR(j = 1; j < n; j++) - { - fac = add(fac0, mult(d, extract_l(L_mult0(j, inv_int[n])))); - BASOP_SATURATE_WARNING_OFF_EVS; + k = shr( L_frame, 6 ); /* FDNS_NPTS = 64 */ + l = 0; + move16(); + + /* get exponent */ + xn_buf_e = 0; + move16(); + FOR( i = 0; i < FDNS_NPTS; i++ ) + { + xn_buf_e = s_max( xn_buf_e, gainlpc_e[i] ); + } + xn_buf_e = shr( add( xn_buf_e, 1 ), 1 ); /* max exponent after sqrt */ + xn_one = shr( 0x4000, sub( xn_buf_e, 1 ) ); /* 1.0 scaled to xn_buf_e */ + + /* Formant enhancement via square root of the LPC gains */ + e = gainlpc_e[0]; + move16(); + m = Sqrt16( gainlpc[0], &e ); + xn_buf[0] = shl( m, sub( e, xn_buf_e ) ); + move16(); + + e = gainlpc_e[1]; + move16(); + m = Sqrt16( gainlpc[1], &e ); + xn_buf[1] = shl( m, sub( e, xn_buf_e ) ); + move16(); + + fac0 = s_min( xn_buf[0], xn_buf[1] ); + fac_e = xn_buf_e; + move16(); + fac0 = Inv16( fac0, &fac_e ); + + FOR( i = 1; i < FDNS_NPTS - 1; i++ ) + { + e = gainlpc_e[i + 1]; + move16(); + m = Sqrt16( gainlpc[i + 1], &e ); + xn_buf[i + 1] = shl( m, sub( e, xn_buf_e ) ); + move16(); + + test(); + IF( ( LE_16( xn_buf[i - 1], xn_buf[i] ) ) && ( LE_16( xn_buf[i + 1], xn_buf[i] ) ) ) + { + m = s_max( xn_buf[i - 1], xn_buf[i + 1] ); + e = xn_buf_e; + move16(); + m = Inv16( m, &e ); + + fac1 = m; + move16(); + tmp = sub( e, fac_e ); + + if ( tmp > 0 ) + fac0 = shr( fac0, tmp ); + if ( tmp < 0 ) + fac1 = shl( fac1, tmp ); + + if ( tmp > 0 ) + { + fac_e = e; + move16(); + } + + d = sub( fac1, fac0 ); + n = sub( i, l ); + assert( n <= 64 ); + + xn_buf[l] = xn_one; + move16(); + FOR( j = 1; j < n; j++ ) + { + fac = add( fac0, mult( d, extract_l( L_mult0( j, inv_int[n] ) ) ) ); + BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB - xn_buf[l + j] = s_min(xn_one, shl_o(mult(xn_buf[l + j], fac), fac_e, &Overflow)); + xn_buf[l + j] = s_min( xn_one, shl_o( mult( xn_buf[l + j], fac ), fac_e, &Overflow ) ); #else - xn_buf[l + j] = s_min(xn_one, shl(mult(xn_buf[l + j], fac), fac_e)); + xn_buf[l + j] = s_min( xn_one, shl( mult( xn_buf[l + j], fac ), fac_e ) ); #endif - move16(); - BASOP_SATURATE_WARNING_ON_EVS; - } - - l = i; - move16(); - - fac0 = m; - move16(); - fac_e = e; - move16(); - } - } - /* i = FDNS_NPTS - 1; Completing changes to gains */ - m = s_min(xn_buf[i - 1], xn_buf[i]); - e = xn_buf_e; - move16(); - m = Inv16(m, &e); - - fac1 = m; - move16(); - tmp = sub(e, fac_e); - - if (tmp > 0) fac0 = shr(fac0, tmp); - if (tmp < 0) fac1 = shl(fac1, tmp); - - if (tmp > 0) - { - fac_e = e; - move16(); - } - - d = sub(fac1, fac0); - n = sub(i, l); - assert(n <= 64); - - xn_buf[l] = xn_one; - move16(); - FOR(j = 1; j < n; j++) - { - fac = add(fac0, mult(d, extract_l(L_mult0(j, inv_int[n])))); - BASOP_SATURATE_WARNING_OFF_EVS; + move16(); + BASOP_SATURATE_WARNING_ON_EVS; + } + + l = i; + move16(); + + fac0 = m; + move16(); + fac_e = e; + move16(); + } + } + /* i = FDNS_NPTS - 1; Completing changes to gains */ + m = s_min( xn_buf[i - 1], xn_buf[i] ); + e = xn_buf_e; + move16(); + m = Inv16( m, &e ); + + fac1 = m; + move16(); + tmp = sub( e, fac_e ); + + if ( tmp > 0 ) + fac0 = shr( fac0, tmp ); + if ( tmp < 0 ) + fac1 = shl( fac1, tmp ); + + if ( tmp > 0 ) + { + fac_e = e; + move16(); + } + + d = sub( fac1, fac0 ); + n = sub( i, l ); + assert( n <= 64 ); + + xn_buf[l] = xn_one; + move16(); + FOR( j = 1; j < n; j++ ) + { + fac = add( fac0, mult( d, extract_l( L_mult0( j, inv_int[n] ) ) ) ); + BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB xn_buf[l + j] = s_min( xn_one, shl_sat( mult( xn_buf[l + j], fac ), fac_e ) ); #else - xn_buf[l + j] = s_min(xn_one, shl(mult(xn_buf[l + j], fac), fac_e)); + xn_buf[l + j] = s_min( xn_one, shl( mult( xn_buf[l + j], fac ), fac_e ) ); #endif - move16(); - BASOP_SATURATE_WARNING_ON_EVS; - } - - xn_buf[i] = xn_one; - move16(); - - /* Application of changed gains onto decoded MDCT lines */ - FOR(i = 0; i < L_frame; i += k) - { - FOR(l = 0; l < k; l++) - { - *spectrum = Mpy_32_16_1(*spectrum, *xn_buf); - move32(); - spectrum++; - } - xn_buf++; - } - - tmp = sub(L_frameTCX, L_frame); - FOR(i = 0; i < tmp; i++) - { - spectrum[i] = L_shr(spectrum[i], xn_buf_e); - move32(); - } - *spectrum_e = add(*spectrum_e, xn_buf_e); - move16(); + move16(); + BASOP_SATURATE_WARNING_ON_EVS; + } + xn_buf[i] = xn_one; + move16(); + + /* Application of changed gains onto decoded MDCT lines */ + FOR( i = 0; i < L_frame; i += k ) + { + FOR( l = 0; l < k; l++ ) + { + *spectrum = Mpy_32_16_1( *spectrum, *xn_buf ); + move32(); + spectrum++; + } + xn_buf++; + } + + tmp = sub( L_frameTCX, L_frame ); + FOR( i = 0; i < tmp; i++ ) + { + spectrum[i] = L_shr( spectrum[i], xn_buf_e ); + move32(); + } + *spectrum_e = add( *spectrum_e, xn_buf_e ); + move16(); } void tcxFormantEnhancement_with_shift( @@ -298,12 +299,12 @@ void tcxFormantEnhancement_with_shift( { fac0 = shr( fac0, tmp ); } - IF ( LT_16( tmp, 0 ) ) + IF( LT_16( tmp, 0 ) ) { fac1 = shl( fac1, tmp ); } - IF ( GT_16( tmp, 0 ) ) + IF( GT_16( tmp, 0 ) ) { fac_e = e; move16(); @@ -369,7 +370,7 @@ void tcxFormantEnhancement_with_shift( fac = add( fac0, mult( d, extract_l( L_mult0( j, inv_int[n] ) ) ) ); BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB - xn_buf[l + j] = s_min( xn_one, shl_o( mult( xn_buf[l + j], fac ), fac_e, &Overflow )); + xn_buf[l + j] = s_min( xn_one, shl_o( mult( xn_buf[l + j], fac ), fac_e, &Overflow ) ); #else xn_buf[l + j] = s_min( xn_one, shl( mult( xn_buf[l + j], fac ), fac_e ) ); #endif @@ -406,82 +407,85 @@ void tcxFormantEnhancement_with_shift( } void tcxInvertWindowGrouping( - TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */ - Word32 xn_buf[], - Word32 spectrum[], - const Word16 L_frame, - const Word8 fUseTns, - const Word16 last_core, - const Word16 index, - const Word16 frame_cnt, - const Word16 bfi -) + TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */ + Word32 xn_buf[], + Word32 spectrum[], + const Word16 L_frame, + const Word8 fUseTns, + const Word16 last_core, + const Word16 index, + const Word16 frame_cnt, + const Word16 bfi ) { - Word16 i, L_win, L_spec; - Word32 *p; - - - L_win = shr(L_frame, 1); - L_spec = hTcxCfg->tnsConfig[0][0].iFilterBorders[0]; - move16(); - - test(); - test(); - if ((frame_cnt != 0) && (bfi == 0) && NE_16(last_core, ACELP_CORE)) /* fix sub-window overlap */ - { - hTcxCfg->tcx_last_overlap_mode = hTcxCfg->tcx_curr_overlap_mode; - move16(); - } - test(); test(); test(); test(); test(); test(); test(); - IF(((bfi == 0) && ((hTcxCfg->tcx_last_overlap_mode != FULL_OVERLAP) || - ((hTcxCfg->tcx_curr_overlap_mode == FULL_OVERLAP) && (frame_cnt == 0) && (index == 0)))) - || - ((bfi != 0) && ((hTcxCfg->tcx_last_overlap_mode != FULL_OVERLAP) && - !(hTcxCfg->tcx_curr_overlap_mode == FULL_OVERLAP)))) - { - /* ungroup sub-windows: deinterleave MDCT bins into separate windows */ - p = xn_buf; - FOR(i = 1; i < L_win; i += 2) - { - *p++ = spectrum[i]; - move32(); - } - - p = spectrum; - FOR(i = 0; i < L_frame; i += 2) - { - *p++ = spectrum[i]; - move32(); - } - - p = spectrum + L_frame - 1; - FOR(i = sub(L_frame, 1); i > L_win; i -= 2) - { - *p-- = spectrum[i]; - move32(); - } - Copy32(xn_buf, spectrum + L_win, shr(L_win, 1)); - - test(); - test(); - IF((hTcxCfg->fIsTNSAllowed != 0) && (bfi == 0) && (fUseTns != 0)) - { - /* rearrange LF sub-window lines prior to TNS synthesis filtering */ - IF(LT_16(L_spec, L_frame)) - { - Copy32(spectrum + 8, spectrum + 16, sub(shr(L_spec, 1), 8)); - Copy32(spectrum + L_frame / 2, spectrum + 8, 8); - Copy32(spectrum + L_frame / 2 + 8, spectrum + L_spec / 2 + 8, sub(shr(L_spec, 1), 8)); - } - ELSE - { - Copy32(spectrum + L_win, xn_buf, 8); - Copy32(spectrum + 8, spectrum + 16, sub(L_win, 8)); - Copy32(xn_buf, spectrum + 8, 8); - } - } - } + Word16 i, L_win, L_spec; + Word32 *p; + + + L_win = shr( L_frame, 1 ); + L_spec = hTcxCfg->tnsConfig[0][0].iFilterBorders[0]; + move16(); + test(); + test(); + if ( ( frame_cnt != 0 ) && ( bfi == 0 ) && NE_16( last_core, ACELP_CORE ) ) /* fix sub-window overlap */ + { + hTcxCfg->tcx_last_overlap_mode = hTcxCfg->tcx_curr_overlap_mode; + move16(); + } + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( ( bfi == 0 ) && ( ( hTcxCfg->tcx_last_overlap_mode != FULL_OVERLAP ) || + ( ( hTcxCfg->tcx_curr_overlap_mode == FULL_OVERLAP ) && ( frame_cnt == 0 ) && ( index == 0 ) ) ) ) || + ( ( bfi != 0 ) && ( ( hTcxCfg->tcx_last_overlap_mode != FULL_OVERLAP ) && + !( hTcxCfg->tcx_curr_overlap_mode == FULL_OVERLAP ) ) ) ) + { + /* ungroup sub-windows: deinterleave MDCT bins into separate windows */ + p = xn_buf; + FOR( i = 1; i < L_win; i += 2 ) + { + *p++ = spectrum[i]; + move32(); + } + + p = spectrum; + FOR( i = 0; i < L_frame; i += 2 ) + { + *p++ = spectrum[i]; + move32(); + } + + p = spectrum + L_frame - 1; + FOR( i = sub( L_frame, 1 ); i > L_win; i -= 2 ) + { + *p-- = spectrum[i]; + move32(); + } + Copy32( xn_buf, spectrum + L_win, shr( L_win, 1 ) ); + + test(); + test(); + IF( ( hTcxCfg->fIsTNSAllowed != 0 ) && ( bfi == 0 ) && ( fUseTns != 0 ) ) + { + /* rearrange LF sub-window lines prior to TNS synthesis filtering */ + IF( LT_16( L_spec, L_frame ) ) + { + Copy32( spectrum + 8, spectrum + 16, sub( shr( L_spec, 1 ), 8 ) ); + Copy32( spectrum + L_frame / 2, spectrum + 8, 8 ); + Copy32( spectrum + L_frame / 2 + 8, spectrum + L_spec / 2 + 8, sub( shr( L_spec, 1 ), 8 ) ); + } + ELSE + { + Copy32( spectrum + L_win, xn_buf, 8 ); + Copy32( spectrum + 8, spectrum + 16, sub( L_win, 8 ) ); + Copy32( xn_buf, spectrum + 8, 8 ); + } + } + } } #ifdef IVAS_CODE_TCX_COM @@ -493,24 +497,24 @@ void tcxInvertWindowGrouping( *-------------------------------------------------------------------*/ void tcx5SpectrumInterleaving( - const int16_t tcx5Size, - float* spectrum) + const int16_t tcx5Size, + float *spectrum ) { - int16_t i; - float interleaveBuf[N_TCX10_MAX]; + int16_t i; + float interleaveBuf[N_TCX10_MAX]; - set_f(interleaveBuf, 0.0f, N_TCX10_MAX); + set_f( interleaveBuf, 0.0f, N_TCX10_MAX ); - /* group sub-windows: interleave bins according to their frequencies */ - for (i = 0; i < tcx5Size; i++) - { - interleaveBuf[2 * i] = spectrum[i]; - interleaveBuf[2 * i + 1] = spectrum[tcx5Size + i]; - } + /* group sub-windows: interleave bins according to their frequencies */ + for ( i = 0; i < tcx5Size; i++ ) + { + interleaveBuf[2 * i] = spectrum[i]; + interleaveBuf[2 * i + 1] = spectrum[tcx5Size + i]; + } - mvr2r(interleaveBuf, spectrum, 2 * tcx5Size); + mvr2r( interleaveBuf, spectrum, 2 * tcx5Size ); - return; + return; } @@ -521,24 +525,24 @@ void tcx5SpectrumInterleaving( *-------------------------------------------------------------------*/ void tcx5SpectrumDeinterleaving( - const int16_t tcx5Size, - float* spectrum) + const int16_t tcx5Size, + float *spectrum ) { - int16_t i; - float interleaveBuf[N_TCX10_MAX]; + int16_t i; + float interleaveBuf[N_TCX10_MAX]; - set_f(interleaveBuf, 0.0f, N_TCX10_MAX); + set_f( interleaveBuf, 0.0f, N_TCX10_MAX ); - /* ungroup sub-windows: interleave bins according to their frequencies */ - for (i = 0; i < tcx5Size; i++) - { - interleaveBuf[i] = spectrum[2 * i]; - interleaveBuf[tcx5Size + i] = spectrum[2 * i + 1]; - } + /* ungroup sub-windows: interleave bins according to their frequencies */ + for ( i = 0; i < tcx5Size; i++ ) + { + interleaveBuf[i] = spectrum[2 * i]; + interleaveBuf[tcx5Size + i] = spectrum[2 * i + 1]; + } - mvr2r(interleaveBuf, spectrum, 2 * tcx5Size); + mvr2r( interleaveBuf, spectrum, 2 * tcx5Size ); - return; + return; } @@ -549,26 +553,26 @@ void tcx5SpectrumDeinterleaving( *-------------------------------------------------------------------*/ void tcx5TnsGrouping( - const int16_t L_frame, /* i : frame length (TCX5) */ - const int16_t L_spec, /* i : coded spec length (TCX5, derived from filter borders*/ - float* spectrum) + const int16_t L_frame, /* i : frame length (TCX5) */ + const int16_t L_spec, /* i : coded spec length (TCX5, derived from filter borders*/ + float *spectrum ) { - /* rearrange LF sub-window lines prior to TNS synthesis filtering */ - if (L_spec < L_frame) - { - mvr2r(spectrum + 8, spectrum + 16, L_spec - 8); - mvr2r(spectrum + L_frame, spectrum + 8, 8); - mvr2r(spectrum + L_frame + 8, spectrum + L_spec + 8, L_spec - 8); - } - else - { - float buff[8]; /* Buffer for the rearrangement of LF TCX5 */ - mvr2r(spectrum + L_spec, buff, 8); - mvr2r(spectrum + 8, spectrum + 16, L_spec - 8); - mvr2r(buff, spectrum + 8, 8); - } - - return; + /* rearrange LF sub-window lines prior to TNS synthesis filtering */ + if ( L_spec < L_frame ) + { + mvr2r( spectrum + 8, spectrum + 16, L_spec - 8 ); + mvr2r( spectrum + L_frame, spectrum + 8, 8 ); + mvr2r( spectrum + L_frame + 8, spectrum + L_spec + 8, L_spec - 8 ); + } + else + { + float buff[8]; /* Buffer for the rearrangement of LF TCX5 */ + mvr2r( spectrum + L_spec, buff, 8 ); + mvr2r( spectrum + 8, spectrum + 16, L_spec - 8 ); + mvr2r( buff, spectrum + 8, 8 ); + } + + return; } @@ -579,40 +583,40 @@ void tcx5TnsGrouping( *-------------------------------------------------------------------*/ void tcx5TnsUngrouping( - const int16_t L_frame, /* i : frame length (TCX5) */ - const int16_t L_spec, /* i : coded spec length (TCX5, derived from filter borders*/ - float* spectrum, - const int16_t enc_dec /* i : 0: encoder, else decoder */ + const int16_t L_frame, /* i : frame length (TCX5) */ + const int16_t L_spec, /* i : coded spec length (TCX5, derived from filter borders*/ + float *spectrum, + const int16_t enc_dec /* i : 0: encoder, else decoder */ ) { - /* undo rearrangement of LF sub-window lines prior to TNS analysis */ - if (L_spec < L_frame) - { - mvr2r(spectrum + L_spec + 8, spectrum + L_frame + 8, L_spec - 8); - mvr2r(spectrum + 8, spectrum + L_frame, 8); - mvr2r(spectrum + 16, spectrum + 8, L_spec - 8); - set_zero(spectrum + L_spec, L_frame - L_spec); - set_zero(spectrum + L_frame + L_spec, L_frame - L_spec); - } - else - { - float buff[8]; /* Buffer for the rearrangement of LF TCX5 */ - - mvr2r(spectrum + 8, buff, 8); - - if (enc_dec == ENC) - { - mvr2r(spectrum + 16, spectrum + 8, L_frame - 8); - mvr2r(buff, spectrum + L_frame, 8); - } - else - { - mvr2r(spectrum + 16, spectrum + 8, L_spec - 8); - mvr2r(buff, spectrum + L_spec, 8); - } - } - - return; + /* undo rearrangement of LF sub-window lines prior to TNS analysis */ + if ( L_spec < L_frame ) + { + mvr2r( spectrum + L_spec + 8, spectrum + L_frame + 8, L_spec - 8 ); + mvr2r( spectrum + 8, spectrum + L_frame, 8 ); + mvr2r( spectrum + 16, spectrum + 8, L_spec - 8 ); + set_zero( spectrum + L_spec, L_frame - L_spec ); + set_zero( spectrum + L_frame + L_spec, L_frame - L_spec ); + } + else + { + float buff[8]; /* Buffer for the rearrangement of LF TCX5 */ + + mvr2r( spectrum + 8, buff, 8 ); + + if ( enc_dec == ENC ) + { + mvr2r( spectrum + 16, spectrum + 8, L_frame - 8 ); + mvr2r( buff, spectrum + L_frame, 8 ); + } + else + { + mvr2r( spectrum + 16, spectrum + 8, L_spec - 8 ); + mvr2r( buff, spectrum + L_spec, 8 ); + } + } + + return; } #endif @@ -743,4 +747,4 @@ void tcx5TnsUngrouping_fx( } return; -} \ No newline at end of file +} diff --git a/lib_com/common_api_types.h b/lib_com/common_api_types.h index 6af1b0ee1..ed0cfa5c2 100644 --- a/lib_com/common_api_types.h +++ b/lib_com/common_api_types.h @@ -216,7 +216,6 @@ typedef struct _IVAS_JBM_TRACE_DATA } IVAS_JBM_TRACE_DATA; - /*----------------------------------------------------------------------------------* * Renderer API structures and enums *----------------------------------------------------------------------------------*/ @@ -232,12 +231,12 @@ typedef struct _IVAS_ROOM_ACOUSTICS_CONFIG float acousticPreDelay; /* Time elapsed between input signal and late reverberation start, float, range [0.001..10] */ float inputPreDelay; /* Offset in seconds from where DSR is computed in the RIR (0 = at source), float, range [0.001..10] */ #ifdef IVAS_FLOAT_FIXED - Word32 pFc_input_fx[IVAS_CLDFB_NO_CHANNELS_MAX]; /* Center frequencies for which following values are provided: */ - Word32 pAcoustic_rt60_fx[IVAS_CLDFB_NO_CHANNELS_MAX]; /* - The room's T60 per center frequency */ - Word32 pAcoustic_dsr_fx[IVAS_CLDFB_NO_CHANNELS_MAX]; /* - The room's Diffuse to Source Ratio per center frequency */ - Word32 acousticPreDelay_fx; /* Time elapsed between input signal and late reverberation start, float, range [0.001..10] *//*Assumed Q-27*/ - Word32 inputPreDelay_fx; /* Offset in seconds from where DSR is computed in the RIR (0 = at source), float, range [0.001..10] *//* Assumed Q-27*/ -#endif // IVAS_FLOAT_FIXED + Word32 pFc_input_fx[IVAS_CLDFB_NO_CHANNELS_MAX]; /* Center frequencies for which following values are provided: */ + Word32 pAcoustic_rt60_fx[IVAS_CLDFB_NO_CHANNELS_MAX]; /* - The room's T60 per center frequency */ + Word32 pAcoustic_dsr_fx[IVAS_CLDFB_NO_CHANNELS_MAX]; /* - The room's Diffuse to Source Ratio per center frequency */ + Word32 acousticPreDelay_fx; /* Time elapsed between input signal and late reverberation start, float, range [0.001..10] */ /*Assumed Q-27*/ + Word32 inputPreDelay_fx; /* Offset in seconds from where DSR is computed in the RIR (0 = at source), float, range [0.001..10] */ /* Assumed Q-27*/ +#endif // IVAS_FLOAT_FIXED /* early reflections */ int16_t use_er; /* ER activation flag */ @@ -256,7 +255,7 @@ typedef struct _IVAS_RENDER_CONFIG IVAS_ROOM_ACOUSTICS_CONFIG_DATA roomAcoustics; float directivity[IVAS_MAX_NUM_OBJECTS * 3]; #ifdef IVAS_FLOAT_FIXED - Word16 directivity_fx[IVAS_MAX_NUM_OBJECTS * 3]; // has the following q-factor pattern: {6, 6, 15, 6, 6, 15, 6, 6, 15, 6, 6, 15} + Word16 directivity_fx[IVAS_MAX_NUM_OBJECTS * 3]; // has the following q-factor pattern: {6, 6, 15, 6, 6, 15, 6, 6, 15, 6, 6, 15} #endif } IVAS_RENDER_CONFIG_DATA, *IVAS_RENDER_CONFIG_HANDLE; diff --git a/lib_com/complex_basop.c b/lib_com/complex_basop.c index b63d76cc7..b9a20ddaf 100644 --- a/lib_com/complex_basop.c +++ b/lib_com/complex_basop.c @@ -17,8 +17,7 @@ #include "stl.h" - -#if (WMOPS) +#if ( WMOPS ) extern BASIC_OP multiCounter[MAXCOUNTERS]; @@ -27,431 +26,464 @@ extern int currCounter; #endif /* if WMOPS */ - #ifdef COMPLEX_OPERATOR /* ================================ New Complex Basops ========================= */ -cmplx CL_shr (cmplx inp, Word16 shift_val) { - cmplx out; - out.re = L_shr (inp.re, shift_val); - out.im = L_shr (inp.im, shift_val); -#if (WMOPS) - multiCounter[currCounter].CL_shr++; - multiCounter[currCounter].L_shr--; - multiCounter[currCounter].L_shr--; -#endif - return out; -} - -cmplx CL_shl (cmplx inp, Word16 shift_val) { - cmplx out; - out.re = L_shl (inp.re, shift_val); - out.im = L_shl (inp.im, shift_val); -#if (WMOPS) - multiCounter[currCounter].CL_shl++; - multiCounter[currCounter].L_shl--; - multiCounter[currCounter].L_shl--; +cmplx CL_shr( cmplx inp, Word16 shift_val ) +{ + cmplx out; + out.re = L_shr( inp.re, shift_val ); + out.im = L_shr( inp.im, shift_val ); +#if ( WMOPS ) + multiCounter[currCounter].CL_shr++; + multiCounter[currCounter].L_shr--; + multiCounter[currCounter].L_shr--; +#endif + return out; +} + +cmplx CL_shl( cmplx inp, Word16 shift_val ) +{ + cmplx out; + out.re = L_shl( inp.re, shift_val ); + out.im = L_shl( inp.im, shift_val ); +#if ( WMOPS ) + multiCounter[currCounter].CL_shl++; + multiCounter[currCounter].L_shl--; + multiCounter[currCounter].L_shl--; +#endif + return out; +} + +cmplx CL_add( cmplx inp1, cmplx inp2 ) +{ + cmplx out; + out.re = L_add( inp1.re, inp2.re ); + out.im = L_add( inp1.im, inp2.im ); +#if ( WMOPS ) + multiCounter[currCounter].CL_add++; + multiCounter[currCounter].L_add--; + multiCounter[currCounter].L_add--; +#endif + return out; +} + +cmplx CL_sub( cmplx inp1, cmplx inp2 ) +{ + cmplx out; + out.re = L_sub( inp1.re, inp2.re ); + out.im = L_sub( inp1.im, inp2.im ); +#if ( WMOPS ) + multiCounter[currCounter].CL_sub++; + multiCounter[currCounter].L_sub--; + multiCounter[currCounter].L_sub--; +#endif + return out; +} + +cmplx CL_scale( cmplx x, Word16 y ) +{ + cmplx result; + result.re = Mpy_32_16_r( x.re, y ); + result.im = Mpy_32_16_r( x.im, y ); +#if ( WMOPS ) + multiCounter[currCounter].Mpy_32_16_r--; + multiCounter[currCounter].Mpy_32_16_r--; + multiCounter[currCounter].CL_scale++; +#endif /* #if (WMOPS) */ + return ( result ); +} + +cmplx CL_dscale( cmplx x, Word16 y1, Word16 y2 ) +{ + cmplx result; + result.re = Mpy_32_16_r( x.re, y1 ); + result.im = Mpy_32_16_r( x.im, y2 ); +#if ( WMOPS ) + multiCounter[currCounter].Mpy_32_16_r--; + multiCounter[currCounter].Mpy_32_16_r--; + multiCounter[currCounter].CL_dscale++; +#endif /* #if (WMOPS) */ + return ( result ); +} + +cmplx CL_msu_j( cmplx x, cmplx y ) +{ + cmplx result; + result.re = L_add( x.re, y.im ); + result.im = L_sub( x.im, y.re ); +#if ( WMOPS ) + multiCounter[currCounter].CL_msu_j++; + multiCounter[currCounter].L_add--; + multiCounter[currCounter].L_sub--; +#endif + return result; +} + +cmplx CL_mac_j( cmplx x, cmplx y ) +{ + cmplx result; + result.re = L_sub( x.re, y.im ); + result.im = L_add( x.im, y.re ); +#if ( WMOPS ) + multiCounter[currCounter].CL_mac_j++; + multiCounter[currCounter].L_add--; + multiCounter[currCounter].L_sub--; +#endif + return result; +} + +cmplx CL_move( cmplx x ) +{ +#if ( WMOPS ) + multiCounter[currCounter].CL_move++; +#endif + return x; +} + +Word32 CL_Extract_real( cmplx x ) +{ +#if ( WMOPS ) + multiCounter[currCounter].CL_Extract_real++; +#endif + return x.re; +} + +Word32 CL_Extract_imag( cmplx x ) +{ +#if ( WMOPS ) + multiCounter[currCounter].CL_Extract_imag++; +#endif + return x.im; +} + +cmplx CL_form( Word32 re, Word32 im ) +{ + cmplx result; + result.re = re; + result.im = im; +#if ( WMOPS ) + multiCounter[currCounter].CL_form++; +#endif + return result; +} + +cmplx CL_multr_32x16( cmplx input, cmplx_s coeff ) +{ + cmplx result; + result.re = W_round48_L( W_sub_nosat( W_mult_32_16( input.re, coeff.re ), W_mult_32_16( input.im, coeff.im ) ) ); + result.im = W_round48_L( W_add_nosat( W_mult_32_16( input.re, coeff.im ), W_mult_32_16( input.im, coeff.re ) ) ); +#if ( WMOPS ) + multiCounter[currCounter].CL_multr_32x16++; + multiCounter[currCounter].W_mult_32_16--; + multiCounter[currCounter].W_mult_32_16--; + multiCounter[currCounter].W_mult_32_16--; + multiCounter[currCounter].W_mult_32_16--; + multiCounter[currCounter].W_sub_nosat--; + multiCounter[currCounter].W_add_nosat--; + multiCounter[currCounter].W_round48_L--; + multiCounter[currCounter].W_round48_L--; +#endif + return result; +} + +cmplx CL_negate( cmplx x ) +{ + cmplx result; + result.re = L_negate( x.re ); + result.im = L_negate( x.im ); +#if ( WMOPS ) + multiCounter[currCounter].CL_negate++; + multiCounter[currCounter].L_negate--; + multiCounter[currCounter].L_negate--; +#endif + return result; +} + +cmplx CL_conjugate( cmplx x ) +{ + cmplx result; + result.re = x.re; + result.im = L_negate( x.im ); +#if ( WMOPS ) + multiCounter[currCounter].CL_conjugate++; + multiCounter[currCounter].L_negate--; +#endif + return result; +} + + +cmplx CL_mul_j( cmplx input ) +{ + cmplx temp, result; + temp = CL_negate( input ); + result.re = temp.im; + result.im = input.re; +#if ( WMOPS ) + multiCounter[currCounter].CL_mul_j++; + multiCounter[currCounter].CL_negate--; +#endif + return result; +} + +cmplx CL_swap_real_imag( cmplx input ) +{ + cmplx result; + result.re = input.im; + result.im = input.re; +#if ( WMOPS ) + multiCounter[currCounter].CL_swap_real_imag++; +#endif + return result; +} + +cmplx_s C_add( cmplx_s inp1, cmplx_s inp2 ) +{ + cmplx_s out; + out.re = add( inp1.re, inp2.re ); + out.im = add( inp1.im, inp2.im ); + +#if ( WMOPS ) + multiCounter[currCounter].C_add++; + multiCounter[currCounter].add--; + multiCounter[currCounter].add--; +#endif + return out; +} + +cmplx_s C_sub( cmplx_s inp1, cmplx_s inp2 ) +{ + cmplx_s out; + out.re = sub( inp1.re, inp2.re ); + out.im = sub( inp1.im, inp2.im ); + +#if ( WMOPS ) + multiCounter[currCounter].C_sub++; + multiCounter[currCounter].sub--; + multiCounter[currCounter].sub--; +#endif + return out; +} + +cmplx_s C_mul_j( cmplx_s input ) +{ + cmplx_s result; + Word16 temp; + temp = negate( input.im ); + result.re = temp; + result.im = input.re; + +#if ( WMOPS ) + multiCounter[currCounter].C_mul_j++; + multiCounter[currCounter].negate--; +#endif + return result; +} + +cmplx_s C_multr( cmplx_s x, cmplx_s c ) +{ + cmplx_s result; + result.re = round_fx( W_sat_l( W_sub_nosat( W_mult_16_16( x.re, c.re ), W_mult_16_16( x.im, c.im ) ) ) ); + result.im = round_fx( W_sat_l( W_add_nosat( W_mult_16_16( x.im, c.re ), W_mult_16_16( x.re, c.im ) ) ) ); + +#if ( WMOPS ) + multiCounter[currCounter].C_multr++; + multiCounter[currCounter].W_mult_16_16--; + multiCounter[currCounter].W_mult_16_16--; + multiCounter[currCounter].W_mult_16_16--; + multiCounter[currCounter].W_mult_16_16--; + multiCounter[currCounter].W_sub_nosat--; + multiCounter[currCounter].W_add_nosat--; + multiCounter[currCounter].W_sat_l--; + multiCounter[currCounter].W_sat_l--; + multiCounter[currCounter].round--; + multiCounter[currCounter].round--; +#endif + return result; +} + +cmplx_s C_form( Word16 re, Word16 im ) +{ + cmplx_s result; + result.re = re; + result.im = im; +#if ( WMOPS ) + multiCounter[currCounter].C_form++; +#endif + return result; +} + +cmplx C_scale( cmplx_s x, Word16 y ) +{ + cmplx result; + result.re = L_mult( x.re, y ); + result.im = L_mult( x.im, y ); +#if ( WMOPS ) + multiCounter[currCounter].L_mult--; + multiCounter[currCounter].L_mult--; + multiCounter[currCounter].C_scale++; +#endif /* #if (WMOPS) */ + return ( result ); +} + +cmplx_s CL_round32_16( cmplx x ) +{ + cmplx_s result; + result.re = round_fx( x.re ); + result.im = round_fx( x.im ); + +#if ( WMOPS ) + multiCounter[currCounter].CL_round32_16++; + multiCounter[currCounter].round--; + multiCounter[currCounter].round--; +#endif + return result; +} + +cmplx CL_scale_32( cmplx x, Word32 y ) +{ + cmplx result; + result.re = Mpy_32_32_r( x.re, y ); + result.im = Mpy_32_32_r( x.im, y ); +#if ( WMOPS ) + multiCounter[currCounter].Mpy_32_32_r--; + multiCounter[currCounter].Mpy_32_32_r--; + multiCounter[currCounter].CL_scale_32++; +#endif /* #if (WMOPS) */ + return ( result ); +} + +cmplx CL_dscale_32( cmplx x, Word32 y1, Word32 y2 ) +{ + cmplx result; + result.re = Mpy_32_32_r( x.re, y1 ); + result.im = Mpy_32_32_r( x.im, y2 ); +#if ( WMOPS ) + multiCounter[currCounter].Mpy_32_32_r--; + multiCounter[currCounter].Mpy_32_32_r--; + multiCounter[currCounter].CL_dscale_32++; +#endif /* #if (WMOPS) */ + return ( result ); +} + +cmplx CL_multr_32x32( cmplx x, cmplx y ) +{ + cmplx result; + result.re = W_round64_L( W_sub( W_mult_32_32( x.re, y.re ), W_mult_32_32( x.im, y.im ) ) ); + result.im = W_round64_L( W_add( W_mult_32_32( x.im, y.re ), W_mult_32_32( x.re, y.im ) ) ); + +#if ( WMOPS ) + multiCounter[currCounter].CL_multr_32x32++; + multiCounter[currCounter].W_mult_32_32--; + multiCounter[currCounter].W_mult_32_32--; + multiCounter[currCounter].W_mult_32_32--; + multiCounter[currCounter].W_mult_32_32--; + multiCounter[currCounter].W_round64_L--; + multiCounter[currCounter].W_round64_L--; + multiCounter[currCounter].W_sub--; + multiCounter[currCounter].W_add--; +#endif + return result; +} + +cmplx_s C_mac_r( cmplx x, cmplx_s y, Word16 c ) +{ + cmplx_s result; + cmplx temp = CL_add( x, C_scale( y, c ) ); + result = CL_round32_16( temp ); + +#if ( WMOPS ) + multiCounter[currCounter].C_mac_r++; + multiCounter[currCounter].CL_add--; + multiCounter[currCounter].C_scale--; + multiCounter[currCounter].CL_round32_16--; +#endif + return result; +} + +cmplx_s C_msu_r( cmplx x, cmplx_s y, Word16 c ) +{ + cmplx_s result; + cmplx temp = CL_sub( x, C_scale( y, c ) ); + result = CL_round32_16( temp ); + +#if ( WMOPS ) + multiCounter[currCounter].C_msu_r++; + multiCounter[currCounter].CL_sub--; + multiCounter[currCounter].C_scale--; + multiCounter[currCounter].CL_round32_16--; +#endif + return result; +} + +Word16 C_Extract_real( cmplx_s x ) +{ +#if ( WMOPS ) + multiCounter[currCounter].C_Extract_real++; #endif - return out; + return x.re; } -cmplx CL_add (cmplx inp1, cmplx inp2) { - cmplx out; - out.re = L_add (inp1.re, inp2.re); - out.im = L_add (inp1.im, inp2.im); -#if (WMOPS) - multiCounter[currCounter].CL_add++; - multiCounter[currCounter].L_add--; - multiCounter[currCounter].L_add--; +Word16 C_Extract_imag( cmplx_s x ) +{ +#if ( WMOPS ) + multiCounter[currCounter].C_Extract_imag++; #endif - return out; + return x.im; +} + +cmplx_s C_negate( cmplx_s x ) +{ + cmplx_s result; + result.re = negate( x.re ); + result.im = negate( x.im ); +#if ( WMOPS ) + multiCounter[currCounter].C_negate++; + multiCounter[currCounter].negate--; + multiCounter[currCounter].negate--; +#endif + return result; } -cmplx CL_sub (cmplx inp1, cmplx inp2) { - cmplx out; - out.re = L_sub (inp1.re, inp2.re); - out.im = L_sub (inp1.im, inp2.im); -#if (WMOPS) - multiCounter[currCounter].CL_sub++; - multiCounter[currCounter].L_sub--; - multiCounter[currCounter].L_sub--; +cmplx_s C_conjugate( cmplx_s x ) +{ + cmplx_s result; + result.re = x.re; + result.im = negate( x.im ); +#if ( WMOPS ) + multiCounter[currCounter].C_conjugate++; + multiCounter[currCounter].negate--; +#endif + return result; +} + +cmplx_s C_shr( cmplx_s inp, Word16 shift_val ) +{ + cmplx_s out; + out.re = shr( inp.re, shift_val ); + out.im = shr( inp.im, shift_val ); +#if ( WMOPS ) + multiCounter[currCounter].C_shr++; + multiCounter[currCounter].shr--; + multiCounter[currCounter].shr--; #endif - return out; -} - -cmplx CL_scale(cmplx x, Word16 y) { - cmplx result; - result.re = Mpy_32_16_r (x.re, y); - result.im = Mpy_32_16_r (x.im, y); -#if (WMOPS) - multiCounter[currCounter].Mpy_32_16_r--; - multiCounter[currCounter].Mpy_32_16_r--; - multiCounter[currCounter].CL_scale++; -#endif/* #if (WMOPS) */ - return (result); -} - -cmplx CL_dscale (cmplx x, Word16 y1, Word16 y2) { - cmplx result; - result.re = Mpy_32_16_r (x.re, y1); - result.im = Mpy_32_16_r (x.im, y2); -#if (WMOPS) - multiCounter[currCounter].Mpy_32_16_r--; - multiCounter[currCounter].Mpy_32_16_r--; - multiCounter[currCounter].CL_dscale++; -#endif/* #if (WMOPS) */ - return (result); -} - -cmplx CL_msu_j (cmplx x, cmplx y) { - cmplx result; - result.re = L_add (x.re, y.im); - result.im = L_sub (x.im, y.re); -#if (WMOPS) - multiCounter[currCounter].CL_msu_j++; - multiCounter[currCounter].L_add--; - multiCounter[currCounter].L_sub--; -#endif - return result; -} - -cmplx CL_mac_j (cmplx x, cmplx y) { - cmplx result; - result.re = L_sub (x.re, y.im ); - result.im = L_add (x.im, y.re ); -#if (WMOPS) - multiCounter[currCounter].CL_mac_j++; - multiCounter[currCounter].L_add--; - multiCounter[currCounter].L_sub--; -#endif - return result; -} - -cmplx CL_move (cmplx x) { -#if (WMOPS) - multiCounter[currCounter].CL_move++; -#endif - return x; -} - -Word32 CL_Extract_real (cmplx x) { -#if (WMOPS) - multiCounter[currCounter].CL_Extract_real++; -#endif - return x.re; -} - -Word32 CL_Extract_imag (cmplx x) { -#if (WMOPS) - multiCounter[currCounter].CL_Extract_imag++; -#endif - return x.im; -} - -cmplx CL_form (Word32 re, Word32 im) { - cmplx result; - result.re = re; - result.im = im; -#if (WMOPS) - multiCounter[currCounter].CL_form++; -#endif - return result; -} - -cmplx CL_multr_32x16 (cmplx input, cmplx_s coeff) { - cmplx result; - result.re = W_round48_L (W_sub_nosat (W_mult_32_16 (input.re, coeff.re), W_mult_32_16 (input.im, coeff.im) ) ); - result.im = W_round48_L (W_add_nosat (W_mult_32_16 (input.re, coeff.im), W_mult_32_16 (input.im, coeff.re) ) ); -#if (WMOPS) - multiCounter[currCounter].CL_multr_32x16++; - multiCounter[currCounter].W_mult_32_16--; - multiCounter[currCounter].W_mult_32_16--; - multiCounter[currCounter].W_mult_32_16--; - multiCounter[currCounter].W_mult_32_16--; - multiCounter[currCounter].W_sub_nosat--; - multiCounter[currCounter].W_add_nosat--; - multiCounter[currCounter].W_round48_L--; - multiCounter[currCounter].W_round48_L--; -#endif - return result; -} - -cmplx CL_negate(cmplx x) { - cmplx result; - result.re = L_negate (x.re); - result.im = L_negate (x.im); -#if (WMOPS) - multiCounter[currCounter].CL_negate++; - multiCounter[currCounter].L_negate--; - multiCounter[currCounter].L_negate--; -#endif - return result; -} - -cmplx CL_conjugate (cmplx x) { - cmplx result; - result.re = x.re; - result.im = L_negate (x.im); -#if (WMOPS) - multiCounter[currCounter].CL_conjugate++; - multiCounter[currCounter].L_negate--; -#endif - return result; -} - - -cmplx CL_mul_j (cmplx input) { - cmplx temp, result; - temp = CL_negate (input); - result.re = temp.im; - result.im = input.re; -#if (WMOPS) - multiCounter[currCounter].CL_mul_j++; - multiCounter[currCounter].CL_negate--; -#endif - return result; -} - -cmplx CL_swap_real_imag (cmplx input) { - cmplx result; - result.re = input.im; - result.im = input.re; -#if (WMOPS) - multiCounter[currCounter].CL_swap_real_imag++; -#endif - return result; -} - -cmplx_s C_add (cmplx_s inp1, cmplx_s inp2) { - cmplx_s out; - out.re = add (inp1.re, inp2.re); - out.im = add (inp1.im, inp2.im); - -#if (WMOPS) - multiCounter[currCounter].C_add++; - multiCounter[currCounter].add--; - multiCounter[currCounter].add--; -#endif - return out; -} - -cmplx_s C_sub (cmplx_s inp1, cmplx_s inp2) { - cmplx_s out; - out.re = sub (inp1.re, inp2.re); - out.im = sub (inp1.im, inp2.im); - -#if (WMOPS) - multiCounter[currCounter].C_sub++; - multiCounter[currCounter].sub--; - multiCounter[currCounter].sub--; -#endif - return out; -} - -cmplx_s C_mul_j (cmplx_s input) { - cmplx_s result; - Word16 temp; - temp = negate(input.im); - result.re = temp; - result.im = input.re; - -#if (WMOPS) - multiCounter[currCounter].C_mul_j++; - multiCounter[currCounter].negate--; -#endif - return result; -} - -cmplx_s C_multr (cmplx_s x, cmplx_s c) { - cmplx_s result; - result.re = round_fx (W_sat_l (W_sub_nosat (W_mult_16_16 (x.re, c.re), W_mult_16_16 (x.im, c.im) ) ) ); - result.im = round_fx (W_sat_l (W_add_nosat (W_mult_16_16 (x.im, c.re), W_mult_16_16 (x.re, c.im) ) ) ); - -#if (WMOPS) - multiCounter[currCounter].C_multr++; - multiCounter[currCounter].W_mult_16_16--; - multiCounter[currCounter].W_mult_16_16--; - multiCounter[currCounter].W_mult_16_16--; - multiCounter[currCounter].W_mult_16_16--; - multiCounter[currCounter].W_sub_nosat--; - multiCounter[currCounter].W_add_nosat--; - multiCounter[currCounter].W_sat_l--; - multiCounter[currCounter].W_sat_l--; - multiCounter[currCounter].round--; - multiCounter[currCounter].round--; -#endif - return result; -} - -cmplx_s C_form ( Word16 re, Word16 im) { - cmplx_s result; - result.re = re; - result.im = im; -#if (WMOPS) - multiCounter[currCounter].C_form++; -#endif - return result; -} - -cmplx C_scale(cmplx_s x, Word16 y) { - cmplx result; - result.re = L_mult(x.re, y); - result.im = L_mult(x.im, y); -#if (WMOPS) - multiCounter[currCounter].L_mult--; - multiCounter[currCounter].L_mult--; - multiCounter[currCounter].C_scale++; -#endif/* #if (WMOPS) */ - return (result); -} - -cmplx_s CL_round32_16 (cmplx x) { - cmplx_s result; - result.re = round_fx (x.re); - result.im = round_fx (x.im); - -#if (WMOPS) - multiCounter[currCounter].CL_round32_16++; - multiCounter[currCounter].round--; - multiCounter[currCounter].round--; -#endif - return result; -} - -cmplx CL_scale_32 (cmplx x, Word32 y) { - cmplx result; - result.re = Mpy_32_32_r (x.re, y); - result.im = Mpy_32_32_r (x.im, y); -#if (WMOPS) - multiCounter[currCounter].Mpy_32_32_r--; - multiCounter[currCounter].Mpy_32_32_r--; - multiCounter[currCounter].CL_scale_32++; -#endif/* #if (WMOPS) */ - return (result); -} - -cmplx CL_dscale_32 (cmplx x, Word32 y1, Word32 y2) { - cmplx result; - result.re = Mpy_32_32_r (x.re, y1); - result.im = Mpy_32_32_r (x.im, y2); -#if (WMOPS) - multiCounter[currCounter].Mpy_32_32_r--; - multiCounter[currCounter].Mpy_32_32_r--; - multiCounter[currCounter].CL_dscale_32++; -#endif/* #if (WMOPS) */ - return (result); -} - -cmplx CL_multr_32x32 (cmplx x, cmplx y) { - cmplx result; - result.re = W_round64_L (W_sub (W_mult_32_32 (x.re, y.re), W_mult_32_32(x.im, y.im) ) ) ; - result.im = W_round64_L (W_add (W_mult_32_32 (x.im, y.re), W_mult_32_32(x.re, y.im) ) ) ; - -#if (WMOPS) - multiCounter[currCounter].CL_multr_32x32++; - multiCounter[currCounter].W_mult_32_32--; - multiCounter[currCounter].W_mult_32_32--; - multiCounter[currCounter].W_mult_32_32--; - multiCounter[currCounter].W_mult_32_32--; - multiCounter[currCounter].W_round64_L--; - multiCounter[currCounter].W_round64_L--; - multiCounter[currCounter].W_sub--; - multiCounter[currCounter].W_add--; -#endif - return result; -} - -cmplx_s C_mac_r (cmplx x, cmplx_s y, Word16 c) { - cmplx_s result; - cmplx temp = CL_add (x, C_scale (y, c) ); - result = CL_round32_16 (temp); - -#if (WMOPS) - multiCounter[currCounter].C_mac_r++; - multiCounter[currCounter].CL_add--; - multiCounter[currCounter].C_scale--; - multiCounter[currCounter].CL_round32_16--; -#endif - return result; -} - -cmplx_s C_msu_r (cmplx x, cmplx_s y, Word16 c) { - cmplx_s result; - cmplx temp = CL_sub (x, C_scale (y, c) ); - result = CL_round32_16 (temp); - -#if (WMOPS) - multiCounter[currCounter].C_msu_r++; - multiCounter[currCounter].CL_sub--; - multiCounter[currCounter].C_scale--; - multiCounter[currCounter].CL_round32_16--; -#endif - return result; -} - -Word16 C_Extract_real (cmplx_s x) { -#if (WMOPS) - multiCounter[currCounter].C_Extract_real++; -#endif - return x.re; -} - -Word16 C_Extract_imag (cmplx_s x) { -#if (WMOPS) - multiCounter[currCounter].C_Extract_imag++; -#endif - return x.im; -} - -cmplx_s C_negate (cmplx_s x) { - cmplx_s result; - result.re = negate (x.re); - result.im = negate (x.im); -#if (WMOPS) - multiCounter[currCounter].C_negate++; - multiCounter[currCounter].negate--; - multiCounter[currCounter].negate--; -#endif - return result; -} - -cmplx_s C_conjugate (cmplx_s x) { - cmplx_s result; - result.re = x.re; - result.im = negate (x.im); -#if (WMOPS) - multiCounter[currCounter].C_conjugate++; - multiCounter[currCounter].negate--; -#endif - return result; -} - -cmplx_s C_shr (cmplx_s inp, Word16 shift_val) { - cmplx_s out; - out.re = shr (inp.re, shift_val); - out.im = shr (inp.im, shift_val); -#if (WMOPS) - multiCounter[currCounter].C_shr++; - multiCounter[currCounter].shr--; - multiCounter[currCounter].shr--; -#endif - return out; -} - -cmplx_s C_shl (cmplx_s inp, Word16 shift_val) { - cmplx_s out; - out.re = shl (inp.re, shift_val); - out.im = shl (inp.im, shift_val); -#if (WMOPS) - multiCounter[currCounter].C_shl++; - multiCounter[currCounter].shl--; - multiCounter[currCounter].shl--; -#endif - return out; + return out; +} + +cmplx_s C_shl( cmplx_s inp, Word16 shift_val ) +{ + cmplx_s out; + out.re = shl( inp.re, shift_val ); + out.im = shl( inp.im, shift_val ); +#if ( WMOPS ) + multiCounter[currCounter].C_shl++; + multiCounter[currCounter].shl--; + multiCounter[currCounter].shl--; +#endif + return out; } #endif /* #ifdef COMPLEX_OPERATOR */ /* end of file */ - diff --git a/lib_com/complex_basop.h b/lib_com/complex_basop.h index 3c1a8f715..117ba400e 100644 --- a/lib_com/complex_basop.h +++ b/lib_com/complex_basop.h @@ -1,12 +1,12 @@ - /***************************************************************************** +/***************************************************************************** - * +* - * Complex arithmetic operators +* Complex arithmetic operators - * +* - *****************************************************************************/ +*****************************************************************************/ #ifndef _COMPLEX_BASIC_OP_H #define _COMPLEX_BASIC_OP_H @@ -18,15 +18,15 @@ typedef struct { - Word32 re; - Word32 im; -}cmplx; + Word32 re; + Word32 im; +} cmplx; typedef struct { - Word16 re; - Word16 im; -}cmplx_s; + Word16 re; + Word16 im; +} cmplx_s; /*___________________________________________________________________________ | | @@ -34,44 +34,43 @@ typedef struct |___________________________________________________________________________| */ -cmplx CL_shr (cmplx inp, Word16 shift_val); -cmplx CL_shl (cmplx inp, Word16 shift_val); -cmplx CL_add (cmplx inp1, cmplx inp2); -cmplx CL_sub (cmplx inp1, cmplx inp2); -cmplx CL_scale (cmplx x, Word16 y); -cmplx CL_dscale (cmplx x, Word16 y1, Word16 y2); -cmplx CL_msu_j (cmplx x, cmplx y); -cmplx CL_mac_j (cmplx x, cmplx y); -cmplx CL_move (cmplx x); -Word32 CL_Extract_real (cmplx x); -Word32 CL_Extract_imag (cmplx x); -cmplx CL_form (Word32 re, Word32 im); -cmplx CL_multr_32x16 (cmplx input, cmplx_s coeff); -cmplx CL_negate (cmplx x); -cmplx CL_conjugate (cmplx x); -cmplx CL_mul_j (cmplx input); -cmplx CL_swap_real_imag (cmplx input); -cmplx_s C_add (cmplx_s inp1, cmplx_s inp2); -cmplx_s C_sub (cmplx_s inp1, cmplx_s inp2); -cmplx_s C_mul_j (cmplx_s input); -cmplx_s C_multr (cmplx_s x, cmplx_s c); -cmplx_s C_form (Word16 re, Word16 im ); +cmplx CL_shr( cmplx inp, Word16 shift_val ); +cmplx CL_shl( cmplx inp, Word16 shift_val ); +cmplx CL_add( cmplx inp1, cmplx inp2 ); +cmplx CL_sub( cmplx inp1, cmplx inp2 ); +cmplx CL_scale( cmplx x, Word16 y ); +cmplx CL_dscale( cmplx x, Word16 y1, Word16 y2 ); +cmplx CL_msu_j( cmplx x, cmplx y ); +cmplx CL_mac_j( cmplx x, cmplx y ); +cmplx CL_move( cmplx x ); +Word32 CL_Extract_real( cmplx x ); +Word32 CL_Extract_imag( cmplx x ); +cmplx CL_form( Word32 re, Word32 im ); +cmplx CL_multr_32x16( cmplx input, cmplx_s coeff ); +cmplx CL_negate( cmplx x ); +cmplx CL_conjugate( cmplx x ); +cmplx CL_mul_j( cmplx input ); +cmplx CL_swap_real_imag( cmplx input ); +cmplx_s C_add( cmplx_s inp1, cmplx_s inp2 ); +cmplx_s C_sub( cmplx_s inp1, cmplx_s inp2 ); +cmplx_s C_mul_j( cmplx_s input ); +cmplx_s C_multr( cmplx_s x, cmplx_s c ); +cmplx_s C_form( Word16 re, Word16 im ); -cmplx C_scale (cmplx_s x, Word16 y); -cmplx_s CL_round32_16 (cmplx x); -cmplx CL_scale_32 (cmplx x, Word32 y); -cmplx CL_dscale_32 (cmplx x, Word32 y1, Word32 y2); -cmplx CL_multr_32x32 (cmplx x, cmplx y); -cmplx_s C_mac_r (cmplx x, cmplx_s y, Word16 c); -cmplx_s C_msu_r (cmplx x, cmplx_s y, Word16 c); -Word16 C_Extract_real (cmplx_s x ); -Word16 C_Extract_imag (cmplx_s x ); -cmplx_s C_negate (cmplx_s x); -cmplx_s C_conjugate (cmplx_s x); -cmplx_s C_shr (cmplx_s inp, Word16 shift_val); -cmplx_s C_shl (cmplx_s inp, Word16 shift_val); +cmplx C_scale( cmplx_s x, Word16 y ); +cmplx_s CL_round32_16( cmplx x ); +cmplx CL_scale_32( cmplx x, Word32 y ); +cmplx CL_dscale_32( cmplx x, Word32 y1, Word32 y2 ); +cmplx CL_multr_32x32( cmplx x, cmplx y ); +cmplx_s C_mac_r( cmplx x, cmplx_s y, Word16 c ); +cmplx_s C_msu_r( cmplx x, cmplx_s y, Word16 c ); +Word16 C_Extract_real( cmplx_s x ); +Word16 C_Extract_imag( cmplx_s x ); +cmplx_s C_negate( cmplx_s x ); +cmplx_s C_conjugate( cmplx_s x ); +cmplx_s C_shr( cmplx_s inp, Word16 shift_val ); +cmplx_s C_shl( cmplx_s inp, Word16 shift_val ); #endif /* #ifdef COMPLEX_OPERATOR */ #endif /* ifndef _COMPLEX_BASIC_OP_H */ - diff --git a/lib_com/control.c b/lib_com/control.c index 2d0a46c25..94f3d5aeb 100644 --- a/lib_com/control.c +++ b/lib_com/control.c @@ -9,12 +9,12 @@ History: 07 Nov 04 v2.0 Incorporation of new 32-bit / 40-bit / control - operators for the ITU-T Standard Tool Library as + operators for the ITU-T Standard Tool Library as described in Geneva, 20-30 January 2004 WP 3/16 Q10/16 TD 11 document and subsequent discussions on the wp3audio@yahoogroups.com email reflector. March 06 v2.1 Changed to improve portability. - + ============================================================================ */ @@ -28,220 +28,254 @@ int call_occurred = 1; #ifdef CONTROL_CODE_OPS -Flag LT_16 (Word16 var1, Word16 var2) { - Flag F_ret = 0; - - if( var1 < var2 ) - { - F_ret = 1; - } -#if (WMOPS) - multiCounter[currCounter].LT_16++; -#endif - return F_ret; -} - -Flag GT_16 (Word16 var1, Word16 var2) { - Flag F_ret = 0; - - if( var1 > var2 ) - { - F_ret = 1; - } -#if (WMOPS) - multiCounter[currCounter].GT_16++; -#endif - return F_ret; -} - -Flag LE_16 (Word16 var1, Word16 var2) { - Flag F_ret = 0; - - if (var1 <= var2) { - F_ret = 1; - } -#if (WMOPS) - multiCounter[currCounter].LE_16++; -#endif - return F_ret; -} - -Flag GE_16 (Word16 var1, Word16 var2) { - Flag F_ret = 0; - - if (var1 >= var2) { - F_ret = 1; - } -#if (WMOPS) - multiCounter[currCounter].GE_16++; -#endif - return F_ret; -} - -Flag EQ_16 (Word16 var1, Word16 var2) { - Flag F_ret = 0; - - if (var1 == var2) { - F_ret = 1; - } -#if (WMOPS) - multiCounter[currCounter].EQ_16++; -#endif - return F_ret; -} - -Flag NE_16 (Word16 var1, Word16 var2) { - Flag F_ret = 0; - - if (var1 != var2) { - F_ret = 1; - } -#if (WMOPS) - multiCounter[currCounter].NE_16++; -#endif - return F_ret; -} - -Flag LT_32 (Word32 L_var1, Word32 L_var2) { - Flag F_ret = 0; - - if (L_var1 < L_var2) { - F_ret = 1; - } -#if (WMOPS) - multiCounter[currCounter].LT_32++; -#endif - return F_ret; -} - -Flag GT_32 (Word32 L_var1, Word32 L_var2) { - Flag F_ret = 0; - - if (L_var1 > L_var2) { - F_ret = 1; - } -#if (WMOPS) - multiCounter[currCounter].GT_32++; -#endif - return F_ret; -} - -Flag LE_32 (Word32 L_var1, Word32 L_var2) { - Flag F_ret = 0; - - if (L_var1 <= L_var2) { - F_ret = 1; - } -#if (WMOPS) - multiCounter[currCounter].LE_32++; -#endif - return F_ret; -} - -Flag GE_32 (Word32 L_var1, Word32 L_var2) { - Flag F_ret = 0; - - if (L_var1 >= L_var2) { - F_ret = 1; - } -#if (WMOPS) - multiCounter[currCounter].GE_32++; -#endif - return F_ret; -} - -Flag EQ_32 (Word32 L_var1, Word32 L_var2) { - Flag F_ret = 0; - - if (L_var1 == L_var2) { - F_ret = 1; - } -#if (WMOPS) - multiCounter[currCounter].EQ_32++; -#endif - return F_ret; -} - -Flag NE_32 (Word32 L_var1, Word32 L_var2) { - Flag F_ret = 0; - - if (L_var1 != L_var2) { - F_ret = 1; - } -#if (WMOPS) - multiCounter[currCounter].NE_32++; -#endif - return F_ret; -} - -Flag LT_64 (Word64 L64_var1, Word64 L64_var2) { - Flag F_ret = 0; - - if (L64_var1 < L64_var2) { - F_ret = 1; - } -#if (WMOPS) - multiCounter[currCounter].LT_64++; -#endif - return F_ret; -} - -Flag GT_64 (Word64 L64_var1, Word64 L64_var2) { - Flag F_ret = 0; - - if (L64_var1 > L64_var2) { - F_ret = 1; - } -#if (WMOPS) - multiCounter[currCounter].GT_64++; -#endif - return F_ret; -} - -Flag LE_64 (Word64 L64_var1, Word64 L64_var2) { - Flag F_ret = 0; - - if (L64_var1 <= L64_var2) { - F_ret = 1; - } -#if (WMOPS) - multiCounter[currCounter].LE_64++; -#endif - return F_ret; -} -Flag GE_64 (Word64 L64_var1, Word64 L64_var2) { - Flag F_ret = 0; - - if (L64_var1 >= L64_var2) { - F_ret = 1; - } -#if (WMOPS) - multiCounter[currCounter].GE_64++; -#endif - return F_ret; -} - -Flag EQ_64 (Word64 L64_var1, Word64 L64_var2) { - Flag F_ret = 0; - - if (L64_var1 == L64_var2) { - F_ret = 1; - } -#if (WMOPS) - multiCounter[currCounter].EQ_64++; -#endif - return F_ret; -} -Flag NE_64 (Word64 L64_var1, Word64 L64_var2) { - Flag F_ret = 0; - - if (L64_var1 != L64_var2) { - F_ret = 1; - } -#if (WMOPS) - multiCounter[currCounter].NE_64++; -#endif - return F_ret; +Flag LT_16( Word16 var1, Word16 var2 ) +{ + Flag F_ret = 0; + + if ( var1 < var2 ) + { + F_ret = 1; + } +#if ( WMOPS ) + multiCounter[currCounter].LT_16++; +#endif + return F_ret; +} + +Flag GT_16( Word16 var1, Word16 var2 ) +{ + Flag F_ret = 0; + + if ( var1 > var2 ) + { + F_ret = 1; + } +#if ( WMOPS ) + multiCounter[currCounter].GT_16++; +#endif + return F_ret; +} + +Flag LE_16( Word16 var1, Word16 var2 ) +{ + Flag F_ret = 0; + + if ( var1 <= var2 ) + { + F_ret = 1; + } +#if ( WMOPS ) + multiCounter[currCounter].LE_16++; +#endif + return F_ret; +} + +Flag GE_16( Word16 var1, Word16 var2 ) +{ + Flag F_ret = 0; + + if ( var1 >= var2 ) + { + F_ret = 1; + } +#if ( WMOPS ) + multiCounter[currCounter].GE_16++; +#endif + return F_ret; +} + +Flag EQ_16( Word16 var1, Word16 var2 ) +{ + Flag F_ret = 0; + + if ( var1 == var2 ) + { + F_ret = 1; + } +#if ( WMOPS ) + multiCounter[currCounter].EQ_16++; +#endif + return F_ret; +} + +Flag NE_16( Word16 var1, Word16 var2 ) +{ + Flag F_ret = 0; + + if ( var1 != var2 ) + { + F_ret = 1; + } +#if ( WMOPS ) + multiCounter[currCounter].NE_16++; +#endif + return F_ret; +} + +Flag LT_32( Word32 L_var1, Word32 L_var2 ) +{ + Flag F_ret = 0; + + if ( L_var1 < L_var2 ) + { + F_ret = 1; + } +#if ( WMOPS ) + multiCounter[currCounter].LT_32++; +#endif + return F_ret; +} + +Flag GT_32( Word32 L_var1, Word32 L_var2 ) +{ + Flag F_ret = 0; + + if ( L_var1 > L_var2 ) + { + F_ret = 1; + } +#if ( WMOPS ) + multiCounter[currCounter].GT_32++; +#endif + return F_ret; +} + +Flag LE_32( Word32 L_var1, Word32 L_var2 ) +{ + Flag F_ret = 0; + + if ( L_var1 <= L_var2 ) + { + F_ret = 1; + } +#if ( WMOPS ) + multiCounter[currCounter].LE_32++; +#endif + return F_ret; +} + +Flag GE_32( Word32 L_var1, Word32 L_var2 ) +{ + Flag F_ret = 0; + + if ( L_var1 >= L_var2 ) + { + F_ret = 1; + } +#if ( WMOPS ) + multiCounter[currCounter].GE_32++; +#endif + return F_ret; +} + +Flag EQ_32( Word32 L_var1, Word32 L_var2 ) +{ + Flag F_ret = 0; + + if ( L_var1 == L_var2 ) + { + F_ret = 1; + } +#if ( WMOPS ) + multiCounter[currCounter].EQ_32++; +#endif + return F_ret; +} + +Flag NE_32( Word32 L_var1, Word32 L_var2 ) +{ + Flag F_ret = 0; + + if ( L_var1 != L_var2 ) + { + F_ret = 1; + } +#if ( WMOPS ) + multiCounter[currCounter].NE_32++; +#endif + return F_ret; +} + +Flag LT_64( Word64 L64_var1, Word64 L64_var2 ) +{ + Flag F_ret = 0; + + if ( L64_var1 < L64_var2 ) + { + F_ret = 1; + } +#if ( WMOPS ) + multiCounter[currCounter].LT_64++; +#endif + return F_ret; +} + +Flag GT_64( Word64 L64_var1, Word64 L64_var2 ) +{ + Flag F_ret = 0; + + if ( L64_var1 > L64_var2 ) + { + F_ret = 1; + } +#if ( WMOPS ) + multiCounter[currCounter].GT_64++; +#endif + return F_ret; +} + +Flag LE_64( Word64 L64_var1, Word64 L64_var2 ) +{ + Flag F_ret = 0; + + if ( L64_var1 <= L64_var2 ) + { + F_ret = 1; + } +#if ( WMOPS ) + multiCounter[currCounter].LE_64++; +#endif + return F_ret; +} +Flag GE_64( Word64 L64_var1, Word64 L64_var2 ) +{ + Flag F_ret = 0; + + if ( L64_var1 >= L64_var2 ) + { + F_ret = 1; + } +#if ( WMOPS ) + multiCounter[currCounter].GE_64++; +#endif + return F_ret; +} + +Flag EQ_64( Word64 L64_var1, Word64 L64_var2 ) +{ + Flag F_ret = 0; + + if ( L64_var1 == L64_var2 ) + { + F_ret = 1; + } +#if ( WMOPS ) + multiCounter[currCounter].EQ_64++; +#endif + return F_ret; +} +Flag NE_64( Word64 L64_var1, Word64 L64_var2 ) +{ + Flag F_ret = 0; + + if ( L64_var1 != L64_var2 ) + { + F_ret = 1; + } +#if ( WMOPS ) + multiCounter[currCounter].NE_64++; +#endif + return F_ret; } #endif /* #ifdef CONTROL_CODE_OPS */ diff --git a/lib_com/control.h b/lib_com/control.h index 6b140d0ee..d6a9610ac 100644 --- a/lib_com/control.h +++ b/lib_com/control.h @@ -41,25 +41,25 @@ * Constants and Globals * *****************************************************************************/ -#if (WMOPS) +#if ( WMOPS ) extern BASIC_OP multiCounter[MAXCOUNTERS]; extern int currCounter; - /* Technical note : - * The following 3 variables are only used for correct complexity - * evaluation of the following structure : - * IF{ - * ... - * } ELSE IF { - * ... - * } ELSE IF { - * ... - * } - * ... - * } ELSE { - * ... - * } - */ +/* Technical note : + * The following 3 variables are only used for correct complexity + * evaluation of the following structure : + * IF{ + * ... + * } ELSE IF { + * ... + * } ELSE IF { + * ... + * } + * ... + * } ELSE { + * ... + * } + */ extern int funcId_where_last_call_to_else_occurred; extern long funcid_total_wmops_at_last_call_to_else; extern int call_occurred; @@ -86,13 +86,18 @@ extern int call_occurred; * *****************************************************************************/ #ifndef WMOPS -#define FOR( a) for( a) +#define FOR( a ) for ( a ) #else /* ifndef WMOPS */ -#define FOR( a) if( incrFor(), 0); else for( a) - -static __inline void incrFor (void) { - multiCounter[currCounter].For++; +#define FOR( a ) \ + if ( incrFor(), 0 ) \ + ; \ + else \ + for ( a ) + +static __inline void incrFor( void ) +{ + multiCounter[currCounter].For++; } #endif /* ifndef WMOPS */ @@ -111,13 +116,14 @@ static __inline void incrFor (void) { * *****************************************************************************/ #ifndef WMOPS -#define WHILE(a) while (a) +#define WHILE( a ) while ( a ) #else /* ifndef WMOPS */ -#define WHILE(a) while (incrWhile(), a) +#define WHILE( a ) while ( incrWhile(), a ) -static __inline void incrWhile (void) { - multiCounter[currCounter].While++; +static __inline void incrWhile( void ) +{ + multiCounter[currCounter].While++; } #endif /* ifndef WMOPS */ @@ -163,23 +169,22 @@ static __inline void incrWhile (void) { * *****************************************************************************/ #ifndef WMOPS -#define IF(a) if (a) +#define IF( a ) if ( a ) #else /* ifndef WMOPS */ -#define IF(a) if (incrIf (), a) - -static __inline void incrIf (void) { - /* Technical note : - * If the "IF" operator comes just after an "ELSE", its counter - * must not be incremented. - */ - if ((currCounter != funcId_where_last_call_to_else_occurred) - || (TotalWeightedOperation () != funcid_total_wmops_at_last_call_to_else) - || (call_occurred == 1)) - multiCounter[currCounter].If++; - - call_occurred = 0; - funcId_where_last_call_to_else_occurred = MAXCOUNTERS; +#define IF( a ) if ( incrIf(), a ) + +static __inline void incrIf( void ) +{ + /* Technical note : + * If the "IF" operator comes just after an "ELSE", its counter + * must not be incremented. + */ + if ( ( currCounter != funcId_where_last_call_to_else_occurred ) || ( TotalWeightedOperation() != funcid_total_wmops_at_last_call_to_else ) || ( call_occurred == 1 ) ) + multiCounter[currCounter].If++; + + call_occurred = 0; + funcId_where_last_call_to_else_occurred = MAXCOUNTERS; } #endif /* ifndef WMOPS */ @@ -199,19 +204,22 @@ static __inline void incrIf (void) { #define ELSE else #else /* ifndef WMOPS */ -#define ELSE else if (incrElse (), 0) ; else +#define ELSE \ + else if ( incrElse(), 0 ); \ + else -static __inline void incrElse (void) { - multiCounter[currCounter].If++; +static __inline void incrElse( void ) +{ + multiCounter[currCounter].If++; - /* We keep track of the funcId of the last function which used ELSE {...} structure. */ - funcId_where_last_call_to_else_occurred = currCounter; + /* We keep track of the funcId of the last function which used ELSE {...} structure. */ + funcId_where_last_call_to_else_occurred = currCounter; - /* We keep track of the number of WMOPS of this funcId when the ELSE macro was called. */ - funcid_total_wmops_at_last_call_to_else = TotalWeightedOperation (); + /* We keep track of the number of WMOPS of this funcId when the ELSE macro was called. */ + funcid_total_wmops_at_last_call_to_else = TotalWeightedOperation(); - /* call_occurred is set to 0, in order to count the next IF (if necessary) */ - call_occurred = 0; + /* call_occurred is set to 0, in order to count the next IF (if necessary) */ + call_occurred = 0; } #endif /* ifndef WMOPS */ @@ -228,13 +236,14 @@ static __inline void incrElse (void) { * *****************************************************************************/ #ifndef WMOPS -#define SWITCH(a) switch (a) +#define SWITCH( a ) switch ( a ) #else /* ifndef WMOPS */ -#define SWITCH(a) switch (incrSwitch (), a) +#define SWITCH( a ) switch ( incrSwitch(), a ) -static __inline void incrSwitch (void) { - multiCounter[currCounter].Switch++; +static __inline void incrSwitch( void ) +{ + multiCounter[currCounter].Switch++; } #endif /* ifndef WMOPS */ @@ -254,10 +263,15 @@ static __inline void incrSwitch (void) { #define CONTINUE continue #else /* ifndef WMOPS */ -#define CONTINUE if (incrContinue (), 0); else continue - -static __inline void incrContinue (void) { - multiCounter[currCounter].Continue++; +#define CONTINUE \ + if ( incrContinue(), 0 ) \ + ; \ + else \ + continue + +static __inline void incrContinue( void ) +{ + multiCounter[currCounter].Continue++; } #endif /* ifndef WMOPS */ @@ -277,10 +291,15 @@ static __inline void incrContinue (void) { #define BREAK break #else /* ifndef WMOPS */ -#define BREAK if (incrBreak (), 0); else break - -static __inline void incrBreak (void) { - multiCounter[currCounter].Break++; +#define BREAK \ + if ( incrBreak(), 0 ) \ + ; \ + else \ + break + +static __inline void incrBreak( void ) +{ + multiCounter[currCounter].Break++; } #endif /* ifndef WMOPS */ @@ -300,41 +319,45 @@ static __inline void incrBreak (void) { #define GOTO goto #else /* ifndef WMOPS */ -#define GOTO if (incrGoto (), 0); else goto - -static __inline void incrGoto (void) { - multiCounter[currCounter].Goto++; +#define GOTO \ + if ( incrGoto(), 0 ) \ + ; \ + else \ + goto + +static __inline void incrGoto( void ) +{ + multiCounter[currCounter].Goto++; } #endif /* ifndef WMOPS */ - /* * New control code basops -*/ + */ #ifdef CONTROL_CODE_OPS -Flag LT_16 (Word16 var1, Word16 var2); -Flag GT_16 (Word16 var1, Word16 var2); -Flag LE_16 (Word16 var1, Word16 var2); -Flag GE_16 (Word16 var1, Word16 var2); -Flag EQ_16 (Word16 var1, Word16 var2); -Flag NE_16 (Word16 var1, Word16 var2); - -Flag LT_32 (Word32 L_var1, Word32 L_var2); -Flag GT_32 (Word32 L_var1, Word32 L_var2); -Flag LE_32 (Word32 L_var1, Word32 L_var2); -Flag GE_32 (Word32 L_var1, Word32 L_var2); -Flag EQ_32 (Word32 L_var1, Word32 L_var2); -Flag NE_32 (Word32 L_var1, Word32 L_var2); - -Flag LT_64 (Word64 L64_var1, Word64 L64_var2); -Flag GT_64 (Word64 L64_var1, Word64 L64_var2); -Flag LE_64 (Word64 L64_var1, Word64 L64_var2); -Flag GE_64 (Word64 L64_var1, Word64 L64_var2); -Flag EQ_64 (Word64 L64_var1, Word64 L64_var2); -Flag NE_64 (Word64 L64_var1, Word64 L64_var2); - +Flag LT_16( Word16 var1, Word16 var2 ); +Flag GT_16( Word16 var1, Word16 var2 ); +Flag LE_16( Word16 var1, Word16 var2 ); +Flag GE_16( Word16 var1, Word16 var2 ); +Flag EQ_16( Word16 var1, Word16 var2 ); +Flag NE_16( Word16 var1, Word16 var2 ); + +Flag LT_32( Word32 L_var1, Word32 L_var2 ); +Flag GT_32( Word32 L_var1, Word32 L_var2 ); +Flag LE_32( Word32 L_var1, Word32 L_var2 ); +Flag GE_32( Word32 L_var1, Word32 L_var2 ); +Flag EQ_32( Word32 L_var1, Word32 L_var2 ); +Flag NE_32( Word32 L_var1, Word32 L_var2 ); + +Flag LT_64( Word64 L64_var1, Word64 L64_var2 ); +Flag GT_64( Word64 L64_var1, Word64 L64_var2 ); +Flag LE_64( Word64 L64_var1, Word64 L64_var2 ); +Flag GE_64( Word64 L64_var1, Word64 L64_var2 ); +Flag EQ_64( Word64 L64_var1, Word64 L64_var2 ); +Flag NE_64( Word64 L64_var1, Word64 L64_var2 ); + #endif /* #ifdef CONTROL_CODE_OPS */ diff --git a/lib_com/core_com_config.c b/lib_com/core_com_config.c index e99e2323b..c91e6f782 100644 --- a/lib_com/core_com_config.c +++ b/lib_com/core_com_config.c @@ -58,15 +58,15 @@ Word16 is_EVS_bitrate( Word16 j; j = 0; - WHILE ( LT_16(j , SIZE_BRATE_TBL) && NE_32(ivas_total_brate , brate_tbl[j]) ) + WHILE( LT_16( j, SIZE_BRATE_TBL ) && NE_32( ivas_total_brate, brate_tbl[j] ) ) { j++; } /* AMR-WB IO mode/EVS primary mode determination */ - IF ( GE_16(j , SIZE_BRATE_TBL )) + IF( GE_16( j, SIZE_BRATE_TBL ) ) { - SWITCH ( ivas_total_brate ) + SWITCH( ivas_total_brate ) { case ACELP_6k60: case ACELP_8k85: @@ -82,7 +82,7 @@ Word16 is_EVS_bitrate( { return 0; } - BREAK; + BREAK; } *Opt_AMR_WB = 1; @@ -109,7 +109,7 @@ Word16 get_codec_mode( { Word16 codec_mode = -1; - SWITCH ( total_brate ) + SWITCH( total_brate ) { case 5900: codec_mode = MODE1; @@ -213,263 +213,264 @@ int16_t getTcxonly_ivas( Word16 getTcxonly( #ifdef IVAS_CODE_SWITCHING - const Word16 element_mode, /* i : IVAS element mode */ + const Word16 element_mode, /* i : IVAS element mode */ #endif - const Word32 total_brate /* i : total bitrate */ + const Word32 total_brate /* i : total bitrate */ #ifdef IVAS_CODE_SWITCHING - , const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0)*/ - const int16_t is_ism_format /* i : flag indicating ISM format */ + , + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0)*/ + const int16_t is_ism_format /* i : flag indicating ISM format */ #endif ) { - Word16 tcxonly; - tcxonly = 0; - move16(); -#ifdef IVAS_CODE_SWITCHING - SWITCH(element_mode) - { - case EVS_MONO: -#endif - if (GT_32(total_brate, 32000)) - { - tcxonly = 1; - move16(); - } + Word16 tcxonly; + tcxonly = 0; + move16(); #ifdef IVAS_CODE_SWITCHING - break; - case IVAS_SCE: - if (is_ism_format) - { - if (total_brate > MAX_ACELP_BRATE_ISM) - { - tcxonly = 1; - } - } - else - { - if (total_brate > MAX_ACELP_BRATE) - { - tcxonly = 1; - } - } - break; - - case IVAS_CPE_DFT: - case IVAS_CPE_TD: - if (total_brate > MAX_ACELP_BRATE) - { - tcxonly = 1; - } - break; - case IVAS_CPE_MDCT: - if (total_brate >= (MCT_flag ? IVAS_32k : IVAS_48k)) - { - tcxonly = 1; - } - break; -#endif - return tcxonly; - } - -Word16 getTcxonly_fx( - const Word16 element_mode, /* i : IVAS element mode */ - const Word32 total_brate, /* i : total bitrate */ - const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0)*/ - const Word16 is_ism_format /* i : flag indicating ISM format */ -) -{ - Word16 tcxonly = 0; - SWITCH( element_mode ) { case EVS_MONO: - IF( GT_32( total_brate, ACELP_32k ) ) +#endif + if ( GT_32( total_brate, 32000 ) ) { tcxonly = 1; + move16(); } - BREAK; +#ifdef IVAS_CODE_SWITCHING + break; case IVAS_SCE: - IF( is_ism_format ) + if ( is_ism_format ) { - IF( GT_32( total_brate, MAX_ACELP_BRATE_ISM ) ) + if ( total_brate > MAX_ACELP_BRATE_ISM ) { tcxonly = 1; } } - ELSE + else { - IF( GT_32( total_brate, MAX_ACELP_BRATE ) ) + if ( total_brate > MAX_ACELP_BRATE ) { tcxonly = 1; } } - BREAK; + break; case IVAS_CPE_DFT: case IVAS_CPE_TD: - IF( GT_32( total_brate, MAX_ACELP_BRATE ) ) + if ( total_brate > MAX_ACELP_BRATE ) { tcxonly = 1; } - BREAK; + break; case IVAS_CPE_MDCT: - IF( GE_32( total_brate, ( MCT_flag ? IVAS_32k : IVAS_48k ) ) ) + if ( total_brate >= ( MCT_flag ? IVAS_32k : IVAS_48k ) ) { tcxonly = 1; } - BREAK; + break; +#endif + return tcxonly; } - return tcxonly; -} + Word16 getTcxonly_fx( + const Word16 element_mode, /* i : IVAS element mode */ + const Word32 total_brate, /* i : total bitrate */ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0)*/ + const Word16 is_ism_format /* i : flag indicating ISM format */ + ) + { + Word16 tcxonly = 0; -/*-------------------------------------------------------------------* - * getCtxHm() - * - * - *-------------------------------------------------------------------*/ + SWITCH( element_mode ) + { + case EVS_MONO: + IF( GT_32( total_brate, ACELP_32k ) ) + { + tcxonly = 1; + } + BREAK; + case IVAS_SCE: + IF( is_ism_format ) + { + IF( GT_32( total_brate, MAX_ACELP_BRATE_ISM ) ) + { + tcxonly = 1; + } + } + ELSE + { + IF( GT_32( total_brate, MAX_ACELP_BRATE ) ) + { + tcxonly = 1; + } + } + BREAK; -Word16 getCtxHm( - const Word16 element_mode, /* i : IVAS element mode */ - const Word32 total_brate, /* i : total bitrate */ - const Word16 rf_flag /* i : flag to signal the RF mode */ -) -{ - Word16 ctx_hm; + case IVAS_CPE_DFT: + case IVAS_CPE_TD: + IF( GT_32( total_brate, MAX_ACELP_BRATE ) ) + { + tcxonly = 1; + } + BREAK; + case IVAS_CPE_MDCT: + IF( GE_32( total_brate, ( MCT_flag ? IVAS_32k : IVAS_48k ) ) ) + { + tcxonly = 1; + } + BREAK; + } - ctx_hm = 0; - move16(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - if ( ( ( LE_16( element_mode, IVAS_SCE ) && GT_32( total_brate, LPC_SHAPED_ARI_MAX_RATE ) ) || ( GT_16( element_mode, IVAS_SCE ) && GT_32( total_brate, LPC_SHAPED_ARI_MAX_RATE_CPE ) ) ) && !rf_flag && ( ( LE_32( total_brate, IVAS_64k ) && NE_16( element_mode, IVAS_CPE_DFT ) ) || ( LT_32( total_brate, 24400 ) && EQ_16( element_mode, IVAS_CPE_DFT ) ) ) && NE_16( element_mode, IVAS_CPE_MDCT ) ) - { - ctx_hm = 1; - move16(); + return tcxonly; } - return ctx_hm; -} - -/*-------------------------------------------------------------------* - * getResq() - * - * - *-------------------------------------------------------------------*/ - -Word16 getResq( - const Word32 total_brate /* i : total bitrate */ -) -{ - Word16 resq; + /*-------------------------------------------------------------------* + * getCtxHm() + * + * + *-------------------------------------------------------------------*/ - resq = 0; - move16(); - IF ( LE_32( total_brate, IVAS_64k ) ) + Word16 getCtxHm( + const Word16 element_mode, /* i : IVAS element mode */ + const Word32 total_brate, /* i : total bitrate */ + const Word16 rf_flag /* i : flag to signal the RF mode */ + ) { - resq = 1; - move16(); - } + Word16 ctx_hm; - return resq; -} + ctx_hm = 0; + move16(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + if ( ( ( LE_16( element_mode, IVAS_SCE ) && GT_32( total_brate, LPC_SHAPED_ARI_MAX_RATE ) ) || ( GT_16( element_mode, IVAS_SCE ) && GT_32( total_brate, LPC_SHAPED_ARI_MAX_RATE_CPE ) ) ) && !rf_flag && ( ( LE_32( total_brate, IVAS_64k ) && NE_16( element_mode, IVAS_CPE_DFT ) ) || ( LT_32( total_brate, 24400 ) && EQ_16( element_mode, IVAS_CPE_DFT ) ) ) && NE_16( element_mode, IVAS_CPE_MDCT ) ) + { + ctx_hm = 1; + move16(); + } -/*-------------------------------------------------------------------* - * getTnsAllowed() - * - * - *-------------------------------------------------------------------*/ + return ctx_hm; + } -Word16 getTnsAllowed( - const Word32 total_brate, /* i : total bitrate */ - const Word16 igf, /* i : flag indicating IGF activity*/ - const Word16 element_mode /* i : IVAS element mode */ -) -{ - Word16 tnsAllowed = 0; + /*-------------------------------------------------------------------* + * getResq() + * + * + *-------------------------------------------------------------------*/ - tnsAllowed = 0; - move16(); - IF( NE_16(igf , 0) ) + Word16 getResq( + const Word32 total_brate /* i : total bitrate */ + ) { - IF( GT_32( total_brate, HQ_16k40 ) || ( GT_32( total_brate, HQ_13k20 ) && EQ_16( element_mode, IVAS_CPE_DFT ) ) ) + Word16 resq; + + resq = 0; + move16(); + IF( LE_32( total_brate, IVAS_64k ) ) { - tnsAllowed = 1; + resq = 1; move16(); } + + return resq; } - ELSE + + /*-------------------------------------------------------------------* + * getTnsAllowed() + * + * + *-------------------------------------------------------------------*/ + + Word16 getTnsAllowed( + const Word32 total_brate, /* i : total bitrate */ + const Word16 igf, /* i : flag indicating IGF activity*/ + const Word16 element_mode /* i : IVAS element mode */ + ) { - IF( GT_32( total_brate, HQ_32k ) ) + Word16 tnsAllowed = 0; + + tnsAllowed = 0; + move16(); + IF( NE_16( igf, 0 ) ) { - tnsAllowed = 1; - move16(); + IF( GT_32( total_brate, HQ_16k40 ) || ( GT_32( total_brate, HQ_13k20 ) && EQ_16( element_mode, IVAS_CPE_DFT ) ) ) + { + tnsAllowed = 1; + move16(); + } + } + ELSE + { + IF( GT_32( total_brate, HQ_32k ) ) + { + tnsAllowed = 1; + move16(); + } } + + return tnsAllowed; } - return tnsAllowed; -} + /*-------------------------------------------------------------------* + * getRestrictedMode() + * + * + *-------------------------------------------------------------------*/ -/*-------------------------------------------------------------------* - * getRestrictedMode() - * - * - *-------------------------------------------------------------------*/ + Word16 getRestrictedMode( + const Word16 element_mode, /* i : IVAS element mode */ + const Word32 total_brate, /* i : total bitrate */ + const Word16 Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ + ) + { + Word16 restrictedMode = 3; -Word16 getRestrictedMode( - const Word16 element_mode, /* i : IVAS element mode */ - const Word32 total_brate, /* i : total bitrate */ - const Word16 Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ -) -{ - Word16 restrictedMode = 3; + IF( !Opt_AMR_WB && ( GT_32( total_brate, HQ_32k ) && NE_16( element_mode, IVAS_SCE ) ) ) + { + restrictedMode = 6; + } + ELSE IF( !Opt_AMR_WB && ( GT_32( total_brate, HQ_48k ) && EQ_16( element_mode, IVAS_SCE ) ) ) + { + restrictedMode = 6; + } + ELSE IF( Opt_AMR_WB ) + { + restrictedMode = 1; + } - IF ( !Opt_AMR_WB && ( GT_32(total_brate , HQ_32k) && NE_16(element_mode , IVAS_SCE) ) ) - { - restrictedMode = 6; - } - ELSE IF ( !Opt_AMR_WB && ( GT_32(total_brate , HQ_48k) && EQ_16(element_mode , IVAS_SCE) ) ) - { - restrictedMode = 6; - } - ELSE IF ( Opt_AMR_WB ) - { - restrictedMode = 1; + return restrictedMode; } - return restrictedMode; -} - -/*-------------------------------------------------------------------* - * getMdctWindowLength() - * - * - *-------------------------------------------------------------------*/ + /*-------------------------------------------------------------------* + * getMdctWindowLength() + * + * + *-------------------------------------------------------------------*/ -int16_t getMdctWindowLength( - const int16_t fscale ) -{ - int16_t mdctWindowLength; + int16_t getMdctWindowLength( + const int16_t fscale ) + { + int16_t mdctWindowLength; - mdctWindowLength = ( L_LOOK_12k8 * fscale ) / FSCALE_DENOM; + mdctWindowLength = ( L_LOOK_12k8 * fscale ) / FSCALE_DENOM; - return mdctWindowLength; -} + return mdctWindowLength; + } #ifdef IVAS_FLOAT_FIXED -Word16 getMdctWindowLength_fx( - const Word16 fscale ) -{ - Word16 mdctWindowLength; - mdctWindowLength = extract_l( L_shr( L_mult0( L_LOOK_12k8, fscale ), LD_FSCALE_DENOM ) ); + Word16 getMdctWindowLength_fx( + const Word16 fscale ) + { + Word16 mdctWindowLength; + mdctWindowLength = extract_l( L_shr( L_mult0( L_LOOK_12k8, fscale ), LD_FSCALE_DENOM ) ); - return mdctWindowLength; -} + return mdctWindowLength; + } #endif // IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* @@ -478,1076 +479,1094 @@ Word16 getMdctWindowLength_fx( * *-------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -Word16 sr2fscale_fx( - const Word32 sr_core /* i : internal sampling rate */ -) -{ - return (Word16) ( ( FSCALE_DENOM * sr_core ) / 12800 ); -} -#endif - -int16_t sr2fscale( - const int32_t sr_core /* i : internal sampling rate */ -) -{ - - return (int16_t) ( ( FSCALE_DENOM * sr_core ) / 12800 ); -} - -/*-------------------------------------------------------------------* - * getCoreSamplerateMode2_flt() - * - * - *-------------------------------------------------------------------*/ - -int32_t getCoreSamplerateMode2_flt( - const int16_t element_mode, /* i : IVAS element mode */ - const int32_t total_brate, /* i : total bitrate */ - const int16_t bwidth, /* i : audio bandwidth */ - const int16_t flag_ACELP16k, /* i : ACELP@16kHz flag */ - const int16_t rf_mode, /* i : flag to signal the RF mode */ - const IVAS_FORMAT is_ism_format /* i : flag indicating ISM format */ -) -{ - int32_t sr_core = 0; - - if ( bwidth == NB ) - { - sr_core = INT_FS_12k8; - } - else if ( element_mode == EVS_MONO && ( ( bwidth == WB && total_brate < ACELP_13k20 ) || ( bwidth == SWB && total_brate <= ACELP_13k20 ) || ( rf_mode == 1 ) ) ) - { - sr_core = INT_FS_12k8; - } - else if ( element_mode > EVS_MONO && flag_ACELP16k == 0 ) - { - sr_core = INT_FS_12k8; - } - else if ( bwidth == WB || ( bwidth == SWB && total_brate <= ACELP_32k ) || ( bwidth == FB && total_brate <= ACELP_32k ) ) - { - sr_core = INT_FS_16k; - } - else if ( ( bwidth == SWB || bwidth == FB ) && total_brate <= MAX_ACELP_BRATE && element_mode == IVAS_SCE && !is_ism_format ) - { - sr_core = INT_FS_16k; - } - else if ( ( bwidth == SWB || bwidth == FB ) && total_brate <= MAX_ACELP_BRATE_ISM && element_mode == IVAS_SCE && is_ism_format ) - { - sr_core = INT_FS_16k; - } - else if ( ( bwidth == SWB || bwidth == FB ) && total_brate <= MAX_ACELP_BRATE && element_mode == IVAS_SCE && is_ism_format ) + Word16 sr2fscale_fx( + const Word32 sr_core /* i : internal sampling rate */ + ) { - sr_core = 25600; + return (Word16) ( ( FSCALE_DENOM * sr_core ) / 12800 ); } - else if ( ( ( bwidth == SWB || bwidth == FB ) && element_mode == EVS_MONO && total_brate <= HQ_64k ) || ( element_mode > IVAS_SCE && ( ( bwidth == SWB && total_brate <= IVAS_96k ) || ( bwidth == FB && total_brate <= IVAS_96k ) ) ) ) - { - sr_core = 25600; - } - else if ( bwidth == SWB || bwidth == FB ) - { - sr_core = 32000; - } - - return sr_core; -} - -Word32 getCoreSamplerateMode2( - const Word16 element_mode, /* i : IVAS element mode */ - const Word32 total_brate, /* i : total bitrate */ - const Word16 bwidth, /* i : audio bandwidth */ - const Word16 flag_ACELP16k, /* i : ACELP@16kHz flag */ - const Word16 rf_mode, /* i : flag to signal the RF mode */ - const IVAS_FORMAT is_ism_format /* i : flag indicating ISM format */ -) -{ +#endif - Word32 sr_core; - Word16 bwd_swb_or_fb_flag; - sr_core = -1; /* to suppress MSVC warning */ move32(); - - bwd_swb_or_fb_flag = s_or((Word16)EQ_16(bwidth, SWB), (Word16)EQ_16(bwidth, FB)); - test(); test(); test(); test(); test(); test(); test(); test(); test(); test(); - test(); test(); test(); test(); test(); test(); test(); - test(); test(); test(); test(); test(); - IF(EQ_32(bwidth, NB)) - { - sr_core = INT_FS_12k8; - move32(); - } - ELSE IF(EQ_16(element_mode, EVS_MONO) && (L_and(EQ_32(bwidth, WB), LT_32(total_brate, ACELP_13k20)) || - L_and(EQ_32(bwidth, SWB), LE_32(total_brate, ACELP_13k20)) || EQ_16(rf_mode, 1))) - - { - sr_core = INT_FS_12k8; - move32(); - } - ELSE IF(GT_16(element_mode, EVS_MONO) && flag_ACELP16k == 0) - { - sr_core = INT_FS_12k8; - move32(); - } - ELSE IF(EQ_32(bwidth, WB) || ((LE_32(total_brate, ACELP_32k)) && ((EQ_32(bwidth, SWB)) || (EQ_32(bwidth, FB))))) - { - sr_core = INT_FS_16k; - move32(); - } - ELSE IF(bwd_swb_or_fb_flag && LE_32(total_brate, MAX_ACELP_BRATE) && EQ_16(element_mode, IVAS_SCE) && !is_ism_format) - { - sr_core = INT_FS_16k; - move32(); - } - ELSE IF(bwd_swb_or_fb_flag && LE_32(total_brate, MAX_ACELP_BRATE_ISM) && EQ_16(element_mode, IVAS_SCE) && is_ism_format) - { - sr_core = INT_FS_16k; - } - ELSE IF (bwd_swb_or_fb_flag && LE_32(total_brate, MAX_ACELP_BRATE) && EQ_16(element_mode, IVAS_SCE) && is_ism_format) - { - sr_core = 25600; - } - ELSE IF((EQ_16(element_mode, EVS_MONO) && (bwd_swb_or_fb_flag && LE_32(total_brate, HQ_64k))) - || (GT_16(element_mode, IVAS_SCE) && ((EQ_16(bwidth, SWB) && LE_32(total_brate, IVAS_96k)) || (EQ_16(bwidth, FB) && LE_32(total_brate, IVAS_96k))))) - { - sr_core = 25600; - move32(); - } - ELSE IF(bwd_swb_or_fb_flag) - { - sr_core = 32000; - move32(); - } - ELSE + int16_t sr2fscale( + const int32_t sr_core /* i : internal sampling rate */ + ) { - assert(0); - } - - return sr_core; -} - -Word16 getTcxBandwidth( - const Word16 bwidth /* i : audio bandwidth */ -) -{ - - Word16 tcxBandwidth; - tcxBandwidth = 16384/*0.5f Q15*/; - move16(); - if (EQ_16(bwidth, NB)) - { - tcxBandwidth = 10240/*0.3125f Q15*/; - move16(); - - } - - return tcxBandwidth; -} - -/*-------------------------------------------------------------------* - * getTcxBandwidth_flt() - * - * - *-------------------------------------------------------------------*/ + return (int16_t) ( ( FSCALE_DENOM * sr_core ) / 12800 ); + } -float getTcxBandwidth_flt( - const int16_t bwidth /* i : audio bandwidth */ -) -{ - float tcxBandwidth = 0.5f; + /*-------------------------------------------------------------------* + * getCoreSamplerateMode2_flt() + * + * + *-------------------------------------------------------------------*/ - if ( bwidth == NB ) + int32_t getCoreSamplerateMode2_flt( + const int16_t element_mode, /* i : IVAS element mode */ + const int32_t total_brate, /* i : total bitrate */ + const int16_t bwidth, /* i : audio bandwidth */ + const int16_t flag_ACELP16k, /* i : ACELP@16kHz flag */ + const int16_t rf_mode, /* i : flag to signal the RF mode */ + const IVAS_FORMAT is_ism_format /* i : flag indicating ISM format */ + ) { - tcxBandwidth = 0.3125f; - } + int32_t sr_core = 0; - return tcxBandwidth; -} + if ( bwidth == NB ) + { + sr_core = INT_FS_12k8; + } + else if ( element_mode == EVS_MONO && ( ( bwidth == WB && total_brate < ACELP_13k20 ) || ( bwidth == SWB && total_brate <= ACELP_13k20 ) || ( rf_mode == 1 ) ) ) + { + sr_core = INT_FS_12k8; + } + else if ( element_mode > EVS_MONO && flag_ACELP16k == 0 ) + { + sr_core = INT_FS_12k8; + } + else if ( bwidth == WB || ( bwidth == SWB && total_brate <= ACELP_32k ) || ( bwidth == FB && total_brate <= ACELP_32k ) ) + { + sr_core = INT_FS_16k; + } + else if ( ( bwidth == SWB || bwidth == FB ) && total_brate <= MAX_ACELP_BRATE && element_mode == IVAS_SCE && !is_ism_format ) + { + sr_core = INT_FS_16k; + } + else if ( ( bwidth == SWB || bwidth == FB ) && total_brate <= MAX_ACELP_BRATE_ISM && element_mode == IVAS_SCE && is_ism_format ) + { + sr_core = INT_FS_16k; + } + else if ( ( bwidth == SWB || bwidth == FB ) && total_brate <= MAX_ACELP_BRATE && element_mode == IVAS_SCE && is_ism_format ) + { + sr_core = 25600; + } + else if ( ( ( bwidth == SWB || bwidth == FB ) && element_mode == EVS_MONO && total_brate <= HQ_64k ) || ( element_mode > IVAS_SCE && ( ( bwidth == SWB && total_brate <= IVAS_96k ) || ( bwidth == FB && total_brate <= IVAS_96k ) ) ) ) + { + sr_core = 25600; + } + else if ( bwidth == SWB || bwidth == FB ) + { + sr_core = 32000; + } -/*-------------------------------------------------------------------* - * getIgfPresent() - * - * - *-------------------------------------------------------------------*/ + return sr_core; + } -int16_t getIgfPresent( - const int16_t element_mode, /* i : IVAS element mode */ - const int32_t total_brate, /* i : total bitrate */ - const int16_t bwidth, /* i : audio bandwidth */ - const int16_t rf_mode /* i : flag to signal the RF mode */ -) -{ - int16_t igfPresent = 0; + Word32 getCoreSamplerateMode2( + const Word16 element_mode, /* i : IVAS element mode */ + const Word32 total_brate, /* i : total bitrate */ + const Word16 bwidth, /* i : audio bandwidth */ + const Word16 flag_ACELP16k, /* i : ACELP@16kHz flag */ + const Word16 rf_mode, /* i : flag to signal the RF mode */ + const IVAS_FORMAT is_ism_format /* i : flag indicating ISM format */ + ) + { + Word32 sr_core; + Word16 bwd_swb_or_fb_flag; + sr_core = -1; /* to suppress MSVC warning */ + move32(); - if ( bwidth == SWB ) - { - switch ( element_mode ) + bwd_swb_or_fb_flag = s_or( (Word16) EQ_16( bwidth, SWB ), (Word16) EQ_16( bwidth, FB ) ); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( EQ_32( bwidth, NB ) ) { - case EVS_MONO: - case IVAS_SCE: - if ( total_brate <= HQ_64k ) - { - igfPresent = 1; - } - break; - case IVAS_CPE_DFT: - case IVAS_CPE_TD: - if ( total_brate <= HQ_48k ) - { - igfPresent = 1; - } - break; - case IVAS_CPE_MDCT: - if ( total_brate <= IVAS_96k ) - { - igfPresent = 1; - } - break; + sr_core = INT_FS_12k8; + move32(); } - } - else if ( bwidth == FB ) - { - switch ( element_mode ) + ELSE IF( EQ_16( element_mode, EVS_MONO ) && ( L_and( EQ_32( bwidth, WB ), LT_32( total_brate, ACELP_13k20 ) ) || + L_and( EQ_32( bwidth, SWB ), LE_32( total_brate, ACELP_13k20 ) ) || EQ_16( rf_mode, 1 ) ) ) + { - case EVS_MONO: - case IVAS_SCE: - if ( total_brate <= IVAS_128k ) - { - igfPresent = 1; - } - break; - case IVAS_CPE_DFT: - case IVAS_CPE_TD: - if ( total_brate <= IVAS_48k ) - { - igfPresent = 1; - } - break; - case IVAS_CPE_MDCT: - if ( total_brate <= IVAS_128k ) - { - igfPresent = 1; - } - break; + sr_core = INT_FS_12k8; + move32(); } - } - else if ( bwidth == WB ) - { - switch ( element_mode ) + ELSE IF( GT_16( element_mode, EVS_MONO ) && flag_ACELP16k == 0 ) { - case EVS_MONO: - case IVAS_SCE: - if ( total_brate <= ACELP_9k60 ) - { - igfPresent = 1; - } - break; - case IVAS_CPE_DFT: - case IVAS_CPE_TD: - case IVAS_CPE_MDCT: - if ( total_brate <= ACELP_13k20 ) - { - igfPresent = 1; - } - break; + sr_core = INT_FS_12k8; + move32(); } - } - - if ( ( ( bwidth == WB ) || ( bwidth == SWB ) ) && ( rf_mode == 1 ) && ( total_brate == ACELP_13k20 ) ) - { - igfPresent = 1; - } - - return igfPresent; -} - -Word16 getIgfPresent_fx( - const Word16 element_mode, /* i : IVAS element mode */ - const Word32 total_brate, /* i : total bitrate */ - const Word16 bwidth, /* i : audio bandwidth */ - const Word16 rf_mode /* i : flag to signal the RF mode */ -) -{ - Word16 igfPresent = 0; - move16(); - - IF( EQ_16( bwidth, SWB ) ) - { - SWITCH( element_mode ) + ELSE IF( EQ_32( bwidth, WB ) || ( ( LE_32( total_brate, ACELP_32k ) ) && ( ( EQ_32( bwidth, SWB ) ) || ( EQ_32( bwidth, FB ) ) ) ) ) { - case EVS_MONO: - case IVAS_SCE: - IF( LE_32( total_brate, HQ_64k ) ) - { - igfPresent = 1; - move16(); - } - BREAK; - case IVAS_CPE_DFT: - case IVAS_CPE_TD: - IF( LE_32( total_brate, HQ_48k ) ) - { - igfPresent = 1; - move16(); - } - BREAK; - case IVAS_CPE_MDCT: - IF( LE_32( total_brate, IVAS_96k ) ) - { - igfPresent = 1; - move16(); - } - BREAK; + sr_core = INT_FS_16k; + move32(); } - } - ELSE IF( EQ_16( bwidth, FB ) ) - { - SWITCH( element_mode ) + ELSE IF( bwd_swb_or_fb_flag && LE_32( total_brate, MAX_ACELP_BRATE ) && EQ_16( element_mode, IVAS_SCE ) && !is_ism_format ) { - case EVS_MONO: - case IVAS_SCE: - IF( LE_32( total_brate, IVAS_128k ) ) - { - igfPresent = 1; - move16(); - } - BREAK; - case IVAS_CPE_DFT: - case IVAS_CPE_TD: - IF( LE_32( total_brate, IVAS_48k ) ) - { - igfPresent = 1; - move16(); - } - BREAK; - case IVAS_CPE_MDCT: - IF( LE_32( total_brate, IVAS_128k ) ) - { - igfPresent = 1; - move16(); - } - BREAK; + sr_core = INT_FS_16k; + move32(); } - } - ELSE IF( bwidth == WB ) - { - SWITCH ( element_mode ) + ELSE IF( bwd_swb_or_fb_flag && LE_32( total_brate, MAX_ACELP_BRATE_ISM ) && EQ_16( element_mode, IVAS_SCE ) && is_ism_format ) { - case EVS_MONO: - case IVAS_SCE: - IF( LE_32( total_brate, ACELP_9k60 ) ) - { - igfPresent = 1; - move16(); - } - BREAK; - case IVAS_CPE_DFT: - case IVAS_CPE_TD: - case IVAS_CPE_MDCT: - IF ( LE_32( total_brate, ACELP_13k20 ) ) - { - igfPresent = 1; - move16(); - } - BREAK; + sr_core = INT_FS_16k; } - } - test(); - test(); - test(); - IF ( ( ( EQ_16( bwidth, WB ) ) || ( EQ_16( bwidth, SWB ) ) ) && ( EQ_16( rf_mode, 1 ) ) && ( EQ_32( total_brate, ACELP_13k20 ) ) ) - { - igfPresent = 1; - move16(); - } - - return igfPresent; -} -/*-------------------------------------------------------------------* - * getCnaPresent() - * - * - *-------------------------------------------------------------------*/ - -int16_t getCnaPresent( - const int16_t element_mode, /* i : element mode */ - const int32_t element_brate, /* i : element bitrate */ - const int32_t total_brate, /* i : total bitrate */ - const int16_t bwidth /* i : audio bandwidth */ -) -{ - int16_t flag_cna = 0; - - if ( element_mode == IVAS_CPE_DFT && element_brate <= CNA_MAX_BRATE_DFT_STEREO ) - { - flag_cna = 1; - } - else - { - if ( bwidth == NB && total_brate <= ACELP_13k20 ) + ELSE IF( bwd_swb_or_fb_flag && LE_32( total_brate, MAX_ACELP_BRATE ) && EQ_16( element_mode, IVAS_SCE ) && is_ism_format ) { - flag_cna = 1; + sr_core = 25600; } - - if ( bwidth == WB && total_brate <= ACELP_13k20 ) + ELSE IF( ( EQ_16( element_mode, EVS_MONO ) && ( bwd_swb_or_fb_flag && LE_32( total_brate, HQ_64k ) ) ) || ( GT_16( element_mode, IVAS_SCE ) && ( ( EQ_16( bwidth, SWB ) && LE_32( total_brate, IVAS_96k ) ) || ( EQ_16( bwidth, FB ) && LE_32( total_brate, IVAS_96k ) ) ) ) ) { - flag_cna = 1; + sr_core = 25600; + move32(); } - - if ( bwidth == SWB && total_brate <= ACELP_13k20 ) + ELSE IF( bwd_swb_or_fb_flag ) { - flag_cna = 1; + sr_core = 32000; + move32(); } + ELSE + { + assert( 0 ); + } + + return sr_core; } - return flag_cna; -} + Word16 getTcxBandwidth( + const Word16 bwidth /* i : audio bandwidth */ + ) + { -Word16 getCnaPresent_fx( - const Word16 element_mode, /* i : element mode */ - const Word32 element_brate, /* i : element bitrate */ - const Word32 total_brate, /* i : total bitrate */ - const Word16 bwidth /* i : audio bandwidth */ -) -{ - Word16 flag_cna = 0; + Word16 tcxBandwidth; - IF( EQ_16( element_mode, IVAS_CPE_DFT ) && LE_32( element_brate, CNA_MAX_BRATE_DFT_STEREO ) ) - { - flag_cna = 1; - } - ELSE - { + tcxBandwidth = 16384 /*0.5f Q15*/; move16(); - test(); - IF ( LE_16( bwidth, SWB ) && ( LE_32( total_brate, ACELP_13k20 ) ) ) + if ( EQ_16( bwidth, NB ) ) { - flag_cna = 1; + tcxBandwidth = 10240 /*0.3125f Q15*/; move16(); } - } - return flag_cna; -} -/*-------------------------------------------------------------------* - * getTcxLtp() - * - * - *-------------------------------------------------------------------*/ + return tcxBandwidth; + } -Word16 getTcxLtp( - const Word32 sr_core /* i : internal sampling rate */ -) -{ - Word16 tcxltp = 0; + /*-------------------------------------------------------------------* + * getTcxBandwidth_flt() + * + * + *-------------------------------------------------------------------*/ - tcxltp = 0; - move16(); - test(); - IF( ( LE_32( sr_core, 25600 ) ) ) + float getTcxBandwidth_flt( + const int16_t bwidth /* i : audio bandwidth */ + ) { - tcxltp = 1; - move16(); - } + float tcxBandwidth = 0.5f; - return tcxltp; -} + if ( bwidth == NB ) + { + tcxBandwidth = 0.3125f; + } -/*-------------------------------------------------------------------* - * initPitchLagParameters() - * - * - *-------------------------------------------------------------------*/ + return tcxBandwidth; + } -Word16 initPitchLagParameters( - const Word32 sr_core, - Word16 *pit_min, - Word16 *pit_fr1, - Word16 *pit_fr1b, - Word16 *pit_fr2, - Word16 *pit_max ) -{ - Word16 pit_res_max; + /*-------------------------------------------------------------------* + * getIgfPresent() + * + * + *-------------------------------------------------------------------*/ - IF( EQ_32( sr_core, INT_FS_12k8 ) ) + int16_t getIgfPresent( + const int16_t element_mode, /* i : IVAS element mode */ + const int32_t total_brate, /* i : total bitrate */ + const int16_t bwidth, /* i : audio bandwidth */ + const int16_t rf_mode /* i : flag to signal the RF mode */ + ) { - *pit_min = PIT_MIN_12k8; - move16(); - *pit_max = PIT_MAX_12k8; - move16(); - *pit_fr2 = PIT_FR2_12k8; - move16(); - *pit_fr1 = PIT_FR1_12k8; - move16(); - *pit_fr1b = PIT_FR1_8b_12k8; - move16(); - pit_res_max = 4; - move16(); - } - ELSE IF( EQ_32( sr_core, INT_FS_16k ) ) - { - *pit_min = PIT_MIN_16k; - move16(); - *pit_max = PIT16k_MAX; - move16(); - *pit_fr2 = PIT_FR2_16k; - move16(); - *pit_fr1 = PIT_FR1_16k; - move16(); - *pit_fr1b = PIT_FR1_8b_16k; - move16(); - pit_res_max = 6; - move16(); - } - ELSE IF( EQ_32(sr_core , 25600) ) - { - *pit_min = PIT_MIN_25k6; - move16(); - *pit_max = PIT_MAX_25k6; - move16(); - *pit_fr2 = PIT_FR2_25k6; - move16(); - *pit_fr1 = PIT_FR1_25k6; - move16(); - *pit_fr1b = PIT_FR1_8b_25k6; - move16(); - pit_res_max = 4; - move16(); - } - ELSE /* sr_core==32000 */ - { - *pit_min = PIT_MIN_32k; - move16(); - *pit_max = PIT_MAX_32k; - move16(); - *pit_fr2 = PIT_FR2_32k; - move16(); - *pit_fr1 = PIT_FR1_32k; - move16(); - *pit_fr1b = PIT_FR1_8b_32k; - move16(); - pit_res_max = 6; - move16(); - } + int16_t igfPresent = 0; - return pit_res_max; -} -/*-------------------------------------------------------------------* - * getNumTcxCodedLines() - * - * - *-------------------------------------------------------------------*/ + if ( bwidth == SWB ) + { + switch ( element_mode ) + { + case EVS_MONO: + case IVAS_SCE: + if ( total_brate <= HQ_64k ) + { + igfPresent = 1; + } + break; + case IVAS_CPE_DFT: + case IVAS_CPE_TD: + if ( total_brate <= HQ_48k ) + { + igfPresent = 1; + } + break; + case IVAS_CPE_MDCT: + if ( total_brate <= IVAS_96k ) + { + igfPresent = 1; + } + break; + } + } + else if ( bwidth == FB ) + { + switch ( element_mode ) + { + case EVS_MONO: + case IVAS_SCE: + if ( total_brate <= IVAS_128k ) + { + igfPresent = 1; + } + break; + case IVAS_CPE_DFT: + case IVAS_CPE_TD: + if ( total_brate <= IVAS_48k ) + { + igfPresent = 1; + } + break; + case IVAS_CPE_MDCT: + if ( total_brate <= IVAS_128k ) + { + igfPresent = 1; + } + break; + } + } + else if ( bwidth == WB ) + { + switch ( element_mode ) + { + case EVS_MONO: + case IVAS_SCE: + if ( total_brate <= ACELP_9k60 ) + { + igfPresent = 1; + } + break; + case IVAS_CPE_DFT: + case IVAS_CPE_TD: + case IVAS_CPE_MDCT: + if ( total_brate <= ACELP_13k20 ) + { + igfPresent = 1; + } + break; + } + } -Word16 getNumTcxCodedLines( - const Word16 bwidth /* i : audio bandwidth */ -) -{ - Word16 tcx_coded_lines; + if ( ( ( bwidth == WB ) || ( bwidth == SWB ) ) && ( rf_mode == 1 ) && ( total_brate == ACELP_13k20 ) ) + { + igfPresent = 1; + } - tcx_coded_lines = 0; - move16(); + return igfPresent; + } - SWITCH( bwidth ) + Word16 getIgfPresent_fx( + const Word16 element_mode, /* i : IVAS element mode */ + const Word32 total_brate, /* i : total bitrate */ + const Word16 bwidth, /* i : audio bandwidth */ + const Word16 rf_mode /* i : flag to signal the RF mode */ + ) { - case NB: - tcx_coded_lines = 160; - BREAK; - case WB: - tcx_coded_lines = 320; - BREAK; - case SWB: - tcx_coded_lines = 640; - BREAK; - case FB: - tcx_coded_lines = 960; - BREAK; - default: - tcx_coded_lines = 0; - BREAK; + Word16 igfPresent = 0; + move16(); + + IF( EQ_16( bwidth, SWB ) ) + { + SWITCH( element_mode ) + { + case EVS_MONO: + case IVAS_SCE: + IF( LE_32( total_brate, HQ_64k ) ) + { + igfPresent = 1; + move16(); + } + BREAK; + case IVAS_CPE_DFT: + case IVAS_CPE_TD: + IF( LE_32( total_brate, HQ_48k ) ) + { + igfPresent = 1; + move16(); + } + BREAK; + case IVAS_CPE_MDCT: + IF( LE_32( total_brate, IVAS_96k ) ) + { + igfPresent = 1; + move16(); + } + BREAK; + } + } + ELSE IF( EQ_16( bwidth, FB ) ) + { + SWITCH( element_mode ) + { + case EVS_MONO: + case IVAS_SCE: + IF( LE_32( total_brate, IVAS_128k ) ) + { + igfPresent = 1; + move16(); + } + BREAK; + case IVAS_CPE_DFT: + case IVAS_CPE_TD: + IF( LE_32( total_brate, IVAS_48k ) ) + { + igfPresent = 1; + move16(); + } + BREAK; + case IVAS_CPE_MDCT: + IF( LE_32( total_brate, IVAS_128k ) ) + { + igfPresent = 1; + move16(); + } + BREAK; + } + } + ELSE IF( bwidth == WB ) + { + SWITCH( element_mode ) + { + case EVS_MONO: + case IVAS_SCE: + IF( LE_32( total_brate, ACELP_9k60 ) ) + { + igfPresent = 1; + move16(); + } + BREAK; + case IVAS_CPE_DFT: + case IVAS_CPE_TD: + case IVAS_CPE_MDCT: + IF( LE_32( total_brate, ACELP_13k20 ) ) + { + igfPresent = 1; + move16(); + } + BREAK; + } + } + test(); + test(); + test(); + IF( ( ( EQ_16( bwidth, WB ) ) || ( EQ_16( bwidth, SWB ) ) ) && ( EQ_16( rf_mode, 1 ) ) && ( EQ_32( total_brate, ACELP_13k20 ) ) ) + { + igfPresent = 1; + move16(); + } + + return igfPresent; } + /*-------------------------------------------------------------------* + * getCnaPresent() + * + * + *-------------------------------------------------------------------*/ - return tcx_coded_lines; -} + int16_t getCnaPresent( + const int16_t element_mode, /* i : element mode */ + const int32_t element_brate, /* i : element bitrate */ + const int32_t total_brate, /* i : total bitrate */ + const int16_t bwidth /* i : audio bandwidth */ + ) + { + int16_t flag_cna = 0; -/*-------------------------------------------------------------------* - * getTcxLpcShapedAri() - * - * - *-------------------------------------------------------------------*/ + if ( element_mode == IVAS_CPE_DFT && element_brate <= CNA_MAX_BRATE_DFT_STEREO ) + { + flag_cna = 1; + } + else + { + if ( bwidth == NB && total_brate <= ACELP_13k20 ) + { + flag_cna = 1; + } -Word16 getTcxLpcShapedAri( - const Word32 total_brate, /* i : total bitrate */ - const Word16 rf_mode, /* i : flag to signal the RF mode */ - const Word16 element_mode /* i : IVAS element mode */ -) -{ - Word16 tcx_lpc_shaped_ari = 0; + if ( bwidth == WB && total_brate <= ACELP_13k20 ) + { + flag_cna = 1; + } - move16(); - test(); - test(); - test(); - IF( ( ( LE_16( element_mode, IVAS_SCE ) && LE_32( total_brate, LPC_SHAPED_ARI_MAX_RATE ) ) || ( GT_16( element_mode, IVAS_SCE ) && LE_32( total_brate, LPC_SHAPED_ARI_MAX_RATE_CPE ) ) ) || rf_mode ) - { - tcx_lpc_shaped_ari = 1; - move16(); + if ( bwidth == SWB && total_brate <= ACELP_13k20 ) + { + flag_cna = 1; + } + } + + return flag_cna; } - return tcx_lpc_shaped_ari; -} + Word16 getCnaPresent_fx( + const Word16 element_mode, /* i : element mode */ + const Word32 element_brate, /* i : element bitrate */ + const Word32 total_brate, /* i : total bitrate */ + const Word16 bwidth /* i : audio bandwidth */ + ) + { + Word16 flag_cna = 0; + IF( EQ_16( element_mode, IVAS_CPE_DFT ) && LE_32( element_brate, CNA_MAX_BRATE_DFT_STEREO ) ) + { + flag_cna = 1; + } + ELSE + { + move16(); + test(); + IF( LE_16( bwidth, SWB ) && ( LE_32( total_brate, ACELP_13k20 ) ) ) + { + flag_cna = 1; + move16(); + } + } -/*-----------------------------------------------------------------------* - * init_tcx_window_cfg() - * - * Initialization of TCX windows - *-----------------------------------------------------------------------*/ - -void init_tcx_window_cfg( - TCX_CONFIG_HANDLE hTcxCfg, /* i/o: TCX Config handle */ - const int32_t sr_core, /* i : SR core */ - const int32_t input_Fs, /* i : input/output SR */ - const int16_t L_frame, /* i : L_frame at sr_core */ - const int16_t L_frameTCX, /* i : L_frame at i/o SR */ - const int16_t encoderLookahead_enc, /* i : encoder LA at sr_core */ - const int16_t encoderLookahead_FB, /* i : encoder LA at i/o SR */ - const int16_t mdctWindowLength, /* i : window length at sr_core */ - const int16_t mdctWindowLengthFB, /* i : window length at i/o SR */ - const int16_t element_mode /* i : mode of CPE/SCE */ -) -{ - /* Symmetric window = sine LD window*/ - hTcxCfg->tcx_mdct_window_delay = mdctWindowLength; - hTcxCfg->tcx_mdct_window_delayFB = mdctWindowLengthFB; - hTcxCfg->tcx_mdct_window_length = mdctWindowLength; - hTcxCfg->tcx_mdct_window_lengthFB = mdctWindowLengthFB; - - mdct_window_sine_flt( hTcxCfg->tcx_mdct_window_flt, sr_core, hTcxCfg->tcx_mdct_window_length, FULL_OVERLAP, element_mode ); - if ( hTcxCfg->tcx_mdct_window_length == hTcxCfg->tcx_mdct_window_lengthFB ) - { - mvr2r( hTcxCfg->tcx_mdct_window_flt, hTcxCfg->tcx_mdct_windowFB_flt, hTcxCfg->tcx_mdct_window_length ); - } - else - { - mdct_window_sine_flt( hTcxCfg->tcx_mdct_windowFB_flt, input_Fs, hTcxCfg->tcx_mdct_window_lengthFB, FULL_OVERLAP, element_mode ); + return flag_cna; } + /*-------------------------------------------------------------------* + * getTcxLtp() + * + * + *-------------------------------------------------------------------*/ - /*ALDO windows for MODE2*/ - mdct_window_aldo_flt( hTcxCfg->tcx_aldo_window_1_flt, hTcxCfg->tcx_aldo_window_2_flt, L_frame ); - mdct_window_aldo_flt( hTcxCfg->tcx_aldo_window_1_FB_flt, hTcxCfg->tcx_aldo_window_2_FB_flt, NS2SA( input_Fs, FRAME_SIZE_NS ) ); - hTcxCfg->tcx_aldo_window_1_trunc_flt = hTcxCfg->tcx_aldo_window_1_flt + NS2SA( sr_core, N_ZERO_MDCT_NS ); - hTcxCfg->tcx_aldo_window_1_FB_trunc_flt = hTcxCfg->tcx_aldo_window_1_FB_flt + NS2SA( input_Fs, N_ZERO_MDCT_NS ); - - /*1.25ms transition window for ACELP->TCX*/ - hTcxCfg->tcx_mdct_window_trans_length = NS2SA( sr_core, ACELP_TCX_TRANS_NS ); - mdct_window_sine_flt( hTcxCfg->tcx_mdct_window_trans_flt, sr_core, hTcxCfg->tcx_mdct_window_trans_length, TRANSITION_OVERLAP, element_mode ); - hTcxCfg->tcx_mdct_window_trans_lengthFB = NS2SA( input_Fs, ACELP_TCX_TRANS_NS ); - if ( hTcxCfg->tcx_mdct_window_trans_length == hTcxCfg->tcx_mdct_window_trans_lengthFB ) + Word16 getTcxLtp( + const Word32 sr_core /* i : internal sampling rate */ + ) { - mvr2r( hTcxCfg->tcx_mdct_window_trans_flt, hTcxCfg->tcx_mdct_window_transFB_flt, hTcxCfg->tcx_mdct_window_trans_length ); - } - else - { - mdct_window_sine_flt( hTcxCfg->tcx_mdct_window_transFB_flt, input_Fs, hTcxCfg->tcx_mdct_window_trans_lengthFB, TRANSITION_OVERLAP, element_mode ); - } + Word16 tcxltp = 0; - /*Mid-OLA*/ - /*compute minimum length for "half" window: lookahead - 5ms. It must be also multiple of 2*/ - hTcxCfg->tcx_mdct_window_half_length = 2 * ( ( encoderLookahead_enc - (int16_t) ( 0.005f * sr_core + 0.5f ) ) >> 1 ); - hTcxCfg->tcx_mdct_window_half_lengthFB = 2 * ( ( encoderLookahead_FB - (int16_t) ( 0.005f * input_Fs + 0.5f ) ) >> 1 ); - assert( ( hTcxCfg->tcx_mdct_window_half_length > 16 ) && "Half window can not be large enough!" ); + tcxltp = 0; + move16(); + test(); + IF( ( LE_32( sr_core, 25600 ) ) ) + { + tcxltp = 1; + move16(); + } - mdct_window_sine_flt( hTcxCfg->tcx_mdct_window_half_flt, sr_core, hTcxCfg->tcx_mdct_window_half_length, HALF_OVERLAP, element_mode ); - if ( hTcxCfg->tcx_mdct_window_half_length == hTcxCfg->tcx_mdct_window_half_lengthFB ) - { - mvr2r( hTcxCfg->tcx_mdct_window_half_flt, hTcxCfg->tcx_mdct_window_halfFB_flt, hTcxCfg->tcx_mdct_window_half_length ); - } - else - { - mdct_window_sine_flt( hTcxCfg->tcx_mdct_window_halfFB_flt, input_Fs, hTcxCfg->tcx_mdct_window_half_lengthFB, HALF_OVERLAP, element_mode ); + return tcxltp; } - /* minimum overlap 1.25 ms */ - hTcxCfg->tcx_mdct_window_min_length = (int16_t) ( sr_core * INV_CLDFB_BANDWIDTH ); - hTcxCfg->tcx_mdct_window_min_lengthFB = (int16_t) ( input_Fs * INV_CLDFB_BANDWIDTH ); - /* save complexity by copying the small windows if they have the same length */ - if ( hTcxCfg->tcx_mdct_window_min_length == hTcxCfg->tcx_mdct_window_trans_length ) - { - mvr2r( hTcxCfg->tcx_mdct_window_trans_flt, hTcxCfg->tcx_mdct_window_minimum_flt, hTcxCfg->tcx_mdct_window_min_length ); - } - else - { - mdct_window_sine_flt( hTcxCfg->tcx_mdct_window_minimum_flt, sr_core, hTcxCfg->tcx_mdct_window_min_length, MIN_OVERLAP, element_mode ); - } + /*-------------------------------------------------------------------* + * initPitchLagParameters() + * + * + *-------------------------------------------------------------------*/ - if ( hTcxCfg->tcx_mdct_window_min_lengthFB == hTcxCfg->tcx_mdct_window_trans_lengthFB ) - { - mvr2r( hTcxCfg->tcx_mdct_window_transFB_flt, hTcxCfg->tcx_mdct_window_minimumFB_flt, hTcxCfg->tcx_mdct_window_min_lengthFB ); - } - else if ( hTcxCfg->tcx_mdct_window_min_length == hTcxCfg->tcx_mdct_window_min_lengthFB ) + Word16 initPitchLagParameters( + const Word32 sr_core, + Word16 *pit_min, + Word16 *pit_fr1, + Word16 *pit_fr1b, + Word16 *pit_fr2, + Word16 *pit_max ) { - mvr2r( hTcxCfg->tcx_mdct_window_minimum_flt, hTcxCfg->tcx_mdct_window_minimumFB_flt, hTcxCfg->tcx_mdct_window_min_lengthFB ); + Word16 pit_res_max; + + IF( EQ_32( sr_core, INT_FS_12k8 ) ) + { + *pit_min = PIT_MIN_12k8; + move16(); + *pit_max = PIT_MAX_12k8; + move16(); + *pit_fr2 = PIT_FR2_12k8; + move16(); + *pit_fr1 = PIT_FR1_12k8; + move16(); + *pit_fr1b = PIT_FR1_8b_12k8; + move16(); + pit_res_max = 4; + move16(); + } + ELSE IF( EQ_32( sr_core, INT_FS_16k ) ) + { + *pit_min = PIT_MIN_16k; + move16(); + *pit_max = PIT16k_MAX; + move16(); + *pit_fr2 = PIT_FR2_16k; + move16(); + *pit_fr1 = PIT_FR1_16k; + move16(); + *pit_fr1b = PIT_FR1_8b_16k; + move16(); + pit_res_max = 6; + move16(); + } + ELSE IF( EQ_32( sr_core, 25600 ) ) + { + *pit_min = PIT_MIN_25k6; + move16(); + *pit_max = PIT_MAX_25k6; + move16(); + *pit_fr2 = PIT_FR2_25k6; + move16(); + *pit_fr1 = PIT_FR1_25k6; + move16(); + *pit_fr1b = PIT_FR1_8b_25k6; + move16(); + pit_res_max = 4; + move16(); + } + ELSE /* sr_core==32000 */ + { + *pit_min = PIT_MIN_32k; + move16(); + *pit_max = PIT_MAX_32k; + move16(); + *pit_fr2 = PIT_FR2_32k; + move16(); + *pit_fr1 = PIT_FR1_32k; + move16(); + *pit_fr1b = PIT_FR1_8b_32k; + move16(); + pit_res_max = 6; + move16(); + } + + return pit_res_max; } - else + + /*-------------------------------------------------------------------* + * getNumTcxCodedLines() + * + * + *-------------------------------------------------------------------*/ + + Word16 getNumTcxCodedLines( + const Word16 bwidth /* i : audio bandwidth */ + ) { - mdct_window_sine_flt( hTcxCfg->tcx_mdct_window_minimumFB_flt, input_Fs, hTcxCfg->tcx_mdct_window_min_lengthFB, MIN_OVERLAP, element_mode ); - } + Word16 tcx_coded_lines; - /* TCX Offset */ - hTcxCfg->tcx_offset = ( hTcxCfg->tcx_mdct_window_delay >> 1 ); - hTcxCfg->tcx_offsetFB = ( hTcxCfg->tcx_mdct_window_delayFB >> 1 ); - /*<0 rectangular transition with optimized window size = L_frame+L_frame/4*/ - hTcxCfg->lfacNext = hTcxCfg->tcx_offset - L_frame / 4; - hTcxCfg->lfacNextFB = hTcxCfg->tcx_offsetFB - L_frameTCX / 4; + tcx_coded_lines = 0; + move16(); - return; -} + SWITCH( bwidth ) + { + case NB: + tcx_coded_lines = 160; + BREAK; + case WB: + tcx_coded_lines = 320; + BREAK; + case SWB: + tcx_coded_lines = 640; + BREAK; + case FB: + tcx_coded_lines = 960; + BREAK; + default: + tcx_coded_lines = 0; + BREAK; + } -/*-----------------------------------------------------------------------* - * init_tcx() - * - * Initialization of TCX - *-----------------------------------------------------------------------*/ - -void init_tcx_cfg( - TCX_CONFIG_HANDLE hTcxCfg, - const int32_t total_brate, - const int32_t sr_core, - const int32_t input_Fs, - const int16_t L_frame, - const int16_t bwidth, - const int16_t L_frameTCX, - const int16_t fscale, - const int16_t encoderLookahead_enc, - const int16_t encoderLookahead_FB, - const float preemph_fac, - const int16_t tcxonly, - const int16_t rf_mode, - const int16_t igf, - const int16_t infoIGFStopFreq, - const int16_t element_mode, - const int16_t ini_frame, - const int16_t MCT_flag ) -{ - int16_t i; - int16_t mdctWindowLength; - int16_t mdctWindowLengthFB; - int16_t na_scale_bwidth; + return tcx_coded_lines; + } + + /*-------------------------------------------------------------------* + * getTcxLpcShapedAri() + * + * + *-------------------------------------------------------------------*/ - hTcxCfg->preemph_fac_flt = preemph_fac; - hTcxCfg->tcx5Size = NS2SA( sr_core, FRAME_SIZE_NS / 4 ); /* Always 5 ms */ - hTcxCfg->tcx5SizeFB = NS2SA( input_Fs, FRAME_SIZE_NS / 4 ); /* Always 5 ms */ + Word16 getTcxLpcShapedAri( + const Word32 total_brate, /* i : total bitrate */ + const Word16 rf_mode, /* i : flag to signal the RF mode */ + const Word16 element_mode /* i : IVAS element mode */ + ) + { + Word16 tcx_lpc_shaped_ari = 0; - hTcxCfg->tcx_mdct_window_length_old = hTcxCfg->tcx_mdct_window_length; - mdctWindowLength = getMdctWindowLength( fscale ); - mdctWindowLengthFB = (int16_t) ( mdctWindowLength * input_Fs / sr_core ); + move16(); + test(); + test(); + test(); + IF( ( ( LE_16( element_mode, IVAS_SCE ) && LE_32( total_brate, LPC_SHAPED_ARI_MAX_RATE ) ) || ( GT_16( element_mode, IVAS_SCE ) && LE_32( total_brate, LPC_SHAPED_ARI_MAX_RATE_CPE ) ) ) || rf_mode ) + { + tcx_lpc_shaped_ari = 1; + move16(); + } - init_tcx_window_cfg( hTcxCfg, sr_core, input_Fs, L_frame, L_frameTCX, encoderLookahead_enc, encoderLookahead_FB, mdctWindowLength, mdctWindowLengthFB, element_mode ); + return tcx_lpc_shaped_ari; + } + + + /*-----------------------------------------------------------------------* + * init_tcx_window_cfg() + * + * Initialization of TCX windows + *-----------------------------------------------------------------------*/ + + void init_tcx_window_cfg( + TCX_CONFIG_HANDLE hTcxCfg, /* i/o: TCX Config handle */ + const int32_t sr_core, /* i : SR core */ + const int32_t input_Fs, /* i : input/output SR */ + const int16_t L_frame, /* i : L_frame at sr_core */ + const int16_t L_frameTCX, /* i : L_frame at i/o SR */ + const int16_t encoderLookahead_enc, /* i : encoder LA at sr_core */ + const int16_t encoderLookahead_FB, /* i : encoder LA at i/o SR */ + const int16_t mdctWindowLength, /* i : window length at sr_core */ + const int16_t mdctWindowLengthFB, /* i : window length at i/o SR */ + const int16_t element_mode /* i : mode of CPE/SCE */ + ) + { + /* Symmetric window = sine LD window*/ + hTcxCfg->tcx_mdct_window_delay = mdctWindowLength; + hTcxCfg->tcx_mdct_window_delayFB = mdctWindowLengthFB; + hTcxCfg->tcx_mdct_window_length = mdctWindowLength; + hTcxCfg->tcx_mdct_window_lengthFB = mdctWindowLengthFB; + + mdct_window_sine_flt( hTcxCfg->tcx_mdct_window_flt, sr_core, hTcxCfg->tcx_mdct_window_length, FULL_OVERLAP, element_mode ); + if ( hTcxCfg->tcx_mdct_window_length == hTcxCfg->tcx_mdct_window_lengthFB ) + { + mvr2r( hTcxCfg->tcx_mdct_window_flt, hTcxCfg->tcx_mdct_windowFB_flt, hTcxCfg->tcx_mdct_window_length ); + } + else + { + mdct_window_sine_flt( hTcxCfg->tcx_mdct_windowFB_flt, input_Fs, hTcxCfg->tcx_mdct_window_lengthFB, FULL_OVERLAP, element_mode ); + } - /* SQ deadzone & memory quantization*/ - hTcxCfg->sq_rounding_flt = 0.375f; /*deadzone of 1.25->rounding=1-1.25/2 (No deadzone=0.5)*/ + /*ALDO windows for MODE2*/ + mdct_window_aldo_flt( hTcxCfg->tcx_aldo_window_1_flt, hTcxCfg->tcx_aldo_window_2_flt, L_frame ); + mdct_window_aldo_flt( hTcxCfg->tcx_aldo_window_1_FB_flt, hTcxCfg->tcx_aldo_window_2_FB_flt, NS2SA( input_Fs, FRAME_SIZE_NS ) ); + hTcxCfg->tcx_aldo_window_1_trunc_flt = hTcxCfg->tcx_aldo_window_1_flt + NS2SA( sr_core, N_ZERO_MDCT_NS ); + hTcxCfg->tcx_aldo_window_1_FB_trunc_flt = hTcxCfg->tcx_aldo_window_1_FB_flt + NS2SA( input_Fs, N_ZERO_MDCT_NS ); + + /*1.25ms transition window for ACELP->TCX*/ + hTcxCfg->tcx_mdct_window_trans_length = NS2SA( sr_core, ACELP_TCX_TRANS_NS ); + mdct_window_sine_flt( hTcxCfg->tcx_mdct_window_trans_flt, sr_core, hTcxCfg->tcx_mdct_window_trans_length, TRANSITION_OVERLAP, element_mode ); + hTcxCfg->tcx_mdct_window_trans_lengthFB = NS2SA( input_Fs, ACELP_TCX_TRANS_NS ); + if ( hTcxCfg->tcx_mdct_window_trans_length == hTcxCfg->tcx_mdct_window_trans_lengthFB ) + { + mvr2r( hTcxCfg->tcx_mdct_window_trans_flt, hTcxCfg->tcx_mdct_window_transFB_flt, hTcxCfg->tcx_mdct_window_trans_length ); + } + else + { + mdct_window_sine_flt( hTcxCfg->tcx_mdct_window_transFB_flt, input_Fs, hTcxCfg->tcx_mdct_window_trans_lengthFB, TRANSITION_OVERLAP, element_mode ); + } - /* TCX rate loop */ - hTcxCfg->tcxRateLoopOpt = ( tcxonly ) ? 2 : 0; - hTcxCfg->tcxRateLoopOpt = ( element_mode == IVAS_CPE_MDCT ) ? 3 : hTcxCfg->tcxRateLoopOpt; + /*Mid-OLA*/ + /*compute minimum length for "half" window: lookahead - 5ms. It must be also multiple of 2*/ + hTcxCfg->tcx_mdct_window_half_length = 2 * ( ( encoderLookahead_enc - (int16_t) ( 0.005f * sr_core + 0.5f ) ) >> 1 ); + hTcxCfg->tcx_mdct_window_half_lengthFB = 2 * ( ( encoderLookahead_FB - (int16_t) ( 0.005f * input_Fs + 0.5f ) ) >> 1 ); + assert( ( hTcxCfg->tcx_mdct_window_half_length > 16 ) && "Half window can not be large enough!" ); - /* TCX bandwidth */ - hTcxCfg->bandwidth_flt = getTcxBandwidth_flt( bwidth ); + mdct_window_sine_flt( hTcxCfg->tcx_mdct_window_half_flt, sr_core, hTcxCfg->tcx_mdct_window_half_length, HALF_OVERLAP, element_mode ); + if ( hTcxCfg->tcx_mdct_window_half_length == hTcxCfg->tcx_mdct_window_half_lengthFB ) + { + mvr2r( hTcxCfg->tcx_mdct_window_half_flt, hTcxCfg->tcx_mdct_window_halfFB_flt, hTcxCfg->tcx_mdct_window_half_length ); + } + else + { + mdct_window_sine_flt( hTcxCfg->tcx_mdct_window_halfFB_flt, input_Fs, hTcxCfg->tcx_mdct_window_half_lengthFB, HALF_OVERLAP, element_mode ); + } - /* set number of coded lines */ - hTcxCfg->tcx_coded_lines = getNumTcxCodedLines( bwidth ); + /* minimum overlap 1.25 ms */ + hTcxCfg->tcx_mdct_window_min_length = (int16_t) ( sr_core * INV_CLDFB_BANDWIDTH ); + hTcxCfg->tcx_mdct_window_min_lengthFB = (int16_t) ( input_Fs * INV_CLDFB_BANDWIDTH ); + /* save complexity by copying the small windows if they have the same length */ + if ( hTcxCfg->tcx_mdct_window_min_length == hTcxCfg->tcx_mdct_window_trans_length ) + { + mvr2r( hTcxCfg->tcx_mdct_window_trans_flt, hTcxCfg->tcx_mdct_window_minimum_flt, hTcxCfg->tcx_mdct_window_min_length ); + } + else + { + mdct_window_sine_flt( hTcxCfg->tcx_mdct_window_minimum_flt, sr_core, hTcxCfg->tcx_mdct_window_min_length, MIN_OVERLAP, element_mode ); + } - /* TNS in TCX */ - hTcxCfg->pCurrentTnsConfig = NULL; - hTcxCfg->fIsTNSAllowed = getTnsAllowed( total_brate, igf, element_mode ); + if ( hTcxCfg->tcx_mdct_window_min_lengthFB == hTcxCfg->tcx_mdct_window_trans_lengthFB ) + { + mvr2r( hTcxCfg->tcx_mdct_window_transFB_flt, hTcxCfg->tcx_mdct_window_minimumFB_flt, hTcxCfg->tcx_mdct_window_min_lengthFB ); + } + else if ( hTcxCfg->tcx_mdct_window_min_length == hTcxCfg->tcx_mdct_window_min_lengthFB ) + { + mvr2r( hTcxCfg->tcx_mdct_window_minimum_flt, hTcxCfg->tcx_mdct_window_minimumFB_flt, hTcxCfg->tcx_mdct_window_min_lengthFB ); + } + else + { + mdct_window_sine_flt( hTcxCfg->tcx_mdct_window_minimumFB_flt, input_Fs, hTcxCfg->tcx_mdct_window_min_lengthFB, MIN_OVERLAP, element_mode ); + } - if ( hTcxCfg->fIsTNSAllowed ) - { - InitTnsConfigs_flt( bwidth, hTcxCfg->tcx_coded_lines, hTcxCfg->tnsConfig, infoIGFStopFreq, total_brate, element_mode, MCT_flag ); + /* TCX Offset */ + hTcxCfg->tcx_offset = ( hTcxCfg->tcx_mdct_window_delay >> 1 ); + hTcxCfg->tcx_offsetFB = ( hTcxCfg->tcx_mdct_window_delayFB >> 1 ); + /*<0 rectangular transition with optimized window size = L_frame+L_frame/4*/ + hTcxCfg->lfacNext = hTcxCfg->tcx_offset - L_frame / 4; + hTcxCfg->lfacNextFB = hTcxCfg->tcx_offsetFB - L_frameTCX / 4; + + return; + } + + /*-----------------------------------------------------------------------* + * init_tcx() + * + * Initialization of TCX + *-----------------------------------------------------------------------*/ + + void init_tcx_cfg( + TCX_CONFIG_HANDLE hTcxCfg, + const int32_t total_brate, + const int32_t sr_core, + const int32_t input_Fs, + const int16_t L_frame, + const int16_t bwidth, + const int16_t L_frameTCX, + const int16_t fscale, + const int16_t encoderLookahead_enc, + const int16_t encoderLookahead_FB, + const float preemph_fac, + const int16_t tcxonly, + const int16_t rf_mode, + const int16_t igf, + const int16_t infoIGFStopFreq, + const int16_t element_mode, + const int16_t ini_frame, + const int16_t MCT_flag ) + { + int16_t i; + int16_t mdctWindowLength; + int16_t mdctWindowLengthFB; + int16_t na_scale_bwidth; + + hTcxCfg->preemph_fac_flt = preemph_fac; + hTcxCfg->tcx5Size = NS2SA( sr_core, FRAME_SIZE_NS / 4 ); /* Always 5 ms */ + hTcxCfg->tcx5SizeFB = NS2SA( input_Fs, FRAME_SIZE_NS / 4 ); /* Always 5 ms */ + + hTcxCfg->tcx_mdct_window_length_old = hTcxCfg->tcx_mdct_window_length; + mdctWindowLength = getMdctWindowLength( fscale ); + mdctWindowLengthFB = (int16_t) ( mdctWindowLength * input_Fs / sr_core ); + + init_tcx_window_cfg( hTcxCfg, sr_core, input_Fs, L_frame, L_frameTCX, encoderLookahead_enc, encoderLookahead_FB, mdctWindowLength, mdctWindowLengthFB, element_mode ); + + /* SQ deadzone & memory quantization*/ + hTcxCfg->sq_rounding_flt = 0.375f; /*deadzone of 1.25->rounding=1-1.25/2 (No deadzone=0.5)*/ + + /* TCX rate loop */ + hTcxCfg->tcxRateLoopOpt = ( tcxonly ) ? 2 : 0; + hTcxCfg->tcxRateLoopOpt = ( element_mode == IVAS_CPE_MDCT ) ? 3 : hTcxCfg->tcxRateLoopOpt; + + /* TCX bandwidth */ + hTcxCfg->bandwidth_flt = getTcxBandwidth_flt( bwidth ); + + /* set number of coded lines */ + hTcxCfg->tcx_coded_lines = getNumTcxCodedLines( bwidth ); + + /* TNS in TCX */ + hTcxCfg->pCurrentTnsConfig = NULL; + hTcxCfg->fIsTNSAllowed = getTnsAllowed( total_brate, igf, element_mode ); + + if ( hTcxCfg->fIsTNSAllowed ) + { + InitTnsConfigs_flt( bwidth, hTcxCfg->tcx_coded_lines, hTcxCfg->tnsConfig, infoIGFStopFreq, total_brate, element_mode, MCT_flag ); - SetAllowTnsOnWhite_flt( hTcxCfg->tnsConfig, element_mode == IVAS_CPE_MDCT ); - } + SetAllowTnsOnWhite_flt( hTcxCfg->tnsConfig, element_mode == IVAS_CPE_MDCT ); + } - if ( ini_frame == 0 ) - { - hTcxCfg->tcx_curr_overlap_mode = hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; - hTcxCfg->last_aldo = 1; - } + if ( ini_frame == 0 ) + { + hTcxCfg->tcx_curr_overlap_mode = hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; + hTcxCfg->last_aldo = 1; + } - /* Context HM*/ - hTcxCfg->ctx_hm = getCtxHm( element_mode, total_brate, rf_mode ); + /* Context HM*/ + hTcxCfg->ctx_hm = getCtxHm( element_mode, total_brate, rf_mode ); - /* Residual Coding*/ - hTcxCfg->resq = getResq( total_brate ); - hTcxCfg->tcxRateLoopOpt = ( hTcxCfg->resq && !tcxonly ) ? 1 : hTcxCfg->tcxRateLoopOpt; + /* Residual Coding*/ + hTcxCfg->resq = getResq( total_brate ); + hTcxCfg->tcxRateLoopOpt = ( hTcxCfg->resq && !tcxonly ) ? 1 : hTcxCfg->tcxRateLoopOpt; - /*Set bandwidth scale*/ - if ( bwidth == NB ) - { - na_scale_bwidth = NB; - } - else if ( sr_core <= INT_FS_16k ) - { - na_scale_bwidth = WB; - } - else - { - na_scale_bwidth = SWB; - } + /*Set bandwidth scale*/ + if ( bwidth == NB ) + { + na_scale_bwidth = NB; + } + else if ( sr_core <= INT_FS_16k ) + { + na_scale_bwidth = WB; + } + else + { + na_scale_bwidth = SWB; + } - /* Scale TCX for non-active frames to adjust loudness with ACELP*/ - hTcxCfg->na_scale_flt = 1.f; + /* Scale TCX for non-active frames to adjust loudness with ACELP*/ + hTcxCfg->na_scale_flt = 1.f; - if ( na_scale_bwidth < SWB && !tcxonly ) - { - for ( i = 0; i < SIZE_SCALE_TABLE_TCX; i++ ) + if ( na_scale_bwidth < SWB && !tcxonly ) { - if ( ( na_scale_bwidth == scaleTcxTable[i].bwmode ) && - ( total_brate >= scaleTcxTable[i].bitrateFrom ) && - ( total_brate < scaleTcxTable[i].bitrateTo ) ) + for ( i = 0; i < SIZE_SCALE_TABLE_TCX; i++ ) { - if ( rf_mode ) + if ( ( na_scale_bwidth == scaleTcxTable[i].bwmode ) && + ( total_brate >= scaleTcxTable[i].bitrateFrom ) && + ( total_brate < scaleTcxTable[i].bitrateTo ) ) { - i--; + if ( rf_mode ) + { + i--; + } + hTcxCfg->na_scale_flt = scaleTcxTable[i].scale_flt; + break; } - hTcxCfg->na_scale_flt = scaleTcxTable[i].scale_flt; - break; } } - } - - if ( tcxonly ) - { - InitPsychLPC( sr_core, L_frame, hTcxCfg ); - } - else - { - hTcxCfg->psychParamsCurrent = NULL; - } - - return; -} -#ifdef IVAS_FLOAT_FIXED -void init_tcx_window_cfg_fx( - TCX_CONFIG_HANDLE hTcxCfg, /* i/o: TCX Config handle */ - const Word32 sr_core, /* i : SR core */ - const Word32 input_Fs, /* i : input/output SR */ - const Word16 L_frame, /* i : L_frame at sr_core */ - const Word16 L_frameTCX, /* i : L_frame at i/o SR */ - const Word16 mdctWindowLength, /* i : window length at sr_core */ - const Word16 mdctWindowLengthFB, /* i : window length at i/o SR */ - const Word16 element_mode /* i : mode of CPE/SCE */ -) -{ - /* Symmetric window = sine LD window*/ - hTcxCfg->tcx_mdct_window_delay = mdctWindowLength; - hTcxCfg->tcx_mdct_window_delayFB = mdctWindowLengthFB; - hTcxCfg->tcx_mdct_window_length = mdctWindowLength; - hTcxCfg->tcx_mdct_window_lengthFB = mdctWindowLengthFB; - mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_window, sr_core, hTcxCfg->tcx_mdct_window_length, FULL_OVERLAP, element_mode ); - - IF( EQ_16( hTcxCfg->tcx_mdct_window_length, hTcxCfg->tcx_mdct_window_lengthFB ) ) - { - Copy_pword( hTcxCfg->tcx_mdct_window, hTcxCfg->tcx_mdct_windowFB, hTcxCfg->tcx_mdct_window_length / 2 ); - } - ELSE - { - mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_windowFB, input_Fs, hTcxCfg->tcx_mdct_window_lengthFB, FULL_OVERLAP, element_mode ); - } - /*ALDO windows for MODE2*/ - mdct_window_aldo( hTcxCfg->tcx_aldo_window_1, hTcxCfg->tcx_aldo_window_1_trunc, hTcxCfg->tcx_aldo_window_2, L_frame ); - mdct_window_aldo( hTcxCfg->tcx_aldo_window_1_FB, hTcxCfg->tcx_aldo_window_1_FB_trunc, hTcxCfg->tcx_aldo_window_2_FB, NS2SA_fx2( input_Fs, FRAME_SIZE_NS ) ); + if ( tcxonly ) + { + InitPsychLPC( sr_core, L_frame, hTcxCfg ); + } + else + { + hTcxCfg->psychParamsCurrent = NULL; + } - /*1.25ms transition window for ACELP->TCX*/ - hTcxCfg->tcx_mdct_window_trans_length = NS2SA_fx2( sr_core, ACELP_TCX_TRANS_NS ); - mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_window_trans, sr_core, hTcxCfg->tcx_mdct_window_trans_length, TRANSITION_OVERLAP, element_mode ); - hTcxCfg->tcx_mdct_window_trans_lengthFB = NS2SA_fx2( input_Fs, ACELP_TCX_TRANS_NS ); - IF( EQ_16( hTcxCfg->tcx_mdct_window_trans_length, hTcxCfg->tcx_mdct_window_trans_lengthFB ) ) - { - Copy_pword( hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_transFB, hTcxCfg->tcx_mdct_window_trans_length / 2 ); - } - ELSE - { - mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_window_transFB, input_Fs, hTcxCfg->tcx_mdct_window_trans_lengthFB, TRANSITION_OVERLAP, element_mode ); - } - /*Mid-OLA*/ - /*compute minimum length for "half" window: lookahead - 5ms. It must be also multiple of 2*/ - hTcxCfg->tcx_mdct_window_half_length = extract_l( L_shr( L_mult0( L_LOOK_12k8 - NS2SA_fx2( 12800, 5000000L ), sr2fscale( sr_core ) ), LD_FSCALE_DENOM ) ); - hTcxCfg->tcx_mdct_window_half_lengthFB = extract_l( L_shr( L_mult0( L_LOOK_12k8 - NS2SA_fx2( 12800, 5000000L ), sr2fscale( input_Fs ) ), LD_FSCALE_DENOM ) ); - assert( GT_16( hTcxCfg->tcx_mdct_window_half_length, 16 ) && "Half window can not be large enough!" ); - - mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_window_half, sr_core, hTcxCfg->tcx_mdct_window_half_length, HALF_OVERLAP, element_mode ); - IF( EQ_16( hTcxCfg->tcx_mdct_window_half_length, hTcxCfg->tcx_mdct_window_half_lengthFB ) ) - { - Copy_pword( hTcxCfg->tcx_mdct_window_half, hTcxCfg->tcx_mdct_window_halfFB, hTcxCfg->tcx_mdct_window_half_length / 2 ); - } - ELSE - { - mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_window_halfFB, input_Fs, hTcxCfg->tcx_mdct_window_half_lengthFB, HALF_OVERLAP, element_mode ); + return; } +#ifdef IVAS_FLOAT_FIXED + void init_tcx_window_cfg_fx( + TCX_CONFIG_HANDLE hTcxCfg, /* i/o: TCX Config handle */ + const Word32 sr_core, /* i : SR core */ + const Word32 input_Fs, /* i : input/output SR */ + const Word16 L_frame, /* i : L_frame at sr_core */ + const Word16 L_frameTCX, /* i : L_frame at i/o SR */ + const Word16 mdctWindowLength, /* i : window length at sr_core */ + const Word16 mdctWindowLengthFB, /* i : window length at i/o SR */ + const Word16 element_mode /* i : mode of CPE/SCE */ + ) + { + /* Symmetric window = sine LD window*/ + hTcxCfg->tcx_mdct_window_delay = mdctWindowLength; + hTcxCfg->tcx_mdct_window_delayFB = mdctWindowLengthFB; + hTcxCfg->tcx_mdct_window_length = mdctWindowLength; + hTcxCfg->tcx_mdct_window_lengthFB = mdctWindowLengthFB; + mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_window, sr_core, hTcxCfg->tcx_mdct_window_length, FULL_OVERLAP, element_mode ); + + IF( EQ_16( hTcxCfg->tcx_mdct_window_length, hTcxCfg->tcx_mdct_window_lengthFB ) ) + { + Copy_pword( hTcxCfg->tcx_mdct_window, hTcxCfg->tcx_mdct_windowFB, hTcxCfg->tcx_mdct_window_length / 2 ); + } + ELSE + { + mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_windowFB, input_Fs, hTcxCfg->tcx_mdct_window_lengthFB, FULL_OVERLAP, element_mode ); + } - /* minimum overlap 1.25 ms */ - hTcxCfg->tcx_mdct_window_min_length = shr( L_frame, 4 ); /* 1.25ms */ - hTcxCfg->tcx_mdct_window_min_lengthFB = shr( L_frameTCX, 4 ); /* 1.25ms */ - /* save complexity by copying the small windows if they have the same length */ - IF( EQ_16( hTcxCfg->tcx_mdct_window_min_length, hTcxCfg->tcx_mdct_window_trans_length ) ) - { - Copy_pword( hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_minimum, hTcxCfg->tcx_mdct_window_min_length / 2 ); - } - ELSE - { - mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_window_minimum, sr_core, hTcxCfg->tcx_mdct_window_min_length, MIN_OVERLAP, element_mode ); - } + /*ALDO windows for MODE2*/ + mdct_window_aldo( hTcxCfg->tcx_aldo_window_1, hTcxCfg->tcx_aldo_window_1_trunc, hTcxCfg->tcx_aldo_window_2, L_frame ); + mdct_window_aldo( hTcxCfg->tcx_aldo_window_1_FB, hTcxCfg->tcx_aldo_window_1_FB_trunc, hTcxCfg->tcx_aldo_window_2_FB, NS2SA_fx2( input_Fs, FRAME_SIZE_NS ) ); - IF( EQ_16( hTcxCfg->tcx_mdct_window_min_lengthFB, hTcxCfg->tcx_mdct_window_trans_lengthFB ) ) - { - Copy_pword( hTcxCfg->tcx_mdct_window_transFB, hTcxCfg->tcx_mdct_window_minimumFB, hTcxCfg->tcx_mdct_window_min_lengthFB / 2 ); - } - ELSE IF( EQ_16( hTcxCfg->tcx_mdct_window_min_length, hTcxCfg->tcx_mdct_window_min_lengthFB ) ) - { - Copy_pword( hTcxCfg->tcx_mdct_window_minimum, hTcxCfg->tcx_mdct_window_minimumFB, hTcxCfg->tcx_mdct_window_min_lengthFB / 2 ); - } - ELSE - { - mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_window_minimumFB, input_Fs, hTcxCfg->tcx_mdct_window_min_lengthFB, MIN_OVERLAP, element_mode ); - } - /* TCX Offset */ - hTcxCfg->tcx_offset = shr( hTcxCfg->tcx_mdct_window_delay, 1 ); - hTcxCfg->tcx_offsetFB = shr( hTcxCfg->tcx_mdct_window_delayFB, 1 ); - /*<0 rectangular transition with optimized window size = L_frame+L_frame/4*/ - hTcxCfg->lfacNext = sub( hTcxCfg->tcx_offset, shr( L_frame, 2 ) ); - hTcxCfg->lfacNextFB = sub( hTcxCfg->tcx_offsetFB, shr( L_frameTCX, 2 ) ); - - return; -} + /*1.25ms transition window for ACELP->TCX*/ + hTcxCfg->tcx_mdct_window_trans_length = NS2SA_fx2( sr_core, ACELP_TCX_TRANS_NS ); + mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_window_trans, sr_core, hTcxCfg->tcx_mdct_window_trans_length, TRANSITION_OVERLAP, element_mode ); + hTcxCfg->tcx_mdct_window_trans_lengthFB = NS2SA_fx2( input_Fs, ACELP_TCX_TRANS_NS ); + IF( EQ_16( hTcxCfg->tcx_mdct_window_trans_length, hTcxCfg->tcx_mdct_window_trans_lengthFB ) ) + { + Copy_pword( hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_transFB, hTcxCfg->tcx_mdct_window_trans_length / 2 ); + } + ELSE + { + mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_window_transFB, input_Fs, hTcxCfg->tcx_mdct_window_trans_lengthFB, TRANSITION_OVERLAP, element_mode ); + } + /*Mid-OLA*/ + /*compute minimum length for "half" window: lookahead - 5ms. It must be also multiple of 2*/ + hTcxCfg->tcx_mdct_window_half_length = extract_l( L_shr( L_mult0( L_LOOK_12k8 - NS2SA_fx2( 12800, 5000000L ), sr2fscale( sr_core ) ), LD_FSCALE_DENOM ) ); + hTcxCfg->tcx_mdct_window_half_lengthFB = extract_l( L_shr( L_mult0( L_LOOK_12k8 - NS2SA_fx2( 12800, 5000000L ), sr2fscale( input_Fs ) ), LD_FSCALE_DENOM ) ); + assert( GT_16( hTcxCfg->tcx_mdct_window_half_length, 16 ) && "Half window can not be large enough!" ); + + mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_window_half, sr_core, hTcxCfg->tcx_mdct_window_half_length, HALF_OVERLAP, element_mode ); + IF( EQ_16( hTcxCfg->tcx_mdct_window_half_length, hTcxCfg->tcx_mdct_window_half_lengthFB ) ) + { + Copy_pword( hTcxCfg->tcx_mdct_window_half, hTcxCfg->tcx_mdct_window_halfFB, hTcxCfg->tcx_mdct_window_half_length / 2 ); + } + ELSE + { + mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_window_halfFB, input_Fs, hTcxCfg->tcx_mdct_window_half_lengthFB, HALF_OVERLAP, element_mode ); + } -void init_tcx_cfg_fx( - TCX_CONFIG_HANDLE hTcxCfg, - const Word32 total_brate, - const Word32 sr_core, - const Word32 input_Fs, - const Word16 L_frame, - const Word16 bwidth, - const Word16 L_frameTCX, - const Word16 fscale, - const Word16 preemph_fac, - const Word16 tcxonly, - const Word16 rf_mode, - const Word16 igf, - const Word16 infoIGFStopFreq, - const Word16 element_mode, - const Word16 ini_frame, - const Word16 MCT_flag, - const Word16 fscaleFB) -{ - Word16 i; - Word16 mdctWindowLength; - Word16 mdctWindowLengthFB; - Word16 na_scale_bwidth; + /* minimum overlap 1.25 ms */ + hTcxCfg->tcx_mdct_window_min_length = shr( L_frame, 4 ); /* 1.25ms */ + hTcxCfg->tcx_mdct_window_min_lengthFB = shr( L_frameTCX, 4 ); /* 1.25ms */ + /* save complexity by copying the small windows if they have the same length */ + IF( EQ_16( hTcxCfg->tcx_mdct_window_min_length, hTcxCfg->tcx_mdct_window_trans_length ) ) + { + Copy_pword( hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_minimum, hTcxCfg->tcx_mdct_window_min_length / 2 ); + } + ELSE + { + mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_window_minimum, sr_core, hTcxCfg->tcx_mdct_window_min_length, MIN_OVERLAP, element_mode ); + } - hTcxCfg->preemph_fac = preemph_fac; - move16(); + IF( EQ_16( hTcxCfg->tcx_mdct_window_min_lengthFB, hTcxCfg->tcx_mdct_window_trans_lengthFB ) ) + { + Copy_pword( hTcxCfg->tcx_mdct_window_transFB, hTcxCfg->tcx_mdct_window_minimumFB, hTcxCfg->tcx_mdct_window_min_lengthFB / 2 ); + } + ELSE IF( EQ_16( hTcxCfg->tcx_mdct_window_min_length, hTcxCfg->tcx_mdct_window_min_lengthFB ) ) + { + Copy_pword( hTcxCfg->tcx_mdct_window_minimum, hTcxCfg->tcx_mdct_window_minimumFB, hTcxCfg->tcx_mdct_window_min_lengthFB / 2 ); + } + ELSE + { + mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_window_minimumFB, input_Fs, hTcxCfg->tcx_mdct_window_min_lengthFB, MIN_OVERLAP, element_mode ); + } + /* TCX Offset */ + hTcxCfg->tcx_offset = shr( hTcxCfg->tcx_mdct_window_delay, 1 ); + hTcxCfg->tcx_offsetFB = shr( hTcxCfg->tcx_mdct_window_delayFB, 1 ); + /*<0 rectangular transition with optimized window size = L_frame+L_frame/4*/ + hTcxCfg->lfacNext = sub( hTcxCfg->tcx_offset, shr( L_frame, 2 ) ); + hTcxCfg->lfacNextFB = sub( hTcxCfg->tcx_offsetFB, shr( L_frameTCX, 2 ) ); + + return; + } + + void init_tcx_cfg_fx( + TCX_CONFIG_HANDLE hTcxCfg, + const Word32 total_brate, + const Word32 sr_core, + const Word32 input_Fs, + const Word16 L_frame, + const Word16 bwidth, + const Word16 L_frameTCX, + const Word16 fscale, + const Word16 preemph_fac, + const Word16 tcxonly, + const Word16 rf_mode, + const Word16 igf, + const Word16 infoIGFStopFreq, + const Word16 element_mode, + const Word16 ini_frame, + const Word16 MCT_flag, + const Word16 fscaleFB ) + { + Word16 i; + Word16 mdctWindowLength; + Word16 mdctWindowLengthFB; + Word16 na_scale_bwidth; + + hTcxCfg->preemph_fac = preemph_fac; + move16(); - hTcxCfg->tcx5Size = shr( L_frame, 2 ); /* Always 5 ms */ - hTcxCfg->tcx5SizeFB = shr( L_frameTCX, 2 ); /* Always 5 ms */ + hTcxCfg->tcx5Size = shr( L_frame, 2 ); /* Always 5 ms */ + hTcxCfg->tcx5SizeFB = shr( L_frameTCX, 2 ); /* Always 5 ms */ - hTcxCfg->tcx_mdct_window_length_old = hTcxCfg->tcx_mdct_window_length; - move16(); - mdctWindowLength = getMdctWindowLength_fx( fscale ); - mdctWindowLengthFB = getMdctWindowLength_fx(fscaleFB); - init_tcx_window_cfg_fx( hTcxCfg, sr_core, input_Fs, L_frame, L_frameTCX, mdctWindowLength, mdctWindowLengthFB, element_mode ); - /* SQ deadzone & memory quantization*/ - hTcxCfg->sq_rounding = 12288 /*0.375f Q15*/; /*deadzone of 1.25->rounding=1-1.25/2 (No deadzone=0.5)*/ - move16(); + hTcxCfg->tcx_mdct_window_length_old = hTcxCfg->tcx_mdct_window_length; + move16(); + mdctWindowLength = getMdctWindowLength_fx( fscale ); + mdctWindowLengthFB = getMdctWindowLength_fx( fscaleFB ); + init_tcx_window_cfg_fx( hTcxCfg, sr_core, input_Fs, L_frame, L_frameTCX, mdctWindowLength, mdctWindowLengthFB, element_mode ); + /* SQ deadzone & memory quantization*/ + hTcxCfg->sq_rounding = 12288 /*0.375f Q15*/; /*deadzone of 1.25->rounding=1-1.25/2 (No deadzone=0.5)*/ + move16(); - /* TCX rate loop */ - hTcxCfg->tcxRateLoopOpt = 0; - move16(); + /* TCX rate loop */ + hTcxCfg->tcxRateLoopOpt = 0; + move16(); - IF( tcxonly != 0 ) - { - hTcxCfg->tcxRateLoopOpt = 2; + IF( tcxonly != 0 ) + { + hTcxCfg->tcxRateLoopOpt = 2; + move16(); + } + IF( EQ_16( element_mode, IVAS_CPE_MDCT ) ) + hTcxCfg->tcxRateLoopOpt = 3; + hTcxCfg->bandwidth = getTcxBandwidth( bwidth ); move16(); - } - IF( EQ_16( element_mode, IVAS_CPE_MDCT ) ) - hTcxCfg->tcxRateLoopOpt = 3; - hTcxCfg->bandwidth = getTcxBandwidth( bwidth ); - move16(); - /* set number of coded lines */ - hTcxCfg->tcx_coded_lines = getNumTcxCodedLines( bwidth ); + /* set number of coded lines */ + hTcxCfg->tcx_coded_lines = getNumTcxCodedLines( bwidth ); - /* TNS in TCX */ - hTcxCfg->pCurrentTnsConfig = NULL; - hTcxCfg->fIsTNSAllowed = getTnsAllowed( total_brate, igf, element_mode ); + /* TNS in TCX */ + hTcxCfg->pCurrentTnsConfig = NULL; + hTcxCfg->fIsTNSAllowed = getTnsAllowed( total_brate, igf, element_mode ); - IF( hTcxCfg->fIsTNSAllowed ) - { - InitTnsConfigs( bwidth, hTcxCfg->tcx_coded_lines, hTcxCfg->tnsConfig, infoIGFStopFreq, total_brate, element_mode, MCT_flag ); + IF( hTcxCfg->fIsTNSAllowed ) + { + InitTnsConfigs( bwidth, hTcxCfg->tcx_coded_lines, hTcxCfg->tnsConfig, infoIGFStopFreq, total_brate, element_mode, MCT_flag ); - SetAllowTnsOnWhite( hTcxCfg->tnsConfig, element_mode == IVAS_CPE_MDCT ); - } + SetAllowTnsOnWhite( hTcxCfg->tnsConfig, element_mode == IVAS_CPE_MDCT ); + } - IF( ini_frame == 0 ) - { - hTcxCfg->tcx_curr_overlap_mode = hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; - hTcxCfg->last_aldo = 1; - } + IF( ini_frame == 0 ) + { + hTcxCfg->tcx_curr_overlap_mode = hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; + hTcxCfg->last_aldo = 1; + } - /* Context HM*/ - hTcxCfg->ctx_hm = getCtxHm( element_mode, total_brate, rf_mode ); + /* Context HM*/ + hTcxCfg->ctx_hm = getCtxHm( element_mode, total_brate, rf_mode ); - /* Residual Coding*/ - hTcxCfg->resq = getResq( total_brate ); - IF( hTcxCfg->resq && !tcxonly ) - { - hTcxCfg->tcxRateLoopOpt = 1; - move16(); - } + /* Residual Coding*/ + hTcxCfg->resq = getResq( total_brate ); + IF( hTcxCfg->resq && !tcxonly ) + { + hTcxCfg->tcxRateLoopOpt = 1; + move16(); + } - /*Set bandwidth scale*/ - IF( EQ_16( bwidth, NB ) ) - { - na_scale_bwidth = NB; - } - ELSE IF( LE_32( sr_core, INT_FS_16k ) ) - { - na_scale_bwidth = WB; - } - ELSE - { - na_scale_bwidth = SWB; - } - hTcxCfg->na_scale = 32767 /*1.0f Q15*/; + /*Set bandwidth scale*/ + IF( EQ_16( bwidth, NB ) ) + { + na_scale_bwidth = NB; + } + ELSE IF( LE_32( sr_core, INT_FS_16k ) ) + { + na_scale_bwidth = WB; + } + ELSE + { + na_scale_bwidth = SWB; + } + hTcxCfg->na_scale = 32767 /*1.0f Q15*/; - IF( LT_16( na_scale_bwidth, SWB ) && !tcxonly ) - { - FOR( i = 0; i < SIZE_SCALE_TABLE_TCX; i++ ) + IF( LT_16( na_scale_bwidth, SWB ) && !tcxonly ) { - IF( ( EQ_16( na_scale_bwidth, scaleTcxTable[i].bwmode ) ) && - ( GE_32( total_brate, scaleTcxTable[i].bitrateFrom ) ) && - ( LT_32( total_brate, scaleTcxTable[i].bitrateTo ) ) ) + FOR( i = 0; i < SIZE_SCALE_TABLE_TCX; i++ ) { - IF( rf_mode ) + IF( ( EQ_16( na_scale_bwidth, scaleTcxTable[i].bwmode ) ) && + ( GE_32( total_brate, scaleTcxTable[i].bitrateFrom ) ) && + ( LT_32( total_brate, scaleTcxTable[i].bitrateTo ) ) ) { - i--; + IF( rf_mode ) + { + i--; + } + hTcxCfg->na_scale = scaleTcxTable[i].scale; + BREAK; } - hTcxCfg->na_scale = scaleTcxTable[i].scale; - BREAK; } } - } - IF( tcxonly ) - { - InitPsychLPC( sr_core, L_frame, hTcxCfg ); - } - ELSE - { - hTcxCfg->psychParamsCurrent = NULL; - } + IF( tcxonly ) + { + InitPsychLPC( sr_core, L_frame, hTcxCfg ); + } + ELSE + { + hTcxCfg->psychParamsCurrent = NULL; + } - return; -} + return; + } #endif // IVAS_FLOAT_FIXED diff --git a/lib_com/count.c b/lib_com/count.c index 664ebeef2..999229e3d 100644 --- a/lib_com/count.c +++ b/lib_com/count.c @@ -9,7 +9,7 @@ History: 03 Nov 04 v2.0 Incorporation of new 32-bit / 40-bit / control - operators for the ITU-T Standard Tool Library as + operators for the ITU-T Standard Tool Library as described in Geneva, 20-30 January 2004 WP 3/16 Q10/16 TD 11 document and subsequent discussions on the wp3audio@yahoogroups.com email reflector. @@ -50,8 +50,8 @@ #include #ifdef WMOPS -static double frameRate = FRAME_RATE; /* default value : 10 ms */ -#endif /* ifdef WMOPS */ +static double frameRate = FRAME_RATE; /* default value : 10 ms */ +#endif /* ifdef WMOPS */ #ifdef WMOPS /* Global counter variable for calculation of complexity weight */ @@ -59,15 +59,17 @@ static double frameRate = FRAME_RATE; /* default value : 10 ms */ BASIC_OP multiCounter[MAXCOUNTERS]; BASIC_OP glob_multiCounter; -int currCounter = 0; /* Zero equals global counter */ -#endif /* ifdef WMOPS */ +int currCounter = 0; /* Zero equals global counter */ +#endif /* ifdef WMOPS */ #ifdef WMOPS -void setFrameRate (int samplingFreq, int frameLength) { - if (frameLength > 0) { - frameRate = samplingFreq / 1000000.0 / frameLength; - } - return; +void setFrameRate( int samplingFreq, int frameLength ) +{ + if ( frameLength > 0 ) + { + frameRate = samplingFreq / 1000000.0 / frameLength; + } + return; } #endif /* ifdef WMOPS */ @@ -81,118 +83,62 @@ void setFrameRate (int samplingFreq, int frameLength) { * with the structure definition BASIC_OP. */ char *BasicOperationList[] = { - "add", "sub", "abs_s", "shl", "shr", - "extract_h", "extract_l", "mult", "L_mult", "negate", - "round", "L_mac", "L_msu", "L_macNs", "L_msuNs", - "L_add", "L_sub", "L_add_c", "L_sub_c", "L_negate", - "L_shl", "L_shr", "mult_r", "shr_r", "mac_r", - - "msu_r", "L_deposit_h", "L_deposit_l", "L_shr_r", "L_abs", - "L_sat", "norm_s", "div_s", "norm_l", "move16", - "move32", "Logic16", "Logic32", "Test", "s_max", - "s_min", "L_max", "L_min", "L40_max", "L40_min", - "shl_r", "L_shl_r", "L40_shr_r", "L40_shl_r", "norm_L40", - - "L40_shl", "L40_shr", "L40_negate", "L40_add", "L40_sub", - "L40_abs", "L40_mult", "L40_mac", "mac_r40", - "L40_msu", "msu_r40", "Mpy_32_16_ss", "Mpy_32_32_ss", "L_mult0", - "L_mac0", "L_msu0", "lshl", "lshr", "L_lshl", - "L_lshr", "L40_lshl", "L40_lshr", "s_and", "s_or", - - "s_xor", "L_and", "L_or", "L_xor", "rotl", - "rotr", "L_rotl", "L_rotr", "L40_set", "L40_deposit_h", - "L40_deposit_l", "L40_deposit32", "Extract40_H", "Extract40_L", "L_Extract40", - "L40_round", "L_saturate40", "round40", "IF", "GOTO", - "BREAK", "SWITCH", "FOR", "WHILE", "CONTINUE", - - "L_mls", "div_l", "i_mult" - - /* New complex basops */ - #ifdef COMPLEX_OPERATOR - , "CL_shr", "CL_shl", "CL_add" - , "CL_sub", "CL_scale", "CL_dscale" - , "CL_msu_j", "CL_mac_j", "CL_move" - , "CL_Extract_real", "CL_Extract_imag", "CL_form" - , "CL_multr_32x16", "CL_negate", "CL_conjugate" - , "CL_mul_j" - , "CL_swap_real_imag" - , "C_add" - , "C_sub" - , "C_mul_j" - , "C_multr" - , "C_form" - - , "C_scale" - , "CL_round32_16", "CL_scale_32", "CL_dscale_32", "CL_multr_32x32" - , "C_mac_r", "C_msu_r", "C_Extract_real", "C_Extract_imag" - , "C_negate", "C_conjugate" - , "C_shr", "C_shl" + "add", "sub", "abs_s", "shl", "shr", + "extract_h", "extract_l", "mult", "L_mult", "negate", + "round", "L_mac", "L_msu", "L_macNs", "L_msuNs", + "L_add", "L_sub", "L_add_c", "L_sub_c", "L_negate", + "L_shl", "L_shr", "mult_r", "shr_r", "mac_r", + + "msu_r", "L_deposit_h", "L_deposit_l", "L_shr_r", "L_abs", + "L_sat", "norm_s", "div_s", "norm_l", "move16", + "move32", "Logic16", "Logic32", "Test", "s_max", + "s_min", "L_max", "L_min", "L40_max", "L40_min", + "shl_r", "L_shl_r", "L40_shr_r", "L40_shl_r", "norm_L40", + + "L40_shl", "L40_shr", "L40_negate", "L40_add", "L40_sub", + "L40_abs", "L40_mult", "L40_mac", "mac_r40", + "L40_msu", "msu_r40", "Mpy_32_16_ss", "Mpy_32_32_ss", "L_mult0", + "L_mac0", "L_msu0", "lshl", "lshr", "L_lshl", + "L_lshr", "L40_lshl", "L40_lshr", "s_and", "s_or", + + "s_xor", "L_and", "L_or", "L_xor", "rotl", + "rotr", "L_rotl", "L_rotr", "L40_set", "L40_deposit_h", + "L40_deposit_l", "L40_deposit32", "Extract40_H", "Extract40_L", "L_Extract40", + "L40_round", "L_saturate40", "round40", "IF", "GOTO", + "BREAK", "SWITCH", "FOR", "WHILE", "CONTINUE", + + "L_mls", "div_l", "i_mult" + +/* New complex basops */ +#ifdef COMPLEX_OPERATOR + , + "CL_shr", "CL_shl", "CL_add", "CL_sub", "CL_scale", "CL_dscale", "CL_msu_j", "CL_mac_j", "CL_move", "CL_Extract_real", "CL_Extract_imag", "CL_form", "CL_multr_32x16", "CL_negate", "CL_conjugate", "CL_mul_j", "CL_swap_real_imag", "C_add", "C_sub", "C_mul_j", "C_multr", "C_form" + + , + "C_scale", "CL_round32_16", "CL_scale_32", "CL_dscale_32", "CL_multr_32x32", "C_mac_r", "C_msu_r", "C_Extract_real", "C_Extract_imag", "C_negate", "C_conjugate", "C_shr", "C_shl" #endif /* #ifdef COMPLEX_OPERATOR */ - /* New 64 bit basops */ +/* New 64 bit basops */ #ifdef ENH_64_BIT_OPERATOR - , "move64" , "W_add_nosat" ,"W_sub_nosat" - , "W_shl" , "W_shr" - , "W_shl_nosat" , "W_shr_nosat" - , "W_mac_32_16" , "W_msu_32_16" , "W_mult_32_16" - , "W_mult0_16_16" , "W_mac0_16_16" , "W_msu0_16_16" - , "W_mult_16_16" , "W_mac_16_16" , "W_msu_16_16" - , "W_shl_sat_l" , "W_sat_l" - , "W_sat_m" , "W_deposit32_l" ,"W_deposit32_h" - , "W_extract_l" , "W_extract_h" - , "W_round48_L" , "W_round32_s" - , "W_norm" - , "W_add" , "W_sub" ,"W_neg" ,"W_abs" - , "W_mult_32_32" , "W_mult0_32_32" - , "W_lshl" , "W_lshr" ,"W_round64_L" + , + "move64", "W_add_nosat", "W_sub_nosat", "W_shl", "W_shr", "W_shl_nosat", "W_shr_nosat", "W_mac_32_16", "W_msu_32_16", "W_mult_32_16", "W_mult0_16_16", "W_mac0_16_16", "W_msu0_16_16", "W_mult_16_16", "W_mac_16_16", "W_msu_16_16", "W_shl_sat_l", "W_sat_l", "W_sat_m", "W_deposit32_l", "W_deposit32_h", "W_extract_l", "W_extract_h", "W_round48_L", "W_round32_s", "W_norm", "W_add", "W_sub", "W_neg", "W_abs", "W_mult_32_32", "W_mult0_32_32", "W_lshl", "W_lshr", "W_round64_L" #endif /* #ifdef ENH_64_BIT_OPERATOR */ #ifdef ENH_32_BIT_OPERATOR - , "Mpy_32_16_1" - , "Mpy_32_16_r" - , "Mpy_32_32" - , "Mpy_32_32_r" - , "Madd_32_16" - , "Madd_32_16_r" - , "Msub_32_16" - , "Msub_32_16_r" - , "Madd_32_32" - , "Madd_32_32_r" - , "Msub_32_32" - , "Msub_32_32_r" + , + "Mpy_32_16_1", "Mpy_32_16_r", "Mpy_32_32", "Mpy_32_32_r", "Madd_32_16", "Madd_32_16_r", "Msub_32_16", "Msub_32_16_r", "Madd_32_32", "Madd_32_32_r", "Msub_32_32", "Msub_32_32_r" #endif /* #ifdef ENH_32_BIT_OPERATOR */ #ifdef ENH_U_32_BIT_OPERATOR - , "UL_addNs" - , "UL_subNs" - , "UL_Mpy_32_32" - , "Mpy_32_32_uu" - , "Mpy_32_16_uu" - , "norm_ul_float" - , "UL_deposit_l" + , + "UL_addNs", "UL_subNs", "UL_Mpy_32_32", "Mpy_32_32_uu", "Mpy_32_16_uu", "norm_ul_float", "UL_deposit_l" #endif /* #ifdef ENH_U_32_BIT_OPERATOR */ #ifdef CONTROL_CODE_OPS - , "LT_16" - , "GT_16" - , "LE_16" - , "GE_16" - , "EQ_16" - , "NE_16" - , "LT_32" - , "GT_32" - , "LE_32" - , "GE_32" - , "EQ_32" - , "NE_32" - , "LT_64" - , "GT_64" - , "LE_64" - , "GE_64" - , "EQ_64" - , "NE_64" + , + "LT_16", "GT_16", "LE_16", "GE_16", "EQ_16", "NE_16", "LT_32", "GT_32", "LE_32", "GE_32", "EQ_32", "NE_32", "LT_64", "GT_64", "LE_64", "GE_64", "EQ_64", "NE_64" #endif /* #ifdef CONTROL_CODE_OPS */ }; @@ -201,136 +147,80 @@ char *BasicOperationList[] = { #ifdef WMOPS const BASIC_OP op_weight = { - 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, - 1, 1, 2, 2, 1, - 1, 1, 1, 2, 1, - - 1, 1, 1, 2, 1, - 1, 1, 18, 1, 1, - 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, - 2, 2, 2, 2, 1, - - 1, 1, 1, 1, 1, - 1, 1, 1, 2, - 1, 2, 2, 2, 1, - 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, - - 1, 1, 1, 1, 3, - 3, 3, 3, 1, 1, - 1, 1, 1, 1, 1, - 1, 1, 1, 3, 2, - 2, 6, 3, 3, 2, - - 1, 32, 1 + 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, + 1, 1, 2, 2, 1, + 1, 1, 1, 2, 1, + + 1, 1, 1, 2, 1, + 1, 1, 18, 1, 1, + 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, + 2, 2, 2, 2, 1, + + 1, 1, 1, 1, 1, + 1, 1, 1, 2, + 1, 2, 2, 2, 1, + 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, + + 1, 1, 1, 1, 3, + 3, 3, 3, 1, 1, + 1, 1, 1, 1, 1, + 1, 1, 1, 3, 2, + 2, 6, 3, 3, 2, + + 1, 32, 1 /* New complex basops */ - #ifdef COMPLEX_OPERATOR - , 1, 1, 1 - , 1, 1, 1 - , 1, 1, 1 - , 1, 1, 1 - , 2, 1, 1 - , 1 - , 1 - , 1 - , 1 - , 1 - , 2 - , 1 - - , 1 - , 1, 1, 1, 2 - , 2, 2, 1, 1 - , 1, 1 - , 1, 1 +#ifdef COMPLEX_OPERATOR + , + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1 + + , + 1, 1, 1, 1, 2, 2, 2, 1, 1, 1, 1, 1, 1 #endif /* #ifdef COMPLEX_OPERATOR */ #ifdef ENH_64_BIT_OPERATOR - /* Weights of new 64 bit basops */ - , 1 , 1 ,1 - , 1 , 1 - , 1 , 1 - , 1 , 1 , 1 - , 1 , 1 , 1 - , 1 , 1 , 1 - , 1 , 1 - , 1 , 1 , 1 - , 1 , 1 - , 1 , 1 - , 1 - , 1 , 1 , 1 , 1 - , 1 , 1 - , 1 , 1 , 1 + /* Weights of new 64 bit basops */ + , + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 #endif /* #ifdef ENH_64_BIT_OPERATOR */ #ifdef ENH_32_BIT_OPERATOR - , 1 - , 1 - , 1 - , 1 - , 1 - , 1 - , 1 - , 1 - , 1 - , 1 - , 1 - , 1 + , + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 #endif /* #ifdef ENH_32_BIT_OPERATOR */ #ifdef ENH_U_32_BIT_OPERATOR - , 1 - , 1 - , 1 - , 2 - , 2 - , 1 - , 1 + , + 1, 1, 1, 2, 2, 1, 1 #endif /* #ifdef ENH_U_32_BIT_OPERATOR */ #ifdef CONTROL_CODE_OPS - , 1 - , 1 - , 1 - , 1 - , 1 - , 1 - , 1 - , 1 - , 1 - , 1 - , 1 - , 1 - , 1 - , 1 - , 1 - , 1 - , 1 - , 1 + , + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 #endif /* #ifdef CONTROL_CODE_OPS */ }; #endif /* ifdef WMOPS */ -Word32 TotalWeightedOperation (void); -Word32 DeltaWeightedOperation (void); +Word32 TotalWeightedOperation( void ); +Word32 DeltaWeightedOperation( void ); #ifdef WMOPS /* Counters for separating counting for different objects */ /* FROM_EVS_DEV */ - /** - maxCounter: current number of counters. Each scope initialized with BASOP_sub_start() gets a own counter assigned. - objectName: Name of each counter passed to BASOP_sub_start(). - fwc_corr: - nbTimeObjectIsCalled: number of times a counter (object) is referenced in the current frame. - */ +/** +maxCounter: current number of counters. Each scope initialized with BASOP_sub_start() gets a own counter assigned. +objectName: Name of each counter passed to BASOP_sub_start(). +fwc_corr: +nbTimeObjectIsCalled: number of times a counter (object) is referenced in the current frame. +*/ static int maxCounter = 0; static char *objectName[MAXCOUNTERS + 1]; @@ -339,7 +229,7 @@ static Word16 fwc_corr[MAXCOUNTERS + 1]; static long int nbTimeObjectIsCalled[MAXCOUNTERS + 1]; -#define NbFuncMax (4096) +#define NbFuncMax ( 4096 ) /** @@ -365,15 +255,15 @@ static Word32 LastWOper[MAXCOUNTERS]; /* FROM_EVS_DEV */ static float total_sum[MAXCOUNTERS]; static Word16 call_tree[MAXCOUNTERS][MAXCOUNTERS]; -static int sum_curr[MAXCOUNTERS+1]; -static int sum_bc[MAXCOUNTERS+1]; -static int sum_wc[MAXCOUNTERS+1]; -static int glob_sum_curr[MAXCOUNTERS+1]; -static int glob_sum_bc[MAXCOUNTERS+1]; -static int glob_sum_wc[MAXCOUNTERS+1]; +static int sum_curr[MAXCOUNTERS + 1]; +static int sum_bc[MAXCOUNTERS + 1]; +static int sum_wc[MAXCOUNTERS + 1]; +static int glob_sum_curr[MAXCOUNTERS + 1]; +static int glob_sum_bc[MAXCOUNTERS + 1]; +static int glob_sum_wc[MAXCOUNTERS + 1]; #if MAX_CALLERS_SAVED_FRAMES #define MAX_CALLERS_PRINT 20 -static float callers_frames[MAX_CALLERS_SAVED_FRAMES+1][MAXCOUNTERS+1]; +static float callers_frames[MAX_CALLERS_SAVED_FRAMES + 1][MAXCOUNTERS + 1]; static int callers_frames_nos[MAX_CALLERS_SAVED_FRAMES]; static float callers_totals[MAX_CALLERS_SAVED_FRAMES]; #endif @@ -382,479 +272,512 @@ static float callers_totals[MAX_CALLERS_SAVED_FRAMES]; #ifdef WMOPS -static char *my_strdup (const char *s) { - /* - * duplicates UNIX function strdup() which is not ANSI standard: - * -- malloc() memory area big enough to hold the string s - * -- copy string into new area - * -- return pointer to new area - * - * returns NULL if either s==NULL or malloc() fails - */ - char *dup; - - if (s == NULL) - return NULL; - - /* allocate memory for copy of ID string (including string terminator) */ - /* NOTE: the ID strings will never be deallocated because there is no way to "destroy" a counter that is not longer needed */ - if ((dup = (char *) malloc (strlen (s) + 1)) == NULL) - return NULL; - - return strcpy (dup, s); +static char *my_strdup( const char *s ) +{ + /* + * duplicates UNIX function strdup() which is not ANSI standard: + * -- malloc() memory area big enough to hold the string s + * -- copy string into new area + * -- return pointer to new area + * + * returns NULL if either s==NULL or malloc() fails + */ + char *dup; + + if ( s == NULL ) + return NULL; + + /* allocate memory for copy of ID string (including string terminator) */ + /* NOTE: the ID strings will never be deallocated because there is no way to "destroy" a counter that is not longer needed */ + if ( ( dup = (char *) malloc( strlen( s ) + 1 ) ) == NULL ) + return NULL; + + return strcpy( dup, s ); } #endif /* ifdef WMOPS */ -int getCounterId (char *objectNameArg) { +int getCounterId( char *objectNameArg ) +{ #if WMOPS - if (maxCounter >= MAXCOUNTERS - 1) - return 0; - objectName[++maxCounter] = my_strdup (objectNameArg); - return maxCounter; + if ( maxCounter >= MAXCOUNTERS - 1 ) + return 0; + objectName[++maxCounter] = my_strdup( objectNameArg ); + return maxCounter; #else /* ifdef WMOPS */ - (void)objectNameArg; - return 0; /* Dummy */ + (void) objectNameArg; + return 0; /* Dummy */ #endif /* ifdef WMOPS */ } #if WMOPS -int readCounterId () { - return currCounter; +int readCounterId() +{ + return currCounter; } #endif /* ifdef WMOPS */ #ifdef WMOPS -char *readCounterIdName () { - return objectName[currCounter]; +char *readCounterIdName() +{ + return objectName[currCounter]; } #endif /* ifdef WMOPS */ -void setCounter (int counterId) { +void setCounter( int counterId ) +{ #if WMOPS - if ((counterId > maxCounter) - || (counterId < 0)) { - currCounter = 0; - return; - } - currCounter = counterId; - call_occurred = 1; + if ( ( counterId > maxCounter ) || ( counterId < 0 ) ) + { + currCounter = 0; + return; + } + currCounter = counterId; + call_occurred = 1; #else - (void)counterId; + (void) counterId; #endif /* ifdef WMOPS */ } -void incrementNbTimeObjectIsCalled (int counterId) { +void incrementNbTimeObjectIsCalled( int counterId ) +{ #if WMOPS - if ((counterId > maxCounter) - || (counterId < 0)) { - nbTimeObjectIsCalled[0]++; - return; - } - nbTimeObjectIsCalled[counterId]++; + if ( ( counterId > maxCounter ) || ( counterId < 0 ) ) + { + nbTimeObjectIsCalled[0]++; + return; + } + nbTimeObjectIsCalled[counterId]++; #else - (void)counterId; + (void) counterId; #endif /* ifdef WMOPS */ } #if WMOPS -static Word32 WMOPS_frameStat (void) { -/* calculate the WMOPS seen so far and update the global - per-frame maximum (glob_wc) - */ - Word32 tot; +static Word32 WMOPS_frameStat( void ) +{ + /* calculate the WMOPS seen so far and update the global + per-frame maximum (glob_wc) + */ + Word32 tot; - tot = TotalWeightedOperation (); - if ( tot > glob_wc[currCounter] ) - { - glob_wc[currCounter] = tot; - } + tot = TotalWeightedOperation(); + if ( tot > glob_wc[currCounter] ) + { + glob_wc[currCounter] = tot; + } - if ( tot < glob_bc[currCounter] ) - { - glob_bc[currCounter] = tot; - } - /* check if fwc() was forgotten at end of last frame */ - if (tot > LastWOper[currCounter]) { - if (!fwc_corr[currCounter]) { - fprintf (stderr, - "count: operations counted after last fwc() for '%s'; " "-> fwc() called\n", - objectName[currCounter] ? objectName[currCounter] : ""); + if ( tot < glob_bc[currCounter] ) + { + glob_bc[currCounter] = tot; + } + /* check if fwc() was forgotten at end of last frame */ + if ( tot > LastWOper[currCounter] ) + { + if ( !fwc_corr[currCounter] ) + { + fprintf( stderr, + "count: operations counted after last fwc() for '%s'; " + "-> fwc() called\n", + objectName[currCounter] ? objectName[currCounter] : "" ); + } + fwc(); } - fwc (); - } - return tot; + return tot; } #endif /* ifdef WMOPS */ #ifdef WMOPS -static void WMOPS_clearMultiCounter (void) { - Word16 i; +static void WMOPS_clearMultiCounter( void ) +{ + Word16 i; - Word32 *ptr = (Word32 *) & multiCounter[currCounter]; - for (i = 0; i < (Word16)(sizeof (multiCounter[currCounter]) / sizeof (Word32)); i++) { - *ptr++ = 0; - } + Word32 *ptr = (Word32 *) &multiCounter[currCounter]; + for ( i = 0; i < (Word16) ( sizeof( multiCounter[currCounter] ) / sizeof( Word32 ) ); i++ ) + { + *ptr++ = 0; + } } #endif /* ifdef WMOPS */ -void ClearNbTimeObjectsAreCalled () { +void ClearNbTimeObjectsAreCalled() +{ #if WMOPS - Word16 i; + Word16 i; - for (i = 0; i < (Word16)(sizeof (multiCounter[currCounter]) / sizeof (Word32)); i++) { - nbTimeObjectIsCalled[i] = 0; - } + for ( i = 0; i < (Word16) ( sizeof( multiCounter[currCounter] ) / sizeof( Word32 ) ); i++ ) + { + nbTimeObjectIsCalled[i] = 0; + } #endif /* ifdef WMOPS */ } -Word32 TotalWeightedOperation () { +Word32 TotalWeightedOperation() +{ #if WMOPS - Word16 i; - Word32 tot, *ptr, *ptr2; - - tot = 0; - ptr = (Word32 *) & multiCounter[currCounter]; - ptr2 = (Word32 *) & op_weight; - for (i = 0; i < (Word16)(sizeof (multiCounter[currCounter]) / sizeof (Word32)); i++) { - tot += ((*ptr++) * (*ptr2++)); - } + Word16 i; + Word32 tot, *ptr, *ptr2; + + tot = 0; + ptr = (Word32 *) &multiCounter[currCounter]; + ptr2 = (Word32 *) &op_weight; + for ( i = 0; i < (Word16) ( sizeof( multiCounter[currCounter] ) / sizeof( Word32 ) ); i++ ) + { + tot += ( ( *ptr++ ) * ( *ptr2++ ) ); + } - return ((Word32) tot); + return ( (Word32) tot ); #else /* ifdef WMOPS */ - return 0; /* Dummy */ + return 0; /* Dummy */ #endif /* ifdef WMOPS */ - } -Word32 DeltaWeightedOperation () { +Word32 DeltaWeightedOperation() +{ #if WMOPS - Word32 NewWOper, delta; + Word32 NewWOper, delta; - NewWOper = TotalWeightedOperation (); - delta = NewWOper - LastWOper[currCounter]; - LastWOper[currCounter] = NewWOper; - return (delta); + NewWOper = TotalWeightedOperation(); + delta = NewWOper - LastWOper[currCounter]; + LastWOper[currCounter] = NewWOper; + return ( delta ); #else /* ifdef WMOPS */ - return 0; /* Dummy */ + return 0; /* Dummy */ #endif /* ifdef WMOPS */ } -void Init_WMOPS_counter (void) { +void Init_WMOPS_counter( void ) +{ #if WMOPS - Word16 i; + Word16 i; - /* reset function weight operation counter variable */ + /* reset function weight operation counter variable */ - for (i = 0; i < NbFuncMax; i++) - wc[currCounter][i] = (Word32) 0; - glob_wc[currCounter] = 0; - nbframe[currCounter] = 0; - total_wmops[currCounter] = 0.0; - for (i = 0; i < NbFuncMax; i++) - { - bc[currCounter][i] = (Word32)MAX_32; - } - glob_bc[currCounter] = MAX_32; - nbcalls[currCounter] = 0; - total_sum[currCounter] = 0.0; - - /* initially clear all counters */ - WMOPS_clearMultiCounter (); - LastWOper[currCounter] = 0; - funcid[currCounter] = 0; - - /* Following line is useful for incrIf(), see control.h */ - call_occurred = 1; - funcId_where_last_call_to_else_occurred = MAXCOUNTERS; - - sum_bc[currCounter] = MAX_32; - sum_wc[currCounter] = 0; - sum_curr[currCounter] = 0; - for (i = 0; i < MAXCOUNTERS; i++) - { - call_tree[currCounter][i] = -1; - } + for ( i = 0; i < NbFuncMax; i++ ) + wc[currCounter][i] = (Word32) 0; + glob_wc[currCounter] = 0; + nbframe[currCounter] = 0; + total_wmops[currCounter] = 0.0; + for ( i = 0; i < NbFuncMax; i++ ) + { + bc[currCounter][i] = (Word32) MAX_32; + } + glob_bc[currCounter] = MAX_32; + nbcalls[currCounter] = 0; + total_sum[currCounter] = 0.0; + + /* initially clear all counters */ + WMOPS_clearMultiCounter(); + LastWOper[currCounter] = 0; + funcid[currCounter] = 0; + + /* Following line is useful for incrIf(), see control.h */ + call_occurred = 1; + funcId_where_last_call_to_else_occurred = MAXCOUNTERS; + + sum_bc[currCounter] = MAX_32; + sum_wc[currCounter] = 0; + sum_curr[currCounter] = 0; + for ( i = 0; i < MAXCOUNTERS; i++ ) + { + call_tree[currCounter][i] = -1; + } - glob_sum_curr[currCounter] = 0; - glob_sum_wc[currCounter] = 0; - glob_sum_bc[currCounter] = MAX_32; + glob_sum_curr[currCounter] = 0; + glob_sum_wc[currCounter] = 0; + glob_sum_bc[currCounter] = MAX_32; #endif /* ifdef WMOPS */ } -Word32 Reset_WMOPS_counter(void) { +Word32 Reset_WMOPS_counter( void ) +{ #if WMOPS - Word32 tot = WMOPS_frameStat (); - - /* increase the frame counter --> a frame is counted WHEN IT BEGINS */ - nbframe[currCounter]++; - /* Call counter */ - nbcalls[currCounter] += funcid[currCounter]; - /* add wmops used in last frame to count, then reset counter (in first frame, this is a no-op */ - total_wmops[currCounter] += (float) (tot * frameRate); - total_sum[currCounter] += (float)((glob_sum_curr[currCounter]) * frameRate); - - /* clear counter before new frame starts */ - WMOPS_clearMultiCounter (); - LastWOper[currCounter] = 0; - funcid[currCounter] = 0; /* new frame, set function id to zero */ - - glob_sum_curr[currCounter] = 0; - sum_curr[currCounter] = 0; - return tot; -#else - return 0; + Word32 tot = WMOPS_frameStat(); + + /* increase the frame counter --> a frame is counted WHEN IT BEGINS */ + nbframe[currCounter]++; + /* Call counter */ + nbcalls[currCounter] += funcid[currCounter]; + /* add wmops used in last frame to count, then reset counter (in first frame, this is a no-op */ + total_wmops[currCounter] += (float) ( tot * frameRate ); + total_sum[currCounter] += (float) ( ( glob_sum_curr[currCounter] ) * frameRate ); + + /* clear counter before new frame starts */ + WMOPS_clearMultiCounter(); + LastWOper[currCounter] = 0; + funcid[currCounter] = 0; /* new frame, set function id to zero */ + + glob_sum_curr[currCounter] = 0; + sum_curr[currCounter] = 0; + return tot; +#else + return 0; #endif /* ifdef WMOPS */ } -Word32 fwc (void) { +Word32 fwc( void ) +{ /* function worst case */ #if WMOPS - Word32 tot; + Word32 tot; - tot = DeltaWeightedOperation (); - if (tot > wc[currCounter][funcid[currCounter]]) - wc[currCounter][funcid[currCounter]] = tot; + tot = DeltaWeightedOperation(); + if ( tot > wc[currCounter][funcid[currCounter]] ) + wc[currCounter][funcid[currCounter]] = tot; - if (tot < bc[currCounter][funcid[currCounter]]) - bc[currCounter][funcid[currCounter]] = tot; + if ( tot < bc[currCounter][funcid[currCounter]] ) + bc[currCounter][funcid[currCounter]] = tot; - funcid[currCounter]++; + funcid[currCounter]++; - /*make sure that BASOP_frame_update(); is put at the end of the main loop*/ - if (funcid[currCounter] >= NbFuncMax) - { - printf("to many function calls\n"); - } - assert(funcid[currCounter] < NbFuncMax); - return (tot); -#else + /*make sure that BASOP_frame_update(); is put at the end of the main loop*/ + if ( funcid[currCounter] >= NbFuncMax ) + { + printf( "to many function calls\n" ); + } + assert( funcid[currCounter] < NbFuncMax ); + return ( tot ); +#else return 0; #endif /* ifdef WMOPS */ } -void WMOPS_output (Word16 dtx_mode) { +void WMOPS_output( Word16 dtx_mode ) +{ #if WMOPS - Word16 i; - Word32 tot, tot_wm, tot_wc; + Word16 i; + Word32 tot, tot_wm, tot_wc; - /* get operations since last reset (or init), but do not update the counters (except the glob_wc[] maximum) - so output CAN be called in each frame without problems. The frame counter is NOT updated! */ - tot = WMOPS_frameStat (); - tot_wm = (Word32) (total_wmops[currCounter] + ((float) tot) * frameRate); + /* get operations since last reset (or init), but do not update the counters (except the glob_wc[] maximum) + so output CAN be called in each frame without problems. The frame counter is NOT updated! */ + tot = WMOPS_frameStat(); + tot_wm = (Word32) ( total_wmops[currCounter] + ( (float) tot ) * frameRate ); - fprintf (stdout, - "%10s:WMOPS=%.3f", objectName[currCounter] ? objectName[currCounter] : "", - ((float) tot) * frameRate); + fprintf( stdout, + "%10s:WMOPS=%.3f", objectName[currCounter] ? objectName[currCounter] : "", + ( (float) tot ) * frameRate ); - if (nbframe[currCounter] != 0) { - fprintf (stdout, " Average=%.3f", tot_wm / (float) nbframe[currCounter]); - } - fprintf (stdout, " WorstCase=%.3f", ((float) glob_wc[currCounter]) * frameRate); - - /* Worst worst case printed only when not in DTX mode */ - if (dtx_mode == 0) { - tot_wc = 0L; - for (i = 0; i < funcid[currCounter]; i++) - tot_wc += wc[currCounter][i]; - fprintf (stdout, " WorstWC=%.3f", ((float) tot_wc) * frameRate); - } - fprintf (stdout, " (%d frames)\n", nbframe[currCounter]); + if ( nbframe[currCounter] != 0 ) + { + fprintf( stdout, " Average=%.3f", tot_wm / (float) nbframe[currCounter] ); + } + fprintf( stdout, " WorstCase=%.3f", ( (float) glob_wc[currCounter] ) * frameRate ); + + /* Worst worst case printed only when not in DTX mode */ + if ( dtx_mode == 0 ) + { + tot_wc = 0L; + for ( i = 0; i < funcid[currCounter]; i++ ) + tot_wc += wc[currCounter][i]; + fprintf( stdout, " WorstWC=%.3f", ( (float) tot_wc ) * frameRate ); + } + fprintf( stdout, " (%d frames)\n", nbframe[currCounter] ); #else - (void)dtx_mode; + (void) dtx_mode; #endif /* ifdef WMOPS */ } -void WMOPS_output_avg (Word16 dtx_mode, Word32 * tot_wm, Word32 * num_frames) { +void WMOPS_output_avg( Word16 dtx_mode, Word32 *tot_wm, Word32 *num_frames ) +{ #if WMOPS - Word16 i; - Word32 tot, tot_wc; + Word16 i; + Word32 tot, tot_wc; - /* get operations since last reset (or init), but do not update the counters (except the glob_wc[] maximum) - so output CAN be called in each frame without problems. The frame counter is NOT updated! */ - tot = WMOPS_frameStat (); - *tot_wm = (Word32) (total_wmops[currCounter] + ((float) tot) * frameRate); - *num_frames = nbframe[currCounter]; + /* get operations since last reset (or init), but do not update the counters (except the glob_wc[] maximum) + so output CAN be called in each frame without problems. The frame counter is NOT updated! */ + tot = WMOPS_frameStat(); + *tot_wm = (Word32) ( total_wmops[currCounter] + ( (float) tot ) * frameRate ); + *num_frames = nbframe[currCounter]; - fprintf (stdout, "%10s:WMOPS=%.3f", objectName[currCounter] ? objectName[currCounter] : "", ((float) tot) * frameRate); + fprintf( stdout, "%10s:WMOPS=%.3f", objectName[currCounter] ? objectName[currCounter] : "", ( (float) tot ) * frameRate ); - if (nbframe[currCounter] != 0) { - fprintf (stdout, " Average=%.3f", *tot_wm / (float) nbframe[currCounter]); - } - fprintf (stdout, " WorstCase=%.3f", ((float) glob_wc[currCounter]) * frameRate); - - /* Worst worst case printed only when not in DTX mode */ - if (dtx_mode == 0) { - tot_wc = 0L; - for (i = 0; i < funcid[currCounter]; i++) - tot_wc += wc[currCounter][i]; - fprintf (stdout, " WorstWC=%.3f", ((float) tot_wc) * frameRate); - } - fprintf (stdout, " (%d frames)\n", nbframe[currCounter]); + if ( nbframe[currCounter] != 0 ) + { + fprintf( stdout, " Average=%.3f", *tot_wm / (float) nbframe[currCounter] ); + } + fprintf( stdout, " WorstCase=%.3f", ( (float) glob_wc[currCounter] ) * frameRate ); + + /* Worst worst case printed only when not in DTX mode */ + if ( dtx_mode == 0 ) + { + tot_wc = 0L; + for ( i = 0; i < funcid[currCounter]; i++ ) + tot_wc += wc[currCounter][i]; + fprintf( stdout, " WorstWC=%.3f", ( (float) tot_wc ) * frameRate ); + } + fprintf( stdout, " (%d frames)\n", nbframe[currCounter] ); #else - (void)dtx_mode; - (void)tot_wm; - (void)num_frames; + (void) dtx_mode; + (void) tot_wm; + (void) num_frames; #endif /* ifdef WMOPS */ } -void generic_WMOPS_output (Word16 dtx_mode, char *test_file_name) { +void generic_WMOPS_output( Word16 dtx_mode, char *test_file_name ) +{ #if WMOPS - int saved_value; - Word16 i; - Word32 tot, tot_wm, tot_wc, *ptr, *ptr2; - Word40 grand_total; - FILE *WMOPS_file; - - saved_value = currCounter; - - /* Count the grand_total WMOPS so that % ratio per function group can be displayed. */ - grand_total = 0; - for (currCounter = 0; currCounter <= maxCounter; currCounter++) { - tot = WMOPS_frameStat (); - grand_total += tot; - } + int saved_value; + Word16 i; + Word32 tot, tot_wm, tot_wc, *ptr, *ptr2; + Word40 grand_total; + FILE *WMOPS_file; + saved_value = currCounter; - if ((WMOPS_file = fopen (WMOPS_DATA_FILENAME, "a")) != NULL) { - - printf ("opened file %s in order to print WMOPS for each function group.\n", WMOPS_DATA_FILENAME); + /* Count the grand_total WMOPS so that % ratio per function group can be displayed. */ + grand_total = 0; + for ( currCounter = 0; currCounter <= maxCounter; currCounter++ ) + { + tot = WMOPS_frameStat(); + grand_total += tot; + } - /* Print the file header line. */ - fprintf (WMOPS_file, "Test file name\tFunction Name \tFrame\tNb Times Called\tWMOPS\t%% versus grand total"); - if (nbframe[saved_value] != 0) - fprintf (WMOPS_file, "\tAverage"); + if ( ( WMOPS_file = fopen( WMOPS_DATA_FILENAME, "a" ) ) != NULL ) + { - fprintf (WMOPS_file, "\tWorstCase"); + printf( "opened file %s in order to print WMOPS for each function group.\n", WMOPS_DATA_FILENAME ); - /* Worst worst case printed only when not in DTX mode */ - if (dtx_mode == 0) - fprintf (WMOPS_file, "\tWorstWC"); + /* Print the file header line. */ + fprintf( WMOPS_file, "Test file name\tFunction Name \tFrame\tNb Times Called\tWMOPS\t%% versus grand total" ); - fprintf (WMOPS_file, "\n"); + if ( nbframe[saved_value] != 0 ) + fprintf( WMOPS_file, "\tAverage" ); - /* Print the WMOPS for each Function Group by scanning all the function groups with currCounter index. */ - for (currCounter = 0; currCounter <= maxCounter; currCounter++) { + fprintf( WMOPS_file, "\tWorstCase" ); - fprintf (WMOPS_file, "%s", test_file_name); - fprintf (WMOPS_file, "\t%s", objectName[currCounter] ? objectName[currCounter] : ""); - fprintf (WMOPS_file, "\t%d", nbframe[currCounter]); + /* Worst worst case printed only when not in DTX mode */ + if ( dtx_mode == 0 ) + fprintf( WMOPS_file, "\tWorstWC" ); - tot = WMOPS_frameStat (); - tot_wm = (Word32) (total_wmops[currCounter] + ((float) tot) * frameRate); + fprintf( WMOPS_file, "\n" ); - fprintf (WMOPS_file, "\t\t%ld", nbTimeObjectIsCalled[currCounter]); - fprintf (WMOPS_file, "\t%.6f", ((float) tot) * frameRate); - fprintf (WMOPS_file, "\t%.3f", ((float) tot) / grand_total * 100); + /* Print the WMOPS for each Function Group by scanning all the function groups with currCounter index. */ + for ( currCounter = 0; currCounter <= maxCounter; currCounter++ ) + { - if (nbframe[currCounter] != 0) - fprintf (WMOPS_file, "\t%.3f", tot_wm / (float) nbframe[currCounter]); + fprintf( WMOPS_file, "%s", test_file_name ); + fprintf( WMOPS_file, "\t%s", objectName[currCounter] ? objectName[currCounter] : "" ); + fprintf( WMOPS_file, "\t%d", nbframe[currCounter] ); - fprintf (WMOPS_file, "\t%.3f", ((float) glob_wc[currCounter]) * frameRate); + tot = WMOPS_frameStat(); + tot_wm = (Word32) ( total_wmops[currCounter] + ( (float) tot ) * frameRate ); - /* Worst worst case printed only when not in DTX mode */ - if (dtx_mode == 0) { - tot_wc = 0L; - for (i = 0; i < funcid[currCounter]; i++) - tot_wc += wc[currCounter][i]; - fprintf (WMOPS_file, "\t%.3f", ((float) tot_wc) * frameRate); - } - fprintf (WMOPS_file, "\n"); + fprintf( WMOPS_file, "\t\t%ld", nbTimeObjectIsCalled[currCounter] ); + fprintf( WMOPS_file, "\t%.6f", ( (float) tot ) * frameRate ); + fprintf( WMOPS_file, "\t%.3f", ( (float) tot ) / grand_total * 100 ); - } + if ( nbframe[currCounter] != 0 ) + fprintf( WMOPS_file, "\t%.3f", tot_wm / (float) nbframe[currCounter] ); - /* Print the file Grand Total line */ - fprintf (WMOPS_file, "%s", test_file_name); - fprintf (WMOPS_file, "\tGrand Total"); - fprintf (WMOPS_file, "\t%d", nbframe[saved_value]); - fprintf (WMOPS_file, "\t\t%.6f", ((float) grand_total) * frameRate); - fprintf (WMOPS_file, "\t100.000"); - fprintf (WMOPS_file, "\n"); - fclose (WMOPS_file); + fprintf( WMOPS_file, "\t%.3f", ( (float) glob_wc[currCounter] ) * frameRate ); - } else - printf ("Can not open file %s for WMOPS editing\n", WMOPS_DATA_FILENAME); + /* Worst worst case printed only when not in DTX mode */ + if ( dtx_mode == 0 ) + { + tot_wc = 0L; + for ( i = 0; i < funcid[currCounter]; i++ ) + tot_wc += wc[currCounter][i]; + fprintf( WMOPS_file, "\t%.3f", ( (float) tot_wc ) * frameRate ); + } + fprintf( WMOPS_file, "\n" ); + } + /* Print the file Grand Total line */ + fprintf( WMOPS_file, "%s", test_file_name ); + fprintf( WMOPS_file, "\tGrand Total" ); + fprintf( WMOPS_file, "\t%d", nbframe[saved_value] ); + fprintf( WMOPS_file, "\t\t%.6f", ( (float) grand_total ) * frameRate ); + fprintf( WMOPS_file, "\t100.000" ); + fprintf( WMOPS_file, "\n" ); + fclose( WMOPS_file ); + } + else + printf( "Can not open file %s for WMOPS editing\n", WMOPS_DATA_FILENAME ); - if ((WMOPS_file = fopen (WMOPS_TOTAL_FILENAME, "a")) != NULL) { - printf ("opened file %s in order to print application's total WMOPS.\n", WMOPS_TOTAL_FILENAME); - fprintf (WMOPS_file, "%s", test_file_name); - fprintf (WMOPS_file, "\tframe=%d", nbframe[currCounter]); - fprintf (WMOPS_file, "\tWMOPS=%.6f", ((float) grand_total) * frameRate); - fprintf (WMOPS_file, "\n"); - fclose (WMOPS_file); - } else - printf ("Can not open file %s for WMOPS editing.\n", WMOPS_TOTAL_FILENAME); + if ( ( WMOPS_file = fopen( WMOPS_TOTAL_FILENAME, "a" ) ) != NULL ) + { + printf( "opened file %s in order to print application's total WMOPS.\n", WMOPS_TOTAL_FILENAME ); + fprintf( WMOPS_file, "%s", test_file_name ); + fprintf( WMOPS_file, "\tframe=%d", nbframe[currCounter] ); + fprintf( WMOPS_file, "\tWMOPS=%.6f", ( (float) grand_total ) * frameRate ); + fprintf( WMOPS_file, "\n" ); + fclose( WMOPS_file ); + } + else + printf( "Can not open file %s for WMOPS editing.\n", WMOPS_TOTAL_FILENAME ); - if ((WMOPS_file = fopen (CODE_PROFILE_FILENAME, "a")) != NULL) { + if ( ( WMOPS_file = fopen( CODE_PROFILE_FILENAME, "a" ) ) != NULL ) + { - printf ("opened file %s in order to print basic operation distribution statistics.\n", CODE_PROFILE_FILENAME); + printf( "opened file %s in order to print basic operation distribution statistics.\n", CODE_PROFILE_FILENAME ); - /* Print the file header line. */ - fprintf (WMOPS_file, "Test file name\tBasic Operation Name\tframe\tWMOPS\t\t%% versus grand total\n"); + /* Print the file header line. */ + fprintf( WMOPS_file, "Test file name\tBasic Operation Name\tframe\tWMOPS\t\t%% versus grand total\n" ); - /* Print the WMOPS for each Basic Operation across all the defined */ - /* Function Groups. */ - for (i = 0; i < (Word16)(sizeof (op_weight) / sizeof (Word32)); i++) { - fprintf (WMOPS_file, "%-16s", test_file_name); - fprintf (WMOPS_file, "\t%s", BasicOperationList[i]); - fprintf (WMOPS_file, "\t%d", nbframe[0]); + /* Print the WMOPS for each Basic Operation across all the defined */ + /* Function Groups. */ + for ( i = 0; i < (Word16) ( sizeof( op_weight ) / sizeof( Word32 ) ); i++ ) + { + fprintf( WMOPS_file, "%-16s", test_file_name ); + fprintf( WMOPS_file, "\t%s", BasicOperationList[i] ); + fprintf( WMOPS_file, "\t%d", nbframe[0] ); + + tot = 0; + ptr = (Word32 *) &multiCounter[0] + i; + ptr2 = (Word32 *) &op_weight + i; + for ( currCounter = 0; currCounter <= maxCounter; currCounter++ ) + { + tot += ( ( *ptr ) * ( *ptr2 ) ); + ptr += ( sizeof( op_weight ) / sizeof( Word32 ) ); + } - tot = 0; - ptr = (Word32 *) & multiCounter[0] + i; - ptr2 = (Word32 *) & op_weight + i; - for (currCounter = 0; currCounter <= maxCounter; currCounter++) { - tot += ((*ptr) * (*ptr2)); - ptr += (sizeof (op_weight) / sizeof (Word32)); - } + fprintf( WMOPS_file, "\t%.6f", ( (float) tot ) * frameRate ); + fprintf( WMOPS_file, "\t%.3f", ( (float) tot ) / grand_total * 100 ); + fprintf( WMOPS_file, "\n" ); + } - fprintf (WMOPS_file, "\t%.6f", ((float) tot) * frameRate); - fprintf (WMOPS_file, "\t%.3f", ((float) tot) / grand_total * 100); - fprintf (WMOPS_file, "\n"); + /* Print the file Grand Total line */ + fprintf( WMOPS_file, "%s", test_file_name ); + fprintf( WMOPS_file, "\tGrand Total" ); + fprintf( WMOPS_file, "\t%d", nbframe[saved_value] ); + fprintf( WMOPS_file, "\t%.6f", ( (float) grand_total ) * frameRate ); + fprintf( WMOPS_file, "\t100.000" ); + fprintf( WMOPS_file, "\n" ); + fclose( WMOPS_file ); } + else + printf( "Can not open file %s for basic operations distribution statistic editing\n", CODE_PROFILE_FILENAME ); - /* Print the file Grand Total line */ - fprintf (WMOPS_file, "%s", test_file_name); - fprintf (WMOPS_file, "\tGrand Total"); - fprintf (WMOPS_file, "\t%d", nbframe[saved_value]); - fprintf (WMOPS_file, "\t%.6f", ((float) grand_total) * frameRate); - fprintf (WMOPS_file, "\t100.000"); - fprintf (WMOPS_file, "\n"); - fclose (WMOPS_file); - - } else - printf ("Can not open file %s for basic operations distribution statistic editing\n", CODE_PROFILE_FILENAME); - - currCounter = saved_value; + currCounter = saved_value; #else - (void)dtx_mode; - (void)test_file_name; + (void) dtx_mode; + (void) test_file_name; #endif /* ifdef WMOPS */ } /* FROM_EVS_DEV */ -#define MAX_STACK 64 +#define MAX_STACK 64 #if WMOPS static int stack[MAX_STACK]; static int sptr; @@ -862,335 +785,346 @@ static int sum_stack[MAX_STACK]; #endif /* jdr 20120117: add FLC similar functions */ -void BASOP_frame_update(void) +void BASOP_frame_update( void ) { #if WMOPS - int i, current; + int i, current; #if MAX_CALLERS_SAVED_FRAMES - int k; + int k; #endif - float total = 0.0f; + float total = 0.0f; #ifdef DEBUG - { - static int sptr_target=-2; - - if (sptr_target == -2) { - sptr_target = sptr; - } else { - if (sptr_target != sptr) { - fprintf(stderr, "BASOP_sub_start/BASOP_sub_end imbalance detected!!!\n"); - sptr_target = sptr; - } + { + static int sptr_target = -2; + + if ( sptr_target == -2 ) + { + sptr_target = sptr; + } + else + { + if ( sptr_target != sptr ) + { + fprintf( stderr, "BASOP_sub_start/BASOP_sub_end imbalance detected!!!\n" ); + sptr_target = sptr; + } + } } - } #endif - /* Get current counter */ - current = readCounterId(); - - /* Update global operation counters */ - for (i=1; i<=maxCounter; i++) - { - int j; + /* Get current counter */ + current = readCounterId(); - for (j=0; j< (int)(sizeof(BASIC_OP)/sizeof(UWord32)); j++) + /* Update global operation counters */ + for ( i = 1; i <= maxCounter; i++ ) { - ((UWord32*)&glob_multiCounter)[j] += ((UWord32*)&multiCounter[i])[j]; + int j; + + for ( j = 0; j < (int) ( sizeof( BASIC_OP ) / sizeof( UWord32 ) ); j++ ) + { + ( (UWord32 *) &glob_multiCounter )[j] += ( (UWord32 *) &multiCounter[i] )[j]; + } } - } #if MAX_CALLERS_SAVED_FRAMES - /* Reset all counters */ - for (i=1; i<=maxCounter; i++) - { - callers_frames[0][i] = 0.0f; - } + /* Reset all counters */ + for ( i = 1; i <= maxCounter; i++ ) + { + callers_frames[0][i] = 0.0f; + } #endif - /* Reset all counters */ - for (i=1; i<=maxCounter; i++) - { - if (current != i && funcid[i] > 0) { - setCounter(i); + /* Reset all counters */ + for ( i = 1; i <= maxCounter; i++ ) + { + if ( current != i && funcid[i] > 0 ) + { + setCounter( i ); - glob_sum_curr[currCounter] += sum_curr[currCounter]; + glob_sum_curr[currCounter] += sum_curr[currCounter]; - if (glob_sum_curr[currCounter] > glob_sum_wc[currCounter]) { - glob_sum_wc[currCounter] = glob_sum_curr[currCounter]; - } - if (glob_sum_curr[currCounter] < glob_sum_bc[currCounter]) { - glob_sum_bc[currCounter] = glob_sum_curr[currCounter]; - } + if ( glob_sum_curr[currCounter] > glob_sum_wc[currCounter] ) + { + glob_sum_wc[currCounter] = glob_sum_curr[currCounter]; + } + if ( glob_sum_curr[currCounter] < glob_sum_bc[currCounter] ) + { + glob_sum_bc[currCounter] = glob_sum_curr[currCounter]; + } #if MAX_CALLERS_SAVED_FRAMES - /* Keep a Copy before it is Reset */ - callers_frames[0][currCounter] = (float)Reset_WMOPS_counter(); - total += callers_frames[0][currCounter]; + /* Keep a Copy before it is Reset */ + callers_frames[0][currCounter] = (float) Reset_WMOPS_counter(); + total += callers_frames[0][currCounter]; #else - total += (float)Reset_WMOPS_counter(); + total += (float) Reset_WMOPS_counter(); #endif + } } - } #if MAX_CALLERS_SAVED_FRAMES - /* Keep Callers for this Worst Case Frame */ - /* Select Slot to Use (Slot 0 is the Current) */ - k = 0; - for (i=k+1; i callers_totals[k]) - { - k+=1; - /* Save Info of Callers */ - for (i=1; i<=maxCounter; i++) + /* Current Greater than the Min? */ + if ( total > callers_totals[k] ) { - callers_frames[k][i] = callers_frames[0][i]; + k += 1; + /* Save Info of Callers */ + for ( i = 1; i <= maxCounter; i++ ) + { + callers_frames[k][i] = callers_frames[0][i]; + } + if ( i < MAXCOUNTERS ) + callers_frames[k][i] = -1; + /* Save Total */ + callers_totals[k - 1] = total; + /* Save Frame Number */ + callers_frames_nos[k - 1] = nbframe[0]; } - if (i < MAXCOUNTERS) - callers_frames[k][i] = -1; - /* Save Total */ - callers_totals[k-1] = total; - /* Save Frame Number */ - callers_frames_nos[k-1] = nbframe[0]; - } #endif - if (total < glob_bc[0]) { - glob_bc[0] = (Word32) total; - } - if (total > glob_wc[0]) { - glob_wc[0] = (Word32) total; - - } - /* Restore current counter */ - setCounter(current); + if ( total < glob_bc[0] ) + { + glob_bc[0] = (Word32) total; + } + if ( total > glob_wc[0] ) + { + glob_wc[0] = (Word32) total; + } + /* Restore current counter */ + setCounter( current ); - nbframe[0] ++; + nbframe[0]++; #endif /* if WMOPS */ } -void printStack(char *text, char* Id) +void printStack( char *text, char *Id ) { #if WMOPS - int i; - if (!Id) return; - if (!strcmp("*", Id) || (!strcmp(Id,objectName[currCounter]))) - { - printf ("%s %s", text, objectName[currCounter]); - for (i=sptr-1; i>0; i--) { - printf(" <- %s", objectName[stack[i]]); - } - printf("\n"); - } + int i; + if ( !Id ) + return; + if ( !strcmp( "*", Id ) || ( !strcmp( Id, objectName[currCounter] ) ) ) + { + printf( "%s %s", text, objectName[currCounter] ); + for ( i = sptr - 1; i > 0; i-- ) + { + printf( " <- %s", objectName[stack[i]] ); + } + printf( "\n" ); + } #else - printf("%s %s\n", text, Id ? Id : "(no name)"); + printf( "%s %s\n", text, Id ? Id : "(no name)" ); #endif } -void BASOP_push_wmops (const char *label) +void BASOP_push_wmops( const char *label ) { #if WMOPS - int new_flag, prev_counter; - int i, j; + int new_flag, prev_counter; + int i, j; - /* Check if new counter label */ - new_flag = 1; - for (i = 1; i <= maxCounter; i++) + /* Check if new counter label */ + new_flag = 1; + for ( i = 1; i <= maxCounter; i++ ) { - if (strcmp(objectName[i], label) == 0) + if ( strcmp( objectName[i], label ) == 0 ) { - new_flag = 0; - break; + new_flag = 0; + break; } } - prev_counter = readCounterId(); + prev_counter = readCounterId(); - /* Configure new record */ - if (new_flag) + /* Configure new record */ + if ( new_flag ) { - i = (int)getCounterId(label); - setCounter(i); - Init_WMOPS_counter(); + i = (int) getCounterId( label ); + setCounter( i ); + Init_WMOPS_counter(); } - else + else { - setCounter(i); + setCounter( i ); } - /* Push current context onto stack */ - if (currCounter >= 0) + /* Push current context onto stack */ + if ( currCounter >= 0 ) { - if (sptr >= MAX_STACK) + if ( sptr >= MAX_STACK ) { - fprintf (stderr, "\r push_wmops(): stack exceeded, try inreasing MAX_STACK\n"); - exit (-1); + fprintf( stderr, "\r push_wmops(): stack exceeded, try inreasing MAX_STACK\n" ); + exit( -1 ); } - stack[sptr++] = prev_counter; + stack[sptr++] = prev_counter; - /* Reset accumulated WMOPS */ - sum_stack[sptr] = 0; + /* Reset accumulated WMOPS */ + sum_stack[sptr] = 0; - /* update call tree */ - for (j = 0; j < MAXCOUNTERS; j++) + /* update call tree */ + for ( j = 0; j < MAXCOUNTERS; j++ ) { - if (call_tree[i][j] == prev_counter) + if ( call_tree[i][j] == prev_counter ) { - break; + break; } - else if (call_tree[i][j] == -1) + else if ( call_tree[i][j] == -1 ) { - call_tree[i][j] = (Word16)prev_counter; - break; + call_tree[i][j] = (Word16) prev_counter; + break; } } } - /*wmops[currCounter].start_selfcnt = ops_cnt; - wmops[currCounter].start_cnt = ops_cnt; - nbTimeObjectIsCalled[currCounter]++;*/ + /*wmops[currCounter].start_selfcnt = ops_cnt; + wmops[currCounter].start_cnt = ops_cnt; + nbTimeObjectIsCalled[currCounter]++;*/ - incrementNbTimeObjectIsCalled(currCounter); + incrementNbTimeObjectIsCalled( currCounter ); - sum_curr[currCounter] = 0; + sum_curr[currCounter] = 0; #ifdef DEBUG_COUNTER - printf("Entering: %s\n", readCounterIdName()); + printf( "Entering: %s\n", readCounterIdName() ); #endif #endif /* if WMOPS */ - UNUSED_PARAM(label); + UNUSED_PARAM( label ); } -Word32 BASOP_pop_wmops (void) +Word32 BASOP_pop_wmops( void ) { #if WMOPS - Word32 ops_cnt; + Word32 ops_cnt; #ifdef DEBUG_COUNTER - printf("Exiting: %s\n", readCounterIdName()); + printf( "Exiting: %s\n", readCounterIdName() ); #endif - ops_cnt = fwc(); + ops_cnt = fwc(); - /* Get back previous context from stack */ - if (sptr > 0) + /* Get back previous context from stack */ + if ( sptr > 0 ) { - int prevCounter; + int prevCounter; - sum_stack[sptr] += ops_cnt; - prevCounter = currCounter; - setCounter(stack[--sptr]); - sum_stack[sptr] += sum_stack[sptr+1]; - sum_curr[prevCounter] += sum_stack[sptr+1]; + sum_stack[sptr] += ops_cnt; + prevCounter = currCounter; + setCounter( stack[--sptr] ); + sum_stack[sptr] += sum_stack[sptr + 1]; + sum_curr[prevCounter] += sum_stack[sptr + 1]; } - else + else { - /* current_record = -1; */ - setCounter(0); + /* current_record = -1; */ + setCounter( 0 ); } - if (sum_curr[currCounter] > sum_wc[currCounter]) { - sum_wc[currCounter] = sum_curr[currCounter]; - } - if (sum_curr[currCounter] < sum_bc[currCounter]) { - sum_bc[currCounter] = sum_curr[currCounter]; - } + if ( sum_curr[currCounter] > sum_wc[currCounter] ) + { + sum_wc[currCounter] = sum_curr[currCounter]; + } + if ( sum_curr[currCounter] < sum_bc[currCounter] ) + { + sum_bc[currCounter] = sum_curr[currCounter]; + } - return ops_cnt; -#else /* if WMOPS */ - return 0; + return ops_cnt; +#else /* if WMOPS */ + return 0; #endif /* if WMOPS */ } -Word32 BASOP_get_wops (void) +Word32 BASOP_get_wops( void ) { - return BASOP_pop_wmops(); + return BASOP_pop_wmops(); } #define FRAMES_PER_SECOND 50.0 -#define MILLION_CYCLES 1e6 -#define FAC (FRAMES_PER_SECOND/MILLION_CYCLES) +#define MILLION_CYCLES 1e6 +#define FAC ( FRAMES_PER_SECOND / MILLION_CYCLES ) #if WMOPS static Word32 prom_cnt = 0; #endif -void WMOPS_destroy(void) +void WMOPS_destroy( void ) { #if WMOPS - int i; + int i; - /* release the memory allocated for the objectName array */ - for (i = 0; i < MAXCOUNTERS+1; i++) - { - if (NULL != objectName[i]) - { - free(objectName[i]); - objectName[i] = NULL; - } - } + /* release the memory allocated for the objectName array */ + for ( i = 0; i < MAXCOUNTERS + 1; i++ ) + { + if ( NULL != objectName[i] ) + { + free( objectName[i] ); + objectName[i] = NULL; + } + } - maxCounter = 0; + maxCounter = 0; #endif - return; + return; } -void WMOPS_output_all(Word16 dtx_mode) +void WMOPS_output_all( Word16 dtx_mode ) { #if WMOPS - float ops_cnt = 0.0f; - int i; - - char *sfmts = "%-40s %8s %8s %7s %7s\n"; - char *dfmts = "%-40s %8.2f %8.3f %7.3f %7.3f\n"; - char *sfmt = "%-40s %8s %8s %7s %7s %7s %7s %7s\n"; - char *dfmt = "%-40s %8.2f %8.3f %7.3f %7.3f %7.3f %7.3f %7.3f\n"; - - fprintf (stderr, "\nProgram Memory Analysis: %12.0f words\n", (float)prom_cnt); - /*fprintf (stderr, "\nInstruction Type Analysis (for worst case frame):\n\n");*/ - fprintf (stderr, "\nInstruction Type Analysis (for worst case frame number %ld):\n\n", (long int)nbframe[0]); /* added -- JPA */ - for (i = 0; i < (int)(sizeof(BasicOperationList)/sizeof(char*)) ; i++) + float ops_cnt = 0.0f; + int i; + + char *sfmts = "%-40s %8s %8s %7s %7s\n"; + char *dfmts = "%-40s %8.2f %8.3f %7.3f %7.3f\n"; + char *sfmt = "%-40s %8s %8s %7s %7s %7s %7s %7s\n"; + char *dfmt = "%-40s %8.2f %8.3f %7.3f %7.3f %7.3f %7.3f %7.3f\n"; + + fprintf( stderr, "\nProgram Memory Analysis: %12.0f words\n", (float) prom_cnt ); + /*fprintf (stderr, "\nInstruction Type Analysis (for worst case frame):\n\n");*/ + fprintf( stderr, "\nInstruction Type Analysis (for worst case frame number %ld):\n\n", (long int) nbframe[0] ); /* added -- JPA */ + for ( i = 0; i < (int) ( sizeof( BasicOperationList ) / sizeof( char * ) ); i++ ) { - if ( ( (UWord32 *) &glob_multiCounter )[i] > 0) - fprintf (stderr, "\t%16s: %12d\n", BasicOperationList[i], ((UWord32*)&glob_multiCounter)[i]); + if ( ( (UWord32 *) &glob_multiCounter )[i] > 0 ) + fprintf( stderr, "\t%16s: %12d\n", BasicOperationList[i], ( (UWord32 *) &glob_multiCounter )[i] ); } - fprintf (stderr, "\n\nWeighted MOPS Analysis:\n"); - fprintf (stderr, "%74s %23s\n", "|------ SELF ------|" - ,"|--- CUMULATIVE ---|"); - fprintf (stderr, sfmt, " routine", " calls", " min ", " max ", " avg ", " min ", " max ", " avg "); - fprintf (stderr, sfmt, " ------------------------", " ------", "------", "------", "------", "------", "------", "------"); - for (i = 1; i <= maxCounter; i++) + fprintf( stderr, "\n\nWeighted MOPS Analysis:\n" ); + fprintf( stderr, "%74s %23s\n", "|------ SELF ------|", "|--- CUMULATIVE ---|" ); + fprintf( stderr, sfmt, " routine", " calls", " min ", " max ", " avg ", " min ", " max ", " avg " ); + fprintf( stderr, sfmt, " ------------------------", " ------", "------", "------", "------", "------", "------", "------" ); + for ( i = 1; i <= maxCounter; i++ ) { - if ( nbcalls[i] > 0 ) - { - fprintf( stderr, dfmt, - objectName[i], - ( nbframe[i] == 0 ) ? 0 : (float) nbcalls[i] / (float) nbframe[0], - ( glob_bc[i] == 0 ) ? 0 : frameRate * (float) glob_bc[i], - ( glob_wc[i] == 0 ) ? 0 : frameRate * (float) glob_wc[i], - ( nbframe[i] == 0 ) ? 0 : (float) total_wmops[i] / (float) nbframe[i], - frameRate * ( glob_sum_bc[i] ), - frameRate * ( glob_sum_wc[i] ), - ( nbframe[i] == 0 ) ? 0 : (float) ( total_sum[i] / (float) nbframe[i] ) ); - /* frameRate*(glob_bc[i]+wmops_children_bc[i]), */ - /* frameRate*(glob_wc[i]+wmops_children_wc[i]), */ - /* (nbframe[i] == 0) ? 0 : (float)((total_wmops[i] + total_wmops_children[i]) /(float)nbframe[i])); */ - } - ops_cnt += total_wmops[i]; + if ( nbcalls[i] > 0 ) + { + fprintf( stderr, dfmt, + objectName[i], + ( nbframe[i] == 0 ) ? 0 : (float) nbcalls[i] / (float) nbframe[0], + ( glob_bc[i] == 0 ) ? 0 : frameRate * (float) glob_bc[i], + ( glob_wc[i] == 0 ) ? 0 : frameRate * (float) glob_wc[i], + ( nbframe[i] == 0 ) ? 0 : (float) total_wmops[i] / (float) nbframe[i], + frameRate * ( glob_sum_bc[i] ), + frameRate * ( glob_sum_wc[i] ), + ( nbframe[i] == 0 ) ? 0 : (float) ( total_sum[i] / (float) nbframe[i] ) ); + /* frameRate*(glob_bc[i]+wmops_children_bc[i]), */ + /* frameRate*(glob_wc[i]+wmops_children_wc[i]), */ + /* (nbframe[i] == 0) ? 0 : (float)((total_wmops[i] + total_wmops_children[i]) /(float)nbframe[i])); */ + } + ops_cnt += total_wmops[i]; } - fprintf (stderr, sfmts, " -----------------", " ------", "------", "------", "------"); + fprintf( stderr, sfmts, " -----------------", " ------", "------", "------", "------" ); if ( nbframe[i] > 0 ) { fprintf( stderr, dfmts, @@ -1238,113 +1172,112 @@ void WMOPS_output_all(Word16 dtx_mode) WMOPS_output(dtx_mode); } #else - (void)dtx_mode; + (void) dtx_mode; #endif #if MAX_CALLERS_SAVED_FRAMES - for (i = 1; i <= MAX_CALLERS_SAVED_FRAMES; i++) - { - int j, k, l, m; - const char *frame_rank[] = { "st", "nd", "rd", "th" }; - float current; + for ( i = 1; i <= MAX_CALLERS_SAVED_FRAMES; i++ ) + { + int j, k, l, m; + const char *frame_rank[] = { "st", "nd", "rd", "th" }; + float current; - k = 0; - for (j=k+1; j callers_totals[k]) - { /* Yes */ - k = j; - } - } - k+=1; - - fprintf(stderr, "\nActive Callers Report for %i%s Worst Case Frame #: %i\n", - i, i<=3?frame_rank[i-1]:frame_rank[3], - callers_frames_nos[k-1]); - /* Print up to 'MAX_CALLERS_PRINT' Callers */ - current = 0.0f; - for (l = 0; l < MAX_CALLERS_PRINT; l++) - { - /* Find Highest Complexity */ - m = 1; - for (j = m+1; j <= maxCounter; j++) - { - if (callers_frames[k][j] < 0) + k = 0; + for ( j = k + 1; j < MAX_CALLERS_SAVED_FRAMES; j++ ) + { + /* Is it the Max? */ + if ( callers_totals[j] > callers_totals[k] ) + { /* Yes */ + k = j; + } + } + k += 1; + + fprintf( stderr, "\nActive Callers Report for %i%s Worst Case Frame #: %i\n", + i, i <= 3 ? frame_rank[i - 1] : frame_rank[3], + callers_frames_nos[k - 1] ); + /* Print up to 'MAX_CALLERS_PRINT' Callers */ + current = 0.0f; + for ( l = 0; l < MAX_CALLERS_PRINT; l++ ) + { + /* Find Highest Complexity */ + m = 1; + for ( j = m + 1; j <= maxCounter; j++ ) + { + if ( callers_frames[k][j] < 0 ) + break; + if ( callers_frames[k][j] > callers_frames[k][m] ) + m = j; + } + /* Done ? */ + if ( callers_frames[k][m] == 0 ) break; - if (callers_frames[k][j] > callers_frames[k][m]) - m = j; - } - /* Done ? */ - if (callers_frames[k][m] == 0) - break; - fprintf(stderr, " %-52s %10.3f\n", objectName[m], callers_frames[k][m]*frameRate); - /* Count it */ - current += callers_frames[k][m]; - /* Mark as Done */ - callers_frames[k][m] = 0.0f; - } - /* Check if All Printed */ - if (current+0.001f < callers_totals[k-1]) - { - fprintf(stderr, " Only first %i Callers have been Printed!\n", MAX_CALLERS_PRINT); - fprintf(stderr, " %-52s %10.3f\n", "Total for non Printed", (callers_totals[k-1]-current)*frameRate); - } - fprintf(stderr, " %-52s %10.3f\n", "Total", callers_totals[k-1]*frameRate); - /* Mark as Done */ - callers_totals[k-1] = 0.0f; - } + fprintf( stderr, " %-52s %10.3f\n", objectName[m], callers_frames[k][m] * frameRate ); + /* Count it */ + current += callers_frames[k][m]; + /* Mark as Done */ + callers_frames[k][m] = 0.0f; + } + /* Check if All Printed */ + if ( current + 0.001f < callers_totals[k - 1] ) + { + fprintf( stderr, " Only first %i Callers have been Printed!\n", MAX_CALLERS_PRINT ); + fprintf( stderr, " %-52s %10.3f\n", "Total for non Printed", ( callers_totals[k - 1] - current ) * frameRate ); + } + fprintf( stderr, " %-52s %10.3f\n", "Total", callers_totals[k - 1] * frameRate ); + /* Mark as Done */ + callers_totals[k - 1] = 0.0f; + } #endif - WMOPS_destroy(); + WMOPS_destroy(); #endif /* if WMOPS */ - UNUSED_PARAM(dtx_mode); + UNUSED_PARAM( dtx_mode ); } -void WMOPS_output_all_std(Word16 dtx_mode) +void WMOPS_output_all_std( Word16 dtx_mode ) { #if WMOPS - float ops_cnt = 0.0f; - int i; - - char *sfmts = "%-40s %8s %8s %7s %7s\n"; - char *dfmts = "%-40s %8.2f %8.3f %7.3f %7.3f\n"; - char *sfmt = "%-40s %8s %8s %7s %7s %7s %7s %7s\n"; - char *dfmt = "%-40s %8.2f %8.3f %7.3f %7.3f %7.3f %7.3f %7.3f\n"; - - fprintf (stdout, "\nProgram Memory Analysis: %12.0f words\n", (float)prom_cnt); - /*fprintf (stdout, "\nInstruction Type Analysis (for worst case frame):\n\n");*/ - fprintf (stdout, "\nInstruction Type Analysis (for worst case frame number %ld):\n\n", (long int)nbframe[0]); /* added -- JPA */ - if ( nbframe[0] > 0 ) - { - for ( i = 0; i < (int) ( sizeof( BasicOperationList ) / sizeof( char * ) ); i++ ) - { - if ( ((UWord32 *) &glob_multiCounter )[i] > 0 ) - fprintf( stdout, "\t%16s: %12d\n", BasicOperationList[i], ( (UWord32 *) &glob_multiCounter )[i] ); - } - } - fprintf (stdout, "\n\nWeighted MOPS Analysis:\n"); - fprintf (stdout, "%74s %23s\n", "|------ SELF ------|" - ,"|--- CUMULATIVE ---|"); - fprintf (stdout, sfmt, " routine", "calls/fr", " min ", " max ", " avg ", " min ", " max ", " avg "); - fprintf (stdout, sfmt, " ------------------------", " ------", "------", "------", "------", "------", "------", "------"); - for (i = 1; i <= maxCounter; i++) - { - fprintf( stdout, dfmt, - objectName[i], - ( nbframe[i] == 0 ) ? 0 : (float) nbcalls[i] / (float) nbframe[0], - ( glob_bc[i] == MAX_32 ) ? 0 : frameRate * (float) glob_bc[i], - ( glob_wc[i] == 0 ) ? 0 : frameRate * (float) glob_wc[i], - ( nbframe[i] == 0 ) ? 0 : (float) total_wmops[i] / (float) nbframe[i], - frameRate * ( glob_sum_bc[i] ), - frameRate * ( glob_sum_wc[i] ), - ( nbframe[i] == 0 ) ? 0 : (float) ( ( total_sum[i] ) / (float) nbframe[i] ) ); - /* frameRate*(glob_bc[i]+wmops_children_bc[i]), */ - /* frameRate*(glob_wc[i]+wmops_children_wc[i]), */ - /* (nbframe[i] == 0) ? 0 : (float)((total_sum[i]) /(float)nbframe[i])); */ - ops_cnt += total_wmops[i]; + float ops_cnt = 0.0f; + int i; + + char *sfmts = "%-40s %8s %8s %7s %7s\n"; + char *dfmts = "%-40s %8.2f %8.3f %7.3f %7.3f\n"; + char *sfmt = "%-40s %8s %8s %7s %7s %7s %7s %7s\n"; + char *dfmt = "%-40s %8.2f %8.3f %7.3f %7.3f %7.3f %7.3f %7.3f\n"; + + fprintf( stdout, "\nProgram Memory Analysis: %12.0f words\n", (float) prom_cnt ); + /*fprintf (stdout, "\nInstruction Type Analysis (for worst case frame):\n\n");*/ + fprintf( stdout, "\nInstruction Type Analysis (for worst case frame number %ld):\n\n", (long int) nbframe[0] ); /* added -- JPA */ + if ( nbframe[0] > 0 ) + { + for ( i = 0; i < (int) ( sizeof( BasicOperationList ) / sizeof( char * ) ); i++ ) + { + if ( ( (UWord32 *) &glob_multiCounter )[i] > 0 ) + fprintf( stdout, "\t%16s: %12d\n", BasicOperationList[i], ( (UWord32 *) &glob_multiCounter )[i] ); + } + } + fprintf( stdout, "\n\nWeighted MOPS Analysis:\n" ); + fprintf( stdout, "%74s %23s\n", "|------ SELF ------|", "|--- CUMULATIVE ---|" ); + fprintf( stdout, sfmt, " routine", "calls/fr", " min ", " max ", " avg ", " min ", " max ", " avg " ); + fprintf( stdout, sfmt, " ------------------------", " ------", "------", "------", "------", "------", "------", "------" ); + for ( i = 1; i <= maxCounter; i++ ) + { + fprintf( stdout, dfmt, + objectName[i], + ( nbframe[i] == 0 ) ? 0 : (float) nbcalls[i] / (float) nbframe[0], + ( glob_bc[i] == MAX_32 ) ? 0 : frameRate * (float) glob_bc[i], + ( glob_wc[i] == 0 ) ? 0 : frameRate * (float) glob_wc[i], + ( nbframe[i] == 0 ) ? 0 : (float) total_wmops[i] / (float) nbframe[i], + frameRate * ( glob_sum_bc[i] ), + frameRate * ( glob_sum_wc[i] ), + ( nbframe[i] == 0 ) ? 0 : (float) ( ( total_sum[i] ) / (float) nbframe[i] ) ); + /* frameRate*(glob_bc[i]+wmops_children_bc[i]), */ + /* frameRate*(glob_wc[i]+wmops_children_wc[i]), */ + /* (nbframe[i] == 0) ? 0 : (float)((total_sum[i]) /(float)nbframe[i])); */ + ops_cnt += total_wmops[i]; } - fprintf (stdout, sfmts, " -----------------", " ------", "------", "------", "------"); + fprintf( stdout, sfmts, " -----------------", " ------", "------", "------", "------" ); if ( nbframe[0] > 0 ) { fprintf( stdout, dfmts, @@ -1392,55 +1325,56 @@ void WMOPS_output_all_std(Word16 dtx_mode) WMOPS_output(dtx_mode); } #else - (void)dtx_mode; + (void) dtx_mode; #endif - WMOPS_destroy(); + WMOPS_destroy(); #endif /* if WMOPS */ - UNUSED_PARAM(dtx_mode); + UNUSED_PARAM( dtx_mode ); } -void Reset_all_WMOPS_counter (void) +void Reset_all_WMOPS_counter( void ) { #if WMOPS - int i; - int currCounterSave; + int i; + int currCounterSave; - currCounterSave = currCounter; + currCounterSave = currCounter; - for (i=2; i <= maxCounter; i++) - { - setCounter(i); - Init_WMOPS_counter(); - objectName[i] = 0; - } + for ( i = 2; i <= maxCounter; i++ ) + { + setCounter( i ); + Init_WMOPS_counter(); + objectName[i] = 0; + } - currCounter = currCounterSave; - maxCounter = 1; + currCounter = currCounterSave; + maxCounter = 1; #endif /* if WMOPS */ } /* Returns the total min/max/avg WMOPS values like printed in BASOP_end(). */ -void BASOP_get_total_wmops(double *min, double *max, double *avg) +void BASOP_get_total_wmops( double *min, double *max, double *avg ) { #if WMOPS - if(min != NULL) - *min = frameRate * glob_bc[0]; - if(max != NULL) - *max = frameRate * glob_wc[0]; - if(avg != NULL) { - int i; - double ops_cnt = 0; - for(i = 1; i <= maxCounter; i++) - ops_cnt += total_wmops[i]; - *avg = (nbframe[0] == 0) ? 0 : ops_cnt / nbframe[0]; - } + if ( min != NULL ) + *min = frameRate * glob_bc[0]; + if ( max != NULL ) + *max = frameRate * glob_wc[0]; + if ( avg != NULL ) + { + int i; + double ops_cnt = 0; + for ( i = 1; i <= maxCounter; i++ ) + ops_cnt += total_wmops[i]; + *avg = ( nbframe[0] == 0 ) ? 0 : ops_cnt / nbframe[0]; + } #endif /* if WMOPS */ - UNUSED_PARAM(min); - UNUSED_PARAM(max); - UNUSED_PARAM(avg); + UNUSED_PARAM( min ); + UNUSED_PARAM( max ); + UNUSED_PARAM( avg ); } /* end of file */ diff --git a/lib_com/count.h b/lib_com/count.h index 76dfae2ed..1e5cd8408 100644 --- a/lib_com/count.h +++ b/lib_com/count.h @@ -54,18 +54,18 @@ * In the end of this file, there is a piece of code illustrating how the * functions can be used. * -******************************************************************************/ + ******************************************************************************/ #ifndef _COUNT_H #define _COUNT_H "$Id$" -/*#define WMOPS 1*/ /* <<<- enable or disable WMOPS profiling features here */ +/*#define WMOPS 1*/ /* <<<- enable or disable WMOPS profiling features here */ -#define MAXCOUNTERS (512) +#define MAXCOUNTERS ( 512 ) #define MAX_CALLERS_SAVED_FRAMES 5 /* # of Frame for which WMOPS Complexity Details will be saved, 0 = Disabled */ -int getCounterId (char *objectName); +int getCounterId( char *objectName ); /* * Create a counter group, the "objectname" will be used when printing * statistics for this counter group. @@ -74,23 +74,23 @@ int getCounterId (char *objectName); */ -int readCounterId (void); +int readCounterId( void ); /* * Returns the current CounterId. */ -void setCounter (int counterId); +void setCounter( int counterId ); /* * Defines which counter group to use, default is zero. */ -char *readCounterIdName (void); +char *readCounterIdName( void ); /* * Returns the current CounterId name. */ -void printStack(char *text, char * Id); +void printStack( char *text, char *Id ); /* * print stack * text: Any text to print initially @@ -99,7 +99,7 @@ void printStack(char *text, char * Id); * "pitch_ol" or any other function name */ -void incrementNbTimeObjectIsCalled (int counterId); +void incrementNbTimeObjectIsCalled( int counterId ); /* * This function enables to increment by 1 a counter * tracking the number of times the application enters a groups of functions. @@ -109,27 +109,26 @@ void incrementNbTimeObjectIsCalled (int counterId); */ -void ClearNbTimeObjectsAreCalled (void); +void ClearNbTimeObjectsAreCalled( void ); /* * This function enables to clear to 0 all the counters enabling to * track the number of times the application enters any groups of functions. */ -void Init_WMOPS_counter (void); +void Init_WMOPS_counter( void ); /* * Initiates the current counter group. */ - Word32 Reset_WMOPS_counter( void ); - /* +/* * Resets the current counter group. */ -void WMOPS_output (Word16 notPrintWorstWorstCase); +void WMOPS_output( Word16 notPrintWorstWorstCase ); /* * Prints the statistics to the screen, if the argument is non zero * the statistics for worst worst case will not be printed. This is typically @@ -137,7 +136,7 @@ void WMOPS_output (Word16 notPrintWorstWorstCase); * */ -void WMOPS_output_avg (Word16 dtx_mode, Word32 * tot_wm, Word32 * num_frames); +void WMOPS_output_avg( Word16 dtx_mode, Word32 *tot_wm, Word32 *num_frames ); /* * same as WMOPS_output + returns the total wmops counter and the number of frames * to support the computation of global average. @@ -145,7 +144,7 @@ void WMOPS_output_avg (Word16 dtx_mode, Word32 * tot_wm, Word32 * num_frames); */ -Word32 fwc (void); +Word32 fwc( void ); /* * worst worst case counter. * @@ -157,7 +156,7 @@ Word32 fwc (void); * The WMOPS_output function add together all parts and presents the sum. */ -void setFrameRate (int samplingFreq, int frameLength); +void setFrameRate( int samplingFreq, int frameLength ); /* * This function can overwrite the value of the frameRate variable that is * initialized by the FRAME_RATE constant. @@ -169,7 +168,7 @@ void setFrameRate (int samplingFreq, int frameLength); * WMOPS_DATA_FILENAME is the macro defining the name of the file * where the Weighted Million of Operations per Second (wMOPS) * are appended, function group by function group. -*/ + */ #define CODE_PROFILE_FILENAME "code_profile.txt" @@ -177,7 +176,7 @@ void setFrameRate (int samplingFreq, int frameLength); * CODE_PROFILE_FILENAME is the macro defining the name of the file * where the Weighted Million of Operations per Second (WMOPS) * are appended, basic operation by basic operation. -*/ + */ #define WMOPS_TOTAL_FILENAME "wmops_total.txt" @@ -185,280 +184,281 @@ void setFrameRate (int samplingFreq, int frameLength); * WMOPS_TOTAL_FILENAME is the macro defining the name of the file * where the Weighted Million of Operations per Second (WMOPS) * are printed, globally for the application. -*/ + */ -#define FRAME_RATE (0.0001F) /* in this version frame_rate can be overwriten online by the new setFrameRate function */ +#define FRAME_RATE ( 0.0001F ) /* in this version frame_rate can be overwriten online by the new setFrameRate function */ /* FRAME_RATE of 0.000025 is corresponding to 40ms frame.*/ /* FRAME_RATE of 0.00005 is corresponding to 20ms frame.*/ /* FRAME_RATE of 0.0001 is corresponding to 10ms frame.*/ /* * FRAME_RATE is the macro defining the calling rate of the * application to benchmark. -*/ + */ /* Global counter variable for calculation of complexity weight */ -typedef struct { - UWord32 add; /* Complexity Weight of 1 */ - UWord32 sub; /* Complexity Weight of 1 */ - UWord32 abs_s; /* Complexity Weight of 1 */ - UWord32 shl; /* Complexity Weight of 1 */ - UWord32 shr; /* Complexity Weight of 1 */ - - UWord32 extract_h; /* Complexity Weight of 1 */ - UWord32 extract_l; /* Complexity Weight of 1 */ - UWord32 mult; /* Complexity Weight of 1 */ - UWord32 L_mult; /* Complexity Weight of 1 */ - UWord32 negate; /* Complexity Weight of 1 */ - - UWord32 round; /* Complexity Weight of 1 */ - UWord32 L_mac; /* Complexity Weight of 1 */ - UWord32 L_msu; /* Complexity Weight of 1 */ - UWord32 L_macNs; /* Complexity Weight of 1 */ - UWord32 L_msuNs; /* Complexity Weight of 1 */ - - UWord32 L_add; /* Complexity Weight of 1 */ - UWord32 L_sub; /* Complexity Weight of 1 */ - UWord32 L_add_c; /* Complexity Weight of 2 */ - UWord32 L_sub_c; /* Complexity Weight of 2 */ - UWord32 L_negate; /* Complexity Weight of 1 */ - - UWord32 L_shl; /* Complexity Weight of 1 */ - UWord32 L_shr; /* Complexity Weight of 1 */ - UWord32 mult_r; /* Complexity Weight of 1 */ - UWord32 shr_r; /* Complexity Weight of 3 */ - UWord32 mac_r; /* Complexity Weight of 1 */ - - UWord32 msu_r; /* Complexity Weight of 1 */ - UWord32 L_deposit_h; /* Complexity Weight of 1 */ - UWord32 L_deposit_l; /* Complexity Weight of 1 */ - UWord32 L_shr_r; /* Complexity Weight of 3 */ - UWord32 L_abs; /* Complexity Weight of 1 */ - - UWord32 L_sat; /* Complexity Weight of 4 */ - UWord32 norm_s; /* Complexity Weight of 1 */ - UWord32 div_s; /* Complexity Weight of 18 */ - UWord32 norm_l; /* Complexity Weight of 1 */ - UWord32 move16; /* Complexity Weight of 1 */ - - UWord32 move32; /* Complexity Weight of 2 */ - UWord32 Logic16; /* Complexity Weight of 1 */ - UWord32 Logic32; /* Complexity Weight of 2 */ - UWord32 Test; /* Complexity Weight of 2 */ - UWord32 s_max; /* Complexity Weight of 1 */ - - UWord32 s_min; /* Complexity Weight of 1 */ - UWord32 L_max; /* Complexity Weight of 1 */ - UWord32 L_min; /* Complexity Weight of 1 */ - UWord32 L40_max; /* Complexity Weight of 1 */ - UWord32 L40_min; /* Complexity Weight of 1 */ - - UWord32 shl_r; /* Complexity Weight of 2 */ - UWord32 L_shl_r; /* Complexity Weight of 2 */ - UWord32 L40_shr_r; /* Complexity Weight of 2 */ - UWord32 L40_shl_r; /* Complexity Weight of 2 */ - UWord32 norm_L40; /* Complexity Weight of 1 */ - - UWord32 L40_shl; /* Complexity Weight of 1 */ - UWord32 L40_shr; /* Complexity Weight of 1 */ - UWord32 L40_negate; /* Complexity Weight of 1 */ - UWord32 L40_add; /* Complexity Weight of 1 */ - UWord32 L40_sub; /* Complexity Weight of 1 */ - - UWord32 L40_abs; /* Complexity Weight of 1 */ - UWord32 L40_mult; /* Complexity Weight of 1 */ - UWord32 L40_mac; /* Complexity Weight of 1 */ - UWord32 mac_r40; /* Complexity Weight of 2 */ - - UWord32 L40_msu; /* Complexity Weight of 1 */ - UWord32 msu_r40; /* Complexity Weight of 2 */ - UWord32 Mpy_32_16_ss; /* Complexity Weight of 2 */ - UWord32 Mpy_32_32_ss; /* Complexity Weight of 2 */ - UWord32 L_mult0; /* Complexity Weight of 1 */ - - UWord32 L_mac0; /* Complexity Weight of 1 */ - UWord32 L_msu0; /* Complexity Weight of 1 */ - UWord32 lshl; /* Complexity Weight of 1 */ - UWord32 lshr; /* Complexity Weight of 1 */ - UWord32 L_lshl; /* Complexity Weight of 1 */ - - UWord32 L_lshr; /* Complexity Weight of 1 */ - UWord32 L40_lshl; /* Complexity Weight of 1 */ - UWord32 L40_lshr; /* Complexity Weight of 1 */ - UWord32 s_and; /* Complexity Weight of 1 */ - UWord32 s_or; /* Complexity Weight of 1 */ - - UWord32 s_xor; /* Complexity Weight of 1 */ - UWord32 L_and; /* Complexity Weight of 1 */ - UWord32 L_or; /* Complexity Weight of 1 */ - UWord32 L_xor; /* Complexity Weight of 1 */ - UWord32 rotl; /* Complexity Weight of 3 */ - - UWord32 rotr; /* Complexity Weight of 3 */ - UWord32 L_rotl; /* Complexity Weight of 3 */ - UWord32 L_rotr; /* Complexity Weight of 3 */ - UWord32 L40_set; /* Complexity Weight of 1 */ - UWord32 L40_deposit_h; /* Complexity Weight of 1 */ - - UWord32 L40_deposit_l; /* Complexity Weight of 1 */ - UWord32 L40_deposit32; /* Complexity Weight of 1 */ - UWord32 Extract40_H; /* Complexity Weight of 1 */ - UWord32 Extract40_L; /* Complexity Weight of 1 */ - UWord32 L_Extract40; /* Complexity Weight of 1 */ - - UWord32 L40_round; /* Complexity Weight of 1 */ - UWord32 L_saturate40; /* Complexity Weight of 1 */ - UWord32 round40; /* Complexity Weight of 1 */ - UWord32 If; /* Complexity Weight of 3 */ - UWord32 Goto; /* Complexity Weight of 2 */ - - UWord32 Break; /* Complexity Weight of 2 */ - UWord32 Switch; /* Complexity Weight of 6 */ - UWord32 For; /* Complexity Weight of 3 */ - UWord32 While; /* Complexity Weight of 3 */ - UWord32 Continue; /* Complexity Weight of 2 */ - - UWord32 L_mls; /* Complexity Weight of 1 */ - UWord32 div_l; /* Complexity Weight of 32 */ - UWord32 i_mult; /* Complexity Weight of 1 */ +typedef struct +{ + UWord32 add; /* Complexity Weight of 1 */ + UWord32 sub; /* Complexity Weight of 1 */ + UWord32 abs_s; /* Complexity Weight of 1 */ + UWord32 shl; /* Complexity Weight of 1 */ + UWord32 shr; /* Complexity Weight of 1 */ + + UWord32 extract_h; /* Complexity Weight of 1 */ + UWord32 extract_l; /* Complexity Weight of 1 */ + UWord32 mult; /* Complexity Weight of 1 */ + UWord32 L_mult; /* Complexity Weight of 1 */ + UWord32 negate; /* Complexity Weight of 1 */ + + UWord32 round; /* Complexity Weight of 1 */ + UWord32 L_mac; /* Complexity Weight of 1 */ + UWord32 L_msu; /* Complexity Weight of 1 */ + UWord32 L_macNs; /* Complexity Weight of 1 */ + UWord32 L_msuNs; /* Complexity Weight of 1 */ + + UWord32 L_add; /* Complexity Weight of 1 */ + UWord32 L_sub; /* Complexity Weight of 1 */ + UWord32 L_add_c; /* Complexity Weight of 2 */ + UWord32 L_sub_c; /* Complexity Weight of 2 */ + UWord32 L_negate; /* Complexity Weight of 1 */ + + UWord32 L_shl; /* Complexity Weight of 1 */ + UWord32 L_shr; /* Complexity Weight of 1 */ + UWord32 mult_r; /* Complexity Weight of 1 */ + UWord32 shr_r; /* Complexity Weight of 3 */ + UWord32 mac_r; /* Complexity Weight of 1 */ + + UWord32 msu_r; /* Complexity Weight of 1 */ + UWord32 L_deposit_h; /* Complexity Weight of 1 */ + UWord32 L_deposit_l; /* Complexity Weight of 1 */ + UWord32 L_shr_r; /* Complexity Weight of 3 */ + UWord32 L_abs; /* Complexity Weight of 1 */ + + UWord32 L_sat; /* Complexity Weight of 4 */ + UWord32 norm_s; /* Complexity Weight of 1 */ + UWord32 div_s; /* Complexity Weight of 18 */ + UWord32 norm_l; /* Complexity Weight of 1 */ + UWord32 move16; /* Complexity Weight of 1 */ + + UWord32 move32; /* Complexity Weight of 2 */ + UWord32 Logic16; /* Complexity Weight of 1 */ + UWord32 Logic32; /* Complexity Weight of 2 */ + UWord32 Test; /* Complexity Weight of 2 */ + UWord32 s_max; /* Complexity Weight of 1 */ + + UWord32 s_min; /* Complexity Weight of 1 */ + UWord32 L_max; /* Complexity Weight of 1 */ + UWord32 L_min; /* Complexity Weight of 1 */ + UWord32 L40_max; /* Complexity Weight of 1 */ + UWord32 L40_min; /* Complexity Weight of 1 */ + + UWord32 shl_r; /* Complexity Weight of 2 */ + UWord32 L_shl_r; /* Complexity Weight of 2 */ + UWord32 L40_shr_r; /* Complexity Weight of 2 */ + UWord32 L40_shl_r; /* Complexity Weight of 2 */ + UWord32 norm_L40; /* Complexity Weight of 1 */ + + UWord32 L40_shl; /* Complexity Weight of 1 */ + UWord32 L40_shr; /* Complexity Weight of 1 */ + UWord32 L40_negate; /* Complexity Weight of 1 */ + UWord32 L40_add; /* Complexity Weight of 1 */ + UWord32 L40_sub; /* Complexity Weight of 1 */ + + UWord32 L40_abs; /* Complexity Weight of 1 */ + UWord32 L40_mult; /* Complexity Weight of 1 */ + UWord32 L40_mac; /* Complexity Weight of 1 */ + UWord32 mac_r40; /* Complexity Weight of 2 */ + + UWord32 L40_msu; /* Complexity Weight of 1 */ + UWord32 msu_r40; /* Complexity Weight of 2 */ + UWord32 Mpy_32_16_ss; /* Complexity Weight of 2 */ + UWord32 Mpy_32_32_ss; /* Complexity Weight of 2 */ + UWord32 L_mult0; /* Complexity Weight of 1 */ + + UWord32 L_mac0; /* Complexity Weight of 1 */ + UWord32 L_msu0; /* Complexity Weight of 1 */ + UWord32 lshl; /* Complexity Weight of 1 */ + UWord32 lshr; /* Complexity Weight of 1 */ + UWord32 L_lshl; /* Complexity Weight of 1 */ + + UWord32 L_lshr; /* Complexity Weight of 1 */ + UWord32 L40_lshl; /* Complexity Weight of 1 */ + UWord32 L40_lshr; /* Complexity Weight of 1 */ + UWord32 s_and; /* Complexity Weight of 1 */ + UWord32 s_or; /* Complexity Weight of 1 */ + + UWord32 s_xor; /* Complexity Weight of 1 */ + UWord32 L_and; /* Complexity Weight of 1 */ + UWord32 L_or; /* Complexity Weight of 1 */ + UWord32 L_xor; /* Complexity Weight of 1 */ + UWord32 rotl; /* Complexity Weight of 3 */ + + UWord32 rotr; /* Complexity Weight of 3 */ + UWord32 L_rotl; /* Complexity Weight of 3 */ + UWord32 L_rotr; /* Complexity Weight of 3 */ + UWord32 L40_set; /* Complexity Weight of 1 */ + UWord32 L40_deposit_h; /* Complexity Weight of 1 */ + + UWord32 L40_deposit_l; /* Complexity Weight of 1 */ + UWord32 L40_deposit32; /* Complexity Weight of 1 */ + UWord32 Extract40_H; /* Complexity Weight of 1 */ + UWord32 Extract40_L; /* Complexity Weight of 1 */ + UWord32 L_Extract40; /* Complexity Weight of 1 */ + + UWord32 L40_round; /* Complexity Weight of 1 */ + UWord32 L_saturate40; /* Complexity Weight of 1 */ + UWord32 round40; /* Complexity Weight of 1 */ + UWord32 If; /* Complexity Weight of 3 */ + UWord32 Goto; /* Complexity Weight of 2 */ + + UWord32 Break; /* Complexity Weight of 2 */ + UWord32 Switch; /* Complexity Weight of 6 */ + UWord32 For; /* Complexity Weight of 3 */ + UWord32 While; /* Complexity Weight of 3 */ + UWord32 Continue; /* Complexity Weight of 2 */ + + UWord32 L_mls; /* Complexity Weight of 1 */ + UWord32 div_l; /* Complexity Weight of 32 */ + UWord32 i_mult; /* Complexity Weight of 1 */ /* New complex basic operators */ #ifdef COMPLEX_OPERATOR - UWord32 CL_shr; /* Complexity Weight of 1 */ - UWord32 CL_shl; /* Complexity Weight of 1 */ - UWord32 CL_add; /* Complexity Weight of 1 */ - UWord32 CL_sub; /* Complexity Weight of 1 */ - UWord32 CL_scale; /* Complexity Weight of 1 */ - UWord32 CL_dscale; /* Complexity Weight of 1 */ - UWord32 CL_msu_j; /* Complexity Weight of 1 */ - UWord32 CL_mac_j; /* Complexity Weight of 1 */ - UWord32 CL_move; /* Complexity Weight of 1 */ - UWord32 CL_Extract_real; /* Complexity Weight of 1 */ - UWord32 CL_Extract_imag; /* Complexity Weight of 1 */ - UWord32 CL_form; /* Complexity Weight of 1 */ - UWord32 CL_multr_32x16; /* Complexity Weight of 2 */ - UWord32 CL_negate; /* Complexity Weight of 1 */ - UWord32 CL_conjugate; /* Complexity Weight of 1 */ - UWord32 CL_mul_j; /* Complexity Weight of 1 */ - UWord32 CL_swap_real_imag; /* Complexity Weight of 1 */ - UWord32 C_add; /* Complexity Weight of 1 */ - UWord32 C_sub; /* Complexity Weight of 1 */ - UWord32 C_mul_j; /* Complexity Weight of 1 */ - UWord32 C_multr; /* Complexity Weight of 2 */ - UWord32 C_form; /* Complexity Weight of 1 */ - - UWord32 C_scale; /* Complexity Weight of 1 */ - UWord32 CL_round32_16; /* Complexity Weight of 1 */ - UWord32 CL_scale_32; /* Complexity Weight of 1 */ - UWord32 CL_dscale_32; /* Complexity Weight of 1 */ - UWord32 CL_multr_32x32; /* Complexity Weight of 2 */ - UWord32 C_mac_r; /* Complexity Weight of 2 */ - UWord32 C_msu_r; /* Complexity Weight of 2 */ - UWord32 C_Extract_real; /* Complexity Weight of 1 */ - UWord32 C_Extract_imag; /* Complexity Weight of 1 */ - UWord32 C_negate; /* Complexity Weight of 1 */ - UWord32 C_conjugate; /* Complexity Weight of 1 */ - UWord32 C_shr; /* Complexity Weight of 1 */ - UWord32 C_shl; /* Complexity Weight of 1 */ + UWord32 CL_shr; /* Complexity Weight of 1 */ + UWord32 CL_shl; /* Complexity Weight of 1 */ + UWord32 CL_add; /* Complexity Weight of 1 */ + UWord32 CL_sub; /* Complexity Weight of 1 */ + UWord32 CL_scale; /* Complexity Weight of 1 */ + UWord32 CL_dscale; /* Complexity Weight of 1 */ + UWord32 CL_msu_j; /* Complexity Weight of 1 */ + UWord32 CL_mac_j; /* Complexity Weight of 1 */ + UWord32 CL_move; /* Complexity Weight of 1 */ + UWord32 CL_Extract_real; /* Complexity Weight of 1 */ + UWord32 CL_Extract_imag; /* Complexity Weight of 1 */ + UWord32 CL_form; /* Complexity Weight of 1 */ + UWord32 CL_multr_32x16; /* Complexity Weight of 2 */ + UWord32 CL_negate; /* Complexity Weight of 1 */ + UWord32 CL_conjugate; /* Complexity Weight of 1 */ + UWord32 CL_mul_j; /* Complexity Weight of 1 */ + UWord32 CL_swap_real_imag; /* Complexity Weight of 1 */ + UWord32 C_add; /* Complexity Weight of 1 */ + UWord32 C_sub; /* Complexity Weight of 1 */ + UWord32 C_mul_j; /* Complexity Weight of 1 */ + UWord32 C_multr; /* Complexity Weight of 2 */ + UWord32 C_form; /* Complexity Weight of 1 */ + + UWord32 C_scale; /* Complexity Weight of 1 */ + UWord32 CL_round32_16; /* Complexity Weight of 1 */ + UWord32 CL_scale_32; /* Complexity Weight of 1 */ + UWord32 CL_dscale_32; /* Complexity Weight of 1 */ + UWord32 CL_multr_32x32; /* Complexity Weight of 2 */ + UWord32 C_mac_r; /* Complexity Weight of 2 */ + UWord32 C_msu_r; /* Complexity Weight of 2 */ + UWord32 C_Extract_real; /* Complexity Weight of 1 */ + UWord32 C_Extract_imag; /* Complexity Weight of 1 */ + UWord32 C_negate; /* Complexity Weight of 1 */ + UWord32 C_conjugate; /* Complexity Weight of 1 */ + UWord32 C_shr; /* Complexity Weight of 1 */ + UWord32 C_shl; /* Complexity Weight of 1 */ #endif /* #ifdef COMPLEX_OPERATOR */ /* New 64 bit basops */ #ifdef ENH_64_BIT_OPERATOR - UWord32 move64; /* Complexity Weight of 1 */ - UWord32 W_add_nosat; /* Complexity Weight of 1 */ - UWord32 W_sub_nosat; /* Complexity Weight of 1 */ - UWord32 W_shl; /* Complexity Weight of 1 */ - UWord32 W_shr; /* Complexity Weight of 1 */ - UWord32 W_shl_nosat; /* Complexity Weight of 1 */ - UWord32 W_shr_nosat; /* Complexity Weight of 1 */ - UWord32 W_mac_32_16; /* Complexity Weight of 1 */ - UWord32 W_msu_32_16; /* Complexity Weight of 1 */ - UWord32 W_mult_32_16; /* Complexity Weight of 1 */ - UWord32 W_mult0_16_16; /* Complexity Weight of 1 */ - UWord32 W_mac0_16_16; /* Complexity Weight of 1 */ - UWord32 W_msu0_16_16; /* Complexity Weight of 1 */ - UWord32 W_mult_16_16; /* Complexity Weight of 1 */ - UWord32 W_mac_16_16; /* Complexity Weight of 1 */ - UWord32 W_msu_16_16; /* Complexity Weight of 1 */ - UWord32 W_shl_sat_l; /* Complexity Weight of 1 */ - UWord32 W_sat_l; /* Complexity Weight of 1 */ - UWord32 W_sat_m; /* Complexity Weight of 1 */ - UWord32 W_deposit32_l; /* Complexity Weight of 1 */ - UWord32 W_deposit32_h; /* Complexity Weight of 1 */ - UWord32 W_extract_l; /* Complexity Weight of 1 */ - UWord32 W_extract_h; /* Complexity Weight of 1 */ - UWord32 W_round48_L; /* Complexity Weight of 1 */ - UWord32 W_round32_s; /* Complexity Weight of 1 */ - UWord32 W_norm; /* Complexity Weight of 1 */ - - UWord32 W_add; /* Complexity Weight of 1 */ - UWord32 W_sub; /* Complexity Weight of 1 */ - UWord32 W_neg; /* Complexity Weight of 1 */ - UWord32 W_abs; /* Complexity Weight of 1 */ - UWord32 W_mult_32_32; /* Complexity Weight of 1 */ - UWord32 W_mult0_32_32; /* Complexity Weight of 1 */ - UWord32 W_lshl; /* Complexity Weight of 1 */ - UWord32 W_lshr; /* Complexity Weight of 1 */ - UWord32 W_round64_L; /* Complexity Weight of 1 */ + UWord32 move64; /* Complexity Weight of 1 */ + UWord32 W_add_nosat; /* Complexity Weight of 1 */ + UWord32 W_sub_nosat; /* Complexity Weight of 1 */ + UWord32 W_shl; /* Complexity Weight of 1 */ + UWord32 W_shr; /* Complexity Weight of 1 */ + UWord32 W_shl_nosat; /* Complexity Weight of 1 */ + UWord32 W_shr_nosat; /* Complexity Weight of 1 */ + UWord32 W_mac_32_16; /* Complexity Weight of 1 */ + UWord32 W_msu_32_16; /* Complexity Weight of 1 */ + UWord32 W_mult_32_16; /* Complexity Weight of 1 */ + UWord32 W_mult0_16_16; /* Complexity Weight of 1 */ + UWord32 W_mac0_16_16; /* Complexity Weight of 1 */ + UWord32 W_msu0_16_16; /* Complexity Weight of 1 */ + UWord32 W_mult_16_16; /* Complexity Weight of 1 */ + UWord32 W_mac_16_16; /* Complexity Weight of 1 */ + UWord32 W_msu_16_16; /* Complexity Weight of 1 */ + UWord32 W_shl_sat_l; /* Complexity Weight of 1 */ + UWord32 W_sat_l; /* Complexity Weight of 1 */ + UWord32 W_sat_m; /* Complexity Weight of 1 */ + UWord32 W_deposit32_l; /* Complexity Weight of 1 */ + UWord32 W_deposit32_h; /* Complexity Weight of 1 */ + UWord32 W_extract_l; /* Complexity Weight of 1 */ + UWord32 W_extract_h; /* Complexity Weight of 1 */ + UWord32 W_round48_L; /* Complexity Weight of 1 */ + UWord32 W_round32_s; /* Complexity Weight of 1 */ + UWord32 W_norm; /* Complexity Weight of 1 */ + + UWord32 W_add; /* Complexity Weight of 1 */ + UWord32 W_sub; /* Complexity Weight of 1 */ + UWord32 W_neg; /* Complexity Weight of 1 */ + UWord32 W_abs; /* Complexity Weight of 1 */ + UWord32 W_mult_32_32; /* Complexity Weight of 1 */ + UWord32 W_mult0_32_32; /* Complexity Weight of 1 */ + UWord32 W_lshl; /* Complexity Weight of 1 */ + UWord32 W_lshr; /* Complexity Weight of 1 */ + UWord32 W_round64_L; /* Complexity Weight of 1 */ #endif /* #ifdef ENH_64_BIT_OPERATOR */ #ifdef ENH_32_BIT_OPERATOR - UWord32 Mpy_32_16_1; /* Complexity Weight of 1 */ - UWord32 Mpy_32_16_r; /* Complexity Weight of 1 */ - UWord32 Mpy_32_32; /* Complexity Weight of 1 */ - UWord32 Mpy_32_32_r; /* Complexity Weight of 1 */ - UWord32 Madd_32_16; /* Complexity Weight of 1 */ - UWord32 Madd_32_16_r; /* Complexity Weight of 1 */ - UWord32 Msub_32_16; /* Complexity Weight of 1 */ - UWord32 Msub_32_16_r; /* Complexity Weight of 1 */ - UWord32 Madd_32_32; /* Complexity Weight of 1 */ - UWord32 Madd_32_32_r; /* Complexity Weight of 1 */ - UWord32 Msub_32_32; /* Complexity Weight of 1 */ - UWord32 Msub_32_32_r; /* Complexity Weight of 1 */ -#endif /* #ifdef ENH_32_BIT_OPERATOR */ + UWord32 Mpy_32_16_1; /* Complexity Weight of 1 */ + UWord32 Mpy_32_16_r; /* Complexity Weight of 1 */ + UWord32 Mpy_32_32; /* Complexity Weight of 1 */ + UWord32 Mpy_32_32_r; /* Complexity Weight of 1 */ + UWord32 Madd_32_16; /* Complexity Weight of 1 */ + UWord32 Madd_32_16_r; /* Complexity Weight of 1 */ + UWord32 Msub_32_16; /* Complexity Weight of 1 */ + UWord32 Msub_32_16_r; /* Complexity Weight of 1 */ + UWord32 Madd_32_32; /* Complexity Weight of 1 */ + UWord32 Madd_32_32_r; /* Complexity Weight of 1 */ + UWord32 Msub_32_32; /* Complexity Weight of 1 */ + UWord32 Msub_32_32_r; /* Complexity Weight of 1 */ +#endif /* #ifdef ENH_32_BIT_OPERATOR */ #ifdef ENH_U_32_BIT_OPERATOR - UWord32 UL_addNs; /* Complexity Weight of 1 */ - UWord32 UL_subNs; /* Complexity Weight of 1 */ - UWord32 UL_Mpy_32_32; /* Complexity Weight of 1 */ - UWord32 Mpy_32_32_uu; /* Complexity Weight of 2 */ - UWord32 Mpy_32_16_uu; /* Complexity Weight of 2 */ - UWord32 norm_ul_float; /* Complexity Weight of 1 */ - UWord32 UL_deposit_l; /* Complexity Weight of 1 */ -#endif /* #ifdef ENH_U_32_BIT_OPERATOR */ + UWord32 UL_addNs; /* Complexity Weight of 1 */ + UWord32 UL_subNs; /* Complexity Weight of 1 */ + UWord32 UL_Mpy_32_32; /* Complexity Weight of 1 */ + UWord32 Mpy_32_32_uu; /* Complexity Weight of 2 */ + UWord32 Mpy_32_16_uu; /* Complexity Weight of 2 */ + UWord32 norm_ul_float; /* Complexity Weight of 1 */ + UWord32 UL_deposit_l; /* Complexity Weight of 1 */ +#endif /* #ifdef ENH_U_32_BIT_OPERATOR */ #ifdef CONTROL_CODE_OPS - UWord32 LT_16; /* Complexity Weight of 1 */ - UWord32 GT_16; /* Complexity Weight of 1 */ - UWord32 LE_16; /* Complexity Weight of 1 */ - UWord32 GE_16; /* Complexity Weight of 1 */ - UWord32 EQ_16; /* Complexity Weight of 1 */ - UWord32 NE_16; /* Complexity Weight of 1 */ - UWord32 LT_32; /* Complexity Weight of 1 */ - UWord32 GT_32; /* Complexity Weight of 1 */ - UWord32 LE_32; /* Complexity Weight of 1 */ - UWord32 GE_32; /* Complexity Weight of 1 */ - UWord32 EQ_32; /* Complexity Weight of 1 */ - UWord32 NE_32; /* Complexity Weight of 1 */ - UWord32 LT_64; /* Complexity Weight of 1 */ - UWord32 GT_64; /* Complexity Weight of 1 */ - UWord32 LE_64; /* Complexity Weight of 1 */ - UWord32 GE_64; /* Complexity Weight of 1 */ - UWord32 EQ_64; /* Complexity Weight of 1 */ - UWord32 NE_64; /* Complexity Weight of 1 */ - + UWord32 LT_16; /* Complexity Weight of 1 */ + UWord32 GT_16; /* Complexity Weight of 1 */ + UWord32 LE_16; /* Complexity Weight of 1 */ + UWord32 GE_16; /* Complexity Weight of 1 */ + UWord32 EQ_16; /* Complexity Weight of 1 */ + UWord32 NE_16; /* Complexity Weight of 1 */ + UWord32 LT_32; /* Complexity Weight of 1 */ + UWord32 GT_32; /* Complexity Weight of 1 */ + UWord32 LE_32; /* Complexity Weight of 1 */ + UWord32 GE_32; /* Complexity Weight of 1 */ + UWord32 EQ_32; /* Complexity Weight of 1 */ + UWord32 NE_32; /* Complexity Weight of 1 */ + UWord32 LT_64; /* Complexity Weight of 1 */ + UWord32 GT_64; /* Complexity Weight of 1 */ + UWord32 LE_64; /* Complexity Weight of 1 */ + UWord32 GE_64; /* Complexity Weight of 1 */ + UWord32 EQ_64; /* Complexity Weight of 1 */ + UWord32 NE_64; /* Complexity Weight of 1 */ + #endif /* #ifdef CONTROL_CODE_OPS */ } BASIC_OP; -Word32 TotalWeightedOperation (void); -Word32 DeltaWeightedOperation (void); +Word32 TotalWeightedOperation( void ); +Word32 DeltaWeightedOperation( void ); -void generic_WMOPS_output (Word16 notPrintWorstWorstCase, char *test_file_name); +void generic_WMOPS_output( Word16 notPrintWorstWorstCase, char *test_file_name ); /* * This function enable to append : * - to WMOPS_DATA_FILENAME file, the WMOPS information related @@ -479,13 +479,13 @@ void generic_WMOPS_output (Word16 notPrintWorstWorstCase, char *test_file_name); * * notPrintWorstWorstCase : Same usage as in WMOPS_output(). */ -void WMOPS_output_all(Word16 dtx_mode); -void WMOPS_output_all_std(Word16 dtx_mode); +void WMOPS_output_all( Word16 dtx_mode ); +void WMOPS_output_all_std( Word16 dtx_mode ); /* - * free all allocated counter memory + * free all allocated counter memory */ -void WMOPS_destroy(void); +void WMOPS_destroy( void ); #if 0 /* * Example of how count.h could be used. @@ -538,32 +538,48 @@ int main () { #endif /* #if 0 */ /* jdr 20120117: add FLC similar functions */ -/* mul 20130729: set BASOP_COUNT_SUBROUTINES to count on a per-BASOP_sub_start()/BASOP_sub_end() base; +/* mul 20130729: set BASOP_COUNT_SUBROUTINES to count on a per-BASOP_sub_start()/BASOP_sub_end() base; otherwise, count only between BASOP_push_wmops(), BASOP_push_wmops() */ #define BASOP_COUNT_SUBROUTINES -void BASOP_push_wmops (const char *label); -Word32 BASOP_pop_wmops (void); - -#define BASOP_init { setFrameRate(32000, 640); Init_WMOPS_counter(); /* 20ms frames */ } -#define BASOP_end { WMOPS_output_all_std(0); } +void BASOP_push_wmops( const char *label ); +Word32 BASOP_pop_wmops( void ); + +#define BASOP_init \ + { \ + setFrameRate( 32000, 640 ); \ + Init_WMOPS_counter(); /* 20ms frames */ \ + } +#define BASOP_end \ + { \ + WMOPS_output_all_std( 0 ); \ + } /*#define BASOP_end { WMOPS_output_all(0); }*/ -#define BASOP_end_noprint { WMOPS_destroy(); } +#define BASOP_end_noprint \ + { \ + WMOPS_destroy(); \ + } #ifdef BASOP_COUNT_SUBROUTINES -#define BASOP_sub_start(label) { BASOP_push_wmops(label); } -#define BASOP_sub_end() { BASOP_pop_wmops(); } +#define BASOP_sub_start( label ) \ + { \ + BASOP_push_wmops( label ); \ + } +#define BASOP_sub_end() \ + { \ + BASOP_pop_wmops(); \ + } #else -#define BASOP_sub_start(label) -#define BASOP_sub_end() +#define BASOP_sub_start( label ) +#define BASOP_sub_end() #endif -void BASOP_frame_update(void); -void Reset_all_WMOPS_counter (void); +void BASOP_frame_update( void ); +void Reset_all_WMOPS_counter( void ); -Word32 BASOP_get_wops (void); +Word32 BASOP_get_wops( void ); /*! Returns the total min/max/avg WMOPS values like printed in BASOP_end(). */ -void BASOP_get_total_wmops(double *min, double *max, double *avg); +void BASOP_get_total_wmops( double *min, double *max, double *avg ); #define SUB_WMOPS_INIT( label ) BASOP_sub_start( label ) @@ -573,12 +589,24 @@ void BASOP_get_total_wmops(double *min, double *max, double *avg); #if !defined WMOPS_FL //&& defined WMOPS #include #define reset_wmops() BASOP_init -//extern int cntr_push_pop; -#define push_wmops( x ) { BASOP_push_wmops(x); } -#define pop_wmops() { BASOP_pop_wmops(); } -#define update_wmops() { BASOP_frame_update(); } -#define print_wmops() { WMOPS_output_all_std(0); } -#define update_mem(); +// extern int cntr_push_pop; +#define push_wmops( x ) \ + { \ + BASOP_push_wmops( x ); \ + } +#define pop_wmops() \ + { \ + BASOP_pop_wmops(); \ + } +#define update_wmops() \ + { \ + BASOP_frame_update(); \ + } +#define print_wmops() \ + { \ + WMOPS_output_all_std( 0 ); \ + } +#define update_mem() ; #endif diff --git a/lib_com/deemph.c b/lib_com/deemph.c index c5fa5da62..a746d326e 100644 --- a/lib_com/deemph.c +++ b/lib_com/deemph.c @@ -81,21 +81,20 @@ void deemph_fx_32( { int16_t i; - signal[0] = L_add(signal[0] , Mpy_32_16_1( ( *mem ), mu )); - FOR ( i = 1; i < L; i++ ) + signal[0] = L_add( signal[0], Mpy_32_16_1( ( *mem ), mu ) ); + FOR( i = 1; i < L; i++ ) { - signal[i] = L_add(signal[i] , Mpy_32_16_1( signal[i - 1], mu )); - signal[i] = L_shl(signal[i], shift); + signal[i] = L_add( signal[i], Mpy_32_16_1( signal[i - 1], mu ) ); + signal[i] = L_shl( signal[i], shift ); } *mem = signal[L - 1]; - move32(); + move32(); return; } - /*========================================================================*/ /* FUNCTION : deemph_fx() */ /*------------------------------------------------------------------------*/ @@ -117,41 +116,41 @@ void deemph_fx_32( /* _ None */ /*========================================================================*/ void deemph_fx( - Word16 *signal, /* i/o: signal Qx */ - const Word16 mu, /* i : deemphasis factor Q15 */ - const Word16 L, /* i : vector size Q0 */ - Word16 *mem /* i/o: memory (y[-1]) Qx */ + Word16 *signal, /* i/o: signal Qx */ + const Word16 mu, /* i : deemphasis factor Q15 */ + const Word16 L, /* i : vector size Q0 */ + Word16 *mem /* i/o: memory (y[-1]) Qx */ ) { - Word16 i; - Word32 L_tmp; + Word16 i; + Word32 L_tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; + Flag Overflow = 0; #endif - L_tmp = L_deposit_h(signal[0]); + L_tmp = L_deposit_h( signal[0] ); #ifdef BASOP_NOGLOB - L_tmp = L_mac_o(L_tmp, *mem, mu, &Overflow); - signal[0] = round_fx_o(L_tmp, &Overflow); + L_tmp = L_mac_o( L_tmp, *mem, mu, &Overflow ); + signal[0] = round_fx_o( L_tmp, &Overflow ); #else - L_tmp = L_mac(L_tmp, *mem, mu); - signal[0] = round_fx(L_tmp); + L_tmp = L_mac( L_tmp, *mem, mu ); + signal[0] = round_fx( L_tmp ); #endif - FOR(i = 1; i < L; i++) - { - L_tmp = L_deposit_h(signal[i]); + FOR( i = 1; i < L; i++ ) + { + L_tmp = L_deposit_h( signal[i] ); #ifdef BASOP_NOGLOB - L_tmp = L_mac_o(L_tmp, signal[i - 1], mu, &Overflow); - signal[i] = round_fx_o(L_tmp, &Overflow); -#else /* BASOP_NOGLOB */ - L_tmp = L_mac(L_tmp, signal[i - 1], mu); - signal[i] = round_fx(L_tmp); + L_tmp = L_mac_o( L_tmp, signal[i - 1], mu, &Overflow ); + signal[i] = round_fx_o( L_tmp, &Overflow ); +#else /* BASOP_NOGLOB */ + L_tmp = L_mac( L_tmp, signal[i - 1], mu ); + signal[i] = round_fx( L_tmp ); #endif /* BASOP_NOGLOB */ - } + } - *mem = signal[L - 1]; - move16(); + *mem = signal[L - 1]; + move16(); } /*-------------------------------------------------------------------* @@ -161,36 +160,36 @@ void deemph_fx( * Output divided by 2 *-------------------------------------------------------------------*/ void Deemph2( - Word16 x[], /* i/o: input signal overwritten by the output Qx/Qx-1 */ - const Word16 mu, /* i : deemphasis factor Q15 */ - const Word16 L, /* i : vector size Q0 */ - Word16 *mem /* i/o: memory (y[-1]) Qx-1 */ + Word16 x[], /* i/o: input signal overwritten by the output Qx/Qx-1 */ + const Word16 mu, /* i : deemphasis factor Q15 */ + const Word16 L, /* i : vector size Q0 */ + Word16 *mem /* i/o: memory (y[-1]) Qx-1 */ ) { - Word16 i; - Word32 L_tmp; + Word16 i; + Word32 L_tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; + Flag Overflow = 0; #endif - /* saturation can occur in L_mac() */ + /* saturation can occur in L_mac() */ - L_tmp = L_mult(x[0], 16384); - x[0] = mac_r(L_tmp, *mem, mu); - move16(); + L_tmp = L_mult( x[0], 16384 ); + x[0] = mac_r( L_tmp, *mem, mu ); + move16(); - FOR(i = 1; i < L; i++) - { - L_tmp = L_mult(x[i], 16384); + FOR( i = 1; i < L; i++ ) + { + L_tmp = L_mult( x[i], 16384 ); #ifdef BASOP_NOGLOB - x[i] = mac_ro(L_tmp, x[i - 1], mu, &Overflow); + x[i] = mac_ro( L_tmp, x[i - 1], mu, &Overflow ); #else - x[i] = mac_r(L_tmp, x[i - 1], mu); + x[i] = mac_r( L_tmp, x[i - 1], mu ); #endif - move16(); - } + move16(); + } - *mem = x[L - 1]; - move16(); + *mem = x[L - 1]; + move16(); } @@ -211,47 +210,46 @@ void Deemph2( * Returns: * void */ -void E_UTIL_deemph2(Word16 shift, Word16 *x, const Word16 mu, const Word16 L, Word16 *mem) +void E_UTIL_deemph2( Word16 shift, Word16 *x, const Word16 mu, const Word16 L, Word16 *mem ) { - Word16 i; - Word32 L_tmp; + Word16 i; + Word32 L_tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; + Flag Overflow = 0; #endif - /* signal[0] = signal[0] + mu * (*mem); */ - L_tmp = L_deposit_h(*mem); - IF(shift >= 0) - { - shift = shr(-32768, shift); - FOR(i = 0; i < L; i++) + /* signal[0] = signal[0] + mu * (*mem); */ + L_tmp = L_deposit_h( *mem ); + IF( shift >= 0 ) { + shift = shr( -32768, shift ); + FOR( i = 0; i < L; i++ ) + { #ifdef BASOP_NOGLOB - L_tmp = L_msu_o(Mpy_32_16_1(L_tmp, mu), x[i], shift, &Overflow); - x[i] = round_fx_o(L_tmp, &Overflow); + L_tmp = L_msu_o( Mpy_32_16_1( L_tmp, mu ), x[i], shift, &Overflow ); + x[i] = round_fx_o( L_tmp, &Overflow ); #else - L_tmp = L_msu(Mpy_32_16_1(L_tmp, mu), x[i], shift); - x[i] = round_fx(L_tmp); + L_tmp = L_msu( Mpy_32_16_1( L_tmp, mu ), x[i], shift ); + x[i] = round_fx( L_tmp ); #endif + } } - - } - ELSE - { - FOR(i = 0; i < L; i++) - { + ELSE + { + FOR( i = 0; i < L; i++ ) + { #ifdef BASOP_NOGLOB - L_tmp = L_msu_o(Mpy_32_16_1(L_tmp, mu), shr_o(x[i],shift, &Overflow),-32768, &Overflow); - x[i] = round_fx_o(L_tmp, &Overflow); + L_tmp = L_msu_o( Mpy_32_16_1( L_tmp, mu ), shr_o( x[i], shift, &Overflow ), -32768, &Overflow ); + x[i] = round_fx_o( L_tmp, &Overflow ); #else /* BASOP_NOGLOB */ - L_tmp = L_msu(Mpy_32_16_1(L_tmp, mu), shr(x[i],shift),-32768); - x[i] = round_fx(L_tmp); + L_tmp = L_msu( Mpy_32_16_1( L_tmp, mu ), shr( x[i], shift ), -32768 ); + x[i] = round_fx( L_tmp ); #endif } - } + } - *mem = x[L - 1]; - move16(); + *mem = x[L - 1]; + move16(); - return; + return; } diff --git a/lib_com/delay_comp.c b/lib_com/delay_comp.c index c9b806951..9174efd31 100644 --- a/lib_com/delay_comp.c +++ b/lib_com/delay_comp.c @@ -50,9 +50,9 @@ /*! r: delay value in ns */ int32_t get_delay( - const int16_t enc_dec, /* i : encoder/decoder flag */ - const int32_t io_fs, /* i : input/output sampling frequency */ - const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const int16_t enc_dec, /* i : encoder/decoder flag */ + const int32_t io_fs, /* i : input/output sampling frequency */ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ HANDLE_CLDFB_FILTER_BANK hCldfb /* i : Handle of Cldfb analysis */ ) { @@ -96,11 +96,11 @@ int32_t get_delay( { delay = IVAS_DEC_DELAY_NS; - if ( hCldfb != NULL ) - { - /* compensate for filterbank delay */ - delay += IVAS_FB_DEC_DELAY_NS; - } + if ( hCldfb != NULL ) + { + /* compensate for filterbank delay */ + delay += IVAS_FB_DEC_DELAY_NS; + } if ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) { @@ -113,86 +113,86 @@ int32_t get_delay( } /*-------------------------------------------------------------------------- -* get_delay_fx() -* -* Function returns various types of delays in the codec in ns. -*--------------------------------------------------------------------------*/ - -Word32 get_delay_fx( /* o : delay value in ms */ - const Word16 what_delay, /* i : what delay? (ENC or DEC) */ - const Word32 io_fs, /* i : input/output sampling frequency */ - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - HANDLE_CLDFB_FILTER_BANK hCldfb /* i : Handle of Cldfb analysis */ + * get_delay_fx() + * + * Function returns various types of delays in the codec in ns. + *--------------------------------------------------------------------------*/ + +Word32 get_delay_fx( /* o : delay value in ms */ + const Word16 what_delay, /* i : what delay? (ENC or DEC) */ + const Word32 io_fs, /* i : input/output sampling frequency */ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + HANDLE_CLDFB_FILTER_BANK hCldfb /* i : Handle of Cldfb analysis */ #ifdef SPLIT_REND_WITH_HEAD_ROT - , - const AUDIO_CONFIG output_config /* i : decoder output config */ + , + const AUDIO_CONFIG output_config /* i : decoder output config */ #endif ) { - Word32 delay = 0; + Word32 delay = 0; - IF(EQ_16(what_delay, ENC)) - { - IF(EQ_16(ivas_format, MONO_FORMAT)) /* EVS mono */ + IF( EQ_16( what_delay, ENC ) ) { - delay = (DELAY_FIR_RESAMPL_NS + ACELP_LOOK_NS); - move32(); + IF( EQ_16( ivas_format, MONO_FORMAT ) ) /* EVS mono */ + { + delay = ( DELAY_FIR_RESAMPL_NS + ACELP_LOOK_NS ); + move32(); + } + ELSE + { + delay = IVAS_ENC_DELAY_NS; + test(); + IF( EQ_16( ivas_format, MASA_FORMAT ) || EQ_16( ivas_format, MASA_ISM_FORMAT ) ) + { + delay = 0; /* All delay is compensated in the decoder with MASA */ + } + } + test(); + IF( EQ_16( ivas_format, SBA_FORMAT ) || EQ_16( ivas_format, SBA_ISM_FORMAT ) ) + { + /* compensate for DirAC/SPAR filterbank delay */ + delay += IVAS_FB_ENC_DELAY_NS; + } } ELSE { - delay = IVAS_ENC_DELAY_NS; - test(); - IF(EQ_16(ivas_format, MASA_FORMAT) || EQ_16(ivas_format, MASA_ISM_FORMAT)) + IF( EQ_16( ivas_format, MONO_FORMAT ) ) /* EVS mono */ { - delay = 0; /* All delay is compensated in the decoder with MASA */ + IF( EQ_32( io_fs, 8000 ) ) + { + delay = DELAY_CLDFB_NS; + move32(); + } + ELSE + { + delay = DELAY_BWE_TOTAL_NS; + move32(); + } } - } - test(); - IF(EQ_16(ivas_format, SBA_FORMAT) || EQ_16(ivas_format, SBA_ISM_FORMAT)) - { - /* compensate for DirAC/SPAR filterbank delay */ - delay += IVAS_FB_ENC_DELAY_NS; - } - } - ELSE - { - IF(EQ_16(ivas_format, MONO_FORMAT)) /* EVS mono */ - { - IF(EQ_32(io_fs,8000)) - { - delay = DELAY_CLDFB_NS; - move32(); - } - ELSE - { - delay = DELAY_BWE_TOTAL_NS; - move32(); - } - } - ELSE /* IVAS */ - { - delay = IVAS_DEC_DELAY_NS; + ELSE /* IVAS */ + { + delay = IVAS_DEC_DELAY_NS; #ifdef SPLIT_REND_WITH_HEAD_ROT - IF(NE_16(output_config, AUDIO_CONFIG_BINAURAL_SPLIT_CODED)) + IF( NE_16( output_config, AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) ) { #endif - IF(hCldfb != NULL) + IF( hCldfb != NULL ) { - /* compensate for filterbank delay */ - delay += IVAS_FB_DEC_DELAY_NS; - } + /* compensate for filterbank delay */ + delay += IVAS_FB_DEC_DELAY_NS; + } #ifdef SPLIT_REND_WITH_HEAD_ROT } #endif test(); - IF(EQ_16(ivas_format, MASA_FORMAT) || EQ_16(ivas_format, MASA_ISM_FORMAT)) + IF( EQ_16( ivas_format, MASA_FORMAT ) || EQ_16( ivas_format, MASA_ISM_FORMAT ) ) { delay += IVAS_ENC_DELAY_NS; /* Compensate also the encoder delay in the decoder with MASA */ } } - } + } - return delay; + return delay; } diff --git a/lib_com/dlpc_bfi_fx.c b/lib_com/dlpc_bfi_fx.c index 21d7fd37c..63391f6d0 100644 --- a/lib_com/dlpc_bfi_fx.c +++ b/lib_com/dlpc_bfi_fx.c @@ -11,33 +11,31 @@ void dlpc_bfi( const Word16 L_frame, - Word16 *lsf_q, /* o : quantized LSFs */ - const Word16 *lsfold, /* i : past quantized LSF */ - const Word16 last_good, /* i : last good received frame */ - const Word16 nbLostCmpt, /* i : counter of consecutive bad frames */ - Word16 mem_MA[], /* i/o: quantizer memory for MA model */ - Word16 mem_AR[], /* i/o: quantizer memory for AR model */ - Word16 *stab_fac, /* i : LSF stability factor */ - Word16 *lsf_adaptive_mean,/* i : LSF adaptive mean, updated when BFI==0 */ - Word16 numlpc, /* i : Number of division per superframe */ + Word16 *lsf_q, /* o : quantized LSFs */ + const Word16 *lsfold, /* i : past quantized LSF */ + const Word16 last_good, /* i : last good received frame */ + const Word16 nbLostCmpt, /* i : counter of consecutive bad frames */ + Word16 mem_MA[], /* i/o: quantizer memory for MA model */ + Word16 mem_AR[], /* i/o: quantizer memory for AR model */ + Word16 *stab_fac, /* i : LSF stability factor */ + Word16 *lsf_adaptive_mean, /* i : LSF adaptive mean, updated when BFI==0 */ + Word16 numlpc, /* i : Number of division per superframe */ Word16 lsf_cng[], - Word8 plcBackgroundNoiseUpdated, - Word16 *lsf_q_cng, /* o : quantized LSFs */ - Word16 *old_lsf_q_cng, /* o : old quantized LSFs for background noise */ - const Word16* lsfBase, /* i : base for differential LSF coding */ - Word8 tcxonly -) + Word8 plcBackgroundNoiseUpdated, + Word16 *lsf_q_cng, /* o : quantized LSFs */ + Word16 *old_lsf_q_cng, /* o : old quantized LSFs for background noise */ + const Word16 *lsfBase, /* i : base for differential LSF coding */ + Word8 tcxonly ) { - lsf_dec_bfi(MODE2, &lsf_q[0], lsfold, lsf_adaptive_mean, lsfBase, mem_MA, mem_AR, *stab_fac, - 0, L_frame, last_good, nbLostCmpt, plcBackgroundNoiseUpdated, lsf_q_cng, lsf_cng, old_lsf_q_cng, 0, 0, tcxonly, 0); + lsf_dec_bfi( MODE2, &lsf_q[0], lsfold, lsf_adaptive_mean, lsfBase, mem_MA, mem_AR, *stab_fac, + 0, L_frame, last_good, nbLostCmpt, plcBackgroundNoiseUpdated, lsf_q_cng, lsf_cng, old_lsf_q_cng, 0, 0, tcxonly, 0 ); - IF ( EQ_16(numlpc,2)) + IF( EQ_16( numlpc, 2 ) ) { /* Decode the second LPC */ - lsf_dec_bfi(MODE2, &lsf_q[M], &lsf_q[0], lsf_adaptive_mean, lsfBase, mem_MA, mem_AR, *stab_fac, - 0, L_frame, last_good, nbLostCmpt+1, plcBackgroundNoiseUpdated, lsf_q_cng, lsf_cng, old_lsf_q_cng, 0, 0, tcxonly, 0); + lsf_dec_bfi( MODE2, &lsf_q[M], &lsf_q[0], lsf_adaptive_mean, lsfBase, mem_MA, mem_AR, *stab_fac, + 0, L_frame, last_good, nbLostCmpt + 1, plcBackgroundNoiseUpdated, lsf_q_cng, lsf_cng, old_lsf_q_cng, 0, 0, tcxonly, 0 ); } /**/ /*No local variabvles defined*/ } - diff --git a/lib_com/edct_fx.c b/lib_com/edct_fx.c index 8e3d4f5fe..0bc9234c2 100644 --- a/lib_com/edct_fx.c +++ b/lib_com/edct_fx.c @@ -4,17 +4,16 @@ #include #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ #include "stl.h" #include "math_32.h" -#ifdef IVAS_FLOAT_FIXED - +#ifdef IVAS_FLOAT_FIXED static Word16 get_edxt_factor( Word16 length ) /* Returns value of sqrtf(2.f/length) in Q15 */ @@ -87,75 +86,75 @@ static Word16 get_edxt_factor( Word16 length ) /* Returns value of sqrtf(2.f/len return factor; } -static Word16 const * get_edct_table(Word16 length, Word16 *q) +static Word16 const *get_edct_table( Word16 length, Word16 *q ) { - Word16 const * edct_table = NULL; - SWITCH (length) + Word16 const *edct_table = NULL; + SWITCH( length ) { - case 1200: - edct_table = edct_table_600_fx; - move16(); - *q = add(*q, 2); - BREAK; - case 960 : - edct_table = edct_table_480_fx; - move16(); - BREAK; - case 640 : - edct_table = edct_table_320_fx; - move16(); - BREAK; - case 320 : - edct_table = edct_table_160_fx; - move16(); - BREAK; - case 256 : - edct_table = edct_table_128_fx; - move16(); - BREAK; - case 240 : - edct_table = edct_table_120_fx; - move16(); - BREAK; - case 200 : - edct_table = edct_table_100_fx; - move16(); - BREAK; - case 160 : - edct_table = edct_table_80_fx ; - move16(); - BREAK; - case 40 : - edct_table = edct_table_20_fx ; - move16(); - BREAK; - case 800 : - edct_table = edct_table_400_fx; - move16(); - *q = add(*q, 2); - BREAK; - case 512 : - edct_table = edct_table_256_fx; - move16(); - BREAK; - case 480 : - edct_table = edct_table_240_fx; - move16(); - BREAK; - case 400 : - edct_table = edct_table_200_fx; - move16(); - BREAK; - case 128 : - edct_table = edct_table_64_fx ; - move16(); - BREAK; - case 80 : - edct_table = edct_table_40_fx ; - move16(); - BREAK; - default: - BREAK; + case 1200: + edct_table = edct_table_600_fx; + move16(); + *q = add( *q, 2 ); + BREAK; + case 960: + edct_table = edct_table_480_fx; + move16(); + BREAK; + case 640: + edct_table = edct_table_320_fx; + move16(); + BREAK; + case 320: + edct_table = edct_table_160_fx; + move16(); + BREAK; + case 256: + edct_table = edct_table_128_fx; + move16(); + BREAK; + case 240: + edct_table = edct_table_120_fx; + move16(); + BREAK; + case 200: + edct_table = edct_table_100_fx; + move16(); + BREAK; + case 160: + edct_table = edct_table_80_fx; + move16(); + BREAK; + case 40: + edct_table = edct_table_20_fx; + move16(); + BREAK; + case 800: + edct_table = edct_table_400_fx; + move16(); + *q = add( *q, 2 ); + BREAK; + case 512: + edct_table = edct_table_256_fx; + move16(); + BREAK; + case 480: + edct_table = edct_table_240_fx; + move16(); + BREAK; + case 400: + edct_table = edct_table_200_fx; + move16(); + BREAK; + case 128: + edct_table = edct_table_64_fx; + move16(); + BREAK; + case 80: + edct_table = edct_table_40_fx; + move16(); + BREAK; + default: + BREAK; } return edct_table; } @@ -174,50 +173,52 @@ static Word16 const * get_edct_table(Word16 length, Word16 *q) * _ (Word16[]) y : output transform Qx *-------------------------------------------------------------------------*/ void edct_fx( - const Word32 *x, /* i : input signal Qq */ - Word32 *y, /* o : output transform Qq */ - Word16 length, /* i : length */ - Word16 *q /* i : Q value of input signal */ + const Word32 *x, /* i : input signal Qq */ + Word32 *y, /* o : output transform Qq */ + Word16 length, /* i : length */ + Word16 *q /* i : Q value of input signal */ ) { Word16 i; Word32 re; Word32 im; - const Word16 *edct_table = 0; /*Q16 */ - Word32 complex_buf[2*(L_FRAME48k/2+240)]; + const Word16 *edct_table = 0; /*Q16 */ + Word32 complex_buf[2 * ( L_FRAME48k / 2 + 240 )]; Word32 L_tmp; Word16 tmp; Word16 len1; - edct_table = get_edct_table(length, q); - len1 = shr(length, 1); + edct_table = get_edct_table( length, q ); + len1 = shr( length, 1 ); /* Twiddling and Pre-rotate */ - FOR (i = 0; i < len1; i++) + FOR( i = 0; i < len1; i++ ) { - L_tmp = Mult_32_16(x[2*i], edct_table[i]); /*Q(q+1) */ - complex_buf[2*i] = Madd_32_16(L_tmp, x[length-1-2*i], edct_table[len1-1-i]); /*Q(q+1) */ move32(); + L_tmp = Mult_32_16( x[2 * i], edct_table[i] ); /*Q(q+1) */ + complex_buf[2 * i] = Madd_32_16( L_tmp, x[length - 1 - 2 * i], edct_table[len1 - 1 - i] ); /*Q(q+1) */ + move32(); - L_tmp = Mult_32_16(x[length-1-2*i], edct_table[i]); /*Q(q+1) */ + L_tmp = Mult_32_16( x[length - 1 - 2 * i], edct_table[i] ); /*Q(q+1) */ - complex_buf[2*i+1] = Msub_32_16(L_tmp, x[2*i], edct_table[len1-1-i]); /*Q(q+1) */ move32(); + complex_buf[2 * i + 1] = Msub_32_16( L_tmp, x[2 * i], edct_table[len1 - 1 - i] ); /*Q(q+1) */ + move32(); } - *q = sub(15, *q); - BASOP_cfft((cmplx *)complex_buf, len1, q, y); + *q = sub( 15, *q ); + BASOP_cfft( (cmplx *) complex_buf, len1, q, y ); - tmp = div_s(1, length); /*Q15 */ - tmp = round_fx(L_shl(L_mult(tmp, 19302), 2)); /*Q15 */ - FOR (i = 0; i < len1; i++) + tmp = div_s( 1, length ); /*Q15 */ + tmp = round_fx( L_shl( L_mult( tmp, 19302 ), 2 ) ); /*Q15 */ + FOR( i = 0; i < len1; i++ ) { - re = Msub_32_16(complex_buf[2*i], complex_buf[2*i+1], tmp); - im = Madd_32_16(complex_buf[2*i+1], complex_buf[2*i], tmp); - y[2 * i] = L_add(Mult_32_16(re, edct_table[i]), Mult_32_16(im, edct_table[len1 - 1 - i])); + re = Msub_32_16( complex_buf[2 * i], complex_buf[2 * i + 1], tmp ); + im = Madd_32_16( complex_buf[2 * i + 1], complex_buf[2 * i], tmp ); + y[2 * i] = L_add( Mult_32_16( re, edct_table[i] ), Mult_32_16( im, edct_table[len1 - 1 - i] ) ); move32(); - y[length - 1 - 2 * i] = L_sub(Mult_32_16(re, edct_table[len1 - 1 - i]), Mult_32_16(im, edct_table[i])); + y[length - 1 - 2 * i] = L_sub( Mult_32_16( re, edct_table[len1 - 1 - i] ), Mult_32_16( im, edct_table[i] ) ); move32(); } /*Q(q-2) */ - *q = sub(15+2, *q); + *q = sub( 15 + 2, *q ); return; } @@ -235,51 +236,51 @@ void edct_fx( * _ (Word16[]) y : output transform Qx *-------------------------------------------------------------------------*/ void edst_fx( - const Word32 *x, /* i : input signal Qq */ - Word32 *y, /* o : output transform Qq */ - Word16 length, /* i : length */ - Word16 *q /* i : Q value of input signal */ + const Word32 *x, /* i : input signal Qq */ + Word32 *y, /* o : output transform Qq */ + Word16 length, /* i : length */ + Word16 *q /* i : Q value of input signal */ ) { Word16 i; Word32 re; Word32 im; - const Word16 *edct_table = 0; /*Q16 */ - Word32 complex_buf[2*(L_FRAME48k/2+240)]; + const Word16 *edct_table = 0; /*Q16 */ + Word32 complex_buf[2 * ( L_FRAME48k / 2 + 240 )]; Word32 L_tmp; Word16 tmp; Word16 len1; - edct_table = get_edct_table(length, q); - len1 = shr(length, 1); + edct_table = get_edct_table( length, q ); + len1 = shr( length, 1 ); /* Twiddling and Pre-rotate */ - FOR (i = 0; i < len1; i++) + FOR( i = 0; i < len1; i++ ) { - L_tmp = Mult_32_16(x[length-1-2*i], edct_table[i]); - complex_buf[2*i] = Madd_32_16(L_tmp, x[2*i], edct_table[len1-1-i]); + L_tmp = Mult_32_16( x[length - 1 - 2 * i], edct_table[i] ); + complex_buf[2 * i] = Madd_32_16( L_tmp, x[2 * i], edct_table[len1 - 1 - i] ); move32(); - L_tmp = Mult_32_16(x[2*i], edct_table[i]); - complex_buf[2*i+1] = Msub_32_16(L_tmp, x[length-1-2*i], edct_table[len1-1-i]); + L_tmp = Mult_32_16( x[2 * i], edct_table[i] ); + complex_buf[2 * i + 1] = Msub_32_16( L_tmp, x[length - 1 - 2 * i], edct_table[len1 - 1 - i] ); move32(); } - *q = sub(15, *q); - BASOP_cfft((cmplx *)complex_buf, len1, q, y); + *q = sub( 15, *q ); + BASOP_cfft( (cmplx *) complex_buf, len1, q, y ); - tmp = div_s(1, length); /*Q15 */ - tmp = round_fx(L_shl(L_mult(tmp, 19302), 2)); /*Q15 */ - FOR (i = 0; i < len1; i++) + tmp = div_s( 1, length ); /*Q15 */ + tmp = round_fx( L_shl( L_mult( tmp, 19302 ), 2 ) ); /*Q15 */ + FOR( i = 0; i < len1; i++ ) { - re = Msub_32_16(complex_buf[2*i], complex_buf[2*i+1], tmp); - im = Madd_32_16(complex_buf[2*i+1], complex_buf[2*i], tmp); - y[2 * i] = L_add(Mult_32_16(re, edct_table[i]), Mult_32_16(im, edct_table[len1 - 1 - i])); + re = Msub_32_16( complex_buf[2 * i], complex_buf[2 * i + 1], tmp ); + im = Madd_32_16( complex_buf[2 * i + 1], complex_buf[2 * i], tmp ); + y[2 * i] = L_add( Mult_32_16( re, edct_table[i] ), Mult_32_16( im, edct_table[len1 - 1 - i] ) ); move32(); - y[length - 1 - 2 * i] = L_sub(Mult_32_16(im, edct_table[i]), Mult_32_16(re, edct_table[len1 - 1 - i])); + y[length - 1 - 2 * i] = L_sub( Mult_32_16( im, edct_table[i] ), Mult_32_16( re, edct_table[len1 - 1 - i] ) ); move32(); } /*Q(q) */ - *q = sub(15+2, *q); + *q = sub( 15 + 2, *q ); return; } @@ -304,20 +305,20 @@ void edst_fx( /* _ None */ /*========================================================================*/ void edct_16fx( - const Word16 *x, /* i : input signal Qx */ - Word16 *y, /* o : output transform Qx */ - Word16 length, /* i : length */ - Word16 bh, /* bit-headroom */ + const Word16 *x, /* i : input signal Qx */ + Word16 *y, /* o : output transform Qx */ + Word16 length, /* i : length */ + Word16 bh, /* bit-headroom */ const Word16 element_mode ) { Word16 i; - Word16 re[L_FRAME48k/2]; - Word16 im[L_FRAME48k/2]; + Word16 re[L_FRAME48k / 2]; + Word16 im[L_FRAME48k / 2]; const Word16 *edct_table = 0; - Word16 re2[L_FRAME48k/2]; - Word16 im2[L_FRAME48k/2]; + Word16 re2[L_FRAME48k / 2]; + Word16 im2[L_FRAME48k / 2]; Word32 L_tmp, Lacc, Lmax; Word16 tmp, fact; @@ -333,17 +334,17 @@ void edct_16fx( #endif /*COMPLETE: some eDCT sub function are missing */ - IF (EQ_16(length,L_FRAME32k)) + IF( EQ_16( length, L_FRAME32k ) ) { edct_table = &edct_table_320_16fx[0]; move16(); } - ELSE IF (EQ_16(length,L_FRAME)) + ELSE IF( EQ_16( length, L_FRAME ) ) { edct_table = &edct_table_128_16fx[0]; move16(); } - ELSE IF (EQ_16(length,L_FRAME16k)) + ELSE IF( EQ_16( length, L_FRAME16k ) ) { edct_table = &edct_table_160_16fx[0]; move16(); @@ -353,117 +354,121 @@ void edct_16fx( } /* Twiddling and Pre-rotate */ - Lmax = L_deposit_l(0); - Len2 = shr(length,1); + Lmax = L_deposit_l( 0 ); + Len2 = shr( length, 1 ); px = x + length - 1; pt = edct_table + Len2 - 1; - FOR (i = 0; i < Len2; i++) + FOR( i = 0; i < Len2; i++ ) { - i2 = shl(i,1); - L_tmp = L_mult(x[i2],edct_table[i]);/*Q(Qx+16) */ + i2 = shl( i, 1 ); + L_tmp = L_mult( x[i2], edct_table[i] ); /*Q(Qx+16) */ - Lacc = L_mac(L_tmp,*px,*pt);/*Q(Qx+16) */ + Lacc = L_mac( L_tmp, *px, *pt ); /*Q(Qx+16) */ - Lmax = L_max(Lmax, Lacc); + Lmax = L_max( Lmax, Lacc ); - L_tmp = L_mult(*px,edct_table[i]);/*Q(Qx+16) */ - Lacc = L_msu(L_tmp,x[i2],*pt);/*Q(Qx+16) */ - Lmax = L_max(Lmax, Lacc); + L_tmp = L_mult( *px, edct_table[i] ); /*Q(Qx+16) */ + Lacc = L_msu( L_tmp, x[i2], *pt ); /*Q(Qx+16) */ + Lmax = L_max( Lmax, Lacc ); px -= 2; pt--; } tmp = 31; - if( Lmax != 0 ) + if ( Lmax != 0 ) { - tmp = norm_l(Lmax); + tmp = norm_l( Lmax ); } - Q_edct = sub(tmp,bh); /*creating a bit-headroom */ + Q_edct = sub( tmp, bh ); /*creating a bit-headroom */ px = x + length - 1; pt = edct_table + Len2 - 1; - FOR (i = 0; i < Len2; i++) + FOR( i = 0; i < Len2; i++ ) { - i2 = shl(i,1); + i2 = shl( i, 1 ); - L_tmp = L_mult(x[i2],edct_table[i]);/*Q(Qx+16) */ + L_tmp = L_mult( x[i2], edct_table[i] ); /*Q(Qx+16) */ #ifdef BASOP_NOGLOB - Lacc = L_mac_o(L_tmp,*px,*pt, &Overflow);/*Q(Qx+16) */ - re2[i] = round_fx_o(L_shl_o(Lacc, Q_edct, &Overflow), &Overflow); /* Q(Qx+Q_edct) */ + Lacc = L_mac_o( L_tmp, *px, *pt, &Overflow ); /*Q(Qx+16) */ + re2[i] = round_fx_o( L_shl_o( Lacc, Q_edct, &Overflow ), &Overflow ); /* Q(Qx+Q_edct) */ #else - Lacc = L_mac(L_tmp,*px,*pt);/*Q(Qx+16) */ - re2[i] = round_fx(L_shl(Lacc, Q_edct)); /* Q(Qx+Q_edct) */ + Lacc = L_mac( L_tmp, *px, *pt ); /*Q(Qx+16) */ + re2[i] = round_fx( L_shl( Lacc, Q_edct ) ); /* Q(Qx+Q_edct) */ #endif - L_tmp = L_mult(*px,edct_table[i]);/*Q(Qx+16) */ + L_tmp = L_mult( *px, edct_table[i] ); /*Q(Qx+16) */ #ifdef BASOP_NOGLOB - Lacc = L_msu_o(L_tmp,x[i2],*pt, &Overflow);/*Q(Qx+16) */ - im2[i] = round_fx_o(L_shl_o(Lacc, Q_edct, &Overflow), &Overflow); /* Q(Qx+Q_edct) */ + Lacc = L_msu_o( L_tmp, x[i2], *pt, &Overflow ); /*Q(Qx+16) */ + im2[i] = round_fx_o( L_shl_o( Lacc, Q_edct, &Overflow ), &Overflow ); /* Q(Qx+Q_edct) */ #else - Lacc = L_msu(L_tmp,x[i2],*pt);/*Q(Qx+16) */ - im2[i] = round_fx(L_shl(Lacc, Q_edct)); /* Q(Qx+Q_edct) */ + Lacc = L_msu( L_tmp, x[i2], *pt ); /*Q(Qx+16) */ + im2[i] = round_fx( L_shl( Lacc, Q_edct ) ); /* Q(Qx+Q_edct) */ #endif px -= 2; pt--; } - IF (EQ_16(length,L_FRAME32k)) + IF( EQ_16( length, L_FRAME32k ) ) { - DoRTFT320_16fx(re2, im2); + DoRTFT320_16fx( re2, im2 ); } - ELSE IF (EQ_16(length,L_FRAME )) + ELSE IF( EQ_16( length, L_FRAME ) ) { - DoRTFT128_16fx(re2, im2); + DoRTFT128_16fx( re2, im2 ); } - ELSE IF (EQ_16(length,L_FRAME16k)) + ELSE IF( EQ_16( length, L_FRAME16k ) ) { - DoRTFT160_16fx(re2, im2); + DoRTFT160_16fx( re2, im2 ); } ELSE { } - tmp = div_s(1,length); /*Q15 */ - L_tmp = L_mult(tmp,19302); /*Q29, (3*PI/4) in Q13 */ - fact = round_fx(L_shl(L_tmp,2)); /*Q15 */ - FOR (i = 0; i < length/2; i++) + tmp = div_s( 1, length ); /*Q15 */ + L_tmp = L_mult( tmp, 19302 ); /*Q29, (3*PI/4) in Q13 */ + fact = round_fx( L_shl( L_tmp, 2 ) ); /*Q15 */ + FOR( i = 0; i < length / 2; i++ ) { - tmp = mult_r(im2[i],fact); /*Q(Qx+Q_edct) */ + tmp = mult_r( im2[i], fact ); /*Q(Qx+Q_edct) */ #ifdef BASOP_NOGLOB - re[i] = sub_o(re2[i], tmp, &Overflow); /*Q(Qx+Q_edct) */ move16(); + re[i] = sub_o( re2[i], tmp, &Overflow ); /*Q(Qx+Q_edct) */ + move16(); #else - re[i] = sub(re2[i],tmp); /*Q(Qx+Q_edct) */ move16(); + re[i] = sub( re2[i], tmp ); /*Q(Qx+Q_edct) */ + move16(); #endif - tmp = mult_r(re2[i],fact); /*Q(Qx+Q_edct) */ + tmp = mult_r( re2[i], fact ); /*Q(Qx+Q_edct) */ #ifdef BASOP_NOGLOB - im[i] = add_o(im2[i],tmp, &Overflow); /*Q(Qx+Q_edct) */ move16(); + im[i] = add_o( im2[i], tmp, &Overflow ); /*Q(Qx+Q_edct) */ + move16(); #else - im[i] = add(im2[i],tmp); /*Q(Qx+Q_edct) */ move16(); + im[i] = add( im2[i], tmp ); /*Q(Qx+Q_edct) */ + move16(); #endif } /* Post-rotate and obtain the output data */ py = y + length - 1; pt = edct_table + Len2 - 1; - FOR (i = 0; i < Len2; i++) + FOR( i = 0; i < Len2; i++ ) { - i2 = shl(i,1); + i2 = shl( i, 1 ); - L_tmp = L_mult(re[i],edct_table[i]);/*Q(Qx+Q_edct+16) */ + L_tmp = L_mult( re[i], edct_table[i] ); /*Q(Qx+Q_edct+16) */ #ifdef BASOP_NOGLOB - Lacc = L_mac_o(L_tmp, im[i], *pt, &Overflow);/*Q(Qx+Q_edct+16) */ - y[i2] = round_fx_o(L_shr_o(Lacc,Q_edct, &Overflow), &Overflow); /* Q(Qx) */ -#else /* BASOP_NOGLOB */ - Lacc = L_mac(L_tmp, im[i], *pt);/*Q(Qx+Q_edct+16) */ - y[i2] = round_fx(L_shr(Lacc,Q_edct)); /* Q(Qx) */ -#endif /* BASOP_NOGLOB */ - - L_tmp = L_mult(re[i],edct_table[length/2-1-i]);/*Q(Qx+Q_edct+16) */ - Lacc = L_msu(L_tmp,im[i],edct_table[i]);/*Q(Qx+Q_edct+16) */ + Lacc = L_mac_o( L_tmp, im[i], *pt, &Overflow ); /*Q(Qx+Q_edct+16) */ + y[i2] = round_fx_o( L_shr_o( Lacc, Q_edct, &Overflow ), &Overflow ); /* Q(Qx) */ +#else /* BASOP_NOGLOB */ + Lacc = L_mac( L_tmp, im[i], *pt ); /*Q(Qx+Q_edct+16) */ + y[i2] = round_fx( L_shr( Lacc, Q_edct ) ); /* Q(Qx) */ +#endif /* BASOP_NOGLOB */ + + L_tmp = L_mult( re[i], edct_table[length / 2 - 1 - i] ); /*Q(Qx+Q_edct+16) */ + Lacc = L_msu( L_tmp, im[i], edct_table[i] ); /*Q(Qx+Q_edct+16) */ #ifdef BASOP_NOGLOB - *py = round_fx_o(L_shr_o(Lacc,Q_edct, &Overflow), &Overflow); /* Q(Qx) */ -#else /* BASOP_NOGLOB */ - *py = round_fx(L_shr(Lacc,Q_edct)); /* Q(Qx) */ + *py = round_fx_o( L_shr_o( Lacc, Q_edct, &Overflow ), &Overflow ); /* Q(Qx) */ +#else /* BASOP_NOGLOB */ + *py = round_fx( L_shr( Lacc, Q_edct ) ); /* Q(Qx) */ #endif py -= 2; @@ -480,10 +485,10 @@ void edct_16fx( *-----------------------------------------------------------------*/ void iedct_short_fx( - const Word32 *in, /* i : input vector */ - Word16 *Q, /* i/o: Q value of input */ - Word32 *out, /* o : output vector */ - const Word16 segment_length /* i : length */ + const Word32 *in, /* i : input vector */ + Word16 *Q, /* i/o: Q value of input */ + Word32 *out, /* o : output vector */ + const Word16 segment_length /* i : length */ ) { Word32 alias[MAX_SEGMENT_LENGTH]; @@ -495,34 +500,34 @@ void iedct_short_fx( move16(); tmp = 0; move16(); - seg_len_div2 = shr(segment_length, 1); - seg_len_div4 = shr(segment_length, 2); - seg_len_3mul_div4 = add(seg_len_div2, seg_len_div4); + seg_len_div2 = shr( segment_length, 1 ); + seg_len_div4 = shr( segment_length, 2 ); + seg_len_3mul_div4 = add( seg_len_div2, seg_len_div4 ); - edct_fx(in, alias, seg_len_div2, Q); - FOR (i = 0; i < seg_len_div2; i++) + edct_fx( in, alias, seg_len_div2, Q ); + FOR( i = 0; i < seg_len_div2; i++ ) { - IF (alias[i] != 0) + IF( alias[i] != 0 ) { tmp = 1; move16(); BREAK; } } - if (tmp == 0) + if ( tmp == 0 ) { *Q = qtmp; move16(); } - FOR (i = 0; i < seg_len_div4; i++) + FOR( i = 0; i < seg_len_div4; i++ ) { - out[i] = alias[seg_len_div4 + i]; + out[i] = alias[seg_len_div4 + i]; move32(); - out[seg_len_div4 + i] = L_negate(alias[seg_len_div2 - 1 - i]); + out[seg_len_div4 + i] = L_negate( alias[seg_len_div2 - 1 - i] ); move32(); - out[seg_len_div2 + i] = L_negate(alias[seg_len_div4 - 1 - i]); + out[seg_len_div2 + i] = L_negate( alias[seg_len_div4 - 1 - i] ); move32(); - out[seg_len_3mul_div4 + i] = L_negate(alias[i]); + out[seg_len_3mul_div4 + i] = L_negate( alias[i] ); move32(); } @@ -658,7 +663,7 @@ void edxt_fx( FOR( k = shr( Nm1, 1 ); k >= 0; k-- ) /* pre-modulation of audio input */ { re[k] = x[2 * k]; - re[Nm1 - k] = Mpy_32_16_1( x[2 * k + 1], shl_sat(xSign, 15) ); + re[Nm1 - k] = Mpy_32_16_1( x[2 * k + 1], shl_sat( xSign, 15 ) ); im[k] = im[Nm1 - k] = 0; } @@ -700,7 +705,7 @@ void edxt_fx( y[shr( Nm1, 1 )] = Mpy_32_16_1( re[shr( length, 1 )], INV_SQRT_2_Q15 ); } - y[Nm1 - Nm1 * (kernelType >> 1)] = L_shr( re[0], 1 ); + y[Nm1 - Nm1 * ( kernelType >> 1 )] = L_shr( re[0], 1 ); } ELSE /* inverse II = III */ { @@ -716,7 +721,7 @@ void edxt_fx( re[k] = L_add( Mpy_32_16_1( x[k], wRe ), Mpy_32_16_1( x[length - k], wIm ) ); im[k] = L_sub( Mpy_32_16_1( x[length - k], wRe ), Mpy_32_16_1( x[k], wIm ) ); } - re[shr( length, 1 )] = Mpy_32_16_1(x[shr( length, 1 )], INV_SQRT_2_Q15); + re[shr( length, 1 )] = Mpy_32_16_1( x[shr( length, 1 )], INV_SQRT_2_Q15 ); } ELSE /* DST type III */ { @@ -730,10 +735,10 @@ void edxt_fx( re[k] = L_add( Mpy_32_16_1( x[Nm1 - k], wRe ), Mpy_32_16_1( x[k - 1], wIm ) ); im[k] = L_sub( Mpy_32_16_1( x[k - 1], wRe ), Mpy_32_16_1( x[Nm1 - k], wIm ) ); } - re[shr( length, 1 )] = Mpy_32_16_1(x[shr( Nm1, 1 )], INV_SQRT_2_Q15); + re[shr( length, 1 )] = Mpy_32_16_1( x[shr( Nm1, 1 )], INV_SQRT_2_Q15 ); } - re[0] = x[Nm1 - Nm1 * shr(kernelType, 1)]; + re[0] = x[Nm1 - Nm1 * shr( kernelType, 1 )]; im[0] = im[shr( length, 1 )] = 0; FOR( k = shr( Nm1, 1 ); k > 0; k-- ) { @@ -755,7 +760,7 @@ void edxt_fx( y[2 * k] = re[k]; IF( NE_16( xSign, 0 ) ) { - y[2 * k + 1] = Mpy_32_16_1(re[sub( Nm1, k )], shl_sat(xSign, 15)); + y[2 * k + 1] = Mpy_32_16_1( re[sub( Nm1, k )], shl_sat( xSign, 15 ) ); } ELSE { @@ -767,11 +772,11 @@ void edxt_fx( #endif #ifdef IVAS_FLOAT_FIXED_TO_BE_DONE ELSE - /* TODO: below IF and ELSE blocks are unreachable, verified on code coverage report */ + /* TODO: below IF and ELSE blocks are unreachable, verified on code coverage report */ IF( s_and( kernelType, 1 ) ) /* DST */ { - const float offK = (kernelType == MDST_II && synthesis ? 0.5f : 1.0f - 0.5f * (kernelType >> 1)); - const float offM = (kernelType == MDST_II && synthesis ? 1.0f : 0.5f); + const float offK = ( kernelType == MDST_II && synthesis ? 0.5f : 1.0f - 0.5f * ( kernelType >> 1 ) ); + const float offM = ( kernelType == MDST_II && synthesis ? 1.0f : 0.5f ); FOR( k = 0; k < length; k++ ) { @@ -804,7 +809,7 @@ void edxt_fx( y[0] *= 0.5f; /* scale lowest (i.e. DC) sample */ } } -#endif //IVAS_FLOAT_FIXED_TO_BE_DONE +#endif // IVAS_FLOAT_FIXED_TO_BE_DONE /*v_multc(y, (kernelType == MDCT_II ? -1.f : 1.f) * sqrtf(2.f / length), y, length);*/ fac = get_edxt_factor( length ); /* Q15 */ IF( EQ_16( kernelType, MDCT_II ) ) @@ -818,4 +823,4 @@ void edxt_fx( } return; } -#endif \ No newline at end of file +#endif diff --git a/lib_com/enh1632.c b/lib_com/enh1632.c index da8dc2d10..3704c2bd3 100644 --- a/lib_com/enh1632.c +++ b/lib_com/enh1632.c @@ -9,7 +9,7 @@ History: 07 Nov 04 v2.0 Incorporation of new 32-bit / 40-bit / control - operators for the ITU-T Standard Tool Library as + operators for the ITU-T Standard Tool Library as described in Geneva, 20-30 January 2004 WP 3/16 Q10/16 TD 11 document and subsequent discussions on the wp3audio@yahoogroups.com email reflector. @@ -18,7 +18,7 @@ */ - /***************************************************************************** +/***************************************************************************** * * Enhanced 16/32 bit operators : * s_max() @@ -56,13 +56,12 @@ #include #include "stl.h" -#if (WMOPS) +#if ( WMOPS ) extern BASIC_OP multiCounter[MAXCOUNTERS]; extern int currCounter; #endif /* ifdef WMOPS */ - /***************************************************************************** * * Constants and Globals @@ -93,10 +92,10 @@ extern int currCounter; * * Inputs : * - * var1 16 bit short signed integer (Word16) whose value falls in + * var1 16 bit short signed integer (Word16) whose value falls in * the range 0xffff 8000 <= var1 <= 0x0000 7fff. * - * var2 16 bit short signed integer (Word16) whose value falls in + * var2 16 bit short signed integer (Word16) whose value falls in * the range 0xffff 8000 <= var2 <= 0x0000 7fff. * * Outputs : @@ -105,35 +104,43 @@ extern int currCounter; * * Return Value: * - * var_out 16 bit short signed integer (Word16) whose value falls in + * var_out 16 bit short signed integer (Word16) whose value falls in * the range 0xffff 8000 <= var_out <= 0x0000 7fff. * *****************************************************************************/ -Word16 lshl (Word16 var1, Word16 var2) { - Word16 var_out = 0; +Word16 lshl( Word16 var1, Word16 var2 ) +{ + Word16 var_out = 0; - if (var2 < 0) { - var2 = -var2; - var_out = lshr (var1, var2); + if ( var2 < 0 ) + { + var2 = -var2; + var_out = lshr( var1, var2 ); -#if (WMOPS) - multiCounter[currCounter].lshr--; +#if ( WMOPS ) + multiCounter[currCounter].lshr--; #endif /* ifdef WMOPS */ - - } else { - if (var2 == 0 || var1 == 0) { - var_out = var1; - } else if (var2 >= 16) { - var_out = 0; - } else { - var_out = var1 << var2; } - } -#if (WMOPS) - multiCounter[currCounter].lshl++; + else + { + if ( var2 == 0 || var1 == 0 ) + { + var_out = var1; + } + else if ( var2 >= 16 ) + { + var_out = 0; + } + else + { + var_out = var1 << var2; + } + } +#if ( WMOPS ) + multiCounter[currCounter].lshl++; #endif /* ifdef WMOPS */ - return (var_out); + return ( var_out ); } /***************************************************************************** @@ -152,10 +159,10 @@ Word16 lshl (Word16 var1, Word16 var2) { * * Inputs : * - * var1 16 bit short signed integer (Word16) whose value falls in + * var1 16 bit short signed integer (Word16) whose value falls in * the range 0xffff 8000 <= var1 <= 0x0000 7fff. * - * var2 16 bit short signed integer (Word16) whose value falls in + * var2 16 bit short signed integer (Word16) whose value falls in * the range 0xffff 8000 <= var2 <= 0x0000 7fff. * * Outputs : @@ -164,37 +171,45 @@ Word16 lshl (Word16 var1, Word16 var2) { * * Return Value: * - * var_out 16 bit short signed integer (Word16) whose value falls in + * var_out 16 bit short signed integer (Word16) whose value falls in * the range 0xffff 8000 <= var_out <= 0x0000 7fff. * *****************************************************************************/ -Word16 lshr (Word16 var1, Word16 var2) { - Word16 var_out; +Word16 lshr( Word16 var1, Word16 var2 ) +{ + Word16 var_out; - if (var2 < 0) { - var2 = -var2; - var_out = lshl (var1, var2); + if ( var2 < 0 ) + { + var2 = -var2; + var_out = lshl( var1, var2 ); -#if (WMOPS) - multiCounter[currCounter].lshl--; +#if ( WMOPS ) + multiCounter[currCounter].lshl--; #endif /* ifdef WMOPS */ - - } else { - if (var2 == 0 || var1 == 0) { - var_out = var1; - } else if (var2 >= 16) { - var_out = 0; - } else { - var_out = var1 >> 1; - var_out = var_out & 0x7fff; - var_out = var_out >> (var2 - 1); } - } -#if (WMOPS) - multiCounter[currCounter].lshr++; + else + { + if ( var2 == 0 || var1 == 0 ) + { + var_out = var1; + } + else if ( var2 >= 16 ) + { + var_out = 0; + } + else + { + var_out = var1 >> 1; + var_out = var_out & 0x7fff; + var_out = var_out >> ( var2 - 1 ); + } + } +#if ( WMOPS ) + multiCounter[currCounter].lshr++; #endif /* ifdef WMOPS */ - return (var_out); + return ( var_out ); } @@ -214,10 +229,10 @@ Word16 lshr (Word16 var1, Word16 var2) { * * Inputs : * - * L_var1 32 bit long signed integer (Word32) whose value falls in + * L_var1 32 bit long signed integer (Word32) whose value falls in * the range 0x8000 0000 <= L_var1 <= 0x7fff ffff. * - * var2 16 bit short signed integer (Word16) whose value falls in + * var2 16 bit short signed integer (Word16) whose value falls in * the range 0xffff 8000 <= var2 <= 0x0000 7fff. * * Outputs : @@ -226,35 +241,43 @@ Word16 lshr (Word16 var1, Word16 var2) { * * Return Value: * - * L_var_out 32 bit long signed integer (Word32) whose value falls in + * L_var_out 32 bit long signed integer (Word32) whose value falls in * the range 0x8000 0000 <= L_var_out <= 0x7fff ffff. * *****************************************************************************/ -Word32 L_lshl (Word32 L_var1, Word16 var2) { - Word32 L_var_out = 0; +Word32 L_lshl( Word32 L_var1, Word16 var2 ) +{ + Word32 L_var_out = 0; - if (var2 < 0) { - var2 = -var2; - L_var_out = L_lshr (L_var1, var2); + if ( var2 < 0 ) + { + var2 = -var2; + L_var_out = L_lshr( L_var1, var2 ); -#if (WMOPS) - multiCounter[currCounter].L_lshr--; +#if ( WMOPS ) + multiCounter[currCounter].L_lshr--; #endif /* ifdef WMOPS */ - - } else { - if (var2 == 0 || L_var1 == 0) { - L_var_out = L_var1; - } else if (var2 >= 32) { - L_var_out = 0; - } else { - L_var_out = L_var1 << var2; } - } -#if (WMOPS) - multiCounter[currCounter].L_lshl++; + else + { + if ( var2 == 0 || L_var1 == 0 ) + { + L_var_out = L_var1; + } + else if ( var2 >= 32 ) + { + L_var_out = 0; + } + else + { + L_var_out = L_var1 << var2; + } + } +#if ( WMOPS ) + multiCounter[currCounter].L_lshl++; #endif /* ifdef WMOPS */ - return (L_var_out); + return ( L_var_out ); } @@ -274,10 +297,10 @@ Word32 L_lshl (Word32 L_var1, Word16 var2) { * * Inputs : * - * L_var1 32 bit long signed integer (Word32) whose value falls in + * L_var1 32 bit long signed integer (Word32) whose value falls in * the range 0x8000 0000 <= L_var1 <= 0x7fff ffff. * - * var2 16 bit short signed integer (Word16) whose value falls in + * var2 16 bit short signed integer (Word16) whose value falls in * the range 0xffff 8000 <= var2 <= 0x0000 7fff. * * Outputs : @@ -286,37 +309,45 @@ Word32 L_lshl (Word32 L_var1, Word16 var2) { * * Return Value: * - * L_var_out 32 bit long signed integer (Word32) whose value falls in + * L_var_out 32 bit long signed integer (Word32) whose value falls in * the range 0x8000 0000 <= L_var_out <= 0x7fff ffff. * *****************************************************************************/ -Word32 L_lshr (Word32 L_var1, Word16 var2) { - Word32 L_var_out; +Word32 L_lshr( Word32 L_var1, Word16 var2 ) +{ + Word32 L_var_out; - if (var2 < 0) { - var2 = -var2; - L_var_out = L_lshl (L_var1, var2); + if ( var2 < 0 ) + { + var2 = -var2; + L_var_out = L_lshl( L_var1, var2 ); -#if (WMOPS) - multiCounter[currCounter].L_lshl--; +#if ( WMOPS ) + multiCounter[currCounter].L_lshl--; #endif /* ifdef WMOPS */ - - } else { - if (var2 == 0 || L_var1 == 0) { - L_var_out = L_var1; - } else if (var2 >= 32) { - L_var_out = 0; - } else { - L_var_out = L_var1 >> 1; - L_var_out = L_var_out & 0x7fffffff; - L_var_out = L_var_out >> (var2 - 1); } - } -#if (WMOPS) - multiCounter[currCounter].L_lshr++; + else + { + if ( var2 == 0 || L_var1 == 0 ) + { + L_var_out = L_var1; + } + else if ( var2 >= 32 ) + { + L_var_out = 0; + } + else + { + L_var_out = L_var1 >> 1; + L_var_out = L_var_out & 0x7fffffff; + L_var_out = L_var_out >> ( var2 - 1 ); + } + } +#if ( WMOPS ) + multiCounter[currCounter].L_lshr++; #endif /* ifdef WMOPS */ - return (L_var_out); + return ( L_var_out ); } @@ -333,10 +364,10 @@ Word32 L_lshr (Word32 L_var1, Word16 var2) { * * Inputs : * - * var1 16 bit short signed integer (Word16) whose value falls in + * var1 16 bit short signed integer (Word16) whose value falls in * the range : 0xffff 8000 <= var1 <= 0x0000 7fff. * - * var2 16 bit short signed integer (Word16) whose value falls in + * var2 16 bit short signed integer (Word16) whose value falls in * the range : 0xffff 8000 <= var2 <= 0x0000 7fff. * * Outputs : @@ -345,48 +376,53 @@ Word32 L_lshr (Word32 L_var1, Word16 var2) { * * Return Value : * - * var_out 16 bit short signed integer (Word16) whose value falls in + * var_out 16 bit short signed integer (Word16) whose value falls in * the range : 0xffff 8000 <= var_out <= 0x0000 7fff. * *****************************************************************************/ #ifdef BASOP_NOGLOB -Word16 shl_ro(Word16 var1, Word16 var2, Flag* Overflow) { +Word16 shl_ro( Word16 var1, Word16 var2, Flag *Overflow ) +{ #else -Word16 shl_r (Word16 var1, Word16 var2) { +Word16 shl_r( Word16 var1, Word16 var2 ) +{ #endif - Word16 var_out; + Word16 var_out; - if (var2 >= 0) { + if ( var2 >= 0 ) + { #ifdef BASOP_NOGLOB - var_out = shl_o (var1, var2, Overflow); + var_out = shl_o( var1, var2, Overflow ); #else - var_out = shl (var1, var2); + var_out = shl( var1, var2 ); #endif -#if (WMOPS) - multiCounter[currCounter].shl--; +#if ( WMOPS ) + multiCounter[currCounter].shl--; #endif /* ifdef WMOPS */ - - } else { - var2 = -var2; + } + else + { + var2 = -var2; #ifdef BASOP_NOGLOB - var_out = shr_ro (var1, var2, Overflow); + var_out = shr_ro( var1, var2, Overflow ); #else - var_out = shr_r (var1, var2); + var_out = shr_r( var1, var2 ); #endif -#if (WMOPS) - multiCounter[currCounter].shr_r--; +#if ( WMOPS ) + multiCounter[currCounter].shr_r--; #endif /* ifdef WMOPS */ - } + } -#if (WMOPS) - multiCounter[currCounter].shl_r++; +#if ( WMOPS ) + multiCounter[currCounter].shl_r++; #endif /* ifdef WMOPS */ - return (var_out); + return ( var_out ); } #ifdef BASOP_NOGLOB -Word16 shl_r(Word16 var1, Word16 var2) { - return shl_ro(var1, var2, NULL); +Word16 shl_r( Word16 var1, Word16 var2 ) +{ + return shl_ro( var1, var2, NULL ); } #endif /***************************************************************************** @@ -402,10 +438,10 @@ Word16 shl_r(Word16 var1, Word16 var2) { * * Inputs : * - * L_var1 32 bit long signed integer (Word32) whose value falls in + * L_var1 32 bit long signed integer (Word32) whose value falls in * the range : 0x8000 0000 <= L_var1 <= 0x7fff ffff. * - * var2 16 bit short signed integer (Word16) whose value falls in + * var2 16 bit short signed integer (Word16) whose value falls in * the range : 0xffff 8000 <= var2 <= 0x0000 7fff. * * Outputs : @@ -414,34 +450,37 @@ Word16 shl_r(Word16 var1, Word16 var2) { * * Return Value : * - * L_var_out 32 bit long signed integer (Word32) whose value falls in + * L_var_out 32 bit long signed integer (Word32) whose value falls in * the range : 0x8000 0000 <= var_out <= 0x7fff ffff. * *****************************************************************************/ -Word32 L_shl_r (Word32 L_var1, Word16 var2) { - Word32 var_out; +Word32 L_shl_r( Word32 L_var1, Word16 var2 ) +{ + Word32 var_out; - if (var2 >= 0) { - var_out = L_shl (L_var1, var2); + if ( var2 >= 0 ) + { + var_out = L_shl( L_var1, var2 ); -#if (WMOPS) - multiCounter[currCounter].L_shl--; +#if ( WMOPS ) + multiCounter[currCounter].L_shl--; #endif /* ifdef WMOPS */ + } + else + { + var2 = -var2; + var_out = L_shr_r( L_var1, var2 ); - } else { - var2 = -var2; - var_out = L_shr_r (L_var1, var2); - -#if (WMOPS) - multiCounter[currCounter].L_shr_r--; +#if ( WMOPS ) + multiCounter[currCounter].L_shr_r--; #endif /* ifdef WMOPS */ - } + } -#if (WMOPS) - multiCounter[currCounter].L_shl_r++; +#if ( WMOPS ) + multiCounter[currCounter].L_shl_r++; #endif /* ifdef WMOPS */ - return (var_out); + return ( var_out ); } @@ -466,7 +505,7 @@ Word32 L_shl_r (Word32 L_var1, Word16 var2) { * * Outputs : * - * *var3 Points on a 16 bit short signed integer (Word16) whose + * *var3 Points on a 16 bit short signed integer (Word16) whose * value will be 0 or 1. * * Return Value : @@ -475,21 +514,22 @@ Word32 L_shl_r (Word32 L_var1, Word16 var2) { * the range : 0xffff 8000 <= var_out <= 0x0000 7fff. * *****************************************************************************/ -Word16 rotr (Word16 var1, Word16 var2, Word16 * var3) { - Word16 var_out; - - *var3 = s_and (var1, 0x1); - var_out = s_or (lshr (var1, 1), lshl (var2, 15)); - -#if (WMOPS) - multiCounter[currCounter].s_and--; - multiCounter[currCounter].lshl--; - multiCounter[currCounter].lshr--; - multiCounter[currCounter].s_or--; - multiCounter[currCounter].rotr++; +Word16 rotr( Word16 var1, Word16 var2, Word16 *var3 ) +{ + Word16 var_out; + + *var3 = s_and( var1, 0x1 ); + var_out = s_or( lshr( var1, 1 ), lshl( var2, 15 ) ); + +#if ( WMOPS ) + multiCounter[currCounter].s_and--; + multiCounter[currCounter].lshl--; + multiCounter[currCounter].lshr--; + multiCounter[currCounter].s_or--; + multiCounter[currCounter].rotr++; #endif /* ifdef WMOPS */ - return (var_out); + return ( var_out ); } @@ -514,7 +554,7 @@ Word16 rotr (Word16 var1, Word16 var2, Word16 * var3) { * * Outputs : * - * *var3 Points on a 16 bit short signed integer (Word16) whose + * *var3 Points on a 16 bit short signed integer (Word16) whose * value will be 0 or 1. * * Return Value : @@ -523,22 +563,23 @@ Word16 rotr (Word16 var1, Word16 var2, Word16 * var3) { * the range : 0xffff 8000 <= var_out <= 0x0000 7fff. * *****************************************************************************/ -Word16 rotl (Word16 var1, Word16 var2, Word16 * var3) { - Word16 var_out; +Word16 rotl( Word16 var1, Word16 var2, Word16 *var3 ) +{ + Word16 var_out; - *var3 = lshr (var1, 15); + *var3 = lshr( var1, 15 ); - var_out = s_or (lshl (var1, 1), s_and (var2, 0x1)); + var_out = s_or( lshl( var1, 1 ), s_and( var2, 0x1 ) ); -#if (WMOPS) - multiCounter[currCounter].lshr--; - multiCounter[currCounter].s_and--; - multiCounter[currCounter].lshl--; - multiCounter[currCounter].s_or--; - multiCounter[currCounter].rotl++; +#if ( WMOPS ) + multiCounter[currCounter].lshr--; + multiCounter[currCounter].s_and--; + multiCounter[currCounter].lshl--; + multiCounter[currCounter].s_or--; + multiCounter[currCounter].rotl++; #endif /* ifdef WMOPS */ - return (var_out); + return ( var_out ); } @@ -563,7 +604,7 @@ Word16 rotl (Word16 var1, Word16 var2, Word16 * var3) { * * Outputs : * - * *var3 Points on a 16 bit short signed integer (Word16) whose + * *var3 Points on a 16 bit short signed integer (Word16) whose * value will be 0 or 1. * * Return Value : @@ -572,24 +613,25 @@ Word16 rotl (Word16 var1, Word16 var2, Word16 * var3) { * the range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. * *****************************************************************************/ -Word32 L_rotr (Word32 L_var1, Word16 var2, Word16 * var3) { - Word32 L_var_out; +Word32 L_rotr( Word32 L_var1, Word16 var2, Word16 *var3 ) +{ + Word32 L_var_out; - *var3 = s_and (extract_l (L_var1), 0x1); + *var3 = s_and( extract_l( L_var1 ), 0x1 ); - L_var_out = L_or (L_lshr (L_var1, 1), L_lshl (L_deposit_l (var2), 31)); + L_var_out = L_or( L_lshr( L_var1, 1 ), L_lshl( L_deposit_l( var2 ), 31 ) ); -#if (WMOPS) - multiCounter[currCounter].extract_l--; - multiCounter[currCounter].s_and--; - multiCounter[currCounter].L_deposit_l--; - multiCounter[currCounter].L_lshl--; - multiCounter[currCounter].L_lshr--; - multiCounter[currCounter].L_or--; - multiCounter[currCounter].L_rotr++; +#if ( WMOPS ) + multiCounter[currCounter].extract_l--; + multiCounter[currCounter].s_and--; + multiCounter[currCounter].L_deposit_l--; + multiCounter[currCounter].L_lshl--; + multiCounter[currCounter].L_lshr--; + multiCounter[currCounter].L_or--; + multiCounter[currCounter].L_rotr++; #endif /* ifdef WMOPS */ - return (L_var_out); + return ( L_var_out ); } @@ -614,7 +656,7 @@ Word32 L_rotr (Word32 L_var1, Word16 var2, Word16 * var3) { * * Outputs : * - * *var3 Points on a 16 bit short signed integer (Word16) whose + * *var3 Points on a 16 bit short signed integer (Word16) whose * value will be 0 or 1. * * Return Value : @@ -623,55 +665,26 @@ Word32 L_rotr (Word32 L_var1, Word16 var2, Word16 * var3) { * the range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. * *****************************************************************************/ -Word32 L_rotl (Word32 L_var1, Word16 var2, Word16 * var3) { - Word32 L_var_out; +Word32 L_rotl( Word32 L_var1, Word16 var2, Word16 *var3 ) +{ + Word32 L_var_out; - *var3 = extract_l (L_lshr (L_var1, 31)); + *var3 = extract_l( L_lshr( L_var1, 31 ) ); - L_var_out = L_or (L_lshl (L_var1, 1), L_deposit_l (s_and (var2, 0x1))); + L_var_out = L_or( L_lshl( L_var1, 1 ), L_deposit_l( s_and( var2, 0x1 ) ) ); -#if (WMOPS) - multiCounter[currCounter].L_lshr--; - multiCounter[currCounter].extract_l--; - multiCounter[currCounter].s_and--; - multiCounter[currCounter].L_deposit_l--; - multiCounter[currCounter].L_lshl--; - multiCounter[currCounter].L_or--; - multiCounter[currCounter].L_rotl++; +#if ( WMOPS ) + multiCounter[currCounter].L_lshr--; + multiCounter[currCounter].extract_l--; + multiCounter[currCounter].s_and--; + multiCounter[currCounter].L_deposit_l--; + multiCounter[currCounter].L_lshl--; + multiCounter[currCounter].L_or--; + multiCounter[currCounter].L_rotl++; #endif /* ifdef WMOPS */ - return (L_var_out); + return ( L_var_out ); } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /* end of file */ diff --git a/lib_com/enh1632.h b/lib_com/enh1632.h index 1ac51dccb..2ef87cd64 100644 --- a/lib_com/enh1632.h +++ b/lib_com/enh1632.h @@ -9,13 +9,13 @@ History: 07 Nov 04 v2.0 Incorporation of new 32-bit / 40-bit / control - operators for the ITU-T Standard Tool Library as + operators for the ITU-T Standard Tool Library as described in Geneva, 20-30 January 2004 WP 3/16 Q10/16 TD 11 document and subsequent discussions on the wp3audio@yahoogroups.com email reflector. March 06 v2.1 Changed to improve portability. - Some counters incrementations were missing (s_and, - s_or, s_xor). + Some counters incrementations were missing (s_and, + s_or, s_xor). 30 Nov 09 v2.3 saturate() removed ============================================================================ @@ -36,7 +36,7 @@ #include "stl.h" -#if (WMOPS) +#if ( WMOPS ) #include "count.h" extern BASIC_OP multiCounter[MAXCOUNTERS]; extern int currCounter; @@ -49,22 +49,21 @@ extern int currCounter; * *****************************************************************************/ #ifdef BASOP_NOGLOB -Word16 shl_ro(Word16 var1, Word16 var2, Flag* Overflow); +Word16 shl_ro( Word16 var1, Word16 var2, Flag *Overflow ); #endif -Word16 shl_r (Word16 var1, Word16 var2); -Word32 L_shl_r (Word32 L_var1, Word16 var2); +Word16 shl_r( Word16 var1, Word16 var2 ); +Word32 L_shl_r( Word32 L_var1, Word16 var2 ); -Word16 lshl (Word16 var1, Word16 var2); -Word16 lshr (Word16 var1, Word16 var2); -Word32 L_lshl (Word32 L_var1, Word16 var2); -Word32 L_lshr (Word32 L_var1, Word16 var2); - -Word16 rotr (Word16 var1, Word16 var2, Word16 * var3); -Word16 rotl (Word16 var1, Word16 var2, Word16 * var3); -Word32 L_rotr (Word32 var1, Word16 var2, Word16 * var3); -Word32 L_rotl (Word32 var1, Word16 var2, Word16 * var3); +Word16 lshl( Word16 var1, Word16 var2 ); +Word16 lshr( Word16 var1, Word16 var2 ); +Word32 L_lshl( Word32 L_var1, Word16 var2 ); +Word32 L_lshr( Word32 L_var1, Word16 var2 ); +Word16 rotr( Word16 var1, Word16 var2, Word16 *var3 ); +Word16 rotl( Word16 var1, Word16 var2, Word16 *var3 ); +Word32 L_rotr( Word32 var1, Word16 var2, Word16 *var3 ); +Word32 L_rotl( Word32 var1, Word16 var2, Word16 *var3 ); /***************************************************************************** @@ -85,7 +84,7 @@ Word32 L_rotl (Word32 var1, Word16 var2, Word16 * var3); * * Inputs : * - * var1 16 bit short signed integer (Word16) whose value falls in + * var1 16 bit short signed integer (Word16) whose value falls in * the range : 0x8000 <= var1 <= 0x7fff. * * var2 16 bit short signed integer (Word16) whose value falls in @@ -101,19 +100,20 @@ Word32 L_rotl (Word32 var1, Word16 var2, Word16 * var3); * the range : 0x8000 <= L_var_out <= 0x7fff. * *****************************************************************************/ -static __inline Word16 s_max (Word16 var1, Word16 var2) { - Word16 var_out; +static __inline Word16 s_max( Word16 var1, Word16 var2 ) +{ + Word16 var_out; - if (var1 >= var2) - var_out = var1; - else - var_out = var2; + if ( var1 >= var2 ) + var_out = var1; + else + var_out = var2; -#if (WMOPS) - multiCounter[currCounter].s_max++; +#if ( WMOPS ) + multiCounter[currCounter].s_max++; #endif /* ifdef WMOPS */ - return (var_out); + return ( var_out ); } @@ -129,10 +129,10 @@ static __inline Word16 s_max (Word16 var1, Word16 var2) { * * Inputs : * - * var1 16 bit short signed integer (Word16) whose value falls in + * var1 16 bit short signed integer (Word16) whose value falls in * the range : 0x8000 <= var1 <= 0x7fff. * - * var2 16 bit short signed integer (Word16) whose value falls in + * var2 16 bit short signed integer (Word16) whose value falls in * the range : 0x8000 <= var2 <= 0x7fff. * * Outputs : @@ -141,23 +141,24 @@ static __inline Word16 s_max (Word16 var1, Word16 var2) { * * Return Value : * - * var_out 16 bit short signed integer (Word16) whose value falls in + * var_out 16 bit short signed integer (Word16) whose value falls in * the range : 0x8000 <= var_out <= 0x7fff. * *****************************************************************************/ -static __inline Word16 s_min (Word16 var1, Word16 var2) { - Word16 var_out; +static __inline Word16 s_min( Word16 var1, Word16 var2 ) +{ + Word16 var_out; - if (var1 <= var2) - var_out = var1; - else - var_out = var2; + if ( var1 <= var2 ) + var_out = var1; + else + var_out = var2; -#if (WMOPS) - multiCounter[currCounter].s_min++; +#if ( WMOPS ) + multiCounter[currCounter].s_min++; #endif /* ifdef WMOPS */ - return (var_out); + return ( var_out ); } @@ -189,19 +190,20 @@ static __inline Word16 s_min (Word16 var1, Word16 var2) { * range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. * *****************************************************************************/ -static __inline Word32 L_max (Word32 L_var1, Word32 L_var2) { - Word32 L_var_out; +static __inline Word32 L_max( Word32 L_var1, Word32 L_var2 ) +{ + Word32 L_var_out; - if (L_var1 >= L_var2) - L_var_out = L_var1; - else - L_var_out = L_var2; + if ( L_var1 >= L_var2 ) + L_var_out = L_var1; + else + L_var_out = L_var2; -#if (WMOPS) - multiCounter[currCounter].L_max++; +#if ( WMOPS ) + multiCounter[currCounter].L_max++; #endif /* ifdef WMOPS */ - return (L_var_out); + return ( L_var_out ); } @@ -233,30 +235,23 @@ static __inline Word32 L_max (Word32 L_var1, Word32 L_var2) { * range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. * *****************************************************************************/ -static __inline Word32 L_min (Word32 L_var1, Word32 L_var2) { - Word32 L_var_out; +static __inline Word32 L_min( Word32 L_var1, Word32 L_var2 ) +{ + Word32 L_var_out; - if (L_var1 <= L_var2) - L_var_out = L_var1; - else - L_var_out = L_var2; + if ( L_var1 <= L_var2 ) + L_var_out = L_var1; + else + L_var_out = L_var2; -#if (WMOPS) - multiCounter[currCounter].L_min++; +#if ( WMOPS ) + multiCounter[currCounter].L_min++; #endif /* ifdef WMOPS */ - return (L_var_out); + return ( L_var_out ); } - - - - - - - - /***************************************************************************** * * Function Name : s_and @@ -286,16 +281,17 @@ static __inline Word32 L_min (Word32 L_var1, Word32 L_var2) { * falls in the range 0xffff 8000 <= var_out <= 0x0000 7fff. * *****************************************************************************/ -static __inline Word16 s_and (Word16 var1, Word16 var2) { - Word16 var_out; +static __inline Word16 s_and( Word16 var1, Word16 var2 ) +{ + Word16 var_out; - var_out = var1 & var2; + var_out = var1 & var2; -#if (WMOPS) - multiCounter[currCounter].s_and++; +#if ( WMOPS ) + multiCounter[currCounter].s_and++; #endif /* ifdef WMOPS */ - return (var_out); + return ( var_out ); } @@ -328,16 +324,17 @@ static __inline Word16 s_and (Word16 var1, Word16 var2) { * falls in the range 0x8000 0000 <= L_var_out <= 0x7fff ffff. * *****************************************************************************/ -static __inline Word32 L_and (Word32 L_var1, Word32 L_var2) { - Word32 L_var_out; +static __inline Word32 L_and( Word32 L_var1, Word32 L_var2 ) +{ + Word32 L_var_out; - L_var_out = L_var1 & L_var2; + L_var_out = L_var1 & L_var2; -#if (WMOPS) - multiCounter[currCounter].L_and++; +#if ( WMOPS ) + multiCounter[currCounter].L_and++; #endif /* ifdef WMOPS */ - return (L_var_out); + return ( L_var_out ); } @@ -370,16 +367,17 @@ static __inline Word32 L_and (Word32 L_var1, Word32 L_var2) { * falls in the range 0xffff 8000 <= var_out <= 0x0000 7fff. * *****************************************************************************/ -static __inline Word16 s_or (Word16 var1, Word16 var2) { - Word16 var_out; +static __inline Word16 s_or( Word16 var1, Word16 var2 ) +{ + Word16 var_out; - var_out = var1 | var2; + var_out = var1 | var2; -#if (WMOPS) - multiCounter[currCounter].s_or++; +#if ( WMOPS ) + multiCounter[currCounter].s_or++; #endif /* ifdef WMOPS */ - return (var_out); + return ( var_out ); } @@ -412,17 +410,18 @@ static __inline Word16 s_or (Word16 var1, Word16 var2) { * falls in the range 0x8000 0000 <= L_var_out <= 0x7fff ffff. * *****************************************************************************/ -static __inline Word32 L_or (Word32 L_var1, Word32 L_var2) { +static __inline Word32 L_or( Word32 L_var1, Word32 L_var2 ) +{ - Word32 L_var_out; + Word32 L_var_out; - L_var_out = L_var1 | L_var2; + L_var_out = L_var1 | L_var2; -#if (WMOPS) - multiCounter[currCounter].L_or++; +#if ( WMOPS ) + multiCounter[currCounter].L_or++; #endif /* ifdef WMOPS */ - return (L_var_out); + return ( L_var_out ); } @@ -455,16 +454,17 @@ static __inline Word32 L_or (Word32 L_var1, Word32 L_var2) { * falls in the range 0xffff 8000 <= var_out <= 0x0000 7fff. * *****************************************************************************/ -static __inline Word16 s_xor (Word16 var1, Word16 var2) { - Word16 var_out; +static __inline Word16 s_xor( Word16 var1, Word16 var2 ) +{ + Word16 var_out; - var_out = var1 ^ var2; + var_out = var1 ^ var2; -#if (WMOPS) - multiCounter[currCounter].s_xor++; +#if ( WMOPS ) + multiCounter[currCounter].s_xor++; #endif /* ifdef WMOPS */ - return (var_out); + return ( var_out ); } @@ -497,52 +497,20 @@ static __inline Word16 s_xor (Word16 var1, Word16 var2) { * falls in the range 0x8000 0000 <= L_var_out <= 0x7fff ffff. * *****************************************************************************/ -static __inline Word32 L_xor (Word32 L_var1, Word32 L_var2) { - Word32 L_var_out; +static __inline Word32 L_xor( Word32 L_var1, Word32 L_var2 ) +{ + Word32 L_var_out; - L_var_out = L_var1 ^ L_var2; + L_var_out = L_var1 ^ L_var2; -#if (WMOPS) - multiCounter[currCounter].L_xor++; +#if ( WMOPS ) + multiCounter[currCounter].L_xor++; #endif /* ifdef WMOPS */ - return (L_var_out); + return ( L_var_out ); } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #endif /*_ENH1632_H*/ /* end of file */ diff --git a/lib_com/enh32.c b/lib_com/enh32.c index 9015fc1be..3fb1148fc 100644 --- a/lib_com/enh32.c +++ b/lib_com/enh32.c @@ -23,7 +23,7 @@ #include #include "enh32.h" -#if (WMOPS) +#if ( WMOPS ) extern BASIC_OP multiCounter[MAXCOUNTERS]; extern int currCounter; #endif /* if WMOPS */ @@ -34,7 +34,7 @@ extern int currCounter; * Local Functions * *****************************************************************************/ - + /***************************************************************************** * * Constants and Globals @@ -48,189 +48,201 @@ extern int currCounter; * *****************************************************************************/ -Word32 Mpy_32_16_1 (Word32 L_var1, Word16 var2) { - Word32 L_var_out = W_sat_m (W_mult_32_16 (L_var1, var2) ); -#if (WMOPS) - multiCounter[currCounter].Mpy_32_16_1++; - multiCounter[currCounter].W_mult_32_16--; - multiCounter[currCounter].W_sat_m--; -#endif /* if WMOPS */ +Word32 Mpy_32_16_1( Word32 L_var1, Word16 var2 ) +{ + Word32 L_var_out = W_sat_m( W_mult_32_16( L_var1, var2 ) ); +#if ( WMOPS ) + multiCounter[currCounter].Mpy_32_16_1++; + multiCounter[currCounter].W_mult_32_16--; + multiCounter[currCounter].W_sat_m--; +#endif /* if WMOPS */ return L_var_out; } -Word32 Mpy_32_16_r (Word32 L_var1, Word16 var2) { - Word32 L_var_out = W_round48_L (W_mult_32_16 (L_var1, var2 ) ); -#if (WMOPS) - multiCounter[currCounter].Mpy_32_16_r++; - multiCounter[currCounter].W_mult_32_16--; - multiCounter[currCounter].W_round48_L--; -#endif /* if WMOPS */ - return L_var_out; +Word32 Mpy_32_16_r( Word32 L_var1, Word16 var2 ) +{ + Word32 L_var_out = W_round48_L( W_mult_32_16( L_var1, var2 ) ); +#if ( WMOPS ) + multiCounter[currCounter].Mpy_32_16_r++; + multiCounter[currCounter].W_mult_32_16--; + multiCounter[currCounter].W_round48_L--; +#endif /* if WMOPS */ + return L_var_out; } -Word32 Mpy_32_32 (Word32 L_var1, Word32 L_var2) { - Word32 L_var_out; - Word64 L64_var1; +Word32 Mpy_32_32( Word32 L_var1, Word32 L_var2 ) +{ + Word32 L_var_out; + Word64 L64_var1; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - L64_var1 = ((Word64)L_var1 * L_var2); + L64_var1 = ( (Word64) L_var1 * L_var2 ); #ifdef BASOP_NOGLOB - L64_var1 = W_shl_o (L64_var1, 1, &Overflow); -#else /* BASOP_NOGLOB */ - L64_var1 = W_shl (L64_var1, 1); + L64_var1 = W_shl_o( L64_var1, 1, &Overflow ); +#else /* BASOP_NOGLOB */ + L64_var1 = W_shl( L64_var1, 1 ); #endif /* BASOP_NOGLOB */ - L_var_out = W_extract_h (L64_var1 ); -#if (WMOPS) + L_var_out = W_extract_h( L64_var1 ); +#if ( WMOPS ) multiCounter[currCounter].Mpy_32_32++; - multiCounter[currCounter].W_shl--; - multiCounter[currCounter].W_extract_h--; -#endif /* if WMOPS */ + multiCounter[currCounter].W_shl--; + multiCounter[currCounter].W_extract_h--; +#endif /* if WMOPS */ return L_var_out; } -Word32 Mpy_32_32_r (Word32 L_var1, Word32 L_var2) { - Word32 L_var_out; - Word64 L64_var1; +Word32 Mpy_32_32_r( Word32 L_var1, Word32 L_var2 ) +{ + Word32 L_var_out; + Word64 L64_var1; - L64_var1 = ((Word64) L_var1 * L_var2); - L64_var1 = W_shr (L64_var1, 15); - L_var_out = W_round48_L (L64_var1 ); -#if (WMOPS) + L64_var1 = ( (Word64) L_var1 * L_var2 ); + L64_var1 = W_shr( L64_var1, 15 ); + L_var_out = W_round48_L( L64_var1 ); +#if ( WMOPS ) multiCounter[currCounter].Mpy_32_32_r++; - multiCounter[currCounter].W_shr--; - multiCounter[currCounter].W_round48_L--; -#endif /* if WMOPS */ + multiCounter[currCounter].W_shr--; + multiCounter[currCounter].W_round48_L--; +#endif /* if WMOPS */ return L_var_out; } -Word32 Madd_32_16 (Word32 L_var3, Word32 L_var1, Word16 var2) { - Word32 L_var_out; +Word32 Madd_32_16( Word32 L_var3, Word32 L_var1, Word16 var2 ) +{ + Word32 L_var_out; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - L_var_out = Mpy_32_16_1 (L_var1, var2); + L_var_out = Mpy_32_16_1( L_var1, var2 ); #ifdef BASOP_NOGLOB - L_var_out = L_add_o (L_var3, L_var_out, &Overflow); -#else /* BASOP_NOGLOB */ - L_var_out = L_add (L_var3, L_var_out); + L_var_out = L_add_o( L_var3, L_var_out, &Overflow ); +#else /* BASOP_NOGLOB */ + L_var_out = L_add( L_var3, L_var_out ); #endif /* BASOP_NOGLOB */ - -#if (WMOPS) - multiCounter[currCounter].Mpy_32_16_1--; - multiCounter[currCounter].L_add--; - multiCounter[currCounter].Madd_32_16++; -#endif /* if WMOPS */ - return L_var_out; + +#if ( WMOPS ) + multiCounter[currCounter].Mpy_32_16_1--; + multiCounter[currCounter].L_add--; + multiCounter[currCounter].Madd_32_16++; +#endif /* if WMOPS */ + return L_var_out; } -Word32 Madd_32_16_r (Word32 L_var3, Word32 L_var1, Word16 var2) { - Word32 L_var_out; - - L_var_out = Mpy_32_16_r (L_var1, var2); - L_var_out = L_add (L_var3, L_var_out); - -#if (WMOPS) - multiCounter[currCounter].Mpy_32_16_r--; - multiCounter[currCounter].L_add--; - multiCounter[currCounter].Madd_32_16_r++; -#endif /* if WMOPS */ +Word32 Madd_32_16_r( Word32 L_var3, Word32 L_var1, Word16 var2 ) +{ + Word32 L_var_out; + + L_var_out = Mpy_32_16_r( L_var1, var2 ); + L_var_out = L_add( L_var3, L_var_out ); + +#if ( WMOPS ) + multiCounter[currCounter].Mpy_32_16_r--; + multiCounter[currCounter].L_add--; + multiCounter[currCounter].Madd_32_16_r++; +#endif /* if WMOPS */ return L_var_out; } -Word32 Msub_32_16 (Word32 L_var3, Word32 L_var1, Word16 var2) { - Word32 L_var_out; +Word32 Msub_32_16( Word32 L_var3, Word32 L_var1, Word16 var2 ) +{ + Word32 L_var_out; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - L_var_out = Mpy_32_16_1 (L_var1, var2); + L_var_out = Mpy_32_16_1( L_var1, var2 ); #ifdef BASOP_NOGLOB - L_var_out = L_sub_o(L_var3, L_var_out, &Overflow); + L_var_out = L_sub_o( L_var3, L_var_out, &Overflow ); #else /* BASOP_NOGLOB */ - L_var_out = L_sub(L_var3, L_var_out); + L_var_out = L_sub( L_var3, L_var_out ); #endif - -#if (WMOPS) - multiCounter[currCounter].Mpy_32_16_1--; - multiCounter[currCounter].L_sub--; - multiCounter[currCounter].Msub_32_16++; -#endif /* if WMOPS */ - return L_var_out; + +#if ( WMOPS ) + multiCounter[currCounter].Mpy_32_16_1--; + multiCounter[currCounter].L_sub--; + multiCounter[currCounter].Msub_32_16++; +#endif /* if WMOPS */ + return L_var_out; } -Word32 Msub_32_16_r (Word32 L_var3, Word32 L_var1, Word16 var2) { - Word32 L_var_out; - - L_var_out = Mpy_32_16_r (L_var1, var2); - L_var_out = L_sub (L_var3, L_var_out); - -#if (WMOPS) - multiCounter[currCounter].Mpy_32_16_r--; - multiCounter[currCounter].L_sub--; - multiCounter[currCounter].Msub_32_16_r++; -#endif /* if WMOPS */ - return L_var_out; +Word32 Msub_32_16_r( Word32 L_var3, Word32 L_var1, Word16 var2 ) +{ + Word32 L_var_out; + + L_var_out = Mpy_32_16_r( L_var1, var2 ); + L_var_out = L_sub( L_var3, L_var_out ); + +#if ( WMOPS ) + multiCounter[currCounter].Mpy_32_16_r--; + multiCounter[currCounter].L_sub--; + multiCounter[currCounter].Msub_32_16_r++; +#endif /* if WMOPS */ + return L_var_out; } -Word32 Madd_32_32 (Word32 L_var3, Word32 L_var1, Word32 L_var2) { - Word32 L_var_out; - - L_var_out = Mpy_32_32 (L_var1, L_var2); - L_var_out = L_add (L_var3, L_var_out); - -#if (WMOPS) - multiCounter[currCounter].Mpy_32_32--; - multiCounter[currCounter].L_add--; - multiCounter[currCounter].Madd_32_32++; -#endif /* if WMOPS */ - return L_var_out; +Word32 Madd_32_32( Word32 L_var3, Word32 L_var1, Word32 L_var2 ) +{ + Word32 L_var_out; + + L_var_out = Mpy_32_32( L_var1, L_var2 ); + L_var_out = L_add( L_var3, L_var_out ); + +#if ( WMOPS ) + multiCounter[currCounter].Mpy_32_32--; + multiCounter[currCounter].L_add--; + multiCounter[currCounter].Madd_32_32++; +#endif /* if WMOPS */ + return L_var_out; } -Word32 Madd_32_32_r (Word32 L_var3, Word32 L_var1, Word32 L_var2) { - Word32 L_var_out; - - L_var_out = Mpy_32_32_r (L_var1, L_var2); - L_var_out = L_add (L_var3, L_var_out); - -#if (WMOPS) - multiCounter[currCounter].Mpy_32_32_r--; - multiCounter[currCounter].L_add--; - multiCounter[currCounter].Madd_32_32_r++; -#endif /* if WMOPS */ - return L_var_out; +Word32 Madd_32_32_r( Word32 L_var3, Word32 L_var1, Word32 L_var2 ) +{ + Word32 L_var_out; + + L_var_out = Mpy_32_32_r( L_var1, L_var2 ); + L_var_out = L_add( L_var3, L_var_out ); + +#if ( WMOPS ) + multiCounter[currCounter].Mpy_32_32_r--; + multiCounter[currCounter].L_add--; + multiCounter[currCounter].Madd_32_32_r++; +#endif /* if WMOPS */ + return L_var_out; } -Word32 Msub_32_32 (Word32 L_var3, Word32 L_var1, Word32 L_var2) { - Word32 L_var_out; - - L_var_out = Mpy_32_32 (L_var1, L_var2); - L_var_out = L_sub (L_var3, L_var_out); - -#if (WMOPS) - multiCounter[currCounter].Mpy_32_32--; - multiCounter[currCounter].L_sub--; - multiCounter[currCounter].Msub_32_32++; -#endif /* if WMOPS */ - return L_var_out; +Word32 Msub_32_32( Word32 L_var3, Word32 L_var1, Word32 L_var2 ) +{ + Word32 L_var_out; + + L_var_out = Mpy_32_32( L_var1, L_var2 ); + L_var_out = L_sub( L_var3, L_var_out ); + +#if ( WMOPS ) + multiCounter[currCounter].Mpy_32_32--; + multiCounter[currCounter].L_sub--; + multiCounter[currCounter].Msub_32_32++; +#endif /* if WMOPS */ + return L_var_out; } -Word32 Msub_32_32_r (Word32 L_var3, Word32 L_var1, Word32 L_var2) { - Word32 L_var_out; - - L_var_out = Mpy_32_32_r (L_var1, L_var2); - L_var_out = L_sub (L_var3, L_var_out); - -#if (WMOPS) - multiCounter[currCounter].Mpy_32_32_r--; - multiCounter[currCounter].L_sub--; - multiCounter[currCounter].Msub_32_32_r++; -#endif /* if WMOPS */ - return L_var_out; +Word32 Msub_32_32_r( Word32 L_var3, Word32 L_var1, Word32 L_var2 ) +{ + Word32 L_var_out; + + L_var_out = Mpy_32_32_r( L_var1, L_var2 ); + L_var_out = L_sub( L_var3, L_var_out ); + +#if ( WMOPS ) + multiCounter[currCounter].Mpy_32_32_r--; + multiCounter[currCounter].L_sub--; + multiCounter[currCounter].Msub_32_32_r++; +#endif /* if WMOPS */ + return L_var_out; } #endif /* #ifdef ENH_32_BIT_OPERATOR */ - + /* end of file */ diff --git a/lib_com/enh32.h b/lib_com/enh32.h index a6e220c95..1d275cdd2 100644 --- a/lib_com/enh32.h +++ b/lib_com/enh32.h @@ -3,30 +3,30 @@ #define _ENH32_H #include "stl.h" - -#ifndef Word64 + +#ifndef Word64 #define Word64 long long int #endif - /***************************************************************************** +/***************************************************************************** * * Prototypes for enhanced 32 bit arithmetic operators * *****************************************************************************/ #ifdef ENH_32_BIT_OPERATOR -Word32 Mpy_32_16_1 (Word32 L_var1, Word16 var2); -Word32 Mpy_32_16_r (Word32 L_var1, Word16 var2); -Word32 Mpy_32_32 (Word32 L_var1, Word32 L_var2); -Word32 Mpy_32_32_r (Word32 L_var1, Word32 L_var2); -Word32 Madd_32_16 (Word32 L_var3, Word32 L_var1, Word16 var2); -Word32 Madd_32_16_r (Word32 L_var3, Word32 L_var1, Word16 var2); -Word32 Msub_32_16 (Word32 L_var3, Word32 L_var1, Word16 var2); -Word32 Msub_32_16_r (Word32 L_var3, Word32 L_var1, Word16 var2); -Word32 Madd_32_32 (Word32 L_var3, Word32 L_var1, Word32 L_var2); -Word32 Madd_32_32_r (Word32 L_var3, Word32 L_var1, Word32 L_var2); -Word32 Msub_32_32 (Word32 L_var3, Word32 L_var1, Word32 L_var2); -Word32 Msub_32_32_r (Word32 L_var3, Word32 L_var1, Word32 L_var2); +Word32 Mpy_32_16_1( Word32 L_var1, Word16 var2 ); +Word32 Mpy_32_16_r( Word32 L_var1, Word16 var2 ); +Word32 Mpy_32_32( Word32 L_var1, Word32 L_var2 ); +Word32 Mpy_32_32_r( Word32 L_var1, Word32 L_var2 ); +Word32 Madd_32_16( Word32 L_var3, Word32 L_var1, Word16 var2 ); +Word32 Madd_32_16_r( Word32 L_var3, Word32 L_var1, Word16 var2 ); +Word32 Msub_32_16( Word32 L_var3, Word32 L_var1, Word16 var2 ); +Word32 Msub_32_16_r( Word32 L_var3, Word32 L_var1, Word16 var2 ); +Word32 Madd_32_32( Word32 L_var3, Word32 L_var1, Word32 L_var2 ); +Word32 Madd_32_32_r( Word32 L_var3, Word32 L_var1, Word32 L_var2 ); +Word32 Msub_32_32( Word32 L_var3, Word32 L_var1, Word32 L_var2 ); +Word32 Msub_32_32_r( Word32 L_var3, Word32 L_var1, Word32 L_var2 ); #endif /* #ifdef ENH_32_BIT_OPERATOR */ @@ -34,5 +34,3 @@ Word32 Msub_32_32_r (Word32 L_var3, Word32 L_var1, Word32 L_var2); /* end of file */ - - diff --git a/lib_com/enh64.c b/lib_com/enh64.c index db1c8ee64..f0b804076 100644 --- a/lib_com/enh64.c +++ b/lib_com/enh64.c @@ -1,47 +1,47 @@ /***************************************************************************** -* -* Enhanced 64 bit operators : -* -* W_mac_32_16() -* W_mac0_16_16() -* W_msu0_16_16() -* -*****************************************************************************/ + * + * Enhanced 64 bit operators : + * + * W_mac_32_16() + * W_mac0_16_16() + * W_msu0_16_16() + * + *****************************************************************************/ /***************************************************************************** -* -* Include-Files -* -*****************************************************************************/ + * + * Include-Files + * + *****************************************************************************/ #include #include #include "enh64.h" -#if (WMOPS) +#if ( WMOPS ) extern BASIC_OP multiCounter[MAXCOUNTERS]; extern int currCounter; #endif /* if WMOPS */ /***************************************************************************** -* -* Local Functions -* -*****************************************************************************/ + * + * Local Functions + * + *****************************************************************************/ /***************************************************************************** -* -* Constants and Globals -* -*****************************************************************************/ + * + * Constants and Globals + * + *****************************************************************************/ /***************************************************************************** -* -* Functions -* -*****************************************************************************/ + * + * Functions + * + *****************************************************************************/ #ifdef ENH_64_BIT_OPERATOR @@ -75,16 +75,17 @@ extern int currCounter; | range : 0x80000000 00000000LL <= L64_var1 <= 0x7fffffff ffffffffLL. | |___________________________________________________________________________| */ -Word64 W_add_nosat (Word64 L64_var1, Word64 L64_var2) { - Word64 L64_var_out; - - L64_var_out = L64_var1 + L64_var2; +Word64 W_add_nosat( Word64 L64_var1, Word64 L64_var2 ) +{ + Word64 L64_var_out; + + L64_var_out = L64_var1 + L64_var2; -#if (WMOPS) - multiCounter[currCounter].W_add_nosat++; +#if ( WMOPS ) + multiCounter[currCounter].W_add_nosat++; #endif - - return L64_var_out; + + return L64_var_out; } @@ -117,16 +118,17 @@ Word64 W_add_nosat (Word64 L64_var1, Word64 L64_var2) { | range : 0x80000000 00000000LL <= L64_var1 <= 0x7fffffff ffffffffLL. | |___________________________________________________________________________| */ -Word64 W_sub_nosat (Word64 L64_var1, Word64 L64_var2) { - Word64 L64_var_out; - - L64_var_out = L64_var1 - L64_var2; +Word64 W_sub_nosat( Word64 L64_var1, Word64 L64_var2 ) +{ + Word64 L64_var_out; -#if (WMOPS) - multiCounter[currCounter].W_sub_nosat++; + L64_var_out = L64_var1 - L64_var2; + +#if ( WMOPS ) + multiCounter[currCounter].W_sub_nosat++; #endif - - return L64_var_out; + + return L64_var_out; } @@ -164,57 +166,66 @@ Word64 W_sub_nosat (Word64 L64_var1, Word64 L64_var2) { |___________________________________________________________________________| */ #ifdef BASOP_NOGLOB -Word64 W_shl_o (Word64 L64_var1, Word16 var2, Flag* Overflow) { -#else /* BASOP_NOGLOB */ -Word64 W_shl (Word64 L64_var1, Word16 var2) { +Word64 W_shl_o( Word64 L64_var1, Word16 var2, Flag *Overflow ) +{ +#else /* BASOP_NOGLOB */ +Word64 W_shl( Word64 L64_var1, Word16 var2 ) +{ #endif /* BASOP_NOGLOB */ - - Word64 L64_var_out = 0LL; - - if (var2 <= 0) { - if (var2 < -64) - var2 = -64; - var2 = -var2; - L64_var_out = L64_var1 >> var2; - } - else { - for (; var2 > 0; var2--) { - if (L64_var1 > (Word64) 0X3fffffffffffffffLL) { + + Word64 L64_var_out = 0LL; + + if ( var2 <= 0 ) + { + if ( var2 < -64 ) + var2 = -64; + var2 = -var2; + L64_var_out = L64_var1 >> var2; + } + else + { + for ( ; var2 > 0; var2-- ) + { + if ( L64_var1 > (Word64) 0X3fffffffffffffffLL ) + { #ifdef BASOP_NOGLOB - set_overflow(Overflow); -#else /* BASOP_NOGLOB */ - Overflow = 1; + set_overflow( Overflow ); +#else /* BASOP_NOGLOB */ + Overflow = 1; #endif /* BASOP_NOGLOB */ - L64_var_out = (Word64) 0X7fffffffffffffffLL; - break; - } - else { - if (L64_var1 < (Word64) 0xc000000000000000LL) { + L64_var_out = (Word64) 0X7fffffffffffffffLL; + break; + } + else + { + if ( L64_var1 < (Word64) 0xc000000000000000LL ) + { #ifdef BASOP_NOGLOB - set_overflow(Overflow); -#else /* BASOP_NOGLOB */ - Overflow = 1; + set_overflow( Overflow ); +#else /* BASOP_NOGLOB */ + Overflow = 1; #endif /* BASOP_NOGLOB */ - L64_var_out = (Word64)0x8000000000000000LL; - break; - } - } - L64_var1 *= 2; - L64_var_out = L64_var1; - } - } -#if (WMOPS) - multiCounter[currCounter].W_shl++; + L64_var_out = (Word64) 0x8000000000000000LL; + break; + } + } + L64_var1 *= 2; + L64_var_out = L64_var1; + } + } +#if ( WMOPS ) + multiCounter[currCounter].W_shl++; #endif - -/* BASOP_CHECK();*/ - - return (L64_var_out); + + /* BASOP_CHECK();*/ + + return ( L64_var_out ); } #ifdef BASOP_NOGLOB -Word64 W_shl (Word64 L64_var1, Word16 var2) { - return W_shl_o(L64_var1, var2, NULL); +Word64 W_shl( Word64 L64_var1, Word16 var2 ) +{ + return W_shl_o( L64_var1, var2, NULL ); } #endif /* BASOP_NOGLOB */ @@ -252,26 +263,29 @@ Word64 W_shl (Word64 L64_var1, Word16 var2) { | range : 0x80000000 00000000LL <= L64_var1 <= 0x7fffffff ffffffffLL. | |___________________________________________________________________________| */ -Word64 W_shr (Word64 L64_var1, Word16 var2) { - Word64 L64_var_out; - - if (var2 < 0) { - var2 = -var2; - L64_var_out = W_shl (L64_var1, var2); - -#if (WMOPS) - multiCounter[currCounter].W_shl--; +Word64 W_shr( Word64 L64_var1, Word16 var2 ) +{ + Word64 L64_var_out; + + if ( var2 < 0 ) + { + var2 = -var2; + L64_var_out = W_shl( L64_var1, var2 ); + +#if ( WMOPS ) + multiCounter[currCounter].W_shl--; #endif /* if WMOPS */ - - } else { - L64_var_out = L64_var1 >> var2; - } + } + else + { + L64_var_out = L64_var1 >> var2; + } -#if (WMOPS) - multiCounter[currCounter].W_shr++; +#if ( WMOPS ) + multiCounter[currCounter].W_shr++; #endif /* if WMOPS */ - - return (L64_var_out); + + return ( L64_var_out ); } @@ -282,9 +296,9 @@ Word64 W_shr (Word64 L64_var1, Word16 var2) { | Purpose : | | | | Arithmetically shifts left the 64-bit variable W_var1 by var2 positions. | -| if var2 is negative, W_var1 is shifted to the least significant bits by | +| if var2 is negative, W_var1 is shifted to the least significant bits by | | (�var2) positions with extension of the sign bit . | -| if var2 is positive, W_var1 is shifted to the most significant bits by | +| if var2 is positive, W_var1 is shifted to the most significant bits by | | (var2) positions without saturation control on 64 bits. | | | | Complexity weight : 1 | @@ -309,24 +323,27 @@ Word64 W_shr (Word64 L64_var1, Word16 var2) { | range : 0x80000000 00000000LL <= L64_var1 <= 0x7fffffff ffffffffLL. | |___________________________________________________________________________| */ -Word64 W_shl_nosat (Word64 L64_var1, Word16 var2) { - - Word64 L64_var_out = 0LL; - - if (var2 <= 0) { - var2 = -var2; - L64_var_out = L64_var1 >> var2; - } - else { - L64_var_out = L64_var1 << var2; - } -#if (WMOPS) - multiCounter[currCounter].W_shl_nosat++; +Word64 W_shl_nosat( Word64 L64_var1, Word16 var2 ) +{ + + Word64 L64_var_out = 0LL; + + if ( var2 <= 0 ) + { + var2 = -var2; + L64_var_out = L64_var1 >> var2; + } + else + { + L64_var_out = L64_var1 << var2; + } +#if ( WMOPS ) + multiCounter[currCounter].W_shl_nosat++; #endif - -/* BASOP_CHECK();*/ - - return (L64_var_out); + + /* BASOP_CHECK();*/ + + return ( L64_var_out ); } @@ -337,9 +354,9 @@ Word64 W_shl_nosat (Word64 L64_var1, Word16 var2) { | Purpose : | | | | Arithmetically shifts right the 64-bit variable W_var1 by var2 positions. | -| if var2 is negative, W_var1 is shifted to the most significant bits by | +| if var2 is negative, W_var1 is shifted to the most significant bits by | | (�var2) positions without saturation control on 64 bits. | -| if var2 is positive, W_var1 is shifted to the least significant bits by | +| if var2 is positive, W_var1 is shifted to the least significant bits by | | (var2) positions with extension of the sign bit . | | | | Complexity weight : 1 | @@ -364,22 +381,25 @@ Word64 W_shl_nosat (Word64 L64_var1, Word16 var2) { | range : 0x80000000 00000000LL <= L64_var1 <= 0x7fffffff ffffffffLL. | |___________________________________________________________________________| */ -Word64 W_shr_nosat (Word64 L64_var1, Word16 var2) { - Word64 L64_var_out; - - if (var2 < 0) { - var2 = -var2; - L64_var_out = L64_var1 << var2; - - } else { - L64_var_out = L64_var1 >> var2; - } - -#if (WMOPS) - multiCounter[currCounter].W_shr_nosat++; +Word64 W_shr_nosat( Word64 L64_var1, Word16 var2 ) +{ + Word64 L64_var_out; + + if ( var2 < 0 ) + { + var2 = -var2; + L64_var_out = L64_var1 << var2; + } + else + { + L64_var_out = L64_var1 >> var2; + } + +#if ( WMOPS ) + multiCounter[currCounter].W_shr_nosat++; #endif /* if WMOPS */ - - return (L64_var_out); + + return ( L64_var_out ); } @@ -419,14 +439,15 @@ Word64 W_shr_nosat (Word64 L64_var1, Word16 var2) { | range : 0x80000000 00000000LL <= L64_var_out <= 0x7fffffff ffffffffLL. | |_________________________________________________________________________________________________| */ -Word64 W_mac_32_16 (Word64 L64_var1, Word32 L_var2, Word16 var3) { - Word64 L64_var_out = ((Word64) L_var2*var3) << 1; - L64_var_out += L64_var1; -#if (WMOPS) - multiCounter[currCounter].W_mac_32_16++; -#endif /* if WMOPS */ - return L64_var_out; -} +Word64 W_mac_32_16( Word64 L64_var1, Word32 L_var2, Word16 var3 ) +{ + Word64 L64_var_out = ( (Word64) L_var2 * var3 ) << 1; + L64_var_out += L64_var1; +#if ( WMOPS ) + multiCounter[currCounter].W_mac_32_16++; +#endif /* if WMOPS */ + return L64_var_out; +} /*_________________________________________________________________________________________________ @@ -465,14 +486,15 @@ Word64 W_mac_32_16 (Word64 L64_var1, Word32 L_var2, Word16 var3) { | range : 0x80000000 00000000LL <= L64_var_out <= 0x7fffffff ffffffffLL. | |_________________________________________________________________________________________________| */ -Word64 W_msu_32_16(Word64 L64_var1, Word32 L_var2, Word16 var3) { - Word64 L64_var_out = ((Word64 )L_var2*var3) << 1; - L64_var_out = L64_var1 - L64_var_out; -#if (WMOPS) - multiCounter[currCounter].W_msu_32_16++; +Word64 W_msu_32_16( Word64 L64_var1, Word32 L_var2, Word16 var3 ) +{ + Word64 L64_var_out = ( (Word64) L_var2 * var3 ) << 1; + L64_var_out = L64_var1 - L64_var_out; +#if ( WMOPS ) + multiCounter[currCounter].W_msu_32_16++; #endif /* if WMOPS */ - return L64_var_out; -} + return L64_var_out; +} /*_________________________________________________________________________________________________ @@ -506,13 +528,14 @@ Word64 W_msu_32_16(Word64 L64_var1, Word32 L_var2, Word16 var3) { | range : 0x80000000 00000000LL <= L64_var_out <= 0x7fffffff ffffffffLL. | |_________________________________________________________________________________________________| */ -Word64 W_mult_32_16(Word32 L_var1, Word16 var2) { - Word64 L64_var_out = ((Word64 )L_var1*var2) << 1; -#if (WMOPS) - multiCounter[currCounter].W_mult_32_16++; +Word64 W_mult_32_16( Word32 L_var1, Word16 var2 ) +{ + Word64 L64_var_out = ( (Word64) L_var1 * var2 ) << 1; +#if ( WMOPS ) + multiCounter[currCounter].W_mult_32_16++; #endif /* if WMOPS */ - return L64_var_out; -} + return L64_var_out; +} /*________________________________________________________________________________________________ | | @@ -545,13 +568,14 @@ Word64 W_mult_32_16(Word32 L_var1, Word16 var2) { | range : 0x80000000 00000000LL <= L64_acc <= 0x7fffffff ffffffffLL. | |_________________________________________________________________________________________________| */ -Word64 W_mult0_16_16(Word16 var1, Word16 var2) { - Word64 L64_var_out = (Word64 )var1*var2; -#if (WMOPS) - multiCounter[currCounter].W_mult0_16_16++; +Word64 W_mult0_16_16( Word16 var1, Word16 var2 ) +{ + Word64 L64_var_out = (Word64) var1 * var2; +#if ( WMOPS ) + multiCounter[currCounter].W_mult0_16_16++; #endif /* if WMOPS */ - return L64_var_out; -} + return L64_var_out; +} /*________________________________________________________________________________________________ | | @@ -588,14 +612,15 @@ Word64 W_mult0_16_16(Word16 var1, Word16 var2) { | range : 0x80000000 00000000LL <= L64_var_out <= 0x7fffffff ffffffffLL. | |_________________________________________________________________________________________________| */ -Word64 W_mac0_16_16(Word64 L64_var1, Word16 var2, Word16 var3) { - Word64 L64_var_out = (Word64 )var2*var3; - L64_var_out += L64_var1; -#if (WMOPS) - multiCounter[currCounter].W_mac0_16_16++; +Word64 W_mac0_16_16( Word64 L64_var1, Word16 var2, Word16 var3 ) +{ + Word64 L64_var_out = (Word64) var2 * var3; + L64_var_out += L64_var1; +#if ( WMOPS ) + multiCounter[currCounter].W_mac0_16_16++; #endif /* if WMOPS */ - return L64_var_out; -} + return L64_var_out; +} /*________________________________________________________________________________________________ @@ -633,20 +658,20 @@ Word64 W_mac0_16_16(Word64 L64_var1, Word16 var2, Word16 var3) { | range : 0x80000000 00000000LL <= L64_var_out <= 0x7fffffff ffffffffLL. | |_________________________________________________________________________________________________| */ -Word64 W_msu0_16_16 (Word64 L64_var1, Word16 var2, Word16 var3) { - Word64 L64_var_out = (Word64) var2*var3; - L64_var_out = L64_var1 - L64_var_out; -#if (WMOPS) - multiCounter[currCounter].W_msu0_16_16++; +Word64 W_msu0_16_16( Word64 L64_var1, Word16 var2, Word16 var3 ) +{ + Word64 L64_var_out = (Word64) var2 * var3; + L64_var_out = L64_var1 - L64_var_out; +#if ( WMOPS ) + multiCounter[currCounter].W_msu0_16_16++; #endif /* if WMOPS */ - return L64_var_out; -} - + return L64_var_out; +} /*_____________________________________________________________________________________ | | -| Function Name : W_sat_l | +| Function Name : W_sat_l | | | | Purpose : | | | @@ -671,31 +696,34 @@ Word64 W_msu0_16_16 (Word64 L64_var1, Word16 var2, Word16 var3) { | range : 0x8000 0000 <= L_var_out <= 0x7fff 0000. | |_____________________________________________________________________________________| */ -Word32 W_sat_l (Word64 L64_var) { - Word32 L_var_out; - - if (L64_var > 0x7FFFFFFF) { - L_var_out = 0x7FFFFFFF; - } - else if (L64_var < (int)0x80000000) { - L_var_out = 0x80000000; - } - else { - L_var_out = (Word32)L64_var; - } - -#if (WMOPS) - multiCounter[currCounter].W_sat_l++; +Word32 W_sat_l( Word64 L64_var ) +{ + Word32 L_var_out; + + if ( L64_var > 0x7FFFFFFF ) + { + L_var_out = 0x7FFFFFFF; + } + else if ( L64_var < (int) 0x80000000 ) + { + L_var_out = 0x80000000; + } + else + { + L_var_out = (Word32) L64_var; + } + +#if ( WMOPS ) + multiCounter[currCounter].W_sat_l++; #endif /* if WMOPS */ - - return L_var_out; -} + return L_var_out; +} /*___________________________________________________________________________________ | | -| Function Name : W_sat_m | +| Function Name : W_sat_m | | | | Purpose : | | | @@ -721,18 +749,19 @@ Word32 W_sat_l (Word64 L64_var) { | range : 0x8000 0000 <= L_var_out <= 0x7fff 0000. | |_____________________________________________________________________________________| */ -Word32 W_sat_m (Word64 L64_var) { - Word32 L_var_out; - - L64_var = L64_var >> 16; - L_var_out = W_sat_l (L64_var); - -#if (WMOPS) - multiCounter[currCounter].W_sat_l--; - multiCounter[currCounter].W_sat_m++; +Word32 W_sat_m( Word64 L64_var ) +{ + Word32 L_var_out; + + L64_var = L64_var >> 16; + L_var_out = W_sat_l( L64_var ); + +#if ( WMOPS ) + multiCounter[currCounter].W_sat_l--; + multiCounter[currCounter].W_sat_m++; #endif /* if WMOPS */ - - return L_var_out; + + return L_var_out; } @@ -763,16 +792,17 @@ Word32 W_sat_m (Word64 L64_var) { | range : 0x80000000 00000000LL <= L64_var1 <= 0x7fffffff ffffffffLL. | |__________________________________________________________________________________| */ -Word64 W_deposit32_l (Word32 L_var1) { - Word64 L64_var_out; - - L64_var_out = (Word64) L_var1; +Word64 W_deposit32_l( Word32 L_var1 ) +{ + Word64 L64_var_out; -#if (WMOPS) - multiCounter[currCounter].W_deposit32_l++; + L64_var_out = (Word64) L_var1; + +#if ( WMOPS ) + multiCounter[currCounter].W_deposit32_l++; #endif - - return (L64_var_out); + + return ( L64_var_out ); } @@ -803,16 +833,17 @@ Word64 W_deposit32_l (Word32 L_var1) { | range : 0x80000000 00000000LL <= L64_var1 <= 0x7fffffff ffffffffLL. | |__________________________________________________________________________________| */ -Word64 W_deposit32_h (Word32 L_var1) { - Word64 L64_var_out; - - L64_var_out = (Word64) L_var1 << 32; +Word64 W_deposit32_h( Word32 L_var1 ) +{ + Word64 L64_var_out; + + L64_var_out = (Word64) L_var1 << 32; -#if (WMOPS) - multiCounter[currCounter].W_deposit32_h++; +#if ( WMOPS ) + multiCounter[currCounter].W_deposit32_h++; #endif - - return (L64_var_out); + + return ( L64_var_out ); } @@ -843,18 +874,18 @@ Word64 W_deposit32_h (Word32 L_var1) { | range : 0x8000 0000 <= L_var_out <= 0x7fff 0000. | |__________________________________________________________________________________| */ -Word32 W_extract_l (Word64 L64_var1) { - Word32 L_var_out; - - L_var_out = (Word32) L64_var1; +Word32 W_extract_l( Word64 L64_var1 ) +{ + Word32 L_var_out; + + L_var_out = (Word32) L64_var1; -#if (WMOPS) - multiCounter[currCounter].W_extract_l++; +#if ( WMOPS ) + multiCounter[currCounter].W_extract_l++; #endif /* if WMOPS */ - - return (L_var_out); -} + return ( L_var_out ); +} /*__________________________________________________________________________________ @@ -884,18 +915,18 @@ Word32 W_extract_l (Word64 L64_var1) { | range : 0x8000 0000 <= L_var_out <= 0x7fff 0000. | |__________________________________________________________________________________| */ -Word32 W_extract_h (Word64 L64_var1) { - Word32 L_var_out; - - L_var_out = (Word32) (L64_var1 >> 32); +Word32 W_extract_h( Word64 L64_var1 ) +{ + Word32 L_var_out; -#if (WMOPS) - multiCounter[currCounter].W_extract_h++; + L_var_out = (Word32) ( L64_var1 >> 32 ); + +#if ( WMOPS ) + multiCounter[currCounter].W_extract_h++; #endif /* if WMOPS */ - - return (L_var_out); -} + return ( L_var_out ); +} /*________________________________________________________________________________________________ @@ -929,13 +960,14 @@ Word32 W_extract_h (Word64 L64_var1) { | range : 0x80000000 00000000LL <= L64_acc <= 0x7fffffff ffffffffLL. | |_________________________________________________________________________________________________| */ -Word64 W_mult_16_16 (Word16 var1, Word16 var2) { - Word64 L64_var_out = ((Word64) var1*var2) << 1; -#if (WMOPS) - multiCounter[currCounter].W_mult_16_16++; +Word64 W_mult_16_16( Word16 var1, Word16 var2 ) +{ + Word64 L64_var_out = ( (Word64) var1 * var2 ) << 1; +#if ( WMOPS ) + multiCounter[currCounter].W_mult_16_16++; #endif /* if WMOPS */ - return L64_var_out; -} + return L64_var_out; +} /*________________________________________________________________________________________________ | | | Function Name : W_mac_16_16 | @@ -972,16 +1004,16 @@ Word64 W_mult_16_16 (Word16 var1, Word16 var2) { | range : 0x80000000 00000000LL <= L64_var_out <= 0x7fffffff ffffffffLL. | |_________________________________________________________________________________________________| */ -Word64 W_mac_16_16 (Word64 L64_acc, Word16 var1, Word16 var2) { - Word64 L64_var_out = ((Word64) var1*var2) << 1; - L64_acc = L64_acc + L64_var_out; +Word64 W_mac_16_16( Word64 L64_acc, Word16 var1, Word16 var2 ) +{ + Word64 L64_var_out = ( (Word64) var1 * var2 ) << 1; + L64_acc = L64_acc + L64_var_out; -#if (WMOPS) - multiCounter[currCounter].W_mac_16_16++; +#if ( WMOPS ) + multiCounter[currCounter].W_mac_16_16++; #endif /* if WMOPS */ - return L64_acc; -} - + return L64_acc; +} /*________________________________________________________________________________________________ @@ -1020,14 +1052,15 @@ Word64 W_mac_16_16 (Word64 L64_acc, Word16 var1, Word16 var2) { | range : 0x80000000 00000000LL <= L64_var_out <= 0x7fffffff ffffffffLL. | |_________________________________________________________________________________________________| */ -Word64 W_msu_16_16 (Word64 L64_var1, Word16 var2, Word16 var3) { - Word64 L64_var_out = ((Word64)var2*var3) << 1; - L64_var_out = L64_var1 - L64_var_out; -#if (WMOPS) - multiCounter[currCounter].W_msu_16_16++; +Word64 W_msu_16_16( Word64 L64_var1, Word16 var2, Word16 var3 ) +{ + Word64 L64_var_out = ( (Word64) var2 * var3 ) << 1; + L64_var_out = L64_var1 - L64_var_out; +#if ( WMOPS ) + multiCounter[currCounter].W_msu_16_16++; #endif /* if WMOPS */ - return L64_var_out; -} + return L64_var_out; +} /*___________________________________________________________________________ @@ -1036,7 +1069,7 @@ Word64 W_msu_16_16 (Word64 L64_var1, Word16 var2, Word16 var3) { | | | Purpose : | | | -| Arithmetically shift the 64 bit input L64_var left by n positions with | +| Arithmetically shift the 64 bit input L64_var left by n positions with | | lower 32 bit saturation and return the 32 LSB of 64 bit result | | | | Complexity weight : 1 | @@ -1062,20 +1095,21 @@ Word64 W_msu_16_16 (Word64 L64_var1, Word16 var2, Word16 var3) { | range : 0x8000 0000 <= L_result <= 0x7fff 0000. | |___________________________________________________________________________| */ -Word32 W_shl_sat_l (Word64 L64_var, Word16 n) { - Word32 L_result; - Word64 d_var_64; - - d_var_64 = W_shl (L64_var, n); - L_result = W_sat_l (d_var_64); - -#if (WMOPS) - multiCounter[currCounter].W_shl_sat_l++; - multiCounter[currCounter].W_shl--; - multiCounter[currCounter].W_sat_l--; +Word32 W_shl_sat_l( Word64 L64_var, Word16 n ) +{ + Word32 L_result; + Word64 d_var_64; + + d_var_64 = W_shl( L64_var, n ); + L_result = W_sat_l( d_var_64 ); + +#if ( WMOPS ) + multiCounter[currCounter].W_shl_sat_l++; + multiCounter[currCounter].W_shl--; + multiCounter[currCounter].W_sat_l--; #endif /* if WMOPS */ - - return L_result; + + return L_result; } @@ -1085,8 +1119,8 @@ Word32 W_shl_sat_l (Word64 L64_var, Word16 n) { | | | Purpose : | | | -| Round asymmetrically lower 16 bits, and | -| saturate the 17.47-bit values to 1.31-bit values | +| Round asymmetrically lower 16 bits, and | +| saturate the 17.47-bit values to 1.31-bit values | | Complexity weight : 1 | | | | Inputs : | @@ -1107,44 +1141,49 @@ Word32 W_shl_sat_l (Word64 L64_var, Word16 n) { |__________________________________________________________________________________| */ #ifdef BASOP_NOGLOB -Word32 W_round48_L_o (Word64 L64_var1, Flag* Overflow) { -#else /* BASOP_NOGLOB */ -Word32 W_round48_L (Word64 L64_var1) { +Word32 W_round48_L_o( Word64 L64_var1, Flag *Overflow ) +{ +#else /* BASOP_NOGLOB */ +Word32 W_round48_L( Word64 L64_var1 ) +{ #endif /* BASOP_NOGLOB */ - Word64 L64_var_out; - Word32 L_result; - - Word64 L64_var2 = 0x80000000; - Word64 L64_MIN = 0x8000000000000000LL; - Word64 L64_MAX = 0x7FFFFFFFFFFFFFFFLL; - - L64_var1 = W_shl (L64_var1, 16); - - L64_var_out = L64_var1 + L64_var2; - - if ( ( (L64_var1 ^ L64_var2) & L64_MIN) == 0) { - if ( (L64_var_out ^ L64_var1) & L64_MIN) { - L64_var_out = (L64_var1 < 0) ? L64_MIN : L64_MAX; + Word64 L64_var_out; + Word32 L_result; + + Word64 L64_var2 = 0x80000000; + Word64 L64_MIN = 0x8000000000000000LL; + Word64 L64_MAX = 0x7FFFFFFFFFFFFFFFLL; + + L64_var1 = W_shl( L64_var1, 16 ); + + L64_var_out = L64_var1 + L64_var2; + + if ( ( ( L64_var1 ^ L64_var2 ) & L64_MIN ) == 0 ) + { + if ( ( L64_var_out ^ L64_var1 ) & L64_MIN ) + { + L64_var_out = ( L64_var1 < 0 ) ? L64_MIN : L64_MAX; #ifdef BASOP_NOGLOB - set_overflow(Overflow); -#else /* BASOP_NOGLOB */ - Overflow = 1; + set_overflow( Overflow ); +#else /* BASOP_NOGLOB */ + Overflow = 1; #endif /* BASOP_NOGLOB */ - } - } - L_result = W_extract_h (L64_var_out); -#if (WMOPS) - multiCounter[currCounter].W_round48_L++; - multiCounter[currCounter].W_extract_h--; - multiCounter[currCounter].W_shl--; + } + } + L_result = W_extract_h( L64_var_out ); +#if ( WMOPS ) + multiCounter[currCounter].W_round48_L++; + multiCounter[currCounter].W_extract_h--; + multiCounter[currCounter].W_shl--; #endif /* if WMOPS */ - - return (L_result); + + return ( L_result ); } #ifdef BASOP_NOGLOB -Word32 W_round48_L (Word64 L64_var1) { - return W_round48_L_o(L64_var1, NULL); +Word32 W_round48_L( Word64 L64_var1 ) +{ + return W_round48_L_o( L64_var1, NULL ); } #endif /* BASOP_NOGLOB */ @@ -1154,8 +1193,8 @@ Word32 W_round48_L (Word64 L64_var1) { | | | Purpose : | | | -| Round asymmetrically lower 32 bits, and | -| saturate the 17.47-bit values to 1.15-bit values | +| Round asymmetrically lower 32 bits, and | +| saturate the 17.47-bit values to 1.15-bit values | | Complexity weight : 1 | | | | Inputs : | @@ -1176,47 +1215,52 @@ Word32 W_round48_L (Word64 L64_var1) { |__________________________________________________________________________________| */ #ifdef BASOP_NOGLOB -Word16 W_round32_s_o (Word64 L64_var1, Flag* Overflow) { -#else /* BASOP_NOGLOB */ -Word16 W_round32_s (Word64 L64_var1) { +Word16 W_round32_s_o( Word64 L64_var1, Flag *Overflow ) +{ +#else /* BASOP_NOGLOB */ +Word16 W_round32_s( Word64 L64_var1 ) +{ #endif /* BASOP_NOGLOB */ - Word64 L64_var_out; - Word32 L_var; - Word16 var_out; - - - Word64 L64_var2 = 0x800000000000LL; - Word64 L64_MIN = 0x8000000000000000LL; - Word64 L64_MAX = 0x7FFFFFFFFFFFFFFFLL; - - L64_var1 = W_shl (L64_var1, 16); - L64_var_out = L64_var1 + L64_var2; - - if (((L64_var1 ^ L64_var2) & L64_MIN) == 0) { - if ((L64_var_out ^ L64_var1) & L64_MIN) { - L64_var_out = (L64_var1 < 0) ? L64_MIN : L64_MAX; + Word64 L64_var_out; + Word32 L_var; + Word16 var_out; + + + Word64 L64_var2 = 0x800000000000LL; + Word64 L64_MIN = 0x8000000000000000LL; + Word64 L64_MAX = 0x7FFFFFFFFFFFFFFFLL; + + L64_var1 = W_shl( L64_var1, 16 ); + L64_var_out = L64_var1 + L64_var2; + + if ( ( ( L64_var1 ^ L64_var2 ) & L64_MIN ) == 0 ) + { + if ( ( L64_var_out ^ L64_var1 ) & L64_MIN ) + { + L64_var_out = ( L64_var1 < 0 ) ? L64_MIN : L64_MAX; #ifdef BASOP_NOGLOB - set_overflow(Overflow); -#else /* BASOP_NOGLOB */ - Overflow = 1; + set_overflow( Overflow ); +#else /* BASOP_NOGLOB */ + Overflow = 1; #endif /* BASOP_NOGLOB */ - } - } - L_var = W_extract_h (L64_var_out); - var_out = extract_h (L_var); -#if (WMOPS) - multiCounter[currCounter].W_round32_s ++; - multiCounter[currCounter].W_extract_h--; - multiCounter[currCounter].extract_h--; - multiCounter[currCounter].W_shl--; + } + } + L_var = W_extract_h( L64_var_out ); + var_out = extract_h( L_var ); +#if ( WMOPS ) + multiCounter[currCounter].W_round32_s++; + multiCounter[currCounter].W_extract_h--; + multiCounter[currCounter].extract_h--; + multiCounter[currCounter].W_shl--; #endif /* if WMOPS */ - - return (var_out); + + return ( var_out ); } #ifdef BASOP_NOGLOB -Word16 W_round32_s (Word64 L64_var1) { - return W_round32_s_o(L64_var1, NULL); +Word16 W_round32_s( Word64 L64_var1 ) +{ + return W_round32_s_o( L64_var1, NULL ); } #endif /* BASOP_NOGLOB */ @@ -1248,32 +1292,38 @@ Word16 W_round32_s (Word64 L64_var1) { | range : 0x0000 0000 <= var_out <= 0x0000 003f. | |___________________________________________________________________________| */ -Word16 W_norm (Word64 L64_var1) { - Word16 var_out; - if (L64_var1 == 0) { - var_out = 0; - } - else { - if (L64_var1 == (Word64) 0xffffffffffffffffLL) { - var_out = 63; - } - else { - if (L64_var1 < 0) { - L64_var1 = ~L64_var1; - } - for (var_out = 0; L64_var1 < (Word64) 0x4000000000000000LL; var_out++) { - L64_var1 <<= 1; - } - } - } -#if (WMOPS) - multiCounter[currCounter].W_norm ++; +Word16 W_norm( Word64 L64_var1 ) +{ + Word16 var_out; + if ( L64_var1 == 0 ) + { + var_out = 0; + } + else + { + if ( L64_var1 == (Word64) 0xffffffffffffffffLL ) + { + var_out = 63; + } + else + { + if ( L64_var1 < 0 ) + { + L64_var1 = ~L64_var1; + } + for ( var_out = 0; L64_var1 < (Word64) 0x4000000000000000LL; var_out++ ) + { + L64_var1 <<= 1; + } + } + } +#if ( WMOPS ) + multiCounter[currCounter].W_norm++; #endif /* if WMOPS */ - return (var_out); + return ( var_out ); } - /*______________________________________________________________________________ | | | Function Name : W_add | @@ -1306,34 +1356,39 @@ Word16 W_norm (Word64 L64_var1) { |_______________________________________________________________________________| */ #ifdef BASOP_NOGLOB -Word64 W_add_o (Word64 L64_var1, Word64 L64_var2, Flag* Overflow) { -#else /* BASOP_NOGLOB */ -Word64 W_add (Word64 L64_var1, Word64 L64_var2) { +Word64 W_add_o( Word64 L64_var1, Word64 L64_var2, Flag *Overflow ) +{ +#else /* BASOP_NOGLOB */ +Word64 W_add( Word64 L64_var1, Word64 L64_var2 ) +{ #endif /* BASOP_NOGLOB */ - Word64 L64_var_out; - - L64_var_out = L64_var1 + L64_var2; + Word64 L64_var_out; + + L64_var_out = L64_var1 + L64_var2; - if (((L64_var1 ^ L64_var2) & MIN_64) == 0) { - if ((L64_var_out ^ L64_var1) & MIN_64) { - L64_var_out = (L64_var1 < 0) ? MIN_64 : MAX_64; + if ( ( ( L64_var1 ^ L64_var2 ) & MIN_64 ) == 0 ) + { + if ( ( L64_var_out ^ L64_var1 ) & MIN_64 ) + { + L64_var_out = ( L64_var1 < 0 ) ? MIN_64 : MAX_64; #ifdef BASOP_NOGLOB - set_overflow(Overflow); -#else /* BASOP_NOGLOB */ + set_overflow( Overflow ); +#else /* BASOP_NOGLOB */ Overflow = 1; #endif /* BASOP_NOGLOB */ } } -#if (WMOPS) - multiCounter[currCounter].W_add++; -#endif - return L64_var_out; +#if ( WMOPS ) + multiCounter[currCounter].W_add++; +#endif + return L64_var_out; } #ifdef BASOP_NOGLOB -Word64 W_add (Word64 L64_var1, Word64 L64_var2) { - return W_add_o(L64_var1, L64_var2, NULL); +Word64 W_add( Word64 L64_var1, Word64 L64_var2 ) +{ + return W_add_o( L64_var1, L64_var2, NULL ); } #endif /* BASOP_NOGLOB */ @@ -1369,34 +1424,39 @@ Word64 W_add (Word64 L64_var1, Word64 L64_var2) { |_______________________________________________________________________________| */ #ifdef BASOP_NOGLOB -Word64 W_sub_o (Word64 L64_var1, Word64 L64_var2, Flag* Overflow) { -#else /* BASOP_NOGLOB */ -Word64 W_sub (Word64 L64_var1, Word64 L64_var2) { +Word64 W_sub_o( Word64 L64_var1, Word64 L64_var2, Flag *Overflow ) +{ +#else /* BASOP_NOGLOB */ +Word64 W_sub( Word64 L64_var1, Word64 L64_var2 ) +{ #endif /* BASOP_NOGLOB */ - Word64 L64_var_out; - - L64_var_out = L64_var1 - L64_var2; + Word64 L64_var_out; - if (((L64_var1 ^ L64_var2) & MIN_64) != 0) { - if ((L64_var_out ^ L64_var1) & MIN_64) { - L64_var_out = (L64_var1 < 0) ? MIN_64 : MAX_64; + L64_var_out = L64_var1 - L64_var2; + + if ( ( ( L64_var1 ^ L64_var2 ) & MIN_64 ) != 0 ) + { + if ( ( L64_var_out ^ L64_var1 ) & MIN_64 ) + { + L64_var_out = ( L64_var1 < 0 ) ? MIN_64 : MAX_64; #ifdef BASOP_NOGLOB - set_overflow(Overflow); -#else /* BASOP_NOGLOB */ + set_overflow( Overflow ); +#else /* BASOP_NOGLOB */ Overflow = 1; #endif /* BASOP_NOGLOB */ } } -#if (WMOPS) - multiCounter[currCounter].W_add++; -#endif - return L64_var_out; +#if ( WMOPS ) + multiCounter[currCounter].W_add++; +#endif + return L64_var_out; } #ifdef BASOP_NOGLOB -Word64 W_sub (Word64 L64_var1, Word64 L64_var2) { - return W_sub_o(L64_var1, L64_var2, NULL); +Word64 W_sub( Word64 L64_var1, Word64 L64_var2 ) +{ + return W_sub_o( L64_var1, L64_var2, NULL ); } #endif /* BASOP_NOGLOB */ @@ -1429,35 +1489,39 @@ Word64 W_sub (Word64 L64_var1, Word64 L64_var2) { |_______________________________________________________________________________| */ #ifdef BASOP_NOGLOB -Word64 W_neg_o (Word64 L64_var1, Flag* Overflow) { -#else /* BASOP_NOGLOB */ -Word64 W_neg (Word64 L64_var1) { +Word64 W_neg_o( Word64 L64_var1, Flag *Overflow ) +{ +#else /* BASOP_NOGLOB */ +Word64 W_neg( Word64 L64_var1 ) +{ #endif /* BASOP_NOGLOB */ Word64 L64_var_out; - - if (L64_var1 == MIN_64) { - L64_var_out = MAX_64; + + if ( L64_var1 == MIN_64 ) + { + L64_var_out = MAX_64; #ifdef BASOP_NOGLOB - set_overflow(Overflow); -#else /* BASOP_NOGLOB */ - Overflow = 1; + set_overflow( Overflow ); +#else /* BASOP_NOGLOB */ + Overflow = 1; #endif /* BASOP_NOGLOB */ - } - else { - L64_var_out = -L64_var1; - } + } + else + { + L64_var_out = -L64_var1; + } -#if (WMOPS) +#if ( WMOPS ) multiCounter[currCounter].W_neg++; #endif - - return (L64_var_out); + return ( L64_var_out ); } #ifdef BASOP_NOGLOB -Word64 W_neg (Word64 L64_var1) { - return W_neg_o(L64_var1, NULL); +Word64 W_neg( Word64 L64_var1 ) +{ + return W_neg_o( L64_var1, NULL ); } #endif /* BASOP_NOGLOB */ @@ -1490,39 +1554,46 @@ Word64 W_neg (Word64 L64_var1) { |___________________________________________________________________________| */ #ifdef BASOP_NOGLOB -Word64 W_abs_o (Word64 L64_var1, Flag* Overflow) { -#else /* BASOP_NOGLOB */ -Word64 W_abs (Word64 L64_var1) { +Word64 W_abs_o( Word64 L64_var1, Flag *Overflow ) +{ +#else /* BASOP_NOGLOB */ +Word64 W_abs( Word64 L64_var1 ) +{ #endif /* BASOP_NOGLOB */ Word64 L64_var_out; - if (L64_var1 == MIN_64) { - L64_var_out = MAX_64; + if ( L64_var1 == MIN_64 ) + { + L64_var_out = MAX_64; #ifdef BASOP_NOGLOB - set_overflow(Overflow); -#else /* BASOP_NOGLOB */ - Overflow = 1; + set_overflow( Overflow ); +#else /* BASOP_NOGLOB */ + Overflow = 1; #endif /* BASOP_NOGLOB */ } - else { - if (L64_var1 < 0) { + else + { + if ( L64_var1 < 0 ) + { L64_var_out = -L64_var1; } - else { + else + { L64_var_out = L64_var1; } } -#if (WMOPS) +#if ( WMOPS ) multiCounter[currCounter].W_abs++; #endif - return (L64_var_out); + return ( L64_var_out ); } #ifdef BASOP_NOGLOB -Word64 W_abs (Word64 L64_var1) { - return W_abs_o(L64_var1, NULL); +Word64 W_abs( Word64 L64_var1 ) +{ + return W_abs_o( L64_var1, NULL ); } #endif /* BASOP_NOGLOB */ @@ -1559,33 +1630,38 @@ Word64 W_abs (Word64 L64_var1) { |_________________________________________________________________________________________________| */ #ifdef BASOP_NOGLOB -Word64 W_mult_32_32_o(Word32 L_var1, Word32 L_var2, Flag* Overflow) { -#else /* BASOP_NOGLOB */ -Word64 W_mult_32_32(Word32 L_var1, Word32 L_var2) { +Word64 W_mult_32_32_o( Word32 L_var1, Word32 L_var2, Flag *Overflow ) +{ +#else /* BASOP_NOGLOB */ +Word64 W_mult_32_32( Word32 L_var1, Word32 L_var2 ) +{ #endif /* BASOP_NOGLOB */ - Word64 L64_var_out; - - if ((L_var1 == MIN_32) && (L_var2 == MIN_32)) { - L64_var_out = MAX_64; + Word64 L64_var_out; + + if ( ( L_var1 == MIN_32 ) && ( L_var2 == MIN_32 ) ) + { + L64_var_out = MAX_64; #ifdef BASOP_NOGLOB - set_overflow(Overflow); -#else /* BASOP_NOGLOB */ - Overflow = 1; + set_overflow( Overflow ); +#else /* BASOP_NOGLOB */ + Overflow = 1; #endif /* BASOP_NOGLOB */ - } - else { - L64_var_out = ((Word64 )L_var1*L_var2) << 1; - } - -#if (WMOPS) - multiCounter[currCounter].W_mult_32_32++; -#endif /* if WMOPS */ - return L64_var_out; + } + else + { + L64_var_out = ( (Word64) L_var1 * L_var2 ) << 1; + } + +#if ( WMOPS ) + multiCounter[currCounter].W_mult_32_32++; +#endif /* if WMOPS */ + return L64_var_out; } #ifdef BASOP_NOGLOB -Word64 W_mult_32_32(Word32 L_var1, Word32 L_var2) { - return W_mult_32_32_o(L_var1, L_var2, NULL); +Word64 W_mult_32_32( Word32 L_var1, Word32 L_var2 ) +{ + return W_mult_32_32_o( L_var1, L_var2, NULL ); } #endif /* BASOP_NOGLOB */ @@ -1620,16 +1696,17 @@ Word64 W_mult_32_32(Word32 L_var1, Word32 L_var2) { | range : 0x80000000 00000000LL <= L64_var_out <= 0x7fffffff ffffffffLL. | |_________________________________________________________________________________________________| */ -Word64 W_mult0_32_32 (Word32 L_var1, Word32 L_var2) { - Word64 L64_var_out; - - L64_var_out = (Word64) L_var1*L_var2; +Word64 W_mult0_32_32( Word32 L_var1, Word32 L_var2 ) +{ + Word64 L64_var_out; + L64_var_out = (Word64) L_var1 * L_var2; -#if (WMOPS) - multiCounter[currCounter].W_mult0_32_32++; + +#if ( WMOPS ) + multiCounter[currCounter].W_mult0_32_32++; #endif /* if WMOPS */ - return L64_var_out; + return L64_var_out; } @@ -1639,7 +1716,7 @@ Word64 W_mult0_32_32 (Word32 L_var1, Word32 L_var2) { | | | Purpose : | | | -| Logically shift the 64 bit unsigned input L64_var1 left by var2 positions. | +| Logically shift the 64 bit unsigned input L64_var1 left by var2 positions. | | Zero fill the var2 LSB of the result. If var2 is negative, logically shift | | L64_var1 right by -var2 with zero fill in the MSB. | | | @@ -1647,7 +1724,7 @@ Word64 W_mult0_32_32 (Word32 L_var1, Word32 L_var2) { | | | Inputs : | | | -| L64_var1 64 bit long unsigned signed integer (UWord64) whose value falls | +| L64_var1 64 bit long unsigned signed integer (UWord64) whose value falls | | in the range : 0LL <= L64_var1 <= 0xffffffff ffffffffLL. | | | | var2 | @@ -1661,25 +1738,28 @@ Word64 W_mult0_32_32 (Word32 L_var1, Word32 L_var2) { | Return Value : | | | | L64_var_out | -| 64 bit long unsigned signed integer (UWord64) whose value falls | +| 64 bit long unsigned signed integer (UWord64) whose value falls | | in the range : 0LL <= L64_var1 <= 0xffffffff ffffffffLL. | |______________________________________________________________________________| */ -UWord64 W_lshl (UWord64 L64_var1, Word16 var2) { - - UWord64 L64_var_out = 0LL; - - if (var2 < 0) { - L64_var_out = L64_var1 >> (-var2); - } - else { - L64_var_out = L64_var1 << var2 ; - } -#if (WMOPS) - multiCounter[currCounter].W_lshl++; +UWord64 W_lshl( UWord64 L64_var1, Word16 var2 ) +{ + + UWord64 L64_var_out = 0LL; + + if ( var2 < 0 ) + { + L64_var_out = L64_var1 >> ( -var2 ); + } + else + { + L64_var_out = L64_var1 << var2; + } +#if ( WMOPS ) + multiCounter[currCounter].W_lshl++; #endif - - return (L64_var_out); + + return ( L64_var_out ); } /*_____________________________________________________________________________ @@ -1696,7 +1776,7 @@ UWord64 W_lshl (UWord64 L64_var1, Word16 var2) { | | | Inputs : | | | -| L64_var1 64 bit long unsigned signed integer (UWord64) whose value falls | +| L64_var1 64 bit long unsigned signed integer (UWord64) whose value falls | | in the range : 0LL <= L64_var1 <= 0xffffffff ffffffffLL. | | | | var2 | @@ -1710,25 +1790,28 @@ UWord64 W_lshl (UWord64 L64_var1, Word16 var2) { | Return Value : | | | | L64_var_out | -| 64 bit long unsigned signed integer (UWord64) whose value falls | +| 64 bit long unsigned signed integer (UWord64) whose value falls | | in the range : 0LL <= L64_var1 <= 0xffffffff ffffffffLL. | |______________________________________________________________________________| */ -UWord64 W_lshr (UWord64 L64_var1, Word16 var2) { - - UWord64 L64_var_out = 0LL; - - if (var2 < 0) { - L64_var_out = L64_var1 << (-var2); - } - else { - L64_var_out = L64_var1 >> var2 ; - } -#if (WMOPS) - multiCounter[currCounter].W_lshr++; +UWord64 W_lshr( UWord64 L64_var1, Word16 var2 ) +{ + + UWord64 L64_var_out = 0LL; + + if ( var2 < 0 ) + { + L64_var_out = L64_var1 << ( -var2 ); + } + else + { + L64_var_out = L64_var1 >> var2; + } +#if ( WMOPS ) + multiCounter[currCounter].W_lshr++; #endif - - return (L64_var_out); + + return ( L64_var_out ); } @@ -1738,8 +1821,8 @@ UWord64 W_lshr (UWord64 L64_var1, Word16 var2) { | | | Purpose : | | | -| Round asymmetrically lower 32 bits, and | -| saturate the 1.63-bit values to 1.31-bit values | +| Round asymmetrically lower 32 bits, and | +| saturate the 1.63-bit values to 1.31-bit values | | Complexity weight : 1 | | | | Inputs : | @@ -1759,22 +1842,23 @@ UWord64 W_lshr (UWord64 L64_var1, Word16 var2) { | range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. | |__________________________________________________________________________________| */ -Word32 W_round64_L (Word64 L64_var1) { - Word64 L64_var_out; - Word32 L_result; - - - Word64 L64_tmp = 0x80000000; - L64_var_out = W_add (L64_var1, L64_tmp); - L_result = W_extract_h (L64_var_out); - -#if (WMOPS) - multiCounter[currCounter].W_round64_L++; - multiCounter[currCounter].W_extract_h--; - multiCounter[currCounter].W_add--; +Word32 W_round64_L( Word64 L64_var1 ) +{ + Word64 L64_var_out; + Word32 L_result; + + + Word64 L64_tmp = 0x80000000; + L64_var_out = W_add( L64_var1, L64_tmp ); + L_result = W_extract_h( L64_var_out ); + +#if ( WMOPS ) + multiCounter[currCounter].W_round64_L++; + multiCounter[currCounter].W_extract_h--; + multiCounter[currCounter].W_add--; #endif /* if WMOPS */ - - return (L_result); + + return ( L_result ); } #endif /* #ifdef ENH_64_BIT_OPERATOR */ diff --git a/lib_com/enh64.h b/lib_com/enh64.h index 6c0b82393..9016a27ae 100644 --- a/lib_com/enh64.h +++ b/lib_com/enh64.h @@ -3,8 +3,8 @@ #define _ENH64_H #include "stl.h" - -#ifndef Word64 + +#ifndef Word64 #define Word64 long long int #endif @@ -12,69 +12,69 @@ #define UWord64 unsigned long long int #endif -#define MAX_64 (Word64)0x7fffffffffffffffLL -#define MIN_64 (Word64)0x8000000000000000LL +#define MAX_64 (Word64) 0x7fffffffffffffffLL +#define MIN_64 (Word64) 0x8000000000000000LL - /***************************************************************************** +/***************************************************************************** * * Prototypes for enhanced 64 bit arithmetic operators * *****************************************************************************/ #ifdef ENH_64_BIT_OPERATOR -Word64 W_add_nosat (Word64 L64_var1, Word64 L64_var2); -Word64 W_sub_nosat (Word64 L64_var1, Word64 L64_var2); -Word64 W_shl (Word64 L64_var1, Word16 var2); -Word64 W_shr (Word64 L64_var1, Word16 var2); -Word64 W_shl_nosat (Word64 L64_var1, Word16 var2); -Word64 W_shr_nosat (Word64 L64_var1, Word16 var2); -Word64 W_mult_32_16 (Word32 L_var1, Word16 var2); -Word64 W_mac_32_16 (Word64 L64_acc, Word32 L_var1, Word16 var2); -Word64 W_msu_32_16 (Word64 L64_acc, Word32 L_var1, Word16 var2); -Word64 W_mult0_16_16 (Word16 var1, Word16 var2); -Word64 W_mac0_16_16 (Word64 L64_acc, Word16 var1, Word16 var2); -Word64 W_msu0_16_16 (Word64 L64_acc, Word16 var1, Word16 var2); -Word64 W_mult_16_16 (Word16 var1, Word16 var2); -Word64 W_mac_16_16 (Word64 L64_acc, Word16 var1, Word16 var2); -Word64 W_msu_16_16 (Word64 L64_acc, Word16 var1, Word16 var2); - -Word64 W_deposit32_l (Word32 L_var1); -Word64 W_deposit32_h (Word32 L_var1); - -Word32 W_sat_l (Word64 L64_var); -Word32 W_sat_m (Word64 L64_var); -Word32 W_shl_sat_l (Word64 L64_var, Word16 n); - -Word32 W_extract_l (Word64 L64_var1); -Word32 W_extract_h (Word64 L64_var1); - -Word32 W_round48_L (Word64 L64_var1); -Word16 W_round32_s (Word64 L64_var1); - -Word16 W_norm (Word64 L_var1); - - -Word64 W_add (Word64 L64_var1, Word64 L64_var2); -Word64 W_sub (Word64 L64_var1, Word64 L64_var2); -Word64 W_neg (Word64 L64_var1); -Word64 W_abs (Word64 L64_var1); -Word64 W_mult_32_32 (Word32 L_var1, Word32 L_var2); -Word64 W_mult0_32_32 (Word32 L_var1, Word32 L_var2); -UWord64 W_lshl (UWord64 L64_var1, Word16 var2); -UWord64 W_lshr (UWord64 L64_var1, Word16 var2); -Word32 W_round64_L (Word64 L64_var1) ; +Word64 W_add_nosat( Word64 L64_var1, Word64 L64_var2 ); +Word64 W_sub_nosat( Word64 L64_var1, Word64 L64_var2 ); +Word64 W_shl( Word64 L64_var1, Word16 var2 ); +Word64 W_shr( Word64 L64_var1, Word16 var2 ); +Word64 W_shl_nosat( Word64 L64_var1, Word16 var2 ); +Word64 W_shr_nosat( Word64 L64_var1, Word16 var2 ); +Word64 W_mult_32_16( Word32 L_var1, Word16 var2 ); +Word64 W_mac_32_16( Word64 L64_acc, Word32 L_var1, Word16 var2 ); +Word64 W_msu_32_16( Word64 L64_acc, Word32 L_var1, Word16 var2 ); +Word64 W_mult0_16_16( Word16 var1, Word16 var2 ); +Word64 W_mac0_16_16( Word64 L64_acc, Word16 var1, Word16 var2 ); +Word64 W_msu0_16_16( Word64 L64_acc, Word16 var1, Word16 var2 ); +Word64 W_mult_16_16( Word16 var1, Word16 var2 ); +Word64 W_mac_16_16( Word64 L64_acc, Word16 var1, Word16 var2 ); +Word64 W_msu_16_16( Word64 L64_acc, Word16 var1, Word16 var2 ); + +Word64 W_deposit32_l( Word32 L_var1 ); +Word64 W_deposit32_h( Word32 L_var1 ); + +Word32 W_sat_l( Word64 L64_var ); +Word32 W_sat_m( Word64 L64_var ); +Word32 W_shl_sat_l( Word64 L64_var, Word16 n ); + +Word32 W_extract_l( Word64 L64_var1 ); +Word32 W_extract_h( Word64 L64_var1 ); + +Word32 W_round48_L( Word64 L64_var1 ); +Word16 W_round32_s( Word64 L64_var1 ); + +Word16 W_norm( Word64 L_var1 ); + + +Word64 W_add( Word64 L64_var1, Word64 L64_var2 ); +Word64 W_sub( Word64 L64_var1, Word64 L64_var2 ); +Word64 W_neg( Word64 L64_var1 ); +Word64 W_abs( Word64 L64_var1 ); +Word64 W_mult_32_32( Word32 L_var1, Word32 L_var2 ); +Word64 W_mult0_32_32( Word32 L_var1, Word32 L_var2 ); +UWord64 W_lshl( UWord64 L64_var1, Word16 var2 ); +UWord64 W_lshr( UWord64 L64_var1, Word16 var2 ); +Word32 W_round64_L( Word64 L64_var1 ); #ifdef BASOP_NOGLOB /* * Overflowing operators */ -Word64 W_shl_o (Word64 L64_var1, Word16 var2, Flag* Overflow); -Word32 W_round48_L_o (Word64 L64_var1, Flag* Overflow); -Word16 W_round32_s_o (Word64 L64_var1, Flag* Overflow); -Word64 W_add_o (Word64 L64_var1, Word64 L64_var2, Flag* Overflow); -Word64 W_sub_o (Word64 L64_var1, Word64 L64_var2, Flag* Overflow); -Word64 W_neg_o (Word64 L64_var1, Flag* Overflow); -Word64 W_abs_o (Word64 L64_var1, Flag* Overflow); -Word64 W_mult_32_32_o(Word32 L_var1, Word32 L_var2, Flag* Overflow); +Word64 W_shl_o( Word64 L64_var1, Word16 var2, Flag *Overflow ); +Word32 W_round48_L_o( Word64 L64_var1, Flag *Overflow ); +Word16 W_round32_s_o( Word64 L64_var1, Flag *Overflow ); +Word64 W_add_o( Word64 L64_var1, Word64 L64_var2, Flag *Overflow ); +Word64 W_sub_o( Word64 L64_var1, Word64 L64_var2, Flag *Overflow ); +Word64 W_neg_o( Word64 L64_var1, Flag *Overflow ); +Word64 W_abs_o( Word64 L64_var1, Flag *Overflow ); +Word64 W_mult_32_32_o( Word32 L_var1, Word32 L_var2, Flag *Overflow ); #endif /* BASOP_NOGLOB */ #endif /* #ifdef ENH_64_BIT_OPERATOR */ @@ -83,5 +83,3 @@ Word64 W_mult_32_32_o(Word32 L_var1, Word32 L_var2, Flag* Overflow); /* end of file */ - - diff --git a/lib_com/enhUL32.c b/lib_com/enhUL32.c index 4cb6af850..0aa21b4fc 100644 --- a/lib_com/enhUL32.c +++ b/lib_com/enhUL32.c @@ -6,15 +6,15 @@ ENHANCED UNSIGNED 32-BIT ARITHMETIC OPERATORS History: v.0.5 - 21.March.2014 - + ============================================================================ */ - /***************************************************************************** +/***************************************************************************** * * Enhanced Unsigned 32 bit operators : * see complete list in .h file - * + * *****************************************************************************/ /***************************************************************************** @@ -27,7 +27,7 @@ #include "stl.h" #include "enhUL32.h" -#if (WMOPS) +#if ( WMOPS ) extern BASIC_OP multiCounter[MAXCOUNTERS]; extern int currCounter; #endif /* if WMOPS */ @@ -58,13 +58,14 @@ extern int currCounter; |___________________________________________________________________________| */ -UWord32 UL_deposit_l (UWord16 uvar) { - UWord32 UL_result; - UL_result = (UWord32) uvar; /* no sign extension*/ -#if (WMOPS) - multiCounter[currCounter].UL_deposit_l++; +UWord32 UL_deposit_l( UWord16 uvar ) +{ + UWord32 UL_result; + UL_result = (UWord32) uvar; /* no sign extension*/ +#if ( WMOPS ) + multiCounter[currCounter].UL_deposit_l++; #endif - return (UL_result); + return ( UL_result ); } #if 0 /*_____________________________________________________________________________ @@ -112,7 +113,7 @@ Word16 norm_ul_float (UWord32 UL_var1) { } } -#if (WMOPS) +#if ( WMOPS ) multiCounter[currCounter].norm_ul_float++; #endif @@ -138,24 +139,27 @@ Word16 norm_ul_float (UWord32 UL_var1) { |___________________________________________________________________________| */ -UWord32 UL_addNs (UWord32 UL_var1, UWord32 UL_var2, UWord16 * wrap) { - UWord32 UL_var3; +UWord32 UL_addNs( UWord32 UL_var1, UWord32 UL_var2, UWord16 *wrap ) +{ + UWord32 UL_var3; - /* STL Overflow flag is not updated */ - UL_var3 = UL_var1 + UL_var2; /* 32-bit wrap may occur, like in C */ + /* STL Overflow flag is not updated */ + UL_var3 = UL_var1 + UL_var2; /* 32-bit wrap may occur, like in C */ - if (((UWord64) UL_var1 + (UWord64) UL_var2) > 0xFFFFFFFFU) { - *wrap = 1; /* wrapped output */ - } - else { - *wrap = 0; - } + if ( ( (UWord64) UL_var1 + (UWord64) UL_var2 ) > 0xFFFFFFFFU ) + { + *wrap = 1; /* wrapped output */ + } + else + { + *wrap = 0; + } #if WMOPS - multiCounter[currCounter].UL_addNs++; + multiCounter[currCounter].UL_addNs++; #endif - return UL_var3; + return UL_var3; } /*___________________________________________________________________________ @@ -177,21 +181,24 @@ UWord32 UL_addNs (UWord32 UL_var1, UWord32 UL_var2, UWord16 * wrap) { |___________________________________________________________________________| */ -UWord32 UL_subNs (UWord32 UL_var1, UWord32 UL_var2, UWord16 * sgn) { - UWord32 UL_var3; +UWord32 UL_subNs( UWord32 UL_var1, UWord32 UL_var2, UWord16 *sgn ) +{ + UWord32 UL_var3; - UL_var3 = UL_var1 - UL_var2; /*wrap may occur, like in C */ - if (UL_var1 >= UL_var2) { - *sgn = 0; - } - else { - *sgn = 1; /* "negative", wrapped output */ - } + UL_var3 = UL_var1 - UL_var2; /*wrap may occur, like in C */ + if ( UL_var1 >= UL_var2 ) + { + *sgn = 0; + } + else + { + *sgn = 1; /* "negative", wrapped output */ + } #if WMOPS - multiCounter[currCounter].UL_subNs++; + multiCounter[currCounter].UL_subNs++; #endif - return UL_var3; + return UL_var3; } /*________________________________________________________________________________ @@ -230,20 +237,21 @@ UWord32 UL_subNs (UWord32 UL_var1, UWord32 UL_var2, UWord16 * sgn) { | none | |________________________________________________________________________________| */ -void Mpy_32_16_uu (UWord32 UL_var1, UWord16 uvar2, UWord32 *UL_varout_h, UWord16 *varout_l) { - UWord64 UL64_var1; +void Mpy_32_16_uu( UWord32 UL_var1, UWord16 uvar2, UWord32 *UL_varout_h, UWord16 *varout_l ) +{ + UWord64 UL64_var1; - /* 4294967295 * 65535 < 281474976710655 */ - /* (uint64(2)^16-1 )*(uint64(2)^32-1) < (uint64(2)^(16+32)-1) */ - UL64_var1 = ((UWord64) UL_var1)*((UWord64) uvar2); - *varout_l = (UWord16) UL64_var1; - *UL_varout_h = (UWord32) (UL64_var1>>16); + /* 4294967295 * 65535 < 281474976710655 */ + /* (uint64(2)^16-1 )*(uint64(2)^32-1) < (uint64(2)^(16+32)-1) */ + UL64_var1 = ( (UWord64) UL_var1 ) * ( (UWord64) uvar2 ); + *varout_l = (UWord16) UL64_var1; + *UL_varout_h = (UWord32) ( UL64_var1 >> 16 ); -#if (WMOPS) - multiCounter[currCounter].Mpy_32_16_uu++; +#if ( WMOPS ) + multiCounter[currCounter].Mpy_32_16_uu++; #endif /* if WMOPS */ - return; + return; } /*__________________________________________________________________________________ @@ -281,18 +289,19 @@ void Mpy_32_16_uu (UWord32 UL_var1, UWord16 uvar2, UWord32 *UL_varout_h, UWord16 | none | |__________________________________________________________________________________| */ -void Mpy_32_32_uu (UWord32 UL_var1, UWord32 UL_var2, UWord32 *UL_varout_h, UWord32 *UL_varout_l) { - UWord64 UL64_var1; - /* (uint64(2)^32-1 )*(uint64(2)^32-1) < (uint64(2)^(32+32)-1) */ - UL64_var1 = ((UWord64) UL_var1)*((UWord64) UL_var2); - *UL_varout_h = (UWord32)(UL64_var1>>32); - *UL_varout_l = (UWord32)(UL64_var1); - -#if (WMOPS) - multiCounter[currCounter].Mpy_32_32_uu++; +void Mpy_32_32_uu( UWord32 UL_var1, UWord32 UL_var2, UWord32 *UL_varout_h, UWord32 *UL_varout_l ) +{ + UWord64 UL64_var1; + /* (uint64(2)^32-1 )*(uint64(2)^32-1) < (uint64(2)^(32+32)-1) */ + UL64_var1 = ( (UWord64) UL_var1 ) * ( (UWord64) UL_var2 ); + *UL_varout_h = (UWord32) ( UL64_var1 >> 32 ); + *UL_varout_l = (UWord32) ( UL64_var1 ); + +#if ( WMOPS ) + multiCounter[currCounter].Mpy_32_32_uu++; #endif /* if WMOPS */ - return; + return; } /*_____________________________________________________________________________________ @@ -331,76 +340,79 @@ void Mpy_32_32_uu (UWord32 UL_var1, UWord32 UL_var2, UWord32 *UL_varout_h, UWord | | |_____________________________________________________________________________________| */ -UWord32 UL_Mpy_32_32 (UWord32 UL_var1, UWord32 UL_var2) { - UWord32 UL_varout_l; +UWord32 UL_Mpy_32_32( UWord32 UL_var1, UWord32 UL_var2 ) +{ + UWord32 UL_varout_l; -#define MASK32 0xFFFFFFFFU - /* MASK32 may be needed in case Hardware is using larger than 32 bits for UWord32 type */ - UL_varout_l = (UL_var1&MASK32)*(UL_var2&MASK32); - UL_varout_l = UL_varout_l&MASK32; +#define MASK32 0xFFFFFFFFU + /* MASK32 may be needed in case Hardware is using larger than 32 bits for UWord32 type */ + UL_varout_l = ( UL_var1 & MASK32 ) * ( UL_var2 & MASK32 ); + UL_varout_l = UL_varout_l & MASK32; #undef MASK32 -#if (WMOPS) - multiCounter[currCounter].UL_Mpy_32_32++; +#if ( WMOPS ) + multiCounter[currCounter].UL_Mpy_32_32++; #endif /* if WMOPS */ - return UL_varout_l; + return UL_varout_l; } -#ifdef STL_TYPECASTS +#ifdef STL_TYPECASTS /* (Reuse of existing signed STL "L" operators) with typecasting to make the resulting "UL" code a lot cleaner and more readable. */ -UWord32 UL_lshl( UWord32 UL_var1, Word16 var2) { - return( (UWord32)L_lshl( (Word32) UL_var1, var2)); +UWord32 UL_lshl( UWord32 UL_var1, Word16 var2 ) +{ + return ( (UWord32) L_lshl( (Word32) UL_var1, var2 ) ); } -UWord32 UL_lshr( UWord32 UL_var1, Word16 var2) { - return( (UWord32)L_lshr( (Word32) UL_var1, var2) ); +UWord32 UL_lshr( UWord32 UL_var1, Word16 var2 ) +{ + return ( (UWord32) L_lshr( (Word32) UL_var1, var2 ) ); } -UWord32 UL_and(UWord32 UL_var1, UWord32 UL_var2 ) +UWord32 UL_and( UWord32 UL_var1, UWord32 UL_var2 ) { - return (UWord32) L_and((Word32)UL_var1,(Word32) UL_var2); + return (UWord32) L_and( (Word32) UL_var1, (Word32) UL_var2 ); } -UWord32 UL_or(UWord32 UL_var1, UWord32 UL_var2 ) +UWord32 UL_or( UWord32 UL_var1, UWord32 UL_var2 ) { - return (UWord32) L_or((Word32)UL_var1,(Word32) UL_var2); + return (UWord32) L_or( (Word32) UL_var1, (Word32) UL_var2 ); } -UWord32 UL_xor(UWord32 UL_var1, UWord32 UL_var2 ) +UWord32 UL_xor( UWord32 UL_var1, UWord32 UL_var2 ) { - return (UWord32) L_xor((Word32)UL_var1,(Word32) UL_var2); + return (UWord32) L_xor( (Word32) UL_var1, (Word32) UL_var2 ); } -UWord32 UL_deposit_h(UWord16 uvar1) +UWord32 UL_deposit_h( UWord16 uvar1 ) { - return (UWord32) L_deposit_h((Word32)uvar1); + return (UWord32) L_deposit_h( (Word32) uvar1 ); } -UWord16 u_extract_h(UWord32 UL_var1) +UWord16 u_extract_h( UWord32 UL_var1 ) { - return (UWord16) extract_h((Word32)UL_var1); + return (UWord16) extract_h( (Word32) UL_var1 ); } -UWord16 u_extract_l(UWord32 UL_var1) +UWord16 u_extract_l( UWord32 UL_var1 ) { - return (UWord32)extract_l((Word32)UL_var1); + return (UWord32) extract_l( (Word32) UL_var1 ); } -/* enable convenient reuse of Non-saturating UL_subNs , UL_addNs while "D"iscarding the sgn/wrap output flags */ -UWord32 UL_subNsD(UWord32 UL_var1, UWord32 UL_var2 ) -{ +/* enable convenient reuse of Non-saturating UL_subNs , UL_addNs while "D"iscarding the sgn/wrap output flags */ +UWord32 UL_subNsD( UWord32 UL_var1, UWord32 UL_var2 ) +{ UWord16 dummy_sign; - return UL_subNs(UL_var1,UL_var2,&dummy_sign ); + return UL_subNs( UL_var1, UL_var2, &dummy_sign ); } -UWord32 UL_addNsD(UWord32 UL_var1, UWord32 UL_var2 ) -{ - UWord16 dummy_wrap; - return UL_addNs(UL_var1,UL_var2,&dummy_wrap ); +UWord32 UL_addNsD( UWord32 UL_var1, UWord32 UL_var2 ) +{ + UWord16 dummy_wrap; + return UL_addNs( UL_var1, UL_var2, &dummy_wrap ); } #endif diff --git a/lib_com/enhUL32.h b/lib_com/enhUL32.h index 7b3787289..240dead79 100644 --- a/lib_com/enhUL32.h +++ b/lib_com/enhUL32.h @@ -15,18 +15,18 @@ * Constants and Globals * *****************************************************************************/ -#define STL_TYPECASTS /* logical shift and bitwise manipulation functions */ - /* algorithmically exact to existing signed L_lshr and L_lshr */ +#define STL_TYPECASTS /* logical shift and bitwise manipulation functions */ + /* algorithmically exact to existing signed L_lshr and L_lshr */ #include "stl.h" -#ifndef UWord64 -#define UWord64 unsigned long long /* for local use inside UL_Mpy_32_* */ +#ifndef UWord64 +#define UWord64 unsigned long long /* for local use inside UL_Mpy_32_* */ #endif -#if (WMOPS) +#if ( WMOPS ) #include "count.h" -extern BASIC_OP multiCounter[MAXCOUNTERS]; /* existing signed counters are reused for unsigedn operators */ +extern BASIC_OP multiCounter[MAXCOUNTERS]; /* existing signed counters are reused for unsigedn operators */ extern int currCounter; #endif /* if WMOPS */ @@ -36,16 +36,16 @@ extern int currCounter; * *****************************************************************************/ #ifdef ENH_U_32_BIT_OPERATOR -UWord32 UL_addNs (UWord32 a, UWord32 b, UWord16* wrap); -UWord32 UL_subNs (UWord32 a, UWord32 b, UWord16* sgn); +UWord32 UL_addNs( UWord32 a, UWord32 b, UWord16 *wrap ); +UWord32 UL_subNs( UWord32 a, UWord32 b, UWord16 *sgn ); -UWord32 UL_Mpy_32_32 (UWord32 a, UWord32 b); -void Mpy_32_32_uu (UWord32 a, UWord32 b, UWord32 *c_h, UWord32 *c_l); /* does not saturate */ -void Mpy_32_16_uu (UWord32 a, UWord16 b, UWord32 *c_h, UWord16 *c_l); /* does not saturate */ +UWord32 UL_Mpy_32_32( UWord32 a, UWord32 b ); +void Mpy_32_32_uu( UWord32 a, UWord32 b, UWord32 *c_h, UWord32 *c_l ); /* does not saturate */ +void Mpy_32_16_uu( UWord32 a, UWord16 b, UWord32 *c_h, UWord16 *c_l ); /* does not saturate */ -Word16 norm_ul_float (UWord32 UL_var1); -UWord32 UL_deposit_l (UWord16); /* deposit low without sign extension */ -#endif /* ENH_U_32_BIT_OPERATOR */ +Word16 norm_ul_float( UWord32 UL_var1 ); +UWord32 UL_deposit_l( UWord16 ); /* deposit low without sign extension */ +#endif /* ENH_U_32_BIT_OPERATOR */ /***************************************************************************** * @@ -53,22 +53,22 @@ UWord32 UL_deposit_l (UWord16); /* deposit low without sign extensio * *****************************************************************************/ -#ifdef STL_TYPECASTS +#ifdef STL_TYPECASTS /* (Reuse of existing signed STL "L" operators) with typecasting to make the resulting "UL" code a lot cleaner and more readable. */ -UWord32 UL_lshl( UWord32 UL_var1, Word16 var2); -UWord32 UL_lshr( UWord32 UL_var1, Word16 var2); -UWord32 UL_and(UWord32 UL_var1, UWord32 UL_var2 ); -UWord32 UL_or(UWord32 UL_var1, UWord32 UL_var2 ); -UWord32 UL_xor(UWord32 UL_var1, UWord32 UL_var2 ); -UWord32 UL_deposit_h(UWord16 uvar1); -UWord16 u_extract_h(UWord32 UL_var1); -UWord16 u_extract_l(UWord32 UL_var1); +UWord32 UL_lshl( UWord32 UL_var1, Word16 var2 ); +UWord32 UL_lshr( UWord32 UL_var1, Word16 var2 ); +UWord32 UL_and( UWord32 UL_var1, UWord32 UL_var2 ); +UWord32 UL_or( UWord32 UL_var1, UWord32 UL_var2 ); +UWord32 UL_xor( UWord32 UL_var1, UWord32 UL_var2 ); +UWord32 UL_deposit_h( UWord16 uvar1 ); +UWord16 u_extract_h( UWord32 UL_var1 ); +UWord16 u_extract_l( UWord32 UL_var1 ); -/* enable convenient reuse of Non-saturating UL_subNs , UL_addNs - while "D"iscarding the sgn/wrap output flags */ -UWord32 UL_subNsD(UWord32 UL_var1, UWord32 UL_var2 ); -UWord32 UL_addNsD(UWord32 UL_var1, UWord32 UL_var2 ); +/* enable convenient reuse of Non-saturating UL_subNs , UL_addNs + while "D"iscarding the sgn/wrap output flags */ +UWord32 UL_subNsD( UWord32 UL_var1, UWord32 UL_var2 ); +UWord32 UL_addNsD( UWord32 UL_var1, UWord32 UL_var2 ); #endif #endif /*_ENHUL32_H*/ diff --git a/lib_com/enhancer_fx.c b/lib_com/enhancer_fx.c index d6290b47e..6336dd685 100644 --- a/lib_com/enhancer_fx.c +++ b/lib_com/enhancer_fx.c @@ -2,27 +2,27 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "rom_com.h" /* Static table prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "rom_com.h" /* Static table prototypes */ #include "basop_util.h" /*---------------------------------------------------------------------* * Local constants *---------------------------------------------------------------------*/ -#define pitch_0_9 14746 /* 0.9 in Q14 */ -#define pitch_0_6 9830 /* 0.6 in Q14 */ -#define SIZE 64 -#define SIZE2 32 -#define NUM_STAGES 5 +#define pitch_0_9 14746 /* 0.9 in Q14 */ +#define pitch_0_6 9830 /* 0.6 in Q14 */ +#define SIZE 64 +#define SIZE2 32 +#define NUM_STAGES 5 /*---------------------------------------------------------------------* * Local functions *---------------------------------------------------------------------*/ -static void phase_dispersion_fx(Word32 gain_code,Word16 gain_pit,Word16 code[],Word16 mode,struct dispMem_fx *dm_fx); -static void agc2_fx(const Word16 *sig_in,Word16 *sig_out,const Word16 l_trm); +static void phase_dispersion_fx( Word32 gain_code, Word16 gain_pit, Word16 code[], Word16 mode, struct dispMem_fx *dm_fx ); +static void agc2_fx( const Word16 *sig_in, Word16 *sig_out, const Word16 l_trm ); /*======================================================================================*/ /* FUNCTION : enhancer_fx() */ @@ -59,21 +59,21 @@ static void agc2_fx(const Word16 *sig_in,Word16 *sig_out,const Word16 l_trm); /* _ None */ /*======================================================================================*/ void enhancer_fx( - const Word32 core_brate, /* i : decoder bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 coder_type, /* i : coder type */ - const Word16 i_subfr, /* i : subframe number */ - const Word16 L_frame, /* i : frame size */ - const Word16 voice_fac, /* i : subframe voicing estimation Q15 */ - const Word16 stab_fac, /* i : LP filter stablility measure Q15 */ - Word32 norm_gain_code, /* i : normalised innovative cb. gain Q16 */ - const Word16 gain_inov, /* i : gain of the unscaled innovation Q12 */ - Word32 *gc_threshold,/* i/o: gain code threshold Q16 */ - Word16 *code, /* i/o: innovation Q12 */ - Word16 *exc2, /* i/o: adapt. excitation/total exc. Q_exc*/ - const Word16 gain_pit, /* i : quantized pitch gain Q14 */ - struct dispMem_fx *dm_fx, /* i/o: phase dispersion algorithm memory */ - const Word16 Q_exc /* i : Q of the excitation */ + const Word32 core_brate, /* i : decoder bitrate */ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const Word16 coder_type, /* i : coder type */ + const Word16 i_subfr, /* i : subframe number */ + const Word16 L_frame, /* i : frame size */ + const Word16 voice_fac, /* i : subframe voicing estimation Q15 */ + const Word16 stab_fac, /* i : LP filter stablility measure Q15 */ + Word32 norm_gain_code, /* i : normalised innovative cb. gain Q16 */ + const Word16 gain_inov, /* i : gain of the unscaled innovation Q12 */ + Word32 *gc_threshold, /* i/o: gain code threshold Q16 */ + Word16 *code, /* i/o: innovation Q12 */ + Word16 *exc2, /* i/o: adapt. excitation/total exc. Q_exc*/ + const Word16 gain_pit, /* i : quantized pitch gain Q14 */ + struct dispMem_fx *dm_fx, /* i/o: phase dispersion algorithm memory */ + const Word16 Q_exc /* i : Q of the excitation */ ) { Word16 tmp, fac, *pt_exc2; @@ -84,9 +84,8 @@ void enhancer_fx( Word16 excp[L_SUBFR], sc; - pit_sharp = gain_pit; - move16(); /* to remove gcc warning */ + move16(); /* to remove gcc warning */ pt_exc2 = exc2 + i_subfr; move16(); @@ -96,39 +95,39 @@ void enhancer_fx( i = 2; move16(); /* no dispersion */ - IF (Opt_AMR_WB) + IF( Opt_AMR_WB ) { - IF ( LE_32(core_brate,ACELP_6k60)) + IF( LE_32( core_brate, ACELP_6k60 ) ) { i = 0; - move16(); /* high dispersion */ + move16(); /* high dispersion */ } - ELSE if ( LE_32(core_brate,ACELP_8k85)) + ELSE if ( LE_32( core_brate, ACELP_8k85 ) ) { i = 1; - move16(); /* low dispersion */ + move16(); /* low dispersion */ } } - ELSE IF( NE_16(coder_type,UNVOICED)) + ELSE IF( NE_16( coder_type, UNVOICED ) ) { test(); test(); test(); test(); - IF ( LE_32(core_brate,ACELP_7k20)) + IF( LE_32( core_brate, ACELP_7k20 ) ) { i = 0; move16(); /* high dispersion */ } - ELSE if ( ( EQ_16(coder_type,GENERIC)||EQ_16(coder_type,TRANSITION)||EQ_16(coder_type,AUDIO)||EQ_16(coder_type,INACTIVE))&&LE_32(core_brate,ACELP_9k60)) + ELSE if ( ( EQ_16( coder_type, GENERIC ) || EQ_16( coder_type, TRANSITION ) || EQ_16( coder_type, AUDIO ) || EQ_16( coder_type, INACTIVE ) ) && LE_32( core_brate, ACELP_9k60 ) ) { i = 1; - move16(); /* low dispersion */ + move16(); /* low dispersion */ } } - phase_dispersion_fx(norm_gain_code, gain_pit, code, i, dm_fx); + phase_dispersion_fx( norm_gain_code, gain_pit, code, i, dm_fx ); /*------------------------------------------------------------ * noise enhancer @@ -141,37 +140,37 @@ void enhancer_fx( /* tmp = 0.5f * (1.0f - voice_fac) */ #ifdef BASOP_NOGLOB - tmp = msu_r_sat(0x40000000, voice_fac, 16384); /*Q15 */ /* 1=unvoiced, 0=voiced */ + tmp = msu_r_sat( 0x40000000, voice_fac, 16384 ); /*Q15 */ /* 1=unvoiced, 0=voiced */ #else - tmp = msu_r(0x40000000, voice_fac, 16384); /*Q15 */ /* 1=unvoiced, 0=voiced */ + tmp = msu_r( 0x40000000, voice_fac, 16384 ); /*Q15 */ /* 1=unvoiced, 0=voiced */ #endif /* fac = stab_fac * tmp */ - fac = mult(stab_fac, tmp); /*Q15*/ + fac = mult( stab_fac, tmp ); /*Q15*/ - IF (LT_32(norm_gain_code, *gc_threshold)) + IF( LT_32( norm_gain_code, *gc_threshold ) ) { - L_tmp = Madd_32_16(norm_gain_code, norm_gain_code, 6226);/*Q16 */ - L_tmp = L_min(L_tmp, *gc_threshold);/*Q16 */ + L_tmp = Madd_32_16( norm_gain_code, norm_gain_code, 6226 ); /*Q16 */ + L_tmp = L_min( L_tmp, *gc_threshold ); /*Q16 */ } ELSE { - L_tmp = Mult_32_16(norm_gain_code, 27536);/*Q16 */ - L_tmp = L_max(L_tmp, *gc_threshold); /*Q16 */ + L_tmp = Mult_32_16( norm_gain_code, 27536 ); /*Q16 */ + L_tmp = L_max( L_tmp, *gc_threshold ); /*Q16 */ } *gc_threshold = L_tmp; move32(); /*Q16 */ /* gain_code = (fac * tmp) + (1.0 - fac) * gain_code ==> fac * (tmp - gain_code) + gain_code */ - L_tmp = L_sub(L_tmp, norm_gain_code); /*Q16 */ - norm_gain_code = Madd_32_16(norm_gain_code, L_tmp, fac);/*Q16 */ + L_tmp = L_sub( L_tmp, norm_gain_code ); /*Q16 */ + norm_gain_code = Madd_32_16( norm_gain_code, L_tmp, fac ); /*Q16 */ /* gain_code *= gain_inov - Inverse the normalization */ - L_tmp = Mult_32_16(norm_gain_code, gain_inov); /*Q13*/ /* gain_inov in Q12 */ + L_tmp = Mult_32_16( norm_gain_code, gain_inov ); /*Q13*/ /* gain_inov in Q12 */ sc = 6; move16(); - gain_code_hi = round_fx(L_shl(L_tmp, add(Q_exc, 3))); /* in Q_exc */ + gain_code_hi = round_fx( L_shl( L_tmp, add( Q_exc, 3 ) ) ); /* in Q_exc */ /*------------------------------------------------------------* * pitch enhancer @@ -181,49 +180,49 @@ void enhancer_fx( * filter to decrease energy of code at low frequency. *------------------------------------------------------------*/ test(); - IF( !Opt_AMR_WB && EQ_16(coder_type,UNVOICED)) + IF( !Opt_AMR_WB && EQ_16( coder_type, UNVOICED ) ) { /* Copy(code, exc2, L_SUBFR) */ - FOR (i = 0; i < L_SUBFR; i++) + FOR( i = 0; i < L_SUBFR; i++ ) { - pt_exc2[i] = round_fx(L_shl(L_mult(gain_code_hi, code[i]), sc)); /*Q0 */ /* code in Q12 (Q9 for encoder) */ + pt_exc2[i] = round_fx( L_shl( L_mult( gain_code_hi, code[i] ), sc ) ); /*Q0 */ /* code in Q12 (Q9 for encoder) */ } } ELSE { test(); test(); - IF ( Opt_AMR_WB && ( EQ_32(core_brate,ACELP_8k85)||EQ_32(core_brate,ACELP_6k60))) + IF( Opt_AMR_WB && ( EQ_32( core_brate, ACELP_8k85 ) || EQ_32( core_brate, ACELP_6k60 ) ) ) { #ifdef BASOP_NOGLOB - pit_sharp = shl_sat(gain_pit, 1); /* saturation can occur here Q14 -> Q15 */ + pit_sharp = shl_sat( gain_pit, 1 ); /* saturation can occur here Q14 -> Q15 */ #else - pit_sharp = shl(gain_pit, 1); /* saturation can occur here Q14 -> Q15 */ + pit_sharp = shl( gain_pit, 1 ); /* saturation can occur here Q14 -> Q15 */ #endif /* saturation takes care of "if (pit_sharp > 1.0) { pit_sharp=1.0; }" */ - IF (GT_16(pit_sharp, 16384)) + IF( GT_16( pit_sharp, 16384 ) ) { - tmp16 = mult(pit_sharp, 8192); - FOR (i = 0; i < L_SUBFR; i++) + tmp16 = mult( pit_sharp, 8192 ); + FOR( i = 0; i < L_SUBFR; i++ ) { /* excp[i] = pt_exc2[i] * pit_sharp * 0.25 */ - excp[i] = mult_r(pt_exc2[i], tmp16); + excp[i] = mult_r( pt_exc2[i], tmp16 ); move16(); } } } - IF ( EQ_16(L_frame, L_FRAME16k)) + IF( EQ_16( L_frame, L_FRAME16k ) ) { /* tmp = 0.150 * (1.0 + voice_fac) */ /* 0.30=voiced, 0=unvoiced */ - tmp = mac_r(0x10000000L, voice_fac, 4915);/*Q15 */ + tmp = mac_r( 0x10000000L, voice_fac, 4915 ); /*Q15 */ } ELSE { /* tmp = 0.125 * (1.0 + voice_fac) */ /* 0.25=voiced, 0=unvoiced */ - tmp = mac_r(0x10000000L, voice_fac, 4096);/*Q15 */ + tmp = mac_r( 0x10000000L, voice_fac, 4096 ); /*Q15 */ } /*----------------------------------------------------------------- @@ -232,22 +231,22 @@ void enhancer_fx( * This is applied to code and add_fxed to exc2 *-----------------------------------------------------------------*/ /* pt_exc2[0] += code[0] - tmp * code[1] */ - L_tmp = L_deposit_h(code[0]); /* if Enc :Q9 * Q15 -> Q25 */ - L_tmp = L_msu(L_tmp, code[1], tmp); /* Q12 * Q15 -> Q28 */ + L_tmp = L_deposit_h( code[0] ); /* if Enc :Q9 * Q15 -> Q25 */ + L_tmp = L_msu( L_tmp, code[1], tmp ); /* Q12 * Q15 -> Q28 */ #ifdef BASOP_NOGLOB L_tmp = L_shl_sat( L_mult( gain_code_hi, extract_h( L_tmp ) ), sc ); - pt_exc2[0] = msu_r_sat(L_tmp, -32768, pt_exc2[0]); + pt_exc2[0] = msu_r_sat( L_tmp, -32768, pt_exc2[0] ); #else - L_tmp = L_shl(L_mult(gain_code_hi, extract_h(L_tmp)), sc); - pt_exc2[0] = msu_r(L_tmp, -32768, pt_exc2[0]); + L_tmp = L_shl( L_mult( gain_code_hi, extract_h( L_tmp ) ), sc ); + pt_exc2[0] = msu_r( L_tmp, -32768, pt_exc2[0] ); #endif - move16();/* in Q_exc */ + move16(); /* in Q_exc */ - FOR (i = 1; i < L_SUBFR-1; i++) + FOR( i = 1; i < L_SUBFR - 1; i++ ) { /* pt_exc2[i] += code[i] - tmp * code[i-1] - tmp * code[i+1] */ - L_tmp = L_msu(-32768, code[i], -32768); - L_tmp = L_msu(L_tmp, code[i + 1], tmp); + L_tmp = L_msu( -32768, code[i], -32768 ); + L_tmp = L_msu( L_tmp, code[i + 1], tmp ); #ifdef BASOP_NOGLOB tmp16 = msu_r_sat( L_tmp, code[i - 1], tmp ); L_tmp = L_shl_sat( L_mult( gain_code_hi, tmp16 ), sc ); @@ -261,33 +260,33 @@ void enhancer_fx( } /* pt_exc2[L_SUBFR-1] += code[L_SUBFR-1] - tmp * code[L_SUBFR-2] */ - L_tmp = L_deposit_h(code[L_SUBFR - 1]);/*Q28 */ - L_tmp = L_msu(L_tmp, code[L_SUBFR - 2], tmp);/*Q28 */ - L_tmp = L_shl(L_mult(gain_code_hi, extract_h(L_tmp)), sc); + L_tmp = L_deposit_h( code[L_SUBFR - 1] ); /*Q28 */ + L_tmp = L_msu( L_tmp, code[L_SUBFR - 2], tmp ); /*Q28 */ + L_tmp = L_shl( L_mult( gain_code_hi, extract_h( L_tmp ) ), sc ); #ifdef BASOP_NOGLOB pt_exc2[L_SUBFR - 1] = msu_r_sat( L_tmp, -32768, pt_exc2[L_SUBFR - 1] ); #else - pt_exc2[L_SUBFR - 1] = msu_r(L_tmp, -32768, pt_exc2[L_SUBFR - 1]); + pt_exc2[L_SUBFR - 1] = msu_r( L_tmp, -32768, pt_exc2[L_SUBFR - 1] ); #endif - move16();/* in Q_exc */ + move16(); /* in Q_exc */ test(); test(); - IF ( Opt_AMR_WB && ( EQ_32(core_brate,ACELP_8k85)||EQ_32(core_brate,ACELP_6k60))) + IF( Opt_AMR_WB && ( EQ_32( core_brate, ACELP_8k85 ) || EQ_32( core_brate, ACELP_6k60 ) ) ) { - IF (GT_16(pit_sharp, 16384)) + IF( GT_16( pit_sharp, 16384 ) ) { - FOR (i = 0; i < L_SUBFR; i++) + FOR( i = 0; i < L_SUBFR; i++ ) { /* excp[i] += pt_exc2[i] */ #ifdef BASOP_NOGLOB excp[i] = add_sat( excp[i], pt_exc2[i] ); #else - excp[i] = add(excp[i], pt_exc2[i]); + excp[i] = add( excp[i], pt_exc2[i] ); #endif move16(); } - agc2_fx(pt_exc2, excp, L_SUBFR); - Copy(excp, pt_exc2, L_SUBFR); + agc2_fx( pt_exc2, excp, L_SUBFR ); + Copy( excp, pt_exc2, L_SUBFR ); } } } @@ -329,23 +328,23 @@ void enhancer_fx( /* _ None */ /*======================================================================================*/ void enhancer_ivas_fx( - const Word16 codec_mode, /* i : flag indicating Codec Mode */ - const Word32 core_brate, /* i : decoder bitrate */ - const int16_t cbk_index, /* i : */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 coder_type, /* i : coder type */ - const Word16 i_subfr, /* i : subframe number */ - const Word16 L_frame, /* i : frame size */ - const Word16 voice_fac, /* i : subframe voicing estimation Q15 */ - const Word16 stab_fac, /* i : LP filter stablility measure Q15 */ - Word32 norm_gain_code, /* i : normalised innovative cb. gain Q16 */ - const Word16 gain_inov, /* i : gain of the unscaled innovation Q12 */ - Word32 *gc_threshold,/* i/o: gain code threshold Q16 */ - Word16 *code, /* i/o: innovation Q12 */ - Word16 *exc2, /* i/o: adapt. excitation/total exc. Q_exc*/ - const Word16 gain_pit, /* i : quantized pitch gain Q14 */ - struct dispMem_fx *dm_fx, /* i/o: phase dispersion algorithm memory */ - const Word16 Q_exc /* i : Q of the excitation */ + const Word16 codec_mode, /* i : flag indicating Codec Mode */ + const Word32 core_brate, /* i : decoder bitrate */ + const int16_t cbk_index, /* i : */ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const Word16 coder_type, /* i : coder type */ + const Word16 i_subfr, /* i : subframe number */ + const Word16 L_frame, /* i : frame size */ + const Word16 voice_fac, /* i : subframe voicing estimation Q15 */ + const Word16 stab_fac, /* i : LP filter stablility measure Q15 */ + Word32 norm_gain_code, /* i : normalised innovative cb. gain Q16 */ + const Word16 gain_inov, /* i : gain of the unscaled innovation Q12 */ + Word32 *gc_threshold, /* i/o: gain code threshold Q16 */ + Word16 *code, /* i/o: innovation Q12 */ + Word16 *exc2, /* i/o: adapt. excitation/total exc. Q_exc*/ + const Word16 gain_pit, /* i : quantized pitch gain Q14 */ + struct dispMem_fx *dm_fx, /* i/o: phase dispersion algorithm memory */ + const Word16 Q_exc /* i : Q of the excitation */ ) { Word16 tmp, fac, *pt_exc2; @@ -356,9 +355,8 @@ void enhancer_ivas_fx( Word16 excp[L_SUBFR], sc; - pit_sharp = gain_pit; - move16(); /* to remove gcc warning */ + move16(); /* to remove gcc warning */ pt_exc2 = exc2 + i_subfr; move16(); @@ -368,35 +366,35 @@ void enhancer_ivas_fx( i = 2; move16(); /* no dispersion */ - IF(Opt_AMR_WB) + IF( Opt_AMR_WB ) { - IF(LE_32(core_brate, ACELP_6k60)) + IF( LE_32( core_brate, ACELP_6k60 ) ) { i = 0; - move16(); /* high dispersion */ + move16(); /* high dispersion */ } - ELSE if (LE_32(core_brate, ACELP_8k85)) + ELSE if ( LE_32( core_brate, ACELP_8k85 ) ) { i = 1; - move16(); /* low dispersion */ + move16(); /* low dispersion */ } } - ELSE IF( EQ_16(codec_mode, MODE1) && NE_16(coder_type, UNVOICED)) + ELSE IF( EQ_16( codec_mode, MODE1 ) && NE_16( coder_type, UNVOICED ) ) { test(); test(); test(); test(); - IF(LE_32(core_brate, ACELP_7k20)) + IF( LE_32( core_brate, ACELP_7k20 ) ) { i = 0; move16(); /* high dispersion */ } - ELSE IF ((EQ_16(coder_type, GENERIC) || EQ_16(coder_type, TRANSITION) || EQ_16(coder_type, AUDIO) || EQ_16(coder_type, INACTIVE)) && LE_32(core_brate, ACELP_9k60)) + ELSE IF( ( EQ_16( coder_type, GENERIC ) || EQ_16( coder_type, TRANSITION ) || EQ_16( coder_type, AUDIO ) || EQ_16( coder_type, INACTIVE ) ) && LE_32( core_brate, ACELP_9k60 ) ) { i = 1; - move16(); /* low dispersion */ + move16(); /* low dispersion */ } } ELSE IF( EQ_16( codec_mode, MODE2 ) ) @@ -410,12 +408,12 @@ void enhancer_ivas_fx( i = 1; /* low dispersion */ } } - ELSE IF( EQ_16(codec_mode, MODE1) && EQ_16(coder_type, UNVOICED) && cbk_index /*uc_two_stage_flag*/ ) + ELSE IF( EQ_16( codec_mode, MODE1 ) && EQ_16( coder_type, UNVOICED ) && cbk_index /*uc_two_stage_flag*/ ) { i = 0; /* high dispersion */ } - phase_dispersion_fx(norm_gain_code, gain_pit, code, i, dm_fx); + phase_dispersion_fx( norm_gain_code, gain_pit, code, i, dm_fx ); /*------------------------------------------------------------ * noise enhancer @@ -426,39 +424,39 @@ void enhancer_ivas_fx( * This decreases by 3 dB noise energy variation. *-----------------------------------------------------------*/ - /* tmp = 0.5f * (1.0f - voice_fac) */ + /* tmp = 0.5f * (1.0f - voice_fac) */ #ifdef BASOP_NOGLOB - tmp = msu_r_sat(0x40000000, voice_fac, 16384); /*Q15 */ /* 1=unvoiced, 0=voiced */ + tmp = msu_r_sat( 0x40000000, voice_fac, 16384 ); /*Q15 */ /* 1=unvoiced, 0=voiced */ #else - tmp = msu_r(0x40000000, voice_fac, 16384); /*Q15 */ /* 1=unvoiced, 0=voiced */ + tmp = msu_r( 0x40000000, voice_fac, 16384 ); /*Q15 */ /* 1=unvoiced, 0=voiced */ #endif /* fac = stab_fac * tmp */ - fac = mult(stab_fac, tmp); /*Q15*/ + fac = mult( stab_fac, tmp ); /*Q15*/ - IF(LT_32(norm_gain_code, *gc_threshold)) + IF( LT_32( norm_gain_code, *gc_threshold ) ) { - L_tmp = Madd_32_16(norm_gain_code, norm_gain_code, 6226);/*Q16 */ - L_tmp = L_min(L_tmp, *gc_threshold);/*Q16 */ + L_tmp = Madd_32_16( norm_gain_code, norm_gain_code, 6226 ); /*Q16 */ + L_tmp = L_min( L_tmp, *gc_threshold ); /*Q16 */ } ELSE { - L_tmp = Mult_32_16(norm_gain_code, 27536);/*Q16 */ - L_tmp = L_max(L_tmp, *gc_threshold); /*Q16 */ + L_tmp = Mult_32_16( norm_gain_code, 27536 ); /*Q16 */ + L_tmp = L_max( L_tmp, *gc_threshold ); /*Q16 */ } *gc_threshold = L_tmp; move32(); /*Q16 */ /* gain_code = (fac * tmp) + (1.0 - fac) * gain_code ==> fac * (tmp - gain_code) + gain_code */ - L_tmp = L_sub(L_tmp, norm_gain_code); /*Q16 */ - norm_gain_code = Madd_32_16(norm_gain_code, L_tmp, fac);/*Q16 */ + L_tmp = L_sub( L_tmp, norm_gain_code ); /*Q16 */ + norm_gain_code = Madd_32_16( norm_gain_code, L_tmp, fac ); /*Q16 */ /* gain_code *= gain_inov - Inverse the normalization */ - L_tmp = Mult_32_16(norm_gain_code, gain_inov); /*Q13*/ /* gain_inov in Q12 */ + L_tmp = Mult_32_16( norm_gain_code, gain_inov ); /*Q13*/ /* gain_inov in Q12 */ sc = 6; move16(); - gain_code_hi = round_fx(L_shl(L_tmp, add(Q_exc, 3))); /* in Q_exc */ + gain_code_hi = round_fx( L_shl( L_tmp, add( Q_exc, 3 ) ) ); /* in Q_exc */ /*------------------------------------------------------------* * pitch enhancer @@ -468,100 +466,100 @@ void enhancer_ivas_fx( * filter to decrease energy of code at low frequency. *------------------------------------------------------------*/ test(); - IF(!Opt_AMR_WB && EQ_16(coder_type, UNVOICED)) + IF( !Opt_AMR_WB && EQ_16( coder_type, UNVOICED ) ) { /* Copy(code, exc2, L_SUBFR) */ - FOR(i = 0; i < L_SUBFR; i++) + FOR( i = 0; i < L_SUBFR; i++ ) { - pt_exc2[i] = round_fx(L_shl(L_mult(gain_code_hi, code[i]), sc)); /*Q0 */ /* code in Q12 (Q9 for encoder) */ + pt_exc2[i] = round_fx( L_shl( L_mult( gain_code_hi, code[i] ), sc ) ); /*Q0 */ /* code in Q12 (Q9 for encoder) */ } } ELSE { test(); test(); - IF(Opt_AMR_WB && (EQ_32(core_brate,ACELP_8k85) || EQ_32(core_brate,ACELP_6k60))) + IF( Opt_AMR_WB && ( EQ_32( core_brate, ACELP_8k85 ) || EQ_32( core_brate, ACELP_6k60 ) ) ) { #ifdef BASOP_NOGLOB - pit_sharp = shl_sat(gain_pit, 1); /* saturation can occur here Q14 -> Q15 */ + pit_sharp = shl_sat( gain_pit, 1 ); /* saturation can occur here Q14 -> Q15 */ #else - pit_sharp = shl(gain_pit, 1); /* saturation can occur here Q14 -> Q15 */ + pit_sharp = shl( gain_pit, 1 ); /* saturation can occur here Q14 -> Q15 */ #endif /* saturation takes care of "if (pit_sharp > 1.0) { pit_sharp=1.0; }" */ - IF(GT_16(pit_sharp, 16384)) + IF( GT_16( pit_sharp, 16384 ) ) { - tmp16 = mult(pit_sharp, 8192); - FOR(i = 0; i < L_SUBFR; i++) + tmp16 = mult( pit_sharp, 8192 ); + FOR( i = 0; i < L_SUBFR; i++ ) { /* excp[i] = pt_exc2[i] * pit_sharp * 0.25 */ - excp[i] = mult_r(pt_exc2[i], tmp16); + excp[i] = mult_r( pt_exc2[i], tmp16 ); move16(); } } } - IF(EQ_16(L_frame, L_FRAME16k)) + IF( EQ_16( L_frame, L_FRAME16k ) ) { /* tmp = 0.150 * (1.0 + voice_fac) */ /* 0.30=voiced, 0=unvoiced */ - tmp = mac_r(0x10000000L, voice_fac, 4915);/*Q15 */ + tmp = mac_r( 0x10000000L, voice_fac, 4915 ); /*Q15 */ } ELSE { /* tmp = 0.125 * (1.0 + voice_fac) */ /* 0.25=voiced, 0=unvoiced */ - tmp = mac_r(0x10000000L, voice_fac, 4096);/*Q15 */ + tmp = mac_r( 0x10000000L, voice_fac, 4096 ); /*Q15 */ } - /*----------------------------------------------------------------- - * Do a simple noncasual "sharpening": effectively an FIR - * filter with coefs [-tmp 1.0 -tmp] where tmp=0...0.25. - * This is applied to code and add_fxed to exc2 - *-----------------------------------------------------------------*/ - /* pt_exc2[0] += code[0] - tmp * code[1] */ - L_tmp = L_deposit_h(code[0]); /* if Enc :Q9 * Q15 -> Q25 */ - L_tmp = L_msu(L_tmp, code[1], tmp); /* Q12 * Q15 -> Q28 */ - L_tmp = L_shl(L_mult(gain_code_hi, extract_h(L_tmp)), sc); - pt_exc2[0] = msu_r(L_tmp, -32768, pt_exc2[0]); - move16();/* in Q_exc */ - - FOR(i = 1; i < L_SUBFR - 1; i++) - { - /* pt_exc2[i] += code[i] - tmp * code[i-1] - tmp * code[i+1] */ - L_tmp = L_msu(-32768, code[i], -32768); - L_tmp = L_msu(L_tmp, code[i + 1], tmp); - tmp16 = msu_r(L_tmp, code[i - 1], tmp); - L_tmp = L_shl(L_mult(gain_code_hi, tmp16), sc); + /*----------------------------------------------------------------- + * Do a simple noncasual "sharpening": effectively an FIR + * filter with coefs [-tmp 1.0 -tmp] where tmp=0...0.25. + * This is applied to code and add_fxed to exc2 + *-----------------------------------------------------------------*/ + /* pt_exc2[0] += code[0] - tmp * code[1] */ + L_tmp = L_deposit_h( code[0] ); /* if Enc :Q9 * Q15 -> Q25 */ + L_tmp = L_msu( L_tmp, code[1], tmp ); /* Q12 * Q15 -> Q28 */ + L_tmp = L_shl( L_mult( gain_code_hi, extract_h( L_tmp ) ), sc ); + pt_exc2[0] = msu_r( L_tmp, -32768, pt_exc2[0] ); + move16(); /* in Q_exc */ + + FOR( i = 1; i < L_SUBFR - 1; i++ ) + { + /* pt_exc2[i] += code[i] - tmp * code[i-1] - tmp * code[i+1] */ + L_tmp = L_msu( -32768, code[i], -32768 ); + L_tmp = L_msu( L_tmp, code[i + 1], tmp ); + tmp16 = msu_r( L_tmp, code[i - 1], tmp ); + L_tmp = L_shl( L_mult( gain_code_hi, tmp16 ), sc ); #ifdef BASOP_NOGLOB - pt_exc2[i] = msu_r_sat(L_tmp, -32768, pt_exc2[i]); + pt_exc2[i] = msu_r_sat( L_tmp, -32768, pt_exc2[i] ); #else - pt_exc2[i] = msu_r(L_tmp, -32768, pt_exc2[i]); + pt_exc2[i] = msu_r( L_tmp, -32768, pt_exc2[i] ); #endif - move16(); /* in Q_exc */ - } - - /* pt_exc2[L_SUBFR-1] += code[L_SUBFR-1] - tmp * code[L_SUBFR-2] */ - L_tmp = L_deposit_h(code[L_SUBFR - 1]);/*Q28 */ - L_tmp = L_msu(L_tmp, code[L_SUBFR - 2], tmp);/*Q28 */ - L_tmp = L_shl(L_mult(gain_code_hi, extract_h(L_tmp)), sc); - pt_exc2[L_SUBFR - 1] = msu_r(L_tmp, -32768, pt_exc2[L_SUBFR - 1]); - move16();/* in Q_exc */ - test(); - test(); - IF(Opt_AMR_WB && (EQ_32(core_brate,ACELP_8k85) || EQ_32(core_brate,ACELP_6k60))) - { - IF(GT_16(pit_sharp, 16384)) - { - FOR(i = 0; i < L_SUBFR; i++) - { - /* excp[i] += pt_exc2[i] */ - excp[i] = add(excp[i], pt_exc2[i]); - move16(); - } - agc2_fx(pt_exc2, excp, L_SUBFR); - Copy(excp, pt_exc2, L_SUBFR); - } - } + move16(); /* in Q_exc */ + } + + /* pt_exc2[L_SUBFR-1] += code[L_SUBFR-1] - tmp * code[L_SUBFR-2] */ + L_tmp = L_deposit_h( code[L_SUBFR - 1] ); /*Q28 */ + L_tmp = L_msu( L_tmp, code[L_SUBFR - 2], tmp ); /*Q28 */ + L_tmp = L_shl( L_mult( gain_code_hi, extract_h( L_tmp ) ), sc ); + pt_exc2[L_SUBFR - 1] = msu_r( L_tmp, -32768, pt_exc2[L_SUBFR - 1] ); + move16(); /* in Q_exc */ + test(); + test(); + IF( Opt_AMR_WB && ( EQ_32( core_brate, ACELP_8k85 ) || EQ_32( core_brate, ACELP_6k60 ) ) ) + { + IF( GT_16( pit_sharp, 16384 ) ) + { + FOR( i = 0; i < L_SUBFR; i++ ) + { + /* excp[i] += pt_exc2[i] */ + excp[i] = add( excp[i], pt_exc2[i] ); + move16(); + } + agc2_fx( pt_exc2, excp, L_SUBFR ); + Copy( excp, pt_exc2, L_SUBFR ); + } + } } } @@ -570,23 +568,22 @@ void enhancer_ivas_fx( *---------------------------------------------------------*/ Word16 E_UTIL_enhancer( - Word16 voice_fac, /* i : subframe voicing estimation Q15 */ - Word16 stab_fac, /* i : LP filter stability measure Q15 */ - Word32 gain_code, /* i : innovative cb. gain 15Q16 */ - Word16 gain_inov, /* i : gain of the unscaled innovation Q11 */ - Word32 *gc_threshold, /* i/o: gain code threshold 15Q16 */ - Word16 *code, /* i/o: innovation(in: Q9) code_exp */ - Word16 *exc2, /* i/o: adapt. excitation/total exc. */ - Word16 gain_pit, /* i : Quantized pitch gain 1Q14 */ - Word32 *prev_gain_code, /* i/o: previous codebook gain 15Q16 */ - Word16 prev_gain_pit[], /* i/o: previous pitch gain, size=6 1Q14 */ - Word16 *prev_state, /* i/o: Phase dispersion algorithm memory Q0 */ - Word16 coder_type, /* i : coder type */ - Word16 cdk_index, /* i : */ - Word16 L_subfr, /* i : length of subframe */ - Word16 L_frame, /* i : frame size */ - Word16 Q_new -) + Word16 voice_fac, /* i : subframe voicing estimation Q15 */ + Word16 stab_fac, /* i : LP filter stability measure Q15 */ + Word32 gain_code, /* i : innovative cb. gain 15Q16 */ + Word16 gain_inov, /* i : gain of the unscaled innovation Q11 */ + Word32 *gc_threshold, /* i/o: gain code threshold 15Q16 */ + Word16 *code, /* i/o: innovation(in: Q9) code_exp */ + Word16 *exc2, /* i/o: adapt. excitation/total exc. */ + Word16 gain_pit, /* i : Quantized pitch gain 1Q14 */ + Word32 *prev_gain_code, /* i/o: previous codebook gain 15Q16 */ + Word16 prev_gain_pit[], /* i/o: previous pitch gain, size=6 1Q14 */ + Word16 *prev_state, /* i/o: Phase dispersion algorithm memory Q0 */ + Word16 coder_type, /* i : coder type */ + Word16 cdk_index, /* i : */ + Word16 L_subfr, /* i : length of subframe */ + Word16 L_frame, /* i : frame size */ + Word16 Q_new ) { Word16 disp_mode, i; Word16 tmp, fac, gain; @@ -595,35 +592,38 @@ Word16 E_UTIL_enhancer( Word16 max_cdk_index_uv; move16(); - code_exp = 15-9; - exc2_exp = 15-Q_new; - gain_inov = shr(gain_inov,1); + code_exp = 15 - 9; + exc2_exp = 15 - Q_new; + gain_inov = shr( gain_inov, 1 ); /*-----------------------------------------------------------------* * Phase dispersion to enhance noise at low bit rates *-----------------------------------------------------------------*/ max_cdk_index_uv = 10; move16(); - if ( EQ_16(L_frame, L_FRAME16k)) + if ( EQ_16( L_frame, L_FRAME16k ) ) { max_cdk_index_uv = 14; move16(); } - disp_mode = 2; /* any=off */ move16(); + disp_mode = 2; /* any=off */ + move16(); test(); test(); test(); test(); - IF ( ( (NE_16(coder_type, VOICED))&&(LE_16(cdk_index,2)))||((EQ_16(coder_type,UNVOICED))&&(LE_16(cdk_index,max_cdk_index_uv)))) + IF( ( ( NE_16( coder_type, VOICED ) ) && ( LE_16( cdk_index, 2 ) ) ) || ( ( EQ_16( coder_type, UNVOICED ) ) && ( LE_16( cdk_index, max_cdk_index_uv ) ) ) ) { - disp_mode = 0; /* high */ move16(); + disp_mode = 0; /* high */ + move16(); } - ELSE IF ( (NE_16(coder_type, VOICED))&&(LE_16(cdk_index,7))) + ELSE IF( ( NE_16( coder_type, VOICED ) ) && ( LE_16( cdk_index, 7 ) ) ) { - disp_mode = 1; /* low */ move16(); + disp_mode = 1; /* low */ + move16(); } - phase_dispersion(gain_code, gain_pit,code, &code_exp, disp_mode, prev_gain_code, prev_gain_pit, prev_state, L_subfr); + phase_dispersion( gain_code, gain_pit, code, &code_exp, disp_mode, prev_gain_code, prev_gain_pit, prev_state, L_subfr ); /*------------------------------------------------------------* * noise enhancer * @@ -639,51 +639,51 @@ Word16 E_UTIL_enhancer( /* if gain_code is computed function of energy, noise enhancer is by-passed.*/ BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB - tmp = msu_r_sat(1073741824l/*0.5f Q31*/, 16384/*0.5f Q15*/, voice_fac); /* 1=unvoiced, 0=voiced */ -#else /* BASOP_NOGLOB */ - tmp = msu_r(1073741824l/*0.5f Q31*/, 16384/*0.5f Q15*/, voice_fac); /* 1=unvoiced, 0=voiced */ + tmp = msu_r_sat( 1073741824l /*0.5f Q31*/, 16384 /*0.5f Q15*/, voice_fac ); /* 1=unvoiced, 0=voiced */ +#else /* BASOP_NOGLOB */ + tmp = msu_r( 1073741824l /*0.5f Q31*/, 16384 /*0.5f Q15*/, voice_fac ); /* 1=unvoiced, 0=voiced */ #endif BASOP_SATURATE_WARNING_ON_EVS - fac = mult_r(stab_fac, tmp); /* fac in Q15 */ + fac = mult_r( stab_fac, tmp ); /* fac in Q15 */ - L_tmp = gain_code; /* L_tmp in 15Q16 */ - move32(); + L_tmp = gain_code; /* L_tmp in 15Q16 */ + move32(); - IF (LT_32(L_tmp,*gc_threshold)) + IF( LT_32( L_tmp, *gc_threshold ) ) { - L_tmp = L_shl(Mpy_32_32(L_tmp, 1277752832l/*1.19f/2.0f Q31*/),1); - L_tmp = L_min(L_tmp, *gc_threshold); + L_tmp = L_shl( Mpy_32_32( L_tmp, 1277752832l /*1.19f/2.0f Q31*/ ), 1 ); + L_tmp = L_min( L_tmp, *gc_threshold ); } ELSE { - L_tmp = Mpy_32_32(L_tmp, 1804608000l/*1.0f/1.19f Q31*/); - L_tmp = L_max(L_tmp, *gc_threshold); + L_tmp = Mpy_32_32( L_tmp, 1804608000l /*1.0f/1.19f Q31*/ ); + L_tmp = L_max( L_tmp, *gc_threshold ); } move32(); - *gc_threshold = L_tmp; /* in 15Q16 */ + *gc_threshold = L_tmp; /* in 15Q16 */ /* gain = ( (fac * L_tmp) + (gain_code - fac*gain_code) ) * gain_inov */ /* exponent of L_tmp: 31-16 + 15-11 */ - L_tmp = Mpy_32_16_1(L_add(Mpy_32_16_1(L_tmp, fac), L_sub(gain_code, Mpy_32_16_1(gain_code, fac))), gain_inov); + L_tmp = Mpy_32_16_1( L_add( Mpy_32_16_1( L_tmp, fac ), L_sub( gain_code, Mpy_32_16_1( gain_code, fac ) ) ), gain_inov ); /* exponent gain: 31-16 + 15-11 - tmp */ - tmp = norm_l(L_tmp); + tmp = norm_l( L_tmp ); /* exponent of code: 31-16 + 15-11 - tmp + code_exp */ move16(); - code_exp = sub(add(31-16 + 15-11, code_exp), tmp); + code_exp = sub( add( 31 - 16 + 15 - 11, code_exp ), tmp ); #ifdef BASOP_NOGLOB - L_tmp = L_shl_sat(L_tmp, tmp); - gain = round_fx_sat(L_tmp); + L_tmp = L_shl_sat( L_tmp, tmp ); + gain = round_fx_sat( L_tmp ); #else - L_tmp = L_shl(L_tmp, tmp); - gain = round_fx(L_tmp); + L_tmp = L_shl( L_tmp, tmp ); + gain = round_fx( L_tmp ); #endif - FOR (i=0; iprev_state); - prev_gain_code = &(dm_fx->prev_gain_code); - prev_gain_pit = dm_fx->prev_gain_pit; + prev_state = &( dm_fx->prev_state ); + prev_gain_code = &( dm_fx->prev_gain_code ); + prev_gain_pit = dm_fx->prev_gain_pit; state = 2; move16(); - if (LT_16(gain_pit, pitch_0_9)) + if ( LT_16( gain_pit, pitch_0_9 ) ) { state = 1; move16(); } - if (LT_16(gain_pit, pitch_0_6)) + if ( LT_16( gain_pit, pitch_0_6 ) ) { state = 0; move16(); } - FOR (i = 5; i > 0; i--) + FOR( i = 5; i > 0; i-- ) { prev_gain_pit[i] = prev_gain_pit[i - 1]; move16(); @@ -843,30 +843,30 @@ static void phase_dispersion_fx( #ifdef BASOP_NOGLOB IF( GT_32( L_sub_sat( gain_code, *prev_gain_code ), L_shl_sat( *prev_gain_code, 1 ) ) ) #else - IF (GT_32(L_sub(gain_code, *prev_gain_code), L_shl(*prev_gain_code, 1))) + IF( GT_32( L_sub( gain_code, *prev_gain_code ), L_shl( *prev_gain_code, 1 ) ) ) #endif { - state = s_min(add(state, 1), 2); + state = s_min( add( state, 1 ), 2 ); } ELSE { j = 0; move16(); - FOR (i = 0; i < 6; i++) + FOR( i = 0; i < 6; i++ ) { - j = sub(j, shr(sub(prev_gain_pit[i], pitch_0_6), 15)); + j = sub( j, shr( sub( prev_gain_pit[i], pitch_0_6 ), 15 ) ); } - if (GT_16(j, 2)) + if ( GT_16( j, 2 ) ) { state = 0; move16(); } - if (GT_16(sub(state, *prev_state), 1)) + if ( GT_16( sub( state, *prev_state ), 1 ) ) { - state = sub(state, 1); + state = sub( state, 1 ); } } @@ -879,15 +879,15 @@ static void phase_dispersion_fx( * circular convolution *-----------------------------------------------------------------*/ - state = add(state, mode); /* level of dispersion */ + state = add( state, mode ); /* level of dispersion */ - IF (LT_16(state, 2)) + IF( LT_16( state, 2 ) ) { - r_fft_fx_lc(phs_tbl_dec, SIZE, SIZE2, NUM_STAGES, code, code2, 1); + r_fft_fx_lc( phs_tbl_dec, SIZE, SIZE2, NUM_STAGES, code, code2, 1 ); h_real = Mid_H_phasedisp; move16(); - if (state == 0) + if ( state == 0 ) { h_real = Low_H_phasedisp; move16(); @@ -907,14 +907,14 @@ static void phase_dispersion_fx( h_imag = h_real + L_SUBFR - 1; move16(); - *code_real++ = mult(*code2_real++, *h_real++); - move16(); /* DC */ + *code_real++ = mult( *code2_real++, *h_real++ ); + move16(); /* DC */ - FOR (i=1; i 0 && pulses[i - 1] != 0 && pulses[i + 1] != 0) - { - adj[i] = 11796; /* Q15, 0.36f */ move16(); - } - ELSE IF(i > 0 && (pulses[i - 1] == 0 || pulses[i + 1] == 0)) - { - adj[i] = 17695; /* Q15, 0.54f */ move16(); - } - ELSE - { - adj[i] = 23593; /* Q15, 0.72f */ move16(); - } - } - ELSE IF(LT_16(i, last_sfm)) - { - test(); - IF(pulses[i - 1] != 0 && pulses[i + 1] != 0) - { - adj[i] = 17695; /* Q15, 0.54f */ move16(); - } - ELSE - { - adj[i] = 23593; /* Q15, 0.72f */ move16(); - } - } - ELSE - { - adj[i] = 23593; /* Q15, 0.72f */ move16(); - } - if (att_state == 0) - { - start = i; - move16(); - } + IF( npul == 0 ) + { + /* Noise filled band */ + IF( LE_16( group, 1 ) ) + { + test(); + test(); + test(); + test(); + IF( i > 0 && pulses[i - 1] != 0 && pulses[i + 1] != 0 ) + { + adj[i] = 11796; /* Q15, 0.36f */ + move16(); + } + ELSE IF( i > 0 && ( pulses[i - 1] == 0 || pulses[i + 1] == 0 ) ) + { + adj[i] = 17695; /* Q15, 0.54f */ + move16(); + } + ELSE + { + adj[i] = 23593; /* Q15, 0.72f */ + move16(); + } + } + ELSE IF( LT_16( i, last_sfm ) ) + { + test(); + IF( pulses[i - 1] != 0 && pulses[i + 1] != 0 ) + { + adj[i] = 17695; /* Q15, 0.54f */ + move16(); + } + ELSE + { + adj[i] = 23593; /* Q15, 0.72f */ + move16(); + } + } + ELSE + { + adj[i] = 23593; /* Q15, 0.72f */ + move16(); + } - len = add(len, 1); - move16(); - att_state = 1; - move16(); - } - ELSE - { - adj[i] = MAX_16; /* Q15, 1.0f (saturated) */ - IF(EQ_16(att_state, 1)) /* End of attenuation region found */ - { - /* tmp = min(1, max(0, len-ENV_ADJ_START)*(1.0f/ENV_ADJ_INCL)); */ + if ( att_state == 0 ) + { + start = i; + move16(); + } + + len = add( len, 1 ); + move16(); + att_state = 1; + move16(); + } + ELSE + { + adj[i] = MAX_16; /* Q15, 1.0f (saturated) */ + IF( EQ_16( att_state, 1 ) ) /* End of attenuation region found */ + { + /* tmp = min(1, max(0, len-ENV_ADJ_START)*(1.0f/ENV_ADJ_INCL)); */ #ifdef BASOP_NOGLOB - tmp = round_fx_sat(L_shl_sat(L_mult0(s_max(0, sub(len, ENV_ADJ_START_FX)), ENV_ADJ_INV_INCL_FX),16)); /* Q15 (15+16-16) */ + tmp = round_fx_sat( L_shl_sat( L_mult0( s_max( 0, sub( len, ENV_ADJ_START_FX ) ), ENV_ADJ_INV_INCL_FX ), 16 ) ); /* Q15 (15+16-16) */ #else - tmp = round_fx(L_shl(L_mult0(s_max(0, sub(len, ENV_ADJ_START_FX)), ENV_ADJ_INV_INCL_FX),16)); /* Q15 (15+16-16) */ + tmp = round_fx( L_shl( L_mult0( s_max( 0, sub( len, ENV_ADJ_START_FX ) ), ENV_ADJ_INV_INCL_FX ), 16 ) ); /* Q15 (15+16-16) */ #endif - tmp_diff = sub(MAX_16, tmp); /* Q15 */ move16(); - FOR(j = start; j < i; j++) + tmp_diff = sub( MAX_16, tmp ); /* Q15 */ + move16(); + FOR( j = start; j < i; j++ ) { - /* adj[j] = max(tmp + (1-tmp)*adj[j],env_stab); */ - adj[j] = s_max(add(tmp, mult(tmp_diff, adj[j])), env_stab); /* Q15 (15+15-15) */ move16(); - } - len = 0; - move16(); - att_state = 0; - move16(); - } - } - } - /* length == L_FRAME16k */ - ELSE - { + /* adj[j] = max(tmp + (1-tmp)*adj[j],env_stab); */ + adj[j] = s_max( add( tmp, mult( tmp_diff, adj[j] ) ), env_stab ); /* Q15 (15+15-15) */ + move16(); + } + len = 0; + move16(); + att_state = 0; + move16(); + } + } + } + /* length == L_FRAME16k */ + ELSE + { - /* Calculate low accuracy band attenuation */ - gain_adj = 32767; /* Q15, 1.0f (saturated) */ move16(); + /* Calculate low accuracy band attenuation */ + gain_adj = 32767; /* Q15, 1.0f (saturated) */ + move16(); - test(); - IF(npul > 0 && LT_16(npul, MAX_P_ATT)) - { - /*idx = (short)(npul * att_step[group] + 0.5f) - 1; */ - idx = sub(mult_r(shl(npul,2),att_step_fx[group]), 1); /* Q0 (2+13+1-16) */ - if (LT_16(idx, MAX_P_ATT)) - { - gain_adj = gain_att_fx[idx]; /* Q15 */ move16(); + test(); + IF( npul > 0 && LT_16( npul, MAX_P_ATT ) ) + { + /*idx = (short)(npul * att_step[group] + 0.5f) - 1; */ + idx = sub( mult_r( shl( npul, 2 ), att_step_fx[group] ), 1 ); /* Q0 (2+13+1-16) */ + if ( LT_16( idx, MAX_P_ATT ) ) + { + gain_adj = gain_att_fx[idx]; /* Q15 */ + move16(); + } + } + adj[i] = gain_adj; + move16(); } } - adj[i] = gain_adj; - move16(); - } - } - /* Check if the sequence ended with an attenuation region */ - IF(EQ_16(att_state, 1)) - { - /* tmp = min(1, max(0, len-ENV_ADJ_START)*(1.0f/ENV_ADJ_INCL)); */ + /* Check if the sequence ended with an attenuation region */ + IF( EQ_16( att_state, 1 ) ) + { + /* tmp = min(1, max(0, len-ENV_ADJ_START)*(1.0f/ENV_ADJ_INCL)); */ #ifdef BASOP_NOGLOB - tmp = round_fx_sat(L_shl_sat(L_mult0(s_max(0, sub(len, ENV_ADJ_START_FX)), ENV_ADJ_INV_INCL_FX), 16)); /* Q15 (15+16-16) */ + tmp = round_fx_sat( L_shl_sat( L_mult0( s_max( 0, sub( len, ENV_ADJ_START_FX ) ), ENV_ADJ_INV_INCL_FX ), 16 ) ); /* Q15 (15+16-16) */ #else - tmp = round_fx(L_shl(L_mult0(s_max(0, sub(len, ENV_ADJ_START_FX)), ENV_ADJ_INV_INCL_FX), 16)); /* Q15 (15+16-16) */ + tmp = round_fx( L_shl( L_mult0( s_max( 0, sub( len, ENV_ADJ_START_FX ) ), ENV_ADJ_INV_INCL_FX ), 16 ) ); /* Q15 (15+16-16) */ #endif - tmp_diff = sub(MAX_16, tmp); /* Q15 */ move16(); - FOR(j = start; j < i; j++) - { + tmp_diff = sub( MAX_16, tmp ); /* Q15 */ + move16(); + FOR( j = start; j < i; j++ ) + { - /* adj[j] = max(tmp + (1-tmp)*adj[j],env_stab); */ - adj[j] = s_max(add(tmp, mult(tmp_diff, adj[j])), env_stab); /* Q15 (15+15-15) */ move16(); + /* adj[j] = max(tmp + (1-tmp)*adj[j],env_stab); */ + adj[j] = s_max( add( tmp, mult( tmp_diff, adj[j] ) ), env_stab ); /* Q15 (15+15-15) */ + move16(); + } } - } - return; + return; } diff --git a/lib_com/env_stab.c b/lib_com/env_stab.c index 18da23e27..4140a64dc 100644 --- a/lib_com/env_stab.c +++ b/lib_com/env_stab.c @@ -183,130 +183,134 @@ float env_stability( } -Word16 env_stability_fx( /* in Q15 */ - const Word16* ynrm, /*i: Norm vector for current frame */ - const Word16 nb_sfm, /*i: Number of sub-bands */ - Word16* mem_norm, /*i/o: Norm vector memory from past frame */ - Word16* mem_env_delta, /*i/o: Envelope stability memory for smoothing in Q12 */ - const Word16 core_switching_flag/* i : Core switching flag */ +Word16 env_stability_fx( /* in Q15 */ + const Word16 *ynrm, /*i: Norm vector for current frame */ + const Word16 nb_sfm, /*i: Number of sub-bands */ + Word16 *mem_norm, /*i/o: Norm vector memory from past frame */ + Word16 *mem_env_delta, /*i/o: Envelope stability memory for smoothing in Q12 */ + const Word16 core_switching_flag /* i : Core switching flag */ ) { - Word16 env_delta; - Word16 env_stab; - Word16 tmp, tmp_stab; - Word16 i; - - Word16 exp, exp2; - Word32 L_tmp, L_env_delta; - Word16 inv_nb_sfm; + Word16 env_delta; + Word16 env_stab; + Word16 tmp, tmp_stab; + Word16 i; + + Word16 exp, exp2; + Word32 L_tmp, L_env_delta; + Word16 inv_nb_sfm; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; + Flag Overflow = 0; #endif - IF(core_switching_flag) - { - FOR(i = 0; i < nb_sfm; i++) + IF( core_switching_flag ) { - mem_norm[i] = ynrm[i]; move16(); - } - Overflow = 0; move16(); -#ifdef BASOP_NOGLOB /* Critical Overflow */ - env_delta = shl_o(*mem_env_delta, 1, &Overflow); + FOR( i = 0; i < nb_sfm; i++ ) + { + mem_norm[i] = ynrm[i]; + move16(); + } + Overflow = 0; + move16(); +#ifdef BASOP_NOGLOB /* Critical Overflow */ + env_delta = shl_o( *mem_env_delta, 1, &Overflow ); #else - env_delta = shl(*mem_env_delta, 1); + env_delta = shl( *mem_env_delta, 1 ); #endif - } - ELSE - { - /* Calculate envelope stability parameter */ -L_env_delta = L_deposit_l(0); -FOR(i = 0; i < nb_sfm; i++) -{ - tmp = sub(mem_norm[i], ynrm[i]); - L_env_delta = L_mac0(L_env_delta, tmp, tmp); - mem_norm[i] = ynrm[i]; - move16(); -} + } + ELSE + { + /* Calculate envelope stability parameter */ + L_env_delta = L_deposit_l( 0 ); + FOR( i = 0; i < nb_sfm; i++ ) + { + tmp = sub( mem_norm[i], ynrm[i] ); + L_env_delta = L_mac0( L_env_delta, tmp, tmp ); + mem_norm[i] = ynrm[i]; + move16(); + } -inv_nb_sfm = 19418; /* Q19 */ move16(); -if (nb_sfm == 26) -{ - inv_nb_sfm = 20165; /* Q19 */ move16(); -} -exp = norm_l(L_env_delta); -L_env_delta = Mult_32_16(L_shl(L_env_delta, exp), inv_nb_sfm); /* 0+exp+19-15 */ + inv_nb_sfm = 19418; /* Q19 */ + move16(); + if ( nb_sfm == 26 ) + { + inv_nb_sfm = 20165; /* Q19 */ + move16(); + } + exp = norm_l( L_env_delta ); + L_env_delta = Mult_32_16( L_shl( L_env_delta, exp ), inv_nb_sfm ); /* 0+exp+19-15 */ -L_tmp = Sqrt_l(L_env_delta, &exp2); /* exp+4+31+exp2 */ + L_tmp = Sqrt_l( L_env_delta, &exp2 ); /* exp+4+31+exp2 */ -exp = add(35, add(exp, exp2)); -if (EQ_16(s_and(exp, 1), 1)) -{ - L_tmp = Mult_32_16(L_tmp, 23170); /* 1/sqrt(2) in Q15 */ -} -exp = shr(exp, 1); + exp = add( 35, add( exp, exp2 ) ); + if ( EQ_16( s_and( exp, 1 ), 1 ) ) + { + L_tmp = Mult_32_16( L_tmp, 23170 ); /* 1/sqrt(2) in Q15 */ + } + exp = shr( exp, 1 ); -#ifdef BASOP_NOGLOB /* Critical Overflow */ - env_delta = round_fx_sat( L_shl_sat( L_tmp, sub( 26, exp ) ) ); /* Q10 */ +#ifdef BASOP_NOGLOB /* Critical Overflow */ + env_delta = round_fx_sat( L_shl_sat( L_tmp, sub( 26, exp ) ) ); /* Q10 */ #else -env_delta = round_fx(L_shl(L_tmp, sub(26, exp))); /* Q10 */ + env_delta = round_fx( L_shl( L_tmp, sub( 26, exp ) ) ); /* Q10 */ #endif -L_tmp = L_mult0(26214, env_delta); /* 26214 is 0.1 in Q18. Q28 */ -#ifdef BASOP_NOGLOB /* Critical Overflow */ - L_tmp = L_mac_sat( L_tmp, 29491, *mem_env_delta ); /* 29491 is 0.9 in Q15. Q28 */ + L_tmp = L_mult0( 26214, env_delta ); /* 26214 is 0.1 in Q18. Q28 */ +#ifdef BASOP_NOGLOB /* Critical Overflow */ + L_tmp = L_mac_sat( L_tmp, 29491, *mem_env_delta ); /* 29491 is 0.9 in Q15. Q28 */ - *mem_env_delta = round_fx_sat(L_tmp); /* Q12 */ + *mem_env_delta = round_fx_sat( L_tmp ); /* Q12 */ #else -L_tmp = L_mac(L_tmp, 29491, *mem_env_delta); /* 29491 is 0.9 in Q15. Q28 */ + L_tmp = L_mac( L_tmp, 29491, *mem_env_delta ); /* 29491 is 0.9 in Q15. Q28 */ -*mem_env_delta = round_fx(L_tmp); /* Q12 */ + *mem_env_delta = round_fx( L_tmp ); /* Q12 */ #endif -Overflow = 0; -move16(); -#ifdef BASOP_NOGLOB /* Critical Overflow */ - env_delta = round_fx_o(L_shl_o(L_tmp, 1, &Overflow), &Overflow); /* Q13 */ + Overflow = 0; + move16(); +#ifdef BASOP_NOGLOB /* Critical Overflow */ + env_delta = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /* Q13 */ #else - env_delta = round_fx(L_shl(L_tmp, 1)); /* Q13 */ + env_delta = round_fx( L_shl( L_tmp, 1 ) ); /* Q13 */ #endif - } - IF(Overflow != 0) /* Saturated due to the above up-shifting operation. */ - { - return stab_trans_fx[L_STAB_TBL - 1]; /* The highest quantized index. */ - } - - /* If tmp_stab > (D_STAB_TBL*L_STAB_TBL + M_STAB_TBL), i.e., 0.103138*10+2.51757=3.603137, - * the quantized index is equal to 9. Hence, we only need to worry about any tmpStab < 4. - * In this case, Q13 is good enough. - */ - tmp_stab = sub(env_delta, M_STAB_TBL_FX); /* in Q13 */ - tmp_stab = abs_s(tmp_stab); - - /* Table lookup for smooth transitions - * First, find the quantization level, i, of tmpStab. */ + } + IF( Overflow != 0 ) /* Saturated due to the above up-shifting operation. */ + { + return stab_trans_fx[L_STAB_TBL - 1]; /* The highest quantized index. */ + } + + /* If tmp_stab > (D_STAB_TBL*L_STAB_TBL + M_STAB_TBL), i.e., 0.103138*10+2.51757=3.603137, + * the quantized index is equal to 9. Hence, we only need to worry about any tmpStab < 4. + * In this case, Q13 is good enough. + */ + tmp_stab = sub( env_delta, M_STAB_TBL_FX ); /* in Q13 */ + tmp_stab = abs_s( tmp_stab ); + + /* Table lookup for smooth transitions + * First, find the quantization level, i, of tmpStab. */ #if L_STAB_TBL > 10 #error env_stability_fx: Use more efficient usquant() #endif - tmp_stab = sub(tmp_stab, HALF_D_STAB_TBL_FX); /* in Q13 */ - FOR(i = 0; i < L_STAB_TBL - 1; i++) - { - IF(tmp_stab < 0) + tmp_stab = sub( tmp_stab, HALF_D_STAB_TBL_FX ); /* in Q13 */ + FOR( i = 0; i < L_STAB_TBL - 1; i++ ) { - BREAK; + IF( tmp_stab < 0 ) + { + BREAK; + } + ELSE + { + tmp_stab = sub( tmp_stab, D_STAB_TBL_FX ); /* in Q13 */ + } } - ELSE + + env_stab = stab_trans_fx[i]; + move16(); + if ( LT_16( env_delta, M_STAB_TBL_FX ) ) { - tmp_stab = sub(tmp_stab, D_STAB_TBL_FX); /* in Q13 */ + env_stab = sub( 0x7FFF, stab_trans_fx[i] ); } - } - env_stab = stab_trans_fx[i]; - move16(); - if (LT_16(env_delta, M_STAB_TBL_FX)) - { - env_stab = sub(0x7FFF, stab_trans_fx[i]); - } - - return env_stab; + return env_stab; } /*--------------------------------------------------------------------------* @@ -361,77 +365,77 @@ float env_stab_smo( return state; } -Word16 env_stab_smo_fx( /* Q0 */ - Word16 env_stab, /*i : env_stab value Q15 */ - Word16 *env_stab_state_p, /*i/o: env_stab state probabilities Q15 */ - Word16 *ho_cnt /*i/o: hangover counter for speech state */ +Word16 env_stab_smo_fx( /* Q0 */ + Word16 env_stab, /*i : env_stab value Q15 */ + Word16 *env_stab_state_p, /*i/o: env_stab state probabilities Q15 */ + Word16 *ho_cnt /*i/o: hangover counter for speech state */ ) { - Word16 state, prev_state; - Word16 maxval, pp[NUM_ENV_STAB_PLC_STATES], pa[NUM_ENV_STAB_PLC_STATES]; - Word16 i; - Word16 tmp, sum, exp; + Word16 state, prev_state; + Word16 maxval, pp[NUM_ENV_STAB_PLC_STATES], pa[NUM_ENV_STAB_PLC_STATES]; + Word16 i; + Word16 tmp, sum, exp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; + Flag Overflow = 0; #endif - /* get previous state */ - prev_state = maximum_fx(env_stab_state_p, NUM_ENV_STAB_PLC_STATES, &maxval); - - /* assume two states: speech(0), music(1) */ - /* set a posteriori likelihoods for the two states according to env_stab */ - /* re-scale. Unclear if needed */ - /* env_stab = (env_stab - stab_trans_fx[L_STAB_TBL-1])/(1-2*stab_trans_fx[L_STAB_TBL-1]); */ - tmp = sub(env_stab, stab_trans_fx[L_STAB_TBL - 1]); - tmp = round_fx(L_shl(L_mult(tmp, INV_STAB_TRANS_FX), 1)); /* Q15 */ - - pp[0] = sub(32767, tmp); - move16(); /* 1 in Q15 */ - pp[1] = tmp; - move16(); - - /* calculate a priori likelihoods */ - pa[0] = round_fx(Dot_product(env_stab_tp_fx[0], env_stab_state_p, NUM_ENV_STAB_PLC_STATES)); /* Q15*/ - pa[1] = round_fx(Dot_product(env_stab_tp_fx[1], env_stab_state_p, NUM_ENV_STAB_PLC_STATES)); - - /* multiply elementwise with a posteriori likelihoods */ - sum = 0; - move16(); - FOR(i = 0; i < NUM_ENV_STAB_PLC_STATES; i++) - { - env_stab_state_p[i] = mult_r(pa[i], pp[i]); - move16(); /* Q15 */ - sum = add(sum, env_stab_state_p[i]); - } - - /* renormalize state probabilities */ - exp = norm_s(sum); - tmp = div_s(16384, shl(sum, exp)); /* Q(14-exp) */ - /*tmp = shl(tmp, add(exp, 1));*/ /* Q15 */ - FOR(i = 0; i < NUM_ENV_STAB_PLC_STATES; i++) - { + /* get previous state */ + prev_state = maximum_fx( env_stab_state_p, NUM_ENV_STAB_PLC_STATES, &maxval ); + + /* assume two states: speech(0), music(1) */ + /* set a posteriori likelihoods for the two states according to env_stab */ + /* re-scale. Unclear if needed */ + /* env_stab = (env_stab - stab_trans_fx[L_STAB_TBL-1])/(1-2*stab_trans_fx[L_STAB_TBL-1]); */ + tmp = sub( env_stab, stab_trans_fx[L_STAB_TBL - 1] ); + tmp = round_fx( L_shl( L_mult( tmp, INV_STAB_TRANS_FX ), 1 ) ); /* Q15 */ + + pp[0] = sub( 32767, tmp ); + move16(); /* 1 in Q15 */ + pp[1] = tmp; + move16(); + + /* calculate a priori likelihoods */ + pa[0] = round_fx( Dot_product( env_stab_tp_fx[0], env_stab_state_p, NUM_ENV_STAB_PLC_STATES ) ); /* Q15*/ + pa[1] = round_fx( Dot_product( env_stab_tp_fx[1], env_stab_state_p, NUM_ENV_STAB_PLC_STATES ) ); + + /* multiply elementwise with a posteriori likelihoods */ + sum = 0; + move16(); + FOR( i = 0; i < NUM_ENV_STAB_PLC_STATES; i++ ) + { + env_stab_state_p[i] = mult_r( pa[i], pp[i] ); + move16(); /* Q15 */ + sum = add( sum, env_stab_state_p[i] ); + } + + /* renormalize state probabilities */ + exp = norm_s( sum ); + tmp = div_s( 16384, shl( sum, exp ) ); /* Q(14-exp) */ + /*tmp = shl(tmp, add(exp, 1));*/ /* Q15 */ + FOR( i = 0; i < NUM_ENV_STAB_PLC_STATES; i++ ) + { #ifdef BASOP_NOGLOB - env_stab_state_p[i] = round_fx_o(L_shl_o(L_mult_o(env_stab_state_p[i], tmp, &Overflow), add(exp, 1), &Overflow), &Overflow); /* Q15 */ + env_stab_state_p[i] = round_fx_o( L_shl_o( L_mult_o( env_stab_state_p[i], tmp, &Overflow ), add( exp, 1 ), &Overflow ), &Overflow ); /* Q15 */ #else - env_stab_state_p[i] = round_fx(L_shl(L_mult(env_stab_state_p[i], tmp), add(exp, 1))); /* Q15 */ + env_stab_state_p[i] = round_fx( L_shl( L_mult( env_stab_state_p[i], tmp ), add( exp, 1 ) ) ); /* Q15 */ #endif - } + } - /* find maximum index as return value */ - state = maximum_fx(env_stab_state_p, NUM_ENV_STAB_PLC_STATES, &maxval); + /* find maximum index as return value */ + state = maximum_fx( env_stab_state_p, NUM_ENV_STAB_PLC_STATES, &maxval ); - /* apply some hangover for speech */ - test(); - if (state == 0 && EQ_16(prev_state, 1)) - { - *ho_cnt = ENV_STAB_SMO_HO; - move16(); - } + /* apply some hangover for speech */ + test(); + if ( state == 0 && EQ_16( prev_state, 1 ) ) + { + *ho_cnt = ENV_STAB_SMO_HO; + move16(); + } - IF(*ho_cnt > 0) - { - *ho_cnt = sub(*ho_cnt, 1); - move16(); - } + IF( *ho_cnt > 0 ) + { + *ho_cnt = sub( *ho_cnt, 1 ); + move16(); + } - return state; + return state; } diff --git a/lib_com/env_stab_trans.c b/lib_com/env_stab_trans.c index 4cbca6be8..2062f4e77 100644 --- a/lib_com/env_stab_trans.c +++ b/lib_com/env_stab_trans.c @@ -157,15 +157,15 @@ void env_stab_transient_detect( void env_stab_transient_detect_fx( - const Word16 is_transient, /* i: Transient flag */ - const Word16 length, /* i : Length of spectrum (32 or 48 kHz) */ - const Word16 norm[], /* i : quantization indices for norms */ - Word16 *no_att_hangover, /* i/o: Frame counter for attenuation hangover (Q0) */ - Word32 *L_energy_lt, /* i/o: Long-term energy measure for transient detection (Q13) */ - const Word16 HQ_mode, /* i : HQ coding mode */ - const Word16 bin_th, /* i : HVQ cross-over frequency bin */ - const Word32 *L_coeff, /* i : Coded spectral coefficients */ - const Word16 Qcoeff /* i : Q of coded spectral coefficients */ + const Word16 is_transient, /* i: Transient flag */ + const Word16 length, /* i : Length of spectrum (32 or 48 kHz) */ + const Word16 norm[], /* i : quantization indices for norms */ + Word16 *no_att_hangover, /* i/o: Frame counter for attenuation hangover (Q0) */ + Word32 *L_energy_lt, /* i/o: Long-term energy measure for transient detection (Q13) */ + const Word16 HQ_mode, /* i : HQ coding mode */ + const Word16 bin_th, /* i : HVQ cross-over frequency bin */ + const Word32 *L_coeff, /* i : Coded spectral coefficients */ + const Word16 Qcoeff /* i : Q of coded spectral coefficients */ ) { Word16 i, blk, norm_ind, sqrt_exp, bin_th_1, temp, sh; @@ -177,86 +177,87 @@ void env_stab_transient_detect_fx( L_energy_lt_local = *L_energy_lt; move32(); - L_d_max = L_deposit_l(0); - L_e_frame = L_deposit_l(0); + L_d_max = L_deposit_l( 0 ); + L_e_frame = L_deposit_l( 0 ); temp = 32; move16(); - IF( EQ_16(HQ_mode,HQ_HVQ)) + IF( EQ_16( HQ_mode, HQ_HVQ ) ) { - FOR (i = 0; i < bin_th; i++) /* find adaptive shift */ + FOR( i = 0; i < bin_th; i++ ) /* find adaptive shift */ { - temp = s_min(temp,norm_l(L_coeff[i])); + temp = s_min( temp, norm_l( L_coeff[i] ) ); } - sh = sub(temp,2); /* scale such that 2 msbs are not used, the resulting adaptive Qcoeff will be: Qcoeff+sh-16 */ - FOR (i = 0; i < bin_th; i++) /* Maximum number of loop runs 320 */ + sh = sub( temp, 2 ); /* scale such that 2 msbs are not used, the resulting adaptive Qcoeff will be: Qcoeff+sh-16 */ + FOR( i = 0; i < bin_th; i++ ) /* Maximum number of loop runs 320 */ { - temp = extract_h(L_shl(L_coeff[i],sh)); - L_e_frame = L_mac(L_e_frame,temp,temp); /* Q(2*(Qcoeff+sh-16)+1)=Q(2*(Qcoeff+sh)-31 */ + temp = extract_h( L_shl( L_coeff[i], sh ) ); + L_e_frame = L_mac( L_e_frame, temp, temp ); /* Q(2*(Qcoeff+sh-16)+1)=Q(2*(Qcoeff+sh)-31 */ } bin_th_1 = INV_HVQ_THRES_BIN_24k; move16(); - if (EQ_16(bin_th, HVQ_THRES_BIN_32k)) + if ( EQ_16( bin_th, HVQ_THRES_BIN_32k ) ) { bin_th_1 = INV_HVQ_THRES_BIN_32k; move16(); } - L_temp = Mult_32_16(L_e_frame,bin_th_1); /* Q(2*(Qcoeff-16+sh)+1+21-15) -> Q(2*(Qcoeff+sh)-25) */ - L_e_frame = Sqrt_l(L_temp,&sqrt_exp); - L_e_frame = L_shr(L_e_frame, add(sub(add(sh,Qcoeff),10),shr(sqrt_exp,1))); /* Adjust by (Qcoeff+sh-10) to fixed Q13: Qcoeff+sh+(-25+31)/2 - (Qcoeff+sh-10) -> Q13 */ + L_temp = Mult_32_16( L_e_frame, bin_th_1 ); /* Q(2*(Qcoeff-16+sh)+1+21-15) -> Q(2*(Qcoeff+sh)-25) */ + L_e_frame = Sqrt_l( L_temp, &sqrt_exp ); + L_e_frame = L_shr( L_e_frame, add( sub( add( sh, Qcoeff ), 10 ), shr( sqrt_exp, 1 ) ) ); /* Adjust by (Qcoeff+sh-10) to fixed Q13: Qcoeff+sh+(-25+31)/2 - (Qcoeff+sh-10) -> Q13 */ - IF ( GT_32(L_e_frame, ENERGY_TH_FX)) + IF( GT_32( L_e_frame, ENERGY_TH_FX ) ) { - L_energy_lt_local = Mult_32_16(*L_energy_lt, ENERGY_LT_BETA_FX); - L_temp = Mult_32_16(L_e_frame, ENERGY_LT_BETA_1_FX); - *L_energy_lt = L_add(L_energy_lt_local,L_temp); + L_energy_lt_local = Mult_32_16( *L_energy_lt, ENERGY_LT_BETA_FX ); + L_temp = Mult_32_16( L_e_frame, ENERGY_LT_BETA_1_FX ); + *L_energy_lt = L_add( L_energy_lt_local, L_temp ); move32(); } - IF (*no_att_hangover > 0) + IF( *no_att_hangover > 0 ) { - (*no_att_hangover) = sub((*no_att_hangover), 1); + ( *no_att_hangover ) = sub( ( *no_att_hangover ), 1 ); move16(); } } ELSE { - L_e_frame = L_deposit_l(0); + L_e_frame = L_deposit_l( 0 ); test(); - IF (is_transient && EQ_16(length,L_FRAME32k)) + IF( is_transient && EQ_16( length, L_FRAME32k ) ) { /* Measure subframe energies */ - FOR (blk = 0; blk < NUM_SUBFRAMES; blk++) + FOR( blk = 0; blk < NUM_SUBFRAMES; blk++ ) { - L_E_sub[blk] = L_deposit_l(0); /* Q9 */ + L_E_sub[blk] = L_deposit_l( 0 ); /* Q9 */ - FOR (i=0; i < 2^4 */ + FOR( i = 0; i < BANDS_PER_SUBFRAMES; i++ ) /* 9 times -> < 2^4 */ { norm_ind = subf_norm_groups[blk][i]; move16(); - L_E_sub[blk] = L_add(L_E_sub[blk],L_shr(dicn_fx[norm[norm_ind]],4)); - move32(); ; /* Q10 */ + L_E_sub[blk] = L_add( L_E_sub[blk], L_shr( dicn_fx[norm[norm_ind]], 4 ) ); + move32(); + ; /* Q10 */ } - L_E_sub[blk] = Mult_32_16(L_E_sub[blk], INV_BANDS_PER_SUBFRAMES); - move32(); /* Q(10+17-15) -> Q12 */ + L_E_sub[blk] = Mult_32_16( L_E_sub[blk], INV_BANDS_PER_SUBFRAMES ); + move32(); /* Q(10+17-15) -> Q12 */ - L_e_frame = L_add(L_e_frame,L_E_sub[blk]); /* Q12 */ + L_e_frame = L_add( L_e_frame, L_E_sub[blk] ); /* Q12 */ } /* Test for transient */ /* if (e_frame > ENERGY_TH * NUM_SUBFRAMES) */ - IF (GT_32(L_e_frame, ENERGY_TH_NUM_SUBFRAMES)) + IF( GT_32( L_e_frame, ENERGY_TH_NUM_SUBFRAMES ) ) { - FOR (blk = 0; blk < NUM_SUBFRAMES-1; blk++) + FOR( blk = 0; blk < NUM_SUBFRAMES - 1; blk++ ) { - L_delta_e_sub = L_sub(L_E_sub[blk+1],L_E_sub[blk]); /* Q12 */ - if (GT_32(L_delta_e_sub,L_d_max)) + L_delta_e_sub = L_sub( L_E_sub[blk + 1], L_E_sub[blk] ); /* Q12 */ + if ( GT_32( L_delta_e_sub, L_d_max ) ) { - L_d_max = L_delta_e_sub; /* L_d_max is NOT normalized with *energy_lt */ - move32(); + L_d_max = L_delta_e_sub; /* L_d_max is NOT normalized with *energy_lt */ + move32(); } } } @@ -264,20 +265,20 @@ void env_stab_transient_detect_fx( ELSE { /* Update long-term energy measure */ - L_e_frame = L_deposit_l(0); /* Q9 */ - FOR (i = 0; i < SFM_N_ENV_STAB; i++) /* 27 times -> < 2^5 */ + L_e_frame = L_deposit_l( 0 ); /* Q9 */ + FOR( i = 0; i < SFM_N_ENV_STAB; i++ ) /* 27 times -> < 2^5 */ { - L_e_frame = L_add(L_e_frame,L_shr(dicn_fx[norm[i]],5)); + L_e_frame = L_add( L_e_frame, L_shr( dicn_fx[norm[i]], 5 ) ); /* Q9 */ } - L_e_frame = Mult_32_16(L_e_frame, INV_SFM_N_ENV_STAB); /* Q(9+19-15) -> Q13 */ + L_e_frame = Mult_32_16( L_e_frame, INV_SFM_N_ENV_STAB ); /* Q(9+19-15) -> Q13 */ - IF ( GT_32(L_e_frame, ENERGY_TH_FX)) + IF( GT_32( L_e_frame, ENERGY_TH_FX ) ) { - L_energy_lt_local = Mult_32_16(*L_energy_lt, ENERGY_LT_BETA_FX); - L_temp = Mult_32_16(L_e_frame, ENERGY_LT_BETA_1_FX); - *L_energy_lt = L_add(L_energy_lt_local,L_temp); + L_energy_lt_local = Mult_32_16( *L_energy_lt, ENERGY_LT_BETA_FX ); + L_temp = Mult_32_16( L_e_frame, ENERGY_LT_BETA_1_FX ); + *L_energy_lt = L_add( L_energy_lt_local, L_temp ); move32(); } } @@ -285,18 +286,17 @@ void env_stab_transient_detect_fx( /* Add hang-over for conservative application of stability dependent attenuation */ /* -> Note: L_d_max not normalized with *energy_lt */ /* Hence, we compare L_d_max/DELTA_TH with *energy_lt */ - IF (GT_32(Mult_32_16(L_d_max, INV_DELTA_TH),L_energy_lt_local)) /* Q13 = Q(12 + 16 -15) */ + IF( GT_32( Mult_32_16( L_d_max, INV_DELTA_TH ), L_energy_lt_local ) ) /* Q13 = Q(12 + 16 -15) */ { *no_att_hangover = ATT_LIM_HANGOVER; move16(); } - ELSE if (*no_att_hangover > 0) + ELSE if ( *no_att_hangover > 0 ) { - *no_att_hangover = sub(*no_att_hangover,1); + *no_att_hangover = sub( *no_att_hangover, 1 ); move16(); } } return; } - diff --git a/lib_com/est_tilt_fx.c b/lib_com/est_tilt_fx.c index 7a92e0dd8..c556536e4 100644 --- a/lib_com/est_tilt_fx.c +++ b/lib_com/est_tilt_fx.c @@ -2,10 +2,10 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ #include "stl.h" #include "basop_util.h" @@ -34,15 +34,16 @@ /* RETURN ARGUMENTS : */ /* _ (Word16) tolt_code : tilt of the code Q15 */ /*=======================================================================*/ -Word16 est_tilt_fx( /* o : tilt of the code Q15 */ - const Word16 *exc, /* i : adaptive excitation vector Qx */ - const Word16 gain_pit, /* i : adaptive gain Q14 */ - const Word16 *code, /* i : algebraic excitation vector Q9 */ - const Word32 gain_code, /* i : algebraic code gain Q16 */ - Word16 *voice_fac, /* o : voicing factor Q15 */ - const Word16 Q_exc /* i : Scaling factor of excitation Q0 */ +Word16 est_tilt_fx( /* o : tilt of the code Q15 */ + const Word16 *exc, /* i : adaptive excitation vector Qx */ + const Word16 gain_pit, /* i : adaptive gain Q14 */ + const Word16 *code, /* i : algebraic excitation vector Q9 */ + const Word32 gain_code, /* i : algebraic code gain Q16 */ + Word16 *voice_fac, /* o : voicing factor Q15 */ + const Word16 Q_exc /* i : Scaling factor of excitation Q0 */ #ifdef ADD_LRTD - ,const Word16 L_subfr /* i : Sub frame length */ + , + const Word16 L_subfr /* i : Sub frame length */ #endif ) { @@ -50,42 +51,42 @@ Word16 est_tilt_fx( /* o : tilt of the code Q15 * Word32 L_tmp; Word16 tilt_code; #ifdef ADD_LRTD - PMT("FIX POINT NEED to be adapted for 16 kHz frame length ") + PMT( "FIX POINT NEED to be adapted for 16 kHz frame length " ) #endif - ener1 = extract_h(Dot_product12(exc, exc, L_SUBFR, &exp1)); - exp1 = sub(exp1, add(Q_exc, Q_exc)); - L_tmp = L_mult(gain_pit, gain_pit); /* energy of pitch excitation */ - exp = norm_l(L_tmp); - tmp = extract_h(L_shl(L_tmp, exp)); - ener1 = mult(ener1, tmp); - exp1 = sub(sub(exp1, exp), 10); /* 10 -> gain_pit Q14 to Q9 */ - - ener2 = extract_h(Dot_product12(code, code, L_SUBFR, &exp2)); - - exp = norm_l(gain_code); - tmp = extract_h(L_shl(gain_code, exp)); - tmp = mult(tmp, tmp); /* energy of innovative code excitation */ - ener2 = mult(ener2, tmp); - exp2 = sub(exp2, add(exp, exp)); - - i = sub(exp1, exp2); + ener1 = extract_h( Dot_product12( exc, exc, L_SUBFR, &exp1 ) ); + exp1 = sub( exp1, add( Q_exc, Q_exc ) ); + L_tmp = L_mult( gain_pit, gain_pit ); /* energy of pitch excitation */ + exp = norm_l( L_tmp ); + tmp = extract_h( L_shl( L_tmp, exp ) ); + ener1 = mult( ener1, tmp ); + exp1 = sub( sub( exp1, exp ), 10 ); /* 10 -> gain_pit Q14 to Q9 */ + + ener2 = extract_h( Dot_product12( code, code, L_SUBFR, &exp2 ) ); + + exp = norm_l( gain_code ); + tmp = extract_h( L_shl( gain_code, exp ) ); + tmp = mult( tmp, tmp ); /* energy of innovative code excitation */ + ener2 = mult( ener2, tmp ); + exp2 = sub( exp2, add( exp, exp ) ); + + i = sub( exp1, exp2 ); BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB ener1 = shr_sat( ener1, sub( 1, s_min( i, 0 ) ) ); - ener2 = shr_sat(ener2, add(s_max(0, i), 1)); + ener2 = shr_sat( ener2, add( s_max( 0, i ), 1 ) ); #else - ener1 = shr(ener1, sub(1, s_min(i, 0))); - ener2 = shr(ener2, add(s_max(0, i), 1)); + ener1 = shr( ener1, sub( 1, s_min( i, 0 ) ) ); + ener2 = shr( ener2, add( s_max( 0, i ), 1 ) ); #endif BASOP_SATURATE_WARNING_ON_EVS - tmp = sub(ener1, ener2); - ener1 = add(add(ener1, ener2), 1); + tmp = sub( ener1, ener2 ); + ener1 = add( add( ener1, ener2 ), 1 ); /* find voice factor (1=voiced, -1=unvoiced) */ - exp = div_s(abs_s(tmp), ener1); - if (tmp < 0) + exp = div_s( abs_s( tmp ), ener1 ); + if ( tmp < 0 ) { - exp = negate(exp); + exp = negate( exp ); } *voice_fac = exp; move16(); @@ -93,7 +94,7 @@ Word16 est_tilt_fx( /* o : tilt of the code Q15 * /* tilt of code for next subframe: 0.5=voiced, 0=unvoiced */ /* tilt_code = (float)(0.25*(1.0 + *voice_fac)) */ - tilt_code = mac_r(8192L*65536-0x8000, *voice_fac, 8192); /*Q15 */ + tilt_code = mac_r( 8192L * 65536 - 0x8000, *voice_fac, 8192 ); /*Q15 */ return tilt_code; } @@ -122,16 +123,17 @@ Word16 est_tilt_fx( /* o : tilt of the code Q15 * /* RETURN ARGUMENTS : */ /* _ (Word16) tolt_code : tilt of the code Q15 */ /*=======================================================================*/ -Word16 est_tilt_ivas_fx( /* o : tilt of the code Q15 */ - const Word16 *exc, /* i : adaptive excitation vector Qx */ - const Word16 gain_pit, /* i : adaptive gain Q14 */ - const Word16 *code, /* i : algebraic excitation vector Q9 */ - const Word32 gain_code, /* i : algebraic code gain Q16 */ - Word16 *voice_fac, /* o : voicing factor Q15 */ - const Word16 Q_exc /* i : Scaling factor of excitation Q0 */ -#if 1//def ADD_LRTD - , const Word16 L_subfr, /* i : Sub frame length */ - const Word16 flag_tilt /* i : flag for special tilt */ +Word16 est_tilt_ivas_fx( /* o : tilt of the code Q15 */ + const Word16 *exc, /* i : adaptive excitation vector Qx */ + const Word16 gain_pit, /* i : adaptive gain Q14 */ + const Word16 *code, /* i : algebraic excitation vector Q9 */ + const Word32 gain_code, /* i : algebraic code gain Q16 */ + Word16 *voice_fac, /* o : voicing factor Q15 */ + const Word16 Q_exc /* i : Scaling factor of excitation Q0 */ +#if 1 // def ADD_LRTD + , + const Word16 L_subfr, /* i : Sub frame length */ + const Word16 flag_tilt /* i : flag for special tilt */ #endif ) { @@ -139,63 +141,64 @@ Word16 est_tilt_ivas_fx( /* o : tilt of the code Q15 Word32 L_tmp; Word16 tilt_code; #ifdef ADD_LRTD - PMT("FIX POINT NEED to be adapted for 16 kHz frame length ") + PMT( "FIX POINT NEED to be adapted for 16 kHz frame length " ) #endif - ener1 = extract_h(Dot_product12(exc, exc, L_subfr, &exp1)); - exp1 = sub(exp1, add(Q_exc, Q_exc)); - L_tmp = L_mult(gain_pit, gain_pit); /* energy of pitch excitation */ - exp = norm_l(L_tmp); - tmp = extract_h(L_shl(L_tmp, exp)); - ener1 = mult(ener1, tmp); - exp1 = sub(sub(exp1, exp), 10); /* 10 -> gain_pit Q14 to Q9 */ - - ener2 = extract_h(Dot_product12(code, code, L_subfr, &exp2)); - - exp = norm_l(gain_code); - tmp = extract_h(L_shl(gain_code, exp)); - tmp = mult(tmp, tmp); /* energy of innovative code excitation */ - ener2 = mult(ener2, tmp); - exp2 = sub(exp2, add(exp, exp)); - - i = sub(exp1, exp2); + ener1 = extract_h( Dot_product12( exc, exc, L_subfr, &exp1 ) ); + exp1 = sub( exp1, add( Q_exc, Q_exc ) ); + L_tmp = L_mult( gain_pit, gain_pit ); /* energy of pitch excitation */ + exp = norm_l( L_tmp ); + tmp = extract_h( L_shl( L_tmp, exp ) ); + ener1 = mult( ener1, tmp ); + exp1 = sub( sub( exp1, exp ), 10 ); /* 10 -> gain_pit Q14 to Q9 */ + + ener2 = extract_h( Dot_product12( code, code, L_subfr, &exp2 ) ); + + exp = norm_l( gain_code ); + tmp = extract_h( L_shl( gain_code, exp ) ); + tmp = mult( tmp, tmp ); /* energy of innovative code excitation */ + ener2 = mult( ener2, tmp ); + exp2 = sub( exp2, add( exp, exp ) ); + + i = sub( exp1, exp2 ); BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB ener1 = shr_sat( ener1, sub( 1, s_min( i, 0 ) ) ); - ener2 = shr_sat(ener2, add(s_max(0, i), 1)); + ener2 = shr_sat( ener2, add( s_max( 0, i ), 1 ) ); #else - ener1 = shr(ener1, sub(1, s_min(i, 0))); - ener2 = shr(ener2, add(s_max(0, i), 1)); + ener1 = shr( ener1, sub( 1, s_min( i, 0 ) ) ); + ener2 = shr( ener2, add( s_max( 0, i ), 1 ) ); #endif BASOP_SATURATE_WARNING_ON_EVS - tmp = sub(ener1, ener2); - ener1 = add(add(ener1, ener2), 1); + tmp = sub( ener1, ener2 ); + ener1 = add( add( ener1, ener2 ), 1 ); /* find voice factor (1=voiced, -1=unvoiced) */ - exp = div_s(abs_s(tmp), ener1); + exp = div_s( abs_s( tmp ), ener1 ); IF( LT_16( tmp, 0 ) ) { - exp = negate(exp); + exp = negate( exp ); } *voice_fac = exp; move16(); - IF(flag_tilt == 0) { + IF( flag_tilt == 0 ) + { /* tilt of code for next subframe: 0.5=voiced, 0=unvoiced */ /* tilt_code = (float)(0.25*(1.0 + *voice_fac)) */ - tilt_code = mac_r(8192L * 65536 - 0x8000, *voice_fac, 8192); /*Q15 */ + tilt_code = mac_r( 8192L * 65536 - 0x8000, *voice_fac, 8192 ); /*Q15 */ } - ELSE IF(flag_tilt == 1) + ELSE IF( flag_tilt == 1 ) { /*Between 0.25 (=unvoiced) and 0.5 (=voiced)*/ - //tilt_code = (float)(0.25f + (*voice_fac + 1.0f) * 0.125f); - tilt_code = mac_r(12288L * 65536 - 0x8000, *voice_fac, 4096); /*Q15 */ + // tilt_code = (float)(0.25f + (*voice_fac + 1.0f) * 0.125f); + tilt_code = mac_r( 12288L * 65536 - 0x8000, *voice_fac, 4096 ); /*Q15 */ } ELSE { /*Between 0.28 (=unvoiced) and 0.56 (=voiced)*/ - //tilt_code = (float)(0.28f + (*voice_fac + 1.0f) * 0.14f); - tilt_code = mac_r(13763L * 65536 - 0x8000, *voice_fac, 4588); /*Q15 */ + // tilt_code = (float)(0.28f + (*voice_fac + 1.0f) * 0.14f); + tilt_code = mac_r( 13763L * 65536 - 0x8000, *voice_fac, 4588 ); /*Q15 */ } return tilt_code; @@ -207,13 +210,13 @@ Word16 est_tilt_ivas_fx( /* o : tilt of the code Q15 * Estimate spectral tilt based on the relative E of adaptive * and innovative excitations *-------------------------------------------------------------------*/ -Word16 Est_tilt2( /* o : tilt of the code */ - const Word16 *exc, /* i : adaptive excitation vector Qx */ - const Word16 gain_pit, /* i : adaptive gain Q14 */ - const Word16 *code, /* i : algebraic exctitation vector Q9 */ - const Word32 gain_code, /* i : algebraic code gain Q16 */ - Word16 *voice_fac, /* o : voicing factor Q15 */ - const Word16 Q_exc /* i : Scaling factor of excitation Q0 */ +Word16 Est_tilt2( /* o : tilt of the code */ + const Word16 *exc, /* i : adaptive excitation vector Qx */ + const Word16 gain_pit, /* i : adaptive gain Q14 */ + const Word16 *code, /* i : algebraic exctitation vector Q9 */ + const Word32 gain_code, /* i : algebraic code gain Q16 */ + Word16 *voice_fac, /* o : voicing factor Q15 */ + const Word16 Q_exc /* i : Scaling factor of excitation Q0 */ ) { Word16 i, tmp, exp, ener1, exp1, ener2, exp2; @@ -221,35 +224,35 @@ Word16 Est_tilt2( /* o : tilt of the code */ Word16 tilt_code; /* Scale exc to avoid overflow */ - ener1 = extract_h(Energy_scale(exc, L_SUBFR, Q_exc, &exp1)); + ener1 = extract_h( Energy_scale( exc, L_SUBFR, Q_exc, &exp1 ) ); - exp1 = sub(exp1, add(Q_exc, Q_exc)); - L_tmp = L_mult(gain_pit, gain_pit); /* energy of pitch excitation */ - exp = norm_l(L_tmp); - tmp = extract_h(L_shl(L_tmp, exp)); - ener1 = mult(ener1, tmp); - exp1 = sub(sub(exp1, exp), 10); /* 10 -> gain_pit Q14 to Q9 */ + exp1 = sub( exp1, add( Q_exc, Q_exc ) ); + L_tmp = L_mult( gain_pit, gain_pit ); /* energy of pitch excitation */ + exp = norm_l( L_tmp ); + tmp = extract_h( L_shl( L_tmp, exp ) ); + ener1 = mult( ener1, tmp ); + exp1 = sub( sub( exp1, exp ), 10 ); /* 10 -> gain_pit Q14 to Q9 */ - ener2 = extract_h(Dot_product12(code, code, L_SUBFR, &exp2)); + ener2 = extract_h( Dot_product12( code, code, L_SUBFR, &exp2 ) ); - exp = norm_l(gain_code); - tmp = extract_h(L_shl(gain_code, exp)); - tmp = mult(tmp, tmp); /* energy of innovative code excitation */ - ener2 = mult(ener2, tmp); - exp2 = sub(exp2, add(exp, exp)); + exp = norm_l( gain_code ); + tmp = extract_h( L_shl( gain_code, exp ) ); + tmp = mult( tmp, tmp ); /* energy of innovative code excitation */ + ener2 = mult( ener2, tmp ); + exp2 = sub( exp2, add( exp, exp ) ); - i = sub(exp1, exp2); - ener1 = shr(ener1, sub(1, s_min(i, 0))); - ener2 = shr(ener2, add(s_max(0, i), 1)); + i = sub( exp1, exp2 ); + ener1 = shr( ener1, sub( 1, s_min( i, 0 ) ) ); + ener2 = shr( ener2, add( s_max( 0, i ), 1 ) ); - tmp = sub(ener1, ener2); - ener1 = add(add(ener1, ener2), 1); + tmp = sub( ener1, ener2 ); + ener1 = add( add( ener1, ener2 ), 1 ); /* find voice factor (1=voiced, -1=unvoiced) */ - exp = div_s(abs_s(tmp), ener1); - if (tmp < 0) + exp = div_s( abs_s( tmp ), ener1 ); + if ( tmp < 0 ) { - exp = negate(exp); + exp = negate( exp ); } *voice_fac = exp; move16(); @@ -257,7 +260,7 @@ Word16 Est_tilt2( /* o : tilt of the code */ /* tilt of code for next subframe: 0.5=voiced, 0=unvoiced */ /* tilt_code = (float)(0.25*(1.0 + *voice_fac)) */ - tilt_code = mac_r(8192L*65536-0x8000, *voice_fac, 8192); + tilt_code = mac_r( 8192L * 65536 - 0x8000, *voice_fac, 8192 ); return tilt_code; } @@ -265,127 +268,127 @@ Word16 Est_tilt2( /* o : tilt of the code */ /*---------------------------------------------------------* * Find voice factor and tilt code * *---------------------------------------------------------*/ -void E_UTIL_voice_factor( Word16 *exc, /* i : pointer to the excitation frame Q_new */ - Word16 i_subfr, /* i : subframe index */ - Word16 *code, /* i : innovative codebook Q9 */ - Word16 gain_pit, /* i : adaptive codebook gain 1Q14 */ - Word32 gain_code, /* i : innovative cb. gain 15Q16 */ - Word16 *voice_fac, /* o : subframe voicing estimation Q15 */ - Word16 *tilt_code, /* o : tilt factor Q15 */ - Word16 L_subfr, /* i : subframe length */ - Word16 flag_tilt, /* i : Flag for triggering new voice factor tilt*/ - Word16 Q_new, /* i : excitation buffer format */ - Word16 shift /* i : scaling to get 12bit */ - ) +void E_UTIL_voice_factor( Word16 *exc, /* i : pointer to the excitation frame Q_new */ + Word16 i_subfr, /* i : subframe index */ + Word16 *code, /* i : innovative codebook Q9 */ + Word16 gain_pit, /* i : adaptive codebook gain 1Q14 */ + Word32 gain_code, /* i : innovative cb. gain 15Q16 */ + Word16 *voice_fac, /* o : subframe voicing estimation Q15 */ + Word16 *tilt_code, /* o : tilt factor Q15 */ + Word16 L_subfr, /* i : subframe length */ + Word16 flag_tilt, /* i : Flag for triggering new voice factor tilt*/ + Word16 Q_new, /* i : excitation buffer format */ + Word16 shift /* i : scaling to get 12bit */ +) { Word16 i, e, e2, stmp, exp_ener, fac; Word32 ener, tmp, num; Word64 ener_64; BASOP_SATURATE_ERROR_ON_EVS; - - IF(shift != 0) + + IF( shift != 0 ) + { + fac = shl( 0x4000, add( 1, shift ) ); + /* energy of pitch excitation */ + stmp = mult_r( exc[0 + i_subfr], fac ); /* remove fac bits */ + ener_64 = W_mult0_16_16( stmp, stmp ); + FOR( i = 1; i < L_subfr; i++ ) { - fac = shl(0x4000,add(1,shift)); - /* energy of pitch excitation */ - stmp = mult_r(exc[0+i_subfr], fac); /* remove fac bits */ - ener_64 = W_mult0_16_16(stmp, stmp); - FOR (i=1; i exponent = (15-Q_new)*2+1 */ - } + ener_64 = W_mac0_16_16( ener_64, exc[i + i_subfr], exc[i + i_subfr] ); /* Q_new -> exponent = (15-Q_new)*2+1 */ } - ener = W_sat_l( ener_64 ); - + } + ener = W_sat_l( ener_64 ); + /* exponent of ener: (2*(15-Q_new+shift)+1+2-exp_ener-2*e2) */ - exp_ener = norm_l(ener); - if(ener == 0) + exp_ener = norm_l( ener ); + if ( ener == 0 ) { exp_ener = 31; move16(); } - ener = L_shl(ener,exp_ener); - e2 = norm_s(gain_pit); - gain_pit = shl(gain_pit,e2); - ener = Mpy_32_16_1(ener, mult_r(gain_pit, gain_pit)); + ener = L_shl( ener, exp_ener ); + e2 = norm_s( gain_pit ); + gain_pit = shl( gain_pit, e2 ); + ener = Mpy_32_16_1( ener, mult_r( gain_pit, gain_pit ) ); /* energy of innovative code excitation */ - tmp = L_deposit_l(1); + tmp = L_deposit_l( 1 ); - FOR (i=0; i 13Q18 */ + tmp = L_mac0( tmp, code[i], code[i] ); /* 6Q9 -> 13Q18 */ } /* exponent of tmp: 2*(15-9)+1+2*(15-e)) */ - e = norm_l(gain_code); - gain_code = L_shl(gain_code, e); - tmp = Mpy_32_32(tmp, Mpy_32_32(gain_code,gain_code)); + e = norm_l( gain_code ); + gain_code = L_shl( gain_code, e ); + tmp = Mpy_32_32( tmp, Mpy_32_32( gain_code, gain_code ) ); /* find voice factor (1=voiced, -1=unvoiced) */ /*i = (2*(15-Q_new+shift)+1+2-exp_ener-2*e2) - (2*(15-9)+1 + 2*(15-e));*/ - i = sub(sub(sub(sub(sub(33,add(shift,shift)),add(Q_new,Q_new)),exp_ener),add(e2,e2)),sub(43,add(e,e))); - IF(i >= 0) + i = sub( sub( sub( sub( sub( 33, add( shift, shift ) ), add( Q_new, Q_new ) ), exp_ener ), add( e2, e2 ) ), sub( 43, add( e, e ) ) ); + IF( i >= 0 ) { - ener = L_shr(ener,1); + ener = L_shr( ener, 1 ); #ifdef BASOP_NOGLOB tmp = L_shr_sat( tmp, add( 1, i ) ); #else - tmp = L_shr(tmp, add(1,i)); + tmp = L_shr( tmp, add( 1, i ) ); #endif } ELSE { - tmp = L_shr(tmp,1); + tmp = L_shr( tmp, 1 ); BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB ener = L_shr_sat( ener, sub( 1, i ) ); #else - ener = L_shr(ener, sub(1,i)); + ener = L_shr( ener, sub( 1, i ) ); #endif BASOP_SATURATE_WARNING_ON_EVS } *voice_fac = 0; move16(); - num = L_sub(ener, tmp); - IF(num != 0) + num = L_sub( ener, tmp ); + IF( num != 0 ) { BASOP_SATURATE_WARNING_OFF_EVS /* Allow saturating the voice factor because if has a limited range by definition. */ - *voice_fac = divide3232(num, L_add(ener, tmp)); + *voice_fac = divide3232( num, L_add( ener, tmp ) ); move16(); BASOP_SATURATE_WARNING_ON_EVS } /* find tilt of code for next subframe */ - IF (flag_tilt==0) + IF( flag_tilt == 0 ) { /*Between 0 (=unvoiced) and 0.5 (=voiced)*/ move16(); - *tilt_code = add(8192/*0.25f Q15*/, mult_r(8192/*0.25f Q15*/, *voice_fac)); + *tilt_code = add( 8192 /*0.25f Q15*/, mult_r( 8192 /*0.25f Q15*/, *voice_fac ) ); } - ELSE IF (flag_tilt==1) + ELSE IF( flag_tilt == 1 ) { /*Between 0.25 (=unvoiced) and 0.5 (=voiced)*/ move16(); - *tilt_code = add(mult_r(4096/*0.125f Q15*/, *voice_fac), 12288/*0.125f+0.25f Q15*/); + *tilt_code = add( mult_r( 4096 /*0.125f Q15*/, *voice_fac ), 12288 /*0.125f+0.25f Q15*/ ); } ELSE { /*Between 0.28 (=unvoiced) and 0.56 (=voiced)*/ move16(); - *tilt_code = add(mult_r(4588/*0.14f Q15*/, *voice_fac), 13763/*0.14f+0.28f Q15*/); + *tilt_code = add( mult_r( 4588 /*0.14f Q15*/, *voice_fac ), 13763 /*0.14f+0.28f Q15*/ ); } BASOP_SATURATE_ERROR_OFF_EVS; } diff --git a/lib_com/fd_cng_com.c b/lib_com/fd_cng_com.c index eba4a7980..5e0ec84ed 100644 --- a/lib_com/fd_cng_com.c +++ b/lib_com/fd_cng_com.c @@ -44,8 +44,8 @@ #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED -#define FFT_SCALING_512 1073741824 //Q22 -#define FFT_SCALING_640 1342177280 //Q22 +#define FFT_SCALING_512 1073741824 // Q22 +#define FFT_SCALING_640 1342177280 // Q22 #endif /*------------------------------------------------------------------- * Local function prototypes @@ -88,8 +88,7 @@ ivas_error createFdCngCom_flt( void initFdCngCom_flt( HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ - const float scale -) + const float scale ) { /* Calculate FFT scaling factor */ hFdCngCom->scalingFactor_flt = 1 / ( scale * scale * 8.f ); @@ -101,7 +100,7 @@ void initFdCngCom_flt( /* Initialize the comfort noise generation */ set_f( hFdCngCom->fftBuffer_flt, 0.0f, FFTLEN ); - UNUSED_PARAM(scale); + UNUSED_PARAM( scale ); set_f( hFdCngCom->cngNoiseLevel_flt, 0.0f, FFTCLDFBLEN ); set_f( hFdCngCom->olapBufferSynth2_flt, 0.0f, FFTLEN ); @@ -167,7 +166,7 @@ void deleteFdCngCom_flt( { HANDLE_FD_CNG_COM hsCom = *hFdCngCom; - IF ( hsCom != NULL ) + IF( hsCom != NULL ) { free( hsCom ); *hFdCngCom = NULL; @@ -684,12 +683,12 @@ void apply_scale_flt( *-------------------------------------------------------------------*/ void bandcombinepow_flt( - const float *bandpow, /* i : Power for each band */ - const int16_t nband, /* i : Number of bands */ - int16_t *part, /* i : Partition upper boundaries (band indices starting from 0) */ - const int16_t npart, /* i : Number of partitions */ + const float *bandpow, /* i : Power for each band */ + const int16_t nband, /* i : Number of bands */ + int16_t *part, /* i : Partition upper boundaries (band indices starting from 0) */ + const int16_t npart, /* i : Number of partitions */ const float *psize_inv_flt, /* i : Inverse partition sizes */ - float *partpow /* o : Power for each partition */ + float *partpow /* o : Power for each partition */ ) { int16_t i, p; @@ -810,8 +809,8 @@ static void getmidbands( int16_t *part, /* i : Partition upper boundaries (band indices starting from 0) */ const int16_t npart, /* i : Number of partitions */ int16_t *midband, /* o : Central band of each partition */ - float *psize_flt, /* o : Partition sizes */ - float *psize_inv_flt /* o : Inverse of partition sizes */ + float *psize_flt, /* o : Partition sizes */ + float *psize_inv_flt /* o : Inverse of partition sizes */ ) { int16_t j; @@ -1050,8 +1049,8 @@ void SynthesisSTFT_fx( preemph_ivas_fx( buf_fx + 1, PREEMPH_FAC, M + hFdCngCom->frameSize, &tmp_fx ); // residu(hFdCngCom->A_cng_flt, M, buf + 1 + M, hFdCngCom->exc_cng_flt, hFdCngCom->frameSize); - //floatToFixed_arr( hFdCngCom->A_cng_flt, hFdCngCom->A_cng, Q13, M + 1 ); - //residu_ivas_fx( hFdCngCom->A_cng, Q13, M, buf_fx + 1 + M, hFdCngCom->exc_cng_32fx, hFdCngCom->frameSize ); + // floatToFixed_arr( hFdCngCom->A_cng_flt, hFdCngCom->A_cng, Q13, M + 1 ); + // residu_ivas_fx( hFdCngCom->A_cng, Q13, M, buf_fx + 1 + M, hFdCngCom->exc_cng_32fx, hFdCngCom->frameSize ); residu_ivas_fx( hFdCngCom->A_cng, ( 15 - norm_s( hFdCngCom->A_cng[0] - 1 ) ), M, buf_fx + 1 + M, hFdCngCom->exc_cng_32fx, hFdCngCom->frameSize ); for ( i = 0; i < hFdCngCom->frameSize; i++ ) { @@ -1148,56 +1147,62 @@ void SynthesisSTFT_dirac_fx( Copy32( olapBuffer + hFdCngCom->frameSize, olapBuffer, hFdCngCom->frameSize ); set32_fx( olapBuffer + hFdCngCom->frameSize, 0, hFdCngCom->frameSize ); /*olapBuffer, fftBuffer, olapWin*/ - FOR ( i = shr(hFdCngCom->frameSize, 2); i < i_mult(3, shr(hFdCngCom->frameSize, 2)); i++ ) + FOR( i = shr( hFdCngCom->frameSize, 2 ); i < i_mult( 3, shr( hFdCngCom->frameSize, 2 ) ); i++ ) { - olapBuffer[i] = L_add(olapBuffer[i], Mpy_32_16_1(fftBuffer[i], olapWin[i - hFdCngCom->frameSize / 4])); + olapBuffer[i] = L_add( olapBuffer[i], Mpy_32_16_1( fftBuffer[i], olapWin[i - hFdCngCom->frameSize / 4] ) ); } - FOR ( ; i < i_mult(5, shr(hFdCngCom->frameSize, 2)); i++ ) + FOR( ; i < i_mult( 5, shr( hFdCngCom->frameSize, 2 ) ); i++ ) { - olapBuffer[i] = fftBuffer[i]; move32(); + olapBuffer[i] = fftBuffer[i]; + move32(); } - FOR ( ; i < i_mult(7, shr(hFdCngCom->frameSize, 2)); i++ ) + FOR( ; i < i_mult( 7, shr( hFdCngCom->frameSize, 2 ) ); i++ ) { - olapBuffer[i] = fftBuffer[i]; move32(); + olapBuffer[i] = fftBuffer[i]; + move32(); } - FOR ( ; i < hFdCngCom->fftlen; i++ ) + FOR( ; i < hFdCngCom->fftlen; i++ ) { - olapBuffer[i] = 0; move32(); + olapBuffer[i] = 0; + move32(); } - Word32 fftScale = 0; move32(); - SWITCH(hFdCngCom->fftlen) + Word32 fftScale = 0; + move32(); + SWITCH( hFdCngCom->fftlen ) { case 640: - fftScale = FFT_SCALING_640; move32(); - break; + fftScale = FFT_SCALING_640; + move32(); + break; case 512: - fftScale = FFT_SCALING_512; move32(); - break; + fftScale = FFT_SCALING_512; + move32(); + break; default: - assert(!"Not supported FFT length!"); + assert( !"Not supported FFT length!" ); } /* Get time-domain signal */ - v_multc_fixed(olapBuffer + hFdCngCom->frameSize / 4, fftScale, timeDomainOutput, samples_out); // Q_in - 9 + v_multc_fixed( olapBuffer + hFdCngCom->frameSize / 4, fftScale, timeDomainOutput, samples_out ); // Q_in - 9 /* Get excitation */ - v_multc_fixed(olapBuffer + (hFdCngCom->frameSize / 4) - (M + 1), fftScale, buf, M + 1 + hFdCngCom->frameSize); + v_multc_fixed( olapBuffer + ( hFdCngCom->frameSize / 4 ) - ( M + 1 ), fftScale, buf, M + 1 + hFdCngCom->frameSize ); tmp = buf[0]; preemph_ivas_fx( buf + 1, PREEMPH_FAC, M + hFdCngCom->frameSize, &tmp ); - //residu_ivas_fx( hFdCngCom->A_cng, Q13, M, buf + 1 + M, hFdCngCom->exc_cng_32fx, hFdCngCom->frameSize ); + // residu_ivas_fx( hFdCngCom->A_cng, Q13, M, buf + 1 + M, hFdCngCom->exc_cng_32fx, hFdCngCom->frameSize ); residu_ivas_fx( hFdCngCom->A_cng, 15 - norm_s( hFdCngCom->A_cng[0] - 1 ), M, buf + 1 + M, hFdCngCom->exc_cng_32fx, hFdCngCom->frameSize ); /* update and window olapBuf if we have a output frame that is shorter than the default frame size...*/ - IF ( LT_16(samples_out, hFdCngCom->frameSize )) + IF( LT_16( samples_out, hFdCngCom->frameSize ) ) { - Copy32( olapBuffer + samples_out, olapBuffer + hFdCngCom->frameSize, i_mult(3, shr(hFdCngCom->frameSize, 2))); + Copy32( olapBuffer + samples_out, olapBuffer + hFdCngCom->frameSize, i_mult( 3, shr( hFdCngCom->frameSize, 2 ) ) ); } - FOR ( i = i_mult(5, shr(hFdCngCom->frameSize, 2)); i < i_mult(7, shr(hFdCngCom->frameSize, 2)); i++ ) + FOR( i = i_mult( 5, shr( hFdCngCom->frameSize, 2 ) ); i < i_mult( 7, shr( hFdCngCom->frameSize, 2 ) ); i++ ) { - olapBuffer[i] = Mpy_32_16_1(olapBuffer[i], olapWin[i - 3 * hFdCngCom->frameSize / 4]); + olapBuffer[i] = Mpy_32_16_1( olapBuffer[i], olapWin[i - 3 * hFdCngCom->frameSize / 4] ); } return; @@ -1274,15 +1279,14 @@ float rand_gauss_flt( Word32 rand_gauss_fx( Word32 *x, Word16 *seed, - Word16 q -) + Word16 q ) { Word32 temp; temp = own_random( seed ); - temp = L_add(temp, own_random( seed )); - temp = L_add(temp, own_random( seed )); - temp = L_shr(temp, 15 - q); + temp = L_add( temp, own_random( seed ) ); + temp = L_add( temp, own_random( seed ) ); + temp = L_shr( temp, 15 - q ); *x = temp; @@ -1302,13 +1306,13 @@ Word16 rand_gauss_fix( { Word32 temp; - temp = shr(own_random( seed ), Q2); - temp = L_add(temp, shr(own_random( seed ), Q2)); - temp = L_add(temp, shr(own_random( seed ), Q2)); + temp = shr( own_random( seed ), Q2 ); + temp = L_add( temp, shr( own_random( seed ), Q2 ) ); + temp = L_add( temp, shr( own_random( seed ), Q2 ) ); - *x = (Word16)temp; + *x = (Word16) temp; - return (Word16)temp; + return (Word16) temp; } #endif diff --git a/lib_com/fd_cng_com_fx.c b/lib_com/fd_cng_com_fx.c index a02bc15f4..7125ec40c 100644 --- a/lib_com/fd_cng_com_fx.c +++ b/lib_com/fd_cng_com_fx.c @@ -13,36 +13,34 @@ #include "prot_fx2.h" #include "ivas_prot_fx.h" -#define DELTA_SHIFT 2 -#define DELTA_SHIFT_LD64 67108864l/*DELTA_SHIFT/64.0 Q31*/ -#define CNG_HS 4 /* 4 bit headroom for dot product */ -#define CNG_S 6 /* 1 sign bit, 6 bit integer part, 9 bit frational part for input and output data */ - - /*------------------------------------------------------------------- - * Local function prototypes - *-------------------------------------------------------------------*/ -static void getmidbands(const Word16* part, const Word16 npart, Word16* midband, Word16* psize, - Word16* psize_norm, Word16* psize_norm_exp, Word16* psize_inv); - - - - /*------------------------------------------------------------------- - * createFdCngCom() - * - * Create an instance of type FD_CNG_COM - *-------------------------------------------------------------------*/ +#define DELTA_SHIFT 2 +#define DELTA_SHIFT_LD64 67108864l /*DELTA_SHIFT/64.0 Q31*/ +#define CNG_HS 4 /* 4 bit headroom for dot product */ +#define CNG_S 6 /* 1 sign bit, 6 bit integer part, 9 bit frational part for input and output data */ + +/*------------------------------------------------------------------- + * Local function prototypes + *-------------------------------------------------------------------*/ +static void getmidbands( const Word16 *part, const Word16 npart, Word16 *midband, Word16 *psize, Word16 *psize_norm, Word16 *psize_norm_exp, Word16 *psize_inv ); + + +/*------------------------------------------------------------------- + * createFdCngCom() + * + * Create an instance of type FD_CNG_COM + *-------------------------------------------------------------------*/ ivas_error createFdCngCom( - HANDLE_FD_CNG_COM * hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */ + HANDLE_FD_CNG_COM *hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */ ) { HANDLE_FD_CNG_COM hs; /* Allocate memory */ - hs = (HANDLE_FD_CNG_COM)count_malloc(sizeof(FD_CNG_COM)); + hs = (HANDLE_FD_CNG_COM) count_malloc( sizeof( FD_CNG_COM ) ); - if (hs == NULL) + if ( hs == NULL ) { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FD CNG COM"); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FD CNG COM" ); } *hFdCngCom = hs; @@ -171,16 +169,16 @@ void ivas_initFdCngCom_fx( HANDLE_FD_CNG_COM hFdCngCom, Word16 scale ) return; } #endif -void initFdCngCom(HANDLE_FD_CNG_COM hFdCngCom, Word16 scale) +void initFdCngCom( HANDLE_FD_CNG_COM hFdCngCom, Word16 scale ) { /* Calculate CLDFB scaling factor */ /* shl(i_mult2(scale, scale), 3) does not fit in 16 bit */ /*hFdCngCom->scalingFactor = div_s(1, shl(i_mult2(scale, scale), 3));*/ - assert(2048/*1.0/(1<<4) Q15*/ < mult(scale, scale)); + assert( 2048 /*1.0/(1<<4) Q15*/ < mult( scale, scale ) ); /* Exponent invScalingFactor: -16 = -(2*7 (scale) + 2 (8.0) */ - hFdCngCom->invScalingFactor = shl(mult(scale,scale),1); + hFdCngCom->invScalingFactor = shl( mult( scale, scale ), 1 ); /* Exponent scalingFactor: -15 = -(2*7 (scale) + 2 (8.0) - 1 (1.0)) */ - hFdCngCom->scalingFactor = div_s(0x4000,hFdCngCom->invScalingFactor); + hFdCngCom->scalingFactor = div_s( 0x4000, hFdCngCom->invScalingFactor ); /* Initialize the overlap-add */ set16_fx( hFdCngCom->timeDomainBuffer, 0, L_FRAME16k ); @@ -197,25 +195,27 @@ void initFdCngCom(HANDLE_FD_CNG_COM hFdCngCom, Word16 scale) /* Initialize the comfort noise generation */ set32_fx( hFdCngCom->fftBuffer, 0, FFTLEN ); set32_fx( hFdCngCom->cngNoiseLevel, 0, FFTCLDFBLEN ); - set16_fx( &hFdCngCom->cngNoiseLevelExp, 0, 1); + set16_fx( &hFdCngCom->cngNoiseLevelExp, 0, 1 ); /* Initialize quantizer */ set32_fx( hFdCngCom->sidNoiseEst, 0, NPART ); set16_fx( &hFdCngCom->sidNoiseEstExp, 0, 1 ); - set16_fx( hFdCngCom->A_cng, 0, M+1 ); - hFdCngCom->A_cng[0] = 4096/*1.f Q12*/; /* 3Q12 */ move16(); + set16_fx( hFdCngCom->A_cng, 0, M + 1 ); + hFdCngCom->A_cng[0] = 4096 /*1.f Q12*/; /* 3Q12 */ + move16(); /* Set some counters and flags */ - hFdCngCom->inactive_frame_counter = 0; /* Either SID or zero frames */ move16(); - hFdCngCom->active_frame_counter = 0; + hFdCngCom->inactive_frame_counter = 0; /* Either SID or zero frames */ move16(); - hFdCngCom->frame_type_previous = ACTIVE_FRAME; + hFdCngCom->active_frame_counter = 0; move16(); - hFdCngCom->flag_noisy_speech = 0; + hFdCngCom->frame_type_previous = ACTIVE_FRAME; + move16(); + hFdCngCom->flag_noisy_speech = 0; move16(); hFdCngCom->likelihood_noisy_speech = 0; move16(); - hFdCngCom->numCoreBands = 0; + hFdCngCom->numCoreBands = 0; move16(); hFdCngCom->stopBand = 0; move16(); @@ -229,17 +229,17 @@ void initFdCngCom(HANDLE_FD_CNG_COM hFdCngCom, Word16 scale) move16(); hFdCngCom->seed = 0; move16(); - //hFdCngCom->seed2 = 1; + // hFdCngCom->seed2 = 1; move16(); - //hFdCngCom->seed3 = 2; + // hFdCngCom->seed3 = 2; move16(); hFdCngCom->CngBitrate = -1; move16(); /* Initialize noise estimation algorithm */ set32_fx( hFdCngCom->periodog, 0, PERIODOGLEN ); - mhvals(MSNUMSUBFR*MSSUBFRLEN, &(hFdCngCom->msM_win)); - mhvals(MSSUBFRLEN, &(hFdCngCom->msM_subwin)); + mhvals( MSNUMSUBFR * MSSUBFRLEN, &( hFdCngCom->msM_win ) ); + mhvals( MSSUBFRLEN, &( hFdCngCom->msM_subwin ) ); set32_fx( hFdCngCom->msPeriodogSum, 0, 2 ); hFdCngCom->msPeriodogSum_exp[0] = 0; move16(); @@ -254,21 +254,21 @@ void initFdCngCom(HANDLE_FD_CNG_COM hFdCngCom, Word16 scale) move16(); hFdCngCom->msFrCnt_init_counter = 0; move16(); - hFdCngCom->msFrCnt_init_thresh = 1; + hFdCngCom->msFrCnt_init_thresh = 1; move16(); - hFdCngCom->init_old = 0; + hFdCngCom->init_old = 0; move16(); - hFdCngCom->offsetflag = 0; + hFdCngCom->offsetflag = 0; move16(); - hFdCngCom->msFrCnt = MSSUBFRLEN; + hFdCngCom->msFrCnt = MSSUBFRLEN; move16(); - hFdCngCom->msMinBufferPtr = 0; + hFdCngCom->msMinBufferPtr = 0; move16(); - hFdCngCom->msAlphaCor[0] = 644245120l/*0.3f Q31*/; + hFdCngCom->msAlphaCor[0] = 644245120l /*0.3f Q31*/; move16(); - hFdCngCom->msAlphaCor[1] = 644245120l/*0.3f Q31*/; + hFdCngCom->msAlphaCor[1] = 644245120l /*0.3f Q31*/; move16(); - set16_fx(hFdCngCom->psize, 0, NPART); + set16_fx( hFdCngCom->psize, 0, NPART ); /* Initialize exponents */ hFdCngCom->exp_cldfb_periodog = 0; move16(); @@ -281,14 +281,14 @@ void initFdCngCom(HANDLE_FD_CNG_COM hFdCngCom, Word16 scale) * * Delete an instance of type FD_CNG_COM *-------------------------------------------------------------------*/ -void deleteFdCngCom(HANDLE_FD_CNG_COM * hFdCngCom) /* i/o: Contains the variables related to the CLDFB-based CNG process */ +void deleteFdCngCom( HANDLE_FD_CNG_COM *hFdCngCom ) /* i/o: Contains the variables related to the CLDFB-based CNG process */ { HANDLE_FD_CNG_COM hsCom; hsCom = *hFdCngCom; move16(); - IF (hsCom != NULL) + IF( hsCom != NULL ) { - count_free(hsCom); + count_free( hsCom ); *hFdCngCom = NULL; move16(); } @@ -300,45 +300,44 @@ void deleteFdCngCom(HANDLE_FD_CNG_COM * hFdCngCom) /* i/o: Contains the variable * Initialize the spectral partitioning *-------------------------------------------------------------------*/ void initPartitions( - const Word16* part_in, - const Word16 npart_in, - const Word16 startBand, - const Word16 stopBand, - Word16* part_out, - Word16* npart_out, - Word16* midband, - Word16* psize, - Word16* psize_norm, - Word16* psize_norm_exp, - Word16* psize_inv, - const Word16 stopBandFR -) + const Word16 *part_in, + const Word16 npart_in, + const Word16 startBand, + const Word16 stopBand, + Word16 *part_out, + Word16 *npart_out, + Word16 *midband, + Word16 *psize, + Word16 *psize_norm, + Word16 *psize_norm_exp, + Word16 *psize_inv, + const Word16 stopBandFR ) { Word16 i, j, len_out, tmp16; - IF (part_in != NULL) + IF( part_in != NULL ) { len_out = 0; move16(); - IF (GT_16(stopBandFR, startBand)) + IF( GT_16( stopBandFR, startBand ) ) { - len_out = sub(stopBandFR, startBand); - FOR(i = 0 ; i < len_out; i++) + len_out = sub( stopBandFR, startBand ); + FOR( i = 0; i < len_out; i++ ) { part_out[i] = i; move16(); } } - FOR(j=0 ; j < npart_in; j++) + FOR( j = 0; j < npart_in; j++ ) { - IF (GE_16(part_in[j], stopBand)) + IF( GE_16( part_in[j], stopBand ) ) { BREAK; } - tmp16 = sub(part_in[j],startBand); + tmp16 = sub( part_in[j], startBand ); test(); - if (GE_16(part_in[j],stopBandFR)&&tmp16>=0) + if ( GE_16( part_in[j], stopBandFR ) && tmp16 >= 0 ) { part_out[len_out++] = tmp16; move16(); @@ -347,8 +346,8 @@ void initPartitions( } ELSE { - len_out = sub(stopBand, startBand); - FOR (i = 0 ; i < len_out; i++) + len_out = sub( stopBand, startBand ); + FOR( i = 0; i < len_out; i++ ) { part_out[i] = i; move16(); @@ -357,8 +356,7 @@ void initPartitions( *npart_out = len_out; move16(); - getmidbands(part_out, len_out, midband, psize, psize_norm, psize_norm_exp, psize_inv); - + getmidbands( part_out, len_out, midband, psize, psize_norm, psize_norm_exp, psize_inv ); } @@ -371,8 +369,7 @@ void compress_range( Word32 *in, Word16 in_exp, Word16 *out, - const Word16 len -) + const Word16 len ) { Word16 i; Word32 in_s; @@ -382,24 +379,24 @@ void compress_range( /* out = log2( 1 + in ) */ - IF ( in_exp >= 0 ) + IF( in_exp >= 0 ) { - one_s = L_shr(1073741824l/*0.5 Q31*/,in_exp); - in_exp32 = L_shl(L_deposit_l(add(in_exp,1)),WORD32_BITS-1-LD_DATA_SCALE); - FOR (i=0; i < len; i++) + one_s = L_shr( 1073741824l /*0.5 Q31*/, in_exp ); + in_exp32 = L_shl( L_deposit_l( add( in_exp, 1 ) ), WORD32_BITS - 1 - LD_DATA_SCALE ); + FOR( i = 0; i < len; i++ ) { - in_s = L_add(L_shr(in[i],1),one_s); - L_tmp = L_add(BASOP_Util_Log2(in_s),in_exp32); - if (in_s == 0) + in_s = L_add( L_shr( in[i], 1 ), one_s ); + L_tmp = L_add( BASOP_Util_Log2( in_s ), in_exp32 ); + if ( in_s == 0 ) { out[i] = 0; move16(); } - if (in_s != 0) + if ( in_s != 0 ) { - out[i] = extract_h(L_tmp); + out[i] = extract_h( L_tmp ); } - if(out[i] == 0) + if ( out[i] == 0 ) { out[i] = 1; } @@ -407,27 +404,26 @@ void compress_range( } ELSE { - in_exp = sub(in_exp,1); - in_exp32 = L_shl(L_deposit_l(1),WORD32_BITS-1-LD_DATA_SCALE); - FOR (i=0; i < len; i++) + in_exp = sub( in_exp, 1 ); + in_exp32 = L_shl( L_deposit_l( 1 ), WORD32_BITS - 1 - LD_DATA_SCALE ); + FOR( i = 0; i < len; i++ ) { - L_tmp = L_add(BASOP_Util_Log2(L_add(L_shl(in[i],in_exp),1073741824l/*0.5 Q31*/)),in_exp32); - if (in[i] == 0) + L_tmp = L_add( BASOP_Util_Log2( L_add( L_shl( in[i], in_exp ), 1073741824l /*0.5 Q31*/ ) ), in_exp32 ); + if ( in[i] == 0 ) { out[i] = 0; move16(); } - if (in[i] != 0) + if ( in[i] != 0 ) { - out[i] = extract_h(L_tmp); + out[i] = extract_h( L_tmp ); } - if (out[i] == 0) + if ( out[i] == 0 ) { out[i] = 1; } } } - } /*------------------------------------------------------------------- @@ -439,8 +435,7 @@ void expand_range( Word16 *in, Word32 *out, Word16 *out_exp, - const Word16 len -) + const Word16 len ) { Word16 i; Word16 s; @@ -452,28 +447,28 @@ void expand_range( maxVal = 0; move16(); - FOR (i=0; i < len; i++) + FOR( i = 0; i < len; i++ ) { - maxVal = s_max(maxVal,in[i]); + maxVal = s_max( maxVal, in[i] ); } maxVal2 = maxVal; move16(); s = 0; move16(); - WHILE ( maxVal >= 0 ) + WHILE( maxVal >= 0 ) { - maxVal = sub(maxVal,512/*0.015625 Q15*/); - s = add(s,1); + maxVal = sub( maxVal, 512 /*0.015625 Q15*/ ); + s = add( s, 1 ); } - tmp = sub(maxVal2,maxVal); + tmp = sub( maxVal2, maxVal ); - one_s = L_shr(1073741824l/*0.5 Q31*/,sub(s,1)); - tmp32 = L_shr(726941l/*0.0003385080526823181 Q31*/,s); + one_s = L_shr( 1073741824l /*0.5 Q31*/, sub( s, 1 ) ); + tmp32 = L_shr( 726941l /*0.0003385080526823181 Q31*/, s ); /* out = (2^(in) - 1) */ - FOR (i=0; i < len; i++) + FOR( i = 0; i < len; i++ ) { - out[i] = L_sub(BASOP_Util_InvLog2(L_deposit_h(sub(in[i],tmp))),one_s); + out[i] = L_sub( BASOP_Util_InvLog2( L_deposit_h( sub( in[i], tmp ) ) ), one_s ); move32(); if ( out[i] == 0 ) { @@ -483,7 +478,6 @@ void expand_range( } *out_exp = s; move16(); - } /*------------------------------------------------------------------- @@ -522,8 +516,8 @@ void expand_range_var_exp( FOR( i = 0; i < len; i++ ) { tmp32 = BASOP_util_Pow2( L_deposit_h( in[i] ), in_exp, &tmp_e ); // 2^x - tmp32 = L_sub( tmp32, L_shl( 1, sub( 31, tmp_e ) ) ); // 2^x - 1 - tmp32 = L_shr( tmp32, sub( maxOutExp, tmp_e ) ); // make exp same as maxExpOut + tmp32 = L_sub( tmp32, L_shl( 1, sub( 31, tmp_e ) ) ); // 2^x - 1 + tmp32 = L_shr( tmp32, sub( maxOutExp, tmp_e ) ); // make exp same as maxExpOut out[i] = tmp32; move32(); @@ -548,47 +542,48 @@ void expand_range_var_exp( * Noise estimation using Minimum Statistics (MS) *-------------------------------------------------------------------*/ -void minimum_statistics ( - Word16 len, /* i : Total number of partitions (CLDFB or FFT) */ - Word16 lenFFT, /* i : Number of FFT partitions */ - Word16 *psize, /* i : Partition sizes, fractional */ - Word16 *msPeriodog, /* i : Periodogram (energies) */ - Word16 *msNoiseFloor, /* i/o: Noise floors (energies) */ - Word16 *msNoiseEst, /* i/o: Noise estimates (energies) */ - Word32 *msAlpha, /* i/o: Forgetting factors */ - Word16 *msPsd, /* i/o: Power Spectral Density (smoothed periodogram => energies) */ - Word16 *msPsdFirstMoment, /* i/o: PSD statistics of 1st order (energy means) */ - Word32 *msPsdSecondMoment, /* i/o: PSD statistics of 2nd order (energy variances) */ - Word32 *msMinBuf, /* i/o: Buffer of minima (energies) */ - Word32 *msBminWin, /* o : Bias correction factors */ - Word32 *msBminSubWin, /* o : Bias correction factors */ - Word32 *msCurrentMin, /* i/o: Local minima (energies) */ - Word32 *msCurrentMinOut, /* i/o: Local minima (energies) */ - Word32 *msCurrentMinSubWindow, /* i/o: Local minima (energies) */ - Word16 *msLocalMinFlag, /* i : Binary flag */ - Word16 *msNewMinFlag, /* i : Binary flag */ - Word16 *msPeriodogBuf, /* i/o: Buffer of periodograms (energies) */ - Word16 *msPeriodogBufPtr, /* i/o: Counter */ - HANDLE_FD_CNG_COM hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */ +void minimum_statistics( + Word16 len, /* i : Total number of partitions (CLDFB or FFT) */ + Word16 lenFFT, /* i : Number of FFT partitions */ + Word16 *psize, /* i : Partition sizes, fractional */ + Word16 *msPeriodog, /* i : Periodogram (energies) */ + Word16 *msNoiseFloor, /* i/o: Noise floors (energies) */ + Word16 *msNoiseEst, /* i/o: Noise estimates (energies) */ + Word32 *msAlpha, /* i/o: Forgetting factors */ + Word16 *msPsd, /* i/o: Power Spectral Density (smoothed periodogram => energies) */ + Word16 *msPsdFirstMoment, /* i/o: PSD statistics of 1st order (energy means) */ + Word32 *msPsdSecondMoment, /* i/o: PSD statistics of 2nd order (energy variances) */ + Word32 *msMinBuf, /* i/o: Buffer of minima (energies) */ + Word32 *msBminWin, /* o : Bias correction factors */ + Word32 *msBminSubWin, /* o : Bias correction factors */ + Word32 *msCurrentMin, /* i/o: Local minima (energies) */ + Word32 *msCurrentMinOut, /* i/o: Local minima (energies) */ + Word32 *msCurrentMinSubWindow, /* i/o: Local minima (energies) */ + Word16 *msLocalMinFlag, /* i : Binary flag */ + Word16 *msNewMinFlag, /* i : Binary flag */ + Word16 *msPeriodogBuf, /* i/o: Buffer of periodograms (energies) */ + Word16 *msPeriodogBufPtr, /* i/o: Counter */ + HANDLE_FD_CNG_COM hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */ #ifdef IVAS_CODE_CNG - ,const Word16 enc_dec, /* i : encoder/decoder indicator */ - const Word16 element_mode /* i : IVAS element mode type */ + , + const Word16 enc_dec, /* i : encoder/decoder indicator */ + const Word16 element_mode /* i : IVAS element mode type */ #endif ) { - Word16 i,j,k,s,s1,s2,s3; + Word16 i, j, k, s, s1, s2, s3; Word16 len2; Word16 current_len; Word16 start, stop, cnt; Word16 totsize; Word16 inv_totsize; - Word32 tmp, tmp0, tmp1; - Word32 scalar, scalar2, scalar3; - Word32 snr; - Word32 msAlphaHatMin2; - Word32 BminCorr; - Word32 QeqInvAv; + Word32 tmp, tmp0, tmp1; + Word32 scalar, scalar2, scalar3; + Word32 snr; + Word32 msAlphaHatMin2; + Word32 BminCorr; + Word32 QeqInvAv; Word32 *ptr; Word32 *msPsdSum; Word32 *msPeriodogSum; @@ -611,7 +606,7 @@ void minimum_statistics ( #endif - len2 = i_mult(MSNUMSUBFR,len); + len2 = i_mult( MSNUMSUBFR, len ); msM_win = hFdCngCom->msM_win; move16(); @@ -627,38 +622,41 @@ void minimum_statistics ( msPeriodogSum = hFdCngCom->msPeriodogSum; /* No minimum statistics at initialization */ - IF ( LT_16(hFdCngCom->msFrCnt_init_counter,hFdCngCom->msFrCnt_init_thresh)) + IF( LT_16( hFdCngCom->msFrCnt_init_counter, hFdCngCom->msFrCnt_init_thresh ) ) { - Copy(msPeriodog, msPsd, len); /* 6Q9 */ - Copy(msPeriodog, msNoiseFloor, len); /* 6Q9 */ - Copy(msPeriodog, msNoiseEst, len); /* 6Q9 */ - Copy(msPeriodog, msPsdFirstMoment, len); /* 6Q9 */ + Copy( msPeriodog, msPsd, len ); /* 6Q9 */ + Copy( msPeriodog, msNoiseFloor, len ); /* 6Q9 */ + Copy( msPeriodog, msNoiseEst, len ); /* 6Q9 */ + Copy( msPeriodog, msPsdFirstMoment, len ); /* 6Q9 */ - set32_fx(msPsdSecondMoment, 0l/*0.0 Q31*/, len); - msPeriodogSum[0] = dotp_s_fx(msPeriodog, psize, lenFFT, CNG_HS); + set32_fx( msPsdSecondMoment, 0l /*0.0 Q31*/, len ); + msPeriodogSum[0] = dotp_s_fx( msPeriodog, psize, lenFFT, CNG_HS ); + move32(); + msPsdSum[0] = msPeriodogSum[0]; /* 16Q15 */ move32(); - msPsdSum[0] = msPeriodogSum[0]; /* 16Q15 */ move32(); - IF ( LT_16(lenFFT,len)) + IF( LT_16( lenFFT, len ) ) { - msPeriodogSum[1] = dotp_s_fx(msPeriodog+lenFFT, psize+lenFFT, sub(len,lenFFT), CNG_HS); + msPeriodogSum[1] = dotp_s_fx( msPeriodog + lenFFT, psize + lenFFT, sub( len, lenFFT ), CNG_HS ); + move32(); + msPsdSum[1] = msPeriodogSum[1]; /* 16Q15 */ move32(); - msPsdSum[1] = msPeriodogSum[1]; /* 16Q15 */ move32(); } /* Increment frame counter at initialization */ /* Some frames are sometimes zero at initialization => ignore them */ - IF ( LT_16(msPeriodog[0],hFdCngCom->init_old)) + IF( LT_16( msPeriodog[0], hFdCngCom->init_old ) ) { - set32_fx(msCurrentMinOut, 2147483647l/*1.0 Q31*/, len); /* 16Q15 */ - set32_fx(msCurrentMin, 2147483647l/*1.0 Q31*/, len); /* 16Q15 */ - set32_fx(msMinBuf, 2147483647l/*1.0 Q31*/, len2); /* 16Q15 */ - set32_fx(msCurrentMinSubWindow, 2147483647l/*1.0 Q31*/, len); /* 16Q15 */ + set32_fx( msCurrentMinOut, 2147483647l /*1.0 Q31*/, len ); /* 16Q15 */ + set32_fx( msCurrentMin, 2147483647l /*1.0 Q31*/, len ); /* 16Q15 */ + set32_fx( msMinBuf, 2147483647l /*1.0 Q31*/, len2 ); /* 16Q15 */ + set32_fx( msCurrentMinSubWindow, 2147483647l /*1.0 Q31*/, len ); /* 16Q15 */ - hFdCngCom->msFrCnt_init_counter = add(hFdCngCom->msFrCnt_init_counter,1); + hFdCngCom->msFrCnt_init_counter = add( hFdCngCom->msFrCnt_init_counter, 1 ); move16(); } - hFdCngCom->init_old = msPeriodog[0]; /* 6Q9 */ move16(); + hFdCngCom->init_old = msPeriodog[0]; /* 6Q9 */ + move16(); } ELSE { @@ -671,105 +669,105 @@ void minimum_statistics ( move16(); stop = lenFFT; move16(); - totsize = sub(hFdCngCom->stopFFTbin,hFdCngCom->startBand); - WHILE ( GT_16(stop,start)) + totsize = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); + WHILE( GT_16( stop, start ) ) { - current_len = sub(stop,start); + current_len = sub( stop, start ); /* Compute smoothed correction factor for PSD smoothing */ /* msPeriodogSum[cnt] with format 16Q15 */ - msPeriodogSum[cnt] = dotp_s_fx(msPeriodog+start, psize+start, current_len, CNG_HS); + msPeriodogSum[cnt] = dotp_s_fx( msPeriodog + start, psize + start, current_len, CNG_HS ); move32(); - IF ( msPeriodogSum[cnt] == 0 ) + IF( msPeriodogSum[cnt] == 0 ) { - hFdCngCom->msAlphaCor[cnt] = Mpy_32_16_1(hFdCngCom->msAlphaCor[cnt], msAlphaCorAlpha); + hFdCngCom->msAlphaCor[cnt] = Mpy_32_16_1( hFdCngCom->msAlphaCor[cnt], msAlphaCorAlpha ); move32(); } ELSE { /* calculate scalar with normalized msPeriodogSum[cnt], exponent -2*s1 */ - s1 = norm_l(msPeriodogSum[cnt]); + s1 = norm_l( msPeriodogSum[cnt] ); #ifdef BASOP_NOGLOB msPeriodogSum16 = round_fx_sat( L_shl_sat( msPeriodogSum[cnt], s1 ) ); #else msPeriodogSum16 = round_fx( L_shl( msPeriodogSum[cnt], s1 ) ); #endif - scalar = L_mult(msPeriodogSum16, msPeriodogSum16); + scalar = L_mult( msPeriodogSum16, msPeriodogSum16 ); /* calculate difference, both elements in 16Q15 format, use absolute value to avoid -1.0 x -1.0 multiplications later */ - scalar2 = L_abs(L_sub(msPsdSum[cnt], msPeriodogSum[cnt])); + scalar2 = L_abs( L_sub( msPsdSum[cnt], msPeriodogSum[cnt] ) ); - s2 = WORD32_BITS-1; + s2 = WORD32_BITS - 1; move16(); if ( scalar2 != 0 ) { /* use absolute value to avoid -1.0 x -1.0 multiplications */ - s2 = norm_l(scalar2); + s2 = norm_l( scalar2 ); } #ifdef BASOP_NOGLOB - scalar216 = round_fx_o(L_shl_o(scalar2,s2, &Overflow), &Overflow); + scalar216 = round_fx_o( L_shl_o( scalar2, s2, &Overflow ), &Overflow ); #else - scalar216 = round_fx(L_shl(scalar2,s2)); + scalar216 = round_fx( L_shl( scalar2, s2 ) ); #endif - scalar2 = L_mult(scalar216, scalar216); + scalar2 = L_mult( scalar216, scalar216 ); /* find common exponent */ - tmp16_1 = sub(s1,s2); - tmp16 = s_min(shl(abs_s(tmp16_1),1),WORD32_BITS-1); + tmp16_1 = sub( s1, s2 ); + tmp16 = s_min( shl( abs_s( tmp16_1 ), 1 ), WORD32_BITS - 1 ); if ( tmp16_1 < 0 ) { - scalar2 = L_shr(scalar2,tmp16); + scalar2 = L_shr( scalar2, tmp16 ); } - if(tmp16_1 > 0) + if ( tmp16_1 > 0 ) { - scalar = L_shr(scalar,tmp16); + scalar = L_shr( scalar, tmp16 ); } /* add scalar and scalar2, avoid overflows */ - scalar = L_shr(scalar,1); - scalar2 = L_shr(scalar2,1); - scalar3 = L_add(scalar,scalar2); + scalar = L_shr( scalar, 1 ); + scalar2 = L_shr( scalar2, 1 ); + scalar3 = L_add( scalar, scalar2 ); /* calculate division */ - scalar16 = BASOP_Util_Divide3232_uu_1616_Scale(scalar, scalar3, &s3); - s3 = s_max(s3,-(WORD16_BITS-1)); - scalar16 = shl(scalar16,s3); - scalar16 = s_max(scalar16, MSALPHACORMAX); + scalar16 = BASOP_Util_Divide3232_uu_1616_Scale( scalar, scalar3, &s3 ); + s3 = s_max( s3, -( WORD16_BITS - 1 ) ); + scalar16 = shl( scalar16, s3 ); + scalar16 = s_max( scalar16, MSALPHACORMAX ); - hFdCngCom->msAlphaCor[cnt] = L_add(Mpy_32_16_1(hFdCngCom->msAlphaCor[cnt], msAlphaCorAlpha), - L_mult(scalar16, msAlphaCorAlpha2)); + hFdCngCom->msAlphaCor[cnt] = L_add( Mpy_32_16_1( hFdCngCom->msAlphaCor[cnt], msAlphaCorAlpha ), + L_mult( scalar16, msAlphaCorAlpha2 ) ); move32(); } /* Compute SNR */ /* msPeriodogSum[cnt] with format 16Q15 */ - snr = dotp_s_fx(msNoiseFloor+start, psize+start, current_len, CNG_HS); + snr = dotp_s_fx( msNoiseFloor + start, psize + start, current_len, CNG_HS ); - IF ( GT_32(L_shr(Mpy_32_16_1(msPsdSum[cnt],18431/*0.56246299817 Q15*/),13),snr)) + IF( GT_32( L_shr( Mpy_32_16_1( msPsdSum[cnt], 18431 /*0.56246299817 Q15*/ ), 13 ), snr ) ) { - tmp0 = BASOP_Util_Log2(msPsdSum[cnt]); - tmp1 = BASOP_Util_Log2(snr); - tmp1 = L_sub(tmp0, tmp1); - tmp1 = Mpy_32_16_1(tmp1, MSSNREXP); - msAlphaHatMin2 = BASOP_Util_InvLog2(tmp1); + tmp0 = BASOP_Util_Log2( msPsdSum[cnt] ); + tmp1 = BASOP_Util_Log2( snr ); + tmp1 = L_sub( tmp0, tmp1 ); + tmp1 = Mpy_32_16_1( tmp1, MSSNREXP ); + msAlphaHatMin2 = BASOP_Util_InvLog2( tmp1 ); } ELSE { msAlphaHatMin2 = MSALPHAHATMIN; move32(); } - scalar = Mpy_32_16_1(hFdCngCom->msAlphaCor[cnt], MSALPHAMAX); + scalar = Mpy_32_16_1( hFdCngCom->msAlphaCor[cnt], MSALPHAMAX ); - FOR (j=start; j 0) + if ( tmp16_1 > 0 ) { - scalar2 = L_shr(scalar2,tmp16); + scalar2 = L_shr( scalar2, tmp16 ); } /* add scalar2 and scalar3, avoid overflows */ - scalar2 = L_shr(scalar2,1); - scalar3 = L_shr(scalar3,1); - scalar3 = L_add(scalar2,scalar3); + scalar2 = L_shr( scalar2, 1 ); + scalar3 = L_shr( scalar3, 1 ); + scalar3 = L_add( scalar2, scalar3 ); /* calculate division */ - tmp16 = BASOP_Util_Divide3232_uu_1616_Scale(scalar2, scalar3, &s3); - scalar2 = Mpy_32_16_1(scalar, tmp16); - s3 = s_max(s3,-(WORD32_BITS-1)); - scalar2 = L_shl(scalar2,s3); - msAlpha[j] = L_max(scalar2, msAlphaHatMin2); + tmp16 = BASOP_Util_Divide3232_uu_1616_Scale( scalar2, scalar3, &s3 ); + scalar2 = Mpy_32_16_1( scalar, tmp16 ); + s3 = s_max( s3, -( WORD32_BITS - 1 ) ); + scalar2 = L_shl( scalar2, s3 ); + msAlpha[j] = L_max( scalar2, msAlphaHatMin2 ); move32(); } /* Compute the PSD (smoothed periodogram) in each band */ - msPsd[j] = round_fx(L_add(Mpy_32_16_1(msAlpha[j], msPsd[j]), - Mpy_32_16_1(L_sub(2147483647l/*1.0 Q31*/,msAlpha[j]), msPeriodog[j]))); + msPsd[j] = round_fx( L_add( Mpy_32_16_1( msAlpha[j], msPsd[j] ), + Mpy_32_16_1( L_sub( 2147483647l /*1.0 Q31*/, msAlpha[j] ), msPeriodog[j] ) ) ); } - msPsdSum[cnt] = dotp_s_fx(msPsd+start, psize+start, current_len, CNG_HS); + msPsdSum[cnt] = dotp_s_fx( msPsd + start, psize + start, current_len, CNG_HS ); move32(); - QeqInvAv = 0l/*0.0 Q31*/; + QeqInvAv = 0l /*0.0 Q31*/; move32(); /* scalar: 7Q24 format */ - tmp = 1191182336l/*(float)(MSNUMSUBFR*MSSUBFRLEN)-1.0 Q24*/; + tmp = 1191182336l /*(float)(MSNUMSUBFR*MSSUBFRLEN)-1.0 Q24*/; move32(); - scalar = L_sub(tmp, L_mult(round_fx(tmp), msM_win)); + scalar = L_sub( tmp, L_mult( round_fx( tmp ), msM_win ) ); /* scalar2: 4Q27 format */ - tmp = 1476395008l/*(float)MSSUBFRLEN-1.0 Q27*/; + tmp = 1476395008l /*(float)MSSUBFRLEN-1.0 Q27*/; move32(); - scalar2 = L_sub(tmp, L_mult(round_fx(tmp), msM_subwin)); + scalar2 = L_sub( tmp, L_mult( round_fx( tmp ), msM_subwin ) ); - FOR (j=start; jmsQeqInvAv[cnt] = QeqInvAv; move32(); /* New minimum? */ /* exponent QeqInvAv: CNG_S, exponent MSAV: (4>>1) */ - s = CNG_S+2*MSAV_EXP; + s = CNG_S + 2 * MSAV_EXP; move16(); - BminCorr = Mpy_32_16_1(Sqrt32(QeqInvAv, &s), MSAV); - BminCorr = L_shl(BminCorr,sub(s,1)); + BminCorr = Mpy_32_16_1( Sqrt32( QeqInvAv, &s ), MSAV ); + BminCorr = L_shl( BminCorr, sub( s, 1 ) ); /* exponent BminCorr: 1 */ - BminCorr = L_add(BminCorr, 1073741824l/*0.5 Q31*/); + BminCorr = L_add( BminCorr, 1073741824l /*0.5 Q31*/ ); - FOR (j=start; jmsFrCnt,MSSUBFRLEN)) + IF( GE_16( hFdCngCom->msFrCnt, MSSUBFRLEN ) ) { - FOR ( i = 0; i < 3; i++ ) + FOR( i = 0; i < 3; i++ ) { - IF ( LT_32(hFdCngCom->msQeqInvAv[cnt],L_shr(L_deposit_h(msQeqInvAv_thresh[i]),CNG_S))/*0.0 Q31*/) + IF( LT_32( hFdCngCom->msQeqInvAv[cnt], L_shr( L_deposit_h( msQeqInvAv_thresh[i] ), CNG_S ) ) /*0.0 Q31*/ ) { BREAK; } @@ -982,24 +980,24 @@ void minimum_statistics ( /* Consider the FFT and CLDFB bands separately */ start = stop; move16(); - stop = len; + stop = len; move16(); - totsize = sub(hFdCngCom->stopBand,hFdCngCom->stopFFTbin); - cnt = add(cnt,1); + totsize = sub( hFdCngCom->stopBand, hFdCngCom->stopFFTbin ); + cnt = add( cnt, 1 ); } /*while (stop > start)*/ /* Update minimum between sub windows */ test(); - IF ( GT_16(hFdCngCom->msFrCnt,1)&<_16(hFdCngCom->msFrCnt,MSSUBFRLEN)) + IF( GT_16( hFdCngCom->msFrCnt, 1 ) && LT_16( hFdCngCom->msFrCnt, MSSUBFRLEN ) ) { - FOR (j=0; j 0 ) { msLocalMinFlag[j] = 1; move16(); } - if ( LT_32(msCurrentMinSubWindow[j],msCurrentMinOut[j])/*0.0 Q31*/) + if ( LT_32( msCurrentMinSubWindow[j], msCurrentMinOut[j] ) /*0.0 Q31*/ ) { /* msCurrentMinOut[j] scaled with CNG_S */ msCurrentMinOut[j] = msCurrentMinSubWindow[j]; @@ -1007,23 +1005,23 @@ void minimum_statistics ( } } /* Get the current noise floor */ - Copy_Scale_sig_32_16(msCurrentMinOut, msNoiseFloor, len, -16); + Copy_Scale_sig_32_16( msCurrentMinOut, msNoiseFloor, len, -16 ); } ELSE /* sub window complete */ { - IF ( GE_16(hFdCngCom->msFrCnt,MSSUBFRLEN)) + IF( GE_16( hFdCngCom->msFrCnt, MSSUBFRLEN ) ) { /* Collect buffers */ - Copy32(msCurrentMinSubWindow, msMinBuf+len*hFdCngCom->msMinBufferPtr, len); + Copy32( msCurrentMinSubWindow, msMinBuf + len * hFdCngCom->msMinBufferPtr, len ); /* Compute minimum among all buffers */ - Copy32(msMinBuf, msCurrentMinOut, len); + Copy32( msMinBuf, msCurrentMinOut, len ); ptr = msMinBuf + len; - FOR (i=1; imsSlope[0]; move16(); - FOR (j=0; jmsSlope[1]; move16(); @@ -1045,55 +1043,51 @@ void minimum_statistics ( test(); test(); test(); - IF ( ( msLocalMinFlag[j] != 0 ) - && ( msNewMinFlag[j] == 0 ) - && ( LT_32(L_shr(msCurrentMinSubWindow[j],1),Mpy_32_16_1(msCurrentMinOut[j],slope)) /*0.0 Q31*/ ) - && ( GT_32(msCurrentMinSubWindow[j],msCurrentMinOut[j]) /*0.0 Q31*/ ) - ) + IF( ( msLocalMinFlag[j] != 0 ) && ( msNewMinFlag[j] == 0 ) && ( LT_32( L_shr( msCurrentMinSubWindow[j], 1 ), Mpy_32_16_1( msCurrentMinOut[j], slope ) ) /*0.0 Q31*/ ) && ( GT_32( msCurrentMinSubWindow[j], msCurrentMinOut[j] ) /*0.0 Q31*/ ) ) { msCurrentMinOut[j] = msCurrentMinSubWindow[j]; move32(); i = j; move16(); - FOR (k=0; koffsetflag > 0 ) + IF( hFdCngCom->offsetflag > 0 ) { - Copy(msPeriodog, msPsd, len); - FOR (j=0; j < len; j++) + Copy( msPeriodog, msPsd, len ); + FOR( j = 0; j < len; j++ ) { - msCurrentMinOut[j] = L_deposit_h(msPeriodog[j]); + msCurrentMinOut[j] = L_deposit_h( msPeriodog[j] ); } - set32_fx(hFdCngCom->msAlphaCor, 2147483647l/*1.0 Q31*/, cnt); - set32_fx(msAlpha, 0l/*0.0 Q31*/, len); - Copy(msPeriodog, msPsdFirstMoment, len); - set32_fx(msPsdSecondMoment, 0l/*0.0 Q31*/, len); + set32_fx( hFdCngCom->msAlphaCor, 2147483647l /*1.0 Q31*/, cnt ); + set32_fx( msAlpha, 0l /*0.0 Q31*/, len ); + Copy( msPeriodog, msPsdFirstMoment, len ); + set32_fx( msPsdSecondMoment, 0l /*0.0 Q31*/, len ); - msPsdSum[0] = dotp_s_fx(msPeriodog, psize, lenFFT, CNG_HS); + msPsdSum[0] = dotp_s_fx( msPeriodog, psize, lenFFT, CNG_HS ); move32(); - IF ( LT_16(lenFFT,len)) + IF( LT_16( lenFFT, len ) ) { - msPsdSum[1] = dotp_s_fx(msPeriodog+lenFFT, psize+lenFFT, sub(len,lenFFT), CNG_HS); + msPsdSum[1] = dotp_s_fx( msPeriodog + lenFFT, psize + lenFFT, sub( len, lenFFT ), CNG_HS ); move32(); } } @@ -1108,13 +1102,13 @@ void minimum_statistics ( /* Increment frame counter */ - IF ( EQ_16(hFdCngCom->msFrCnt,MSSUBFRLEN)) + IF( EQ_16( hFdCngCom->msFrCnt, MSSUBFRLEN ) ) { hFdCngCom->msFrCnt = 1; move16(); - hFdCngCom->msMinBufferPtr = add(hFdCngCom->msMinBufferPtr,1); + hFdCngCom->msMinBufferPtr = add( hFdCngCom->msMinBufferPtr, 1 ); move16(); - if ( EQ_16(hFdCngCom->msMinBufferPtr,MSNUMSUBFR)) + if ( EQ_16( hFdCngCom->msMinBufferPtr, MSNUMSUBFR ) ) { hFdCngCom->msMinBufferPtr = 0; move16(); @@ -1122,51 +1116,50 @@ void minimum_statistics ( } ELSE { - hFdCngCom->msFrCnt = add(hFdCngCom->msFrCnt,1); + hFdCngCom->msFrCnt = add( hFdCngCom->msFrCnt, 1 ); } /* Smooth noise estimate during CNG phases */ - FOR (j=0; j= 0/*0.0 Q15*/); + assert( msNoiseEst[j] >= 0 /*0.0 Q15*/ ); } - } #ifdef IVAS_FLOAT_FIXED @@ -1789,31 +1782,29 @@ void minimum_statistics_fx( * Apply bitrate-dependent scale *-------------------------------------------------------------------*/ void apply_scale( - Word32 *scale, /* o : scalefactor */ - const Word16 bwmode, /* i : audio bandwidth */ - const Word32 bitrate, /* i : Bit rate */ - const SCALE_SETUP* scaleTable, /* i : Scale table */ - const Word16 scaleTableSize /* i : Size of scale table */ + Word32 *scale, /* o : scalefactor */ + const Word16 bwmode, /* i : audio bandwidth */ + const Word32 bitrate, /* i : Bit rate */ + const SCALE_SETUP *scaleTable, /* i : Scale table */ + const Word16 scaleTableSize /* i : Size of scale table */ ) { Word16 i; -//PMT("Verifiy if the basop ued are ok for stereo too") - FOR (i=0; i < scaleTableSize; i++) + // PMT("Verifiy if the basop ued are ok for stereo too") + FOR( i = 0; i < scaleTableSize; i++ ) { cast16(); - IF ( s_and( (Word16)EQ_16(bwmode, (Word16)scaleTable[i].bwmode), - s_and( L_sub(bitrate,scaleTable[i].bitrateFrom) >= 0, - L_sub(bitrate,scaleTable[i].bitrateTo) < 0)) - ) + IF( s_and( (Word16) EQ_16( bwmode, (Word16) scaleTable[i].bwmode ), + s_and( L_sub( bitrate, scaleTable[i].bitrateFrom ) >= 0, + L_sub( bitrate, scaleTable[i].bitrateTo ) < 0 ) ) ) { BREAK; } } { - *scale = L_add(*scale, L_deposit_h(scaleTable[i].scale)); + *scale = L_add( *scale, L_deposit_h( scaleTable[i].scale ) ); } - } #ifdef IVAS_FLOAT_FIXED @@ -1823,61 +1814,57 @@ void apply_scale( * Apply bitrate-dependent scale * returns index of scaleTable *-------------------------------------------------------------------*/ - Word16 apply_scale_ind( - Word32 *scale, /* o : scalefactor */ - const Word16 bwmode, /* i : audio bandwidth */ - const Word32 bitrate, /* i : Bit rate */ - const SCALE_SETUP *scaleTable, /* i : Scale table */ - const Word16 scaleTableSize /* i : Size of scale table */ - ) +Word16 apply_scale_ind( + Word32 *scale, /* o : scalefactor */ + const Word16 bwmode, /* i : audio bandwidth */ + const Word32 bitrate, /* i : Bit rate */ + const SCALE_SETUP *scaleTable, /* i : Scale table */ + const Word16 scaleTableSize /* i : Size of scale table */ +) { Word16 i; // PMT("Verifiy if the basop ued are ok for stereo too") - FOR(i = 0; i < scaleTableSize; i++) + FOR( i = 0; i < scaleTableSize; i++ ) { cast16(); - IF(s_and((Word16)EQ_16(bwmode, (Word16)scaleTable[i].bwmode), - s_and(L_sub(bitrate, scaleTable[i].bitrateFrom) >= 0, - L_sub(bitrate, scaleTable[i].bitrateTo) < 0))) + IF( s_and( (Word16) EQ_16( bwmode, (Word16) scaleTable[i].bwmode ), + s_and( L_sub( bitrate, scaleTable[i].bitrateFrom ) >= 0, + L_sub( bitrate, scaleTable[i].bitrateTo ) < 0 ) ) ) { BREAK; } - } { - *scale = L_add(*scale, L_deposit_h(scaleTable[i].scale)); + *scale = L_add( *scale, L_deposit_h( scaleTable[i].scale ) ); } return i; } void apply_scale_ivas_fx( - Word32 *scale, /* o : scalefactor */ - const Word16 bwmode, /* i : audio bandwidth */ - const Word32 bitrate, /* i : Bit rate */ - const SCALE_SETUP* scaleTable, /* i : Scale table */ - const Word16 scaleTableSize, /* i : Size of scale table */ - Word16 *index -) + Word32 *scale, /* o : scalefactor */ + const Word16 bwmode, /* i : audio bandwidth */ + const Word32 bitrate, /* i : Bit rate */ + const SCALE_SETUP *scaleTable, /* i : Scale table */ + const Word16 scaleTableSize, /* i : Size of scale table */ + Word16 *index ) { Word16 i; - //PMT("Verifiy if the basop ued are ok for stereo too") - FOR(i = 0; i < scaleTableSize; i++) + // PMT("Verifiy if the basop ued are ok for stereo too") + FOR( i = 0; i < scaleTableSize; i++ ) { cast16(); - IF(s_and((Word16)EQ_16(bwmode, (Word16)scaleTable[i].bwmode), - s_and(L_sub(bitrate, scaleTable[i].bitrateFrom) >= 0, - L_sub(bitrate, scaleTable[i].bitrateTo) < 0)) - ) + IF( s_and( (Word16) EQ_16( bwmode, (Word16) scaleTable[i].bwmode ), + s_and( L_sub( bitrate, scaleTable[i].bitrateFrom ) >= 0, + L_sub( bitrate, scaleTable[i].bitrateTo ) < 0 ) ) ) { BREAK; } } - assert(i < scaleTableSize); + assert( i < scaleTableSize ); - *scale = L_add(*scale, L_deposit_h(scaleTable[i].scale)); + *scale = L_add( *scale, L_deposit_h( scaleTable[i].scale ) ); *index = i; - } #endif // IVAS_FLOAT_FIXED /*------------------------------------------------------------------- @@ -1886,15 +1873,14 @@ void apply_scale_ivas_fx( * Compute the power for each partition *-------------------------------------------------------------------*/ void bandcombinepow( - const Word32* bandpow, /* i : Power for each band */ - const Word16 exp_bandpow, /* i : exponent of bandpow */ - const Word16 nband, /* i : Number of bands */ - Word16* part, /* i : Partition upper boundaries (band indices starting from 0) */ - const Word16 npart, /* i : Number of partitions */ - const Word16* psize_inv, /* i : Inverse partition sizes */ - Word32* partpow, /* o : Power for each partition */ - Word16* exp_partpow -) + const Word32 *bandpow, /* i : Power for each band */ + const Word16 exp_bandpow, /* i : exponent of bandpow */ + const Word16 nband, /* i : Number of bands */ + Word16 *part, /* i : Partition upper boundaries (band indices starting from 0) */ + const Word16 npart, /* i : Number of partitions */ + const Word16 *psize_inv, /* i : Inverse partition sizes */ + Word32 *partpow, /* o : Power for each partition */ + Word16 *exp_partpow ) { Word16 i, p; @@ -1903,10 +1889,9 @@ void bandcombinepow( Word16 facTabExp[NPART_SHAPING]; - - IF (EQ_16(nband, npart)) + IF( EQ_16( nband, npart ) ) { - Copy32(bandpow, partpow, nband); + Copy32( bandpow, partpow, nband ); smin = 0; move16(); } @@ -1915,40 +1900,39 @@ void bandcombinepow( /* Compute the power in each partition */ prev_part = -1; move16(); - FOR (p=0; p < npart; p++) + FOR( p = 0; p < npart; p++ ) { - len = sub(part[p],prev_part); - facTabExp[p] = getScaleFactor32 (&bandpow[prev_part+1], len); + len = sub( part[p], prev_part ); + facTabExp[p] = getScaleFactor32( &bandpow[prev_part + 1], len ); move16(); prev_part = part[p]; move16(); } - smin = WORD32_BITS-1; + smin = WORD32_BITS - 1; move16(); - FOR (p=0; p < npart; p++) + FOR( p = 0; p < npart; p++ ) { - smin = s_min(smin,facTabExp[p]); + smin = s_min( smin, facTabExp[p] ); } i = 0; move16(); - FOR (p = 0; p < npart; p++) + FOR( p = 0; p < npart; p++ ) { /* Arithmetic averaging of power for all bins in partition */ temp = 0; - move32(); - FOR ( ; i <= part[p]; i++) + move32(); + FOR( ; i <= part[p]; i++ ) { - temp = L_add(temp, Mpy_32_16_1(L_shl(bandpow[i],facTabExp[p]),psize_inv[p])); + temp = L_add( temp, Mpy_32_16_1( L_shl( bandpow[i], facTabExp[p] ), psize_inv[p] ) ); } - partpow[p] = L_shr(temp,sub(facTabExp[p],smin)); + partpow[p] = L_shr( temp, sub( facTabExp[p], smin ) ); move32(); } - } - *exp_partpow = sub(exp_bandpow,smin); + *exp_partpow = sub( exp_bandpow, smin ); move16(); } @@ -1957,64 +1941,62 @@ void bandcombinepow( * * Scale partitions (with smoothing) *-------------------------------------------------------------------*/ -void scalebands ( - const Word32 *partpow, /* i : Power for each partition */ - Word16 *part, /* i : Partition upper boundaries (band indices starting from 0) */ - const Word16 npart, /* i : Number of partitions */ - Word16 *midband, /* i : Central band of each partition */ - const Word16 nFFTpart, /* i : Number of FFT partitions */ - const Word16 nband, /* i : Number of bands */ - Word32 *bandpow, /* o : Power for each band */ - const Word16 flag_fft_en -) +void scalebands( + const Word32 *partpow, /* i : Power for each partition */ + Word16 *part, /* i : Partition upper boundaries (band indices starting from 0) */ + const Word16 npart, /* i : Number of partitions */ + Word16 *midband, /* i : Central band of each partition */ + const Word16 nFFTpart, /* i : Number of FFT partitions */ + const Word16 nband, /* i : Number of bands */ + Word32 *bandpow, /* o : Power for each band */ + const Word16 flag_fft_en ) { Word16 i, j, s, s1, nint, delta, delta_cmp, delta_s; Word16 startBand, startPart, stopPart, stopPartM1; Word32 tmp, val, partpowLD64, partpowLD64M1; - j = 0; move16(); delta = 0; move16(); - partpowLD64M1 = 0L; /* to avoid compilation warnings */ + partpowLD64M1 = 0L; /* to avoid compilation warnings */ /* Interpolate the bin/band-wise levels from the partition levels */ - IF ( EQ_16(nband, npart)) + IF( EQ_16( nband, npart ) ) { - Copy32(partpow, bandpow, npart); + Copy32( partpow, bandpow, npart ); } ELSE { - startBand = 0; + startBand = 0; move16(); - startPart = 0; + startPart = 0; move16(); - stopPart = nFFTpart; + stopPart = nFFTpart; move16(); - WHILE ( LT_16(startBand,nband)) + WHILE( LT_16( startBand, nband ) ) { - stopPartM1 = sub(stopPart, 1); + stopPartM1 = sub( stopPart, 1 ); test(); - IF ( (flag_fft_en != 0) || (GE_16(startPart,nFFTpart))) + IF( ( flag_fft_en != 0 ) || ( GE_16( startPart, nFFTpart ) ) ) { /* first half partition */ j = startPart; move16(); - FOR (i=startBand; i <= midband[j]; i++) + FOR( i = startBand; i <= midband[j]; i++ ) { bandpow[i] = partpow[j]; move32(); } - j = add(j, 1); + j = add( j, 1 ); /* inner partitions */ - IF (j < stopPart) + IF( j < stopPart ) { - partpowLD64M1 = BASOP_Util_Log2(partpow[j-1]); + partpowLD64M1 = BASOP_Util_Log2( partpow[j - 1] ); } /* Debug values to check this variable is set. */ @@ -2027,52 +2009,52 @@ void scalebands ( s = 1; move16(); - FOR ( ; j < stopPart; j++) + FOR( ; j < stopPart; j++ ) { - nint = sub(midband[j], midband[j-1]); + nint = sub( midband[j], midband[j - 1] ); /* log-linear interpolation */ - partpowLD64 = BASOP_Util_Log2(partpow[j]); - tmp = L_sub(partpowLD64, partpowLD64M1); - tmp = Mpy_32_16_1(tmp, getNormReciprocalWord16(nint)); + partpowLD64 = BASOP_Util_Log2( partpow[j] ); + tmp = L_sub( partpowLD64, partpowLD64M1 ); + tmp = Mpy_32_16_1( tmp, getNormReciprocalWord16( nint ) ); /* scale logarithmic value */ - tmp = L_sub(tmp, DELTA_SHIFT_LD64); + tmp = L_sub( tmp, DELTA_SHIFT_LD64 ); delta_s = DELTA_SHIFT; move16(); - WHILE (tmp > 0) + WHILE( tmp > 0 ) { - tmp = L_sub(tmp,33554432l/*0.015625 Q31*/); - delta_s = add(delta_s,1); + tmp = L_sub( tmp, 33554432l /*0.015625 Q31*/ ); + delta_s = add( delta_s, 1 ); } - delta_cmp = shl(1, s_max(-15, sub(WORD16_BITS-1,delta_s))); + delta_cmp = shl( 1, s_max( -15, sub( WORD16_BITS - 1, delta_s ) ) ); - tmp = BASOP_Util_InvLog2(tmp); - s = norm_l(tmp); - s1 = sub(delta_s, s); + tmp = BASOP_Util_InvLog2( tmp ); + s = norm_l( tmp ); + s1 = sub( delta_s, s ); #ifdef BASOP_NOGLOB - delta = round_fx_sat(L_shl_sat(tmp, s)); + delta = round_fx_sat( L_shl_sat( tmp, s ) ); #else - delta = round_fx(L_shl(tmp, s)); + delta = round_fx( L_shl( tmp, s ) ); #endif /* Choose scale such that the interpolation start and end point both are representable and add 1 additional bit hr. */ - delta_s = sub(s_min(norm_l(partpow[j-1]), norm_l(partpow[j])), 1); - val = L_shl(partpow[j-1], delta_s); - FOR ( ; i < midband[j]; i++) + delta_s = sub( s_min( norm_l( partpow[j - 1] ), norm_l( partpow[j] ) ), 1 ); + val = L_shl( partpow[j - 1], delta_s ); + FOR( ; i < midband[j]; i++ ) { - val = L_shl(Mpy_32_16_1(val, delta), s1); - bandpow[i] = L_shr(val, delta_s); + val = L_shl( Mpy_32_16_1( val, delta ), s1 ); + bandpow[i] = L_shr( val, delta_s ); move32(); } - bandpow[i++] = partpow[j]; + bandpow[i++] = partpow[j]; move32(); partpowLD64M1 = partpowLD64; - move32(); + move32(); } - IF ( GT_16(shr(delta, s), delta_cmp)) + IF( GT_16( shr( delta, s ), delta_cmp ) ) { delta = 0x4000; move16(); @@ -2082,23 +2064,21 @@ void scalebands ( /* last half partition */ val = partpow[stopPartM1]; - move32(); - FOR ( ; i <= part[stopPartM1]; i++) + move32(); + FOR( ; i <= part[stopPartM1]; i++ ) { - val = L_shl(Mpy_32_16_1(val,delta), s1); + val = L_shl( Mpy_32_16_1( val, delta ), s1 ); bandpow[i] = val; move32(); } - } - startBand = add(part[stopPartM1], 1); + startBand = add( part[stopPartM1], 1 ); startPart = stopPart; move16(); - stopPart = npart; + stopPart = npart; move16(); } } - } #ifdef IVAS_FLOAT_FIXED @@ -2249,16 +2229,16 @@ void scalebands_fx( * Get central band for each partition *-------------------------------------------------------------------*/ static void getmidbands( - const Word16* part, /* i : Partition upper boundaries (band indices starting from 0) */ - const Word16 npart, /* i : Number of partitions */ - Word16* midband, /* o : Central band of each partition */ - Word16* psize, /* o : Partition sizes */ - Word16* psize_norm, /* o : Partition sizes, fractional values */ - Word16* psize_norm_exp, /* o : Exponent for fractional partition sizes */ - Word16* psize_inv /* o : Inverse of partition sizes */ + const Word16 *part, /* i : Partition upper boundaries (band indices starting from 0) */ + const Word16 npart, /* i : Number of partitions */ + Word16 *midband, /* o : Central band of each partition */ + Word16 *psize, /* o : Partition sizes */ + Word16 *psize_norm, /* o : Partition sizes, fractional values */ + Word16 *psize_norm_exp, /* o : Exponent for fractional partition sizes */ + Word16 *psize_inv /* o : Inverse of partition sizes */ ) { - Word16 j, max_psize, shift; + Word16 j, max_psize, shift; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif @@ -2266,22 +2246,22 @@ static void getmidbands( max_psize = psize[0]; move16(); - /* first half partition */ move16(); + /* first half partition */ move16(); midband[0] = part[0]; - psize[0] = add(part[0], 1); + psize[0] = add( part[0], 1 ); move16(); - psize_inv[0] = getNormReciprocalWord16(psize[0]); + psize_inv[0] = getNormReciprocalWord16( psize[0] ); move16(); /* inner partitions */ - FOR (j = 1; j < npart; j++) + FOR( j = 1; j < npart; j++ ) { - midband[j] = shr(add(add(part[j-1], 1), part[j]), 1); + midband[j] = shr( add( add( part[j - 1], 1 ), part[j] ), 1 ); move16(); - psize[j] = sub(part[j], part[j-1]); + psize[j] = sub( part[j], part[j - 1] ); move16(); - psize_inv[j] = getNormReciprocalWord16(psize[j]); + psize_inv[j] = getNormReciprocalWord16( psize[j] ); move16(); - if(GT_16(psize[j], max_psize)) + if ( GT_16( psize[j], max_psize ) ) { max_psize = psize[j]; move16(); @@ -2290,19 +2270,19 @@ static void getmidbands( shift = 9; move16(); - *psize_norm_exp = sub(15, shift); + *psize_norm_exp = sub( 15, shift ); move16(); - FOR(j=0; j < npart; j++) + FOR( j = 0; j < npart; j++ ) { #ifdef BASOP_NOGLOB - psize_norm[j] = shl_o(psize[j], shift, &Overflow); + psize_norm[j] = shl_o( psize[j], shift, &Overflow ); #else /* BASOP_NOGLOB */ - psize_norm[j] = shl(psize[j], shift); + psize_norm[j] = shl( psize[j], shift ); #endif move16(); } /* minimum_statistics needs fixed exponent of 6 */ - assert(norm_s(-max_psize) >= 9 ); + assert( norm_s( -max_psize ) >= 9 ); } /*------------------------------------------------------------------- @@ -2311,45 +2291,44 @@ static void getmidbands( * STFT analysis filterbank *-------------------------------------------------------------------*/ -void AnalysisSTFT ( +void AnalysisSTFT( const Word16 *timeDomainInput, /* i : pointer to time signal */ Word16 Q, - Word32 *fftBuffer, /* o : FFT bins */ - Word16 *fftBuffer_exp, /* i : exponent of FFT bins */ - HANDLE_FD_CNG_COM hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */ + Word32 *fftBuffer, /* o : FFT bins */ + Word16 *fftBuffer_exp, /* i : exponent of FFT bins */ + HANDLE_FD_CNG_COM hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */ ) { - Word16 i, len; - Word16 len2; + Word16 i, len; + Word16 len2; const PWord16 *olapWin; Word16 *olapBuffer; - - assert( (hFdCngCom->fftlen>>1) == hFdCngCom->frameSize); + assert( ( hFdCngCom->fftlen >> 1 ) == hFdCngCom->frameSize ); /* pointer inititialization */ - assert(hFdCngCom->olapBufferAna != NULL); + assert( hFdCngCom->olapBufferAna != NULL ); olapBuffer = hFdCngCom->olapBufferAna; olapWin = hFdCngCom->olapWinAna; /* olapWin factor is scaled with one bit */ *fftBuffer_exp = 1; move16(); - len = sub(hFdCngCom->fftlen,hFdCngCom->frameSize); - assert(len <= 320); /* see size of olapBuffer */ + len = sub( hFdCngCom->fftlen, hFdCngCom->frameSize ); + assert( len <= 320 ); /* see size of olapBuffer */ /* Window the signal */ - len2 = shr(len,1); - FOR (i=0; i < len2; i++) + len2 = shr( len, 1 ); + FOR( i = 0; i < len2; i++ ) { move32(); move32(); - fftBuffer[i] = L_mult(olapBuffer[i], mult_r(olapWin[i].v.im, 23170/*1.4142135623730950488016887242097 Q14*/)); - fftBuffer[i+len2] = L_mult(olapBuffer[i+len2], mult_r(olapWin[len2-1-i].v.re, 23170/*1.4142135623730950488016887242097 Q14*/)); + fftBuffer[i] = L_mult( olapBuffer[i], mult_r( olapWin[i].v.im, 23170 /*1.4142135623730950488016887242097 Q14*/ ) ); + fftBuffer[i + len2] = L_mult( olapBuffer[i + len2], mult_r( olapWin[len2 - 1 - i].v.re, 23170 /*1.4142135623730950488016887242097 Q14*/ ) ); } - len2 = shr(hFdCngCom->frameSize,1); - FOR (i=0; i frameSize, 1 ); + FOR( i = 0; i < len2; i++ ) { move32(); move32(); @@ -2363,9 +2342,9 @@ void AnalysisSTFT ( } /* Perform FFT */ - BASOP_rfft(fftBuffer, hFdCngCom->fftlen, fftBuffer_exp, -1); + BASOP_rfft( fftBuffer, hFdCngCom->fftlen, fftBuffer_exp, -1 ); - FOR (i=0; i frameSize, len ) + i], Q ); @@ -2374,7 +2353,6 @@ void AnalysisSTFT ( #endif move16(); } - } #ifdef IVAS_FLOAT_FIXED @@ -2440,125 +2418,124 @@ void AnalysisSTFT_fx( * STFT synthesis filterbank *-------------------------------------------------------------------*/ -void SynthesisSTFT ( - Word32 *fftBuffer, /* i : pointer to FFT bins */ - Word16 fftBufferExp, /* i : exponent of FFT bins */ - Word16 *timeDomainOutput, /* o : pointer to time domain signal */ - Word16 *olapBuffer, /* i/o : pointer to overlap buffer */ - const PWord16 *olapWin, /* i : pointer to overlap window */ +void SynthesisSTFT( + Word32 *fftBuffer, /* i : pointer to FFT bins */ + Word16 fftBufferExp, /* i : exponent of FFT bins */ + Word16 *timeDomainOutput, /* o : pointer to time domain signal */ + Word16 *olapBuffer, /* i/o : pointer to overlap buffer */ + const PWord16 *olapWin, /* i : pointer to overlap window */ Word16 tcx_transition, HANDLE_FD_CNG_COM hFdCngCom, /* i/o : pointer to FD_CNG structure containing all buffers and variables */ Word16 gen_exc, Word16 *Q_new, - const Word16 element_mode, /* i : element mode */ - const Word16 nchan_out /* i : number of output channels */ + const Word16 element_mode, /* i : element mode */ + const Word16 nchan_out /* i : number of output channels */ ) { Word16 i, len, scale, tmp; - Word16 len2, len3, len4; - Word16 buf[M+1+L_FRAME16k]; + Word16 len2, len3, len4; + Word16 buf[M + 1 + L_FRAME16k]; /* Perform IFFT */ scale = 0; - BASOP_rfft(fftBuffer, hFdCngCom->fftlen, &scale, 1); - fftBufferExp = add(fftBufferExp, scale); + BASOP_rfft( fftBuffer, hFdCngCom->fftlen, &scale, 1 ); + fftBufferExp = add( fftBufferExp, scale ); hFdCngCom->fftBuffer_exp = fftBufferExp; - fftBufferExp = add(fftBufferExp, hFdCngCom->fftlenShift); + fftBufferExp = add( fftBufferExp, hFdCngCom->fftlenShift ); /* Perform overlap-add */ /* Handle overlap in P/S domain for stereo */ - IF ((EQ_16(element_mode, IVAS_CPE_TD) || EQ_16(element_mode, IVAS_CPE_DFT)) && EQ_16(nchan_out, 2) ) + IF( ( EQ_16( element_mode, IVAS_CPE_TD ) || EQ_16( element_mode, IVAS_CPE_DFT ) ) && EQ_16( nchan_out, 2 ) ) { - Copy(olapBuffer + 3 * hFdCngCom->frameSize / 4 - (M + 1), buf, hFdCngCom->frameSize + M + 1); - set16_fx(olapBuffer, 0, hFdCngCom->fftlen); + Copy( olapBuffer + 3 * hFdCngCom->frameSize / 4 - ( M + 1 ), buf, hFdCngCom->frameSize + M + 1 ); + set16_fx( olapBuffer, 0, hFdCngCom->fftlen ); } ELSE { - Copy(olapBuffer + hFdCngCom->frameSize, olapBuffer, hFdCngCom->frameSize); - set16_fx(olapBuffer + hFdCngCom->frameSize, 0, hFdCngCom->frameSize); + Copy( olapBuffer + hFdCngCom->frameSize, olapBuffer, hFdCngCom->frameSize ); + set16_fx( olapBuffer + hFdCngCom->frameSize, 0, hFdCngCom->frameSize ); } - len2 = shr(hFdCngCom->fftlen,2); - len4 = shr(hFdCngCom->fftlen,3); - len3 = add(len2,len4); - len = add(hFdCngCom->frameSize,len4); - IF ( tcx_transition ) + len2 = shr( hFdCngCom->fftlen, 2 ); + len4 = shr( hFdCngCom->fftlen, 3 ); + len3 = add( len2, len4 ); + len = add( hFdCngCom->frameSize, len4 ); + IF( tcx_transition ) { - FOR (i=0; i < len; i++) + FOR( i = 0; i < len; i++ ) { - olapBuffer[i] = round_fx(L_shl(fftBuffer[i],fftBufferExp-15)); + olapBuffer[i] = round_fx( L_shl( fftBuffer[i], fftBufferExp - 15 ) ); } } ELSE { - FOR (i=0; i < len4; i++) + FOR( i = 0; i < len4; i++ ) { - olapBuffer[i+1*len4] = add_sat(olapBuffer[i+1*len4], mult_r(round_fx(L_shl(fftBuffer[i+1*len4],fftBufferExp-15)),olapWin[i].v.im)); + olapBuffer[i + 1 * len4] = add_sat( olapBuffer[i + 1 * len4], mult_r( round_fx( L_shl( fftBuffer[i + 1 * len4], fftBufferExp - 15 ) ), olapWin[i].v.im ) ); move16(); - olapBuffer[i+2*len4] = add_sat(olapBuffer[i+2*len4], mult_r(round_fx(L_shl(fftBuffer[i+2*len4],fftBufferExp-15)),olapWin[len4-1-i].v.re)); + olapBuffer[i + 2 * len4] = add_sat( olapBuffer[i + 2 * len4], mult_r( round_fx( L_shl( fftBuffer[i + 2 * len4], fftBufferExp - 15 ) ), olapWin[len4 - 1 - i].v.re ) ); move16(); } - FOR (i=len3; i < len; i++) + FOR( i = len3; i < len; i++ ) { - olapBuffer[i] = round_fx_sat(L_shl_sat(fftBuffer[i],fftBufferExp-15)); + olapBuffer[i] = round_fx_sat( L_shl_sat( fftBuffer[i], fftBufferExp - 15 ) ); } } - FOR (i=0; i < len4; i++) + FOR( i = 0; i < len4; i++ ) { - olapBuffer[i+5*len4] = mult_r(round_fx(L_shl(fftBuffer[i+5*len4],fftBufferExp-15)),olapWin[i].v.re); + olapBuffer[i + 5 * len4] = mult_r( round_fx( L_shl( fftBuffer[i + 5 * len4], fftBufferExp - 15 ) ), olapWin[i].v.re ); move16(); - olapBuffer[i+6*len4] = mult_r(round_fx(L_shl(fftBuffer[i+6*len4],fftBufferExp-15)),olapWin[len4-1-i].v.im); + olapBuffer[i + 6 * len4] = mult_r( round_fx( L_shl( fftBuffer[i + 6 * len4], fftBufferExp - 15 ) ), olapWin[len4 - 1 - i].v.im ); move16(); } len = add( len, len2 ); - FOR (i=len; i < hFdCngCom->fftlen ; i++) + FOR( i = len; i < hFdCngCom->fftlen; i++ ) { olapBuffer[i] = 0; move16(); } /* Get time-domain signal */ - FOR (i=0; i < hFdCngCom->frameSize; i++) + FOR( i = 0; i < hFdCngCom->frameSize; i++ ) { - timeDomainOutput[i] = mult_r( olapBuffer[i+len4], hFdCngCom->fftlenFac ); + timeDomainOutput[i] = mult_r( olapBuffer[i + len4], hFdCngCom->fftlenFac ); move16(); } /* Generate excitation */ #ifdef IVAS_CODE_CNG_COM PME() - if ((element_mode == IVAS_CPE_TD || element_mode == IVAS_CPE_DFT) && nchan_out == 2) + if ( ( element_mode == IVAS_CPE_TD || element_mode == IVAS_CPE_DFT ) && nchan_out == 2 ) { - for (i = 0; i < hFdCngCom->frameSize / 2; i++) + for ( i = 0; i < hFdCngCom->frameSize / 2; i++ ) { - buf[i + (M + 1)] += olapBuffer[i + hFdCngCom->frameSize / 4]; + buf[i + ( M + 1 )] += olapBuffer[i + hFdCngCom->frameSize / 4]; } - v_multc(buf, (float)(hFdCngCom->fftlen / 2), buf, M + 1 + hFdCngCom->frameSize); + v_multc( buf, (float) ( hFdCngCom->fftlen / 2 ), buf, M + 1 + hFdCngCom->frameSize ); } else #endif { - FOR(i = 0; i < M + 1 + hFdCngCom->frameSize; i++) + FOR( i = 0; i < M + 1 + hFdCngCom->frameSize; i++ ) { - buf[i] = mult_r(olapBuffer[i + len4 - M - 1], hFdCngCom->fftlenFac); + buf[i] = mult_r( olapBuffer[i + len4 - M - 1], hFdCngCom->fftlenFac ); move16(); } tmp = buf[0]; } - IF ( EQ_16( gen_exc, 1 )) + IF( EQ_16( gen_exc, 1 ) ) { - E_UTIL_f_preemph2( *Q_new-1, buf+1, PREEMPH_FAC, M+hFdCngCom->frameSize, &tmp ); - Residu3_fx( hFdCngCom->A_cng, buf+1+M, hFdCngCom->exc_cng, hFdCngCom->frameSize, 1 ); + E_UTIL_f_preemph2( *Q_new - 1, buf + 1, PREEMPH_FAC, M + hFdCngCom->frameSize, &tmp ); + Residu3_fx( hFdCngCom->A_cng, buf + 1 + M, hFdCngCom->exc_cng, hFdCngCom->frameSize, 1 ); } - IF ( EQ_16( gen_exc, 2 )) + IF( EQ_16( gen_exc, 2 ) ) { - *Q_new = E_UTIL_f_preemph3( buf+1, PREEMPH_FAC, M+hFdCngCom->frameSize, &tmp, 1 ); - Residu3_fx( hFdCngCom->A_cng, buf+1+M, hFdCngCom->exc_cng, hFdCngCom->frameSize, 1 ); + *Q_new = E_UTIL_f_preemph3( buf + 1, PREEMPH_FAC, M + hFdCngCom->frameSize, &tmp, 1 ); + Residu3_fx( hFdCngCom->A_cng, buf + 1 + M, hFdCngCom->exc_cng, hFdCngCom->frameSize, 1 ); } - } #ifdef IVAS_CODE_CNG_COM /*------------------------------------------------------------------- @@ -2568,10 +2545,10 @@ void SynthesisSTFT ( *-------------------------------------------------------------------*/ void SynthesisSTFT_dirac( - float* fftBuffer, /* i : FFT bins */ - float* timeDomainOutput, - float* olapBuffer, - const float* olapWin, + float *fftBuffer, /* i : FFT bins */ + float *timeDomainOutput, + float *olapBuffer, + const float *olapWin, const int16_t samples_out, HANDLE_FD_CNG_COM hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */ ) @@ -2580,46 +2557,46 @@ void SynthesisSTFT_dirac( float buf[M + 1 + 320], tmp; /* Perform IFFT */ - RFFTN(fftBuffer, hFdCngCom->fftSineTab, hFdCngCom->fftlen, 1); + RFFTN( fftBuffer, hFdCngCom->fftSineTab, hFdCngCom->fftlen, 1 ); /* Handle overlap in P/S domain for stereo */ - mvr2r(olapBuffer + hFdCngCom->frameSize, olapBuffer, hFdCngCom->frameSize); - set_f(olapBuffer + hFdCngCom->frameSize, 0.0f, hFdCngCom->frameSize); /*olapBuffer, fftBuffer, olapWin*/ + mvr2r( olapBuffer + hFdCngCom->frameSize, olapBuffer, hFdCngCom->frameSize ); + set_f( olapBuffer + hFdCngCom->frameSize, 0.0f, hFdCngCom->frameSize ); /*olapBuffer, fftBuffer, olapWin*/ - for (i = hFdCngCom->frameSize / 4; i < 3 * hFdCngCom->frameSize / 4; i++) + for ( i = hFdCngCom->frameSize / 4; i < 3 * hFdCngCom->frameSize / 4; i++ ) { olapBuffer[i] += fftBuffer[i] * olapWin[i - hFdCngCom->frameSize / 4]; } - for (; i < 5 * hFdCngCom->frameSize / 4; i++) + for ( ; i < 5 * hFdCngCom->frameSize / 4; i++ ) { olapBuffer[i] = fftBuffer[i]; } - for (; i < 7 * hFdCngCom->frameSize / 4; i++) + for ( ; i < 7 * hFdCngCom->frameSize / 4; i++ ) { olapBuffer[i] = fftBuffer[i]; } - for (; i < hFdCngCom->fftlen; i++) + for ( ; i < hFdCngCom->fftlen; i++ ) { olapBuffer[i] = 0; } /* Get time-domain signal */ - v_multc(olapBuffer + hFdCngCom->frameSize / 4, (float)(hFdCngCom->fftlen / 2), timeDomainOutput, samples_out); + v_multc( olapBuffer + hFdCngCom->frameSize / 4, (float) ( hFdCngCom->fftlen / 2 ), timeDomainOutput, samples_out ); /* Get excitation */ - v_multc(olapBuffer + hFdCngCom->frameSize / 4 - (M + 1), (float)(hFdCngCom->fftlen / 2), buf, M + 1 + hFdCngCom->frameSize); + v_multc( olapBuffer + hFdCngCom->frameSize / 4 - ( M + 1 ), (float) ( hFdCngCom->fftlen / 2 ), buf, M + 1 + hFdCngCom->frameSize ); tmp = buf[0]; - preemph(buf + 1, PREEMPH_FAC, M + hFdCngCom->frameSize, &tmp); - residu(hFdCngCom->A_cng, M, buf + 1 + M, hFdCngCom->exc_cng, hFdCngCom->frameSize); + preemph( buf + 1, PREEMPH_FAC, M + hFdCngCom->frameSize, &tmp ); + residu( hFdCngCom->A_cng, M, buf + 1 + M, hFdCngCom->exc_cng, hFdCngCom->frameSize ); /* update and window olapBuf if we have a output frame that is shorter than the default frame size...*/ - if (samples_out < hFdCngCom->frameSize) + if ( samples_out < hFdCngCom->frameSize ) { - mvr2r(olapBuffer + samples_out, olapBuffer + hFdCngCom->frameSize, 3 * hFdCngCom->frameSize / 4); + mvr2r( olapBuffer + samples_out, olapBuffer + hFdCngCom->frameSize, 3 * hFdCngCom->frameSize / 4 ); } - for (i = 5 * hFdCngCom->frameSize / 4; i < 7 * hFdCngCom->frameSize / 4; i++) + for ( i = 5 * hFdCngCom->frameSize / 4; i < 7 * hFdCngCom->frameSize / 4; i++ ) { olapBuffer[i] *= olapWin[i - 3 * hFdCngCom->frameSize / 4]; } @@ -2629,11 +2606,11 @@ void SynthesisSTFT_dirac( #endif /************************************************************************************** -* Compute some values used in the bias correction of the minimum statistics algorithm * -**************************************************************************************/ + * Compute some values used in the bias correction of the minimum statistics algorithm * + **************************************************************************************/ void mhvals( const Word16 d, - Word16 * m /*, float * h*/ + Word16 *m /*, float * h*/ ) { Word16 i, j; @@ -2641,27 +2618,27 @@ void mhvals( move16(); - assert( d==72 || d==12); /* function only tested for d==72 and d==12) */ + assert( d == 72 || d == 12 ); /* function only tested for d==72 and d==12) */ i = 0; move16(); - FOR (i=0 ; i < len ; i++) + FOR( i = 0; i < len; i++ ) { - IF (LE_16(d,d_array[i])) + IF( LE_16( d, d_array[i] ) ) { BREAK; } } - IF (EQ_16(i, len)) + IF( EQ_16( i, len ) ) { - i = sub(len, 1); + i = sub( len, 1 ); j = i; move16(); } ELSE { - j = sub(i, 1); + j = sub( i, 1 ); } - IF (EQ_16(d, d_array[i])) + IF( EQ_16( d, d_array[i] ) ) { *m = m_array[i]; move16(); @@ -2673,41 +2650,41 @@ void mhvals( /* d_array has exponent 15 */ - qj_e = 15; + qj_e = 15; move16(); - qj_m = L_deposit_h(d_array[i-1]); + qj_m = L_deposit_h( d_array[i - 1] ); - qi_e = 15; + qi_e = 15; move16(); - qi_m = L_deposit_h(d_array[i]); + qi_m = L_deposit_h( d_array[i] ); - q_e = 15; + q_e = 15; move16(); - q_m = L_deposit_h(d); + q_m = L_deposit_h( d ); - qj_m = Sqrt32(qj_m, &qj_e); - qi_m = Sqrt32(qi_m, &qi_e); - q_m = Sqrt32(q_m, &q_e); + qj_m = Sqrt32( qj_m, &qj_e ); + qi_m = Sqrt32( qi_m, &qi_e ); + q_m = Sqrt32( q_m, &q_e ); - tmp1_m = Mpy_32_32(qi_m, qj_m); - tmp1_e = add(qi_e, qj_e); - tmp1_m = L_deposit_h(BASOP_Util_Divide3232_Scale(tmp1_m, q_m, &shift)); - tmp1_e = sub(tmp1_e, q_e); - tmp1_e = add(tmp1_e, shift); - tmp1_m = BASOP_Util_Add_Mant32Exp(tmp1_m, tmp1_e, L_negate(qj_m), qj_e, &tmp1_e); + tmp1_m = Mpy_32_32( qi_m, qj_m ); + tmp1_e = add( qi_e, qj_e ); + tmp1_m = L_deposit_h( BASOP_Util_Divide3232_Scale( tmp1_m, q_m, &shift ) ); + tmp1_e = sub( tmp1_e, q_e ); + tmp1_e = add( tmp1_e, shift ); + tmp1_m = BASOP_Util_Add_Mant32Exp( tmp1_m, tmp1_e, L_negate( qj_m ), qj_e, &tmp1_e ); - tmp2_m = BASOP_Util_Add_Mant32Exp (qi_m, qi_e, L_negate(qj_m), qj_e, &tmp2_e); - tmp1_w16_m = round_fx(tmp2_m); + tmp2_m = BASOP_Util_Add_Mant32Exp( qi_m, qi_e, L_negate( qj_m ), qj_e, &tmp2_e ); + tmp1_w16_m = round_fx( tmp2_m ); tmp1_w16_e = tmp2_e; move16(); - BASOP_Util_Divide_MantExp(sub(m_array[j], m_array[i]), 0, tmp1_w16_m, tmp1_w16_e, &tmp1_w16_m, &tmp1_w16_e); + BASOP_Util_Divide_MantExp( sub( m_array[j], m_array[i] ), 0, tmp1_w16_m, tmp1_w16_e, &tmp1_w16_m, &tmp1_w16_e ); - tmp2_m = Mpy_32_16_1(tmp1_m, tmp1_w16_m); - tmp2_e = add(tmp1_e, tmp1_w16_e); + tmp2_m = Mpy_32_16_1( tmp1_m, tmp1_w16_m ); + tmp2_e = add( tmp1_e, tmp1_w16_e ); - tmp2_m = BASOP_Util_Add_Mant32Exp (tmp2_m, tmp2_e, L_deposit_h(m_array[i]), 0, &tmp2_e); - assert(tmp2_e == 0); - *m = extract_h(tmp2_m); + tmp2_m = BASOP_Util_Add_Mant32Exp( tmp2_m, tmp2_e, L_deposit_h( m_array[i] ), 0, &tmp2_e ); + assert( tmp2_e == 0 ); + *m = extract_h( tmp2_m ); } } @@ -2718,24 +2695,24 @@ void mhvals( * Returns: * random signal format Q3.29 *-------------------------------------------------------------------*/ -Word32 rand_gauss (Word16 *seed) +Word32 rand_gauss( Word16 *seed ) { Word32 temp; Word16 loc_seed; /* This unrolled version reduces the cycles from 17 to 10 */ - loc_seed = extract_l(L_mac0(13849, *seed, 31821)); - temp = L_deposit_l(loc_seed); + loc_seed = extract_l( L_mac0( 13849, *seed, 31821 ) ); + temp = L_deposit_l( loc_seed ); - loc_seed = extract_l(L_mac0(13849, loc_seed, 31821)); - temp = L_msu0(temp,loc_seed,-1); + loc_seed = extract_l( L_mac0( 13849, loc_seed, 31821 ) ); + temp = L_msu0( temp, loc_seed, -1 ); - loc_seed = extract_l(L_mac0(13849, loc_seed, 31821)); - temp = L_msu0(temp,loc_seed,-1); + loc_seed = extract_l( L_mac0( 13849, loc_seed, 31821 ) ); + temp = L_msu0( temp, loc_seed, -1 ); *seed = loc_seed; move16(); - return L_shl(temp,WORD16_BITS-CNG_RAND_GAUSS_SHIFT); + return L_shl( temp, WORD16_BITS - CNG_RAND_GAUSS_SHIFT ); } /*------------------------------------------------------------------- @@ -2744,11 +2721,11 @@ Word32 rand_gauss (Word16 *seed) * *-------------------------------------------------------------------*/ -void lpc_from_spectrum ( +void lpc_from_spectrum( HANDLE_FD_CNG_COM hFdCngCom, - const Word16 start, /*i : start band*/ - const Word16 stop, /*i : stop band*/ - const Word16 preemph_fac /*i : preemphase factor format Q1.15*/ + const Word16 start, /*i : start band*/ + const Word16 stop, /*i : stop band*/ + const Word16 preemph_fac /*i : preemphase factor format Q1.15*/ ) { Word16 i, s1, s2, s3, fftlen2, scale, fftlen4, fftlen8, len, step, preemph_fac2; @@ -2756,58 +2733,58 @@ void lpc_from_spectrum ( Word16 tmp, r_h[32], r_l[32]; const PWord16 *table; - Word32* powspec = hFdCngCom->cngNoiseLevel; /*i : pointer to noise levels format Q5.27*/ - Word16 powspec_exp = hFdCngCom->cngNoiseLevelExp; - Word16 fftlen = hFdCngCom->fftlen; /*i : size of fft*/ - Word16*A = hFdCngCom->A_cng; /*o : lpc coefficients format Q3.12*/ - Word16 lpcorder = M; + Word32 *powspec = hFdCngCom->cngNoiseLevel; /*i : pointer to noise levels format Q5.27*/ + Word16 powspec_exp = hFdCngCom->cngNoiseLevelExp; + Word16 fftlen = hFdCngCom->fftlen; /*i : size of fft*/ + Word16 *A = hFdCngCom->A_cng; /*o : lpc coefficients format Q3.12*/ + Word16 lpcorder = M; scale = 0; move16(); - fftlen2 = shr(fftlen,1); - fftlen4 = shr(fftlen,2); - fftlen8 = shr(fftlen,3); + fftlen2 = shr( fftlen, 1 ); + fftlen4 = shr( fftlen, 2 ); + fftlen8 = shr( fftlen, 3 ); /* Power Spectrum */ maxVal = 0; - move32(); - len = sub(stop, start); - FOR (i=0; i < len; i++) + move32(); + len = sub( stop, start ); + FOR( i = 0; i < len; i++ ) { - maxVal = L_max(maxVal, L_abs(powspec[i])); + maxVal = L_max( maxVal, L_abs( powspec[i] ) ); } - s1 = norm_l(maxVal); + s1 = norm_l( maxVal ); #ifdef BASOP_NOGLOB - nf = L_shr_r_sat(1099511680l/*1e-3f Q40*/,add(sub(powspec_exp,s1),9)); + nf = L_shr_r_sat( 1099511680l /*1e-3f Q40*/, add( sub( powspec_exp, s1 ), 9 ) ); #else - nf = L_shr_r(1099511680l/*1e-3f Q40*/,add(sub(powspec_exp,s1),9)); + nf = L_shr_r( 1099511680l /*1e-3f Q40*/, add( sub( powspec_exp, s1 ), 9 ) ); #endif ptr = fftBuffer; - pti = fftBuffer+1; + pti = fftBuffer + 1; - FOR (i=0; i < start; i++) + FOR( i = 0; i < start; i++ ) { *ptr = nf; move32(); - *pti = L_deposit_l(0); + *pti = L_deposit_l( 0 ); ptr += 2; pti += 2; } - FOR ( ; i < stop; i++ ) + FOR( ; i < stop; i++ ) { - *ptr = L_max( nf, L_shl(powspec[i-start], s1) ); + *ptr = L_max( nf, L_shl( powspec[i - start], s1 ) ); move32(); - *pti = L_deposit_l(0); + *pti = L_deposit_l( 0 ); ptr += 2; pti += 2; } - FOR ( ; i < fftlen2; i++ ) + FOR( ; i < fftlen2; i++ ) { *ptr = nf; move32(); - *pti = L_deposit_l(0); + *pti = L_deposit_l( 0 ); ptr += 2; pti += 2; } @@ -2817,56 +2794,56 @@ void lpc_from_spectrum ( /* Pre-emphasis */ - BASOP_getTables(&table, NULL, &step, fftlen4); - tmp = round_fx(L_shr(L_add(0x40000000, L_mult0(preemph_fac, preemph_fac)),1)); - preemph_fac2 = shr(preemph_fac,1); + BASOP_getTables( &table, NULL, &step, fftlen4 ); + tmp = round_fx( L_shr( L_add( 0x40000000, L_mult0( preemph_fac, preemph_fac ) ), 1 ) ); + preemph_fac2 = shr( preemph_fac, 1 ); ptr = fftBuffer; *ptr = Mpy_32_16_1( *ptr, sub( tmp, preemph_fac2 ) ); move32(); ptr += 2; - FOR ( i = 1; i < fftlen8; i++ ) + FOR( i = 1; i < fftlen8; i++ ) { move32(); - *ptr = Mpy_32_16_1( *ptr, sub( tmp, mult_r(preemph_fac2,add(shr(table[i-1].v.re,1),shr(table[i].v.re,1)) ) ) ); + *ptr = Mpy_32_16_1( *ptr, sub( tmp, mult_r( preemph_fac2, add( shr( table[i - 1].v.re, 1 ), shr( table[i].v.re, 1 ) ) ) ) ); ptr += 2; } move32(); - *ptr = Mpy_32_16_1( *ptr, sub( tmp, mult_r(preemph_fac2,add(shr(table[fftlen8-1].v.re,1),shr(table[fftlen8-1].v.im,1)) ) ) ); + *ptr = Mpy_32_16_1( *ptr, sub( tmp, mult_r( preemph_fac2, add( shr( table[fftlen8 - 1].v.re, 1 ), shr( table[fftlen8 - 1].v.im, 1 ) ) ) ) ); ptr += 2; - FOR ( i = 1; i < fftlen8; i++ ) + FOR( i = 1; i < fftlen8; i++ ) { move32(); - *ptr = Mpy_32_16_1( *ptr, sub( tmp, mult_r(preemph_fac2,add(shr(table[fftlen8-i-1].v.im,1),shr(table[fftlen8-i].v.im,1)) ) ) ); + *ptr = Mpy_32_16_1( *ptr, sub( tmp, mult_r( preemph_fac2, add( shr( table[fftlen8 - i - 1].v.im, 1 ), shr( table[fftlen8 - i].v.im, 1 ) ) ) ) ); ptr += 2; } move32(); *ptr = Mpy_32_16_1( *ptr, tmp ); ptr += 2; - FOR ( i = 1; i < fftlen8; i++ ) + FOR( i = 1; i < fftlen8; i++ ) { move32(); - *ptr = Mpy_32_16_1( *ptr, add( tmp, mult_r(preemph_fac2,add(shr(table[i-1].v.im,1),shr(table[i].v.im,1)) ) ) ); + *ptr = Mpy_32_16_1( *ptr, add( tmp, mult_r( preemph_fac2, add( shr( table[i - 1].v.im, 1 ), shr( table[i].v.im, 1 ) ) ) ) ); ptr += 2; } move32(); - *ptr = Mpy_32_16_1( *ptr, add( tmp, mult_r(preemph_fac2,add(shr(table[fftlen8-1].v.re,1),shr(table[fftlen8-1].v.im,1)) ) ) ); + *ptr = Mpy_32_16_1( *ptr, add( tmp, mult_r( preemph_fac2, add( shr( table[fftlen8 - 1].v.re, 1 ), shr( table[fftlen8 - 1].v.im, 1 ) ) ) ) ); ptr += 2; - FOR ( i = 1; i < fftlen8; i++ ) + FOR( i = 1; i < fftlen8; i++ ) { move32(); - *ptr = Mpy_32_16_1( *ptr, add( tmp, mult_r(preemph_fac2,add(shr(table[fftlen8-i-1].v.re,1),shr(table[fftlen8-i].v.re,1)) ) ) ); + *ptr = Mpy_32_16_1( *ptr, add( tmp, mult_r( preemph_fac2, add( shr( table[fftlen8 - i - 1].v.re, 1 ), shr( table[fftlen8 - i].v.re, 1 ) ) ) ) ); ptr += 2; } move32(); fftBuffer[1] = Mpy_32_16_1( fftBuffer[1], add( tmp, preemph_fac2 ) ); maxVal = 0; - move32(); - FOR (i=0; i < fftlen; i++) + move32(); + FOR( i = 0; i < fftlen; i++ ) { - maxVal = L_max(maxVal, L_abs(fftBuffer[i])); + maxVal = L_max( maxVal, L_abs( fftBuffer[i] ) ); } - s2 = norm_l(maxVal); - FOR (i=0; i < fftlen; i++) + s2 = norm_l( maxVal ); + FOR( i = 0; i < fftlen; i++ ) { fftBuffer[i] = L_shl( fftBuffer[i], s2 ); move32(); @@ -2874,40 +2851,39 @@ void lpc_from_spectrum ( /* Autocorrelation */ - BASOP_rfft(fftBuffer, fftlen, &scale, 1); + BASOP_rfft( fftBuffer, fftlen, &scale, 1 ); - s3 = getScaleFactor32(fftBuffer, add(lpcorder,1)); + s3 = getScaleFactor32( fftBuffer, add( lpcorder, 1 ) ); - FOR (i=0; i <= lpcorder; i++ ) + FOR( i = 0; i <= lpcorder; i++ ) { - r[i] = L_shl(fftBuffer[i], s3); + r[i] = L_shl( fftBuffer[i], s3 ); move32(); } - r[0] = Mpy_32_32( r[0], 1074278656l/*1.0005f Q30*/ ); + r[0] = Mpy_32_32( r[0], 1074278656l /*1.0005f Q30*/ ); move32(); - FOR (i=1; i <= lpcorder; i++ ) + FOR( i = 1; i <= lpcorder; i++ ) { - r[i] = Mpy_32_32( r[i], 1073741824l/*1.f Q30*/ ); + r[i] = Mpy_32_32( r[i], 1073741824l /*1.f Q30*/ ); move32(); } - s3 = getScaleFactor32(r, add(lpcorder,1)); + s3 = getScaleFactor32( r, add( lpcorder, 1 ) ); - FOR (i=0; i <= lpcorder; i++ ) + FOR( i = 0; i <= lpcorder; i++ ) { - r[i] = L_shl(r[i], s3); + r[i] = L_shl( r[i], s3 ); move32(); } - FOR (i=0; i <= lpcorder; i++ ) + FOR( i = 0; i <= lpcorder; i++ ) { - L_Extract(r[i], &r_h[i], &r_l[i]); + L_Extract( r[i], &r_h[i], &r_l[i] ); } /* LPC */ - E_LPC_lev_dur(r_h, r_l, A, NULL, lpcorder, NULL); - + E_LPC_lev_dur( r_h, r_l, A, NULL, lpcorder, NULL ); } /* @@ -2929,43 +2905,42 @@ void lpc_from_spectrum ( Returns: void */ -void msvq_decoder ( - const Word16 *const cb[], /* i : Codebook (indexed cb[*stages][levels][p]) */ - const Word16 stages, /* i : Number of stages */ - const Word16 N, /* i : Vector dimension */ - const Word16 maxN, /* i : Codebook vector dimension */ - const Word16 Idx[], /* i : Indices */ - Word16 *uq /* o : quantized vector */ +void msvq_decoder( + const Word16 *const cb[], /* i : Codebook (indexed cb[*stages][levels][p]) */ + const Word16 stages, /* i : Number of stages */ + const Word16 N, /* i : Vector dimension */ + const Word16 maxN, /* i : Codebook vector dimension */ + const Word16 Idx[], /* i : Indices */ + Word16 *uq /* o : quantized vector */ ) { Word16 s, i, offset; -//PMT("msvq_decoder Not verified") + // PMT("msvq_decoder Not verified") - offset = i_mult(Idx[0], maxN); - FOR (i=0; iA_cng, Aq+i*(M+1), M+1 ); + Copy( hFdCngCom->A_cng, Aq + i * ( M + 1 ), M + 1 ); } E_LPC_a_lsp_conversion( Aq, lsp_new, lsp_old, M ); @@ -2997,14 +2972,14 @@ void FdCng_exc( { Copy( lsp_old, lspCNG, M ); } - FOR( i=0; iexc_cng, exc, L_frame ); Copy( hFdCngCom->exc_cng, exc2, L_frame ); - IF (bwe_exc != NULL) + IF( bwe_exc != NULL ) { - IF(EQ_16(L_frame, L_FRAME)) + IF( EQ_16( L_frame, L_FRAME ) ) { - interp_code_5over2_fx(exc2, bwe_exc, L_frame); + interp_code_5over2_fx( exc2, bwe_exc, L_frame ); } ELSE { - interp_code_4over2_fx(exc2, bwe_exc, L_frame); + interp_code_4over2_fx( exc2, bwe_exc, L_frame ); } } } - diff --git a/lib_com/fft.c b/lib_com/fft.c index 0f1b6dd0a..75f54e2c3 100644 --- a/lib_com/fft.c +++ b/lib_com/fft.c @@ -6399,7 +6399,7 @@ void rfft( #define C81_FX ( FFTC( 0x5a82799a ) ) /* FL2WORD32( 7.071067811865475e-1) */ #define C82_FX ( FFTC( 0xa57d8666 ) ) /* FL2WORD32(-7.071067811865475e-1) */ -#define cplxMpy4_8_0( re, im, a, b, c, d ) \ +#define cplxMpy4_8_0( re, im, a, b, c, d ) \ re = L_shr( L_sub( Mpy_32_16_1( a, c ), Mpy_32_16_1( b, d ) ), 1 ); \ im = L_shr( L_add( Mpy_32_16_1( a, d ), Mpy_32_16_1( b, c ) ), 1 ); diff --git a/lib_com/fft_cldfb_fx.c b/lib_com/fft_cldfb_fx.c index 4e8dd94ab..6271eea26 100644 --- a/lib_com/fft_cldfb_fx.c +++ b/lib_com/fft_cldfb_fx.c @@ -43,49 +43,51 @@ #include "basop_util.h" #include "complex_basop.h" -#define Mpy_32_xx Mpy_32_16_1 +#define Mpy_32_xx Mpy_32_16_1 -#define FFTC(x) WORD322WORD16((Word32)x) +#define FFTC( x ) WORD322WORD16( (Word32) x ) -#define C31 (FFTC(0x91261468)) /* FL2WORD32( -0.86602540) -sqrt(3)/2 */ +#define C31 ( FFTC( 0x91261468 ) ) /* FL2WORD32( -0.86602540) -sqrt(3)/2 */ -#define C51 (FFTC(0x79bc3854)) /* FL2WORD32( 0.95105652) */ -#define C52 (FFTC(0x9d839db0)) /* FL2WORD32(-1.53884180/2) */ -#define C53 (FFTC(0xd18053ce)) /* FL2WORD32(-0.36327126) */ -#define C54 (FFTC(0x478dde64)) /* FL2WORD32( 0.55901699) */ -#define C55 (FFTC(0xb0000001)) /* FL2WORD32(-1.25/2) */ +#define C51 ( FFTC( 0x79bc3854 ) ) /* FL2WORD32( 0.95105652) */ +#define C52 ( FFTC( 0x9d839db0 ) ) /* FL2WORD32(-1.53884180/2) */ +#define C53 ( FFTC( 0xd18053ce ) ) /* FL2WORD32(-0.36327126) */ +#define C54 ( FFTC( 0x478dde64 ) ) /* FL2WORD32( 0.55901699) */ +#define C55 ( FFTC( 0xb0000001 ) ) /* FL2WORD32(-1.25/2) */ -#define C81 (FFTC(0x5a82799a)) /* FL2WORD32( 7.071067811865475e-1) */ -#define C82 (FFTC(0xa57d8666)) /* FL2WORD32(-7.071067811865475e-1) */ +#define C81 ( FFTC( 0x5a82799a ) ) /* FL2WORD32( 7.071067811865475e-1) */ +#define C82 ( FFTC( 0xa57d8666 ) ) /* FL2WORD32(-7.071067811865475e-1) */ -#define C161 (FFTC(0x5a82799a)) /* FL2WORD32( 7.071067811865475e-1) INV_SQRT2 */ -#define C162 (FFTC(0xa57d8666)) /* FL2WORD32(-7.071067811865475e-1) -INV_SQRT2 */ +#define C161 ( FFTC( 0x5a82799a ) ) /* FL2WORD32( 7.071067811865475e-1) INV_SQRT2 */ +#define C162 ( FFTC( 0xa57d8666 ) ) /* FL2WORD32(-7.071067811865475e-1) -INV_SQRT2 */ -#define C163 (FFTC(0x7641af3d)) /* FL2WORD32( 9.238795325112867e-1) COS_PI_DIV8 */ -#define C164 (FFTC(0x89be50c3)) /* FL2WORD32(-9.238795325112867e-1) -COS_PI_DIV8 */ +#define C163 ( FFTC( 0x7641af3d ) ) /* FL2WORD32( 9.238795325112867e-1) COS_PI_DIV8 */ +#define C164 ( FFTC( 0x89be50c3 ) ) /* FL2WORD32(-9.238795325112867e-1) -COS_PI_DIV8 */ -#define C165 (FFTC(0x30fbc54d)) /* FL2WORD32( 3.826834323650898e-1) COS_3PI_DIV8 */ -#define C166 (FFTC(0xcf043ab3)) /* FL2WORD32(-3.826834323650898e-1) -COS_3PI_DIV8 */ +#define C165 ( FFTC( 0x30fbc54d ) ) /* FL2WORD32( 3.826834323650898e-1) COS_3PI_DIV8 */ +#define C166 ( FFTC( 0xcf043ab3 ) ) /* FL2WORD32(-3.826834323650898e-1) -COS_3PI_DIV8 */ -#define cplxMpy4_8_0(re,im,a,b,c,d) re = L_shr(L_sub(Mpy_32_xx(a,c),Mpy_32_xx(b,d)),1); \ - im = L_shr(L_add(Mpy_32_xx(a,d),Mpy_32_xx(b,c)),1); +#define cplxMpy4_8_0( re, im, a, b, c, d ) \ + re = L_shr( L_sub( Mpy_32_xx( a, c ), Mpy_32_xx( b, d ) ), 1 ); \ + im = L_shr( L_add( Mpy_32_xx( a, d ), Mpy_32_xx( b, c ) ), 1 ); -#define cplxMpy4_8_1(re,im,a,b) re = L_shr(a,1); \ - im = L_shr(b,1); +#define cplxMpy4_8_1( re, im, a, b ) \ + re = L_shr( a, 1 ); \ + im = L_shr( b, 1 ); -void fft16_with_cmplx_data(cmplx *pInp, Word16 bsacle); +void fft16_with_cmplx_data( cmplx *pInp, Word16 bsacle ); #if 0 -#define SCALEFACTOR5 ( 4) -#define SCALEFACTOR8 ( 4) -#define SCALEFACTOR10 ( 5) -#define SCALEFACTOR16 ( 5) -#define SCALEFACTOR20 ( 5) -#define SCALEFACTOR30 ( 6) -#define SCALEFACTOR30_1 ( 5) -#define SCALEFACTOR30_2 ( 1) +#define SCALEFACTOR5 ( 4 ) +#define SCALEFACTOR8 ( 4 ) +#define SCALEFACTOR10 ( 5 ) +#define SCALEFACTOR16 ( 5 ) +#define SCALEFACTOR20 ( 5 ) +#define SCALEFACTOR30 ( 6 ) +#define SCALEFACTOR30_1 ( 5 ) +#define SCALEFACTOR30_2 ( 1 ) #else #undef SCALEFACTOR5 #undef SCALEFACTOR8 @@ -96,18 +98,18 @@ void fft16_with_cmplx_data(cmplx *pInp, Word16 bsacle); #undef SCALEFACTOR30_1 #undef SCALEFACTOR30_2 -#define SCALEFACTOR5 ( 0) -#define SCALEFACTOR8 ( 0) -#define SCALEFACTOR10 ( 0) -#define SCALEFACTOR16 ( 0) -#define SCALEFACTOR20 ( 0) -#define SCALEFACTOR30 ( 0) -#define SCALEFACTOR30_1 ( 0) -#define SCALEFACTOR30_2 ( 0) +#define SCALEFACTOR5 ( 0 ) +#define SCALEFACTOR8 ( 0 ) +#define SCALEFACTOR10 ( 0 ) +#define SCALEFACTOR16 ( 0 ) +#define SCALEFACTOR20 ( 0 ) +#define SCALEFACTOR30 ( 0 ) +#define SCALEFACTOR30_1 ( 0 ) +#define SCALEFACTOR30_2 ( 0 ) #endif -cmplx CL_scale_t(cmplx x, Word16 y); -cmplx CL_dscale_t(cmplx x, Word16 y1, Word16 y2); +cmplx CL_scale_t( cmplx x, Word16 y ); +cmplx CL_dscale_t( cmplx x, Word16 y1, Word16 y2 ); /** * \brief Function performs a complex 8-point FFT @@ -122,69 +124,69 @@ cmplx CL_dscale_t(cmplx x, Word16 y1, Word16 y2); * * \return void */ -static void fft8_with_cmplx_data(cmplx *inp) +static void fft8_with_cmplx_data( cmplx *inp ) { cmplx x0, x1, x2, x3, x4, x5, x6, x7; cmplx s0, s1, s2, s3, s4, s5, s6, s7; cmplx t0, t1, t2, t3, t4, t5, t6, t7; /* Pre-additions */ - x0 = CL_shr(inp[0], SCALEFACTOR8); - x1 = CL_shr(inp[1], SCALEFACTOR8); - x2 = CL_shr(inp[2], SCALEFACTOR8); - x3 = CL_shr(inp[3], SCALEFACTOR8); - x4 = CL_shr(inp[4], SCALEFACTOR8); - x5 = CL_shr(inp[5], SCALEFACTOR8); - x6 = CL_shr(inp[6], SCALEFACTOR8); - x7 = CL_shr(inp[7], SCALEFACTOR8); + x0 = CL_shr( inp[0], SCALEFACTOR8 ); + x1 = CL_shr( inp[1], SCALEFACTOR8 ); + x2 = CL_shr( inp[2], SCALEFACTOR8 ); + x3 = CL_shr( inp[3], SCALEFACTOR8 ); + x4 = CL_shr( inp[4], SCALEFACTOR8 ); + x5 = CL_shr( inp[5], SCALEFACTOR8 ); + x6 = CL_shr( inp[6], SCALEFACTOR8 ); + x7 = CL_shr( inp[7], SCALEFACTOR8 ); /* loops are unrolled */ { - t0 = CL_add(x0,x4); - t1 = CL_sub(x0,x4); + t0 = CL_add( x0, x4 ); + t1 = CL_sub( x0, x4 ); - t2 = CL_add(x1,x5); - t3 = CL_sub(x1,x5); + t2 = CL_add( x1, x5 ); + t3 = CL_sub( x1, x5 ); - t4 = CL_add(x2,x6); - t5 = CL_sub(x2,x6); + t4 = CL_add( x2, x6 ); + t5 = CL_sub( x2, x6 ); - t6 = CL_add(x3,x7); - t7 = CL_sub(x3,x7); + t6 = CL_add( x3, x7 ); + t7 = CL_sub( x3, x7 ); } /* Pre-additions and core multiplications */ - s0 = CL_add(t0, t4); - s2 = CL_sub(t0, t4); + s0 = CL_add( t0, t4 ); + s2 = CL_sub( t0, t4 ); - s4 = CL_mac_j(t1, t5); - s5 = CL_msu_j(t1, t5); + s4 = CL_mac_j( t1, t5 ); + s5 = CL_msu_j( t1, t5 ); - s1 = CL_add(t2, t6); - s3 = CL_sub(t2, t6); - s3 = CL_mul_j(s3); + s1 = CL_add( t2, t6 ); + s3 = CL_sub( t2, t6 ); + s3 = CL_mul_j( s3 ); - t0 = CL_add(t3, t7); - t1 = CL_sub(t3, t7); + t0 = CL_add( t3, t7 ); + t1 = CL_sub( t3, t7 ); - s6 = CL_scale_t(CL_msu_j(t1, t0), C81); - s7 = CL_dscale_t(CL_swap_real_imag(CL_msu_j(t0, t1)), C81, C82); + s6 = CL_scale_t( CL_msu_j( t1, t0 ), C81 ); + s7 = CL_dscale_t( CL_swap_real_imag( CL_msu_j( t0, t1 ) ), C81, C82 ); /* Post-additions */ - inp[0] = CL_add(s0, s1); - inp[4] = CL_sub(s0, s1); + inp[0] = CL_add( s0, s1 ); + inp[4] = CL_sub( s0, s1 ); - inp[2] = CL_sub(s2, s3); - inp[6] = CL_add(s2, s3); + inp[2] = CL_sub( s2, s3 ); + inp[6] = CL_add( s2, s3 ); - inp[3] = CL_add(s4, s7); - inp[7] = CL_sub(s4, s7); + inp[3] = CL_add( s4, s7 ); + inp[7] = CL_sub( s4, s7 ); - inp[1] = CL_add(s5, s6); - inp[5] = CL_sub(s5, s6); -#if (WMOPS) + inp[1] = CL_add( s5, s6 ); + inp[5] = CL_sub( s5, s6 ); +#if ( WMOPS ) multiCounter[currCounter].CL_move += 8; #endif } @@ -202,50 +204,49 @@ static void fft8_with_cmplx_data(cmplx *inp) * * \return void */ -static void fft5_with_cmplx_data(cmplx *inp) +static void fft5_with_cmplx_data( cmplx *inp ) { - cmplx x0,x1,x2,x3,x4; - cmplx y1,y2,y3,y4; + cmplx x0, x1, x2, x3, x4; + cmplx y1, y2, y3, y4; cmplx t; - x0 = CL_shr(inp[0],SCALEFACTOR5); - x1 = CL_shr(inp[1],SCALEFACTOR5); - x2 = CL_shr(inp[2],SCALEFACTOR5); - x3 = CL_shr(inp[3],SCALEFACTOR5); - x4 = CL_shr(inp[4],SCALEFACTOR5); + x0 = CL_shr( inp[0], SCALEFACTOR5 ); + x1 = CL_shr( inp[1], SCALEFACTOR5 ); + x2 = CL_shr( inp[2], SCALEFACTOR5 ); + x3 = CL_shr( inp[3], SCALEFACTOR5 ); + x4 = CL_shr( inp[4], SCALEFACTOR5 ); - y1 = CL_add(x1,x4); - y4 = CL_sub(x1,x4); - y3 = CL_add(x2,x3); - y2 = CL_sub(x2,x3); - t = CL_scale_t(CL_sub(y1,y3),C54); - y1 = CL_add(y1,y3); - inp[0] = CL_add(x0,y1); + y1 = CL_add( x1, x4 ); + y4 = CL_sub( x1, x4 ); + y3 = CL_add( x2, x3 ); + y2 = CL_sub( x2, x3 ); + t = CL_scale_t( CL_sub( y1, y3 ), C54 ); + y1 = CL_add( y1, y3 ); + inp[0] = CL_add( x0, y1 ); /* Bit shift left because of the constant C55 which was scaled with the factor 0.5 because of the representation of the values as fracts */ - y1 = CL_add(inp[0],(CL_shl(CL_scale_t(y1,C55),1))); - y3 = CL_sub(y1,t); - y1 = CL_add(y1,t); + y1 = CL_add( inp[0], ( CL_shl( CL_scale_t( y1, C55 ), 1 ) ) ); + y3 = CL_sub( y1, t ); + y1 = CL_add( y1, t ); - t = CL_scale_t(CL_add(y4,y2),C51); + t = CL_scale_t( CL_add( y4, y2 ), C51 ); /* Bit shift left because of the constant C55 which was scaled with the factor 0.5 because of the representation of the values as fracts */ - y4 = CL_add(t,CL_shl(CL_scale_t(y4, C52),1)); - y2 = CL_add(t,CL_scale_t(y2,C53)); + y4 = CL_add( t, CL_shl( CL_scale_t( y4, C52 ), 1 ) ); + y2 = CL_add( t, CL_scale_t( y2, C53 ) ); /* combination */ - inp[1] = CL_msu_j(y1,y2); - inp[4] = CL_mac_j(y1,y2); + inp[1] = CL_msu_j( y1, y2 ); + inp[4] = CL_mac_j( y1, y2 ); - inp[2] = CL_mac_j(y3,y4); - inp[3] = CL_msu_j(y3,y4); - -#if (WMOPS) - multiCounter[currCounter].CL_move += 5; -#endif + inp[2] = CL_mac_j( y3, y4 ); + inp[3] = CL_msu_j( y3, y4 ); +#if ( WMOPS ) + multiCounter[currCounter].CL_move += 5; +#endif } /** @@ -261,99 +262,98 @@ static void fft5_with_cmplx_data(cmplx *inp) * * \return void */ -static void fft10_with_cmplx_data(cmplx *inp_data) +static void fft10_with_cmplx_data( cmplx *inp_data ) { - cmplx r1,r2,r3,r4; - cmplx x0,x1,x2,x3,x4,t; + cmplx r1, r2, r3, r4; + cmplx x0, x1, x2, x3, x4, t; cmplx y[10]; /* FOR i=0 */ { - x0 = CL_shr(inp_data[0],SCALEFACTOR10); - x1 = CL_shr(inp_data[2],SCALEFACTOR10); - x2 = CL_shr(inp_data[4],SCALEFACTOR10); - x3 = CL_shr(inp_data[6],SCALEFACTOR10); - x4 = CL_shr(inp_data[8],SCALEFACTOR10); - - r1 = CL_add(x3,x2); - r4 = CL_sub(x3,x2); - r3 = CL_add(x1,x4); - r2 = CL_sub(x1,x4); - t = CL_scale_t(CL_sub(r1,r3),C54); - r1 = CL_add(r1,r3); - y[0] = CL_add(x0,r1); - r1 = CL_add(y[0],(CL_shl(CL_scale_t(r1,C55),1))); - r3 = CL_sub(r1,t); - r1 = CL_add(r1,t); - t = CL_scale_t((CL_add(r4,r2)),C51); - r4 = CL_add(t,CL_shl(CL_scale_t(r4, C52),1)); - r2 = CL_add(t,CL_scale_t(r2,C53)); - - - y[2] = CL_msu_j(r1,r2); - y[8] = CL_mac_j(r1,r2); - y[4] = CL_mac_j(r3,r4); - y[6] = CL_msu_j(r3,r4); + x0 = CL_shr( inp_data[0], SCALEFACTOR10 ); + x1 = CL_shr( inp_data[2], SCALEFACTOR10 ); + x2 = CL_shr( inp_data[4], SCALEFACTOR10 ); + x3 = CL_shr( inp_data[6], SCALEFACTOR10 ); + x4 = CL_shr( inp_data[8], SCALEFACTOR10 ); + + r1 = CL_add( x3, x2 ); + r4 = CL_sub( x3, x2 ); + r3 = CL_add( x1, x4 ); + r2 = CL_sub( x1, x4 ); + t = CL_scale_t( CL_sub( r1, r3 ), C54 ); + r1 = CL_add( r1, r3 ); + y[0] = CL_add( x0, r1 ); + r1 = CL_add( y[0], ( CL_shl( CL_scale_t( r1, C55 ), 1 ) ) ); + r3 = CL_sub( r1, t ); + r1 = CL_add( r1, t ); + t = CL_scale_t( ( CL_add( r4, r2 ) ), C51 ); + r4 = CL_add( t, CL_shl( CL_scale_t( r4, C52 ), 1 ) ); + r2 = CL_add( t, CL_scale_t( r2, C53 ) ); + + + y[2] = CL_msu_j( r1, r2 ); + y[8] = CL_mac_j( r1, r2 ); + y[4] = CL_mac_j( r3, r4 ); + y[6] = CL_msu_j( r3, r4 ); } /* FOR i=1 */ { - x0 = CL_shr(inp_data[5],SCALEFACTOR10); - x1 = CL_shr(inp_data[1],SCALEFACTOR10); - x2 = CL_shr(inp_data[3],SCALEFACTOR10); - x3 = CL_shr(inp_data[7],SCALEFACTOR10); - x4 = CL_shr(inp_data[9],SCALEFACTOR10); - - r1 = CL_add(x1,x4); - r4 = CL_sub(x1,x4); - r3 = CL_add(x3,x2); - r2 = CL_sub(x3,x2); - t = CL_scale_t(CL_sub(r1,r3),C54); - r1 = CL_add(r1,r3); - y[1] = CL_add(x0,r1); - r1 = CL_add(y[1],(CL_shl(CL_scale_t(r1,C55),1))); - r3 = CL_sub(r1,t); - r1 = CL_add(r1,t); - t = CL_scale_t((CL_add(r4,r2)),C51); - r4 = CL_add(t,CL_shl(CL_scale_t(r4, C52),1)); - r2 = CL_add(t,CL_scale_t(r2,C53)); - - - y[3] = CL_msu_j(r1,r2); - y[9] = CL_mac_j(r1,r2); - y[5] = CL_mac_j(r3,r4); - y[7] = CL_msu_j(r3,r4); + x0 = CL_shr( inp_data[5], SCALEFACTOR10 ); + x1 = CL_shr( inp_data[1], SCALEFACTOR10 ); + x2 = CL_shr( inp_data[3], SCALEFACTOR10 ); + x3 = CL_shr( inp_data[7], SCALEFACTOR10 ); + x4 = CL_shr( inp_data[9], SCALEFACTOR10 ); + + r1 = CL_add( x1, x4 ); + r4 = CL_sub( x1, x4 ); + r3 = CL_add( x3, x2 ); + r2 = CL_sub( x3, x2 ); + t = CL_scale_t( CL_sub( r1, r3 ), C54 ); + r1 = CL_add( r1, r3 ); + y[1] = CL_add( x0, r1 ); + r1 = CL_add( y[1], ( CL_shl( CL_scale_t( r1, C55 ), 1 ) ) ); + r3 = CL_sub( r1, t ); + r1 = CL_add( r1, t ); + t = CL_scale_t( ( CL_add( r4, r2 ) ), C51 ); + r4 = CL_add( t, CL_shl( CL_scale_t( r4, C52 ), 1 ) ); + r2 = CL_add( t, CL_scale_t( r2, C53 ) ); + + + y[3] = CL_msu_j( r1, r2 ); + y[9] = CL_mac_j( r1, r2 ); + y[5] = CL_mac_j( r3, r4 ); + y[7] = CL_msu_j( r3, r4 ); } /* FOR i=0 */ { - inp_data[0] = CL_add(y[0],y[1]); - inp_data[5] = CL_sub(y[0],y[1]); + inp_data[0] = CL_add( y[0], y[1] ); + inp_data[5] = CL_sub( y[0], y[1] ); } /* FOR i=2 */ { - inp_data[2] = CL_add(y[2],y[3]); - inp_data[7] = CL_sub(y[2],y[3]); + inp_data[2] = CL_add( y[2], y[3] ); + inp_data[7] = CL_sub( y[2], y[3] ); } /* FOR i=4 */ { - inp_data[4] = CL_add(y[4],y[5]); - inp_data[9] = CL_sub(y[4],y[5]); + inp_data[4] = CL_add( y[4], y[5] ); + inp_data[9] = CL_sub( y[4], y[5] ); } /* FOR i=6 */ { - inp_data[6] = CL_add(y[6],y[7]); - inp_data[1] = CL_sub(y[6],y[7]); + inp_data[6] = CL_add( y[6], y[7] ); + inp_data[1] = CL_sub( y[6], y[7] ); } /* FOR i=8 */ { - inp_data[8] = CL_add(y[8],y[9]); - inp_data[3] = CL_sub(y[8],y[9]); + inp_data[8] = CL_add( y[8], y[9] ); + inp_data[3] = CL_sub( y[8], y[9] ); } - -#if (WMOPS) - multiCounter[currCounter].CL_move += 10; -#endif +#if ( WMOPS ) + multiCounter[currCounter].CL_move += 10; +#endif } /** @@ -369,131 +369,131 @@ static void fft10_with_cmplx_data(cmplx *inp_data) * * \return void */ -static void fft20_with_cmplx_data(cmplx *inp_data) +static void fft20_with_cmplx_data( cmplx *inp_data ) { - cmplx r1,r2,r3,r4; - cmplx x0,x1,x2,x3,x4; - cmplx t,t0,t1,t2,t3; + cmplx r1, r2, r3, r4; + cmplx x0, x1, x2, x3, x4; + cmplx t, t0, t1, t2, t3; cmplx y[20]; - cmplx *y0, *y1,*y2,*y3,*y4; + cmplx *y0, *y1, *y2, *y3, *y4; - y0 = y; + y0 = y; y1 = &y[4]; y2 = &y[16]; y3 = &y[8]; y4 = &y[12]; { - x0 = CL_shr(inp_data[0],SCALEFACTOR20); - x1 = CL_shr(inp_data[16],SCALEFACTOR20); - x2 = CL_shr(inp_data[12],SCALEFACTOR20); - x3 = CL_shr(inp_data[8],SCALEFACTOR20); - x4 = CL_shr(inp_data[4],SCALEFACTOR20); - - r4 = CL_sub(x1,x4); - r2 = CL_sub(x2,x3); - r1 = CL_add(x1,x4); - r3 = CL_add(x2,x3); - t = CL_scale_t(CL_sub(r1,r3),C54); - r1 = CL_add(r1,r3); - y0[0] = CL_add(x0,r1); - r1 = CL_add(y0[0],(CL_shl(CL_scale_t(r1,C55),1))); - r3 = CL_sub(r1,t); - r1 = CL_add(r1,t); - t = CL_scale_t((CL_add(r4,r2)),C51); - r4 = CL_add(t,CL_shl(CL_scale_t(r4, C52),1)); - r2 = CL_add(t,CL_scale_t(r2,C53)); - - - y1[0] = CL_msu_j(r1,r2); - y2[0] = CL_mac_j(r1,r2); - y3[0] = CL_mac_j(r3,r4); - y4[0] = CL_msu_j(r3,r4); + x0 = CL_shr( inp_data[0], SCALEFACTOR20 ); + x1 = CL_shr( inp_data[16], SCALEFACTOR20 ); + x2 = CL_shr( inp_data[12], SCALEFACTOR20 ); + x3 = CL_shr( inp_data[8], SCALEFACTOR20 ); + x4 = CL_shr( inp_data[4], SCALEFACTOR20 ); + + r4 = CL_sub( x1, x4 ); + r2 = CL_sub( x2, x3 ); + r1 = CL_add( x1, x4 ); + r3 = CL_add( x2, x3 ); + t = CL_scale_t( CL_sub( r1, r3 ), C54 ); + r1 = CL_add( r1, r3 ); + y0[0] = CL_add( x0, r1 ); + r1 = CL_add( y0[0], ( CL_shl( CL_scale_t( r1, C55 ), 1 ) ) ); + r3 = CL_sub( r1, t ); + r1 = CL_add( r1, t ); + t = CL_scale_t( ( CL_add( r4, r2 ) ), C51 ); + r4 = CL_add( t, CL_shl( CL_scale_t( r4, C52 ), 1 ) ); + r2 = CL_add( t, CL_scale_t( r2, C53 ) ); + + + y1[0] = CL_msu_j( r1, r2 ); + y2[0] = CL_mac_j( r1, r2 ); + y3[0] = CL_mac_j( r3, r4 ); + y4[0] = CL_msu_j( r3, r4 ); } { - x0 = CL_shr(inp_data[5],SCALEFACTOR20); - x1 = CL_shr(inp_data[1],SCALEFACTOR20); - x2 = CL_shr(inp_data[17],SCALEFACTOR20); - x3 = CL_shr(inp_data[13],SCALEFACTOR20); - x4 = CL_shr(inp_data[9],SCALEFACTOR20); - - r4 = CL_sub(x1,x4); - r2 = CL_sub(x2,x3); - r1 = CL_add(x1,x4); - r3 = CL_add(x2,x3); - t = CL_scale_t(CL_sub(r1,r3),C54); - r1 = CL_add(r1,r3); - y0[1] = CL_add(x0,r1); - r1 = CL_add(y0[1],(CL_shl(CL_scale_t(r1,C55),1))); - r3 = CL_sub(r1,t); - r1 = CL_add(r1,t); - t = CL_scale_t((CL_add(r4,r2)),C51); - r4 = CL_add(t,CL_shl(CL_scale_t(r4, C52),1)); - r2 = CL_add(t,CL_scale_t(r2,C53)); - - - y1[1] = CL_msu_j(r1,r2); - y2[1] = CL_mac_j(r1,r2); - y3[1] = CL_mac_j(r3,r4); - y4[1] = CL_msu_j(r3,r4); + x0 = CL_shr( inp_data[5], SCALEFACTOR20 ); + x1 = CL_shr( inp_data[1], SCALEFACTOR20 ); + x2 = CL_shr( inp_data[17], SCALEFACTOR20 ); + x3 = CL_shr( inp_data[13], SCALEFACTOR20 ); + x4 = CL_shr( inp_data[9], SCALEFACTOR20 ); + + r4 = CL_sub( x1, x4 ); + r2 = CL_sub( x2, x3 ); + r1 = CL_add( x1, x4 ); + r3 = CL_add( x2, x3 ); + t = CL_scale_t( CL_sub( r1, r3 ), C54 ); + r1 = CL_add( r1, r3 ); + y0[1] = CL_add( x0, r1 ); + r1 = CL_add( y0[1], ( CL_shl( CL_scale_t( r1, C55 ), 1 ) ) ); + r3 = CL_sub( r1, t ); + r1 = CL_add( r1, t ); + t = CL_scale_t( ( CL_add( r4, r2 ) ), C51 ); + r4 = CL_add( t, CL_shl( CL_scale_t( r4, C52 ), 1 ) ); + r2 = CL_add( t, CL_scale_t( r2, C53 ) ); + + + y1[1] = CL_msu_j( r1, r2 ); + y2[1] = CL_mac_j( r1, r2 ); + y3[1] = CL_mac_j( r3, r4 ); + y4[1] = CL_msu_j( r3, r4 ); } { - x0 = CL_shr(inp_data[10],SCALEFACTOR20); - x1 = CL_shr(inp_data[6],SCALEFACTOR20); - x2 = CL_shr(inp_data[2],SCALEFACTOR20); - x3 = CL_shr(inp_data[18],SCALEFACTOR20); - x4 = CL_shr(inp_data[14],SCALEFACTOR20); - - r4 = CL_sub(x1,x4); - r2 = CL_sub(x2,x3); - r1 = CL_add(x1,x4); - r3 = CL_add(x2,x3); - t = CL_scale_t(CL_sub(r1,r3),C54); - r1 = CL_add(r1,r3); - y0[2] = CL_add(x0,r1); - r1 = CL_add(y0[2],(CL_shl(CL_scale_t(r1,C55),1))); - r3 = CL_sub(r1,t); - r1 = CL_add(r1,t); - t = CL_scale_t((CL_add(r4,r2)),C51); - r4 = CL_add(t,CL_shl(CL_scale_t(r4, C52),1)); - r2 = CL_add(t,CL_scale_t(r2,C53)); - - - y1[2] = CL_msu_j(r1,r2); - y2[2] = CL_mac_j(r1,r2); - y3[2] = CL_mac_j(r3,r4); - y4[2] = CL_msu_j(r3,r4); + x0 = CL_shr( inp_data[10], SCALEFACTOR20 ); + x1 = CL_shr( inp_data[6], SCALEFACTOR20 ); + x2 = CL_shr( inp_data[2], SCALEFACTOR20 ); + x3 = CL_shr( inp_data[18], SCALEFACTOR20 ); + x4 = CL_shr( inp_data[14], SCALEFACTOR20 ); + + r4 = CL_sub( x1, x4 ); + r2 = CL_sub( x2, x3 ); + r1 = CL_add( x1, x4 ); + r3 = CL_add( x2, x3 ); + t = CL_scale_t( CL_sub( r1, r3 ), C54 ); + r1 = CL_add( r1, r3 ); + y0[2] = CL_add( x0, r1 ); + r1 = CL_add( y0[2], ( CL_shl( CL_scale_t( r1, C55 ), 1 ) ) ); + r3 = CL_sub( r1, t ); + r1 = CL_add( r1, t ); + t = CL_scale_t( ( CL_add( r4, r2 ) ), C51 ); + r4 = CL_add( t, CL_shl( CL_scale_t( r4, C52 ), 1 ) ); + r2 = CL_add( t, CL_scale_t( r2, C53 ) ); + + + y1[2] = CL_msu_j( r1, r2 ); + y2[2] = CL_mac_j( r1, r2 ); + y3[2] = CL_mac_j( r3, r4 ); + y4[2] = CL_msu_j( r3, r4 ); } { - x0 = CL_shr(inp_data[15],SCALEFACTOR20); - x1 = CL_shr(inp_data[11],SCALEFACTOR20); - x2 = CL_shr(inp_data[7],SCALEFACTOR20); - x3 = CL_shr(inp_data[3],SCALEFACTOR20); - x4 = CL_shr(inp_data[19],SCALEFACTOR20); - - r4 = CL_sub(x1,x4); - r2 = CL_sub(x2,x3); - r1 = CL_add(x1,x4); - r3 = CL_add(x2,x3); - t = CL_scale_t(CL_sub(r1,r3),C54); - r1 = CL_add(r1,r3); - y0[3] = CL_add(x0,r1); - r1 = CL_add(y0[3],(CL_shl(CL_scale_t(r1,C55),1))); - r3 = CL_sub(r1,t); - r1 = CL_add(r1,t); - t = CL_scale_t((CL_add(r4,r2)),C51); - r4 = CL_add(t,CL_shl(CL_scale_t(r4, C52),1)); - r2 = CL_add(t,CL_scale_t(r2,C53)); - - - y1[3] = CL_msu_j(r1,r2); - y2[3] = CL_mac_j(r1,r2); - y3[3] = CL_mac_j(r3,r4); - y4[3] = CL_msu_j(r3,r4); + x0 = CL_shr( inp_data[15], SCALEFACTOR20 ); + x1 = CL_shr( inp_data[11], SCALEFACTOR20 ); + x2 = CL_shr( inp_data[7], SCALEFACTOR20 ); + x3 = CL_shr( inp_data[3], SCALEFACTOR20 ); + x4 = CL_shr( inp_data[19], SCALEFACTOR20 ); + + r4 = CL_sub( x1, x4 ); + r2 = CL_sub( x2, x3 ); + r1 = CL_add( x1, x4 ); + r3 = CL_add( x2, x3 ); + t = CL_scale_t( CL_sub( r1, r3 ), C54 ); + r1 = CL_add( r1, r3 ); + y0[3] = CL_add( x0, r1 ); + r1 = CL_add( y0[3], ( CL_shl( CL_scale_t( r1, C55 ), 1 ) ) ); + r3 = CL_sub( r1, t ); + r1 = CL_add( r1, t ); + t = CL_scale_t( ( CL_add( r4, r2 ) ), C51 ); + r4 = CL_add( t, CL_shl( CL_scale_t( r4, C52 ), 1 ) ); + r2 = CL_add( t, CL_scale_t( r2, C53 ) ); + + + y1[3] = CL_msu_j( r1, r2 ); + y2[3] = CL_mac_j( r1, r2 ); + y3[3] = CL_mac_j( r3, r4 ); + y4[3] = CL_msu_j( r3, r4 ); } { - cmplx * ptr_y = y; + cmplx *ptr_y = y; { cmplx Cy0, Cy1, Cy2, Cy3; @@ -503,16 +503,16 @@ static void fft20_with_cmplx_data(cmplx *inp_data) Cy3 = *ptr_y++; /* Pre-additions */ - t0 = CL_add(Cy0,Cy2); - t1 = CL_sub(Cy0,Cy2); - t2 = CL_add(Cy1,Cy3); - t3 = CL_sub(Cy1,Cy3); + t0 = CL_add( Cy0, Cy2 ); + t1 = CL_sub( Cy0, Cy2 ); + t2 = CL_add( Cy1, Cy3 ); + t3 = CL_sub( Cy1, Cy3 ); - inp_data[0] = CL_add(t0,t2); - inp_data[5] = CL_msu_j(t1,t3); - inp_data[10] = CL_sub(t0,t2); - inp_data[15] = CL_mac_j(t1,t3); + inp_data[0] = CL_add( t0, t2 ); + inp_data[5] = CL_msu_j( t1, t3 ); + inp_data[10] = CL_sub( t0, t2 ); + inp_data[15] = CL_mac_j( t1, t3 ); } { @@ -524,16 +524,16 @@ static void fft20_with_cmplx_data(cmplx *inp_data) Cy3 = *ptr_y++; /* Pre-additions */ - t0 = CL_add(Cy0,Cy2); - t1 = CL_sub(Cy0,Cy2); - t2 = CL_add(Cy1,Cy3); - t3 = CL_sub(Cy1,Cy3); + t0 = CL_add( Cy0, Cy2 ); + t1 = CL_sub( Cy0, Cy2 ); + t2 = CL_add( Cy1, Cy3 ); + t3 = CL_sub( Cy1, Cy3 ); - inp_data[4] = CL_add(t0,t2); - inp_data[9] = CL_msu_j(t1,t3); - inp_data[14] = CL_sub(t0,t2); - inp_data[19] = CL_mac_j(t1,t3); + inp_data[4] = CL_add( t0, t2 ); + inp_data[9] = CL_msu_j( t1, t3 ); + inp_data[14] = CL_sub( t0, t2 ); + inp_data[19] = CL_mac_j( t1, t3 ); } { @@ -545,16 +545,16 @@ static void fft20_with_cmplx_data(cmplx *inp_data) Cy3 = *ptr_y++; /* Pre-additions */ - t0 = CL_add(Cy0,Cy2); - t1 = CL_sub(Cy0,Cy2); - t2 = CL_add(Cy1,Cy3); - t3 = CL_sub(Cy1,Cy3); + t0 = CL_add( Cy0, Cy2 ); + t1 = CL_sub( Cy0, Cy2 ); + t2 = CL_add( Cy1, Cy3 ); + t3 = CL_sub( Cy1, Cy3 ); - inp_data[8] = CL_add(t0,t2); - inp_data[13] = CL_msu_j(t1,t3); - inp_data[18] = CL_sub(t0,t2); - inp_data[3] = CL_mac_j(t1,t3); + inp_data[8] = CL_add( t0, t2 ); + inp_data[13] = CL_msu_j( t1, t3 ); + inp_data[18] = CL_sub( t0, t2 ); + inp_data[3] = CL_mac_j( t1, t3 ); } { @@ -566,15 +566,15 @@ static void fft20_with_cmplx_data(cmplx *inp_data) Cy3 = *ptr_y++; /* Pre-additions */ - t0 = CL_add(Cy0,Cy2); - t1 = CL_sub(Cy0,Cy2); - t2 = CL_add(Cy1,Cy3); - t3 = CL_sub(Cy1,Cy3); - - inp_data[12] = CL_add(t0,t2); - inp_data[17] = CL_msu_j(t1,t3); - inp_data[2] = CL_sub(t0,t2); - inp_data[7] = CL_mac_j(t1,t3); + t0 = CL_add( Cy0, Cy2 ); + t1 = CL_sub( Cy0, Cy2 ); + t2 = CL_add( Cy1, Cy3 ); + t3 = CL_sub( Cy1, Cy3 ); + + inp_data[12] = CL_add( t0, t2 ); + inp_data[17] = CL_msu_j( t1, t3 ); + inp_data[2] = CL_sub( t0, t2 ); + inp_data[7] = CL_mac_j( t1, t3 ); } { @@ -586,22 +586,21 @@ static void fft20_with_cmplx_data(cmplx *inp_data) Cy3 = *ptr_y++; /* Pre-additions */ - t0 = CL_add(Cy0,Cy2); - t1 = CL_sub(Cy0,Cy2); - t2 = CL_add(Cy1,Cy3); - t3 = CL_sub(Cy1,Cy3); + t0 = CL_add( Cy0, Cy2 ); + t1 = CL_sub( Cy0, Cy2 ); + t2 = CL_add( Cy1, Cy3 ); + t3 = CL_sub( Cy1, Cy3 ); - inp_data[16] = CL_add(t0,t2); - inp_data[1] = CL_msu_j(t1,t3); - inp_data[6] = CL_sub(t0,t2); - inp_data[11] = CL_mac_j(t1,t3); + inp_data[16] = CL_add( t0, t2 ); + inp_data[1] = CL_msu_j( t1, t3 ); + inp_data[6] = CL_sub( t0, t2 ); + inp_data[11] = CL_mac_j( t1, t3 ); } } -#if (WMOPS) +#if ( WMOPS ) multiCounter[currCounter].CL_move += 20; -#endif - +#endif } @@ -618,98 +617,98 @@ static void fft20_with_cmplx_data(cmplx *inp_data) * * \return void */ -static void fft30_with_cmplx_data(cmplx * inp) +static void fft30_with_cmplx_data( cmplx *inp ) { - cmplx *l = &inp[0]; - cmplx *h = &inp[15]; + cmplx *l = &inp[0]; + cmplx *h = &inp[15]; cmplx z[30], y[15], x[15], rs1, rs2, rs3, rs4, t; /* 1. FFT15 stage */ - x[0] = CL_shr(inp[0],SCALEFACTOR30_1); - x[1] = CL_shr(inp[18],SCALEFACTOR30_1); - x[2] = CL_shr(inp[6],SCALEFACTOR30_1); - x[3] = CL_shr(inp[24],SCALEFACTOR30_1); - x[4] = CL_shr(inp[12],SCALEFACTOR30_1); + x[0] = CL_shr( inp[0], SCALEFACTOR30_1 ); + x[1] = CL_shr( inp[18], SCALEFACTOR30_1 ); + x[2] = CL_shr( inp[6], SCALEFACTOR30_1 ); + x[3] = CL_shr( inp[24], SCALEFACTOR30_1 ); + x[4] = CL_shr( inp[12], SCALEFACTOR30_1 ); - x[5] = CL_shr(inp[20],SCALEFACTOR30_1); - x[6] = CL_shr(inp[8],SCALEFACTOR30_1); - x[7] = CL_shr(inp[26],SCALEFACTOR30_1); - x[8] = CL_shr(inp[14],SCALEFACTOR30_1); - x[9] = CL_shr(inp[2],SCALEFACTOR30_1); + x[5] = CL_shr( inp[20], SCALEFACTOR30_1 ); + x[6] = CL_shr( inp[8], SCALEFACTOR30_1 ); + x[7] = CL_shr( inp[26], SCALEFACTOR30_1 ); + x[8] = CL_shr( inp[14], SCALEFACTOR30_1 ); + x[9] = CL_shr( inp[2], SCALEFACTOR30_1 ); - x[10] = CL_shr(inp[10],SCALEFACTOR30_1); - x[11] = CL_shr(inp[28],SCALEFACTOR30_1); - x[12] = CL_shr(inp[16],SCALEFACTOR30_1); - x[13] = CL_shr(inp[4],SCALEFACTOR30_1); - x[14] = CL_shr(inp[22],SCALEFACTOR30_1); + x[10] = CL_shr( inp[10], SCALEFACTOR30_1 ); + x[11] = CL_shr( inp[28], SCALEFACTOR30_1 ); + x[12] = CL_shr( inp[16], SCALEFACTOR30_1 ); + x[13] = CL_shr( inp[4], SCALEFACTOR30_1 ); + x[14] = CL_shr( inp[22], SCALEFACTOR30_1 ); /* 1. FFT5 stage */ - rs1 = CL_add(x[1],x[4]); - rs4 = CL_sub(x[1],x[4]); - rs3 = CL_add(x[2],x[3]); - rs2 = CL_sub(x[2],x[3]); - t = CL_scale_t(CL_sub(rs1,rs3),C54); - rs1 = CL_add(rs1,rs3); - y[0] = CL_add(x[0],rs1); - rs1 = CL_add(y[0],(CL_shl(CL_scale_t(rs1,C55),1))); - rs3 = CL_sub(rs1,t); - rs1 = CL_add(rs1,t); - t = CL_scale_t(CL_add(rs4,rs2),C51); - rs4 = CL_add(t,CL_shl(CL_scale_t(rs4, C52),1)); - rs2 = CL_add(t,CL_scale_t(rs2,C53)); + rs1 = CL_add( x[1], x[4] ); + rs4 = CL_sub( x[1], x[4] ); + rs3 = CL_add( x[2], x[3] ); + rs2 = CL_sub( x[2], x[3] ); + t = CL_scale_t( CL_sub( rs1, rs3 ), C54 ); + rs1 = CL_add( rs1, rs3 ); + y[0] = CL_add( x[0], rs1 ); + rs1 = CL_add( y[0], ( CL_shl( CL_scale_t( rs1, C55 ), 1 ) ) ); + rs3 = CL_sub( rs1, t ); + rs1 = CL_add( rs1, t ); + t = CL_scale_t( CL_add( rs4, rs2 ), C51 ); + rs4 = CL_add( t, CL_shl( CL_scale_t( rs4, C52 ), 1 ) ); + rs2 = CL_add( t, CL_scale_t( rs2, C53 ) ); /* combination */ - y[1] = CL_msu_j(rs1,rs2); - y[4] = CL_mac_j(rs1,rs2); - y[2] = CL_mac_j(rs3,rs4); - y[3] = CL_msu_j(rs3,rs4); + y[1] = CL_msu_j( rs1, rs2 ); + y[4] = CL_mac_j( rs1, rs2 ); + y[2] = CL_mac_j( rs3, rs4 ); + y[3] = CL_msu_j( rs3, rs4 ); /* 2. FFT5 stage */ - rs1 = CL_add(x[6],x[9]); - rs4 = CL_sub(x[6],x[9]); - rs3 = CL_add(x[7],x[8]); - rs2 = CL_sub(x[7],x[8]); - t = CL_scale_t(CL_sub(rs1,rs3),C54); - rs1 = CL_add(rs1,rs3); - y[5] = CL_add(x[5],rs1); - rs1 = CL_add(y[5],(CL_shl(CL_scale_t(rs1,C55),1))); - rs3 = CL_sub(rs1,t); - rs1 = CL_add(rs1,t); - t = CL_scale_t(CL_add(rs4,rs2),C51); - rs4 = CL_add(t,CL_shl(CL_scale_t(rs4, C52),1)); - rs2 = CL_add(t,CL_scale_t(rs2,C53)); + rs1 = CL_add( x[6], x[9] ); + rs4 = CL_sub( x[6], x[9] ); + rs3 = CL_add( x[7], x[8] ); + rs2 = CL_sub( x[7], x[8] ); + t = CL_scale_t( CL_sub( rs1, rs3 ), C54 ); + rs1 = CL_add( rs1, rs3 ); + y[5] = CL_add( x[5], rs1 ); + rs1 = CL_add( y[5], ( CL_shl( CL_scale_t( rs1, C55 ), 1 ) ) ); + rs3 = CL_sub( rs1, t ); + rs1 = CL_add( rs1, t ); + t = CL_scale_t( CL_add( rs4, rs2 ), C51 ); + rs4 = CL_add( t, CL_shl( CL_scale_t( rs4, C52 ), 1 ) ); + rs2 = CL_add( t, CL_scale_t( rs2, C53 ) ); /* combination */ - y[6] = CL_msu_j(rs1,rs2); - y[9] = CL_mac_j(rs1,rs2); - y[7] = CL_mac_j(rs3,rs4); - y[8] = CL_msu_j(rs3,rs4); + y[6] = CL_msu_j( rs1, rs2 ); + y[9] = CL_mac_j( rs1, rs2 ); + y[7] = CL_mac_j( rs3, rs4 ); + y[8] = CL_msu_j( rs3, rs4 ); /* 3. FFT5 stage */ - rs1 = CL_add(x[11],x[14]); - rs4 = CL_sub(x[11],x[14]); - rs3 = CL_add(x[12],x[13]); - rs2 = CL_sub(x[12],x[13]); - t = CL_scale_t(CL_sub(rs1,rs3),C54); - rs1 = CL_add(rs1,rs3); - y[10] = CL_add(x[10],rs1); - rs1 = CL_add(y[10],(CL_shl(CL_scale_t(rs1,C55),1))); - rs3 = CL_sub(rs1,t); - rs1 = CL_add(rs1,t); - t = CL_scale_t(CL_add(rs4,rs2),C51); - rs4 = CL_add(t,CL_shl(CL_scale_t(rs4, C52),1)); - rs2 = CL_add(t,CL_scale_t(rs2,C53)); + rs1 = CL_add( x[11], x[14] ); + rs4 = CL_sub( x[11], x[14] ); + rs3 = CL_add( x[12], x[13] ); + rs2 = CL_sub( x[12], x[13] ); + t = CL_scale_t( CL_sub( rs1, rs3 ), C54 ); + rs1 = CL_add( rs1, rs3 ); + y[10] = CL_add( x[10], rs1 ); + rs1 = CL_add( y[10], ( CL_shl( CL_scale_t( rs1, C55 ), 1 ) ) ); + rs3 = CL_sub( rs1, t ); + rs1 = CL_add( rs1, t ); + t = CL_scale_t( CL_add( rs4, rs2 ), C51 ); + rs4 = CL_add( t, CL_shl( CL_scale_t( rs4, C52 ), 1 ) ); + rs2 = CL_add( t, CL_scale_t( rs2, C53 ) ); /* combination */ - y[11] = CL_msu_j(rs1,rs2); - y[14] = CL_mac_j(rs1,rs2); - y[12] = CL_mac_j(rs3,rs4); - y[13] = CL_msu_j(rs3,rs4); + y[11] = CL_msu_j( rs1, rs2 ); + y[14] = CL_mac_j( rs1, rs2 ); + y[12] = CL_mac_j( rs3, rs4 ); + y[13] = CL_msu_j( rs3, rs4 ); /*for (i=10; i<15; i++) { printf("%d,\t %d,\t",y[i].re, y[i].im); @@ -719,52 +718,52 @@ static void fft30_with_cmplx_data(cmplx * inp) /* 1. FFT3 stage */ /* real part */ - rs1 = CL_add(y[5],y[10]); - rs2 = CL_scale_t(CL_sub(y[5],y[10]),C31); - z[0] = CL_add(y[0],rs1); - rs1 = CL_sub(y[0],CL_shr(rs1,1)); + rs1 = CL_add( y[5], y[10] ); + rs2 = CL_scale_t( CL_sub( y[5], y[10] ), C31 ); + z[0] = CL_add( y[0], rs1 ); + rs1 = CL_sub( y[0], CL_shr( rs1, 1 ) ); - z[10] = CL_mac_j(rs1,rs2); - z[5] = CL_msu_j(rs1,rs2); + z[10] = CL_mac_j( rs1, rs2 ); + z[5] = CL_msu_j( rs1, rs2 ); /* 2. FFT3 stage */ - rs1 = CL_add(y[6],y[11]); - rs2 = CL_scale_t(CL_sub(y[6],y[11]),C31); - z[6] = CL_add(y[1],rs1); - rs1 = CL_sub(y[1],CL_shr(rs1,1)); + rs1 = CL_add( y[6], y[11] ); + rs2 = CL_scale_t( CL_sub( y[6], y[11] ), C31 ); + z[6] = CL_add( y[1], rs1 ); + rs1 = CL_sub( y[1], CL_shr( rs1, 1 ) ); - z[1] = CL_mac_j(rs1,rs2); - z[11] = CL_msu_j(rs1,rs2); + z[1] = CL_mac_j( rs1, rs2 ); + z[11] = CL_msu_j( rs1, rs2 ); /* 3. FFT3 stage */ - rs1 = CL_add(y[7],y[12]); - rs2 = CL_scale_t(CL_sub(y[7],y[12]),C31); - z[12] = CL_add(y[2],rs1); - rs1 = CL_sub(y[2],CL_shr(rs1,1)); + rs1 = CL_add( y[7], y[12] ); + rs2 = CL_scale_t( CL_sub( y[7], y[12] ), C31 ); + z[12] = CL_add( y[2], rs1 ); + rs1 = CL_sub( y[2], CL_shr( rs1, 1 ) ); - z[7] = CL_mac_j(rs1,rs2); - z[2] = CL_msu_j(rs1,rs2); + z[7] = CL_mac_j( rs1, rs2 ); + z[2] = CL_msu_j( rs1, rs2 ); /* 4. FFT3 stage */ - rs1 = CL_add(y[8],y[13]); - rs2 = CL_scale_t(CL_sub(y[8],y[13]),C31); - z[3] = CL_add(y[3],rs1); - rs1 = CL_sub(y[3],CL_shr(rs1,1)); + rs1 = CL_add( y[8], y[13] ); + rs2 = CL_scale_t( CL_sub( y[8], y[13] ), C31 ); + z[3] = CL_add( y[3], rs1 ); + rs1 = CL_sub( y[3], CL_shr( rs1, 1 ) ); - z[13] = CL_mac_j(rs1,rs2); - z[8] = CL_msu_j(rs1,rs2); + z[13] = CL_mac_j( rs1, rs2 ); + z[8] = CL_msu_j( rs1, rs2 ); /* 5. FFT3 stage */ - rs1 = CL_add(y[9],y[14]); - rs2 = CL_scale_t(CL_sub(y[9],y[14]),C31); - z[9] = CL_add(y[4],rs1); - rs1 = CL_sub(y[4],CL_shr(rs1,1)); + rs1 = CL_add( y[9], y[14] ); + rs2 = CL_scale_t( CL_sub( y[9], y[14] ), C31 ); + z[9] = CL_add( y[4], rs1 ); + rs1 = CL_sub( y[4], CL_shr( rs1, 1 ) ); - z[4] = CL_mac_j(rs1,rs2); - z[14] = CL_msu_j(rs1,rs2); + z[4] = CL_mac_j( rs1, rs2 ); + z[14] = CL_msu_j( rs1, rs2 ); /*for (i=0; i<15; i++) printf("%d,\t %d,\t",z[i].re, z[i].im); @@ -773,88 +772,88 @@ static void fft30_with_cmplx_data(cmplx * inp) /* 2. FFT15 stage */ - x[0] = CL_shr(inp[15],SCALEFACTOR30_1); - x[1] = CL_shr(inp[3],SCALEFACTOR30_1); - x[2] = CL_shr(inp[21],SCALEFACTOR30_1); - x[3] = CL_shr(inp[9],SCALEFACTOR30_1); - x[4] = CL_shr(inp[27],SCALEFACTOR30_1); + x[0] = CL_shr( inp[15], SCALEFACTOR30_1 ); + x[1] = CL_shr( inp[3], SCALEFACTOR30_1 ); + x[2] = CL_shr( inp[21], SCALEFACTOR30_1 ); + x[3] = CL_shr( inp[9], SCALEFACTOR30_1 ); + x[4] = CL_shr( inp[27], SCALEFACTOR30_1 ); - x[5] = CL_shr(inp[5],SCALEFACTOR30_1); - x[6] = CL_shr(inp[23],SCALEFACTOR30_1); - x[7] = CL_shr(inp[11],SCALEFACTOR30_1); - x[8] = CL_shr(inp[29],SCALEFACTOR30_1); - x[9] = CL_shr(inp[17],SCALEFACTOR30_1); + x[5] = CL_shr( inp[5], SCALEFACTOR30_1 ); + x[6] = CL_shr( inp[23], SCALEFACTOR30_1 ); + x[7] = CL_shr( inp[11], SCALEFACTOR30_1 ); + x[8] = CL_shr( inp[29], SCALEFACTOR30_1 ); + x[9] = CL_shr( inp[17], SCALEFACTOR30_1 ); - x[10] = CL_shr(inp[25],SCALEFACTOR30_1); - x[11] = CL_shr(inp[13],SCALEFACTOR30_1); - x[12] = CL_shr(inp[1],SCALEFACTOR30_1); - x[13] = CL_shr(inp[19],SCALEFACTOR30_1); - x[14] = CL_shr(inp[7],SCALEFACTOR30_1); + x[10] = CL_shr( inp[25], SCALEFACTOR30_1 ); + x[11] = CL_shr( inp[13], SCALEFACTOR30_1 ); + x[12] = CL_shr( inp[1], SCALEFACTOR30_1 ); + x[13] = CL_shr( inp[19], SCALEFACTOR30_1 ); + x[14] = CL_shr( inp[7], SCALEFACTOR30_1 ); /* 1. FFT5 stage */ - rs1 = CL_add(x[1],x[4]); - rs4 = CL_sub(x[1],x[4]); - rs3 = CL_add(x[2],x[3]); - rs2 = CL_sub(x[2],x[3]); - t = CL_scale_t(CL_sub(rs1,rs3),C54); - rs1 = CL_add(rs1,rs3); - y[0] = CL_add(x[0],rs1); - rs1 = CL_add(y[0],(CL_shl(CL_scale_t(rs1,C55),1))); - rs3 = CL_sub(rs1,t); - rs1 = CL_add(rs1,t); - t = CL_scale_t(CL_add(rs4,rs2),C51); - rs4 = CL_add(t,CL_shl(CL_scale_t(rs4, C52),1)); - rs2 = CL_add(t,CL_scale_t(rs2,C53)); + rs1 = CL_add( x[1], x[4] ); + rs4 = CL_sub( x[1], x[4] ); + rs3 = CL_add( x[2], x[3] ); + rs2 = CL_sub( x[2], x[3] ); + t = CL_scale_t( CL_sub( rs1, rs3 ), C54 ); + rs1 = CL_add( rs1, rs3 ); + y[0] = CL_add( x[0], rs1 ); + rs1 = CL_add( y[0], ( CL_shl( CL_scale_t( rs1, C55 ), 1 ) ) ); + rs3 = CL_sub( rs1, t ); + rs1 = CL_add( rs1, t ); + t = CL_scale_t( CL_add( rs4, rs2 ), C51 ); + rs4 = CL_add( t, CL_shl( CL_scale_t( rs4, C52 ), 1 ) ); + rs2 = CL_add( t, CL_scale_t( rs2, C53 ) ); /* combination */ - y[1] = CL_msu_j(rs1,rs2); - y[4] = CL_mac_j(rs1,rs2); - y[2] = CL_mac_j(rs3,rs4); - y[3] = CL_msu_j(rs3,rs4); + y[1] = CL_msu_j( rs1, rs2 ); + y[4] = CL_mac_j( rs1, rs2 ); + y[2] = CL_mac_j( rs3, rs4 ); + y[3] = CL_msu_j( rs3, rs4 ); /* 2. FFT5 stage */ - rs1 = CL_add(x[6],x[9]); - rs4 = CL_sub(x[6],x[9]); - rs3 = CL_add(x[7],x[8]); - rs2 = CL_sub(x[7],x[8]); - t = CL_scale_t(CL_sub(rs1,rs3),C54); - rs1 = CL_add(rs1,rs3); - y[5] = CL_add(x[5],rs1); - rs1 = CL_add(y[5],(CL_shl(CL_scale_t(rs1,C55),1))); - rs3 = CL_sub(rs1,t); - rs1 = CL_add(rs1,t); - t = CL_scale_t(CL_add(rs4,rs2),C51); - rs4 = CL_add(t,CL_shl(CL_scale_t(rs4, C52),1)); - rs2 = CL_add(t,CL_scale_t(rs2,C53)); + rs1 = CL_add( x[6], x[9] ); + rs4 = CL_sub( x[6], x[9] ); + rs3 = CL_add( x[7], x[8] ); + rs2 = CL_sub( x[7], x[8] ); + t = CL_scale_t( CL_sub( rs1, rs3 ), C54 ); + rs1 = CL_add( rs1, rs3 ); + y[5] = CL_add( x[5], rs1 ); + rs1 = CL_add( y[5], ( CL_shl( CL_scale_t( rs1, C55 ), 1 ) ) ); + rs3 = CL_sub( rs1, t ); + rs1 = CL_add( rs1, t ); + t = CL_scale_t( CL_add( rs4, rs2 ), C51 ); + rs4 = CL_add( t, CL_shl( CL_scale_t( rs4, C52 ), 1 ) ); + rs2 = CL_add( t, CL_scale_t( rs2, C53 ) ); /* combination */ - y[6] = CL_msu_j(rs1,rs2); - y[9] = CL_mac_j(rs1,rs2); - y[7] = CL_mac_j(rs3,rs4); - y[8] = CL_msu_j(rs3,rs4); + y[6] = CL_msu_j( rs1, rs2 ); + y[9] = CL_mac_j( rs1, rs2 ); + y[7] = CL_mac_j( rs3, rs4 ); + y[8] = CL_msu_j( rs3, rs4 ); /* 3. FFT5 stage */ - rs1 = CL_add(x[11],x[14]); - rs4 = CL_sub(x[11],x[14]); - rs3 = CL_add(x[12],x[13]); - rs2 = CL_sub(x[12],x[13]); - t = CL_scale_t(CL_sub(rs1,rs3),C54); - rs1 = CL_add(rs1,rs3); - y[10] = CL_add(x[10],rs1); - rs1 = CL_add(y[10],(CL_shl(CL_scale_t(rs1,C55),1))); - rs3 = CL_sub(rs1,t); - rs1 = CL_add(rs1,t); - t = CL_scale_t(CL_add(rs4,rs2),C51); - rs4 = CL_add(t,CL_shl(CL_scale_t(rs4, C52),1)); - rs2 = CL_add(t,CL_scale_t(rs2,C53)); + rs1 = CL_add( x[11], x[14] ); + rs4 = CL_sub( x[11], x[14] ); + rs3 = CL_add( x[12], x[13] ); + rs2 = CL_sub( x[12], x[13] ); + t = CL_scale_t( CL_sub( rs1, rs3 ), C54 ); + rs1 = CL_add( rs1, rs3 ); + y[10] = CL_add( x[10], rs1 ); + rs1 = CL_add( y[10], ( CL_shl( CL_scale_t( rs1, C55 ), 1 ) ) ); + rs3 = CL_sub( rs1, t ); + rs1 = CL_add( rs1, t ); + t = CL_scale_t( CL_add( rs4, rs2 ), C51 ); + rs4 = CL_add( t, CL_shl( CL_scale_t( rs4, C52 ), 1 ) ); + rs2 = CL_add( t, CL_scale_t( rs2, C53 ) ); /* combination */ - y[11] = CL_msu_j(rs1,rs2); - y[14] = CL_mac_j(rs1,rs2); - y[12] = CL_mac_j(rs3,rs4); - y[13] = CL_msu_j(rs3,rs4); + y[11] = CL_msu_j( rs1, rs2 ); + y[14] = CL_mac_j( rs1, rs2 ); + y[12] = CL_mac_j( rs3, rs4 ); + y[13] = CL_msu_j( rs3, rs4 ); /*for (i=10; i<15; i++) { printf("%d,\t %d,\t",y[i].re, y[i].im); @@ -864,52 +863,52 @@ static void fft30_with_cmplx_data(cmplx * inp) /* 1. FFT3 stage */ /* real part */ - rs1 = CL_add(y[5],y[10]); - rs2 = CL_scale_t(CL_sub(y[5],y[10]),C31); - z[15] = CL_add(y[0],rs1); - rs1 = CL_sub(y[0],CL_shr(rs1,1)); + rs1 = CL_add( y[5], y[10] ); + rs2 = CL_scale_t( CL_sub( y[5], y[10] ), C31 ); + z[15] = CL_add( y[0], rs1 ); + rs1 = CL_sub( y[0], CL_shr( rs1, 1 ) ); - z[25] = CL_mac_j(rs1,rs2); - z[20] = CL_msu_j(rs1,rs2); + z[25] = CL_mac_j( rs1, rs2 ); + z[20] = CL_msu_j( rs1, rs2 ); /* 2. FFT3 stage */ - rs1 = CL_add(y[6],y[11]); - rs2 = CL_scale_t(CL_sub(y[6],y[11]),C31); - z[21] = CL_add(y[1],rs1); - rs1 = CL_sub(y[1],CL_shr(rs1,1)); + rs1 = CL_add( y[6], y[11] ); + rs2 = CL_scale_t( CL_sub( y[6], y[11] ), C31 ); + z[21] = CL_add( y[1], rs1 ); + rs1 = CL_sub( y[1], CL_shr( rs1, 1 ) ); - z[16] = CL_mac_j(rs1,rs2); - z[26] = CL_msu_j(rs1,rs2); + z[16] = CL_mac_j( rs1, rs2 ); + z[26] = CL_msu_j( rs1, rs2 ); /* 3. FFT3 stage */ - rs1 = CL_add(y[7],y[12]); - rs2 = CL_scale_t(CL_sub(y[7],y[12]),C31); - z[27] = CL_add(y[2],rs1); - rs1 = CL_sub(y[2],CL_shr(rs1,1)); + rs1 = CL_add( y[7], y[12] ); + rs2 = CL_scale_t( CL_sub( y[7], y[12] ), C31 ); + z[27] = CL_add( y[2], rs1 ); + rs1 = CL_sub( y[2], CL_shr( rs1, 1 ) ); - z[22] = CL_mac_j(rs1,rs2); - z[17] = CL_msu_j(rs1,rs2); + z[22] = CL_mac_j( rs1, rs2 ); + z[17] = CL_msu_j( rs1, rs2 ); /* 4. FFT3 stage */ - rs1 = CL_add(y[8],y[13]); - rs2 = CL_scale_t(CL_sub(y[8],y[13]),C31); - z[18] = CL_add(y[3],rs1); - rs1 = CL_sub(y[3],CL_shr(rs1,1)); + rs1 = CL_add( y[8], y[13] ); + rs2 = CL_scale_t( CL_sub( y[8], y[13] ), C31 ); + z[18] = CL_add( y[3], rs1 ); + rs1 = CL_sub( y[3], CL_shr( rs1, 1 ) ); - z[28] = CL_mac_j(rs1,rs2); - z[23] = CL_msu_j(rs1,rs2); + z[28] = CL_mac_j( rs1, rs2 ); + z[23] = CL_msu_j( rs1, rs2 ); /* 5. FFT3 stage */ - rs1 = CL_add(y[9],y[14]); - rs2 = CL_scale_t(CL_sub(y[9],y[14]),C31); - z[24] = CL_add(y[4],rs1); - rs1 = CL_sub(y[4],CL_shr(rs1,1)); + rs1 = CL_add( y[9], y[14] ); + rs2 = CL_scale_t( CL_sub( y[9], y[14] ), C31 ); + z[24] = CL_add( y[4], rs1 ); + rs1 = CL_sub( y[4], CL_shr( rs1, 1 ) ); - z[19] = CL_mac_j(rs1,rs2); - z[29] = CL_msu_j(rs1,rs2); + z[19] = CL_mac_j( rs1, rs2 ); + z[29] = CL_msu_j( rs1, rs2 ); /*for (i=0; i<30; i++) printf("%d,\t %d,\t",z[i].re, z[i].im); @@ -917,116 +916,130 @@ static void fft30_with_cmplx_data(cmplx * inp) /* 1. FFT2 stage */ - rs1 = CL_shr(z[0], SCALEFACTOR30_2); - rs2 = CL_shr(z[15],SCALEFACTOR30_2); - *l = CL_add(rs1,rs2); - *h = CL_sub(rs1,rs2); - l+=1; h+=1; + rs1 = CL_shr( z[0], SCALEFACTOR30_2 ); + rs2 = CL_shr( z[15], SCALEFACTOR30_2 ); + *l = CL_add( rs1, rs2 ); + *h = CL_sub( rs1, rs2 ); + l += 1; + h += 1; /* 2. FFT2 stage */ - rs1 = CL_shr(z[8], SCALEFACTOR30_2); - rs2 = CL_shr(z[23],SCALEFACTOR30_2); - *h = CL_add(rs1,rs2); - *l = CL_sub(rs1,rs2); - l+=1; h+=1; + rs1 = CL_shr( z[8], SCALEFACTOR30_2 ); + rs2 = CL_shr( z[23], SCALEFACTOR30_2 ); + *h = CL_add( rs1, rs2 ); + *l = CL_sub( rs1, rs2 ); + l += 1; + h += 1; /* 3. FFT2 stage */ - rs1 = CL_shr(z[1], SCALEFACTOR30_2); - rs2 = CL_shr(z[16],SCALEFACTOR30_2); - *l = CL_add(rs1,rs2); - *h = CL_sub(rs1,rs2); - l+=1; h+=1; + rs1 = CL_shr( z[1], SCALEFACTOR30_2 ); + rs2 = CL_shr( z[16], SCALEFACTOR30_2 ); + *l = CL_add( rs1, rs2 ); + *h = CL_sub( rs1, rs2 ); + l += 1; + h += 1; /* 4. FFT2 stage */ - rs1 = CL_shr(z[9], SCALEFACTOR30_2); - rs2 = CL_shr(z[24],SCALEFACTOR30_2); - *h = CL_add(rs1,rs2); - *l = CL_sub(rs1,rs2); - l+=1; h+=1; + rs1 = CL_shr( z[9], SCALEFACTOR30_2 ); + rs2 = CL_shr( z[24], SCALEFACTOR30_2 ); + *h = CL_add( rs1, rs2 ); + *l = CL_sub( rs1, rs2 ); + l += 1; + h += 1; /* 5. FFT2 stage */ - rs1 = CL_shr(z[2], SCALEFACTOR30_2); - rs2 = CL_shr(z[17],SCALEFACTOR30_2); - *l = CL_add(rs1,rs2); - *h = CL_sub(rs1,rs2); - l+=1; h+=1; + rs1 = CL_shr( z[2], SCALEFACTOR30_2 ); + rs2 = CL_shr( z[17], SCALEFACTOR30_2 ); + *l = CL_add( rs1, rs2 ); + *h = CL_sub( rs1, rs2 ); + l += 1; + h += 1; /* 6. FFT2 stage */ - rs1 = CL_shr(z[10], SCALEFACTOR30_2); - rs2 = CL_shr(z[25],SCALEFACTOR30_2); - *h = CL_add(rs1,rs2); - *l = CL_sub(rs1,rs2); - l+=1; h+=1; + rs1 = CL_shr( z[10], SCALEFACTOR30_2 ); + rs2 = CL_shr( z[25], SCALEFACTOR30_2 ); + *h = CL_add( rs1, rs2 ); + *l = CL_sub( rs1, rs2 ); + l += 1; + h += 1; /* 7. FFT2 stage */ - rs1 = CL_shr(z[3], SCALEFACTOR30_2); - rs2 = CL_shr(z[18],SCALEFACTOR30_2); - *l = CL_add(rs1,rs2); - *h = CL_sub(rs1,rs2); - l+=1; h+=1; + rs1 = CL_shr( z[3], SCALEFACTOR30_2 ); + rs2 = CL_shr( z[18], SCALEFACTOR30_2 ); + *l = CL_add( rs1, rs2 ); + *h = CL_sub( rs1, rs2 ); + l += 1; + h += 1; /* 8. FFT2 stage */ - rs1 = CL_shr(z[11], SCALEFACTOR30_2); - rs2 = CL_shr(z[26],SCALEFACTOR30_2); - *h = CL_add(rs1,rs2); - *l = CL_sub(rs1,rs2); - l+=1; h+=1; + rs1 = CL_shr( z[11], SCALEFACTOR30_2 ); + rs2 = CL_shr( z[26], SCALEFACTOR30_2 ); + *h = CL_add( rs1, rs2 ); + *l = CL_sub( rs1, rs2 ); + l += 1; + h += 1; /* 9. FFT2 stage */ - rs1 = CL_shr(z[4], SCALEFACTOR30_2); - rs2 = CL_shr(z[19],SCALEFACTOR30_2); - *l = CL_add(rs1,rs2); - *h = CL_sub(rs1,rs2); - l+=1; h+=1; + rs1 = CL_shr( z[4], SCALEFACTOR30_2 ); + rs2 = CL_shr( z[19], SCALEFACTOR30_2 ); + *l = CL_add( rs1, rs2 ); + *h = CL_sub( rs1, rs2 ); + l += 1; + h += 1; /* 10. FFT2 stage */ - rs1 = CL_shr(z[12], SCALEFACTOR30_2); - rs2 = CL_shr(z[27],SCALEFACTOR30_2); - *h = CL_add(rs1,rs2); - *l = CL_sub(rs1,rs2); - l+=1; h+=1; + rs1 = CL_shr( z[12], SCALEFACTOR30_2 ); + rs2 = CL_shr( z[27], SCALEFACTOR30_2 ); + *h = CL_add( rs1, rs2 ); + *l = CL_sub( rs1, rs2 ); + l += 1; + h += 1; /* 11. FFT2 stage */ - rs1 = CL_shr(z[5], SCALEFACTOR30_2); - rs2 = CL_shr(z[20],SCALEFACTOR30_2); - *l = CL_add(rs1,rs2); - *h = CL_sub(rs1,rs2); - l+=1; h+=1; + rs1 = CL_shr( z[5], SCALEFACTOR30_2 ); + rs2 = CL_shr( z[20], SCALEFACTOR30_2 ); + *l = CL_add( rs1, rs2 ); + *h = CL_sub( rs1, rs2 ); + l += 1; + h += 1; /* 12. FFT2 stage */ - rs1 = CL_shr(z[13], SCALEFACTOR30_2); - rs2 = CL_shr(z[28],SCALEFACTOR30_2); - *h = CL_add(rs1,rs2); - *l = CL_sub(rs1,rs2); - l+=1; h+=1; + rs1 = CL_shr( z[13], SCALEFACTOR30_2 ); + rs2 = CL_shr( z[28], SCALEFACTOR30_2 ); + *h = CL_add( rs1, rs2 ); + *l = CL_sub( rs1, rs2 ); + l += 1; + h += 1; /* 13. FFT2 stage */ - rs1 = CL_shr(z[6], SCALEFACTOR30_2); - rs2 = CL_shr(z[21],SCALEFACTOR30_2); - *l = CL_add(rs1,rs2); - *h = CL_sub(rs1,rs2); - l+=1; h+=1; + rs1 = CL_shr( z[6], SCALEFACTOR30_2 ); + rs2 = CL_shr( z[21], SCALEFACTOR30_2 ); + *l = CL_add( rs1, rs2 ); + *h = CL_sub( rs1, rs2 ); + l += 1; + h += 1; /* 14. FFT2 stage */ - rs1 = CL_shr(z[14], SCALEFACTOR30_2); - rs2 = CL_shr(z[29],SCALEFACTOR30_2); - *h = CL_add(rs1,rs2); - *l = CL_sub(rs1,rs2); - l+=1; h+=1; + rs1 = CL_shr( z[14], SCALEFACTOR30_2 ); + rs2 = CL_shr( z[29], SCALEFACTOR30_2 ); + *h = CL_add( rs1, rs2 ); + *l = CL_sub( rs1, rs2 ); + l += 1; + h += 1; /* 15. FFT2 stage */ - rs1 = CL_shr(z[7], SCALEFACTOR30_2); - rs2 = CL_shr(z[22],SCALEFACTOR30_2); - *l = CL_add(rs1,rs2); - *h = CL_sub(rs1,rs2); - l+=1; h+=1; - -#if (WMOPS) + rs1 = CL_shr( z[7], SCALEFACTOR30_2 ); + rs2 = CL_shr( z[22], SCALEFACTOR30_2 ); + *l = CL_add( rs1, rs2 ); + *h = CL_sub( rs1, rs2 ); + l += 1; + h += 1; + +#if ( WMOPS ) multiCounter[currCounter].CL_move += 30; -#endif - +#endif } /*-------------------------------------------------------------------* @@ -1035,30 +1048,30 @@ static void fft30_with_cmplx_data(cmplx * inp) * Interface functions FFT subroutines *--------------------------------------------------------------------*/ void fft_cldfb_fx( - Word32 *data, /* i/o: input/output vector */ + Word32 *data, /* i/o: input/output vector */ const Word16 size /* size of fft operation */ ) { - SWITCH ( size ) + SWITCH( size ) { case 5: - fft5_with_cmplx_data( (cmplx *)data ); + fft5_with_cmplx_data( (cmplx *) data ); BREAK; case 8: - fft8_with_cmplx_data( (cmplx *)data ); + fft8_with_cmplx_data( (cmplx *) data ); BREAK; case 10: - fft10_with_cmplx_data( (cmplx *)data ); + fft10_with_cmplx_data( (cmplx *) data ); BREAK; case 16: - fft16_with_cmplx_data( (cmplx *)data, 0); + fft16_with_cmplx_data( (cmplx *) data, 0 ); BREAK; case 20: - fft20_with_cmplx_data( (cmplx *)data ); + fft20_with_cmplx_data( (cmplx *) data ); BREAK; case 30: - fft30_with_cmplx_data( (cmplx *)data ); + fft30_with_cmplx_data( (cmplx *) data ); BREAK; default: diff --git a/lib_com/fft_evs.c b/lib_com/fft_evs.c index 17da7a273..86755b13a 100644 --- a/lib_com/fft_evs.c +++ b/lib_com/fft_evs.c @@ -10,47 +10,47 @@ #include "rom_com.h" #include "options.h" #include "stl.h" - /************************************************************************/ - /* FFT */ - /************************************************************************/ - -#define SCALEFACTORN2 ( 3) -#define SCALEFACTOR2 ( 2) -#define SCALEFACTOR3 ( 3) -#define SCALEFACTOR4 ( 3) -#define SCALEFACTOR5 ( 4) -#define SCALEFACTOR8 ( 4) -#define SCALEFACTOR10 ( 5) -#define SCALEFACTOR12 ( 5) -#define SCALEFACTOR15 ( 5) -#define SCALEFACTOR16 ( 5) -#define SCALEFACTOR20 ( 5) -#define SCALEFACTOR24 ( 6) -#define SCALEFACTOR30 ( 6) -#define SCALEFACTOR30_1 ( 5) -#define SCALEFACTOR30_2 ( 1) -#define SCALEFACTOR32 ( 6) -#define SCALEFACTOR32_1 ( 5) -#define SCALEFACTOR32_2 ( 1) -#define SCALEFACTOR40 ( 7) -#define SCALEFACTOR60 ( 7) -#define SCALEFACTOR64 ( 7) -#define SCALEFACTOR80 ( 8) -#define SCALEFACTOR100 (10) -#define SCALEFACTOR120 ( 8) -#define SCALEFACTOR128 ( 8) -#define SCALEFACTOR160 ( 8) -#define SCALEFACTOR192 (10) -#define SCALEFACTOR200 (10) -#define SCALEFACTOR240 ( 9) -#define SCALEFACTOR256 ( 9) -#define SCALEFACTOR320 (10) -#define SCALEFACTOR400 (10) -#define SCALEFACTOR480 (11) -#define SCALEFACTOR600 (10) - - -void fft16_with_cmplx_data( cmplx *pInp, Word16 bsacle); +/************************************************************************/ +/* FFT */ +/************************************************************************/ + +#define SCALEFACTORN2 ( 3 ) +#define SCALEFACTOR2 ( 2 ) +#define SCALEFACTOR3 ( 3 ) +#define SCALEFACTOR4 ( 3 ) +#define SCALEFACTOR5 ( 4 ) +#define SCALEFACTOR8 ( 4 ) +#define SCALEFACTOR10 ( 5 ) +#define SCALEFACTOR12 ( 5 ) +#define SCALEFACTOR15 ( 5 ) +#define SCALEFACTOR16 ( 5 ) +#define SCALEFACTOR20 ( 5 ) +#define SCALEFACTOR24 ( 6 ) +#define SCALEFACTOR30 ( 6 ) +#define SCALEFACTOR30_1 ( 5 ) +#define SCALEFACTOR30_2 ( 1 ) +#define SCALEFACTOR32 ( 6 ) +#define SCALEFACTOR32_1 ( 5 ) +#define SCALEFACTOR32_2 ( 1 ) +#define SCALEFACTOR40 ( 7 ) +#define SCALEFACTOR60 ( 7 ) +#define SCALEFACTOR64 ( 7 ) +#define SCALEFACTOR80 ( 8 ) +#define SCALEFACTOR100 ( 10 ) +#define SCALEFACTOR120 ( 8 ) +#define SCALEFACTOR128 ( 8 ) +#define SCALEFACTOR160 ( 8 ) +#define SCALEFACTOR192 ( 10 ) +#define SCALEFACTOR200 ( 10 ) +#define SCALEFACTOR240 ( 9 ) +#define SCALEFACTOR256 ( 9 ) +#define SCALEFACTOR320 ( 10 ) +#define SCALEFACTOR400 ( 10 ) +#define SCALEFACTOR480 ( 11 ) +#define SCALEFACTOR600 ( 10 ) + + +void fft16_with_cmplx_data( cmplx *pInp, Word16 bsacle ); /** * \brief Profiling / Precision results @@ -91,38 +91,38 @@ void fft16_with_cmplx_data( cmplx *pInp, Word16 bsacle); */ -#define Mpy_32_xx Mpy_32_16_1 +#define Mpy_32_xx Mpy_32_16_1 -#define FFTC(x) WORD322WORD16((Word32)x) +#define FFTC( x ) WORD322WORD16( (Word32) x ) -#define C31 (FFTC(0x91261468)) /* FL2WORD32( -0.86602540) -sqrt(3)/2 */ +#define C31 ( FFTC( 0x91261468 ) ) /* FL2WORD32( -0.86602540) -sqrt(3)/2 */ -#define C51 (FFTC(0x79bc3854)) /* FL2WORD32( 0.95105652) */ -#define C52 (FFTC(0x9d839db0)) /* FL2WORD32(-1.53884180/2) */ -#define C53 (FFTC(0xd18053ce)) /* FL2WORD32(-0.36327126) */ -#define C54 (FFTC(0x478dde64)) /* FL2WORD32( 0.55901699) */ -#define C55 (FFTC(0xb0000001)) /* FL2WORD32(-1.25/2) */ +#define C51 ( FFTC( 0x79bc3854 ) ) /* FL2WORD32( 0.95105652) */ +#define C52 ( FFTC( 0x9d839db0 ) ) /* FL2WORD32(-1.53884180/2) */ +#define C53 ( FFTC( 0xd18053ce ) ) /* FL2WORD32(-0.36327126) */ +#define C54 ( FFTC( 0x478dde64 ) ) /* FL2WORD32( 0.55901699) */ +#define C55 ( FFTC( 0xb0000001 ) ) /* FL2WORD32(-1.25/2) */ -#define C81 (FFTC(0x5a82799a)) /* FL2WORD32( 7.071067811865475e-1) */ -#define C82 (FFTC(0xa57d8666)) /* FL2WORD32(-7.071067811865475e-1) */ +#define C81 ( FFTC( 0x5a82799a ) ) /* FL2WORD32( 7.071067811865475e-1) */ +#define C82 ( FFTC( 0xa57d8666 ) ) /* FL2WORD32(-7.071067811865475e-1) */ -#define C161 (FFTC(0x5a82799a)) /* FL2WORD32( 7.071067811865475e-1) INV_SQRT2 */ -#define C162 (FFTC(0xa57d8666)) /* FL2WORD32(-7.071067811865475e-1) -INV_SQRT2 */ +#define C161 ( FFTC( 0x5a82799a ) ) /* FL2WORD32( 7.071067811865475e-1) INV_SQRT2 */ +#define C162 ( FFTC( 0xa57d8666 ) ) /* FL2WORD32(-7.071067811865475e-1) -INV_SQRT2 */ -#define C163 (FFTC(0x7641af3d)) /* FL2WORD32( 9.238795325112867e-1) COS_PI_DIV8 */ -#define C164 (FFTC(0x89be50c3)) /* FL2WORD32(-9.238795325112867e-1) -COS_PI_DIV8 */ +#define C163 ( FFTC( 0x7641af3d ) ) /* FL2WORD32( 9.238795325112867e-1) COS_PI_DIV8 */ +#define C164 ( FFTC( 0x89be50c3 ) ) /* FL2WORD32(-9.238795325112867e-1) -COS_PI_DIV8 */ -#define C165 (FFTC(0x30fbc54d)) /* FL2WORD32( 3.826834323650898e-1) COS_3PI_DIV8 */ -#define C166 (FFTC(0xcf043ab3)) /* FL2WORD32(-3.826834323650898e-1) -COS_3PI_DIV8 */ +#define C165 ( FFTC( 0x30fbc54d ) ) /* FL2WORD32( 3.826834323650898e-1) COS_3PI_DIV8 */ +#define C166 ( FFTC( 0xcf043ab3 ) ) /* FL2WORD32(-3.826834323650898e-1) -COS_3PI_DIV8 */ -#define cplxMpy4_8_0(re,im,a,b,c,d) re = L_shr(L_sub(Mpy_32_xx(a,c),Mpy_32_xx(b,d)),1); \ - im = L_shr(L_add(Mpy_32_xx(a,d),Mpy_32_xx(b,c)),1); - -#define cplxMpy4_8_1(re,im,a,b) re = L_shr(a,1); \ - im = L_shr(b,1); - +#define cplxMpy4_8_0( re, im, a, b, c, d ) \ + re = L_shr( L_sub( Mpy_32_xx( a, c ), Mpy_32_xx( b, d ) ), 1 ); \ + im = L_shr( L_add( Mpy_32_xx( a, d ), Mpy_32_xx( b, c ) ), 1 ); +#define cplxMpy4_8_1( re, im, a, b ) \ + re = L_shr( a, 1 ); \ + im = L_shr( b, 1 ); /** @@ -138,50 +138,49 @@ void fft16_with_cmplx_data( cmplx *pInp, Word16 bsacle); * * \return void */ -static void fft5_with_cmplx_data(cmplx *inp) +static void fft5_with_cmplx_data( cmplx *inp ) { - cmplx x0,x1,x2,x3,x4; - cmplx y1,y2,y3,y4; + cmplx x0, x1, x2, x3, x4; + cmplx y1, y2, y3, y4; cmplx t; - x0 = CL_shr(inp[0],SCALEFACTOR5); - x1 = CL_shr(inp[1],SCALEFACTOR5); - x2 = CL_shr(inp[2],SCALEFACTOR5); - x3 = CL_shr(inp[3],SCALEFACTOR5); - x4 = CL_shr(inp[4],SCALEFACTOR5); + x0 = CL_shr( inp[0], SCALEFACTOR5 ); + x1 = CL_shr( inp[1], SCALEFACTOR5 ); + x2 = CL_shr( inp[2], SCALEFACTOR5 ); + x3 = CL_shr( inp[3], SCALEFACTOR5 ); + x4 = CL_shr( inp[4], SCALEFACTOR5 ); - y1 = CL_add(x1,x4); - y4 = CL_sub(x1,x4); - y3 = CL_add(x2,x3); - y2 = CL_sub(x2,x3); - t = CL_scale_t(CL_sub(y1,y3),C54); - y1 = CL_add(y1,y3); - inp[0] = CL_add(x0,y1); + y1 = CL_add( x1, x4 ); + y4 = CL_sub( x1, x4 ); + y3 = CL_add( x2, x3 ); + y2 = CL_sub( x2, x3 ); + t = CL_scale_t( CL_sub( y1, y3 ), C54 ); + y1 = CL_add( y1, y3 ); + inp[0] = CL_add( x0, y1 ); /* Bit shift left because of the constant C55 which was scaled with the factor 0.5 because of the representation of the values as fracts */ - y1 = CL_add(inp[0],(CL_shl(CL_scale_t(y1,C55),1))); - y3 = CL_sub(y1,t); - y1 = CL_add(y1,t); + y1 = CL_add( inp[0], ( CL_shl( CL_scale_t( y1, C55 ), 1 ) ) ); + y3 = CL_sub( y1, t ); + y1 = CL_add( y1, t ); - t = CL_scale_t(CL_add(y4,y2),C51); + t = CL_scale_t( CL_add( y4, y2 ), C51 ); /* Bit shift left because of the constant C55 which was scaled with the factor 0.5 because of the representation of the values as fracts */ - y4 = CL_add(t,CL_shl(CL_scale_t(y4, C52),1)); - y2 = CL_add(t,CL_scale_t(y2,C53)); + y4 = CL_add( t, CL_shl( CL_scale_t( y4, C52 ), 1 ) ); + y2 = CL_add( t, CL_scale_t( y2, C53 ) ); /* combination */ - inp[1] = CL_msu_j(y1,y2); - inp[4] = CL_mac_j(y1,y2); + inp[1] = CL_msu_j( y1, y2 ); + inp[4] = CL_mac_j( y1, y2 ); - inp[2] = CL_mac_j(y3,y4); - inp[3] = CL_msu_j(y3,y4); - -#if (WMOPS) - multiCounter[currCounter].CL_move += 5; -#endif + inp[2] = CL_mac_j( y3, y4 ); + inp[3] = CL_msu_j( y3, y4 ); +#if ( WMOPS ) + multiCounter[currCounter].CL_move += 5; +#endif } /** @@ -197,73 +196,71 @@ static void fft5_with_cmplx_data(cmplx *inp) * * \return void */ -static void fft8_with_cmplx_data(cmplx *inp) +static void fft8_with_cmplx_data( cmplx *inp ) { cmplx x0, x1, x2, x3, x4, x5, x6, x7; cmplx s0, s1, s2, s3, s4, s5, s6, s7; cmplx t0, t1, t2, t3, t4, t5, t6, t7; /* Pre-additions */ - x0 = CL_shr(inp[0], SCALEFACTOR8); - x1 = CL_shr(inp[1], SCALEFACTOR8); - x2 = CL_shr(inp[2], SCALEFACTOR8); - x3 = CL_shr(inp[3], SCALEFACTOR8); - x4 = CL_shr(inp[4], SCALEFACTOR8); - x5 = CL_shr(inp[5], SCALEFACTOR8); - x6 = CL_shr(inp[6], SCALEFACTOR8); - x7 = CL_shr(inp[7], SCALEFACTOR8); + x0 = CL_shr( inp[0], SCALEFACTOR8 ); + x1 = CL_shr( inp[1], SCALEFACTOR8 ); + x2 = CL_shr( inp[2], SCALEFACTOR8 ); + x3 = CL_shr( inp[3], SCALEFACTOR8 ); + x4 = CL_shr( inp[4], SCALEFACTOR8 ); + x5 = CL_shr( inp[5], SCALEFACTOR8 ); + x6 = CL_shr( inp[6], SCALEFACTOR8 ); + x7 = CL_shr( inp[7], SCALEFACTOR8 ); /* loops are unrolled */ { - t0 = CL_add(x0,x4); - t1 = CL_sub(x0,x4); + t0 = CL_add( x0, x4 ); + t1 = CL_sub( x0, x4 ); - t2 = CL_add(x1,x5); - t3 = CL_sub(x1,x5); + t2 = CL_add( x1, x5 ); + t3 = CL_sub( x1, x5 ); - t4 = CL_add(x2,x6); - t5 = CL_sub(x2,x6); + t4 = CL_add( x2, x6 ); + t5 = CL_sub( x2, x6 ); - t6 = CL_add(x3,x7); - t7 = CL_sub(x3,x7); + t6 = CL_add( x3, x7 ); + t7 = CL_sub( x3, x7 ); } /* Pre-additions and core multiplications */ - s0 = CL_add(t0, t4); - s2 = CL_sub(t0, t4); + s0 = CL_add( t0, t4 ); + s2 = CL_sub( t0, t4 ); - s4 = CL_mac_j(t1, t5); - s5 = CL_msu_j(t1, t5); + s4 = CL_mac_j( t1, t5 ); + s5 = CL_msu_j( t1, t5 ); - s1 = CL_add(t2, t6); - s3 = CL_sub(t2, t6); - s3 = CL_mul_j(s3); + s1 = CL_add( t2, t6 ); + s3 = CL_sub( t2, t6 ); + s3 = CL_mul_j( s3 ); - t0 = CL_add(t3, t7); - t1 = CL_sub(t3, t7); + t0 = CL_add( t3, t7 ); + t1 = CL_sub( t3, t7 ); - s6 = CL_scale_t(CL_msu_j(t1, t0), C81); - s7 = CL_dscale_t(CL_swap_real_imag(CL_msu_j(t0, t1)), C81, C82); + s6 = CL_scale_t( CL_msu_j( t1, t0 ), C81 ); + s7 = CL_dscale_t( CL_swap_real_imag( CL_msu_j( t0, t1 ) ), C81, C82 ); /* Post-additions */ - inp[0] = CL_add(s0, s1); - inp[4] = CL_sub(s0, s1); + inp[0] = CL_add( s0, s1 ); + inp[4] = CL_sub( s0, s1 ); - inp[2] = CL_sub(s2, s3); - inp[6] = CL_add(s2, s3); + inp[2] = CL_sub( s2, s3 ); + inp[6] = CL_add( s2, s3 ); - inp[3] = CL_add(s4, s7); - inp[7] = CL_sub(s4, s7); + inp[3] = CL_add( s4, s7 ); + inp[7] = CL_sub( s4, s7 ); - inp[1] = CL_add(s5, s6); - inp[5] = CL_sub(s5, s6); -#if (WMOPS) + inp[1] = CL_add( s5, s6 ); + inp[5] = CL_sub( s5, s6 ); +#if ( WMOPS ) multiCounter[currCounter].CL_move += 8; -#endif - - +#endif } @@ -281,99 +278,98 @@ static void fft8_with_cmplx_data(cmplx *inp) * \return void */ -static void fft10_with_cmplx_data(cmplx *inp_data) +static void fft10_with_cmplx_data( cmplx *inp_data ) { - cmplx r1,r2,r3,r4; - cmplx x0,x1,x2,x3,x4,t; + cmplx r1, r2, r3, r4; + cmplx x0, x1, x2, x3, x4, t; cmplx y[10]; /* FOR i=0 */ { - x0 = CL_shr(inp_data[0],SCALEFACTOR10); - x1 = CL_shr(inp_data[2],SCALEFACTOR10); - x2 = CL_shr(inp_data[4],SCALEFACTOR10); - x3 = CL_shr(inp_data[6],SCALEFACTOR10); - x4 = CL_shr(inp_data[8],SCALEFACTOR10); - - r1 = CL_add(x3,x2); - r4 = CL_sub(x3,x2); - r3 = CL_add(x1,x4); - r2 = CL_sub(x1,x4); - t = CL_scale_t(CL_sub(r1,r3),C54); - r1 = CL_add(r1,r3); - y[0] = CL_add(x0,r1); - r1 = CL_add(y[0],(CL_shl(CL_scale_t(r1,C55),1))); - r3 = CL_sub(r1,t); - r1 = CL_add(r1,t); - t = CL_scale_t((CL_add(r4,r2)),C51); - r4 = CL_add(t,CL_shl(CL_scale_t(r4, C52),1)); - r2 = CL_add(t,CL_scale_t(r2,C53)); - - - y[2] = CL_msu_j(r1,r2); - y[8] = CL_mac_j(r1,r2); - y[4] = CL_mac_j(r3,r4); - y[6] = CL_msu_j(r3,r4); + x0 = CL_shr( inp_data[0], SCALEFACTOR10 ); + x1 = CL_shr( inp_data[2], SCALEFACTOR10 ); + x2 = CL_shr( inp_data[4], SCALEFACTOR10 ); + x3 = CL_shr( inp_data[6], SCALEFACTOR10 ); + x4 = CL_shr( inp_data[8], SCALEFACTOR10 ); + + r1 = CL_add( x3, x2 ); + r4 = CL_sub( x3, x2 ); + r3 = CL_add( x1, x4 ); + r2 = CL_sub( x1, x4 ); + t = CL_scale_t( CL_sub( r1, r3 ), C54 ); + r1 = CL_add( r1, r3 ); + y[0] = CL_add( x0, r1 ); + r1 = CL_add( y[0], ( CL_shl( CL_scale_t( r1, C55 ), 1 ) ) ); + r3 = CL_sub( r1, t ); + r1 = CL_add( r1, t ); + t = CL_scale_t( ( CL_add( r4, r2 ) ), C51 ); + r4 = CL_add( t, CL_shl( CL_scale_t( r4, C52 ), 1 ) ); + r2 = CL_add( t, CL_scale_t( r2, C53 ) ); + + + y[2] = CL_msu_j( r1, r2 ); + y[8] = CL_mac_j( r1, r2 ); + y[4] = CL_mac_j( r3, r4 ); + y[6] = CL_msu_j( r3, r4 ); } /* FOR i=1 */ { - x0 = CL_shr(inp_data[5],SCALEFACTOR10); - x1 = CL_shr(inp_data[1],SCALEFACTOR10); - x2 = CL_shr(inp_data[3],SCALEFACTOR10); - x3 = CL_shr(inp_data[7],SCALEFACTOR10); - x4 = CL_shr(inp_data[9],SCALEFACTOR10); - - r1 = CL_add(x1,x4); - r4 = CL_sub(x1,x4); - r3 = CL_add(x3,x2); - r2 = CL_sub(x3,x2); - t = CL_scale_t(CL_sub(r1,r3),C54); - r1 = CL_add(r1,r3); - y[1] = CL_add(x0,r1); - r1 = CL_add(y[1],(CL_shl(CL_scale_t(r1,C55),1))); - r3 = CL_sub(r1,t); - r1 = CL_add(r1,t); - t = CL_scale_t((CL_add(r4,r2)),C51); - r4 = CL_add(t,CL_shl(CL_scale_t(r4, C52),1)); - r2 = CL_add(t,CL_scale_t(r2,C53)); - - - y[3] = CL_msu_j(r1,r2); - y[9] = CL_mac_j(r1,r2); - y[5] = CL_mac_j(r3,r4); - y[7] = CL_msu_j(r3,r4); + x0 = CL_shr( inp_data[5], SCALEFACTOR10 ); + x1 = CL_shr( inp_data[1], SCALEFACTOR10 ); + x2 = CL_shr( inp_data[3], SCALEFACTOR10 ); + x3 = CL_shr( inp_data[7], SCALEFACTOR10 ); + x4 = CL_shr( inp_data[9], SCALEFACTOR10 ); + + r1 = CL_add( x1, x4 ); + r4 = CL_sub( x1, x4 ); + r3 = CL_add( x3, x2 ); + r2 = CL_sub( x3, x2 ); + t = CL_scale_t( CL_sub( r1, r3 ), C54 ); + r1 = CL_add( r1, r3 ); + y[1] = CL_add( x0, r1 ); + r1 = CL_add( y[1], ( CL_shl( CL_scale_t( r1, C55 ), 1 ) ) ); + r3 = CL_sub( r1, t ); + r1 = CL_add( r1, t ); + t = CL_scale_t( ( CL_add( r4, r2 ) ), C51 ); + r4 = CL_add( t, CL_shl( CL_scale_t( r4, C52 ), 1 ) ); + r2 = CL_add( t, CL_scale_t( r2, C53 ) ); + + + y[3] = CL_msu_j( r1, r2 ); + y[9] = CL_mac_j( r1, r2 ); + y[5] = CL_mac_j( r3, r4 ); + y[7] = CL_msu_j( r3, r4 ); } /* FOR i=0 */ { - inp_data[0] = CL_add(y[0],y[1]); - inp_data[5] = CL_sub(y[0],y[1]); + inp_data[0] = CL_add( y[0], y[1] ); + inp_data[5] = CL_sub( y[0], y[1] ); } /* FOR i=2 */ { - inp_data[2] = CL_add(y[2],y[3]); - inp_data[7] = CL_sub(y[2],y[3]); + inp_data[2] = CL_add( y[2], y[3] ); + inp_data[7] = CL_sub( y[2], y[3] ); } /* FOR i=4 */ { - inp_data[4] = CL_add(y[4],y[5]); - inp_data[9] = CL_sub(y[4],y[5]); + inp_data[4] = CL_add( y[4], y[5] ); + inp_data[9] = CL_sub( y[4], y[5] ); } /* FOR i=6 */ { - inp_data[6] = CL_add(y[6],y[7]); - inp_data[1] = CL_sub(y[6],y[7]); + inp_data[6] = CL_add( y[6], y[7] ); + inp_data[1] = CL_sub( y[6], y[7] ); } /* FOR i=8 */ { - inp_data[8] = CL_add(y[8],y[9]); - inp_data[3] = CL_sub(y[8],y[9]); + inp_data[8] = CL_add( y[8], y[9] ); + inp_data[3] = CL_sub( y[8], y[9] ); } - -#if (WMOPS) - multiCounter[currCounter].CL_move += 10; -#endif +#if ( WMOPS ) + multiCounter[currCounter].CL_move += 10; +#endif } @@ -391,142 +387,140 @@ static void fft10_with_cmplx_data(cmplx *inp_data) * \return void */ -static void fft15_with_cmplx_data(cmplx *inp_data) +static void fft15_with_cmplx_data( cmplx *inp_data ) { - cmplx c0,c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14; - cmplx c_z0,c_z1, c_z2, c_z3, c_z4, c_z5, c_z6, c_z7, c_z8, c_z9, c_z10, c_z11, c_z12, c_z13, c_z14; - cmplx c_y1,c_y2,c_y3,c_y4; - cmplx c_t; - - c0 = CL_shr(inp_data[ 0],SCALEFACTOR15); - c1 = CL_shr(inp_data[ 3],SCALEFACTOR15); - c2 = CL_shr(inp_data[ 6],SCALEFACTOR15); - c3 = CL_shr(inp_data[ 9],SCALEFACTOR15); - c4 = CL_shr(inp_data[12],SCALEFACTOR15); - c5 = CL_shr(inp_data[ 5],SCALEFACTOR15); - c6 = CL_shr(inp_data[ 8],SCALEFACTOR15); - c7 = CL_shr(inp_data[11],SCALEFACTOR15); - c8 = CL_shr(inp_data[14],SCALEFACTOR15); - c9 = CL_shr(inp_data[ 2],SCALEFACTOR15); - c10 = CL_shr(inp_data[10],SCALEFACTOR15); - c11 = CL_shr(inp_data[13],SCALEFACTOR15); - c12 = CL_shr(inp_data[ 1],SCALEFACTOR15); - c13 = CL_shr(inp_data[ 4],SCALEFACTOR15); - c14 = CL_shr(inp_data[ 7],SCALEFACTOR15); - - /* 1. FFT5 stage */ - c_y1 = CL_add(c1,c4); - c_y4 = CL_sub(c1,c4); - c_y3 = CL_add(c2,c3); - c_y2 = CL_sub(c2,c3); - c_t = CL_scale_t(CL_sub(c_y1,c_y3),C54); - c_y1 = CL_add(c_y1,c_y3); - c_z0 = CL_add(c0,c_y1); - c_y1 = CL_add(c_z0,(CL_shl(CL_scale_t(c_y1,C55),1))); - c_y3 = CL_sub(c_y1,c_t); - c_y1 = CL_add(c_y1,c_t); - c_t = CL_scale_t(CL_add(c_y4,c_y2),C51); - c_y4 = CL_add(c_t,CL_shl(CL_scale_t(c_y4,C52),1)); - c_y2 = CL_add(c_t,CL_scale_t(c_y2,C53)); + cmplx c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14; + cmplx c_z0, c_z1, c_z2, c_z3, c_z4, c_z5, c_z6, c_z7, c_z8, c_z9, c_z10, c_z11, c_z12, c_z13, c_z14; + cmplx c_y1, c_y2, c_y3, c_y4; + cmplx c_t; + + c0 = CL_shr( inp_data[0], SCALEFACTOR15 ); + c1 = CL_shr( inp_data[3], SCALEFACTOR15 ); + c2 = CL_shr( inp_data[6], SCALEFACTOR15 ); + c3 = CL_shr( inp_data[9], SCALEFACTOR15 ); + c4 = CL_shr( inp_data[12], SCALEFACTOR15 ); + c5 = CL_shr( inp_data[5], SCALEFACTOR15 ); + c6 = CL_shr( inp_data[8], SCALEFACTOR15 ); + c7 = CL_shr( inp_data[11], SCALEFACTOR15 ); + c8 = CL_shr( inp_data[14], SCALEFACTOR15 ); + c9 = CL_shr( inp_data[2], SCALEFACTOR15 ); + c10 = CL_shr( inp_data[10], SCALEFACTOR15 ); + c11 = CL_shr( inp_data[13], SCALEFACTOR15 ); + c12 = CL_shr( inp_data[1], SCALEFACTOR15 ); + c13 = CL_shr( inp_data[4], SCALEFACTOR15 ); + c14 = CL_shr( inp_data[7], SCALEFACTOR15 ); + + /* 1. FFT5 stage */ + c_y1 = CL_add( c1, c4 ); + c_y4 = CL_sub( c1, c4 ); + c_y3 = CL_add( c2, c3 ); + c_y2 = CL_sub( c2, c3 ); + c_t = CL_scale_t( CL_sub( c_y1, c_y3 ), C54 ); + c_y1 = CL_add( c_y1, c_y3 ); + c_z0 = CL_add( c0, c_y1 ); + c_y1 = CL_add( c_z0, ( CL_shl( CL_scale_t( c_y1, C55 ), 1 ) ) ); + c_y3 = CL_sub( c_y1, c_t ); + c_y1 = CL_add( c_y1, c_t ); + c_t = CL_scale_t( CL_add( c_y4, c_y2 ), C51 ); + c_y4 = CL_add( c_t, CL_shl( CL_scale_t( c_y4, C52 ), 1 ) ); + c_y2 = CL_add( c_t, CL_scale_t( c_y2, C53 ) ); /* combination */ - c_z1 = CL_msu_j(c_y1,c_y2); - c_z2 = CL_mac_j(c_y3,c_y4); - c_z3 = CL_msu_j(c_y3,c_y4); - c_z4 = CL_mac_j(c_y1,c_y2); + c_z1 = CL_msu_j( c_y1, c_y2 ); + c_z2 = CL_mac_j( c_y3, c_y4 ); + c_z3 = CL_msu_j( c_y3, c_y4 ); + c_z4 = CL_mac_j( c_y1, c_y2 ); /* 2. FFT5 stage */ - c_y1 = CL_add(c6,c9); - c_y4 = CL_sub(c6,c9); - c_y3 = CL_add(c7,c8); - c_y2 = CL_sub(c7,c8); - c_t = CL_scale_t(CL_sub(c_y1,c_y3),C54); - c_y1 = CL_add(c_y1,c_y3); - c_z5 = CL_add(c5,c_y1); - c_y1 = CL_add(c_z5,(CL_shl(CL_scale_t(c_y1,C55),1))); - c_y3 = CL_sub(c_y1,c_t); - c_y1 = CL_add(c_y1,c_t); - c_t = CL_scale_t(CL_add(c_y4,c_y2),C51); - c_y4 = CL_add(c_t,CL_shl(CL_scale_t(c_y4,C52),1)); - c_y2 = CL_add(c_t,CL_scale_t(c_y2,C53)); + c_y1 = CL_add( c6, c9 ); + c_y4 = CL_sub( c6, c9 ); + c_y3 = CL_add( c7, c8 ); + c_y2 = CL_sub( c7, c8 ); + c_t = CL_scale_t( CL_sub( c_y1, c_y3 ), C54 ); + c_y1 = CL_add( c_y1, c_y3 ); + c_z5 = CL_add( c5, c_y1 ); + c_y1 = CL_add( c_z5, ( CL_shl( CL_scale_t( c_y1, C55 ), 1 ) ) ); + c_y3 = CL_sub( c_y1, c_t ); + c_y1 = CL_add( c_y1, c_t ); + c_t = CL_scale_t( CL_add( c_y4, c_y2 ), C51 ); + c_y4 = CL_add( c_t, CL_shl( CL_scale_t( c_y4, C52 ), 1 ) ); + c_y2 = CL_add( c_t, CL_scale_t( c_y2, C53 ) ); /* combination */ - c_z6 = CL_msu_j(c_y1,c_y2); - c_z7 = CL_mac_j(c_y3,c_y4); - c_z8 = CL_msu_j(c_y3,c_y4); - c_z9 = CL_mac_j(c_y1,c_y2); + c_z6 = CL_msu_j( c_y1, c_y2 ); + c_z7 = CL_mac_j( c_y3, c_y4 ); + c_z8 = CL_msu_j( c_y3, c_y4 ); + c_z9 = CL_mac_j( c_y1, c_y2 ); /* 3. FFT5 stage */ - c_y1 = CL_add(c11,c14); - c_y4 = CL_sub(c11,c14); - c_y3 = CL_add(c12,c13); - c_y2 = CL_sub(c12,c13); - c_t = CL_scale_t(CL_sub(c_y1,c_y3),C54); - c_y1 = CL_add(c_y1,c_y3); - c_z10 = CL_add(c10,c_y1); - c_y1 = CL_add(c_z10,(CL_shl(CL_scale_t(c_y1,C55),1))); - c_y3 = CL_sub(c_y1,c_t); - c_y1 = CL_add(c_y1,c_t); - c_t = CL_scale_t(CL_add(c_y4,c_y2),C51); - c_y4 = CL_add(c_t,CL_shl(CL_scale_t(c_y4,C52),1)); - c_y2 = CL_add(c_t,CL_scale_t(c_y2,C53)); + c_y1 = CL_add( c11, c14 ); + c_y4 = CL_sub( c11, c14 ); + c_y3 = CL_add( c12, c13 ); + c_y2 = CL_sub( c12, c13 ); + c_t = CL_scale_t( CL_sub( c_y1, c_y3 ), C54 ); + c_y1 = CL_add( c_y1, c_y3 ); + c_z10 = CL_add( c10, c_y1 ); + c_y1 = CL_add( c_z10, ( CL_shl( CL_scale_t( c_y1, C55 ), 1 ) ) ); + c_y3 = CL_sub( c_y1, c_t ); + c_y1 = CL_add( c_y1, c_t ); + c_t = CL_scale_t( CL_add( c_y4, c_y2 ), C51 ); + c_y4 = CL_add( c_t, CL_shl( CL_scale_t( c_y4, C52 ), 1 ) ); + c_y2 = CL_add( c_t, CL_scale_t( c_y2, C53 ) ); /* combination */ - c_z11 = CL_msu_j(c_y1,c_y2); - c_z12 = CL_mac_j(c_y3,c_y4); - c_z13 = CL_msu_j(c_y3,c_y4); - c_z14 = CL_mac_j(c_y1,c_y2); - + c_z11 = CL_msu_j( c_y1, c_y2 ); + c_z12 = CL_mac_j( c_y3, c_y4 ); + c_z13 = CL_msu_j( c_y3, c_y4 ); + c_z14 = CL_mac_j( c_y1, c_y2 ); /* 1. FFT3 stage */ - c_y1 = CL_add(c_z5,c_z10); - c_y2 = CL_scale_t(CL_sub(c_z5,c_z10),C31); - inp_data[0] = CL_add(c_z0,c_y1); - c_y1 = CL_sub(c_z0,CL_shr(c_y1,1)); - inp_data[10] = CL_mac_j(c_y1,c_y2); - inp_data[5] = CL_msu_j(c_y1,c_y2); + c_y1 = CL_add( c_z5, c_z10 ); + c_y2 = CL_scale_t( CL_sub( c_z5, c_z10 ), C31 ); + inp_data[0] = CL_add( c_z0, c_y1 ); + c_y1 = CL_sub( c_z0, CL_shr( c_y1, 1 ) ); + inp_data[10] = CL_mac_j( c_y1, c_y2 ); + inp_data[5] = CL_msu_j( c_y1, c_y2 ); /* 2. FFT3 stage */ - c_y1 = CL_add(c_z6,c_z11); - c_y2 = CL_scale_t(CL_sub(c_z6,c_z11),C31); - inp_data[6] = CL_add(c_z1,c_y1); - c_y1 = CL_sub(c_z1,CL_shr(c_y1,1)); - inp_data[1] = CL_mac_j(c_y1,c_y2); - inp_data[11] = CL_msu_j(c_y1,c_y2); + c_y1 = CL_add( c_z6, c_z11 ); + c_y2 = CL_scale_t( CL_sub( c_z6, c_z11 ), C31 ); + inp_data[6] = CL_add( c_z1, c_y1 ); + c_y1 = CL_sub( c_z1, CL_shr( c_y1, 1 ) ); + inp_data[1] = CL_mac_j( c_y1, c_y2 ); + inp_data[11] = CL_msu_j( c_y1, c_y2 ); /* 3. FFT3 stage */ - c_y1 = CL_add(c_z7,c_z12); - c_y2 = CL_scale_t(CL_sub(c_z7,c_z12),C31); - inp_data[12] = CL_add(c_z2,c_y1); - c_y1 = CL_sub(c_z2,CL_shr(c_y1,1)); - inp_data[7] = CL_mac_j(c_y1,c_y2); - inp_data[2] = CL_msu_j(c_y1,c_y2); + c_y1 = CL_add( c_z7, c_z12 ); + c_y2 = CL_scale_t( CL_sub( c_z7, c_z12 ), C31 ); + inp_data[12] = CL_add( c_z2, c_y1 ); + c_y1 = CL_sub( c_z2, CL_shr( c_y1, 1 ) ); + inp_data[7] = CL_mac_j( c_y1, c_y2 ); + inp_data[2] = CL_msu_j( c_y1, c_y2 ); /* 4. FFT3 stage */ - c_y1 = CL_add(c_z8,c_z13); - c_y2 = CL_scale_t(CL_sub(c_z8,c_z13),C31); - inp_data[3] = CL_add(c_z3,c_y1); - c_y1 = CL_sub(c_z3,CL_shr(c_y1,1)); - inp_data[13] = CL_mac_j(c_y1,c_y2); - inp_data[8] = CL_msu_j(c_y1,c_y2); + c_y1 = CL_add( c_z8, c_z13 ); + c_y2 = CL_scale_t( CL_sub( c_z8, c_z13 ), C31 ); + inp_data[3] = CL_add( c_z3, c_y1 ); + c_y1 = CL_sub( c_z3, CL_shr( c_y1, 1 ) ); + inp_data[13] = CL_mac_j( c_y1, c_y2 ); + inp_data[8] = CL_msu_j( c_y1, c_y2 ); /* 5. FFT3 stage */ - c_y1 = CL_add(c_z9,c_z14); - c_y2 = CL_scale_t(CL_sub(c_z9,c_z14),C31); - inp_data[9] = CL_add(c_z4,c_y1); - c_y1 = CL_sub(c_z4,CL_shr(c_y1,1)); - inp_data[4] = CL_mac_j(c_y1,c_y2); - inp_data[14] = CL_msu_j(c_y1,c_y2); - -#if (WMOPS) + c_y1 = CL_add( c_z9, c_z14 ); + c_y2 = CL_scale_t( CL_sub( c_z9, c_z14 ), C31 ); + inp_data[9] = CL_add( c_z4, c_y1 ); + c_y1 = CL_sub( c_z4, CL_shr( c_y1, 1 ) ); + inp_data[4] = CL_mac_j( c_y1, c_y2 ); + inp_data[14] = CL_msu_j( c_y1, c_y2 ); + +#if ( WMOPS ) multiCounter[currCounter].CL_move += 15; -#endif - +#endif } @@ -544,222 +538,220 @@ static void fft15_with_cmplx_data(cmplx *inp_data) * * \return void */ -void fft16(Word32 *re, Word32 *im, Word16 s, Word16 bScale) +void fft16( Word32 *re, Word32 *im, Word16 s, Word16 bScale ) { - int i; + int i; if ( s == 2 ) { - fft16_with_cmplx_data( (cmplx *) re, bScale ); + fft16_with_cmplx_data( (cmplx *) re, bScale ); } else { cmplx inp_data[16]; - FOR(i=0; i<16; i++) - { - inp_data[i] = CL_form(re[s*i], im[s*i]); - } - fft16_with_cmplx_data(inp_data, bScale ); - FOR(i=0; i<16; i++) - { - re[s*i] = CL_Extract_real(inp_data[i]); - im[s*i] = CL_Extract_imag(inp_data[i]); - } + FOR( i = 0; i < 16; i++ ) + { + inp_data[i] = CL_form( re[s * i], im[s * i] ); + } + fft16_with_cmplx_data( inp_data, bScale ); + FOR( i = 0; i < 16; i++ ) + { + re[s * i] = CL_Extract_real( inp_data[i] ); + im[s * i] = CL_Extract_imag( inp_data[i] ); + } } } -void fft16_with_cmplx_data(cmplx *input, Word16 bScale ) +void fft16_with_cmplx_data( cmplx *input, Word16 bScale ) { cmplx x0, x1, x2, x3, temp; - cmplx t0,t2,t4,t6,t7; + cmplx t0, t2, t4, t6, t7; cmplx y[16]; - IF (bScale) + IF( bScale ) { { - x0 = CL_shr(input[0],SCALEFACTOR16); - x1 = CL_shr(input[4],SCALEFACTOR16); - x2 = CL_shr(input[8],SCALEFACTOR16); - x3 = CL_shr(input[12],SCALEFACTOR16); - t0 = CL_add(x0,x2); - t2 = CL_sub(x0,x2); - t4 = CL_add(x1,x3); - t6 = CL_sub(x1,x3); - t6 = CL_mul_j(t6); - y[0] = CL_add(t0,t4); - y[1] = CL_sub(t2,t6); - y[2] = CL_sub(t0,t4); - y[3] = CL_add(t2,t6); - - - x0 = CL_shr(input[1],SCALEFACTOR16); - x1 = CL_shr(input[5],SCALEFACTOR16); - x2 = CL_shr(input[9],SCALEFACTOR16); - x3 = CL_shr(input[13],SCALEFACTOR16); - t0 = CL_add(x0,x2); - t2 = CL_sub(x0,x2); - t4 = CL_add(x1,x3); - t6 = CL_sub(x1,x3); - t6 = CL_mul_j(t6); - y[4] = CL_add(t0,t4); - y[5] = CL_sub(t2,t6); - y[6] = CL_sub(t0,t4); - y[7] = CL_add(t2,t6); - - - x0 = CL_shr(input[2],SCALEFACTOR16); - x1 = CL_shr(input[6],SCALEFACTOR16); - x2 = CL_shr(input[10],SCALEFACTOR16); - x3 = CL_shr(input[14],SCALEFACTOR16); - t0 = CL_add(x0,x2); - t2 = CL_sub(x0,x2); - t4 = CL_add(x1,x3); - t6 = CL_sub(x1,x3); - t6 = CL_mul_j(t6); - y[8] = CL_add(t0,t4); - y[9] = CL_sub(t2,t6); - y[10] = CL_sub(t4,t0); - y[10] = CL_mul_j(y[10]); - y[11] = CL_add(t2,t6); - - - x0 = CL_shr(input[3],SCALEFACTOR16); - x1 = CL_shr(input[7],SCALEFACTOR16); - x2 = CL_shr(input[11],SCALEFACTOR16); - x3 = CL_shr(input[15],SCALEFACTOR16); - t0 = CL_add(x0,x2); - t2 = CL_sub(x0,x2); - t4 = CL_add(x1,x3); - t6 = CL_sub(x1,x3); - t6 = CL_mul_j(t6); - y[12] = CL_add(t0,t4); - y[13] = CL_sub(t2,t6); - y[14] = CL_sub(t0,t4); - y[15] = CL_add(t2,t6); + x0 = CL_shr( input[0], SCALEFACTOR16 ); + x1 = CL_shr( input[4], SCALEFACTOR16 ); + x2 = CL_shr( input[8], SCALEFACTOR16 ); + x3 = CL_shr( input[12], SCALEFACTOR16 ); + t0 = CL_add( x0, x2 ); + t2 = CL_sub( x0, x2 ); + t4 = CL_add( x1, x3 ); + t6 = CL_sub( x1, x3 ); + t6 = CL_mul_j( t6 ); + y[0] = CL_add( t0, t4 ); + y[1] = CL_sub( t2, t6 ); + y[2] = CL_sub( t0, t4 ); + y[3] = CL_add( t2, t6 ); + + + x0 = CL_shr( input[1], SCALEFACTOR16 ); + x1 = CL_shr( input[5], SCALEFACTOR16 ); + x2 = CL_shr( input[9], SCALEFACTOR16 ); + x3 = CL_shr( input[13], SCALEFACTOR16 ); + t0 = CL_add( x0, x2 ); + t2 = CL_sub( x0, x2 ); + t4 = CL_add( x1, x3 ); + t6 = CL_sub( x1, x3 ); + t6 = CL_mul_j( t6 ); + y[4] = CL_add( t0, t4 ); + y[5] = CL_sub( t2, t6 ); + y[6] = CL_sub( t0, t4 ); + y[7] = CL_add( t2, t6 ); + + + x0 = CL_shr( input[2], SCALEFACTOR16 ); + x1 = CL_shr( input[6], SCALEFACTOR16 ); + x2 = CL_shr( input[10], SCALEFACTOR16 ); + x3 = CL_shr( input[14], SCALEFACTOR16 ); + t0 = CL_add( x0, x2 ); + t2 = CL_sub( x0, x2 ); + t4 = CL_add( x1, x3 ); + t6 = CL_sub( x1, x3 ); + t6 = CL_mul_j( t6 ); + y[8] = CL_add( t0, t4 ); + y[9] = CL_sub( t2, t6 ); + y[10] = CL_sub( t4, t0 ); + y[10] = CL_mul_j( y[10] ); + y[11] = CL_add( t2, t6 ); + + + x0 = CL_shr( input[3], SCALEFACTOR16 ); + x1 = CL_shr( input[7], SCALEFACTOR16 ); + x2 = CL_shr( input[11], SCALEFACTOR16 ); + x3 = CL_shr( input[15], SCALEFACTOR16 ); + t0 = CL_add( x0, x2 ); + t2 = CL_sub( x0, x2 ); + t4 = CL_add( x1, x3 ); + t6 = CL_sub( x1, x3 ); + t6 = CL_mul_j( t6 ); + y[12] = CL_add( t0, t4 ); + y[13] = CL_sub( t2, t6 ); + y[14] = CL_sub( t0, t4 ); + y[15] = CL_add( t2, t6 ); } } else { { - t0 = CL_add(input[ 0],input[ 8]); - t2 = CL_sub(input[ 0],input[ 8]); - t4 = CL_add(input[ 4],input[12]); - t7 = CL_sub(input[ 4],input[12]); - - y[0] = CL_add(t0,t4); - y[1] = CL_msu_j(t2,t7); - y[2] = CL_sub(t0,t4); - y[3] = CL_mac_j(t2,t7); + t0 = CL_add( input[0], input[8] ); + t2 = CL_sub( input[0], input[8] ); + t4 = CL_add( input[4], input[12] ); + t7 = CL_sub( input[4], input[12] ); + + y[0] = CL_add( t0, t4 ); + y[1] = CL_msu_j( t2, t7 ); + y[2] = CL_sub( t0, t4 ); + y[3] = CL_mac_j( t2, t7 ); } /* i=1 */ { - t0 = CL_add(input[ 1],input[ 9]); - t2 = CL_sub(input[ 1],input[ 9]); - t4 = CL_add(input[ 5],input[13]); - t7 = CL_sub(input[ 5],input[13]); - - y[4] = CL_add(t0,t4); - y[5] = CL_msu_j(t2,t7); - y[6] = CL_sub(t0,t4); - y[7] = CL_mac_j(t2,t7); + t0 = CL_add( input[1], input[9] ); + t2 = CL_sub( input[1], input[9] ); + t4 = CL_add( input[5], input[13] ); + t7 = CL_sub( input[5], input[13] ); + + y[4] = CL_add( t0, t4 ); + y[5] = CL_msu_j( t2, t7 ); + y[6] = CL_sub( t0, t4 ); + y[7] = CL_mac_j( t2, t7 ); } /* i=2 */ { - t0 = CL_add(input[ 2],input[ 10]); - t2 = CL_sub(input[ 2],input[ 10]); - t4 = CL_add(input[ 6],input[14]); - t7 = CL_sub(input[ 6],input[14]); - - y[8] = CL_add(t0,t4); - y[9] = CL_msu_j(t2,t7); - temp = CL_sub(t0,t4); - y[10] = CL_negate(CL_mul_j(temp)); - y[11] = CL_mac_j(t2,t7); + t0 = CL_add( input[2], input[10] ); + t2 = CL_sub( input[2], input[10] ); + t4 = CL_add( input[6], input[14] ); + t7 = CL_sub( input[6], input[14] ); + + y[8] = CL_add( t0, t4 ); + y[9] = CL_msu_j( t2, t7 ); + temp = CL_sub( t0, t4 ); + y[10] = CL_negate( CL_mul_j( temp ) ); + y[11] = CL_mac_j( t2, t7 ); } /* i=3 */ { - t0 = CL_add(input[ 3],input[ 11]); - t2 = CL_sub(input[ 3],input[ 11]); - t4 = CL_add(input[ 7],input[15]); - t7 = CL_sub(input[ 7],input[15]); - - y[12] = CL_add(t0,t4); - y[13] = CL_msu_j(t2,t7); - y[14] = CL_sub(t0,t4); - y[15] = CL_mac_j(t2,t7); + t0 = CL_add( input[3], input[11] ); + t2 = CL_sub( input[3], input[11] ); + t4 = CL_add( input[7], input[15] ); + t7 = CL_sub( input[7], input[15] ); + + y[12] = CL_add( t0, t4 ); + y[13] = CL_msu_j( t2, t7 ); + y[14] = CL_sub( t0, t4 ); + y[15] = CL_mac_j( t2, t7 ); } - } - x0 = CL_scale_t(y[11],C162); - y[11] = CL_mac_j(x0,x0); + x0 = CL_scale_t( y[11], C162 ); + y[11] = CL_mac_j( x0, x0 ); - x0 = CL_scale_t(y[14],C162); - y[14] = CL_mac_j(x0,x0); + x0 = CL_scale_t( y[14], C162 ); + y[14] = CL_mac_j( x0, x0 ); - x0 = CL_scale_t(y[6],C161); - y[6] = CL_msu_j(x0,x0); + x0 = CL_scale_t( y[6], C161 ); + y[6] = CL_msu_j( x0, x0 ); - x0 = CL_scale_t(y[9],C161); - y[9] = CL_msu_j(x0,x0); + x0 = CL_scale_t( y[9], C161 ); + y[9] = CL_msu_j( x0, x0 ); - y[5] = CL_mac_j(CL_scale_t(y[5], C163), CL_scale_t(y[5], C166)); - y[7] = CL_mac_j(CL_scale_t(y[7], C165), CL_scale_t(y[7], C164)); - y[13] = CL_mac_j(CL_scale_t(y[13], C165), CL_scale_t(y[13], C164)); - y[15] = CL_mac_j(CL_scale_t(y[15], C164), CL_scale_t(y[15], C165)); + y[5] = CL_mac_j( CL_scale_t( y[5], C163 ), CL_scale_t( y[5], C166 ) ); + y[7] = CL_mac_j( CL_scale_t( y[7], C165 ), CL_scale_t( y[7], C164 ) ); + y[13] = CL_mac_j( CL_scale_t( y[13], C165 ), CL_scale_t( y[13], C164 ) ); + y[15] = CL_mac_j( CL_scale_t( y[15], C164 ), CL_scale_t( y[15], C165 ) ); /* i=0 */ { - t0 = CL_add(y[ 0],y[ 8]); - t2 = CL_sub(y[ 0],y[ 8]); - t4 = CL_add(y[ 4],y[12]); - t7 = CL_sub(y[ 4],y[12]); - - input[0] = CL_add(t0,t4); - input[4] = CL_msu_j(t2,t7); - input[8] = CL_sub(t0,t4); - input[12] = CL_mac_j(t2,t7); + t0 = CL_add( y[0], y[8] ); + t2 = CL_sub( y[0], y[8] ); + t4 = CL_add( y[4], y[12] ); + t7 = CL_sub( y[4], y[12] ); + + input[0] = CL_add( t0, t4 ); + input[4] = CL_msu_j( t2, t7 ); + input[8] = CL_sub( t0, t4 ); + input[12] = CL_mac_j( t2, t7 ); } /* i=1 */ { - t0 = CL_add(y[ 1],y[ 9]); - t2 = CL_sub(y[ 1],y[ 9]); - t4 = CL_add(y[ 5],y[13]); - t7 = CL_sub(y[ 5],y[13]); - - input[1] = CL_add(t0,t4); - input[5] = CL_msu_j(t2,t7); - input[9] = CL_sub(t0,t4); - input[13] = CL_mac_j(t2,t7); + t0 = CL_add( y[1], y[9] ); + t2 = CL_sub( y[1], y[9] ); + t4 = CL_add( y[5], y[13] ); + t7 = CL_sub( y[5], y[13] ); + + input[1] = CL_add( t0, t4 ); + input[5] = CL_msu_j( t2, t7 ); + input[9] = CL_sub( t0, t4 ); + input[13] = CL_mac_j( t2, t7 ); } /* i=2 */ { - t0 = CL_add(y[ 2],y[ 10]); - t2 = CL_sub(y[ 2],y[ 10]); - t4 = CL_add(y[ 6],y[14]); - t7 = CL_sub(y[ 6],y[14]); - - input[2] = CL_add(t0,t4); - input[6] = CL_msu_j(t2,t7); - input[10] = CL_sub(t0,t4); - input[14] = CL_mac_j(t2,t7); + t0 = CL_add( y[2], y[10] ); + t2 = CL_sub( y[2], y[10] ); + t4 = CL_add( y[6], y[14] ); + t7 = CL_sub( y[6], y[14] ); + + input[2] = CL_add( t0, t4 ); + input[6] = CL_msu_j( t2, t7 ); + input[10] = CL_sub( t0, t4 ); + input[14] = CL_mac_j( t2, t7 ); } /* i=3 */ { - t0 = CL_add(y[ 3],y[ 11]); - t2 = CL_sub(y[ 3],y[ 11]); - t4 = CL_add(y[ 7],y[15]); - t7 = CL_sub(y[ 7],y[15]); - - input[3] = CL_add(t0,t4); - input[7] = CL_msu_j(t2,t7); - input[11] = CL_sub(t0,t4); - input[15] = CL_mac_j(t2,t7); + t0 = CL_add( y[3], y[11] ); + t2 = CL_sub( y[3], y[11] ); + t4 = CL_add( y[7], y[15] ); + t7 = CL_sub( y[7], y[15] ); + + input[3] = CL_add( t0, t4 ); + input[7] = CL_msu_j( t2, t7 ); + input[11] = CL_sub( t0, t4 ); + input[15] = CL_mac_j( t2, t7 ); } -#if (WMOPS) +#if ( WMOPS ) multiCounter[currCounter].CL_move += 16; -#endif - +#endif } @@ -776,131 +768,131 @@ void fft16_with_cmplx_data(cmplx *input, Word16 bScale ) * * \return void */ -static void fft20_with_cmplx_data(cmplx *inp_data) +static void fft20_with_cmplx_data( cmplx *inp_data ) { - cmplx r1,r2,r3,r4; - cmplx x0,x1,x2,x3,x4; - cmplx t,t0,t1,t2,t3; + cmplx r1, r2, r3, r4; + cmplx x0, x1, x2, x3, x4; + cmplx t, t0, t1, t2, t3; cmplx y[20]; - cmplx *y0, *y1,*y2,*y3,*y4; + cmplx *y0, *y1, *y2, *y3, *y4; - y0 = y; + y0 = y; y1 = &y[4]; y2 = &y[16]; y3 = &y[8]; y4 = &y[12]; { - x0 = CL_shr(inp_data[0],SCALEFACTOR20); - x1 = CL_shr(inp_data[16],SCALEFACTOR20); - x2 = CL_shr(inp_data[12],SCALEFACTOR20); - x3 = CL_shr(inp_data[8],SCALEFACTOR20); - x4 = CL_shr(inp_data[4],SCALEFACTOR20); - - r4 = CL_sub(x1,x4); - r2 = CL_sub(x2,x3); - r1 = CL_add(x1,x4); - r3 = CL_add(x2,x3); - t = CL_scale_t(CL_sub(r1,r3),C54); - r1 = CL_add(r1,r3); - y0[0] = CL_add(x0,r1); - r1 = CL_add(y0[0],(CL_shl(CL_scale_t(r1,C55),1))); - r3 = CL_sub(r1,t); - r1 = CL_add(r1,t); - t = CL_scale_t((CL_add(r4,r2)),C51); - r4 = CL_add(t,CL_shl(CL_scale_t(r4, C52),1)); - r2 = CL_add(t,CL_scale_t(r2,C53)); - - - y1[0] = CL_msu_j(r1,r2); - y2[0] = CL_mac_j(r1,r2); - y3[0] = CL_mac_j(r3,r4); - y4[0] = CL_msu_j(r3,r4); + x0 = CL_shr( inp_data[0], SCALEFACTOR20 ); + x1 = CL_shr( inp_data[16], SCALEFACTOR20 ); + x2 = CL_shr( inp_data[12], SCALEFACTOR20 ); + x3 = CL_shr( inp_data[8], SCALEFACTOR20 ); + x4 = CL_shr( inp_data[4], SCALEFACTOR20 ); + + r4 = CL_sub( x1, x4 ); + r2 = CL_sub( x2, x3 ); + r1 = CL_add( x1, x4 ); + r3 = CL_add( x2, x3 ); + t = CL_scale_t( CL_sub( r1, r3 ), C54 ); + r1 = CL_add( r1, r3 ); + y0[0] = CL_add( x0, r1 ); + r1 = CL_add( y0[0], ( CL_shl( CL_scale_t( r1, C55 ), 1 ) ) ); + r3 = CL_sub( r1, t ); + r1 = CL_add( r1, t ); + t = CL_scale_t( ( CL_add( r4, r2 ) ), C51 ); + r4 = CL_add( t, CL_shl( CL_scale_t( r4, C52 ), 1 ) ); + r2 = CL_add( t, CL_scale_t( r2, C53 ) ); + + + y1[0] = CL_msu_j( r1, r2 ); + y2[0] = CL_mac_j( r1, r2 ); + y3[0] = CL_mac_j( r3, r4 ); + y4[0] = CL_msu_j( r3, r4 ); } { - x0 = CL_shr(inp_data[5],SCALEFACTOR20); - x1 = CL_shr(inp_data[1],SCALEFACTOR20); - x2 = CL_shr(inp_data[17],SCALEFACTOR20); - x3 = CL_shr(inp_data[13],SCALEFACTOR20); - x4 = CL_shr(inp_data[9],SCALEFACTOR20); - - r4 = CL_sub(x1,x4); - r2 = CL_sub(x2,x3); - r1 = CL_add(x1,x4); - r3 = CL_add(x2,x3); - t = CL_scale_t(CL_sub(r1,r3),C54); - r1 = CL_add(r1,r3); - y0[1] = CL_add(x0,r1); - r1 = CL_add(y0[1],(CL_shl(CL_scale_t(r1,C55),1))); - r3 = CL_sub(r1,t); - r1 = CL_add(r1,t); - t = CL_scale_t((CL_add(r4,r2)),C51); - r4 = CL_add(t,CL_shl(CL_scale_t(r4, C52),1)); - r2 = CL_add(t,CL_scale_t(r2,C53)); - - - y1[1] = CL_msu_j(r1,r2); - y2[1] = CL_mac_j(r1,r2); - y3[1] = CL_mac_j(r3,r4); - y4[1] = CL_msu_j(r3,r4); + x0 = CL_shr( inp_data[5], SCALEFACTOR20 ); + x1 = CL_shr( inp_data[1], SCALEFACTOR20 ); + x2 = CL_shr( inp_data[17], SCALEFACTOR20 ); + x3 = CL_shr( inp_data[13], SCALEFACTOR20 ); + x4 = CL_shr( inp_data[9], SCALEFACTOR20 ); + + r4 = CL_sub( x1, x4 ); + r2 = CL_sub( x2, x3 ); + r1 = CL_add( x1, x4 ); + r3 = CL_add( x2, x3 ); + t = CL_scale_t( CL_sub( r1, r3 ), C54 ); + r1 = CL_add( r1, r3 ); + y0[1] = CL_add( x0, r1 ); + r1 = CL_add( y0[1], ( CL_shl( CL_scale_t( r1, C55 ), 1 ) ) ); + r3 = CL_sub( r1, t ); + r1 = CL_add( r1, t ); + t = CL_scale_t( ( CL_add( r4, r2 ) ), C51 ); + r4 = CL_add( t, CL_shl( CL_scale_t( r4, C52 ), 1 ) ); + r2 = CL_add( t, CL_scale_t( r2, C53 ) ); + + + y1[1] = CL_msu_j( r1, r2 ); + y2[1] = CL_mac_j( r1, r2 ); + y3[1] = CL_mac_j( r3, r4 ); + y4[1] = CL_msu_j( r3, r4 ); } { - x0 = CL_shr(inp_data[10],SCALEFACTOR20); - x1 = CL_shr(inp_data[6],SCALEFACTOR20); - x2 = CL_shr(inp_data[2],SCALEFACTOR20); - x3 = CL_shr(inp_data[18],SCALEFACTOR20); - x4 = CL_shr(inp_data[14],SCALEFACTOR20); - - r4 = CL_sub(x1,x4); - r2 = CL_sub(x2,x3); - r1 = CL_add(x1,x4); - r3 = CL_add(x2,x3); - t = CL_scale_t(CL_sub(r1,r3),C54); - r1 = CL_add(r1,r3); - y0[2] = CL_add(x0,r1); - r1 = CL_add(y0[2],(CL_shl(CL_scale_t(r1,C55),1))); - r3 = CL_sub(r1,t); - r1 = CL_add(r1,t); - t = CL_scale_t((CL_add(r4,r2)),C51); - r4 = CL_add(t,CL_shl(CL_scale_t(r4, C52),1)); - r2 = CL_add(t,CL_scale_t(r2,C53)); - - - y1[2] = CL_msu_j(r1,r2); - y2[2] = CL_mac_j(r1,r2); - y3[2] = CL_mac_j(r3,r4); - y4[2] = CL_msu_j(r3,r4); + x0 = CL_shr( inp_data[10], SCALEFACTOR20 ); + x1 = CL_shr( inp_data[6], SCALEFACTOR20 ); + x2 = CL_shr( inp_data[2], SCALEFACTOR20 ); + x3 = CL_shr( inp_data[18], SCALEFACTOR20 ); + x4 = CL_shr( inp_data[14], SCALEFACTOR20 ); + + r4 = CL_sub( x1, x4 ); + r2 = CL_sub( x2, x3 ); + r1 = CL_add( x1, x4 ); + r3 = CL_add( x2, x3 ); + t = CL_scale_t( CL_sub( r1, r3 ), C54 ); + r1 = CL_add( r1, r3 ); + y0[2] = CL_add( x0, r1 ); + r1 = CL_add( y0[2], ( CL_shl( CL_scale_t( r1, C55 ), 1 ) ) ); + r3 = CL_sub( r1, t ); + r1 = CL_add( r1, t ); + t = CL_scale_t( ( CL_add( r4, r2 ) ), C51 ); + r4 = CL_add( t, CL_shl( CL_scale_t( r4, C52 ), 1 ) ); + r2 = CL_add( t, CL_scale_t( r2, C53 ) ); + + + y1[2] = CL_msu_j( r1, r2 ); + y2[2] = CL_mac_j( r1, r2 ); + y3[2] = CL_mac_j( r3, r4 ); + y4[2] = CL_msu_j( r3, r4 ); } { - x0 = CL_shr(inp_data[15],SCALEFACTOR20); - x1 = CL_shr(inp_data[11],SCALEFACTOR20); - x2 = CL_shr(inp_data[7],SCALEFACTOR20); - x3 = CL_shr(inp_data[3],SCALEFACTOR20); - x4 = CL_shr(inp_data[19],SCALEFACTOR20); - - r4 = CL_sub(x1,x4); - r2 = CL_sub(x2,x3); - r1 = CL_add(x1,x4); - r3 = CL_add(x2,x3); - t = CL_scale_t(CL_sub(r1,r3),C54); - r1 = CL_add(r1,r3); - y0[3] = CL_add(x0,r1); - r1 = CL_add(y0[3],(CL_shl(CL_scale_t(r1,C55),1))); - r3 = CL_sub(r1,t); - r1 = CL_add(r1,t); - t = CL_scale_t((CL_add(r4,r2)),C51); - r4 = CL_add(t,CL_shl(CL_scale_t(r4, C52),1)); - r2 = CL_add(t,CL_scale_t(r2,C53)); - - - y1[3] = CL_msu_j(r1,r2); - y2[3] = CL_mac_j(r1,r2); - y3[3] = CL_mac_j(r3,r4); - y4[3] = CL_msu_j(r3,r4); + x0 = CL_shr( inp_data[15], SCALEFACTOR20 ); + x1 = CL_shr( inp_data[11], SCALEFACTOR20 ); + x2 = CL_shr( inp_data[7], SCALEFACTOR20 ); + x3 = CL_shr( inp_data[3], SCALEFACTOR20 ); + x4 = CL_shr( inp_data[19], SCALEFACTOR20 ); + + r4 = CL_sub( x1, x4 ); + r2 = CL_sub( x2, x3 ); + r1 = CL_add( x1, x4 ); + r3 = CL_add( x2, x3 ); + t = CL_scale_t( CL_sub( r1, r3 ), C54 ); + r1 = CL_add( r1, r3 ); + y0[3] = CL_add( x0, r1 ); + r1 = CL_add( y0[3], ( CL_shl( CL_scale_t( r1, C55 ), 1 ) ) ); + r3 = CL_sub( r1, t ); + r1 = CL_add( r1, t ); + t = CL_scale_t( ( CL_add( r4, r2 ) ), C51 ); + r4 = CL_add( t, CL_shl( CL_scale_t( r4, C52 ), 1 ) ); + r2 = CL_add( t, CL_scale_t( r2, C53 ) ); + + + y1[3] = CL_msu_j( r1, r2 ); + y2[3] = CL_mac_j( r1, r2 ); + y3[3] = CL_mac_j( r3, r4 ); + y4[3] = CL_msu_j( r3, r4 ); } { - cmplx * ptr_y = y; + cmplx *ptr_y = y; { cmplx Cy0, Cy1, Cy2, Cy3; @@ -910,16 +902,16 @@ static void fft20_with_cmplx_data(cmplx *inp_data) Cy3 = *ptr_y++; /* Pre-additions */ - t0 = CL_add(Cy0,Cy2); - t1 = CL_sub(Cy0,Cy2); - t2 = CL_add(Cy1,Cy3); - t3 = CL_sub(Cy1,Cy3); + t0 = CL_add( Cy0, Cy2 ); + t1 = CL_sub( Cy0, Cy2 ); + t2 = CL_add( Cy1, Cy3 ); + t3 = CL_sub( Cy1, Cy3 ); - inp_data[0] = CL_add(t0,t2); - inp_data[5] = CL_msu_j(t1,t3); - inp_data[10] = CL_sub(t0,t2); - inp_data[15] = CL_mac_j(t1,t3); + inp_data[0] = CL_add( t0, t2 ); + inp_data[5] = CL_msu_j( t1, t3 ); + inp_data[10] = CL_sub( t0, t2 ); + inp_data[15] = CL_mac_j( t1, t3 ); } { @@ -931,16 +923,16 @@ static void fft20_with_cmplx_data(cmplx *inp_data) Cy3 = *ptr_y++; /* Pre-additions */ - t0 = CL_add(Cy0,Cy2); - t1 = CL_sub(Cy0,Cy2); - t2 = CL_add(Cy1,Cy3); - t3 = CL_sub(Cy1,Cy3); + t0 = CL_add( Cy0, Cy2 ); + t1 = CL_sub( Cy0, Cy2 ); + t2 = CL_add( Cy1, Cy3 ); + t3 = CL_sub( Cy1, Cy3 ); - inp_data[4] = CL_add(t0,t2); - inp_data[9] = CL_msu_j(t1,t3); - inp_data[14] = CL_sub(t0,t2); - inp_data[19] = CL_mac_j(t1,t3); + inp_data[4] = CL_add( t0, t2 ); + inp_data[9] = CL_msu_j( t1, t3 ); + inp_data[14] = CL_sub( t0, t2 ); + inp_data[19] = CL_mac_j( t1, t3 ); } { @@ -952,16 +944,16 @@ static void fft20_with_cmplx_data(cmplx *inp_data) Cy3 = *ptr_y++; /* Pre-additions */ - t0 = CL_add(Cy0,Cy2); - t1 = CL_sub(Cy0,Cy2); - t2 = CL_add(Cy1,Cy3); - t3 = CL_sub(Cy1,Cy3); + t0 = CL_add( Cy0, Cy2 ); + t1 = CL_sub( Cy0, Cy2 ); + t2 = CL_add( Cy1, Cy3 ); + t3 = CL_sub( Cy1, Cy3 ); - inp_data[8] = CL_add(t0,t2); - inp_data[13] = CL_msu_j(t1,t3); - inp_data[18] = CL_sub(t0,t2); - inp_data[3] = CL_mac_j(t1,t3); + inp_data[8] = CL_add( t0, t2 ); + inp_data[13] = CL_msu_j( t1, t3 ); + inp_data[18] = CL_sub( t0, t2 ); + inp_data[3] = CL_mac_j( t1, t3 ); } { @@ -973,15 +965,15 @@ static void fft20_with_cmplx_data(cmplx *inp_data) Cy3 = *ptr_y++; /* Pre-additions */ - t0 = CL_add(Cy0,Cy2); - t1 = CL_sub(Cy0,Cy2); - t2 = CL_add(Cy1,Cy3); - t3 = CL_sub(Cy1,Cy3); - - inp_data[12] = CL_add(t0,t2); - inp_data[17] = CL_msu_j(t1,t3); - inp_data[2] = CL_sub(t0,t2); - inp_data[7] = CL_mac_j(t1,t3); + t0 = CL_add( Cy0, Cy2 ); + t1 = CL_sub( Cy0, Cy2 ); + t2 = CL_add( Cy1, Cy3 ); + t3 = CL_sub( Cy1, Cy3 ); + + inp_data[12] = CL_add( t0, t2 ); + inp_data[17] = CL_msu_j( t1, t3 ); + inp_data[2] = CL_sub( t0, t2 ); + inp_data[7] = CL_mac_j( t1, t3 ); } { @@ -993,22 +985,21 @@ static void fft20_with_cmplx_data(cmplx *inp_data) Cy3 = *ptr_y++; /* Pre-additions */ - t0 = CL_add(Cy0,Cy2); - t1 = CL_sub(Cy0,Cy2); - t2 = CL_add(Cy1,Cy3); - t3 = CL_sub(Cy1,Cy3); + t0 = CL_add( Cy0, Cy2 ); + t1 = CL_sub( Cy0, Cy2 ); + t2 = CL_add( Cy1, Cy3 ); + t3 = CL_sub( Cy1, Cy3 ); - inp_data[16] = CL_add(t0,t2); - inp_data[1] = CL_msu_j(t1,t3); - inp_data[6] = CL_sub(t0,t2); - inp_data[11] = CL_mac_j(t1,t3); + inp_data[16] = CL_add( t0, t2 ); + inp_data[1] = CL_msu_j( t1, t3 ); + inp_data[6] = CL_sub( t0, t2 ); + inp_data[11] = CL_mac_j( t1, t3 ); } } -#if (WMOPS) +#if ( WMOPS ) multiCounter[currCounter].CL_move += 20; -#endif - +#endif } @@ -1026,98 +1017,98 @@ static void fft20_with_cmplx_data(cmplx *inp_data) * \return void */ -static void fft30_with_cmplx_data(cmplx * inp) +static void fft30_with_cmplx_data( cmplx *inp ) { - cmplx *l = &inp[0]; - cmplx *h = &inp[15]; + cmplx *l = &inp[0]; + cmplx *h = &inp[15]; cmplx z[30], y[15], x[15], rs1, rs2, rs3, rs4, t; /* 1. FFT15 stage */ - x[0] = CL_shr(inp[0],SCALEFACTOR30_1); - x[1] = CL_shr(inp[18],SCALEFACTOR30_1); - x[2] = CL_shr(inp[6],SCALEFACTOR30_1); - x[3] = CL_shr(inp[24],SCALEFACTOR30_1); - x[4] = CL_shr(inp[12],SCALEFACTOR30_1); + x[0] = CL_shr( inp[0], SCALEFACTOR30_1 ); + x[1] = CL_shr( inp[18], SCALEFACTOR30_1 ); + x[2] = CL_shr( inp[6], SCALEFACTOR30_1 ); + x[3] = CL_shr( inp[24], SCALEFACTOR30_1 ); + x[4] = CL_shr( inp[12], SCALEFACTOR30_1 ); - x[5] = CL_shr(inp[20],SCALEFACTOR30_1); - x[6] = CL_shr(inp[8],SCALEFACTOR30_1); - x[7] = CL_shr(inp[26],SCALEFACTOR30_1); - x[8] = CL_shr(inp[14],SCALEFACTOR30_1); - x[9] = CL_shr(inp[2],SCALEFACTOR30_1); + x[5] = CL_shr( inp[20], SCALEFACTOR30_1 ); + x[6] = CL_shr( inp[8], SCALEFACTOR30_1 ); + x[7] = CL_shr( inp[26], SCALEFACTOR30_1 ); + x[8] = CL_shr( inp[14], SCALEFACTOR30_1 ); + x[9] = CL_shr( inp[2], SCALEFACTOR30_1 ); - x[10] = CL_shr(inp[10],SCALEFACTOR30_1); - x[11] = CL_shr(inp[28],SCALEFACTOR30_1); - x[12] = CL_shr(inp[16],SCALEFACTOR30_1); - x[13] = CL_shr(inp[4],SCALEFACTOR30_1); - x[14] = CL_shr(inp[22],SCALEFACTOR30_1); + x[10] = CL_shr( inp[10], SCALEFACTOR30_1 ); + x[11] = CL_shr( inp[28], SCALEFACTOR30_1 ); + x[12] = CL_shr( inp[16], SCALEFACTOR30_1 ); + x[13] = CL_shr( inp[4], SCALEFACTOR30_1 ); + x[14] = CL_shr( inp[22], SCALEFACTOR30_1 ); /* 1. FFT5 stage */ - rs1 = CL_add(x[1],x[4]); - rs4 = CL_sub(x[1],x[4]); - rs3 = CL_add(x[2],x[3]); - rs2 = CL_sub(x[2],x[3]); - t = CL_scale_t(CL_sub(rs1,rs3),C54); - rs1 = CL_add(rs1,rs3); - y[0] = CL_add(x[0],rs1); - rs1 = CL_add(y[0],(CL_shl(CL_scale_t(rs1,C55),1))); - rs3 = CL_sub(rs1,t); - rs1 = CL_add(rs1,t); - t = CL_scale_t(CL_add(rs4,rs2),C51); - rs4 = CL_add(t,CL_shl(CL_scale_t(rs4, C52),1)); - rs2 = CL_add(t,CL_scale_t(rs2,C53)); + rs1 = CL_add( x[1], x[4] ); + rs4 = CL_sub( x[1], x[4] ); + rs3 = CL_add( x[2], x[3] ); + rs2 = CL_sub( x[2], x[3] ); + t = CL_scale_t( CL_sub( rs1, rs3 ), C54 ); + rs1 = CL_add( rs1, rs3 ); + y[0] = CL_add( x[0], rs1 ); + rs1 = CL_add( y[0], ( CL_shl( CL_scale_t( rs1, C55 ), 1 ) ) ); + rs3 = CL_sub( rs1, t ); + rs1 = CL_add( rs1, t ); + t = CL_scale_t( CL_add( rs4, rs2 ), C51 ); + rs4 = CL_add( t, CL_shl( CL_scale_t( rs4, C52 ), 1 ) ); + rs2 = CL_add( t, CL_scale_t( rs2, C53 ) ); /* combination */ - y[1] = CL_msu_j(rs1,rs2); - y[4] = CL_mac_j(rs1,rs2); - y[2] = CL_mac_j(rs3,rs4); - y[3] = CL_msu_j(rs3,rs4); + y[1] = CL_msu_j( rs1, rs2 ); + y[4] = CL_mac_j( rs1, rs2 ); + y[2] = CL_mac_j( rs3, rs4 ); + y[3] = CL_msu_j( rs3, rs4 ); /* 2. FFT5 stage */ - rs1 = CL_add(x[6],x[9]); - rs4 = CL_sub(x[6],x[9]); - rs3 = CL_add(x[7],x[8]); - rs2 = CL_sub(x[7],x[8]); - t = CL_scale_t(CL_sub(rs1,rs3),C54); - rs1 = CL_add(rs1,rs3); - y[5] = CL_add(x[5],rs1); - rs1 = CL_add(y[5],(CL_shl(CL_scale_t(rs1,C55),1))); - rs3 = CL_sub(rs1,t); - rs1 = CL_add(rs1,t); - t = CL_scale_t(CL_add(rs4,rs2),C51); - rs4 = CL_add(t,CL_shl(CL_scale_t(rs4, C52),1)); - rs2 = CL_add(t,CL_scale_t(rs2,C53)); + rs1 = CL_add( x[6], x[9] ); + rs4 = CL_sub( x[6], x[9] ); + rs3 = CL_add( x[7], x[8] ); + rs2 = CL_sub( x[7], x[8] ); + t = CL_scale_t( CL_sub( rs1, rs3 ), C54 ); + rs1 = CL_add( rs1, rs3 ); + y[5] = CL_add( x[5], rs1 ); + rs1 = CL_add( y[5], ( CL_shl( CL_scale_t( rs1, C55 ), 1 ) ) ); + rs3 = CL_sub( rs1, t ); + rs1 = CL_add( rs1, t ); + t = CL_scale_t( CL_add( rs4, rs2 ), C51 ); + rs4 = CL_add( t, CL_shl( CL_scale_t( rs4, C52 ), 1 ) ); + rs2 = CL_add( t, CL_scale_t( rs2, C53 ) ); /* combination */ - y[6] = CL_msu_j(rs1,rs2); - y[9] = CL_mac_j(rs1,rs2); - y[7] = CL_mac_j(rs3,rs4); - y[8] = CL_msu_j(rs3,rs4); + y[6] = CL_msu_j( rs1, rs2 ); + y[9] = CL_mac_j( rs1, rs2 ); + y[7] = CL_mac_j( rs3, rs4 ); + y[8] = CL_msu_j( rs3, rs4 ); /* 3. FFT5 stage */ - rs1 = CL_add(x[11],x[14]); - rs4 = CL_sub(x[11],x[14]); - rs3 = CL_add(x[12],x[13]); - rs2 = CL_sub(x[12],x[13]); - t = CL_scale_t(CL_sub(rs1,rs3),C54); - rs1 = CL_add(rs1,rs3); - y[10] = CL_add(x[10],rs1); - rs1 = CL_add(y[10],(CL_shl(CL_scale_t(rs1,C55),1))); - rs3 = CL_sub(rs1,t); - rs1 = CL_add(rs1,t); - t = CL_scale_t(CL_add(rs4,rs2),C51); - rs4 = CL_add(t,CL_shl(CL_scale_t(rs4, C52),1)); - rs2 = CL_add(t,CL_scale_t(rs2,C53)); + rs1 = CL_add( x[11], x[14] ); + rs4 = CL_sub( x[11], x[14] ); + rs3 = CL_add( x[12], x[13] ); + rs2 = CL_sub( x[12], x[13] ); + t = CL_scale_t( CL_sub( rs1, rs3 ), C54 ); + rs1 = CL_add( rs1, rs3 ); + y[10] = CL_add( x[10], rs1 ); + rs1 = CL_add( y[10], ( CL_shl( CL_scale_t( rs1, C55 ), 1 ) ) ); + rs3 = CL_sub( rs1, t ); + rs1 = CL_add( rs1, t ); + t = CL_scale_t( CL_add( rs4, rs2 ), C51 ); + rs4 = CL_add( t, CL_shl( CL_scale_t( rs4, C52 ), 1 ) ); + rs2 = CL_add( t, CL_scale_t( rs2, C53 ) ); /* combination */ - y[11] = CL_msu_j(rs1,rs2); - y[14] = CL_mac_j(rs1,rs2); - y[12] = CL_mac_j(rs3,rs4); - y[13] = CL_msu_j(rs3,rs4); + y[11] = CL_msu_j( rs1, rs2 ); + y[14] = CL_mac_j( rs1, rs2 ); + y[12] = CL_mac_j( rs3, rs4 ); + y[13] = CL_msu_j( rs3, rs4 ); /*for (i=10; i<15; i++) { printf("%d,\t %d,\t",y[i].re, y[i].im); @@ -1127,52 +1118,52 @@ static void fft30_with_cmplx_data(cmplx * inp) /* 1. FFT3 stage */ /* real part */ - rs1 = CL_add(y[5],y[10]); - rs2 = CL_scale_t(CL_sub(y[5],y[10]),C31); - z[0] = CL_add(y[0],rs1); - rs1 = CL_sub(y[0],CL_shr(rs1,1)); + rs1 = CL_add( y[5], y[10] ); + rs2 = CL_scale_t( CL_sub( y[5], y[10] ), C31 ); + z[0] = CL_add( y[0], rs1 ); + rs1 = CL_sub( y[0], CL_shr( rs1, 1 ) ); - z[10] = CL_mac_j(rs1,rs2); - z[5] = CL_msu_j(rs1,rs2); + z[10] = CL_mac_j( rs1, rs2 ); + z[5] = CL_msu_j( rs1, rs2 ); /* 2. FFT3 stage */ - rs1 = CL_add(y[6],y[11]); - rs2 = CL_scale_t(CL_sub(y[6],y[11]),C31); - z[6] = CL_add(y[1],rs1); - rs1 = CL_sub(y[1],CL_shr(rs1,1)); + rs1 = CL_add( y[6], y[11] ); + rs2 = CL_scale_t( CL_sub( y[6], y[11] ), C31 ); + z[6] = CL_add( y[1], rs1 ); + rs1 = CL_sub( y[1], CL_shr( rs1, 1 ) ); - z[1] = CL_mac_j(rs1,rs2); - z[11] = CL_msu_j(rs1,rs2); + z[1] = CL_mac_j( rs1, rs2 ); + z[11] = CL_msu_j( rs1, rs2 ); /* 3. FFT3 stage */ - rs1 = CL_add(y[7],y[12]); - rs2 = CL_scale_t(CL_sub(y[7],y[12]),C31); - z[12] = CL_add(y[2],rs1); - rs1 = CL_sub(y[2],CL_shr(rs1,1)); + rs1 = CL_add( y[7], y[12] ); + rs2 = CL_scale_t( CL_sub( y[7], y[12] ), C31 ); + z[12] = CL_add( y[2], rs1 ); + rs1 = CL_sub( y[2], CL_shr( rs1, 1 ) ); - z[7] = CL_mac_j(rs1,rs2); - z[2] = CL_msu_j(rs1,rs2); + z[7] = CL_mac_j( rs1, rs2 ); + z[2] = CL_msu_j( rs1, rs2 ); /* 4. FFT3 stage */ - rs1 = CL_add(y[8],y[13]); - rs2 = CL_scale_t(CL_sub(y[8],y[13]),C31); - z[3] = CL_add(y[3],rs1); - rs1 = CL_sub(y[3],CL_shr(rs1,1)); + rs1 = CL_add( y[8], y[13] ); + rs2 = CL_scale_t( CL_sub( y[8], y[13] ), C31 ); + z[3] = CL_add( y[3], rs1 ); + rs1 = CL_sub( y[3], CL_shr( rs1, 1 ) ); - z[13] = CL_mac_j(rs1,rs2); - z[8] = CL_msu_j(rs1,rs2); + z[13] = CL_mac_j( rs1, rs2 ); + z[8] = CL_msu_j( rs1, rs2 ); /* 5. FFT3 stage */ - rs1 = CL_add(y[9],y[14]); - rs2 = CL_scale_t(CL_sub(y[9],y[14]),C31); - z[9] = CL_add(y[4],rs1); - rs1 = CL_sub(y[4],CL_shr(rs1,1)); + rs1 = CL_add( y[9], y[14] ); + rs2 = CL_scale_t( CL_sub( y[9], y[14] ), C31 ); + z[9] = CL_add( y[4], rs1 ); + rs1 = CL_sub( y[4], CL_shr( rs1, 1 ) ); - z[4] = CL_mac_j(rs1,rs2); - z[14] = CL_msu_j(rs1,rs2); + z[4] = CL_mac_j( rs1, rs2 ); + z[14] = CL_msu_j( rs1, rs2 ); /*for (i=0; i<15; i++) printf("%d,\t %d,\t",z[i].re, z[i].im); @@ -1181,88 +1172,88 @@ static void fft30_with_cmplx_data(cmplx * inp) /* 2. FFT15 stage */ - x[0] = CL_shr(inp[15],SCALEFACTOR30_1); - x[1] = CL_shr(inp[3],SCALEFACTOR30_1); - x[2] = CL_shr(inp[21],SCALEFACTOR30_1); - x[3] = CL_shr(inp[9],SCALEFACTOR30_1); - x[4] = CL_shr(inp[27],SCALEFACTOR30_1); + x[0] = CL_shr( inp[15], SCALEFACTOR30_1 ); + x[1] = CL_shr( inp[3], SCALEFACTOR30_1 ); + x[2] = CL_shr( inp[21], SCALEFACTOR30_1 ); + x[3] = CL_shr( inp[9], SCALEFACTOR30_1 ); + x[4] = CL_shr( inp[27], SCALEFACTOR30_1 ); - x[5] = CL_shr(inp[5],SCALEFACTOR30_1); - x[6] = CL_shr(inp[23],SCALEFACTOR30_1); - x[7] = CL_shr(inp[11],SCALEFACTOR30_1); - x[8] = CL_shr(inp[29],SCALEFACTOR30_1); - x[9] = CL_shr(inp[17],SCALEFACTOR30_1); + x[5] = CL_shr( inp[5], SCALEFACTOR30_1 ); + x[6] = CL_shr( inp[23], SCALEFACTOR30_1 ); + x[7] = CL_shr( inp[11], SCALEFACTOR30_1 ); + x[8] = CL_shr( inp[29], SCALEFACTOR30_1 ); + x[9] = CL_shr( inp[17], SCALEFACTOR30_1 ); - x[10] = CL_shr(inp[25],SCALEFACTOR30_1); - x[11] = CL_shr(inp[13],SCALEFACTOR30_1); - x[12] = CL_shr(inp[1],SCALEFACTOR30_1); - x[13] = CL_shr(inp[19],SCALEFACTOR30_1); - x[14] = CL_shr(inp[7],SCALEFACTOR30_1); + x[10] = CL_shr( inp[25], SCALEFACTOR30_1 ); + x[11] = CL_shr( inp[13], SCALEFACTOR30_1 ); + x[12] = CL_shr( inp[1], SCALEFACTOR30_1 ); + x[13] = CL_shr( inp[19], SCALEFACTOR30_1 ); + x[14] = CL_shr( inp[7], SCALEFACTOR30_1 ); /* 1. FFT5 stage */ - rs1 = CL_add(x[1],x[4]); - rs4 = CL_sub(x[1],x[4]); - rs3 = CL_add(x[2],x[3]); - rs2 = CL_sub(x[2],x[3]); - t = CL_scale_t(CL_sub(rs1,rs3),C54); - rs1 = CL_add(rs1,rs3); - y[0] = CL_add(x[0],rs1); - rs1 = CL_add(y[0],(CL_shl(CL_scale_t(rs1,C55),1))); - rs3 = CL_sub(rs1,t); - rs1 = CL_add(rs1,t); - t = CL_scale_t(CL_add(rs4,rs2),C51); - rs4 = CL_add(t,CL_shl(CL_scale_t(rs4, C52),1)); - rs2 = CL_add(t,CL_scale_t(rs2,C53)); + rs1 = CL_add( x[1], x[4] ); + rs4 = CL_sub( x[1], x[4] ); + rs3 = CL_add( x[2], x[3] ); + rs2 = CL_sub( x[2], x[3] ); + t = CL_scale_t( CL_sub( rs1, rs3 ), C54 ); + rs1 = CL_add( rs1, rs3 ); + y[0] = CL_add( x[0], rs1 ); + rs1 = CL_add( y[0], ( CL_shl( CL_scale_t( rs1, C55 ), 1 ) ) ); + rs3 = CL_sub( rs1, t ); + rs1 = CL_add( rs1, t ); + t = CL_scale_t( CL_add( rs4, rs2 ), C51 ); + rs4 = CL_add( t, CL_shl( CL_scale_t( rs4, C52 ), 1 ) ); + rs2 = CL_add( t, CL_scale_t( rs2, C53 ) ); /* combination */ - y[1] = CL_msu_j(rs1,rs2); - y[4] = CL_mac_j(rs1,rs2); - y[2] = CL_mac_j(rs3,rs4); - y[3] = CL_msu_j(rs3,rs4); + y[1] = CL_msu_j( rs1, rs2 ); + y[4] = CL_mac_j( rs1, rs2 ); + y[2] = CL_mac_j( rs3, rs4 ); + y[3] = CL_msu_j( rs3, rs4 ); /* 2. FFT5 stage */ - rs1 = CL_add(x[6],x[9]); - rs4 = CL_sub(x[6],x[9]); - rs3 = CL_add(x[7],x[8]); - rs2 = CL_sub(x[7],x[8]); - t = CL_scale_t(CL_sub(rs1,rs3),C54); - rs1 = CL_add(rs1,rs3); - y[5] = CL_add(x[5],rs1); - rs1 = CL_add(y[5],(CL_shl(CL_scale_t(rs1,C55),1))); - rs3 = CL_sub(rs1,t); - rs1 = CL_add(rs1,t); - t = CL_scale_t(CL_add(rs4,rs2),C51); - rs4 = CL_add(t,CL_shl(CL_scale_t(rs4, C52),1)); - rs2 = CL_add(t,CL_scale_t(rs2,C53)); + rs1 = CL_add( x[6], x[9] ); + rs4 = CL_sub( x[6], x[9] ); + rs3 = CL_add( x[7], x[8] ); + rs2 = CL_sub( x[7], x[8] ); + t = CL_scale_t( CL_sub( rs1, rs3 ), C54 ); + rs1 = CL_add( rs1, rs3 ); + y[5] = CL_add( x[5], rs1 ); + rs1 = CL_add( y[5], ( CL_shl( CL_scale_t( rs1, C55 ), 1 ) ) ); + rs3 = CL_sub( rs1, t ); + rs1 = CL_add( rs1, t ); + t = CL_scale_t( CL_add( rs4, rs2 ), C51 ); + rs4 = CL_add( t, CL_shl( CL_scale_t( rs4, C52 ), 1 ) ); + rs2 = CL_add( t, CL_scale_t( rs2, C53 ) ); /* combination */ - y[6] = CL_msu_j(rs1,rs2); - y[9] = CL_mac_j(rs1,rs2); - y[7] = CL_mac_j(rs3,rs4); - y[8] = CL_msu_j(rs3,rs4); + y[6] = CL_msu_j( rs1, rs2 ); + y[9] = CL_mac_j( rs1, rs2 ); + y[7] = CL_mac_j( rs3, rs4 ); + y[8] = CL_msu_j( rs3, rs4 ); /* 3. FFT5 stage */ - rs1 = CL_add(x[11],x[14]); - rs4 = CL_sub(x[11],x[14]); - rs3 = CL_add(x[12],x[13]); - rs2 = CL_sub(x[12],x[13]); - t = CL_scale_t(CL_sub(rs1,rs3),C54); - rs1 = CL_add(rs1,rs3); - y[10] = CL_add(x[10],rs1); - rs1 = CL_add(y[10],(CL_shl(CL_scale_t(rs1,C55),1))); - rs3 = CL_sub(rs1,t); - rs1 = CL_add(rs1,t); - t = CL_scale_t(CL_add(rs4,rs2),C51); - rs4 = CL_add(t,CL_shl(CL_scale_t(rs4, C52),1)); - rs2 = CL_add(t,CL_scale_t(rs2,C53)); + rs1 = CL_add( x[11], x[14] ); + rs4 = CL_sub( x[11], x[14] ); + rs3 = CL_add( x[12], x[13] ); + rs2 = CL_sub( x[12], x[13] ); + t = CL_scale_t( CL_sub( rs1, rs3 ), C54 ); + rs1 = CL_add( rs1, rs3 ); + y[10] = CL_add( x[10], rs1 ); + rs1 = CL_add( y[10], ( CL_shl( CL_scale_t( rs1, C55 ), 1 ) ) ); + rs3 = CL_sub( rs1, t ); + rs1 = CL_add( rs1, t ); + t = CL_scale_t( CL_add( rs4, rs2 ), C51 ); + rs4 = CL_add( t, CL_shl( CL_scale_t( rs4, C52 ), 1 ) ); + rs2 = CL_add( t, CL_scale_t( rs2, C53 ) ); /* combination */ - y[11] = CL_msu_j(rs1,rs2); - y[14] = CL_mac_j(rs1,rs2); - y[12] = CL_mac_j(rs3,rs4); - y[13] = CL_msu_j(rs3,rs4); + y[11] = CL_msu_j( rs1, rs2 ); + y[14] = CL_mac_j( rs1, rs2 ); + y[12] = CL_mac_j( rs3, rs4 ); + y[13] = CL_msu_j( rs3, rs4 ); /*for (i=10; i<15; i++) { printf("%d,\t %d,\t",y[i].re, y[i].im); @@ -1272,52 +1263,52 @@ static void fft30_with_cmplx_data(cmplx * inp) /* 1. FFT3 stage */ /* real part */ - rs1 = CL_add(y[5],y[10]); - rs2 = CL_scale_t(CL_sub(y[5],y[10]),C31); - z[15] = CL_add(y[0],rs1); - rs1 = CL_sub(y[0],CL_shr(rs1,1)); + rs1 = CL_add( y[5], y[10] ); + rs2 = CL_scale_t( CL_sub( y[5], y[10] ), C31 ); + z[15] = CL_add( y[0], rs1 ); + rs1 = CL_sub( y[0], CL_shr( rs1, 1 ) ); - z[25] = CL_mac_j(rs1,rs2); - z[20] = CL_msu_j(rs1,rs2); + z[25] = CL_mac_j( rs1, rs2 ); + z[20] = CL_msu_j( rs1, rs2 ); /* 2. FFT3 stage */ - rs1 = CL_add(y[6],y[11]); - rs2 = CL_scale_t(CL_sub(y[6],y[11]),C31); - z[21] = CL_add(y[1],rs1); - rs1 = CL_sub(y[1],CL_shr(rs1,1)); + rs1 = CL_add( y[6], y[11] ); + rs2 = CL_scale_t( CL_sub( y[6], y[11] ), C31 ); + z[21] = CL_add( y[1], rs1 ); + rs1 = CL_sub( y[1], CL_shr( rs1, 1 ) ); - z[16] = CL_mac_j(rs1,rs2); - z[26] = CL_msu_j(rs1,rs2); + z[16] = CL_mac_j( rs1, rs2 ); + z[26] = CL_msu_j( rs1, rs2 ); /* 3. FFT3 stage */ - rs1 = CL_add(y[7],y[12]); - rs2 = CL_scale_t(CL_sub(y[7],y[12]),C31); - z[27] = CL_add(y[2],rs1); - rs1 = CL_sub(y[2],CL_shr(rs1,1)); + rs1 = CL_add( y[7], y[12] ); + rs2 = CL_scale_t( CL_sub( y[7], y[12] ), C31 ); + z[27] = CL_add( y[2], rs1 ); + rs1 = CL_sub( y[2], CL_shr( rs1, 1 ) ); - z[22] = CL_mac_j(rs1,rs2); - z[17] = CL_msu_j(rs1,rs2); + z[22] = CL_mac_j( rs1, rs2 ); + z[17] = CL_msu_j( rs1, rs2 ); /* 4. FFT3 stage */ - rs1 = CL_add(y[8],y[13]); - rs2 = CL_scale_t(CL_sub(y[8],y[13]),C31); - z[18] = CL_add(y[3],rs1); - rs1 = CL_sub(y[3],CL_shr(rs1,1)); + rs1 = CL_add( y[8], y[13] ); + rs2 = CL_scale_t( CL_sub( y[8], y[13] ), C31 ); + z[18] = CL_add( y[3], rs1 ); + rs1 = CL_sub( y[3], CL_shr( rs1, 1 ) ); - z[28] = CL_mac_j(rs1,rs2); - z[23] = CL_msu_j(rs1,rs2); + z[28] = CL_mac_j( rs1, rs2 ); + z[23] = CL_msu_j( rs1, rs2 ); /* 5. FFT3 stage */ - rs1 = CL_add(y[9],y[14]); - rs2 = CL_scale_t(CL_sub(y[9],y[14]),C31); - z[24] = CL_add(y[4],rs1); - rs1 = CL_sub(y[4],CL_shr(rs1,1)); + rs1 = CL_add( y[9], y[14] ); + rs2 = CL_scale_t( CL_sub( y[9], y[14] ), C31 ); + z[24] = CL_add( y[4], rs1 ); + rs1 = CL_sub( y[4], CL_shr( rs1, 1 ) ); - z[19] = CL_mac_j(rs1,rs2); - z[29] = CL_msu_j(rs1,rs2); + z[19] = CL_mac_j( rs1, rs2 ); + z[29] = CL_msu_j( rs1, rs2 ); /*for (i=0; i<30; i++) printf("%d,\t %d,\t",z[i].re, z[i].im); @@ -1325,116 +1316,130 @@ static void fft30_with_cmplx_data(cmplx * inp) /* 1. FFT2 stage */ - rs1 = CL_shr(z[0], SCALEFACTOR30_2); - rs2 = CL_shr(z[15],SCALEFACTOR30_2); - *l = CL_add(rs1,rs2); - *h = CL_sub(rs1,rs2); - l+=1; h+=1; + rs1 = CL_shr( z[0], SCALEFACTOR30_2 ); + rs2 = CL_shr( z[15], SCALEFACTOR30_2 ); + *l = CL_add( rs1, rs2 ); + *h = CL_sub( rs1, rs2 ); + l += 1; + h += 1; /* 2. FFT2 stage */ - rs1 = CL_shr(z[8], SCALEFACTOR30_2); - rs2 = CL_shr(z[23],SCALEFACTOR30_2); - *h = CL_add(rs1,rs2); - *l = CL_sub(rs1,rs2); - l+=1; h+=1; + rs1 = CL_shr( z[8], SCALEFACTOR30_2 ); + rs2 = CL_shr( z[23], SCALEFACTOR30_2 ); + *h = CL_add( rs1, rs2 ); + *l = CL_sub( rs1, rs2 ); + l += 1; + h += 1; /* 3. FFT2 stage */ - rs1 = CL_shr(z[1], SCALEFACTOR30_2); - rs2 = CL_shr(z[16],SCALEFACTOR30_2); - *l = CL_add(rs1,rs2); - *h = CL_sub(rs1,rs2); - l+=1; h+=1; + rs1 = CL_shr( z[1], SCALEFACTOR30_2 ); + rs2 = CL_shr( z[16], SCALEFACTOR30_2 ); + *l = CL_add( rs1, rs2 ); + *h = CL_sub( rs1, rs2 ); + l += 1; + h += 1; /* 4. FFT2 stage */ - rs1 = CL_shr(z[9], SCALEFACTOR30_2); - rs2 = CL_shr(z[24],SCALEFACTOR30_2); - *h = CL_add(rs1,rs2); - *l = CL_sub(rs1,rs2); - l+=1; h+=1; + rs1 = CL_shr( z[9], SCALEFACTOR30_2 ); + rs2 = CL_shr( z[24], SCALEFACTOR30_2 ); + *h = CL_add( rs1, rs2 ); + *l = CL_sub( rs1, rs2 ); + l += 1; + h += 1; /* 5. FFT2 stage */ - rs1 = CL_shr(z[2], SCALEFACTOR30_2); - rs2 = CL_shr(z[17],SCALEFACTOR30_2); - *l = CL_add(rs1,rs2); - *h = CL_sub(rs1,rs2); - l+=1; h+=1; + rs1 = CL_shr( z[2], SCALEFACTOR30_2 ); + rs2 = CL_shr( z[17], SCALEFACTOR30_2 ); + *l = CL_add( rs1, rs2 ); + *h = CL_sub( rs1, rs2 ); + l += 1; + h += 1; /* 6. FFT2 stage */ - rs1 = CL_shr(z[10], SCALEFACTOR30_2); - rs2 = CL_shr(z[25],SCALEFACTOR30_2); - *h = CL_add(rs1,rs2); - *l = CL_sub(rs1,rs2); - l+=1; h+=1; + rs1 = CL_shr( z[10], SCALEFACTOR30_2 ); + rs2 = CL_shr( z[25], SCALEFACTOR30_2 ); + *h = CL_add( rs1, rs2 ); + *l = CL_sub( rs1, rs2 ); + l += 1; + h += 1; /* 7. FFT2 stage */ - rs1 = CL_shr(z[3], SCALEFACTOR30_2); - rs2 = CL_shr(z[18],SCALEFACTOR30_2); - *l = CL_add(rs1,rs2); - *h = CL_sub(rs1,rs2); - l+=1; h+=1; + rs1 = CL_shr( z[3], SCALEFACTOR30_2 ); + rs2 = CL_shr( z[18], SCALEFACTOR30_2 ); + *l = CL_add( rs1, rs2 ); + *h = CL_sub( rs1, rs2 ); + l += 1; + h += 1; /* 8. FFT2 stage */ - rs1 = CL_shr(z[11], SCALEFACTOR30_2); - rs2 = CL_shr(z[26],SCALEFACTOR30_2); - *h = CL_add(rs1,rs2); - *l = CL_sub(rs1,rs2); - l+=1; h+=1; + rs1 = CL_shr( z[11], SCALEFACTOR30_2 ); + rs2 = CL_shr( z[26], SCALEFACTOR30_2 ); + *h = CL_add( rs1, rs2 ); + *l = CL_sub( rs1, rs2 ); + l += 1; + h += 1; /* 9. FFT2 stage */ - rs1 = CL_shr(z[4], SCALEFACTOR30_2); - rs2 = CL_shr(z[19],SCALEFACTOR30_2); - *l = CL_add(rs1,rs2); - *h = CL_sub(rs1,rs2); - l+=1; h+=1; + rs1 = CL_shr( z[4], SCALEFACTOR30_2 ); + rs2 = CL_shr( z[19], SCALEFACTOR30_2 ); + *l = CL_add( rs1, rs2 ); + *h = CL_sub( rs1, rs2 ); + l += 1; + h += 1; /* 10. FFT2 stage */ - rs1 = CL_shr(z[12], SCALEFACTOR30_2); - rs2 = CL_shr(z[27],SCALEFACTOR30_2); - *h = CL_add(rs1,rs2); - *l = CL_sub(rs1,rs2); - l+=1; h+=1; + rs1 = CL_shr( z[12], SCALEFACTOR30_2 ); + rs2 = CL_shr( z[27], SCALEFACTOR30_2 ); + *h = CL_add( rs1, rs2 ); + *l = CL_sub( rs1, rs2 ); + l += 1; + h += 1; /* 11. FFT2 stage */ - rs1 = CL_shr(z[5], SCALEFACTOR30_2); - rs2 = CL_shr(z[20],SCALEFACTOR30_2); - *l = CL_add(rs1,rs2); - *h = CL_sub(rs1,rs2); - l+=1; h+=1; + rs1 = CL_shr( z[5], SCALEFACTOR30_2 ); + rs2 = CL_shr( z[20], SCALEFACTOR30_2 ); + *l = CL_add( rs1, rs2 ); + *h = CL_sub( rs1, rs2 ); + l += 1; + h += 1; /* 12. FFT2 stage */ - rs1 = CL_shr(z[13], SCALEFACTOR30_2); - rs2 = CL_shr(z[28],SCALEFACTOR30_2); - *h = CL_add(rs1,rs2); - *l = CL_sub(rs1,rs2); - l+=1; h+=1; + rs1 = CL_shr( z[13], SCALEFACTOR30_2 ); + rs2 = CL_shr( z[28], SCALEFACTOR30_2 ); + *h = CL_add( rs1, rs2 ); + *l = CL_sub( rs1, rs2 ); + l += 1; + h += 1; /* 13. FFT2 stage */ - rs1 = CL_shr(z[6], SCALEFACTOR30_2); - rs2 = CL_shr(z[21],SCALEFACTOR30_2); - *l = CL_add(rs1,rs2); - *h = CL_sub(rs1,rs2); - l+=1; h+=1; + rs1 = CL_shr( z[6], SCALEFACTOR30_2 ); + rs2 = CL_shr( z[21], SCALEFACTOR30_2 ); + *l = CL_add( rs1, rs2 ); + *h = CL_sub( rs1, rs2 ); + l += 1; + h += 1; /* 14. FFT2 stage */ - rs1 = CL_shr(z[14], SCALEFACTOR30_2); - rs2 = CL_shr(z[29],SCALEFACTOR30_2); - *h = CL_add(rs1,rs2); - *l = CL_sub(rs1,rs2); - l+=1; h+=1; + rs1 = CL_shr( z[14], SCALEFACTOR30_2 ); + rs2 = CL_shr( z[29], SCALEFACTOR30_2 ); + *h = CL_add( rs1, rs2 ); + *l = CL_sub( rs1, rs2 ); + l += 1; + h += 1; /* 15. FFT2 stage */ - rs1 = CL_shr(z[7], SCALEFACTOR30_2); - rs2 = CL_shr(z[22],SCALEFACTOR30_2); - *l = CL_add(rs1,rs2); - *h = CL_sub(rs1,rs2); - l+=1; h+=1; - -#if (WMOPS) + rs1 = CL_shr( z[7], SCALEFACTOR30_2 ); + rs2 = CL_shr( z[22], SCALEFACTOR30_2 ); + *l = CL_add( rs1, rs2 ); + *h = CL_sub( rs1, rs2 ); + l += 1; + h += 1; + +#if ( WMOPS ) multiCounter[currCounter].CL_move += 30; -#endif - +#endif } /** @@ -1452,364 +1457,362 @@ static void fft30_with_cmplx_data(cmplx * inp) */ -static void fft32_with_cmplx_data(cmplx * inp) +static void fft32_with_cmplx_data( cmplx *inp ) { cmplx x[32], y[32], t[32], s[32], temp, temp1; - const cmplx_s *pRotVector_32 = ( const cmplx_s *)RotVector_32; - + const cmplx_s *pRotVector_32 = (const cmplx_s *) RotVector_32; + /* 1. FFT8 stage */ - x[0] = CL_shr(inp[0], SCALEFACTOR32_1); - x[1] = CL_shr(inp[4], SCALEFACTOR32_1); - x[2] = CL_shr(inp[8], SCALEFACTOR32_1); - x[3] = CL_shr(inp[12], SCALEFACTOR32_1); - x[4] = CL_shr(inp[16], SCALEFACTOR32_1); - x[5] = CL_shr(inp[20], SCALEFACTOR32_1); - x[6] = CL_shr(inp[24], SCALEFACTOR32_1); - x[7] = CL_shr(inp[28], SCALEFACTOR32_1); - - - t[0] = CL_add(x[0],x[4]); - t[1] = CL_sub(x[0],x[4]); - t[2] = CL_add(x[1],x[5]); - t[3] = CL_sub(x[1],x[5]); - t[4] = CL_add(x[2],x[6]); - t[5] = CL_sub(x[2],x[6]); - t[6] = CL_add(x[3],x[7]); - t[7] = CL_sub(x[3],x[7]); + x[0] = CL_shr( inp[0], SCALEFACTOR32_1 ); + x[1] = CL_shr( inp[4], SCALEFACTOR32_1 ); + x[2] = CL_shr( inp[8], SCALEFACTOR32_1 ); + x[3] = CL_shr( inp[12], SCALEFACTOR32_1 ); + x[4] = CL_shr( inp[16], SCALEFACTOR32_1 ); + x[5] = CL_shr( inp[20], SCALEFACTOR32_1 ); + x[6] = CL_shr( inp[24], SCALEFACTOR32_1 ); + x[7] = CL_shr( inp[28], SCALEFACTOR32_1 ); + + + t[0] = CL_add( x[0], x[4] ); + t[1] = CL_sub( x[0], x[4] ); + t[2] = CL_add( x[1], x[5] ); + t[3] = CL_sub( x[1], x[5] ); + t[4] = CL_add( x[2], x[6] ); + t[5] = CL_sub( x[2], x[6] ); + t[6] = CL_add( x[3], x[7] ); + t[7] = CL_sub( x[3], x[7] ); /* Pre-additions and core multiplications */ - s[0] = CL_add(t[0], t[4]); - s[2] = CL_sub(t[0], t[4]); - s[4] = CL_mac_j(t[1], t[5]); - s[5] = CL_msu_j(t[1], t[5]); - s[1] = CL_add(t[2], t[6]); - s[3] = CL_sub(t[2], t[6]); - s[3] = CL_mul_j(s[3]); - - temp = CL_add(t[3], t[7]); - temp1 = CL_sub(t[3], t[7]); - s[6] = CL_scale_t(CL_msu_j(temp1, temp), C81); - s[7] = CL_dscale_t(CL_swap_real_imag( CL_msu_j(temp, temp1)), C81, C82); - - - y[0] = CL_add(s[0],s[1]); - y[4] = CL_sub(s[0],s[1]); - y[2] = CL_sub(s[2],s[3]); - y[6] = CL_add(s[2],s[3]); - y[3] = CL_add(s[4],s[7]); - y[7] = CL_sub(s[4],s[7]); - y[1] = CL_add(s[5],s[6]); - y[5] = CL_sub(s[5],s[6]); + s[0] = CL_add( t[0], t[4] ); + s[2] = CL_sub( t[0], t[4] ); + s[4] = CL_mac_j( t[1], t[5] ); + s[5] = CL_msu_j( t[1], t[5] ); + s[1] = CL_add( t[2], t[6] ); + s[3] = CL_sub( t[2], t[6] ); + s[3] = CL_mul_j( s[3] ); + + temp = CL_add( t[3], t[7] ); + temp1 = CL_sub( t[3], t[7] ); + s[6] = CL_scale_t( CL_msu_j( temp1, temp ), C81 ); + s[7] = CL_dscale_t( CL_swap_real_imag( CL_msu_j( temp, temp1 ) ), C81, C82 ); + + + y[0] = CL_add( s[0], s[1] ); + y[4] = CL_sub( s[0], s[1] ); + y[2] = CL_sub( s[2], s[3] ); + y[6] = CL_add( s[2], s[3] ); + y[3] = CL_add( s[4], s[7] ); + y[7] = CL_sub( s[4], s[7] ); + y[1] = CL_add( s[5], s[6] ); + y[5] = CL_sub( s[5], s[6] ); /* 2. FFT8 stage */ - x[0] = CL_shr(inp[1], SCALEFACTOR32_1); - x[1] = CL_shr(inp[5], SCALEFACTOR32_1); - x[2] = CL_shr(inp[9], SCALEFACTOR32_1); - x[3] = CL_shr(inp[13], SCALEFACTOR32_1); - x[4] = CL_shr(inp[17], SCALEFACTOR32_1); - x[5] = CL_shr(inp[21], SCALEFACTOR32_1); - x[6] = CL_shr(inp[25], SCALEFACTOR32_1); - x[7] = CL_shr(inp[29], SCALEFACTOR32_1); - - - t[0] = CL_add(x[0],x[4]); - t[1] = CL_sub(x[0],x[4]); - t[2] = CL_add(x[1],x[5]); - t[3] = CL_sub(x[1],x[5]); - t[4] = CL_add(x[2],x[6]); - t[5] = CL_sub(x[2],x[6]); - t[6] = CL_add(x[3],x[7]); - t[7] = CL_sub(x[3],x[7]); + x[0] = CL_shr( inp[1], SCALEFACTOR32_1 ); + x[1] = CL_shr( inp[5], SCALEFACTOR32_1 ); + x[2] = CL_shr( inp[9], SCALEFACTOR32_1 ); + x[3] = CL_shr( inp[13], SCALEFACTOR32_1 ); + x[4] = CL_shr( inp[17], SCALEFACTOR32_1 ); + x[5] = CL_shr( inp[21], SCALEFACTOR32_1 ); + x[6] = CL_shr( inp[25], SCALEFACTOR32_1 ); + x[7] = CL_shr( inp[29], SCALEFACTOR32_1 ); + + + t[0] = CL_add( x[0], x[4] ); + t[1] = CL_sub( x[0], x[4] ); + t[2] = CL_add( x[1], x[5] ); + t[3] = CL_sub( x[1], x[5] ); + t[4] = CL_add( x[2], x[6] ); + t[5] = CL_sub( x[2], x[6] ); + t[6] = CL_add( x[3], x[7] ); + t[7] = CL_sub( x[3], x[7] ); /* Pre-additions and core multiplications */ - s[0] = CL_add(t[0], t[4]); - s[2] = CL_sub(t[0], t[4]); - s[4] = CL_mac_j(t[1], t[5]); - s[5] = CL_msu_j(t[1], t[5]); - s[1] = CL_add(t[2], t[6]); - s[3] = CL_sub(t[2], t[6]); - s[3] = CL_mul_j(s[3]); + s[0] = CL_add( t[0], t[4] ); + s[2] = CL_sub( t[0], t[4] ); + s[4] = CL_mac_j( t[1], t[5] ); + s[5] = CL_msu_j( t[1], t[5] ); + s[1] = CL_add( t[2], t[6] ); + s[3] = CL_sub( t[2], t[6] ); + s[3] = CL_mul_j( s[3] ); - temp = CL_add(t[3], t[7]); - temp1 = CL_sub(t[3], t[7]); - s[6] = CL_scale_t(CL_msu_j(temp1, temp), C81); - s[7] = CL_dscale_t(CL_swap_real_imag( CL_msu_j(temp, temp1)), C81, C82); + temp = CL_add( t[3], t[7] ); + temp1 = CL_sub( t[3], t[7] ); + s[6] = CL_scale_t( CL_msu_j( temp1, temp ), C81 ); + s[7] = CL_dscale_t( CL_swap_real_imag( CL_msu_j( temp, temp1 ) ), C81, C82 ); /* Post-additions */ - y[8] = CL_add(s[0],s[1]); - y[12] = CL_sub(s[0],s[1]); - y[10] = CL_sub(s[2],s[3]); - y[14] = CL_add(s[2],s[3]); - y[11] = CL_add(s[4],s[7]); - y[15] = CL_sub(s[4],s[7]); - y[9] = CL_add(s[5],s[6]); - y[13] = CL_sub(s[5],s[6]); + y[8] = CL_add( s[0], s[1] ); + y[12] = CL_sub( s[0], s[1] ); + y[10] = CL_sub( s[2], s[3] ); + y[14] = CL_add( s[2], s[3] ); + y[11] = CL_add( s[4], s[7] ); + y[15] = CL_sub( s[4], s[7] ); + y[9] = CL_add( s[5], s[6] ); + y[13] = CL_sub( s[5], s[6] ); /* 3. FFT8 stage */ - x[0] = CL_shr(inp[2], SCALEFACTOR32_1); - x[1] = CL_shr(inp[6], SCALEFACTOR32_1); - x[2] = CL_shr(inp[10], SCALEFACTOR32_1); - x[3] = CL_shr(inp[14], SCALEFACTOR32_1); - x[4] = CL_shr(inp[18], SCALEFACTOR32_1); - x[5] = CL_shr(inp[22], SCALEFACTOR32_1); - x[6] = CL_shr(inp[26], SCALEFACTOR32_1); - x[7] = CL_shr(inp[30], SCALEFACTOR32_1); - - - t[0] = CL_add(x[0],x[4]); - t[1] = CL_sub(x[0],x[4]); - t[2] = CL_add(x[1],x[5]); - t[3] = CL_sub(x[1],x[5]); - t[4] = CL_add(x[2],x[6]); - t[5] = CL_sub(x[2],x[6]); - t[6] = CL_add(x[3],x[7]); - t[7] = CL_sub(x[3],x[7]); + x[0] = CL_shr( inp[2], SCALEFACTOR32_1 ); + x[1] = CL_shr( inp[6], SCALEFACTOR32_1 ); + x[2] = CL_shr( inp[10], SCALEFACTOR32_1 ); + x[3] = CL_shr( inp[14], SCALEFACTOR32_1 ); + x[4] = CL_shr( inp[18], SCALEFACTOR32_1 ); + x[5] = CL_shr( inp[22], SCALEFACTOR32_1 ); + x[6] = CL_shr( inp[26], SCALEFACTOR32_1 ); + x[7] = CL_shr( inp[30], SCALEFACTOR32_1 ); + + + t[0] = CL_add( x[0], x[4] ); + t[1] = CL_sub( x[0], x[4] ); + t[2] = CL_add( x[1], x[5] ); + t[3] = CL_sub( x[1], x[5] ); + t[4] = CL_add( x[2], x[6] ); + t[5] = CL_sub( x[2], x[6] ); + t[6] = CL_add( x[3], x[7] ); + t[7] = CL_sub( x[3], x[7] ); /* Pre-additions and core multiplications */ - s[0] = CL_add(t[0], t[4]); - s[2] = CL_sub(t[0], t[4]); - s[4] = CL_mac_j(t[1], t[5]); - s[5] = CL_msu_j(t[1], t[5]); - s[1] = CL_add(t[2], t[6]); - s[3] = CL_sub(t[2], t[6]); - s[3] = CL_mul_j(s[3]); + s[0] = CL_add( t[0], t[4] ); + s[2] = CL_sub( t[0], t[4] ); + s[4] = CL_mac_j( t[1], t[5] ); + s[5] = CL_msu_j( t[1], t[5] ); + s[1] = CL_add( t[2], t[6] ); + s[3] = CL_sub( t[2], t[6] ); + s[3] = CL_mul_j( s[3] ); - temp = CL_add(t[3], t[7]); - temp1 = CL_sub(t[3], t[7]); - s[6] = CL_scale_t(CL_msu_j(temp1, temp), C81); - s[7] = CL_dscale_t(CL_swap_real_imag( CL_msu_j(temp, temp1)), C81, C82); + temp = CL_add( t[3], t[7] ); + temp1 = CL_sub( t[3], t[7] ); + s[6] = CL_scale_t( CL_msu_j( temp1, temp ), C81 ); + s[7] = CL_dscale_t( CL_swap_real_imag( CL_msu_j( temp, temp1 ) ), C81, C82 ); /* Post-additions */ - y[16] = CL_add(s[0],s[1]); - y[20] = CL_sub(s[0],s[1]); - y[18] = CL_sub(s[2],s[3]); - y[22] = CL_add(s[2],s[3]); - y[19] = CL_add(s[4],s[7]); - y[23] = CL_sub(s[4],s[7]); - y[17] = CL_add(s[5],s[6]); - y[21] = CL_sub(s[5],s[6]); + y[16] = CL_add( s[0], s[1] ); + y[20] = CL_sub( s[0], s[1] ); + y[18] = CL_sub( s[2], s[3] ); + y[22] = CL_add( s[2], s[3] ); + y[19] = CL_add( s[4], s[7] ); + y[23] = CL_sub( s[4], s[7] ); + y[17] = CL_add( s[5], s[6] ); + y[21] = CL_sub( s[5], s[6] ); /* 4. FFT8 stage */ - x[0] = CL_shr(inp[3], SCALEFACTOR32_1); - x[1] = CL_shr(inp[7], SCALEFACTOR32_1); - x[2] = CL_shr(inp[11], SCALEFACTOR32_1); - x[3] = CL_shr(inp[15], SCALEFACTOR32_1); - x[4] = CL_shr(inp[19], SCALEFACTOR32_1); - x[5] = CL_shr(inp[23], SCALEFACTOR32_1); - x[6] = CL_shr(inp[27], SCALEFACTOR32_1); - x[7] = CL_shr(inp[31], SCALEFACTOR32_1); + x[0] = CL_shr( inp[3], SCALEFACTOR32_1 ); + x[1] = CL_shr( inp[7], SCALEFACTOR32_1 ); + x[2] = CL_shr( inp[11], SCALEFACTOR32_1 ); + x[3] = CL_shr( inp[15], SCALEFACTOR32_1 ); + x[4] = CL_shr( inp[19], SCALEFACTOR32_1 ); + x[5] = CL_shr( inp[23], SCALEFACTOR32_1 ); + x[6] = CL_shr( inp[27], SCALEFACTOR32_1 ); + x[7] = CL_shr( inp[31], SCALEFACTOR32_1 ); - t[0] = CL_add(x[0],x[4]); - t[1] = CL_sub(x[0],x[4]); - t[2] = CL_add(x[1],x[5]); - t[3] = CL_sub(x[1],x[5]); - t[4] = CL_add(x[2],x[6]); - t[5] = CL_sub(x[2],x[6]); - t[6] = CL_add(x[3],x[7]); - t[7] = CL_sub(x[3],x[7]); + t[0] = CL_add( x[0], x[4] ); + t[1] = CL_sub( x[0], x[4] ); + t[2] = CL_add( x[1], x[5] ); + t[3] = CL_sub( x[1], x[5] ); + t[4] = CL_add( x[2], x[6] ); + t[5] = CL_sub( x[2], x[6] ); + t[6] = CL_add( x[3], x[7] ); + t[7] = CL_sub( x[3], x[7] ); /* Pre-additions and core multiplications */ - s[0] = CL_add(t[0], t[4]); - s[2] = CL_sub(t[0], t[4]); - s[4] = CL_mac_j(t[1], t[5]); - s[5] = CL_msu_j(t[1], t[5]); - s[1] = CL_add(t[2], t[6]); - s[3] = CL_sub(t[2], t[6]); - s[3] = CL_mul_j(s[3]); + s[0] = CL_add( t[0], t[4] ); + s[2] = CL_sub( t[0], t[4] ); + s[4] = CL_mac_j( t[1], t[5] ); + s[5] = CL_msu_j( t[1], t[5] ); + s[1] = CL_add( t[2], t[6] ); + s[3] = CL_sub( t[2], t[6] ); + s[3] = CL_mul_j( s[3] ); - temp = CL_add(t[3], t[7]); - temp1 = CL_sub(t[3], t[7]); - s[6] = CL_scale_t(CL_msu_j(temp1, temp), C81); - s[7] = CL_dscale_t(CL_swap_real_imag( CL_msu_j(temp, temp1)), C81, C82); + temp = CL_add( t[3], t[7] ); + temp1 = CL_sub( t[3], t[7] ); + s[6] = CL_scale_t( CL_msu_j( temp1, temp ), C81 ); + s[7] = CL_dscale_t( CL_swap_real_imag( CL_msu_j( temp, temp1 ) ), C81, C82 ); /* Post-additions */ - y[24] = CL_add(s[0],s[1]); - y[28] = CL_sub(s[0],s[1]); - y[26] = CL_sub(s[2],s[3]); - y[30] = CL_add(s[2],s[3]); - y[27] = CL_add(s[4],s[7]); - y[31] = CL_sub(s[4],s[7]); - y[25] = CL_add(s[5],s[6]); - y[29] = CL_sub(s[5],s[6]); + y[24] = CL_add( s[0], s[1] ); + y[28] = CL_sub( s[0], s[1] ); + y[26] = CL_sub( s[2], s[3] ); + y[30] = CL_add( s[2], s[3] ); + y[27] = CL_add( s[4], s[7] ); + y[31] = CL_sub( s[4], s[7] ); + y[25] = CL_add( s[5], s[6] ); + y[29] = CL_sub( s[5], s[6] ); /* apply twiddle factors */ - y[0] = CL_shr(y[0],SCALEFACTOR32_2); - y[1] = CL_shr(y[1],SCALEFACTOR32_2); - y[2] = CL_shr(y[2],SCALEFACTOR32_2); - y[3] = CL_shr(y[3],SCALEFACTOR32_2); - y[4] = CL_shr(y[4],SCALEFACTOR32_2); - y[5] = CL_shr(y[5],SCALEFACTOR32_2); - y[6] = CL_shr(y[6],SCALEFACTOR32_2); - y[7] = CL_shr(y[7],SCALEFACTOR32_2); - y[8] = CL_shr(y[8],SCALEFACTOR32_2); - y[16] = CL_shr(y[16],SCALEFACTOR32_2); - y[24] = CL_shr(y[24],SCALEFACTOR32_2); - y[20] = CL_shr(y[20],SCALEFACTOR32_2); - - - y[9] = CL_mult_32x16((CL_shr(y[9],1)), pRotVector_32[ 0 ]); - y[10] = CL_mult_32x16((CL_shr(y[10],1)), pRotVector_32[ 1 ]); - y[11] = CL_mult_32x16((CL_shr(y[11],1)), pRotVector_32[ 2 ]); - y[12] = CL_mult_32x16((CL_shr(y[12],1)), pRotVector_32[ 3 ]); - y[13] = CL_mult_32x16((CL_shr(y[13],1)), pRotVector_32[ 4 ]); - y[14] = CL_mult_32x16((CL_shr(y[14],1)), pRotVector_32[ 5 ]); - y[15] = CL_mult_32x16((CL_shr(y[15],1)), pRotVector_32[ 6 ]); - y[17] = CL_mult_32x16((CL_shr(y[17],1)), pRotVector_32[ 7 ]); - y[18] = CL_mult_32x16((CL_shr(y[18],1)), pRotVector_32[ 8 ]); - y[19] = CL_mult_32x16((CL_shr(y[19],1)), pRotVector_32[ 9 ]); - y[21] = CL_mult_32x16((CL_shr(y[21],1)), pRotVector_32[ 10 ]); - y[22] = CL_mult_32x16((CL_shr(y[22],1)), pRotVector_32[ 11 ]); - y[23] = CL_mult_32x16((CL_shr(y[23],1)), pRotVector_32[ 12 ]); - y[25] = CL_mult_32x16((CL_shr(y[25],1)), pRotVector_32[ 13 ]); - y[26] = CL_mult_32x16((CL_shr(y[26],1)), pRotVector_32[ 14 ]); - y[27] = CL_mult_32x16((CL_shr(y[27],1)), pRotVector_32[ 15 ]); - y[28] = CL_mult_32x16((CL_shr(y[28],1)), pRotVector_32[ 16 ]); - y[29] = CL_mult_32x16((CL_shr(y[29],1)), pRotVector_32[ 17 ]); - y[30] = CL_mult_32x16((CL_shr(y[30],1)), pRotVector_32[ 18 ]); - y[31] = CL_mult_32x16((CL_shr(y[31],1)), pRotVector_32[ 19 ]); + y[0] = CL_shr( y[0], SCALEFACTOR32_2 ); + y[1] = CL_shr( y[1], SCALEFACTOR32_2 ); + y[2] = CL_shr( y[2], SCALEFACTOR32_2 ); + y[3] = CL_shr( y[3], SCALEFACTOR32_2 ); + y[4] = CL_shr( y[4], SCALEFACTOR32_2 ); + y[5] = CL_shr( y[5], SCALEFACTOR32_2 ); + y[6] = CL_shr( y[6], SCALEFACTOR32_2 ); + y[7] = CL_shr( y[7], SCALEFACTOR32_2 ); + y[8] = CL_shr( y[8], SCALEFACTOR32_2 ); + y[16] = CL_shr( y[16], SCALEFACTOR32_2 ); + y[24] = CL_shr( y[24], SCALEFACTOR32_2 ); + y[20] = CL_shr( y[20], SCALEFACTOR32_2 ); + + + y[9] = CL_mult_32x16( ( CL_shr( y[9], 1 ) ), pRotVector_32[0] ); + y[10] = CL_mult_32x16( ( CL_shr( y[10], 1 ) ), pRotVector_32[1] ); + y[11] = CL_mult_32x16( ( CL_shr( y[11], 1 ) ), pRotVector_32[2] ); + y[12] = CL_mult_32x16( ( CL_shr( y[12], 1 ) ), pRotVector_32[3] ); + y[13] = CL_mult_32x16( ( CL_shr( y[13], 1 ) ), pRotVector_32[4] ); + y[14] = CL_mult_32x16( ( CL_shr( y[14], 1 ) ), pRotVector_32[5] ); + y[15] = CL_mult_32x16( ( CL_shr( y[15], 1 ) ), pRotVector_32[6] ); + y[17] = CL_mult_32x16( ( CL_shr( y[17], 1 ) ), pRotVector_32[7] ); + y[18] = CL_mult_32x16( ( CL_shr( y[18], 1 ) ), pRotVector_32[8] ); + y[19] = CL_mult_32x16( ( CL_shr( y[19], 1 ) ), pRotVector_32[9] ); + y[21] = CL_mult_32x16( ( CL_shr( y[21], 1 ) ), pRotVector_32[10] ); + y[22] = CL_mult_32x16( ( CL_shr( y[22], 1 ) ), pRotVector_32[11] ); + y[23] = CL_mult_32x16( ( CL_shr( y[23], 1 ) ), pRotVector_32[12] ); + y[25] = CL_mult_32x16( ( CL_shr( y[25], 1 ) ), pRotVector_32[13] ); + y[26] = CL_mult_32x16( ( CL_shr( y[26], 1 ) ), pRotVector_32[14] ); + y[27] = CL_mult_32x16( ( CL_shr( y[27], 1 ) ), pRotVector_32[15] ); + y[28] = CL_mult_32x16( ( CL_shr( y[28], 1 ) ), pRotVector_32[16] ); + y[29] = CL_mult_32x16( ( CL_shr( y[29], 1 ) ), pRotVector_32[17] ); + y[30] = CL_mult_32x16( ( CL_shr( y[30], 1 ) ), pRotVector_32[18] ); + y[31] = CL_mult_32x16( ( CL_shr( y[31], 1 ) ), pRotVector_32[19] ); /* 1. FFT4 stage */ /* Pre-additions */ - t[0] = CL_add(y[0],y[16]); - t[1] = CL_sub(y[0],y[16]); - t[2] = CL_add(y[8],y[24]); - t[3] = CL_mul_j(CL_sub(y[8],y[24])); + t[0] = CL_add( y[0], y[16] ); + t[1] = CL_sub( y[0], y[16] ); + t[2] = CL_add( y[8], y[24] ); + t[3] = CL_mul_j( CL_sub( y[8], y[24] ) ); /* Post-additions */ - inp[0] = CL_add(t[0], t[2]); - inp[8] = CL_sub(t[1], t[3]); - inp[16] = CL_sub(t[0], t[2]); - inp[24] = CL_add(t[1], t[3]); + inp[0] = CL_add( t[0], t[2] ); + inp[8] = CL_sub( t[1], t[3] ); + inp[16] = CL_sub( t[0], t[2] ); + inp[24] = CL_add( t[1], t[3] ); /* 2. FFT4 stage */ /* Pre-additions */ - t[0] = CL_add(y[1],y[17]); - t[1] = CL_sub(y[1],y[17]); - t[2] = CL_add(y[9],y[25]); - t[3] = CL_mul_j(CL_sub(y[9],y[25])); + t[0] = CL_add( y[1], y[17] ); + t[1] = CL_sub( y[1], y[17] ); + t[2] = CL_add( y[9], y[25] ); + t[3] = CL_mul_j( CL_sub( y[9], y[25] ) ); /* Post-additions */ - inp[1] = CL_add(t[0], t[2]); - inp[9] = CL_sub(t[1], t[3]); - inp[17] = CL_sub(t[0], t[2]); - inp[25] = CL_add(t[1], t[3]); + inp[1] = CL_add( t[0], t[2] ); + inp[9] = CL_sub( t[1], t[3] ); + inp[17] = CL_sub( t[0], t[2] ); + inp[25] = CL_add( t[1], t[3] ); /* 3. FFT4 stage */ /* Pre-additions */ - t[0] = CL_add(y[2],y[18]); - t[1] = CL_sub(y[2],y[18]); - t[2] = CL_add(y[10],y[26]); - t[3] = CL_mul_j(CL_sub(y[10],y[26])); + t[0] = CL_add( y[2], y[18] ); + t[1] = CL_sub( y[2], y[18] ); + t[2] = CL_add( y[10], y[26] ); + t[3] = CL_mul_j( CL_sub( y[10], y[26] ) ); /* Post-additions */ - inp[2] = CL_add(t[0], t[2]); - inp[10] = CL_sub(t[1], t[3]); - inp[18] = CL_sub(t[0], t[2]); - inp[26] = CL_add(t[1], t[3]); + inp[2] = CL_add( t[0], t[2] ); + inp[10] = CL_sub( t[1], t[3] ); + inp[18] = CL_sub( t[0], t[2] ); + inp[26] = CL_add( t[1], t[3] ); /* 4. FFT4 stage */ /* Pre-additions */ - t[0] = CL_add(y[3],y[19]); - t[1] = CL_sub(y[3],y[19]); - t[2] = CL_add(y[11],y[27]); - t[3] = CL_mul_j(CL_sub(y[11],y[27])); + t[0] = CL_add( y[3], y[19] ); + t[1] = CL_sub( y[3], y[19] ); + t[2] = CL_add( y[11], y[27] ); + t[3] = CL_mul_j( CL_sub( y[11], y[27] ) ); /* Post-additions */ - inp[3] = CL_add(t[0], t[2]); - inp[11] = CL_sub(t[1], t[3]); - inp[19] = CL_sub(t[0], t[2]); - inp[27] = CL_add(t[1], t[3]); + inp[3] = CL_add( t[0], t[2] ); + inp[11] = CL_sub( t[1], t[3] ); + inp[19] = CL_sub( t[0], t[2] ); + inp[27] = CL_add( t[1], t[3] ); /* 5. FFT4 stage */ /* Pre-additions */ - t[0] = CL_msu_j(y[4],y[20]); - t[1] = CL_mac_j(y[4],y[20]); - t[2] = CL_add(y[12],y[28]); - t[3] = CL_mul_j(CL_sub(y[12],y[28])); + t[0] = CL_msu_j( y[4], y[20] ); + t[1] = CL_mac_j( y[4], y[20] ); + t[2] = CL_add( y[12], y[28] ); + t[3] = CL_mul_j( CL_sub( y[12], y[28] ) ); /* Post-additions */ - inp[4] = CL_add(t[0], t[2]); - inp[12] = CL_sub(t[1], t[3]); - inp[20] = CL_sub(t[0], t[2]); - inp[28] = CL_add(t[1], t[3]); + inp[4] = CL_add( t[0], t[2] ); + inp[12] = CL_sub( t[1], t[3] ); + inp[20] = CL_sub( t[0], t[2] ); + inp[28] = CL_add( t[1], t[3] ); /* 6. FFT4 stage */ /* Pre-additions */ - t[0] = CL_add(y[5],y[21]); - t[1] = CL_sub(y[5],y[21]); - t[2] = CL_add(y[13],y[29]); - t[3] = CL_mul_j(CL_sub(y[13],y[29])); + t[0] = CL_add( y[5], y[21] ); + t[1] = CL_sub( y[5], y[21] ); + t[2] = CL_add( y[13], y[29] ); + t[3] = CL_mul_j( CL_sub( y[13], y[29] ) ); /* Post-additions */ - inp[5] = CL_add(t[0], t[2]); - inp[13] = CL_sub(t[1], t[3]); - inp[21] = CL_sub(t[0], t[2]); - inp[29] = CL_add(t[1], t[3]); + inp[5] = CL_add( t[0], t[2] ); + inp[13] = CL_sub( t[1], t[3] ); + inp[21] = CL_sub( t[0], t[2] ); + inp[29] = CL_add( t[1], t[3] ); /* 7. FFT4 stage */ /* Pre-additions */ - t[0] = CL_add(y[6],y[22]); - t[1] = CL_sub(y[6],y[22]); - t[2] = CL_add(y[14],y[30]); - t[3] = CL_mul_j(CL_sub(y[14],y[30])); + t[0] = CL_add( y[6], y[22] ); + t[1] = CL_sub( y[6], y[22] ); + t[2] = CL_add( y[14], y[30] ); + t[3] = CL_mul_j( CL_sub( y[14], y[30] ) ); /* Post-additions */ - inp[6] = CL_add(t[0], t[2]); - inp[14] = CL_sub(t[1], t[3]); - inp[22] = CL_sub(t[0], t[2]); - inp[30] = CL_add(t[1], t[3]); + inp[6] = CL_add( t[0], t[2] ); + inp[14] = CL_sub( t[1], t[3] ); + inp[22] = CL_sub( t[0], t[2] ); + inp[30] = CL_add( t[1], t[3] ); /* 8. FFT4 stage */ /* Pre-additions */ - t[0] = CL_add(y[7],y[23]); - t[1] = CL_sub(y[7],y[23]); - t[2] = CL_add(y[15],y[31]); - t[3] = CL_mul_j(CL_sub(y[15],y[31])); + t[0] = CL_add( y[7], y[23] ); + t[1] = CL_sub( y[7], y[23] ); + t[2] = CL_add( y[15], y[31] ); + t[3] = CL_mul_j( CL_sub( y[15], y[31] ) ); /* Post-additions */ - inp[7] = CL_add(t[0], t[2]); - inp[15] = CL_sub(t[1], t[3]); - inp[23] = CL_sub(t[0], t[2]); - inp[31] = CL_add(t[1], t[3]); + inp[7] = CL_add( t[0], t[2] ); + inp[15] = CL_sub( t[1], t[3] ); + inp[23] = CL_sub( t[0], t[2] ); + inp[31] = CL_add( t[1], t[3] ); -#if (WMOPS) +#if ( WMOPS ) multiCounter[currCounter].CL_move += 32; -#endif - - +#endif } @@ -1831,317 +1834,310 @@ static void fft32_with_cmplx_data(cmplx * inp) */ static void fftN2( - cmplx *__restrict pComplexBuf, - const Word16 *__restrict W, - Word16 len, - Word16 dim1, - Word16 dim2, - Word16 sc, - Word32 *x, - Word16 Woff -) + cmplx *__restrict pComplexBuf, + const Word16 *__restrict W, + Word16 len, + Word16 dim1, + Word16 dim2, + Word16 sc, + Word32 *x, + Word16 Woff ) { - Word16 i, j; - cmplx *x_cmplx = (cmplx *)x; - - assert(len == (dim1*dim2)); - assert((dim1 == 3) || (dim1 == 5) || (dim1 == 8) || (dim1 == 10) || (dim1 == 15) || (dim1 == 16) || (dim1 == 20) || (dim1 == 30) || (dim1 == 32)); - assert((dim2 == 4) || (dim2 == 8) || (dim2 == 10) || (dim2 == 12) || (dim2 == 16) || (dim2 == 20)); - - FOR(i = 0; i= 2; j -= 2 ) @@ -2206,7 +2206,7 @@ void edct2_fx_ivas( a[1] = L_sub( a[0], xr ); a[0] = L_add( a[0], xr ); - IF ( GT_16(n, 4) ) + IF( GT_16( n, 4 ) ) { rftbsub( n, a, nc, w + nw ); bitrv2_SR( n, ip + 2, a ); @@ -2218,16 +2218,16 @@ void edct2_fx_ivas( } } - IF ( GE_16(isgn, 0) ) + IF( GE_16( isgn, 0 ) ) { a[0] = L_shr( a[0], 1 ); } dctsub( n, a, nc, w + nw ); - IF ( GE_16(isgn, 0) ) + IF( GE_16( isgn, 0 ) ) { - IF ( GT_16(n, 4) ) + IF( GT_16( n, 4 ) ) { bitrv2_SR( n, ip + 2, a ); cftfsub( n, a, w ); @@ -2254,8 +2254,8 @@ void edct2_fx_ivas( } void DoRTFTn_fx_ivas( - Word32 *x, /* i/o: real part of input and output data */ - Word32 *y, /* i/o: imaginary part of input and output data */ + Word32 *x, /* i/o: real part of input and output data */ + Word32 *y, /* i/o: imaginary part of input and output data */ const Word16 n /* i : size of the FFT up to 1024 */ ) { @@ -2349,7 +2349,7 @@ void fft3_fx_ivas( Z2 = &Z1[m]; z2 = &Z2[0]; /* Z2 = &Z[2m]; */ x = &X[0]; - FOR ( i = 0; i < n / 3; i++ ) + FOR( i = 0; i < n / 3; i++ ) { *z0++ = *x++; /* Z0[i] = X[3i]; */ *z1++ = *x++; /* Z1[i] = X[3i+1]; */ @@ -2371,121 +2371,121 @@ void fft3_fx_ivas( RZ2 = &Z2[0]; IZ2 = &Z2[m]; - c1_step = negate(step); + c1_step = negate( step ); s1_step = step; - c2_step = negate(shl(step, 1)); - s2_step = shl(step, 1); - c1_ind = add(T_SIN_PI_2, c1_step); + c2_step = negate( shl( step, 1 ) ); + s2_step = shl( step, 1 ); + c1_ind = add( T_SIN_PI_2, c1_step ); s1_ind = s1_step; - c2_ind = add(T_SIN_PI_2, c2_step); + c2_ind = add( T_SIN_PI_2, c2_step ); s2_ind = s2_step; /* special case: i = 0 */ - RY[0] = L_add(RZ0[0], L_add(RZ1[0], RZ2[0])); + RY[0] = L_add( RZ0[0], L_add( RZ1[0], RZ2[0] ) ); /* first 3/12 */ - for (i = 1; i < 3 * m / 8; i++, c1_ind = add(c1_ind, c1_step), s1_ind = add(s1_ind, s1_step), c2_ind = add(c2_ind,c2_step), s2_ind = add(s2_ind, s2_step)) - { - RY[i] = L_add(RZ0[i], L_add(Mpy_32_16_1(RZ1[i], t_sin[c1_ind]), - L_add(Mpy_32_16_1(IZ1[-i], t_sin[s1_ind]), - L_add(Mpy_32_16_1(RZ2[i], t_sin[c2_ind]), - Mpy_32_16_1(IZ2[-i], t_sin[s2_ind]))))); - IY[-i] = L_sub(IZ0[-i], L_add(L_sub(Mpy_32_16_1(RZ1[i], t_sin[s1_ind]), - Mpy_32_16_1(IZ1[-i], t_sin[c1_ind])), - L_sub(Mpy_32_16_1(RZ2[i], t_sin[s2_ind]), - Mpy_32_16_1(IZ2[-i], t_sin[c2_ind])))); + for ( i = 1; i < 3 * m / 8; i++, c1_ind = add( c1_ind, c1_step ), s1_ind = add( s1_ind, s1_step ), c2_ind = add( c2_ind, c2_step ), s2_ind = add( s2_ind, s2_step ) ) + { + RY[i] = L_add( RZ0[i], L_add( Mpy_32_16_1( RZ1[i], t_sin[c1_ind] ), + L_add( Mpy_32_16_1( IZ1[-i], t_sin[s1_ind] ), + L_add( Mpy_32_16_1( RZ2[i], t_sin[c2_ind] ), + Mpy_32_16_1( IZ2[-i], t_sin[s2_ind] ) ) ) ) ); + IY[-i] = L_sub( IZ0[-i], L_add( L_sub( Mpy_32_16_1( RZ1[i], t_sin[s1_ind] ), + Mpy_32_16_1( IZ1[-i], t_sin[c1_ind] ) ), + L_sub( Mpy_32_16_1( RZ2[i], t_sin[s2_ind] ), + Mpy_32_16_1( IZ2[-i], t_sin[c2_ind] ) ) ) ); } /* next 1/12 */ - for ( ; i < 4 * m / 8; i++, c1_ind = add(c1_ind, c1_step), s1_ind = add(s1_ind, s1_step), c2_ind = sub(c2_ind, c2_step), s2_ind = sub(s2_ind, s2_step) ) - { - RY[i] = L_add(RZ0[i], L_sub(L_add(Mpy_32_16_1(RZ1[i], t_sin[c1_ind]), - Mpy_32_16_1(IZ1[-i], t_sin[s1_ind])), - L_sub(Mpy_32_16_1(RZ2[i], t_sin[c2_ind]), - Mpy_32_16_1(IZ2[-i], t_sin[s2_ind])))); - IY[-i] = L_sub(IZ0[-i], L_sub(Mpy_32_16_1(RZ1[ i], t_sin[s1_ind]), - L_sub(Mpy_32_16_1(IZ1[-i], t_sin[c1_ind]), - L_add(Mpy_32_16_1(RZ2[ i], t_sin[s2_ind]), - Mpy_32_16_1(IZ2[-i], t_sin[c2_ind]))))); + for ( ; i < 4 * m / 8; i++, c1_ind = add( c1_ind, c1_step ), s1_ind = add( s1_ind, s1_step ), c2_ind = sub( c2_ind, c2_step ), s2_ind = sub( s2_ind, s2_step ) ) + { + RY[i] = L_add( RZ0[i], L_sub( L_add( Mpy_32_16_1( RZ1[i], t_sin[c1_ind] ), + Mpy_32_16_1( IZ1[-i], t_sin[s1_ind] ) ), + L_sub( Mpy_32_16_1( RZ2[i], t_sin[c2_ind] ), + Mpy_32_16_1( IZ2[-i], t_sin[s2_ind] ) ) ) ); + IY[-i] = L_sub( IZ0[-i], L_sub( Mpy_32_16_1( RZ1[i], t_sin[s1_ind] ), + L_sub( Mpy_32_16_1( IZ1[-i], t_sin[c1_ind] ), + L_add( Mpy_32_16_1( RZ2[i], t_sin[s2_ind] ), + Mpy_32_16_1( IZ2[-i], t_sin[c2_ind] ) ) ) ) ); } /* special case: i = m/2 i.e. 1/3 */ - RY[i] = L_add(RZ0[i], - L_sub(Mpy_32_16_1(RZ1[i], t_sin[c1_ind]), - Mpy_32_16_1(RZ2[i], t_sin[c2_ind]))); - IY[-i] = L_negate(L_add(Mpy_32_16_1(RZ1[i], t_sin[s1_ind]), - Mpy_32_16_1(RZ2[i], t_sin[s2_ind]))); + RY[i] = L_add( RZ0[i], + L_sub( Mpy_32_16_1( RZ1[i], t_sin[c1_ind] ), + Mpy_32_16_1( RZ2[i], t_sin[c2_ind] ) ) ); + IY[-i] = L_negate( L_add( Mpy_32_16_1( RZ1[i], t_sin[s1_ind] ), + Mpy_32_16_1( RZ2[i], t_sin[s2_ind] ) ) ); i++; - c1_ind = add(c1_ind, c1_step); - s1_ind = add(s1_ind, s1_step); - c2_ind = sub(c2_ind, c2_step); - s2_ind = sub(s2_ind, s2_step); + c1_ind = add( c1_ind, c1_step ); + s1_ind = add( s1_ind, s1_step ); + c2_ind = sub( c2_ind, c2_step ); + s2_ind = sub( s2_ind, s2_step ); /* next 2/12 */ - for ( j = i - 2; i < 6 * m / 8; i++, j--, c1_ind = add(c1_ind, c1_step), s1_ind = add(s1_ind, s1_step), c2_ind = sub(c2_ind, c2_step), s2_ind = sub(s2_ind, s2_step) ) + for ( j = i - 2; i < 6 * m / 8; i++, j--, c1_ind = add( c1_ind, c1_step ), s1_ind = add( s1_ind, s1_step ), c2_ind = sub( c2_ind, c2_step ), s2_ind = sub( s2_ind, s2_step ) ) { - RY[i] = L_add(RZ0[j], L_sub(Mpy_32_16_1(RZ1[j], t_sin[c1_ind]), - L_add(Mpy_32_16_1(IZ1[-j], t_sin[s1_ind]), - L_add(Mpy_32_16_1(RZ2[j], t_sin[c2_ind]), - Mpy_32_16_1(IZ2[-j], t_sin[s2_ind]))))); + RY[i] = L_add( RZ0[j], L_sub( Mpy_32_16_1( RZ1[j], t_sin[c1_ind] ), + L_add( Mpy_32_16_1( IZ1[-j], t_sin[s1_ind] ), + L_add( Mpy_32_16_1( RZ2[j], t_sin[c2_ind] ), + Mpy_32_16_1( IZ2[-j], t_sin[s2_ind] ) ) ) ) ); - IY[-i] = L_negate(L_add(IZ0[-j], L_add(Mpy_32_16_1(RZ1[j], t_sin[s1_ind]), - L_add(Mpy_32_16_1(IZ1[-j], t_sin[c1_ind]), - L_sub(Mpy_32_16_1(RZ2[j], t_sin[s2_ind]), - Mpy_32_16_1(IZ2[-j], t_sin[c2_ind])))))); + IY[-i] = L_negate( L_add( IZ0[-j], L_add( Mpy_32_16_1( RZ1[j], t_sin[s1_ind] ), + L_add( Mpy_32_16_1( IZ1[-j], t_sin[c1_ind] ), + L_sub( Mpy_32_16_1( RZ2[j], t_sin[s2_ind] ), + Mpy_32_16_1( IZ2[-j], t_sin[c2_ind] ) ) ) ) ) ); } /*--------------------------half--------------------------*/ /* next 2/12 */ - for ( ; i < 8 * m / 8; i++, j--, c1_ind = sub(c1_ind, c1_step), s1_ind = sub(s1_ind, s1_step), c2_ind = add(c2_ind, c2_step), s2_ind = add(s2_ind, s2_step) ) - { - RY[i] = L_sub(RZ0[j], L_add(Mpy_32_16_1(RZ1[j], t_sin[c1_ind]), - L_add(Mpy_32_16_1(IZ1[-j], t_sin[s1_ind]), - L_sub(Mpy_32_16_1(RZ2[j], t_sin[c2_ind]), - Mpy_32_16_1(IZ2[-j], t_sin[s2_ind]))))); - IY[-i] = L_negate(L_add(IZ0[-j], L_sub(Mpy_32_16_1(RZ1[j], t_sin[s1_ind]), - L_add(Mpy_32_16_1(IZ1[-j], t_sin[c1_ind]), - L_add(Mpy_32_16_1(RZ2[j], t_sin[s2_ind]), - Mpy_32_16_1(IZ2[-j], t_sin[c2_ind])))))); + for ( ; i < 8 * m / 8; i++, j--, c1_ind = sub( c1_ind, c1_step ), s1_ind = sub( s1_ind, s1_step ), c2_ind = add( c2_ind, c2_step ), s2_ind = add( s2_ind, s2_step ) ) + { + RY[i] = L_sub( RZ0[j], L_add( Mpy_32_16_1( RZ1[j], t_sin[c1_ind] ), + L_add( Mpy_32_16_1( IZ1[-j], t_sin[s1_ind] ), + L_sub( Mpy_32_16_1( RZ2[j], t_sin[c2_ind] ), + Mpy_32_16_1( IZ2[-j], t_sin[s2_ind] ) ) ) ) ); + IY[-i] = L_negate( L_add( IZ0[-j], L_sub( Mpy_32_16_1( RZ1[j], t_sin[s1_ind] ), + L_add( Mpy_32_16_1( IZ1[-j], t_sin[c1_ind] ), + L_add( Mpy_32_16_1( RZ2[j], t_sin[s2_ind] ), + Mpy_32_16_1( IZ2[-j], t_sin[c2_ind] ) ) ) ) ) ); } /* special case: i = m, i.e 2/3 */ - RY[i] = L_sub(RZ0[j], L_add(Mpy_32_16_1(RZ1[j], t_sin[c1_ind]), - Mpy_32_16_1(RZ2[j], t_sin[c2_ind]))); - IY[-i++] = L_sub(Mpy_32_16_1(RZ2[j], t_sin[s2_ind]), - Mpy_32_16_1(RZ1[j], t_sin[s1_ind])); - c1_ind = sub(c1_ind, c1_step), s1_ind = sub(s1_ind, s1_step), c2_ind = add(c2_ind, c2_step), s2_ind = add(s2_ind, s2_step); + RY[i] = L_sub( RZ0[j], L_add( Mpy_32_16_1( RZ1[j], t_sin[c1_ind] ), + Mpy_32_16_1( RZ2[j], t_sin[c2_ind] ) ) ); + IY[-i++] = L_sub( Mpy_32_16_1( RZ2[j], t_sin[s2_ind] ), + Mpy_32_16_1( RZ1[j], t_sin[s1_ind] ) ); + c1_ind = sub( c1_ind, c1_step ), s1_ind = sub( s1_ind, s1_step ), c2_ind = add( c2_ind, c2_step ), s2_ind = add( s2_ind, s2_step ); /* next 1/12 */ - for ( j = 1; i < 9 * m / 8; i++, j++, c1_ind = sub(c1_ind, c1_step), s1_ind = sub(s1_ind, s1_step), c2_ind = add(c2_ind, c2_step), s2_ind = add(s2_ind, s2_step) ) - { - RY[i] = L_sub(RZ0[j], L_sub(Mpy_32_16_1(RZ1[j], t_sin[c1_ind]), - L_sub(Mpy_32_16_1(IZ1[-j], t_sin[s1_ind]), - L_add(Mpy_32_16_1(RZ2[j], t_sin[c2_ind]), - Mpy_32_16_1(IZ2[-j], t_sin[s2_ind]))))); - IY[-i] = L_sub(IZ0[-j], L_add(Mpy_32_16_1(RZ1[j], t_sin[s1_ind]), - L_sub(Mpy_32_16_1(IZ1[-j], t_sin[c1_ind]), - L_sub(Mpy_32_16_1(RZ2[j], t_sin[s2_ind]), - Mpy_32_16_1(IZ2[-j], t_sin[c2_ind]))))); + for ( j = 1; i < 9 * m / 8; i++, j++, c1_ind = sub( c1_ind, c1_step ), s1_ind = sub( s1_ind, s1_step ), c2_ind = add( c2_ind, c2_step ), s2_ind = add( s2_ind, s2_step ) ) + { + RY[i] = L_sub( RZ0[j], L_sub( Mpy_32_16_1( RZ1[j], t_sin[c1_ind] ), + L_sub( Mpy_32_16_1( IZ1[-j], t_sin[s1_ind] ), + L_add( Mpy_32_16_1( RZ2[j], t_sin[c2_ind] ), + Mpy_32_16_1( IZ2[-j], t_sin[s2_ind] ) ) ) ) ); + IY[-i] = L_sub( IZ0[-j], L_add( Mpy_32_16_1( RZ1[j], t_sin[s1_ind] ), + L_sub( Mpy_32_16_1( IZ1[-j], t_sin[c1_ind] ), + L_sub( Mpy_32_16_1( RZ2[j], t_sin[s2_ind] ), + Mpy_32_16_1( IZ2[-j], t_sin[c2_ind] ) ) ) ) ); } /* last 3/12 */ - for ( ; i < 12 * m / 8; i++, j++, c1_ind = sub(c1_ind, c1_step), s1_ind = sub(s1_ind, s1_step), c2_ind = sub(c2_ind, c2_step), s2_ind = sub(s2_ind, s2_step) ) - { - RY[i] = L_sub(RZ0[j], L_sub(L_sub(Mpy_32_16_1(RZ1[j], t_sin[c1_ind]), - Mpy_32_16_1(IZ1[-j], t_sin[s1_ind])), - L_sub(Mpy_32_16_1(RZ2[j], t_sin[c2_ind]), - Mpy_32_16_1(IZ2[-j], t_sin[s2_ind])))); - IY[-i] = L_sub(IZ0[-j], L_sub(L_add(Mpy_32_16_1(RZ1[j], t_sin[s1_ind]), - Mpy_32_16_1(IZ1[-j], t_sin[c1_ind])), - L_add(Mpy_32_16_1(RZ2[j], t_sin[s2_ind]), - Mpy_32_16_1(IZ2[-j], t_sin[c2_ind])))); + for ( ; i < 12 * m / 8; i++, j++, c1_ind = sub( c1_ind, c1_step ), s1_ind = sub( s1_ind, s1_step ), c2_ind = sub( c2_ind, c2_step ), s2_ind = sub( s2_ind, s2_step ) ) + { + RY[i] = L_sub( RZ0[j], L_sub( L_sub( Mpy_32_16_1( RZ1[j], t_sin[c1_ind] ), + Mpy_32_16_1( IZ1[-j], t_sin[s1_ind] ) ), + L_sub( Mpy_32_16_1( RZ2[j], t_sin[c2_ind] ), + Mpy_32_16_1( IZ2[-j], t_sin[s2_ind] ) ) ) ); + IY[-i] = L_sub( IZ0[-j], L_sub( L_add( Mpy_32_16_1( RZ1[j], t_sin[s1_ind] ), + Mpy_32_16_1( IZ1[-j], t_sin[c1_ind] ) ), + L_add( Mpy_32_16_1( RZ2[j], t_sin[s2_ind] ), + Mpy_32_16_1( IZ2[-j], t_sin[c2_ind] ) ) ) ); } /* special case: i = 3*m/2 */ - RY[i] = L_sub(RZ0[j], L_sub(Mpy_32_16_1(RZ1[j], t_sin[c1_ind]), - Mpy_32_16_1(RZ2[j], t_sin[c2_ind]))); + RY[i] = L_sub( RZ0[j], L_sub( Mpy_32_16_1( RZ1[j], t_sin[c1_ind] ), + Mpy_32_16_1( RZ2[j], t_sin[c2_ind] ) ) ); return; } @@ -2542,15 +2542,15 @@ void ifft3_fx_ivas( /* Inverse butterflies of order 3. */ /* Construction of Y0 */ - RY0[0] = L_add(RZ0[0], L_add(RZ1[0], RZ2[0])); - FOR ( i = 1; i < m / 2; i++ ) + RY0[0] = L_add( RZ0[0], L_add( RZ1[0], RZ2[0] ) ); + FOR( i = 1; i < m / 2; i++ ) { - RY0[i] = L_add(RZ0[i], L_add(RZ1[i], RZ2[-i])); - IY0[-i] = L_add(IZ0[-i], L_sub(IZ1[-i], IZ2[i])); + RY0[i] = L_add( RZ0[i], L_add( RZ1[i], RZ2[-i] ) ); + IY0[-i] = L_add( IZ0[-i], L_sub( IZ1[-i], IZ2[i] ) ); } /* m/2 */ - RY0[i] = L_add(RZ0[i], L_add(RZ1[i], RZ2[-i])); + RY0[i] = L_add( RZ0[i], L_add( RZ1[i], RZ2[-i] ) ); /* Construction of Y1 */ c0_ind = T_SIN_PI_2; @@ -2560,57 +2560,57 @@ void ifft3_fx_ivas( c2_ind = T_SIN_PI_2 * 1 / 3; s2_ind = T_SIN_PI_2 * 2 / 3; - RY1[0] = L_sub(Mpy_32_16_1(RZ0[0], t_sin[c0_ind]), - L_add(Mpy_32_16_1(RZ1[0], t_sin[c1_ind]), - L_add(Mpy_32_16_1(RZ2[0], t_sin[c2_ind]), - L_add(Mpy_32_16_1(IZ1[0], t_sin[s1_ind]), - Mpy_32_16_1(IZ2[0], t_sin[s2_ind]))))); - - c0_ind = sub(c0_ind, step); - s0_ind = add(s0_ind, step); - c1_ind = add(c1_ind, step); - s1_ind = sub(s1_ind, step); - c2_ind = sub(c2_ind, step); - s2_ind = add(s2_ind, step); - for ( i = 1; i < m / 4; i++, c0_ind = sub(c0_ind, step), s0_ind = add(s0_ind, step), c1_ind = add(c1_ind, step), s1_ind = sub(s1_ind, step), c2_ind = sub(c2_ind, step), s2_ind = add(s2_ind, step) ) - { - RY1[i] = L_sub(Mpy_32_16_1(RZ0[i], t_sin[c0_ind]), - L_add(Mpy_32_16_1(RZ1[i], t_sin[c1_ind]), - L_add(Mpy_32_16_1(RZ2[-i], t_sin[c2_ind]), - L_add(Mpy_32_16_1(IZ0[-i], t_sin[s0_ind]), - L_add(Mpy_32_16_1(IZ1[-i], t_sin[s1_ind]), - Mpy_32_16_1(IZ2[i], t_sin[s2_ind])))))); - IY1[-i] = L_add(L_sub(Mpy_32_16_1(IZ0[-i], t_sin[c0_ind]), - Mpy_32_16_1(IZ1[-i], t_sin[c1_ind])), - L_add(Mpy_32_16_1(IZ2[i], t_sin[c2_ind]), - L_add(Mpy_32_16_1(RZ0[i], t_sin[s0_ind]), - L_sub(Mpy_32_16_1(RZ1[i], t_sin[s1_ind]), - Mpy_32_16_1(RZ2[-i], t_sin[s2_ind]))))); + RY1[0] = L_sub( Mpy_32_16_1( RZ0[0], t_sin[c0_ind] ), + L_add( Mpy_32_16_1( RZ1[0], t_sin[c1_ind] ), + L_add( Mpy_32_16_1( RZ2[0], t_sin[c2_ind] ), + L_add( Mpy_32_16_1( IZ1[0], t_sin[s1_ind] ), + Mpy_32_16_1( IZ2[0], t_sin[s2_ind] ) ) ) ) ); + + c0_ind = sub( c0_ind, step ); + s0_ind = add( s0_ind, step ); + c1_ind = add( c1_ind, step ); + s1_ind = sub( s1_ind, step ); + c2_ind = sub( c2_ind, step ); + s2_ind = add( s2_ind, step ); + for ( i = 1; i < m / 4; i++, c0_ind = sub( c0_ind, step ), s0_ind = add( s0_ind, step ), c1_ind = add( c1_ind, step ), s1_ind = sub( s1_ind, step ), c2_ind = sub( c2_ind, step ), s2_ind = add( s2_ind, step ) ) + { + RY1[i] = L_sub( Mpy_32_16_1( RZ0[i], t_sin[c0_ind] ), + L_add( Mpy_32_16_1( RZ1[i], t_sin[c1_ind] ), + L_add( Mpy_32_16_1( RZ2[-i], t_sin[c2_ind] ), + L_add( Mpy_32_16_1( IZ0[-i], t_sin[s0_ind] ), + L_add( Mpy_32_16_1( IZ1[-i], t_sin[s1_ind] ), + Mpy_32_16_1( IZ2[i], t_sin[s2_ind] ) ) ) ) ) ); + IY1[-i] = L_add( L_sub( Mpy_32_16_1( IZ0[-i], t_sin[c0_ind] ), + Mpy_32_16_1( IZ1[-i], t_sin[c1_ind] ) ), + L_add( Mpy_32_16_1( IZ2[i], t_sin[c2_ind] ), + L_add( Mpy_32_16_1( RZ0[i], t_sin[s0_ind] ), + L_sub( Mpy_32_16_1( RZ1[i], t_sin[s1_ind] ), + Mpy_32_16_1( RZ2[-i], t_sin[s2_ind] ) ) ) ) ); } - for ( ; i < m / 2; i++, c0_ind = sub(c0_ind, step), s0_ind = add(s0_ind, step), c1_ind = add(c1_ind, step), s1_ind = sub(s1_ind, step), c2_ind = add(c2_ind, step), s2_ind = sub(s2_ind, step) ) - { - RY1[i] = L_sub(Mpy_32_16_1(RZ0[i], t_sin[c0_ind]), - L_add(L_sub(Mpy_32_16_1(RZ1[i], t_sin[c1_ind]), - Mpy_32_16_1(RZ2[-i], t_sin[c2_ind])), - L_add(Mpy_32_16_1(IZ0[-i], t_sin[s0_ind]), - L_add(Mpy_32_16_1(IZ1[-i], t_sin[s1_ind]), - Mpy_32_16_1(IZ2[i], t_sin[s2_ind]))))); - IY1[-i] = L_sub(Mpy_32_16_1(IZ0[-i], t_sin[c0_ind]), - L_sub(L_add(Mpy_32_16_1(IZ1[-i], t_sin[c1_ind]), - Mpy_32_16_1(IZ2[i], t_sin[c2_ind])), - L_add(Mpy_32_16_1(RZ0[i], t_sin[s0_ind]), - L_sub(Mpy_32_16_1(RZ1[i], t_sin[s1_ind]), - Mpy_32_16_1(RZ2[-i], t_sin[s2_ind]))))); + for ( ; i < m / 2; i++, c0_ind = sub( c0_ind, step ), s0_ind = add( s0_ind, step ), c1_ind = add( c1_ind, step ), s1_ind = sub( s1_ind, step ), c2_ind = add( c2_ind, step ), s2_ind = sub( s2_ind, step ) ) + { + RY1[i] = L_sub( Mpy_32_16_1( RZ0[i], t_sin[c0_ind] ), + L_add( L_sub( Mpy_32_16_1( RZ1[i], t_sin[c1_ind] ), + Mpy_32_16_1( RZ2[-i], t_sin[c2_ind] ) ), + L_add( Mpy_32_16_1( IZ0[-i], t_sin[s0_ind] ), + L_add( Mpy_32_16_1( IZ1[-i], t_sin[s1_ind] ), + Mpy_32_16_1( IZ2[i], t_sin[s2_ind] ) ) ) ) ); + IY1[-i] = L_sub( Mpy_32_16_1( IZ0[-i], t_sin[c0_ind] ), + L_sub( L_add( Mpy_32_16_1( IZ1[-i], t_sin[c1_ind] ), + Mpy_32_16_1( IZ2[i], t_sin[c2_ind] ) ), + L_add( Mpy_32_16_1( RZ0[i], t_sin[s0_ind] ), + L_sub( Mpy_32_16_1( RZ1[i], t_sin[s1_ind] ), + Mpy_32_16_1( RZ2[-i], t_sin[s2_ind] ) ) ) ) ); } /* m/2 */ - RY1[i] = L_sub(Mpy_32_16_1(RZ0[i], t_sin[c0_ind]), - L_add(L_sub(Mpy_32_16_1(RZ1[i], t_sin[c1_ind]), - Mpy_32_16_1(RZ2[-i], t_sin[c2_ind])), - L_add(Mpy_32_16_1(IZ0[-i], t_sin[s0_ind]), - L_add(Mpy_32_16_1(IZ1[-i], t_sin[s1_ind]), - Mpy_32_16_1(IZ2[i], t_sin[s2_ind]))))); + RY1[i] = L_sub( Mpy_32_16_1( RZ0[i], t_sin[c0_ind] ), + L_add( L_sub( Mpy_32_16_1( RZ1[i], t_sin[c1_ind] ), + Mpy_32_16_1( RZ2[-i], t_sin[c2_ind] ) ), + L_add( Mpy_32_16_1( IZ0[-i], t_sin[s0_ind] ), + L_add( Mpy_32_16_1( IZ1[-i], t_sin[s1_ind] ), + Mpy_32_16_1( IZ2[i], t_sin[s2_ind] ) ) ) ) ); /* Construction of Y2 */ c0_ind = T_SIN_PI_2; @@ -2620,89 +2620,89 @@ void ifft3_fx_ivas( c2_ind = T_SIN_PI_2 * 1 / 3; s2_ind = T_SIN_PI_2 * 2 / 3; step2 = 2 * step; - RY2[0] = L_sub(Mpy_32_16_1(RZ0[0], t_sin[c0_ind]), - L_sub(L_add(Mpy_32_16_1(RZ1[0], t_sin[c1_ind]), - Mpy_32_16_1(RZ2[0], t_sin[c2_ind])), - L_add(Mpy_32_16_1(IZ1[0], t_sin[s1_ind]), - Mpy_32_16_1(IZ2[0], t_sin[s2_ind])))); - - c0_ind = sub(c0_ind, step2); - s0_ind = add(s0_ind, step2); - c1_ind = sub(c1_ind, step2); - s1_ind = add(s1_ind, step2); - c2_ind = add(c2_ind, step2); - s2_ind = sub(s2_ind, step2); - for ( i = 1; i < m / 8; i++, c0_ind = sub(c0_ind, step2), s0_ind = add(s0_ind, step2), c1_ind = sub(c1_ind, step2), s1_ind = add(s1_ind, step2), c2_ind = add(c2_ind, step2), s2_ind = sub(s2_ind, step2) ) - { - RY2[i] = L_sub(Mpy_32_16_1(RZ0[i], t_sin[c0_ind]), - L_add(L_add(Mpy_32_16_1(RZ1[i], t_sin[c1_ind]), - Mpy_32_16_1(RZ2[-i], t_sin[c2_ind])), - L_sub(Mpy_32_16_1(IZ0[-i], t_sin[s0_ind]), - L_add(Mpy_32_16_1(IZ1[-i], t_sin[s1_ind]), - Mpy_32_16_1(IZ2[i], t_sin[s2_ind]))))); - IY2[-i] = L_add(L_sub(Mpy_32_16_1(IZ0[-i], t_sin[c0_ind]), - Mpy_32_16_1(IZ1[-i], t_sin[c1_ind])), - L_add(Mpy_32_16_1(IZ2[i], t_sin[c2_ind]), - L_sub(Mpy_32_16_1(RZ0[i], t_sin[s0_ind]), - L_sub(Mpy_32_16_1(RZ1[i], t_sin[s1_ind]), - Mpy_32_16_1(RZ2[-i], t_sin[s2_ind]))))); + RY2[0] = L_sub( Mpy_32_16_1( RZ0[0], t_sin[c0_ind] ), + L_sub( L_add( Mpy_32_16_1( RZ1[0], t_sin[c1_ind] ), + Mpy_32_16_1( RZ2[0], t_sin[c2_ind] ) ), + L_add( Mpy_32_16_1( IZ1[0], t_sin[s1_ind] ), + Mpy_32_16_1( IZ2[0], t_sin[s2_ind] ) ) ) ); + + c0_ind = sub( c0_ind, step2 ); + s0_ind = add( s0_ind, step2 ); + c1_ind = sub( c1_ind, step2 ); + s1_ind = add( s1_ind, step2 ); + c2_ind = add( c2_ind, step2 ); + s2_ind = sub( s2_ind, step2 ); + for ( i = 1; i < m / 8; i++, c0_ind = sub( c0_ind, step2 ), s0_ind = add( s0_ind, step2 ), c1_ind = sub( c1_ind, step2 ), s1_ind = add( s1_ind, step2 ), c2_ind = add( c2_ind, step2 ), s2_ind = sub( s2_ind, step2 ) ) + { + RY2[i] = L_sub( Mpy_32_16_1( RZ0[i], t_sin[c0_ind] ), + L_add( L_add( Mpy_32_16_1( RZ1[i], t_sin[c1_ind] ), + Mpy_32_16_1( RZ2[-i], t_sin[c2_ind] ) ), + L_sub( Mpy_32_16_1( IZ0[-i], t_sin[s0_ind] ), + L_add( Mpy_32_16_1( IZ1[-i], t_sin[s1_ind] ), + Mpy_32_16_1( IZ2[i], t_sin[s2_ind] ) ) ) ) ); + IY2[-i] = L_add( L_sub( Mpy_32_16_1( IZ0[-i], t_sin[c0_ind] ), + Mpy_32_16_1( IZ1[-i], t_sin[c1_ind] ) ), + L_add( Mpy_32_16_1( IZ2[i], t_sin[c2_ind] ), + L_sub( Mpy_32_16_1( RZ0[i], t_sin[s0_ind] ), + L_sub( Mpy_32_16_1( RZ1[i], t_sin[s1_ind] ), + Mpy_32_16_1( RZ2[-i], t_sin[s2_ind] ) ) ) ) ); } - for ( ; i < m / 4; i++, c0_ind = sub(c0_ind, step2), s0_ind = add(s0_ind, step2), c1_ind = add(c1_ind, step2), s1_ind = sub(s1_ind, step2), c2_ind = add(c2_ind, step2), s2_ind = sub(s2_ind, step2) ) - { - RY2[i] = L_add(Mpy_32_16_1(RZ0[i], t_sin[c0_ind]), - L_sub(Mpy_32_16_1(RZ1[i], t_sin[c1_ind]), - L_sub(L_add(Mpy_32_16_1(RZ2[-i], t_sin[c2_ind]), - Mpy_32_16_1(IZ0[-i], t_sin[s0_ind])), - L_add(Mpy_32_16_1(IZ1[-i], t_sin[s1_ind]), - Mpy_32_16_1(IZ2[i], t_sin[s2_ind]))))); - IY2[-i] = L_add(Mpy_32_16_1(IZ0[-i], t_sin[c0_ind]), - L_add(Mpy_32_16_1(IZ1[-i], t_sin[c1_ind]), - L_add(Mpy_32_16_1(IZ2[i], t_sin[c2_ind]), - L_sub(Mpy_32_16_1(RZ0[i], t_sin[s0_ind]), - L_sub(Mpy_32_16_1(RZ1[i], t_sin[s1_ind]), - Mpy_32_16_1(RZ2[-i], t_sin[s2_ind])))))); + for ( ; i < m / 4; i++, c0_ind = sub( c0_ind, step2 ), s0_ind = add( s0_ind, step2 ), c1_ind = add( c1_ind, step2 ), s1_ind = sub( s1_ind, step2 ), c2_ind = add( c2_ind, step2 ), s2_ind = sub( s2_ind, step2 ) ) + { + RY2[i] = L_add( Mpy_32_16_1( RZ0[i], t_sin[c0_ind] ), + L_sub( Mpy_32_16_1( RZ1[i], t_sin[c1_ind] ), + L_sub( L_add( Mpy_32_16_1( RZ2[-i], t_sin[c2_ind] ), + Mpy_32_16_1( IZ0[-i], t_sin[s0_ind] ) ), + L_add( Mpy_32_16_1( IZ1[-i], t_sin[s1_ind] ), + Mpy_32_16_1( IZ2[i], t_sin[s2_ind] ) ) ) ) ); + IY2[-i] = L_add( Mpy_32_16_1( IZ0[-i], t_sin[c0_ind] ), + L_add( Mpy_32_16_1( IZ1[-i], t_sin[c1_ind] ), + L_add( Mpy_32_16_1( IZ2[i], t_sin[c2_ind] ), + L_sub( Mpy_32_16_1( RZ0[i], t_sin[s0_ind] ), + L_sub( Mpy_32_16_1( RZ1[i], t_sin[s1_ind] ), + Mpy_32_16_1( RZ2[-i], t_sin[s2_ind] ) ) ) ) ) ); } - for ( ; i < 3 * m / 8; i++, c0_ind = sub(c0_ind, step2), s0_ind = add(s0_ind, step2), c1_ind = add(c1_ind, step2), s1_ind = sub(s1_ind, step2), c2_ind = sub(c2_ind, step2), s2_ind = add(s2_ind, step2) ) - { - RY2[i] = L_sub(L_add(Mpy_32_16_1(RZ0[i], t_sin[c0_ind]), - Mpy_32_16_1(RZ1[i], t_sin[c1_ind])), - L_sub(L_add(Mpy_32_16_1(RZ2[-i], t_sin[c2_ind]), - Mpy_32_16_1(IZ0[-i], t_sin[s0_ind])), - L_sub(Mpy_32_16_1(IZ1[-i], t_sin[s1_ind]), - Mpy_32_16_1(IZ2[i], t_sin[s2_ind])))); - IY2[-i] = L_sub(L_add(Mpy_32_16_1(IZ0[-i], t_sin[c0_ind]), - L_add(Mpy_32_16_1(IZ1[-i], t_sin[c1_ind]), - L_add(Mpy_32_16_1(IZ2[i], t_sin[c2_ind]), - Mpy_32_16_1(RZ0[i], t_sin[s0_ind])))), - L_add(Mpy_32_16_1(RZ1[i], t_sin[s1_ind]), - Mpy_32_16_1(RZ2[-i], t_sin[s2_ind]))); + for ( ; i < 3 * m / 8; i++, c0_ind = sub( c0_ind, step2 ), s0_ind = add( s0_ind, step2 ), c1_ind = add( c1_ind, step2 ), s1_ind = sub( s1_ind, step2 ), c2_ind = sub( c2_ind, step2 ), s2_ind = add( s2_ind, step2 ) ) + { + RY2[i] = L_sub( L_add( Mpy_32_16_1( RZ0[i], t_sin[c0_ind] ), + Mpy_32_16_1( RZ1[i], t_sin[c1_ind] ) ), + L_sub( L_add( Mpy_32_16_1( RZ2[-i], t_sin[c2_ind] ), + Mpy_32_16_1( IZ0[-i], t_sin[s0_ind] ) ), + L_sub( Mpy_32_16_1( IZ1[-i], t_sin[s1_ind] ), + Mpy_32_16_1( IZ2[i], t_sin[s2_ind] ) ) ) ); + IY2[-i] = L_sub( L_add( Mpy_32_16_1( IZ0[-i], t_sin[c0_ind] ), + L_add( Mpy_32_16_1( IZ1[-i], t_sin[c1_ind] ), + L_add( Mpy_32_16_1( IZ2[i], t_sin[c2_ind] ), + Mpy_32_16_1( RZ0[i], t_sin[s0_ind] ) ) ) ), + L_add( Mpy_32_16_1( RZ1[i], t_sin[s1_ind] ), + Mpy_32_16_1( RZ2[-i], t_sin[s2_ind] ) ) ); } - for ( ; i < m / 2; i++, c0_ind = add(c0_ind, step2), s0_ind = sub(s0_ind, step2), c1_ind = add(c1_ind, step2), s1_ind = sub(s1_ind, step2), c2_ind = sub(c2_ind, step2), s2_ind = add(s2_ind, step2) ) - { - RY2[i] = L_sub(L_sub(Mpy_32_16_1(RZ1[i], t_sin[c1_ind]), - Mpy_32_16_1(RZ0[i], t_sin[c0_ind])), - L_sub(L_add(Mpy_32_16_1(RZ2[-i], t_sin[c2_ind]), - Mpy_32_16_1(IZ0[-i], t_sin[s0_ind])), - L_sub(Mpy_32_16_1(IZ1[-i], t_sin[s1_ind]), - Mpy_32_16_1(IZ2[i], t_sin[s2_ind])))); - IY2[-i] = L_add(L_sub(Mpy_32_16_1(IZ1[-i], t_sin[c1_ind]), - Mpy_32_16_1(IZ0[-i], t_sin[c0_ind])), - L_sub(L_add(Mpy_32_16_1(IZ2[i], t_sin[c2_ind]), - Mpy_32_16_1(RZ0[i], t_sin[s0_ind])), - L_add(Mpy_32_16_1(RZ1[i], t_sin[s1_ind]), - Mpy_32_16_1(RZ2[-i], t_sin[s2_ind])))); + for ( ; i < m / 2; i++, c0_ind = add( c0_ind, step2 ), s0_ind = sub( s0_ind, step2 ), c1_ind = add( c1_ind, step2 ), s1_ind = sub( s1_ind, step2 ), c2_ind = sub( c2_ind, step2 ), s2_ind = add( s2_ind, step2 ) ) + { + RY2[i] = L_sub( L_sub( Mpy_32_16_1( RZ1[i], t_sin[c1_ind] ), + Mpy_32_16_1( RZ0[i], t_sin[c0_ind] ) ), + L_sub( L_add( Mpy_32_16_1( RZ2[-i], t_sin[c2_ind] ), + Mpy_32_16_1( IZ0[-i], t_sin[s0_ind] ) ), + L_sub( Mpy_32_16_1( IZ1[-i], t_sin[s1_ind] ), + Mpy_32_16_1( IZ2[i], t_sin[s2_ind] ) ) ) ); + IY2[-i] = L_add( L_sub( Mpy_32_16_1( IZ1[-i], t_sin[c1_ind] ), + Mpy_32_16_1( IZ0[-i], t_sin[c0_ind] ) ), + L_sub( L_add( Mpy_32_16_1( IZ2[i], t_sin[c2_ind] ), + Mpy_32_16_1( RZ0[i], t_sin[s0_ind] ) ), + L_add( Mpy_32_16_1( RZ1[i], t_sin[s1_ind] ), + Mpy_32_16_1( RZ2[-i], t_sin[s2_ind] ) ) ) ); } /* m/2 */ - RY2[i] = L_sub(L_sub(Mpy_32_16_1(RZ1[i], t_sin[c1_ind]), - Mpy_32_16_1(RZ0[i], t_sin[c0_ind])), - L_sub(L_add(Mpy_32_16_1(RZ2[-i], t_sin[c2_ind]), - Mpy_32_16_1(IZ0[-i], t_sin[s0_ind])), - L_sub(Mpy_32_16_1(IZ1[-i], t_sin[s1_ind]), - Mpy_32_16_1(IZ2[i], t_sin[s2_ind])))); + RY2[i] = L_sub( L_sub( Mpy_32_16_1( RZ1[i], t_sin[c1_ind] ), + Mpy_32_16_1( RZ0[i], t_sin[c0_ind] ) ), + L_sub( L_add( Mpy_32_16_1( RZ2[-i], t_sin[c2_ind] ), + Mpy_32_16_1( IZ0[-i], t_sin[s0_ind] ) ), + L_sub( Mpy_32_16_1( IZ1[-i], t_sin[s1_ind] ), + Mpy_32_16_1( IZ2[i], t_sin[s2_ind] ) ) ) ); /* Compute the inverse FFT for all 3 blocks. */ ifft_rel_fx32( RY0, m, order ); @@ -2714,12 +2714,12 @@ void ifft3_fx_ivas( y2 = RY2; /* Interlacing and scaling, scale = 1/3 */ - scale = (Word16)(0x2AAB); - FOR ( i = 0; i < n; ) + scale = (Word16) ( 0x2AAB ); + FOR( i = 0; i < n; ) { - X[i++] = Mpy_32_16_1(( *y0++ ), scale); - X[i++] = Mpy_32_16_1(( *y1++ ), scale); - X[i++] = Mpy_32_16_1(( *y2++ ), scale); + X[i++] = Mpy_32_16_1( ( *y0++ ), scale ); + X[i++] = Mpy_32_16_1( ( *y1++ ), scale ); + X[i++] = Mpy_32_16_1( ( *y2++ ), scale ); } return; @@ -2735,26 +2735,26 @@ static void rfft_post( Word16 s, c; Word16 i = 0; - tmp1 = L_add(buf[0], buf[1]); - buf[1] = L_sub(buf[0], buf[1]); + tmp1 = L_add( buf[0], buf[1] ); + buf[1] = L_sub( buf[0], buf[1] ); buf[0] = tmp1; - FOR ( i = 1; i <= ( len + 2 ) / 4; i++ ) + FOR( i = 1; i <= ( len + 2 ) / 4; i++ ) { s = sine_table[i]; /* sin(pi*i/(len/2)) */ c = sine_table[i + len / 4]; /* cos(pi*i/(len/2)) */ - tmp1 = L_sub(buf[2 * i], buf[len - 2 * i]); - tmp2 = L_add(buf[2 * i + 1], buf[len - 2 * i + 1]); - tmp3 = L_sub(Mpy_32_16_1(tmp1, s), Mpy_32_16_1(tmp2, c)); /* real part of j*W(k,N)*[T(k) - T'(N-k)] */ - tmp4 = L_add(Mpy_32_16_1(tmp1, c), Mpy_32_16_1(tmp2, s)); /* imag part of j*W(k,N)*[T(k) - T'(N-k)] */ - tmp1 = L_add(buf[2 * i], buf[len - 2 * i]); - tmp2 = L_sub(buf[2 * i + 1], buf[len - 2 * i + 1]); - - buf[2 * i] = L_shr(L_sub(tmp1, tmp3), 1); - buf[2 * i + 1] = L_shr(L_sub(tmp2, tmp4), 1); - buf[len - 2 * i] = L_shr(L_add(tmp1, tmp3), 1); - buf[len - 2 * i + 1] = L_negate(L_shr(L_add(tmp2, tmp4), 1)); + tmp1 = L_sub( buf[2 * i], buf[len - 2 * i] ); + tmp2 = L_add( buf[2 * i + 1], buf[len - 2 * i + 1] ); + tmp3 = L_sub( Mpy_32_16_1( tmp1, s ), Mpy_32_16_1( tmp2, c ) ); /* real part of j*W(k,N)*[T(k) - T'(N-k)] */ + tmp4 = L_add( Mpy_32_16_1( tmp1, c ), Mpy_32_16_1( tmp2, s ) ); /* imag part of j*W(k,N)*[T(k) - T'(N-k)] */ + tmp1 = L_add( buf[2 * i], buf[len - 2 * i] ); + tmp2 = L_sub( buf[2 * i + 1], buf[len - 2 * i + 1] ); + + buf[2 * i] = L_shr( L_sub( tmp1, tmp3 ), 1 ); + buf[2 * i + 1] = L_shr( L_sub( tmp2, tmp4 ), 1 ); + buf[len - 2 * i] = L_shr( L_add( tmp1, tmp3 ), 1 ); + buf[len - 2 * i + 1] = L_negate( L_shr( L_add( tmp2, tmp4 ), 1 ) ); } } @@ -2763,31 +2763,31 @@ static void rfft_pre( Word32 *buf, const Word16 len ) { - const Word16 scale = (Word16)(1.0f / len * 32768.0); + const Word16 scale = (Word16) ( 1.0f / len * 32768.0 ); Word32 tmp1, tmp2, tmp3, tmp4; Word16 s, c; Word16 i = 0; - tmp1 = L_add(buf[0], buf[1]); - buf[1] = Mpy_32_16_1(L_sub(buf[0], buf[1]), scale); - buf[0] = Mpy_32_16_1(tmp1, scale); + tmp1 = L_add( buf[0], buf[1] ); + buf[1] = Mpy_32_16_1( L_sub( buf[0], buf[1] ), scale ); + buf[0] = Mpy_32_16_1( tmp1, scale ); - FOR ( i = 1; i <= ( len + 2 ) / 4; i++ ) + FOR( i = 1; i <= ( len + 2 ) / 4; i++ ) { s = sine_table[i]; /* sin(pi*i/(len/2)) */ c = sine_table[i + len / 4]; /* cos(pi*i/(len/2)) */ - tmp1 = L_sub(buf[2 * i], buf[len - 2 * i]); - tmp2 = L_add(buf[2 * i + 1], buf[len - 2 * i + 1]); - tmp3 = L_add(Mpy_32_16_1(tmp1, s), Mpy_32_16_1(tmp2, c)); /* real part of j*W(k,N)*[T(k) - T'(N-k)] */ - tmp4 = L_sub(Mpy_32_16_1(tmp2, s), Mpy_32_16_1(tmp1, c)); /* imag part of j*W(k,N)*[T(k) - T'(N-k)] */ - tmp1 = L_add(buf[2 * i], buf[len - 2 * i]); - tmp2 = L_sub(buf[2 * i + 1], buf[len - 2 * i + 1]); - - buf[2 * i] = Mpy_32_16_1(L_add(tmp1, tmp3), scale); - buf[2 * i + 1] = L_negate(Mpy_32_16_1(L_add(tmp2, tmp4), scale)); - buf[len - 2 * i] = Mpy_32_16_1(L_sub(tmp1, tmp3), scale); - buf[len - 2 * i + 1] = Mpy_32_16_1(L_sub(tmp2, tmp4), scale); + tmp1 = L_sub( buf[2 * i], buf[len - 2 * i] ); + tmp2 = L_add( buf[2 * i + 1], buf[len - 2 * i + 1] ); + tmp3 = L_add( Mpy_32_16_1( tmp1, s ), Mpy_32_16_1( tmp2, c ) ); /* real part of j*W(k,N)*[T(k) - T'(N-k)] */ + tmp4 = L_sub( Mpy_32_16_1( tmp2, s ), Mpy_32_16_1( tmp1, c ) ); /* imag part of j*W(k,N)*[T(k) - T'(N-k)] */ + tmp1 = L_add( buf[2 * i], buf[len - 2 * i] ); + tmp2 = L_sub( buf[2 * i + 1], buf[len - 2 * i + 1] ); + + buf[2 * i] = Mpy_32_16_1( L_add( tmp1, tmp3 ), scale ); + buf[2 * i + 1] = L_negate( Mpy_32_16_1( L_add( tmp2, tmp4 ), scale ) ); + buf[len - 2 * i] = Mpy_32_16_1( L_sub( tmp1, tmp3 ), scale ); + buf[len - 2 * i + 1] = Mpy_32_16_1( L_sub( tmp2, tmp4 ), scale ); } return; @@ -2801,47 +2801,47 @@ Word16 RFFTN_fx( { assert( len <= 640 && len > 0 ); - IF ( EQ_16(len, 640) ) + IF( EQ_16( len, 640 ) ) { Word32 x[320], y[320]; Word16 i; - IF ( NE_16(sign, -1) ) + IF( NE_16( sign, -1 ) ) { rfft_pre( sine_table, data, len ); } - FOR ( i = 0; i < 320; i++ ) + FOR( i = 0; i < 320; i++ ) { x[i] = data[2 * i]; y[i] = data[2 * i + 1]; } DoRTFT320_fx( x, y ); - FOR ( i = 0; i < 320; i++ ) + FOR( i = 0; i < 320; i++ ) { data[2 * i] = x[i]; data[2 * i + 1] = y[i]; } - IF ( EQ_16(sign, -1) ) + IF( EQ_16( sign, -1 ) ) { rfft_post( sine_table, data, len ); } } ELSE { - IF ( EQ_16(len, 512) ) + IF( EQ_16( len, 512 ) ) { Word16 i; const Word16 log2 = 9; Word32 reordered_data[512]; - IF ( EQ_16(sign, -1) ) + IF( EQ_16( sign, -1 ) ) { fft_rel_fx32( data, len, log2 ); reordered_data[0] = data[0]; reordered_data[1] = data[len / 2]; - FOR ( i = 1; i < len / 2; i++ ) + FOR( i = 1; i < len / 2; i++ ) { reordered_data[2 * i] = data[i]; reordered_data[2 * i + 1] = data[len - i]; @@ -2851,7 +2851,7 @@ Word16 RFFTN_fx( { reordered_data[0] = data[0]; reordered_data[len / 2] = data[1]; - FOR ( i = 1; i < len / 2; i++ ) + FOR( i = 1; i < len / 2; i++ ) { reordered_data[i] = data[2 * i]; reordered_data[len - i] = data[2 * i + 1]; @@ -3101,7 +3101,7 @@ static void nextFFT( const Word16 length ) { cmplx val[5]; - SWITCH ( length ) + SWITCH( length ) { case 2: fft2( x ); @@ -3113,13 +3113,13 @@ static void nextFFT( fft4( x ); BREAK; case 5: - FOR ( Word32 i = 0; i < 5; i++ ) + FOR( Word32 i = 0; i < 5; i++ ) { val[i].re = x[2 * i]; val[i].im = x[2 * i + 1]; } fft5( val ); - FOR ( Word32 i = 0; i < 5; i++ ) + FOR( Word32 i = 0; i < 5; i++ ) { x[2 * i] = val[i].re; x[2 * i + 1] = val[i].im; @@ -3215,13 +3215,13 @@ static void cooleyTukeyFFT( fft4( x ); BREAK; case 5: - FOR ( i = 0; i < 5; i++ ) + FOR( i = 0; i < 5; i++ ) { val[i].re = x[2 * i]; val[i].im = x[2 * i + 1]; } fft5( val ); - FOR ( i = 0; i < 5; i++ ) + FOR( i = 0; i < 5; i++ ) { x[2 * i] = val[i].re; x[2 * i + 1] = val[i].im; @@ -3234,7 +3234,7 @@ static void cooleyTukeyFFT( { factor = findFactor( length ); - IF ( GT_16(factor, 0) && GT_16( length / factor, 1 ) ) + IF( GT_16( factor, 0 ) && GT_16( length / factor, 1 ) ) { n1 = factor; n2 = length / factor; @@ -3314,7 +3314,7 @@ static void pfaDFT( Word16 i, ii; Word16 cnt; - IF ( GT_16(numFactors, 1) ) + IF( GT_16( numFactors, 1 ) ) { Word32 *tmp = scratch1; Word16 n1_inv = 1, n2_inv = 1; @@ -3342,7 +3342,7 @@ static void pfaDFT( idx += incr; - IF ( GT_16(idx, length) ) + IF( GT_16( idx, length ) ) { idx -= length; } @@ -3378,7 +3378,7 @@ static void pfaDFT( tmp[2 * idx + 1] = x[cnt++]; idx += n2; - IF ( GT_16(idx, length) ) + IF( GT_16( idx, length ) ) { idx -= length; } @@ -5080,14 +5080,14 @@ static void fft_lenN( case 10: { cmplx y[10]; - FOR ( j = 0; j < dim2; j++ ) + FOR( j = 0; j < dim2; j++ ) { { y[j] = xx[0 + j * dim1]; }; } fft_len10( &y[0] ); - FOR ( j = 0; j < dim2; j++ ) + FOR( j = 0; j < dim2; j++ ) { x[0 + j * dim1] = y[j]; } @@ -5106,7 +5106,7 @@ static void fft_lenN( } } fft_len10( &y[0] ); - FOR ( j = 0; j < dim2; j++ ) + FOR( j = 0; j < dim2; j++ ) { x[i + j * dim1] = y[j]; } @@ -5117,7 +5117,7 @@ static void fft_lenN( case 16: { cmplx y[16]; - FOR ( j = 0; j < dim2; j++ ) + FOR( j = 0; j < dim2; j++ ) { { y[j] = xx[0 + j * dim1]; @@ -5125,7 +5125,7 @@ static void fft_lenN( } fft_len16( &y[0] ); - FOR ( j = 0; j < dim2; j++ ) + FOR( j = 0; j < dim2; j++ ) { x[0 + j * dim1] = y[j]; } @@ -5144,7 +5144,7 @@ static void fft_lenN( } } fft_len16( &y[0] ); - FOR ( j = 0; j < dim2; j++ ) + FOR( j = 0; j < dim2; j++ ) { x[i + j * dim1] = y[j]; } @@ -5155,14 +5155,14 @@ static void fft_lenN( case 20: { cmplx y[20]; - FOR ( j = 0; j < dim2; j++ ) + FOR( j = 0; j < dim2; j++ ) { { y[j] = xx[0 + j * dim1]; }; } fft_len20_fx( &y[0] ); - FOR ( j = 0; j < dim2; j++ ) + FOR( j = 0; j < dim2; j++ ) { x[0 + j * dim1] = y[j]; } @@ -5189,7 +5189,7 @@ static void fft_lenN( } } fft_len20_fx( &y[0] ); - FOR ( j = 0; j < dim2; j++ ) + FOR( j = 0; j < dim2; j++ ) { x[i + j * dim1] = y[j]; } @@ -5200,14 +5200,14 @@ static void fft_lenN( case 32: { cmplx y[32]; - FOR ( j = 0; j < dim2; j++ ) + FOR( j = 0; j < dim2; j++ ) { { y[j] = xx[0 + j * dim1]; }; } fft_len32( &y[0] ); - FOR ( j = 0; j < dim2; j++ ) + FOR( j = 0; j < dim2; j++ ) { x[0 + j * dim1] = y[j]; } @@ -5234,7 +5234,7 @@ static void fft_lenN( } } fft_len32( &y[0] ); - FOR ( j = 0; j < dim2; j++ ) + FOR( j = 0; j < dim2; j++ ) { x[i + j * dim1] = y[j]; } @@ -5260,7 +5260,7 @@ void fft_fx( { cmplx x[960]; - FOR ( Word32 j = 0; j < length; j++ ) + FOR( Word32 j = 0; j < length; j++ ) { x[j].re = re[s * j]; x[j].im = im[s * j]; @@ -5323,7 +5323,7 @@ void fft_fx( assert( !"fft length is not supported!" ); } - FOR ( Word32 j = 0; j < length; j++ ) + FOR( Word32 j = 0; j < length; j++ ) { re[s * j] = x[j].re; im[s * j] = x[j].im; @@ -5333,8 +5333,8 @@ void fft_fx( } void rfft_fx( - Word32 *x, /* i/o: values */ - const Word16 *w, /* i : window */ + Word32 *x, /* i/o: values */ + const Word16 *w, /* i : window */ const Word16 length, /* i : length of fft */ const Word16 isign /* i : sign */ ) @@ -5374,61 +5374,61 @@ void rfft_fx( assert( 0 ); } - SWITCH ( isign ) + SWITCH( isign ) { case -1: fft_fx( x, x + 1, sizeOfFft2, 2 ); - tmp = L_add(x[0], x[1]); - x[1] = L_sub(x[0], x[1]); + tmp = L_add( x[0], x[1] ); + x[1] = L_sub( x[0], x[1] ); x[0] = tmp; - FOR ( i = 1; i <= sizeOfFft4; i++ ) + FOR( i = 1; i <= sizeOfFft4; i++ ) { - t1 = L_sub(x[2 * i], x[length - 2 * i]); - t2 = L_add(x[2 * i + 1], x[length - 2 * i + 1]); - t3 = L_sub(Mpy_32_16_1(t1, w[i]), Mpy_32_16_1(t2, w[i + sizeOfFft4])); - t4 = L_add(Mpy_32_16_1(t1, w[i + sizeOfFft4]), Mpy_32_16_1(t2, w[i])); - t1 = L_add(x[2 * i], x[length - 2 * i]); - t2 = L_sub(x[2 * i + 1], x[length - 2 * i + 1]); - - x[2 * i] = Mpy_32_16_1(L_sub(t1, t3), 16384); - x[2 * i + 1] = Mpy_32_16_1(L_sub(t2, t4), 16384); - x[length - 2 * i] = Mpy_32_16_1(L_add(t1, t3), 16384); - x[length - 2 * i + 1] = Mpy_32_16_1(L_negate(L_add(t2, t4)), 16384); + t1 = L_sub( x[2 * i], x[length - 2 * i] ); + t2 = L_add( x[2 * i + 1], x[length - 2 * i + 1] ); + t3 = L_sub( Mpy_32_16_1( t1, w[i] ), Mpy_32_16_1( t2, w[i + sizeOfFft4] ) ); + t4 = L_add( Mpy_32_16_1( t1, w[i + sizeOfFft4] ), Mpy_32_16_1( t2, w[i] ) ); + t1 = L_add( x[2 * i], x[length - 2 * i] ); + t2 = L_sub( x[2 * i + 1], x[length - 2 * i + 1] ); + + x[2 * i] = Mpy_32_16_1( L_sub( t1, t3 ), 16384 ); + x[2 * i + 1] = Mpy_32_16_1( L_sub( t2, t4 ), 16384 ); + x[length - 2 * i] = Mpy_32_16_1( L_add( t1, t3 ), 16384 ); + x[length - 2 * i + 1] = Mpy_32_16_1( L_negate( L_add( t2, t4 ) ), 16384 ); } BREAK; case +1: - tmp = Mpy_32_16_1( L_add( x[0], x[1] ), 16384); - x[1] = Mpy_32_16_1( L_sub( x[1], x[0] ), 16384); + tmp = Mpy_32_16_1( L_add( x[0], x[1] ), 16384 ); + x[1] = Mpy_32_16_1( L_sub( x[1], x[0] ), 16384 ); x[0] = tmp; - FOR ( i = 1; i <= sizeOfFft4; i++ ) + FOR( i = 1; i <= sizeOfFft4; i++ ) { - t1 = L_sub(x[2 * i], x[length - 2 * i]); - t2 = L_add(x[2 * i + 1], x[length - 2 * i + 1]); - t3 = L_add(Mpy_32_16_1(t1, w[i]), Mpy_32_16_1(t2, w[i + sizeOfFft4])); - t4 = L_sub(Mpy_32_16_1(t2, w[i]), Mpy_32_16_1(t1, w[i + sizeOfFft4])); - t1 = L_add(x[2 * i], x[length - 2 * i]); - t2 = L_sub(x[2 * i + 1], x[length - 2 * i + 1]); - - x[2 * i] = Mpy_32_16_1(L_sub( t1, t3 ), 16384); - x[2 * i + 1] = Mpy_32_16_1( L_sub( t4, t2 ), 16384); - x[length - 2 * i] = Mpy_32_16_1(L_add( t1, t3 ), 16384); - x[length - 2 * i + 1] = Mpy_32_16_1(L_add( t2, t4 ), 16384); + t1 = L_sub( x[2 * i], x[length - 2 * i] ); + t2 = L_add( x[2 * i + 1], x[length - 2 * i + 1] ); + t3 = L_add( Mpy_32_16_1( t1, w[i] ), Mpy_32_16_1( t2, w[i + sizeOfFft4] ) ); + t4 = L_sub( Mpy_32_16_1( t2, w[i] ), Mpy_32_16_1( t1, w[i + sizeOfFft4] ) ); + t1 = L_add( x[2 * i], x[length - 2 * i] ); + t2 = L_sub( x[2 * i + 1], x[length - 2 * i + 1] ); + + x[2 * i] = Mpy_32_16_1( L_sub( t1, t3 ), 16384 ); + x[2 * i + 1] = Mpy_32_16_1( L_sub( t4, t2 ), 16384 ); + x[length - 2 * i] = Mpy_32_16_1( L_add( t1, t3 ), 16384 ); + x[length - 2 * i + 1] = Mpy_32_16_1( L_add( t2, t4 ), 16384 ); } fft_fx( x, x + 1, sizeOfFft2, 2 ); - FOR ( i = 0; i < length; i += 2 ) + FOR( i = 0; i < length; i += 2 ) { - x[i] = Mpy_32_16_1(x[i], s1); - x[i + 1] = Mpy_32_16_1(x[i+1], s2); + x[i] = Mpy_32_16_1( x[i], s1 ); + x[i + 1] = Mpy_32_16_1( x[i + 1], s2 ); } BREAK; @@ -5440,20 +5440,20 @@ void rfft_fx( Word16 find_guarded_bits_fx( Word32 n ) { return n <= 1 ? 0 : n <= 2 ? 1 - : n <= 4 ? 2 - : n <= 8 ? 3 - : n <= 16 ? 4 - : n <= 32 ? 5 - : n <= 64 ? 6 - : n <= 128 ? 7 - : n <= 256 ? 8 - : n <= 512 ? 9 - : n <= 1024 ? 10 - : n <= 2048 ? 11 - : n <= 4096 ? 12 - : n <= 8192 ? 13 - : n <= 16384 ? 14 - : 15; + : n <= 4 ? 2 + : n <= 8 ? 3 + : n <= 16 ? 4 + : n <= 32 ? 5 + : n <= 64 ? 6 + : n <= 128 ? 7 + : n <= 256 ? 8 + : n <= 512 ? 9 + : n <= 1024 ? 10 + : n <= 2048 ? 11 + : n <= 4096 ? 12 + : n <= 8192 ? 13 + : n <= 16384 ? 14 + : 15; } Word16 L_norm_arr( Word32 *arr, Word16 size ) diff --git a/lib_com/fft_fx_evs.c b/lib_com/fft_fx_evs.c index c7f310669..b36bac55f 100644 --- a/lib_com/fft_fx_evs.c +++ b/lib_com/fft_fx_evs.c @@ -2,32 +2,32 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "rom_com.h" /* Static table prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "rom_com.h" /* Static table prototypes */ #include "stl.h" #include /*-----------------------------------------------------------------* -* Local functions -*-----------------------------------------------------------------*/ + * Local functions + *-----------------------------------------------------------------*/ -#define FFT3_ONE_THIRD 21845 /* 1/3 in Q16 */ +#define FFT3_ONE_THIRD 21845 /* 1/3 in Q16 */ /* DCT related */ -#define KP559016994_16FX 1200479845 /* EDCT & EMDCT constants */ -#define KP951056516_16FX 2042378325 /* EDCT & EMDCT constants */ -#define KP587785252_16FX 1262259213 /* EDCT & EMDCT constants */ +#define KP559016994_16FX 1200479845 /* EDCT & EMDCT constants */ +#define KP951056516_16FX 2042378325 /* EDCT & EMDCT constants */ +#define KP587785252_16FX 1262259213 /* EDCT & EMDCT constants */ -static void fft5_shift4_16fx( Word16 n1, Word16 *zRe, Word16 *zIm, const Word16 *Idx ); +static void fft5_shift4_16fx( Word16 n1, Word16 *zRe, Word16 *zIm, const Word16 *Idx ); static void fft64_16fx( Word16 *x, Word16 *y, const Word16 *Idx ); static void fft32_5_16fx( Word16 *x, Word16 *y, const Word16 *Idx ); -static void cftmdl_16fx(Word16 n, Word16 l, Word16 *a, const Word32 *w); +static void cftmdl_16fx( Word16 n, Word16 l, Word16 *a, const Word32 *w ); static void cftfsub_16fx( Word16 n, Word16 *a, const Word32 *w ); -static void cft1st_16fx(Word16 n, Word16 *a, const Word32 *w); -static void cftmdl_16fx(Word16 n, Word16 l, Word16 *a, const Word32 *w); -static void fft5_shift4_16fx( Word16 n1, Word16 *zRe, Word16 *zIm, const Word16 *Idx ); +static void cft1st_16fx( Word16 n, Word16 *a, const Word32 *w ); +static void cftmdl_16fx( Word16 n, Word16 l, Word16 *a, const Word32 *w ); +static void fft5_shift4_16fx( Word16 n1, Word16 *zRe, Word16 *zIm, const Word16 *Idx ); static void bitrv2_SR_16fx( Word16 n, const Word16 *ip, Word16 *a ); static void fft64_16fx( Word16 *x, Word16 *y, const Word16 *Idx ); static void fft5_32_16fx( Word16 *zRe, Word16 *zIm, const Word16 *Idx ); @@ -36,8 +36,8 @@ static void cdftForw_16fx( Word16 n, Word16 *a, const Word16 *ip, const Word32 * #include "math_32.h" /*-----------------------------------------------------------------* -* Local functions -*-----------------------------------------------------------------*/ + * Local functions + *-----------------------------------------------------------------*/ static void cdftForw_fx( Word16 n, Word32 *a, const Word16 *ip, const Word16 *w ); static void bitrv2_SR_fx( Word16 n, const Word16 *ip, Word32 *a ); static void cftfsub_fx( Word16 n, Word32 *a, const Word16 *w ); @@ -46,7 +46,7 @@ static void cftmdl_fx( Word16 n, Word16 l, Word32 *a, const Word16 *w ); void DoRTFTn_fx( - Word32 *x, /* i/o : real part of input and output data */ + Word32 *x, /* i/o : real part of input and output data */ Word32 *y, /* i/o : imaginary part of input and output data */ const Word16 n /* i : size of the FFT up to 1024 */ ) @@ -56,7 +56,7 @@ void DoRTFTn_fx( Word32 z[2048], *pt; pt = z; - FOR ( i=0; i=1 ; i--) + FOR( i = n - 1; i >= 1; i-- ) { - x[i]=*pt++; + x[i] = *pt++; move16(); - y[i]=*pt++; + y[i] = *pt++; move16(); } @@ -114,17 +114,17 @@ void DoRTFTn_fx( * Main fuction of Complex Discrete Fourier Transform *-----------------------------------------------------------------*/ static void cdftForw_fx( - Word16 n, /* i : data length of real and imag */ - Word32 *a, /* i/o : input/output data Q(q)*/ - const Word16 *ip, /* i : work area for bit reversal */ - const Word16 *w /* i : cos/sin table Q14*/ + Word16 n, /* i : data length of real and imag */ + Word32 *a, /* i/o : input/output data Q(q)*/ + const Word16 *ip, /* i : work area for bit reversal */ + const Word16 *w /* i : cos/sin table Q14*/ ) { /* bit reversal */ - bitrv2_SR_fx(n, ip + 2, a); + bitrv2_SR_fx( n, ip + 2, a ); /* Do FFT */ - cftfsub_fx(n, a, w); + cftfsub_fx( n, a, w ); } /*-----------------------------------------------------------------* @@ -132,9 +132,9 @@ static void cdftForw_fx( * Bit reversal *-----------------------------------------------------------------*/ static void bitrv2_SR_fx( - Word16 n, /* i : data length of real and imag */ - const Word16 *ip, /* i/o : work area for bit reversal */ - Word32 *a /* i/o : input/output data Q(q)*/ + Word16 n, /* i : data length of real and imag */ + const Word16 *ip, /* i/o : work area for bit reversal */ + Word32 *a /* i/o : input/output data Q(q)*/ ) { Word16 j, j1, k, k1, m, m2; @@ -146,25 +146,29 @@ static void bitrv2_SR_fx( m = 1; move16(); - WHILE (shl(m, 3) < l) + WHILE( shl( m, 3 ) < l ) { - l = shr(l, 1); - m = shl(m, 1); + l = shr( l, 1 ); + m = shl( m, 1 ); } - m2 = shl(m, 1); - IF (shl(m, 3) == l) + m2 = shl( m, 1 ); + IF( shl( m, 3 ) == l ) { - FOR (k = 0; k < m; k++) + FOR( k = 0; k < m; k++ ) { - FOR (j = 0; j < k; j++) + FOR( j = 0; j < k; j++ ) { - j1 = add(shl(j, 1), ip[k]); - k1 = add(shl(k, 1), ip[j]); - xr = a[j1]; move32(); - xi = a[j1 + 1]; move32(); - yr = a[k1]; move32(); - yi = a[k1 + 1]; move32(); + j1 = add( shl( j, 1 ), ip[k] ); + k1 = add( shl( k, 1 ), ip[j] ); + xr = a[j1]; + move32(); + xi = a[j1 + 1]; + move32(); + yr = a[k1]; + move32(); + yi = a[k1 + 1]; + move32(); a[j1] = yr; move32(); a[j1 + 1] = yi; @@ -173,12 +177,16 @@ static void bitrv2_SR_fx( move32(); a[k1 + 1] = xi; move32(); - j1 = add(j1, m2); - k1 = add(k1, shl(m2, 1)); - xr = a[j1]; move32(); - xi = a[j1 + 1]; move32(); - yr = a[k1]; move32(); - yi = a[k1 + 1]; move32(); + j1 = add( j1, m2 ); + k1 = add( k1, shl( m2, 1 ) ); + xr = a[j1]; + move32(); + xi = a[j1 + 1]; + move32(); + yr = a[k1]; + move32(); + yi = a[k1 + 1]; + move32(); a[j1] = yr; move32(); a[j1 + 1] = yi; @@ -187,13 +195,18 @@ static void bitrv2_SR_fx( move32(); a[k1 + 1] = xi; move32(); - j1 = add(j1, m2); - k1 = sub(k1, m2); - xr = a[j1]; move32(); - xi = a[j1 + 1]; move32(); - xi = a[j1 + 1]; move32(); - yr = a[k1]; move32(); - yi = a[k1 + 1]; move32(); + j1 = add( j1, m2 ); + k1 = sub( k1, m2 ); + xr = a[j1]; + move32(); + xi = a[j1 + 1]; + move32(); + xi = a[j1 + 1]; + move32(); + yr = a[k1]; + move32(); + yi = a[k1 + 1]; + move32(); a[j1] = yr; move32(); a[j1 + 1] = yi; @@ -202,12 +215,16 @@ static void bitrv2_SR_fx( move32(); a[k1 + 1] = xi; move32(); - j1 = add(j1, m2); - k1 = add(k1, shl(m2, 1)); - xr = a[j1]; move32(); - xi = a[j1 + 1]; move32(); - yr = a[k1]; move32(); - yi = a[k1 + 1]; move32(); + j1 = add( j1, m2 ); + k1 = add( k1, shl( m2, 1 ) ); + xr = a[j1]; + move32(); + xi = a[j1 + 1]; + move32(); + yr = a[k1]; + move32(); + yi = a[k1 + 1]; + move32(); a[j1] = yr; move32(); a[j1 + 1] = yi; @@ -218,12 +235,16 @@ static void bitrv2_SR_fx( move32(); } - j1 = add(add(shl(k, 1), m2), ip[k]); - k1 = add(j1, m2); - xr = a[j1]; move32(); - xi = a[j1 + 1]; move32(); - yr = a[k1]; move32(); - yi = a[k1 + 1]; move32(); + j1 = add( add( shl( k, 1 ), m2 ), ip[k] ); + k1 = add( j1, m2 ); + xr = a[j1]; + move32(); + xi = a[j1 + 1]; + move32(); + yr = a[k1]; + move32(); + yi = a[k1 + 1]; + move32(); a[j1] = yr; move32(); a[j1 + 1] = yi; @@ -236,16 +257,20 @@ static void bitrv2_SR_fx( } ELSE { - FOR (k = 1; k < m; k++) + FOR( k = 1; k < m; k++ ) { - FOR (j = 0; j < k; j++) + FOR( j = 0; j < k; j++ ) { - j1 = add(shl(j, 1), ip[k]); - k1 = add(shl(k, 1), ip[j]); - xr = a[j1]; move32(); - xi = a[j1 + 1]; move32(); - yr = a[k1]; move32(); - yi = a[k1 + 1]; move32(); + j1 = add( shl( j, 1 ), ip[k] ); + k1 = add( shl( k, 1 ), ip[j] ); + xr = a[j1]; + move32(); + xi = a[j1 + 1]; + move32(); + yr = a[k1]; + move32(); + yi = a[k1 + 1]; + move32(); a[j1] = yr; move32(); a[j1 + 1] = yi; @@ -254,12 +279,16 @@ static void bitrv2_SR_fx( move32(); a[k1 + 1] = xi; move32(); - j1 = add(j1, m2); - k1 = add(k1, m2); - xr = a[j1]; move32(); - xi = a[j1 + 1]; move32(); - yr = a[k1]; move32(); - yi = a[k1 + 1]; move32(); + j1 = add( j1, m2 ); + k1 = add( k1, m2 ); + xr = a[j1]; + move32(); + xi = a[j1 + 1]; + move32(); + yr = a[k1]; + move32(); + yi = a[k1 + 1]; + move32(); a[j1] = yr; move32(); a[j1 + 1] = yi; @@ -280,9 +309,9 @@ static void bitrv2_SR_fx( * Complex Discrete Fourier Transform *-----------------------------------------------------------------*/ static void cftfsub_fx( - Word16 n, /* i : data length of real and imag */ - Word32 *a, /* i/o : input/output data Q(q)*/ - const Word16 *w /* i : cos/sin table Q14*/ + Word16 n, /* i : data length of real and imag */ + Word32 *a, /* i/o : input/output data Q(q)*/ + const Word16 *w /* i : cos/sin table Q14*/ ) { Word16 j, j1, j2, j3, l; @@ -291,60 +320,60 @@ static void cftfsub_fx( l = 2; move16(); - IF (n > 8) + IF( n > 8 ) { - cft1st_fx(n, a, w); + cft1st_fx( n, a, w ); l = 8; move16(); - WHILE ((shl(l, 2) < n)) + WHILE( ( shl( l, 2 ) < n ) ) { - cftmdl_fx(n, l, a, w); - l = shl(l, 2); + cftmdl_fx( n, l, a, w ); + l = shl( l, 2 ); } } - IF (shl(l, 2) == n) + IF( shl( l, 2 ) == n ) { - FOR (j = 0; j < l; j += 2) + FOR( j = 0; j < l; j += 2 ) { - j1 = add(j, l); - j2 = add(j1, l); - j3 = add(j2, l); - x0r = L_add(a[j], a[j1]); - x0i = L_add(a[j + 1], a[j1 + 1]); - x1r = L_sub(a[j], a[j1]); - x1i = L_sub(a[j + 1], a[j1 + 1]); - x2r = L_add(a[j2], a[j3]); - x2i = L_add(a[j2 + 1], a[j3 + 1]); - x3r = L_sub(a[j2], a[j3]); - x3i = L_sub(a[j2 + 1], a[j3 + 1]); - a[j] = L_add(x0r, x2r); + j1 = add( j, l ); + j2 = add( j1, l ); + j3 = add( j2, l ); + x0r = L_add( a[j], a[j1] ); + x0i = L_add( a[j + 1], a[j1 + 1] ); + x1r = L_sub( a[j], a[j1] ); + x1i = L_sub( a[j + 1], a[j1 + 1] ); + x2r = L_add( a[j2], a[j3] ); + x2i = L_add( a[j2 + 1], a[j3 + 1] ); + x3r = L_sub( a[j2], a[j3] ); + x3i = L_sub( a[j2 + 1], a[j3 + 1] ); + a[j] = L_add( x0r, x2r ); move32(); - a[j2] = L_sub(x0r, x2r); + a[j2] = L_sub( x0r, x2r ); move32(); - a[j + 1] = L_add(x0i, x2i); + a[j + 1] = L_add( x0i, x2i ); move32(); - a[j2 + 1] = L_sub(x0i, x2i); + a[j2 + 1] = L_sub( x0i, x2i ); move32(); - a[j1] = L_sub(x1r, x3i); + a[j1] = L_sub( x1r, x3i ); move32(); - a[j1 + 1] = L_add(x1i, x3r); + a[j1 + 1] = L_add( x1i, x3r ); move32(); - a[j3] = L_add(x1r, x3i); + a[j3] = L_add( x1r, x3i ); move32(); - a[j3 + 1] = L_sub(x1i, x3r); + a[j3 + 1] = L_sub( x1i, x3r ); move32(); } } ELSE { - FOR (j = 0; j < l; j += 2) + FOR( j = 0; j < l; j += 2 ) { - j1 = add(j, l); - x0r = L_sub(a[j], a[j1]); - x0i = L_sub(a[j + 1], a[j1 + 1]); - a[j] = L_add(a[j], a[j1]); + j1 = add( j, l ); + x0r = L_sub( a[j], a[j1] ); + x0i = L_sub( a[j + 1], a[j1 + 1] ); + a[j] = L_add( a[j], a[j1] ); move32(); - a[j + 1] = L_add(a[j + 1], a[j1 + 1]); + a[j + 1] = L_add( a[j + 1], a[j1 + 1] ); move32(); a[j1] = x0r; move32(); @@ -363,78 +392,78 @@ static void cftfsub_fx( * Subfunction of Complex Discrete Fourier Transform *-----------------------------------------------------------------*/ static void cft1st_fx( - Word16 n, /* i : data length of real and imag */ - Word32 *a, /* i/o : input/output data Q(q)*/ - const Word16 *w /* i : cos/sin table Q14*/ + Word16 n, /* i : data length of real and imag */ + Word32 *a, /* i/o : input/output data Q(q)*/ + const Word16 *w /* i : cos/sin table Q14*/ ) { Word16 j, k1, k2; Word16 wk1r, wk1i, wk2r, wk2i, wk3r, wk3i; Word32 x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i; - x0r = L_add(a[0], a[2]); - x0i = L_add(a[1], a[3]); - x1r = L_sub(a[0], a[2]); - x1i = L_sub(a[1], a[3]); - x2r = L_add(a[4], a[6]); - x2i = L_add(a[5], a[7]); - x3r = L_sub(a[4], a[6]); - x3i = L_sub(a[5], a[7]); - a[0] = L_add(x0r, x2r); + x0r = L_add( a[0], a[2] ); + x0i = L_add( a[1], a[3] ); + x1r = L_sub( a[0], a[2] ); + x1i = L_sub( a[1], a[3] ); + x2r = L_add( a[4], a[6] ); + x2i = L_add( a[5], a[7] ); + x3r = L_sub( a[4], a[6] ); + x3i = L_sub( a[5], a[7] ); + a[0] = L_add( x0r, x2r ); move32(); - a[1] = L_add(x0i, x2i); + a[1] = L_add( x0i, x2i ); move32(); - a[4] = L_sub(x0r, x2r); + a[4] = L_sub( x0r, x2r ); move32(); - a[5] = L_sub(x0i, x2i); + a[5] = L_sub( x0i, x2i ); move32(); - a[2] = L_sub(x1r, x3i); + a[2] = L_sub( x1r, x3i ); move32(); - a[3] = L_add(x1i, x3r); + a[3] = L_add( x1i, x3r ); move32(); - a[6] = L_add(x1r, x3i); + a[6] = L_add( x1r, x3i ); move32(); - a[7] = L_sub(x1i, x3r); + a[7] = L_sub( x1i, x3r ); move32(); wk1r = w[2]; move16(); - x0r = L_add(a[8], a[10]); - x0i = L_add(a[9], a[11]); - x1r = L_sub(a[8], a[10]); - x1i = L_sub(a[9], a[11]); - x2r = L_add(a[12], a[14]); - x2i = L_add(a[13], a[15]); - x3r = L_sub(a[12], a[14]); - x3i = L_sub(a[13], a[15]); - a[8] = L_add(x0r, x2r); + x0r = L_add( a[8], a[10] ); + x0i = L_add( a[9], a[11] ); + x1r = L_sub( a[8], a[10] ); + x1i = L_sub( a[9], a[11] ); + x2r = L_add( a[12], a[14] ); + x2i = L_add( a[13], a[15] ); + x3r = L_sub( a[12], a[14] ); + x3i = L_sub( a[13], a[15] ); + a[8] = L_add( x0r, x2r ); move32(); - a[9] = L_add(x0i, x2i); + a[9] = L_add( x0i, x2i ); move32(); - a[12] = L_sub(x2i, x0i); + a[12] = L_sub( x2i, x0i ); move32(); - a[13] = L_sub(x0r, x2r); + a[13] = L_sub( x0r, x2r ); move32(); - x0r = L_sub(x1r, x3i); - x0i = L_add(x1i ,x3r); - a[10] = Mult_32_16(L_shl(L_sub(x0r, x0i), 1), wk1r); + x0r = L_sub( x1r, x3i ); + x0i = L_add( x1i, x3r ); + a[10] = Mult_32_16( L_shl( L_sub( x0r, x0i ), 1 ), wk1r ); move32(); - a[11] = Mult_32_16(L_shl(L_add(x0r, x0i), 1), wk1r); + a[11] = Mult_32_16( L_shl( L_add( x0r, x0i ), 1 ), wk1r ); move32(); - x0r = L_add(x3i, x1r); - x0i = L_sub(x3r,x1i); - a[14] = Mult_32_16(L_shl(L_sub(x0i, x0r), 1), wk1r); + x0r = L_add( x3i, x1r ); + x0i = L_sub( x3r, x1i ); + a[14] = Mult_32_16( L_shl( L_sub( x0i, x0r ), 1 ), wk1r ); move32(); - a[15] = Mult_32_16(L_shl(L_add(x0i, x0r), 1), wk1r); + a[15] = Mult_32_16( L_shl( L_add( x0i, x0r ), 1 ), wk1r ); move32(); k1 = 0; move16(); - FOR (j = 16; j < n; j += 16) + FOR( j = 16; j < n; j += 16 ) { - k1 = add(k1, 2); - k2 = shl(k1, 1); + k1 = add( k1, 2 ); + k2 = shl( k1, 1 ); wk2r = w[k1]; move16(); wk2i = w[k1 + 1]; @@ -443,74 +472,74 @@ static void cft1st_fx( move16(); wk1i = w[k2 + 1]; move16(); - wk3r = extract_l(L_sub(L_deposit_l(wk1r), L_shr(L_mult(wk2i, wk1i), 14))); - wk3i = extract_l(L_msu0(L_shr(L_mult(wk2i, wk1r), 14), wk1i, 1)); - x0r = L_add(a[j], a[j + 2]); - x0i = L_add(a[j + 1], a[j + 3]); - x1r = L_sub(a[j], a[j + 2]); - x1i = L_sub(a[j + 1], a[j + 3]); - x2r = L_add(a[j + 4], a[j + 6]); - x2i = L_add(a[j + 5], a[j + 7]); - x3r = L_sub(a[j + 4], a[j + 6]); - x3i = L_sub(a[j + 5], a[j + 7]); - a[j] = L_add(x0r, x2r); + wk3r = extract_l( L_sub( L_deposit_l( wk1r ), L_shr( L_mult( wk2i, wk1i ), 14 ) ) ); + wk3i = extract_l( L_msu0( L_shr( L_mult( wk2i, wk1r ), 14 ), wk1i, 1 ) ); + x0r = L_add( a[j], a[j + 2] ); + x0i = L_add( a[j + 1], a[j + 3] ); + x1r = L_sub( a[j], a[j + 2] ); + x1i = L_sub( a[j + 1], a[j + 3] ); + x2r = L_add( a[j + 4], a[j + 6] ); + x2i = L_add( a[j + 5], a[j + 7] ); + x3r = L_sub( a[j + 4], a[j + 6] ); + x3i = L_sub( a[j + 5], a[j + 7] ); + a[j] = L_add( x0r, x2r ); move32(); - a[j + 1] = L_add(x0i, x2i); + a[j + 1] = L_add( x0i, x2i ); move32(); - x0r = L_sub(x0r, x2r); - x0i = L_sub(x0i, x2i); - a[j + 4] = L_sub(Mult_32_16(L_shl(x0r, 1), wk2r), Mult_32_16(L_shl(x0i, 1), wk2i)); + x0r = L_sub( x0r, x2r ); + x0i = L_sub( x0i, x2i ); + a[j + 4] = L_sub( Mult_32_16( L_shl( x0r, 1 ), wk2r ), Mult_32_16( L_shl( x0i, 1 ), wk2i ) ); move32(); - a[j + 5] = L_add(Mult_32_16(L_shl(x0i, 1), wk2r), Mult_32_16(L_shl(x0r, 1), wk2i)); + a[j + 5] = L_add( Mult_32_16( L_shl( x0i, 1 ), wk2r ), Mult_32_16( L_shl( x0r, 1 ), wk2i ) ); move32(); - x0r = L_sub(x1r, x3i); - x0i = L_add(x1i, x3r); - a[j + 2] = L_sub(Mult_32_16(L_shl(x0r, 1), wk1r), Mult_32_16(L_shl(x0i, 1), wk1i)); + x0r = L_sub( x1r, x3i ); + x0i = L_add( x1i, x3r ); + a[j + 2] = L_sub( Mult_32_16( L_shl( x0r, 1 ), wk1r ), Mult_32_16( L_shl( x0i, 1 ), wk1i ) ); move32(); - a[j + 3] = L_add(Mult_32_16(L_shl(x0i, 1), wk1r), Mult_32_16(L_shl(x0r, 1), wk1i)); + a[j + 3] = L_add( Mult_32_16( L_shl( x0i, 1 ), wk1r ), Mult_32_16( L_shl( x0r, 1 ), wk1i ) ); move32(); - x0r = L_add(x1r, x3i); - x0i = L_sub(x1i, x3r); - a[j + 6] = L_sub(Mult_32_16(L_shl(x0r, 1), wk3r), Mult_32_16(L_shl(x0i, 1), wk3i)); + x0r = L_add( x1r, x3i ); + x0i = L_sub( x1i, x3r ); + a[j + 6] = L_sub( Mult_32_16( L_shl( x0r, 1 ), wk3r ), Mult_32_16( L_shl( x0i, 1 ), wk3i ) ); move32(); - a[j + 7] = L_add(Mult_32_16(L_shl(x0i, 1), wk3r), Mult_32_16(L_shl(x0r, 1), wk3i)); + a[j + 7] = L_add( Mult_32_16( L_shl( x0i, 1 ), wk3r ), Mult_32_16( L_shl( x0r, 1 ), wk3i ) ); move32(); wk1r = w[k2 + 2]; move16(); wk1i = w[k2 + 3]; move16(); - wk3r = extract_l(L_sub(L_deposit_l(wk1r), L_shr(L_mult(wk2r, wk1i), 14))); - wk3i = extract_l(L_msu0(L_shr(L_mult(wk2r, wk1r), 14), wk1i, 1)); - x0r = L_add(a[j + 8], a[j + 10]); - x0i = L_add(a[j + 9], a[j + 11]); - x1r = L_sub(a[j + 8], a[j + 10]); - x1i = L_sub(a[j + 9], a[j + 11]); - x2r = L_add(a[j + 12], a[j + 14]); - x2i = L_add(a[j + 13], a[j + 15]); - x3r = L_sub(a[j + 12], a[j + 14]); - x3i = L_sub(a[j + 13], a[j + 15]); - a[j + 8] = L_add(x0r, x2r); + wk3r = extract_l( L_sub( L_deposit_l( wk1r ), L_shr( L_mult( wk2r, wk1i ), 14 ) ) ); + wk3i = extract_l( L_msu0( L_shr( L_mult( wk2r, wk1r ), 14 ), wk1i, 1 ) ); + x0r = L_add( a[j + 8], a[j + 10] ); + x0i = L_add( a[j + 9], a[j + 11] ); + x1r = L_sub( a[j + 8], a[j + 10] ); + x1i = L_sub( a[j + 9], a[j + 11] ); + x2r = L_add( a[j + 12], a[j + 14] ); + x2i = L_add( a[j + 13], a[j + 15] ); + x3r = L_sub( a[j + 12], a[j + 14] ); + x3i = L_sub( a[j + 13], a[j + 15] ); + a[j + 8] = L_add( x0r, x2r ); move32(); - a[j + 9] = L_add(x0i, x2i); + a[j + 9] = L_add( x0i, x2i ); move32(); - x0r = L_sub(x0r, x2r); - x0i = L_sub(x0i, x2i); - a[j + 12] = L_negate(L_add(Mult_32_16(L_shl(x0r, 1), wk2i), Mult_32_16(L_shl(x0i, 1), wk2r))); + x0r = L_sub( x0r, x2r ); + x0i = L_sub( x0i, x2i ); + a[j + 12] = L_negate( L_add( Mult_32_16( L_shl( x0r, 1 ), wk2i ), Mult_32_16( L_shl( x0i, 1 ), wk2r ) ) ); move32(); - a[j + 13] = L_sub(Mult_32_16(L_shl(x0r, 1), wk2r), Mult_32_16(L_shl(x0i, 1), wk2i)); + a[j + 13] = L_sub( Mult_32_16( L_shl( x0r, 1 ), wk2r ), Mult_32_16( L_shl( x0i, 1 ), wk2i ) ); move32(); - x0r = L_sub(x1r, x3i); - x0i = L_add(x1i, x3r); - a[j + 10] = L_sub(Mult_32_16(L_shl(x0r, 1), wk1r), Mult_32_16(L_shl(x0i, 1), wk1i)); + x0r = L_sub( x1r, x3i ); + x0i = L_add( x1i, x3r ); + a[j + 10] = L_sub( Mult_32_16( L_shl( x0r, 1 ), wk1r ), Mult_32_16( L_shl( x0i, 1 ), wk1i ) ); move32(); - a[j + 11] = L_add(Mult_32_16(L_shl(x0i, 1), wk1r), Mult_32_16(L_shl(x0r, 1), wk1i)); + a[j + 11] = L_add( Mult_32_16( L_shl( x0i, 1 ), wk1r ), Mult_32_16( L_shl( x0r, 1 ), wk1i ) ); move32(); - x0r =L_add(x1r, x3i); - x0i =L_sub(x1i, x3r); - a[j + 14] = L_sub(Mult_32_16(L_shl(x0r, 1), wk3r), Mult_32_16(L_shl(x0i, 1), wk3i)); + x0r = L_add( x1r, x3i ); + x0i = L_sub( x1i, x3r ); + a[j + 14] = L_sub( Mult_32_16( L_shl( x0r, 1 ), wk3r ), Mult_32_16( L_shl( x0i, 1 ), wk3i ) ); move32(); - a[j + 15] = L_add(Mult_32_16(L_shl(x0i, 1), wk3r), Mult_32_16(L_shl(x0r, 1), wk3i)); + a[j + 15] = L_add( Mult_32_16( L_shl( x0i, 1 ), wk3r ), Mult_32_16( L_shl( x0r, 1 ), wk3i ) ); move32(); } @@ -522,10 +551,10 @@ static void cft1st_fx( * Subfunction of Complex Discrete Fourier Transform *-----------------------------------------------------------------*/ static void cftmdl_fx( - Word16 n, /* i : data length of real and imag */ - Word16 l, /* i : initial shift for processing */ - Word32 *a, /* i/o : input/output data Q(Qx+Q_edct)*/ - const Word16 *w /* i : cos/sin table Q30*/ + Word16 n, /* i : data length of real and imag */ + Word16 l, /* i : initial shift for processing */ + Word32 *a, /* i/o : input/output data Q(Qx+Q_edct)*/ + const Word16 *w /* i : cos/sin table Q30*/ ) { Word16 j, j1, j2, j3, k, k1, k2, m, m2; @@ -533,83 +562,83 @@ static void cftmdl_fx( Word32 x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i; Word16 tmp; - m = shl(l, 2); - FOR (j = 0; j < l; j += 2) - { - j1 = add(j, l); - j2 = add(j1, l); - j3 = add(j2, l); - x0r = L_add(a[j], a[j1]); - x0i = L_add(a[j + 1], a[j1 + 1]); - x1r = L_sub(a[j], a[j1]); - x1i = L_sub(a[j + 1], a[j1 + 1]); - x2r = L_add(a[j2], a[j3]); - x2i = L_add(a[j2 + 1], a[j3 + 1]); - x3r = L_sub(a[j2], a[j3]); - x3i = L_sub(a[j2 + 1], a[j3 + 1]); - a[j] = L_add(x0r, x2r); + m = shl( l, 2 ); + FOR( j = 0; j < l; j += 2 ) + { + j1 = add( j, l ); + j2 = add( j1, l ); + j3 = add( j2, l ); + x0r = L_add( a[j], a[j1] ); + x0i = L_add( a[j + 1], a[j1 + 1] ); + x1r = L_sub( a[j], a[j1] ); + x1i = L_sub( a[j + 1], a[j1 + 1] ); + x2r = L_add( a[j2], a[j3] ); + x2i = L_add( a[j2 + 1], a[j3 + 1] ); + x3r = L_sub( a[j2], a[j3] ); + x3i = L_sub( a[j2 + 1], a[j3 + 1] ); + a[j] = L_add( x0r, x2r ); move32(); - a[j + 1] = L_add(x0i, x2i); + a[j + 1] = L_add( x0i, x2i ); move32(); - a[j2] = L_sub(x0r, x2r); + a[j2] = L_sub( x0r, x2r ); move32(); - a[j2 + 1] =L_sub(x0i, x2i); + a[j2 + 1] = L_sub( x0i, x2i ); move32(); - a[j1] = L_sub(x1r, x3i); + a[j1] = L_sub( x1r, x3i ); move32(); - a[j1 + 1] = L_add(x1i, x3r); + a[j1 + 1] = L_add( x1i, x3r ); move32(); - a[j3] = L_add(x1r, x3i); + a[j3] = L_add( x1r, x3i ); move32(); - a[j3 + 1] = L_sub(x1i, x3r); + a[j3 + 1] = L_sub( x1i, x3r ); move32(); } wk1r = w[2]; move16(); - tmp = add(l, m); - FOR (j = m; j < tmp; j += 2) - { - j1 = add(j, l); - j2 = add(j1, l); - j3 = add(j2, l); - x0r = L_add(a[j], a[j1]); - x0i = L_add(a[j + 1], a[j1 + 1]); - x1r = L_sub(a[j], a[j1]); - x1i = L_sub(a[j + 1], a[j1 + 1]); - x2r = L_add(a[j2], a[j3]); - x2i = L_add(a[j2 + 1], a[j3 + 1]); - x3r = L_sub(a[j2], a[j3]); - x3i = L_sub(a[j2 + 1], a[j3 + 1]); - a[j] = L_add(x0r, x2r); + tmp = add( l, m ); + FOR( j = m; j < tmp; j += 2 ) + { + j1 = add( j, l ); + j2 = add( j1, l ); + j3 = add( j2, l ); + x0r = L_add( a[j], a[j1] ); + x0i = L_add( a[j + 1], a[j1 + 1] ); + x1r = L_sub( a[j], a[j1] ); + x1i = L_sub( a[j + 1], a[j1 + 1] ); + x2r = L_add( a[j2], a[j3] ); + x2i = L_add( a[j2 + 1], a[j3 + 1] ); + x3r = L_sub( a[j2], a[j3] ); + x3i = L_sub( a[j2 + 1], a[j3 + 1] ); + a[j] = L_add( x0r, x2r ); move32(); - a[j + 1] = L_add(x0i, x2i); + a[j + 1] = L_add( x0i, x2i ); move32(); - a[j2] = L_sub(x2i, x0i); + a[j2] = L_sub( x2i, x0i ); move32(); - a[j2 + 1] = L_sub(x0r, x2r); + a[j2 + 1] = L_sub( x0r, x2r ); move32(); - x0r = L_sub(x1r, x3i); - x0i = L_add(x1i, x3r); - a[j1] = Mult_32_16(L_shl(L_sub(x0r, x0i), 1), wk1r); + x0r = L_sub( x1r, x3i ); + x0i = L_add( x1i, x3r ); + a[j1] = Mult_32_16( L_shl( L_sub( x0r, x0i ), 1 ), wk1r ); move32(); - a[j1 + 1] = Mult_32_16(L_shl(L_add(x0r, x0i), 1), wk1r); + a[j1 + 1] = Mult_32_16( L_shl( L_add( x0r, x0i ), 1 ), wk1r ); move32(); - x0r = L_add(x3i, x1r); - x0i = L_sub(x3r, x1i); - a[j3] = Mult_32_16(L_shl(L_sub(x0i, x0r), 1), wk1r); + x0r = L_add( x3i, x1r ); + x0i = L_sub( x3r, x1i ); + a[j3] = Mult_32_16( L_shl( L_sub( x0i, x0r ), 1 ), wk1r ); move32(); - a[j3 + 1] = Mult_32_16(L_shl(L_add(x0r, x0i), 1), wk1r); + a[j3 + 1] = Mult_32_16( L_shl( L_add( x0r, x0i ), 1 ), wk1r ); move32(); } k1 = 0; move16(); - m2 = shl(m, 1); - FOR (k = m2; k < n; k += m2) + m2 = shl( m, 1 ); + FOR( k = m2; k < n; k += m2 ) { - k1 = add(k1, 2); - k2 = shl(k1, 1); + k1 = add( k1, 2 ); + k2 = shl( k1, 1 ); wk2r = w[k1]; move16(); wk2i = w[k1 + 1]; @@ -618,44 +647,44 @@ static void cftmdl_fx( move16(); wk1i = w[k2 + 1]; move16(); - wk3r = extract_l(L_sub(L_deposit_l(wk1r), L_shr(L_mult(wk2i, wk1i), 14))); - wk3i = extract_l(L_msu0(L_shr(L_mult(wk2i, wk1r), 14), wk1i, 1)); + wk3r = extract_l( L_sub( L_deposit_l( wk1r ), L_shr( L_mult( wk2i, wk1i ), 14 ) ) ); + wk3i = extract_l( L_msu0( L_shr( L_mult( wk2i, wk1r ), 14 ), wk1i, 1 ) ); - tmp = add(l, k) ; - FOR (j = k; j < tmp; j += 2) + tmp = add( l, k ); + FOR( j = k; j < tmp; j += 2 ) { - j1 = add(j, l); - j2 = add(j1, l); - j3 = add(j2, l); - x0r = L_add(a[j], a[j1]); - x0i = L_add(a[j + 1], a[j1 + 1]); - x1r = L_sub(a[j], a[j1]); - x1i = L_sub(a[j + 1], a[j1 + 1]); - x2r = L_add(a[j2], a[j3]); - x2i = L_add(a[j2 + 1], a[j3 + 1]); - x3r = L_sub(a[j2], a[j3]); - x3i = L_sub(a[j2 + 1], a[j3 + 1]); - a[j] = L_add(x0r, x2r); + j1 = add( j, l ); + j2 = add( j1, l ); + j3 = add( j2, l ); + x0r = L_add( a[j], a[j1] ); + x0i = L_add( a[j + 1], a[j1 + 1] ); + x1r = L_sub( a[j], a[j1] ); + x1i = L_sub( a[j + 1], a[j1 + 1] ); + x2r = L_add( a[j2], a[j3] ); + x2i = L_add( a[j2 + 1], a[j3 + 1] ); + x3r = L_sub( a[j2], a[j3] ); + x3i = L_sub( a[j2 + 1], a[j3 + 1] ); + a[j] = L_add( x0r, x2r ); move32(); - a[j + 1] = L_add(x0i, x2i); + a[j + 1] = L_add( x0i, x2i ); move32(); - x0r = L_sub(x0r, x2r); - x0i = L_sub(x0i, x2i); - a[j2] = L_sub(Mult_32_16(L_shl(x0r, 1), wk2r), Mult_32_16(L_shl(x0i, 1), wk2i)); + x0r = L_sub( x0r, x2r ); + x0i = L_sub( x0i, x2i ); + a[j2] = L_sub( Mult_32_16( L_shl( x0r, 1 ), wk2r ), Mult_32_16( L_shl( x0i, 1 ), wk2i ) ); move32(); - a[j2 + 1] = L_add(Mult_32_16(L_shl(x0i, 1), wk2r), Mult_32_16(L_shl(x0r, 1), wk2i)); + a[j2 + 1] = L_add( Mult_32_16( L_shl( x0i, 1 ), wk2r ), Mult_32_16( L_shl( x0r, 1 ), wk2i ) ); move32(); - x0r = L_sub(x1r, x3i); - x0i = L_add(x1i, x3r); - a[j1] = L_sub(Mult_32_16(L_shl(x0r, 1), wk1r), Mult_32_16(L_shl(x0i, 1), wk1i)); + x0r = L_sub( x1r, x3i ); + x0i = L_add( x1i, x3r ); + a[j1] = L_sub( Mult_32_16( L_shl( x0r, 1 ), wk1r ), Mult_32_16( L_shl( x0i, 1 ), wk1i ) ); move32(); - a[j1 + 1] = L_add(Mult_32_16(L_shl(x0i, 1), wk1r), Mult_32_16(L_shl(x0r, 1), wk1i)); + a[j1 + 1] = L_add( Mult_32_16( L_shl( x0i, 1 ), wk1r ), Mult_32_16( L_shl( x0r, 1 ), wk1i ) ); move32(); - x0r = L_add(x1r, x3i); - x0i = L_sub(x1i, x3r); - a[j3] = L_sub(Mult_32_16(L_shl(x0r, 1), wk3r), Mult_32_16(L_shl(x0i, 1), wk3i)); + x0r = L_add( x1r, x3i ); + x0i = L_sub( x1i, x3r ); + a[j3] = L_sub( Mult_32_16( L_shl( x0r, 1 ), wk3r ), Mult_32_16( L_shl( x0i, 1 ), wk3i ) ); move32(); - a[j3 + 1] = L_add(Mult_32_16(L_shl(x0i, 1), wk3r), Mult_32_16(L_shl(x0r, 1), wk3i)); + a[j3 + 1] = L_add( Mult_32_16( L_shl( x0i, 1 ), wk3r ), Mult_32_16( L_shl( x0r, 1 ), wk3i ) ); move32(); } @@ -663,44 +692,44 @@ static void cftmdl_fx( move16(); wk1i = w[k2 + 3]; move16(); - wk3r = extract_l(L_sub(L_deposit_l(wk1r), L_shr(L_mult(wk2r, wk1i), 14))); - wk3i = extract_l(L_msu0(L_shr(L_mult(wk2r, wk1r), 14), wk1i, 1)); + wk3r = extract_l( L_sub( L_deposit_l( wk1r ), L_shr( L_mult( wk2r, wk1i ), 14 ) ) ); + wk3i = extract_l( L_msu0( L_shr( L_mult( wk2r, wk1r ), 14 ), wk1i, 1 ) ); - tmp = add(l, add(k, m)); - FOR (j = add(k, m); j < tmp; j += 2) + tmp = add( l, add( k, m ) ); + FOR( j = add( k, m ); j < tmp; j += 2 ) { - j1 = add(j, l); - j2 = add(j1, l); - j3 = add(j2, l); - x0r = L_add(a[j], a[j1]); - x0i = L_add(a[j + 1], a[j1 + 1]); - x1r = L_sub(a[j], a[j1]); - x1i = L_sub(a[j + 1], a[j1 + 1]); - x2r = L_add(a[j2], a[j3]); - x2i = L_add(a[j2 + 1], a[j3 + 1]); - x3r = L_sub(a[j2], a[j3]); - x3i = L_sub(a[j2 + 1], a[j3 + 1]); - a[j] = L_add(x0r, x2r); + j1 = add( j, l ); + j2 = add( j1, l ); + j3 = add( j2, l ); + x0r = L_add( a[j], a[j1] ); + x0i = L_add( a[j + 1], a[j1 + 1] ); + x1r = L_sub( a[j], a[j1] ); + x1i = L_sub( a[j + 1], a[j1 + 1] ); + x2r = L_add( a[j2], a[j3] ); + x2i = L_add( a[j2 + 1], a[j3 + 1] ); + x3r = L_sub( a[j2], a[j3] ); + x3i = L_sub( a[j2 + 1], a[j3 + 1] ); + a[j] = L_add( x0r, x2r ); move32(); - a[j + 1] = L_add(x0i, x2i); + a[j + 1] = L_add( x0i, x2i ); move32(); - x0r= L_sub(x0r, x2r); - x0i=L_sub(x0i, x2i); - a[j2] = L_negate(L_add(Mult_32_16(L_shl(x0r, 1), wk2i), Mult_32_16(L_shl(x0i, 1), wk2r))); + x0r = L_sub( x0r, x2r ); + x0i = L_sub( x0i, x2i ); + a[j2] = L_negate( L_add( Mult_32_16( L_shl( x0r, 1 ), wk2i ), Mult_32_16( L_shl( x0i, 1 ), wk2r ) ) ); move32(); - a[j2 + 1] = L_sub(Mult_32_16(L_shl(x0r, 1), wk2r), Mult_32_16(L_shl(x0i, 1), wk2i)); + a[j2 + 1] = L_sub( Mult_32_16( L_shl( x0r, 1 ), wk2r ), Mult_32_16( L_shl( x0i, 1 ), wk2i ) ); move32(); - x0r = L_sub(x1r, x3i); - x0i = L_add(x1i, x3r); - a[j1] = L_sub(Mult_32_16(L_shl(x0r, 1), wk1r), Mult_32_16(L_shl(x0i, 1), wk1i)); + x0r = L_sub( x1r, x3i ); + x0i = L_add( x1i, x3r ); + a[j1] = L_sub( Mult_32_16( L_shl( x0r, 1 ), wk1r ), Mult_32_16( L_shl( x0i, 1 ), wk1i ) ); move32(); - a[j1 + 1] = L_add(Mult_32_16(L_shl(x0i, 1), wk1r), Mult_32_16(L_shl(x0r, 1), wk1i)); + a[j1 + 1] = L_add( Mult_32_16( L_shl( x0i, 1 ), wk1r ), Mult_32_16( L_shl( x0r, 1 ), wk1i ) ); move32(); - x0r = L_add(x1r, x3i); - x0i = L_sub(x1i, x3r); - a[j3] = L_sub(Mult_32_16(L_shl(x0r, 1), wk3r), Mult_32_16(L_shl(x0i, 1), wk3i)); + x0r = L_add( x1r, x3i ); + x0i = L_sub( x1i, x3r ); + a[j3] = L_sub( Mult_32_16( L_shl( x0r, 1 ), wk3r ), Mult_32_16( L_shl( x0i, 1 ), wk3i ) ); move32(); - a[j3 + 1] = L_add(Mult_32_16(L_shl(x0i, 1), wk3r), Mult_32_16(L_shl(x0r, 1), wk3i)); + a[j3 + 1] = L_add( Mult_32_16( L_shl( x0i, 1 ), wk3r ), Mult_32_16( L_shl( x0r, 1 ), wk3i ) ); move32(); } } @@ -712,7 +741,7 @@ static void cftmdl_fx( static void cftbsub_fx( Word16 n, Word32 *a, - const Word16 *w /* i : cos/sin table */ + const Word16 *w /* i : cos/sin table */ ) { Word16 j, j1, j2, j3, l; @@ -720,62 +749,62 @@ static void cftbsub_fx( l = 2; move16(); - IF (n > 8) + IF( n > 8 ) { - cft1st_fx(n, a, w); + cft1st_fx( n, a, w ); l = 8; move16(); - WHILE (LT_16(shl(l, 2), n)) + WHILE( LT_16( shl( l, 2 ), n ) ) { - cftmdl_fx(n, l, a, w); - l = shl(l, 2); + cftmdl_fx( n, l, a, w ); + l = shl( l, 2 ); } } - IF (EQ_16(shl(l, 2), n)) + IF( EQ_16( shl( l, 2 ), n ) ) { - FOR (j = 0; j < l; j += 2) + FOR( j = 0; j < l; j += 2 ) { - j1 = add(j, l); - j2 = add(j1, l); - j3 = add(j2, l); - x0r = L_add(a[j], a[j1]); - x0i = L_negate(L_add(a[j + 1], a[j1 + 1])); - x1r = L_sub(a[j], a[j1]); - x1i = L_sub(a[j1 + 1], a[j + 1]); - x2r = L_add(a[j2], a[j3]); - x2i = L_add(a[j2 + 1], a[j3 + 1]); - x3r = L_sub(a[j2], a[j3]); - x3i = L_sub(a[j2 + 1], a[j3 + 1]); - a[j] = L_add(x0r, x2r); + j1 = add( j, l ); + j2 = add( j1, l ); + j3 = add( j2, l ); + x0r = L_add( a[j], a[j1] ); + x0i = L_negate( L_add( a[j + 1], a[j1 + 1] ) ); + x1r = L_sub( a[j], a[j1] ); + x1i = L_sub( a[j1 + 1], a[j + 1] ); + x2r = L_add( a[j2], a[j3] ); + x2i = L_add( a[j2 + 1], a[j3 + 1] ); + x3r = L_sub( a[j2], a[j3] ); + x3i = L_sub( a[j2 + 1], a[j3 + 1] ); + a[j] = L_add( x0r, x2r ); move32(); - a[j + 1] = L_sub(x0i, x2i); + a[j + 1] = L_sub( x0i, x2i ); move32(); - a[j2] = L_sub(x0r, x2r); + a[j2] = L_sub( x0r, x2r ); move32(); - a[j2 + 1] = L_add(x0i, x2i); + a[j2 + 1] = L_add( x0i, x2i ); move32(); - a[j1] = L_sub(x1r, x3i); + a[j1] = L_sub( x1r, x3i ); move32(); - a[j1 + 1] = L_sub(x1i, x3r); + a[j1 + 1] = L_sub( x1i, x3r ); move32(); - a[j3] = L_add(x1r, x3i); + a[j3] = L_add( x1r, x3i ); move32(); - a[j3 + 1] = L_add(x1i, x3r); + a[j3 + 1] = L_add( x1i, x3r ); move32(); } } ELSE { - FOR (j = 0; j < l; j += 2) + FOR( j = 0; j < l; j += 2 ) { - j1 = add(j, l); - x0r = L_sub(a[j], a[j1]); - x0i = L_sub(a[j1 + 1], a[j + 1]); - a[j] = L_add(a[j], a[j1]); + j1 = add( j, l ); + x0r = L_sub( a[j], a[j1] ); + x0i = L_sub( a[j1 + 1], a[j + 1] ); + a[j] = L_add( a[j], a[j1] ); move32(); - a[j + 1] = L_negate(L_add(a[j + 1], a[j1 + 1])); + a[j + 1] = L_negate( L_add( a[j + 1], a[j1 + 1] ) ); move32(); a[j1] = x0r; move32(); @@ -791,43 +820,42 @@ static void rftfsub_fx( Word16 n, Word32 *a, Word16 nc, - const Word16 *c -) + const Word16 *c ) { Word16 j, k, kk, ks, m, tmp; Word32 xr, xi, yr, yi; Word16 wkr, wki; - m = shr(n, 1); + m = shr( n, 1 ); /*ks = 2 * nc / m; */ - tmp = shl(nc, 1); + tmp = shl( nc, 1 ); ks = 0; move16(); - WHILE (GE_16(tmp, m)) + WHILE( GE_16( tmp, m ) ) { - ks = add(ks, 1); - tmp = sub(tmp, m); + ks = add( ks, 1 ); + tmp = sub( tmp, m ); } kk = 0; move16(); - FOR (j = 2; j < m; j += 2) + FOR( j = 2; j < m; j += 2 ) { - k = sub(n, j); - kk = add(kk, ks); - wkr = sub(8192, c[nc - kk]); + k = sub( n, j ); + kk = add( kk, ks ); + wkr = sub( 8192, c[nc - kk] ); wki = c[kk]; move16(); - xr = L_sub(a[j], a[k]); - xi = L_add(a[j + 1], a[k + 1]); - yr = L_sub(Mult_32_16(L_shl(xr, 1), wkr), Mult_32_16(L_shl(xi, 1), wki)); - yi = L_add(Mult_32_16(L_shl(xi, 1), wkr), Mult_32_16(L_shl(xr, 1), wki)); - a[j] = L_sub(a[j], yr); + xr = L_sub( a[j], a[k] ); + xi = L_add( a[j + 1], a[k + 1] ); + yr = L_sub( Mult_32_16( L_shl( xr, 1 ), wkr ), Mult_32_16( L_shl( xi, 1 ), wki ) ); + yi = L_add( Mult_32_16( L_shl( xi, 1 ), wkr ), Mult_32_16( L_shl( xr, 1 ), wki ) ); + a[j] = L_sub( a[j], yr ); move32(); - a[j + 1] = L_sub(a[j + 1], yi); + a[j + 1] = L_sub( a[j + 1], yi ); move32(); - a[k] = L_add(a[k], yr); + a[k] = L_add( a[k], yr ); move32(); - a[k + 1] = L_sub(a[k + 1], yi); + a[k + 1] = L_sub( a[k + 1], yi ); move32(); } } @@ -837,47 +865,46 @@ static void rftbsub_fx( Word16 n, Word32 *a, Word16 nc, - const Word16 *c -) + const Word16 *c ) { Word16 j, k, kk, ks, m, tmp; Word32 xr, xi, yr, yi; Word16 wkr, wki; - a[1] = L_negate(a[1]); - m = shr(n, 1); + a[1] = L_negate( a[1] ); + m = shr( n, 1 ); /*ks = 2 * nc / m; */ - tmp = shl(nc, 1); + tmp = shl( nc, 1 ); ks = 0; move16(); - WHILE (GE_16(tmp, m)) + WHILE( GE_16( tmp, m ) ) { - ks = add(ks, 1); - tmp = sub(tmp, m); + ks = add( ks, 1 ); + tmp = sub( tmp, m ); } kk = 0; move16(); - FOR (j = 2; j < m; j += 2) + FOR( j = 2; j < m; j += 2 ) { - k = sub(n, j); - kk = add(kk, ks); - wkr = sub(8192, c[nc - kk]); + k = sub( n, j ); + kk = add( kk, ks ); + wkr = sub( 8192, c[nc - kk] ); wki = c[kk]; move16(); - xr = L_sub(a[j], a[k]); - xi = L_add(a[j + 1], a[k + 1]); - yr = L_add(Mult_32_16(L_shl(xr, 1), wkr), Mult_32_16(L_shl(xi, 1), wki)); - yi = L_sub(Mult_32_16(L_shl(xi, 1), wkr), Mult_32_16(L_shl(xr, 1), wki)); - a[j] = L_sub(a[j], yr); + xr = L_sub( a[j], a[k] ); + xi = L_add( a[j + 1], a[k + 1] ); + yr = L_add( Mult_32_16( L_shl( xr, 1 ), wkr ), Mult_32_16( L_shl( xi, 1 ), wki ) ); + yi = L_sub( Mult_32_16( L_shl( xi, 1 ), wkr ), Mult_32_16( L_shl( xr, 1 ), wki ) ); + a[j] = L_sub( a[j], yr ); move32(); - a[j + 1] = L_sub(yi, a[j + 1]); + a[j + 1] = L_sub( yi, a[j + 1] ); move32(); - a[k] = L_add(a[k], yr); + a[k] = L_add( a[k], yr ); move32(); - a[k + 1] = L_sub(yi, a[k + 1]); + a[k + 1] = L_sub( yi, a[k + 1] ); move32(); } - a[m + 1] = L_negate(a[m + 1]); + a[m + 1] = L_negate( a[m + 1] ); move32(); } @@ -886,39 +913,38 @@ static void dctsub_fx( Word16 n, Word32 *a, Word16 nc, - const Word16 *c -) + const Word16 *c ) { Word16 j, k, kk, ks, m, tmp; Word16 wkr, wki; Word32 xr; - m = shr(n, 1); + m = shr( n, 1 ); /*ks = nc / n; */ tmp = nc; move16(); ks = 0; move16(); - WHILE (GE_16(tmp, n)) + WHILE( GE_16( tmp, n ) ) { - ks = add(ks, 1); - tmp = sub(tmp, n); + ks = add( ks, 1 ); + tmp = sub( tmp, n ); } kk = 0; move16(); - FOR (j = 1; j < m; j++) + FOR( j = 1; j < m; j++ ) { - k = sub(n, j); - kk = add(kk, ks); - wkr = sub(c[kk], c[nc - kk]); - wki = add(c[kk], c[nc - kk]); - xr = L_sub(Mult_32_16(L_shl(a[j], 1), wki), Mult_32_16(L_shl(a[k], 1), wkr)); - a[j] = L_add(Mult_32_16(L_shl(a[j], 1), wkr), Mult_32_16(L_shl(a[k], 1), wki)); + k = sub( n, j ); + kk = add( kk, ks ); + wkr = sub( c[kk], c[nc - kk] ); + wki = add( c[kk], c[nc - kk] ); + xr = L_sub( Mult_32_16( L_shl( a[j], 1 ), wki ), Mult_32_16( L_shl( a[k], 1 ), wkr ) ); + a[j] = L_add( Mult_32_16( L_shl( a[j], 1 ), wkr ), Mult_32_16( L_shl( a[k], 1 ), wki ) ); move32(); a[k] = xr; move32(); } - a[m] = Mult_32_16(L_shl(a[m], 1), c[0]); + a[m] = Mult_32_16( L_shl( a[m], 1 ), c[0] ); } /*-----------------------------------------------------------------* @@ -935,99 +961,98 @@ void edct2_fx( Word32 *a, Word16 *q, const Word16 *ip, - const Word16 *w -) + const Word16 *w ) { Word16 j, nw, nc; Word32 xr; - *q = Exp16Array(n, in); - *q = add(*q, 6); - FOR (j = 0; j < n; j++) + *q = Exp16Array( n, in ); + *q = add( *q, 6 ); + FOR( j = 0; j < n; j++ ) { - a[j] = L_shl((Word32) in[j], *q); + a[j] = L_shl( (Word32) in[j], *q ); move32(); } nw = ip[0]; move16(); - if (GT_16(n, shl(nw, 2))) + if ( GT_16( n, shl( nw, 2 ) ) ) { - nw = shr(n, 2); + nw = shr( n, 2 ); } nc = ip[1]; move16(); - if (n > nc) + if ( n > nc ) { nc = n; move16(); } - IF (isgn < 0) + IF( isgn < 0 ) { xr = a[n - 1]; move32(); - FOR (j = n - 2; j >= 2; j -= 2) + FOR( j = n - 2; j >= 2; j -= 2 ) { - a[j + 1] = L_sub(a[j], a[j - 1]); + a[j + 1] = L_sub( a[j], a[j - 1] ); move32(); - a[j] = L_add(a[j], a[j - 1]); + a[j] = L_add( a[j], a[j - 1] ); move32(); } - a[1] = L_sub(a[0], xr); + a[1] = L_sub( a[0], xr ); move32(); - a[0] = L_add(a[0], xr); + a[0] = L_add( a[0], xr ); move32(); - IF (n > 4) + IF( n > 4 ) { - rftbsub_fx(n, a, nc, w + nw); - bitrv2_SR_fx(n, ip + 2, a); - cftbsub_fx(n, a, w); + rftbsub_fx( n, a, nc, w + nw ); + bitrv2_SR_fx( n, ip + 2, a ); + cftbsub_fx( n, a, w ); } - ELSE IF (n == 4) + ELSE IF( n == 4 ) { - cftfsub_fx(n, a, w); + cftfsub_fx( n, a, w ); } } - IF (isgn >= 0) + IF( isgn >= 0 ) { - a[0] = L_shr(a[0], 1); + a[0] = L_shr( a[0], 1 ); move32(); } - dctsub_fx(n, a, nc, w + nw); + dctsub_fx( n, a, nc, w + nw ); - IF (isgn >= 0) + IF( isgn >= 0 ) { - IF (n > 4) + IF( n > 4 ) { - bitrv2_SR_fx(n, ip + 2, a); - cftfsub_fx(n, a, w); - rftfsub_fx(n, a, nc, w + nw); + bitrv2_SR_fx( n, ip + 2, a ); + cftfsub_fx( n, a, w ); + rftfsub_fx( n, a, nc, w + nw ); } - ELSE IF (n == 4) + ELSE IF( n == 4 ) { - cftfsub_fx(n, a, w); + cftfsub_fx( n, a, w ); } - xr = L_sub(a[0], a[1]); - a[0] = L_add(a[0], a[1]); + xr = L_sub( a[0], a[1] ); + a[0] = L_add( a[0], a[1] ); move32(); - FOR (j = 2; j < n; j += 2) + FOR( j = 2; j < n; j += 2 ) { - a[j - 1] = L_sub(a[j], a[j + 1]); + a[j - 1] = L_sub( a[j], a[j + 1] ); move32(); - a[j] = L_add(a[j], a[j + 1]); + a[j] = L_add( a[j], a[j + 1] ); move32(); } a[n - 1] = xr; move32(); - FOR (j = 0; j < n; j ++) + FOR( j = 0; j < n; j++ ) { - a[j] = L_shr(a[j], 5); + a[j] = L_shr( a[j], 5 ); move32(); } } @@ -1035,19 +1060,19 @@ void edct2_fx( /*-----------------------------------------------------------------* -* fft5_shift4() -* 5-point FFT with 4-point circular shift -*-----------------------------------------------------------------*/ + * fft5_shift4() + * 5-point FFT with 4-point circular shift + *-----------------------------------------------------------------*/ static void fft5_shift4_16fx( - Word16 n1, /* i : length of data */ - Word16 *zRe, /* i/o : real part of input and output data */ - Word16 *zIm, /* i/o : imaginary part of input and output data */ - const Word16 *Idx /* i : pointer of the address table */ + Word16 n1, /* i : length of data */ + Word16 *zRe, /* i/o : real part of input and output data */ + Word16 *zIm, /* i/o : imaginary part of input and output data */ + const Word16 *Idx /* i : pointer of the address table */ ) { - Word16 T1, To, T8, Tt, T9, Ts, Te, Tp, Th, Tn,T2, T3, T4, T5, T6, T7; - Word16 i0,i1,i2,i3,i4; + Word16 T1, To, T8, Tt, T9, Ts, Te, Tp, Th, Tn, T2, T3, T4, T5, T6, T7; + Word16 i0, i1, i2, i3, i4; Word32 L_tmp; @@ -1055,11 +1080,11 @@ static void fft5_shift4_16fx( move16(); i1 = Idx[n1]; move16(); - i2 = Idx[n1*2]; + i2 = Idx[n1 * 2]; move16(); - i3 = Idx[n1*3]; + i3 = Idx[n1 * 3]; move16(); - i4 = Idx[n1*4]; + i4 = Idx[n1 * 4]; move16(); T1 = zRe[i0]; @@ -1074,168 +1099,168 @@ static void fft5_shift4_16fx( #ifdef BASOP_NOGLOB T4 = add_sat( T2, T3 ); #else - T4 = add(T2,T3); + T4 = add( T2, T3 ); #endif T5 = zRe[i2]; move16(); T6 = zRe[i3]; move16(); #ifdef BASOP_NOGLOB - T7 = add_sat(T5,T6); - T8 = add_sat(T4,T7); - Tt = sub_sat(T5,T6); + T7 = add_sat( T5, T6 ); + T8 = add_sat( T4, T7 ); + Tt = sub_sat( T5, T6 ); #else - T7 = add(T5,T6); - T8 = add(T4,T7); - Tt = sub(T5,T6); + T7 = add( T5, T6 ); + T8 = add( T4, T7 ); + Tt = sub( T5, T6 ); #endif /* T9 = KP559016994 * (T4 - T7); */ #ifdef BASOP_NOGLOB - L_tmp = Mult_32_16(KP559016994_16FX,sub_sat(T4,T7)); - T9 = round_fx_sat(L_tmp); - Ts = sub_sat(T2,T3); + L_tmp = Mult_32_16( KP559016994_16FX, sub_sat( T4, T7 ) ); + T9 = round_fx_sat( L_tmp ); + Ts = sub_sat( T2, T3 ); #else - L_tmp = Mult_32_16(KP559016994_16FX,sub(T4,T7)); - T9 = round_fx(L_tmp); - Ts = sub(T2,T3); + L_tmp = Mult_32_16( KP559016994_16FX, sub( T4, T7 ) ); + T9 = round_fx( L_tmp ); + Ts = sub( T2, T3 ); #endif T2 = zIm[i1]; move16(); T3 = zIm[i4]; move16(); - T4 = add(T2,T3); + T4 = add( T2, T3 ); T5 = zIm[i2]; move16(); T6 = zIm[i3]; move16(); #ifdef BASOP_NOGLOB - T7 = add_sat(T5,T6); - Te = sub_sat(T2,T3); - Tp = add_sat(T4,T7); - Th = sub_sat(T5,T6); + T7 = add_sat( T5, T6 ); + Te = sub_sat( T2, T3 ); + Tp = add_sat( T4, T7 ); + Th = sub_sat( T5, T6 ); #else - T7 = add(T5,T6); - Te = sub(T2,T3); - Tp = add(T4,T7); - Th = sub(T5,T6); + T7 = add( T5, T6 ); + Te = sub( T2, T3 ); + Tp = add( T4, T7 ); + Th = sub( T5, T6 ); #endif #ifdef BASOP_NOGLOB /* Tn = KP559016994 * (T4 - T7); */ - L_tmp = Mult_32_16(KP559016994_16FX, sub_sat(T4, T7)); - Tn = round_fx_sat(L_tmp); - zRe[i0] = add_sat(T1, T8); + L_tmp = Mult_32_16( KP559016994_16FX, sub_sat( T4, T7 ) ); + Tn = round_fx_sat( L_tmp ); + zRe[i0] = add_sat( T1, T8 ); move16(); - zIm[i0] = add_sat(To, Tp); + zIm[i0] = add_sat( To, Tp ); #else /* Tn = KP559016994 * (T4 - T7); */ - L_tmp = Mult_32_16(KP559016994_16FX, sub(T4, T7)); - Tn = round_fx(L_tmp); - zRe[i0] = add(T1,T8); + L_tmp = Mult_32_16( KP559016994_16FX, sub( T4, T7 ) ); + Tn = round_fx( L_tmp ); + zRe[i0] = add( T1, T8 ); move16(); - zIm[i0] = add(To, Tp); + zIm[i0] = add( To, Tp ); #endif move16(); /* T2 = KP951056516*Te + KP587785252*Th; */ - L_tmp = Mult_32_16(KP951056516_16FX,Te); - L_tmp = Madd_32_16(L_tmp,KP587785252_16FX,Th); + L_tmp = Mult_32_16( KP951056516_16FX, Te ); + L_tmp = Madd_32_16( L_tmp, KP587785252_16FX, Th ); #ifdef BASOP_NOGLOB - T2 = round_fx_sat(L_tmp); + T2 = round_fx_sat( L_tmp ); #else - T2 = round_fx(L_tmp); + T2 = round_fx( L_tmp ); #endif /*T3 = KP951056516*Th - KP587785252*Te; */ - L_tmp = Mult_32_16(KP951056516_16FX,Th); - L_tmp = Msub_32_16(L_tmp,KP587785252_16FX,Te); + L_tmp = Mult_32_16( KP951056516_16FX, Th ); + L_tmp = Msub_32_16( L_tmp, KP587785252_16FX, Te ); #ifdef BASOP_NOGLOB - T3 = round_fx_sat(L_tmp); + T3 = round_fx_sat( L_tmp ); #else - T3 = round_fx(L_tmp); + T3 = round_fx( L_tmp ); #endif #ifdef BASOP_NOGLOB - T6 = sub_sat(T1, shr_sat(T8, 2)); - T4 = add_sat(T9, T6); - T5 = sub_sat(T6, T9); - zRe[i1] = sub_sat(T4, T2); + T6 = sub_sat( T1, shr_sat( T8, 2 ) ); + T4 = add_sat( T9, T6 ); + T5 = sub_sat( T6, T9 ); + zRe[i1] = sub_sat( T4, T2 ); move16(); - zRe[i2] = add_sat(T5, T3); + zRe[i2] = add_sat( T5, T3 ); move16(); - zRe[i4] = add_sat(T4, T2); + zRe[i4] = add_sat( T4, T2 ); move16(); - zRe[i3] = sub_sat(T5, T3); + zRe[i3] = sub_sat( T5, T3 ); move16(); #else - T6 = sub(T1, shr(T8, 2)); - T4 = add(T9, T6); - T5 = sub(T6, T9); - zRe[i1] = sub(T4, T2); + T6 = sub( T1, shr( T8, 2 ) ); + T4 = add( T9, T6 ); + T5 = sub( T6, T9 ); + zRe[i1] = sub( T4, T2 ); move16(); - zRe[i2] = add(T5, T3); + zRe[i2] = add( T5, T3 ); move16(); - zRe[i4] = add(T4,T2); + zRe[i4] = add( T4, T2 ); move16(); - zRe[i3] = sub(T5, T3); + zRe[i3] = sub( T5, T3 ); move16(); #endif /* T2 = KP951056516 * Ts + KP587785252 * Tt; */ - L_tmp = Mult_32_16(KP951056516_16FX,Ts); - L_tmp = Madd_32_16(L_tmp,KP587785252_16FX,Tt); + L_tmp = Mult_32_16( KP951056516_16FX, Ts ); + L_tmp = Madd_32_16( L_tmp, KP587785252_16FX, Tt ); #ifdef BASOP_NOGLOB T2 = round_fx_sat( L_tmp ); #else - T2 = round_fx(L_tmp); + T2 = round_fx( L_tmp ); #endif /* T3 = KP951056516 * Tt - KP587785252 * Ts; */ - L_tmp = Mult_32_16(KP951056516_16FX,Tt); - L_tmp = Msub_32_16(L_tmp,KP587785252_16FX,Ts); + L_tmp = Mult_32_16( KP951056516_16FX, Tt ); + L_tmp = Msub_32_16( L_tmp, KP587785252_16FX, Ts ); #ifdef BASOP_NOGLOB T3 = round_fx_sat( L_tmp ); #else - T3 = round_fx(L_tmp); + T3 = round_fx( L_tmp ); #endif #ifdef BASOP_NOGLOB - T6 = sub_sat(To, shr(Tp, 2)); - T4 = add_sat(Tn, T6); - T5 = sub_sat(T6, Tn); - zIm[i4] = sub_sat(T4,T2); + T6 = sub_sat( To, shr( Tp, 2 ) ); + T4 = add_sat( Tn, T6 ); + T5 = sub_sat( T6, Tn ); + zIm[i4] = sub_sat( T4, T2 ); move16(); - zIm[i2] = sub_sat(T5,T3); + zIm[i2] = sub_sat( T5, T3 ); move16(); - zIm[i1] = add_sat(T2,T4); + zIm[i1] = add_sat( T2, T4 ); move16(); - zIm[i3] = add_sat(T3,T5); + zIm[i3] = add_sat( T3, T5 ); move16(); #else - T6 = sub(To, shr(Tp, 2)); - T4 = add(Tn, T6); - T5 = sub(T6, Tn); - zIm[i4] = sub(T4,T2); + T6 = sub( To, shr( Tp, 2 ) ); + T4 = add( Tn, T6 ); + T5 = sub( T6, Tn ); + zIm[i4] = sub( T4, T2 ); move16(); - zIm[i2] = sub(T5,T3); + zIm[i2] = sub( T5, T3 ); move16(); - zIm[i1] = add(T2,T4); + zIm[i1] = add( T2, T4 ); move16(); - zIm[i3] = add(T3,T5); + zIm[i3] = add( T3, T5 ); move16(); #endif return; } /*-----------------------------------------------------------------* -* fft5_32() -* 5-point FFT called for 32 times -*-----------------------------------------------------------------*/ + * fft5_32() + * 5-point FFT called for 32 times + *-----------------------------------------------------------------*/ static void fft5_32_16fx( - Word16 *zRe, /* i/o : real part of input and output data */ - Word16 *zIm, /* i/o : imaginary part of input and output data */ - const Word16 *Idx /* i : pointer of the address table */ + Word16 *zRe, /* i/o : real part of input and output data */ + Word16 *zIm, /* i/o : imaginary part of input and output data */ + const Word16 *Idx /* i : pointer of the address table */ ) { - Word16 T1, To, T8, Tt, T9, Ts, Te, Tp, Th, Tn,T2, T3, T4, T5, T6, T7; - Word16 i0,i1,i2,i3,i4; + Word16 T1, To, T8, Tt, T9, Ts, Te, Tp, Th, Tn, T2, T3, T4, T5, T6, T7; + Word16 i0, i1, i2, i3, i4; Word32 L_tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; @@ -1262,169 +1287,167 @@ static void fft5_32_16fx( move16(); #ifdef BASOP_NOGLOB - T4 = add_sat(T2, T3); + T4 = add_sat( T2, T3 ); T5 = zRe[i2]; move16(); T6 = zRe[i3]; move16(); - T7 = add_o(T5,T6, &Overflow); - T8 = add_o(T4,T7, &Overflow); - Tt = sub_o(T5,T6, &Overflow); + T7 = add_o( T5, T6, &Overflow ); + T8 = add_o( T4, T7, &Overflow ); + Tt = sub_o( T5, T6, &Overflow ); #else - T4 = add(T2, T3); + T4 = add( T2, T3 ); T5 = zRe[i2]; move16(); T6 = zRe[i3]; move16(); - T7 = add(T5,T6); - T8 = add(T4,T7); - Tt = sub(T5,T6); + T7 = add( T5, T6 ); + T8 = add( T4, T7 ); + Tt = sub( T5, T6 ); #endif #ifdef BASOP_NOGLOB /* T9 = KP559016994 * (T4 - T7); */ - L_tmp = Mult_32_16(KP559016994_16FX, sub_sat(T4, T7)); - T9 = round_fx_sat(L_tmp); - Ts = sub_sat(T2, T3); + L_tmp = Mult_32_16( KP559016994_16FX, sub_sat( T4, T7 ) ); + T9 = round_fx_sat( L_tmp ); + Ts = sub_sat( T2, T3 ); T2 = zIm[i1]; move16(); T3 = zIm[i4]; move16(); - T4 = add_sat(T2, T3); + T4 = add_sat( T2, T3 ); T5 = zIm[i2]; move16(); T6 = zIm[i3]; move16(); - T7 = add_sat(T5,T6); - Te = sub_sat(T2,T3); - Tp = add_sat(T4,T7); - Th = sub_sat(T5,T6); - L_tmp = Mult_32_16(KP559016994_16FX,sub_sat(T4,T7)); - Tn = round_fx_sat(L_tmp); + T7 = add_sat( T5, T6 ); + Te = sub_sat( T2, T3 ); + Tp = add_sat( T4, T7 ); + Th = sub_sat( T5, T6 ); + L_tmp = Mult_32_16( KP559016994_16FX, sub_sat( T4, T7 ) ); + Tn = round_fx_sat( L_tmp ); #else /* T9 = KP559016994 * (T4 - T7); */ - L_tmp = Mult_32_16(KP559016994_16FX, sub(T4, T7)); - T9 = round_fx(L_tmp); - Ts = sub(T2, T3); + L_tmp = Mult_32_16( KP559016994_16FX, sub( T4, T7 ) ); + T9 = round_fx( L_tmp ); + Ts = sub( T2, T3 ); T2 = zIm[i1]; move16(); T3 = zIm[i4]; move16(); - T4 = add(T2, T3); + T4 = add( T2, T3 ); T5 = zIm[i2]; move16(); T6 = zIm[i3]; move16(); - T7 = add(T5,T6); - Te = sub(T2,T3); - Tp = add(T4,T7); - Th = sub(T5,T6); - L_tmp = Mult_32_16(KP559016994_16FX,sub(T4,T7)); - Tn = round_fx(L_tmp); + T7 = add( T5, T6 ); + Te = sub( T2, T3 ); + Tp = add( T4, T7 ); + Th = sub( T5, T6 ); + L_tmp = Mult_32_16( KP559016994_16FX, sub( T4, T7 ) ); + Tn = round_fx( L_tmp ); #endif #ifdef BASOP_NOGLOB - zRe[i0] = add_o(T1,T8, &Overflow); + zRe[i0] = add_o( T1, T8, &Overflow ); move16(); - zIm[i0] = add_o(To,Tp, &Overflow); + zIm[i0] = add_o( To, Tp, &Overflow ); move32(); #else - zRe[i0] = add(T1,T8); + zRe[i0] = add( T1, T8 ); move16(); - zIm[i0] = add(To,Tp); + zIm[i0] = add( To, Tp ); move32(); #endif #ifdef BASOP_NOGLOB /*T2 = KP951056516*Te + KP587785252*Th; */ - L_tmp = Mult_32_16(KP951056516_16FX, Te); - L_tmp = Madd_32_16(L_tmp, KP587785252_16FX, Th); - T2 = round_fx_sat(L_tmp); + L_tmp = Mult_32_16( KP951056516_16FX, Te ); + L_tmp = Madd_32_16( L_tmp, KP587785252_16FX, Th ); + T2 = round_fx_sat( L_tmp ); /*T3 = KP951056516*Th - KP587785252*Te; */ - L_tmp = Mult_32_16(KP951056516_16FX, Th); - L_tmp = Msub_32_16(L_tmp, KP587785252_16FX, Te); - T3 = round_fx_sat(L_tmp); - + L_tmp = Mult_32_16( KP951056516_16FX, Th ); + L_tmp = Msub_32_16( L_tmp, KP587785252_16FX, Te ); + T3 = round_fx_sat( L_tmp ); - T6 = sub_sat(T1, shr(T8, 2)); - T4 = add_sat(T9, T6); - T5 = sub_sat(T6, T9); + T6 = sub_sat( T1, shr( T8, 2 ) ); + T4 = add_sat( T9, T6 ); + T5 = sub_sat( T6, T9 ); - zRe[i3] = sub_o(T4,T2, &Overflow); + zRe[i3] = sub_o( T4, T2, &Overflow ); move32(); - zRe[i1] = add_o(T5,T3, &Overflow); + zRe[i1] = add_o( T5, T3, &Overflow ); move32(); - zRe[i2] = add_o(T4,T2, &Overflow); + zRe[i2] = add_o( T4, T2, &Overflow ); move32(); - zRe[i4] = sub_o(T5,T3, &Overflow); + zRe[i4] = sub_o( T5, T3, &Overflow ); move32(); #else /*T2 = KP951056516*Te + KP587785252*Th; */ - L_tmp = Mult_32_16(KP951056516_16FX, Te); - L_tmp = Madd_32_16(L_tmp, KP587785252_16FX, Th); - T2 = round_fx(L_tmp); + L_tmp = Mult_32_16( KP951056516_16FX, Te ); + L_tmp = Madd_32_16( L_tmp, KP587785252_16FX, Th ); + T2 = round_fx( L_tmp ); /*T3 = KP951056516*Th - KP587785252*Te; */ - L_tmp = Mult_32_16(KP951056516_16FX, Th); - L_tmp = Msub_32_16(L_tmp, KP587785252_16FX, Te); - T3 = round_fx(L_tmp); + L_tmp = Mult_32_16( KP951056516_16FX, Th ); + L_tmp = Msub_32_16( L_tmp, KP587785252_16FX, Te ); + T3 = round_fx( L_tmp ); + T6 = sub( T1, shr( T8, 2 ) ); + T4 = add( T9, T6 ); + T5 = sub( T6, T9 ); - T6 = sub(T1, shr(T8, 2)); - T4 = add(T9, T6); - T5 = sub(T6, T9); - - zRe[i3] = sub(T4,T2); + zRe[i3] = sub( T4, T2 ); move32(); - zRe[i1] = add(T5,T3); + zRe[i1] = add( T5, T3 ); move32(); - zRe[i2] = add(T4,T2); + zRe[i2] = add( T4, T2 ); move32(); - zRe[i4] = sub(T5,T3); + zRe[i4] = sub( T5, T3 ); move32(); #endif /* T2 = KP951056516 * Ts + KP587785252 * Tt; */ - L_tmp = Mult_32_16(KP951056516_16FX,Ts); - L_tmp = Madd_32_16(L_tmp,KP587785252_16FX,Tt); - T2 = round_fx_sat(L_tmp); + L_tmp = Mult_32_16( KP951056516_16FX, Ts ); + L_tmp = Madd_32_16( L_tmp, KP587785252_16FX, Tt ); + T2 = round_fx_sat( L_tmp ); /* T3 = KP951056516 * Tt - KP587785252 * Ts; */ - L_tmp = Mult_32_16(KP951056516_16FX,Tt); - L_tmp = Msub_32_16(L_tmp,KP587785252_16FX,Ts); + L_tmp = Mult_32_16( KP951056516_16FX, Tt ); + L_tmp = Msub_32_16( L_tmp, KP587785252_16FX, Ts ); #ifdef BASOP_NOGLOB - T3 = round_fx_sat(L_tmp); + T3 = round_fx_sat( L_tmp ); - T6 = sub_sat(To, shr(Tp, 2)); - T4 = add_sat(Tn, T6); - T5 = sub_sat(T6, Tn); - zIm[i2] = sub_sat(T4,T2); + T6 = sub_sat( To, shr( Tp, 2 ) ); + T4 = add_sat( Tn, T6 ); + T5 = sub_sat( T6, Tn ); + zIm[i2] = sub_sat( T4, T2 ); move16(); - zIm[i1] = sub_sat(T5,T3); + zIm[i1] = sub_sat( T5, T3 ); move16(); - zIm[i3] = add_sat(T2,T4); + zIm[i3] = add_sat( T2, T4 ); move16(); - zIm[i4] = add_sat(T3,T5); + zIm[i4] = add_sat( T3, T5 ); move16(); #else - T3 = round_fx(L_tmp); + T3 = round_fx( L_tmp ); - T6 = sub(To, shr(Tp, 2)); - T4 = add(Tn, T6); - T5 = sub(T6, Tn); - zIm[i2] = sub(T4,T2); + T6 = sub( To, shr( Tp, 2 ) ); + T4 = add( Tn, T6 ); + T5 = sub( T6, Tn ); + zIm[i2] = sub( T4, T2 ); move16(); - zIm[i1] = sub(T5,T3); + zIm[i1] = sub( T5, T3 ); move16(); - zIm[i3] = add(T2,T4); + zIm[i3] = add( T2, T4 ); move16(); - zIm[i4] = add(T3,T5); + zIm[i4] = add( T3, T5 ); move16(); #endif @@ -1432,40 +1455,40 @@ static void fft5_32_16fx( } /*-----------------------------------------------------------------* -* fft64() -* 64-point FFT -*-----------------------------------------------------------------*/ + * fft64() + * 64-point FFT + *-----------------------------------------------------------------*/ static void fft64_16fx( - Word16 *x, /* i/o : real part of input and output data */ - Word16 *y, /* i/o : imaginary part of input and output data */ - const Word16 *Idx /* i : pointer of the address table */ + Word16 *x, /* i/o : real part of input and output data */ + Word16 *y, /* i/o : imaginary part of input and output data */ + const Word16 *Idx /* i : pointer of the address table */ ) { - Word16 i,id,jd; + Word16 i, id, jd; Word16 z[128]; - move16();/*penalty for 1 ptr init */ - FOR ( i=0; i<64; i++ ) + move16(); /*penalty for 1 ptr init */ + FOR( i = 0; i < 64; i++ ) { id = Idx[i]; move16(); - z[2*i] = x[id]; + z[2 * i] = x[id]; move16(); - z[2*i+1] = y[id]; + z[2 * i + 1] = y[id]; move16(); } - cdftForw_16fx(128, z, Ip_fft64, w_fft128_16fx); + cdftForw_16fx( 128, z, Ip_fft64, w_fft128_16fx ); - move16();/*penalty for 1 ptr init */ - FOR( i=0; i<64 ; i++) + move16(); /*penalty for 1 ptr init */ + FOR( i = 0; i < 64; i++ ) { jd = Odx_fft64[i]; move16(); id = Idx[jd]; move16(); - x[id]=z[2*i]; + x[id] = z[2 * i]; move16(); - y[id]=z[2*i+1]; + y[id] = z[2 * i + 1]; move16(); } @@ -1474,41 +1497,41 @@ static void fft64_16fx( /*-----------------------------------------------------------------* -* fft32_5() -* 32-point FFT called for 5 times -*-----------------------------------------------------------------*/ + * fft32_5() + * 32-point FFT called for 5 times + *-----------------------------------------------------------------*/ static void fft32_5_16fx( - Word16 *x, /* i/o : real part of input and output data */ - Word16 *y, /* i/o : imaginary part of input and output data */ - const Word16 *Idx /* i : pointer of the address table */ + Word16 *x, /* i/o : real part of input and output data */ + Word16 *y, /* i/o : imaginary part of input and output data */ + const Word16 *Idx /* i : pointer of the address table */ ) { - Word16 i,id,jd; + Word16 i, id, jd; Word16 z[64]; - move16();/*penalty for 1 ptr init */ - FOR( i=0; i<32; i++ ) + move16(); /*penalty for 1 ptr init */ + FOR( i = 0; i < 32; i++ ) { id = Idx[i]; move16(); - z[2*i] = x[id]; + z[2 * i] = x[id]; move16(); - z[2*i+1] = y[id]; + z[2 * i + 1] = y[id]; move16(); } - cdftForw_16fx(64,z,Ip_fft32,w_fft32_16fx); + cdftForw_16fx( 64, z, Ip_fft32, w_fft32_16fx ); - move16();/*penalty for 1 ptr init */ - FOR( i=0; i<32; i++ ) + move16(); /*penalty for 1 ptr init */ + FOR( i = 0; i < 32; i++ ) { jd = Odx_fft32_5[i]; move16(); id = Idx[jd]; move16(); - x[id]=z[2*i]; + x[id] = z[2 * i]; move16(); - y[id]=z[2*i+1]; + y[id] = z[2 * i + 1]; move16(); } @@ -1516,125 +1539,124 @@ static void fft32_5_16fx( } - /*-----------------------------------------------------------------* -* DoRTFT160() -* a low complexity 2-dimensional DFT of 160 points -*-----------------------------------------------------------------*/ + * DoRTFT160() + * a low complexity 2-dimensional DFT of 160 points + *-----------------------------------------------------------------*/ void DoRTFT160_16fx( - Word16 x[], /* i/o : real part of input and output data */ - Word16 y[] /* i/o : imaginary part of input and output data */ + Word16 x[], /* i/o : real part of input and output data */ + Word16 y[] /* i/o : imaginary part of input and output data */ ) { Word16 j; /* Applying 32-point FFT for 5 times based on the address table Idx_dortft160 */ - FOR(j=0; j<5; j++) + FOR( j = 0; j < 5; j++ ) { - fft32_5_16fx(x,y,Idx_dortft160+shl(j,5)/*32*j*/); + fft32_5_16fx( x, y, Idx_dortft160 + shl( j, 5 ) /*32*j*/ ); } /* Applying 5-point FFT for 32 times based on the address table Idx_dortft160 */ - FOR(j=0; j<32; j++) + FOR( j = 0; j < 32; j++ ) { - fft5_32_16fx(x,y,Idx_dortft160+j); + fft5_32_16fx( x, y, Idx_dortft160 + j ); } return; } /*-----------------------------------------------------------------* -* DoRTFT320() -* a low complexity 2-dimensional DFT of 320 points -*-----------------------------------------------------------------*/ + * DoRTFT320() + * a low complexity 2-dimensional DFT of 320 points + *-----------------------------------------------------------------*/ void DoRTFT320_16fx( - Word16 *x, /* i/o : real part of input and output data */ - Word16 *y /* i/o : imaginary part of input and output data */ + Word16 *x, /* i/o : real part of input and output data */ + Word16 *y /* i/o : imaginary part of input and output data */ ) { Word16 j; /* Applying 64-point FFT for 5 times based on the address table Idx_dortft160 */ - FOR(j=0; j<5; j++) + FOR( j = 0; j < 5; j++ ) { - fft64_16fx(x,y,Idx_dortft320+shl(j,6)/*64*j*/); + fft64_16fx( x, y, Idx_dortft320 + shl( j, 6 ) /*64*j*/ ); } /* Applying 5-point FFT for 64 times based on the address table Idx_dortft160 */ - FOR(j=0; j<64; j++) + FOR( j = 0; j < 64; j++ ) { - fft5_shift4_16fx(64,x,y,Idx_dortft320+j); + fft5_shift4_16fx( 64, x, y, Idx_dortft320 + j ); } return; } /*-----------------------------------------------------------------* -* DoRTFT128() -* FFT with 128 points -*-----------------------------------------------------------------*/ + * DoRTFT128() + * FFT with 128 points + *-----------------------------------------------------------------*/ void DoRTFT128_16fx( - Word16 *x, /* i/o : real part of input and output data Q(Qx+Q_edct)*/ - Word16 *y /* i/o : imaginary part of input and output data Q(Qx+Q_edct)*/ + Word16 *x, /* i/o : real part of input and output data Q(Qx+Q_edct)*/ + Word16 *y /* i/o : imaginary part of input and output data Q(Qx+Q_edct)*/ ) { Word16 i; Word16 z[256]; - move16();/*penalty for 1 ptr init */ - FOR ( i=0; i<128; i++ ) + move16(); /*penalty for 1 ptr init */ + FOR( i = 0; i < 128; i++ ) { - z[2*i] = x[i]; + z[2 * i] = x[i]; move16(); - z[2*i+1] = y[i]; + z[2 * i + 1] = y[i]; move16(); } - cdftForw_16fx(256,z,Ip_fft128,w_fft128_16fx); + cdftForw_16fx( 256, z, Ip_fft128, w_fft128_16fx ); - x[0]=z[0]; + x[0] = z[0]; move16(); - y[0]=z[1]; + y[0] = z[1]; move16(); - move16();/*penalty for 1 ptr init */ - move16();/*penalty for 1 ptr init */ - FOR( i=1; i<128 ; i++) + move16(); /*penalty for 1 ptr init */ + move16(); /*penalty for 1 ptr init */ + FOR( i = 1; i < 128; i++ ) { - x[128-i]=z[2*i]; + x[128 - i] = z[2 * i]; move16(); - y[128-i]=z[2*i+1]; + y[128 - i] = z[2 * i + 1]; move16(); } return; } /*-----------------------------------------------------------------* -* cdftForw() -* Main fuction of Complex Discrete Fourier Transform -*-----------------------------------------------------------------*/ + * cdftForw() + * Main fuction of Complex Discrete Fourier Transform + *-----------------------------------------------------------------*/ static void cdftForw_16fx( - Word16 n, /* i : data length of real and imag */ - Word16 *a, /* i/o : input/output data Q(Qx+Q_edct)*/ - const Word16 *ip, /* i : work area for bit reversal */ - const Word32 *w /* i : cos/sin table Q30*/ + Word16 n, /* i : data length of real and imag */ + Word16 *a, /* i/o : input/output data Q(Qx+Q_edct)*/ + const Word16 *ip, /* i : work area for bit reversal */ + const Word32 *w /* i : cos/sin table Q30*/ ) { /* bit reversal */ - bitrv2_SR_16fx(n, ip + 2, a); + bitrv2_SR_16fx( n, ip + 2, a ); /* Do FFT */ - cftfsub_16fx(n, a, w); + cftfsub_16fx( n, a, w ); } /*-----------------------------------------------------------------* -* bitrv2_SR() -* Bit reversal -*-----------------------------------------------------------------*/ + * bitrv2_SR() + * Bit reversal + *-----------------------------------------------------------------*/ static void bitrv2_SR_16fx( - Word16 n, /* i : data length of real and imag */ - const Word16 *ip, /* i/o : work area for bit reversal */ - Word16 *a /* i/o : input/output data Q(Qx+Q_edct)*/ + Word16 n, /* i : data length of real and imag */ + const Word16 *ip, /* i/o : work area for bit reversal */ + Word16 *a /* i/o : input/output data Q(Qx+Q_edct)*/ ) { Word16 j, j1, k, k1, m, m2; @@ -1646,21 +1668,21 @@ static void bitrv2_SR_16fx( m = 1; move16(); - WHILE (LT_16(shl(m,3),l)) + WHILE( LT_16( shl( m, 3 ), l ) ) { - l = shr(l,1); - m = shl(m,1); + l = shr( l, 1 ); + m = shl( m, 1 ); } - m2 = shl(m,1); - IF (EQ_16(shl(m, 3),l)) + m2 = shl( m, 1 ); + IF( EQ_16( shl( m, 3 ), l ) ) { - FOR (k = 0; k < m; k++) + FOR( k = 0; k < m; k++ ) { - FOR (j = 0; j < k; j++) + FOR( j = 0; j < k; j++ ) { - j1 = add(shl(j,1),ip[k]); - k1 = add(shl(k,1),ip[j]); + j1 = add( shl( j, 1 ), ip[k] ); + k1 = add( shl( k, 1 ), ip[j] ); xr = a[j1]; move16(); xi = a[j1 + 1]; @@ -1677,8 +1699,8 @@ static void bitrv2_SR_16fx( move16(); a[k1 + 1] = xi; move16(); - j1 = add(j1,m2); - k1 = add(k1,shl(m2,1)); + j1 = add( j1, m2 ); + k1 = add( k1, shl( m2, 1 ) ); xr = a[j1]; move16(); xi = a[j1 + 1]; @@ -1695,8 +1717,8 @@ static void bitrv2_SR_16fx( move16(); a[k1 + 1] = xi; move16(); - j1 = add(j1,m2); - k1 = sub(k1,m2); + j1 = add( j1, m2 ); + k1 = sub( k1, m2 ); xr = a[j1]; move16(); xi = a[j1 + 1]; @@ -1715,8 +1737,8 @@ static void bitrv2_SR_16fx( move16(); a[k1 + 1] = xi; move16(); - j1 = add(j1,m2); - k1 = add(k1,shl(m2,1)); + j1 = add( j1, m2 ); + k1 = add( k1, shl( m2, 1 ) ); xr = a[j1]; move16(); xi = a[j1 + 1]; @@ -1735,8 +1757,8 @@ static void bitrv2_SR_16fx( move16(); } - j1 = add(add(shl(k,1),m2),ip[k]); - k1 = add(j1,m2); + j1 = add( add( shl( k, 1 ), m2 ), ip[k] ); + k1 = add( j1, m2 ); xr = a[j1]; move16(); xi = a[j1 + 1]; @@ -1757,12 +1779,12 @@ static void bitrv2_SR_16fx( } ELSE { - FOR (k = 1; k < m; k++) + FOR( k = 1; k < m; k++ ) { - FOR (j = 0; j < k; j++) + FOR( j = 0; j < k; j++ ) { - j1 = add(shl(j,1),ip[k]); - k1 = add(shl(k,1),ip[j]); + j1 = add( shl( j, 1 ), ip[k] ); + k1 = add( shl( k, 1 ), ip[j] ); xr = a[j1]; move16(); xi = a[j1 + 1]; @@ -1779,8 +1801,8 @@ static void bitrv2_SR_16fx( move16(); a[k1 + 1] = xi; move16(); - j1 = add(j1,m2); - k1 = add(k1,m2); + j1 = add( j1, m2 ); + k1 = add( k1, m2 ); xr = a[j1]; move16(); xi = a[j1 + 1]; @@ -1805,13 +1827,13 @@ static void bitrv2_SR_16fx( } /*-----------------------------------------------------------------* -* cftfsub() -* Complex Discrete Fourier Transform -*-----------------------------------------------------------------*/ + * cftfsub() + * Complex Discrete Fourier Transform + *-----------------------------------------------------------------*/ static void cftfsub_16fx( - Word16 n, /* i : data length of real and imag */ - Word16 *a, /* i/o : input/output data Q(Qx+Q_edct)*/ - const Word32 *w /* i : cos/sin table Q30*/ + Word16 n, /* i : data length of real and imag */ + Word16 *a, /* i/o : input/output data Q(Qx+Q_edct)*/ + const Word32 *w /* i : cos/sin table Q30*/ ) { Word16 j, j1, j2, j3, l; @@ -1822,93 +1844,93 @@ static void cftfsub_16fx( l = 2; move16(); - IF (GT_16(n,8)) + IF( GT_16( n, 8 ) ) { - cft1st_16fx(n, a, w); + cft1st_16fx( n, a, w ); l = 8; move16(); - WHILE (LT_16(shl(l, 2),n)) + WHILE( LT_16( shl( l, 2 ), n ) ) { - cftmdl_16fx(n, l, a, w); - l = shl(l,2); + cftmdl_16fx( n, l, a, w ); + l = shl( l, 2 ); } } - IF (EQ_16(shl(l,2),n)) + IF( EQ_16( shl( l, 2 ), n ) ) { - FOR (j = 0; j < l; j += 2) + FOR( j = 0; j < l; j += 2 ) { - j1 = add(j,l); - j2 = add(j1,l); - j3 = add(j2,l); - x0r = add(a[j],a[j1]); - x0i = add(a[j + 1],a[j1 + 1]); - x1r = sub(a[j],a[j1]); - x1i = sub(a[j + 1],a[j1 + 1]); - x2r = add(a[j2],a[j3]); - x2i = add(a[j2 + 1],a[j3 + 1]); - x3r = sub(a[j2],a[j3]); - x3i = sub(a[j2 + 1],a[j3 + 1]); - a[j] = add(x0r,x2r); + j1 = add( j, l ); + j2 = add( j1, l ); + j3 = add( j2, l ); + x0r = add( a[j], a[j1] ); + x0i = add( a[j + 1], a[j1 + 1] ); + x1r = sub( a[j], a[j1] ); + x1i = sub( a[j + 1], a[j1 + 1] ); + x2r = add( a[j2], a[j3] ); + x2i = add( a[j2 + 1], a[j3 + 1] ); + x3r = sub( a[j2], a[j3] ); + x3i = sub( a[j2 + 1], a[j3 + 1] ); + a[j] = add( x0r, x2r ); move16(); - a[j + 1] = add(x0i,x2i); + a[j + 1] = add( x0i, x2i ); move16(); - a[j2] = sub(x0r,x2r); + a[j2] = sub( x0r, x2r ); move16(); - a[j2 + 1] = sub(x0i,x2i); + a[j2 + 1] = sub( x0i, x2i ); move16(); - a[j1] = sub(x1r,x3i); + a[j1] = sub( x1r, x3i ); move16(); - a[j1 + 1] = add(x1i,x3r); + a[j1 + 1] = add( x1i, x3r ); move16(); - a[j3] = add(x1r,x3i); + a[j3] = add( x1r, x3i ); move16(); - a[j3 + 1] = sub(x1i,x3r); + a[j3 + 1] = sub( x1i, x3r ); move16(); } } ELSE { - FOR (j = 0; j < l; j += 2) + FOR( j = 0; j < l; j += 2 ) { #ifdef BASOP_NOGLOB - j1 = add_o(j,l, &Overflow); - x0r = sub_o(a[j],a[j1], &Overflow); - x0i = sub_o(a[j + 1],a[j1 + 1], &Overflow); - a[j] = add_o(a[j],a[j1], &Overflow); + j1 = add_o( j, l, &Overflow ); + x0r = sub_o( a[j], a[j1], &Overflow ); + x0i = sub_o( a[j + 1], a[j1 + 1], &Overflow ); + a[j] = add_o( a[j], a[j1], &Overflow ); move16(); - a[j + 1] = add_o(a[j + 1],a[j1 + 1], &Overflow); + a[j + 1] = add_o( a[j + 1], a[j1 + 1], &Overflow ); move16(); a[j1] = x0r; move16(); a[j1 + 1] = x0i; move16(); -#else - j1 = add(j,l); - x0r = sub(a[j],a[j1]); - x0i = sub(a[j + 1],a[j1 + 1]); - a[j] = add(a[j],a[j1]); +#else + j1 = add( j, l ); + x0r = sub( a[j], a[j1] ); + x0i = sub( a[j + 1], a[j1 + 1] ); + a[j] = add( a[j], a[j1] ); move16(); - a[j + 1] = add(a[j + 1],a[j1 + 1]); + a[j + 1] = add( a[j + 1], a[j1 + 1] ); move16(); a[j1] = x0r; move16(); a[j1 + 1] = x0i; move16(); -#endif +#endif } } return; } /*-----------------------------------------------------------------* -* cft1st() -* Subfunction of Complex Discrete Fourier Transform -*-----------------------------------------------------------------*/ + * cft1st() + * Subfunction of Complex Discrete Fourier Transform + *-----------------------------------------------------------------*/ static void cft1st_16fx( - Word16 n, /* i : data length of real and imag */ - Word16 *a, /* i/o : input/output data Q(Qx+Q_edct)*/ - const Word32 *w /* i : cos/sin table Q30*/ + Word16 n, /* i : data length of real and imag */ + Word16 *a, /* i/o : input/output data Q(Qx+Q_edct)*/ + const Word32 *w /* i : cos/sin table Q30*/ ) { Word16 j, k1, k2; @@ -1921,348 +1943,356 @@ static void cft1st_16fx( #endif #ifdef BASOP_NOGLOB - x0r = add_o(a[0],a[2], &Overflow); - x0i = add_o(a[1],a[3], &Overflow); - x1r = sub_o(a[0],a[2], &Overflow); - x1i = sub_o(a[1],a[3], &Overflow); - x2r = add_o(a[4],a[6], &Overflow); - x2i = add_o(a[5],a[7], &Overflow); - x3r = sub_o(a[4],a[6], &Overflow); - x3i = sub_o(a[5],a[7], &Overflow); - a[0] = add_o(x0r,x2r, &Overflow); + x0r = add_o( a[0], a[2], &Overflow ); + x0i = add_o( a[1], a[3], &Overflow ); + x1r = sub_o( a[0], a[2], &Overflow ); + x1i = sub_o( a[1], a[3], &Overflow ); + x2r = add_o( a[4], a[6], &Overflow ); + x2i = add_o( a[5], a[7], &Overflow ); + x3r = sub_o( a[4], a[6], &Overflow ); + x3i = sub_o( a[5], a[7], &Overflow ); + a[0] = add_o( x0r, x2r, &Overflow ); move16(); - a[1] = add_o(x0i,x2i, &Overflow); + a[1] = add_o( x0i, x2i, &Overflow ); move16(); - a[4] = sub_o(x0r,x2r, &Overflow); + a[4] = sub_o( x0r, x2r, &Overflow ); move16(); - a[5] = sub_o(x0i,x2i, &Overflow); + a[5] = sub_o( x0i, x2i, &Overflow ); move16(); - a[2] = sub_o(x1r,x3i, &Overflow); + a[2] = sub_o( x1r, x3i, &Overflow ); move16(); - a[3] = add_o(x1i,x3r, &Overflow); + a[3] = add_o( x1i, x3r, &Overflow ); move16(); - a[6] = add_o(x1r,x3i, &Overflow); + a[6] = add_o( x1r, x3i, &Overflow ); move16(); - a[7] = sub_o(x1i,x3r, &Overflow); + a[7] = sub_o( x1i, x3r, &Overflow ); #else - x0r = add(a[0],a[2]); - x0i = add(a[1],a[3]); - x1r = sub(a[0],a[2]); - x1i = sub(a[1],a[3]); - x2r = add(a[4],a[6]); - x2i = add(a[5],a[7]); - x3r = sub(a[4],a[6]); - x3i = sub(a[5],a[7]); - a[0] = add(x0r,x2r); + x0r = add( a[0], a[2] ); + x0i = add( a[1], a[3] ); + x1r = sub( a[0], a[2] ); + x1i = sub( a[1], a[3] ); + x2r = add( a[4], a[6] ); + x2i = add( a[5], a[7] ); + x3r = sub( a[4], a[6] ); + x3i = sub( a[5], a[7] ); + a[0] = add( x0r, x2r ); move16(); - a[1] = add(x0i,x2i); + a[1] = add( x0i, x2i ); move16(); - a[4] = sub(x0r,x2r); + a[4] = sub( x0r, x2r ); move16(); - a[5] = sub(x0i,x2i); + a[5] = sub( x0i, x2i ); move16(); - a[2] = sub(x1r,x3i); + a[2] = sub( x1r, x3i ); move16(); - a[3] = add(x1i,x3r); + a[3] = add( x1i, x3r ); move16(); - a[6] = add(x1r,x3i); + a[6] = add( x1r, x3i ); move16(); - a[7] = sub(x1i,x3r); + a[7] = sub( x1i, x3r ); move16(); #endif wk1r = w[2]; move32(); #ifdef BASOP_NOGLOB - x0r = add_o(a[8],a[10], &Overflow); - x0i = add_o(a[9],a[11], &Overflow); - x1r = sub_o(a[8],a[10], &Overflow); - x1i = sub_o(a[9],a[11], &Overflow); - x2r = add_o(a[12],a[14], &Overflow); - x2i = add_o(a[13],a[15], &Overflow); - x3r = sub_o(a[12],a[14], &Overflow); - x3i = sub_o(a[13],a[15], &Overflow); - a[8] = add_o(x0r,x2r, &Overflow); + x0r = add_o( a[8], a[10], &Overflow ); + x0i = add_o( a[9], a[11], &Overflow ); + x1r = sub_o( a[8], a[10], &Overflow ); + x1i = sub_o( a[9], a[11], &Overflow ); + x2r = add_o( a[12], a[14], &Overflow ); + x2i = add_o( a[13], a[15], &Overflow ); + x3r = sub_o( a[12], a[14], &Overflow ); + x3i = sub_o( a[13], a[15], &Overflow ); + a[8] = add_o( x0r, x2r, &Overflow ); move16(); - a[9] = add_o(x0i,x2i, &Overflow); + a[9] = add_o( x0i, x2i, &Overflow ); move16(); - a[12] = sub_o(x2i,x0i, &Overflow); + a[12] = sub_o( x2i, x0i, &Overflow ); move16(); - a[13] = sub_o(x0r,x2r, &Overflow); + a[13] = sub_o( x0r, x2r, &Overflow ); move16(); - x0r = sub_o(x1r,x3i, &Overflow); - x0i = add_o(x1i,x3r, &Overflow); - tmp = sub_o(x0r,x0i, &Overflow); + x0r = sub_o( x1r, x3i, &Overflow ); + x0i = add_o( x1i, x3r, &Overflow ); + tmp = sub_o( x0r, x0i, &Overflow ); #else - x0r = add(a[8],a[10]); - x0i = add(a[9],a[11]); - x1r = sub(a[8],a[10]); - x1i = sub(a[9],a[11]); - x2r = add(a[12],a[14]); - x2i = add(a[13],a[15]); - x3r = sub(a[12],a[14]); - x3i = sub(a[13],a[15]); - a[8] = add(x0r,x2r); + x0r = add( a[8], a[10] ); + x0i = add( a[9], a[11] ); + x1r = sub( a[8], a[10] ); + x1i = sub( a[9], a[11] ); + x2r = add( a[12], a[14] ); + x2i = add( a[13], a[15] ); + x3r = sub( a[12], a[14] ); + x3i = sub( a[13], a[15] ); + a[8] = add( x0r, x2r ); move16(); - a[9] = add(x0i,x2i); + a[9] = add( x0i, x2i ); move16(); - a[12] = sub(x2i,x0i); + a[12] = sub( x2i, x0i ); move16(); - a[13] = sub(x0r,x2r); + a[13] = sub( x0r, x2r ); move16(); - x0r = sub(x1r,x3i); - x0i = add(x1i,x3r); - tmp = sub(x0r,x0i); + x0r = sub( x1r, x3i ); + x0i = add( x1i, x3r ); + tmp = sub( x0r, x0i ); #endif - L_tmp = Mult_32_16(wk1r,tmp); /*Q(15+Qx+Q_edct) */ + L_tmp = Mult_32_16( wk1r, tmp ); /*Q(15+Qx+Q_edct) */ #ifdef BASOP_NOGLOB - a[10] = round_fx_o(L_shl_o(L_tmp,1, &Overflow), &Overflow); /*Q(Qx+Q_edct) */ + a[10] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ - tmp = add_o(x0r,x0i, &Overflow); - L_tmp = Mult_32_16(wk1r,tmp); /*Q(15+Qx+Q_edct) */ - a[11] = round_fx_o(L_shl_o(L_tmp,1, &Overflow), &Overflow); /* Q(Qx+Q_edct) */ + tmp = add_o( x0r, x0i, &Overflow ); + L_tmp = Mult_32_16( wk1r, tmp ); /*Q(15+Qx+Q_edct) */ + a[11] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /* Q(Qx+Q_edct) */ - x0r = add_o(x3i,x1r, &Overflow); - x0i = sub_o(x3r,x1i, &Overflow); - tmp = sub_o(x0i,x0r, &Overflow); - L_tmp = Mult_32_16(wk1r,tmp); /*Q(15+Qx+Q_edct) */ - a[14] = round_fx_o(L_shl_o(L_tmp,1, &Overflow), &Overflow); /*Q(Qx+Q_edct) */ + x0r = add_o( x3i, x1r, &Overflow ); + x0i = sub_o( x3r, x1i, &Overflow ); + tmp = sub_o( x0i, x0r, &Overflow ); + L_tmp = Mult_32_16( wk1r, tmp ); /*Q(15+Qx+Q_edct) */ + a[14] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ - tmp = add_o(x0i,x0r, &Overflow); - L_tmp = Mult_32_16(wk1r,tmp); /*Q(15+Qx+Q_edct) */ - a[15] = round_fx_o(L_shl_o(L_tmp,1, &Overflow), &Overflow); /*Q(Qx+Q_edct) */ + tmp = add_o( x0i, x0r, &Overflow ); + L_tmp = Mult_32_16( wk1r, tmp ); /*Q(15+Qx+Q_edct) */ + a[15] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ #else - a[10] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ + a[10] = round_fx( L_shl( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ - tmp = add(x0r,x0i); - L_tmp = Mult_32_16(wk1r,tmp); /*Q(15+Qx+Q_edct) */ - a[11] = round_fx(L_shl(L_tmp,1)); /* Q(Qx+Q_edct) */ + tmp = add( x0r, x0i ); + L_tmp = Mult_32_16( wk1r, tmp ); /*Q(15+Qx+Q_edct) */ + a[11] = round_fx( L_shl( L_tmp, 1 ) ); /* Q(Qx+Q_edct) */ - x0r = add(x3i,x1r); - x0i = sub(x3r,x1i); - tmp = sub(x0i,x0r); - L_tmp = Mult_32_16(wk1r,tmp); /*Q(15+Qx+Q_edct) */ - a[14] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ + x0r = add( x3i, x1r ); + x0i = sub( x3r, x1i ); + tmp = sub( x0i, x0r ); + L_tmp = Mult_32_16( wk1r, tmp ); /*Q(15+Qx+Q_edct) */ + a[14] = round_fx( L_shl( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ - tmp = add(x0i,x0r); - L_tmp = Mult_32_16(wk1r,tmp); /*Q(15+Qx+Q_edct) */ - a[15] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ + tmp = add( x0i, x0r ); + L_tmp = Mult_32_16( wk1r, tmp ); /*Q(15+Qx+Q_edct) */ + a[15] = round_fx( L_shl( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ #endif k1 = 0; move16(); - FOR (j = 16; j < n; j += 16) + FOR( j = 16; j < n; j += 16 ) { - k1 = add(k1,2); - k2 = shl(k1,1); + k1 = add( k1, 2 ); + k2 = shl( k1, 1 ); - wk2r = w[k1]; move32(); - wk2i = w[k1 + 1]; move32(); - wk1r = w[k2]; move32(); - wk1i = w[k2 + 1]; move32(); + wk2r = w[k1]; + move32(); + wk2i = w[k1 + 1]; + move32(); + wk1r = w[k2]; + move32(); + wk1i = w[k2 + 1]; + move32(); - L_tmp = L_shl(Mult_32_32(wk2i,wk1i),1);/*Q29 */ - wk3r = L_sub(wk1r,L_shl(L_tmp,1));/*Q30 */ + L_tmp = L_shl( Mult_32_32( wk2i, wk1i ), 1 ); /*Q29 */ + wk3r = L_sub( wk1r, L_shl( L_tmp, 1 ) ); /*Q30 */ - L_tmp = L_shl(Mult_32_32(wk2i,wk1r),1);/*Q29 */ - wk3i = L_sub(L_shl(L_tmp,1),wk1i);/*Q30 */ + L_tmp = L_shl( Mult_32_32( wk2i, wk1r ), 1 ); /*Q29 */ + wk3i = L_sub( L_shl( L_tmp, 1 ), wk1i ); /*Q30 */ #ifdef BASOP_NOGLOB - x0r = add_o(a[j], a[j + 2], &Overflow); - x0i = add_o(a[j + 1], a[j + 3], &Overflow); - x1r = sub_o(a[j], a[j + 2], &Overflow); - x1i = sub_o(a[j + 1], a[j + 3], &Overflow); - x2r = add_o(a[j + 4], a[j + 6], &Overflow); - x2i = add_o(a[j + 5], a[j + 7], &Overflow); - x3r = sub_o(a[j + 4], a[j + 6], &Overflow); - x3i = sub_o(a[j + 5], a[j + 7], &Overflow); - a[j] = add_o(x0r, x2r, &Overflow); - move16(); - a[j + 1] = add_o(x0i, x2i, &Overflow); - move16(); - - x0r = sub_o(x0r, x2r, &Overflow); - x0i = sub_o(x0i, x2i, &Overflow); - L_tmp = Mult_32_16(wk2r, x0r);/*Q(15+Qx+Q_edct) */ - L_tmp = Msub_32_16(L_tmp, wk2i, x0i); /*Q(15+Qx+Q_edct) */ - a[j + 4] = round_fx_o(L_shl_o(L_tmp, 1, &Overflow), &Overflow); /*Q(Qx+Q_edct) */ - - L_tmp = Mult_32_16(wk2r, x0i);/*Q(15+Qx+Q_edct) */ - L_tmp = Madd_32_16(L_tmp, wk2i, x0r); /*Q(15+Qx+Q_edct) */ - a[j + 5] = round_fx_o(L_shl_o(L_tmp, 1, &Overflow), &Overflow); /*Q(Qx+Q_edct) */ - - x0r = sub_o(x1r, x3i, &Overflow); - x0i = add_o(x1i, x3r, &Overflow); - L_tmp = Mult_32_16(wk1r, x0r);/*Q(15+Qx+Q_edct) */ - L_tmp = Msub_32_16(L_tmp, wk1i, x0i); /*Q(15+Qx+Q_edct) */ - a[j + 2] = round_fx_o(L_shl_o(L_tmp, 1, &Overflow), &Overflow); /*Q(Qx+Q_edct) */ - - L_tmp = Mult_32_16(wk1r, x0i);/*Q(15+Qx+Q_edct) */ - L_tmp = Madd_32_16(L_tmp, wk1i, x0r); /*Q(15+Qx+Q_edct) */ - a[j + 3] = round_fx_o(L_shl_o(L_tmp, 1, &Overflow), &Overflow); /*Q(Qx+Q_edct) */ - - x0r = add_o(x1r, x3i, &Overflow); - x0i = sub_o(x1i, x3r, &Overflow); - L_tmp = Mult_32_16(wk3r, x0r); /*Q(15+Qx+Q_edct) */ - L_tmp = Msub_32_16(L_tmp, wk3i, x0i); /*Q(15+Qx+Q_edct) */ - a[j + 6] = round_fx_o(L_shl_o(L_tmp, 1, &Overflow), &Overflow); /*Q(Qx+Q_edct) */ - - L_tmp = Mult_32_16(wk3r, x0i); /*Q(15+Qx+Q_edct) */ - L_tmp = Madd_32_16(L_tmp, wk3i, x0r); /*Q(15+Qx+Q_edct) */ - a[j + 7] = round_fx_o(L_shl_o(L_tmp, 1, &Overflow), &Overflow); /*Q(Qx+Q_edct) */ - - wk1r = w[k2 + 2]; move32(); - wk1i = w[k2 + 3]; move32(); - L_tmp = L_shl(Mult_32_32(wk2r, wk1i), 1);/*Q29 */ - wk3r = L_sub(wk1r, L_shl(L_tmp, 1)); /*Q30 */ - - L_tmp = L_shl(Mult_32_32(wk2r, wk1r), 1);/*Q29 */ - wk3i = L_sub(L_shl(L_tmp, 1), wk1i); /*Q30 */ - - x0r = add_o(a[j + 8], a[j + 10], &Overflow); - x0i = add_o(a[j + 9], a[j + 11], &Overflow); - x1r = sub_o(a[j + 8], a[j + 10], &Overflow); - x1i = sub_o(a[j + 9], a[j + 11], &Overflow); - x2r = add_o(a[j + 12], a[j + 14], &Overflow); - x2i = add_o(a[j + 13], a[j + 15], &Overflow); - x3r = sub_o(a[j + 12], a[j + 14], &Overflow); - x3i = sub_o(a[j + 13], a[j + 15], &Overflow); - a[j + 8] = add_o(x0r, x2r, &Overflow); - move16(); - a[j + 9] = add_o(x0i, x2i, &Overflow); - move16(); - - x0r = sub_o(x0r, x2r, &Overflow); - x0i = sub_o(x0i, x2i, &Overflow); - tmp = negate(x0r); - L_tmp = Mult_32_16(wk2i, tmp);/*Q(15+Qx+Q_edct) */ - L_tmp = Msub_32_16(L_tmp, wk2r, x0i); /*Q(15+Qx+Q_edct) */ - a[j + 12] = round_fx_o(L_shl_o(L_tmp, 1, &Overflow), &Overflow); /*Q(Qx+Q_edct) */ - - tmp = negate(x0i); - L_tmp = Mult_32_16(wk2i, tmp);/*Q(15+Qx+Q_edct) */ - L_tmp = Madd_32_16(L_tmp, wk2r, x0r); /*Q(15+Qx+Q_edct) */ - a[j + 13] = round_fx_o(L_shl_o(L_tmp, 1, &Overflow), &Overflow); /*Q(Qx+Q_edct) */ - - x0r = sub_o(x1r, x3i, &Overflow); - x0i = add_o(x1i, x3r, &Overflow); - L_tmp = Mult_32_16(wk1r, x0r);/*Q(15+Qx+Q_edct) */ - L_tmp = Msub_32_16(L_tmp, wk1i, x0i); /*Q(15+Qx+Q_edct) */ - a[j + 10] = round_fx_o(L_shl_o(L_tmp, 1, &Overflow), &Overflow); /*Q(Qx+Q_edct) */ - - L_tmp = Mult_32_16(wk1r, x0i);/*Q(15+Qx+Q_edct) */ - L_tmp = Madd_32_16(L_tmp, wk1i, x0r); /*Q(15+Qx+Q_edct) */ - a[j + 11] = round_fx_o(L_shl_o(L_tmp, 1, &Overflow), &Overflow); /*Q(Qx+Q_edct) */ - - x0r = add_o(x1r, x3i, &Overflow); - x0i = sub_o(x1i, x3r, &Overflow); - - L_tmp = Mult_32_16(wk3r, x0r); /*Q(15+Qx+Q_edct) */ - L_tmp = Msub_32_16(L_tmp, wk3i, x0i); /*Q(15+Qx+Q_edct) */ - a[j + 14] = round_fx_o(L_shl_o(L_tmp, 1, &Overflow), &Overflow); /*Q(Qx+Q_edct) */ - - L_tmp = Mult_32_16(wk3r, x0i); /*Q(15+Qx+Q_edct) */ - L_tmp = Madd_32_16(L_tmp, wk3i, x0r); /*Q(15+Qx+Q_edct) */ - a[j + 15] = round_fx_o(L_shl_o(L_tmp, 1, &Overflow), &Overflow); /*Q(Qx+Q_edct) */ + x0r = add_o( a[j], a[j + 2], &Overflow ); + x0i = add_o( a[j + 1], a[j + 3], &Overflow ); + x1r = sub_o( a[j], a[j + 2], &Overflow ); + x1i = sub_o( a[j + 1], a[j + 3], &Overflow ); + x2r = add_o( a[j + 4], a[j + 6], &Overflow ); + x2i = add_o( a[j + 5], a[j + 7], &Overflow ); + x3r = sub_o( a[j + 4], a[j + 6], &Overflow ); + x3i = sub_o( a[j + 5], a[j + 7], &Overflow ); + a[j] = add_o( x0r, x2r, &Overflow ); + move16(); + a[j + 1] = add_o( x0i, x2i, &Overflow ); + move16(); + + x0r = sub_o( x0r, x2r, &Overflow ); + x0i = sub_o( x0i, x2i, &Overflow ); + L_tmp = Mult_32_16( wk2r, x0r ); /*Q(15+Qx+Q_edct) */ + L_tmp = Msub_32_16( L_tmp, wk2i, x0i ); /*Q(15+Qx+Q_edct) */ + a[j + 4] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + + L_tmp = Mult_32_16( wk2r, x0i ); /*Q(15+Qx+Q_edct) */ + L_tmp = Madd_32_16( L_tmp, wk2i, x0r ); /*Q(15+Qx+Q_edct) */ + a[j + 5] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + + x0r = sub_o( x1r, x3i, &Overflow ); + x0i = add_o( x1i, x3r, &Overflow ); + L_tmp = Mult_32_16( wk1r, x0r ); /*Q(15+Qx+Q_edct) */ + L_tmp = Msub_32_16( L_tmp, wk1i, x0i ); /*Q(15+Qx+Q_edct) */ + a[j + 2] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + + L_tmp = Mult_32_16( wk1r, x0i ); /*Q(15+Qx+Q_edct) */ + L_tmp = Madd_32_16( L_tmp, wk1i, x0r ); /*Q(15+Qx+Q_edct) */ + a[j + 3] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + + x0r = add_o( x1r, x3i, &Overflow ); + x0i = sub_o( x1i, x3r, &Overflow ); + L_tmp = Mult_32_16( wk3r, x0r ); /*Q(15+Qx+Q_edct) */ + L_tmp = Msub_32_16( L_tmp, wk3i, x0i ); /*Q(15+Qx+Q_edct) */ + a[j + 6] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + + L_tmp = Mult_32_16( wk3r, x0i ); /*Q(15+Qx+Q_edct) */ + L_tmp = Madd_32_16( L_tmp, wk3i, x0r ); /*Q(15+Qx+Q_edct) */ + a[j + 7] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + + wk1r = w[k2 + 2]; + move32(); + wk1i = w[k2 + 3]; + move32(); + L_tmp = L_shl( Mult_32_32( wk2r, wk1i ), 1 ); /*Q29 */ + wk3r = L_sub( wk1r, L_shl( L_tmp, 1 ) ); /*Q30 */ + + L_tmp = L_shl( Mult_32_32( wk2r, wk1r ), 1 ); /*Q29 */ + wk3i = L_sub( L_shl( L_tmp, 1 ), wk1i ); /*Q30 */ + + x0r = add_o( a[j + 8], a[j + 10], &Overflow ); + x0i = add_o( a[j + 9], a[j + 11], &Overflow ); + x1r = sub_o( a[j + 8], a[j + 10], &Overflow ); + x1i = sub_o( a[j + 9], a[j + 11], &Overflow ); + x2r = add_o( a[j + 12], a[j + 14], &Overflow ); + x2i = add_o( a[j + 13], a[j + 15], &Overflow ); + x3r = sub_o( a[j + 12], a[j + 14], &Overflow ); + x3i = sub_o( a[j + 13], a[j + 15], &Overflow ); + a[j + 8] = add_o( x0r, x2r, &Overflow ); + move16(); + a[j + 9] = add_o( x0i, x2i, &Overflow ); + move16(); + + x0r = sub_o( x0r, x2r, &Overflow ); + x0i = sub_o( x0i, x2i, &Overflow ); + tmp = negate( x0r ); + L_tmp = Mult_32_16( wk2i, tmp ); /*Q(15+Qx+Q_edct) */ + L_tmp = Msub_32_16( L_tmp, wk2r, x0i ); /*Q(15+Qx+Q_edct) */ + a[j + 12] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + + tmp = negate( x0i ); + L_tmp = Mult_32_16( wk2i, tmp ); /*Q(15+Qx+Q_edct) */ + L_tmp = Madd_32_16( L_tmp, wk2r, x0r ); /*Q(15+Qx+Q_edct) */ + a[j + 13] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + + x0r = sub_o( x1r, x3i, &Overflow ); + x0i = add_o( x1i, x3r, &Overflow ); + L_tmp = Mult_32_16( wk1r, x0r ); /*Q(15+Qx+Q_edct) */ + L_tmp = Msub_32_16( L_tmp, wk1i, x0i ); /*Q(15+Qx+Q_edct) */ + a[j + 10] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + + L_tmp = Mult_32_16( wk1r, x0i ); /*Q(15+Qx+Q_edct) */ + L_tmp = Madd_32_16( L_tmp, wk1i, x0r ); /*Q(15+Qx+Q_edct) */ + a[j + 11] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + + x0r = add_o( x1r, x3i, &Overflow ); + x0i = sub_o( x1i, x3r, &Overflow ); + + L_tmp = Mult_32_16( wk3r, x0r ); /*Q(15+Qx+Q_edct) */ + L_tmp = Msub_32_16( L_tmp, wk3i, x0i ); /*Q(15+Qx+Q_edct) */ + a[j + 14] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + + L_tmp = Mult_32_16( wk3r, x0i ); /*Q(15+Qx+Q_edct) */ + L_tmp = Madd_32_16( L_tmp, wk3i, x0r ); /*Q(15+Qx+Q_edct) */ + a[j + 15] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ #else - x0r = add(a[j],a[j + 2]); - x0i = add(a[j + 1],a[j + 3]); - x1r = sub(a[j],a[j + 2]); - x1i = sub(a[j + 1],a[j + 3]); - x2r = add(a[j + 4],a[j + 6]); - x2i = add(a[j + 5],a[j + 7]); - x3r = sub(a[j + 4],a[j + 6]); - x3i = sub(a[j + 5],a[j + 7]); - a[j] = add(x0r,x2r); - move16(); - a[j + 1] = add(x0i,x2i); - move16(); - - x0r = sub(x0r,x2r); - x0i = sub(x0i,x2i); - L_tmp = Mult_32_16(wk2r,x0r);/*Q(15+Qx+Q_edct) */ - L_tmp = Msub_32_16(L_tmp,wk2i,x0i); /*Q(15+Qx+Q_edct) */ - a[j + 4] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ - - L_tmp = Mult_32_16(wk2r,x0i);/*Q(15+Qx+Q_edct) */ - L_tmp = Madd_32_16(L_tmp,wk2i,x0r); /*Q(15+Qx+Q_edct) */ - a[j + 5] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ - - x0r = sub(x1r,x3i); - x0i = add(x1i,x3r); - L_tmp = Mult_32_16(wk1r,x0r);/*Q(15+Qx+Q_edct) */ - L_tmp = Msub_32_16(L_tmp,wk1i,x0i); /*Q(15+Qx+Q_edct) */ - a[j + 2] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ - - L_tmp = Mult_32_16(wk1r,x0i);/*Q(15+Qx+Q_edct) */ - L_tmp = Madd_32_16(L_tmp,wk1i,x0r); /*Q(15+Qx+Q_edct) */ - a[j + 3] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ - - x0r = add(x1r,x3i); - x0i = sub(x1i,x3r); - L_tmp = Mult_32_16(wk3r,x0r); /*Q(15+Qx+Q_edct) */ - L_tmp = Msub_32_16(L_tmp,wk3i,x0i); /*Q(15+Qx+Q_edct) */ - a[j + 6] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ - - L_tmp = Mult_32_16(wk3r,x0i); /*Q(15+Qx+Q_edct) */ - L_tmp = Madd_32_16(L_tmp,wk3i,x0r); /*Q(15+Qx+Q_edct) */ - a[j + 7] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ - - wk1r = w[k2 + 2]; move32(); - wk1i = w[k2 + 3]; move32(); - L_tmp = L_shl(Mult_32_32(wk2r,wk1i),1);/*Q29 */ - wk3r = L_sub(wk1r,L_shl(L_tmp,1)); /*Q30 */ - - L_tmp = L_shl(Mult_32_32(wk2r,wk1r),1);/*Q29 */ - wk3i = L_sub(L_shl(L_tmp,1),wk1i); /*Q30 */ - - x0r = add(a[j + 8],a[j + 10]); - x0i = add(a[j + 9],a[j + 11]); - x1r = sub(a[j + 8],a[j + 10]); - x1i = sub(a[j + 9],a[j + 11]); - x2r = add(a[j + 12],a[j + 14]); - x2i = add(a[j + 13],a[j + 15]); - x3r = sub(a[j + 12],a[j + 14]); - x3i = sub(a[j + 13],a[j + 15]); - a[j + 8] = add(x0r,x2r); - move16(); - a[j + 9] = add(x0i,x2i); - move16(); - - x0r = sub(x0r,x2r); - x0i = sub(x0i,x2i); - tmp = negate(x0r); - L_tmp = Mult_32_16(wk2i,tmp);/*Q(15+Qx+Q_edct) */ - L_tmp = Msub_32_16(L_tmp,wk2r,x0i); /*Q(15+Qx+Q_edct) */ - a[j + 12] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ - - tmp = negate(x0i); - L_tmp = Mult_32_16(wk2i,tmp);/*Q(15+Qx+Q_edct) */ - L_tmp = Madd_32_16(L_tmp,wk2r,x0r); /*Q(15+Qx+Q_edct) */ - a[j + 13] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ - - x0r = sub(x1r,x3i); - x0i = add(x1i,x3r); - L_tmp = Mult_32_16(wk1r,x0r);/*Q(15+Qx+Q_edct) */ - L_tmp = Msub_32_16(L_tmp,wk1i,x0i); /*Q(15+Qx+Q_edct) */ - a[j + 10] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ - - L_tmp = Mult_32_16(wk1r,x0i);/*Q(15+Qx+Q_edct) */ - L_tmp = Madd_32_16(L_tmp,wk1i,x0r); /*Q(15+Qx+Q_edct) */ - a[j + 11] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ - - x0r = add(x1r,x3i); - x0i = sub(x1i,x3r); - - L_tmp = Mult_32_16(wk3r,x0r); /*Q(15+Qx+Q_edct) */ - L_tmp = Msub_32_16(L_tmp,wk3i,x0i); /*Q(15+Qx+Q_edct) */ - a[j + 14] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ - - L_tmp = Mult_32_16(wk3r,x0i); /*Q(15+Qx+Q_edct) */ - L_tmp = Madd_32_16(L_tmp,wk3i,x0r); /*Q(15+Qx+Q_edct) */ - a[j + 15] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ + x0r = add( a[j], a[j + 2] ); + x0i = add( a[j + 1], a[j + 3] ); + x1r = sub( a[j], a[j + 2] ); + x1i = sub( a[j + 1], a[j + 3] ); + x2r = add( a[j + 4], a[j + 6] ); + x2i = add( a[j + 5], a[j + 7] ); + x3r = sub( a[j + 4], a[j + 6] ); + x3i = sub( a[j + 5], a[j + 7] ); + a[j] = add( x0r, x2r ); + move16(); + a[j + 1] = add( x0i, x2i ); + move16(); + + x0r = sub( x0r, x2r ); + x0i = sub( x0i, x2i ); + L_tmp = Mult_32_16( wk2r, x0r ); /*Q(15+Qx+Q_edct) */ + L_tmp = Msub_32_16( L_tmp, wk2i, x0i ); /*Q(15+Qx+Q_edct) */ + a[j + 4] = round_fx( L_shl( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ + + L_tmp = Mult_32_16( wk2r, x0i ); /*Q(15+Qx+Q_edct) */ + L_tmp = Madd_32_16( L_tmp, wk2i, x0r ); /*Q(15+Qx+Q_edct) */ + a[j + 5] = round_fx( L_shl( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ + + x0r = sub( x1r, x3i ); + x0i = add( x1i, x3r ); + L_tmp = Mult_32_16( wk1r, x0r ); /*Q(15+Qx+Q_edct) */ + L_tmp = Msub_32_16( L_tmp, wk1i, x0i ); /*Q(15+Qx+Q_edct) */ + a[j + 2] = round_fx( L_shl( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ + + L_tmp = Mult_32_16( wk1r, x0i ); /*Q(15+Qx+Q_edct) */ + L_tmp = Madd_32_16( L_tmp, wk1i, x0r ); /*Q(15+Qx+Q_edct) */ + a[j + 3] = round_fx( L_shl( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ + + x0r = add( x1r, x3i ); + x0i = sub( x1i, x3r ); + L_tmp = Mult_32_16( wk3r, x0r ); /*Q(15+Qx+Q_edct) */ + L_tmp = Msub_32_16( L_tmp, wk3i, x0i ); /*Q(15+Qx+Q_edct) */ + a[j + 6] = round_fx( L_shl( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ + + L_tmp = Mult_32_16( wk3r, x0i ); /*Q(15+Qx+Q_edct) */ + L_tmp = Madd_32_16( L_tmp, wk3i, x0r ); /*Q(15+Qx+Q_edct) */ + a[j + 7] = round_fx( L_shl( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ + + wk1r = w[k2 + 2]; + move32(); + wk1i = w[k2 + 3]; + move32(); + L_tmp = L_shl( Mult_32_32( wk2r, wk1i ), 1 ); /*Q29 */ + wk3r = L_sub( wk1r, L_shl( L_tmp, 1 ) ); /*Q30 */ + + L_tmp = L_shl( Mult_32_32( wk2r, wk1r ), 1 ); /*Q29 */ + wk3i = L_sub( L_shl( L_tmp, 1 ), wk1i ); /*Q30 */ + + x0r = add( a[j + 8], a[j + 10] ); + x0i = add( a[j + 9], a[j + 11] ); + x1r = sub( a[j + 8], a[j + 10] ); + x1i = sub( a[j + 9], a[j + 11] ); + x2r = add( a[j + 12], a[j + 14] ); + x2i = add( a[j + 13], a[j + 15] ); + x3r = sub( a[j + 12], a[j + 14] ); + x3i = sub( a[j + 13], a[j + 15] ); + a[j + 8] = add( x0r, x2r ); + move16(); + a[j + 9] = add( x0i, x2i ); + move16(); + + x0r = sub( x0r, x2r ); + x0i = sub( x0i, x2i ); + tmp = negate( x0r ); + L_tmp = Mult_32_16( wk2i, tmp ); /*Q(15+Qx+Q_edct) */ + L_tmp = Msub_32_16( L_tmp, wk2r, x0i ); /*Q(15+Qx+Q_edct) */ + a[j + 12] = round_fx( L_shl( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ + + tmp = negate( x0i ); + L_tmp = Mult_32_16( wk2i, tmp ); /*Q(15+Qx+Q_edct) */ + L_tmp = Madd_32_16( L_tmp, wk2r, x0r ); /*Q(15+Qx+Q_edct) */ + a[j + 13] = round_fx( L_shl( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ + + x0r = sub( x1r, x3i ); + x0i = add( x1i, x3r ); + L_tmp = Mult_32_16( wk1r, x0r ); /*Q(15+Qx+Q_edct) */ + L_tmp = Msub_32_16( L_tmp, wk1i, x0i ); /*Q(15+Qx+Q_edct) */ + a[j + 10] = round_fx( L_shl( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ + + L_tmp = Mult_32_16( wk1r, x0i ); /*Q(15+Qx+Q_edct) */ + L_tmp = Madd_32_16( L_tmp, wk1i, x0r ); /*Q(15+Qx+Q_edct) */ + a[j + 11] = round_fx( L_shl( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ + + x0r = add( x1r, x3i ); + x0i = sub( x1i, x3r ); + + L_tmp = Mult_32_16( wk3r, x0r ); /*Q(15+Qx+Q_edct) */ + L_tmp = Msub_32_16( L_tmp, wk3i, x0i ); /*Q(15+Qx+Q_edct) */ + a[j + 14] = round_fx( L_shl( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ + + L_tmp = Mult_32_16( wk3r, x0i ); /*Q(15+Qx+Q_edct) */ + L_tmp = Madd_32_16( L_tmp, wk3i, x0r ); /*Q(15+Qx+Q_edct) */ + a[j + 15] = round_fx( L_shl( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ #endif } @@ -2270,14 +2300,14 @@ static void cft1st_16fx( } /*-----------------------------------------------------------------* -* cftmdl() -* Subfunction of Complex Discrete Fourier Transform -*-----------------------------------------------------------------*/ + * cftmdl() + * Subfunction of Complex Discrete Fourier Transform + *-----------------------------------------------------------------*/ static void cftmdl_16fx( - Word16 n, /* i : data length of real and imag */ - Word16 l, /* i : initial shift for processing */ - Word16 *a, /* i/o : input/output data Q(Qx+Q_edct)*/ - const Word32 *w /* i : cos/sin table Q30*/ + Word16 n, /* i : data length of real and imag */ + Word16 l, /* i : initial shift for processing */ + Word16 *a, /* i/o : input/output data Q(Qx+Q_edct)*/ + const Word32 *w /* i : cos/sin table Q30*/ ) { Word16 j, j1, j2, j3, k, k1, k2, m, m2; @@ -2289,277 +2319,281 @@ static void cftmdl_16fx( #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - m = shl(l, 2); + m = shl( l, 2 ); move16(); - FOR (j = 0; j < l; j += 2) + FOR( j = 0; j < l; j += 2 ) { #ifdef BASOP_NOGLOB - j1 = add_o(j, l, &Overflow); - j2 = add_o(j1, l, &Overflow); - j3 = add_o(j2, l, &Overflow); - x0r = add_o(a[j], a[j1], &Overflow); - x0i = add_o(a[j + 1], a[j1 + 1], &Overflow); - x1r = sub_o(a[j], a[j1], &Overflow); - x1i = sub_o(a[j + 1], a[j1 + 1], &Overflow); - x2r = add_o(a[j2], a[j3], &Overflow); - x2i = add_o(a[j2 + 1], a[j3 + 1], &Overflow); - x3r = sub_o(a[j2], a[j3], &Overflow); - x3i = sub_o(a[j2 + 1], a[j3 + 1], &Overflow); - a[j] = add_o(x0r, x2r, &Overflow); + j1 = add_o( j, l, &Overflow ); + j2 = add_o( j1, l, &Overflow ); + j3 = add_o( j2, l, &Overflow ); + x0r = add_o( a[j], a[j1], &Overflow ); + x0i = add_o( a[j + 1], a[j1 + 1], &Overflow ); + x1r = sub_o( a[j], a[j1], &Overflow ); + x1i = sub_o( a[j + 1], a[j1 + 1], &Overflow ); + x2r = add_o( a[j2], a[j3], &Overflow ); + x2i = add_o( a[j2 + 1], a[j3 + 1], &Overflow ); + x3r = sub_o( a[j2], a[j3], &Overflow ); + x3i = sub_o( a[j2 + 1], a[j3 + 1], &Overflow ); + a[j] = add_o( x0r, x2r, &Overflow ); move16(); - a[j + 1] = add_o(x0i, x2i, &Overflow); + a[j + 1] = add_o( x0i, x2i, &Overflow ); move16(); - a[j2] = sub_o(x0r, x2r, &Overflow); + a[j2] = sub_o( x0r, x2r, &Overflow ); move16(); - a[j2 + 1] = sub_o(x0i, x2i, &Overflow); + a[j2 + 1] = sub_o( x0i, x2i, &Overflow ); move16(); - a[j1] = sub_o(x1r, x3i, &Overflow); + a[j1] = sub_o( x1r, x3i, &Overflow ); move16(); - a[j1 + 1] = add_o(x1i, x3r, &Overflow); + a[j1 + 1] = add_o( x1i, x3r, &Overflow ); move16(); - a[j3] = add_o(x1r, x3i, &Overflow); + a[j3] = add_o( x1r, x3i, &Overflow ); move16(); - a[j3 + 1] = sub_o(x1i, x3r, &Overflow); + a[j3 + 1] = sub_o( x1i, x3r, &Overflow ); move16(); #else - j1 = add(j,l); - j2 = add(j1,l); - j3 = add(j2,l); - x0r = add(a[j],a[j1]); - x0i = add(a[j + 1],a[j1 + 1]); - x1r = sub(a[j],a[j1]); - x1i = sub(a[j + 1],a[j1 + 1]); - x2r = add(a[j2],a[j3]); - x2i = add(a[j2 + 1],a[j3 + 1]); - x3r = sub(a[j2],a[j3]); - x3i = sub(a[j2 + 1],a[j3 + 1]); - a[j] = add(x0r,x2r); + j1 = add( j, l ); + j2 = add( j1, l ); + j3 = add( j2, l ); + x0r = add( a[j], a[j1] ); + x0i = add( a[j + 1], a[j1 + 1] ); + x1r = sub( a[j], a[j1] ); + x1i = sub( a[j + 1], a[j1 + 1] ); + x2r = add( a[j2], a[j3] ); + x2i = add( a[j2 + 1], a[j3 + 1] ); + x3r = sub( a[j2], a[j3] ); + x3i = sub( a[j2 + 1], a[j3 + 1] ); + a[j] = add( x0r, x2r ); move16(); - a[j + 1] = add(x0i,x2i); + a[j + 1] = add( x0i, x2i ); move16(); - a[j2] = sub(x0r,x2r); + a[j2] = sub( x0r, x2r ); move16(); - a[j2 + 1] = sub(x0i,x2i); + a[j2 + 1] = sub( x0i, x2i ); move16(); - a[j1] = sub(x1r,x3i); + a[j1] = sub( x1r, x3i ); move16(); - a[j1 + 1] = add(x1i,x3r); + a[j1 + 1] = add( x1i, x3r ); move16(); - a[j3] = add(x1r,x3i); + a[j3] = add( x1r, x3i ); move16(); - a[j3 + 1] = sub(x1i,x3r); + a[j3 + 1] = sub( x1i, x3r ); move16(); #endif } wk1r = w[2]; move32(); - tmp2 = add(l,m); - FOR (j = m; j < tmp2; j += 2) + tmp2 = add( l, m ); + FOR( j = m; j < tmp2; j += 2 ) { #ifdef BASOP_NOGLOB - j1 = add_o(j, l, &Overflow); - j2 = add_o(j1, l, &Overflow); - j3 = add_o(j2, l, &Overflow); - x0r = add_o(a[j], a[j1], &Overflow); - x0i = add_o(a[j + 1], a[j1 + 1], &Overflow); - x1r = sub_o(a[j], a[j1], &Overflow); - x1i = sub_o(a[j + 1], a[j1 + 1], &Overflow); - x2r = add_o(a[j2], a[j3], &Overflow); - x2i = add_o(a[j2 + 1], a[j3 + 1], &Overflow); - x3r = sub_o(a[j2], a[j3], &Overflow); - x3i = sub_o(a[j2 + 1], a[j3 + 1], &Overflow); - a[j] = add_o(x0r, x2r, &Overflow); - move16(); - a[j + 1] = add_o(x0i, x2i, &Overflow); - move16(); - a[j2] = sub_o(x2i, x0i, &Overflow); - move16(); - a[j2 + 1] = sub_o(x0r, x2r, &Overflow); - move16(); - - x0r = sub_o(x1r, x3i, &Overflow); - x0i = add_o(x1i, x3r, &Overflow); - tmp = sub_o(x0r, x0i, &Overflow); - L_tmp = Mult_32_16(wk1r, tmp);/*Q(15+Qx+Q_edct) */ - a[j1] = round_fx_o(L_shl_o(L_tmp, 1, &Overflow), &Overflow); /*Q(Qx+Q_edct) */ - - tmp = add_o(x0r, x0i, &Overflow); - L_tmp = Mult_32_16(wk1r, tmp); /*Q(15+Qx+Q_edct) */ - a[j1 + 1] = round_fx_o(L_shl_o(L_tmp, 1, &Overflow), &Overflow); /*Q(Qx+Q_edct) */ - - x0r = add_o(x3i, x1r, &Overflow); - x0i = sub_o(x3r, x1i, &Overflow); - tmp = sub_o(x0i, x0r, &Overflow); - L_tmp = Mult_32_16(wk1r, tmp);/*Q(15+Qx+Q_edct) */ - a[j3] = round_fx_o(L_shl_o(L_tmp, 1, &Overflow), &Overflow); /*Q(Qx+Q_edct) */ - - tmp = add_o(x0i, x0r, &Overflow); - L_tmp = Mult_32_16(wk1r, tmp); /*Q(15+Qx+Q_edct) */ - a[j3 + 1] = round_fx_o(L_shl_o(L_tmp, 1, &Overflow), &Overflow); /*Q(Qx+Q_edct) */ -#else - j1 = add(j,l); - j2 = add(j1,l); - j3 = add(j2,l); - x0r = add(a[j],a[j1]); - x0i = add(a[j + 1],a[j1 + 1]); - x1r = sub(a[j],a[j1]); - x1i = sub(a[j + 1],a[j1 + 1]); - x2r = add(a[j2],a[j3]); - x2i = add(a[j2 + 1],a[j3 + 1]); - x3r = sub(a[j2],a[j3]); - x3i = sub(a[j2 + 1],a[j3 + 1]); - a[j] = add(x0r,x2r); - move16(); - a[j + 1] = add(x0i,x2i); - move16(); - a[j2] = sub(x2i,x0i); - move16(); - a[j2 + 1] = sub(x0r,x2r); - move16(); - - x0r = sub(x1r,x3i); - x0i = add(x1i,x3r); - tmp = sub(x0r,x0i); - L_tmp = Mult_32_16(wk1r,tmp);/*Q(15+Qx+Q_edct) */ - a[j1] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ - - tmp = add(x0r,x0i); - L_tmp = Mult_32_16(wk1r,tmp); /*Q(15+Qx+Q_edct) */ - a[j1 + 1] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ - - x0r = add(x3i,x1r); - x0i = sub(x3r,x1i); - tmp = sub(x0i,x0r); - L_tmp = Mult_32_16(wk1r,tmp);/*Q(15+Qx+Q_edct) */ - a[j3] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ - - tmp = add(x0i,x0r); - L_tmp = Mult_32_16(wk1r,tmp); /*Q(15+Qx+Q_edct) */ - a[j3 + 1] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ + j1 = add_o( j, l, &Overflow ); + j2 = add_o( j1, l, &Overflow ); + j3 = add_o( j2, l, &Overflow ); + x0r = add_o( a[j], a[j1], &Overflow ); + x0i = add_o( a[j + 1], a[j1 + 1], &Overflow ); + x1r = sub_o( a[j], a[j1], &Overflow ); + x1i = sub_o( a[j + 1], a[j1 + 1], &Overflow ); + x2r = add_o( a[j2], a[j3], &Overflow ); + x2i = add_o( a[j2 + 1], a[j3 + 1], &Overflow ); + x3r = sub_o( a[j2], a[j3], &Overflow ); + x3i = sub_o( a[j2 + 1], a[j3 + 1], &Overflow ); + a[j] = add_o( x0r, x2r, &Overflow ); + move16(); + a[j + 1] = add_o( x0i, x2i, &Overflow ); + move16(); + a[j2] = sub_o( x2i, x0i, &Overflow ); + move16(); + a[j2 + 1] = sub_o( x0r, x2r, &Overflow ); + move16(); + + x0r = sub_o( x1r, x3i, &Overflow ); + x0i = add_o( x1i, x3r, &Overflow ); + tmp = sub_o( x0r, x0i, &Overflow ); + L_tmp = Mult_32_16( wk1r, tmp ); /*Q(15+Qx+Q_edct) */ + a[j1] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + + tmp = add_o( x0r, x0i, &Overflow ); + L_tmp = Mult_32_16( wk1r, tmp ); /*Q(15+Qx+Q_edct) */ + a[j1 + 1] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + + x0r = add_o( x3i, x1r, &Overflow ); + x0i = sub_o( x3r, x1i, &Overflow ); + tmp = sub_o( x0i, x0r, &Overflow ); + L_tmp = Mult_32_16( wk1r, tmp ); /*Q(15+Qx+Q_edct) */ + a[j3] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + + tmp = add_o( x0i, x0r, &Overflow ); + L_tmp = Mult_32_16( wk1r, tmp ); /*Q(15+Qx+Q_edct) */ + a[j3 + 1] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ +#else + j1 = add( j, l ); + j2 = add( j1, l ); + j3 = add( j2, l ); + x0r = add( a[j], a[j1] ); + x0i = add( a[j + 1], a[j1 + 1] ); + x1r = sub( a[j], a[j1] ); + x1i = sub( a[j + 1], a[j1 + 1] ); + x2r = add( a[j2], a[j3] ); + x2i = add( a[j2 + 1], a[j3 + 1] ); + x3r = sub( a[j2], a[j3] ); + x3i = sub( a[j2 + 1], a[j3 + 1] ); + a[j] = add( x0r, x2r ); + move16(); + a[j + 1] = add( x0i, x2i ); + move16(); + a[j2] = sub( x2i, x0i ); + move16(); + a[j2 + 1] = sub( x0r, x2r ); + move16(); + + x0r = sub( x1r, x3i ); + x0i = add( x1i, x3r ); + tmp = sub( x0r, x0i ); + L_tmp = Mult_32_16( wk1r, tmp ); /*Q(15+Qx+Q_edct) */ + a[j1] = round_fx( L_shl( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ + + tmp = add( x0r, x0i ); + L_tmp = Mult_32_16( wk1r, tmp ); /*Q(15+Qx+Q_edct) */ + a[j1 + 1] = round_fx( L_shl( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ + + x0r = add( x3i, x1r ); + x0i = sub( x3r, x1i ); + tmp = sub( x0i, x0r ); + L_tmp = Mult_32_16( wk1r, tmp ); /*Q(15+Qx+Q_edct) */ + a[j3] = round_fx( L_shl( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ + + tmp = add( x0i, x0r ); + L_tmp = Mult_32_16( wk1r, tmp ); /*Q(15+Qx+Q_edct) */ + a[j3 + 1] = round_fx( L_shl( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ #endif } k1 = 0; move16(); - m2 = shl(m,1); - FOR (k = m2; k < n; k += m2) + m2 = shl( m, 1 ); + FOR( k = m2; k < n; k += m2 ) { - k1 = add(k1,2); - k2 = shl(k1,1); - wk2r = w[k1]; move32(); - wk2i = w[k1 + 1]; move32(); - wk1r = w[k2]; move32(); - wk1i = w[k2 + 1]; move32(); - L_tmp = L_shl(Mult_32_32(wk2i,wk1i),1);/*Q29 */ - wk3r = L_sub(wk1r,L_shl(L_tmp,1));/*Q30 */ + k1 = add( k1, 2 ); + k2 = shl( k1, 1 ); + wk2r = w[k1]; + move32(); + wk2i = w[k1 + 1]; + move32(); + wk1r = w[k2]; + move32(); + wk1i = w[k2 + 1]; + move32(); + L_tmp = L_shl( Mult_32_32( wk2i, wk1i ), 1 ); /*Q29 */ + wk3r = L_sub( wk1r, L_shl( L_tmp, 1 ) ); /*Q30 */ - L_tmp = L_shl(Mult_32_32(wk2i,wk1r),1);/*Q29 */ - wk3i = L_sub(L_shl(L_tmp,1),wk1i);/*Q30 */ + L_tmp = L_shl( Mult_32_32( wk2i, wk1r ), 1 ); /*Q29 */ + wk3i = L_sub( L_shl( L_tmp, 1 ), wk1i ); /*Q30 */ - tmp2 = add(l,k); - FOR (j = k; j < tmp2; j += 2) + tmp2 = add( l, k ); + FOR( j = k; j < tmp2; j += 2 ) { #ifdef BASOP_NOGLOB - j1 = add_o(j, l, &Overflow); - j2 = add_o(j1, l, &Overflow); - j3 = add_o(j2, l, &Overflow); - x0r = add_o(a[j], a[j1], &Overflow); - x0i = add_o(a[j + 1], a[j1 + 1], &Overflow); - x1r = sub_o(a[j], a[j1], &Overflow); - x1i = sub_o(a[j + 1], a[j1 + 1], &Overflow); - x2r = add_o(a[j2], a[j3], &Overflow); - x2i = add_o(a[j2 + 1], a[j3 + 1], &Overflow); - x3r = sub_o(a[j2], a[j3], &Overflow); - x3i = sub_o(a[j2 + 1], a[j3 + 1], &Overflow); - a[j] = add_o(x0r, x2r, &Overflow); + j1 = add_o( j, l, &Overflow ); + j2 = add_o( j1, l, &Overflow ); + j3 = add_o( j2, l, &Overflow ); + x0r = add_o( a[j], a[j1], &Overflow ); + x0i = add_o( a[j + 1], a[j1 + 1], &Overflow ); + x1r = sub_o( a[j], a[j1], &Overflow ); + x1i = sub_o( a[j + 1], a[j1 + 1], &Overflow ); + x2r = add_o( a[j2], a[j3], &Overflow ); + x2i = add_o( a[j2 + 1], a[j3 + 1], &Overflow ); + x3r = sub_o( a[j2], a[j3], &Overflow ); + x3i = sub_o( a[j2 + 1], a[j3 + 1], &Overflow ); + a[j] = add_o( x0r, x2r, &Overflow ); move16(); - a[j + 1] = add_o(x0i, x2i, &Overflow); + a[j + 1] = add_o( x0i, x2i, &Overflow ); move16(); - x0r = sub_o(x0r, x2r, &Overflow); - x0i = sub_o(x0i, x2i, &Overflow); - - L_tmp = Mult_32_16(wk2r, x0r); /*Q(15+Qx+Q_edct) */ - L_tmp = Msub_32_16(L_tmp, wk2i, x0i); /*Q(15+Qx+Q_edct) */ - a[j2] = round_fx_o(L_shl_o(L_tmp, 1, &Overflow), &Overflow); /*Q(Qx+Q_edct) */ - - L_tmp = Mult_32_16(wk2r, x0i); /*Q(15+Qx+Q_edct) */ - L_tmp = Madd_32_16(L_tmp, wk2i, x0r); /*Q(15+Qx+Q_edct) */ - a[j2 + 1] = round_fx_o(L_shl_o(L_tmp, 1, &Overflow), &Overflow); /*Q(Qx+Q_edct) */ - - x0r = sub_o(x1r, x3i, &Overflow); - x0i = add_o(x1i, x3r, &Overflow); - - L_tmp = Mult_32_16(wk1r, x0r); /*Q(15+Qx+Q_edct) */ - L_tmp = Msub_32_16(L_tmp, wk1i, x0i); /*Q(15+Qx+Q_edct) */ - a[j1] = round_fx_o(L_shl_o(L_tmp, 1, &Overflow), &Overflow); /*Q(Qx+Q_edct) */ - - L_tmp = Mult_32_16(wk1r, x0i); /*Q(15+Qx+Q_edct) */ - L_tmp = Madd_32_16(L_tmp, wk1i, x0r); /*Q(15+Qx+Q_edct) */ - a[j1 + 1] = round_fx_o(L_shl_o(L_tmp, 1, &Overflow), &Overflow); /*Q(Qx+Q_edct) */ - - L_x0r = L_add((Word32)x1r, (Word32)x3i); - L_x0i = L_sub((Word32)x1i, (Word32)x3r); - x0r = extract_l(L_x0r); - x0i = extract_l(L_x0i); - L_tmp = Mult_32_16(wk3r, x0r); /*Q(15+Qx+Q_edct) */ - L_tmp = Msub_32_16(L_tmp, wk3i, x0i); /*Q(15+Qx+Q_edct) */ - a[j3] = round_fx_o(L_shl_o(L_tmp, 1, &Overflow), &Overflow); /*Q(Qx+Q_edct) */ - - L_tmp = Mult_32_16(wk3r, x0i); /*Q(15+Qx+Q_edct) */ - L_tmp = Madd_32_16(L_tmp, wk3i, x0r); /*Q(15+Qx+Q_edct) */ - a[j3 + 1] = round_fx_o(L_shl_o(L_tmp, 1, &Overflow), &Overflow); /*Q(Qx+Q_edct) */ -#else - j1 = add(j,l); - j2 = add(j1,l); - j3 = add(j2,l); - x0r = add(a[j],a[j1]); - x0i = add(a[j + 1],a[j1 + 1]); - x1r = sub(a[j],a[j1]); - x1i = sub(a[j + 1],a[j1 + 1]); - x2r = add(a[j2],a[j3]); - x2i = add(a[j2 + 1],a[j3 + 1]); - x3r = sub(a[j2],a[j3]); - x3i = sub(a[j2 + 1],a[j3 + 1]); - a[j] = add(x0r,x2r); + x0r = sub_o( x0r, x2r, &Overflow ); + x0i = sub_o( x0i, x2i, &Overflow ); + + L_tmp = Mult_32_16( wk2r, x0r ); /*Q(15+Qx+Q_edct) */ + L_tmp = Msub_32_16( L_tmp, wk2i, x0i ); /*Q(15+Qx+Q_edct) */ + a[j2] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + + L_tmp = Mult_32_16( wk2r, x0i ); /*Q(15+Qx+Q_edct) */ + L_tmp = Madd_32_16( L_tmp, wk2i, x0r ); /*Q(15+Qx+Q_edct) */ + a[j2 + 1] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + + x0r = sub_o( x1r, x3i, &Overflow ); + x0i = add_o( x1i, x3r, &Overflow ); + + L_tmp = Mult_32_16( wk1r, x0r ); /*Q(15+Qx+Q_edct) */ + L_tmp = Msub_32_16( L_tmp, wk1i, x0i ); /*Q(15+Qx+Q_edct) */ + a[j1] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + + L_tmp = Mult_32_16( wk1r, x0i ); /*Q(15+Qx+Q_edct) */ + L_tmp = Madd_32_16( L_tmp, wk1i, x0r ); /*Q(15+Qx+Q_edct) */ + a[j1 + 1] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + + L_x0r = L_add( (Word32) x1r, (Word32) x3i ); + L_x0i = L_sub( (Word32) x1i, (Word32) x3r ); + x0r = extract_l( L_x0r ); + x0i = extract_l( L_x0i ); + L_tmp = Mult_32_16( wk3r, x0r ); /*Q(15+Qx+Q_edct) */ + L_tmp = Msub_32_16( L_tmp, wk3i, x0i ); /*Q(15+Qx+Q_edct) */ + a[j3] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + + L_tmp = Mult_32_16( wk3r, x0i ); /*Q(15+Qx+Q_edct) */ + L_tmp = Madd_32_16( L_tmp, wk3i, x0r ); /*Q(15+Qx+Q_edct) */ + a[j3 + 1] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ +#else + j1 = add( j, l ); + j2 = add( j1, l ); + j3 = add( j2, l ); + x0r = add( a[j], a[j1] ); + x0i = add( a[j + 1], a[j1 + 1] ); + x1r = sub( a[j], a[j1] ); + x1i = sub( a[j + 1], a[j1 + 1] ); + x2r = add( a[j2], a[j3] ); + x2i = add( a[j2 + 1], a[j3 + 1] ); + x3r = sub( a[j2], a[j3] ); + x3i = sub( a[j2 + 1], a[j3 + 1] ); + a[j] = add( x0r, x2r ); move16(); - a[j + 1] = add(x0i,x2i); + a[j + 1] = add( x0i, x2i ); move16(); - x0r = sub(x0r,x2r); - x0i = sub(x0i,x2i); + x0r = sub( x0r, x2r ); + x0i = sub( x0i, x2i ); - L_tmp = Mult_32_16(wk2r,x0r); /*Q(15+Qx+Q_edct) */ - L_tmp = Msub_32_16(L_tmp,wk2i,x0i); /*Q(15+Qx+Q_edct) */ - a[j2] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ + L_tmp = Mult_32_16( wk2r, x0r ); /*Q(15+Qx+Q_edct) */ + L_tmp = Msub_32_16( L_tmp, wk2i, x0i ); /*Q(15+Qx+Q_edct) */ + a[j2] = round_fx( L_shl( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ - L_tmp = Mult_32_16(wk2r,x0i); /*Q(15+Qx+Q_edct) */ - L_tmp = Madd_32_16(L_tmp,wk2i,x0r); /*Q(15+Qx+Q_edct) */ - a[j2 + 1] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ + L_tmp = Mult_32_16( wk2r, x0i ); /*Q(15+Qx+Q_edct) */ + L_tmp = Madd_32_16( L_tmp, wk2i, x0r ); /*Q(15+Qx+Q_edct) */ + a[j2 + 1] = round_fx( L_shl( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ - x0r = sub(x1r,x3i); - x0i = add(x1i,x3r); + x0r = sub( x1r, x3i ); + x0i = add( x1i, x3r ); - L_tmp = Mult_32_16(wk1r,x0r); /*Q(15+Qx+Q_edct) */ - L_tmp = Msub_32_16(L_tmp,wk1i,x0i); /*Q(15+Qx+Q_edct) */ - a[j1] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ + L_tmp = Mult_32_16( wk1r, x0r ); /*Q(15+Qx+Q_edct) */ + L_tmp = Msub_32_16( L_tmp, wk1i, x0i ); /*Q(15+Qx+Q_edct) */ + a[j1] = round_fx( L_shl( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ - L_tmp = Mult_32_16(wk1r,x0i); /*Q(15+Qx+Q_edct) */ - L_tmp = Madd_32_16(L_tmp,wk1i,x0r); /*Q(15+Qx+Q_edct) */ - a[j1 + 1] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ + L_tmp = Mult_32_16( wk1r, x0i ); /*Q(15+Qx+Q_edct) */ + L_tmp = Madd_32_16( L_tmp, wk1i, x0r ); /*Q(15+Qx+Q_edct) */ + a[j1 + 1] = round_fx( L_shl( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ - L_x0r = L_add((Word32) x1r, (Word32) x3i); - L_x0i = L_sub((Word32) x1i, (Word32) x3r); - x0r = extract_l(L_x0r); - x0i = extract_l(L_x0i); - L_tmp = Mult_32_16(wk3r,x0r); /*Q(15+Qx+Q_edct) */ - L_tmp = Msub_32_16(L_tmp,wk3i,x0i); /*Q(15+Qx+Q_edct) */ - a[j3] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ + L_x0r = L_add( (Word32) x1r, (Word32) x3i ); + L_x0i = L_sub( (Word32) x1i, (Word32) x3r ); + x0r = extract_l( L_x0r ); + x0i = extract_l( L_x0i ); + L_tmp = Mult_32_16( wk3r, x0r ); /*Q(15+Qx+Q_edct) */ + L_tmp = Msub_32_16( L_tmp, wk3i, x0i ); /*Q(15+Qx+Q_edct) */ + a[j3] = round_fx( L_shl( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ - L_tmp = Mult_32_16(wk3r,x0i); /*Q(15+Qx+Q_edct) */ - L_tmp = Madd_32_16(L_tmp,wk3i,x0r); /*Q(15+Qx+Q_edct) */ - a[j3 + 1] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ + L_tmp = Mult_32_16( wk3r, x0i ); /*Q(15+Qx+Q_edct) */ + L_tmp = Madd_32_16( L_tmp, wk3i, x0r ); /*Q(15+Qx+Q_edct) */ + a[j3 + 1] = round_fx( L_shl( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ #endif } @@ -2568,123 +2602,123 @@ static void cftmdl_16fx( wk1i = w[k2 + 3]; move32(); #ifdef BASOP_NOGLOB - L_tmp = L_shl_o(Mult_32_32(wk2r,wk1i),1, &Overflow);/*Q29 */ - wk3r = L_sub_o(wk1r,L_shl_o(L_tmp,1, &Overflow), &Overflow); /*Q30 */ + L_tmp = L_shl_o( Mult_32_32( wk2r, wk1i ), 1, &Overflow ); /*Q29 */ + wk3r = L_sub_o( wk1r, L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q30 */ - L_tmp = L_shl_o(Mult_32_32(wk2r,wk1r),1, &Overflow);/*Q29 */ - wk3i = L_sub_o(L_shl_o(L_tmp,1, &Overflow),wk1i, &Overflow); /*Q30 */ + L_tmp = L_shl_o( Mult_32_32( wk2r, wk1r ), 1, &Overflow ); /*Q29 */ + wk3i = L_sub_o( L_shl_o( L_tmp, 1, &Overflow ), wk1i, &Overflow ); /*Q30 */ #else - L_tmp = L_shl(Mult_32_32(wk2r,wk1i),1);/*Q29 */ - wk3r = L_sub(wk1r,L_shl(L_tmp,1)); /*Q30 */ + L_tmp = L_shl( Mult_32_32( wk2r, wk1i ), 1 ); /*Q29 */ + wk3r = L_sub( wk1r, L_shl( L_tmp, 1 ) ); /*Q30 */ - L_tmp = L_shl(Mult_32_32(wk2r,wk1r),1);/*Q29 */ - wk3i = L_sub(L_shl(L_tmp,1),wk1i); /*Q30 */ + L_tmp = L_shl( Mult_32_32( wk2r, wk1r ), 1 ); /*Q29 */ + wk3i = L_sub( L_shl( L_tmp, 1 ), wk1i ); /*Q30 */ #endif - tmp2 = add(l,add(k,m)); - FOR (j = add(k,m); j < tmp2; j += 2) + tmp2 = add( l, add( k, m ) ); + FOR( j = add( k, m ); j < tmp2; j += 2 ) { #ifdef BASOP_NOGLOB - j1 = add_o(j, l, &Overflow); - j2 = add_o(j1, l, &Overflow); - j3 = add_o(j2, l, &Overflow); - x0r = add_o(a[j], a[j1], &Overflow); - x0i = add_o(a[j + 1], a[j1 + 1], &Overflow); - x1r = sub_o(a[j], a[j1], &Overflow); - x1i = sub_o(a[j + 1], a[j1 + 1], &Overflow); - x2r = add_o(a[j2], a[j3], &Overflow); - x2i = add_o(a[j2 + 1], a[j3 + 1], &Overflow); - x3r = sub_o(a[j2], a[j3], &Overflow); - x3i = sub_o(a[j2 + 1], a[j3 + 1], &Overflow); - a[j] = add_o(x0r, x2r, &Overflow); + j1 = add_o( j, l, &Overflow ); + j2 = add_o( j1, l, &Overflow ); + j3 = add_o( j2, l, &Overflow ); + x0r = add_o( a[j], a[j1], &Overflow ); + x0i = add_o( a[j + 1], a[j1 + 1], &Overflow ); + x1r = sub_o( a[j], a[j1], &Overflow ); + x1i = sub_o( a[j + 1], a[j1 + 1], &Overflow ); + x2r = add_o( a[j2], a[j3], &Overflow ); + x2i = add_o( a[j2 + 1], a[j3 + 1], &Overflow ); + x3r = sub_o( a[j2], a[j3], &Overflow ); + x3i = sub_o( a[j2 + 1], a[j3 + 1], &Overflow ); + a[j] = add_o( x0r, x2r, &Overflow ); move16(); - a[j + 1] = add_o(x0i, x2i, &Overflow); + a[j + 1] = add_o( x0i, x2i, &Overflow ); move16(); - x0r = sub_o(x0r, x2r, &Overflow); - x0i = sub_o(x0i, x2i, &Overflow); - - tmp = negate(x0r); - L_tmp = Mult_32_16(wk2i, tmp);/*Q(15+Qx+Q_edct) */ - L_tmp = Msub_32_16(L_tmp, wk2r, x0i); /*Q(15+Qx+Q_edct) */ - a[j2] = round_fx_o(L_shl_o(L_tmp, 1, &Overflow), &Overflow); /*Q(Qx+Q_edct) */ - - tmp = negate(x0i); - L_tmp = Mult_32_16(wk2i, tmp);/*Q(15+Qx+Q_edct) */ - L_tmp = Madd_32_16(L_tmp, wk2r, x0r); /*Q(15+Qx+Q_edct) */ - a[j2 + 1] = round_fx_o(L_shl_o(L_tmp, 1, &Overflow), &Overflow); /*Q(Qx+Q_edct) */ - - x0r = sub_o(x1r, x3i, &Overflow); - x0i = add_o(x1i, x3r, &Overflow); - - L_tmp = Mult_32_16(wk1r, x0r);/*Q(15+Qx+Q_edct) */ - L_tmp = Msub_32_16(L_tmp, wk1i, x0i); /*Q(15+Qx+Q_edct) */ - a[j1] = round_fx_o(L_shl_o(L_tmp, 1, &Overflow), &Overflow); /*Q(Qx+Q_edct) */ - - L_tmp = Mult_32_16(wk1r, x0i);/*Q(15+Qx+Q_edct) */ - L_tmp = Madd_32_16(L_tmp, wk1i, x0r); /*Q(15+Qx+Q_edct) */ - a[j1 + 1] = round_fx_o(L_shl_o(L_tmp, 1, &Overflow), &Overflow); /*Q(Qx+Q_edct) */ - - x0r = add_o(x1r, x3i, &Overflow); - x0i = sub_o(x1i, x3r, &Overflow); - - L_tmp = Mult_32_16(wk3r, x0r); /*Q(15+Qx+Q_edct) */ - L_tmp = Msub_32_16(L_tmp, wk3i, x0i); /*Q(15+Qx+Q_edct) */ - a[j3] = round_fx_o(L_shl_o(L_tmp, 1, &Overflow), &Overflow); /*Q(Qx+Q_edct) */ - - L_tmp = Mult_32_16(wk3r, x0i); /*Q(15+Qx+Q_edct) */ - L_tmp = Madd_32_16(L_tmp, wk3i, x0r); /*Q(15+Qx+Q_edct) */ - a[j3 + 1] = round_fx_o(L_shl_o(L_tmp, 1, &Overflow), &Overflow); /*Q(Qx+Q_edct) */ -#else - j1 = add(j,l); - j2 = add(j1,l); - j3 = add(j2,l); - x0r = add(a[j],a[j1]); - x0i = add(a[j + 1],a[j1 + 1]); - x1r = sub(a[j],a[j1]); - x1i = sub(a[j + 1],a[j1 + 1]); - x2r = add(a[j2],a[j3]); - x2i = add(a[j2 + 1],a[j3 + 1]); - x3r = sub(a[j2],a[j3]); - x3i = sub(a[j2 + 1],a[j3 + 1]); - a[j] = add(x0r,x2r); + x0r = sub_o( x0r, x2r, &Overflow ); + x0i = sub_o( x0i, x2i, &Overflow ); + + tmp = negate( x0r ); + L_tmp = Mult_32_16( wk2i, tmp ); /*Q(15+Qx+Q_edct) */ + L_tmp = Msub_32_16( L_tmp, wk2r, x0i ); /*Q(15+Qx+Q_edct) */ + a[j2] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + + tmp = negate( x0i ); + L_tmp = Mult_32_16( wk2i, tmp ); /*Q(15+Qx+Q_edct) */ + L_tmp = Madd_32_16( L_tmp, wk2r, x0r ); /*Q(15+Qx+Q_edct) */ + a[j2 + 1] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + + x0r = sub_o( x1r, x3i, &Overflow ); + x0i = add_o( x1i, x3r, &Overflow ); + + L_tmp = Mult_32_16( wk1r, x0r ); /*Q(15+Qx+Q_edct) */ + L_tmp = Msub_32_16( L_tmp, wk1i, x0i ); /*Q(15+Qx+Q_edct) */ + a[j1] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + + L_tmp = Mult_32_16( wk1r, x0i ); /*Q(15+Qx+Q_edct) */ + L_tmp = Madd_32_16( L_tmp, wk1i, x0r ); /*Q(15+Qx+Q_edct) */ + a[j1 + 1] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + + x0r = add_o( x1r, x3i, &Overflow ); + x0i = sub_o( x1i, x3r, &Overflow ); + + L_tmp = Mult_32_16( wk3r, x0r ); /*Q(15+Qx+Q_edct) */ + L_tmp = Msub_32_16( L_tmp, wk3i, x0i ); /*Q(15+Qx+Q_edct) */ + a[j3] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + + L_tmp = Mult_32_16( wk3r, x0i ); /*Q(15+Qx+Q_edct) */ + L_tmp = Madd_32_16( L_tmp, wk3i, x0r ); /*Q(15+Qx+Q_edct) */ + a[j3 + 1] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ +#else + j1 = add( j, l ); + j2 = add( j1, l ); + j3 = add( j2, l ); + x0r = add( a[j], a[j1] ); + x0i = add( a[j + 1], a[j1 + 1] ); + x1r = sub( a[j], a[j1] ); + x1i = sub( a[j + 1], a[j1 + 1] ); + x2r = add( a[j2], a[j3] ); + x2i = add( a[j2 + 1], a[j3 + 1] ); + x3r = sub( a[j2], a[j3] ); + x3i = sub( a[j2 + 1], a[j3 + 1] ); + a[j] = add( x0r, x2r ); move16(); - a[j + 1] = add(x0i,x2i); + a[j + 1] = add( x0i, x2i ); move16(); - x0r = sub(x0r,x2r); - x0i = sub(x0i,x2i); + x0r = sub( x0r, x2r ); + x0i = sub( x0i, x2i ); - tmp = negate(x0r); - L_tmp = Mult_32_16(wk2i,tmp);/*Q(15+Qx+Q_edct) */ - L_tmp = Msub_32_16(L_tmp,wk2r,x0i); /*Q(15+Qx+Q_edct) */ - a[j2] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ + tmp = negate( x0r ); + L_tmp = Mult_32_16( wk2i, tmp ); /*Q(15+Qx+Q_edct) */ + L_tmp = Msub_32_16( L_tmp, wk2r, x0i ); /*Q(15+Qx+Q_edct) */ + a[j2] = round_fx( L_shl( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ - tmp = negate(x0i); - L_tmp = Mult_32_16(wk2i,tmp);/*Q(15+Qx+Q_edct) */ - L_tmp = Madd_32_16(L_tmp,wk2r,x0r); /*Q(15+Qx+Q_edct) */ - a[j2 + 1] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ + tmp = negate( x0i ); + L_tmp = Mult_32_16( wk2i, tmp ); /*Q(15+Qx+Q_edct) */ + L_tmp = Madd_32_16( L_tmp, wk2r, x0r ); /*Q(15+Qx+Q_edct) */ + a[j2 + 1] = round_fx( L_shl( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ - x0r = sub(x1r,x3i); - x0i = add(x1i,x3r); + x0r = sub( x1r, x3i ); + x0i = add( x1i, x3r ); - L_tmp = Mult_32_16(wk1r,x0r);/*Q(15+Qx+Q_edct) */ - L_tmp = Msub_32_16(L_tmp,wk1i,x0i); /*Q(15+Qx+Q_edct) */ - a[j1] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ + L_tmp = Mult_32_16( wk1r, x0r ); /*Q(15+Qx+Q_edct) */ + L_tmp = Msub_32_16( L_tmp, wk1i, x0i ); /*Q(15+Qx+Q_edct) */ + a[j1] = round_fx( L_shl( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ - L_tmp = Mult_32_16(wk1r,x0i);/*Q(15+Qx+Q_edct) */ - L_tmp = Madd_32_16(L_tmp,wk1i,x0r); /*Q(15+Qx+Q_edct) */ - a[j1 + 1] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ + L_tmp = Mult_32_16( wk1r, x0i ); /*Q(15+Qx+Q_edct) */ + L_tmp = Madd_32_16( L_tmp, wk1i, x0r ); /*Q(15+Qx+Q_edct) */ + a[j1 + 1] = round_fx( L_shl( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ - x0r = add(x1r,x3i); - x0i = sub(x1i,x3r); + x0r = add( x1r, x3i ); + x0i = sub( x1i, x3r ); - L_tmp = Mult_32_16(wk3r,x0r); /*Q(15+Qx+Q_edct) */ - L_tmp = Msub_32_16(L_tmp,wk3i,x0i); /*Q(15+Qx+Q_edct) */ - a[j3] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ + L_tmp = Mult_32_16( wk3r, x0r ); /*Q(15+Qx+Q_edct) */ + L_tmp = Msub_32_16( L_tmp, wk3i, x0i ); /*Q(15+Qx+Q_edct) */ + a[j3] = round_fx( L_shl( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ - L_tmp = Mult_32_16(wk3r,x0i); /*Q(15+Qx+Q_edct) */ - L_tmp = Madd_32_16(L_tmp,wk3i,x0r); /*Q(15+Qx+Q_edct) */ - a[j3 + 1] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ + L_tmp = Mult_32_16( wk3r, x0i ); /*Q(15+Qx+Q_edct) */ + L_tmp = Madd_32_16( L_tmp, wk3i, x0r ); /*Q(15+Qx+Q_edct) */ + a[j3 + 1] = round_fx( L_shl( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ #endif } } @@ -2692,53 +2726,53 @@ static void cftmdl_16fx( return; } -void fft3_fx(const Word16 X[], Word16 Y[], const Word16 n) +void fft3_fx( const Word16 X[], Word16 Y[], const Word16 n ) { - Word16 Z[PH_ECU_SPEC_SIZE]; + Word16 Z[PH_ECU_SPEC_SIZE]; Word16 *Z0, *Z1, *Z2; Word16 *z0, *z1, *z2; const Word16 *x; const Word16 *t_sin = sincos_t_rad3_fx; - Word16 m, mMinus1, step; - Word16 i, l; - Word16 c1_ind, s1_ind, c2_ind, s2_ind; - Word16 c1_step, s1_step, c2_step, s2_step; + Word16 m, mMinus1, step; + Word16 i, l; + Word16 c1_ind, s1_ind, c2_ind, s2_ind; + Word16 c1_step, s1_step, c2_step, s2_step; Word16 *RY, *IY, *RZ0, *IZ0, *RZ1, *IZ1, *RZ2, *IZ2; - Word32 acc; - Word16 mBy2, orderMinus1; + Word32 acc; + Word16 mBy2, orderMinus1; const Word16 *pPhaseTbl; /* Determine the order of the transform, the length of decimated */ /* transforms m, and the step for the sine and cosine tables. */ - SWITCH(n) + SWITCH( n ) { - case 1536: - orderMinus1 = 9-1; - move16(); - m = 512; - move16(); - step = 1; - move16(); - pPhaseTbl = FFT_W256; - BREAK; - case 384: - orderMinus1 = 7-1; - move16(); - m = 128; - move16(); - step = 4; - move16(); - pPhaseTbl = FFT_W64; - BREAK; - default: - orderMinus1 = 7-1; - move16(); - m = 128; - move16(); - step = 4; - move16(); - pPhaseTbl = FFT_W64; - BREAK; + case 1536: + orderMinus1 = 9 - 1; + move16(); + m = 512; + move16(); + step = 1; + move16(); + pPhaseTbl = FFT_W256; + BREAK; + case 384: + orderMinus1 = 7 - 1; + move16(); + m = 128; + move16(); + step = 4; + move16(); + pPhaseTbl = FFT_W64; + BREAK; + default: + orderMinus1 = 7 - 1; + move16(); + m = 128; + move16(); + step = 4; + move16(); + pPhaseTbl = FFT_W64; + BREAK; } /* Compose decimated sequences X[3i], X[3i+1],X[3i+2] */ @@ -2746,27 +2780,30 @@ void fft3_fx(const Word16 X[], Word16 Y[], const Word16 n) Z0 = &Z[0]; z0 = &Z0[0]; Z1 = &Z0[m]; - z1 = &Z1[0]; /* Z1 = &Z[ m]; */ + z1 = &Z1[0]; /* Z1 = &Z[ m]; */ Z2 = &Z1[m]; - z2 = &Z2[0]; /* Z2 = &Z[2m]; */ - x = &X[0]; - FOR (i = 0; i < m; i++) + z2 = &Z2[0]; /* Z2 = &Z[2m]; */ + x = &X[0]; + FOR( i = 0; i < m; i++ ) { - *z0++ = *x++; /* Z0[i] = X[3i]; */ move16(); - *z1++ = *x++; /* Z1[i] = X[3i+1]; */ move16(); - *z2++ = *x++; /* Z2[i] = X[3i+2]; */ move16(); + *z0++ = *x++; /* Z0[i] = X[3i]; */ + move16(); + *z1++ = *x++; /* Z1[i] = X[3i+1]; */ + move16(); + *z2++ = *x++; /* Z2[i] = X[3i+2]; */ + move16(); } - mBy2 = shr(m,1); - r_fft_fx_lc(pPhaseTbl, m, mBy2, orderMinus1, Z0, Z0, 1); - r_fft_fx_lc(pPhaseTbl, m, mBy2, orderMinus1, Z1, Z1, 1); - r_fft_fx_lc(pPhaseTbl, m, mBy2, orderMinus1, Z2, Z2, 1); + mBy2 = shr( m, 1 ); + r_fft_fx_lc( pPhaseTbl, m, mBy2, orderMinus1, Z0, Z0, 1 ); + r_fft_fx_lc( pPhaseTbl, m, mBy2, orderMinus1, Z1, Z1, 1 ); + r_fft_fx_lc( pPhaseTbl, m, mBy2, orderMinus1, Z2, Z2, 1 ); /* Butterflies of order 3. */ /* pointer initialization */ - mMinus1 = sub(m,1); + mMinus1 = sub( m, 1 ); RY = &Y[0]; IY = &Y[n]; - IY--; /* Decrement the address counter.*/ + IY--; /* Decrement the address counter.*/ RZ0 = &Z0[0]; IZ0 = &Z0[mMinus1]; RZ1 = &Z1[0]; @@ -2774,270 +2811,270 @@ void fft3_fx(const Word16 X[], Word16 Y[], const Word16 n) RZ2 = &Z2[0]; IZ2 = &Z2[mMinus1]; - c1_step = negate(step); + c1_step = negate( step ); s1_step = step; move16(); - c2_step = shl(c1_step,1); - s2_step = shl(s1_step,1); - c1_ind = add(T_SIN_PI_2, c1_step); + c2_step = shl( c1_step, 1 ); + s2_step = shl( s1_step, 1 ); + c1_ind = add( T_SIN_PI_2, c1_step ); s1_ind = s1_step; move16(); - c2_ind = add(T_SIN_PI_2, c2_step); + c2_ind = add( T_SIN_PI_2, c2_step ); s2_ind = s2_step; move16(); /* special case: i = 0 */ - acc = L_mult(*RZ0++, 0x4000); - acc = L_mac(acc, *RZ1++, 0x4000); + acc = L_mult( *RZ0++, 0x4000 ); + acc = L_mac( acc, *RZ1++, 0x4000 ); #ifdef BASOP_NOGLOB *RY++ = mac_r_sat( acc, *RZ2++, 0x4000 ); #else - *RY++ = mac_r(acc, *RZ2++, 0x4000); + *RY++ = mac_r( acc, *RZ2++, 0x4000 ); #endif move16(); /* first 3/12-- from 1 to (3*m/8)-1 */ - l = sub(shr(n, 3),1); /* (3*m/8) - 1 = (n/8) - 1 */ - FOR (i = 0; i < l; i++) + l = sub( shr( n, 3 ), 1 ); /* (3*m/8) - 1 = (n/8) - 1 */ + FOR( i = 0; i < l; i++ ) { - acc = L_shl(*RZ0++, 15); /* Align with the following non-fractional mode so as to gain 1 more bit headroom. */ - acc = L_mac0(acc, *RZ1, t_sin[c1_ind]); /* Non-fractional mode gains 1 more bit headroom. */ - acc = L_mac0(acc, *IZ1, t_sin[s1_ind]); - acc = L_mac0(acc, *RZ2, t_sin[c2_ind]); - acc = L_mac0(acc, *IZ2, t_sin[s2_ind]); - *RY++ = round_fx(acc); /* bit growth = 1 (compensated by non-fractional mode MAC). */ + acc = L_shl( *RZ0++, 15 ); /* Align with the following non-fractional mode so as to gain 1 more bit headroom. */ + acc = L_mac0( acc, *RZ1, t_sin[c1_ind] ); /* Non-fractional mode gains 1 more bit headroom. */ + acc = L_mac0( acc, *IZ1, t_sin[s1_ind] ); + acc = L_mac0( acc, *RZ2, t_sin[c2_ind] ); + acc = L_mac0( acc, *IZ2, t_sin[s2_ind] ); + *RY++ = round_fx( acc ); /* bit growth = 1 (compensated by non-fractional mode MAC). */ - acc = L_shl(*IZ0--, 15); - acc = L_msu0(acc, *RZ1++, t_sin[s1_ind]); - acc = L_mac0(acc, *IZ1--, t_sin[c1_ind]); - acc = L_msu0(acc, *RZ2++, t_sin[s2_ind]); - acc = L_mac0(acc, *IZ2--, t_sin[c2_ind]); - *IY-- = round_fx(acc); + acc = L_shl( *IZ0--, 15 ); + acc = L_msu0( acc, *RZ1++, t_sin[s1_ind] ); + acc = L_mac0( acc, *IZ1--, t_sin[c1_ind] ); + acc = L_msu0( acc, *RZ2++, t_sin[s2_ind] ); + acc = L_mac0( acc, *IZ2--, t_sin[c2_ind] ); + *IY-- = round_fx( acc ); - c1_ind = add(c1_ind, c1_step); - s1_ind = add(s1_ind, s1_step); - c2_ind = add(c2_ind, c2_step); - s2_ind = add(s2_ind, s2_step); + c1_ind = add( c1_ind, c1_step ); + s1_ind = add( s1_ind, s1_step ); + c2_ind = add( c2_ind, c2_step ); + s2_ind = add( s2_ind, s2_step ); } /* next 1/12-- from (3*m/8) to (4*m/8)-1 */ - l = shr(m,3); /* (4*m/8) - (3*m/8) = m/8 */ - FOR (i = 0; i < l; i++) + l = shr( m, 3 ); /* (4*m/8) - (3*m/8) = m/8 */ + FOR( i = 0; i < l; i++ ) { - acc = L_shl(*RZ0++, 15); - acc = L_mac0(acc, *RZ1, t_sin[c1_ind]); /* Non-fractional mode gains 1 more bit headroom. */ - acc = L_mac0(acc, *IZ1, t_sin[s1_ind]); - acc = L_msu0(acc, *RZ2, t_sin[c2_ind]); - acc = L_mac0(acc, *IZ2, t_sin[s2_ind]); - *RY++ = round_fx(acc); + acc = L_shl( *RZ0++, 15 ); + acc = L_mac0( acc, *RZ1, t_sin[c1_ind] ); /* Non-fractional mode gains 1 more bit headroom. */ + acc = L_mac0( acc, *IZ1, t_sin[s1_ind] ); + acc = L_msu0( acc, *RZ2, t_sin[c2_ind] ); + acc = L_mac0( acc, *IZ2, t_sin[s2_ind] ); + *RY++ = round_fx( acc ); - acc = L_shl(*IZ0--, 15); - acc = L_msu0(acc, *RZ1++, t_sin[s1_ind]); - acc = L_mac0(acc, *IZ1--, t_sin[c1_ind]); - acc = L_msu0(acc, *RZ2++, t_sin[s2_ind]); - acc = L_msu0(acc, *IZ2--, t_sin[c2_ind]); - *IY-- = round_fx(acc); + acc = L_shl( *IZ0--, 15 ); + acc = L_msu0( acc, *RZ1++, t_sin[s1_ind] ); + acc = L_mac0( acc, *IZ1--, t_sin[c1_ind] ); + acc = L_msu0( acc, *RZ2++, t_sin[s2_ind] ); + acc = L_msu0( acc, *IZ2--, t_sin[c2_ind] ); + *IY-- = round_fx( acc ); - c1_ind = add(c1_ind, c1_step); - s1_ind = add(s1_ind, s1_step); - c2_ind = sub(c2_ind, c2_step); - s2_ind = sub(s2_ind, s2_step); + c1_ind = add( c1_ind, c1_step ); + s1_ind = add( s1_ind, s1_step ); + c2_ind = sub( c2_ind, c2_step ); + s2_ind = sub( s2_ind, s2_step ); } /* special case: i = m/2 i.e. 1/3 */ - acc = L_shl(*RZ0--, 15); - acc = L_mac0(acc, *RZ1, t_sin[c1_ind]); - acc = L_msu0(acc, *RZ2, t_sin[c2_ind]); - *RY++ = round_fx(acc); + acc = L_shl( *RZ0--, 15 ); + acc = L_mac0( acc, *RZ1, t_sin[c1_ind] ); + acc = L_msu0( acc, *RZ2, t_sin[c2_ind] ); + *RY++ = round_fx( acc ); acc = 0; - acc = L_msu0(acc, *RZ1--, t_sin[s1_ind]); - acc = L_msu0(acc, *RZ2--, t_sin[s2_ind]); - *IY-- = round_fx(acc); + acc = L_msu0( acc, *RZ1--, t_sin[s1_ind] ); + acc = L_msu0( acc, *RZ2--, t_sin[s2_ind] ); + *IY-- = round_fx( acc ); IZ0++; IZ1++; IZ2++; - c1_ind = add(c1_ind, c1_step); - s1_ind = add(s1_ind, s1_step); - c2_ind = sub(c2_ind, c2_step); - s2_ind = sub(s2_ind, s2_step); + c1_ind = add( c1_ind, c1_step ); + s1_ind = add( s1_ind, s1_step ); + c2_ind = sub( c2_ind, c2_step ); + s2_ind = sub( s2_ind, s2_step ); /* next 2/12-- from ((m/2)+1) to (6*m/8)-1 */ - l = sub(shr(m,2), 1); /* (6*m/8) - ((m/2)+1) = m/4 - 1 */ - FOR (i = 0; i < l; i++) + l = sub( shr( m, 2 ), 1 ); /* (6*m/8) - ((m/2)+1) = m/4 - 1 */ + FOR( i = 0; i < l; i++ ) { - acc = L_shl(*RZ0--, 15); - acc = L_mac0(acc, *RZ1, t_sin[c1_ind]); /* Non-fractional mode gains 1 more bit headroom. */ - acc = L_msu0(acc, *IZ1, t_sin[s1_ind]); - acc = L_msu0(acc, *RZ2, t_sin[c2_ind]); - acc = L_msu0(acc, *IZ2, t_sin[s2_ind]); - *RY++ = round_fx(acc); + acc = L_shl( *RZ0--, 15 ); + acc = L_mac0( acc, *RZ1, t_sin[c1_ind] ); /* Non-fractional mode gains 1 more bit headroom. */ + acc = L_msu0( acc, *IZ1, t_sin[s1_ind] ); + acc = L_msu0( acc, *RZ2, t_sin[c2_ind] ); + acc = L_msu0( acc, *IZ2, t_sin[s2_ind] ); + *RY++ = round_fx( acc ); - acc = L_mult0(*IZ0++, -32768); - acc = L_msu0(acc, *RZ1--, t_sin[s1_ind]); - acc = L_msu0(acc, *IZ1++, t_sin[c1_ind]); - acc = L_msu0(acc, *RZ2--, t_sin[s2_ind]); - acc = L_mac0(acc, *IZ2++, t_sin[c2_ind]); - *IY-- = round_fx(acc); + acc = L_mult0( *IZ0++, -32768 ); + acc = L_msu0( acc, *RZ1--, t_sin[s1_ind] ); + acc = L_msu0( acc, *IZ1++, t_sin[c1_ind] ); + acc = L_msu0( acc, *RZ2--, t_sin[s2_ind] ); + acc = L_mac0( acc, *IZ2++, t_sin[c2_ind] ); + *IY-- = round_fx( acc ); - c1_ind = add(c1_ind, c1_step); - s1_ind = add(s1_ind, s1_step); - c2_ind = sub(c2_ind, c2_step); - s2_ind = sub(s2_ind, s2_step); + c1_ind = add( c1_ind, c1_step ); + s1_ind = add( s1_ind, s1_step ); + c2_ind = sub( c2_ind, c2_step ); + s2_ind = sub( s2_ind, s2_step ); } /*--------------------------half--------------------------// */ /* next 2/12-- from (6*m/8) to (8*m/8) - 1 */ - l = shr(m,2); - FOR (i = 0; i < l; i++) + l = shr( m, 2 ); + FOR( i = 0; i < l; i++ ) { - acc = L_shl(*RZ0--, 15); - acc = L_msu0(acc, *RZ1, t_sin[c1_ind]); /* Non-fractional mode gains 1 more bit headroom. */ - acc = L_msu0(acc, *IZ1, t_sin[s1_ind]); - acc = L_msu0(acc, *RZ2, t_sin[c2_ind]); - acc = L_mac0(acc, *IZ2, t_sin[s2_ind]); - *RY++ = round_fx(acc); + acc = L_shl( *RZ0--, 15 ); + acc = L_msu0( acc, *RZ1, t_sin[c1_ind] ); /* Non-fractional mode gains 1 more bit headroom. */ + acc = L_msu0( acc, *IZ1, t_sin[s1_ind] ); + acc = L_msu0( acc, *RZ2, t_sin[c2_ind] ); + acc = L_mac0( acc, *IZ2, t_sin[s2_ind] ); + *RY++ = round_fx( acc ); - acc = L_mult0(*IZ0++, -32768); - acc = L_msu0(acc, *RZ1--, t_sin[s1_ind]); - acc = L_mac0(acc, *IZ1++, t_sin[c1_ind]); - acc = L_mac0(acc, *RZ2--, t_sin[s2_ind]); - acc = L_mac0(acc, *IZ2++, t_sin[c2_ind]); - *IY-- = round_fx(acc); + acc = L_mult0( *IZ0++, -32768 ); + acc = L_msu0( acc, *RZ1--, t_sin[s1_ind] ); + acc = L_mac0( acc, *IZ1++, t_sin[c1_ind] ); + acc = L_mac0( acc, *RZ2--, t_sin[s2_ind] ); + acc = L_mac0( acc, *IZ2++, t_sin[c2_ind] ); + *IY-- = round_fx( acc ); - c1_ind = sub(c1_ind, c1_step); - s1_ind = sub(s1_ind, s1_step); - c2_ind = add(c2_ind, c2_step); - s2_ind = add(s2_ind, s2_step); + c1_ind = sub( c1_ind, c1_step ); + s1_ind = sub( s1_ind, s1_step ); + c2_ind = add( c2_ind, c2_step ); + s2_ind = add( s2_ind, s2_step ); } /* special case: i = m, i.e 2/3 */ - acc = L_shl(*RZ0++, 15); - acc = L_msu0(acc, *RZ1, t_sin[c1_ind]); - acc = L_msu0(acc, *RZ2, t_sin[c2_ind]); - *RY++ = round_fx(acc); - - acc = L_deposit_l(0); - acc = L_msu0(acc, *RZ1++, t_sin[s1_ind]); - acc = L_mac0(acc, *RZ2++, t_sin[s2_ind]); - *IY-- = round_fx(acc); + acc = L_shl( *RZ0++, 15 ); + acc = L_msu0( acc, *RZ1, t_sin[c1_ind] ); + acc = L_msu0( acc, *RZ2, t_sin[c2_ind] ); + *RY++ = round_fx( acc ); + + acc = L_deposit_l( 0 ); + acc = L_msu0( acc, *RZ1++, t_sin[s1_ind] ); + acc = L_mac0( acc, *RZ2++, t_sin[s2_ind] ); + *IY-- = round_fx( acc ); IZ0--; /* Just decrement the address counter */ IZ1--; IZ2--; - c1_ind = sub(c1_ind, c1_step); - s1_ind = sub(s1_ind, s1_step); - c2_ind = add(c2_ind, c2_step); - s2_ind = add(s2_ind, s2_step); + c1_ind = sub( c1_ind, c1_step ); + s1_ind = sub( s1_ind, s1_step ); + c2_ind = add( c2_ind, c2_step ); + s2_ind = add( s2_ind, s2_step ); /* next 1/12-- from (m + 1) to (9*m/8) - 1 */ - l = sub(shr(m, 3), 1); /* (9*m/8) - (m +1) = m/8 - 1 */ - FOR (i = 0; i < l; i++) + l = sub( shr( m, 3 ), 1 ); /* (9*m/8) - (m +1) = m/8 - 1 */ + FOR( i = 0; i < l; i++ ) { - acc = L_shl(*RZ0++, 15); - acc = L_msu0(acc, *RZ1, t_sin[c1_ind]); /* Non-fractional mode gains 1 more bit headroom. */ - acc = L_mac0(acc, *IZ1, t_sin[s1_ind]); - acc = L_msu0(acc, *RZ2, t_sin[c2_ind]); - acc = L_msu0(acc, *IZ2, t_sin[s2_ind]); - *RY++ = round_fx(acc); + acc = L_shl( *RZ0++, 15 ); + acc = L_msu0( acc, *RZ1, t_sin[c1_ind] ); /* Non-fractional mode gains 1 more bit headroom. */ + acc = L_mac0( acc, *IZ1, t_sin[s1_ind] ); + acc = L_msu0( acc, *RZ2, t_sin[c2_ind] ); + acc = L_msu0( acc, *IZ2, t_sin[s2_ind] ); + *RY++ = round_fx( acc ); - acc = L_shl(*IZ0--, 15); - acc = L_msu0(acc, *RZ1++, t_sin[s1_ind]); - acc = L_msu0(acc, *IZ1--, t_sin[c1_ind]); - acc = L_mac0(acc, *RZ2++, t_sin[s2_ind]); - acc = L_msu0(acc, *IZ2--, t_sin[c2_ind]); - *IY-- = round_fx(acc); + acc = L_shl( *IZ0--, 15 ); + acc = L_msu0( acc, *RZ1++, t_sin[s1_ind] ); + acc = L_msu0( acc, *IZ1--, t_sin[c1_ind] ); + acc = L_mac0( acc, *RZ2++, t_sin[s2_ind] ); + acc = L_msu0( acc, *IZ2--, t_sin[c2_ind] ); + *IY-- = round_fx( acc ); - c1_ind = sub(c1_ind, c1_step); - s1_ind = sub(s1_ind, s1_step); - c2_ind = add(c2_ind, c2_step); - s2_ind = add(s2_ind, s2_step); + c1_ind = sub( c1_ind, c1_step ); + s1_ind = sub( s1_ind, s1_step ); + c2_ind = add( c2_ind, c2_step ); + s2_ind = add( s2_ind, s2_step ); } /* last 3/12-- from (9*m/8) to (12*m/8) - 1 */ - l = shr(n,3); /* (12*m/8) - (9*m/8) = 3*m/8 = n/8 */ - FOR (i = 0; i < l; i++) + l = shr( n, 3 ); /* (12*m/8) - (9*m/8) = 3*m/8 = n/8 */ + FOR( i = 0; i < l; i++ ) { - acc = L_shl(*RZ0++, 15); - acc = L_msu0(acc, *RZ1, t_sin[c1_ind]); /* Non-fractional mode gains 1 more bit headroom. */ - acc = L_mac0(acc, *IZ1, t_sin[s1_ind]); - acc = L_mac0(acc, *RZ2, t_sin[c2_ind]); - acc = L_msu0(acc, *IZ2, t_sin[s2_ind]); - *RY++ = round_fx(acc); + acc = L_shl( *RZ0++, 15 ); + acc = L_msu0( acc, *RZ1, t_sin[c1_ind] ); /* Non-fractional mode gains 1 more bit headroom. */ + acc = L_mac0( acc, *IZ1, t_sin[s1_ind] ); + acc = L_mac0( acc, *RZ2, t_sin[c2_ind] ); + acc = L_msu0( acc, *IZ2, t_sin[s2_ind] ); + *RY++ = round_fx( acc ); - acc = L_shl(*IZ0--, 15); - acc = L_msu0(acc, *RZ1++, t_sin[s1_ind]); - acc = L_msu0(acc, *IZ1--, t_sin[c1_ind]); - acc = L_mac0(acc, *RZ2++, t_sin[s2_ind]); - acc = L_mac0(acc, *IZ2--, t_sin[c2_ind]); - *IY-- = round_fx(acc); + acc = L_shl( *IZ0--, 15 ); + acc = L_msu0( acc, *RZ1++, t_sin[s1_ind] ); + acc = L_msu0( acc, *IZ1--, t_sin[c1_ind] ); + acc = L_mac0( acc, *RZ2++, t_sin[s2_ind] ); + acc = L_mac0( acc, *IZ2--, t_sin[c2_ind] ); + *IY-- = round_fx( acc ); - c1_ind = sub(c1_ind, c1_step); - s1_ind = sub(s1_ind, s1_step); - c2_ind = sub(c2_ind, c2_step); - s2_ind = sub(s2_ind, s2_step); + c1_ind = sub( c1_ind, c1_step ); + s1_ind = sub( s1_ind, s1_step ); + c2_ind = sub( c2_ind, c2_step ); + s2_ind = sub( s2_ind, s2_step ); } /* special case: i = 3*m/2 */ - acc = L_shl(*RZ0, 15); - acc = L_msu0(acc, *RZ1, t_sin[c1_ind]); - acc = L_mac0(acc, *RZ2, t_sin[c2_ind]); - *RY = round_fx(acc); + acc = L_shl( *RZ0, 15 ); + acc = L_msu0( acc, *RZ1, t_sin[c1_ind] ); + acc = L_mac0( acc, *RZ2, t_sin[c2_ind] ); + *RY = round_fx( acc ); return; } -void ifft3_fx(const Word16 Z[], Word16 X[], const Word16 n) +void ifft3_fx( const Word16 Z[], Word16 X[], const Word16 n ) { - Word16 Y[PH_ECU_SPEC_SIZE]; + Word16 Y[PH_ECU_SPEC_SIZE]; const Word16 *t_sin = sincos_t_rad3_fx; - Word16 m, mMinus1, step, step2; - Word16 i, l; - Word16 c0_ind, s0_ind, c1_ind, s1_ind, c2_ind, s2_ind; - const Word16 *RZ0, *IZ0, *RZ1, *IZ1, *RZ2, *IZ2; + Word16 m, mMinus1, step, step2; + Word16 i, l; + Word16 c0_ind, s0_ind, c1_ind, s1_ind, c2_ind, s2_ind; + const Word16 *RZ0, *IZ0, *RZ1, *IZ1, *RZ2, *IZ2; const Word16 *RZ00, *IZ00, *RZ10, *IZ10, *RZ20, *IZ20; Word16 *RY0, *IY0, *RY1, *IY1, *RY2, *IY2, *y0, *y1, *y2, *pX; - Word32 acc; - Word16 mBy2, orderMinus1, nMinusMBy2; + Word32 acc; + Word16 mBy2, orderMinus1, nMinusMBy2; const Word16 *pPhaseTbl; /* Determine the order of the transform, the length of decimated */ /* transforms m, and the step for the sine and cosine tables. */ - SWITCH(n) + SWITCH( n ) { - case 1536: - orderMinus1 = 9-1; - move16(); - m = 512; - move16(); - step = 1; - move16(); - pPhaseTbl = FFT_W256; - BREAK; - case 384: - orderMinus1 = 7-1; - move16(); - m = 128; - move16(); - step = 4; - move16(); - pPhaseTbl = FFT_W64; - BREAK; - default: - orderMinus1 = 7-1; - move16(); - m = 128; - move16(); - step = 4; - move16(); - pPhaseTbl = FFT_W64; - BREAK; + case 1536: + orderMinus1 = 9 - 1; + move16(); + m = 512; + move16(); + step = 1; + move16(); + pPhaseTbl = FFT_W256; + BREAK; + case 384: + orderMinus1 = 7 - 1; + move16(); + m = 128; + move16(); + step = 4; + move16(); + pPhaseTbl = FFT_W64; + BREAK; + default: + orderMinus1 = 7 - 1; + move16(); + m = 128; + move16(); + step = 4; + move16(); + pPhaseTbl = FFT_W64; + BREAK; } - nMinusMBy2 = shr(sub(n, m),1); - mMinus1 = sub(m,1); + nMinusMBy2 = shr( sub( n, m ), 1 ); + mMinus1 = sub( m, 1 ); /* pointer initialization */ RY0 = &Y[0]; IY0 = &Y[m]; @@ -3053,7 +3090,7 @@ void ifft3_fx(const Word16 Z[], Word16 X[], const Word16 n) IZ10 = &IZ00[-m]; IZ20 = &IZ00[-nMinusMBy2]; - RZ0 = RZ00; /* Reset the pointers to zero positions. */ + RZ0 = RZ00; /* Reset the pointers to zero positions. */ RZ1 = RZ10; RZ2 = RZ20; IZ0 = IZ00; @@ -3063,289 +3100,289 @@ void ifft3_fx(const Word16 Z[], Word16 X[], const Word16 n) /* Inverse butterflies of order 3. */ /* Construction of Y0 */ - acc = L_mult(*RZ0++, 0x4000); - acc = L_mac(acc, *RZ1++, 0x4000); - *RY0++ = mac_r(acc, *RZ2--, 0x4000); + acc = L_mult( *RZ0++, 0x4000 ); + acc = L_mac( acc, *RZ1++, 0x4000 ); + *RY0++ = mac_r( acc, *RZ2--, 0x4000 ); move16(); IZ0--; IZ1--; IZ2++; IY0--; - l = sub(shr(m, 1), 1); - FOR (i = 0; i < l; i++) + l = sub( shr( m, 1 ), 1 ); + FOR( i = 0; i < l; i++ ) { - acc = L_mult(*RZ0++, 0x4000); - acc = L_mac(acc, *RZ1++, 0x4000); - *RY0++ = mac_r(acc, *RZ2--, 0x4000); + acc = L_mult( *RZ0++, 0x4000 ); + acc = L_mac( acc, *RZ1++, 0x4000 ); + *RY0++ = mac_r( acc, *RZ2--, 0x4000 ); move16(); - acc = L_mult(*IZ0--, 0x4000); - acc = L_mac(acc, *IZ1--, 0x4000); - *IY0-- = msu_r(acc, *IZ2++, 0x4000); + acc = L_mult( *IZ0--, 0x4000 ); + acc = L_mac( acc, *IZ1--, 0x4000 ); + *IY0-- = msu_r( acc, *IZ2++, 0x4000 ); move16(); } /* m/2 */ - acc = L_mult(*RZ0, 0x4000); - acc = L_mac(acc, *RZ1, 0x4000); - *RY0++ = mac_r(acc, *RZ2, 0x4000); + acc = L_mult( *RZ0, 0x4000 ); + acc = L_mac( acc, *RZ1, 0x4000 ); + *RY0++ = mac_r( acc, *RZ2, 0x4000 ); move16(); /* Construction of Y1 */ - c0_ind=T_SIN_PI_2; - s0_ind=0; - c1_ind=T_SIN_PI_2*1/3; - s1_ind=T_SIN_PI_2*2/3; - c2_ind=T_SIN_PI_2*1/3; - s2_ind=T_SIN_PI_2*2/3; - - RZ0 = RZ00; /* Reset pointers to zero positions. */ + c0_ind = T_SIN_PI_2; + s0_ind = 0; + c1_ind = T_SIN_PI_2 * 1 / 3; + s1_ind = T_SIN_PI_2 * 2 / 3; + c2_ind = T_SIN_PI_2 * 1 / 3; + s2_ind = T_SIN_PI_2 * 2 / 3; + + RZ0 = RZ00; /* Reset pointers to zero positions. */ RZ1 = RZ10; RZ2 = RZ20; IZ0 = IZ00; IZ1 = IZ10; IZ2 = IZ20; - acc = L_mult0(*RZ0++, t_sin[c0_ind]); - acc = L_msu0(acc, *RZ1++, t_sin[c1_ind]); - acc = L_msu0(acc, *RZ2--, t_sin[c2_ind]); + acc = L_mult0( *RZ0++, t_sin[c0_ind] ); + acc = L_msu0( acc, *RZ1++, t_sin[c1_ind] ); + acc = L_msu0( acc, *RZ2--, t_sin[c2_ind] ); IZ0--; - acc = L_msu0(acc, *IZ1--, t_sin[s1_ind]); - acc = L_msu0(acc, *IZ2++, t_sin[s2_ind]); - *RY1++ = round_fx(acc); + acc = L_msu0( acc, *IZ1--, t_sin[s1_ind] ); + acc = L_msu0( acc, *IZ2++, t_sin[s2_ind] ); + *RY1++ = round_fx( acc ); - c0_ind=sub(c0_ind,step); - s0_ind=add(s0_ind,step); - c1_ind=add(c1_ind,step); - s1_ind=sub(s1_ind,step); - c2_ind=sub(c2_ind,step); - s2_ind=add(s2_ind,step); + c0_ind = sub( c0_ind, step ); + s0_ind = add( s0_ind, step ); + c1_ind = add( c1_ind, step ); + s1_ind = sub( s1_ind, step ); + c2_ind = sub( c2_ind, step ); + s2_ind = add( s2_ind, step ); /* From 1 to (m/4) - 1. */ - l = sub(shr(m,2),1); - FOR (i = 0; i < l; i++) - { - acc = L_mult0(*RZ0, t_sin[c0_ind]); - acc = L_msu0(acc, *RZ1, t_sin[c1_ind]); - acc = L_msu0(acc, *RZ2, t_sin[c2_ind]); - acc = L_msu0(acc, *IZ0, t_sin[s0_ind]); - acc = L_msu0(acc, *IZ1, t_sin[s1_ind]); - acc = L_msu0(acc, *IZ2, t_sin[s2_ind]); - *RY1++ = round_fx(acc); - - acc = L_mult0(*IZ0--, t_sin[c0_ind]); - acc = L_msu0(acc, *IZ1--, t_sin[c1_ind]); - acc = L_mac0(acc, *IZ2++, t_sin[c2_ind]); - acc = L_mac0(acc, *RZ0++, t_sin[s0_ind]); - acc = L_mac0(acc, *RZ1++, t_sin[s1_ind]); - acc = L_msu0(acc, *RZ2--, t_sin[s2_ind]); - *IY1-- = round_fx(acc); - - c0_ind=sub(c0_ind,step); - s0_ind=add(s0_ind,step); - c1_ind=add(c1_ind,step); - s1_ind=sub(s1_ind,step); - c2_ind=sub(c2_ind,step); - s2_ind=add(s2_ind,step); + l = sub( shr( m, 2 ), 1 ); + FOR( i = 0; i < l; i++ ) + { + acc = L_mult0( *RZ0, t_sin[c0_ind] ); + acc = L_msu0( acc, *RZ1, t_sin[c1_ind] ); + acc = L_msu0( acc, *RZ2, t_sin[c2_ind] ); + acc = L_msu0( acc, *IZ0, t_sin[s0_ind] ); + acc = L_msu0( acc, *IZ1, t_sin[s1_ind] ); + acc = L_msu0( acc, *IZ2, t_sin[s2_ind] ); + *RY1++ = round_fx( acc ); + + acc = L_mult0( *IZ0--, t_sin[c0_ind] ); + acc = L_msu0( acc, *IZ1--, t_sin[c1_ind] ); + acc = L_mac0( acc, *IZ2++, t_sin[c2_ind] ); + acc = L_mac0( acc, *RZ0++, t_sin[s0_ind] ); + acc = L_mac0( acc, *RZ1++, t_sin[s1_ind] ); + acc = L_msu0( acc, *RZ2--, t_sin[s2_ind] ); + *IY1-- = round_fx( acc ); + + c0_ind = sub( c0_ind, step ); + s0_ind = add( s0_ind, step ); + c1_ind = add( c1_ind, step ); + s1_ind = sub( s1_ind, step ); + c2_ind = sub( c2_ind, step ); + s2_ind = add( s2_ind, step ); } /* From m/4 to m/2 -1. */ - l = shr(m, 2); /* m/2 - m/4 = m/4 */ - FOR (i = 0; i < l; i++) - { - acc = L_mult0(*RZ0, t_sin[c0_ind]); - acc = L_msu0(acc, *RZ1, t_sin[c1_ind]); - acc = L_mac0(acc, *RZ2, t_sin[c2_ind]); - acc = L_msu0(acc, *IZ0, t_sin[s0_ind]); - acc = L_msu0(acc, *IZ1, t_sin[s1_ind]); - acc = L_msu0(acc, *IZ2, t_sin[s2_ind]); - *RY1++ = round_fx(acc); - - acc = L_mult0(*IZ0--, t_sin[c0_ind]); - acc = L_msu0(acc, *IZ1--, t_sin[c1_ind]); - acc = L_msu0(acc, *IZ2++, t_sin[c2_ind]); - acc = L_mac0(acc, *RZ0++, t_sin[s0_ind]); - acc = L_mac0(acc, *RZ1++, t_sin[s1_ind]); - acc = L_msu0(acc, *RZ2--, t_sin[s2_ind]); - *IY1-- = round_fx(acc); - - c0_ind=sub(c0_ind,step); - s0_ind=add(s0_ind,step); - c1_ind=add(c1_ind,step); - s1_ind=sub(s1_ind,step); - c2_ind=add(c2_ind,step); - s2_ind=sub(s2_ind,step); + l = shr( m, 2 ); /* m/2 - m/4 = m/4 */ + FOR( i = 0; i < l; i++ ) + { + acc = L_mult0( *RZ0, t_sin[c0_ind] ); + acc = L_msu0( acc, *RZ1, t_sin[c1_ind] ); + acc = L_mac0( acc, *RZ2, t_sin[c2_ind] ); + acc = L_msu0( acc, *IZ0, t_sin[s0_ind] ); + acc = L_msu0( acc, *IZ1, t_sin[s1_ind] ); + acc = L_msu0( acc, *IZ2, t_sin[s2_ind] ); + *RY1++ = round_fx( acc ); + + acc = L_mult0( *IZ0--, t_sin[c0_ind] ); + acc = L_msu0( acc, *IZ1--, t_sin[c1_ind] ); + acc = L_msu0( acc, *IZ2++, t_sin[c2_ind] ); + acc = L_mac0( acc, *RZ0++, t_sin[s0_ind] ); + acc = L_mac0( acc, *RZ1++, t_sin[s1_ind] ); + acc = L_msu0( acc, *RZ2--, t_sin[s2_ind] ); + *IY1-- = round_fx( acc ); + + c0_ind = sub( c0_ind, step ); + s0_ind = add( s0_ind, step ); + c1_ind = add( c1_ind, step ); + s1_ind = sub( s1_ind, step ); + c2_ind = add( c2_ind, step ); + s2_ind = sub( s2_ind, step ); } /* m/2 */ - acc = L_mult0(*RZ0, t_sin[c0_ind]); - acc = L_msu0(acc, *RZ1, t_sin[c1_ind]); - acc = L_mac0(acc, *RZ2, t_sin[c2_ind]); - acc = L_msu0(acc, *IZ0, t_sin[s0_ind]); - acc = L_msu0(acc, *IZ1, t_sin[s1_ind]); - acc = L_msu0(acc, *IZ2, t_sin[s2_ind]); - *RY1++ = round_fx(acc); + acc = L_mult0( *RZ0, t_sin[c0_ind] ); + acc = L_msu0( acc, *RZ1, t_sin[c1_ind] ); + acc = L_mac0( acc, *RZ2, t_sin[c2_ind] ); + acc = L_msu0( acc, *IZ0, t_sin[s0_ind] ); + acc = L_msu0( acc, *IZ1, t_sin[s1_ind] ); + acc = L_msu0( acc, *IZ2, t_sin[s2_ind] ); + *RY1++ = round_fx( acc ); /* Construction of Y2 */ - c0_ind=T_SIN_PI_2; - s0_ind=0; - c1_ind=T_SIN_PI_2*1/3; - s1_ind=T_SIN_PI_2*2/3; - c2_ind=T_SIN_PI_2*1/3; - s2_ind=T_SIN_PI_2*2/3; - step2 = shl(step,1); - - RZ0 = RZ00; /* Reset pointers to zero positions. */ + c0_ind = T_SIN_PI_2; + s0_ind = 0; + c1_ind = T_SIN_PI_2 * 1 / 3; + s1_ind = T_SIN_PI_2 * 2 / 3; + c2_ind = T_SIN_PI_2 * 1 / 3; + s2_ind = T_SIN_PI_2 * 2 / 3; + step2 = shl( step, 1 ); + + RZ0 = RZ00; /* Reset pointers to zero positions. */ RZ1 = RZ10; RZ2 = RZ20; IZ0 = IZ00; IZ1 = IZ10; IZ2 = IZ20; - acc = L_mult0(*RZ0++, t_sin[c0_ind]); - acc = L_msu0(acc, *RZ1++, t_sin[c1_ind]); - acc = L_msu0(acc, *RZ2--, t_sin[c2_ind]); + acc = L_mult0( *RZ0++, t_sin[c0_ind] ); + acc = L_msu0( acc, *RZ1++, t_sin[c1_ind] ); + acc = L_msu0( acc, *RZ2--, t_sin[c2_ind] ); IZ0--; - acc = L_mac0(acc, *IZ1--, t_sin[s1_ind]); - acc = L_mac0(acc, *IZ2++, t_sin[s2_ind]); - *RY2++ = round_fx(acc); + acc = L_mac0( acc, *IZ1--, t_sin[s1_ind] ); + acc = L_mac0( acc, *IZ2++, t_sin[s2_ind] ); + *RY2++ = round_fx( acc ); - c0_ind=sub(c0_ind,step2); - s0_ind=add(s0_ind,step2); - c1_ind=sub(c1_ind,step2); - s1_ind=add(s1_ind,step2); - c2_ind=add(c2_ind,step2); - s2_ind=sub(s2_ind,step2); + c0_ind = sub( c0_ind, step2 ); + s0_ind = add( s0_ind, step2 ); + c1_ind = sub( c1_ind, step2 ); + s1_ind = add( s1_ind, step2 ); + c2_ind = add( c2_ind, step2 ); + s2_ind = sub( s2_ind, step2 ); /* From 1 to (m/8) - 1. */ - l = sub(shr(m, 3),1); /* m/8 - 1. */ - FOR (i = 0; i < l; i++) - { - acc = L_mult0(*RZ0, t_sin[c0_ind]); - acc = L_msu0(acc, *RZ1, t_sin[c1_ind]); - acc = L_msu0(acc, *RZ2, t_sin[c2_ind]); - acc = L_msu0(acc, *IZ0, t_sin[s0_ind]); - acc = L_mac0(acc, *IZ1, t_sin[s1_ind]); - acc = L_mac0(acc, *IZ2, t_sin[s2_ind]); - *RY2++ = round_fx(acc); - - acc = L_mult0(*IZ0--, t_sin[c0_ind]); - acc = L_msu0(acc, *IZ1--, t_sin[c1_ind]); - acc = L_mac0(acc, *IZ2++, t_sin[c2_ind]); - acc = L_mac0(acc, *RZ0++, t_sin[s0_ind]); - acc = L_msu0(acc, *RZ1++, t_sin[s1_ind]); - acc = L_mac0(acc, *RZ2--, t_sin[s2_ind]); - *IY2-- = round_fx(acc); - - c0_ind=sub(c0_ind,step2); - s0_ind=add(s0_ind,step2); - c1_ind=sub(c1_ind,step2); - s1_ind=add(s1_ind,step2); - c2_ind=add(c2_ind,step2); - s2_ind=sub(s2_ind,step2); + l = sub( shr( m, 3 ), 1 ); /* m/8 - 1. */ + FOR( i = 0; i < l; i++ ) + { + acc = L_mult0( *RZ0, t_sin[c0_ind] ); + acc = L_msu0( acc, *RZ1, t_sin[c1_ind] ); + acc = L_msu0( acc, *RZ2, t_sin[c2_ind] ); + acc = L_msu0( acc, *IZ0, t_sin[s0_ind] ); + acc = L_mac0( acc, *IZ1, t_sin[s1_ind] ); + acc = L_mac0( acc, *IZ2, t_sin[s2_ind] ); + *RY2++ = round_fx( acc ); + + acc = L_mult0( *IZ0--, t_sin[c0_ind] ); + acc = L_msu0( acc, *IZ1--, t_sin[c1_ind] ); + acc = L_mac0( acc, *IZ2++, t_sin[c2_ind] ); + acc = L_mac0( acc, *RZ0++, t_sin[s0_ind] ); + acc = L_msu0( acc, *RZ1++, t_sin[s1_ind] ); + acc = L_mac0( acc, *RZ2--, t_sin[s2_ind] ); + *IY2-- = round_fx( acc ); + + c0_ind = sub( c0_ind, step2 ); + s0_ind = add( s0_ind, step2 ); + c1_ind = sub( c1_ind, step2 ); + s1_ind = add( s1_ind, step2 ); + c2_ind = add( c2_ind, step2 ); + s2_ind = sub( s2_ind, step2 ); } /* From (m/8) to (m/4) - 1. */ - l = shr(m, 3); /* m/4 - m/8 = m/8 */ - FOR (i = 0; i < l; i++) - { - acc = L_mult0(*RZ0, t_sin[c0_ind]); - acc = L_mac0(acc, *RZ1, t_sin[c1_ind]); - acc = L_msu0(acc, *RZ2, t_sin[c2_ind]); - acc = L_msu0(acc, *IZ0, t_sin[s0_ind]); - acc = L_mac0(acc, *IZ1, t_sin[s1_ind]); - acc = L_mac0(acc, *IZ2, t_sin[s2_ind]); - *RY2++ = round_fx(acc); - - acc = L_mult0(*IZ0--, t_sin[c0_ind]); - acc = L_mac0(acc, *IZ1--, t_sin[c1_ind]); - acc = L_mac0(acc, *IZ2++, t_sin[c2_ind]); - acc = L_mac0(acc, *RZ0++, t_sin[s0_ind]); - acc = L_msu0(acc, *RZ1++, t_sin[s1_ind]); - acc = L_mac0(acc, *RZ2--, t_sin[s2_ind]); - *IY2-- = round_fx(acc); - - c0_ind=sub(c0_ind,step2); - s0_ind=add(s0_ind,step2); - c1_ind=add(c1_ind,step2); - s1_ind=sub(s1_ind,step2); - c2_ind=add(c2_ind,step2); - s2_ind=sub(s2_ind,step2); + l = shr( m, 3 ); /* m/4 - m/8 = m/8 */ + FOR( i = 0; i < l; i++ ) + { + acc = L_mult0( *RZ0, t_sin[c0_ind] ); + acc = L_mac0( acc, *RZ1, t_sin[c1_ind] ); + acc = L_msu0( acc, *RZ2, t_sin[c2_ind] ); + acc = L_msu0( acc, *IZ0, t_sin[s0_ind] ); + acc = L_mac0( acc, *IZ1, t_sin[s1_ind] ); + acc = L_mac0( acc, *IZ2, t_sin[s2_ind] ); + *RY2++ = round_fx( acc ); + + acc = L_mult0( *IZ0--, t_sin[c0_ind] ); + acc = L_mac0( acc, *IZ1--, t_sin[c1_ind] ); + acc = L_mac0( acc, *IZ2++, t_sin[c2_ind] ); + acc = L_mac0( acc, *RZ0++, t_sin[s0_ind] ); + acc = L_msu0( acc, *RZ1++, t_sin[s1_ind] ); + acc = L_mac0( acc, *RZ2--, t_sin[s2_ind] ); + *IY2-- = round_fx( acc ); + + c0_ind = sub( c0_ind, step2 ); + s0_ind = add( s0_ind, step2 ); + c1_ind = add( c1_ind, step2 ); + s1_ind = sub( s1_ind, step2 ); + c2_ind = add( c2_ind, step2 ); + s2_ind = sub( s2_ind, step2 ); } /* From m/4 to 3*m/8 - 1. */ - l = shr(m, 3); /* 3*m/8 - m/4 = m/8 */ - FOR (i = 0; i < l; i++) - { - acc = L_mult0(*RZ0, t_sin[c0_ind]); - acc = L_mac0(acc, *RZ1, t_sin[c1_ind]); - acc = L_msu0(acc, *RZ2, t_sin[c2_ind]); - acc = L_msu0(acc, *IZ0, t_sin[s0_ind]); - acc = L_mac0(acc, *IZ1, t_sin[s1_ind]); - acc = L_msu0(acc, *IZ2, t_sin[s2_ind]); - *RY2++ = round_fx(acc); - - acc = L_mult0(*IZ0--, t_sin[c0_ind]); - acc = L_mac0(acc, *IZ1--, t_sin[c1_ind]); - acc = L_mac0(acc, *IZ2++, t_sin[c2_ind]); - acc = L_mac0(acc, *RZ0++, t_sin[s0_ind]); - acc = L_msu0(acc, *RZ1++, t_sin[s1_ind]); - acc = L_msu0(acc, *RZ2--, t_sin[s2_ind]); - *IY2-- = round_fx(acc); - - c0_ind=sub(c0_ind,step2); - s0_ind=add(s0_ind,step2); - c1_ind=add(c1_ind,step2); - s1_ind=sub(s1_ind,step2); - c2_ind=sub(c2_ind,step2); - s2_ind=add(s2_ind,step2); + l = shr( m, 3 ); /* 3*m/8 - m/4 = m/8 */ + FOR( i = 0; i < l; i++ ) + { + acc = L_mult0( *RZ0, t_sin[c0_ind] ); + acc = L_mac0( acc, *RZ1, t_sin[c1_ind] ); + acc = L_msu0( acc, *RZ2, t_sin[c2_ind] ); + acc = L_msu0( acc, *IZ0, t_sin[s0_ind] ); + acc = L_mac0( acc, *IZ1, t_sin[s1_ind] ); + acc = L_msu0( acc, *IZ2, t_sin[s2_ind] ); + *RY2++ = round_fx( acc ); + + acc = L_mult0( *IZ0--, t_sin[c0_ind] ); + acc = L_mac0( acc, *IZ1--, t_sin[c1_ind] ); + acc = L_mac0( acc, *IZ2++, t_sin[c2_ind] ); + acc = L_mac0( acc, *RZ0++, t_sin[s0_ind] ); + acc = L_msu0( acc, *RZ1++, t_sin[s1_ind] ); + acc = L_msu0( acc, *RZ2--, t_sin[s2_ind] ); + *IY2-- = round_fx( acc ); + + c0_ind = sub( c0_ind, step2 ); + s0_ind = add( s0_ind, step2 ); + c1_ind = add( c1_ind, step2 ); + s1_ind = sub( s1_ind, step2 ); + c2_ind = sub( c2_ind, step2 ); + s2_ind = add( s2_ind, step2 ); } /* From 3*m/8 to m/2 - 1*/ - l = shr(m, 3); /* m/2 - 3*m/8 = m/8 */ - FOR (i = 0; i < l; i++) - { - acc = L_mult0(*RZ1, t_sin[c1_ind]); - acc = L_msu0(acc, *RZ0, t_sin[c0_ind]); - acc = L_msu0(acc, *RZ2, t_sin[c2_ind]); - acc = L_msu0(acc, *IZ0, t_sin[s0_ind]); - acc = L_mac0(acc, *IZ1, t_sin[s1_ind]); - acc = L_msu0(acc, *IZ2, t_sin[s2_ind]); - *RY2++ = round_fx(acc); - - acc = L_mult0(*IZ1--, t_sin[c1_ind]); - acc = L_msu0(acc, *IZ0--, t_sin[c0_ind]); - acc = L_mac0(acc, *IZ2++, t_sin[c2_ind]); - acc = L_mac0(acc, *RZ0++, t_sin[s0_ind]); - acc = L_msu0(acc, *RZ1++, t_sin[s1_ind]); - acc = L_msu0(acc, *RZ2--, t_sin[s2_ind]); - *IY2-- = round_fx(acc); - - c0_ind=add(c0_ind,step2); - s0_ind=sub(s0_ind,step2); - c1_ind=add(c1_ind,step2); - s1_ind=sub(s1_ind,step2); - c2_ind=sub(c2_ind,step2); - s2_ind=add(s2_ind,step2); + l = shr( m, 3 ); /* m/2 - 3*m/8 = m/8 */ + FOR( i = 0; i < l; i++ ) + { + acc = L_mult0( *RZ1, t_sin[c1_ind] ); + acc = L_msu0( acc, *RZ0, t_sin[c0_ind] ); + acc = L_msu0( acc, *RZ2, t_sin[c2_ind] ); + acc = L_msu0( acc, *IZ0, t_sin[s0_ind] ); + acc = L_mac0( acc, *IZ1, t_sin[s1_ind] ); + acc = L_msu0( acc, *IZ2, t_sin[s2_ind] ); + *RY2++ = round_fx( acc ); + + acc = L_mult0( *IZ1--, t_sin[c1_ind] ); + acc = L_msu0( acc, *IZ0--, t_sin[c0_ind] ); + acc = L_mac0( acc, *IZ2++, t_sin[c2_ind] ); + acc = L_mac0( acc, *RZ0++, t_sin[s0_ind] ); + acc = L_msu0( acc, *RZ1++, t_sin[s1_ind] ); + acc = L_msu0( acc, *RZ2--, t_sin[s2_ind] ); + *IY2-- = round_fx( acc ); + + c0_ind = add( c0_ind, step2 ); + s0_ind = sub( s0_ind, step2 ); + c1_ind = add( c1_ind, step2 ); + s1_ind = sub( s1_ind, step2 ); + c2_ind = sub( c2_ind, step2 ); + s2_ind = add( s2_ind, step2 ); } /* m/2 */ - acc = L_mult0(*RZ1, t_sin[c1_ind]); - acc = L_msu0(acc, *RZ0, t_sin[c0_ind]); - acc = L_msu0(acc, *RZ2, t_sin[c2_ind]); - acc = L_msu0(acc, *IZ0, t_sin[s0_ind]); - acc = L_mac0(acc, *IZ1, t_sin[s1_ind]); - acc = L_msu0(acc, *IZ2, t_sin[s2_ind]); - *RY2++ = round_fx(acc); + acc = L_mult0( *RZ1, t_sin[c1_ind] ); + acc = L_msu0( acc, *RZ0, t_sin[c0_ind] ); + acc = L_msu0( acc, *RZ2, t_sin[c2_ind] ); + acc = L_msu0( acc, *IZ0, t_sin[s0_ind] ); + acc = L_mac0( acc, *IZ1, t_sin[s1_ind] ); + acc = L_msu0( acc, *IZ2, t_sin[s2_ind] ); + *RY2++ = round_fx( acc ); /* Compute the inverse FFT for all 3 blocks. */ - RY0 = &Y[0]; /* Rewind the pointers. */ + RY0 = &Y[0]; /* Rewind the pointers. */ RY1 = &Y[m]; RY2 = &RY1[m]; - mBy2 = shr(m,1); - r_fft_fx_lc(pPhaseTbl, m, mBy2, orderMinus1, RY0, RY0, 0); /* inverse FFT */ - r_fft_fx_lc(pPhaseTbl, m, mBy2, orderMinus1, RY1, RY1, 0); /* inverse FFT */ - r_fft_fx_lc(pPhaseTbl, m, mBy2, orderMinus1, RY2, RY2, 0); /* inverse FFT */ + mBy2 = shr( m, 1 ); + r_fft_fx_lc( pPhaseTbl, m, mBy2, orderMinus1, RY0, RY0, 0 ); /* inverse FFT */ + r_fft_fx_lc( pPhaseTbl, m, mBy2, orderMinus1, RY1, RY1, 0 ); /* inverse FFT */ + r_fft_fx_lc( pPhaseTbl, m, mBy2, orderMinus1, RY2, RY2, 0 ); /* inverse FFT */ y0 = RY0; y1 = RY1; @@ -3353,7 +3390,7 @@ void ifft3_fx(const Word16 Z[], Word16 X[], const Word16 n) /* Interlacing and scaling, scale = 1/3 */ pX = X; - FOR (i = 0; i < m; i++) + FOR( i = 0; i < m; i++ ) { #ifdef BASOP_NOGLOB *pX++ = shl_sat( mult_r( *y0++, FFT3_ONE_THIRD ), 1 ); @@ -3365,9 +3402,9 @@ void ifft3_fx(const Word16 Z[], Word16 X[], const Word16 n) #else *pX++ = shl( mult_r( *y0++, FFT3_ONE_THIRD ), 1 ); move16(); - *pX++ = shl(mult_r(*y1++, FFT3_ONE_THIRD), 1); + *pX++ = shl( mult_r( *y1++, FFT3_ONE_THIRD ), 1 ); move16(); - *pX++ = shl(mult_r(*y2++, FFT3_ONE_THIRD), 1); + *pX++ = shl( mult_r( *y2++, FFT3_ONE_THIRD ), 1 ); move16(); #endif } diff --git a/lib_com/fft_rel.c b/lib_com/fft_rel.c index f16916814..0891367c6 100644 --- a/lib_com/fft_rel.c +++ b/lib_com/fft_rel.c @@ -46,11 +46,11 @@ * Local constants *---------------------------------------------------------------------*/ -#define N_MAX_FFT 1024 -#define N_MAX_DIV2 ( N_MAX_FFT >> 1 ) -#define N_MAX_DIV4 ( N_MAX_DIV2 >> 1 ) -#define INV_SQR2_FX 23170 -#define N_MAX_SAS 256 +#define N_MAX_FFT 1024 +#define N_MAX_DIV2 ( N_MAX_FFT >> 1 ) +#define N_MAX_DIV4 ( N_MAX_DIV2 >> 1 ) +#define INV_SQR2_FX 23170 +#define N_MAX_SAS 256 /*---------------------------------------------------------------------* * fft_rel() * @@ -304,181 +304,181 @@ void fft_rel( void fft_rel_fx( - Word16 x[], /* i/o: input/output vector */ - const Word16 n, /* i : vector length */ - const Word16 m /* i : log2 of vector length */ + Word16 x[], /* i/o: input/output vector */ + const Word16 n, /* i : vector length */ + const Word16 m /* i : log2 of vector length */ ) { - Word16 i, j, k, n1, n2, n4; - Word16 step; - Word16 xt, t1, t2; - Word16 *x0, *x1, *x2; - const Word16 *s, *c; - Word16 *xi2, *xi3, *xi4, *xi1; + Word16 i, j, k, n1, n2, n4; + Word16 step; + Word16 xt, t1, t2; + Word16 *x0, *x1, *x2; + const Word16 *s, *c; + Word16 *xi2, *xi3, *xi4, *xi1; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; + Flag Overflow = 0; #endif - /*-----------------------------------------------------------------* - * Digit reverse counter - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * Digit reverse counter + *-----------------------------------------------------------------*/ - j = 0; - move16(); - x0 = &x[0]; - move16(); - FOR(i = 0; i < n - 1; i++) - { - IF(LT_16(i, j)) - { - xt = x[j]; - move16(); - x[j] = *x0; - move16(); - *x0 = xt; - move16(); - } - x0++; - k = shr(n, 1); - WHILE(LE_16(k, j)) + j = 0; + move16(); + x0 = &x[0]; + move16(); + FOR( i = 0; i < n - 1; i++ ) { - j = sub(j, k); - k = shr(k, 1); + IF( LT_16( i, j ) ) + { + xt = x[j]; + move16(); + x[j] = *x0; + move16(); + *x0 = xt; + move16(); + } + x0++; + k = shr( n, 1 ); + WHILE( LE_16( k, j ) ) + { + j = sub( j, k ); + k = shr( k, 1 ); + } + j = add( j, k ); } - j = add(j, k); - } - /*-----------------------------------------------------------------* - * Length two butterflies - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * Length two butterflies + *-----------------------------------------------------------------*/ - x0 = &x[0]; - move16(); - x1 = &x[1]; - move16(); - FOR(i = 0; i < n / 2; i++) - { - xt = *x0; + x0 = &x[0]; + move16(); + x1 = &x[1]; move16(); + FOR( i = 0; i < n / 2; i++ ) + { + xt = *x0; + move16(); #ifdef BASOP_NOGLOB - *x0 = add_o(xt, *x1, &Overflow); + *x0 = add_o( xt, *x1, &Overflow ); #else - *x0 = add(xt, *x1); + *x0 = add( xt, *x1 ); #endif - move16(); + move16(); #ifdef BASOP_NOGLOB - *x1 = sub_o(xt, *x1, &Overflow); + *x1 = sub_o( xt, *x1, &Overflow ); #else - *x1 = sub(xt, *x1); + *x1 = sub( xt, *x1 ); #endif - move16(); - x0++; - x0++; - x1++; - x1++; - } + move16(); + x0++; + x0++; + x1++; + x1++; + } - /*-----------------------------------------------------------------* - * Other butterflies - * - * The implementation described in [1] has been changed by using - * table lookup for evaluating sine and cosine functions. The - * variable ind and its increment step are needed to access table - * entries. Note that this implementation assumes n4 to be so - * small that ind will never exceed the table. Thus the input - * argument n and the constant N_MAX_SAS must be set properly. - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * Other butterflies + * + * The implementation described in [1] has been changed by using + * table lookup for evaluating sine and cosine functions. The + * variable ind and its increment step are needed to access table + * entries. Note that this implementation assumes n4 to be so + * small that ind will never exceed the table. Thus the input + * argument n and the constant N_MAX_SAS must be set properly. + *-----------------------------------------------------------------*/ - n2 = 1; - move16(); - /* step = N_MAX_SAS/4; */ - FOR(k = 2; k <= m; k++) - { - n4 = n2; + n2 = 1; move16(); - n2 = shl(n4, 1); - n1 = shl(n2, 1); + /* step = N_MAX_SAS/4; */ + FOR( k = 2; k <= m; k++ ) + { + n4 = n2; + move16(); + n2 = shl( n4, 1 ); + n1 = shl( n2, 1 ); - step = N_MAX_SAS / n1; + step = N_MAX_SAS / n1; - x0 = x; - x1 = x + n2; - x2 = x + add(n2, n4); - FOR(i = 0; i < n; i += n1) - { - xt = *x0; - move16(); /* xt = x[i]; */ + x0 = x; + x1 = x + n2; + x2 = x + add( n2, n4 ); + FOR( i = 0; i < n; i += n1 ) + { + xt = *x0; + move16(); /* xt = x[i]; */ #ifdef BASOP_NOGLOB - *x0 = add_o(xt, *x1, &Overflow); -#else /* BASOP_NOGLOB */ - *x0 = add(xt, *x1); -#endif /* BASOP_NOGLOB */ - move16(); /* x[i] = xt + x[i+n2]; */ + *x0 = add_o( xt, *x1, &Overflow ); +#else /* BASOP_NOGLOB */ + *x0 = add( xt, *x1 ); +#endif /* BASOP_NOGLOB */ + move16(); /* x[i] = xt + x[i+n2]; */ #ifdef BASOP_NOGLOB - *x1 = sub_o(xt, *x1, &Overflow); -#else /* BASOP_NOGLOB */ - *x1 = sub(xt, *x1); -#endif /* BASOP_NOGLOB */ - move16(); /* x[i+n2] = xt - x[i+n2]; */ - *x2 = negate(*x2); - move16(); /* x[i+n2+n4] = -x[i+n2+n4]; */ - - - s = sincos_t_fx + step; - c = s + 64; - xi1 = x + add(i, 1); - xi3 = xi1 + n2; - xi2 = xi3 - 2; - xi4 = xi1 + sub(n1, 2); + *x1 = sub_o( xt, *x1, &Overflow ); +#else /* BASOP_NOGLOB */ + *x1 = sub( xt, *x1 ); +#endif /* BASOP_NOGLOB */ + move16(); /* x[i+n2] = xt - x[i+n2]; */ + *x2 = negate( *x2 ); + move16(); /* x[i+n2+n4] = -x[i+n2+n4]; */ + + + s = sincos_t_fx + step; + c = s + 64; + xi1 = x + add( i, 1 ); + xi3 = xi1 + n2; + xi2 = xi3 - 2; + xi4 = xi1 + sub( n1, 2 ); - FOR(j = 1; j < n4; j++) - { + FOR( j = 1; j < n4; j++ ) + { #ifdef BASOP_NOGLOB - t1 = add_o(mult_r(*xi3, *c), mult_r(*xi4, *s), &Overflow); /* t1 = *xi3**(pt_c+ind) + *xi4**(pt_s+ind); */ - t2 = sub_o(mult_r(*xi3, *s), mult_r(*xi4, *c), &Overflow); /* t2 = *xi3**(pt_s+ind) - *xi4**(pt_c+ind); */ - *xi4 = sub_o(*xi2, t2, &Overflow); -#else /* BASOP_NOGLOB */ - t1 = add(mult_r(*xi3, *c), mult_r(*xi4, *s)); /* t1 = *xi3**(pt_c+ind) + *xi4**(pt_s+ind); */ - t2 = sub(mult_r(*xi3, *s), mult_r(*xi4, *c)); /* t2 = *xi3**(pt_s+ind) - *xi4**(pt_c+ind); */ - *xi4 = sub(*xi2, t2); + t1 = add_o( mult_r( *xi3, *c ), mult_r( *xi4, *s ), &Overflow ); /* t1 = *xi3**(pt_c+ind) + *xi4**(pt_s+ind); */ + t2 = sub_o( mult_r( *xi3, *s ), mult_r( *xi4, *c ), &Overflow ); /* t2 = *xi3**(pt_s+ind) - *xi4**(pt_c+ind); */ + *xi4 = sub_o( *xi2, t2, &Overflow ); +#else /* BASOP_NOGLOB */ + t1 = add( mult_r( *xi3, *c ), mult_r( *xi4, *s ) ); /* t1 = *xi3**(pt_c+ind) + *xi4**(pt_s+ind); */ + t2 = sub( mult_r( *xi3, *s ), mult_r( *xi4, *c ) ); /* t2 = *xi3**(pt_s+ind) - *xi4**(pt_c+ind); */ + *xi4 = sub( *xi2, t2 ); #endif /* BASOP_NOGLOB */ - move16(); + move16(); #ifdef BASOP_NOGLOB - *xi3 = negate(add_o(*xi2, t2, &Overflow)); -#else /* BASOP_NOGLOB */ - *xi3 = negate(add(*xi2, t2)); + *xi3 = negate( add_o( *xi2, t2, &Overflow ) ); +#else /* BASOP_NOGLOB */ + *xi3 = negate( add( *xi2, t2 ) ); #endif /* BASOP_NOGLOB */ - move16(); + move16(); #ifdef BASOP_NOGLOB - *xi2 = sub_o(*xi1, t1, &Overflow); -#else /* BASOP_NOGLOB */ - *xi2 = sub(*xi1, t1); + *xi2 = sub_o( *xi1, t1, &Overflow ); +#else /* BASOP_NOGLOB */ + *xi2 = sub( *xi1, t1 ); #endif /* BASOP_NOGLOB */ - move16(); + move16(); #ifdef BASOP_NOGLOB - *xi1 = add_o(*xi1, t1, &Overflow); -#else /* BASOP_NOGLOB */ - *xi1 = add(*xi1, t1); + *xi1 = add_o( *xi1, t1, &Overflow ); +#else /* BASOP_NOGLOB */ + *xi1 = add( *xi1, t1 ); #endif /* BASOP_NOGLOB */ - move16(); + move16(); - xi4--; - xi2--; - xi3++; - xi1++; - c += step; - s += step; /* autoincrement by ar0 */ - } + xi4--; + xi2--; + xi3++; + xi1++; + c += step; + s += step; /* autoincrement by ar0 */ + } - x0 += n1; - x1 += n1; - x2 += n1; + x0 += n1; + x1 += n1; + x2 += n1; + } + /* step = shr(step, 1); */ } - /* step = shr(step, 1); */ - } - return; + return; } #if 0 @@ -590,13 +590,13 @@ void fft_rel_fx32( move32(); /* xt = x[i]; */ #ifdef BASOP_NOGLOB *x0 = L_add_o(xt, *x1, &Overflow); -#else /* BASOP_NOGLOB */ +#else /* BASOP_NOGLOB */ *x0 = L_add(xt, *x1); #endif /* BASOP_NOGLOB */ move32(); /* x[i] = xt + x[i+n2]; */ #ifdef BASOP_NOGLOB *x1 = L_sub_o(xt, *x1, &Overflow); -#else /* BASOP_NOGLOB */ +#else /* BASOP_NOGLOB */ *x1 = L_sub(xt, *x1); #endif /* BASOP_NOGLOB */ move32(); /* x[i+n2] = xt - x[i+n2]; */ @@ -617,7 +617,7 @@ void fft_rel_fx32( t1 = L_add_o(Mpy_32_16_1(*xi3, *c), Mpy_32_16_1(*xi4, *s), &Overflow); /* t1 = *xi3**(pt_c+ind) + *xi4**(pt_s+ind); */ t2 = L_sub_o(Mpy_32_16_1(*xi3, *s), Mpy_32_16_1(*xi4, *c), &Overflow); /* t2 = *xi3**(pt_s+ind) - *xi4**(pt_c+ind); */ *xi4 = L_sub_o(*xi2, t2, &Overflow); -#else /* BASOP_NOGLOB */ +#else /* BASOP_NOGLOB */ t1 = L_add(Mpy_32_16_1(*xi3, *c), Mpy_32_16_1(*xi4, *s)); /* t1 = *xi3**(pt_c+ind) + *xi4**(pt_s+ind); */ t2 = L_sub(Mpy_32_16_1(*xi3, *s), Mpy_32_16_1(*xi4, *c)); /* t2 = *xi3**(pt_s+ind) - *xi4**(pt_c+ind); */ *xi4 = L_sub(*xi2, t2); @@ -625,19 +625,19 @@ void fft_rel_fx32( move16(); #ifdef BASOP_NOGLOB *xi3 = L_negate(L_add_o(*xi2, t2, &Overflow)); -#else /* BASOP_NOGLOB */ +#else /* BASOP_NOGLOB */ *xi3 = L_negate(L_add(*xi2, t2)); #endif /* BASOP_NOGLOB */ move32(); #ifdef BASOP_NOGLOB *xi2 = L_sub_o(*xi1, t1, &Overflow); -#else /* BASOP_NOGLOB */ +#else /* BASOP_NOGLOB */ *xi2 = L_sub(*xi1, t1); #endif /* BASOP_NOGLOB */ move32(); #ifdef BASOP_NOGLOB *xi1 = L_add_o(*xi1, t1, &Overflow); -#else /* BASOP_NOGLOB */ +#else /* BASOP_NOGLOB */ *xi1 = L_add(*xi1, t1); #endif /* BASOP_NOGLOB */ move32(); @@ -661,7 +661,7 @@ void fft_rel_fx32( } #else void fft_rel_fx32( - Word32 x[], /* i/o: input/output vector */ + Word32 x[], /* i/o: input/output vector */ const Word16 n, /* i : vector length */ const Word16 m /* i : log2 of vector length */ ) @@ -679,50 +679,53 @@ void fft_rel_fx32( Word32 *x2even, *x2odd; Word32 temp[512]; - IF ( EQ_16(n, 128) || EQ_16(n, 256) || EQ_16(n, 512) ) + IF( EQ_16( n, 128 ) || EQ_16( n, 256 ) || EQ_16( n, 512 ) ) { idx = fft256_read_indexes; /* Combined Digit reverse counter & Length two butterflies */ - IF ( EQ_16(n, 128) ) + IF( EQ_16( n, 128 ) ) { x2 = temp; - FOR ( i = 0; i < 64; i++ ) + FOR( i = 0; i < 64; i++ ) { j = *idx++; k = *idx++; - *x2++ = L_add(x[shr(j, 1)], x[shr(k, 1)]); - *x2++ = L_sub(x[shr(j, 1)], x[shr(k, 1)]); + *x2++ = L_add( x[shr( j, 1 )], x[shr( k, 1 )] ); + *x2++ = L_sub( x[shr( j, 1 )], x[shr( k, 1 )] ); } } - ELSE IF ( EQ_16(n, 256) ) + ELSE IF( EQ_16( n, 256 ) ) { x2 = temp; - FOR ( i = 0; i < 128; i++ ) + FOR( i = 0; i < 128; i++ ) { j = *idx++; k = *idx++; - *x2++ = L_add(x[j], x[k]); - *x2++ = L_sub(x[j], x[k]); + *x2++ = L_add( x[j], x[k] ); + *x2++ = L_sub( x[j], x[k] ); } } - ELSE IF ( EQ_16(n, 512) ) + ELSE IF( EQ_16( n, 512 ) ) { x2even = temp; x2odd = temp + 256; - FOR ( i = 0; i < 128; i++ ) + FOR( i = 0; i < 128; i++ ) { - j = shl(*idx, 1); idx++; - k = shl(*idx, 1); idx++; - - *x2even++ = L_add(x[j], x[k]); - *x2even++ = L_sub(x[j], x[k]); - j++; k++; - *x2odd++ = L_add(x[j], x[k]); - *x2odd++ = L_sub(x[j], x[k]); + j = shl( *idx, 1 ); + idx++; + k = shl( *idx, 1 ); + idx++; + + *x2even++ = L_add( x[j], x[k] ); + *x2even++ = L_sub( x[j], x[k] ); + j++; + k++; + *x2odd++ = L_add( x[j], x[k] ); + *x2odd++ = L_sub( x[j], x[k] ); } } @@ -740,14 +743,14 @@ void fft_rel_fx32( x1 = x0 + 2; x2 = x; - FOR ( i = 0; i < n; i += 4 ) + FOR( i = 0; i < n; i += 4 ) { - *x2++ = L_add(*x0++, *x1); /* x[i] = xt + x[i+n2]; */ + *x2++ = L_add( *x0++, *x1 ); /* x[i] = xt + x[i+n2]; */ *x2++ = *x0; x0--; - *x2++ = L_sub(*x0, *x1); /* x[i+n2] = xt - x[i+n2]; */ + *x2++ = L_sub( *x0, *x1 ); /* x[i+n2] = xt - x[i+n2]; */ x1++; - *x2++ = L_negate(*x1); /* x[i+n2+n4] = -x[i+n2+n4]; */ + *x2++ = L_negate( *x1 ); /* x[i+n2+n4] = -x[i+n2+n4]; */ x0 += 4; x1 += 3; /* x1 has already advanced */ @@ -762,9 +765,9 @@ void fft_rel_fx32( j = 0; x0 = &x[0]; - FOR ( i = 0; i < n - 1; i++ ) + FOR( i = 0; i < n - 1; i++ ) { - IF ( LT_16(i, j) ) + IF( LT_16( i, j ) ) { xt = x[j]; x[j] = *x0; @@ -772,10 +775,10 @@ void fft_rel_fx32( } x0++; k = n / 2; - WHILE ( LE_16(k, j) ) + WHILE( LE_16( k, j ) ) { j -= k; - k = shr(k, 1); + k = shr( k, 1 ); } j += k; } @@ -786,10 +789,10 @@ void fft_rel_fx32( x0 = &x[0]; x1 = &x[1]; - FOR ( i = 0; i < n / 2; i++ ) + FOR( i = 0; i < n / 2; i++ ) { - *x1 = L_sub(*x0, *x1); - *x0 = L_sub(L_shl(*x0, 1), *x1); + *x1 = L_sub( *x0, *x1 ); + *x0 = L_sub( L_shl( *x0, 1 ), *x1 ); x0++; x0++; @@ -808,11 +811,11 @@ void fft_rel_fx32( x0 = x; x1 = x0 + 2; - FOR ( i = 0; i < n; i += 4 ) + FOR( i = 0; i < n; i += 4 ) { - *x1 = L_sub(*x0, *x1); /* x[i+n2] = xt - x[i+n2]; */ - *x0 = L_sub(L_shl(*x0, 1), *x1++); /* x[i] = xt + x[i+n2]; */ - *x1 = L_negate(*x1); /* x[i+n2+n4] = -x[i+n2+n4]; */ + *x1 = L_sub( *x0, *x1 ); /* x[i+n2] = xt - x[i+n2]; */ + *x0 = L_sub( L_shl( *x0, 1 ), *x1++ ); /* x[i] = xt + x[i+n2]; */ + *x1 = L_negate( *x1 ); /* x[i+n2+n4] = -x[i+n2+n4]; */ x0 += 4; x1 += 3; /* x1 has already advanced */ @@ -837,22 +840,22 @@ void fft_rel_fx32( step = N_MAX_DIV4; - FOR ( k = 3; k <= m; k++ ) + FOR( k = 3; k <= m; k++ ) { - step = shr(step, 1); - n4 = shl(n4, 1); - n2 = shl(n2, 1); - n1 = shl(n1, 1); + step = shr( step, 1 ); + n4 = shl( n4, 1 ); + n2 = shl( n2, 1 ); + n1 = shl( n1, 1 ); x0 = x; x1 = x0 + n2; x2 = x1 + n4; - FOR ( i = 0; i < n; i += n1 ) + FOR( i = 0; i < n; i += n1 ) { - *x1 = L_sub(*x0, *x1); /* x[i+n2] = xt - x[i+n2]; */ - *x0 = L_sub(L_shl(*x0, 1), *x1); /* x[i] = xt + x[i+n2]; */ - *x2 = L_negate(*x2); /* x[i+n2+n4] = -x[i+n2+n4]; */ + *x1 = L_sub( *x0, *x1 ); /* x[i+n2] = xt - x[i+n2]; */ + *x0 = L_sub( L_shl( *x0, 1 ), *x1 ); /* x[i] = xt + x[i+n2]; */ + *x2 = L_negate( *x2 ); /* x[i+n2+n4] = -x[i+n2+n4]; */ s = sincos_t_ext_fx; c = s + N_MAX_FFT / 4; /* 1024/4 = 256, 256/4=64 */ @@ -862,7 +865,7 @@ void fft_rel_fx32( x0 += n1; xi4 = x0; - FOR ( j = 1; j < n4; j++ ) + FOR( j = 1; j < n4; j++ ) { xi3++; xi1++; @@ -871,13 +874,13 @@ void fft_rel_fx32( c += step; s += step; /* autoincrement by ar0 */ - t1 = L_add(Mpy_32_16_1(*xi3, *c), Mpy_32_16_1(*xi4, *s)); /* t1 = *xi3**(pt_c+ind) + *xi4**(pt_s+ind); */ - t2 = L_sub(Mpy_32_16_1(*xi3, *s), Mpy_32_16_1(*xi4, *c)); /* t2 = *xi3**(pt_s+ind) - *xi4**(pt_c+ind); */ + t1 = L_add( Mpy_32_16_1( *xi3, *c ), Mpy_32_16_1( *xi4, *s ) ); /* t1 = *xi3**(pt_c+ind) + *xi4**(pt_s+ind); */ + t2 = L_sub( Mpy_32_16_1( *xi3, *s ), Mpy_32_16_1( *xi4, *c ) ); /* t2 = *xi3**(pt_s+ind) - *xi4**(pt_c+ind); */ - *xi4 = L_sub(*xi2, t2); - *xi2 = L_sub(*xi1, t1); - *xi1 = L_sub(L_shl(*xi1, 1), *xi2); - *xi3 = L_negate(L_add(L_shl(t2, 1), *xi4)); + *xi4 = L_sub( *xi2, t2 ); + *xi2 = L_sub( *xi1, t1 ); + *xi1 = L_sub( L_shl( *xi1, 1 ), *xi2 ); + *xi3 = L_negate( L_add( L_shl( t2, 1 ), *xi4 ) ); } x1 += n1; @@ -887,4 +890,4 @@ void fft_rel_fx32( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_com/fft_rel_fx.c b/lib_com/fft_rel_fx.c index 04144515d..405c500b5 100644 --- a/lib_com/fft_rel_fx.c +++ b/lib_com/fft_rel_fx.c @@ -2,10 +2,10 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include "options.h" /* Compilation switches */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "rom_com.h" /* Static table prototypes */ +#include "options.h" /* Compilation switches */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "rom_com.h" /* Static table prototypes */ #include "stl.h" #include "stdint.h" @@ -71,49 +71,49 @@ *------------------------------------------------------------------------*/ static void c_fft_fx( - const Word16 *phs_tbl, /* i : Table of phases */ - Word16 SIZE, /* i : Size of the FFT */ - Word16 NUM_STAGE, /* i : Number of stages */ - const Word16 *in_ptr, /* i : coefficients in the order re[0], re[n/2], re[1], im[1], ..., re[n/2-1], im[n/2-1] */ - Word16 *out_ptr, /* o : coefficients in the order re[0], re[n/2], re[1], im[1], ..., re[n/2-1], im[n/2-1] */ + const Word16 *phs_tbl, /* i : Table of phases */ + Word16 SIZE, /* i : Size of the FFT */ + Word16 NUM_STAGE, /* i : Number of stages */ + const Word16 *in_ptr, /* i : coefficients in the order re[0], re[n/2], re[1], im[1], ..., re[n/2-1], im[n/2-1] */ + Word16 *out_ptr, /* o : coefficients in the order re[0], re[n/2], re[1], im[1], ..., re[n/2-1], im[n/2-1] */ /* in_ptr & out_ptr must not overlap! */ - const Word16 isign) /* i : 1=fft, otherwise it is ifft*/ + const Word16 isign ) /* i : 1=fft, otherwise it is ifft*/ { Word16 i, j, k, ii, jj, kk, ji, kj; Word32 L_tmp1, L_tmp2; - Word16 tmp1,tmp2,tmp3,tmp4; + Word16 tmp1, tmp2, tmp3, tmp4; const Word16 *table_ptr; - const Word16 *input_ptr1,*input_ptr2,*input_ptr3,*input_ptr4; - Word16 shift=0; + const Word16 *input_ptr1, *input_ptr2, *input_ptr3, *input_ptr4; + Word16 shift = 0; /* Setup Reorder Variables */ table_ptr = NULL; table_ptr = FFT_REORDER_1024; - SWITCH(SIZE) - { - case 1024: - shift = 0; - BREAK; - case 512: - shift = 1; - BREAK; - case 256: - shift = 2; - BREAK; - case 128: - shift = 3; - BREAK; - case 64: - shift = 4; - BREAK; - } + SWITCH( SIZE ) + { + case 1024: + shift = 0; + BREAK; + case 512: + shift = 1; + BREAK; + case 256: + shift = 2; + BREAK; + case 128: + shift = 3; + BREAK; + case 64: + shift = 4; + BREAK; + } /* The FFT part */ - IF (isign != 0) + IF( isign != 0 ) { /* Unrolled 1st/2nd Stage * 1) to take advantage of Table Values (0 & +/- 16384) * 2) to perform reordering of Input Values */ - FOR (k = 0; k < SIZE; k += 8) + FOR( k = 0; k < SIZE; k += 8 ) { /* * This loop use: @@ -125,52 +125,52 @@ static void c_fft_fx( * is counted as a move16() */ - input_ptr1 = in_ptr + (const Word16 ) ((uintptr_t)(*table_ptr++)>>(uintptr_t)shift); + input_ptr1 = in_ptr + ( const Word16 )( (uintptr_t) ( *table_ptr++ ) >> (uintptr_t) shift ); - L_tmp1 = L_mult(*input_ptr1++, 16384); - L_tmp2 = L_mult(*input_ptr1, 16384); + L_tmp1 = L_mult( *input_ptr1++, 16384 ); + L_tmp2 = L_mult( *input_ptr1, 16384 ); - input_ptr1 = in_ptr + (const Word16)((uintptr_t)(*table_ptr++) >> (uintptr_t)shift); + input_ptr1 = in_ptr + ( const Word16 )( (uintptr_t) ( *table_ptr++ ) >> (uintptr_t) shift ); #ifdef BASOP_NOGLOB tmp1 = msu_r_sat( L_tmp1, *input_ptr1, 16384 ); - tmp3 = mac_r_sat(L_tmp1, *input_ptr1++, 16384); + tmp3 = mac_r_sat( L_tmp1, *input_ptr1++, 16384 ); #else - tmp1 = msu_r(L_tmp1, *input_ptr1, 16384); - tmp3 = mac_r(L_tmp1, *input_ptr1++, 16384); + tmp1 = msu_r( L_tmp1, *input_ptr1, 16384 ); + tmp3 = mac_r( L_tmp1, *input_ptr1++, 16384 ); #endif - input_ptr2 = in_ptr + (const Word16)((uintptr_t)(*table_ptr++) >> (uintptr_t)shift); - input_ptr3 = in_ptr + (const Word16)((uintptr_t)(*table_ptr++) >> (uintptr_t)shift); + input_ptr2 = in_ptr + ( const Word16 )( (uintptr_t) ( *table_ptr++ ) >> (uintptr_t) shift ); + input_ptr3 = in_ptr + ( const Word16 )( (uintptr_t) ( *table_ptr++ ) >> (uintptr_t) shift ); - L_tmp1 = L_mult(*input_ptr2++, 16384); + L_tmp1 = L_mult( *input_ptr2++, 16384 ); #ifdef BASOP_NOGLOB tmp2 = mac_r_sat( L_tmp1, *input_ptr3, 16384 ); - tmp4 = msu_r_sat(L_tmp1, *input_ptr3++, 16384); + tmp4 = msu_r_sat( L_tmp1, *input_ptr3++, 16384 ); #else - tmp2 = mac_r(L_tmp1, *input_ptr3, 16384); - tmp4 = msu_r(L_tmp1, *input_ptr3++, 16384); + tmp2 = mac_r( L_tmp1, *input_ptr3, 16384 ); + tmp4 = msu_r( L_tmp1, *input_ptr3++, 16384 ); #endif - L_tmp1 = L_mult(tmp3, 16384); + L_tmp1 = L_mult( tmp3, 16384 ); #ifdef BASOP_NOGLOB out_ptr[k] = mac_r_sat( L_tmp1, tmp2, 16384 ); move16(); - out_ptr[k+4] = msu_r_sat(L_tmp1, tmp2, 16384); + out_ptr[k + 4] = msu_r_sat( L_tmp1, tmp2, 16384 ); move16(); - tmp2 = mac_r_sat(L_tmp2, *input_ptr1, 16384); - tmp3 = msu_r_sat(L_tmp2, *input_ptr1, 16384); + tmp2 = mac_r_sat( L_tmp2, *input_ptr1, 16384 ); + tmp3 = msu_r_sat( L_tmp2, *input_ptr1, 16384 ); #else - out_ptr[k] = mac_r(L_tmp1, tmp2, 16384); + out_ptr[k] = mac_r( L_tmp1, tmp2, 16384 ); move16(); - out_ptr[k+4] = msu_r(L_tmp1, tmp2, 16384); + out_ptr[k + 4] = msu_r( L_tmp1, tmp2, 16384 ); move16(); - tmp2 = mac_r(L_tmp2, *input_ptr1, 16384); - tmp3 = msu_r(L_tmp2, *input_ptr1, 16384); + tmp2 = mac_r( L_tmp2, *input_ptr1, 16384 ); + tmp3 = msu_r( L_tmp2, *input_ptr1, 16384 ); #endif - L_tmp2 = L_mult(*input_ptr2, 16384); + L_tmp2 = L_mult( *input_ptr2, 16384 ); - L_tmp1 = L_mult(tmp1, 16384); + L_tmp1 = L_mult( tmp1, 16384 ); #ifdef BASOP_NOGLOB tmp1 = msu_r_sat( L_tmp2, *input_ptr3, 16384 ); out_ptr[k + 2] = mac_r_sat( L_tmp1, tmp1, 16384 ); @@ -178,74 +178,74 @@ static void c_fft_fx( out_ptr[k + 6] = msu_r_sat( L_tmp1, tmp1, 16384 ); move16(); #else - tmp1 = msu_r(L_tmp2, *input_ptr3, 16384); - out_ptr[k+2] = mac_r(L_tmp1, tmp1, 16384); + tmp1 = msu_r( L_tmp2, *input_ptr3, 16384 ); + out_ptr[k + 2] = mac_r( L_tmp1, tmp1, 16384 ); move16(); - out_ptr[k+6] = msu_r(L_tmp1, tmp1, 16384); + out_ptr[k + 6] = msu_r( L_tmp1, tmp1, 16384 ); move16(); #endif - L_tmp1 = L_mult(tmp2, 16384); + L_tmp1 = L_mult( tmp2, 16384 ); #ifdef BASOP_NOGLOB tmp2 = mac_r_sat( L_tmp2, *input_ptr3, 16384 ); - out_ptr[k+1] = mac_r_sat(L_tmp1, tmp2, 16384); + out_ptr[k + 1] = mac_r_sat( L_tmp1, tmp2, 16384 ); move16(); - out_ptr[k+5] = msu_r_sat(L_tmp1, tmp2, 16384); + out_ptr[k + 5] = msu_r_sat( L_tmp1, tmp2, 16384 ); move16(); #else - tmp2 = mac_r(L_tmp2, *input_ptr3, 16384); - out_ptr[k+1] = mac_r(L_tmp1, tmp2, 16384); + tmp2 = mac_r( L_tmp2, *input_ptr3, 16384 ); + out_ptr[k + 1] = mac_r( L_tmp1, tmp2, 16384 ); move16(); - out_ptr[k+5] = msu_r(L_tmp1, tmp2, 16384); + out_ptr[k + 5] = msu_r( L_tmp1, tmp2, 16384 ); move16(); #endif - L_tmp1 = L_mult(tmp3, 16384); + L_tmp1 = L_mult( tmp3, 16384 ); #ifdef BASOP_NOGLOB out_ptr[k + 3] = msu_r_sat( L_tmp1, tmp4, 16384 ); move16(); - out_ptr[k+7] = mac_r_sat(L_tmp1, tmp4, 16384); + out_ptr[k + 7] = mac_r_sat( L_tmp1, tmp4, 16384 ); move16(); #else - out_ptr[k+3] = msu_r(L_tmp1, tmp4, 16384); + out_ptr[k + 3] = msu_r( L_tmp1, tmp4, 16384 ); move16(); - out_ptr[k+7] = mac_r(L_tmp1, tmp4, 16384); + out_ptr[k + 7] = mac_r( L_tmp1, tmp4, 16384 ); move16(); #endif } /* Remaining Stages */ - FOR (i = 2; i < NUM_STAGE; i++) + FOR( i = 2; i < NUM_STAGE; i++ ) { /* i is stage counter */ - jj = shl(2, i); /* FFT size */ - kk = shl(jj, 1); /* 2 * FFT size */ - ii = shr(SIZE, i); + jj = shl( 2, i ); /* FFT size */ + kk = shl( jj, 1 ); /* 2 * FFT size */ + ii = shr( SIZE, i ); ji = 0; - move16(); /* ji is phase table index */ + move16(); /* ji is phase table index */ - FOR (j = 0; j < jj; j += 2) + FOR( j = 0; j < jj; j += 2 ) { /* j is sample counter */ - FOR (k = j; k < SIZE; k += kk) + FOR( k = j; k < SIZE; k += kk ) { /* k is butterfly top */ - kj = add(k, jj); /* kj is butterfly bottom */ + kj = add( k, jj ); /* kj is butterfly bottom */ /* Butterfly computations */ - L_tmp1 = L_msu(L_mult(*(out_ptr + kj), phs_tbl[ji]), - *(out_ptr + kj + 1), phs_tbl[ji + 1]); - L_tmp2 = L_mac(L_mult(*(out_ptr + kj + 1), phs_tbl[ji]), - *(out_ptr + kj), phs_tbl[ji + 1]); + L_tmp1 = L_msu( L_mult( *( out_ptr + kj ), phs_tbl[ji] ), + *( out_ptr + kj + 1 ), phs_tbl[ji + 1] ); + L_tmp2 = L_mac( L_mult( *( out_ptr + kj + 1 ), phs_tbl[ji] ), + *( out_ptr + kj ), phs_tbl[ji + 1] ); - out_ptr[kj] = mac_r(L_negate(L_tmp1), out_ptr[k], 16384); + out_ptr[kj] = mac_r( L_negate( L_tmp1 ), out_ptr[k], 16384 ); move16(); - out_ptr[kj+1] = mac_r(L_negate(L_tmp2), out_ptr[k+1], 16384); + out_ptr[kj + 1] = mac_r( L_negate( L_tmp2 ), out_ptr[k + 1], 16384 ); move16(); - out_ptr[k] = mac_r(L_tmp1, out_ptr[k], 16384); + out_ptr[k] = mac_r( L_tmp1, out_ptr[k], 16384 ); move16(); - out_ptr[k+1] = mac_r(L_tmp2, out_ptr[k+1], 16384); + out_ptr[k + 1] = mac_r( L_tmp2, out_ptr[k + 1], 16384 ); move16(); } - ji = add(ji, ii); + ji = add( ji, ii ); } } } @@ -255,7 +255,7 @@ static void c_fft_fx( * 1) to take advantage of Table Values (0 & +/- 16384) * 2) to perform reordering of Input Values */ - FOR (k = 0; k < SIZE; k += 8) + FOR( k = 0; k < SIZE; k += 8 ) { /* * This loop use: @@ -266,100 +266,100 @@ static void c_fft_fx( * The addition of 'in_ptr' + and index value from 'reorder_ptr' * is counted as a move16() */ - input_ptr1= in_ptr + (const Word16)((uintptr_t)(*table_ptr++) >> (uintptr_t)shift); - input_ptr2 = in_ptr + (const Word16)((uintptr_t)(*table_ptr++) >> (uintptr_t)shift); + input_ptr1 = in_ptr + ( const Word16 )( (uintptr_t) ( *table_ptr++ ) >> (uintptr_t) shift ); + input_ptr2 = in_ptr + ( const Word16 )( (uintptr_t) ( *table_ptr++ ) >> (uintptr_t) shift ); - input_ptr3 = in_ptr + (const Word16)((uintptr_t)(*table_ptr++) >> (uintptr_t)shift); - input_ptr4 = in_ptr + (const Word16)((uintptr_t)(*table_ptr++) >> (uintptr_t)shift); + input_ptr3 = in_ptr + ( const Word16 )( (uintptr_t) ( *table_ptr++ ) >> (uintptr_t) shift ); + input_ptr4 = in_ptr + ( const Word16 )( (uintptr_t) ( *table_ptr++ ) >> (uintptr_t) shift ); - tmp3 = sub(*input_ptr1, *input_ptr2); - tmp4 = add(*input_ptr1++, *input_ptr2++); + tmp3 = sub( *input_ptr1, *input_ptr2 ); + tmp4 = add( *input_ptr1++, *input_ptr2++ ); - tmp2 = sub(input_ptr3[0], input_ptr4[0]); - tmp1 = sub(input_ptr3[1], input_ptr4[1]); + tmp2 = sub( input_ptr3[0], input_ptr4[0] ); + tmp1 = sub( input_ptr3[1], input_ptr4[1] ); - out_ptr[k+2] = sub(tmp3, tmp1); + out_ptr[k + 2] = sub( tmp3, tmp1 ); move16(); - out_ptr[k+6] = add(tmp3, tmp1); + out_ptr[k + 6] = add( tmp3, tmp1 ); move16(); - tmp1 = sub(*input_ptr1, *input_ptr2); - out_ptr[k+3] = add(tmp1, tmp2); + tmp1 = sub( *input_ptr1, *input_ptr2 ); + out_ptr[k + 3] = add( tmp1, tmp2 ); move16(); - out_ptr[k+7] = sub(tmp1, tmp2); + out_ptr[k + 7] = sub( tmp1, tmp2 ); move16(); - tmp1 = add(input_ptr3[0], input_ptr4[0]); - tmp3 = add(input_ptr3[1], input_ptr4[1]); + tmp1 = add( input_ptr3[0], input_ptr4[0] ); + tmp3 = add( input_ptr3[1], input_ptr4[1] ); - out_ptr[k] = add(tmp4, tmp1); + out_ptr[k] = add( tmp4, tmp1 ); move16(); - out_ptr[k+4] = sub(tmp4, tmp1); + out_ptr[k + 4] = sub( tmp4, tmp1 ); move16(); - tmp4 = add(*input_ptr1, *input_ptr2); - out_ptr[k+1] = add(tmp4, tmp3); + tmp4 = add( *input_ptr1, *input_ptr2 ); + out_ptr[k + 1] = add( tmp4, tmp3 ); move16(); - out_ptr[k+5] = sub(tmp4, tmp3); + out_ptr[k + 5] = sub( tmp4, tmp3 ); move16(); } - table_ptr = phs_tbl + SIZE; /* access part of table that is scaled by 2 */ + table_ptr = phs_tbl + SIZE; /* access part of table that is scaled by 2 */ /* Remaining Stages */ - FOR (i = 2; i < NUM_STAGE; i++) + FOR( i = 2; i < NUM_STAGE; i++ ) { /* i is stage counter */ - jj = shl(2, i); /* FFT size */ - kk = shl(jj, 1); /* 2 * FFT size */ - ii = shr(SIZE, i); + jj = shl( 2, i ); /* FFT size */ + kk = shl( jj, 1 ); /* 2 * FFT size */ + ii = shr( SIZE, i ); ji = 0; - move16(); /* ji is phase table index */ + move16(); /* ji is phase table index */ - FOR (j = 0; j < jj; j += 2) + FOR( j = 0; j < jj; j += 2 ) { /* j is sample counter */ /* This can be computed by successive add_fxitions of ii to ji, starting from 0 hence line-count it as a one-line add (still need to increment op count!!) */ - FOR (k = j; k < SIZE; k += kk) + FOR( k = j; k < SIZE; k += kk ) { /* k is butterfly top */ - kj = add(k, jj); /* kj is butterfly bottom */ + kj = add( k, jj ); /* kj is butterfly bottom */ /* Butterfly computations */ #ifdef BASOP_NOGLOB - tmp1 = mac_r_sat(L_mult_sat(out_ptr[kj], table_ptr[ji]), out_ptr[kj+1], table_ptr[ji + 1]); + tmp1 = mac_r_sat( L_mult_sat( out_ptr[kj], table_ptr[ji] ), out_ptr[kj + 1], table_ptr[ji + 1] ); - tmp2 = msu_r_sat(L_mult_sat(out_ptr[kj+1], table_ptr[ji]), out_ptr[kj], table_ptr[ji+1]); + tmp2 = msu_r_sat( L_mult_sat( out_ptr[kj + 1], table_ptr[ji] ), out_ptr[kj], table_ptr[ji + 1] ); - out_ptr[kj] = sub_sat(out_ptr[k], tmp1); + out_ptr[kj] = sub_sat( out_ptr[k], tmp1 ); move16(); - out_ptr[kj+1] = sub_sat(out_ptr[k+1], tmp2); + out_ptr[kj + 1] = sub_sat( out_ptr[k + 1], tmp2 ); move16(); - out_ptr[k] = add_sat(out_ptr[k], tmp1); + out_ptr[k] = add_sat( out_ptr[k], tmp1 ); move16(); - out_ptr[k+1] = add_sat(out_ptr[k+1], tmp2); + out_ptr[k + 1] = add_sat( out_ptr[k + 1], tmp2 ); move16(); #else - tmp1 = mac_r(L_mult(out_ptr[kj], table_ptr[ji]), - out_ptr[kj+1], table_ptr[ji + 1]); + tmp1 = mac_r( L_mult( out_ptr[kj], table_ptr[ji] ), + out_ptr[kj + 1], table_ptr[ji + 1] ); - tmp2 = msu_r(L_mult(out_ptr[kj+1], table_ptr[ji]), - out_ptr[kj], table_ptr[ji+1]); + tmp2 = msu_r( L_mult( out_ptr[kj + 1], table_ptr[ji] ), + out_ptr[kj], table_ptr[ji + 1] ); - out_ptr[kj] = sub(out_ptr[k], tmp1); + out_ptr[kj] = sub( out_ptr[k], tmp1 ); move16(); - out_ptr[kj+1] = sub(out_ptr[k+1], tmp2); + out_ptr[kj + 1] = sub( out_ptr[k + 1], tmp2 ); move16(); - out_ptr[k] = add(out_ptr[k], tmp1); + out_ptr[k] = add( out_ptr[k], tmp1 ); move16(); - out_ptr[k+1] = add(out_ptr[k+1], tmp2); + out_ptr[k + 1] = add( out_ptr[k + 1], tmp2 ); move16(); #endif } - ji = add(ji, ii); + ji = add( ji, ii ); } } } @@ -371,13 +371,13 @@ static void c_fft_fx( * Perform FFT fixed-point for real-valued sequences of length 32, 64 or 128 *--------------------------------------------------------------------------------*/ void r_fft_fx_lc( - const Word16 *phs_tbl, /* i : Table of phase */ - const Word16 SIZE, /* i : Size of the FFT */ - const Word16 SIZE2, /* i : Size / 2 */ - const Word16 NUM_STAGE, /* i : Number of stage */ - const Word16 *in_ptr, /* i : coefficients in the order re[0], re[1], ... re[n/2], im[n/2-1], im[n/2-2], ..., im[1] */ - Word16 *out_ptr, /* o : coefficients in the order re[0], re[1], ... re[n/2], im[n/2-1], im[n/2-2], ..., im[1] */ - const Word16 isign /* i : 1=fft, otherwize it's ifft */ + const Word16 *phs_tbl, /* i : Table of phase */ + const Word16 SIZE, /* i : Size of the FFT */ + const Word16 SIZE2, /* i : Size / 2 */ + const Word16 NUM_STAGE, /* i : Number of stage */ + const Word16 *in_ptr, /* i : coefficients in the order re[0], re[1], ... re[n/2], im[n/2-1], im[n/2-2], ..., im[1] */ + Word16 *out_ptr, /* o : coefficients in the order re[0], re[1], ... re[n/2], im[n/2-1], im[n/2-2], ..., im[1] */ + const Word16 isign /* i : 1=fft, otherwize it's ifft */ ) { Word16 tmp2_real, tmp2_imag; @@ -386,43 +386,43 @@ void r_fft_fx_lc( Word32 Ltmp1; const Word16 *phstbl_ptrDn; Word16 *ptrDn; - Word16 temp[1024]; /* Accommodates real input FFT size up to 1024. */ + Word16 temp[1024]; /* Accommodates real input FFT size up to 1024. */ /* Setup Pointers */ - phstbl_ptrDn = &phs_tbl[SIZE-1]; + phstbl_ptrDn = &phs_tbl[SIZE - 1]; /* The FFT part */ - IF (isign != 0) + IF( isign != 0 ) { Word16 *ptRealUp, *ptRealDn, *ptImaUp, *ptImaDn; /* Perform the complex FFT */ - c_fft_fx(phs_tbl, SIZE, NUM_STAGE, in_ptr, temp, isign); + c_fft_fx( phs_tbl, SIZE, NUM_STAGE, in_ptr, temp, isign ); /* First, handle the DC and foldover frequencies */ - out_ptr[SIZE2] = sub(temp[0], temp[1]); + out_ptr[SIZE2] = sub( temp[0], temp[1] ); move16(); - out_ptr[0] = sub(add(temp[0], temp[1]), shr(NUM_STAGE, 1)); - move16();/* DC have a small offset */ + out_ptr[0] = sub( add( temp[0], temp[1] ), shr( NUM_STAGE, 1 ) ); + move16(); /* DC have a small offset */ - ptrDn = &temp[SIZE-1]; + ptrDn = &temp[SIZE - 1]; - ptImaDn = &out_ptr[SIZE-1]; + ptImaDn = &out_ptr[SIZE - 1]; ptRealUp = &out_ptr[1]; - ptImaUp = &out_ptr[SIZE2+1]; - ptRealDn = &out_ptr[SIZE2-1]; + ptImaUp = &out_ptr[SIZE2 + 1]; + ptRealDn = &out_ptr[SIZE2 - 1]; /* Now, handle the remaining positive frequencies */ - FOR (i = 2; i <= SIZE2; i += 2) + FOR( i = 2; i <= SIZE2; i += 2 ) { - Ltmp1_imag = L_mult(temp[i+1], 16384); + Ltmp1_imag = L_mult( temp[i + 1], 16384 ); #ifdef BASOP_NOGLOB Ltmp1_imag = L_msu_sat( Ltmp1_imag, *ptrDn, 16384 ); tmp2_real = add_sat( temp[i + 1], *ptrDn-- ); - Ltmp1_real = L_mult(temp[i], 16384); + Ltmp1_real = L_mult( temp[i], 16384 ); Ltmp1_real = L_mac_sat( Ltmp1_real, *ptrDn, 16384 ); - tmp2_imag = sub(*ptrDn--, temp[i]); + tmp2_imag = sub( *ptrDn--, temp[i] ); *ptRealUp++ = msu_r_sat( L_mac_sat( Ltmp1_real, tmp2_real, phs_tbl[i] ), tmp2_imag, phs_tbl[i + 1] ); @@ -436,23 +436,23 @@ void r_fft_fx_lc( *ptRealDn-- = mac_r_sat( Ltmp1_real, tmp2_real, *phstbl_ptrDn-- ); move16(); #else - Ltmp1_imag = L_msu(Ltmp1_imag, *ptrDn, 16384); - tmp2_real = add(temp[i+1], *ptrDn--); + Ltmp1_imag = L_msu( Ltmp1_imag, *ptrDn, 16384 ); + tmp2_real = add( temp[i + 1], *ptrDn-- ); - Ltmp1_real = L_mult(temp[i], 16384); - Ltmp1_real = L_mac(Ltmp1_real, *ptrDn, 16384); - tmp2_imag = sub(*ptrDn--, temp[i]); + Ltmp1_real = L_mult( temp[i], 16384 ); + Ltmp1_real = L_mac( Ltmp1_real, *ptrDn, 16384 ); + tmp2_imag = sub( *ptrDn--, temp[i] ); - *ptRealUp++ = msu_r(L_mac(Ltmp1_real, tmp2_real, phs_tbl[i]), tmp2_imag, phs_tbl[i+1]); + *ptRealUp++ = msu_r( L_mac( Ltmp1_real, tmp2_real, phs_tbl[i] ), tmp2_imag, phs_tbl[i + 1] ); move16(); - *ptImaDn-- = mac_r(L_mac(Ltmp1_imag, tmp2_imag, phs_tbl[i]), tmp2_real, phs_tbl[i+1]); + *ptImaDn-- = mac_r( L_mac( Ltmp1_imag, tmp2_imag, phs_tbl[i] ), tmp2_real, phs_tbl[i + 1] ); move16(); - Ltmp1 = L_mac(L_negate(Ltmp1_imag), tmp2_real, *phstbl_ptrDn); - Ltmp1_real = L_mac(Ltmp1_real, tmp2_imag, *phstbl_ptrDn--); - *ptImaUp++ = msu_r(Ltmp1, tmp2_imag, *phstbl_ptrDn); + Ltmp1 = L_mac( L_negate( Ltmp1_imag ), tmp2_real, *phstbl_ptrDn ); + Ltmp1_real = L_mac( Ltmp1_real, tmp2_imag, *phstbl_ptrDn-- ); + *ptImaUp++ = msu_r( Ltmp1, tmp2_imag, *phstbl_ptrDn ); move16(); - *ptRealDn-- = mac_r(Ltmp1_real, tmp2_real, *phstbl_ptrDn--); + *ptRealDn-- = mac_r( Ltmp1_real, tmp2_real, *phstbl_ptrDn-- ); move16(); #endif } @@ -462,25 +462,25 @@ void r_fft_fx_lc( const Word16 *ptRealUp, *ptRealDn, *ptImaUp, *ptImaDn; /* First, handle the DC and foldover frequencies */ - Ltmp1 = L_mult(in_ptr[0], 16384); - temp[0] = mac_r(Ltmp1, in_ptr[SIZE2], 16384); + Ltmp1 = L_mult( in_ptr[0], 16384 ); + temp[0] = mac_r( Ltmp1, in_ptr[SIZE2], 16384 ); move16(); - temp[1] = msu_r(Ltmp1, in_ptr[SIZE2], 16384); + temp[1] = msu_r( Ltmp1, in_ptr[SIZE2], 16384 ); move16(); - ptrDn = &temp[SIZE-1]; + ptrDn = &temp[SIZE - 1]; /* Here we cast to Word16 * from a const Word16 *. */ /* This is ok because we use these pointers for */ /* reading only. This is just to avoid declaring a */ /* bunch of 4 other pointer with const Word16 *. */ - ptImaDn = &in_ptr[SIZE-1]; + ptImaDn = &in_ptr[SIZE - 1]; ptRealUp = &in_ptr[1]; - ptImaUp = &in_ptr[SIZE2+1]; - ptRealDn = &in_ptr[SIZE2-1]; + ptImaUp = &in_ptr[SIZE2 + 1]; + ptRealDn = &in_ptr[SIZE2 - 1]; /* Now, handle the remaining positive frequencies */ - FOR (i = 2; i <= SIZE2; i += 2) + FOR( i = 2; i <= SIZE2; i += 2 ) { #ifdef BASOP_NOGLOB Ltmp1_imag = L_mult( *ptImaDn, 16384 ); @@ -500,28 +500,28 @@ void r_fft_fx_lc( *ptrDn-- = msu_r_sat( Ltmp1_real, tmp2_real, *phstbl_ptrDn-- ); move16(); #else - Ltmp1_imag = L_mult(*ptImaDn, 16384); - Ltmp1_imag = L_msu(Ltmp1_imag, *ptImaUp, 16384); - tmp2_real = add(*ptImaDn--, *ptImaUp++); - Ltmp1_real = L_mult(*ptRealUp, 16384); - Ltmp1_real = L_mac(Ltmp1_real, *ptRealDn, 16384); - tmp2_imag = sub(*ptRealUp++, *ptRealDn--); + Ltmp1_imag = L_mult( *ptImaDn, 16384 ); + Ltmp1_imag = L_msu( Ltmp1_imag, *ptImaUp, 16384 ); + tmp2_real = add( *ptImaDn--, *ptImaUp++ ); + Ltmp1_real = L_mult( *ptRealUp, 16384 ); + Ltmp1_real = L_mac( Ltmp1_real, *ptRealDn, 16384 ); + tmp2_imag = sub( *ptRealUp++, *ptRealDn-- ); - temp[i] = mac_r(L_msu(Ltmp1_real, tmp2_real, phs_tbl[i]), tmp2_imag, phs_tbl[i+1]); + temp[i] = mac_r( L_msu( Ltmp1_real, tmp2_real, phs_tbl[i] ), tmp2_imag, phs_tbl[i + 1] ); move16(); - temp[i+1] = mac_r(L_mac(Ltmp1_imag, tmp2_imag, phs_tbl[i]), tmp2_real, phs_tbl[i+1]); + temp[i + 1] = mac_r( L_mac( Ltmp1_imag, tmp2_imag, phs_tbl[i] ), tmp2_real, phs_tbl[i + 1] ); move16(); - Ltmp1 = L_mac(L_negate(Ltmp1_imag), tmp2_real, *phstbl_ptrDn); - Ltmp1_real = L_msu(Ltmp1_real, tmp2_imag, *phstbl_ptrDn--); - *ptrDn-- = msu_r(Ltmp1, tmp2_imag, *phstbl_ptrDn); + Ltmp1 = L_mac( L_negate( Ltmp1_imag ), tmp2_real, *phstbl_ptrDn ); + Ltmp1_real = L_msu( Ltmp1_real, tmp2_imag, *phstbl_ptrDn-- ); + *ptrDn-- = msu_r( Ltmp1, tmp2_imag, *phstbl_ptrDn ); move16(); - *ptrDn-- = msu_r(Ltmp1_real, tmp2_real, *phstbl_ptrDn--); + *ptrDn-- = msu_r( Ltmp1_real, tmp2_real, *phstbl_ptrDn-- ); move16(); #endif } /* Perform the complex ifFT */ - c_fft_fx(phs_tbl, SIZE, NUM_STAGE, temp, out_ptr, isign); + c_fft_fx( phs_tbl, SIZE, NUM_STAGE, temp, out_ptr, isign ); } } diff --git a/lib_com/fill_spectrum.c b/lib_com/fill_spectrum.c index 2fd58ade8..187ee475d 100644 --- a/lib_com/fill_spectrum.c +++ b/lib_com/fill_spectrum.c @@ -532,261 +532,260 @@ void ivas_fill_spectrum_fx( #endif void fill_spectrum_fx( - Word16 *coeff, /* i/o: normalized MLT spectrum / nf spectrum Q12 */ - Word32 *L_coeff_out, /* i/o: Noisefilled MLT spectrum Q12 */ - const Word16 *R, /* i : number of pulses per band Q0 */ - const Word16 is_transient, /* i : transient flag Q0 */ - Word16 norm[], /* i : quantization indices for norms Q0 */ - const Word16 *hq_generic_fenv, /* i : HQ GENERIC envelope Q1 */ - const Word16 hq_generic_offset, /* i : HQ GENERIC offset Q0 */ - const Word16 nf_idx, /* i : noise fill index Q0 */ - const Word16 length, /* i : Length of spectrum (32 or 48 kHz) Q0 */ - const Word16 env_stab, /* i : Envelope stability measure [0..1] Q15 */ - Word16 *no_att_hangover, /* i/o: Frame counter for attenuation hangover Q0 */ - Word32 *L_energy_lt, /* i/o: Long-term energy measure for transient detection Q13 */ - Word16 *bwe_seed, /* i/o: random seed for generating BWE input Q0 */ - const Word16 hq_generic_exc_clas, /* i : BWE excitation class Q0 */ - const Word16 core_sfm, /* i : index of the end band for core Q0 */ - const Word16 HQ_mode, /* i : HQ mode Q0 */ - Word16 noise_level[], /* i : noise levels for harmonic modes Q15 */ - const Word32 L_core_brate, /* i : target bit-rate Q0 */ - Word16 prev_noise_level[], /* i/o: noise factor in previous frame Q15 */ - Word16 *prev_R, /* i/o: bit allocation info. in previous frame Q0 */ - Word32 *prev_coeff_out, /* i/o: decoded spectrum in previous frame Q12 */ - const Word16 *peak_idx, /* i : peak indices for hvq Q0 */ - const Word16 Npeaks, /* i : number of peaks in hvq Q0 */ - const Word16 *npulses, /* i : number of pulses per band Q0 */ - const Word16 prev_is_transient, /* i : previous transient flag Q0 */ - Word32 *prev_normq, /* i/o: previous norms Q14 */ - Word32 *prev_env, /* i/o: previous noise envelopes Q(prev_env_Q) */ - const Word16 prev_bfi, /* i : previous bad frame indicator Q0 */ - const Word16 *sfmsize, /* i : Length of bands Q0 */ - const Word16 *sfm_start, /* i : Start of bands Q0 */ - const Word16 *sfm_end, /* i : End of bands Q0 */ - Word16 *prev_L_swb_norm, /* i/o: HVQ/Harmonic mode normalization length Q0 */ - const Word16 prev_hq_mode, /* i : Previous HQ mode Q0 */ - const Word16 num_sfm, /* i : Total number of bands Q0 */ - Word16 *prev_env_Q, - const Word16 num_env_bands, /* i : Number sub bands to be encoded for HQ_GEN Q0 */ - const Word16 element_mode /* i : IVAS element mode */ + Word16 *coeff, /* i/o: normalized MLT spectrum / nf spectrum Q12 */ + Word32 *L_coeff_out, /* i/o: Noisefilled MLT spectrum Q12 */ + const Word16 *R, /* i : number of pulses per band Q0 */ + const Word16 is_transient, /* i : transient flag Q0 */ + Word16 norm[], /* i : quantization indices for norms Q0 */ + const Word16 *hq_generic_fenv, /* i : HQ GENERIC envelope Q1 */ + const Word16 hq_generic_offset, /* i : HQ GENERIC offset Q0 */ + const Word16 nf_idx, /* i : noise fill index Q0 */ + const Word16 length, /* i : Length of spectrum (32 or 48 kHz) Q0 */ + const Word16 env_stab, /* i : Envelope stability measure [0..1] Q15 */ + Word16 *no_att_hangover, /* i/o: Frame counter for attenuation hangover Q0 */ + Word32 *L_energy_lt, /* i/o: Long-term energy measure for transient detection Q13 */ + Word16 *bwe_seed, /* i/o: random seed for generating BWE input Q0 */ + const Word16 hq_generic_exc_clas, /* i : BWE excitation class Q0 */ + const Word16 core_sfm, /* i : index of the end band for core Q0 */ + const Word16 HQ_mode, /* i : HQ mode Q0 */ + Word16 noise_level[], /* i : noise levels for harmonic modes Q15 */ + const Word32 L_core_brate, /* i : target bit-rate Q0 */ + Word16 prev_noise_level[], /* i/o: noise factor in previous frame Q15 */ + Word16 *prev_R, /* i/o: bit allocation info. in previous frame Q0 */ + Word32 *prev_coeff_out, /* i/o: decoded spectrum in previous frame Q12 */ + const Word16 *peak_idx, /* i : peak indices for hvq Q0 */ + const Word16 Npeaks, /* i : number of peaks in hvq Q0 */ + const Word16 *npulses, /* i : number of pulses per band Q0 */ + const Word16 prev_is_transient, /* i : previous transient flag Q0 */ + Word32 *prev_normq, /* i/o: previous norms Q14 */ + Word32 *prev_env, /* i/o: previous noise envelopes Q(prev_env_Q) */ + const Word16 prev_bfi, /* i : previous bad frame indicator Q0 */ + const Word16 *sfmsize, /* i : Length of bands Q0 */ + const Word16 *sfm_start, /* i : Start of bands Q0 */ + const Word16 *sfm_end, /* i : End of bands Q0 */ + Word16 *prev_L_swb_norm, /* i/o: HVQ/Harmonic mode normalization length Q0 */ + const Word16 prev_hq_mode, /* i : Previous HQ mode Q0 */ + const Word16 num_sfm, /* i : Total number of bands Q0 */ + Word16 *prev_env_Q, + const Word16 num_env_bands, /* i : Number sub bands to be encoded for HQ_GEN Q0 */ + const Word16 element_mode /* i : IVAS element mode */ ) { - Word16 CodeBook[FREQ_LENGTH]; /* Q12 */ - Word16 cb_size; - Word16 last_sfm; - Word16 CodeBook_mod[FREQ_LENGTH]; /*Q12 */ - Word16 norm_adj[NB_SFM]; /*Q15 */ - Word16 high_sfm; - Word16 flag_32K_env_hangover; - Word16 bin_th; - Word16 peak_pos[L_HARMONIC_EXC]; - Word16 bwe_peaks[L_FRAME48k]; - Word32 L_normq_v[NB_SFM]; /*Q14 */ - Word16 coeff_fine[L_SPEC48k_EXT]; /*Q15 */ - Word32 L_coeff_out1[L_SPEC48k_EXT]; /*Q12 */ - set16_fx(peak_pos, 0, L_HARMONIC_EXC); - set16_fx(bwe_peaks, 0, L_FRAME48k); - set16_fx(norm_adj, 32767, num_sfm); /* 1.0, Q15 */ - cb_size = 0; - move16(); - bin_th = 0; - move16(); - high_sfm = 23; - move16(); - - test(); - IF(EQ_16(HQ_mode, HQ_TRANSIENT)) - { - last_sfm = sub(num_sfm, 1); - } - ELSE IF(EQ_16(HQ_mode, HQ_GEN_SWB) || EQ_16(HQ_mode, HQ_GEN_FB)) - { - last_sfm = s_max(core_sfm, sub(num_env_bands, 1)); - } - ELSE - { - last_sfm = core_sfm; - move16(); - } - - IF(EQ_16(HQ_mode, HQ_HARMONIC)) - { - /*high_sfm = (core_brate == HQ_BWE_CROSSOVER_BRATE) ? HVQ_THRES_SFM_24k-1 : HVQ_THRES_SFM_32k-3; */ - high_sfm = sub(HVQ_THRES_SFM_32k, 1); - if (LT_32(L_core_brate, HQ_BWE_CROSSOVER_BRATE)) - { - high_sfm = sub(HVQ_THRES_SFM_24k, 1); - } - - if (LT_16(last_sfm, high_sfm)) - { - last_sfm = high_sfm; - move16(); - } - } - ELSE if (EQ_16(HQ_mode, HQ_HVQ)) - { - bin_th = sfm_end[last_sfm]; + Word16 CodeBook[FREQ_LENGTH]; /* Q12 */ + Word16 cb_size; + Word16 last_sfm; + Word16 CodeBook_mod[FREQ_LENGTH]; /*Q12 */ + Word16 norm_adj[NB_SFM]; /*Q15 */ + Word16 high_sfm; + Word16 flag_32K_env_hangover; + Word16 bin_th; + Word16 peak_pos[L_HARMONIC_EXC]; + Word16 bwe_peaks[L_FRAME48k]; + Word32 L_normq_v[NB_SFM]; /*Q14 */ + Word16 coeff_fine[L_SPEC48k_EXT]; /*Q15 */ + Word32 L_coeff_out1[L_SPEC48k_EXT]; /*Q12 */ + set16_fx( peak_pos, 0, L_HARMONIC_EXC ); + set16_fx( bwe_peaks, 0, L_FRAME48k ); + set16_fx( norm_adj, 32767, num_sfm ); /* 1.0, Q15 */ + cb_size = 0; + move16(); + bin_th = 0; move16(); - } - - /* Transient analysis for envelope stability measure */ - IF(EQ_16(length, L_FRAME32k)) - { - env_stab_transient_detect_fx(is_transient, length, norm, no_att_hangover, L_energy_lt, HQ_mode, bin_th, L_coeff_out, 12); - } - - test(); - test(); - test(); - test(); - IF(EQ_16(length, L_FRAME16k) || - ((EQ_16(length, L_FRAME32k) && NE_16(HQ_mode, HQ_HARMONIC) && NE_16(HQ_mode, HQ_HVQ)) && *no_att_hangover == 0)) - { - /* Norm adjustment function */ - env_adj_fx(npulses, length, last_sfm, norm_adj, env_stab, sfmsize); - } - - /*flag_32K_env_hangover = ( length == L_FRAME32k && ( (env_stab < 0.5f && *no_att_hangover == 0) || HQ_mode == HQ_HVQ ) ); */ - flag_32K_env_hangover = 0; - move16(); - test(); - test(); - test(); - if (EQ_16(length, L_FRAME32k) && ((LT_16(env_stab, 16384) && *no_att_hangover == 0) || EQ_16(HQ_mode, HQ_HVQ))) - { - flag_32K_env_hangover = 1; + high_sfm = 23; move16(); - } - - - /*----------------------------------------------------------------* - * Build noise-fill codebook - *----------------------------------------------------------------*/ - - IF(NE_16(HQ_mode, HQ_HVQ)) - { - cb_size = build_nf_codebook_fx(flag_32K_env_hangover, coeff, sfm_start, sfmsize, sfm_end, last_sfm, R, CodeBook, CodeBook_mod); - } - /*----------------------------------------------------------------* - * Prepare fine structure for Harmonic and HVQ - *----------------------------------------------------------------*/ - - IF(EQ_16(HQ_mode, HQ_HARMONIC)) - { - harm_bwe_fine_fx(R, last_sfm, high_sfm, num_sfm, norm, sfm_start, sfm_end, prev_L_swb_norm, coeff, L_coeff_out, coeff_fine); - } - ELSE IF(EQ_16(HQ_mode, HQ_HVQ)) - { - hvq_bwe_fine_fx(last_sfm, num_sfm, sfm_end, peak_idx, Npeaks, peak_pos, prev_L_swb_norm, L_coeff_out, bwe_peaks, coeff_fine); - } - - /*----------------------------------------------------------------* - * Apply noise-fill - *----------------------------------------------------------------*/ - - test(); - IF(NE_16(HQ_mode, HQ_HVQ) && cb_size > 0) - { - apply_noisefill_HQ_fx(R, length, flag_32K_env_hangover, L_core_brate, last_sfm, CodeBook, - CodeBook_mod, cb_size, sfm_start, sfm_end, sfmsize, coeff); - } - - /*----------------------------------------------------------------* - * Normal mode BWE - *----------------------------------------------------------------*/ - - IF(HQ_mode == HQ_NORMAL) - { - hq_fold_bwe_fx(last_sfm, sfm_end, num_sfm, coeff); - } - - /*----------------------------------------------------------------* - * Apply noise-fill adjustment - *----------------------------------------------------------------*/ - - test(); - test(); - test(); - IF((GE_16(length, L_FRAME32k) || GT_32(L_core_brate, HQ_32k) || LT_32(L_core_brate, HQ_24k40)) - && NE_16(HQ_mode, HQ_HVQ)) - { - apply_nf_gain_fx(nf_idx, last_sfm, R, sfm_start, sfm_end, coeff); - } - - /*----------------------------------------------------------------* - * Prepare fine strucutre for HQ GENERIC - *----------------------------------------------------------------*/ - test(); - IF(EQ_16(HQ_mode, HQ_GEN_SWB) || EQ_16(HQ_mode, HQ_GEN_FB)) - { - hq_generic_fine_fx(coeff, last_sfm, sfm_start, sfm_end, bwe_seed, coeff_fine); - } - - /*----------------------------------------------------------------* - * Apply envelope - *----------------------------------------------------------------*/ - - test(); - IF(NE_16(HQ_mode, HQ_HARMONIC) && NE_16(HQ_mode, HQ_HVQ)) - { - apply_envelope_fx(coeff, norm, norm_adj, num_sfm, last_sfm, HQ_mode, length, sfm_start, sfm_end, - L_normq_v, L_coeff_out, coeff_fine, L_coeff_out1); - } - - /*----------------------------------------------------------------* - * Harmonic BWE, HVQ BWE and HQ SWB BWE - *----------------------------------------------------------------*/ - test(); - IF(EQ_16(HQ_mode, HQ_HARMONIC)) - { - harm_bwe_fx(coeff_fine, coeff, num_sfm, sfm_start, sfm_end, last_sfm, R, prev_hq_mode, norm, noise_level, prev_noise_level, bwe_seed, L_coeff_out, element_mode); - } - ELSE IF(EQ_16(HQ_mode, HQ_HVQ)) - { - hvq_bwe_fx(L_coeff_out, coeff_fine, sfm_start, sfm_end, sfmsize, last_sfm, prev_hq_mode, bwe_peaks, bin_th, num_sfm, L_core_brate, R, norm, - noise_level, prev_noise_level, bwe_seed, L_coeff_out, 15, 12); - } - ELSE IF(EQ_16(HQ_mode, HQ_GEN_SWB) || EQ_16(HQ_mode, HQ_GEN_FB)) - { - hq_bwe_fx(HQ_mode, L_coeff_out1, hq_generic_fenv, L_coeff_out, hq_generic_offset, prev_L_swb_norm, hq_generic_exc_clas, sfm_end, num_sfm, num_env_bands, R); - } - - /*----------------------------------------------------------------* - * HQ WB BWE refinements - *----------------------------------------------------------------*/ - test(); - IF(EQ_16(length, L_FRAME16k) && LE_32(L_core_brate, HQ_32k)) - { - hq_wb_nf_bwe_fx(coeff, is_transient, prev_bfi, L_normq_v, num_sfm, sfm_start, sfm_end, sfmsize, last_sfm, R, - prev_is_transient, prev_normq, prev_env, bwe_seed, prev_coeff_out, prev_R, L_coeff_out, prev_env_Q); - } - - /*----------------------------------------------------------------* - * Update memories - *----------------------------------------------------------------*/ - - test(); - IF(NE_16(HQ_mode, HQ_HARMONIC) && NE_16(HQ_mode, HQ_HVQ)) - { - prev_noise_level[0] = 3277; - move16();/* 0.1 in Q15 */ - prev_noise_level[1] = 3277; - move16();/* 0.1 in Q15 */ - } - test(); - IF(!(EQ_16(length, L_FRAME16k) && LE_32(L_core_brate, HQ_32k))) - { - set32_fx(prev_env, 0, SFM_N_WB); - set32_fx(prev_normq, 0, SFM_N_WB); - } - - test(); - IF(EQ_16(length, L_FRAME32k) && LE_32(L_core_brate, HQ_32k)) - { - *prev_R = R[SFM_N_WB - 1]; - Copy32(L_coeff_out + L_FRAME16k - L_HQ_WB_BWE, prev_coeff_out, L_HQ_WB_BWE); - } - - return; + + test(); + IF( EQ_16( HQ_mode, HQ_TRANSIENT ) ) + { + last_sfm = sub( num_sfm, 1 ); + } + ELSE IF( EQ_16( HQ_mode, HQ_GEN_SWB ) || EQ_16( HQ_mode, HQ_GEN_FB ) ) + { + last_sfm = s_max( core_sfm, sub( num_env_bands, 1 ) ); + } + ELSE + { + last_sfm = core_sfm; + move16(); + } + + IF( EQ_16( HQ_mode, HQ_HARMONIC ) ) + { + /*high_sfm = (core_brate == HQ_BWE_CROSSOVER_BRATE) ? HVQ_THRES_SFM_24k-1 : HVQ_THRES_SFM_32k-3; */ + high_sfm = sub( HVQ_THRES_SFM_32k, 1 ); + if ( LT_32( L_core_brate, HQ_BWE_CROSSOVER_BRATE ) ) + { + high_sfm = sub( HVQ_THRES_SFM_24k, 1 ); + } + + if ( LT_16( last_sfm, high_sfm ) ) + { + last_sfm = high_sfm; + move16(); + } + } + ELSE if ( EQ_16( HQ_mode, HQ_HVQ ) ) + { + bin_th = sfm_end[last_sfm]; + move16(); + } + + /* Transient analysis for envelope stability measure */ + IF( EQ_16( length, L_FRAME32k ) ) + { + env_stab_transient_detect_fx( is_transient, length, norm, no_att_hangover, L_energy_lt, HQ_mode, bin_th, L_coeff_out, 12 ); + } + + test(); + test(); + test(); + test(); + IF( EQ_16( length, L_FRAME16k ) || + ( ( EQ_16( length, L_FRAME32k ) && NE_16( HQ_mode, HQ_HARMONIC ) && NE_16( HQ_mode, HQ_HVQ ) ) && *no_att_hangover == 0 ) ) + { + /* Norm adjustment function */ + env_adj_fx( npulses, length, last_sfm, norm_adj, env_stab, sfmsize ); + } + + /*flag_32K_env_hangover = ( length == L_FRAME32k && ( (env_stab < 0.5f && *no_att_hangover == 0) || HQ_mode == HQ_HVQ ) ); */ + flag_32K_env_hangover = 0; + move16(); + test(); + test(); + test(); + if ( EQ_16( length, L_FRAME32k ) && ( ( LT_16( env_stab, 16384 ) && *no_att_hangover == 0 ) || EQ_16( HQ_mode, HQ_HVQ ) ) ) + { + flag_32K_env_hangover = 1; + move16(); + } + + + /*----------------------------------------------------------------* + * Build noise-fill codebook + *----------------------------------------------------------------*/ + + IF( NE_16( HQ_mode, HQ_HVQ ) ) + { + cb_size = build_nf_codebook_fx( flag_32K_env_hangover, coeff, sfm_start, sfmsize, sfm_end, last_sfm, R, CodeBook, CodeBook_mod ); + } + /*----------------------------------------------------------------* + * Prepare fine structure for Harmonic and HVQ + *----------------------------------------------------------------*/ + + IF( EQ_16( HQ_mode, HQ_HARMONIC ) ) + { + harm_bwe_fine_fx( R, last_sfm, high_sfm, num_sfm, norm, sfm_start, sfm_end, prev_L_swb_norm, coeff, L_coeff_out, coeff_fine ); + } + ELSE IF( EQ_16( HQ_mode, HQ_HVQ ) ) + { + hvq_bwe_fine_fx( last_sfm, num_sfm, sfm_end, peak_idx, Npeaks, peak_pos, prev_L_swb_norm, L_coeff_out, bwe_peaks, coeff_fine ); + } + + /*----------------------------------------------------------------* + * Apply noise-fill + *----------------------------------------------------------------*/ + + test(); + IF( NE_16( HQ_mode, HQ_HVQ ) && cb_size > 0 ) + { + apply_noisefill_HQ_fx( R, length, flag_32K_env_hangover, L_core_brate, last_sfm, CodeBook, + CodeBook_mod, cb_size, sfm_start, sfm_end, sfmsize, coeff ); + } + + /*----------------------------------------------------------------* + * Normal mode BWE + *----------------------------------------------------------------*/ + + IF( HQ_mode == HQ_NORMAL ) + { + hq_fold_bwe_fx( last_sfm, sfm_end, num_sfm, coeff ); + } + + /*----------------------------------------------------------------* + * Apply noise-fill adjustment + *----------------------------------------------------------------*/ + + test(); + test(); + test(); + IF( ( GE_16( length, L_FRAME32k ) || GT_32( L_core_brate, HQ_32k ) || LT_32( L_core_brate, HQ_24k40 ) ) && NE_16( HQ_mode, HQ_HVQ ) ) + { + apply_nf_gain_fx( nf_idx, last_sfm, R, sfm_start, sfm_end, coeff ); + } + + /*----------------------------------------------------------------* + * Prepare fine strucutre for HQ GENERIC + *----------------------------------------------------------------*/ + test(); + IF( EQ_16( HQ_mode, HQ_GEN_SWB ) || EQ_16( HQ_mode, HQ_GEN_FB ) ) + { + hq_generic_fine_fx( coeff, last_sfm, sfm_start, sfm_end, bwe_seed, coeff_fine ); + } + + /*----------------------------------------------------------------* + * Apply envelope + *----------------------------------------------------------------*/ + + test(); + IF( NE_16( HQ_mode, HQ_HARMONIC ) && NE_16( HQ_mode, HQ_HVQ ) ) + { + apply_envelope_fx( coeff, norm, norm_adj, num_sfm, last_sfm, HQ_mode, length, sfm_start, sfm_end, + L_normq_v, L_coeff_out, coeff_fine, L_coeff_out1 ); + } + + /*----------------------------------------------------------------* + * Harmonic BWE, HVQ BWE and HQ SWB BWE + *----------------------------------------------------------------*/ + test(); + IF( EQ_16( HQ_mode, HQ_HARMONIC ) ) + { + harm_bwe_fx( coeff_fine, coeff, num_sfm, sfm_start, sfm_end, last_sfm, R, prev_hq_mode, norm, noise_level, prev_noise_level, bwe_seed, L_coeff_out, element_mode ); + } + ELSE IF( EQ_16( HQ_mode, HQ_HVQ ) ) + { + hvq_bwe_fx( L_coeff_out, coeff_fine, sfm_start, sfm_end, sfmsize, last_sfm, prev_hq_mode, bwe_peaks, bin_th, num_sfm, L_core_brate, R, norm, + noise_level, prev_noise_level, bwe_seed, L_coeff_out, 15, 12 ); + } + ELSE IF( EQ_16( HQ_mode, HQ_GEN_SWB ) || EQ_16( HQ_mode, HQ_GEN_FB ) ) + { + hq_bwe_fx( HQ_mode, L_coeff_out1, hq_generic_fenv, L_coeff_out, hq_generic_offset, prev_L_swb_norm, hq_generic_exc_clas, sfm_end, num_sfm, num_env_bands, R ); + } + + /*----------------------------------------------------------------* + * HQ WB BWE refinements + *----------------------------------------------------------------*/ + test(); + IF( EQ_16( length, L_FRAME16k ) && LE_32( L_core_brate, HQ_32k ) ) + { + hq_wb_nf_bwe_fx( coeff, is_transient, prev_bfi, L_normq_v, num_sfm, sfm_start, sfm_end, sfmsize, last_sfm, R, + prev_is_transient, prev_normq, prev_env, bwe_seed, prev_coeff_out, prev_R, L_coeff_out, prev_env_Q ); + } + + /*----------------------------------------------------------------* + * Update memories + *----------------------------------------------------------------*/ + + test(); + IF( NE_16( HQ_mode, HQ_HARMONIC ) && NE_16( HQ_mode, HQ_HVQ ) ) + { + prev_noise_level[0] = 3277; + move16(); /* 0.1 in Q15 */ + prev_noise_level[1] = 3277; + move16(); /* 0.1 in Q15 */ + } + test(); + IF( !( EQ_16( length, L_FRAME16k ) && LE_32( L_core_brate, HQ_32k ) ) ) + { + set32_fx( prev_env, 0, SFM_N_WB ); + set32_fx( prev_normq, 0, SFM_N_WB ); + } + + test(); + IF( EQ_16( length, L_FRAME32k ) && LE_32( L_core_brate, HQ_32k ) ) + { + *prev_R = R[SFM_N_WB - 1]; + Copy32( L_coeff_out + L_FRAME16k - L_HQ_WB_BWE, prev_coeff_out, L_HQ_WB_BWE ); + } + + return; } diff --git a/lib_com/findpulse.c b/lib_com/findpulse.c index 34889aac3..be75d3c83 100644 --- a/lib_com/findpulse.c +++ b/lib_com/findpulse.c @@ -142,106 +142,106 @@ int16_t findpulse( } -Word16 findpulse_fx( /* o : pulse position */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 res[], /* i : Residual signal <12 bits */ - const Word16 T0, /* i : Pitch estimation Q0 */ - const Word16 enc, /* i : enc = 1 -> encoder side; enc = 0 -> decoder side */ - Word16 *sign /* i/o: sign of the maximum */ +Word16 findpulse_fx( /* o : pulse position */ + const Word16 L_frame, /* i : length of the frame */ + const Word16 res[], /* i : Residual signal <12 bits */ + const Word16 T0, /* i : Pitch estimation Q0 */ + const Word16 enc, /* i : enc = 1 -> encoder side; enc = 0 -> decoder side */ + Word16 *sign /* i/o: sign of the maximum */ ) { - const Word16 *ptr; - Word16 maxval; - Word16 i, maxi; - Word32 Ltmp; - Word16 resf[L_FRAME16k]; /* Low pass filtered residual */ - - IF(enc != DEC) - { - /*------------------------------------------------------------------------* - * 1. Very simple LP filter - *------------------------------------------------------------------------*/ - - /* resf[0] = 0.50f * res[0] + 0.25f * res[1] */ - Ltmp = L_mult(res[0], 16384); - resf[0] = mac_r(Ltmp, res[1], 8192); - move16(); - FOR(i = 1; i < L_frame - 1; i++) + const Word16 *ptr; + Word16 maxval; + Word16 i, maxi; + Word32 Ltmp; + Word16 resf[L_FRAME16k]; /* Low pass filtered residual */ + + IF( enc != DEC ) { - /* resf[i] = 0.25f * res[i-1] + 0.5f * res[i] + 0.25f * res[i+1] */ - Ltmp = L_mult(8192, res[i - 1]); - Ltmp = L_mac(Ltmp, 16384, res[i]); - resf[i] = mac_r(Ltmp, 8192, res[i + 1]); - move16(); - } + /*------------------------------------------------------------------------* + * 1. Very simple LP filter + *------------------------------------------------------------------------*/ - /* resf[L_frame-1] = 0.25f * res[L_frame-2] + 0.50f * res[L_frame-1] */ - Ltmp = L_mult(res[L_frame - 2], 8192); - resf[L_frame - 1] = mac_r(Ltmp, 16384, res[L_frame - 1]); - move16(); + /* resf[0] = 0.50f * res[0] + 0.25f * res[1] */ + Ltmp = L_mult( res[0], 16384 ); + resf[0] = mac_r( Ltmp, res[1], 8192 ); + move16(); + FOR( i = 1; i < L_frame - 1; i++ ) + { + /* resf[i] = 0.25f * res[i-1] + 0.5f * res[i] + 0.25f * res[i+1] */ + Ltmp = L_mult( 8192, res[i - 1] ); + Ltmp = L_mac( Ltmp, 16384, res[i] ); + resf[i] = mac_r( Ltmp, 8192, res[i + 1] ); + move16(); + } - /*------------------------------------------------------------------------* - * 2. Find "biggest" pitch pulse - *------------------------------------------------------------------------*/ + /* resf[L_frame-1] = 0.25f * res[L_frame-2] + 0.50f * res[L_frame-1] */ + Ltmp = L_mult( res[L_frame - 2], 8192 ); + resf[L_frame - 1] = mac_r( Ltmp, 16384, res[L_frame - 1] ); + move16(); - ptr = resf + L_frame - 1; - move16(); - maxi = 0; - move16(); + /*------------------------------------------------------------------------* + * 2. Find "biggest" pitch pulse + *------------------------------------------------------------------------*/ - FOR(i = 1; i < T0; i++) - { - Ltmp = L_mult0(ptr[-maxi], ptr[-maxi]); - if (L_msu0(Ltmp, ptr[-i], ptr[-i]) < 0) - { - maxi = i; + ptr = resf + L_frame - 1; move16(); - } - } - /* - *sign = 1; move16(); - test(); - if (ptr[-maxi] >= 0) - { - *sign = 0; move16(); - }*/ - *sign = negate(shr(ptr[-maxi], 15)); - move16(); - } - ELSE - { - /*-----------------------------------------------------------------* - * 2. Find "biggest" pulse in the last pitch section according to the sign - *-----------------------------------------------------------------*/ - - maxval = 0; - move16(); - maxi = 0; - move16(); - - IF(*sign == 0) - { - FOR(i = 0; i < T0; i++) + maxi = 0; + move16(); + + FOR( i = 1; i < T0; i++ ) { - if (GE_16(res[i], maxval)) + Ltmp = L_mult0( ptr[-maxi], ptr[-maxi] ); + if ( L_msu0( Ltmp, ptr[-i], ptr[-i] ) < 0 ) { - maxi = add(i, 1); + maxi = i; + move16(); } - maxval = s_max(res[i], maxval); } + /* + *sign = 1; move16(); + test(); + if (ptr[-maxi] >= 0) + { + *sign = 0; move16(); + }*/ + *sign = negate( shr( ptr[-maxi], 15 ) ); + move16(); } ELSE { - FOR(i = 0; i < T0; i++) + /*-----------------------------------------------------------------* + * 2. Find "biggest" pulse in the last pitch section according to the sign + *-----------------------------------------------------------------*/ + + maxval = 0; + move16(); + maxi = 0; + move16(); + + IF( *sign == 0 ) { - if (LE_16(res[i], maxval)) + FOR( i = 0; i < T0; i++ ) { - maxi = add(i, 1); + if ( GE_16( res[i], maxval ) ) + { + maxi = add( i, 1 ); + } + maxval = s_max( res[i], maxval ); + } + } + ELSE + { + FOR( i = 0; i < T0; i++ ) + { + if ( LE_16( res[i], maxval ) ) + { + maxi = add( i, 1 ); + } + maxval = s_min( res[i], maxval ); } - maxval = s_min(res[i], maxval); } } - } - return maxi; -} \ No newline at end of file + return maxi; +} diff --git a/lib_com/fine_gain_bits_fx.c b/lib_com/fine_gain_bits_fx.c index 778af0a17..1ffc69535 100644 --- a/lib_com/fine_gain_bits_fx.c +++ b/lib_com/fine_gain_bits_fx.c @@ -3,10 +3,10 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" #endif @@ -19,36 +19,36 @@ *--------------------------------------------------------------------------*/ static void subband_gain_bits_fx( - const Word16 *Rk, /* i : bit allocation per band Q3 */ - const Word16 N, /* i : number of bands */ - Word16 *bits, /* o : gain bits per band */ - const Word16 *sfmsize /* i : Size of bands */ + const Word16 *Rk, /* i : bit allocation per band Q3 */ + const Word16 N, /* i : number of bands */ + Word16 *bits, /* o : gain bits per band */ + const Word16 *sfmsize /* i : Size of bands */ ) { - Word16 i,b,tot; + Word16 i, b, tot; Word16 bps; tot = 0; move16(); - FOR ( i = 0; i < N; i++ ) + FOR( i = 0; i < N; i++ ) { /*bps = (short)(Rk[i]*((word16)min(32767, ceil(32767.0f/sfmsize[i]); inexact C-integer division approx. */ - bps = extract_l(L_shr(L_mult0(Rk[i], inv_tbl_fx[sfmsize[i]]), 18)); /* 3+15 */ - if (EQ_32(L_shl(L_mult0(sfmsize[i], add(bps, 1)), 3), Rk[i])) + bps = extract_l( L_shr( L_mult0( Rk[i], inv_tbl_fx[sfmsize[i]] ), 18 ) ); /* 3+15 */ + if ( EQ_32( L_shl( L_mult0( sfmsize[i], add( bps, 1 ) ), 3 ), Rk[i] ) ) { - bps = add(bps, 1); + bps = add( bps, 1 ); } - bps = s_min(7, bps); + bps = s_min( 7, bps ); b = fine_gain_bits[bps]; move16(); bits[i] = b; move16(); - tot = add(tot, b); + tot = add( tot, b ); } - if ( tot == 0) + if ( tot == 0 ) { /* If no gain bits were assigned, use one bit anyway for potential PVQ overage */ bits[0] = 1; @@ -64,22 +64,22 @@ static void subband_gain_bits_fx( * Assign gain adjustment bits and update bit budget *--------------------------------------------------------------------------*/ -Word16 assign_gain_bits_fx( /* o : Number of assigned gain bits */ - const Word16 core, /* i : HQ core */ - const Word16 BANDS, /* i : Number of bands */ - const Word16 *band_width, /* i : Sub band bandwidth */ - Word16 *Rk, /* i/o: Bit allocation/Adjusted bit alloc. Q3 */ - Word16 *gain_bits_array, /* o : Assigned gain bits */ - Word16 *Rcalc /* o : Bit budget for shape quantizer Q3 */ +Word16 assign_gain_bits_fx( /* o : Number of assigned gain bits */ + const Word16 core, /* i : HQ core */ + const Word16 BANDS, /* i : Number of bands */ + const Word16 *band_width, /* i : Sub band bandwidth */ + Word16 *Rk, /* i/o: Bit allocation/Adjusted bit alloc. Q3 */ + Word16 *gain_bits_array, /* o : Assigned gain bits */ + Word16 *Rcalc /* o : Bit budget for shape quantizer Q3 */ ) { Word16 gain_bits_tot; Word16 i; /* Allocate gain bits for every subband used, based on bit rate and bandwidth */ - IF( EQ_16(core, HQ_CORE)) + IF( EQ_16( core, HQ_CORE ) ) { - subband_gain_bits_fx(Rk, BANDS, gain_bits_array, band_width); + subband_gain_bits_fx( Rk, BANDS, gain_bits_array, band_width ); } ELSE { @@ -92,14 +92,14 @@ Word16 assign_gain_bits_fx( /* o : Number of assigned gain bits move16(); *Rcalc = 0; move16(); - FOR (i = 0; i < BANDS; i++) + FOR( i = 0; i < BANDS; i++ ) { - IF (Rk[i] > 0) + IF( Rk[i] > 0 ) { - Rk[i] = sub(Rk[i], shl(gain_bits_array[i], 3)); + Rk[i] = sub( Rk[i], shl( gain_bits_array[i], 3 ) ); move16(); - gain_bits_tot = add(gain_bits_tot, gain_bits_array[i]); - *Rcalc = add(*Rcalc, Rk[i]); + gain_bits_tot = add( gain_bits_tot, gain_bits_array[i] ); + *Rcalc = add( *Rcalc, Rk[i] ); move16(); } } diff --git a/lib_com/float_to_fix_ops.c b/lib_com/float_to_fix_ops.c index c11bc4f46..7cf76a7cf 100644 --- a/lib_com/float_to_fix_ops.c +++ b/lib_com/float_to_fix_ops.c @@ -5,37 +5,37 @@ #include "options.h" #include "prot.h" #include "prot_fx2.h" -Word32 floatToFixed(float f, Word16 Q) +Word32 floatToFixed( float f, Word16 Q ) { - if (f == 1.0f && Q == Q15) - return MAX16B; - if (f == 1.0f && Q == Q31) - return MAXVAL_WORD32; - if (Q < 0) - return (Word32)((float)(f) / (double)(1llu << (-Q)) + (f >= 0 ? 0.5 : -0.5)); - else - { - Word64 result_32; - result_32=(Word64)(f * (double)(1llu << Q) + (f >= 0 ? 0.5 : -0.5)); - if (result_32 > MAX_32) - return MAX_32; - if (result_32 < MIN_32) - return MIN_32; - return (Word32)result_32; - } + if ( f == 1.0f && Q == Q15 ) + return MAX16B; + if ( f == 1.0f && Q == Q31 ) + return MAXVAL_WORD32; + if ( Q < 0 ) + return (Word32) ( (float) ( f ) / (double) ( 1llu << ( -Q ) ) + ( f >= 0 ? 0.5 : -0.5 ) ); + else + { + Word64 result_32; + result_32 = (Word64) ( f * (double) ( 1llu << Q ) + ( f >= 0 ? 0.5 : -0.5 ) ); + if ( result_32 > MAX_32 ) + return MAX_32; + if ( result_32 < MIN_32 ) + return MIN_32; + return (Word32) result_32; + } } -float fixedToFloat(Word32 i, Word16 Q) +float fixedToFloat( Word32 i, Word16 Q ) { - if (Q < 0) - return (i * (float)(((unsigned)1) << (-Q))); - else - return (float)(i) / (float)((unsigned int)1 << Q); + if ( Q < 0 ) + return ( i * (float) ( ( (unsigned) 1 ) << ( -Q ) ) ); + else + return (float) ( i ) / (float) ( (unsigned int) 1 << Q ); } -void floatToFixed_arrL(float *f, Word32 *i, Word16 Q, Word16 l) +void floatToFixed_arrL( float *f, Word32 *i, Word16 Q, Word16 l ) { - for (int j = 0; j < l; j++) - { + for ( int j = 0; j < l; j++ ) + { #if 0 i[j] = floatToFixed(f[j], Q); #else @@ -50,7 +50,7 @@ void floatToFixed_arrL(float *f, Word32 *i, Word16 Q, Word16 l) } i[j] = (Word32) i64_val; #endif - } + } } void floatToFixed_arr16( float *f, Word16 *i, Word16 Q, Word16 l ) { @@ -81,7 +81,7 @@ float fixedToFloat_32( Word32 number, Word16 Q ) { float val = 0.0f; assert( abs_s( Q ) <= 63 ); - if (abs_s( Q ) > 31 ) + if ( abs_s( Q ) > 31 ) { if ( Q > 0 ) { @@ -102,8 +102,8 @@ float fixedToFloat_32( Word32 number, Word16 Q ) Word32 floatToFixed_32( float number, Word16 Q ) { float val = 0.0f; - assert(abs_s( Q ) <= 63 ); - if (abs_s( Q ) > 31 ) + assert( abs_s( Q ) <= 63 ); + if ( abs_s( Q ) > 31 ) { if ( Q > 0 ) { @@ -146,80 +146,80 @@ void fixedToFloat_arrL32( Word32 *i, float *f, Word16 Q, Word16 l ) } } -void floatToFixed_arr(float *f, Word16 *i, Word16 Q, Word16 l) +void floatToFixed_arr( float *f, Word16 *i, Word16 Q, Word16 l ) { - for (int j = 0; j < l; j++) - { + for ( int j = 0; j < l; j++ ) + { #if 0 i[j] = (Word16)floatToFixed(f[j], Q); #else - Word32 i32_val = floatToFixed(f[j], Q); - IF (i32_val > MAX_16) + Word32 i32_val = floatToFixed( f[j], Q ); + IF( i32_val > MAX_16 ) { i32_val = MAX_16; } - ELSE IF (i32_val < MIN_16) + ELSE IF( i32_val < MIN_16 ) { i32_val = MIN_16; } - i[j] = (Word16)i32_val; + i[j] = (Word16) i32_val; #endif - } + } } -void fixedToFloat_arrL(Word32 *i, float *f, Word16 Q, Word16 l) +void fixedToFloat_arrL( Word32 *i, float *f, Word16 Q, Word16 l ) { - for (int j = 0; j < l; j++) - { - f[j] = fixedToFloat(i[j], Q); - } + for ( int j = 0; j < l; j++ ) + { + f[j] = fixedToFloat( i[j], Q ); + } } -void fixedToFloat_arr(Word16 *i, float *f, Word16 Q, Word16 l) +void fixedToFloat_arr( Word16 *i, float *f, Word16 Q, Word16 l ) { - for (int j = 0; j < l; j++) - { - f[j] = fixedToFloat(i[j], Q); - } + for ( int j = 0; j < l; j++ ) + { + f[j] = fixedToFloat( i[j], Q ); + } } -Word16 Q_factor(float x) +Word16 Q_factor( float x ) { Word16 Q = 15; if ( x >= 1 || x <= -1 ) - Q = norm_s((Word16)abs((Word32)x)); + Q = norm_s( (Word16) abs( (Word32) x ) ); return Q; } -Word16 Q_factor_L(float x) +Word16 Q_factor_L( float x ) { Word16 Q = 31; if ( x >= 1 || x <= -1 ) - Q = norm_l(abs((Word32)x)); + Q = norm_l( abs( (Word32) x ) ); return Q; } Word16 Q_factor_L_32( Word32 x ) { Word16 Q = 31; if ( x >= 1 || x <= -1 ) - Q = norm_l(L_abs( (Word32) x ) ); + Q = norm_l( L_abs( (Word32) x ) ); return Q; } -Word16 Q_factor_arr(float *x, Word16 l) +Word16 Q_factor_arr( float *x, Word16 l ) { - Word16 Q = 15; - for (int i = 0; i < l; i++) - { - if (x[i] >= 1 || x[i] <= -1) - Q = s_min(Q, norm_s((Word16)abs((Word32)x[i]))); - } - return Q; + Word16 Q = 15; + for ( int i = 0; i < l; i++ ) + { + if ( x[i] >= 1 || x[i] <= -1 ) + Q = s_min( Q, norm_s( (Word16) abs( (Word32) x[i] ) ) ); + } + return Q; } -Word16 Q_factor_arrL(float *x, Word16 l) +Word16 Q_factor_arrL( float *x, Word16 l ) { - Word16 Q = 31; - for (int i = 0; i < l; i++) - { - if (x[i] >= 1 || x[i] <= -1) - Q = s_min(Q, norm_l((Word32)abs((Word32)x[i]))); - } - return Q; + Word16 Q = 31; + for ( int i = 0; i < l; i++ ) + { + if ( x[i] >= 1 || x[i] <= -1 ) + Q = s_min( Q, norm_l( (Word32) abs( (Word32) x[i] ) ) ); + } + return Q; } #ifdef IVAS_FLOAT_FIXED diff --git a/lib_com/frame_ener.c b/lib_com/frame_ener.c index b4c2d4a3a..46fcddfb3 100644 --- a/lib_com/frame_ener.c +++ b/lib_com/frame_ener.c @@ -134,7 +134,7 @@ void fer_energy_fx( *enr = W_extract_h( W_tmp ); // Q = q_synth * 2 + shift - 32 enr_tmp = BASOP_Util_Divide3216_Scale( *enr, shr( L_frame, 1 ) /*Q0*/, &exp ); - *enr = L_shr( L_deposit_l( enr_tmp ), (shift-32-exp-1)); + *enr = L_shr( L_deposit_l( enr_tmp ), ( shift - 32 - exp - 1 ) ); } return; } @@ -191,130 +191,124 @@ float frame_energy( * Estimation of pitch-synchronous (voiced) or mean half-frame (unvoiced) energy *----------------------------------------------------------------------------------*/ Word16 frame_ener_fx( - const Word16 L_frame, /* i : length of the frame */ - const Word16 clas, /* i : frame classification */ - const Word16 *synth, /* i : synthesized speech at Fs = 12k8 Hz Q_new */ - const Word16 pitch, /* i : pitch period Q0 */ - Word32 *enr_q, /* o : pitch-synchronous or half_frame energy Q0 */ - const Word16 offset, /* i : speech pointer offset (0 or L_FRAME) */ - const Word16 Q_new, /* i : Scaling factor */ - Word16 shift, /* i : Shift need to obtain 12 bits vectors */ - const Word16 enc /* i : Encoder/decoder */ + const Word16 L_frame, /* i : length of the frame */ + const Word16 clas, /* i : frame classification */ + const Word16 *synth, /* i : synthesized speech at Fs = 12k8 Hz Q_new */ + const Word16 pitch, /* i : pitch period Q0 */ + Word32 *enr_q, /* o : pitch-synchronous or half_frame energy Q0 */ + const Word16 offset, /* i : speech pointer offset (0 or L_FRAME) */ + const Word16 Q_new, /* i : Scaling factor */ + Word16 shift, /* i : Shift need to obtain 12 bits vectors */ + const Word16 enc /* i : Encoder/decoder */ ) { - Word16 len, exp_enrq, exp_tmp, pos; - Word16 i; - const Word16 *pt_synth; - Word32 Ltmp; - - exp_enrq = 0; - move16(); - test(); - test(); - IF((EQ_16(clas, VOICED_CLAS)) || (EQ_16(clas, ONSET)) || (EQ_16(clas, SIN_ONSET))) /* current frame is voiced */ - { - /* current frame is voiced */ - len = pitch; - move16(); /* pitch value at the end of frame */ - pt_synth = synth; + Word16 len, exp_enrq, exp_tmp, pos; + Word16 i; + const Word16 *pt_synth; + Word32 Ltmp; + + exp_enrq = 0; move16(); - if (offset != 0) + test(); + test(); + IF( ( EQ_16( clas, VOICED_CLAS ) ) || ( EQ_16( clas, ONSET ) ) || ( EQ_16( clas, SIN_ONSET ) ) ) /* current frame is voiced */ { - pt_synth = synth + sub(L_frame, len); + /* current frame is voiced */ + len = pitch; + move16(); /* pitch value at the end of frame */ + pt_synth = synth; + move16(); + if ( offset != 0 ) + { + pt_synth = synth + sub( L_frame, len ); + } + emaximum_fx( Q_new, pt_synth, len, enr_q ); + move16(); /* pitch synchronous E */ + IF( enc != 0 ) + { + exp_enrq = norm_l( *enr_q ); + *enr_q = L_shl( *enr_q, exp_enrq ); + move32(); + exp_enrq = sub( exp_enrq, 2 ); + } } - emaximum_fx(Q_new, pt_synth, len, enr_q); - move16();/* pitch synchronous E */ - IF(enc != 0) + ELSE { - exp_enrq = norm_l(*enr_q); - *enr_q = L_shl(*enr_q, exp_enrq); - move32(); - exp_enrq = sub(exp_enrq, 2); - } - } - ELSE - { - /* current frame is unvoiced */ - Word16 L_frame2, exp2, enr_q_tmp; - - L_frame2 = shr(L_frame,1); - pos = 0; - move16(); + /* current frame is unvoiced */ + Word16 L_frame2, exp2, enr_q_tmp; - if (offset != 0) - { - pos = sub(L_frame, L_frame2); - } + L_frame2 = shr( L_frame, 1 ); + pos = 0; + move16(); + + if ( offset != 0 ) + { + pos = sub( L_frame, L_frame2 ); + } #ifdef BASOP_NOGLOB - Ltmp = L_mult_sat(synth[pos], synth[pos]); + Ltmp = L_mult_sat( synth[pos], synth[pos] ); #else - Ltmp = L_mult(synth[pos], synth[pos]); + Ltmp = L_mult( synth[pos], synth[pos] ); #endif - FOR(i = 1; i < L_frame2; i++) + FOR( i = 1; i < L_frame2; i++ ) { #ifdef BASOP_NOGLOB - Ltmp = L_mac_sat(Ltmp, synth[pos + i], synth[pos + i]); + Ltmp = L_mac_sat( Ltmp, synth[pos + i], synth[pos + i] ); #else /* BASOP_NOGLOB */ - Ltmp = L_mac(Ltmp, synth[pos + i], synth[pos + i]); + Ltmp = L_mac( Ltmp, synth[pos + i], synth[pos + i] ); #endif } test(); - IF(EQ_32(Ltmp, MAX_32) || enc != 0) + IF( EQ_32( Ltmp, MAX_32 ) || enc != 0 ) { - /* scale down when overflow occurs */ - *enr_q = Energy_scale(synth + pos, L_frame2, shift, &exp_enrq); - move32(); - } - ELSE - { - shift = 0; - move16(); - /* Normalize acc in Q31 (energy already calculated) */ - pos = norm_l(Ltmp); - Ltmp = L_shl(Ltmp, pos); - exp_enrq = sub(30, pos); /* exponent = 0..30 */ - *enr_q = Ltmp; - move32(); - } + /* scale down when overflow occurs */ + *enr_q = Energy_scale( synth + pos, L_frame2, shift, &exp_enrq ); + move32(); + } + ELSE + { + shift = 0; + move16(); + /* Normalize acc in Q31 (energy already calculated) */ + pos = norm_l( Ltmp ); + Ltmp = L_shl( Ltmp, pos ); + exp_enrq = sub( 30, pos ); /* exponent = 0..30 */ + *enr_q = Ltmp; + move32(); + } /* enr2 = 1.0f/L_FRAME2 * dot_product(synth, synth, L_FRAME2) */ - exp_enrq = sub(exp_enrq, shl(shift, 1)); + exp_enrq = sub( exp_enrq, shl( shift, 1 ) ); - IF(enc != 0) + IF( enc != 0 ) { - assert(L_frame == 256 || L_frame == 320); + assert( L_frame == 256 || L_frame == 320 ); - exp_tmp = add(shl(Q_new, 1), -2 + 7); /* L_subfr == L_SUBFR */ - exp_enrq = sub(exp_enrq, exp_tmp); - exp_enrq = sub(31, exp_enrq); + exp_tmp = add( shl( Q_new, 1 ), -2 + 7 ); /* L_subfr == L_SUBFR */ + exp_enrq = sub( exp_enrq, exp_tmp ); + exp_enrq = sub( 31, exp_enrq ); - IF(EQ_16(L_frame, 320)) + IF( EQ_16( L_frame, 320 ) ) { - *enr_q = Mult_32_16(*enr_q, 26214); /*x 0.8 to get /160*/ - i = norm_l(*enr_q); - *enr_q = L_shl(*enr_q, i); - exp_enrq = add(i, exp_enrq); + *enr_q = Mult_32_16( *enr_q, 26214 ); /*x 0.8 to get /160*/ + i = norm_l( *enr_q ); + *enr_q = L_shl( *enr_q, i ); + exp_enrq = add( i, exp_enrq ); } } ELSE { - exp_enrq = sub(exp_enrq, add(Q_new, Q_new)); - enr_q_tmp /*Q30 exp2+exp_enrq*/ = BASOP_Util_Divide3216_Scale(*enr_q /*Q31*/, L_frame2 /*Q0*/, &exp2); - *enr_q = L_shr(L_deposit_l(enr_q_tmp),sub(30,add(exp2,exp_enrq))); /*Q0*/ - *enr_q = L_add(*enr_q, 1); + exp_enrq = sub( exp_enrq, add( Q_new, Q_new ) ); + enr_q_tmp /*Q30 exp2+exp_enrq*/ = BASOP_Util_Divide3216_Scale( *enr_q /*Q31*/, L_frame2 /*Q0*/, &exp2 ); + *enr_q = L_shr( L_deposit_l( enr_q_tmp ), sub( 30, add( exp2, exp_enrq ) ) ); /*Q0*/ + *enr_q = L_add( *enr_q, 1 ); move32(); exp_enrq = 0; move16(); } + } - - - - - - } - - return exp_enrq; + return exp_enrq; } /*------------------------------------------------------------------------* @@ -322,81 +316,83 @@ Word16 frame_ener_fx( * * Compute pitch-synchronous energy at the frame end *------------------------------------------------------------------------*/ -Word16 frame_energy_fx( /* o : Frame energy in Q8 */ - Word16 L_frame, - const Word16 *pitch, /* i : pitch values for each subframe Q6 */ - const Word16 *speech, /* i : pointer to speech signal for E computation Q_syn*/ - const Word16 lp_speech, /* i : long term active speech energy average Q8 */ - Word16 *frame_ener, /* o : pitch-synchronous energy at frame end Q8 */ - const Word16 Q_syn /* i : Synthesis scaling */ +Word16 frame_energy_fx( /* o : Frame energy in Q8 */ + Word16 L_frame, + const Word16 *pitch, /* i : pitch values for each subframe Q6 */ + const Word16 *speech, /* i : pointer to speech signal for E computation Q_syn*/ + const Word16 lp_speech, /* i : long term active speech energy average Q8 */ + Word16 *frame_ener, /* o : pitch-synchronous energy at frame end Q8 */ + const Word16 Q_syn /* i : Synthesis scaling */ ) { - Word32 Ltmp; - const Word16 *pt1; - Word16 tmp16, exp1, exp2, tmp1, tmp2; - Word16 len, enern; + Word32 Ltmp; + const Word16 *pt1; + Word16 tmp16, exp1, exp2, tmp1, tmp2; + Word16 len, enern; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; + Flag Overflow = 0; #endif - /* len = (0.5f * (pitch[2]/64.0 + pitch[3]/64.0) + 0.5f) */ + /* len = (0.5f * (pitch[2]/64.0 + pitch[3]/64.0) + 0.5f) */ #ifdef BASOP_NOGLOB - len = mult_r(add_o(pitch[2], pitch[3], &Overflow), 256); + len = mult_r( add_o( pitch[2], pitch[3], &Overflow ), 256 ); #else - len = mult_r(add(pitch[2], pitch[3]), 256); + len = mult_r( add( pitch[2], pitch[3] ), 256 ); #endif - if (LT_16(len, L_SUBFR)) - { - len = shl(len, 1); - } - pt1 = speech + sub(L_frame, len); + if ( LT_16( len, L_SUBFR ) ) + { + len = shl( len, 1 ); + } + pt1 = speech + sub( L_frame, len ); - /* *frame_ener = 10.0f * log10(dot_product(pt1, pt1, len) / (float)len) */ + /* *frame_ener = 10.0f * log10(dot_product(pt1, pt1, len) / (float)len) */ - tmp1 = norm_s(len); - tmp2 = shl(len, tmp1); - tmp1 = sub(15, tmp1); + tmp1 = norm_s( len ); + tmp2 = shl( len, tmp1 ); + tmp1 = sub( 15, tmp1 ); - Ltmp = Dot_productSq16HQ(0, pt1, len, &exp1); - exp1 = sub(exp1, shl(Q_syn, 1)); - exp1 = sub(exp1, 1); /* compensation of leftshift caused by mac operation in dot_productSq16HQ */ - tmp16 = BASOP_Util_Divide3216_Scale(Ltmp, len, &exp2); + Ltmp = Dot_productSq16HQ( 0, pt1, len, &exp1 ); + exp1 = sub( exp1, shl( Q_syn, 1 ) ); + exp1 = sub( exp1, 1 ); /* compensation of leftshift caused by mac operation in dot_productSq16HQ */ + tmp16 = BASOP_Util_Divide3216_Scale( Ltmp, len, &exp2 ); - exp1 = add(exp1, exp2); - exp1 = add(exp1, 1); /* compensate result of division Q-1 */ + exp1 = add( exp1, exp2 ); + exp1 = add( exp1, 1 ); /* compensate result of division Q-1 */ - tmp2 = norm_s(tmp16); - Ltmp = L_shl(L_deposit_h(tmp16), tmp2); /*Q16, (exp1-tmp2) = Q31, exp1-tmp2+15*/ + tmp2 = norm_s( tmp16 ); + Ltmp = L_shl( L_deposit_h( tmp16 ), tmp2 ); /*Q16, (exp1-tmp2) = Q31, exp1-tmp2+15*/ - Ltmp = BASOP_Util_Log2(Ltmp);/*Q(31-6) = Q25*/ - exp1 = sub(15 + exp1, tmp2); + Ltmp = BASOP_Util_Log2( Ltmp ); /*Q(31-6) = Q25*/ + exp1 = sub( 15 + exp1, tmp2 ); - /*add ld(2^exp1)=exp1 but check format, first*/ - tmp16 = sub(sub(15, norm_s(exp1)), 5); /*factor to shift Ltmp and exp1 with (shr) to avoid overflows when adding*/ + /*add ld(2^exp1)=exp1 but check format, first*/ + tmp16 = sub( sub( 15, norm_s( exp1 ) ), 5 ); /*factor to shift Ltmp and exp1 with (shr) to avoid overflows when adding*/ #ifdef BASOP_NOGLOB - Ltmp = L_shr_o(Ltmp, tmp16, &Overflow); /*Q25, tmp16*/ + Ltmp = L_shr_o( Ltmp, tmp16, &Overflow ); /*Q25, tmp16*/ #else - Ltmp = L_shr(Ltmp, tmp16); /*Q25, tmp16*/ + Ltmp = L_shr( Ltmp, tmp16 ); /*Q25, tmp16*/ #endif - exp2 = shr(exp1, tmp16); /*Q0 , tmp16*/ + exp2 = shr( exp1, tmp16 ); /*Q0 , tmp16*/ #ifdef BASOP_NOGLOB - Ltmp = L_add_o(Ltmp, L_shl(L_deposit_l(exp2), 25), &Overflow); /*Q25, tmp16, normalized*/ + Ltmp = L_add_o( Ltmp, L_shl( L_deposit_l( exp2 ), 25 ), &Overflow ); /*Q25, tmp16, normalized*/ #else - Ltmp = L_add(Ltmp, L_shl(L_deposit_l(exp2), 25)); /*Q25, tmp16, normalized*/ + Ltmp = L_add( Ltmp, L_shl( L_deposit_l( exp2 ), 25 ) ); /*Q25, tmp16, normalized*/ #endif /*make 10*log10 out of log2*/ - Ltmp = Mpy_32_16_1(Ltmp, LG10); /*Q25,tmp16 * Q13 = Q23, tmp16*/ + Ltmp = Mpy_32_16_1( Ltmp, LG10 ); /*Q25,tmp16 * Q13 = Q23, tmp16*/ #ifdef BASOP_NOGLOB - * frame_ener = extract_h(L_shl_o(Ltmp, add(tmp16, 1), &Overflow));/*Q8*/ move16(); - enern = sub_o(*frame_ener, lp_speech, &Overflow); /*Q8*/ + *frame_ener = extract_h( L_shl_o( Ltmp, add( tmp16, 1 ), &Overflow ) ); /*Q8*/ + move16(); + enern = sub_o( *frame_ener, lp_speech, &Overflow ); /*Q8*/ #else - * frame_ener = extract_h(L_shl(Ltmp, add(tmp16, 1)));/*Q8*/ move16(); - enern = sub(*frame_ener, lp_speech); /*Q8*/ + *frame_ener = extract_h( L_shl( Ltmp, add( tmp16, 1 ) ) ); /*Q8*/ + move16(); + enern = sub( *frame_ener, lp_speech ); /*Q8*/ #endif - return enern; + return enern; } diff --git a/lib_com/gain_inov_fx.c b/lib_com/gain_inov_fx.c index 5f4232f40..7f767c028 100644 --- a/lib_com/gain_inov_fx.c +++ b/lib_com/gain_inov_fx.c @@ -11,46 +11,45 @@ #include "rom_com.h" -Word32 calc_gain_inov( /* returns innovation gain Q16 */ - const Word16 *code, /* i : algebraic excitation Q9 */ - const Word16 lcode, /* i : Subframe size Q0 */ - Word32 *dotp, /* o : intermediate result Q31-e */ - Word16 *dotp_e /* o : intermediate result exponent Q0 */ +Word32 calc_gain_inov( /* returns innovation gain Q16 */ + const Word16 *code, /* i : algebraic excitation Q9 */ + const Word16 lcode, /* i : Subframe size Q0 */ + Word32 *dotp, /* o : intermediate result Q31-e */ + Word16 *dotp_e /* o : intermediate result exponent Q0 */ ) { Word32 L_tmp; Word16 exp_L_tmp, i; /* L_tmp = dot_product(code, code, lcode) + 0.01 */ - L_tmp = Dot_product12_offs(code, code, lcode, &exp_L_tmp, 2621l/*0.01f/2.0f Q19*/); - exp_L_tmp = sub(exp_L_tmp, 18); + L_tmp = Dot_product12_offs( code, code, lcode, &exp_L_tmp, 2621l /*0.01f/2.0f Q19*/ ); + exp_L_tmp = sub( exp_L_tmp, 18 ); /* gain_inov = 1.0f / sqrt((dot_product(code, code, lcode) + 0.01) / lcode) */ /* Note: lcode is in range: 32,40,64,80 */ - assert((lcode == 32) || (lcode == 40) || (lcode == 64) || (lcode == 80)); - if (s_and(lcode, sub(lcode, 1)) != 0) + assert( ( lcode == 32 ) || ( lcode == 40 ) || ( lcode == 64 ) || ( lcode == 80 ) ); + if ( s_and( lcode, sub( lcode, 1 ) ) != 0 ) { - L_tmp = Mpy_32_32(L_tmp, 1717986918l/*64.0/80.0 Q31*/); + L_tmp = Mpy_32_32( L_tmp, 1717986918l /*64.0/80.0 Q31*/ ); } - exp_L_tmp = sub(exp_L_tmp, sub(14, norm_s(lcode))); + exp_L_tmp = sub( exp_L_tmp, sub( 14, norm_s( lcode ) ) ); - i = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, i); - exp_L_tmp = sub(exp_L_tmp, i); + i = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, i ); + exp_L_tmp = sub( exp_L_tmp, i ); - if (dotp != NULL) + if ( dotp != NULL ) { *dotp = L_tmp; move32(); } - if (dotp_e != NULL) + if ( dotp_e != NULL ) { *dotp_e = exp_L_tmp; move16(); } - L_tmp = ISqrt32norm(L_tmp, &exp_L_tmp); + L_tmp = ISqrt32norm( L_tmp, &exp_L_tmp ); - return L_shl(L_tmp, sub(exp_L_tmp, 15)); /* 15Q16 */ + return L_shl( L_tmp, sub( exp_L_tmp, 15 ) ); /* 15Q16 */ } - diff --git a/lib_com/get_gain.c b/lib_com/get_gain.c index 73acb4569..e6288ad01 100644 --- a/lib_com/get_gain.c +++ b/lib_com/get_gain.c @@ -77,106 +77,105 @@ float get_gain_flt( //TO DO rename get_gain_flt to get_gain once macro introduced #endif -Word32 get_gain( /* output: codebook gain (adaptive or fixed) Q16 */ - const Word16 x[], /* input : target signal */ - const Word16 y[], /* input : filtered codebook excitation */ - const Word16 n /* input : segment length */ +Word32 get_gain( /* output: codebook gain (adaptive or fixed) Q16 */ + const Word16 x[], /* input : target signal */ + const Word16 y[], /* input : filtered codebook excitation */ + const Word16 n /* input : segment length */ ) { - Word32 tcorr, tener, Lgain; - Word16 exp_c, exp_e, exp, tmp; + Word32 tcorr, tener, Lgain; + Word16 exp_c, exp_e, exp, tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; + Flag Overflow = 0; #endif - tcorr = L_deposit_l(0); - tener = L_deposit_l(0); + tcorr = L_deposit_l( 0 ); + tener = L_deposit_l( 0 ); + /*----------------------------------------------------------------* + * Find gain based on inter-correlation product + *----------------------------------------------------------------*/ - /*----------------------------------------------------------------* - * Find gain based on inter-correlation product - *----------------------------------------------------------------*/ - - tcorr = Dot_product16HQ(0, x, y, n, &exp_c); - tener = Dot_productSq16HQ(0, y, n, &exp_e); + tcorr = Dot_product16HQ( 0, x, y, n, &exp_c ); + tener = Dot_productSq16HQ( 0, y, n, &exp_e ); #ifdef BASOP_NOGLOB - BASOP_Util_Divide_MantExp(round_fx_o(tcorr, &Overflow), exp_c, s_max(round_fx_o(tener, &Overflow), 1), exp_e, &tmp, &exp); - Lgain = L_shl_o(L_deposit_l(tmp)/*Q15*/, add(1, exp), &Overflow)/*Q16*/; + BASOP_Util_Divide_MantExp( round_fx_o( tcorr, &Overflow ), exp_c, s_max( round_fx_o( tener, &Overflow ), 1 ), exp_e, &tmp, &exp ); + Lgain = L_shl_o( L_deposit_l( tmp ) /*Q15*/, add( 1, exp ), &Overflow ) /*Q16*/; #else - BASOP_Util_Divide_MantExp(round_fx(tcorr), exp_c, s_max(round_fx(tener), 1), exp_e, &tmp, &exp); - Lgain = L_shl(L_deposit_l(tmp)/*Q15*/, add(1, exp))/*Q16*/; + BASOP_Util_Divide_MantExp( round_fx( tcorr ), exp_c, s_max( round_fx( tener ), 1 ), exp_e, &tmp, &exp ); + Lgain = L_shl( L_deposit_l( tmp ) /*Q15*/, add( 1, exp ) ) /*Q16*/; #endif - return Lgain; + return Lgain; } -Word32 get_gain2( /* output: codebook gain (adaptive or fixed) Q16 */ - const Word16 x[], /* input : target signal */ - const Word16 y[], /* input : filtered codebook excitation */ - const Word16 n /* input : segment length */ +Word32 get_gain2( /* output: codebook gain (adaptive or fixed) Q16 */ + const Word16 x[], /* input : target signal */ + const Word16 y[], /* input : filtered codebook excitation */ + const Word16 n /* input : segment length */ ) { - Word32 tcorr, tener, Lgain; - Word16 m_corr, m_ener, negative, Q_corr, Q_ener; + Word32 tcorr, tener, Lgain; + Word16 m_corr, m_ener, negative, Q_corr, Q_ener; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; + Flag Overflow = 0; #endif - negative = 0; - move16(); + negative = 0; + move16(); - /*----------------------------------------------------------------* - * Find gain based on inter-correlation product - *----------------------------------------------------------------*/ - tcorr = Dot_product16HQ(0, x, y, n, &Q_corr); - tener = Dot_productSq16HQ(0, y, n, &Q_ener); + /*----------------------------------------------------------------* + * Find gain based on inter-correlation product + *----------------------------------------------------------------*/ + tcorr = Dot_product16HQ( 0, x, y, n, &Q_corr ); + tener = Dot_productSq16HQ( 0, y, n, &Q_ener ); - tener = L_max(tener, 1); + tener = L_max( tener, 1 ); - if (tcorr <= 0) - { - negative = 1; - move16(); - } - BASOP_SATURATE_WARNING_OFF_EVS /*tcorr max be negative maxvall - not critical*/ - tcorr = L_abs(tcorr); - BASOP_SATURATE_WARNING_ON_EVS - - m_corr = extract_h(tcorr); - - m_ener = extract_h(tener); - - IF(GT_16(m_corr, m_ener)) - { - m_corr = shr(m_corr, 1); - Q_corr = add(Q_corr, 1); - } - if (m_ener == 0) - { - move16(); - m_corr = 0x7FFF; - } - if (m_ener != 0) - { - m_corr = div_s(m_corr, m_ener); - } + if ( tcorr <= 0 ) + { + negative = 1; + move16(); + } + BASOP_SATURATE_WARNING_OFF_EVS /*tcorr max be negative maxvall - not critical*/ + tcorr = L_abs( tcorr ); + BASOP_SATURATE_WARNING_ON_EVS + + m_corr = extract_h( tcorr ); - Q_corr = sub(Q_corr, Q_ener); + m_ener = extract_h( tener ); + + IF( GT_16( m_corr, m_ener ) ) + { + m_corr = shr( m_corr, 1 ); + Q_corr = add( Q_corr, 1 ); + } + if ( m_ener == 0 ) + { + move16(); + m_corr = 0x7FFF; + } + if ( m_ener != 0 ) + { + m_corr = div_s( m_corr, m_ener ); + } + + Q_corr = sub( Q_corr, Q_ener ); #ifdef BASOP_NOGLOB - Lgain = L_shl_o(L_deposit_l(m_corr), add(Q_corr, 1), &Overflow); /* Lgain in Q16 */ + Lgain = L_shl_o( L_deposit_l( m_corr ), add( Q_corr, 1 ), &Overflow ); /* Lgain in Q16 */ #else - Lgain = L_shl(L_deposit_l(m_corr), add(Q_corr, 1)); /* Lgain in Q16 */ + Lgain = L_shl( L_deposit_l( m_corr ), add( Q_corr, 1 ) ); /* Lgain in Q16 */ #endif - if (negative != 0) - { - Lgain = L_negate(Lgain); /* Lgain in Q16 */ - } + if ( negative != 0 ) + { + Lgain = L_negate( Lgain ); /* Lgain in Q16 */ + } - return Lgain; + return Lgain; } diff --git a/lib_com/gs_bitallocation_fx.c b/lib_com/gs_bitallocation_fx.c index 01466f24f..b3da54d2a 100644 --- a/lib_com/gs_bitallocation_fx.c +++ b/lib_com/gs_bitallocation_fx.c @@ -2,12 +2,12 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "assert.h" /* Debug prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "assert.h" /* Debug prototypes */ #include "stl.h" /*==================================================================================*/ @@ -64,7 +64,7 @@ void bands_and_bit_alloc_fx( { Word16 bandoffset, i, j, nb_bands_max, bit_new_bands, bit_tmp, st_band, nb_bands; - Word16 ener_vec[MBANDS_GN_BITALLOC16k]; /*Q12 */ + Word16 ener_vec[MBANDS_GN_BITALLOC16k]; /*Q12 */ Word16 nb_tot_bands = 16; Word16 bit_index, bit_index_mem, imax; Word32 L_tmp; @@ -77,40 +77,43 @@ void bands_and_bit_alloc_fx( Word32 bits_per_bands[MBANDS_GN_BITALLOC16k]; Word16 w_sum_bit; #ifdef REMOVE_IVAS_UNUSED_PARAMETERS_WARNING - (void)GSC_IVAS_mode; - (void)element_mode; + (void) GSC_IVAS_mode; + (void) element_mode; #endif #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif nb_tot_bands = MBANDS_GN; move16(); - if (EQ_16(L_frame, L_FRAME16k)) + if ( EQ_16( L_frame, L_FRAME16k ) ) { nb_tot_bands = MBANDS_GN_BITALLOC16k; move16(); } - Copy( Ener_per_bd_iQ, Ener_per_bd_iQ_tmp, nb_tot_bands); + Copy( Ener_per_bd_iQ, Ener_per_bd_iQ_tmp, nb_tot_bands ); - set32_fx( bits_per_bands, 0, MBANDS_GN_BITALLOC16k); - set16_fx( out_bits_per_bands, 0, MBANDS_GN_BITALLOC16k); + set32_fx( bits_per_bands, 0, MBANDS_GN_BITALLOC16k ); + set16_fx( out_bits_per_bands, 0, MBANDS_GN_BITALLOC16k ); /* To adapt current energy band to PVQ freq band for sorting*/ #ifdef BASOP_NOGLOB - ener_vec[0] = add_o(Ener_per_bd_iQ[0],Ener_per_bd_iQ[1], &Overflow); /*Q12 */ -#else /* BASOP_NOGLOB */ - ener_vec[0] = add(Ener_per_bd_iQ[0],Ener_per_bd_iQ[1]); /*Q12 */ + ener_vec[0] = add_o( Ener_per_bd_iQ[0], Ener_per_bd_iQ[1], &Overflow ); /*Q12 */ +#else /* BASOP_NOGLOB */ + ener_vec[0] = add( Ener_per_bd_iQ[0], Ener_per_bd_iQ[1] ); /*Q12 */ #endif - Copy( Ener_per_bd_iQ_tmp+1, ener_vec, MBANDS_GN-1); /*Q12 */ - ener_vec[MBANDS_GN-1] = ener_vec[MBANDS_GN-2]; + Copy( Ener_per_bd_iQ_tmp + 1, ener_vec, MBANDS_GN - 1 ); /*Q12 */ + ener_vec[MBANDS_GN - 1] = ener_vec[MBANDS_GN - 2]; move16(); - IF (EQ_16(L_frame, L_FRAME16k)) + IF( EQ_16( L_frame, L_FRAME16k ) ) { ener_vec[16] = Ener_per_bd_iQ[16]; - ener_vec[17] = mac_r(L_mult(Ener_per_bd_iQ[16], 16384), Ener_per_bd_iQ[17],16384); + ener_vec[17] = mac_r( L_mult( Ener_per_bd_iQ[16], 16384 ), Ener_per_bd_iQ[17], 16384 ); ener_vec[18] = Ener_per_bd_iQ[17]; - ener_vec[19] = mult_r(Ener_per_bd_iQ[17], 26214); - move16(); move16(); move16(); move16(); + ener_vec[19] = mult_r( Ener_per_bd_iQ[17], 26214 ); + move16(); + move16(); + move16(); + move16(); } /*------------------------------------------------------------------------ @@ -123,7 +126,7 @@ void bands_and_bit_alloc_fx( bit_new_bands = 5; move16(); #ifdef ADD_LRTD - if (GT_32(core_brate, ACELP_16k40) && EQ_16(L_frame, L_FRAME16k)) + if ( GT_32( core_brate, ACELP_16k40 ) && EQ_16( L_frame, L_FRAME16k ) ) { bit_new_bands = 7; move16(); @@ -131,51 +134,51 @@ void bands_and_bit_alloc_fx( i = 0; move16(); - WHILE (LT_16(i, SIZE_BRATE_INTERMED_TBL)) + WHILE( LT_16( i, SIZE_BRATE_INTERMED_TBL ) ) { - IF (LE_32(core_brate, brate_intermed_tbl[i])) + IF( LE_32( core_brate, brate_intermed_tbl[i] ) ) { BREAK; } - IF (EQ_32(brate_intermed_tbl[i], ACELP_24k40)) + IF( EQ_32( brate_intermed_tbl[i], ACELP_24k40 ) ) { BREAK; } - i = add(i,1); + i = add( i, 1 ); } - if (GT_16(element_mode, EVS_MONO) && EQ_16(coder_type, AUDIO) && - LE_32(core_brate, STEREO_GSC_BIT_RATE_ALLOC) && EQ_32(brate_intermed_tbl[i], ACELP_9k60)) /* Bit allocation should be mapped to 8 kb/s instead of 9.6 kb/s in this case */ + if ( GT_16( element_mode, EVS_MONO ) && EQ_16( coder_type, AUDIO ) && + LE_32( core_brate, STEREO_GSC_BIT_RATE_ALLOC ) && EQ_32( brate_intermed_tbl[i], ACELP_9k60 ) ) /* Bit allocation should be mapped to 8 kb/s instead of 9.6 kb/s in this case */ { - i = sub(i,1); + i = sub( i, 1 ); } - bit_index = i_mult2( BRATE2IDX_fx(brate_intermed_tbl[i]), 17); + bit_index = i_mult2( BRATE2IDX_fx( brate_intermed_tbl[i] ), 17 ); #else - bit_index = i_mult2(BRATE2IDX_fx(core_brate),17); + bit_index = i_mult2( BRATE2IDX_fx( core_brate ), 17 ); #endif bit_index_mem = bit_index; move16(); test(); test(); - IF( (EQ_16(coder_type,AUDIO)||EQ_16(coder_type,INACTIVE))&&EQ_16(bwidth,NB)) + IF( ( EQ_16( coder_type, AUDIO ) || EQ_16( coder_type, INACTIVE ) ) && EQ_16( bwidth, NB ) ) { - IF(GE_32(core_brate,ACELP_9k60)) + IF( GE_32( core_brate, ACELP_9k60 ) ) { /* *bit = (short)(core_brate*(1.0f/50) + 0.5f) - bits_used - 25; */ - L_tmp = Mult_32_16(core_brate,20971); - tmp = extract_l(L_shr_r(L_tmp,5)); - *bit = sub(sub(tmp,bits_used), 25); + L_tmp = Mult_32_16( core_brate, 20971 ); + tmp = extract_l( L_shr_r( L_tmp, 5 ) ); + *bit = sub( sub( tmp, bits_used ), 25 ); move16(); } ELSE { - L_tmp = Mult_32_16(core_brate,20971); - tmp = extract_l(L_shr_r(L_tmp,5)); - *bit = sub(sub(tmp,bits_used), 21); + L_tmp = Mult_32_16( core_brate, 20971 ); + tmp = extract_l( L_shr_r( L_tmp, 5 ) ); + *bit = sub( sub( tmp, bits_used ), 21 ); move16(); } nb_tot_bands = 10; @@ -185,53 +188,53 @@ void bands_and_bit_alloc_fx( { /* *bit = (short)(core_brate*(1.0f/50) + 0.5f) - bits_used - GSC_freq_bits[bit_index]; */ - L_tmp = Mult_32_16(core_brate,20971); - tmp = extract_l(L_shr_r(L_tmp,5)); - *bit = sub(sub(tmp,bits_used),GSC_freq_bits[bit_index]); + L_tmp = Mult_32_16( core_brate, 20971 ); + tmp = extract_l( L_shr_r( L_tmp, 5 ) ); + *bit = sub( sub( tmp, bits_used ), GSC_freq_bits[bit_index] ); move16(); } #ifdef ADD_LRTD - if (L_frame == L_FRAME16k) - { - *bit -= 8; - } + if ( L_frame == L_FRAME16k ) + { + *bit -= 8; + } - if (coder_type == INACTIVE && core_brate <= GSC_LRES_GAINQ_LIMIT) /* can happen only for 2nd channel inactive */ + if ( coder_type == INACTIVE && core_brate <= GSC_LRES_GAINQ_LIMIT ) /* can happen only for 2nd channel inactive */ { *bit += GSC_LRES_NB_NITS; } - if (*bit > 0) + if ( *bit > 0 ) { - if (GSC_IVAS_mode > 0) + if ( GSC_IVAS_mode > 0 ) { SWB_bit_budget = *bit; st_band = 5; - set_f(bits_per_bands, 0, MBANDS_GN_BITALLOC16k); + set_f( bits_per_bands, 0, MBANDS_GN_BITALLOC16k ); /* 2- Decide the pourcentage of bits allocated to LF (between 50-75%) depending of the temporal contribution in GSC */ - bit_fracf = (-0.125f * Diff_len + 76.0f) / 100; - bit_fracf = check_bounds(bit_fracf, 0.50f, 0.75f); + bit_fracf = ( -0.125f * Diff_len + 76.0f ) / 100; + bit_fracf = check_bounds( bit_fracf, 0.50f, 0.75f ); /* Adjusment of the bitrate between LF and HF base on the content type */ /* 1 = new GSC bit alloc 2 = GSC bit alloc for tc frame 3 = more music like (should not happen often given music is coded with dft) */ - if (GSC_IVAS_mode <= 3) + if ( GSC_IVAS_mode <= 3 ) { nb_bands_max -= 6; } - if (GSC_IVAS_mode == 2) + if ( GSC_IVAS_mode == 2 ) { bit_fracf += 0.1f; nb_bands_max--; } - if (GSC_IVAS_mode == 3) + if ( GSC_IVAS_mode == 3 ) { bit_fracf -= 0.1f; nb_bands_max += 3; @@ -240,28 +243,28 @@ void bands_and_bit_alloc_fx( /* First find how much we want to share between LF and HF, at low bitrate, a miminum of bits is needed in LF by limitating the number of bands*/ /* Adjust the number of band based on the content type and bitrate */ nb_bands_adj = 1.0f; - if (GSC_IVAS_mode == 1 && core_brate < GSC_L_RATE_STG) + if ( GSC_IVAS_mode == 1 && core_brate < GSC_L_RATE_STG ) { nb_bands_adj = 0.0125f * SWB_bit_budget - 0.75f; } - else if (GSC_IVAS_mode != 2 && core_brate > GSC_H_RATE_STG) + else if ( GSC_IVAS_mode != 2 && core_brate > GSC_H_RATE_STG ) { nb_bands_adj = 0.02f * SWB_bit_budget - 1.2f; } - nb_bands_max = (int16_t)(nb_bands_max * nb_bands_adj + 0.5f); - nb_bands_max = check_bounds_s(nb_bands_max, 5, nb_tot_bands); + nb_bands_max = (int16_t) ( nb_bands_max * nb_bands_adj + 0.5f ); + nb_bands_max = check_bounds_s( nb_bands_max, 5, nb_tot_bands ); bit_fracf *= SWB_bit_budget; /* Estimation of the number of bit used in HF */ /* with only the first weigthing The number of bits in max_ener_band[st_band-1] = 17% of bit_fracf */ mb = .17f * bit_fracf; - mp = (2.0f * DSR_NB_PULSE); - if (core_brate < GSC_L_RATE_STG && GSC_IVAS_mode == 3) + mp = ( 2.0f * DSR_NB_PULSE ); + if ( core_brate < GSC_L_RATE_STG && GSC_IVAS_mode == 3 ) { mp = 1.5f * DSR_NB_PULSE; } - else if (core_brate < GSC_L_RATE_STG) + else if ( core_brate < GSC_L_RATE_STG ) { mp = DSR_NB_PULSE; } @@ -269,12 +272,12 @@ void bands_and_bit_alloc_fx( /* We want max_ener_band[st_band] <= max_ener_band[st_band-1] and max_ener_band[nb_bands_max-1] <= max_ener_band[st_band]*/ /* We will estimate the number of bits to allocate of HF and put the remaining bits, if any, back on LF */ /* compute the total possible number of band to be coded */ - nb_tot_bands = (int16_t)((SWB_bit_budget - bit_fracf) / (mp + (mb - mp) / 2.0f)); - mp = min(mp, mb); - if (nb_tot_bands + st_band > nb_bands_max) + nb_tot_bands = (int16_t) ( ( SWB_bit_budget - bit_fracf ) / ( mp + ( mb - mp ) / 2.0f ) ); + mp = min( mp, mb ); + if ( nb_tot_bands + st_band > nb_bands_max ) { - bit_adj = ((mb + mp) / 2) * (nb_tot_bands + st_band - nb_bands_max); - bit_adj = max(0, bit_adj); + bit_adj = ( ( mb + mp ) / 2 ) * ( nb_tot_bands + st_band - nb_bands_max ); + bit_adj = max( 0, bit_adj ); nb_tot_bands = nb_bands_max - st_band; bit_fracf += bit_adj; } @@ -282,7 +285,7 @@ void bands_and_bit_alloc_fx( /* Allocate bits to LF */ etmp = 0.23f; - for (j = 0; j < st_band; j++) + for ( j = 0; j < st_band; j++ ) { i = j; max_ener_band[j] = i; @@ -294,19 +297,19 @@ void bands_and_bit_alloc_fx( SWB_bit_budget -= bit_fracf; /* Find low energy band in HF */ - set_s(nb_pulse_per_band, 2, MBANDS_GN_BITALLOC16k); - for (i = st_band + 2; i < nb_tot_bands - 1; i++) + set_s( nb_pulse_per_band, 2, MBANDS_GN_BITALLOC16k ); + for ( i = st_band + 2; i < nb_tot_bands - 1; i++ ) { - if (ener_vec[i] < ener_vec[i - 1] && ener_vec[i] < ener_vec[i + 1]) + if ( ener_vec[i] < ener_vec[i - 1] && ener_vec[i] < ener_vec[i + 1] ) { nb_pulse_per_band[i] = 1; } } - for (j = st_band; j < nb_tot_bands; j++) + for ( j = st_band; j < nb_tot_bands; j++ ) { - if (j > 6) + if ( j > 6 ) { - i = maximum(ener_vec, nb_tot_bands, &etmp); + i = maximum( ener_vec, nb_tot_bands, &etmp ); } else { @@ -318,16 +321,16 @@ void bands_and_bit_alloc_fx( } /* Recompute the final bit distribution for HF */ - if (nb_tot_bands > st_band) + if ( nb_tot_bands > st_band ) { bit_fracf = DSR_NB_PULSE; - mb = (SWB_bit_budget * 2 / (nb_tot_bands - st_band)) - mp; - bit_fracf = (mb - mp) / (nb_tot_bands - st_band); + mb = ( SWB_bit_budget * 2 / ( nb_tot_bands - st_band ) ) - mp; + bit_fracf = ( mb - mp ) / ( nb_tot_bands - st_band ); mb -= bit_fracf; /* Do the distribution */ - for (j = st_band; j < nb_tot_bands; j++) + for ( j = st_band; j < nb_tot_bands; j++ ) { - if (nb_pulse_per_band[max_ener_band[j]] > 1) + if ( nb_pulse_per_band[max_ener_band[j]] > 1 ) { bits_per_bands[max_ener_band[j]] = mb; } @@ -341,15 +344,15 @@ void bands_and_bit_alloc_fx( } /* Series of verification in case bit allocated != the budget */ - if (SWB_bit_budget > 0) + if ( SWB_bit_budget > 0 ) { i = st_band - 1; - while (SWB_bit_budget > 0) + while ( SWB_bit_budget > 0 ) { bits_per_bands[i]++; SWB_bit_budget--; i--; - if (i == -1) + if ( i == -1 ) { i = st_band - 1; } @@ -360,9 +363,9 @@ void bands_and_bit_alloc_fx( sum_bit = 0; j = 0; - for (i = 0; i < nb_bands; i++) + for ( i = 0; i < nb_bands; i++ ) { - if (bits_per_bands[i] > 112) + if ( bits_per_bands[i] > 112 ) { sum_bit += bits_per_bands[i] - 112; bits_per_bands[i] = 112; @@ -370,16 +373,16 @@ void bands_and_bit_alloc_fx( } /* safety check for overage bit reallocation */ - else if (bits_per_bands[i] + sum_bit / 3 > 112) + else if ( bits_per_bands[i] + sum_bit / 3 > 112 ) { j = i + 1; } } - if (sum_bit != 0) + if ( sum_bit != 0 ) { - sum_bit /= (nb_bands - j); - for (i = j; i < nb_bands; i++) + sum_bit /= ( nb_bands - j ); + for ( i = j; i < nb_bands; i++ ) { bits_per_bands[i] += sum_bit; } @@ -387,91 +390,91 @@ void bands_and_bit_alloc_fx( } else #endif - IF(EQ_16(GSC_noisy_speech, 1)) - { - SWB_bit_budget = *bit; - move16(); - nb_bands = 5; - move16(); + IF( EQ_16( GSC_noisy_speech, 1 ) ) + { + SWB_bit_budget = *bit; + move16(); + nb_bands = 5; + move16(); #ifdef ADD_LRTD - fzero_val = 0.0f; - if (element_mode > EVS_MONO) - { - fzero_val = MIN16B_FLT; - } + fzero_val = 0.0f; + if ( element_mode > EVS_MONO ) + { + fzero_val = MIN16B_FLT; + } - if (coder_type == UNVOICED && element_mode > EVS_MONO) - { - nb_bands = 3; - if (SWB_bit_budget > 20) + if ( coder_type == UNVOICED && element_mode > EVS_MONO ) { - nb_bands = 5; + nb_bands = 3; + if ( SWB_bit_budget > 20 ) + { + nb_bands = 5; + } + } + else if ( bwidth < SWB ) + { + nb_bands = 7; } - } - else if (bwidth < SWB) - { - nb_bands = 7; - } #endif - st_band = nb_bands; - move16(); + st_band = nb_bands; + move16(); - set32_fx(bits_per_bands, 0, MBANDS_GN); - /*bit_fracf = (1.0f/nb_bands)*(SWB_bit_budget); */ - bit_fracf = L_mult(div_s(1, nb_bands), shl(SWB_bit_budget, 2)); /* Q18 */ + set32_fx( bits_per_bands, 0, MBANDS_GN ); + /*bit_fracf = (1.0f/nb_bands)*(SWB_bit_budget); */ + bit_fracf = L_mult( div_s( 1, nb_bands ), shl( SWB_bit_budget, 2 ) ); /* Q18 */ - nb_tot_bands = sub(nb_bands_max, 6); - nb_tot_bands = s_min(nb_tot_bands, 16); + nb_tot_bands = sub( nb_bands_max, 6 ); + nb_tot_bands = s_min( nb_tot_bands, 16 ); - FOR(j = 0; j < 2; j++) - { - i = j; - move16(); - max_ener_band[j] = i; - move16(); - ener_vec[i] = 0; - move16(); - } -#ifdef ADD_LRTD - if (bwidth < SWB) - { - if (coder_type == UNVOICED && element_mode > EVS_MONO) + FOR( j = 0; j < 2; j++ ) { - nb_tot_bands = 5; - } -#endif - FOR(; j < nb_bands; j++) - { - i = maximum_fx(ener_vec, nb_tot_bands, &etmp); + i = j; + move16(); max_ener_band[j] = i; move16(); ener_vec[i] = 0; move16(); } #ifdef ADD_LRTD - } - else - { - for (; j < nb_bands; j++) + if ( bwidth < SWB ) { - i = maximum(ener_vec, nb_tot_bands, &etmp); - max_ener_band[j] = i; - ener_vec[i] = fzero_val; + if ( coder_type == UNVOICED && element_mode > EVS_MONO ) + { + nb_tot_bands = 5; + } +#endif + FOR( ; j < nb_bands; j++ ) + { + i = maximum_fx( ener_vec, nb_tot_bands, &etmp ); + max_ener_band[j] = i; + move16(); + ener_vec[i] = 0; + move16(); + } +#ifdef ADD_LRTD + } + else + { + for ( ; j < nb_bands; j++ ) + { + i = maximum( ener_vec, nb_tot_bands, &etmp ); + max_ener_band[j] = i; + ener_vec[i] = fzero_val; + } } - } #endif - set32_fx(bits_per_bands, bit_fracf, nb_bands); - } + set32_fx( bits_per_bands, bit_fracf, nb_bands ); + } ELSE { bit_index++; - bit_tmp = sub(*bit,GSC_freq_bits[bit_index]); + bit_tmp = sub( *bit, GSC_freq_bits[bit_index] ); bit_index++; - nb_bands_max = add(nb_bands_max,GSC_freq_bits[bit_index]); + nb_bands_max = add( nb_bands_max, GSC_freq_bits[bit_index] ); bit_index++; *pvq_len = 112; @@ -479,7 +482,7 @@ void bands_and_bit_alloc_fx( st_band = 7; move16(); #ifdef ADD_LRTD - if (L_frame == L_FRAME16k && core_brate > ACELP_16k40) + if ( L_frame == L_FRAME16k && core_brate > ACELP_16k40 ) { *pvq_len = 160; st_band = 10; @@ -488,29 +491,29 @@ void bands_and_bit_alloc_fx( bit_new_bands = 5; } #endif - IF(LE_32(core_brate,ACELP_9k60)) + IF( LE_32( core_brate, ACELP_9k60 ) ) { *pvq_len = 80; move16(); st_band = 5; move16(); - IF(Diff_len == 0) + IF( Diff_len == 0 ) { - nb_bands_max = add(nb_bands_max,2); - bit_tmp = sub(bit_tmp,13); + nb_bands_max = add( nb_bands_max, 2 ); + bit_tmp = sub( bit_tmp, 13 ); } } - ELSE IF(Diff_len == 0) + ELSE IF( Diff_len == 0 ) { - nb_bands_max = add(nb_bands_max,2); - bit_tmp = sub(bit_tmp,17); + nb_bands_max = add( nb_bands_max, 2 ); + bit_tmp = sub( bit_tmp, 17 ); } - nb_bands = shr(*pvq_len,4); + nb_bands = shr( *pvq_len, 4 ); #ifdef ADD_LRTD - nb_bands_max = min(nb_bands_max, MBANDS_GN_BITALLOC16k); + nb_bands_max = min( nb_bands_max, MBANDS_GN_BITALLOC16k ); #endif /*------------------------------------------------------------------------ * Ajustement of the maximum number of bands in function of the @@ -520,23 +523,23 @@ void bands_and_bit_alloc_fx( test(); test(); test(); - IF(EQ_16(coder_type,INACTIVE) || GE_16(noise_lev,NOISE_LEVEL_SP3)) + IF( EQ_16( coder_type, INACTIVE ) || GE_16( noise_lev, NOISE_LEVEL_SP3 ) ) { /* Probably classification error -> concentrate bits on LF */ #ifdef ADD_LRTD - if (L_frame == L_FRAME16k && core_brate >= ACELP_24k40) + if ( L_frame == L_FRAME16k && core_brate >= ACELP_24k40 ) { nb_bands_max = nb_tot_bands - 2; } - else if (core_brate >= ACELP_16k40) + else if ( core_brate >= ACELP_16k40 ) { nb_bands_max = nb_bands + 2; } else #endif - if (GE_32(core_brate,ACELP_8k00)) + if ( GE_32( core_brate, ACELP_8k00 ) ) { - nb_bands_max = add(nb_bands,1); + nb_bands_max = add( nb_bands, 1 ); } else { @@ -544,31 +547,31 @@ void bands_and_bit_alloc_fx( move16(); } } - ELSE IF(GE_16(noise_lev,NOISE_LEVEL_SP2) || - (LE_32(core_brate,ACELP_13k20) && GE_32(core_brate,ACELP_9k60) && cor_strong_limit == 0)) /* Very low dynamic, tend to speech, do not try to code HF at all */ + ELSE IF( GE_16( noise_lev, NOISE_LEVEL_SP2 ) || + ( LE_32( core_brate, ACELP_13k20 ) && GE_32( core_brate, ACELP_9k60 ) && cor_strong_limit == 0 ) ) /* Very low dynamic, tend to speech, do not try to code HF at all */ { - nb_bands_max = sub(nb_bands_max,2); + nb_bands_max = sub( nb_bands_max, 2 ); } - ELSE if (GE_16(noise_lev,NOISE_LEVEL_SP1)) /* Very low dynamic, tend to speech, code less HF */ + ELSE if ( GE_16( noise_lev, NOISE_LEVEL_SP1 ) ) /* Very low dynamic, tend to speech, code less HF */ { - nb_bands_max = sub(nb_bands_max,1); + nb_bands_max = sub( nb_bands_max, 1 ); } - #ifdef ADD_LRTD - if (L_frame == L_FRAME16k) +#ifdef ADD_LRTD + if ( L_frame == L_FRAME16k ) { - if (core_brate < ACELP_24k40) + if ( core_brate < ACELP_24k40 ) { nb_bands_max -= 4; } - else if (core_brate < ACELP_32k) + else if ( core_brate < ACELP_32k ) { - if (Diff_len > 0 || noise_lev >= NOISE_LEVEL_SP2) + if ( Diff_len > 0 || noise_lev >= NOISE_LEVEL_SP2 ) { nb_bands_max -= 2; bit_new_bands *= 2; } } - else if (core_brate >= ACELP_32k) + else if ( core_brate >= ACELP_32k ) { bit_new_bands *= 2; } @@ -576,7 +579,7 @@ void bands_and_bit_alloc_fx( #endif test(); - if (EQ_16(bwidth,NB) && GT_16(nb_bands_max,10)) + if ( EQ_16( bwidth, NB ) && GT_16( nb_bands_max, 10 ) ) { nb_bands_max = 10; move16(); @@ -585,24 +588,24 @@ void bands_and_bit_alloc_fx( /*------------------------------------------------------------------------ * Find extra number of band to code according to bit rate availables *-----------------------------------------------------------------------*/ - WHILE(GE_16(bit_tmp,bit_new_bands) && LE_16(nb_bands,sub(nb_bands_max,1))) + WHILE( GE_16( bit_tmp, bit_new_bands ) && LE_16( nb_bands, sub( nb_bands_max, 1 ) ) ) { - bit_tmp = sub(bit_tmp,bit_new_bands); - nb_bands = add(nb_bands,1); + bit_tmp = sub( bit_tmp, bit_new_bands ); + nb_bands = add( nb_bands, 1 ); } /*------------------------------------------------------------------------ * Fractional bits to distribute on the first x bands *-----------------------------------------------------------------------*/ #ifdef ADD_LRTD - if (L_frame == L_FRAME16k && core_brate > ACELP_32k) + if ( L_frame == L_FRAME16k && core_brate > ACELP_32k ) { bit_fracf = 0; } else #endif { - bit_fracf = L_mult(div_s(1, st_band), shl(bit_tmp, 2)); /* Q18 */ + bit_fracf = L_mult( div_s( 1, st_band ), shl( bit_tmp, 2 ) ); /* Q18 */ } /*------------------------------------------------------------------------ * Complete the bit allocation per frequency band @@ -610,19 +613,19 @@ void bands_and_bit_alloc_fx( imax = 5; move16(); - if (GT_32(core_brate,ACELP_9k60)) + if ( GT_32( core_brate, ACELP_9k60 ) ) { imax = 7; move16(); } - FOR(i = 0; i < imax; i++) + FOR( i = 0; i < imax; i++ ) { - bits_per_bands[i] = L_add(GSC_freq_bits_fx[bit_index],bit_fracf); - move32();/* Q18 */ - bit_index = add(bit_index,1); + bits_per_bands[i] = L_add( GSC_freq_bits_fx[bit_index], bit_fracf ); + move32(); /* Q18 */ + bit_index = add( bit_index, 1 ); } #ifdef ADD_LRTD - if (L_frame == L_FRAME16k && core_brate > ACELP_16k40) + if ( L_frame == L_FRAME16k && core_brate > ACELP_16k40 ) { bit_index = 0; i = imax - 1; @@ -630,29 +633,29 @@ void bands_and_bit_alloc_fx( i++; bit_index++; - for (; i < 10; i++) + for ( ; i < 10; i++ ) { bits_per_bands[i] += Compl_GSC_freq_bits[bit_index] + bit_fracf; bit_index++; } } #endif - IF(Diff_len == 0) + IF( Diff_len == 0 ) { - bit_index = add(bit_index_mem,10); - FOR(i = 0; i < 7; i++) + bit_index = add( bit_index_mem, 10 ); + FOR( i = 0; i < 7; i++ ) { - bits_per_bands[i] = L_add(bits_per_bands[i],GSC_freq_bits_fx[bit_index]); - move32();/*chk Q18 */ - bit_index = add(bit_index,1); + bits_per_bands[i] = L_add( bits_per_bands[i], GSC_freq_bits_fx[bit_index] ); + move32(); /*chk Q18 */ + bit_index = add( bit_index, 1 ); } } #ifdef ADD_LRTD - if (bit_fracf < 0) + if ( bit_fracf < 0 ) { - for (j = 0; j < nb_tot_bands; j++) + for ( j = 0; j < nb_tot_bands; j++ ) { - bits_per_bands[j] = max(bits_per_bands[j], 0); + bits_per_bands[j] = max( bits_per_bands[j], 0 ); } } @@ -661,18 +664,18 @@ void bands_and_bit_alloc_fx( * Complete the bit allocation per frequency band for 16kHz high brate mode *--------------------------------------------------------------------------*/ #ifdef ADD_LRTD - if (L_frame == L_FRAME16k && core_brate > ACELP_32k) + if ( L_frame == L_FRAME16k && core_brate > ACELP_32k ) { - for (j = st_band; j < nb_bands; j++) + for ( j = st_band; j < nb_bands; j++ ) { bits_per_bands[j] = bit_new_bands; } - bit_fracf = (1.0f / nb_bands) * (bit_tmp); + bit_fracf = ( 1.0f / nb_bands ) * ( bit_tmp ); - etmp = 2.0f * bit_fracf / (nb_bands + 1); + etmp = 2.0f * bit_fracf / ( nb_bands + 1 ); bit_fracf = etmp; - for (j = nb_bands - 1; j >= 0; j--) + for ( j = nb_bands - 1; j >= 0; j-- ) { bits_per_bands[j] += etmp; etmp += bit_fracf; @@ -681,9 +684,9 @@ void bands_and_bit_alloc_fx( else #endif { - FOR(j = st_band; j < nb_bands; j++) + FOR( j = st_band; j < nb_bands; j++ ) { - bits_per_bands[j] = L_shl(bit_new_bands, 18); + bits_per_bands[j] = L_shl( bit_new_bands, 18 ); move32(); /*chk Q18 */ } } @@ -693,36 +696,36 @@ void bands_and_bit_alloc_fx( * This is function of the spectral dynamic and the bitrate *--------------------------------------------------------------------------*/ - bandoffset = sub(nb_tot_bands,add(nb_bands,2)); + bandoffset = sub( nb_tot_bands, add( nb_bands, 2 ) ); test(); test(); test(); test(); test(); - IF(LE_16(noise_lev,NOISE_LEVEL_SP1a)) + IF( LE_16( noise_lev, NOISE_LEVEL_SP1a ) ) { - bandoffset = sub(bandoffset,1); + bandoffset = sub( bandoffset, 1 ); } - ELSE if ((LE_32(core_brate,ACELP_13k20) && (EQ_16(coder_type,INACTIVE) || GE_16(noise_lev,NOISE_LEVEL_SP3))) || - (LE_32(core_brate,ACELP_13k20) && GE_32(core_brate,ACELP_9k60) && cor_strong_limit == 0)) + ELSE if ( ( LE_32( core_brate, ACELP_13k20 ) && ( EQ_16( coder_type, INACTIVE ) || GE_16( noise_lev, NOISE_LEVEL_SP3 ) ) ) || + ( LE_32( core_brate, ACELP_13k20 ) && GE_32( core_brate, ACELP_9k60 ) && cor_strong_limit == 0 ) ) { - bandoffset = add(bandoffset,1); + bandoffset = add( bandoffset, 1 ); } - bandoffset = s_max(bandoffset ,0); + bandoffset = s_max( bandoffset, 0 ); /*-------------------------------------------------------------------------- * Initiazed sorted vector * For the first x bands to be included in th final sorted vector * Sort the remaining bands in decrease energy order *--------------------------------------------------------------------------*/ - FOR(j = 0; j < nb_tot_bands; j++) + FOR( j = 0; j < nb_tot_bands; j++ ) { max_ener_band[j] = -10; move16(); } - FOR(j = 0; j < st_band; j++) + FOR( j = 0; j < st_band; j++ ) { max_ener_band[j] = j; move16(); @@ -731,10 +734,10 @@ void bands_and_bit_alloc_fx( } pos = st_band; move16(); - FOR(; j < nb_bands; j++) + FOR( ; j < nb_bands; j++ ) { - i = maximum_fx(ener_vec, sub(nb_tot_bands,bandoffset), &etmp); - pos = s_max(pos,i); + i = maximum_fx( ener_vec, sub( nb_tot_bands, bandoffset ), &etmp ); + pos = s_max( pos, i ); max_ener_band[j] = i; move16(); ener_vec[i] = -10; @@ -745,87 +748,88 @@ void bands_and_bit_alloc_fx( test(); test(); test(); - IF(GT_16(sub(nb_tot_bands, bandoffset),nb_bands) && (GT_16(pos,7) && EQ_32(core_brate,ACELP_8k00)) && EQ_16(bwidth,WB)) + IF( GT_16( sub( nb_tot_bands, bandoffset ), nb_bands ) && ( GT_16( pos, 7 ) && EQ_32( core_brate, ACELP_8k00 ) ) && EQ_16( bwidth, WB ) ) { - band = sub(nb_tot_bands, add(bandoffset,nb_bands)); - FOR(j = 0; j < band; j++) + band = sub( nb_tot_bands, add( bandoffset, nb_bands ) ); + FOR( j = 0; j < band; j++ ) { - i = maximum_fx(ener_vec, sub(nb_tot_bands,bandoffset), &etmp); - max_ener_band[add(nb_bands,j)] = i; + i = maximum_fx( ener_vec, sub( nb_tot_bands, bandoffset ), &etmp ); + max_ener_band[add( nb_bands, j )] = i; move16(); ener_vec[i] = -10; move16(); - bits_per_bands[add(nb_bands,j)] = 1310720; + bits_per_bands[add( nb_bands, j )] = 1310720; move32(); /*Q18 */ } - nb_bands = add(nb_bands,band); + nb_bands = add( nb_bands, band ); - bit_tmp = i_mult2(band,5); + bit_tmp = i_mult2( band, 5 ); - IF(LE_16(band,2)) + IF( LE_16( band, 2 ) ) { - FOR(j = sub(st_band,1); j < nb_bands; j++) + FOR( j = sub( st_band, 1 ); j < nb_bands; j++ ) { - bits_per_bands[j] = L_add(bits_per_bands[j],262144); /*Q18 */ move32(); + bits_per_bands[j] = L_add( bits_per_bands[j], 262144 ); /*Q18 */ + move32(); } - bit_tmp = add(bit_tmp, add(sub(nb_bands, st_band) , 1)); + bit_tmp = add( bit_tmp, add( sub( nb_bands, st_band ), 1 ) ); } i = 0; move16(); j = 0; move16(); - FOR(; bit_tmp > 0; bit_tmp--) + FOR( ; bit_tmp > 0; bit_tmp-- ) { - bits_per_bands[j] = L_sub(bits_per_bands[j],262144); /*Q18 */ - j = add(j,1); - if (EQ_16(j,sub(st_band, i))) + bits_per_bands[j] = L_sub( bits_per_bands[j], 262144 ); /*Q18 */ + j = add( j, 1 ); + if ( EQ_16( j, sub( st_band, i ) ) ) { j = 0; move16(); } test(); - if (j == 0 && LT_16(i,sub(st_band, 1))) + if ( j == 0 && LT_16( i, sub( st_band, 1 ) ) ) { - i = add(i,1); + i = add( i, 1 ); } } } } - /*-------------------------------------------------------------------------- - * Bit sum verification for GSC inactive at very high rate - * The maximum number of bits per band of length 16 is 112 - * Redistribute the overage bits if needed - *--------------------------------------------------------------------------*/ + /*-------------------------------------------------------------------------- + * Bit sum verification for GSC inactive at very high rate + * The maximum number of bits per band of length 16 is 112 + * Redistribute the overage bits if needed + *--------------------------------------------------------------------------*/ sum_bit = 0; move16(); j = 0; move16(); - FOR(i = 0; i < nb_bands; i++) + FOR( i = 0; i < nb_bands; i++ ) { - L_tmp = Mult_32_16(sum_bit, 10923); + L_tmp = Mult_32_16( sum_bit, 10923 ); - IF(GT_32(bits_per_bands[i], 29360128)) /* 112 in Q18 */ + IF( GT_32( bits_per_bands[i], 29360128 ) ) /* 112 in Q18 */ { - sum_bit = L_add(sum_bit, L_sub(bits_per_bands[i], 29360128)); /* Q18 */ + sum_bit = L_add( sum_bit, L_sub( bits_per_bands[i], 29360128 ) ); /* Q18 */ bits_per_bands[i] = 29360128; move32(); - j = add(i, 1); + j = add( i, 1 ); } - ELSE if (GT_32(L_add(bits_per_bands[i], L_tmp), 29360128)) /* Q18 */ + ELSE if ( GT_32( L_add( bits_per_bands[i], L_tmp ), 29360128 ) ) /* Q18 */ { - j = add(i, 1); + j = add( i, 1 ); } } - IF(sum_bit != 0) + IF( sum_bit != 0 ) { - tmp = sub(nb_bands, j); - sum_bit = Mult_32_16(sum_bit, div_s(1, tmp)); /* Q18 */ - FOR(i = j; i < nb_bands; i++) + tmp = sub( nb_bands, j ); + sum_bit = Mult_32_16( sum_bit, div_s( 1, tmp ) ); /* Q18 */ + FOR( i = j; i < nb_bands; i++ ) { - bits_per_bands[i] = L_add(bits_per_bands[i], sum_bit); - move32();/* Q18 */ + bits_per_bands[i] = L_add( bits_per_bands[i], sum_bit ); + move32(); /* Q18 */ } } /*-------------------------------------------------------------------------- @@ -833,61 +837,61 @@ void bands_and_bit_alloc_fx( *--------------------------------------------------------------------------*/ w_sum_bit = 0; move16(); - FOR(i = 0; i < nb_bands; i++) + FOR( i = 0; i < nb_bands; i++ ) { - out_bits_per_bands[i] = shl(extract_l(L_shr(bits_per_bands[i], 18)), 3); + out_bits_per_bands[i] = shl( extract_l( L_shr( bits_per_bands[i], 18 ) ), 3 ); move16(); - w_sum_bit = add(w_sum_bit, out_bits_per_bands[i]); /* Q3 */ + w_sum_bit = add( w_sum_bit, out_bits_per_bands[i] ); /* Q3 */ } - tmp = shl(*bit, 3); + tmp = shl( *bit, 3 ); #ifdef ADD_LRTD - if (GSC_IVAS_mode != 0 && sum_bit < *bit) /* If we need to add bits, we are doing it on the LF */ + if ( GSC_IVAS_mode != 0 && sum_bit < *bit ) /* If we need to add bits, we are doing it on the LF */ { - reajust_bits(bits_per_bands, 0, nb_bands, (int16_t)sum_bit, *bit); + reajust_bits( bits_per_bands, 0, nb_bands, (int16_t) sum_bit, *bit ); } else { - reajust_bits(bits_per_bands, nb_bands - 1, 0, (int16_t)sum_bit, *bit); + reajust_bits( bits_per_bands, nb_bands - 1, 0, (int16_t) sum_bit, *bit ); } #else - IF(GT_16(tmp, w_sum_bit)) + IF( GT_16( tmp, w_sum_bit ) ) + { + i = sub( nb_bands, 1 ); + move16(); + FOR( ; tmp > w_sum_bit; w_sum_bit += ( 1 << 3 ) ) { - i = sub(nb_bands, 1); + out_bits_per_bands[i] = add( out_bits_per_bands[i], 1 << 3 ); move16(); - FOR(; tmp > w_sum_bit; w_sum_bit += (1 << 3)) + i = sub( i, 1 ); + if ( i == 0 ) { - out_bits_per_bands[i] = add(out_bits_per_bands[i], 1 << 3); - move16(); - i = sub(i, 1); - if (i == 0) - { - i = sub(nb_bands, 1); - } + i = sub( nb_bands, 1 ); } } + } #endif /*-------------------------------------------------------------------------- * Recompute the real number/length of frequency bands to encode *--------------------------------------------------------------------------*/ - * nb_subbands = nb_bands; + *nb_subbands = nb_bands; move16(); - *pvq_len = shl(*nb_subbands, 4); + *pvq_len = shl( *nb_subbands, 4 ); /*-------------------------------------------------------------------------- * Concatenate bands (encoder only) *--------------------------------------------------------------------------*/ - IF(exc_diff != NULL) + IF( exc_diff != NULL ) { - FOR(j = 0; j < nb_bands; j++) + FOR( j = 0; j < nb_bands; j++ ) { - Copy(exc_diff + shl(max_ener_band[j], 4), concat_in + shl(j, 4), 16); + Copy( exc_diff + shl( max_ener_band[j], 4 ), concat_in + shl( j, 4 ), 16 ); } } #ifdef ADD_LRTD } else /* *bit == 0 */ { - set_s(bits_per_bands_s, 0, nb_tot_bands); + set_s( bits_per_bands_s, 0, nb_tot_bands ); *nb_subbands = 0; *pvq_len = 0; } @@ -902,22 +906,22 @@ void bands_and_bit_alloc_fx( *-------------------------------------------------------------------*/ static void reajust_bits( - float* bits_per_bands, + float *bits_per_bands, const int16_t st_band, const int16_t end_band, const int16_t sum_bit_in, - const int16_t bit_bdgt_in) + const int16_t bit_bdgt_in ) { int16_t i, amount_to_add, incr; int16_t bit_bdgt, sum_bit; incr = 1; - if (end_band < st_band) + if ( end_band < st_band ) { incr = -1; } - if (bit_bdgt_in < sum_bit_in) + if ( bit_bdgt_in < sum_bit_in ) { amount_to_add = -1; bit_bdgt = sum_bit_in; @@ -931,16 +935,16 @@ static void reajust_bits( } i = st_band; - while (bit_bdgt > sum_bit) + while ( bit_bdgt > sum_bit ) { - if (amount_to_add > 0 || (amount_to_add < 0 && bits_per_bands[i] > 1)) + if ( amount_to_add > 0 || ( amount_to_add < 0 && bits_per_bands[i] > 1 ) ) { bits_per_bands[i] += amount_to_add; - sum_bit += (int16_t)abs(amount_to_add); + sum_bit += (int16_t) abs( amount_to_add ); } i += incr; - if (i == end_band) + if ( i == end_band ) { i = st_band; } @@ -949,4 +953,4 @@ static void reajust_bits( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_com/gs_bitallocation_ivas_fx.c b/lib_com/gs_bitallocation_ivas_fx.c index 2c9bb1737..48990d122 100644 --- a/lib_com/gs_bitallocation_ivas_fx.c +++ b/lib_com/gs_bitallocation_ivas_fx.c @@ -2,17 +2,17 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "ivas_prot.h" /* Function prototypes */ -#include "assert.h" /* Debug prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "ivas_prot.h" /* Function prototypes */ +#include "assert.h" /* Debug prototypes */ #include "stl.h" -static void reajust_bits_fx( Word32* bits_per_bands, const Word16 st_band, const Word16 end_band, const Word16 sum_bit_in, const Word16 bit_bdgt_in); +static void reajust_bits_fx( Word32 *bits_per_bands, const Word16 st_band, const Word16 end_band, const Word16 sum_bit_in, const Word16 bit_bdgt_in ); /*==================================================================================*/ /* FUNCTION : void bands_and_bit_alloc_ivas_fx(); */ @@ -68,56 +68,59 @@ void bands_and_bit_alloc_ivas_fx( { Word16 bandoffset, i, j, nb_bands_max, bit_new_bands, bit_tmp, st_band, nb_bands; - Word16 ener_vec[MBANDS_GN_BITALLOC16k]; /*Q12 */ + Word16 ener_vec[MBANDS_GN_BITALLOC16k]; /*Q12 */ Word16 nb_tot_bands = 16; Word16 bit_index, bit_index_mem, imax; Word32 L_tmp; - Word32 sum_bit/*Q18*/, bit_fracf /*Q18*/; + Word32 sum_bit /*Q18*/, bit_fracf /*Q18*/; Word16 etmp; Word16 tmp; - Word16 Ener_per_bd_iQ_tmp[MBANDS_GN_BITALLOC16k]; //Q13 + Word16 Ener_per_bd_iQ_tmp[MBANDS_GN_BITALLOC16k]; // Q13 Word16 pos, band; - Word32 SWB_bit_budget; // Q0 -> Q18 - Word32 bits_per_bands[MBANDS_GN_BITALLOC16k]; //Q18 + Word32 SWB_bit_budget; // Q0 -> Q18 + Word32 bits_per_bands[MBANDS_GN_BITALLOC16k]; // Q18 Word16 w_sum_bit; Word16 fzero_val; Word32 mp, mb, nb_bands_adj, bit_adj; Word16 nb_pulse_per_band[MBANDS_GN_BITALLOC16k]; #ifdef REMOVE_IVAS_UNUSED_PARAMETERS_WARNING - (void)GSC_IVAS_mode; - (void)element_mode; + (void) GSC_IVAS_mode; + (void) element_mode; #endif #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif nb_tot_bands = MBANDS_GN; move16(); - IF (EQ_16(L_frame, L_FRAME16k)) + IF( EQ_16( L_frame, L_FRAME16k ) ) { nb_tot_bands = MBANDS_GN_BITALLOC16k; move16(); } - Copy( Ener_per_bd_iQ, Ener_per_bd_iQ_tmp, nb_tot_bands); + Copy( Ener_per_bd_iQ, Ener_per_bd_iQ_tmp, nb_tot_bands ); - set32_fx( bits_per_bands, 0, MBANDS_GN_BITALLOC16k); - set16_fx( out_bits_per_bands, 0, MBANDS_GN_BITALLOC16k); + set32_fx( bits_per_bands, 0, MBANDS_GN_BITALLOC16k ); + set16_fx( out_bits_per_bands, 0, MBANDS_GN_BITALLOC16k ); /* To adapt current energy band to PVQ freq band for sorting*/ #ifdef BASOP_NOGLOB - ener_vec[0] = add_o(Ener_per_bd_iQ[0],Ener_per_bd_iQ[1], &Overflow); /*Q12 */ -#else /* BASOP_NOGLOB */ - ener_vec[0] = add(Ener_per_bd_iQ[0],Ener_per_bd_iQ[1]); /*Q12 */ + ener_vec[0] = add_o( Ener_per_bd_iQ[0], Ener_per_bd_iQ[1], &Overflow ); /*Q12 */ +#else /* BASOP_NOGLOB */ + ener_vec[0] = add( Ener_per_bd_iQ[0], Ener_per_bd_iQ[1] ); /*Q12 */ #endif - Copy( Ener_per_bd_iQ_tmp+1, ener_vec, MBANDS_GN-1); /*Q12 */ - ener_vec[MBANDS_GN-1] = ener_vec[MBANDS_GN-2]; + Copy( Ener_per_bd_iQ_tmp + 1, ener_vec, MBANDS_GN - 1 ); /*Q12 */ + ener_vec[MBANDS_GN - 1] = ener_vec[MBANDS_GN - 2]; move16(); - IF (EQ_16(L_frame, L_FRAME16k)) + IF( EQ_16( L_frame, L_FRAME16k ) ) { ener_vec[16] = Ener_per_bd_iQ[16]; - ener_vec[17] = mac_r(L_mult(Ener_per_bd_iQ[16], 16384), Ener_per_bd_iQ[17],16384); + ener_vec[17] = mac_r( L_mult( Ener_per_bd_iQ[16], 16384 ), Ener_per_bd_iQ[17], 16384 ); ener_vec[18] = Ener_per_bd_iQ[17]; - ener_vec[19] = mult_r(Ener_per_bd_iQ[17], 26214); - move16(); move16(); move16(); move16(); + ener_vec[19] = mult_r( Ener_per_bd_iQ[17], 26214 ); + move16(); + move16(); + move16(); + move16(); } /*------------------------------------------------------------------------ @@ -129,8 +132,8 @@ void bands_and_bit_alloc_ivas_fx( move16(); bit_new_bands = 5; move16(); -#if 1//def ADD_LRTD - IF(GT_32(core_brate, ACELP_16k40) && EQ_16(L_frame, L_FRAME16k)) +#if 1 // def ADD_LRTD + IF( GT_32( core_brate, ACELP_16k40 ) && EQ_16( L_frame, L_FRAME16k ) ) { bit_new_bands = 7; move16(); @@ -138,51 +141,51 @@ void bands_and_bit_alloc_ivas_fx( i = 0; move16(); - WHILE (LT_16(i, SIZE_BRATE_INTERMED_TBL)) + WHILE( LT_16( i, SIZE_BRATE_INTERMED_TBL ) ) { - IF (LE_32(core_brate, brate_intermed_tbl[i])) + IF( LE_32( core_brate, brate_intermed_tbl[i] ) ) { BREAK; } - IF (EQ_32(brate_intermed_tbl[i], ACELP_24k40)) + IF( EQ_32( brate_intermed_tbl[i], ACELP_24k40 ) ) { BREAK; } - i = add(i,1); + i = add( i, 1 ); } - IF(GT_16(element_mode, EVS_MONO) && EQ_16(coder_type, AUDIO) && - LE_32(core_brate, STEREO_GSC_BIT_RATE_ALLOC) && EQ_32(brate_intermed_tbl[i], ACELP_9k60)) /* Bit allocation should be mapped to 8 kb/s instead of 9.6 kb/s in this case */ + IF( GT_16( element_mode, EVS_MONO ) && EQ_16( coder_type, AUDIO ) && + LE_32( core_brate, STEREO_GSC_BIT_RATE_ALLOC ) && EQ_32( brate_intermed_tbl[i], ACELP_9k60 ) ) /* Bit allocation should be mapped to 8 kb/s instead of 9.6 kb/s in this case */ { - i = sub(i,1); + i = sub( i, 1 ); } - bit_index = i_mult2( BRATE2IDX_fx(brate_intermed_tbl[i]), 17); + bit_index = i_mult2( BRATE2IDX_fx( brate_intermed_tbl[i] ), 17 ); #else - bit_index = i_mult2(BRATE2IDX_fx(core_brate),17); + bit_index = i_mult2( BRATE2IDX_fx( core_brate ), 17 ); #endif bit_index_mem = bit_index; move16(); test(); test(); - IF( (EQ_16(coder_type,AUDIO)||EQ_16(coder_type,INACTIVE))&&EQ_16(bwidth,NB)) + IF( ( EQ_16( coder_type, AUDIO ) || EQ_16( coder_type, INACTIVE ) ) && EQ_16( bwidth, NB ) ) { - IF(GE_32(core_brate,ACELP_9k60)) + IF( GE_32( core_brate, ACELP_9k60 ) ) { /* *bit = (short)(core_brate*(1.0f/50) + 0.5f) - bits_used - 25; */ - L_tmp = Mult_32_16(core_brate,20971); - tmp = extract_l(L_shr_r(L_tmp,5)); - *bit = sub(sub(tmp,bits_used), 25); + L_tmp = Mult_32_16( core_brate, 20971 ); + tmp = extract_l( L_shr_r( L_tmp, 5 ) ); + *bit = sub( sub( tmp, bits_used ), 25 ); move16(); } ELSE { - L_tmp = Mult_32_16(core_brate,20971); - tmp = extract_l(L_shr_r(L_tmp,5)); - *bit = sub(sub(tmp,bits_used), 21); + L_tmp = Mult_32_16( core_brate, 20971 ); + tmp = extract_l( L_shr_r( L_tmp, 5 ) ); + *bit = sub( sub( tmp, bits_used ), 21 ); move16(); } nb_tot_bands = 10; @@ -192,147 +195,147 @@ void bands_and_bit_alloc_ivas_fx( { /* *bit = (short)(core_brate*(1.0f/50) + 0.5f) - bits_used - GSC_freq_bits[bit_index]; */ - L_tmp = Mult_32_16(core_brate,20971); - tmp = extract_l(L_shr_r(L_tmp,5)); - *bit = sub(sub(tmp,bits_used),GSC_freq_bits[bit_index]); + L_tmp = Mult_32_16( core_brate, 20971 ); + tmp = extract_l( L_shr_r( L_tmp, 5 ) ); + *bit = sub( sub( tmp, bits_used ), GSC_freq_bits[bit_index] ); move16(); } -#if 1 //def ADD_LRTD - IF(L_frame == L_FRAME16k) - { - *bit -= 8; - } +#if 1 // def ADD_LRTD + IF( L_frame == L_FRAME16k ) + { + *bit -= 8; + } - IF(coder_type == INACTIVE && core_brate <= GSC_LRES_GAINQ_LIMIT) /* can happen only for 2nd channel inactive */ + IF( coder_type == INACTIVE && core_brate <= GSC_LRES_GAINQ_LIMIT ) /* can happen only for 2nd channel inactive */ { *bit += GSC_LRES_NB_NITS; } - IF(*bit > 0) + IF( *bit > 0 ) { - IF(GSC_IVAS_mode > 0) + IF( GSC_IVAS_mode > 0 ) { SWB_bit_budget = *bit; // Q0 st_band = 5; - set_l(bits_per_bands, 0, MBANDS_GN_BITALLOC16k); + set_l( bits_per_bands, 0, MBANDS_GN_BITALLOC16k ); /* 2- Decide the pourcentage of bits allocated to LF (between 50-75%) depending of the temporal contribution in GSC */ - //bit_fracf = (-0.125f * Diff_len + 76.0f) / 100; + // bit_fracf = (-0.125f * Diff_len + 76.0f) / 100; bit_fracf = L_add( Mpy_32_32( -2684355, L_shl( Diff_len, Q18 ) ), 199229 ); // Q18 - //bit_fracf = check_bounds(bit_fracf, 0.50f, 0.75f); - bit_fracf = check_bounds_l(bit_fracf, 131072, 196608); //Q18 + // bit_fracf = check_bounds(bit_fracf, 0.50f, 0.75f); + bit_fracf = check_bounds_l( bit_fracf, 131072, 196608 ); // Q18 /* Adjusment of the bitrate between LF and HF base on the content type */ /* 1 = new GSC bit alloc 2 = GSC bit alloc for tc frame 3 = more music like (should not happen often given music is coded with dft) */ - IF(GSC_IVAS_mode <= 3) + IF( GSC_IVAS_mode <= 3 ) { nb_bands_max -= 6; } - IF(GSC_IVAS_mode == 2) + IF( GSC_IVAS_mode == 2 ) { - //bit_fracf += 0.1f; - bit_fracf = L_add(bit_fracf, 26214);//Q18 + // bit_fracf += 0.1f; + bit_fracf = L_add( bit_fracf, 26214 ); // Q18 nb_bands_max--; } - IF(GSC_IVAS_mode == 3) + IF( GSC_IVAS_mode == 3 ) { - //bit_fracf -= 0.1f; - bit_fracf = L_sub(bit_fracf, 26214);//Q18 + // bit_fracf -= 0.1f; + bit_fracf = L_sub( bit_fracf, 26214 ); // Q18 nb_bands_max += 3; } /* First find how much we want to share between LF and HF, at low bitrate, a miminum of bits is needed in LF by limitating the number of bands*/ /* Adjust the number of band based on the content type and bitrate */ - //nb_bands_adj = 1.0f; + // nb_bands_adj = 1.0f; nb_bands_adj = ONE_IN_Q18; - IF(GSC_IVAS_mode == 1 && core_brate < GSC_L_RATE_STG) + IF( GSC_IVAS_mode == 1 && core_brate < GSC_L_RATE_STG ) { - //nb_bands_adj = 0.0125f * SWB_bit_budget - 0.75f; + // nb_bands_adj = 0.0125f * SWB_bit_budget - 0.75f; nb_bands_adj = L_sub( Mpy_32_32( 26843546, L_shl( SWB_bit_budget, Q18 ) ), 196608 ); // Q18 } - ELSE IF(GSC_IVAS_mode != 2 && core_brate > GSC_H_RATE_STG) + ELSE IF( GSC_IVAS_mode != 2 && core_brate > GSC_H_RATE_STG ) { - //nb_bands_adj = 0.02f * SWB_bit_budget - 1.2f; + // nb_bands_adj = 0.02f * SWB_bit_budget - 1.2f; nb_bands_adj = L_sub( Mpy_32_32( 42949673, L_shl( SWB_bit_budget, Q18 ) ), 314572 ); // Q18 } - //nb_bands_max = (int16_t)(nb_bands_max * nb_bands_adj + 0.5f); - nb_bands_max = (Word16) L_shr_r(nb_bands_max * nb_bands_adj, Q18); //Q0 - nb_bands_max = check_bounds_s(nb_bands_max, 5, nb_tot_bands); + // nb_bands_max = (int16_t)(nb_bands_max * nb_bands_adj + 0.5f); + nb_bands_max = (Word16) L_shr_r( nb_bands_max * nb_bands_adj, Q18 ); // Q0 + nb_bands_max = check_bounds_s( nb_bands_max, 5, nb_tot_bands ); - //bit_fracf *= SWB_bit_budget; - bit_fracf = bit_fracf * SWB_bit_budget; //Q18 + // bit_fracf *= SWB_bit_budget; + bit_fracf = bit_fracf * SWB_bit_budget; // Q18 /* Estimation of the number of bit used in HF */ /* with only the first weigthing The number of bits in max_ener_band[st_band-1] = 17% of bit_fracf */ - //mb = .17f * bit_fracf; - mb = Mpy_32_32(365072220, bit_fracf); //Q18 - //mp = 2 * DSR_NB_PULSE); - mp = 2359296; //Q18 - IF(core_brate < GSC_L_RATE_STG && GSC_IVAS_mode == 3) + // mb = .17f * bit_fracf; + mb = Mpy_32_32( 365072220, bit_fracf ); // Q18 + // mp = 2 * DSR_NB_PULSE); + mp = 2359296; // Q18 + IF( core_brate < GSC_L_RATE_STG && GSC_IVAS_mode == 3 ) { - //mp = 1.5f * DSR_NB_PULSE; - mp = 1769472; //Q18 + // mp = 1.5f * DSR_NB_PULSE; + mp = 1769472; // Q18 } - ELSE IF(core_brate < GSC_L_RATE_STG) + ELSE IF( core_brate < GSC_L_RATE_STG ) { - //mp = DSR_NB_PULSE; + // mp = DSR_NB_PULSE; mp = DSR_NB_PULSE_Q18; } /* We want max_ener_band[st_band] <= max_ener_band[st_band-1] and max_ener_band[nb_bands_max-1] <= max_ener_band[st_band]*/ /* We will estimate the number of bits to allocate of HF and put the remaining bits, if any, back on LF */ /* compute the total possible number of band to be coded */ - //nb_tot_bands = (int16_t)((SWB_bit_budget - bit_fracf) / (mp + (mb - mp) / 2.0f)); + // nb_tot_bands = (int16_t)((SWB_bit_budget - bit_fracf) / (mp + (mb - mp) / 2.0f)); nb_tot_bands = (Word16) ( L_sub( L_shl( SWB_bit_budget, Q18 ), bit_fracf ) / L_add( mp, L_shr( L_sub( mb, mp ), 1 ) ) ); - mp = min(mp, mb); - IF(nb_tot_bands + st_band > nb_bands_max) + mp = min( mp, mb ); + IF( nb_tot_bands + st_band > nb_bands_max ) { - bit_adj = ((mb + mp) / 2) * (nb_tot_bands + st_band - nb_bands_max); - bit_adj = max(0, bit_adj); + bit_adj = ( ( mb + mp ) / 2 ) * ( nb_tot_bands + st_band - nb_bands_max ); + bit_adj = max( 0, bit_adj ); nb_tot_bands = nb_bands_max - st_band; - //bit_fracf += bit_adj; - bit_fracf = L_add( bit_fracf, bit_adj ); //Q18 + // bit_fracf += bit_adj; + bit_fracf = L_add( bit_fracf, bit_adj ); // Q18 } nb_tot_bands += st_band; /* Allocate bits to LF */ - //etmp = 0.23f; - Word32 etmp_32fx = 493921239; //Q15 - FOR(j = 0; j < st_band; j++) + // etmp = 0.23f; + Word32 etmp_32fx = 493921239; // Q15 + FOR( j = 0; j < st_band; j++ ) { i = j; max_ener_band[j] = i; ener_vec[i] = MIN16B; - //bits_per_bands[j] = etmp * bit_fracf; - bits_per_bands[j] = Mpy_32_32(bit_fracf, etmp_32fx); //33 - 15 = Q18 - //etmp -= 0.015f; - etmp_32fx = L_sub(etmp_32fx, 32212255); + // bits_per_bands[j] = etmp * bit_fracf; + bits_per_bands[j] = Mpy_32_32( bit_fracf, etmp_32fx ); // 33 - 15 = Q18 + // etmp -= 0.015f; + etmp_32fx = L_sub( etmp_32fx, 32212255 ); } - //SWB_bit_budget -= bit_fracf; - SWB_bit_budget = L_sub(L_shl(SWB_bit_budget, Q18),bit_fracf); //Q0->Q18 + // SWB_bit_budget -= bit_fracf; + SWB_bit_budget = L_sub( L_shl( SWB_bit_budget, Q18 ), bit_fracf ); // Q0->Q18 /* Find low energy band in HF */ - set_s(nb_pulse_per_band, 2, MBANDS_GN_BITALLOC16k); - FOR(i = st_band + 2; i < nb_tot_bands - 1; i++) + set_s( nb_pulse_per_band, 2, MBANDS_GN_BITALLOC16k ); + FOR( i = st_band + 2; i < nb_tot_bands - 1; i++ ) { - IF(ener_vec[i] < ener_vec[i - 1] && ener_vec[i] < ener_vec[i + 1]) + IF( ener_vec[i] < ener_vec[i - 1] && ener_vec[i] < ener_vec[i + 1] ) { nb_pulse_per_band[i] = 1; } } - FOR(j = st_band; j < nb_tot_bands; j++) + FOR( j = st_band; j < nb_tot_bands; j++ ) { - IF(j > 6) + IF( j > 6 ) { - i = maximum_fx(ener_vec, nb_tot_bands, &etmp); + i = maximum_fx( ener_vec, nb_tot_bands, &etmp ); } ELSE { @@ -344,41 +347,41 @@ void bands_and_bit_alloc_ivas_fx( } /* Recompute the final bit distribution for HF */ - IF(nb_tot_bands > st_band) + IF( nb_tot_bands > st_band ) { - //bit_fracf = DSR_NB_PULSE; - mb = (SWB_bit_budget * 2 / (nb_tot_bands - st_band)) - mp; // Q18 - bit_fracf = (mb - mp) / (nb_tot_bands - st_band); - mb = L_sub(mb, bit_fracf); + // bit_fracf = DSR_NB_PULSE; + mb = ( SWB_bit_budget * 2 / ( nb_tot_bands - st_band ) ) - mp; // Q18 + bit_fracf = ( mb - mp ) / ( nb_tot_bands - st_band ); + mb = L_sub( mb, bit_fracf ); /* Do the distribution */ - FOR(j = st_band; j < nb_tot_bands; j++) + FOR( j = st_band; j < nb_tot_bands; j++ ) { - IF(nb_pulse_per_band[max_ener_band[j]] > 1) + IF( nb_pulse_per_band[max_ener_band[j]] > 1 ) { bits_per_bands[max_ener_band[j]] = mb; } ELSE { - //bits_per_bands[max_ener_band[j]] = 4.5f; + // bits_per_bands[max_ener_band[j]] = 4.5f; bits_per_bands[max_ener_band[j]] = 1179648; } - mb = L_sub(mb, bit_fracf); + mb = L_sub( mb, bit_fracf ); SWB_bit_budget = L_sub( SWB_bit_budget, bits_per_bands[max_ener_band[j]] ); // Q18 } } /* Series of verification in case bit allocated != the budget */ - IF(SWB_bit_budget > 0) + IF( SWB_bit_budget > 0 ) { i = st_band - 1; WHILE( SWB_bit_budget > 0 ) { - //bits_per_bands[i]++; - bits_per_bands[i] = L_add(bits_per_bands[i], 262144); - //SWB_bit_budget--; - SWB_bit_budget = L_sub(SWB_bit_budget, 262144); + // bits_per_bands[i]++; + bits_per_bands[i] = L_add( bits_per_bands[i], 262144 ); + // SWB_bit_budget--; + SWB_bit_budget = L_sub( SWB_bit_budget, 262144 ); i--; - IF(i == -1) + IF( i == -1 ) { i = st_band - 1; } @@ -389,31 +392,31 @@ void bands_and_bit_alloc_ivas_fx( sum_bit = 0; j = 0; - FOR(i = 0; i < nb_bands; i++) + FOR( i = 0; i < nb_bands; i++ ) { - //if (bits_per_bands[i] > 112) - IF(bits_per_bands[i] > 29360128) + // if (bits_per_bands[i] > 112) + IF( bits_per_bands[i] > 29360128 ) { sum_bit += bits_per_bands[i] - 112; - sum_bit = L_add(sum_bit, L_sub(bits_per_bands[i] , 29360128)); - //bits_per_bands[i] = 112; + sum_bit = L_add( sum_bit, L_sub( bits_per_bands[i], 29360128 ) ); + // bits_per_bands[i] = 112; bits_per_bands[i] = 29360128; j = i + 1; } /* safety check for overage bit reallocation */ - //else if (bits_per_bands[i] + sum_bit / 3 > 112) - ELSE IF(bits_per_bands[i] + sum_bit / 3 > 29360128) + // else if (bits_per_bands[i] + sum_bit / 3 > 112) + ELSE IF( bits_per_bands[i] + sum_bit / 3 > 29360128 ) { j = i + 1; } } - IF(sum_bit != 0) + IF( sum_bit != 0 ) { - //sum_bit /= (nb_bands - j); - sum_bit = sum_bit/(nb_bands - j); - FOR(i = j; i < nb_bands; i++) + // sum_bit /= (nb_bands - j); + sum_bit = sum_bit / ( nb_bands - j ); + FOR( i = j; i < nb_bands; i++ ) { bits_per_bands[i] += sum_bit; } @@ -421,31 +424,31 @@ void bands_and_bit_alloc_ivas_fx( } ELSE #endif - IF(EQ_16(GSC_noisy_speech, 1)) + IF( EQ_16( GSC_noisy_speech, 1 ) ) { SWB_bit_budget = *bit; move16(); nb_bands = 5; move16(); -#if 1//def ADD_LRTD +#if 1 // def ADD_LRTD - //fzero_val = 0.0f; + // fzero_val = 0.0f; fzero_val = 0; - IF(element_mode > EVS_MONO) + IF( element_mode > EVS_MONO ) { fzero_val = MIN16B; } - IF(coder_type == UNVOICED && element_mode > EVS_MONO) + IF( coder_type == UNVOICED && element_mode > EVS_MONO ) { nb_bands = 3; - IF(SWB_bit_budget > 20) + IF( SWB_bit_budget > 20 ) { nb_bands = 5; } } - ELSE IF(bwidth < SWB) + ELSE IF( bwidth < SWB ) { nb_bands = 7; } @@ -455,68 +458,68 @@ void bands_and_bit_alloc_ivas_fx( st_band = nb_bands; move16(); - set32_fx(bits_per_bands, 0, MBANDS_GN); + set32_fx( bits_per_bands, 0, MBANDS_GN ); /*bit_fracf = (1.0f/nb_bands)*(SWB_bit_budget); */ - bit_fracf = L_mult(div_s(1, nb_bands), shl((Word16)SWB_bit_budget, 2)); /* Q18 */ + bit_fracf = L_mult( div_s( 1, nb_bands ), shl( (Word16) SWB_bit_budget, 2 ) ); /* Q18 */ - nb_tot_bands = sub(nb_bands_max, 6); - nb_tot_bands = s_min(nb_tot_bands, 16); + nb_tot_bands = sub( nb_bands_max, 6 ); + nb_tot_bands = s_min( nb_tot_bands, 16 ); - FOR(j = 0; j < 2; j++) + FOR( j = 0; j < 2; j++ ) { i = j; move16(); max_ener_band[j] = i; move16(); - //ener_vec[i] = 0; + // ener_vec[i] = 0; ener_vec[i] = fzero_val; move16(); } -#if 1//def ADD_LRTD - IF(bwidth < SWB) +#if 1 // def ADD_LRTD + IF( bwidth < SWB ) { - IF(coder_type == UNVOICED && element_mode > EVS_MONO) + IF( coder_type == UNVOICED && element_mode > EVS_MONO ) { nb_tot_bands = 5; } #endif - FOR(; j < nb_bands; j++) + FOR( ; j < nb_bands; j++ ) { - i = maximum_fx(ener_vec, nb_tot_bands, &etmp); + i = maximum_fx( ener_vec, nb_tot_bands, &etmp ); max_ener_band[j] = i; move16(); - //ener_vec[i] = 0; + // ener_vec[i] = 0; ener_vec[i] = fzero_val; move16(); } -#if 1//def ADD_LRTD +#if 1 // def ADD_LRTD } ELSE { - FOR(; j < nb_bands; j++) + FOR( ; j < nb_bands; j++ ) { - i = maximum_fx(ener_vec, nb_tot_bands, &etmp); + i = maximum_fx( ener_vec, nb_tot_bands, &etmp ); max_ener_band[j] = i; ener_vec[i] = fzero_val; } } #endif - set32_fx(bits_per_bands, bit_fracf, nb_bands); + set32_fx( bits_per_bands, bit_fracf, nb_bands ); } ELSE { bit_index++; - bit_tmp = sub(*bit,GSC_freq_bits[bit_index]); + bit_tmp = sub( *bit, GSC_freq_bits[bit_index] ); bit_index++; - nb_bands_max = add(nb_bands_max,GSC_freq_bits[bit_index]); + nb_bands_max = add( nb_bands_max, GSC_freq_bits[bit_index] ); bit_index++; *pvq_len = 112; move16(); st_band = 7; move16(); -#if 1//def ADD_LRTD - IF(L_frame == L_FRAME16k && core_brate > ACELP_16k40) +#if 1 // def ADD_LRTD + IF( L_frame == L_FRAME16k && core_brate > ACELP_16k40 ) { *pvq_len = 160; st_band = 10; @@ -525,29 +528,29 @@ void bands_and_bit_alloc_ivas_fx( bit_new_bands = 5; } #endif - IF(LE_32(core_brate,ACELP_9k60)) + IF( LE_32( core_brate, ACELP_9k60 ) ) { *pvq_len = 80; move16(); st_band = 5; move16(); - IF(Diff_len == 0) + IF( Diff_len == 0 ) { - nb_bands_max = add(nb_bands_max,2); - bit_tmp = sub(bit_tmp,13); + nb_bands_max = add( nb_bands_max, 2 ); + bit_tmp = sub( bit_tmp, 13 ); } } - ELSE IF(Diff_len == 0) + ELSE IF( Diff_len == 0 ) { - nb_bands_max = add(nb_bands_max,2); - bit_tmp = sub(bit_tmp,17); + nb_bands_max = add( nb_bands_max, 2 ); + bit_tmp = sub( bit_tmp, 17 ); } - nb_bands = shr(*pvq_len,4); -#if 1//def ADD_LRTD - nb_bands_max = min(nb_bands_max, MBANDS_GN_BITALLOC16k); + nb_bands = shr( *pvq_len, 4 ); +#if 1 // def ADD_LRTD + nb_bands_max = min( nb_bands_max, MBANDS_GN_BITALLOC16k ); #endif /*------------------------------------------------------------------------ * Ajustement of the maximum number of bands in function of the @@ -557,23 +560,23 @@ void bands_and_bit_alloc_ivas_fx( test(); test(); test(); - IF(EQ_16(coder_type,INACTIVE) || GE_16(noise_lev,NOISE_LEVEL_SP3)) + IF( EQ_16( coder_type, INACTIVE ) || GE_16( noise_lev, NOISE_LEVEL_SP3 ) ) { /* Probably classification error -> concentrate bits on LF */ -#if 1//def ADD_LRTD - IF(L_frame == L_FRAME16k && core_brate >= ACELP_24k40) +#if 1 // def ADD_LRTD + IF( L_frame == L_FRAME16k && core_brate >= ACELP_24k40 ) { nb_bands_max = nb_tot_bands - 2; } - ELSE IF(core_brate >= ACELP_16k40) + ELSE IF( core_brate >= ACELP_16k40 ) { nb_bands_max = nb_bands + 2; } ELSE #endif - IF(GE_32(core_brate,ACELP_8k00)) + IF( GE_32( core_brate, ACELP_8k00 ) ) { - nb_bands_max = add(nb_bands,1); + nb_bands_max = add( nb_bands, 1 ); } ELSE { @@ -581,31 +584,31 @@ void bands_and_bit_alloc_ivas_fx( move16(); } } - ELSE IF(GE_16(noise_lev,NOISE_LEVEL_SP2) || - (LE_32(core_brate,ACELP_13k20) && GE_32(core_brate,ACELP_9k60) && cor_strong_limit == 0)) /* Very low dynamic, tend to speech, do not try to code HF at all */ + ELSE IF( GE_16( noise_lev, NOISE_LEVEL_SP2 ) || + ( LE_32( core_brate, ACELP_13k20 ) && GE_32( core_brate, ACELP_9k60 ) && cor_strong_limit == 0 ) ) /* Very low dynamic, tend to speech, do not try to code HF at all */ { - nb_bands_max = sub(nb_bands_max,2); + nb_bands_max = sub( nb_bands_max, 2 ); } - ELSE IF(GE_16(noise_lev,NOISE_LEVEL_SP1)) /* Very low dynamic, tend to speech, code less HF */ + ELSE IF( GE_16( noise_lev, NOISE_LEVEL_SP1 ) ) /* Very low dynamic, tend to speech, code less HF */ { - nb_bands_max = sub(nb_bands_max,1); + nb_bands_max = sub( nb_bands_max, 1 ); } - #if 1//def ADD_LRTD - IF(L_frame == L_FRAME16k) +#if 1 // def ADD_LRTD + IF( L_frame == L_FRAME16k ) { - IF(core_brate < ACELP_24k40) + IF( core_brate < ACELP_24k40 ) { nb_bands_max -= 4; } - ELSE IF(core_brate < ACELP_32k) + ELSE IF( core_brate < ACELP_32k ) { - IF(Diff_len > 0 || noise_lev >= NOISE_LEVEL_SP2) + IF( Diff_len > 0 || noise_lev >= NOISE_LEVEL_SP2 ) { nb_bands_max -= 2; bit_new_bands *= 2; } } - ELSE IF(core_brate >= ACELP_32k) + ELSE IF( core_brate >= ACELP_32k ) { bit_new_bands *= 2; } @@ -613,7 +616,7 @@ void bands_and_bit_alloc_ivas_fx( #endif test(); - IF(EQ_16(bwidth,NB) && GT_16(nb_bands_max,10)) + IF( EQ_16( bwidth, NB ) && GT_16( nb_bands_max, 10 ) ) { nb_bands_max = 10; move16(); @@ -622,24 +625,24 @@ void bands_and_bit_alloc_ivas_fx( /*------------------------------------------------------------------------ * Find extra number of band to code according to bit rate availables *-----------------------------------------------------------------------*/ - WHILE(GE_16(bit_tmp,bit_new_bands) && LE_16(nb_bands,sub(nb_bands_max,1))) + WHILE( GE_16( bit_tmp, bit_new_bands ) && LE_16( nb_bands, sub( nb_bands_max, 1 ) ) ) { - bit_tmp = sub(bit_tmp,bit_new_bands); - nb_bands = add(nb_bands,1); + bit_tmp = sub( bit_tmp, bit_new_bands ); + nb_bands = add( nb_bands, 1 ); } /*------------------------------------------------------------------------ * Fractional bits to distribute on the first x bands *-----------------------------------------------------------------------*/ -#if 1//def ADD_LRTD - IF(L_frame == L_FRAME16k && core_brate > ACELP_32k) +#if 1 // def ADD_LRTD + IF( L_frame == L_FRAME16k && core_brate > ACELP_32k ) { bit_fracf = 0; } ELSE #endif { - bit_fracf = L_mult(div_s(1, st_band), shl(bit_tmp, 2)); /* Q18 */ + bit_fracf = L_mult( div_s( 1, st_band ), shl( bit_tmp, 2 ) ); /* Q18 */ } /*------------------------------------------------------------------------ * Complete the bit allocation per frequency band @@ -647,51 +650,51 @@ void bands_and_bit_alloc_ivas_fx( imax = 5; move16(); - IF(GT_32(core_brate,ACELP_9k60)) + IF( GT_32( core_brate, ACELP_9k60 ) ) { imax = 7; move16(); } - FOR(i = 0; i < imax; i++) + FOR( i = 0; i < imax; i++ ) { - bits_per_bands[i] = L_add(GSC_freq_bits_fx_Q18[bit_index],bit_fracf); - move32();/* Q18 */ - bit_index = add(bit_index,1); + bits_per_bands[i] = L_add( GSC_freq_bits_fx_Q18[bit_index], bit_fracf ); + move32(); /* Q18 */ + bit_index = add( bit_index, 1 ); } -#if 1//def ADD_LRTD - IF(L_frame == L_FRAME16k && core_brate > ACELP_16k40) +#if 1 // def ADD_LRTD + IF( L_frame == L_FRAME16k && core_brate > ACELP_16k40 ) { bit_index = 0; i = imax - 1; - //bits_per_bands[i] += Compl_GSC_freq_bits[bit_index]; + // bits_per_bands[i] += Compl_GSC_freq_bits[bit_index]; bits_per_bands[i] = L_add( bits_per_bands[i], L_shl( Compl_GSC_freq_bits[bit_index], Q18 ) ); i++; bit_index++; - FOR(; i < 10; i++) + FOR( ; i < 10; i++ ) { - //bits_per_bands[i] += Compl_GSC_freq_bits[bit_index] + bit_fracf; + // bits_per_bands[i] += Compl_GSC_freq_bits[bit_index] + bit_fracf; bits_per_bands[i] = L_add( bits_per_bands[i], L_add( L_shl( Compl_GSC_freq_bits[bit_index], Q18 ), bit_fracf ) ); bit_index++; } } #endif - IF(Diff_len == 0) + IF( Diff_len == 0 ) { - bit_index = add(bit_index_mem,10); - FOR(i = 0; i < 7; i++) + bit_index = add( bit_index_mem, 10 ); + FOR( i = 0; i < 7; i++ ) { - bits_per_bands[i] = L_add(bits_per_bands[i], GSC_freq_bits_fx_Q18[bit_index]); - move32();/*chk Q18 */ - bit_index = add(bit_index,1); + bits_per_bands[i] = L_add( bits_per_bands[i], GSC_freq_bits_fx_Q18[bit_index] ); + move32(); /*chk Q18 */ + bit_index = add( bit_index, 1 ); } } -#if 1//def ADD_LRTD - IF(bit_fracf < 0) +#if 1 // def ADD_LRTD + IF( bit_fracf < 0 ) { - FOR(j = 0; j < nb_tot_bands; j++) + FOR( j = 0; j < nb_tot_bands; j++ ) { - bits_per_bands[j] = max(bits_per_bands[j], 0); + bits_per_bands[j] = max( bits_per_bands[j], 0 ); } } @@ -699,36 +702,36 @@ void bands_and_bit_alloc_ivas_fx( /*-------------------------------------------------------------------------- * Complete the bit allocation per frequency band for 16kHz high brate mode *--------------------------------------------------------------------------*/ -#if 1//def ADD_LRTD - IF(L_frame == L_FRAME16k && core_brate > ACELP_32k) +#if 1 // def ADD_LRTD + IF( L_frame == L_FRAME16k && core_brate > ACELP_32k ) { - FOR(j = st_band; j < nb_bands; j++) + FOR( j = st_band; j < nb_bands; j++ ) { - //bits_per_bands[j] = bit_new_bands; - bits_per_bands[j] = L_shl(bit_new_bands, Q18); + // bits_per_bands[j] = bit_new_bands; + bits_per_bands[j] = L_shl( bit_new_bands, Q18 ); } - //bit_fracf = (1.0f / nb_bands) * (bit_tmp); - bit_fracf = (262144 / nb_bands) * (bit_tmp); + // bit_fracf = (1.0f / nb_bands) * (bit_tmp); + bit_fracf = ( 262144 / nb_bands ) * ( bit_tmp ); - //etmp = 2.0f * bit_fracf / (nb_bands + 1); - etmp = (Word16) L_shr(L_shl(bit_fracf, Q1) / (nb_bands + 1), Q3); //Q15 - //bit_fracf = etmp; - bit_fracf = L_shl(etmp, Q3); //Q18 - FOR(j = nb_bands - 1; j >= 0; j--) + // etmp = 2.0f * bit_fracf / (nb_bands + 1); + etmp = (Word16) L_shr( L_shl( bit_fracf, Q1 ) / ( nb_bands + 1 ), Q3 ); // Q15 + // bit_fracf = etmp; + bit_fracf = L_shl( etmp, Q3 ); // Q18 + FOR( j = nb_bands - 1; j >= 0; j-- ) { - //bits_per_bands[j] = etmp; - //etmp += bit_fracf; - bits_per_bands[j] = L_add(bits_per_bands[j], L_shl(etmp, Q3)); // Q18 - etmp = (Word16)L_add(etmp, L_shr(bit_fracf, Q3)); + // bits_per_bands[j] = etmp; + // etmp += bit_fracf; + bits_per_bands[j] = L_add( bits_per_bands[j], L_shl( etmp, Q3 ) ); // Q18 + etmp = (Word16) L_add( etmp, L_shr( bit_fracf, Q3 ) ); } } ELSE #endif { - FOR(j = st_band; j < nb_bands; j++) + FOR( j = st_band; j < nb_bands; j++ ) { - bits_per_bands[j] = L_shl(bit_new_bands, 18); + bits_per_bands[j] = L_shl( bit_new_bands, 18 ); move32(); /*chk Q18 */ } } @@ -738,36 +741,36 @@ void bands_and_bit_alloc_ivas_fx( * This is function of the spectral dynamic and the bitrate *--------------------------------------------------------------------------*/ - bandoffset = sub(nb_tot_bands,add(nb_bands,2)); + bandoffset = sub( nb_tot_bands, add( nb_bands, 2 ) ); test(); test(); test(); test(); test(); - IF(LE_16(noise_lev,NOISE_LEVEL_SP1a)) + IF( LE_16( noise_lev, NOISE_LEVEL_SP1a ) ) { - bandoffset = sub(bandoffset,1); + bandoffset = sub( bandoffset, 1 ); } - ELSE IF((LE_32(core_brate,ACELP_13k20) && (EQ_16(coder_type,INACTIVE) || GE_16(noise_lev,NOISE_LEVEL_SP3))) || - (LE_32(core_brate,ACELP_13k20) && GE_32(core_brate,ACELP_9k60) && cor_strong_limit == 0)) + ELSE IF( ( LE_32( core_brate, ACELP_13k20 ) && ( EQ_16( coder_type, INACTIVE ) || GE_16( noise_lev, NOISE_LEVEL_SP3 ) ) ) || + ( LE_32( core_brate, ACELP_13k20 ) && GE_32( core_brate, ACELP_9k60 ) && cor_strong_limit == 0 ) ) { - bandoffset = add(bandoffset,1); + bandoffset = add( bandoffset, 1 ); } - bandoffset = s_max(bandoffset ,0); + bandoffset = s_max( bandoffset, 0 ); /*-------------------------------------------------------------------------- * Initiazed sorted vector * For the first x bands to be included in th final sorted vector * Sort the remaining bands in decrease energy order *--------------------------------------------------------------------------*/ - FOR(j = 0; j < nb_tot_bands; j++) + FOR( j = 0; j < nb_tot_bands; j++ ) { max_ener_band[j] = -10; move16(); } - FOR(j = 0; j < st_band; j++) + FOR( j = 0; j < st_band; j++ ) { max_ener_band[j] = j; move16(); @@ -776,10 +779,10 @@ void bands_and_bit_alloc_ivas_fx( } pos = st_band; move16(); - FOR(; j < nb_bands; j++) + FOR( ; j < nb_bands; j++ ) { - i = maximum_fx(ener_vec, sub(nb_tot_bands,bandoffset), &etmp); - pos = s_max(pos,i); + i = maximum_fx( ener_vec, sub( nb_tot_bands, bandoffset ), &etmp ); + pos = s_max( pos, i ); max_ener_band[j] = i; move16(); ener_vec[i] = -10; @@ -790,163 +793,164 @@ void bands_and_bit_alloc_ivas_fx( test(); test(); test(); - IF(GT_16(sub(nb_tot_bands, bandoffset),nb_bands) && (GT_16(pos,7) && EQ_32(core_brate,ACELP_8k00)) && EQ_16(bwidth,WB)) + IF( GT_16( sub( nb_tot_bands, bandoffset ), nb_bands ) && ( GT_16( pos, 7 ) && EQ_32( core_brate, ACELP_8k00 ) ) && EQ_16( bwidth, WB ) ) { - band = sub(nb_tot_bands, add(bandoffset,nb_bands)); - FOR(j = 0; j < band; j++) + band = sub( nb_tot_bands, add( bandoffset, nb_bands ) ); + FOR( j = 0; j < band; j++ ) { - i = maximum_fx(ener_vec, sub(nb_tot_bands,bandoffset), &etmp); - max_ener_band[add(nb_bands,j)] = i; + i = maximum_fx( ener_vec, sub( nb_tot_bands, bandoffset ), &etmp ); + max_ener_band[add( nb_bands, j )] = i; move16(); ener_vec[i] = -10; move16(); - bits_per_bands[add(nb_bands,j)] = 1310720; + bits_per_bands[add( nb_bands, j )] = 1310720; move32(); /*Q18 */ } - nb_bands = add(nb_bands,band); + nb_bands = add( nb_bands, band ); - bit_tmp = i_mult2(band,5); + bit_tmp = i_mult2( band, 5 ); - IF(LE_16(band,2)) + IF( LE_16( band, 2 ) ) { - FOR(j = sub(st_band,1); j < nb_bands; j++) + FOR( j = sub( st_band, 1 ); j < nb_bands; j++ ) { - bits_per_bands[j] = L_add(bits_per_bands[j],262144); /*Q18 */ move32(); + bits_per_bands[j] = L_add( bits_per_bands[j], 262144 ); /*Q18 */ + move32(); } - bit_tmp = add(bit_tmp, add(sub(nb_bands, st_band) , 1)); + bit_tmp = add( bit_tmp, add( sub( nb_bands, st_band ), 1 ) ); } i = 0; move16(); j = 0; move16(); - FOR(; bit_tmp > 0; bit_tmp--) + FOR( ; bit_tmp > 0; bit_tmp-- ) { - bits_per_bands[j] = L_sub(bits_per_bands[j],262144); /*Q18 */ - j = add(j,1); - IF(EQ_16(j,sub(st_band, i))) + bits_per_bands[j] = L_sub( bits_per_bands[j], 262144 ); /*Q18 */ + j = add( j, 1 ); + IF( EQ_16( j, sub( st_band, i ) ) ) { j = 0; move16(); } test(); - IF(j == 0 && LT_16(i,sub(st_band, 1))) + IF( j == 0 && LT_16( i, sub( st_band, 1 ) ) ) { - i = add(i,1); + i = add( i, 1 ); } } } } - /*-------------------------------------------------------------------------- - * Bit sum verification for GSC inactive at very high rate - * The maximum number of bits per band of length 16 is 112 - * Redistribute the overage bits if needed - *--------------------------------------------------------------------------*/ + /*-------------------------------------------------------------------------- + * Bit sum verification for GSC inactive at very high rate + * The maximum number of bits per band of length 16 is 112 + * Redistribute the overage bits if needed + *--------------------------------------------------------------------------*/ sum_bit = 0; move16(); j = 0; move16(); - FOR(i = 0; i < nb_bands; i++) + FOR( i = 0; i < nb_bands; i++ ) { - L_tmp = Mult_32_16(sum_bit, 10923); + L_tmp = Mult_32_16( sum_bit, 10923 ); - IF(GT_32(bits_per_bands[i], 29360128)) /* 112 in Q18 */ + IF( GT_32( bits_per_bands[i], 29360128 ) ) /* 112 in Q18 */ { - sum_bit = L_add(sum_bit, L_sub(bits_per_bands[i], 29360128)); /* Q18 */ + sum_bit = L_add( sum_bit, L_sub( bits_per_bands[i], 29360128 ) ); /* Q18 */ bits_per_bands[i] = 29360128; move32(); - j = add(i, 1); + j = add( i, 1 ); } - ELSE IF(GT_32(L_add(bits_per_bands[i], L_tmp), 29360128)) /* Q18 */ + ELSE IF( GT_32( L_add( bits_per_bands[i], L_tmp ), 29360128 ) ) /* Q18 */ { - j = add(i, 1); + j = add( i, 1 ); } } - IF(sum_bit != 0) + IF( sum_bit != 0 ) { - tmp = sub(nb_bands, j); - sum_bit = Mult_32_16(sum_bit, div_s(1, tmp)); /* Q18 */ - FOR(i = j; i < nb_bands; i++) + tmp = sub( nb_bands, j ); + sum_bit = Mult_32_16( sum_bit, div_s( 1, tmp ) ); /* Q18 */ + FOR( i = j; i < nb_bands; i++ ) { - bits_per_bands[i] = L_add(bits_per_bands[i], sum_bit); - move32();/* Q18 */ + bits_per_bands[i] = L_add( bits_per_bands[i], sum_bit ); + move32(); /* Q18 */ } } /*-------------------------------------------------------------------------- * second step of bit sum verification, normally sum_bit == *bit *--------------------------------------------------------------------------*/ -#if 1//def ADD_LRTD +#if 1 // def ADD_LRTD sum_bit = 0; - FOR(i = 0; i < nb_bands; i++) + FOR( i = 0; i < nb_bands; i++ ) { - //bits_per_bands[i] = (float)floor(bits_per_bands[i]); + // bits_per_bands[i] = (float)floor(bits_per_bands[i]); bits_per_bands[i] = L_shl( L_shr( bits_per_bands[i], Q18 ), Q18 ); sum_bit = L_add( sum_bit, L_shr( bits_per_bands[i], Q18 ) ); } - IF(GSC_IVAS_mode != 0 && sum_bit < *bit) /* If we need to add bits, we are doing it on the LF */ + IF( GSC_IVAS_mode != 0 && sum_bit < *bit ) /* If we need to add bits, we are doing it on the LF */ { - reajust_bits_fx(bits_per_bands, 0, nb_bands, (int16_t)sum_bit, *bit); + reajust_bits_fx( bits_per_bands, 0, nb_bands, (int16_t) sum_bit, *bit ); } ELSE { - reajust_bits_fx(bits_per_bands, nb_bands - 1, 0, (int16_t)sum_bit, *bit); + reajust_bits_fx( bits_per_bands, nb_bands - 1, 0, (int16_t) sum_bit, *bit ); } w_sum_bit = 0; move16(); - FOR(i = 0; i < nb_bands; i++) + FOR( i = 0; i < nb_bands; i++ ) { - out_bits_per_bands[i] = shl(extract_l(L_shr(bits_per_bands[i], 18)), 3); + out_bits_per_bands[i] = shl( extract_l( L_shr( bits_per_bands[i], 18 ) ), 3 ); move16(); - w_sum_bit = add(w_sum_bit, out_bits_per_bands[i]); /* Q3 */ + w_sum_bit = add( w_sum_bit, out_bits_per_bands[i] ); /* Q3 */ } - tmp = shl(*bit, 3); + tmp = shl( *bit, 3 ); #else - IF(GT_16(tmp, w_sum_bit)) + IF( GT_16( tmp, w_sum_bit ) ) + { + i = sub( nb_bands, 1 ); + move16(); + FOR( ; tmp > w_sum_bit; w_sum_bit += ( 1 << 3 ) ) { - i = sub(nb_bands, 1); + out_bits_per_bands[i] = add( out_bits_per_bands[i], 1 << 3 ); move16(); - FOR(; tmp > w_sum_bit; w_sum_bit += (1 << 3)) + i = sub( i, 1 ); + IF( i == 0 ) { - out_bits_per_bands[i] = add(out_bits_per_bands[i], 1 << 3); - move16(); - i = sub(i, 1); - IF(i == 0) - { - i = sub(nb_bands, 1); - } + i = sub( nb_bands, 1 ); } } + } #endif /*-------------------------------------------------------------------------- * Recompute the real number/length of frequency bands to encode *--------------------------------------------------------------------------*/ - * nb_subbands = nb_bands; + *nb_subbands = nb_bands; move16(); - *pvq_len = shl(*nb_subbands, 4); + *pvq_len = shl( *nb_subbands, 4 ); /*-------------------------------------------------------------------------- * Concatenate bands (encoder only) *--------------------------------------------------------------------------*/ - IF(exc_diff != NULL) + IF( exc_diff != NULL ) { - FOR(j = 0; j < nb_bands; j++) + FOR( j = 0; j < nb_bands; j++ ) { - Copy(exc_diff + shl(max_ener_band[j], 4), concat_in + shl(j, 4), 16); + Copy( exc_diff + shl( max_ener_band[j], 4 ), concat_in + shl( j, 4 ), 16 ); } } -#if 1//def ADD_LRTD +#if 1 // def ADD_LRTD } ELSE /* *bit == 0 */ { - set_s(out_bits_per_bands, 0, nb_tot_bands); + set_s( out_bits_per_bands, 0, nb_tot_bands ); *nb_subbands = 0; *pvq_len = 0; } #endif return; } -#if 1//def ADD_LRTD +#if 1 // def ADD_LRTD /*-------------------------------------------------------------------* * reajust_bits() * @@ -954,22 +958,22 @@ void bands_and_bit_alloc_ivas_fx( *-------------------------------------------------------------------*/ static void reajust_bits_fx( - Word32* bits_per_bands, + Word32 *bits_per_bands, const Word16 st_band, const Word16 end_band, const Word16 sum_bit_in, - const Word16 bit_bdgt_in) + const Word16 bit_bdgt_in ) { Word16 i, amount_to_add, incr; Word16 bit_bdgt, sum_bit; incr = 1; - IF(end_band < st_band) + IF( end_band < st_band ) { incr = -1; } - IF(bit_bdgt_in < sum_bit_in) + IF( bit_bdgt_in < sum_bit_in ) { amount_to_add = -1; bit_bdgt = sum_bit_in; @@ -983,18 +987,18 @@ static void reajust_bits_fx( } i = st_band; - WHILE(bit_bdgt > sum_bit) + WHILE( bit_bdgt > sum_bit ) { - //if (amount_to_add > 0 || (amount_to_add < 0 && bits_per_bands[i] > 1)) - IF(amount_to_add > 0 || (amount_to_add < 0 && bits_per_bands[i] > 262144)) + // if (amount_to_add > 0 || (amount_to_add < 0 && bits_per_bands[i] > 1)) + IF( amount_to_add > 0 || ( amount_to_add < 0 && bits_per_bands[i] > 262144 ) ) { - //bits_per_bands[i] += amount_to_add; + // bits_per_bands[i] += amount_to_add; bits_per_bands[i] = L_add( bits_per_bands[i], L_shl( amount_to_add, Q18 ) ); sum_bit = add( sum_bit, abs_s( amount_to_add ) ); } i += incr; - IF(i == end_band) + IF( i == end_band ) { i = st_band; } @@ -1003,4 +1007,4 @@ static void reajust_bits_fx( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_com/gs_gains_fx.c b/lib_com/gs_gains_fx.c index 3d41b89eb..e81af00c8 100644 --- a/lib_com/gs_gains_fx.c +++ b/lib_com/gs_gains_fx.c @@ -34,9 +34,9 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ #include "prot_fx1.h" #include "prot_fx2.h" #include "stl.h" @@ -45,8 +45,7 @@ * Local constants *-------------------------------------------------------------------*/ -static Word16 VDQ_vec_fx( Word16 *Qvec_out_fx, const Word16 *mean_dic_fx, const Word16 *dic_fx, - const Word16 index_fx, const Word16 vec_en_fx ); +static Word16 VDQ_vec_fx( Word16 *Qvec_out_fx, const Word16 *mean_dic_fx, const Word16 *dic_fx, const Word16 index_fx, const Word16 vec_en_fx ); /*========================================================================*/ /* FUNCTION : void Comp_and_apply_gain_enc_fx */ @@ -69,14 +68,13 @@ static Word16 VDQ_vec_fx( Word16 *Qvec_out_fx, const Word16 *mean_dic_fx, const /* _ None */ /*========================================================================*/ void Comp_and_apply_gain_fx( - Word16 exc_diffQ[], /* i/o: Quantized excitation */ - Word16 Ener_per_bd_iQ[], /* i : Target ener per band Q13 */ - Word16 Ener_per_bd_yQ[], /* i/o : Ener per band for norm vector i->Q13/o->Q13 */ - Word16 Mbands_gn, /* i : number of bands */ - const Word16 ReUseGain, /* i : Reuse the gain in Ener_per_bd_yQ */ + Word16 exc_diffQ[], /* i/o: Quantized excitation */ + Word16 Ener_per_bd_iQ[], /* i : Target ener per band Q13 */ + Word16 Ener_per_bd_yQ[], /* i/o : Ener per band for norm vector i->Q13/o->Q13 */ + Word16 Mbands_gn, /* i : number of bands */ + const Word16 ReUseGain, /* i : Reuse the gain in Ener_per_bd_yQ */ Word16 Qexc_diff, - Word16 Q_exc -) + Word16 Q_exc ) { Word16 i, i_band; Word16 StartBin, NB_Qbins; @@ -90,29 +88,29 @@ void Comp_and_apply_gain_fx( /* Recreate excitation for local synthesis and decoder */ StartBin = 0; move16(); - NB_Qbins = 0; + NB_Qbins = 0; move16(); - tmp_exp = add(14,sub(Q_exc,Qexc_diff)); /* In case of reuse, it can be computed outside the loop*/ + tmp_exp = add( 14, sub( Q_exc, Qexc_diff ) ); /* In case of reuse, it can be computed outside the loop*/ FOR( i_band = 0; i_band < Mbands_gn; i_band++ ) { - StartBin = add(StartBin, NB_Qbins); + StartBin = add( StartBin, NB_Qbins ); NB_Qbins = mfreq_bindiv_loc[i_band]; move16(); - IF( EQ_16(ReUseGain,1)) + IF( EQ_16( ReUseGain, 1 ) ) { y_gain = Ener_per_bd_yQ[i_band]; move16(); - FOR(i = StartBin ; i < NB_Qbins + StartBin ; i++) + FOR( i = StartBin; i < NB_Qbins + StartBin; i++ ) { #ifdef BASOP_NOGLOB - L32 = L_shl_o(L_mult(exc_diffQ[i], y_gain),tmp_exp, &Overflow); /*Q_exc+16 */ - exc_diffQ[i] = round_fx_o(L32, &Overflow);/*Q_exc */ -#else /* BASOP_NOGLOB */ - L32 = L_shl(L_mult(exc_diffQ[i], y_gain),tmp_exp); /*Q_exc+16 */ - exc_diffQ[i] = round_fx(L32);/*Q_exc */ -#endif /* BASOP_NOGLOB */ + L32 = L_shl_o( L_mult( exc_diffQ[i], y_gain ), tmp_exp, &Overflow ); /*Q_exc+16 */ + exc_diffQ[i] = round_fx_o( L32, &Overflow ); /*Q_exc */ +#else /* BASOP_NOGLOB */ + L32 = L_shl( L_mult( exc_diffQ[i], y_gain ), tmp_exp ); /*Q_exc+16 */ + exc_diffQ[i] = round_fx( L32 ); /*Q_exc */ +#endif /* BASOP_NOGLOB */ } } ELSE @@ -121,28 +119,28 @@ void Comp_and_apply_gain_fx( * y_gain = pow(10.0, (Ener_per_bd_iQ[i_band]-Ener_per_bd_yQ[i_band])) * = pow(2, 3.321928*(Ener_per_bd_iQ[i_band]-Ener_per_bd_yQ[i_band])) *-----------------------------------------------------------------*/ - L16 = sub(Ener_per_bd_iQ[i_band], Ener_per_bd_yQ[i_band]);/*Q12 */ - L32 = L_mult(L16, 27213); /* 3.321928 in Q13 -> Q26 */ - L32 = L_shr(L32, 10); /* From Q26 to Q16 */ - frac = L_Extract_lc(L32, &exp1); /* Extract exponent of gcode0 */ - y_gain = extract_l(Pow2(14, frac));/* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ + L16 = sub( Ener_per_bd_iQ[i_band], Ener_per_bd_yQ[i_band] ); /*Q12 */ + L32 = L_mult( L16, 27213 ); /* 3.321928 in Q13 -> Q26 */ + L32 = L_shr( L32, 10 ); /* From Q26 to Q16 */ + frac = L_Extract_lc( L32, &exp1 ); /* Extract exponent of gcode0 */ + y_gain = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ + /* output of Pow2() will be: */ + /* 16384 < Pow2() <= 32767 */ #ifdef BASOP_NOGLOB - Ener_per_bd_yQ[i_band] = shl_o(y_gain, sub(exp1, 13), &Overflow); -#else /* BASOP_NOGLOB */ - Ener_per_bd_yQ[i_band] = shl(y_gain, sub(exp1, 13)); -#endif /* BASOP_NOGLOB */ - move16();/*Q1 */ - tmp_exp = add(add(exp1,1),sub(Q_exc,Qexc_diff)); - - FOR(i = StartBin ; i < NB_Qbins + StartBin ; i++) + Ener_per_bd_yQ[i_band] = shl_o( y_gain, sub( exp1, 13 ), &Overflow ); +#else /* BASOP_NOGLOB */ + Ener_per_bd_yQ[i_band] = shl( y_gain, sub( exp1, 13 ) ); +#endif /* BASOP_NOGLOB */ + move16(); /*Q1 */ + tmp_exp = add( add( exp1, 1 ), sub( Q_exc, Qexc_diff ) ); + + FOR( i = StartBin; i < NB_Qbins + StartBin; i++ ) { - L32 = L_mult(exc_diffQ[i], y_gain); /*Qexc_diff+15 */ + L32 = L_mult( exc_diffQ[i], y_gain ); /*Qexc_diff+15 */ #ifdef BASOP_NOGLOB - exc_diffQ[i] = round_fx_o(L_shl_o(L32,tmp_exp, &Overflow), &Overflow); /*Q_exc */ -#else /* BASOP_NOGLOB */ - exc_diffQ[i] = round_fx(L_shl(L32,tmp_exp)); /*Q_exc */ + exc_diffQ[i] = round_fx_o( L_shl_o( L32, tmp_exp, &Overflow ), &Overflow ); /*Q_exc */ +#else /* BASOP_NOGLOB */ + exc_diffQ[i] = round_fx( L_shl( L32, tmp_exp ) ); /*Q_exc */ #endif } } @@ -175,57 +173,57 @@ void Comp_and_apply_gain_fx( /* RETURN ARGUMENTS : */ /* _ None */ /*========================================================================*/ -static Word16 Comp_band_log_ener( /* o : Band gain Q12 */ - const Word16 *pt_fx, /* i : Dct input Q_sc */ - const Word16 Len, /* i : Lenght en energy accumulation */ - const Word16 Q_sc, /* i : scaling of input */ - const Word16 E_sc /* i : Additional scaling factor for energy */ +static Word16 Comp_band_log_ener( /* o : Band gain Q12 */ + const Word16 *pt_fx, /* i : Dct input Q_sc */ + const Word16 Len, /* i : Lenght en energy accumulation */ + const Word16 Q_sc, /* i : scaling of input */ + const Word16 E_sc /* i : Additional scaling factor for energy */ ) { Word32 L_tmp; Word16 e_tmp, f_tmp, tmp16, ener_exp; /*for(i = 0; i < 8; i++){etmp += (*pt * *pt);pt++;}*/ - L_tmp = Calc_Energy_Autoscaled(pt_fx, Q_sc, Len, &ener_exp); + L_tmp = Calc_Energy_Autoscaled( pt_fx, Q_sc, Len, &ener_exp ); /*y_gain4[j] = (float)log10(sqrt(etmp< Q12 */ + move16(); /* 8 -> Q12 */ } - ELSE IF (LE_32(core_brate,ACELP_8k00)) + ELSE IF( LE_32( core_brate, ACELP_8k00 ) ) { Gain_off = 27034; - move16(); /* 6.6f -> Q12 */ + move16(); /* 6.6f -> Q12 */ } - ELSE IF (LE_32(core_brate,ACELP_9k60)) + ELSE IF( LE_32( core_brate, ACELP_9k60 ) ) { Gain_off = 19661; - move16(); /*4.8f-> Q12 */ + move16(); /*4.8f-> Q12 */ } - ELSE IF (LE_32(core_brate,ACELP_11k60)) + ELSE IF( LE_32( core_brate, ACELP_11k60 ) ) { Gain_off = 14336; - move16(); /* 3.5f -> Q12 */ + move16(); /* 3.5f -> Q12 */ } - ELSE IF (LE_32(core_brate,ACELP_13k20)) + ELSE IF( LE_32( core_brate, ACELP_13k20 ) ) { Gain_off = 12288; move16(); /* 3.0f -> Q12 dB */ @@ -341,10 +339,10 @@ static void GSC_gain_adj( /*mimic ACELP decay of energy for low rates*/ FOR( i = 0; i < MBANDS_GN; i++ ) { - old_y_gain[i] = y_gain_tmp[i]; + old_y_gain[i] = y_gain_tmp[i]; move16(); /*y_gainQ[i] = y_gain_tmp[i]+mean_4g[0]-(i*(Gain_off/20.f)/((float) Mbands_gn));*/ - y_gainQ[i] = add(y_gain_tmp[i], sub(mean_g, i_mult2(i, mult_r(Gain_off, 102)))); + y_gainQ[i] = add( y_gain_tmp[i], sub( mean_g, i_mult2( i, mult_r( Gain_off, 102 ) ) ) ); move16(); } } @@ -359,25 +357,25 @@ static void GSC_gain_adj( * Quantization of the energy per band *-------------------------------------------------------------------*/ static void GSC_gain_adj_ivas_fx( - const Word16 coder_type, /* i : Coder type */ - const int16_t Mbands_gn, /* i : Number of band */ - const Word32 core_brate, /* i : Bit rate */ - const Word16 mean_g, /* i : Average gain Q12 */ - Word16 *old_y_gain, /* i/o: Previous frame dequantized vector */ - const Word16 *y_gain_tmp, /* i : Dequantized gains */ - Word16 *y_gainQ /* i/o: Output gains Q12 */ + const Word16 coder_type, /* i : Coder type */ + const int16_t Mbands_gn, /* i : Number of band */ + const Word32 core_brate, /* i : Bit rate */ + const Word16 mean_g, /* i : Average gain Q12 */ + Word16 *old_y_gain, /* i/o: Previous frame dequantized vector */ + const Word16 *y_gain_tmp, /* i : Dequantized gains */ + Word16 *y_gainQ /* i/o: Output gains Q12 */ ) { /* Gain adjustment to fit ACELP generic inactive coding gain at low rate */ Word16 Gain_off, i; - IF(NE_16(coder_type, INACTIVE) && NE_16(coder_type, UNVOICED)) + IF( NE_16( coder_type, INACTIVE ) && NE_16( coder_type, UNVOICED ) ) { - FOR(i = 0; i < Mbands_gn; i++) + FOR( i = 0; i < Mbands_gn; i++ ) { old_y_gain[i] = y_gain_tmp[i]; move16(); - y_gainQ[i] = add(y_gain_tmp[i], mean_g); + y_gainQ[i] = add( y_gain_tmp[i], mean_g ); move16(); } } @@ -388,42 +386,42 @@ static void GSC_gain_adj_ivas_fx( IF( LE_32( core_brate, ACELP_5k00 ) && EQ_16( coder_type, UNVOICED ) ) { Gain_off = 18432; - move16(); /* 9 -> Q11 */ + move16(); /* 9 -> Q11 */ } - IF(LE_32(core_brate,ACELP_7k20)) + IF( LE_32( core_brate, ACELP_7k20 ) ) { Gain_off = 16384; - move16(); /* 8 -> Q11 */ + move16(); /* 8 -> Q11 */ } - ELSE IF(LE_32(core_brate,ACELP_8k00)) + ELSE IF( LE_32( core_brate, ACELP_8k00 ) ) { Gain_off = 13517; - move16(); /* 6.6f -> Q11 */ + move16(); /* 6.6f -> Q11 */ } - ELSE IF(LE_32(core_brate,ACELP_9k60)) + ELSE IF( LE_32( core_brate, ACELP_9k60 ) ) { Gain_off = 9830; - move16(); /*4.8f-> Q11 */ + move16(); /*4.8f-> Q11 */ } - ELSE IF(LE_32(core_brate,ACELP_11k60)) + ELSE IF( LE_32( core_brate, ACELP_11k60 ) ) { Gain_off = 7168; - move16(); /* 3.5f -> Q11 */ + move16(); /* 3.5f -> Q11 */ } - ELSE IF(LE_32(core_brate,ACELP_13k20)) + ELSE IF( LE_32( core_brate, ACELP_13k20 ) ) { Gain_off = 6144; move16(); /* 3.0f -> Q11 dB */ } /*mimic ACELP decay of energy for low rates*/ - FOR(i = 0; i < Mbands_gn; i++) + FOR( i = 0; i < Mbands_gn; i++ ) { old_y_gain[i] = y_gain_tmp[i]; move16(); /*y_gainQ[i] = y_gain_tmp[i]+mean_4g[0]-(i*(Gain_off/20.f)/((float) Mbands_gn));*/ - //y_gainQ[i] = add(y_gain_tmp[i], sub(mean_g, i_mult2(i, mult_r(Gain_off, 102)))); - y_gainQ[i] = add(y_gain_tmp[i], sub(mean_g, i_mult2(i, mult_r(Gain_off, 205)))); + // y_gainQ[i] = add(y_gain_tmp[i], sub(mean_g, i_mult2(i, mult_r(Gain_off, 102)))); + y_gainQ[i] = add( y_gain_tmp[i], sub( mean_g, i_mult2( i, mult_r( Gain_off, 205 ) ) ) ); move16(); } } @@ -452,13 +450,13 @@ static void GSC_gain_adj_ivas_fx( /* RETURN ARGUMENTS : */ /* _ (Word16) : average frequency gain */ /*==========================================================================*/ -Word16 gsc_gaindec_fx( /* o : average frequency gain */ - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 y_gainQ_fx[], /* o : quantized gain per band */ - const Word32 core_brate_fx, /* i : core used */ - Word16 old_y_gain_fx[], /* i/o: AR gain quantizer for low rate */ - const Word16 coder_type, /* i : coding type */ - const Word16 bwidth_fx /* i : input signal bandwidth */ +Word16 gsc_gaindec_fx( /* o : average frequency gain */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 y_gainQ_fx[], /* o : quantized gain per band */ + const Word32 core_brate_fx, /* i : core used */ + Word16 old_y_gain_fx[], /* i/o: AR gain quantizer for low rate */ + const Word16 coder_type, /* i : coding type */ + const Word16 bwidth_fx /* i : input signal bandwidth */ ) { Word16 idx_g_fx, i; @@ -467,47 +465,47 @@ Word16 gsc_gaindec_fx( /* o : average frequency gain */ test(); test(); - IF( (EQ_16(coder_type,AUDIO)||EQ_16(coder_type,INACTIVE))&&EQ_16(bwidth_fx,NB)) + IF( ( EQ_16( coder_type, AUDIO ) || EQ_16( coder_type, INACTIVE ) ) && EQ_16( bwidth_fx, NB ) ) { idx_g_fx = (Word16) get_next_indice( st_fx, 6 ); - VDQ_vec_fx(&mean_4g_fx, Gain_meanNB_fx, Gain_mean_dicNB_fx, idx_g_fx, 1 ); + VDQ_vec_fx( &mean_4g_fx, Gain_meanNB_fx, Gain_mean_dicNB_fx, idx_g_fx, 1 ); idx_g_fx = (Word16) get_next_indice( st_fx, 6 ); move16(); - VDQ_vec_fx(y_gainQ_fx, Mean_dic_NB_fx, Gain_dic1_NB_fx, idx_g_fx, 3 ); + VDQ_vec_fx( y_gainQ_fx, Mean_dic_NB_fx, Gain_dic1_NB_fx, idx_g_fx, 3 ); - IF(LT_32(core_brate_fx,ACELP_9k60)) + IF( LT_32( core_brate_fx, ACELP_9k60 ) ) { idx_g_fx = (Word16) get_next_indice( st_fx, 5 ); - VDQ_vec_fx(y_gainQ_fx+3, Mean_dic_NB_fx+3, Gain_dic2_NB_fx, idx_g_fx, 3 ); + VDQ_vec_fx( y_gainQ_fx + 3, Mean_dic_NB_fx + 3, Gain_dic2_NB_fx, idx_g_fx, 3 ); idx_g_fx = (Word16) get_next_indice( st_fx, 4 ); - VDQ_vec_fx(y_gainQ_fx+6, Mean_dic_NB_fx+6, Gain_dic3_NB_fx, idx_g_fx, 4 ); + VDQ_vec_fx( y_gainQ_fx + 6, Mean_dic_NB_fx + 6, Gain_dic3_NB_fx, idx_g_fx, 4 ); } ELSE { idx_g_fx = (Word16) get_next_indice( st_fx, 6 ); - VDQ_vec_fx(y_gainQ_fx+3, Mean_dic_NB_fx+3, Gain_dic2_NBHR_fx, idx_g_fx, 3 ); + VDQ_vec_fx( y_gainQ_fx + 3, Mean_dic_NB_fx + 3, Gain_dic2_NBHR_fx, idx_g_fx, 3 ); idx_g_fx = (Word16) get_next_indice( st_fx, 7 ); - VDQ_vec_fx(y_gainQ_fx+6, Mean_dic_NB_fx+6, Gain_dic3_NBHR_fx, idx_g_fx, 4 ); + VDQ_vec_fx( y_gainQ_fx + 6, Mean_dic_NB_fx + 6, Gain_dic3_NBHR_fx, idx_g_fx, 4 ); } test(); - IF( LE_32(core_brate_fx,ACELP_9k60)&&EQ_16(coder_type,INACTIVE)) + IF( LE_32( core_brate_fx, ACELP_9k60 ) && EQ_16( coder_type, INACTIVE ) ) { /* Some energy is needed in high band for stat_noise_uv_enc to be functional in inactive speech */ - y_gainQ_fx[10] = mean_fx(y_gainQ_fx+6, 3); + y_gainQ_fx[10] = mean_fx( y_gainQ_fx + 6, 3 ); move16(); - y_gainQ_fx[11] = mean_fx(y_gainQ_fx+7, 3); + y_gainQ_fx[11] = mean_fx( y_gainQ_fx + 7, 3 ); move16(); - y_gainQ_fx[12] = mean_fx(y_gainQ_fx+8, 3); + y_gainQ_fx[12] = mean_fx( y_gainQ_fx + 8, 3 ); move16(); - y_gainQ_fx[13] = mean_fx(y_gainQ_fx+9, 3); + y_gainQ_fx[13] = mean_fx( y_gainQ_fx + 9, 3 ); move16(); - y_gainQ_fx[14] = mean_fx(y_gainQ_fx+10, 3); + y_gainQ_fx[14] = mean_fx( y_gainQ_fx + 10, 3 ); move16(); - y_gainQ_fx[15] = mean_fx(y_gainQ_fx+11, 3); + y_gainQ_fx[15] = mean_fx( y_gainQ_fx + 11, 3 ); move16(); } ELSE @@ -519,18 +517,18 @@ Word16 gsc_gaindec_fx( /* o : average frequency gain */ { idx_g_fx = (Word16) get_next_indice( st_fx, 6 ); - VDQ_vec_fx(&mean_4g_fx, mean_m_fx, mean_gain_dic_fx, idx_g_fx, 1 ); + VDQ_vec_fx( &mean_4g_fx, mean_m_fx, mean_gain_dic_fx, idx_g_fx, 1 ); - IF(LE_32(core_brate_fx,ACELP_9k60)) + IF( LE_32( core_brate_fx, ACELP_9k60 ) ) { /*--------------------------------------------------------------------------------------* * UQ of the first 8 bands and half of the last 8 bands *--------------------------------------------------------------------------------------*/ idx_g_fx = (Word16) get_next_indice( st_fx, 5 ); - VDQ_vec_fx(y_gainQ_fx, YGain_mean_LR_fx, YGain_dic1_LR_fx, idx_g_fx, 3 ); + VDQ_vec_fx( y_gainQ_fx, YGain_mean_LR_fx, YGain_dic1_LR_fx, idx_g_fx, 3 ); idx_g_fx = (Word16) get_next_indice( st_fx, 5 ); - VDQ_vec_fx(y_gainQ_fx+3, YGain_mean_LR_fx+3, YGain_dic2_LR_fx, idx_g_fx, 4 ); + VDQ_vec_fx( y_gainQ_fx + 3, YGain_mean_LR_fx + 3, YGain_dic2_LR_fx, idx_g_fx, 4 ); /*----------------------------------------------------------------------* * Interpolation of the last 4 Q bands to create bands 8-16 @@ -539,56 +537,55 @@ Word16 gsc_gaindec_fx( /* o : average frequency gain */ idx_g_fx = (Word16) get_next_indice( st_fx, 5 ); - VDQ_vec_fx(y_gainQ_fx+7, YGain_mean_LR_fx+7, YGain_dic3_LR_fx, idx_g_fx, 5 ); + VDQ_vec_fx( y_gainQ_fx + 7, YGain_mean_LR_fx + 7, YGain_dic3_LR_fx, idx_g_fx, 5 ); - Copy(y_gainQ_fx+8, y_gain_tmp3_fx, 4); - set16_fx(y_gainQ_fx+12, 0, 4); + Copy( y_gainQ_fx + 8, y_gain_tmp3_fx, 4 ); + set16_fx( y_gainQ_fx + 12, 0, 4 ); - fft_rel_fx(y_gainQ_fx+8, 4, 2); + fft_rel_fx( y_gainQ_fx + 8, 4, 2 ); y_gainQ_fx[15] = y_gainQ_fx[11]; move16(); y_gainQ_fx[11] = 0; move16(); - ifft_rel_fx(y_gainQ_fx+8, 8, 3); - FOR(i = 8; i < 16; i++) + ifft_rel_fx( y_gainQ_fx + 8, 8, 3 ); + FOR( i = 8; i < 16; i++ ) { /*y_gainQ_fx[i] *= 1.41f;*/ - y_gainQ_fx[i] = round_fx(L_shl(L_mult(y_gainQ_fx[i] , 23101),1));/*Q12 */ + y_gainQ_fx[i] = round_fx( L_shl( L_mult( y_gainQ_fx[i], 23101 ), 1 ) ); /*Q12 */ } /*----------------------------------------------------------------------* * Copy the true Q values in the specific bands *----------------------------------------------------------------------*/ y_gainQ_fx[8] = y_gain_tmp3_fx[0]; move16(); - y_gainQ_fx[10]= y_gain_tmp3_fx[1]; + y_gainQ_fx[10] = y_gain_tmp3_fx[1]; move16(); - y_gainQ_fx[12]= y_gain_tmp3_fx[2]; + y_gainQ_fx[12] = y_gain_tmp3_fx[2]; move16(); - y_gainQ_fx[14]= y_gain_tmp3_fx[3]; + y_gainQ_fx[14] = y_gain_tmp3_fx[3]; move16(); } ELSE { idx_g_fx = (Word16) get_next_indice( st_fx, 6 ); - VDQ_vec_fx(y_gainQ_fx, YG_mean16_fx, YG_dicMR_1_fx, idx_g_fx, 4 ); + VDQ_vec_fx( y_gainQ_fx, YG_mean16_fx, YG_dicMR_1_fx, idx_g_fx, 4 ); idx_g_fx = (Word16) get_next_indice( st_fx, 5 ); - VDQ_vec_fx(y_gainQ_fx+4, YG_mean16_fx+4, YG_dicMR_2_fx, idx_g_fx, 4 ); + VDQ_vec_fx( y_gainQ_fx + 4, YG_mean16_fx + 4, YG_dicMR_2_fx, idx_g_fx, 4 ); idx_g_fx = (Word16) get_next_indice( st_fx, 5 ); - VDQ_vec_fx(y_gainQ_fx+8, YG_mean16_fx+8, YG_dicMR_3_fx, idx_g_fx, 4 ); + VDQ_vec_fx( y_gainQ_fx + 8, YG_mean16_fx + 8, YG_dicMR_3_fx, idx_g_fx, 4 ); idx_g_fx = (Word16) get_next_indice( st_fx, 4 ); - VDQ_vec_fx(y_gainQ_fx+12, YG_mean16_fx+12, YG_dicMR_4_fx, idx_g_fx, 4 ); + VDQ_vec_fx( y_gainQ_fx + 12, YG_mean16_fx + 12, YG_dicMR_4_fx, idx_g_fx, 4 ); } } /* Gain adjustment to fit ACELP generic inactive coding gain at low rate */ - GSC_gain_adj(coder_type, core_brate_fx, mean_4g_fx, old_y_gain_fx, y_gainQ_fx, y_gainQ_fx); + GSC_gain_adj( coder_type, core_brate_fx, mean_4g_fx, old_y_gain_fx, y_gainQ_fx, y_gainQ_fx ); return mean_4g_fx; - } #ifdef IVAS_FLOAT_FIXED @@ -612,114 +609,114 @@ Word16 gsc_gaindec_fx( /* o : average frequency gain */ /* RETURN ARGUMENTS : */ /* _ (Word16) : average frequency gain */ /*==========================================================================*/ -Word16 gsc_gaindec_ivas_fx( /* o : average frequency gain */ - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 y_gainQ_fx[], /* o : quantized gain per band */ - const Word32 core_brate_fx, /* i : core used */ - Word16 old_y_gain_fx[], /* i/o: AR gain quantizer for low rate */ - const Word16 coder_type, /* i : coding type */ - const Word16 bwidth_fx /* i : input signal bandwidth */ +Word16 gsc_gaindec_ivas_fx( /* o : average frequency gain */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 y_gainQ_fx[], /* o : quantized gain per band */ + const Word32 core_brate_fx, /* i : core used */ + Word16 old_y_gain_fx[], /* i/o: AR gain quantizer for low rate */ + const Word16 coder_type, /* i : coding type */ + const Word16 bwidth_fx /* i : input signal bandwidth */ ) { Word16 idx_g_fx, i; Word16 mean_4g_fx; Word16 Mbands_gn = MBANDS_GN; Word16 y_gain_tmp3_fx[MBANDS_GN]; - IF( EQ_16(st_fx->L_frame, L_FRAME16k ) ) + IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { Mbands_gn = MBANDS_GN16k; } test(); test(); - IF((EQ_16(coder_type, AUDIO) || EQ_16(coder_type, INACTIVE)) && EQ_16(bwidth_fx, NB)) + IF( ( EQ_16( coder_type, AUDIO ) || EQ_16( coder_type, INACTIVE ) ) && EQ_16( bwidth_fx, NB ) ) { - idx_g_fx = (Word16)get_next_indice(st_fx, 6); - VDQ_vec_fx(&mean_4g_fx, Gain_meanNB_fx, Gain_mean_dicNB_fx, idx_g_fx, 1); + idx_g_fx = (Word16) get_next_indice( st_fx, 6 ); + VDQ_vec_fx( &mean_4g_fx, Gain_meanNB_fx, Gain_mean_dicNB_fx, idx_g_fx, 1 ); - idx_g_fx = (Word16)get_next_indice(st_fx, 6); + idx_g_fx = (Word16) get_next_indice( st_fx, 6 ); move16(); - VDQ_vec_fx(y_gainQ_fx, Mean_dic_NB_fx, Gain_dic1_NB_fx, idx_g_fx, 3); + VDQ_vec_fx( y_gainQ_fx, Mean_dic_NB_fx, Gain_dic1_NB_fx, idx_g_fx, 3 ); - IF(LT_32(core_brate_fx, ACELP_9k60)) + IF( LT_32( core_brate_fx, ACELP_9k60 ) ) { - idx_g_fx = (Word16)get_next_indice(st_fx, 5); - VDQ_vec_fx(y_gainQ_fx + 3, Mean_dic_NB_fx + 3, Gain_dic2_NB_fx, idx_g_fx, 3); + idx_g_fx = (Word16) get_next_indice( st_fx, 5 ); + VDQ_vec_fx( y_gainQ_fx + 3, Mean_dic_NB_fx + 3, Gain_dic2_NB_fx, idx_g_fx, 3 ); - idx_g_fx = (Word16)get_next_indice(st_fx, 4); - VDQ_vec_fx(y_gainQ_fx + 6, Mean_dic_NB_fx + 6, Gain_dic3_NB_fx, idx_g_fx, 4); + idx_g_fx = (Word16) get_next_indice( st_fx, 4 ); + VDQ_vec_fx( y_gainQ_fx + 6, Mean_dic_NB_fx + 6, Gain_dic3_NB_fx, idx_g_fx, 4 ); } ELSE { - idx_g_fx = (Word16)get_next_indice(st_fx, 6); - VDQ_vec_fx(y_gainQ_fx + 3, Mean_dic_NB_fx + 3, Gain_dic2_NBHR_fx, idx_g_fx, 3); + idx_g_fx = (Word16) get_next_indice( st_fx, 6 ); + VDQ_vec_fx( y_gainQ_fx + 3, Mean_dic_NB_fx + 3, Gain_dic2_NBHR_fx, idx_g_fx, 3 ); - idx_g_fx = (Word16)get_next_indice(st_fx, 7); - VDQ_vec_fx(y_gainQ_fx + 6, Mean_dic_NB_fx + 6, Gain_dic3_NBHR_fx, idx_g_fx, 4); + idx_g_fx = (Word16) get_next_indice( st_fx, 7 ); + VDQ_vec_fx( y_gainQ_fx + 6, Mean_dic_NB_fx + 6, Gain_dic3_NBHR_fx, idx_g_fx, 4 ); } test(); - IF(LE_32(core_brate_fx, ACELP_9k60) && EQ_16(coder_type, INACTIVE)) + IF( LE_32( core_brate_fx, ACELP_9k60 ) && EQ_16( coder_type, INACTIVE ) ) { /* Some energy is needed in high band for stat_noise_uv_enc to be functional in inactive speech */ - y_gainQ_fx[10] = mean_fx(y_gainQ_fx + 6, 3); + y_gainQ_fx[10] = mean_fx( y_gainQ_fx + 6, 3 ); move16(); - y_gainQ_fx[11] = mean_fx(y_gainQ_fx + 7, 3); + y_gainQ_fx[11] = mean_fx( y_gainQ_fx + 7, 3 ); move16(); - y_gainQ_fx[12] = mean_fx(y_gainQ_fx + 8, 3); + y_gainQ_fx[12] = mean_fx( y_gainQ_fx + 8, 3 ); move16(); - y_gainQ_fx[13] = mean_fx(y_gainQ_fx + 9, 3); + y_gainQ_fx[13] = mean_fx( y_gainQ_fx + 9, 3 ); move16(); - y_gainQ_fx[14] = mean_fx(y_gainQ_fx + 10, 3); + y_gainQ_fx[14] = mean_fx( y_gainQ_fx + 10, 3 ); move16(); - y_gainQ_fx[15] = mean_fx(y_gainQ_fx + 11, 3); + y_gainQ_fx[15] = mean_fx( y_gainQ_fx + 11, 3 ); move16(); } ELSE { - set16_fx(y_gainQ_fx + 10, 0, MBANDS_GN - 10); + set16_fx( y_gainQ_fx + 10, 0, MBANDS_GN - 10 ); } } ELSE { - idx_g_fx = (Word16)get_next_indice(st_fx, 6); + idx_g_fx = (Word16) get_next_indice( st_fx, 6 ); - VDQ_vec_fx(&mean_4g_fx, mean_m_fx, mean_gain_dic_fx, idx_g_fx, 1); + VDQ_vec_fx( &mean_4g_fx, mean_m_fx, mean_gain_dic_fx, idx_g_fx, 1 ); - IF(LT_32(core_brate_fx,ACELP_9k60)) + IF( LT_32( core_brate_fx, ACELP_9k60 ) ) { /*--------------------------------------------------------------------------------------* * UQ of the first 8 bands and half of the last 8 bands *--------------------------------------------------------------------------------------*/ - idx_g_fx = (Word16)get_next_indice(st_fx, 5); - VDQ_vec_fx(y_gainQ_fx, YGain_mean_LR_fx, YGain_dic1_LR_fx, idx_g_fx, 3); + idx_g_fx = (Word16) get_next_indice( st_fx, 5 ); + VDQ_vec_fx( y_gainQ_fx, YGain_mean_LR_fx, YGain_dic1_LR_fx, idx_g_fx, 3 ); - idx_g_fx = (Word16)get_next_indice(st_fx, 5); - VDQ_vec_fx(y_gainQ_fx + 3, YGain_mean_LR_fx + 3, YGain_dic2_LR_fx, idx_g_fx, 4); + idx_g_fx = (Word16) get_next_indice( st_fx, 5 ); + VDQ_vec_fx( y_gainQ_fx + 3, YGain_mean_LR_fx + 3, YGain_dic2_LR_fx, idx_g_fx, 4 ); /*----------------------------------------------------------------------* * Interpolation of the last 4 Q bands to create bands 8-16 * And scaling *----------------------------------------------------------------------*/ - idx_g_fx = (Word16)get_next_indice(st_fx, 5); + idx_g_fx = (Word16) get_next_indice( st_fx, 5 ); - VDQ_vec_fx(y_gainQ_fx + 7, YGain_mean_LR_fx + 7, YGain_dic3_LR_fx, idx_g_fx, 5); + VDQ_vec_fx( y_gainQ_fx + 7, YGain_mean_LR_fx + 7, YGain_dic3_LR_fx, idx_g_fx, 5 ); - Copy(y_gainQ_fx + 8, y_gain_tmp3_fx, 4); - set16_fx(y_gainQ_fx + 12, 0, 4); + Copy( y_gainQ_fx + 8, y_gain_tmp3_fx, 4 ); + set16_fx( y_gainQ_fx + 12, 0, 4 ); - fft_rel_fx(y_gainQ_fx + 8, 4, 2); + fft_rel_fx( y_gainQ_fx + 8, 4, 2 ); y_gainQ_fx[15] = y_gainQ_fx[11]; move16(); y_gainQ_fx[11] = 0; move16(); - ifft_rel_fx(y_gainQ_fx + 8, 8, 3); - FOR(i = 8; i < 16; i++) + ifft_rel_fx( y_gainQ_fx + 8, 8, 3 ); + FOR( i = 8; i < 16; i++ ) { /*y_gainQ_fx[i] *= 1.41f;*/ - y_gainQ_fx[i] = round_fx(L_shl(L_mult(y_gainQ_fx[i] , 23101),1));/*Q12 */ + y_gainQ_fx[i] = round_fx( L_shl( L_mult( y_gainQ_fx[i], 23101 ), 1 ) ); /*Q12 */ } /*----------------------------------------------------------------------* * Copy the true Q values in the specific bands @@ -769,11 +766,10 @@ Word16 gsc_gaindec_ivas_fx( /* o : average frequency gain * } } - /* Gain adjustment to fit ACELP generic inactive coding gain at low rate */ - GSC_gain_adj_ivas_fx(coder_type, Mbands_gn, core_brate_fx, mean_4g_fx, old_y_gain_fx, y_gainQ_fx, y_gainQ_fx); + /* Gain adjustment to fit ACELP generic inactive coding gain at low rate */ + GSC_gain_adj_ivas_fx( coder_type, Mbands_gn, core_brate_fx, mean_4g_fx, old_y_gain_fx, y_gainQ_fx, y_gainQ_fx ); return mean_4g_fx; - } #endif @@ -782,18 +778,18 @@ Word16 gsc_gaindec_ivas_fx( /* o : average frequency gain * * * Quantization of the energy per band *-------------------------------------------------------------------*/ -Word16 gsc_gainQ_fx( /*Q12*/ - BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ - const Word16 y_gain4[], /* i : Energy per band Q12 */ - Word16 y_gainQ[], /* o : quantized energy per band Q12 */ - const Word32 core_brate, /* i : Core rate */ - const Word16 coder_type, /* i : coding type */ - const Word16 bwidth /* i : input signal bandwidth */ +Word16 gsc_gainQ_fx( /*Q12*/ + BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ + const Word16 y_gain4[], /* i : Energy per band Q12 */ + Word16 y_gainQ[], /* o : quantized energy per band Q12 */ + const Word32 core_brate, /* i : Core rate */ + const Word16 coder_type, /* i : coding type */ + const Word16 bwidth /* i : input signal bandwidth */ ) { Word16 y_gain_tmp[MBANDS_GN], y_gain_tmp2[MBANDS_GN]; Word16 i, idx_g = 0; - Word16 mean_4g[1] = {0}, tmp16,tmp1, tmp2; + Word16 mean_4g[1] = { 0 }, tmp16, tmp1, tmp2; Word16 Mbands_gn = MBANDS_GN; Word16 y_gain_tmp3[MBANDS_GN]; Word16 cnt; @@ -803,76 +799,76 @@ Word16 gsc_gainQ_fx( /*Q12*/ test(); test(); - IF( (EQ_16(coder_type,AUDIO)||EQ_16(coder_type,INACTIVE))&&EQ_16(bwidth,NB)) + IF( ( EQ_16( coder_type, AUDIO ) || EQ_16( coder_type, INACTIVE ) ) && EQ_16( bwidth, NB ) ) { /*ftmp1 = mean(y_gain4, 10)-0.6f;*/ - L_tmp = L_deposit_l(0); - FOR(cnt = 0 ; cnt < 10 ; cnt++) + L_tmp = L_deposit_l( 0 ); + FOR( cnt = 0; cnt < 10; cnt++ ) { - L_tmp = L_mac(L_tmp,y_gain4[cnt], 3277); + L_tmp = L_mac( L_tmp, y_gain4[cnt], 3277 ); } - tmp16 = sub(round_fx(L_tmp), 4915); + tmp16 = sub( round_fx( L_tmp ), 4915 ); - FOR(i = 0; i < Mbands_gn; i++) + FOR( i = 0; i < Mbands_gn; i++ ) { y_gain_tmp2[i] = y_gain4[i]; move16(); /*if(y_gain4[i] < ftmp1-0.6f)*/ - y_gain_tmp2[i] = s_max(y_gain_tmp2[i], tmp16); + y_gain_tmp2[i] = s_max( y_gain_tmp2[i], tmp16 ); move16(); } - L_tmp = L_deposit_l(0); - FOR(i = 0; i < 10; i++) + L_tmp = L_deposit_l( 0 ); + FOR( i = 0; i < 10; i++ ) { - L_tmp = L_mac(L_tmp,y_gain_tmp2[i], 3277); + L_tmp = L_mac( L_tmp, y_gain_tmp2[i], 3277 ); } /* Quantized mean gain without clipping */ - mean_4g[0] = round_fx(L_tmp); - idx_g = vquant_fx(mean_4g, Gain_meanNB_fx, mean_4g, Gain_mean_dicNB_fx, 1, 64); + mean_4g[0] = round_fx( L_tmp ); + idx_g = vquant_fx( mean_4g, Gain_meanNB_fx, mean_4g, Gain_mean_dicNB_fx, 1, 64 ); push_indice_fx( hBstr, IND_MEAN_GAIN2, idx_g, 6 ); - FOR(i = 0; i < Mbands_gn; i++) + FOR( i = 0; i < Mbands_gn; i++ ) { - y_gain_tmp[i] = sub(y_gain_tmp2[i],mean_4g[0]); + y_gain_tmp[i] = sub( y_gain_tmp2[i], mean_4g[0] ); move16(); } /*if(y_gain_tmp[9] < -0.3f){y_gain_tmp[9] = -0.3f;}*/ - y_gain_tmp[9] = s_max(y_gain_tmp[9], -1229); + y_gain_tmp[9] = s_max( y_gain_tmp[9], -1229 ); move16(); - set16_fx(y_gain_tmp+10, 0, MBANDS_GN-10); - idx_g = vquant_fx(y_gain_tmp, Mean_dic_NB_fx, y_gain_tmp, Gain_dic1_NB_fx, 3, 64); + set16_fx( y_gain_tmp + 10, 0, MBANDS_GN - 10 ); + idx_g = vquant_fx( y_gain_tmp, Mean_dic_NB_fx, y_gain_tmp, Gain_dic1_NB_fx, 3, 64 ); push_indice_fx( hBstr, IND_Y_GAIN_TMP, idx_g, 6 ); - IF(LT_32(core_brate,ACELP_9k60)) + IF( LT_32( core_brate, ACELP_9k60 ) ) { - idx_g = vquant_fx(y_gain_tmp+3, Mean_dic_NB_fx+3, y_gain_tmp+3, Gain_dic2_NB_fx, 3, 32); + idx_g = vquant_fx( y_gain_tmp + 3, Mean_dic_NB_fx + 3, y_gain_tmp + 3, Gain_dic2_NB_fx, 3, 32 ); push_indice_fx( hBstr, IND_Y_GAIN_TMP, idx_g, 5 ); - idx_g = vquant_fx(y_gain_tmp+6, Mean_dic_NB_fx+6, y_gain_tmp+6, Gain_dic3_NB_fx, 4, 16); + idx_g = vquant_fx( y_gain_tmp + 6, Mean_dic_NB_fx + 6, y_gain_tmp + 6, Gain_dic3_NB_fx, 4, 16 ); push_indice_fx( hBstr, IND_Y_GAIN_TMP, idx_g, 4 ); } ELSE { - idx_g = vquant_fx(y_gain_tmp+3, Mean_dic_NB_fx+3, y_gain_tmp+3, Gain_dic2_NBHR_fx, 3, 64); + idx_g = vquant_fx( y_gain_tmp + 3, Mean_dic_NB_fx + 3, y_gain_tmp + 3, Gain_dic2_NBHR_fx, 3, 64 ); push_indice_fx( hBstr, IND_Y_GAIN_TMP, idx_g, 6 ); - idx_g = vquant_fx(y_gain_tmp+6, Mean_dic_NB_fx+6, y_gain_tmp+6, Gain_dic3_NBHR_fx, 4, 128); + idx_g = vquant_fx( y_gain_tmp + 6, Mean_dic_NB_fx + 6, y_gain_tmp + 6, Gain_dic3_NBHR_fx, 4, 128 ); push_indice_fx( hBstr, IND_Y_GAIN_TMP, idx_g, 7 ); - }/*add end */ + } /*add end */ test(); - IF( LE_32(core_brate,ACELP_9k60)&&EQ_16(coder_type,INACTIVE)) + IF( LE_32( core_brate, ACELP_9k60 ) && EQ_16( coder_type, INACTIVE ) ) { /* Some energy is needed in high band for stat_noise_uv_enc to be functional in inactive speech */ - y_gain_tmp[10] = round_fx(L_mac(L_mac(L_mult(y_gain_tmp[6],8192),y_gain_tmp[7],8192),y_gain_tmp[8],8192)); - y_gain_tmp[11] = round_fx(L_mac(L_mac(L_mult(y_gain_tmp[7],8192),y_gain_tmp[8],8192),y_gain_tmp[9],8192)); + y_gain_tmp[10] = round_fx( L_mac( L_mac( L_mult( y_gain_tmp[6], 8192 ), y_gain_tmp[7], 8192 ), y_gain_tmp[8], 8192 ) ); + y_gain_tmp[11] = round_fx( L_mac( L_mac( L_mult( y_gain_tmp[7], 8192 ), y_gain_tmp[8], 8192 ), y_gain_tmp[9], 8192 ) ); - y_gain_tmp[12] = round_fx(L_mac(L_mac(L_mult(y_gain_tmp[8],8192),y_gain_tmp[9],8192),y_gain_tmp[10],8192)); - y_gain_tmp[13] = round_fx(L_mac(L_mac(L_mult(y_gain_tmp[9],8192),y_gain_tmp[10],8192),y_gain_tmp[11],8192)); - y_gain_tmp[14] = round_fx(L_mac(L_mac(L_mult(y_gain_tmp[10],8192),y_gain_tmp[11],8192),y_gain_tmp[12],8192)); - y_gain_tmp[15] = round_fx(L_mac(L_mac(L_mult(y_gain_tmp[11],8192),y_gain_tmp[12],8192),y_gain_tmp[13],8192)); + y_gain_tmp[12] = round_fx( L_mac( L_mac( L_mult( y_gain_tmp[8], 8192 ), y_gain_tmp[9], 8192 ), y_gain_tmp[10], 8192 ) ); + y_gain_tmp[13] = round_fx( L_mac( L_mac( L_mult( y_gain_tmp[9], 8192 ), y_gain_tmp[10], 8192 ), y_gain_tmp[11], 8192 ) ); + y_gain_tmp[14] = round_fx( L_mac( L_mac( L_mult( y_gain_tmp[10], 8192 ), y_gain_tmp[11], 8192 ), y_gain_tmp[12], 8192 ) ); + y_gain_tmp[15] = round_fx( L_mac( L_mac( L_mult( y_gain_tmp[11], 8192 ), y_gain_tmp[12], 8192 ), y_gain_tmp[13], 8192 ) ); } ELSE { @@ -883,124 +879,124 @@ Word16 gsc_gainQ_fx( /*Q12*/ { /*ftmp1 = mean(y_gain4, 16);*/ - L_tmp =0; - FOR(cnt = 0 ; cnt < 16 ; cnt++) + L_tmp = 0; + FOR( cnt = 0; cnt < 16; cnt++ ) { - L_tmp = L_mac(L_tmp,y_gain4[cnt], 2048); + L_tmp = L_mac( L_tmp, y_gain4[cnt], 2048 ); } - tmp16 = round_fx(L_tmp); + tmp16 = round_fx( L_tmp ); - tmp1 = sub(tmp16,4915); - tmp2 = add(tmp16,4915); - L_tmp =0; - FOR(i = 0; i < 16; i++) + tmp1 = sub( tmp16, 4915 ); + tmp2 = add( tmp16, 4915 ); + L_tmp = 0; + FOR( i = 0; i < 16; i++ ) { y_gain_tmp2[i] = y_gain4[i]; move16(); /*if(y_gain4[i] < ftmp1-0.6f)*/ - y_gain_tmp2[i] = s_max(y_gain_tmp2[i], tmp1); + y_gain_tmp2[i] = s_max( y_gain_tmp2[i], tmp1 ); move16(); /*else if(y_gain4[i] > ftmp1+0.6f)*/ - y_gain_tmp2[i] = s_min(y_gain_tmp2[i], tmp2); + y_gain_tmp2[i] = s_min( y_gain_tmp2[i], tmp2 ); move16(); - L_tmp = L_mac(L_tmp,y_gain_tmp2[i], 2048); + L_tmp = L_mac( L_tmp, y_gain_tmp2[i], 2048 ); } - FOR(; i < Mbands_gn; i++) + FOR( ; i < Mbands_gn; i++ ) { y_gain_tmp2[i] = y_gain4[i]; /*if(y_gain4[i] < ftmp1-0.6f)*/ - y_gain_tmp2[i] = s_max(y_gain_tmp2[i], tmp1); /* Just the last move is needed, because s_max and s_min could be done in 1 line*/ + y_gain_tmp2[i] = s_max( y_gain_tmp2[i], tmp1 ); /* Just the last move is needed, because s_max and s_min could be done in 1 line*/ /*else if(y_gain4[i] > ftmp1+0.6f)*/ - y_gain_tmp2[i] = s_min(y_gain_tmp2[i], tmp2); + y_gain_tmp2[i] = s_min( y_gain_tmp2[i], tmp2 ); move16(); } /* Quantized mean gain without clipping */ - mean_4g[0] = round_fx(L_tmp); + mean_4g[0] = round_fx( L_tmp ); /*idx_g = (short)vquant(mean_4g, mean_m, mean_4g, mean_gain_dic, 1, 64);*/ - idx_g = vquant_fx(mean_4g, mean_m_fx, mean_4g, mean_gain_dic_fx, 1, 64); + idx_g = vquant_fx( mean_4g, mean_m_fx, mean_4g, mean_gain_dic_fx, 1, 64 ); push_indice_fx( hBstr, IND_MEAN_GAIN2, idx_g, 6 ); - FOR(i = 0; i < Mbands_gn; i++) + FOR( i = 0; i < Mbands_gn; i++ ) { - y_gain_tmp[i] = sub(y_gain_tmp2[i],mean_4g[0]); + y_gain_tmp[i] = sub( y_gain_tmp2[i], mean_4g[0] ); move16(); } - IF( LT_32(core_brate,ACELP_9k60)) + IF( LT_32( core_brate, ACELP_9k60 ) ) { /*mvr2r(y_gain_tmp, y_gain_tmp2, 8); */ - Copy(y_gain_tmp, y_gain_tmp2, 8); + Copy( y_gain_tmp, y_gain_tmp2, 8 ); y_gain_tmp2[8] = y_gain_tmp[8]; move16(); y_gain_tmp2[9] = y_gain_tmp[10]; move16(); - y_gain_tmp2[10] =y_gain_tmp[12]; + y_gain_tmp2[10] = y_gain_tmp[12]; move16(); - y_gain_tmp2[11] =y_gain_tmp[14]; + y_gain_tmp2[11] = y_gain_tmp[14]; move16(); idx_g = 0; /*idx_g = (short)vquant(y_gain_tmp2, YGain_mean_LR, y_gain_tmp2, YGain_dic1_LR, 3, 32);*/ - idx_g = vquant_fx(y_gain_tmp2, YGain_mean_LR_fx, y_gain_tmp2, YGain_dic1_LR_fx, 3, 32 ); + idx_g = vquant_fx( y_gain_tmp2, YGain_mean_LR_fx, y_gain_tmp2, YGain_dic1_LR_fx, 3, 32 ); push_indice_fx( hBstr, IND_Y_GAIN_TMP, idx_g, 5 ); /*idx_g = (short)vquant(y_gain_tmp2+3, YGain_mean_LR+3, y_gain_tmp2+3, YGain_dic2_LR, 4, 32);*/ - idx_g = vquant_fx(y_gain_tmp2+3, YGain_mean_LR_fx+3, y_gain_tmp2+3, YGain_dic2_LR_fx, 4, 32 ); + idx_g = vquant_fx( y_gain_tmp2 + 3, YGain_mean_LR_fx + 3, y_gain_tmp2 + 3, YGain_dic2_LR_fx, 4, 32 ); push_indice_fx( hBstr, IND_Y_GAIN_TMP, idx_g, 5 ); /*idx_g = (short)vquant(y_gain_tmp2+7, YGain_mean_LR+7, y_gain_tmp2+7, YGain_dic3_LR, 5, 32);*/ - idx_g = vquant_fx(y_gain_tmp2+7, YGain_mean_LR_fx+7, y_gain_tmp2+7, YGain_dic3_LR_fx, 5, 32); + idx_g = vquant_fx( y_gain_tmp2 + 7, YGain_mean_LR_fx + 7, y_gain_tmp2 + 7, YGain_dic3_LR_fx, 5, 32 ); push_indice_fx( hBstr, IND_Y_GAIN_TMP, idx_g, 5 ); /*set_f(y_gain_tmp2+12, 0, MBANDS_GN-12);*/ - set16_fx(y_gain_tmp2+12, 0, MBANDS_GN-12); + set16_fx( y_gain_tmp2 + 12, 0, MBANDS_GN - 12 ); /* Update to quantized vector */ - Copy(y_gain_tmp2, y_gain_tmp, 8); + Copy( y_gain_tmp2, y_gain_tmp, 8 ); - Copy(y_gain_tmp2+8, y_gain_tmp3, 4); - set16_fx(y_gain_tmp+8, 0,8); - fft_rel_fx(y_gain_tmp2+8, 4, 2); + Copy( y_gain_tmp2 + 8, y_gain_tmp3, 4 ); + set16_fx( y_gain_tmp + 8, 0, 8 ); + fft_rel_fx( y_gain_tmp2 + 8, 4, 2 ); - Copy(y_gain_tmp2+8, y_gain_tmp+8, 3); + Copy( y_gain_tmp2 + 8, y_gain_tmp + 8, 3 ); y_gain_tmp[15] = y_gain_tmp2[11]; - ifft_rel_fx(y_gain_tmp+8, 8, 3); + ifft_rel_fx( y_gain_tmp + 8, 8, 3 ); - FOR(i = 8; i < 16; i++) + FOR( i = 8; i < 16; i++ ) { /*y_gain_tmp[i] *= 1.41f;*/ - y_gain_tmp[i] = shl( mult_r(y_gain_tmp[i] , 23101),1) ; + y_gain_tmp[i] = shl( mult_r( y_gain_tmp[i], 23101 ), 1 ); move16(); } y_gain_tmp[8] = y_gain_tmp3[0]; move16(); - y_gain_tmp[10]= y_gain_tmp3[1]; + y_gain_tmp[10] = y_gain_tmp3[1]; move16(); - y_gain_tmp[12]= y_gain_tmp3[2]; + y_gain_tmp[12] = y_gain_tmp3[2]; move16(); - y_gain_tmp[14]= y_gain_tmp3[3]; + y_gain_tmp[14] = y_gain_tmp3[3]; move16(); } ELSE { - idx_g = vquant_fx(y_gain_tmp, YG_mean16_fx, y_gain_tmp, YG_dicMR_1_fx, 4, 64); + idx_g = vquant_fx( y_gain_tmp, YG_mean16_fx, y_gain_tmp, YG_dicMR_1_fx, 4, 64 ); push_indice_fx( hBstr, IND_Y_GAIN_TMP, idx_g, 6 ); - idx_g = vquant_fx(y_gain_tmp+4, YG_mean16_fx+4, y_gain_tmp+4, YG_dicMR_2_fx, 4, 32); + idx_g = vquant_fx( y_gain_tmp + 4, YG_mean16_fx + 4, y_gain_tmp + 4, YG_dicMR_2_fx, 4, 32 ); push_indice_fx( hBstr, IND_Y_GAIN_TMP, idx_g, 5 ); - idx_g = vquant_fx(y_gain_tmp+8, YG_mean16_fx+8, y_gain_tmp+8, YG_dicMR_3_fx, 4, 32); + idx_g = vquant_fx( y_gain_tmp + 8, YG_mean16_fx + 8, y_gain_tmp + 8, YG_dicMR_3_fx, 4, 32 ); push_indice_fx( hBstr, IND_Y_GAIN_TMP, idx_g, 5 ); - idx_g = vquant_fx(y_gain_tmp+12, YG_mean16_fx+12, y_gain_tmp+12, YG_dicMR_4_fx, 4, 16); + idx_g = vquant_fx( y_gain_tmp + 12, YG_mean16_fx + 12, y_gain_tmp + 12, YG_dicMR_4_fx, 4, 16 ); push_indice_fx( hBstr, IND_Y_GAIN_TMP, idx_g, 4 ); } } /* Gain adjustment to fit ACELP generic inactive coding gain at low rate */ - GSC_gain_adj(coder_type, core_brate, mean_4g[0], y_gain_tmp2 /* dummy buffer */, y_gain_tmp, y_gainQ); + GSC_gain_adj( coder_type, core_brate, mean_4g[0], y_gain_tmp2 /* dummy buffer */, y_gain_tmp, y_gainQ ); - return mean_4g[0]; /*Q12*/ + return mean_4g[0]; /*Q12*/ } /*-------------------------------------------------------------------* * VDQ_vec() @@ -1008,26 +1004,26 @@ Word16 gsc_gainQ_fx( /*Q12*/ * Return the dequantized vector of index *-------------------------------------------------------------------*/ static Word16 VDQ_vec_fx( - Word16 *Qvec_out_fx, /* o: Quanitzed vector */ - const Word16 *mean_dic_fx, /* i: average codebook */ - const Word16 *dic_fx, /* i: codebook */ - const Word16 index_fx, /* i: index of codebook*/ - const Word16 vec_en_fx /* i: vector length */ + Word16 *Qvec_out_fx, /* o: Quanitzed vector */ + const Word16 *mean_dic_fx, /* i: average codebook */ + const Word16 *dic_fx, /* i: codebook */ + const Word16 index_fx, /* i: index of codebook*/ + const Word16 vec_en_fx /* i: vector length */ ) { Word16 i, j; /*j = shr_r(extract_l(L_mult(index_fx,vec_en_fx)),1);*/ - j = i_mult2(index_fx,vec_en_fx); - FOR ( i = 0; i < vec_en_fx; i++) + j = i_mult2( index_fx, vec_en_fx ); + FOR( i = 0; i < vec_en_fx; i++ ) { Qvec_out_fx[i] = dic_fx[j++]; move16(); } - FOR(i = 0; i < vec_en_fx; i++) + FOR( i = 0; i < vec_en_fx; i++ ) { - Qvec_out_fx[i] = add(Qvec_out_fx[i],mean_dic_fx[i]); + Qvec_out_fx[i] = add( Qvec_out_fx[i], mean_dic_fx[i] ); move16(); } diff --git a/lib_com/gs_inact_switching_fx.c b/lib_com/gs_inact_switching_fx.c index 5bfd30572..16fbddb41 100644 --- a/lib_com/gs_inact_switching_fx.c +++ b/lib_com/gs_inact_switching_fx.c @@ -2,19 +2,19 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ #include "stl.h" /*-------------------------------------------------------------------* * Local constants *-------------------------------------------------------------------*/ -#define ALPHA0_FX 13107 -#define BETA0_FX (32768-ALPHA0_FX) +#define ALPHA0_FX 13107 +#define BETA0_FX ( 32768 - ALPHA0_FX ) /*========================================================================*/ /* FUNCTION : Inac_swtch_ematch_fx() */ @@ -40,16 +40,18 @@ /* _ None */ /*========================================================================*/ void Inac_swtch_ematch_fx( - Word16 exc2[], /* i/o: CELP/GSC excitation buffer Q_exc*/ - Word16 dct_exc_tmp[], /* i : GSC excitation in DCT domain */ - Word16 lt_ener_per_band[], /* i/o: Long term energy per band Q12 */ - const Word16 coder_type, /* i : Coding mode */ - const Word16 L_frame, /* i : Frame lenght */ - const Word32 core_brate, /* i : Core bit rate */ - const Word16 Q_exc /* i : input and output format of exc2 */ - ,const Word16 bfi /* i : frame lost indicator */ - ,const Word16 last_core, /* i : Last core used */ - const Word16 last_codec_mode /* i : Last codec mode */ + Word16 exc2[], /* i/o: CELP/GSC excitation buffer Q_exc*/ + Word16 dct_exc_tmp[], /* i : GSC excitation in DCT domain */ + Word16 lt_ener_per_band[], /* i/o: Long term energy per band Q12 */ + const Word16 coder_type, /* i : Coding mode */ + const Word16 L_frame, /* i : Frame lenght */ + const Word32 core_brate, /* i : Core bit rate */ + const Word16 Q_exc /* i : input and output format of exc2 */ + , + const Word16 bfi /* i : frame lost indicator */ + , + const Word16 last_core, /* i : Last core used */ + const Word16 last_codec_mode /* i : Last codec mode */ ) { Word16 Ener_per_bd[MBANDS_GN]; @@ -57,7 +59,7 @@ void Inac_swtch_ematch_fx( Word16 *pt_exc; Word16 j, i; - Word16 exp,frac; + Word16 exp, frac; Word32 L_tmp; /*-------------------------------------------------------------------------- @@ -70,86 +72,85 @@ void Inac_swtch_ematch_fx( test(); test(); test(); - IF(EQ_16(coder_type,AUDIO)&&bfi==0) + IF( EQ_16( coder_type, AUDIO ) && bfi == 0 ) { - Ener_per_band_comp_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1); + Ener_per_band_comp_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1 ); /* reset long-term energy per band */ - FOR(i = 0; i < MBANDS_GN; i++) + FOR( i = 0; i < MBANDS_GN; i++ ) { lt_ener_per_band[i] = Ener_per_bd[i]; move16(); } - } - ELSE IF( EQ_16(coder_type,VOICED)||EQ_16(coder_type,GENERIC)||EQ_16(coder_type,TRANSITION)||NE_16(last_core,ACELP_CORE)||NE_16(last_codec_mode,MODE1)) + ELSE IF( EQ_16( coder_type, VOICED ) || EQ_16( coder_type, GENERIC ) || EQ_16( coder_type, TRANSITION ) || NE_16( last_core, ACELP_CORE ) || NE_16( last_codec_mode, MODE1 ) ) { /* Find spectrum and energy per band for GC and VC frames */ - edct_16fx( exc2, dct_exc_tmp, L_frame, 5, EVS_MONO); + edct_16fx( exc2, dct_exc_tmp, L_frame, 5, EVS_MONO ); - Ener_per_band_comp_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1); + Ener_per_band_comp_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1 ); /* reset long-term energy per band */ - FOR(i = 0; i < MBANDS_GN; i++) + FOR( i = 0; i < MBANDS_GN; i++ ) { lt_ener_per_band[i] = Ener_per_bd[i]; move16(); } } - ELSE IF( EQ_16(coder_type,INACTIVE)&&LE_32(core_brate,ACELP_24k40)) + ELSE IF( EQ_16( coder_type, INACTIVE ) && LE_32( core_brate, ACELP_24k40 ) ) { /* Find spectrum and energy per band for inactive frames */ - edct_16fx( exc2, dct_exc_tmp, L_frame, 5, EVS_MONO); + edct_16fx( exc2, dct_exc_tmp, L_frame, 5, EVS_MONO ); Ener_per_band_comp_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1 ); /* More agressive smoothing in the first 50 frames */ pt_exc = dct_exc_tmp; move16(); - FOR(i = 0; i < MBANDS_GN; i++) + FOR( i = 0; i < MBANDS_GN; i++ ) { /* Compute smoothing gain to apply with gain limitation */ - L_tmp = L_mult(ALPHA0_FX,lt_ener_per_band[i]); /*Q(15+12+1)=Q(28) */ - L_tmp = L_mac(L_tmp,BETA0_FX,Ener_per_bd[i]); /*Q28 */ - lt_ener_per_band[i] = round_fx(L_tmp); /*Q12 */ + L_tmp = L_mult( ALPHA0_FX, lt_ener_per_band[i] ); /*Q(15+12+1)=Q(28) */ + L_tmp = L_mac( L_tmp, BETA0_FX, Ener_per_bd[i] ); /*Q28 */ + lt_ener_per_band[i] = round_fx( L_tmp ); /*Q12 */ - ftmp = sub(lt_ener_per_band[i],Ener_per_bd[i]); /*Q12 */ + ftmp = sub( lt_ener_per_band[i], Ener_per_bd[i] ); /*Q12 */ /* ftmp = (float)pow(10, ftmp);= pow(2,3.321928*ftmp);*/ - L_tmp = L_mult(27213,ftmp); /*Q(13+12+1)=Q26 ; 27213=3.321928 in Q13 */ - L_tmp = L_shr(L_tmp, 10); /* From Q26 to Q16 */ - frac = L_Extract_lc(L_tmp, &exp); /* Extract exponent of ftmp */ - ftmp = extract_l(Pow2(14, frac));/* Put 14 as exponent so that */ + L_tmp = L_mult( 27213, ftmp ); /*Q(13+12+1)=Q26 ; 27213=3.321928 in Q13 */ + L_tmp = L_shr( L_tmp, 10 ); /* From Q26 to Q16 */ + frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent of ftmp */ + ftmp = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ - exp = sub(exp,14); - IF( LT_16(i,2)) + exp = sub( exp, 14 ); + IF( LT_16( i, 2 ) ) { - FOR (j = 0; j < 8; j ++) + FOR( j = 0; j < 8; j++ ) { - L_tmp = L_mult(*pt_exc,ftmp); /* Q_exc*Q0 -> Q(Q_exc+1) */ + L_tmp = L_mult( *pt_exc, ftmp ); /* Q_exc*Q0 -> Q(Q_exc+1) */ #ifdef BASOP_NOGLOB L_tmp = L_shl_sat( L_tmp, add( exp, 15 ) ); /* Q(Q_exc+1) -> Q(16+Q_exc)*/ - *pt_exc = round_fx_sat(L_tmp); + *pt_exc = round_fx_sat( L_tmp ); #else - L_tmp = L_shl(L_tmp, add(exp,15)); /* Q(Q_exc+1) -> Q(16+Q_exc)*/ - *pt_exc = round_fx(L_tmp); + L_tmp = L_shl( L_tmp, add( exp, 15 ) ); /* Q(Q_exc+1) -> Q(16+Q_exc)*/ + *pt_exc = round_fx( L_tmp ); #endif pt_exc++; } } ELSE { - FOR (j = 0; j < 16; j ++) + FOR( j = 0; j < 16; j++ ) { - L_tmp = L_mult(*pt_exc,ftmp); /* Q_exc*Q0 -> Q(Q_exc+1) */ + L_tmp = L_mult( *pt_exc, ftmp ); /* Q_exc*Q0 -> Q(Q_exc+1) */ #ifdef BASOP_NOGLOB L_tmp = L_shl_sat( L_tmp, add( exp, 15 ) ); /* Q(Q_exc+1) -> Q(16+Q_exc)*/ - *pt_exc = round_fx_sat(L_tmp); /*Q_exc*/ + *pt_exc = round_fx_sat( L_tmp ); /*Q_exc*/ #else - L_tmp = L_shl(L_tmp, add(exp,15)); /* Q(Q_exc+1) -> Q(16+Q_exc)*/ - *pt_exc = round_fx(L_tmp); /*Q_exc*/ + L_tmp = L_shl( L_tmp, add( exp, 15 ) ); /* Q(Q_exc+1) -> Q(16+Q_exc)*/ + *pt_exc = round_fx( L_tmp ); /*Q_exc*/ #endif pt_exc++; } @@ -157,7 +158,7 @@ void Inac_swtch_ematch_fx( } /* Going back to time */ - edct_16fx( dct_exc_tmp, exc2, L_frame, 5 , EVS_MONO); + edct_16fx( dct_exc_tmp, exc2, L_frame, 5, EVS_MONO ); } return; @@ -165,17 +166,20 @@ void Inac_swtch_ematch_fx( void Inac_switch_ematch_ivas_fx( - Word16 exc2[], /* i/o: CELP/GSC excitation buffer Q_exc*/ - Word16 dct_exc_tmp[], /* i : GSC excitation in DCT domain */ - Word16 lt_ener_per_band[], /* i/o: Long term energy per band Q12 */ - const Word16 coder_type, /* i : Coding mode */ - const Word16 L_frame, /* i : Frame lenght */ - const Word32 total_brate, /* i : total bit rate */ - const Word16 Q_exc /* i : input and output format of exc2 */ - , const Word16 bfi /* i : frame lost indicator */ - , const Word16 last_core, /* i : Last core used */ - const Word16 last_codec_mode /* i : Last codec mode */ - , const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag*/ + Word16 exc2[], /* i/o: CELP/GSC excitation buffer Q_exc*/ + Word16 dct_exc_tmp[], /* i : GSC excitation in DCT domain */ + Word16 lt_ener_per_band[], /* i/o: Long term energy per band Q12 */ + const Word16 coder_type, /* i : Coding mode */ + const Word16 L_frame, /* i : Frame lenght */ + const Word32 total_brate, /* i : total bit rate */ + const Word16 Q_exc /* i : input and output format of exc2 */ + , + const Word16 bfi /* i : frame lost indicator */ + , + const Word16 last_core, /* i : Last core used */ + const Word16 last_codec_mode /* i : Last codec mode */ + , + const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag*/ const Word16 element_mode /* i : element mode */ ) { @@ -199,77 +203,76 @@ void Inac_switch_ematch_ivas_fx( test(); test(); test(); - IF((EQ_16(coder_type, AUDIO) || (EQ_16(coder_type, UNVOICED) && EQ_16(tdm_low_rate_mode, 1))) && bfi == 0) + IF( ( EQ_16( coder_type, AUDIO ) || ( EQ_16( coder_type, UNVOICED ) && EQ_16( tdm_low_rate_mode, 1 ) ) ) && bfi == 0 ) { - Ener_per_band_comp_ivas_fx(dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1, L_frame); + Ener_per_band_comp_ivas_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1, L_frame ); /* reset long-term energy per band */ - FOR(i = 0; i < MBANDS_GN; i++) + FOR( i = 0; i < MBANDS_GN; i++ ) { lt_ener_per_band[i] = Ener_per_bd[i]; move16(); } - } - ELSE IF(EQ_16(coder_type, VOICED) || EQ_16(coder_type, GENERIC) || EQ_16(coder_type, TRANSITION) || NE_16(last_core, ACELP_CORE) || NE_16(last_codec_mode, MODE1) || (GT_16(element_mode, EVS_MONO) && EQ_16(coder_type, UNVOICED))) + ELSE IF( EQ_16( coder_type, VOICED ) || EQ_16( coder_type, GENERIC ) || EQ_16( coder_type, TRANSITION ) || NE_16( last_core, ACELP_CORE ) || NE_16( last_codec_mode, MODE1 ) || ( GT_16( element_mode, EVS_MONO ) && EQ_16( coder_type, UNVOICED ) ) ) { /* Find spectrum and energy per band for GC and VC frames */ - edct_16fx(exc2, dct_exc_tmp, L_frame, 5, element_mode); + edct_16fx( exc2, dct_exc_tmp, L_frame, 5, element_mode ); - Ener_per_band_comp_ivas_fx(dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1, L_frame); + Ener_per_band_comp_ivas_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1, L_frame ); /* reset long-term energy per band */ - FOR(i = 0; i < MBANDS_GN; i++) + FOR( i = 0; i < MBANDS_GN; i++ ) { lt_ener_per_band[i] = Ener_per_bd[i]; move16(); } } - ELSE IF(EQ_16(coder_type, INACTIVE) && LE_32(total_brate, MAX_GSC_INACTIVE_BRATE)) + ELSE IF( EQ_16( coder_type, INACTIVE ) && LE_32( total_brate, MAX_GSC_INACTIVE_BRATE ) ) { /* Find spectrum and energy per band for inactive frames */ - edct_16fx(exc2, dct_exc_tmp, L_frame, 5, element_mode); - Ener_per_band_comp_ivas_fx(dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1, L_frame); + edct_16fx( exc2, dct_exc_tmp, L_frame, 5, element_mode ); + Ener_per_band_comp_ivas_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1, L_frame ); /* More agressive smoothing in the first 50 frames */ pt_exc = dct_exc_tmp; move16(); - FOR(i = 0; i < MBANDS_GN; i++) + FOR( i = 0; i < MBANDS_GN; i++ ) { /* Compute smoothing gain to apply with gain limitation */ - L_tmp = L_mult(ALPHA0_FX, lt_ener_per_band[i]); /*Q(15+12+1)=Q(28) */ - L_tmp = L_mac(L_tmp, BETA0_FX, Ener_per_bd[i]); /*Q28 */ - lt_ener_per_band[i] = round_fx(L_tmp); /*Q12 */ + L_tmp = L_mult( ALPHA0_FX, lt_ener_per_band[i] ); /*Q(15+12+1)=Q(28) */ + L_tmp = L_mac( L_tmp, BETA0_FX, Ener_per_bd[i] ); /*Q28 */ + lt_ener_per_band[i] = round_fx( L_tmp ); /*Q12 */ - ftmp = sub(lt_ener_per_band[i], Ener_per_bd[i]); /*Q12 */ + ftmp = sub( lt_ener_per_band[i], Ener_per_bd[i] ); /*Q12 */ /* ftmp = (float)pow(10, ftmp);= pow(2,3.321928*ftmp);*/ - L_tmp = L_mult(27213, ftmp); /*Q(13+12+1)=Q26 ; 27213=3.321928 in Q13 */ - L_tmp = L_shr(L_tmp, 10); /* From Q26 to Q16 */ - frac = L_Extract_lc(L_tmp, &exp); /* Extract exponent of ftmp */ - ftmp = extract_l(Pow2(14, frac));/* Put 14 as exponent so that */ + L_tmp = L_mult( 27213, ftmp ); /*Q(13+12+1)=Q26 ; 27213=3.321928 in Q13 */ + L_tmp = L_shr( L_tmp, 10 ); /* From Q26 to Q16 */ + frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent of ftmp */ + ftmp = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ - exp = sub(exp, 14); - IF(LT_16(i, 2)) + exp = sub( exp, 14 ); + IF( LT_16( i, 2 ) ) { - FOR(j = 0; j < 8; j++) + FOR( j = 0; j < 8; j++ ) { - L_tmp = L_mult0(*pt_exc, ftmp); - L_tmp = L_shl_sat(L_tmp, add(exp, 15)); /* Q(Q_exc) -> Q(15+Q_exc)*/ - *pt_exc = round_fx_sat(L_tmp); /*Q_exc - 1*/ + L_tmp = L_mult0( *pt_exc, ftmp ); + L_tmp = L_shl_sat( L_tmp, add( exp, 15 ) ); /* Q(Q_exc) -> Q(15+Q_exc)*/ + *pt_exc = round_fx_sat( L_tmp ); /*Q_exc - 1*/ pt_exc++; } } ELSE { - FOR(j = 0; j < 16; j++) + FOR( j = 0; j < 16; j++ ) { - L_tmp = L_mult0(*pt_exc,ftmp); - L_tmp = L_shl_sat(L_tmp, add(exp,15)); /* Q(Q_exc) -> Q(15+Q_exc)*/ - *pt_exc = round_fx_sat(L_tmp); /*Q_exc - 1*/ + L_tmp = L_mult0( *pt_exc, ftmp ); + L_tmp = L_shl_sat( L_tmp, add( exp, 15 ) ); /* Q(Q_exc) -> Q(15+Q_exc)*/ + *pt_exc = round_fx_sat( L_tmp ); /*Q_exc - 1*/ pt_exc++; } } @@ -278,8 +281,8 @@ void Inac_switch_ematch_ivas_fx( /* Going back to time */ Scale_sig( dct_exc_tmp, 240, 1 ); // Q_exc Scale_sig( exc2, 240, 1 ); // Q_exc - edct_16fx(dct_exc_tmp, exc2, L_frame, 5, element_mode); + edct_16fx( dct_exc_tmp, exc2, L_frame, 5, element_mode ); } return; -} \ No newline at end of file +} diff --git a/lib_com/gs_noisefill_fx.c b/lib_com/gs_noisefill_fx.c index 8c6d55ffe..1809a1f6f 100644 --- a/lib_com/gs_noisefill_fx.c +++ b/lib_com/gs_noisefill_fx.c @@ -14,26 +14,25 @@ *-------------------------------------------------------------------*/ static void gs_noisf_fx( - const Word16 Start_BIN, /* i : First bin for noise fill */ - const Word16 NB_Qbins, /* i : Number of bin per band */ - const Word16 Noise_fac, /* i : Noise level Q15 */ - const Word16 *y_norm, /* i : Quantized pulses Qn */ - Word16 *exc_diffQ, /* o : Quantized pulses with noise added Qn */ - Word16 *seed_tcx, /* i : Random generator seed */ - const Word16 coder_type, /* i : coder type */ - Word16 qNoise_fac -) + const Word16 Start_BIN, /* i : First bin for noise fill */ + const Word16 NB_Qbins, /* i : Number of bin per band */ + const Word16 Noise_fac, /* i : Noise level Q15 */ + const Word16 *y_norm, /* i : Quantized pulses Qn */ + Word16 *exc_diffQ, /* o : Quantized pulses with noise added Qn */ + Word16 *seed_tcx, /* i : Random generator seed */ + const Word16 coder_type, /* i : coder type */ + Word16 qNoise_fac ) { Word32 ftmp; Word16 i, k; Word16 NB_zer; - Word32 const_1=1; + Word32 const_1 = 1; Word16 tmp; - NB_zer = shr(NB_Qbins,1); + NB_zer = shr( NB_Qbins, 1 ); - const_1 = L_shl(const_1, add(qNoise_fac, qNoise_fac)); - if( EQ_16(coder_type,INACTIVE)) + const_1 = L_shl( const_1, add( qNoise_fac, qNoise_fac ) ); + if ( EQ_16( coder_type, INACTIVE ) ) { NB_zer = 2; move16(); @@ -44,36 +43,35 @@ static void gs_noisf_fx( * injected only from 1066Hz to 6400Hz. * *----------------------------------------------*/ - FOR( k=Start_BIN; k= ACELP_22k60 ) + ELSE IF( bitrate >= ACELP_22k60 ) { noise_offset = 9830; - move16();/*.3f * 32768 */ + move16(); /*.3f * 32768 */ } - ELSE IF ( bitrate >= ACELP_9k60 ) + ELSE IF( bitrate >= ACELP_9k60 ) { noise_offset = 11469; move16(); /*0.35f * 32768 */ @@ -119,11 +117,11 @@ static void EstimateNoiseLevel_inner_fx( move16(); /*.4f * 32768 */ } - set16_fx( noisepb + i_band, noise_offset, sub(Mbands_gn, i_band) ); + set16_fx( noisepb + i_band, noise_offset, sub( Mbands_gn, i_band ) ); FOR( i = i_band; i < 5; i++ ) { - noisepb[i] = s_min(noisepb[i], 6554); + noisepb[i] = s_min( noisepb[i], 6554 ); move16(); } @@ -153,16 +151,16 @@ static void EstimateNoiseLevel_inner_fx( /* _ None */ /*==========================================================================*/ static void EstimateNoiseLevel_fx( - Word16 *noisepb, /* o : Noise per band */ - const Word32 bitrate, /* i : Bitrate of the codec */ - const Word16 Diff_len, /* i : number of bin before cut-off frequency */ - const Word16 Mbands_gn, /* i : number of bands */ - const Word16 coder_type, /* i : coder type */ - const Word16 noise_lev, /* i : pulses dynamic */ - const Word16 pit_band_idx, /* i : bin position of the cut-off frequency */ - Word16 last_bin, /* i : the last bin of bit allocation */ + Word16 *noisepb, /* o : Noise per band */ + const Word32 bitrate, /* i : Bitrate of the codec */ + const Word16 Diff_len, /* i : number of bin before cut-off frequency */ + const Word16 Mbands_gn, /* i : number of bands */ + const Word16 coder_type, /* i : coder type */ + const Word16 noise_lev, /* i : pulses dynamic */ + const Word16 pit_band_idx, /* i : bin position of the cut-off frequency */ + Word16 last_bin, /* i : the last bin of bit allocation */ Word16 bwidth, - const int16_t L_frame /* i : frame length */ + const int16_t L_frame /* i : frame length */ ) { Word16 i_band; @@ -170,18 +168,18 @@ static void EstimateNoiseLevel_fx( i_band = 0; move16(); - IF( LT_16(Diff_len, L_frame)) + IF( LT_16( Diff_len, L_frame ) ) { - EstimateNoiseLevel_inner_fx(noisepb, bitrate, i_band, MBANDS_GN); + EstimateNoiseLevel_inner_fx( noisepb, bitrate, i_band, MBANDS_GN ); IF( coder_type != INACTIVE ) { test(); test(); - IF( (EQ_32(bitrate,ACELP_8k00)&>_16(last_bin,8))&&NE_16(bwidth,NB)) + IF( ( EQ_32( bitrate, ACELP_8k00 ) && GT_16( last_bin, 8 ) ) && NE_16( bwidth, NB ) ) { - FOR( ; Mbands_gn > i_band; i_band++) + FOR( ; Mbands_gn > i_band; i_band++ ) { - noisepb[i_band] = add(noisepb[i_band],noisepb[i_band]); + noisepb[i_band] = add( noisepb[i_band], noisepb[i_band] ); move16(); } } @@ -189,49 +187,49 @@ static void EstimateNoiseLevel_fx( { FOR( ; pit_band_idx > i_band; i_band++ ) { - noisepb[i_band] = mult_r(noisepb[i_band], 16384); - move16();/* 1/2=0.5 in Q15 */ + noisepb[i_band] = mult_r( noisepb[i_band], 16384 ); + move16(); /* 1/2=0.5 in Q15 */ } } } } test(); - IF ( (EQ_16(coder_type,INACTIVE)||GE_16(noise_lev,NOISE_LEVEL_SP3)) && EQ_16(L_frame, L_FRAME)) + IF( ( EQ_16( coder_type, INACTIVE ) || GE_16( noise_lev, NOISE_LEVEL_SP3 ) ) && EQ_16( L_frame, L_FRAME ) ) { FOR( i_band = 9; i_band < Mbands_gn; i_band++ ) { - noisepb[i_band] = add(noisepb[i_band], mult_r(noisepb[i_band], 4915)); - move16();/*noisepb[i_band]*1.15=noisepb[i_band] *(1 + 0.15) */ + noisepb[i_band] = add( noisepb[i_band], mult_r( noisepb[i_band], 4915 ) ); + move16(); /*noisepb[i_band]*1.15=noisepb[i_band] *(1 + 0.15) */ } } - ELSE IF(EQ_16(L_frame, L_FRAME16k)) + ELSE IF( EQ_16( L_frame, L_FRAME16k ) ) { - IF (EQ_32(bitrate, ACELP_13k20)) + IF( EQ_32( bitrate, ACELP_13k20 ) ) { - set16_fx(noisepb, 14746/*0.45*/, Mbands_gn); + set16_fx( noisepb, 14746 /*0.45*/, Mbands_gn ); } - IF (EQ_16(coder_type, INACTIVE)) + IF( EQ_16( coder_type, INACTIVE ) ) { - FOR (; i_band < Mbands_gn; i_band++) + FOR( ; i_band < Mbands_gn; i_band++ ) { - noisepb[i_band] = 13107/*.4f*/; + noisepb[i_band] = 13107 /*.4f*/; move16(); } } - ELSE IF (LE_16(noise_lev, NOISE_LEVEL_SP1) && GT_32(bitrate, ACELP_16k40)) + ELSE IF( LE_16( noise_lev, NOISE_LEVEL_SP1 ) && GT_32( bitrate, ACELP_16k40 ) ) { - FOR (; i_band < sub(Mbands_gn, 4); i_band++) + FOR( ; i_band < sub( Mbands_gn, 4 ); i_band++ ) { - noisepb[i_band] = mult_r(noisepb[i_band], 19661)/*.6f*/; + noisepb[i_band] = mult_r( noisepb[i_band], 19661 ) /*.6f*/; move16(); } } - ELSE IF (LE_16(noise_lev, NOISE_LEVEL_SP2) && GT_32(bitrate, ACELP_16k40)) + ELSE IF( LE_16( noise_lev, NOISE_LEVEL_SP2 ) && GT_32( bitrate, ACELP_16k40 ) ) { - FOR (; i_band < sub(Mbands_gn, 4); i_band++) + FOR( ; i_band < sub( Mbands_gn, 4 ); i_band++ ) { - noisepb[i_band] = mult_r(noisepb[i_band], 26214)/*.8f*/; + noisepb[i_band] = mult_r( noisepb[i_band], 26214 ) /*.8f*/; move16(); } } @@ -265,20 +263,19 @@ static void EstimateNoiseLevel_fx( /* _ None */ /*============================================================================*/ static void Apply_NoiseFill_fx( - Word16 *exc_diffQ, /* i/o: Noise per band qexc_diffQ */ - Word16 *seed_tcx, /* i : Seed for noise */ - const Word16 *noisepb, /* i : Noise per band Q15 */ - const Word16 Diff_len, /* i : number of bin before cut-off frequency */ - const Word16 Mbands_gn, /* i : number of bands */ - const Word16 coder_type, /* i : coder type */ - const Word16 *freq_nsbin_per_band, /* i : bin per bands tables */ - Word16 qexc_diffQ -) + Word16 *exc_diffQ, /* i/o: Noise per band qexc_diffQ */ + Word16 *seed_tcx, /* i : Seed for noise */ + const Word16 *noisepb, /* i : Noise per band Q15 */ + const Word16 Diff_len, /* i : number of bin before cut-off frequency */ + const Word16 Mbands_gn, /* i : number of bands */ + const Word16 coder_type, /* i : coder type */ + const Word16 *freq_nsbin_per_band, /* i : bin per bands tables */ + Word16 qexc_diffQ ) { Word16 StartBin, NB_Qbins, i_band; StartBin = 0; move16(); - NB_Qbins = 0; + NB_Qbins = 0; move16(); FOR( i_band = 0; i_band < Mbands_gn; i_band++ ) @@ -288,9 +285,9 @@ static void Apply_NoiseFill_fx( NB_Qbins = freq_nsbin_per_band[i_band]; move16(); - IF( LT_16(Diff_len,L_FRAME)) + IF( LT_16( Diff_len, L_FRAME ) ) { - gs_noisf_fx( StartBin , NB_Qbins, noisepb[i_band], exc_diffQ, exc_diffQ, seed_tcx, coder_type, qexc_diffQ); + gs_noisf_fx( StartBin, NB_Qbins, noisepb[i_band], exc_diffQ, exc_diffQ, seed_tcx, coder_type, qexc_diffQ ); } } @@ -321,10 +318,10 @@ void freq_dnw_scaling_fx( const Word16 cor_strong_limit, /* i : HF correlation */ const Word16 coder_type, /* i : coder type */ const Word16 noise_lev, /* i : Noise level */ - const Word32 core_brate, /* i : Core bitrate */ - Word16 fy_norm[], /* i/o: Frequency quantized parameter */ - Word16 Qx, /* Q format of fy_norm*/ - const int16_t L_frame /* i : frame length */ + const Word32 core_brate, /* i : Core bitrate */ + Word16 fy_norm[], /* i/o: Frequency quantized parameter */ + Word16 Qx, /* Q format of fy_norm*/ + const int16_t L_frame /* i : frame length */ ) { @@ -336,116 +333,115 @@ void freq_dnw_scaling_fx( start_sc = L_frame; move16(); test(); - IF( LE_32(core_brate,ACELP_8k00)&&EQ_16(coder_type,INACTIVE)) + IF( LE_32( core_brate, ACELP_8k00 ) && EQ_16( coder_type, INACTIVE ) ) { - sc_dyn = mult_r(sc_dyn,4915); /*Q15 (0.15 in Q15) */ + sc_dyn = mult_r( sc_dyn, 4915 ); /*Q15 (0.15 in Q15) */ start_sc = 64; move16(); } - ELSE IF ( EQ_16(coder_type,INACTIVE)) + ELSE IF( EQ_16( coder_type, INACTIVE ) ) { - sc_dyn = mult_r(sc_dyn,8192); /*Q15 (0.25 in Q15) */ + sc_dyn = mult_r( sc_dyn, 8192 ); /*Q15 (0.25 in Q15) */ start_sc = 80; move16(); } ELSE { /*sc_dyn = (float)(NOISE_LEVEL_SP3 - noise_lev)/10.0f + 0.4f;*/ - sc_dyn = extract_l(L_mac(13107, sub(NOISE_LEVEL_SP3, noise_lev), 1638)); /*Q0*Q14x2+Q15 =Q15*/ - start_sc = add(112, shl(sub(NOISE_LEVEL_SP3, noise_lev), 4)); - if( EQ_16(noise_lev,NOISE_LEVEL_SP0)) + sc_dyn = extract_l( L_mac( 13107, sub( NOISE_LEVEL_SP3, noise_lev ), 1638 ) ); /*Q0*Q14x2+Q15 =Q15*/ + start_sc = add( 112, shl( sub( NOISE_LEVEL_SP3, noise_lev ), 4 ) ); + if ( EQ_16( noise_lev, NOISE_LEVEL_SP0 ) ) { start_sc = L_FRAME; move16(); } } - IF (EQ_16(L_frame, L_FRAME16k) && LE_32(core_brate, ACELP_24k40)) + IF( EQ_16( L_frame, L_FRAME16k ) && LE_32( core_brate, ACELP_24k40 ) ) { /*sc_dyn += 0.125f;*/ - sc_dyn = add(sc_dyn, 4096); /* Saturates to 1.0 */ + sc_dyn = add( sc_dyn, 4096 ); /* Saturates to 1.0 */ } - FOR(i = start_sc; i < L_frame; i++) + FOR( i = start_sc; i < L_frame; i++ ) { - fy_norm[i] = mult_r(fy_norm[i],sc_dyn); - move16();/*Qx */ + fy_norm[i] = mult_r( fy_norm[i], sc_dyn ); + move16(); /*Qx */ } test(); test(); - IF( (LT_32(core_brate,ACELP_13k20)&&cor_strong_limit==0)||LT_32(core_brate,ACELP_9k60)) + IF( ( LT_32( core_brate, ACELP_13k20 ) && cor_strong_limit == 0 ) || LT_32( core_brate, ACELP_9k60 ) ) { - FOR(i = 160; i < L_frame; i++) + FOR( i = 160; i < L_frame; i++ ) { - fy_norm[i] = s_min(fy_norm[i],shl(1,Qx)); + fy_norm[i] = s_min( fy_norm[i], shl( 1, Qx ) ); move16(); - fy_norm[i] = s_max(fy_norm[i],shl(-1,Qx)); + fy_norm[i] = s_max( fy_norm[i], shl( -1, Qx ) ); move16(); } } - ELSE IF ( LT_32(core_brate,ACELP_22k60)) + ELSE IF( LT_32( core_brate, ACELP_22k60 ) ) { - FOR(i = 160; i < L_frame; i++) + FOR( i = 160; i < L_frame; i++ ) { - fy_norm[i] = s_min(fy_norm[i],shr_r(1536,sub(10,Qx))); + fy_norm[i] = s_min( fy_norm[i], shr_r( 1536, sub( 10, Qx ) ) ); move16(); - fy_norm[i] = s_max(fy_norm[i],shr_r(-1536,sub(10,Qx))); + fy_norm[i] = s_max( fy_norm[i], shr_r( -1536, sub( 10, Qx ) ) ); move16(); } } return; - } static void Decreas_freqPeak_fx( - const Word16 *lsf_new, /* i : ISFs at the end of the frame */ - Word16 *exc_diffQ, /* i/o: frequency coefficients of per band */ - Word16 rat /* i : threshold of ratio between consecutive lsf_new_diff */ + const Word16 *lsf_new, /* i : ISFs at the end of the frame */ + Word16 *exc_diffQ, /* i/o: frequency coefficients of per band */ + Word16 rat /* i : threshold of ratio between consecutive lsf_new_diff */ ) { Word16 i, j, k; Word16 last_bin = 0; Word16 pos = 0; - Word16 *src, max_val,avrg; - Word32 L_avrg,L_tmp; + Word16 *src, max_val, avrg; + Word32 L_avrg, L_tmp; Word16 lsf_new_diff[M]; - Word16 tmp,tmp1,exp; + Word16 tmp, tmp1, exp; Word16 tmp2; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - move16(); /*ptr init*/ - lsf_new_diff[0] = 0; /* prevent unitialized value */ - FOR(j=1; j<(M-1); j++) + move16(); /*ptr init*/ + lsf_new_diff[0] = 0; /* prevent unitialized value */ + FOR( j = 1; j < ( M - 1 ); j++ ) { - lsf_new_diff[j] =sub( lsf_new[j] , lsf_new[j-1]);/*Qx2.56 */ + lsf_new_diff[j] = sub( lsf_new[j], lsf_new[j - 1] ); /*Qx2.56 */ } avrg = 0; move16(); - L_avrg = L_deposit_l(0); + L_avrg = L_deposit_l( 0 ); max_val = 1; move16(); - FOR(i=160; iQ_exc + 6 */ - avrg = round_fx(L_shl(L_avrg,10));/*Q_exc */ - last_bin = M-1; - move16(); /* When the search is false, should equate the end of the vector, not the beginning */ - FOR(i=0; i<(M-1); i++) + L_avrg = Mult_32_16( L_avrg, 21845 ); /*Q_exc+21 -15 ->Q_exc + 6 */ + avrg = round_fx( L_shl( L_avrg, 10 ) ); /*Q_exc */ + last_bin = M - 1; + move16(); /* When the search is false, should equate the end of the vector, not the beginning */ + FOR( i = 0; i < ( M - 1 ); i++ ) { - if(GT_16(lsf_new[i],10240)) + if ( GT_16( lsf_new[i], 10240 ) ) { last_bin = i; move16(); @@ -453,44 +449,43 @@ static void Decreas_freqPeak_fx( } } - FOR(i=last_bin; i<14; i++) + FOR( i = last_bin; i < 14; i++ ) { - tmp = mult_r(rat,lsf_new_diff[i-1] );/*Qx2.56 */ - IF(GT_16(tmp , lsf_new_diff[i])) + tmp = mult_r( rat, lsf_new_diff[i - 1] ); /*Qx2.56 */ + IF( GT_16( tmp, lsf_new_diff[i] ) ) { - src = &exc_diffQ[shl(sub(i,1),4)]; + src = &exc_diffQ[shl( sub( i, 1 ), 4 )]; move16(); - FOR(j=0; j<2; j++) + FOR( j = 0; j < 2; j++ ) { - FOR(k=0; k<16; k++) + FOR( k = 0; k < 16; k++ ) { - tmp = mult_r(16384,abs_s(*src)); - IF(GT_16(tmp,avrg)) + tmp = mult_r( 16384, abs_s( *src ) ); + IF( GT_16( tmp, avrg ) ) { - tmp = abs_s(*src) ; - exp = norm_s(max_val); - tmp1 = div_s(shl(1,sub(14,exp)),max_val);/*Q(29 - exp - Q_exc) */ - L_tmp = L_mult(tmp,tmp1);/*Q(30 - exp) */ + tmp = abs_s( *src ); + exp = norm_s( max_val ); + tmp1 = div_s( shl( 1, sub( 14, exp ) ), max_val ); /*Q(29 - exp - Q_exc) */ + L_tmp = L_mult( tmp, tmp1 ); /*Q(30 - exp) */ #ifdef BASOP_NOGLOB - tmp = round_fx_o(L_shl_o(L_tmp,exp, &Overflow), &Overflow);/*Q14 */ + tmp = round_fx_o( L_shl_o( L_tmp, exp, &Overflow ), &Overflow ); /*Q14 */ #else - tmp = round_fx(L_shl(L_tmp,exp));/*Q14 */ + tmp = round_fx( L_shl( L_tmp, exp ) ); /*Q14 */ #endif - tmp = sub(32767,tmp);/*Q14 */ - L_tmp = L_mult(avrg,tmp);/*Q_exc +15 */ + tmp = sub( 32767, tmp ); /*Q14 */ + L_tmp = L_mult( avrg, tmp ); /*Q_exc +15 */ - tmp = round_fx(L_shl(L_tmp,1)); - tmp1 = negate(tmp); + tmp = round_fx( L_shl( L_tmp, 1 ) ); + tmp1 = negate( tmp ); tmp2 = *src; - *(src) = tmp1; + *( src ) = tmp1; move16(); - if( tmp2 > 0 ) + if ( tmp2 > 0 ) { - *(src) = tmp; + *( src ) = tmp; move16(); } - } src++; } @@ -498,13 +493,13 @@ static void Decreas_freqPeak_fx( } } - tmp = mult_r(8192,max_val);/*Q_exc */ + tmp = mult_r( 8192, max_val ); /*Q_exc */ test(); - IF(EQ_16(abs_s(exc_diffQ[pos]),max_val)&>_16(tmp,avrg)) + IF( EQ_16( abs_s( exc_diffQ[pos] ), max_val ) && GT_16( tmp, avrg ) ) { - FOR(i=pos-1; iQ(2*Q_exc-7) */ + tmp = sub( end_band, start_band ); + tmp = div_s( 1, tmp ); /*Q15 */ + Ener_fx = Mult_32_16( Ener_fx, tmp ); /*Q(2*Q_exc-7+15)->Q(2*Q_exc-7) */ - exp1 = norm_l(Ener_fx); - Ener_fx = L_shl(Ener_fx, exp1); - exp1 = 31-exp1-sub(shl(Q_exc,1),7); + exp1 = norm_l( Ener_fx ); + Ener_fx = L_shl( Ener_fx, exp1 ); + exp1 = 31 - exp1 - sub( shl( Q_exc, 1 ), 7 ); move16(); - Ener_fx = Isqrt_lc(Ener_fx, &exp1); /*Q(31-exp1) */ + Ener_fx = Isqrt_lc( Ener_fx, &exp1 ); /*Q(31-exp1) */ - weight_fx = 16384; /*Q15 */ + weight_fx = 16384; /*Q15 */ src_fx = &exc_diffQ_fx[start_band]; /*Q_exc */ - FOR(i=last_bin; i Q16 */ + L_tmp = L_shr( L_mult0( Ener_per_bd_iQ_fx[i + 1], 27213 ), 9 ); /* 3.321928 in Q13 -> Q16 */ - frac = L_Extract_lc(L_tmp, &exp); /* Extract exponent of L_tmp */ - tmp = extract_l(Pow2(14, frac));/* Put 14 as exponent so that */ + frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent of L_tmp */ + tmp = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ - exp = sub(exp, 14); + exp = sub( exp, 14 ); #ifdef BASOP_NOGLOB - Ener1_fx = mult_ro(13107, shl_o(tmp, exp, &Overflow), &Overflow); /*Q0 */ -#else /* BASOP_NOGLOB */ - Ener1_fx = mult_r(13107, shl(tmp, exp)); /*Q0 */ -#endif /* BASOP_NOGLOB */ + Ener1_fx = mult_ro( 13107, shl_o( tmp, exp, &Overflow ), &Overflow ); /*Q0 */ +#else /* BASOP_NOGLOB */ + Ener1_fx = mult_r( 13107, shl( tmp, exp ) ); /*Q0 */ +#endif /* BASOP_NOGLOB */ - FOR(j=0; j<16; j++) + FOR( j = 0; j < 16; j++ ) { /**src = Ener1*(weight*(*src)*Ener + (1.0f-weight)*own_random(seed_tcx)/32768.0f); */ - L_tmp = Mult_32_16(Ener_fx, *src_fx); /*Q(31-exp+Q_exc-15) -> Q(16-exp+Q_exc) */ - tmp = extract_l(L_shr(L_tmp, add(4, sub(Q_exc, exp1)))); /*Q12 */ - tmp = mult_r(weight_fx, tmp); /*Q12 */ + L_tmp = Mult_32_16( Ener_fx, *src_fx ); /*Q(31-exp+Q_exc-15) -> Q(16-exp+Q_exc) */ + tmp = extract_l( L_shr( L_tmp, add( 4, sub( Q_exc, exp1 ) ) ) ); /*Q12 */ + tmp = mult_r( weight_fx, tmp ); /*Q12 */ - L_tmp = L_mult0(sub(32767, weight_fx), Random(seed_tcx)); /*Q30 */ - tmp1 = round_fx(L_shr(L_tmp, 2)); + L_tmp = L_mult0( sub( 32767, weight_fx ), Random( seed_tcx ) ); /*Q30 */ + tmp1 = round_fx( L_shr( L_tmp, 2 ) ); - L_exc_diffQ_fx[16*i+j] = L_mult0(Ener1_fx, add(tmp, tmp1)); /*Q12 */ move32(); + L_exc_diffQ_fx[16 * i + j] = L_mult0( Ener1_fx, add( tmp, tmp1 ) ); /*Q12 */ + move32(); src_fx++; } } /*Ener1 = (float)(0.4f*pow(10, Ener_per_bd_iQ[15])); */ - L_tmp = L_shr(L_mult0(Ener_per_bd_iQ_fx[15], 27213), 9); /* 3.321928 in Q13 -> Q16 */ + L_tmp = L_shr( L_mult0( Ener_per_bd_iQ_fx[15], 27213 ), 9 ); /* 3.321928 in Q13 -> Q16 */ - frac = L_Extract_lc(L_tmp, &exp); /* Extract exponent of L_tmp */ - tmp = extract_l(Pow2(14, frac));/* Put 14 as exponent so that */ + frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent of L_tmp */ + tmp = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ - exp = sub(exp, 14); + exp = sub( exp, 14 ); #ifdef BASOP_NOGLOB - Ener1_fx = mult_r(13107, shl_o(tmp, exp, &Overflow)); /*Q0 */ -#else /* BASOP_NOGLOB */ - Ener1_fx = mult_r(13107, shl(tmp, exp)); /*Q0 */ -#endif /* BASOP_NOGLOB */ + Ener1_fx = mult_r( 13107, shl_o( tmp, exp, &Overflow ) ); /*Q0 */ +#else /* BASOP_NOGLOB */ + Ener1_fx = mult_r( 13107, shl( tmp, exp ) ); /*Q0 */ +#endif /* BASOP_NOGLOB */ src_fx = &exc_diffQ_fx[224]; - FOR(j=0; j<32; j++) + FOR( j = 0; j < 32; j++ ) { /**src = Ener1*(weight*(*src)*Ener + (1.0f-weight)*own_random(seed_tcx)/32768.0f); */ - L_tmp = Mult_32_16(Ener_fx, *src_fx); /*Q(31-exp+Q_exc-15) -> Q(16-exp+Q_exc) */ - tmp = extract_l(L_shr(L_tmp, add(4, sub(Q_exc, exp1)))); /*Q12 */ - tmp = mult_r(weight_fx, tmp); /*Q12 */ + L_tmp = Mult_32_16( Ener_fx, *src_fx ); /*Q(31-exp+Q_exc-15) -> Q(16-exp+Q_exc) */ + tmp = extract_l( L_shr( L_tmp, add( 4, sub( Q_exc, exp1 ) ) ) ); /*Q12 */ + tmp = mult_r( weight_fx, tmp ); /*Q12 */ - L_tmp = L_mult0(sub(32767, weight_fx), Random(seed_tcx)); /*Q30 */ - tmp1 = round_fx(L_shr(L_tmp, 2)); /*Q12 */ + L_tmp = L_mult0( sub( 32767, weight_fx ), Random( seed_tcx ) ); /*Q30 */ + tmp1 = round_fx( L_shr( L_tmp, 2 ) ); /*Q12 */ - L_exc_diffQ_fx[16*i+j] = L_mult0(Ener1_fx, add(tmp, tmp1)); /*Q12 */ move32(); + L_exc_diffQ_fx[16 * i + j] = L_mult0( Ener1_fx, add( tmp, tmp1 ) ); /*Q12 */ + move32(); src_fx++; } exc_diffQ_max = 0; move16(); - FOR(i=start_band; i Q27 */ - L_tmp = L_shr(L_tmp, 10); /* From Q27 to Q16 */ + L_tmp = L_mult( Ener_per_bd_iQ[j], 27213 ); /* 3.321928 in Q13 -> Q27 */ + L_tmp = L_shr( L_tmp, 10 ); /* From Q27 to Q16 */ - frac = L_Extract_lc(L_tmp, &exp); /* Extract exponent of L_tmp */ - tmp = extract_l(Pow2(14, frac));/* Put 14 as exponent so that */ + frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent of L_tmp */ + tmp = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ - exp = sub(exp, 14); + exp = sub( exp, 14 ); #ifdef BASOP_NOGLOB - tmp1 = shl_o(tmp,exp, &Overflow); -#else /* BASOP_NOGLOB */ - tmp1 = shl(tmp,exp); + tmp1 = shl_o( tmp, exp, &Overflow ); +#else /* BASOP_NOGLOB */ + tmp1 = shl( tmp, exp ); #endif /* BASOP_NOGLOB */ - move16(); + move16(); #ifdef BASOP_NOGLOB - ener = add_o (tmp1,ener, &Overflow);/*Q0 */ -#else /* BASOP_NOGLOB */ - ener = add (tmp1,ener);/*Q0 */ -#endif /* BASOP_NOGLOB */ + ener = add_o( tmp1, ener, &Overflow ); /*Q0 */ +#else /* BASOP_NOGLOB */ + ener = add( tmp1, ener ); /*Q0 */ +#endif /* BASOP_NOGLOB */ } test(); - IF( EQ_32(core_brate,ACELP_8k00)&&NE_16(bwidth,NB)) + IF( EQ_32( core_brate, ACELP_8k00 ) && NE_16( bwidth, NB ) ) { - if(NE_16(last_coder_type,AUDIO)) + if ( NE_16( last_coder_type, AUDIO ) ) { *last_ener = ener; move16(); } test(); test(); - IF((GT_16(last_bin,8)||Diff_len!=0)&&EQ_16(last_coder_type,AUDIO)) + IF( ( GT_16( last_bin, 8 ) || Diff_len != 0 ) && EQ_16( last_coder_type, AUDIO ) ) { MAX_Bin = 10; move16(); @@ -749,12 +745,12 @@ void highband_exc_dct_in_fx( last_bin_tmp = last_bin; move16(); - last_bin = s_max(last_bin , MAX_Bin); - last_bin = add(last_bin, 1); + last_bin = s_max( last_bin, MAX_Bin ); + last_bin = add( last_bin, 1 ); } ELSE { - IF (EQ_16(L_frame, L_FRAME16k)) + IF( EQ_16( L_frame, L_FRAME16k ) ) { last_bin = MBANDS_GN16k; move16(); @@ -768,13 +764,13 @@ void highband_exc_dct_in_fx( move16(); } - IF( bfi || LT_32(core_brate, 6000) || (LT_32(core_brate, 8600) && EQ_16(coder_type, UNVOICED))) + IF( bfi || LT_32( core_brate, 6000 ) || ( LT_32( core_brate, 8600 ) && EQ_16( coder_type, UNVOICED ) ) ) { set16_fx( noisepb, 13107, MBANDS_GN ); /*0.4 in Q15 */ } - ELSE IF (EQ_16(GSC_IVAS_mode, 3) || (GSC_IVAS_mode > 0 && EQ_16(GSC_noisy_speech, 1))) + ELSE IF( EQ_16( GSC_IVAS_mode, 3 ) || ( GSC_IVAS_mode > 0 && EQ_16( GSC_noisy_speech, 1 ) ) ) { - set16_fx(noisepb, 13107/*0.4f*/, MBANDS_GN16k); + set16_fx( noisepb, 13107 /*0.4f*/, MBANDS_GN16k ); } ELSE { @@ -783,33 +779,33 @@ void highband_exc_dct_in_fx( IF( exc_wo_nf != NULL ) { - Copy( exc_diffQ, exc_wo_nf, L_frame); + Copy( exc_diffQ, exc_wo_nf, L_frame ); } test(); - IF(GSC_IVAS_mode == 0 && GSC_noisy_speech && !bfi && LE_16(element_mode, IVAS_SCE)) + IF( GSC_IVAS_mode == 0 && GSC_noisy_speech && !bfi && LE_16( element_mode, IVAS_SCE ) ) { set16_fx( noisepb, 3277, MBANDS_GN ); } - IF (LT_32(core_brate, 6000) && LE_16(coder_type, UNVOICED)) + IF( LT_32( core_brate, 6000 ) && LE_16( coder_type, UNVOICED ) ) { - FOR (i = 0; i < L_frame; i++) + FOR( i = 0; i < L_frame; i++ ) { - IF (exc_diffQ[i] == 0) + IF( exc_diffQ[i] == 0 ) { - //PMT("code below to be validated for IVAS use") - /* exc_diffQ[i] += 2.0f * noisepb[0] * ((float)own_random(seed_tcx) / PCM16_TO_FLT_FAC);*/ - tmp = mult(shl(noisepb[0],1), Random(seed_tcx));/*Q15 */ - tmp = shr(tmp, sub(15, Qexc_diffQ));/*qNoise_fac */ - exc_diffQ[i] = add(exc_diffQ[i], tmp); - move16();/*Q */ + // PMT("code below to be validated for IVAS use") + /* exc_diffQ[i] += 2.0f * noisepb[0] * ((float)own_random(seed_tcx) / PCM16_TO_FLT_FAC);*/ + tmp = mult( shl( noisepb[0], 1 ), Random( seed_tcx ) ); /*Q15 */ + tmp = shr( tmp, sub( 15, Qexc_diffQ ) ); /*qNoise_fac */ + exc_diffQ[i] = add( exc_diffQ[i], tmp ); + move16(); /*Q */ } } } ELSE { - Apply_NoiseFill_fx(exc_diffQ, seed_tcx, noisepb, Diff_len, last_bin, coder_type, mfreq_bindiv, Qexc_diffQ); + Apply_NoiseFill_fx( exc_diffQ, seed_tcx, noisepb, Diff_len, last_bin, coder_type, mfreq_bindiv, Qexc_diffQ ); } /*--------------------------------------------------------------------------------------* * Quantize average gain @@ -817,22 +813,22 @@ void highband_exc_dct_in_fx( * VQ of remaining gain per band *--------------------------------------------------------------------------------------*/ test(); - IF( EQ_32(core_brate,ACELP_8k00)&&NE_16(bwidth,NB)) + IF( EQ_32( core_brate, ACELP_8k00 ) && NE_16( bwidth, NB ) ) { - Ener_per_band_comp_fx(exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, add(last_bin,1), 0); + Ener_per_band_comp_fx( exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, add( last_bin, 1 ), 0 ); } ELSE { - Ener_per_band_comp_fx(exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, MBANDS_GN, 1 ); + Ener_per_band_comp_fx( exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, MBANDS_GN, 1 ); - IF( LT_16(nb_subfr, 4) && LT_16(L_frame, L_FRAME16k)) + IF( LT_16( nb_subfr, 4 ) && LT_16( L_frame, L_FRAME16k ) ) { - FOR(i = L_FRAME-16; i < L_FRAME; i++) + FOR( i = L_FRAME - 16; i < L_FRAME; i++ ) { /*exc_diffQ[i] *= 0.067f * i - 15.0f; = -15 - (-0.067f * i) */ - tmp = msu_r(-7680*65536, -17564, shl(i,6));/*-15 in Q9; -0.067 in Q18 and i in Q6= Q9 */ - L_tmp = L_mult(exc_diffQ[i],tmp); /*Q(Qexc_diffQ+10) */ - exc_diffQ[i] = round_fx(L_shl(L_tmp,16-10));/*Qexc_diffQ */ + tmp = msu_r( -7680 * 65536, -17564, shl( i, 6 ) ); /*-15 in Q9; -0.067 in Q18 and i in Q6= Q9 */ + L_tmp = L_mult( exc_diffQ[i], tmp ); /*Q(Qexc_diffQ+10) */ + exc_diffQ[i] = round_fx( L_shl( L_tmp, 16 - 10 ) ); /*Qexc_diffQ */ } } } @@ -842,37 +838,37 @@ void highband_exc_dct_in_fx( IF( bfi ) { test(); - IF (GSC_noisy_speech == 0 && GT_16(coder_type,UNVOICED)) /* Here coder_type == last_coder_type because of the bfi */ + IF( GSC_noisy_speech == 0 && GT_16( coder_type, UNVOICED ) ) /* Here coder_type == last_coder_type because of the bfi */ { - FOR( i=0; i= 1) + if ( GSC_IVAS_mode >= 1 ) { float scale_factLF = 0.9f; float scale_factHF = 0.9f; - if (GSC_IVAS_mode == 1 && GSC_noisy_speech == 0) + if ( GSC_IVAS_mode == 1 && GSC_noisy_speech == 0 ) { scale_factHF = 0.8f; } - else if (GSC_IVAS_mode == 2 || GSC_noisy_speech == 1) + else if ( GSC_IVAS_mode == 2 || GSC_noisy_speech == 1 ) { scale_factHF = 0.71f; } - else if (GSC_IVAS_mode == 3) + else if ( GSC_IVAS_mode == 3 ) { scale_factHF = 0.9f; } - for (i = 0; i < pit_band_idx * 16; i++) + for ( i = 0; i < pit_band_idx * 16; i++ ) { exc_diffQ[i] *= scale_factLF; } - for (; i < L_frame; i++) + for ( ; i < L_frame; i++ ) { exc_diffQ[i] *= scale_factHF; } } - else if (GSC_noisy_speech) + else if ( GSC_noisy_speech ) { float scale_fact = 0.9f; - if (element_mode == IVAS_CPE_TD) + if ( element_mode == IVAS_CPE_TD ) { - if (coder_type == INACTIVE) + if ( coder_type == INACTIVE ) { scale_fact = 1.0f; } @@ -922,29 +918,29 @@ void highband_exc_dct_in_fx( scale_fact = 0.95f; } } - else if (element_mode > IVAS_SCE) + else if ( element_mode > IVAS_SCE ) { scale_fact = 0.71f; } - for (i = 0; i < L_frame; i++) + for ( i = 0; i < L_frame; i++ ) { exc_diffQ[i] *= scale_fact; } } - if (GSC_noisy_speech && element_mode > IVAS_SCE && core_brate < ACELP_7k20) + if ( GSC_noisy_speech && element_mode > IVAS_SCE && core_brate < ACELP_7k20 ) { - for (i = 80; i < L_frame; i++) + for ( i = 80; i < L_frame; i++ ) { - exc_diffQ[i] *= (+0.0024f * (float)i + 1.192f); + exc_diffQ[i] *= ( +0.0024f * (float) i + 1.192f ); } } #else IF( GSC_noisy_speech ) { - FOR( i= 0; i < L_frame; i++ ) + FOR( i = 0; i < L_frame; i++ ) { - exc_diffQ[i] = mult_r(exc_diffQ[i], 29491); + exc_diffQ[i] = mult_r( exc_diffQ[i], 29491 ); move16(); } } @@ -953,7 +949,7 @@ void highband_exc_dct_in_fx( IF( exc_wo_nf != NULL ) { - Comp_and_apply_gain_fx( exc_wo_nf, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 1 , Qexc_diffQ, Q_exc); + Comp_and_apply_gain_fx( exc_wo_nf, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 1, Qexc_diffQ, Q_exc ); Vr_add( exc_dct_in, exc_wo_nf, exc_wo_nf, L_frame ); } /*--------------------------------------------------------------------------------------* @@ -967,26 +963,26 @@ void highband_exc_dct_in_fx( test(); IF( core_brate == ACELP_8k00 && bwidth != NB ) { - IF( EQ_16(bwe_flag,1)) + IF( EQ_16( bwe_flag, 1 ) ) { - last_bin = sub(last_bin, 1); - tmp = i_mult(MAX_Bin, 16); - tmp1 = i_mult(last_bin, 16); - src = &exc_diffQ[sub(L_FRAME,1)]; + last_bin = sub( last_bin, 1 ); + tmp = i_mult( MAX_Bin, 16 ); + tmp1 = i_mult( last_bin, 16 ); + src = &exc_diffQ[sub( L_FRAME, 1 )]; move16(); - dst = &exc_dct_in[sub(tmp,1)]; + dst = &exc_dct_in[sub( tmp, 1 )]; move16(); - end = &exc_diffQ[sub(tmp1,1)]; + end = &exc_diffQ[sub( tmp1, 1 )]; move16(); - WHILE (src> end) + WHILE( src > end ) { *src-- = *dst--; move16(); } test(); test(); - if( (bitallocation_exc[0] != 0 || bitallocation_exc[1] != 0) && EQ_32(core_brate, ACELP_8k00)) + if ( ( bitallocation_exc[0] != 0 || bitallocation_exc[1] != 0 ) && EQ_32( core_brate, ACELP_8k00 ) ) { exc_diffQ[160] = 0; move16(); @@ -994,79 +990,83 @@ void highband_exc_dct_in_fx( Q_hb_exc = 0; move16(); - envelop_modify_fx( exc_diffQ, seed_tcx, last_bin, Ener_per_bd_iQ, Q_exc, &Q_hb_exc); - Copy_Scale_sig( &exc_diffQ[tmp1], &exc_dct_in[tmp1], sub(L_FRAME,tmp1), sub(Q_exc, Q_hb_exc)); /* from Q_hb_exc -> Q_exc as expected */ + envelop_modify_fx( exc_diffQ, seed_tcx, last_bin, Ener_per_bd_iQ, Q_exc, &Q_hb_exc ); + Copy_Scale_sig( &exc_diffQ[tmp1], &exc_dct_in[tmp1], sub( L_FRAME, tmp1 ), sub( Q_exc, Q_hb_exc ) ); /* from Q_hb_exc -> Q_exc as expected */ } - IF( LT_16(nb_subfr,4)) + IF( LT_16( nb_subfr, 4 ) ) { - FOR( i = sub(L_FRAME,16); i < L_FRAME; i++ ) + FOR( i = sub( L_FRAME, 16 ); i < L_FRAME; i++ ) { /*exc_dct_in[i] *= (0.067f*i-15.f); */ - tmp = mult_r(17564,shl(i,6)); /*0.067 in Q18 and i in Q6= Q9 */ - tmp = sub(tmp,7680); /*15 in Q9 = Q9 */ - L_tmp = L_mult(exc_dct_in[i],tmp);/*Q(Q_exc+10) */ + tmp = mult_r( 17564, shl( i, 6 ) ); /*0.067 in Q18 and i in Q6= Q9 */ + tmp = sub( tmp, 7680 ); /*15 in Q9 = Q9 */ + L_tmp = L_mult( exc_dct_in[i], tmp ); /*Q(Q_exc+10) */ #ifdef BASOP_NOGLOB - exc_dct_in[i] = round_fx_o(L_shl_o(L_tmp,6, &Overflow), &Overflow);/*Q_exc */ -#else /* BASOP_NOGLOB */ - exc_dct_in[i] = round_fx(L_shl(L_tmp,6));/*Q_exc */ -#endif /* BASOP_NOGLOB */ + exc_dct_in[i] = round_fx_o( L_shl_o( L_tmp, 6, &Overflow ), &Overflow ); /*Q_exc */ +#else /* BASOP_NOGLOB */ + exc_dct_in[i] = round_fx( L_shl( L_tmp, 6 ) ); /*Q_exc */ +#endif /* BASOP_NOGLOB */ } } - tmp1 = mult_r(ener,16384); - tmp1 = sub(*last_ener,tmp1); - tmp = mult_r(*last_ener,16384); - tmp = sub(ener,tmp); + tmp1 = mult_r( ener, 16384 ); + tmp1 = sub( *last_ener, tmp1 ); + tmp = mult_r( *last_ener, 16384 ); + tmp = sub( ener, tmp ); test(); - IF( tmp>0 && tmp1>0 ) + IF( tmp > 0 && tmp1 > 0 ) { length_bin = 6; move16(); - IF(last_coder_type != AUDIO) + IF( last_coder_type != AUDIO ) { set16_fx( last_bitallocation_band, 0, 6 ); - Copy( &exc_dct_in[(4+length_bin)*16], &last_exc_dct_in[(4+length_bin)*16], length_bin*16 ); + Copy( &exc_dct_in[( 4 + length_bin ) * 16], &last_exc_dct_in[( 4 + length_bin ) * 16], length_bin * 16 ); } - FOR(i=4; i<(4+length_bin); i++) + FOR( i = 4; i < ( 4 + length_bin ); i++ ) { test(); - IF( !(bitallocation_band[i] == 0 && last_bitallocation_band[i-4] == 0)) + IF( !( bitallocation_band[i] == 0 && last_bitallocation_band[i - 4] == 0 ) ) { - k = shl(add(i,length_bin),4); - src = &exc_dct_in[k]; /*(i+length_bin)*16*/ + k = shl( add( i, length_bin ), 4 ); + src = &exc_dct_in[k]; /*(i+length_bin)*16*/ dst = &last_exc_dct_in[k]; - FOR(j=0; j<16; j++) + FOR( j = 0; j < 16; j++ ) { - tmp= mult_r(10923,abs_s(*src)); - tmp1 =mult_r(10923,abs_s(*dst)); + tmp = mult_r( 10923, abs_s( *src ) ); + tmp1 = mult_r( 10923, abs_s( *dst ) ); - IF(GT_16(tmp,abs_s(*dst))) + IF( GT_16( tmp, abs_s( *dst ) ) ) { tmp2 = *src; #ifdef BASOP_NOGLOB - * src = mult_r(16384, sub_o(*src, abs_s(*dst), &Overflow)); /*Q_exc */ move16(); - tmp = mult_r(16384,add_o(tmp2 , abs_s(*dst), &Overflow)); /*Q_exc */ -#else /* BASOP_NOGLOB */ - * src = mult_r(16384, sub(*src, abs_s(*dst))); /*Q_exc */ move16(); - tmp = mult_r(16384,add(tmp2 , abs_s(*dst))); /*Q_exc */ + *src = mult_r( 16384, sub_o( *src, abs_s( *dst ), &Overflow ) ); /*Q_exc */ + move16(); + tmp = mult_r( 16384, add_o( tmp2, abs_s( *dst ), &Overflow ) ); /*Q_exc */ +#else /* BASOP_NOGLOB */ + *src = mult_r( 16384, sub( *src, abs_s( *dst ) ) ); /*Q_exc */ + move16(); + tmp = mult_r( 16384, add( tmp2, abs_s( *dst ) ) ); /*Q_exc */ #endif - if( tmp2 > 0 ) + if ( tmp2 > 0 ) { *src = tmp; move16(); } } - ELSE IF (GT_16(tmp1,abs_s(*src))) + ELSE IF( GT_16( tmp1, abs_s( *src ) ) ) { - tmp = mult_r(*src,22938); - tmp1 = mult_r(9830,abs_s(*dst)); + tmp = mult_r( *src, 22938 ); + tmp1 = mult_r( 9830, abs_s( *dst ) ); tmp2 = *src; - *src = sub(tmp,tmp1); /*Q_exc */ move16(); - if( tmp2 > 0 ) + *src = sub( tmp, tmp1 ); /*Q_exc */ + move16(); + if ( tmp2 > 0 ) { - *src = add(tmp,tmp1); /*Q_exc */ move16(); + *src = add( tmp, tmp1 ); /*Q_exc */ + move16(); } } src++; @@ -1075,7 +1075,7 @@ void highband_exc_dct_in_fx( } } } - IF(EQ_16(bwe_flag,1)) + IF( EQ_16( bwe_flag, 1 ) ) { Decreas_freqPeak_fx( lsf_new, exc_dct_in, 9830 ); } @@ -1085,8 +1085,8 @@ void highband_exc_dct_in_fx( } } - Copy( &exc_dct_in[64], &last_exc_dct_in[64], L_frame-64 ); - Copy(&bitallocation_band[4], last_bitallocation_band, 6); + Copy( &exc_dct_in[64], &last_exc_dct_in[64], L_frame - 64 ); + Copy( &bitallocation_band[4], last_bitallocation_band, 6 ); *last_ener = ener; move16(); @@ -1095,35 +1095,35 @@ void highband_exc_dct_in_fx( #ifdef IVAS_FLOAT_FIXED void highband_exc_dct_in_ivas_fx( - const Word32 core_brate, /* i : core bitrate */ - const Word16 *mfreq_bindiv, /* i : bin per bands tables */ - Word16 last_bin, /* i : last bin of bit allocation */ - Word16 Diff_len, /* i : number of bin before cut-off frequency */ - Word16 noise_lev, /* i : pulses dynamic */ - Word16 pit_band_idx, /* i : bin position of the cut-off frequency */ - Word16 *exc_diffQ, /* i : frequency coefficients of per band */ - Word16 *seed_tcx, /* i : Seed for noise */ - Word16 *Ener_per_bd_iQ, /* i : Quantized energy of targeted vector */ - Word16 nb_subfr, /* i : Number of subframe considered */ - Word16 *exc_dct_in, /* o : dct of residual signal */ - Word16 last_coder_type, /* i : coding type of last frame */ - Word16 *bitallocation_band, /* i : bit allocation flag of each band */ - const Word16 *lsf_new, /* i : LSFs at the end of the frame */ - Word16 *last_exc_dct_in, /* i : dct of residual signal of last frame */ - Word16 *last_ener, /* i : frequency energy of last frame */ - Word16 *last_bitallocation_band, /* i : bit allocation flag of each band of last frame */ - Word16 *bitallocation_exc, /* i : flag of decoded coefficients */ - Word16 bfi, /* i : bad frame indicator */ - const Word16 coder_type, /* i : coder type */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 *mfreq_bindiv, /* i : bin per bands tables */ + Word16 last_bin, /* i : last bin of bit allocation */ + Word16 Diff_len, /* i : number of bin before cut-off frequency */ + Word16 noise_lev, /* i : pulses dynamic */ + Word16 pit_band_idx, /* i : bin position of the cut-off frequency */ + Word16 *exc_diffQ, /* i : frequency coefficients of per band */ + Word16 *seed_tcx, /* i : Seed for noise */ + Word16 *Ener_per_bd_iQ, /* i : Quantized energy of targeted vector */ + Word16 nb_subfr, /* i : Number of subframe considered */ + Word16 *exc_dct_in, /* o : dct of residual signal */ + Word16 last_coder_type, /* i : coding type of last frame */ + Word16 *bitallocation_band, /* i : bit allocation flag of each band */ + const Word16 *lsf_new, /* i : LSFs at the end of the frame */ + Word16 *last_exc_dct_in, /* i : dct of residual signal of last frame */ + Word16 *last_ener, /* i : frequency energy of last frame */ + Word16 *last_bitallocation_band, /* i : bit allocation flag of each band of last frame */ + Word16 *bitallocation_exc, /* i : flag of decoded coefficients */ + Word16 bfi, /* i : bad frame indicator */ + const Word16 coder_type, /* i : coder type */ Word16 bwidth, - Word16 *exc_wo_nf, /* o : temporal excitation (in f domain) without noisefill */ + Word16 *exc_wo_nf, /* o : temporal excitation (in f domain) without noisefill */ Word16 Qexc_diffQ, Word16 Q_exc, - const Word16 GSC_noisy_speech - , Word16 *lt_ener_per_band_fx, /* i/o: Average per band energy */ - const Word16 L_frame, /* i : frame length */ - const Word16 element_mode, /* i : IVAS element mode */ - const Word16 GSC_IVAS_mode /* i : GSC IVAS mode */ + const Word16 GSC_noisy_speech, + Word16 *lt_ener_per_band_fx, /* i/o: Average per band energy */ + const Word16 L_frame, /* i : frame length */ + const Word16 element_mode, /* i : IVAS element mode */ + const Word16 GSC_IVAS_mode /* i : GSC IVAS mode */ ) { Word16 i, j, k; @@ -1141,43 +1141,43 @@ void highband_exc_dct_in_ivas_fx( Flag Overflow = 0; #endif - FOR(j = 10; j < MBANDS_GN; j++) + FOR( j = 10; j < MBANDS_GN; j++ ) { /* ener += (float)pow(10, Ener_per_bd_iQ[j]); ener += (float)pow(2, 3.321928*Ener_per_bd_iQ[j]); */ - L_tmp = L_mult(Ener_per_bd_iQ[j], 27213); /* 3.321928 in Q13 -> Q27 */ - L_tmp = L_shr(L_tmp, 10); /* From Q27 to Q16 */ + L_tmp = L_mult( Ener_per_bd_iQ[j], 27213 ); /* 3.321928 in Q13 -> Q27 */ + L_tmp = L_shr( L_tmp, 10 ); /* From Q27 to Q16 */ - frac = L_Extract_lc(L_tmp, &exp); /* Extract exponent of L_tmp */ - tmp = extract_l(Pow2(14, frac));/* Put 14 as exponent so that */ + frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent of L_tmp */ + tmp = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ - exp = sub(exp, 14); + exp = sub( exp, 14 ); #ifdef BASOP_NOGLOB - tmp1 = shl_o(tmp, exp, &Overflow); -#else /* BASOP_NOGLOB */ - tmp1 = shl(tmp, exp); + tmp1 = shl_o( tmp, exp, &Overflow ); +#else /* BASOP_NOGLOB */ + tmp1 = shl( tmp, exp ); #endif /* BASOP_NOGLOB */ move16(); #ifdef BASOP_NOGLOB - ener = add_o(tmp1, ener, &Overflow);/*Q0 */ -#else /* BASOP_NOGLOB */ - ener = add(tmp1, ener);/*Q0 */ -#endif /* BASOP_NOGLOB */ + ener = add_o( tmp1, ener, &Overflow ); /*Q0 */ +#else /* BASOP_NOGLOB */ + ener = add( tmp1, ener ); /*Q0 */ +#endif /* BASOP_NOGLOB */ } test(); - IF(EQ_32(core_brate, ACELP_8k00) && NE_16(bwidth, NB)) + IF( EQ_32( core_brate, ACELP_8k00 ) && NE_16( bwidth, NB ) ) { - IF(NE_16(last_coder_type, AUDIO)) + IF( NE_16( last_coder_type, AUDIO ) ) { *last_ener = ener; move16(); } test(); test(); - IF((GT_16(last_bin, 8) || Diff_len != 0) && EQ_16(last_coder_type, AUDIO)) + IF( ( GT_16( last_bin, 8 ) || Diff_len != 0 ) && EQ_16( last_coder_type, AUDIO ) ) { MAX_Bin = 10; move16(); @@ -1192,12 +1192,12 @@ void highband_exc_dct_in_ivas_fx( last_bin_tmp = last_bin; move16(); - last_bin = s_max(last_bin, MAX_Bin); - last_bin = add(last_bin, 1); + last_bin = s_max( last_bin, MAX_Bin ); + last_bin = add( last_bin, 1 ); } ELSE { - IF(EQ_16(L_frame, L_FRAME16k)) + IF( EQ_16( L_frame, L_FRAME16k ) ) { last_bin = MBANDS_GN16k; move16(); @@ -1211,111 +1211,111 @@ void highband_exc_dct_in_ivas_fx( move16(); } - IF(bfi || LT_32(core_brate, 6000) || (LT_32(core_brate, 8600) && EQ_16(coder_type, UNVOICED))) + IF( bfi || LT_32( core_brate, 6000 ) || ( LT_32( core_brate, 8600 ) && EQ_16( coder_type, UNVOICED ) ) ) { - set16_fx(noisepb, 13107, MBANDS_GN); /*0.4 in Q15 */ + set16_fx( noisepb, 13107, MBANDS_GN ); /*0.4 in Q15 */ } - ELSE IF(EQ_16(GSC_IVAS_mode, 3) || (GSC_IVAS_mode > 0 && EQ_16(GSC_noisy_speech, 1))) + ELSE IF( EQ_16( GSC_IVAS_mode, 3 ) || ( GSC_IVAS_mode > 0 && EQ_16( GSC_noisy_speech, 1 ) ) ) { - set16_fx(noisepb, 13107/*0.4f*/, MBANDS_GN16k); + set16_fx( noisepb, 13107 /*0.4f*/, MBANDS_GN16k ); } ELSE { - EstimateNoiseLevel_fx(noisepb, core_brate, Diff_len, last_bin, coder_type, noise_lev, pit_band_idx, last_bin_tmp, bwidth, L_frame); + EstimateNoiseLevel_fx( noisepb, core_brate, Diff_len, last_bin, coder_type, noise_lev, pit_band_idx, last_bin_tmp, bwidth, L_frame ); } - IF(exc_wo_nf != NULL) + IF( exc_wo_nf != NULL ) { - Copy(exc_diffQ, exc_wo_nf, L_frame); + Copy( exc_diffQ, exc_wo_nf, L_frame ); } test(); - IF(GSC_IVAS_mode == 0 && GSC_noisy_speech && !bfi && LE_16(element_mode, IVAS_SCE)) + IF( GSC_IVAS_mode == 0 && GSC_noisy_speech && !bfi && LE_16( element_mode, IVAS_SCE ) ) { - set16_fx(noisepb, 3277, MBANDS_GN); + set16_fx( noisepb, 3277, MBANDS_GN ); } - IF(LT_32(core_brate, 6000) && LE_16(coder_type, UNVOICED)) + IF( LT_32( core_brate, 6000 ) && LE_16( coder_type, UNVOICED ) ) { - FOR(i = 0; i < L_frame; i++) + FOR( i = 0; i < L_frame; i++ ) { - IF(exc_diffQ[i] == 0) + IF( exc_diffQ[i] == 0 ) { - //PMT("code below to be validated for IVAS use") - /* exc_diffQ[i] += 2.0f * noisepb[0] * ((float)own_random(seed_tcx) / PCM16_TO_FLT_FAC);*/ - tmp = mult(shl(noisepb[0], 1), Random(seed_tcx));/*Q15 */ - tmp = shr(tmp, sub(15, Qexc_diffQ));/*qNoise_fac */ - exc_diffQ[i] = add(exc_diffQ[i], tmp); - move16();/*Q */ + // PMT("code below to be validated for IVAS use") + /* exc_diffQ[i] += 2.0f * noisepb[0] * ((float)own_random(seed_tcx) / PCM16_TO_FLT_FAC);*/ + tmp = mult( shl( noisepb[0], 1 ), Random( seed_tcx ) ); /*Q15 */ + tmp = shr( tmp, sub( 15, Qexc_diffQ ) ); /*qNoise_fac */ + exc_diffQ[i] = add( exc_diffQ[i], tmp ); + move16(); /*Q */ } } } ELSE { - Apply_NoiseFill_fx(exc_diffQ, seed_tcx, noisepb, Diff_len, last_bin, coder_type, mfreq_bindiv, Qexc_diffQ); + Apply_NoiseFill_fx( exc_diffQ, seed_tcx, noisepb, Diff_len, last_bin, coder_type, mfreq_bindiv, Qexc_diffQ ); } - /*--------------------------------------------------------------------------------------* - * Quantize average gain - * Subtract Q averaged gain - * VQ of remaining gain per band - *--------------------------------------------------------------------------------------*/ + /*--------------------------------------------------------------------------------------* + * Quantize average gain + * Subtract Q averaged gain + * VQ of remaining gain per band + *--------------------------------------------------------------------------------------*/ test(); - IF(EQ_32(core_brate, ACELP_8k00) && NE_16(bwidth, NB)) + IF( EQ_32( core_brate, ACELP_8k00 ) && NE_16( bwidth, NB ) ) { - Ener_per_band_comp_ivas_fx(exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, add(last_bin, 1), 0, L_frame); + Ener_per_band_comp_ivas_fx( exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, add( last_bin, 1 ), 0, L_frame ); } ELSE { - Ener_per_band_comp_ivas_fx(exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, MBANDS_GN, 1, L_frame); + Ener_per_band_comp_ivas_fx( exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, MBANDS_GN, 1, L_frame ); - IF(LT_16(nb_subfr, 4) && LT_16(L_frame, L_FRAME16k)) + IF( LT_16( nb_subfr, 4 ) && LT_16( L_frame, L_FRAME16k ) ) { - FOR(i = L_FRAME - 16; i < L_FRAME; i++) + FOR( i = L_FRAME - 16; i < L_FRAME; i++ ) { /*exc_diffQ[i] *= 0.067f * i - 15.0f; = -15 - (-0.067f * i) */ - tmp = msu_r(-7680 * 65536, -17564, shl(i,6));/*-15 in Q9; -0.067 in Q18 and i in Q6= Q9 */ - L_tmp = L_mult(exc_diffQ[i],tmp); /*Q(Qexc_diffQ+10) */ - exc_diffQ[i] = round_fx(L_shl(L_tmp,16 - 10));/*Qexc_diffQ */ + tmp = msu_r( -7680 * 65536, -17564, shl( i, 6 ) ); /*-15 in Q9; -0.067 in Q18 and i in Q6= Q9 */ + L_tmp = L_mult( exc_diffQ[i], tmp ); /*Q(Qexc_diffQ+10) */ + exc_diffQ[i] = round_fx( L_shl( L_tmp, 16 - 10 ) ); /*Qexc_diffQ */ } } } - /*--------------------------------------------------------------------------------------* - * Check potential energy excitation overshoot - *--------------------------------------------------------------------------------------*/ - IF(bfi) + /*--------------------------------------------------------------------------------------* + * Check potential energy excitation overshoot + *--------------------------------------------------------------------------------------*/ + IF( bfi ) { test(); - IF(GSC_noisy_speech == 0 && GT_16(coder_type, UNVOICED)) /* Here coder_type == last_coder_type because of the bfi */ + IF( GSC_noisy_speech == 0 && GT_16( coder_type, UNVOICED ) ) /* Here coder_type == last_coder_type because of the bfi */ { - FOR(i = 0; i < last_bin; i++) + FOR( i = 0; i < last_bin; i++ ) { - Ener_per_bd_iQ[i] = s_min(Ener_per_bd_iQ[i], sub(sub(lt_ener_per_band_fx[i], 154), Ener_per_bd_yQ[i])); + Ener_per_bd_iQ[i] = s_min( Ener_per_bd_iQ[i], sub( sub( lt_ener_per_band_fx[i], 154 ), Ener_per_bd_yQ[i] ) ); move16(); - lt_ener_per_band_fx[i] = sub(lt_ener_per_band_fx[i], 77); + lt_ener_per_band_fx[i] = sub( lt_ener_per_band_fx[i], 77 ); move16(); } - FOR(; i < MBANDS_GN; i++) + FOR( ; i < MBANDS_GN; i++ ) { - Ener_per_bd_iQ[i] = s_min(Ener_per_bd_iQ[i], sub(lt_ener_per_band_fx[i], 154)); + Ener_per_bd_iQ[i] = s_min( Ener_per_bd_iQ[i], sub( lt_ener_per_band_fx[i], 154 ) ); move16(); - lt_ener_per_band_fx[i] = sub(lt_ener_per_band_fx[i], 77); + lt_ener_per_band_fx[i] = sub( lt_ener_per_band_fx[i], 77 ); move16(); } } ELSE { - FOR(i = 0; i < last_bin; i++) + FOR( i = 0; i < last_bin; i++ ) { - Ener_per_bd_iQ[i] = s_min(Ener_per_bd_iQ[i], sub(add(lt_ener_per_band_fx[i],1229), Ener_per_bd_yQ[i])); + Ener_per_bd_iQ[i] = s_min( Ener_per_bd_iQ[i], sub( add( lt_ener_per_band_fx[i], 1229 ), Ener_per_bd_yQ[i] ) ); move16(); - lt_ener_per_band_fx[i] = sub(lt_ener_per_band_fx[i], 77); + lt_ener_per_band_fx[i] = sub( lt_ener_per_band_fx[i], 77 ); move16(); } - FOR(; i < MBANDS_GN; i++) + FOR( ; i < MBANDS_GN; i++ ) { - Ener_per_bd_iQ[i] = s_min(Ener_per_bd_iQ[i], add(lt_ener_per_band_fx[i],1229)); + Ener_per_bd_iQ[i] = s_min( Ener_per_bd_iQ[i], add( lt_ener_per_band_fx[i], 1229 ) ); move16(); - lt_ener_per_band_fx[i] = sub(lt_ener_per_band_fx[i], 77); + lt_ener_per_band_fx[i] = sub( lt_ener_per_band_fx[i], 77 ); move16(); } } @@ -1323,94 +1323,94 @@ void highband_exc_dct_in_ivas_fx( /*--------------------------------------------------------------------------------------* * Apply decoded gain onto the difference signal *--------------------------------------------------------------------------------------*/ -#if 1//def ADD_LRTD - IF(GSC_IVAS_mode >= 1) +#if 1 // def ADD_LRTD + IF( GSC_IVAS_mode >= 1 ) { - //float scale_factLF = 0.9f; + // float scale_factLF = 0.9f; Word16 scale_factLF = 29491; - //float scale_factHF = 0.9f; + // float scale_factHF = 0.9f; Word16 scale_factHF = 29491; - IF(GSC_IVAS_mode == 1 && GSC_noisy_speech == 0) + IF( GSC_IVAS_mode == 1 && GSC_noisy_speech == 0 ) { - //scale_factHF = 0.8f; + // scale_factHF = 0.8f; scale_factHF = 26214; } - ELSE IF(GSC_IVAS_mode == 2 || GSC_noisy_speech == 1) + ELSE IF( GSC_IVAS_mode == 2 || GSC_noisy_speech == 1 ) { - //scale_factHF = 0.71f; + // scale_factHF = 0.71f; scale_factHF = 23265; } - ELSE IF(GSC_IVAS_mode == 3) + ELSE IF( GSC_IVAS_mode == 3 ) { - //scale_factHF = 0.9f; + // scale_factHF = 0.9f; scale_factHF = 29491; } - FOR(i = 0; i < pit_band_idx * 16; i++) + FOR( i = 0; i < pit_band_idx * 16; i++ ) { - //exc_diffQ[i] *= scale_factLF; - exc_diffQ[i] = mult_r(exc_diffQ[i], scale_factLF); + // exc_diffQ[i] *= scale_factLF; + exc_diffQ[i] = mult_r( exc_diffQ[i], scale_factLF ); } - FOR(; i < L_frame; i++) + FOR( ; i < L_frame; i++ ) { - //exc_diffQ[i] *= scale_factHF; - exc_diffQ[i] = mult_r(exc_diffQ[i], scale_factHF); + // exc_diffQ[i] *= scale_factHF; + exc_diffQ[i] = mult_r( exc_diffQ[i], scale_factHF ); } } - ELSE IF(GSC_noisy_speech) + ELSE IF( GSC_noisy_speech ) { - //float scale_fact = 0.9f; + // float scale_fact = 0.9f; Word16 scale_fact = 29491; - IF(element_mode == IVAS_CPE_TD) + IF( element_mode == IVAS_CPE_TD ) { - IF(coder_type == INACTIVE) + IF( coder_type == INACTIVE ) { - //scale_fact = 1.0f; + // scale_fact = 1.0f; scale_fact = 32767; } ELSE { - //scale_fact = 0.95f; + // scale_fact = 0.95f; scale_fact = 31129; } } - ELSE IF(element_mode > IVAS_SCE) + ELSE IF( element_mode > IVAS_SCE ) { - //scale_fact = 0.71f; + // scale_fact = 0.71f; scale_fact = 23265; } - FOR(i = 0; i < L_frame; i++) + FOR( i = 0; i < L_frame; i++ ) { - //exc_diffQ[i] *= scale_fact; - exc_diffQ[i] = mult_r(exc_diffQ[i], scale_fact); + // exc_diffQ[i] *= scale_fact; + exc_diffQ[i] = mult_r( exc_diffQ[i], scale_fact ); } } - IF(GSC_noisy_speech && element_mode > IVAS_SCE && core_brate < ACELP_7k20) + IF( GSC_noisy_speech && element_mode > IVAS_SCE && core_brate < ACELP_7k20 ) { - FOR(i = 80; i < L_frame; i++) + FOR( i = 80; i < L_frame; i++ ) { - //exc_diffQ[i] *= (+0.0024f * (float)i + 1.192f); + // exc_diffQ[i] *= (+0.0024f * (float)i + 1.192f); exc_diffQ[i] = mult_r( shl( exc_diffQ[i], 1 ) /*Q16*/, (Word16) L_shr( L_add( 629 * i, 312475 ) /*Q18*/, Q4 ) /*Q14*/ ); } } #else - IF(GSC_noisy_speech) + IF( GSC_noisy_speech ) { - FOR(i = 0; i < L_frame; i++) + FOR( i = 0; i < L_frame; i++ ) { - exc_diffQ[i] = mult_r(exc_diffQ[i], 29491); + exc_diffQ[i] = mult_r( exc_diffQ[i], 29491 ); move16(); } } #endif - Comp_and_apply_gain_fx(exc_diffQ, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 0, Qexc_diffQ, Q_exc); + Comp_and_apply_gain_fx( exc_diffQ, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 0, Qexc_diffQ, Q_exc ); - IF(exc_wo_nf != NULL) + IF( exc_wo_nf != NULL ) { - Comp_and_apply_gain_fx(exc_wo_nf, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 1, Qexc_diffQ, Q_exc); - Vr_add(exc_dct_in, exc_wo_nf, exc_wo_nf, L_frame); + Comp_and_apply_gain_fx( exc_wo_nf, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 1, Qexc_diffQ, Q_exc ); + Vr_add( exc_dct_in, exc_wo_nf, exc_wo_nf, L_frame ); } /*--------------------------------------------------------------------------------------* * add the correction layer to the LF bins, @@ -1419,30 +1419,30 @@ void highband_exc_dct_in_ivas_fx( * DC is Zeroed *--------------------------------------------------------------------------------------*/ - Vr_add(exc_dct_in, exc_diffQ, exc_dct_in, L_frame); + Vr_add( exc_dct_in, exc_diffQ, exc_dct_in, L_frame ); test(); - IF(core_brate == ACELP_8k00 && bwidth != NB) + IF( core_brate == ACELP_8k00 && bwidth != NB ) { - IF(EQ_16(bwe_flag, 1)) + IF( EQ_16( bwe_flag, 1 ) ) { - last_bin = sub(last_bin, 1); - tmp = i_mult(MAX_Bin, 16); - tmp1 = i_mult(last_bin, 16); - src = &exc_diffQ[sub(L_FRAME, 1)]; + last_bin = sub( last_bin, 1 ); + tmp = i_mult( MAX_Bin, 16 ); + tmp1 = i_mult( last_bin, 16 ); + src = &exc_diffQ[sub( L_FRAME, 1 )]; move16(); - dst = &exc_dct_in[sub(tmp, 1)]; + dst = &exc_dct_in[sub( tmp, 1 )]; move16(); - end = &exc_diffQ[sub(tmp1, 1)]; + end = &exc_diffQ[sub( tmp1, 1 )]; move16(); - WHILE(src > end) + WHILE( src > end ) { *src-- = *dst--; move16(); } test(); test(); - IF((bitallocation_exc[0] != 0 || bitallocation_exc[1] != 0) && EQ_32(core_brate, ACELP_8k00)) + IF( ( bitallocation_exc[0] != 0 || bitallocation_exc[1] != 0 ) && EQ_32( core_brate, ACELP_8k00 ) ) { exc_diffQ[160] = 0; move16(); @@ -1450,79 +1450,83 @@ void highband_exc_dct_in_ivas_fx( Q_hb_exc = 0; move16(); - envelop_modify_fx(exc_diffQ, seed_tcx, last_bin, Ener_per_bd_iQ, Q_exc, &Q_hb_exc); - Copy_Scale_sig(&exc_diffQ[tmp1], &exc_dct_in[tmp1], sub(L_FRAME, tmp1), sub(Q_exc, Q_hb_exc)); /* from Q_hb_exc -> Q_exc as expected */ + envelop_modify_fx( exc_diffQ, seed_tcx, last_bin, Ener_per_bd_iQ, Q_exc, &Q_hb_exc ); + Copy_Scale_sig( &exc_diffQ[tmp1], &exc_dct_in[tmp1], sub( L_FRAME, tmp1 ), sub( Q_exc, Q_hb_exc ) ); /* from Q_hb_exc -> Q_exc as expected */ } - IF(LT_16(nb_subfr, 4)) + IF( LT_16( nb_subfr, 4 ) ) { - FOR(i = sub(L_FRAME, 16); i < L_FRAME; i++) + FOR( i = sub( L_FRAME, 16 ); i < L_FRAME; i++ ) { /*exc_dct_in[i] *= (0.067f*i-15.f); */ - tmp = mult_r(17564, shl(i, 6)); /*0.067 in Q18 and i in Q6= Q9 */ - tmp = sub(tmp, 7680); /*15 in Q9 = Q9 */ - L_tmp = L_mult(exc_dct_in[i], tmp);/*Q(Q_exc+10) */ + tmp = mult_r( 17564, shl( i, 6 ) ); /*0.067 in Q18 and i in Q6= Q9 */ + tmp = sub( tmp, 7680 ); /*15 in Q9 = Q9 */ + L_tmp = L_mult( exc_dct_in[i], tmp ); /*Q(Q_exc+10) */ #ifdef BASOP_NOGLOB - exc_dct_in[i] = round_fx_o(L_shl_o(L_tmp, 6, &Overflow), &Overflow);/*Q_exc */ -#else /* BASOP_NOGLOB */ - exc_dct_in[i] = round_fx(L_shl(L_tmp, 6));/*Q_exc */ -#endif /* BASOP_NOGLOB */ + exc_dct_in[i] = round_fx_o( L_shl_o( L_tmp, 6, &Overflow ), &Overflow ); /*Q_exc */ +#else /* BASOP_NOGLOB */ + exc_dct_in[i] = round_fx( L_shl( L_tmp, 6 ) ); /*Q_exc */ +#endif /* BASOP_NOGLOB */ } } - tmp1 = mult_r(ener, 16384); - tmp1 = sub(*last_ener, tmp1); - tmp = mult_r(*last_ener, 16384); - tmp = sub(ener, tmp); + tmp1 = mult_r( ener, 16384 ); + tmp1 = sub( *last_ener, tmp1 ); + tmp = mult_r( *last_ener, 16384 ); + tmp = sub( ener, tmp ); test(); - IF(tmp > 0 && tmp1 > 0) + IF( tmp > 0 && tmp1 > 0 ) { length_bin = 6; move16(); - IF(last_coder_type != AUDIO) + IF( last_coder_type != AUDIO ) { - set16_fx(last_bitallocation_band, 0, 6); - Copy(&exc_dct_in[(4 + length_bin) * 16], &last_exc_dct_in[(4 + length_bin) * 16], length_bin * 16); + set16_fx( last_bitallocation_band, 0, 6 ); + Copy( &exc_dct_in[( 4 + length_bin ) * 16], &last_exc_dct_in[( 4 + length_bin ) * 16], length_bin * 16 ); } - FOR(i = 4; i < (4 + length_bin); i++) + FOR( i = 4; i < ( 4 + length_bin ); i++ ) { test(); - IF(!(bitallocation_band[i] == 0 && last_bitallocation_band[i - 4] == 0)) + IF( !( bitallocation_band[i] == 0 && last_bitallocation_band[i - 4] == 0 ) ) { - k = shl(add(i, length_bin), 4); - src = &exc_dct_in[k]; /*(i+length_bin)*16*/ + k = shl( add( i, length_bin ), 4 ); + src = &exc_dct_in[k]; /*(i+length_bin)*16*/ dst = &last_exc_dct_in[k]; - FOR(j = 0; j < 16; j++) + FOR( j = 0; j < 16; j++ ) { - tmp = mult_r(10923, abs_s(*src)); - tmp1 = mult_r(10923, abs_s(*dst)); + tmp = mult_r( 10923, abs_s( *src ) ); + tmp1 = mult_r( 10923, abs_s( *dst ) ); - IF(GT_16(tmp, abs_s(*dst))) + IF( GT_16( tmp, abs_s( *dst ) ) ) { tmp2 = *src; #ifdef BASOP_NOGLOB - * src = mult_r(16384, sub_o(*src, abs_s(*dst), &Overflow)); /*Q_exc */ move16(); - tmp = mult_r(16384, add_o(tmp2, abs_s(*dst), &Overflow)); /*Q_exc */ -#else /* BASOP_NOGLOB */ - * src = mult_r(16384, sub(*src, abs_s(*dst))); /*Q_exc */ move16(); - tmp = mult_r(16384, add(tmp2, abs_s(*dst))); /*Q_exc */ + *src = mult_r( 16384, sub_o( *src, abs_s( *dst ), &Overflow ) ); /*Q_exc */ + move16(); + tmp = mult_r( 16384, add_o( tmp2, abs_s( *dst ), &Overflow ) ); /*Q_exc */ +#else /* BASOP_NOGLOB */ + *src = mult_r( 16384, sub( *src, abs_s( *dst ) ) ); /*Q_exc */ + move16(); + tmp = mult_r( 16384, add( tmp2, abs_s( *dst ) ) ); /*Q_exc */ #endif - IF(tmp2 > 0) + IF( tmp2 > 0 ) { *src = tmp; move16(); } } - ELSE IF(GT_16(tmp1, abs_s(*src))) + ELSE IF( GT_16( tmp1, abs_s( *src ) ) ) { - tmp = mult_r(*src, 22938); - tmp1 = mult_r(9830, abs_s(*dst)); + tmp = mult_r( *src, 22938 ); + tmp1 = mult_r( 9830, abs_s( *dst ) ); tmp2 = *src; - *src = sub(tmp, tmp1); /*Q_exc */ move16(); - IF(tmp2 > 0) + *src = sub( tmp, tmp1 ); /*Q_exc */ + move16(); + IF( tmp2 > 0 ) { - *src = add(tmp, tmp1); /*Q_exc */ move16(); + *src = add( tmp, tmp1 ); /*Q_exc */ + move16(); } } src++; @@ -1531,21 +1535,21 @@ void highband_exc_dct_in_ivas_fx( } } } - IF(EQ_16(bwe_flag, 1)) + IF( EQ_16( bwe_flag, 1 ) ) { - Decreas_freqPeak_fx(lsf_new, exc_dct_in, 9830); + Decreas_freqPeak_fx( lsf_new, exc_dct_in, 9830 ); } ELSE { - Decreas_freqPeak_fx(lsf_new, exc_dct_in, 16384); + Decreas_freqPeak_fx( lsf_new, exc_dct_in, 16384 ); } } - Copy(&exc_dct_in[64], &last_exc_dct_in[64], L_frame - 64); - Copy(&bitallocation_band[4], last_bitallocation_band, 6); + Copy( &exc_dct_in[64], &last_exc_dct_in[64], L_frame - 64 ); + Copy( &bitallocation_band[4], last_bitallocation_band, 6 ); *last_ener = ener; move16(); return; } -#endif \ No newline at end of file +#endif diff --git a/lib_com/gs_preech.c b/lib_com/gs_preech.c index cab7caacf..36487d90f 100644 --- a/lib_com/gs_preech.c +++ b/lib_com/gs_preech.c @@ -141,120 +141,120 @@ void pre_echo_att( } void pre_echo_att_fx( - Word32 *Last_frame_ener_fx, /* i/o: Energy of the last frame 2*Q_new+1*/ - Word16 *exc_fx, /* i/o: Excitation of the current frame Q_new*/ - const Word16 gsc_attack_flag_fx, /* i : flag signalling attack encoded by AC mode (GSC) */ - const Word16 Q_new, - const Word16 last_coder_type, /* i : Last coding mode */ - const Word16 L_frame /* i : Frame length*/ + Word32 *Last_frame_ener_fx, /* i/o: Energy of the last frame 2*Q_new+1*/ + Word16 *exc_fx, /* i/o: Excitation of the current frame Q_new*/ + const Word16 gsc_attack_flag_fx, /* i : flag signalling attack encoded by AC mode (GSC) */ + const Word16 Q_new, + const Word16 last_coder_type, /* i : Last coding mode */ + const Word16 L_frame /* i : Frame length*/ ) { - Word32 etmp_fx; - Word32 finc_fx[ATT_LENGHT16k] = { 0 }; - Word16 ratio_fx; - Word16 attack_pos_fx, i; - Word32 L_tmp, L_tmp1; - Word16 tmp, n1, n2, exp, frac1, frac2; - Word32 etmp1_fx; - Word16 att_len; - - test(); - IF(GT_16(gsc_attack_flag_fx, 0) && EQ_16(last_coder_type, AUDIO)) /*gsc_attack_flag_fx does not get set for all the test cases */ - { - /*-------------------------------------------------------------------------* - * Find where the onset (attack) occurs by computing the energy per section - * The inverse weighting aims to favor the first maxima in case of - * gradual onset - *-------------------------------------------------------------------------*/ - att_len = ATT_LENGHT; - if (L_frame == L_FRAME16k) - { - att_len = ATT_LENGHT16k; - } - FOR(i = 0; i < att_len; i++) + Word32 etmp_fx; + Word32 finc_fx[ATT_LENGHT16k] = { 0 }; + Word16 ratio_fx; + Word16 attack_pos_fx, i; + Word32 L_tmp, L_tmp1; + Word16 tmp, n1, n2, exp, frac1, frac2; + Word32 etmp1_fx; + Word16 att_len; + + test(); + IF( GT_16( gsc_attack_flag_fx, 0 ) && EQ_16( last_coder_type, AUDIO ) ) /*gsc_attack_flag_fx does not get set for all the test cases */ { - L_tmp = sum2_fx(&exc_fx[shl(i, 2)], ATT_SEG_LEN); /*2*Q_new+1, //ATT_SEG_LEN=(L_FRAME/ATT_LENGHT)=4(=shl(x,2))*/ - tmp = div_s(sub(att_len, i), att_len); /*Q15 */ - L_tmp = Mult_32_16(L_tmp, tmp); /*2*Q_new+1 */ - finc_fx[i] = L_tmp; - move32(); /*2*Q_new+1 */ - } + /*-------------------------------------------------------------------------* + * Find where the onset (attack) occurs by computing the energy per section + * The inverse weighting aims to favor the first maxima in case of + * gradual onset + *-------------------------------------------------------------------------*/ + att_len = ATT_LENGHT; + if ( L_frame == L_FRAME16k ) + { + att_len = ATT_LENGHT16k; + } + FOR( i = 0; i < att_len; i++ ) + { + L_tmp = sum2_fx( &exc_fx[shl( i, 2 )], ATT_SEG_LEN ); /*2*Q_new+1, //ATT_SEG_LEN=(L_FRAME/ATT_LENGHT)=4(=shl(x,2))*/ + tmp = div_s( sub( att_len, i ), att_len ); /*Q15 */ + L_tmp = Mult_32_16( L_tmp, tmp ); /*2*Q_new+1 */ + finc_fx[i] = L_tmp; + move32(); /*2*Q_new+1 */ + } - attack_pos_fx = maximum_32_fx(finc_fx, att_len, &etmp_fx); + attack_pos_fx = maximum_32_fx( finc_fx, att_len, &etmp_fx ); - /* Scaled the maximum energy and allowed 6 dB increase*/ - etmp_fx = L_shr(etmp_fx, add(2 + 1 - 4, shl(Q_new, 1)));/*2*Q_new+1 //INV_ATT_SEG_LEN=1/4(=shr(x,2)) -> Q4 */ - etmp1_fx = etmp_fx; - move32(); + /* Scaled the maximum energy and allowed 6 dB increase*/ + etmp_fx = L_shr( etmp_fx, add( 2 + 1 - 4, shl( Q_new, 1 ) ) ); /*2*Q_new+1 //INV_ATT_SEG_LEN=1/4(=shr(x,2)) -> Q4 */ + etmp1_fx = etmp_fx; + move32(); #ifdef BASOP_NOGLOB - *Last_frame_ener_fx = L_shl_sat( *Last_frame_ener_fx, 2 ); + *Last_frame_ener_fx = L_shl_sat( *Last_frame_ener_fx, 2 ); #else - *Last_frame_ener_fx = L_shl( *Last_frame_ener_fx, 2 ); + *Last_frame_ener_fx = L_shl( *Last_frame_ener_fx, 2 ); #endif - move32(); /*2*Q_new+1 */ + move32(); /*2*Q_new+1 */ - /* If the maximum normalized energy > last frame energy + 6dB */ - test(); - IF(GT_32(etmp_fx, *Last_frame_ener_fx) && attack_pos_fx > 0) - { - /* Find the average energy before the attack */ - L_tmp = sum32_fx(finc_fx, attack_pos_fx); /*Q1 */ - L_tmp1 = L_shr(L_mult(attack_pos_fx, attack_pos_fx), 1); /*Q0 */ - tmp = round_fx(Isqrt(L_tmp1)); /*Q15 */ - L_tmp = L_shr(L_tmp, 2); /*Q1 ; ATT_SEG_LEN=4 */ - etmp_fx = Mult_32_16(L_tmp, tmp); /*Q1 */ - - etmp_fx = L_shr(etmp_fx, add(1 - 4, shl(Q_new, 1))); /* makes etmp i nQ4 as *Last_frame_ener_fx */ - /* Find the correction factor and apply it before the attack */ - /* ratio = (float)sqrt(*Last_frame_ener/etmp);*/ - /* = isqrt(etmp/(*Last_frame_ener)) */ - etmp_fx = L_max(etmp_fx, 1); - *Last_frame_ener_fx = L_max(*Last_frame_ener_fx, 1); - n1 = norm_l(etmp_fx); - n2 = norm_l(*Last_frame_ener_fx); - - n1 = sub(n1, 1); - exp = sub(n1, n2); - - frac1 = round_fx(L_shl(etmp_fx, n1)); + /* If the maximum normalized energy > last frame energy + 6dB */ + test(); + IF( GT_32( etmp_fx, *Last_frame_ener_fx ) && attack_pos_fx > 0 ) + { + /* Find the average energy before the attack */ + L_tmp = sum32_fx( finc_fx, attack_pos_fx ); /*Q1 */ + L_tmp1 = L_shr( L_mult( attack_pos_fx, attack_pos_fx ), 1 ); /*Q0 */ + tmp = round_fx( Isqrt( L_tmp1 ) ); /*Q15 */ + L_tmp = L_shr( L_tmp, 2 ); /*Q1 ; ATT_SEG_LEN=4 */ + etmp_fx = Mult_32_16( L_tmp, tmp ); /*Q1 */ + + etmp_fx = L_shr( etmp_fx, add( 1 - 4, shl( Q_new, 1 ) ) ); /* makes etmp i nQ4 as *Last_frame_ener_fx */ + /* Find the correction factor and apply it before the attack */ + /* ratio = (float)sqrt(*Last_frame_ener/etmp);*/ + /* = isqrt(etmp/(*Last_frame_ener)) */ + etmp_fx = L_max( etmp_fx, 1 ); + *Last_frame_ener_fx = L_max( *Last_frame_ener_fx, 1 ); + n1 = norm_l( etmp_fx ); + n2 = norm_l( *Last_frame_ener_fx ); + + n1 = sub( n1, 1 ); + exp = sub( n1, n2 ); + + frac1 = round_fx( L_shl( etmp_fx, n1 ) ); #ifdef BASOP_NOGLOB - frac2 = round_fx_sat( L_shl_sat( *Last_frame_ener_fx, n2 ) ); + frac2 = round_fx_sat( L_shl_sat( *Last_frame_ener_fx, n2 ) ); #else - frac2 = round_fx( L_shl( *Last_frame_ener_fx, n2 ) ); + frac2 = round_fx( L_shl( *Last_frame_ener_fx, n2 ) ); #endif - L_tmp = L_mult0(128, div_s(frac1, frac2)); /* s = gain_out / gain_in */ - L_tmp = L_shr(L_tmp, exp); /* add exponent */ - - L_tmp = Isqrt(L_tmp); - ratio_fx = round_fx(L_shl(L_tmp, 9)); - - /* Pre-echo atttenuation should never increase the energy */ - ratio_fx = s_min(ratio_fx, 8192); - FOR(i = 0; i < attack_pos_fx*ATT_SEG_LEN; i++) - { - /*exc_fx[i] *= ratio_fx;*/ - exc_fx[i] = round_fx(L_shl(L_mac(-8192, exc_fx[i], ratio_fx), 2)); - } + L_tmp = L_mult0( 128, div_s( frac1, frac2 ) ); /* s = gain_out / gain_in */ + L_tmp = L_shr( L_tmp, exp ); /* add exponent */ + + L_tmp = Isqrt( L_tmp ); + ratio_fx = round_fx( L_shl( L_tmp, 9 ) ); + + /* Pre-echo atttenuation should never increase the energy */ + ratio_fx = s_min( ratio_fx, 8192 ); + FOR( i = 0; i < attack_pos_fx * ATT_SEG_LEN; i++ ) + { + /*exc_fx[i] *= ratio_fx;*/ + exc_fx[i] = round_fx( L_shl( L_mac( -8192, exc_fx[i], ratio_fx ), 2 ) ); + } + } + *Last_frame_ener_fx = etmp1_fx; + move32(); } - *Last_frame_ener_fx = etmp1_fx; - move32(); - } - ELSE - { - /*-------------------------------------------------------* - * In normal cases, just compute the energy of the frame - *-------------------------------------------------------*/ - - etmp_fx = sum2_fx(exc_fx, L_frame); /*2*Q_new+1 */ + ELSE + { + /*-------------------------------------------------------* + * In normal cases, just compute the energy of the frame + *-------------------------------------------------------*/ + + etmp_fx = sum2_fx( exc_fx, L_frame ); /*2*Q_new+1 */ #ifdef ADD_LRTD PMTE() - etmp_fx = L_shr(etmp_fx, add(8 + 1 - 4, shl(Q_new, 1))); /*2*Q_new+1 //INV_L_FRAME = 1/256 -> Q4*/ + etmp_fx = L_shr( etmp_fx, add( 8 + 1 - 4, shl( Q_new, 1 ) ) ); /*2*Q_new+1 //INV_L_FRAME = 1/256 -> Q4*/ #else - etmp_fx = L_shr(etmp_fx,add(8 + 1 - 4, shl(Q_new,1))); /*2*Q_new+1 //INV_L_FRAME = 1/256 -> Q4*/ + etmp_fx = L_shr( etmp_fx, add( 8 + 1 - 4, shl( Q_new, 1 ) ) ); /*2*Q_new+1 //INV_L_FRAME = 1/256 -> Q4*/ #endif *Last_frame_ener_fx = etmp_fx; move32(); /*2*Q_new+1*/ - } + } - return; + return; } diff --git a/lib_com/guided_plc_util.c b/lib_com/guided_plc_util.c index a38b1f96d..af03981fe 100644 --- a/lib_com/guided_plc_util.c +++ b/lib_com/guided_plc_util.c @@ -324,4 +324,4 @@ static void reorder_lsfs_flt( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_com/guided_plc_util_fx.c b/lib_com/guided_plc_util_fx.c index 11d5c7108..87ab48143 100644 --- a/lib_com/guided_plc_util_fx.c +++ b/lib_com/guided_plc_util_fx.c @@ -10,10 +10,10 @@ #include "basop_util.h" #include "rom_basop_util.h" - /*-------------------------------------------------------------------* - * Local function prototypes - *-------------------------------------------------------------------*/ -static void reorder_lsfs(Word16* lsf, const Word16 min_dist, const Word16 n, const Word32 sr_core); +/*-------------------------------------------------------------------* + * Local function prototypes + *-------------------------------------------------------------------*/ +static void reorder_lsfs( Word16 *lsf, const Word16 min_dist, const Word16 n, const Word32 sr_core ); /*-------------------------------------------------------------------* @@ -21,33 +21,32 @@ static void reorder_lsfs(Word16* lsf, const Word16 min_dist, const Word16 n, con * * *-------------------------------------------------------------------*/ -void getLookAheadResSig( - Word16 *speechLookAhead, - Word16 *A_3Q12, - Word16 *res, - const Word16 L_frame, - const Word16 numSubFrame -) +void getLookAheadResSig( + Word16 *speechLookAhead, + Word16 *A_3Q12, + Word16 *res, + const Word16 L_frame, + const Word16 numSubFrame ) { Word16 *p_A; Word16 i_subfr; Word16 subfr_len[2] = { L_SUBFR, L_SUBFR }; - if( GT_16( L_FRAME16k, L_frame )) + if ( GT_16( L_FRAME16k, L_frame ) ) { subfr_len[1] = 48; move16(); /* 0.75 * L_SUBFR(64) */ } p_A = A_3Q12; - FOR(i_subfr=0; i_subfrlsfoldbfi1_14Q1[i] ); L_tmp = L_mac( L_tmp, divide_by_3_Q15, decState->lsfoldbfi0_14Q1[i] ); @@ -87,16 +85,15 @@ void updateLSFForConcealment( * *-------------------------------------------------------------------*/ -void getConcealedLP( - PLC_ENC_EVS_HANDLE memDecState, - Word16 *AqCon, - const Word16 lsfBase[], +void getConcealedLP( + PLC_ENC_EVS_HANDLE memDecState, + Word16 *AqCon, + const Word16 lsfBase[], const Word16 last_good, - const Word16 L_frame -) + const Word16 L_frame ) { Word16 *lsf; - Word16 lsp[(NB_DIV+1)*M]; + Word16 lsp[( NB_DIV + 1 ) * M]; Word32 int_fs; move16(); @@ -104,14 +101,14 @@ void getConcealedLP( dlpc_bfi( L_frame, &lsf[0], memDecState->lsfold_14Q1, last_good, - 1, memDecState->mem_MA_14Q1, memDecState->mem_AR, &(memDecState->stab_fac_Q15), memDecState->lsf_adaptive_mean_14Q1, - 1, NULL, 0, NULL, NULL, lsfBase, 0); + 1, memDecState->mem_MA_14Q1, memDecState->mem_AR, &( memDecState->stab_fac_Q15 ), memDecState->lsf_adaptive_mean_14Q1, + 1, NULL, 0, NULL, NULL, lsfBase, 0 ); Copy( memDecState->lspold_Q15, lsp, M ); int_fs = INT_FS_FX; move32(); - if( EQ_16(L_frame,L_FRAME_16k)) + if ( EQ_16( L_frame, L_FRAME_16k ) ) { int_fs = INT_FS_16k_FX; move32(); @@ -127,19 +124,18 @@ void getConcealedLP( * * *-------------------------------------------------------------------*/ -void getConcealedLSF( - PLC_ENC_EVS_HANDLE memDecState, - const Word16 lsfBase[], +void getConcealedLSF( + PLC_ENC_EVS_HANDLE memDecState, + const Word16 lsfBase[], const Word16 last_good, - const Word16 L_frame -) + const Word16 L_frame ) { Word16 *lsf = memDecState->lsf_con; dlpc_bfi( L_frame, &lsf[0], memDecState->lsfold_14Q1, last_good, - 1, memDecState->mem_MA_14Q1, memDecState->mem_AR, &(memDecState->stab_fac_Q15), memDecState->lsf_adaptive_mean_14Q1, - 1, NULL, 0, NULL, NULL, lsfBase, 0); + 1, memDecState->mem_MA_14Q1, memDecState->mem_AR, &( memDecState->stab_fac_Q15 ), memDecState->lsf_adaptive_mean_14Q1, + 1, NULL, 0, NULL, NULL, lsfBase, 0 ); return; } @@ -150,21 +146,20 @@ void getConcealedLSF( * *-------------------------------------------------------------------*/ -void RecLpcSpecPowDiffuseLc( - Word16 *lspq, - Word16 *lsp_old, - Word16 *lsfq, - Decoder_State *st, - const Word16 reset_q -) +void RecLpcSpecPowDiffuseLc( + Word16 *lspq, + Word16 *lsp_old, + Word16 *lsfq, + Decoder_State *st, + const Word16 reset_q ) { const Word16 *means; Word16 lsf_old[M]; Word16 i; - means = PlcGetLsfBase ( st->lpcQuantization, - st->narrowBand, - st->sr_core ); + means = PlcGetLsfBase( st->lpcQuantization, + st->narrowBand, + st->sr_core ); Copy( st->lsf_old_fx, lsf_old, M ); @@ -174,12 +169,12 @@ void RecLpcSpecPowDiffuseLc( IF( reset_q ) { - FOR ( i=0; imem_MA_fx[i], means[i]); + lsfq[i] = add( st->mem_MA_fx[i], means[i] ); move16(); } - sort_fx( lsfq, 0, sub(M, 1) ); + sort_fx( lsfq, 0, sub( M, 1 ) ); reorder_lsfs( lsfq, LSF_GAP_FX, M, st->sr_core ); lsf2lsp_fx( lsfq, lspq, M, st->sr_core ); @@ -187,7 +182,7 @@ void RecLpcSpecPowDiffuseLc( ELSE { modify_lsf( lsfq, M, st->sr_core, reset_q ); - lsf2lsp_fx(lsfq, lspq, M, st->sr_core); + lsf2lsp_fx( lsfq, lspq, M, st->sr_core ); } return; @@ -201,58 +196,58 @@ void modify_lsf( Word16 *lsf, const Word16 n, const Word32 sr_core, - const Word16 reset_q -) + const Word16 reset_q ) { Word16 i, k, th_x1p28_Q14; Word16 gap, gap_sum; - th_x1p28_Q14 = 4864/*1900.0f*1.28f Q1*/; + th_x1p28_Q14 = 4864 /*1900.0f*1.28f Q1*/; move16(); - if( EQ_32( sr_core, INT_FS_16k)) + if ( EQ_32( sr_core, INT_FS_16k ) ) { - th_x1p28_Q14 = 6080/*2375.0f*1.28f Q1*/; + th_x1p28_Q14 = 6080 /*2375.0f*1.28f Q1*/; move16(); } IF( reset_q == 0 ) { - th_x1p28_Q14 = 2048; /* 800.0f*1.28f Q1*/ move16(); - if( EQ_32( sr_core, INT_FS_16k)) + th_x1p28_Q14 = 2048; /* 800.0f*1.28f Q1*/ + move16(); + if ( EQ_32( sr_core, INT_FS_16k ) ) { - th_x1p28_Q14 = 2560; /*1000.0f*1.28f Q1*/ move16(); + th_x1p28_Q14 = 2560; /*1000.0f*1.28f Q1*/ + move16(); } } - FOR ( i=1; i= 0; i--) /* Reverify the minimum ISF gap in the reverse direction */ + FOR( i = sub( n, 1 ); i >= 0; i-- ) /* Reverify the minimum ISF gap in the reverse direction */ { - IF (LE_16(lsf[i], th2)) + IF( LE_16( lsf[i], th2 ) ) { curr_min_dist = min_dist_fac2; move16(); } ELSE { - if (LE_16(lsf[i], th1)) + if ( LE_16( lsf[i], th1 ) ) { curr_min_dist = min_dist_fac3; move16(); } } - if (GT_16(lsf[i], lsf_max)) + if ( GT_16( lsf[i], lsf_max ) ) { lsf[i] = lsf_max; move16(); } - lsf_max = sub(lsf[i], curr_min_dist); + lsf_max = sub( lsf[i], curr_min_dist ); } } return; } - diff --git a/lib_com/hp50.c b/lib_com/hp50.c index 890b12d4c..0e99e3203 100644 --- a/lib_com/hp50.c +++ b/lib_com/hp50.c @@ -138,7 +138,7 @@ void hp20_flt( #endif -#define HP20_COEFF_SCALE (2) +#define HP20_COEFF_SCALE ( 2 ) /* * hp20 @@ -150,215 +150,216 @@ void hp20_flt( * void */ -static Word32 HP50_Mode2_Mpy_32_16_fix(Word32 a, Word16 b) +static Word32 HP50_Mode2_Mpy_32_16_fix( Word32 a, Word16 b ) { - Word32 result = Mpy_32_16_1(a, b); - /* perform rounding towards lower value for negative results */ - if (result < 0) result = L_add(result, 1); - return result; + Word32 result = Mpy_32_16_1( a, b ); + /* perform rounding towards lower value for negative results */ + if ( result < 0 ) + result = L_add( result, 1 ); + return result; } -static Word32 HP50_Mpy_32_32_fix(Word32 a, Word32 b) +static Word32 HP50_Mpy_32_32_fix( Word32 a, Word32 b ) { - Word32 result = Mpy_32_32(a, b); - /* perform rounding towards lower value for negative results */ - if (result < 0) result = L_add(result, 1); - return result; + Word32 result = Mpy_32_32( a, b ); + /* perform rounding towards lower value for negative results */ + if ( result < 0 ) + result = L_add( result, 1 ); + return result; } static void filter_2nd_order( - Word16 signal[], - const Word16 stride, - const Word16 prescale, - const Word16 lg, - Word32 mem[4], - Word32 a1, - Word32 a2, - Word32 b1, - Word32 b2 -) + Word16 signal[], + const Word16 stride, + const Word16 prescale, + const Word16 lg, + Word32 mem[4], + Word32 a1, + Word32 a2, + Word32 b1, + Word32 b2 ) { - Word16 i; - Word16 x2, x1; - Word32 L_sum, L_y1, L_y2; + Word16 i; + Word16 x2, x1; + Word32 L_sum, L_y1, L_y2; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; + Flag Overflow = 0; #endif - /* - * Saturation: The states of the filter, namely L_y1 and L_y2 shall - * never saturate, because that causes error in the filter feedback. - * The final output written into signal[] might saturate because of - * unavoidable filter overshoot. - */ + /* + * Saturation: The states of the filter, namely L_y1 and L_y2 shall + * never saturate, because that causes error in the filter feedback. + * The final output written into signal[] might saturate because of + * unavoidable filter overshoot. + */ - /* Execute first 2 iterations with 32-bit x anx y memory values */ - BASOP_SATURATE_ERROR_ON_EVS - L_sum = HP50_Mpy_32_32_fix(b2, mem[2]); /* b2*x2 */ - L_sum = L_add(L_sum, HP50_Mpy_32_32_fix(b1, mem[3])); /* b1*x1 */ - x2 = shr(signal[0 * stride], prescale); - L_sum = L_add(L_sum, HP50_Mode2_Mpy_32_16_fix(b2, x2)); /* b2*x0 */ - L_sum = L_add(L_sum, HP50_Mpy_32_32_fix(mem[0], a2)); /* y2*a2 */ - L_sum = L_add(L_sum, HP50_Mpy_32_32_fix(mem[1], a1)); /* y1*a1 */ + /* Execute first 2 iterations with 32-bit x anx y memory values */ + BASOP_SATURATE_ERROR_ON_EVS + L_sum = HP50_Mpy_32_32_fix( b2, mem[2] ); /* b2*x2 */ + L_sum = L_add( L_sum, HP50_Mpy_32_32_fix( b1, mem[3] ) ); /* b1*x1 */ + x2 = shr( signal[0 * stride], prescale ); + L_sum = L_add( L_sum, HP50_Mode2_Mpy_32_16_fix( b2, x2 ) ); /* b2*x0 */ + L_sum = L_add( L_sum, HP50_Mpy_32_32_fix( mem[0], a2 ) ); /* y2*a2 */ + L_sum = L_add( L_sum, HP50_Mpy_32_32_fix( mem[1], a1 ) ); /* y1*a1 */ #ifdef BASOP_NOGLOB - L_y2 = L_shl_o(L_sum, HP20_COEFF_SCALE, &Overflow); + L_y2 = L_shl_o( L_sum, HP20_COEFF_SCALE, &Overflow ); #else - L_y2 = L_shl(L_sum, HP20_COEFF_SCALE); + L_y2 = L_shl( L_sum, HP20_COEFF_SCALE ); #endif - BASOP_SATURATE_ERROR_OFF_EVS + BASOP_SATURATE_ERROR_OFF_EVS BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB - signal[0 * stride] = round_fx_o(L_shl_o(L_y2, prescale, &Overflow), &Overflow); -#else /* BASOP_NOGLOB */ - signal[0 * stride] = round_fx(L_shl(L_y2, prescale)); + signal[0 * stride] = round_fx_o( L_shl_o( L_y2, prescale, &Overflow ), &Overflow ); +#else /* BASOP_NOGLOB */ + signal[0 * stride] = round_fx( L_shl( L_y2, prescale ) ); #endif /* BASOP_NOGLOB */ - BASOP_SATURATE_WARNING_ON_EVS + BASOP_SATURATE_WARNING_ON_EVS BASOP_SATURATE_ERROR_ON_EVS - L_sum = HP50_Mpy_32_32_fix(b2, mem[3]); /* b2*x2 */ - L_sum = L_add(L_sum, HP50_Mode2_Mpy_32_16_fix(b1, x2)); /* b1*x1 */ - x1 = shr(signal[1 * stride], prescale); - L_sum = L_add(L_sum, HP50_Mode2_Mpy_32_16_fix(b2, x1)); /* b2*x0 */ - L_sum = L_add(L_sum, HP50_Mpy_32_32_fix(mem[1], a2)); /* y2*a2 */ - L_sum = L_add(L_sum, HP50_Mpy_32_32_fix(L_y2, a1)); /* y1*a1 */ + L_sum = HP50_Mpy_32_32_fix( b2, mem[3] ); /* b2*x2 */ + L_sum = L_add( L_sum, HP50_Mode2_Mpy_32_16_fix( b1, x2 ) ); /* b1*x1 */ + x1 = shr( signal[1 * stride], prescale ); + L_sum = L_add( L_sum, HP50_Mode2_Mpy_32_16_fix( b2, x1 ) ); /* b2*x0 */ + L_sum = L_add( L_sum, HP50_Mpy_32_32_fix( mem[1], a2 ) ); /* y2*a2 */ + L_sum = L_add( L_sum, HP50_Mpy_32_32_fix( L_y2, a1 ) ); /* y1*a1 */ #ifdef BASOP_NOGLOB - L_y1 = L_shl_o(L_sum, HP20_COEFF_SCALE, &Overflow); + L_y1 = L_shl_o( L_sum, HP20_COEFF_SCALE, &Overflow ); #else - L_y1 = L_shl(L_sum, HP20_COEFF_SCALE); + L_y1 = L_shl( L_sum, HP20_COEFF_SCALE ); #endif - BASOP_SATURATE_ERROR_OFF_EVS + BASOP_SATURATE_ERROR_OFF_EVS BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB - signal[1 * stride] = round_fx_o(L_shl_o(L_y1, prescale, &Overflow), &Overflow); -#else /* BASOP_NOGLOB */ - signal[1 * stride] = round_fx(L_shl(L_y1, prescale)); + signal[1 * stride] = round_fx_o( L_shl_o( L_y1, prescale, &Overflow ), &Overflow ); +#else /* BASOP_NOGLOB */ + signal[1 * stride] = round_fx( L_shl( L_y1, prescale ) ); #endif /* BASOP_NOGLOB */ - BASOP_SATURATE_WARNING_ON_EVS + BASOP_SATURATE_WARNING_ON_EVS /* New we use a trick and toggle x1/x2 and L_y1/L_y2 to save a few cycles unrolling the loop by 2 */ - FOR(i = 2; i < lg; i += 2) - { - /* y[i+0] = b2*x[i-2] + b1*x[i-1] + b2*x[i-0] + a2*y[i-2] + a1*y[i-1]; */ - BASOP_SATURATE_ERROR_ON_EVS - L_sum = HP50_Mode2_Mpy_32_16_fix(b2, x2); - L_sum = L_add(L_sum, HP50_Mode2_Mpy_32_16_fix(b1, x1)); - x2 = shr(signal[i*stride], prescale); - L_sum = L_add(L_sum, HP50_Mode2_Mpy_32_16_fix(b2, x2)); - L_sum = L_add(L_sum, HP50_Mpy_32_32_fix(L_y2, a2)); - L_sum = L_add(L_sum, HP50_Mpy_32_32_fix(L_y1, a1)); + FOR( i = 2; i < lg; i += 2 ) + { + /* y[i+0] = b2*x[i-2] + b1*x[i-1] + b2*x[i-0] + a2*y[i-2] + a1*y[i-1]; */ + BASOP_SATURATE_ERROR_ON_EVS + L_sum = HP50_Mode2_Mpy_32_16_fix( b2, x2 ); + L_sum = L_add( L_sum, HP50_Mode2_Mpy_32_16_fix( b1, x1 ) ); + x2 = shr( signal[i * stride], prescale ); + L_sum = L_add( L_sum, HP50_Mode2_Mpy_32_16_fix( b2, x2 ) ); + L_sum = L_add( L_sum, HP50_Mpy_32_32_fix( L_y2, a2 ) ); + L_sum = L_add( L_sum, HP50_Mpy_32_32_fix( L_y1, a1 ) ); #ifdef BASOP_NOGLOB - L_y2 = L_shl_o(L_sum, HP20_COEFF_SCALE, &Overflow); + L_y2 = L_shl_o( L_sum, HP20_COEFF_SCALE, &Overflow ); #else - L_y2 = L_shl(L_sum, HP20_COEFF_SCALE); + L_y2 = L_shl( L_sum, HP20_COEFF_SCALE ); #endif - BASOP_SATURATE_ERROR_OFF_EVS - BASOP_SATURATE_WARNING_OFF_EVS + BASOP_SATURATE_ERROR_OFF_EVS + BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB - signal[i*stride] = round_fx_o(L_shl_o(L_y2, prescale, &Overflow), &Overflow); -#else /* BASOP_NOGLOB */ - signal[i*stride] = round_fx(L_shl(L_y2, prescale)); + signal[i * stride] = round_fx_o( L_shl_o( L_y2, prescale, &Overflow ), &Overflow ); +#else /* BASOP_NOGLOB */ + signal[i * stride] = round_fx( L_shl( L_y2, prescale ) ); #endif /* BASOP_NOGLOB */ - BASOP_SATURATE_WARNING_ON_EVS - /* y[i+1] = b2*x[i-1] + b1*x[i-0] + b2*x[i+1] + a2*y[i-1] + a1*y[i+0]; */ - BASOP_SATURATE_ERROR_ON_EVS - L_sum = HP50_Mode2_Mpy_32_16_fix(b2, x1); - L_sum = L_add(L_sum, HP50_Mode2_Mpy_32_16_fix(b1, x2)); - x1 = shr(signal[(i + 1)*stride], prescale); - L_sum = L_add(L_sum, HP50_Mode2_Mpy_32_16_fix(b2, x1)); - L_sum = L_add(L_sum, HP50_Mpy_32_32_fix(L_y1, a2)); - L_sum = L_add(L_sum, HP50_Mpy_32_32_fix(L_y2, a1)); + BASOP_SATURATE_WARNING_ON_EVS + /* y[i+1] = b2*x[i-1] + b1*x[i-0] + b2*x[i+1] + a2*y[i-1] + a1*y[i+0]; */ + BASOP_SATURATE_ERROR_ON_EVS + L_sum = HP50_Mode2_Mpy_32_16_fix( b2, x1 ); + L_sum = L_add( L_sum, HP50_Mode2_Mpy_32_16_fix( b1, x2 ) ); + x1 = shr( signal[( i + 1 ) * stride], prescale ); + L_sum = L_add( L_sum, HP50_Mode2_Mpy_32_16_fix( b2, x1 ) ); + L_sum = L_add( L_sum, HP50_Mpy_32_32_fix( L_y1, a2 ) ); + L_sum = L_add( L_sum, HP50_Mpy_32_32_fix( L_y2, a1 ) ); #ifdef BASOP_NOGLOB - L_y1 = L_shl_o(L_sum, HP20_COEFF_SCALE, &Overflow); + L_y1 = L_shl_o( L_sum, HP20_COEFF_SCALE, &Overflow ); #else - L_y1 = L_shl(L_sum, HP20_COEFF_SCALE); + L_y1 = L_shl( L_sum, HP20_COEFF_SCALE ); #endif - BASOP_SATURATE_ERROR_OFF_EVS - BASOP_SATURATE_WARNING_OFF_EVS + BASOP_SATURATE_ERROR_OFF_EVS + BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB - signal[(i + 1)*stride] = round_fx_o(L_shl_o(L_y1, prescale, &Overflow), &Overflow); + signal[( i + 1 ) * stride] = round_fx_o( L_shl_o( L_y1, prescale, &Overflow ), &Overflow ); #else /* BASOP_NOGLOB */ - signal[(i + 1)*stride] = round_fx(L_shl(L_y1, prescale)); + signal[( i + 1 ) * stride] = round_fx( L_shl( L_y1, prescale ) ); #endif - BASOP_SATURATE_WARNING_ON_EVS - } - /* update static filter memory from variables */ - mem[0] = L_y2; - move32(); - mem[1] = L_y1; - move32(); - mem[2] = L_deposit_h(x2); - mem[3] = L_deposit_h(x1); + BASOP_SATURATE_WARNING_ON_EVS + } + /* update static filter memory from variables */ + mem[0] = L_y2; + move32(); + mem[1] = L_y1; + move32(); + mem[2] = L_deposit_h( x2 ); + mem[3] = L_deposit_h( x1 ); - return; + return; } -void hp20(Word16 signal[], /* i/o: signal to filter any */ - const Word16 stride, /* i : stride to be applied accessing signal */ - const Word16 lg, /* i : length of signal (integer) Q0 */ - Word32 mem[5], /* i/o: static filter memory with this layout: */ - /* mem[0]: y[-2] (32-bit) */ - /* mem[1]; y[-1] (32-bit) */ - /* mem[2]: x[-2] << 16 */ - /* mem[3]: x[-1] << 16 */ - /* Note: mem[0..3] need to be scaled per frame */ - /* mem[4]: states scale */ - const Word32 sFreq) /* i : input sampling rate Q0 */ +void hp20( Word16 signal[], /* i/o: signal to filter any */ + const Word16 stride, /* i : stride to be applied accessing signal */ + const Word16 lg, /* i : length of signal (integer) Q0 */ + Word32 mem[5], /* i/o: static filter memory with this layout: */ + /* mem[0]: y[-2] (32-bit) */ + /* mem[1]; y[-1] (32-bit) */ + /* mem[2]: x[-2] << 16 */ + /* mem[3]: x[-1] << 16 */ + /* Note: mem[0..3] need to be scaled per frame */ + /* mem[4]: states scale */ + const Word32 sFreq ) /* i : input sampling rate Q0 */ { - Word32 a1, b1, a2, b2; - Word16 prescale, prescaleOld, diff; + Word32 a1, b1, a2, b2; + Word16 prescale, prescaleOld, diff; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; + Flag Overflow = 0; #endif - prescale = getScaleFactor16(signal, lg); - prescaleOld = extract_l(mem[4]); + prescale = getScaleFactor16( signal, lg ); + prescaleOld = extract_l( mem[4] ); #ifdef BASOP_NOGLOB - diff = norm_l( L_shl_sat( mem[2], prescaleOld ) ); + diff = norm_l( L_shl_sat( mem[2], prescaleOld ) ); #else - diff = norm_l(L_shl(mem[2], prescaleOld)); + diff = norm_l( L_shl( mem[2], prescaleOld ) ); #endif - if (mem[2] != 0) - { - prescale = s_min(prescale, diff); - } + if ( mem[2] != 0 ) + { + prescale = s_min( prescale, diff ); + } #ifdef BASOP_NOGLOB - diff = norm_l(L_shl_o(mem[3], prescaleOld, &Overflow)); + diff = norm_l( L_shl_o( mem[3], prescaleOld, &Overflow ) ); #else - diff = norm_l(L_shl(mem[3], prescaleOld)); + diff = norm_l( L_shl( mem[3], prescaleOld ) ); #endif - if (mem[3] != 0) - { - prescale = s_min(prescale, diff); - } - /* Take into account the left shift performed into the loop + 1 bit headroom*/ - prescale = s_max(-12, sub(1 + HP20_COEFF_SCALE, prescale)); - IF(prescale != prescaleOld) - { - diff = sub(prescale, prescaleOld); + if ( mem[3] != 0 ) + { + prescale = s_min( prescale, diff ); + } + /* Take into account the left shift performed into the loop + 1 bit headroom*/ + prescale = s_max( -12, sub( 1 + HP20_COEFF_SCALE, prescale ) ); + IF( prescale != prescaleOld ) + { + diff = sub( prescale, prescaleOld ); #ifdef BASOP_NOGLOB - mem[0] = L_shr_o(mem[0], diff, &Overflow); - move32(); - mem[1] = L_shr_o(mem[1], diff, &Overflow); - move32(); - mem[2] = L_shr_o(mem[2], diff, &Overflow); - move32(); - mem[3] = L_shr_o(mem[3], diff, &Overflow); - move32(); + mem[0] = L_shr_o( mem[0], diff, &Overflow ); + move32(); + mem[1] = L_shr_o( mem[1], diff, &Overflow ); + move32(); + mem[2] = L_shr_o( mem[2], diff, &Overflow ); + move32(); + mem[3] = L_shr_o( mem[3], diff, &Overflow ); + move32(); #else - mem[0] = L_shr(mem[0], diff); - move32(); - mem[1] = L_shr(mem[1], diff); - move32(); + mem[0] = L_shr( mem[0], diff ); + move32(); + mem[1] = L_shr( mem[1], diff ); + move32(); mem[2] = L_shr( mem[2], diff ); move32(); mem[3] = L_shr( mem[3], diff ); @@ -439,146 +440,153 @@ void hp20(Word16 signal[], /* i/o: signal to filter any * #ifdef IVAS_FLOAT_FIXED void hp20_fix32( - Word32 signal_fx[], - const Word16 lg, - Word32 mem_fx[], - const Word32 Fs) + Word32 signal_fx[], + const Word16 lg, + Word32 mem_fx[], + const Word32 Fs ) { - Word16 i; - Word32 a1_fx, a2_fx, b1_fx, b2_fx; - Word16 Qx0, Qx1, Qx2, Qy1, Qprev_y1, Qy2, Qprev_y2, Qmin; - Word64 x0_fx64, x1_fx64, x2_fx64, y0_fx64, y1_fx64, y2_fx64, R1, R2, R3, R4, R5; - - if (Fs == 8000) - { - /* hp filter 20Hz at 3dB for 8000KHz input sampling rate - [b,a] = butter(2, 20.0/4000.0, 'high'); - b = [0.988954248067140 -1.977908496134280 0.988954248067140] - a =[1.000000000000000 -1.977786483776764 0.978030508491796]*/ - a1_fx = 1061816033l /* 1.977786483776764 Q29*/; - a2_fx = -525076131l /*-0.978030508491796 Q29*/; - b1_fx = -1061881538l /*-1.977908496134280 Q29*/; - b2_fx = 530940769l /* 0.988954248067140 Q29*/; - } - else if (Fs == 16000) - { - /* hp filter 20Hz at 3dB for 16000KHz sampling rate - [b,a] = butter(2, 20.0/8000.0, 'high'); - b =[ 0.994461788958195 -1.988923577916390 0.994461788958195] - a =[1.000000000000000 -1.988892905899653 0.988954249933127] */ - a1_fx = 1067778748l /* 1.988892905899653 Q29*/; - a2_fx = -530940770l /*-0.988954249933127 Q29*/; - b1_fx = -1067795215l /*-1.988923577916390 Q29*/; - b2_fx = 533897608l /* 0.994461788958195 Q29*/; - } - else if (Fs == 32000) - { - /* hp filter 20Hz at 3dB for 32000KHz sampling rate - [b,a] = butter(2, 20.0/16000.0, 'high'); - b =[0.997227049904470 -1.994454099808940 0.997227049904470] - a =[1.000000000000000 -1.994446410541927 0.994461789075954]*/ - a1_fx = 1070760263l /* 1.994446410541927 Q29*/; - a2_fx = -533897608l /*-0.994461789075954 Q29*/; - b1_fx = -1070764392l /*-1.994454099808940 Q29*/; - b2_fx = 535382196l /* 0.997227049904470 Q29*/; - } - else - { - /* hp filter 20Hz at 3dB for 48000KHz sampling rate - [b,a] = butter(2, 20.0/24000.0, 'high'); - b =[ 0.998150511190452 -1.996301022380904 0.998150511190452] - a =[1.000000000000000 -1.996297601769122 0.996304442992686]*/ - a1_fx = 1071754114l /* 1.996297601769122 Q29*/; - a2_fx = -534886875l /*-0.996304442992686 Q29*/; - b1_fx = -1071755951l /*-1.996301022380904 Q29*/; - b2_fx = 535877975l /* 0.998150511190452 Q29*/; - } - - Qprev_y1 = extract_l(mem_fx[4]); - Qprev_y2 = extract_l(mem_fx[5]); - y1_fx64 = mem_fx[0]; - y2_fx64 = mem_fx[1]; - x0_fx64 = mem_fx[2]; - x1_fx64 = mem_fx[3]; - - for (i = 0; i < lg; i++) - { - x2_fx64 = x1_fx64; - x1_fx64 = x0_fx64; - x0_fx64 = signal_fx[i]; - - Qy1 = W_norm(y1_fx64); - if (y1_fx64 == 0) { - Qy1 = 62; - } - Qy1 = Qy1 - 34; - R1 = W_shl(y1_fx64, Qy1) * a1_fx; - Qy1 += Qprev_y1; - - Qy2 = W_norm(y2_fx64); - if (y2_fx64 == 0) { - Qy2 = 62; - } - Qy2 = Qy2 - 34; - R2 = W_shl(y2_fx64, Qy2) * a2_fx; - Qy2 += Qprev_y2; - - Qx0 = W_norm(x0_fx64); - if (x0_fx64 == 0) { - Qx0 = 62; - } - Qx0 = Qx0 - 34; - R3 = W_shl(x0_fx64, Qx0) * b2_fx; - - Qx1 = W_norm(x1_fx64); - if (x1_fx64 == 0) { - Qx1 = 62; - } - Qx1 = Qx1 - 34; - R4 = W_shl(x1_fx64, Qx1) * b1_fx; - - Qx2 = W_norm(x2_fx64); - if (x2_fx64 == 0) { - Qx2 = 62; - } - Qx2 = Qx2 - 34; - R5 = W_shl(x2_fx64, Qx2) * b2_fx; - - Qmin = min(Qy1, Qy2); - y0_fx64 = (R1 >> (Qy1 - Qmin)) + (R2 >> (Qy2 - Qmin)); - Qmin = min(Qmin, Qx0); - Qmin = min(Qmin, Qx1); - Qmin = min(Qmin, Qx2); - y0_fx64 = (y0_fx64 >> (min(Qy1, Qy2) - Qmin)) + (R3 >> (Qx0 - Qmin)) + (R4 >> (Qx1 - Qmin)) + (R5 >> (Qx2 - Qmin)); - y0_fx64 = y0_fx64 >> 29; - - signal_fx[i] = W_extract_l(W_shr(y0_fx64, Qmin)); - - y2_fx64 = y1_fx64; - y1_fx64 = y0_fx64; - Qprev_y2 = Qprev_y1; - Qprev_y1 = Qmin; - } - - Qy1 = W_norm(y1_fx64); - if (y1_fx64 != 0 && Qy1 < 32) { - y1_fx64 = y1_fx64 >> (32 - Qy1); - Qprev_y1 -= (32 - Qy1); - } - - Qy2 = W_norm(y2_fx64); - if (y2_fx64 != 0 && Qy2 < 32) { - y2_fx64 = y2_fx64 >> (32 - Qy2); - Qprev_y2 -= (32 - Qy2); - } - - mem_fx[0] = W_extract_l(y1_fx64); - mem_fx[1] = W_extract_l(y2_fx64); - mem_fx[2] = W_extract_l(x0_fx64); - mem_fx[3] = W_extract_l(x1_fx64); - mem_fx[4] = Qprev_y1; - mem_fx[5] = Qprev_y2; - - return; + Word16 i; + Word32 a1_fx, a2_fx, b1_fx, b2_fx; + Word16 Qx0, Qx1, Qx2, Qy1, Qprev_y1, Qy2, Qprev_y2, Qmin; + Word64 x0_fx64, x1_fx64, x2_fx64, y0_fx64, y1_fx64, y2_fx64, R1, R2, R3, R4, R5; + + if ( Fs == 8000 ) + { + /* hp filter 20Hz at 3dB for 8000KHz input sampling rate + [b,a] = butter(2, 20.0/4000.0, 'high'); + b = [0.988954248067140 -1.977908496134280 0.988954248067140] + a =[1.000000000000000 -1.977786483776764 0.978030508491796]*/ + a1_fx = 1061816033l /* 1.977786483776764 Q29*/; + a2_fx = -525076131l /*-0.978030508491796 Q29*/; + b1_fx = -1061881538l /*-1.977908496134280 Q29*/; + b2_fx = 530940769l /* 0.988954248067140 Q29*/; + } + else if ( Fs == 16000 ) + { + /* hp filter 20Hz at 3dB for 16000KHz sampling rate + [b,a] = butter(2, 20.0/8000.0, 'high'); + b =[ 0.994461788958195 -1.988923577916390 0.994461788958195] + a =[1.000000000000000 -1.988892905899653 0.988954249933127] */ + a1_fx = 1067778748l /* 1.988892905899653 Q29*/; + a2_fx = -530940770l /*-0.988954249933127 Q29*/; + b1_fx = -1067795215l /*-1.988923577916390 Q29*/; + b2_fx = 533897608l /* 0.994461788958195 Q29*/; + } + else if ( Fs == 32000 ) + { + /* hp filter 20Hz at 3dB for 32000KHz sampling rate + [b,a] = butter(2, 20.0/16000.0, 'high'); + b =[0.997227049904470 -1.994454099808940 0.997227049904470] + a =[1.000000000000000 -1.994446410541927 0.994461789075954]*/ + a1_fx = 1070760263l /* 1.994446410541927 Q29*/; + a2_fx = -533897608l /*-0.994461789075954 Q29*/; + b1_fx = -1070764392l /*-1.994454099808940 Q29*/; + b2_fx = 535382196l /* 0.997227049904470 Q29*/; + } + else + { + /* hp filter 20Hz at 3dB for 48000KHz sampling rate + [b,a] = butter(2, 20.0/24000.0, 'high'); + b =[ 0.998150511190452 -1.996301022380904 0.998150511190452] + a =[1.000000000000000 -1.996297601769122 0.996304442992686]*/ + a1_fx = 1071754114l /* 1.996297601769122 Q29*/; + a2_fx = -534886875l /*-0.996304442992686 Q29*/; + b1_fx = -1071755951l /*-1.996301022380904 Q29*/; + b2_fx = 535877975l /* 0.998150511190452 Q29*/; + } + + Qprev_y1 = extract_l( mem_fx[4] ); + Qprev_y2 = extract_l( mem_fx[5] ); + y1_fx64 = mem_fx[0]; + y2_fx64 = mem_fx[1]; + x0_fx64 = mem_fx[2]; + x1_fx64 = mem_fx[3]; + + for ( i = 0; i < lg; i++ ) + { + x2_fx64 = x1_fx64; + x1_fx64 = x0_fx64; + x0_fx64 = signal_fx[i]; + + Qy1 = W_norm( y1_fx64 ); + if ( y1_fx64 == 0 ) + { + Qy1 = 62; + } + Qy1 = Qy1 - 34; + R1 = W_shl( y1_fx64, Qy1 ) * a1_fx; + Qy1 += Qprev_y1; + + Qy2 = W_norm( y2_fx64 ); + if ( y2_fx64 == 0 ) + { + Qy2 = 62; + } + Qy2 = Qy2 - 34; + R2 = W_shl( y2_fx64, Qy2 ) * a2_fx; + Qy2 += Qprev_y2; + + Qx0 = W_norm( x0_fx64 ); + if ( x0_fx64 == 0 ) + { + Qx0 = 62; + } + Qx0 = Qx0 - 34; + R3 = W_shl( x0_fx64, Qx0 ) * b2_fx; + + Qx1 = W_norm( x1_fx64 ); + if ( x1_fx64 == 0 ) + { + Qx1 = 62; + } + Qx1 = Qx1 - 34; + R4 = W_shl( x1_fx64, Qx1 ) * b1_fx; + + Qx2 = W_norm( x2_fx64 ); + if ( x2_fx64 == 0 ) + { + Qx2 = 62; + } + Qx2 = Qx2 - 34; + R5 = W_shl( x2_fx64, Qx2 ) * b2_fx; + + Qmin = min( Qy1, Qy2 ); + y0_fx64 = ( R1 >> ( Qy1 - Qmin ) ) + ( R2 >> ( Qy2 - Qmin ) ); + Qmin = min( Qmin, Qx0 ); + Qmin = min( Qmin, Qx1 ); + Qmin = min( Qmin, Qx2 ); + y0_fx64 = ( y0_fx64 >> ( min( Qy1, Qy2 ) - Qmin ) ) + ( R3 >> ( Qx0 - Qmin ) ) + ( R4 >> ( Qx1 - Qmin ) ) + ( R5 >> ( Qx2 - Qmin ) ); + y0_fx64 = y0_fx64 >> 29; + + signal_fx[i] = W_extract_l( W_shr( y0_fx64, Qmin ) ); + + y2_fx64 = y1_fx64; + y1_fx64 = y0_fx64; + Qprev_y2 = Qprev_y1; + Qprev_y1 = Qmin; + } + + Qy1 = W_norm( y1_fx64 ); + if ( y1_fx64 != 0 && Qy1 < 32 ) + { + y1_fx64 = y1_fx64 >> ( 32 - Qy1 ); + Qprev_y1 -= ( 32 - Qy1 ); + } + + Qy2 = W_norm( y2_fx64 ); + if ( y2_fx64 != 0 && Qy2 < 32 ) + { + y2_fx64 = y2_fx64 >> ( 32 - Qy2 ); + Qprev_y2 -= ( 32 - Qy2 ); + } + + mem_fx[0] = W_extract_l( y1_fx64 ); + mem_fx[1] = W_extract_l( y2_fx64 ); + mem_fx[2] = W_extract_l( x0_fx64 ); + mem_fx[3] = W_extract_l( x1_fx64 ); + mem_fx[4] = Qprev_y1; + mem_fx[5] = Qprev_y2; + + return; } -#endif \ No newline at end of file +#endif diff --git a/lib_com/hq2_bit_alloc.c b/lib_com/hq2_bit_alloc.c index dbb9404f8..cd7f17aab 100644 --- a/lib_com/hq2_bit_alloc.c +++ b/lib_com/hq2_bit_alloc.c @@ -666,7 +666,7 @@ void hq2_bit_alloc_har( /*allocate bits*/ /*Bits_grp[GRP_SB-1] = (int16_t)min((grp_bit_avg/p2a_bands + bits_allocweigh*norm_diff),10);*/ - L_temp = L_mult( grp_bit_avg_fx, Inv_p2a_bands_fx ); /* Q0+QIpb+1 */ + L_temp = L_mult( grp_bit_avg_fx, Inv_p2a_bands_fx ); /* Q0+QIpb+1 */ L_temp2 = Mpy_32_16_1( L_norm_diff, bits_allocweigh_fx ); /* Qbe+Q15-15 */ L_temp = L_shr( L_temp, add( QIpb, 1 ) ); @@ -890,7 +890,7 @@ void hq2_bit_alloc( /*Rk[k] = ((float) *bit_budget / Rcnt + weight * (band_energy[k] - Ravg)); */ L_tmp = Mpy_32_16_1( L_sub( L_shl( L_band_energy[k], sub( SWB_BWE_LR_QRk, SWB_BWE_LR_Qbe ) ), L_Ravg ), weight_fx ); /* SWB_BWE_LR_QRk + Q13 - 15 */ - L_tmp = L_shl( L_tmp, 2 ); /* -> SWB_BWE_LR_QRk */ + L_tmp = L_shl( L_tmp, 2 ); /* -> SWB_BWE_LR_QRk */ L_Rk[k] = L_add( L_shr( L_deposit_l( div_fx ), sub( Qdiv, SWB_BWE_LR_QRk ) ), L_tmp ); } diff --git a/lib_com/hq2_bit_alloc_fx.c b/lib_com/hq2_bit_alloc_fx.c index 99cb5d4d9..eb3342b29 100644 --- a/lib_com/hq2_bit_alloc_fx.c +++ b/lib_com/hq2_bit_alloc_fx.c @@ -35,218 +35,218 @@ #include "prot_fx2.h" #include "rom_com.h" -#define MIN_BITS_FIX 0 /* QRk=18 */ -#define HQ_16k40_BIT (HQ_16k40/50) /* 16400/50=328 */ -#define Qbf 14 /* Q value for bits_fact */ -#define C1_QRk (1< 0) - { - be_sum_fx = add(be_sum_fx, y_index_fx[k]); - } - } - QBavg = 0; - move16(); - - /*Ravg = (float) be_sum/be_cnt;*/ - Ravg_fx = 0; - move16(); - QRavg = 0; - move16(); - IF(be_cnt_fx != 0x0) - { - exp_normn = norm_s(be_sum_fx); - exp_normn = sub(exp_normn, 1); - exp_normd = norm_s(be_cnt_fx); - Ravg_fx = div_s(shl(be_sum_fx, exp_normn), shl(be_cnt_fx, exp_normd)); - - Ravg_fx = shr(Ravg_fx, 2); /* safe shift */ - QRavg = add(sub(exp_normn, exp_normd), 15 - 2); - } - - enr_diffcnt_fx = 0; - move16(); - th_5_fx = shl(5, QRavg); - FOR(j = 0; j < be_cnt_fx; j++) - { - if (GT_16(abs_s(sub(Ravg_fx, shl(y_index_fx[j], QRavg))), th_5_fx)) - { - enr_diffcnt_fx = add(enr_diffcnt_fx, 1); - } - } - - scale_fact_fx = 19661; - move16(); /* 0.60f 19660.8(Q15) */ - if (enr_diffcnt_fx > 0) - { - scale_fact_fx = 11468; - move16(); /* 0.35f 11468.8(Q15) */ - } - - /* Bits allocation to individual SB's in a group based on Band Energies */ - FOR(j = 0; j < be_cnt_fx; j++) - { - Rcnt_fx = add(i, 1); - - /* Ravg = (float) be_sum/Rcnt; */ - exp_normn = norm_s(be_sum_fx); - exp_normn = sub(exp_normn, 1); - exp_normd = norm_s(Rcnt_fx); - Ravg_fx = div_s(shl(be_sum_fx, exp_normn), shl(Rcnt_fx, exp_normd)); - Ravg_fx = shr(Ravg_fx, 2); /* safe shift */ - QRavg = add(sub(exp_normn, exp_normd), 15 - 2); - - if (be_sum_fx <= 0) - { - be_sum_fx = 1; - move16(); - } - - /* Bits_avg = (float) Bits/(be_sum+EPSILON); */ - Bits_avg_fx = 0; - move16(); - QBavg = 0; - move16(); - IF(Bits != 0) - { - exp_normn = norm_s(Bits); - exp_normn = sub(exp_normn, 1); - exp_normd = norm_s(be_sum_fx); - Bits_avg_fx = div_s(shl(Bits, exp_normn), shl(be_sum_fx, exp_normd)); - Bits_avg_fx = shr(Bits_avg_fx, 2); /* safe_shift */ - QBavg = add(sub(exp_normn, exp_normd), 15 - 2); - } - FOR(k = 0; k <= i; k++) - { - IF(L_R_temp[k] > 0) /* Rtemp -> SWB_BWE_LR_QRk */ - { - /* Allocate more bits to SB, if SB bandenergy is higher than average energy */ - /* R_temp[k] = (float)( Bits_avg * y_index[k]+( scale_fact * (y_index[k] - Ravg))); */ - L_temp1 = L_mult(Bits_avg_fx, y_index_fx[k]); /* QBavg+1 */ - L_temp2 = L_mult(scale_fact_fx, sub(shl(y_index_fx[k], QRavg), Ravg_fx)); /* 15+QRavg+1 */ - L_R_temp[k] = L_add(L_shr(L_temp1, sub(add(QBavg, 1), SWB_BWE_LR_QRk)), L_shr(L_temp2, sub(add(QRavg, 16), SWB_BWE_LR_QRk))); /* SWB_BWE_LR_QRk */ - } - } - IF(LT_32(L_R_temp[i], L_Bits_needed)) - { - L_R_temp[i] = L_deposit_l(0); - - p2aflags_fx_ptr[index_fx[i]] = 0; - move16(); - - /* be_sum -= y_index[i]; */ - be_sum_fx = sub(be_sum_fx, y_index_fx[i]); - - i = sub(i, 1); - } - ELSE - { - BREAK; - } - } - - /* Rearrange the bit allocation to align with original */ - FOR(k = 0; k < band_num_fx; k++) - { - j = index_fx[k]; - move16(); - L_R_ptr[j] = L_R_temp[k]; - move32(); - } - - return; + Word16 i, j, k; + Word32 L_R_temp[14]; /* QRk = QL_Rsubband; */ + Word16 Ravg_fx; + Word16 QRavg; + + const Word32 *L_y_ptr; + Word32 *L_R_ptr; + + Word16 Bits_avg_fx; + Word16 QBavg; + Word16 scale_fact_fx; + + Word16 band_num_fx; + Word16 index_fx[14]; + + Word16 y_index_fx[14]; + + Word16 be_sum_fx; /* Q0 */ + + Word16 exp_normn, exp_normd; + Word16 enr_diffcnt_fx; + Word16 th_5_fx; + Word16 Rcnt_fx; + + Word16 be_cnt_fx; + Word16 *p2aflags_fx_ptr; + + Word32 L_temp1; + Word32 L_temp2; + + band_num_fx = sub( end_band, start_band ); + L_y_ptr = L_be + start_band; + L_R_ptr = L_Rsubband + start_band; + p2aflags_fx_ptr = p2aflags_fx + start_band; + + FOR( i = 0; i < band_num_fx; i++ ) + { + y_index_fx[i] = extract_h( L_shr( L_y_ptr[i], sub( SWB_BWE_LR_Qbe, 16 ) ) ); + index_fx[i] = i; + move16(); + } + + + /* Rearrange norm vector in decreasing order */ + reordvct_fx( y_index_fx, band_num_fx, index_fx ); + + be_sum_fx = 0; + move16(); + be_cnt_fx = 0; + move16(); + FOR( j = 0; j < band_num_fx; j++ ) + { + test(); + IF( y_index_fx[j] <= 0 || p2aflags_fx_ptr[index_fx[j]] == 0 ) + { + y_index_fx[j] = 0; + move16(); + L_R_temp[j] = L_deposit_l( 0 ); + } + ELSE + { + L_R_temp[j] = C1_QRk; + move32(); /* filled not zero value */ + be_cnt_fx = add( be_cnt_fx, 1 ); + } + } + + i = sub( be_cnt_fx, 1 ); + FOR( k = 0; k <= i; k++ ) + { + if ( L_R_temp[k] > 0 ) + { + be_sum_fx = add( be_sum_fx, y_index_fx[k] ); + } + } + QBavg = 0; + move16(); + + /*Ravg = (float) be_sum/be_cnt;*/ + Ravg_fx = 0; + move16(); + QRavg = 0; + move16(); + IF( be_cnt_fx != 0x0 ) + { + exp_normn = norm_s( be_sum_fx ); + exp_normn = sub( exp_normn, 1 ); + exp_normd = norm_s( be_cnt_fx ); + Ravg_fx = div_s( shl( be_sum_fx, exp_normn ), shl( be_cnt_fx, exp_normd ) ); + + Ravg_fx = shr( Ravg_fx, 2 ); /* safe shift */ + QRavg = add( sub( exp_normn, exp_normd ), 15 - 2 ); + } + + enr_diffcnt_fx = 0; + move16(); + th_5_fx = shl( 5, QRavg ); + FOR( j = 0; j < be_cnt_fx; j++ ) + { + if ( GT_16( abs_s( sub( Ravg_fx, shl( y_index_fx[j], QRavg ) ) ), th_5_fx ) ) + { + enr_diffcnt_fx = add( enr_diffcnt_fx, 1 ); + } + } + + scale_fact_fx = 19661; + move16(); /* 0.60f 19660.8(Q15) */ + if ( enr_diffcnt_fx > 0 ) + { + scale_fact_fx = 11468; + move16(); /* 0.35f 11468.8(Q15) */ + } + + /* Bits allocation to individual SB's in a group based on Band Energies */ + FOR( j = 0; j < be_cnt_fx; j++ ) + { + Rcnt_fx = add( i, 1 ); + + /* Ravg = (float) be_sum/Rcnt; */ + exp_normn = norm_s( be_sum_fx ); + exp_normn = sub( exp_normn, 1 ); + exp_normd = norm_s( Rcnt_fx ); + Ravg_fx = div_s( shl( be_sum_fx, exp_normn ), shl( Rcnt_fx, exp_normd ) ); + Ravg_fx = shr( Ravg_fx, 2 ); /* safe shift */ + QRavg = add( sub( exp_normn, exp_normd ), 15 - 2 ); + + if ( be_sum_fx <= 0 ) + { + be_sum_fx = 1; + move16(); + } + + /* Bits_avg = (float) Bits/(be_sum+EPSILON); */ + Bits_avg_fx = 0; + move16(); + QBavg = 0; + move16(); + IF( Bits != 0 ) + { + exp_normn = norm_s( Bits ); + exp_normn = sub( exp_normn, 1 ); + exp_normd = norm_s( be_sum_fx ); + Bits_avg_fx = div_s( shl( Bits, exp_normn ), shl( be_sum_fx, exp_normd ) ); + Bits_avg_fx = shr( Bits_avg_fx, 2 ); /* safe_shift */ + QBavg = add( sub( exp_normn, exp_normd ), 15 - 2 ); + } + FOR( k = 0; k <= i; k++ ) + { + IF( L_R_temp[k] > 0 ) /* Rtemp -> SWB_BWE_LR_QRk */ + { + /* Allocate more bits to SB, if SB bandenergy is higher than average energy */ + /* R_temp[k] = (float)( Bits_avg * y_index[k]+( scale_fact * (y_index[k] - Ravg))); */ + L_temp1 = L_mult( Bits_avg_fx, y_index_fx[k] ); /* QBavg+1 */ + L_temp2 = L_mult( scale_fact_fx, sub( shl( y_index_fx[k], QRavg ), Ravg_fx ) ); /* 15+QRavg+1 */ + L_R_temp[k] = L_add( L_shr( L_temp1, sub( add( QBavg, 1 ), SWB_BWE_LR_QRk ) ), L_shr( L_temp2, sub( add( QRavg, 16 ), SWB_BWE_LR_QRk ) ) ); /* SWB_BWE_LR_QRk */ + } + } + IF( LT_32( L_R_temp[i], L_Bits_needed ) ) + { + L_R_temp[i] = L_deposit_l( 0 ); + + p2aflags_fx_ptr[index_fx[i]] = 0; + move16(); + + /* be_sum -= y_index[i]; */ + be_sum_fx = sub( be_sum_fx, y_index_fx[i] ); + + i = sub( i, 1 ); + } + ELSE + { + BREAK; + } + } + + /* Rearrange the bit allocation to align with original */ + FOR( k = 0; k < band_num_fx; k++ ) + { + j = index_fx[k]; + move16(); + L_R_ptr[j] = L_R_temp[k]; + move32(); + } + + return; } /*-------------------------------------------------------------------* @@ -256,409 +256,410 @@ void Bits2indvsb_fx( *-------------------------------------------------------------------*/ void hq2_bit_alloc_har_fx( - const Word32 *L_y, /* i : Qbe band energy of sub-vectors */ - Word16 B_fx, /* i : Q0 number of available bits */ - const Word16 N_fx, /* i : Q0 number of sub-vectors */ - Word32 *L_Rsubband, /* o : QRk sub-band bit-allocation vector */ - Word16 p2a_bands_fx, /* i : highfreq bands */ - const Word32 L_core_brate, /* i : Q0 core bit rate */ - Word16 p2a_flags_fx[], /* i/o: Q0 p2a_flags */ - const Word16 band_width_fx[] /* i : Q0 table of band_width */ + const Word32 *L_y, /* i : Qbe band energy of sub-vectors */ + Word16 B_fx, /* i : Q0 number of available bits */ + const Word16 N_fx, /* i : Q0 number of sub-vectors */ + Word32 *L_Rsubband, /* o : QRk sub-band bit-allocation vector */ + Word16 p2a_bands_fx, /* i : highfreq bands */ + const Word32 L_core_brate, /* i : Q0 core bit rate */ + Word16 p2a_flags_fx[], /* i/o: Q0 p2a_flags */ + const Word16 band_width_fx[] /* i : Q0 table of band_width */ ) { - Word16 i, j, k; - - Word32 L_norm_sum; /* Qbe */ - Word32 L_Ravg_sub[GRP_SB]; /* Qbe */ - Word32 L_temp_band_energy[BANDS_MAX]; /* Qbe */ - - Word16 j_fx, k_fx, Bits_grp_fx[GRP_SB]; - - Word32 L_temp_band_energydiff[BANDS_MAX]; - Word16 G1_BE_DIFF_POS_fx; /* Q0 */ - Word32 L_G1_BE_DIFF_VAL; /* Qbe Word32 */ - Word16 final_gr_fact_pos_fx, gmax_range_fx[2], temp_fx; - Word16 bits_fact_fx, bits_fact1_fx; /* Q? */ - Word16 grp_rngmax_fx[2] = { 0 }; - Word16 index_fx[NB_SWB_SUBBANDS_HAR], y_index_fx[NB_SWB_SUBBANDS_HAR], esthf_bits_fx, grp_bit_avg_fx, harmonic_band_fx; - Word32 L_norm_sum_avg; - Word32 L_norm_diff; /* Qbe */ - Word16 bits_allocweigh_fx; /* Q15 */ - Word16 grp_bound_fx[5]; - Word32 L_grp_thr[GRP_SB]; /* not require Word32 precission */ - Word16 lf_hf_ge_r_fx; /* Q15 */ - Word32 L_avg_enhf_en_diff; /* Qbe */ - - Word16 B_norm_fx; - - Word32 L_temp, L_temp2; - Word16 exp, frac; - - Word32 L_THR1, L_THR2, L_THR3; - - Word16 exp_norm; - Word16 norm_sum_fx; - Word16 Qns; /* Q value for norm_sum_fx */ - Word16 Inv_norm_sum_fx; /* 1/norm_sum */ - Word16 QIns; /* Q value for Inv_norm_sum_fx */ - - Word16 exp_normn, exp_normd; - Word16 div_fx; - - Word16 Inv_p2a_bands_fx; - Word16 QIpb; - - Word16 exp_shift; - - L_THR1 = L_shl(L_deposit_l(THR1), SWB_BWE_LR_QRk); - L_THR2 = L_shl(L_deposit_l(THR2), SWB_BWE_LR_QRk); - L_THR3 = L_shl(L_deposit_l(THR3), SWB_BWE_LR_QRk); - - set16_fx(Bits_grp_fx, 0, GRP_SB); - - /* Initialize subbands bits allocation vector based on harmonic bands */ - harmonic_band_fx = add(sub(N_fx, p2a_bands_fx), 1); - /*printf("harmonic_band= %d %d\n", harmonic_band, harmonic_band_fx);*/ - FOR(k = 0; k < N_fx; k++) - { - L_Rsubband[k] = (Word32)(C1_QRk); - move32(); /* Constant Value */ - L_temp_band_energy[k] = L_y[k]; - move32(); /* SWB_BWE_LR_Qbe */ - } - final_gr_fact_pos_fx = 2; - move16(); - bits_fact_fx = C1_Qbf; - move16(); - bits_fact1_fx = C1_Qbf; - move16(); - - gmax_range_fx[0] = G1_RANGE; - move16(); - gmax_range_fx[1] = G1G2_RANGE; - move16(); - - IF(EQ_32(L_core_brate, HQ_16k40)) - { - gmax_range_fx[1] = add(gmax_range_fx[1], 2); - move16(); - } - - /* decide each group range, for grouping spectral coefficients */ - grp_rngmax_fx[1] = 16; - move16(); - grp_rngmax_fx[0] = 7; - move16(); - temp_fx = 0; - move16(); - FOR(i = 0; i < 2; i++) - { - j_fx = gmax_range_fx[i]; - move16(); - k_fx = 0; - move16(); - WHILE(GE_32(L_temp_band_energy[gmax_range_fx[i] - 1], L_temp_band_energy[j_fx]) && LT_16(j_fx, grp_rngmax_fx[i])) - { - test(); - k_fx = add(k_fx, 1); - j_fx = add(j_fx, 1); - } - - temp_fx = k_fx; - move16(); - IF(GT_16(temp_fx, 1)) - { - FOR(temp_fx = 2; temp_fx <= k_fx; ) - { - IF(LT_32(L_temp_band_energy[gmax_range_fx[i] + temp_fx - 1], L_temp_band_energy[gmax_range_fx[i] + temp_fx])) - { - BREAK; - } - ELSE IF(GE_32(L_temp_band_energy[gmax_range_fx[i] + temp_fx - 1], L_temp_band_energy[gmax_range_fx[i] + temp_fx])) - { - temp_fx = add(temp_fx, 1);; - IF(GT_16(temp_fx, k_fx)) - { - temp_fx = sub(temp_fx, 1); - BREAK; - } - } - } - - gmax_range_fx[i] = add(gmax_range_fx[i], temp_fx); - move16(); - } - ELSE - { - gmax_range_fx[i] = add(gmax_range_fx[i], temp_fx); - move16(); - } - } - - grp_bound_fx[0] = 0; - move16(); - FOR(i = 1; i < GRP_SB - 1; i++) - { - grp_bound_fx[i] = gmax_range_fx[i - 1]; - move16(); - } - grp_bound_fx[i] = harmonic_band_fx; - move16(); - grp_bound_fx[i + 1] = N_fx; - move16(); - - - FOR(i = 0; i < GRP_SB; i++) - { - L_Ravg_sub[i] = L_deposit_l(0); - FOR(j = grp_bound_fx[i]; j < grp_bound_fx[i + 1]; j++) - { - IF(L_temp_band_energy[j] > 0x0L) - { - L_Ravg_sub[i] = L_add(L_Ravg_sub[i], L_temp_band_energy[j]); - move32(); - } - } - } - - L_temp_band_energydiff[0] = L_temp_band_energy[0]; - move32(); - FOR(j = 1; j < harmonic_band_fx; j++) - { - L_temp_band_energydiff[j] = L_abs(L_sub(L_temp_band_energy[j], L_temp_band_energy[j - 1])); - move32(); - } - - G1_BE_DIFF_POS_fx = 0; - move16(); - L_G1_BE_DIFF_VAL = L_deposit_l(0); - - FOR(j = 1; j < harmonic_band_fx; j++) - { - IF(GT_32(L_temp_band_energydiff[j], L_G1_BE_DIFF_VAL)) - { - G1_BE_DIFF_POS_fx = j; - move16(); - L_G1_BE_DIFF_VAL = L_temp_band_energydiff[j]; - } - } - - test(); - test(); - IF(LT_16(G1_BE_DIFF_POS_fx, gmax_range_fx[0]) && G1_BE_DIFF_POS_fx > 0) - { - final_gr_fact_pos_fx = 0; - move16(); - } - ELSE IF(GE_16(G1_BE_DIFF_POS_fx, gmax_range_fx[0]) && LT_16(G1_BE_DIFF_POS_fx, gmax_range_fx[1])) - { - final_gr_fact_pos_fx = 1; - move16(); - } - ELSE - { - final_gr_fact_pos_fx = 2; - move16(); - } - - test(); - IF(final_gr_fact_pos_fx == 0 || EQ_16(final_gr_fact_pos_fx, 1)) - { - IF(EQ_32(L_core_brate, HQ_16k40)) - { - bits_fact_fx = BITS_FACT_1p10; - move16(); /* 1.10f; */ /* G1 */ - bits_fact1_fx = BITS_FACT_0p92; - move16(); /* 0.92f; */ /* G3 */ - } - ELSE - { - bits_fact_fx = BITS_FACT_1p05; - move16(); /* 1.05f; */ /* G1 */ - bits_fact1_fx = BITS_FACT_0p97; - move16(); /* 0.97f; */ /* G3 */ - } - } - ELSE - { - IF(EQ_32(L_core_brate, HQ_16k40)) - { - bits_fact_fx = BITS_FACT_0p97; - move16(); /* 0.97f; */ /* G1 */ - bits_fact1_fx = BITS_FACT_1p00; - move16(); /* 1.00f; */ /* G3 */ - } - ELSE - { - bits_fact_fx = BITS_FACT_0p92; - move16(); /* 0.92f; */ /* G1 */ - bits_fact1_fx = BITS_FACT_1p00; - move16(); /* 1.00f; */ /* G3 */ - } - } - - j = sub(N_fx, harmonic_band_fx); - FOR(i = 0; i < j; i++) - { - y_index_fx[i] = extract_h(L_shl(L_temp_band_energy[harmonic_band_fx + i], sub(16, SWB_BWE_LR_Qbe))); - index_fx[i] = add(harmonic_band_fx, i); - move16(); - } - - reordvct_fx(y_index_fx, sub(N_fx, harmonic_band_fx), index_fx); - - /* Log2 */ - L_temp = L_deposit_l(band_width_fx[index_fx[0]]); - exp = norm_l(L_temp); - frac = Log2_norm_lc(L_shl(L_temp, exp)); - exp = sub(30, exp); - L_temp = L_Comp(exp, frac); - /* ceil */ - if (L_and(0x0000ffff, L_temp) > 0) - { - L_temp = L_add(L_temp, 0x00010000); - } - esthf_bits_fx = extract_h(L_temp); - - L_grp_thr[0] = L_THR1; - move32(); - L_grp_thr[1] = L_THR2; - move32(); - L_grp_thr[2] = L_THR3; - move32(); - L_grp_thr[3] = L_shl(L_deposit_l(esthf_bits_fx), SWB_BWE_LR_QRk); - move16(); - - L_norm_sum = L_deposit_l(1); - FOR(i = 0; i < 3; i++) - { - L_norm_sum = L_add(L_norm_sum, L_Ravg_sub[i]); - } - - /*reserve bits for HF coding */ - L_temp = L_add(L_norm_sum, L_Ravg_sub[GRP_SB - 1]); - exp_normn = norm_l(L_temp); - exp_normn = sub(exp_normn, 1); - exp_normd = norm_s(N_fx); - - div_fx = div_l(L_shl(L_temp, exp_normn), shl(N_fx, exp_normd)); /* (Qbe+exp_normn)-(0+exp_normd)-1) */ - L_norm_sum_avg = L_shr(L_deposit_h(div_fx), add(sub(exp_normn, exp_normd), 15)); /* -> Qbe */ - - exp_norm = norm_l(L_norm_sum); - norm_sum_fx = extract_h(L_shl(L_norm_sum, exp_norm)); /* SWB_BWE_LR_Qbe+exp_norm-16 */ - Qns = sub(add(SWB_BWE_LR_Qbe, exp_norm), 16); - - Inv_norm_sum_fx = div_s(0x4000 /* Q15 */, norm_sum_fx); - QIns = sub(31, exp_norm); /* 14 - (14+exp_norm-16) + 15 */ - - grp_bit_avg_fx = div_s_ss(B_fx, GRP_SB); /* Q0 */ - - exp_normd = norm_s(p2a_bands_fx); - Inv_p2a_bands_fx = div_s(0x3fff, shl(p2a_bands_fx, exp_normd)); /* 14-exp_normd+15 */ - QIpb = sub(29, exp_normd); - - L_temp = L_shl(Mult_32_16(L_Ravg_sub[GRP_SB - 1], Inv_p2a_bands_fx), sub(SWB_BWE_LR_Qbe, sub(QIpb, 1))); - L_norm_diff = L_sub(L_temp, L_norm_sum_avg); /* Qbe */ - - L_temp = Mult_32_16(L_Ravg_sub[GRP_SB - 1], sub(GRP_SB, 1)); /* Qbe+0+1 */ - L_temp = Mult_32_16(L_temp, Inv_norm_sum_fx); /* Qbe+1+QIpb+1 */ - lf_hf_ge_r_fx = round_fx(L_shl(L_temp, sub(15 + 16, sub(add(SWB_BWE_LR_Qbe, QIns), 30)))); - - exp_normn = norm_s(norm_sum_fx); - exp_normn = sub(exp_normn, 1); - exp_normd = norm_s(harmonic_band_fx); - - div_fx = div_s(shl(norm_sum_fx, exp_normn), shl(harmonic_band_fx, exp_normd)); - L_avg_enhf_en_diff = L_sub(L_temp_band_energy[index_fx[0]], L_shl(L_deposit_h(div_fx), sub(sub(SWB_BWE_LR_Qbe, (add(Qns, sub(exp_normn, exp_normd)))), 31))); /* Qbe - (Qns+exp_normn-(exp_normd)+15) -16 */ - - test(); - IF(GT_16(lf_hf_ge_r_fx, 26214) && GT_32(L_avg_enhf_en_diff, (Word32)(8 << SWB_BWE_LR_Qbe))) /* 0.8=26214.4(Q15) 8.0f=131072(Qbe) */ - { - bits_allocweigh_fx = 6554; - move16(); /* 0.2 6553.6(Q15) */ - if (L_norm_diff < 0x0L) - { - bits_allocweigh_fx = 13107; - move16(); /* 0.4 13107.2(Q15) */ - } - - /*allocate bits*/ - /*Bits_grp[GRP_SB-1] = (short)min((grp_bit_avg/p2a_bands + bits_allocweigh*norm_diff),10);*/ - L_temp = L_mult(grp_bit_avg_fx, Inv_p2a_bands_fx); /* Q0+QIpb+1 */ - L_temp2 = Mult_32_16(L_norm_diff, bits_allocweigh_fx); /* Qbe+Q15-15 */ - - L_temp = L_shr(L_temp, add(QIpb, 1)); - L_temp = L_add(L_shl(L_temp, SWB_BWE_LR_Qbe), L_temp2); - - Bits_grp_fx[GRP_SB - 1] = extract_h(L_shl(L_temp, sub(16, SWB_BWE_LR_Qbe))); - Bits_grp_fx[GRP_SB - 1] = s_min(Bits_grp_fx[GRP_SB - 1], 10); - move16(); - - if (LT_16(Bits_grp_fx[GRP_SB - 1], esthf_bits_fx)) - { - Bits_grp_fx[GRP_SB - 1] = 0; - move16(); - } - B_fx = sub(B_fx, Bits_grp_fx[GRP_SB - 1]); - } - - exp_shift = sub(add(SWB_BWE_LR_Qbe, QIns), 47); /* (SWB_BWE_LR_Qbe+14+1+QIns-15-16) */ - exp_norm = norm_s(B_fx); - B_norm_fx = shl(B_fx, exp_norm); - exp_shift = add(exp_shift, exp_norm); - - IF(EQ_16(final_gr_fact_pos_fx, 1)) - { - L_temp = Mult_32_16(L_Ravg_sub[1], extract_h(L_mult(bits_fact_fx, B_norm_fx))); - L_temp = Mult_32_16(L_temp, Inv_norm_sum_fx); - Bits_grp_fx[1] = extract_h(L_shr(L_temp, exp_shift)); - - L_temp = Mult_32_16(L_Ravg_sub[2], extract_h(L_mult(bits_fact1_fx, B_norm_fx))); - L_temp = Mult_32_16(L_temp, Inv_norm_sum_fx); - Bits_grp_fx[2] = extract_h(L_shr(L_temp, exp_shift)); - - Bits_grp_fx[0] = sub(sub(B_fx, Bits_grp_fx[1]), Bits_grp_fx[2]); - move16(); - } - ELSE - { - L_temp = Mult_32_16(L_Ravg_sub[0], extract_h(L_mult(bits_fact_fx, B_norm_fx))); - L_temp = Mult_32_16(L_temp, Inv_norm_sum_fx); - Bits_grp_fx[0] = extract_h(L_shr(L_temp, exp_shift)); - - L_temp = Mult_32_16(L_Ravg_sub[2], extract_h(L_mult(bits_fact1_fx, B_norm_fx))); - L_temp = Mult_32_16(L_temp, Inv_norm_sum_fx); - Bits_grp_fx[2] = extract_h(L_shr(L_temp, exp_shift)); - - Bits_grp_fx[1] = sub(sub(B_fx, Bits_grp_fx[0]), Bits_grp_fx[2]); - move16(); - } - - IF(LT_16(Bits_grp_fx[2], THR2)) - { - Bits_grp_fx[1] = add(Bits_grp_fx[1], Bits_grp_fx[2]); - move16(); - Bits_grp_fx[2] = 0; - move16(); - } - - FOR(i = 0; i < GRP_SB; i++) - { - IF(Bits_grp_fx[i] > 0) - { - Bits2indvsb_fx(L_temp_band_energy, grp_bound_fx[i], grp_bound_fx[i + 1], Bits_grp_fx[i], L_grp_thr[i], L_Rsubband, p2a_flags_fx); - } - ELSE - { - set32_fx(L_Rsubband + grp_bound_fx[i], 0x0L, sub(grp_bound_fx[i + 1], grp_bound_fx[i])); - IF(EQ_16(i, GRP_SB - 1)) - { - set16_fx(p2a_flags_fx + grp_bound_fx[i], 0, sub(grp_bound_fx[i + 1], grp_bound_fx[i])); - } - } - } - - return; + Word16 i, j, k; + + Word32 L_norm_sum; /* Qbe */ + Word32 L_Ravg_sub[GRP_SB]; /* Qbe */ + Word32 L_temp_band_energy[BANDS_MAX]; /* Qbe */ + + Word16 j_fx, k_fx, Bits_grp_fx[GRP_SB]; + + Word32 L_temp_band_energydiff[BANDS_MAX]; + Word16 G1_BE_DIFF_POS_fx; /* Q0 */ + Word32 L_G1_BE_DIFF_VAL; /* Qbe Word32 */ + Word16 final_gr_fact_pos_fx, gmax_range_fx[2], temp_fx; + Word16 bits_fact_fx, bits_fact1_fx; /* Q? */ + Word16 grp_rngmax_fx[2] = { 0 }; + Word16 index_fx[NB_SWB_SUBBANDS_HAR], y_index_fx[NB_SWB_SUBBANDS_HAR], esthf_bits_fx, grp_bit_avg_fx, harmonic_band_fx; + Word32 L_norm_sum_avg; + Word32 L_norm_diff; /* Qbe */ + Word16 bits_allocweigh_fx; /* Q15 */ + Word16 grp_bound_fx[5]; + Word32 L_grp_thr[GRP_SB]; /* not require Word32 precission */ + Word16 lf_hf_ge_r_fx; /* Q15 */ + Word32 L_avg_enhf_en_diff; /* Qbe */ + + Word16 B_norm_fx; + + Word32 L_temp, L_temp2; + Word16 exp, frac; + + Word32 L_THR1, L_THR2, L_THR3; + + Word16 exp_norm; + Word16 norm_sum_fx; + Word16 Qns; /* Q value for norm_sum_fx */ + Word16 Inv_norm_sum_fx; /* 1/norm_sum */ + Word16 QIns; /* Q value for Inv_norm_sum_fx */ + + Word16 exp_normn, exp_normd; + Word16 div_fx; + + Word16 Inv_p2a_bands_fx; + Word16 QIpb; + + Word16 exp_shift; + + L_THR1 = L_shl( L_deposit_l( THR1 ), SWB_BWE_LR_QRk ); + L_THR2 = L_shl( L_deposit_l( THR2 ), SWB_BWE_LR_QRk ); + L_THR3 = L_shl( L_deposit_l( THR3 ), SWB_BWE_LR_QRk ); + + set16_fx( Bits_grp_fx, 0, GRP_SB ); + + /* Initialize subbands bits allocation vector based on harmonic bands */ + harmonic_band_fx = add( sub( N_fx, p2a_bands_fx ), 1 ); + /*printf("harmonic_band= %d %d\n", harmonic_band, harmonic_band_fx);*/ + FOR( k = 0; k < N_fx; k++ ) + { + L_Rsubband[k] = (Word32) ( C1_QRk ); + move32(); /* Constant Value */ + L_temp_band_energy[k] = L_y[k]; + move32(); /* SWB_BWE_LR_Qbe */ + } + final_gr_fact_pos_fx = 2; + move16(); + bits_fact_fx = C1_Qbf; + move16(); + bits_fact1_fx = C1_Qbf; + move16(); + + gmax_range_fx[0] = G1_RANGE; + move16(); + gmax_range_fx[1] = G1G2_RANGE; + move16(); + + IF( EQ_32( L_core_brate, HQ_16k40 ) ) + { + gmax_range_fx[1] = add( gmax_range_fx[1], 2 ); + move16(); + } + + /* decide each group range, for grouping spectral coefficients */ + grp_rngmax_fx[1] = 16; + move16(); + grp_rngmax_fx[0] = 7; + move16(); + temp_fx = 0; + move16(); + FOR( i = 0; i < 2; i++ ) + { + j_fx = gmax_range_fx[i]; + move16(); + k_fx = 0; + move16(); + WHILE( GE_32( L_temp_band_energy[gmax_range_fx[i] - 1], L_temp_band_energy[j_fx] ) && LT_16( j_fx, grp_rngmax_fx[i] ) ) + { + test(); + k_fx = add( k_fx, 1 ); + j_fx = add( j_fx, 1 ); + } + + temp_fx = k_fx; + move16(); + IF( GT_16( temp_fx, 1 ) ) + { + FOR( temp_fx = 2; temp_fx <= k_fx; ) + { + IF( LT_32( L_temp_band_energy[gmax_range_fx[i] + temp_fx - 1], L_temp_band_energy[gmax_range_fx[i] + temp_fx] ) ) + { + BREAK; + } + ELSE IF( GE_32( L_temp_band_energy[gmax_range_fx[i] + temp_fx - 1], L_temp_band_energy[gmax_range_fx[i] + temp_fx] ) ) + { + temp_fx = add( temp_fx, 1 ); + ; + IF( GT_16( temp_fx, k_fx ) ) + { + temp_fx = sub( temp_fx, 1 ); + BREAK; + } + } + } + + gmax_range_fx[i] = add( gmax_range_fx[i], temp_fx ); + move16(); + } + ELSE + { + gmax_range_fx[i] = add( gmax_range_fx[i], temp_fx ); + move16(); + } + } + + grp_bound_fx[0] = 0; + move16(); + FOR( i = 1; i < GRP_SB - 1; i++ ) + { + grp_bound_fx[i] = gmax_range_fx[i - 1]; + move16(); + } + grp_bound_fx[i] = harmonic_band_fx; + move16(); + grp_bound_fx[i + 1] = N_fx; + move16(); + + + FOR( i = 0; i < GRP_SB; i++ ) + { + L_Ravg_sub[i] = L_deposit_l( 0 ); + FOR( j = grp_bound_fx[i]; j < grp_bound_fx[i + 1]; j++ ) + { + IF( L_temp_band_energy[j] > 0x0L ) + { + L_Ravg_sub[i] = L_add( L_Ravg_sub[i], L_temp_band_energy[j] ); + move32(); + } + } + } + + L_temp_band_energydiff[0] = L_temp_band_energy[0]; + move32(); + FOR( j = 1; j < harmonic_band_fx; j++ ) + { + L_temp_band_energydiff[j] = L_abs( L_sub( L_temp_band_energy[j], L_temp_band_energy[j - 1] ) ); + move32(); + } + + G1_BE_DIFF_POS_fx = 0; + move16(); + L_G1_BE_DIFF_VAL = L_deposit_l( 0 ); + + FOR( j = 1; j < harmonic_band_fx; j++ ) + { + IF( GT_32( L_temp_band_energydiff[j], L_G1_BE_DIFF_VAL ) ) + { + G1_BE_DIFF_POS_fx = j; + move16(); + L_G1_BE_DIFF_VAL = L_temp_band_energydiff[j]; + } + } + + test(); + test(); + IF( LT_16( G1_BE_DIFF_POS_fx, gmax_range_fx[0] ) && G1_BE_DIFF_POS_fx > 0 ) + { + final_gr_fact_pos_fx = 0; + move16(); + } + ELSE IF( GE_16( G1_BE_DIFF_POS_fx, gmax_range_fx[0] ) && LT_16( G1_BE_DIFF_POS_fx, gmax_range_fx[1] ) ) + { + final_gr_fact_pos_fx = 1; + move16(); + } + ELSE + { + final_gr_fact_pos_fx = 2; + move16(); + } + + test(); + IF( final_gr_fact_pos_fx == 0 || EQ_16( final_gr_fact_pos_fx, 1 ) ) + { + IF( EQ_32( L_core_brate, HQ_16k40 ) ) + { + bits_fact_fx = BITS_FACT_1p10; + move16(); /* 1.10f; */ /* G1 */ + bits_fact1_fx = BITS_FACT_0p92; + move16(); /* 0.92f; */ /* G3 */ + } + ELSE + { + bits_fact_fx = BITS_FACT_1p05; + move16(); /* 1.05f; */ /* G1 */ + bits_fact1_fx = BITS_FACT_0p97; + move16(); /* 0.97f; */ /* G3 */ + } + } + ELSE + { + IF( EQ_32( L_core_brate, HQ_16k40 ) ) + { + bits_fact_fx = BITS_FACT_0p97; + move16(); /* 0.97f; */ /* G1 */ + bits_fact1_fx = BITS_FACT_1p00; + move16(); /* 1.00f; */ /* G3 */ + } + ELSE + { + bits_fact_fx = BITS_FACT_0p92; + move16(); /* 0.92f; */ /* G1 */ + bits_fact1_fx = BITS_FACT_1p00; + move16(); /* 1.00f; */ /* G3 */ + } + } + + j = sub( N_fx, harmonic_band_fx ); + FOR( i = 0; i < j; i++ ) + { + y_index_fx[i] = extract_h( L_shl( L_temp_band_energy[harmonic_band_fx + i], sub( 16, SWB_BWE_LR_Qbe ) ) ); + index_fx[i] = add( harmonic_band_fx, i ); + move16(); + } + + reordvct_fx( y_index_fx, sub( N_fx, harmonic_band_fx ), index_fx ); + + /* Log2 */ + L_temp = L_deposit_l( band_width_fx[index_fx[0]] ); + exp = norm_l( L_temp ); + frac = Log2_norm_lc( L_shl( L_temp, exp ) ); + exp = sub( 30, exp ); + L_temp = L_Comp( exp, frac ); + /* ceil */ + if ( L_and( 0x0000ffff, L_temp ) > 0 ) + { + L_temp = L_add( L_temp, 0x00010000 ); + } + esthf_bits_fx = extract_h( L_temp ); + + L_grp_thr[0] = L_THR1; + move32(); + L_grp_thr[1] = L_THR2; + move32(); + L_grp_thr[2] = L_THR3; + move32(); + L_grp_thr[3] = L_shl( L_deposit_l( esthf_bits_fx ), SWB_BWE_LR_QRk ); + move16(); + + L_norm_sum = L_deposit_l( 1 ); + FOR( i = 0; i < 3; i++ ) + { + L_norm_sum = L_add( L_norm_sum, L_Ravg_sub[i] ); + } + + /*reserve bits for HF coding */ + L_temp = L_add( L_norm_sum, L_Ravg_sub[GRP_SB - 1] ); + exp_normn = norm_l( L_temp ); + exp_normn = sub( exp_normn, 1 ); + exp_normd = norm_s( N_fx ); + + div_fx = div_l( L_shl( L_temp, exp_normn ), shl( N_fx, exp_normd ) ); /* (Qbe+exp_normn)-(0+exp_normd)-1) */ + L_norm_sum_avg = L_shr( L_deposit_h( div_fx ), add( sub( exp_normn, exp_normd ), 15 ) ); /* -> Qbe */ + + exp_norm = norm_l( L_norm_sum ); + norm_sum_fx = extract_h( L_shl( L_norm_sum, exp_norm ) ); /* SWB_BWE_LR_Qbe+exp_norm-16 */ + Qns = sub( add( SWB_BWE_LR_Qbe, exp_norm ), 16 ); + + Inv_norm_sum_fx = div_s( 0x4000 /* Q15 */, norm_sum_fx ); + QIns = sub( 31, exp_norm ); /* 14 - (14+exp_norm-16) + 15 */ + + grp_bit_avg_fx = div_s_ss( B_fx, GRP_SB ); /* Q0 */ + + exp_normd = norm_s( p2a_bands_fx ); + Inv_p2a_bands_fx = div_s( 0x3fff, shl( p2a_bands_fx, exp_normd ) ); /* 14-exp_normd+15 */ + QIpb = sub( 29, exp_normd ); + + L_temp = L_shl( Mult_32_16( L_Ravg_sub[GRP_SB - 1], Inv_p2a_bands_fx ), sub( SWB_BWE_LR_Qbe, sub( QIpb, 1 ) ) ); + L_norm_diff = L_sub( L_temp, L_norm_sum_avg ); /* Qbe */ + + L_temp = Mult_32_16( L_Ravg_sub[GRP_SB - 1], sub( GRP_SB, 1 ) ); /* Qbe+0+1 */ + L_temp = Mult_32_16( L_temp, Inv_norm_sum_fx ); /* Qbe+1+QIpb+1 */ + lf_hf_ge_r_fx = round_fx( L_shl( L_temp, sub( 15 + 16, sub( add( SWB_BWE_LR_Qbe, QIns ), 30 ) ) ) ); + + exp_normn = norm_s( norm_sum_fx ); + exp_normn = sub( exp_normn, 1 ); + exp_normd = norm_s( harmonic_band_fx ); + + div_fx = div_s( shl( norm_sum_fx, exp_normn ), shl( harmonic_band_fx, exp_normd ) ); + L_avg_enhf_en_diff = L_sub( L_temp_band_energy[index_fx[0]], L_shl( L_deposit_h( div_fx ), sub( sub( SWB_BWE_LR_Qbe, ( add( Qns, sub( exp_normn, exp_normd ) ) ) ), 31 ) ) ); /* Qbe - (Qns+exp_normn-(exp_normd)+15) -16 */ + + test(); + IF( GT_16( lf_hf_ge_r_fx, 26214 ) && GT_32( L_avg_enhf_en_diff, (Word32) ( 8 << SWB_BWE_LR_Qbe ) ) ) /* 0.8=26214.4(Q15) 8.0f=131072(Qbe) */ + { + bits_allocweigh_fx = 6554; + move16(); /* 0.2 6553.6(Q15) */ + if ( L_norm_diff < 0x0L ) + { + bits_allocweigh_fx = 13107; + move16(); /* 0.4 13107.2(Q15) */ + } + + /*allocate bits*/ + /*Bits_grp[GRP_SB-1] = (short)min((grp_bit_avg/p2a_bands + bits_allocweigh*norm_diff),10);*/ + L_temp = L_mult( grp_bit_avg_fx, Inv_p2a_bands_fx ); /* Q0+QIpb+1 */ + L_temp2 = Mult_32_16( L_norm_diff, bits_allocweigh_fx ); /* Qbe+Q15-15 */ + + L_temp = L_shr( L_temp, add( QIpb, 1 ) ); + L_temp = L_add( L_shl( L_temp, SWB_BWE_LR_Qbe ), L_temp2 ); + + Bits_grp_fx[GRP_SB - 1] = extract_h( L_shl( L_temp, sub( 16, SWB_BWE_LR_Qbe ) ) ); + Bits_grp_fx[GRP_SB - 1] = s_min( Bits_grp_fx[GRP_SB - 1], 10 ); + move16(); + + if ( LT_16( Bits_grp_fx[GRP_SB - 1], esthf_bits_fx ) ) + { + Bits_grp_fx[GRP_SB - 1] = 0; + move16(); + } + B_fx = sub( B_fx, Bits_grp_fx[GRP_SB - 1] ); + } + + exp_shift = sub( add( SWB_BWE_LR_Qbe, QIns ), 47 ); /* (SWB_BWE_LR_Qbe+14+1+QIns-15-16) */ + exp_norm = norm_s( B_fx ); + B_norm_fx = shl( B_fx, exp_norm ); + exp_shift = add( exp_shift, exp_norm ); + + IF( EQ_16( final_gr_fact_pos_fx, 1 ) ) + { + L_temp = Mult_32_16( L_Ravg_sub[1], extract_h( L_mult( bits_fact_fx, B_norm_fx ) ) ); + L_temp = Mult_32_16( L_temp, Inv_norm_sum_fx ); + Bits_grp_fx[1] = extract_h( L_shr( L_temp, exp_shift ) ); + + L_temp = Mult_32_16( L_Ravg_sub[2], extract_h( L_mult( bits_fact1_fx, B_norm_fx ) ) ); + L_temp = Mult_32_16( L_temp, Inv_norm_sum_fx ); + Bits_grp_fx[2] = extract_h( L_shr( L_temp, exp_shift ) ); + + Bits_grp_fx[0] = sub( sub( B_fx, Bits_grp_fx[1] ), Bits_grp_fx[2] ); + move16(); + } + ELSE + { + L_temp = Mult_32_16( L_Ravg_sub[0], extract_h( L_mult( bits_fact_fx, B_norm_fx ) ) ); + L_temp = Mult_32_16( L_temp, Inv_norm_sum_fx ); + Bits_grp_fx[0] = extract_h( L_shr( L_temp, exp_shift ) ); + + L_temp = Mult_32_16( L_Ravg_sub[2], extract_h( L_mult( bits_fact1_fx, B_norm_fx ) ) ); + L_temp = Mult_32_16( L_temp, Inv_norm_sum_fx ); + Bits_grp_fx[2] = extract_h( L_shr( L_temp, exp_shift ) ); + + Bits_grp_fx[1] = sub( sub( B_fx, Bits_grp_fx[0] ), Bits_grp_fx[2] ); + move16(); + } + + IF( LT_16( Bits_grp_fx[2], THR2 ) ) + { + Bits_grp_fx[1] = add( Bits_grp_fx[1], Bits_grp_fx[2] ); + move16(); + Bits_grp_fx[2] = 0; + move16(); + } + + FOR( i = 0; i < GRP_SB; i++ ) + { + IF( Bits_grp_fx[i] > 0 ) + { + Bits2indvsb_fx( L_temp_band_energy, grp_bound_fx[i], grp_bound_fx[i + 1], Bits_grp_fx[i], L_grp_thr[i], L_Rsubband, p2a_flags_fx ); + } + ELSE + { + set32_fx( L_Rsubband + grp_bound_fx[i], 0x0L, sub( grp_bound_fx[i + 1], grp_bound_fx[i] ) ); + IF( EQ_16( i, GRP_SB - 1 ) ) + { + set16_fx( p2a_flags_fx + grp_bound_fx[i], 0, sub( grp_bound_fx[i + 1], grp_bound_fx[i] ) ); + } + } + } + + return; } /*--------------------------------------------------------------------------* @@ -668,276 +669,274 @@ void hq2_bit_alloc_har_fx( *--------------------------------------------------------------------------*/ Word32 hq2_bit_alloc_fx( - const Word32 L_band_energy[], /* i : band energy of each subband */ - const Word16 bands, /* i : total number of subbands in a frame */ - Word32 L_Rk[], /* i/o: Bit allocation/Adjusted bit alloc. */ - Word16 *bit_budget_fx, /* i/o: bit bugdet */ - Word16 *p2a_flags, /* i : HF tonal indicator */ - const Word16 weight_fx, /* i : weight */ - const Word16 band_width[], /* i : Sub band bandwidth */ - const Word16 num_bits, /* i : available bits */ - const Word16 hqswb_clas, /* i : HQ2 class information */ - const Word16 bwidth, /* i : input bandwidth */ - const Word16 is_transient /* i : indicator HQ_TRANSIENT or not */ + const Word32 L_band_energy[], /* i : band energy of each subband */ + const Word16 bands, /* i : total number of subbands in a frame */ + Word32 L_Rk[], /* i/o: Bit allocation/Adjusted bit alloc. */ + Word16 *bit_budget_fx, /* i/o: bit bugdet */ + Word16 *p2a_flags, /* i : HF tonal indicator */ + const Word16 weight_fx, /* i : weight */ + const Word16 band_width[], /* i : Sub band bandwidth */ + const Word16 num_bits, /* i : available bits */ + const Word16 hqswb_clas, /* i : HQ2 class information */ + const Word16 bwidth, /* i : input bandwidth */ + const Word16 is_transient /* i : indicator HQ_TRANSIENT or not */ ) { - Word16 j, k; - Word16 tmp; - Word16 bit_budget_norm_fx; - - Word32 L_Rcalc, L_Ravg, L_Rcalc1; - - Word16 exp_normn, exp_normd; - - Word16 Rcnt_fx; - - Word16 div_fx; - Word16 Qdiv; - - Word32 L_tmp; - Word16 tmp_fx; - - Word32 L_maxxy; - Word16 maxdex_fx; - Word32 L_dummy; - - Word16 bit_budget_temp_fx; - - Word16 negflag; - - Word32 L_THR1, L_THR2, L_THR3; - - L_THR1 = L_shl(L_deposit_l(THR1), SWB_BWE_LR_QRk); - L_THR2 = L_shl(L_deposit_l(THR2), SWB_BWE_LR_QRk); - L_THR3 = L_shl(L_deposit_l(THR3), SWB_BWE_LR_QRk); - - /* Init Rk to non-zero values for bands to be allocated bits */ - IF(LE_16(num_bits, HQ_16k40_BIT)) - { - set32_fx(L_Rk, (Word32)(C1_QRk), bands); /* 1< 0) - { - L_Ravg = L_add(L_Ravg, L_shl(L_band_energy[k], sub(SWB_BWE_LR_QRk, SWB_BWE_LR_Qbe))); /* SWB_BWE_LR_QRk-SWB_BWE_LR_Qbe */ - Rcnt_fx = add(Rcnt_fx, 1); - } - } - /* Ravg Qband_energy */ - - /*L_Ravg /= Rcnt; */ - exp_normd = norm_l(L_Ravg); - exp_normd = sub(exp_normd, 1); - exp_normn = norm_s(Rcnt_fx); - - tmp = shl(Rcnt_fx, exp_normn); - tmp = s_max(tmp, 1); - IF(L_Ravg > 0) - { - div_fx = div_l(L_shl(L_Ravg, exp_normd), tmp); /* Qdiv = 14+exp_normd-(exp_normn)-1 */ - } - ELSE - { - div_fx = div_l(L_shl(L_abs(L_Ravg), exp_normd), tmp); /* Qdiv = 14+exp_normd-(exp_normn)-1 */ - div_fx = negate(div_fx); - } - - Qdiv = sub(sub(add(SWB_BWE_LR_QRk, exp_normd), exp_normn), 1); - - L_Ravg = L_shr(L_deposit_l(div_fx), sub(Qdiv, SWB_BWE_LR_QRk)); - - exp_normd = norm_s(*bit_budget_fx); - exp_normd = sub(exp_normd, 1); - bit_budget_norm_fx = shl(*bit_budget_fx, exp_normd); - div_fx = 0; - move16(); - - test(); - IF(bit_budget_norm_fx > 0 && LT_16(bit_budget_norm_fx, tmp)) - { - div_fx = div_s(bit_budget_norm_fx, tmp); - } - Qdiv = add(sub(exp_normd, exp_normn), 15); - FOR(k = 0; k < bands; k++) - { - IF(L_Rk[k] > 0) - { - /*Rk[k] = ((float) *bit_budget / Rcnt + weight * (band_energy[k] - Ravg)); */ - - L_tmp = Mult_32_16(L_sub(L_shl(L_band_energy[k], sub(SWB_BWE_LR_QRk, SWB_BWE_LR_Qbe)), L_Ravg), weight_fx); /* SWB_BWE_LR_QRk + Q13 - 15 */ - L_tmp = L_shl(L_tmp, 2); /* -> SWB_BWE_LR_QRk */ - - L_Rk[k] = L_add(L_shr(L_deposit_l(div_fx), sub(Qdiv, SWB_BWE_LR_QRk)), L_tmp); - move32(); - } - } - - negflag = 0; - move16(); - L_Rcalc = L_deposit_l(0); - FOR(k = 0; k < bands; k++) - { - IF(LT_32(L_Rk[k], MIN_BITS_FIX)) - { - L_Rk[k] = L_deposit_l(0); - negflag = 1; - move16(); - } - L_Rcalc = L_add(L_Rcalc, L_Rk[k]); /*SWB_BWE_LR_QRk */ - } - - /* prune noiselike bands with low allocation */ - test(); - IF(LE_16(num_bits, HQ_16k40_BIT) && negflag == 0) - { - L_maxxy = L_deposit_l(0); - maxdex_fx = -1; - move16(); - L_Rcalc = L_deposit_l(0); - - /* find worst under-allocation */ - FOR(k = sub(bands, 1); k >= 0; k--) - { - tmp_fx = s_min(band_width[k], s_max(12, shr(band_width[k], 2))); - L_dummy = L_sub(L_shl(L_deposit_l(tmp_fx), SWB_BWE_LR_QRk), L_Rk[k]); /*SWB_BWE_LR_QRk */ - test(); - test(); - IF(p2a_flags[k] == 0 && GT_32(L_dummy, L_maxxy) && L_Rk[k] > 0) - { - maxdex_fx = k; - move16(); - L_maxxy = L_dummy; /*SWB_BWE_LR_QRk */ - move32(); - } - } - - /* prune worst allocation and recalculate total allocation */ - if (GT_16(maxdex_fx, -1)) - { - L_Rk[maxdex_fx] = L_deposit_l(0); - } - FOR(k = 0; k < bands; k++) - { - L_Rcalc = L_add(L_Rcalc, L_Rk[k]); /*SWB_BWE_LR_QRk */ - } - } - test(); - test(); - IF(EQ_32(L_Rcalc, L_Rcalc1) && EQ_16(bwidth, SWB)) - { - /* Reallocate bits to individual subbands for HQ_NORMAL mode */ - /* if bits allocated to subbands areless than predefined threshold */ - test(); - IF(EQ_16(hqswb_clas, HQ_NORMAL) && LT_16(num_bits, HQ_16k40_BIT)) - { - L_dummy = L_deposit_l(0); - FOR(k = 0; k < bands; k++) - { - test(); - test(); - test(); - test(); - test(); - IF(LT_16(k, 11) && LT_32(L_Rk[k], L_THR1)) - { - L_Rk[k] = L_deposit_l(0); - } - ELSE IF(GE_16(k, 11) && LT_16(k, 16) && LT_32(L_Rk[k], L_THR2)) - { - L_Rk[k] = L_deposit_l(0); - } - ELSE if (GE_16(k, 16) && LT_16(k, bands) && LT_32(L_Rk[k], L_THR3)) - { - L_Rk[k] = L_deposit_l(0); - } - - L_dummy = L_add(L_dummy, L_Rk[k]); - } - - IF(EQ_32(L_dummy, L_Rcalc)) - { - test(); - IF(EQ_16(hqswb_clas, HQ_NORMAL) && LT_16(num_bits, HQ_16k40_BIT)) - { - bit_budget_temp_fx = *bit_budget_fx; - move16(); - FOR(k = 0; k < NB_SWB_SUBBANDS; k++) - { - test(); - IF(p2a_flags[bands - NB_SWB_SUBBANDS + k] == 1 && L_Rk[bands - NB_SWB_SUBBANDS + k] == 0) - { - p2a_flags[bands - NB_SWB_SUBBANDS + k] = 0; - move16(); - bit_budget_temp_fx = sub(bit_budget_temp_fx, bits_lagIndices_modeNormal[k]); - } - } - - IF(LT_16(bit_budget_temp_fx, *bit_budget_fx)) - { - *bit_budget_fx = bit_budget_temp_fx; - move16(); - /* a negative *bit_budget_fx may occur here due to Bit Errors */ - /* handled outside this function to properly set flag: st_fx->BER_detect */ - } - ELSE IF(EQ_16(bit_budget_temp_fx, *bit_budget_fx)) - { - BREAK; - } - } - ELSE - { - BREAK; - } - } - } - ELSE - { - BREAK; - } - } - ELSE IF(EQ_32(L_Rcalc, L_Rcalc1) && NE_16(bwidth, SWB)) - { - BREAK; - } - - L_Rcalc1 = L_Rcalc; - move32(); - - } - - return L_Rcalc; + Word16 j, k; + Word16 tmp; + Word16 bit_budget_norm_fx; + + Word32 L_Rcalc, L_Ravg, L_Rcalc1; + + Word16 exp_normn, exp_normd; + + Word16 Rcnt_fx; + + Word16 div_fx; + Word16 Qdiv; + + Word32 L_tmp; + Word16 tmp_fx; + + Word32 L_maxxy; + Word16 maxdex_fx; + Word32 L_dummy; + + Word16 bit_budget_temp_fx; + + Word16 negflag; + + Word32 L_THR1, L_THR2, L_THR3; + + L_THR1 = L_shl( L_deposit_l( THR1 ), SWB_BWE_LR_QRk ); + L_THR2 = L_shl( L_deposit_l( THR2 ), SWB_BWE_LR_QRk ); + L_THR3 = L_shl( L_deposit_l( THR3 ), SWB_BWE_LR_QRk ); + + /* Init Rk to non-zero values for bands to be allocated bits */ + IF( LE_16( num_bits, HQ_16k40_BIT ) ) + { + set32_fx( L_Rk, (Word32) ( C1_QRk ), bands ); /* 1< 0 ) + { + L_Ravg = L_add( L_Ravg, L_shl( L_band_energy[k], sub( SWB_BWE_LR_QRk, SWB_BWE_LR_Qbe ) ) ); /* SWB_BWE_LR_QRk-SWB_BWE_LR_Qbe */ + Rcnt_fx = add( Rcnt_fx, 1 ); + } + } + /* Ravg Qband_energy */ + + /*L_Ravg /= Rcnt; */ + exp_normd = norm_l( L_Ravg ); + exp_normd = sub( exp_normd, 1 ); + exp_normn = norm_s( Rcnt_fx ); + + tmp = shl( Rcnt_fx, exp_normn ); + tmp = s_max( tmp, 1 ); + IF( L_Ravg > 0 ) + { + div_fx = div_l( L_shl( L_Ravg, exp_normd ), tmp ); /* Qdiv = 14+exp_normd-(exp_normn)-1 */ + } + ELSE + { + div_fx = div_l( L_shl( L_abs( L_Ravg ), exp_normd ), tmp ); /* Qdiv = 14+exp_normd-(exp_normn)-1 */ + div_fx = negate( div_fx ); + } + + Qdiv = sub( sub( add( SWB_BWE_LR_QRk, exp_normd ), exp_normn ), 1 ); + + L_Ravg = L_shr( L_deposit_l( div_fx ), sub( Qdiv, SWB_BWE_LR_QRk ) ); + + exp_normd = norm_s( *bit_budget_fx ); + exp_normd = sub( exp_normd, 1 ); + bit_budget_norm_fx = shl( *bit_budget_fx, exp_normd ); + div_fx = 0; + move16(); + + test(); + IF( bit_budget_norm_fx > 0 && LT_16( bit_budget_norm_fx, tmp ) ) + { + div_fx = div_s( bit_budget_norm_fx, tmp ); + } + Qdiv = add( sub( exp_normd, exp_normn ), 15 ); + FOR( k = 0; k < bands; k++ ) + { + IF( L_Rk[k] > 0 ) + { + /*Rk[k] = ((float) *bit_budget / Rcnt + weight * (band_energy[k] - Ravg)); */ + + L_tmp = Mult_32_16( L_sub( L_shl( L_band_energy[k], sub( SWB_BWE_LR_QRk, SWB_BWE_LR_Qbe ) ), L_Ravg ), weight_fx ); /* SWB_BWE_LR_QRk + Q13 - 15 */ + L_tmp = L_shl( L_tmp, 2 ); /* -> SWB_BWE_LR_QRk */ + + L_Rk[k] = L_add( L_shr( L_deposit_l( div_fx ), sub( Qdiv, SWB_BWE_LR_QRk ) ), L_tmp ); + move32(); + } + } + + negflag = 0; + move16(); + L_Rcalc = L_deposit_l( 0 ); + FOR( k = 0; k < bands; k++ ) + { + IF( LT_32( L_Rk[k], MIN_BITS_FIX ) ) + { + L_Rk[k] = L_deposit_l( 0 ); + negflag = 1; + move16(); + } + L_Rcalc = L_add( L_Rcalc, L_Rk[k] ); /*SWB_BWE_LR_QRk */ + } + + /* prune noiselike bands with low allocation */ + test(); + IF( LE_16( num_bits, HQ_16k40_BIT ) && negflag == 0 ) + { + L_maxxy = L_deposit_l( 0 ); + maxdex_fx = -1; + move16(); + L_Rcalc = L_deposit_l( 0 ); + + /* find worst under-allocation */ + FOR( k = sub( bands, 1 ); k >= 0; k-- ) + { + tmp_fx = s_min( band_width[k], s_max( 12, shr( band_width[k], 2 ) ) ); + L_dummy = L_sub( L_shl( L_deposit_l( tmp_fx ), SWB_BWE_LR_QRk ), L_Rk[k] ); /*SWB_BWE_LR_QRk */ + test(); + test(); + IF( p2a_flags[k] == 0 && GT_32( L_dummy, L_maxxy ) && L_Rk[k] > 0 ) + { + maxdex_fx = k; + move16(); + L_maxxy = L_dummy; /*SWB_BWE_LR_QRk */ + move32(); + } + } + + /* prune worst allocation and recalculate total allocation */ + if ( GT_16( maxdex_fx, -1 ) ) + { + L_Rk[maxdex_fx] = L_deposit_l( 0 ); + } + FOR( k = 0; k < bands; k++ ) + { + L_Rcalc = L_add( L_Rcalc, L_Rk[k] ); /*SWB_BWE_LR_QRk */ + } + } + test(); + test(); + IF( EQ_32( L_Rcalc, L_Rcalc1 ) && EQ_16( bwidth, SWB ) ) + { + /* Reallocate bits to individual subbands for HQ_NORMAL mode */ + /* if bits allocated to subbands areless than predefined threshold */ + test(); + IF( EQ_16( hqswb_clas, HQ_NORMAL ) && LT_16( num_bits, HQ_16k40_BIT ) ) + { + L_dummy = L_deposit_l( 0 ); + FOR( k = 0; k < bands; k++ ) + { + test(); + test(); + test(); + test(); + test(); + IF( LT_16( k, 11 ) && LT_32( L_Rk[k], L_THR1 ) ) + { + L_Rk[k] = L_deposit_l( 0 ); + } + ELSE IF( GE_16( k, 11 ) && LT_16( k, 16 ) && LT_32( L_Rk[k], L_THR2 ) ) + { + L_Rk[k] = L_deposit_l( 0 ); + } + ELSE if ( GE_16( k, 16 ) && LT_16( k, bands ) && LT_32( L_Rk[k], L_THR3 ) ) + { + L_Rk[k] = L_deposit_l( 0 ); + } + + L_dummy = L_add( L_dummy, L_Rk[k] ); + } + + IF( EQ_32( L_dummy, L_Rcalc ) ) + { + test(); + IF( EQ_16( hqswb_clas, HQ_NORMAL ) && LT_16( num_bits, HQ_16k40_BIT ) ) + { + bit_budget_temp_fx = *bit_budget_fx; + move16(); + FOR( k = 0; k < NB_SWB_SUBBANDS; k++ ) + { + test(); + IF( p2a_flags[bands - NB_SWB_SUBBANDS + k] == 1 && L_Rk[bands - NB_SWB_SUBBANDS + k] == 0 ) + { + p2a_flags[bands - NB_SWB_SUBBANDS + k] = 0; + move16(); + bit_budget_temp_fx = sub( bit_budget_temp_fx, bits_lagIndices_modeNormal[k] ); + } + } + + IF( LT_16( bit_budget_temp_fx, *bit_budget_fx ) ) + { + *bit_budget_fx = bit_budget_temp_fx; + move16(); + /* a negative *bit_budget_fx may occur here due to Bit Errors */ + /* handled outside this function to properly set flag: st_fx->BER_detect */ + } + ELSE IF( EQ_16( bit_budget_temp_fx, *bit_budget_fx ) ) + { + BREAK; + } + } + ELSE + { + BREAK; + } + } + } + ELSE + { + BREAK; + } + } + ELSE IF( EQ_32( L_Rcalc, L_Rcalc1 ) && NE_16( bwidth, SWB ) ) + { + BREAK; + } + + L_Rcalc1 = L_Rcalc; + move32(); + } + + return L_Rcalc; } - diff --git a/lib_com/hq2_core_com_fx.c b/lib_com/hq2_core_com_fx.c index 9f7a5661b..c649e8d17 100644 --- a/lib_com/hq2_core_com_fx.c +++ b/lib_com/hq2_core_com_fx.c @@ -33,193 +33,192 @@ #include #include "options.h" -#include "cnst.h" /* Audio core constants */ -#include "rom_com.h" /* Static table prototypes */ +#include "cnst.h" /* Audio core constants */ +#include "rom_com.h" /* Static table prototypes */ #include "prot_fx2.h" - - /*--------------------------------------------------------------------------* - * mdct_spectrum_denorm() - * - * - *--------------------------------------------------------------------------*/ +/*--------------------------------------------------------------------------* + * mdct_spectrum_denorm() + * + * + *--------------------------------------------------------------------------*/ void mdct_spectrum_denorm_fx( - const Word16 inp_vector[], /* i : Q0 : */ - Word32 L_y2[], /* i/o : Qs : decoded spectrum */ - const Word16 band_start[], /* i : Q0 : table of start freq for every subband */ - const Word16 band_end[], /* i : Q0 : table of end freq for every subband */ - const Word16 band_width[], /* i : Q0 : table of bandwidth for every subband */ - const Word32 L_band_energy[], /* i : Qbe : band energy */ - const Word16 npulses[], /* i : Q0 : number of coded spectrum */ - const Word16 bands, /* i : Q0 : number of subbands */ - const Word16 ld_slope_fx, /* i : Q15 : */ - const Word16 pd_thresh_fx /* i : Q15 : */ + const Word16 inp_vector[], /* i : Q0 : */ + Word32 L_y2[], /* i/o : Qs : decoded spectrum */ + const Word16 band_start[], /* i : Q0 : table of start freq for every subband */ + const Word16 band_end[], /* i : Q0 : table of end freq for every subband */ + const Word16 band_width[], /* i : Q0 : table of bandwidth for every subband */ + const Word32 L_band_energy[], /* i : Qbe : band energy */ + const Word16 npulses[], /* i : Q0 : number of coded spectrum */ + const Word16 bands, /* i : Q0 : number of subbands */ + const Word16 ld_slope_fx, /* i : Q15 : */ + const Word16 pd_thresh_fx /* i : Q15 : */ ) { - Word16 i, k; - Word32 L_Eyy; - Word32 L_tmp, L_temp; - Word16 temp_fx, temp_lo_fx, temp_hi_fx; - Word32 L_inp_tmp[L_FRAME48k]; - Word16 exp_norm; - Word16 exp_safe; - Word16 exp_normn, exp_normd; + Word16 i, k; + Word32 L_Eyy; + Word32 L_tmp, L_temp; + Word16 temp_fx, temp_lo_fx, temp_hi_fx; + Word32 L_inp_tmp[L_FRAME48k]; + Word16 exp_norm; + Word16 exp_safe; + Word16 exp_normn, exp_normd; - Word16 pd_fx; - Word16 Qpd; + Word16 pd_fx; + Word16 Qpd; - Word16 div_pd_fx; - Word16 Qdivpd; - Word32 L_div_pd; + Word16 div_pd_fx; + Word16 Qdivpd; + Word32 L_div_pd; - Word16 frac, exp; + Word16 frac, exp; - Word16 gain_tweak_fx; - Word16 Qtweak; + Word16 gain_tweak_fx; + Word16 Qtweak; - Word16 exp_shift; + Word16 exp_shift; - Word16 QEyy; - Word16 pow_fx; - Word16 Qpow; - Word16 Qdiv; - Word16 Qgamma; - Word16 gamma_fx; + Word16 QEyy; + Word16 pow_fx; + Word16 Qpow; + Word16 Qdiv; + Word16 Qgamma; + Word16 gamma_fx; - Word16 cond_fx; + Word16 cond_fx; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; + Flag Overflow = 0; #endif - exp_safe = 4; /* safe bit for overflow */ - - FOR(k = 0; k < bands; k++) - { - L_tmp = L_deposit_l(0); - FOR(i = band_start[k]; i <= band_end[k]; i++) - { - L_inp_tmp[i] = L_mult(inp_vector[i], inp_vector[i]); - move32(); /* Q0+Q0+1 */ - L_tmp = L_or(L_tmp, L_inp_tmp[i]); - } - exp_norm = norm_l(L_tmp); - exp_norm = sub(exp_norm, exp_safe); - - L_Eyy = L_deposit_l(0); - FOR(i = band_start[k]; i <= band_end[k]; i++) - { - /*Eyy += (float) inp_vector[i] * inp_vector[i]; */ - L_Eyy = L_add(L_Eyy, L_shl(L_inp_tmp[i], exp_norm)); /* Q1+exp_norm */ - } - QEyy = add(1, exp_norm); - - IF(L_Eyy > 0x0L) - { - /* Set gamma to be pulse gain which results in perfect quantized subband energy */ - /*gamma = (float) sqrt (pow (2.0f, band_energy[k]) / Eyy); */ - - /* Pow part (pow(2.0f, band_energy) ) */ - L_temp = L_shr(L_band_energy[k], sub(SWB_BWE_LR_Qbe, 16)); - temp_lo_fx = L_Extract_lc(L_temp, &temp_hi_fx); - Qpow = sub(14, temp_hi_fx); - pow_fx = extract_l(Pow2(14, temp_lo_fx)); /* Qpow */ - - /* Div part ( pow (2.0f, band_energy[i])/Eyy ) */ - exp_normn = norm_s(pow_fx); - exp_normn = sub(exp_normn, 1); - exp_normd = norm_l(L_Eyy); - temp_fx = div_s(shl(pow_fx, exp_normn), extract_h(L_shl(L_Eyy, exp_normd))); - Qdiv = add(sub(add(Qpow, exp_normn), add(QEyy, exp_normd)), 31); - - exp_norm = norm_s(temp_fx); - temp_fx = shl(temp_fx, exp_norm); - Qdiv = add(Qdiv, exp_norm); - - /* Sqrt part sqrt(pow (2.0f, band_energy[i])/Eyy) */ - Qgamma = add(Qdiv, 16); - IF(s_and(Qdiv, 1) == 0) /* Qdiv % 2 == 0 */ - { - L_temp = Sqrt_l(L_shr(L_deposit_h(temp_fx), 1), &exp_norm); - L_temp = L_shr(L_temp, exp_norm); - Qgamma = sub(shr(Qgamma, 1), 1); - gamma_fx = round_fx(L_temp); - } - ELSE - { - L_temp = Sqrt_l(L_deposit_h(temp_fx), &exp_norm); - L_temp = L_shr(L_temp, exp_norm); - Qgamma = shr(Qgamma, 1); - gamma_fx = round_fx(L_temp); - } - - /* Adjust gamma based on pulse density (0 bit MSE gain estimator) */ - /*pd = (float) npulses[k] / band_width[k]; */ - exp_normn = norm_s(npulses[k]); - exp_normn = sub(exp_normn, 1); - exp_normd = norm_s(band_width[k]); - pd_fx = div_s(shl(npulses[k], exp_normn), shl(band_width[k], exp_normd)); - Qpd = add(sub(exp_normn, exp_normd), 15); + exp_safe = 4; /* safe bit for overflow */ + + FOR( k = 0; k < bands; k++ ) + { + L_tmp = L_deposit_l( 0 ); + FOR( i = band_start[k]; i <= band_end[k]; i++ ) + { + L_inp_tmp[i] = L_mult( inp_vector[i], inp_vector[i] ); + move32(); /* Q0+Q0+1 */ + L_tmp = L_or( L_tmp, L_inp_tmp[i] ); + } + exp_norm = norm_l( L_tmp ); + exp_norm = sub( exp_norm, exp_safe ); + + L_Eyy = L_deposit_l( 0 ); + FOR( i = band_start[k]; i <= band_end[k]; i++ ) + { + /*Eyy += (float) inp_vector[i] * inp_vector[i]; */ + L_Eyy = L_add( L_Eyy, L_shl( L_inp_tmp[i], exp_norm ) ); /* Q1+exp_norm */ + } + QEyy = add( 1, exp_norm ); + + IF( L_Eyy > 0x0L ) + { + /* Set gamma to be pulse gain which results in perfect quantized subband energy */ + /*gamma = (float) sqrt (pow (2.0f, band_energy[k]) / Eyy); */ + + /* Pow part (pow(2.0f, band_energy) ) */ + L_temp = L_shr( L_band_energy[k], sub( SWB_BWE_LR_Qbe, 16 ) ); + temp_lo_fx = L_Extract_lc( L_temp, &temp_hi_fx ); + Qpow = sub( 14, temp_hi_fx ); + pow_fx = extract_l( Pow2( 14, temp_lo_fx ) ); /* Qpow */ + + /* Div part ( pow (2.0f, band_energy[i])/Eyy ) */ + exp_normn = norm_s( pow_fx ); + exp_normn = sub( exp_normn, 1 ); + exp_normd = norm_l( L_Eyy ); + temp_fx = div_s( shl( pow_fx, exp_normn ), extract_h( L_shl( L_Eyy, exp_normd ) ) ); + Qdiv = add( sub( add( Qpow, exp_normn ), add( QEyy, exp_normd ) ), 31 ); + + exp_norm = norm_s( temp_fx ); + temp_fx = shl( temp_fx, exp_norm ); + Qdiv = add( Qdiv, exp_norm ); + + /* Sqrt part sqrt(pow (2.0f, band_energy[i])/Eyy) */ + Qgamma = add( Qdiv, 16 ); + IF( s_and( Qdiv, 1 ) == 0 ) /* Qdiv % 2 == 0 */ + { + L_temp = Sqrt_l( L_shr( L_deposit_h( temp_fx ), 1 ), &exp_norm ); + L_temp = L_shr( L_temp, exp_norm ); + Qgamma = sub( shr( Qgamma, 1 ), 1 ); + gamma_fx = round_fx( L_temp ); + } + ELSE + { + L_temp = Sqrt_l( L_deposit_h( temp_fx ), &exp_norm ); + L_temp = L_shr( L_temp, exp_norm ); + Qgamma = shr( Qgamma, 1 ); + gamma_fx = round_fx( L_temp ); + } + + /* Adjust gamma based on pulse density (0 bit MSE gain estimator) */ + /*pd = (float) npulses[k] / band_width[k]; */ + exp_normn = norm_s( npulses[k] ); + exp_normn = sub( exp_normn, 1 ); + exp_normd = norm_s( band_width[k] ); + pd_fx = div_s( shl( npulses[k], exp_normn ), shl( band_width[k], exp_normd ) ); + Qpd = add( sub( exp_normn, exp_normd ), 15 ); #ifdef BASOP_NOGLOB - cond_fx = sub(shl_o(pd_fx, sub(15, Qpd), &Overflow), pd_thresh_fx/*Q15*/); + cond_fx = sub( shl_o( pd_fx, sub( 15, Qpd ), &Overflow ), pd_thresh_fx /*Q15*/ ); #else /* BASOP_NOGLOB */ - cond_fx = sub(shl(pd_fx, sub(15, Qpd)), pd_thresh_fx/*Q15*/); + cond_fx = sub( shl( pd_fx, sub( 15, Qpd ) ), pd_thresh_fx /*Q15*/ ); #endif - Overflow = 0; - move16(); /* allow overflow happen. */ - IF(cond_fx < 0) - { - /*gain_tweak = (float) pow (2.0f, (ld_slope * log2_f (pd / pd_thresh))); */ - /* Div part */ - exp_normn = norm_s(pd_fx); - exp_normn = sub(exp_normn, 1); - exp_normd = norm_s(pd_thresh_fx); - div_pd_fx = div_s(shl(pd_fx, exp_normn), shl(pd_thresh_fx, exp_normd)); /* Qpd+exp_normn - (15 + exp_normd) + 15 */ - Qdivpd = add(sub(add(Qpd, exp_normn), add(15, exp_normd)), 15); - - /* Log2 part */ - exp_norm = norm_s(div_pd_fx); - L_div_pd = L_deposit_h(shl(div_pd_fx, exp_norm)); - Qdivpd = add(add(Qdivpd, exp_norm), 16); - - frac = Log2_norm_lc(L_div_pd); - exp = sub(30, Qdivpd); - L_tmp = L_Comp(exp, frac); /* Q16 */ - - /* Mult part */ - L_tmp = Mpy_32_16_1(L_tmp, ld_slope_fx); - - /* Pow part */ - temp_lo_fx = L_Extract_lc(L_tmp, &temp_hi_fx); - Qtweak = sub(14, temp_hi_fx); - gain_tweak_fx = extract_l(Pow2(14, temp_lo_fx)); - - /*gamma *= gain_tweak; */ - L_tmp = L_mult(gamma_fx, gain_tweak_fx); /* Qgamma+Qtweak+1 */ - exp_norm = norm_l(L_tmp); + Overflow = 0; + move16(); /* allow overflow happen. */ + IF( cond_fx < 0 ) + { + /*gain_tweak = (float) pow (2.0f, (ld_slope * log2_f (pd / pd_thresh))); */ + /* Div part */ + exp_normn = norm_s( pd_fx ); + exp_normn = sub( exp_normn, 1 ); + exp_normd = norm_s( pd_thresh_fx ); + div_pd_fx = div_s( shl( pd_fx, exp_normn ), shl( pd_thresh_fx, exp_normd ) ); /* Qpd+exp_normn - (15 + exp_normd) + 15 */ + Qdivpd = add( sub( add( Qpd, exp_normn ), add( 15, exp_normd ) ), 15 ); + + /* Log2 part */ + exp_norm = norm_s( div_pd_fx ); + L_div_pd = L_deposit_h( shl( div_pd_fx, exp_norm ) ); + Qdivpd = add( add( Qdivpd, exp_norm ), 16 ); + + frac = Log2_norm_lc( L_div_pd ); + exp = sub( 30, Qdivpd ); + L_tmp = L_Comp( exp, frac ); /* Q16 */ + + /* Mult part */ + L_tmp = Mpy_32_16_1( L_tmp, ld_slope_fx ); + + /* Pow part */ + temp_lo_fx = L_Extract_lc( L_tmp, &temp_hi_fx ); + Qtweak = sub( 14, temp_hi_fx ); + gain_tweak_fx = extract_l( Pow2( 14, temp_lo_fx ) ); + + /*gamma *= gain_tweak; */ + L_tmp = L_mult( gamma_fx, gain_tweak_fx ); /* Qgamma+Qtweak+1 */ + exp_norm = norm_l( L_tmp ); #ifdef BASOP_NOGLOB - gamma_fx = round_fx_o(L_shl_o(L_tmp, exp_norm, &Overflow), &Overflow); + gamma_fx = round_fx_o( L_shl_o( L_tmp, exp_norm, &Overflow ), &Overflow ); #else - gamma_fx = round_fx(L_shl(L_tmp, exp_norm)); + gamma_fx = round_fx( L_shl( L_tmp, exp_norm ) ); #endif - Qgamma = sub(add(add(Qgamma, Qtweak), exp_norm), 15);/*Qgamma+Qtweak+1+exp_norm-16; */ - } - - exp_shift = sub(SWB_BWE_LR_Qs - 1, Qgamma); - FOR(i = band_start[k]; i <= band_end[k]; i++) - { - /*y2[i] = gamma * inp_vector[i]; */ - L_tmp = L_mult(gamma_fx, (Word16)inp_vector[i]); /* Qgamma+0+1=Qgamma+1 */ - L_y2[i] = L_shl(L_tmp, exp_shift); - move32(); - } - } - } - - return; + Qgamma = sub( add( add( Qgamma, Qtweak ), exp_norm ), 15 ); /*Qgamma+Qtweak+1+exp_norm-16; */ + } + + exp_shift = sub( SWB_BWE_LR_Qs - 1, Qgamma ); + FOR( i = band_start[k]; i <= band_end[k]; i++ ) + { + /*y2[i] = gamma * inp_vector[i]; */ + L_tmp = L_mult( gamma_fx, (Word16) inp_vector[i] ); /* Qgamma+0+1=Qgamma+1 */ + L_y2[i] = L_shl( L_tmp, exp_shift ); + move32(); + } + } + } + + return; } /*==========================================================================*/ /* FUNCTION : void hq2_core_configure_fx() */ @@ -246,198 +245,195 @@ void mdct_spectrum_denorm_fx( /*==========================================================================*/ void hq2_core_configure_fx( - const Word16 frame_length, - const Word16 num_bits, - const Word16 is_transient, - Word16 *bands, - Word16 *length, - Word16 band_width[], - Word16 band_start[], - Word16 band_end[], - Word32 *L_qint, - Word16 *eref, - Word16 *bit_alloc_weight, - Word16 *gqlevs, - Word16 *Ngq, - Word16 *p2a_bands, - Word16 *p2a_th, - Word16 *pd_thresh, - Word16 *ld_slope, - Word16 *ni_coef, - Word32 L_bwe_br -) + const Word16 frame_length, + const Word16 num_bits, + const Word16 is_transient, + Word16 *bands, + Word16 *length, + Word16 band_width[], + Word16 band_start[], + Word16 band_end[], + Word32 *L_qint, + Word16 *eref, + Word16 *bit_alloc_weight, + Word16 *gqlevs, + Word16 *Ngq, + Word16 *p2a_bands, + Word16 *p2a_th, + Word16 *pd_thresh, + Word16 *ld_slope, + Word16 *ni_coef, + Word32 L_bwe_br ) +{ + const Xcore_Config *xcore_config_fx; + + Word16 i, k; + Word16 bands_sh; + + xcore_config_fx = &xcore_config_32kHz_013200bps_long; /* default set for VC Warning */ + + IF( EQ_16( frame_length, L_FRAME8k ) ) + { + IF( is_transient ) + { + IF( LE_16( num_bits, ACELP_7k20 / FRAMES_PER_SEC ) ) + { + xcore_config_fx = &xcore_config_8kHz_007200bps_short; + } + ELSE IF( LE_16( num_bits, ACELP_8k00 / FRAMES_PER_SEC ) ) + { + xcore_config_fx = &xcore_config_8kHz_008000bps_short; + } + ELSE IF( LE_16( num_bits, ACELP_13k20 / FRAMES_PER_SEC ) ) + { + xcore_config_fx = &xcore_config_8kHz_013200bps_short; + } + ELSE + { + xcore_config_fx = &xcore_config_8kHz_016400bps_short; + } + } + ELSE + { + IF( LE_16( num_bits, ACELP_7k20 / FRAMES_PER_SEC ) ) + { + xcore_config_fx = &xcore_config_8kHz_007200bps_long; + } + ELSE IF( LE_16( num_bits, ACELP_8k00 / FRAMES_PER_SEC ) ) + { + xcore_config_fx = &xcore_config_8kHz_008000bps_long; + } + ELSE IF( LE_16( num_bits, ACELP_13k20 / FRAMES_PER_SEC ) ) + { + xcore_config_fx = &xcore_config_8kHz_013200bps_long; + } + ELSE + { + xcore_config_fx = &xcore_config_8kHz_016400bps_long; + } + } + } + ELSE IF( EQ_16( frame_length, L_FRAME16k ) ) + { + IF( is_transient ) + { + IF( LE_16( num_bits, ACELP_13k20 / FRAMES_PER_SEC ) ) + { + xcore_config_fx = &xcore_config_16kHz_013200bps_short; + move16(); + } + ELSE if ( LE_16( num_bits, ACELP_16k40 / FRAMES_PER_SEC ) ) + { + xcore_config_fx = &xcore_config_16kHz_016400bps_short; + move16(); + } + } + ELSE + { + IF( LE_16( num_bits, ACELP_13k20 / FRAMES_PER_SEC ) ) + { + xcore_config_fx = &xcore_config_16kHz_013200bps_long; + move16(); + } + ELSE if ( LE_16( num_bits, ACELP_16k40 / FRAMES_PER_SEC ) ) + { + xcore_config_fx = &xcore_config_16kHz_016400bps_long; + move16(); + } + } + } + ELSE /* (frame_length == SWB) */ + { + IF( is_transient ){ + IF( LE_32( L_bwe_br, ACELP_13k20 ) ){ + xcore_config_fx = &xcore_config_32kHz_013200bps_short; + move16(); +} +ELSE if ( LE_32( L_bwe_br, ACELP_16k40 ) ) +{ + xcore_config_fx = &xcore_config_32kHz_016400bps_short; + move16(); +} +} +ELSE { - const Xcore_Config *xcore_config_fx; - - Word16 i, k; - Word16 bands_sh; - - xcore_config_fx = &xcore_config_32kHz_013200bps_long; /* default set for VC Warning */ - - IF(EQ_16(frame_length, L_FRAME8k)) - { - IF(is_transient) - { - IF(LE_16(num_bits, ACELP_7k20 / FRAMES_PER_SEC)) - { - xcore_config_fx = &xcore_config_8kHz_007200bps_short; - } - ELSE IF(LE_16(num_bits, ACELP_8k00 / FRAMES_PER_SEC)) - { - xcore_config_fx = &xcore_config_8kHz_008000bps_short; - } - ELSE IF(LE_16(num_bits, ACELP_13k20 / FRAMES_PER_SEC)) - { - xcore_config_fx = &xcore_config_8kHz_013200bps_short; - } - ELSE - { - xcore_config_fx = &xcore_config_8kHz_016400bps_short; - } - } - ELSE - { - IF(LE_16(num_bits, ACELP_7k20 / FRAMES_PER_SEC)) - { - xcore_config_fx = &xcore_config_8kHz_007200bps_long; - } - ELSE IF(LE_16(num_bits, ACELP_8k00 / FRAMES_PER_SEC)) - { - xcore_config_fx = &xcore_config_8kHz_008000bps_long; - } - ELSE IF(LE_16(num_bits, ACELP_13k20 / FRAMES_PER_SEC)) - { - xcore_config_fx = &xcore_config_8kHz_013200bps_long; - } - ELSE - { - xcore_config_fx = &xcore_config_8kHz_016400bps_long; - } - } - } - ELSE IF(EQ_16(frame_length, L_FRAME16k)) - { - IF(is_transient) - { - IF(LE_16(num_bits, ACELP_13k20 / FRAMES_PER_SEC)) - { - xcore_config_fx = &xcore_config_16kHz_013200bps_short; - move16(); - } - ELSE if (LE_16(num_bits, ACELP_16k40 / FRAMES_PER_SEC)) - { - xcore_config_fx = &xcore_config_16kHz_016400bps_short; - move16(); - } - } - ELSE - { - IF(LE_16(num_bits, ACELP_13k20 / FRAMES_PER_SEC)) - { - xcore_config_fx = &xcore_config_16kHz_013200bps_long; - move16(); - } - ELSE if (LE_16(num_bits, ACELP_16k40 / FRAMES_PER_SEC)) - { - xcore_config_fx = &xcore_config_16kHz_016400bps_long; - move16(); - } - } - } - ELSE /* (frame_length == SWB) */ - { - IF(is_transient) - { - IF(LE_32(L_bwe_br, ACELP_13k20)) - { - xcore_config_fx = &xcore_config_32kHz_013200bps_short; - move16(); - } - ELSE if (LE_32(L_bwe_br, ACELP_16k40)) - { - xcore_config_fx = &xcore_config_32kHz_016400bps_short; - move16(); - } - } - ELSE - { - IF(LE_32(L_bwe_br, ACELP_13k20)) - { - xcore_config_fx = &xcore_config_32kHz_013200bps_long; - move16(); - } - ELSE if (LE_32(L_bwe_br, ACELP_16k40)) - { - xcore_config_fx = &xcore_config_32kHz_016400bps_long; - move16(); - } - } - } - - *bands = xcore_config_fx->bands; - move16(); - *length = xcore_config_fx->bw; - move16(); - *L_qint = xcore_config_fx->L_qint; - move32(); - - *eref = xcore_config_fx->eref; - move16(); - *bit_alloc_weight = xcore_config_fx->bit_alloc_weight; - move16(); - *gqlevs = xcore_config_fx->gqlevs; - move16(); - *Ngq = xcore_config_fx->Ngq; - move16(); - - *p2a_bands = xcore_config_fx->p2a_bands; - move16(); - *p2a_th = xcore_config_fx->p2a_th; - move16(); - - *pd_thresh = xcore_config_fx->pd_thresh; - move16(); - *ld_slope = xcore_config_fx->ld_slope; - move16(); - *ni_coef = xcore_config_fx->ni_coef; - move16(); - - /*mvs2s_fx (xcore_config_fx->band_width, band_width, *bands); */ - Copy(xcore_config_fx->band_width, band_width, *bands); - - /* Expand band_width[] table for short windows */ - IF(is_transient) - { - bands_sh = *bands; - move16(); - *bands = shl(bands_sh, 2); - *length = shl(*length, 2); - - FOR(i = 1; i <= 3; i++) - { - FOR(k = 0; k < bands_sh; k++) - { - band_width[i * bands_sh + k] = band_width[k]; - move16(); - } - } - } - - /* Formulate band_start and band_end tables from band_width table */ - band_start[0] = 0; - move16(); - band_end[0] = sub(band_width[0], 1); - move16(); - FOR(k = 1; k < *bands; k++) - { - band_start[k] = add(band_start[k - 1], band_width[k - 1]); - move16(); - band_end[k] = sub(add(band_start[k], band_width[k]), 1); - move16(); - } - - - return; + IF( LE_32( L_bwe_br, ACELP_13k20 ) ) + { + xcore_config_fx = &xcore_config_32kHz_013200bps_long; + move16(); + } + ELSE if ( LE_32( L_bwe_br, ACELP_16k40 ) ) + { + xcore_config_fx = &xcore_config_32kHz_016400bps_long; + move16(); + } +} +} + +*bands = xcore_config_fx->bands; +move16(); +*length = xcore_config_fx->bw; +move16(); +*L_qint = xcore_config_fx->L_qint; +move32(); + +*eref = xcore_config_fx->eref; +move16(); +*bit_alloc_weight = xcore_config_fx->bit_alloc_weight; +move16(); +*gqlevs = xcore_config_fx->gqlevs; +move16(); +*Ngq = xcore_config_fx->Ngq; +move16(); + +*p2a_bands = xcore_config_fx->p2a_bands; +move16(); +*p2a_th = xcore_config_fx->p2a_th; +move16(); + +*pd_thresh = xcore_config_fx->pd_thresh; +move16(); +*ld_slope = xcore_config_fx->ld_slope; +move16(); +*ni_coef = xcore_config_fx->ni_coef; +move16(); + +/*mvs2s_fx (xcore_config_fx->band_width, band_width, *bands); */ +Copy( xcore_config_fx->band_width, band_width, *bands ); + +/* Expand band_width[] table for short windows */ +IF( is_transient ) +{ + bands_sh = *bands; + move16(); + *bands = shl( bands_sh, 2 ); + *length = shl( *length, 2 ); + + FOR( i = 1; i <= 3; i++ ) + { + FOR( k = 0; k < bands_sh; k++ ) + { + band_width[i * bands_sh + k] = band_width[k]; + move16(); + } + } +} + +/* Formulate band_start and band_end tables from band_width table */ +band_start[0] = 0; +move16(); +band_end[0] = sub( band_width[0], 1 ); +move16(); +FOR( k = 1; k < *bands; k++ ) +{ + band_start[k] = add( band_start[k - 1], band_width[k - 1] ); + move16(); + band_end[k] = sub( add( band_start[k], band_width[k] ), 1 ); + move16(); +} + + +return; } /*--------------------------------------------------------------------------* @@ -447,52 +443,52 @@ void hq2_core_configure_fx( *--------------------------------------------------------------------------*/ void reverse_transient_frame_energies_fx( - Word32 L_band_energy[], /* o : Q14 : band energies */ - const Word16 bands /* i : Q0 : number of bands */ + Word32 L_band_energy[], /* o : Q14 : band energies */ + const Word16 bands /* i : Q0 : number of bands */ ) { - Word16 k, k1, k2; - Word32 L_be; - Word16 bands_2, bands_4, bands_8; - Word32 *p_be1, *p_be2; - - bands_2 = shr(bands, 1); - bands_4 = shr(bands, 2); - bands_8 = shr(bands, 3); - - k1 = bands_4; - k2 = sub(bands_2, 1); - p_be1 = &L_band_energy[k1]; - p_be2 = &L_band_energy[k2]; - FOR(k = 0; k < bands_8; k++) - { - L_be = *p_be1; - move32(); - *p_be1 = *p_be2; - move32(); - *p_be2 = L_be; - move32(); - p_be1++; - p_be2--; - } - - k1 = sub(bands, bands_4); /* 3*bands/4 */ - k2 = sub(bands, 1); - p_be1 = &L_band_energy[k1]; - p_be2 = &L_band_energy[k2]; - FOR(k = 0; k < bands_8; k++) - { - L_be = *p_be1; - move32(); - *p_be1 = *p_be2; - move32(); - *p_be2 = L_be; - move32(); - p_be1++; - p_be2--; - } - - return; + Word16 k, k1, k2; + Word32 L_be; + Word16 bands_2, bands_4, bands_8; + Word32 *p_be1, *p_be2; + + bands_2 = shr( bands, 1 ); + bands_4 = shr( bands, 2 ); + bands_8 = shr( bands, 3 ); + + k1 = bands_4; + k2 = sub( bands_2, 1 ); + p_be1 = &L_band_energy[k1]; + p_be2 = &L_band_energy[k2]; + FOR( k = 0; k < bands_8; k++ ) + { + L_be = *p_be1; + move32(); + *p_be1 = *p_be2; + move32(); + *p_be2 = L_be; + move32(); + p_be1++; + p_be2--; + } + + k1 = sub( bands, bands_4 ); /* 3*bands/4 */ + k2 = sub( bands, 1 ); + p_be1 = &L_band_energy[k1]; + p_be2 = &L_band_energy[k2]; + FOR( k = 0; k < bands_8; k++ ) + { + L_be = *p_be1; + move32(); + *p_be1 = *p_be2; + move32(); + *p_be2 = L_be; + move32(); + p_be1++; + p_be2--; + } + + return; } @@ -503,79 +499,79 @@ void reverse_transient_frame_energies_fx( *--------------------------------------------------------------------------*/ void spt_shorten_domain_pre_fx( - const Word16 band_start[], /* i: Starting position of sub band */ - const Word16 band_end[], /* i: End position of sub band */ - const Word16 prev_SWB_peak_pos[], /* i: Spectral peak */ - const Word16 BANDS, /* i: total number of bands */ - const Word32 L_bwe_br, /* i: bitrate information */ - Word16 new_band_start[], /* o: Starting position of new shorten sub band */ - Word16 new_band_end[], /* o: End position of new shorten sub band */ - Word16 new_band_width[] /* o: new sub band bandwidth */ + const Word16 band_start[], /* i: Starting position of sub band */ + const Word16 band_end[], /* i: End position of sub band */ + const Word16 prev_SWB_peak_pos[], /* i: Spectral peak */ + const Word16 BANDS, /* i: total number of bands */ + const Word32 L_bwe_br, /* i: bitrate information */ + Word16 new_band_start[], /* o: Starting position of new shorten sub band */ + Word16 new_band_end[], /* o: End position of new shorten sub band */ + Word16 new_band_width[] /* o: new sub band bandwidth */ ) { - Word16 j; - Word16 k; - Word16 kpos; - - Word16 new_band_width_half; - const Word16 *p_bw_SPT_tbl; /* pointer of bw_SPT_tbl */ - - p_bw_SPT_tbl = bw_SPT_tbl[0]; - if (EQ_32(L_bwe_br, HQ_16k40)) - { - p_bw_SPT_tbl = bw_SPT_tbl[1]; - } - - kpos = 0; - j = 0; - move16(); - FOR(k = sub(BANDS, SPT_SHORTEN_SBNUM); k < BANDS; k++) - { - IF(prev_SWB_peak_pos[kpos] != 0) - { - new_band_width[j] = p_bw_SPT_tbl[j]; - - /*shorten the bandwidth for pulse resolution*/ - new_band_width_half = shr(new_band_width[j], 1); - move16(); - new_band_start[j] = sub(prev_SWB_peak_pos[kpos], new_band_width_half); - move16(); - new_band_end[j] = add(prev_SWB_peak_pos[kpos], new_band_width_half); - move16(); - - IF(LT_16(new_band_start[j], band_start[k])) - { - new_band_start[j] = band_start[k]; - move16(); - new_band_end[j] = add(new_band_start[j], sub(new_band_width[j], 1)); - move16(); - } - ELSE IF(GT_16(new_band_end[j], band_end[k])) - { - new_band_end[j] = band_end[k]; - move16(); - new_band_start[j] = sub(new_band_end[j], sub(new_band_width[j], 1)); - move16(); - } - } - ELSE - { - new_band_width[j] = p_bw_SPT_tbl[j]; - - /*shorten the bandwidth for pulse resolution*/ - new_band_width_half = shr(new_band_width[j], 1); - move16(); - new_band_start[j] = sub(shr(add(band_start[k], band_end[k]), 1), new_band_width_half); - move16(); - new_band_end[j] = add(shr(add(band_start[k], band_end[k]), 1), new_band_width_half); - move16(); - } - - kpos = add(kpos, 1); - j = add(j, 1); - } - - return; + Word16 j; + Word16 k; + Word16 kpos; + + Word16 new_band_width_half; + const Word16 *p_bw_SPT_tbl; /* pointer of bw_SPT_tbl */ + + p_bw_SPT_tbl = bw_SPT_tbl[0]; + if ( EQ_32( L_bwe_br, HQ_16k40 ) ) + { + p_bw_SPT_tbl = bw_SPT_tbl[1]; + } + + kpos = 0; + j = 0; + move16(); + FOR( k = sub( BANDS, SPT_SHORTEN_SBNUM ); k < BANDS; k++ ) + { + IF( prev_SWB_peak_pos[kpos] != 0 ) + { + new_band_width[j] = p_bw_SPT_tbl[j]; + + /*shorten the bandwidth for pulse resolution*/ + new_band_width_half = shr( new_band_width[j], 1 ); + move16(); + new_band_start[j] = sub( prev_SWB_peak_pos[kpos], new_band_width_half ); + move16(); + new_band_end[j] = add( prev_SWB_peak_pos[kpos], new_band_width_half ); + move16(); + + IF( LT_16( new_band_start[j], band_start[k] ) ) + { + new_band_start[j] = band_start[k]; + move16(); + new_band_end[j] = add( new_band_start[j], sub( new_band_width[j], 1 ) ); + move16(); + } + ELSE IF( GT_16( new_band_end[j], band_end[k] ) ) + { + new_band_end[j] = band_end[k]; + move16(); + new_band_start[j] = sub( new_band_end[j], sub( new_band_width[j], 1 ) ); + move16(); + } + } + ELSE + { + new_band_width[j] = p_bw_SPT_tbl[j]; + + /*shorten the bandwidth for pulse resolution*/ + new_band_width_half = shr( new_band_width[j], 1 ); + move16(); + new_band_start[j] = sub( shr( add( band_start[k], band_end[k] ), 1 ), new_band_width_half ); + move16(); + new_band_end[j] = add( shr( add( band_start[k], band_end[k] ), 1 ), new_band_width_half ); + move16(); + } + + kpos = add( kpos, 1 ); + j = add( j, 1 ); + } + + return; } /*--------------------------------------------------------------------------* @@ -585,32 +581,32 @@ void spt_shorten_domain_pre_fx( *--------------------------------------------------------------------------*/ void spt_shorten_domain_band_save_fx( - const Word16 bands, /* i: total subband */ - const Word16 band_start[], /* i: starting position of subband */ - const Word16 band_end[], /* i: end position of subband */ - const Word16 band_width[], /* i: band width of subband */ - Word16 org_band_start[], /* o: starting position of subband */ - Word16 org_band_end[], /* o: end position of subband */ - Word16 org_band_width[] /* o: band width of subband */ + const Word16 bands, /* i: total subband */ + const Word16 band_start[], /* i: starting position of subband */ + const Word16 band_end[], /* i: end position of subband */ + const Word16 band_width[], /* i: band width of subband */ + Word16 org_band_start[], /* o: starting position of subband */ + Word16 org_band_end[], /* o: end position of subband */ + Word16 org_band_width[] /* o: band width of subband */ ) { - Word16 k; - Word16 kpos; - - kpos = 0; - move16(); - FOR(k = sub(bands, SPT_SHORTEN_SBNUM); k < bands; k++) - { - org_band_start[kpos] = band_start[k]; - move16(); - org_band_end[kpos] = band_end[k]; - move16(); - org_band_width[kpos] = band_width[k]; - move16(); - kpos = add(kpos, 1); - } - - return; + Word16 k; + Word16 kpos; + + kpos = 0; + move16(); + FOR( k = sub( bands, SPT_SHORTEN_SBNUM ); k < bands; k++ ) + { + org_band_start[kpos] = band_start[k]; + move16(); + org_band_end[kpos] = band_end[k]; + move16(); + org_band_width[kpos] = band_width[k]; + move16(); + kpos = add( kpos, 1 ); + } + + return; } /*--------------------------------------------------------------------------* @@ -620,32 +616,32 @@ void spt_shorten_domain_band_save_fx( *--------------------------------------------------------------------------*/ void spt_shorten_domain_band_restore_fx( - const Word16 bands, /* i: total subband */ - Word16 band_start[], /* i/o: starting position of subband */ - Word16 band_end[], /* i/o: end position of subband */ - Word16 band_width[], /* i/o: band width of subband */ - const Word16 org_band_start[], /* o: starting position of subband */ - const Word16 org_band_end[], /* o: end position of subband */ - const Word16 org_band_width[] /* o: band width of subband */ + const Word16 bands, /* i: total subband */ + Word16 band_start[], /* i/o: starting position of subband */ + Word16 band_end[], /* i/o: end position of subband */ + Word16 band_width[], /* i/o: band width of subband */ + const Word16 org_band_start[], /* o: starting position of subband */ + const Word16 org_band_end[], /* o: end position of subband */ + const Word16 org_band_width[] /* o: band width of subband */ ) { - Word16 k; - Word16 kpos; - - kpos = 0; - move16(); - FOR(k = sub(bands, SPT_SHORTEN_SBNUM); k < bands; k++) - { - band_start[k] = org_band_start[kpos]; - move16(); - band_end[k] = org_band_end[kpos]; - move16(); - band_width[k] = org_band_width[kpos]; - move16(); - kpos = add(kpos, 1); - } - - return; + Word16 k; + Word16 kpos; + + kpos = 0; + move16(); + FOR( k = sub( bands, SPT_SHORTEN_SBNUM ); k < bands; k++ ) + { + band_start[k] = org_band_start[kpos]; + move16(); + band_end[k] = org_band_end[kpos]; + move16(); + band_width[k] = org_band_width[kpos]; + move16(); + kpos = add( kpos, 1 ); + } + + return; } /*--------------------------------------------------------------------------* @@ -655,160 +651,159 @@ void spt_shorten_domain_band_restore_fx( *--------------------------------------------------------------------------*/ void spt_swb_peakpos_tmp_save_fx( - const Word32 L_y2[], /* i: coded spectral information */ - const Word16 bands, /* i: total number of bands */ - const Word16 band_start[], /* i: starting position of subband */ - const Word16 band_end[], /* i: end position of subband */ - Word16 prev_SWB_peak_pos_tmp[] /* o: spectral peaks */ + const Word32 L_y2[], /* i: coded spectral information */ + const Word16 bands, /* i: total number of bands */ + const Word16 band_start[], /* i: starting position of subband */ + const Word16 band_end[], /* i: end position of subband */ + Word16 prev_SWB_peak_pos_tmp[] /* o: spectral peaks */ ) { - Word16 i, j, k; - Word32 L_peak_max; - Word32 L_abs_y2; - - j = 0; - move16(); - FOR(k = sub(bands, SPT_SHORTEN_SBNUM); k < bands; k++) - { - L_peak_max = L_deposit_l(0); - prev_SWB_peak_pos_tmp[j] = 0; - move16(); - FOR(i = band_start[k]; i <= band_end[k]; i++) - { - L_abs_y2 = L_abs(L_y2[i]); - move32(); - IF(LT_32(L_peak_max, L_abs_y2)) - { - L_peak_max = L_abs_y2; - move32(); - prev_SWB_peak_pos_tmp[j] = i; - move16(); - } - } - j = add(j, 1); - } - return; + Word16 i, j, k; + Word32 L_peak_max; + Word32 L_abs_y2; + + j = 0; + move16(); + FOR( k = sub( bands, SPT_SHORTEN_SBNUM ); k < bands; k++ ) + { + L_peak_max = L_deposit_l( 0 ); + prev_SWB_peak_pos_tmp[j] = 0; + move16(); + FOR( i = band_start[k]; i <= band_end[k]; i++ ) + { + L_abs_y2 = L_abs( L_y2[i] ); + move32(); + IF( LT_32( L_peak_max, L_abs_y2 ) ) + { + L_peak_max = L_abs_y2; + move32(); + prev_SWB_peak_pos_tmp[j] = i; + move16(); + } + } + j = add( j, 1 ); + } + return; } -//already present need this one because appropriate and uses basops other than previous one. +// already present need this one because appropriate and uses basops other than previous one. void bit_allocation_second_fx( - Word32 *Rk, - Word32 *Rk_sort, - Word16 BANDS, - const Word16 *band_width, - Word16 *k_sort, - Word16 *k_num, - const Word16 *p2a_flags, - const Word16 p2a_bands, - const Word16 *last_bitalloc, - const Word16 input_frame -) + Word32 *Rk, + Word32 *Rk_sort, + Word16 BANDS, + const Word16 *band_width, + Word16 *k_sort, + Word16 *k_num, + const Word16 *p2a_flags, + const Word16 p2a_bands, + const Word16 *last_bitalloc, + const Word16 input_frame ) { - Word16 k, k2 = 0; - Word16 ever_bits[BANDS_MAX], ever_sort[BANDS_MAX];/*Q12 */ - Word16 class_flag = 0; - Word16 rk_temp = 32767, ever_temp = 32767;/*Q12 */ - Word16 exp; - Word16 tmp; - Word32 L_tmp; - - FOR(k = 0; k < BANDS; k++) - { - test(); - test(); - test(); - IF(((GE_16(k_sort[k], sub(BANDS, p2a_bands))) && (EQ_16(p2a_flags[k_sort[k]], 1))) || - ((GE_16(k_sort[k], sub(BANDS, 2))) && (EQ_16(last_bitalloc[sub(k_sort[k], sub(BANDS, 2))], 1)))) - { - exp = norm_s(band_width[k_sort[k]]); - tmp = shl(band_width[k_sort[k]], exp);/*Q(exp) */ - tmp = div_s(16384, tmp);/*Q(15+14-exp = 29-exp) */ - L_tmp = Mult_32_16(Rk_sort[k], tmp);/* Q(16+29-exp-15 = 30-exp) */ - tmp = sub(18, exp); - ever_bits[k] = extract_l(L_shr(L_tmp, tmp));/*Q12 */ - IF(LT_16(ever_bits[k], rk_temp)) - { - rk_temp = ever_bits[k]; - move16(); - k2 = k; - move16(); - } - class_flag = 1; - } - } - test(); - IF(class_flag == 0 || EQ_16(input_frame, L_FRAME8k)) - { - FOR(k = 0; k < BANDS; k++) - { - test(); - IF(LT_16(k_sort[k], sub(BANDS, p2a_bands)) && Rk_sort[k] > 0) - { - exp = norm_s(band_width[k_sort[k]]); - tmp = shl(band_width[k_sort[k]], exp);/*Q(exp) */ - tmp = div_s(16384, tmp);/*Q(15+14-exp = 29-exp) */ - L_tmp = Mult_32_16(Rk_sort[k], tmp);/* Q(16+29-exp-15 = 30-exp) */ - tmp = sub(18, exp); - ever_sort[k] = extract_l(L_shr(L_tmp, tmp));/*Q12 */ - IF(LT_16(ever_sort[k], ever_temp)) - { - ever_temp = ever_sort[k]; - move16(); - k2 = k; - move16(); - } - } - } - } - - k_num[0] = k2; - IF(EQ_16(k_sort[k2], sub(BANDS, 1))) - { - FOR(k = 0; k < BANDS; k++) - { - if (EQ_16(k_sort[k], sub(k_sort[k2], 1))) - { - k_num[1] = k; - move16(); - } - } - } - ELSE IF(k_sort[k2] == 0) - { - FOR(k = 0; k < BANDS; k++) - { - if (EQ_16(k_sort[k], add(k_sort[k2], 1))) - { - k_num[1] = k; - move16(); - } - } - } - ELSE - { - IF(LT_32(Rk[sub(k_sort[k2],1)],Rk[add(k_sort[k2],1)])) - { - FOR(k = 0; k < BANDS; k++) - { - if (EQ_16(k_sort[k],sub(k_sort[k2],1))) - { - k_num[1] = k; - move16(); - } - } - } - ELSE - { - FOR(k = 0; k < BANDS; k++) - { - if (EQ_16(k_sort[k],add(k_sort[k2],1))) - { - k_num[1] = k; - move16(); - } - } - } - } + Word16 k, k2 = 0; + Word16 ever_bits[BANDS_MAX], ever_sort[BANDS_MAX]; /*Q12 */ + Word16 class_flag = 0; + Word16 rk_temp = 32767, ever_temp = 32767; /*Q12 */ + Word16 exp; + Word16 tmp; + Word32 L_tmp; + + FOR( k = 0; k < BANDS; k++ ) + { + test(); + test(); + test(); + IF( ( ( GE_16( k_sort[k], sub( BANDS, p2a_bands ) ) ) && ( EQ_16( p2a_flags[k_sort[k]], 1 ) ) ) || + ( ( GE_16( k_sort[k], sub( BANDS, 2 ) ) ) && ( EQ_16( last_bitalloc[sub( k_sort[k], sub( BANDS, 2 ) )], 1 ) ) ) ) + { + exp = norm_s( band_width[k_sort[k]] ); + tmp = shl( band_width[k_sort[k]], exp ); /*Q(exp) */ + tmp = div_s( 16384, tmp ); /*Q(15+14-exp = 29-exp) */ + L_tmp = Mult_32_16( Rk_sort[k], tmp ); /* Q(16+29-exp-15 = 30-exp) */ + tmp = sub( 18, exp ); + ever_bits[k] = extract_l( L_shr( L_tmp, tmp ) ); /*Q12 */ + IF( LT_16( ever_bits[k], rk_temp ) ) + { + rk_temp = ever_bits[k]; + move16(); + k2 = k; + move16(); + } + class_flag = 1; + } + } + test(); + IF( class_flag == 0 || EQ_16( input_frame, L_FRAME8k ) ) + { + FOR( k = 0; k < BANDS; k++ ) + { + test(); + IF( LT_16( k_sort[k], sub( BANDS, p2a_bands ) ) && Rk_sort[k] > 0 ) + { + exp = norm_s( band_width[k_sort[k]] ); + tmp = shl( band_width[k_sort[k]], exp ); /*Q(exp) */ + tmp = div_s( 16384, tmp ); /*Q(15+14-exp = 29-exp) */ + L_tmp = Mult_32_16( Rk_sort[k], tmp ); /* Q(16+29-exp-15 = 30-exp) */ + tmp = sub( 18, exp ); + ever_sort[k] = extract_l( L_shr( L_tmp, tmp ) ); /*Q12 */ + IF( LT_16( ever_sort[k], ever_temp ) ) + { + ever_temp = ever_sort[k]; + move16(); + k2 = k; + move16(); + } + } + } + } + + k_num[0] = k2; + IF( EQ_16( k_sort[k2], sub( BANDS, 1 ) ) ) + { + FOR( k = 0; k < BANDS; k++ ) + { + if ( EQ_16( k_sort[k], sub( k_sort[k2], 1 ) ) ) + { + k_num[1] = k; + move16(); + } + } + } + ELSE IF( k_sort[k2] == 0 ) + { + FOR( k = 0; k < BANDS; k++ ) + { + if ( EQ_16( k_sort[k], add( k_sort[k2], 1 ) ) ) + { + k_num[1] = k; + move16(); + } + } + } + ELSE + { + IF( LT_32( Rk[sub( k_sort[k2], 1 )], Rk[add( k_sort[k2], 1 )] ) ) + { + FOR( k = 0; k < BANDS; k++ ) + { + if ( EQ_16( k_sort[k], sub( k_sort[k2], 1 ) ) ) + { + k_num[1] = k; + move16(); + } + } + } + ELSE + { + FOR( k = 0; k < BANDS; k++ ) + { + if ( EQ_16( k_sort[k], add( k_sort[k2], 1 ) ) ) + { + k_num[1] = k; + move16(); + } + } + } + } } diff --git a/lib_com/hq2_noise_inject.c b/lib_com/hq2_noise_inject.c index baca87cae..d7cded1bc 100644 --- a/lib_com/hq2_noise_inject.c +++ b/lib_com/hq2_noise_inject.c @@ -273,5 +273,3 @@ void hq2_noise_inject( return; } - - diff --git a/lib_com/hq2_noise_inject_fx.c b/lib_com/hq2_noise_inject_fx.c index 9763255a2..9f787fde5 100644 --- a/lib_com/hq2_noise_inject_fx.c +++ b/lib_com/hq2_noise_inject_fx.c @@ -37,655 +37,656 @@ #include "move.h" #include "count.h" - /*--------------------------------------------------------------------------* - * hq2_noise_inject() - * - * HQ2 noise injection for WB signals - *--------------------------------------------------------------------------*/ +/*--------------------------------------------------------------------------* + * hq2_noise_inject() + * + * HQ2 noise injection for WB signals + *--------------------------------------------------------------------------*/ void hq2_noise_inject_fx( - Word32 L_y2[], - const Word16 band_start[], - const Word16 band_end[], - const Word16 band_width[], - Word32 Ep_fx[], - Word32 Rk_fx[], - const Word16 npulses[], - Word16 ni_seed, - const Word16 bands, - const Word16 ni_start_band, - const Word16 bw_low, - const Word16 bw_high, - const Word32 enerL_fx, - const Word32 enerH_fx, - Word32 last_ni_gain_fx[], - Word16 last_env_fx[], - Word16 *last_max_pos_pulse, - Word16 *p2a_flags, - Word16 p2a_bands, - const Word16 hqswb_clas, - const Word16 bwidth, - const Word32 bwe_br -) + Word32 L_y2[], + const Word16 band_start[], + const Word16 band_end[], + const Word16 band_width[], + Word32 Ep_fx[], + Word32 Rk_fx[], + const Word16 npulses[], + Word16 ni_seed, + const Word16 bands, + const Word16 ni_start_band, + const Word16 bw_low, + const Word16 bw_high, + const Word32 enerL_fx, + const Word32 enerH_fx, + Word32 last_ni_gain_fx[], + Word16 last_env_fx[], + Word16 *last_max_pos_pulse, + Word16 *p2a_flags, + Word16 p2a_bands, + const Word16 hqswb_clas, + const Word16 bwidth, + const Word32 bwe_br ) { - Word32 L_tmp, L_tmp2, L_tmp2x, L_tmp3, L_tmp1; - Word16 exp, exp2, Q_speech; - Word16 pd_fx[BANDS_MAX], rand_fx, peak_fx[BANDS_MAX], fac_fx; + Word32 L_tmp, L_tmp2, L_tmp2x, L_tmp3, L_tmp1; + Word16 exp, exp2, Q_speech; + Word16 pd_fx[BANDS_MAX], rand_fx, peak_fx[BANDS_MAX], fac_fx; - Word16 tmp, tmpx, tmp1, tmp2, tmp3, tmp4, Q_env_fx[BANDS_MAX], Q_Ep_fx[BANDS_MAX]; + Word16 tmp, tmpx, tmp1, tmp2, tmp3, tmp4, Q_env_fx[BANDS_MAX], Q_Ep_fx[BANDS_MAX]; - Word16 Qs = SWB_BWE_LR_Qs; - Word32 env_fx[BANDS_MAX]; - Word16 env_fx2[BANDS_MAX]; - Word32 ni_gain_fx[BANDS_MAX]; - Word16 y2hat_fx[L_FRAME48k]; + Word16 Qs = SWB_BWE_LR_Qs; + Word32 env_fx[BANDS_MAX]; + Word16 env_fx2[BANDS_MAX]; + Word32 ni_gain_fx[BANDS_MAX]; + Word16 y2hat_fx[L_FRAME48k]; - Word16 i, j, k, ni_end_band, satur, count[BANDS_MAX], max_pos_pulse, pos; - Word16 sb = bands; + Word16 i, j, k, ni_end_band, satur, count[BANDS_MAX], max_pos_pulse, pos; + Word16 sb = bands; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; + Flag Overflow = 0; #endif - satur = 0; - move16(); + satur = 0; + move16(); - FOR(i = 0; i < bands; i++) - { + FOR( i = 0; i < bands; i++ ) + { #ifdef BASOP_NOGLOB - Ep_fx[i] = L_shl_o(Ep_fx[i], 6, &Overflow);/* Q-6 -> Q0 */ move32(); -#else /* BASOP_NOGLOB */ - Ep_fx[i] = L_shl(Ep_fx[i], 6);/* Q-6 -> Q0 */ move32(); + Ep_fx[i] = L_shl_o( Ep_fx[i], 6, &Overflow ); /* Q-6 -> Q0 */ + move32(); +#else /* BASOP_NOGLOB */ + Ep_fx[i] = L_shl( Ep_fx[i], 6 ); /* Q-6 -> Q0 */ + move32(); #endif /* BASOP_NOGLOB */ - } - - tmp = add(band_end[bands - 1], 1); - FOR(k = 0; k < tmp; k++) - { - y2hat_fx[k] = (Word16)L_min(L_max(L_shr(L_y2[k], Qs), -32768), 32767); - move16(); /* Extract_l or something else is missing here */ - } - - test(); - test(); - test(); - test(); - IF((EQ_16(hqswb_clas, HQ_HARMONIC) || EQ_16(hqswb_clas, HQ_NORMAL)) && (EQ_32(bwe_br, HQ_16k40) || EQ_32(bwe_br, HQ_13k20)) && EQ_16(bwidth, SWB)) - { - sb = 17; - move16(); - if (EQ_32(bwe_br, HQ_16k40)) - { - sb = 19; - move16(); - } - } - - /* calculate the envelopes/ the decoded peak coeff./number of the decoded coeff./ the last subbands of the bit-allocated/saturation of bit-allocation */ - ni_end_band = bands; - max_pos_pulse = bands; - FOR(k = ni_start_band; k < ni_end_band; k++) - { - tmp = div_s(1, band_width[k]); /*Q15 */ - L_tmp = Mult_32_16(Rk_fx[k], tmp);/*Q(16+15-15=16) */ - pd_fx[k] = extract_h(L_shl(L_tmp, 10)); /*16+10-16 =Q10 */ - - L_tmp2 = Ep_fx[k];/*Q0 */ - move32(); - L_tmp = L_max(1, L_tmp2); - exp = norm_l(L_tmp); - tmp = extract_h(L_shl(L_tmp, exp)); - - L_tmp3 = (Word32)band_width[k]; - move32(); - exp2 = norm_l(L_tmp3); - tmp2 = extract_h(L_shl(L_tmp3, exp2)); - - exp2 = sub(exp, exp2); /* Denormalize and substract */ - - tmp3 = sub(tmp2, tmp); - if (tmp3 > 0) - { - tmp2 = shr(tmp2, 1); - } - if (tmp3 > 0) - { - exp2 = add(exp2, 1); - } - tmp = div_s(tmp2, tmp); - L_tmp = L_deposit_h(tmp); - L_tmp = Isqrt_lc(L_tmp, &exp2); - env_fx[k] = L_tmp; - move32();/*Q(31-exp2) move32(); */ - Q_env_fx[k] = sub(31, exp2); - move16(); - tmp = sub(17, Q_env_fx[k]); + } + + tmp = add( band_end[bands - 1], 1 ); + FOR( k = 0; k < tmp; k++ ) + { + y2hat_fx[k] = (Word16) L_min( L_max( L_shr( L_y2[k], Qs ), -32768 ), 32767 ); + move16(); /* Extract_l or something else is missing here */ + } + + test(); + test(); + test(); + test(); + IF( ( EQ_16( hqswb_clas, HQ_HARMONIC ) || EQ_16( hqswb_clas, HQ_NORMAL ) ) && ( EQ_32( bwe_br, HQ_16k40 ) || EQ_32( bwe_br, HQ_13k20 ) ) && EQ_16( bwidth, SWB ) ) + { + sb = 17; + move16(); + if ( EQ_32( bwe_br, HQ_16k40 ) ) + { + sb = 19; + move16(); + } + } + + /* calculate the envelopes/ the decoded peak coeff./number of the decoded coeff./ the last subbands of the bit-allocated/saturation of bit-allocation */ + ni_end_band = bands; + max_pos_pulse = bands; + FOR( k = ni_start_band; k < ni_end_band; k++ ) + { + tmp = div_s( 1, band_width[k] ); /*Q15 */ + L_tmp = Mult_32_16( Rk_fx[k], tmp ); /*Q(16+15-15=16) */ + pd_fx[k] = extract_h( L_shl( L_tmp, 10 ) ); /*16+10-16 =Q10 */ + + L_tmp2 = Ep_fx[k]; /*Q0 */ + move32(); + L_tmp = L_max( 1, L_tmp2 ); + exp = norm_l( L_tmp ); + tmp = extract_h( L_shl( L_tmp, exp ) ); + + L_tmp3 = (Word32) band_width[k]; + move32(); + exp2 = norm_l( L_tmp3 ); + tmp2 = extract_h( L_shl( L_tmp3, exp2 ) ); + + exp2 = sub( exp, exp2 ); /* Denormalize and substract */ + + tmp3 = sub( tmp2, tmp ); + if ( tmp3 > 0 ) + { + tmp2 = shr( tmp2, 1 ); + } + if ( tmp3 > 0 ) + { + exp2 = add( exp2, 1 ); + } + tmp = div_s( tmp2, tmp ); + L_tmp = L_deposit_h( tmp ); + L_tmp = Isqrt_lc( L_tmp, &exp2 ); + env_fx[k] = L_tmp; + move32(); /*Q(31-exp2) move32(); */ + Q_env_fx[k] = sub( 31, exp2 ); + move16(); + tmp = sub( 17, Q_env_fx[k] ); #ifdef BASOP_NOGLOB - env_fx2[k] = extract_h(L_shl_o(env_fx[k], tmp, &Overflow));/*Q1 */ -#else /* BASOP_NOGLOB */ - env_fx2[k] = extract_h(L_shl(env_fx[k], tmp));/*Q1 */ -#endif /* BASOP_NOGLOB */ - peak_fx[k] = 0; - move16(); - count[k] = 0; - move16(); - - IF(npulses[k] != 0) - { - FOR(i = band_start[k]; i <= band_end[k]; i++) - { - L_tmp = L_mult0(y2hat_fx[i], y2hat_fx[i]); /*0 */ + env_fx2[k] = extract_h( L_shl_o( env_fx[k], tmp, &Overflow ) ); /*Q1 */ +#else /* BASOP_NOGLOB */ + env_fx2[k] = extract_h( L_shl( env_fx[k], tmp ) ); /*Q1 */ +#endif /* BASOP_NOGLOB */ + peak_fx[k] = 0; + move16(); + count[k] = 0; + move16(); + + IF( npulses[k] != 0 ) + { + FOR( i = band_start[k]; i <= band_end[k]; i++ ) + { + L_tmp = L_mult0( y2hat_fx[i], y2hat_fx[i] ); /*0 */ #ifdef BASOP_NOGLOB - Ep_fx[k] = L_sub_o(Ep_fx[k], L_tmp, &Overflow); -#else /* BASOP_NOGLOB */ - Ep_fx[k] = L_sub(Ep_fx[k], L_tmp); -#endif /* BASOP_NOGLOB */ - move32();/*0 */ - IF(GT_16(abs_s(y2hat_fx[i]), peak_fx[k])) - { - peak_fx[k] = abs_s(y2hat_fx[i]); - move16();/*0 */ - } - - IF(y2hat_fx[i] != 0) - { - count[k] = add(count[k], 1); - move16(); - } - } - - max_pos_pulse = k; - L_tmp2 = Ep_fx[k]; - move32(); - L_tmp = L_max(1, L_tmp2); - exp = norm_l(L_tmp); - tmp = extract_h(L_shl(L_tmp, exp)); - - L_tmp3 = (Word32)band_width[k]; - exp2 = norm_l(L_tmp3); - tmp2 = extract_h(L_shl(L_tmp3, exp2)); - - exp2 = sub(exp, exp2); /* Denormalize and substract */ - - tmp3 = sub(tmp2, tmp); - if (tmp3 > 0) - { - tmp2 = shr(tmp2, 1); - } - if (tmp3 > 0) - { - exp2 = add(exp2, 1); - } - tmp = div_s(tmp2, tmp); - L_tmp = L_deposit_h(tmp); - L_tmp = Isqrt_lc(L_tmp, &exp2); - Ep_fx[k] = L_tmp; - move32();/*Q(31-exp2) */ - Q_Ep_fx[k] = sub(31, exp2); - move16(); - } - ELSE - { - Ep_fx[k] = env_fx[k]; - move32();/*Q(Q_env_fx[k]) */ - Q_Ep_fx[k] = Q_env_fx[k]; - move16();/*31-exp2 */ - } - } - - FOR(k = ni_start_band; k < ni_end_band; k++) - { - /* calculate the noise gain */ - satur = 0; - move16(); - if (GE_16(pd_fx[k], 819)) - { - satur = 1; - move16(); - } - - test(); - IF(satur == 0 && Ep_fx[k] > 0) - { - IF(npulses[k] != 0) - { - IF(EQ_16(bwidth, SWB)) - { - IF(NE_16(hqswb_clas, HQ_TRANSIENT)) - { - IF(peak_fx[k] != 0) - { - Q_speech = norm_s(peak_fx[k]); - tmp = shl(peak_fx[k], Q_speech);/*Q(Q_speech) */ - tmp = div_s(16384, tmp);/*Q(15+14-Q_speech) */ - } - ELSE - { - tmp = 0x7fff; - move16(); - Q_speech = 0; - move16(); - } - L_tmp2x = Mult_32_16(Ep_fx[k], tmp);/* Q(Q_Ep_fx[k]+29-Q_speech-15 = Q_Ep_fx[k]-Q_speech+14) */ - tmp = sub(Q_Ep_fx[k], Q_speech); - tmpx = add(tmp, 1); - tmp2 = extract_l(L_shr(L_tmp2x, s_min(tmpx, 31)));/*Q13 Ep[k]/peak[k] */ - - IF(EQ_16(hqswb_clas, HQ_HARMONIC)) - { - tmp = sub(1536, pd_fx[k]); /*Q10 */ - tmp3 = shl(tmp, 4); /*Q14 */ - L_tmp = Mult_32_16(env_fx[k], tmp3);/*Q(Q_env_fx[k]+14-15 = Q_env_fx[k]-1) */ - L_tmp = Mult_32_16(L_tmp, 6144);/*Q(Q_env_fx[k]-1+10-15 = Q_env_fx[k]-6) */ - - IF(peak_fx[k] != 0) - { - Q_speech = norm_s(peak_fx[k]); - tmp = shl(peak_fx[k], Q_speech);/*Q(Q_speech) */ - tmp = div_s(16384, tmp);/*Q(15+14-Q_speech) */ - } - ELSE - { - tmp = 0x7fff; - move16(); - Q_speech = 0; - move16(); - } - - L_tmp2 = Mult_32_16(Ep_fx[k], tmp);/* Q(Q_Ep_fx[k]+29-Q_speech-15=Q_Ep_fx[k]-Q_speech+14) */ - L_tmp3 = Mult_32_16(L_tmp, tmp);/* Q(Q_env_fx[k]-6+29-Q_speech-15=Q_env_fx[k]-Q_speech+8) */ - L_tmp = Mult_32_32(L_tmp2, L_tmp3); /*Q(Q_Ep_fx[k]-Q_speech+14+Q_env_fx[k]-Q_speech+8-31=Q_Ep_fx[k]+Q_env_fx[k]-2*Q_speech-9) */ - - tmp = add(Q_Ep_fx[k], Q_env_fx[k]); - tmp = sub(tmp, Q_speech); - tmp = sub(tmp, Q_speech); - tmp = sub(37, tmp); - tmp1 = extract_h(L_shl(L_tmp, tmp));/*Q12 //6.0f*(1.5f - pd[k])*env[k]*Ep[k]/(peak[k]*peak[k]) */ - - fac_fx = tmp1; - move16();/*Q12 */ - if (GT_16(k, sb)) - { - fac_fx = mult(24576, tmp2);/*//Q(14+13-15=12) */ - } - } - ELSE - { - IF(LE_16(k,sb)) - { - tmp = sub(1536,pd_fx[k]); /*Q10 */ - tmp3 = shl(tmp,4); /*Q14 */ - L_tmp = Mult_32_16(L_tmp2x,tmp3);/*Q(Q_Ep_fx[k]-Q_speech+14+14-15 = Q_Ep_fx[k]-Q_speech+13) */ - L_tmp = Mult_32_16(L_tmp,20480);/*Q(Q_Ep_fx[k]-Q_speech+13+12-15 = Q_Ep_fx[k]-Q_speech+10) */ - fac_fx = extract_h(L_shl(L_tmp,sub(add(18,Q_speech),Q_Ep_fx[k])));/*Q_Ep_fx[k]-Q_speech+10 +18+Q_speech-Q_Ep_fx[k] -16 =12 */ - } - ELSE - { - fac_fx = shl(mult(32767,tmp2),1);/*//Q(13+13-15+1=12) */ - } - } - } - ELSE - { - fac_fx = 4505; - move16();/*Q12 */ - } - } - ELSE - { - tmp = sub(1536,pd_fx[k]); /*Q10 */ - tmp2 = s_min(1024,tmp); /*q10 */ - tmp2 = shl(tmp2,4); /*Q14 */ - L_tmp = Mult_32_16(env_fx[k],tmp2);/*Q(Q_env_fx[k]+14-15 = Q_env_fx[k]-1) */ - L_tmp = Mult_32_16(L_tmp,20480);/*Q(Q_env_fx[k]-1+10-15 = Q_env_fx[k]-6) */ - - IF(peak_fx[k] != 0) - { - Q_speech = norm_s(peak_fx[k]); - tmp = shl(peak_fx[k],Q_speech);/*Q(Q_speech) */ - tmp = div_s(16384,tmp);/*Q(15+14-Q_speech) */ - } - ELSE - { - tmp = 0x7fff; - move16(); - Q_speech = 0; - move16(); - } - - L_tmp2 = Mult_32_16(Ep_fx[k],tmp);/* Q(Q_Ep_fx[k]+29-Q_speech-15=Q_Ep_fx[k]-Q_speech+14) */ - L_tmp3 = Mult_32_16(L_tmp,tmp);/* Q(Q_env_fx[k]-6+29-Q_speech-15=Q_env_fx[k]-Q_speech+8) */ - L_tmp = Mult_32_32(L_tmp2,L_tmp3); /*Q(Q_Ep_fx[k]-Q_speech+14+Q_env_fx[k]-Q_speech+8-31=Q_Ep_fx[k]+Q_env_fx[k]-2*Q_speech-9) */ - - tmp = add(Q_Ep_fx[k],Q_env_fx[k]); - tmp = sub(tmp,Q_speech); - tmp = sub(tmp,Q_speech); - tmp = sub(37,tmp); - - fac_fx = extract_h(L_shl(L_tmp,tmp));/*Q12 */ - - test(); - IF(GT_16(k,1) && LT_16(k,sub(ni_end_band,1))) - { - IF(env_fx2[k] != 0) - { - Q_speech = norm_s(env_fx2[k]); - tmp = shl(env_fx2[k],Q_speech);/*Q(Q_speech+1) */ - tmp = div_s(16384,tmp);/*Q(15+14-Q_speech-1=28-Q_speech) */ - Q_speech = sub(28,Q_speech); - } - ELSE - { - tmp = 0x7fff; - move16(); - Q_speech = 0; - move16(); - } - tmp1 = mult(env_fx2[add(k,1)],16384);/*Q(1+15-15=1) Q1 */ - tmp2 = sub(env_fx2[k],tmp1); - tmp1 = mult(env_fx2[k],16384);/*Q(1+15-15=1) Q1 */ - tmp3 = sub(tmp1,env_fx2[sub(k,1)]); - tmp1 = mult(peak_fx[k],16384);/*Q(0+15-15=0) Q0 */ - tmp4 = sub(tmp1,shr(env_fx2[k],1)); - test(); - test(); - test(); - IF(count[add(k,1)] == 0 && tmp2 > 0 && tmp3 < 0) - { - L_tmp = L_mult(env_fx2[add(k,1)],tmp);/* Q(1+Q_speech+1 = Q_speech+2) */ - L_tmp = Mult_32_16(L_tmp,24576); /*Q(Q_speech+2+14-15=Q_speech+1) */ - fac_fx = extract_h(L_shl(L_tmp,sub(27,Q_speech)));/*Q12 */ - } - ELSE IF(count[sub(k,1)] == 0 && tmp4 > 0) - { - L_tmp = L_mult(env_fx2[sub(k,1)],tmp); /* Q(1+Q_speech+1 = Q_speech+2) */ + Ep_fx[k] = L_sub_o( Ep_fx[k], L_tmp, &Overflow ); +#else /* BASOP_NOGLOB */ + Ep_fx[k] = L_sub( Ep_fx[k], L_tmp ); +#endif /* BASOP_NOGLOB */ + move32(); /*0 */ + IF( GT_16( abs_s( y2hat_fx[i] ), peak_fx[k] ) ) + { + peak_fx[k] = abs_s( y2hat_fx[i] ); + move16(); /*0 */ + } + + IF( y2hat_fx[i] != 0 ) + { + count[k] = add( count[k], 1 ); + move16(); + } + } + + max_pos_pulse = k; + L_tmp2 = Ep_fx[k]; + move32(); + L_tmp = L_max( 1, L_tmp2 ); + exp = norm_l( L_tmp ); + tmp = extract_h( L_shl( L_tmp, exp ) ); + + L_tmp3 = (Word32) band_width[k]; + exp2 = norm_l( L_tmp3 ); + tmp2 = extract_h( L_shl( L_tmp3, exp2 ) ); + + exp2 = sub( exp, exp2 ); /* Denormalize and substract */ + + tmp3 = sub( tmp2, tmp ); + if ( tmp3 > 0 ) + { + tmp2 = shr( tmp2, 1 ); + } + if ( tmp3 > 0 ) + { + exp2 = add( exp2, 1 ); + } + tmp = div_s( tmp2, tmp ); + L_tmp = L_deposit_h( tmp ); + L_tmp = Isqrt_lc( L_tmp, &exp2 ); + Ep_fx[k] = L_tmp; + move32(); /*Q(31-exp2) */ + Q_Ep_fx[k] = sub( 31, exp2 ); + move16(); + } + ELSE + { + Ep_fx[k] = env_fx[k]; + move32(); /*Q(Q_env_fx[k]) */ + Q_Ep_fx[k] = Q_env_fx[k]; + move16(); /*31-exp2 */ + } + } + + FOR( k = ni_start_band; k < ni_end_band; k++ ) + { + /* calculate the noise gain */ + satur = 0; + move16(); + if ( GE_16( pd_fx[k], 819 ) ) + { + satur = 1; + move16(); + } + + test(); + IF( satur == 0 && Ep_fx[k] > 0 ) + { + IF( npulses[k] != 0 ) + { + IF( EQ_16( bwidth, SWB ) ) + { + IF( NE_16( hqswb_clas, HQ_TRANSIENT ) ) + { + IF( peak_fx[k] != 0 ) + { + Q_speech = norm_s( peak_fx[k] ); + tmp = shl( peak_fx[k], Q_speech ); /*Q(Q_speech) */ + tmp = div_s( 16384, tmp ); /*Q(15+14-Q_speech) */ + } + ELSE + { + tmp = 0x7fff; + move16(); + Q_speech = 0; + move16(); + } + L_tmp2x = Mult_32_16( Ep_fx[k], tmp ); /* Q(Q_Ep_fx[k]+29-Q_speech-15 = Q_Ep_fx[k]-Q_speech+14) */ + tmp = sub( Q_Ep_fx[k], Q_speech ); + tmpx = add( tmp, 1 ); + tmp2 = extract_l( L_shr( L_tmp2x, s_min( tmpx, 31 ) ) ); /*Q13 Ep[k]/peak[k] */ + + IF( EQ_16( hqswb_clas, HQ_HARMONIC ) ) + { + tmp = sub( 1536, pd_fx[k] ); /*Q10 */ + tmp3 = shl( tmp, 4 ); /*Q14 */ + L_tmp = Mult_32_16( env_fx[k], tmp3 ); /*Q(Q_env_fx[k]+14-15 = Q_env_fx[k]-1) */ + L_tmp = Mult_32_16( L_tmp, 6144 ); /*Q(Q_env_fx[k]-1+10-15 = Q_env_fx[k]-6) */ + + IF( peak_fx[k] != 0 ) + { + Q_speech = norm_s( peak_fx[k] ); + tmp = shl( peak_fx[k], Q_speech ); /*Q(Q_speech) */ + tmp = div_s( 16384, tmp ); /*Q(15+14-Q_speech) */ + } + ELSE + { + tmp = 0x7fff; + move16(); + Q_speech = 0; + move16(); + } + + L_tmp2 = Mult_32_16( Ep_fx[k], tmp ); /* Q(Q_Ep_fx[k]+29-Q_speech-15=Q_Ep_fx[k]-Q_speech+14) */ + L_tmp3 = Mult_32_16( L_tmp, tmp ); /* Q(Q_env_fx[k]-6+29-Q_speech-15=Q_env_fx[k]-Q_speech+8) */ + L_tmp = Mult_32_32( L_tmp2, L_tmp3 ); /*Q(Q_Ep_fx[k]-Q_speech+14+Q_env_fx[k]-Q_speech+8-31=Q_Ep_fx[k]+Q_env_fx[k]-2*Q_speech-9) */ + + tmp = add( Q_Ep_fx[k], Q_env_fx[k] ); + tmp = sub( tmp, Q_speech ); + tmp = sub( tmp, Q_speech ); + tmp = sub( 37, tmp ); + tmp1 = extract_h( L_shl( L_tmp, tmp ) ); /*Q12 //6.0f*(1.5f - pd[k])*env[k]*Ep[k]/(peak[k]*peak[k]) */ + + fac_fx = tmp1; + move16(); /*Q12 */ + if ( GT_16( k, sb ) ) + { + fac_fx = mult( 24576, tmp2 ); /*//Q(14+13-15=12) */ + } + } + ELSE + { + IF( LE_16( k, sb ) ) + { + tmp = sub( 1536, pd_fx[k] ); /*Q10 */ + tmp3 = shl( tmp, 4 ); /*Q14 */ + L_tmp = Mult_32_16( L_tmp2x, tmp3 ); /*Q(Q_Ep_fx[k]-Q_speech+14+14-15 = Q_Ep_fx[k]-Q_speech+13) */ + L_tmp = Mult_32_16( L_tmp, 20480 ); /*Q(Q_Ep_fx[k]-Q_speech+13+12-15 = Q_Ep_fx[k]-Q_speech+10) */ + fac_fx = extract_h( L_shl( L_tmp, sub( add( 18, Q_speech ), Q_Ep_fx[k] ) ) ); /*Q_Ep_fx[k]-Q_speech+10 +18+Q_speech-Q_Ep_fx[k] -16 =12 */ + } + ELSE + { + fac_fx = shl( mult( 32767, tmp2 ), 1 ); /*//Q(13+13-15+1=12) */ + } + } + } + ELSE + { + fac_fx = 4505; + move16(); /*Q12 */ + } + } + ELSE + { + tmp = sub( 1536, pd_fx[k] ); /*Q10 */ + tmp2 = s_min( 1024, tmp ); /*q10 */ + tmp2 = shl( tmp2, 4 ); /*Q14 */ + L_tmp = Mult_32_16( env_fx[k], tmp2 ); /*Q(Q_env_fx[k]+14-15 = Q_env_fx[k]-1) */ + L_tmp = Mult_32_16( L_tmp, 20480 ); /*Q(Q_env_fx[k]-1+10-15 = Q_env_fx[k]-6) */ + + IF( peak_fx[k] != 0 ) + { + Q_speech = norm_s( peak_fx[k] ); + tmp = shl( peak_fx[k], Q_speech ); /*Q(Q_speech) */ + tmp = div_s( 16384, tmp ); /*Q(15+14-Q_speech) */ + } + ELSE + { + tmp = 0x7fff; + move16(); + Q_speech = 0; + move16(); + } + + L_tmp2 = Mult_32_16( Ep_fx[k], tmp ); /* Q(Q_Ep_fx[k]+29-Q_speech-15=Q_Ep_fx[k]-Q_speech+14) */ + L_tmp3 = Mult_32_16( L_tmp, tmp ); /* Q(Q_env_fx[k]-6+29-Q_speech-15=Q_env_fx[k]-Q_speech+8) */ + L_tmp = Mult_32_32( L_tmp2, L_tmp3 ); /*Q(Q_Ep_fx[k]-Q_speech+14+Q_env_fx[k]-Q_speech+8-31=Q_Ep_fx[k]+Q_env_fx[k]-2*Q_speech-9) */ + + tmp = add( Q_Ep_fx[k], Q_env_fx[k] ); + tmp = sub( tmp, Q_speech ); + tmp = sub( tmp, Q_speech ); + tmp = sub( 37, tmp ); + + fac_fx = extract_h( L_shl( L_tmp, tmp ) ); /*Q12 */ + + test(); + IF( GT_16( k, 1 ) && LT_16( k, sub( ni_end_band, 1 ) ) ) + { + IF( env_fx2[k] != 0 ) + { + Q_speech = norm_s( env_fx2[k] ); + tmp = shl( env_fx2[k], Q_speech ); /*Q(Q_speech+1) */ + tmp = div_s( 16384, tmp ); /*Q(15+14-Q_speech-1=28-Q_speech) */ + Q_speech = sub( 28, Q_speech ); + } + ELSE + { + tmp = 0x7fff; + move16(); + Q_speech = 0; + move16(); + } + tmp1 = mult( env_fx2[add( k, 1 )], 16384 ); /*Q(1+15-15=1) Q1 */ + tmp2 = sub( env_fx2[k], tmp1 ); + tmp1 = mult( env_fx2[k], 16384 ); /*Q(1+15-15=1) Q1 */ + tmp3 = sub( tmp1, env_fx2[sub( k, 1 )] ); + tmp1 = mult( peak_fx[k], 16384 ); /*Q(0+15-15=0) Q0 */ + tmp4 = sub( tmp1, shr( env_fx2[k], 1 ) ); + test(); + test(); + test(); + IF( count[add( k, 1 )] == 0 && tmp2 > 0 && tmp3 < 0 ) + { + L_tmp = L_mult( env_fx2[add( k, 1 )], tmp ); /* Q(1+Q_speech+1 = Q_speech+2) */ + L_tmp = Mult_32_16( L_tmp, 24576 ); /*Q(Q_speech+2+14-15=Q_speech+1) */ + fac_fx = extract_h( L_shl( L_tmp, sub( 27, Q_speech ) ) ); /*Q12 */ + } + ELSE IF( count[sub( k, 1 )] == 0 && tmp4 > 0 ) + { + L_tmp = L_mult( env_fx2[sub( k, 1 )], tmp ); /* Q(1+Q_speech+1 = Q_speech+2) */ #ifdef BASOP_NOGLOB - fac_fx = extract_h(L_shl_o(L_tmp, sub(26, Q_speech), &Overflow));/*Q12 */ + fac_fx = extract_h( L_shl_o( L_tmp, sub( 26, Q_speech ), &Overflow ) ); /*Q12 */ #else - fac_fx = extract_h(L_shl(L_tmp,sub(26,Q_speech)));/*Q12 */ + fac_fx = extract_h( L_shl( L_tmp, sub( 26, Q_speech ) ) ); /*Q12 */ #endif - } - } - - test(); - IF(GE_16(k,sub(ni_end_band,p2a_bands)) && EQ_16(bwidth,WB)) - { - L_tmp = Mult_32_16(enerH_fx, bw_low); - L_tmp2 = Mult_32_16(enerL_fx, bw_high); - L_tmp = L_sub(L_tmp,L_tmp2); - tmp1 = mult(peak_fx[k],16384);/*Q(0+15-15=0) Q0 */ - tmp4 = sub(tmp1,shr(env_fx2[k],1)); - test(); - IF(L_tmp > 0 && tmp4 < 0) - { - IF(peak_fx[k] != 0) - { - Q_speech = norm_s(peak_fx[k]); - tmp = shl(peak_fx[k],Q_speech);/*Q(Q_speech) */ - tmp = div_s(16384,tmp);/*Q(15+14-Q_speech) */ - } - ELSE - { - tmp = 0x7fff; - move16(); - Q_speech = 0; - move16(); - } - L_tmp2 = Mult_32_16(Ep_fx[k],tmp);/* Q(Q_Ep_fx[k]+29-Q_speech-15 = Q_Ep_fx[k]-Q_speech+14) */ - tmp = sub(Q_Ep_fx[k],Q_speech); - tmp = add(tmp,1); - tmp = extract_l(L_shr(L_tmp2,tmp));/*Q13 */ - tmp = sub(16384,tmp);/*Q13 */ - fac_fx = extract_h(L_shl(L_mult(fac_fx,tmp),2));/*Q12*/ - } - - IF(p2a_flags[k] == 0) - { - L_tmp2 = Mult_32_16(Ep_fx[k],fac_fx);/*Q(Q_Ep_fx[k]+12-15 = Q_Ep_fx[k]-3) */ - Q_speech = norm_l(L_tmp2); - tmp = extract_h(L_shl(L_tmp2,Q_speech));/*Q(Q_Ep_fx[k]-3+Q_speech-16 = Q_Ep_fx[k]+Q_speech-19) */ - IF(tmp != 0) - { - tmp = div_s(16384,tmp);/*Q(15+14-Q_Ep_fx[k]-Q_speech+19 = 48-Q_Ep_fx[k]-Q_speech) */ - L_tmp2 = Mult_32_16(env_fx[k],tmp);/*Q(Q_env_fx[k]+48-Q_Ep_fx[k]-Q_speech-15 = Q_env_fx[k]-Q_Ep_fx[k]-Q_speech+33) */ - L_tmp2 = Mult_32_16(L_tmp2,20480);/*Q(Q_env_fx[k]-Q_Ep_fx[k]-Q_speech+33+14-15 = Q_env_fx[k]-Q_Ep_fx[k]-Q_speech+32) */ - tmp = sub(Q_env_fx[k],Q_Ep_fx[k]); - tmp = sub(tmp,Q_speech); - tmp = add(tmp,25); + } + } + + test(); + IF( GE_16( k, sub( ni_end_band, p2a_bands ) ) && EQ_16( bwidth, WB ) ) + { + L_tmp = Mult_32_16( enerH_fx, bw_low ); + L_tmp2 = Mult_32_16( enerL_fx, bw_high ); + L_tmp = L_sub( L_tmp, L_tmp2 ); + tmp1 = mult( peak_fx[k], 16384 ); /*Q(0+15-15=0) Q0 */ + tmp4 = sub( tmp1, shr( env_fx2[k], 1 ) ); + test(); + IF( L_tmp > 0 && tmp4 < 0 ) + { + IF( peak_fx[k] != 0 ) + { + Q_speech = norm_s( peak_fx[k] ); + tmp = shl( peak_fx[k], Q_speech ); /*Q(Q_speech) */ + tmp = div_s( 16384, tmp ); /*Q(15+14-Q_speech) */ + } + ELSE + { + tmp = 0x7fff; + move16(); + Q_speech = 0; + move16(); + } + L_tmp2 = Mult_32_16( Ep_fx[k], tmp ); /* Q(Q_Ep_fx[k]+29-Q_speech-15 = Q_Ep_fx[k]-Q_speech+14) */ + tmp = sub( Q_Ep_fx[k], Q_speech ); + tmp = add( tmp, 1 ); + tmp = extract_l( L_shr( L_tmp2, tmp ) ); /*Q13 */ + tmp = sub( 16384, tmp ); /*Q13 */ + fac_fx = extract_h( L_shl( L_mult( fac_fx, tmp ), 2 ) ); /*Q12*/ + } + + IF( p2a_flags[k] == 0 ) + { + L_tmp2 = Mult_32_16( Ep_fx[k], fac_fx ); /*Q(Q_Ep_fx[k]+12-15 = Q_Ep_fx[k]-3) */ + Q_speech = norm_l( L_tmp2 ); + tmp = extract_h( L_shl( L_tmp2, Q_speech ) ); /*Q(Q_Ep_fx[k]-3+Q_speech-16 = Q_Ep_fx[k]+Q_speech-19) */ + IF( tmp != 0 ) + { + tmp = div_s( 16384, tmp ); /*Q(15+14-Q_Ep_fx[k]-Q_speech+19 = 48-Q_Ep_fx[k]-Q_speech) */ + L_tmp2 = Mult_32_16( env_fx[k], tmp ); /*Q(Q_env_fx[k]+48-Q_Ep_fx[k]-Q_speech-15 = Q_env_fx[k]-Q_Ep_fx[k]-Q_speech+33) */ + L_tmp2 = Mult_32_16( L_tmp2, 20480 ); /*Q(Q_env_fx[k]-Q_Ep_fx[k]-Q_speech+33+14-15 = Q_env_fx[k]-Q_Ep_fx[k]-Q_speech+32) */ + tmp = sub( Q_env_fx[k], Q_Ep_fx[k] ); + tmp = sub( tmp, Q_speech ); + tmp = add( tmp, 25 ); #ifdef BASOP_NOGLOB - L_tmp = L_shr_sat( L_tmp2, tmp ); /*Q7 */ + L_tmp = L_shr_sat( L_tmp2, tmp ); /*Q7 */ #else - L_tmp = L_shr(L_tmp2,tmp);/*Q7 */ + L_tmp = L_shr( L_tmp2, tmp ); /*Q7 */ #endif - tmp = extract_l(L_min(L_tmp,192));/* */ - fac_fx = extract_h(L_shl(L_mult(fac_fx,tmp),8));/*Q12 */ - } - ELSE - { - tmp = 0x7fff;/*Q0 */ - L_tmp2 = Mult_32_16(env_fx[k],tmp);/*Q(Q_env_fx[k]+0-15 = Q_env_fx[k]-15) */ - L_tmp2 = Mult_32_16(L_tmp2,20480);/*Q(Q_env_fx[k]-15+14-15 = Q_env_fx[k]-16) */ - tmp = sub(Q_env_fx[k],23); + tmp = extract_l( L_min( L_tmp, 192 ) ); /* */ + fac_fx = extract_h( L_shl( L_mult( fac_fx, tmp ), 8 ) ); /*Q12 */ + } + ELSE + { + tmp = 0x7fff; /*Q0 */ + L_tmp2 = Mult_32_16( env_fx[k], tmp ); /*Q(Q_env_fx[k]+0-15 = Q_env_fx[k]-15) */ + L_tmp2 = Mult_32_16( L_tmp2, 20480 ); /*Q(Q_env_fx[k]-15+14-15 = Q_env_fx[k]-16) */ + tmp = sub( Q_env_fx[k], 23 ); #ifdef BASOP_NOGLOB - L_tmp = L_shr_sat( L_tmp2, tmp ); /*Q7 */ + L_tmp = L_shr_sat( L_tmp2, tmp ); /*Q7 */ #else - L_tmp = L_shr(L_tmp2,tmp);/*Q7 */ + L_tmp = L_shr( L_tmp2, tmp ); /*Q7 */ #endif - tmp = extract_l((L_min(L_tmp,192)));/* */ - fac_fx = extract_h(L_shl(L_mult(fac_fx,tmp),8));/*Q12 */ - } - } - } - } - } - ELSE - { - fac_fx = 4505; - move16(); - test(); - if (EQ_16(hqswb_clas,HQ_HARMONIC) && EQ_16(bwidth,SWB)) - { - fac_fx = 3277; - move16(); - } - } - - L_tmp = Mult_32_16(Ep_fx[k], fac_fx);/*Q(Q_Ep_fx[k]+12-15 = Q_Ep_fx[k]-3) */ + tmp = extract_l( ( L_min( L_tmp, 192 ) ) ); /* */ + fac_fx = extract_h( L_shl( L_mult( fac_fx, tmp ), 8 ) ); /*Q12 */ + } + } + } + } + } + ELSE + { + fac_fx = 4505; + move16(); + test(); + if ( EQ_16( hqswb_clas, HQ_HARMONIC ) && EQ_16( bwidth, SWB ) ) + { + fac_fx = 3277; + move16(); + } + } + + L_tmp = Mult_32_16( Ep_fx[k], fac_fx ); /*Q(Q_Ep_fx[k]+12-15 = Q_Ep_fx[k]-3) */ #ifdef BASOP_NOGLOB - ni_gain_fx[k] = L_shr_o(L_tmp, sub(Q_Ep_fx[k], 20), &Overflow); + ni_gain_fx[k] = L_shr_o( L_tmp, sub( Q_Ep_fx[k], 20 ), &Overflow ); #else /* BASOP_NOGLOB */ - ni_gain_fx[k] = L_shr(L_tmp, sub(Q_Ep_fx[k], 20)); + ni_gain_fx[k] = L_shr( L_tmp, sub( Q_Ep_fx[k], 20 ) ); #endif - move32();/*Q17 */ - } - ELSE - { - ni_gain_fx[k] = L_deposit_l(0); - } - - /* smooth the noise gain between the current frame and the previous frame */ - pos = s_max(max_pos_pulse, *last_max_pos_pulse); - move16(); - if (EQ_16(bwidth, SWB)) - { - pos = sub(ni_end_band, 1); - move16(); - } - - IF(LE_16(k, pos)) - { - test(); - IF(k > 0 && LT_16(sub(k, ni_end_band), -1)) - { - tmp1 = mult(last_env_fx[k], 16384);/*Q(1+15-15=1) Q1 */ - tmp2 = sub(env_fx2[k], tmp1);/*>0 */ - tmp1 = mult(env_fx2[k], 16384);/*Q(1+15-15=1) Q1 */ - tmp3 = sub(tmp1, last_env_fx[k]);/*<0 */ - L_tmp = L_add((Word32)env_fx2[k], (Word32)env_fx2[sub(k, 1)]); - L_tmp = L_add(L_tmp, (Word32)env_fx2[add(k, 1)]);/*Q1 */ - L_tmp1 = L_add((Word32)last_env_fx[k], (Word32)last_env_fx[sub(k, 1)]); - L_tmp1 = L_add(L_tmp1, (Word32)last_env_fx[add(k, 1)]);/*Q1 */ - L_tmp2 = Mult_32_16(L_tmp1, 16384);/*Q(1+15-15) Q1 */ - L_tmp2 = L_sub(L_tmp, L_tmp2);/*>0 */ - L_tmp3 = Mult_32_16(L_tmp, 16384);/*Q(1+15-15) Q1 */ - L_tmp3 = L_sub(L_tmp3, L_tmp1);/*<0 */ - test(); - test(); - test(); - IF((tmp2 > 0 && tmp3 < 0) || (L_tmp2 > 0 && L_tmp3 < 0)) - { - IF(GT_32(ni_gain_fx[k], last_ni_gain_fx[k])) - { - L_tmp = Mult_32_16(ni_gain_fx[k], 6554);/*Q(17+15-15 = 17) */ - L_tmp1 = Mult_32_16(last_ni_gain_fx[k], 26214);/*Q17 */ - ni_gain_fx[k] = L_add(L_tmp, L_tmp1); - move32(); - } - ELSE - { - L_tmp = Mult_32_16(ni_gain_fx[k],19661);/*Q(17+15-15 = 17) */ - L_tmp1 = Mult_32_16(last_ni_gain_fx[k],13107);/*Q17 */ - ni_gain_fx[k] = L_add(L_tmp,L_tmp1); - move32(); - } - } - } - ELSE IF(add(sub(k, ni_end_band), 1) == 0) - { - tmp1 = mult(last_env_fx[k], 16384);/*Q(1+15-15=1) Q1 */ - tmp2 = sub(env_fx2[k], tmp1);/*>0 */ - tmp1 = mult(env_fx2[k], 16384);/*Q(1+15-15=1) Q1 */ - tmp3 = sub(tmp1, last_env_fx[k]);/*<0 */ - L_tmp = L_add((Word32)env_fx2[k], (Word32)env_fx2[sub(k, 1)]);/*Q1 */ - L_tmp1 = L_add((Word32)last_env_fx[k], (Word32)last_env_fx[sub(k, 1)]);/*Q1 */ - L_tmp2 = Mult_32_16(L_tmp1, 16384);/*Q(1+15-15) Q1 */ - L_tmp2 = L_sub(L_tmp, L_tmp2);/*>0 */ - L_tmp3 = Mult_32_16(L_tmp, 16384);/*Q(1+15-15) Q1 */ - L_tmp3 = L_sub(L_tmp3, L_tmp1);/*<0 */ - - test(); - test(); - test(); - IF((tmp2 > 0 && tmp3 < 0) || (L_tmp2 > 0 && L_tmp3 < 0)) - { - IF(GT_32(ni_gain_fx[k], last_ni_gain_fx[k])) - { - L_tmp = Mult_32_16(ni_gain_fx[k], 6554);/*Q(17+15-15 = 17) */ - L_tmp1 = Mult_32_16(last_ni_gain_fx[k], 26214);/*Q17 */ - ni_gain_fx[k] = L_add(L_tmp, L_tmp1); - move32(); - } - ELSE - { - L_tmp = Mult_32_16(ni_gain_fx[k],19661);/*Q(17+15-15 = 17) */ - L_tmp1 = Mult_32_16(last_ni_gain_fx[k],13107);/*Q17 */ - ni_gain_fx[k] = L_add(L_tmp,L_tmp1); - move32(); - } - } - } - } - - /* inject noise into the non-decoded coeffs */ - test(); - test(); - IF(add(sub(k, ni_end_band), p2a_bands) >= 0 && p2a_flags[k] == 0 && NE_16(bwidth, SWB)) - { - FOR(i = band_start[k]; i <= band_end[k]; i++) - { - IF(L_y2[i] != 0) - { - L_y2[i] = Mult_32_16(L_y2[i], 26215); - move32();/*Q(12+15-15=12) */ - } - } - } - - test(); - test(); - test(); - IF(EQ_16(k, max_pos_pulse) && add(sub(k, bands), p2a_bands) < 0 && NE_16(satur, 1) && NE_16(bwidth, SWB)) - { - j = 0; - Q_speech = norm_l(ni_gain_fx[k]); - tmp = extract_h(L_shl(ni_gain_fx[k], Q_speech));/*Q(Q_speech+1) */ - IF(tmp != 0) - { - tmp = div_s(16384, tmp);/*Q(15+14-Q_speech-1 = 28-Q_speech) */ - L_tmp = Mult_32_16(Ep_fx[k], tmp); /*Q(Q_Ep_fx[k]+28-Q_speech-15 = Q_Ep_fx[k]+13-Q_speech) */ - tmp = sub(Q_Ep_fx[k], Q_speech); - tmp = sub(15, tmp); + move32(); /*Q17 */ + } + ELSE + { + ni_gain_fx[k] = L_deposit_l( 0 ); + } + + /* smooth the noise gain between the current frame and the previous frame */ + pos = s_max( max_pos_pulse, *last_max_pos_pulse ); + move16(); + if ( EQ_16( bwidth, SWB ) ) + { + pos = sub( ni_end_band, 1 ); + move16(); + } + + IF( LE_16( k, pos ) ) + { + test(); + IF( k > 0 && LT_16( sub( k, ni_end_band ), -1 ) ) + { + tmp1 = mult( last_env_fx[k], 16384 ); /*Q(1+15-15=1) Q1 */ + tmp2 = sub( env_fx2[k], tmp1 ); /*>0 */ + tmp1 = mult( env_fx2[k], 16384 ); /*Q(1+15-15=1) Q1 */ + tmp3 = sub( tmp1, last_env_fx[k] ); /*<0 */ + L_tmp = L_add( (Word32) env_fx2[k], (Word32) env_fx2[sub( k, 1 )] ); + L_tmp = L_add( L_tmp, (Word32) env_fx2[add( k, 1 )] ); /*Q1 */ + L_tmp1 = L_add( (Word32) last_env_fx[k], (Word32) last_env_fx[sub( k, 1 )] ); + L_tmp1 = L_add( L_tmp1, (Word32) last_env_fx[add( k, 1 )] ); /*Q1 */ + L_tmp2 = Mult_32_16( L_tmp1, 16384 ); /*Q(1+15-15) Q1 */ + L_tmp2 = L_sub( L_tmp, L_tmp2 ); /*>0 */ + L_tmp3 = Mult_32_16( L_tmp, 16384 ); /*Q(1+15-15) Q1 */ + L_tmp3 = L_sub( L_tmp3, L_tmp1 ); /*<0 */ + test(); + test(); + test(); + IF( ( tmp2 > 0 && tmp3 < 0 ) || ( L_tmp2 > 0 && L_tmp3 < 0 ) ) + { + IF( GT_32( ni_gain_fx[k], last_ni_gain_fx[k] ) ) + { + L_tmp = Mult_32_16( ni_gain_fx[k], 6554 ); /*Q(17+15-15 = 17) */ + L_tmp1 = Mult_32_16( last_ni_gain_fx[k], 26214 ); /*Q17 */ + ni_gain_fx[k] = L_add( L_tmp, L_tmp1 ); + move32(); + } + ELSE + { + L_tmp = Mult_32_16( ni_gain_fx[k], 19661 ); /*Q(17+15-15 = 17) */ + L_tmp1 = Mult_32_16( last_ni_gain_fx[k], 13107 ); /*Q17 */ + ni_gain_fx[k] = L_add( L_tmp, L_tmp1 ); + move32(); + } + } + } + ELSE IF( add( sub( k, ni_end_band ), 1 ) == 0 ) + { + tmp1 = mult( last_env_fx[k], 16384 ); /*Q(1+15-15=1) Q1 */ + tmp2 = sub( env_fx2[k], tmp1 ); /*>0 */ + tmp1 = mult( env_fx2[k], 16384 ); /*Q(1+15-15=1) Q1 */ + tmp3 = sub( tmp1, last_env_fx[k] ); /*<0 */ + L_tmp = L_add( (Word32) env_fx2[k], (Word32) env_fx2[sub( k, 1 )] ); /*Q1 */ + L_tmp1 = L_add( (Word32) last_env_fx[k], (Word32) last_env_fx[sub( k, 1 )] ); /*Q1 */ + L_tmp2 = Mult_32_16( L_tmp1, 16384 ); /*Q(1+15-15) Q1 */ + L_tmp2 = L_sub( L_tmp, L_tmp2 ); /*>0 */ + L_tmp3 = Mult_32_16( L_tmp, 16384 ); /*Q(1+15-15) Q1 */ + L_tmp3 = L_sub( L_tmp3, L_tmp1 ); /*<0 */ + + test(); + test(); + test(); + IF( ( tmp2 > 0 && tmp3 < 0 ) || ( L_tmp2 > 0 && L_tmp3 < 0 ) ) + { + IF( GT_32( ni_gain_fx[k], last_ni_gain_fx[k] ) ) + { + L_tmp = Mult_32_16( ni_gain_fx[k], 6554 ); /*Q(17+15-15 = 17) */ + L_tmp1 = Mult_32_16( last_ni_gain_fx[k], 26214 ); /*Q17 */ + ni_gain_fx[k] = L_add( L_tmp, L_tmp1 ); + move32(); + } + ELSE + { + L_tmp = Mult_32_16( ni_gain_fx[k], 19661 ); /*Q(17+15-15 = 17) */ + L_tmp1 = Mult_32_16( last_ni_gain_fx[k], 13107 ); /*Q17 */ + ni_gain_fx[k] = L_add( L_tmp, L_tmp1 ); + move32(); + } + } + } + } + + /* inject noise into the non-decoded coeffs */ + test(); + test(); + IF( add( sub( k, ni_end_band ), p2a_bands ) >= 0 && p2a_flags[k] == 0 && NE_16( bwidth, SWB ) ) + { + FOR( i = band_start[k]; i <= band_end[k]; i++ ) + { + IF( L_y2[i] != 0 ) + { + L_y2[i] = Mult_32_16( L_y2[i], 26215 ); + move32(); /*Q(12+15-15=12) */ + } + } + } + + test(); + test(); + test(); + IF( EQ_16( k, max_pos_pulse ) && add( sub( k, bands ), p2a_bands ) < 0 && NE_16( satur, 1 ) && NE_16( bwidth, SWB ) ) + { + j = 0; + Q_speech = norm_l( ni_gain_fx[k] ); + tmp = extract_h( L_shl( ni_gain_fx[k], Q_speech ) ); /*Q(Q_speech+1) */ + IF( tmp != 0 ) + { + tmp = div_s( 16384, tmp ); /*Q(15+14-Q_speech-1 = 28-Q_speech) */ + L_tmp = Mult_32_16( Ep_fx[k], tmp ); /*Q(Q_Ep_fx[k]+28-Q_speech-15 = Q_Ep_fx[k]+13-Q_speech) */ + tmp = sub( Q_Ep_fx[k], Q_speech ); + tmp = sub( 15, tmp ); #ifdef BASOP_NOGLOB - tmp = extract_h(L_shl_o(L_tmp, tmp, &Overflow));/*Q12 */ + tmp = extract_h( L_shl_o( L_tmp, tmp, &Overflow ) ); /*Q12 */ #else - tmp = extract_h(L_shl(L_tmp, tmp));/*Q12 */ + tmp = extract_h( L_shl( L_tmp, tmp ) ); /*Q12 */ #endif - } - ELSE - { - tmp = 0x7fff;/*Q0 */ - L_tmp = Mult_32_16(Ep_fx[k],tmp); /*Q(Q_Ep_fx[k]+0-15 = Q_Ep_fx[k]-15) */ - tmp = sub(43,Q_Ep_fx[k]); + } + ELSE + { + tmp = 0x7fff; /*Q0 */ + L_tmp = Mult_32_16( Ep_fx[k], tmp ); /*Q(Q_Ep_fx[k]+0-15 = Q_Ep_fx[k]-15) */ + tmp = sub( 43, Q_Ep_fx[k] ); #ifdef BASOP_NOGLOB - tmp = extract_h(L_shl_o(L_tmp,tmp, &Overflow));/*Q12 */ + tmp = extract_h( L_shl_o( L_tmp, tmp, &Overflow ) ); /*Q12 */ #else - tmp = extract_h(L_shl(L_tmp,tmp));/*Q12 */ + tmp = extract_h( L_shl( L_tmp, tmp ) ); /*Q12 */ #endif - } - fac_fx = s_max(tmp, 4096);/*Q12 */ - - FOR(i = band_start[k]; i <= band_end[k]; i++) - { - IF(L_y2[i] == 0) - { - rand_fx = Random(&ni_seed); /*Q15 */ - IF(band_width[k] != 0) - { - Q_speech = norm_s(band_width[k]); + } + fac_fx = s_max( tmp, 4096 ); /*Q12 */ + + FOR( i = band_start[k]; i <= band_end[k]; i++ ) + { + IF( L_y2[i] == 0 ) + { + rand_fx = Random( &ni_seed ); /*Q15 */ + IF( band_width[k] != 0 ) + { + Q_speech = norm_s( band_width[k] ); #ifdef BASOP_NOGLOB - tmp = shl_o(band_width[k], Q_speech, &Overflow);/*Q(Q_speech) */ + tmp = shl_o( band_width[k], Q_speech, &Overflow ); /*Q(Q_speech) */ #else - tmp = shl(band_width[k], Q_speech);/*Q(Q_speech) */ + tmp = shl( band_width[k], Q_speech ); /*Q(Q_speech) */ #endif - tmp = div_s(16384, tmp);/*Q(15+14-Q_speech) */ - } - ELSE - { - tmp = 0x7fff; - Q_speech = 0; - } - tmp1 = sub(fac_fx, 4096);/*Q12 */ - L_tmp = L_mult(tmp1, j);/*Q13 */ - L_tmp = Mult_32_16(L_tmp, tmp);/*Q(13+29-Q_speech-15 = 27-Q_speech) */ + tmp = div_s( 16384, tmp ); /*Q(15+14-Q_speech) */ + } + ELSE + { + tmp = 0x7fff; + Q_speech = 0; + } + tmp1 = sub( fac_fx, 4096 ); /*Q12 */ + L_tmp = L_mult( tmp1, j ); /*Q13 */ + L_tmp = Mult_32_16( L_tmp, tmp ); /*Q(13+29-Q_speech-15 = 27-Q_speech) */ #ifdef BASOP_NOGLOB - tmp = extract_h(L_shl_o(L_tmp, add(1, Q_speech), &Overflow));/*Q12 */ + tmp = extract_h( L_shl_o( L_tmp, add( 1, Q_speech ), &Overflow ) ); /*Q12 */ #else - tmp = extract_h(L_shl(L_tmp, add(1, Q_speech)));/*Q12 */ + tmp = extract_h( L_shl( L_tmp, add( 1, Q_speech ) ) ); /*Q12 */ #endif - tmp = sub(fac_fx, tmp);/*Q12 */ - L_tmp = Mult_32_16(ni_gain_fx[k], tmp);/*Q(17+12-15=14) */ - L_y2[i] = L_add(L_y2[i], L_shr(Mult_32_16(L_tmp, rand_fx), 2)); - move32();/*Q12 */ - } - j = add(j, 1); - } - } - ELSE - { - FOR(i = band_start[k]; i <= band_end[k]; i++) - { - IF(L_y2[i] == 0) - { - rand_fx = Random(&ni_seed); /*Q15 */ - L_tmp = Mult_32_16(ni_gain_fx[k],rand_fx);/*Q(17+15-15=17) */ - L_y2[i] = L_add(L_y2[i],L_shr(L_tmp,5)); - move32();/*Q12 */ - } - } - } - } - - Copy(env_fx2, last_env_fx, ni_end_band); - Copy32(ni_gain_fx, last_ni_gain_fx, ni_end_band); - *last_max_pos_pulse = max_pos_pulse; - move16(); - return; + tmp = sub( fac_fx, tmp ); /*Q12 */ + L_tmp = Mult_32_16( ni_gain_fx[k], tmp ); /*Q(17+12-15=14) */ + L_y2[i] = L_add( L_y2[i], L_shr( Mult_32_16( L_tmp, rand_fx ), 2 ) ); + move32(); /*Q12 */ + } + j = add( j, 1 ); + } + } + ELSE + { + FOR( i = band_start[k]; i <= band_end[k]; i++ ) + { + IF( L_y2[i] == 0 ) + { + rand_fx = Random( &ni_seed ); /*Q15 */ + L_tmp = Mult_32_16( ni_gain_fx[k], rand_fx ); /*Q(17+15-15=17) */ + L_y2[i] = L_add( L_y2[i], L_shr( L_tmp, 5 ) ); + move32(); /*Q12 */ + } + } + } + } + + Copy( env_fx2, last_env_fx, ni_end_band ); + Copy32( ni_gain_fx, last_ni_gain_fx, ni_end_band ); + *last_max_pos_pulse = max_pos_pulse; + move16(); + return; } diff --git a/lib_com/hq_bit_allocation_fx.c b/lib_com/hq_bit_allocation_fx.c index 31c4ff383..2b798c962 100644 --- a/lib_com/hq_bit_allocation_fx.c +++ b/lib_com/hq_bit_allocation_fx.c @@ -2,11 +2,11 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include "options.h" /* Compilation switches */ -#include "stl.h" /* required for wmc_tool */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "cnst.h" /* Common constants */ +#include "options.h" /* Compilation switches */ +#include "stl.h" /* required for wmc_tool */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "cnst.h" /* Common constants */ #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" #endif @@ -163,81 +163,79 @@ void ivas_hq_bit_allocation_fx( } avrg_wnorm = shr( avrg_wnorm, 3 ); - FOR( i = 0; i < 4; i++ ) - { - IF( LT_16( wnorm[i], avrg_wnorm ) ) - { + FOR( i = 0; i < 4; i++ ){ + IF( LT_16( wnorm[i], avrg_wnorm ) ){ wnorm[i] = avrg_wnorm; - move16(); - } - } - - /* Estimate number of bits per band */ - *sum = BitAllocWB_fx( wnorm, *num_bits, nb_sfm, R, Rsubband ); - } - ELSE - { - reordvct_fx( wnorm, nb_sfm, idx ); - bitalloc_fx( wnorm, idx, *num_bits, nb_sfm, QBIT_MAX2, R, sfmsize, hqswb_clas ); - bitallocsum_fx( R, nb_sfm, sum, Rsubband, *num_bits, length, sfmsize ); + move16(); } } - ELSE - { - reordvct_fx( wnorm, nb_sfm, idx ); - /* enlarge the wnorm value so that more bits can be allocated to (sfm_limit/2 ~ sfm_limit) range */ - IF( EQ_16( hqswb_clas, HQ_HARMONIC ) ) + /* Estimate number of bits per band */ + *sum = BitAllocWB_fx( wnorm, *num_bits, nb_sfm, R, Rsubband ); +} +ELSE +{ + reordvct_fx( wnorm, nb_sfm, idx ); + bitalloc_fx( wnorm, idx, *num_bits, nb_sfm, QBIT_MAX2, R, sfmsize, hqswb_clas ); + bitallocsum_fx( R, nb_sfm, sum, Rsubband, *num_bits, length, sfmsize ); +} +} +ELSE +{ + reordvct_fx( wnorm, nb_sfm, idx ); + + /* enlarge the wnorm value so that more bits can be allocated to (sfm_limit/2 ~ sfm_limit) range */ + IF( EQ_16( hqswb_clas, HQ_HARMONIC ) ) + { + tmp = shr( sfm_limit, 1 ); + tmp2 = sub( tmp, 1 ); + FOR( i = tmp; i < sfm_limit; i++ ) { - tmp = shr( sfm_limit, 1 ); - tmp2 = sub( tmp, 1 ); - FOR( i = tmp; i < sfm_limit; i++ ) - { - wnorm[i] = wnorm[tmp2]; - move16(); - } + wnorm[i] = wnorm[tmp2]; + move16(); } - bitalloc_fx( wnorm, idx, *num_bits, nb_sfm, QBIT_MAX2, R, sfmsize, hqswb_clas ); - bitallocsum_fx( R, nb_sfm, sum, Rsubband, *num_bits, length, sfmsize ); } + bitalloc_fx( wnorm, idx, *num_bits, nb_sfm, QBIT_MAX2, R, sfmsize, hqswb_clas ); + bitallocsum_fx( R, nb_sfm, sum, Rsubband, *num_bits, length, sfmsize ); +} - /* Find last coded core band */ - *core_sfm = sub( nb_sfm, 1 ); - test(); - test(); - IF( hqswb_clas == HQ_NORMAL || EQ_16( hqswb_clas, HQ_HARMONIC ) ) +/* Find last coded core band */ +*core_sfm = sub( nb_sfm, 1 ); +test(); +test(); +IF( hqswb_clas == HQ_NORMAL || EQ_16( hqswb_clas, HQ_HARMONIC ) ) +{ + *core_sfm = find_last_band_fx( R, nb_sfm ); +} +ELSE IF( EQ_16( hqswb_clas, HQ_GEN_SWB ) || EQ_16( hqswb_clas, HQ_GEN_FB ) ) +{ + *core_sfm = find_last_band_fx( R, nb_sfm ); + IF( LT_16( *core_sfm, num_env_bands ) ) { - *core_sfm = find_last_band_fx( R, nb_sfm ); - } - ELSE IF( EQ_16( hqswb_clas, HQ_GEN_SWB ) || EQ_16( hqswb_clas, HQ_GEN_FB ) ) - { - *core_sfm = find_last_band_fx( R, nb_sfm ); - IF( LT_16( *core_sfm, num_env_bands ) ) - { - *core_sfm = sub( num_env_bands, 1 ); - } + *core_sfm = sub( num_env_bands, 1 ); } +} - *num_bits = sub( *num_bits, *sum ); +*num_bits = sub( *num_bits, *sum ); - return; +return; } #endif void hq_bit_allocation_fx( - const Word32 core_brate, /* i : Core bit-rate Q0 */ - const Word16 length, /* i : Frame length Q0 */ - const Word16 hqswb_clas, /* i : HQ class Q0 */ - Word16 *num_bits, /* i/o: Remaining bit budget Q0 */ - const Word16 *normqlg2, /* i : Quantized norms Q0 */ - const Word16 nb_sfm, /* i : Number sub bands to be encoded Q0 */ - const Word16 *sfmsize, /* i : Sub band bandwidths Q0 */ - Word16 *noise_level, /* o : HVQ noise level */ - Word16 *R, /* o : Bit allocation per sub band Q0 */ - Word16 *Rsubband, /* o : Fractional bit allocation Q3 */ - Word16 *sum, /* o : Sum of allocated shape bits Q0 */ - Word16 *core_sfm, /* o : Last coded band in core Q0 */ - const Word16 num_env_bands /* i : Number sub bands to be encoded for HQ_GEN Q0 */ + const Word32 core_brate, /* i : Core bit-rate Q0 */ + const Word16 length, /* i : Frame length Q0 */ + const Word16 hqswb_clas, /* i : HQ class Q0 */ + Word16 *num_bits, /* i/o: Remaining bit budget Q0 */ + const Word16 *normqlg2, /* i : Quantized norms Q0 */ + const Word16 nb_sfm, /* i : Number sub bands to be encoded Q0 */ + const Word16 *sfmsize, /* i : Sub band bandwidths Q0 */ + Word16 *noise_level, /* o : HVQ noise level */ + Word16 *R, /* o : Bit allocation per sub band Q0 */ + Word16 *Rsubband, /* o : Fractional bit allocation Q3 */ + Word16 *sum, /* o : Sum of allocated shape bits Q0 */ + Word16 *core_sfm, /* o : Last coded band in core Q0 */ + const Word16 num_env_bands /* i : Number sub bands to be encoded for HQ_GEN Q0 */ ) { Word16 i; @@ -254,7 +252,7 @@ void hq_bit_allocation_fx( Word16 sfm_limit = nb_sfm; move16(); - set16_fx( R, 0, NB_SFM); + set16_fx( R, 0, NB_SFM ); FOR( i = 0; i < nb_sfm; i++ ) { idx[i] = i; @@ -263,35 +261,35 @@ void hq_bit_allocation_fx( test(); test(); test(); - if( NE_16(hqswb_clas, HQ_TRANSIENT)&&NE_16(hqswb_clas,HQ_HVQ)&&!(EQ_16(length,L_FRAME16k)&&EQ_32(core_brate,HQ_32k))) + if ( NE_16( hqswb_clas, HQ_TRANSIENT ) && NE_16( hqswb_clas, HQ_HVQ ) && !( EQ_16( length, L_FRAME16k ) && EQ_32( core_brate, HQ_32k ) ) ) { /* 'nf_idx' 2-bits index written later */ - *num_bits = sub(*num_bits, 2); + *num_bits = sub( *num_bits, 2 ); } test(); - IF ( EQ_16(hqswb_clas, HQ_GEN_SWB)||EQ_16(hqswb_clas,HQ_GEN_FB)) + IF( EQ_16( hqswb_clas, HQ_GEN_SWB ) || EQ_16( hqswb_clas, HQ_GEN_FB ) ) { - IF ( EQ_32(core_brate, HQ_32k)) + IF( EQ_32( core_brate, HQ_32k ) ) { - *num_bits = sub(*num_bits, HQ_GENERIC_SWB_NBITS2 ); + *num_bits = sub( *num_bits, HQ_GENERIC_SWB_NBITS2 ); } ELSE { - *num_bits = sub(*num_bits, HQ_GENERIC_SWB_NBITS ); + *num_bits = sub( *num_bits, HQ_GENERIC_SWB_NBITS ); } - if ( EQ_16(hqswb_clas, HQ_GEN_FB)) + if ( EQ_16( hqswb_clas, HQ_GEN_FB ) ) { - *num_bits = sub(*num_bits, HQ_GENERIC_FB_NBITS ); + *num_bits = sub( *num_bits, HQ_GENERIC_FB_NBITS ); } } - IF( ( EQ_16(length, L_FRAME48k))&&(NE_16(hqswb_clas,HQ_HARMONIC))&&(NE_16(hqswb_clas,HQ_HVQ))) + IF( ( EQ_16( length, L_FRAME48k ) ) && ( NE_16( hqswb_clas, HQ_HARMONIC ) ) && ( NE_16( hqswb_clas, HQ_HVQ ) ) ) { tmp = 0; move16(); - if( EQ_16(hqswb_clas,HQ_TRANSIENT)) + if ( EQ_16( hqswb_clas, HQ_TRANSIENT ) ) { tmp = 1; move16(); @@ -303,24 +301,24 @@ void hq_bit_allocation_fx( Copy( normqlg2, wnorm, nb_sfm ); } - IF( EQ_16(hqswb_clas, HQ_HARMONIC)) + IF( EQ_16( hqswb_clas, HQ_HARMONIC ) ) { /* classification and limit bandwidth for bit allocation */ - sfm_limit = sub(sfm_limit, 2); + sfm_limit = sub( sfm_limit, 2 ); limit_band_noise_level_calc_fx( wnorm, &sfm_limit, core_brate, noise_level ); /* Detect important band in high frequency region */ - E_low = sum16_fx(wnorm, SFM_G1); + E_low = sum16_fx( wnorm, SFM_G1 ); i_max = 0; move16(); E_max = MIN16B; move16(); E_hb_mean = 0; move16(); - FOR( i = SFM_G1; i < nb_sfm; i++) + FOR( i = SFM_G1; i < nb_sfm; i++ ) { - E_hb_mean = add(E_hb_mean, wnorm[i]); - IF( GT_16(wnorm[i], E_max)) + E_hb_mean = add( E_hb_mean, wnorm[i] ); + IF( GT_16( wnorm[i], E_max ) ) { E_max = wnorm[i]; move16(); @@ -328,13 +326,13 @@ void hq_bit_allocation_fx( move16(); } } - E_hb_mean = shr(E_hb_mean, 4); /* Truncated division by SFM_G1 */ - set16_fx( wnorm + sfm_limit, -20, sub(nb_sfm, sfm_limit) ); - IF (L_msu0(L_deposit_l(E_low), E_max, 15) <= 0) + E_hb_mean = shr( E_hb_mean, 4 ); /* Truncated division by SFM_G1 */ + set16_fx( wnorm + sfm_limit, -20, sub( nb_sfm, sfm_limit ) ); + IF( L_msu0( L_deposit_l( E_low ), E_max, 15 ) <= 0 ) { - IF (L_msu(L_deposit_h(E_hb_mean), E_max, 21955) <= 0) /* 21955 = 0.67 (Q15) */ + IF( L_msu( L_deposit_h( E_hb_mean ), E_max, 21955 ) <= 0 ) /* 21955 = 0.67 (Q15) */ { - if (GE_16(i_max, sfm_limit)) + if ( GE_16( i_max, sfm_limit ) ) { wnorm[i_max] = E_max; move16(); @@ -346,30 +344,30 @@ void hq_bit_allocation_fx( test(); test(); test(); - IF( EQ_16(hqswb_clas, HQ_HVQ)) + IF( EQ_16( hqswb_clas, HQ_HVQ ) ) { *sum = 0; move16(); } - ELSE IF ( EQ_16(hqswb_clas, HQ_GEN_SWB)||(EQ_16(hqswb_clas,HQ_TRANSIENT)&&EQ_16(length,L_FRAME32k)&&LE_32(core_brate,HQ_32k))) + ELSE IF( EQ_16( hqswb_clas, HQ_GEN_SWB ) || ( EQ_16( hqswb_clas, HQ_TRANSIENT ) && EQ_16( length, L_FRAME32k ) && LE_32( core_brate, HQ_32k ) ) ) { *sum = BitAllocF_fx( wnorm, core_brate, *num_bits, nb_sfm, R, Rsubband, hqswb_clas, num_env_bands ); } - ELSE IF( EQ_16(length, L_FRAME16k)&&EQ_32(core_brate,HQ_32k)) + ELSE IF( EQ_16( length, L_FRAME16k ) && EQ_32( core_brate, HQ_32k ) ) { - IF( NE_16(hqswb_clas, HQ_TRANSIENT)) + IF( NE_16( hqswb_clas, HQ_TRANSIENT ) ) { avrg_wnorm = wnorm[10]; move16(); - FOR( i=11; i<18; i++ ) + FOR( i = 11; i < 18; i++ ) { - avrg_wnorm = add(avrg_wnorm, wnorm[i]); + avrg_wnorm = add( avrg_wnorm, wnorm[i] ); } - avrg_wnorm = shr(avrg_wnorm, 3); - FOR( i=0; i<4; i++ ) + avrg_wnorm = shr( avrg_wnorm, 3 ); + FOR( i = 0; i < 4; i++ ) { - if( LT_16(wnorm[i], avrg_wnorm)) + if ( LT_16( wnorm[i], avrg_wnorm ) ) { wnorm[i] = avrg_wnorm; move16(); @@ -381,21 +379,21 @@ void hq_bit_allocation_fx( } ELSE { - reordvct_fx(wnorm, nb_sfm, idx); + reordvct_fx( wnorm, nb_sfm, idx ); bitalloc_fx( wnorm, idx, *num_bits, nb_sfm, QBIT_MAX2, R, sfmsize, hqswb_clas ); bitallocsum_fx( R, nb_sfm, sum, Rsubband, *num_bits, length, sfmsize ); } } ELSE { - reordvct_fx(wnorm, nb_sfm, idx); + reordvct_fx( wnorm, nb_sfm, idx ); /* enlarge the wnorm value so that more bits can be allocated to (sfm_limit/2 ~ sfm_limit) range */ - IF( EQ_16(hqswb_clas, HQ_HARMONIC)) + IF( EQ_16( hqswb_clas, HQ_HARMONIC ) ) { - tmp = shr(sfm_limit,1); - tmp2 = sub(tmp,1); - FOR( i=tmp; i #include "options.h" -#include "cnst.h" /* Audio core constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "cnst.h" /* Audio core constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" #endif @@ -309,23 +309,23 @@ void ivas_hq_configure_fx( #endif void hq_configure_evs_fx( - const Word16 length, /* i : Frame length Q0 */ - const Word16 hqswb_clas, /* i : HQ SWB class Q0 */ - const Word32 core_brate, /* i : Codec bitrate Q0 */ - Word16 *num_sfm, /* o : Total number of subbands Q0 */ - Word16 *nb_sfm, /* o : Total number of coded bands Q0 */ - Word16 *start_norm, /* o : First norm to be SDE encoded Q0 */ - Word16 *num_env_bands, /* o : Number coded envelope bands Q0 */ - Word16 *numnrmibits, /* o : Number of bits in fall-back norm encoding Q0 */ - Word16 *hq_generic_offset, /* o : Freq offset for HQ GENERIC Q0 */ - Word16 *sfmsize, /* o : Subband bandwidths Q0 */ - Word16 *sfm_start, /* o : Subband start coefficients Q0 */ - Word16 *sfm_end /* o : Subband end coefficients Q0 */ + const Word16 length, /* i : Frame length Q0 */ + const Word16 hqswb_clas, /* i : HQ SWB class Q0 */ + const Word32 core_brate, /* i : Codec bitrate Q0 */ + Word16 *num_sfm, /* o : Total number of subbands Q0 */ + Word16 *nb_sfm, /* o : Total number of coded bands Q0 */ + Word16 *start_norm, /* o : First norm to be SDE encoded Q0 */ + Word16 *num_env_bands, /* o : Number coded envelope bands Q0 */ + Word16 *numnrmibits, /* o : Number of bits in fall-back norm encoding Q0 */ + Word16 *hq_generic_offset, /* o : Freq offset for HQ GENERIC Q0 */ + Word16 *sfmsize, /* o : Subband bandwidths Q0 */ + Word16 *sfm_start, /* o : Subband start coefficients Q0 */ + Word16 *sfm_end /* o : Subband end coefficients Q0 */ ) { - const Word16* p_sfmsize; - const Word16* p_sfm_start; - const Word16* p_sfm_end; + const Word16 *p_sfmsize; + const Word16 *p_sfm_start; + const Word16 *p_sfm_end; Word16 i, bw_ext; bw_ext = 0; @@ -334,12 +334,12 @@ void hq_configure_evs_fx( move16(); #ifndef SOLVED_COMP_ENC_DEC - IF(EQ_16(length, L_FRAME48k)) /*tbv SOLVED_COMP_ENC_DEC*/ + IF( EQ_16( length, L_FRAME48k ) ) /*tbv SOLVED_COMP_ENC_DEC*/ #else - IF ( EQ_16(length, L_SPEC48k)) + IF( EQ_16( length, L_SPEC48k ) ) #endif { - IF ( EQ_16(hqswb_clas, HQ_GEN_FB)) + IF( EQ_16( hqswb_clas, HQ_GEN_FB ) ) { *num_sfm = NB_SFM; move16(); @@ -351,7 +351,7 @@ void hq_configure_evs_fx( move16(); test(); - IF ( GE_32(core_brate, HQ_32k)) + IF( GE_32( core_brate, HQ_32k ) ) { *hq_generic_offset = HQ_GENERIC_FOFFSET_32K; move16(); @@ -370,7 +370,7 @@ void hq_configure_evs_fx( } ELSE { - IF(EQ_16(hqswb_clas, HQ_HARMONIC)) + IF( EQ_16( hqswb_clas, HQ_HARMONIC ) ) { *num_sfm = SFM_N_HARM_FB; move16(); @@ -386,15 +386,15 @@ void hq_configure_evs_fx( p_sfm_end = band_end_harm; move16(); } - ELSE IF ( EQ_16(hqswb_clas, HQ_HVQ)) + ELSE IF( EQ_16( hqswb_clas, HQ_HVQ ) ) { - IF ( LT_32(core_brate, HQ_BWE_CROSSOVER_BRATE)) + IF( LT_32( core_brate, HQ_BWE_CROSSOVER_BRATE ) ) { *num_sfm = SFM_N_HARM_FB; move16(); *nb_sfm = HVQ_THRES_SFM_24k; move16(); - *num_env_bands = sub(*num_sfm, *nb_sfm); + *num_env_bands = sub( *num_sfm, *nb_sfm ); move16(); *start_norm = HVQ_THRES_SFM_24k; move16(); @@ -405,7 +405,7 @@ void hq_configure_evs_fx( move16(); *nb_sfm = HVQ_THRES_SFM_32k; move16(); - *num_env_bands = sub(*num_sfm, *nb_sfm); + *num_env_bands = sub( *num_sfm, *nb_sfm ); move16(); *start_norm = HVQ_THRES_SFM_32k; move16(); @@ -413,7 +413,9 @@ void hq_configure_evs_fx( p_sfmsize = band_len_harm; p_sfm_start = band_start_harm; p_sfm_end = band_end_harm; - move16();move16();move16(); + move16(); + move16(); + move16(); } ELSE { @@ -433,9 +435,9 @@ void hq_configure_evs_fx( } } } - ELSE IF( EQ_16(length, L_SPEC32k)) + ELSE IF( EQ_16( length, L_SPEC32k ) ) { - IF ( EQ_16(hqswb_clas, HQ_HARMONIC)) + IF( EQ_16( hqswb_clas, HQ_HARMONIC ) ) { *num_sfm = SFM_N_HARM; move16(); @@ -451,15 +453,15 @@ void hq_configure_evs_fx( p_sfm_end = band_end_harm; move16(); } - ELSE IF ( EQ_16(hqswb_clas, HQ_HVQ)) + ELSE IF( EQ_16( hqswb_clas, HQ_HVQ ) ) { - IF ( LT_32(core_brate, HQ_BWE_CROSSOVER_BRATE)) + IF( LT_32( core_brate, HQ_BWE_CROSSOVER_BRATE ) ) { *num_sfm = SFM_N_HARM; move16(); *nb_sfm = HVQ_THRES_SFM_24k; move16(); - *num_env_bands = sub(*num_sfm, *nb_sfm); + *num_env_bands = sub( *num_sfm, *nb_sfm ); *start_norm = HVQ_THRES_SFM_24k; move16(); @@ -470,7 +472,7 @@ void hq_configure_evs_fx( move16(); *nb_sfm = HVQ_THRES_SFM_32k; move16(); - *num_env_bands = sub(*num_sfm, *nb_sfm); + *num_env_bands = sub( *num_sfm, *nb_sfm ); *start_norm = HVQ_THRES_SFM_32k; move16(); @@ -481,9 +483,8 @@ void hq_configure_evs_fx( move16(); p_sfm_end = band_end_harm; move16(); - } - ELSE IF ( EQ_16(hqswb_clas, HQ_GEN_SWB)) + ELSE IF( EQ_16( hqswb_clas, HQ_GEN_SWB ) ) { *num_sfm = SFM_N_SWB; move16(); @@ -494,7 +495,7 @@ void hq_configure_evs_fx( p_sfm_end = band_end_HQ; move16(); - IF ( GE_32(core_brate, HQ_32k)) + IF( GE_32( core_brate, HQ_32k ) ) { *hq_generic_offset = HQ_GENERIC_FOFFSET_32K; move16(); @@ -530,23 +531,29 @@ void hq_configure_evs_fx( move16(); } } - ELSE IF (EQ_16(length, L_SPEC48k_EXT ) ) + ELSE IF( EQ_16( length, L_SPEC48k_EXT ) ) { bw_ext = 1; p_sfmsize = band_len_HQ; p_sfm_start = band_start_HQ; p_sfm_end = band_end_HQ; *num_sfm = NB_SFM; - move16(); move16(); move16(); move16(); + move16(); + move16(); + move16(); + move16(); } - ELSE IF (EQ_16(length, L_SPEC16k_EXT)) + ELSE IF( EQ_16( length, L_SPEC16k_EXT ) ) { bw_ext = 1; p_sfmsize = band_len_wb; p_sfm_start = band_start_wb; p_sfm_end = band_end_wb; *num_sfm = SFM_N_WB; - move16();move16();move16();move16(); + move16(); + move16(); + move16(); + move16(); } ELSE { @@ -564,29 +571,30 @@ void hq_configure_evs_fx( p_sfm_end = band_end_wb; move16(); } - IF (bw_ext) + IF( bw_ext ) { - FOR (i = 0; i < *num_sfm; i++) + FOR( i = 0; i < *num_sfm; i++ ) { /*sfmsize[i] = (int16_t)(1.25f * p_sfmsize[i]);*/ - sfmsize[i] = mult_r(shl(p_sfmsize[i],1),20480); + sfmsize[i] = mult_r( shl( p_sfmsize[i], 1 ), 20480 ); /*sfm_start[i] = (int16_t)(1.25f * p_sfm_start[i]);*/ - sfm_start[i] = mult_r(shl(p_sfm_start[i], 1), 20480); + sfm_start[i] = mult_r( shl( p_sfm_start[i], 1 ), 20480 ); /*sfm_end[i] = (int16_t)(1.25f * p_sfm_end[i]);*/ - sfm_end[i] = mult_r(shl(p_sfm_end[i], 1), 20480); + sfm_end[i] = mult_r( shl( p_sfm_end[i], 1 ), 20480 ); } *nb_sfm = *num_sfm; *num_env_bands = *num_sfm; - move16();move16(); + move16(); + move16(); } else { - Copy(p_sfmsize, sfmsize, *num_sfm); - Copy(p_sfm_start, sfm_start, *num_sfm); - Copy(p_sfm_end, sfm_end, *num_sfm); + Copy( p_sfmsize, sfmsize, *num_sfm ); + Copy( p_sfm_start, sfm_start, *num_sfm ); + Copy( p_sfm_end, sfm_end, *num_sfm ); } - *numnrmibits = extract_l(L_mult0(sub(*num_env_bands, 1), NORMI_BITS)); + *numnrmibits = extract_l( L_mult0( sub( *num_env_bands, 1 ), NORMI_BITS ) ); return; } diff --git a/lib_com/hq_tools_fx.c b/lib_com/hq_tools_fx.c index 2fedf796b..7e6ab6dfb 100644 --- a/lib_com/hq_tools_fx.c +++ b/lib_com/hq_tools_fx.c @@ -31,210 +31,207 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include #include -#include "options.h" /* Compilation switches */ +#include "options.h" /* Compilation switches */ #include "rom_com.h" /* Static table prototypes FIP version */ -#include "stl.h" /* required for wmc_tool */ +#include "stl.h" /* required for wmc_tool */ #include "prot_fx2.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" #endif - /*--------------------------------------------------------------------------* - * Local function prototypes - *--------------------------------------------------------------------------*/ - -static void overlap_hq_bwe_fx(const Word32 *hq_swb_overlap_buf, Word32 *coeff_out, const Word16 n_swb_overlap_offset, - const Word16 n_swb_overlap, const Word16 *R, const Word16 num_env_bands, const Word16 num_sfm, const Word16 *sfm_end); +/*--------------------------------------------------------------------------* + * Local function prototypes + *--------------------------------------------------------------------------*/ +static void overlap_hq_bwe_fx( const Word32 *hq_swb_overlap_buf, Word32 *coeff_out, const Word16 n_swb_overlap_offset, const Word16 n_swb_overlap, const Word16 *R, const Word16 num_env_bands, const Word16 num_sfm, const Word16 *sfm_end ); /*--------------------------------------------------------------------------* -* hq_swb_harmonic_calc_norm_envelop() -* -* Calculate normalization envelop -*--------------------------------------------------------------------------*/ + * hq_swb_harmonic_calc_norm_envelop() + * + * Calculate normalization envelop + *--------------------------------------------------------------------------*/ void hq_swb_harmonic_calc_norm_envelop_fx( - const Word32 *L_SWB_signal, /* i : input signal Q=12*/ - Word32 *L_envelope, /* o : output envelope Q=12*/ - const Word16 L_swb_norm, /* i : length of normaliztion */ - const Word16 SWB_flength /* i : length of input signal */ + const Word32 *L_SWB_signal, /* i : input signal Q=12*/ + Word32 *L_envelope, /* o : output envelope Q=12*/ + const Word16 L_swb_norm, /* i : length of normaliztion */ + const Word16 SWB_flength /* i : length of input signal */ ) { - Word16 lookback; - Word16 env_index; - Word16 n_freq; - Word16 n_lag_now; - Word16 n_lag; - Word16 i; - Word32 L_tmp; - - lookback = shr(L_swb_norm, 1); - env_index = 0; - move16(); - FOR(n_freq = 0; n_freq < lookback; n_freq++) - { - n_lag_now = add(lookback, n_freq); - - /* Apply MA filter */ - L_envelope[env_index] = EPSILLON_FX; - move16(); - - FOR(n_lag = 0; n_lag < n_lag_now; n_lag++) - { - L_tmp = L_abs(L_SWB_signal[n_lag]); + Word16 lookback; + Word16 env_index; + Word16 n_freq; + Word16 n_lag_now; + Word16 n_lag; + Word16 i; + Word32 L_tmp; + + lookback = shr( L_swb_norm, 1 ); + env_index = 0; + move16(); + FOR( n_freq = 0; n_freq < lookback; n_freq++ ) + { + n_lag_now = add( lookback, n_freq ); + + /* Apply MA filter */ + L_envelope[env_index] = EPSILLON_FX; + move16(); + + FOR( n_lag = 0; n_lag < n_lag_now; n_lag++ ) + { + L_tmp = L_abs( L_SWB_signal[n_lag] ); #ifdef BASOP_NOGLOB L_envelope[env_index] = L_add_sat( L_envelope[env_index], L_tmp ); #else - L_envelope[env_index] = L_add(L_envelope[env_index], L_tmp); + L_envelope[env_index] = L_add( L_envelope[env_index], L_tmp ); #endif - move32(); - } - env_index = add(env_index, 1); - } - - n_lag_now = L_swb_norm; - move16(); - - FOR(n_freq = 0; n_freq < SWB_flength - L_swb_norm; n_freq++) - { - /* Apply MA filter */ - L_envelope[env_index] = EPSILLON_FX; - move16(); - FOR(n_lag = 0; n_lag < n_lag_now; n_lag++) - { - L_tmp = L_abs(L_SWB_signal[add(n_freq, n_lag)]); + move32(); + } + env_index = add( env_index, 1 ); + } + + n_lag_now = L_swb_norm; + move16(); + + FOR( n_freq = 0; n_freq < SWB_flength - L_swb_norm; n_freq++ ) + { + /* Apply MA filter */ + L_envelope[env_index] = EPSILLON_FX; + move16(); + FOR( n_lag = 0; n_lag < n_lag_now; n_lag++ ) + { + L_tmp = L_abs( L_SWB_signal[add( n_freq, n_lag )] ); #ifdef BASOP_NOGLOB L_envelope[env_index] = L_add_sat( L_envelope[env_index], L_tmp ); #else - L_envelope[env_index] = L_add(L_envelope[env_index], L_tmp); + L_envelope[env_index] = L_add( L_envelope[env_index], L_tmp ); #endif - move32(); - } - env_index = add(env_index, 1); - } - - i = 0; - move16(); - FOR(n_freq = SWB_flength - L_swb_norm; n_freq < SWB_flength - lookback; n_freq++) - { - n_lag_now = sub(L_swb_norm, i); - - /* Apply MA filter */ - L_envelope[env_index] = L_deposit_l(EPSILLON_FX); - FOR(n_lag = 0; n_lag < n_lag_now; n_lag++) - { - L_tmp = L_abs(L_SWB_signal[add(n_freq, n_lag)]); + move32(); + } + env_index = add( env_index, 1 ); + } + + i = 0; + move16(); + FOR( n_freq = SWB_flength - L_swb_norm; n_freq < SWB_flength - lookback; n_freq++ ) + { + n_lag_now = sub( L_swb_norm, i ); + + /* Apply MA filter */ + L_envelope[env_index] = L_deposit_l( EPSILLON_FX ); + FOR( n_lag = 0; n_lag < n_lag_now; n_lag++ ) + { + L_tmp = L_abs( L_SWB_signal[add( n_freq, n_lag )] ); #ifdef BASOP_NOGLOB - L_envelope[env_index] = L_add_sat( L_envelope[env_index], L_tmp ); + L_envelope[env_index] = L_add_sat( L_envelope[env_index], L_tmp ); #else - L_envelope[env_index] = L_add(L_envelope[env_index], L_tmp); + L_envelope[env_index] = L_add( L_envelope[env_index], L_tmp ); #endif - move32(); - } - env_index = add(env_index, 1); - i = add(i, 1); - } + move32(); + } + env_index = add( env_index, 1 ); + i = add( i, 1 ); + } - return; + return; } /*--------------------------------------------------------------------------* -* noise_level_calc_fx() -* -* Calculate noise level and limited band -*--------------------------------------------------------------------------*/ + * noise_level_calc_fx() + * + * Calculate noise level and limited band + *--------------------------------------------------------------------------*/ void limit_band_noise_level_calc_fx( - const Word16 *wnorm, /* i : reordered norm of sub-vectors */ - Word16 *limit, /* o : highest band of bit allocation */ - const Word32 core_brate, /* i : bit rate */ - Word16 *noise_level /* o : noise level Q15 */ + const Word16 *wnorm, /* i : reordered norm of sub-vectors */ + Word16 *limit, /* o : highest band of bit allocation */ + const Word32 core_brate, /* i : bit rate */ + Word16 *noise_level /* o : noise level Q15 */ ) { - Word16 ener_limit, ener_sum; - Word16 i; - Word16 nb_sfm; - Word32 fact; - Word16 tmp; - - nb_sfm = *limit; - move16(); - ener_limit = 0; - move16(); - *noise_level = 0; - move16(); - FOR(i = 0; i < 10; i++) - { - ener_limit = add(ener_limit, wnorm[i]); - *noise_level = add(*noise_level, abs_s(sub(wnorm[i + 1], wnorm[i]))); - move16(); - - } - ener_sum = ener_limit; - move16(); - - tmp = sub(nb_sfm, 1); - FOR(i = 10; i < tmp; i++) - { - ener_sum = add(ener_sum, wnorm[i]); - *noise_level = add(*noise_level, abs_s(sub(wnorm[i + 1], wnorm[i]))); - move16(); - } - ener_sum = add(ener_sum, wnorm[nb_sfm - 1]); - - - fact = 2022929597; - move32(); - if (LT_32(core_brate, HQ_BWE_CROSSOVER_BRATE)) - { - fact = L_add(1900523029, 1); - } - - fact = Mult_32_16(fact, ener_sum); - i = 9; - move16(); - test(); - WHILE(LT_32(L_deposit_h(ener_limit), fact) && LT_16(add(i, 1), nb_sfm)) - { - ener_limit = add(ener_limit, wnorm[++i]); - test(); - } - *limit = i; - move16(); - - /* calculate noise level for spectrum filling */ - if (*noise_level < 0) - { - *noise_level = 0; - move16(); - } - - IF(GE_16(*noise_level, shr(ener_sum, 2))) - { - *noise_level = 0; - move16(); - } - ELSE - { - IF(ener_sum != 0) - { - *noise_level = sub(8192, div_s(*noise_level, ener_sum)); - } - ELSE - { - *noise_level = 8192; - } - move16(); - } - - return; + Word16 ener_limit, ener_sum; + Word16 i; + Word16 nb_sfm; + Word32 fact; + Word16 tmp; + + nb_sfm = *limit; + move16(); + ener_limit = 0; + move16(); + *noise_level = 0; + move16(); + FOR( i = 0; i < 10; i++ ) + { + ener_limit = add( ener_limit, wnorm[i] ); + *noise_level = add( *noise_level, abs_s( sub( wnorm[i + 1], wnorm[i] ) ) ); + move16(); + } + ener_sum = ener_limit; + move16(); + + tmp = sub( nb_sfm, 1 ); + FOR( i = 10; i < tmp; i++ ) + { + ener_sum = add( ener_sum, wnorm[i] ); + *noise_level = add( *noise_level, abs_s( sub( wnorm[i + 1], wnorm[i] ) ) ); + move16(); + } + ener_sum = add( ener_sum, wnorm[nb_sfm - 1] ); + + + fact = 2022929597; + move32(); + if ( LT_32( core_brate, HQ_BWE_CROSSOVER_BRATE ) ) + { + fact = L_add( 1900523029, 1 ); + } + + fact = Mult_32_16( fact, ener_sum ); + i = 9; + move16(); + test(); + WHILE( LT_32( L_deposit_h( ener_limit ), fact ) && LT_16( add( i, 1 ), nb_sfm ) ) + { + ener_limit = add( ener_limit, wnorm[++i] ); + test(); + } + *limit = i; + move16(); + + /* calculate noise level for spectrum filling */ + if ( *noise_level < 0 ) + { + *noise_level = 0; + move16(); + } + + IF( GE_16( *noise_level, shr( ener_sum, 2 ) ) ) + { + *noise_level = 0; + move16(); + } + ELSE + { + IF( ener_sum != 0 ) + { + *noise_level = sub( 8192, div_s( *noise_level, ener_sum ) ); + } + ELSE + { + *noise_level = 8192; + } + move16(); + } + + return; } /*--------------------------------------------------------------------------* @@ -244,141 +241,141 @@ void limit_band_noise_level_calc_fx( * NOTE: Q values preliminary *--------------------------------------------------------------------------*/ -Word16 build_nf_codebook_fx( /* o : Number of coefficients in nf codebook Q=0*/ - const Word16 flag_32K_env_ho, /* i : Envelope attenuation hangover flag Q=0*/ - const Word16 *coeff, /* i : Coded spectral coefficients Q=12*/ - const Word16 *sfm_start, /* i : Subband start indices Q=0*/ - const Word16 *sfmsize, /* i : Subband widths Q=0*/ - const Word16 *sfm_end, /* i : Subband end indices Q=0*/ - const Word16 last_sfm, /* i : Last coded band Q=0*/ - const Word16 *R, /* i : Per-band bit allocation Q=0*/ - Word16 *CodeBook, /* o : Noise-fill codebook Q=12*/ - Word16 *CodeBook_mod /* o : Densified noise-fill codebook Q=12*/ +Word16 build_nf_codebook_fx( /* o : Number of coefficients in nf codebook Q=0*/ + const Word16 flag_32K_env_ho, /* i : Envelope attenuation hangover flag Q=0*/ + const Word16 *coeff, /* i : Coded spectral coefficients Q=12*/ + const Word16 *sfm_start, /* i : Subband start indices Q=0*/ + const Word16 *sfmsize, /* i : Subband widths Q=0*/ + const Word16 *sfm_end, /* i : Subband end indices Q=0*/ + const Word16 last_sfm, /* i : Last coded band Q=0*/ + const Word16 *R, /* i : Per-band bit allocation Q=0*/ + Word16 *CodeBook, /* o : Noise-fill codebook Q=12*/ + Word16 *CodeBook_mod /* o : Densified noise-fill codebook Q=12*/ ) { - Word16 sfm_base; - Word16 sfm; - Word16 E_cb_vec; - Word16 i, j; - Word16 cb_size; - - /* Build codebook */ - - cb_size = 0; - move16(); - - FOR(sfm = 0; sfm <= last_sfm; sfm++) - { - IF(R[sfm] != 0) - { - IF(flag_32K_env_ho) - { - /* Build compressed (+/- 1) noise-fill codebook */ - sfm_base = sfm_start[sfm]; - move16(); - FOR(i = 0; i < sfmsize[sfm] / 8; i++) - { - E_cb_vec = 0; - move16(); - FOR(j = sfm_base + i * 8; j < sfm_base + (i + 1) * 8; j++) - { - IF(coeff[j] > 0) - { - CodeBook_mod[cb_size] = 1 << 12; - move16(); /* set to 1, Q value 12 */ - E_cb_vec = add(E_cb_vec, 1); - } - ELSE IF(coeff[j] < 0) - { - CodeBook_mod[cb_size] = -1 * (1 << 12); - move16(); /* set to -1, Q value 12 */ - E_cb_vec = add(E_cb_vec, 1); - } - ELSE - { - CodeBook_mod[cb_size] = 0; - move16(); - } - cb_size = add(cb_size, 1); - } - - if (E_cb_vec < 2) - { - cb_size = sub(cb_size, 8); - } - } - } - ELSE - { - FOR(j = sfm_start[sfm]; j < sfm_end[sfm]; j++) - { - CodeBook[cb_size] = coeff[j]; - move16(); - cb_size = add(cb_size,1); - } - } - } - } - - IF(flag_32K_env_ho) - { - FOR(j = 0; j < cb_size; j++) - { - IF(CodeBook_mod[j] != 0) - { - /* Densify codebook */ - CodeBook[j] = -4096; - move16(); /* -1 in Q12 */ - if (CodeBook_mod[j] > 0) - { - CodeBook[j] = 4096; - move16(); /* 1 in Q12 */ - } - - IF(CodeBook_mod[cb_size - j - 1] != 0) - { - CodeBook[j] = shl(CodeBook[j], 1); - move16(); /* Mult by 2 */ - } - } - ELSE - { - CodeBook[j] = CodeBook_mod[cb_size - j - 1]; - move16(); - } - } - } - - return cb_size; + Word16 sfm_base; + Word16 sfm; + Word16 E_cb_vec; + Word16 i, j; + Word16 cb_size; + + /* Build codebook */ + + cb_size = 0; + move16(); + + FOR( sfm = 0; sfm <= last_sfm; sfm++ ) + { + IF( R[sfm] != 0 ) + { + IF( flag_32K_env_ho ) + { + /* Build compressed (+/- 1) noise-fill codebook */ + sfm_base = sfm_start[sfm]; + move16(); + FOR( i = 0; i < sfmsize[sfm] / 8; i++ ) + { + E_cb_vec = 0; + move16(); + FOR( j = sfm_base + i * 8; j < sfm_base + ( i + 1 ) * 8; j++ ) + { + IF( coeff[j] > 0 ) + { + CodeBook_mod[cb_size] = 1 << 12; + move16(); /* set to 1, Q value 12 */ + E_cb_vec = add( E_cb_vec, 1 ); + } + ELSE IF( coeff[j] < 0 ) + { + CodeBook_mod[cb_size] = -1 * ( 1 << 12 ); + move16(); /* set to -1, Q value 12 */ + E_cb_vec = add( E_cb_vec, 1 ); + } + ELSE + { + CodeBook_mod[cb_size] = 0; + move16(); + } + cb_size = add( cb_size, 1 ); + } + + if ( E_cb_vec < 2 ) + { + cb_size = sub( cb_size, 8 ); + } + } + } + ELSE + { + FOR( j = sfm_start[sfm]; j < sfm_end[sfm]; j++ ) + { + CodeBook[cb_size] = coeff[j]; + move16(); + cb_size = add( cb_size, 1 ); + } + } + } + } + + IF( flag_32K_env_ho ) + { + FOR( j = 0; j < cb_size; j++ ) + { + IF( CodeBook_mod[j] != 0 ) + { + /* Densify codebook */ + CodeBook[j] = -4096; + move16(); /* -1 in Q12 */ + if ( CodeBook_mod[j] > 0 ) + { + CodeBook[j] = 4096; + move16(); /* 1 in Q12 */ + } + + IF( CodeBook_mod[cb_size - j - 1] != 0 ) + { + CodeBook[j] = shl( CodeBook[j], 1 ); + move16(); /* Mult by 2 */ + } + } + ELSE + { + CodeBook[j] = CodeBook_mod[cb_size - j - 1]; + move16(); + } + } + } + + return cb_size; } /*--------------------------------------------------------------------------* -* find_last_band() -* -* Find the last band which has bits allocated -*--------------------------------------------------------------------------*/ - -Word16 find_last_band_fx( /* o : index of last band */ - const Word16 *bitalloc, /* i : bit allocation */ - const Word16 nb_sfm /* i : number of possibly coded bands */ + * find_last_band() + * + * Find the last band which has bits allocated + *--------------------------------------------------------------------------*/ + +Word16 find_last_band_fx( /* o : index of last band */ + const Word16 *bitalloc, /* i : bit allocation */ + const Word16 nb_sfm /* i : number of possibly coded bands */ ) { - Word16 sfm, core_sfm; + Word16 sfm, core_sfm; - core_sfm = sub(nb_sfm, 1); + core_sfm = sub( nb_sfm, 1 ); - FOR(sfm = nb_sfm - 1; sfm >= 0; sfm--) - { - IF(bitalloc[sfm] != 0) - { - core_sfm = sfm; - move16(); - BREAK; - } - } + FOR( sfm = nb_sfm - 1; sfm >= 0; sfm-- ) + { + IF( bitalloc[sfm] != 0 ) + { + core_sfm = sfm; + move16(); + BREAK; + } + } - return core_sfm; + return core_sfm; } /*--------------------------------------------------------------------------* @@ -388,110 +385,110 @@ Word16 find_last_band_fx( /* o : index of last band */ *--------------------------------------------------------------------------*/ void apply_noisefill_HQ_fx( - const Word16 *R, /* i : bit allocation Q0 */ - const Word16 length, /* i : input frame length Q0 */ - const Word16 flag_32K_env_ho,/* i : envelope stability hangover flag Q0 */ - const Word32 L_core_brate, /* i : core bit rate Q0 */ - const Word16 last_sfm, /* i : last coded subband Q0 */ - const Word16 *CodeBook, /* i : Noise-fill codebook Q12 */ - const Word16 *CodeBook_mod, /* i : Densified noise-fill codebook Q12 */ - const Word16 cb_size, /* i : Codebook length Q0 */ - const Word16 *sfm_start, /* i : Subband start coefficient Q0 */ - const Word16 *sfm_end, /* i : Subband end coefficient Q0 */ - const Word16 *sfmsize, /* i : Subband band width Q0 */ - Word16 *coeff /* i/o: coded/noisefilled spectrum Q12 */ + const Word16 *R, /* i : bit allocation Q0 */ + const Word16 length, /* i : input frame length Q0 */ + const Word16 flag_32K_env_ho, /* i : envelope stability hangover flag Q0 */ + const Word32 L_core_brate, /* i : core bit rate Q0 */ + const Word16 last_sfm, /* i : last coded subband Q0 */ + const Word16 *CodeBook, /* i : Noise-fill codebook Q12 */ + const Word16 *CodeBook_mod, /* i : Densified noise-fill codebook Q12 */ + const Word16 cb_size, /* i : Codebook length Q0 */ + const Word16 *sfm_start, /* i : Subband start coefficient Q0 */ + const Word16 *sfm_end, /* i : Subband end coefficient Q0 */ + const Word16 *sfmsize, /* i : Subband band width Q0 */ + Word16 *coeff /* i/o: coded/noisefilled spectrum Q12 */ ) { - Word16 sfm; - Word16 cb_pos; - Word16 E_corr; - Word16 cb_buff[PVQ_MAX_BAND_SIZE]; - Word16 i, j; - Word16 istart; - UWord16 lsb; - Word32 L_E_cb_vec; - Word32 L_E_corr; - - test(); - test(); - IF((GE_16(length, L_FRAME32k)) || (NE_32(L_core_brate, HQ_32k))) - { - /* Read from codebook */ - cb_pos = 0; - move16(); - - FOR(sfm = 0; sfm <= last_sfm; sfm++) - { - IF(R[sfm] == 0) - { - IF(EQ_16(flag_32K_env_ho, 1)) - { - L_E_cb_vec = L_deposit_l(0); - IF(LT_16(sfm, 20)) - { - FOR(i = 0; i < sfmsize[sfm]; i++) - { - cb_buff[i] = CodeBook_mod[cb_pos++]; - move16(); - L_E_cb_vec = L_mac0(L_E_cb_vec, cb_buff[i], cb_buff[i]); /*Q24 (12+12) */ - - if (GE_16(cb_pos, cb_size)) - { - cb_pos = 0; - move16(); - } - } - } - ELSE - { - FOR(i = 0; i < sfmsize[sfm]; i++) - { - cb_buff[i] = CodeBook[cb_pos++]; - move16(); - L_E_cb_vec = L_mac0(L_E_cb_vec, cb_buff[i], cb_buff[i]); /*Q24 (12+12) */ - - if (GE_16(cb_pos, cb_size)) - { - cb_pos = 0; - move16(); - } - } - } - - /*E_corr = E_cb_vec / ((float) sfmsize[sfm]); */ - Mpy_32_16_ss(L_E_cb_vec, inv_tbl_fx[sfmsize[sfm]], &L_E_corr, &lsb); /*Q24 (24+15+1-16) */ - move16(); - - /*E_corr = 1.0f / (float)sqrt(E_corr); */ - L_E_corr = Isqrt(L_E_corr); /*Q19 (31-24/2) */ - E_corr = extract_h(L_shl(L_E_corr, 10)); /*Q13 (13-(19-16)) */ - - istart = sfm_start[sfm]; - move16(); - FOR(j = istart; j < sfm_end[sfm]; j++) - { - /*coeff[j] = cb_buff[j - istart] * E_corr; */ - coeff[j] = extract_h(L_shl(L_mult(cb_buff[j - istart], E_corr), 2)); /*Q12 (12+13+1+2-16) */ - } - } - ELSE - { - FOR(j = sfm_start[sfm]; j < sfm_end[sfm]; j++) - { - coeff[j] = CodeBook[cb_pos++]; - move16(); - if (GE_16(cb_pos, cb_size)) - { - cb_pos = 0; - move16(); - } - } - } - } - } - } - - return; + Word16 sfm; + Word16 cb_pos; + Word16 E_corr; + Word16 cb_buff[PVQ_MAX_BAND_SIZE]; + Word16 i, j; + Word16 istart; + UWord16 lsb; + Word32 L_E_cb_vec; + Word32 L_E_corr; + + test(); + test(); + IF( ( GE_16( length, L_FRAME32k ) ) || ( NE_32( L_core_brate, HQ_32k ) ) ) + { + /* Read from codebook */ + cb_pos = 0; + move16(); + + FOR( sfm = 0; sfm <= last_sfm; sfm++ ) + { + IF( R[sfm] == 0 ) + { + IF( EQ_16( flag_32K_env_ho, 1 ) ) + { + L_E_cb_vec = L_deposit_l( 0 ); + IF( LT_16( sfm, 20 ) ) + { + FOR( i = 0; i < sfmsize[sfm]; i++ ) + { + cb_buff[i] = CodeBook_mod[cb_pos++]; + move16(); + L_E_cb_vec = L_mac0( L_E_cb_vec, cb_buff[i], cb_buff[i] ); /*Q24 (12+12) */ + + if ( GE_16( cb_pos, cb_size ) ) + { + cb_pos = 0; + move16(); + } + } + } + ELSE + { + FOR( i = 0; i < sfmsize[sfm]; i++ ) + { + cb_buff[i] = CodeBook[cb_pos++]; + move16(); + L_E_cb_vec = L_mac0( L_E_cb_vec, cb_buff[i], cb_buff[i] ); /*Q24 (12+12) */ + + if ( GE_16( cb_pos, cb_size ) ) + { + cb_pos = 0; + move16(); + } + } + } + + /*E_corr = E_cb_vec / ((float) sfmsize[sfm]); */ + Mpy_32_16_ss( L_E_cb_vec, inv_tbl_fx[sfmsize[sfm]], &L_E_corr, &lsb ); /*Q24 (24+15+1-16) */ + move16(); + + /*E_corr = 1.0f / (float)sqrt(E_corr); */ + L_E_corr = Isqrt( L_E_corr ); /*Q19 (31-24/2) */ + E_corr = extract_h( L_shl( L_E_corr, 10 ) ); /*Q13 (13-(19-16)) */ + + istart = sfm_start[sfm]; + move16(); + FOR( j = istart; j < sfm_end[sfm]; j++ ) + { + /*coeff[j] = cb_buff[j - istart] * E_corr; */ + coeff[j] = extract_h( L_shl( L_mult( cb_buff[j - istart], E_corr ), 2 ) ); /*Q12 (12+13+1+2-16) */ + } + } + ELSE + { + FOR( j = sfm_start[sfm]; j < sfm_end[sfm]; j++ ) + { + coeff[j] = CodeBook[cb_pos++]; + move16(); + if ( GE_16( cb_pos, cb_size ) ) + { + cb_pos = 0; + move16(); + } + } + } + } + } + } + + return; } /*--------------------------------------------------------------------------* @@ -501,126 +498,124 @@ void apply_noisefill_HQ_fx( *--------------------------------------------------------------------------*/ void harm_bwe_fine_fx( - const Word16 *R, /* i : bit allocation */ - const Word16 last_sfm, /* i : last coded subband */ - const Word16 high_sfm, /* i : higher transition band to BWE */ - const Word16 num_sfm, /* i : total number of bands */ - const Word16 *norm, /* i : quantization indices for norms */ - const Word16 *sfm_start, /* i : Subband start coefficient */ - const Word16 *sfm_end, /* i : Subband end coefficient */ - Word16 *prev_L_swb_norm, /* i/o: last normalize length */ - Word16 *coeff, /* i/o: coded/noisefilled normalized spectrum */ - Word32 *coeff_out, /* o : coded/noisefilled spectrum */ - Word16 *coeff_fine /* o : BWE fine structure */ + const Word16 *R, /* i : bit allocation */ + const Word16 last_sfm, /* i : last coded subband */ + const Word16 high_sfm, /* i : higher transition band to BWE */ + const Word16 num_sfm, /* i : total number of bands */ + const Word16 *norm, /* i : quantization indices for norms */ + const Word16 *sfm_start, /* i : Subband start coefficient */ + const Word16 *sfm_end, /* i : Subband end coefficient */ + Word16 *prev_L_swb_norm, /* i/o: last normalize length */ + Word16 *coeff, /* i/o: coded/noisefilled normalized spectrum */ + Word32 *coeff_out, /* o : coded/noisefilled spectrum */ + Word16 *coeff_fine /* o : BWE fine structure */ ) { - Word16 sfm; - Word16 i; - Word32 normq; - Word16 SWB_signal[L_HARMONIC_EXC]; - Word32 envelope[L_HARMONIC_EXC], L_signal[L_HARMONIC_EXC]; - Word16 enve_lo[L_HARMONIC_EXC], enve_hi[L_HARMONIC_EXC]; - Word16 *src, *dst, *end; - Word16 norm_signal; - - Word16 norm_width = 64; - move16(); - - /* shape the spectrum */ - FOR(sfm = 0; sfm <= last_sfm; sfm++) - { - IF(R[sfm] != 0) - { - normq = dicn_fx[norm[sfm]]; - move32(); - - FOR(i = sfm_start[sfm]; i < sfm_end[sfm]; i++) - { - coeff_out[i] = L_shl(Mult_32_16(normq, coeff[i]), 1); /*12 14+12+1+1-16 */ - move32(); - } - } - ELSE - { - FOR(i = sfm_start[sfm]; i < sfm_end[sfm]; i++) - { - coeff_out[i] = L_deposit_l(0); - } - } - } - - /* excitation replication */ - Copy32(coeff_out, L_signal, L_HARMONIC_EXC); - calc_normal_length_fx_32(HQ_CORE, coeff_out, HQ_HARMONIC, -1, &norm_width, prev_L_swb_norm); - hq_swb_harmonic_calc_norm_envelop_fx(L_signal, envelope, norm_width, L_HARMONIC_EXC); - - /* Normalize with envelope */ - FOR(i = 0; i < L_HARMONIC_EXC; i++) - { - IF(L_signal[i] > 0) - { - norm_signal = norm_l(envelope[i]); - enve_lo[i] = L_Extract_lc(L_shl(envelope[i], norm_signal), &enve_hi[i]); - L_signal[i] = Div_32(L_signal[i], enve_hi[i], enve_lo[i]); + Word16 sfm; + Word16 i; + Word32 normq; + Word16 SWB_signal[L_HARMONIC_EXC]; + Word32 envelope[L_HARMONIC_EXC], L_signal[L_HARMONIC_EXC]; + Word16 enve_lo[L_HARMONIC_EXC], enve_hi[L_HARMONIC_EXC]; + Word16 *src, *dst, *end; + Word16 norm_signal; + + Word16 norm_width = 64; + move16(); + + /* shape the spectrum */ + FOR( sfm = 0; sfm <= last_sfm; sfm++ ) + { + IF( R[sfm] != 0 ) + { + normq = dicn_fx[norm[sfm]]; + move32(); + + FOR( i = sfm_start[sfm]; i < sfm_end[sfm]; i++ ) + { + coeff_out[i] = L_shl( Mult_32_16( normq, coeff[i] ), 1 ); /*12 14+12+1+1-16 */ + move32(); + } + } + ELSE + { + FOR( i = sfm_start[sfm]; i < sfm_end[sfm]; i++ ) + { + coeff_out[i] = L_deposit_l( 0 ); + } + } + } + + /* excitation replication */ + Copy32( coeff_out, L_signal, L_HARMONIC_EXC ); + calc_normal_length_fx_32( HQ_CORE, coeff_out, HQ_HARMONIC, -1, &norm_width, prev_L_swb_norm ); + hq_swb_harmonic_calc_norm_envelop_fx( L_signal, envelope, norm_width, L_HARMONIC_EXC ); + + /* Normalize with envelope */ + FOR( i = 0; i < L_HARMONIC_EXC; i++ ) + { + IF( L_signal[i] > 0 ) + { + norm_signal = norm_l( envelope[i] ); + enve_lo[i] = L_Extract_lc( L_shl( envelope[i], norm_signal ), &enve_hi[i] ); + L_signal[i] = Div_32( L_signal[i], enve_hi[i], enve_lo[i] ); #ifdef BASOP_NOGLOB - SWB_signal[i] = round_fx_sat(L_shl_sat(L_signal[i], norm_signal)); + SWB_signal[i] = round_fx_sat( L_shl_sat( L_signal[i], norm_signal ) ); #else - SWB_signal[i] = round_fx(L_shl(L_signal[i], norm_signal)); + SWB_signal[i] = round_fx( L_shl( L_signal[i], norm_signal ) ); #endif - move16(); - move16(); - move32(); - - } - ELSE - { - norm_signal = norm_l(envelope[i]); - enve_lo[i] = L_Extract_lc(L_shl(envelope[i], norm_signal), &enve_hi[i]); - L_signal[i] = L_negate(Div_32(L_negate(L_signal[i]), enve_hi[i], enve_lo[i])); + move16(); + move16(); + move32(); + } + ELSE + { + norm_signal = norm_l( envelope[i] ); + enve_lo[i] = L_Extract_lc( L_shl( envelope[i], norm_signal ), &enve_hi[i] ); + L_signal[i] = L_negate( Div_32( L_negate( L_signal[i] ), enve_hi[i], enve_lo[i] ) ); #ifdef BASOP_NOGLOB - SWB_signal[i] = round_fx_sat(L_shl_sat(L_signal[i], norm_signal)); + SWB_signal[i] = round_fx_sat( L_shl_sat( L_signal[i], norm_signal ) ); #else - SWB_signal[i] = round_fx(L_shl(L_signal[i], norm_signal)); + SWB_signal[i] = round_fx( L_shl( L_signal[i], norm_signal ) ); #endif - move16(); - move16(); - move32(); - - } - } - - dst = coeff_fine + sfm_end[last_sfm]; - end = coeff_fine + sfm_end[num_sfm - 1]; - - IF(LE_16(sub(sfm_end[last_sfm], sfm_end[high_sfm]), (L_HARMONIC_EXC - START_EXC))) - { - src = SWB_signal + START_EXC + sub(sfm_end[last_sfm], sfm_end[high_sfm]); - } - ELSE - { - src = SWB_signal + L_HARMONIC_EXC - 1; - } - - WHILE(dst < end) - { - logic32(); - WHILE(dst < end && src < &SWB_signal[L_HARMONIC_EXC]) - { - *dst++ = *src++; - move16(); - } - src--; - - logic32(); - WHILE(dst < end && src >= &SWB_signal[START_EXC]) - { - *dst++ = *src--; - move16(); - } - src++; - } - - return; + move16(); + move16(); + move32(); + } + } + + dst = coeff_fine + sfm_end[last_sfm]; + end = coeff_fine + sfm_end[num_sfm - 1]; + + IF( LE_16( sub( sfm_end[last_sfm], sfm_end[high_sfm] ), ( L_HARMONIC_EXC - START_EXC ) ) ) + { + src = SWB_signal + START_EXC + sub( sfm_end[last_sfm], sfm_end[high_sfm] ); + } + ELSE + { + src = SWB_signal + L_HARMONIC_EXC - 1; + } + + WHILE( dst < end ) + { + logic32(); + WHILE( dst < end && src < &SWB_signal[L_HARMONIC_EXC] ) + { + *dst++ = *src++; + move16(); + } + src--; + + logic32(); + WHILE( dst < end && src >= &SWB_signal[START_EXC] ) + { + *dst++ = *src--; + move16(); + } + src++; + } + + return; } /*--------------------------------------------------------------------------* @@ -630,124 +625,123 @@ void harm_bwe_fine_fx( *--------------------------------------------------------------------------*/ void hvq_bwe_fine_fx( - const Word16 last_sfm, /* i : last coded subband Q0 */ - const Word16 num_sfm, /* i : total number of bands Q0 */ - const Word16 *sfm_end, /* i : Subband end coefficient Q0 */ - const Word16 *peak_idx, /* i : Peak index Q0 */ - const Word16 Npeaks, /* i : Number of peaks Q0 */ - Word16 *peak_pos, /* o : Peak positions Q0 */ - Word16 *prev_L_swb_norm, /* i/o: last normalize length Q0 */ - Word32 *L_coeff, /* i : coded/noisefilled normalized spectrum Q12 */ - Word16 *bwe_peaks, /* o : Positions of peaks in BWE Q0 */ - Word16 *coeff_fine /* o : HVQ BWE fine structure Q15 */ + const Word16 last_sfm, /* i : last coded subband Q0 */ + const Word16 num_sfm, /* i : total number of bands Q0 */ + const Word16 *sfm_end, /* i : Subband end coefficient Q0 */ + const Word16 *peak_idx, /* i : Peak index Q0 */ + const Word16 Npeaks, /* i : Number of peaks Q0 */ + Word16 *peak_pos, /* o : Peak positions Q0 */ + Word16 *prev_L_swb_norm, /* i/o: last normalize length Q0 */ + Word32 *L_coeff, /* i : coded/noisefilled normalized spectrum Q12 */ + Word16 *bwe_peaks, /* o : Positions of peaks in BWE Q0 */ + Word16 *coeff_fine /* o : HVQ BWE fine structure Q15 */ ) { - Word16 i, j; - Word16 SWB_signal[L_HARMONIC_EXC]; - Word32 L_envelope[L_HARMONIC_EXC]; - Word16 *src, *dst, *end; - Word16 *peak_dst, *peak_src; - Word16 norm_width = 64; - Word16 tmp; - Word16 shift, shift2; - Word32 L_tmp; - UWord16 lsb; - - calc_normal_length_fx_32(HQ_CORE, L_coeff, HQ_HVQ, -1, &norm_width, prev_L_swb_norm); - - hq_swb_harmonic_calc_norm_envelop_fx(L_coeff, L_envelope, norm_width, L_HARMONIC_EXC); - - /* Normalize with envelope */ - FOR(i = 0; i < L_HARMONIC_EXC; i++) - { - /*SWB_signal[i] = SWB_signal[i] / envelope[i]; */ - - shift = norm_l(L_envelope[i]); + Word16 i, j; + Word16 SWB_signal[L_HARMONIC_EXC]; + Word32 L_envelope[L_HARMONIC_EXC]; + Word16 *src, *dst, *end; + Word16 *peak_dst, *peak_src; + Word16 norm_width = 64; + Word16 tmp; + Word16 shift, shift2; + Word32 L_tmp; + UWord16 lsb; + + calc_normal_length_fx_32( HQ_CORE, L_coeff, HQ_HVQ, -1, &norm_width, prev_L_swb_norm ); + + hq_swb_harmonic_calc_norm_envelop_fx( L_coeff, L_envelope, norm_width, L_HARMONIC_EXC ); + + /* Normalize with envelope */ + FOR( i = 0; i < L_HARMONIC_EXC; i++ ) + { + /*SWB_signal[i] = SWB_signal[i] / envelope[i]; */ + + shift = norm_l( L_envelope[i] ); #ifdef BASOP_NOGLOB - tmp = round_fx_sat(L_shl_sat(L_envelope[i], shift)); /* 12+s-16=Q(-4+s) */ + tmp = round_fx_sat( L_shl_sat( L_envelope[i], shift ) ); /* 12+s-16=Q(-4+s) */ #else - tmp = round_fx(L_shl(L_envelope[i], shift)); /* 12+s-16=Q(-4+s) */ + tmp = round_fx( L_shl( L_envelope[i], shift ) ); /* 12+s-16=Q(-4+s) */ #endif - /* Avoid division by zero */ - if (tmp == 0) - { - tmp = 1 << 14; - move16(); - } - - tmp = div_s(1 << 14, tmp); /* 15+14-(-4+s)=Q(33-s) */ - Mpy_32_16_ss(L_coeff[i], tmp, &L_tmp, &lsb); /* 12+33-s+1-16=Q(30-s) */ - shift2 = add(shift, 1); - tmp = round_fx(L_shl(L_tmp, shift2)); /* 30-s+s+1-16=Q(15) */ - SWB_signal[i] = add(tmp, lshr(lsb, sub(32, shift2))); - move16(); /* Q15 */ - /*SWB_signal[i] = round_fx(L_shl(L_tmp, add(shift, 1))); // 30-s+s+1-16=Q(15) */ - - } - - dst = coeff_fine; - end = coeff_fine + sfm_end[num_sfm - 1] - sfm_end[last_sfm]; - - src = SWB_signal + START_EXC; - peak_src = peak_pos + START_EXC; - - FOR(i = 0; i < Npeaks; i++) - { - if (LT_16(peak_idx[i], L_HARMONIC_EXC)) - { - peak_pos[peak_idx[i]] = 1; - move16(); - } - } - - i = sub(L_HARMONIC_EXC, 1); - WHILE(i-- > 0) - { - IF(EQ_16(peak_pos[i], 1)) - { - BREAK; - } - } - - if (LT_16(i, 180)) - { - i = 180; - move16(); - } - - FOR(j = L_HARMONIC_EXC - 1; j > i + 1; j--) - { - SWB_signal[j] = 0; - move16(); - } - - peak_dst = bwe_peaks + sfm_end[last_sfm]; - WHILE(dst < end) - { - test(); - WHILE(dst < end && src < &SWB_signal[L_HARMONIC_EXC]) - { - *dst++ = *src++; - move16(); - *peak_dst++ = *peak_src++; - move16(); - } - peak_src--; - src--; - - test(); - WHILE(dst < end && src >= &SWB_signal[START_EXC]) - { - *dst++ = *src--; - move16(); - *peak_dst++ = *peak_src--; - move16(); - } - peak_src++; - src++; - } - - return; + /* Avoid division by zero */ + if ( tmp == 0 ) + { + tmp = 1 << 14; + move16(); + } + + tmp = div_s( 1 << 14, tmp ); /* 15+14-(-4+s)=Q(33-s) */ + Mpy_32_16_ss( L_coeff[i], tmp, &L_tmp, &lsb ); /* 12+33-s+1-16=Q(30-s) */ + shift2 = add( shift, 1 ); + tmp = round_fx( L_shl( L_tmp, shift2 ) ); /* 30-s+s+1-16=Q(15) */ + SWB_signal[i] = add( tmp, lshr( lsb, sub( 32, shift2 ) ) ); + move16(); /* Q15 */ + /*SWB_signal[i] = round_fx(L_shl(L_tmp, add(shift, 1))); // 30-s+s+1-16=Q(15) */ + } + + dst = coeff_fine; + end = coeff_fine + sfm_end[num_sfm - 1] - sfm_end[last_sfm]; + + src = SWB_signal + START_EXC; + peak_src = peak_pos + START_EXC; + + FOR( i = 0; i < Npeaks; i++ ) + { + if ( LT_16( peak_idx[i], L_HARMONIC_EXC ) ) + { + peak_pos[peak_idx[i]] = 1; + move16(); + } + } + + i = sub( L_HARMONIC_EXC, 1 ); + WHILE( i-- > 0 ) + { + IF( EQ_16( peak_pos[i], 1 ) ) + { + BREAK; + } + } + + if ( LT_16( i, 180 ) ) + { + i = 180; + move16(); + } + + FOR( j = L_HARMONIC_EXC - 1; j > i + 1; j-- ) + { + SWB_signal[j] = 0; + move16(); + } + + peak_dst = bwe_peaks + sfm_end[last_sfm]; + WHILE( dst < end ) + { + test(); + WHILE( dst < end && src < &SWB_signal[L_HARMONIC_EXC] ) + { + *dst++ = *src++; + move16(); + *peak_dst++ = *peak_src++; + move16(); + } + peak_src--; + src--; + + test(); + WHILE( dst < end && src >= &SWB_signal[START_EXC] ) + { + *dst++ = *src--; + move16(); + *peak_dst++ = *peak_src--; + move16(); + } + peak_src++; + src++; + } + + return; } /*--------------------------------------------------------------------------* @@ -757,40 +751,40 @@ void hvq_bwe_fine_fx( *--------------------------------------------------------------------------*/ void hq_fold_bwe_fx( - const Word16 last_sfm, /* i : last coded subband Q0 */ - const Word16 *sfm_end, /* i : Subband end coefficient Q0 */ - const Word16 num_sfm, /* i : Number of subbands Q0 */ - Word16 *coeff /* i/o: coded/noisefilled normalized spectrum Q12 */ + const Word16 last_sfm, /* i : last coded subband Q0 */ + const Word16 *sfm_end, /* i : Subband end coefficient Q0 */ + const Word16 num_sfm, /* i : Number of subbands Q0 */ + Word16 *coeff /* i/o: coded/noisefilled normalized spectrum Q12 */ ) { - Word16 low_coeff; - Word16 first_coeff; - Word16 *src, *dst, *end; - - low_coeff = shr(sfm_end[last_sfm], 1); - src = coeff + sfm_end[last_sfm] - 1; - - first_coeff = sfm_end[last_sfm]; - dst = coeff + sfm_end[last_sfm]; - end = coeff + sfm_end[num_sfm - 1]; - - WHILE(dst < end) - { - WHILE(dst < end && src >= &coeff[low_coeff]) - { - *dst++ = *src--; - move16(); - } - - src++; - - WHILE(dst < end && src < &coeff[first_coeff]) - { - *dst++ = *src++; - move16(); - } - } - return; + Word16 low_coeff; + Word16 first_coeff; + Word16 *src, *dst, *end; + + low_coeff = shr( sfm_end[last_sfm], 1 ); + src = coeff + sfm_end[last_sfm] - 1; + + first_coeff = sfm_end[last_sfm]; + dst = coeff + sfm_end[last_sfm]; + end = coeff + sfm_end[num_sfm - 1]; + + WHILE( dst < end ) + { + WHILE( dst < end && src >= &coeff[low_coeff] ) + { + *dst++ = *src--; + move16(); + } + + src++; + + WHILE( dst < end && src < &coeff[first_coeff] ) + { + *dst++ = *src++; + move16(); + } + } + return; } /*--------------------------------------------------------------------------* @@ -800,31 +794,31 @@ void hq_fold_bwe_fx( *--------------------------------------------------------------------------*/ void apply_nf_gain_fx( - const Word16 nf_idx, /* i : noise fill gain index Q0 */ - const Word16 last_sfm, /* i : last coded subband Q0 */ - const Word16 *R, /* i : bit allocation Q0 */ - const Word16 *sfm_start, /* i : Subband start coefficient Q0 */ - const Word16 *sfm_end, /* i : Subband end coefficient Q0 */ - Word16 *coeff /* i/o: coded/noisefilled normalized spectrum Q12 */ + const Word16 nf_idx, /* i : noise fill gain index Q0 */ + const Word16 last_sfm, /* i : last coded subband Q0 */ + const Word16 *R, /* i : bit allocation Q0 */ + const Word16 *sfm_start, /* i : Subband start coefficient Q0 */ + const Word16 *sfm_end, /* i : Subband end coefficient Q0 */ + Word16 *coeff /* i/o: coded/noisefilled normalized spectrum Q12 */ ) { - Word16 sfm; - Word16 j; - - FOR(sfm = 0; sfm <= last_sfm; sfm++) - { - IF(R[sfm] == 0) - { - FOR(j = sfm_start[sfm]; j < sfm_end[sfm]; j++) - { - /* Scale NoiseFill */ - coeff[j] = shr(coeff[j], nf_idx); - move16(); - } - } - } - - return; + Word16 sfm; + Word16 j; + + FOR( sfm = 0; sfm <= last_sfm; sfm++ ) + { + IF( R[sfm] == 0 ) + { + FOR( j = sfm_start[sfm]; j < sfm_end[sfm]; j++ ) + { + /* Scale NoiseFill */ + coeff[j] = shr( coeff[j], nf_idx ); + move16(); + } + } + } + + return; } @@ -1020,175 +1014,179 @@ void ivas_harm_bwe_fx( #endif void harm_bwe_fx( - const Word16 *coeff_fine, /* i : fine structure for BWE */ - const Word16 *coeff, /* i : coded/noisefilled normalized spectrum */ - const Word16 num_sfm, /* i : Number of subbands */ - const Word16 *sfm_start, /* i : Subband start coefficient */ - const Word16 *sfm_end, /* i : Subband end coefficient */ - const Word16 last_sfm, /* i : last coded subband */ - const Word16 *R, /* i : bit allocation */ - const Word16 prev_hq_mode, /* i : previous hq mode */ - Word16 *norm, /* i/o: quantization indices for norms */ - Word16 *noise_level, /* i/o: noise levels for harmonic modes */ - Word16 *prev_noise_level, /* i/o: noise factor in previous frame */ - Word16 *bwe_seed, /* i/o: random seed for generating BWE input */ - Word32 *coeff_out, /* o : coded/noisefilled spectrum */ - const Word16 element_mode /* i : IVAS element mode */ -) -{ - Word16 i, j; - Word16 sfm, band_width; - Word32 normq, L_tmp, L_tmp2; - Word32 E_L; - Word16 alfa = 16384; - Word16 tmp, tmp1, exp1; - Word16 beta; - Word32 *src, *dst; - - move16(); /* alfa */ - - FOR(sfm = 0; sfm <= last_sfm; sfm++) - { - IF(R[sfm] == 0) - { - normq = dicn_fx[norm[sfm]]; /*Q14 */ move16(); - - FOR(i = sfm_start[sfm]; i < sfm_end[sfm]; i++) - { - coeff_out[i] = L_shl(Mult_32_16(normq, coeff[i]), 1); - move32(); /*12 Q(14 +12+1-16 +1) */ - - } - } - } - noise_level[1] = noise_level[0]; - move16(); - - /* shaping the BWE spectrum further by envelopes and noise factors */ - L_tmp = L_mult(29491, prev_noise_level[0]); /* 15 +1 +15 */ - noise_level[0] = round_fx(L_mac(L_tmp, 3277, noise_level[0])); /*15 */ - - L_tmp = L_mult(29491, prev_noise_level[1]); - noise_level[1] = round_fx(L_mac(L_tmp, 3277, noise_level[1])); - - test(); - IF(prev_hq_mode == HQ_NORMAL || EQ_16(prev_hq_mode, HQ_GEN_SWB)) - { - IF(LT_16(noise_level[0], 8192)) - { - noise_level[0] = shl(noise_level[0], 2); - move16(); - } - - IF(LT_16(noise_level[1], 8192)) - { - noise_level[1] = shl(noise_level[1], 2); - move16(); - } - } - - FOR(i = add(last_sfm, 1); i < num_sfm; i++) - { - E_L = 1; - move32(); - FOR(j = sfm_start[i]; j < sfm_end[i]; j++) - { - L_tmp = L_mult0(coeff_fine[j], coeff_fine[j]);/*Q30 */ - E_L = L_add(E_L, L_shr(L_tmp, 6));/*Q24 */ - } - - normq = dicn_fx[norm[i]]; - move32(); - - alfa = noise_level[0]; - move16(); - if (GT_16(i, 27)) - { - alfa = noise_level[1]; - move16(); - } - - band_width = sub(sfm_end[i], sfm_start[i]); /* */ - exp1 = norm_l(E_L); - IF(exp1 == 0) - { - E_L = Mult_32_16(E_L, inv_tbl_fx[band_width]); /* Q24 (24+15+1-16) *//*24+15+1-16 */ - tmp = div_l(E_L, sub(32767, alfa)); /*Q24-15-1 =8 */ - tmp = s_max(1, tmp); - L_tmp = L_deposit_h(tmp); /*24 */ - E_L = Isqrt(L_tmp); /* Q19 (31-24/2) */ - } - ELSE - { - exp1 = sub(exp1,1); - E_L = Mult_32_16(L_shl(E_L,exp1), inv_tbl_fx[band_width]); /* Q24+exp1 (24+exp1+15+1-16) */ - tmp = div_l(E_L,sub(32767,alfa)); /*Q24+exp1-15-1 =8+exp1 */ - tmp = s_max(1,tmp); - L_tmp = L_shl(L_deposit_l(tmp),sub(16,exp1)); /*24 8+exp1+16-exp1 */ - E_L = Isqrt(L_tmp); /* Q19 (31-24/2) */ - } - - exp1 = norm_s(alfa); - tmp1 = shl(alfa, exp1); - if (EQ_16(element_mode, EVS_MONO)) - { - exp1 = add(1, exp1); - } -#ifdef DEBUGGING - else - { - //PMT("VERIFY if this really matches IVAS float") - } -#endif - tmp1 = s_max(tmp1, 16384); - tmp1 = div_s(16384, tmp1); - L_tmp2 = L_deposit_h(tmp1); - L_tmp2 = Isqrt_lc(L_tmp2, &exp1); - - beta = round_fx(L_shl(L_tmp2, exp1)); - beta = shr(beta, 1); /*Q15 */ - - - FOR(sfm = sfm_start[i]; sfm < sfm_end[i]; sfm++) - { - L_tmp = Mult_32_16(E_L, coeff_fine[sfm]); /*Q19 19 + 15 +1-16 */ -#ifdef BASOP_NOGLOB - L_tmp = L_shl_sat(L_tmp, 9);/*Q28 */ -#else - L_tmp = L_shl(L_tmp, 9);/*Q28 */ -#endif - tmp = Random(bwe_seed); /*Q15 */ - L_tmp2 = L_shr(L_mult(beta, tmp), 3);/* Q28 31-3 15+15 +1-3 */ -#ifdef BASOP_NOGLOB - L_tmp = L_add_sat(L_tmp, L_tmp2);/*Q28 */ - coeff_out[sfm] = L_shl_sat(Mult_32_32(L_tmp, normq), 1);/*Q12 28 +14 +1 -31 */ move32(); -#else - L_tmp = L_add(L_tmp, L_tmp2);/*Q28 */ - coeff_out[sfm] = L_shl(Mult_32_32(L_tmp, normq), 1);/*Q12 28 +14 +1 -31 */ move32(); -#endif - } - } - - prev_noise_level[0] = noise_level[0]; - move16(); - prev_noise_level[1] = noise_level[1]; - move16(); - - src = &coeff_out[add(sfm_end[last_sfm], L_HARMONIC_EXC - START_EXC)]; /*Q12 */ - - dst = src - 1; - FOR(i = 0; i < 16; i++) - { - *src = Mult_32_16(*src, hvq_bwe_fac_fx[i]); /* Q12 (12+15+1-16) */ move32(); - src++; - *dst = Mult_32_16(*dst, hvq_bwe_fac_fx[i]); /* Q12 (12+15+1-16) */ move32(); - dst--; - } - IF(EQ_16(num_sfm, 33)) - { - set32_fx(&coeff_out[800], 0, 160); - } - return; + const Word16 *coeff_fine, /* i : fine structure for BWE */ + const Word16 *coeff, /* i : coded/noisefilled normalized spectrum */ + const Word16 num_sfm, /* i : Number of subbands */ + const Word16 *sfm_start, /* i : Subband start coefficient */ + const Word16 *sfm_end, /* i : Subband end coefficient */ + const Word16 last_sfm, /* i : last coded subband */ + const Word16 *R, /* i : bit allocation */ + const Word16 prev_hq_mode, /* i : previous hq mode */ + Word16 *norm, /* i/o: quantization indices for norms */ + Word16 *noise_level, /* i/o: noise levels for harmonic modes */ + Word16 *prev_noise_level, /* i/o: noise factor in previous frame */ + Word16 *bwe_seed, /* i/o: random seed for generating BWE input */ + Word32 *coeff_out, /* o : coded/noisefilled spectrum */ + const Word16 element_mode /* i : IVAS element mode */ +) +{ + Word16 i, j; + Word16 sfm, band_width; + Word32 normq, L_tmp, L_tmp2; + Word32 E_L; + Word16 alfa = 16384; + Word16 tmp, tmp1, exp1; + Word16 beta; + Word32 *src, *dst; + + move16(); /* alfa */ + + FOR( sfm = 0; sfm <= last_sfm; sfm++ ) + { + IF( R[sfm] == 0 ) + { + normq = dicn_fx[norm[sfm]]; /*Q14 */ + move16(); + + FOR( i = sfm_start[sfm]; i < sfm_end[sfm]; i++ ) + { + coeff_out[i] = L_shl( Mult_32_16( normq, coeff[i] ), 1 ); + move32(); /*12 Q(14 +12+1-16 +1) */ + } + } + } + noise_level[1] = noise_level[0]; + move16(); + + /* shaping the BWE spectrum further by envelopes and noise factors */ + L_tmp = L_mult( 29491, prev_noise_level[0] ); /* 15 +1 +15 */ + noise_level[0] = round_fx( L_mac( L_tmp, 3277, noise_level[0] ) ); /*15 */ + + L_tmp = L_mult( 29491, prev_noise_level[1] ); + noise_level[1] = round_fx( L_mac( L_tmp, 3277, noise_level[1] ) ); + + test(); + IF( prev_hq_mode == HQ_NORMAL || EQ_16( prev_hq_mode, HQ_GEN_SWB ) ) + { + IF( LT_16( noise_level[0], 8192 ) ) + { + noise_level[0] = shl( noise_level[0], 2 ); + move16(); + } + + IF( LT_16( noise_level[1], 8192 ) ) + { + noise_level[1] = shl( noise_level[1], 2 ); + move16(); + } + } + + FOR( i = add( last_sfm, 1 ); i < num_sfm; i++ ) + { + E_L = 1; + move32(); + FOR( j = sfm_start[i]; j < sfm_end[i]; j++ ) + { + L_tmp = L_mult0( coeff_fine[j], coeff_fine[j] ); /*Q30 */ + E_L = L_add( E_L, L_shr( L_tmp, 6 ) ); /*Q24 */ + } + + normq = dicn_fx[norm[i]]; + move32(); + + alfa = noise_level[0]; + move16(); + if ( GT_16( i, 27 ) ) + { + alfa = noise_level[1]; + move16(); + } + + band_width = sub( sfm_end[i], sfm_start[i] ); /* */ + exp1 = norm_l( E_L ); + IF( exp1 == 0 ) + { + E_L = Mult_32_16( E_L, inv_tbl_fx[band_width] ); /* Q24 (24+15+1-16) */ /*24+15+1-16 */ + tmp = div_l( E_L, sub( 32767, alfa ) ); /*Q24-15-1 =8 */ + tmp = s_max( 1, tmp ); + L_tmp = L_deposit_h( tmp ); /*24 */ + E_L = Isqrt( L_tmp ); /* Q19 (31-24/2) */ + } + ELSE + { + exp1 = sub( exp1, 1 ); + E_L = Mult_32_16( L_shl( E_L, exp1 ), inv_tbl_fx[band_width] ); /* Q24+exp1 (24+exp1+15+1-16) */ + tmp = div_l( E_L, sub( 32767, alfa ) ); /*Q24+exp1-15-1 =8+exp1 */ + tmp = s_max( 1, tmp ); + L_tmp = L_shl( L_deposit_l( tmp ), sub( 16, exp1 ) ); /*24 8+exp1+16-exp1 */ + E_L = Isqrt( L_tmp ); /* Q19 (31-24/2) */ + } + + exp1 = norm_s( alfa ); + tmp1 = shl( alfa, exp1 ); + if ( EQ_16( element_mode, EVS_MONO ) ) + { + exp1 = add( 1, exp1 ); + } +#ifdef DEBUGGING + else + { + // PMT("VERIFY if this really matches IVAS float") + } +#endif + tmp1 = s_max( tmp1, 16384 ); + tmp1 = div_s( 16384, tmp1 ); + L_tmp2 = L_deposit_h( tmp1 ); + L_tmp2 = Isqrt_lc( L_tmp2, &exp1 ); + + beta = round_fx( L_shl( L_tmp2, exp1 ) ); + beta = shr( beta, 1 ); /*Q15 */ + + + FOR( sfm = sfm_start[i]; sfm < sfm_end[i]; sfm++ ) + { + L_tmp = Mult_32_16( E_L, coeff_fine[sfm] ); /*Q19 19 + 15 +1-16 */ +#ifdef BASOP_NOGLOB + L_tmp = L_shl_sat( L_tmp, 9 ); /*Q28 */ +#else + L_tmp = L_shl( L_tmp, 9 ); /*Q28 */ +#endif + tmp = Random( bwe_seed ); /*Q15 */ + L_tmp2 = L_shr( L_mult( beta, tmp ), 3 ); /* Q28 31-3 15+15 +1-3 */ +#ifdef BASOP_NOGLOB + L_tmp = L_add_sat( L_tmp, L_tmp2 ); /*Q28 */ + coeff_out[sfm] = L_shl_sat( Mult_32_32( L_tmp, normq ), 1 ); /*Q12 28 +14 +1 -31 */ + move32(); +#else + L_tmp = L_add( L_tmp, L_tmp2 ); /*Q28 */ + coeff_out[sfm] = L_shl( Mult_32_32( L_tmp, normq ), 1 ); /*Q12 28 +14 +1 -31 */ + move32(); +#endif + } + } + + prev_noise_level[0] = noise_level[0]; + move16(); + prev_noise_level[1] = noise_level[1]; + move16(); + + src = &coeff_out[add( sfm_end[last_sfm], L_HARMONIC_EXC - START_EXC )]; /*Q12 */ + + dst = src - 1; + FOR( i = 0; i < 16; i++ ) + { + *src = Mult_32_16( *src, hvq_bwe_fac_fx[i] ); /* Q12 (12+15+1-16) */ + move32(); + src++; + *dst = Mult_32_16( *dst, hvq_bwe_fac_fx[i] ); /* Q12 (12+15+1-16) */ + move32(); + dst--; + } + IF( EQ_16( num_sfm, 33 ) ) + { + set32_fx( &coeff_out[800], 0, 160 ); + } + return; } /*--------------------------------------------------------------------------* @@ -1198,439 +1196,442 @@ void harm_bwe_fx( *--------------------------------------------------------------------------*/ void hvq_bwe_fx( - const Word32 *L_coeff, /* i : coded/noisefilled normalized spectrum Q12 */ - const Word16 *coeff_fine, /* i : coded/noisefilled normalized spectrum Qin */ - const Word16 *sfm_start, /* i : Subband start coefficient Q0 */ - const Word16 *sfm_end, /* i : Subband end coefficient Q0 */ - const Word16 *sfm_len, /* i : Subband length Q0 */ - const Word16 last_sfm, /* i : last coded subband Q0 */ - const Word16 prev_hq_mode, /* i : previous hq mode Q0 */ - const Word16 *bwe_peaks, /* i : HVQ bwe peaks Q0 */ - const Word16 bin_th, /* i : HVQ transition bin Q0 */ - const Word16 num_sfm, /* i : Number of bands Q0 */ - const Word32 core_brate, /* i : Core bitrate Q0 */ - const Word16 *R, /* i : Bit allocation */ - Word16 *norm, /* i/o: quantization indices for norms Q0 */ - Word16 *noise_level, /* i/o: noise levels for harmonic modes Q15 */ - Word16 *prev_noise_level, /* i/o: noise factor in previous frame Q15 */ - Word16 *bwe_seed, /* i/o: random seed for generating BWE input Q0 */ - Word32 *L_coeff_out, /* o : coded/noisefilled spectrum Qout*/ - const Word16 qin, - const Word16 qout -) + const Word32 *L_coeff, /* i : coded/noisefilled normalized spectrum Q12 */ + const Word16 *coeff_fine, /* i : coded/noisefilled normalized spectrum Qin */ + const Word16 *sfm_start, /* i : Subband start coefficient Q0 */ + const Word16 *sfm_end, /* i : Subband end coefficient Q0 */ + const Word16 *sfm_len, /* i : Subband length Q0 */ + const Word16 last_sfm, /* i : last coded subband Q0 */ + const Word16 prev_hq_mode, /* i : previous hq mode Q0 */ + const Word16 *bwe_peaks, /* i : HVQ bwe peaks Q0 */ + const Word16 bin_th, /* i : HVQ transition bin Q0 */ + const Word16 num_sfm, /* i : Number of bands Q0 */ + const Word32 core_brate, /* i : Core bitrate Q0 */ + const Word16 *R, /* i : Bit allocation */ + Word16 *norm, /* i/o: quantization indices for norms Q0 */ + Word16 *noise_level, /* i/o: noise levels for harmonic modes Q15 */ + Word16 *prev_noise_level, /* i/o: noise factor in previous frame Q15 */ + Word16 *bwe_seed, /* i/o: random seed for generating BWE input Q0 */ + Word32 *L_coeff_out, /* o : coded/noisefilled spectrum Qout*/ + const Word16 qin, + const Word16 qout ) { - Word16 i, j; - Word16 N; - Word32 L_normq; - Word32 L_E; - Word32 L_tmp_norm = 0; - Word16 bwe_noise_th = 0; - Word16 peak_band, low, high, sel_norm; - Word16 norm_ind; - Word32 *L_src, *L_dst; - Word16 istart, iend; - Word16 offset = sfm_end[last_sfm]; - - /* Fx specific variables */ - Word32 L_tmp0, L_tmp1; - Word16 tmp, tmp2, band_size; - Word16 last_norm_ind; - Word16 shift, power_shift; - Word16 coeff_s[L_FRAME48k]; - Word16 j_N; - Word16 n_c; - UWord16 lsb; - - move32(); /* L_tmp_norm */ - move16(); /* bwe_noise_th */ - - bwe_noise_th = add(bin_th, shr(sub(sfm_end[sub(num_sfm, 1)], bin_th), 1)); - logqnorm_fx(&L_coeff_out[sfm_start[last_sfm]], qout, &norm[last_sfm], 40, sfm_len[last_sfm], 0); - move16(); - - /* shaping the BWE spectrum further by envelopes and noise factors */ - noise_level[0] = round_fx(L_mac(L_mult(29491, prev_noise_level[0]), 3277, noise_level[0])); /* Q15 (15+15+1-16) */ - noise_level[1] = round_fx(L_mac(L_mult(29491, prev_noise_level[1]), 3277, noise_level[1])); /* Q15 (15+15+1-16) */ - - test(); - IF(prev_hq_mode == HQ_NORMAL || EQ_16(prev_hq_mode, HQ_GEN_SWB)) - { - IF(LT_16(noise_level[0], 8192 /* 0.25f */)) - { - noise_level[0] = shl(noise_level[0], 2); - move16(); - } - - IF(LT_16(noise_level[1], 8192 /* 0.25f */)) - { - noise_level[1] = shl(noise_level[1], 2); - move16(); - } - } - - norm_ind = add(last_sfm, 1); - IF(LT_32(core_brate, HQ_BWE_CROSSOVER_BRATE)) - { - peak_band = 0; - move16(); - - tmp = 1; - move16(); - FOR(i = sfm_start[norm_ind]; i < sfm_end[norm_ind + 1]; i++) - { - tmp2 = abs_s(coeff_fine[i - offset]); - tmp = s_max(tmp, tmp2); - } - band_size = sub(sfm_end[norm_ind + 1], sfm_start[norm_ind]); - - /* Headroom for square and accumulate */ - shift = sub(norm_s(tmp), sqac_headroom_fx[band_size]); - L_E = L_deposit_l(1); - FOR(i = sfm_start[norm_ind]; i < sfm_end[norm_ind + 1]; i++) - { - if (bwe_peaks[i]) - { - peak_band = 1; - move16(); - } - /* E_L += coeff_fine[i-offset] * coeff_fine[i-offset]; */ - coeff_s[i] = shl(coeff_fine[i - offset], shift); - move16();/* Q15 + shift */ - L_E = L_mac0(L_E, coeff_s[i], coeff_s[i]); /* Q2*(qin + shift) */ - } - power_shift = shl(shift, 1); - - L_E = L_shr(L_E, sub(power_shift, 28 - 2 * qin)); /* Q28 */ - - /* E_L = (float)sqrt((sfm_end[norm_ind+1] - sfm_start[norm_ind])/E_L); */ - L_E = Mult_32_16(L_E, inv_tbl_fx[band_size]); /* Q28 (28+15+1-16) */ - /* To avoid overflow in Isqrt() */ - if (L_E == 0) - { - L_E = L_deposit_l(1); - } - L_E = Isqrt(L_E); /* Q17 (31-28/2) */ - - /* normq = 0.1f*dicn[norm[norm_ind-1]] + 0.8f*dicn[norm[norm_ind]] + 0.1f*dicn[norm[norm_ind+1]]; */ - /* tmp_norm = 0.1f*dicn[norm[norm_ind]] + 0.8f*dicn[norm[norm_ind+1]] + 0.1f*dicn[norm[norm_ind+2]]; */ - L_tmp0 = L_add(dicn_fx[norm[norm_ind]], 0); - L_tmp1 = L_add(dicn_fx[norm[norm_ind + 1]], 0); - L_normq = Madd_32_16(Madd_32_16(Mult_32_16(L_tmp0, 26214 /* Q15, 0.8f */), dicn_fx[norm[norm_ind - 1]], 3277 /* Q15, 0.1f */), L_tmp1, 3277 /* Q15, 0.1f */); /* Q14 (14+15+1-16) */ move16(); - L_tmp_norm = Madd_32_16(Madd_32_16(Mult_32_16(L_tmp1, 26214 /* Q15, 0.8f */), dicn_fx[norm[norm_ind + 2]], 3277 /* Q15, 0.1f */), L_tmp0, 3277 /* Q15, 0.1f */); /* Q14 (14+15+1-16) */ move16(); - - istart = sfm_start[norm_ind]; - move16(); - /* iend = istart + sfm_len[norm_ind]/2; */ - iend = 240; - move16(); - - noise_mix_fx(&coeff_fine[-offset], L_E, L_normq, bwe_seed, istart, iend, noise_level[0], L_coeff_out, qin, qout); - - j = 0; - move16(); - /* N = sfm_len[norm_ind]/2+sfm_len[norm_ind+1]/2-1; */ - N = 31; - move16(); - j_N = N; - move16(); - - istart = iend; - move16(); - /* iend = sfm_start[norm_ind+1] + sfm_len[norm_ind+1]/2; */ - iend = 272; - move16(); - - /* special case that is not handled by noise_mix_fx() */ - n_c = sub(MAX_16, noise_level[0]); /* Q15 */ - FOR(i = istart; i < iend; i++) - { - /* coeff_out[i] = ((float)(N-j)/N*normq + (float)j/N*tmp_norm)*((1.0f - noise_level[i/bwe_noise_th])*coeff_fine[i-offset]*E_L + noise_level[i/bwe_noise_th]*own_random(bwe_seed)/32768.0f); */ - L_tmp1 = Madd_32_16(Mult_32_16(L_normq, inv_N_fx[j_N]), L_tmp_norm, inv_N_fx[j]); /* Q14 (14+15+1-16) */ - j = add(j, 1); - j_N = sub(j_N, 1); - - Mpy_32_16_ss(L_E, coeff_fine[i - offset], &L_tmp0, &lsb); /* Qin+2 (17+qin+1-16) */ - Mpy_32_16_ss(L_tmp0, n_c, &L_tmp0, &lsb); /* Qin+2-15 (qin+2+15+1-16) */ - - IF(L_tmp0 != 0) - { - /* Normalize with 1 bit headroom for addition */ - tmp = 30 - (qin + 2); /* Assuming fixed Q values */ - tmp = s_min(norm_l(L_tmp0), tmp); - tmp = sub(tmp, 1); - - L_tmp0 = L_add(L_shl(L_tmp0, tmp), L_deposit_l(lshr(lsb, sub(16, tmp)))); /* Qin+2+tmp */ - - L_tmp0 = L_add(L_tmp0, L_shr(L_mult0(noise_level[0], Random(bwe_seed)), sub(30 - (qin + 2), tmp))); /* Qin+2+tmp */ - tmp = round_fx(L_shl(L_tmp0, 27 - (qin + 2) - tmp)); /* Q11 (Qin+2+tmp+27-qin-2-tmp-16) */ - - Mpy_32_16_ss(L_tmp1, tmp, &L_tmp0, &lsb); /* Q10 (14+11+1-16) */ - L_coeff_out[i] = L_add(L_shl(L_tmp0, qout - 10), L_deposit_l(lshr(lsb, 10 + 16 - qout))); - move32(); /* Qout (10+qout-10) */ - } - ELSE - { - L_tmp0 = L_mult0(noise_level[0], Random(bwe_seed)); /* Q30 (15+15) */ - tmp = round_fx(L_tmp0); /* Q14 (30-16) */ - Mpy_32_16_ss(L_tmp1, tmp, &L_tmp0, &lsb); /* Q13 (14+14+1-16) */ - L_coeff_out[i] = L_shr(L_tmp0,13 - qout); - move32();/* Qout (13-(13-qout)) */ - } - } - - istart = iend; - move16(); - iend = sfm_end[norm_ind + 1]; - move16(); - - noise_mix_fx(&coeff_fine[-offset], L_E, L_tmp_norm, bwe_seed, istart, iend, noise_level[0], L_coeff_out, qin, qout); - - norm_ind = add(norm_ind, 2); - } - - FOR(; norm_ind < num_sfm; norm_ind++) - { - IF(R[norm_ind] == 0) - { - peak_band = 0; - move16(); - - FOR(i = sfm_start[norm_ind]; i < sfm_end[norm_ind]; i++) - { - if (bwe_peaks[i]) - { - peak_band = 1; - move16(); - } - } - - istart = sfm_start[norm_ind]; - move16(); - iend = sfm_end[norm_ind]; - move16(); - - last_norm_ind = sub(num_sfm, 1); - test(); - test(); - IF(EQ_16(peak_band, 1) && GT_16(norm_ind, add(last_sfm, 1)) && LT_16(norm_ind, last_norm_ind)) - { - istart = sub(istart, shr(sfm_len[norm_ind - 1], 1)); - iend = add(iend, shr(sfm_len[norm_ind + 1], 1)); - } - - tmp = 1; - move16(); - FOR(i = istart; i < iend; i++) - { - tmp2 = abs_s(coeff_fine[i - offset]); - tmp = s_max(tmp, tmp2); - } - band_size = sub(iend, istart); - /* Headroom for square and accumulate */ - shift = sub(norm_s(tmp), sqac_headroom_fx[band_size]); - - L_E = 1L; - move32(); - FOR(i = istart; i < iend; i++) - { - /* E_L += coeff_fine[i-offset] * coeff_fine[i-offset]; */ - coeff_s[i] = shl(coeff_fine[i - offset], shift); - move16();/* Q15 + shift */ - L_E = L_mac0(L_E, coeff_s[i], coeff_s[i]); /* Q2*(15 + shift) */ - } - power_shift = shl(shift, 1); - - L_E = L_shr(L_E, sub(power_shift, 28 - 2 * qin)); /* Q28 */ - - /* E_L = (float)sqrt((iend - istart)/E_L); */ - L_E = Mult_32_16(L_E, inv_tbl_fx[band_size]); /* Q28 (28+15+1-16) */ - /* To avoid overflow in Isqrt() */ - if (L_E == 0) - { - L_E = 1L; - move32(); - } - L_E = Isqrt(L_E); /* Q17 (31-28/2) */ - - IF(peak_band) - { - IF(GT_16(add(norm_ind, 2), num_sfm)) - { - /* normq = 0.15f*dicn[norm[norm_ind-1]] + 0.85f*dicn[norm[norm_ind]]; */ - L_normq = Madd_32_16(Mult_32_16(dicn_fx[norm[norm_ind]], 27853 /* Q15, 0.85f */), dicn_fx[norm[norm_ind - 1]], 4915 /* Q15, 0.1f */); /* Q14 (14+15+1-16) */ move16(); - move16(); - } - ELSE - { - /* normq = 0.1f*dicn[norm[norm_ind-1]] + 0.8f*dicn[norm[norm_ind]] + 0.1f*dicn[norm[norm_ind+1]]; */ - L_normq = Madd_32_16(Madd_32_16(Mult_32_16(dicn_fx[norm[norm_ind]], 26214 /* Q15, 0.8f */), dicn_fx[norm[norm_ind + 1]], 3277 /* Q15, 0.1f */), dicn_fx[norm[norm_ind - 1]], 3277 /* Q15, 0.1f */); /* Q14 (14+15+1-16) */ move16(); - move16(); - move16(); - } - } - ELSE - { - low = norm_ind; - move16(); - high = s_min(add(norm_ind,1), last_norm_ind); - move16(); - sel_norm = norm[norm_ind - 1]; - move16(); - FOR(j = low; j <= high; j++) - { - if (GT_16(norm[j], sel_norm)) - { - sel_norm = norm[j]; - move16(); - } - } - L_normq = dicn_fx[sel_norm]; - move16(); - } - - iend = s_min(sfm_end[norm_ind], bwe_noise_th); - move16(); - IF(GT_16(iend, sfm_start[norm_ind])) - { - noise_mix_fx(&coeff_fine[-offset], L_E, L_normq, bwe_seed, sfm_start[norm_ind], iend, noise_level[0], L_coeff_out, qin, qout); - } - ELSE - { - iend = sfm_end[norm_ind]; - move16(); - noise_mix_fx(&coeff_fine[-offset], L_E, L_normq, bwe_seed, sfm_start[norm_ind], iend, noise_level[1], L_coeff_out, qin, qout); - } - /* Noisemix up to threshold done */ - IF(EQ_16(iend, bwe_noise_th)) - { - noise_mix_fx(&coeff_fine[-offset], L_E, L_normq, bwe_seed, iend, sfm_end[norm_ind], noise_level[1], L_coeff_out, qin, qout); - } - - } - ELSE /* R[norm_ind] > 0 */ - { - FOR(i = sfm_start[norm_ind]; i < sfm_end[norm_ind]; i++) - { - L_coeff_out[i] = L_coeff[i]; /* Scaling already applied */ move32(); - } - } - } - - prev_noise_level[0] = noise_level[0]; - move16(); - prev_noise_level[1] = noise_level[1]; - move16(); - L_src = &L_coeff_out[add(sfm_end[last_sfm], L_HARMONIC_EXC - START_EXC)]; /* Address initialization */ - L_dst = L_src - 1; /* Address computation */ - - FOR(i = 0; i < 16; i++) - { - *L_src = Mult_32_16(*L_src, hvq_bwe_fac_fx[i]); - L_src++; /* Qout (Qout+15+1-16) */ move32(); - *L_dst = Mult_32_16(*L_dst, hvq_bwe_fac_fx[i]); - L_dst--; /* Qout (Qout+15+1-16) */ move32(); - } - - return; + Word16 i, j; + Word16 N; + Word32 L_normq; + Word32 L_E; + Word32 L_tmp_norm = 0; + Word16 bwe_noise_th = 0; + Word16 peak_band, low, high, sel_norm; + Word16 norm_ind; + Word32 *L_src, *L_dst; + Word16 istart, iend; + Word16 offset = sfm_end[last_sfm]; + + /* Fx specific variables */ + Word32 L_tmp0, L_tmp1; + Word16 tmp, tmp2, band_size; + Word16 last_norm_ind; + Word16 shift, power_shift; + Word16 coeff_s[L_FRAME48k]; + Word16 j_N; + Word16 n_c; + UWord16 lsb; + + move32(); /* L_tmp_norm */ + move16(); /* bwe_noise_th */ + + bwe_noise_th = add( bin_th, shr( sub( sfm_end[sub( num_sfm, 1 )], bin_th ), 1 ) ); + logqnorm_fx( &L_coeff_out[sfm_start[last_sfm]], qout, &norm[last_sfm], 40, sfm_len[last_sfm], 0 ); + move16(); + + /* shaping the BWE spectrum further by envelopes and noise factors */ + noise_level[0] = round_fx( L_mac( L_mult( 29491, prev_noise_level[0] ), 3277, noise_level[0] ) ); /* Q15 (15+15+1-16) */ + noise_level[1] = round_fx( L_mac( L_mult( 29491, prev_noise_level[1] ), 3277, noise_level[1] ) ); /* Q15 (15+15+1-16) */ + + test(); + IF( prev_hq_mode == HQ_NORMAL || EQ_16( prev_hq_mode, HQ_GEN_SWB ) ) + { + IF( LT_16( noise_level[0], 8192 /* 0.25f */ ) ) + { + noise_level[0] = shl( noise_level[0], 2 ); + move16(); + } + + IF( LT_16( noise_level[1], 8192 /* 0.25f */ ) ) + { + noise_level[1] = shl( noise_level[1], 2 ); + move16(); + } + } + + norm_ind = add( last_sfm, 1 ); + IF( LT_32( core_brate, HQ_BWE_CROSSOVER_BRATE ) ) + { + peak_band = 0; + move16(); + + tmp = 1; + move16(); + FOR( i = sfm_start[norm_ind]; i < sfm_end[norm_ind + 1]; i++ ) + { + tmp2 = abs_s( coeff_fine[i - offset] ); + tmp = s_max( tmp, tmp2 ); + } + band_size = sub( sfm_end[norm_ind + 1], sfm_start[norm_ind] ); + + /* Headroom for square and accumulate */ + shift = sub( norm_s( tmp ), sqac_headroom_fx[band_size] ); + L_E = L_deposit_l( 1 ); + FOR( i = sfm_start[norm_ind]; i < sfm_end[norm_ind + 1]; i++ ) + { + if ( bwe_peaks[i] ) + { + peak_band = 1; + move16(); + } + /* E_L += coeff_fine[i-offset] * coeff_fine[i-offset]; */ + coeff_s[i] = shl( coeff_fine[i - offset], shift ); + move16(); /* Q15 + shift */ + L_E = L_mac0( L_E, coeff_s[i], coeff_s[i] ); /* Q2*(qin + shift) */ + } + power_shift = shl( shift, 1 ); + + L_E = L_shr( L_E, sub( power_shift, 28 - 2 * qin ) ); /* Q28 */ + + /* E_L = (float)sqrt((sfm_end[norm_ind+1] - sfm_start[norm_ind])/E_L); */ + L_E = Mult_32_16( L_E, inv_tbl_fx[band_size] ); /* Q28 (28+15+1-16) */ + /* To avoid overflow in Isqrt() */ + if ( L_E == 0 ) + { + L_E = L_deposit_l( 1 ); + } + L_E = Isqrt( L_E ); /* Q17 (31-28/2) */ + + /* normq = 0.1f*dicn[norm[norm_ind-1]] + 0.8f*dicn[norm[norm_ind]] + 0.1f*dicn[norm[norm_ind+1]]; */ + /* tmp_norm = 0.1f*dicn[norm[norm_ind]] + 0.8f*dicn[norm[norm_ind+1]] + 0.1f*dicn[norm[norm_ind+2]]; */ + L_tmp0 = L_add( dicn_fx[norm[norm_ind]], 0 ); + L_tmp1 = L_add( dicn_fx[norm[norm_ind + 1]], 0 ); + L_normq = Madd_32_16( Madd_32_16( Mult_32_16( L_tmp0, 26214 /* Q15, 0.8f */ ), dicn_fx[norm[norm_ind - 1]], 3277 /* Q15, 0.1f */ ), L_tmp1, 3277 /* Q15, 0.1f */ ); /* Q14 (14+15+1-16) */ + move16(); + L_tmp_norm = Madd_32_16( Madd_32_16( Mult_32_16( L_tmp1, 26214 /* Q15, 0.8f */ ), dicn_fx[norm[norm_ind + 2]], 3277 /* Q15, 0.1f */ ), L_tmp0, 3277 /* Q15, 0.1f */ ); /* Q14 (14+15+1-16) */ + move16(); + + istart = sfm_start[norm_ind]; + move16(); + /* iend = istart + sfm_len[norm_ind]/2; */ + iend = 240; + move16(); + + noise_mix_fx( &coeff_fine[-offset], L_E, L_normq, bwe_seed, istart, iend, noise_level[0], L_coeff_out, qin, qout ); + + j = 0; + move16(); + /* N = sfm_len[norm_ind]/2+sfm_len[norm_ind+1]/2-1; */ + N = 31; + move16(); + j_N = N; + move16(); + + istart = iend; + move16(); + /* iend = sfm_start[norm_ind+1] + sfm_len[norm_ind+1]/2; */ + iend = 272; + move16(); + + /* special case that is not handled by noise_mix_fx() */ + n_c = sub( MAX_16, noise_level[0] ); /* Q15 */ + FOR( i = istart; i < iend; i++ ) + { + /* coeff_out[i] = ((float)(N-j)/N*normq + (float)j/N*tmp_norm)*((1.0f - noise_level[i/bwe_noise_th])*coeff_fine[i-offset]*E_L + noise_level[i/bwe_noise_th]*own_random(bwe_seed)/32768.0f); */ + L_tmp1 = Madd_32_16( Mult_32_16( L_normq, inv_N_fx[j_N] ), L_tmp_norm, inv_N_fx[j] ); /* Q14 (14+15+1-16) */ + j = add( j, 1 ); + j_N = sub( j_N, 1 ); + + Mpy_32_16_ss( L_E, coeff_fine[i - offset], &L_tmp0, &lsb ); /* Qin+2 (17+qin+1-16) */ + Mpy_32_16_ss( L_tmp0, n_c, &L_tmp0, &lsb ); /* Qin+2-15 (qin+2+15+1-16) */ + + IF( L_tmp0 != 0 ) + { + /* Normalize with 1 bit headroom for addition */ + tmp = 30 - ( qin + 2 ); /* Assuming fixed Q values */ + tmp = s_min( norm_l( L_tmp0 ), tmp ); + tmp = sub( tmp, 1 ); + + L_tmp0 = L_add( L_shl( L_tmp0, tmp ), L_deposit_l( lshr( lsb, sub( 16, tmp ) ) ) ); /* Qin+2+tmp */ + + L_tmp0 = L_add( L_tmp0, L_shr( L_mult0( noise_level[0], Random( bwe_seed ) ), sub( 30 - ( qin + 2 ), tmp ) ) ); /* Qin+2+tmp */ + tmp = round_fx( L_shl( L_tmp0, 27 - ( qin + 2 ) - tmp ) ); /* Q11 (Qin+2+tmp+27-qin-2-tmp-16) */ + + Mpy_32_16_ss( L_tmp1, tmp, &L_tmp0, &lsb ); /* Q10 (14+11+1-16) */ + L_coeff_out[i] = L_add( L_shl( L_tmp0, qout - 10 ), L_deposit_l( lshr( lsb, 10 + 16 - qout ) ) ); + move32(); /* Qout (10+qout-10) */ + } + ELSE + { + L_tmp0 = L_mult0( noise_level[0], Random( bwe_seed ) ); /* Q30 (15+15) */ + tmp = round_fx( L_tmp0 ); /* Q14 (30-16) */ + Mpy_32_16_ss( L_tmp1, tmp, &L_tmp0, &lsb ); /* Q13 (14+14+1-16) */ + L_coeff_out[i] = L_shr( L_tmp0, 13 - qout ); + move32(); /* Qout (13-(13-qout)) */ + } + } + + istart = iend; + move16(); + iend = sfm_end[norm_ind + 1]; + move16(); + + noise_mix_fx( &coeff_fine[-offset], L_E, L_tmp_norm, bwe_seed, istart, iend, noise_level[0], L_coeff_out, qin, qout ); + + norm_ind = add( norm_ind, 2 ); + } + + FOR( ; norm_ind < num_sfm; norm_ind++ ) + { + IF( R[norm_ind] == 0 ) + { + peak_band = 0; + move16(); + + FOR( i = sfm_start[norm_ind]; i < sfm_end[norm_ind]; i++ ) + { + if ( bwe_peaks[i] ) + { + peak_band = 1; + move16(); + } + } + + istart = sfm_start[norm_ind]; + move16(); + iend = sfm_end[norm_ind]; + move16(); + + last_norm_ind = sub( num_sfm, 1 ); + test(); + test(); + IF( EQ_16( peak_band, 1 ) && GT_16( norm_ind, add( last_sfm, 1 ) ) && LT_16( norm_ind, last_norm_ind ) ) + { + istart = sub( istart, shr( sfm_len[norm_ind - 1], 1 ) ); + iend = add( iend, shr( sfm_len[norm_ind + 1], 1 ) ); + } + + tmp = 1; + move16(); + FOR( i = istart; i < iend; i++ ) + { + tmp2 = abs_s( coeff_fine[i - offset] ); + tmp = s_max( tmp, tmp2 ); + } + band_size = sub( iend, istart ); + /* Headroom for square and accumulate */ + shift = sub( norm_s( tmp ), sqac_headroom_fx[band_size] ); + + L_E = 1L; + move32(); + FOR( i = istart; i < iend; i++ ) + { + /* E_L += coeff_fine[i-offset] * coeff_fine[i-offset]; */ + coeff_s[i] = shl( coeff_fine[i - offset], shift ); + move16(); /* Q15 + shift */ + L_E = L_mac0( L_E, coeff_s[i], coeff_s[i] ); /* Q2*(15 + shift) */ + } + power_shift = shl( shift, 1 ); + + L_E = L_shr( L_E, sub( power_shift, 28 - 2 * qin ) ); /* Q28 */ + + /* E_L = (float)sqrt((iend - istart)/E_L); */ + L_E = Mult_32_16( L_E, inv_tbl_fx[band_size] ); /* Q28 (28+15+1-16) */ + /* To avoid overflow in Isqrt() */ + if ( L_E == 0 ) + { + L_E = 1L; + move32(); + } + L_E = Isqrt( L_E ); /* Q17 (31-28/2) */ + + IF( peak_band ) + { + IF( GT_16( add( norm_ind, 2 ), num_sfm ) ) + { + /* normq = 0.15f*dicn[norm[norm_ind-1]] + 0.85f*dicn[norm[norm_ind]]; */ + L_normq = Madd_32_16( Mult_32_16( dicn_fx[norm[norm_ind]], 27853 /* Q15, 0.85f */ ), dicn_fx[norm[norm_ind - 1]], 4915 /* Q15, 0.1f */ ); /* Q14 (14+15+1-16) */ + move16(); + move16(); + } + ELSE + { + /* normq = 0.1f*dicn[norm[norm_ind-1]] + 0.8f*dicn[norm[norm_ind]] + 0.1f*dicn[norm[norm_ind+1]]; */ + L_normq = Madd_32_16( Madd_32_16( Mult_32_16( dicn_fx[norm[norm_ind]], 26214 /* Q15, 0.8f */ ), dicn_fx[norm[norm_ind + 1]], 3277 /* Q15, 0.1f */ ), dicn_fx[norm[norm_ind - 1]], 3277 /* Q15, 0.1f */ ); /* Q14 (14+15+1-16) */ + move16(); + move16(); + move16(); + } + } + ELSE + { + low = norm_ind; + move16(); + high = s_min( add( norm_ind, 1 ), last_norm_ind ); + move16(); + sel_norm = norm[norm_ind - 1]; + move16(); + FOR( j = low; j <= high; j++ ) + { + if ( GT_16( norm[j], sel_norm ) ) + { + sel_norm = norm[j]; + move16(); + } + } + L_normq = dicn_fx[sel_norm]; + move16(); + } + + iend = s_min( sfm_end[norm_ind], bwe_noise_th ); + move16(); + IF( GT_16( iend, sfm_start[norm_ind] ) ) + { + noise_mix_fx( &coeff_fine[-offset], L_E, L_normq, bwe_seed, sfm_start[norm_ind], iend, noise_level[0], L_coeff_out, qin, qout ); + } + ELSE + { + iend = sfm_end[norm_ind]; + move16(); + noise_mix_fx( &coeff_fine[-offset], L_E, L_normq, bwe_seed, sfm_start[norm_ind], iend, noise_level[1], L_coeff_out, qin, qout ); + } + /* Noisemix up to threshold done */ + IF( EQ_16( iend, bwe_noise_th ) ) + { + noise_mix_fx( &coeff_fine[-offset], L_E, L_normq, bwe_seed, iend, sfm_end[norm_ind], noise_level[1], L_coeff_out, qin, qout ); + } + } + ELSE /* R[norm_ind] > 0 */ + { + FOR( i = sfm_start[norm_ind]; i < sfm_end[norm_ind]; i++ ) + { + L_coeff_out[i] = L_coeff[i]; /* Scaling already applied */ + move32(); + } + } + } + + prev_noise_level[0] = noise_level[0]; + move16(); + prev_noise_level[1] = noise_level[1]; + move16(); + L_src = &L_coeff_out[add( sfm_end[last_sfm], L_HARMONIC_EXC - START_EXC )]; /* Address initialization */ + L_dst = L_src - 1; /* Address computation */ + + FOR( i = 0; i < 16; i++ ) + { + *L_src = Mult_32_16( *L_src, hvq_bwe_fac_fx[i] ); + L_src++; /* Qout (Qout+15+1-16) */ + move32(); + *L_dst = Mult_32_16( *L_dst, hvq_bwe_fac_fx[i] ); + L_dst--; /* Qout (Qout+15+1-16) */ + move32(); + } + + return; } -/*-------------------------------------------------------------------* -* hvq_concat_bands_fx() -* -* Compute the band limits for concatenated bands for PVQ target signal in HVQ -*--------------------------------------------------------------------------*/ -void hvq_concat_bands_fx -( - const Word16 pvq_bands, /* i : Number of bands in concatenated PVQ target */ - const Word16 *sel_bnds, /* i : Array of selected high bands */ - const Word16 n_sel_bnds, /* i : Number of selected high bands */ - Word16 *hvq_band_start, /* i : Band start indices */ - Word16 *hvq_band_width, /* i : Band widths */ - Word16 *hvq_band_end /* i : Band end indices */ -) -{ - Word16 k, k_1; - const Word16 *pSelBnds; - - pSelBnds = sel_bnds; - FOR(k = 0; k < pvq_bands; k++) - { - - IF(GE_16(k, sub(pvq_bands, n_sel_bnds))) - { - k_1 = sub(k, 1); - hvq_band_start[k] = hvq_band_end[k_1]; - move16(); - hvq_band_width[k] = band_len_harm[*pSelBnds++]; - move16(); - move16(); - hvq_band_end[k] = add(hvq_band_end[k_1], hvq_band_width[k]); - move16(); - } - ELSE - { - hvq_band_start[k] = extract_l(L_mult0(k, HVQ_PVQ_COEFS)); - hvq_band_width[k] = HVQ_PVQ_COEFS; - move16(); - hvq_band_end[k] = add(hvq_band_start[k], HVQ_PVQ_COEFS); - move16(); - } - } - - return; +/*-------------------------------------------------------------------* + * hvq_concat_bands_fx() + * + * Compute the band limits for concatenated bands for PVQ target signal in HVQ + *--------------------------------------------------------------------------*/ +void hvq_concat_bands_fx( + const Word16 pvq_bands, /* i : Number of bands in concatenated PVQ target */ + const Word16 *sel_bnds, /* i : Array of selected high bands */ + const Word16 n_sel_bnds, /* i : Number of selected high bands */ + Word16 *hvq_band_start, /* i : Band start indices */ + Word16 *hvq_band_width, /* i : Band widths */ + Word16 *hvq_band_end /* i : Band end indices */ +) +{ + Word16 k, k_1; + const Word16 *pSelBnds; + + pSelBnds = sel_bnds; + FOR( k = 0; k < pvq_bands; k++ ) + { + + IF( GE_16( k, sub( pvq_bands, n_sel_bnds ) ) ) + { + k_1 = sub( k, 1 ); + hvq_band_start[k] = hvq_band_end[k_1]; + move16(); + hvq_band_width[k] = band_len_harm[*pSelBnds++]; + move16(); + move16(); + hvq_band_end[k] = add( hvq_band_end[k_1], hvq_band_width[k] ); + move16(); + } + ELSE + { + hvq_band_start[k] = extract_l( L_mult0( k, HVQ_PVQ_COEFS ) ); + hvq_band_width[k] = HVQ_PVQ_COEFS; + move16(); + hvq_band_end[k] = add( hvq_band_start[k], HVQ_PVQ_COEFS ); + move16(); + } + } + + return; } /*--------------------------------------------------------------------------* * noise_mix_fx() *--------------------------------------------------------------------------*/ void noise_mix_fx( - const Word16 *coeff_fine, /* i : normalized fine structure spectrum Qin */ - const Word32 L_E, /* i : normalization factor Q17 */ - const Word32 L_normq, /* i : quantized norm Q14 */ - Word16 *seed, /* i/o: random seed Q0 */ - const Word16 istart, /* i : start coefficient Q0 */ - const Word16 iend, /* i : end coefficient Q0 */ - const Word16 noise_level, /* i : noise_level Q0 */ - Word32 *L_coeff_out, /* o : noise mixed spectrum Qout */ - const Word16 qin, - const Word16 qout -) + const Word16 *coeff_fine, /* i : normalized fine structure spectrum Qin */ + const Word32 L_E, /* i : normalization factor Q17 */ + const Word32 L_normq, /* i : quantized norm Q14 */ + Word16 *seed, /* i/o: random seed Q0 */ + const Word16 istart, /* i : start coefficient Q0 */ + const Word16 iend, /* i : end coefficient Q0 */ + const Word16 noise_level, /* i : noise_level Q0 */ + Word32 *L_coeff_out, /* o : noise mixed spectrum Qout */ + const Word16 qin, + const Word16 qout ) { - Word16 i, tmp, n_c; - Word32 L_tmp0; - UWord16 lsb; - - n_c = sub(MAX_16, noise_level); /* Q15 */ - FOR(i = istart; i < iend; i++) - { - /* L_coeff_out[i] = ((1.0f - noise_level)*coeff_fine[i]*L_E + noise_level*own_random(seed)/32768.0f)*normq; */ - Mpy_32_16_ss(L_E, coeff_fine[i], &L_tmp0, &lsb); /* Qin+qL_E-15 (qL_E+qin+1-16) */ - Mpy_32_16_ss(L_tmp0, n_c, &L_tmp0, &lsb); /* Qin+qL_E-15 (qin+qL_E-15+15+1-16) */ - - IF(L_tmp0 != 0) - { - /* Normalize with 1 bit headroom for addition */ - tmp = 30 - (qin + 2); /* Assuming fixed Q values */ - tmp = s_min(norm_l(L_tmp0), tmp); - tmp = sub(tmp, 1); - - L_tmp0 = L_add(L_shl(L_tmp0, tmp), L_deposit_l(lshr(lsb, sub(16, tmp)))); /* Qin+2+tmp */ - L_tmp0 = L_add(L_tmp0, L_shr(L_mult0(noise_level, Random(seed)), sub(30 - (qin + 2), tmp))); /* Qin+2+tmp */ - - tmp = round_fx(L_shl(L_tmp0, 27 - (qin + 2) - tmp)); /* Q11 (Qin+2+tmp+27-qin-2-tmp-16) */ - Mpy_32_16_ss(L_normq, tmp, &L_tmp0, &lsb); /* Q10 (14+11+1-16) */ - L_coeff_out[i] = L_add(L_shl(L_tmp0, qout - 10), L_deposit_l(lshr(lsb, 10 + 16 - qout))); - move32();/* Qout (10+qout-10) */ - } - ELSE - { - L_tmp0 = L_mult0(noise_level, Random(seed)); /* Q30 (15+15) */ - tmp = round_fx(L_tmp0); /* Q14 (30-16) */ - Mpy_32_16_ss(L_normq, tmp, &L_tmp0, &lsb); /* Q13 (14+14+1-16) */ - L_coeff_out[i] = L_shr(L_tmp0,13 - qout); - move32();/* Qout (13-(13-qout)) */ - } - } + Word16 i, tmp, n_c; + Word32 L_tmp0; + UWord16 lsb; + + n_c = sub( MAX_16, noise_level ); /* Q15 */ + FOR( i = istart; i < iend; i++ ) + { + /* L_coeff_out[i] = ((1.0f - noise_level)*coeff_fine[i]*L_E + noise_level*own_random(seed)/32768.0f)*normq; */ + Mpy_32_16_ss( L_E, coeff_fine[i], &L_tmp0, &lsb ); /* Qin+qL_E-15 (qL_E+qin+1-16) */ + Mpy_32_16_ss( L_tmp0, n_c, &L_tmp0, &lsb ); /* Qin+qL_E-15 (qin+qL_E-15+15+1-16) */ + + IF( L_tmp0 != 0 ) + { + /* Normalize with 1 bit headroom for addition */ + tmp = 30 - ( qin + 2 ); /* Assuming fixed Q values */ + tmp = s_min( norm_l( L_tmp0 ), tmp ); + tmp = sub( tmp, 1 ); + + L_tmp0 = L_add( L_shl( L_tmp0, tmp ), L_deposit_l( lshr( lsb, sub( 16, tmp ) ) ) ); /* Qin+2+tmp */ + L_tmp0 = L_add( L_tmp0, L_shr( L_mult0( noise_level, Random( seed ) ), sub( 30 - ( qin + 2 ), tmp ) ) ); /* Qin+2+tmp */ + + tmp = round_fx( L_shl( L_tmp0, 27 - ( qin + 2 ) - tmp ) ); /* Q11 (Qin+2+tmp+27-qin-2-tmp-16) */ + Mpy_32_16_ss( L_normq, tmp, &L_tmp0, &lsb ); /* Q10 (14+11+1-16) */ + L_coeff_out[i] = L_add( L_shl( L_tmp0, qout - 10 ), L_deposit_l( lshr( lsb, 10 + 16 - qout ) ) ); + move32(); /* Qout (10+qout-10) */ + } + ELSE + { + L_tmp0 = L_mult0( noise_level, Random( seed ) ); /* Q30 (15+15) */ + tmp = round_fx( L_tmp0 ); /* Q14 (30-16) */ + Mpy_32_16_ss( L_normq, tmp, &L_tmp0, &lsb ); /* Q13 (14+14+1-16) */ + L_coeff_out[i] = L_shr( L_tmp0, 13 - qout ); + move32(); /* Qout (13-(13-qout)) */ + } + } } @@ -1640,40 +1641,40 @@ void noise_mix_fx( * Prepare HQ GENERIC HF fine structure *--------------------------------------------------------------------------*/ void hq_generic_fine_fx( - Word16 *coeff, /* i : coded/noisefilled normalized spectrum */ - const Word16 last_sfm, /* i : Last coded band */ - const Word16 *sfm_start, /* i : Subband start coefficient */ - const Word16 *sfm_end, /* i : Subband end coefficient */ - Word16 *bwe_seed, /* i/o: random seed for generating BWE input */ - Word16 *coeff_out1 /* o : HQ GENERIC input */ + Word16 *coeff, /* i : coded/noisefilled normalized spectrum */ + const Word16 last_sfm, /* i : Last coded band */ + const Word16 *sfm_start, /* i : Subband start coefficient */ + const Word16 *sfm_end, /* i : Subband end coefficient */ + Word16 *bwe_seed, /* i/o: random seed for generating BWE input */ + Word16 *coeff_out1 /* o : HQ GENERIC input */ ) { - Word16 sfm; - Word16 i; - - FOR(sfm = 0; sfm <= last_sfm; sfm++) - { - FOR(i = sfm_start[sfm]; i < sfm_end[sfm]; i++) - { - IF(coeff[i] == 0) - { - coeff_out1[i] = -2048; - move16(); - if (Random(bwe_seed) > 0) - { - coeff_out1[i] = 2048; - move16(); - } - } - ELSE - { - coeff_out1[i] = coeff[i]; - move16(); - } - } - } - - return; + Word16 sfm; + Word16 i; + + FOR( sfm = 0; sfm <= last_sfm; sfm++ ) + { + FOR( i = sfm_start[sfm]; i < sfm_end[sfm]; i++ ) + { + IF( coeff[i] == 0 ) + { + coeff_out1[i] = -2048; + move16(); + if ( Random( bwe_seed ) > 0 ) + { + coeff_out1[i] = 2048; + move16(); + } + } + ELSE + { + coeff_out1[i] = coeff[i]; + move16(); + } + } + } + + return; } /*--------------------------------------------------------------------------* @@ -1682,54 +1683,53 @@ void hq_generic_fine_fx( * Overlapping at the boundary between HQ core and BWE *--------------------------------------------------------------------------*/ static void overlap_hq_bwe_fx( - const Word32 *hq_swb_overlap_buf, /* i : spectrum from HQ core */ - Word32 *coeff_out, /* i/o: spectrum from BWE, overlapped output */ - const Word16 n_swb_overlap_offset, /* i : starting offset of overlapping */ - const Word16 n_swb_overlap, /* i : length of overlapping */ - const Word16 *R, - const Word16 num_env_bands, - const Word16 num_sfm, - const Word16 *sfm_end -) + const Word32 *hq_swb_overlap_buf, /* i : spectrum from HQ core */ + Word32 *coeff_out, /* i/o: spectrum from BWE, overlapped output */ + const Word16 n_swb_overlap_offset, /* i : starting offset of overlapping */ + const Word16 n_swb_overlap, /* i : length of overlapping */ + const Word16 *R, + const Word16 num_env_bands, + const Word16 num_sfm, + const Word16 *sfm_end ) { - Word16 i; - Word16 weighting; - Word16 step; - Word16 exp, tmp, n_band; - - IF(R[sub(num_env_bands, 1)] != 0) - { - Copy32(hq_swb_overlap_buf, &coeff_out[n_swb_overlap_offset], n_swb_overlap); - } - ELSE - { - exp = norm_s(n_swb_overlap); - tmp = div_s(16384, shl(n_swb_overlap, exp));/*15 + 14 - exp */ - tmp = shr(tmp, sub(14, exp));/*15 */ - step = mult_r(tmp, 32767);/*15 */ - weighting = 32767; - move16(); - FOR(i = 0; i < n_swb_overlap; i++) - { - coeff_out[add(n_swb_overlap_offset,i)] = L_add(coeff_out[add(n_swb_overlap_offset,i)], - Mult_32_16(L_sub(hq_swb_overlap_buf[i], coeff_out[add(n_swb_overlap_offset,i)]), weighting)); - move32(); - weighting = sub(weighting, step); - } - } - - FOR(n_band = num_env_bands; n_band < num_sfm; n_band++) - { - IF(R[n_band] != 0) - { - FOR(i = sfm_end[sub(n_band, 1)]; i < sfm_end[n_band]; ++i) - { - coeff_out[i] = hq_swb_overlap_buf[sub(i, n_swb_overlap_offset)]; - move32(); - } - } - } - return; + Word16 i; + Word16 weighting; + Word16 step; + Word16 exp, tmp, n_band; + + IF( R[sub( num_env_bands, 1 )] != 0 ) + { + Copy32( hq_swb_overlap_buf, &coeff_out[n_swb_overlap_offset], n_swb_overlap ); + } + ELSE + { + exp = norm_s( n_swb_overlap ); + tmp = div_s( 16384, shl( n_swb_overlap, exp ) ); /*15 + 14 - exp */ + tmp = shr( tmp, sub( 14, exp ) ); /*15 */ + step = mult_r( tmp, 32767 ); /*15 */ + weighting = 32767; + move16(); + FOR( i = 0; i < n_swb_overlap; i++ ) + { + coeff_out[add( n_swb_overlap_offset, i )] = L_add( coeff_out[add( n_swb_overlap_offset, i )], + Mult_32_16( L_sub( hq_swb_overlap_buf[i], coeff_out[add( n_swb_overlap_offset, i )] ), weighting ) ); + move32(); + weighting = sub( weighting, step ); + } + } + + FOR( n_band = num_env_bands; n_band < num_sfm; n_band++ ) + { + IF( R[n_band] != 0 ) + { + FOR( i = sfm_end[sub( n_band, 1 )]; i < sfm_end[n_band]; ++i ) + { + coeff_out[i] = hq_swb_overlap_buf[sub( i, n_swb_overlap_offset )]; + move32(); + } + } + } + return; } /*--------------------------------------------------------------------------* @@ -1738,311 +1738,308 @@ static void overlap_hq_bwe_fx( * mapping high frequency envelope to high band norm *--------------------------------------------------------------------------*/ void map_hq_generic_fenv_norm_fx( - const Word16 hqswb_clas, - const Word16 *hq_generic_fenv, /* Q1, frequency-domain BWE envelope */ - Word16 *ynrm, - Word16 *normqlg2, - const Word16 num_env_bands, - const Word16 nb_sfm, - const Word16 hq_generic_offset -) + const Word16 hqswb_clas, + const Word16 *hq_generic_fenv, /* Q1, frequency-domain BWE envelope */ + Word16 *ynrm, + Word16 *normqlg2, + const Word16 num_env_bands, + const Word16 nb_sfm, + const Word16 hq_generic_offset ) { - Word32 env_fl[17];/*Q10 */ - Word16 i; - - set32_fx(env_fl, 0, 17); - - IF(EQ_16(hq_generic_offset, 144)) - { - env_fl[0] = L_shl(hq_generic_fenv[1], 7); - move32(); - env_fl[1] = L_add(L_mult0(hq_generic_fenv[2], 85), L_mult0(hq_generic_fenv[3], 43)); - move32(); - env_fl[2] = L_add(L_mult0(hq_generic_fenv[3], 85), L_mult0(hq_generic_fenv[4], 43)); - move32(); - env_fl[3] = L_add(L_mult0(hq_generic_fenv[4], 43), L_mult0(hq_generic_fenv[5], 85)); - move32(); - env_fl[4] = L_add(L_mult0(hq_generic_fenv[5], 43), L_mult0(hq_generic_fenv[6], 85)); - move32(); - env_fl[5] = L_shl(hq_generic_fenv[7], 7); - move32(); - env_fl[6] = L_add(L_mult0(hq_generic_fenv[8], 96), L_mult0(hq_generic_fenv[9], 32)); - move32(); - env_fl[7] = L_add(L_mult0(hq_generic_fenv[9], 96), L_mult0(hq_generic_fenv[10], 32)); - move32(); - env_fl[8] = L_add(L_mult0(hq_generic_fenv[10], 32), L_mult0(hq_generic_fenv[11], 96)); - move32(); - } - ELSE - { - env_fl[0] = L_add(L_mult0(hq_generic_fenv[0],43),L_mult0(hq_generic_fenv[1],85)); - move32(); - env_fl[1] = L_add(L_mult0(hq_generic_fenv[1],43),L_mult0(hq_generic_fenv[2],85)); - move32(); - env_fl[2] = L_shl(hq_generic_fenv[3],7); - move32(); - env_fl[3] = L_add(L_mult0(hq_generic_fenv[4],85),L_mult0(hq_generic_fenv[5],43)); - move32(); - env_fl[4] = L_add(L_mult0(hq_generic_fenv[5],85),L_mult0(hq_generic_fenv[6],43)); - move32(); - env_fl[5] = L_add(L_mult0(hq_generic_fenv[6],43),L_mult0(hq_generic_fenv[7],85)); - move32(); - env_fl[6] = L_add(L_mult0(hq_generic_fenv[7],43),L_mult0(hq_generic_fenv[8],85)); - move32(); - env_fl[7] = L_add(L_mult0(hq_generic_fenv[8],43),L_mult0(hq_generic_fenv[9],85)); - move32(); - env_fl[8] = L_add(L_mult0(hq_generic_fenv[9],43),L_mult0(hq_generic_fenv[10],85)); - move32(); - env_fl[9] = L_add(L_mult0(hq_generic_fenv[10],32),L_mult0(hq_generic_fenv[11],96)); - move32(); - env_fl[10] = L_shl(hq_generic_fenv[12],7); - move32(); - env_fl[11] = L_shl(hq_generic_fenv[13],7); - move32(); - } - - IF(EQ_16(hqswb_clas, HQ_GEN_FB)) - { - IF(EQ_16(hq_generic_offset, 144)) - { - env_fl[9] = L_shl(hq_generic_fenv[12], 7); - move32(); - env_fl[10] = L_add(L_mult0(hq_generic_fenv[12], 32), L_mult0(hq_generic_fenv[13], 96)); - move32(); - env_fl[11] = L_add(L_mult0(hq_generic_fenv[13], 64), L_mult0(hq_generic_fenv[14], 64)); - move32(); - env_fl[12] = L_shl(hq_generic_fenv[12], 7); - move32(); - env_fl[13] = env_fl[12]; - move32(); - } - ELSE - { - env_fl[12] = L_shl(hq_generic_fenv[14],7); - move32(); - env_fl[13] = L_add(L_mult0(hq_generic_fenv[14],32),L_mult0(hq_generic_fenv[15],96)); - move32(); - env_fl[14] = L_add(L_mult0(hq_generic_fenv[15],64),L_mult0(hq_generic_fenv[16],64)); - move32(); - env_fl[15] = L_shl(hq_generic_fenv[16],7); - move32(); - env_fl[16] = env_fl[15]; - move32(); - } - } - - logqnorm_2_fx(env_fl, 40, num_env_bands, nb_sfm, ynrm + num_env_bands, normqlg2 + num_env_bands, thren_fx); - - FOR(i = num_env_bands; i < nb_sfm; ++i) - { - normqlg2[i] = dicnlg2[s_min(add(ynrm[i], 10), 39)]; - move16(); - } - return; + Word32 env_fl[17]; /*Q10 */ + Word16 i; + + set32_fx( env_fl, 0, 17 ); + + IF( EQ_16( hq_generic_offset, 144 ) ) + { + env_fl[0] = L_shl( hq_generic_fenv[1], 7 ); + move32(); + env_fl[1] = L_add( L_mult0( hq_generic_fenv[2], 85 ), L_mult0( hq_generic_fenv[3], 43 ) ); + move32(); + env_fl[2] = L_add( L_mult0( hq_generic_fenv[3], 85 ), L_mult0( hq_generic_fenv[4], 43 ) ); + move32(); + env_fl[3] = L_add( L_mult0( hq_generic_fenv[4], 43 ), L_mult0( hq_generic_fenv[5], 85 ) ); + move32(); + env_fl[4] = L_add( L_mult0( hq_generic_fenv[5], 43 ), L_mult0( hq_generic_fenv[6], 85 ) ); + move32(); + env_fl[5] = L_shl( hq_generic_fenv[7], 7 ); + move32(); + env_fl[6] = L_add( L_mult0( hq_generic_fenv[8], 96 ), L_mult0( hq_generic_fenv[9], 32 ) ); + move32(); + env_fl[7] = L_add( L_mult0( hq_generic_fenv[9], 96 ), L_mult0( hq_generic_fenv[10], 32 ) ); + move32(); + env_fl[8] = L_add( L_mult0( hq_generic_fenv[10], 32 ), L_mult0( hq_generic_fenv[11], 96 ) ); + move32(); + } + ELSE + { + env_fl[0] = L_add( L_mult0( hq_generic_fenv[0], 43 ), L_mult0( hq_generic_fenv[1], 85 ) ); + move32(); + env_fl[1] = L_add( L_mult0( hq_generic_fenv[1], 43 ), L_mult0( hq_generic_fenv[2], 85 ) ); + move32(); + env_fl[2] = L_shl( hq_generic_fenv[3], 7 ); + move32(); + env_fl[3] = L_add( L_mult0( hq_generic_fenv[4], 85 ), L_mult0( hq_generic_fenv[5], 43 ) ); + move32(); + env_fl[4] = L_add( L_mult0( hq_generic_fenv[5], 85 ), L_mult0( hq_generic_fenv[6], 43 ) ); + move32(); + env_fl[5] = L_add( L_mult0( hq_generic_fenv[6], 43 ), L_mult0( hq_generic_fenv[7], 85 ) ); + move32(); + env_fl[6] = L_add( L_mult0( hq_generic_fenv[7], 43 ), L_mult0( hq_generic_fenv[8], 85 ) ); + move32(); + env_fl[7] = L_add( L_mult0( hq_generic_fenv[8], 43 ), L_mult0( hq_generic_fenv[9], 85 ) ); + move32(); + env_fl[8] = L_add( L_mult0( hq_generic_fenv[9], 43 ), L_mult0( hq_generic_fenv[10], 85 ) ); + move32(); + env_fl[9] = L_add( L_mult0( hq_generic_fenv[10], 32 ), L_mult0( hq_generic_fenv[11], 96 ) ); + move32(); + env_fl[10] = L_shl( hq_generic_fenv[12], 7 ); + move32(); + env_fl[11] = L_shl( hq_generic_fenv[13], 7 ); + move32(); + } + + IF( EQ_16( hqswb_clas, HQ_GEN_FB ) ) + { + IF( EQ_16( hq_generic_offset, 144 ) ) + { + env_fl[9] = L_shl( hq_generic_fenv[12], 7 ); + move32(); + env_fl[10] = L_add( L_mult0( hq_generic_fenv[12], 32 ), L_mult0( hq_generic_fenv[13], 96 ) ); + move32(); + env_fl[11] = L_add( L_mult0( hq_generic_fenv[13], 64 ), L_mult0( hq_generic_fenv[14], 64 ) ); + move32(); + env_fl[12] = L_shl( hq_generic_fenv[12], 7 ); + move32(); + env_fl[13] = env_fl[12]; + move32(); + } + ELSE + { + env_fl[12] = L_shl( hq_generic_fenv[14], 7 ); + move32(); + env_fl[13] = L_add( L_mult0( hq_generic_fenv[14], 32 ), L_mult0( hq_generic_fenv[15], 96 ) ); + move32(); + env_fl[14] = L_add( L_mult0( hq_generic_fenv[15], 64 ), L_mult0( hq_generic_fenv[16], 64 ) ); + move32(); + env_fl[15] = L_shl( hq_generic_fenv[16], 7 ); + move32(); + env_fl[16] = env_fl[15]; + move32(); + } + } + + logqnorm_2_fx( env_fl, 40, num_env_bands, nb_sfm, ynrm + num_env_bands, normqlg2 + num_env_bands, thren_fx ); + + FOR( i = num_env_bands; i < nb_sfm; ++i ) + { + normqlg2[i] = dicnlg2[s_min( add( ynrm[i], 10 ), 39 )]; + move16(); + } + return; } -static void update_rsubband_fx(const Word16 nb_sfm, - Word16 *Rsubband, /* Q3 */ - Word16 b_add_bits_denv -) +static void update_rsubband_fx( const Word16 nb_sfm, + Word16 *Rsubband, /* Q3 */ + Word16 b_add_bits_denv ) { - Word16 i; - - /* updating bit allocation */ - WHILE(b_add_bits_denv > 0) - { - i = sub(nb_sfm, 1); - WHILE(b_add_bits_denv > 0 && i >= 0) - { - IF(GT_16(Rsubband[i], 24)) - { - Rsubband[i] = sub(Rsubband[i], 8); - move16(); - b_add_bits_denv = sub(b_add_bits_denv, 1); - } - i = sub(i, 1); - } - } - - return; + Word16 i; + + /* updating bit allocation */ + WHILE( b_add_bits_denv > 0 ) + { + i = sub( nb_sfm, 1 ); + WHILE( b_add_bits_denv > 0 && i >= 0 ) + { + IF( GT_16( Rsubband[i], 24 ) ) + { + Rsubband[i] = sub( Rsubband[i], 8 ); + move16(); + b_add_bits_denv = sub( b_add_bits_denv, 1 ); + } + i = sub( i, 1 ); + } + } + + return; } Word16 get_nor_delta_hf_fx( - Decoder_State *st, - Word16 *ynrm, - Word16 *Rsubband, /* Q3 */ - const Word16 num_env_bands, - const Word16 nb_sfm, - const Word16 core_sfm -) + Decoder_State *st, + Word16 *ynrm, + Word16 *Rsubband, /* Q3 */ + const Word16 num_env_bands, + const Word16 nb_sfm, + const Word16 core_sfm ) { - Word16 i; - Word16 delta, bitsforDelta, add_bits_denv; - - add_bits_denv = 0; - move16(); - IF(GE_16(core_sfm, num_env_bands)) - { - bitsforDelta = (Word16)get_next_indice(st, 2); - bitsforDelta = add(bitsforDelta, 2); - add_bits_denv = add(add_bits_denv, 2); - - FOR(i = num_env_bands; i < nb_sfm; ++i) - { - IF(Rsubband[i] != 0) - { - delta = (Word16)get_next_indice(st, bitsforDelta); - ynrm[i] = add(ynrm[i], sub(delta, (shl(1, sub(bitsforDelta, 1))))); - move16(); - - /* safety check in case of bit errors */ - test(); - if (ynrm[i] < 0 || GT_16(ynrm[i], 39)) - { - ynrm[i] = 39; - move16(); - st->BER_detect = 1; - move16(); - } - /*ynrm[i] += delta - (1<<(bitsforDelta-1));*/ - add_bits_denv = add(add_bits_denv, bitsforDelta); - } - } - update_rsubband_fx(nb_sfm, Rsubband, add_bits_denv); - } - return add_bits_denv; + Word16 i; + Word16 delta, bitsforDelta, add_bits_denv; + + add_bits_denv = 0; + move16(); + IF( GE_16( core_sfm, num_env_bands ) ) + { + bitsforDelta = (Word16) get_next_indice( st, 2 ); + bitsforDelta = add( bitsforDelta, 2 ); + add_bits_denv = add( add_bits_denv, 2 ); + + FOR( i = num_env_bands; i < nb_sfm; ++i ) + { + IF( Rsubband[i] != 0 ) + { + delta = (Word16) get_next_indice( st, bitsforDelta ); + ynrm[i] = add( ynrm[i], sub( delta, ( shl( 1, sub( bitsforDelta, 1 ) ) ) ) ); + move16(); + + /* safety check in case of bit errors */ + test(); + if ( ynrm[i] < 0 || GT_16( ynrm[i], 39 ) ) + { + ynrm[i] = 39; + move16(); + st->BER_detect = 1; + move16(); + } + /*ynrm[i] += delta - (1<<(bitsforDelta-1));*/ + add_bits_denv = add( add_bits_denv, bitsforDelta ); + } + } + update_rsubband_fx( nb_sfm, Rsubband, add_bits_denv ); + } + return add_bits_denv; } /*-------------------------------------------------------------------* -* calc_nor_delta_hf() -* -* -*--------------------------------------------------------------------------*/ + * calc_nor_delta_hf() + * + * + *--------------------------------------------------------------------------*/ Word16 calc_nor_delta_hf_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word32* t_audio, /* i : transform-domain coefficients */ - Word16* ynrm, /* i/o: norm indices */ - Word16* Rsubband, /* i/o: sub-band bit allocation */ - const Word16 num_env_bands, /* i : Number coded envelope bands */ - const Word16 nb_sfm, /* i : Number of envelope bands */ - const Word16* sfmsize, /* i : band length */ - const Word16* sfm_start, /* i : Start index of bands */ - const Word16 core_sfm /* i : index of the end band for core */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word32 *t_audio, /* i : transform-domain coefficients */ + Word16 *ynrm, /* i/o: norm indices */ + Word16 *Rsubband, /* i/o: sub-band bit allocation */ + const Word16 num_env_bands, /* i : Number coded envelope bands */ + const Word16 nb_sfm, /* i : Number of envelope bands */ + const Word16 *sfmsize, /* i : band length */ + const Word16 *sfm_start, /* i : Start index of bands */ + const Word16 core_sfm /* i : index of the end band for core */ ) { - Word16 i; - Word16 ynrm_t[44], normqlg2_t[44]; - Word16 delta, max_delta, min_delta, bitsforDelta, add_bits_denv; - - max_delta = -100; - move16(); - calc_norm_fx(t_audio, 12, ynrm_t, normqlg2_t, 0, nb_sfm, sfmsize, sfm_start); - add_bits_denv = 0; - move16(); - FOR(i = num_env_bands; i < nb_sfm; ++i) - { - IF(Rsubband[i] != 0) - { - delta = sub(ynrm_t[i], ynrm[i]); - IF(delta > 0) - { - delta = add(delta, 1); - } - ELSE - { - delta = negate(delta); - } - if (GT_16(delta, max_delta)) - { - max_delta = delta; - move16(); - } - } - } - IF(GE_16(core_sfm, num_env_bands)) - { - IF(LT_16(max_delta, 16)) - { - bitsforDelta = 2; - move16(); - FOR(; max_delta >= 2; max_delta >>= 1) - { - bitsforDelta = add(bitsforDelta, 1); - } - } - ELSE - { - bitsforDelta = 5; - move16(); - } - max_delta = sub(shl(1, sub(bitsforDelta, 1)), 1); - min_delta = negate(add(max_delta, 1)); - - /* updating norm & storing delta norm */ - add_bits_denv = 2; - move16(); - push_indice_fx(hBstr, IND_DELTA_ENV_HQ, sub(bitsforDelta, 2), 2); - FOR(i = num_env_bands; i < nb_sfm; ++i) - { - IF(Rsubband[i] != 0) - { - delta = sub(ynrm_t[i], ynrm[i]); - IF(GT_16(delta, max_delta)) - { - delta = max_delta; - move16(); - } - ELSE if (LT_16(delta, min_delta)) - { - delta = min_delta; - move16(); - } - push_indice_fx(hBstr, IND_DELTA_ENV_HQ, delta - min_delta, bitsforDelta); - ynrm[i] = add(ynrm[i], delta); - move16(); - add_bits_denv = add(add_bits_denv, bitsforDelta); - } - } - - /* updating bit allocation */ - update_rsubband_fx(nb_sfm, Rsubband, add_bits_denv); - } - return add_bits_denv; + Word16 i; + Word16 ynrm_t[44], normqlg2_t[44]; + Word16 delta, max_delta, min_delta, bitsforDelta, add_bits_denv; + + max_delta = -100; + move16(); + calc_norm_fx( t_audio, 12, ynrm_t, normqlg2_t, 0, nb_sfm, sfmsize, sfm_start ); + add_bits_denv = 0; + move16(); + FOR( i = num_env_bands; i < nb_sfm; ++i ) + { + IF( Rsubband[i] != 0 ) + { + delta = sub( ynrm_t[i], ynrm[i] ); + IF( delta > 0 ) + { + delta = add( delta, 1 ); + } + ELSE + { + delta = negate( delta ); + } + if ( GT_16( delta, max_delta ) ) + { + max_delta = delta; + move16(); + } + } + } + IF( GE_16( core_sfm, num_env_bands ) ) + { + IF( LT_16( max_delta, 16 ) ) + { + bitsforDelta = 2; + move16(); + FOR( ; max_delta >= 2; max_delta >>= 1 ) + { + bitsforDelta = add( bitsforDelta, 1 ); + } + } + ELSE + { + bitsforDelta = 5; + move16(); + } + max_delta = sub( shl( 1, sub( bitsforDelta, 1 ) ), 1 ); + min_delta = negate( add( max_delta, 1 ) ); + + /* updating norm & storing delta norm */ + add_bits_denv = 2; + move16(); + push_indice_fx( hBstr, IND_DELTA_ENV_HQ, sub( bitsforDelta, 2 ), 2 ); + FOR( i = num_env_bands; i < nb_sfm; ++i ) + { + IF( Rsubband[i] != 0 ) + { + delta = sub( ynrm_t[i], ynrm[i] ); + IF( GT_16( delta, max_delta ) ) + { + delta = max_delta; + move16(); + } + ELSE if ( LT_16( delta, min_delta ) ) + { + delta = min_delta; + move16(); + } + push_indice_fx( hBstr, IND_DELTA_ENV_HQ, delta - min_delta, bitsforDelta ); + ynrm[i] = add( ynrm[i], delta ); + move16(); + add_bits_denv = add( add_bits_denv, bitsforDelta ); + } + } + + /* updating bit allocation */ + update_rsubband_fx( nb_sfm, Rsubband, add_bits_denv ); + } + return add_bits_denv; } /*-------------------------------------------------------------------* -* hq_bwe_fx() -* -* HQ GENERIC -*--------------------------------------------------------------------------*/ + * hq_bwe_fx() + * + * HQ GENERIC + *--------------------------------------------------------------------------*/ void hq_bwe_fx( - const Word16 HQ_mode, /* i : HQ mode */ - Word32* coeff_out1, /* i/o: BWE input & temporary buffer */ - const Word16* hq_generic_fenv, /* i : SWB frequency envelopes */ - Word32* coeff_out, /* o : SWB signal in MDCT domain */ - const Word16 hq_generic_offset, /* i : frequency offset for representing hq generic*/ - Word16* prev_L_swb_norm, /* i/o: last normalize length */ - const Word16 hq_generic_exc_clas, /* i : hq generic hf excitation class */ - const Word16* sfm_end, /* i : End of bands */ - const Word16 num_sfm, /* i : Number of bands */ - const Word16 num_env_bands, /* i : Number of coded envelope bands */ - const Word16* R /* i : Bit allocation */ + const Word16 HQ_mode, /* i : HQ mode */ + Word32 *coeff_out1, /* i/o: BWE input & temporary buffer */ + const Word16 *hq_generic_fenv, /* i : SWB frequency envelopes */ + Word32 *coeff_out, /* o : SWB signal in MDCT domain */ + const Word16 hq_generic_offset, /* i : frequency offset for representing hq generic*/ + Word16 *prev_L_swb_norm, /* i/o: last normalize length */ + const Word16 hq_generic_exc_clas, /* i : hq generic hf excitation class */ + const Word16 *sfm_end, /* i : End of bands */ + const Word16 num_sfm, /* i : Number of bands */ + const Word16 num_env_bands, /* i : Number of coded envelope bands */ + const Word16 *R /* i : Bit allocation */ ) { - Word16 n_swb_overlap_offset, n_swb_overlap; - Word32 hq_swb_overlap_buf_fx[L_FRAME32k]; + Word16 n_swb_overlap_offset, n_swb_overlap; + Word32 hq_swb_overlap_buf_fx[L_FRAME32k]; - n_swb_overlap_offset = add(swb_bwe_subband[0], hq_generic_offset); - n_swb_overlap = sub(sfm_end[sub(num_env_bands, 1)], n_swb_overlap_offset); + n_swb_overlap_offset = add( swb_bwe_subband[0], hq_generic_offset ); + n_swb_overlap = sub( sfm_end[sub( num_env_bands, 1 )], n_swb_overlap_offset ); - Copy32(&coeff_out[n_swb_overlap_offset], hq_swb_overlap_buf_fx, sub(add(n_swb_overlap, sfm_end[sub(num_sfm, 1)]), sfm_end[sub(num_env_bands, 1)])); + Copy32( &coeff_out[n_swb_overlap_offset], hq_swb_overlap_buf_fx, sub( add( n_swb_overlap, sfm_end[sub( num_sfm, 1 )] ), sfm_end[sub( num_env_bands, 1 )] ) ); - hq_generic_decoding_fx(HQ_mode, coeff_out1, hq_generic_fenv, coeff_out, hq_generic_offset, prev_L_swb_norm, hq_generic_exc_clas, R); + hq_generic_decoding_fx( HQ_mode, coeff_out1, hq_generic_fenv, coeff_out, hq_generic_offset, prev_L_swb_norm, hq_generic_exc_clas, R ); - overlap_hq_bwe_fx(hq_swb_overlap_buf_fx, coeff_out, n_swb_overlap_offset, n_swb_overlap, R, num_env_bands, num_sfm, sfm_end); + overlap_hq_bwe_fx( hq_swb_overlap_buf_fx, coeff_out, n_swb_overlap_offset, n_swb_overlap, R, num_env_bands, num_sfm, sfm_end ); - return; + return; } /*--------------------------------------------------------------------------* @@ -2052,457 +2049,450 @@ void hq_bwe_fx( *--------------------------------------------------------------------------*/ void hq_wb_nf_bwe_fx( - const Word16 *coeff_fx, /* i : coded/noisefilled normalized spectrum */ - const Word16 is_transient, - const Word16 prev_bfi, /* i : previous bad frame indicator */ - const Word32 *L_normq_v, - const Word16 num_sfm, /* i : Number of subbands */ - const Word16 *sfm_start, /* i : Subband start coefficient */ - const Word16 *sfm_end, /* i : Subband end coefficient */ - const Word16 *sfmsize, /* i : Subband band width */ - const Word16 last_sfm, /* i : last coded subband */ - const Word16 *R, /* i : bit allocation */ - const Word16 prev_is_transient, /* i : previous transient flag */ - Word32 *prev_normq_fx, /* i/o: previous norms */ - Word32 *prev_env_fx, /* i/o: previous noise envelopes */ - Word16 *bwe_seed, /* i/o: random seed for generating BWE input */ - Word32 *prev_coeff_out_fx, /* i/o: decoded spectrum in previous frame */ - Word16 *prev_R, /* i/o: bit allocation info. in previous frame */ - Word32 *L_coeff_out, /* o : coded/noisefilled spectrum */ - Word16 *prev_env_Q -) + const Word16 *coeff_fx, /* i : coded/noisefilled normalized spectrum */ + const Word16 is_transient, + const Word16 prev_bfi, /* i : previous bad frame indicator */ + const Word32 *L_normq_v, + const Word16 num_sfm, /* i : Number of subbands */ + const Word16 *sfm_start, /* i : Subband start coefficient */ + const Word16 *sfm_end, /* i : Subband end coefficient */ + const Word16 *sfmsize, /* i : Subband band width */ + const Word16 last_sfm, /* i : last coded subband */ + const Word16 *R, /* i : bit allocation */ + const Word16 prev_is_transient, /* i : previous transient flag */ + Word32 *prev_normq_fx, /* i/o: previous norms */ + Word32 *prev_env_fx, /* i/o: previous noise envelopes */ + Word16 *bwe_seed, /* i/o: random seed for generating BWE input */ + Word32 *prev_coeff_out_fx, /* i/o: decoded spectrum in previous frame */ + Word16 *prev_R, /* i/o: bit allocation info. in previous frame */ + Word32 *L_coeff_out, /* o : coded/noisefilled spectrum */ + Word16 *prev_env_Q ) { - Word16 i; - Word16 sfm; - Word16 total_bit; - Word16 num; - Word32 env_fx, peak_fx, fabs_coeff_out_fx, min_coef_fx; - Word32 L_tmp1, L_tmp2 = 0, L_tmp3, L_tmp4; - Word16 tmp1, exp = 0, exp1, exp2, exp3, harm_para_fx, sharp_fx, step_fx, alfa_fx = 4096; - Word32 avrg_norm_fx, prev_avrg_norm_fx; - Word16 bitalloc_var_fx; - Word16 tmp; - Word32 L_tmp; - Word32 mean_fx; - - IF(is_transient == 0) - { - IF(EQ_16(prev_bfi, 1)) - { - Copy32(L_normq_v, prev_normq_fx, SFM_N_WB); - } - - /* the variance of bit allocation */ - total_bit = 0; - bitalloc_var_fx = 0; - FOR(sfm = 8; sfm <= last_sfm; sfm++) - { - tmp = abs_s(sub(R[sfm], R[sub(sfm, 1)])); - bitalloc_var_fx = add(bitalloc_var_fx, tmp); - total_bit = add(total_bit, R[sfm]); - } - test(); - IF(GT_16(last_sfm, 8) && total_bit > 0) - { - exp = norm_s(total_bit); - tmp = shl(total_bit, exp);/*Q(exp) */ - tmp = div_s(16384, tmp);/*Q(15+14-exp) */ - L_tmp = L_mult(tmp, bitalloc_var_fx); /*Q(29-exp+1) */ + Word16 i; + Word16 sfm; + Word16 total_bit; + Word16 num; + Word32 env_fx, peak_fx, fabs_coeff_out_fx, min_coef_fx; + Word32 L_tmp1, L_tmp2 = 0, L_tmp3, L_tmp4; + Word16 tmp1, exp = 0, exp1, exp2, exp3, harm_para_fx, sharp_fx, step_fx, alfa_fx = 4096; + Word32 avrg_norm_fx, prev_avrg_norm_fx; + Word16 bitalloc_var_fx; + Word16 tmp; + Word32 L_tmp; + Word32 mean_fx; + + IF( is_transient == 0 ) + { + IF( EQ_16( prev_bfi, 1 ) ) + { + Copy32( L_normq_v, prev_normq_fx, SFM_N_WB ); + } + + /* the variance of bit allocation */ + total_bit = 0; + bitalloc_var_fx = 0; + FOR( sfm = 8; sfm <= last_sfm; sfm++ ) + { + tmp = abs_s( sub( R[sfm], R[sub( sfm, 1 )] ) ); + bitalloc_var_fx = add( bitalloc_var_fx, tmp ); + total_bit = add( total_bit, R[sfm] ); + } + test(); + IF( GT_16( last_sfm, 8 ) && total_bit > 0 ) + { + exp = norm_s( total_bit ); + tmp = shl( total_bit, exp ); /*Q(exp) */ + tmp = div_s( 16384, tmp ); /*Q(15+14-exp) */ + L_tmp = L_mult( tmp, bitalloc_var_fx ); /*Q(29-exp+1) */ #ifdef BASOP_NOGLOB - bitalloc_var_fx = round_fx_sat(L_shl_sat(L_tmp, exp));/*Q14 */ + bitalloc_var_fx = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /*Q14 */ #else - bitalloc_var_fx = round_fx(L_shl(L_tmp, exp));/*Q14 */ + bitalloc_var_fx = round_fx( L_shl( L_tmp, exp ) ); /*Q14 */ #endif - } - ELSE - { - bitalloc_var_fx = 0; /*Q14 */ - } - /* calculate the peak-average ratio of saturable subbands */ - num = 0; - sharp_fx = 0; - FOR(sfm = last_sfm; sfm >= 8; sfm--) - { - tmp = shl(sfmsize[sfm], 9);/*Q9 */ - tmp = mult(rat_fx[sfm], tmp);/*Q(14+9-15=8) */ + } + ELSE + { + bitalloc_var_fx = 0; /*Q14 */ + } + /* calculate the peak-average ratio of saturable subbands */ + num = 0; + sharp_fx = 0; + FOR( sfm = last_sfm; sfm >= 8; sfm-- ) + { + tmp = shl( sfmsize[sfm], 9 ); /*Q9 */ + tmp = mult( rat_fx[sfm], tmp ); /*Q(14+9-15=8) */ #ifdef BASOP_NOGLOB - IF(GE_16(shl_sat(R[sfm], 8), tmp)) + IF( GE_16( shl_sat( R[sfm], 8 ), tmp ) ) #else - IF(GE_16(shl(R[sfm], 8), tmp)) + IF( GE_16( shl( R[sfm], 8 ), tmp ) ) #endif - { - peak_fx = 0; - move16(); - mean_fx = 0; - move16(); - FOR(i = sfm_start[sfm]; i < sfm_end[sfm]; i++) - { - fabs_coeff_out_fx = L_abs(L_coeff_out[i]); + { + peak_fx = 0; + move16(); + mean_fx = 0; + move16(); + FOR( i = sfm_start[sfm]; i < sfm_end[sfm]; i++ ) + { + fabs_coeff_out_fx = L_abs( L_coeff_out[i] ); #ifdef BASOP_NOGLOB - mean_fx = L_add_sat(mean_fx, fabs_coeff_out_fx);/*Q12 */ + mean_fx = L_add_sat( mean_fx, fabs_coeff_out_fx ); /*Q12 */ #else - mean_fx = L_add(mean_fx, fabs_coeff_out_fx);/*Q12 */ + mean_fx = L_add( mean_fx, fabs_coeff_out_fx ); /*Q12 */ #endif - if (GT_32(fabs_coeff_out_fx, peak_fx)) - { - peak_fx = fabs_coeff_out_fx;/*Q12 */ - move32(); - } - } - - IF(mean_fx != 0) - { - exp = norm_l(mean_fx); + if ( GT_32( fabs_coeff_out_fx, peak_fx ) ) + { + peak_fx = fabs_coeff_out_fx; /*Q12 */ + move32(); + } + } + + IF( mean_fx != 0 ) + { + exp = norm_l( mean_fx ); #ifdef BASOP_NOGLOB - mean_fx = L_shl_sat(mean_fx, exp);/*Q(exp+12) */ - tmp = round_fx_sat(mean_fx);/*Q(exp-4) */ + mean_fx = L_shl_sat( mean_fx, exp ); /*Q(exp+12) */ + tmp = round_fx_sat( mean_fx ); /*Q(exp-4) */ #else - mean_fx = L_shl(mean_fx, exp);/*Q(exp+12) */ - tmp = round_fx(mean_fx);/*Q(exp-4) */ + mean_fx = L_shl( mean_fx, exp ); /*Q(exp+12) */ + tmp = round_fx( mean_fx ); /*Q(exp-4) */ #endif - tmp = div_s(16384, tmp); /*Q(15+14-exp+4 = 33-exp) */ - L_tmp = Mult_32_16(peak_fx, tmp);/*Q(12+33-exp-15 = 30-exp) */ - tmp = shl(sfmsize[sfm], 9);/*Q9 */ - L_tmp = Mult_32_16(L_tmp, tmp);/*Q(30-exp+9-15 = 24-exp) */ - tmp = round_fx(L_shl(L_tmp, exp));/*Q8 */ - sharp_fx = add(sharp_fx, tmp); - } - num = add(num, 1); - } - } - test(); - IF(num != 0 && sharp_fx != 0) - { - num = add(num, num); - exp = norm_s(sharp_fx); - sharp_fx = shl(sharp_fx, exp);/*Q(8+exp) */ - tmp = div_s(16384, sharp_fx);/*Q(21-exp) */ - L_tmp = L_mult(num, tmp);/*Q(22-exp) */ - sharp_fx = round_fx(L_shl(L_tmp, add(8, exp)));/*Q14 */ - } - ELSE - { - sharp_fx = 16384; - move16();/*Q14 = 1 */ - } - harm_para_fx = sharp_fx; - move16();/*Q14 */ - - IF(last_sfm == 0) - { - tmp = 0; - move16(); - } - ELSE - { - tmp = div_s(1,last_sfm);/*Q15 */ - } - - L_tmp = L_mult(5, sharp_fx);/*Q15 */ - L_tmp = Mult_32_16(L_tmp, tmp);/*Q15 */ + tmp = div_s( 16384, tmp ); /*Q(15+14-exp+4 = 33-exp) */ + L_tmp = Mult_32_16( peak_fx, tmp ); /*Q(12+33-exp-15 = 30-exp) */ + tmp = shl( sfmsize[sfm], 9 ); /*Q9 */ + L_tmp = Mult_32_16( L_tmp, tmp ); /*Q(30-exp+9-15 = 24-exp) */ + tmp = round_fx( L_shl( L_tmp, exp ) ); /*Q8 */ + sharp_fx = add( sharp_fx, tmp ); + } + num = add( num, 1 ); + } + } + test(); + IF( num != 0 && sharp_fx != 0 ) + { + num = add( num, num ); + exp = norm_s( sharp_fx ); + sharp_fx = shl( sharp_fx, exp ); /*Q(8+exp) */ + tmp = div_s( 16384, sharp_fx ); /*Q(21-exp) */ + L_tmp = L_mult( num, tmp ); /*Q(22-exp) */ + sharp_fx = round_fx( L_shl( L_tmp, add( 8, exp ) ) ); /*Q14 */ + } + ELSE + { + sharp_fx = 16384; + move16(); /*Q14 = 1 */ + } + harm_para_fx = sharp_fx; + move16(); /*Q14 */ + + IF( last_sfm == 0 ) + { + tmp = 0; + move16(); + } + ELSE + { + tmp = div_s( 1, last_sfm ); /*Q15 */ + } + + L_tmp = L_mult( 5, sharp_fx ); /*Q15 */ + L_tmp = Mult_32_16( L_tmp, tmp ); /*Q15 */ #ifdef BASOP_NOGLOB - step_fx = round_fx_sat(L_shl_sat(L_tmp, 16));/*Q15 */ + step_fx = round_fx_sat( L_shl_sat( L_tmp, 16 ) ); /*Q15 */ #else - step_fx = round_fx(L_shl(L_tmp, 16));/*Q15 */ + step_fx = round_fx( L_shl( L_tmp, 16 ) ); /*Q15 */ #endif - alfa_fx = 20480; - move16();/*Q13 = 2.5 */ - /* fill noise for the insaturable subbands */ - FOR(sfm = 0; sfm < num_sfm; sfm++) - { - env_fx = L_deposit_l(0); - L_tmp2 = L_deposit_l(0); - exp = 0; - move16(); - test(); - IF(R[sfm] != 0 && LT_16(R[sfm], shl(mult(24756, sfmsize[sfm]), 1))) - { - /* calculate the energy of the undecoded coefficients */ - env_fx = L_deposit_l(0); - exp1 = norm_l(L_normq_v[sfm]); - L_tmp4 = L_shl(L_normq_v[sfm], exp1); /*14+exp1 */ - L_tmp1 = Mult_32_32(L_tmp4, L_tmp4); /*2*exp1-3 14+exp1+14+exp1 -31 */ - L_tmp2 = L_deposit_l(0); - peak_fx = L_deposit_l(0); - min_coef_fx = 0x7fffffff; - move32(); - - FOR(i = sfm_start[sfm]; i < sfm_end[sfm]; i++) - { - fabs_coeff_out_fx = L_abs(L_coeff_out[i]); - test(); - if (LT_32(fabs_coeff_out_fx, min_coef_fx) && L_coeff_out[i] != 0) - { - min_coef_fx = fabs_coeff_out_fx; - move32(); - } - if (GT_32(fabs_coeff_out_fx, peak_fx)) - { - peak_fx = fabs_coeff_out_fx; - move32(); - } - } - - exp2 = norm_l(peak_fx); - FOR(i = sfm_start[sfm]; i < sfm_end[sfm]; i++) - { - L_tmp4 = L_shl(L_coeff_out[i], exp2); /*12+exp2 */ - L_tmp3 = L_shr(Mult_32_32(L_tmp4, L_tmp4), 4);/*2*exp2-7-4 12+exp2+12+exp2-31-4 */ - L_tmp2 = L_add(L_tmp2, L_tmp3); /*2*exp2-11 */ - } - - tmp1 = div_s(1, sfmsize[sfm]); /*15 */ - L_tmp4 = Mult_32_16(L_tmp2, tmp1);/*2*exp2-11 2*exp2-7+15+1-16 */ - - exp = norm_l(L_tmp1); - L_tmp1 = L_shl(L_tmp1, exp);/*exp + 2*exp1 - 3 */ - exp1 = sub(add(exp, shl(exp1, 1)), 3); - - exp = norm_l(L_tmp4); - L_tmp4 = L_shl(L_tmp4, exp);/*exp + 2*exp1 - 3 */ - exp2 = sub(add(exp, shl(exp2, 1)), 11); - exp = s_min(exp1, exp2); - - L_tmp1 = L_shl(L_tmp1, sub(exp, exp1)); - L_tmp4 = L_shl(L_tmp4, sub(exp, exp2)); - env_fx = L_sub(L_tmp1, L_tmp4); /*exp */ - exp1 = norm_l(env_fx); - env_fx = L_shl(env_fx, exp1);/*exp + exp1 */ - exp = add(exp, exp1); - - IF(env_fx > 0) - { - IF(sfm == 0) - { - avrg_norm_fx = L_add(L_shr(L_normq_v[0], 1), L_shr(L_normq_v[1], 1));/*13 */ - avrg_norm_fx = L_add(avrg_norm_fx, L_shr(L_normq_v[2], 1));/*13 */ - prev_avrg_norm_fx = L_add(L_shr(prev_normq_fx[0], 1), L_shr(prev_normq_fx[1], 1));/*13 */ - prev_avrg_norm_fx = L_add(prev_avrg_norm_fx, L_shr(prev_normq_fx[2], 1));/*13 */ - } - ELSE IF(EQ_16(sfm, 25)) - { - avrg_norm_fx = L_add(L_shr(L_normq_v[23], 1), L_shr(L_normq_v[24], 1));/*13 */ - avrg_norm_fx = L_add(avrg_norm_fx, L_shr(L_normq_v[25], 1));/*13 */ - prev_avrg_norm_fx = L_add(L_shr(prev_normq_fx[23], 1), L_shr(prev_normq_fx[24], 1));/*13 */ - prev_avrg_norm_fx = L_add(prev_avrg_norm_fx, L_shr(prev_normq_fx[25], 1));/*13 */ - } - ELSE - { - avrg_norm_fx = L_add(L_shr(L_normq_v[sub(sfm,1)],1),L_shr(L_normq_v[sfm],1));/*13 */ - avrg_norm_fx = L_add(avrg_norm_fx,L_shr(L_normq_v[sfm + 1],1));/*13 */ - prev_avrg_norm_fx = L_add(L_shr(prev_normq_fx[sub(sfm,1)],1),L_shr(prev_normq_fx[sfm],1));/*13 */ - prev_avrg_norm_fx = L_add(prev_avrg_norm_fx,L_shr(prev_normq_fx[add(sfm,1)],1));/*13 */ - } - - test(); - test(); - IF((GT_16(bitalloc_var_fx, 4915) || LT_32(L_normq_v[sfm], peak_fx)) && peak_fx != 0) - { - Word16 exp_p; - exp_p = norm_l(peak_fx); - exp = sub(31, exp); - env_fx = Isqrt_lc(env_fx, &exp); - L_tmp1 = Mult_32_32(env_fx, L_shl(peak_fx, exp_p));/*12+exp2-exp 31-exp+12+exp1-31 */ - L_tmp2 = Mult_32_16(avrg_norm_fx, harm_para_fx);/*12 13 + 14 + 1 -16 */ - exp1 = norm_l(L_tmp1); - L_tmp1 = L_shl(L_tmp1, exp1);/* 12+exp2-exp+exp1 */ - exp = add(sub(12, exp), add(exp1, exp_p)); - L_tmp2 = Div_32(L_tmp2, extract_h(L_tmp1), extract_l(L_tmp1)); - exp = sub(43, exp); - } - ELSE - { - L_tmp1 = Mult_32_16(L_normq_v[sfm],alfa_fx);/*12 13 + 14 + 1 -16 */ - IF(LT_32(L_tmp1,peak_fx)) - { - exp = sub(31,exp); - env_fx = Isqrt_lc(env_fx,&exp); - exp1 = norm_l(env_fx); - env_fx = L_shl(env_fx,exp1);/* 31-exp+exp1 */ - exp = add(sub(31,exp),exp1); - L_tmp1 = (Word32)sharp_fx; - L_tmp2 = Div_32(L_tmp1, extract_h(env_fx), extract_l(env_fx)); /* 45-exp 14 - exp + 31 //39-exp 8 - exp + 31 */ - exp = sub(45,exp); - exp1 = norm_l(peak_fx); - L_tmp1 = L_shl(peak_fx,exp1); /*12 + exp1 */ - L_tmp1 = Div_32(L_tmp2,extract_h(L_tmp1), extract_l(L_tmp1)); /* exp - (12 + exp1) +31 */ - L_tmp2 = Mult_32_32(L_tmp2,L_tmp1);/*2*exp+exp1-12 exp +exp - (12 + exp1) +31 - 31 */ - exp = sub(add(shl(exp,1),exp1),12); - } - ELSE - { - exp = sub(31,exp); - env_fx = Isqrt_lc(env_fx,&exp); - exp1 = norm_l(env_fx); - env_fx = L_shl(env_fx,exp1);/* 31-exp+exp1 */ - exp = add(sub(31,exp),exp1); - L_tmp1 = (Word32)(sharp_fx); - L_tmp2 = Div_32(L_tmp1, extract_h(env_fx), extract_l(env_fx)); /* 45-exp 14 - exp + 31 //39-exp 8 - exp + 31 */ - exp = sub(45,exp); - } + alfa_fx = 20480; + move16(); /*Q13 = 2.5 */ + /* fill noise for the insaturable subbands */ + FOR( sfm = 0; sfm < num_sfm; sfm++ ) + { + env_fx = L_deposit_l( 0 ); + L_tmp2 = L_deposit_l( 0 ); + exp = 0; + move16(); + test(); + IF( R[sfm] != 0 && LT_16( R[sfm], shl( mult( 24756, sfmsize[sfm] ), 1 ) ) ) + { + /* calculate the energy of the undecoded coefficients */ + env_fx = L_deposit_l( 0 ); + exp1 = norm_l( L_normq_v[sfm] ); + L_tmp4 = L_shl( L_normq_v[sfm], exp1 ); /*14+exp1 */ + L_tmp1 = Mult_32_32( L_tmp4, L_tmp4 ); /*2*exp1-3 14+exp1+14+exp1 -31 */ + L_tmp2 = L_deposit_l( 0 ); + peak_fx = L_deposit_l( 0 ); + min_coef_fx = 0x7fffffff; + move32(); + + FOR( i = sfm_start[sfm]; i < sfm_end[sfm]; i++ ) + { + fabs_coeff_out_fx = L_abs( L_coeff_out[i] ); + test(); + if ( LT_32( fabs_coeff_out_fx, min_coef_fx ) && L_coeff_out[i] != 0 ) + { + min_coef_fx = fabs_coeff_out_fx; + move32(); + } + if ( GT_32( fabs_coeff_out_fx, peak_fx ) ) + { + peak_fx = fabs_coeff_out_fx; + move32(); + } + } + + exp2 = norm_l( peak_fx ); + FOR( i = sfm_start[sfm]; i < sfm_end[sfm]; i++ ) + { + L_tmp4 = L_shl( L_coeff_out[i], exp2 ); /*12+exp2 */ + L_tmp3 = L_shr( Mult_32_32( L_tmp4, L_tmp4 ), 4 ); /*2*exp2-7-4 12+exp2+12+exp2-31-4 */ + L_tmp2 = L_add( L_tmp2, L_tmp3 ); /*2*exp2-11 */ + } + + tmp1 = div_s( 1, sfmsize[sfm] ); /*15 */ + L_tmp4 = Mult_32_16( L_tmp2, tmp1 ); /*2*exp2-11 2*exp2-7+15+1-16 */ + + exp = norm_l( L_tmp1 ); + L_tmp1 = L_shl( L_tmp1, exp ); /*exp + 2*exp1 - 3 */ + exp1 = sub( add( exp, shl( exp1, 1 ) ), 3 ); + + exp = norm_l( L_tmp4 ); + L_tmp4 = L_shl( L_tmp4, exp ); /*exp + 2*exp1 - 3 */ + exp2 = sub( add( exp, shl( exp2, 1 ) ), 11 ); + exp = s_min( exp1, exp2 ); + + L_tmp1 = L_shl( L_tmp1, sub( exp, exp1 ) ); + L_tmp4 = L_shl( L_tmp4, sub( exp, exp2 ) ); + env_fx = L_sub( L_tmp1, L_tmp4 ); /*exp */ + exp1 = norm_l( env_fx ); + env_fx = L_shl( env_fx, exp1 ); /*exp + exp1 */ + exp = add( exp, exp1 ); + + IF( env_fx > 0 ) + { + IF( sfm == 0 ) + { + avrg_norm_fx = L_add( L_shr( L_normq_v[0], 1 ), L_shr( L_normq_v[1], 1 ) ); /*13 */ + avrg_norm_fx = L_add( avrg_norm_fx, L_shr( L_normq_v[2], 1 ) ); /*13 */ + prev_avrg_norm_fx = L_add( L_shr( prev_normq_fx[0], 1 ), L_shr( prev_normq_fx[1], 1 ) ); /*13 */ + prev_avrg_norm_fx = L_add( prev_avrg_norm_fx, L_shr( prev_normq_fx[2], 1 ) ); /*13 */ + } + ELSE IF( EQ_16( sfm, 25 ) ) + { + avrg_norm_fx = L_add( L_shr( L_normq_v[23], 1 ), L_shr( L_normq_v[24], 1 ) ); /*13 */ + avrg_norm_fx = L_add( avrg_norm_fx, L_shr( L_normq_v[25], 1 ) ); /*13 */ + prev_avrg_norm_fx = L_add( L_shr( prev_normq_fx[23], 1 ), L_shr( prev_normq_fx[24], 1 ) ); /*13 */ + prev_avrg_norm_fx = L_add( prev_avrg_norm_fx, L_shr( prev_normq_fx[25], 1 ) ); /*13 */ + } + ELSE + { + avrg_norm_fx = L_add( L_shr( L_normq_v[sub( sfm, 1 )], 1 ), L_shr( L_normq_v[sfm], 1 ) ); /*13 */ + avrg_norm_fx = L_add( avrg_norm_fx, L_shr( L_normq_v[sfm + 1], 1 ) ); /*13 */ + prev_avrg_norm_fx = L_add( L_shr( prev_normq_fx[sub( sfm, 1 )], 1 ), L_shr( prev_normq_fx[sfm], 1 ) ); /*13 */ + prev_avrg_norm_fx = L_add( prev_avrg_norm_fx, L_shr( prev_normq_fx[add( sfm, 1 )], 1 ) ); /*13 */ + } + + test(); + test(); + IF( ( GT_16( bitalloc_var_fx, 4915 ) || LT_32( L_normq_v[sfm], peak_fx ) ) && peak_fx != 0 ) + { + Word16 exp_p; + exp_p = norm_l( peak_fx ); + exp = sub( 31, exp ); + env_fx = Isqrt_lc( env_fx, &exp ); + L_tmp1 = Mult_32_32( env_fx, L_shl( peak_fx, exp_p ) ); /*12+exp2-exp 31-exp+12+exp1-31 */ + L_tmp2 = Mult_32_16( avrg_norm_fx, harm_para_fx ); /*12 13 + 14 + 1 -16 */ + exp1 = norm_l( L_tmp1 ); + L_tmp1 = L_shl( L_tmp1, exp1 ); /* 12+exp2-exp+exp1 */ + exp = add( sub( 12, exp ), add( exp1, exp_p ) ); + L_tmp2 = Div_32( L_tmp2, extract_h( L_tmp1 ), extract_l( L_tmp1 ) ); + exp = sub( 43, exp ); + } + ELSE + { + L_tmp1 = Mult_32_16( L_normq_v[sfm], alfa_fx ); /*12 13 + 14 + 1 -16 */ + IF( LT_32( L_tmp1, peak_fx ) ) + { + exp = sub( 31, exp ); + env_fx = Isqrt_lc( env_fx, &exp ); + exp1 = norm_l( env_fx ); + env_fx = L_shl( env_fx, exp1 ); /* 31-exp+exp1 */ + exp = add( sub( 31, exp ), exp1 ); + L_tmp1 = (Word32) sharp_fx; + L_tmp2 = Div_32( L_tmp1, extract_h( env_fx ), extract_l( env_fx ) ); /* 45-exp 14 - exp + 31 //39-exp 8 - exp + 31 */ + exp = sub( 45, exp ); + exp1 = norm_l( peak_fx ); + L_tmp1 = L_shl( peak_fx, exp1 ); /*12 + exp1 */ + L_tmp1 = Div_32( L_tmp2, extract_h( L_tmp1 ), extract_l( L_tmp1 ) ); /* exp - (12 + exp1) +31 */ + L_tmp2 = Mult_32_32( L_tmp2, L_tmp1 ); /*2*exp+exp1-12 exp +exp - (12 + exp1) +31 - 31 */ + exp = sub( add( shl( exp, 1 ), exp1 ), 12 ); + } + ELSE + { + exp = sub( 31, exp ); + env_fx = Isqrt_lc( env_fx, &exp ); + exp1 = norm_l( env_fx ); + env_fx = L_shl( env_fx, exp1 ); /* 31-exp+exp1 */ + exp = add( sub( 31, exp ), exp1 ); + L_tmp1 = (Word32) ( sharp_fx ); + L_tmp2 = Div_32( L_tmp1, extract_h( env_fx ), extract_l( env_fx ) ); /* 45-exp 14 - exp + 31 //39-exp 8 - exp + 31 */ + exp = sub( 45, exp ); + } #ifdef BASOP_NOGLOB - sharp_fx = add_sat(sharp_fx,shr(step_fx,1)); + sharp_fx = add_sat( sharp_fx, shr( step_fx, 1 ) ); #else - sharp_fx = add(sharp_fx,shr(step_fx,1)); + sharp_fx = add( sharp_fx, shr( step_fx, 1 ) ); #endif - } + } #ifdef BASOP_NOGLOB IF( GT_32( L_tmp2, L_shl_sat( min_coef_fx, sub( exp, 13 ) ) ) ) /*exp */ #else - IF(GT_32(L_tmp2, L_shl(min_coef_fx, sub(exp, 13))))/*exp */ + IF( GT_32( L_tmp2, L_shl( min_coef_fx, sub( exp, 13 ) ) ) ) /*exp */ #endif - { - L_tmp2 = L_shr(min_coef_fx, 1); - exp = 12; - move16(); - } - - IF(EQ_16(prev_bfi, 1)) - { - prev_env_Q[sfm] = exp; - move16(); - prev_env_fx[sfm] = L_tmp2; - move32(); - } - /* smooth the noise magnitudes between inter-frame */ - test(); - test(); + { + L_tmp2 = L_shr( min_coef_fx, 1 ); + exp = 12; + move16(); + } + + IF( EQ_16( prev_bfi, 1 ) ) + { + prev_env_Q[sfm] = exp; + move16(); + prev_env_fx[sfm] = L_tmp2; + move32(); + } + /* smooth the noise magnitudes between inter-frame */ + test(); + test(); #ifdef BASOP_NOGLOB IF( GT_32( prev_avrg_norm_fx, L_shr( avrg_norm_fx, 1 ) ) && LT_32( prev_avrg_norm_fx, L_shl_sat( avrg_norm_fx, 1 ) ) && prev_is_transient == 0 ) #else - IF(GT_32(prev_avrg_norm_fx, L_shr(avrg_norm_fx, 1)) && LT_32(prev_avrg_norm_fx, L_shl(avrg_norm_fx, 1)) && prev_is_transient == 0) + IF( GT_32( prev_avrg_norm_fx, L_shr( avrg_norm_fx, 1 ) ) && LT_32( prev_avrg_norm_fx, L_shl( avrg_norm_fx, 1 ) ) && prev_is_transient == 0 ) #endif - { - exp1 = norm_l(prev_env_fx[sfm]); - L_tmp1 = L_shl(prev_env_fx[sfm], exp1);/* prev_env_Q[sfm] +exp1 */ - - exp2 = norm_l(L_tmp2); - L_tmp3 = L_shl(L_tmp2, exp2);/* exp +exp2 */ - exp3 = s_min(add(prev_env_Q[sfm], exp1), add(exp, exp2)); - - L_tmp1 = L_shl(L_tmp1, sub(sub(exp3, prev_env_Q[sfm]), exp1)); /*exp3 */ - L_tmp3 = L_shl(L_tmp3, sub(sub(exp3, exp), exp2)); /*exp3 */ - L_tmp2 = L_add(L_shr(L_tmp1, 1), L_shr(L_tmp3, 1));/*exp3 */ - exp = exp3; - move16(); - } - FOR(i = sfm_start[sfm]; i < sfm_end[sfm]; i++) - { - IF(coeff_fx[i] == 0) - { - tmp1 = Random(bwe_seed);/*Q15 */ - L_tmp1 = Mult_32_16(L_tmp2, tmp1);/*exp exp+15+1 -16 */ - L_tmp1 = L_shl(L_tmp1, sub(12, exp)); - L_coeff_out[i] = L_tmp1; - move32(); - } - } - } - ELSE - { - exp = 0; - move16(); - L_tmp2 = L_deposit_l(0); - } - } - ELSE IF(R[sfm] == 0) - { - /* fill random noise for 0 bit subbands */ - FOR(i = sfm_start[sfm]; i < sfm_end[sfm]; i++) - { - IF(coeff_fx[i] == 0) - { - tmp1 = Random(bwe_seed);/*Q15 */ - L_tmp1 = Mult_32_16(L_normq_v[sfm], tmp1);/*14 14+15+1 -16 */ - L_tmp1 = L_shr(L_tmp1, 2);/* */ - L_coeff_out[i] = L_tmp1; - move32(); - } - } - L_tmp2 = L_normq_v[sfm]; - move32(); - exp = 14; - move16(); - } - - test(); - test(); - test(); - test(); + { + exp1 = norm_l( prev_env_fx[sfm] ); + L_tmp1 = L_shl( prev_env_fx[sfm], exp1 ); /* prev_env_Q[sfm] +exp1 */ + + exp2 = norm_l( L_tmp2 ); + L_tmp3 = L_shl( L_tmp2, exp2 ); /* exp +exp2 */ + exp3 = s_min( add( prev_env_Q[sfm], exp1 ), add( exp, exp2 ) ); + + L_tmp1 = L_shl( L_tmp1, sub( sub( exp3, prev_env_Q[sfm] ), exp1 ) ); /*exp3 */ + L_tmp3 = L_shl( L_tmp3, sub( sub( exp3, exp ), exp2 ) ); /*exp3 */ + L_tmp2 = L_add( L_shr( L_tmp1, 1 ), L_shr( L_tmp3, 1 ) ); /*exp3 */ + exp = exp3; + move16(); + } + FOR( i = sfm_start[sfm]; i < sfm_end[sfm]; i++ ) + { + IF( coeff_fx[i] == 0 ) + { + tmp1 = Random( bwe_seed ); /*Q15 */ + L_tmp1 = Mult_32_16( L_tmp2, tmp1 ); /*exp exp+15+1 -16 */ + L_tmp1 = L_shl( L_tmp1, sub( 12, exp ) ); + L_coeff_out[i] = L_tmp1; + move32(); + } + } + } + ELSE + { + exp = 0; + move16(); + L_tmp2 = L_deposit_l( 0 ); + } + } + ELSE IF( R[sfm] == 0 ) + { + /* fill random noise for 0 bit subbands */ + FOR( i = sfm_start[sfm]; i < sfm_end[sfm]; i++ ) + { + IF( coeff_fx[i] == 0 ) + { + tmp1 = Random( bwe_seed ); /*Q15 */ + L_tmp1 = Mult_32_16( L_normq_v[sfm], tmp1 ); /*14 14+15+1 -16 */ + L_tmp1 = L_shr( L_tmp1, 2 ); /* */ + L_coeff_out[i] = L_tmp1; + move32(); + } + } + L_tmp2 = L_normq_v[sfm]; + move32(); + exp = 14; + move16(); + } + + test(); + test(); + test(); + test(); #ifdef BASOP_NOGLOB - IF( EQ_16( sfm, sub( SFM_N_WB, 1 ) ) && prev_is_transient == 0 && GT_32( prev_normq_fx[sfm], L_shr( L_normq_v[sfm], 1 ) ) - && LT_32(prev_normq_fx[sfm], L_shl_sat(L_normq_v[sfm], 1)) && LE_16(bitalloc_var_fx, 4915)) + IF( EQ_16( sfm, sub( SFM_N_WB, 1 ) ) && prev_is_transient == 0 && GT_32( prev_normq_fx[sfm], L_shr( L_normq_v[sfm], 1 ) ) && LT_32( prev_normq_fx[sfm], L_shl_sat( L_normq_v[sfm], 1 ) ) && LE_16( bitalloc_var_fx, 4915 ) ) #else - IF(EQ_16(sfm, sub(SFM_N_WB, 1)) && prev_is_transient == 0 && GT_32(prev_normq_fx[sfm], L_shr(L_normq_v[sfm], 1)) - && LT_32(prev_normq_fx[sfm], L_shl(L_normq_v[sfm], 1)) && LE_16(bitalloc_var_fx, 4915)) + IF( EQ_16( sfm, sub( SFM_N_WB, 1 ) ) && prev_is_transient == 0 && GT_32( prev_normq_fx[sfm], L_shr( L_normq_v[sfm], 1 ) ) && LT_32( prev_normq_fx[sfm], L_shl( L_normq_v[sfm], 1 ) ) && LE_16( bitalloc_var_fx, 4915 ) ) #endif - { - Word32 *p_prev_coeff_out = prev_coeff_out_fx; - FOR(i = add(sfm_start[sfm], 12); i < sfm_end[sfm]; i++) - { - test(); - test(); - test(); - test(); + { + Word32 *p_prev_coeff_out = prev_coeff_out_fx; + FOR( i = add( sfm_start[sfm], 12 ); i < sfm_end[sfm]; i++ ) + { + test(); + test(); + test(); + test(); #ifdef BASOP_NOGLOB - IF( GT_32( L_abs( L_coeff_out[i] ), L_shl_sat( L_abs( *p_prev_coeff_out ), 2 ) ) - || LT_32(L_abs(L_coeff_out[i]), L_shr(L_abs(*p_prev_coeff_out), 2)) - || ((R[sfm] == 0 || *prev_R == 0) && add_sat(R[sfm], *prev_R) != 0)) + IF( GT_32( L_abs( L_coeff_out[i] ), L_shl_sat( L_abs( *p_prev_coeff_out ), 2 ) ) || LT_32( L_abs( L_coeff_out[i] ), L_shr( L_abs( *p_prev_coeff_out ), 2 ) ) || ( ( R[sfm] == 0 || *prev_R == 0 ) && add_sat( R[sfm], *prev_R ) != 0 ) ) #else - IF(GT_32(L_abs(L_coeff_out[i]), L_shl(L_abs(*p_prev_coeff_out), 2)) - || LT_32(L_abs(L_coeff_out[i]), L_shr(L_abs(*p_prev_coeff_out), 2)) - || ((R[sfm] == 0 || *prev_R == 0) && add(R[sfm], *prev_R) != 0)) + IF( GT_32( L_abs( L_coeff_out[i] ), L_shl( L_abs( *p_prev_coeff_out ), 2 ) ) || LT_32( L_abs( L_coeff_out[i] ), L_shr( L_abs( *p_prev_coeff_out ), 2 ) ) || ( ( R[sfm] == 0 || *prev_R == 0 ) && add( R[sfm], *prev_R ) != 0 ) ) #endif - { + { #ifdef BASOP_NOGLOB - L_tmp = L_add_sat( L_shr( L_abs( L_coeff_out[i] ), 1 ), L_shr( L_abs( *p_prev_coeff_out ), 1 ) ); + L_tmp = L_add_sat( L_shr( L_abs( L_coeff_out[i] ), 1 ), L_shr( L_abs( *p_prev_coeff_out ), 1 ) ); #else - L_tmp = L_add(L_shr(L_abs(L_coeff_out[i]), 1), L_shr(L_abs(*p_prev_coeff_out), 1)); + L_tmp = L_add( L_shr( L_abs( L_coeff_out[i] ), 1 ), L_shr( L_abs( *p_prev_coeff_out ), 1 ) ); #endif - if (L_coeff_out[i] <= 0) - { - L_tmp = L_negate(L_tmp); - } - L_coeff_out[i] = L_tmp; - move32(); - } - p_prev_coeff_out++; - } - } - prev_env_Q[sfm] = exp; - move16(); - prev_env_fx[sfm] = L_tmp2; - move32(); - } - } - ELSE - { - /* fill random noise for 0 bit subbands of transient frame */ - FOR(sfm = 0; sfm < num_sfm; sfm++) - { - IF(R[sfm] == 0) - { - FOR(i = sfm_start[sfm]; i < sfm_end[sfm]; i++) - { - tmp1 = Random(bwe_seed);/*Q15 */ - L_tmp1 = Mult_32_16(L_normq_v[sfm],tmp1);/*14 14+15+1 -16 */ - L_tmp1 = L_shr(L_tmp1,2);/* */ - L_coeff_out[i] = L_tmp1; - move32(); - } - } - } - set16_fx(prev_env_Q, 0, SFM_N_WB); - set32_fx(prev_env_fx, 0, SFM_N_WB); - } - - Copy32(L_normq_v, prev_normq_fx, SFM_N_WB); - Copy32(L_coeff_out + L_FRAME16k - L_HQ_WB_BWE, prev_coeff_out_fx, L_HQ_WB_BWE); - *prev_R = R[SFM_N_WB - 1]; - - return; + if ( L_coeff_out[i] <= 0 ) + { + L_tmp = L_negate( L_tmp ); + } + L_coeff_out[i] = L_tmp; + move32(); + } + p_prev_coeff_out++; + } + } + prev_env_Q[sfm] = exp; + move16(); + prev_env_fx[sfm] = L_tmp2; + move32(); + } + } + ELSE + { + /* fill random noise for 0 bit subbands of transient frame */ + FOR( sfm = 0; sfm < num_sfm; sfm++ ) + { + IF( R[sfm] == 0 ) + { + FOR( i = sfm_start[sfm]; i < sfm_end[sfm]; i++ ) + { + tmp1 = Random( bwe_seed ); /*Q15 */ + L_tmp1 = Mult_32_16( L_normq_v[sfm], tmp1 ); /*14 14+15+1 -16 */ + L_tmp1 = L_shr( L_tmp1, 2 ); /* */ + L_coeff_out[i] = L_tmp1; + move32(); + } + } + } + set16_fx( prev_env_Q, 0, SFM_N_WB ); + set32_fx( prev_env_fx, 0, SFM_N_WB ); + } + + Copy32( L_normq_v, prev_normq_fx, SFM_N_WB ); + Copy32( L_coeff_out + L_FRAME16k - L_HQ_WB_BWE, prev_coeff_out_fx, L_HQ_WB_BWE ); + *prev_R = R[SFM_N_WB - 1]; + + return; } /*--------------------------------------------------------------------------* @@ -2512,40 +2502,40 @@ void hq_wb_nf_bwe_fx( *--------------------------------------------------------------------------*/ void enforce_zero_for_min_envelope_fx( - const Word16 hqswb_clas, /* i : HQ coding mode Q0 */ - const Word16 *ynrm, /* i : Envelope indices Q0 */ - Word32 *L_coefsq, /* i/o: Quantized spectrum/zeroed spectrum Q12 */ - const Word16 nb_sfm, /* i : Number of coded sub bands Q0 */ - const Word16 *sfm_start, /* i : Sub band start indices Q0 */ - const Word16 *sfm_end /* i : Sub band end indices Q0 */ + const Word16 hqswb_clas, /* i : HQ coding mode Q0 */ + const Word16 *ynrm, /* i : Envelope indices Q0 */ + Word32 *L_coefsq, /* i/o: Quantized spectrum/zeroed spectrum Q12 */ + const Word16 nb_sfm, /* i : Number of coded sub bands Q0 */ + const Word16 *sfm_start, /* i : Sub band start indices Q0 */ + const Word16 *sfm_end /* i : Sub band end indices Q0 */ ) { - Word16 i, j; - - /* prevent non-zero output for all-zero input */ - IF(NE_16(hqswb_clas, HQ_HVQ)) - { - IF(EQ_16(ynrm[0], 31)) - { - FOR(j = sfm_start[0]; j < sfm_end[0]; j++) - { - L_coefsq[j] = L_deposit_l(0); - } - } - - FOR(i = 1; i < nb_sfm; i++) - { - IF(EQ_16(ynrm[i], 39)) - { - FOR(j = sfm_start[i]; j < sfm_end[i]; j++) - { - L_coefsq[j] = L_deposit_l(0); - } - } - } - } - - return; + Word16 i, j; + + /* prevent non-zero output for all-zero input */ + IF( NE_16( hqswb_clas, HQ_HVQ ) ) + { + IF( EQ_16( ynrm[0], 31 ) ) + { + FOR( j = sfm_start[0]; j < sfm_end[0]; j++ ) + { + L_coefsq[j] = L_deposit_l( 0 ); + } + } + + FOR( i = 1; i < nb_sfm; i++ ) + { + IF( EQ_16( ynrm[i], 39 ) ) + { + FOR( j = sfm_start[i]; j < sfm_end[i]; j++ ) + { + L_coefsq[j] = L_deposit_l( 0 ); + } + } + } + } + + return; } /*--------------------------------------------------------------------------* @@ -2555,97 +2545,95 @@ void enforce_zero_for_min_envelope_fx( *--------------------------------------------------------------------------*/ void apply_envelope_fx( - const Word16 *coeff, /* i/o: Coded/noisefilled normalized spectrum Q12 */ - const Word16 *norm, /* i : Envelope Q0 */ - const Word16 *norm_adj, /* i : Envelope adjustment Q15 */ - const Word16 num_sfm, /* i : Total number of bands Q0 */ - const Word16 last_sfm, /* i : Last coded band Q0 */ - const Word16 HQ_mode, /* i : HQ mode Q0 */ - const Word16 length, /* i : Frame length Q0 */ - const Word16 *sfm_start, /* i : Sub band start indices Q0 */ - const Word16 *sfm_end, /* i : Sub band end indices Q0 */ - Word32 *normq_v, /* o : Envelope with adjustment Q14 */ - Word32 *coeff_out, /* o : coded/noisefilled spectrum Q12 */ - const Word16 *coeff1, /* i : coded/noisefilled spectrum Q12 */ - Word32 *coeff_out1 /* o : coded/noisefilled spectrum Q12 */ + const Word16 *coeff, /* i/o: Coded/noisefilled normalized spectrum Q12 */ + const Word16 *norm, /* i : Envelope Q0 */ + const Word16 *norm_adj, /* i : Envelope adjustment Q15 */ + const Word16 num_sfm, /* i : Total number of bands Q0 */ + const Word16 last_sfm, /* i : Last coded band Q0 */ + const Word16 HQ_mode, /* i : HQ mode Q0 */ + const Word16 length, /* i : Frame length Q0 */ + const Word16 *sfm_start, /* i : Sub band start indices Q0 */ + const Word16 *sfm_end, /* i : Sub band end indices Q0 */ + Word32 *normq_v, /* o : Envelope with adjustment Q14 */ + Word32 *coeff_out, /* o : coded/noisefilled spectrum Q12 */ + const Word16 *coeff1, /* i : coded/noisefilled spectrum Q12 */ + Word32 *coeff_out1 /* o : coded/noisefilled spectrum Q12 */ ) { - Word16 i; - Word16 sfm; - UWord16 lsb; - Word32 normq; - Word32 L_tmp; - Word16 len; - - len = num_sfm; - move16(); - test(); - if (EQ_16(HQ_mode, HQ_GEN_SWB) || EQ_16(HQ_mode, HQ_GEN_FB)) - { - len = add(last_sfm, 1); - } - - IF(EQ_16(length, L_FRAME16k)) - { - FOR(sfm = 0; sfm < num_sfm; sfm++) - { - normq_v[sfm] = dicn_fx[norm[sfm]]; - move16(); - move32(); - /*normq = normq_v[sfm] * norm_adj[sfm]; */ - Mpy_32_16_ss(normq_v[sfm], norm_adj[sfm], &normq, &lsb); /* Q14 (14+15+1-16) */ - - FOR(i = sfm_start[sfm]; i < sfm_end[sfm]; i++) - { - /*coeff_out[i] = coeff[i]*normq; */ - Mpy_32_16_ss(normq, coeff[i], &L_tmp, &lsb); - coeff_out[i] = L_add(L_shl(L_tmp, 1), lshr(lsb, 15)); - move32(); /* Q12 (14+12+1-16)+1 */ - } - } - } - ELSE - { - FOR(sfm = 0; sfm < len; sfm++) - { - normq_v[sfm] = dicn_fx[norm[sfm]]; - move16(); - move32(); - /*normq_v[sfm] *= norm_adj[sfm]; */ - Mpy_32_16_ss(normq_v[sfm], norm_adj[sfm], &normq_v[sfm], &lsb); - move32(); /* Q14 (14+15+1-16) */ - - normq = normq_v[sfm]; - move32(); - FOR(i = sfm_start[sfm]; i < sfm_end[sfm]; i++) - { - /*coeff_out[i] = coeff[i]*normq; */ - Mpy_32_16_ss(normq, coeff[i], &L_tmp, &lsb); - coeff_out[i] = L_add(L_shl(L_tmp, 1), lshr(lsb, 15)); - move32(); /* Q12 (14+12+1-16)+1 */ - } - } - - test(); - IF(EQ_16(HQ_mode, HQ_GEN_SWB) || EQ_16(HQ_mode,HQ_GEN_FB)) - { - FOR(sfm = 0; sfm <= last_sfm; sfm++) - { - normq = normq_v[sfm]; - move32(); - FOR(i = sfm_start[sfm]; i < sfm_end[sfm]; i++) - { - /*coeff_out1[i] = coeff_out1[i]*normq; */ - Mpy_32_16_ss(normq, coeff1[i], &L_tmp, &lsb); - coeff_out1[i] = L_add(L_shl(L_tmp, 1), lshr(lsb, 15)); - move32(); /* Q12 (14+12+1-16)+1 */ - } - } - } - } - - - return; -} + Word16 i; + Word16 sfm; + UWord16 lsb; + Word32 normq; + Word32 L_tmp; + Word16 len; + + len = num_sfm; + move16(); + test(); + if ( EQ_16( HQ_mode, HQ_GEN_SWB ) || EQ_16( HQ_mode, HQ_GEN_FB ) ) + { + len = add( last_sfm, 1 ); + } + + IF( EQ_16( length, L_FRAME16k ) ) + { + FOR( sfm = 0; sfm < num_sfm; sfm++ ) + { + normq_v[sfm] = dicn_fx[norm[sfm]]; + move16(); + move32(); + /*normq = normq_v[sfm] * norm_adj[sfm]; */ + Mpy_32_16_ss( normq_v[sfm], norm_adj[sfm], &normq, &lsb ); /* Q14 (14+15+1-16) */ + + FOR( i = sfm_start[sfm]; i < sfm_end[sfm]; i++ ) + { + /*coeff_out[i] = coeff[i]*normq; */ + Mpy_32_16_ss( normq, coeff[i], &L_tmp, &lsb ); + coeff_out[i] = L_add( L_shl( L_tmp, 1 ), lshr( lsb, 15 ) ); + move32(); /* Q12 (14+12+1-16)+1 */ + } + } + } + ELSE + { + FOR( sfm = 0; sfm < len; sfm++ ) + { + normq_v[sfm] = dicn_fx[norm[sfm]]; + move16(); + move32(); + /*normq_v[sfm] *= norm_adj[sfm]; */ + Mpy_32_16_ss( normq_v[sfm], norm_adj[sfm], &normq_v[sfm], &lsb ); + move32(); /* Q14 (14+15+1-16) */ + + normq = normq_v[sfm]; + move32(); + FOR( i = sfm_start[sfm]; i < sfm_end[sfm]; i++ ) + { + /*coeff_out[i] = coeff[i]*normq; */ + Mpy_32_16_ss( normq, coeff[i], &L_tmp, &lsb ); + coeff_out[i] = L_add( L_shl( L_tmp, 1 ), lshr( lsb, 15 ) ); + move32(); /* Q12 (14+12+1-16)+1 */ + } + } + + test(); + IF( EQ_16( HQ_mode, HQ_GEN_SWB ) || EQ_16( HQ_mode, HQ_GEN_FB ) ) + { + FOR( sfm = 0; sfm <= last_sfm; sfm++ ) + { + normq = normq_v[sfm]; + move32(); + FOR( i = sfm_start[sfm]; i < sfm_end[sfm]; i++ ) + { + /*coeff_out1[i] = coeff_out1[i]*normq; */ + Mpy_32_16_ss( normq, coeff1[i], &L_tmp, &lsb ); + coeff_out1[i] = L_add( L_shl( L_tmp, 1 ), lshr( lsb, 15 ) ); + move32(); /* Q12 (14+12+1-16)+1 */ + } + } + } + } + return; +} diff --git a/lib_com/hvq_pvq_bitalloc_fx.c b/lib_com/hvq_pvq_bitalloc_fx.c index 47cd6eba2..43e014ce9 100644 --- a/lib_com/hvq_pvq_bitalloc_fx.c +++ b/lib_com/hvq_pvq_bitalloc_fx.c @@ -2,12 +2,12 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ +#include "options.h" /* Compilation switches */ #include "rom_com.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "cnst.h" /* Common constants */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "cnst.h" /* Common constants */ /*--------------------------------------------------------------------------*/ /* Function hvq_pvq_bitalloc */ @@ -18,16 +18,16 @@ /*--------------------------------------------------------------------------*/ Word16 hvq_pvq_bitalloc_fx( - Word16 num_bits, /* i/o: Number of available bits (including gain bits) */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 bwidth_fx, /* i : Encoded bandwidth */ - const Word16 *ynrm, /* i : Envelope coefficients */ - const Word32 manE_peak, /* i : Peak energy mantissa */ - const Word16 expE_peak, /* i : Peak energy exponent */ - Word16 *Rk, /* o : bit allocation for concatenated vector */ - Word16 *R, /* i/o: Global bit allocation */ - Word16 *sel_bands, /* o : Selected bands for encoding */ - Word16 *n_sel_bands /* o : No. of selected bands for encoding */ + Word16 num_bits, /* i/o: Number of available bits (including gain bits) */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 bwidth_fx, /* i : Encoded bandwidth */ + const Word16 *ynrm, /* i : Envelope coefficients */ + const Word32 manE_peak, /* i : Peak energy mantissa */ + const Word16 expE_peak, /* i : Peak energy exponent */ + Word16 *Rk, /* o : bit allocation for concatenated vector */ + Word16 *R, /* i/o: Global bit allocation */ + Word16 *sel_bands, /* o : Selected bands for encoding */ + Word16 *n_sel_bands /* o : No. of selected bands for encoding */ ) { Word16 num_bands, band_max_bits; @@ -42,7 +42,7 @@ Word16 hvq_pvq_bitalloc_fx( UWord16 lsb; Word16 num_sfm; - IF (EQ_16(bwidth_fx, FB)) + IF( EQ_16( bwidth_fx, FB ) ) { num_sfm = SFM_N_HARM_FB; } @@ -51,7 +51,7 @@ Word16 hvq_pvq_bitalloc_fx( num_sfm = SFM_N_HARM; } - IF ( LT_32(core_brate, HQ_BWE_CROSSOVER_BRATE)) + IF( LT_32( core_brate, HQ_BWE_CROSSOVER_BRATE ) ) { band_max_bits = HVQ_BAND_MAX_BITS_24k; move16(); @@ -59,13 +59,15 @@ Word16 hvq_pvq_bitalloc_fx( move16(); k_start = HVQ_THRES_SFM_24k; move16(); - IF (EQ_16(bwidth_fx, FB)) + IF( EQ_16( bwidth_fx, FB ) ) { - reciprocal = 2731; /* Q15, 1/(SFM_N_HARM_FB + 1 - k_start) */ move16(); + reciprocal = 2731; /* Q15, 1/(SFM_N_HARM_FB + 1 - k_start) */ + move16(); } ELSE { - reciprocal = 3277; /* Q15, 1/(SFM_N_HARM + 1 - k_start) */ move16(); + reciprocal = 3277; /* Q15, 1/(SFM_N_HARM + 1 - k_start) */ + move16(); } } ELSE @@ -76,30 +78,32 @@ Word16 hvq_pvq_bitalloc_fx( move16(); k_start = HVQ_THRES_SFM_32k; move16(); - IF (EQ_16(bwidth_fx, FB)) + IF( EQ_16( bwidth_fx, FB ) ) { - reciprocal = 3641; /* Q15, 1/(SFM_N_HARM_FB + 1 - k_start) */ move16(); + reciprocal = 3641; /* Q15, 1/(SFM_N_HARM_FB + 1 - k_start) */ + move16(); } ELSE { - reciprocal = 4681; /* Q15, 1/(SFM_N_HARM + 1 - k_start) */ move16(); + reciprocal = 4681; /* Q15, 1/(SFM_N_HARM + 1 - k_start) */ + move16(); } } - num_bands = mult( num_bits, one_over_band_max_bits ); /* Q0 */ - num_bits = sub( num_bits, i_mult(num_bands, band_max_bits) ); /* Q0 */ + num_bands = mult( num_bits, one_over_band_max_bits ); /* Q0 */ + num_bits = sub( num_bits, i_mult( num_bands, band_max_bits ) ); /* Q0 */ - IF ( GE_16(num_bits, HVQ_NEW_BAND_BIT_THR)) + IF( GE_16( num_bits, HVQ_NEW_BAND_BIT_THR ) ) { - num_bands = add(num_bands, 1); + num_bands = add( num_bands, 1 ); } ELSE { - num_bits = add(num_bits, band_max_bits); + num_bits = add( num_bits, band_max_bits ); } /* safety check in case of bit errors */ - if (LT_16(num_bands, 1)) + if ( LT_16( num_bands, 1 ) ) { return 0; } @@ -108,30 +112,30 @@ Word16 hvq_pvq_bitalloc_fx( move16(); envSum = 0; move16(); - E_max = L_deposit_l(0); + E_max = L_deposit_l( 0 ); k_max = k_start; move16(); - FOR ( k = k_start; k < num_sfm; k++ ) + FOR( k = k_start; k < num_sfm; k++ ) { indx = ynrm[k]; move16(); - tmp = dicn_fx[indx]; /* Q14 */ - move32(); - envSum = add(envSum, indx); /* Since the size of dicn_fx = 40, ynrm[k] must be less than 41. 16 bits are enough for envSum.*/ - IF (GT_32(tmp, E_max)) + tmp = dicn_fx[indx]; /* Q14 */ + move32(); + envSum = add( envSum, indx ); /* Since the size of dicn_fx = 40, ynrm[k] must be less than 41. 16 bits are enough for envSum.*/ + IF( GT_32( tmp, E_max ) ) { E_max = tmp; - move32(); + move32(); k_max = k; move16(); } } - env_mean = L_mult(envSum, reciprocal); /* env_mean in Q16 */ - IF (GT_32(L_sub(env_mean, L_deposit_h(ynrm[k_max])), 0x30000L)) /* condition: env_mean - ynrm[k_max] > 3 */ + env_mean = L_mult( envSum, reciprocal ); /* env_mean in Q16 */ + IF( GT_32( L_sub( env_mean, L_deposit_h( ynrm[k_max] ) ), 0x30000L ) ) /* condition: env_mean - ynrm[k_max] > 3 */ { - expo = norm_l(E_max); - E_max = L_shl(E_max, expo); - Mpy_32_16_ss(E_max, 0x7a12, &E_max5, &lsb); /* NB: 5.0e5 = 0x7a12(Q15) x 2^19. */ + expo = norm_l( E_max ); + E_max = L_shl( E_max, expo ); + Mpy_32_16_ss( E_max, 0x7a12, &E_max5, &lsb ); /* NB: 5.0e5 = 0x7a12(Q15) x 2^19. */ /* True floating point value of E_max*5e5 = E_max5 x 2^(19 - expo - 14). * In this context, the 32-bit E_max5 is in Q0, and * -14 is due to Emax in Q14. @@ -139,52 +143,52 @@ Word16 hvq_pvq_bitalloc_fx( */ /* Align the Q-points of the floating point Emax*5e5 and E_peak. */ - align = sub(expo, expE_peak); - align = add(align, (19 - 14) - (31 - 2*12)); - IF (align < 0) + align = sub( expo, expE_peak ); + align = add( align, ( 19 - 14 ) - ( 31 - 2 * 12 ) ); + IF( align < 0 ) { - acc = L_sub(E_max5, L_shl(manE_peak, align)); + acc = L_sub( E_max5, L_shl( manE_peak, align ) ); } ELSE { - acc = L_sub(L_shr(E_max5, align), manE_peak); + acc = L_sub( L_shr( E_max5, align ), manE_peak ); } - IF (acc > 0) /* condition: E_max*5.e5 > E_peak */ + IF( acc > 0 ) /* condition: E_max*5.e5 > E_peak */ { - IF ( EQ_16(band_len_harm[k_max], 96)) + IF( EQ_16( band_len_harm[k_max], 96 ) ) { n = 61; } ELSE { - QuantaPerDsDirac_fx(band_len_harm[k_max], 1, hBitsN, &n); + QuantaPerDsDirac_fx( band_len_harm[k_max], 1, hBitsN, &n ); } - m = shl(sub(num_bits, HVQ_PVQ_GAIN_BITS), 3); - IF (GE_16(m, n)) + m = shl( sub( num_bits, HVQ_PVQ_GAIN_BITS ), 3 ); + IF( GE_16( m, n ) ) { - IF (GT_16(num_bands, 1)) /* condition: num_bands > 1 */ + IF( GT_16( num_bands, 1 ) ) /* condition: num_bands > 1 */ { sel_bands[*n_sel_bands] = k_max; move16(); - *n_sel_bands = add(*n_sel_bands, 1); - R[k_max] = 1; /* Mark that the band has been encoded for fill_spectrum */ move16(); + *n_sel_bands = add( *n_sel_bands, 1 ); + R[k_max] = 1; /* Mark that the band has been encoded for fill_spectrum */ + move16(); } } } } /* Allocate bits */ - tmp = sub(num_bands,1); - FOR (k = 0; k < tmp; k++) + tmp = sub( num_bands, 1 ); + FOR( k = 0; k < tmp; k++ ) { - Rk[k] = shl(sub(band_max_bits, HVQ_PVQ_GAIN_BITS), 3); + Rk[k] = shl( sub( band_max_bits, HVQ_PVQ_GAIN_BITS ), 3 ); move16(); } /* NB: When it exits the above loop, k = num_bands - 1. */ - Rk[k] = shl(sub(num_bits, HVQ_PVQ_GAIN_BITS), 3); + Rk[k] = shl( sub( num_bits, HVQ_PVQ_GAIN_BITS ), 3 ); move16(); return num_bands; } - diff --git a/lib_com/ifft_rel.c b/lib_com/ifft_rel.c index c36dc8805..ff67fd3e4 100644 --- a/lib_com/ifft_rel.c +++ b/lib_com/ifft_rel.c @@ -45,9 +45,9 @@ * Local constants *-----------------------------------------------------------------*/ -#define N_MAX_FFT 1024 -#define INV_SQR2_FX 23170 -#define N_MAX_SAS 256 +#define N_MAX_FFT 1024 +#define INV_SQR2_FX 23170 +#define N_MAX_SAS 256 /*---------------------------------------------------------------------* * ifft_rel() * @@ -290,365 +290,365 @@ void ifft_rel( void ifft_rel_fx( - Word16 io[], /* i/o: input/output vector */ - const Word16 n, /* i : vector length */ - const Word16 m /* i : log2 of vector length */ + Word16 io[], /* i/o: input/output vector */ + const Word16 n, /* i : vector length */ + const Word16 m /* i : log2 of vector length */ ) { - Word16 i, j, k; - Word16 step; - Word16 n2, n4, n8, i0; - Word16 is, id; - Word16 *x, *xi0, *xi1, *xi2, *xi3, *xi4, *xup1, *xdn6, *xup3, *xdn8; - Word16 xt; - Word16 r1; - Word16 t1, t2, t3, t4, t5; - const Word16 *s, *c, *s3, *c3; + Word16 i, j, k; + Word16 step; + Word16 n2, n4, n8, i0; + Word16 is, id; + Word16 *x, *xi0, *xi1, *xi2, *xi3, *xi4, *xup1, *xdn6, *xup3, *xdn8; + Word16 xt; + Word16 r1; + Word16 t1, t2, t3, t4, t5; + const Word16 *s, *c, *s3, *c3; - Word16 cc1, cc3, ss1, ss3; - Word16 tmp; + Word16 cc1, cc3, ss1, ss3; + Word16 tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; + Flag Overflow = 0; #endif - /*-----------------------------------------------------------------* - * ifft - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * ifft + *-----------------------------------------------------------------*/ - x = &io[-1]; - move16(); - n2 = shl(n, 1); - FOR(k = 1; k < m; k++) - { - is = 0; - move16(); - id = n2; - move16(); - n2 = shr(n2, 1); - move16(); - n4 = shr(n2, 2); - move16(); - n8 = shr(n4, 1); + x = &io[-1]; move16(); - tmp = sub(n, 1); - WHILE(LT_16(is, tmp)) + n2 = shl( n, 1 ); + FOR( k = 1; k < m; k++ ) { - xi1 = x + is + 1; - move16(); - xi2 = xi1 + n4; - move16(); - xi3 = xi2 + n4; - move16(); - xi4 = xi3 + n4; - move16(); + is = 0; + move16(); + id = n2; + move16(); + n2 = shr( n2, 1 ); + move16(); + n4 = shr( n2, 2 ); + move16(); + n8 = shr( n4, 1 ); + move16(); + tmp = sub( n, 1 ); + WHILE( LT_16( is, tmp ) ) + { + xi1 = x + is + 1; + move16(); + xi2 = xi1 + n4; + move16(); + xi3 = xi2 + n4; + move16(); + xi4 = xi3 + n4; + move16(); - FOR(i = is; i < n; i += id) - { + FOR( i = is; i < n; i += id ) + { #ifdef BASOP_NOGLOB - t1 = sub_o(*xi1, *xi3, &Overflow); - *xi1 = add_o(*xi1, *xi3, &Overflow); -#else /* BASOP_NOGLOB */ - t1 = sub(*xi1, *xi3); - *xi1 = add(*xi1, *xi3); + t1 = sub_o( *xi1, *xi3, &Overflow ); + *xi1 = add_o( *xi1, *xi3, &Overflow ); +#else /* BASOP_NOGLOB */ + t1 = sub( *xi1, *xi3 ); + *xi1 = add( *xi1, *xi3 ); #endif /* BASOP_NOGLOB */ - move16(); + move16(); #ifdef BASOP_NOGLOB - *xi2 = shl_o(*xi2, 1, &Overflow); -#else /* BASOP_NOGLOB */ - *xi2 = shl(*xi2, 1); + *xi2 = shl_o( *xi2, 1, &Overflow ); +#else /* BASOP_NOGLOB */ + *xi2 = shl( *xi2, 1 ); #endif /* BASOP_NOGLOB */ - move16(); + move16(); #ifdef BASOP_NOGLOB - *xi3 = sub_o(t1, shl_o(*xi4, 1, &Overflow), &Overflow); -#else /* BASOP_NOGLOB */ - *xi3 = sub(t1, shl(*xi4, 1)); + *xi3 = sub_o( t1, shl_o( *xi4, 1, &Overflow ), &Overflow ); +#else /* BASOP_NOGLOB */ + *xi3 = sub( t1, shl( *xi4, 1 ) ); #endif /* BASOP_NOGLOB */ - move16(); + move16(); #ifdef BASOP_NOGLOB - *xi4 = add_o(t1, shl_o(*xi4, 1, &Overflow), &Overflow); -#else /* BASOP_NOGLOB */ - *xi4 = add(t1, shl(*xi4, 1)); + *xi4 = add_o( t1, shl_o( *xi4, 1, &Overflow ), &Overflow ); +#else /* BASOP_NOGLOB */ + *xi4 = add( t1, shl( *xi4, 1 ) ); #endif /* BASOP_NOGLOB */ - move16(); + move16(); - IF(NE_16(n4, 1)) - { + IF( NE_16( n4, 1 ) ) + { #ifdef BASOP_NOGLOB - t1 = mult_r(sub_o(*(xi2 + n8), *(xi1 + n8), &Overflow), INV_SQR2_FX); - t2 = mult_r(add_o(*(xi4 + n8), *(xi3 + n8), &Overflow), INV_SQR2_FX); -#else /* BASOP_NOGLOB */ - t1 = mult_r(sub(*(xi2 + n8), *(xi1 + n8)), INV_SQR2_FX); - t2 = mult_r(add(*(xi4 + n8), *(xi3 + n8)), INV_SQR2_FX); + t1 = mult_r( sub_o( *( xi2 + n8 ), *( xi1 + n8 ), &Overflow ), INV_SQR2_FX ); + t2 = mult_r( add_o( *( xi4 + n8 ), *( xi3 + n8 ), &Overflow ), INV_SQR2_FX ); +#else /* BASOP_NOGLOB */ + t1 = mult_r( sub( *( xi2 + n8 ), *( xi1 + n8 ) ), INV_SQR2_FX ); + t2 = mult_r( add( *( xi4 + n8 ), *( xi3 + n8 ) ), INV_SQR2_FX ); #endif /* BASOP_NOGLOB */ #ifdef BASOP_NOGLOB - *(xi1 + n8) = add_o(*(xi1 + n8), *(xi2 + n8), &Overflow); -#else /* BASOP_NOGLOB */ - *(xi1 + n8) = add(*(xi1 + n8), *(xi2 + n8)); + *( xi1 + n8 ) = add_o( *( xi1 + n8 ), *( xi2 + n8 ), &Overflow ); +#else /* BASOP_NOGLOB */ + *( xi1 + n8 ) = add( *( xi1 + n8 ), *( xi2 + n8 ) ); #endif /* BASOP_NOGLOB */ - move16(); + move16(); #ifdef BASOP_NOGLOB - *(xi2 + n8) = sub_o(*(xi4 + n8), *(xi3 + n8), &Overflow); -#else /* BASOP_NOGLOB */ - *(xi2 + n8) = sub(*(xi4 + n8), *(xi3 + n8)); + *( xi2 + n8 ) = sub_o( *( xi4 + n8 ), *( xi3 + n8 ), &Overflow ); +#else /* BASOP_NOGLOB */ + *( xi2 + n8 ) = sub( *( xi4 + n8 ), *( xi3 + n8 ) ); #endif /* BASOP_NOGLOB */ - move16(); + move16(); #ifdef BASOP_NOGLOB - *(xi3 + n8) = negate(shl_o(add_o(t2, t1, &Overflow), 1, &Overflow)); -#else /* BASOP_NOGLOB */ - *(xi3 + n8) = negate(shl(add(t2, t1), 1)); + *( xi3 + n8 ) = negate( shl_o( add_o( t2, t1, &Overflow ), 1, &Overflow ) ); +#else /* BASOP_NOGLOB */ + *( xi3 + n8 ) = negate( shl( add( t2, t1 ), 1 ) ); #endif /* BASOP_NOGLOB */ - move16(); + move16(); #ifdef BASOP_NOGLOB - *(xi4 + n8) = shl_o(sub_o(t1, t2, &Overflow), 1, &Overflow); -#else /* BASOP_NOGLOB */ - *(xi4 + n8) = shl(sub(t1, t2), 1); + *( xi4 + n8 ) = shl_o( sub_o( t1, t2, &Overflow ), 1, &Overflow ); +#else /* BASOP_NOGLOB */ + *( xi4 + n8 ) = shl( sub( t1, t2 ), 1 ); #endif /* BASOP_NOGLOB */ - move16(); + move16(); + } + xi1 += id; + move16(); + xi2 += id; + move16(); + xi3 += id; + move16(); + xi4 += id; + move16(); + } + is = sub( shl( id, 1 ), n2 ); + id = shl( id, 2 ); } - xi1 += id; + /*Can be acheived with a shr */ + step = N_MAX_SAS / n2; move16(); - xi2 += id; + + s = sincos_t_fx + step; move16(); - xi3 += id; + c = s + 64; move16(); - xi4 += id; + s3 = sincos_t_fx + i_mult2( step, 3 ); move16(); - } - is = sub(shl(id, 1), n2); - id = shl(id, 2); - } - /*Can be acheived with a shr */ - step = N_MAX_SAS / n2; - move16(); - - s = sincos_t_fx + step; - move16(); - c = s + 64; - move16(); - s3 = sincos_t_fx + i_mult2(step, 3); - move16(); - c3 = s3 + 64; - move16(); - FOR(j = 2; j <= n8; j++) - { - cc1 = *c; - move16(); - ss1 = *s; - move16(); - cc3 = *c3; - move16(); - ss3 = *s3; - move16(); + c3 = s3 + 64; + move16(); + FOR( j = 2; j <= n8; j++ ) + { + cc1 = *c; + move16(); + ss1 = *s; + move16(); + cc3 = *c3; + move16(); + ss3 = *s3; + move16(); - is = 0; - move16(); - id = shl(n2, 1); + is = 0; + move16(); + id = shl( n2, 1 ); - c += step; - move16(); - s += step; - move16(); + c += step; + move16(); + s += step; + move16(); - c3 += 3 * step; - move16(); - s3 += 3 * step; - move16(); - WHILE(LT_16(is, sub(n, 1))) - { - xup1 = x + j + is; - move16(); - xup3 = xup1 + shl(n4, 1); - move16(); - xdn6 = xup3 - shl(j, 1) + 2; - move16(); + c3 += 3 * step; + move16(); + s3 += 3 * step; + move16(); + WHILE( LT_16( is, sub( n, 1 ) ) ) + { + xup1 = x + j + is; + move16(); + xup3 = xup1 + shl( n4, 1 ); + move16(); + xdn6 = xup3 - shl( j, 1 ) + 2; + move16(); - xdn8 = xdn6 + shl(n4, 1); - move16(); + xdn8 = xdn6 + shl( n4, 1 ); + move16(); - FOR(i = is; i < n; i += id) - { + FOR( i = is; i < n; i += id ) + { #ifdef BASOP_NOGLOB - t1 = sub_o(*xup1, *xdn6, &Overflow); - *xup1 = add_o(*xup1, *xdn6, &Overflow); -#else /* BASOP_NOGLOB */ - t1 = sub(*xup1, *xdn6); - *xup1 = add(*xup1, *xdn6); + t1 = sub_o( *xup1, *xdn6, &Overflow ); + *xup1 = add_o( *xup1, *xdn6, &Overflow ); +#else /* BASOP_NOGLOB */ + t1 = sub( *xup1, *xdn6 ); + *xup1 = add( *xup1, *xdn6 ); #endif /* BASOP_NOGLOB */ - move16(); - xup1 += n4; - move16(); - xdn6 -= n4; - move16(); + move16(); + xup1 += n4; + move16(); + xdn6 -= n4; + move16(); #ifdef BASOP_NOGLOB - t2 = sub_o(*xdn6, *xup1, &Overflow); - *xdn6 = add_o(*xup1, *xdn6, &Overflow); -#else /* BASOP_NOGLOB */ - t2 = sub(*xdn6, *xup1); - *xdn6 = add(*xup1, *xdn6); + t2 = sub_o( *xdn6, *xup1, &Overflow ); + *xdn6 = add_o( *xup1, *xdn6, &Overflow ); +#else /* BASOP_NOGLOB */ + t2 = sub( *xdn6, *xup1 ); + *xdn6 = add( *xup1, *xdn6 ); #endif /* BASOP_NOGLOB */ - move16(); + move16(); - xdn6 += n4; - move16(); + xdn6 += n4; + move16(); #ifdef BASOP_NOGLOB - t3 = add_o(*xdn8, *xup3, &Overflow); - *xdn6 = sub_o(*xdn8, *xup3, &Overflow); -#else /* BASOP_NOGLOB */ - t3 = add(*xdn8, *xup3); - *xdn6 = sub(*xdn8, *xup3); + t3 = add_o( *xdn8, *xup3, &Overflow ); + *xdn6 = sub_o( *xdn8, *xup3, &Overflow ); +#else /* BASOP_NOGLOB */ + t3 = add( *xdn8, *xup3 ); + *xdn6 = sub( *xdn8, *xup3 ); #endif /* BASOP_NOGLOB */ - move16(); + move16(); - xup3 += n4; - move16(); - xdn8 -= n4; - move16(); + xup3 += n4; + move16(); + xdn8 -= n4; + move16(); #ifdef BASOP_NOGLOB - t4 = add_o(*xup3, *xdn8, &Overflow); - *xup1 = sub_o(*xup3, *xdn8, &Overflow); -#else /* BASOP_NOGLOB */ - t4 = add(*xup3, *xdn8); - *xup1 = sub(*xup3, *xdn8); + t4 = add_o( *xup3, *xdn8, &Overflow ); + *xup1 = sub_o( *xup3, *xdn8, &Overflow ); +#else /* BASOP_NOGLOB */ + t4 = add( *xup3, *xdn8 ); + *xup1 = sub( *xup3, *xdn8 ); #endif /* BASOP_NOGLOB */ - move16(); + move16(); #ifdef BASOP_NOGLOB - t5 = sub_o(t1, t4, &Overflow); - t1 = add_o(t1, t4, &Overflow); - t4 = sub_o(t2, t3, &Overflow); - t2 = add_o(t2, t3, &Overflow); - *xup3 = sub_o(mult_r(t1, cc3), mult_r(t2, ss3), &Overflow); -#else /* BASOP_NOGLOB */ - t5 = sub(t1, t4); - t1 = add(t1, t4); - t4 = sub(t2, t3); - t2 = add(t2, t3); - *xup3 = sub(mult_r(t1, cc3), mult_r(t2, ss3)); + t5 = sub_o( t1, t4, &Overflow ); + t1 = add_o( t1, t4, &Overflow ); + t4 = sub_o( t2, t3, &Overflow ); + t2 = add_o( t2, t3, &Overflow ); + *xup3 = sub_o( mult_r( t1, cc3 ), mult_r( t2, ss3 ), &Overflow ); +#else /* BASOP_NOGLOB */ + t5 = sub( t1, t4 ); + t1 = add( t1, t4 ); + t4 = sub( t2, t3 ); + t2 = add( t2, t3 ); + *xup3 = sub( mult_r( t1, cc3 ), mult_r( t2, ss3 ) ); #endif /* BASOP_NOGLOB */ - move16(); - xup3 -= n4; - move16(); + move16(); + xup3 -= n4; + move16(); #ifdef BASOP_NOGLOB - *xup3 = add_o(mult_r(t5, cc1), mult_r(t4, ss1), &Overflow); -#else /* BASOP_NOGLOB */ - *xup3 = add(mult_r(t5, cc1), mult_r(t4, ss1)); + *xup3 = add_o( mult_r( t5, cc1 ), mult_r( t4, ss1 ), &Overflow ); +#else /* BASOP_NOGLOB */ + *xup3 = add( mult_r( t5, cc1 ), mult_r( t4, ss1 ) ); #endif /* BASOP_NOGLOB */ - move16(); + move16(); #ifdef BASOP_NOGLOB - *xdn8 = sub_o(mult_r(t5, ss1), mult_r(t4, cc1), &Overflow); -#else /* BASOP_NOGLOB */ - *xdn8 = sub(mult_r(t5, ss1), mult_r(t4, cc1)); + *xdn8 = sub_o( mult_r( t5, ss1 ), mult_r( t4, cc1 ), &Overflow ); +#else /* BASOP_NOGLOB */ + *xdn8 = sub( mult_r( t5, ss1 ), mult_r( t4, cc1 ) ); #endif /* BASOP_NOGLOB */ - move16(); + move16(); - xdn8 += n4; - move16(); + xdn8 += n4; + move16(); #ifdef BASOP_NOGLOB - *xdn8 = add_o(mult_r(t2, cc3), mult_r(t1, ss3), &Overflow); -#else /* BASOP_NOGLOB */ - *xdn8 = add(mult_r(t2, cc3), mult_r(t1, ss3)); + *xdn8 = add_o( mult_r( t2, cc3 ), mult_r( t1, ss3 ), &Overflow ); +#else /* BASOP_NOGLOB */ + *xdn8 = add( mult_r( t2, cc3 ), mult_r( t1, ss3 ) ); #endif /* BASOP_NOGLOB */ - move16(); + move16(); - xup1 -= n4; - move16(); - xup1 += id; - move16(); - xup3 += id; - move16(); - xdn6 += id; - move16(); - xdn8 += id; - move16(); + xup1 -= n4; + move16(); + xup1 += id; + move16(); + xup3 += id; + move16(); + xdn6 += id; + move16(); + xdn8 += id; + move16(); + } + is = sub( shl( id, 1 ), n2 ); + id = shl( id, 2 ); + } } - is = sub(shl(id, 1), n2); - id = shl(id, 2); - } } - } - /*-----------------------------------------------------------------* - * Length two butterflies - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * Length two butterflies + *-----------------------------------------------------------------*/ - is = 1; - move16(); - id = 4; - move16(); - WHILE(is < n) - { - xi0 = x + is; + is = 1; move16(); - xi1 = xi0 + 1; + id = 4; move16(); - - FOR(i0 = is; i0 <= n; i0 += id) + WHILE( is < n ) { - r1 = *xi0; - move16(); + xi0 = x + is; + move16(); + xi1 = xi0 + 1; + move16(); + + FOR( i0 = is; i0 <= n; i0 += id ) + { + r1 = *xi0; + move16(); #ifdef BASOP_NOGLOB - *xi0 = add_o(r1, *xi1, &Overflow); -#else /* BASOP_NOGLOB */ - *xi0 = add(r1, *xi1); + *xi0 = add_o( r1, *xi1, &Overflow ); +#else /* BASOP_NOGLOB */ + *xi0 = add( r1, *xi1 ); #endif /* BASOP_NOGLOB */ - move16(); + move16(); #ifdef BASOP_NOGLOB - *xi1 = sub_o(r1, *xi1, &Overflow); + *xi1 = sub_o( r1, *xi1, &Overflow ); #else /* BASOP_NOGLOB */ - *xi1 = sub(r1, *xi1); + *xi1 = sub( r1, *xi1 ); #endif - move16(); - xi0 += id; - move16(); - xi1 += id; - move16(); + move16(); + xi0 += id; + move16(); + xi1 += id; + move16(); + } + is = sub( shl( id, 1 ), 1 ); + id = shl( id, 2 ); } - is = sub(shl(id, 1), 1); - id = shl(id, 2); - } - /*-----------------------------------------------------------------* - * Digit reverse counter - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * Digit reverse counter + *-----------------------------------------------------------------*/ - j = 1; - move16(); - FOR(i = 1; i < n; i++) - { - IF(LT_16(i, j)) - { - xt = x[j]; - move16(); - x[j] = x[i]; - move16(); - x[i] = xt; - move16(); - } - k = shr(n, 1); - WHILE(LT_16(k, j)) + j = 1; + move16(); + FOR( i = 1; i < n; i++ ) { - j = sub(j, k); - k = shr(k, 1); + IF( LT_16( i, j ) ) + { + xt = x[j]; + move16(); + x[j] = x[i]; + move16(); + x[i] = xt; + move16(); + } + k = shr( n, 1 ); + WHILE( LT_16( k, j ) ) + { + j = sub( j, k ); + k = shr( k, 1 ); + } + j = add( j, k ); } - j = add(j, k); - } - /*-----------------------------------------------------------------* - * Normalization - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * Normalization + *-----------------------------------------------------------------*/ - tmp = div_s(1, n); /*Q15 */ - FOR(i = 1; i <= n; i++) - { - x[i] = mult_r(x[i], tmp); - move16(); - } + tmp = div_s( 1, n ); /*Q15 */ + FOR( i = 1; i <= n; i++ ) + { + x[i] = mult_r( x[i], tmp ); + move16(); + } - return; + return; } #if 0 @@ -711,26 +711,26 @@ void ifft_rel_fx32( #ifdef BASOP_NOGLOB t1 = L_sub_o(*xi1, *xi3, &Overflow); *xi1 = L_add_o(*xi1, *xi3, &Overflow); -#else /* BASOP_NOGLOB */ +#else /* BASOP_NOGLOB */ t1 = L_sub(*xi1, *xi3); *xi1 = L_add(*xi1, *xi3); #endif /* BASOP_NOGLOB */ move32(); #ifdef BASOP_NOGLOB *xi2 = L_shl_o(*xi2, 1, &Overflow); -#else /* BASOP_NOGLOB */ +#else /* BASOP_NOGLOB */ *xi2 = L_shl(*xi2, 1); #endif /* BASOP_NOGLOB */ move32(); #ifdef BASOP_NOGLOB *xi3 = L_sub_o(t1, L_shl_o(*xi4, 1, &Overflow), &Overflow); -#else /* BASOP_NOGLOB */ +#else /* BASOP_NOGLOB */ *xi3 = L_sub(t1, L_shl(*xi4, 1)); #endif /* BASOP_NOGLOB */ move32(); #ifdef BASOP_NOGLOB *xi4 = L_add_o(t1, L_shl_o(*xi4, 1, &Overflow), &Overflow); -#else /* BASOP_NOGLOB */ +#else /* BASOP_NOGLOB */ *xi4 = L_add(t1, L_shl(*xi4, 1)); #endif /* BASOP_NOGLOB */ move32(); @@ -740,32 +740,32 @@ void ifft_rel_fx32( #ifdef BASOP_NOGLOB t1 = Mpy_32_16_1(L_sub_o(*(xi2 + n8), *(xi1 + n8), &Overflow), INV_SQR2_FX); t2 = Mpy_32_16_1(L_add_o(*(xi4 + n8), *(xi3 + n8), &Overflow), INV_SQR2_FX); -#else /* BASOP_NOGLOB */ +#else /* BASOP_NOGLOB */ t1 = Mpy_32_16_1(L_sub(*(xi2 + n8), *(xi1 + n8)), INV_SQR2_FX); t2 = Mpy_32_16_1(L_add(*(xi4 + n8), *(xi3 + n8)), INV_SQR2_FX); #endif /* BASOP_NOGLOB */ #ifdef BASOP_NOGLOB *(xi1 + n8) = L_add_o(*(xi1 + n8), *(xi2 + n8), &Overflow); -#else /* BASOP_NOGLOB */ +#else /* BASOP_NOGLOB */ *(xi1 + n8) = add(*(xi1 + n8), *(xi2 + n8)); #endif /* BASOP_NOGLOB */ move32(); #ifdef BASOP_NOGLOB *(xi2 + n8) = L_sub_o(*(xi4 + n8), *(xi3 + n8), &Overflow); -#else /* BASOP_NOGLOB */ +#else /* BASOP_NOGLOB */ *(xi2 + n8) = L_sub(*(xi4 + n8), *(xi3 + n8)); #endif /* BASOP_NOGLOB */ move32(); #ifdef BASOP_NOGLOB *(xi3 + n8) = L_negate(L_shl_o(L_add_o(t2, t1, &Overflow), 1, &Overflow)); -#else /* BASOP_NOGLOB */ +#else /* BASOP_NOGLOB */ *(xi3 + n8) = L_negate(shl(add(t2, t1), 1)); #endif /* BASOP_NOGLOB */ move32(); #ifdef BASOP_NOGLOB *(xi4 + n8) = L_shl_o(L_sub_o(t1, t2, &Overflow), 1, &Overflow); -#else /* BASOP_NOGLOB */ +#else /* BASOP_NOGLOB */ *(xi4 + n8) = L_shl(L_sub(t1, t2), 1); #endif /* BASOP_NOGLOB */ move32(); @@ -835,7 +835,7 @@ void ifft_rel_fx32( #ifdef BASOP_NOGLOB t1 = L_sub_o(*xup1, *xdn6, &Overflow); *xup1 = L_add_o(*xup1, *xdn6, &Overflow); -#else /* BASOP_NOGLOB */ +#else /* BASOP_NOGLOB */ t1 = L_sub(*xup1, *xdn6); *xup1 = L_add(*xup1, *xdn6); #endif /* BASOP_NOGLOB */ @@ -848,7 +848,7 @@ void ifft_rel_fx32( #ifdef BASOP_NOGLOB t2 = L_sub_o(*xdn6, *xup1, &Overflow); *xdn6 = L_add_o(*xup1, *xdn6, &Overflow); -#else /* BASOP_NOGLOB */ +#else /* BASOP_NOGLOB */ t2 = L_sub(*xdn6, *xup1); *xdn6 = L_add(*xup1, *xdn6); #endif /* BASOP_NOGLOB */ @@ -859,7 +859,7 @@ void ifft_rel_fx32( #ifdef BASOP_NOGLOB t3 = L_add_o(*xdn8, *xup3, &Overflow); *xdn6 = L_sub_o(*xdn8, *xup3, &Overflow); -#else /* BASOP_NOGLOB */ +#else /* BASOP_NOGLOB */ t3 = L_add(*xdn8, *xup3); *xdn6 = L_sub(*xdn8, *xup3); #endif /* BASOP_NOGLOB */ @@ -873,7 +873,7 @@ void ifft_rel_fx32( #ifdef BASOP_NOGLOB t4 = L_add_o(*xup3, *xdn8, &Overflow); *xup1 = L_sub_o(*xup3, *xdn8, &Overflow); -#else /* BASOP_NOGLOB */ +#else /* BASOP_NOGLOB */ t4 = L_add(*xup3, *xdn8); *xup1 = L_sub(*xup3, *xdn8); #endif /* BASOP_NOGLOB */ @@ -885,7 +885,7 @@ void ifft_rel_fx32( t4 = L_sub_o(t2, t3, &Overflow); t2 = L_add_o(t2, t3, &Overflow); *xup3 = L_sub_o(Mpy_32_16_1(t1, cc3), Mpy_32_16_1(t2, ss3), &Overflow); -#else /* BASOP_NOGLOB */ +#else /* BASOP_NOGLOB */ t5 = L_sub(t1, t4); t1 = L_add(t1, t4); t4 = L_sub(t2, t3); @@ -897,13 +897,13 @@ void ifft_rel_fx32( move32(); #ifdef BASOP_NOGLOB *xup3 = L_add_o(Mpy_32_16_1(t5, cc1), Mpy_32_16_1(t4, ss1), &Overflow); -#else /* BASOP_NOGLOB */ +#else /* BASOP_NOGLOB */ *xup3 = L_add(Mpy_32_16_1(t5, cc1), Mpy_32_16_1(t4, ss1)); #endif /* BASOP_NOGLOB */ move32(); #ifdef BASOP_NOGLOB *xdn8 = L_sub_o(Mpy_32_16_1(t5, ss1), Mpy_32_16_1(t4, cc1), &Overflow); -#else /* BASOP_NOGLOB */ +#else /* BASOP_NOGLOB */ *xdn8 = L_sub(Mpy_32_16_1(t5, ss1), Mpy_32_16_1(t4, cc1)); #endif /* BASOP_NOGLOB */ move32(); @@ -912,7 +912,7 @@ void ifft_rel_fx32( move32(); #ifdef BASOP_NOGLOB *xdn8 = L_add_o(Mpy_32_16_1(t2, cc3), Mpy_32_16_1(t1, ss3), &Overflow); -#else /* BASOP_NOGLOB */ +#else /* BASOP_NOGLOB */ *xdn8 = L_add(Mpy_32_16_1(t2, cc3), Mpy_32_16_1(t1, ss3)); #endif /* BASOP_NOGLOB */ move32(); @@ -955,7 +955,7 @@ void ifft_rel_fx32( move32(); #ifdef BASOP_NOGLOB *xi0 = L_add_o(r1, *xi1, &Overflow); -#else /* BASOP_NOGLOB */ +#else /* BASOP_NOGLOB */ *xi0 = add(r1, *xi1); #endif /* BASOP_NOGLOB */ move32(); @@ -1014,11 +1014,11 @@ void ifft_rel_fx32( return; } #else -#define INV_SQRT_2_16 (Word16)(0x5A82) +#define INV_SQRT_2_16 ( Word16 )( 0x5A82 ) void ifft_rel_fx32( - Word32 io[], /* i/o: input/output vector */ - const Word16 n, /* i : vector length */ - const Word16 m /* i : log2 of vector length */ + Word32 io[], /* i/o: input/output vector */ + const Word16 n, /* i : vector length */ + const Word16 m /* i : log2 of vector length */ ) { Word16 i, j, k; @@ -1035,7 +1035,7 @@ void ifft_rel_fx32( Word32 temp[512]; Word16 n_inv = 128; - SWITCH (n) + SWITCH( n ) { case 128: n_inv = 256; @@ -1047,7 +1047,7 @@ void ifft_rel_fx32( n_inv = 64; BREAK; default: - assert(0); + assert( 0 ); BREAK; } @@ -1056,37 +1056,37 @@ void ifft_rel_fx32( *-----------------------------------------------------------------*/ x = &io[-1]; - n2 = shl(n, 1); - FOR ( k = 1; k < m; k++ ) + n2 = shl( n, 1 ); + FOR( k = 1; k < m; k++ ) { is = 0; id = n2; - n2 = shr(n2, 1); - n4 = shr(n2, 2); - n8 = shr(n4, 1); - WHILE ( LT_16(is, n - 1) ) + n2 = shr( n2, 1 ); + n4 = shr( n2, 2 ); + n8 = shr( n4, 1 ); + WHILE( LT_16( is, n - 1 ) ) { xi1 = x + is + 1; xi2 = xi1 + n4; xi3 = xi2 + n4; xi4 = xi3 + n4; - FOR ( i = is; i < n; i += id ) + FOR( i = is; i < n; i += id ) { - t1 = L_sub(*xi1, *xi3); - *xi1 = L_add(*xi1, *xi3); - *xi2 = L_shl(*xi2, 1); - *xi3 = L_sub(t1, L_shl(*xi4, 1)); - *xi4 = L_add(t1, L_shl(*xi4, 1)); - IF ( n4 != 1 ) + t1 = L_sub( *xi1, *xi3 ); + *xi1 = L_add( *xi1, *xi3 ); + *xi2 = L_shl( *xi2, 1 ); + *xi3 = L_sub( t1, L_shl( *xi4, 1 ) ); + *xi4 = L_add( t1, L_shl( *xi4, 1 ) ); + IF( n4 != 1 ) { - t1 = Mpy_32_16_1(L_sub( *( xi2 + n8 ), *( xi1 + n8 ) ), INV_SQRT_2_16); - t2 = Mpy_32_16_1(L_add( *( xi4 + n8 ), *( xi3 + n8 ) ), INV_SQRT_2_16); + t1 = Mpy_32_16_1( L_sub( *( xi2 + n8 ), *( xi1 + n8 ) ), INV_SQRT_2_16 ); + t2 = Mpy_32_16_1( L_add( *( xi4 + n8 ), *( xi3 + n8 ) ), INV_SQRT_2_16 ); - *( xi1 + n8 ) = L_add(*( xi1 + n8 ), *( xi2 + n8 )); - *( xi2 + n8 ) = L_sub(*( xi4 + n8 ), *( xi3 + n8 )); - *( xi3 + n8 ) = L_shl(L_negate(L_add(t2, t1)), 1 ); - *( xi4 + n8 ) = L_shl(L_sub(t1, t2), 1 ); + *( xi1 + n8 ) = L_add( *( xi1 + n8 ), *( xi2 + n8 ) ); + *( xi2 + n8 ) = L_sub( *( xi4 + n8 ), *( xi3 + n8 ) ); + *( xi3 + n8 ) = L_shl( L_negate( L_add( t2, t1 ) ), 1 ); + *( xi4 + n8 ) = L_shl( L_sub( t1, t2 ), 1 ); } xi1 += id; xi2 += id; @@ -1102,7 +1102,7 @@ void ifft_rel_fx32( c = s + N_MAX_FFT / 4; s3 = sincos_t_ext_fx + 3 * step; c3 = s3 + N_MAX_FFT / 4; - FOR ( j = 2; j <= n8; j++ ) + FOR( j = 2; j <= n8; j++ ) { cc1 = *c; ss1 = *s; @@ -1117,44 +1117,44 @@ void ifft_rel_fx32( c3 += 3 * step; s3 += 3 * step; - WHILE ( LT_16(is, n - 1) ) + WHILE( LT_16( is, n - 1 ) ) { xup1 = x + j + is; xup3 = xup1 + 2 * n4; xdn6 = xup3 - 2 * j + 2; xdn8 = xdn6 + 2 * n4; - FOR ( i = is; i < n; i += id ) + FOR( i = is; i < n; i += id ) { - t1 = L_sub(*xup1, *xdn6); - *xup1 = L_add(*xup1, *xdn6); + t1 = L_sub( *xup1, *xdn6 ); + *xup1 = L_add( *xup1, *xdn6 ); xup1 += n4; xdn6 -= n4; - t2 = L_sub(*xdn6, *xup1); - *xdn6 = L_add(*xup1, *xdn6); + t2 = L_sub( *xdn6, *xup1 ); + *xdn6 = L_add( *xup1, *xdn6 ); xdn6 += n4; - t3 = L_add(*xdn8, *xup3); - *xdn6 = L_sub(*xdn8, *xup3); + t3 = L_add( *xdn8, *xup3 ); + *xdn6 = L_sub( *xdn8, *xup3 ); xup3 += n4; xdn8 -= n4; - t4 = L_add(*xup3, *xdn8); - *xup1 = L_sub(*xup3, *xdn8); + t4 = L_add( *xup3, *xdn8 ); + *xup1 = L_sub( *xup3, *xdn8 ); - t5 = L_sub(t1, t4); - t1 = L_add(t1, t4); - t4 = L_sub(t2, t3); - t2 = L_add(t2, t3); - *xup3 = L_sub(Mpy_32_16_1(t1, cc3), Mpy_32_16_1(t2, ss3)); + t5 = L_sub( t1, t4 ); + t1 = L_add( t1, t4 ); + t4 = L_sub( t2, t3 ); + t2 = L_add( t2, t3 ); + *xup3 = L_sub( Mpy_32_16_1( t1, cc3 ), Mpy_32_16_1( t2, ss3 ) ); xup3 -= n4; - *xup3 = L_add(Mpy_32_16_1(t5, cc1), Mpy_32_16_1(t4, ss1)); - *xdn8 = L_sub(Mpy_32_16_1(t5, ss1), Mpy_32_16_1(t4, cc1)); + *xup3 = L_add( Mpy_32_16_1( t5, cc1 ), Mpy_32_16_1( t4, ss1 ) ); + *xdn8 = L_sub( Mpy_32_16_1( t5, ss1 ), Mpy_32_16_1( t4, cc1 ) ); xdn8 += n4; - *xdn8 = L_add(Mpy_32_16_1(t2, cc3), Mpy_32_16_1(t1, ss3)); + *xdn8 = L_add( Mpy_32_16_1( t2, cc3 ), Mpy_32_16_1( t1, ss3 ) ); xup1 -= n4; xup1 += id; @@ -1162,8 +1162,8 @@ void ifft_rel_fx32( xdn6 += id; xdn8 += id; } - is = shl(id, 1) - n2; - id = shl(id, 2); + is = shl( id, 1 ) - n2; + id = shl( id, 2 ); } } } @@ -1174,21 +1174,21 @@ void ifft_rel_fx32( is = 1; id = 4; - WHILE ( LT_16(is, n) ) + WHILE( LT_16( is, n ) ) { xi0 = x + is; xi1 = xi0 + 1; - FOR ( i0 = is; i0 <= n; i0 += id ) + FOR( i0 = is; i0 <= n; i0 += id ) { r1 = *xi0; - *xi0 = L_add(r1, *xi1); - *xi1 = L_sub(r1, *xi1); + *xi0 = L_add( r1, *xi1 ); + *xi1 = L_sub( r1, *xi1 ); xi0 += id; xi1 += id; } - is = shl(id, 1) - 1; - id = shl(id, 2); + is = shl( id, 1 ) - 1; + id = shl( id, 2 ); } /*-----------------------------------------------------------------* @@ -1197,25 +1197,25 @@ void ifft_rel_fx32( idx = fft256_read_indexes; xi0 = &temp[0] - 1; - IF ( EQ_16(n, 128) ) + IF( EQ_16( n, 128 ) ) { - FOR ( i = 0; i < n; i++ ) + FOR( i = 0; i < n; i++ ) { j = *idx++; temp[i] = x[1 + shr( j, 1 )]; } } - ELSE IF ( EQ_16(n, 256) ) + ELSE IF( EQ_16( n, 256 ) ) { - FOR ( i = 0; i < n; i++ ) + FOR( i = 0; i < n; i++ ) { j = *idx++; temp[i] = x[1 + j]; } } - ELSE IF ( EQ_16(n, 512) ) + ELSE IF( EQ_16( n, 512 ) ) { - FOR ( i = 0; i < 256; i++ ) + FOR( i = 0; i < 256; i++ ) { j = *idx++; temp[i] = x[1 + 2 * j]; @@ -1226,21 +1226,21 @@ void ifft_rel_fx32( { xi0 = x; j = 1; - FOR ( i = 1; i < n; i++ ) + FOR( i = 1; i < n; i++ ) { - IF ( LT_16(i, j) ) + IF( LT_16( i, j ) ) { xt = x[j]; x[j] = x[i]; x[i] = xt; } - k = shr(n, 1); - WHILE ( LT_16(k, j) ) + k = shr( n, 1 ); + WHILE( LT_16( k, j ) ) { - j = sub(j, k); - k = shr(k, 1); + j = sub( j, k ); + k = shr( k, 1 ); } - j = add(j, k); + j = add( j, k ); } } @@ -1248,11 +1248,11 @@ void ifft_rel_fx32( * Normalization *-----------------------------------------------------------------*/ - FOR ( i = 1; i <= n; i++ ) + FOR( i = 1; i <= n; i++ ) { - x[i] = Mpy_32_16_1(xi0[i], n_inv); + x[i] = Mpy_32_16_1( xi0[i], n_inv ); } return; } -#endif \ No newline at end of file +#endif diff --git a/lib_com/igf_base.c b/lib_com/igf_base.c index 39ec2187c..658707947 100644 --- a/lib_com/igf_base.c +++ b/lib_com/igf_base.c @@ -508,9 +508,9 @@ static void IGF_gridSetUp_flt( } #ifdef IVAS_FLOAT_FIXED - //hGrid->fFactor = float_to_fix16(hGrid->fFactor_flt, Q14); - //hGrid->lFactor = float_to_fix16(hGrid->lFactor_flt, Q14); - //hGrid->gFactor = float_to_fix16(hGrid->gFactor_flt, Q14); + // hGrid->fFactor = float_to_fix16(hGrid->fFactor_flt, Q14); + // hGrid->lFactor = float_to_fix16(hGrid->lFactor_flt, Q14); + // hGrid->gFactor = float_to_fix16(hGrid->gFactor_flt, Q14); #endif return; diff --git a/lib_com/igf_base_fx.c b/lib_com/igf_base_fx.c index 95008e3b0..1b9f44d63 100644 --- a/lib_com/igf_base_fx.c +++ b/lib_com/igf_base_fx.c @@ -16,21 +16,21 @@ /**********************************************************************/ /* returns an int val, multiplied with transFac **************************************************************************/ -Word16 IGF_ApplyTransFac( /**< out: Q0 | multiplication factor */ - const Word16 val, /**< in: Q15 | input value for multiplication, Q15 */ - const Word16 transFac /**< in: Q14 | multiplicator for variable val, Q14: 1.25f=0x5000, 1.0f=0x4000, 0.5f=0x2000 */ +Word16 IGF_ApplyTransFac( /**< out: Q0 | multiplication factor */ + const Word16 val, /**< in: Q15 | input value for multiplication, Q15 */ + const Word16 transFac /**< in: Q14 | multiplicator for variable val, Q14: 1.25f=0x5000, 1.0f=0x4000, 0.5f=0x2000 */ ) { Word16 ret; - if(EQ_16(transFac, 0x4000)) + if ( EQ_16( transFac, 0x4000 ) ) { return val; } - ret = shl(val, 1); - ret = mac_r(0x00000000, ret, transFac); - ret = add(ret, s_and(ret, 1)); + ret = shl( val, 1 ); + ret = mac_r( 0x00000000, ret, transFac ); + ret = add( ret, s_and( ret, 1 ) ); return ret; @@ -49,330 +49,330 @@ Word16 IGF_MapBitRateToIndex( Word16 bitRateIndex = IGF_BITRATE_UNKNOWN; move16(); /* Stereo/CPE modes */ - IF(GT_16(element_mode, IVAS_SCE)) + IF( GT_16( element_mode, IVAS_SCE ) ) { - SWITCH (bwidth) + SWITCH( bwidth ) { - case IGF_MODE_WB: - IF(LE_32(brate, IVAS_13k2) && EQ_16(rf_mode, 1)) - { - bitRateIndex = IGF_BITRATE_RF_WB_13200; - move16(); - } - ELSE IF(LE_32(brate, ACELP_9k60)) - { - bitRateIndex = IGF_BITRATE_WB_13200_CPE; - move16(); - } - ELSE IF(LE_32(brate, IVAS_13k2)) - { - bitRateIndex = IGF_BITRATE_WB_16400_CPE; - move16(); - } - BREAK; - case IGF_MODE_SWB: - /* DFT and TD Stereo bitrates */ - IF(LE_32(brate, ACELP_9k60)) - { - bitRateIndex = IGF_BITRATE_SWB_13200_CPE; - move16(); - } - ELSE IF(LE_32(brate, IVAS_13k2)) - { - IF(EQ_16(rf_mode, 1)) + case IGF_MODE_WB: + IF( LE_32( brate, IVAS_13k2 ) && EQ_16( rf_mode, 1 ) ) { - bitRateIndex = IGF_BITRATE_RF_SWB_13200; + bitRateIndex = IGF_BITRATE_RF_WB_13200; move16(); } - ELSE + ELSE IF( LE_32( brate, ACELP_9k60 ) ) { - bitRateIndex = IGF_BITRATE_SWB_16400_CPE; + bitRateIndex = IGF_BITRATE_WB_13200_CPE; move16(); } - } - ELSE IF(LE_32(brate, IVAS_16k4)) - { - bitRateIndex = IGF_BITRATE_SWB_24400_CPE; - move16(); - } - ELSE IF(LE_32(brate, IVAS_24k4) ) - { - bitRateIndex = IGF_BITRATE_SWB_32000_CPE; - move16(); - } - ELSE IF(LE_32(brate, IVAS_32k) ) - { - bitRateIndex = IGF_BITRATE_SWB_32000; - move16(); - } - /* MDCT Stereo bitrates */ - ELSE IF(LE_32(brate, IVAS_48k) ) - { - bitRateIndex = IGF_BITRATE_SWB_48000_CPE; - move16(); - } - ELSE IF(LE_32(brate, IVAS_64k) ) - { - bitRateIndex = IGF_BITRATE_SWB_64000_CPE; - move16(); - } - ELSE IF(LE_32(brate, IVAS_80k) ) - { - bitRateIndex = IGF_BITRATE_SWB_80000_CPE; - move16(); - } - ELSE IF(LE_32(brate, IVAS_96k)) - { - bitRateIndex = IGF_BITRATE_SWB_96000_CPE; - move16(); - } - BREAK; - case IGF_MODE_FB: - /* DFT and TD Stereo bitrates */ - IF(LE_32(brate, IVAS_16k4) ) - { - bitRateIndex = IGF_BITRATE_FB_24400_CPE; - move16(); - } - ELSE IF(LE_32(brate, IVAS_24k4) ) - { - bitRateIndex = IGF_BITRATE_FB_32000_CPE; - move16(); - } - ELSE IF(LE_32(brate, IVAS_32k)) - { - bitRateIndex = IGF_BITRATE_FB_32000; - move16(); - } - /* MDCT Stereo bitrates */ - ELSE IF(LE_32(brate, IVAS_48k)) - { - bitRateIndex = IGF_BITRATE_FB_48000_CPE; - move16(); - } - ELSE IF(LE_32(brate, IVAS_64k) ) - { - bitRateIndex = IGF_BITRATE_FB_64000_CPE; - move16(); - } - ELSE IF(LE_32(brate, IVAS_80k) ) - { - bitRateIndex = IGF_BITRATE_FB_80000_CPE; - move16(); - } - ELSE IF(LE_32(brate, IVAS_96k) ) - { - bitRateIndex = IGF_BITRATE_FB_96000_CPE; - move16(); - } - ELSE IF(LE_32(brate, IVAS_128k)) - { - bitRateIndex = IGF_BITRATE_FB_128000_CPE; - move16(); - } - BREAK; + ELSE IF( LE_32( brate, IVAS_13k2 ) ) + { + bitRateIndex = IGF_BITRATE_WB_16400_CPE; + move16(); + } + BREAK; + case IGF_MODE_SWB: + /* DFT and TD Stereo bitrates */ + IF( LE_32( brate, ACELP_9k60 ) ) + { + bitRateIndex = IGF_BITRATE_SWB_13200_CPE; + move16(); + } + ELSE IF( LE_32( brate, IVAS_13k2 ) ) + { + IF( EQ_16( rf_mode, 1 ) ) + { + bitRateIndex = IGF_BITRATE_RF_SWB_13200; + move16(); + } + ELSE + { + bitRateIndex = IGF_BITRATE_SWB_16400_CPE; + move16(); + } + } + ELSE IF( LE_32( brate, IVAS_16k4 ) ) + { + bitRateIndex = IGF_BITRATE_SWB_24400_CPE; + move16(); + } + ELSE IF( LE_32( brate, IVAS_24k4 ) ) + { + bitRateIndex = IGF_BITRATE_SWB_32000_CPE; + move16(); + } + ELSE IF( LE_32( brate, IVAS_32k ) ) + { + bitRateIndex = IGF_BITRATE_SWB_32000; + move16(); + } + /* MDCT Stereo bitrates */ + ELSE IF( LE_32( brate, IVAS_48k ) ) + { + bitRateIndex = IGF_BITRATE_SWB_48000_CPE; + move16(); + } + ELSE IF( LE_32( brate, IVAS_64k ) ) + { + bitRateIndex = IGF_BITRATE_SWB_64000_CPE; + move16(); + } + ELSE IF( LE_32( brate, IVAS_80k ) ) + { + bitRateIndex = IGF_BITRATE_SWB_80000_CPE; + move16(); + } + ELSE IF( LE_32( brate, IVAS_96k ) ) + { + bitRateIndex = IGF_BITRATE_SWB_96000_CPE; + move16(); + } + BREAK; + case IGF_MODE_FB: + /* DFT and TD Stereo bitrates */ + IF( LE_32( brate, IVAS_16k4 ) ) + { + bitRateIndex = IGF_BITRATE_FB_24400_CPE; + move16(); + } + ELSE IF( LE_32( brate, IVAS_24k4 ) ) + { + bitRateIndex = IGF_BITRATE_FB_32000_CPE; + move16(); + } + ELSE IF( LE_32( brate, IVAS_32k ) ) + { + bitRateIndex = IGF_BITRATE_FB_32000; + move16(); + } + /* MDCT Stereo bitrates */ + ELSE IF( LE_32( brate, IVAS_48k ) ) + { + bitRateIndex = IGF_BITRATE_FB_48000_CPE; + move16(); + } + ELSE IF( LE_32( brate, IVAS_64k ) ) + { + bitRateIndex = IGF_BITRATE_FB_64000_CPE; + move16(); + } + ELSE IF( LE_32( brate, IVAS_80k ) ) + { + bitRateIndex = IGF_BITRATE_FB_80000_CPE; + move16(); + } + ELSE IF( LE_32( brate, IVAS_96k ) ) + { + bitRateIndex = IGF_BITRATE_FB_96000_CPE; + move16(); + } + ELSE IF( LE_32( brate, IVAS_128k ) ) + { + bitRateIndex = IGF_BITRATE_FB_128000_CPE; + move16(); + } + BREAK; } } /* SCE modes: use tunings done for DFT stereo bitrates also for according SCE bitrates, otherwise same config as mono modes */ - ELSE IF(EQ_16(element_mode, IVAS_SCE)) + ELSE IF( EQ_16( element_mode, IVAS_SCE ) ) { - SWITCH (bwidth) + SWITCH( bwidth ) { - case IGF_MODE_WB: - IF(LE_32(brate, IVAS_13k2) && EQ_16(rf_mode, 1) ) - { - bitRateIndex = IGF_BITRATE_RF_WB_13200; - move16(); - } - ELSE IF(LE_32(brate, ACELP_9k60)) /* bitrates 8000 and 9600 */ - { - bitRateIndex = IGF_BITRATE_WB_9600; - move16(); - } - BREAK; - case IGF_MODE_SWB: - IF(LE_32(brate, ACELP_9k60) ) - { - bitRateIndex = IGF_BITRATE_SWB_13200_CPE; - move16(); - } - ELSE IF(LE_32(brate, IVAS_13k2) ) - { - IF(EQ_16(rf_mode, 1)) + case IGF_MODE_WB: + IF( LE_32( brate, IVAS_13k2 ) && EQ_16( rf_mode, 1 ) ) { - bitRateIndex = IGF_BITRATE_RF_SWB_13200; + bitRateIndex = IGF_BITRATE_RF_WB_13200; move16(); } - ELSE + ELSE IF( LE_32( brate, ACELP_9k60 ) ) /* bitrates 8000 and 9600 */ { - bitRateIndex = IGF_BITRATE_SWB_16400_CPE; + bitRateIndex = IGF_BITRATE_WB_9600; move16(); } - } - ELSE IF(LE_32(brate, IVAS_16k4) ) - { - bitRateIndex = IGF_BITRATE_SWB_24400_CPE; - move16(); - } - ELSE IF(LE_32(brate, IVAS_24k4)) - { - move16(); - bitRateIndex = IGF_BITRATE_SWB_32000_CPE; - } - ELSE IF(LE_32(brate, IVAS_32k) ) - { - bitRateIndex = IGF_BITRATE_SWB_32000; - move16(); - } - ELSE IF(LE_32(brate, IVAS_48k)) - { - bitRateIndex = IGF_BITRATE_SWB_48000; - move16(); - } - ELSE IF(LE_32(brate, IVAS_64k)) - { - bitRateIndex = IGF_BITRATE_SWB_64000; - move16(); - } - BREAK; - case IGF_MODE_FB: - IF(LE_32(brate, IVAS_16k4) ) - { - bitRateIndex = IGF_BITRATE_FB_24400_CPE; - move16(); - } - ELSE IF(LE_32(brate, IVAS_24k4)) - { - bitRateIndex = IGF_BITRATE_FB_32000_CPE; - move16(); - } - ELSE IF(LE_32(brate, IVAS_32k) ) - { - bitRateIndex = IGF_BITRATE_FB_32000; - move16(); - } - ELSE IF(LE_32(brate, IVAS_48k)) - { - bitRateIndex = IGF_BITRATE_FB_48000; - move16(); - } - ELSE IF(LE_32(brate, IVAS_64k)) - { - bitRateIndex = IGF_BITRATE_FB_64000; - move16(); - } - ELSE IF(LE_32(brate, IVAS_96k)) - { - bitRateIndex = IGF_BITRATE_FB_96000; - move16(); - } - ELSE IF(LE_32(brate, IVAS_128k)) - { - bitRateIndex = IGF_BITRATE_FB_128000; - move16(); - } - BREAK; + BREAK; + case IGF_MODE_SWB: + IF( LE_32( brate, ACELP_9k60 ) ) + { + bitRateIndex = IGF_BITRATE_SWB_13200_CPE; + move16(); + } + ELSE IF( LE_32( brate, IVAS_13k2 ) ) + { + IF( EQ_16( rf_mode, 1 ) ) + { + bitRateIndex = IGF_BITRATE_RF_SWB_13200; + move16(); + } + ELSE + { + bitRateIndex = IGF_BITRATE_SWB_16400_CPE; + move16(); + } + } + ELSE IF( LE_32( brate, IVAS_16k4 ) ) + { + bitRateIndex = IGF_BITRATE_SWB_24400_CPE; + move16(); + } + ELSE IF( LE_32( brate, IVAS_24k4 ) ) + { + move16(); + bitRateIndex = IGF_BITRATE_SWB_32000_CPE; + } + ELSE IF( LE_32( brate, IVAS_32k ) ) + { + bitRateIndex = IGF_BITRATE_SWB_32000; + move16(); + } + ELSE IF( LE_32( brate, IVAS_48k ) ) + { + bitRateIndex = IGF_BITRATE_SWB_48000; + move16(); + } + ELSE IF( LE_32( brate, IVAS_64k ) ) + { + bitRateIndex = IGF_BITRATE_SWB_64000; + move16(); + } + BREAK; + case IGF_MODE_FB: + IF( LE_32( brate, IVAS_16k4 ) ) + { + bitRateIndex = IGF_BITRATE_FB_24400_CPE; + move16(); + } + ELSE IF( LE_32( brate, IVAS_24k4 ) ) + { + bitRateIndex = IGF_BITRATE_FB_32000_CPE; + move16(); + } + ELSE IF( LE_32( brate, IVAS_32k ) ) + { + bitRateIndex = IGF_BITRATE_FB_32000; + move16(); + } + ELSE IF( LE_32( brate, IVAS_48k ) ) + { + bitRateIndex = IGF_BITRATE_FB_48000; + move16(); + } + ELSE IF( LE_32( brate, IVAS_64k ) ) + { + bitRateIndex = IGF_BITRATE_FB_64000; + move16(); + } + ELSE IF( LE_32( brate, IVAS_96k ) ) + { + bitRateIndex = IGF_BITRATE_FB_96000; + move16(); + } + ELSE IF( LE_32( brate, IVAS_128k ) ) + { + bitRateIndex = IGF_BITRATE_FB_128000; + move16(); + } + BREAK; } } /* EVS mono */ else { - SWITCH (bwidth) + SWITCH( bwidth ) { - case IGF_MODE_WB: - IF(LE_32(brate, ACELP_13k20) && EQ_16(rf_mode, 1)) - { - bitRateIndex = IGF_BITRATE_RF_WB_13200; - move16(); - } - ELSE IF(LE_32(brate, ACELP_9k60)) /* bitrates 8000 and 9600 */ - { - bitRateIndex = IGF_BITRATE_WB_9600; - move16(); - } - BREAK; - case IGF_MODE_SWB: - IF(LE_32(brate, ACELP_9k60)) - { - move16(); - bitRateIndex = IGF_BITRATE_SWB_9600; - } - ELSE IF(LE_32(brate, ACELP_13k20) ) - { - IF(EQ_16(rf_mode, 1)) + case IGF_MODE_WB: + IF( LE_32( brate, ACELP_13k20 ) && EQ_16( rf_mode, 1 ) ) { - bitRateIndex = IGF_BITRATE_RF_SWB_13200; + bitRateIndex = IGF_BITRATE_RF_WB_13200; move16(); } - ELSE + ELSE IF( LE_32( brate, ACELP_9k60 ) ) /* bitrates 8000 and 9600 */ { - bitRateIndex = IGF_BITRATE_SWB_13200; + bitRateIndex = IGF_BITRATE_WB_9600; move16(); } - } - ELSE IF(LE_32(brate, ACELP_16k40) ) - { - bitRateIndex = IGF_BITRATE_SWB_16400; - move16(); - } - ELSE IF(LE_32(brate, ACELP_24k40)) - { - bitRateIndex = IGF_BITRATE_SWB_24400; - move16(); - } - ELSE IF(LE_32(brate, ACELP_32k)) - { - bitRateIndex = IGF_BITRATE_SWB_32000; - move16(); - } - ELSE IF(LE_32(brate, ACELP_48k)) - { - bitRateIndex = IGF_BITRATE_SWB_48000; - move16(); - } - ELSE IF(LE_32(brate, ACELP_64k) ) - { - bitRateIndex = IGF_BITRATE_SWB_64000; - move16(); - } - BREAK; - case IGF_MODE_FB: - IF(LE_32(brate, ACELP_16k40) ) - { - bitRateIndex = IGF_BITRATE_FB_16400; - move16(); - } - ELSE IF(LE_32(brate, ACELP_24k40)) - { - bitRateIndex = IGF_BITRATE_FB_24400; - move16(); - } - ELSE IF(LE_32(brate, ACELP_32k) ) - { - bitRateIndex = IGF_BITRATE_FB_32000; - move16(); - } - ELSE IF(LE_32(brate, ACELP_48k) ) - { - bitRateIndex = IGF_BITRATE_FB_48000; - move16(); - } - ELSE IF(LE_32(brate, ACELP_64k)) - { - bitRateIndex = IGF_BITRATE_FB_64000; - move16(); - } - ELSE IF(LE_32(brate, HQ_96k) ) - { - bitRateIndex = IGF_BITRATE_FB_96000; - move16(); - } - ELSE IF(LE_32(brate, HQ_128k)) - { - bitRateIndex = IGF_BITRATE_FB_128000; - move16(); - } - BREAK; + BREAK; + case IGF_MODE_SWB: + IF( LE_32( brate, ACELP_9k60 ) ) + { + move16(); + bitRateIndex = IGF_BITRATE_SWB_9600; + } + ELSE IF( LE_32( brate, ACELP_13k20 ) ) + { + IF( EQ_16( rf_mode, 1 ) ) + { + bitRateIndex = IGF_BITRATE_RF_SWB_13200; + move16(); + } + ELSE + { + bitRateIndex = IGF_BITRATE_SWB_13200; + move16(); + } + } + ELSE IF( LE_32( brate, ACELP_16k40 ) ) + { + bitRateIndex = IGF_BITRATE_SWB_16400; + move16(); + } + ELSE IF( LE_32( brate, ACELP_24k40 ) ) + { + bitRateIndex = IGF_BITRATE_SWB_24400; + move16(); + } + ELSE IF( LE_32( brate, ACELP_32k ) ) + { + bitRateIndex = IGF_BITRATE_SWB_32000; + move16(); + } + ELSE IF( LE_32( brate, ACELP_48k ) ) + { + bitRateIndex = IGF_BITRATE_SWB_48000; + move16(); + } + ELSE IF( LE_32( brate, ACELP_64k ) ) + { + bitRateIndex = IGF_BITRATE_SWB_64000; + move16(); + } + BREAK; + case IGF_MODE_FB: + IF( LE_32( brate, ACELP_16k40 ) ) + { + bitRateIndex = IGF_BITRATE_FB_16400; + move16(); + } + ELSE IF( LE_32( brate, ACELP_24k40 ) ) + { + bitRateIndex = IGF_BITRATE_FB_24400; + move16(); + } + ELSE IF( LE_32( brate, ACELP_32k ) ) + { + bitRateIndex = IGF_BITRATE_FB_32000; + move16(); + } + ELSE IF( LE_32( brate, ACELP_48k ) ) + { + bitRateIndex = IGF_BITRATE_FB_48000; + move16(); + } + ELSE IF( LE_32( brate, ACELP_64k ) ) + { + bitRateIndex = IGF_BITRATE_FB_64000; + move16(); + } + ELSE IF( LE_32( brate, HQ_96k ) ) + { + bitRateIndex = IGF_BITRATE_FB_96000; + move16(); + } + ELSE IF( LE_32( brate, HQ_128k ) ) + { + bitRateIndex = IGF_BITRATE_FB_128000; + move16(); + } + BREAK; } } @@ -382,13 +382,13 @@ Word16 IGF_MapBitRateToIndex( /**********************************************************************/ /* IGF grid setup **************************************************************************/ -static void IGF_gridSetUp(H_IGF_GRID hGrid, /**< out: | IGF grid handle */ - Word16 bitRateIndex, /**< in: Q0 | IGF bitrate index */ - Word32 sampleRate, /**< in: | sample rate */ - Word16 frameLength, /**< in: | frame length */ - Word16 transFac, /**< in: | transFac */ - Word16 igfMinFq /**< in: | IGF minimum frequency indicating lower start frequency for copy up */ - ) +static void IGF_gridSetUp( H_IGF_GRID hGrid, /**< out: | IGF grid handle */ + Word16 bitRateIndex, /**< in: Q0 | IGF bitrate index */ + Word32 sampleRate, /**< in: | sample rate */ + Word16 frameLength, /**< in: | frame length */ + Word16 transFac, /**< in: | transFac */ + Word16 igfMinFq /**< in: | IGF minimum frequency indicating lower start frequency for copy up */ +) { Word16 t; Word16 sfb; @@ -401,452 +401,451 @@ static void IGF_gridSetUp(H_IGF_GRID hGrid, Word32 L_tmp1; Word32 L_tmp2; - swb_offset = NULL; + swb_offset = NULL; move16(); swb_offset_len = 0; move16(); - SWITCH (bitRateIndex) + SWITCH( bitRateIndex ) { - case IGF_BITRATE_WB_9600: - case IGF_BITRATE_SWB_9600: - case IGF_BITRATE_RF_WB_13200: - case IGF_BITRATE_RF_SWB_13200: - case IGF_BITRATE_SWB_13200: - case IGF_BITRATE_SWB_16400: - case IGF_BITRATE_SWB_24400: - case IGF_BITRATE_SWB_32000: - case IGF_BITRATE_SWB_48000: - swb_offset = &swb_offset_LB_new[bitRateIndex][1]; - swb_offset_len = swb_offset_LB_new[bitRateIndex][0]; - move16(); - Copy(&igf_whitening_TH[bitRateIndex][0][0], &hGrid->whiteningThreshold[0][0], IGF_MAX_TILES * 2); - BREAK; - case IGF_BITRATE_FB_16400: - case IGF_BITRATE_FB_24400: - case IGF_BITRATE_FB_32000: - swb_offset = &swb_offset_LB_new[bitRateIndex][1]; - swb_offset_len = swb_offset_LB_new[bitRateIndex][0]; - move16(); - Copy(&igf_whitening_TH[bitRateIndex][0][0], &hGrid->whiteningThreshold[0][0], IGF_MAX_TILES * 2); - BREAK; - case IGF_BITRATE_FB_48000: - case IGF_BITRATE_FB_96000: - case IGF_BITRATE_FB_128000: - swb_offset = &swb_offset_LB_new[bitRateIndex][1]; - swb_offset_len = swb_offset_LB_new[bitRateIndex][0]; - move16(); - Copy(&igf_whitening_TH[bitRateIndex][0][0], &hGrid->whiteningThreshold[0][0], IGF_MAX_TILES * 2); - BREAK; - case IGF_BITRATE_UNKNOWN: - default: - assert(0); + case IGF_BITRATE_WB_9600: + case IGF_BITRATE_SWB_9600: + case IGF_BITRATE_RF_WB_13200: + case IGF_BITRATE_RF_SWB_13200: + case IGF_BITRATE_SWB_13200: + case IGF_BITRATE_SWB_16400: + case IGF_BITRATE_SWB_24400: + case IGF_BITRATE_SWB_32000: + case IGF_BITRATE_SWB_48000: + swb_offset = &swb_offset_LB_new[bitRateIndex][1]; + swb_offset_len = swb_offset_LB_new[bitRateIndex][0]; + move16(); + Copy( &igf_whitening_TH[bitRateIndex][0][0], &hGrid->whiteningThreshold[0][0], IGF_MAX_TILES * 2 ); + BREAK; + case IGF_BITRATE_FB_16400: + case IGF_BITRATE_FB_24400: + case IGF_BITRATE_FB_32000: + swb_offset = &swb_offset_LB_new[bitRateIndex][1]; + swb_offset_len = swb_offset_LB_new[bitRateIndex][0]; + move16(); + Copy( &igf_whitening_TH[bitRateIndex][0][0], &hGrid->whiteningThreshold[0][0], IGF_MAX_TILES * 2 ); + BREAK; + case IGF_BITRATE_FB_48000: + case IGF_BITRATE_FB_96000: + case IGF_BITRATE_FB_128000: + swb_offset = &swb_offset_LB_new[bitRateIndex][1]; + swb_offset_len = swb_offset_LB_new[bitRateIndex][0]; + move16(); + Copy( &igf_whitening_TH[bitRateIndex][0][0], &hGrid->whiteningThreshold[0][0], IGF_MAX_TILES * 2 ); + BREAK; + case IGF_BITRATE_UNKNOWN: + default: + assert( 0 ); } - FOR(sfb = 0; sfb < swb_offset_len; sfb++) + FOR( sfb = 0; sfb < swb_offset_len; sfb++ ) { - hGrid->swb_offset[sfb] = IGF_ApplyTransFac(swb_offset[sfb], transFac); + hGrid->swb_offset[sfb] = IGF_ApplyTransFac( swb_offset[sfb], transFac ); move16(); } - hGrid->infoIsRefined = 0; + hGrid->infoIsRefined = 0; move16(); - frameLength = IGF_ApplyTransFac(frameLength, transFac); - tmp2 = norm_s(frameLength); - bandwidth = shl(frameLength,tmp2); - hGrid->swb_offset_len = extract_l(L_shr(sampleRate, 2)); - tmp1 = sub(norm_s(hGrid->swb_offset_len), 1); - hGrid->swb_offset_len = shl(hGrid->swb_offset_len, tmp1); - bandwidth = div_s(hGrid->swb_offset_len, bandwidth); - tmp2 = sub(add(tmp2, 1), tmp1); - bandwidth = shr(bandwidth, sub(15, tmp2)); - - - hGrid->swb_offset_len = swb_offset_len; + frameLength = IGF_ApplyTransFac( frameLength, transFac ); + tmp2 = norm_s( frameLength ); + bandwidth = shl( frameLength, tmp2 ); + hGrid->swb_offset_len = extract_l( L_shr( sampleRate, 2 ) ); + tmp1 = sub( norm_s( hGrid->swb_offset_len ), 1 ); + hGrid->swb_offset_len = shl( hGrid->swb_offset_len, tmp1 ); + bandwidth = div_s( hGrid->swb_offset_len, bandwidth ); + tmp2 = sub( add( tmp2, 1 ), tmp1 ); + bandwidth = shr( bandwidth, sub( 15, tmp2 ) ); + + + hGrid->swb_offset_len = swb_offset_len; move16(); - hGrid->startSfb = 0; + hGrid->startSfb = 0; move16(); - hGrid->stopSfb = sub(hGrid->swb_offset_len, 1); - hGrid->startLine = hGrid->swb_offset[ hGrid->startSfb ]; + hGrid->stopSfb = sub( hGrid->swb_offset_len, 1 ); + hGrid->startLine = hGrid->swb_offset[hGrid->startSfb]; move16(); - hGrid->stopLine = hGrid->swb_offset[ hGrid->stopSfb ]; + hGrid->stopLine = hGrid->swb_offset[hGrid->stopSfb]; move16(); - hGrid->startFrequency = imult1616(bandwidth, hGrid->startLine); - hGrid->stopFrequency = imult1616(bandwidth, hGrid->stopLine); + hGrid->startFrequency = imult1616( bandwidth, hGrid->startLine ); + hGrid->stopFrequency = imult1616( bandwidth, hGrid->stopLine ); - L_tmp1 = L_mult0(igfMinFq, frameLength); - tmp1 = sub(norm_l(L_tmp1), 1); - L_tmp1 = L_shl(L_tmp1, tmp1); + L_tmp1 = L_mult0( igfMinFq, frameLength ); + tmp1 = sub( norm_l( L_tmp1 ), 1 ); + L_tmp1 = L_shl( L_tmp1, tmp1 ); - tmp2 = norm_l(sampleRate); - L_tmp2 = L_shl(sampleRate, tmp2); - tmp1 = add(WORD16_BITS-1, sub(tmp1, add(tmp2, 1))); /* takes into account sampleRate >> 1 */ + tmp2 = norm_l( sampleRate ); + L_tmp2 = L_shl( sampleRate, tmp2 ); + tmp1 = add( WORD16_BITS - 1, sub( tmp1, add( tmp2, 1 ) ) ); /* takes into account sampleRate >> 1 */ - hGrid->minSrcSubband = div_s(extract_h(L_tmp1), extract_h(L_tmp2)); - hGrid->minSrcSubband = shr(hGrid->minSrcSubband, tmp1); + hGrid->minSrcSubband = div_s( extract_h( L_tmp1 ), extract_h( L_tmp2 ) ); + hGrid->minSrcSubband = shr( hGrid->minSrcSubband, tmp1 ); - hGrid->minSrcSubband = add(hGrid->minSrcSubband, s_and(hGrid->minSrcSubband, 1)); - hGrid->minSrcFrequency = imult1616(bandwidth, hGrid->minSrcSubband); - hGrid->infoGranuleLen = frameLength; + hGrid->minSrcSubband = add( hGrid->minSrcSubband, s_and( hGrid->minSrcSubband, 1 ) ); + hGrid->minSrcFrequency = imult1616( bandwidth, hGrid->minSrcSubband ); + hGrid->infoGranuleLen = frameLength; move16(); - hGrid->infoTransFac = transFac; + hGrid->infoTransFac = transFac; move16(); - hGrid->sfbWrap[0] = 0; + hGrid->sfbWrap[0] = 0; move16(); - hGrid->tile[0] = hGrid->startLine; + hGrid->tile[0] = hGrid->startLine; move16(); /*************************************************************************/ - SWITCH (bitRateIndex) + SWITCH( bitRateIndex ) { - /* SWB 13200 */ - case IGF_BITRATE_WB_9600: - hGrid->nTiles = 2; - move16(); - wrp_sfb = 2; - move16(); + /* SWB 13200 */ + case IGF_BITRATE_WB_9600: + hGrid->nTiles = 2; + move16(); + wrp_sfb = 2; + move16(); - /*1st*/ - hGrid->sfbWrap[0+1] = wrp_sfb; - move16(); - hGrid->sbWrap[0] = hGrid->minSrcSubband; - move16(); - hGrid->tile[0+1] = hGrid->swb_offset[wrp_sfb]; - move16(); + /*1st*/ + hGrid->sfbWrap[0 + 1] = wrp_sfb; + move16(); + hGrid->sbWrap[0] = hGrid->minSrcSubband; + move16(); + hGrid->tile[0 + 1] = hGrid->swb_offset[wrp_sfb]; + move16(); - /*2nd*/ - hGrid->sfbWrap[1+1] = hGrid->stopSfb; - move16(); - hGrid->sbWrap[1] = hGrid->minSrcSubband; - move16(); - hGrid->tile[1+1] = hGrid->swb_offset[hGrid->stopSfb]; - move16(); - BREAK; - - case IGF_BITRATE_RF_WB_13200: - hGrid->nTiles = 2; - wrp_sfb = 2; - - /*1st*/ - hGrid->sfbWrap[0+1] = wrp_sfb; - hGrid->sbWrap[0] = hGrid->minSrcSubband; - hGrid->tile[0+1] = hGrid->swb_offset[wrp_sfb]; - - /*2nd*/ - hGrid->sfbWrap[1+1] = hGrid->stopSfb; - hGrid->sbWrap[1] = hGrid->minSrcSubband; - hGrid->tile[1+1] = hGrid->swb_offset[hGrid->stopSfb]; - - BREAK; - case IGF_BITRATE_SWB_9600: - hGrid->nTiles = 3; - wrp_sfb = 1; - - /*1st*/ - hGrid->sfbWrap[0+1] = wrp_sfb; - hGrid->sbWrap[0] = hGrid->minSrcSubband; - hGrid->tile[0+1] = hGrid->swb_offset[wrp_sfb]; - - /*2nd*/ - wrp_sfb = 2; - hGrid->sfbWrap[1+1] = wrp_sfb; - hGrid->sbWrap[1] = hGrid->minSrcSubband + IGF_ApplyTransFac(32, transFac); - hGrid->tile[1+1] = hGrid->swb_offset[wrp_sfb]; - - /*3rd*/ - hGrid->sfbWrap[2+1] = hGrid->stopSfb; - hGrid->sbWrap[2] = hGrid->minSrcSubband + IGF_ApplyTransFac(46, transFac); - hGrid->tile[2+1] = hGrid->swb_offset[hGrid->stopSfb]; - - BREAK; - case IGF_BITRATE_RF_SWB_13200: - hGrid->nTiles = 3; - wrp_sfb = 1; - - /*1st*/ - hGrid->sfbWrap[0+1] = wrp_sfb; - hGrid->sbWrap[0] = hGrid->minSrcSubband; - hGrid->tile[0+1] = hGrid->swb_offset[wrp_sfb]; - - /*2nd*/ - wrp_sfb = 2; - hGrid->sfbWrap[1+1] = wrp_sfb; - hGrid->sbWrap[1] = hGrid->minSrcSubband + IGF_ApplyTransFac(32, transFac); - hGrid->tile[1+1] = hGrid->swb_offset[wrp_sfb]; - - /*3rd*/ - hGrid->sfbWrap[2+1] = hGrid->stopSfb; - hGrid->sbWrap[2] = hGrid->minSrcSubband + IGF_ApplyTransFac(46, transFac); - hGrid->tile[2+1] = hGrid->swb_offset[hGrid->stopSfb]; - - BREAK; - - case IGF_BITRATE_SWB_13200: - hGrid->nTiles = 2; - move16(); - wrp_sfb = 4; - move16(); + /*2nd*/ + hGrid->sfbWrap[1 + 1] = hGrid->stopSfb; + move16(); + hGrid->sbWrap[1] = hGrid->minSrcSubband; + move16(); + hGrid->tile[1 + 1] = hGrid->swb_offset[hGrid->stopSfb]; + move16(); + BREAK; - /*1st*/ - hGrid->sfbWrap[0+1] = wrp_sfb; - move16(); - hGrid->sbWrap[0] = hGrid->minSrcSubband; - move16(); - hGrid->tile[0+1] = hGrid->swb_offset[wrp_sfb]; - move16(); + case IGF_BITRATE_RF_WB_13200: + hGrid->nTiles = 2; + wrp_sfb = 2; - /*2nd*/ - hGrid->sfbWrap[1+1] = hGrid->stopSfb; - move16(); - hGrid->sbWrap[1] = add(hGrid->minSrcSubband, IGF_ApplyTransFac(32, transFac)); - move16(); - hGrid->tile[1+1] = hGrid->swb_offset[hGrid->stopSfb]; - move16(); - BREAK; + /*1st*/ + hGrid->sfbWrap[0 + 1] = wrp_sfb; + hGrid->sbWrap[0] = hGrid->minSrcSubband; + hGrid->tile[0 + 1] = hGrid->swb_offset[wrp_sfb]; - case IGF_BITRATE_SWB_16400: - hGrid->nTiles = 3; - move16(); - wrp_sfb = 4; - move16(); + /*2nd*/ + hGrid->sfbWrap[1 + 1] = hGrid->stopSfb; + hGrid->sbWrap[1] = hGrid->minSrcSubband; + hGrid->tile[1 + 1] = hGrid->swb_offset[hGrid->stopSfb]; - /*1st*/ - hGrid->sfbWrap[0+1] = wrp_sfb; - move16(); - hGrid->sbWrap[0] = hGrid->minSrcSubband; - move16(); - hGrid->tile[0+1] = hGrid->swb_offset[wrp_sfb]; - move16(); + BREAK; + case IGF_BITRATE_SWB_9600: + hGrid->nTiles = 3; + wrp_sfb = 1; - /*2nd*/ - hGrid->sfbWrap[1+1] = 6; - move16(); - hGrid->sbWrap[1] = add(hGrid->minSrcSubband, IGF_ApplyTransFac(48, transFac)); - move16(); - hGrid->tile[1+1] = hGrid->swb_offset[6]; - move16(); + /*1st*/ + hGrid->sfbWrap[0 + 1] = wrp_sfb; + hGrid->sbWrap[0] = hGrid->minSrcSubband; + hGrid->tile[0 + 1] = hGrid->swb_offset[wrp_sfb]; - /*3nd*/ - hGrid->sfbWrap[2+1] = hGrid->stopSfb; - move16(); - hGrid->sbWrap[2] = add(hGrid->minSrcSubband, IGF_ApplyTransFac(64, transFac)); - move16(); - hGrid->tile[2+1] = hGrid->swb_offset[hGrid->stopSfb]; - move16(); - BREAK; + /*2nd*/ + wrp_sfb = 2; + hGrid->sfbWrap[1 + 1] = wrp_sfb; + hGrid->sbWrap[1] = hGrid->minSrcSubband + IGF_ApplyTransFac( 32, transFac ); + hGrid->tile[1 + 1] = hGrid->swb_offset[wrp_sfb]; - case IGF_BITRATE_SWB_24400: - case IGF_BITRATE_SWB_32000: - hGrid->nTiles = 3; - move16(); - wrp_sfb = 4; - move16(); + /*3rd*/ + hGrid->sfbWrap[2 + 1] = hGrid->stopSfb; + hGrid->sbWrap[2] = hGrid->minSrcSubband + IGF_ApplyTransFac( 46, transFac ); + hGrid->tile[2 + 1] = hGrid->swb_offset[hGrid->stopSfb]; - /*1st*/ - hGrid->sfbWrap[0+1] = wrp_sfb; - move16(); - hGrid->sbWrap[0] = hGrid->minSrcSubband; - move16(); - hGrid->tile[0+1] = hGrid->swb_offset[wrp_sfb]; - move16(); + BREAK; + case IGF_BITRATE_RF_SWB_13200: + hGrid->nTiles = 3; + wrp_sfb = 1; - /*2nd*/ - hGrid->sfbWrap[1+1] = 7; - move16(); - hGrid->sbWrap[1] = add(hGrid->minSrcSubband, IGF_ApplyTransFac(32, transFac)); - move16(); - hGrid->tile[1+1] = hGrid->swb_offset[7]; - move16(); + /*1st*/ + hGrid->sfbWrap[0 + 1] = wrp_sfb; + hGrid->sbWrap[0] = hGrid->minSrcSubband; + hGrid->tile[0 + 1] = hGrid->swb_offset[wrp_sfb]; - /*3nd*/ - hGrid->sfbWrap[2+1] = hGrid->stopSfb; - move16(); - hGrid->sbWrap[2] = add(hGrid->minSrcSubband, IGF_ApplyTransFac(64, transFac)); - move16(); - hGrid->tile[2+1] = hGrid->swb_offset[hGrid->stopSfb]; - move16(); - BREAK; - case IGF_BITRATE_SWB_48000: - hGrid->nTiles = 1; - move16(); - wrp_sfb = hGrid->stopSfb; - move16(); + /*2nd*/ + wrp_sfb = 2; + hGrid->sfbWrap[1 + 1] = wrp_sfb; + hGrid->sbWrap[1] = hGrid->minSrcSubband + IGF_ApplyTransFac( 32, transFac ); + hGrid->tile[1 + 1] = hGrid->swb_offset[wrp_sfb]; - /*1st*/ - hGrid->sfbWrap[0+1] = hGrid->stopSfb; - move16(); - hGrid->sbWrap[0] = sub(shl(hGrid->startLine, 1), hGrid->stopLine); - move16(); - hGrid->tile[0+1] = hGrid->swb_offset[hGrid->stopSfb]; - move16(); + /*3rd*/ + hGrid->sfbWrap[2 + 1] = hGrid->stopSfb; + hGrid->sbWrap[2] = hGrid->minSrcSubband + IGF_ApplyTransFac( 46, transFac ); + hGrid->tile[2 + 1] = hGrid->swb_offset[hGrid->stopSfb]; - BREAK; - case IGF_BITRATE_FB_16400: - hGrid->nTiles = 3; - move16(); - wrp_sfb = 4; - move16(); + BREAK; - /*1st*/ - hGrid->sfbWrap[0+1] = wrp_sfb; - move16(); - hGrid->sbWrap[0] = hGrid->minSrcSubband; - move16(); - hGrid->tile[0+1] = hGrid->swb_offset[wrp_sfb]; - move16(); - wrp_sfb = 7; - move16(); + case IGF_BITRATE_SWB_13200: + hGrid->nTiles = 2; + move16(); + wrp_sfb = 4; + move16(); - /*2nd*/ - hGrid->sfbWrap[1+1] = wrp_sfb; - move16(); - hGrid->sbWrap[1] = hGrid->minSrcSubband; - move16(); - hGrid->tile[1+1] = hGrid->swb_offset[wrp_sfb]; - move16(); + /*1st*/ + hGrid->sfbWrap[0 + 1] = wrp_sfb; + move16(); + hGrid->sbWrap[0] = hGrid->minSrcSubband; + move16(); + hGrid->tile[0 + 1] = hGrid->swb_offset[wrp_sfb]; + move16(); - /*3nd*/ - hGrid->sfbWrap[2+1] = hGrid->stopSfb; - move16(); - hGrid->sbWrap[2] = hGrid->minSrcSubband; - move16(); - hGrid->tile[2+1] = hGrid->swb_offset[hGrid->stopSfb]; - move16(); + /*2nd*/ + hGrid->sfbWrap[1 + 1] = hGrid->stopSfb; + move16(); + hGrid->sbWrap[1] = add( hGrid->minSrcSubband, IGF_ApplyTransFac( 32, transFac ) ); + move16(); + hGrid->tile[1 + 1] = hGrid->swb_offset[hGrid->stopSfb]; + move16(); + BREAK; - BREAK; + case IGF_BITRATE_SWB_16400: + hGrid->nTiles = 3; + move16(); + wrp_sfb = 4; + move16(); - case IGF_BITRATE_FB_24400: - case IGF_BITRATE_FB_32000: - hGrid->nTiles = 4; - move16(); - wrp_sfb = 4; - move16(); + /*1st*/ + hGrid->sfbWrap[0 + 1] = wrp_sfb; + move16(); + hGrid->sbWrap[0] = hGrid->minSrcSubband; + move16(); + hGrid->tile[0 + 1] = hGrid->swb_offset[wrp_sfb]; + move16(); - /*1st*/ - hGrid->sfbWrap[0+1] = wrp_sfb; - move16(); - hGrid->sbWrap[0] = hGrid->minSrcSubband; - move16(); - hGrid->tile[0+1] = hGrid->swb_offset[wrp_sfb]; - move16(); - wrp_sfb = 6; - move16(); + /*2nd*/ + hGrid->sfbWrap[1 + 1] = 6; + move16(); + hGrid->sbWrap[1] = add( hGrid->minSrcSubband, IGF_ApplyTransFac( 48, transFac ) ); + move16(); + hGrid->tile[1 + 1] = hGrid->swb_offset[6]; + move16(); + + /*3nd*/ + hGrid->sfbWrap[2 + 1] = hGrid->stopSfb; + move16(); + hGrid->sbWrap[2] = add( hGrid->minSrcSubband, IGF_ApplyTransFac( 64, transFac ) ); + move16(); + hGrid->tile[2 + 1] = hGrid->swb_offset[hGrid->stopSfb]; + move16(); + BREAK; + + case IGF_BITRATE_SWB_24400: + case IGF_BITRATE_SWB_32000: + hGrid->nTiles = 3; + move16(); + wrp_sfb = 4; + move16(); + + /*1st*/ + hGrid->sfbWrap[0 + 1] = wrp_sfb; + move16(); + hGrid->sbWrap[0] = hGrid->minSrcSubband; + move16(); + hGrid->tile[0 + 1] = hGrid->swb_offset[wrp_sfb]; + move16(); + + /*2nd*/ + hGrid->sfbWrap[1 + 1] = 7; + move16(); + hGrid->sbWrap[1] = add( hGrid->minSrcSubband, IGF_ApplyTransFac( 32, transFac ) ); + move16(); + hGrid->tile[1 + 1] = hGrid->swb_offset[7]; + move16(); + + /*3nd*/ + hGrid->sfbWrap[2 + 1] = hGrid->stopSfb; + move16(); + hGrid->sbWrap[2] = add( hGrid->minSrcSubband, IGF_ApplyTransFac( 64, transFac ) ); + move16(); + hGrid->tile[2 + 1] = hGrid->swb_offset[hGrid->stopSfb]; + move16(); + BREAK; + case IGF_BITRATE_SWB_48000: + hGrid->nTiles = 1; + move16(); + wrp_sfb = hGrid->stopSfb; + move16(); + + /*1st*/ + hGrid->sfbWrap[0 + 1] = hGrid->stopSfb; + move16(); + hGrid->sbWrap[0] = sub( shl( hGrid->startLine, 1 ), hGrid->stopLine ); + move16(); + hGrid->tile[0 + 1] = hGrid->swb_offset[hGrid->stopSfb]; + move16(); + + BREAK; + case IGF_BITRATE_FB_16400: + hGrid->nTiles = 3; + move16(); + wrp_sfb = 4; + move16(); + + /*1st*/ + hGrid->sfbWrap[0 + 1] = wrp_sfb; + move16(); + hGrid->sbWrap[0] = hGrid->minSrcSubband; + move16(); + hGrid->tile[0 + 1] = hGrid->swb_offset[wrp_sfb]; + move16(); + wrp_sfb = 7; + move16(); + + /*2nd*/ + hGrid->sfbWrap[1 + 1] = wrp_sfb; + move16(); + hGrid->sbWrap[1] = hGrid->minSrcSubband; + move16(); + hGrid->tile[1 + 1] = hGrid->swb_offset[wrp_sfb]; + move16(); + + /*3nd*/ + hGrid->sfbWrap[2 + 1] = hGrid->stopSfb; + move16(); + hGrid->sbWrap[2] = hGrid->minSrcSubband; + move16(); + hGrid->tile[2 + 1] = hGrid->swb_offset[hGrid->stopSfb]; + move16(); + + BREAK; + + case IGF_BITRATE_FB_24400: + case IGF_BITRATE_FB_32000: + hGrid->nTiles = 4; + move16(); + wrp_sfb = 4; + move16(); + + /*1st*/ + hGrid->sfbWrap[0 + 1] = wrp_sfb; + move16(); + hGrid->sbWrap[0] = hGrid->minSrcSubband; + move16(); + hGrid->tile[0 + 1] = hGrid->swb_offset[wrp_sfb]; + move16(); + wrp_sfb = 6; + move16(); - /*2nd*/ - hGrid->sfbWrap[1+1] = wrp_sfb; - move16(); - hGrid->sbWrap[1] = add(hGrid->minSrcSubband, IGF_ApplyTransFac(32, transFac)); - move16(); - hGrid->tile[1+1] = hGrid->swb_offset[wrp_sfb]; - move16(); - wrp_sfb = 9; - move16(); + /*2nd*/ + hGrid->sfbWrap[1 + 1] = wrp_sfb; + move16(); + hGrid->sbWrap[1] = add( hGrid->minSrcSubband, IGF_ApplyTransFac( 32, transFac ) ); + move16(); + hGrid->tile[1 + 1] = hGrid->swb_offset[wrp_sfb]; + move16(); + wrp_sfb = 9; + move16(); - /*3nd*/ - hGrid->sfbWrap[2+1] = wrp_sfb; - move16(); - hGrid->sbWrap[2] = hGrid->minSrcSubband; - move16(); - hGrid->tile[2+1] = hGrid->swb_offset[wrp_sfb]; - move16(); + /*3nd*/ + hGrid->sfbWrap[2 + 1] = wrp_sfb; + move16(); + hGrid->sbWrap[2] = hGrid->minSrcSubband; + move16(); + hGrid->tile[2 + 1] = hGrid->swb_offset[wrp_sfb]; + move16(); - /*4nd*/ - hGrid->sfbWrap[3+1] = hGrid->stopSfb; - move16(); - hGrid->sbWrap[3] = add(hGrid->minSrcSubband, sub(hGrid->swb_offset[9], hGrid->swb_offset[8])); - move16(); - hGrid->tile[3+1] = hGrid->swb_offset[hGrid->stopSfb]; - move16(); - BREAK; - case IGF_BITRATE_FB_48000: - case IGF_BITRATE_FB_96000: - case IGF_BITRATE_FB_128000: - hGrid->nTiles = 1; - move16(); + /*4nd*/ + hGrid->sfbWrap[3 + 1] = hGrid->stopSfb; + move16(); + hGrid->sbWrap[3] = add( hGrid->minSrcSubband, sub( hGrid->swb_offset[9], hGrid->swb_offset[8] ) ); + move16(); + hGrid->tile[3 + 1] = hGrid->swb_offset[hGrid->stopSfb]; + move16(); + BREAK; + case IGF_BITRATE_FB_48000: + case IGF_BITRATE_FB_96000: + case IGF_BITRATE_FB_128000: + hGrid->nTiles = 1; + move16(); - /*1st*/ - hGrid->sfbWrap[0+1] = hGrid->stopSfb; - move16(); - hGrid->sbWrap[0] = sub(shl(hGrid->startLine, 1), hGrid->stopLine); - move16(); - hGrid->tile[0+1] = hGrid->swb_offset[hGrid->stopSfb]; - move16(); + /*1st*/ + hGrid->sfbWrap[0 + 1] = hGrid->stopSfb; + move16(); + hGrid->sbWrap[0] = sub( shl( hGrid->startLine, 1 ), hGrid->stopLine ); + move16(); + hGrid->tile[0 + 1] = hGrid->swb_offset[hGrid->stopSfb]; + move16(); - BREAK; - default: - assert(0); - }/*switch*/ + BREAK; + default: + assert( 0 ); + } /*switch*/ /*************************************************************************/ /*************************************************************************/ /* adapt level envelope: */ - SWITCH (bitRateIndex) + SWITCH( bitRateIndex ) { - case IGF_BITRATE_RF_WB_13200: - case IGF_BITRATE_WB_9600: - hGrid->gFactor = 13107/*0.80f Q14*/; - move16(); - hGrid->fFactor = 11469/*0.70f Q14*/; - move16(); - hGrid->lFactor = 9830/*0.60f Q14*/; - move16(); - BREAK; - case IGF_BITRATE_SWB_13200: - case IGF_BITRATE_FB_16400: - case IGF_BITRATE_SWB_16400: - hGrid->gFactor = 15237/*0.93f Q14*/; - move16(); - hGrid->fFactor = 3277/*0.20f Q14*/; - move16(); - hGrid->lFactor = 13926/*0.85f Q14*/; - move16(); - BREAK; - case IGF_BITRATE_FB_24400: - case IGF_BITRATE_SWB_24400: - case IGF_BITRATE_FB_32000: - case IGF_BITRATE_SWB_32000: - hGrid->gFactor = 15811/*0.965f Q14*/; - move16(); - hGrid->fFactor = 3277/*0.20f Q14*/; - move16(); - hGrid->lFactor = 13926/*0.85f Q14*/; - move16(); - BREAK; - case IGF_BITRATE_FB_48000: - case IGF_BITRATE_SWB_48000: - hGrid->gFactor = 16384/*1.00f Q14*/; - move16(); - hGrid->fFactor = 3277/*0.20f Q14*/; - move16(); - hGrid->lFactor = 16384/*1.00f Q14*/; - move16(); - BREAK; - case IGF_BITRATE_SWB_9600: - case IGF_BITRATE_RF_SWB_13200: - default: - hGrid->gFactor = 16384/*1.00f Q14*/; - move16(); - hGrid->fFactor = 0/*0.00f Q14*/; - move16(); - hGrid->lFactor = 16384/*1.00f Q14*/; - move16(); + case IGF_BITRATE_RF_WB_13200: + case IGF_BITRATE_WB_9600: + hGrid->gFactor = 13107 /*0.80f Q14*/; + move16(); + hGrid->fFactor = 11469 /*0.70f Q14*/; + move16(); + hGrid->lFactor = 9830 /*0.60f Q14*/; + move16(); + BREAK; + case IGF_BITRATE_SWB_13200: + case IGF_BITRATE_FB_16400: + case IGF_BITRATE_SWB_16400: + hGrid->gFactor = 15237 /*0.93f Q14*/; + move16(); + hGrid->fFactor = 3277 /*0.20f Q14*/; + move16(); + hGrid->lFactor = 13926 /*0.85f Q14*/; + move16(); + BREAK; + case IGF_BITRATE_FB_24400: + case IGF_BITRATE_SWB_24400: + case IGF_BITRATE_FB_32000: + case IGF_BITRATE_SWB_32000: + hGrid->gFactor = 15811 /*0.965f Q14*/; + move16(); + hGrid->fFactor = 3277 /*0.20f Q14*/; + move16(); + hGrid->lFactor = 13926 /*0.85f Q14*/; + move16(); + BREAK; + case IGF_BITRATE_FB_48000: + case IGF_BITRATE_SWB_48000: + hGrid->gFactor = 16384 /*1.00f Q14*/; + move16(); + hGrid->fFactor = 3277 /*0.20f Q14*/; + move16(); + hGrid->lFactor = 16384 /*1.00f Q14*/; + move16(); + BREAK; + case IGF_BITRATE_SWB_9600: + case IGF_BITRATE_RF_SWB_13200: + default: + hGrid->gFactor = 16384 /*1.00f Q14*/; + move16(); + hGrid->fFactor = 0 /*0.00f Q14*/; + move16(); + hGrid->lFactor = 16384 /*1.00f Q14*/; + move16(); } - FOR (t = add(hGrid->nTiles, 1); t < IGF_MAX_TILES; t++) + FOR( t = add( hGrid->nTiles, 1 ); t < IGF_MAX_TILES; t++ ) { - hGrid->tile[t] = 0; + hGrid->tile[t] = 0; move16(); hGrid->sbWrap[t - 1] = 0; move16(); - hGrid->sfbWrap[t] = 0; + hGrid->sfbWrap[t] = 0; move16(); } - } #ifdef IVAS_FLOAT_FIXED static void IGF_gridSetUp_ivas_fx( @@ -1015,7 +1014,7 @@ static void IGF_gridSetUp_ivas_fx( move16(); } - FOR ( t = add(hGrid->nTiles , 1); t < IGF_MAX_TILES; t++ ) + FOR( t = add( hGrid->nTiles, 1 ); t < IGF_MAX_TILES; t++ ) { hGrid->tile[t] = 0; move16(); @@ -1032,17 +1031,17 @@ static void IGF_gridSetUp_ivas_fx( /**********************************************************************/ /* calculates energy per sfb via power spectrum **************************************************************************/ -void IGFCommonFuncsCalcSfbEnergyPowerSpec(const Word16 startSfb, /**< in: Q0 | start sfb index */ - const Word16 stopSfb, /**< in: Q0 | stop sfb index */ - const Word16 *swb_offset, /**< in: Q0 | IGF swb offset table */ - Word32 *pPowerSpectrum, /**< in: Q31 | power spectrum */ - Word16 *pPowerSpectrum_exp, /**< in: | Exponent of PowerSpectrum */ - Word32 *sfbEnergy, /**< out:Q31 | SFB energies , will be initialized inside this function */ - Word16 *sfbEnergy_exp /**< out: | Exponent of PowerSpectrum */ - ) +void IGFCommonFuncsCalcSfbEnergyPowerSpec( const Word16 startSfb, /**< in: Q0 | start sfb index */ + const Word16 stopSfb, /**< in: Q0 | stop sfb index */ + const Word16 *swb_offset, /**< in: Q0 | IGF swb offset table */ + Word32 *pPowerSpectrum, /**< in: Q31 | power spectrum */ + Word16 *pPowerSpectrum_exp, /**< in: | Exponent of PowerSpectrum */ + Word32 *sfbEnergy, /**< out:Q31 | SFB energies , will be initialized inside this function */ + Word16 *sfbEnergy_exp /**< out: | Exponent of PowerSpectrum */ +) { - Word16/*Q0*/ sfb; - Word16/*Q0*/ line; + Word16 /*Q0*/ sfb; + Word16 /*Q0*/ line; Word32 L_c; #ifdef BASOP_NOGLOB_DECLARE_LOCAL @@ -1050,37 +1049,37 @@ void IGFCommonFuncsCalcSfbEnergyPowerSpec(const Word16 startSfb, Flag Carry = 0; #endif - FOR (sfb = startSfb; sfb < stopSfb; sfb++) + FOR( sfb = startSfb; sfb < stopSfb; sfb++ ) { - sfbEnergy[sfb] = L_deposit_l(0); + sfbEnergy[sfb] = L_deposit_l( 0 ); } - IF (NULL == pPowerSpectrum) + IF( NULL == pPowerSpectrum ) { return; } - FOR (sfb = startSfb; sfb < stopSfb; sfb++) + FOR( sfb = startSfb; sfb < stopSfb; sfb++ ) { - L_c = L_deposit_l(0); - FOR (line = swb_offset[sfb]; line < swb_offset[sfb+1]; line++) + L_c = L_deposit_l( 0 ); + FOR( line = swb_offset[sfb]; line < swb_offset[sfb + 1]; line++ ) { Carry = 0; #ifdef BASOP_NOGLOB - sfbEnergy[sfb] = L_add_co(sfbEnergy[sfb], pPowerSpectrum[line], &Carry, &Overflow); -#else /* BASOP_NOGLOB */ - sfbEnergy[sfb] = L_add_c(sfbEnergy[sfb], pPowerSpectrum[line]); + sfbEnergy[sfb] = L_add_co( sfbEnergy[sfb], pPowerSpectrum[line], &Carry, &Overflow ); +#else /* BASOP_NOGLOB */ + sfbEnergy[sfb] = L_add_c( sfbEnergy[sfb], pPowerSpectrum[line] ); #endif /* BASOP_NOGLOB */ move32(); Overflow = 0; #ifdef BASOP_NOGLOB - L_c = L_macNs_co(L_c,0,0, &Carry, &Overflow); + L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); #else /* BASOP_NOGLOB */ - L_c = L_macNs(L_c,0,0); + L_c = L_macNs( L_c, 0, 0 ); #endif } - sfbEnergy[sfb] = norm_llQ31(L_c,sfbEnergy[sfb],&(sfbEnergy_exp[sfb])); + sfbEnergy[sfb] = norm_llQ31( L_c, sfbEnergy[sfb], &( sfbEnergy_exp[sfb] ) ); move32(); - sfbEnergy_exp[sfb] = add(sfbEnergy_exp[sfb],*pPowerSpectrum_exp); + sfbEnergy_exp[sfb] = add( sfbEnergy_exp[sfb], *pPowerSpectrum_exp ); move16(); } } @@ -1088,14 +1087,14 @@ void IGFCommonFuncsCalcSfbEnergyPowerSpec(const Word16 startSfb, /**********************************************************************/ /* calculate the MDCT square spectrum in the IGF range **************************************************************************/ -void IGFCommonFuncsMDCTSquareSpec(const Word16 sqrtBgn, /**< in: Q0 | start MDCT subband index */ - const Word16 sqrtEnd, /**< in: Q0 | stop MDCT subband index */ - const Word32 *mdctSpec, /**< in: Q31 | MDCT spectrum to square */ - const Word16 mdctSpec_e, /**< in: | exponent of mdctSpectrum */ - Word32 *mdctSquareSpec, /**< out:Q31 | MDCT square spectrum */ - Word16 *mdctSquareSpec_e, /**< out: | exponent of mdctSquareSpec */ - Word16 indexOffset /**< in: Q0 | index offset */ - ) +void IGFCommonFuncsMDCTSquareSpec( const Word16 sqrtBgn, /**< in: Q0 | start MDCT subband index */ + const Word16 sqrtEnd, /**< in: Q0 | stop MDCT subband index */ + const Word32 *mdctSpec, /**< in: Q31 | MDCT spectrum to square */ + const Word16 mdctSpec_e, /**< in: | exponent of mdctSpectrum */ + Word32 *mdctSquareSpec, /**< out:Q31 | MDCT square spectrum */ + Word16 *mdctSquareSpec_e, /**< out: | exponent of mdctSquareSpec */ + Word16 indexOffset /**< in: Q0 | index offset */ +) { Word16 i; Word16 j; @@ -1104,28 +1103,26 @@ void IGFCommonFuncsMDCTSquareSpec(const Word16 sqrtBgn, /* get headroom, only in IGF range */ - s1 = getScaleFactor32(mdctSpec + sqrtBgn, sub(sqrtEnd, sqrtBgn)); + s1 = getScaleFactor32( mdctSpec + sqrtBgn, sub( sqrtEnd, sqrtBgn ) ); /* set new exponent */ - *mdctSquareSpec_e = add(shl(sub(mdctSpec_e, s1), 1), 1); + *mdctSquareSpec_e = add( shl( sub( mdctSpec_e, s1 ), 1 ), 1 ); move16(); /* MDCT square spectrum: MDCT^2 */ - j = add(sqrtBgn, indexOffset); /* handle indexOffset with care, otherwise memory overruns may occur! */ + j = add( sqrtBgn, indexOffset ); /* handle indexOffset with care, otherwise memory overruns may occur! */ - FOR (i = sqrtBgn; i < sqrtEnd; i++) + FOR( i = sqrtBgn; i < sqrtEnd; i++ ) { #ifdef BASOP_NOGLOB tmp = round_fx_sat( L_shl_sat( mdctSpec[i], s1 ) ); #else - tmp = round_fx(L_shl(mdctSpec[i], s1)); + tmp = round_fx( L_shl( mdctSpec[i], s1 ) ); #endif - mdctSquareSpec[j++] = L_mult0(tmp, tmp); + mdctSquareSpec[j++] = L_mult0( tmp, tmp ); move32(); } - - } /**********************************************************************/ /* @@ -1170,17 +1167,17 @@ void IGFCommonFuncsMDCTSquareSpec_ivas( const Word16 sqrtBgn, /**< in write bits to stream **************************************************************************/ void IGFCommonFuncsWriteSerialBit( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - Word16 *pBitOffset, /**< out: Q0 | bit offset */ - Word16 bit /**< in: Q0 | value of bit */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 *pBitOffset, /**< out: Q0 | bit offset */ + Word16 bit /**< in: Q0 | value of bit */ ) { - IF (hBstr) + IF( hBstr ) { - push_next_indice_fx(hBstr, bit, 1); + push_next_indice_fx( hBstr, bit, 1 ); } - *pBitOffset = add(*pBitOffset, 1); + *pBitOffset = add( *pBitOffset, 1 ); move16(); return; @@ -1193,7 +1190,7 @@ Word16 IGFCommonFuncsIGFConfiguration( const Word32 total_brate, /* i : bitrate in bs e.g. 9600 for 9.6kbs */ const Word16 bwidth, /* i : audio bandwidth */ const Word16 element_mode, /* i : element mode */ - H_IGF_INFO hIGFInfo, /* o : IGF info handle */ + H_IGF_INFO hIGFInfo, /* o : IGF info handle */ const Word16 rf_mode /* i : flag to signal the RF mode */ ) { @@ -1204,31 +1201,33 @@ Word16 IGFCommonFuncsIGFConfiguration( Word16 igfMinFq; Word16 maxHopsize; - retValue = 0; /* bitrate index is unknown -> error! */ move16(); + retValue = 0; /* bitrate index is unknown -> error! */ + move16(); /* interface call for reading in settings */ - hIGFInfo->bitRateIndex = IGF_MapBitRateToIndex(total_brate, bwidth, element_mode, rf_mode); + hIGFInfo->bitRateIndex = IGF_MapBitRateToIndex( total_brate, bwidth, element_mode, rf_mode ); - IF (NE_16(hIGFInfo->bitRateIndex, IGF_BITRATE_UNKNOWN)) + IF( NE_16( hIGFInfo->bitRateIndex, IGF_BITRATE_UNKNOWN ) ) { - retValue = 1; /* no error */ move16(); + retValue = 1; /* no error */ + move16(); /* mapping to local values */ - sampleRate = igfMode[hIGFInfo->bitRateIndex].sampleRate; + sampleRate = igfMode[hIGFInfo->bitRateIndex].sampleRate; move32(); frameLength = igfMode[hIGFInfo->bitRateIndex].frameLength; move16(); - igfMinFq = igfMode[hIGFInfo->bitRateIndex].igfMinFq; + igfMinFq = igfMode[hIGFInfo->bitRateIndex].igfMinFq; move16(); - maxHopsize = igfMode[hIGFInfo->bitRateIndex].maxHopsize; + maxHopsize = igfMode[hIGFInfo->bitRateIndex].maxHopsize; move16(); /* basic information */ - hIGFInfo->sampleRate = sampleRate; + hIGFInfo->sampleRate = sampleRate; move32(); hIGFInfo->frameLength = frameLength; move16(); - hIGFInfo->maxHopsize = maxHopsize; + hIGFInfo->maxHopsize = maxHopsize; move16(); #if 0 //100820 temp fix @@ -1239,30 +1238,30 @@ Word16 IGFCommonFuncsIGFConfiguration( move16(); /* set up regular IGF grid for TCX 20 (transfac = 1.f) */ - hGrid = &hIGFInfo->grid[IGF_GRID_LB_NORM]; - IGF_gridSetUp(hGrid, - hIGFInfo->bitRateIndex, - sampleRate, - frameLength, - 16384/*1 Q14*/, - igfMinFq); + hGrid = &hIGFInfo->grid[IGF_GRID_LB_NORM]; + IGF_gridSetUp( hGrid, + hIGFInfo->bitRateIndex, + sampleRate, + frameLength, + 16384 /*1 Q14*/, + igfMinFq ); /* set up IGF grid for CELP->TCX 20 transitions (transfac = 1.25) */ - hGrid = &hIGFInfo->grid[IGF_GRID_LB_TRAN]; - IGF_gridSetUp(hGrid, - hIGFInfo->bitRateIndex, - sampleRate, - frameLength, - 20480/*1.25 Q14*/, - igfMinFq); + hGrid = &hIGFInfo->grid[IGF_GRID_LB_TRAN]; + IGF_gridSetUp( hGrid, + hIGFInfo->bitRateIndex, + sampleRate, + frameLength, + 20480 /*1.25 Q14*/, + igfMinFq ); /* set up IGF grid for TCX 10 (transfac = 0.5) */ - hGrid = &hIGFInfo->grid[IGF_GRID_LB_SHORT]; - IGF_gridSetUp(hGrid, - hIGFInfo->bitRateIndex, - sampleRate, - frameLength, - 8192/*0.50f Q14*/, - igfMinFq); + hGrid = &hIGFInfo->grid[IGF_GRID_LB_SHORT]; + IGF_gridSetUp( hGrid, + hIGFInfo->bitRateIndex, + sampleRate, + frameLength, + 8192 /*0.50f Q14*/, + igfMinFq ); } return retValue; @@ -1357,15 +1356,15 @@ Word16 IGFCommonFuncsIGFGetCFTables( const Word16 bwidth, /* i : audio bandwidth */ const Word16 element_mode, /* i : element mode */ const Word16 rf_mode, /* i : flag to signal the RF mode */ - const uint16_t** cf_se00, /* o : CF table for t == 0 and f == 0 */ - const uint16_t** cf_se01, /* o : CF table for t == 0 and f == 1 */ - Word16* cf_off_se01, /* o : offset for CF table above */ - const uint16_t** cf_se02, /* o : CF tables for t == 0 and f >= 2 */ - const Word16** cf_off_se02, /* o : offsets for CF tables above */ - const uint16_t** cf_se10, /* o : CF table for t == 1 and f == 0 */ - Word16* cf_off_se10, /* o : offset for CF table above */ - const uint16_t** cf_se11, /* o : CF tables for t == 1 and f >= 1 */ - const Word16** cf_off_se11 /* o : offsets for CF tables above */ + const uint16_t **cf_se00, /* o : CF table for t == 0 and f == 0 */ + const uint16_t **cf_se01, /* o : CF table for t == 0 and f == 1 */ + Word16 *cf_off_se01, /* o : offset for CF table above */ + const uint16_t **cf_se02, /* o : CF tables for t == 0 and f >= 2 */ + const Word16 **cf_off_se02, /* o : offsets for CF tables above */ + const uint16_t **cf_se10, /* o : CF table for t == 1 and f == 0 */ + Word16 *cf_off_se10, /* o : offset for CF table above */ + const uint16_t **cf_se11, /* o : CF tables for t == 1 and f >= 1 */ + const Word16 **cf_off_se11 /* o : offsets for CF tables above */ ) { Word16 retValue; @@ -1373,157 +1372,204 @@ Word16 IGFCommonFuncsIGFGetCFTables( retValue = 0; /* bitrate index is unknown -> error! */ - bitRateIndex = IGF_MapBitRateToIndex(total_brate, bwidth, element_mode, rf_mode); + bitRateIndex = IGF_MapBitRateToIndex( total_brate, bwidth, element_mode, rf_mode ); - IF (bitRateIndex != IGF_BITRATE_UNKNOWN) + IF( bitRateIndex != IGF_BITRATE_UNKNOWN ) { retValue = 1; /* no error */ - SWITCH (bitRateIndex) + SWITCH( bitRateIndex ) { - case IGF_BITRATE_WB_13200_CPE: - bitRateIndex = IGF_BITRATE_WB_9600; - move16(); - BREAK; - case IGF_BITRATE_WB_16400_CPE: - bitRateIndex = IGF_BITRATE_WB_9600; - move16(); - BREAK; - case IGF_BITRATE_SWB_13200_CPE: - bitRateIndex = IGF_BITRATE_SWB_9600; - move16(); - BREAK; - case IGF_BITRATE_SWB_16400_CPE: - bitRateIndex = IGF_BITRATE_SWB_13200; - move16(); - BREAK; - case IGF_BITRATE_SWB_24400_CPE: - bitRateIndex = IGF_BITRATE_SWB_16400; - move16(); - BREAK; - case IGF_BITRATE_FB_24400_CPE: - bitRateIndex = IGF_BITRATE_FB_16400; - move16(); - BREAK; - case IGF_BITRATE_SWB_32000_CPE: - bitRateIndex = IGF_BITRATE_SWB_24400; - move16(); - BREAK; - case IGF_BITRATE_FB_32000_CPE: - bitRateIndex = IGF_BITRATE_FB_24400; - move16(); - BREAK; - case IGF_BITRATE_FB_48000_CPE: - case IGF_BITRATE_FB_64000_CPE: - bitRateIndex = IGF_BITRATE_FB_32000; - move16(); - BREAK; + case IGF_BITRATE_WB_13200_CPE: + bitRateIndex = IGF_BITRATE_WB_9600; + move16(); + BREAK; + case IGF_BITRATE_WB_16400_CPE: + bitRateIndex = IGF_BITRATE_WB_9600; + move16(); + BREAK; + case IGF_BITRATE_SWB_13200_CPE: + bitRateIndex = IGF_BITRATE_SWB_9600; + move16(); + BREAK; + case IGF_BITRATE_SWB_16400_CPE: + bitRateIndex = IGF_BITRATE_SWB_13200; + move16(); + BREAK; + case IGF_BITRATE_SWB_24400_CPE: + bitRateIndex = IGF_BITRATE_SWB_16400; + move16(); + BREAK; + case IGF_BITRATE_FB_24400_CPE: + bitRateIndex = IGF_BITRATE_FB_16400; + move16(); + BREAK; + case IGF_BITRATE_SWB_32000_CPE: + bitRateIndex = IGF_BITRATE_SWB_24400; + move16(); + BREAK; + case IGF_BITRATE_FB_32000_CPE: + bitRateIndex = IGF_BITRATE_FB_24400; + move16(); + BREAK; + case IGF_BITRATE_FB_48000_CPE: + case IGF_BITRATE_FB_64000_CPE: + bitRateIndex = IGF_BITRATE_FB_32000; + move16(); + BREAK; } - switch (bitRateIndex) + switch ( bitRateIndex ) { - case IGF_BITRATE_WB_9600: - case IGF_BITRATE_RF_WB_13200: - case IGF_BITRATE_SWB_9600: - case IGF_BITRATE_SWB_13200: - case IGF_BITRATE_RF_SWB_13200: - case IGF_BITRATE_SWB_16400: - case IGF_BITRATE_SWB_24400: - case IGF_BITRATE_SWB_32000: - case IGF_BITRATE_SWB_48000: - case IGF_BITRATE_SWB_64000: - *cf_se00 = cf_se00_tab; - *cf_se01 = cf_se01_tab[bitRateIndex]; - *cf_off_se01 = cf_off_se01_tab[bitRateIndex]; - *cf_se02 = &cf_se02_tab[bitRateIndex][0][0]; - *cf_off_se02 = &cf_off_se02_tab[bitRateIndex][0]; - *cf_se10 = &cf_se10_tab[0]; - *cf_off_se10 = cf_off_se10_tab; - *cf_se11 = &cf_se11_tab[0][0][0]; - *cf_off_se11 = &cf_off_se11_tab[0][0]; - move16();move16();move16();move16();move16();move16();move16();move16();move16(); + case IGF_BITRATE_WB_9600: + case IGF_BITRATE_RF_WB_13200: + case IGF_BITRATE_SWB_9600: + case IGF_BITRATE_SWB_13200: + case IGF_BITRATE_RF_SWB_13200: + case IGF_BITRATE_SWB_16400: + case IGF_BITRATE_SWB_24400: + case IGF_BITRATE_SWB_32000: + case IGF_BITRATE_SWB_48000: + case IGF_BITRATE_SWB_64000: + *cf_se00 = cf_se00_tab; + *cf_se01 = cf_se01_tab[bitRateIndex]; + *cf_off_se01 = cf_off_se01_tab[bitRateIndex]; + *cf_se02 = &cf_se02_tab[bitRateIndex][0][0]; + *cf_off_se02 = &cf_off_se02_tab[bitRateIndex][0]; + *cf_se10 = &cf_se10_tab[0]; + *cf_off_se10 = cf_off_se10_tab; + *cf_se11 = &cf_se11_tab[0][0][0]; + *cf_off_se11 = &cf_off_se11_tab[0][0]; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); - BREAK; - case IGF_BITRATE_FB_16400: - case IGF_BITRATE_FB_24400: - case IGF_BITRATE_FB_32000: - bitRateIndex = bitRateIndex - IGF_BITRATE_FB_16400 + IGF_BITRATE_SWB_16400; - *cf_se00 = cf_se00_tab; - *cf_se01 = cf_se01_tab[bitRateIndex]; - *cf_off_se01 = cf_off_se01_tab[bitRateIndex]; - *cf_se02 = &cf_se02_tab[bitRateIndex][0][0]; - *cf_off_se02 = &cf_off_se02_tab[bitRateIndex][0]; - *cf_se10 = &cf_se10_tab[0]; - *cf_off_se10 = cf_off_se10_tab; - *cf_se11 = &cf_se11_tab[0][0][0]; - *cf_off_se11 = &cf_off_se11_tab[0][0]; - move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); - BREAK; - case IGF_BITRATE_FB_48000: - case IGF_BITRATE_FB_64000: - bitRateIndex = bitRateIndex - IGF_BITRATE_FB_48000 + IGF_BITRATE_SWB_48000; - *cf_se00 = cf_se00_tab; - *cf_se01 = cf_se01_tab[bitRateIndex]; - *cf_off_se01 = cf_off_se01_tab[bitRateIndex]; - *cf_se02 = &cf_se02_tab[bitRateIndex][0][0]; - *cf_off_se02 = &cf_off_se02_tab[bitRateIndex][0]; - *cf_se10 = &cf_se10_tab[0]; - *cf_off_se10 = cf_off_se10_tab; - *cf_se11 = &cf_se11_tab[0][0][0]; - *cf_off_se11 = &cf_off_se11_tab[0][0]; - move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); - BREAK; - case IGF_BITRATE_FB_96000: - case IGF_BITRATE_FB_128000: - case IGF_BITRATE_FB_80000_CPE: - case IGF_BITRATE_FB_96000_CPE: - case IGF_BITRATE_FB_128000_CPE: - bitRateIndex = IGF_BITRATE_SWB_48000; - *cf_se00 = cf_se00_tab; - *cf_se01 = cf_se01_tab[bitRateIndex]; - *cf_off_se01 = cf_off_se01_tab[bitRateIndex]; - *cf_se02 = &cf_se02_tab[bitRateIndex][0][0]; - *cf_off_se02 = &cf_off_se02_tab[bitRateIndex][0]; - *cf_se10 = &cf_se10_tab[0]; - *cf_off_se10 = cf_off_se10_tab; - *cf_se11 = &cf_se11_tab[0][0][0]; - *cf_off_se11 = &cf_off_se11_tab[0][0]; - move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); - BREAK; - case IGF_BITRATE_SWB_48000_CPE: - bitRateIndex = IGF_BITRATE_SWB_16400; - *cf_se00 = cf_se00_tab; - *cf_se01 = cf_se01_tab[bitRateIndex]; - *cf_off_se01 = cf_off_se01_tab[bitRateIndex]; - *cf_se02 = &cf_se02_tab[bitRateIndex][0][0]; - *cf_off_se02 = &cf_off_se02_tab[bitRateIndex][0]; - *cf_se10 = &cf_se10_tab[0]; - *cf_off_se10 = cf_off_se10_tab; - *cf_se11 = &cf_se11_tab[0][0][0]; - *cf_off_se11 = &cf_off_se11_tab[0][0]; - move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); - BREAK; - case IGF_BITRATE_SWB_64000_CPE: - case IGF_BITRATE_SWB_80000_CPE: - case IGF_BITRATE_SWB_96000_CPE: - bitRateIndex = IGF_BITRATE_SWB_48000; /*bitRateIndex-IGF_BITRATE_SWB_56000+IGF_BITRATE_SWB_48000;*/ - *cf_se00 = cf_se00_tab; - *cf_se01 = cf_se01_tab[bitRateIndex]; - *cf_off_se01 = cf_off_se01_tab[bitRateIndex]; - *cf_se02 = &cf_se02_tab[bitRateIndex][0][0]; - *cf_off_se02 = &cf_off_se02_tab[bitRateIndex][0]; - *cf_se10 = &cf_se10_tab[0]; - *cf_off_se10 = cf_off_se10_tab; - *cf_se11 = &cf_se11_tab[0][0][0]; - *cf_off_se11 = &cf_off_se11_tab[0][0]; - move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); - BREAK; - case IGF_BITRATE_UNKNOWN: - default: - assert(0); + BREAK; + case IGF_BITRATE_FB_16400: + case IGF_BITRATE_FB_24400: + case IGF_BITRATE_FB_32000: + bitRateIndex = bitRateIndex - IGF_BITRATE_FB_16400 + IGF_BITRATE_SWB_16400; + *cf_se00 = cf_se00_tab; + *cf_se01 = cf_se01_tab[bitRateIndex]; + *cf_off_se01 = cf_off_se01_tab[bitRateIndex]; + *cf_se02 = &cf_se02_tab[bitRateIndex][0][0]; + *cf_off_se02 = &cf_off_se02_tab[bitRateIndex][0]; + *cf_se10 = &cf_se10_tab[0]; + *cf_off_se10 = cf_off_se10_tab; + *cf_se11 = &cf_se11_tab[0][0][0]; + *cf_off_se11 = &cf_off_se11_tab[0][0]; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + BREAK; + case IGF_BITRATE_FB_48000: + case IGF_BITRATE_FB_64000: + bitRateIndex = bitRateIndex - IGF_BITRATE_FB_48000 + IGF_BITRATE_SWB_48000; + *cf_se00 = cf_se00_tab; + *cf_se01 = cf_se01_tab[bitRateIndex]; + *cf_off_se01 = cf_off_se01_tab[bitRateIndex]; + *cf_se02 = &cf_se02_tab[bitRateIndex][0][0]; + *cf_off_se02 = &cf_off_se02_tab[bitRateIndex][0]; + *cf_se10 = &cf_se10_tab[0]; + *cf_off_se10 = cf_off_se10_tab; + *cf_se11 = &cf_se11_tab[0][0][0]; + *cf_off_se11 = &cf_off_se11_tab[0][0]; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + BREAK; + case IGF_BITRATE_FB_96000: + case IGF_BITRATE_FB_128000: + case IGF_BITRATE_FB_80000_CPE: + case IGF_BITRATE_FB_96000_CPE: + case IGF_BITRATE_FB_128000_CPE: + bitRateIndex = IGF_BITRATE_SWB_48000; + *cf_se00 = cf_se00_tab; + *cf_se01 = cf_se01_tab[bitRateIndex]; + *cf_off_se01 = cf_off_se01_tab[bitRateIndex]; + *cf_se02 = &cf_se02_tab[bitRateIndex][0][0]; + *cf_off_se02 = &cf_off_se02_tab[bitRateIndex][0]; + *cf_se10 = &cf_se10_tab[0]; + *cf_off_se10 = cf_off_se10_tab; + *cf_se11 = &cf_se11_tab[0][0][0]; + *cf_off_se11 = &cf_off_se11_tab[0][0]; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + BREAK; + case IGF_BITRATE_SWB_48000_CPE: + bitRateIndex = IGF_BITRATE_SWB_16400; + *cf_se00 = cf_se00_tab; + *cf_se01 = cf_se01_tab[bitRateIndex]; + *cf_off_se01 = cf_off_se01_tab[bitRateIndex]; + *cf_se02 = &cf_se02_tab[bitRateIndex][0][0]; + *cf_off_se02 = &cf_off_se02_tab[bitRateIndex][0]; + *cf_se10 = &cf_se10_tab[0]; + *cf_off_se10 = cf_off_se10_tab; + *cf_se11 = &cf_se11_tab[0][0][0]; + *cf_off_se11 = &cf_off_se11_tab[0][0]; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + BREAK; + case IGF_BITRATE_SWB_64000_CPE: + case IGF_BITRATE_SWB_80000_CPE: + case IGF_BITRATE_SWB_96000_CPE: + bitRateIndex = IGF_BITRATE_SWB_48000; /*bitRateIndex-IGF_BITRATE_SWB_56000+IGF_BITRATE_SWB_48000;*/ + *cf_se00 = cf_se00_tab; + *cf_se01 = cf_se01_tab[bitRateIndex]; + *cf_off_se01 = cf_off_se01_tab[bitRateIndex]; + *cf_se02 = &cf_se02_tab[bitRateIndex][0][0]; + *cf_off_se02 = &cf_off_se02_tab[bitRateIndex][0]; + *cf_se10 = &cf_se10_tab[0]; + *cf_off_se10 = cf_off_se10_tab; + *cf_se11 = &cf_se11_tab[0][0][0]; + *cf_off_se11 = &cf_off_se11_tab[0][0]; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + BREAK; + case IGF_BITRATE_UNKNOWN: + default: + assert( 0 ); } } return retValue; } - diff --git a/lib_com/index_pvq_opt_fx.c b/lib_com/index_pvq_opt_fx.c index fae04e953..713c2afb0 100644 --- a/lib_com/index_pvq_opt_fx.c +++ b/lib_com/index_pvq_opt_fx.c @@ -5,27 +5,27 @@ #include #include #include "options.h" -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ #include "prot_fx1.h" #include "prot_fx2.h" #include "basop_util.h" -#define N_OPT_FX 5 /* complexity setting, direct functional calculation limit & low dim recursion limit */ -#define TABLE_LIM_OPT_FX 96 /* odd divisor table , N-row_recursion limit setting, due to dim */ +#define N_OPT_FX 5 /* complexity setting, direct functional calculation limit & low dim recursion limit */ +#define TABLE_LIM_OPT_FX 96 /* odd divisor table , N-row_recursion limit setting, due to dim */ /* local typedefs for optimized pvq indexing, used locally c-file to vectorize common function calls */ -typedef void (*VEC2INDFUNCM) (const Word16* , Word16* , UWord32*, UWord32*); -typedef UWord32 (*NFUNCM) (Word16); -typedef UWord32 (*H_FUNCM) ( UWord32 ); -typedef void (*IND2VECFUNCM) ( Word16, Word16, UWord32, Word16* ) ; -typedef void (*NDIM_FUNCM) ( Word16, Word16, UWord32, Word16* ); +typedef void ( *VEC2INDFUNCM )( const Word16 *, Word16 *, UWord32 *, UWord32 * ); +typedef UWord32 ( *NFUNCM )( Word16 ); +typedef UWord32 ( *H_FUNCM )( UWord32 ); +typedef void ( *IND2VECFUNCM )( Word16, Word16, UWord32, Word16 * ); +typedef void ( *NDIM_FUNCM )( Word16, Word16, UWord32, Word16 * ); /* local constants for indexing functions */ -#define SIGNBIT_FX 0x80000000u -#define SIGNBIT_SHRT_FX 0x8000 -#define UDIVBY3_FX 2863311531U +#define SIGNBIT_FX 0x80000000u +#define SIGNBIT_SHRT_FX 0x8000 +#define UDIVBY3_FX 2863311531U /*-------------------------------------------------------------------* * f_odd_exact_div_opt_fx() @@ -33,18 +33,18 @@ typedef void (*NDIM_FUNCM) ( Word16, Word16, UWord32, Word16* ); * find 1/(den1*2+1) * ( num1p*num2p - num3) , * if the result is known a priori to be exactly a 32bit UWord32 *-------------------------------------------------------------------*/ -static -UWord32 f_odd_exact_div_opt_fx( /* o : see Eq. */ - UWord32 num1p, /* i : see Eq. */ /* (2n-1) or n , i.e can be short also */ - UWord32 num2p, /* i : see Eq. */ - UWord32 num3, /* i : see Eq. */ - Word16 den1 /* i : see Eq. */ /*range [0..127] can be made to short */ +static UWord32 f_odd_exact_div_opt_fx( /* o : see Eq. */ + UWord32 num1p, + /* i : see Eq. */ /* (2n-1) or n , i.e can be short also */ + UWord32 num2p, /* i : see Eq. */ + UWord32 num3, /* i : see Eq. */ + Word16 den1 /* i : see Eq. */ /*range [0..127] can be made to short */ ) { UWord32 UL_tmp; - UL_tmp = UL_Mpy_32_32(exactdivodd[den1],UL_subNsD(UL_Mpy_32_32(num1p,num2p),num3)); + UL_tmp = UL_Mpy_32_32( exactdivodd[den1], UL_subNsD( UL_Mpy_32_32( num1p, num2p ), num3 ) ); - return (UL_tmp); + return ( UL_tmp ); } /*---------------------------------------------------------------------------* @@ -53,38 +53,37 @@ UWord32 f_odd_exact_div_opt_fx( /* o : see Eq. */ * returns (num1p*num2p - num3 )/ den1 * if the result is known a priori to be exactly a 32bit unsigned integer *--------------------------------------------------------------------------*/ -static -UWord32 f_even_exact_div_opt_fx( /* o : see Eq. */ - UWord32 UL_num1p, /* i : see Eq. 2n-1 or n can be short input */ - UWord32 UL_num2p, /* i : see Eq. range should be larger than num1p */ - UWord32 UL_num3, /* i : see Eq. */ - Word16 den1 /* i : see Eq. */ +static UWord32 f_even_exact_div_opt_fx( /* o : see Eq. */ + UWord32 UL_num1p, /* i : see Eq. 2n-1 or n can be short input */ + UWord32 UL_num2p, /* i : see Eq. range should be larger than num1p */ + UWord32 UL_num3, /* i : see Eq. */ + Word16 den1 /* i : see Eq. */ ) { - UWord32 UL_tmp, UL_oddfactor; - Word16 den1_m1, even_sh; + UWord32 UL_tmp, UL_oddfactor; + Word16 den1_m1, even_sh; UWord32 UL_tmp_h; UWord16 sgn; - den1_m1 = sub(den1,1); /* remove top bit */ - even_sh = sub(15, norm_s(s_xor(den1_m1, den1))); /* STL signed ops ok as den1 <= 127 */ + den1_m1 = sub( den1, 1 ); /* remove top bit */ + even_sh = sub( 15, norm_s( s_xor( den1_m1, den1 ) ) ); /* STL signed ops ok as den1 <= 127 */ - UL_oddfactor = exactdivodd[lshr(den1_m1,even_sh)]; + UL_oddfactor = exactdivodd[lshr( den1_m1, even_sh )]; move32(); - even_sh = sub(even_sh,1); + even_sh = sub( even_sh, 1 ); - Mpy_32_32_uu(UL_num1p, UL_num2p, &UL_tmp_h, &UL_tmp); /* cost ~4 */ - UL_tmp = UL_subNs(UL_tmp,UL_num3,&sgn); /* may wrap for underflow */ - if(sgn) /* underflow */ + Mpy_32_32_uu( UL_num1p, UL_num2p, &UL_tmp_h, &UL_tmp ); /* cost ~4 */ + UL_tmp = UL_subNs( UL_tmp, UL_num3, &sgn ); /* may wrap for underflow */ + if ( sgn ) /* underflow */ { - UL_tmp_h = UL_subNsD(UL_tmp_h,1U); /* single basicop -> if */ + UL_tmp_h = UL_subNsD( UL_tmp_h, 1U ); /* single basicop -> if */ } - UL_tmp = UL_or(UL_lshl(UL_tmp_h,sub(32,even_sh)), UL_lshr(UL_tmp,even_sh)); + UL_tmp = UL_or( UL_lshl( UL_tmp_h, sub( 32, even_sh ) ), UL_lshr( UL_tmp, even_sh ) ); /* total cost 9-11 , old solution had 15-16*/ /* now use tabled modular multiplicative inverse for the odd part division */ - return UL_Mpy_32_32(UL_tmp, UL_oddfactor); + return UL_Mpy_32_32( UL_tmp, UL_oddfactor ); } /* direct calculation functions for smaller dimensions to speed up indexing @@ -124,15 +123,14 @@ U(n,k) = 1 + A(n-1,k-1)>>1 + A(n-1,k)>>1 + A(n,k-1)>>1; A(n,k) is always odd /*-------------------------------------------------------------------* * a_three_fx() *-------------------------------------------------------------------*/ -static -UWord32 a_three_fx( /* o: offset for dim 3 */ - UWord32 k_val /* i: nb unit pulses */ -) /* k_val may be higher than 16 bit signed */ +static UWord32 a_three_fx( /* o: offset for dim 3 */ + UWord32 k_val /* i: nb unit pulses */ + ) /* k_val may be higher than 16 bit signed */ { IF( k_val ) { /* return (ONE_U + k_val*((k_val - ONE_U) << ONE)); */ - return UL_addNsD(1U,UL_Mpy_32_32(k_val,UL_lshl(UL_subNsD(k_val,1U),1))); + return UL_addNsD( 1U, UL_Mpy_32_32( k_val, UL_lshl( UL_subNsD( k_val, 1U ), 1 ) ) ); } ELSE { @@ -143,18 +141,17 @@ UWord32 a_three_fx( /* o: offset for dim 3 */ /*-------------------------------------------------------------------* * a_four_fx() *-------------------------------------------------------------------*/ -static -UWord32 a_four_fx( /* o: offset for dim 4 */ - UWord32 k_val /* i: nb unit pulses */ +static UWord32 a_four_fx( /* o: offset for dim 4 */ + UWord32 k_val /* i: nb unit pulses */ ) { UWord32 UL_2k; - IF(k_val) + IF( k_val ) { /* return UDIVBY3*((k_val<0,k=0) */ - h_mem[1] = UL_deposit_l(1); /* A(*,k=1) */ + h_mem[0] = UL_deposit_l( 0 ); /* A(=>0,k=0) */ + h_mem[1] = UL_deposit_l( 1 ); /* A(*,k=1) */ - UL_k_val_in = UL_deposit_l(k_val_in); - IF(EQ_16(dim_in,2)) + UL_k_val_in = UL_deposit_l( k_val_in ); + IF( EQ_16( dim_in, 2 ) ) { - FOR( k_val = 2 ; k_val <= UL_k_val_in ; k_val++ ) + FOR( k_val = 2; k_val <= UL_k_val_in; k_val++ ) { - h_mem[k_val] = UL_subNsD(UL_lshl(k_val,1),1U); - move32(); /* A(2, 2 .. k ) */ + h_mem[k_val] = UL_subNsD( UL_lshl( k_val, 1 ), 1U ); + move32(); /* A(2, 2 .. k ) */ } - h_mem[k_val] = UL_k_val_in; - move32(); /* U(2,k+1) */ + h_mem[k_val] = UL_k_val_in; + move32(); /* U(2,k+1) */ } ELSE { - k_val_prev = UL_deposit_l(1U); - FOR(k_val_curr = 2; k_val_curr<=UL_k_val_in; k_val_curr++) + k_val_prev = UL_deposit_l( 1U ); + FOR( k_val_curr = 2; k_val_curr <= UL_k_val_in; k_val_curr++ ) { - h_mem[k_val_curr] = UL_addNsD(1U , UL_Mpy_32_32(k_val_curr, UL_lshl(k_val_prev,1))); + h_mem[k_val_curr] = UL_addNsD( 1U, UL_Mpy_32_32( k_val_curr, UL_lshl( k_val_prev, 1 ) ) ); move32(); - k_val_prev = UL_addNsD(k_val_curr, 0U); /* 1 op*/ + k_val_prev = UL_addNsD( k_val_curr, 0U ); /* 1 op*/ } - h_mem[k_val_curr] = UL_Mpy_32_32(k_val_curr,k_val_prev); - move32(); /* % U(3,k_val_in+1) u_three(k+1) */ + h_mem[k_val_curr] = UL_Mpy_32_32( k_val_curr, k_val_prev ); + move32(); /* % U(3,k_val_in+1) u_three(k+1) */ } return; @@ -268,27 +260,26 @@ void initOffsets_fx( Word16 dim_in , UWord32* h_mem, Word16 k_val_in) * * create offsets for A(n,k) from lower A(n-1,k) *-------------------------------------------------------------------*/ -static -void a_fwd_fx( - UWord32 *a_in, /* i/o: offsets */ - Word16 n_items /* i : items, k's */ +static void a_fwd_fx( + UWord32 *a_in, /* i/o: offsets */ + Word16 n_items /* i : items, k's */ ) { - UWord32 a_1, a_in0 ; - Word16 i ; - UWord32* a_in_prev_ptr; + UWord32 a_1, a_in0; + Word16 i; + UWord32 *a_in_prev_ptr; - a_in0 = UL_deposit_l(1); + a_in0 = UL_deposit_l( 1 ); - a_in_prev_ptr=&(a_in[-1]); /* single loop ptr setup not counted; */ - FOR(i=1; i<=n_items; i++) /* basic A fwd row recursion */ + a_in_prev_ptr = &( a_in[-1] ); /* single loop ptr setup not counted; */ + FOR( i = 1; i <= n_items; i++ ) /* basic A fwd row recursion */ { - a_1 = UL_addNsD(a_in0, UL_addNsD(a_in_prev_ptr[i], a_in[i])) ; + a_1 = UL_addNsD( a_in0, UL_addNsD( a_in_prev_ptr[i], a_in[i] ) ); a_in_prev_ptr[i] = a_in0; move32(); - a_in0 = UL_addNsD(a_1, 0U); + a_in0 = UL_addNsD( a_1, 0U ); } - a_in_prev_ptr[i] = a_in0; + a_in_prev_ptr[i] = a_in0; move32(); return; } @@ -298,72 +289,68 @@ void a_fwd_fx( * * create offsets for A(n,k) from higher A(n+1,k) *-------------------------------------------------------------------*/ -static -void a_bwd_fx( - UWord32 *a_in, /* i/o: offsets */ - Word16 n_items /* i: n_items */ +static void a_bwd_fx( + UWord32 *a_in, /* i/o: offsets */ + Word16 n_items /* i: n_items */ ) { - UWord32 a_1, a_in0; - Word16 i; - UWord32* a_in_prev_ptr; + UWord32 a_1, a_in0; + Word16 i; + UWord32 *a_in_prev_ptr; - a_in0 = UL_deposit_l(0); - a_in_prev_ptr = &(a_in[-1]); + a_in0 = UL_deposit_l( 0 ); + a_in_prev_ptr = &( a_in[-1] ); - FOR(i = 1; i<=n_items; i++) /*basic A reverse row recursion */ + FOR( i = 1; i <= n_items; i++ ) /*basic A reverse row recursion */ { /* 2x[i] ptr memory access below are treated as ptr access */ - a_1 = UL_subNsD(UL_subNsD(a_in[i], a_in0), a_in_prev_ptr[i]); + a_1 = UL_subNsD( UL_subNsD( a_in[i], a_in0 ), a_in_prev_ptr[i] ); a_in_prev_ptr[i] = a_in0; move32(); - a_in0 = UL_addNsD(a_1, 0U); - + a_in0 = UL_addNsD( a_1, 0U ); } - a_in_prev_ptr[i] = a_in0; + a_in_prev_ptr[i] = a_in0; move32(); return; } -static -UWord32 direct_row_A2U_rec_calc_fx(Word16 dim_in , Word16 k_val_in, UWord32 a_km2, UWord32 a_km1) +static UWord32 direct_row_A2U_rec_calc_fx( Word16 dim_in, Word16 k_val_in, UWord32 a_km2, UWord32 a_km1 ) { /* U(n,k) = (A(n,k-2)-1)/2 + ((2*n-1)*A(n,k-1) - A(n,k-2) )/2*(k-1) */ /* U(n,k) = floor(A(n,k-2)/2) + (n*A(n,k-1) - floor(A(n,k-1)/2) - floor(A(n,k-2)/2) +1 )/(k-1) */ /* U(n,k) = floor(A(n,k-2)/2) + (n*A(n,k-1) - (floor(A(n,k-1)/2) + floor(A(n,k-2)/2) +1) )/(k-1) */ - UWord32 km2_size, UL_um2, UL_dim ; - Word16 divisor; + UWord32 km2_size, UL_um2, UL_dim; + Word16 divisor; - divisor = sub(k_val_in,1); - UL_um2 = UL_lshr(a_km2,1U); - UL_dim = UL_deposit_l(dim_in); - km2_size = UL_addNsD(UL_addNsD(UL_lshr(a_km1,1), UL_um2), 1U); - IF(s_and(divisor,0x1) != 0) + divisor = sub( k_val_in, 1 ); + UL_um2 = UL_lshr( a_km2, 1U ); + UL_dim = UL_deposit_l( dim_in ); + km2_size = UL_addNsD( UL_addNsD( UL_lshr( a_km1, 1 ), UL_um2 ), 1U ); + IF( s_and( divisor, 0x1 ) != 0 ) { /* odd */ - return UL_addNsD(UL_um2, f_odd_exact_div_opt_fx( UL_dim, a_km1, km2_size, shr(divisor,1))); + return UL_addNsD( UL_um2, f_odd_exact_div_opt_fx( UL_dim, a_km1, km2_size, shr( divisor, 1 ) ) ); } ELSE { /* even divisor, */ - return UL_addNsD(UL_um2, f_even_exact_div_opt_fx(UL_dim, a_km1, km2_size, divisor)); + return UL_addNsD( UL_um2, f_even_exact_div_opt_fx( UL_dim, a_km1, km2_size, divisor ) ); } } -static -void a_u_fwd_fx(UWord32 *a_u_in, - Word16 k_val_in, - Word16 mem_size_m1) +static void a_u_fwd_fx( UWord32 *a_u_in, + Word16 k_val_in, + Word16 mem_size_m1 ) { UWord32 u_kp1_prev, u_kp1; - UWord32 u_k_prev ; + UWord32 u_k_prev; u_kp1_prev = a_u_in[mem_size_m1]; - move32(); /* previous n U (n,k+1) value*/ - u_k_prev = UL_lshr(a_u_in[k_val_in],1); /* previous n A(n,k) value*/ + move32(); /* previous n U (n,k+1) value*/ + u_k_prev = UL_lshr( a_u_in[k_val_in], 1 ); /* previous n A(n,k) value*/ - a_fwd_fx(&a_u_in[1], k_val_in); /* a_u_in[k==ZERO] = zero if n>0 */ + a_fwd_fx( &a_u_in[1], k_val_in ); /* a_u_in[k==ZERO] = zero if n>0 */ /* low dynamic last offset entry mixed recursion */ /* used for size calculation */ @@ -371,8 +358,8 @@ void a_u_fwd_fx(UWord32 *a_u_in, /* U(n,k+1) = 1 + U(n-1,k+1) + (A(n-1,k)-1)/2 + (A(n,k)-1)/2 */ /* Note, A(n,k) always odd for k>0 , subtracted one always shifted out */ - u_kp1 = UL_lshr(a_u_in[k_val_in],1); - a_u_in[mem_size_m1] = UL_addNsD(1U, UL_addNsD(u_kp1_prev, UL_addNsD(u_k_prev,u_kp1))); + u_kp1 = UL_lshr( a_u_in[k_val_in], 1 ); + a_u_in[mem_size_m1] = UL_addNsD( 1U, UL_addNsD( u_kp1_prev, UL_addNsD( u_k_prev, u_kp1 ) ) ); return; } @@ -381,115 +368,114 @@ void a_u_fwd_fx(UWord32 *a_u_in, * * find and return N_MPVQ(n,k) and also offsets A(n, 0 to k ) and U(n,k+1). *-------------------------------------------------------------------*/ -static -UWord32 nm_h_prep_opt_fx( /* o: msize for dim */ - Word16 dim_in, /* i: dimension */ - Word16 k_val_in, /* i: nb unit pulses */ - UWord32 *h /* o: A/U offsets array */ +static UWord32 nm_h_prep_opt_fx( /* o: msize for dim */ + Word16 dim_in, /* i: dimension */ + Word16 k_val_in, /* i: nb unit pulses */ + UWord32 *h /* o: A/U offsets array */ ) { - Word16 mem_size_m1, k_val,tmp ; + Word16 mem_size_m1, k_val, tmp; Word16 dim_tmp, d_start; - UWord32 h_saveA, h_saveB, u_kp1,a_k; /* registers for alternating A(n,k-1), A(n,k-2)*/ + UWord32 h_saveA, h_saveB, u_kp1, a_k; /* registers for alternating A(n,k-1), A(n,k-2)*/ UWord32 numDsub1; - Word16 end_loop, add_last_odd ; + Word16 end_loop, add_last_odd; - h[0] = UL_deposit_l(0); /* % A(=>0,k=0) */ - h[1] = UL_deposit_l(1); /* % A(*,k=1) */ + h[0] = UL_deposit_l( 0 ); /* % A(=>0,k=0) */ + h[1] = UL_deposit_l( 1 ); /* % A(*,k=1) */ - mem_size_m1 = add(k_val_in,1); + mem_size_m1 = add( k_val_in, 1 ); - assert(dim_in > N_OPT_FX); /* code now optimized with direct functions for dim <= N_OPT_FX ) */ - IF( (GT_16(k_val_in, TABLE_LIM_OPT_FX))) + assert( dim_in > N_OPT_FX ); /* code now optimized with direct functions for dim <= N_OPT_FX ) */ + IF( ( GT_16( k_val_in, TABLE_LIM_OPT_FX ) ) ) { d_start = 2; move16(); - if( GE_16(dim_in,3)) + if ( GE_16( dim_in, 3 ) ) { /* start from A(3), U(3) */ d_start = 3; - move16(); /* single op */ + move16(); /* single op */ } - initOffsets_fx(d_start, h, k_val_in); - FOR(dim_tmp = d_start; dim_tmp < dim_in; dim_tmp++) + initOffsets_fx( d_start, h, k_val_in ); + FOR( dim_tmp = d_start; dim_tmp < dim_in; dim_tmp++ ) { - a_u_fwd_fx(h, k_val_in, mem_size_m1); + a_u_fwd_fx( h, k_val_in, mem_size_m1 ); } - a_k = h[k_val_in]; + a_k = h[k_val_in]; move32(); - u_kp1 = h[mem_size_m1]; + u_kp1 = h[mem_size_m1]; move32(); } ELSE { - numDsub1 = UL_deposit_l(sub(shl(dim_in,1),1)); - h[2] = numDsub1; + numDsub1 = UL_deposit_l( sub( shl( dim_in, 1 ), 1 ) ); + h[2] = numDsub1; move32(); /* interleaved " odd, even [odd]" divisor calls */ - h_saveA = numDsub1; + h_saveA = numDsub1; move32(); - h_saveB = UL_deposit_l(1); + h_saveB = UL_deposit_l( 1 ); /* OPT: makes sure that the STL FOR loop is not broken */ - tmp = sub(k_val_in,3); - add_last_odd = 0; - move16() ; /*k_val_in=0 1 2*/ - if(tmp == 0) + tmp = sub( k_val_in, 3 ); + add_last_odd = 0; + move16(); /*k_val_in=0 1 2*/ + if ( tmp == 0 ) { add_last_odd = 1; - move16(); /*k_val_in =3 */ + move16(); /*k_val_in =3 */ } - k_val = 3; + k_val = 3; move16(); - IF( tmp > 0 ) + IF( tmp > 0 ) { /* k_val_in = 3,4, 5,6, 7 ... */ - end_loop = mem_size_m1; + end_loop = mem_size_m1; move16(); - add_last_odd = s_and(k_val_in,0x1) ; - move16(); /* odd -> 0x00100*/ + add_last_odd = s_and( k_val_in, 0x1 ); + move16(); /* odd -> 0x00100*/ /* even loop limits, and odd tail exists , and */ - if(NE_16(add_last_odd,0)) + if ( NE_16( add_last_odd, 0 ) ) { - end_loop = sub(end_loop,1); /* make initial loop to even number of (odd-even )pairs *//* one basicop */ + end_loop = sub( end_loop, 1 ); /* make initial loop to even number of (odd-even )pairs */ /* one basicop */ } - FOR(k_val = 3; k_val < end_loop ; k_val++ ) + FOR( k_val = 3; k_val < end_loop; k_val++ ) { /* the optimized non broken loop k=(3,4)(5,6)...(odd,even)*/ /* A(n,k) = A(n,k-2) + ((2*n-1)*A(n,k-1)-A(n,k-2)) /(k-1) */ /* first odd k, even divisor */ - h_saveB = UL_addNsD(h_saveB, f_even_exact_div_opt_fx(numDsub1, h_saveA, h_saveB, sub(k_val,1))); - h[k_val] = h_saveB; + h_saveB = UL_addNsD( h_saveB, f_even_exact_div_opt_fx( numDsub1, h_saveA, h_saveB, sub( k_val, 1 ) ) ); + h[k_val] = h_saveB; move32(); /* next even k, odd divisor */ /*k_val++; */ - h_saveA = UL_addNsD(h_saveA, f_odd_exact_div_opt_fx(numDsub1, h_saveB, h_saveA,shr(k_val,1))); - k_val++; /* ptr incr */ - h[k_val] = h_saveA; + h_saveA = UL_addNsD( h_saveA, f_odd_exact_div_opt_fx( numDsub1, h_saveB, h_saveA, shr( k_val, 1 ) ) ); + k_val++; /* ptr incr */ + h[k_val] = h_saveA; move32(); } } - if(NE_16(add_last_odd,0)) + if ( NE_16( add_last_odd, 0 ) ) { /* add a last odd call as needed , not to be called if k_val_in is [0,1,2] */ - h_saveB = UL_addNsD(h_saveB,f_even_exact_div_opt_fx(numDsub1, h_saveA, h_saveB, sub(k_val,1))); + h_saveB = UL_addNsD( h_saveB, f_even_exact_div_opt_fx( numDsub1, h_saveA, h_saveB, sub( k_val, 1 ) ) ); h[k_val_in] = h_saveB; move32(); } /* always do the last (k+1) recursion based on U(n,k+1) = func( A(n-2,k+1), A(n-1,k+1) ) */ - a_k = h[k_val_in] ; + a_k = h[k_val_in]; move32(); - u_kp1 = direct_row_A2U_rec_calc_fx(dim_in, mem_size_m1 , h[sub(mem_size_m1,2)], a_k ); + u_kp1 = direct_row_A2U_rec_calc_fx( dim_in, mem_size_m1, h[sub( mem_size_m1, 2 )], a_k ); h[mem_size_m1] = u_kp1; move32(); } /* N_MPVQ(n,k) = 1 + U(n,k+1) + U(n,k) = 1 + U(n,k+1) + floor(A(n,k))/2) ; */ /* as A(n,k) always odd */ - return ( UL_addNsD(1U, UL_addNsD(u_kp1, UL_lshr(a_k,1)))); + return ( UL_addNsD( 1U, UL_addNsD( u_kp1, UL_lshr( a_k, 1 ) ) ) ); } /* @@ -497,35 +483,34 @@ UWord32 nm_h_prep_opt_fx( /* o: msize for dim */ find first offset in range 0..k_val_in that is less than ind_in using a tree search with direct function calls [ or memory iteration] */ -static -Word16 find_amp_split_offset_func_mem_fx( /* o: found k_value */ - UWord32 ind_in, - Word16 high, /* i: k_val_in (high bound) */ - H_FUNCM h_func_ptr, /* i: offset function pointer */ - UWord32 *UL_tmp_offset) /* o: offset found */ +static Word16 find_amp_split_offset_func_mem_fx( /* o: found k_value */ + UWord32 ind_in, + Word16 high, /* i: k_val_in (high bound) */ + H_FUNCM h_func_ptr, /* i: offset function pointer */ + UWord32 *UL_tmp_offset ) /* o: offset found */ { - Word16 not_ready, low, k_test=0; - UWord16 sgn ; + Word16 not_ready, low, k_test = 0; + UWord16 sgn; UWord32 UL_tmp; /* split over A(n,k) = h_mem(k), or use direct A function evaluation */ - low = 0; + low = 0; move16(); - move32(); /* account for adaptive function ptr setup */ - not_ready = 1 ; + move32(); /* account for adaptive function ptr setup */ + not_ready = 1; move16(); - WHILE( not_ready != 0) + WHILE( not_ready != 0 ) { - k_test = shr(add(low,high),1); /*% split range in half */ - *UL_tmp_offset = (*h_func_ptr)(UL_deposit_l(k_test)); /* call direct A offset-function */ + k_test = shr( add( low, high ), 1 ); /*% split range in half */ + *UL_tmp_offset = ( *h_func_ptr )( UL_deposit_l( k_test ) ); /* call direct A offset-function */ - UL_tmp = UL_subNs(*UL_tmp_offset, ind_in, &sgn ); - IF ( sgn ) + UL_tmp = UL_subNs( *UL_tmp_offset, ind_in, &sgn ); + IF( sgn ) { /* (*tmp_offset < ind_in) */ - low = add(1, k_test) ; - if( GE_16(k_test ,high)) + low = add( 1, k_test ); + if ( GE_16( k_test, high ) ) { not_ready = 0; move16(); /* single basicop */ @@ -534,8 +519,8 @@ Word16 find_amp_split_offset_func_mem_fx( /* o: found k_v ELSE { /* (ind_in <= *tmp_offset ) */ - high = sub(k_test,1); - if( UL_tmp == 0) + high = sub( k_test, 1 ); + if ( UL_tmp == 0 ) { /* (*tmp_offset == ind_in) */ not_ready = 0; @@ -550,20 +535,19 @@ Word16 find_amp_split_offset_func_mem_fx( /* o: found k_v get_lead_sign_fx() updated index and return leading sign */ -static -Word16 get_lead_sign_fx(UWord32 *ind) +static Word16 get_lead_sign_fx( UWord32 *ind ) { Word16 leading_sign; leading_sign = 1; move16(); - if( UL_and(*ind,1) != 0 ) + if ( UL_and( *ind, 1 ) != 0 ) { /* leading sign stored in LSB */ - leading_sign = -1; + leading_sign = -1; move16(); } - (*ind) = UL_lshr(*ind,1); + ( *ind ) = UL_lshr( *ind, 1 ); return leading_sign; } @@ -571,78 +555,75 @@ Word16 get_lead_sign_fx(UWord32 *ind) /*-------------------------------------------------------------------* * mind2vec_one_fx() *-------------------------------------------------------------------*/ -static -void mind2vec_one_fx( - Word16 k_val_in, /* i: nb unit pulses */ - Word16 leading_sign, /* i: leading sign -1, 0, 1*/ - UWord32 ind, /* i: index */ /* parameter needed as it is used in a function array */ - Word16* vec_out /* o: pulse train */ +static void mind2vec_one_fx( + Word16 k_val_in, /* i: nb unit pulses */ + Word16 leading_sign, /* i: leading sign -1, 0, 1*/ + UWord32 ind, + /* i: index */ /* parameter needed as it is used in a function array */ + Word16 *vec_out /* o: pulse train */ ) { /* NB input k_val_in can be zero */ /* *vec_out = leading_sign*k_val_in; */ - *vec_out = (Word16)ind; /* dummy assignment to avoid gcc "unused parameter" warning for ind, i.e no move16() needed */ + *vec_out = (Word16) ind; /* dummy assignment to avoid gcc "unused parameter" warning for ind, i.e no move16() needed */ /* *vec_out = extract_l(L_mult0(leading_sign,k_val_in)); move16(); // 3 ops */ - if( leading_sign < 0 ) + if ( leading_sign < 0 ) { - k_val_in = negate(k_val_in); /* single basicop --> if */ + k_val_in = negate( k_val_in ); /* single basicop --> if */ } - *vec_out = k_val_in; - move16(); /* 1 op */ + *vec_out = k_val_in; + move16(); /* 1 op */ } -static -void mind2vec_two_fx( - Word16 k_val_in, /* i: nb unit pulses */ - Word16 leading_sign, /* i: leading sign -1,0, 1 */ - UWord32 ind_in, /* i: index */ - Word16 *vec_out /* o: pulse train */ +static void mind2vec_two_fx( + Word16 k_val_in, /* i: nb unit pulses */ + Word16 leading_sign, /* i: leading sign -1,0, 1 */ + UWord32 ind_in, /* i: index */ + Word16 *vec_out /* o: pulse train */ ) { UWord32 UL_ind_tmp; - Word16 val1; + Word16 val1; - IF (ind_in == 0) + IF( ind_in == 0 ) { /* ind_in == 0 */ - mind2vec_one_fx( k_val_in,leading_sign,ind_in,vec_out); + mind2vec_one_fx( k_val_in, leading_sign, ind_in, vec_out ); } - ELSE IF ( EQ_16((Word16)u_extract_l(ind_in), sub(shl(k_val_in,1),1))) + ELSE IF( EQ_16( (Word16) u_extract_l( ind_in ), sub( shl( k_val_in, 1 ), 1 ) ) ) { /* signed ops fine as 2*KMAX << 32767) */ /* (ind_in == ( (unsigned int)(k_val_in<dim; i++) + FOR( i = 0; i < entry->dim; i++ ) { - vec_out[i]=0; + vec_out[i] = 0; move16(); /* set all of short vector to zero , required for fast/early exit logic */ } - leading_sign = 1; + leading_sign = 1; move16(); - if(entry->lead_sign_ind != 0) + if ( entry->lead_sign_ind != 0 ) { leading_sign = -1; move16(); } - IF(entry->k_val != 0) + IF( entry->k_val != 0 ) { - IF(GT_16(entry->dim,N_OPT_FX)) /* N_OPT_FX */ + IF( GT_16( entry->dim, N_OPT_FX ) ) /* N_OPT_FX */ { /* generic */ - mind2vec_fx(entry->dim, entry->k_val, leading_sign, entry->index, vec_out, h_mem); + mind2vec_fx( entry->dim, entry->k_val, leading_sign, entry->index, vec_out, h_mem ); } ELSE { /* specialized functions, with direct offset calculations */ - (mind2vec_f_fx[entry->dim])(entry->k_val, leading_sign, entry->index, vec_out); + ( mind2vec_f_fx[entry->dim] )( entry->k_val, leading_sign, entry->index, vec_out ); } } @@ -887,69 +863,68 @@ void mpvq_decode_vec_fx( /* o : void */ } /*-------------------------------------------------------------------* -* vec2mind_one_fx() -*-------------------------------------------------------------------*/ -static -void vec2mind_one_fx( - const Word16* vec_in, /* i : PVQ pulse train */ - Word16 *k_val_out_ptr , /* o : number of unit pulses */ /* parameter needed as it is used in a function array */ - UWord32 *next_sign_ind, /* i/o: next sign ind */ - UWord32* ind /* o: MPVQ index */ + * vec2mind_one_fx() + *-------------------------------------------------------------------*/ +static void vec2mind_one_fx( + const Word16 *vec_in, /* i : PVQ pulse train */ + Word16 *k_val_out_ptr, + /* o : number of unit pulses */ /* parameter needed as it is used in a function array */ + UWord32 *next_sign_ind, /* i/o: next sign ind */ + UWord32 *ind /* o: MPVQ index */ ) { - *ind = (Word32)(*k_val_out_ptr) ; /* dummy assignment to avoid gcc "unused parameter" warning for *k_val_out_ptr, i.e no move32 needed() */ - *ind = UL_deposit_l(0); + *ind = (Word32) ( *k_val_out_ptr ); /* dummy assignment to avoid gcc "unused parameter" warning for *k_val_out_ptr, i.e no move32 needed() */ + *ind = UL_deposit_l( 0 ); - *next_sign_ind = UL_deposit_l(0); - if( *vec_in < 0 ) + *next_sign_ind = UL_deposit_l( 0 ); + if ( *vec_in < 0 ) { - *next_sign_ind = UL_deposit_l(1); /*single basicop */ + *next_sign_ind = UL_deposit_l( 1 ); /*single basicop */ } - return ; + return; } /*-------------------------------------------------------------------* -* vec2mind_two_fx() -*-------------------------------------------------------------------*/ -static -void vec2mind_two_fx( - const Word16* vec_in, /* i : PVQ pulse train */ - Word16 *k_val_out_ptr , /* o : number of unit pulses */ - UWord32 *next_sign_ind, /* i/o: next sign ind */ - UWord32* ind /* o: MPVQ index */ + * vec2mind_two_fx() + *-------------------------------------------------------------------*/ +static void vec2mind_two_fx( + const Word16 *vec_in, /* i : PVQ pulse train */ + Word16 *k_val_out_ptr, /* o : number of unit pulses */ + UWord32 *next_sign_ind, /* i/o: next sign ind */ + UWord32 *ind /* o: MPVQ index */ ) { UWord32 lead_sign_ind_add; - Word16 abs0,abs1,abs01,sptr; + Word16 abs0, abs1, abs01, sptr; - abs0 = abs_s(vec_in[0]); - abs1 = abs_s(vec_in[1]); - abs01 = add(abs0, abs1); + abs0 = abs_s( vec_in[0] ); + abs1 = abs_s( vec_in[1] ); + abs01 = add( abs0, abs1 ); *k_val_out_ptr = abs01; - move16(); /* can be zero */ - *ind = UL_deposit_l(0); /* [KMAX 0 ] , and dual zeros */ + move16(); /* can be zero */ + *ind = UL_deposit_l( 0 ); /* [KMAX 0 ] , and dual zeros */ - *next_sign_ind = UL_deposit_h(SIGNBIT_SHRT_FX); /* "unset" sign flag set */ /* dual zeroes can happen in a recursive encoding call */ + *next_sign_ind = UL_deposit_h( SIGNBIT_SHRT_FX ); /* "unset" sign flag set */ /* dual zeroes can happen in a recursive encoding call */ IF( abs01 != 0 ) { - sptr = 0; - move16(); /*used as ptr to vec0 or vec1 value */ - *next_sign_ind = UL_deposit_l(sptr); + sptr = 0; + move16(); /*used as ptr to vec0 or vec1 value */ + *next_sign_ind = UL_deposit_l( sptr ); test(); - IF(abs0 != 0 && abs1 != 0 ) + IF( abs0 != 0 && abs1 != 0 ) { /* likely most frequent/common case */ /* [ KMAX-1 1],[ KMAX-1 -1] ... [ 1 +(KMAX-1) ],[ 1 -(KMAX-1)] */ /* sign always shifted to first pos */ - lead_sign_ind_add = UL_deposit_l(1) ; - if( vec_in[1] < 0) + lead_sign_ind_add = UL_deposit_l( 1 ); + if ( vec_in[1] < 0 ) { - lead_sign_ind_add = UL_deposit_l(2); /* single op */ + lead_sign_ind_add = UL_deposit_l( 2 ); /* single op */ } - *ind = UL_addNsD(UL_deposit_l((UWord16)lshl(sub(abs1,1),1)),lead_sign_ind_add); + *ind = UL_addNsD( UL_deposit_l( (UWord16) lshl( sub( abs1, 1 ), 1 ) ), lead_sign_ind_add ); } ELSE { @@ -957,23 +932,22 @@ void vec2mind_two_fx( IF( abs0 == 0 ) { /* [ 0 KMAX]*/ - *ind = UL_deposit_l((UWord16) sub(lshl(abs1,1),1)); - sptr = 1; + *ind = UL_deposit_l( (UWord16) sub( lshl( abs1, 1 ), 1 ) ); + sptr = 1; move16(); } } /* *next_sign_ind= (unsigned int)(vec_in[*next_sign_ind]<0); */ - if( vec_in[sptr] < 0 ) + if ( vec_in[sptr] < 0 ) { - *next_sign_ind = UL_deposit_l(1); /*single instruction */ + *next_sign_ind = UL_deposit_l( 1 ); /*single instruction */ } } return; } -static -void enc_push_sign(Word16 val, UWord32* next_sign_ind, UWord32 *index) +static void enc_push_sign( Word16 val, UWord32 *next_sign_ind, UWord32 *index ) { /* % Check if the leading sign 'bit' is to be added @@ -981,20 +955,20 @@ void enc_push_sign(Word16 val, UWord32* next_sign_ind, UWord32 *index) % (one can also put it in the MSB , but then one needs to access h_mem twice and shift the sign bit into position ) */ test(); - IF( (UL_and(*next_sign_ind,SIGNBIT_FX) == 0) && (val != 0)) + IF( ( UL_and( *next_sign_ind, SIGNBIT_FX ) == 0 ) && ( val != 0 ) ) { - *index = UL_addNsD(UL_lshl(*index,1),*next_sign_ind); + *index = UL_addNsD( UL_lshl( *index, 1 ), *next_sign_ind ); } /* push sign to next non_zero position */ - /* *next_sign_ind = *next_sign_ind ;*/ /* default is to keep stored sign index */ - if( val < 0 ) + /* *next_sign_ind = *next_sign_ind ;*/ /* default is to keep stored sign index */ + if ( val < 0 ) { - *next_sign_ind = UL_deposit_l(1); /* single basicop */ + *next_sign_ind = UL_deposit_l( 1 ); /* single basicop */ } - if( val > 0) + if ( val > 0 ) { - *next_sign_ind = UL_deposit_l(0); /* single basicop */ + *next_sign_ind = UL_deposit_l( 0 ); /* single basicop */ } } @@ -1003,92 +977,87 @@ void enc_push_sign(Word16 val, UWord32* next_sign_ind, UWord32 *index) * generic call saves PROM , *-------------------------------------------------------------------*/ -static -void vec2mind_gen345_fx( - const Word16* vec_in, /* i : PVQ abs pulse train */ - Word16 *k_val_out_ptr, /* o : number of unit pulses */ - UWord32 *next_sign_ind , /* i/o: next sign ind */ - UWord32* index , /* o: MPVQ index */ - VEC2INDFUNCM vec2indfunc_ptr, /* i: */ - H_FUNCM a_func_ptr /*i: offset function */ +static void vec2mind_gen345_fx( + const Word16 *vec_in, /* i : PVQ abs pulse train */ + Word16 *k_val_out_ptr, /* o : number of unit pulses */ + UWord32 *next_sign_ind, /* i/o: next sign ind */ + UWord32 *index, /* o: MPVQ index */ + VEC2INDFUNCM vec2indfunc_ptr, /* i: */ + H_FUNCM a_func_ptr /*i: offset function */ ) { - Word16 tmp_val; + Word16 tmp_val; tmp_val = vec_in[0]; move16(); - move32(); /* adaptive function call setup */ - (*vec2indfunc_ptr)(&vec_in[1], k_val_out_ptr, next_sign_ind, index); + move32(); /* adaptive function call setup */ + ( *vec2indfunc_ptr )( &vec_in[1], k_val_out_ptr, next_sign_ind, index ); - enc_push_sign(tmp_val, next_sign_ind, index); + enc_push_sign( tmp_val, next_sign_ind, index ); - move32(); /* adaptive function call setup */ - *index = UL_addNsD(*index,(*a_func_ptr)(UL_deposit_l(*k_val_out_ptr))); + move32(); /* adaptive function call setup */ + *index = UL_addNsD( *index, ( *a_func_ptr )( UL_deposit_l( *k_val_out_ptr ) ) ); - *k_val_out_ptr = add(*k_val_out_ptr, abs_s(tmp_val)); + *k_val_out_ptr = add( *k_val_out_ptr, abs_s( tmp_val ) ); - return ; + return; } /*-------------------------------------------------------------------* * vec2mind_three_fx() *-------------------------------------------------------------------*/ -static -void vec2mind_three_fx( - const Word16* vec_in, /* i : PVQ pulse train */ - Word16* k_val_out_ptr, /* o : number of unit pulses */ - UWord32 *next_sign_ind, /* i/o: next sign ind */ - UWord32 *index /* o: MPVQ index */ +static void vec2mind_three_fx( + const Word16 *vec_in, /* i : PVQ pulse train */ + Word16 *k_val_out_ptr, /* o : number of unit pulses */ + UWord32 *next_sign_ind, /* i/o: next sign ind */ + UWord32 *index /* o: MPVQ index */ ) { - vec2mind_gen345_fx(vec_in,k_val_out_ptr, next_sign_ind, index, vec2mind_two_fx, a_three_fx); - return ; + vec2mind_gen345_fx( vec_in, k_val_out_ptr, next_sign_ind, index, vec2mind_two_fx, a_three_fx ); + return; } /*-------------------------------------------------------------------* * vec2mind_four_fx() *-------------------------------------------------------------------*/ -static -void vec2mind_four_fx( - const Word16* vec_in, /* i : PVQ pulse train */ - Word16* k_val_out_ptr, /* o : number of unit pulses */ - UWord32* next_sign_ind , /* i/o: next sign ind */ - UWord32* index /* o: MPVQ index */ +static void vec2mind_four_fx( + const Word16 *vec_in, /* i : PVQ pulse train */ + Word16 *k_val_out_ptr, /* o : number of unit pulses */ + UWord32 *next_sign_ind, /* i/o: next sign ind */ + UWord32 *index /* o: MPVQ index */ ) { - vec2mind_gen345_fx(vec_in, k_val_out_ptr, next_sign_ind, index, vec2mind_three_fx, a_four_fx); - return ; + vec2mind_gen345_fx( vec_in, k_val_out_ptr, next_sign_ind, index, vec2mind_three_fx, a_four_fx ); + return; } /*-------------------------------------------------------------------* * vec2mind_five_fx() *-------------------------------------------------------------------*/ -static -void vec2mind_five_fx( - const Word16* vec_in, /* i : PVQ abs pulse train */ - Word16 *k_val_out_ptr, /* o : number of unit pulses */ - UWord32 *next_sign_ind , /* i/o: next sign ind */ - UWord32* index /* o: MPVQ index */ +static void vec2mind_five_fx( + const Word16 *vec_in, /* i : PVQ abs pulse train */ + Word16 *k_val_out_ptr, /* o : number of unit pulses */ + UWord32 *next_sign_ind, /* i/o: next sign ind */ + UWord32 *index /* o: MPVQ index */ ) { - vec2mind_gen345_fx(vec_in,k_val_out_ptr, next_sign_ind, index, vec2mind_four_fx, a_five_fx); - return ; + vec2mind_gen345_fx( vec_in, k_val_out_ptr, next_sign_ind, index, vec2mind_four_fx, a_five_fx ); + return; } /*-------------------------------------------------------------------* -* vec2mind_fx() -*-------------------------------------------------------------------*/ -static -void vec2mind_fx(Word16 dim_in, /* i : dim */ - Word16 k_val_in, /* i : number of unit pulses */ - const Word16* vec_in, /* i : PVQ pulse train */ - UWord32 *next_sign_ind, /* o : pushed leading sign */ - UWord32 *index , /* o : MPVQ index */ - UWord32 *N_MPVQ_ptr, /* o : size(N_MPVQ(dim,K_val_in))*/ - UWord32* h_mem) /* o : offsets */ + * vec2mind_fx() + *-------------------------------------------------------------------*/ +static void vec2mind_fx( Word16 dim_in, /* i : dim */ + Word16 k_val_in, /* i : number of unit pulses */ + const Word16 *vec_in, /* i : PVQ pulse train */ + UWord32 *next_sign_ind, /* o : pushed leading sign */ + UWord32 *index, /* o : MPVQ index */ + UWord32 *N_MPVQ_ptr, /* o : size(N_MPVQ(dim,K_val_in))*/ + UWord32 *h_mem ) /* o : offsets */ { - Word16 pos, mem_size_m1, k_val_acc, tmp_val; + Word16 pos, mem_size_m1, k_val_acc, tmp_val; UWord32 tmp_h; /* @@ -1104,41 +1073,41 @@ void vec2mind_fx(Word16 dim_in, /* i : dim % calculate size */ - mem_size_m1 = add(k_val_in,1); - *next_sign_ind = UL_deposit_h(SIGNBIT_SHRT_FX); /* highest bit set signals no sign found yet, should always be 0 or 1 out, */ + mem_size_m1 = add( k_val_in, 1 ); + *next_sign_ind = UL_deposit_h( SIGNBIT_SHRT_FX ); /* highest bit set signals no sign found yet, should always be 0 or 1 out, */ - pos = sub(dim_in,2); /* adress 2nd last sample */ - vec2mind_two_fx(&vec_in[pos],&k_val_acc,next_sign_ind ,index); - initOffsets_fx( 3, h_mem, k_val_in) ; /* start recursions at 3rd sample */ + pos = sub( dim_in, 2 ); /* adress 2nd last sample */ + vec2mind_two_fx( &vec_in[pos], &k_val_acc, next_sign_ind, index ); + initOffsets_fx( 3, h_mem, k_val_in ); /* start recursions at 3rd sample */ - tmp_h = h_mem[k_val_acc]; + tmp_h = h_mem[k_val_acc]; move32(); - FOR (pos--; pos>=0; pos--) + FOR( pos--; pos >= 0; pos-- ) { tmp_val = vec_in[pos]; move16(); - enc_push_sign(tmp_val, next_sign_ind, index); + enc_push_sign( tmp_val, next_sign_ind, index ); /* now add indexing offset up to this reverse (r_l) accumulated amplitude point */ - *index = UL_addNsD(*index, tmp_h); /* k_val_acc==0 ==>0 */ + *index = UL_addNsD( *index, tmp_h ); /* k_val_acc==0 ==>0 */ - /* k_val_acc = k_val_acc + vec_abs[pos];*/ /* now increase acc k value for next N */ - k_val_acc = add(k_val_acc, abs_s(tmp_val)); + /* k_val_acc = k_val_acc + vec_abs[pos];*/ /* now increase acc k value for next N */ + k_val_acc = add( k_val_acc, abs_s( tmp_val ) ); IF( pos != 0 ) { - a_u_fwd_fx(h_mem, k_val_in ,mem_size_m1); + a_u_fwd_fx( h_mem, k_val_in, mem_size_m1 ); /* update A(n,k=1:k_val_in) and U(n,k_val_in+1) */ /* NB here (k_val_in + 2 elements always has to be updated */ } - tmp_h = UL_addNsD(h_mem[k_val_acc], 0U); + tmp_h = UL_addNsD( h_mem[k_val_acc], 0U ); } /* size is needed for the subseqent arithmetic encoding/transmission of the index. use relation N_MPVQ(n,K) = 1 + (A(n, K)-1)/2 + U(n, 1 + K) = N_MPVQ(n,K) = 1 + (A(n, K)>>1) + U(n, 1 + K) , as A(n,K) is odd) */ - *N_MPVQ_ptr = UL_addNsD(1U,UL_addNsD(UL_lshr(tmp_h,1),h_mem[ mem_size_m1])); - move32();/* calc total size */ + *N_MPVQ_ptr = UL_addNsD( 1U, UL_addNsD( UL_lshr( tmp_h, 1 ), h_mem[mem_size_m1] ) ); + move32(); /* calc total size */ return; } @@ -1149,38 +1118,36 @@ void vec2mind_fx(Word16 dim_in, /* i : dim * returns struct with lead sign index, MPVQ-index, dim and N_MPVQ size *-------------------------------------------------------------------------*/ -PvqEntry mpvq_encode_vec_fx( /* o : leading_sign_index, index, size, k_val */ - const Word16* vec_in, /* i : signed pulse train */ - Word16 dim_in, /* i : dimension */ - Word16 k_val_local /* i : nb unit pulses */ +PvqEntry mpvq_encode_vec_fx( /* o : leading_sign_index, index, size, k_val */ + const Word16 *vec_in, /* i : signed pulse train */ + Word16 dim_in, /* i : dimension */ + Word16 k_val_local /* i : nb unit pulses */ ) { PvqEntry result; - UWord32 h_mem[ 1 + KMAX_NON_DIRECT_FX + 1 ] ; /* now always assign max offset buffer for dim 6 , - actually only 1+k_val_in+1 needed ) */ + UWord32 h_mem[1 + KMAX_NON_DIRECT_FX + 1]; /* now always assign max offset buffer for dim 6 , + actually only 1+k_val_in+1 needed ) */ UWord32 lead_sign_ind; - VEC2INDFUNCM vec2mind_f[1+N_OPT_FX] = { (VEC2INDFUNCM)NULL, vec2mind_one_fx, vec2mind_two_fx, vec2mind_three_fx, vec2mind_four_fx, vec2mind_five_fx }; + VEC2INDFUNCM vec2mind_f[1 + N_OPT_FX] = { (VEC2INDFUNCM) NULL, vec2mind_one_fx, vec2mind_two_fx, vec2mind_three_fx, vec2mind_four_fx, vec2mind_five_fx }; - result.k_val = k_val_local; + result.k_val = k_val_local; move16(); - result.dim = dim_in; + result.dim = dim_in; move16(); /* NB , k_val_local may be changed in some sub encoding routines */ - IF( GT_16(dim_in, N_OPT_FX)) + IF( GT_16( dim_in, N_OPT_FX ) ) { /* use the generic dimension function */ - vec2mind_fx(dim_in, k_val_local, vec_in, &lead_sign_ind, &result.index, &result.size, h_mem); + vec2mind_fx( dim_in, k_val_local, vec_in, &lead_sign_ind, &result.index, &result.size, h_mem ); } ELSE /* if (dim_in<=N_OPT), h_mem not used */ { - move32(); /* adaptive function ptr setup */ - (vec2mind_f[dim_in])(vec_in, &k_val_local, &lead_sign_ind, &result.index); - result.size = direct_msize_fx(dim_in, k_val_local); + move32(); /* adaptive function ptr setup */ + ( vec2mind_f[dim_in] )( vec_in, &k_val_local, &lead_sign_ind, &result.index ); + result.size = direct_msize_fx( dim_in, k_val_local ); } - result.lead_sign_ind = u_extract_l(lead_sign_ind); + result.lead_sign_ind = u_extract_l( lead_sign_ind ); return result; } - - diff --git a/lib_com/int_lsp.c b/lib_com/int_lsp.c index f07a624ab..a340281f7 100644 --- a/lib_com/int_lsp.c +++ b/lib_com/int_lsp.c @@ -98,59 +98,59 @@ void int_lsp( } void int_lsp_fx( - const Word16 L_frame, /* i : length of the frame */ - const Word16 lsp_old[], /* i : LSPs from past frame */ - const Word16 lsp_new[], /* i : LSPs from present frame */ - Word16 *Aq, /* o : LP coefficients in both subframes */ - const Word16 m, /* i : order of LP filter */ - const Word16 *int_coeffs, /* i : interpolation coefficients */ - const Word16 Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ + const Word16 L_frame, /* i : length of the frame */ + const Word16 lsp_old[], /* i : LSPs from past frame */ + const Word16 lsp_new[], /* i : LSPs from present frame */ + Word16 *Aq, /* o : LP coefficients in both subframes */ + const Word16 m, /* i : order of LP filter */ + const Word16 *int_coeffs, /* i : interpolation coefficients */ + const Word16 Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ ) { - Word16 lsp[M], fnew, fold; - Word16 i, k; - const Word16 *pt_int_coeffs = NULL; - Word32 L_tmp; - Word16 tmp; - - tmp = shr(L_frame, 6); /*L_frame/L_SUBFR */ - - IF(EQ_16(L_frame, L_FRAME)) - { - pt_int_coeffs = int_coeffs; - move16(); - } - ELSE /* L_frame == L_FRAME16k */ - { - pt_int_coeffs = interpol_frac_16k_fx; - } - FOR(k = 0; k < tmp; k++) - { - fnew = pt_int_coeffs[k]; - move16(); - fold = sub(32767, fnew); /* 1.0 - fac_new */ - if (fold != 0) - fold = add(fold, 1); - FOR(i = 0; i < m; i++) + Word16 lsp[M], fnew, fold; + Word16 i, k; + const Word16 *pt_int_coeffs = NULL; + Word32 L_tmp; + Word16 tmp; + + tmp = shr( L_frame, 6 ); /*L_frame/L_SUBFR */ + + IF( EQ_16( L_frame, L_FRAME ) ) { - L_tmp = L_mult(lsp_old[i], fold); - L_tmp = L_mac(L_tmp, lsp_new[i], fnew); - if (fold == 0) - L_tmp = L_mac(L_tmp, lsp_new[i], 1); /* 'fnew' should have been 32768 */ - lsp[i] = round_fx(L_tmp); + pt_int_coeffs = int_coeffs; + move16(); } - IF(Opt_AMR_WB) + ELSE /* L_frame == L_FRAME16k */ { - E_LPC_f_isp_a_conversion(lsp, Aq, m); + pt_int_coeffs = interpol_frac_16k_fx; } - ELSE + FOR( k = 0; k < tmp; k++ ) { - E_LPC_f_lsp_a_conversion(lsp, Aq, m); + fnew = pt_int_coeffs[k]; + move16(); + fold = sub( 32767, fnew ); /* 1.0 - fac_new */ + if ( fold != 0 ) + fold = add( fold, 1 ); + FOR( i = 0; i < m; i++ ) + { + L_tmp = L_mult( lsp_old[i], fold ); + L_tmp = L_mac( L_tmp, lsp_new[i], fnew ); + if ( fold == 0 ) + L_tmp = L_mac( L_tmp, lsp_new[i], 1 ); /* 'fnew' should have been 32768 */ + lsp[i] = round_fx( L_tmp ); + } + IF( Opt_AMR_WB ) + { + E_LPC_f_isp_a_conversion( lsp, Aq, m ); + } + ELSE + { + E_LPC_f_lsp_a_conversion( lsp, Aq, m ); + } + Aq += ( m + 1 ); } - Aq += (m + 1); - } - return; + return; } @@ -236,78 +236,78 @@ void int_lsp4( } void int_lsp4_fx( - const Word16 L_frame, /* i : length of the frame */ - const Word16 lsp_old[], /* i : LSPs from past frame Q15*/ - const Word16 lsp_mid[], /* i : LSPs from mid-frame Q15*/ - const Word16 lsp_new[], /* i : LSPs from present frame Q15*/ - Word16 *Aq, /* o : LP coefficients in both subframes Q12*/ - const Word16 m, /* i : order of LP filter */ - Word16 relax_prev_lsf_interp /* i : relax prev frame lsf interp after erasure */ + const Word16 L_frame, /* i : length of the frame */ + const Word16 lsp_old[], /* i : LSPs from past frame Q15*/ + const Word16 lsp_mid[], /* i : LSPs from mid-frame Q15*/ + const Word16 lsp_new[], /* i : LSPs from present frame Q15*/ + Word16 *Aq, /* o : LP coefficients in both subframes Q12*/ + const Word16 m, /* i : order of LP filter */ + Word16 relax_prev_lsf_interp /* i : relax prev frame lsf interp after erasure */ ) { - Word16 lsp[M16k]; - Word16 i, j, k; - Word32 L_tmp; - const Word16 *pt_int_coeffs; - - IF(EQ_16(L_frame, L_FRAME)) - { - IF(EQ_16(relax_prev_lsf_interp, 1)) - { - pt_int_coeffs = interpol_frac_mid_relaxprev_12k8_fx; - } - ELSE IF(EQ_16(relax_prev_lsf_interp, 2)) - { - pt_int_coeffs = interpol_frac_mid_FEC_fx; - } - ELSE IF(EQ_16(relax_prev_lsf_interp, -1)) + Word16 lsp[M16k]; + Word16 i, j, k; + Word32 L_tmp; + const Word16 *pt_int_coeffs; + + IF( EQ_16( L_frame, L_FRAME ) ) { - pt_int_coeffs = interpol_frac_mid_relaxprev_pred_12k8_fx; + IF( EQ_16( relax_prev_lsf_interp, 1 ) ) + { + pt_int_coeffs = interpol_frac_mid_relaxprev_12k8_fx; + } + ELSE IF( EQ_16( relax_prev_lsf_interp, 2 ) ) + { + pt_int_coeffs = interpol_frac_mid_FEC_fx; + } + ELSE IF( EQ_16( relax_prev_lsf_interp, -1 ) ) + { + pt_int_coeffs = interpol_frac_mid_relaxprev_pred_12k8_fx; + } + ELSE + { + pt_int_coeffs = interpol_frac_mid_fx; + } } - ELSE + ELSE /* L_frame == L_FRAME16k */ { - pt_int_coeffs = interpol_frac_mid_fx; + IF( EQ_16( relax_prev_lsf_interp, 1 ) ) + { + pt_int_coeffs = interpol_frac_mid_relaxprev_16k_fx; + } + ELSE IF( EQ_16( relax_prev_lsf_interp, 2 ) ) + { + pt_int_coeffs = interpol_frac_mid_16k_FEC_fx; + } + ELSE IF( EQ_16( relax_prev_lsf_interp, -1 ) ) + { + pt_int_coeffs = interpol_frac_mid_relaxprev_pred_16k_fx; + } + ELSE + { + pt_int_coeffs = interpol_frac_mid_16k_fx; + } } - } - ELSE /* L_frame == L_FRAME16k */ - { - IF(EQ_16(relax_prev_lsf_interp,1)) - { - pt_int_coeffs = interpol_frac_mid_relaxprev_16k_fx; - } - ELSE IF(EQ_16(relax_prev_lsf_interp,2)) - { - pt_int_coeffs = interpol_frac_mid_16k_FEC_fx; - } - ELSE IF(EQ_16(relax_prev_lsf_interp,-1)) - { - pt_int_coeffs = interpol_frac_mid_relaxprev_pred_16k_fx; - } - ELSE - { - pt_int_coeffs = interpol_frac_mid_16k_fx; - } - } - k = sub(shr(L_frame, 6), 1); - FOR(j = 0; j < k; j++) - { - FOR(i = 0; i < m; i++) + k = sub( shr( L_frame, 6 ), 1 ); + FOR( j = 0; j < k; j++ ) { - L_tmp = L_mult(lsp_old[i], *pt_int_coeffs); /*Q31 */ - L_tmp = L_mac(L_tmp, lsp_mid[i], *(pt_int_coeffs + 1)); /*Q31 */ - lsp[i] = mac_r(L_tmp, lsp_new[i], *(pt_int_coeffs + 2)); - move16(); - } - pt_int_coeffs += 3; - move16(); + FOR( i = 0; i < m; i++ ) + { + L_tmp = L_mult( lsp_old[i], *pt_int_coeffs ); /*Q31 */ + L_tmp = L_mac( L_tmp, lsp_mid[i], *( pt_int_coeffs + 1 ) ); /*Q31 */ + lsp[i] = mac_r( L_tmp, lsp_new[i], *( pt_int_coeffs + 2 ) ); + move16(); + } + pt_int_coeffs += 3; + move16(); - E_LPC_f_lsp_a_conversion(lsp, Aq, m); - Aq += (m + 1); - move16(); - } + E_LPC_f_lsp_a_conversion( lsp, Aq, m ); + Aq += ( m + 1 ); + move16(); + } - /* Last subframe */ - E_LPC_f_lsp_a_conversion(lsp_new, Aq, m); + /* Last subframe */ + E_LPC_f_lsp_a_conversion( lsp_new, Aq, m ); - return; + return; } diff --git a/lib_com/interleave_spectrum.c b/lib_com/interleave_spectrum.c index 88aeffdf9..12e628fb7 100644 --- a/lib_com/interleave_spectrum.c +++ b/lib_com/interleave_spectrum.c @@ -129,88 +129,88 @@ void interleave_spectrum( } void interleave_spectrum_fx( - Word32 *coefs, /* i/o: input and output coefficients Q12 */ - const Word16 length /* i : length of spectrum Q0 */ + Word32 *coefs, /* i/o: input and output coefficients Q12 */ + const Word16 length /* i : length of spectrum Q0 */ ) { - Word16 i, j, k; - Word32 *p1, *p2, *p3, *p4; - Word32 *p_out; - Word32 coefs_out[L_FRAME48k]; - Word16 sublen[3] = { 240, 160, 80 }; - Word16 grps; - const Word16 *bw; - const Word16 *cnt; - - /* Common inits */ - p1 = coefs; - p_out = coefs_out; + Word16 i, j, k; + Word32 *p1, *p2, *p3, *p4; + Word32 *p_out; + Word32 coefs_out[L_FRAME48k]; + Word16 sublen[3] = { 240, 160, 80 }; + Word16 grps; + const Word16 *bw; + const Word16 *cnt; + + /* Common inits */ + p1 = coefs; + p_out = coefs_out; #ifdef SOLVED_COMP_ENC_DEC - IF(EQ_16(length, L_SPEC48k)) + IF( EQ_16( length, L_SPEC48k ) ) #else - IF(EQ_16(length, L_FRAME48k)) + IF( EQ_16( length, L_FRAME48k ) ) #endif - { - bw = intl_bw_48; - cnt = intl_cnt_48; - grps = N_INTL_GRP_48; - move16(); - p2 = p1 + sublen[0]; - p3 = p2 + sublen[0]; - p4 = p3 + sublen[0]; - } - ELSE IF(EQ_16(length, L_SPEC32k)) - { - bw = intl_bw_32; - cnt = intl_cnt_32; - grps = N_INTL_GRP_32; - move16(); - p2 = p1 + sublen[1]; - p3 = p2 + sublen[1]; - p4 = p3 + sublen[1]; - } - ELSE /* length == L_SPEC16k */ - { - bw = intl_bw_16; - cnt = intl_cnt_16; - grps = N_INTL_GRP_16; - move16(); - p2 = p1 + sublen[2]; - p3 = p2 + sublen[2]; - p4 = p3 + sublen[2]; - } - - FOR(i = 0; i < grps; i++) - { - FOR(j = 0; j < cnt[i]; j++) { - FOR(k = 0; k < bw[i]; k++) - { - *p_out++ = *p1++; - move32(); - } - FOR(k = 0; k < bw[i]; k++) - { - *p_out++ = *p2++; - move32(); - } - FOR(k = 0; k < bw[i]; k++) - { - *p_out++ = *p3++; - move32(); - } - FOR(k = 0; k < bw[i]; k++) - { - *p_out++ = *p4++; - move32(); - } + bw = intl_bw_48; + cnt = intl_cnt_48; + grps = N_INTL_GRP_48; + move16(); + p2 = p1 + sublen[0]; + p3 = p2 + sublen[0]; + p4 = p3 + sublen[0]; + } + ELSE IF( EQ_16( length, L_SPEC32k ) ) + { + bw = intl_bw_32; + cnt = intl_cnt_32; + grps = N_INTL_GRP_32; + move16(); + p2 = p1 + sublen[1]; + p3 = p2 + sublen[1]; + p4 = p3 + sublen[1]; + } + ELSE /* length == L_SPEC16k */ + { + bw = intl_bw_16; + cnt = intl_cnt_16; + grps = N_INTL_GRP_16; + move16(); + p2 = p1 + sublen[2]; + p3 = p2 + sublen[2]; + p4 = p3 + sublen[2]; + } + + FOR( i = 0; i < grps; i++ ) + { + FOR( j = 0; j < cnt[i]; j++ ) + { + FOR( k = 0; k < bw[i]; k++ ) + { + *p_out++ = *p1++; + move32(); + } + FOR( k = 0; k < bw[i]; k++ ) + { + *p_out++ = *p2++; + move32(); + } + FOR( k = 0; k < bw[i]; k++ ) + { + *p_out++ = *p3++; + move32(); + } + FOR( k = 0; k < bw[i]; k++ ) + { + *p_out++ = *p4++; + move32(); + } + } } - } - /* For FB the interleaved spectrum is 800 samples */ - Copy32(coefs_out, coefs, (Word16)(p_out - coefs_out)); + /* For FB the interleaved spectrum is 800 samples */ + Copy32( coefs_out, coefs, (Word16) ( p_out - coefs_out ) ); - return; + return; } @@ -385,97 +385,96 @@ void ivas_de_interleave_spectrum_fx( #endif void de_interleave_spectrum_fx( - Word32 *coefs, /* i/o: input and output coefficients Q12 */ - const Word16 length /* i : length of spectrum Q0 */ + Word32 *coefs, /* i/o: input and output coefficients Q12 */ + const Word16 length /* i : length of spectrum Q0 */ ) { - Word16 i, j, k; - Word32 *p1, *p2, *p3, *p4; - Word32 *p_in; - Word32 coefs_out[L_FRAME48k]; - Word16 sublen[] = { 80, 160, 240, 320, 480, 720 }; - Word16 grps; - Word16 l_frame; - const Word16 *bw; - const Word16 *cnt; - - /* common for all groups */ - p1 = coefs_out; - l_frame = length; - move16(); + Word16 i, j, k; + Word32 *p1, *p2, *p3, *p4; + Word32 *p_in; + Word32 coefs_out[L_FRAME48k]; + Word16 sublen[] = { 80, 160, 240, 320, 480, 720 }; + Word16 grps; + Word16 l_frame; + const Word16 *bw; + const Word16 *cnt; + + /* common for all groups */ + p1 = coefs_out; + l_frame = length; + move16(); #ifdef SOLVED_COMP_ENC_DEC - IF(EQ_16(length, L_SPEC48k)) + IF( EQ_16( length, L_SPEC48k ) ) #else - IF(EQ_16(length, L_FRAME48k)) + IF( EQ_16( length, L_FRAME48k ) ) #endif - { - bw = intl_bw_48; - cnt = intl_cnt_48; - grps = N_INTL_GRP_48; - move16(); + { + bw = intl_bw_48; + cnt = intl_cnt_48; + grps = N_INTL_GRP_48; + move16(); #ifdef SOLVED_COMP_ENC_DEC - l_frame = L_FRAME48k; - move16(); + l_frame = L_FRAME48k; + move16(); #endif - p2 = coefs_out + sublen[2]; /* 240, length/4 */ - p3 = coefs_out + sublen[4]; /* 480, 2*length/4 */ - p4 = coefs_out + sublen[5]; /* 720, 3*length/4 */ - } - ELSE IF(EQ_16(length, L_SPEC32k)) - { - bw = intl_bw_32; - cnt = intl_cnt_32; - grps = N_INTL_GRP_32; - move16(); + p2 = coefs_out + sublen[2]; /* 240, length/4 */ + p3 = coefs_out + sublen[4]; /* 480, 2*length/4 */ + p4 = coefs_out + sublen[5]; /* 720, 3*length/4 */ + } + ELSE IF( EQ_16( length, L_SPEC32k ) ) + { + bw = intl_bw_32; + cnt = intl_cnt_32; + grps = N_INTL_GRP_32; + move16(); + + p2 = coefs_out + sublen[1]; /* 160 */ + p3 = coefs_out + sublen[3]; /* 320 */ + p4 = coefs_out + sublen[4]; /* 480 */ + } + ELSE /* length == L_SPEC16k */ + { + bw = intl_bw_16; + cnt = intl_cnt_16; + grps = N_INTL_GRP_16; + move16(); - p2 = coefs_out + sublen[1]; /* 160 */ - p3 = coefs_out + sublen[3]; /* 320 */ - p4 = coefs_out + sublen[4]; /* 480 */ - } - ELSE /* length == L_SPEC16k */ - { - bw = intl_bw_16; - cnt = intl_cnt_16; - grps = N_INTL_GRP_16; - move16(); - - p2 = coefs_out + sublen[0]; /* 80 */ - p3 = coefs_out + sublen[1]; /* 160 */ - p4 = coefs_out + sublen[2]; /* 240 */ - } - - set32_fx(coefs_out, 0, L_FRAME48k); - p_in = coefs; - - FOR(i = 0; i < grps; i++) - { - FOR(j = 0; j < cnt[i]; j++) + p2 = coefs_out + sublen[0]; /* 80 */ + p3 = coefs_out + sublen[1]; /* 160 */ + p4 = coefs_out + sublen[2]; /* 240 */ + } + + set32_fx( coefs_out, 0, L_FRAME48k ); + p_in = coefs; + + FOR( i = 0; i < grps; i++ ) { - FOR(k = 0; k < bw[i]; k++) - { - *p1++ = *p_in++; - move32(); - } - FOR(k = 0; k < bw[i]; k++) - { - *p2++ = *p_in++; - move32(); - } - FOR(k = 0; k < bw[i]; k++) - { - *p3++ = *p_in++; - move32(); - } - FOR(k = 0; k < bw[i]; k++) - { - *p4++ = *p_in++; - move32(); - } + FOR( j = 0; j < cnt[i]; j++ ) + { + FOR( k = 0; k < bw[i]; k++ ) + { + *p1++ = *p_in++; + move32(); + } + FOR( k = 0; k < bw[i]; k++ ) + { + *p2++ = *p_in++; + move32(); + } + FOR( k = 0; k < bw[i]; k++ ) + { + *p3++ = *p_in++; + move32(); + } + FOR( k = 0; k < bw[i]; k++ ) + { + *p4++ = *p_in++; + move32(); + } + } } - } - Copy32(coefs_out, coefs, l_frame); + Copy32( coefs_out, coefs, l_frame ); - return; + return; } - diff --git a/lib_com/interpol.c b/lib_com/interpol.c index c90aa9f0e..2dfab173b 100644 --- a/lib_com/interpol.c +++ b/lib_com/interpol.c @@ -81,80 +81,80 @@ float interpolation( } -Word32 Interpol_lc_fx( /* o : interpolated value Qx+16 */ - const Word16 *x, /* i : input vector Q0 */ - const Word16 *win, /* i : interpolation window Q14 */ - const Word16 frac, /* i : fraction (0..up_samp) Q0 */ - const Word16 up_samp, /* i : upsampling factor Q0 */ - const Word16 nb_coef /* i : number of coefficients Q0 */ +Word32 Interpol_lc_fx( /* o : interpolated value Qx+16 */ + const Word16 *x, /* i : input vector Q0 */ + const Word16 *win, /* i : interpolation window Q14 */ + const Word16 frac, /* i : fraction (0..up_samp) Q0 */ + const Word16 up_samp, /* i : upsampling factor Q0 */ + const Word16 nb_coef /* i : number of coefficients Q0 */ ) { - Word16 i; - const Word16 *c1, *c2, *x2; - Word32 L_sum; - - x2 = &x[1]; - c1 = &win[frac]; - c2 = &win[sub(up_samp, frac)]; - { - Word64 L_sum64 = 0; - move64(); - FOR(i = 0; i < nb_coef; i++) + Word16 i; + const Word16 *c1, *c2, *x2; + Word32 L_sum; + + x2 = &x[1]; + c1 = &win[frac]; + c2 = &win[sub( up_samp, frac )]; { - /* Using L_mac0 limits the risk of saturation during the loop, saturation may occures after the loop */ - L_sum64 = W_mac0_16_16(L_sum64, *x, *c1); - --x; - L_sum64 = W_mac0_16_16(L_sum64, *x2, *c2); - ++x2; - c2 += up_samp; /* move16() not needed, since the coefficient can be rearrange in bit exact way */ - c1 += up_samp; + Word64 L_sum64 = 0; + move64(); + FOR( i = 0; i < nb_coef; i++ ) + { + /* Using L_mac0 limits the risk of saturation during the loop, saturation may occures after the loop */ + L_sum64 = W_mac0_16_16( L_sum64, *x, *c1 ); + --x; + L_sum64 = W_mac0_16_16( L_sum64, *x2, *c2 ); + ++x2; + c2 += up_samp; /* move16() not needed, since the coefficient can be rearrange in bit exact way */ + c1 += up_samp; + } + L_sum = W_sat_l( L_sum64 ); } - L_sum = W_sat_l(L_sum64); - } #ifdef BASOP_NOGLOB - L_sum = L_shl_sat( L_sum, 1 ); + L_sum = L_shl_sat( L_sum, 1 ); #else - L_sum = L_shl( L_sum, 1 ); + L_sum = L_shl( L_sum, 1 ); #endif - return L_sum; + return L_sum; } -Word16 Interpol_4( /* o : interpolated value */ - Word16 * x, /* i : input vector */ - Word16 frac /* i : fraction (-4..+3) */ +Word16 Interpol_4( /* o : interpolated value */ + Word16 *x, /* i : input vector */ + Word16 frac /* i : fraction (-4..+3) */ ) { - Word16 i; - Word32 L_sum; + Word16 i; + Word32 L_sum; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; + Flag Overflow = 0; #endif - x = x - L_INTERPOL1 + 1; - - L_sum = L_mult(x[0], (inter4_1_fx + UP_SAMP - 1)[-frac]); - FOR(i = 1; i < 2 * L_INTERPOL1; i++) - { - /* - * Here, additions with UP_SAMP are not counted - * because, the window could easily be modified - * so that the values needed are contiguous. - */ - frac -= UP_SAMP; - L_sum = L_mac(L_sum, x[i], (inter4_1_fx + UP_SAMP - 1)[-frac]); - } - BASOP_SATURATE_WARNING_OFF_EVS + x = x - L_INTERPOL1 + 1; + + L_sum = L_mult( x[0], ( inter4_1_fx + UP_SAMP - 1 )[-frac] ); + FOR( i = 1; i < 2 * L_INTERPOL1; i++ ) + { + /* + * Here, additions with UP_SAMP are not counted + * because, the window could easily be modified + * so that the values needed are contiguous. + */ + frac -= UP_SAMP; + L_sum = L_mac( L_sum, x[i], ( inter4_1_fx + UP_SAMP - 1 )[-frac] ); + } + BASOP_SATURATE_WARNING_OFF_EVS /* Here, saturation might occur by intention */ #ifdef BASOP_NOGLOB - L_sum = L_shl_o(L_sum, 1, &Overflow); -#else /* BASOP_NOGLOB */ - L_sum = L_shl(L_sum, 1); + L_sum = L_shl_o( L_sum, 1, &Overflow ); +#else /* BASOP_NOGLOB */ + L_sum = L_shl( L_sum, 1 ); #endif /* BASOP_NOGLOB */ - BASOP_SATURATE_WARNING_ON_EVS + BASOP_SATURATE_WARNING_ON_EVS #ifdef BASOP_NOGLOB - return round_fx_o(L_sum, &Overflow); + return round_fx_o( L_sum, &Overflow ); #else /* BASOP_NOGLOB */ - return round_fx(L_sum); + return round_fx( L_sum ); #endif } diff --git a/lib_com/isf_dec_amr_wb_fx.c b/lib_com/isf_dec_amr_wb_fx.c index 52aec845f..b97bee56d 100644 --- a/lib_com/isf_dec_amr_wb_fx.c +++ b/lib_com/isf_dec_amr_wb_fx.c @@ -31,143 +31,145 @@ *******************************************************************************************************/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx2.h" /* Function prototypes */ #ifdef _MSC_VER -void E_LPC_isf_isp_conversion(const Word16 isf[], Word16 isp[], const Word16 m); +void E_LPC_isf_isp_conversion( const Word16 isf[], Word16 isp[], const Word16 m ); #endif /*---------------------------------------------------------------------* -* isf_dec_amr_wb() -* -* Decoding of ISF parameters in AMR-WB IO mode -*---------------------------------------------------------------------*/ + * isf_dec_amr_wb() + * + * Decoding of ISF parameters in AMR-WB IO mode + *---------------------------------------------------------------------*/ void isf_dec_amr_wb_fx( - Decoder_State *st, /* i/o: State structure */ - Word16 *Aq, /* o : quantized A(z) for 4 subframes */ - Word16 *isf_new, /* o : de-quantized ISF vector */ - Word16 *isp_new /* o : de-quantized ISP vector */ + Decoder_State *st, /* i/o: State structure */ + Word16 *Aq, /* o : quantized A(z) for 4 subframes */ + Word16 *isf_new, /* o : de-quantized ISF vector */ + Word16 *isp_new /* o : de-quantized ISP vector */ ) { - Word16 i; - Word16 indice[7]; - Word32 L_tmp; - - set16_fx(indice, -1, 7); - - /*---------------------------------* - * ISF de-quantization of SID frames - *---------------------------------*/ - - IF(EQ_32(st->core_brate, SID_1k75)) - { - - indice[0] = (Word16)get_next_indice(st, 6); - move16(); - indice[1] = (Word16)get_next_indice(st, 6); - move16(); - indice[2] = (Word16)get_next_indice(st, 6); - move16(); - indice[3] = (Word16)get_next_indice(st, 5); - move16(); - indice[4] = (Word16)get_next_indice(st, 5); - move16(); - - disf_ns_28b_fx(indice, isf_new); - - reorder_isf_fx(isf_new, ISF_GAP_FX, M, Fs_2); - - E_LPC_isf_isp_conversion(isf_new, isp_new, M); - /* return if SID frame (conversion to A(z) done in the calling function) */ - return; - } - - /*-----------------------------------------------------------------* - * ISF de-quantization of all other frames - *-----------------------------------------------------------------*/ - - IF(EQ_32(st->core_brate, ACELP_6k60)) - { - indice[0] = (Word16)get_next_indice(st, 8); - move16(); - indice[1] = (Word16)get_next_indice(st, 8); - move16(); - indice[2] = (Word16)get_next_indice(st, 7); - move16(); - indice[3] = (Word16)get_next_indice(st, 7); - move16(); - indice[4] = (Word16)get_next_indice(st, 6); - move16(); - - disf_2s_36b_fx(indice, isf_new, st->mem_AR_fx, st->mem_MA_fx, 1); - } - ELSE - { - indice[0] = (Word16)get_next_indice(st, 8); - move16(); - indice[1] = (Word16)get_next_indice(st, 8); - move16(); - indice[2] = (Word16)get_next_indice(st, 6); - move16(); - indice[3] = (Word16)get_next_indice(st, 7); - move16(); - indice[4] = (Word16)get_next_indice(st, 7); - move16(); - indice[5] = (Word16)get_next_indice(st, 5); - move16(); - indice[6] = (Word16)get_next_indice(st, 5); - move16(); - - disf_2s_46b_fx(indice, isf_new, st->mem_AR_fx, st->mem_MA_fx,1); - } - reorder_isf_fx(isf_new, ISF_GAP_FX, M, Fs_2); - /* convert quantized ISFs to ISPs */ - E_LPC_isf_isp_conversion(isf_new, isp_new, M); - - /*-------------------------------------------------------------------------------------* - * FEC - update adaptive mean ISF vector - *-------------------------------------------------------------------------------------*/ - - FOR(i = 0; i < M; i++) - { - /*st->lsf_adaptive_mean[i] = (st->lsfoldbfi1[i] + st->lsfoldbfi0[i] + isf_new[i]) / 3;*/ - L_tmp = L_mult(st->lsfoldbfi1_fx[i], 10923); - L_tmp = L_mac(L_tmp, st->lsfoldbfi0_fx[i], 10923); - st->lsf_adaptive_mean_fx[i] = round_fx(L_mac(L_tmp, isf_new[i], 10923)); - } - - /*-------------------------------------------------------------------------------------* - * ISP interpolation - * A(z) calculation - *-------------------------------------------------------------------------------------*/ - - if (st->rate_switching_reset) - { - /*extrapolation instead of interpolation*/ - Copy(isp_new, st->lsp_old_fx, M); - Copy(isf_new, st->lsf_old_fx, M); - } - - /* ISP interpolation and A(z) calculation */ - int_lsp_fx(L_FRAME, st->lsp_old_fx, isp_new, Aq, M, interpol_isp_amr_wb_fx, 1); - - /*------------------------------------------------------------------* - * Check ISF stability : distance between old ISF and current ISF - *------------------------------------------------------------------*/ - - IF(EQ_16(st->element_mode, EVS_MONO)) { - st->stab_fac_fx = lsf_stab_fx(isf_new, st->lsf_old_fx, 1, st->L_frame); + Word16 i; + Word16 indice[7]; + Word32 L_tmp; + + set16_fx( indice, -1, 7 ); + + /*---------------------------------* + * ISF de-quantization of SID frames + *---------------------------------*/ + + IF( EQ_32( st->core_brate, SID_1k75 ) ) + { + + indice[0] = (Word16) get_next_indice( st, 6 ); + move16(); + indice[1] = (Word16) get_next_indice( st, 6 ); + move16(); + indice[2] = (Word16) get_next_indice( st, 6 ); + move16(); + indice[3] = (Word16) get_next_indice( st, 5 ); + move16(); + indice[4] = (Word16) get_next_indice( st, 5 ); + move16(); + + disf_ns_28b_fx( indice, isf_new ); + + reorder_isf_fx( isf_new, ISF_GAP_FX, M, Fs_2 ); + + E_LPC_isf_isp_conversion( isf_new, isp_new, M ); + /* return if SID frame (conversion to A(z) done in the calling function) */ + return; + } + + /*-----------------------------------------------------------------* + * ISF de-quantization of all other frames + *-----------------------------------------------------------------*/ + + IF( EQ_32( st->core_brate, ACELP_6k60 ) ) + { + indice[0] = (Word16) get_next_indice( st, 8 ); + move16(); + indice[1] = (Word16) get_next_indice( st, 8 ); + move16(); + indice[2] = (Word16) get_next_indice( st, 7 ); + move16(); + indice[3] = (Word16) get_next_indice( st, 7 ); + move16(); + indice[4] = (Word16) get_next_indice( st, 6 ); + move16(); + + disf_2s_36b_fx( indice, isf_new, st->mem_AR_fx, st->mem_MA_fx, 1 ); + } + ELSE + { + indice[0] = (Word16) get_next_indice( st, 8 ); + move16(); + indice[1] = (Word16) get_next_indice( st, 8 ); + move16(); + indice[2] = (Word16) get_next_indice( st, 6 ); + move16(); + indice[3] = (Word16) get_next_indice( st, 7 ); + move16(); + indice[4] = (Word16) get_next_indice( st, 7 ); + move16(); + indice[5] = (Word16) get_next_indice( st, 5 ); + move16(); + indice[6] = (Word16) get_next_indice( st, 5 ); + move16(); + + disf_2s_46b_fx( indice, isf_new, st->mem_AR_fx, st->mem_MA_fx, 1 ); + } + reorder_isf_fx( isf_new, ISF_GAP_FX, M, Fs_2 ); + /* convert quantized ISFs to ISPs */ + E_LPC_isf_isp_conversion( isf_new, isp_new, M ); + + /*-------------------------------------------------------------------------------------* + * FEC - update adaptive mean ISF vector + *-------------------------------------------------------------------------------------*/ + + FOR( i = 0; i < M; i++ ) + { + /*st->lsf_adaptive_mean[i] = (st->lsfoldbfi1[i] + st->lsfoldbfi0[i] + isf_new[i]) / 3;*/ + L_tmp = L_mult( st->lsfoldbfi1_fx[i], 10923 ); + L_tmp = L_mac( L_tmp, st->lsfoldbfi0_fx[i], 10923 ); + st->lsf_adaptive_mean_fx[i] = round_fx( L_mac( L_tmp, isf_new[i], 10923 ) ); + } + + /*-------------------------------------------------------------------------------------* + * ISP interpolation + * A(z) calculation + *-------------------------------------------------------------------------------------*/ + + if ( st->rate_switching_reset ) + { + /*extrapolation instead of interpolation*/ + Copy( isp_new, st->lsp_old_fx, M ); + Copy( isf_new, st->lsf_old_fx, M ); } - else { - st->stab_fac_fx = lsf_stab_ivas_fx(isf_new, st->lsf_old_fx, 1, st->L_frame); + + /* ISP interpolation and A(z) calculation */ + int_lsp_fx( L_FRAME, st->lsp_old_fx, isp_new, Aq, M, interpol_isp_amr_wb_fx, 1 ); + + /*------------------------------------------------------------------* + * Check ISF stability : distance between old ISF and current ISF + *------------------------------------------------------------------*/ + + IF( EQ_16( st->element_mode, EVS_MONO ) ) + { + st->stab_fac_fx = lsf_stab_fx( isf_new, st->lsf_old_fx, 1, st->L_frame ); + } + else + { + st->stab_fac_fx = lsf_stab_ivas_fx( isf_new, st->lsf_old_fx, 1, st->L_frame ); } - return; + return; } /*-------------------------------------------------------------------* @@ -177,41 +179,41 @@ void isf_dec_amr_wb_fx( *-------------------------------------------------------------------*/ void disf_ns_28b_fx( - Word16 *indice, /* i : quantized indices (use indice[0] = -1 in the decoder) */ - Word16 *isf_q /* o : ISF in the frequency domain (0..6400) */ + Word16 *indice, /* i : quantized indices (use indice[0] = -1 in the decoder) */ + Word16 *isf_q /* o : ISF in the frequency domain (0..6400) */ ) { - Word16 i; - - FOR(i = 0; i < 2; i++) - { - isf_q[i] = dico1_ns_28b_fx[indice[0] * 2 + i]; - move16(); - } - - FOR(i = 0; i < 3; i++) - { - isf_q[i + 2] = dico2_ns_28b_fx[indice[1] * 3 + i]; - move16(); - isf_q[i + 5] = dico3_ns_28b_fx[indice[2] * 3 + i]; - move16(); - } - - FOR(i = 0; i < 4; i++) - { - isf_q[i + 8] = dico4_ns_28b_fx[indice[3] * 4 + i]; - move16(); - isf_q[i + 12] = dico5_ns_28b_fx[indice[4] * 4 + i]; - move16(); - } - - FOR(i = 0; i < M; i++) - { - isf_q[i] = add(isf_q[i], mean_isf_noise_amr_wb_fx[i]); - move16(); - } - - return; + Word16 i; + + FOR( i = 0; i < 2; i++ ) + { + isf_q[i] = dico1_ns_28b_fx[indice[0] * 2 + i]; + move16(); + } + + FOR( i = 0; i < 3; i++ ) + { + isf_q[i + 2] = dico2_ns_28b_fx[indice[1] * 3 + i]; + move16(); + isf_q[i + 5] = dico3_ns_28b_fx[indice[2] * 3 + i]; + move16(); + } + + FOR( i = 0; i < 4; i++ ) + { + isf_q[i + 8] = dico4_ns_28b_fx[indice[3] * 4 + i]; + move16(); + isf_q[i + 12] = dico5_ns_28b_fx[indice[4] * 4 + i]; + move16(); + } + + FOR( i = 0; i < M; i++ ) + { + isf_q[i] = add( isf_q[i], mean_isf_noise_amr_wb_fx[i] ); + move16(); + } + + return; } /*-------------------------------------------------------------------* @@ -221,68 +223,68 @@ void disf_ns_28b_fx( *-------------------------------------------------------------------*/ void disf_2s_46b_fx( - Word16 *indice, /* i : quantized indices (use indice[0] = -1 in the decoder) */ - Word16 *isf_q, /* o : quantized ISFs in the cosine domain */ - Word16 *mem_AR, /* o : quantizer memory for AR model */ - Word16 *mem_MA, /* i/o: quantizer memory for MA model */ - const Word16 enc_dec /* i : encoder (0), decoder (1) G722.2 FER */ + Word16 *indice, /* i : quantized indices (use indice[0] = -1 in the decoder) */ + Word16 *isf_q, /* o : quantized ISFs in the cosine domain */ + Word16 *mem_AR, /* o : quantizer memory for AR model */ + Word16 *mem_MA, /* i/o: quantizer memory for MA model */ + const Word16 enc_dec /* i : encoder (0), decoder (1) G722.2 FER */ ) { - Word16 i; - - IF(enc_dec != 0) /* Redirection for G722.2 compatibility */ - { - i = 0; - move16(); - WHILE(NE_16(Indirect_dico1[i], indice[0])) - { - i = add(i, 1); - } - indice[0] = i; - move16(); - } - - FOR(i = 0; i < 9; i++) - { - isf_q[i] = dico1_isf_fx[indice[0] * 9 + i]; - move16(); - } - - FOR(i = 0; i < 7; i++) - { - isf_q[i + 9] = dico2_isf_fx[indice[1] * 7 + i]; - move16(); - } - - FOR(i = 0; i < 3; i++) - { - isf_q[i] = add(isf_q[i], dico21_isf_46b_fx[indice[2] * 3 + i]); - move16(); - isf_q[i + 3] = add(isf_q[i + 3], dico22_isf_46b_fx[indice[3] * 3 + i]); - move16(); - isf_q[i + 6] = add(isf_q[i + 6], dico23_isf_46b_fx[indice[4] * 3 + i]); - move16(); - isf_q[i + 9] = add(isf_q[i + 9], dico24_isf_46b_fx[indice[5] * 3 + i]); - move16(); - } - - FOR(i = 0; i < 4; i++) - { - isf_q[i + 12] = add(isf_q[i + 12], dico25_isf_46b_fx[indice[6] * 4 + i]); - move16(); - } - - FOR(i = 0; i < M; i++) - { - mem_AR[i] = add(isf_q[i], mult_r(MU_MA_FX, mem_MA[i])); - move16(); /* Update with quantized ISF vector for AR model */ - mem_MA[i] = isf_q[i]; - move16(); /* Update with quantized prediction error for MA model */ - isf_q[i] = add(mem_AR[i], mean_isf_amr_wb_fx[i]); - move16(); /* Quantized ISFs */ - } - - return; + Word16 i; + + IF( enc_dec != 0 ) /* Redirection for G722.2 compatibility */ + { + i = 0; + move16(); + WHILE( NE_16( Indirect_dico1[i], indice[0] ) ) + { + i = add( i, 1 ); + } + indice[0] = i; + move16(); + } + + FOR( i = 0; i < 9; i++ ) + { + isf_q[i] = dico1_isf_fx[indice[0] * 9 + i]; + move16(); + } + + FOR( i = 0; i < 7; i++ ) + { + isf_q[i + 9] = dico2_isf_fx[indice[1] * 7 + i]; + move16(); + } + + FOR( i = 0; i < 3; i++ ) + { + isf_q[i] = add( isf_q[i], dico21_isf_46b_fx[indice[2] * 3 + i] ); + move16(); + isf_q[i + 3] = add( isf_q[i + 3], dico22_isf_46b_fx[indice[3] * 3 + i] ); + move16(); + isf_q[i + 6] = add( isf_q[i + 6], dico23_isf_46b_fx[indice[4] * 3 + i] ); + move16(); + isf_q[i + 9] = add( isf_q[i + 9], dico24_isf_46b_fx[indice[5] * 3 + i] ); + move16(); + } + + FOR( i = 0; i < 4; i++ ) + { + isf_q[i + 12] = add( isf_q[i + 12], dico25_isf_46b_fx[indice[6] * 4 + i] ); + move16(); + } + + FOR( i = 0; i < M; i++ ) + { + mem_AR[i] = add( isf_q[i], mult_r( MU_MA_FX, mem_MA[i] ) ); + move16(); /* Update with quantized ISF vector for AR model */ + mem_MA[i] = isf_q[i]; + move16(); /* Update with quantized prediction error for MA model */ + isf_q[i] = add( mem_AR[i], mean_isf_amr_wb_fx[i] ); + move16(); /* Quantized ISFs */ + } + + return; } @@ -293,70 +295,70 @@ void disf_2s_46b_fx( *-------------------------------------------------------------------*/ void disf_2s_36b_fx( - Word16 *indice, /* i : quantized indices (use indice[0] = -1 in the decoder) */ - Word16 *isf_q, /* o : quantized ISFs in the cosine domain */ - Word16 *mem_AR, /* i/o: quantizer memory for AR model */ - Word16 *mem_MA, /* i/o: quantizer memory for MA model */ - const Word16 enc_dec /* i : encoder (0), decoder (1) G722.2 FER */ + Word16 *indice, /* i : quantized indices (use indice[0] = -1 in the decoder) */ + Word16 *isf_q, /* o : quantized ISFs in the cosine domain */ + Word16 *mem_AR, /* i/o: quantizer memory for AR model */ + Word16 *mem_MA, /* i/o: quantizer memory for MA model */ + const Word16 enc_dec /* i : encoder (0), decoder (1) G722.2 FER */ ) { - Word16 i; - const Word16 *pt_dico1; - - IF(enc_dec != 0) /* Redirection for G722.2 interoperability */ - { - i = 0; - move16(); - WHILE(NE_16(Indirect_dico1[i], indice[0])) - { - i = add(i, 1); - } - indice[0] = i; - move16(); - } - - - pt_dico1 = dico1_isf_fx; /* Pointer of the 1st stage, 1st plit */ - - FOR(i = 0; i < 9; i++) - { - isf_q[i] = pt_dico1[indice[0] * 9 + i]; - move16(); - } - - FOR(i = 0; i < 7; i++) - { - isf_q[i + 9] = dico2_isf_fx[indice[1] * 7 + i]; - move16(); - } - - FOR(i = 0; i < 5; i++) - { - isf_q[i] = add(isf_q[i], dico21_isf_36b_fx[indice[2] * 5 + i]); - move16(); - } - - FOR(i = 0; i < 4; i++) - { - isf_q[i + 5] = add(isf_q[i + 5], dico22_isf_36b_fx[indice[3] * 4 + i]); - move16(); - } - - FOR(i = 0; i < 7; i++) - { - isf_q[i + 9] = add(isf_q[i + 9], dico23_isf_36b_fx[indice[4] * 7 + i]); - move16(); - } - - FOR(i = 0; i < M; i++) - { - mem_AR[i] = add(isf_q[i], mult_r(MU_MA_FX, mem_MA[i])); - move16(); /* Update with quantized ISF vector for AR model */ - mem_MA[i] = isf_q[i]; - move16(); /* Update with quantized prediction error for MA model */ - isf_q[i] = mem_AR[i] + mean_isf_amr_wb_fx[i]; - move16(); /* Quantized ISFs */ - } - - return; + Word16 i; + const Word16 *pt_dico1; + + IF( enc_dec != 0 ) /* Redirection for G722.2 interoperability */ + { + i = 0; + move16(); + WHILE( NE_16( Indirect_dico1[i], indice[0] ) ) + { + i = add( i, 1 ); + } + indice[0] = i; + move16(); + } + + + pt_dico1 = dico1_isf_fx; /* Pointer of the 1st stage, 1st plit */ + + FOR( i = 0; i < 9; i++ ) + { + isf_q[i] = pt_dico1[indice[0] * 9 + i]; + move16(); + } + + FOR( i = 0; i < 7; i++ ) + { + isf_q[i + 9] = dico2_isf_fx[indice[1] * 7 + i]; + move16(); + } + + FOR( i = 0; i < 5; i++ ) + { + isf_q[i] = add( isf_q[i], dico21_isf_36b_fx[indice[2] * 5 + i] ); + move16(); + } + + FOR( i = 0; i < 4; i++ ) + { + isf_q[i + 5] = add( isf_q[i + 5], dico22_isf_36b_fx[indice[3] * 4 + i] ); + move16(); + } + + FOR( i = 0; i < 7; i++ ) + { + isf_q[i + 9] = add( isf_q[i + 9], dico23_isf_36b_fx[indice[4] * 7 + i] ); + move16(); + } + + FOR( i = 0; i < M; i++ ) + { + mem_AR[i] = add( isf_q[i], mult_r( MU_MA_FX, mem_MA[i] ) ); + move16(); /* Update with quantized ISF vector for AR model */ + mem_MA[i] = isf_q[i]; + move16(); /* Update with quantized prediction error for MA model */ + isf_q[i] = mem_AR[i] + mean_isf_amr_wb_fx[i]; + move16(); /* Quantized ISFs */ + } + + return; } diff --git a/lib_com/ivas_agc_com.c b/lib_com/ivas_agc_com.c index 2059a1384..97cad5ed7 100644 --- a/lib_com/ivas_agc_com.c +++ b/lib_com/ivas_agc_com.c @@ -109,4 +109,3 @@ void ivas_agc_calcGainParams( return; } - diff --git a/lib_com/ivas_agc_com_fx.c b/lib_com/ivas_agc_com_fx.c index 20a045973..3b8a95e93 100644 --- a/lib_com/ivas_agc_com_fx.c +++ b/lib_com/ivas_agc_com_fx.c @@ -107,25 +107,25 @@ void ivas_agc_calcGainParams_fx( UWord16 *maxAttExp, const Word16 numCoeffs ) { - //Word16 totExp; - //Word16 Bm; - //Word16 nbits; + // Word16 totExp; + // Word16 Bm; + // Word16 nbits; - //nbits = NBITS_DIFFG; + // nbits = NBITS_DIFFG; assert( EQ_16( numCoeffs, IVAS_SPAR_MAX_DMX_CHS ) ); *absEmin = s_max( ABS_EMIN_MAX, LOG2_NUMCOEFF_SQRKMAX ); - //totExp = add( add( *absEmin, AGC_EMAX ), 1 ); + // totExp = add( add( *absEmin, AGC_EMAX ), 1 ); /**betaE = (UWord16)ceilf(logf(totExp) * INV_LOG_2);*/ *betaE = (UWord16) LOG2_4; /*Bm = (UWord16)ceilf(logf((AGC_EMAX + 1 + 1)) * INV_LOG_2);*/ - //Bm = 1; + // Bm = 1; - //IF( GT_16( nbits, 0 ) ) + // IF( GT_16( nbits, 0 ) ) //{ - // Bm = s_min( AGC_BITS_PER_CH - 1, NBITS_DIFFG ); - //} + // Bm = s_min( AGC_BITS_PER_CH - 1, NBITS_DIFFG ); + // } /**maxAttExp = ((UWord16) powf( 2, Bm ) ) - 2;*/ *maxAttExp = sub( shl( 2, 1 ), 2 ); diff --git a/lib_com/ivas_dirac_com.c b/lib_com/ivas_dirac_com.c index f0f82bf97..8a37462d4 100644 --- a/lib_com/ivas_dirac_com.c +++ b/lib_com/ivas_dirac_com.c @@ -100,7 +100,7 @@ Word16 ivas_get_hodirac_flag_fx( *------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED ivas_error ivas_dirac_config_fx( - void *st_ivas, /* i/o: IVAS encoder/decoder state structure */ + void *st_ivas, /* i/o: IVAS encoder/decoder state structure */ const Word16 enc_dec /* i : encoder or decoder flag */ ) { @@ -119,20 +119,20 @@ ivas_error ivas_dirac_config_fx( error = IVAS_ERR_OK; - IF ( EQ_16(enc_dec , ENC)) + IF( EQ_16( enc_dec, ENC ) ) { - ivas_format = ((Encoder_Struct *)st_ivas)->hEncoderConfig->ivas_format; - element_mode = &((Encoder_Struct *)st_ivas)->hEncoderConfig->element_mode_init; - sba_order = ((Encoder_Struct *)st_ivas)->sba_analysis_order; - ivas_total_brate = ((Encoder_Struct *)st_ivas)->hEncoderConfig->ivas_total_brate; - Fs = ((Encoder_Struct *)st_ivas)->hEncoderConfig->input_Fs; - band_grouping = ((Encoder_Struct *)st_ivas)->hDirAC->band_grouping; - hConfig = ((Encoder_Struct *)st_ivas)->hDirAC->hConfig; - hQMetaData = ((Encoder_Struct *)st_ivas)->hQMetaData; - IF (((Encoder_Struct *)st_ivas)->hSpar != NULL) + ivas_format = ( (Encoder_Struct *) st_ivas )->hEncoderConfig->ivas_format; + element_mode = &( (Encoder_Struct *) st_ivas )->hEncoderConfig->element_mode_init; + sba_order = ( (Encoder_Struct *) st_ivas )->sba_analysis_order; + ivas_total_brate = ( (Encoder_Struct *) st_ivas )->hEncoderConfig->ivas_total_brate; + Fs = ( (Encoder_Struct *) st_ivas )->hEncoderConfig->input_Fs; + band_grouping = ( (Encoder_Struct *) st_ivas )->hDirAC->band_grouping; + hConfig = ( (Encoder_Struct *) st_ivas )->hDirAC->hConfig; + hQMetaData = ( (Encoder_Struct *) st_ivas )->hQMetaData; + IF( ( (Encoder_Struct *) st_ivas )->hSpar != NULL ) { - hFbMdft = ((Encoder_Struct *)st_ivas)->hSpar->hFbMixer; - dirac_to_spar_md_bands = ((Encoder_Struct *)st_ivas)->hSpar->dirac_to_spar_md_bands; + hFbMdft = ( (Encoder_Struct *) st_ivas )->hSpar->hFbMixer; + dirac_to_spar_md_bands = ( (Encoder_Struct *) st_ivas )->hSpar->dirac_to_spar_md_bands; } ELSE { @@ -142,34 +142,34 @@ ivas_error ivas_dirac_config_fx( } ELSE { - ivas_format = ((Decoder_Struct *)st_ivas)->ivas_format; - element_mode = &((Decoder_Struct *)st_ivas)->element_mode_init; - sba_order = ((Decoder_Struct *)st_ivas)->sba_analysis_order; - ivas_total_brate = ((Decoder_Struct *)st_ivas)->hDecoderConfig->ivas_total_brate; - Fs = ((Decoder_Struct *)st_ivas)->hDecoderConfig->output_Fs; - band_grouping = ((Decoder_Struct *)st_ivas)->hDirAC->band_grouping; - hConfig = ((Decoder_Struct *)st_ivas)->hDirAC->hConfig; - hQMetaData = ((Decoder_Struct *)st_ivas)->hQMetaData; - IF (((Decoder_Struct *)st_ivas)->hSpar != NULL) + ivas_format = ( (Decoder_Struct *) st_ivas )->ivas_format; + element_mode = &( (Decoder_Struct *) st_ivas )->element_mode_init; + sba_order = ( (Decoder_Struct *) st_ivas )->sba_analysis_order; + ivas_total_brate = ( (Decoder_Struct *) st_ivas )->hDecoderConfig->ivas_total_brate; + Fs = ( (Decoder_Struct *) st_ivas )->hDecoderConfig->output_Fs; + band_grouping = ( (Decoder_Struct *) st_ivas )->hDirAC->band_grouping; + hConfig = ( (Decoder_Struct *) st_ivas )->hDirAC->hConfig; + hQMetaData = ( (Decoder_Struct *) st_ivas )->hQMetaData; + IF( ( (Decoder_Struct *) st_ivas )->hSpar != NULL ) { - hFbMdft = ((Decoder_Struct *)st_ivas)->hSpar->hFbMixer; - dirac_to_spar_md_bands = ((Decoder_Struct *)st_ivas)->hSpar->dirac_to_spar_md_bands; + hFbMdft = ( (Decoder_Struct *) st_ivas )->hSpar->hFbMixer; + dirac_to_spar_md_bands = ( (Decoder_Struct *) st_ivas )->hSpar->dirac_to_spar_md_bands; } ELSE { hFbMdft = NULL; dirac_to_spar_md_bands = NULL; } - ((Decoder_Struct *)st_ivas)->hDirAC->hFbMdft = hFbMdft; + ( (Decoder_Struct *) st_ivas )->hDirAC->hFbMdft = hFbMdft; } - IF (ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT) + IF( ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT ) { hConfig->nbands = IVAS_MAX_NUM_BANDS; - spar_dirac_split_band = s_min(IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND); + spar_dirac_split_band = s_min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND ); - IF (ivas_get_hodirac_flag(ivas_total_brate, sba_order))//add call after merge of 100861_dirac_dec + IF( ivas_get_hodirac_flag( ivas_total_brate, sba_order ) ) // add call after merge of 100861_dirac_dec { spar_dirac_split_band = 0; } @@ -181,47 +181,47 @@ ivas_error ivas_dirac_config_fx( } hConfig->enc_param_start_band = 0; hConfig->dec_param_estim = FALSE; - IF (ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT) /* skip for MASA decoder */ + IF( ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT ) /* skip for MASA decoder */ { - IF ((error = ivas_dirac_sba_config_fx(hQMetaData, element_mode, ivas_total_brate, sba_order, hConfig->nbands - spar_dirac_split_band, - ivas_format)) != IVAS_ERR_OK) + IF( ( error = ivas_dirac_sba_config_fx( hQMetaData, element_mode, ivas_total_brate, sba_order, hConfig->nbands - spar_dirac_split_band, + ivas_format ) ) != IVAS_ERR_OK ) { return error; } - IF (hQMetaData != NULL) + IF( hQMetaData != NULL ) { - IF (enc_dec == ENC) + IF( enc_dec == ENC ) { hConfig->nbands = hQMetaData->q_direction[0].cfg.nbands; } - hConfig->enc_param_start_band = add(hQMetaData->q_direction[0].cfg.start_band , spar_dirac_split_band); + hConfig->enc_param_start_band = add( hQMetaData->q_direction[0].cfg.start_band, spar_dirac_split_band ); } hConfig->dec_param_estim = TRUE; - IF (hConfig->dec_param_estim == TRUE) + IF( hConfig->dec_param_estim == TRUE ) { hConfig->enc_param_start_band = spar_dirac_split_band; } - IF (ivas_get_hodirac_flag(ivas_total_brate, sba_order)) + IF( ivas_get_hodirac_flag( ivas_total_brate, sba_order ) ) { hConfig->dec_param_estim = FALSE; hConfig->enc_param_start_band = 0; - set_c((int8_t *)hQMetaData->twoDirBands, (int8_t)1, hQMetaData->q_direction[0].cfg.nbands); - hQMetaData->numTwoDirBands = (uint8_t)hQMetaData->q_direction[0].cfg.nbands; + set_c( (int8_t *) hQMetaData->twoDirBands, (int8_t) 1, hQMetaData->q_direction[0].cfg.nbands ); + hQMetaData->numTwoDirBands = (uint8_t) hQMetaData->q_direction[0].cfg.nbands; } } - IF (ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT) + IF( ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT ) { - //100861_dirac_dec - ivas_dirac_config_bands(band_grouping, IVAS_MAX_NUM_BANDS, (Word16)(Fs * INV_CLDFB_BANDWIDTH + 0.5f), dirac_to_spar_md_bands, hQMetaData->useLowerBandRes, hConfig->enc_param_start_band, hFbMdft); + // 100861_dirac_dec + ivas_dirac_config_bands( band_grouping, IVAS_MAX_NUM_BANDS, (Word16) ( Fs * INV_CLDFB_BANDWIDTH + 0.5f ), dirac_to_spar_md_bands, hQMetaData->useLowerBandRes, hConfig->enc_param_start_band, hFbMdft ); } ELSE { - ivas_dirac_config_bands(band_grouping, hConfig->nbands, (Word16)(Fs * INV_CLDFB_BANDWIDTH + 0.5f), NULL, 0, 0, hFbMdft); + ivas_dirac_config_bands( band_grouping, hConfig->nbands, (Word16) ( Fs * INV_CLDFB_BANDWIDTH + 0.5f ), NULL, 0, 0, hFbMdft ); } return error; @@ -587,52 +587,52 @@ void ivas_get_dirac_sba_max_md_bits_fx( const Word16 nbands, IVAS_FORMAT ivas_format ) { - IF ( sba_total_brate <= IVAS_13k2 ) + IF( sba_total_brate <= IVAS_13k2 ) { *bits_frame_nominal = ACELP_9k60 / FRAMES_PER_SEC; *metadata_max_bits = 70; } - ELSE IF ( sba_total_brate <= IVAS_16k4 ) + ELSE IF( sba_total_brate <= IVAS_16k4 ) { *bits_frame_nominal = ACELP_13k20 / FRAMES_PER_SEC; *metadata_max_bits = 80; } - ELSE IF ( sba_total_brate <= IVAS_24k4 ) + ELSE IF( sba_total_brate <= IVAS_24k4 ) { *bits_frame_nominal = ACELP_16k40 / FRAMES_PER_SEC; *metadata_max_bits = 103; /* OSBA needs an additional 2-bits safety margin to avoid acelp crashes */ - IF ( ivas_format == SBA_ISM_FORMAT ) + IF( ivas_format == SBA_ISM_FORMAT ) { - ( *metadata_max_bits ) = sub((*metadata_max_bits), 3); + ( *metadata_max_bits ) = sub( ( *metadata_max_bits ), 3 ); } } - ELSE IF ( sba_total_brate <= IVAS_32k ) + ELSE IF( sba_total_brate <= IVAS_32k ) { *bits_frame_nominal = ACELP_32k / FRAMES_PER_SEC; *metadata_max_bits = 214; } - ELSE IF ( sba_total_brate <= IVAS_48k ) + ELSE IF( sba_total_brate <= IVAS_48k ) { *bits_frame_nominal = IVAS_48k / FRAMES_PER_SEC; *metadata_max_bits = 240; } - ELSE IF ( sba_total_brate <= IVAS_64k ) + ELSE IF( sba_total_brate <= IVAS_64k ) { *bits_frame_nominal = IVAS_64k / FRAMES_PER_SEC; *metadata_max_bits = 200; } - ELSE IF ( sba_total_brate <= IVAS_80k ) + ELSE IF( sba_total_brate <= IVAS_80k ) { *bits_frame_nominal = IVAS_80k / FRAMES_PER_SEC; *metadata_max_bits = 200; } - ELSE IF ( sba_total_brate <= IVAS_96k ) + ELSE IF( sba_total_brate <= IVAS_96k ) { *bits_frame_nominal = IVAS_96k / FRAMES_PER_SEC; *metadata_max_bits = 200; } - ELSE IF ( sba_total_brate <= IVAS_128k ) + ELSE IF( sba_total_brate <= IVAS_128k ) { *bits_frame_nominal = IVAS_128k / FRAMES_PER_SEC; *metadata_max_bits = 250; @@ -641,31 +641,35 @@ void ivas_get_dirac_sba_max_md_bits_fx( { //*bits_frame_nominal = (int16_t) ( sba_total_brate / FRAMES_PER_SEC ); Word16 tmp_exp = 0, tmp; - tmp = BASOP_Util_Divide3232_Scale(sba_total_brate, FRAMES_PER_SEC, &tmp_exp); - *bits_frame_nominal = shr(tmp, 15 - tmp_exp); + tmp = BASOP_Util_Divide3232_Scale( sba_total_brate, FRAMES_PER_SEC, &tmp_exp ); + *bits_frame_nominal = shr( tmp, 15 - tmp_exp ); *metadata_max_bits = MAX16B; /* no limit */ } - Word32 var1 = L_mult0(*metadata_max_bits, nbands); + Word32 var1 = L_mult0( *metadata_max_bits, nbands ); Word16 exp = 0; - Word16 var2 = BASOP_Util_Divide3232_Scale(var1, 5, &exp); - Word32 var2_32 = L_deposit_h(var2); + Word16 var2 = BASOP_Util_Divide3232_Scale( var1, 5, &exp ); + Word32 var2_32 = L_deposit_h( var2 ); Word32 var4 = var2_32; - + Word16 exp_res = 0; - IF (var1 % 5 != 0) { - var4 = BASOP_Util_Add_Mant32Exp(var2_32, exp, ONE_IN_Q30, 1, &exp_res); + IF( var1 % 5 != 0 ) + { + var4 = BASOP_Util_Add_Mant32Exp( var2_32, exp, ONE_IN_Q30, 1, &exp_res ); exp = exp_res; } - Word16 flag = BASOP_Util_Cmp_Mant32Exp(MAX16B, 31, var4, exp); + Word16 flag = BASOP_Util_Cmp_Mant32Exp( MAX16B, 31, var4, exp ); Word32 tmp; - if (flag == 1) { + if ( flag == 1 ) + { tmp = var4; } - else { + else + { tmp = MAX16B; exp = 31; } - *metadata_max_bits = (Word16)L_shr(tmp, 31 - exp);; + *metadata_max_bits = (Word16) L_shr( tmp, 31 - exp ); + ; *qmetadata_max_bit_req = QMETADATA_MAXBIT_REQ_SBA >> 1; return; @@ -678,64 +682,64 @@ void ivas_get_dirac_sba_max_md_bits( int16_t *metadata_max_bits, int16_t *qmetadata_max_bit_req, const int16_t nbands, - IVAS_FORMAT ivas_format) + IVAS_FORMAT ivas_format ) { - if (sba_total_brate <= IVAS_13k2) + if ( sba_total_brate <= IVAS_13k2 ) { *bits_frame_nominal = ACELP_9k60 / FRAMES_PER_SEC; *metadata_max_bits = 70; } - else if (sba_total_brate <= IVAS_16k4) + else if ( sba_total_brate <= IVAS_16k4 ) { *bits_frame_nominal = ACELP_13k20 / FRAMES_PER_SEC; *metadata_max_bits = 80; } - else if (sba_total_brate <= IVAS_24k4) + else if ( sba_total_brate <= IVAS_24k4 ) { *bits_frame_nominal = ACELP_16k40 / FRAMES_PER_SEC; *metadata_max_bits = 103; /* OSBA needs an additional 2-bits safety margin to avoid acelp crashes */ - if (ivas_format == SBA_ISM_FORMAT) + if ( ivas_format == SBA_ISM_FORMAT ) { - (*metadata_max_bits) -= 3; + ( *metadata_max_bits ) -= 3; } } - else if (sba_total_brate <= IVAS_32k) + else if ( sba_total_brate <= IVAS_32k ) { *bits_frame_nominal = ACELP_32k / FRAMES_PER_SEC; *metadata_max_bits = 214; } - else if (sba_total_brate <= IVAS_48k) + else if ( sba_total_brate <= IVAS_48k ) { *bits_frame_nominal = IVAS_48k / FRAMES_PER_SEC; *metadata_max_bits = 240; } - else if (sba_total_brate <= IVAS_64k) + else if ( sba_total_brate <= IVAS_64k ) { *bits_frame_nominal = IVAS_64k / FRAMES_PER_SEC; *metadata_max_bits = 200; } - else if (sba_total_brate <= IVAS_80k) + else if ( sba_total_brate <= IVAS_80k ) { *bits_frame_nominal = IVAS_80k / FRAMES_PER_SEC; *metadata_max_bits = 200; } - else if (sba_total_brate <= IVAS_96k) + else if ( sba_total_brate <= IVAS_96k ) { *bits_frame_nominal = IVAS_96k / FRAMES_PER_SEC; *metadata_max_bits = 200; } - else if (sba_total_brate <= IVAS_128k) + else if ( sba_total_brate <= IVAS_128k ) { *bits_frame_nominal = IVAS_128k / FRAMES_PER_SEC; *metadata_max_bits = 250; } else { - *bits_frame_nominal = (int16_t)(sba_total_brate / FRAMES_PER_SEC); + *bits_frame_nominal = (int16_t) ( sba_total_brate / FRAMES_PER_SEC ); *metadata_max_bits = MAX16B; /* no limit */ } - *metadata_max_bits = (int16_t)min((float)MAX16B, ceilf((float)*metadata_max_bits * nbands / 5)); + *metadata_max_bits = (int16_t) min( (float) MAX16B, ceilf( (float) *metadata_max_bits * nbands / 5 ) ); *qmetadata_max_bit_req = QMETADATA_MAXBIT_REQ_SBA >> 1; return; @@ -749,12 +753,12 @@ void ivas_get_dirac_sba_max_md_bits( #ifdef IVAS_FLOAT_FIXED ivas_error ivas_dirac_sba_config_fx( IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ - Word16 *element_mode, /* i/o: element mode of the core coder */ - Word32 sba_total_brate, /* i : SBA total bitrate */ - const Word16 sba_order, /* i : Ambisonic (SBA) order */ - const Word16 nbands /* i : number of frequency bands */ + Word16 *element_mode, /* i/o: element mode of the core coder */ + Word32 sba_total_brate, /* i : SBA total bitrate */ + const Word16 sba_order, /* i : Ambisonic (SBA) order */ + const Word16 nbands /* i : number of frequency bands */ , - IVAS_FORMAT ivas_format) + IVAS_FORMAT ivas_format ) { Word16 nbands_coded; Word16 hodirac_flag; @@ -763,17 +767,17 @@ ivas_error ivas_dirac_sba_config_fx( Word32 tmp1 = IVAS_192k; Word32 tmp2 = SPAR_DIRAC_SPLIT_START_BAND; Word16 exp = 0; - Word16 tmp3 = BASOP_Util_Divide3232_Scale(tmp1, tmp2, &exp); - Word32 res = L_shr(L_deposit_h(tmp3), 31 - exp); + Word16 tmp3 = BASOP_Util_Divide3232_Scale( tmp1, tmp2, &exp ); + Word32 res = L_shr( L_deposit_h( tmp3 ), 31 - exp ); error = IVAS_ERR_OK; hQMetaData->is_masa_ivas_format = 0; - hodirac_flag = ivas_get_hodirac_flag(sba_total_brate, sba_order);//implemented on 100861_dirac_dec + hodirac_flag = ivas_get_hodirac_flag( sba_total_brate, sba_order ); // implemented on 100861_dirac_dec /* map the bitrate for SID frame */ - IF (EQ_32(sba_total_brate , IVAS_SID_5k2)) + IF( EQ_32( sba_total_brate, IVAS_SID_5k2 ) ) { - IF (EQ_16(*element_mode , IVAS_SCE)) + IF( EQ_16( *element_mode, IVAS_SCE ) ) { sba_total_brate = ACELP_24k40; } @@ -783,9 +787,9 @@ ivas_error ivas_dirac_sba_config_fx( } } - ivas_set_qmetadata_maxbit_req(hQMetaData, SBA_FORMAT); + ivas_set_qmetadata_maxbit_req( hQMetaData, SBA_FORMAT ); - IF (LE_32(sba_total_brate , IVAS_16k4)) + IF( LE_32( sba_total_brate, IVAS_16k4 ) ) { hQMetaData->useLowerRes = 1; } @@ -795,17 +799,17 @@ ivas_error ivas_dirac_sba_config_fx( } nbands_coded = nbands; - - IF (LE_32(sba_total_brate , res)) + + IF( LE_32( sba_total_brate, res ) ) { hQMetaData->useLowerBandRes = 1; Word16 tmp = nbands % 2; - nbands_coded = add(shr(nbands, 1) , tmp); + nbands_coded = add( shr( nbands, 1 ), tmp ); } ELSE { hQMetaData->useLowerBandRes = 0; - IF (hodirac_flag == 0) + IF( hodirac_flag == 0 ) { nbands_coded = nbands - 1; /* always combine the last two bands */ } @@ -813,19 +817,19 @@ ivas_error ivas_dirac_sba_config_fx( { Word16 no_dirs = 1; - IF (hodirac_flag) + IF( hodirac_flag ) { no_dirs = 2; } - IF ((error = ivas_qmetadata_allocate_memory(hQMetaData, nbands_coded, no_dirs, 0)) != IVAS_ERR_OK)//WIP + IF( ( error = ivas_qmetadata_allocate_memory( hQMetaData, nbands_coded, no_dirs, 0 ) ) != IVAS_ERR_OK ) // WIP { return error; } } - ivas_get_dirac_sba_max_md_bits_fx(sba_total_brate, &hQMetaData->bits_frame_nominal, &hQMetaData->metadata_max_bits, &hQMetaData->qmetadata_max_bit_req, hQMetaData->q_direction[0].cfg.nbands, - ivas_format); + ivas_get_dirac_sba_max_md_bits_fx( sba_total_brate, &hQMetaData->bits_frame_nominal, &hQMetaData->metadata_max_bits, &hQMetaData->qmetadata_max_bit_req, hQMetaData->q_direction[0].cfg.nbands, + ivas_format ); return error; } @@ -914,36 +918,36 @@ void computeDirectionVectors_fixed( Word32 *intensity_real_z, const Word16 enc_param_start_band, const Word16 num_frequency_bands, - Word32 *direction_vector_x,/*Q30*/ - Word32 *direction_vector_y,/*Q30*/ - Word32 *direction_vector_z,/*Q30*/ - Word16 i_e /*Exponent of all the intensity buffers*/) + Word32 *direction_vector_x, /*Q30*/ + Word32 *direction_vector_y, /*Q30*/ + Word32 *direction_vector_z, /*Q30*/ + Word16 i_e /*Exponent of all the intensity buffers*/ ) { Word16 i; Word32 intensityNorm; Word16 intensityNorm_e; - Word32 temp1; - Word16 exp1; + Word32 temp1; + Word16 exp1; Word16 norm_x, norm_y, norm_z; Word32 scaled_x, scaled_y, scaled_z; Word16 e_x, e_y, e_z; for ( i = enc_param_start_band; i < enc_param_start_band + num_frequency_bands; ++i ) { norm_x = norm_l( *intensity_real_x ); - norm_y = norm_l( *intensity_real_y); + norm_y = norm_l( *intensity_real_y ); norm_z = norm_l( *intensity_real_z ); scaled_x = L_shl( *intensity_real_x, norm_x ); - scaled_y = L_shl( *intensity_real_y, norm_y); - scaled_z = L_shl( *intensity_real_z, norm_z); + scaled_y = L_shl( *intensity_real_y, norm_y ); + scaled_z = L_shl( *intensity_real_z, norm_z ); e_x = i_e - norm_x; e_y = i_e - norm_y; e_z = i_e - norm_z; - temp1 = BASOP_Util_Add_Mant32Exp( Mult_32_32( scaled_x, scaled_x ), 2*e_x, Mult_32_32( scaled_y, scaled_y ), 2*e_y, &exp1 ); - intensityNorm = BASOP_Util_Add_Mant32Exp( temp1, exp1, Mult_32_32( scaled_z, scaled_z ), 2 * e_z, &intensityNorm_e); + temp1 = BASOP_Util_Add_Mant32Exp( Mult_32_32( scaled_x, scaled_x ), 2 * e_x, Mult_32_32( scaled_y, scaled_y ), 2 * e_y, &exp1 ); + intensityNorm = BASOP_Util_Add_Mant32Exp( temp1, exp1, Mult_32_32( scaled_z, scaled_z ), 2 * e_z, &intensityNorm_e ); - IF ( LE_32(intensityNorm , EPSILON_FX) ) + IF( LE_32( intensityNorm, EPSILON_FX ) ) { - intensityNorm = L_shl(1, intensityNorm_e); + intensityNorm = L_shl( 1, intensityNorm_e ); *( direction_vector_x++ ) = ONE_IN_Q30; *( direction_vector_y++ ) = 0; *( direction_vector_z++ ) = 0; @@ -953,12 +957,12 @@ void computeDirectionVectors_fixed( } ELSE { - intensityNorm = ISqrt32( intensityNorm, &intensityNorm_e ); /*Q31-intensityNorm_e*/ - *( direction_vector_x++ ) = L_shl(Mult_32_32(scaled_x , intensityNorm),e_x+ intensityNorm_e-1);/*Q30*/ + intensityNorm = ISqrt32( intensityNorm, &intensityNorm_e ); /*Q31-intensityNorm_e*/ + *( direction_vector_x++ ) = L_shl( Mult_32_32( scaled_x, intensityNorm ), e_x + intensityNorm_e - 1 ); /*Q30*/ intensity_real_x++; - *( direction_vector_y++ ) = L_shl(Mult_32_32( scaled_y, intensityNorm ), e_y+ intensityNorm_e-1);/*Q30*/ + *( direction_vector_y++ ) = L_shl( Mult_32_32( scaled_y, intensityNorm ), e_y + intensityNorm_e - 1 ); /*Q30*/ intensity_real_y++; - *( direction_vector_z++ ) = L_shl(Mult_32_32(scaled_z, intensityNorm), e_z + intensityNorm_e-1);/*Q30*/ + *( direction_vector_z++ ) = L_shl( Mult_32_32( scaled_z, intensityNorm ), e_z + intensityNorm_e - 1 ); /*Q30*/ intensity_real_z++; } } @@ -1041,11 +1045,11 @@ void computeDirectionVectors_fx( { intensityNorm = ISqrt32( intensityNorm, &exp ); // Q31-exp Word32 temp = L_shr( Mpy_32_32( *( intensity_real_x++ ), intensityNorm ), ( *i_q - exp - min_factor ) ); - *( direction_vector_x++ ) = temp; // i_q + Q31-exp -31 = i_q -exp + *( direction_vector_x++ ) = temp; // i_q + Q31-exp -31 = i_q -exp temp = L_shr( Mpy_32_32( *( intensity_real_y++ ), intensityNorm ), ( *i_q - exp - min_factor ) ); - *( direction_vector_y++ ) = temp; // i_q + Q31-exp -31 = i_q -exp + *( direction_vector_y++ ) = temp; // i_q + Q31-exp -31 = i_q -exp temp = L_shr( Mpy_32_32( *( intensity_real_z++ ), intensityNorm ), ( *i_q - exp - min_factor ) ); - *( direction_vector_z++ ) = temp; // i_q + Q31-exp-31 = i_q -exp + *( direction_vector_z++ ) = temp; // i_q + Q31-exp-31 = i_q -exp } } *i_q = min_factor; @@ -1162,27 +1166,26 @@ void computeDiffuseness_fx( intensity_slow_abs[k] = L_add( *( p_tmp++ ), intensity_slow_abs[k] ); } } - Word16 init_exp = 31 - (( 2 * ( q_factor_intensity ) ) - 31),exp; - + Word16 init_exp = 31 - ( ( 2 * ( q_factor_intensity ) ) - 31 ), exp; + Word16 exp1 = 0, exp2; /* Compute Diffuseness */ p_tmp = intensity_slow_abs; - for ( i = 0; i < num_freq_bands; ++i ) - { - exp = init_exp; - Word32 temp = *( p_tmp++ ); - tmp_1 = Sqrt32( temp, &exp ); - tmp = L_deposit_h( BASOP_Util_Divide3232_Scale( tmp_1, L_add( energy_slow[i],1 ), &exp1 ) ); - exp2 = 31 - exp1 + (31- exp - q_factor_energy ); - if ( exp2 > 30 ) - { + for ( i = 0; i < num_freq_bands; ++i ) + { + exp = init_exp; + Word32 temp = *( p_tmp++ ); + tmp_1 = Sqrt32( temp, &exp ); + tmp = L_deposit_h( BASOP_Util_Divide3232_Scale( tmp_1, L_add( energy_slow[i], 1 ), &exp1 ) ); + exp2 = 31 - exp1 + ( 31 - exp - q_factor_energy ); + if ( exp2 > 30 ) + { tmp = L_shr( tmp, ( exp2 - 30 ) ); exp2 -= ( exp2 - 30 ); - } - tmp = L_sub( L_shl( 1, exp2 ), tmp ); - diffuseness[i] = ( ( tmp < L_shl( 1, exp2 ) ) ? ( ( tmp < 0 ) ? 0 : tmp ) : L_shl( 1, exp2 ) ); - out_exp[i] = exp2; - + } + tmp = L_sub( L_shl( 1, exp2 ), tmp ); + diffuseness[i] = ( ( tmp < L_shl( 1, exp2 ) ) ? ( ( tmp < 0 ) ? 0 : tmp ) : L_shl( 1, exp2 ) ); + out_exp[i] = exp2; } return; } @@ -2092,4 +2095,4 @@ static UWord16 deindex_sph_idx_general_fx( return id_th; } -#endif \ No newline at end of file +#endif diff --git a/lib_com/ivas_entropy_coder_common.c b/lib_com/ivas_entropy_coder_common.c index 4d7b3c0d8..9dcf13060 100644 --- a/lib_com/ivas_entropy_coder_common.c +++ b/lib_com/ivas_entropy_coder_common.c @@ -56,15 +56,15 @@ void ivas_wrap_arround( { Word16 i; - FOR ( i = 0; i < length; i++ ) + FOR( i = 0; i < length; i++ ) { - IF ( LT_16(pArr[i], min_val) ) + IF( LT_16( pArr[i], min_val ) ) { - pArr[i] = add(sub(max_val, min_val), add( pArr[i], 1)); + pArr[i] = add( sub( max_val, min_val ), add( pArr[i], 1 ) ); } - IF ( GT_16(pArr[i], max_val) ) + IF( GT_16( pArr[i], max_val ) ) { - pArr[i] = sub(add(min_val, pArr[i]), add(max_val, 1)); + pArr[i] = sub( add( min_val, pArr[i] ), add( max_val, 1 ) ); } } @@ -87,9 +87,9 @@ void ivas_get_cum_freq_model( pCum_freq_model[length] = 0; - FOR ( i = length; i > 0; i-- ) + FOR( i = length; i > 0; i-- ) { - pCum_freq_model[i - 1] = add(pCum_freq_model[i], pFreq_model[i]); + pCum_freq_model[i - 1] = add( pCum_freq_model[i], pFreq_model[i] ); } return; @@ -107,9 +107,9 @@ Word16 ivas_map_num_pred_r_to_idx( const Word16 active_w_flag ) { Word16 pred_r_to_idx = -1; - IF ( EQ_16(active_w_flag, 0) ) + IF( EQ_16( active_w_flag, 0 ) ) { - SWITCH ( num_quant_points_pred_r ) + SWITCH( num_quant_points_pred_r ) { case 1: pred_r_to_idx = PRED_Q_1; @@ -133,7 +133,7 @@ Word16 ivas_map_num_pred_r_to_idx( } ELSE { - SWITCH ( num_quant_points_pred_r ) + SWITCH( num_quant_points_pred_r ) { case 7: pred_r_to_idx = PRED_Q_7_ACTIVE_W; @@ -164,7 +164,7 @@ Word16 ivas_map_num_drct_r_to_idx( const Word16 num_quant_points_drct_r ) { Word16 drct_r_to_idx = -1; - SWITCH ( num_quant_points_drct_r ) + SWITCH( num_quant_points_drct_r ) { case 1: drct_r_to_idx = DRCT_Q_1; @@ -196,7 +196,7 @@ Word16 ivas_map_num_decd_r_to_idx( const Word16 num_quant_points_decd_r ) { Word16 decd_r_to_idx = -1; - SWITCH ( num_quant_points_decd_r ) + SWITCH( num_quant_points_decd_r ) { case 1: decd_r_to_idx = DECD_Q_1; @@ -358,56 +358,56 @@ static void ivas_spar_arith_com_init_fx( ivas_get_cum_freq_model( pArith->pFreq_model, pArith->range, pArith->cum_freq[0] ); - FOR ( i = 0; i < pArith->num_models - 1; i++ ) + FOR( i = 0; i < pArith->num_models - 1; i++ ) { pArith->pAlt_freq_models[i] = pFreq_models->freq_model[i + 1]; ivas_get_cum_freq_model( pArith->pAlt_freq_models[i], pArith->range, pArith->cum_freq[i + 1] ); } - IF ( EQ_16(enc_dec, ENC) ) + IF( EQ_16( enc_dec, ENC ) ) { sum = 0; - FOR ( i = 1; i < pArith->range + 1; i++ ) + FOR( i = 1; i < pArith->range + 1; i++ ) { - sum = add(sum, pArith->pFreq_model[i]); + sum = add( sum, pArith->pFreq_model[i] ); } - log2_int = norm_s(sum); + log2_int = norm_s( sum ); tmp32 = L_deposit_h( shl( sum, log2_int ) ); - log2_frac = Log2_norm_lc(tmp32); - log2_int32 = L_shl((Word32)sub(sub(30,log2_int),16), 15); - L_tmp2 = L_add(log2_int32, (Word32)log2_frac); /* Q15 */ - FOR ( i = 1; i < pArith->range + 1; i++ ) + log2_frac = Log2_norm_lc( tmp32 ); + log2_int32 = L_shl( (Word32) sub( sub( 30, log2_int ), 16 ), 15 ); + L_tmp2 = L_add( log2_int32, (Word32) log2_frac ); /* Q15 */ + FOR( i = 1; i < pArith->range + 1; i++ ) { Word32 L_tmp1; - log2_int = norm_s(pArith->pFreq_model[i]); + log2_int = norm_s( pArith->pFreq_model[i] ); tmp32 = L_deposit_h( shl( pArith->pFreq_model[i], log2_int ) ); - log2_frac = Log2_norm_lc(tmp32); - log2_int32 = L_shl((Word32)sub(sub(30,log2_int),16), 15); - L_tmp1 = L_add(log2_int32, (Word32)log2_frac); /* Q15 */ - pArith->saved_dist_arr[0][i - 1] = L_sub(L_tmp1, L_tmp2); + log2_frac = Log2_norm_lc( tmp32 ); + log2_int32 = L_shl( (Word32) sub( sub( 30, log2_int ), 16 ), 15 ); + L_tmp1 = L_add( log2_int32, (Word32) log2_frac ); /* Q15 */ + pArith->saved_dist_arr[0][i - 1] = L_sub( L_tmp1, L_tmp2 ); } - FOR ( j = 0; j < pArith->num_models - 1; j++ ) + FOR( j = 0; j < pArith->num_models - 1; j++ ) { sum = 0; - FOR ( i = 1; i < pArith->range + 1; i++ ) + FOR( i = 1; i < pArith->range + 1; i++ ) { - sum = add(sum, pArith->pAlt_freq_models[j][i]); + sum = add( sum, pArith->pAlt_freq_models[j][i] ); } - log2_int = norm_s(sum); + log2_int = norm_s( sum ); tmp32 = L_deposit_h( shl( sum, log2_int ) ); - log2_frac = Log2_norm_lc(tmp32); - log2_int32 = L_shl((Word32)sub(sub(30,log2_int),16), 15); - L_tmp2 = L_add(log2_int32, (Word32)log2_frac); /* Q15 */ - FOR ( i = 1; i < pArith->range + 1; i++ ) + log2_frac = Log2_norm_lc( tmp32 ); + log2_int32 = L_shl( (Word32) sub( sub( 30, log2_int ), 16 ), 15 ); + L_tmp2 = L_add( log2_int32, (Word32) log2_frac ); /* Q15 */ + FOR( i = 1; i < pArith->range + 1; i++ ) { Word32 L_tmp1; - log2_int = norm_s(pArith->pAlt_freq_models[j][i]); + log2_int = norm_s( pArith->pAlt_freq_models[j][i] ); tmp32 = L_deposit_h( shl( pArith->pAlt_freq_models[j][i], log2_int ) ); - log2_frac = Log2_norm_lc(tmp32); - log2_int32 = L_shl((Word32)sub(sub(30,log2_int),16), 15); - L_tmp1 = L_add(log2_int32, (Word32)log2_frac); /* Q15 */ - pArith->saved_dist_arr[j + 1][i - 1] = L_sub(L_tmp1, L_tmp2); + log2_frac = Log2_norm_lc( tmp32 ); + log2_int32 = L_shl( (Word32) sub( sub( 30, log2_int ), 16 ), 15 ); + L_tmp1 = L_add( log2_int32, (Word32) log2_frac ); /* Q15 */ + pArith->saved_dist_arr[j + 1][i - 1] = L_sub( L_tmp1, L_tmp2 ); } } } @@ -420,56 +420,56 @@ static void ivas_spar_arith_com_init_fx( ivas_get_cum_freq_model( pArith_diff->pFreq_model, pArith_diff->range, pArith_diff->cum_freq[0] ); - FOR ( i = 0; i < pArith_diff->num_models - 1; i++ ) + FOR( i = 0; i < pArith_diff->num_models - 1; i++ ) { pArith_diff->pAlt_freq_models[i] = pFreq_models->diff_freq_model[i + 1]; ivas_get_cum_freq_model( pArith_diff->pAlt_freq_models[i], pArith_diff->range, pArith_diff->cum_freq[i + 1] ); } - IF ( EQ_16(enc_dec, ENC) ) + IF( EQ_16( enc_dec, ENC ) ) { sum = 0; - FOR ( i = 1; i < pArith_diff->range + 1; i++ ) + FOR( i = 1; i < pArith_diff->range + 1; i++ ) { - sum = add(sum, pArith_diff->pFreq_model[i]); + sum = add( sum, pArith_diff->pFreq_model[i] ); } - log2_int = norm_s(sum); + log2_int = norm_s( sum ); tmp32 = L_deposit_h( shl( sum, log2_int ) ); - log2_frac = Log2_norm_lc(tmp32); - log2_int32 = L_shl((Word32)sub(sub(30,log2_int),16), 15); - L_tmp2 = L_add(log2_int32, (Word32)log2_frac); /* Q15 */ - FOR ( i = 1; i < pArith_diff->range + 1; i++ ) + log2_frac = Log2_norm_lc( tmp32 ); + log2_int32 = L_shl( (Word32) sub( sub( 30, log2_int ), 16 ), 15 ); + L_tmp2 = L_add( log2_int32, (Word32) log2_frac ); /* Q15 */ + FOR( i = 1; i < pArith_diff->range + 1; i++ ) { Word32 L_tmp1; - log2_int = norm_s(pArith_diff->pFreq_model[i]); + log2_int = norm_s( pArith_diff->pFreq_model[i] ); tmp32 = L_deposit_h( shl( pArith_diff->pFreq_model[i], log2_int ) ); - log2_frac = Log2_norm_lc(tmp32); - log2_int32 = L_shl((Word32)sub(sub(30,log2_int),16), 15); - L_tmp1 = L_add(log2_int32, (Word32)log2_frac); /* Q15 */ - pArith_diff->saved_dist_arr[0][i - 1] = L_sub(L_tmp1, L_tmp2); + log2_frac = Log2_norm_lc( tmp32 ); + log2_int32 = L_shl( (Word32) sub( sub( 30, log2_int ), 16 ), 15 ); + L_tmp1 = L_add( log2_int32, (Word32) log2_frac ); /* Q15 */ + pArith_diff->saved_dist_arr[0][i - 1] = L_sub( L_tmp1, L_tmp2 ); } - FOR ( j = 0; j < pArith_diff->num_models - 1; j++ ) + FOR( j = 0; j < pArith_diff->num_models - 1; j++ ) { sum = 0; - FOR ( i = 1; i < pArith_diff->range + 1; i++ ) + FOR( i = 1; i < pArith_diff->range + 1; i++ ) { - sum = add(sum, pArith_diff->pAlt_freq_models[j][i]); + sum = add( sum, pArith_diff->pAlt_freq_models[j][i] ); } - log2_int = norm_s(sum); + log2_int = norm_s( sum ); tmp32 = L_deposit_h( shl( sum, log2_int ) ); - log2_frac = Log2_norm_lc(tmp32); - log2_int32 = L_shl((Word32)sub(sub(30,log2_int),16), 15); - L_tmp2 = L_add(log2_int32, (Word32)log2_frac); /* Q15 */ - FOR ( i = 1; i < pArith_diff->range + 1; i++ ) + log2_frac = Log2_norm_lc( tmp32 ); + log2_int32 = L_shl( (Word32) sub( sub( 30, log2_int ), 16 ), 15 ); + L_tmp2 = L_add( log2_int32, (Word32) log2_frac ); /* Q15 */ + FOR( i = 1; i < pArith_diff->range + 1; i++ ) { Word32 L_tmp1; - log2_int = norm_s(pArith_diff->pAlt_freq_models[j][i]); + log2_int = norm_s( pArith_diff->pAlt_freq_models[j][i] ); tmp32 = L_deposit_h( shl( pArith_diff->pAlt_freq_models[j][i], log2_int ) ); - log2_frac = Log2_norm_lc(tmp32); - log2_int32 = L_shl((Word32)sub(sub(30,log2_int),16), 15); - L_tmp1 = L_add(log2_int32, (Word32)log2_frac); /* Q15 */ - pArith_diff->saved_dist_arr[j + 1][i - 1] = L_sub(L_tmp1, L_tmp2); + log2_frac = Log2_norm_lc( tmp32 ); + log2_int32 = L_shl( (Word32) sub( sub( 30, log2_int ), 16 ), 15 ); + L_tmp1 = L_add( log2_int32, (Word32) log2_frac ); /* Q15 */ + pArith_diff->saved_dist_arr[j + 1][i - 1] = L_sub( L_tmp1, L_tmp2 ); } } } @@ -492,13 +492,13 @@ void ivas_spar_arith_coeffs_com_init( Word16 i, pred_r_index, drct_r_index, decd_r_index; Word16 num_quant_points_pred_r, num_quant_points_drct_r, num_quant_points_decd_r; - FOR ( i = 0; i < MAX_QUANT_STRATS; i++ ) + FOR( i = 0; i < MAX_QUANT_STRATS; i++ ) { num_quant_points_pred_r = ivas_spar_br_table_consts[table_idx].q_lvls[i][0]; /* 0: pred_r */ pred_r_index = ivas_map_num_pred_r_to_idx( num_quant_points_pred_r, ivas_spar_br_table_consts[table_idx].active_w ); #ifdef IVAS_FLOAT_FIXED ivas_spar_arith_com_init_fx( &pArith_coeffs->pred_arith_re[i], &ivas_arith_pred_r_consts[pred_r_index], - &pArith_coeffs->pred_arith_re_diff[i], pSpar_cfg->quant_strat[i].PR.q_levels[0], enc_dec ); + &pArith_coeffs->pred_arith_re_diff[i], pSpar_cfg->quant_strat[i].PR.q_levels[0], enc_dec ); #else ivas_spar_arith_com_init( &pArith_coeffs->pred_arith_re[i], &ivas_arith_pred_r_consts[pred_r_index], &pArith_coeffs->pred_arith_re_diff[i], pSpar_cfg->quant_strat[i].PR.q_levels[0], enc_dec ); @@ -507,7 +507,7 @@ void ivas_spar_arith_coeffs_com_init( drct_r_index = ivas_map_num_drct_r_to_idx( num_quant_points_drct_r ); #ifdef IVAS_FLOAT_FIXED ivas_spar_arith_com_init_fx( &pArith_coeffs->drct_arith_re[i], &ivas_arith_drct_r_consts[drct_r_index], - &pArith_coeffs->drct_arith_re_diff[i], pSpar_cfg->quant_strat[i].C.q_levels[0], enc_dec ); + &pArith_coeffs->drct_arith_re_diff[i], pSpar_cfg->quant_strat[i].C.q_levels[0], enc_dec ); #else ivas_spar_arith_com_init( &pArith_coeffs->drct_arith_re[i], &ivas_arith_drct_r_consts[drct_r_index], &pArith_coeffs->drct_arith_re_diff[i], pSpar_cfg->quant_strat[i].C.q_levels[0], enc_dec ); @@ -516,7 +516,7 @@ void ivas_spar_arith_coeffs_com_init( decd_r_index = ivas_map_num_decd_r_to_idx( num_quant_points_decd_r ); #ifdef IVAS_FLOAT_FIXED ivas_spar_arith_com_init_fx( &pArith_coeffs->decd_arith_re[i], &ivas_arith_decd_r_consts[decd_r_index], - &pArith_coeffs->decd_arith_re_diff[i], pSpar_cfg->quant_strat[i].P_r.q_levels[0], enc_dec ); + &pArith_coeffs->decd_arith_re_diff[i], pSpar_cfg->quant_strat[i].P_r.q_levels[0], enc_dec ); #else ivas_spar_arith_com_init( &pArith_coeffs->decd_arith_re[i], &ivas_arith_decd_r_consts[decd_r_index], &pArith_coeffs->decd_arith_re_diff[i], pSpar_cfg->quant_strat[i].P_r.q_levels[0], enc_dec ); @@ -544,14 +544,14 @@ static void ivas_huffman_dec_init_min_max_len( p_huff_cfg->min_len = p_huff_cfg->sym_len; p_huff_cfg->max_len = 0; - FOR ( i = 0; i < p_huff_cfg->sym_len; i++ ) + FOR( i = 0; i < p_huff_cfg->sym_len; i++ ) { code_len = codebook[1]; - IF ( GT_16(p_huff_cfg->min_len, code_len) ) + IF( GT_16( p_huff_cfg->min_len, code_len ) ) { p_huff_cfg->min_len = code_len; } - IF ( LT_16(p_huff_cfg->max_len, code_len) ) + IF( LT_16( p_huff_cfg->max_len, code_len ) ) { p_huff_cfg->max_len = code_len; } @@ -578,13 +578,13 @@ void ivas_spar_huff_coeffs_com_init( Word16 num_quant_points_pred_r, num_quant_points_drct_r, num_quant_points_decd_r; ivas_huffman_cfg_t *p_huff_cfg; - FOR ( i = 0; i < MAX_QUANT_STRATS; i++ ) + FOR( i = 0; i < MAX_QUANT_STRATS; i++ ) { p_huff_cfg = &pHuff_coeffs->pred_huff_re[i]; num_quant_points_pred_r = ivas_spar_br_table_consts[table_idx].q_lvls[i][0]; /* 0: pred_r */ pred_r_index = ivas_map_num_pred_r_to_idx( num_quant_points_pred_r, 0 ); p_huff_cfg->codebook = &ivas_huff_pred_r_consts[pred_r_index].code_book[0][0]; - IF ( EQ_16(enc_dec, DEC) ) + IF( EQ_16( enc_dec, DEC ) ) { p_huff_cfg->sym_len = pSpar_cfg->quant_strat[i].PR.q_levels[0]; ivas_huffman_dec_init_min_max_len( p_huff_cfg ); @@ -594,7 +594,7 @@ void ivas_spar_huff_coeffs_com_init( num_quant_points_drct_r = ivas_spar_br_table_consts[table_idx].q_lvls[i][1]; /* 1: drct_r */ drct_r_index = ivas_map_num_drct_r_to_idx( num_quant_points_drct_r ); p_huff_cfg->codebook = &ivas_huff_drct_r_consts[drct_r_index].code_book[0][0]; - IF ( EQ_16(enc_dec, DEC) ) + IF( EQ_16( enc_dec, DEC ) ) { p_huff_cfg->sym_len = pSpar_cfg->quant_strat[i].C.q_levels[0]; ivas_huffman_dec_init_min_max_len( p_huff_cfg ); @@ -604,7 +604,7 @@ void ivas_spar_huff_coeffs_com_init( num_quant_points_decd_r = ivas_spar_br_table_consts[table_idx].q_lvls[i][2]; /* 2: decd_r */ decd_r_index = ivas_map_num_decd_r_to_idx( num_quant_points_decd_r ); p_huff_cfg->codebook = &ivas_huff_decd_r_consts[decd_r_index].code_book[0][0]; - IF ( EQ_16(enc_dec, DEC) ) + IF( EQ_16( enc_dec, DEC ) ) { p_huff_cfg->sym_len = pSpar_cfg->quant_strat[i].P_r.q_levels[0]; ivas_huffman_dec_init_min_max_len( p_huff_cfg ); diff --git a/lib_com/ivas_fb_mixer.c b/lib_com/ivas_fb_mixer.c index d7b77a29d..e11e81b8f 100644 --- a/lib_com/ivas_fb_mixer.c +++ b/lib_com/ivas_fb_mixer.c @@ -130,7 +130,7 @@ static int16_t ivas_get_num_bands( #ifdef IVAS_FLOAT_FIXED ivas_error ivas_fb_set_cfg( - IVAS_FB_CFG **pFb_cfg_out, /* o : FB config. handle */ + IVAS_FB_CFG **pFb_cfg_out, /* o : FB config. handle */ const Word16 ivas_format, /* i : IVAS format */ const Word16 num_in_chans, /* i : number of FB input channels */ const Word16 num_out_chans, /* i : number of FB output channels */ @@ -141,7 +141,7 @@ ivas_error ivas_fb_set_cfg( { IVAS_FB_CFG *pFb_cfg; - IF ( ( pFb_cfg = (IVAS_FB_CFG *) malloc( sizeof( IVAS_FB_CFG ) ) ) == NULL ) + IF( ( pFb_cfg = (IVAS_FB_CFG *) malloc( sizeof( IVAS_FB_CFG ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer config" ); } @@ -154,13 +154,13 @@ ivas_error ivas_fb_set_cfg( pFb_cfg->active_w_mixing = active_w_mixing; pFb_cfg->windowed_fr_offset = 0; - IF ( ivas_format == ISM_FORMAT ) + IF( ivas_format == ISM_FORMAT ) { pFb_cfg->fb_latency = NS2SA( sampling_rate, DELAY_FB_4_NS ); pFb_cfg->fade_len = NS2SA( sampling_rate, DELAY_FB_4_NS ); pFb_cfg->prior_input_length = NS2SA( sampling_rate, DELAY_DIRAC_ENC_CMP_NS_PARAM_ISM ) + NS2SA( sampling_rate, DIRAC_SLOT_ENC_NS ); } - ELSE IF ( ivas_format == SBA_FORMAT ) + ELSE IF( ivas_format == SBA_FORMAT ) { pFb_cfg->fb_latency = NS2SA( sampling_rate, DELAY_FB_1_NS ); @@ -168,13 +168,13 @@ ivas_error ivas_fb_set_cfg( pFb_cfg->prior_input_length = NS2SA( sampling_rate, FRAME_SIZE_NS ); pFb_cfg->windowed_fr_offset = (Word16) ( (float) ( sampling_rate / FRAMES_PER_SEC ) * 3.0f / 4.0f ) - NS2SA( sampling_rate, DELAY_DIRAC_SPAR_ENC_CMP_NS ); } - ELSE IF ( ivas_format == MASA_FORMAT ) + ELSE IF( ivas_format == MASA_FORMAT ) { pFb_cfg->fb_latency = NS2SA( sampling_rate, DELAY_FB_1_NS ); pFb_cfg->fade_len = NS2SA( sampling_rate, DELAY_FB_1_NS ); pFb_cfg->prior_input_length = NS2SA( sampling_rate, DELAY_DIRAC_ENC_CMP_NS ) + NS2SA( sampling_rate, DIRAC_SLOT_ENC_NS ); } - ELSE IF ( ivas_format == MC_FORMAT ) + ELSE IF( ivas_format == MC_FORMAT ) { pFb_cfg->fb_latency = NS2SA( sampling_rate, DELAY_FB_1_NS ); pFb_cfg->fade_len = NS2SA( sampling_rate, DELAY_FB_1_NS ); @@ -500,28 +500,28 @@ ivas_error ivas_FB_mixer_open_fx( } #ifndef IVAS_FLOAT_FIXED /////////////////////////////// FLOAT /////////////////////////////////////////////// - for (i = 0; i < num_chs_alloc; i++) - { - if (fb_cfg->num_out_chans == 0) - { - hFbMixer->ppFilterbank_inFR_re[i] = NULL; - hFbMixer->ppFilterbank_inFR_im[i] = NULL; - } - else + for ( i = 0; i < num_chs_alloc; i++ ) { - j = fb_cfg->remix_order[i]; + if ( fb_cfg->num_out_chans == 0 ) + { + hFbMixer->ppFilterbank_inFR_re[i] = NULL; + hFbMixer->ppFilterbank_inFR_im[i] = NULL; + } + else + { + j = fb_cfg->remix_order[i]; - if ((hFbMixer->ppFilterbank_inFR_re[j] = (float *)malloc(sizeof(float) * frame_len)) == NULL) - { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder"); - } + if ( ( hFbMixer->ppFilterbank_inFR_re[j] = (float *) malloc( sizeof( float ) * frame_len ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); + } - if ((hFbMixer->ppFilterbank_inFR_im[j] = (float *)malloc(sizeof(float) * frame_len)) == NULL) - { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder"); - } + if ( ( hFbMixer->ppFilterbank_inFR_im[j] = (float *) malloc( sizeof( float ) * frame_len ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); + } + } } - } #else for ( i = 0; i < num_chs_alloc; i++ ) { @@ -558,18 +558,18 @@ ivas_error ivas_FB_mixer_open_fx( } #ifndef IVAS_FLOAT_FIXED //////////////////////////// Float ////////////////////////////////////// - for (i = 0; i < num_chs_alloc; i++) - { - if ((hFbMixer->ppFilterbank_prior_input[i] = (float *)malloc(sizeof(float) * fb_cfg->prior_input_length)) == NULL) + for ( i = 0; i < num_chs_alloc; i++ ) { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder"); + if ( ( hFbMixer->ppFilterbank_prior_input[i] = (float *) malloc( sizeof( float ) * fb_cfg->prior_input_length ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); + } + set_f( hFbMixer->ppFilterbank_prior_input[i], 0, fb_cfg->prior_input_length ); } - set_f(hFbMixer->ppFilterbank_prior_input[i], 0, fb_cfg->prior_input_length); - } #else - FOR ( i = 0; i < num_chs_alloc; i++ ) + FOR( i = 0; i < num_chs_alloc; i++ ) { - IF ( ( hFbMixer->ppFilterbank_prior_input_fx[i] = (Word32 *) malloc( sizeof( Word32 ) * fb_cfg->prior_input_length ) ) == NULL ) + IF( ( hFbMixer->ppFilterbank_prior_input_fx[i] = (Word32 *) malloc( sizeof( Word32 ) * fb_cfg->prior_input_length ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); } @@ -596,13 +596,13 @@ ivas_error ivas_FB_mixer_open_fx( } #else Word32 *pTemp_mem_fx; - IF ( ( pTemp_mem_fx = (Word32 *) malloc( sizeof( Word32 ) * fb_cfg->num_out_chans * max( fb_cfg->num_in_chans, fb_cfg->nchan_fb_in ) * IVAS_MAX_NUM_BANDS ) ) == NULL ) + IF( ( pTemp_mem_fx = (Word32 *) malloc( sizeof( Word32 ) * fb_cfg->num_out_chans * max( fb_cfg->num_in_chans, fb_cfg->nchan_fb_in ) * IVAS_MAX_NUM_BANDS ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer" ); } - FOR ( i = 0; i < fb_cfg->num_out_chans; i++ ) + FOR( i = 0; i < fb_cfg->num_out_chans; i++ ) { - FOR ( j = 0; j < fb_cfg->num_in_chans; j++ ) + FOR( j = 0; j < fb_cfg->num_in_chans; j++ ) { hFbMixer->prior_mixer_fx[i][j] = pTemp_mem_fx; pTemp_mem_fx += IVAS_MAX_NUM_BANDS; @@ -689,19 +689,19 @@ ivas_error ivas_FB_mixer_open_fx( { #ifdef IVAS_FLOAT_FIXED #if 1 /*********************Intermediate Conversion that needs to remove *****************************/ - //const Word16 *pAll_bins_per_band_48k = NULL; + // const Word16 *pAll_bins_per_band_48k = NULL; - //const float *pAll_fb_fr[2]; + // const float *pAll_fb_fr[2]; - //IF( hFbMixer->fb_cfg->num_out_chans > 0 ) + // IF( hFbMixer->fb_cfg->num_out_chans > 0 ) //{ - // IF( hFbMixer->fb_cfg->fb_latency == NS2SA( sampling_rate, DELAY_FB_1_NS ) ) - // { - // pAll_fb_fr[0] = ivas_fb_fr_12band_1ms_re; - // pAll_fb_fr[1] = ivas_fb_fr_12band_1ms_im; - // } - // pAll_bins_per_band_48k = ivas_fb_bins_per_band_12band_1ms[0]; - //} + // IF( hFbMixer->fb_cfg->fb_latency == NS2SA( sampling_rate, DELAY_FB_1_NS ) ) + // { + // pAll_fb_fr[0] = ivas_fb_fr_12band_1ms_re; + // pAll_fb_fr[1] = ivas_fb_fr_12band_1ms_im; + // } + // pAll_bins_per_band_48k = ivas_fb_bins_per_band_12band_1ms[0]; + // } /************************************* Float table is gettin assigned here **************************************/ // if ((error = ivas_fb_mixer_get_window(hFbMixer->fb_cfg->fb_latency, sampling_rate, &(hFbMixer->pAna_window))) != IVAS_ERR_OK) @@ -1154,47 +1154,47 @@ void ivas_fb_mixer_cross_fading( #ifdef IVAS_FLOAT_FIXED void ivas_fb_mixer_cross_fading_fx( - IVAS_FB_MIXER_HANDLE hFbMixer, - Word32 **ppOut_pcm_fx, - Word32 *pMdft_out_old_fx, - Word32 *pMdft_out_new_fx, - const Word16 ch, - const Word16 frame_len, - const Word16 cf_offset) + IVAS_FB_MIXER_HANDLE hFbMixer, + Word32 **ppOut_pcm_fx, + Word32 *pMdft_out_old_fx, + Word32 *pMdft_out_new_fx, + const Word16 ch, + const Word16 frame_len, + const Word16 cf_offset ) { - Word16 k, fade_start_offset, fade_end_offset; + Word16 k, fade_start_offset, fade_end_offset; - if (hFbMixer->first_frame[ch] == 0) - { - fade_start_offset = hFbMixer->cross_fade_start_offset; - fade_end_offset = hFbMixer->cross_fade_end_offset; - - for (k = 0; k < fade_start_offset; k++) + if ( hFbMixer->first_frame[ch] == 0 ) { - ppOut_pcm_fx[ch][k] = pMdft_out_old_fx[k + cf_offset]; - } + fade_start_offset = hFbMixer->cross_fade_start_offset; + fade_end_offset = hFbMixer->cross_fade_end_offset; - for (k = fade_start_offset; k < fade_end_offset; k++) - { - ppOut_pcm_fx[ch][k] = L_add(Mpy_32_16_1(pMdft_out_new_fx[k + cf_offset], hFbMixer->pFilterbank_cross_fade_fx[k - fade_start_offset]), Mpy_32_16_1(pMdft_out_old_fx[k + cf_offset], (ONE_IN_Q15 - hFbMixer->pFilterbank_cross_fade_fx[k - fade_start_offset]))); - } + for ( k = 0; k < fade_start_offset; k++ ) + { + ppOut_pcm_fx[ch][k] = pMdft_out_old_fx[k + cf_offset]; + } - for (k = fade_end_offset; k < frame_len; k++) - { - ppOut_pcm_fx[ch][k] = pMdft_out_new_fx[k + cf_offset]; - } - } - else - { - hFbMixer->first_frame[ch] = 0; + for ( k = fade_start_offset; k < fade_end_offset; k++ ) + { + ppOut_pcm_fx[ch][k] = L_add( Mpy_32_16_1( pMdft_out_new_fx[k + cf_offset], hFbMixer->pFilterbank_cross_fade_fx[k - fade_start_offset] ), Mpy_32_16_1( pMdft_out_old_fx[k + cf_offset], ( ONE_IN_Q15 - hFbMixer->pFilterbank_cross_fade_fx[k - fade_start_offset] ) ) ); + } - for (k = 0; k < frame_len; k++) + for ( k = fade_end_offset; k < frame_len; k++ ) + { + ppOut_pcm_fx[ch][k] = pMdft_out_new_fx[k + cf_offset]; + } + } + else { - ppOut_pcm_fx[ch][k] = pMdft_out_new_fx[k + cf_offset]; + hFbMixer->first_frame[ch] = 0; + + for ( k = 0; k < frame_len; k++ ) + { + ppOut_pcm_fx[ch][k] = pMdft_out_new_fx[k + cf_offset]; + } } - } - return; + return; } #endif @@ -1615,7 +1615,7 @@ static Word16 ivas_calculate_abs_fr_fx( move16(); Word32 cldfb_nrg_fx = 0; - Word16 cldfb_nrg_e = 0; + Word16 cldfb_nrg_e = 0; move16(); Word16 short_stride = pFb->fb_bin_to_band.short_stride; move16(); @@ -1633,27 +1633,27 @@ static Word16 ivas_calculate_abs_fr_fx( { Word32 sq_abs_fx; - Word16 sq_abs_e; + Word16 sq_abs_e; - //Word32 real = L_shr( *long_mdft_ptr_re_fx, 3 ); // Q27 + // Word32 real = L_shr( *long_mdft_ptr_re_fx, 3 ); // Q27 Word32 real = *long_mdft_ptr_re_fx; // Q31 move32(); - //Word32 imag = L_shr( *long_mdft_ptr_im_fx, 3 ); // Q27 + // Word32 imag = L_shr( *long_mdft_ptr_im_fx, 3 ); // Q27 Word32 imag = *long_mdft_ptr_im_fx; // Q31 - Word16 real_exp, imag_exp; + Word16 real_exp, imag_exp; move32(); Word32 real_sq, imag_sq; real_sq = Mpy_32_32( real, real ); - real_exp = 2; - move32(); + real_exp = 2; + move32(); imag_sq = Mpy_32_32( imag, imag ); - imag_exp = 2; + imag_exp = 2; move32(); - sq_abs_fx = BASOP_Util_Add_Mant32Exp(real_sq, real_exp, imag_sq, imag_exp, &sq_abs_e);// Q22 + sq_abs_fx = BASOP_Util_Add_Mant32Exp( real_sq, real_exp, imag_sq, imag_exp, &sq_abs_e ); // Q22 move32(); long_mdft_ptr_re_fx++; @@ -1676,18 +1676,18 @@ static Word16 ivas_calculate_abs_fr_fx( } /* accumulate bin energies within a CLDFB band */ - cldfb_nrg_fx = BASOP_Util_Add_Mant32Exp(cldfb_nrg_fx,cldfb_nrg_e,sq_abs_fx,sq_abs_e,&cldfb_nrg_e); + cldfb_nrg_fx = BASOP_Util_Add_Mant32Exp( cldfb_nrg_fx, cldfb_nrg_e, sq_abs_fx, sq_abs_e, &cldfb_nrg_e ); move32(); IF( !( ( j + 1 ) % num_bins_per_cldfb_band ) ) { Word32 temp = Sqrt32( cldfb_nrg_fx, &cldfb_nrg_e ); move32(); - temp = L_shl( temp, sub(cldfb_nrg_e, Q9 ) ); // Q22 + temp = L_shl( temp, sub( cldfb_nrg_e, Q9 ) ); // Q22 move32(); pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band_fx[j / num_bins_per_cldfb_band][i] = temp; cldfb_nrg_fx = 0; - cldfb_nrg_e = 0; + cldfb_nrg_e = 0; move16(); } } @@ -2344,16 +2344,16 @@ static ivas_error ivas_fb_mixer_get_window( static ivas_error ivas_fb_mixer_get_window_fx( const Word16 fade_len, /* i : window fading length in samples */ const Word32 sampling_rate, /* i : sampling rate */ - const Word16 **pWindow /* o : pointer to the window coefficents */ + const Word16 **pWindow /* o : pointer to the window coefficents */ ) { ivas_error error; error = IVAS_ERR_OK; - IF ( EQ_16( fade_len, NS2SA( sampling_rate, DELAY_FB_4_NS ) ) ) + IF( EQ_16( fade_len, NS2SA( sampling_rate, DELAY_FB_4_NS ) ) ) { - SWITCH ( sampling_rate ) + SWITCH( sampling_rate ) { case 48000: *pWindow = ivas_fb_cf_4ms_48k_fx; @@ -2368,9 +2368,9 @@ static ivas_error ivas_fb_mixer_get_window_fx( return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Unsupported Sampling frequency!" ); } } - ELSE IF ( EQ_16( fade_len, NS2SA( sampling_rate, DELAY_FB_1_NS ) ) ) + ELSE IF( EQ_16( fade_len, NS2SA( sampling_rate, DELAY_FB_1_NS ) ) ) { - SWITCH ( sampling_rate ) + SWITCH( sampling_rate ) { case 48000: *pWindow = ivas_fb_cf_1ms_48k_fx; @@ -2584,14 +2584,14 @@ static void ivas_get_ld_fb_resp_fx( { Word16 b, s, frame_len; const Word32 *pCheby_fx; - frame_len = 0; + frame_len = 0; /*common scratch buffers for computing impulse/frequency responses, pre-ring, post-ring and circular shifted outputs to optimize stack*/ Word32 scratch1_fx[L_FRAME32k * 2]; Word32 scratch2_fx[L_FRAME32k * 2]; - set32_fx(scratch1_fx,0,L_FRAME32k*2); - set32_fx(scratch2_fx,0,L_FRAME32k*2); + set32_fx( scratch1_fx, 0, L_FRAME32k * 2 ); + set32_fx( scratch2_fx, 0, L_FRAME32k * 2 ); const Word32 *han_win_fx = NULL; diff --git a/lib_com/ivas_filters.c b/lib_com/ivas_filters.c index 07c678311..69a4e13c1 100644 --- a/lib_com/ivas_filters.c +++ b/lib_com/ivas_filters.c @@ -43,9 +43,9 @@ /*------------------------------------------------------------------------------------------* * Local functions declaration *------------------------------------------------------------------------------------------*/ -static void ivas_iir_2_filter(ivas_filters_process_state_t *filter_state, float *pIn_Out, const int16_t length, const int16_t stage); +static void ivas_iir_2_filter( ivas_filters_process_state_t *filter_state, float *pIn_Out, const int16_t length, const int16_t stage ); #ifdef IVAS_FLOAT_FIXED -static void ivas_iir_2_filter_fx(ivas_filters_process_state_t *filter_state, Word32 *pIn_Out_fx, const Word16 length, const Word16 stage, Word16 q_fcator); +static void ivas_iir_2_filter_fx( ivas_filters_process_state_t *filter_state, Word32 *pIn_Out_fx, const Word16 length, const Word16 stage, Word16 q_fcator ); #endif /*-----------------------------------------------------------------------------------------* * Function ivas_filters_init() @@ -101,20 +101,20 @@ void ivas_filters_init( #ifdef IVAS_FLOAT_FIXED void ivas_filters_init_fx( ivas_filters_process_state_t *filter_state, /* i/o: filter state handle */ - const Word32 *filt_coeff_fx, /* i : filter coefficients */ - const Word16 order) /* i : filter order */ + const Word32 *filt_coeff_fx, /* i : filter coefficients */ + const Word16 order ) /* i : filter order */ { Word16 i; filter_state->order = order; - IF(EQ_16(order, IVAS_FILTER_ORDER_2) || EQ_16(order, IVAS_FILTER_ORDER_1)) + IF( EQ_16( order, IVAS_FILTER_ORDER_2 ) || EQ_16( order, IVAS_FILTER_ORDER_1 ) ) { - filter_state->filt_len = add(order, 1); + filter_state->filt_len = add( order, 1 ); - FOR(i = 0; i < IVAS_BIQUAD_FILT_LEN; i++) + FOR( i = 0; i < IVAS_BIQUAD_FILT_LEN; i++ ) { filter_state->num_fx[IVAS_FILTER_STAGE_0][i] = filt_coeff_fx[i]; - filter_state->den_fx[IVAS_FILTER_STAGE_0][i] = filt_coeff_fx[add(i, IVAS_BIQUAD_FILT_LEN)]; + filter_state->den_fx[IVAS_FILTER_STAGE_0][i] = filt_coeff_fx[add( i, IVAS_BIQUAD_FILT_LEN )]; } filter_state->state_fx[0][0] = 0; @@ -125,13 +125,13 @@ void ivas_filters_init_fx( { filter_state->filt_len = IVAS_BIQUAD_FILT_LEN; - FOR(i = 0; i < IVAS_BIQUAD_FILT_LEN; i++) + FOR( i = 0; i < IVAS_BIQUAD_FILT_LEN; i++ ) { filter_state->num_fx[IVAS_FILTER_STAGE_0][i] = filt_coeff_fx[i]; - filter_state->den_fx[IVAS_FILTER_STAGE_0][i] = filt_coeff_fx[add(i, IVAS_BIQUAD_FILT_LEN)]; - filter_state->num_fx[IVAS_FILTER_STAGE_1][i] = filt_coeff_fx[add(i, i_mult(IVAS_BIQUAD_FILT_LEN,2))]; - filter_state->den_fx[IVAS_FILTER_STAGE_1][i] = filt_coeff_fx[add(i, i_mult(IVAS_BIQUAD_FILT_LEN, 3))]; + filter_state->den_fx[IVAS_FILTER_STAGE_0][i] = filt_coeff_fx[add( i, IVAS_BIQUAD_FILT_LEN )]; + filter_state->num_fx[IVAS_FILTER_STAGE_1][i] = filt_coeff_fx[add( i, i_mult( IVAS_BIQUAD_FILT_LEN, 2 ) )]; + filter_state->den_fx[IVAS_FILTER_STAGE_1][i] = filt_coeff_fx[add( i, i_mult( IVAS_BIQUAD_FILT_LEN, 3 ) )]; } filter_state->state_fx[0][0] = 0; @@ -147,7 +147,6 @@ void ivas_filters_init_fx( #endif - /*-----------------------------------------------------------------------------------------* * Function ivas_filter_process() * @@ -181,22 +180,21 @@ void ivas_filter_process( #ifdef IVAS_FLOAT_FIXED void ivas_filter_process_fx( ivas_filters_process_state_t *filter_state, /* i/o: filter state handle */ - Word32 *pIn_Out_fx, /* i/o: signal subject to filtering */ + Word32 *pIn_Out_fx, /* i/o: signal subject to filtering */ const Word16 length, /* i : filter order */ - Word16 q_factor -) + Word16 q_factor ) { - SWITCH(filter_state->order) + SWITCH( filter_state->order ) { case IVAS_FILTER_ORDER_1: case IVAS_FILTER_ORDER_2: - ivas_iir_2_filter_fx(filter_state, pIn_Out_fx, length, IVAS_FILTER_STAGE_0, q_factor); + ivas_iir_2_filter_fx( filter_state, pIn_Out_fx, length, IVAS_FILTER_STAGE_0, q_factor ); BREAK; case IVAS_FILTER_ORDER_4: /* biquad-1 */ - ivas_iir_2_filter_fx(filter_state, pIn_Out_fx, length, IVAS_FILTER_STAGE_0, q_factor); + ivas_iir_2_filter_fx( filter_state, pIn_Out_fx, length, IVAS_FILTER_STAGE_0, q_factor ); /* biquad-2 */ - ivas_iir_2_filter_fx(filter_state, pIn_Out_fx, length, IVAS_FILTER_STAGE_1, q_factor); + ivas_iir_2_filter_fx( filter_state, pIn_Out_fx, length, IVAS_FILTER_STAGE_1, q_factor ); BREAK; default: BREAK; @@ -207,7 +205,6 @@ void ivas_filter_process_fx( #endif - /*-----------------------------------------------------------------------------------------* * Function ivas_iir_2_filter() * @@ -244,7 +241,7 @@ static void ivas_iir_2_filter_fx( Word32 *pIn_Out_fx, const Word16 length, const Word16 stage, - Word16 q_factor) + Word16 q_factor ) { Word16 i, j; @@ -252,7 +249,7 @@ static void ivas_iir_2_filter_fx( Word32 *pOut_fx = pIn_Out_fx; Word32 tmp_pIn_buf_i_fx; - Word32 L_tmp, L_tmp_1; + Word32 L_tmp, L_tmp_1; Word64 L_tmp_2; Word16 L_tmp_q_factor, L_tmp_2_q_factor, L_tmp_3_q_factor, L_tmp_4_q_factor, L_tmp_5_q_factor, L_tmp_6_q_factor; @@ -261,80 +258,82 @@ static void ivas_iir_2_filter_fx( Word16 q_factor_filter_num = 30; Word16 q_factor_filter_den = 30; - FOR(i = 0; i < length; i++) + FOR( i = 0; i < length; i++ ) { tmp_pIn_buf_i_fx = pIn_fx[i]; /*L_tmp = Mpy_32_32(pIn_fx[i], filter_state->num_fx[stage][0]);*/ - L_tmp_q_factor = sub(add(q_factor, q_factor_filter_num), 31); + L_tmp_q_factor = sub( add( q_factor, q_factor_filter_num ), 31 ); - IF(GE_16(L_tmp_q_factor, q_factor)) { - q_factor_diff = sub(L_tmp_q_factor, q_factor); - pOut_fx[i] = L_add((filter_state->state_fx[stage][0]), L_shr(Mpy_32_32(filter_state->num_fx[stage][0], pIn_fx[i]), q_factor_diff)); + IF( GE_16( L_tmp_q_factor, q_factor ) ) + { + q_factor_diff = sub( L_tmp_q_factor, q_factor ); + pOut_fx[i] = L_add( ( filter_state->state_fx[stage][0] ), L_shr( Mpy_32_32( filter_state->num_fx[stage][0], pIn_fx[i] ), q_factor_diff ) ); L_tmp_2_q_factor = q_factor; } - ELSE{ - q_factor_diff = sub(q_factor, L_tmp_q_factor); - pOut_fx[i] = L_add(L_shr(filter_state->state_fx[stage][0], q_factor_diff), (Mpy_32_32(filter_state->num_fx[stage][0], pIn_fx[i]))); - pOut_fx[i] = L_shl(pOut_fx[i], q_factor_diff); + ELSE + { + q_factor_diff = sub( q_factor, L_tmp_q_factor ); + pOut_fx[i] = L_add( L_shr( filter_state->state_fx[stage][0], q_factor_diff ), ( Mpy_32_32( filter_state->num_fx[stage][0], pIn_fx[i] ) ) ); + pOut_fx[i] = L_shl( pOut_fx[i], q_factor_diff ); L_tmp_2_q_factor = q_factor; - } - FOR(j = 1; j < filter_state->filt_len; j++) + FOR( j = 1; j < filter_state->filt_len; j++ ) { /*L_tmp_1 = filter_state->num_fx[stage][j] * tmp_pIn_buf_i_fx;*/ - L_tmp_3_q_factor = sub(add(q_factor_filter_num, q_factor), 31); + L_tmp_3_q_factor = sub( add( q_factor_filter_num, q_factor ), 31 ); - IF(GE_16(L_tmp_3_q_factor, q_factor)) { - q_factor_diff = sub(L_tmp_3_q_factor, q_factor); - L_tmp = L_add((filter_state->state_fx[stage][j]), L_shr(Mpy_32_32(filter_state->num_fx[stage][j], tmp_pIn_buf_i_fx), q_factor_diff)); + IF( GE_16( L_tmp_3_q_factor, q_factor ) ) + { + q_factor_diff = sub( L_tmp_3_q_factor, q_factor ); + L_tmp = L_add( ( filter_state->state_fx[stage][j] ), L_shr( Mpy_32_32( filter_state->num_fx[stage][j], tmp_pIn_buf_i_fx ), q_factor_diff ) ); L_tmp_4_q_factor = q_factor; } - ELSE{ - q_factor_diff = sub(q_factor, L_tmp_3_q_factor); - L_tmp = L_add(L_shr(filter_state->state_fx[stage][j], q_factor_diff), (Mpy_32_32(filter_state->num_fx[stage][j], tmp_pIn_buf_i_fx))); + ELSE + { + q_factor_diff = sub( q_factor, L_tmp_3_q_factor ); + L_tmp = L_add( L_shr( filter_state->state_fx[stage][j], q_factor_diff ), ( Mpy_32_32( filter_state->num_fx[stage][j], tmp_pIn_buf_i_fx ) ) ); L_tmp_4_q_factor = L_tmp_3_q_factor; - } /*L_tmp_3 = filter_state->den_fx[stage][j] * pOut_fx[i];*/ - L_tmp_5_q_factor = sub(add(q_factor_filter_den, L_tmp_2_q_factor), 31); + L_tmp_5_q_factor = sub( add( q_factor_filter_den, L_tmp_2_q_factor ), 31 ); - IF(GE_16(L_tmp_5_q_factor, L_tmp_4_q_factor)) { - q_factor_diff = sub(L_tmp_5_q_factor, L_tmp_4_q_factor); - L_tmp_1 = L_sub(L_tmp, L_shr(Mpy_32_32(filter_state->den_fx[stage][j], pOut_fx[i]), q_factor_diff)); + IF( GE_16( L_tmp_5_q_factor, L_tmp_4_q_factor ) ) + { + q_factor_diff = sub( L_tmp_5_q_factor, L_tmp_4_q_factor ); + L_tmp_1 = L_sub( L_tmp, L_shr( Mpy_32_32( filter_state->den_fx[stage][j], pOut_fx[i] ), q_factor_diff ) ); L_tmp_6_q_factor = L_tmp_4_q_factor; - } - ELSE{ - q_factor_diff = sub(L_tmp_4_q_factor, L_tmp_5_q_factor); - L_tmp_1 = L_sub(L_shr(L_tmp, q_factor_diff), Mpy_32_32(filter_state->den_fx[stage][j], pOut_fx[i])); + ELSE + { + q_factor_diff = sub( L_tmp_4_q_factor, L_tmp_5_q_factor ); + L_tmp_1 = L_sub( L_shr( L_tmp, q_factor_diff ), Mpy_32_32( filter_state->den_fx[stage][j], pOut_fx[i] ) ); L_tmp_6_q_factor = L_tmp_5_q_factor; } - IF(GE_16(L_tmp_6_q_factor, q_factor)) { - q_factor_diff = sub(L_tmp_6_q_factor, q_factor); - L_tmp_2 = W_shr((Word64)L_tmp_1, q_factor_diff); + IF( GE_16( L_tmp_6_q_factor, q_factor ) ) + { + q_factor_diff = sub( L_tmp_6_q_factor, q_factor ); + L_tmp_2 = W_shr( (Word64) L_tmp_1, q_factor_diff ); } - ELSE{ - q_factor_diff = sub(q_factor, L_tmp_6_q_factor); - L_tmp_2 = W_shl((Word64)L_tmp_1, q_factor_diff); + ELSE + { + q_factor_diff = sub( q_factor, L_tmp_6_q_factor ); + L_tmp_2 = W_shl( (Word64) L_tmp_1, q_factor_diff ); } - filter_state->state_fx[stage][j - 1] = W_extract_l(L_tmp_2); + filter_state->state_fx[stage][j - 1] = W_extract_l( L_tmp_2 ); - //filter_state->state[stage][j - 1] = WORD322FL_SCALE(filter_state->state_fx[stage][j - 1], sub(31, q_factor)); + // filter_state->state[stage][j - 1] = WORD322FL_SCALE(filter_state->state_fx[stage][j - 1], sub(31, q_factor)); } - } - } #endif - diff --git a/lib_com/ivas_ism_com.c b/lib_com/ivas_ism_com.c index ed0a260b0..a27621adb 100644 --- a/lib_com/ivas_ism_com.c +++ b/lib_com/ivas_ism_com.c @@ -55,13 +55,13 @@ #define BETA_ISM_LOW_IMP 0.6f #define BETA_ISM_MEDIUM_IMP 0.8f -#define MAX_BRATE_TCX_32k 48000 -#define BITS_IVAS_512k ( IVAS_512k / FRAMES_PER_SEC ) -#define BITS_ACELP_12k8_HIGH_LIMIT ( ACELP_12k8_HIGH_LIMIT / FRAMES_PER_SEC ) -#define BITS_MIN_BRATE_SWB_BWE ( MIN_BRATE_SWB_BWE / FRAMES_PER_SEC ) -#define BITS_MIN_BRATE_WB_BWE ( MIN_BRATE_WB_BWE / FRAMES_PER_SEC ) -#define BITS_ACELP_16k_LOW_LIMIT_1k6 ( ACELP_16k_LOW_LIMIT + SWB_TBE_1k6 ) / FRAMES_PER_SEC -#define BITS_MAX_BRATE_TCX_32k ( MAX_BRATE_TCX_32k / FRAMES_PER_SEC ) +#define MAX_BRATE_TCX_32k 48000 +#define BITS_IVAS_512k ( IVAS_512k / FRAMES_PER_SEC ) +#define BITS_ACELP_12k8_HIGH_LIMIT ( ACELP_12k8_HIGH_LIMIT / FRAMES_PER_SEC ) +#define BITS_MIN_BRATE_SWB_BWE ( MIN_BRATE_SWB_BWE / FRAMES_PER_SEC ) +#define BITS_MIN_BRATE_WB_BWE ( MIN_BRATE_WB_BWE / FRAMES_PER_SEC ) +#define BITS_ACELP_16k_LOW_LIMIT_1k6 ( ACELP_16k_LOW_LIMIT + SWB_TBE_1k6 ) / FRAMES_PER_SEC +#define BITS_MAX_BRATE_TCX_32k ( MAX_BRATE_TCX_32k / FRAMES_PER_SEC ) /*-------------------------------------------------------------------* @@ -78,7 +78,7 @@ void bitbudget_to_brate( { Word16 i; - FOR ( i = 0; i < N; i++ ) + FOR( i = 0; i < N; i++ ) { y[i] = FRAMES_PER_SEC * x[i]; } @@ -394,7 +394,7 @@ ivas_error ivas_ism_config_fx( const Word32 ism_total_brate, /* i : ISM total bitrate */ const Word16 nchan_transport, /* i : number of transport channels */ const Word16 nchan_ism, /* i : number of objects */ - ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ + ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ const Word16 ism_extended_metadata_flag, /* i : extended metadata flag */ const Word16 null_metadata_flag[MAX_NUM_OBJECTS], /* i : NULL MD flag */ const Word16 ism_imp[], /* i : ISM importance flags */ @@ -415,7 +415,7 @@ ivas_error ivas_ism_config_fx( error = IVAS_ERR_OK; move16(); - IF ( combined_format_flag ) + IF( combined_format_flag ) { n_ISms = nchan_ism; move16(); @@ -431,20 +431,20 @@ ivas_error ivas_ism_config_fx( move16(); bits_side = 0; move16(); - IF ( hIsmMeta != NULL ) + IF( hIsmMeta != NULL ) { - FOR ( ch = 0; ch < n_ISms; ch++ ) + FOR( ch = 0; ch < n_ISms; ch++ ) { ism_metadata_flag_global = s_or( ism_metadata_flag_global, ism_imp[ch] ); } } /* decision about bitrates per channel */ - IF ( combined_format_flag ) + IF( combined_format_flag ) { /* combined format: decision about bitrates per channel - variable during the session (at one ivas_total_brate) */ - //bits_ism = (Word16) ( ism_total_brate / FRAMES_PER_SEC ); - bits_ism = ( Word16 ) Mpy_32_32( 42949673, ism_total_brate ); + // bits_ism = (Word16) ( ism_total_brate / FRAMES_PER_SEC ); + bits_ism = (Word16) Mpy_32_32( 42949673, ism_total_brate ); tmp1 = BASOP_Util_Divide1616_Scale( bits_ism, n_ISms, &exp ); set_s( bits_element, shr( tmp1, ( 15 - exp ) ), n_ISms ); bits_element[n_ISms - 1] = add( bits_element[n_ISms - 1], bits_ism % n_ISms ); @@ -454,40 +454,40 @@ ivas_error ivas_ism_config_fx( ELSE { /* ISM format: decision about bitrates per channel - constant during the session (at one ivas_total_brate) */ - //bits_ism = (Word16) ( ism_total_brate / FRAMES_PER_SEC ); - // 1 / 50 * 2 ^ 31 -- > 42949673, --> Q31, + // bits_ism = (Word16) ( ism_total_brate / FRAMES_PER_SEC ); + // 1 / 50 * 2 ^ 31 -- > 42949673, --> Q31, //(Q31 +Q0) - Q31 --> Q0 - bits_ism = (Word16)Mpy_32_32( 42949673, ism_total_brate ); - tmp1 = BASOP_Util_Divide1616_Scale(bits_ism, n_ISms, &exp); + bits_ism = (Word16) Mpy_32_32( 42949673, ism_total_brate ); + tmp1 = BASOP_Util_Divide1616_Scale( bits_ism, n_ISms, &exp ); set_s( bits_element, shr( tmp1, ( 15 - exp ) ), n_ISms ); bits_element[n_ISms - 1] = add( bits_element[n_ISms - 1], bits_ism % n_ISms ); bitbudget_to_brate( bits_element, element_brate, n_ISms ); /* count ISm common signaling bits */ - IF ( hIsmMeta != NULL ) + IF( hIsmMeta != NULL ) { nb_bits_metadata[0] = add( nb_bits_metadata[0], add( n_ISms * ISM_METADATA_FLAG_BITS, nchan_ism ) ); - IF ( GE_32( ism_total_brate, ISM_EXTENDED_METADATA_BRATE ) ) + IF( GE_32( ism_total_brate, ISM_EXTENDED_METADATA_BRATE ) ) { nb_bits_metadata[0] = add( nb_bits_metadata[0], ISM_EXTENDED_METADATA_BITS ); - IF ( ism_extended_metadata_flag ) + IF( ism_extended_metadata_flag ) { nb_bits_metadata[0] = add( nb_bits_metadata[0], ISM_METADATA_IS_NDP_BITS ); } } - FOR ( ch = 0; ch < n_ISms; ch++ ) + FOR( ch = 0; ch < n_ISms; ch++ ) { - IF ( null_metadata_flag[ch] ) + IF( null_metadata_flag[ch] ) { nb_bits_metadata[0] = add( nb_bits_metadata[0], ISM_METADATA_MD_FLAG_BITS ); nb_bits_metadata[0] = add( nb_bits_metadata[0], ISM_METADATA_FLAG_BITS ); } ELSE { - IF ( ism_imp[ch] == ISM_NO_META ) + IF( ism_imp[ch] == ISM_NO_META ) { nb_bits_metadata[0] = add( nb_bits_metadata[0], ISM_METADATA_MD_FLAG_BITS ); nb_bits_metadata[0] = add( nb_bits_metadata[0], ISM_METADATA_INACTIVE_FLAG_BITS ); @@ -498,12 +498,12 @@ ivas_error ivas_ism_config_fx( } /* split metadata bitbudget equally between channels */ - IF ( nb_bits_metadata != NULL ) + IF( nb_bits_metadata != NULL ) { bits_side = sum_s( nb_bits_metadata, n_ISms ); tmp1 = BASOP_Util_Divide1616_Scale( bits_side, n_ISms, &exp ); set_s( nb_bits_metadata, shr( tmp1, ( 15 - exp ) ), n_ISms ); - nb_bits_metadata[n_ISms - 1] = add( nb_bits_metadata[n_ISms - 1], bits_side % n_ISms ); + nb_bits_metadata[n_ISms - 1] = add( nb_bits_metadata[n_ISms - 1], bits_side % n_ISms ); v_sub_s( bits_element, nb_bits_metadata, bits_CoreCoder, n_ISms ); bitbudget_to_brate( bits_CoreCoder, total_brate, n_ISms ); @@ -511,7 +511,7 @@ ivas_error ivas_ism_config_fx( } /* assign less CoreCoder bit-budget to inactive streams (at least one stream must be active) */ - IF ( ism_metadata_flag_global ) + IF( ism_metadata_flag_global ) { Word16 diff, n_higher, flag_higher[MAX_NUM_OBJECTS]; @@ -519,9 +519,9 @@ ivas_error ivas_ism_config_fx( diff = 0; move16(); - FOR ( ch = 0; ch < n_ISms; ch++ ) + FOR( ch = 0; ch < n_ISms; ch++ ) { - IF ( EQ_16( ism_imp[ch], ISM_NO_META ) ) + IF( EQ_16( ism_imp[ch], ISM_NO_META ) ) { diff = add( diff, sub( bits_CoreCoder[ch], BITS_ISM_INACTIVE ) ); bits_CoreCoder[ch] = BITS_ISM_INACTIVE; @@ -532,13 +532,13 @@ ivas_error ivas_ism_config_fx( n_higher = sum_s( flag_higher, n_ISms ); test(); - IF ( GT_16( diff, 0 ) && GT_16( n_higher, 0 ) ) + IF( GT_16( diff, 0 ) && GT_16( n_higher, 0 ) ) { tmp = BASOP_Util_Divide1616_Scale( diff, n_higher, &exp ); tmp = shr( tmp, ( 15 - exp ) ); - FOR ( ch = 0; ch < n_ISms; ch++ ) + FOR( ch = 0; ch < n_ISms; ch++ ) { - IF ( flag_higher[ch] ) + IF( flag_higher[ch] ) { bits_CoreCoder[ch] = add( bits_CoreCoder[ch], tmp ); } @@ -548,7 +548,7 @@ ivas_error ivas_ism_config_fx( move16(); ch = 0; move16(); - WHILE ( EQ_16( flag_higher[ch], 0 ) ) + WHILE( EQ_16( flag_higher[ch], 0 ) ) { ch = add( ch, 1 ); } @@ -559,39 +559,39 @@ ivas_error ivas_ism_config_fx( diff = 0; move16(); - FOR ( ch = 0; ch < n_ISms; ch++ ) + FOR( ch = 0; ch < n_ISms; ch++ ) { Word16 limit; limit = BITS_MIN_BRATE_SWB_BWE; move16(); - IF ( LT_32( element_brate[ch], MIN_BRATE_SWB_STEREO ) ) /* replicate function set_bw() -> check the coded audio band-width */ + IF( LT_32( element_brate[ch], MIN_BRATE_SWB_STEREO ) ) /* replicate function set_bw() -> check the coded audio band-width */ { limit = BITS_MIN_BRATE_WB_BWE; move16(); } - ELSE IF ( GE_32( element_brate[ch], SCE_CORE_16k_LOW_LIMIT ) ) /* replicate function set_ACELP_flag() -> it is not intended to switch the ACELP internal sampling rate within an object */ + ELSE IF( GE_32( element_brate[ch], SCE_CORE_16k_LOW_LIMIT ) ) /* replicate function set_ACELP_flag() -> it is not intended to switch the ACELP internal sampling rate within an object */ { /*limit = SCE_CORE_16k_LOW_LIMIT;*/ limit = BITS_ACELP_16k_LOW_LIMIT_1k6; move16(); } - IF ( EQ_16( ism_imp[ch], ISM_NO_META ) ) + IF( EQ_16( ism_imp[ch], ISM_NO_META ) ) { tmp = BITS_ISM_INACTIVE; move16(); } - ELSE IF ( EQ_16( ism_imp[ch], ISM_LOW_IMP ) ) + ELSE IF( EQ_16( ism_imp[ch], ISM_LOW_IMP ) ) { - //tmp = (Word16) ( BETA_ISM_LOW_IMP * bits_CoreCoder[ch] ); + // tmp = (Word16) ( BETA_ISM_LOW_IMP * bits_CoreCoder[ch] ); tmp1 = BASOP_Util_Divide1616_Scale( bits_CoreCoder[ch], 5, &exp ); - tmp = shr( mult( tmp1, 24576 ), ( 15 - exp + 13 ) - 15); + tmp = shr( mult( tmp1, 24576 ), ( 15 - exp + 13 ) - 15 ); tmp = s_max( limit, tmp ); } - ELSE IF ( EQ_16( ism_imp[ch], ISM_MEDIUM_IMP ) ) + ELSE IF( EQ_16( ism_imp[ch], ISM_MEDIUM_IMP ) ) { - //tmp = (Word16) ( BETA_ISM_MEDIUM_IMP * bits_CoreCoder[ch] ); + // tmp = (Word16) ( BETA_ISM_MEDIUM_IMP * bits_CoreCoder[ch] ); tmp1 = BASOP_Util_Divide1616_Scale( bits_CoreCoder[ch], 5, &exp ); tmp = shr( mult( tmp1, 16384 ), ( 15 - exp + 12 ) - 15 ); tmp = s_max( limit, tmp ); @@ -608,13 +608,13 @@ ivas_error ivas_ism_config_fx( } test(); - IF ( GT_16( diff, 0 ) && GT_16( n_higher, 0 ) ) + IF( GT_16( diff, 0 ) && GT_16( n_higher, 0 ) ) { - tmp = BASOP_Util_Divide1616_Scale( diff , n_higher, &exp ); + tmp = BASOP_Util_Divide1616_Scale( diff, n_higher, &exp ); tmp = shr( tmp, ( 15 - exp ) ); - FOR ( ch = 0; ch < n_ISms; ch++ ) + FOR( ch = 0; ch < n_ISms; ch++ ) { - IF ( flag_higher[ch] ) + IF( flag_higher[ch] ) { bits_CoreCoder[ch] = add( bits_CoreCoder[ch], tmp ); } @@ -624,21 +624,21 @@ ivas_error ivas_ism_config_fx( move16(); ch = 0; move16(); - WHILE ( EQ_16( flag_higher[ch], 0 ) ) + WHILE( EQ_16( flag_higher[ch], 0 ) ) { ch = add( ch, 1 ); } - bits_CoreCoder[ch] = add(bits_CoreCoder[ch], tmp ); + bits_CoreCoder[ch] = add( bits_CoreCoder[ch], tmp ); } /* verify for the maximum bitrate @12.8kHz core */ diff = 0; move16(); - FOR ( ch = 0; ch < n_ISms; ch++ ) + FOR( ch = 0; ch < n_ISms; ch++ ) { limit_high = BITS_IVAS_512k; move16(); - IF ( LT_32( element_brate[ch], SCE_CORE_16k_LOW_LIMIT ) ) /* replicate function set_ACELP_flag() -> it is not intended to switch the ACELP internal sampling rate within an object */ + IF( LT_32( element_brate[ch], SCE_CORE_16k_LOW_LIMIT ) ) /* replicate function set_ACELP_flag() -> it is not intended to switch the ACELP internal sampling rate within an object */ { limit_high = BITS_ACELP_12k8_HIGH_LIMIT; move16(); @@ -653,13 +653,13 @@ ivas_error ivas_ism_config_fx( /* limitation to avoid too high bitrate in one active TCX channel */ test(); - IF ( GE_32( element_brate[0], SCE_CORE_16k_LOW_LIMIT ) && LE_32( element_brate[0], IVAS_32k ) ) + IF( GE_32( element_brate[0], SCE_CORE_16k_LOW_LIMIT ) && LE_32( element_brate[0], IVAS_32k ) ) { diff = 0; move16(); limit_high = BITS_MAX_BRATE_TCX_32k; - FOR ( ch = 0; ch < n_ISms; ch++ ) + FOR( ch = 0; ch < n_ISms; ch++ ) { tmp = (Word16) s_min( bits_CoreCoder[ch], limit_high ); @@ -669,15 +669,15 @@ ivas_error ivas_ism_config_fx( } } - IF ( GT_16( diff, 0 ) ) + IF( GT_16( diff, 0 ) ) { ch = 0; move16(); - FOR ( ch = 0; ch < n_ISms; ch++ ) + FOR( ch = 0; ch < n_ISms; ch++ ) { - IF ( EQ_16( flag_higher[ch], 0 ) ) + IF( EQ_16( flag_higher[ch], 0 ) ) { - IF ( GT_16( diff, limit_high ) ) + IF( GT_16( diff, limit_high ) ) { diff = add( diff, sub( bits_CoreCoder[ch], limit_high ) ); bits_CoreCoder[ch] = limit_high; @@ -687,7 +687,7 @@ ivas_error ivas_ism_config_fx( { bits_CoreCoder[ch] = add( bits_CoreCoder[ch], diff ); - IF ( combined_format_flag ) + IF( combined_format_flag ) { diff = 0; move16(); @@ -698,15 +698,15 @@ ivas_error ivas_ism_config_fx( } } - IF ( combined_format_flag ) + IF( combined_format_flag ) { - IF ( GT_16( diff, 0 ) ) + IF( GT_16( diff, 0 ) ) { - FOR ( ch = 0; ch < n_ISms; ch++ ) + FOR( ch = 0; ch < n_ISms; ch++ ) { - IF ( LE_16( ism_imp[ch], ISM_MEDIUM_IMP ) ) + IF( LE_16( ism_imp[ch], ISM_MEDIUM_IMP ) ) { - IF ( GT_16( diff, limit_high ) ) + IF( GT_16( diff, limit_high ) ) { diff = add( diff, sub( bits_CoreCoder[ch], limit_high ) ); bits_CoreCoder[ch] = limit_high; @@ -714,7 +714,7 @@ ivas_error ivas_ism_config_fx( } ELSE { - bits_CoreCoder[ch] = add( bits_CoreCoder[ch], diff ); + bits_CoreCoder[ch] = add( bits_CoreCoder[ch], diff ); BREAK; } } @@ -790,12 +790,12 @@ void ivas_ism_reset_metadata_enc( } void ivas_ism_reset_metadata_API( - ISM_METADATA_HANDLE hIsmMeta /* i/o: ISM metadata handle */ + ISM_METADATA_HANDLE hIsmMeta /* i/o: ISM metadata handle */ ) { - ivas_ism_reset_metadata_enc(hIsmMeta); + ivas_ism_reset_metadata_enc( hIsmMeta ); - return; + return; } #else @@ -815,12 +815,12 @@ void ivas_ism_reset_metadata( } void ivas_ism_reset_metadata_API( - ISM_METADATA_HANDLE hIsmMeta /* i/o: ISM metadata handle */ + ISM_METADATA_HANDLE hIsmMeta /* i/o: ISM metadata handle */ ) { - ivas_ism_reset_metadata(hIsmMeta); + ivas_ism_reset_metadata( hIsmMeta ); - return; + return; } #endif @@ -831,8 +831,6 @@ void ivas_ism_reset_metadata_API( *-------------------------------------------------------------------*/ - - /*-------------------------------------------------------------------* * ism_quant_meta() * @@ -887,32 +885,32 @@ int16_t ism_quant_meta( /*! r: dequantized value */ #ifdef IVAS_FLOAT_FIXED Word32 ism_dequant_meta_fx( - const Word16 idx, /* i : quantizer index */ + const Word16 idx, /* i : quantizer index */ const Word32 borders_fx[], /* i : level borders */ const Word32 q_step_fx, /* i : quantization step */ const Word32 q_step_border_fx, /* i : quantization step at the border */ - const Word16 cbsize /* i : codebook size */ + const Word16 cbsize /* i : codebook size */ ) { Word16 idx_start; Word32 qlow_fx, step_fx, valQ_fx; - IF ( idx <= L_shr(L_sub( borders_fx[1], borders_fx[0] ), 21) / L_shr(q_step_border_fx, 21) ) + IF( idx <= L_shr( L_sub( borders_fx[1], borders_fx[0] ), 21 ) / L_shr( q_step_border_fx, 21 ) ) { qlow_fx = borders_fx[0]; idx_start = 0; step_fx = q_step_border_fx; } - ELSE IF ( idx <= cbsize - 1 - L_shr( L_sub( borders_fx[3], borders_fx[2] ), 21) / L_shr(q_step_border_fx, 21) ) + ELSE IF( idx <= cbsize - 1 - L_shr( L_sub( borders_fx[3], borders_fx[2] ), 21 ) / L_shr( q_step_border_fx, 21 ) ) { qlow_fx = borders_fx[1]; - idx_start = (Word16) ( L_shr( L_sub( borders_fx[1], borders_fx[0] ), 21) / L_shr(q_step_border_fx , 21)); + idx_start = (Word16) ( L_shr( L_sub( borders_fx[1], borders_fx[0] ), 21 ) / L_shr( q_step_border_fx, 21 ) ); step_fx = q_step_fx; } ELSE { qlow_fx = borders_fx[2]; - idx_start = (Word16) ( cbsize - 1 - L_shr(L_sub( borders_fx[3], borders_fx[2] ), 21) / L_shr(q_step_border_fx, 21) ); + idx_start = (Word16) ( cbsize - 1 - L_shr( L_sub( borders_fx[3], borders_fx[2] ), 21 ) / L_shr( q_step_border_fx, 21 ) ); step_fx = q_step_border_fx; } @@ -996,7 +994,7 @@ void ivas_param_ism_config( #ifdef IVAS_FLOAT_FIXED void ivas_param_ism_config_fx( PARAM_ISM_CONFIG_HANDLE hParamIsm, /* i/o: IVAS Param ISM Config Structure */ - const Word16 nchan_obj /* i : number of ISM channels */ + const Word16 nchan_obj /* i : number of ISM channels */ ) { Word16 i; @@ -1004,14 +1002,14 @@ void ivas_param_ism_config_fx( hParamIsm->nbands = MAX_PARAM_ISM_NBANDS; move16(); - FOR ( i = 0; i < hParamIsm->nbands; i++ ) + FOR( i = 0; i < hParamIsm->nbands; i++ ) { hParamIsm->nblocks[i] = MAX_PARAM_ISM_NBLOCKS; move16(); } /* for elevation zero compute the max azi quantization indices */ - FOR ( i = 0; i < nchan_obj; i++ ) + FOR( i = 0; i < nchan_obj; i++ ) { hParamIsm->last_az_diff[i] = 0; move16(); @@ -1153,15 +1151,15 @@ void update_last_metadata( #ifdef IVAS_FLOAT_FIXED void update_last_metadata_fx( - const Word16 nchan_ism, /* i : number of objects */ + const Word16 nchan_ism, /* i : number of objects */ ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ - const Word16 updt_flag[] /* i : last metadata update flag */ + const Word16 updt_flag[] /* i : last metadata update flag */ ) { Word16 ch; - FOR ( ch = 0; ch < nchan_ism; ch++ ) + FOR( ch = 0; ch < nchan_ism; ch++ ) { - IF ( EQ_16( updt_flag[ch], 1 ) ) + IF( EQ_16( updt_flag[ch], 1 ) ) { hIsmMeta[ch]->last_azimuth_fx = hIsmMeta[ch]->azimuth_fx; move32(); @@ -1182,13 +1180,13 @@ void update_last_metadata_fx( #ifdef IVAS_FLOAT_FIXED void ivas_get_ism_sid_quan_bitbudget_fx( - const Word16 nchan_ism, /* i : number of objects */ - Word16 *nBits_azimuth, /* o : number of Q bits for azimuth */ - Word16 *nBits_elevation, /* o : number of Q bits for elevation */ - Word32 *q_step_fx, /* o : quantization step */ - Word32 *q_step_border_fx, /* o : quantization step at the border */ - Word16 *nBits_coh, /* o : number of Q bits for coherence */ - Word16 *nBits_sce_id /* o : number of Q bits for sce_id_dtx */ + const Word16 nchan_ism, /* i : number of objects */ + Word16 *nBits_azimuth, /* o : number of Q bits for azimuth */ + Word16 *nBits_elevation, /* o : number of Q bits for elevation */ + Word32 *q_step_fx, /* o : quantization step */ + Word32 *q_step_border_fx, /* o : quantization step at the border */ + Word16 *nBits_coh, /* o : number of Q bits for coherence */ + Word16 *nBits_sce_id /* o : number of Q bits for sce_id_dtx */ ) { *nBits_azimuth = ISM_DTX_AZI_BITS_HIGH; @@ -1198,7 +1196,7 @@ void ivas_get_ism_sid_quan_bitbudget_fx( *nBits_coh = ISM_DTX_COH_SCA_BITS; *nBits_sce_id = 1; - IF ( nchan_ism >= 3 ) + IF( nchan_ism >= 3 ) { *nBits_azimuth = ISM_DTX_AZI_BITS_LOW; *nBits_elevation = ISM_DTX_ELE_BITS_LOW; diff --git a/lib_com/ivas_lfe_com.c b/lib_com/ivas_lfe_com.c index 01e479da4..123981394 100644 --- a/lib_com/ivas_lfe_com.c +++ b/lib_com/ivas_lfe_com.c @@ -101,15 +101,15 @@ void ivas_lfe_lpf_select_filt_coeff( #ifdef IVAS_FLOAT_FIXED void ivas_lfe_lpf_select_filt_coeff_fx( - const Word32 sampling_rate, /* i : sampling rate */ - const Word16 order, /* i : filter order */ - const Word32 **ppFilt_coeff_fx /* o : filter coefficients */ + const Word32 sampling_rate, /* i : sampling rate */ + const Word16 order, /* i : filter order */ + const Word32 **ppFilt_coeff_fx /* o : filter coefficients */ ) { - SWITCH(order) + SWITCH( order ) { case IVAS_FILTER_ORDER_2: - SWITCH(sampling_rate) + SWITCH( sampling_rate ) { case 16000: *ppFilt_coeff_fx = ivas_lpf_2_butter_16k_fx; @@ -125,7 +125,7 @@ void ivas_lfe_lpf_select_filt_coeff_fx( } BREAK; case IVAS_FILTER_ORDER_4: - SWITCH(sampling_rate) + SWITCH( sampling_rate ) { case 16000: *ppFilt_coeff_fx = ivas_lpf_4_butter_16k_sos_fx; @@ -141,7 +141,7 @@ void ivas_lfe_lpf_select_filt_coeff_fx( } BREAK; default: - assert(!"Unsupported LFE Filter order"); + assert( !"Unsupported LFE Filter order" ); } return; @@ -149,7 +149,6 @@ void ivas_lfe_lpf_select_filt_coeff_fx( #endif - /*-----------------------------------------------------------------------------------------* * Function ivas_lfe_window_init() * diff --git a/lib_com/ivas_masa_com.c b/lib_com/ivas_masa_com.c index f3666bd4e..c4cac721c 100644 --- a/lib_com/ivas_masa_com.c +++ b/lib_com/ivas_masa_com.c @@ -180,11 +180,11 @@ void ivas_masa_set_elements_fx( { Word16 tmp, tmp_e; - IF ( EQ_16( nchan_transport, 2 ) ) + IF( EQ_16( nchan_transport, 2 ) ) { test(); test(); - IF ( GE_32( ivas_total_brate, MCMASA_SEPARATE_BRATE ) && EQ_16( mc_mode, MC_MODE_MCMASA ) ) + IF( GE_32( ivas_total_brate, MCMASA_SEPARATE_BRATE ) && EQ_16( mc_mode, MC_MODE_MCMASA ) ) { *nCPE = 1; move16(); @@ -194,24 +194,24 @@ void ivas_masa_set_elements_fx( *element_mode = IVAS_SCE; /* This is needed for the initialization phase to initialize codec mode to SCE, since it is written first to the file*/ move16(); } - ELSE IF ( EQ_16( ivas_format, MASA_ISM_FORMAT ) && NE_16( ism_mode, ISM_MODE_NONE ) ) + ELSE IF( EQ_16( ivas_format, MASA_ISM_FORMAT ) && NE_16( ism_mode, ISM_MODE_NONE ) ) { *nCPE = 1; move16(); - IF ( EQ_16( *element_mode, -1 ) ) + IF( EQ_16( *element_mode, -1 ) ) { *element_mode = IVAS_CPE_DFT; /* To have it initialized in case it was not already. */ move16(); } - IF ( GT_32( ivas_total_brate, MIN_BRATE_MDCT_STEREO ) ) + IF( GT_32( ivas_total_brate, MIN_BRATE_MDCT_STEREO ) ) { *element_mode = IVAS_CPE_MDCT; move16(); test(); test(); test(); - IF ( ( EQ_16( ism_mode, ISM_MASA_MODE_DISC ) || EQ_16( ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_16( ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) && LT_32( L_sub( ivas_total_brate, ism_total_brate ), MIN_BRATE_MDCT_STEREO ) ) + IF( ( EQ_16( ism_mode, ISM_MASA_MODE_DISC ) || EQ_16( ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_16( ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) && LT_32( L_sub( ivas_total_brate, ism_total_brate ), MIN_BRATE_MDCT_STEREO ) ) { *element_mode = IVAS_CPE_DFT; move16(); @@ -225,44 +225,44 @@ void ivas_masa_set_elements_fx( *nSCE = 0; move16(); - IF ( GT_32( ivas_total_brate, MIN_BRATE_MDCT_STEREO ) ) + IF( GT_32( ivas_total_brate, MIN_BRATE_MDCT_STEREO ) ) { *element_mode = IVAS_CPE_MDCT; move16(); } } - tmp = BASOP_Util_Divide3216_Scale(ivas_total_brate, FRAMES_PER_SEC, &tmp_e); - hQMetaData->bits_frame_nominal = shr(tmp, negate(add(1, tmp_e))); // Q0 - IF ( EQ_16(ivas_format, MASA_ISM_FORMAT) && ( EQ_16(ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ) || EQ_16(ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ) || EQ_16(ism_mode,ISM_MASA_MODE_DISC) ) ) + tmp = BASOP_Util_Divide3216_Scale( ivas_total_brate, FRAMES_PER_SEC, &tmp_e ); + hQMetaData->bits_frame_nominal = shr( tmp, negate( add( 1, tmp_e ) ) ); // Q0 + IF( EQ_16( ivas_format, MASA_ISM_FORMAT ) && ( EQ_16( ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_16( ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_16( ism_mode, ISM_MASA_MODE_DISC ) ) ) { - tmp = BASOP_Util_Divide3216_Scale(ism_total_brate, FRAMES_PER_SEC, &tmp_e); - tmp = shr(tmp, negate(add(1, tmp_e))); // Q0 - hQMetaData->bits_frame_nominal = sub(hQMetaData->bits_frame_nominal, tmp); + tmp = BASOP_Util_Divide3216_Scale( ism_total_brate, FRAMES_PER_SEC, &tmp_e ); + tmp = shr( tmp, negate( add( 1, tmp_e ) ) ); // Q0 + hQMetaData->bits_frame_nominal = sub( hQMetaData->bits_frame_nominal, tmp ); } } - ELSE IF ( GE_16( nchan_transport, 1 ) ) + ELSE IF( GE_16( nchan_transport, 1 ) ) { *nCPE = 0; move16(); *nSCE = 1; move16(); - IF ( EQ_32( ivas_total_brate, IVAS_13k2 ) ) + IF( EQ_32( ivas_total_brate, IVAS_13k2 ) ) { hQMetaData->bits_frame_nominal = ACELP_9k60 / FRAMES_PER_SEC; move16(); } - ELSE IF ( LE_32( ivas_total_brate, IVAS_16k4 ) ) + ELSE IF( LE_32( ivas_total_brate, IVAS_16k4 ) ) { hQMetaData->bits_frame_nominal = ACELP_13k20 / FRAMES_PER_SEC; move16(); } - ELSE IF ( LE_32( ivas_total_brate, IVAS_24k4 ) ) + ELSE IF( LE_32( ivas_total_brate, IVAS_24k4 ) ) { hQMetaData->bits_frame_nominal = ACELP_16k40 / FRAMES_PER_SEC; move16(); } - ELSE IF ( LE_32( ivas_total_brate, IVAS_32k ) ) + ELSE IF( LE_32( ivas_total_brate, IVAS_32k ) ) { hQMetaData->bits_frame_nominal = ACELP_24k40 / FRAMES_PER_SEC; move16(); @@ -1039,7 +1039,7 @@ UWord16 index_theta_phi_16_fx( { IF( GT_16( gridData->no_phi[id_th], 1 ) ) { - id_phi = quantize_phi_masa_fx( phi_fx, (Word16)EQ_16( s_and( id_th, 1 ), 1 ), &phi_hat_fx, gridData->no_phi[id_th] ); + id_phi = quantize_phi_masa_fx( phi_fx, (Word16) EQ_16( s_and( id_th, 1 ), 1 ), &phi_hat_fx, gridData->no_phi[id_th] ); } ELSE { @@ -1050,7 +1050,7 @@ UWord16 index_theta_phi_16_fx( } ELSE { - id_phi = quantize_phi_masa_fx( phi_fx, (Word16)EQ_16( s_and( id_th, 1 ), 1 ), &phi_hat_fx, gridData->no_phi[id_th] ); + id_phi = quantize_phi_masa_fx( phi_fx, (Word16) EQ_16( s_and( id_th, 1 ), 1 ), &phi_hat_fx, gridData->no_phi[id_th] ); } *p_theta = theta_hat_fx; @@ -1194,10 +1194,10 @@ static Word16 quantize_theta_masa_fx( /*! r: index azimuth */ static int16_t quantize_phi_masa( - float phi, /* i : azimuth value */ - const Word16 flag_delta, /* i : flag indicating if the azimuth codebook is translated or not */ - float *phi_hat, /* o : quantized azimuth */ - const Word16 n /* i : azimuth codebook size */ + float phi, /* i : azimuth value */ + const Word16 flag_delta, /* i : flag indicating if the azimuth codebook is translated or not */ + float *phi_hat, /* o : quantized azimuth */ + const Word16 n /* i : azimuth codebook size */ ) { int16_t id_phi; @@ -1601,8 +1601,8 @@ void deindex_sph_idx_fx( } } } - *theta_fx = (Word32)(theta * ( 1 << 22 )); - *phi_fx = (Word32)(phi * ( 1 << 22 )); + *theta_fx = (Word32) ( theta * ( 1 << 22 ) ); + *phi_fx = (Word32) ( phi * ( 1 << 22 ) ); return; } @@ -1666,27 +1666,27 @@ Word16 valid_ratio_index_fx( move16(); set16_fx( base, 1, len ); - FOR ( i = 1; i < len; i++ ) + FOR( i = 1; i < len; i++ ) { - base[i] = i_mult(base[i - 1], 10); + base[i] = i_mult( base[i - 1], 10 ); } sum = 0; move16(); - FOR ( i = len - 1; i >= 0; i-- ) + FOR( i = len - 1; i >= 0; i-- ) { - IF(EQ_16(index, 0)) + IF( EQ_16( index, 0 ) ) { elem = 0; move16(); } ELSE { - elem = idiv1616(index, base[i]); + elem = idiv1616( index, base[i] ); } - sum = add(sum, elem); - index = sub(index, i_mult(elem, base[i])); + sum = add( sum, elem ); + index = sub( index, i_mult( elem, base[i] ) ); } - IF ( LE_16(sum, K ) ) + IF( LE_16( sum, K ) ) { out = 1; move16(); @@ -1916,7 +1916,7 @@ void distribute_evenly_ism_fx( move16(); FOR( i = 0; i < nchan_ism; i++ ) { - IF(EQ_16(K, 0)) + IF( EQ_16( K, 0 ) ) { idx[i] = 0; move16(); @@ -2044,4 +2044,3 @@ Word32 calculate_cpe_brate_MASA_ISM_fx( return cpe_brate; } - diff --git a/lib_com/ivas_mc_com.c b/lib_com/ivas_mc_com.c index 92f855920..ec3b5333e 100644 --- a/lib_com/ivas_mc_com.c +++ b/lib_com/ivas_mc_com.c @@ -48,74 +48,74 @@ /*! r : MC format mode */ MC_MODE ivas_mc_mode_select( const MC_LS_SETUP mc_ls_setup, /* i : MC loudspeaker setup */ - const Word32 total_brate /* i : IVAS total bitrate */ + const Word32 total_brate /* i : IVAS total bitrate */ ) { MC_MODE mc_mode = MC_MODE_MCT; move16(); - SWITCH ( mc_ls_setup ) + SWITCH( mc_ls_setup ) { case MC_LS_SETUP_5_1: - IF ( LT_32( total_brate, IVAS_48k ) ) + IF( LT_32( total_brate, IVAS_48k ) ) { mc_mode = MC_MODE_MCMASA; move16(); } - ELSE IF ( LT_32( total_brate, IVAS_96k ) ) + ELSE IF( LT_32( total_brate, IVAS_96k ) ) { mc_mode = MC_MODE_PARAMMC; move16(); } BREAK; case MC_LS_SETUP_7_1: - IF ( LT_32( total_brate, IVAS_48k ) ) + IF( LT_32( total_brate, IVAS_48k ) ) { mc_mode = MC_MODE_MCMASA; move16(); } - ELSE IF ( LT_32( total_brate, IVAS_128k ) ) + ELSE IF( LT_32( total_brate, IVAS_128k ) ) { mc_mode = MC_MODE_PARAMMC; move16(); } BREAK; case MC_LS_SETUP_5_1_2: - IF ( LT_32( total_brate, IVAS_48k ) ) + IF( LT_32( total_brate, IVAS_48k ) ) { mc_mode = MC_MODE_MCMASA; move16(); } - ELSE IF ( LT_32( total_brate, IVAS_128k ) ) + ELSE IF( LT_32( total_brate, IVAS_128k ) ) { mc_mode = MC_MODE_PARAMMC; move16(); } BREAK; case MC_LS_SETUP_5_1_4: - IF ( LT_32( total_brate, IVAS_96k ) ) + IF( LT_32( total_brate, IVAS_96k ) ) { mc_mode = MC_MODE_MCMASA; move16(); } - ELSE IF ( LT_32( total_brate, IVAS_160k ) ) + ELSE IF( LT_32( total_brate, IVAS_160k ) ) { mc_mode = MC_MODE_PARAMMC; move16(); } BREAK; case MC_LS_SETUP_7_1_4: - IF ( LT_32( total_brate, IVAS_128k ) ) + IF( LT_32( total_brate, IVAS_128k ) ) { mc_mode = MC_MODE_MCMASA; move16(); } - ELSE IF ( LT_32( total_brate, IVAS_160k ) ) + ELSE IF( LT_32( total_brate, IVAS_160k ) ) { mc_mode = MC_MODE_PARAMMC; move16(); } - ELSE IF ( LT_32( total_brate, IVAS_192k ) ) + ELSE IF( LT_32( total_brate, IVAS_192k ) ) { mc_mode = MC_MODE_PARAMUPMIX; move16(); @@ -146,7 +146,7 @@ Word16 ivas_mc_ls_setup_get_num_channels( nchan = 0; move16(); - SWITCH ( mc_ls_setup ) + SWITCH( mc_ls_setup ) { case MC_LS_SETUP_5_1: nchan = 6; @@ -225,7 +225,7 @@ MC_LS_SETUP ivas_mc_map_output_config_to_mc_ls_setup( mc_ls_setup = MC_LS_SETUP_INVALID; move16(); - SWITCH ( output_config ) + SWITCH( output_config ) { case IVAS_AUDIO_CONFIG_5_1: mc_ls_setup = MC_LS_SETUP_5_1; @@ -290,7 +290,7 @@ AUDIO_CONFIG ivas_mc_map_ls_setup_to_output_config( default: assert( 0 && "MC loudspeaker setup is not valid!\n" ); } - move16(); + move16(); return audio_config; } diff --git a/lib_com/ivas_mc_param_com.c b/lib_com/ivas_mc_param_com.c index a56d013d0..07c646cb7 100644 --- a/lib_com/ivas_mc_param_com.c +++ b/lib_com/ivas_mc_param_com.c @@ -102,11 +102,11 @@ uint16_t ivas_param_mc_get_configuration_index( #ifdef IVAS_FLOAT_FIXED void ivas_param_mc_metadata_open( - const MC_LS_SETUP mc_ls_setup, /* i : MC ls setup */ + const MC_LS_SETUP mc_ls_setup, /* i : MC ls setup */ #ifndef FIX_901_PARAMMC_DEAD_CODE - const Word16 lfe_index, /* i : channel index of LFE */ + const Word16 lfe_index, /* i : channel index of LFE */ #endif - const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC /* o : handle for the Parametric MC parameter coding state */ ) { @@ -128,21 +128,21 @@ void ivas_param_mc_metadata_open( /* get configuration index */ config_index = ivas_param_mc_get_configuration_index( mc_ls_setup, ivas_total_brate ); - IF ( EQ_16((Word16)config_index , PARAM_MC_NUM_CONFIGS) ) + IF( EQ_16( (Word16) config_index, PARAM_MC_NUM_CONFIGS ) ) { assert( 0 && "ParamMC configuration index not found!" ); } /* Band Grouping */ - IF ( EQ_16(hMetadataPMC->num_parameter_bands , 20) ) + IF( EQ_16( hMetadataPMC->num_parameter_bands, 20 ) ) { Copy( param_mc_coding_band_mapping_20, hMetadataPMC->coding_band_mapping, 20 ); } - ELSE IF ( EQ_16(hMetadataPMC->num_parameter_bands , 14) ) + ELSE IF( EQ_16( hMetadataPMC->num_parameter_bands, 14 ) ) { Copy( param_mc_coding_band_mapping_14, hMetadataPMC->coding_band_mapping, 14 ); } - ELSE IF ( EQ_16(hMetadataPMC->num_parameter_bands , 10) ) + ELSE IF( EQ_16( hMetadataPMC->num_parameter_bands, 10 ) ) { Copy( param_mc_coding_band_mapping_10, hMetadataPMC->coding_band_mapping, 10 ); } @@ -156,34 +156,34 @@ void ivas_param_mc_metadata_open( #endif hMetadataPMC->icc_mapping_conf = ivas_param_mc_conf[config_index].icc_mapping_conf; hMetadataPMC->ild_mapping_conf = ivas_param_mc_conf[config_index].ild_mapping_conf; - hMetadataPMC->ild_factors = ivas_param_mc_conf[config_index].ild_factors; //float + hMetadataPMC->ild_factors = ivas_param_mc_conf[config_index].ild_factors; // float hMetadataPMC->ild_factors_fx = ivas_param_mc_conf[config_index].ild_factors_fx; #ifndef FIX_901_PARAMMC_DEAD_CODE /* set default ICC maps */ - FOR ( i = 0; i < PARAM_MC_PARAMETER_FRAMES; i++ ) + FOR( i = 0; i < PARAM_MC_PARAMETER_FRAMES; i++ ) { ivas_param_mc_default_icc_map( hMetadataPMC->icc_mapping_conf, hMetadataPMC->icc_mapping[i] ); } #endif /* init remaining flags and indices */ hMetadataPMC->param_frame_idx = 0; - move16(); + move16(); #ifndef FIX_901_PARAMMC_DEAD_CODE hMetadataPMC->flag_use_adaptive_icc_map = 0; - move16(); + move16(); #endif hMetadataPMC->bAttackPresent = 0; - move16(); + move16(); hMetadataPMC->attackIndex = 0; - move16(); + move16(); hMetadataPMC->lfe_on = 1; - move16(); + move16(); /* set coded bwidth to FB at the beginning */ hMetadataPMC->coded_bwidth = FB; - move16(); + move16(); hMetadataPMC->last_coded_bwidth = FB; - move16(); + move16(); ivas_param_mc_set_coded_bands( hMetadataPMC ); @@ -822,7 +822,7 @@ static void ivas_param_mc_set_coding_scheme( hMetadataPMC->icc_coding.sym_freq = &ivas_param_mc_sym_freq_icc_cicp6_48_16bits[0]; hMetadataPMC->icc_coding.cum_freq_delta = &ivas_param_mc_cum_freq_icc_delta_cicp6_48_16bits[0]; hMetadataPMC->icc_coding.sym_freq_delta = &ivas_param_mc_sym_freq_icc_delta_cicp6_48_16bits[0]; - hMetadataPMC->icc_coding.quantizer = &ivas_param_mc_quant_icc[0]; //float + hMetadataPMC->icc_coding.quantizer = &ivas_param_mc_quant_icc[0]; // float hMetadataPMC->icc_coding.quantizer_fx = &ivas_param_mc_quant_icc_fx[0]; hMetadataPMC->icc_coding.quantizer_size = PARAM_MC_SZ_ICC_QUANTIZER; move16(); @@ -833,7 +833,7 @@ static void ivas_param_mc_set_coding_scheme( hMetadataPMC->ild_coding.sym_freq = &ivas_param_mc_sym_freq_ild_cicp6_48_16bits[0]; hMetadataPMC->ild_coding.cum_freq_delta = &ivas_param_mc_cum_freq_ild_delta_cicp6_48_16bits[0]; hMetadataPMC->ild_coding.sym_freq_delta = &ivas_param_mc_sym_freq_ild_delta_cicp6_48_16bits[0]; - hMetadataPMC->ild_coding.quantizer = &ivas_param_mc_quant_ild_5d1_48[0]; //float + hMetadataPMC->ild_coding.quantizer = &ivas_param_mc_quant_ild_5d1_48[0]; // float hMetadataPMC->ild_coding.quantizer_fx = &ivas_param_mc_quant_ild_5d1_48_fx[0]; hMetadataPMC->ild_coding.quantizer_size = PARAM_MC_SZ_ILD_QUANTIZER_4BITS; move16(); @@ -846,7 +846,7 @@ static void ivas_param_mc_set_coding_scheme( hMetadataPMC->icc_coding.sym_freq = &ivas_param_mc_sym_freq_icc_cicp12_48_16bits[0]; hMetadataPMC->icc_coding.cum_freq_delta = &ivas_param_mc_cum_freq_icc_delta_cicp12_48_16bits[0]; hMetadataPMC->icc_coding.sym_freq_delta = &ivas_param_mc_sym_freq_icc_delta_cicp12_48_16bits[0]; - hMetadataPMC->icc_coding.quantizer = &ivas_param_mc_quant_icc[0]; //float + hMetadataPMC->icc_coding.quantizer = &ivas_param_mc_quant_icc[0]; // float hMetadataPMC->icc_coding.quantizer_fx = &ivas_param_mc_quant_icc_fx[0]; hMetadataPMC->icc_coding.quantizer_size = PARAM_MC_SZ_ICC_QUANTIZER; move16(); @@ -857,7 +857,7 @@ static void ivas_param_mc_set_coding_scheme( hMetadataPMC->ild_coding.sym_freq = &ivas_param_mc_sym_freq_ild_cicp12_48_16bits[0]; hMetadataPMC->ild_coding.cum_freq_delta = &ivas_param_mc_cum_freq_ild_delta_cicp12_48_16bits[0]; hMetadataPMC->ild_coding.sym_freq_delta = &ivas_param_mc_sym_freq_ild_delta_cicp12_48_16bits[0]; - hMetadataPMC->ild_coding.quantizer = &ivas_param_mc_quant_ild_5d1_48[0]; //float + hMetadataPMC->ild_coding.quantizer = &ivas_param_mc_quant_ild_5d1_48[0]; // float hMetadataPMC->ild_coding.quantizer_fx = &ivas_param_mc_quant_ild_5d1_48_fx[0]; hMetadataPMC->ild_coding.quantizer_size = PARAM_MC_SZ_ILD_QUANTIZER_4BITS; move16(); @@ -870,7 +870,7 @@ static void ivas_param_mc_set_coding_scheme( hMetadataPMC->icc_coding.sym_freq = &ivas_param_mc_sym_freq_icc_cicp14_48_16bits[0]; hMetadataPMC->icc_coding.cum_freq_delta = &ivas_param_mc_cum_freq_icc_delta_cicp14_48_16bits[0]; hMetadataPMC->icc_coding.sym_freq_delta = &ivas_param_mc_sym_freq_icc_delta_cicp14_48_16bits[0]; - hMetadataPMC->icc_coding.quantizer = &ivas_param_mc_quant_icc[0]; //float + hMetadataPMC->icc_coding.quantizer = &ivas_param_mc_quant_icc[0]; // float hMetadataPMC->icc_coding.quantizer_fx = &ivas_param_mc_quant_icc_fx[0]; hMetadataPMC->icc_coding.quantizer_size = PARAM_MC_SZ_ICC_QUANTIZER; move16(); @@ -881,7 +881,7 @@ static void ivas_param_mc_set_coding_scheme( hMetadataPMC->ild_coding.sym_freq = &ivas_param_mc_sym_freq_ild_cicp14_48_16bits[0]; hMetadataPMC->ild_coding.cum_freq_delta = &ivas_param_mc_cum_freq_ild_delta_cicp14_48_16bits[0]; hMetadataPMC->ild_coding.sym_freq_delta = &ivas_param_mc_sym_freq_ild_delta_cicp14_48_16bits[0]; - hMetadataPMC->ild_coding.quantizer = &ivas_param_mc_quant_ild_5d1_48[0]; //float + hMetadataPMC->ild_coding.quantizer = &ivas_param_mc_quant_ild_5d1_48[0]; // float hMetadataPMC->ild_coding.quantizer_fx = &ivas_param_mc_quant_ild_5d1_48_fx[0]; hMetadataPMC->ild_coding.quantizer_size = PARAM_MC_SZ_ILD_QUANTIZER_4BITS; move16(); @@ -895,7 +895,7 @@ static void ivas_param_mc_set_coding_scheme( hMetadataPMC->icc_coding.sym_freq = &ivas_param_mc_sym_freq_icc_combined_48_16bits[0]; hMetadataPMC->icc_coding.cum_freq_delta = &ivas_param_mc_cum_freq_icc_delta_combined_48_16bits[0]; hMetadataPMC->icc_coding.sym_freq_delta = &ivas_param_mc_sym_freq_icc_delta_combined_48_16bits[0]; - hMetadataPMC->icc_coding.quantizer = &ivas_param_mc_quant_icc[0]; //float + hMetadataPMC->icc_coding.quantizer = &ivas_param_mc_quant_icc[0]; // float hMetadataPMC->icc_coding.quantizer_fx = &ivas_param_mc_quant_icc_fx[0]; hMetadataPMC->icc_coding.quantizer_size = PARAM_MC_SZ_ICC_QUANTIZER; move16(); @@ -906,7 +906,7 @@ static void ivas_param_mc_set_coding_scheme( hMetadataPMC->ild_coding.sym_freq = &ivas_param_mc_sym_freq_ild_combined_48_16bits[0]; hMetadataPMC->ild_coding.cum_freq_delta = &ivas_param_mc_cum_freq_ild_delta_combined_48_16bits[0]; hMetadataPMC->ild_coding.sym_freq_delta = &ivas_param_mc_sym_freq_ild_delta_combined_48_16bits[0]; - hMetadataPMC->ild_coding.quantizer = &ivas_param_mc_quant_ild_5d1_48[0]; //float + hMetadataPMC->ild_coding.quantizer = &ivas_param_mc_quant_ild_5d1_48[0]; // float hMetadataPMC->ild_coding.quantizer_fx = &ivas_param_mc_quant_ild_5d1_48_fx[0]; hMetadataPMC->ild_coding.quantizer_size = PARAM_MC_SZ_ILD_QUANTIZER_4BITS; move16(); diff --git a/lib_com/ivas_mct_com.c b/lib_com/ivas_mct_com.c index 7dac33b63..6da936755 100644 --- a/lib_com/ivas_mct_com.c +++ b/lib_com/ivas_mct_com.c @@ -231,7 +231,7 @@ void splitAvailableBitsMCT( FOR( i = 0; i < nchan; i++ ) { - IF(mct_chan_mode[i] != MCT_CHAN_MODE_IGNORE ) + IF( mct_chan_mode[i] != MCT_CHAN_MODE_IGNORE ) { min_chan_bits[i] = 0; move16(); @@ -275,7 +275,7 @@ void splitAvailableBitsMCT( mct_chan_mode[i] != MCT_CHAN_MODE_IGNORE ) { assert( split_ratio[i] >= 1 && split_ratio[i] < BITRATE_MCT_RATIO_RANGE ); - *bits_frame_channel = (Word16)L_shr((Word32)split_ratio[i]* remaining_bits, NBBITS_MCT_RATIO) + min_chan_bits[i]; + *bits_frame_channel = (Word16) L_shr( (Word32) split_ratio[i] * remaining_bits, NBBITS_MCT_RATIO ) + min_chan_bits[i]; move16(); bits_split += *bits_frame_channel; move16(); @@ -331,7 +331,7 @@ void splitAvailableBitsMCT( temp_res = L_shr( temp_res, NBBITS_MCT_RATIO ); move16(); } - *bits_frame_channel -= (Word16)temp_res; + *bits_frame_channel -= (Word16) temp_res; move16(); *bits_frame_channel = max( min_chan_bits[i], *bits_frame_channel ); move16(); @@ -376,4 +376,4 @@ void splitAvailableBitsMCT( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_com/ivas_mdct_imdct_fx.c b/lib_com/ivas_mdct_imdct_fx.c index a9c7370fa..c14432c08 100644 --- a/lib_com/ivas_mdct_imdct_fx.c +++ b/lib_com/ivas_mdct_imdct_fx.c @@ -63,13 +63,13 @@ *-----------------------------------------------------------------------------------------*/ void ivas_tda_fx( - const Word32 *pIn, /* i : time domain buffer of size 2*length */ - Word32 *pOut, /* o : time domain buffer of size length */ + const Word32 *pIn, /* i : time domain buffer of size 2*length */ + Word32 *pOut, /* o : time domain buffer of size length */ const Word16 length /* i : length of time alised signal buffer */ ) { Word16 i; - Word16 len_by_2 = shr(length, 1); + Word16 len_by_2 = shr( length, 1 ); FOR( i = 0; i < len_by_2; i++ ) { @@ -139,47 +139,47 @@ void ivas_mdct_fx( const Word32 *pIn, Word32 *pOut, const Word16 length, - Word16 *q_out) + Word16 *q_out ) { const Word16 *pTwid_re, *pTwid_im; Word16 i, len_by_2; Word32 re[IVAS_480_PT_LEN], im[IVAS_480_PT_LEN]; Word32 ivas_mdct_scaling_gain; - len_by_2 = shr(length, 1); + len_by_2 = shr( length, 1 ); ivas_mdct_scaling_gain = ivas_get_mdct_scaling_gain_fx( len_by_2 ); ivas_get_twid_factors_fx1( length, &pTwid_re, &pTwid_im ); - FOR ( i = 0; i < len_by_2; i++ ) + FOR( i = 0; i < len_by_2; i++ ) { - pOut[i] = L_sub(pIn[len_by_2 + i], pIn[len_by_2 - i - 1]); - pOut[len_by_2 + i] = L_add(pIn[length * 2 - i - 1], pIn[length + i]); + pOut[i] = L_sub( pIn[len_by_2 + i], pIn[len_by_2 - i - 1] ); + pOut[len_by_2 + i] = L_add( pIn[length * 2 - i - 1], pIn[length + i] ); } - FOR ( i = 0; i < len_by_2; i++ ) + FOR( i = 0; i < len_by_2; i++ ) { - re[i] = L_negate(L_add(Mpy_32_16_1( pOut[2 * i], pTwid_re[i]), Mpy_32_16_1(pOut[length - 1 - 2 * i], pTwid_im[i]))); - im[i] = L_sub(Mpy_32_16_1(pOut[length - 1 - 2 * i], pTwid_re[i]), Mpy_32_16_1(pOut[2 * i], pTwid_im[i])); + re[i] = L_negate( L_add( Mpy_32_16_1( pOut[2 * i], pTwid_re[i] ), Mpy_32_16_1( pOut[length - 1 - 2 * i], pTwid_im[i] ) ) ); + im[i] = L_sub( Mpy_32_16_1( pOut[length - 1 - 2 * i], pTwid_re[i] ), Mpy_32_16_1( pOut[2 * i], pTwid_im[i] ) ); } DoFFT_fx( &re[0], &im[0], len_by_2 ); - FOR ( i = 0; i < len_by_2; i++ ) + FOR( i = 0; i < len_by_2; i++ ) { - re[i] = Mult_32_32(re[i], ivas_mdct_scaling_gain); - im[i] = Mult_32_32(im[i], ivas_mdct_scaling_gain); + re[i] = Mult_32_32( re[i], ivas_mdct_scaling_gain ); + im[i] = Mult_32_32( im[i], ivas_mdct_scaling_gain ); } *q_out = *q_out + Q15; - FOR ( i = 0; i < len_by_2; i++ ) + FOR( i = 0; i < len_by_2; i++ ) { Word32 tmp; - tmp = L_sub(Mpy_32_16_1(re[i], pTwid_re[i]), Mpy_32_16_1(im[i], pTwid_im[i])); - im[i] = L_add(Mpy_32_16_1(im[i], pTwid_re[i]), Mpy_32_16_1(re[i], pTwid_im[i])); + tmp = L_sub( Mpy_32_16_1( re[i], pTwid_re[i] ), Mpy_32_16_1( im[i], pTwid_im[i] ) ); + im[i] = L_add( Mpy_32_16_1( im[i], pTwid_re[i] ), Mpy_32_16_1( re[i], pTwid_im[i] ) ); re[i] = tmp; } - FOR ( i = 0; i < len_by_2; i++ ) + FOR( i = 0; i < len_by_2; i++ ) { pOut[length - 2 * i - 1] = re[i]; pOut[2 * i] = im[i]; @@ -203,17 +203,17 @@ static void ivas_ifft_cplx( Word16 i; Word32 ivas_imdct_one_by_powergain = IVAS_ONE_BY_IMDCT_SCALING_GAIN_Q16; /*re-arrange inputs to use fft as ifft */ - re[0] = Mult_32_32(re[0], ivas_imdct_one_by_powergain); - im[0] = Mult_32_32(im[0], ivas_imdct_one_by_powergain); + re[0] = Mult_32_32( re[0], ivas_imdct_one_by_powergain ); + im[0] = Mult_32_32( im[0], ivas_imdct_one_by_powergain ); - FOR ( i = 1; i <= shr(length, 1); i++ ) + FOR( i = 1; i <= shr( length, 1 ); i++ ) { - Word32 tmp = Mult_32_32(re[length - i], ivas_imdct_one_by_powergain); - re[length - i] = Mult_32_32(re[i], ivas_imdct_one_by_powergain); + Word32 tmp = Mult_32_32( re[length - i], ivas_imdct_one_by_powergain ); + re[length - i] = Mult_32_32( re[i], ivas_imdct_one_by_powergain ); re[i] = tmp; - tmp = Mult_32_32(im[length - i], ivas_imdct_one_by_powergain); - im[length - i] = Mult_32_32(im[i], ivas_imdct_one_by_powergain); + tmp = Mult_32_32( im[length - i], ivas_imdct_one_by_powergain ); + im[length - i] = Mult_32_32( im[i], ivas_imdct_one_by_powergain ); im[i] = tmp; } @@ -230,15 +230,15 @@ static void ivas_ifft_cplx( *-----------------------------------------------------------------------------------------*/ void ivas_itda_fx( - const Word32 *re, /* i : time alised signal after IDCT */ - Word32 *pOut, /* o : time domain buffer of size 2*length */ + const Word32 *re, /* i : time alised signal after IDCT */ + Word32 *pOut, /* o : time domain buffer of size 2*length */ const Word16 length /* i : length of time alised signal buffer */ ) { Word16 i; - Word16 len_by_2 = shr(length, 1); + Word16 len_by_2 = shr( length, 1 ); - FOR ( i = 0; i < len_by_2; i++ ) + FOR( i = 0; i < len_by_2; i++ ) { pOut[i] = -re[len_by_2 - i - 1]; pOut[len_by_2 + i] = re[i]; @@ -260,43 +260,43 @@ void ivas_imdct_fx( const Word32 *pIn, Word32 *pOut, const Word16 length, - Word16 *q_out) + Word16 *q_out ) { const Word16 *pTwid_re, *pTwid_im; - Word16 len_by_2 = shr(length, 1); + Word16 len_by_2 = shr( length, 1 ); Word16 i; Word32 re[IVAS_480_PT_LEN]; Word32 im[IVAS_480_PT_LEN]; ivas_get_twid_factors_fx1( length, &pTwid_re, &pTwid_im ); - FOR ( i = 0; i < len_by_2; i++ ) + FOR( i = 0; i < len_by_2; i++ ) { - re[i] = L_add(Mpy_32_16_1(pIn[length - 2 * i - 1], pTwid_re[i]), Mpy_32_16_1(pIn[2 * i], pTwid_im[i])); /*stl_arr_index*/ + re[i] = L_add( Mpy_32_16_1( pIn[length - 2 * i - 1], pTwid_re[i] ), Mpy_32_16_1( pIn[2 * i], pTwid_im[i] ) ); /*stl_arr_index*/ im[i] = L_sub( Mpy_32_16_1( pIn[2 * i], pTwid_re[i] ), Mpy_32_16_1( pIn[length - 2 * i - 1], pTwid_im[i] ) ); /*stl_arr_index*/ } ivas_ifft_cplx( &re[0], &im[0], len_by_2 ); - IF (GT_16(len_by_2, 0)) + IF( GT_16( len_by_2, 0 ) ) { - *q_out = *q_out - Q15; + *q_out = *q_out - Q15; } - FOR ( i = 0; i < len_by_2; i++ ) + FOR( i = 0; i < len_by_2; i++ ) { Word32 tmp; - tmp = L_add(Mpy_32_16_1(re[i], pTwid_re[i]), Mpy_32_16_1(im[i], pTwid_im[i])); - im[i] = L_sub(Mpy_32_16_1(im[i], pTwid_re[i]), Mpy_32_16_1(re[i], pTwid_im[i])); + tmp = L_add( Mpy_32_16_1( re[i], pTwid_re[i] ), Mpy_32_16_1( im[i], pTwid_im[i] ) ); + im[i] = L_sub( Mpy_32_16_1( im[i], pTwid_re[i] ), Mpy_32_16_1( re[i], pTwid_im[i] ) ); re[i] = tmp; } - FOR ( i = ( len_by_2 - 1 ); i >= 0; i-- ) + FOR( i = ( len_by_2 - 1 ); i >= 0; i-- ) { re[2 * i + 1] = im[( len_by_2 - 1 ) - i]; re[2 * i] = -re[i]; } - FOR ( i = 0; i < len_by_2; i++ ) + FOR( i = 0; i < len_by_2; i++ ) { pOut[i] = -re[len_by_2 - i - 1]; pOut[len_by_2 + i] = re[i]; @@ -319,25 +319,25 @@ void ivas_get_twid_factors_fx1( const Word16 **pTwid_re, const Word16 **pTwid_im ) { - IF ( EQ_16(length, 480) ) + IF( EQ_16( length, 480 ) ) { - *pTwid_re = (const Word16 *)&ivas_cos_twiddle_480_fx[0]; - *pTwid_im = (const Word16 *)&ivas_sin_twiddle_480_fx[0]; + *pTwid_re = (const Word16 *) &ivas_cos_twiddle_480_fx[0]; + *pTwid_im = (const Word16 *) &ivas_sin_twiddle_480_fx[0]; } - ELSE IF ( EQ_16(length, 320) ) + ELSE IF( EQ_16( length, 320 ) ) { - *pTwid_re = (const Word16 *)&ivas_cos_twiddle_320_fx[0]; - *pTwid_im = (const Word16 *)&ivas_sin_twiddle_320_fx[0]; + *pTwid_re = (const Word16 *) &ivas_cos_twiddle_320_fx[0]; + *pTwid_im = (const Word16 *) &ivas_sin_twiddle_320_fx[0]; } - ELSE IF ( EQ_16(length, 160) ) + ELSE IF( EQ_16( length, 160 ) ) { - *pTwid_re = (const Word16 *)&ivas_cos_twiddle_160_fx[0]; - *pTwid_im = (const Word16 *)&ivas_sin_twiddle_160_fx[0]; + *pTwid_re = (const Word16 *) &ivas_cos_twiddle_160_fx[0]; + *pTwid_im = (const Word16 *) &ivas_sin_twiddle_160_fx[0]; } - ELSE IF ( EQ_16(length, 80 ) ) + ELSE IF( EQ_16( length, 80 ) ) { - *pTwid_re = (const Word16 *)&ivas_cos_twiddle_80_fx[0]; - *pTwid_im = (const Word16 *)&ivas_sin_twiddle_80_fx[0]; + *pTwid_re = (const Word16 *) &ivas_cos_twiddle_80_fx[0]; + *pTwid_im = (const Word16 *) &ivas_sin_twiddle_80_fx[0]; } ELSE { @@ -359,7 +359,7 @@ Word32 ivas_get_mdct_scaling_gain_fx( { Word32 gain = 0; - SWITCH ( dct_len_by_2 ) + SWITCH( dct_len_by_2 ) { case L_FRAME48k >> 2: { diff --git a/lib_com/ivas_mdft_imdft.c b/lib_com/ivas_mdft_imdft.c index 9bd3d6838..ab9339523 100644 --- a/lib_com/ivas_mdft_imdft.c +++ b/lib_com/ivas_mdft_imdft.c @@ -324,15 +324,15 @@ static void ivas_ifft_cplx1_fx( for ( i = 1; i <= length >> 1; i++ ) { - tmp = Mpy_32_32( re[length - i], one_by_length ); /*stl_arr_index*/ + tmp = Mpy_32_32( re[length - i], one_by_length ); /*stl_arr_index*/ re[length - i] = Mpy_32_32( re[i], one_by_length ); /*stl_arr_index*/ re[i] = tmp; - tmp = Mpy_32_32( im[length - i], one_by_length ); /*stl_arr_index*/ + tmp = Mpy_32_32( im[length - i], one_by_length ); /*stl_arr_index*/ im[length - i] = Mpy_32_32( im[i], one_by_length ); /*stl_arr_index*/ im[i] = tmp; } - + fft_fx( re, im, length, 1 ); return; @@ -347,9 +347,9 @@ static void ivas_ifft_cplx1_fx( *-----------------------------------------------------------------------------------------*/ void ivas_mdft_fx( - const Word32 *pIn, /* i : input time-domain signal */ - Word32 *pOut_re, /* o : Real part of MDFT signal */ - Word32 *pOut_im, /* o : Imag. part of MDFT signal */ + const Word32 *pIn, /* i : input time-domain signal */ + Word32 *pOut_re, /* o : Real part of MDFT signal */ + Word32 *pOut_im, /* o : Imag. part of MDFT signal */ const Word16 input_length, /* i : signal length */ const Word16 mdft_length /* i : MDFT length */ ) @@ -365,19 +365,19 @@ void ivas_mdft_fx( { for ( j = 0; j < mdft_length; j++ ) { - re[j] = Mpy_32_32(pIn[j] , pTwid[j]); - im[j] = Mpy_32_32 (- pIn[j] , pTwid[mdft_length - j]); + re[j] = Mpy_32_32( pIn[j], pTwid[j] ); + im[j] = Mpy_32_32( -pIn[j], pTwid[mdft_length - j] ); } } else { for ( j = 0; j < mdft_length; j++ ) { - re[j] = Msub_32_32(Mpy_32_32(pIn[j] , pTwid[j]) , pIn[j + mdft_length] , pTwid[mdft_length - j]); - im[j] = Msub_32_32(Mpy_32_32(-pIn[j] , pTwid[mdft_length - j]) , pIn[j + mdft_length] , pTwid[j]); + re[j] = Msub_32_32( Mpy_32_32( pIn[j], pTwid[j] ), pIn[j + mdft_length], pTwid[mdft_length - j] ); + im[j] = Msub_32_32( Mpy_32_32( -pIn[j], pTwid[mdft_length - j] ), pIn[j + mdft_length], pTwid[j] ); } } - + fft_fx( re, im, mdft_length, 1 ); for ( j = 0; j < len_by_2; j++ ) { @@ -399,9 +399,9 @@ void ivas_mdft_fx( *-----------------------------------------------------------------------------------------*/ void ivas_imdft_fx( - const Word32 *pRe, /* i : Real part of MDFT signal */ - const Word32 *pIm, /* i : Imag. part of MDFT signal */ - Word32 *pOut, /* o : output time-domain signal */ + const Word32 *pRe, /* i : Real part of MDFT signal */ + const Word32 *pIm, /* i : Imag. part of MDFT signal */ + Word32 *pOut, /* o : output time-domain signal */ const Word16 length /* i : signal length */ ) { @@ -424,11 +424,11 @@ void ivas_imdft_fx( } ivas_ifft_cplx1_fx( re_tmp, im_tmp, length ); - + for ( j = 0; j < length; j++ ) { - tmp = Msub_32_32(Mpy_32_32(re_tmp[j] >> 6 , pTwid[j]) , im_tmp[j] >> 6, pTwid[length - j]); - im_tmp[j] = -( Madd_32_32( Mpy_32_32(re_tmp[j] >> 6, pTwid[length - j]) , im_tmp[j] >> 6, pTwid[j] )); + tmp = Msub_32_32( Mpy_32_32( re_tmp[j] >> 6, pTwid[j] ), im_tmp[j] >> 6, pTwid[length - j] ); + im_tmp[j] = -( Madd_32_32( Mpy_32_32( re_tmp[j] >> 6, pTwid[length - j] ), im_tmp[j] >> 6, pTwid[j] ) ); re_tmp[j] = tmp; } return; @@ -566,4 +566,4 @@ void ivas_imdft( } return; -} \ No newline at end of file +} diff --git a/lib_com/ivas_omasa_com.c b/lib_com/ivas_omasa_com.c index d7b0c9e33..c76621969 100644 --- a/lib_com/ivas_omasa_com.c +++ b/lib_com/ivas_omasa_com.c @@ -95,7 +95,7 @@ ISM_MODE ivas_omasa_ism_mode_select( ) { ISM_MODE ism_mode = ISM_MODE_NONE; - move16(); + move16(); SWITCH( nchan_ism ) { @@ -103,68 +103,68 @@ ISM_MODE ivas_omasa_ism_mode_select( IF( GE_32( ivas_total_brate, IVAS_24k4 ) ) { ism_mode = ISM_MASA_MODE_DISC; - move16(); + move16(); } ELSE { ism_mode = ISM_MODE_NONE; - move16(); + move16(); } BREAK; case 2: IF( GE_32( ivas_total_brate, IVAS_48k ) ) { ism_mode = ISM_MASA_MODE_DISC; - move16(); + move16(); } ELSE IF( GE_32( ivas_total_brate, IVAS_32k ) ) { ism_mode = ISM_MASA_MODE_PARAM_ONE_OBJ; - move16(); + move16(); } ELSE { ism_mode = ISM_MODE_NONE; - move16(); + move16(); } BREAK; case 3: IF( GE_32( ivas_total_brate, IVAS_96k ) ) { ism_mode = ISM_MASA_MODE_DISC; - move16(); + move16(); } ELSE IF( GE_32( ivas_total_brate, IVAS_64k ) ) { ism_mode = ISM_MASA_MODE_PARAM_ONE_OBJ; - move16(); + move16(); } ELSE IF( GE_32( ivas_total_brate, IVAS_32k ) ) { ism_mode = ISM_MASA_MODE_MASA_ONE_OBJ; - move16(); + move16(); } ELSE { ism_mode = ISM_MODE_NONE; - move16(); + move16(); } BREAK; case 4: IF( GE_32( ivas_total_brate, IVAS_128k ) ) { ism_mode = ISM_MASA_MODE_DISC; - move16(); + move16(); } ELSE IF( GE_32( ivas_total_brate, IVAS_64k ) ) { ism_mode = ISM_MASA_MODE_PARAM_ONE_OBJ; - move16(); + move16(); } ELSE IF( GE_32( ivas_total_brate, IVAS_32k ) ) { ism_mode = ISM_MASA_MODE_MASA_ONE_OBJ; - move16(); + move16(); } ELSE { @@ -639,7 +639,7 @@ void ivas_combined_format_brate_sanity( IF( LT_32( element_brate, ACELP_12k8_HIGH_LIMIT ) ) { limit_high = ACELP_12k8_HIGH_LIMIT / FRAMES_PER_SEC; - move16(); + move16(); nBits = extract_l( div_l( *core_brate, shr( FRAMES_PER_SEC, 1 ) ) ); *diff_nBits = sub( nBits, limit_high ); @@ -664,7 +664,7 @@ void ivas_combined_format_brate_sanity( IF( EQ_16( core, ACELP_CORE ) ) { *inactive_coder_type_flag = 0; /* AVQ by default */ - move16(); + move16(); IF( LE_32( L_add( *core_brate, brate_diff ), MAX_GSC_INACTIVE_BRATE ) ) { *inactive_coder_type_flag = 1; /* GSC */ @@ -1240,4 +1240,4 @@ int16_t calculate_brate_limit_flag( return brate_limit_flag; } -#endif \ No newline at end of file +#endif diff --git a/lib_com/ivas_pca_tools.c b/lib_com/ivas_pca_tools.c index b3f04d7ef..98db76f4b 100644 --- a/lib_com/ivas_pca_tools.c +++ b/lib_com/ivas_pca_tools.c @@ -69,24 +69,24 @@ void eye_matrix( #ifdef IVAS_FLOAT_FIXED void eye_matrix_fx( - Word16 *mat, - const Word16 n, - const Word16 d) + Word16 *mat, + const Word16 n, + const Word16 d ) { - Word16 i; + Word16 i; - FOR(i = 0; i < n * n; i++) - { - mat[i] = 0; - move16(); - } - FOR(i = 0; i < n; i++) - { - mat[i * n + i] = d; - move16(); - } + FOR( i = 0; i < n * n; i++ ) + { + mat[i] = 0; + move16(); + } + FOR( i = 0; i < n; i++ ) + { + mat[i * n + i] = d; + move16(); + } - return; + return; } #endif /*---------------------------------------------------------------------* @@ -573,14 +573,22 @@ void dquat2mat_fx( Word16 cw, cx, cy, cz; Word16 dw, dx, dy, dz; - a = ql[0];move16(); - b = ql[1];move16(); - c = ql[2];move16(); - d = ql[3];move16(); - w = qr[0];move16(); - x = qr[1];move16(); - y = qr[2];move16(); - z = qr[3];move16(); + a = ql[0]; + move16(); + b = ql[1]; + move16(); + c = ql[2]; + move16(); + d = ql[3]; + move16(); + w = qr[0]; + move16(); + x = qr[1]; + move16(); + y = qr[2]; + move16(); + z = qr[3]; + move16(); aw = mult( a, w ); // Ql + Qr - 15 ax = mult( a, x ); ay = mult( a, y ); @@ -676,58 +684,60 @@ void quat_shortestpath( #ifdef IVAS_FLOAT_FIXED // Not tested void quat_shortestpath_fx( - const Word16 *q00, - Word16 *q01, - const Word16 *q10, - Word16 *q11) + const Word16 *q00, + Word16 *q01, + const Word16 *q10, + Word16 *q11 ) { - Word32 d0, d1; - Word16 res, i; - Word16 exp1 = 0, exp2 = 0; - - d0 = dotp_fx(q00, q01, IVAS_PCA_INTERP, &exp1); - d1 = dotp_fx(q10, q11, IVAS_PCA_INTERP, &exp2); - - res = 0; - move16(); - IF(LT_32(d0, 0) && LT_32(d1, 0)) - { - res = 1; + Word32 d0, d1; + Word16 res, i; + Word16 exp1 = 0, exp2 = 0; + + d0 = dotp_fx( q00, q01, IVAS_PCA_INTERP, &exp1 ); + d1 = dotp_fx( q10, q11, IVAS_PCA_INTERP, &exp2 ); + + res = 0; move16(); - } - ELSE - { - IF(LT_32(d0, 0)) - { - IF(GT_32((-d0), d1)) - { - res = 1; - move16(); - } - } - ELSE - { - IF(LT_32(d1, 0)) - { - IF(GT_32((-d1), d0)) - { - res = 1; - move16(); - } - } - } - } - - IF(res) - { - FOR(i = 0; i < IVAS_PCA_INTERP; i++) + IF( LT_32( d0, 0 ) && LT_32( d1, 0 ) ) + { + res = 1; + move16(); + } + ELSE + { + IF( LT_32( d0, 0 ) ) { - q01[i] = -q01[i];move16(); - q11[i] = -q11[i];move16(); + IF( GT_32( ( -d0 ), d1 ) ) + { + res = 1; + move16(); + } } - } + ELSE + { + IF( LT_32( d1, 0 ) ) + { + IF( GT_32( ( -d1 ), d0 ) ) + { + res = 1; + move16(); + } + } + } + } - return; + IF( res ) + { + FOR( i = 0; i < IVAS_PCA_INTERP; i++ ) + { + q01[i] = -q01[i]; + move16(); + q11[i] = -q11[i]; + move16(); + } + } + + return; } #endif /*---------------------------------------------------------------------* @@ -789,20 +799,20 @@ static void norm_quat( #ifdef IVAS_FLOAT_FIXED static void norm_quat_fx( - Word16 *q) + Word16 *q ) { - Word32 norm_q; - Word16 i, exp1 = 0; - norm_q = dotp_fx(q, q, IVAS_PCA_INTERP, &exp1); - exp1 = (31 - (exp1 + 2)); - norm_q = ISqrt32(norm_q, &exp1); /*q(15 - exp)*/ - - FOR(i = 0; i < IVAS_PCA_INTERP; i++) - { - q[i] = mult(q[i], (Word16)L_shr(norm_q, 15)); // todo : recheck - } - - return; + Word32 norm_q; + Word16 i, exp1 = 0; + norm_q = dotp_fx( q, q, IVAS_PCA_INTERP, &exp1 ); + exp1 = ( 31 - ( exp1 + 2 ) ); + norm_q = ISqrt32( norm_q, &exp1 ); /*q(15 - exp)*/ + + FOR( i = 0; i < IVAS_PCA_INTERP; i++ ) + { + q[i] = mult( q[i], (Word16) L_shr( norm_q, 15 ) ); // todo : recheck + } + + return; } #endif @@ -826,26 +836,26 @@ static void quat_nlerp_preproc( #ifdef IVAS_FLOAT_FIXED static void quat_nlerp_preproc_fx( - const Word16 *q0, - const Word16 *q1, - const Word16 alpha, - Word16 *q_slerp) + const Word16 *q0, + const Word16 *q1, + const Word16 alpha, + Word16 *q_slerp ) { - Word16 i; - Word16 tmp1, tmp2; + Word16 i; + Word16 tmp1, tmp2; - FOR(i = 0; i < IVAS_PCA_INTERP; i++) - { - tmp1 = mult((MAX_16 - alpha), q1[i]); - tmp2 = mult_r(alpha, q0[i]); - IF((alpha == q0[i]) && (alpha == 32767)) - tmp2 = 32767; - q_slerp[i] = add(tmp1, tmp2); - } + FOR( i = 0; i < IVAS_PCA_INTERP; i++ ) + { + tmp1 = mult( ( MAX_16 - alpha ), q1[i] ); + tmp2 = mult_r( alpha, q0[i] ); + IF( ( alpha == q0[i] ) && ( alpha == 32767 ) ) + tmp2 = 32767; + q_slerp[i] = add( tmp1, tmp2 ); + } - norm_quat_fx(q_slerp); + norm_quat_fx( q_slerp ); - return; + return; } #endif @@ -874,35 +884,36 @@ void pca_interp_preproc( } #ifdef IVAS_FLOAT_FIXED void pca_interp_preproc_fx( - const Word16 *prev_ql, - const Word16 *prev_qr, - const Word16 *ql, - const Word16 *qr, - const Word16 len, - Word16 *ql_interp, - Word16 *qr_interp) + const Word16 *prev_ql, + const Word16 *prev_qr, + const Word16 *ql, + const Word16 *qr, + const Word16 len, + Word16 *ql_interp, + Word16 *qr_interp ) { - Word16 alpha; - Word16 j; - Word16 tmp, tmp2, tmp3; - FOR(j = 0; j < len; j++) - { - tmp = sub(len, 1); - IF(EQ_16(j, 0)) { - alpha = 0; - move16(); + Word16 alpha; + Word16 j; + Word16 tmp, tmp2, tmp3; + FOR( j = 0; j < len; j++ ) + { + tmp = sub( len, 1 ); + IF( EQ_16( j, 0 ) ) + { + alpha = 0; + move16(); + } + ELSE + alpha = idiv1616( j, tmp ); // the increment can be updated by simple delta //q15 + tmp2 = mult( EVS_PI_FX, alpha ); // q13 + tmp3 = getCosWord16( tmp2 ); // q14 + alpha = shr( sub( ONE_IN_Q14, tmp3 ), 1 ); // q15 + alpha = sub( MAX_16, alpha ); + quat_nlerp_preproc_fx( prev_ql, ql, alpha, &ql_interp[j * IVAS_PCA_INTERP] ); + quat_nlerp_preproc_fx( prev_qr, qr, alpha, &qr_interp[j * IVAS_PCA_INTERP] ); } - ELSE - alpha = idiv1616(j, tmp); // the increment can be updated by simple delta //q15 - tmp2 = mult(EVS_PI_FX, alpha); // q13 - tmp3 = getCosWord16(tmp2); // q14 - alpha = shr(sub(ONE_IN_Q14, tmp3), 1); // q15 - alpha = sub(MAX_16, alpha); - quat_nlerp_preproc_fx(prev_ql, ql, alpha, &ql_interp[j * IVAS_PCA_INTERP]); - quat_nlerp_preproc_fx(prev_qr, qr, alpha, &qr_interp[j * IVAS_PCA_INTERP]); - } - - return; + + return; } #endif @@ -951,7 +962,7 @@ static void sp2cart_fx( q[3] = mult( getSinWord16( ph3 ), s1s2 ); // q15 q[2] = mult( getCosWord16( ph3 ), s1s2 ); // q15 q[1] = mult( getCosWord16( ph2 ), s1 ); // q15 - q[0] = shl_sat(getCosWord16( ph1 ), 1); //q15 + q[0] = shl_sat( getCosWord16( ph1 ), 1 ); // q15 return; } @@ -977,7 +988,7 @@ static Word16 calc_n2_fx( Word16 n2; Word32 temp = L_mult( 23040, getSinWord16( ph1 ) ); // q8 n2 = round_fx( temp ); - n2 = shr(n2, 7); + n2 = shr( n2, 7 ); IF( EQ_16( s_and( n2, 1 ), 0 ) ) { n2 = add( n2, 1 ); @@ -1015,10 +1026,10 @@ static Word16 calc_n3_fx( const Word16 ph2 ) { Word16 n3; - Word16 temp1 = mult( getSinWord16( ph2 ), getSinWord16( ph1 ) ); // q7 + q15 - q15 - n3 = round_fx( L_mult( temp1, getSinWord16( ph2 ) ) ); // q7 + q15 - q15 + Word16 temp1 = mult( getSinWord16( ph2 ), getSinWord16( ph1 ) ); // q7 + q15 - q15 + n3 = round_fx( L_mult( temp1, getSinWord16( ph2 ) ) ); // q7 + q15 - q15 - n3 = shr(n3, 8); + n3 = shr( n3, 8 ); IF( EQ_16( n3, 0 ) ) { @@ -1197,7 +1208,7 @@ static Word16 get_pca_offset_n2_fx( const Word16 index1 ) { Word16 index2; - IF( LE_16(index1, IVAS_PCA_N1_EQ )) + IF( LE_16( index1, IVAS_PCA_N1_EQ ) ) { index2 = ivas_pca_offset_n2[index1]; move16(); @@ -1439,12 +1450,12 @@ void pca_dec_s3_fx( move16(); Word16 num_fx = 12868; - d_fx = idiv1616( num_fx, n1 ); // Q12 + d_fx = idiv1616( num_fx, n1 ); // Q12 ph1_q_fx = i_mult( index1, d_fx ); // Q12 n2 = calc_n2_fx( ph1_q_fx ); - j = L_sub(j , ivas_pca_offset_index1[index1]); + j = L_sub( j, ivas_pca_offset_index1[index1] ); index2 = -1; move16(); FOR( i = 0; i < n2; i++ ) @@ -1459,7 +1470,7 @@ void pca_dec_s3_fx( assert( index2 > -1 ); - IF( EQ_16(n2, 1) ) + IF( EQ_16( n2, 1 ) ) { ph2_q_fx = 0; move16(); @@ -1469,17 +1480,17 @@ void pca_dec_s3_fx( num_fx = 12868; move16(); - d_fx = idiv1616( num_fx, sub(n2, 1) ); // Q12 - ph2_q_fx = i_mult( index2, d_fx ); // Q12 + d_fx = idiv1616( num_fx, sub( n2, 1 ) ); // Q12 + ph2_q_fx = i_mult( index2, d_fx ); // Q12 } - j = L_sub(j, ivas_pca_offset_index2[index2 + get_pca_offset_n2_fx( index1 )]); + j = L_sub( j, ivas_pca_offset_index2[index2 + get_pca_offset_n2_fx( index1 )] ); index3 = (Word16) j; move16(); n3 = calc_n3_fx( ph1_q_fx, ph2_q_fx ); - IF( EQ_16(n3, 1 )) + IF( EQ_16( n3, 1 ) ) { ph3_q_fx = 0; move16(); @@ -1488,13 +1499,13 @@ void pca_dec_s3_fx( { num_fx = 6434; move16(); - d_fx = idiv1616( num_fx, n3 ); // Q10 - ph3_q_fx = round_fx(L_mult( index3, d_fx )); // Q10 - //ph3_q_fx = shl(ph3_q_fx, 2); + d_fx = idiv1616( num_fx, n3 ); // Q10 + ph3_q_fx = round_fx( L_mult( index3, d_fx ) ); // Q10 + // ph3_q_fx = shl(ph3_q_fx, 2); } sp2cart_fx( ph1_q_fx, ph2_q_fx, ph3_q_fx, q_fx ); return; } -#endif \ No newline at end of file +#endif diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 77ac23f55..61a49b5d1 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -46,11 +46,11 @@ #include "ivas_error_utils.h" ivas_error ivas_masa_dec_open_fx( - Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ + Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ ); void ivas_masa_dec_close_fx( - MASA_DECODER_HANDLE *hMasa /* i/o: MASA metadata structure */ + MASA_DECODER_HANDLE *hMasa /* i/o: MASA metadata structure */ ); void generate_gridEq_fx( @@ -58,29 +58,29 @@ void generate_gridEq_fx( ); void masa_sample_rate_band_correction_fx( - MASA_CODEC_CONFIG *config, /* i/o: MASA codec config */ - Word16 *band_mapping, /* i/o: Band mapping used and modified */ - IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: QMetadata structure for modification */ - const UWord8 maxBand, /* i : max band */ - UWord8 is_encoder, /* i : signals if called at encoder */ - MASA_DECODER_EXT_OUT_META_HANDLE hExtOutMeta /* i/o: MASA decoder metadata ext out buffer */ + MASA_CODEC_CONFIG *config, /* i/o: MASA codec config */ + Word16 *band_mapping, /* i/o: Band mapping used and modified */ + IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: QMetadata structure for modification */ + const UWord8 maxBand, /* i : max band */ + UWord8 is_encoder, /* i : signals if called at encoder */ + MASA_DECODER_EXT_OUT_META_HANDLE hExtOutMeta /* i/o: MASA decoder metadata ext out buffer */ ); void ivas_masa_set_elements_fx( - const Word32 ivas_total_brate, /* i : codec total bitrate */ - const Word16 mc_mode, /* i : MC format mode */ - const Word16 nchan_transport, /* i : number of MASA input/transport channels */ - IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ - Word16 *element_mode, /* o : element mode */ - Word16 *nSCE, /* o : number of SCEs */ - Word16 *nCPE, /* o : number of CPEs */ - const Word16 ivas_format, /* i : IVAS format */ - const ISM_MODE ism_mode, /* i : ISM mode */ - const Word32 ism_total_brate /* i : initial ISM total bitrate */ + const Word32 ivas_total_brate, /* i : codec total bitrate */ + const Word16 mc_mode, /* i : MC format mode */ + const Word16 nchan_transport, /* i : number of MASA input/transport channels */ + IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ + Word16 *element_mode, /* o : element mode */ + Word16 *nSCE, /* o : number of SCEs */ + Word16 *nCPE, /* o : number of CPEs */ + const Word16 ivas_format, /* i : IVAS format */ + const ISM_MODE ism_mode, /* i : ISM mode */ + const Word32 ism_total_brate /* i : initial ISM total bitrate */ ); void ivas_masa_set_coding_config_fx( - MASA_CODEC_CONFIG *config, /* i/o: MASA coding config structure */ + MASA_CODEC_CONFIG *config, /* i/o: MASA coding config structure */ Word16 *band_mapping, /* o : Band mapping used */ const Word32 ivas_total_brate, /* i : IVAS total bitrate */ const Word16 nchan_transport, /* i : number of transport channels (mono/stereo) */ @@ -88,11 +88,11 @@ void ivas_masa_set_coding_config_fx( ); void ivas_masa_prerender_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - Word32 *output_fx[], /* i/o: synthesized core-coder transport channels */ - Word16 *q_shift, /* o : specifies how much the Q-factor of output has changed by. */ - const Word16 output_frame, /* i : output frame length per channel */ - const Word16 nchan_remapped /* i : number of transports used in core */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + Word32 *output_fx[], /* i/o: synthesized core-coder transport channels */ + Word16 *q_shift, /* o : specifies how much the Q-factor of output has changed by. */ + const Word16 output_frame, /* i : output frame length per channel */ + const Word16 nchan_remapped /* i : number of transports used in core */ ); ivas_error ivas_masa_dec_reconfigure_fx( @@ -127,15 +127,15 @@ UWord16 index_theta_phi_16_fx( ); ivas_error ivas_masa_decode_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder struct */ - Decoder_State *st, /* i/o: decoder state structure */ - Word16 *nb_bits_read /* o : number of bits read */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder struct */ + Decoder_State *st, /* i/o: decoder state structure */ + Word16 *nb_bits_read /* o : number of bits read */ ); void ivas_omasa_rearrange_channels_fx( - Word32 *output[], /* o : output synthesis signal */ - const Word16 nchan_transport_ism, /* o : number of ISM TCs */ - const Word16 output_frame /* i : output frame length per channel */ + Word32 *output[], /* o : output synthesis signal */ + const Word16 nchan_transport_ism, /* o : number of ISM TCs */ + const Word16 output_frame /* i : output frame length per channel */ ); #ifdef IVAS_FLOAT_FIXED @@ -152,19 +152,19 @@ ivas_error ivas_omasa_dec_config_fx( UWord16 *nSamplesRendered, /* o : number of samples flushed from the previous frame (JBM) */ Word16 *num_src, Word16 SrcInd[MAX_NUM_TDREND_CHANNELS], - Word16 *data /* o : output synthesis signal */ + Word16 *data /* o : output synthesis signal */ ); ivas_error ivas_td_binaural_renderer_sf_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - Word32 *output_fx[], /* i/o: SCE channels / Binaural synthesis */ - const Word16 q_factor, /* i : Q-factor of input/output */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Word32 *output_fx[], /* i/o: SCE channels / Binaural synthesis */ + const Word16 q_factor, /* i : Q-factor of input/output */ const Word16 n_samples_granularity /* i : granularity of the renderer/buffer */ ); #endif void ivas_omasa_modify_masa_energy_ratios_fx( - IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ - Word32 masa_to_total_energy_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_MAXIMUM_CODING_SUBBANDS] // Q30 + IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ + Word32 masa_to_total_energy_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_MAXIMUM_CODING_SUBBANDS] // Q30 ); Word32 calculate_cpe_brate_MASA_ISM_fx( @@ -174,12 +174,12 @@ Word32 calculate_cpe_brate_MASA_ISM_fx( ); Word16 ivas_jbm_dec_get_num_tc_channels_fx( - Decoder_Struct *st_ivas /* i : IVAS decoder handle */ + Decoder_Struct *st_ivas /* i : IVAS decoder handle */ ); ivas_error ivas_jbm_dec_tc_buffer_open_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const TC_BUFFER_MODE tc_buffer_mode, /* i : buffer mode */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const TC_BUFFER_MODE tc_buffer_mode, /* i : buffer mode */ const Word16 nchan_transport_jbm, /* i : number of real transport channels */ const Word16 nchan_transport_internal, /* i : number of totally buffered channels */ const Word16 nchan_full, /* i : number of channels to fully store */ @@ -301,7 +301,7 @@ void sns_compute_scf_fx( const PsychoacousticParameters *pPsychParams, const Word16 L_frame, Word32 *scf, - Word16 q); + Word16 q ); void sns_interpolate_scalefactors_fx( Word32 *scf_int, /* o : interpolated scalefactors for spectrum shaping */ @@ -409,14 +409,14 @@ void init_tcx_info_fx( ); void decoder_tcx_IGF_mono_fx( - Decoder_State *st, /* i/o: coder memory state */ - Word32 x_fx[], /* o : de-quatized coefficients */ - Word16 *x_e, /* o : de-quatized coefficients exponent */ - Word16 *x_len, /* o : de-quatized coefficients length */ - const Word16 L_frame, /* i : frame length */ - const Word16 left_rect, /* i : left part is rectangular */ - const Word16 bfi, /* i : bad frame indicator */ - const Word16 frame_cnt /* i : frame counter in the super_frame */ + Decoder_State *st, /* i/o: coder memory state */ + Word32 x_fx[], /* o : de-quatized coefficients */ + Word16 *x_e, /* o : de-quatized coefficients exponent */ + Word16 *x_len, /* o : de-quatized coefficients length */ + const Word16 L_frame, /* i : frame length */ + const Word16 left_rect, /* i : left part is rectangular */ + const Word16 bfi, /* i : bad frame indicator */ + const Word16 frame_cnt /* i : frame counter in the super_frame */ ); void decoder_tcx_IGF_stereo_fx( @@ -450,53 +450,53 @@ void stereo_dft_dec_reset_fx( void stereo_dft_dec_update_fx( STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ - const Word16 output_frame, /* i : output frame length */ - const Word16 sba_dirac_stereo_flag /* i : signal stereo output for SBA DirAC */ + const Word16 output_frame, /* i : output frame length */ + const Word16 sba_dirac_stereo_flag /* i : signal stereo output for SBA DirAC */ ); void stereo_dft_res_ecu_fx( STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: Decoder DFT stereo handle */ - Word32 *pDFT_RES, /* i/o: residual signal */ - Word32 *const DFT_PRED_RES, /* i/o: residual prediction signal */ - const Word16 k, /* i : Subframe index */ - const Word16 output_frame, /* i : Output frame length */ - const Word16 prev_bfi, /* i : Previous BFI */ - const Word32 dmx_nrg, /* i : Down-mix energy */ - Word16 *num_plocs, /* i/o: Number of peak locations */ - Word16 *plocs, /* i/o: Peak locations (bin) */ - Word32 *plocsi, /* i/o: Peak locations (fractional) */ - Word32 *input_mem /* o : Residual DFT buffer input mem */ + Word32 *pDFT_RES, /* i/o: residual signal */ + Word32 *const DFT_PRED_RES, /* i/o: residual prediction signal */ + const Word16 k, /* i : Subframe index */ + const Word16 output_frame, /* i : Output frame length */ + const Word16 prev_bfi, /* i : Previous BFI */ + const Word32 dmx_nrg, /* i : Down-mix energy */ + Word16 *num_plocs, /* i/o: Number of peak locations */ + Word16 *plocs, /* i/o: Peak locations (bin) */ + Word32 *plocsi, /* i/o: Peak locations (fractional) */ + Word32 *input_mem /* o : Residual DFT buffer input mem */ ); void stereo_dft_res_subst_spec_fx( STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: Decoder DFT stereo handle */ - Word32 *pDFT_RES, /* i/o: residual signal */ - const Word32 *const DFT_PRED_RES, /* i : residual prediction signal */ - const Word16 time_offs, /* i : Time offset for phase adjustment*/ - const Word16 L_res, /* i : bandwidth of residual signal */ - const Word16 L_ana, /* i : Length of FFT analysis */ - const Word16 k, /* i : Subframe index */ - Word16 *num_plocs, /* i/o: Number of peak locations */ - Word16 *plocs, /* i/o: Peak locations (bin) */ - Word32 *plocsi, /* i/o: Peak locations (fractional) */ - const Word16 analysis_flag /* i : Flag for running peak analysis */ + Word32 *pDFT_RES, /* i/o: residual signal */ + const Word32 *const DFT_PRED_RES, /* i : residual prediction signal */ + const Word16 time_offs, /* i : Time offset for phase adjustment*/ + const Word16 L_res, /* i : bandwidth of residual signal */ + const Word16 L_ana, /* i : Length of FFT analysis */ + const Word16 k, /* i : Subframe index */ + Word16 *num_plocs, /* i/o: Number of peak locations */ + Word16 *plocs, /* i/o: Peak locations (bin) */ + Word32 *plocsi, /* i/o: Peak locations (fractional) */ + const Word16 analysis_flag /* i : Flag for running peak analysis */ ); void stereo_dft_res_ecu_burst_att_fx( STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: Decoder DFT stereo handle */ - Word32 *pDFT_RES, /* i/o: residual signal /att. residual */ - const Word32 dmx_nrg, /* i : dmx energy of current frame */ - const Word16 L_res, /* i : Bandwidth of residual */ - const Word16 L_ana /* i : Length of FFT analysis */ + Word32 *pDFT_RES, /* i/o: residual signal /att. residual */ + const Word32 dmx_nrg, /* i : dmx energy of current frame */ + const Word16 L_res, /* i : Bandwidth of residual */ + const Word16 L_ana /* i : Length of FFT analysis */ ); void stereo_dft_generate_res_pred_fx( - STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ - const Word16 samp_ratio, /* i : sampling ratio */ - Word32 *pDFT_DMX, /* i : downmix signal */ - Word32 *DFT_PRED_RES, /* o : residual prediction signal */ - Word32 *pPredGain, /* i : residual prediction gains */ - const Word16 k, /* i : subframe index */ - Word32 *ap_filt_DMX, /* i : enhanced stereo filling signal */ - Word16 *stop, /* o : last FD stereo filling bin */ - const Word16 bfi /* i : BFI flag */ + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ + const Word16 samp_ratio, /* i : sampling ratio */ + Word32 *pDFT_DMX, /* i : downmix signal */ + Word32 *DFT_PRED_RES, /* o : residual prediction signal */ + Word32 *pPredGain, /* i : residual prediction gains */ + const Word16 k, /* i : subframe index */ + Word32 *ap_filt_DMX, /* i : enhanced stereo filling signal */ + Word16 *stop, /* o : last FD stereo filling bin */ + const Word16 bfi /* i : BFI flag */ ); #endif @@ -520,20 +520,18 @@ void init_basic_allpass_fx( const Word16 *delays ); void filter_with_allpass_fx( - const Word32 *sig, /* i : allpass input signal */ - Word32 *out, /* o : filtered output */ - const Word16 len, /* i : length of input */ + const Word32 *sig, /* i : allpass input signal */ + Word32 *out, /* o : filtered output */ + const Word16 len, /* i : length of input */ basic_allpass_t *ap, /* i/o: basic allpass structure */ - Word16 q_shift -); + Word16 q_shift ); Word32 stereo_dft_dmx_swb_nrg_fx( - const Word32 *dmx_k0, /* i : first subframe spectrum */ - const Word32 *dmx_k1, /* i : second subframe spectrum */ + const Word32 *dmx_k0, /* i : first subframe spectrum */ + const Word32 *dmx_k1, /* i : second subframe spectrum */ const Word16 frame_length, /* i : frame lanegth */ const Word16 q0, - const Word16 q1 -); + const Word16 q1 ); void stereo_dft_dec_core_switching_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ @@ -582,33 +580,33 @@ Word16 ivas_get_sba_num_TCs_fx( ); Word16 ivas_sba_get_nchan_fx( - const Word16 sba_order, /* i : Ambisonic (SBA) order */ - const Word16 sba_planar /* i : SBA planar flag */ + const Word16 sba_order, /* i : Ambisonic (SBA) order */ + const Word16 sba_planar /* i : SBA planar flag */ ); void ivas_dirac_dec_set_md_map_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const Word16 nCldfbTs /* i : number of CLDFB time slots */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const Word16 nCldfbTs /* i : number of CLDFB time slots */ ); void ivas_jbm_dec_get_adapted_subframes_fx( - const Word16 nCldfbTs, /* i : number of time slots in the current frame */ - Word16 *subframe_nbslots, /* i/o: subframe grid */ - Word16 *nb_subframes /* i/o: number of subframes in the frame */ + const Word16 nCldfbTs, /* i : number of time slots in the current frame */ + Word16 *subframe_nbslots, /* i/o: subframe grid */ + Word16 *nb_subframes /* i/o: number of subframes in the frame */ ); void ivas_jbm_dec_copy_tc_no_tsm_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle Q0 */ - Word32 *tc_fx[], /* i : transport channels Q11 */ - const Word16 output_frame /* i : output frame size Q0 */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle Q0 */ + Word32 *tc_fx[], /* i : transport channels Q11 */ + const Word16 output_frame /* i : output frame size Q0 */ ); void ivas_ism_param_dec_tc_gain_ajust_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - const UWord16 nSamples, /* i : number of samples to be compensate */ - const UWord16 nFadeLength, /* i : length of the crossfade in samples */ - Word32 *transport_channels_f[], /* i : synthesized core-coder transport channels/DirAC output Q_tc*/ - Word16 *Q_tc /* i/o : Q of input tc buffer */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const UWord16 nSamples, /* i : number of samples to be compensate */ + const UWord16 nFadeLength, /* i : length of the crossfade in samples */ + Word32 *transport_channels_f[], /* i : synthesized core-coder transport channels/DirAC output Q_tc*/ + Word16 *Q_tc /* i/o : Q of input tc buffer */ ); #ifdef IVAS_FLOAT_FIXED @@ -686,65 +684,64 @@ Word16 masa_sq_fx( ); void ivas_compute_spar_params_fx( - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - Word16 q_cov_real, - Word32 dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], - Word16 *q_dm_fv_re, - const Word16 i_ts, - Word32 ***mixer_mat_fx, - Word16 *q_mixer_mat, - const Word16 start_band, - const Word16 end_band, - const Word16 dtx_vad, - const Word16 num_ch, - const Word16 bands_bw, - const Word16 active_w, - const Word16 active_w_vlbr, - ivas_spar_md_com_cfg *hSparCfg, - ivas_spar_md_t *hSparMd, - Word32 *pWscale_fx, - Word16 *q_pWscale, - const Word16 from_dirac, - const Word16 dyn_active_w_flag -); + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 q_cov_real, + Word32 dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word16 *q_dm_fv_re, + const Word16 i_ts, + Word32 ***mixer_mat_fx, + Word16 *q_mixer_mat, + const Word16 start_band, + const Word16 end_band, + const Word16 dtx_vad, + const Word16 num_ch, + const Word16 bands_bw, + const Word16 active_w, + const Word16 active_w_vlbr, + ivas_spar_md_com_cfg *hSparCfg, + ivas_spar_md_t *hSparMd, + Word32 *pWscale_fx, + Word16 *q_pWscale, + const Word16 from_dirac, + const Word16 dyn_active_w_flag ); ivas_error ivas_ism_metadata_dec_fx( - const Word32 ism_total_brate, /* i : ISM total bitrate */ - const Word16 nchan_ism, /* i : number of ISM channels */ - Word16 *nchan_transport, /* o : number of transport channels */ + const Word32 ism_total_brate, /* i : ISM total bitrate */ + const Word16 nchan_ism, /* i : number of ISM channels */ + Word16 *nchan_transport, /* o : number of transport channels */ ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ SCE_DEC_HANDLE hSCE[], /* i/o: SCE decoder handles */ - const Word16 bfi, /* i : bfi flag */ - Word16 nb_bits_metadata[], /* o : number of metadata bits */ + const Word16 bfi, /* i : bfi flag */ + Word16 nb_bits_metadata[], /* o : number of metadata bits */ ISM_MODE ism_mode, /* i : ISM mode */ ISM_DTX_DATA_DEC hISMDTX, /* i/o: ISM DTX structure */ const PARAM_ISM_CONFIG_HANDLE hParamIsm, /* i : Param ISM Config Handle */ - Word16 *ism_extmeta_active, /* i/o: Extended metadata active in renderer */ - Word16 *ism_extmeta_cnt, /* i/o: Number of change frames observed */ + Word16 *ism_extmeta_active, /* i/o: Extended metadata active in renderer */ + Word16 *ism_extmeta_cnt, /* i/o: Number of change frames observed */ DEC_CORE_HANDLE st0 /* i : core-coder handle */ ); void ivas_get_ism_sid_quan_bitbudget_fx( - const Word16 nchan_ism, /* i : number of objects */ - Word16 *nBits_azimuth, /* o : number of Q bits for azimuth */ - Word16 *nBits_elevation, /* o : number of Q bits for elevation */ - Word32 *q_step_fx, /* o : quantization step */ - Word32 *q_step_border_fx, /* o : quantization step at the border */ - Word16 *nBits_coh, /* o : number of Q bits for coherence */ - Word16 *nBits_sce_id /* o : number of Q bits for sce_id_dtx */ + const Word16 nchan_ism, /* i : number of objects */ + Word16 *nBits_azimuth, /* o : number of Q bits for azimuth */ + Word16 *nBits_elevation, /* o : number of Q bits for elevation */ + Word32 *q_step_fx, /* o : quantization step */ + Word32 *q_step_border_fx, /* o : quantization step at the border */ + Word16 *nBits_coh, /* o : number of Q bits for coherence */ + Word16 *nBits_sce_id /* o : number of Q bits for sce_id_dtx */ ); void ivas_ism_metadata_sid_dec_fx( SCE_DEC_HANDLE hSCE[MAX_SCE], /* i/o: SCE decoder structure */ - const Word32 ism_total_brate, /* i : ISM total bitrate */ - const Word16 bfi, /* i : bfi flag */ - const Word16 nchan_ism, /* i : number of objects */ - const Word16 nchan_transport, /* i : number of transport channels*/ + const Word32 ism_total_brate, /* i : ISM total bitrate */ + const Word16 bfi, /* i : bfi flag */ + const Word16 nchan_ism, /* i : number of objects */ + const Word16 nchan_transport, /* i : number of transport channels*/ const ISM_MODE ism_mode, /* i : ISM mode */ - Word16 *flag_noisy_speech, /* o : noisy speech flag */ - Word16 *sce_id_dtx, /* o : SCE DTX ID */ + Word16 *flag_noisy_speech, /* o : noisy speech flag */ + Word16 *sce_id_dtx, /* o : SCE DTX ID */ ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ - Word16 nb_bits_metadata[] /* o : number of metadata bits */ + Word16 nb_bits_metadata[] /* o : number of metadata bits */ ); #ifdef IVAS_FLOAT_FIXED @@ -798,35 +795,35 @@ void ivas_post_proc_fx( ); #endif -//ivas_lfe_dec_fx.c +// ivas_lfe_dec_fx.c void ivas_lfe_dec_close_fx( LFE_DEC_HANDLE *hLFE /* i/o: LFE encoder handle */ ); ivas_error ivas_create_lfe_dec_fx( - LFE_DEC_HANDLE *hLFE_out, /* o : IVAS LFE decoder structure */ - const Word32 output_Fs, /* i : output sampling rate */ - const Word32 binauralization_delay_ns /* i : additional LFE delay to sync with binaural renderer */ + LFE_DEC_HANDLE *hLFE_out, /* o : IVAS LFE decoder structure */ + const Word32 output_Fs, /* i : output sampling rate */ + const Word32 binauralization_delay_ns /* i : additional LFE delay to sync with binaural renderer */ ); void ivas_lfe_dec_fx( - LFE_DEC_HANDLE hLFE, /* i/o: LFE decoder handle */ - Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling*/ - const Word16 output_frame, /* i : output frame length per channel */ - const Word16 bfi, /* i : BFI flag */ - Word32 output_lfe_ch[] /* o : output LFE synthesis */ + LFE_DEC_HANDLE hLFE, /* i/o: LFE decoder handle */ + Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling*/ + const Word16 output_frame, /* i : output frame length per channel */ + const Word16 bfi, /* i : BFI flag */ + Word32 output_lfe_ch[] /* o : output LFE synthesis */ ); void ivas_lfe_tdplc_fx( - LFE_DEC_HANDLE hLFE, /* i/o: LFE decoder handle */ - const Word32 *prevsynth, /* i : previous frame synthesis */ - Word32 *ytda, /* o : output time-domain buffer */ - const Word16 output_frame /* i : output frame length */ + LFE_DEC_HANDLE hLFE, /* i/o: LFE decoder handle */ + const Word32 *prevsynth, /* i : previous frame synthesis */ + Word32 *ytda, /* o : output time-domain buffer */ + const Word16 output_frame /* i : output frame length */ ); void ivas_lfe_dec_close_fx( - LFE_DEC_HANDLE *hLFE /* i/o: LFE decoder handle */ + LFE_DEC_HANDLE *hLFE /* i/o: LFE decoder handle */ ); @@ -881,42 +878,42 @@ void ivas_mcmasa_split_brate_fx( ); void update_last_metadata_fx( - const Word16 nchan_ism, /* i : number of objects */ + const Word16 nchan_ism, /* i : number of objects */ ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ - const Word16 updt_flag[] /* i : last metadata update flag */ + const Word16 updt_flag[] /* i : last metadata update flag */ ); ivas_error ivas_jbm_dec_tc_buffer_reconfigure_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const TC_BUFFER_MODE tc_buffer_mode, /* i : new buffer mode */ - const Word16 nchan_transport_jbm, /* i : new number of real transport channels */ - const Word16 nchan_transport_internal, /* i : new number of totally buffered channels */ - const Word16 nchan_full, /* i : new number of channels to fully store */ - const Word16 n_samples_granularity /* i : new granularity of the renderer/buffer */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const TC_BUFFER_MODE tc_buffer_mode, /* i : new buffer mode */ + const Word16 nchan_transport_jbm, /* i : new number of real transport channels */ + const Word16 nchan_transport_internal, /* i : new number of totally buffered channels */ + const Word16 nchan_full, /* i : new number of channels to fully store */ + const Word16 n_samples_granularity /* i : new granularity of the renderer/buffer */ ); ivas_error ivas_dirac_allocate_parameters_fx( SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common data for spatial parametric rendering */ - const Word16 params_flag /* i : set of parameters flag */ + const Word16 params_flag /* i : set of parameters flag */ ); Word16 configure_reqularization_factor_fx( const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const Word32 ivas_total_brate /* i : IVAS total bitrate */ + const Word32 ivas_total_brate /* i : IVAS total bitrate */ ); ivas_error ivas_ism_config_fx( - const Word32 ism_total_brate, /* i : ISM total bitrate */ - const Word16 nchan_transport, /* i : number of transport channels */ - const Word16 nchan_ism, /* i : number of objects */ - ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ - const Word16 ism_extended_metadata_flag, /* i : extended metadata flag */ - const Word16 null_metadata_flag[MAX_NUM_OBJECTS], /* i : NULL MD flag */ - const Word16 ism_imp[], /* i : ISM importance flags */ - Word32 element_brate[], /* o : element bitrate per object */ - Word32 total_brate[], /* o : total bitrate per object */ - Word16 nb_bits_metadata[], /* i/o: number of metadata bits */ - const Word16 combined_format_flag /* i : flag indicating combined format */ + const Word32 ism_total_brate, /* i : ISM total bitrate */ + const Word16 nchan_transport, /* i : number of transport channels */ + const Word16 nchan_ism, /* i : number of objects */ + ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ + const Word16 ism_extended_metadata_flag, /* i : extended metadata flag */ + const Word16 null_metadata_flag[MAX_NUM_OBJECTS], /* i : NULL MD flag */ + const Word16 ism_imp[], /* i : ISM importance flags */ + Word32 element_brate[], /* o : element bitrate per object */ + Word32 total_brate[], /* o : total bitrate per object */ + Word16 nb_bits_metadata[], /* i/o: number of metadata bits */ + const Word16 combined_format_flag /* i : flag indicating combined format */ ); Word16 IGF_MapBitRateToIndex( @@ -930,7 +927,7 @@ Word16 ivas_jbm_dec_get_render_granularity( const RENDERER_TYPE rendererType, /* i : renderer type */ const IVAS_FORMAT ivas_format, /* i : ivas format */ const MC_MODE mc_mode, /* i : MC mode */ - const Word32 output_Fs /* i : sampling rate */ + const Word32 output_Fs /* i : sampling rate */ ); // ivas_stereo_dft_com.c @@ -963,40 +960,39 @@ ivas_error ivas_ls_custom_open_fx( ); ivas_error ivas_ism_renderer_open_fx( - Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); void ivas_ism_render_sf_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - Word32 *output_fx[], /* i/o: core-coder transport channels/object output */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Word32 *output_fx[], /* i/o: core-coder transport channels/object output */ const Word16 n_samples_to_render /* i : output frame length per channel */ ); void ivas_jbm_dec_get_adapted_linear_interpolator_fx( const Word16 default_interp_length, /* i : default length of the (full-frame) interpolator */ const Word16 interp_length, /* i : length of the interpolator to be created */ - Word16 *interpolator_fx /* o : the interpolator */ + Word16 *interpolator_fx /* o : the interpolator */ ); void ivas_omasa_separate_object_render_jbm_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const UWord16 nSamplesRendered, /* i : number of samples rendered */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const UWord16 nSamplesRendered, /* i : number of samples rendered */ Word32 input_fx_in[][L_FRAME48k], /* i : separated object signal */ - Word32 *output_fx[], /* o : rendered time signal */ - const Word16 subframes_rendered, /* i : number of subframes rendered */ - const Word16 slots_rendered /* i : number of CLDFB slots rendered */ + Word32 *output_fx[], /* o : rendered time signal */ + const Word16 subframes_rendered, /* i : number of subframes rendered */ + const Word16 slots_rendered /* i : number of CLDFB slots rendered */ ); void get_panning_gain( const Word16 sinAngleMapped, - Word16 *panningGains -); + Word16 *panningGains ); void ivas_ism_get_stereo_gains_fx( - const Word16 aziDeg, /* i : object azimuth */ - const Word16 eleDeg, /* i : object elevation */ - Word16 *left_gain_fx, /* o : left channel gain */ - Word16 *right_gain_fx /* o : right channel gain */ + const Word16 aziDeg, /* i : object azimuth */ + const Word16 eleDeg, /* i : object elevation */ + Word16 *left_gain_fx, /* o : left channel gain */ + Word16 *right_gain_fx /* o : right channel gain */ ); // ivas_mct_dec_mct_fx.c @@ -1049,10 +1045,10 @@ void stereo_decoder_tcx_fx( Word16 *q_x_ch1 ); void v_multc_acc_32_16( - const Word32 x[], /* i : Input vector */ - const Word16 c, /* i : Constant */ - Word32 y[], /* o : Output vector that contains y + c*x */ - const Word16 N /* i : Vector length */ + const Word32 x[], /* i : Input vector */ + const Word16 c, /* i : Constant */ + Word32 y[], /* o : Output vector that contains y + c*x */ + const Word16 N /* i : Vector length */ ); void v_multc_acc_32_32( const Word32 x[], /* i : Input vector */ @@ -1062,65 +1058,65 @@ void v_multc_acc_32_32( ); void ivas_mono_stereo_downmix_mcmasa_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - Word32 *output_f_fx[], /* i/o: synthesized core-coder transport channels/mono or stereo output */ - Word16 output_frame /* i : output frame length per channel */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Word32 *output_f_fx[], /* i/o: synthesized core-coder transport channels/mono or stereo output */ + Word16 output_frame /* i : output frame length per channel */ ); void ivas_apply_non_diegetic_panning_fx( - Word32 *output_f_fx[], /* i/o: core-coder transport mono channel/stereo output */ - const Word16 non_diegetic_pan_gain_fx, /* i : non-diegetic panning gain */ - const Word16 output_frame /* i : output frame length per channel */ + Word32 *output_f_fx[], /* i/o: core-coder transport mono channel/stereo output */ + const Word16 non_diegetic_pan_gain_fx, /* i : non-diegetic panning gain */ + const Word16 output_frame /* i : output frame length per channel */ ); void ivas_mono_downmix_render_passive_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - Word32 *output_f_fx[], /* i/o: synthesized core-coder transport channels/mono output */ - const Word16 output_frame /* i : output frame length */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Word32 *output_f_fx[], /* i/o: synthesized core-coder transport channels/mono output */ + const Word16 output_frame /* i : output frame length */ ); void ivas_sba_dirac_stereo_smooth_parameters_fx( STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD handle for upmixing */ - const Word16 cross_fade_start_offset, /* i : SPAR mixer delay compensation */ - const Word32 output_Fs, /* i : Fs for delay calculation */ - const Word16 num_md_sub_frames /* i : number of subframes in mixing matrix */ + const Word16 cross_fade_start_offset, /* i : SPAR mixer delay compensation */ + const Word32 output_Fs, /* i : Fs for delay calculation */ + const Word16 num_md_sub_frames /* i : number of subframes in mixing matrix */ ); void stereo_dft_dec_synthesize_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i : DFT buffers */ - const Word16 chan, /* i : channel number */ - Word32 output[L_FRAME48k], /* o : output synthesis signal */ - const Word16 output_frame /* i : output frame length */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i : DFT buffers */ + const Word16 chan, /* i : channel number */ + Word32 output[L_FRAME48k], /* o : output synthesis signal */ + const Word16 output_frame /* i : output frame length */ ); void stereo_dft_dec_smooth_parameters_fx( - STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ - const Word16 prev_sid_nodata, /* i : Previous SID/No data indicator */ - const Word16 active_frame_counter, /* i : Active frame counter */ - const Word32 element_brate /* i : Element bitrate */ + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ + const Word16 prev_sid_nodata, /* i : Previous SID/No data indicator */ + const Word16 active_frame_counter, /* i : Active frame counter */ + const Word32 element_brate /* i : Element bitrate */ ); void stereo_dft_dec_res_fx( - CPE_DEC_HANDLE hCPE, /* i/o: decoder CPE handle */ + CPE_DEC_HANDLE hCPE, /* i/o: decoder CPE handle */ Word32 res_buf[STEREO_DFT_N_8k], /* i : residual buffer */ - Word16 q_res, /* i : q fact of residural buffer */ + Word16 q_res, /* i : q fact of residural buffer */ Word32 *output /* o : output */ ); void stereo_dft_dec_fx( - STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ - Decoder_State *st0, /* i/o: decoder state structure */ + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ + Decoder_State *st0, /* i/o: decoder state structure */ Word32 DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i/o: DFT buffers */ Word32 *input_mem, /* i/o: mem of buffer DFT analysis */ - STEREO_CNG_DEC_HANDLE hStereoCng, /* i/o: Stereo CNG data structure */ - const Word16 sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC */ - const Word16 sba_mono_flag, /* i : signal mono output for SBA DirAC */ - ivas_spar_md_dec_state_t *hMdDec, /* i : SPAR MD handle for upmixing */ - const Word16 cross_fade_start_offset, /* i : SPAR mixer delay compensation */ - const Word32 output_Fs, /* i : Fs for delay calculation */ - const Word16 nchan_transport, /* i : number of transpor channels */ - const Word16 num_md_sub_frames /* i : number of MD subframes */ + STEREO_CNG_DEC_HANDLE hStereoCng, /* i/o: Stereo CNG data structure */ + const Word16 sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC */ + const Word16 sba_mono_flag, /* i : signal mono output for SBA DirAC */ + ivas_spar_md_dec_state_t *hMdDec, /* i : SPAR MD handle for upmixing */ + const Word16 cross_fade_start_offset, /* i : SPAR mixer delay compensation */ + const Word32 output_Fs, /* i : Fs for delay calculation */ + const Word16 nchan_transport, /* i : number of transpor channels */ + const Word16 num_md_sub_frames /* i : number of MD subframes */ ); @@ -1162,19 +1158,18 @@ void convert_coeffs_to_higher_res_fx( void create_IDCT_N_Matrix_fx( Word32 *inv_matrixFloatQ, /* i/o: RAM buffer */ - const Word16 N, /* i : DCT length, number of time samples */ - const Word16 n_cols, /* i : number of dct coeffs (as DCT may be truncated) */ - const Word16 alloc_size /* i : RAM buffer size in elements */ + const Word16 N, /* i : DCT length, number of time samples */ + const Word16 n_cols, /* i : number of dct coeffs (as DCT may be truncated) */ + const Word16 alloc_size /* i : RAM buffer size in elements */ ); void ivas_dirac_dec_get_frequency_axis_fx( Word16 *frequency_axis, /* Q0 */ const Word32 output_Fs, - const Word16 num_freq_bands -); + const Word16 num_freq_bands ); void ivas_decision_matrix_dec_fx( - Decoder_State *st, /* i/o: decoder state structure */ + Decoder_State *st, /* i/o: decoder state structure */ Word16 *sharpFlag, /* o : formant sharpening flag */ Word16 *core_switching_flag, /* o : ACELP->HQ switching frame flag */ const Word32 element_brate, /* i : element bitrate */ @@ -1231,8 +1226,8 @@ Word16 matrix_product_diag_fx( // ivas_stereo_mdct_core_dec_fx.c void stereo_mdct_core_dec_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ Word32 *signal_out[CPE_CHANNELS], /* o : synthesis @internal_FS */ Word16 signal_outFB[CPE_CHANNELS][L_FRAME48k] /* o : synthesis @output_FS */ ); @@ -1300,33 +1295,33 @@ void IGFDecReadData_ivas_fx( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: ); void stereo_tca_init_dec_fx( - STEREO_TCA_DEC_HANDLE hStereoTCA /* i/o: Stereo TCA handle for Fixed */ + STEREO_TCA_DEC_HANDLE hStereoTCA /* i/o: Stereo TCA handle for Fixed */ ); void stereo_icBWE_init_dec_fx( - STEREO_ICBWE_DEC_HANDLE hStereoICBWE /* i/o: Stereo inter-channel BWE handle */ + STEREO_ICBWE_DEC_HANDLE hStereoICBWE /* i/o: Stereo inter-channel BWE handle */ ); void stereo_icBWE_decproc_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *output[CPE_CHANNELS], /* i/o: output synthesis */ - Word32 outputHB[CPE_CHANNELS][L_FRAME48k], /* i : HB synthesis */ - const Word16 last_core, /* i : last core, primary channel */ - const Word16 last_bwidth, /* i : last bandwidth */ - const Word16 output_frame, /* i : frame length */ - Word16 q_output /* i : Q-fac of output */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 *output[CPE_CHANNELS], /* i/o: output synthesis */ + Word32 outputHB[CPE_CHANNELS][L_FRAME48k], /* i : HB synthesis */ + const Word16 last_core, /* i : last core, primary channel */ + const Word16 last_bwidth, /* i : last bandwidth */ + const Word16 output_frame, /* i : frame length */ + Word16 q_output /* i : Q-fac of output */ ); void add_HB_to_mono_dmx_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 output[L_FRAME48k], /* i/o: output synthesis */ - Word32 outputHB[L_FRAME48k], /* i : HB synthesis */ - const Word16 last_core, /* i : last core, primary channel */ - const Word16 output_frame /* i : frame length */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 output[L_FRAME48k], /* i/o: output synthesis */ + Word32 outputHB[L_FRAME48k], /* i : HB synthesis */ + const Word16 last_core, /* i : last core, primary channel */ + const Word16 output_frame /* i : frame length */ ); void stereo_dft_dmx_out_reset_fx( - STEREO_DFT_DMX_DATA_HANDLE hStereoDftDmx /* i/o: DFT stereo DMX decoder */ + STEREO_DFT_DMX_DATA_HANDLE hStereoDftDmx /* i/o: DFT stereo DMX decoder */ ); void ivas_get_dirac_sba_max_md_bits_fx( @@ -1335,19 +1330,19 @@ void ivas_get_dirac_sba_max_md_bits_fx( Word16 *metadata_max_bits, Word16 *qmetadata_max_bit_req, const Word16 nbands, - IVAS_FORMAT ivas_format); + IVAS_FORMAT ivas_format ); ivas_error ivas_dirac_sba_config_fx( IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ - Word16 *element_mode, /* i/o: element mode of the core coder */ - Word32 sba_total_brate, /* i : SBA total bitrate */ - const Word16 sba_order, /* i : Ambisonic (SBA) order */ - const Word16 nbands /* i : number of frequency bands */ + Word16 *element_mode, /* i/o: element mode of the core coder */ + Word32 sba_total_brate, /* i : SBA total bitrate */ + const Word16 sba_order, /* i : Ambisonic (SBA) order */ + const Word16 nbands /* i : number of frequency bands */ , - IVAS_FORMAT ivas_format); + IVAS_FORMAT ivas_format ); ivas_error ivas_dirac_config_fx( - void *st_ivas, /* i/o: IVAS encoder/decoder state structure */ + void *st_ivas, /* i/o: IVAS encoder/decoder state structure */ const Word16 enc_dec /* i : encoder or decoder flag */ ); @@ -1363,22 +1358,21 @@ void FdCngDecodeDiracMDCTStereoSID_fx( CPE_DEC_HANDLE hCPE /* i/o: CPE decoder state structure */ ); -//tonalMDCTconcealment.c +// tonalMDCTconcealment.c void TonalMdctConceal_whiten_noise_shape_ivas_fx( Decoder_State *st, const Word16 L_frame, const TONALMDCTCONC_NOISE_SHAPE_WHITENING_MODE whitening_mode ); void stereo_icBWE_dec_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *synthRef_fx, /* i/o: Reference channel HB synthesis at output Fs */ - Word32 *synth_fx, /* o : Non reference channel HB synthesis at output Fs */ - const Word16 *fb_synth_ref_fx, /* i : ref. high-band synthesis 16-20 kHz */ - const Word16 *voice_factors_fx, /* i : voicing factors */ - const Word16 output_frame, /* i : frame length */ - Word16 *Q_syn - ); - + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 *synthRef_fx, /* i/o: Reference channel HB synthesis at output Fs */ + Word32 *synth_fx, /* o : Non reference channel HB synthesis at output Fs */ + const Word16 *fb_synth_ref_fx, /* i : ref. high-band synthesis 16-20 kHz */ + const Word16 *voice_factors_fx, /* i : voicing factors */ + const Word16 output_frame, /* i : frame length */ + Word16 *Q_syn ); + void decoder_tcx_tns_fx( Decoder_State *st, /* i/o: coder memory state */ const Word16 L_frame_glob, /* i : frame length */ @@ -1393,17 +1387,16 @@ void decoder_tcx_tns_fx( const Word16 whitenedDomain ); void ivas_mdct_core_tns_ns_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word16 fUseTns[CPE_CHANNELS][NB_DIV], /* i : two entries for each channel in TCX10 */ - STnsData tnsData[CPE_CHANNELS][NB_DIV], /* o : TNS parameter */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word16 fUseTns[CPE_CHANNELS][NB_DIV], /* i : two entries for each channel in TCX10 */ + STnsData tnsData[CPE_CHANNELS][NB_DIV], /* o : TNS parameter */ Word32 *x_fx[CPE_CHANNELS][NB_DIV], /* o : synthesis @internal_FS */ - Word32 Aq_fx[CPE_CHANNELS][(NB_SUBFR16k + 1) * (M + 1)], /* o : LP coefficients */ - const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ - Word16 x_e[CPE_CHANNELS][NB_DIV] -); + Word32 Aq_fx[CPE_CHANNELS][( NB_SUBFR16k + 1 ) * ( M + 1 )], /* o : LP coefficients */ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ + Word16 x_e[CPE_CHANNELS][NB_DIV] ); void decoder_tcx_imdct_fx( - Decoder_State *st, /* i/o: coder memory state */ + Decoder_State *st, /* i/o: coder memory state */ const Word16 L_frame_glob, /* i : frame length */ const Word16 L_frameTCX_glob, const Word16 L_spec, @@ -1418,7 +1411,7 @@ void decoder_tcx_imdct_fx( Word16 q_win, const UWord16 kernelType, /* i : TCX transform kernel type */ const Word16 fUseTns, /* i : flag that is set if TNS data is present */ - Word16 synth_fx[], /* i/o: synth[-M..L_frame] */ + Word16 synth_fx[], /* i/o: synth[-M..L_frame] */ Word16 synthFB_fx[], const Word16 bfi, /* i : Bad frame indicator */ const Word16 frame_cnt, /* i : frame counter in the super frame */ @@ -1426,18 +1419,18 @@ void decoder_tcx_imdct_fx( ); void ivas_sba_dirac_stereo_dec_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ Word32 *output[CPE_CHANNELS], /* i/o: output synthesis signal */ - const Word16 output_frame, /* i : output frame length per channel */ - const Word16 mcmasa /* i : McMASA flag */ + const Word16 output_frame, /* i : output frame length per channel */ + const Word16 mcmasa /* i : McMASA flag */ ); ivas_error ivas_osba_render_sf_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ UWord16 *nSamplesAvailableNext, /* o : number of CLDFB slots still to render */ - Word32 *p_output[] /* o : rendered time signal */ + Word32 *p_output[] /* o : rendered time signal */ ); void ivas_hq_core_dec_fx( @@ -1640,33 +1633,33 @@ void ivas_harm_bwe_fx( ); void ivas_hq_pred_hb_bws_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 *ynrm, /* i : norm quantization index vector */ - const Word16 length, /* i : frame length */ - const Word16 hqswb_clas, /* i : HQ SWB class */ - const Word16 *SWB_fenv /* i : SWB frequency envelopes Q1 */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 *ynrm, /* i : norm quantization index vector */ + const Word16 length, /* i : frame length */ + const Word16 hqswb_clas, /* i : HQ SWB class */ + const Word16 *SWB_fenv /* i : SWB frequency envelopes Q1 */ ); void synchro_synthesis_fx( - const Word32 ivas_total_brate, /* i : IVAS total bitrate */ - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *output_fx[CPE_CHANNELS], /* i/o: output synthesis signal */ - const Word16 output_frame, /* i : Number of samples */ - const Word16 sba_dirac_stereo_flag /* i : signal stereo output for SBA DirAC */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 *output_fx[CPE_CHANNELS], /* i/o: output synthesis signal */ + const Word16 output_frame, /* i : Number of samples */ + const Word16 sba_dirac_stereo_flag /* i : signal stereo output for SBA DirAC */ ); -//ivas_dirac_output_synthesis_cov +// ivas_dirac_output_synthesis_cov void ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( - Word32 *RealBuffer_fx, /* i : input channel filter bank samples (real part) */ - Word16 RealBuffer_e, /* i : exponent input channel filter bank samples (real part)*/ - Word32 *ImagBuffer_fx, /* i : input channel filter bank samples (imaginary part */ - Word16 ImagBuffer_e, /* i : exponent input channel filter bank samples (real part)*/ - Word32 cx_fx[PARAM_MC_MAX_PARAMETER_BANDS][PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS], /* o : accumulated input covariance (real part) */ - Word16 *cx_e, /* i : exponent for accumulated input covariance (real part) */ - Word32 cx_imag_fx[PARAM_MC_MAX_PARAMETER_BANDS][PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS], /* o : accumulated input covariance (imaginary part) */ - Word16 *cx_imag_e, /* i : exponent accumulated input covariance (imag part) */ - PARAM_MC_DEC_HANDLE hParamMC, /* i : handle to Parametric MC state */ - const Word16 nchan_in /* i : number of input channels */ + Word32 *RealBuffer_fx, /* i : input channel filter bank samples (real part) */ + Word16 RealBuffer_e, /* i : exponent input channel filter bank samples (real part)*/ + Word32 *ImagBuffer_fx, /* i : input channel filter bank samples (imaginary part */ + Word16 ImagBuffer_e, /* i : exponent input channel filter bank samples (real part)*/ + Word32 cx_fx[PARAM_MC_MAX_PARAMETER_BANDS][PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS], /* o : accumulated input covariance (real part) */ + Word16 *cx_e, /* i : exponent for accumulated input covariance (real part) */ + Word32 cx_imag_fx[PARAM_MC_MAX_PARAMETER_BANDS][PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS], /* o : accumulated input covariance (imaginary part) */ + Word16 *cx_imag_e, /* i : exponent accumulated input covariance (imag part) */ + PARAM_MC_DEC_HANDLE hParamMC, /* i : handle to Parametric MC state */ + const Word16 nchan_in /* i : number of input channels */ ); void configureFdCngDec_ivas_fx( @@ -1678,15 +1671,17 @@ void configureFdCngDec_ivas_fx( const Word16 element_mode ); void synchonize_channels_mdct_sid_fx( - Decoder_State *sts[CPE_CHANNELS], /* i/o: decoder state structure */ - const Word16 n /* i : channel number */ + Decoder_State *sts[CPE_CHANNELS], /* i/o: decoder state structure */ + const Word16 n /* i : channel number */ ); void ivas_interpolate_3_over_1_allpass_fx( - const Word16 *input_fx, /* i : input signal */ /* Q_input */ - const Word16 len, /* i : number of input samples */ - Word16 *out_fx, /* o : output signal */ /* Q_input */ - Word16 *mem_fx /* i/o: memory */ /* Q_input */ + const Word16 *input_fx, + /* i : input signal */ /* Q_input */ + const Word16 len, /* i : number of input samples */ + Word16 *out_fx, + /* o : output signal */ /* Q_input */ + Word16 *mem_fx /* i/o: memory */ /* Q_input */ ); void ivas_wb_tbe_dec_fx( @@ -1728,7 +1723,7 @@ Word16 ivas_wb_bwe_dec_fx( void ivas_param_ism_config_fx( PARAM_ISM_CONFIG_HANDLE hParamIsm, /* i/o: IVAS Param ISM Config Structure */ - const Word16 nchan_obj /* i : number of ISM channels */ + const Word16 nchan_obj /* i : number of ISM channels */ ); void ivas_mdct_core_invQ_fx( @@ -1758,20 +1753,19 @@ void ivas_mdct_tcx10_bit_distribution_fx( void TonalMDCTConceal_Detect_ivas_fx( const TonalMDCTConcealPtr hTonalMDCTConc, const Word32 pitchLag, - Word16 * numIndices, - const PsychoacousticParameters* psychParamsCurrent, - Word16 element_mode -); + Word16 *numIndices, + const PsychoacousticParameters *psychParamsCurrent, + Word16 element_mode ); Word16 GetPLCModeDecision_ivas_fx( - Decoder_State *st /* i/o: decoder memory state pointer */ + Decoder_State *st /* i/o: decoder memory state pointer */ ); void ivas_DetectTonalComponents_fx( Word16 indexOfTonalPeak[], Word16 lowerIndex[], Word16 upperIndex[], - Word16* pNumIndexes, + Word16 *pNumIndexes, const Word32 lastPitchLag, const Word32 currentPitchLag, const Word16 lastMDCTSpectrum[], @@ -1782,40 +1776,38 @@ void ivas_DetectTonalComponents_fx( const Word32 secondLastPowerSpectrum[], const Word16 nSamples, const Word16 nSamplesCore, - Word16 floorPowerSpectrum, /* i: lower limit for power spectrum bins */ - const PsychoacousticParameters* psychParamsCurrent, - Word16 element_mode -); + Word16 floorPowerSpectrum, /* i: lower limit for power spectrum bins */ + const PsychoacousticParameters *psychParamsCurrent, + Word16 element_mode ); ivas_error stereo_dft_dec_create_fx( STEREO_DFT_DEC_DATA_HANDLE *hStereoDft, /* i/o: decoder DFT stereo handle */ - const Word32 element_brate, /* i : element bitrate */ - const Word32 output_Fs, /* i : output sampling rate */ - const Word16 sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC */ - const Word16 nchan_transport /* i : number of transport channels */ + const Word32 element_brate, /* i : element bitrate */ + const Word32 output_Fs, /* i : output sampling rate */ + const Word16 sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC */ + const Word16 nchan_transport /* i : number of transport channels */ ); void stereo_cng_init_dec_fx( STEREO_CNG_DEC_HANDLE hStereoCng, /* i/o: stereo CNG decoder structure */ - const Word16 *frameSize /* i : pointer to frameSize of channel 0 to be used for channel 1 */ + const Word16 *frameSize /* i : pointer to frameSize of channel 0 to be used for channel 1 */ ); ivas_error stereo_memory_dec_fx( const Word32 ivas_total_brate, /* i : IVAS total bitrate */ - CPE_DEC_HANDLE hCPE, /* i : CPE decoder structure */ + CPE_DEC_HANDLE hCPE, /* i : CPE decoder structure */ const Word16 nb_bits_metadata, /* i : number of metadata bits */ const Word32 output_Fs, /* i : output sampling rate */ - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const MC_MODE mc_mode, /* i : MC mode */ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const MC_MODE mc_mode, /* i : MC mode */ const Word16 nchan_transport /* i : number of transport channels*/ ); void initFdCngDec_ivas_fx( DEC_CORE_HANDLE st, /* i/o: decoder state structure */ - Word16 scale -); + Word16 scale ); -void ivas_initFdCngCom_fx(HANDLE_FD_CNG_COM hFdCngCom, Word16 scale); +void ivas_initFdCngCom_fx( HANDLE_FD_CNG_COM hFdCngCom, Word16 scale ); Word16 set_ACELP_flag_IVAS( const Word16 element_mode, /* i : element mode */ @@ -1858,15 +1850,15 @@ Word16 ivas_qmetadata_dereorder_generic( #ifdef IVAS_FLOAT_FIXED void update_bits_next_block( IVAS_QDIRECTION *q_direction, /* i/o: qdirection */ - Word16 *p_diff, /* i/o: bits to be transferred */ - const Word16 j, /* i : subband to update bit alloc to*/ - const Word16 max_i, /* i : number of subbands */ - const Word16 max_k /* i : n umber of subframes */ + Word16 *p_diff, /* i/o: bits to be transferred */ + const Word16 j, /* i : subband to update bit alloc to*/ + const Word16 max_i, /* i : number of subbands */ + const Word16 max_k /* i : n umber of subframes */ ); #endif UWord32 ivas_syn_output_fx( - Word32 *synth[], /* i/o: float synthesis signal */ + Word32 *synth[], /* i/o: float synthesis signal */ const Word16 q_synth, const Word16 output_frame, /* i : output frame length (one channel) */ const Word16 n_channels, /* i : number of output channels */ @@ -1978,12 +1970,12 @@ void ivas_qmetadata_close( ivas_error ivas_spar_dec_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder struct */ - Word16 *nb_bits_read /* o : number of MD bits read */ + Word16 *nb_bits_read /* o : number of MD bits read */ ); void ivas_spar_md_dec_process_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling */ const Word16 num_bands_out, /* i : number of output bands */ const Word16 sba_order /* i : Ambisonic (SBA) order */ ); @@ -1997,10 +1989,9 @@ ivas_error TDREND_Update_object_positions_fx( ivas_error TDREND_MIX_LIST_SetOrient_fx( BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ - const Word32 *FrontVec_p_fx, /* i : Listener's orientation front vector */ - const Word32 *UpVec_p_fx, /* i : Listener's orientation up vector */ - const Word16 orient_q -); + const Word32 *FrontVec_p_fx, /* i : Listener's orientation front vector */ + const Word32 *UpVec_p_fx, /* i : Listener's orientation up vector */ + const Word16 orient_q ); void TDREND_MIX_LIST_SetPos_fx( BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ @@ -2010,59 +2001,59 @@ void TDREND_MIX_LIST_SetPos_fx( ivas_error TDREND_Update_listener_orientation_fx( BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD Renderer handle */ const Word16 headRotEnabled, /* i : Headrotation flag */ - const IVAS_QUATERNION *headPosition_fx, /* i : Listener orientation */ - const IVAS_VECTOR3 *Pos_fx /* i : Listener Position */ + const IVAS_QUATERNION *headPosition_fx, /* i : Listener orientation */ + const IVAS_VECTOR3 *Pos_fx /* i : Listener Position */ ); void QuatToRotMat_fx( const IVAS_QUATERNION quat, /* i : quaternion describing the rotation Qx */ - Word32 Rmat[3][3] /* o : real-space rotation matrix for this rotation 2*Qx-32 */ + Word32 Rmat[3][3] /* o : real-space rotation matrix for this rotation 2*Qx-32 */ ); Word32 TDREND_SPATIAL_VecNorm_fx( - const Word32 *Vec_p, /* i : Vector for norm calculation */ - const Word16 in_exp, /* i : Input exp */ - Word16 *out_exp /* o : Output exp */ + const Word32 *Vec_p, /* i : Vector for norm calculation */ + const Word16 in_exp, /* i : Input exp */ + Word16 *out_exp /* o : Output exp */ ); void TDREND_SPATIAL_VecMapToNewCoordSystem_fx( - const Word32 *Vec_p, /* i : Input vector */ - const Word32 *TranslVec_p, /* i : Translation vector */ - const Word32 *DirVec_p, /* i : Direction vector */ - const Word32 *UpVec_p, /* i : Up vector */ - const Word32 *RightVec_p, /* i : Right vector */ - Word32 *MappedVec_p, /* o : Transformed vector */ - Word32 *LisRelPosAbs /* o : Transformed vector ignoring orientation */ + const Word32 *Vec_p, /* i : Input vector */ + const Word32 *TranslVec_p, /* i : Translation vector */ + const Word32 *DirVec_p, /* i : Direction vector */ + const Word32 *UpVec_p, /* i : Up vector */ + const Word32 *RightVec_p, /* i : Right vector */ + Word32 *MappedVec_p, /* o : Transformed vector */ + Word32 *LisRelPosAbs /* o : Transformed vector ignoring orientation */ ); void ivas_mct_side_bits_fx( MCT_DEC_HANDLE hMCT, /* i/o: MCT decoder structure */ CPE_DEC_HANDLE hCPE[MCT_MAX_BLOCKS], /* i/o: CPE decoder structure */ - const Word16 nCPE, /* i : number of CPEs */ + const Word16 nCPE, /* i : number of CPEs */ Decoder_State *st0, /* i : decoder handle for Bstr */ - const Word16 bfi, /* i : BFI flag */ - UWord16 *bitstream, /* o : bitstream indices */ - const Word32 ivas_total_brate, /* i : IVAS total bitrate */ - const Word16 nb_bits_metadata /* i : number of metadata bits */ + const Word16 bfi, /* i : BFI flag */ + UWord16 *bitstream, /* o : bitstream indices */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + const Word16 nb_bits_metadata /* i : number of metadata bits */ ); -#ifdef BASOP_NOGLOB /*Critical overflow */ +#ifdef BASOP_NOGLOB /*Critical overflow */ Flag conv_fx_32( #else void conv_fx_32( #endif - const Word16 x[], /* i : i vector Q_new*/ - const Word16 h[], /* i : impulse response (or second i vector) Q(15)*/ - Word32 y[], /* o : output vetor (result of convolution) 12 bits*/ - const Word16 L /* i : vector size */ + const Word16 x[], /* i : i vector Q_new*/ + const Word16 h[], /* i : impulse response (or second i vector) Q(15)*/ + Word32 y[], /* o : output vetor (result of convolution) 12 bits*/ + const Word16 L /* i : vector size */ ); void stereo_dtf_cng_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ Word32 DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i/o: DFT buffers */ - const Word16 output_frame, /* i : output frame size */ - Word16 q_dft /* i : Q factor of the DFT data */ + const Word16 output_frame, /* i : output frame size */ + Word16 q_dft /* i : Q factor of the DFT data */ ); #endif // IVAS_FLOAT_FIXED @@ -2095,25 +2086,24 @@ void swb_tbe_reset_synth_ivas_fx( Word32 genSHBsynth_state_lsyn_filt_shb_local_fx_32[] ); void InitSWBdecBuffer_ivas_fx( - Decoder_State* st_fx /* i/o: SHB decoder structure */ + Decoder_State *st_fx /* i/o: SHB decoder structure */ ); void td_bwe_dec_init_ivas_fx( - Decoder_State* st_fx, /* i/o: SHB decoder structure */ + Decoder_State *st_fx, /* i/o: SHB decoder structure */ TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ - const Word32 output_Fs /* i : output sampling rate */ + const Word32 output_Fs /* i : output sampling rate */ ); void ivas_dirac_dec_render_sf_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - float *output_f[], /* i/o: synthesized core-coder transport channels/DirAC output */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + float *output_f[], /* i/o: synthesized core-coder transport channels/DirAC output */ #ifdef MSAN_FIX Word32 *output_fx[], /* i/o: synthesized core-coder transport channels/DirAC output */ -#endif // MSAN_FIX - const int16_t nchan_transport, /* i : number of transport channels */ +#endif // MSAN_FIX + const int16_t nchan_transport, /* i : number of transport channels */ Word32 *pppQMfFrame_ts_re_fx[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX], - Word32 *pppQMfFrame_ts_im_fx[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX] -); + Word32 *pppQMfFrame_ts_im_fx[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX] ); void ivas_dirac_dec_render_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ @@ -2125,20 +2115,20 @@ void ivas_dirac_dec_render_fx( ); void ivas_dirac_dec_read_BS_fx( - const int32_t ivas_total_brate, /* i : IVAS total bitrate */ - Decoder_State *st, /* i/o: decoder Core state structure */ - DIRAC_DEC_HANDLE hDirAC, /* i/o: decoder DirAC handle */ - SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial rendering data handle */ - IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q metadata */ - int16_t *nb_bits, /* o : number of bits read */ - const int16_t last_bit_pos, /* i : last read bitstream position */ - const int16_t hodirac_flag, /* i : flag to indicate HO-DirAC mode */ - int16_t *dirac_to_spar_md_bands /* o : DirAC->SPAR MD bands */ + const int32_t ivas_total_brate, /* i : IVAS total bitrate */ + Decoder_State *st, /* i/o: decoder Core state structure */ + DIRAC_DEC_HANDLE hDirAC, /* i/o: decoder DirAC handle */ + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial rendering data handle */ + IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q metadata */ + int16_t *nb_bits, /* o : number of bits read */ + const int16_t last_bit_pos, /* i : last read bitstream position */ + const int16_t hodirac_flag, /* i : flag to indicate HO-DirAC mode */ + int16_t *dirac_to_spar_md_bands /* o : DirAC->SPAR MD bands */ ); ivas_error ivas_dirac_dec_config_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const DIRAC_CONFIG_FLAG flag_configopen /* i/ : Flag determining if we open or reconfigure the DirAC decoder */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const DIRAC_CONFIG_FLAG flag_configopen /* i/ : Flag determining if we open or reconfigure the DirAC decoder */ ); void ivas_dirac_dec_output_synthesis_cov_close_fx( @@ -2147,19 +2137,19 @@ void ivas_dirac_dec_output_synthesis_cov_close_fx( ); ivas_error ivas_init_decoder_front_fx( - Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); ivas_error ivas_init_decoder_fx( - Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); void destroy_core_dec_fx( - DEC_CORE_HANDLE hCoreCoder /* i/o: core decoder structure */ + DEC_CORE_HANDLE hCoreCoder /* i/o: core decoder structure */ ); void ivas_destroy_dec_fx( - Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); ivas_error ivas_ism_dec_config_fx( @@ -2170,14 +2160,14 @@ ivas_error ivas_ism_dec_config_fx( ); ivas_error ivas_ism_metadata_dec_create_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const Word16 n_ISms, /* i : number of objects */ Word32 element_brate_tmp[] /* o : element bitrate per object */ ); ivas_error ivas_sba_dec_reconfigure_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ uint16_t *nSamplesFlushed, /* o : number of samples flushed */ - int16_t *data /* o : output synthesis signal */ + int16_t *data /* o : output synthesis signal */ ); ivas_error ivas_spar_md_dec_matrix_open_fx( @@ -2196,8 +2186,8 @@ ivas_error ivas_spar_dec_open_fx( void ivas_param_mc_dec_read_BS_fx( const Word32 ivas_total_brate, /* i : IVAS total bitrate */ - Decoder_State *st, /* i/o: decoder state structure */ - PARAM_MC_DEC_HANDLE hParamMC, /* i/o: decoder ParamMC handle */ + Decoder_State *st, /* i/o: decoder state structure */ + PARAM_MC_DEC_HANDLE hParamMC, /* i/o: decoder ParamMC handle */ Word16 *nb_bits /* o : number of bits written */ ); @@ -2227,19 +2217,19 @@ Word16 param_mc_get_num_cldfb_syntheses_fx( ); ivas_error ivas_FB_mixer_open_fx( - IVAS_FB_MIXER_HANDLE *hFbMixer_out, /* i/o: FB mixer handle */ - const Word32 sampling_rate, /* i : sampling rate */ - IVAS_FB_CFG *fb_cfg, /* i : FB config. handle */ - const Word16 spar_reconfig_flag /* i : SPAR reconfiguration flag */ + IVAS_FB_MIXER_HANDLE *hFbMixer_out, /* i/o: FB mixer handle */ + const Word32 sampling_rate, /* i : sampling rate */ + IVAS_FB_CFG *fb_cfg, /* i : FB config. handle */ + const Word16 spar_reconfig_flag /* i : SPAR reconfiguration flag */ ); void ivas_fb_mixer_cross_fading_fx( - IVAS_FB_MIXER_HANDLE hFbMixer, - Word32 **ppOut_pcm_fx, - Word32 *pMdft_out_old_fx, - Word32 *pMdft_out_new_fx, - const int16_t ch, - const int16_t frame_len, - const int16_t cf_offset ); + IVAS_FB_MIXER_HANDLE hFbMixer, + Word32 **ppOut_pcm_fx, + Word32 *pMdft_out_old_fx, + Word32 *pMdft_out_new_fx, + const int16_t ch, + const int16_t frame_len, + const int16_t cf_offset ); #endif diff --git a/lib_com/ivas_qmetadata_com.c b/lib_com/ivas_qmetadata_com.c index 12bc2f9e9..f816a740a 100644 --- a/lib_com/ivas_qmetadata_com.c +++ b/lib_com/ivas_qmetadata_com.c @@ -90,7 +90,7 @@ ivas_error ivas_qmetadata_open( ) { /* allocate MetaData handle */ - IF ( ( *hQMetaData = (IVAS_QMETADATA_HANDLE) malloc( sizeof( IVAS_QMETADATA ) ) ) == NULL ) + IF( ( *hQMetaData = (IVAS_QMETADATA_HANDLE) malloc( sizeof( IVAS_QMETADATA ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for Q MetaData" ); } @@ -279,15 +279,15 @@ ivas_error ivas_qmetadata_allocate_memory( { set_zero( hQMetaData->q_direction[dir].band_data[j].elevation, MAX_PARAM_SPATIAL_SUBFRAMES ); #ifdef IVAS_FLOAT_FIXED - set32_fx( hQMetaData->q_direction[dir].band_data[j].elevation_fx,0, MAX_PARAM_SPATIAL_SUBFRAMES ); + set32_fx( hQMetaData->q_direction[dir].band_data[j].elevation_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); #endif set_zero( hQMetaData->q_direction[dir].band_data[j].azimuth, MAX_PARAM_SPATIAL_SUBFRAMES ); #ifdef IVAS_FLOAT_FIXED - set32_fx( hQMetaData->q_direction[dir].band_data[j].azimuth_fx,0, MAX_PARAM_SPATIAL_SUBFRAMES ); + set32_fx( hQMetaData->q_direction[dir].band_data[j].azimuth_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); #endif set_zero( hQMetaData->q_direction[dir].band_data[j].energy_ratio, MAX_PARAM_SPATIAL_SUBFRAMES ); #ifdef IVAS_FLOAT_FIXED - set32_fx( hQMetaData->q_direction[dir].band_data[j].energy_ratio_fx,0, MAX_PARAM_SPATIAL_SUBFRAMES ); + set32_fx( hQMetaData->q_direction[dir].band_data[j].energy_ratio_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); #endif } } @@ -526,7 +526,7 @@ ivas_error only_reduce_bits_direction_fx( Word16 *bits_dir0; Word16 bits_sph_idx_orig[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; -#ifdef FIX_QMETADATA_PENALTY +#ifdef FIX_QMETADATA_PENALTY Word32 penalty[MASA_MAXIMUM_CODING_SUBBANDS]; Word16 tmp; #else @@ -617,7 +617,7 @@ ivas_error only_reduce_bits_direction_fx( } ELSE { -#ifdef FIX_QMETADATA_PENALTY +#ifdef FIX_QMETADATA_PENALTY Word16 m, sorted, index1, index2; @@ -648,21 +648,21 @@ ivas_error only_reduce_bits_direction_fx( FOR( k = 0; k < no_subframes; k++ ) { tmp = add( tmp, sub( bits_sph_idx_orig[index2][k], q_direction->band_data[index2].bits_sph_idx[k] ) ); - } + } penalty[1] = L_shr( W_extract_l( W_mult_32_16( tmp, bits_sph_idx_orig[index1][0] ) ), 1 ); IF( LT_32( penalty[0], penalty[1] ) ) - { + { sorted = 0; move16(); ind_order[j] = index2; move16(); ind_order[j + 1] = index1; move16(); + } } } - } - - + + #else FOR( j = 0; j < coding_subbands; j++ ) { diff --git a/lib_com/ivas_qspherical_com.c b/lib_com/ivas_qspherical_com.c index c7cbe3aba..9c2f5f643 100644 --- a/lib_com/ivas_qspherical_com.c +++ b/lib_com/ivas_qspherical_com.c @@ -210,7 +210,7 @@ Word16 ivas_dirac_project_azimuth_index( { Word16 az_idx_proj; - IF ( EQ_16(az_alph_proj, 1) ) + IF( EQ_16( az_alph_proj, 1 ) ) { return 0; } @@ -218,7 +218,7 @@ Word16 ivas_dirac_project_azimuth_index( /* evaluate floor((az_idx / az_alph) * az_alph_proj + 0.5) using only integer */ az_idx_proj = ( 2 * az_idx * az_alph_proj + az_alph ) / ( 2 * az_alph ); - IF(EQ_16(az_idx_proj, az_alph_proj) ) + IF( EQ_16( az_idx_proj, az_alph_proj ) ) { az_idx_proj = 0; move16(); @@ -452,25 +452,22 @@ Word16 quantize_phi_fx( { id_phi = add( id_phi, ( n % 2 ) ); } - ELSE - { - IF( EQ_16( id_phi, add( shr( n, 1 ), ( n % 2 ) ) ) ) - { - IF( n % 2 ) - { + ELSE{ + IF( EQ_16( id_phi, add( shr( n, 1 ), ( n % 2 ) ) ) ){ + IF( n % 2 ){ id_phi = sub( id_phi, 1 ); - } - ELSE - { - id_phi = negate( id_phi ); - } - } - } +} +ELSE +{ + id_phi = negate( id_phi ); +} +} +} - *phi_hat = L_add( L_add( ( id_phi * delta_phi_fx ), dd_fx ), DEGREE_180_Q_22 ); - id_phi = add( id_phi, shr( n, 1 ) ); +*phi_hat = L_add( L_add( ( id_phi * delta_phi_fx ), dd_fx ), DEGREE_180_Q_22 ); +id_phi = add( id_phi, shr( n, 1 ) ); - return id_phi; +return id_phi; } #endif /*-----------------------------------------------------------------------* diff --git a/lib_com/ivas_rom_com.c b/lib_com/ivas_rom_com.c index f8db53655..4a3d2ab6a 100644 --- a/lib_com/ivas_rom_com.c +++ b/lib_com/ivas_rom_com.c @@ -9177,254 +9177,254 @@ const Word32 one_by_q_level[64] = /* Q Factor is 31*/ const Word32 ivas_han_win_48k_fx[L_FRAME32k] = { - 5760, 22976, 51712, 91904, 143552, 206784, 281408, 367552, 465216, - 574272, 694912, 826944, 970496, 1125504, 1292032, 1470016, 1659456, - 1860352, 2072704, 2296576, 2531904, 2778624, 3036864, 3306560, 3587648, - 3880256, 4184256, 4499712, 4826624, 5164992, 5514752, 5875968, 6248576, - 6632640, 7028096, 7434944, 7853248, 8282880, 8723968, 9176448, 9640320, - 10115584, 10602176, 11100224, 11609536, 12130304, 12662400, 13205824, 13760576, - 14326720, 14904192, 15492928, 16093056, 16704512, 17327232, 17961216, 18606592, - 19263168, 19931072, 20610240, 21300672, 22002368, 22715328, 23439488, 24174912, - 24921600, 25679424, 26448512, 27228800, 28020288, 28822976, 29636864, 30461888, - 31298048, 32145344, 33003840, 33873472, 34754176, 35646016, 36548992, 37463040, - 38388224, 39324416, 40271680, 41230016, 42199424, 43179840, 44171264, 45173696, - 46187200, 47211648, 48247104, 49293504, 50350848, 51419200, 52498432, 53588608, - 54689664, 55801664, 56924544, 58058304, 59202944, 60358400, 61524736, 62701888, - 63889856, 65088640, 66298176, 67518528, 68749632, 69991488, 71244096, 72507392, - 73781440, 75066176, 76361536, 77667648, 78984384, 80311744, 81649728, 82998400, - 84357568, 85727424, 87107776, 88498688, 89900160, 91312128, 92734656, 94167680, - 95611136, 97065088, 98529472, 100004288, 101489536, 102985152, 104491200, 106007552, - 107534336, 109071424, 110618816, 112176512, 113744512, 115322816, 116911296, 118510080, - 120119040, 121738240, 123367552, 125007104, 126656768, 128316608, 129986496, 131666496, - 133356608, 135056768, 136766976, 138487232, 140217408, 141957632, 143707840, 145467968, - 147238016, 149017984, 150807872, 152607616, 154417216, 156236672, 158065920, 159904960, - 161753728, 163612352, 165480640, 167358720, 169246464, 171143808, 173050880, 174967552, - 176893888, 178829760, 180775296, 182730304, 184694848, 186668928, 188652480, 190645504, - 192648000, 194659904, 196681216, 198711936, 200752000, 202801344, 204860032, 206928064, - 209005376, 211091904, 213187648, 215292672, 217406784, 219530048, 221662528, 223804096, - 225954752, 228114496, 230283264, 232461056, 234647872, 236843584, 239048320, 241262016, - 243484544, 245716032, 247956288, 250205440, 252463424, 254730112, 257005632, 259289856, - 261582784, 263884416, 266194688, 268513664, 270841216, 273177344, 275522048, 277875264, - 280237056, 282607296, 284986048, 287373184, 289768768, 292172672, 294584960, 297005632, - 299434560, 301871808, 304317312, 306771072, 309233024, 311703040, 314181312, 316667712, - 319162240, 321664832, 324175424, 326694080, 329220672, 331755200, 334297728, 336848192, - 339406528, 341972672, 344546688, 347128448, 349718080, 352315328, 354920384, 357533120, - 360153536, 362781568, 365417152, 368060352, 370711168, 373369408, 376035200, 378708416, - 381389120, 384077120, 386772608, 389475456, 392185536, 394902976, 397627648, 400359552, - 403098624, 405844928, 408598400, 411358976, 414126592, 416901312, 419683008, 422471680, - 425267392, 428070016, 430879552, 433695936, 436519232, 439349312, 442186112, 445029696, - 447880064, 450737088, 453600832, 456471168, 459348160, 462231616, 465121600, 468018176, - 470921280, 473830784, 476746688, 479668928, 482597632, 485532608, 488473856, 491421376, - 494375168, 497335168, 500301184, 503273472, 506251840, 509236288, 512226752, 515223296, - 518225728, 521234048, 524248320, 527268608, 530294592, 533326528, 536364096, 539407552, - 542456576, 545511296, 548571712, 551637888, 554709440, 557786624, 560869376, 563957504, - 567051264, 570150272, 573254656, 576364544, 579479616, 582600064, 585725696, 588856704, - 591992704, 595134080, 598280256, 601431680, 604588160, 607749632, 610916224, 614087680, - 617264128, 620445312, 623631488, 626822336, 630017984, 633218496, 636423616, 639633408, - 642847872, 646067008, 649290624, 652518784, 655751552, 658988672, 662230400, 665476352, - 668726784, 671981504, 675240576, 678503808, 681771264, 685042944, 688318784, 691598848, - 694882880, 698171072, 701463168, 704759296, 708059392, 711363328, 714671296, 717982976, - 721298560, 724617728, 727940864, 731267392, 734597760, 737931776, 741269376, 744610624, - 747955200, 751303488, 754655040, 758009984, 761368512, 764730240, 768095360, 771463616, - 774835200, 778209792, 781587840, 784968832, 788352896, 791740160, 795130304, 798523584, - 801919616, 805318784, 808720640, 812125312, 815532928, 818943168, 822356288, 825771840, - 829190272, 832611200, 836034816, 839460928, 842889472, 846320640, 849754112, 853190080, - 856628352, 860068992, 863511808, 866957056, 870404352, 873853696, 877305408, 880759104, - 884215040, 887672832, 891132736, 894594496, 898058112, 901523840, 904991232, 908460544, - 911931456, 915404288, 918878528, 922354560, 925832384, 929311616, 932792512, 936274816, - 939758720, 943243904, 946730624, 950218560, 953707840, 957198528, 960690368, 964183488, - 967677568, 971172992, 974669440, 978166912, 981665536, 985164992, 988665600, 992166912, - 995669248, 999172288, 1002676288, 1006180864, 1009686208, 1013192384, 1016698880, 1020206336, - 1023714176, 1027222656, 1030731584, 1034241024, 1037750784, 1041260928, 1044771584, 1048282368, - 1051793600, 1055304896, 1058816512, 1062328192, 1065839872, 1069351872, 1072863808, 1076375808, - 1079887744, 1083399680, 1086911488, 1090423168, 1093934592, 1097445760, 1100956928, 1104467584, - 1107977984, 1111488000, 1114997504, 1118506624, 1122015232, 1125523456, 1129031040, 1132538112, - 1136044544, 1139550336, 1143055360, 1146559616, 1150063104, 1153565696, 1157067648, 1160568576, - 1164068480, 1167567488, 1171065600, 1174562560, 1178058496, 1181553408, 1185046912, 1188539520, - 1192030720, 1195520768, 1199009408, 1202496768, 1205982720, 1209467008, 1212950144, 1216431744, - 1219911936, 1223390336, 1226867328, 1230342528, 1233816192, 1237288064, 1240758144, 1244226560, - 1247693056, 1251157760, 1254620416, 1258081152, 1261539968, 1264996864, 1268451712, 1271904384, - 1275355008, 1278803456, 1282249728, 1285693696, 1289135488, 1292574848, 1296011904, 1299446784, - 1302878976, 1306308736, 1309736064, 1313160960, 1316583296, 1320002944, 1323420032, 1326834304, - 1330246144, 1333655040, 1337061120, 1340464512, 1343865088, 1347262592, 1350657152, 1354048768, - 1357437440, 1360823168, 1364205824, 1367585280, 1370961664, 1374334720, 1377704704, 1381071360, - 1384434816, 1387794944, 1391151616, 1394504960, 1397854976, 1401201152, 1404544000, 1407883520, - 1411219328, 1414551552, 1417880064, 1421204992, 1424526080, 1427843456, 1431157120, 1434466944, - 1437772928, 1441074944, 1444373120, 1447667072, 1450957312, 1454243328, 1457525248, 1460803328, - 1464077056, 1467346688, 1470612096, 1473873408, 1477130240, 1480382848, 1483630976, 1486874752, - 1490114048, 1493348992, 1496579584, 1499805440, 1503026944, 1506243584, 1509455744, 1512663296, - 1515866112, 1519064192, 1522257536, 1525446144, 1528629760, 1531808512, 1534982272, 1538151296, - 1541315328, 1544474368, 1547628288, 1550777216, 1553921024, 1557059840, 1560193152, 1563321472, - 1566444672, 1569562240, 1572674816, 1575782016, 1578883584, 1581980032, 1585070848, 1588156416, - 1591236352, 1594310912, 1597379584, 1600442880, 1603500544, 1606552576, 1609598592 + 5760, 22976, 51712, 91904, 143552, 206784, 281408, 367552, 465216, + 574272, 694912, 826944, 970496, 1125504, 1292032, 1470016, 1659456, + 1860352, 2072704, 2296576, 2531904, 2778624, 3036864, 3306560, 3587648, + 3880256, 4184256, 4499712, 4826624, 5164992, 5514752, 5875968, 6248576, + 6632640, 7028096, 7434944, 7853248, 8282880, 8723968, 9176448, 9640320, + 10115584, 10602176, 11100224, 11609536, 12130304, 12662400, 13205824, 13760576, + 14326720, 14904192, 15492928, 16093056, 16704512, 17327232, 17961216, 18606592, + 19263168, 19931072, 20610240, 21300672, 22002368, 22715328, 23439488, 24174912, + 24921600, 25679424, 26448512, 27228800, 28020288, 28822976, 29636864, 30461888, + 31298048, 32145344, 33003840, 33873472, 34754176, 35646016, 36548992, 37463040, + 38388224, 39324416, 40271680, 41230016, 42199424, 43179840, 44171264, 45173696, + 46187200, 47211648, 48247104, 49293504, 50350848, 51419200, 52498432, 53588608, + 54689664, 55801664, 56924544, 58058304, 59202944, 60358400, 61524736, 62701888, + 63889856, 65088640, 66298176, 67518528, 68749632, 69991488, 71244096, 72507392, + 73781440, 75066176, 76361536, 77667648, 78984384, 80311744, 81649728, 82998400, + 84357568, 85727424, 87107776, 88498688, 89900160, 91312128, 92734656, 94167680, + 95611136, 97065088, 98529472, 100004288, 101489536, 102985152, 104491200, 106007552, + 107534336, 109071424, 110618816, 112176512, 113744512, 115322816, 116911296, 118510080, + 120119040, 121738240, 123367552, 125007104, 126656768, 128316608, 129986496, 131666496, + 133356608, 135056768, 136766976, 138487232, 140217408, 141957632, 143707840, 145467968, + 147238016, 149017984, 150807872, 152607616, 154417216, 156236672, 158065920, 159904960, + 161753728, 163612352, 165480640, 167358720, 169246464, 171143808, 173050880, 174967552, + 176893888, 178829760, 180775296, 182730304, 184694848, 186668928, 188652480, 190645504, + 192648000, 194659904, 196681216, 198711936, 200752000, 202801344, 204860032, 206928064, + 209005376, 211091904, 213187648, 215292672, 217406784, 219530048, 221662528, 223804096, + 225954752, 228114496, 230283264, 232461056, 234647872, 236843584, 239048320, 241262016, + 243484544, 245716032, 247956288, 250205440, 252463424, 254730112, 257005632, 259289856, + 261582784, 263884416, 266194688, 268513664, 270841216, 273177344, 275522048, 277875264, + 280237056, 282607296, 284986048, 287373184, 289768768, 292172672, 294584960, 297005632, + 299434560, 301871808, 304317312, 306771072, 309233024, 311703040, 314181312, 316667712, + 319162240, 321664832, 324175424, 326694080, 329220672, 331755200, 334297728, 336848192, + 339406528, 341972672, 344546688, 347128448, 349718080, 352315328, 354920384, 357533120, + 360153536, 362781568, 365417152, 368060352, 370711168, 373369408, 376035200, 378708416, + 381389120, 384077120, 386772608, 389475456, 392185536, 394902976, 397627648, 400359552, + 403098624, 405844928, 408598400, 411358976, 414126592, 416901312, 419683008, 422471680, + 425267392, 428070016, 430879552, 433695936, 436519232, 439349312, 442186112, 445029696, + 447880064, 450737088, 453600832, 456471168, 459348160, 462231616, 465121600, 468018176, + 470921280, 473830784, 476746688, 479668928, 482597632, 485532608, 488473856, 491421376, + 494375168, 497335168, 500301184, 503273472, 506251840, 509236288, 512226752, 515223296, + 518225728, 521234048, 524248320, 527268608, 530294592, 533326528, 536364096, 539407552, + 542456576, 545511296, 548571712, 551637888, 554709440, 557786624, 560869376, 563957504, + 567051264, 570150272, 573254656, 576364544, 579479616, 582600064, 585725696, 588856704, + 591992704, 595134080, 598280256, 601431680, 604588160, 607749632, 610916224, 614087680, + 617264128, 620445312, 623631488, 626822336, 630017984, 633218496, 636423616, 639633408, + 642847872, 646067008, 649290624, 652518784, 655751552, 658988672, 662230400, 665476352, + 668726784, 671981504, 675240576, 678503808, 681771264, 685042944, 688318784, 691598848, + 694882880, 698171072, 701463168, 704759296, 708059392, 711363328, 714671296, 717982976, + 721298560, 724617728, 727940864, 731267392, 734597760, 737931776, 741269376, 744610624, + 747955200, 751303488, 754655040, 758009984, 761368512, 764730240, 768095360, 771463616, + 774835200, 778209792, 781587840, 784968832, 788352896, 791740160, 795130304, 798523584, + 801919616, 805318784, 808720640, 812125312, 815532928, 818943168, 822356288, 825771840, + 829190272, 832611200, 836034816, 839460928, 842889472, 846320640, 849754112, 853190080, + 856628352, 860068992, 863511808, 866957056, 870404352, 873853696, 877305408, 880759104, + 884215040, 887672832, 891132736, 894594496, 898058112, 901523840, 904991232, 908460544, + 911931456, 915404288, 918878528, 922354560, 925832384, 929311616, 932792512, 936274816, + 939758720, 943243904, 946730624, 950218560, 953707840, 957198528, 960690368, 964183488, + 967677568, 971172992, 974669440, 978166912, 981665536, 985164992, 988665600, 992166912, + 995669248, 999172288, 1002676288, 1006180864, 1009686208, 1013192384, 1016698880, 1020206336, + 1023714176, 1027222656, 1030731584, 1034241024, 1037750784, 1041260928, 1044771584, 1048282368, + 1051793600, 1055304896, 1058816512, 1062328192, 1065839872, 1069351872, 1072863808, 1076375808, + 1079887744, 1083399680, 1086911488, 1090423168, 1093934592, 1097445760, 1100956928, 1104467584, + 1107977984, 1111488000, 1114997504, 1118506624, 1122015232, 1125523456, 1129031040, 1132538112, + 1136044544, 1139550336, 1143055360, 1146559616, 1150063104, 1153565696, 1157067648, 1160568576, + 1164068480, 1167567488, 1171065600, 1174562560, 1178058496, 1181553408, 1185046912, 1188539520, + 1192030720, 1195520768, 1199009408, 1202496768, 1205982720, 1209467008, 1212950144, 1216431744, + 1219911936, 1223390336, 1226867328, 1230342528, 1233816192, 1237288064, 1240758144, 1244226560, + 1247693056, 1251157760, 1254620416, 1258081152, 1261539968, 1264996864, 1268451712, 1271904384, + 1275355008, 1278803456, 1282249728, 1285693696, 1289135488, 1292574848, 1296011904, 1299446784, + 1302878976, 1306308736, 1309736064, 1313160960, 1316583296, 1320002944, 1323420032, 1326834304, + 1330246144, 1333655040, 1337061120, 1340464512, 1343865088, 1347262592, 1350657152, 1354048768, + 1357437440, 1360823168, 1364205824, 1367585280, 1370961664, 1374334720, 1377704704, 1381071360, + 1384434816, 1387794944, 1391151616, 1394504960, 1397854976, 1401201152, 1404544000, 1407883520, + 1411219328, 1414551552, 1417880064, 1421204992, 1424526080, 1427843456, 1431157120, 1434466944, + 1437772928, 1441074944, 1444373120, 1447667072, 1450957312, 1454243328, 1457525248, 1460803328, + 1464077056, 1467346688, 1470612096, 1473873408, 1477130240, 1480382848, 1483630976, 1486874752, + 1490114048, 1493348992, 1496579584, 1499805440, 1503026944, 1506243584, 1509455744, 1512663296, + 1515866112, 1519064192, 1522257536, 1525446144, 1528629760, 1531808512, 1534982272, 1538151296, + 1541315328, 1544474368, 1547628288, 1550777216, 1553921024, 1557059840, 1560193152, 1563321472, + 1566444672, 1569562240, 1572674816, 1575782016, 1578883584, 1581980032, 1585070848, 1588156416, + 1591236352, 1594310912, 1597379584, 1600442880, 1603500544, 1606552576, 1609598592 }; /* Q Factor is 31*/ const Word32 ivas_han_win_32k_fx[L_FRAME32k] = { - 12928, 51648, 116224, 206656, 322880, 464960, 632832, 826496, 1046016, - 1291328, 1562496, 1859392, 2182080, 2530560, 2904832, 3304832, 3730560, - 4182080, 4659328, 5162304, 5690944, 6245312, 6825344, 7431104, 8062464, - 8719488, 9402112, 10110336, 10844160, 11603520, 12388480, 13198976, 14034944, - 14896448, 15783424, 16695808, 17633664, 18596928, 19585536, 20599552, 21638912, - 22703552, 23793472, 24908672, 26049088, 27214720, 28405504, 29621504, 30862592, - 32128704, 33419968, 34736192, 36077440, 37443712, 38834816, 40250880, 41691776, - 43157504, 44648064, 46163328, 47703360, 49268032, 50857408, 52471296, 54109824, - 55772928, 57460416, 59172416, 60908800, 62669568, 64454656, 66264064, 68097664, - 69955456, 71837440, 73743488, 75673600, 77627712, 79605824, 81607808, 83633664, - 85683392, 87756864, 89854080, 91974912, 94119360, 96287424, 98478976, 100694016, - 102932416, 105194240, 107479296, 109787648, 112119232, 114473856, 116851584, 119252352, - 121676096, 124122688, 126592192, 129084480, 131599488, 134137088, 136697408, 139280192, - 141885440, 144513152, 147163264, 149835584, 152530176, 155246848, 157985728, 160746560, - 163529408, 166334144, 169160704, 172009024, 174879040, 177770752, 180683904, 183618624, - 186574720, 189552128, 192550848, 195570752, 198611840, 201673920, 204756992, 207860992, - 210985792, 214131392, 217297600, 220484480, 223691840, 226919680, 230167936, 233436416, - 236725120, 240033984, 243362880, 246711744, 250080512, 253469120, 256877440, 260305472, - 263753024, 267220096, 270706496, 274212288, 277737280, 281281408, 284844672, 288426880, - 292027904, 295647808, 299286464, 302943744, 306619456, 310313728, 314026368, 317757248, - 321506304, 325273472, 329058688, 332861760, 336682688, 340521408, 344377664, 348251520, - 352142784, 356051456, 359977344, 363920448, 367880640, 371857792, 375851840, 379862656, - 383890112, 387934272, 391994880, 396071936, 400165248, 404274816, 408400384, 412542016, - 416699584, 420872960, 425062016, 429266688, 433486912, 437722368, 441973248, 446239360, - 450520576, 454816704, 459127808, 463453696, 467794112, 472149248, 476518784, 480902784, - 485300992, 489713344, 494139840, 498580032, 503034304, 507502208, 511983808, 516478848, - 520987392, 525509120, 530044032, 534592000, 539153088, 543726912, 548313600, 552912832, - 557524608, 562148736, 566785408, 571434048, 576094784, 580767616, 585452224, 590148608, - 594856576, 599576192, 604307072, 609049344, 613802752, 618567296, 623342592, 628128896, - 632925888, 637733504, 642551552, 647380096, 652218752, 657067648, 661926400, 666795264, - 671673856, 676562176, 681459968, 686367232, 691283648, 696209536, 701144320, 706088192, - 711040768, 716002176, 720972224, 725950656, 730937472, 735932480, 740935808, 745947008, - 750966144, 755992960, 761027456, 766069504, 771118976, 776175680, 781239680, 786310528, - 791388416, 796472896, 801564288, 806662080, 811766400, 816876928, 821993792, 827116544, - 832245248, 837379776, 842520064, 847665856, 852817152, 857973696, 863135424, 868302208, - 873474048, 878650560, 883831808, 889017728, 894207936, 899402624, 904601216, 909804160, - 915010944, 920221696, 925435904, 930653952, 935875200, 941099776, 946327616, 951558592, - 956792384, 962029120, 967268416, 972510272, 977754624, 983001344, 988250112, 993501120, - 998753856, 1004008576, 1009264704, 1014522624, 1019781888, 1025042560, 1030304256, 1035566976, - 1040830784, 1046095232, 1051360384, 1056626048, 1061892224, 1067158592, 1072425280, 1077691776, - 1082958208, 1088224512, 1093490560, 1098755968, 1104020736, 1109284864, 1114548224, 1119810432, - 1125071616, 1130331520, 1135590272, 1140847232, 1146102912, 1151356544, 1156608512, 1161858304, - 1167106048, 1172351616, 1177594624, 1182835200, 1188073344, 1193308544, 1198541056, 1203770368, - 1208996736, 1214219648, 1219439232, 1224655488, 1229867904, 1235076736, 1240281472, 1245482240, - 1250679040, 1255871360, 1261059456, 1266243072, 1271421952, 1276596224, 1281765504, 1286929920, - 1292089088, 1297243008, 1302391552, 1307534592, 1312672000, 1317803520, 1322929280, 1328049152, - 1333162752, 1338270336, 1343371264, 1348465920, 1353553920, 1358635264, 1363709568, 1368776960, - 1373837312, 1378890496, 1383936256, 1388974336, 1394004992, 1399028224, 1404043264, 1409050496, - 1414049792, 1419040640, 1424023424, 1428997632, 1433963392, 1438920448, 1443868672, 1448808064, - 1453738496, 1458659328, 1463571328, 1468473856, 1473366912, 1478250240, 1483124096, 1487987968, - 1492841856, 1497685632, 1502519296, 1507342592, 1512155392, 1516957696, 1521749504, 1526530176, - 1531299968, 1536059008, 1540806912, 1545543424, 1550268672, 1554982528, 1559684864, 1564375168, - 1569053952, 1573720832, 1578375680, 1583018240, 1587648640, 1592266496, 1596872192, 1601464960, - 1606045312, 1610612736, 1615167488, 1619708672, 1624237184, 1628752384, 1633254272, 1637742464, - 1642217216, 1646678400, 1651125504, 1655558784, 1659978240, 1664383616, 1668774784, 1673151488, - 1677513856, 1681861760, 1686194816, 1690513408, 1694817024, 1699105792, 1703379200, 1707637760, - 1711880960, 1716108800, 1720321152, 1724518144, 1728699392, 1732865024, 1737014400, 1741148160, - 1745265792, 1749367296, 1753452288, 1757521152, 1761573632, 1765609344, 1769628416, 1773630976, - 1777616640, 1781585408, 1785536768, 1789471488, 1793388800, 1797288832, 1801171328, 1805036544, - 1808883968, 1812713728, 1816525824, 1820320000, 1824096000, 1827854208, 1831594112, 1835315968, - 1839019520, 1842704384, 1846370944, 1850018944, 1853648256, 1857258624, 1860850432, 1864423168, - 1867976960, 1871511296, 1875026688, 1878522880, 1881999616, 1885456896, 1888894720, 1892312832, - 1895711488, 1899089920, 1902448896, 1905787904, 1909106688, 1912405504, 1915684096, 1918942592, - 1922180480, 1925398016, 1928595200, 1931771904, 1934927616, 1938062848, 1941177344, 1944270848, - 1947343360, 1950395136, 1953425664, 1956434944, 1959422976, 1962389632, 1965335040, 1968259072, - 1971161344, 1974042368, 1976901504, 1979739008, 1982554624, 1985348352, 1988120320, 1990870272, - 1993597952, 1996303616, 1998987264, 2001648384, 2004287104, 2006903552, 2009497728, 2012069376, - 2014618112, 2017144576, 2019648256, 2022129024, 2024587136, 2027022336, 2029434624, 2031823872, - 2034190080, 2036533120, 2038853120, 2041149696, 2043423232, 2045673344, 2047900160, 2050103296, - 2052283136, 2054439552, 2056572160, 2058681216, 2060766464, 2062828160, 2064865920, 2066879744, - 2068869888, 2070835968, 2072778240, 2074696192, 2076590336, 2078460160, 2080305792, 2082127360, - 2083924608, 2085697536, 2087446016, 2089170304, 2090870144, 2092545280, 2094196096, 2095822336, - 2097424128, 2099001088, 2100553472, 2102081024, 2103584000, 2105062144, 2106515456, 2107943936, - 2109347584, 2110726272, 2112080000, 2113408768, 2114712448, 2115991168, 2117244672, 2118473216, - 2119676672, 2120854912, 2122007936, 2123135744, 2124238336, 2125315584, 2126367616, 2127394304, - 2128395520, 2129371648, 2130322048, 2131247232, 2132146944, 2133021184, 2133869824, 2134693120, - 2135490816, 2136263040, 2137009664, 2137730688, 2138426112, 2139095936, 2139740160, 2140358656, - 2140951552, 2141518720, 2142060288, 2142576128, 2143066112, 2143530496, 2143969152, 2144382080, - 2144769280, 2145130496, 2145466112, 2145775872, 2146060032, 2146318208, 2146550528, 2146757120, - 2146937984, 2147092992, 2147222016, 2147325440, 2147403008, 2147454592, 2147480448 + 12928, 51648, 116224, 206656, 322880, 464960, 632832, 826496, 1046016, + 1291328, 1562496, 1859392, 2182080, 2530560, 2904832, 3304832, 3730560, + 4182080, 4659328, 5162304, 5690944, 6245312, 6825344, 7431104, 8062464, + 8719488, 9402112, 10110336, 10844160, 11603520, 12388480, 13198976, 14034944, + 14896448, 15783424, 16695808, 17633664, 18596928, 19585536, 20599552, 21638912, + 22703552, 23793472, 24908672, 26049088, 27214720, 28405504, 29621504, 30862592, + 32128704, 33419968, 34736192, 36077440, 37443712, 38834816, 40250880, 41691776, + 43157504, 44648064, 46163328, 47703360, 49268032, 50857408, 52471296, 54109824, + 55772928, 57460416, 59172416, 60908800, 62669568, 64454656, 66264064, 68097664, + 69955456, 71837440, 73743488, 75673600, 77627712, 79605824, 81607808, 83633664, + 85683392, 87756864, 89854080, 91974912, 94119360, 96287424, 98478976, 100694016, + 102932416, 105194240, 107479296, 109787648, 112119232, 114473856, 116851584, 119252352, + 121676096, 124122688, 126592192, 129084480, 131599488, 134137088, 136697408, 139280192, + 141885440, 144513152, 147163264, 149835584, 152530176, 155246848, 157985728, 160746560, + 163529408, 166334144, 169160704, 172009024, 174879040, 177770752, 180683904, 183618624, + 186574720, 189552128, 192550848, 195570752, 198611840, 201673920, 204756992, 207860992, + 210985792, 214131392, 217297600, 220484480, 223691840, 226919680, 230167936, 233436416, + 236725120, 240033984, 243362880, 246711744, 250080512, 253469120, 256877440, 260305472, + 263753024, 267220096, 270706496, 274212288, 277737280, 281281408, 284844672, 288426880, + 292027904, 295647808, 299286464, 302943744, 306619456, 310313728, 314026368, 317757248, + 321506304, 325273472, 329058688, 332861760, 336682688, 340521408, 344377664, 348251520, + 352142784, 356051456, 359977344, 363920448, 367880640, 371857792, 375851840, 379862656, + 383890112, 387934272, 391994880, 396071936, 400165248, 404274816, 408400384, 412542016, + 416699584, 420872960, 425062016, 429266688, 433486912, 437722368, 441973248, 446239360, + 450520576, 454816704, 459127808, 463453696, 467794112, 472149248, 476518784, 480902784, + 485300992, 489713344, 494139840, 498580032, 503034304, 507502208, 511983808, 516478848, + 520987392, 525509120, 530044032, 534592000, 539153088, 543726912, 548313600, 552912832, + 557524608, 562148736, 566785408, 571434048, 576094784, 580767616, 585452224, 590148608, + 594856576, 599576192, 604307072, 609049344, 613802752, 618567296, 623342592, 628128896, + 632925888, 637733504, 642551552, 647380096, 652218752, 657067648, 661926400, 666795264, + 671673856, 676562176, 681459968, 686367232, 691283648, 696209536, 701144320, 706088192, + 711040768, 716002176, 720972224, 725950656, 730937472, 735932480, 740935808, 745947008, + 750966144, 755992960, 761027456, 766069504, 771118976, 776175680, 781239680, 786310528, + 791388416, 796472896, 801564288, 806662080, 811766400, 816876928, 821993792, 827116544, + 832245248, 837379776, 842520064, 847665856, 852817152, 857973696, 863135424, 868302208, + 873474048, 878650560, 883831808, 889017728, 894207936, 899402624, 904601216, 909804160, + 915010944, 920221696, 925435904, 930653952, 935875200, 941099776, 946327616, 951558592, + 956792384, 962029120, 967268416, 972510272, 977754624, 983001344, 988250112, 993501120, + 998753856, 1004008576, 1009264704, 1014522624, 1019781888, 1025042560, 1030304256, 1035566976, + 1040830784, 1046095232, 1051360384, 1056626048, 1061892224, 1067158592, 1072425280, 1077691776, + 1082958208, 1088224512, 1093490560, 1098755968, 1104020736, 1109284864, 1114548224, 1119810432, + 1125071616, 1130331520, 1135590272, 1140847232, 1146102912, 1151356544, 1156608512, 1161858304, + 1167106048, 1172351616, 1177594624, 1182835200, 1188073344, 1193308544, 1198541056, 1203770368, + 1208996736, 1214219648, 1219439232, 1224655488, 1229867904, 1235076736, 1240281472, 1245482240, + 1250679040, 1255871360, 1261059456, 1266243072, 1271421952, 1276596224, 1281765504, 1286929920, + 1292089088, 1297243008, 1302391552, 1307534592, 1312672000, 1317803520, 1322929280, 1328049152, + 1333162752, 1338270336, 1343371264, 1348465920, 1353553920, 1358635264, 1363709568, 1368776960, + 1373837312, 1378890496, 1383936256, 1388974336, 1394004992, 1399028224, 1404043264, 1409050496, + 1414049792, 1419040640, 1424023424, 1428997632, 1433963392, 1438920448, 1443868672, 1448808064, + 1453738496, 1458659328, 1463571328, 1468473856, 1473366912, 1478250240, 1483124096, 1487987968, + 1492841856, 1497685632, 1502519296, 1507342592, 1512155392, 1516957696, 1521749504, 1526530176, + 1531299968, 1536059008, 1540806912, 1545543424, 1550268672, 1554982528, 1559684864, 1564375168, + 1569053952, 1573720832, 1578375680, 1583018240, 1587648640, 1592266496, 1596872192, 1601464960, + 1606045312, 1610612736, 1615167488, 1619708672, 1624237184, 1628752384, 1633254272, 1637742464, + 1642217216, 1646678400, 1651125504, 1655558784, 1659978240, 1664383616, 1668774784, 1673151488, + 1677513856, 1681861760, 1686194816, 1690513408, 1694817024, 1699105792, 1703379200, 1707637760, + 1711880960, 1716108800, 1720321152, 1724518144, 1728699392, 1732865024, 1737014400, 1741148160, + 1745265792, 1749367296, 1753452288, 1757521152, 1761573632, 1765609344, 1769628416, 1773630976, + 1777616640, 1781585408, 1785536768, 1789471488, 1793388800, 1797288832, 1801171328, 1805036544, + 1808883968, 1812713728, 1816525824, 1820320000, 1824096000, 1827854208, 1831594112, 1835315968, + 1839019520, 1842704384, 1846370944, 1850018944, 1853648256, 1857258624, 1860850432, 1864423168, + 1867976960, 1871511296, 1875026688, 1878522880, 1881999616, 1885456896, 1888894720, 1892312832, + 1895711488, 1899089920, 1902448896, 1905787904, 1909106688, 1912405504, 1915684096, 1918942592, + 1922180480, 1925398016, 1928595200, 1931771904, 1934927616, 1938062848, 1941177344, 1944270848, + 1947343360, 1950395136, 1953425664, 1956434944, 1959422976, 1962389632, 1965335040, 1968259072, + 1971161344, 1974042368, 1976901504, 1979739008, 1982554624, 1985348352, 1988120320, 1990870272, + 1993597952, 1996303616, 1998987264, 2001648384, 2004287104, 2006903552, 2009497728, 2012069376, + 2014618112, 2017144576, 2019648256, 2022129024, 2024587136, 2027022336, 2029434624, 2031823872, + 2034190080, 2036533120, 2038853120, 2041149696, 2043423232, 2045673344, 2047900160, 2050103296, + 2052283136, 2054439552, 2056572160, 2058681216, 2060766464, 2062828160, 2064865920, 2066879744, + 2068869888, 2070835968, 2072778240, 2074696192, 2076590336, 2078460160, 2080305792, 2082127360, + 2083924608, 2085697536, 2087446016, 2089170304, 2090870144, 2092545280, 2094196096, 2095822336, + 2097424128, 2099001088, 2100553472, 2102081024, 2103584000, 2105062144, 2106515456, 2107943936, + 2109347584, 2110726272, 2112080000, 2113408768, 2114712448, 2115991168, 2117244672, 2118473216, + 2119676672, 2120854912, 2122007936, 2123135744, 2124238336, 2125315584, 2126367616, 2127394304, + 2128395520, 2129371648, 2130322048, 2131247232, 2132146944, 2133021184, 2133869824, 2134693120, + 2135490816, 2136263040, 2137009664, 2137730688, 2138426112, 2139095936, 2139740160, 2140358656, + 2140951552, 2141518720, 2142060288, 2142576128, 2143066112, 2143530496, 2143969152, 2144382080, + 2144769280, 2145130496, 2145466112, 2145775872, 2146060032, 2146318208, 2146550528, 2146757120, + 2146937984, 2147092992, 2147222016, 2147325440, 2147403008, 2147454592, 2147480448 }; /* Q Factor is 31*/ const Word32 ivas_han_win_16k_fx[L_FRAME32k] = { - 51584, 206336, 464192, 825216, 1289344, 1856512, 2526592, 3299648, 4175552, - 5154240, 6235584, 7419520, 8705856, 10094592, 11585472, 13178432, 14873280, - 16669824, 18568000, 20567552, 22668288, 24869952, 27172480, 29575488, 32078848, - 34682304, 37385600, 40188480, 43090624, 46091840, 49191808, 52390144, 55686656, - 59081024, 62572800, 66161792, 69847552, 73629824, 77508160, 81482176, 85551552, - 89715904, 93974784, 98327808, 102774528, 107314560, 111947456, 116672768, 121490048, - 126398720, 131398528, 136488832, 141669184, 146939136, 152298048, 157745600, 163281088, - 168904064, 174614016, 180410304, 186292480, 192259904, 198312000, 204448256, 210667968, - 216970688, 223355584, 229822336, 236370112, 242998400, 249706432, 256493632, 263359424, - 270303040, 277323904, 284421184, 291594368, 298842688, 306165440, 313562048, 321031552, - 328573440, 336186944, 343871360, 351625792, 359449600, 367342144, 375302528, 383329984, - 391423744, 399583168, 407807232, 416095424, 424446720, 432860480, 441335680, 449871744, - 458467776, 467122752, 475836160, 484606976, 493434496, 502317568, 511255744, 520247936, - 529293184, 538390784, 547539840, 556739456, 565988800, 575286848, 584632832, 594025792, - 603464960, 612949248, 622477568, 632049536, 641663872, 651319808, 661016192, 670752128, - 680527040, 690339584, 700189056, 710074240, 719994624, 729948800, 739936128, 749955328, - 760005760, 770086400, 780196224, 790334336, 800499328, 810690816, 820907648, 831148608, - 841412992, 851699584, 862007680, 872335936, 882683648, 893049664, 903433024, 913832832, - 924248064, 934677504, 945120256, 955575552, 966042176, 976519040, 987005248, 997499904, - 1008001792, 1018510080, 1029023552, 1039541440, 1050062528, 1060585984, 1071110720, 1081635456, - 1092159616, 1102681984, 1113201664, 1123717504, 1134228480, 1144733696, 1155232256, 1165722752, - 1176204288, 1186676224, 1197137280, 1207586432, 1218022656, 1228445184, 1238852864, 1249244416, - 1259619328, 1269976192, 1280314368, 1290632832, 1300930304, 1311205888, 1321458432, 1331687552, - 1341891840, 1352070400, 1362221952, 1372346112, 1382441472, 1392506880, 1402541952, 1412545280, - 1422516224, 1432453632, 1442356608, 1452224000, 1462054912, 1471848832, 1481604480, 1491320832, - 1500997120, 1510632320, 1520225536, 1529775744, 1539282176, 1548744192, 1558160256, 1567529728, - 1576852096, 1586125824, 1595350272, 1604524800, 1613648128, 1622719872, 1631738624, 1640703744, - 1649614592, 1658469888, 1667269376, 1676011520, 1684695808, 1693321472, 1701887616, 1710393344, - 1718837760, 1727220480, 1735540352, 1743796480, 1751988480, 1760115200, 1768175616, 1776169856, - 1784096256, 1791954688, 1799744000, 1807463424, 1815112576, 1822690048, 1830195968, 1837629184, - 1844988928, 1852274688, 1859485440, 1866620672, 1873679872, 1880662016, 1887566976, 1894393600, - 1901141248, 1907809536, 1914397696, 1920904960, 1927330816, 1933674624, 1939936000, 1946114048, - 1952208256, 1958218240, 1964142848, 1969982336, 1975735552, 1981401984, 1986981376, 1992472832, - 1997876224, 2003190656, 2008415744, 2013551360, 2018596352, 2023550720, 2028413824, 2033185152, - 2037864192, 2042450688, 2046944256, 2051344128, 2055650048, 2059861888, 2063978752, 2068000512, - 2071926784, 2075757056, 2079491072, 2083128576, 2086668928, 2090112128, 2093457408, 2096705024, - 2099854080, 2102904832, 2105856512, 2108709120, 2111462144, 2114115584, 2116668928, 2119122176, - 2121475072, 2123727104, 2125878528, 2127928576, 2129877504, 2131724800, 2133470464, 2135114496, - 2136656384, 2138096128, 2139433728, 2140668928, 2141801472, 2142831616, 2143758848, 2144583424, - 2145304960, 2145923584, 2146439168, 2146851840, 2147161344, 2147367680, 2147470848, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0 + 51584, 206336, 464192, 825216, 1289344, 1856512, 2526592, 3299648, 4175552, + 5154240, 6235584, 7419520, 8705856, 10094592, 11585472, 13178432, 14873280, + 16669824, 18568000, 20567552, 22668288, 24869952, 27172480, 29575488, 32078848, + 34682304, 37385600, 40188480, 43090624, 46091840, 49191808, 52390144, 55686656, + 59081024, 62572800, 66161792, 69847552, 73629824, 77508160, 81482176, 85551552, + 89715904, 93974784, 98327808, 102774528, 107314560, 111947456, 116672768, 121490048, + 126398720, 131398528, 136488832, 141669184, 146939136, 152298048, 157745600, 163281088, + 168904064, 174614016, 180410304, 186292480, 192259904, 198312000, 204448256, 210667968, + 216970688, 223355584, 229822336, 236370112, 242998400, 249706432, 256493632, 263359424, + 270303040, 277323904, 284421184, 291594368, 298842688, 306165440, 313562048, 321031552, + 328573440, 336186944, 343871360, 351625792, 359449600, 367342144, 375302528, 383329984, + 391423744, 399583168, 407807232, 416095424, 424446720, 432860480, 441335680, 449871744, + 458467776, 467122752, 475836160, 484606976, 493434496, 502317568, 511255744, 520247936, + 529293184, 538390784, 547539840, 556739456, 565988800, 575286848, 584632832, 594025792, + 603464960, 612949248, 622477568, 632049536, 641663872, 651319808, 661016192, 670752128, + 680527040, 690339584, 700189056, 710074240, 719994624, 729948800, 739936128, 749955328, + 760005760, 770086400, 780196224, 790334336, 800499328, 810690816, 820907648, 831148608, + 841412992, 851699584, 862007680, 872335936, 882683648, 893049664, 903433024, 913832832, + 924248064, 934677504, 945120256, 955575552, 966042176, 976519040, 987005248, 997499904, + 1008001792, 1018510080, 1029023552, 1039541440, 1050062528, 1060585984, 1071110720, 1081635456, + 1092159616, 1102681984, 1113201664, 1123717504, 1134228480, 1144733696, 1155232256, 1165722752, + 1176204288, 1186676224, 1197137280, 1207586432, 1218022656, 1228445184, 1238852864, 1249244416, + 1259619328, 1269976192, 1280314368, 1290632832, 1300930304, 1311205888, 1321458432, 1331687552, + 1341891840, 1352070400, 1362221952, 1372346112, 1382441472, 1392506880, 1402541952, 1412545280, + 1422516224, 1432453632, 1442356608, 1452224000, 1462054912, 1471848832, 1481604480, 1491320832, + 1500997120, 1510632320, 1520225536, 1529775744, 1539282176, 1548744192, 1558160256, 1567529728, + 1576852096, 1586125824, 1595350272, 1604524800, 1613648128, 1622719872, 1631738624, 1640703744, + 1649614592, 1658469888, 1667269376, 1676011520, 1684695808, 1693321472, 1701887616, 1710393344, + 1718837760, 1727220480, 1735540352, 1743796480, 1751988480, 1760115200, 1768175616, 1776169856, + 1784096256, 1791954688, 1799744000, 1807463424, 1815112576, 1822690048, 1830195968, 1837629184, + 1844988928, 1852274688, 1859485440, 1866620672, 1873679872, 1880662016, 1887566976, 1894393600, + 1901141248, 1907809536, 1914397696, 1920904960, 1927330816, 1933674624, 1939936000, 1946114048, + 1952208256, 1958218240, 1964142848, 1969982336, 1975735552, 1981401984, 1986981376, 1992472832, + 1997876224, 2003190656, 2008415744, 2013551360, 2018596352, 2023550720, 2028413824, 2033185152, + 2037864192, 2042450688, 2046944256, 2051344128, 2055650048, 2059861888, 2063978752, 2068000512, + 2071926784, 2075757056, 2079491072, 2083128576, 2086668928, 2090112128, 2093457408, 2096705024, + 2099854080, 2102904832, 2105856512, 2108709120, 2111462144, 2114115584, 2116668928, 2119122176, + 2121475072, 2123727104, 2125878528, 2127928576, 2129877504, 2131724800, 2133470464, 2135114496, + 2136656384, 2138096128, 2139433728, 2140668928, 2141801472, 2142831616, 2143758848, 2144583424, + 2145304960, 2145923584, 2146439168, 2146851840, 2147161344, 2147367680, 2147470848, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0 }; /* Q Factor is 30 */ @@ -9513,1019 +9513,1019 @@ const Word32 ivas_sine_frame_len_640_fx[577] = { }; /************************ Q30 *******************************/ -const Word32 ivas_fb_fr_12band_1ms_re_fx[IVAS_FB_12_1MS_LEN] = { - 1046768256, 1012312512, 944113536, 843565952, 712700800, 554033920, 370399360, 163534048, -67588040, - -313003296, -547361792, -745791424, -889130944, -964720960, -967822016, -901839040, -777730304, - -612432896, -426573984, -241764928, -77701744, 50405768, 134107528, 173698992, 183571312, - 181978912, 174963648, 163434880, 148881184, 132470640, 115304208, 98219512, 81912736, - 66862960, 53409868, 41724844, 31871182, 23797162, 17385436, 12455156, 8801240, - 6197829, 4427144, 3280128, 2575327, 2155348, 1897329, 1705752, 1516863, - 1289431, 1005694, 661856, 267796, -161263, -604780, -1043282, -1457411, - -1832285, -2155534, -2420027, -2621275, -2759126, -2835035, -2853297, -2818571, - -2737039, -2614376, -2456980, -2270381, -2060530, -1832512, -1591794, -1343094, - -1091494, -841376, -597362, -363290, -143021, 60510, 244561, 407408, - 547618, 664738, 758550, 829643, 878668, 906840, 915250, 905346, - 878343, 835721, 778738, 708948, 627794, 537107, 438729, 334948, - 228103, 120925, 16090, -83524, -175327, -256811, -326026, -381381, - -422046, -447703, -458837, -456405, -442013, -417522, -385138, -347000, - -305255, -261681, -217812, -174648, -132866, -92642, -53935, -16402, - 20279, 56463, 92235, 127494, 161728, 194173, 223691, 249012, - 268700, 281445, 286068, 281804, 268278, 245720, 214858, 177029, - 133974, 87839, 40901, -4492, -46220, -82436, -111817, -133546, - -147456, -153913, -153846, -148528, -139528, -128444, -116827, -105934, - -96699, -89563, -84536, -81138, -78561, -75704, -71400, -64501, - -54108, -39627, -20946, 1593, 27122, 54374, 81719, 107372, - 129497, 146446, 156855, 159848, 155068, 142780, 123803, 99496, - 71589, 42078, 8610925, 16407290, 31915518, 54983844, 85416624, 123087880, - 168063984, 221958576, 289536032, 364878560, 426914240, 455184448, 434995104, 358099712, - 224036640, 40240900, -178615296, -412308800, -637390400, -829991424, -968687232, -1037118016, - -1026013056, -934381184, -769721024, -547208704, -287987072, -16727445, 241188016, 462583776, - 629070144, 729071296, 758930560, 723116864, 633312128, 506752128, 363680000, 224696192, - 107612800, 25033840, -24212064, -54589336, -75035176, -87485160, -93580896, -94591848, - -91737704, -86038536, -78437624, -69711224, -60533488, -51423856, -42794000, -34920752, - -27987240, -22072318, -17188296, -13279352, -10254646, -7989723, -6353249, -5207335, - -4426934, -3897128, -3525509, -3236283, -2977071, -2710878, -2419337, -2094076, - -1738366, -1359253, -969076, -579170, -201992, 153445, 478767, 769398, - 1021418, 1233894, 1405828, 1538184, 1631253, 1686663, 1705249, 1689093, - 1639776, 1560317, 1453594, 1324024, 1175972, 1015086, 846649, 676618, - 509991, 351706, 205173, 73207, -43142, -143513, -229073, -301290, - -362531, -414799, -460247, -500043, -534968, -564551, -587849, -602888, - -607619, -599579, -576918, -538114, -482894, -411845, -327078, -231622, - -129783, -26319, 73437, 164513, 242258, 303205, 344935, 366711, - 369107, 354325, 325569, 287088, 243371, 199057, 158131, 123882, - 98274, 82114, 74715, 74333, 78122, 82791, 84734, 80757, - 68210, 45592, 12513, -29958, -79606, -133015, -186134, -234445, - -273650, -299897, -310406, -303565, -279332, -239075, -185665, -123028, - -55984, 10396, 12276729, 12693837, 13547048, 14871155, 16707203, 19094012, - 22050984, 25567530, 29581572, 33971516, 38534384, 42985632, 46940136, 49924776, - 51363228, 50604824, 46909464, 39493740, 27503144, 10070768, -13759776, -44999620, - -84980336, -136135984, -207135712, -303422240, -412817600, -514972896, -589851392, -619651584, - -591583168, -499579936, -345470464, -138966128, 103208400, 359174656, 604351488, 814326528, - 967700992, 1048627328, 1048680832, 967863296, 814603776, 604752128, 359708672, 103884792, - -138140928, -344495008, -498458752, -590328384, -618282624, -588395136, -513462144, -411289888, - -301917376, -205694144, -134796400, -83778624, -43967052, -12923312, 10688964, 27884292, - 39622020, 46770036, 50183460, 50644772, 48893804, 45580600, 41282912, 36475948, - 31549672, 26793770, 22418028, 18548592, 15250408, 12530037, 10357491, 8671122, - 7396225, 6448686, 5748701, 5221465, 4805724, 4451326, 4123487, 3798131, - 3463431, 3114322, 2752946, 2383612, 2013354, 1648090, 1293873, 954378, - 632818, 330406, 48532, -212349, -450755, -665332, -853410, -1012414, - -1138953, -1230412, -1284349, -1300013, -1277722, -1220043, -1130902, -1016282, - -883017, -739061, -592113, -449695, -317863, -201395, -102837, -23014, - 39453, 87271, 124545, 155673, 185224, 216854, 253275, 295449, - 342868, 393176, 442827, 487113, 521090, 539819, 539332, 516817, - 471355, 403816, 317194, 216106, 106711, -4112, -109126, -201659, - -275976, -328059, -355725, -359045, -340068, -302808, -252589, -195699, - -138533, -87141, -46428, -19866, -8984, -13439, -30918, -57611, - -88487, -118040, -140755, -151891, -147872, -126858, -88834, -35798, - 28549, 99021, 169585, 233841, 285797, 320360, 333987, 324942, - 293611, 242374, 175498, 98630, 18357, -58534, -125609, -177509, - -210361, -222240, -213241, -185532, -143021, -91031, -35654, 16794, - 60506, 90695, 104157, 99518, 77443, 40482, -7123, -59963, - -111945, -157005, -189668, -205697, -202469, -179335, -137639, -80671, - -13290, 58484, 128123, 189173, 235954, 264066, 270883, 255765, - 220174, 2505037, 2442157, 2316154, 2126672, 1874467, 1561489, 1192761, - 775600, 321304, -157412, -645618, -1131069, -1604363, -2065994, -2526609, - -3015154, -3577470, -4283816, -5223516, -6510031, -8269471, -10642073, -13763168, - -17761360, -22731886, -28733746, -35756756, -43722016, -52444716, -61644104, -70903304, - -79696304, -87342288, -93058336, -95895816, -94830640, -88641344, -76058616, -55443336, - -24863958, 24611116, 107440320, 224788944, 364047616, 507399776, 634242176, 724330048, - 760427264, 730852288, 631136576, 464936832, 243827808, -13803173, -284784032, -543737088, - -765995008, -930417472, -1021827456, -1032720576, -964074624, -825139200, -632243584, -406773696, - -172552176, 47020828, 231770176, 367063072, 445488224, 467504928, 441322720, 381553248, - 308519520, 243096544, 190940560, 146958368, 109144704, 76984176, 50110068, 28195132, - 10859917, -2331860, -11867127, -18267046, -22063578, -23780578, -23911906, -22907786, - -21160858, -19000796, -16689673, -14424574, -12340740, -10519832, -8997765, -7775391, - -6827615, -6113435, -5583605, -5187945, -4880011, -4620898, -4380691, -4139162, - -3884798, -3613535, -3326639, -3028821, -2726195, -2424818, -2129499, -1843272, - -1567228, -1300854, -1042591, -790584, -543428, -300799, -63891, 164435, - 379755, 576491, 748467, 889663, 994911, 1060624, 1085268, 1069727, - 1017300, 933554, 825817, 702603, 572797, 444929, 326372, 222801, - 137707, 72284, 25430, -5886, -26190, -40792, -55143, -74076, - -101256, -138661, -186386, -242548, -303550, -364410, -419384, -462555, - -488576, -493231, -474014, -430404, -364059, -278663, -179684, -73826, - 31531, 129079, 212203, 275656, 315980, 331857, 324141, 295780, - 251424, 196978, 138929, 83734, 37113, 3535, -14258, -15450, - -1229, 25423, 60045, 97246, 131265, 156654, 168829, 164631, - 142633, 103366, 49247, -15601, -85794, -155177, -217478, -266899, - -298743, -309847, -298949, -266783, -216054, -151145, -77727, -2174, - 69017, 702811, 654136, 559557, 424419, 255932, 62727, -146313, - -362395, -578054, -786994, -985086, -1169469, -1339221, -1493760, -1633415, - -1757450, -1864970, -1953010, -2018235, -2055396, -2060043, -2027296, -1955369, - -1844129, -1698799, -1527422, -1343910, -1163448, -1004247, -880298, -801810, - -765486, -754582, -727814, -620985, -336399, 251272, 1302991, 3002489, - 5560181, 9191239, 14115464, 20525480, 28584940, 38387408, 49958096, 63204572, - 77930464, 93777392, 110263472, 126708904, 142322784, 156083648, 166946144, 173586320, - 175308576, 166325584, 128680304, 48303544, -74757040, -231715952, -407042976, -580775616, - -731094848, -837272320, -882366976, -855569984, -753729472, -582012992, -353498368, -87845872, - 190881904, 456905760, 685667520, 856595200, 955419584, 975703808, 919454400, 796692096, - 624085824, 422776032, 215700912, 24714716, -132116288, -242736960, -302620672, -315365760, - -293500640, -258619744, -225315280, -194015376, -163910608, -135501680, -109209736, -85466480, - -64529184, -46551644, -31533836, -19377918, -9878438, -2769905, 2268515, 5573895, - 7492172, 8348992, 8445734, 8040905, 7351921, 6546074, 5747758, 5036624, - 4458304, 4026662, 3735443, 3561663, 3475902, 3444629, 3437763, 3428836, - 3399492, 3337488, 3238697, 3103696, 2938339, 2749967, 2547660, 2338971, - 2130630, 1926285, 1727949, 1534741, 1344902, 1155176, 962956, 765794, - 563232, 356016, 147339, -58398, -254956, -435840, -594040, -723684, - -819800, -879714, -902536, -890086, -845966, -775986, -686897, -586473, - -482133, -380953, -288451, -208799, -143979, -94350, -58234, -32830, - -14133, 1978, 19701, 42276, 72069, 109808, 154947, 205272, - 257581, 307614, 350943, 383061, 400284, 399785, 380309, 341971, - 286657, 217523, 139066, 56385, -24953, -99742, -163283, -212106, - -243951, -258230, -255733, -167174, -239722, -322173, -408810, -492821, - -566516, -622391, -653378, -653921, -619965, -549788, -443508, -303565, - -133727, 60691, 274135, 500595, 734943, 972407, 1209697, 1443978, - 1673718, 1897211, 2113333, 2319888, 2514652, 2693915, 2854207, 2991285, - 3102696, 3187122, 3247515, 3290252, 3328147, 3378477, 3464934, 3613501, - 3852565, 4205968, 4691138, 5309438, 6043184, 6844465, 7633047, 8285794, - 8638327, 8477588, 7550391, 5561188, 2190063, -2903797, -10053462, -19577218, - -31739716, -46747292, -64700276, -85602512, -109304912, -135555296, -163926944, -194002976, - -225285872, -258586768, -293477632, -315364832, -302650912, -242803328, -132218944, 24580560, - 215544720, 422611008, 623927680, 796557504, 919359168, 975661312, 955439360, 856681664, - 685819520, 457116384, 191139072, -87558504, -353200000, -581723904, -753469440, -855356160, - -882212736, -837186048, -731079168, -580827520, -407153984, -231873488, -74945544, 48100840, - 128479736, 166141328, 175151264, 173462112, 166856272, 156024384, 142286160, 126683672, - 110236760, 93736176, 77863432, 63103528, 49819328, 38212324, 28380444, 20303444, - 13891988, 8985083, 5391207, 2889572, 1262319, 294475, -203348, -398749, - -423662, -382151, -343523, -352875, -428668, -574135, -776792, -1018896, - -1276918, -1529859, -1757571, -1946540, -2086827, -2175642, -2213314, -2205436, - -2158564, -2081784, -1982822, -1869689, -1747600, -1621008, -1491391, -1359644, - -1224514, -1085096, -939557, -787433, -628324, -463767, -295726, -127991, - 35529, 189782, 330335, 452518, 553054, 629169, 679950, 705285, - 706896, 687113, 649626, 598183, 537192, 470470, 401849, 334088, - 269582, 209498, 154619, 104683, 59308, 17469, -21588, -58843, - -94673, -129406, -162639, -193876, -221997, -245959, -264363, -276167, - -280285, -276237, -263718, -243144, -215155, -181048, -225261, -273555, - -307889, -326103, -327476, -312684, -283609, -243038, -194256, -140631, - -85182, -30244, 22798, 73608, 122885, 172169, 223570, 279366, - 341593, 411622, 489814, 575248, 665622, 757256, 845294, 923987, - 987121, 1028456, 1042203, 1023430, 968397, 874758, 741642, 569587, - 360379, 116796, -157659, -459031, -783110, -1125546, -1481872, -1847416, - -2217186, -2585716, -2947037, -3294742, -3622346, -3923849, -4194709, -4432970, - -4640760, -4825675, -5002266, -5192922, -5428408, -5747161, -6193793, -6815752, - -7658969, -8761350, -10145511, -11809549, -13717971, -15791409, -17898084, -19845242, - -21374384, -22157722, -21800466, -19845174, -15783279, -9068449, 863064, 14571969, - 32592328, 55410852, 83458416, 117107272, 156758688, 202942128, 257651808, 325933440, - 402044000, 464971200, 494205696, 474891008, 398522784, 264288720, 79206760, -142533824, - -381224512, -613975168, -817483264, -970950784, -1058690624, -1072345920, -1012679872, -893613760, - -734287744, -546547584, -339769856, -124623176, 88170360, 288225568, 466194112, 614172160, - 726163904, 798321728, 829131584, 819397568, 772133120, 692285376, 586377152, 462039040, - 327503712, 191064064, 60554008, -57130884, -156432848, -233429280, -286014272, -313941504, - -318749984, -303544416, -272698496, -231426688, -185371904, -140057616, -100631488, -69996648, - -46622364, -28166424, -13810469, -2980571, 4834391, 10133794, 13384151, 15027667, - 15460742, 15036408, 14051635, 12751812, 11326396, 9916592, 8616869, 7484565, - 6544389, 5798046, 5229236, 4811721, 4513168, 4300801, 4143382, 4014381, - 3892172, 3761242, 3611156, 3436579, 3235728, 3009947, 2762235, 2496885, - 2218419, 1931526, 1640448, 1349202, 1061301, 780105, 508675, 250099, - 7326, -216639, -418984, -597023, -748502, -871609, -965247, -1029025, - -1063439, -1069768, -1050128, -1007269, -944511, -865478, -773983, -673761, - -568371, -460991, -354385, -250799, -152007, -59299, 26411, 104546, - 174730, 236744, 290418, 335608, 372145, 399853, 418548, 428095, - 428430, 419636, 401963, 375881, 342083, 301499, 255265, 204699, - 151239, 96397, 41685, -11436, -61625, -107696, -148661, -183744, - -212399, -234301, -249338, -257586, -259295, -171383, -167771, -160946, - -151648, -140875, -129741, -119346, -110602, -104127, -100108, -98276, - -97857, -97667, -96155, -91604, -82246, -66504, -43110, -11334, - 28976, 77253, 132282, 192171, 254555, 316653, 375561, 428343, - 472340, 505222, 525246, 531204, 522588, 499415, 462302, 412189, - 350367, 278167, 197008, 108113, 12645, -88501, -194453, -304491, - -417705, -533098, -649202, -764225, -875703, -980757, -1075829, -1157086, - -1220253, -1261142, -1275529, -1259757, -1210576, -1125738, -1003720, -844248, - -647867, -416383, -152288, 140834, 458975, 797247, 1150575, 1513140, - 1879071, 2241774, 2594688, 2930577, 3242477, 3523085, 3766061, 3965621, - 4118279, 4222622, 4281408, 4301274, 4294860, 4279931, 4280984, 4327080, - 4452293, 4691546, 5079427, 5643594, 6401946, 7353690, 8475606, 9711576, - 10969534, 12110916, 12950640, 13248182, 12713298, 10999818, 7719470, 2437137, - -5306709, -16007364, -30173754, -48382488, -71457888, -101754088, -140816912, -185763344, - -231466336, -272424224, -303010560, -318021792, -313081312, -285067456, -232401024, -155266144, - -55676148, 62564504, 194048000, 332049728, 468930560, 596597632, 707022848, 792757376, - 847434880, 866203136, 846081856, 786193920, 687883392, 554677120, 392130080, 207514704, - 9432382, -192707744, -389200480, -570675136, -728479808, -856350656, -952308800, -1015864832, - -1046220032, -1043342848, -1008126784, -942413952, -848923648, -731177152, -593366784, -440223744, - -276851936, -108565096, 59292484, 221513920, 373199296, 509904800, 627780928, 723682304, - 795257728, 841006144, 860308096, 853421632, 821452480, 766292160, 690533568, 597361024, - 490425248, 373702496, 251347920, 127544600, 6357648, -108405296, -213318272, -305445280, - -382425728, -442537280, -484731648, -508645408, -514583008, -503476768, -476822816, -436599136, - -385166592, -325160416, -259373680, -190640560, -121721768, -55198692, 6621388, 61783672, - 108746912, 146423216, 174197536, 191924704, 199906864, 198850976, 189810704, 174114128, - 153282784, 128943984, 102742896, 76256368, 50914548, 27932052, 8253544, -7485707, - -18981258, -26263536, -29686804, -29902128, -27874808, -24904632, -21873452, -18924710, - -16109369, -13513449, -11193274, -9184409, -7497119, -6124396, -5043505, -4222392, - -3622104, -3201531, -2919256, -2736657, -2618792, -2536063, -2464195, -2384826, - -2284834, -2156265, -1995319, -1801974, -1578908, -1331064, -1064692, -787000, - -505396, -227288, 40476, 291657, 521006, 724191, 898044, 1040397, - 1150221, 1227397, 1272778, 1287922, 1275099, 1237007, 1176756, 1097593, - 1002895, 895923, 779853, 657586, 531818, 404912, 279016, 155978, - 37491, -74965, -179989, -276315, -362698, -438012, -501167, -551237, - -587418, -609171, -616196, -608571, -586708, -551466, -504065, -446144, - -379632, -306754, -229859, -151391, -73706, 962, 70672, 133776, - 189046, 235630, 273114, 301432, 320873, 331952, 335393, 331988, - 322579, 307941, 288792, 265710, 239189, 209598, 177267, 142480, - 105576, 66945, 27114, -13271, -53400, -92348, -129065, -162474, - -191486, -215114, -232503, -243037, -246348, -242394, -231432, -214048, - -191082, -163619, -132881, -100182, -66814, -34004, -2809, 25897, - 51498, 73603, 92073, 106961, 118497, 127000, 132851, 136409, - 137987, 137791, 135930, 132384, 127051, 119749, 110286, 98485, - 84255, 67615, 48748, 27996, 5888, -16902, -39568, -61243, - -81031, -98099, -111715, -121326, -162998, -160088, -154357, -145969, - -135159, -122211, -107436, -91156, -73678, -55283, -36214, -16667, - 3198, 23260, 43411, 63547, 83543, 103238, 122414, 140790, - 158012, 173664, 187268, 198317, 206286, 210673, 211020, 206956, - 198214, 184663, 166317, 143347, 116078, 84982, 50655, 13802, - -24798, -64311, -103888, -142674, -179845, -214613, -246243, -274051, - -297418, -315773, -328608, -335464, -335942, -329700, -316476, -296086, - -268464, -233660, -191884, -143511, -89112, -29451, 34490, 101547, - 170354, 239401, 307043, 371566, 431212, 484258, 529040, 564034, - 587875, 599425, 597777, 582315, 552693, 508884, 451144, 380049, - 296447, 201490, 96577, -16612, -136189, -260017, -385787, -510997, - -633031, -749140, -856549, -952436, -1034059, -1098739, -1143998, -1167540, - -1167397, -1141901, -1089827, -1010351, -903194, -768558, -607272, -420711, - -210944, 19368, 266825, 527423, 796421, 1068545, 1337896, 1598264, - 1843121, 2066095, 2261075, 2422874, 2547443, 2632705, 2678810, 2689041, - 2669949, 2632165, 2590157, 2562709, 2571986, 2643435, 2803848, 3080521, - 3498078, 4076931, 4828788, 5754789, 6839761, 8050914, 9330877, 10598671, - 11740823, 12618964, 13055458, 12877144, 11632705, 8232321, 1712792, -8269488, - -21676128, -38124492, -56918448, -77081536, -97412152, -116545320, -133029752, -145407808, - -152301808, -152496656, -145019616, -129208872, -104771344, -71822984, -30912372, 16976826, - 70442824, 127704136, 186656480, 244947920, 300068000, 349448640, 390571840, 421080480, - 438886880, 442275104, 429992032, 401322976, 356148672, 294980192, 218969888, 129897104, - 30128484, -77446248, -189501472, -302382688, -412230048, -515113984, -607177664, -684781632, - -744644480, -783974400, -800586304, -792999936, -760514496, -703256576, -622199232, -519150624, - -396712160, -258207056, -107581408, 50718884, 211891600, 370936768, 522825024, 662669440, - 785895232, 888400000, 966700096, 1018056320, 1040574720, 1033278976, 996150976, 930138240, - 837128128, 719891072, 581993344, 427717504, 261968336, 89712808, -84335696, -255470448, - -419050304, -570668224, -706270592, -822273344, -915657792, -984053440, -1025798848, -1039984064, - -1026470080, -985886720, -919608064, -829707328, -718891392, -590417984, -447997504, -295682944, - -137750720, 21423548, 177490944, 326252736, 463778272, 586513216, 691375872, 775837824, - 837987456, 876574784, 891035520, 881494912, 848751424, 794240448, 719980032, 628500544, - 522760032, 406049152, 281887712, 153916800, 25789502, -98936256, -216899504, -325029824, - -420629824, -501444512, -565715328, -612217792, -640282304, -649796800, -641192896, -615415808, - -573878848, -518405728, -451161088, -374573216, -291251040, -203897664, -115224504, -27867474, - 55691216, 133193880, 202668432, 262478208, 311359200, 348444032, 373271968, 385785760, - 386315040, 375548096, 354492672, 324428128, 286850336, 243411744, 195858832, 145969024, - 95489384, 46079124, -742270, -43639588, -81497992, -113449472, -138889424, -157482720, - -169159888, -174103616, -172726688, -165642240, -153628176, -137586864, -118502264, -97395800, - -75283368, -53134364, -31835154, -12157406, 5266631, 19962188, 31621642, 40107016, - 45443876, 47808948, 47510056, 44961972, 40656428, 35131248, 28935710, 22599292, - 16597725, 11327856, 7077267, 4007588, 2004813, 698472, -159366, -668117, - -915026, -972592, -904574, -762742, -589613, -417127, -268777, -159451, - -97435, -84877, -119630, -195920, -305911, -440293, -589480, -743976, - -895177, -1035483, -1158746, -1260167, -1336478, -1385695, -1407139, -1401122, - -1368900, -1312362, -1233971, -1136502, -1023004, -896600, -760484, -617774, - -471538, -324684, -179997, -40056, 92731, 216208, 328430, 427747, - 512770, 582446, 636028, 673130, 693701, 698053, 686825, 660989, - 621793, 570758, 509593, 440184, 364504, 284586, 202444, 120043, - 39232, -38277, -110964, -177497, -236776, -287918, -330276, -363413, - -387116, -401358, -406302, -402269, -389735, -369301, -341693, -307732, - -268335, -224488, -177248, -127707, -76997, -26251, 23403, 70879, - 115146, 155262, 190393, 219846, 243073, 259708, 269557, 272617, - 269062, 259245, 243667, 222969, 197896, 169274, 137970, 104873, - 70854, 36751, 3337, -28682, -58696, -86176, -110690, -131889, - -149514, -163373, -173350, -179385, -181478, -179682, -174108, -164916, - -152331, -136632, -118169, -97351, -74653, -50603, -25781, -795, - 23721, 47148, 68883, 88374, 105138, 118782, 129014, 135661, - 138666, 138092, 134111, 126995, -72761, -56245, -38209, -19019, - 926, 21206, 41377, 60995, 79616, 96811, 112175, 125335, - 135964, 143783, 148571, 150171, 148491, 143510, 135276, 123908, - 109592, 92580, 73182, 51764, 28741, 4570, -20258, -45231, - -69817, -93477, -115679, -135902, -153653, -168473, -179953, -187739, - -191549, -191176, -186499, -177490, -164220, -146855, -125663, -101009, - -73349, -43220, -11236, 21933, 55569, 88924, 121238, 151753, - 179734, 204484, 225359, 241786, 253272, 259417, 259926, 254614, - 243416, 226386, 203704, 175675, 142727, 105408, 64381, 20414, - -25629, -72803, -120096, -166448, -210776, -251991, -289028, -320870, - -346577, -365309, -376354, -379149, -373302, -358603, -335043, -302817, - -262324, -214167, -159142, -98227, -32564, 36563, 107751, 179503, - 250256, 318414, 382371, 440551, 491426, 533563, 565640, 586488, - 595111, 590727, 572783, 540991, 495337, 436112, 363911, 279647, - 184541, 80117, -31824, -149225, -269813, -391137, -510624, -625621, - -733459, -831498, -917191, -988123, -1042078, -1077064, -1091376, -1083624, - -1052786, -998241, -919828, -817879, -693286, -547530, -382754, -201766, - -8088, 194084, 399903, 603998, 800600, 983813, 1147877, 1287596, - 1398749, 1478666, 1526731, 1545029, 1538843, 1517225, 1493308, 1484620, - 1512997, 1604428, 1788384, 2097022, 2563860, 3222329, 4104042, 5237042, - 6645377, 8348986, 10388584, 12857124, 15616492, 18195220, 20086854, 20833852, - 20030730, 17354698, 12586763, 5632648, -3464912, -14518786, -27198686, -41038776, - -55453300, -69758216, -83199240, -94984200, -104319184, -110446312, -112682200, -110454752, - -103337336, -91078120, -73623784, -51135812, -23998892, 7179643, 41579336, 78185368, - 115815920, 153157712, 188808416, 221324672, 249274288, 271290496, 286126560, 292708608, - 290184736, 277968256, 255773584, 223642784, 181961872, 131465504, 73229656, 8652162, - -60578956, -132528392, -205066832, -275933056, -342803008, -403363968, -455390976, -496823520, - -525839776, -540925440, -540935296, -525144960, -493290304, -445593920, -382776288, -306051584, - -217107424, -118068792, -11447024, 99925072, 212970192, 324453472, 431076864, 529578144, - 616831424, 689946368, 746362368, 783935232, 801012800, 796497984, 769895232, 721340928, - 651613760, 562127360, 454901984, 332518336, 198053008, 54997860, -92834592, -241417152, - -386622272, -524341152, -650604416, -761700160, -854286656, -925495040, -973019712, -995193152, - -991042688, -960327360, -903553472, -821968256, -717531648, -592866496, -451188992, -296220608, - -132085040, 36808156, 205888512, 370555840, 526312064, 668891968, 794386240, 899356480, - 980934400, 1036909248, 1065792000, 1066936320, 1040546496, 987467136, 909149824, 807691200, - 685777408, 546616256, 393851264, 231466848, 63682176, -105158952, -270702912, -428699744, - -575114688, -706232704, -818754752, -909882496, -977389312, -1019675904, -1035808896, -1025541568, - -989316224, -928248256, -844092096, -739190912, -616410240, -479058656, -330797152, -175539264, - -17346022, 139682832, 291517408, 434303488, 564462720, 678784448, 774506688, 849384640, - 901743936, 930519040, 935273728, 916205312, 874131520, 810461056, 727147968, 626633152, - 511772224, 385754272, 252012128, 114127448, -24266644, -159583088, -288375648, -407428352, - -513837376, -605083264, -679091392, -734279488, -769591104, -784513984, -779083840, -753872640, - -709962816, -648908288, -572682880, -483618976, -384336832, -277668320, -166575776, -54069264, - 56875640, 163397472, 262823600, 352738016, 431040544, 495996064, 546272512, 580966656, - 599617664, 602207872, 589151552, 561271552, 519765696, 466163232, 402273376, 330127520, - 251916672, 169926224, 86470040, 3825426, -75828792, -150469632, -218281248, -277698720, - -327443424, -366549120, -394378400, -410629056, -415330784, -408832544, -391780864, -365090688, - -329909184, -287574176, -239568528, -187472016, -132911848, -77513936, -22855780, 29577298, - 78431608, 122519032, 160844800, 192628240, 217316432, 234590304, 244363440, 246773968, - 242169824, 231088240, 214230352, 192431808, 166630544, 137832768, 107078304, 75406624, - 43824304, 13275079, -15386599, -41417940, -64205456, -83277544, -98311776, -109136888, - -115729656, -118206952, -116813448, -111905648, -103932808, -93415768, -80924248, -67053716, - -52402552, -37550280, -23037704, -9349536, 3099972, 13977919, 23039974, 30133750, - 35198404, 38260568, 39427008, 38874332, 36836352, 33589632, 29437968, 24696382, - 19675442, 14666438, 9928193, 5675861, 2072344, -777524, -2829749, -4100893, - -4665396, -4650187, -4237832, -3670417, -3111787, -2588999, -2111154, -1692910, - -1342761, -1064792, -858034, -718046, -637371, -606817, -616039, -654489, - -711863, -778707, -846654, -908726, -959364, -994500, -1011439, -1008780, - -986218, -944402, -884714, -809115, -719958, -619860, -511553, -397807, - -281326, -164706, -50372, 59439, 162717, 257679, 342798, 416803, - 478690, 527728, 563468, 585733, 594629, 590529, 574063, 546100, - 507723, 460200, 404950, 343501, 277458, 208453, 138112, 68013, - -346, -65582, -126442, -181831, -230824, -272671, -306807, -332846, - -350584, -359987, -361185, -354465, -340256, -319119, -291736, -258891, - -221458, -180384, -136669, -91350, -45474, -81, 43821, 85280, - 123419, 157461, 186741, 210730, 229036, 241421, 247797, 248224, - 242908, 232183, 216503, 196419, 172565, 145631, 116349, 85467, - 53736, 21886, -9380, -39409, -67596, -93402, -116356, -136059, - -152188, -164499, -172828, -177091, -177288, -173497, -165880, -154675, - -140195, -122823, -103005, -81242, -58073, -34073, -9827, 14076, - 37067, 58607, 78202, 95423, 109908, 121382, 129651, 134613, - 136254, 134645, 129937, 122348, -44011, -24892, -4829, 15720, - 36281, 56369, 75506, 93227, 109092, 122701, 133696, 141775, - 146697, 148290, 146451, 141157, 132459, 120486, 105445, 87616, - 67345, 45046, 21187, -3718, -29118, -54435, -79078, -102456, - -123992, -143137, -159380, -172271, -181421, -186524, -187359, -183802, - -175830, -163523, -147066, -126746, -102945, -76138, -46876, -15782, - 16466, 49153, 81535, 112860, 142385, 169387, 193186, 213156, - 228742, 239468, 244958, 244937, 239247, 227851, 210839, 188425, - 160956, 128901, 92851, 53506, 11664, -31790, -75908, -119691, - -162116, -202159, -238815, -271127, -298207, -319262, -333613, -340713, - -340163, -331730, -315348, -291129, -259362, -220512, -175214, -124263, - -68599, -9299, 52451, 115372, 178114, 239282, 297468, 351266, - 399319, 440334, 473120, 496614, 509913, 512295, 503248, 482484, - 449964, 405893, 350744, 285237, 210350, 127286, 37477, -57465, - -155750, -255468, -354592, -451046, -542708, -627478, -703289, -768173, - -820272, -857921, -879657, -884318, -871054, -839446, -789522, -721878, - -637689, -538829, -427837, -308012, -183306, -58351, 61766, 171575, - 265595, 338530, 385818, 403920, 391045, 347469, 276387, 184146, - 81162, -18121, -94264, -123407, -76036, 81568, 389991, 895519, - 1710701, 3002792, 4825273, 7109226, 9729646, 12512602, 15248433, 17702624, - 19630608, 20791430, 20963006, 19955790, 17626208, 13887624, 8719623, 2174045, - -5621665, -14464834, -24081046, -34131360, -44222504, -53920252, -62765096, -70290080, - -76039792, -79590136, -80567832, -78669104, -73676656, -65474260, -54058260, -39545472, - -22176940, -2317326, 19550376, 42834668, 66849928, 90834856, 113974736, 135426640, - 154347008, 169920736, 181390720, 188086896, 189453888, 185076096, 174699280, 158247904, - 135837376, 107780464, 74587640, 36960972, -4218522, -47909872, -92937136, -138019856, - -181808096, -222921312, -259989808, -291697568, -316825344, -334292320, -343195264, -342844000, - -332791264, -312856704, -283143456, -244046832, -196254272, -140736784, -78731208, -11714102, - 58632672, 130463552, 201817312, 270670080, 334992000, 392806176, 442247552, 481620896, - 509455360, 524554208, 526038368, 513381696, 486437344, 445453888, 391080448, 324360480, - 246714016, 159908576, 66019492, -32619810, -133476120, -233882016, -331106848, -422431424, - -505224224, -577016896, -635577152, -678976448, -705651136, -714454400, -704697856, -676181184, - -629208640, -564592384, -483640672, -388133216, -280282016, -162679760, -38236756, 89892360, - 218389968, 343862752, 462932736, 572329472, 668980864, 750100160, 813266368, 856496128, - 878304640, 877753856, 854486592, 808744960, 741372928, 653802560, 548023872, 426538944, - 292301664, 148644560, -806035, -152223392, -301680672, -445254848, -579131904, -699710144, - -803698816, -888209216, -950836352, -989727616, -1003637824, -991967616, -954785856, -892832832, - -807506624, -700830848, -575405568, -434342368, -281185056, -119818392, 45633172, 210913568, - 371747552, 523954144, 663558144, 786896576, 890717440, 972267648, 1029367616, 1060471360, - 1064709056, 1041912064, 992618752, 918061696, 820136128, 701350912, 564763136, 413905312, - 252702016, 85283768, -84153016, -251373152, -412193952, -562598208, -698834304, -817510976, - -915681728, -990918592, -1041372160, -1065817344, -1063683392, -1035067008, -980729024, -902074176, - -801114432, -680417408, -543040576, -392453440, -232449024, -67047936, 99603672, 263338768, - 420074528, 565914944, 697248640, 810838912, 903904448, 974187712, 1020010432, 1040314112, - 1034684224, 1003358720, 947219392, 867767552, 767083328, 647771264, 512892224, 365884480, - 210475200, 50585176, -109770824, -266585856, -415961728, -554206912, -677928256, -784115520, - -870214784, -934190464, -974573952, -990497408, -981711808, -948590080, -892113472, -813843264, - -715877760, -600795712, -471588352, -331581056, -184347104, -33615956, 116822016, 263211632, - 401927360, 529563904, 643020416, 739576448, 816957632, 873389632, 907638720, 919038784, - 907503104, 873521728, 818144448, 742948992, 649996672, 541776128, 421136352, 291211584, - 155339280, 16974000, -120401088, -253362480, -378632256, -493159552, -594195200, -679358336, - -746692608, -794711040, -822428992, -829383232, -815638016, -781777600, -728885632, -658512064, - -572628224, -473572352, -363985824, -246742688, -124873992, -1489180, 120303760, 237476976, - 347158464, 446702912, 533755744, 606308928, 662747520, 701884928, 722987456, 725786624, - 710479424, 677716736, 628580224, 564548800, 487455296, 399434400, 302864160, 200301680, - 94415504, -12084029, -116514408, -216288720, -308979968, -392380352, -464553824, -523880992, - -569095168, -599308544, -614028672, -613164032, -597019520, -566281600, -521994336, -465525920, - -398528192, -322889120, -240680240, -154100192, -65416176, 23095468, 109207648, 190798608, - 265904304, 332765472, 389868896, 435980928, 470173824, 491842976, 500715808, 496851904, - 480634304, 452752704, 414179264, 366137088, 310063456, 247567808, 180386464, 110334864, - 39258892, -31013516, -98719224, -162203968, -219962560, -270674336, -313232768, -346769088, - -370668672, -384580928, -388421408, -382367424, -366846528, -342518912, -310254080, -271102432, - -226263200, -177048848, -124847760, -71085712, -17187518, 35460372, 85545152, 131860032, - 173332944, 209050736, 238278608, 260474080, 275295552, 282605088, 282465888, 275134240, - 261046656, 240802480, 215142736, 184925744, 151100368, 114677616, 76701576, 38220244, - 257309, -36214540, -70298016, -101192744, -128213464, -150804368, -168549456, -181178720, - -188570000, -190746832, -187872144, -180238592, -168255376, -152432528, -133362752, -111701864, - -88148040, -63420712, -38239704, -13305140, 10721270, 33233146, 53694084, 71649704, - 86736888, 98689968, 107343928, 112634456, 114595192, 113352176, 109115832, 102170872, - 92864472, 81593048, 68788288, 54902676, 40395092, 25716910, 11298924, -2460449, - -15205434, -26631372, -36491212, -44599896, -50836640, -55145052, -57531268, -58060172, - -56849976, -54065368, -49909488, -44615140, -38435440, -31634326, -24477204, -17222048, - -10111227, -3364318, 2827930, 8308287, 12956318, 16690166, 19466890, 21281350, - 22163806, 22176328, 21408246, 19970784, 17991204, 15606606, 12957738, 10182934, - 7412561, 4764010, 2337587, 213264, -1551419, -2922471, -3889289, -4463602, - -4677182, -4578945, -4230953, -3704343, -3074240, -2415525, -1797252, -1280920, - -898770, -627791, -434755, -305164, -227603, -191690, -187557, -206218, - -239500, -280340, -322733, -361874, -394053, -416670, -428076, -427515, - -414945, -390943, -356535, -313106, -262250, -205705, -145243, -82626, - -19530, 42469, 101945, 157622, 208399, 253344, 291709, 322917, - 346571, 362440, 370466, 370745, 363530, 349215, 328325, 301500, - 269486, 233106, 193250, 150849, 106856, 62226, 17894, -25242, - -66343, -104637, -139433, -170137, -196253, -217395, -233281, -243746, - -248732, -248291, -242579, -231853, -216463, -196846, -173514, -147048, - -118082, -87293, -55383, -23069, 8934, 39937, 69279, 96351, - 120609, 141582, 158888, 172233, 181426, 186370, 187072, 183631, - 176235, 165155, 150734, 133374, 113527, 91685, 68363, 44092, - 19408, -5162, -29106, -51936, -73196, -92471, -109389, -123633, - -134942, -143118, -148026, -149603, -147856, -142863, -134772, -123799, - -110225, -94386, -76670, -57503, -37343, -16663, 4054, 24338, - 43732, 61811, 78191, 92535, 62535, 80267, 96515, 110869, - 122950, 132423, 139005, 142473, 142671, 139519, 133011, 123223, - 110309, 94503, 76111, 55508, 33131, 9465, -14962, -39597, - -63868, -87203, -109039, -128839, -146103, -160377, -171269, -178455, - -181688, -180805, -175730, -166482, -153172, -136001, -115264, -91340, - -64689, -35842, -5393, 26011, 57690, 88934, 119026, 147254, - 172929, 195397, 214061, 228390, 237937, 242348, 241373, 234879, - 222848, 205389, 182733, 155232, 123355, 87684, 48894, 7752, - -34905, -78188, -121168, -162899, -202440, -238873, -271320, -298971, - -321092, -337048, -346317, -348499, -343329, -330684, -310588, -283215, - -248890, -208087, -161430, -109684, -53754, 5325, 66401, 128208, - 189391, 248521, 304122, 354711, 398828, 435097, 462282, 479357, - 485586, 480607, 464520, 437982, 402277, 359398, 312090, 263877, - 219044, 182590, 160108, 157649, 181489, 237891, 332809, 471594, - 658900, 898625, 1197641, 1570523, 1996663, 2404745, 2717774, 2865679, - 2785718, 2427096, 1754169, 749686, -583221, -2219740, -4113328, -6196593, - -8383364, -10571665, -12647668, -14490343, -15976733, -16987568, -17413068, -17158614, - -16150145, -14338955, -11705745, -8263683, -4060347, 821616, 6265157, 12120884, - 18210488, 24331478, 30263100, 35773284, 40626432, 44591748, 47451940, 49011856, - 49106908, 47610828, 44442580, 39572032, 33024242, 24882062, 15286939, 4437778, - -7412170, -19960400, -32862134, -45739056, -58189596, -69800496, -80159352, -88867704, - -95554448, -99888904, -101593376, -100454560, -96333512, -89173816, -79007528, -65958664, - -50244076, -32171454, -12134525, 9394608, 31875820, 54713840, 77273336, 98895824, - 118918056, 136691248, 151600704, 163085296, 170656112, 173913744, 172563664, 166429120, - 155461200, 139745456, 119505000, 95099632, 67021116, 35884416, 2415097, -32566908, - -68166792, -103437232, -137402992, -169087216, -197538720, -221859376, -241231120, -254941424, - -262406848, -263193680, -257034992, -243843760, -223721280, -196960640, -164045024, -125640616, - -82584344, -35866404, 13391901, 63964612, 114551216, 163809728, 210391808, 252979168, - 290320064, 321265088, 344801344, 360083392, 366461088, 363502304, 351010944, 329038400, - 297889248, 258119712, 210529696, 156147840, 96210000, 32131786, -34524592, -102088152, - -168820816, -232961936, -292774464, -346591552, -392862560, -430196672, -457403712, -473530208, - -477890048, -470088800, -450040832, -417978368, -374452640, -320326336, -256757808, -185176992, - -107253736, -24859086, 59979564, 145128320, 228400464, 307612608, 380641824, 445482432, - 500300512, 543485312, 573695616, 589899584, 591407872, 577897856, 549428800, 506447456, - 449783328, 380634208, 300541536, 211356352, 115196864, 14397969, -88545520, -191040832, - -290462720, -384220896, -469827680, -544963968, -607541824, -655762304, -688166080, -703676928, - -701634816, -681819648, -644463424, -590250752, -520308160, -436181376, -339801440, -233440544, - -119658328, -1240033, 118872048, 237652048, 352067200, 459155616, 556103232, 640318080, - 709499520, 761700928, 795384128, 809463808, 803340864, 776923520, 730635776, 665412608, - 582681792, 484333184, 372675584, 250382144, 120426184, -13991622, -149522608, -282754144, - -410296096, -528867712, -635382464, -727028736, -801344512, -856283200, -890270272, -902247552, - -891705280, -858699904, -803857856, -728364736, -633940096, -522797984, -397595008, -261366368, - -117451720, 30587386, 179056320, 324220320, 462399104, 590061056, 703913984, 800990592, - 878726208, 935027008, 968326336, 977628096, 962536000, 923267520, 860652416, 776115520, - 671644160, 549741504, 413365632, 265857680, 110858864, -47779968, -206094880, -360108800, - -505932192, -639862208, -758477376, -858725824, -938004160, -994225728, -1025875712, -1032052032, - -1012490816, -967575808, -898331200, -806398464, -693996736, -563869056, -419215008, -263610912, - -100920864, 64800176, 229408368, 388775616, 538893952, 675977408, 796558208, 897575488, - 976453568, 1031168128, 1060298880, 1063066560, 1039353856, 989709440, 915335680, 818058560, - 700282816, 564931648, 415373344, 255336384, 88815592, -80029120, -246977680, -407857120, - -558646720, -695580608, -815240832, -914661376, -991426624, -1043686208, -1070172608, -1070248192, - -1043923520, -991857408, -915341120, -816266432, -697079168, -560719104, -410547744, -250265472, - -83820864, 84686600, 251107216, 411343136, 561449088, 697729408, 816829056, 915815936, - 992253184, 1044259072, 1070553344, 1070488704, 1044066752, 991938048, 915385920, 816295104, - 697105216, 560750656, 410588608, 250316144, 83879304, -84624008, -251044992, -411286048, - -561401792, -697695936, -816812672, -915819008, -992277056, -1044304128, -1070619200, -1070574144, - -1044169920, -992056576, -915517184, -816436096, -697252864, -560901952, -410740480, -250465744, - -84023984, 84486696, 250917232, 411169760, 561298496, 697607040, 816739008, 915761280, - 992235520, 1044278912, 1070609856, 1070580032, 1044190208, 992090048, 915562432, 816491584, - 697316864, 560972608, 410815936, 250544048, 84103240, -84408312, -250841440, -411098144, - -561232512, -697547840, -816687680, -915718464, -992201920, -1044254720, -1070595200, -1070574848, - -1044194112, -992102592, -915582912, -816519232, -697350784, -561011712, -410859200, -250590352, - -84151408, 84359424, 250792960, 411051168, 561188032, 697506752, 816650880, 915686656, - 992175616, 1044234432, 1070581248, 1070567360, 1044193024, 992107776, 915594112, 816535872, - 697372352, 561037568, 410888512, 250622304, 84185136, -84324824, -250758368, -411017408, - -561155904, -697477056, -816624192, -915663552, -992156544, -1044219712, -1070571008, -1070561728, - -1044192000, -992111168, -915601728, -816547392, -697387392, -561055616, -410909120, -250644896, - -84209144, 84299992, 250733312, 410992736, 561132224, 697454848, 816603968, 915645824, - 992141696, 1044208000, 1070562816, 1070557056, 1044191040, 992113920, 915607936, 816556928, - 697399936, 561070784, 410926464, 250663904, 84229272, -84279312, -250712656, -410972640, - -561113216, -697437440, -816588608, -915632832, -992131328, -1044200448, -1070558208, -1070555520, - -1044192384, -992118080, -915614784, -816566208, -697411328, -561084032, -410941184, -250679696, - -84245752, 84262552, 250696016, 410956544, 561098048, 697423552, 816576320, 915622464, - 992123200, 1044194816, 1070555200 +const Word32 ivas_fb_fr_12band_1ms_re_fx[IVAS_FB_12_1MS_LEN] = { + 1046768256, 1012312512, 944113536, 843565952, 712700800, 554033920, 370399360, 163534048, -67588040, + -313003296, -547361792, -745791424, -889130944, -964720960, -967822016, -901839040, -777730304, + -612432896, -426573984, -241764928, -77701744, 50405768, 134107528, 173698992, 183571312, + 181978912, 174963648, 163434880, 148881184, 132470640, 115304208, 98219512, 81912736, + 66862960, 53409868, 41724844, 31871182, 23797162, 17385436, 12455156, 8801240, + 6197829, 4427144, 3280128, 2575327, 2155348, 1897329, 1705752, 1516863, + 1289431, 1005694, 661856, 267796, -161263, -604780, -1043282, -1457411, + -1832285, -2155534, -2420027, -2621275, -2759126, -2835035, -2853297, -2818571, + -2737039, -2614376, -2456980, -2270381, -2060530, -1832512, -1591794, -1343094, + -1091494, -841376, -597362, -363290, -143021, 60510, 244561, 407408, + 547618, 664738, 758550, 829643, 878668, 906840, 915250, 905346, + 878343, 835721, 778738, 708948, 627794, 537107, 438729, 334948, + 228103, 120925, 16090, -83524, -175327, -256811, -326026, -381381, + -422046, -447703, -458837, -456405, -442013, -417522, -385138, -347000, + -305255, -261681, -217812, -174648, -132866, -92642, -53935, -16402, + 20279, 56463, 92235, 127494, 161728, 194173, 223691, 249012, + 268700, 281445, 286068, 281804, 268278, 245720, 214858, 177029, + 133974, 87839, 40901, -4492, -46220, -82436, -111817, -133546, + -147456, -153913, -153846, -148528, -139528, -128444, -116827, -105934, + -96699, -89563, -84536, -81138, -78561, -75704, -71400, -64501, + -54108, -39627, -20946, 1593, 27122, 54374, 81719, 107372, + 129497, 146446, 156855, 159848, 155068, 142780, 123803, 99496, + 71589, 42078, 8610925, 16407290, 31915518, 54983844, 85416624, 123087880, + 168063984, 221958576, 289536032, 364878560, 426914240, 455184448, 434995104, 358099712, + 224036640, 40240900, -178615296, -412308800, -637390400, -829991424, -968687232, -1037118016, + -1026013056, -934381184, -769721024, -547208704, -287987072, -16727445, 241188016, 462583776, + 629070144, 729071296, 758930560, 723116864, 633312128, 506752128, 363680000, 224696192, + 107612800, 25033840, -24212064, -54589336, -75035176, -87485160, -93580896, -94591848, + -91737704, -86038536, -78437624, -69711224, -60533488, -51423856, -42794000, -34920752, + -27987240, -22072318, -17188296, -13279352, -10254646, -7989723, -6353249, -5207335, + -4426934, -3897128, -3525509, -3236283, -2977071, -2710878, -2419337, -2094076, + -1738366, -1359253, -969076, -579170, -201992, 153445, 478767, 769398, + 1021418, 1233894, 1405828, 1538184, 1631253, 1686663, 1705249, 1689093, + 1639776, 1560317, 1453594, 1324024, 1175972, 1015086, 846649, 676618, + 509991, 351706, 205173, 73207, -43142, -143513, -229073, -301290, + -362531, -414799, -460247, -500043, -534968, -564551, -587849, -602888, + -607619, -599579, -576918, -538114, -482894, -411845, -327078, -231622, + -129783, -26319, 73437, 164513, 242258, 303205, 344935, 366711, + 369107, 354325, 325569, 287088, 243371, 199057, 158131, 123882, + 98274, 82114, 74715, 74333, 78122, 82791, 84734, 80757, + 68210, 45592, 12513, -29958, -79606, -133015, -186134, -234445, + -273650, -299897, -310406, -303565, -279332, -239075, -185665, -123028, + -55984, 10396, 12276729, 12693837, 13547048, 14871155, 16707203, 19094012, + 22050984, 25567530, 29581572, 33971516, 38534384, 42985632, 46940136, 49924776, + 51363228, 50604824, 46909464, 39493740, 27503144, 10070768, -13759776, -44999620, + -84980336, -136135984, -207135712, -303422240, -412817600, -514972896, -589851392, -619651584, + -591583168, -499579936, -345470464, -138966128, 103208400, 359174656, 604351488, 814326528, + 967700992, 1048627328, 1048680832, 967863296, 814603776, 604752128, 359708672, 103884792, + -138140928, -344495008, -498458752, -590328384, -618282624, -588395136, -513462144, -411289888, + -301917376, -205694144, -134796400, -83778624, -43967052, -12923312, 10688964, 27884292, + 39622020, 46770036, 50183460, 50644772, 48893804, 45580600, 41282912, 36475948, + 31549672, 26793770, 22418028, 18548592, 15250408, 12530037, 10357491, 8671122, + 7396225, 6448686, 5748701, 5221465, 4805724, 4451326, 4123487, 3798131, + 3463431, 3114322, 2752946, 2383612, 2013354, 1648090, 1293873, 954378, + 632818, 330406, 48532, -212349, -450755, -665332, -853410, -1012414, + -1138953, -1230412, -1284349, -1300013, -1277722, -1220043, -1130902, -1016282, + -883017, -739061, -592113, -449695, -317863, -201395, -102837, -23014, + 39453, 87271, 124545, 155673, 185224, 216854, 253275, 295449, + 342868, 393176, 442827, 487113, 521090, 539819, 539332, 516817, + 471355, 403816, 317194, 216106, 106711, -4112, -109126, -201659, + -275976, -328059, -355725, -359045, -340068, -302808, -252589, -195699, + -138533, -87141, -46428, -19866, -8984, -13439, -30918, -57611, + -88487, -118040, -140755, -151891, -147872, -126858, -88834, -35798, + 28549, 99021, 169585, 233841, 285797, 320360, 333987, 324942, + 293611, 242374, 175498, 98630, 18357, -58534, -125609, -177509, + -210361, -222240, -213241, -185532, -143021, -91031, -35654, 16794, + 60506, 90695, 104157, 99518, 77443, 40482, -7123, -59963, + -111945, -157005, -189668, -205697, -202469, -179335, -137639, -80671, + -13290, 58484, 128123, 189173, 235954, 264066, 270883, 255765, + 220174, 2505037, 2442157, 2316154, 2126672, 1874467, 1561489, 1192761, + 775600, 321304, -157412, -645618, -1131069, -1604363, -2065994, -2526609, + -3015154, -3577470, -4283816, -5223516, -6510031, -8269471, -10642073, -13763168, + -17761360, -22731886, -28733746, -35756756, -43722016, -52444716, -61644104, -70903304, + -79696304, -87342288, -93058336, -95895816, -94830640, -88641344, -76058616, -55443336, + -24863958, 24611116, 107440320, 224788944, 364047616, 507399776, 634242176, 724330048, + 760427264, 730852288, 631136576, 464936832, 243827808, -13803173, -284784032, -543737088, + -765995008, -930417472, -1021827456, -1032720576, -964074624, -825139200, -632243584, -406773696, + -172552176, 47020828, 231770176, 367063072, 445488224, 467504928, 441322720, 381553248, + 308519520, 243096544, 190940560, 146958368, 109144704, 76984176, 50110068, 28195132, + 10859917, -2331860, -11867127, -18267046, -22063578, -23780578, -23911906, -22907786, + -21160858, -19000796, -16689673, -14424574, -12340740, -10519832, -8997765, -7775391, + -6827615, -6113435, -5583605, -5187945, -4880011, -4620898, -4380691, -4139162, + -3884798, -3613535, -3326639, -3028821, -2726195, -2424818, -2129499, -1843272, + -1567228, -1300854, -1042591, -790584, -543428, -300799, -63891, 164435, + 379755, 576491, 748467, 889663, 994911, 1060624, 1085268, 1069727, + 1017300, 933554, 825817, 702603, 572797, 444929, 326372, 222801, + 137707, 72284, 25430, -5886, -26190, -40792, -55143, -74076, + -101256, -138661, -186386, -242548, -303550, -364410, -419384, -462555, + -488576, -493231, -474014, -430404, -364059, -278663, -179684, -73826, + 31531, 129079, 212203, 275656, 315980, 331857, 324141, 295780, + 251424, 196978, 138929, 83734, 37113, 3535, -14258, -15450, + -1229, 25423, 60045, 97246, 131265, 156654, 168829, 164631, + 142633, 103366, 49247, -15601, -85794, -155177, -217478, -266899, + -298743, -309847, -298949, -266783, -216054, -151145, -77727, -2174, + 69017, 702811, 654136, 559557, 424419, 255932, 62727, -146313, + -362395, -578054, -786994, -985086, -1169469, -1339221, -1493760, -1633415, + -1757450, -1864970, -1953010, -2018235, -2055396, -2060043, -2027296, -1955369, + -1844129, -1698799, -1527422, -1343910, -1163448, -1004247, -880298, -801810, + -765486, -754582, -727814, -620985, -336399, 251272, 1302991, 3002489, + 5560181, 9191239, 14115464, 20525480, 28584940, 38387408, 49958096, 63204572, + 77930464, 93777392, 110263472, 126708904, 142322784, 156083648, 166946144, 173586320, + 175308576, 166325584, 128680304, 48303544, -74757040, -231715952, -407042976, -580775616, + -731094848, -837272320, -882366976, -855569984, -753729472, -582012992, -353498368, -87845872, + 190881904, 456905760, 685667520, 856595200, 955419584, 975703808, 919454400, 796692096, + 624085824, 422776032, 215700912, 24714716, -132116288, -242736960, -302620672, -315365760, + -293500640, -258619744, -225315280, -194015376, -163910608, -135501680, -109209736, -85466480, + -64529184, -46551644, -31533836, -19377918, -9878438, -2769905, 2268515, 5573895, + 7492172, 8348992, 8445734, 8040905, 7351921, 6546074, 5747758, 5036624, + 4458304, 4026662, 3735443, 3561663, 3475902, 3444629, 3437763, 3428836, + 3399492, 3337488, 3238697, 3103696, 2938339, 2749967, 2547660, 2338971, + 2130630, 1926285, 1727949, 1534741, 1344902, 1155176, 962956, 765794, + 563232, 356016, 147339, -58398, -254956, -435840, -594040, -723684, + -819800, -879714, -902536, -890086, -845966, -775986, -686897, -586473, + -482133, -380953, -288451, -208799, -143979, -94350, -58234, -32830, + -14133, 1978, 19701, 42276, 72069, 109808, 154947, 205272, + 257581, 307614, 350943, 383061, 400284, 399785, 380309, 341971, + 286657, 217523, 139066, 56385, -24953, -99742, -163283, -212106, + -243951, -258230, -255733, -167174, -239722, -322173, -408810, -492821, + -566516, -622391, -653378, -653921, -619965, -549788, -443508, -303565, + -133727, 60691, 274135, 500595, 734943, 972407, 1209697, 1443978, + 1673718, 1897211, 2113333, 2319888, 2514652, 2693915, 2854207, 2991285, + 3102696, 3187122, 3247515, 3290252, 3328147, 3378477, 3464934, 3613501, + 3852565, 4205968, 4691138, 5309438, 6043184, 6844465, 7633047, 8285794, + 8638327, 8477588, 7550391, 5561188, 2190063, -2903797, -10053462, -19577218, + -31739716, -46747292, -64700276, -85602512, -109304912, -135555296, -163926944, -194002976, + -225285872, -258586768, -293477632, -315364832, -302650912, -242803328, -132218944, 24580560, + 215544720, 422611008, 623927680, 796557504, 919359168, 975661312, 955439360, 856681664, + 685819520, 457116384, 191139072, -87558504, -353200000, -581723904, -753469440, -855356160, + -882212736, -837186048, -731079168, -580827520, -407153984, -231873488, -74945544, 48100840, + 128479736, 166141328, 175151264, 173462112, 166856272, 156024384, 142286160, 126683672, + 110236760, 93736176, 77863432, 63103528, 49819328, 38212324, 28380444, 20303444, + 13891988, 8985083, 5391207, 2889572, 1262319, 294475, -203348, -398749, + -423662, -382151, -343523, -352875, -428668, -574135, -776792, -1018896, + -1276918, -1529859, -1757571, -1946540, -2086827, -2175642, -2213314, -2205436, + -2158564, -2081784, -1982822, -1869689, -1747600, -1621008, -1491391, -1359644, + -1224514, -1085096, -939557, -787433, -628324, -463767, -295726, -127991, + 35529, 189782, 330335, 452518, 553054, 629169, 679950, 705285, + 706896, 687113, 649626, 598183, 537192, 470470, 401849, 334088, + 269582, 209498, 154619, 104683, 59308, 17469, -21588, -58843, + -94673, -129406, -162639, -193876, -221997, -245959, -264363, -276167, + -280285, -276237, -263718, -243144, -215155, -181048, -225261, -273555, + -307889, -326103, -327476, -312684, -283609, -243038, -194256, -140631, + -85182, -30244, 22798, 73608, 122885, 172169, 223570, 279366, + 341593, 411622, 489814, 575248, 665622, 757256, 845294, 923987, + 987121, 1028456, 1042203, 1023430, 968397, 874758, 741642, 569587, + 360379, 116796, -157659, -459031, -783110, -1125546, -1481872, -1847416, + -2217186, -2585716, -2947037, -3294742, -3622346, -3923849, -4194709, -4432970, + -4640760, -4825675, -5002266, -5192922, -5428408, -5747161, -6193793, -6815752, + -7658969, -8761350, -10145511, -11809549, -13717971, -15791409, -17898084, -19845242, + -21374384, -22157722, -21800466, -19845174, -15783279, -9068449, 863064, 14571969, + 32592328, 55410852, 83458416, 117107272, 156758688, 202942128, 257651808, 325933440, + 402044000, 464971200, 494205696, 474891008, 398522784, 264288720, 79206760, -142533824, + -381224512, -613975168, -817483264, -970950784, -1058690624, -1072345920, -1012679872, -893613760, + -734287744, -546547584, -339769856, -124623176, 88170360, 288225568, 466194112, 614172160, + 726163904, 798321728, 829131584, 819397568, 772133120, 692285376, 586377152, 462039040, + 327503712, 191064064, 60554008, -57130884, -156432848, -233429280, -286014272, -313941504, + -318749984, -303544416, -272698496, -231426688, -185371904, -140057616, -100631488, -69996648, + -46622364, -28166424, -13810469, -2980571, 4834391, 10133794, 13384151, 15027667, + 15460742, 15036408, 14051635, 12751812, 11326396, 9916592, 8616869, 7484565, + 6544389, 5798046, 5229236, 4811721, 4513168, 4300801, 4143382, 4014381, + 3892172, 3761242, 3611156, 3436579, 3235728, 3009947, 2762235, 2496885, + 2218419, 1931526, 1640448, 1349202, 1061301, 780105, 508675, 250099, + 7326, -216639, -418984, -597023, -748502, -871609, -965247, -1029025, + -1063439, -1069768, -1050128, -1007269, -944511, -865478, -773983, -673761, + -568371, -460991, -354385, -250799, -152007, -59299, 26411, 104546, + 174730, 236744, 290418, 335608, 372145, 399853, 418548, 428095, + 428430, 419636, 401963, 375881, 342083, 301499, 255265, 204699, + 151239, 96397, 41685, -11436, -61625, -107696, -148661, -183744, + -212399, -234301, -249338, -257586, -259295, -171383, -167771, -160946, + -151648, -140875, -129741, -119346, -110602, -104127, -100108, -98276, + -97857, -97667, -96155, -91604, -82246, -66504, -43110, -11334, + 28976, 77253, 132282, 192171, 254555, 316653, 375561, 428343, + 472340, 505222, 525246, 531204, 522588, 499415, 462302, 412189, + 350367, 278167, 197008, 108113, 12645, -88501, -194453, -304491, + -417705, -533098, -649202, -764225, -875703, -980757, -1075829, -1157086, + -1220253, -1261142, -1275529, -1259757, -1210576, -1125738, -1003720, -844248, + -647867, -416383, -152288, 140834, 458975, 797247, 1150575, 1513140, + 1879071, 2241774, 2594688, 2930577, 3242477, 3523085, 3766061, 3965621, + 4118279, 4222622, 4281408, 4301274, 4294860, 4279931, 4280984, 4327080, + 4452293, 4691546, 5079427, 5643594, 6401946, 7353690, 8475606, 9711576, + 10969534, 12110916, 12950640, 13248182, 12713298, 10999818, 7719470, 2437137, + -5306709, -16007364, -30173754, -48382488, -71457888, -101754088, -140816912, -185763344, + -231466336, -272424224, -303010560, -318021792, -313081312, -285067456, -232401024, -155266144, + -55676148, 62564504, 194048000, 332049728, 468930560, 596597632, 707022848, 792757376, + 847434880, 866203136, 846081856, 786193920, 687883392, 554677120, 392130080, 207514704, + 9432382, -192707744, -389200480, -570675136, -728479808, -856350656, -952308800, -1015864832, + -1046220032, -1043342848, -1008126784, -942413952, -848923648, -731177152, -593366784, -440223744, + -276851936, -108565096, 59292484, 221513920, 373199296, 509904800, 627780928, 723682304, + 795257728, 841006144, 860308096, 853421632, 821452480, 766292160, 690533568, 597361024, + 490425248, 373702496, 251347920, 127544600, 6357648, -108405296, -213318272, -305445280, + -382425728, -442537280, -484731648, -508645408, -514583008, -503476768, -476822816, -436599136, + -385166592, -325160416, -259373680, -190640560, -121721768, -55198692, 6621388, 61783672, + 108746912, 146423216, 174197536, 191924704, 199906864, 198850976, 189810704, 174114128, + 153282784, 128943984, 102742896, 76256368, 50914548, 27932052, 8253544, -7485707, + -18981258, -26263536, -29686804, -29902128, -27874808, -24904632, -21873452, -18924710, + -16109369, -13513449, -11193274, -9184409, -7497119, -6124396, -5043505, -4222392, + -3622104, -3201531, -2919256, -2736657, -2618792, -2536063, -2464195, -2384826, + -2284834, -2156265, -1995319, -1801974, -1578908, -1331064, -1064692, -787000, + -505396, -227288, 40476, 291657, 521006, 724191, 898044, 1040397, + 1150221, 1227397, 1272778, 1287922, 1275099, 1237007, 1176756, 1097593, + 1002895, 895923, 779853, 657586, 531818, 404912, 279016, 155978, + 37491, -74965, -179989, -276315, -362698, -438012, -501167, -551237, + -587418, -609171, -616196, -608571, -586708, -551466, -504065, -446144, + -379632, -306754, -229859, -151391, -73706, 962, 70672, 133776, + 189046, 235630, 273114, 301432, 320873, 331952, 335393, 331988, + 322579, 307941, 288792, 265710, 239189, 209598, 177267, 142480, + 105576, 66945, 27114, -13271, -53400, -92348, -129065, -162474, + -191486, -215114, -232503, -243037, -246348, -242394, -231432, -214048, + -191082, -163619, -132881, -100182, -66814, -34004, -2809, 25897, + 51498, 73603, 92073, 106961, 118497, 127000, 132851, 136409, + 137987, 137791, 135930, 132384, 127051, 119749, 110286, 98485, + 84255, 67615, 48748, 27996, 5888, -16902, -39568, -61243, + -81031, -98099, -111715, -121326, -162998, -160088, -154357, -145969, + -135159, -122211, -107436, -91156, -73678, -55283, -36214, -16667, + 3198, 23260, 43411, 63547, 83543, 103238, 122414, 140790, + 158012, 173664, 187268, 198317, 206286, 210673, 211020, 206956, + 198214, 184663, 166317, 143347, 116078, 84982, 50655, 13802, + -24798, -64311, -103888, -142674, -179845, -214613, -246243, -274051, + -297418, -315773, -328608, -335464, -335942, -329700, -316476, -296086, + -268464, -233660, -191884, -143511, -89112, -29451, 34490, 101547, + 170354, 239401, 307043, 371566, 431212, 484258, 529040, 564034, + 587875, 599425, 597777, 582315, 552693, 508884, 451144, 380049, + 296447, 201490, 96577, -16612, -136189, -260017, -385787, -510997, + -633031, -749140, -856549, -952436, -1034059, -1098739, -1143998, -1167540, + -1167397, -1141901, -1089827, -1010351, -903194, -768558, -607272, -420711, + -210944, 19368, 266825, 527423, 796421, 1068545, 1337896, 1598264, + 1843121, 2066095, 2261075, 2422874, 2547443, 2632705, 2678810, 2689041, + 2669949, 2632165, 2590157, 2562709, 2571986, 2643435, 2803848, 3080521, + 3498078, 4076931, 4828788, 5754789, 6839761, 8050914, 9330877, 10598671, + 11740823, 12618964, 13055458, 12877144, 11632705, 8232321, 1712792, -8269488, + -21676128, -38124492, -56918448, -77081536, -97412152, -116545320, -133029752, -145407808, + -152301808, -152496656, -145019616, -129208872, -104771344, -71822984, -30912372, 16976826, + 70442824, 127704136, 186656480, 244947920, 300068000, 349448640, 390571840, 421080480, + 438886880, 442275104, 429992032, 401322976, 356148672, 294980192, 218969888, 129897104, + 30128484, -77446248, -189501472, -302382688, -412230048, -515113984, -607177664, -684781632, + -744644480, -783974400, -800586304, -792999936, -760514496, -703256576, -622199232, -519150624, + -396712160, -258207056, -107581408, 50718884, 211891600, 370936768, 522825024, 662669440, + 785895232, 888400000, 966700096, 1018056320, 1040574720, 1033278976, 996150976, 930138240, + 837128128, 719891072, 581993344, 427717504, 261968336, 89712808, -84335696, -255470448, + -419050304, -570668224, -706270592, -822273344, -915657792, -984053440, -1025798848, -1039984064, + -1026470080, -985886720, -919608064, -829707328, -718891392, -590417984, -447997504, -295682944, + -137750720, 21423548, 177490944, 326252736, 463778272, 586513216, 691375872, 775837824, + 837987456, 876574784, 891035520, 881494912, 848751424, 794240448, 719980032, 628500544, + 522760032, 406049152, 281887712, 153916800, 25789502, -98936256, -216899504, -325029824, + -420629824, -501444512, -565715328, -612217792, -640282304, -649796800, -641192896, -615415808, + -573878848, -518405728, -451161088, -374573216, -291251040, -203897664, -115224504, -27867474, + 55691216, 133193880, 202668432, 262478208, 311359200, 348444032, 373271968, 385785760, + 386315040, 375548096, 354492672, 324428128, 286850336, 243411744, 195858832, 145969024, + 95489384, 46079124, -742270, -43639588, -81497992, -113449472, -138889424, -157482720, + -169159888, -174103616, -172726688, -165642240, -153628176, -137586864, -118502264, -97395800, + -75283368, -53134364, -31835154, -12157406, 5266631, 19962188, 31621642, 40107016, + 45443876, 47808948, 47510056, 44961972, 40656428, 35131248, 28935710, 22599292, + 16597725, 11327856, 7077267, 4007588, 2004813, 698472, -159366, -668117, + -915026, -972592, -904574, -762742, -589613, -417127, -268777, -159451, + -97435, -84877, -119630, -195920, -305911, -440293, -589480, -743976, + -895177, -1035483, -1158746, -1260167, -1336478, -1385695, -1407139, -1401122, + -1368900, -1312362, -1233971, -1136502, -1023004, -896600, -760484, -617774, + -471538, -324684, -179997, -40056, 92731, 216208, 328430, 427747, + 512770, 582446, 636028, 673130, 693701, 698053, 686825, 660989, + 621793, 570758, 509593, 440184, 364504, 284586, 202444, 120043, + 39232, -38277, -110964, -177497, -236776, -287918, -330276, -363413, + -387116, -401358, -406302, -402269, -389735, -369301, -341693, -307732, + -268335, -224488, -177248, -127707, -76997, -26251, 23403, 70879, + 115146, 155262, 190393, 219846, 243073, 259708, 269557, 272617, + 269062, 259245, 243667, 222969, 197896, 169274, 137970, 104873, + 70854, 36751, 3337, -28682, -58696, -86176, -110690, -131889, + -149514, -163373, -173350, -179385, -181478, -179682, -174108, -164916, + -152331, -136632, -118169, -97351, -74653, -50603, -25781, -795, + 23721, 47148, 68883, 88374, 105138, 118782, 129014, 135661, + 138666, 138092, 134111, 126995, -72761, -56245, -38209, -19019, + 926, 21206, 41377, 60995, 79616, 96811, 112175, 125335, + 135964, 143783, 148571, 150171, 148491, 143510, 135276, 123908, + 109592, 92580, 73182, 51764, 28741, 4570, -20258, -45231, + -69817, -93477, -115679, -135902, -153653, -168473, -179953, -187739, + -191549, -191176, -186499, -177490, -164220, -146855, -125663, -101009, + -73349, -43220, -11236, 21933, 55569, 88924, 121238, 151753, + 179734, 204484, 225359, 241786, 253272, 259417, 259926, 254614, + 243416, 226386, 203704, 175675, 142727, 105408, 64381, 20414, + -25629, -72803, -120096, -166448, -210776, -251991, -289028, -320870, + -346577, -365309, -376354, -379149, -373302, -358603, -335043, -302817, + -262324, -214167, -159142, -98227, -32564, 36563, 107751, 179503, + 250256, 318414, 382371, 440551, 491426, 533563, 565640, 586488, + 595111, 590727, 572783, 540991, 495337, 436112, 363911, 279647, + 184541, 80117, -31824, -149225, -269813, -391137, -510624, -625621, + -733459, -831498, -917191, -988123, -1042078, -1077064, -1091376, -1083624, + -1052786, -998241, -919828, -817879, -693286, -547530, -382754, -201766, + -8088, 194084, 399903, 603998, 800600, 983813, 1147877, 1287596, + 1398749, 1478666, 1526731, 1545029, 1538843, 1517225, 1493308, 1484620, + 1512997, 1604428, 1788384, 2097022, 2563860, 3222329, 4104042, 5237042, + 6645377, 8348986, 10388584, 12857124, 15616492, 18195220, 20086854, 20833852, + 20030730, 17354698, 12586763, 5632648, -3464912, -14518786, -27198686, -41038776, + -55453300, -69758216, -83199240, -94984200, -104319184, -110446312, -112682200, -110454752, + -103337336, -91078120, -73623784, -51135812, -23998892, 7179643, 41579336, 78185368, + 115815920, 153157712, 188808416, 221324672, 249274288, 271290496, 286126560, 292708608, + 290184736, 277968256, 255773584, 223642784, 181961872, 131465504, 73229656, 8652162, + -60578956, -132528392, -205066832, -275933056, -342803008, -403363968, -455390976, -496823520, + -525839776, -540925440, -540935296, -525144960, -493290304, -445593920, -382776288, -306051584, + -217107424, -118068792, -11447024, 99925072, 212970192, 324453472, 431076864, 529578144, + 616831424, 689946368, 746362368, 783935232, 801012800, 796497984, 769895232, 721340928, + 651613760, 562127360, 454901984, 332518336, 198053008, 54997860, -92834592, -241417152, + -386622272, -524341152, -650604416, -761700160, -854286656, -925495040, -973019712, -995193152, + -991042688, -960327360, -903553472, -821968256, -717531648, -592866496, -451188992, -296220608, + -132085040, 36808156, 205888512, 370555840, 526312064, 668891968, 794386240, 899356480, + 980934400, 1036909248, 1065792000, 1066936320, 1040546496, 987467136, 909149824, 807691200, + 685777408, 546616256, 393851264, 231466848, 63682176, -105158952, -270702912, -428699744, + -575114688, -706232704, -818754752, -909882496, -977389312, -1019675904, -1035808896, -1025541568, + -989316224, -928248256, -844092096, -739190912, -616410240, -479058656, -330797152, -175539264, + -17346022, 139682832, 291517408, 434303488, 564462720, 678784448, 774506688, 849384640, + 901743936, 930519040, 935273728, 916205312, 874131520, 810461056, 727147968, 626633152, + 511772224, 385754272, 252012128, 114127448, -24266644, -159583088, -288375648, -407428352, + -513837376, -605083264, -679091392, -734279488, -769591104, -784513984, -779083840, -753872640, + -709962816, -648908288, -572682880, -483618976, -384336832, -277668320, -166575776, -54069264, + 56875640, 163397472, 262823600, 352738016, 431040544, 495996064, 546272512, 580966656, + 599617664, 602207872, 589151552, 561271552, 519765696, 466163232, 402273376, 330127520, + 251916672, 169926224, 86470040, 3825426, -75828792, -150469632, -218281248, -277698720, + -327443424, -366549120, -394378400, -410629056, -415330784, -408832544, -391780864, -365090688, + -329909184, -287574176, -239568528, -187472016, -132911848, -77513936, -22855780, 29577298, + 78431608, 122519032, 160844800, 192628240, 217316432, 234590304, 244363440, 246773968, + 242169824, 231088240, 214230352, 192431808, 166630544, 137832768, 107078304, 75406624, + 43824304, 13275079, -15386599, -41417940, -64205456, -83277544, -98311776, -109136888, + -115729656, -118206952, -116813448, -111905648, -103932808, -93415768, -80924248, -67053716, + -52402552, -37550280, -23037704, -9349536, 3099972, 13977919, 23039974, 30133750, + 35198404, 38260568, 39427008, 38874332, 36836352, 33589632, 29437968, 24696382, + 19675442, 14666438, 9928193, 5675861, 2072344, -777524, -2829749, -4100893, + -4665396, -4650187, -4237832, -3670417, -3111787, -2588999, -2111154, -1692910, + -1342761, -1064792, -858034, -718046, -637371, -606817, -616039, -654489, + -711863, -778707, -846654, -908726, -959364, -994500, -1011439, -1008780, + -986218, -944402, -884714, -809115, -719958, -619860, -511553, -397807, + -281326, -164706, -50372, 59439, 162717, 257679, 342798, 416803, + 478690, 527728, 563468, 585733, 594629, 590529, 574063, 546100, + 507723, 460200, 404950, 343501, 277458, 208453, 138112, 68013, + -346, -65582, -126442, -181831, -230824, -272671, -306807, -332846, + -350584, -359987, -361185, -354465, -340256, -319119, -291736, -258891, + -221458, -180384, -136669, -91350, -45474, -81, 43821, 85280, + 123419, 157461, 186741, 210730, 229036, 241421, 247797, 248224, + 242908, 232183, 216503, 196419, 172565, 145631, 116349, 85467, + 53736, 21886, -9380, -39409, -67596, -93402, -116356, -136059, + -152188, -164499, -172828, -177091, -177288, -173497, -165880, -154675, + -140195, -122823, -103005, -81242, -58073, -34073, -9827, 14076, + 37067, 58607, 78202, 95423, 109908, 121382, 129651, 134613, + 136254, 134645, 129937, 122348, -44011, -24892, -4829, 15720, + 36281, 56369, 75506, 93227, 109092, 122701, 133696, 141775, + 146697, 148290, 146451, 141157, 132459, 120486, 105445, 87616, + 67345, 45046, 21187, -3718, -29118, -54435, -79078, -102456, + -123992, -143137, -159380, -172271, -181421, -186524, -187359, -183802, + -175830, -163523, -147066, -126746, -102945, -76138, -46876, -15782, + 16466, 49153, 81535, 112860, 142385, 169387, 193186, 213156, + 228742, 239468, 244958, 244937, 239247, 227851, 210839, 188425, + 160956, 128901, 92851, 53506, 11664, -31790, -75908, -119691, + -162116, -202159, -238815, -271127, -298207, -319262, -333613, -340713, + -340163, -331730, -315348, -291129, -259362, -220512, -175214, -124263, + -68599, -9299, 52451, 115372, 178114, 239282, 297468, 351266, + 399319, 440334, 473120, 496614, 509913, 512295, 503248, 482484, + 449964, 405893, 350744, 285237, 210350, 127286, 37477, -57465, + -155750, -255468, -354592, -451046, -542708, -627478, -703289, -768173, + -820272, -857921, -879657, -884318, -871054, -839446, -789522, -721878, + -637689, -538829, -427837, -308012, -183306, -58351, 61766, 171575, + 265595, 338530, 385818, 403920, 391045, 347469, 276387, 184146, + 81162, -18121, -94264, -123407, -76036, 81568, 389991, 895519, + 1710701, 3002792, 4825273, 7109226, 9729646, 12512602, 15248433, 17702624, + 19630608, 20791430, 20963006, 19955790, 17626208, 13887624, 8719623, 2174045, + -5621665, -14464834, -24081046, -34131360, -44222504, -53920252, -62765096, -70290080, + -76039792, -79590136, -80567832, -78669104, -73676656, -65474260, -54058260, -39545472, + -22176940, -2317326, 19550376, 42834668, 66849928, 90834856, 113974736, 135426640, + 154347008, 169920736, 181390720, 188086896, 189453888, 185076096, 174699280, 158247904, + 135837376, 107780464, 74587640, 36960972, -4218522, -47909872, -92937136, -138019856, + -181808096, -222921312, -259989808, -291697568, -316825344, -334292320, -343195264, -342844000, + -332791264, -312856704, -283143456, -244046832, -196254272, -140736784, -78731208, -11714102, + 58632672, 130463552, 201817312, 270670080, 334992000, 392806176, 442247552, 481620896, + 509455360, 524554208, 526038368, 513381696, 486437344, 445453888, 391080448, 324360480, + 246714016, 159908576, 66019492, -32619810, -133476120, -233882016, -331106848, -422431424, + -505224224, -577016896, -635577152, -678976448, -705651136, -714454400, -704697856, -676181184, + -629208640, -564592384, -483640672, -388133216, -280282016, -162679760, -38236756, 89892360, + 218389968, 343862752, 462932736, 572329472, 668980864, 750100160, 813266368, 856496128, + 878304640, 877753856, 854486592, 808744960, 741372928, 653802560, 548023872, 426538944, + 292301664, 148644560, -806035, -152223392, -301680672, -445254848, -579131904, -699710144, + -803698816, -888209216, -950836352, -989727616, -1003637824, -991967616, -954785856, -892832832, + -807506624, -700830848, -575405568, -434342368, -281185056, -119818392, 45633172, 210913568, + 371747552, 523954144, 663558144, 786896576, 890717440, 972267648, 1029367616, 1060471360, + 1064709056, 1041912064, 992618752, 918061696, 820136128, 701350912, 564763136, 413905312, + 252702016, 85283768, -84153016, -251373152, -412193952, -562598208, -698834304, -817510976, + -915681728, -990918592, -1041372160, -1065817344, -1063683392, -1035067008, -980729024, -902074176, + -801114432, -680417408, -543040576, -392453440, -232449024, -67047936, 99603672, 263338768, + 420074528, 565914944, 697248640, 810838912, 903904448, 974187712, 1020010432, 1040314112, + 1034684224, 1003358720, 947219392, 867767552, 767083328, 647771264, 512892224, 365884480, + 210475200, 50585176, -109770824, -266585856, -415961728, -554206912, -677928256, -784115520, + -870214784, -934190464, -974573952, -990497408, -981711808, -948590080, -892113472, -813843264, + -715877760, -600795712, -471588352, -331581056, -184347104, -33615956, 116822016, 263211632, + 401927360, 529563904, 643020416, 739576448, 816957632, 873389632, 907638720, 919038784, + 907503104, 873521728, 818144448, 742948992, 649996672, 541776128, 421136352, 291211584, + 155339280, 16974000, -120401088, -253362480, -378632256, -493159552, -594195200, -679358336, + -746692608, -794711040, -822428992, -829383232, -815638016, -781777600, -728885632, -658512064, + -572628224, -473572352, -363985824, -246742688, -124873992, -1489180, 120303760, 237476976, + 347158464, 446702912, 533755744, 606308928, 662747520, 701884928, 722987456, 725786624, + 710479424, 677716736, 628580224, 564548800, 487455296, 399434400, 302864160, 200301680, + 94415504, -12084029, -116514408, -216288720, -308979968, -392380352, -464553824, -523880992, + -569095168, -599308544, -614028672, -613164032, -597019520, -566281600, -521994336, -465525920, + -398528192, -322889120, -240680240, -154100192, -65416176, 23095468, 109207648, 190798608, + 265904304, 332765472, 389868896, 435980928, 470173824, 491842976, 500715808, 496851904, + 480634304, 452752704, 414179264, 366137088, 310063456, 247567808, 180386464, 110334864, + 39258892, -31013516, -98719224, -162203968, -219962560, -270674336, -313232768, -346769088, + -370668672, -384580928, -388421408, -382367424, -366846528, -342518912, -310254080, -271102432, + -226263200, -177048848, -124847760, -71085712, -17187518, 35460372, 85545152, 131860032, + 173332944, 209050736, 238278608, 260474080, 275295552, 282605088, 282465888, 275134240, + 261046656, 240802480, 215142736, 184925744, 151100368, 114677616, 76701576, 38220244, + 257309, -36214540, -70298016, -101192744, -128213464, -150804368, -168549456, -181178720, + -188570000, -190746832, -187872144, -180238592, -168255376, -152432528, -133362752, -111701864, + -88148040, -63420712, -38239704, -13305140, 10721270, 33233146, 53694084, 71649704, + 86736888, 98689968, 107343928, 112634456, 114595192, 113352176, 109115832, 102170872, + 92864472, 81593048, 68788288, 54902676, 40395092, 25716910, 11298924, -2460449, + -15205434, -26631372, -36491212, -44599896, -50836640, -55145052, -57531268, -58060172, + -56849976, -54065368, -49909488, -44615140, -38435440, -31634326, -24477204, -17222048, + -10111227, -3364318, 2827930, 8308287, 12956318, 16690166, 19466890, 21281350, + 22163806, 22176328, 21408246, 19970784, 17991204, 15606606, 12957738, 10182934, + 7412561, 4764010, 2337587, 213264, -1551419, -2922471, -3889289, -4463602, + -4677182, -4578945, -4230953, -3704343, -3074240, -2415525, -1797252, -1280920, + -898770, -627791, -434755, -305164, -227603, -191690, -187557, -206218, + -239500, -280340, -322733, -361874, -394053, -416670, -428076, -427515, + -414945, -390943, -356535, -313106, -262250, -205705, -145243, -82626, + -19530, 42469, 101945, 157622, 208399, 253344, 291709, 322917, + 346571, 362440, 370466, 370745, 363530, 349215, 328325, 301500, + 269486, 233106, 193250, 150849, 106856, 62226, 17894, -25242, + -66343, -104637, -139433, -170137, -196253, -217395, -233281, -243746, + -248732, -248291, -242579, -231853, -216463, -196846, -173514, -147048, + -118082, -87293, -55383, -23069, 8934, 39937, 69279, 96351, + 120609, 141582, 158888, 172233, 181426, 186370, 187072, 183631, + 176235, 165155, 150734, 133374, 113527, 91685, 68363, 44092, + 19408, -5162, -29106, -51936, -73196, -92471, -109389, -123633, + -134942, -143118, -148026, -149603, -147856, -142863, -134772, -123799, + -110225, -94386, -76670, -57503, -37343, -16663, 4054, 24338, + 43732, 61811, 78191, 92535, 62535, 80267, 96515, 110869, + 122950, 132423, 139005, 142473, 142671, 139519, 133011, 123223, + 110309, 94503, 76111, 55508, 33131, 9465, -14962, -39597, + -63868, -87203, -109039, -128839, -146103, -160377, -171269, -178455, + -181688, -180805, -175730, -166482, -153172, -136001, -115264, -91340, + -64689, -35842, -5393, 26011, 57690, 88934, 119026, 147254, + 172929, 195397, 214061, 228390, 237937, 242348, 241373, 234879, + 222848, 205389, 182733, 155232, 123355, 87684, 48894, 7752, + -34905, -78188, -121168, -162899, -202440, -238873, -271320, -298971, + -321092, -337048, -346317, -348499, -343329, -330684, -310588, -283215, + -248890, -208087, -161430, -109684, -53754, 5325, 66401, 128208, + 189391, 248521, 304122, 354711, 398828, 435097, 462282, 479357, + 485586, 480607, 464520, 437982, 402277, 359398, 312090, 263877, + 219044, 182590, 160108, 157649, 181489, 237891, 332809, 471594, + 658900, 898625, 1197641, 1570523, 1996663, 2404745, 2717774, 2865679, + 2785718, 2427096, 1754169, 749686, -583221, -2219740, -4113328, -6196593, + -8383364, -10571665, -12647668, -14490343, -15976733, -16987568, -17413068, -17158614, + -16150145, -14338955, -11705745, -8263683, -4060347, 821616, 6265157, 12120884, + 18210488, 24331478, 30263100, 35773284, 40626432, 44591748, 47451940, 49011856, + 49106908, 47610828, 44442580, 39572032, 33024242, 24882062, 15286939, 4437778, + -7412170, -19960400, -32862134, -45739056, -58189596, -69800496, -80159352, -88867704, + -95554448, -99888904, -101593376, -100454560, -96333512, -89173816, -79007528, -65958664, + -50244076, -32171454, -12134525, 9394608, 31875820, 54713840, 77273336, 98895824, + 118918056, 136691248, 151600704, 163085296, 170656112, 173913744, 172563664, 166429120, + 155461200, 139745456, 119505000, 95099632, 67021116, 35884416, 2415097, -32566908, + -68166792, -103437232, -137402992, -169087216, -197538720, -221859376, -241231120, -254941424, + -262406848, -263193680, -257034992, -243843760, -223721280, -196960640, -164045024, -125640616, + -82584344, -35866404, 13391901, 63964612, 114551216, 163809728, 210391808, 252979168, + 290320064, 321265088, 344801344, 360083392, 366461088, 363502304, 351010944, 329038400, + 297889248, 258119712, 210529696, 156147840, 96210000, 32131786, -34524592, -102088152, + -168820816, -232961936, -292774464, -346591552, -392862560, -430196672, -457403712, -473530208, + -477890048, -470088800, -450040832, -417978368, -374452640, -320326336, -256757808, -185176992, + -107253736, -24859086, 59979564, 145128320, 228400464, 307612608, 380641824, 445482432, + 500300512, 543485312, 573695616, 589899584, 591407872, 577897856, 549428800, 506447456, + 449783328, 380634208, 300541536, 211356352, 115196864, 14397969, -88545520, -191040832, + -290462720, -384220896, -469827680, -544963968, -607541824, -655762304, -688166080, -703676928, + -701634816, -681819648, -644463424, -590250752, -520308160, -436181376, -339801440, -233440544, + -119658328, -1240033, 118872048, 237652048, 352067200, 459155616, 556103232, 640318080, + 709499520, 761700928, 795384128, 809463808, 803340864, 776923520, 730635776, 665412608, + 582681792, 484333184, 372675584, 250382144, 120426184, -13991622, -149522608, -282754144, + -410296096, -528867712, -635382464, -727028736, -801344512, -856283200, -890270272, -902247552, + -891705280, -858699904, -803857856, -728364736, -633940096, -522797984, -397595008, -261366368, + -117451720, 30587386, 179056320, 324220320, 462399104, 590061056, 703913984, 800990592, + 878726208, 935027008, 968326336, 977628096, 962536000, 923267520, 860652416, 776115520, + 671644160, 549741504, 413365632, 265857680, 110858864, -47779968, -206094880, -360108800, + -505932192, -639862208, -758477376, -858725824, -938004160, -994225728, -1025875712, -1032052032, + -1012490816, -967575808, -898331200, -806398464, -693996736, -563869056, -419215008, -263610912, + -100920864, 64800176, 229408368, 388775616, 538893952, 675977408, 796558208, 897575488, + 976453568, 1031168128, 1060298880, 1063066560, 1039353856, 989709440, 915335680, 818058560, + 700282816, 564931648, 415373344, 255336384, 88815592, -80029120, -246977680, -407857120, + -558646720, -695580608, -815240832, -914661376, -991426624, -1043686208, -1070172608, -1070248192, + -1043923520, -991857408, -915341120, -816266432, -697079168, -560719104, -410547744, -250265472, + -83820864, 84686600, 251107216, 411343136, 561449088, 697729408, 816829056, 915815936, + 992253184, 1044259072, 1070553344, 1070488704, 1044066752, 991938048, 915385920, 816295104, + 697105216, 560750656, 410588608, 250316144, 83879304, -84624008, -251044992, -411286048, + -561401792, -697695936, -816812672, -915819008, -992277056, -1044304128, -1070619200, -1070574144, + -1044169920, -992056576, -915517184, -816436096, -697252864, -560901952, -410740480, -250465744, + -84023984, 84486696, 250917232, 411169760, 561298496, 697607040, 816739008, 915761280, + 992235520, 1044278912, 1070609856, 1070580032, 1044190208, 992090048, 915562432, 816491584, + 697316864, 560972608, 410815936, 250544048, 84103240, -84408312, -250841440, -411098144, + -561232512, -697547840, -816687680, -915718464, -992201920, -1044254720, -1070595200, -1070574848, + -1044194112, -992102592, -915582912, -816519232, -697350784, -561011712, -410859200, -250590352, + -84151408, 84359424, 250792960, 411051168, 561188032, 697506752, 816650880, 915686656, + 992175616, 1044234432, 1070581248, 1070567360, 1044193024, 992107776, 915594112, 816535872, + 697372352, 561037568, 410888512, 250622304, 84185136, -84324824, -250758368, -411017408, + -561155904, -697477056, -816624192, -915663552, -992156544, -1044219712, -1070571008, -1070561728, + -1044192000, -992111168, -915601728, -816547392, -697387392, -561055616, -410909120, -250644896, + -84209144, 84299992, 250733312, 410992736, 561132224, 697454848, 816603968, 915645824, + 992141696, 1044208000, 1070562816, 1070557056, 1044191040, 992113920, 915607936, 816556928, + 697399936, 561070784, 410926464, 250663904, 84229272, -84279312, -250712656, -410972640, + -561113216, -697437440, -816588608, -915632832, -992131328, -1044200448, -1070558208, -1070555520, + -1044192384, -992118080, -915614784, -816566208, -697411328, -561084032, -410941184, -250679696, + -84245752, 84262552, 250696016, 410956544, 561098048, 697423552, 816576320, 915622464, + 992123200, 1044194816, 1070555200 }; /************************ Q30 *******************************/ const Word32 ivas_fb_fr_12band_1ms_im_fx[IVAS_FB_12_1MS_LEN] = { - -96495528, -286734272, -468692800, -637041216, -786562176, -912433280, -1009964416, -1075182976, -1098333440, - -1060972224, -954328512, -784950848, -567387776, -321857280, -71378072, 161019520, 355191072, - 496249664, 576290688, 595228096, 560553408, 486341472, 391112608, 296445024, 219833024, - 161425424, 113971872, 75074912, 43676944, 18947558, 106207, -13606639, -22959300, - -28697174, -31541624, -32158708, -31154358, -29054292, -26304144, -23261552, -20202826, - -17324756, -14756116, -12565362, -10774012, -9366401, -8302065, -7524551, -6970827, - -6577419, -6286071, -6046737, -5819771, -5576294, -5297871, -4975268, -4606808, - -4196583, -3752523, -3284873, -2804624, -2322651, -1848752, -1391471, -957667, - -552820, -180887, 155183, 453533, 712892, 932744, 1112922, 1253892, - 1356428, 1421957, 1452251, 1449752, 1417222, 1357998, 1275581, 1173833, - 1056523, 927513, 790325, 648358, 504521, 361522, 221574, 86743, - -41290, -160871, -270597, -368994, -454781, -526614, -583403, -624117, - -648145, -655120, -645267, -619210, -578251, -524110, -459110, -385841, - -307254, -226274, -145851, -68575, 3253, 67950, 124299, 171779, - 210318, 240423, 262847, 278659, 288884, 294565, 296445, 295082, - 290614, 282963, 271701, 256332, 236226, 210937, 180155, 143993, - 102888, 57812, 10083, -38529, -86081, -130429, -169562, -201608, - -225146, -239179, -243376, -237949, -223786, -202225, -175080, -144342, - -112142, -80430, -50955, -24990, -3380, 13628, 26240, 35170, - 41402, 46169, 50665, 56013, 62999, 72081, 83214, 95949, - 109364, 122266, 133211, 140767, 143575, 140609, 131207, 115267, - 93186, 65957, 34996, 2134, -30636, -61239, -87791, -108676, - -122781, -129495, 12356724, 36406252, 58390684, 76977432, 90719600, 98265728, - 98008264, 88608552, 62420976, 2547174, -98862584, -234978608, -391650304, -549723776, - -687929024, -785620992, -825677888, -796781568, -695135040, -525144384, -299188480, -36327380, - 239749920, 503413376, 729982272, 898556864, 994367488, 1010422464, 948197568, 817333696, - 634343104, 420516896, 199273200, -6719048, -178276784, -302004160, -371805248, -389615456, - -365008416, -315253344, -262675984, -217917568, -178521248, -143001072, -111343304, -83569488, - -59728692, -39750832, -23483756, -10668693, -980101, 5968707, 10589352, 13306198, - 14527738, 14637296, 13974127, 12830675, 11443325, 9996437, 8620832, 7402724, - 6386965, 5588127, 4995412, 4583292, 4315642, 4154179, 4060473, 4001515, - 3949354, 3884093, 3791711, 3665350, 3502261, 3304372, 3075215, 2820550, - 2545809, 2257129, 1959450, 1657946, 1356600, 1059795, 771079, 494646, - 234059, -6519, -223731, -414017, -575061, -704879, -803133, -870150, - -907983, -919252, -907936, -878057, -834296, -780659, -721070, -658192, - -594157, -529649, -464852, -398810, -330536, -258557, -182049, -100384, - -14134, 75538, 166137, 254665, 337160, 409716, 468199, 509317, - 530349, 530086, 508400, 466928, 408381, 336929, 257279, 174830, - 94651, 21581, -40724, -89563, -123905, -143909, -151339, -148811, - -139947, -128462, -118197, -112219, -112926, -121327, -137375, -159531, - -185372, -211440, -234054, -249316, -253979, -245431, -222426, -184880, - -134334, -73467, -6263, 62723, 128418, 186074, 231361, 261147, - 273444, 267948, 261810, 763373, 1198560, 1499796, 1578270, 1304628, - 517808, -987783, -3443484, -7111908, -12256820, -19143168, -27996048, -39000040, - -52248820, -67752040, -85376464, -104873664, -125808744, -147634944, -169591248, -190910720, - -210637232, -228834976, -242239792, -233744176, -184602112, -88256112, 52564248, 227312048, - 419154080, 607121280, 768828480, 883312000, 933778624, 909811200, 808862336, 636755584, - 407214048, 140391440, -139342896, -406167488, -635714880, -807834944, -908809408, -932820096, - -882419648, -768029696, -606446400, -418634368, -226977824, -52442412, 88143752, 184240560, - 233125792, 241364816, 227710480, 209276640, 189331712, 167814560, 145682224, 123701848, - 102633120, 83021960, 65302000, 49722020, 36415812, 25376218, 16511686, 9640718, - 4539034, 941445, -1420767, -2818065, -3495818, -3676385, -3542409, -3243683, - -2888735, -2555377, -2287831, -2108851, -2019462, -2010501, -2062586, -2155553, - -2267238, -2380241, -2479146, -2554886, -2600826, -2615545, -2598567, -2552488, - -2479078, -2381454, -2260948, -2119607, -1957826, -1777065, -1577959, -1362941, - -1134431, -897064, -655697, -417094, -187702, 25095, 215280, 377113, - 507239, 603471, 666470, 698219, 703186, 686502, 654728, 613906, - 570192, 528056, 491058, 460427, 436171, 416130, 397422, 375887, - 347709, 309014, 257411, 191469, 111939, 20899, -77459, -178052, - -274516, -360654, -430246, -478480, -501684, -498487, -469248, -416789, - -345433, -261310, -171090, -82033, -635, 67321, 117943, 148920, - 160318, 153895, 133448, 103776, 70703, 39859, 16616, 4954, - 7564, 25024, 56260, 98143, 146331, 195238, 239125, 272241, - 289930, 288679, 266989, 225117, 165550, 92349, 11219, -71466, - -148857, -214705, -263567, -291740, -297224, -280306, -243136, -189895, - -125985, -57873, 7933, 65157, 108741, 134971, 142193, 130597, - 102524, 61859, 13944, -35316, -79751, -113898, -133249, -135053, - -118286, -84087, -35339, 23302, 86186, 146930, 199365, 237874, - 258253, 257864, 236196, 194657, 136724, 67341, -7287, -80567, - -145896, -270343, -808574, -1340072, -1858807, -2358665, -2831742, -3270963, - -3669340, -4023521, -4333619, -4606985, -4857566, -5108708, -5390687, -5741295, - -6200425, -6807718, -7593886, -8575752, -9745172, -11063108, -12448231, -13772797, - -14853837, -15454158, -15279006, -13985197, -11185029, -6465256, 602227, 10431847, - 23410894, 39863840, 60045788, 84103768, 112100696, 143979968, 179711728, 219302416, - 264231232, 316950432, 366815488, 391499840, 373734272, 303947296, 180205328, 8607086, - -197450336, -418782432, -632721152, -815848960, -946877184, -1009294400, -993460928, -897898880, - -729596672, -503316064, -239947616, 35840880, 298430624, 524143840, 693923584, 795387200, - 824107840, 783846592, 685860544, 547189184, 388365568, 230527600, 92671240, -11219515, - -74492144, -105158200, -120261872, -127544112, -128388320, -124354624, -116661448, -106489408, - -94793200, -82429304, -70062176, -58237700, -47334588, -37619828, -29226616, -22202334, - -16501587, -12028281, -8635400, -6159899, -4423260, -3257870, -2504859, -2031762, - -1726474, -1507393, -1314142, -1112384, -883004, -624119, -340602, -45467, - 248842, 528315, 783713, 1007231, 1196662, 1351165, 1473983, 1568019, - 1637995, 1686519, 1716364, 1727429, 1719421, 1689696, 1636232, 1556028, - 1448006, 1311510, 1148760, 963094, 760758, 548770, 336091, 131254, - -56814, -221101, -355658, -457521, -525555, -561787, -569830, -555666, - -525766, -487535, -447411, -411297, -382938, -364634, -356100, -355594, - -359287, -362732, -360583, -348172, -321291, -277591, -216139, -138411, - -47457, 51579, 152676, 248783, 333218, 399646, 443388, 461240, - 452449, 418164, 361960, 288882, 205559, 118975, 36377, -35977, - -92851, -131037, -149092, -147929, -130154, -100234, -63486, -25973, - 6639, 29226, 38204, 31469, 9051, -27322, -73989, -126155, - -177996, -223678, -257577, -275273, -273644, -251592, -209808, -151108, - -79807, -1677, 76962, 149510, 210060, 253638, 277008, 278653, - 259231, -101021, -297456, -477733, -632297, -753728, -836696, -878615, - -879031, -839751, -763739, -654959, -517096, -353514, -166209, 43748, - 276781, 533724, 815969, 1123958, 1457300, 1813342, 2187857, 2574262, - 2965417, 3353797, 3734536, 4106324, 4475222, 4855377, 5272512, 5763051, - 6375849, 7168185, 8204533, 9548340, 11257436, 13371571, 15905385, 18833006, - 22081010, 25512624, 28924300, 32032662, 34478724, 35820256, 35546928, 33078728, - 27793346, 19027280, 6112874, -11628489, -34851840, -64232176, -100493888, -144608256, - -198909072, -270631488, -359662496, -448624032, -516131776, -543967680, -518454176, -432622496, - -287176640, -90768024, 140893552, 386715040, 622670976, 824595136, 971067648, 1045974272, - 1040467264, 954060352, 794731136, 578022784, 325234560, 60958056, -189791088, -404423968, - -565354624, -661869440, -691213888, -658569600, -576189312, -461441856, -334519392, -215323504, - -121182328, -57886044, -14972652, 16811060, 39759696, 55435020, 65035460, 69706136, - 70441104, 68189248, 63775032, 57948004, 51329736, 44447116, 37701544, 31399154, - 25736924, 20832988, 16723796, 13393488, 10776430, 8783249, 7304115, 6229334, - 5450365, 4874027, 4420041, 4029271, 3658127, 3282309, 2889391, 2480032, - 2060348, 1642421, 1237795, 858544, 512575, 205752, -60998, -288674, - -481834, -645256, -785054, -905653, -1011013, -1102347, -1179780, -1240896, - -1282805, -1301283, -1292960, -1254661, -1185341, -1085250, -957344, -806069, - -638185, -461195, -283738, -113885, 40607, 173836, 281340, 361227, - 413418, 440281, 445517, 434398, 412451, 385525, 358529, 335589, - 319068, 309999, 307515, 309612, 312947, 313829, 308220, 292759, - 264732, 222913, 167314, 99696, 23013, -58414, -139717, -215530, - -280898, -331372, -363803, -376281, -368659, -342216, -299851, -245477, - -183947, -120287, -59527, -210294, -218804, -207034, -170663, -107684, - -17542, 97483, 233628, 384636, 543572, 702055, 852320, 986414, - 1098210, 1182279, 1235630, 1256080, 1243695, 1198697, 1122785, 1016812, - 882318, 719277, 528144, 307851, 58485, -220576, -527549, -860384, - -1213683, -1581737, -1955989, -2329539, -2695405, -3052665, -3405215, -3769076, - -4170617, -4653891, -5276647, -6116192, -7261256, -8815022, -10881268, -13564073, - -16947616, -21093540, -26015144, -31675226, -37956612, -44665032, -51498380, -58060316, - -63829408, -68189520, -70395848, -69627624, -64938208, -55334156, -39669268, -16742548, - 15011598, 57892376, 121157856, 215274688, 334456672, 461378272, 576139200, 658546880, - 691230336, 661933376, 565469888, 404588960, 189999104, -60718748, -324979552, -577770304, - -794500352, -953869504, -1040332032, -1045906432, -971073600, -824675520, -622820672, -386923360, - -141145440, 90490632, 286893152, 432351840, 518213184, 543769536, 515984864, 448531552, - 359622208, 270636384, 198948336, 144668672, 100561448, 64293740, 34896780, 11649924, - -6117171, -19054578, -27836140, -33125540, -35583508, -35831208, -34449244, -31950346, - -28780702, -25304532, -21811144, -18510242, -15544263, -12991323, -10880449, -9198353, - -7904592, -6938712, -6232849, -5716818, -5326765, -5007114, -4715109, -4419761, - -4103101, -3757115, -3383050, -2987624, -2581751, -2177166, -1785567, -1416314, - -1076470, -769692, -497117, -257162, -46868, 137886, 301064, 446309, - 576003, 691438, 792390, 877665, 945087, 992265, 1016767, 1016861, - 991628, 941464, 867976, 774150, 663993, 542420, 414732, 286370, - 162380, 47204, -55707, -143950, -216326, -272693, -313915, -341561, - -357718, -364650, -364603, -359521, -350944, -339867, -326770, -311628, - -294057, -273429, -249069, -220397, -187092, -149183, -107127, -61803, - -14483, 33260, 79674, 122959, 161417, 193583, -137153, -86096, - -23462, 46165, 118296, 188311, 252569, 308033, 353183, 387345, - 411326, 426448, 434961, 438884, 440375, 440558, 440044, 437930, - 432614, 421046, 399869, 364878, 312384, 238720, 141646, 19702, - -126527, -295376, -483051, -684957, -894831, -1106337, -1312215, -1505978, - -1680884, -1831578, -1952736, -2040617, -2091372, -2102604, -2071473, -1996480, - -1875541, -1708206, -1493799, -1234127, -931547, -591976, -222473, 165877, - 561490, 950008, 1319512, 1659151, 1966270, 2245658, 2518227, 2819813, - 3210306, 3770160, 4608328, 5854141, 7662371, 10198175, 13638330, 18147660, - 23877010, 30930782, 39364468, 49144104, 60148836, 72123392, 84694024, 97312800, - 109298904, 119765360, 127705376, 131866912, 130934488, 123231464, 107234464, 75050672, - 9470806, -97677456, -239897616, -403333024, -569087680, -716066368, -823729024, -874943616, - -858298112, -769767616, -613463168, -401328448, -152012800, 111316600, 362752096, 579800640, - 754066560, 884317376, 967646720, 1002358976, 988932224, 930137792, 830908864, 698079680, - 539965760, 365883200, 185588480, 8720114, -155758112, -300047104, -417930816, -505075680, - -559213504, -580180096, -569826624, -531795520, -471193568, -394169856, -307444800, -217803664, - -131610264, -54348980, 9748328, 57999172, 89445504, 104945984, 107368432, 102279568, - 94596192, 85655480, 75877136, 65846368, 56016016, 46757852, 38321108, 30867838, - 24467266, 19124186, 14784349, 11357873, 8727069, 6764325, 5338255, 4325655, - 3614320, 3109507, 2733412, 2427369, 2148937, 1871452, 1580043, 1270071, - 943252, 606145, 267130, -64446, -380185, -672695, -936550, -1167777, - -1364195, -1524669, -1649207, -1738275, -1792904, -1814221, -1803670, -1762759, - -1693364, -1597596, -1478091, -1337881, -1180581, -1010189, -831132, -647987, - -465420, -287874, -119474, 36238, 176365, 298810, 402244, 486148, - 550683, 596630, 625208, 637968, 636614, 622900, 598511, 565006, - 523771, 476024, 422831, 365155, 303902, 239978, 174336, 108003, - 42099, -22177, -83566, -140800, -192647, -237981, -275829, -305435, - -326287, -338158, -341095, -335431, -321739, -300823, -273643, -241298, - -204944, -165780, -124974, -83660, -42880, 10137, 29849, 47985, - 63702, 76520, 86314, 93425, 98550, 102746, 107236, 113334, - 122202, 134769, 151505, 172398, 196816, 223585, 250966, 276853, - 298844, 314511, 321522, 317919, 302199, 273538, 231774, 177523, - 112040, 37218, -44643, -130911, -218896, -305922, -389579, -467717, - -538627, -600924, -653636, -695990, -727439, -747408, -755314, -750348, - -731559, -697715, -647504, -579487, -492405, -385195, -257342, -108895, - 59211, 245234, 446381, 659034, 878627, 1100007, 1317397, 1524851, - 1716231, 1885675, 2027510, 2136678, 2208531, 2239209, 2225330, 2164370, - 2054318, 1894140, 1683476, 1423258, 1115462, 763860, 373717, -47467, - -490570, -944379, -1396841, -1835173, -2248037, -2626382, -2966637, -3272111, - -3556917, -3847305, -4185583, -4630274, -5258922, -6165632, -7461554, -9268313, - -11715324, -14927984, -19021866, -24085232, -30171698, -37277344, -45335748, -54189964, - -63598244, -73198584, -82549584, -91078392, -98377112, -103118416, -100391208, -84628624, - -52954552, -4492618, 59827860, 137363792, 223933312, 314109568, 401591168, 479653696, - 541630720, 581410176, 593897728, 575427264, 524078976, 439891712, 324946016, 183315184, - 20883088, -154960944, -335730752, -512333504, -675605952, -816870016, -928462720, -1004220224, - -1039868736, -1033319296, -984830528, -897064000, -775182272, -627308096, -461708352, -284291552, - -100579392, 83598736, 262525088, 430732416, 583209600, 715532736, 824009920, 905775040, - 958871552, 982291840, 975995776, 940888192, 878773504, 792274432, 684731072, 560072576, - 422675872, 277208288, 128466608, -18787604, -159985744, -290901824, -407785088, -507474624, - -587489088, -646091776, -682326144, -696024192, -687785152, -658928000, -611418688, -547776704, - -470963680, -384259392, -291130144, -195094672, -99592464, -7860071, 77180528, 153017120, - 217622960, 269510560, 307761952, 332035072, 342546656, 340033376, 325693088, 301109632, - 268164672, 228941216, 185622192, 140390128, 95330560, 52345244, 13076479, -21151680, - -49376268, -71017224, -85881800, -94147080, -96327536, -93222768, -85856648, -75400496, - -63097824, -50176000, -37774988, -26857674, -18169908, -11863887, -7301392, -3914018, - -1479242, 185291, 1236420, 1817970, 2053955, 2052907, 1903852, 1679448, - 1434536, 1209401, 1029974, 911183, 857962, 868350, 934655, 1046022, - 1189342, 1351150, 1518125, 1678330, 1821294, 1938725, 2024278, 2073883, - 2085335, 2058391, 1994281, 1895693, 1766278, 1610593, 1433645, 1240831, - 1037545, 829139, 620601, 416556, 221024, 37473, -131344, -283279, - -416878, -531220, -625958, -701127, -757159, -794697, -814605, -817824, - -805400, -778384, -737905, -685103, -621229, -547610, -465741, -377252, - -283979, -187900, -91166, 4001, 95326, 180608, 257764, 324972, - 380709, 423871, 453787, 470280, 473637, 464613, 444338, 414280, - 376112, 331644, 282692, 231012, 178188, 125609, 74399, 25440, - -20646, -63433, -102670, -138199, -169921, -197722, -221454, -240892, - -255747, -265667, -270281, -269233, -262252, -249189, -230092, -205221, - -175099, -140492, -102411, -62059, -20785, 19997, 58880, 94556, - 125879, 151942, 172113, 186075, 193810, 195596, 191955, 183604, - 171377, 156168, 138843, 120200, 100900, 81458, 62216, 43368, - 24971, 6998, -10624, -27957, -45013, -61705, -77836, -93079, - -106999, -119067, -128714, -135370, -138532, -137806, -132971, -123999, - -111091, -94667, -75361, -53969, 10765, 32074, 52722, 72311, - 90486, 106963, 121523, 134027, 144392, 152600, 158658, 162605, - 164468, 164267, 161985, 157577, 150955, 142011, 130615, 116649, - 100019, 80692, 58704, 34200, 7431, -21221, -51265, -82083, - -112977, -143167, -171845, -198187, -221409, -240776, -255657, -265518, - -269970, -268744, -261725, -248915, -230452, -206572, -177616, -143996, - -106204, -64784, -20348, 26444, 74865, 124130, 173377, 221686, - 268054, 311432, 350709, 384766, 412472, 432751, 444591, 447117, - 439606, 421553, 392681, 352994, 302769, 242592, 173323, 96118, - 12366, -76299, -168083, -261025, -353085, -442152, -526117, -602884, - -670441, -726859, -770364, -799329, -812348, -808221, -786031, -745129, - -685209, -606288, -508783, -393474, -261578, -114689, 45155, 215561, - 393723, 576534, 760547, 942104, 1117306, 1282158, 1432549, 1564416, - 1673729, 1756688, 1809722, 1829726, 1814087, 1760970, 1669365, 1539414, - 1372449, 1171316, 940345, 685584, 414591, 136477, -138614, -399774, - -636264, -838162, -997771, -1110606, -1177191, -1204204, -1206433, -1207707, - -1242622, -1356751, -1607660, -2063815, -2804506, -3917005, -5495374, -7636020, - -10436517, -13992514, -18402674, -23818388, -30616280, -38795064, -47468192, -55465196, - -61624760, -64816688, -64030596, -58439904, -47471160, -30852034, -8650500, 18708296, - 50440096, 85421744, 122227560, 159185040, 194443776, 226058080, 252076752, 270638720, - 280067616, 278963616, 266285680, 241422224, 204245248, 155146128, 95049592, 25405990, - -51839956, -134302160, -219227456, -303587872, -384188544, -457786240, -521215424, -571515392, - -606054656, -622647040, -619654592, -596072512, -551593600, -486646944, -402411264, -300798944, - -184413264, -56477480, 79260352, 218645328, 357251200, 490529920, 613968768, 723250432, - 814409344, 883978944, 929123648, 947751552, 938601472, 901303104, 836405248, 745373248, - 630551936, 495099232, 342887840, 178382704, 6494100, -167583760, -338549120, -501169472, - -650463872, -781868416, -891402304, -975790912, -1032769600, -1061261696, -1060915456, -1031960960, - -975385600, -892916224, -786977856, -660620736, -517435968, -361449888, -197010624, -28662768, - 138980608, 301369056, 454141632, 593248768, 715063168, 816478784, 894992576, 948769664, - 976686784, 978356608, 954128576, 905069824, 832924288, 740053568, 629360000, 504194944, - 368255424, 225472400, 79893288, -64436384, -203589744, -333869568, -451910592, -554770112, - -640004160, -705727744, -750656768, -774131456, -776120512, -757206720, -718553856, -661857536, - -589281088, -503378688, -407008864, -303241088, -195258304, -86258672, 20640266, 122492392, - 216605760, 300615264, 372542752, 430843584, 474437952, 502727104, 515593600, 513386816, - 496894016, 467298720, 426127872, 375190336, 316508064, 252243568, 184625248, 115873648, - 48130852, -16604751, -76536328, -130117360, -176090096, -213512624, -241774240, -260598816, - -270036736, -270445792, -262462656, -246965456, -225030192, -197881696, -166842016, -133277536, - -98547200, -63953468, -30697916, 157309, 27720696, 51294532, 70389352, 84729480, - 94249824, 99084304, 99546808, 96105616, 89352656, 79969008, 68688296, 56259452, - 43410724, 30816176, 19066356, 8644033, -93590, -6926218, -11773978, -14694671, - -15872813, -15605618, -14280676, -12378042, -10430668, -8704424, -7182491, -5854782, - -4729147, -3804335, -3072066, -2516383, -2116394, -1847634, -1684290, -1600530, - -1572012, -1576721, -1595767, -1613665, -1618550, -1602016, -1558925, -1486975, - -1386301, -1258946, -1108416, -939180, -756297, -565028, -370575, -177839, - 8715, 185182, 348246, 495214, 623986, 733038, 821363, 888436, - 934161, 958831, 963086, 947887, 914478, 864367, 799293, 721209, - 632236, 534643, 430794, 323115, 214029, 105923, 1076, -98376, - -190504, -273617, -346304, -407458, -456294, -492355, -515505, -525917, - -524051, -510616, -486547, -452951, -411079, -362277, -307954, -249541, - -188465, -126117, -63839, -2894, 55536, 110376, 160649, 205502, - 244200, 276144, 300872, 318070, 327574, 329385, 323660, 310724, - 291059, 265298, 234214, 198698, 159739, 118393, 75754, 32922, - -9033, -49104, -86375, -120044, -149449, -174076, -193569, -207727, - -216503, -219983, -218381, -212007, -201261, -186599, -168524, -147564, - -124261, -99161, -72807, -45733, -18468, 8473, 34584, 59372, - 82359, 103090, 121141, 136131, 147730, 155680, 159803, 160015, - 156337, 148897, 137934, 123794, 106916, 87821, 67091, 45345, - 23216, 1326, -19743, -39465, 109887, 120382, 128416, 133765, - 136261, 135794, 132320, 125859, 116497, 104388, 89749, 72858, - 54047, 33695, 12222, -9922, -32266, -54329, -75626, -95683, - -114044, -130284, -144009, -154878, -162593, -166923, -167696, -164811, - -158239, -148026, -134294, -117244, -97153, -74370, -49314, -22469, - 5628, 34390, 63198, 91407, 118365, 143426, 165965, 185395, - 201183, 212860, 220042, 222435, 219848, 212195, 199508, 181929, - 159715, 133233, 102952, 69434, 33331, -4639, -43696, -83016, - -121744, -159013, -193957, -225733, -253530, -276597, -294249, -305894, - -311042, -309326, -300512, -284516, -261407, -231423, -194963, -152600, - -105060, -53228, 1881, 59128, 117284, 175043, 231069, 284005, - 332527, 375354, 411300, 439283, 458370, 467783, 466935, 455431, - 433101, 399985, 356360, 302726, 239820, 168592, 90219, 6068, - -82296, -173156, -264641, -354785, -441533, -522811, -596538, -660703, - -713385, -752830, -777471, -786003, -777391, -750944, -706300, -643488, - -562898, -465330, -351937, -224267, -84196, 66044, 223948, 386697, - 551263, 714370, 872609, 1022412, 1160192, 1282340, 1385409, 1466141, - 1521718, 1549819, 1548936, 1518450, 1458982, 1372447, 1262386, 1133907, - 993924, 850871, 714752, 596518, 507835, 460031, 463573, 526525, - 653821, 845263, 1094812, 1388217, 1702729, 2004387, 2248836, 2377871, - 2322716, 1997670, 1310909, 31361, -2276023, -5884963, -10790734, -16840258, - -23748608, -31120974, -38472224, -45255760, -50892408, -54804412, -56448304, -55348896, - -51129788, -43541476, -32483506, -18021422, -395893, 19975162, 42503072, 66442420, - 90913264, 114929960, 137436576, 157346768, 173587488, 185144144, 191106144, 190710336, - 183381248, 168765648, 146760624, 117533176, 81530704, 39481248, -7616625, -58514600, - -111745512, -165663824, -218494432, -268388400, -313484064, -351971232, -382156480, -402527424, - -411813344, -409040128, -393577504, -365176384, -323994752, -270611200, -206024384, -131639056, - -49237472, 39062252, 130860688, 223542656, 314352192, 400474784, 479124064, 547630784, - 603530816, 644649344, 669178624, 675746624, 663473536, 632014912, 581589056, 512987520, - 427568224, 327230528, 214373088, 91835128, -37177272, -169178032, -300498464, -427392512, - -546146752, -653191616, -745210944, -819245440, -872788352, -903868288, -911118272, -893827520, - -851974272, -786238976, -697996288, -589286400, -462766208, -321640832, -169578832, -10611593, - 150978672, 310780032, 464377088, 607478720, 736043264, 846397952, 935348160, 1000273472, - 1039207744, 1050900416, 1034856960, 991357632, 921452992, 826937088, 710298944, 574652800, - 423651328, 261382080, 92266240, -79072984, -248102448, -410503776, -562126720, -699092736, - -817911936, -915573376, -989624896, -1038234688, -1060238592, -1055167808, -1023259008, -965445760, - -883330880, -779142016, -655670144, -516193728, -364390176, -204236960, -39905496, 124349848, - 284304192, 435873248, 575219968, 698854144, 803721536, 887281600, 947570240, 983247040, - 993625152, 978684224, 939064256, 876042880, 791495168, 687838208, 567961280, 435144608, - 292968064, 145212944, -4240369, -151516576, -292848000, -424673056, -543728192, -647130176, - -732447680, -797759168, -841696640, -863474048, -862898880, -840368384, -796849536, -733844032, - -653339328, -557747648, -449833824, -332635680, -209377712, -83381528, 42024892, 163596368, - 278255872, 383173696, 475838368, 554117568, 616307264, 661168640, 687951104, 696401792, - 686761024, 659744256, 616512064, 558627584, 488004704, 406847392, 317582464, 222787984, - 125119136, 27233782, -68280144, -158973472, -242598960, -317167264, -380994112, -432737696, - -471425664, -496470656, -507674976, -505223904, -489668640, -461899200, -423108800, -374750624, - -318488480, -256143216, -189636144, -120931576, -51979948, 15336795, 79255984, 138179872, - 190714864, 235703648, 272249056, 299729728, 317807040, 326423456, 325792768, 316382656, - 298890368, 274212512, 243410272, 207670816, 168266608, 126513920, 83731472, 41200944, - 130175, -38379756, -73362784, -104010672, -129689920, -149952464, -164540112, -173382736, - -176590656, -174441552, -167362736, -155909328, -140739472, -122587248, -102234616, -80482928, - -58125464, -35921428, -14572560, 5297181, 23158150, 38587464, 51277008, 61037024, - 67795232, 71591800, 72570464, 70966328, 67090884, 61315048, 54050700, 45731812, - 36795552, 27664472, 18730052, 10338603, 2779584, -3722787, -9014984, -13015846, - -15715349, -17169656, -17493876, -16851572, -15443180, -13491852, -11229971, -8883501, - -6659666, -4731320, -3230436, -2179638, -1456508, -951706, -619736, -422906, - -328742, -307762, -334784, -388143, -450439, -507929, -550755, -572282, - -568989, -539768, -485654, -409163, -313997, -204481, -85334, 38748, - 163232, 284008, 397435, 500481, 590686, 666220, 725799, 768696, - 794640, 803805, 796717, 774237, 737483, 687817, 626774, 556060, - 477482, 392946, 304395, 213796, 123081, 34130, -51284, -131518, - -205101, -270753, -327424, -374293, -410797, -436619, -451696, -456198, - -450524, -435265, -411195, -379231, -340412, -295864, -246780, -194382, - -139908, -84576, -29579, 23948, 74940, 122415, 165488, 203392, - 235477, 261232, 280287, 292420, 297563, 295805, 287381, 272679, - 252217, 226642, 196699, 163225, 127113, 89298, 50723, 12319, - -25022, -60468, -93267, -122762, -148403, -169755, -186505, -198455, - -205529, -207755, -205269, -198296, -187147, -172200, -153899, -132733, - -109235, -83965, -57505, -30448, -3387, 23090, 48419, 72062, - 93519, 112344, 128152, 140629, 149540, 154739, 156171, 153875, - 147984, 138721, 126390, 111370, 94099, 75064, 54779, 33779, - 12593, -8262, -28303, -47084, 123494, 129971, 133493, 133924, - 131201, 125331, 116398, 104559, 90037, 73124, 54170, 33578, - 11793, -10702, -33406, -55797, -77356, -97567, -115939, -132009, - -145355, -155607, -162458, -165670, -165080, -160609, -152268, -140154, - -124457, -105454, -83508, -59060, -32622, -4767, 23884, 52680, - 80946, 108005, 133192, 155874, 175459, 191418, 203293, 210711, - 213394, 211167, 203964, 191828, 174916, 153495, 127939, 98723, - 66416, 31667, -4798, -42202, -79720, -116501, -151685, -184419, - -213882, -239294, -259946, -275209, -284560, -287590, -284024, -273728, - -256722, -233178, -203429, -167959, -127402, -82528, -34229, 16495, - 68562, 120826, 172104, 221199, 266929, 308151, 343787, 372847, - 394455, 407868, 412493, 407908, 393872, 370338, 337461, 295599, - 245318, 187388, 122773, 52620, -21757, -98901, -177232, -255084, - -330731, -402431, -468456, -527135, -576892, -616284, -644032, -659054, - -660495, -647746, -620468, -578601, -522379, -452338, -369318, -274467, - -169243, -55405, 64986, 189594, 315816, 440826, 561623, 675096, - 778120, 867669, 940959, 995619, 1029881, 1042792, 1034432, 1006137, - 960689, 902497, 837686, 774157, 721490, 690799, 694367, 745251, - 856581, 1040935, 1309312, 1670468, 2129651, 2688819, 3345656, 4105519, - 4976393, 5840188, 6459558, 6619945, 6147045, 4905821, 2810464, -169248, - -4002855, -8597662, -13799897, -19399282, -25136440, -30713178, -35805064, -40075928, - -43193604, -44846368, -44759276, -42709760, -38541820, -32178052, -23629058, -12999656, - -491521, 13597969, 28880844, 44887552, 61079704, 76866240, 91622528, 104711816, - 115508400, 123421568, 127919688, 128553392, 124977088, 116967832, 104440944, 87461480, - 66251100, 41189824, 12812431, -18200672, -51037968, -84776544, -118406512, -150859520, - -181040640, -207862576, -230281344, -247332144, -258164320, -262074240, -258534976, -247221616, - -228031216, -201096704, -166793872, -125740976, -78790864, -27015406, 28317512, 85773968, - 143790256, 200714592, 254853088, 304518720, 348082144, 384022272, 410975936, 427784064, - 433533952, 427595232, 409648832, 379707872, 338129120, 285614880, 223204848, 152257552, - 74422120, -8399482, -94098672, -180413920, -264990464, -345444480, -419429888, -484706304, - -539205312, -581094272, -608834752, -621234048, -617488768, -597217728, -560484416, -507806784, - -440154880, -358935456, -265963920, -163424032, -53816484, 60102860, 175393008, 289004832, - 397862624, 498948160, 589385088, 666520704, 728003904, 771855360, 796529472, 800965376, - 784625088, 747518528, 690213376, 613829888, 520020448, 410934048, 289166720, 157698512, - 19819390, -120954952, -260974400, -396551008, -524057792, -640027584, -741248576, -824854336, - -888405760, -929962176, -948139904, -942156672, -911859520, -857736896, -780912768, -683123584, - -566678912, -434405344, -289576544, -135830144, 22925716, 182614304, 339097376, 488284896, - 626244608, 749307648, 854168576, 937975616, 998409984, 1033750912, 1042925056, 1025539008, - 981893504, 912979136, 820453376, 706599552, 574268864, 426807104, 267967136, 101810936, - -67397744, -235305840, -397586848, -550055296, -688779008, -810183040, -911146880, -989084800, - -1042054592, -1068829184, -1068826112, -1042089792, -989328512, -911898304, -811770624, -691481728, - -554069376, -402995648, -242059584, -75301504, 93098968, 258928160, 418044256, 566481536, - 700549504, 816925696, 912738304, 985637504, 1033853888, 1056241408, 1052304960, 1022211200, - 966782848, 887476096, 786342208, 665974016, 529439200, 380201408, 222031488, 58911676, - -105065728, -265801808, -419294496, -561739072, -689623232, -799814720, -889638656, -956942720, - -1000149696, -1018294336, -1011044736, -978708096, -922219648, -843115968, -743493120, -625951040, - -493525056, -349607232, -197858608, -42115448, 113708584, 265721584, 410151424, 543440192, - 662332480, 763955904, 845890496, 906227200, 943612480, 957278400, 947058112, 913385664, - 857280704, 780318336, 684585088, 572622656, 447359776, 312035584, 170115056, 25199920, - -119063552, -259076960, -391380192, -512737632, -620217856, -711264960, -783759808, -836069184, - -867082944, -876236800, -863521472, -829477248, -775175296, -702184896, -612528832, -508627616, - -393234080, -269360256, -140198384, -9038325, 120816904, 246134720, 363834016, 471061440, - 565260864, 644234816, 706195520, 749805696, 774206528, 779033856, 764420928, 730989120, - 679825600, 612449984, 530770240, 437028800, 333741664, 223630656, 109551536, -5580210, - -118864264, -227488864, -328800992, -420371296, -500052800, -566030976, -616865088, -651519232, - -669382144, -670276608, -654456960, -622595968, -575760768, -515379648, -443199648, -361236896, - -271720576, -177032864, -79645232, 17945830, 113283088, 204010512, 287931712, 363063040, - 427680576, 480359328, 520004224, 545871936, 557583232, 555125952, 538848000, 509441632, - 467918976, 415579744, 353972064, 284847840, 210113616, 131778400, 51899980, -27469024, - -104333832, -176807568, -243157520, -301846336, -351567360, -391273184, -420196800, -437865024, - -444103968, -439036576, -423072480, -396890720, -361415584, -317786848, -267324960, -211492304, - -151851792, -90023688, -27642056, 33688092, 92431824, 147162464, 196595872, 239620272, - 275320544, 302996800, 322176864, 332622304, 334328064, 327516064, 312622880, 290282112, - 261301872, 226638432, 187366672, 144647984, 99697160, 53748436, 8022341, -36306296, - -78138080, -116475864, -150447968, -179327376, -202546304, -219706160, -230582416, -235124880, - -233452928, -225846496, -212732912, -194670144, -172327120, -146461568, -117896304, -87494416, - -56134348, -24685366, 6015840, 35186796, 62118600, 86192504, 106893400, 123819856, - 136690672, 145347696, 149755152, 149995552, 146262368, 138849824, 128140336, 114589888, - 98711832, 81059840, 62210316, 42744900, 23233612, 4218996, -13798199, -30371520, - -45119144, -57731856, -67978520, -75708944, -80854288, -83424880, -83505872, -81250776, - -76873240, -70637384, -62847076, -53834452, -43948188, -33541804, -22962404, -12540202, - -2579104, 6651381, 14922708, 22052188, 27906138, 32401252, 35504228, 37229756, - 37636996, 36824736, 34925464, 32098614, 28523208, 24390258, 19895138, 15230230, - 10578097, 6105390, 1957699, -1744518, -4908812, -7472372, -9402388, -10695210, - -11374340, -11487438, -11102430, -10302999, -9183557, -7844043, -6384651, -4900844, - -3478715, -2191066, -1094124, -225317, 398208, 779956, 943926, 936293, - 833844, 703157, 565034, 427621, 299915, 188242, 97070, 28671, - -16282, -38631, -40246, -23848, 7370, 49924, 100305, 155103, - 211184, 265743, 316398, 361188, 398601, 427542, 447320, 457596, - 458351, 449838, 432541, 407131, 374438, 335404, 291067, 242523, - 190911, 137380, 83081, 29131, -23391, -73477, -120193, -162709, - -200302, -232373, -258456, -278222, -291483, -298191, -298431, -292422, - -280496, -263099, -240767, -214119, -183837, -150654, -115335, -78667, - -41439, -4430, 31603, 65943, 97920, 126924, 152420, 173951, - 191152, 203753, 211586, 214590, 212809, 206390, 195581, 180724, - 162245, 140642, 116472, 90338, 62871, 34716, 6512, -21115, - -47577, -72327, -94874, -114790, -131717, -145374, -155554, -162130, - -165050, -164338, -160089, -152466, -141696, -128062, -111900, -93592, - -73557, -52247, -30134, -7706, 14546, 36139, 56604, 75501, - 92426, 107025, 118997, 128106, 134187, 137146, 136964, 133700, - 127480, 118502, 107020, 93345, 116040, 106373, 94004, 79158, - 62121, 43240, 22912, 1579, -20281, -42169, -63569, -83966, - -102856, -119760, -134234, -145882, -154369, -159426, -160859, -158557, - -152493, -142728, -129410, -112770, -93122, -70853, -46417, -20326, - 6860, 34548, 62118, 88942, 114393, 137861, 158767, 176575, - 190802, 201034, 206937, 208261, 204852, 196660, 183736, 166241, - 144442, 118709, 89511, 57407, 23039, -12886, -49603, -86311, - -122184, -156394, -188125, -216596, -241075, -260902, -275496, -284383, - -287194, -283688, -273753, -257415, -234835, -206316, -172290, -133320, - -90085, -43369, 5950, 56922, 108538, 159746, 209478, 256659, - 300236, 339190, 372562, 399462, 419103, 430808, 434043, 428427, - 413772, 390087, 357626, 316892, 268676, 214058, 154439, 91515, - 27295, -35962, -95765, -149503, -194502, -228208, -248287, -252875, - -240711, -211453, -165805, -105883, -35276, 40539, 114314, 176503, - 215759, 217978, 167946, 29216, -265669, -759935, -1454826, -2329191, - -3341857, -4434792, -5535889, -6563153, -7428902, -8044769, -8326572, -8199427, - -7602384, -6492797, -4849871, -2677498, -5997, 3107152, 6577829, 10296906, - 14133125, 17937022, 21545892, 24789544, 27496750, 29502072, 30652904, 30816402, - 29886096, 27787848, 24484978, 19982264, 14328683, 7618649, -8275, -8369346, - -17242212, -26370120, -35468600, -44233488, -52350068, -59503100, -65387360, -69718488, - -72243656, -72751784, -71082920, -67136432, -60877660, -52342804, -41641768, -28958772, - -14550630, 1257369, 18077938, 35470524, 52952152, 70010080, 86115976, 100741256, - 113373128, 123530864, 130781872, 134756976, 135164528, 131802696, 124569704, 113471440, - 98626208, 80266312, 58736392, 34488268, 8072537, -19873172, -48638900, -77459776, - -105535736, -132052984, -156206736, -177224544, -194389536, -207063008, -214705568, -216896176, - -213348592, -203924480, -188642880, -167685488, -141397504, -110283944, -75001352, -36344852, - 4768980, 47323316, 90225720, 132335712, 172494592, 209556688, 242421216, 270063936, - 291567712, 306150848, 313192864, 312256320, 303104480, 285713824, 260281152, 227224928, - 187180496, 140989248, 89681992, 34456540, -23349740, -82291968, -140853584, -197485040, - -250644464, -298839136, -340666720, -374855200, -400300192, -416098816, -421578912, -416322848, - -400184960, -373302304, -336098016, -289277056, -233814336, -170935472, -102090216, -28919474, - 46783608, 123117448, 198119696, 269817600, 336279616, 395667328, 446285568, 486630272, - 515431904, 531693952, 534724512, 524161024, 499986336, 462536352, 412498304, 350899776, - 279088736, 198704400, 111640296, 19999716, -73955136, -167859072, -259303504, -345898400, - -425334720, -495445856, -554266496, -600087168, -631503040, -647455744, -647266496, -630660352, - -597779904, -549188672, -485863232, -409174688, -320859648, -222981056, -117879984, -8119592, - 103577704, 214398032, 321507232, 422123680, 513590720, 593446784, 659491904, 709847616, - 743010112, 757894080, 753866240, 730767680, 688924608, 629145984, 552709376, 461334048, - 357142464, 242611072, 120511064, -6158985, -134247200, -260527344, -381780576, -494877952, - -596861632, -685022336, -756971776, -810707072, -844666432, -857773504, -849470528, -819737792, - -769099840, -698617600, -609866880, -504903104, -386213792, -256659104, -119402648, 22166518, - 164518080, 304069184, 437275360, 560721088, 671207872, 765837888, 842089984, 897887232, - 931653440, 942357376, 929543168, 893346752, 834496704, 754300416, 654615040, 537804480, - 406682912, 264446352, 114594352, -39157032, -192968032, -342971968, -485373120, -616543680, - -733116800, -832073664, -910822080, -967264896, -999856064, -1007642752, -990292800, -948106752, - -882013184, -793548800, -684822016, -558462848, -417558400, -265576992, -106281872, 56362708, - 218291040, 375438528, 523844608, 659753344, 779709440, 880646656, 959966976, 1015607872, - 1046096320, 1050588096, 1028890880, 981471296, 909444864, 814549696, 699104192, 565949568, - 418379808, 260058736, 94928648, -72889120, -239197984, -399832192, -550762240, -688196992, - -808680064, -909177600, -987155392, -1040643904, -1068288256, -1069383232, -1043891456, -992444800, - -916328960, -817451520, -698297344, -561877056, -411613792, -251225136, -84665176, 83959240, - 250492800, 410833184, 561032192, 697392512, 816558400, 915598016, 992075520, 1044110528, - 1070424512, 1070372096, 1043956672, 991830592, 915278784, 816187328, 696996800, 560642560, - 410482208, 250213232, 83781792, -84714288, -251126384, -411357152, -561461504, -697743552, - -816847808, -915841536, -992287296, -1044302592, -1070606528, -1070551232, -1044137856, -992016512, - -915470336, -816383744, -697196352, -560842560, -410679552, -250404528, -83963680, 84544936, - 250972336, 411220768, 561344576, 697647424, 816773248, 915788800, 992256192, 1044292480, - 1070616448, 1070579840, 1044183488, 992077376, 915544384, 816468800, 697290112, 560942720, - 410783712, 250510352, 84068912, -84442472, -250874656, -411129728, -561261824, -697574272, - -816710848, -915738048, -992217536, -1044266240, -1070602624, -1070578112, -1044193344, -992097920, - -915574656, -816507712, -697336256, -560994752, -410840192, -250569808, -84129840, 84381496, - 250815008, 411072672, 561208512, 697525760, 816667968, 915701504, 992187968, 1044243968, - 1070587840, 1070570944, 1044193664, 992105472, 915588992, 816528256, 697362432, 561025728, - 410875072, 250607648, 84169704, -84340632, -250774144, -411032768, -561170496, -697490560, - -816636288, -915674048, -992165248, -1044226432, -1070575744, -1070564352, -1044192576, -992109760, - -915598336, -816542272, -697380608, -561047424, -410899648, -250634432, -84197944, 84311648, - 250745136, 411004448, 561143488, 697465472, 816613632, 915654272, 992148736, 1044213504, - 1070566592, 1070559104, 1044191232, 992112320, 915604608, 816552064, 697393600, 561063296, - 410917984, 250654720, 84219640, -84289112, -250722352, -410981984, -561121984, -697445376, - -816595520, -915638656, -992135872, -1044203776, -1070560128, -1070556032, -1044191616, -992116032, - -915611456, -816561792, -697405888, -561077696, -410934112, -250672080, -84237752, 84270736, - 250704176, 410964480, 561105536, 697430400, 816582400, 915627520, 992127104, 1044197440, - 1070556416, 1070555008, 1044193216, 992120256, 915618176, 816570816, 697417024, 561090688, - 410948576, 250687680, 84254088 + -96495528, -286734272, -468692800, -637041216, -786562176, -912433280, -1009964416, -1075182976, -1098333440, + -1060972224, -954328512, -784950848, -567387776, -321857280, -71378072, 161019520, 355191072, + 496249664, 576290688, 595228096, 560553408, 486341472, 391112608, 296445024, 219833024, + 161425424, 113971872, 75074912, 43676944, 18947558, 106207, -13606639, -22959300, + -28697174, -31541624, -32158708, -31154358, -29054292, -26304144, -23261552, -20202826, + -17324756, -14756116, -12565362, -10774012, -9366401, -8302065, -7524551, -6970827, + -6577419, -6286071, -6046737, -5819771, -5576294, -5297871, -4975268, -4606808, + -4196583, -3752523, -3284873, -2804624, -2322651, -1848752, -1391471, -957667, + -552820, -180887, 155183, 453533, 712892, 932744, 1112922, 1253892, + 1356428, 1421957, 1452251, 1449752, 1417222, 1357998, 1275581, 1173833, + 1056523, 927513, 790325, 648358, 504521, 361522, 221574, 86743, + -41290, -160871, -270597, -368994, -454781, -526614, -583403, -624117, + -648145, -655120, -645267, -619210, -578251, -524110, -459110, -385841, + -307254, -226274, -145851, -68575, 3253, 67950, 124299, 171779, + 210318, 240423, 262847, 278659, 288884, 294565, 296445, 295082, + 290614, 282963, 271701, 256332, 236226, 210937, 180155, 143993, + 102888, 57812, 10083, -38529, -86081, -130429, -169562, -201608, + -225146, -239179, -243376, -237949, -223786, -202225, -175080, -144342, + -112142, -80430, -50955, -24990, -3380, 13628, 26240, 35170, + 41402, 46169, 50665, 56013, 62999, 72081, 83214, 95949, + 109364, 122266, 133211, 140767, 143575, 140609, 131207, 115267, + 93186, 65957, 34996, 2134, -30636, -61239, -87791, -108676, + -122781, -129495, 12356724, 36406252, 58390684, 76977432, 90719600, 98265728, + 98008264, 88608552, 62420976, 2547174, -98862584, -234978608, -391650304, -549723776, + -687929024, -785620992, -825677888, -796781568, -695135040, -525144384, -299188480, -36327380, + 239749920, 503413376, 729982272, 898556864, 994367488, 1010422464, 948197568, 817333696, + 634343104, 420516896, 199273200, -6719048, -178276784, -302004160, -371805248, -389615456, + -365008416, -315253344, -262675984, -217917568, -178521248, -143001072, -111343304, -83569488, + -59728692, -39750832, -23483756, -10668693, -980101, 5968707, 10589352, 13306198, + 14527738, 14637296, 13974127, 12830675, 11443325, 9996437, 8620832, 7402724, + 6386965, 5588127, 4995412, 4583292, 4315642, 4154179, 4060473, 4001515, + 3949354, 3884093, 3791711, 3665350, 3502261, 3304372, 3075215, 2820550, + 2545809, 2257129, 1959450, 1657946, 1356600, 1059795, 771079, 494646, + 234059, -6519, -223731, -414017, -575061, -704879, -803133, -870150, + -907983, -919252, -907936, -878057, -834296, -780659, -721070, -658192, + -594157, -529649, -464852, -398810, -330536, -258557, -182049, -100384, + -14134, 75538, 166137, 254665, 337160, 409716, 468199, 509317, + 530349, 530086, 508400, 466928, 408381, 336929, 257279, 174830, + 94651, 21581, -40724, -89563, -123905, -143909, -151339, -148811, + -139947, -128462, -118197, -112219, -112926, -121327, -137375, -159531, + -185372, -211440, -234054, -249316, -253979, -245431, -222426, -184880, + -134334, -73467, -6263, 62723, 128418, 186074, 231361, 261147, + 273444, 267948, 261810, 763373, 1198560, 1499796, 1578270, 1304628, + 517808, -987783, -3443484, -7111908, -12256820, -19143168, -27996048, -39000040, + -52248820, -67752040, -85376464, -104873664, -125808744, -147634944, -169591248, -190910720, + -210637232, -228834976, -242239792, -233744176, -184602112, -88256112, 52564248, 227312048, + 419154080, 607121280, 768828480, 883312000, 933778624, 909811200, 808862336, 636755584, + 407214048, 140391440, -139342896, -406167488, -635714880, -807834944, -908809408, -932820096, + -882419648, -768029696, -606446400, -418634368, -226977824, -52442412, 88143752, 184240560, + 233125792, 241364816, 227710480, 209276640, 189331712, 167814560, 145682224, 123701848, + 102633120, 83021960, 65302000, 49722020, 36415812, 25376218, 16511686, 9640718, + 4539034, 941445, -1420767, -2818065, -3495818, -3676385, -3542409, -3243683, + -2888735, -2555377, -2287831, -2108851, -2019462, -2010501, -2062586, -2155553, + -2267238, -2380241, -2479146, -2554886, -2600826, -2615545, -2598567, -2552488, + -2479078, -2381454, -2260948, -2119607, -1957826, -1777065, -1577959, -1362941, + -1134431, -897064, -655697, -417094, -187702, 25095, 215280, 377113, + 507239, 603471, 666470, 698219, 703186, 686502, 654728, 613906, + 570192, 528056, 491058, 460427, 436171, 416130, 397422, 375887, + 347709, 309014, 257411, 191469, 111939, 20899, -77459, -178052, + -274516, -360654, -430246, -478480, -501684, -498487, -469248, -416789, + -345433, -261310, -171090, -82033, -635, 67321, 117943, 148920, + 160318, 153895, 133448, 103776, 70703, 39859, 16616, 4954, + 7564, 25024, 56260, 98143, 146331, 195238, 239125, 272241, + 289930, 288679, 266989, 225117, 165550, 92349, 11219, -71466, + -148857, -214705, -263567, -291740, -297224, -280306, -243136, -189895, + -125985, -57873, 7933, 65157, 108741, 134971, 142193, 130597, + 102524, 61859, 13944, -35316, -79751, -113898, -133249, -135053, + -118286, -84087, -35339, 23302, 86186, 146930, 199365, 237874, + 258253, 257864, 236196, 194657, 136724, 67341, -7287, -80567, + -145896, -270343, -808574, -1340072, -1858807, -2358665, -2831742, -3270963, + -3669340, -4023521, -4333619, -4606985, -4857566, -5108708, -5390687, -5741295, + -6200425, -6807718, -7593886, -8575752, -9745172, -11063108, -12448231, -13772797, + -14853837, -15454158, -15279006, -13985197, -11185029, -6465256, 602227, 10431847, + 23410894, 39863840, 60045788, 84103768, 112100696, 143979968, 179711728, 219302416, + 264231232, 316950432, 366815488, 391499840, 373734272, 303947296, 180205328, 8607086, + -197450336, -418782432, -632721152, -815848960, -946877184, -1009294400, -993460928, -897898880, + -729596672, -503316064, -239947616, 35840880, 298430624, 524143840, 693923584, 795387200, + 824107840, 783846592, 685860544, 547189184, 388365568, 230527600, 92671240, -11219515, + -74492144, -105158200, -120261872, -127544112, -128388320, -124354624, -116661448, -106489408, + -94793200, -82429304, -70062176, -58237700, -47334588, -37619828, -29226616, -22202334, + -16501587, -12028281, -8635400, -6159899, -4423260, -3257870, -2504859, -2031762, + -1726474, -1507393, -1314142, -1112384, -883004, -624119, -340602, -45467, + 248842, 528315, 783713, 1007231, 1196662, 1351165, 1473983, 1568019, + 1637995, 1686519, 1716364, 1727429, 1719421, 1689696, 1636232, 1556028, + 1448006, 1311510, 1148760, 963094, 760758, 548770, 336091, 131254, + -56814, -221101, -355658, -457521, -525555, -561787, -569830, -555666, + -525766, -487535, -447411, -411297, -382938, -364634, -356100, -355594, + -359287, -362732, -360583, -348172, -321291, -277591, -216139, -138411, + -47457, 51579, 152676, 248783, 333218, 399646, 443388, 461240, + 452449, 418164, 361960, 288882, 205559, 118975, 36377, -35977, + -92851, -131037, -149092, -147929, -130154, -100234, -63486, -25973, + 6639, 29226, 38204, 31469, 9051, -27322, -73989, -126155, + -177996, -223678, -257577, -275273, -273644, -251592, -209808, -151108, + -79807, -1677, 76962, 149510, 210060, 253638, 277008, 278653, + 259231, -101021, -297456, -477733, -632297, -753728, -836696, -878615, + -879031, -839751, -763739, -654959, -517096, -353514, -166209, 43748, + 276781, 533724, 815969, 1123958, 1457300, 1813342, 2187857, 2574262, + 2965417, 3353797, 3734536, 4106324, 4475222, 4855377, 5272512, 5763051, + 6375849, 7168185, 8204533, 9548340, 11257436, 13371571, 15905385, 18833006, + 22081010, 25512624, 28924300, 32032662, 34478724, 35820256, 35546928, 33078728, + 27793346, 19027280, 6112874, -11628489, -34851840, -64232176, -100493888, -144608256, + -198909072, -270631488, -359662496, -448624032, -516131776, -543967680, -518454176, -432622496, + -287176640, -90768024, 140893552, 386715040, 622670976, 824595136, 971067648, 1045974272, + 1040467264, 954060352, 794731136, 578022784, 325234560, 60958056, -189791088, -404423968, + -565354624, -661869440, -691213888, -658569600, -576189312, -461441856, -334519392, -215323504, + -121182328, -57886044, -14972652, 16811060, 39759696, 55435020, 65035460, 69706136, + 70441104, 68189248, 63775032, 57948004, 51329736, 44447116, 37701544, 31399154, + 25736924, 20832988, 16723796, 13393488, 10776430, 8783249, 7304115, 6229334, + 5450365, 4874027, 4420041, 4029271, 3658127, 3282309, 2889391, 2480032, + 2060348, 1642421, 1237795, 858544, 512575, 205752, -60998, -288674, + -481834, -645256, -785054, -905653, -1011013, -1102347, -1179780, -1240896, + -1282805, -1301283, -1292960, -1254661, -1185341, -1085250, -957344, -806069, + -638185, -461195, -283738, -113885, 40607, 173836, 281340, 361227, + 413418, 440281, 445517, 434398, 412451, 385525, 358529, 335589, + 319068, 309999, 307515, 309612, 312947, 313829, 308220, 292759, + 264732, 222913, 167314, 99696, 23013, -58414, -139717, -215530, + -280898, -331372, -363803, -376281, -368659, -342216, -299851, -245477, + -183947, -120287, -59527, -210294, -218804, -207034, -170663, -107684, + -17542, 97483, 233628, 384636, 543572, 702055, 852320, 986414, + 1098210, 1182279, 1235630, 1256080, 1243695, 1198697, 1122785, 1016812, + 882318, 719277, 528144, 307851, 58485, -220576, -527549, -860384, + -1213683, -1581737, -1955989, -2329539, -2695405, -3052665, -3405215, -3769076, + -4170617, -4653891, -5276647, -6116192, -7261256, -8815022, -10881268, -13564073, + -16947616, -21093540, -26015144, -31675226, -37956612, -44665032, -51498380, -58060316, + -63829408, -68189520, -70395848, -69627624, -64938208, -55334156, -39669268, -16742548, + 15011598, 57892376, 121157856, 215274688, 334456672, 461378272, 576139200, 658546880, + 691230336, 661933376, 565469888, 404588960, 189999104, -60718748, -324979552, -577770304, + -794500352, -953869504, -1040332032, -1045906432, -971073600, -824675520, -622820672, -386923360, + -141145440, 90490632, 286893152, 432351840, 518213184, 543769536, 515984864, 448531552, + 359622208, 270636384, 198948336, 144668672, 100561448, 64293740, 34896780, 11649924, + -6117171, -19054578, -27836140, -33125540, -35583508, -35831208, -34449244, -31950346, + -28780702, -25304532, -21811144, -18510242, -15544263, -12991323, -10880449, -9198353, + -7904592, -6938712, -6232849, -5716818, -5326765, -5007114, -4715109, -4419761, + -4103101, -3757115, -3383050, -2987624, -2581751, -2177166, -1785567, -1416314, + -1076470, -769692, -497117, -257162, -46868, 137886, 301064, 446309, + 576003, 691438, 792390, 877665, 945087, 992265, 1016767, 1016861, + 991628, 941464, 867976, 774150, 663993, 542420, 414732, 286370, + 162380, 47204, -55707, -143950, -216326, -272693, -313915, -341561, + -357718, -364650, -364603, -359521, -350944, -339867, -326770, -311628, + -294057, -273429, -249069, -220397, -187092, -149183, -107127, -61803, + -14483, 33260, 79674, 122959, 161417, 193583, -137153, -86096, + -23462, 46165, 118296, 188311, 252569, 308033, 353183, 387345, + 411326, 426448, 434961, 438884, 440375, 440558, 440044, 437930, + 432614, 421046, 399869, 364878, 312384, 238720, 141646, 19702, + -126527, -295376, -483051, -684957, -894831, -1106337, -1312215, -1505978, + -1680884, -1831578, -1952736, -2040617, -2091372, -2102604, -2071473, -1996480, + -1875541, -1708206, -1493799, -1234127, -931547, -591976, -222473, 165877, + 561490, 950008, 1319512, 1659151, 1966270, 2245658, 2518227, 2819813, + 3210306, 3770160, 4608328, 5854141, 7662371, 10198175, 13638330, 18147660, + 23877010, 30930782, 39364468, 49144104, 60148836, 72123392, 84694024, 97312800, + 109298904, 119765360, 127705376, 131866912, 130934488, 123231464, 107234464, 75050672, + 9470806, -97677456, -239897616, -403333024, -569087680, -716066368, -823729024, -874943616, + -858298112, -769767616, -613463168, -401328448, -152012800, 111316600, 362752096, 579800640, + 754066560, 884317376, 967646720, 1002358976, 988932224, 930137792, 830908864, 698079680, + 539965760, 365883200, 185588480, 8720114, -155758112, -300047104, -417930816, -505075680, + -559213504, -580180096, -569826624, -531795520, -471193568, -394169856, -307444800, -217803664, + -131610264, -54348980, 9748328, 57999172, 89445504, 104945984, 107368432, 102279568, + 94596192, 85655480, 75877136, 65846368, 56016016, 46757852, 38321108, 30867838, + 24467266, 19124186, 14784349, 11357873, 8727069, 6764325, 5338255, 4325655, + 3614320, 3109507, 2733412, 2427369, 2148937, 1871452, 1580043, 1270071, + 943252, 606145, 267130, -64446, -380185, -672695, -936550, -1167777, + -1364195, -1524669, -1649207, -1738275, -1792904, -1814221, -1803670, -1762759, + -1693364, -1597596, -1478091, -1337881, -1180581, -1010189, -831132, -647987, + -465420, -287874, -119474, 36238, 176365, 298810, 402244, 486148, + 550683, 596630, 625208, 637968, 636614, 622900, 598511, 565006, + 523771, 476024, 422831, 365155, 303902, 239978, 174336, 108003, + 42099, -22177, -83566, -140800, -192647, -237981, -275829, -305435, + -326287, -338158, -341095, -335431, -321739, -300823, -273643, -241298, + -204944, -165780, -124974, -83660, -42880, 10137, 29849, 47985, + 63702, 76520, 86314, 93425, 98550, 102746, 107236, 113334, + 122202, 134769, 151505, 172398, 196816, 223585, 250966, 276853, + 298844, 314511, 321522, 317919, 302199, 273538, 231774, 177523, + 112040, 37218, -44643, -130911, -218896, -305922, -389579, -467717, + -538627, -600924, -653636, -695990, -727439, -747408, -755314, -750348, + -731559, -697715, -647504, -579487, -492405, -385195, -257342, -108895, + 59211, 245234, 446381, 659034, 878627, 1100007, 1317397, 1524851, + 1716231, 1885675, 2027510, 2136678, 2208531, 2239209, 2225330, 2164370, + 2054318, 1894140, 1683476, 1423258, 1115462, 763860, 373717, -47467, + -490570, -944379, -1396841, -1835173, -2248037, -2626382, -2966637, -3272111, + -3556917, -3847305, -4185583, -4630274, -5258922, -6165632, -7461554, -9268313, + -11715324, -14927984, -19021866, -24085232, -30171698, -37277344, -45335748, -54189964, + -63598244, -73198584, -82549584, -91078392, -98377112, -103118416, -100391208, -84628624, + -52954552, -4492618, 59827860, 137363792, 223933312, 314109568, 401591168, 479653696, + 541630720, 581410176, 593897728, 575427264, 524078976, 439891712, 324946016, 183315184, + 20883088, -154960944, -335730752, -512333504, -675605952, -816870016, -928462720, -1004220224, + -1039868736, -1033319296, -984830528, -897064000, -775182272, -627308096, -461708352, -284291552, + -100579392, 83598736, 262525088, 430732416, 583209600, 715532736, 824009920, 905775040, + 958871552, 982291840, 975995776, 940888192, 878773504, 792274432, 684731072, 560072576, + 422675872, 277208288, 128466608, -18787604, -159985744, -290901824, -407785088, -507474624, + -587489088, -646091776, -682326144, -696024192, -687785152, -658928000, -611418688, -547776704, + -470963680, -384259392, -291130144, -195094672, -99592464, -7860071, 77180528, 153017120, + 217622960, 269510560, 307761952, 332035072, 342546656, 340033376, 325693088, 301109632, + 268164672, 228941216, 185622192, 140390128, 95330560, 52345244, 13076479, -21151680, + -49376268, -71017224, -85881800, -94147080, -96327536, -93222768, -85856648, -75400496, + -63097824, -50176000, -37774988, -26857674, -18169908, -11863887, -7301392, -3914018, + -1479242, 185291, 1236420, 1817970, 2053955, 2052907, 1903852, 1679448, + 1434536, 1209401, 1029974, 911183, 857962, 868350, 934655, 1046022, + 1189342, 1351150, 1518125, 1678330, 1821294, 1938725, 2024278, 2073883, + 2085335, 2058391, 1994281, 1895693, 1766278, 1610593, 1433645, 1240831, + 1037545, 829139, 620601, 416556, 221024, 37473, -131344, -283279, + -416878, -531220, -625958, -701127, -757159, -794697, -814605, -817824, + -805400, -778384, -737905, -685103, -621229, -547610, -465741, -377252, + -283979, -187900, -91166, 4001, 95326, 180608, 257764, 324972, + 380709, 423871, 453787, 470280, 473637, 464613, 444338, 414280, + 376112, 331644, 282692, 231012, 178188, 125609, 74399, 25440, + -20646, -63433, -102670, -138199, -169921, -197722, -221454, -240892, + -255747, -265667, -270281, -269233, -262252, -249189, -230092, -205221, + -175099, -140492, -102411, -62059, -20785, 19997, 58880, 94556, + 125879, 151942, 172113, 186075, 193810, 195596, 191955, 183604, + 171377, 156168, 138843, 120200, 100900, 81458, 62216, 43368, + 24971, 6998, -10624, -27957, -45013, -61705, -77836, -93079, + -106999, -119067, -128714, -135370, -138532, -137806, -132971, -123999, + -111091, -94667, -75361, -53969, 10765, 32074, 52722, 72311, + 90486, 106963, 121523, 134027, 144392, 152600, 158658, 162605, + 164468, 164267, 161985, 157577, 150955, 142011, 130615, 116649, + 100019, 80692, 58704, 34200, 7431, -21221, -51265, -82083, + -112977, -143167, -171845, -198187, -221409, -240776, -255657, -265518, + -269970, -268744, -261725, -248915, -230452, -206572, -177616, -143996, + -106204, -64784, -20348, 26444, 74865, 124130, 173377, 221686, + 268054, 311432, 350709, 384766, 412472, 432751, 444591, 447117, + 439606, 421553, 392681, 352994, 302769, 242592, 173323, 96118, + 12366, -76299, -168083, -261025, -353085, -442152, -526117, -602884, + -670441, -726859, -770364, -799329, -812348, -808221, -786031, -745129, + -685209, -606288, -508783, -393474, -261578, -114689, 45155, 215561, + 393723, 576534, 760547, 942104, 1117306, 1282158, 1432549, 1564416, + 1673729, 1756688, 1809722, 1829726, 1814087, 1760970, 1669365, 1539414, + 1372449, 1171316, 940345, 685584, 414591, 136477, -138614, -399774, + -636264, -838162, -997771, -1110606, -1177191, -1204204, -1206433, -1207707, + -1242622, -1356751, -1607660, -2063815, -2804506, -3917005, -5495374, -7636020, + -10436517, -13992514, -18402674, -23818388, -30616280, -38795064, -47468192, -55465196, + -61624760, -64816688, -64030596, -58439904, -47471160, -30852034, -8650500, 18708296, + 50440096, 85421744, 122227560, 159185040, 194443776, 226058080, 252076752, 270638720, + 280067616, 278963616, 266285680, 241422224, 204245248, 155146128, 95049592, 25405990, + -51839956, -134302160, -219227456, -303587872, -384188544, -457786240, -521215424, -571515392, + -606054656, -622647040, -619654592, -596072512, -551593600, -486646944, -402411264, -300798944, + -184413264, -56477480, 79260352, 218645328, 357251200, 490529920, 613968768, 723250432, + 814409344, 883978944, 929123648, 947751552, 938601472, 901303104, 836405248, 745373248, + 630551936, 495099232, 342887840, 178382704, 6494100, -167583760, -338549120, -501169472, + -650463872, -781868416, -891402304, -975790912, -1032769600, -1061261696, -1060915456, -1031960960, + -975385600, -892916224, -786977856, -660620736, -517435968, -361449888, -197010624, -28662768, + 138980608, 301369056, 454141632, 593248768, 715063168, 816478784, 894992576, 948769664, + 976686784, 978356608, 954128576, 905069824, 832924288, 740053568, 629360000, 504194944, + 368255424, 225472400, 79893288, -64436384, -203589744, -333869568, -451910592, -554770112, + -640004160, -705727744, -750656768, -774131456, -776120512, -757206720, -718553856, -661857536, + -589281088, -503378688, -407008864, -303241088, -195258304, -86258672, 20640266, 122492392, + 216605760, 300615264, 372542752, 430843584, 474437952, 502727104, 515593600, 513386816, + 496894016, 467298720, 426127872, 375190336, 316508064, 252243568, 184625248, 115873648, + 48130852, -16604751, -76536328, -130117360, -176090096, -213512624, -241774240, -260598816, + -270036736, -270445792, -262462656, -246965456, -225030192, -197881696, -166842016, -133277536, + -98547200, -63953468, -30697916, 157309, 27720696, 51294532, 70389352, 84729480, + 94249824, 99084304, 99546808, 96105616, 89352656, 79969008, 68688296, 56259452, + 43410724, 30816176, 19066356, 8644033, -93590, -6926218, -11773978, -14694671, + -15872813, -15605618, -14280676, -12378042, -10430668, -8704424, -7182491, -5854782, + -4729147, -3804335, -3072066, -2516383, -2116394, -1847634, -1684290, -1600530, + -1572012, -1576721, -1595767, -1613665, -1618550, -1602016, -1558925, -1486975, + -1386301, -1258946, -1108416, -939180, -756297, -565028, -370575, -177839, + 8715, 185182, 348246, 495214, 623986, 733038, 821363, 888436, + 934161, 958831, 963086, 947887, 914478, 864367, 799293, 721209, + 632236, 534643, 430794, 323115, 214029, 105923, 1076, -98376, + -190504, -273617, -346304, -407458, -456294, -492355, -515505, -525917, + -524051, -510616, -486547, -452951, -411079, -362277, -307954, -249541, + -188465, -126117, -63839, -2894, 55536, 110376, 160649, 205502, + 244200, 276144, 300872, 318070, 327574, 329385, 323660, 310724, + 291059, 265298, 234214, 198698, 159739, 118393, 75754, 32922, + -9033, -49104, -86375, -120044, -149449, -174076, -193569, -207727, + -216503, -219983, -218381, -212007, -201261, -186599, -168524, -147564, + -124261, -99161, -72807, -45733, -18468, 8473, 34584, 59372, + 82359, 103090, 121141, 136131, 147730, 155680, 159803, 160015, + 156337, 148897, 137934, 123794, 106916, 87821, 67091, 45345, + 23216, 1326, -19743, -39465, 109887, 120382, 128416, 133765, + 136261, 135794, 132320, 125859, 116497, 104388, 89749, 72858, + 54047, 33695, 12222, -9922, -32266, -54329, -75626, -95683, + -114044, -130284, -144009, -154878, -162593, -166923, -167696, -164811, + -158239, -148026, -134294, -117244, -97153, -74370, -49314, -22469, + 5628, 34390, 63198, 91407, 118365, 143426, 165965, 185395, + 201183, 212860, 220042, 222435, 219848, 212195, 199508, 181929, + 159715, 133233, 102952, 69434, 33331, -4639, -43696, -83016, + -121744, -159013, -193957, -225733, -253530, -276597, -294249, -305894, + -311042, -309326, -300512, -284516, -261407, -231423, -194963, -152600, + -105060, -53228, 1881, 59128, 117284, 175043, 231069, 284005, + 332527, 375354, 411300, 439283, 458370, 467783, 466935, 455431, + 433101, 399985, 356360, 302726, 239820, 168592, 90219, 6068, + -82296, -173156, -264641, -354785, -441533, -522811, -596538, -660703, + -713385, -752830, -777471, -786003, -777391, -750944, -706300, -643488, + -562898, -465330, -351937, -224267, -84196, 66044, 223948, 386697, + 551263, 714370, 872609, 1022412, 1160192, 1282340, 1385409, 1466141, + 1521718, 1549819, 1548936, 1518450, 1458982, 1372447, 1262386, 1133907, + 993924, 850871, 714752, 596518, 507835, 460031, 463573, 526525, + 653821, 845263, 1094812, 1388217, 1702729, 2004387, 2248836, 2377871, + 2322716, 1997670, 1310909, 31361, -2276023, -5884963, -10790734, -16840258, + -23748608, -31120974, -38472224, -45255760, -50892408, -54804412, -56448304, -55348896, + -51129788, -43541476, -32483506, -18021422, -395893, 19975162, 42503072, 66442420, + 90913264, 114929960, 137436576, 157346768, 173587488, 185144144, 191106144, 190710336, + 183381248, 168765648, 146760624, 117533176, 81530704, 39481248, -7616625, -58514600, + -111745512, -165663824, -218494432, -268388400, -313484064, -351971232, -382156480, -402527424, + -411813344, -409040128, -393577504, -365176384, -323994752, -270611200, -206024384, -131639056, + -49237472, 39062252, 130860688, 223542656, 314352192, 400474784, 479124064, 547630784, + 603530816, 644649344, 669178624, 675746624, 663473536, 632014912, 581589056, 512987520, + 427568224, 327230528, 214373088, 91835128, -37177272, -169178032, -300498464, -427392512, + -546146752, -653191616, -745210944, -819245440, -872788352, -903868288, -911118272, -893827520, + -851974272, -786238976, -697996288, -589286400, -462766208, -321640832, -169578832, -10611593, + 150978672, 310780032, 464377088, 607478720, 736043264, 846397952, 935348160, 1000273472, + 1039207744, 1050900416, 1034856960, 991357632, 921452992, 826937088, 710298944, 574652800, + 423651328, 261382080, 92266240, -79072984, -248102448, -410503776, -562126720, -699092736, + -817911936, -915573376, -989624896, -1038234688, -1060238592, -1055167808, -1023259008, -965445760, + -883330880, -779142016, -655670144, -516193728, -364390176, -204236960, -39905496, 124349848, + 284304192, 435873248, 575219968, 698854144, 803721536, 887281600, 947570240, 983247040, + 993625152, 978684224, 939064256, 876042880, 791495168, 687838208, 567961280, 435144608, + 292968064, 145212944, -4240369, -151516576, -292848000, -424673056, -543728192, -647130176, + -732447680, -797759168, -841696640, -863474048, -862898880, -840368384, -796849536, -733844032, + -653339328, -557747648, -449833824, -332635680, -209377712, -83381528, 42024892, 163596368, + 278255872, 383173696, 475838368, 554117568, 616307264, 661168640, 687951104, 696401792, + 686761024, 659744256, 616512064, 558627584, 488004704, 406847392, 317582464, 222787984, + 125119136, 27233782, -68280144, -158973472, -242598960, -317167264, -380994112, -432737696, + -471425664, -496470656, -507674976, -505223904, -489668640, -461899200, -423108800, -374750624, + -318488480, -256143216, -189636144, -120931576, -51979948, 15336795, 79255984, 138179872, + 190714864, 235703648, 272249056, 299729728, 317807040, 326423456, 325792768, 316382656, + 298890368, 274212512, 243410272, 207670816, 168266608, 126513920, 83731472, 41200944, + 130175, -38379756, -73362784, -104010672, -129689920, -149952464, -164540112, -173382736, + -176590656, -174441552, -167362736, -155909328, -140739472, -122587248, -102234616, -80482928, + -58125464, -35921428, -14572560, 5297181, 23158150, 38587464, 51277008, 61037024, + 67795232, 71591800, 72570464, 70966328, 67090884, 61315048, 54050700, 45731812, + 36795552, 27664472, 18730052, 10338603, 2779584, -3722787, -9014984, -13015846, + -15715349, -17169656, -17493876, -16851572, -15443180, -13491852, -11229971, -8883501, + -6659666, -4731320, -3230436, -2179638, -1456508, -951706, -619736, -422906, + -328742, -307762, -334784, -388143, -450439, -507929, -550755, -572282, + -568989, -539768, -485654, -409163, -313997, -204481, -85334, 38748, + 163232, 284008, 397435, 500481, 590686, 666220, 725799, 768696, + 794640, 803805, 796717, 774237, 737483, 687817, 626774, 556060, + 477482, 392946, 304395, 213796, 123081, 34130, -51284, -131518, + -205101, -270753, -327424, -374293, -410797, -436619, -451696, -456198, + -450524, -435265, -411195, -379231, -340412, -295864, -246780, -194382, + -139908, -84576, -29579, 23948, 74940, 122415, 165488, 203392, + 235477, 261232, 280287, 292420, 297563, 295805, 287381, 272679, + 252217, 226642, 196699, 163225, 127113, 89298, 50723, 12319, + -25022, -60468, -93267, -122762, -148403, -169755, -186505, -198455, + -205529, -207755, -205269, -198296, -187147, -172200, -153899, -132733, + -109235, -83965, -57505, -30448, -3387, 23090, 48419, 72062, + 93519, 112344, 128152, 140629, 149540, 154739, 156171, 153875, + 147984, 138721, 126390, 111370, 94099, 75064, 54779, 33779, + 12593, -8262, -28303, -47084, 123494, 129971, 133493, 133924, + 131201, 125331, 116398, 104559, 90037, 73124, 54170, 33578, + 11793, -10702, -33406, -55797, -77356, -97567, -115939, -132009, + -145355, -155607, -162458, -165670, -165080, -160609, -152268, -140154, + -124457, -105454, -83508, -59060, -32622, -4767, 23884, 52680, + 80946, 108005, 133192, 155874, 175459, 191418, 203293, 210711, + 213394, 211167, 203964, 191828, 174916, 153495, 127939, 98723, + 66416, 31667, -4798, -42202, -79720, -116501, -151685, -184419, + -213882, -239294, -259946, -275209, -284560, -287590, -284024, -273728, + -256722, -233178, -203429, -167959, -127402, -82528, -34229, 16495, + 68562, 120826, 172104, 221199, 266929, 308151, 343787, 372847, + 394455, 407868, 412493, 407908, 393872, 370338, 337461, 295599, + 245318, 187388, 122773, 52620, -21757, -98901, -177232, -255084, + -330731, -402431, -468456, -527135, -576892, -616284, -644032, -659054, + -660495, -647746, -620468, -578601, -522379, -452338, -369318, -274467, + -169243, -55405, 64986, 189594, 315816, 440826, 561623, 675096, + 778120, 867669, 940959, 995619, 1029881, 1042792, 1034432, 1006137, + 960689, 902497, 837686, 774157, 721490, 690799, 694367, 745251, + 856581, 1040935, 1309312, 1670468, 2129651, 2688819, 3345656, 4105519, + 4976393, 5840188, 6459558, 6619945, 6147045, 4905821, 2810464, -169248, + -4002855, -8597662, -13799897, -19399282, -25136440, -30713178, -35805064, -40075928, + -43193604, -44846368, -44759276, -42709760, -38541820, -32178052, -23629058, -12999656, + -491521, 13597969, 28880844, 44887552, 61079704, 76866240, 91622528, 104711816, + 115508400, 123421568, 127919688, 128553392, 124977088, 116967832, 104440944, 87461480, + 66251100, 41189824, 12812431, -18200672, -51037968, -84776544, -118406512, -150859520, + -181040640, -207862576, -230281344, -247332144, -258164320, -262074240, -258534976, -247221616, + -228031216, -201096704, -166793872, -125740976, -78790864, -27015406, 28317512, 85773968, + 143790256, 200714592, 254853088, 304518720, 348082144, 384022272, 410975936, 427784064, + 433533952, 427595232, 409648832, 379707872, 338129120, 285614880, 223204848, 152257552, + 74422120, -8399482, -94098672, -180413920, -264990464, -345444480, -419429888, -484706304, + -539205312, -581094272, -608834752, -621234048, -617488768, -597217728, -560484416, -507806784, + -440154880, -358935456, -265963920, -163424032, -53816484, 60102860, 175393008, 289004832, + 397862624, 498948160, 589385088, 666520704, 728003904, 771855360, 796529472, 800965376, + 784625088, 747518528, 690213376, 613829888, 520020448, 410934048, 289166720, 157698512, + 19819390, -120954952, -260974400, -396551008, -524057792, -640027584, -741248576, -824854336, + -888405760, -929962176, -948139904, -942156672, -911859520, -857736896, -780912768, -683123584, + -566678912, -434405344, -289576544, -135830144, 22925716, 182614304, 339097376, 488284896, + 626244608, 749307648, 854168576, 937975616, 998409984, 1033750912, 1042925056, 1025539008, + 981893504, 912979136, 820453376, 706599552, 574268864, 426807104, 267967136, 101810936, + -67397744, -235305840, -397586848, -550055296, -688779008, -810183040, -911146880, -989084800, + -1042054592, -1068829184, -1068826112, -1042089792, -989328512, -911898304, -811770624, -691481728, + -554069376, -402995648, -242059584, -75301504, 93098968, 258928160, 418044256, 566481536, + 700549504, 816925696, 912738304, 985637504, 1033853888, 1056241408, 1052304960, 1022211200, + 966782848, 887476096, 786342208, 665974016, 529439200, 380201408, 222031488, 58911676, + -105065728, -265801808, -419294496, -561739072, -689623232, -799814720, -889638656, -956942720, + -1000149696, -1018294336, -1011044736, -978708096, -922219648, -843115968, -743493120, -625951040, + -493525056, -349607232, -197858608, -42115448, 113708584, 265721584, 410151424, 543440192, + 662332480, 763955904, 845890496, 906227200, 943612480, 957278400, 947058112, 913385664, + 857280704, 780318336, 684585088, 572622656, 447359776, 312035584, 170115056, 25199920, + -119063552, -259076960, -391380192, -512737632, -620217856, -711264960, -783759808, -836069184, + -867082944, -876236800, -863521472, -829477248, -775175296, -702184896, -612528832, -508627616, + -393234080, -269360256, -140198384, -9038325, 120816904, 246134720, 363834016, 471061440, + 565260864, 644234816, 706195520, 749805696, 774206528, 779033856, 764420928, 730989120, + 679825600, 612449984, 530770240, 437028800, 333741664, 223630656, 109551536, -5580210, + -118864264, -227488864, -328800992, -420371296, -500052800, -566030976, -616865088, -651519232, + -669382144, -670276608, -654456960, -622595968, -575760768, -515379648, -443199648, -361236896, + -271720576, -177032864, -79645232, 17945830, 113283088, 204010512, 287931712, 363063040, + 427680576, 480359328, 520004224, 545871936, 557583232, 555125952, 538848000, 509441632, + 467918976, 415579744, 353972064, 284847840, 210113616, 131778400, 51899980, -27469024, + -104333832, -176807568, -243157520, -301846336, -351567360, -391273184, -420196800, -437865024, + -444103968, -439036576, -423072480, -396890720, -361415584, -317786848, -267324960, -211492304, + -151851792, -90023688, -27642056, 33688092, 92431824, 147162464, 196595872, 239620272, + 275320544, 302996800, 322176864, 332622304, 334328064, 327516064, 312622880, 290282112, + 261301872, 226638432, 187366672, 144647984, 99697160, 53748436, 8022341, -36306296, + -78138080, -116475864, -150447968, -179327376, -202546304, -219706160, -230582416, -235124880, + -233452928, -225846496, -212732912, -194670144, -172327120, -146461568, -117896304, -87494416, + -56134348, -24685366, 6015840, 35186796, 62118600, 86192504, 106893400, 123819856, + 136690672, 145347696, 149755152, 149995552, 146262368, 138849824, 128140336, 114589888, + 98711832, 81059840, 62210316, 42744900, 23233612, 4218996, -13798199, -30371520, + -45119144, -57731856, -67978520, -75708944, -80854288, -83424880, -83505872, -81250776, + -76873240, -70637384, -62847076, -53834452, -43948188, -33541804, -22962404, -12540202, + -2579104, 6651381, 14922708, 22052188, 27906138, 32401252, 35504228, 37229756, + 37636996, 36824736, 34925464, 32098614, 28523208, 24390258, 19895138, 15230230, + 10578097, 6105390, 1957699, -1744518, -4908812, -7472372, -9402388, -10695210, + -11374340, -11487438, -11102430, -10302999, -9183557, -7844043, -6384651, -4900844, + -3478715, -2191066, -1094124, -225317, 398208, 779956, 943926, 936293, + 833844, 703157, 565034, 427621, 299915, 188242, 97070, 28671, + -16282, -38631, -40246, -23848, 7370, 49924, 100305, 155103, + 211184, 265743, 316398, 361188, 398601, 427542, 447320, 457596, + 458351, 449838, 432541, 407131, 374438, 335404, 291067, 242523, + 190911, 137380, 83081, 29131, -23391, -73477, -120193, -162709, + -200302, -232373, -258456, -278222, -291483, -298191, -298431, -292422, + -280496, -263099, -240767, -214119, -183837, -150654, -115335, -78667, + -41439, -4430, 31603, 65943, 97920, 126924, 152420, 173951, + 191152, 203753, 211586, 214590, 212809, 206390, 195581, 180724, + 162245, 140642, 116472, 90338, 62871, 34716, 6512, -21115, + -47577, -72327, -94874, -114790, -131717, -145374, -155554, -162130, + -165050, -164338, -160089, -152466, -141696, -128062, -111900, -93592, + -73557, -52247, -30134, -7706, 14546, 36139, 56604, 75501, + 92426, 107025, 118997, 128106, 134187, 137146, 136964, 133700, + 127480, 118502, 107020, 93345, 116040, 106373, 94004, 79158, + 62121, 43240, 22912, 1579, -20281, -42169, -63569, -83966, + -102856, -119760, -134234, -145882, -154369, -159426, -160859, -158557, + -152493, -142728, -129410, -112770, -93122, -70853, -46417, -20326, + 6860, 34548, 62118, 88942, 114393, 137861, 158767, 176575, + 190802, 201034, 206937, 208261, 204852, 196660, 183736, 166241, + 144442, 118709, 89511, 57407, 23039, -12886, -49603, -86311, + -122184, -156394, -188125, -216596, -241075, -260902, -275496, -284383, + -287194, -283688, -273753, -257415, -234835, -206316, -172290, -133320, + -90085, -43369, 5950, 56922, 108538, 159746, 209478, 256659, + 300236, 339190, 372562, 399462, 419103, 430808, 434043, 428427, + 413772, 390087, 357626, 316892, 268676, 214058, 154439, 91515, + 27295, -35962, -95765, -149503, -194502, -228208, -248287, -252875, + -240711, -211453, -165805, -105883, -35276, 40539, 114314, 176503, + 215759, 217978, 167946, 29216, -265669, -759935, -1454826, -2329191, + -3341857, -4434792, -5535889, -6563153, -7428902, -8044769, -8326572, -8199427, + -7602384, -6492797, -4849871, -2677498, -5997, 3107152, 6577829, 10296906, + 14133125, 17937022, 21545892, 24789544, 27496750, 29502072, 30652904, 30816402, + 29886096, 27787848, 24484978, 19982264, 14328683, 7618649, -8275, -8369346, + -17242212, -26370120, -35468600, -44233488, -52350068, -59503100, -65387360, -69718488, + -72243656, -72751784, -71082920, -67136432, -60877660, -52342804, -41641768, -28958772, + -14550630, 1257369, 18077938, 35470524, 52952152, 70010080, 86115976, 100741256, + 113373128, 123530864, 130781872, 134756976, 135164528, 131802696, 124569704, 113471440, + 98626208, 80266312, 58736392, 34488268, 8072537, -19873172, -48638900, -77459776, + -105535736, -132052984, -156206736, -177224544, -194389536, -207063008, -214705568, -216896176, + -213348592, -203924480, -188642880, -167685488, -141397504, -110283944, -75001352, -36344852, + 4768980, 47323316, 90225720, 132335712, 172494592, 209556688, 242421216, 270063936, + 291567712, 306150848, 313192864, 312256320, 303104480, 285713824, 260281152, 227224928, + 187180496, 140989248, 89681992, 34456540, -23349740, -82291968, -140853584, -197485040, + -250644464, -298839136, -340666720, -374855200, -400300192, -416098816, -421578912, -416322848, + -400184960, -373302304, -336098016, -289277056, -233814336, -170935472, -102090216, -28919474, + 46783608, 123117448, 198119696, 269817600, 336279616, 395667328, 446285568, 486630272, + 515431904, 531693952, 534724512, 524161024, 499986336, 462536352, 412498304, 350899776, + 279088736, 198704400, 111640296, 19999716, -73955136, -167859072, -259303504, -345898400, + -425334720, -495445856, -554266496, -600087168, -631503040, -647455744, -647266496, -630660352, + -597779904, -549188672, -485863232, -409174688, -320859648, -222981056, -117879984, -8119592, + 103577704, 214398032, 321507232, 422123680, 513590720, 593446784, 659491904, 709847616, + 743010112, 757894080, 753866240, 730767680, 688924608, 629145984, 552709376, 461334048, + 357142464, 242611072, 120511064, -6158985, -134247200, -260527344, -381780576, -494877952, + -596861632, -685022336, -756971776, -810707072, -844666432, -857773504, -849470528, -819737792, + -769099840, -698617600, -609866880, -504903104, -386213792, -256659104, -119402648, 22166518, + 164518080, 304069184, 437275360, 560721088, 671207872, 765837888, 842089984, 897887232, + 931653440, 942357376, 929543168, 893346752, 834496704, 754300416, 654615040, 537804480, + 406682912, 264446352, 114594352, -39157032, -192968032, -342971968, -485373120, -616543680, + -733116800, -832073664, -910822080, -967264896, -999856064, -1007642752, -990292800, -948106752, + -882013184, -793548800, -684822016, -558462848, -417558400, -265576992, -106281872, 56362708, + 218291040, 375438528, 523844608, 659753344, 779709440, 880646656, 959966976, 1015607872, + 1046096320, 1050588096, 1028890880, 981471296, 909444864, 814549696, 699104192, 565949568, + 418379808, 260058736, 94928648, -72889120, -239197984, -399832192, -550762240, -688196992, + -808680064, -909177600, -987155392, -1040643904, -1068288256, -1069383232, -1043891456, -992444800, + -916328960, -817451520, -698297344, -561877056, -411613792, -251225136, -84665176, 83959240, + 250492800, 410833184, 561032192, 697392512, 816558400, 915598016, 992075520, 1044110528, + 1070424512, 1070372096, 1043956672, 991830592, 915278784, 816187328, 696996800, 560642560, + 410482208, 250213232, 83781792, -84714288, -251126384, -411357152, -561461504, -697743552, + -816847808, -915841536, -992287296, -1044302592, -1070606528, -1070551232, -1044137856, -992016512, + -915470336, -816383744, -697196352, -560842560, -410679552, -250404528, -83963680, 84544936, + 250972336, 411220768, 561344576, 697647424, 816773248, 915788800, 992256192, 1044292480, + 1070616448, 1070579840, 1044183488, 992077376, 915544384, 816468800, 697290112, 560942720, + 410783712, 250510352, 84068912, -84442472, -250874656, -411129728, -561261824, -697574272, + -816710848, -915738048, -992217536, -1044266240, -1070602624, -1070578112, -1044193344, -992097920, + -915574656, -816507712, -697336256, -560994752, -410840192, -250569808, -84129840, 84381496, + 250815008, 411072672, 561208512, 697525760, 816667968, 915701504, 992187968, 1044243968, + 1070587840, 1070570944, 1044193664, 992105472, 915588992, 816528256, 697362432, 561025728, + 410875072, 250607648, 84169704, -84340632, -250774144, -411032768, -561170496, -697490560, + -816636288, -915674048, -992165248, -1044226432, -1070575744, -1070564352, -1044192576, -992109760, + -915598336, -816542272, -697380608, -561047424, -410899648, -250634432, -84197944, 84311648, + 250745136, 411004448, 561143488, 697465472, 816613632, 915654272, 992148736, 1044213504, + 1070566592, 1070559104, 1044191232, 992112320, 915604608, 816552064, 697393600, 561063296, + 410917984, 250654720, 84219640, -84289112, -250722352, -410981984, -561121984, -697445376, + -816595520, -915638656, -992135872, -1044203776, -1070560128, -1070556032, -1044191616, -992116032, + -915611456, -816561792, -697405888, -561077696, -410934112, -250672080, -84237752, 84270736, + 250704176, 410964480, 561105536, 697430400, 816582400, 915627520, 992127104, 1044197440, + 1070556416, 1070555008, 1044193216, 992120256, 915618176, 816570816, 697417024, 561090688, + 410948576, 250687680, 84254088 }; #endif diff --git a/lib_com/ivas_rom_com.h b/lib_com/ivas_rom_com.h index 6adf3b6bf..dce741b3e 100644 --- a/lib_com/ivas_rom_com.h +++ b/lib_com/ivas_rom_com.h @@ -107,7 +107,7 @@ extern const Word16 pow_10_icbwe_gsMappingDFT_tbl_fx[]; extern const float tdm_ratio_tabl[]; extern const UWord32 tdm_ratio_tabl_fx[TDM_NQ + 1]; extern const float tdm_den_ratio_tabl[]; -extern const UWord32 tdm_den_ratio_tabl_fx[]; +extern const UWord32 tdm_den_ratio_tabl_fx[]; extern const int16_t tdm_bit_allc_tbl[5][6]; /* LSFs Intra-frame prediction tables */ @@ -372,7 +372,7 @@ extern const Word16 ls_elevation_CICP19_idx[11]; extern const float shoebox_sin_cos_tbl[11][2]; extern const Word32 shoebox_sin_cos_tbl_fx[11][2]; -#endif +#endif extern const float cb_azi_chan[]; extern const Word32 delta_phi_val[90]; extern const Word32 inv_delta_phi_val[90]; @@ -445,7 +445,7 @@ extern const Word32 ivas_lfe_window_coeff_16k_fx[IVAS_LFE_FADE_LEN_16K]; extern const int16_t ivas_lfe_num_ele_in_coder_models[2][4]; -extern const Word16 ivas_lfe_log2_num_ele_in_coder_models_fx[2][4]; +extern const Word16 ivas_lfe_log2_num_ele_in_coder_models_fx[2][4]; extern const int16_t ivas_lfe_num_dct_pass_bins_tbl[IVAS_LFE_NUM_COEFFS_IN_SUBGRP]; extern const int16_t ivas_lfe_min_shift_tbl[IVAS_LFE_NUM_COEFFS_IN_SUBGRP]; extern const ivas_lfe_freq_models ivas_str_lfe_freq_models; diff --git a/lib_com/ivas_rom_com_fx.c b/lib_com/ivas_rom_com_fx.c index 605dd3a75..726c23cb3 100644 --- a/lib_com/ivas_rom_com_fx.c +++ b/lib_com/ivas_rom_com_fx.c @@ -38,7 +38,7 @@ #include "ivas_rom_com_fx.h" #include "wmc_auto.h" -#define SHC( x ) ( (Word16) x ) +#define SHC( x ) ( (Word16) x ) /* clang-format off */ const Word16 ivas_sin_twiddle_480_fx[ IVAS_480_PT_LEN >> 1 ] = { @@ -556,88 +556,612 @@ const Word32 pow_10_q23[14] = { /* clang-format on */ const Word16 ivas_tan_panning_gain_dirac_tbl_fx[601] = { - SHC( 0x8000 ), SHC( 0x8001 ), SHC( 0x8002 ), SHC( 0x8003 ), SHC( 0x8005 ), SHC( 0x8007 ), SHC( 0x800a ), SHC( 0x800e ), - SHC( 0x8012 ), SHC( 0x8016 ), SHC( 0x801c ), SHC( 0x8021 ), SHC( 0x8028 ), SHC( 0x802f ), SHC( 0x8036 ), SHC( 0x803e ), - SHC( 0x8047 ), SHC( 0x8050 ), SHC( 0x805a ), SHC( 0x8064 ), SHC( 0x806f ), SHC( 0x807b ), SHC( 0x8087 ), SHC( 0x8094 ), - SHC( 0x80a1 ), SHC( 0x80af ), SHC( 0x80be ), SHC( 0x80cd ), SHC( 0x80dd ), SHC( 0x80ee ), SHC( 0x80ff ), SHC( 0x8110 ), - SHC( 0x8123 ), SHC( 0x8136 ), SHC( 0x814a ), SHC( 0x815e ), SHC( 0x8173 ), SHC( 0x8188 ), SHC( 0x819f ), SHC( 0x81b6 ), - SHC( 0x81cd ), SHC( 0x81e5 ), SHC( 0x81fe ), SHC( 0x8218 ), SHC( 0x8232 ), SHC( 0x824d ), SHC( 0x8269 ), SHC( 0x8285 ), - SHC( 0x82a2 ), SHC( 0x82c0 ), SHC( 0x82de ), SHC( 0x82fd ), SHC( 0x831d ), SHC( 0x833d ), SHC( 0x835f ), SHC( 0x8380 ), - SHC( 0x83a3 ), SHC( 0x83c6 ), SHC( 0x83ea ), SHC( 0x840f ), SHC( 0x8435 ), SHC( 0x845b ), SHC( 0x8482 ), SHC( 0x84a9 ), - SHC( 0x84d2 ), SHC( 0x84fb ), SHC( 0x8525 ), SHC( 0x854f ), SHC( 0x857b ), SHC( 0x85a7 ), SHC( 0x85d4 ), SHC( 0x8601 ), - SHC( 0x8630 ), SHC( 0x865f ), SHC( 0x868f ), SHC( 0x86c0 ), SHC( 0x86f1 ), SHC( 0x8723 ), SHC( 0x8756 ), SHC( 0x878a ), - SHC( 0x87bf ), SHC( 0x87f4 ), SHC( 0x882a ), SHC( 0x8861 ), SHC( 0x8899 ), SHC( 0x88d2 ), SHC( 0x890b ), SHC( 0x8945 ), - SHC( 0x8980 ), SHC( 0x89bc ), SHC( 0x89f9 ), SHC( 0x8a36 ), SHC( 0x8a74 ), SHC( 0x8ab3 ), SHC( 0x8af3 ), SHC( 0x8b34 ), - SHC( 0x8b75 ), SHC( 0x8bb8 ), SHC( 0x8bfb ), SHC( 0x8c3f ), SHC( 0x8c83 ), SHC( 0x8cc9 ), SHC( 0x8d10 ), SHC( 0x8d57 ), - SHC( 0x8d9f ), SHC( 0x8de8 ), SHC( 0x8e32 ), SHC( 0x8e7d ), SHC( 0x8ec8 ), SHC( 0x8f15 ), SHC( 0x8f62 ), SHC( 0x8fb0 ), - SHC( 0x8fff ), SHC( 0x904f ), SHC( 0x90a0 ), SHC( 0x90f1 ), SHC( 0x9143 ), SHC( 0x9197 ), SHC( 0x91eb ), SHC( 0x9240 ), - SHC( 0x9296 ), SHC( 0x92ed ), SHC( 0x9344 ), SHC( 0x939d ), SHC( 0x93f6 ), SHC( 0x9450 ), SHC( 0x94ab ), SHC( 0x9507 ), - SHC( 0x9564 ), SHC( 0x95c2 ), SHC( 0x9621 ), SHC( 0x9680 ), SHC( 0x96e1 ), SHC( 0x9742 ), SHC( 0x97a4 ), SHC( 0x9807 ), - SHC( 0x986b ), SHC( 0x98d0 ), SHC( 0x9936 ), SHC( 0x999c ), SHC( 0x9a04 ), SHC( 0x9a6c ), SHC( 0x9ad5 ), SHC( 0x9b40 ), - SHC( 0x9bab ), SHC( 0x9c16 ), SHC( 0x9c83 ), SHC( 0x9cf1 ), SHC( 0x9d60 ), SHC( 0x9dcf ), SHC( 0x9e3f ), SHC( 0x9eb1 ), - SHC( 0x9f23 ), SHC( 0x9f96 ), SHC( 0xa00a ), SHC( 0xa07e ), SHC( 0xa0f4 ), SHC( 0xa16a ), SHC( 0xa1e2 ), SHC( 0xa25a ), - SHC( 0xa2d3 ), SHC( 0xa34d ), SHC( 0xa3c8 ), SHC( 0xa444 ), SHC( 0xa4c1 ), SHC( 0xa53e ), SHC( 0xa5bd ), SHC( 0xa63c ), - SHC( 0xa6bc ), SHC( 0xa73d ), SHC( 0xa7bf ), SHC( 0xa842 ), SHC( 0xa8c5 ), SHC( 0xa94a ), SHC( 0xa9cf ), SHC( 0xaa55 ), - SHC( 0xaadc ), SHC( 0xab64 ), SHC( 0xabed ), SHC( 0xac76 ), SHC( 0xad01 ), SHC( 0xad8c ), SHC( 0xae18 ), SHC( 0xaea5 ), - SHC( 0xaf33 ), SHC( 0xafc1 ), SHC( 0xb051 ), SHC( 0xb0e1 ), SHC( 0xb172 ), SHC( 0xb204 ), SHC( 0xb296 ), SHC( 0xb32a ), - SHC( 0xb3be ), SHC( 0xb453 ), SHC( 0xb4e9 ), SHC( 0xb580 ), SHC( 0xb617 ), SHC( 0xb6b0 ), SHC( 0xb749 ), SHC( 0xb7e2 ), - SHC( 0xb87d ), SHC( 0xb918 ), SHC( 0xb9b4 ), SHC( 0xba51 ), SHC( 0xbaef ), SHC( 0xbb8d ), SHC( 0xbc2c ), SHC( 0xbccc ), - SHC( 0xbd6d ), SHC( 0xbe0e ), SHC( 0xbeb0 ), SHC( 0xbf53 ), SHC( 0xbff7 ), SHC( 0xc09b ), SHC( 0xc140 ), SHC( 0xc1e5 ), - SHC( 0xc28c ), SHC( 0xc333 ), SHC( 0xc3da ), SHC( 0xc483 ), SHC( 0xc52c ), SHC( 0xc5d6 ), SHC( 0xc680 ), SHC( 0xc72b ), - SHC( 0xc7d7 ), SHC( 0xc883 ), SHC( 0xc930 ), SHC( 0xc9de ), SHC( 0xca8c ), SHC( 0xcb3b ), SHC( 0xcbea ), SHC( 0xcc9a ), - SHC( 0xcd4b ), SHC( 0xcdfc ), SHC( 0xceae ), SHC( 0xcf60 ), SHC( 0xd013 ), SHC( 0xd0c7 ), SHC( 0xd17b ), SHC( 0xd22f ), - SHC( 0xd2e5 ), SHC( 0xd39a ), SHC( 0xd451 ), SHC( 0xd507 ), SHC( 0xd5bf ), SHC( 0xd676 ), SHC( 0xd72f ), SHC( 0xd7e7 ), - SHC( 0xd8a1 ), SHC( 0xd95a ), SHC( 0xda14 ), SHC( 0xdacf ), SHC( 0xdb8a ), SHC( 0xdc46 ), SHC( 0xdd02 ), SHC( 0xddbe ), - SHC( 0xde7b ), SHC( 0xdf38 ), SHC( 0xdff5 ), SHC( 0xe0b3 ), SHC( 0xe172 ), SHC( 0xe230 ), SHC( 0xe2f0 ), SHC( 0xe3af ), - SHC( 0xe46f ), SHC( 0xe52f ), SHC( 0xe5ef ), SHC( 0xe6b0 ), SHC( 0xe771 ), SHC( 0xe833 ), SHC( 0xe8f4 ), SHC( 0xe9b6 ), - SHC( 0xea78 ), SHC( 0xeb3b ), SHC( 0xebfe ), SHC( 0xecc1 ), SHC( 0xed84 ), SHC( 0xee47 ), SHC( 0xef0b ), SHC( 0xefcf ), - SHC( 0xf093 ), SHC( 0xf157 ), SHC( 0xf21c ), SHC( 0xf2e0 ), SHC( 0xf3a5 ), SHC( 0xf46a ), SHC( 0xf52f ), SHC( 0xf5f5 ), - SHC( 0xf6ba ), SHC( 0xf77f ), SHC( 0xf845 ), SHC( 0xf90b ), SHC( 0xf9d0 ), SHC( 0xfa96 ), SHC( 0xfb5c ), SHC( 0xfc22 ), - SHC( 0xfce8 ), SHC( 0xfdae ), SHC( 0xfe74 ), SHC( 0xff3a ), SHC( 0x0000 ), SHC( 0x00c6 ), SHC( 0x018c ), SHC( 0x0252 ), - SHC( 0x0318 ), SHC( 0x03de ), SHC( 0x04a4 ), SHC( 0x056a ), SHC( 0x0630 ), SHC( 0x06f5 ), SHC( 0x07bb ), SHC( 0x0881 ), - SHC( 0x0946 ), SHC( 0x0a0b ), SHC( 0x0ad1 ), SHC( 0x0b96 ), SHC( 0x0c5b ), SHC( 0x0d20 ), SHC( 0x0de4 ), SHC( 0x0ea9 ), - SHC( 0x0f6d ), SHC( 0x1031 ), SHC( 0x10f5 ), SHC( 0x11b9 ), SHC( 0x127c ), SHC( 0x133f ), SHC( 0x1402 ), SHC( 0x14c5 ), - SHC( 0x1588 ), SHC( 0x164a ), SHC( 0x170c ), SHC( 0x17cd ), SHC( 0x188f ), SHC( 0x1950 ), SHC( 0x1a11 ), SHC( 0x1ad1 ), - SHC( 0x1b91 ), SHC( 0x1c51 ), SHC( 0x1d10 ), SHC( 0x1dd0 ), SHC( 0x1e8e ), SHC( 0x1f4d ), SHC( 0x200b ), SHC( 0x20c8 ), - SHC( 0x2185 ), SHC( 0x2242 ), SHC( 0x22fe ), SHC( 0x23ba ), SHC( 0x2476 ), SHC( 0x2531 ), SHC( 0x25ec ), SHC( 0x26a6 ), - SHC( 0x275f ), SHC( 0x2819 ), SHC( 0x28d1 ), SHC( 0x298a ), SHC( 0x2a41 ), SHC( 0x2af9 ), SHC( 0x2baf ), SHC( 0x2c66 ), - SHC( 0x2d1b ), SHC( 0x2dd1 ), SHC( 0x2e85 ), SHC( 0x2f39 ), SHC( 0x2fed ), SHC( 0x30a0 ), SHC( 0x3152 ), SHC( 0x3204 ), - SHC( 0x32b5 ), SHC( 0x3366 ), SHC( 0x3416 ), SHC( 0x34c5 ), SHC( 0x3574 ), SHC( 0x3622 ), SHC( 0x36d0 ), SHC( 0x377d ), - SHC( 0x3829 ), SHC( 0x38d5 ), SHC( 0x3980 ), SHC( 0x3a2a ), SHC( 0x3ad4 ), SHC( 0x3b7d ), SHC( 0x3c26 ), SHC( 0x3ccd ), - SHC( 0x3d74 ), SHC( 0x3e1b ), SHC( 0x3ec0 ), SHC( 0x3f65 ), SHC( 0x4009 ), SHC( 0x40ad ), SHC( 0x4150 ), SHC( 0x41f2 ), - SHC( 0x4293 ), SHC( 0x4334 ), SHC( 0x43d4 ), SHC( 0x4473 ), SHC( 0x4511 ), SHC( 0x45af ), SHC( 0x464c ), SHC( 0x46e8 ), - SHC( 0x4783 ), SHC( 0x481e ), SHC( 0x48b7 ), SHC( 0x4950 ), SHC( 0x49e9 ), SHC( 0x4a80 ), SHC( 0x4b17 ), SHC( 0x4bad ), - SHC( 0x4c42 ), SHC( 0x4cd6 ), SHC( 0x4d6a ), SHC( 0x4dfc ), SHC( 0x4e8e ), SHC( 0x4f1f ), SHC( 0x4faf ), SHC( 0x503f ), - SHC( 0x50cd ), SHC( 0x515b ), SHC( 0x51e8 ), SHC( 0x5274 ), SHC( 0x52ff ), SHC( 0x538a ), SHC( 0x5413 ), SHC( 0x549c ), - SHC( 0x5524 ), SHC( 0x55ab ), SHC( 0x5631 ), SHC( 0x56b6 ), SHC( 0x573b ), SHC( 0x57be ), SHC( 0x5841 ), SHC( 0x58c3 ), - SHC( 0x5944 ), SHC( 0x59c4 ), SHC( 0x5a43 ), SHC( 0x5ac2 ), SHC( 0x5b3f ), SHC( 0x5bbc ), SHC( 0x5c38 ), SHC( 0x5cb3 ), - SHC( 0x5d2d ), SHC( 0x5da6 ), SHC( 0x5e1e ), SHC( 0x5e96 ), SHC( 0x5f0c ), SHC( 0x5f82 ), SHC( 0x5ff6 ), SHC( 0x606a ), - SHC( 0x60dd ), SHC( 0x614f ), SHC( 0x61c1 ), SHC( 0x6231 ), SHC( 0x62a0 ), SHC( 0x630f ), SHC( 0x637d ), SHC( 0x63ea ), - SHC( 0x6455 ), SHC( 0x64c0 ), SHC( 0x652b ), SHC( 0x6594 ), SHC( 0x65fc ), SHC( 0x6664 ), SHC( 0x66ca ), SHC( 0x6730 ), - SHC( 0x6795 ), SHC( 0x67f9 ), SHC( 0x685c ), SHC( 0x68be ), SHC( 0x691f ), SHC( 0x6980 ), SHC( 0x69df ), SHC( 0x6a3e ), - SHC( 0x6a9c ), SHC( 0x6af9 ), SHC( 0x6b55 ), SHC( 0x6bb0 ), SHC( 0x6c0a ), SHC( 0x6c63 ), SHC( 0x6cbc ), SHC( 0x6d13 ), - SHC( 0x6d6a ), SHC( 0x6dc0 ), SHC( 0x6e15 ), SHC( 0x6e69 ), SHC( 0x6ebd ), SHC( 0x6f0f ), SHC( 0x6f60 ), SHC( 0x6fb1 ), - SHC( 0x7001 ), SHC( 0x7050 ), SHC( 0x709e ), SHC( 0x70eb ), SHC( 0x7138 ), SHC( 0x7183 ), SHC( 0x71ce ), SHC( 0x7218 ), - SHC( 0x7261 ), SHC( 0x72a9 ), SHC( 0x72f0 ), SHC( 0x7337 ), SHC( 0x737d ), SHC( 0x73c1 ), SHC( 0x7405 ), SHC( 0x7448 ), - SHC( 0x748b ), SHC( 0x74cc ), SHC( 0x750d ), SHC( 0x754d ), SHC( 0x758c ), SHC( 0x75ca ), SHC( 0x7607 ), SHC( 0x7644 ), - SHC( 0x7680 ), SHC( 0x76bb ), SHC( 0x76f5 ), SHC( 0x772e ), SHC( 0x7767 ), SHC( 0x779f ), SHC( 0x77d6 ), SHC( 0x780c ), - SHC( 0x7841 ), SHC( 0x7876 ), SHC( 0x78aa ), SHC( 0x78dd ), SHC( 0x790f ), SHC( 0x7940 ), SHC( 0x7971 ), SHC( 0x79a1 ), - SHC( 0x79d0 ), SHC( 0x79ff ), SHC( 0x7a2c ), SHC( 0x7a59 ), SHC( 0x7a85 ), SHC( 0x7ab1 ), SHC( 0x7adb ), SHC( 0x7b05 ), - SHC( 0x7b2e ), SHC( 0x7b57 ), SHC( 0x7b7e ), SHC( 0x7ba5 ), SHC( 0x7bcb ), SHC( 0x7bf1 ), SHC( 0x7c16 ), SHC( 0x7c3a ), - SHC( 0x7c5d ), SHC( 0x7c80 ), SHC( 0x7ca1 ), SHC( 0x7cc3 ), SHC( 0x7ce3 ), SHC( 0x7d03 ), SHC( 0x7d22 ), SHC( 0x7d40 ), - SHC( 0x7d5e ), SHC( 0x7d7b ), SHC( 0x7d97 ), SHC( 0x7db3 ), SHC( 0x7dce ), SHC( 0x7de8 ), SHC( 0x7e02 ), SHC( 0x7e1b ), - SHC( 0x7e33 ), SHC( 0x7e4a ), SHC( 0x7e61 ), SHC( 0x7e78 ), SHC( 0x7e8d ), SHC( 0x7ea2 ), SHC( 0x7eb6 ), SHC( 0x7eca ), - SHC( 0x7edd ), SHC( 0x7ef0 ), SHC( 0x7f01 ), SHC( 0x7f12 ), SHC( 0x7f23 ), SHC( 0x7f33 ), SHC( 0x7f42 ), SHC( 0x7f51 ), - SHC( 0x7f5f ), SHC( 0x7f6c ), SHC( 0x7f79 ), SHC( 0x7f85 ), SHC( 0x7f91 ), SHC( 0x7f9c ), SHC( 0x7fa6 ), SHC( 0x7fb0 ), - SHC( 0x7fb9 ), SHC( 0x7fc2 ), SHC( 0x7fca ), SHC( 0x7fd1 ), SHC( 0x7fd8 ), SHC( 0x7fdf ), SHC( 0x7fe4 ), SHC( 0x7fea ), - SHC( 0x7fee ), SHC( 0x7ff2 ), SHC( 0x7ff6 ), SHC( 0x7ff9 ), SHC( 0x7ffb ), SHC( 0x7ffd ), SHC( 0x7ffe ), SHC( 0x7fff ), - SHC( 0x7fff ), + SHC( 0x8000 ), + SHC( 0x8001 ), + SHC( 0x8002 ), + SHC( 0x8003 ), + SHC( 0x8005 ), + SHC( 0x8007 ), + SHC( 0x800a ), + SHC( 0x800e ), + SHC( 0x8012 ), + SHC( 0x8016 ), + SHC( 0x801c ), + SHC( 0x8021 ), + SHC( 0x8028 ), + SHC( 0x802f ), + SHC( 0x8036 ), + SHC( 0x803e ), + SHC( 0x8047 ), + SHC( 0x8050 ), + SHC( 0x805a ), + SHC( 0x8064 ), + SHC( 0x806f ), + SHC( 0x807b ), + SHC( 0x8087 ), + SHC( 0x8094 ), + SHC( 0x80a1 ), + SHC( 0x80af ), + SHC( 0x80be ), + SHC( 0x80cd ), + SHC( 0x80dd ), + SHC( 0x80ee ), + SHC( 0x80ff ), + SHC( 0x8110 ), + SHC( 0x8123 ), + SHC( 0x8136 ), + SHC( 0x814a ), + SHC( 0x815e ), + SHC( 0x8173 ), + SHC( 0x8188 ), + SHC( 0x819f ), + SHC( 0x81b6 ), + SHC( 0x81cd ), + SHC( 0x81e5 ), + SHC( 0x81fe ), + SHC( 0x8218 ), + SHC( 0x8232 ), + SHC( 0x824d ), + SHC( 0x8269 ), + SHC( 0x8285 ), + SHC( 0x82a2 ), + SHC( 0x82c0 ), + SHC( 0x82de ), + SHC( 0x82fd ), + SHC( 0x831d ), + SHC( 0x833d ), + SHC( 0x835f ), + SHC( 0x8380 ), + SHC( 0x83a3 ), + SHC( 0x83c6 ), + SHC( 0x83ea ), + SHC( 0x840f ), + SHC( 0x8435 ), + SHC( 0x845b ), + SHC( 0x8482 ), + SHC( 0x84a9 ), + SHC( 0x84d2 ), + SHC( 0x84fb ), + SHC( 0x8525 ), + SHC( 0x854f ), + SHC( 0x857b ), + SHC( 0x85a7 ), + SHC( 0x85d4 ), + SHC( 0x8601 ), + SHC( 0x8630 ), + SHC( 0x865f ), + SHC( 0x868f ), + SHC( 0x86c0 ), + SHC( 0x86f1 ), + SHC( 0x8723 ), + SHC( 0x8756 ), + SHC( 0x878a ), + SHC( 0x87bf ), + SHC( 0x87f4 ), + SHC( 0x882a ), + SHC( 0x8861 ), + SHC( 0x8899 ), + SHC( 0x88d2 ), + SHC( 0x890b ), + SHC( 0x8945 ), + SHC( 0x8980 ), + SHC( 0x89bc ), + SHC( 0x89f9 ), + SHC( 0x8a36 ), + SHC( 0x8a74 ), + SHC( 0x8ab3 ), + SHC( 0x8af3 ), + SHC( 0x8b34 ), + SHC( 0x8b75 ), + SHC( 0x8bb8 ), + SHC( 0x8bfb ), + SHC( 0x8c3f ), + SHC( 0x8c83 ), + SHC( 0x8cc9 ), + SHC( 0x8d10 ), + SHC( 0x8d57 ), + SHC( 0x8d9f ), + SHC( 0x8de8 ), + SHC( 0x8e32 ), + SHC( 0x8e7d ), + SHC( 0x8ec8 ), + SHC( 0x8f15 ), + SHC( 0x8f62 ), + SHC( 0x8fb0 ), + SHC( 0x8fff ), + SHC( 0x904f ), + SHC( 0x90a0 ), + SHC( 0x90f1 ), + SHC( 0x9143 ), + SHC( 0x9197 ), + SHC( 0x91eb ), + SHC( 0x9240 ), + SHC( 0x9296 ), + SHC( 0x92ed ), + SHC( 0x9344 ), + SHC( 0x939d ), + SHC( 0x93f6 ), + SHC( 0x9450 ), + SHC( 0x94ab ), + SHC( 0x9507 ), + SHC( 0x9564 ), + SHC( 0x95c2 ), + SHC( 0x9621 ), + SHC( 0x9680 ), + SHC( 0x96e1 ), + SHC( 0x9742 ), + SHC( 0x97a4 ), + SHC( 0x9807 ), + SHC( 0x986b ), + SHC( 0x98d0 ), + SHC( 0x9936 ), + SHC( 0x999c ), + SHC( 0x9a04 ), + SHC( 0x9a6c ), + SHC( 0x9ad5 ), + SHC( 0x9b40 ), + SHC( 0x9bab ), + SHC( 0x9c16 ), + SHC( 0x9c83 ), + SHC( 0x9cf1 ), + SHC( 0x9d60 ), + SHC( 0x9dcf ), + SHC( 0x9e3f ), + SHC( 0x9eb1 ), + SHC( 0x9f23 ), + SHC( 0x9f96 ), + SHC( 0xa00a ), + SHC( 0xa07e ), + SHC( 0xa0f4 ), + SHC( 0xa16a ), + SHC( 0xa1e2 ), + SHC( 0xa25a ), + SHC( 0xa2d3 ), + SHC( 0xa34d ), + SHC( 0xa3c8 ), + SHC( 0xa444 ), + SHC( 0xa4c1 ), + SHC( 0xa53e ), + SHC( 0xa5bd ), + SHC( 0xa63c ), + SHC( 0xa6bc ), + SHC( 0xa73d ), + SHC( 0xa7bf ), + SHC( 0xa842 ), + SHC( 0xa8c5 ), + SHC( 0xa94a ), + SHC( 0xa9cf ), + SHC( 0xaa55 ), + SHC( 0xaadc ), + SHC( 0xab64 ), + SHC( 0xabed ), + SHC( 0xac76 ), + SHC( 0xad01 ), + SHC( 0xad8c ), + SHC( 0xae18 ), + SHC( 0xaea5 ), + SHC( 0xaf33 ), + SHC( 0xafc1 ), + SHC( 0xb051 ), + SHC( 0xb0e1 ), + SHC( 0xb172 ), + SHC( 0xb204 ), + SHC( 0xb296 ), + SHC( 0xb32a ), + SHC( 0xb3be ), + SHC( 0xb453 ), + SHC( 0xb4e9 ), + SHC( 0xb580 ), + SHC( 0xb617 ), + SHC( 0xb6b0 ), + SHC( 0xb749 ), + SHC( 0xb7e2 ), + SHC( 0xb87d ), + SHC( 0xb918 ), + SHC( 0xb9b4 ), + SHC( 0xba51 ), + SHC( 0xbaef ), + SHC( 0xbb8d ), + SHC( 0xbc2c ), + SHC( 0xbccc ), + SHC( 0xbd6d ), + SHC( 0xbe0e ), + SHC( 0xbeb0 ), + SHC( 0xbf53 ), + SHC( 0xbff7 ), + SHC( 0xc09b ), + SHC( 0xc140 ), + SHC( 0xc1e5 ), + SHC( 0xc28c ), + SHC( 0xc333 ), + SHC( 0xc3da ), + SHC( 0xc483 ), + SHC( 0xc52c ), + SHC( 0xc5d6 ), + SHC( 0xc680 ), + SHC( 0xc72b ), + SHC( 0xc7d7 ), + SHC( 0xc883 ), + SHC( 0xc930 ), + SHC( 0xc9de ), + SHC( 0xca8c ), + SHC( 0xcb3b ), + SHC( 0xcbea ), + SHC( 0xcc9a ), + SHC( 0xcd4b ), + SHC( 0xcdfc ), + SHC( 0xceae ), + SHC( 0xcf60 ), + SHC( 0xd013 ), + SHC( 0xd0c7 ), + SHC( 0xd17b ), + SHC( 0xd22f ), + SHC( 0xd2e5 ), + SHC( 0xd39a ), + SHC( 0xd451 ), + SHC( 0xd507 ), + SHC( 0xd5bf ), + SHC( 0xd676 ), + SHC( 0xd72f ), + SHC( 0xd7e7 ), + SHC( 0xd8a1 ), + SHC( 0xd95a ), + SHC( 0xda14 ), + SHC( 0xdacf ), + SHC( 0xdb8a ), + SHC( 0xdc46 ), + SHC( 0xdd02 ), + SHC( 0xddbe ), + SHC( 0xde7b ), + SHC( 0xdf38 ), + SHC( 0xdff5 ), + SHC( 0xe0b3 ), + SHC( 0xe172 ), + SHC( 0xe230 ), + SHC( 0xe2f0 ), + SHC( 0xe3af ), + SHC( 0xe46f ), + SHC( 0xe52f ), + SHC( 0xe5ef ), + SHC( 0xe6b0 ), + SHC( 0xe771 ), + SHC( 0xe833 ), + SHC( 0xe8f4 ), + SHC( 0xe9b6 ), + SHC( 0xea78 ), + SHC( 0xeb3b ), + SHC( 0xebfe ), + SHC( 0xecc1 ), + SHC( 0xed84 ), + SHC( 0xee47 ), + SHC( 0xef0b ), + SHC( 0xefcf ), + SHC( 0xf093 ), + SHC( 0xf157 ), + SHC( 0xf21c ), + SHC( 0xf2e0 ), + SHC( 0xf3a5 ), + SHC( 0xf46a ), + SHC( 0xf52f ), + SHC( 0xf5f5 ), + SHC( 0xf6ba ), + SHC( 0xf77f ), + SHC( 0xf845 ), + SHC( 0xf90b ), + SHC( 0xf9d0 ), + SHC( 0xfa96 ), + SHC( 0xfb5c ), + SHC( 0xfc22 ), + SHC( 0xfce8 ), + SHC( 0xfdae ), + SHC( 0xfe74 ), + SHC( 0xff3a ), + SHC( 0x0000 ), + SHC( 0x00c6 ), + SHC( 0x018c ), + SHC( 0x0252 ), + SHC( 0x0318 ), + SHC( 0x03de ), + SHC( 0x04a4 ), + SHC( 0x056a ), + SHC( 0x0630 ), + SHC( 0x06f5 ), + SHC( 0x07bb ), + SHC( 0x0881 ), + SHC( 0x0946 ), + SHC( 0x0a0b ), + SHC( 0x0ad1 ), + SHC( 0x0b96 ), + SHC( 0x0c5b ), + SHC( 0x0d20 ), + SHC( 0x0de4 ), + SHC( 0x0ea9 ), + SHC( 0x0f6d ), + SHC( 0x1031 ), + SHC( 0x10f5 ), + SHC( 0x11b9 ), + SHC( 0x127c ), + SHC( 0x133f ), + SHC( 0x1402 ), + SHC( 0x14c5 ), + SHC( 0x1588 ), + SHC( 0x164a ), + SHC( 0x170c ), + SHC( 0x17cd ), + SHC( 0x188f ), + SHC( 0x1950 ), + SHC( 0x1a11 ), + SHC( 0x1ad1 ), + SHC( 0x1b91 ), + SHC( 0x1c51 ), + SHC( 0x1d10 ), + SHC( 0x1dd0 ), + SHC( 0x1e8e ), + SHC( 0x1f4d ), + SHC( 0x200b ), + SHC( 0x20c8 ), + SHC( 0x2185 ), + SHC( 0x2242 ), + SHC( 0x22fe ), + SHC( 0x23ba ), + SHC( 0x2476 ), + SHC( 0x2531 ), + SHC( 0x25ec ), + SHC( 0x26a6 ), + SHC( 0x275f ), + SHC( 0x2819 ), + SHC( 0x28d1 ), + SHC( 0x298a ), + SHC( 0x2a41 ), + SHC( 0x2af9 ), + SHC( 0x2baf ), + SHC( 0x2c66 ), + SHC( 0x2d1b ), + SHC( 0x2dd1 ), + SHC( 0x2e85 ), + SHC( 0x2f39 ), + SHC( 0x2fed ), + SHC( 0x30a0 ), + SHC( 0x3152 ), + SHC( 0x3204 ), + SHC( 0x32b5 ), + SHC( 0x3366 ), + SHC( 0x3416 ), + SHC( 0x34c5 ), + SHC( 0x3574 ), + SHC( 0x3622 ), + SHC( 0x36d0 ), + SHC( 0x377d ), + SHC( 0x3829 ), + SHC( 0x38d5 ), + SHC( 0x3980 ), + SHC( 0x3a2a ), + SHC( 0x3ad4 ), + SHC( 0x3b7d ), + SHC( 0x3c26 ), + SHC( 0x3ccd ), + SHC( 0x3d74 ), + SHC( 0x3e1b ), + SHC( 0x3ec0 ), + SHC( 0x3f65 ), + SHC( 0x4009 ), + SHC( 0x40ad ), + SHC( 0x4150 ), + SHC( 0x41f2 ), + SHC( 0x4293 ), + SHC( 0x4334 ), + SHC( 0x43d4 ), + SHC( 0x4473 ), + SHC( 0x4511 ), + SHC( 0x45af ), + SHC( 0x464c ), + SHC( 0x46e8 ), + SHC( 0x4783 ), + SHC( 0x481e ), + SHC( 0x48b7 ), + SHC( 0x4950 ), + SHC( 0x49e9 ), + SHC( 0x4a80 ), + SHC( 0x4b17 ), + SHC( 0x4bad ), + SHC( 0x4c42 ), + SHC( 0x4cd6 ), + SHC( 0x4d6a ), + SHC( 0x4dfc ), + SHC( 0x4e8e ), + SHC( 0x4f1f ), + SHC( 0x4faf ), + SHC( 0x503f ), + SHC( 0x50cd ), + SHC( 0x515b ), + SHC( 0x51e8 ), + SHC( 0x5274 ), + SHC( 0x52ff ), + SHC( 0x538a ), + SHC( 0x5413 ), + SHC( 0x549c ), + SHC( 0x5524 ), + SHC( 0x55ab ), + SHC( 0x5631 ), + SHC( 0x56b6 ), + SHC( 0x573b ), + SHC( 0x57be ), + SHC( 0x5841 ), + SHC( 0x58c3 ), + SHC( 0x5944 ), + SHC( 0x59c4 ), + SHC( 0x5a43 ), + SHC( 0x5ac2 ), + SHC( 0x5b3f ), + SHC( 0x5bbc ), + SHC( 0x5c38 ), + SHC( 0x5cb3 ), + SHC( 0x5d2d ), + SHC( 0x5da6 ), + SHC( 0x5e1e ), + SHC( 0x5e96 ), + SHC( 0x5f0c ), + SHC( 0x5f82 ), + SHC( 0x5ff6 ), + SHC( 0x606a ), + SHC( 0x60dd ), + SHC( 0x614f ), + SHC( 0x61c1 ), + SHC( 0x6231 ), + SHC( 0x62a0 ), + SHC( 0x630f ), + SHC( 0x637d ), + SHC( 0x63ea ), + SHC( 0x6455 ), + SHC( 0x64c0 ), + SHC( 0x652b ), + SHC( 0x6594 ), + SHC( 0x65fc ), + SHC( 0x6664 ), + SHC( 0x66ca ), + SHC( 0x6730 ), + SHC( 0x6795 ), + SHC( 0x67f9 ), + SHC( 0x685c ), + SHC( 0x68be ), + SHC( 0x691f ), + SHC( 0x6980 ), + SHC( 0x69df ), + SHC( 0x6a3e ), + SHC( 0x6a9c ), + SHC( 0x6af9 ), + SHC( 0x6b55 ), + SHC( 0x6bb0 ), + SHC( 0x6c0a ), + SHC( 0x6c63 ), + SHC( 0x6cbc ), + SHC( 0x6d13 ), + SHC( 0x6d6a ), + SHC( 0x6dc0 ), + SHC( 0x6e15 ), + SHC( 0x6e69 ), + SHC( 0x6ebd ), + SHC( 0x6f0f ), + SHC( 0x6f60 ), + SHC( 0x6fb1 ), + SHC( 0x7001 ), + SHC( 0x7050 ), + SHC( 0x709e ), + SHC( 0x70eb ), + SHC( 0x7138 ), + SHC( 0x7183 ), + SHC( 0x71ce ), + SHC( 0x7218 ), + SHC( 0x7261 ), + SHC( 0x72a9 ), + SHC( 0x72f0 ), + SHC( 0x7337 ), + SHC( 0x737d ), + SHC( 0x73c1 ), + SHC( 0x7405 ), + SHC( 0x7448 ), + SHC( 0x748b ), + SHC( 0x74cc ), + SHC( 0x750d ), + SHC( 0x754d ), + SHC( 0x758c ), + SHC( 0x75ca ), + SHC( 0x7607 ), + SHC( 0x7644 ), + SHC( 0x7680 ), + SHC( 0x76bb ), + SHC( 0x76f5 ), + SHC( 0x772e ), + SHC( 0x7767 ), + SHC( 0x779f ), + SHC( 0x77d6 ), + SHC( 0x780c ), + SHC( 0x7841 ), + SHC( 0x7876 ), + SHC( 0x78aa ), + SHC( 0x78dd ), + SHC( 0x790f ), + SHC( 0x7940 ), + SHC( 0x7971 ), + SHC( 0x79a1 ), + SHC( 0x79d0 ), + SHC( 0x79ff ), + SHC( 0x7a2c ), + SHC( 0x7a59 ), + SHC( 0x7a85 ), + SHC( 0x7ab1 ), + SHC( 0x7adb ), + SHC( 0x7b05 ), + SHC( 0x7b2e ), + SHC( 0x7b57 ), + SHC( 0x7b7e ), + SHC( 0x7ba5 ), + SHC( 0x7bcb ), + SHC( 0x7bf1 ), + SHC( 0x7c16 ), + SHC( 0x7c3a ), + SHC( 0x7c5d ), + SHC( 0x7c80 ), + SHC( 0x7ca1 ), + SHC( 0x7cc3 ), + SHC( 0x7ce3 ), + SHC( 0x7d03 ), + SHC( 0x7d22 ), + SHC( 0x7d40 ), + SHC( 0x7d5e ), + SHC( 0x7d7b ), + SHC( 0x7d97 ), + SHC( 0x7db3 ), + SHC( 0x7dce ), + SHC( 0x7de8 ), + SHC( 0x7e02 ), + SHC( 0x7e1b ), + SHC( 0x7e33 ), + SHC( 0x7e4a ), + SHC( 0x7e61 ), + SHC( 0x7e78 ), + SHC( 0x7e8d ), + SHC( 0x7ea2 ), + SHC( 0x7eb6 ), + SHC( 0x7eca ), + SHC( 0x7edd ), + SHC( 0x7ef0 ), + SHC( 0x7f01 ), + SHC( 0x7f12 ), + SHC( 0x7f23 ), + SHC( 0x7f33 ), + SHC( 0x7f42 ), + SHC( 0x7f51 ), + SHC( 0x7f5f ), + SHC( 0x7f6c ), + SHC( 0x7f79 ), + SHC( 0x7f85 ), + SHC( 0x7f91 ), + SHC( 0x7f9c ), + SHC( 0x7fa6 ), + SHC( 0x7fb0 ), + SHC( 0x7fb9 ), + SHC( 0x7fc2 ), + SHC( 0x7fca ), + SHC( 0x7fd1 ), + SHC( 0x7fd8 ), + SHC( 0x7fdf ), + SHC( 0x7fe4 ), + SHC( 0x7fea ), + SHC( 0x7fee ), + SHC( 0x7ff2 ), + SHC( 0x7ff6 ), + SHC( 0x7ff9 ), + SHC( 0x7ffb ), + SHC( 0x7ffd ), + SHC( 0x7ffe ), + SHC( 0x7fff ), + SHC( 0x7fff ), }; #ifdef IVAS_FLOAT_FIXED -const Masa_Diffuseness_Ratios masa_diffuse_ratios[DIRAC_DIFFUSE_LEVELS][DIRAC_DIFFUSE_LEVELS] = -{ -{ +const Masa_Diffuseness_Ratios masa_diffuse_ratios[DIRAC_DIFFUSE_LEVELS][DIRAC_DIFFUSE_LEVELS] = { + { { 0, 0, 0, 0 }, { 0, 0, 0, 1 }, { 0, 0, 0, 2 }, @@ -646,8 +1170,8 @@ const Masa_Diffuseness_Ratios masa_diffuse_ratios[DIRAC_DIFFUSE_LEVELS][DIRAC_DI { 0, 3, 0, 5 }, { 0, 5, 0, 6 }, { 0, 7, 0, 7 }, -}, -{ + }, + { { 0, 0, 1, 0 }, { 0, 0, 1, 1 }, { 0, 0, 1, 2 }, @@ -656,8 +1180,8 @@ const Masa_Diffuseness_Ratios masa_diffuse_ratios[DIRAC_DIFFUSE_LEVELS][DIRAC_DI { 0, 3, 1, 5 }, { 0, 5, 1, 6 }, { 0, 7, 1, 7 }, -}, -{ + }, + { { 0, 0, 2, 0 }, { 0, 0, 2, 1 }, { 0, 0, 2, 2 }, @@ -666,8 +1190,8 @@ const Masa_Diffuseness_Ratios masa_diffuse_ratios[DIRAC_DIFFUSE_LEVELS][DIRAC_DI { 0, 3, 2, 5 }, { 0, 5, 2, 6 }, { 0, 7, 2, 7 }, -}, -{ + }, + { { 1, 0, 3, 0 }, { 1, 0, 3, 1 }, { 1, 0, 3, 2 }, @@ -676,8 +1200,8 @@ const Masa_Diffuseness_Ratios masa_diffuse_ratios[DIRAC_DIFFUSE_LEVELS][DIRAC_DI { 1, 3, 3, 5 }, { 1, 5, 3, 6 }, { 1, 7, 3, 7 }, -}, -{ + }, + { { 2, 0, 4, 0 }, { 2, 0, 4, 1 }, { 2, 0, 4, 2 }, @@ -686,8 +1210,8 @@ const Masa_Diffuseness_Ratios masa_diffuse_ratios[DIRAC_DIFFUSE_LEVELS][DIRAC_DI { 2, 3, 4, 5 }, { 2, 5, 4, 6 }, { 3, 7, 4, 7 }, -}, -{ + }, + { { 3, 0, 5, 0 }, { 3, 0, 5, 1 }, { 3, 0, 5, 2 }, @@ -696,8 +1220,8 @@ const Masa_Diffuseness_Ratios masa_diffuse_ratios[DIRAC_DIFFUSE_LEVELS][DIRAC_DI { 3, 3, 5, 5 }, { 3, 4, 5, 6 }, { 4, 7, 5, 7 }, -}, -{ + }, + { { 5, 0, 6, 0 }, { 5, 0, 6, 1 }, { 5, 0, 6, 2 }, @@ -706,8 +1230,8 @@ const Masa_Diffuseness_Ratios masa_diffuse_ratios[DIRAC_DIFFUSE_LEVELS][DIRAC_DI { 4, 3, 6, 5 }, { 4, 4, 6, 6 }, { 5, 7, 6, 7 }, -}, -{ + }, + { { 7, 0, 7, 0 }, { 7, 0, 7, 1 }, { 7, 0, 7, 2 }, @@ -716,7 +1240,7 @@ const Masa_Diffuseness_Ratios masa_diffuse_ratios[DIRAC_DIFFUSE_LEVELS][DIRAC_DI { 7, 4, 7, 5 }, { 7, 5, 7, 6 }, { 6, 6, 7, 7 }, -} + } }; #endif diff --git a/lib_com/ivas_rom_com_fx.h b/lib_com/ivas_rom_com_fx.h index b12c4ab05..80f98bb35 100644 --- a/lib_com/ivas_rom_com_fx.h +++ b/lib_com/ivas_rom_com_fx.h @@ -40,14 +40,14 @@ #include "stat_com.h" #include "ivas_stat_com.h" -extern const Word16 ivas_sin_twiddle_480_fx[ IVAS_480_PT_LEN >> 1 ]; -extern const Word16 ivas_cos_twiddle_480_fx[ IVAS_480_PT_LEN >> 1 ]; -extern const Word16 ivas_sin_twiddle_320_fx[ IVAS_320_PT_LEN >> 1 ]; -extern const Word16 ivas_cos_twiddle_320_fx[ IVAS_320_PT_LEN >> 1 ]; -extern const Word16 ivas_sin_twiddle_160_fx[ IVAS_160_PT_LEN >> 1 ]; -extern const Word16 ivas_cos_twiddle_160_fx[ IVAS_160_PT_LEN >> 1 ]; -extern const Word16 ivas_sin_twiddle_80_fx[ IVAS_80_PT_LEN >> 1 ]; -extern const Word16 ivas_cos_twiddle_80_fx[ IVAS_80_PT_LEN >> 1 ]; +extern const Word16 ivas_sin_twiddle_480_fx[IVAS_480_PT_LEN >> 1]; +extern const Word16 ivas_cos_twiddle_480_fx[IVAS_480_PT_LEN >> 1]; +extern const Word16 ivas_sin_twiddle_320_fx[IVAS_320_PT_LEN >> 1]; +extern const Word16 ivas_cos_twiddle_320_fx[IVAS_320_PT_LEN >> 1]; +extern const Word16 ivas_sin_twiddle_160_fx[IVAS_160_PT_LEN >> 1]; +extern const Word16 ivas_cos_twiddle_160_fx[IVAS_160_PT_LEN >> 1]; +extern const Word16 ivas_sin_twiddle_80_fx[IVAS_80_PT_LEN >> 1]; +extern const Word16 ivas_cos_twiddle_80_fx[IVAS_80_PT_LEN >> 1]; extern const Word16 nf_tw_smoothing_coeffs_fx[N_LTP_GAIN_MEMS]; extern const Word32 dft_res_gains_q_fx[][2]; extern const Word16 dft_res_cod_alpha_fx[STEREO_DFT_BAND_MAX]; @@ -84,7 +84,7 @@ extern const Word16 pow_10_q11[128]; #ifdef IVAS_FLOAT_FIXED extern const Word32 pow_10_q23[14]; #endif -extern const Word16 ivas_sin_az_fx[ 361 ]; +extern const Word16 ivas_sin_az_fx[361]; extern const Word16 ivas_sine_panning_tbl_fx[601]; extern const Word16 ivas_tan_panning_gain_dirac_tbl_fx[601]; #endif diff --git a/lib_com/ivas_sba_config.c b/lib_com/ivas_sba_config.c index 308813ea9..737127e59 100644 --- a/lib_com/ivas_sba_config.c +++ b/lib_com/ivas_sba_config.c @@ -136,7 +136,7 @@ void ivas_sba_config_fx( } ELSE IF( LT_16( nb_channels, 0 ) ) { - nb_channels = (Word16)ivas_sba_get_nchan_fx( sba_order, sba_planar ); + nb_channels = (Word16) ivas_sba_get_nchan_fx( sba_order, sba_planar ); } ELSE { @@ -250,7 +250,7 @@ Word16 ivas_sba_get_analysis_order( sba_analysis_order = sba_order; - IF ( LT_32(ivas_total_brate, SBA_MIN_BRATE_HOA )) + IF( LT_32( ivas_total_brate, SBA_MIN_BRATE_HOA ) ) { /* Hard coding the sba_analysis_order as 1 as higher not supported below SBA_MIN_BRATE_HOA bitrate */ sba_analysis_order = SBA_FOA_ORDER; @@ -293,16 +293,16 @@ Word16 ivas_sba_get_nchan_fx( { Word16 nb_channels; - IF (sba_planar) + IF( sba_planar ) { - nb_channels = add(mult(2 , sba_order) , 1); + nb_channels = add( mult( 2, sba_order ), 1 ); } ELSE { - nb_channels = mult0(add(sba_order , 1) , add(sba_order , 1)); + nb_channels = mult0( add( sba_order, 1 ), add( sba_order, 1 ) ); } - return (nb_channels); + return ( nb_channels ); } /*-------------------------------------------------------------------* @@ -388,7 +388,7 @@ void ivas_sba_get_spar_hoa_ch_ind( Word16 ch; const Word16 *hoa_ind; - IF (GE_32(ivas_total_brate, IVAS_512k)) + IF( GE_32( ivas_total_brate, IVAS_512k ) ) { hoa_ind = HOA_keep_ind_spar512; } @@ -397,7 +397,7 @@ void ivas_sba_get_spar_hoa_ch_ind( hoa_ind = HOA_keep_ind_spar; } - FOR ( ch = 0; ch < num_md_chs; ch++ ) + FOR( ch = 0; ch < num_md_chs; ch++ ) { HOA_md_ind[ch] = hoa_ind[ch]; } @@ -418,7 +418,7 @@ void ivas_sba_get_spar_hoa_md_flag( Word16 *spar_hoa_md_flag, Word16 *spar_hoa_dirac2spar_md_flag ) { - IF ( GT_16(sba_order, 1) && GE_32(ivas_total_brate, IVAS_256k )) + IF( GT_16( sba_order, 1 ) && GE_32( ivas_total_brate, IVAS_256k ) ) { *spar_hoa_md_flag = 1; } @@ -427,7 +427,7 @@ void ivas_sba_get_spar_hoa_md_flag( *spar_hoa_md_flag = 0; } - IF (GT_16(sba_order, 1) && GE_32(ivas_total_brate, IVAS_512k)) + IF( GT_16( sba_order, 1 ) && GE_32( ivas_total_brate, IVAS_512k ) ) { *spar_hoa_dirac2spar_md_flag = 0; } diff --git a/lib_com/ivas_sns_com_fx.c b/lib_com/ivas_sns_com_fx.c index 3d96e4819..b08155749 100644 --- a/lib_com/ivas_sns_com_fx.c +++ b/lib_com/ivas_sns_com_fx.c @@ -56,7 +56,7 @@ void sns_compute_scf_fx( const PsychoacousticParameters *pPsychParams, const Word16 L_frame, Word32 *scf, - Word16 q) + Word16 q ) { Word16 i, n, k; Word32 x[FDNS_NPTS], xs[FDNS_NPTS], mean, xl4[SNS_NPTS], nf, xl[FDNS_NPTS]; @@ -143,10 +143,11 @@ void sns_compute_scf_fx( /* Noise floor at -40dB */ sum = 0; - for (Word16 ind = 0; ind < FDNS_NPTS; ind++) { - sum += (Word64)xs[ind]; + for ( Word16 ind = 0; ind < FDNS_NPTS; ind++ ) + { + sum += (Word64) xs[ind]; } - mean = (Word32)(sum >> 6); + mean = (Word32) ( sum >> 6 ); nf = Mpy_32_16_1( mean, 3 ); // 3 => powf( 10.0f, -4.0f ) in Q15 nf = L_max( nf, 0 ); // 0 => powf( 2.0f, -32.0f ) in Q15 @@ -205,10 +206,11 @@ void sns_compute_scf_fx( /* Remove mean and scaling */ sum = 0; - for (Word16 ind = 0; ind < SNS_NPTS; ind++) { - sum += (Word64)xl4[ind]; + for ( Word16 ind = 0; ind < SNS_NPTS; ind++ ) + { + sum += (Word64) xl4[ind]; } - mean = (Word32)(sum >> 4); + mean = (Word32) ( sum >> 4 ); FOR( i = 0; i < SNS_NPTS; i++ ) { diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index 592825241..9afcffe24 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -61,18 +61,18 @@ #define IVAS_REMIX_MULT_FAC ( 0.5f ) -#define IVAS_ACTIVEW_DM_F ( 1.0f ) +#define IVAS_ACTIVEW_DM_F ( 1.0f ) #define IVAS_ACTIVEW_DM_F_Q30 ( ONE_IN_Q30 ) -#define IVAS_ACTIVEW_DM_F_DTX ( 0.25f ) +#define IVAS_ACTIVEW_DM_F_DTX ( 0.25f ) #define IVAS_ACTIVEW_DM_F_DTX_Q30 ( 268435456 ) -#define IVAS_ACTIVEW_DM_F_VLBR ( 0.25f ) +#define IVAS_ACTIVEW_DM_F_VLBR ( 0.25f ) #define IVAS_ACTIVEW_DM_F_VLBR_Q30 ( 268435456 ) -#define IVAS_LIN_ACTIVEW_QUAD_ACTIVEW_THRESH ( 3.0f ) +#define IVAS_LIN_ACTIVEW_QUAD_ACTIVEW_THRESH ( 3.0f ) #define IVAS_LIN_ACTIVEW_QUAD_ACTIVEW_THRESH_Q29 ( 1610612736 ) -#define IVAS_P_NORM_SCALING ( 1.0f ) +#define IVAS_P_NORM_SCALING ( 1.0f ) #define IVAS_P_NORM_SCALING_FX ( ONE_IN_Q31 ) // Q31 -#define IVAS_P_NORM_SCALING_DTX ( 0.75f ) +#define IVAS_P_NORM_SCALING_DTX ( 0.75f ) #define IVAS_P_NORM_SCALING_DTX_FX ( 1610612736 ) // Q31 #define IVAS_MAT_DIM_3 ( 3 ) @@ -101,11 +101,11 @@ static void ivas_get_pred_coeffs_fx( const Word16 res_ind, Word16 *q_pred_coeffs, Word16 *q_dm_fv_re ); -static void ivas_reorder_array_fx(Word32 in_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS], const Word16 in_chans, const Word16 order[IVAS_SPAR_MAX_CH], Word32 ***mixer_mat, const Word16 start_band, const Word16 end_band); -static void ivas_get_Wscaling_factor_fx(Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word16 q_cov_real, Word32 pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], Word16 q_pred_coeffs_re, Word32 ***mixer_mat, Word16 q_mixer_mat, const Word16 start_band, const Word16 end_band, const Word16 dtx_vad, const Word16 num_ch, const Word16 *pNum_dmx, const Word16 bands_bw, const Word16 active_w, const Word16 active_w_vlbr, Word32 *pWscale, Word16 *q_pWscale, const Word16 dyn_active_w_flag); -static void ivas_calc_post_pred_per_band_fx(Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word16 q_cov_real, Word32 ***mixer_mat, Word16 q_mixer_mat, const Word16 num_ch, const Word16 band_idx, Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word16 *q_postpred_cov_re); -static Word16 ivas_is_mat_inv_fx(Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM], Word16 q_in_re, const Word16 dim); -static void ivas_calc_mat_inv_fx(Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM], Word16 q_in_re, const Word16 dim, Word32 out_re[MAX_MAT_DIM][MAX_MAT_DIM], Word16 *q_out_re); +static void ivas_reorder_array_fx( Word32 in_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS], const Word16 in_chans, const Word16 order[IVAS_SPAR_MAX_CH], Word32 ***mixer_mat, const Word16 start_band, const Word16 end_band ); +static void ivas_get_Wscaling_factor_fx( Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word16 q_cov_real, Word32 pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], Word16 q_pred_coeffs_re, Word32 ***mixer_mat, Word16 q_mixer_mat, const Word16 start_band, const Word16 end_band, const Word16 dtx_vad, const Word16 num_ch, const Word16 *pNum_dmx, const Word16 bands_bw, const Word16 active_w, const Word16 active_w_vlbr, Word32 *pWscale, Word16 *q_pWscale, const Word16 dyn_active_w_flag ); +static void ivas_calc_post_pred_per_band_fx( Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word16 q_cov_real, Word32 ***mixer_mat, Word16 q_mixer_mat, const Word16 num_ch, const Word16 band_idx, Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word16 *q_postpred_cov_re ); +static Word16 ivas_is_mat_inv_fx( Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM], Word16 q_in_re, const Word16 dim ); +static void ivas_calc_mat_inv_fx( Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM], Word16 q_in_re, const Word16 dim, Word32 out_re[MAX_MAT_DIM][MAX_MAT_DIM], Word16 *q_out_re ); #endif static void ivas_get_pred_coeffs( float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], float ppPred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], float ppDM_Fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], const int16_t in_chans, const int16_t start_band, const int16_t end_band, const int16_t active_w, const int16_t active_w_vlbr, const int16_t dtx_vad, const int16_t from_dirac, const int16_t dyn_active_w_flag, const int16_t res_ind ); @@ -936,7 +936,7 @@ static void ivas_get_pred_coeffs_fx( den_f = L_max( den_f, 1 ); dm_g[b] = activew_quad_thresh; // Q29 DM_F[b] = BASOP_Util_Divide3232_Scale_cadence( Mpy_32_32( dm_g[b], num_f ), den_f, &s_dm_f ); - div_shift = sub(s_dm_f, 2); + div_shift = sub( s_dm_f, 2 ); DM_F[b] = L_shl( DM_F[b], div_shift ); // Q30 } } @@ -1053,20 +1053,21 @@ static void ivas_get_Wscaling_factor_fx( Word16 b, ch, q_tmp, q_postpred_cov_re; Word32 dm_f_local, abs_val; Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; - - q_postpred_cov_re = 0; move16(); - - FOR ( ch = 0; ch < IVAS_SPAR_MAX_CH; ch++ ) + + q_postpred_cov_re = 0; + move16(); + + FOR( ch = 0; ch < IVAS_SPAR_MAX_CH; ch++ ) { set32_fx( postpred_cov_re[ch], 0, IVAS_SPAR_MAX_CH ); } - IF ( EQ_16(dtx_vad, 0) ) + IF( EQ_16( dtx_vad, 0 ) ) { dm_f_local = IVAS_ACTIVEW_DM_F_SCALE_DTX_FX; // Q31 move32(); } - ELSE IF( NE_16(active_w_vlbr, 0) ) + ELSE IF( NE_16( active_w_vlbr, 0 ) ) { dm_f_local = IVAS_ACTIVEW_DM_F_SCALE_VLBR_FX; // Q31 move32(); @@ -1077,61 +1078,63 @@ static void ivas_get_Wscaling_factor_fx( move32(); } - FOR ( b = start_band; b < end_band; b++ ) + FOR( b = start_band; b < end_band; b++ ) { pWscale[b] = 1; move32(); test(); - IF ( EQ_16( active_w, 1 ) && EQ_16( dyn_active_w_flag, 0 ) ) + IF( EQ_16( active_w, 1 ) && EQ_16( dyn_active_w_flag, 0 ) ) { Word16 guard_bits, q_Gw_sq, q_g_sq, q_min, tmp_exp; Word32 Gw_sq, g_sq, tmp; - + g_sq = 0; move32(); - IF ( NE_16(num_ch, pNum_dmx[i_mult( b, bands_bw)]) ) + IF( NE_16( num_ch, pNum_dmx[i_mult( b, bands_bw )] ) ) { - ivas_calc_post_pred_per_band_fx( cov_real, q_cov_real, mixer_mat, q_mixer_mat, num_ch, b, postpred_cov_re, &q_postpred_cov_re); + ivas_calc_post_pred_per_band_fx( cov_real, q_cov_real, mixer_mat, q_mixer_mat, num_ch, b, postpred_cov_re, &q_postpred_cov_re ); } - Gw_sq = BASOP_Util_Divide3232_Scale(cov_real[0][0][b], L_max( postpred_cov_re[0][0], IVAS_FIX_EPS ), &tmp_exp); - q_Gw_sq = add(sub(15, tmp_exp), sub(q_cov_real, q_postpred_cov_re)); + Gw_sq = BASOP_Util_Divide3232_Scale( cov_real[0][0][b], L_max( postpred_cov_re[0][0], IVAS_FIX_EPS ), &tmp_exp ); + q_Gw_sq = add( sub( 15, tmp_exp ), sub( q_cov_real, q_postpred_cov_re ) ); - guard_bits = find_guarded_bits_fx(num_ch); + guard_bits = find_guarded_bits_fx( num_ch ); - FOR ( ch = 0; ch < num_ch - 1; ch++ ) + FOR( ch = 0; ch < num_ch - 1; ch++ ) { - abs_val = L_shr(Mpy_32_32(pred_coeffs_re[ch][b], pred_coeffs_re[ch][b]), guard_bits); - g_sq = L_add(g_sq, abs_val); + abs_val = L_shr( Mpy_32_32( pred_coeffs_re[ch][b], pred_coeffs_re[ch][b] ), guard_bits ); + g_sq = L_add( g_sq, abs_val ); } - q_g_sq = sub(add(q_pred_coeffs_re, q_pred_coeffs_re), add(31, guard_bits)); + q_g_sq = sub( add( q_pred_coeffs_re, q_pred_coeffs_re ), add( 31, guard_bits ) ); - tmp_exp = sub(31, q_Gw_sq); - Gw_sq = Sqrt32(Gw_sq, &tmp_exp); - q_Gw_sq = sub(31, tmp_exp); + tmp_exp = sub( 31, q_Gw_sq ); + Gw_sq = Sqrt32( Gw_sq, &tmp_exp ); + q_Gw_sq = sub( 31, tmp_exp ); - tmp = Mpy_32_32( ONE_IN_Q31 /*4 in Q28*/, Mpy_32_32(dm_f_local, g_sq) ); - q_tmp = sub(q_g_sq, 3); + tmp = Mpy_32_32( ONE_IN_Q31 /*4 in Q28*/, Mpy_32_32( dm_f_local, g_sq ) ); + q_tmp = sub( q_g_sq, 3 ); - q_min = s_min(q_Gw_sq, q_tmp); - Gw_sq = L_shr(Gw_sq, sub(q_Gw_sq, q_min)); - q_Gw_sq = q_min; move16(); - tmp = L_shr(tmp, sub(q_tmp, q_min)); + q_min = s_min( q_Gw_sq, q_tmp ); + Gw_sq = L_shr( Gw_sq, sub( q_Gw_sq, q_min ) ); + q_Gw_sq = q_min; + move16(); + tmp = L_shr( tmp, sub( q_tmp, q_min ) ); - tmp = L_add(Gw_sq, tmp); + tmp = L_add( Gw_sq, tmp ); - tmp_exp = sub(31, q_min); - tmp = Sqrt32(tmp, &tmp_exp); - q_tmp = sub(31, tmp_exp); + tmp_exp = sub( 31, q_min ); + tmp = Sqrt32( tmp, &tmp_exp ); + q_tmp = sub( 31, tmp_exp ); - q_min = s_min(q_Gw_sq, q_tmp); - Gw_sq = L_shr(Gw_sq, sub(q_Gw_sq, q_min)); - q_Gw_sq = q_min; move16(); - tmp = L_shr(tmp, sub(q_tmp, q_min)); + q_min = s_min( q_Gw_sq, q_tmp ); + Gw_sq = L_shr( Gw_sq, sub( q_Gw_sq, q_min ) ); + q_Gw_sq = q_min; + move16(); + tmp = L_shr( tmp, sub( q_tmp, q_min ) ); - pWscale[b] = Mpy_32_32(L_add(Gw_sq, tmp), ONE_IN_Q30 /* 0.5 in Q31*/); + pWscale[b] = Mpy_32_32( L_add( Gw_sq, tmp ), ONE_IN_Q30 /* 0.5 in Q31*/ ); q_pWscale[b] = q_Gw_sq; move16(); } @@ -1257,127 +1260,137 @@ void ivas_create_fullr_dmx_mat( #ifdef IVAS_FLOAT_FIXED void ivas_create_fullr_dmx_mat_fx( - Word32 pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word32 pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], Word16 q_pred_coeffs_re, - Word32 dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], - Word16 q_dm_fv_re, + Word32 dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word16 q_dm_fv_re, Word32 ***mixer_mat, Word16 *q_mixer_mat, - const Word16 in_chans, - const Word16 start_band, - const Word16 end_band, - const Word16 active_w, - ivas_spar_md_com_cfg *hMdCfg) + const Word16 in_chans, + const Word16 start_band, + const Word16 end_band, + const Word16 active_w, + ivas_spar_md_com_cfg *hMdCfg ) { - Word16 i, j, k, b; - const Word16 *order; + Word16 i, j, k, b; + const Word16 *order; Word32 max_val_tmp_p2; - Word32 tmp_p1_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; - Word32 tmp_p2_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; - Word32 down_mix_mat1_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; - Word16 remix_unmix_order; - Word16 nbands; - - max_val_tmp_p2 = 0; move32(); - - nbands = sub(end_band, start_band); - remix_unmix_order = hMdCfg->remix_unmix_order; move16(); - - order = remix_order_set[remix_unmix_order]; move16(); - - FOR (i = 0; i < in_chans; i++) - { - FOR (j = 0; j < in_chans; j++) - { - set32_fx(&tmp_p1_re[i][j][start_band], 0, nbands); - set32_fx(&tmp_p2_re[i][j][start_band], 0, nbands); - set32_fx(&down_mix_mat1_re[i][j][start_band], 0, nbands); - } - } - - FOR (j = 0; j < in_chans; j++) - { - FOR (b = start_band; b < end_band; b++) - { - tmp_p2_re[j][j][b] = L_shl(1, q_pred_coeffs_re); move32(); - max_val_tmp_p2 = L_max(max_val_tmp_p2, L_abs(tmp_p2_re[j][j][b])); - } - } - - FOR (j = 1; j < in_chans; j++) - { - FOR (b = start_band; b < end_band; b++) - { - tmp_p2_re[j][0][b] = -pred_coeffs_re[j - 1][b]; move32(); - max_val_tmp_p2 = L_max(max_val_tmp_p2, L_abs(tmp_p2_re[j][0][b])); - } - } - - IF (EQ_16(active_w, 1)) - { + Word32 tmp_p1_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; + Word32 tmp_p2_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; + Word32 down_mix_mat1_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; + Word16 remix_unmix_order; + Word16 nbands; + + max_val_tmp_p2 = 0; + move32(); + + nbands = sub( end_band, start_band ); + remix_unmix_order = hMdCfg->remix_unmix_order; + move16(); + + order = remix_order_set[remix_unmix_order]; + move16(); + + FOR( i = 0; i < in_chans; i++ ) + { + FOR( j = 0; j < in_chans; j++ ) + { + set32_fx( &tmp_p1_re[i][j][start_band], 0, nbands ); + set32_fx( &tmp_p2_re[i][j][start_band], 0, nbands ); + set32_fx( &down_mix_mat1_re[i][j][start_band], 0, nbands ); + } + } + + FOR( j = 0; j < in_chans; j++ ) + { + FOR( b = start_band; b < end_band; b++ ) + { + tmp_p2_re[j][j][b] = L_shl( 1, q_pred_coeffs_re ); + move32(); + max_val_tmp_p2 = L_max( max_val_tmp_p2, L_abs( tmp_p2_re[j][j][b] ) ); + } + } + + FOR( j = 1; j < in_chans; j++ ) + { + FOR( b = start_band; b < end_band; b++ ) + { + tmp_p2_re[j][0][b] = -pred_coeffs_re[j - 1][b]; + move32(); + max_val_tmp_p2 = L_max( max_val_tmp_p2, L_abs( tmp_p2_re[j][0][b] ) ); + } + } + + IF( EQ_16( active_w, 1 ) ) + { Word16 guard_bits; - Word32 max_val, tmp_re; - - max_val = 0; move32(); - - FOR (j = 0; j < in_chans; j++) - { - FOR (b = start_band; b < end_band; b++) - { - tmp_p1_re[j][j][b] = L_shl(1, q_dm_fv_re); move32(); - max_val = L_max(max_val, L_abs(tmp_p1_re[j][j][b])); - } - } - - FOR (j = 1; j < in_chans; j++) - { - FOR (b = start_band; b < end_band; b++) - { - tmp_p1_re[0][j][b] = dm_fv_re[j - 1][b]; move32(); - max_val = L_max(max_val, L_abs(tmp_p1_re[0][j][b])); - } - } - - guard_bits = add(norm_l(max_val), norm_l(max_val_tmp_p2)); - guard_bits = s_max(sub(find_guarded_bits_fx(sub(end_band, start_band)), guard_bits), 0); - /* 4x4 mult */ - FOR (i = 0; i < in_chans; i++) - { - FOR (j = 0; j < in_chans; j++) - { - FOR (k = 0; k < in_chans; k++) - { - FOR (b = start_band; b < end_band; b++) - { - tmp_re = L_shr(Mpy_32_32(tmp_p2_re[i][k][b], tmp_p1_re[k][j][b]), guard_bits); - down_mix_mat1_re[i][j][b] = L_add(down_mix_mat1_re[i][j][b], tmp_re); move32(); - } - } - } - } - *q_mixer_mat = sub(add(q_dm_fv_re, q_pred_coeffs_re), add(31, guard_bits)); - } - ELSE - { - FOR (j = 0; j < in_chans; j++) - { - FOR (k = 0; k < in_chans; k++) - { - FOR (b = start_band; b < end_band; b++) - { - down_mix_mat1_re[j][k][b] = tmp_p2_re[j][k][b]; move32(); - } - } - } + Word32 max_val, tmp_re; + + max_val = 0; + move32(); + + FOR( j = 0; j < in_chans; j++ ) + { + FOR( b = start_band; b < end_band; b++ ) + { + tmp_p1_re[j][j][b] = L_shl( 1, q_dm_fv_re ); + move32(); + max_val = L_max( max_val, L_abs( tmp_p1_re[j][j][b] ) ); + } + } + + FOR( j = 1; j < in_chans; j++ ) + { + FOR( b = start_band; b < end_band; b++ ) + { + tmp_p1_re[0][j][b] = dm_fv_re[j - 1][b]; + move32(); + max_val = L_max( max_val, L_abs( tmp_p1_re[0][j][b] ) ); + } + } + + guard_bits = add( norm_l( max_val ), norm_l( max_val_tmp_p2 ) ); + guard_bits = s_max( sub( find_guarded_bits_fx( sub( end_band, start_band ) ), guard_bits ), 0 ); + /* 4x4 mult */ + FOR( i = 0; i < in_chans; i++ ) + { + FOR( j = 0; j < in_chans; j++ ) + { + FOR( k = 0; k < in_chans; k++ ) + { + FOR( b = start_band; b < end_band; b++ ) + { + tmp_re = L_shr( Mpy_32_32( tmp_p2_re[i][k][b], tmp_p1_re[k][j][b] ), guard_bits ); + down_mix_mat1_re[i][j][b] = L_add( down_mix_mat1_re[i][j][b], tmp_re ); + move32(); + } + } + } + } + *q_mixer_mat = sub( add( q_dm_fv_re, q_pred_coeffs_re ), add( 31, guard_bits ) ); + } + ELSE + { + FOR( j = 0; j < in_chans; j++ ) + { + FOR( k = 0; k < in_chans; k++ ) + { + FOR( b = start_band; b < end_band; b++ ) + { + down_mix_mat1_re[j][k][b] = tmp_p2_re[j][k][b]; + move32(); + } + } + } *q_mixer_mat = q_pred_coeffs_re; - } + } - IF (NE_16(remix_unmix_order, 3)) - { - ivas_reorder_array_fx(down_mix_mat1_re, in_chans, order, mixer_mat, start_band, end_band); - } + IF( NE_16( remix_unmix_order, 3 ) ) + { + ivas_reorder_array_fx( down_mix_mat1_re, in_chans, order, mixer_mat, start_band, end_band ); + } - return; + return; } #endif // IVAS_FLOAT_FIXED @@ -1426,13 +1439,14 @@ static void ivas_reorder_array_fx( { Word16 i, j, b, idx; - FOR ( i = 0; i < in_chans; i++ ) + FOR( i = 0; i < in_chans; i++ ) { - idx = order[i]; move16(); + idx = order[i]; + move16(); - FOR ( j = 0; j < in_chans; j++ ) + FOR( j = 0; j < in_chans; j++ ) { - FOR ( b = start_band; b < end_band; b++ ) + FOR( b = start_band; b < end_band; b++ ) { mixer_mat[i][j][b] = in_re[idx][j][b]; move32(); @@ -1530,34 +1544,34 @@ static void ivas_calc_post_pred_per_band_fx( Word32 dmx_mat_conj[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; Word32 temp_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; Word32 max_val; - Word64 tmp_re; + Word64 tmp_re; max_val = 1; move32(); - FOR ( i = 0; i < num_ch; i++ ) + FOR( i = 0; i < num_ch; i++ ) { - FOR ( j = 0; j < num_ch; j++ ) + FOR( j = 0; j < num_ch; j++ ) { dmx_mat_conj[i][j] = mixer_mat[j][i][band_idx]; move32(); - max_val = L_max(max_val, L_abs(dmx_mat_conj[i][j])); + max_val = L_max( max_val, L_abs( dmx_mat_conj[i][j] ) ); } } - guard_bits = find_guarded_bits_fx(num_ch); + guard_bits = find_guarded_bits_fx( num_ch ); - tmp = norm_l(max_val); - IF(LT_16(tmp, guard_bits)) + tmp = norm_l( max_val ); + IF( LT_16( tmp, guard_bits ) ) { - guard_bits = sub(guard_bits, tmp); + guard_bits = sub( guard_bits, tmp ); } - ELSE - { - guard_bits = 0; + ELSE + { + guard_bits = 0; move16(); - } + } - FOR ( i = 0; i < num_ch; i++ ) + FOR( i = 0; i < num_ch; i++ ) { set32_fx( temp_mat[i], 0, num_ch ); set32_fx( postpred_cov_re[i], 0, num_ch ); @@ -1566,65 +1580,67 @@ static void ivas_calc_post_pred_per_band_fx( max_val = 1; move32(); /* num_ch x num_ch mult */ - FOR ( i = 0; i < num_ch; i++ ) + FOR( i = 0; i < num_ch; i++ ) { - FOR ( j = 0; j < num_ch; j++ ) + FOR( j = 0; j < num_ch; j++ ) { - tmp_re = 0; - FOR ( k = 0; k < num_ch; k++ ) + tmp_re = 0; + FOR( k = 0; k < num_ch; k++ ) + { + tmp_re = W_add( tmp_re, W_shr( W_mult0_32_32( cov_real[i][k][band_idx], dmx_mat_conj[k][j] ), guard_bits ) ); + } + IF( LT_64( W_abs( tmp_re ), L_shl( IVAS_FIX_EPS, guard_bits ) ) ) { - tmp_re = W_add(tmp_re, W_shr(W_mult0_32_32(cov_real[i][k][band_idx], dmx_mat_conj[k][j]), guard_bits)); + tmp_re = 0; } - IF(LT_64(W_abs(tmp_re), L_shl(IVAS_FIX_EPS, guard_bits))) - { - tmp_re = 0; - } - temp_mat[i][j] = W_extract_l(W_shr(tmp_re, q_mixer_mat)); // Q = (q_cov_real - guard_bits) + temp_mat[i][j] = W_extract_l( W_shr( tmp_re, q_mixer_mat ) ); // Q = (q_cov_real - guard_bits) move32(); - max_val = L_max(max_val, L_abs(temp_mat[i][j])); + max_val = L_max( max_val, L_abs( temp_mat[i][j] ) ); } } - q_temp_mat = sub(q_cov_real, guard_bits); + q_temp_mat = sub( q_cov_real, guard_bits ); - guard_bits = find_guarded_bits_fx(num_ch); + guard_bits = find_guarded_bits_fx( num_ch ); - tmp = norm_l(max_val); - IF(LT_16(tmp, guard_bits)) + tmp = norm_l( max_val ); + IF( LT_16( tmp, guard_bits ) ) { - guard_bits = sub(guard_bits, tmp); + guard_bits = sub( guard_bits, tmp ); } - ELSE - { - guard_bits = 0; + ELSE + { + guard_bits = 0; move16(); - } + } /* num_ch x num_ch mult */ - FOR ( i = 0; i < num_ch; i++ ) + FOR( i = 0; i < num_ch; i++ ) { - FOR ( j = i; j < num_ch; j++ ) + FOR( j = i; j < num_ch; j++ ) { - tmp_re = 0; move64(); - FOR ( k = 0; k < num_ch; k++ ) + tmp_re = 0; + move64(); + FOR( k = 0; k < num_ch; k++ ) { - tmp_re = W_add(tmp_re, W_shr(W_mult0_32_32(mixer_mat[i][k][band_idx], temp_mat[k][j]), guard_bits)); + tmp_re = W_add( tmp_re, W_shr( W_mult0_32_32( mixer_mat[i][k][band_idx], temp_mat[k][j] ), guard_bits ) ); } - IF(LT_64(W_abs(tmp_re), L_shl(IVAS_FIX_EPS, guard_bits))) - { - tmp_re = 0; move64(); - } + IF( LT_64( W_abs( tmp_re ), L_shl( IVAS_FIX_EPS, guard_bits ) ) ) + { + tmp_re = 0; + move64(); + } - postpred_cov_re[i][j] = W_extract_l(W_shr(tmp_re, q_mixer_mat)); + postpred_cov_re[i][j] = W_extract_l( W_shr( tmp_re, q_mixer_mat ) ); move32(); } } - *q_postpred_cov_re = sub(q_temp_mat, guard_bits); + *q_postpred_cov_re = sub( q_temp_mat, guard_bits ); - FOR ( i = 0; i < num_ch; i++ ) + FOR( i = 0; i < num_ch; i++ ) { - FOR ( j = 0; j < i; j++ ) + FOR( j = 0; j < i; j++ ) { postpred_cov_re[i][j] = postpred_cov_re[j][i]; move32(); @@ -1824,7 +1840,7 @@ static void ivas_calc_p_coeffs_per_band( { pSparMd->band_coeffs[b_ts_idx].P_re[j - num_dmx] = cov_uu_re[i - num_dmx][j - num_dmx]; #ifdef IVAS_FLOAT_FIXED - pSparMd->band_coeffs[b_ts_idx].P_re_fx[j - num_dmx] =(Word32) (pSparMd->band_coeffs[b_ts_idx].P_re[j - num_dmx] *ONE_IN_Q22); + pSparMd->band_coeffs[b_ts_idx].P_re_fx[j - num_dmx] = (Word32) ( pSparMd->band_coeffs[b_ts_idx].P_re[j - num_dmx] * ONE_IN_Q22 ); #endif } } @@ -1857,20 +1873,21 @@ static void ivas_calc_p_coeffs_per_band_fx( Word32 cov_uu_re[IVAS_SPAR_MAX_CH - 1][IVAS_SPAR_MAX_CH - 1]; Word16 b_ts_idx; - b_ts_idx = add(band_idx, imult1616(i_ts, IVAS_MAX_NUM_BANDS)); + b_ts_idx = add( band_idx, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) ); IF( NE_16( num_dmx, num_ch ) ) { set32_fx( pSparMd->band_coeffs[b_ts_idx].P_re_fx, 0, IVAS_SPAR_MAX_CH - 1 ); - pSparMd->band_coeffs[b_ts_idx].q_P_re_fx = 0;move16(); - FOR ( i = 0; i < IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS; i++ ) + pSparMd->band_coeffs[b_ts_idx].q_P_re_fx = 0; + move16(); + FOR( i = 0; i < IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS; i++ ) { set32_fx( recon_uu_re[i], 0, IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ); } - FOR ( i = num_dmx; i < num_ch; i++ ) + FOR( i = num_dmx; i < num_ch; i++ ) { - FOR ( j = num_dmx; j < num_ch; j++ ) + FOR( j = num_dmx; j < num_ch; j++ ) { cov_uu_re[i - num_dmx][j - num_dmx] = postpred_cov_re[i][j]; move32(); @@ -1879,97 +1896,99 @@ static void ivas_calc_p_coeffs_per_band_fx( q_cov_uu_re = q_postpred_cov_re; move16(); - IF ( dtx_vad == 1 ) + IF( dtx_vad == 1 ) { - FOR ( i = 1; i < num_dmx; i++ ) + FOR( i = 1; i < num_dmx; i++ ) { - FOR ( j = 1; j < num_dmx; j++ ) + FOR( j = 1; j < num_dmx; j++ ) { cov_dd_re[i - 1][j - 1] = postpred_cov_re[i][j]; move32(); } } - Word16 q_C_re = pSparMd->band_coeffs[b_ts_idx].q_C_re_fx; move16(); - - IF ( EQ_16( num_dmx, 2 ) ) + Word16 q_C_re = pSparMd->band_coeffs[b_ts_idx].q_C_re_fx; + move16(); + + IF( EQ_16( num_dmx, 2 ) ) { Word32 re1, re2; - re1 = W_extract_l(W_shr( W_mult0_32_32(pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], cov_dd_re[0][0]), q_C_re)); - re2 = W_extract_l(W_shr(W_mult0_32_32(pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], cov_dd_re[0][0]), q_C_re)); + re1 = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], cov_dd_re[0][0] ), q_C_re ) ); + re2 = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], cov_dd_re[0][0] ), q_C_re ) ); - recon_uu_re[0][0] = W_extract_l(W_shr(W_mult0_32_32(pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], re1), q_C_re)); - recon_uu_re[0][1] = W_extract_l(W_shr(W_mult0_32_32(pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], re1), q_C_re)); - recon_uu_re[1][0] = W_extract_l(W_shr(W_mult0_32_32(pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], re2), q_C_re)); - recon_uu_re[1][1] = W_extract_l(W_shr(W_mult0_32_32(pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], re2), q_C_re)); + recon_uu_re[0][0] = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], re1 ), q_C_re ) ); + recon_uu_re[0][1] = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], re1 ), q_C_re ) ); + recon_uu_re[1][0] = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], re2 ), q_C_re ) ); + recon_uu_re[1][1] = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], re2 ), q_C_re ) ); - FOR ( i = 0; i < 2; i++ ) + FOR( i = 0; i < 2; i++ ) { - FOR ( j = 0; j < 2; j++ ) + FOR( j = 0; j < 2; j++ ) { - cov_uu_re[i][j] = L_sub(cov_uu_re[i][j], recon_uu_re[i][j]); + cov_uu_re[i][j] = L_sub( cov_uu_re[i][j], recon_uu_re[i][j] ); move32(); } } } - ELSE IF ( EQ_16( num_dmx, 3 ) ) + ELSE IF( EQ_16( num_dmx, 3 ) ) { Word32 re1[2], re2; set32_fx( re1, 0, 2 ); - FOR ( j = 0; j < 2; j++ ) + FOR( j = 0; j < 2; j++ ) { - FOR ( k = 0; k < 2; k++ ) + FOR( k = 0; k < 2; k++ ) { Word32 re; - re = W_extract_l(W_shr(W_mult0_32_32(pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][k], cov_dd_re[k][j]), q_C_re)); - re1[j] = L_add(re1[j], re); + re = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][k], cov_dd_re[k][j] ), q_C_re ) ); + re1[j] = L_add( re1[j], re ); move32(); } } - re2 = W_extract_l(W_shr(W_mult0_32_32(pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], re1[0]), q_C_re)); - recon_uu_re[0][0] = re2; move32(); - re2 = W_extract_l(W_shr(W_mult0_32_32(pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][1], re1[1]), q_C_re)); - recon_uu_re[0][0] = L_add(recon_uu_re[0][0], re2); + re2 = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], re1[0] ), q_C_re ) ); + recon_uu_re[0][0] = re2; + move32(); + re2 = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][1], re1[1] ), q_C_re ) ); + recon_uu_re[0][0] = L_add( recon_uu_re[0][0], re2 ); - cov_uu_re[0][0] = L_sub(cov_uu_re[0][0], recon_uu_re[0][0]); + cov_uu_re[0][0] = L_sub( cov_uu_re[0][0], recon_uu_re[0][0] ); } - ELSE IF ( EQ_16( num_dmx, 4 ) ) + ELSE IF( EQ_16( num_dmx, 4 ) ) { /* Step 1: Multiply C * cov_dd * C' */ Word32 re1[3], re; - FOR ( i = 0; i < num_ch - num_dmx; i++ ) + FOR( i = 0; i < num_ch - num_dmx; i++ ) { set32_fx( re1, 0, 3 ); - FOR ( m = 0; m < num_dmx - 1; m++ ) + FOR( m = 0; m < num_dmx - 1; m++ ) { - FOR ( k = 0; k < num_dmx - 1; k++ ) + FOR( k = 0; k < num_dmx - 1; k++ ) { - re = W_extract_l(W_shr(W_mult0_32_32(pSparMd->band_coeffs[b_ts_idx].C_re_fx[i][k], cov_dd_re[k][m]), q_C_re)); - re1[m] = L_add(re1[m], re); + re = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[i][k], cov_dd_re[k][m] ), q_C_re ) ); + re1[m] = L_add( re1[m], re ); move32(); } } - FOR ( j = 0; j < num_ch - num_dmx; j++ ) + FOR( j = 0; j < num_ch - num_dmx; j++ ) { - FOR ( m = 0; m < num_dmx - 1; m++ ) + FOR( m = 0; m < num_dmx - 1; m++ ) { - re = W_extract_l(W_shr(W_mult0_32_32(pSparMd->band_coeffs[b_ts_idx].C_re_fx[j][m], re1[m]), q_C_re)); - recon_uu_re[i][j] = L_add(recon_uu_re[i][j], re); + re = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[j][m], re1[m] ), q_C_re ) ); + recon_uu_re[i][j] = L_add( recon_uu_re[i][j], re ); move32(); } } } /* Step 2: cov_uu - recon_uu */ - FOR ( i = 0; i < num_ch - num_dmx; i++ ) + FOR( i = 0; i < num_ch - num_dmx; i++ ) { - FOR ( j = 0; j < num_ch - num_dmx; j++ ) + FOR( j = 0; j < num_ch - num_dmx; j++ ) { - cov_uu_re[i][j] = L_sub(cov_uu_re[i][j], recon_uu_re[i][j]); + cov_uu_re[i][j] = L_sub( cov_uu_re[i][j], recon_uu_re[i][j] ); move32(); } } @@ -1979,8 +1998,8 @@ static void ivas_calc_p_coeffs_per_band_fx( p_norm_scaling = IVAS_P_NORM_SCALING_FX; move32(); - test(); - IF ( EQ_16( dtx_vad, 0 ) && EQ_16( num_dmx, 1 ) ) + test(); + IF( EQ_16( dtx_vad, 0 ) && EQ_16( num_dmx, 1 ) ) { p_norm_scaling = IVAS_P_NORM_SCALING_DTX_FX; move32(); @@ -1989,27 +2008,28 @@ static void ivas_calc_p_coeffs_per_band_fx( trace = 0; move32(); - FOR ( i = num_dmx; i < num_ch; i++ ) + FOR( i = num_dmx; i < num_ch; i++ ) { - trace = L_add(trace, L_abs(cov_uu_re[i - num_dmx][i - num_dmx])); + trace = L_add( trace, L_abs( cov_uu_re[i - num_dmx][i - num_dmx] ) ); } factor = L_max( IVAS_FIX_EPS, postpred_cov_re[0][0] ); factor = L_max( factor, Mpy_32_32( p_norm_scaling, trace ) ); - Word16 factor_exp = 0; move16(); - factor = BASOP_Util_Divide3232_Scale(L_shl(1, q_postpred_cov_re), factor, &factor_exp); - factor = L_shl_sat(factor, factor_exp); + Word16 factor_exp = 0; + move16(); + factor = BASOP_Util_Divide3232_Scale( L_shl( 1, q_postpred_cov_re ), factor, &factor_exp ); + factor = L_shl_sat( factor, factor_exp ); /* normalise Hermitian (except for rounding) cov_uu */ - FOR ( i = num_dmx; i < num_ch; i++ ) + FOR( i = num_dmx; i < num_ch; i++ ) { - FOR ( j = num_dmx; j < num_ch; j++ ) + FOR( j = num_dmx; j < num_ch; j++ ) { - IF ( EQ_16(i, j) ) + IF( EQ_16( i, j ) ) { /* force diagonal to be real */ - cov_uu_re[i - num_dmx][j - num_dmx] = W_extract_l(W_shr(W_mult0_32_32(cov_uu_re[i - num_dmx][j - num_dmx], factor), 15)); + cov_uu_re[i - num_dmx][j - num_dmx] = W_extract_l( W_shr( W_mult0_32_32( cov_uu_re[i - num_dmx][j - num_dmx], factor ), 15 ) ); move32(); } ELSE @@ -2021,29 +2041,30 @@ static void ivas_calc_p_coeffs_per_band_fx( } } - Word16 cov_uu_re_exp; + Word16 cov_uu_re_exp; /* take sqrt of max of diags and zero */ - FOR ( i = num_dmx; i < num_ch; i++ ) + FOR( i = num_dmx; i < num_ch; i++ ) { - cov_uu_re_exp = sub(31, q_cov_uu_re); + cov_uu_re_exp = sub( 31, q_cov_uu_re ); cov_uu_re[i - num_dmx][i - num_dmx] = Sqrt32( L_max( 0, cov_uu_re[i - num_dmx][i - num_dmx] ), &cov_uu_re_exp ); - cov_uu_re[i - num_dmx][i - num_dmx] = L_shl(cov_uu_re[i - num_dmx][i - num_dmx], sub( q_cov_uu_re, sub(31, cov_uu_re_exp))); - move32(); move32(); + cov_uu_re[i - num_dmx][i - num_dmx] = L_shl( cov_uu_re[i - num_dmx][i - num_dmx], sub( q_cov_uu_re, sub( 31, cov_uu_re_exp ) ) ); + move32(); + move32(); } /* save into MD struct */ - FOR ( i = num_dmx; i < num_ch; i++ ) + FOR( i = num_dmx; i < num_ch; i++ ) { - FOR ( j = num_dmx; j < num_ch; j++ ) + FOR( j = num_dmx; j < num_ch; j++ ) { - IF ( EQ_16(i, j) ) + IF( EQ_16( i, j ) ) { pSparMd->band_coeffs[b_ts_idx].P_re_fx[j - num_dmx] = cov_uu_re[i - num_dmx][j - num_dmx]; move32(); } } } - pSparMd->band_coeffs[b_ts_idx].q_P_re_fx = q_cov_uu_re; + pSparMd->band_coeffs[b_ts_idx].q_P_re_fx = q_cov_uu_re; move16(); } @@ -2150,123 +2171,127 @@ static void ivas_calc_c_coeffs_per_band( #ifdef IVAS_FLOAT_FIXED static void ivas_calc_c_coeffs_per_band_fx( - ivas_spar_md_t *pSparMd, - const Word16 i_ts, - Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - Word16 q_post_pred_cov_re, - const Word16 num_ch, - const Word16 num_dmx, - const Word16 band_idx, - const Word16 dtx_vad) + ivas_spar_md_t *pSparMd, + const Word16 i_ts, + Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 q_post_pred_cov_re, + const Word16 num_ch, + const Word16 num_dmx, + const Word16 band_idx, + const Word16 dtx_vad ) { - Word16 i, j, k; - - /* worst case for cov_ud is actually 12 x 3 */ - Word32 cov_ud_re[IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS][IVAS_SPAR_MAX_DMX_CHS - 1]; - Word32 cov_dd_re[FOA_CHANNELS - 1][FOA_CHANNELS - 1]; - Word32 cov_dd_re_inv[FOA_CHANNELS - 1][FOA_CHANNELS - 1]; - Word16 q_cov_dd_re_inv; - Word32 trace_cov_dd_re; - Word32 abs_trace; - Word16 b_ts_idx; - - b_ts_idx = add(band_idx, imult1616(i_ts, IVAS_MAX_NUM_BANDS)); - - IF (EQ_16(dtx_vad, 0)) - { - set32_fx(&pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], 0, (IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS) * (IVAS_SPAR_MAX_DMX_CHS - 1)); - pSparMd->band_coeffs[b_ts_idx].q_C_re_fx = 0; move16(); - return; - } - - FOR (i = num_dmx; i < num_ch; i++) - { - FOR (j = 1; j < num_dmx; j++) - { - cov_ud_re[i - num_dmx][j - 1] = postpred_cov_re[i][j]; + Word16 i, j, k; + + /* worst case for cov_ud is actually 12 x 3 */ + Word32 cov_ud_re[IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS][IVAS_SPAR_MAX_DMX_CHS - 1]; + Word32 cov_dd_re[FOA_CHANNELS - 1][FOA_CHANNELS - 1]; + Word32 cov_dd_re_inv[FOA_CHANNELS - 1][FOA_CHANNELS - 1]; + Word16 q_cov_dd_re_inv; + Word32 trace_cov_dd_re; + Word32 abs_trace; + Word16 b_ts_idx; + + b_ts_idx = add( band_idx, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) ); + + IF( EQ_16( dtx_vad, 0 ) ) + { + set32_fx( &pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], 0, ( IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ) * ( IVAS_SPAR_MAX_DMX_CHS - 1 ) ); + pSparMd->band_coeffs[b_ts_idx].q_C_re_fx = 0; + move16(); + return; + } + + FOR( i = num_dmx; i < num_ch; i++ ) + { + FOR( j = 1; j < num_dmx; j++ ) + { + cov_ud_re[i - num_dmx][j - 1] = postpred_cov_re[i][j]; move32(); - } - } + } + } - FOR (i = 1; i < num_dmx; i++) - { - FOR (j = 1; j < num_dmx; j++) - { - cov_dd_re[i - 1][j - 1] = postpred_cov_re[i][j]; - } - } + FOR( i = 1; i < num_dmx; i++ ) + { + FOR( j = 1; j < num_dmx; j++ ) + { + cov_dd_re[i - 1][j - 1] = postpred_cov_re[i][j]; + } + } trace_cov_dd_re = 0; move32(); - FOR (i = 0; i < num_dmx - 1; i++) - { - trace_cov_dd_re = L_add(trace_cov_dd_re, cov_dd_re[i][i]); - } - trace_cov_dd_re = Mpy_32_32(trace_cov_dd_re, 10737418 /* 0.005f in Q31*/); - - abs_trace = L_abs(trace_cov_dd_re); - - IF (LE_32( abs_trace , IVAS_FIX_EPS)) - { - /* protection from cases when variance of residual channels is very small */ - set32_fx(&pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], 0, (IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS) * (IVAS_SPAR_MAX_DMX_CHS - 1)); - pSparMd->band_coeffs[b_ts_idx].q_C_re_fx = 0; move16(); - } - ELSE - { - FOR (i = 0; i < num_dmx - 1; i++) - { - cov_dd_re[i][i] = L_add(trace_cov_dd_re, cov_dd_re[i][i]); + FOR( i = 0; i < num_dmx - 1; i++ ) + { + trace_cov_dd_re = L_add( trace_cov_dd_re, cov_dd_re[i][i] ); + } + trace_cov_dd_re = Mpy_32_32( trace_cov_dd_re, 10737418 /* 0.005f in Q31*/ ); + + abs_trace = L_abs( trace_cov_dd_re ); + + IF( LE_32( abs_trace, IVAS_FIX_EPS ) ) + { + /* protection from cases when variance of residual channels is very small */ + set32_fx( &pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], 0, ( IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ) * ( IVAS_SPAR_MAX_DMX_CHS - 1 ) ); + pSparMd->band_coeffs[b_ts_idx].q_C_re_fx = 0; + move16(); + } + ELSE + { + FOR( i = 0; i < num_dmx - 1; i++ ) + { + cov_dd_re[i][i] = L_add( trace_cov_dd_re, cov_dd_re[i][i] ); move32(); - } - test(); - IF (EQ_16( ivas_is_mat_inv_fx(cov_dd_re, q_post_pred_cov_re, num_dmx - 1), 1) && LT_16(num_dmx, FOA_CHANNELS)) - { - set32_fx(&pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], 0, (IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS) * (IVAS_SPAR_MAX_DMX_CHS - 1)); - pSparMd->band_coeffs[b_ts_idx].q_C_re_fx = 0; move16(); - } - ELSE - { - ivas_calc_mat_inv_fx(cov_dd_re, q_post_pred_cov_re, num_dmx - 1, cov_dd_re_inv, &q_cov_dd_re_inv); - - Word16 tmp; - Word64 max_val = 1; move64(); - Word64 C_re_fx[IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS][IVAS_SPAR_MAX_DMX_CHS - 1]; - - FOR (i = 0; i < num_ch - num_dmx; i++) - { - FOR (j = 0; j < num_dmx - 1; j++) - { - C_re_fx[i][j] = 0; + } + test(); + IF( EQ_16( ivas_is_mat_inv_fx( cov_dd_re, q_post_pred_cov_re, num_dmx - 1 ), 1 ) && LT_16( num_dmx, FOA_CHANNELS ) ) + { + set32_fx( &pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], 0, ( IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ) * ( IVAS_SPAR_MAX_DMX_CHS - 1 ) ); + pSparMd->band_coeffs[b_ts_idx].q_C_re_fx = 0; + move16(); + } + ELSE + { + ivas_calc_mat_inv_fx( cov_dd_re, q_post_pred_cov_re, num_dmx - 1, cov_dd_re_inv, &q_cov_dd_re_inv ); + + Word16 tmp; + Word64 max_val = 1; + move64(); + Word64 C_re_fx[IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS][IVAS_SPAR_MAX_DMX_CHS - 1]; + + FOR( i = 0; i < num_ch - num_dmx; i++ ) + { + FOR( j = 0; j < num_dmx - 1; j++ ) + { + C_re_fx[i][j] = 0; move64(); - FOR (k = 0; k < num_dmx - 1; k++) - { - C_re_fx[i][j] = W_add_nosat(C_re_fx[i][j], W_mult0_32_32(cov_ud_re[i][k], cov_dd_re_inv[k][j])); + FOR( k = 0; k < num_dmx - 1; k++ ) + { + C_re_fx[i][j] = W_add_nosat( C_re_fx[i][j], W_mult0_32_32( cov_ud_re[i][k], cov_dd_re_inv[k][j] ) ); move64(); - } - IF(LT_64(max_val, W_abs(C_re_fx[i][j]))) - { - max_val = W_abs(C_re_fx[i][j]); - } - } - } - - tmp = s_max(sub(32, W_norm(max_val)), 0); - - FOR(i = 0; i < num_ch - num_dmx; i++) - { - FOR(j = 0; j < num_dmx - 1; j++) - { - pSparMd->band_coeffs[b_ts_idx].C_re_fx[i][j] = W_extract_l(W_shr(C_re_fx[i][j], tmp)); + } + IF( LT_64( max_val, W_abs( C_re_fx[i][j] ) ) ) + { + max_val = W_abs( C_re_fx[i][j] ); + } + } + } + + tmp = s_max( sub( 32, W_norm( max_val ) ), 0 ); + + FOR( i = 0; i < num_ch - num_dmx; i++ ) + { + FOR( j = 0; j < num_dmx - 1; j++ ) + { + pSparMd->band_coeffs[b_ts_idx].C_re_fx[i][j] = W_extract_l( W_shr( C_re_fx[i][j], tmp ) ); move32(); - } - } - pSparMd->band_coeffs[b_ts_idx].q_C_re_fx = sub(add(q_cov_dd_re_inv, q_post_pred_cov_re), tmp); - } - } + } + } + pSparMd->band_coeffs[b_ts_idx].q_C_re_fx = sub( add( q_cov_dd_re_inv, q_post_pred_cov_re ), tmp ); + } + } - return; + return; } #endif // IVAS_FLOAT_FIXED @@ -2310,7 +2335,7 @@ void ivas_calc_c_p_coeffs( { pSparMd->band_coeffs[band_idx + i_ts * IVAS_MAX_NUM_BANDS].C_re[i][j] = 0.0f; #ifdef IVAS_FLOAT_FIXED - pSparMd->band_coeffs[band_idx + i_ts * IVAS_MAX_NUM_BANDS].C_re_fx[i][j] = 0; + pSparMd->band_coeffs[band_idx + i_ts * IVAS_MAX_NUM_BANDS].C_re_fx[i][j] = 0; #endif } } @@ -2327,7 +2352,7 @@ void ivas_calc_c_p_coeffs( pSparMd->band_coeffs[band_idx + i_ts * IVAS_MAX_NUM_BANDS].P_re[i - num_dmx] = 0; #ifdef IVAS_FLOAT_FIXED pSparMd->band_coeffs[band_idx + i_ts * IVAS_MAX_NUM_BANDS].P_re_fx[i - num_dmx] = 0; -#endif +#endif } } } @@ -2340,10 +2365,10 @@ void ivas_calc_c_p_coeffs( void ivas_calc_c_p_coeffs_fx( ivas_spar_md_t *pSparMd, Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - Word16 q_cov_real, + Word16 q_cov_real, const Word16 i_ts, Word32 ***mixer_mat, - Word16 q_mixer_mat, + Word16 q_mixer_mat, const Word16 num_ch, const Word16 num_dmx, const Word16 band_idx, @@ -2354,41 +2379,41 @@ void ivas_calc_c_p_coeffs_fx( Word16 i, j, q_postpred_cov_re; Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; - IF ( NE_16( num_dmx, num_ch )) + IF( NE_16( num_dmx, num_ch ) ) { ivas_calc_post_pred_per_band_fx( cov_real, q_cov_real, mixer_mat, q_mixer_mat, num_ch, band_idx, postpred_cov_re, &q_postpred_cov_re ); - IF ( NE_16(num_dmx, 1 )) + IF( NE_16( num_dmx, 1 ) ) { ivas_calc_c_coeffs_per_band_fx( pSparMd, i_ts, postpred_cov_re, q_postpred_cov_re, num_ch, num_dmx, band_idx, dtx_vad ); } - IF ( dyn_active_w_flag ) + IF( dyn_active_w_flag ) { - FOR ( i = 0; i < num_ch - num_dmx; i++ ) + FOR( i = 0; i < num_ch - num_dmx; i++ ) { - FOR ( j = 0; j < num_dmx - 1; j++ ) + FOR( j = 0; j < num_dmx - 1; j++ ) { pSparMd->band_coeffs[band_idx + i_ts * IVAS_MAX_NUM_BANDS].C_re_fx[i][j] = 0; move32(); } } - pSparMd->band_coeffs[band_idx + i_ts * IVAS_MAX_NUM_BANDS].q_C_re_fx = 0; + pSparMd->band_coeffs[band_idx + i_ts * IVAS_MAX_NUM_BANDS].q_C_re_fx = 0; move16(); } - IF ( EQ_16( compute_p_flag, 1 ) ) + IF( EQ_16( compute_p_flag, 1 ) ) { ivas_calc_p_coeffs_per_band_fx( pSparMd, i_ts, postpred_cov_re, q_postpred_cov_re, num_ch, dtx_vad, num_dmx, band_idx ); } - IF ( dyn_active_w_flag ) + IF( dyn_active_w_flag ) { - FOR ( i = num_dmx; i < num_ch; i++ ) + FOR( i = num_dmx; i < num_ch; i++ ) { pSparMd->band_coeffs[band_idx + i_ts * IVAS_MAX_NUM_BANDS].P_re_fx[i - num_dmx] = 0; move32(); } - pSparMd->band_coeffs[band_idx + i_ts * IVAS_MAX_NUM_BANDS].q_P_re_fx = 0; + pSparMd->band_coeffs[band_idx + i_ts * IVAS_MAX_NUM_BANDS].q_P_re_fx = 0; move16(); } } @@ -2453,64 +2478,63 @@ static void ivas_calc_mat_det( #ifdef IVAS_FLOAT_FIXED static void ivas_calc_mat_det_fx( - Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM], - Word16 q_in_re, - const Word16 dim, - Word64 *det_re, - Word16 *q_det_re -) + Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM], + Word16 q_in_re, + const Word16 dim, + Word64 *det_re, + Word16 *q_det_re ) { - IF ( EQ_16( dim, IVAS_MAT_DIM_3)) - { - Word64 re1, re2, re; - re1 = W_mult0_32_32(in_re[1][1], in_re[2][2]); - re2 = W_mult0_32_32(in_re[1][2], in_re[2][1]); - re = W_sub_nosat(re1, re2); + IF( EQ_16( dim, IVAS_MAT_DIM_3 ) ) + { + Word64 re1, re2, re; + re1 = W_mult0_32_32( in_re[1][1], in_re[2][2] ); + re2 = W_mult0_32_32( in_re[1][2], in_re[2][1] ); + re = W_sub_nosat( re1, re2 ); - re1 = W_mult0_32_32(in_re[0][0], W_extract_h(re)); + re1 = W_mult0_32_32( in_re[0][0], W_extract_h( re ) ); - *det_re = re1; + *det_re = re1; move64(); - re1 = W_mult0_32_32(in_re[1][0], in_re[2][2]); - re2 = W_mult0_32_32(in_re[1][2], in_re[2][0]); - re = W_sub_nosat(re1, re2); + re1 = W_mult0_32_32( in_re[1][0], in_re[2][2] ); + re2 = W_mult0_32_32( in_re[1][2], in_re[2][0] ); + re = W_sub_nosat( re1, re2 ); - re1 = W_mult0_32_32(in_re[0][1], W_extract_h(re)); + re1 = W_mult0_32_32( in_re[0][1], W_extract_h( re ) ); - *det_re = W_sub_nosat(*det_re, re1); + *det_re = W_sub_nosat( *det_re, re1 ); - re1 = W_mult0_32_32(in_re[1][0], in_re[2][1]); - re2 = W_mult0_32_32(in_re[1][1], in_re[2][0]); - re = W_sub_nosat(re1, re2); + re1 = W_mult0_32_32( in_re[1][0], in_re[2][1] ); + re2 = W_mult0_32_32( in_re[1][1], in_re[2][0] ); + re = W_sub_nosat( re1, re2 ); - re1 = W_mult0_32_32(in_re[0][2], W_extract_h(re)); + re1 = W_mult0_32_32( in_re[0][2], W_extract_h( re ) ); - *det_re = W_add_nosat(*det_re, re1); + *det_re = W_add_nosat( *det_re, re1 ); - *q_det_re = add(q_in_re, sub(add(q_in_re, q_in_re), 32)); - } - ELSE IF(EQ_16(dim, IVAS_MAT_DIM_2)) - { - Word64 re1, re2; - re1 = W_mult0_32_32(in_re[0][0], in_re[1][1]); - re2 = W_mult0_32_32(in_re[0][1], in_re[1][0]); - *det_re = W_sub_nosat(re1, re2); - *q_det_re = add(q_in_re, q_in_re); - } - ELSE IF( EQ_16( dim, IVAS_MAT_DIM_1)) - { - *det_re = in_re[0][0]; + *q_det_re = add( q_in_re, sub( add( q_in_re, q_in_re ), 32 ) ); + } + ELSE IF( EQ_16( dim, IVAS_MAT_DIM_2 ) ) + { + Word64 re1, re2; + re1 = W_mult0_32_32( in_re[0][0], in_re[1][1] ); + re2 = W_mult0_32_32( in_re[0][1], in_re[1][0] ); + *det_re = W_sub_nosat( re1, re2 ); + *q_det_re = add( q_in_re, q_in_re ); + } + ELSE IF( EQ_16( dim, IVAS_MAT_DIM_1 ) ) + { + *det_re = in_re[0][0]; move32(); - *q_det_re = q_in_re; + *q_det_re = q_in_re; move16(); - } - ELSE - { - assert(!"matrix dimention not supported!"); - } + } + ELSE + { + assert( !"matrix dimention not supported!" ); + } - return; + return; } #endif // IVAS_FLOAT_FIXED @@ -2562,23 +2586,24 @@ static void ivas_get_mat_cofactor_fx( { Word16 i, j; Word16 r = 0, c = 0; - move16(); move16(); + move16(); + move16(); - FOR ( i = 0; i < MAX_MAT_DIM; i++ ) + FOR( i = 0; i < MAX_MAT_DIM; i++ ) { - FOR ( j = 0; j < MAX_MAT_DIM; j++ ) + FOR( j = 0; j < MAX_MAT_DIM; j++ ) { test(); - IF ( NE_16(i, row) && NE_16(j, col) ) + IF( NE_16( i, row ) && NE_16( j, col ) ) { out_re[r][c] = in_re[i][j]; move64(); - c = add(c, 1); + c = add( c, 1 ); } } - IF ( EQ_16(c, 2 )) + IF( EQ_16( c, 2 ) ) { - r = add(r, 1); + r = add( r, 1 ); c = 0; move16(); } @@ -2692,111 +2717,120 @@ static void ivas_calc_mat_inv( #ifdef IVAS_FLOAT_FIXED static void ivas_calc_mat_inv_fx( - Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM], - Word16 q_in_re, - const Word16 dim, - Word32 out_re[MAX_MAT_DIM][MAX_MAT_DIM], - Word16 *q_out_re) + Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM], + Word16 q_in_re, + const Word16 dim, + Word32 out_re[MAX_MAT_DIM][MAX_MAT_DIM], + Word16 *q_out_re ) { - Word64 det; - Word16 one_by_det, q_one_by_det; - Word16 i, j, q_tmp; - - IF ( EQ_16(dim, IVAS_MAT_DIM_1)) - { - det = W_mult0_32_32(in_re[0][0], in_re[0][0]); - /* assert to catch cases when input is singular matrix*/ - assert(det > 0); - - //det = (dbl_in_re[0][0] * dbl_in_re[0][0]); - //det = 1 / det = 1 / (dbl_in_re[0][0] * dbl_in_re[0][0]); - //dbl_out_re[0][0] = dbl_in_re[0][0] * det = dbl_in_re[0][0] * (1 / (dbl_in_re[0][0] * dbl_in_re[0][0])); - //dbl_out_re[0][0] = 1 / dbl_in_re[0][0]; - - one_by_det = BASOP_Util_Divide3232_Scale(1, in_re[0][0], &q_tmp); - q_one_by_det = sub(15, add(q_tmp, q_in_re)); - - out_re[0][0] = one_by_det; move32(); - *q_out_re = q_one_by_det; move16(); - } - ELSE IF(EQ_16(dim, IVAS_MAT_DIM_2)) - { - Word64 det_re; - Word16 q_det_re; - - ivas_calc_mat_det_fx(in_re, q_in_re, dim, &det_re, &q_det_re); - q_tmp = W_norm(det_re); - q_tmp = s_max(sub(32, q_tmp),0); - - det_re = W_shr(det_re, q_tmp); - q_det_re = sub(q_det_re, q_tmp); - - det = W_mult0_32_32(W_extract_l(det_re), W_extract_l(det_re)); - /* assert to catch cases when input is singular matrix*/ - assert(det > 0); - - one_by_det = BASOP_Util_Divide3232_Scale(1, W_extract_l(det_re), &q_tmp); //Q = (15 - (q_tmp + q_det_re)) - - out_re[0][0] = Mpy_32_16_1(in_re[1][1], one_by_det); - - out_re[0][1] = -Mpy_32_16_1(in_re[0][1], one_by_det); - - out_re[1][0] = -Mpy_32_16_1(in_re[1][0], one_by_det); - - out_re[1][1] = Mpy_32_16_1(in_re[0][0], one_by_det); - - *q_out_re = sub(q_in_re, add(q_tmp, q_det_re)); // Q = (15-(q_tmp + q_det_re)) + q_in_re - 15 - } - ELSE IF(EQ_16(dim, IVAS_MAT_DIM_3)) - { - Word32 fac_re[IVAS_MAT_DIM_3][IVAS_MAT_DIM_3]; - Word64 det_re, W_tmp; - Word16 q_det_re, q_W_tmp = 0; move16(); - Word16 sign = 1; move16(); - - ivas_calc_mat_det_fx(in_re, q_in_re, dim, &det_re, &q_det_re); - q_tmp = W_norm(det_re); - q_tmp = s_max(sub(32, q_tmp), 0); - - det_re = W_shr(det_re, q_tmp); - q_det_re = sub(q_det_re, q_tmp); - - IF(EQ_64(det_re, 0)) - { - det_re = 1; move64(); - } - - one_by_det = BASOP_Util_Divide3232_Scale(1, W_extract_l(det_re), &q_tmp); - q_one_by_det = sub(15, add(q_tmp, q_det_re)); - - FOR (i = 0; i < dim; i++) - { - FOR (j = 0; j < dim; j++) - { - ivas_get_mat_cofactor_fx(in_re, fac_re, i, j); - ivas_calc_mat_det_fx(fac_re, q_in_re, IVAS_MAT_DIM_2, &W_tmp, &q_W_tmp); - - out_re[j][i] = Mpy_32_16_1(W_extract_h(W_tmp), one_by_det); move32(); - out_re[j][i] = W_extract_l(W_mult0_32_32(out_re[j][i], sign)); move32(); - - IF ( s_and(add(i, j), 1) == 0) - { - sign = -1; move16(); - } - ELSE - { - sign = 1; move16(); - } - } - } - *q_out_re = sub(add(sub(q_W_tmp, 32), q_one_by_det), 15); - } - ELSE - { - assert(!"matrix dimension not supported!"); - } - - return; + Word64 det; + Word16 one_by_det, q_one_by_det; + Word16 i, j, q_tmp; + + IF( EQ_16( dim, IVAS_MAT_DIM_1 ) ) + { + det = W_mult0_32_32( in_re[0][0], in_re[0][0] ); + /* assert to catch cases when input is singular matrix*/ + assert( det > 0 ); + + // det = (dbl_in_re[0][0] * dbl_in_re[0][0]); + // det = 1 / det = 1 / (dbl_in_re[0][0] * dbl_in_re[0][0]); + // dbl_out_re[0][0] = dbl_in_re[0][0] * det = dbl_in_re[0][0] * (1 / (dbl_in_re[0][0] * dbl_in_re[0][0])); + // dbl_out_re[0][0] = 1 / dbl_in_re[0][0]; + + one_by_det = BASOP_Util_Divide3232_Scale( 1, in_re[0][0], &q_tmp ); + q_one_by_det = sub( 15, add( q_tmp, q_in_re ) ); + + out_re[0][0] = one_by_det; + move32(); + *q_out_re = q_one_by_det; + move16(); + } + ELSE IF( EQ_16( dim, IVAS_MAT_DIM_2 ) ) + { + Word64 det_re; + Word16 q_det_re; + + ivas_calc_mat_det_fx( in_re, q_in_re, dim, &det_re, &q_det_re ); + q_tmp = W_norm( det_re ); + q_tmp = s_max( sub( 32, q_tmp ), 0 ); + + det_re = W_shr( det_re, q_tmp ); + q_det_re = sub( q_det_re, q_tmp ); + + det = W_mult0_32_32( W_extract_l( det_re ), W_extract_l( det_re ) ); + /* assert to catch cases when input is singular matrix*/ + assert( det > 0 ); + + one_by_det = BASOP_Util_Divide3232_Scale( 1, W_extract_l( det_re ), &q_tmp ); // Q = (15 - (q_tmp + q_det_re)) + + out_re[0][0] = Mpy_32_16_1( in_re[1][1], one_by_det ); + + out_re[0][1] = -Mpy_32_16_1( in_re[0][1], one_by_det ); + + out_re[1][0] = -Mpy_32_16_1( in_re[1][0], one_by_det ); + + out_re[1][1] = Mpy_32_16_1( in_re[0][0], one_by_det ); + + *q_out_re = sub( q_in_re, add( q_tmp, q_det_re ) ); // Q = (15-(q_tmp + q_det_re)) + q_in_re - 15 + } + ELSE IF( EQ_16( dim, IVAS_MAT_DIM_3 ) ) + { + Word32 fac_re[IVAS_MAT_DIM_3][IVAS_MAT_DIM_3]; + Word64 det_re, W_tmp; + Word16 q_det_re, q_W_tmp = 0; + move16(); + Word16 sign = 1; + move16(); + + ivas_calc_mat_det_fx( in_re, q_in_re, dim, &det_re, &q_det_re ); + q_tmp = W_norm( det_re ); + q_tmp = s_max( sub( 32, q_tmp ), 0 ); + + det_re = W_shr( det_re, q_tmp ); + q_det_re = sub( q_det_re, q_tmp ); + + IF( EQ_64( det_re, 0 ) ) + { + det_re = 1; + move64(); + } + + one_by_det = BASOP_Util_Divide3232_Scale( 1, W_extract_l( det_re ), &q_tmp ); + q_one_by_det = sub( 15, add( q_tmp, q_det_re ) ); + + FOR( i = 0; i < dim; i++ ) + { + FOR( j = 0; j < dim; j++ ) + { + ivas_get_mat_cofactor_fx( in_re, fac_re, i, j ); + ivas_calc_mat_det_fx( fac_re, q_in_re, IVAS_MAT_DIM_2, &W_tmp, &q_W_tmp ); + + out_re[j][i] = Mpy_32_16_1( W_extract_h( W_tmp ), one_by_det ); + move32(); + out_re[j][i] = W_extract_l( W_mult0_32_32( out_re[j][i], sign ) ); + move32(); + + IF( s_and( add( i, j ), 1 ) == 0 ) + { + sign = -1; + move16(); + } + ELSE + { + sign = 1; + move16(); + } + } + } + *q_out_re = sub( add( sub( q_W_tmp, 32 ), q_one_by_det ), 15 ); + } + ELSE + { + assert( !"matrix dimension not supported!" ); + } + + return; } #endif // IVAS_FLOAT_FIXED @@ -2840,29 +2874,32 @@ static int16_t ivas_is_mat_inv( #ifdef IVAS_FLOAT_FIXED static Word16 ivas_is_mat_inv_fx( - Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM], - Word16 q_in_re, - const Word16 dim) + Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM], + Word16 q_in_re, + const Word16 dim ) { - Word16 is_det_zero = 0, q_det_re = 0, tmp; move16(); move16(); - Word64 det, det_re; + Word16 is_det_zero = 0, q_det_re = 0, tmp; + move16(); + move16(); + Word64 det, det_re; + + ivas_calc_mat_det_fx( in_re, q_in_re, dim, &det_re, &q_det_re ); - ivas_calc_mat_det_fx(in_re, q_in_re, dim, &det_re, &q_det_re); + tmp = W_norm( det_re ); + tmp = s_max( sub( 32, tmp ), 0 ); - tmp = W_norm(det_re); - tmp = s_max(sub(32, tmp), 0); - - det_re = W_shr(det_re, tmp); - q_det_re = sub(q_det_re, tmp); + det_re = W_shr( det_re, tmp ); + q_det_re = sub( q_det_re, tmp ); - det = W_mult0_32_32(W_extract_l(det_re), W_extract_l(det_re)); + det = W_mult0_32_32( W_extract_l( det_re ), W_extract_l( det_re ) ); - IF (LE_64( det, IVAS_FIX_EPS)) - { - is_det_zero = 1; move16(); - } + IF( LE_64( det, IVAS_FIX_EPS ) ) + { + is_det_zero = 1; + move16(); + } - return is_det_zero; + return is_det_zero; } #endif // IVAS_FLOAT_FIXED @@ -2930,12 +2967,12 @@ void ivas_compute_spar_params( #ifdef IVAS_FLOAT_FIXED void ivas_compute_spar_params_fx( Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - Word16 q_cov_real, + Word16 q_cov_real, Word32 dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], - Word16 *q_dm_fv_re, + Word16 *q_dm_fv_re, const Word16 i_ts, Word32 ***mixer_mat_fx, - Word16 *q_mixer_mat, + Word16 *q_mixer_mat, const Word16 start_band, const Word16 end_band, const Word16 dtx_vad, @@ -2946,7 +2983,7 @@ void ivas_compute_spar_params_fx( ivas_spar_md_com_cfg *hSparCfg, ivas_spar_md_t *hSparMd, Word32 *pWscale_fx, - Word16 *q_pWscale, + Word16 *q_pWscale, const Word16 from_dirac, const Word16 dyn_active_w_flag ) { @@ -2961,48 +2998,52 @@ void ivas_compute_spar_params_fx( ivas_get_Wscaling_factor_fx( cov_real, q_cov_real, pred_coeffs_re, q_pred_coeffs, mixer_mat_fx, *q_mixer_mat, start_band, end_band, dtx_vad, num_ch, hSparCfg->num_dmx_chans_per_band, bands_bw, active_w, active_w_vlbr, pWscale_fx, q_pWscale, dyn_active_w_flag ); - FOR (b = start_band; b < end_band; b++) - { - Word16 tmp_exp, q_tmp, tmp; - Word16 onebyscale_fx = BASOP_Util_Divide3232_Scale(L_shl(1, q_pWscale[b]), pWscale_fx[b], &tmp_exp); - q_tmp = sub(15, tmp_exp); - - tmp = sub(add(q_pred_coeffs, q_tmp), 15); - FOR (i = 0; i < num_ch - 1; i++) - { - hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re_fx[i] = Mpy_32_16_1(pred_coeffs_re[i][b], onebyscale_fx); - move32(); - IF (LT_16( tmp, 0)) - { - tmp = -tmp;move16(); - hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re_fx[i] = L_shl(hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re_fx[i], add(tmp, 22)); - move32(); - } - ELSE { - hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re_fx[i] = L_shr(hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re_fx[i], sub(tmp, 22)); - move32(); - } - } - // hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].q_pred_re_fx = sub(add(q_pred_coeffs, q_tmp), 15); - hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].q_pred_re_fx = Q22; move16(); - - FOR (i = 0; i < num_ch; i++) - { - mixer_mat_fx[0][i][b] = W_extract_l(W_shr(W_mult0_32_32(mixer_mat_fx[0][i][b], pWscale_fx[b]), q_pWscale[b])); + FOR( b = start_band; b < end_band; b++ ) + { + Word16 tmp_exp, q_tmp, tmp; + Word16 onebyscale_fx = BASOP_Util_Divide3232_Scale( L_shl( 1, q_pWscale[b] ), pWscale_fx[b], &tmp_exp ); + q_tmp = sub( 15, tmp_exp ); + + tmp = sub( add( q_pred_coeffs, q_tmp ), 15 ); + FOR( i = 0; i < num_ch - 1; i++ ) + { + hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re_fx[i] = Mpy_32_16_1( pred_coeffs_re[i][b], onebyscale_fx ); + move32(); + IF( LT_16( tmp, 0 ) ) + { + tmp = -tmp; + move16(); + hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re_fx[i] = L_shl( hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re_fx[i], add( tmp, 22 ) ); + move32(); + } + ELSE + { + hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re_fx[i] = L_shr( hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re_fx[i], sub( tmp, 22 ) ); + move32(); + } + } + // hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].q_pred_re_fx = sub(add(q_pred_coeffs, q_tmp), 15); + hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].q_pred_re_fx = Q22; + move16(); + + FOR( i = 0; i < num_ch; i++ ) + { + mixer_mat_fx[0][i][b] = W_extract_l( W_shr( W_mult0_32_32( mixer_mat_fx[0][i][b], pWscale_fx[b] ), q_pWscale[b] ) ); move32(); - } - } + } + } - FOR ( b = start_band; b < end_band; b++ ) + FOR( b = start_band; b < end_band; b++ ) { - ndm = hSparCfg->num_dmx_chans_per_band[b * bands_bw]; move16(); + ndm = hSparCfg->num_dmx_chans_per_band[b * bands_bw]; + move16(); - IF ( NE_16( ndm, num_ch ) ) + IF( NE_16( ndm, num_ch ) ) { - ivas_calc_c_p_coeffs_fx( hSparMd, cov_real, q_cov_real, i_ts, mixer_mat_fx, *q_mixer_mat, num_ch, ndm, b, dtx_vad, 1, dyn_active_w_flag ); - + ivas_calc_c_p_coeffs_fx( hSparMd, cov_real, q_cov_real, i_ts, mixer_mat_fx, *q_mixer_mat, num_ch, ndm, b, dtx_vad, 1, dyn_active_w_flag ); + Word16 q_tmp = hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].q_C_re_fx; - IF( NE_16(ndm, 1 )) + IF( NE_16( ndm, 1 ) ) { #ifdef MSAN_FIX FOR( i = 0; i < num_ch - ndm; i++ ) @@ -3014,11 +3055,11 @@ void ivas_compute_spar_params_fx( } } #else - for (i = 0; i < IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS; i++) + for ( i = 0; i < IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS; i++ ) { - for (int j = 0; j < IVAS_SPAR_MAX_DMX_CHS - 1; j++) + for ( int j = 0; j < IVAS_SPAR_MAX_DMX_CHS - 1; j++ ) { - hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].C_re_fx[i][j] = L_shr(hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].C_re_fx[i][j], sub(q_tmp, 22)); + hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].C_re_fx[i][j] = L_shr( hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].C_re_fx[i][j], sub( q_tmp, 22 ) ); } } #endif @@ -3027,9 +3068,9 @@ void ivas_compute_spar_params_fx( q_tmp = hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].q_P_re_fx; - for (int j = 0; j < IVAS_SPAR_MAX_CH - 1; j++) + for ( int j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) { - hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].P_re_fx[j] = L_shr(hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].P_re_fx[j], sub(q_tmp, 22)); + hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].P_re_fx[j] = L_shr( hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].P_re_fx[j], sub( q_tmp, 22 ) ); } hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].q_P_re_fx = Q22; } @@ -3049,14 +3090,14 @@ void ivas_compute_spar_params_fx( Word32 diff_norm_order1_table[4] = { 0, 805306368, 402653184, 268435456 }; Word32 diff_norm_order2_table[6] = { 0, 1342177280, 671088640, 447392416, 335544320, 268435456 }; Word32 diff_norm_order3_table[8] = { 0, 1879048192, 939524096, 626349376, 469762048, 375809632, 313174688, 268435456 }; -#define EPSILON_FX_THR 70 +#define EPSILON_FX_THR 70 #define ONE_BY_THREE_Q31 715827882 -#define ONE_BY_FIVE_Q31 429496729 +#define ONE_BY_FIVE_Q31 429496729 #define ONE_BY_SEVEN_Q31 306783378 void ivas_get_spar_md_from_dirac_fx( - Word32 azi_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], - Word32 ele_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], - Word32 diffuseness_fx[IVAS_MAX_NUM_BANDS], + Word32 azi_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], + Word32 ele_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], + Word32 diffuseness_fx[IVAS_MAX_NUM_BANDS], const int16_t n_ts, Word32 ***mixer_mat_fx, ivas_spar_md_t *hSpar_md, @@ -3075,33 +3116,33 @@ void ivas_get_spar_md_from_dirac_fx( int16_t block, ch; - //float response_avg[MAX_OUTPUT_CHANNELS]; + // float response_avg[MAX_OUTPUT_CHANNELS]; Word32 response_avg_fx[MAX_OUTPUT_CHANNELS]; - //float response[MAX_PARAM_SPATIAL_SUBFRAMES][MAX_OUTPUT_CHANNELS]; + // float response[MAX_PARAM_SPATIAL_SUBFRAMES][MAX_OUTPUT_CHANNELS]; Word32 response_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MAX_OUTPUT_CHANNELS]; - //float cov_real_dirac[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; + // float cov_real_dirac[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; Word32 cov_real_dirac_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; - //float *pCov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; + // float *pCov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; Word32 *pCov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; - //float dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; + // float dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; Word32 dm_fv_re_fx[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; Word16 q_dm_fv_re_fx = 0; - //float Wscale[IVAS_MAX_NUM_BANDS]; + // float Wscale[IVAS_MAX_NUM_BANDS]; Word16 q_Wscale[IVAS_MAX_NUM_BANDS] = { 0 }; - Word32 Wscale_fx[IVAS_MAX_NUM_BANDS] = { 0 }; - //float mixer_mat_local[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH][IVAS_MAX_NUM_BANDS]; + Word32 Wscale_fx[IVAS_MAX_NUM_BANDS] = { 0 }; + // float mixer_mat_local[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH][IVAS_MAX_NUM_BANDS]; Word32 mixer_mat_local_fx[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH][IVAS_MAX_NUM_BANDS]; - //float **ppMixer_mat[IVAS_MAX_FB_MIXER_OUT_CH]; + // float **ppMixer_mat[IVAS_MAX_FB_MIXER_OUT_CH]; Word32 **ppMixer_mat_fx[IVAS_MAX_FB_MIXER_OUT_CH]; - //float *pMixer_mat[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH]; + // float *pMixer_mat[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH]; Word32 *pMixer_mat_fx[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH]; Word16 q_ppMixer_mat = 0; - //float en_ratio_fac, diff_norm_order1, diff_norm_order2, diff_norm_order3; + // float en_ratio_fac, diff_norm_order1, diff_norm_order2, diff_norm_order3; Word32 en_ratio_fac_fx, diff_norm_order1_fx, diff_norm_order2_fx, diff_norm_order3_fx; int16_t active_w; int16_t ndm, foa_ch, hoa2_ch; - //float P_dir_fact[IVAS_SPAR_MAX_CH - 1]; + // float P_dir_fact[IVAS_SPAR_MAX_CH - 1]; Word32 P_dir_fact_fx[IVAS_SPAR_MAX_CH - 1]; const int16_t *remix_order; @@ -3113,73 +3154,73 @@ void ivas_get_spar_md_from_dirac_fx( // hoa2_ch max 6 foa_ch = FOA_CHANNELS; // foa_ch 4; - //diff_norm_order1 = 3.0f; + // diff_norm_order1 = 3.0f; diff_norm_order1_fx = 3; - //diff_norm_order2 = 5.0f; + // diff_norm_order2 = 5.0f; diff_norm_order2_fx = 5; - //diff_norm_order3 = 7.0f; + // diff_norm_order3 = 7.0f; diff_norm_order3_fx = 7; for ( i = 0; i < IVAS_MAX_FB_MIXER_OUT_CH; i++ ) { for ( j = 0; j < IVAS_MAX_SPAR_FB_MIXER_IN_CH; j++ ) { - //pMixer_mat[i][j] = mixer_mat_local[i][j]; + // pMixer_mat[i][j] = mixer_mat_local[i][j]; pMixer_mat_fx[i][j] = mixer_mat_local_fx[i][j]; } - //ppMixer_mat[i] = pMixer_mat[i]; + // ppMixer_mat[i] = pMixer_mat[i]; ppMixer_mat_fx[i] = pMixer_mat_fx[i]; } if ( ( start_band >= 6 && hSpar_md_cfg->nchan_transport <= 2 && ( dtx_vad == 1 ) ) || ( useLowerRes && start_band >= 3 && hSpar_md_cfg->nchan_transport <= 2 && ( dtx_vad == 1 ) ) ) { - //float P_norm[3]; + // float P_norm[3]; Word32 P_norm_fx[3]; int16_t idx; ndm = hSpar_md_cfg->num_dmx_chans_per_band[start_band - 1]; // ndm max value of 4 - //P_norm[0] = 0.0f; + // P_norm[0] = 0.0f; P_norm_fx[0] = 0; for ( i = 0; i < max( 0, foa_ch - ndm ); i++ ) { // use 64bit if low precission - //P_norm[0] += hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; + // P_norm[0] += hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; P_norm_fx[0] = P_norm_fx[0] + Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); } - //P_norm[0] *= diff_norm_order1 / min( diff_norm_order1, max( 0, foa_ch - ndm ) ); - // P_norm_fx[0] *= diff_norm_order1 / min( diff_norm_order1, max( 0, foa_ch - ndm ) ); + // P_norm[0] *= diff_norm_order1 / min( diff_norm_order1, max( 0, foa_ch - ndm ) ); + // P_norm_fx[0] *= diff_norm_order1 / min( diff_norm_order1, max( 0, foa_ch - ndm ) ); P_norm_fx[0] = Mpy_32_32( L_shl( P_norm_fx[0], 3 ), diff_norm_order1_table[min( diff_norm_order1_fx, max( 0, foa_ch - ndm ) )] ); - // P_norm[1] = 0.0f; + // P_norm[1] = 0.0f; P_norm_fx[1] = 0; for ( ; i < max( 0, min( num_ch, hoa2_ch ) - ndm ); i++ ) { - //P_norm[1] += hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; + // P_norm[1] += hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; P_norm_fx[1] = P_norm_fx[1] + Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); } - //P_norm[1] *= diff_norm_order2 / min( diff_norm_order2, max( 0, min( num_ch, hoa2_ch ) - ndm ) ); - // P_norm_fx[1] *= diff_norm_order2 / min( diff_norm_order2, max( 0, min( num_ch, hoa2_ch ) - ndm ) ); + // P_norm[1] *= diff_norm_order2 / min( diff_norm_order2, max( 0, min( num_ch, hoa2_ch ) - ndm ) ); + // P_norm_fx[1] *= diff_norm_order2 / min( diff_norm_order2, max( 0, min( num_ch, hoa2_ch ) - ndm ) ); P_norm_fx[1] = Mpy_32_32( L_shl( P_norm_fx[1], 3 ), diff_norm_order2_table[min( diff_norm_order2_fx, max( 0, min( num_ch, hoa2_ch ) - ndm ) )] ); - //P_norm[2] = 0.0f; + // P_norm[2] = 0.0f; P_norm_fx[2] = 0; for ( ; i < num_ch - ndm; i++ ) { - //P_norm[2] += hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; + // P_norm[2] += hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; P_norm_fx[2] = P_norm_fx[2] + Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); } - //P_norm[2] *= diff_norm_order3 / min( diff_norm_order3, max( 0, num_ch - ndm ) ); - // P_norm_fx[2] *= diff_norm_order3 / min( diff_norm_order3, max( 0, num_ch - ndm ) ); + // P_norm[2] *= diff_norm_order3 / min( diff_norm_order3, max( 0, num_ch - ndm ) ); + // P_norm_fx[2] *= diff_norm_order3 / min( diff_norm_order3, max( 0, num_ch - ndm ) ); P_norm_fx[2] = Mpy_32_32( L_shl( P_norm_fx[2], 3 ), diff_norm_order3_table[min( diff_norm_order3_fx, max( 0, num_ch - ndm ) )] ); for ( i = 0; i < max( 0, foa_ch - ndm ); i++ ) { idx = remix_order[i + ndm] - ndm; - //P_dir_fact[idx] = hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; + // P_dir_fact[idx] = hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); - //P_dir_fact[idx] = P_dir_fact[idx] / max( IVAS_FLT_EPS, P_norm[0] ); + // P_dir_fact[idx] = P_dir_fact[idx] / max( IVAS_FLT_EPS, P_norm[0] ); if ( P_dir_fact_fx[idx] == 0 ) { P_dir_fact_fx[idx] = 0; @@ -3193,9 +3234,9 @@ void ivas_get_spar_md_from_dirac_fx( for ( ; i < max( 0, min( num_ch, hoa2_ch ) - ndm ); i++ ) { idx = remix_order[i + ndm] - ndm; - //P_dir_fact[idx] = hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; + // P_dir_fact[idx] = hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); - //P_dir_fact[idx] = P_dir_fact[idx] / max( IVAS_FLT_EPS, P_norm[1] ); + // P_dir_fact[idx] = P_dir_fact[idx] / max( IVAS_FLT_EPS, P_norm[1] ); if ( P_dir_fact_fx[idx] == 0 ) { P_dir_fact_fx[idx] = 0; @@ -3203,15 +3244,15 @@ void ivas_get_spar_md_from_dirac_fx( else { P_dir_fact_fx[idx] = divide3232( P_dir_fact_fx[idx], max( P_norm_fx[1], IVAS_FIX_EPS ) ); - P_dir_fact_fx[idx] = L_shl(P_dir_fact_fx[idx], 15); + P_dir_fact_fx[idx] = L_shl( P_dir_fact_fx[idx], 15 ); } } for ( ; i < num_ch - ndm; i++ ) { idx = remix_order[i + ndm] - ndm; - //P_dir_fact[idx] = hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; + // P_dir_fact[idx] = hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); - //P_dir_fact[idx] = P_dir_fact[idx] / max( IVAS_FLT_EPS, P_norm[2] ); + // P_dir_fact[idx] = P_dir_fact[idx] / max( IVAS_FLT_EPS, P_norm[2] ); if ( P_dir_fact_fx[idx] == 0 ) { P_dir_fact_fx[idx] = 0; @@ -3219,7 +3260,7 @@ void ivas_get_spar_md_from_dirac_fx( else { P_dir_fact_fx[idx] = divide3232( P_dir_fact_fx[idx], max( P_norm_fx[2], IVAS_FIX_EPS ) ); - P_dir_fact_fx[idx] = L_shl(P_dir_fact_fx[idx], 15); + P_dir_fact_fx[idx] = L_shl( P_dir_fact_fx[idx], 15 ); } } } @@ -3231,13 +3272,13 @@ void ivas_get_spar_md_from_dirac_fx( ndm = hSpar_md_cfg->num_dmx_chans_per_band[band]; /*SPAR from DirAC*/ - //set_f( response_avg, 0.0f, MAX_OUTPUT_CHANNELS ); + // set_f( response_avg, 0.0f, MAX_OUTPUT_CHANNELS ); set32_fx( response_avg_fx, 0, MAX_OUTPUT_CHANNELS ); if ( n_ts > 1 ) { - //ivas_dirac_dec_get_response( (int16_t) azi_dirac[band][i_ts], (int16_t) ele_dirac[band][i_ts], response_avg, order ); - ivas_dirac_dec_get_response_fx( (int16_t) L_shr(azi_dirac_fx[band][i_ts], Q22), (int16_t) L_shr(ele_dirac_fx[band][i_ts], Q22), response_avg_fx, order ); + // ivas_dirac_dec_get_response( (int16_t) azi_dirac[band][i_ts], (int16_t) ele_dirac[band][i_ts], response_avg, order ); + ivas_dirac_dec_get_response_fx( (int16_t) L_shr( azi_dirac_fx[band][i_ts], Q22 ), (int16_t) L_shr( ele_dirac_fx[band][i_ts], Q22 ), response_avg_fx, order ); /*for ( int l = 0; l < MAX_OUTPUT_CHANNELS; l++ ) { response_avg[l] = (float) response_avg_fx[l] / ( 1 << 30 ); @@ -3245,8 +3286,8 @@ void ivas_get_spar_md_from_dirac_fx( } else if ( useLowerRes ) { - //ivas_dirac_dec_get_response( (int16_t) azi_dirac[band][0], (int16_t) ele_dirac[band][0], response_avg, order ); - ivas_dirac_dec_get_response_fx( (int16_t) L_shr(azi_dirac_fx[band][0], Q22), (int16_t) L_shr(ele_dirac_fx[band][0], Q22), response_avg_fx, order ); + // ivas_dirac_dec_get_response( (int16_t) azi_dirac[band][0], (int16_t) ele_dirac[band][0], response_avg, order ); + ivas_dirac_dec_get_response_fx( (int16_t) L_shr( azi_dirac_fx[band][0], Q22 ), (int16_t) L_shr( ele_dirac_fx[band][0], Q22 ), response_avg_fx, order ); /*for ( int l = 0; l < MAX_OUTPUT_CHANNELS; l++ ) { response_avg[l] = (float) response_avg_fx[l] / ( 1 << 30 ); @@ -3256,8 +3297,8 @@ void ivas_get_spar_md_from_dirac_fx( { for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) { - //ivas_dirac_dec_get_response( (int16_t) azi_dirac[band][block], (int16_t) ele_dirac[band][block], &( response[block][0] ), order ); - ivas_dirac_dec_get_response_fx( (int16_t) L_shr(azi_dirac_fx[band][block], Q22), (int16_t) L_shr(ele_dirac_fx[band][block], Q22), &( response_fx[block][0] ), order ); + // ivas_dirac_dec_get_response( (int16_t) azi_dirac[band][block], (int16_t) ele_dirac[band][block], &( response[block][0] ), order ); + ivas_dirac_dec_get_response_fx( (int16_t) L_shr( azi_dirac_fx[band][block], Q22 ), (int16_t) L_shr( ele_dirac_fx[band][block], Q22 ), &( response_fx[block][0] ), order ); /*for ( int l = 0; l < MAX_OUTPUT_CHANNELS; l++ ) { response[block][l] = (float) response_fx[block][l] / ( 1 << 30 ); @@ -3266,7 +3307,7 @@ void ivas_get_spar_md_from_dirac_fx( /* average responses in all subframes*/ { - //float norm; + // float norm; Word32 norm_fx; Word16 norm_q; int16_t num_ch_order, hoa2_ch_order; @@ -3279,25 +3320,25 @@ void ivas_get_spar_md_from_dirac_fx( Word64 temp = 0; for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) { - //response_avg[ch] += response[block][ch]; + // response_avg[ch] += response[block][ch]; temp = temp + response_fx[block][ch]; } - //response_avg[ch] /= MAX_PARAM_SPATIAL_SUBFRAMES; - response_avg_fx[ch] = W_extract_l(W_shr( temp, 2 )); + // response_avg[ch] /= MAX_PARAM_SPATIAL_SUBFRAMES; + response_avg_fx[ch] = W_extract_l( W_shr( temp, 2 ) ); } /*normalize 1st order*/ - //norm = 0.0f; + // norm = 0.0f; norm_fx = 0; norm_q = 0; for ( ch = 1; ch < foa_ch; ch++ ) { - //norm += response_avg[ch] * response_avg[ch]; + // norm += response_avg[ch] * response_avg[ch]; norm_fx = norm_fx + Mpy_32_32( response_avg_fx[ch], response_avg_fx[ch] ); } norm_q = 31 - ( 30 + 30 - 31 ); - //norm = max( EPSILON, sqrtf( norm ) ); + // norm = max( EPSILON, sqrtf( norm ) ); if ( norm_fx ) { norm_fx = Sqrt32( norm_fx, &norm_q ); @@ -3308,13 +3349,13 @@ void ivas_get_spar_md_from_dirac_fx( } if ( norm_q < 0 ) { - norm_fx = L_shr( norm_fx, (-1 * norm_q) ); + norm_fx = L_shr( norm_fx, ( -1 * norm_q ) ); norm_q = 0; } norm_fx = L_shr( norm_fx, 1 - norm_q ); for ( ch = 1; ch < foa_ch; ch++ ) - { - //response_avg[ch] /= norm; + { + // response_avg[ch] /= norm; if ( norm_fx < EPSILON_FX_THR ) { if ( response_avg_fx[ch] != 0 ) @@ -3332,19 +3373,19 @@ void ivas_get_spar_md_from_dirac_fx( response_avg_fx[ch] = divide3232( response_avg_fx[ch], norm_fx ); response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); } - //response_avg[ch] = (float) response_avg_fx[ch] / ( 1 << 30 ); + // response_avg[ch] = (float) response_avg_fx[ch] / ( 1 << 30 ); } /*normalize 2nd order*/ - //norm = 0.0f; + // norm = 0.0f; norm_fx = 0; for ( ch = foa_ch; ch < min( hoa2_ch_order, num_ch_order ); ch++ ) { - //norm += response_avg[ch] * response_avg[ch]; + // norm += response_avg[ch] * response_avg[ch]; norm_fx = norm_fx + Mpy_32_32( response_avg_fx[ch], response_avg_fx[ch] ); } norm_q = 31 - ( 29 + 29 - 31 ); - //norm = max( EPSILON, sqrtf( norm ) ); + // norm = max( EPSILON, sqrtf( norm ) ); if ( norm_fx ) { norm_fx = Sqrt32( norm_fx, &norm_q ); @@ -3376,18 +3417,18 @@ void ivas_get_spar_md_from_dirac_fx( response_avg_fx[ch] = divide3232( response_avg_fx[ch], norm_fx ); response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); } - //response_avg[ch] = (float)response_avg_fx[ch] / (1 << 30); + // response_avg[ch] = (float)response_avg_fx[ch] / (1 << 30); } /*normalize 3rd order*/ - //norm = 0.0f; + // norm = 0.0f; for ( ch = hoa2_ch_order; ch < num_ch_order; ch++ ) { - //norm += response_avg[ch] * response_avg[ch]; + // norm += response_avg[ch] * response_avg[ch]; norm_fx = norm_fx + Mpy_32_32( response_avg_fx[ch], response_avg_fx[ch] ); } norm_q = 31 - ( 29 + 29 - 31 ); - //norm = max( EPSILON, sqrtf( norm ) ); + // norm = max( EPSILON, sqrtf( norm ) ); if ( norm_fx ) { norm_fx = Sqrt32( norm_fx, &norm_q ); @@ -3404,7 +3445,7 @@ void ivas_get_spar_md_from_dirac_fx( norm_fx = L_shr( norm_fx, 1 - norm_q ); for ( ch = hoa2_ch_order; ch < num_ch_order; ch++ ) { - //response_avg[ch] /= norm; + // response_avg[ch] /= norm; if ( norm_fx < EPSILON_FX_THR ) { response_avg_fx[ch] = response_avg_fx[ch]; @@ -3420,19 +3461,19 @@ void ivas_get_spar_md_from_dirac_fx( response_avg_fx[ch] = divide3232( response_avg_fx[ch], norm_fx ); response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); } - //response_avg[ch] = (float) response_avg_fx[ch] / ( 1 << 30 ); + // response_avg[ch] = (float) response_avg_fx[ch] / ( 1 << 30 ); } } } for ( i = FOA_CHANNELS + 1; i < num_ch; i++ ) { - //response_avg[i] = response_avg[HOA_keep_ind[i]]; + // response_avg[i] = response_avg[HOA_keep_ind[i]]; response_avg_fx[i] = response_avg_fx[HOA_keep_ind[i]]; } - //en_ratio_fac = ( 1.0f - diffuseness[band] ); - en_ratio_fac_fx = ( ONE_IN_Q31 - L_shl_sat(diffuseness_fx[band],1) );//assuming q of dissusion 30 + // en_ratio_fac = ( 1.0f - diffuseness[band] ); + en_ratio_fac_fx = ( ONE_IN_Q31 - L_shl_sat( diffuseness_fx[band], 1 ) ); // assuming q of dissusion 30 for ( i = 0; i < num_ch; i++ ) { @@ -3442,49 +3483,48 @@ void ivas_get_spar_md_from_dirac_fx( { if ( i == 0 ) { - //cov_real_dirac[i][i][band] = 1.0f; + // cov_real_dirac[i][i][band] = 1.0f; cov_real_dirac_fx[i][i][band] = ONE_IN_Q30; } else { Word32 en_ratio_fac_sq = 0; - //cov_real_dirac[i][j][band] = en_ratio_fac * response_avg[i] * response_avg[j]; - cov_real_dirac_fx[i][j][band] = Mpy_32_32(L_shl_sat(Mpy_32_32(en_ratio_fac_fx, response_avg_fx[i]),1), response_avg_fx[j]); + // cov_real_dirac[i][j][band] = en_ratio_fac * response_avg[i] * response_avg[j]; + cov_real_dirac_fx[i][j][band] = Mpy_32_32( L_shl_sat( Mpy_32_32( en_ratio_fac_fx, response_avg_fx[i] ), 1 ), response_avg_fx[j] ); if ( hSpar_md_cfg->nchan_transport <= 2 ) { - //cov_real_dirac[i][j][band] *= en_ratio_fac; - cov_real_dirac_fx[i][j][band] = Mpy_32_32(cov_real_dirac_fx[i][j][band],en_ratio_fac_fx); + // cov_real_dirac[i][j][band] *= en_ratio_fac; + cov_real_dirac_fx[i][j][band] = Mpy_32_32( cov_real_dirac_fx[i][j][band], en_ratio_fac_fx ); if ( ( i >= ndm ) && ( dtx_vad == 1 ) ) { - en_ratio_fac_sq = Mpy_32_32(en_ratio_fac_fx, en_ratio_fac_fx); - cov_real_dirac_fx[i][j][band] = cov_real_dirac_fx[i][j][band] + Mpy_32_32((ONE_IN_Q31 - en_ratio_fac_sq), P_dir_fact_fx[i - ndm]); - //cov_real_dirac[i][j][band] += ( 1.0f - ( en_ratio_fac * en_ratio_fac ) ) * P_dir_fact[i - ndm]; + en_ratio_fac_sq = Mpy_32_32( en_ratio_fac_fx, en_ratio_fac_fx ); + cov_real_dirac_fx[i][j][band] = cov_real_dirac_fx[i][j][band] + Mpy_32_32( ( ONE_IN_Q31 - en_ratio_fac_sq ), P_dir_fact_fx[i - ndm] ); + // cov_real_dirac[i][j][band] += ( 1.0f - ( en_ratio_fac * en_ratio_fac ) ) * P_dir_fact[i - ndm]; } else { if ( i < foa_ch ) { - en_ratio_fac_sq = Mpy_32_32(en_ratio_fac_fx, en_ratio_fac_fx); - Word32 temp = Mpy_32_32((ONE_IN_Q31 - en_ratio_fac_sq), ONE_BY_THREE_Q31); - cov_real_dirac_fx[i][j][band] = cov_real_dirac_fx[i][j][band] + L_shr(temp, 1); - //cov_real_dirac[i][j][band] += ( 1.0f - ( en_ratio_fac * en_ratio_fac ) ) / diff_norm_order1; - + en_ratio_fac_sq = Mpy_32_32( en_ratio_fac_fx, en_ratio_fac_fx ); + Word32 temp = Mpy_32_32( ( ONE_IN_Q31 - en_ratio_fac_sq ), ONE_BY_THREE_Q31 ); + cov_real_dirac_fx[i][j][band] = cov_real_dirac_fx[i][j][band] + L_shr( temp, 1 ); + // cov_real_dirac[i][j][band] += ( 1.0f - ( en_ratio_fac * en_ratio_fac ) ) / diff_norm_order1; } else if ( i < hoa2_ch ) { - en_ratio_fac_sq = Mpy_32_32(en_ratio_fac_fx, en_ratio_fac_fx); - Word32 temp = Mpy_32_32((ONE_IN_Q31 - en_ratio_fac_sq), ONE_BY_FIVE_Q31); - cov_real_dirac_fx[i][j][band] = cov_real_dirac_fx[i][j][band] + L_shr(temp, 1); - //cov_real_dirac[i][j][band] += ( 1.0f - ( en_ratio_fac * en_ratio_fac ) ) / diff_norm_order2; + en_ratio_fac_sq = Mpy_32_32( en_ratio_fac_fx, en_ratio_fac_fx ); + Word32 temp = Mpy_32_32( ( ONE_IN_Q31 - en_ratio_fac_sq ), ONE_BY_FIVE_Q31 ); + cov_real_dirac_fx[i][j][band] = cov_real_dirac_fx[i][j][band] + L_shr( temp, 1 ); + // cov_real_dirac[i][j][band] += ( 1.0f - ( en_ratio_fac * en_ratio_fac ) ) / diff_norm_order2; } else { - en_ratio_fac_sq = Mpy_32_32(en_ratio_fac_fx, en_ratio_fac_fx); - Word32 temp = Mpy_32_32((ONE_IN_Q31 - en_ratio_fac_sq), ONE_BY_SEVEN_Q31); - cov_real_dirac_fx[i][j][band] = cov_real_dirac_fx[i][j][band] + L_shr(temp, 1); - //cov_real_dirac[i][j][band] += ( 1.0f - ( en_ratio_fac * en_ratio_fac ) ) / diff_norm_order3; + en_ratio_fac_sq = Mpy_32_32( en_ratio_fac_fx, en_ratio_fac_fx ); + Word32 temp = Mpy_32_32( ( ONE_IN_Q31 - en_ratio_fac_sq ), ONE_BY_SEVEN_Q31 ); + cov_real_dirac_fx[i][j][band] = cov_real_dirac_fx[i][j][band] + L_shr( temp, 1 ); + // cov_real_dirac[i][j][band] += ( 1.0f - ( en_ratio_fac * en_ratio_fac ) ) / diff_norm_order3; } } } @@ -3492,26 +3532,26 @@ void ivas_get_spar_md_from_dirac_fx( { if ( i < foa_ch ) { - //cov_real_dirac[i][j][band] += ( 1.0f - en_ratio_fac ) / diff_norm_order1; - cov_real_dirac_fx[i][j][band] = cov_real_dirac_fx[i][j][band] + L_shr(Mpy_32_32(( ONE_IN_Q31 - en_ratio_fac_fx ), ONE_BY_THREE_Q31),1); + // cov_real_dirac[i][j][band] += ( 1.0f - en_ratio_fac ) / diff_norm_order1; + cov_real_dirac_fx[i][j][band] = cov_real_dirac_fx[i][j][band] + L_shr( Mpy_32_32( ( ONE_IN_Q31 - en_ratio_fac_fx ), ONE_BY_THREE_Q31 ), 1 ); } else if ( i < hoa2_ch ) { - //cov_real_dirac[i][j][band] += ( 1.0f - en_ratio_fac ) / diff_norm_order2; - cov_real_dirac_fx[i][j][band] = cov_real_dirac_fx[i][j][band] + L_shr(Mpy_32_32((ONE_IN_Q31 - en_ratio_fac_fx), ONE_BY_FIVE_Q31), 1); + // cov_real_dirac[i][j][band] += ( 1.0f - en_ratio_fac ) / diff_norm_order2; + cov_real_dirac_fx[i][j][band] = cov_real_dirac_fx[i][j][band] + L_shr( Mpy_32_32( ( ONE_IN_Q31 - en_ratio_fac_fx ), ONE_BY_FIVE_Q31 ), 1 ); } else { - //cov_real_dirac[i][j][band] += ( 1.0f - en_ratio_fac ) / diff_norm_order3; - cov_real_dirac_fx[i][j][band] = cov_real_dirac_fx[i][j][band] + L_shr(Mpy_32_32((ONE_IN_Q31 - en_ratio_fac_fx), ONE_BY_SEVEN_Q31), 1); + // cov_real_dirac[i][j][band] += ( 1.0f - en_ratio_fac ) / diff_norm_order3; + cov_real_dirac_fx[i][j][band] = cov_real_dirac_fx[i][j][band] + L_shr( Mpy_32_32( ( ONE_IN_Q31 - en_ratio_fac_fx ), ONE_BY_SEVEN_Q31 ), 1 ); } } } } else { - //cov_real_dirac[i][j][band] = en_ratio_fac * response_avg[i] * response_avg[j]; - cov_real_dirac_fx[i][j][band] = L_shl_sat(Mpy_32_32(Mpy_32_32(en_ratio_fac_fx, response_avg_fx[i]), response_avg_fx[j]), 1); + // cov_real_dirac[i][j][band] = en_ratio_fac * response_avg[i] * response_avg[j]; + cov_real_dirac_fx[i][j][band] = L_shl_sat( Mpy_32_32( Mpy_32_32( en_ratio_fac_fx, response_avg_fx[i] ), response_avg_fx[j] ), 1 ); } } } @@ -3521,7 +3561,7 @@ void ivas_get_spar_md_from_dirac_fx( { for ( j = 0; j < num_ch; j++ ) { - //pCov_real[i][j] = cov_real_dirac[i][j]; + // pCov_real[i][j] = cov_real_dirac[i][j]; pCov_real_fx[i][j] = cov_real_dirac_fx[i][j]; } } @@ -3534,25 +3574,25 @@ void ivas_get_spar_md_from_dirac_fx( active_w = ( dyn_active_w_flag == 1 ) || ( hSpar_md_cfg->active_w == 1 ); -// #ifdef IVAS_FLOAT_FIXED + // #ifdef IVAS_FLOAT_FIXED ivas_compute_spar_params_fx( pCov_real_fx, Q30, dm_fv_re_fx, &q_dm_fv_re_fx, i_ts, ppMixer_mat_fx, &q_ppMixer_mat, start_band, end_band, dtx_vad, num_ch, 1, active_w, active_w_vlbr, hSpar_md_cfg, hSpar_md, Wscale_fx, q_Wscale, 1, dyn_active_w_flag ); -// #else -// for (int i = 0; i < num_ch; i++) -// { -// for (int j = 0; j < num_ch; j++) -// { -// for (int k = start_band; k < end_band; k++) -// { -// cov_real_dirac[i][j][k] = (float)cov_real_dirac_fx[i][j][k] / (1 << 30); -// } -// } -// } - -// ivas_compute_spar_params( pCov_real, dm_fv_re, i_ts, ppMixer_mat, start_band, end_band, dtx_vad, num_ch, 1, active_w, active_w_vlbr, hSpar_md_cfg, hSpar_md, Wscale, 1, dyn_active_w_flag ); -// -//#endif // IVAS_FLOAT_FIXED + // #else + // for (int i = 0; i < num_ch; i++) + // { + // for (int j = 0; j < num_ch; j++) + // { + // for (int k = start_band; k < end_band; k++) + // { + // cov_real_dirac[i][j][k] = (float)cov_real_dirac_fx[i][j][k] / (1 << 30); + // } + // } + // } + + // ivas_compute_spar_params( pCov_real, dm_fv_re, i_ts, ppMixer_mat, start_band, end_band, dtx_vad, num_ch, 1, active_w, active_w_vlbr, hSpar_md_cfg, hSpar_md, Wscale, 1, dyn_active_w_flag ); + // + //#endif // IVAS_FLOAT_FIXED if ( mixer_mat_fx != NULL ) { @@ -3580,7 +3620,7 @@ void ivas_get_spar_md_from_dirac_fx( { for ( j = 0; j < num_ch; j++ ) { - mixer_mat_fx[0][j][band + i_ts * IVAS_MAX_NUM_BANDS] = Mpy_32_32(mixer_mat_fx[0][j][band + i_ts * IVAS_MAX_NUM_BANDS], Wscale_d[band]); + mixer_mat_fx[0][j][band + i_ts * IVAS_MAX_NUM_BANDS] = Mpy_32_32( mixer_mat_fx[0][j][band + i_ts * IVAS_MAX_NUM_BANDS], Wscale_d[band] ); } } } @@ -4051,7 +4091,7 @@ void ivas_dirac_dec_get_response_fixed( cos_az[2] = L_sub( Mpy_32_32( Mpy_32_32( ( 1 << Q30 ), cos_1 ), cos_az[1] ) << 4, cos_az[0] ); // Q29 sin_az[0] = sin_1 << 2; // Q29 sin_az[1] = Mpy_32_32( Mpy_32_32( sin_1, ( 1 << Q30 ) ), cos_1 ) << 6; // Q29 - sin_az[2] = Mpy_32_32( sin_1, L_sub( L_shl_sat(Mpy_32_32( ( 1 << Q30 ), cos_2 ), 5), ( 1 << 29 ) ) ) << 4; + sin_az[2] = Mpy_32_32( sin_1, L_sub( L_shl_sat( Mpy_32_32( ( 1 << Q30 ), cos_2 ), 5 ), ( 1 << 29 ) ) ) << 4; response[0] = ( 1 << 29 ); /* Un-optimized code - for reference */ @@ -6149,14 +6189,14 @@ void ivas_dirac_dec_get_response_fx( Word32 *response_fx, const Word16 ambisonics_order ) { - //float response[MAX_OUTPUT_CHANNELS]; + // float response[MAX_OUTPUT_CHANNELS]; int16_t index_azimuth, index_elevation; int16_t el, e, az; - //float cos_1, cos_2, sin_1, cos_az[3]; + // float cos_1, cos_2, sin_1, cos_az[3]; Word32 cos_1_fx, cos_2_fx, sin_1_fx, cos_az_fx[3]; - //float sin_az[3]; + // float sin_az[3]; Word32 sin_az_fx[3]; - //float f, c; + // float f, c; Word32 f_fx, c_fx; Word32 c_fx_better; int16_t l, m; @@ -6167,32 +6207,32 @@ void ivas_dirac_dec_get_response_fx( e = index_elevation > 90 ? -1 : 1; el = index_elevation > 90 ? 180 - index_elevation : index_elevation; az = index_azimuth > 180 ? 360 - index_azimuth : index_azimuth; - //f = index_azimuth > 180 ? -1.0f : 1.0f; + // f = index_azimuth > 180 ? -1.0f : 1.0f; f_fx = index_azimuth > 180 ? -1 : 1; - //cos_1 = dirac_gains_trg_term[az][0]; + // cos_1 = dirac_gains_trg_term[az][0]; cos_1_fx = dirac_gains_trg_term_fx[az][0]; - //cos_2 = cos_1 * cos_1; + // cos_2 = cos_1 * cos_1; cos_2_fx = Mpy_32_32( cos_1_fx, cos_1_fx ); - //sin_1 = f * dirac_gains_trg_term[az][1]; + // sin_1 = f * dirac_gains_trg_term[az][1]; sin_1_fx = dirac_gains_trg_term_fx[az][1]; if ( f_fx == -1 ) { sin_1_fx = L_negate( sin_1_fx ); } - //cos_az[0] = cos_1; + // cos_az[0] = cos_1; cos_az_fx[0] = cos_1_fx; - //cos_az[1] = 2.0f * cos_2 - 1.0f; + // cos_az[1] = 2.0f * cos_2 - 1.0f; cos_az_fx[1] = L_shl_sat( ( cos_2_fx - ONE_IN_Q30 ), 1 ); - //cos_az[2] = 2.0f * cos_1 * cos_az[1] - cos_az[0]; + // cos_az[2] = 2.0f * cos_1 * cos_az[1] - cos_az[0]; cos_az_fx[2] = L_shl_sat( ( Mpy_32_32( cos_1_fx, cos_az_fx[1] ) - L_shr( cos_az_fx[0], 1 ) ), 1 ); - //sin_az[0] = sin_1; + // sin_az[0] = sin_1; sin_az_fx[0] = sin_1_fx; - //sin_az[1] = sin_1 * 2.0f * cos_1; + // sin_az[1] = sin_1 * 2.0f * cos_1; sin_az_fx[1] = L_shl_sat( Mpy_32_32( sin_1_fx, cos_1_fx ), 1 ); - //sin_az[2] = sin_1 * ( 4.0f * cos_2 - 1.0f ); + // sin_az[2] = sin_1 * ( 4.0f * cos_2 - 1.0f ); sin_az_fx[2] = L_shl_sat( Mpy_32_32( sin_1_fx, ( cos_2_fx - ONE_IN_Q29 ) ), 2 ); - //response[0] = 1.0f; + // response[0] = 1.0f; response_fx[0] = ONE_IN_Q30; /* Un-optimized code - for reference */ /* for( l = 1; l<= ambisonics_order; l++ ) */ @@ -6236,15 +6276,15 @@ void ivas_dirac_dec_get_response_fx( { b = b_2 + m; a = dirac_gains_P_idx[b]; - //c = SQRT2 * dirac_gains_norm_term[a] * dirac_gains_Pnm[el][a]; + // c = SQRT2 * dirac_gains_norm_term[a] * dirac_gains_Pnm[el][a]; c_fx = Mpy_32_32( SQRT2_FIXED, Mpy_32_32( dirac_gains_norm_term_fx[a], dirac_gains_Pnm_int[el][a] ) ); c_fx_better = local_result_table[el][a]; - //response[b] = c * sin_az[l - m - 1]; + // response[b] = c * sin_az[l - m - 1]; response_fx[b] = Mpy_32_32( L_shl( c_fx, 3 ), sin_az_fx[l - m - 1] ); response_fx[b] = Mpy_32_32( c_fx_better, sin_az_fx[l - m - 1] ); b1 = b1_2 - m; - //response[b1] = c * cos_az[l - m - 1]; + // response[b1] = c * cos_az[l - m - 1]; response_fx[b1] = Mpy_32_32( L_shl( c_fx, 3 ), cos_az_fx[l - m - 1] ); response_fx[b1] = Mpy_32_32( c_fx_better, cos_az_fx[l - m - 1] ); } @@ -6253,7 +6293,7 @@ void ivas_dirac_dec_get_response_fx( { b = b_2 + m; a = dirac_gains_P_idx[b]; - //c = SQRT2 * dirac_gains_norm_term[a] * dirac_gains_Pnm[el][a]; + // c = SQRT2 * dirac_gains_norm_term[a] * dirac_gains_Pnm[el][a]; c_fx = Mpy_32_32( SQRT2_FIXED, Mpy_32_32( dirac_gains_norm_term_fx[a], dirac_gains_Pnm_int[el][a] ) ); c_fx_better = local_result_table[el][a]; if ( e == -1 ) @@ -6261,25 +6301,25 @@ void ivas_dirac_dec_get_response_fx( c_fx = L_negate( c_fx ); c_fx_better = L_negate( c_fx_better ); } - //c = c * e; + // c = c * e; - //response[b] = c * sin_az[l - m - 1]; + // response[b] = c * sin_az[l - m - 1]; response_fx[b] = Mpy_32_32( L_shl( c_fx, 3 ), sin_az_fx[l - m - 1] ); response_fx[b] = Mpy_32_32( c_fx_better, sin_az_fx[l - m - 1] ); b1 = b1_2 - m; - //response[b1] = c * cos_az[l - m - 1]; + // response[b1] = c * cos_az[l - m - 1]; response_fx[b1] = Mpy_32_32( L_shl( c_fx, 3 ), cos_az_fx[l - m - 1] ); response_fx[b1] = Mpy_32_32( c_fx_better, cos_az_fx[l - m - 1] ); } b = b_2 + l; a = dirac_gains_P_idx[b]; - //c = dirac_gains_norm_term[a] * dirac_gains_Pnm[el][a]; + // c = dirac_gains_norm_term[a] * dirac_gains_Pnm[el][a]; c_fx = Mpy_32_32( dirac_gains_norm_term_fx[a], dirac_gains_Pnm_int[el][a] ); c_fx_better = local_result_table_2[el][a]; if ( l % 2 == 1 ) { - //c = c * e; + // c = c * e; if ( e == -1 ) { c_fx = L_negate( c_fx ); @@ -6287,7 +6327,7 @@ void ivas_dirac_dec_get_response_fx( } } - //response[b] = c; + // response[b] = c; response_fx[b] = L_shl( c_fx, 2 ); response_fx[b] = c_fx_better; } @@ -6300,7 +6340,7 @@ void ivas_dirac_dec_get_response_fixed_Q( const Word16 elevation, Word32 *response, const Word16 ambisonics_order, - Word16 Q_out) + Word16 Q_out ) { Word16 index_azimuth, index_elevation; Word16 el, e, az; @@ -6310,25 +6350,25 @@ void ivas_dirac_dec_get_response_fixed_Q( Word16 l, m; Word16 b, b1, b_2, b1_2, a; - index_azimuth = (azimuth + 180) % 360; + index_azimuth = ( azimuth + 180 ) % 360; index_elevation = elevation + 90; e = index_elevation > 90 ? -1 : 1; el = index_elevation > 90 ? 180 - index_elevation : index_elevation; az = index_azimuth > 180 ? 360 - index_azimuth : index_azimuth; - f = index_azimuth > 180 ? -(1 << Q29) : (1 << Q29); - - cos_1 = dirac_gains_trg_term_int[az][0] >> 1; // Q29 - cos_2 = Mpy_32_32(cos_1, cos_1); // Q27 - sin_1 = Mpy_32_32(f, dirac_gains_trg_term_int[az][1] >> 1); // Q27 - cos_az[0] = cos_1; // Q29 - cos_az[1] = L_sub(Mpy_32_32((1 << Q30), cos_2), (1 << Q25)) << 4; // Q29 - cos_az[2] = L_sub(Mpy_32_32(Mpy_32_32((1 << Q30), cos_1), cos_az[1]) << 4, cos_az[0]); // Q29 - sin_az[0] = sin_1 << 2; // Q29 - sin_az[1] = Mpy_32_32(Mpy_32_32(sin_1, (1 << Q30)), cos_1) << 6; // Q29 - sin_az[2] = Mpy_32_32(sin_1, L_sub(L_shl_sat(Mpy_32_32((1 << Q30), cos_2), 5), (1 << 29))) << 4; - - response[0] = L_shl(1, Q_out); + f = index_azimuth > 180 ? -( 1 << Q29 ) : ( 1 << Q29 ); + + cos_1 = dirac_gains_trg_term_int[az][0] >> 1; // Q29 + cos_2 = Mpy_32_32( cos_1, cos_1 ); // Q27 + sin_1 = Mpy_32_32( f, dirac_gains_trg_term_int[az][1] >> 1 ); // Q27 + cos_az[0] = cos_1; // Q29 + cos_az[1] = L_sub( Mpy_32_32( ( 1 << Q30 ), cos_2 ), ( 1 << Q25 ) ) << 4; // Q29 + cos_az[2] = L_sub( Mpy_32_32( Mpy_32_32( ( 1 << Q30 ), cos_1 ), cos_az[1] ) << 4, cos_az[0] ); // Q29 + sin_az[0] = sin_1 << 2; // Q29 + sin_az[1] = Mpy_32_32( Mpy_32_32( sin_1, ( 1 << Q30 ) ), cos_1 ) << 6; // Q29 + sin_az[2] = Mpy_32_32( sin_1, L_sub( L_shl_sat( Mpy_32_32( ( 1 << Q30 ), cos_2 ), 5 ), ( 1 << 29 ) ) ) << 4; + + response[0] = L_shl( 1, Q_out ); /* Un-optimized code - for reference */ /* for( l = 1; l<= ambisonics_order; l++ ) */ /* { */ @@ -6363,50 +6403,50 @@ void ivas_dirac_dec_get_response_fixed_Q( /* response[b] = c; */ /* } */ - FOR(l = 1; l <= ambisonics_order; l++) + FOR( l = 1; l <= ambisonics_order; l++ ) { b_2 = l * l; b1_2 = l * l + 2 * l; - FOR(m = 0; m < l; m += 2) + FOR( m = 0; m < l; m += 2 ) { b = b_2 + m; a = dirac_gains_P_idx[b]; - c = Mpy_32_32(Mpy_32_32(SQRT2_FIXED, dirac_gains_norm_term_int[a]), dirac_gains_Pnm_int[el][a]); // Q25 + c = Mpy_32_32( Mpy_32_32( SQRT2_FIXED, dirac_gains_norm_term_int[a] ), dirac_gains_Pnm_int[el][a] ); // Q25 - response[b] = L_shl(Mpy_32_32(c, sin_az[l - m - 1]), Q_out - Q23); // Q_out + response[b] = L_shl( Mpy_32_32( c, sin_az[l - m - 1] ), Q_out - Q23 ); // Q_out b1 = b1_2 - m; - response[b1] = L_shl(Mpy_32_32(c, cos_az[l - m - 1]), Q_out - Q23); // Q_out + response[b1] = L_shl( Mpy_32_32( c, cos_az[l - m - 1] ), Q_out - Q23 ); // Q_out } - FOR(m = 1; m < l; m += 2) + FOR( m = 1; m < l; m += 2 ) { b = b_2 + m; a = dirac_gains_P_idx[b]; - c = Mpy_32_32(Mpy_32_32(SQRT2_FIXED, dirac_gains_norm_term_int[a]), dirac_gains_Pnm_int[el][a]); // Q25 - IF(e == -1) + c = Mpy_32_32( Mpy_32_32( SQRT2_FIXED, dirac_gains_norm_term_int[a] ), dirac_gains_Pnm_int[el][a] ); // Q25 + IF( e == -1 ) { c = -c; } - response[b] = L_shl(Mpy_32_32(c, sin_az[l - m - 1]), Q_out - Q23); // Q29 + response[b] = L_shl( Mpy_32_32( c, sin_az[l - m - 1] ), Q_out - Q23 ); // Q29 b1 = b1_2 - m; - response[b1] = L_shl(Mpy_32_32(c, cos_az[l - m - 1]), Q_out - Q23); // Q29 + response[b1] = L_shl( Mpy_32_32( c, cos_az[l - m - 1] ), Q_out - Q23 ); // Q29 } b = b_2 + l; a = dirac_gains_P_idx[b]; - c = Mpy_32_32(dirac_gains_norm_term_int[a], dirac_gains_Pnm_int[el][a]); //Q26 - IF(l % 2 == 1) + c = Mpy_32_32( dirac_gains_norm_term_int[a], dirac_gains_Pnm_int[el][a] ); // Q26 + IF( l % 2 == 1 ) { - IF(e == -1) + IF( e == -1 ) { c = -c; } } - response[b] = L_shl(c, Q_out - Q26); // Q29 + response[b] = L_shl( c, Q_out - Q26 ); // Q29 } return; @@ -6607,173 +6647,172 @@ void ivas_spar_set_bitrate_config( } #ifdef IVAS_FLOAT_FIXED -static Word32 ceil32_fx(Word32 var1, Word16 q) +static Word32 ceil32_fx( Word32 var1, Word16 q ) { - Word32 ans, temp; - ans = L_shr(var1, q); - temp = L_shl(ans, q); - IF(GT_32(ans, temp)) + Word32 ans, temp; + ans = L_shr( var1, q ); + temp = L_shl( ans, q ); + IF( GT_32( ans, temp ) ) return ans; - ELSE - return L_add(ans, 1); + ELSE return L_add( ans, 1 ); } void ivas_spar_set_bitrate_config_fx( - ivas_spar_md_com_cfg *pSpar_md_cfg, /* i/o: SPAR MD config. handle */ - const Word16 table_idx, /* i : config. table index */ - const Word16 num_bands, /* i : number of bands */ - const Word16 dirac2spar_md_flag, - const Word16 enc_flag, - const Word16 pca_flag, - const Word16 agc_flag) + ivas_spar_md_com_cfg *pSpar_md_cfg, /* i/o: SPAR MD config. handle */ + const Word16 table_idx, /* i : config. table index */ + const Word16 num_bands, /* i : number of bands */ + const Word16 dirac2spar_md_flag, + const Word16 enc_flag, + const Word16 pca_flag, + const Word16 agc_flag ) { - Word32 ivas_total_brate; - Word16 i, total_bits, max_bits, code, length; - Word16 sba_order; - Word16 md_coding_bits_header; - Word16 agc_bits, pca_bits, num_PR_bits_dirac_bands; - Word16 bits_PR, bits_C, bits_P; - Word16 wc_coarse_strat; - Word16 n_input, n_dmx, n_dec; - Word16 quant_strat; - Word16 bands_bw; - - pSpar_md_cfg->nchan_transport = ivas_spar_br_table_consts[table_idx].nchan_transport; - - FOR (i = 0; i < pSpar_md_cfg->nchan_transport; i++) - { - pSpar_md_cfg->max_freq_per_chan[i] = ivas_spar_br_table_consts[table_idx].fpcs; - } - - pSpar_md_cfg->active_w = ivas_spar_br_table_consts[table_idx].active_w; - pSpar_md_cfg->agc_bits_ch_idx = ivas_spar_br_table_consts[table_idx].agc_bits_ch_idx; + Word32 ivas_total_brate; + Word16 i, total_bits, max_bits, code, length; + Word16 sba_order; + Word16 md_coding_bits_header; + Word16 agc_bits, pca_bits, num_PR_bits_dirac_bands; + Word16 bits_PR, bits_C, bits_P; + Word16 wc_coarse_strat; + Word16 n_input, n_dmx, n_dec; + Word16 quant_strat; + Word16 bands_bw; + + pSpar_md_cfg->nchan_transport = ivas_spar_br_table_consts[table_idx].nchan_transport; + + FOR( i = 0; i < pSpar_md_cfg->nchan_transport; i++ ) + { + pSpar_md_cfg->max_freq_per_chan[i] = ivas_spar_br_table_consts[table_idx].fpcs; + } + + pSpar_md_cfg->active_w = ivas_spar_br_table_consts[table_idx].active_w; + pSpar_md_cfg->agc_bits_ch_idx = ivas_spar_br_table_consts[table_idx].agc_bits_ch_idx; #ifdef IVAS_FLOAT_FIXED ivas_spar_get_uniform_quant_strat_fx( pSpar_md_cfg, table_idx ); #else ivas_spar_get_uniform_quant_strat( pSpar_md_cfg, table_idx ); #endif - pSpar_md_cfg->quant_strat_bits = ivas_get_bits_to_encode(MAX_QUANT_STRATS); - - /* BLOCK: getEntropyCoderModels */ - - pSpar_md_cfg->remix_unmix_order = ivas_spar_br_table_consts[table_idx].dmx_str; - - /* bits per block*/ - total_bits = 0; - max_bits = 0; - - ivas_total_brate = ivas_spar_br_table_consts[table_idx].ivas_total_brate; - sba_order = ivas_spar_br_table_consts[table_idx].sba_order; - ivas_get_spar_table_idx_fx(ivas_total_brate, sba_order, ivas_spar_br_table_consts[table_idx].bwidth, &length, &code); - Word16 temp; - Word16 div1; - FOR (i = 0; i < pSpar_md_cfg->nchan_transport; i++) - { - div1 = BASOP_Util_Divide3232_Scale(ivas_spar_br_table_consts[table_idx].core_brs[i][0], FRAMES_PER_SEC, &temp); - total_bits = add(total_bits, shr(div1, sub(15, temp))); - div1 = BASOP_Util_Divide3232_Scale(ivas_spar_br_table_consts[table_idx].core_brs[i][1], FRAMES_PER_SEC, &temp); - max_bits = add(max_bits, shr(div1, sub(15, temp))); - } + pSpar_md_cfg->quant_strat_bits = ivas_get_bits_to_encode( MAX_QUANT_STRATS ); + /* BLOCK: getEntropyCoderModels */ - div1 = BASOP_Util_Divide3232_Scale(ivas_total_brate, FRAMES_PER_SEC, &temp); - pSpar_md_cfg->tgt_bits_per_blk = sub(shr(div1, sub(15, temp)), add(add(add(add(add(IVAS_FORMAT_SIGNALING_NBITS_EXTENDED, SBA_PLANAR_BITS), 0), SBA_ORDER_BITS), length), total_bits)); - pSpar_md_cfg->max_bits_per_blk = sub(shr(div1, sub(15, temp)), add(add(add(add(add(IVAS_FORMAT_SIGNALING_NBITS_EXTENDED, SBA_PLANAR_BITS), 0), SBA_ORDER_BITS), length), max_bits)); + pSpar_md_cfg->remix_unmix_order = ivas_spar_br_table_consts[table_idx].dmx_str; - md_coding_bits_header = add(SPAR_NUM_CODING_STRAT_BITS, pSpar_md_cfg->quant_strat_bits); + /* bits per block*/ + total_bits = 0; + max_bits = 0; - pSpar_md_cfg->tgt_bits_per_blk = sub(pSpar_md_cfg->tgt_bits_per_blk, md_coding_bits_header); - pSpar_md_cfg->max_bits_per_blk = sub(pSpar_md_cfg->max_bits_per_blk, md_coding_bits_header); + ivas_total_brate = ivas_spar_br_table_consts[table_idx].ivas_total_brate; + sba_order = ivas_spar_br_table_consts[table_idx].sba_order; + ivas_get_spar_table_idx_fx( ivas_total_brate, sba_order, ivas_spar_br_table_consts[table_idx].bwidth, &length, &code ); + Word16 temp; + Word16 div1; + FOR( i = 0; i < pSpar_md_cfg->nchan_transport; i++ ) + { + div1 = BASOP_Util_Divide3232_Scale( ivas_spar_br_table_consts[table_idx].core_brs[i][0], FRAMES_PER_SEC, &temp ); + total_bits = add( total_bits, shr( div1, sub( 15, temp ) ) ); + div1 = BASOP_Util_Divide3232_Scale( ivas_spar_br_table_consts[table_idx].core_brs[i][1], FRAMES_PER_SEC, &temp ); + max_bits = add( max_bits, shr( div1, sub( 15, temp ) ) ); + } - IF (LT_32(ivas_total_brate, IVAS_24k4)) - { - bands_bw = 2; - } - ELSE - { - bands_bw = 1; - } - div1 = BASOP_Util_Divide3232_Scale(i_mult(pSpar_md_cfg->tgt_bits_per_blk, num_bands), IVAS_MAX_NUM_BANDS, &temp); - pSpar_md_cfg->tgt_bits_per_blk = (Word16)ceil32_fx(div1, 15 - temp); + div1 = BASOP_Util_Divide3232_Scale( ivas_total_brate, FRAMES_PER_SEC, &temp ); + pSpar_md_cfg->tgt_bits_per_blk = sub( shr( div1, sub( 15, temp ) ), add( add( add( add( add( IVAS_FORMAT_SIGNALING_NBITS_EXTENDED, SBA_PLANAR_BITS ), 0 ), SBA_ORDER_BITS ), length ), total_bits ) ); + pSpar_md_cfg->max_bits_per_blk = sub( shr( div1, sub( 15, temp ) ), add( add( add( add( add( IVAS_FORMAT_SIGNALING_NBITS_EXTENDED, SBA_PLANAR_BITS ), 0 ), SBA_ORDER_BITS ), length ), max_bits ) ); - div1 = BASOP_Util_Divide3232_Scale(i_mult(pSpar_md_cfg->max_bits_per_blk, num_bands), IVAS_MAX_NUM_BANDS, &temp); - pSpar_md_cfg->max_bits_per_blk = (Word16)ceil32_fx(div1, 15 - temp); + md_coding_bits_header = add( SPAR_NUM_CODING_STRAT_BITS, pSpar_md_cfg->quant_strat_bits ); - pSpar_md_cfg->tgt_bits_per_blk = add(pSpar_md_cfg->tgt_bits_per_blk, md_coding_bits_header); - pSpar_md_cfg->max_bits_per_blk = add(pSpar_md_cfg->max_bits_per_blk, md_coding_bits_header); + pSpar_md_cfg->tgt_bits_per_blk = sub( pSpar_md_cfg->tgt_bits_per_blk, md_coding_bits_header ); + pSpar_md_cfg->max_bits_per_blk = sub( pSpar_md_cfg->max_bits_per_blk, md_coding_bits_header ); - IF (enc_flag) - { - /*calculate the actual worst case bits*/ - IF (GE_32(ivas_total_brate, BRATE_SPAR_Q_STRAT)) + IF( LT_32( ivas_total_brate, IVAS_24k4 ) ) { - quant_strat = QUANT_STRAT_0; + bands_bw = 2; } ELSE { - quant_strat = QUANT_STRAT_2; + bands_bw = 1; } - num_PR_bits_dirac_bands = (EQ_16(dirac2spar_md_flag, 1)) ? sub(num_bands, SPAR_DIRAC_SPLIT_START_BAND) : 0; - div1 = BASOP_Util_Divide3232_Scale(num_PR_bits_dirac_bands, bands_bw, &temp); - num_PR_bits_dirac_bands = shr(div1, sub(15, temp)); - num_PR_bits_dirac_bands = s_max(0, num_PR_bits_dirac_bands); - num_PR_bits_dirac_bands = i_mult(num_PR_bits_dirac_bands, DIRAC_TO_SPAR_HBR_PRED_CHS); - - n_input = ivas_sba_get_nchan_metadata(sba_order, ivas_total_brate); - n_dmx = ivas_spar_br_table_consts[table_idx].nchan_transport; - n_dec = sub(n_input, n_dmx); - bits_PR = ivas_spar_br_table_consts_fx[table_idx].q_lvls[quant_strat][0]; - num_PR_bits_dirac_bands = i_mult(num_PR_bits_dirac_bands, bits_PR); - bits_PR = i_mult(bits_PR, sub(n_input, 1)); - bits_C = i_mult(ivas_spar_br_table_consts_fx[table_idx].q_lvls[quant_strat][1], i_mult( sub(n_dmx, 1), n_dec)); - bits_P = i_mult(ivas_spar_br_table_consts_fx[table_idx].q_lvls[quant_strat][2], n_dec); - - wc_coarse_strat = add(add(bits_PR, bits_C), bits_P); - wc_coarse_strat = i_mult(wc_coarse_strat, num_bands); - div1 = BASOP_Util_Divide3232_Scale(wc_coarse_strat, bands_bw, &temp); - wc_coarse_strat = shr(div1, sub(15, temp)); - wc_coarse_strat = sub(wc_coarse_strat, num_PR_bits_dirac_bands); - wc_coarse_strat = add(wc_coarse_strat, md_coding_bits_header); - - IF (LT_16(pSpar_md_cfg->max_bits_per_blk, wc_coarse_strat)) - { - assert(0); - } + div1 = BASOP_Util_Divide3232_Scale( i_mult( pSpar_md_cfg->tgt_bits_per_blk, num_bands ), IVAS_MAX_NUM_BANDS, &temp ); + pSpar_md_cfg->tgt_bits_per_blk = (Word16) ceil32_fx( div1, 15 - temp ); - IF (agc_flag) - { - IF (EQ_16(pSpar_md_cfg->nchan_transport, 1)) - { - agc_bits = AGC_BITS_PER_CH; - } - ELSE - { - agc_bits = add(i_mult(AGC_BITS_PER_CH, pSpar_md_cfg->nchan_transport), AGC_SIGNALLING_BITS); - } - } - ELSE - { - agc_bits = AGC_SIGNALLING_BITS; - } + div1 = BASOP_Util_Divide3232_Scale( i_mult( pSpar_md_cfg->max_bits_per_blk, num_bands ), IVAS_MAX_NUM_BANDS, &temp ); + pSpar_md_cfg->max_bits_per_blk = (Word16) ceil32_fx( div1, 15 - temp ); - IF (EQ_32(ivas_total_brate, PCA_BRATE) && EQ_32(sba_order, SBA_FOA_ORDER)) - { - pca_bits = 1; - IF (pca_flag) - { - pca_bits = add(pca_bits, sub(add(IVAS_PCA_QBITS, IVAS_PCA_QBITS), 1)); - } - } - ELSE + pSpar_md_cfg->tgt_bits_per_blk = add( pSpar_md_cfg->tgt_bits_per_blk, md_coding_bits_header ); + pSpar_md_cfg->max_bits_per_blk = add( pSpar_md_cfg->max_bits_per_blk, md_coding_bits_header ); + + IF( enc_flag ) { - pca_bits = 0; - } + /*calculate the actual worst case bits*/ + IF( GE_32( ivas_total_brate, BRATE_SPAR_Q_STRAT ) ) + { + quant_strat = QUANT_STRAT_0; + } + ELSE + { + quant_strat = QUANT_STRAT_2; + } + + num_PR_bits_dirac_bands = ( EQ_16( dirac2spar_md_flag, 1 ) ) ? sub( num_bands, SPAR_DIRAC_SPLIT_START_BAND ) : 0; + div1 = BASOP_Util_Divide3232_Scale( num_PR_bits_dirac_bands, bands_bw, &temp ); + num_PR_bits_dirac_bands = shr( div1, sub( 15, temp ) ); + num_PR_bits_dirac_bands = s_max( 0, num_PR_bits_dirac_bands ); + num_PR_bits_dirac_bands = i_mult( num_PR_bits_dirac_bands, DIRAC_TO_SPAR_HBR_PRED_CHS ); + + n_input = ivas_sba_get_nchan_metadata( sba_order, ivas_total_brate ); + n_dmx = ivas_spar_br_table_consts[table_idx].nchan_transport; + n_dec = sub( n_input, n_dmx ); + bits_PR = ivas_spar_br_table_consts_fx[table_idx].q_lvls[quant_strat][0]; + num_PR_bits_dirac_bands = i_mult( num_PR_bits_dirac_bands, bits_PR ); + bits_PR = i_mult( bits_PR, sub( n_input, 1 ) ); + bits_C = i_mult( ivas_spar_br_table_consts_fx[table_idx].q_lvls[quant_strat][1], i_mult( sub( n_dmx, 1 ), n_dec ) ); + bits_P = i_mult( ivas_spar_br_table_consts_fx[table_idx].q_lvls[quant_strat][2], n_dec ); + + wc_coarse_strat = add( add( bits_PR, bits_C ), bits_P ); + wc_coarse_strat = i_mult( wc_coarse_strat, num_bands ); + div1 = BASOP_Util_Divide3232_Scale( wc_coarse_strat, bands_bw, &temp ); + wc_coarse_strat = shr( div1, sub( 15, temp ) ); + wc_coarse_strat = sub( wc_coarse_strat, num_PR_bits_dirac_bands ); + wc_coarse_strat = add( wc_coarse_strat, md_coding_bits_header ); + + IF( LT_16( pSpar_md_cfg->max_bits_per_blk, wc_coarse_strat ) ) + { + assert( 0 ); + } + + IF( agc_flag ) + { + IF( EQ_16( pSpar_md_cfg->nchan_transport, 1 ) ) + { + agc_bits = AGC_BITS_PER_CH; + } + ELSE + { + agc_bits = add( i_mult( AGC_BITS_PER_CH, pSpar_md_cfg->nchan_transport ), AGC_SIGNALLING_BITS ); + } + } + ELSE + { + agc_bits = AGC_SIGNALLING_BITS; + } - pSpar_md_cfg->max_md_bits_spar = add(add(pSpar_md_cfg->max_bits_per_blk, agc_bits), pca_bits); - } + IF( EQ_32( ivas_total_brate, PCA_BRATE ) && EQ_32( sba_order, SBA_FOA_ORDER ) ) + { + pca_bits = 1; + IF( pca_flag ) + { + pca_bits = add( pca_bits, sub( add( IVAS_PCA_QBITS, IVAS_PCA_QBITS ), 1 ) ); + } + } + ELSE + { + pca_bits = 0; + } - return; + pSpar_md_cfg->max_md_bits_spar = add( add( pSpar_md_cfg->max_bits_per_blk, agc_bits ), pca_bits ); + } + + return; } #endif /*-----------------------------------------------------------------------------------------* diff --git a/lib_com/ivas_spar_com_quant_util.c b/lib_com/ivas_spar_com_quant_util.c index 79e55940a..859f1ee24 100644 --- a/lib_com/ivas_spar_com_quant_util.c +++ b/lib_com/ivas_spar_com_quant_util.c @@ -108,20 +108,20 @@ void ivas_quantise_real_values_fx( index[i] = 0; } } - else if ( q_levels && max_value_fx != min_value_fx) + else if ( q_levels && max_value_fx != min_value_fx ) { - Word16 nor_q_level = norm_l(q_levels - 1); - Word32 one_by_q_levels = divide3232(L_shl(1, (nor_q_level)), L_shl((q_levels - 1), (nor_q_level))); - one_by_q_levels = L_shl(one_by_q_levels, 16); - q_step_fx = Mpy_32_32((max_value_fx - min_value_fx), one_by_q_levels); - Word32 one_by_max_min = divide3232(ONE_IN_Q28,L_sub(max_value_fx, min_value_fx)); - one_by_q_step_fx = (q_levels - 1)*one_by_max_min; + Word16 nor_q_level = norm_l( q_levels - 1 ); + Word32 one_by_q_levels = divide3232( L_shl( 1, ( nor_q_level ) ), L_shl( ( q_levels - 1 ), ( nor_q_level ) ) ); + one_by_q_levels = L_shl( one_by_q_levels, 16 ); + q_step_fx = Mpy_32_32( ( max_value_fx - min_value_fx ), one_by_q_levels ); + Word32 one_by_max_min = divide3232( ONE_IN_Q28, L_sub( max_value_fx, min_value_fx ) ); + one_by_q_step_fx = ( q_levels - 1 ) * one_by_max_min; Word32 val_fx; for ( i = 0; i < dim; i++ ) { val_fx = max( min_value_fx, min( values_fx[i], max_value_fx ) ); - index[i] = (int16_t)L_shr(Mpy_32_32(one_by_q_step_fx, val_fx),12); - quant_fx[i] = index[i] * q_step_fx; + index[i] = (int16_t) L_shr( Mpy_32_32( one_by_q_step_fx, val_fx ), 12 ); + quant_fx[i] = index[i] * q_step_fx; } } else @@ -163,25 +163,24 @@ void ivas_spar_get_uniform_quant_strat( pSpar_md_com_cfg->quant_strat[i].PR.q_levels[1] = PQ_q_lvl; pSpar_md_com_cfg->quant_strat[i].PR.min = -1.2f; pSpar_md_com_cfg->quant_strat[i].PR.max = 1.2f; - + pSpar_md_com_cfg->quant_strat[i].C.q_levels[0] = C_q_lvl; pSpar_md_com_cfg->quant_strat[i].C.q_levels[1] = C_q_lvl; pSpar_md_com_cfg->quant_strat[i].C.min = -0.8f; pSpar_md_com_cfg->quant_strat[i].C.max = 0.8f; - + pSpar_md_com_cfg->quant_strat[i].P_r.q_levels[0] = Pr_q_lvl; pSpar_md_com_cfg->quant_strat[i].P_r.q_levels[1] = Pr_q_lvl; pSpar_md_com_cfg->quant_strat[i].P_r.min = 0; pSpar_md_com_cfg->quant_strat[i].P_r.max = 0.8f; - + pSpar_md_com_cfg->quant_strat[i].P_c.q_levels[0] = Pc_q_lvl; pSpar_md_com_cfg->quant_strat[i].P_c.q_levels[1] = Pc_q_lvl; pSpar_md_com_cfg->quant_strat[i].P_c.min = -0.8f; pSpar_md_com_cfg->quant_strat[i].P_c.max = 0.8f; - } else { @@ -189,25 +188,24 @@ void ivas_spar_get_uniform_quant_strat( pSpar_md_com_cfg->quant_strat[i].PR.q_levels[1] = PQ_q_lvl; pSpar_md_com_cfg->quant_strat[i].PR.max = 1; pSpar_md_com_cfg->quant_strat[i].PR.min = -1; - + pSpar_md_com_cfg->quant_strat[i].C.q_levels[0] = C_q_lvl; pSpar_md_com_cfg->quant_strat[i].C.q_levels[1] = C_q_lvl; pSpar_md_com_cfg->quant_strat[i].C.max = 2; pSpar_md_com_cfg->quant_strat[i].C.min = -2; - + pSpar_md_com_cfg->quant_strat[i].P_r.q_levels[0] = Pr_q_lvl; pSpar_md_com_cfg->quant_strat[i].P_r.q_levels[1] = Pr_q_lvl; pSpar_md_com_cfg->quant_strat[i].P_r.max = 1.0f; pSpar_md_com_cfg->quant_strat[i].P_r.min = 0; - + pSpar_md_com_cfg->quant_strat[i].P_c.q_levels[0] = Pc_q_lvl; pSpar_md_com_cfg->quant_strat[i].P_c.q_levels[1] = Pc_q_lvl; pSpar_md_com_cfg->quant_strat[i].P_c.max = 0.5; pSpar_md_com_cfg->quant_strat[i].P_c.min = -0.5; - } } @@ -345,34 +343,34 @@ void ivas_map_prior_coeffs_quant( { ivas_quant_strat_t qs = pSpar_md_cfg->quant_strat[qsi]; ivas_quant_strat_t prev_qs = pSpar_md_cfg->quant_strat[pSpar_md_cfg->prev_quant_idx]; - //float one_by_q_lvl_PR = 1.0f / max( prev_qs.PR.q_levels[0] - 1, 1 ); - Word32 one_by_q_lvl_PR_fx = one_by_q_level[max(prev_qs.PR.q_levels[0] - 1, 1) ]; - //float one_by_q_lvl_C = 1.0f / max( prev_qs.C.q_levels[0] - 1, 1 ); - Word32 one_by_q_lvl_C_fx = one_by_q_level[max(prev_qs.C.q_levels[0] - 1, 1) ]; - //float one_by_q_lvl_P_r = 1.0f / max( prev_qs.P_r.q_levels[0] - 1, 1 ); - Word32 one_by_q_lvl_P_r_fx = one_by_q_level[max(prev_qs.P_r.q_levels[0] - 1, 1) ]; + // float one_by_q_lvl_PR = 1.0f / max( prev_qs.PR.q_levels[0] - 1, 1 ); + Word32 one_by_q_lvl_PR_fx = one_by_q_level[max( prev_qs.PR.q_levels[0] - 1, 1 )]; + // float one_by_q_lvl_C = 1.0f / max( prev_qs.C.q_levels[0] - 1, 1 ); + Word32 one_by_q_lvl_C_fx = one_by_q_level[max( prev_qs.C.q_levels[0] - 1, 1 )]; + // float one_by_q_lvl_P_r = 1.0f / max( prev_qs.P_r.q_levels[0] - 1, 1 ); + Word32 one_by_q_lvl_P_r_fx = one_by_q_level[max( prev_qs.P_r.q_levels[0] - 1, 1 )]; for ( i = 0; i < nB; i++ ) { for ( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) { - Word32 trial1 = (qs.PR.q_levels[0] - 1) * pSpar_md_prior->band_coeffs_idx[i].pred_index_re[j]; + Word32 trial1 = ( qs.PR.q_levels[0] - 1 ) * pSpar_md_prior->band_coeffs_idx[i].pred_index_re[j]; trial1 = trial1 << 16; - trial1 = round_fx(Mpy_32_32(trial1, one_by_q_lvl_PR_fx)); - //pSpar_md_prior->band_coeffs_idx_mapped[i].pred_index_re[j] = (int16_t) round( ( qs.PR.q_levels[0] - 1 ) * pSpar_md_prior->band_coeffs_idx[i].pred_index_re[j] * one_by_q_lvl_PR ); - pSpar_md_prior->band_coeffs_idx_mapped[i].pred_index_re[j] = extract_l(trial1); - Word32 trial2 = (qs.P_r.q_levels[0] - 1) * pSpar_md_prior->band_coeffs_idx[i].decd_index_re[j]; + trial1 = round_fx( Mpy_32_32( trial1, one_by_q_lvl_PR_fx ) ); + // pSpar_md_prior->band_coeffs_idx_mapped[i].pred_index_re[j] = (int16_t) round( ( qs.PR.q_levels[0] - 1 ) * pSpar_md_prior->band_coeffs_idx[i].pred_index_re[j] * one_by_q_lvl_PR ); + pSpar_md_prior->band_coeffs_idx_mapped[i].pred_index_re[j] = extract_l( trial1 ); + Word32 trial2 = ( qs.P_r.q_levels[0] - 1 ) * pSpar_md_prior->band_coeffs_idx[i].decd_index_re[j]; trial2 = trial2 << 16; - trial2 = round_fx(Mpy_32_32(trial2, one_by_q_lvl_P_r_fx)); - //pSpar_md_prior->band_coeffs_idx_mapped[i].decd_index_re[j] = (int16_t) round( ( qs.P_r.q_levels[0] - 1 ) * pSpar_md_prior->band_coeffs_idx[i].decd_index_re[j] * one_by_q_lvl_P_r ); - pSpar_md_prior->band_coeffs_idx_mapped[i].decd_index_re[j] = extract_l(trial2); + trial2 = round_fx( Mpy_32_32( trial2, one_by_q_lvl_P_r_fx ) ); + // pSpar_md_prior->band_coeffs_idx_mapped[i].decd_index_re[j] = (int16_t) round( ( qs.P_r.q_levels[0] - 1 ) * pSpar_md_prior->band_coeffs_idx[i].decd_index_re[j] * one_by_q_lvl_P_r ); + pSpar_md_prior->band_coeffs_idx_mapped[i].decd_index_re[j] = extract_l( trial2 ); } for ( j = 0; j < IVAS_SPAR_MAX_C_COEFF; j++ ) { - Word32 trial1 = (qs.C.q_levels[0] - 1) * pSpar_md_prior->band_coeffs_idx[i].drct_index_re[j]; + Word32 trial1 = ( qs.C.q_levels[0] - 1 ) * pSpar_md_prior->band_coeffs_idx[i].drct_index_re[j]; trial1 = trial1 << 16; - trial1 = round_fx(Mpy_32_32(trial1, one_by_q_lvl_C_fx)); - //pSpar_md_prior->band_coeffs_idx_mapped[i].drct_index_re[j] = (int16_t) round( ( qs.C.q_levels[0] - 1 ) * pSpar_md_prior->band_coeffs_idx[i].drct_index_re[j] * one_by_q_lvl_C ); - pSpar_md_prior->band_coeffs_idx_mapped[i].drct_index_re[j] = extract_l(trial1); + trial1 = round_fx( Mpy_32_32( trial1, one_by_q_lvl_C_fx ) ); + // pSpar_md_prior->band_coeffs_idx_mapped[i].drct_index_re[j] = (int16_t) round( ( qs.C.q_levels[0] - 1 ) * pSpar_md_prior->band_coeffs_idx[i].drct_index_re[j] * one_by_q_lvl_C ); + pSpar_md_prior->band_coeffs_idx_mapped[i].drct_index_re[j] = extract_l( trial1 ); } } } @@ -399,40 +397,40 @@ void ivas_map_prior_coeffs_quant( ivas_spar_md_prev_t *pSpar_md_prior, ivas_spar_md_com_cfg *pSpar_md_cfg, const int16_t qsi, - const int16_t nB) + const int16_t nB ) { int16_t i, j; - if (qsi != pSpar_md_cfg->prev_quant_idx) + if ( qsi != pSpar_md_cfg->prev_quant_idx ) { ivas_quant_strat_t qs = pSpar_md_cfg->quant_strat[qsi]; ivas_quant_strat_t prev_qs = pSpar_md_cfg->quant_strat[pSpar_md_cfg->prev_quant_idx]; - float one_by_q_lvl_PR = 1.0f / max(prev_qs.PR.q_levels[0] - 1, 1); - float one_by_q_lvl_C = 1.0f / max(prev_qs.C.q_levels[0] - 1, 1); - float one_by_q_lvl_P_r = 1.0f / max(prev_qs.P_r.q_levels[0] - 1, 1); - for (i = 0; i < nB; i++) + float one_by_q_lvl_PR = 1.0f / max( prev_qs.PR.q_levels[0] - 1, 1 ); + float one_by_q_lvl_C = 1.0f / max( prev_qs.C.q_levels[0] - 1, 1 ); + float one_by_q_lvl_P_r = 1.0f / max( prev_qs.P_r.q_levels[0] - 1, 1 ); + for ( i = 0; i < nB; i++ ) { - for (j = 0; j < IVAS_SPAR_MAX_CH - 1; j++) + for ( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) { - pSpar_md_prior->band_coeffs_idx_mapped[i].pred_index_re[j] = (int16_t)round((qs.PR.q_levels[0] - 1) * pSpar_md_prior->band_coeffs_idx[i].pred_index_re[j] * one_by_q_lvl_PR); - pSpar_md_prior->band_coeffs_idx_mapped[i].decd_index_re[j] = (int16_t)round((qs.P_r.q_levels[0] - 1) * pSpar_md_prior->band_coeffs_idx[i].decd_index_re[j] * one_by_q_lvl_P_r); + pSpar_md_prior->band_coeffs_idx_mapped[i].pred_index_re[j] = (int16_t) round( ( qs.PR.q_levels[0] - 1 ) * pSpar_md_prior->band_coeffs_idx[i].pred_index_re[j] * one_by_q_lvl_PR ); + pSpar_md_prior->band_coeffs_idx_mapped[i].decd_index_re[j] = (int16_t) round( ( qs.P_r.q_levels[0] - 1 ) * pSpar_md_prior->band_coeffs_idx[i].decd_index_re[j] * one_by_q_lvl_P_r ); } - for (j = 0; j < IVAS_SPAR_MAX_C_COEFF; j++) + for ( j = 0; j < IVAS_SPAR_MAX_C_COEFF; j++ ) { - pSpar_md_prior->band_coeffs_idx_mapped[i].drct_index_re[j] = (int16_t)round((qs.C.q_levels[0] - 1) * pSpar_md_prior->band_coeffs_idx[i].drct_index_re[j] * one_by_q_lvl_C); + pSpar_md_prior->band_coeffs_idx_mapped[i].drct_index_re[j] = (int16_t) round( ( qs.C.q_levels[0] - 1 ) * pSpar_md_prior->band_coeffs_idx[i].drct_index_re[j] * one_by_q_lvl_C ); } } } else { - for (i = 0; i < nB; i++) + for ( i = 0; i < nB; i++ ) { - for (j = 0; j < IVAS_SPAR_MAX_CH - 1; j++) + for ( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) { pSpar_md_prior->band_coeffs_idx_mapped[i].pred_index_re[j] = pSpar_md_prior->band_coeffs_idx[i].pred_index_re[j]; pSpar_md_prior->band_coeffs_idx_mapped[i].decd_index_re[j] = pSpar_md_prior->band_coeffs_idx[i].decd_index_re[j]; } - for (j = 0; j < IVAS_SPAR_MAX_C_COEFF; j++) + for ( j = 0; j < IVAS_SPAR_MAX_C_COEFF; j++ ) { pSpar_md_prior->band_coeffs_idx_mapped[i].drct_index_re[j] = pSpar_md_prior->band_coeffs_idx[i].drct_index_re[j]; } @@ -459,13 +457,13 @@ void ivas_spar_quant_dtx_init( } void ivas_spar_quant_dtx_init_fx( - ivas_spar_md_t *spar_md, - Word32 *min_max) + ivas_spar_md_t *spar_md, + Word32 *min_max ) { - spar_md->min_max_fx[0] = min_max[0]; - spar_md->min_max_fx[1] = min_max[1]; + spar_md->min_max_fx[0] = min_max[0]; + spar_md->min_max_fx[1] = min_max[1]; - return; + return; } /*-----------------------------------------------------------------------------------------* @@ -540,29 +538,28 @@ void ivas_clear_band_coeffs( set_zero( (float *) pband_coeffs[i].P_quant_re, ( IVAS_SPAR_MAX_CH - 1 ) ); set_zero( pband_coeffs[i].pred_re, ( IVAS_SPAR_MAX_CH - 1 ) ); set_zero( pband_coeffs[i].pred_quant_re, ( IVAS_SPAR_MAX_CH - 1 ) ); - } return; } void ivas_clear_band_coeffs_fx( - ivas_band_coeffs_t *pband_coeffs, - const UWord16 num_bands) + ivas_band_coeffs_t *pband_coeffs, + const UWord16 num_bands ) { - UWord16 i; - - for (i = 0; i < num_bands; i++) - { - set32_fx((Word32 *)pband_coeffs[i].C_re_fx, 0, (IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS) * (IVAS_SPAR_MAX_DMX_CHS - 1)); - set32_fx((Word32 *)pband_coeffs[i].P_re_fx, 0, (IVAS_SPAR_MAX_CH - 1)); - set32_fx((Word32 *)pband_coeffs[i].C_quant_re_fx, 0, (IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS) * (IVAS_SPAR_MAX_DMX_CHS - 1)); - set32_fx((Word32 *)pband_coeffs[i].P_quant_re_fx, 0, (IVAS_SPAR_MAX_CH - 1)); - set32_fx(pband_coeffs[i].pred_re_fx, 0, (IVAS_SPAR_MAX_CH - 1)); - set32_fx(pband_coeffs[i].pred_quant_re_fx, 0, (IVAS_SPAR_MAX_CH - 1)); - } - - return; + UWord16 i; + + for ( i = 0; i < num_bands; i++ ) + { + set32_fx( (Word32 *) pband_coeffs[i].C_re_fx, 0, ( IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ) * ( IVAS_SPAR_MAX_DMX_CHS - 1 ) ); + set32_fx( (Word32 *) pband_coeffs[i].P_re_fx, 0, ( IVAS_SPAR_MAX_CH - 1 ) ); + set32_fx( (Word32 *) pband_coeffs[i].C_quant_re_fx, 0, ( IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ) * ( IVAS_SPAR_MAX_DMX_CHS - 1 ) ); + set32_fx( (Word32 *) pband_coeffs[i].P_quant_re_fx, 0, ( IVAS_SPAR_MAX_CH - 1 ) ); + set32_fx( pband_coeffs[i].pred_re_fx, 0, ( IVAS_SPAR_MAX_CH - 1 ) ); + set32_fx( pband_coeffs[i].pred_quant_re_fx, 0, ( IVAS_SPAR_MAX_CH - 1 ) ); + } + + return; } /*-----------------------------------------------------------------------------------------* @@ -579,7 +576,7 @@ void ivas_clear_band_coeff_idx( for ( i = 0; i < num_bands; i++ ) { - set16_fx( pband_coeff_idx[i].pred_index_re, 0, ( sub(IVAS_SPAR_MAX_CH, 1 )) ); + set16_fx( pband_coeff_idx[i].pred_index_re, 0, ( sub( IVAS_SPAR_MAX_CH, 1 ) ) ); set16_fx( pband_coeff_idx[i].drct_index_re, 0, IVAS_SPAR_MAX_C_COEFF ); set16_fx( pband_coeff_idx[i].decd_index_re, 0, sub( IVAS_SPAR_MAX_CH, 1 ) ); } diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index 437b8d55e..586d88f1a 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -56,45 +56,45 @@ typedef struct /* ISM metadata handle (storage for one frame of read ISM metadata) */ typedef struct { - int16_t ism_metadata_flag; /* flag whether metadata are coded in particular frame of particular object */ - int16_t last_ism_metadata_flag; /* last frame ism_metadata_flag */ + int16_t ism_metadata_flag; /* flag whether metadata are coded in particular frame of particular object */ + int16_t last_ism_metadata_flag; /* last frame ism_metadata_flag */ #ifdef IVAS_FLOAT_FIXED - Word32 azimuth_fx; /* azimuth value read from the input metadata file */ /* Q22 */ - Word32 elevation_fx; /* elevation value read from the input metadata file */ /* Q22 */ - Word16 radius_fx; /* radius value read from the input metadata file */ /* Q9 */ - Word32 yaw_fx; /* yaw value read from the input metadata file */ /* Q22 */ - Word32 pitch_fx; /* pitch value read from the input metadata file */ /* Q22 */ + Word32 azimuth_fx; /* azimuth value read from the input metadata file */ /* Q22 */ + Word32 elevation_fx; /* elevation value read from the input metadata file */ /* Q22 */ + Word16 radius_fx; /* radius value read from the input metadata file */ /* Q9 */ + Word32 yaw_fx; /* yaw value read from the input metadata file */ /* Q22 */ + Word32 pitch_fx; /* pitch value read from the input metadata file */ /* Q22 */ #endif - float azimuth; /* azimuth value read from the input metadata file */ - float elevation; /* elevation value read from the input metadata file */ - float radius; /* radius value read from the input metadata file */ - float yaw; /* yaw value read from the input metadata file */ - float pitch; /* pitch value read from the input metadata file */ + float azimuth; /* azimuth value read from the input metadata file */ + float elevation; /* elevation value read from the input metadata file */ + float radius; /* radius value read from the input metadata file */ + float yaw; /* yaw value read from the input metadata file */ + float pitch; /* pitch value read from the input metadata file */ - int16_t non_diegetic_flag; /* Non-diegetic (non-headtracked) object flag */ + int16_t non_diegetic_flag; /* Non-diegetic (non-headtracked) object flag */ ISM_METADATA_ANGLE position_angle; /* Angle structs for azimuth and elevation */ ISM_METADATA_ANGLE orientation_angle; /* Angle structs for yaw and pitch */ int16_t last_radius_idx; /* last frame index of coded radius */ int16_t radius_diff_cnt; /* FEC counter of consecutive differentially radius coded frames */ - float last_azimuth; /* MD smoothing in DTX- last Q azimuth value */ - float last_elevation; /* MD smoothing in DTX - last Q elevation value */ - float last_true_azimuth; /* MD smoothing in DTX- last true Q azimuth value */ - float last_true_elevation; /* MD smoothing in DTX- last true Q elevation value */ + float last_azimuth; /* MD smoothing in DTX- last Q azimuth value */ + float last_elevation; /* MD smoothing in DTX - last Q elevation value */ + float last_true_azimuth; /* MD smoothing in DTX- last true Q azimuth value */ + float last_true_elevation; /* MD smoothing in DTX- last true Q elevation value */ #ifdef IVAS_FLOAT_FIXED - Word32 last_azimuth_fx; /* MD smoothing in DTX- last Q azimuth value */ /* Q22 */ - Word32 last_elevation_fx; /* MD smoothing in DTX - last Q elevation value */ /* Q22 */ - Word32 last_true_azimuth_fx; /* MD smoothing in DTX- last true Q azimuth value */ /* Q22 */ + Word32 last_azimuth_fx; /* MD smoothing in DTX- last Q azimuth value */ /* Q22 */ + Word32 last_elevation_fx; /* MD smoothing in DTX - last Q elevation value */ /* Q22 */ + Word32 last_true_azimuth_fx; /* MD smoothing in DTX- last true Q azimuth value */ /* Q22 */ Word32 last_true_elevation_fx; /* MD smoothing in DTX- last true Q elevation value */ /* Q22 */ #endif - int16_t ism_md_fec_cnt_enc; /* counter of continuous frames where MD are not transmitted */ - int16_t ism_md_inc_diff_cnt; /* counter of continuous frames where MD are transmitted in inactive segments when MD significantly changes */ - float last_true_radius; /* last true Q radius value */ + int16_t ism_md_fec_cnt_enc; /* counter of continuous frames where MD are not transmitted */ + int16_t ism_md_inc_diff_cnt; /* counter of continuous frames where MD are transmitted in inactive segments when MD significantly changes */ + float last_true_radius; /* last true Q radius value */ - int16_t ism_imp; /* ISM importance flag */ + int16_t ism_imp; /* ISM importance flag */ int16_t ism_md_null_flag; int16_t ism_md_lowrate_flag; float q_azimuth_old; @@ -111,9 +111,9 @@ typedef struct stereo_dft_config_data_struct { int16_t dmx_active; int16_t band_res; - int16_t prm_res; /* Send prm every # DFT frames */ - int16_t res_pred_mode; /* mode : from 0 (off) to 1 (on) */ - int16_t res_cod_mode; /* mode : from 0 (off) to 3 */ + int16_t prm_res; /* Send prm every # DFT frames */ + int16_t res_pred_mode; /* mode : from 0 (off) to 1 (on) */ + int16_t res_cod_mode; /* mode : from 0 (off) to 3 */ int16_t hybrid_itd_flag; int16_t ada_wb_res_cod_mode; /* res_cod_mode for adaptive wide band residual coding */ @@ -180,18 +180,18 @@ typedef struct ivas_dirac_config_data_struct /* SPAR MD structures */ typedef struct ivas_band_coeffs_t { - float pred_re[IVAS_SPAR_MAX_CH - 1];//22 - float C_re[IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS][IVAS_SPAR_MAX_DMX_CHS - 1];//22 - float P_re[IVAS_SPAR_MAX_CH - 1];//22 + float pred_re[IVAS_SPAR_MAX_CH - 1]; // 22 + float C_re[IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS][IVAS_SPAR_MAX_DMX_CHS - 1]; // 22 + float P_re[IVAS_SPAR_MAX_CH - 1]; // 22 float pred_quant_re[IVAS_SPAR_MAX_CH - 1]; float C_quant_re[IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS][IVAS_SPAR_MAX_DMX_CHS - 1]; float P_quant_re[IVAS_SPAR_MAX_CH - 1]; - Word16 q_pred_re_fx; + Word16 q_pred_re_fx; Word32 pred_re_fx[IVAS_SPAR_MAX_CH - 1]; - Word16 q_C_re_fx; + Word16 q_C_re_fx; Word32 C_re_fx[IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS][IVAS_SPAR_MAX_DMX_CHS - 1]; - Word16 q_P_re_fx; + Word16 q_P_re_fx; Word32 P_re_fx[IVAS_SPAR_MAX_CH - 1]; Word32 pred_quant_re_fx[IVAS_SPAR_MAX_CH - 1]; Word32 C_quant_re_fx[IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS][IVAS_SPAR_MAX_DMX_CHS - 1]; @@ -355,7 +355,7 @@ typedef struct ivas_agc_com_state_t float *winFunc; #ifdef IVAS_FLOAT_FIXED Word16 *winFunc_fx; -#endif // IVAS_FLOAT_FIXED +#endif // IVAS_FLOAT_FIXED int16_t in_delay; /* TODO: JBM check if this needs to be adjusted in the dec */ uint16_t absEmin; uint16_t betaE; @@ -596,7 +596,7 @@ typedef struct ivas_masa_qmetadata_frame_struct #ifndef IVAS_FLOAT_FIXED float dir_comp_ratio; #else - Word16 dir_comp_ratio_fx; /* Q15 */ + Word16 dir_comp_ratio_fx; /* Q15 */ #endif uint8_t is_masa_ivas_format; @@ -844,7 +844,7 @@ typedef struct ivas_fb_mixer_state_structure Word32 *ppFilterbank_inFR_im_fx[IVAS_MAX_FB_MIXER_IN_CH]; Word32 *ppFilterbank_prior_input_fx[IVAS_MAX_FB_MIXER_IN_CH]; Word32 *prior_mixer_fx[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH]; -#endif +#endif /* store sin part in const table (no need to store 1s and 0s, no need to do windowing for 1's and 0's as well) */ int16_t cross_fade_start_offset; @@ -906,11 +906,12 @@ typedef struct ivas_param_ism_data_structure } PARAM_ISM_CONFIG_DATA, *PARAM_ISM_CONFIG_HANDLE; #ifdef IVAS_FLOAT_FIXED -typedef struct { - Word16 ratio1; /* Modified ratio index1 (hordiac_flag is 0) */ - Word16 ratio2; /* Modified ratio index2 (hordiac_flag is 0) */ - Word16 hordiac_ratio1; /* Modified ratio index1 (hordiac_flag is 1) */ - Word16 hoardia_ratio2; /* Modified ratio index2 (hordiac_flag is 1) */ +typedef struct +{ + Word16 ratio1; /* Modified ratio index1 (hordiac_flag is 0) */ + Word16 ratio2; /* Modified ratio index2 (hordiac_flag is 0) */ + Word16 hordiac_ratio1; /* Modified ratio index1 (hordiac_flag is 1) */ + Word16 hoardia_ratio2; /* Modified ratio index2 (hordiac_flag is 1) */ } Masa_Diffuseness_Ratios; #endif diff --git a/lib_com/ivas_stereo_mdct_bands_com.c b/lib_com/ivas_stereo_mdct_bands_com.c index 31fba45c5..af8110c06 100644 --- a/lib_com/ivas_stereo_mdct_bands_com.c +++ b/lib_com/ivas_stereo_mdct_bands_com.c @@ -188,7 +188,7 @@ void stereo_mdct_init_bands_fx( } } /* change bands above the igf start line to match igf bands */ - for( i = 1, k = igfSfbStep; i < hIgfGrid->swb_offset_len; i++, k += igfSfbStep ) + for ( i = 1, k = igfSfbStep; i < hIgfGrid->swb_offset_len; i++, k += igfSfbStep ) { sfbOffset[*sfbCnt + i] = hIgfGrid->swb_offset[k]; } diff --git a/lib_com/ivas_stereo_mdct_stereo_com.c b/lib_com/ivas_stereo_mdct_stereo_com.c index 7fd46eefb..275dcbdae 100644 --- a/lib_com/ivas_stereo_mdct_stereo_com.c +++ b/lib_com/ivas_stereo_mdct_stereo_com.c @@ -52,7 +52,7 @@ void splitAvailableBits_fx( const Word16 total_bits, /* i : total available bits for TCX coding */ - const Word16 split_ratio, /* i : split ratio */ + const Word16 split_ratio, /* i : split ratio */ const Word16 isSBAStereoMode, /* i : signal core coding for SBA */ Word16 *bits_ch0, /* o : bits for channel 0 */ Word16 *bits_ch1 /* o : bits for channel 1 */ @@ -65,7 +65,7 @@ void splitAvailableBits_fx( if ( split_ratio < 7 && isSBAStereoMode ) { //*bits_ch0 += (int16_t) ( 0.2 * *bits_ch0 ); - *bits_ch0 += (Word16) ( Mpy_32_16_1( 6554, *bits_ch0 ) ); // 0.2 in Q15 + *bits_ch0 += (Word16) ( Mpy_32_16_1( 6554, *bits_ch0 ) ); // 0.2 in Q15 } *bits_ch1 = total_bits - *bits_ch0; diff --git a/lib_com/ivas_stereo_psychlpc_com.c b/lib_com/ivas_stereo_psychlpc_com.c index c68350c1b..fce1f62ab 100644 --- a/lib_com/ivas_stereo_psychlpc_com.c +++ b/lib_com/ivas_stereo_psychlpc_com.c @@ -50,7 +50,7 @@ static void SpectrumWeighting_Init( const Word16 isTCX20, PsychoacousticParameters *pPsychParams ) { - IF ( isTCX20 ) + IF( isTCX20 ) { pPsychParams->bandLengths = pSpectrumWarping->bandLengthsTCX20; } @@ -91,7 +91,7 @@ ivas_error PsychoacousticParameters_Init( } ELSE { - assert( EQ_16(pPsychParams->nBands , 64) ); + assert( EQ_16( pPsychParams->nBands, 64 ) ); SWITCH( sr_core ) { case 16000: @@ -118,8 +118,8 @@ ivas_error PsychoacousticParameters_Init( *-------------------------------------------------------------------*/ void InitPsychLPC( - const Word32 sr_core, /* i : sampling rate of core-coder */ - const Word16 L_frame, /* i : frame length */ + const Word32 sr_core, /* i : sampling rate of core-coder */ + const Word16 L_frame, /* i : frame length */ const TCX_CONFIG_HANDLE hTcxCfg /* i : TCX configuration handle */ ) { @@ -164,14 +164,14 @@ void SetCurrentPsychParams( const Word16 last_frame_was_concealed_cng, TCX_CONFIG_HANDLE hTcxCfg ) { - IF ( EQ_16(hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP) && EQ_16(last_frame_was_concealed_cng, 0) ) + IF( EQ_16( hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) && EQ_16( last_frame_was_concealed_cng, 0 ) ) { assert( core == TCX_20_CORE ); hTcxCfg->psychParamsCurrent = &hTcxCfg->psychParamsTCX20AfterACELP; } ELSE { - hTcxCfg->psychParamsCurrent = ( EQ_16(core, TCX_10_CORE) ) ? &hTcxCfg->psychParamsTCX10 : &hTcxCfg->psychParamsTCX20; + hTcxCfg->psychParamsCurrent = ( EQ_16( core, TCX_10_CORE ) ) ? &hTcxCfg->psychParamsTCX10 : &hTcxCfg->psychParamsTCX20; } return; diff --git a/lib_com/ivas_stereo_td_bit_alloc.c b/lib_com/ivas_stereo_td_bit_alloc.c index d9ec5ada7..1458bc8e6 100644 --- a/lib_com/ivas_stereo_td_bit_alloc.c +++ b/lib_com/ivas_stereo_td_bit_alloc.c @@ -510,7 +510,7 @@ void tdm_bit_alloc( IF( coder_type == INACTIVE ) { Word32 res_fix = 0; - res_fix = Mpy_32_32(644245095, ( element_brate_wo_meta - 500 ) ); + res_fix = Mpy_32_32( 644245095, ( element_brate_wo_meta - 500 ) ); res_fix = ( ( res_fix / 100 ) * 100 ); *total_brate_sec = max( *total_brate_sec, res_fix ); @@ -520,9 +520,9 @@ void tdm_bit_alloc( ELSE { Word32 res_fix = 0; - res_fix = Mpy_32_32(1073741824, ( element_brate_wo_meta - 500 ) ); + res_fix = Mpy_32_32( 1073741824, ( element_brate_wo_meta - 500 ) ); res_fix = ( ( res_fix / 100 ) * 100 ); - *total_brate_sec = max(*total_brate_sec, res_fix ); + *total_brate_sec = max( *total_brate_sec, res_fix ); //*total_brate_sec = max(*total_brate_sec, (int16_t)(0.5f * (element_brate_wo_meta - 500) / 100) * 100); /* tmp_bits = -abs(tdm_inst_ratio_idx-16)*200*idx; */ @@ -538,20 +538,19 @@ void tdm_bit_alloc( bit_rate_diff_fx = tmp_bits; } ELSE{ - IF( ener_ratio_idx < LRTD_STEREO_MID_IS_PRIM ) - { + IF( ener_ratio_idx < LRTD_STEREO_MID_IS_PRIM ){ bit_rate_diff_fx = ( LRTD_STEREO_MID_IS_PRIM - ener_ratio_idx ) * bit_rate_diff_fx; - bit_rate_diff_fx = L_shr( bit_rate_diff_fx, 1 ); - bit_rate_diff_fx = bit_rate_diff_fx / 10; // basop gives very minor deviation - } - ELSE - { - bit_rate_diff_fx = ( ener_ratio_idx - LRTD_STEREO_MID_IS_PRIM ) * bit_rate_diff_fx; - bit_rate_diff_fx = L_shr(bit_rate_diff_fx, 1); - bit_rate_diff_fx = bit_rate_diff_fx / 10; // basop gives very minor deviation - } - } + bit_rate_diff_fx = L_shr( bit_rate_diff_fx, 1 ); + bit_rate_diff_fx = bit_rate_diff_fx / 10; // basop gives very minor deviation + } + ELSE + { + bit_rate_diff_fx = ( ener_ratio_idx - LRTD_STEREO_MID_IS_PRIM ) * bit_rate_diff_fx; + bit_rate_diff_fx = L_shr( bit_rate_diff_fx, 1 ); + bit_rate_diff_fx = bit_rate_diff_fx / 10; // basop gives very minor deviation + } +} /*bit_rate_diff2 = ((Word16)(10.f*(-0.5f*ener_ratio_LR+0.5f)*bit_rate_diff)/100)*100;*/ *total_brate_sec += ( (Word16) ( bit_rate_diff_fx / 100 ) * 100 ); *total_brate_sec = max( *total_brate_sec, tdm_bit_allc_tbl[idx][coder_type] ); @@ -593,7 +592,7 @@ IF( ( ener_ratio_idx <= 1 || ener_ratio_idx >= 29 ) && coder_type >= UNVOICED ) } ELSE { - *total_brate_sec = min(*total_brate_sec, Mpy_32_32(9663677, element_brate_wo_meta)* 100); + *total_brate_sec = min( *total_brate_sec, Mpy_32_32( 9663677, element_brate_wo_meta ) * 100 ); } *total_brate_sec = min( *total_brate_sec, 18000 ); @@ -896,23 +895,23 @@ void td_stereo_param_updt_fx( } /* This is only to keep the buffer up-to-date */ - Word16 mult_factor = 26214/*0.8f in Q15*/; + Word16 mult_factor = 26214 /*0.8f in Q15*/; Word16 min_tdm_Pri_pitch_buf_fx = 0; Word16 Flag = 0; IF( flag_ACELP16k == 1 ) { - FOR(i = 0; i < NB_SUBFR; i++) + FOR( i = 0; i < NB_SUBFR; i++ ) { - tdm_Pri_pitch_buf_fx[i] = mult(pitch_buf_PCh_fx[i], mult_factor); - min_tdm_Pri_pitch_buf_fx = s_min(tdm_Pri_pitch_buf_fx[i], min_tdm_Pri_pitch_buf_fx); + tdm_Pri_pitch_buf_fx[i] = mult( pitch_buf_PCh_fx[i], mult_factor ); + min_tdm_Pri_pitch_buf_fx = s_min( tdm_Pri_pitch_buf_fx[i], min_tdm_Pri_pitch_buf_fx ); } - Flag = BASOP_Util_Cmp_Mant32Exp( L_deposit_l(min_tdm_Pri_pitch_buf_fx), 31 - Q_var, PIT_MIN, 31 ); - IF(Flag == -1) + Flag = BASOP_Util_Cmp_Mant32Exp( L_deposit_l( min_tdm_Pri_pitch_buf_fx ), 31 - Q_var, PIT_MIN, 31 ); + IF( Flag == -1 ) { - FOR(i = 0; i < NB_SUBFR; i++) + FOR( i = 0; i < NB_SUBFR; i++ ) { - tdm_Pri_pitch_buf_fx[i] = s_max(tdm_Pri_pitch_buf_fx[i], shr(PIT_MIN, Q_var)); + tdm_Pri_pitch_buf_fx[i] = s_max( tdm_Pri_pitch_buf_fx[i], shr( PIT_MIN, Q_var ) ); } } } @@ -1003,14 +1002,14 @@ static void tdm_SCh_LSF_intra_pred_tri_diag_mat_fx( lsf_tmp_ptr2_fx = lsf_tmp_ptr1_fx; - *lsf_SCh_ptr_fx = mult_r( *lsf_tmp_ptr1_fx++, *prd_ptr_fx++ ); //Q2.56 + 15 -15 - *lsf_SCh_ptr_fx = add( *lsf_SCh_ptr_fx, mult_r( *lsf_tmp_ptr1_fx, *prd_ptr_fx++ ) );//Q2.56 + 15 -15 + *lsf_SCh_ptr_fx = mult_r( *lsf_tmp_ptr1_fx++, *prd_ptr_fx++ ); // Q2.56 + 15 -15 + *lsf_SCh_ptr_fx = add( *lsf_SCh_ptr_fx, mult_r( *lsf_tmp_ptr1_fx, *prd_ptr_fx++ ) ); // Q2.56 + 15 -15 lsf_SCh_ptr_fx++; FOR( i = 1; i < M - 1; i++ ) { - lsf_tmp_ptr1_fx = lsf_tmp_ptr2_fx;//Q2.56 - *lsf_SCh_ptr_fx = mult_r( *lsf_tmp_ptr1_fx++, *prd_ptr_fx++ );//Q2.56 + 15 -15 + lsf_tmp_ptr1_fx = lsf_tmp_ptr2_fx; // Q2.56 + *lsf_SCh_ptr_fx = mult_r( *lsf_tmp_ptr1_fx++, *prd_ptr_fx++ ); // Q2.56 + 15 -15 lsf_tmp_ptr2_fx = lsf_tmp_ptr1_fx; *lsf_SCh_ptr_fx = add( *lsf_SCh_ptr_fx, mult_r( ( *lsf_tmp_ptr1_fx++ ), ( *prd_ptr_fx++ ) ) ); ( *lsf_SCh_ptr_fx ) = add( *lsf_SCh_ptr_fx, mult_r( ( *lsf_tmp_ptr1_fx ), ( *prd_ptr_fx++ ) ) ); @@ -1018,10 +1017,10 @@ static void tdm_SCh_LSF_intra_pred_tri_diag_mat_fx( } lsf_tmp_ptr1_fx = lsf_tmp_ptr2_fx; - *lsf_SCh_ptr_fx = mult_r((*lsf_tmp_ptr1_fx), (*prd_ptr_fx)); + *lsf_SCh_ptr_fx = mult_r( ( *lsf_tmp_ptr1_fx ), ( *prd_ptr_fx ) ); lsf_tmp_ptr1_fx++; prd_ptr_fx++; - *lsf_SCh_ptr_fx = add( mult_r( ( *lsf_tmp_ptr1_fx), ( *prd_ptr_fx) ), *lsf_SCh_ptr_fx); + *lsf_SCh_ptr_fx = add( mult_r( ( *lsf_tmp_ptr1_fx ), ( *prd_ptr_fx ) ), *lsf_SCh_ptr_fx ); v_add_16( lsf_SCh_fx, lsf_mean_out_fx, lsf_SCh_fx, M ); @@ -1184,9 +1183,9 @@ static void tdm_SCh_LSF_intra_pred_one_bit_dec_fx( beta_fx = Beta_Q_x_fx[beta_index_fx]; // Q15 /* pulling the LSFs closer to the avergae */ - FOR ( i = 0; i < M; i++ ) + FOR( i = 0; i < M; i++ ) { - pred_lsf_SCh_fx[i] = add( mult_r( beta_fx, tdm_lsfQ_PCh_fx[i] ), mult_r(sub( 32767, beta_fx ), lsf_mean_fx[i] )); + pred_lsf_SCh_fx[i] = add( mult_r( beta_fx, tdm_lsfQ_PCh_fx[i] ), mult_r( sub( 32767, beta_fx ), lsf_mean_fx[i] ) ); } return; @@ -1251,14 +1250,14 @@ static void tdm_SCh_LSF_intra_pred_one_bit_enc_fx( FOR( i = 0; i < M; i++ ) { - Word32 wgt_A_temp = Mpy_32_16_1(L_mult(A_temp_fx[i], A_temp_fx[i]), lsf_wgts_new_fx[i]);// - Word32 wgt_B_temp = Mpy_32_16_1(L_mult(B_temp_fx[i], B_temp_fx[i]), lsf_wgts_new_fx[i]); - Word32 wgt_AB_temp = Mpy_32_16_1(L_mult(A_temp_fx[i], B_temp_fx[i]), lsf_wgts_new_fx[i]); - Word32 Beta_Q_x0 = L_mult(Beta_Q_x_fx[0], Beta_Q_x_fx[0]);//Q31 - Word32 Beta_Q_x1 = L_mult(Beta_Q_x_fx[1], Beta_Q_x_fx[1]);//Q31 + Word32 wgt_A_temp = Mpy_32_16_1( L_mult( A_temp_fx[i], A_temp_fx[i] ), lsf_wgts_new_fx[i] ); // + Word32 wgt_B_temp = Mpy_32_16_1( L_mult( B_temp_fx[i], B_temp_fx[i] ), lsf_wgts_new_fx[i] ); + Word32 wgt_AB_temp = Mpy_32_16_1( L_mult( A_temp_fx[i], B_temp_fx[i] ), lsf_wgts_new_fx[i] ); + Word32 Beta_Q_x0 = L_mult( Beta_Q_x_fx[0], Beta_Q_x_fx[0] ); // Q31 + Word32 Beta_Q_x1 = L_mult( Beta_Q_x_fx[1], Beta_Q_x_fx[1] ); // Q31 - WD_fx[0] = L_add(WD_fx[0], L_add(L_add(wgt_A_temp, Mpy_32_16_1(L_shl(wgt_AB_temp, 1), Beta_Q_x_fx[0])), Mpy_32_32(wgt_B_temp, Beta_Q_x0))); - WD_fx[1] = L_add(WD_fx[1], L_add(L_add(wgt_A_temp, Mpy_32_16_1(L_shl(wgt_AB_temp, 1), Beta_Q_x_fx[1])), Mpy_32_32(wgt_B_temp, Beta_Q_x1))); + WD_fx[0] = L_add( WD_fx[0], L_add( L_add( wgt_A_temp, Mpy_32_16_1( L_shl( wgt_AB_temp, 1 ), Beta_Q_x_fx[0] ) ), Mpy_32_32( wgt_B_temp, Beta_Q_x0 ) ) ); + WD_fx[1] = L_add( WD_fx[1], L_add( L_add( wgt_A_temp, Mpy_32_16_1( L_shl( wgt_AB_temp, 1 ), Beta_Q_x_fx[1] ) ), Mpy_32_32( wgt_B_temp, Beta_Q_x1 ) ) ); } IF( WD_fx[0] < WD_fx[1] ) @@ -1332,10 +1331,10 @@ static void tdm_SCh_LSF_intra_pred_one_bit_enc( *-------------------------------------------------------------------*/ void tdm_SCh_lsf_reuse_fx( - const Word16 enc_dec, /* i : encoder/decoder flag */ - const Word32 element_brate, /* i : element bitrate */ - Word16 lsf_new_fx[M], /* i/o: LSFs at the end of the frame */ - Word16 lsp_new_fx[M], /* i/o: LSPs at the end of the frame */ + const Word16 enc_dec, /* i : encoder/decoder flag */ + const Word32 element_brate, /* i : element bitrate */ + Word16 lsf_new_fx[M], /* i/o: LSFs at the end of the frame */ + Word16 lsp_new_fx[M], /* i/o: LSPs at the end of the frame */ const Word16 tdm_lsfQ_PCh_fx[M], /* i : primary channel LSFs */ const Word16 lsf_wgts_fx[M], /* i : LSF weights */ Word16 *beta_index /* i/o: quantization index */ @@ -1343,15 +1342,15 @@ void tdm_SCh_lsf_reuse_fx( { const Word16 *Beta_Q1bit_re_use_fx; - IF( LE_32(element_brate, IVAS_13k2 )) + IF( LE_32( element_brate, IVAS_13k2 ) ) { Beta_Q1bit_re_use_fx = tdm_Beta_Q1bit_re_use_13k2_fx; } - ELSE IF(LE_32(element_brate, IVAS_16k4 )) + ELSE IF( LE_32( element_brate, IVAS_16k4 ) ) { Beta_Q1bit_re_use_fx = tdm_Beta_Q1bit_re_use_16k4_fx; } - ELSE IF(LE_32(element_brate, IVAS_32k )) + ELSE IF( LE_32( element_brate, IVAS_32k ) ) { Beta_Q1bit_re_use_fx = tdm_Beta_Q1bit_re_use_24k4_32k_fx; } @@ -1360,7 +1359,7 @@ void tdm_SCh_lsf_reuse_fx( Beta_Q1bit_re_use_fx = tdm_Beta_Q1bit_re_use_48k_fx; } - IF( EQ_16(enc_dec, ENC )) + IF( EQ_16( enc_dec, ENC ) ) { tdm_SCh_LSF_intra_pred_one_bit_enc_fx( lsf_new_fx, tdm_lsfQ_PCh_fx, lsf_new_fx, tdm_LSF_MEAN_RE_USE_fx, lsf_wgts_fx, Beta_Q1bit_re_use_fx, beta_index ); } diff --git a/lib_com/ivas_tools.c b/lib_com/ivas_tools.c index c8a0475b5..da11a7ac9 100644 --- a/lib_com/ivas_tools.c +++ b/lib_com/ivas_tools.c @@ -153,7 +153,7 @@ uint32_t ivas_syn_output( #ifdef IVAS_FLOAT_FIXED UWord32 ivas_syn_output_fx( - Word32 *synth[], /* i/o: float synthesis signal */ + Word32 *synth[], /* i/o: float synthesis signal */ const Word16 q_synth, const Word16 output_frame, /* i : output frame length (one channel) */ const Word16 n_channels, /* i : number of output channels */ @@ -168,11 +168,11 @@ UWord32 ivas_syn_output_fx( * float to integer conversion with saturation control *-----------------------------------------------------------------*/ - FOR ( n = 0; n < n_channels; n++ ) + FOR( n = 0; n < n_channels; n++ ) { noClipping += mvl2s_r( synth[n], q_synth, synth_loc, output_frame ); - FOR ( i = 0; i < output_frame; i++ ) + FOR( i = 0; i < output_frame; i++ ) { synth_out[i * n_channels + n] = synth_loc[i]; } @@ -217,10 +217,10 @@ void ivas_syn_output_f( #ifdef IVAS_FLOAT_FIXED void ivas_syn_output_f_fx( - Word32 *synth[], /* i/o: float synthesis signal */ + Word32 *synth[], /* i/o: float synthesis signal */ const Word16 output_frame, /* i : output frame length (one channel) */ const Word16 n_channels, /* i : number of output channels */ - Word32 *synth_out /* o : integer 16 bits synthesis signal */ + Word32 *synth_out /* o : integer 16 bits synthesis signal */ ) { Word16 i, n; @@ -229,9 +229,9 @@ void ivas_syn_output_f_fx( * float to integer conversion with saturation control *-----------------------------------------------------------------*/ - FOR ( n = 0; n < n_channels; n++ ) + FOR( n = 0; n < n_channels; n++ ) { - FOR ( i = 0; i < output_frame; i++ ) + FOR( i = 0; i < output_frame; i++ ) { synth_out[i * n_channels + n] = synth[n][i]; } @@ -249,28 +249,28 @@ void ivas_syn_output_f_fx( *-------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED void mvr2r_inc_fixed_one( - const Word32 x_fx[], /* i : input vector */ - const Word16 x_inc, /* i : increment for vector x[] */ - Word32 y_fx[], /* o : output vector */ - const Word16 y_inc, /* i : increment for vector y[] */ - const Word16 n /* i : vector size */ + const Word32 x_fx[], /* i : input vector */ + const Word16 x_inc, /* i : increment for vector x[] */ + Word32 y_fx[], /* o : output vector */ + const Word16 y_inc, /* i : increment for vector y[] */ + const Word16 n /* i : vector size */ ) { Word16 i; Word16 ix; Word16 iy; - IF(n <= 0) + IF( n <= 0 ) { /* cannot transfer vectors with size 0 */ return; } - IF(y_fx < x_fx) + IF( y_fx < x_fx ) { ix = 0; iy = 0; - FOR(i = 0; i < n; i++) + FOR( i = 0; i < n; i++ ) { y_fx[iy] = x_fx[ix]; @@ -280,9 +280,9 @@ void mvr2r_inc_fixed_one( } ELSE { - ix = (n - 1) * x_inc; - iy = (n - 1) * y_inc; - FOR(i = n - 1; i >= 0; i--) + ix = ( n - 1 ) * x_inc; + iy = ( n - 1 ) * y_inc; + FOR( i = n - 1; i >= 0; i-- ) { y_fx[iy] = x_fx[ix]; @@ -424,13 +424,13 @@ void v_add_inc( #ifdef IVAS_FLOAT_FIXED // for same q// void v_add_inc_fx( - const Word32 x1[], /* i : Input vector 1 */ - const Word16 x_inc, /* i : Increment for input vector 1 */ + const Word32 x1[], /* i : Input vector 1 */ + const Word16 x_inc, /* i : Increment for input vector 1 */ const Word32 x2[], /* i : Input vector 2 */ const Word16 x2_inc, /* i : Increment for input vector 2 */ Word32 y[], /* o : Output vector that contains vector 1 + vector 2 */ - const Word16 y_inc, /* i : increment for vector y[] */ - const Word16 N /* i : Vector length */ + const Word16 y_inc, /* i : increment for vector y[] */ + const Word16 N /* i : Vector length */ ) { Word16 i; @@ -439,7 +439,7 @@ void v_add_inc_fx( Word16 iy = 0; FOR( i = 0; i < N; i++ ) { - y[iy] = L_add(x1[ix1], x2[ix2]); + y[iy] = L_add( x1[ix1], x2[ix2] ); ix1 += x_inc; ix2 += x2_inc; iy += y_inc; @@ -486,32 +486,32 @@ void v_mult_inc_fx( return; } -//when buffers have constant q/ +// when buffers have constant q/ void v_mult_inc_fixed( - const Word32 x1_fx[], /* i : Input vector 1 */ - const Word16 x1_inc, /* i : Increment for input vector 1 */ - const Word32 x2_fx[], /* i : Input vector 2 */ - const Word16 x2_inc, /* i : Increment for input vector 1 */ - Word32 y_fx[], /* o : Output vector that contains vector 1 .* vector 2 */ - const Word16 y_inc, /* i : increment for vector y[i] */ - const Word16 N /* i : Vector length */ + const Word32 x1_fx[], /* i : Input vector 1 */ + const Word16 x1_inc, /* i : Increment for input vector 1 */ + const Word32 x2_fx[], /* i : Input vector 2 */ + const Word16 x2_inc, /* i : Increment for input vector 1 */ + Word32 y_fx[], /* o : Output vector that contains vector 1 .* vector 2 */ + const Word16 y_inc, /* i : increment for vector y[i] */ + const Word16 N /* i : Vector length */ ) { - Word16 i; - Word16 ix1 = 0; - Word16 ix2 = 0; - Word16 iy = 0; + Word16 i; + Word16 ix1 = 0; + Word16 ix2 = 0; + Word16 iy = 0; - FOR(i = 0; i < N; i++) - { - y_fx[iy] = Mpy_32_32(x1_fx[ix1], x2_fx[ix2]); + FOR( i = 0; i < N; i++ ) + { + y_fx[iy] = Mpy_32_32( x1_fx[ix1], x2_fx[ix2] ); - ix1 = add(ix1, x1_inc); - ix2 = add(ix2, x2_inc); - iy = add(iy, y_inc); - } + ix1 = add( ix1, x1_inc ); + ix2 = add( ix2, x2_inc ); + iy = add( iy, y_inc ); + } - return; + return; } #endif @@ -619,14 +619,14 @@ void v_addc_fixed( const Word32 x[], /* i : Input vector */ const Word32 c, /* i : Constant */ Word32 y[], /* o : Output vector that contains c*x */ - const Word16 N /* i : Vector length */ + const Word16 N /* i : Vector length */ ) { Word16 i; - FOR(i = 0; i < N; i++) + FOR( i = 0; i < N; i++ ) { - y[i] = L_add(c, x[i]); + y[i] = L_add( c, x[i] ); } return; @@ -1150,7 +1150,7 @@ int16_t check_bounds_s( * Ensure the input value is within the given limits *-------------------------------------------------------------------*/ - /*! r: Adjusted value */ +/*! r: Adjusted value */ Word32 check_bounds_l( const Word32 value, /* i : Input value */ const Word32 low, /* i : Low limit */ @@ -1159,7 +1159,7 @@ Word32 check_bounds_l( { Word32 value_adj; - value_adj = min(max(value, low), high); + value_adj = min( max( value, low ), high ); return value_adj; } @@ -1416,10 +1416,10 @@ Word16 matrix_product_q30_fx( FOR( k = 0; k < rowsX; ++k ) { //( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[k + i * rowsX], Y_fx[k + j * rowsY] ) ); - W_tmp = W_add( W_tmp, W_mult0_32_32( X_fx[k + i * rowsX], Y_fx[k + j * rowsY] ) );//Q56 + W_tmp = W_add( W_tmp, W_mult0_32_32( X_fx[k + i * rowsX], Y_fx[k + j * rowsY] ) ); // Q56 } W_tmp = W_shl( W_tmp, 6 ); - ( *Zp_fx ) = L_sub(W_round64_L( W_tmp ), 64); //adjusting for precision + ( *Zp_fx ) = L_sub( W_round64_L( W_tmp ), 64 ); // adjusting for precision Zp_fx++; } } @@ -1723,9 +1723,9 @@ Word16 matrix_diag_product_fx( Word32 *Zp = Z; /* Processing */ - IF( EQ_16(transpX, 1 )) /* We use X transpose */ + IF( EQ_16( transpX, 1 ) ) /* We use X transpose */ { - IF( NE_16(rowsX, entriesY )) + IF( NE_16( rowsX, entriesY ) ) { return EXIT_FAILURE; } @@ -1740,7 +1740,7 @@ Word16 matrix_diag_product_fx( } ELSE /* Regular case */ { - IF(NE_16(colsX, entriesY )) + IF( NE_16( colsX, entriesY ) ) { return EXIT_FAILURE; } @@ -1811,7 +1811,7 @@ Word16 diag_matrix_product_fx( } } - *Z_e = add(Y_e, X_e); + *Z_e = add( Y_e, X_e ); return EXIT_SUCCESS; } @@ -2217,14 +2217,14 @@ void v_multc_acc_32_16( const Word32 x[], /* i : Input vector */ const Word16 c, /* i : Constant */ Word32 y[], /* o : Output vector that contains y + c*x */ - const Word16 N /* i : Vector length */ + const Word16 N /* i : Vector length */ ) { Word16 i; - FOR ( i = 0; i < N; i++ ) + FOR( i = 0; i < N; i++ ) { - y[i] = L_add(y[i],Mpy_32_16_1(x[i],c)); + y[i] = L_add( y[i], Mpy_32_16_1( x[i], c ) ); } return; @@ -2302,10 +2302,10 @@ void lls_interp_n( } void lls_interp_n_fx( - Word16 x_fx[], /* i/o: input/output vector */ + Word16 x_fx[], /* i/o: input/output vector */ const Word16 N, /* i : length of the input vector */ - Word16 *a_fx, /* o : calculated slope */ - Word16 *b_fx, /* o : calculated offset */ + Word16 *a_fx, /* o : calculated slope */ + Word16 *b_fx, /* o : calculated offset */ const Word16 upd /* i : use 1 to update x[] with the interpolated output */ ) { @@ -2321,44 +2321,44 @@ void lls_interp_n_fx( Word16 dot_exp = 0, sum_ix_q = 0; ; Word32 num; - assert(N > 0 && N <= 10); + assert( N > 0 && N <= 10 ); sum_x_fx = 0; - FOR (int idx = 0; idx < N; idx++) + FOR( int idx = 0; idx < N; idx++ ) { - sum_x_fx = (Word32)sum_x_fx + x_fx[idx]; + sum_x_fx = (Word32) sum_x_fx + x_fx[idx]; } - sum_ix_fx = dotp_fx(x_fx, n_i_fx, N, &dot_exp); - sum_ix_q = 30 - (dot_exp - (11 + 15)); + sum_ix_fx = dotp_fx( x_fx, n_i_fx, N, &dot_exp ); + sum_ix_q = 30 - ( dot_exp - ( 11 + 15 ) ); - sum_ix_fx = L_shr(sum_ix_fx, sum_ix_q - 15); - num = L_sub((sum_ix_fx * N), (sum_x_fx * sum_i_fx[N])); - slope_fx = Mpy_32_32(num, res_table[N]); - offset_fx = Mpy_32_16_1(L_sub(sum_x_fx, (slope_fx * sum_i_fx[N])), one_by_n_fx[N]); + sum_ix_fx = L_shr( sum_ix_fx, sum_ix_q - 15 ); + num = L_sub( ( sum_ix_fx * N ), ( sum_x_fx * sum_i_fx[N] ) ); + slope_fx = Mpy_32_32( num, res_table[N] ); + offset_fx = Mpy_32_16_1( L_sub( sum_x_fx, ( slope_fx * sum_i_fx[N] ) ), one_by_n_fx[N] ); - IF (upd) + IF( upd ) { - FOR (i = 0; i < N; i++) + FOR( i = 0; i < N; i++ ) { - IF(slope_fx * i > MAX_WORD16) + IF( slope_fx * i > MAX_WORD16 ) { x_fx[i] = MAX_WORD16; } ELSE { - x_fx[i] = (Word16)L_add_sat((slope_fx * i), offset_fx); + x_fx[i] = (Word16) L_add_sat( ( slope_fx * i ), offset_fx ); } } } - IF(a_fx != NULL) + IF( a_fx != NULL ) { - *a_fx = (Word16)slope_fx; + *a_fx = (Word16) slope_fx; } - IF(b_fx != NULL) + IF( b_fx != NULL ) { - *b_fx = (Word16)offset_fx; + *b_fx = (Word16) offset_fx; } return; @@ -2590,7 +2590,7 @@ void v_sort_ind( *-------------------------------------------------------------------------*/ void v_sort_ind_fixed( - Word32 *x, /* i/o: Vector to be sorted */ + Word32 *x, /* i/o: Vector to be sorted */ Word16 *idx, /* o : Original index positions */ const Word16 len /* i : vector length */ ) @@ -2599,16 +2599,16 @@ void v_sort_ind_fixed( Word32 tempr; Word16 tempi; - FOR ( i = 0; i < len; i++ ) + FOR( i = 0; i < len; i++ ) { idx[i] = i; } - FOR ( i = len - 2; i >= 0; i-- ) + FOR( i = len - 2; i >= 0; i-- ) { tempr = x[i]; tempi = idx[i]; - FOR ( j = i + 1; ( j < len ) && ( tempr > x[j] ); j++ ) + FOR( j = i + 1; ( j < len ) && ( tempr > x[j] ); j++ ) { x[j - 1] = x[j]; idx[j - 1] = idx[j]; @@ -2649,23 +2649,23 @@ int16_t is_IVAS_bitrate( } Word16 is_IVAS_bitrate_fx( - const Word32 ivas_total_brate /* i : IVAS total bitrate */ + const Word32 ivas_total_brate /* i : IVAS total bitrate */ ) { - Word16 j; + Word16 j; - j = SIZE_IVAS_BRATE_TBL - IVAS_NUM_ACTIVE_BRATES; /* skip NO_DATA and SID bitrates */ - WHILE (LE_16(j, SIZE_IVAS_BRATE_TBL) && NE_32(ivas_total_brate, ivas_brate_tbl[j])) - { - j++; - } + j = SIZE_IVAS_BRATE_TBL - IVAS_NUM_ACTIVE_BRATES; /* skip NO_DATA and SID bitrates */ + WHILE( LE_16( j, SIZE_IVAS_BRATE_TBL ) && NE_32( ivas_total_brate, ivas_brate_tbl[j] ) ) + { + j++; + } - IF (j >= SIZE_IVAS_BRATE_TBL) - { - return 0; - } + IF( j >= SIZE_IVAS_BRATE_TBL ) + { + return 0; + } - return 1; + return 1; } /*-------------------------------------------------------------------* diff --git a/lib_com/ivas_transient_det.c b/lib_com/ivas_transient_det.c index ecfc85acc..54539e383 100644 --- a/lib_com/ivas_transient_det.c +++ b/lib_com/ivas_transient_det.c @@ -48,8 +48,8 @@ *------------------------------------------------------------------------------------------*/ #define IVAS_TDET_PARM_ENV_EPS ( 1e-5f ) -#ifdef IVAS_FLOAT_FIXED -#define IVAS_TDET_PARM_ENV_EPS_fx 21474 //Q31 +#ifdef IVAS_FLOAT_FIXED +#define IVAS_TDET_PARM_ENV_EPS_fx 21474 // Q31 #endif #ifdef IVAS_FLOAT_FIXED @@ -61,12 +61,12 @@ #define IVAS_TDET_DUCK_MULT_FAC ( 1.1f ) #define IVAS_TDET_PARM_TRANS_THR ( 0.1f ) #endif -#define IVAS_TDET_ONLY ( 1 ) +#define IVAS_TDET_ONLY ( 1 ) /*env_hpf*/ -#define IVAS_C_HPF_48k ( 0.675231906655777f ) -#define IVAS_C_HPF_32k ( 0.554854910159853f ) -#define IVAS_C_HPF_16k ( 0.307863971328499f ) +#define IVAS_C_HPF_48k ( 0.675231906655777f ) +#define IVAS_C_HPF_32k ( 0.554854910159853f ) +#define IVAS_C_HPF_16k ( 0.307863971328499f ) #ifdef IVAS_FLOAT_FIXED #define IVAS_C_HPF_48k_fx ( 0x2b370000 ) @@ -98,9 +98,9 @@ #ifdef IVAS_FLOAT_FIXED /*induck*/ -#define IVAS_C_IN_DUCK_48k_fx ( 1073294525 ) // Q30 -#define IVAS_C_IN_DUCK_32k_fx ( 1073070945 ) // Q30 -#define IVAS_C_IN_DUCK_16k_fx ( 1072400485 ) // Q30 +#define IVAS_C_IN_DUCK_48k_fx ( 1073294525 ) // Q30 +#define IVAS_C_IN_DUCK_32k_fx ( 1073070945 ) // Q30 +#define IVAS_C_IN_DUCK_16k_fx ( 1072400485 ) // Q30 /*outduck*/ #define IVAS_C_OUT_DUCK_48k_fx ( 1073294525 ) // Q30 @@ -133,7 +133,7 @@ static void ivas_transient_det_init( #ifndef IVAS_FLOAT_FIXED float filt_coeff_arr[3][IVAS_BIQUAD_FILT_LEN << 1]; #else - Word32 filt_coeff_arr_fx[3][IVAS_BIQUAD_FILT_LEN << 1]; + Word32 filt_coeff_arr_fx[3][IVAS_BIQUAD_FILT_LEN << 1]; #endif #ifdef IVAS_FLOAT_FIXED @@ -144,16 +144,16 @@ static void ivas_transient_det_init( hTranDet->out_duck_gain = 1.0f; #endif - FOR ( i = 0; i < 3; i++ ) + FOR( i = 0; i < 3; i++ ) { #ifndef IVAS_FLOAT_FIXED set_zero( filt_coeff_arr[i], IVAS_BIQUAD_FILT_LEN << 1 ); #else - set32_fx(filt_coeff_arr_fx[i], 0, IVAS_BIQUAD_FILT_LEN << 1); + set32_fx( filt_coeff_arr_fx[i], 0, IVAS_BIQUAD_FILT_LEN << 1 ); #endif } - SWITCH ( sampling_rate ) + SWITCH( sampling_rate ) { #ifndef IVAS_FLOAT_FIXED case 48000: @@ -208,74 +208,74 @@ static void ivas_transient_det_init( hTranDet->out_duck_coeff = IVAS_C_OUT_DUCK_16k; break; #else - case 48000: - /*env_hpf*/ - filt_coeff_arr_fx[0][0] = IVAS_C_HPF_48k_fx; - filt_coeff_arr_fx[0][1] = -IVAS_C_HPF_48k_fx; - filt_coeff_arr_fx[0][3] = ONE_IN_Q30; - filt_coeff_arr_fx[0][4] = -IVAS_C_HPF_48k_fx; - - /*env_fast*/ - filt_coeff_arr_fx[1][0] = ONE_IN_Q30 - IVAS_C_FAST_48k_fx; - filt_coeff_arr_fx[1][3] = ONE_IN_Q30; - filt_coeff_arr_fx[1][4] = -IVAS_C_FAST_48k_fx; - - /*env_slow*/ - filt_coeff_arr_fx[2][0] = ONE_IN_Q30 - IVAS_C_SLOW_48k_fx; - filt_coeff_arr_fx[2][3] = ONE_IN_Q30; - filt_coeff_arr_fx[2][4] = -IVAS_C_SLOW_48k_fx; - - hTranDet->in_duck_coeff = IVAS_C_IN_DUCK_48k_fx; - hTranDet->out_duck_coeff = IVAS_C_OUT_DUCK_48k_fx; - - - BREAK; - case 32000: - /*env_hpf*/ - filt_coeff_arr_fx[0][0] = IVAS_C_HPF_32k_fx; - filt_coeff_arr_fx[0][1] = -IVAS_C_HPF_32k_fx; - filt_coeff_arr_fx[0][3] = ONE_IN_Q30; - filt_coeff_arr_fx[0][4] = -IVAS_C_HPF_32k_fx; - - /*env_fast*/ - filt_coeff_arr_fx[1][0] = ONE_IN_Q30 - IVAS_C_FAST_32k_fx; - filt_coeff_arr_fx[1][3] = ONE_IN_Q30; - filt_coeff_arr_fx[1][4] = -IVAS_C_FAST_32k_fx; - - - /*env_slow*/ - filt_coeff_arr_fx[2][0] = ONE_IN_Q30 - IVAS_C_SLOW_32k_fx; - filt_coeff_arr_fx[2][3] = ONE_IN_Q30; - filt_coeff_arr_fx[2][4] = -IVAS_C_SLOW_32k_fx; - hTranDet->in_duck_coeff = IVAS_C_IN_DUCK_32k_fx; - hTranDet->out_duck_coeff = IVAS_C_OUT_DUCK_32k_fx; - - - BREAK; - case 16000: - /*env_hpf*/ - filt_coeff_arr_fx[0][0] = IVAS_C_HPF_16k_fx; - filt_coeff_arr_fx[0][1] = -IVAS_C_HPF_16k_fx; - filt_coeff_arr_fx[0][3] = ONE_IN_Q30; - filt_coeff_arr_fx[0][4] = -IVAS_C_HPF_16k_fx; - - - /*env_fast*/ - filt_coeff_arr_fx[1][0] = ONE_IN_Q30 - IVAS_C_FAST_16k_fx; - filt_coeff_arr_fx[1][3] = ONE_IN_Q30; - filt_coeff_arr_fx[1][4] = -IVAS_C_FAST_16k_fx; - - - /*env_slow*/ - filt_coeff_arr_fx[2][0] = ONE_IN_Q30 - IVAS_C_SLOW_16k_fx; - filt_coeff_arr_fx[2][3] = ONE_IN_Q30; - filt_coeff_arr_fx[2][4] = -IVAS_C_SLOW_16k_fx; - - hTranDet->in_duck_coeff = IVAS_C_IN_DUCK_16k_fx; - hTranDet->out_duck_coeff = IVAS_C_OUT_DUCK_16k_fx; - - - BREAK; + case 48000: + /*env_hpf*/ + filt_coeff_arr_fx[0][0] = IVAS_C_HPF_48k_fx; + filt_coeff_arr_fx[0][1] = -IVAS_C_HPF_48k_fx; + filt_coeff_arr_fx[0][3] = ONE_IN_Q30; + filt_coeff_arr_fx[0][4] = -IVAS_C_HPF_48k_fx; + + /*env_fast*/ + filt_coeff_arr_fx[1][0] = ONE_IN_Q30 - IVAS_C_FAST_48k_fx; + filt_coeff_arr_fx[1][3] = ONE_IN_Q30; + filt_coeff_arr_fx[1][4] = -IVAS_C_FAST_48k_fx; + + /*env_slow*/ + filt_coeff_arr_fx[2][0] = ONE_IN_Q30 - IVAS_C_SLOW_48k_fx; + filt_coeff_arr_fx[2][3] = ONE_IN_Q30; + filt_coeff_arr_fx[2][4] = -IVAS_C_SLOW_48k_fx; + + hTranDet->in_duck_coeff = IVAS_C_IN_DUCK_48k_fx; + hTranDet->out_duck_coeff = IVAS_C_OUT_DUCK_48k_fx; + + + BREAK; + case 32000: + /*env_hpf*/ + filt_coeff_arr_fx[0][0] = IVAS_C_HPF_32k_fx; + filt_coeff_arr_fx[0][1] = -IVAS_C_HPF_32k_fx; + filt_coeff_arr_fx[0][3] = ONE_IN_Q30; + filt_coeff_arr_fx[0][4] = -IVAS_C_HPF_32k_fx; + + /*env_fast*/ + filt_coeff_arr_fx[1][0] = ONE_IN_Q30 - IVAS_C_FAST_32k_fx; + filt_coeff_arr_fx[1][3] = ONE_IN_Q30; + filt_coeff_arr_fx[1][4] = -IVAS_C_FAST_32k_fx; + + + /*env_slow*/ + filt_coeff_arr_fx[2][0] = ONE_IN_Q30 - IVAS_C_SLOW_32k_fx; + filt_coeff_arr_fx[2][3] = ONE_IN_Q30; + filt_coeff_arr_fx[2][4] = -IVAS_C_SLOW_32k_fx; + hTranDet->in_duck_coeff = IVAS_C_IN_DUCK_32k_fx; + hTranDet->out_duck_coeff = IVAS_C_OUT_DUCK_32k_fx; + + + BREAK; + case 16000: + /*env_hpf*/ + filt_coeff_arr_fx[0][0] = IVAS_C_HPF_16k_fx; + filt_coeff_arr_fx[0][1] = -IVAS_C_HPF_16k_fx; + filt_coeff_arr_fx[0][3] = ONE_IN_Q30; + filt_coeff_arr_fx[0][4] = -IVAS_C_HPF_16k_fx; + + + /*env_fast*/ + filt_coeff_arr_fx[1][0] = ONE_IN_Q30 - IVAS_C_FAST_16k_fx; + filt_coeff_arr_fx[1][3] = ONE_IN_Q30; + filt_coeff_arr_fx[1][4] = -IVAS_C_FAST_16k_fx; + + + /*env_slow*/ + filt_coeff_arr_fx[2][0] = ONE_IN_Q30 - IVAS_C_SLOW_16k_fx; + filt_coeff_arr_fx[2][3] = ONE_IN_Q30; + filt_coeff_arr_fx[2][4] = -IVAS_C_SLOW_16k_fx; + + hTranDet->in_duck_coeff = IVAS_C_IN_DUCK_16k_fx; + hTranDet->out_duck_coeff = IVAS_C_OUT_DUCK_16k_fx; + + + BREAK; #endif } @@ -284,9 +284,9 @@ static void ivas_transient_det_init( ivas_filters_init( &hTranDet->env_fast, (const float *) filt_coeff_arr[1], IVAS_FILTER_ORDER_1 ); ivas_filters_init( &hTranDet->env_slow, (const float *) filt_coeff_arr[2], IVAS_FILTER_ORDER_1 ); #else - ivas_filters_init_fx(&hTranDet->env_hpf, (const Word32 *)filt_coeff_arr_fx[0], IVAS_FILTER_ORDER_1); - ivas_filters_init_fx(&hTranDet->env_fast, (const Word32 *)filt_coeff_arr_fx[1], IVAS_FILTER_ORDER_1); - ivas_filters_init_fx(&hTranDet->env_slow, (const Word32 *)filt_coeff_arr_fx[2], IVAS_FILTER_ORDER_1); + ivas_filters_init_fx( &hTranDet->env_hpf, (const Word32 *) filt_coeff_arr_fx[0], IVAS_FILTER_ORDER_1 ); + ivas_filters_init_fx( &hTranDet->env_fast, (const Word32 *) filt_coeff_arr_fx[1], IVAS_FILTER_ORDER_1 ); + ivas_filters_init_fx( &hTranDet->env_slow, (const Word32 *) filt_coeff_arr_fx[2], IVAS_FILTER_ORDER_1 ); #endif @@ -575,24 +575,25 @@ void ivas_td_decorr_get_ducking_gains_fx( mvl2l( pIn_pcm, e_fast_fx, frame_len ); /* env hpf */ - ivas_filter_process_fx( &hTranDet->env_hpf, e_fast_fx, frame_len, q); + ivas_filter_process_fx( &hTranDet->env_hpf, e_fast_fx, frame_len, q ); - Word16 q_factor_diff = sub(31, q); + Word16 q_factor_diff = sub( 31, q ); - FOR (i = 0; i < frame_len; i++) { - e_fast_fx[i] = L_add(L_abs(e_fast_fx[i]), L_shr(IVAS_TDET_PARM_ENV_EPS_fx, q_factor_diff)); + FOR( i = 0; i < frame_len; i++ ) + { + e_fast_fx[i] = L_add( L_abs( e_fast_fx[i] ), L_shr( IVAS_TDET_PARM_ENV_EPS_fx, q_factor_diff ) ); e_slow_fx[i] = e_fast_fx[i]; } /* env fast*/ - ivas_filter_process_fx(&hTranDet->env_fast, e_fast_fx, frame_len, q); + ivas_filter_process_fx( &hTranDet->env_fast, e_fast_fx, frame_len, q ); /* env slow */ - ivas_filter_process_fx(&hTranDet->env_slow, e_slow_fx, frame_len, q); + ivas_filter_process_fx( &hTranDet->env_slow, e_slow_fx, frame_len, q ); - IF ( tdet_flag ) + IF( tdet_flag ) { - FOR ( i = 0; i < frame_len; i++ ) + FOR( i = 0; i < frame_len; i++ ) { in_duck_gain = ivas_calc_duck_gain_fx( in_duck_gain, in_duck_coeff, e_slow_fx[i], e_fast_fx[i], duck_mult_fac ); pIn_duck_gains[i] = in_duck_gain; @@ -601,7 +602,7 @@ void ivas_td_decorr_get_ducking_gains_fx( } ELSE { - FOR ( i = 0; i < frame_len; i++ ) + FOR( i = 0; i < frame_len; i++ ) { in_duck_gain = ivas_calc_duck_gain_fx( in_duck_gain, in_duck_coeff, e_slow_fx[i], e_fast_fx[i], duck_mult_fac ); pIn_duck_gains[i] = in_duck_gain; @@ -614,4 +615,4 @@ void ivas_td_decorr_get_ducking_gains_fx( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_com/lag_wind.c b/lib_com/lag_wind.c index 53cbcd97b..e7fe28882 100644 --- a/lib_com/lag_wind.c +++ b/lib_com/lag_wind.c @@ -176,162 +176,160 @@ void adapt_lag_wind_fx( *-------------------------------------------------------------*/ void lag_wind( - Word16 r_h[], /* in/out: autocorrelations */ - Word16 r_l[], /* in/out: autocorrelations */ - Word16 m, /* input : order of LP filter */ - Word32 sr_core, /* input : sampling rate */ - Word16 strength /* input : LAGW_WEAK, LAGW_MEDIUM, or LAGW_STRONG */ + Word16 r_h[], /* in/out: autocorrelations */ + Word16 r_l[], /* in/out: autocorrelations */ + Word16 m, /* input : order of LP filter */ + Word32 sr_core, /* input : sampling rate */ + Word16 strength /* input : LAGW_WEAK, LAGW_MEDIUM, or LAGW_STRONG */ ) { - Word16 i; - Word32 tmp; - const Word16 *wnd_h, *wnd_l; + Word16 i; + Word32 tmp; + const Word16 *wnd_h, *wnd_l; - assert(0 <= strength && strength <= NUM_LAGW_STRENGTHS); - SWITCH(sr_core) - { + assert( 0 <= strength && strength <= NUM_LAGW_STRENGTHS ); + SWITCH( sr_core ) + { case 8000: - assert(m <= 16); - assert(strength == LAGW_STRONG); - wnd_h = lag_window_8k[0]; - wnd_l = lag_window_8k[1]; - BREAK; + assert( m <= 16 ); + assert( strength == LAGW_STRONG ); + wnd_h = lag_window_8k[0]; + wnd_l = lag_window_8k[1]; + BREAK; case 12800: - assert(m <= 16); - wnd_h = lag_window_12k8[strength][0]; - wnd_l = lag_window_12k8[strength][1]; - BREAK; + assert( m <= 16 ); + wnd_h = lag_window_12k8[strength][0]; + wnd_l = lag_window_12k8[strength][1]; + BREAK; case 16000: - assert(m <= 16); - wnd_h = lag_window_16k[strength][0]; - wnd_l = lag_window_16k[strength][1]; - BREAK; + assert( m <= 16 ); + wnd_h = lag_window_16k[strength][0]; + wnd_l = lag_window_16k[strength][1]; + BREAK; case 24000: case 25600: - assert(m <= 16); - wnd_h = lag_window_25k6[strength][0]; - wnd_l = lag_window_25k6[strength][1]; - BREAK; + assert( m <= 16 ); + wnd_h = lag_window_25k6[strength][0]; + wnd_l = lag_window_25k6[strength][1]; + BREAK; case 32000: - assert(m <= 16); - wnd_h = lag_window_32k[strength][0]; - wnd_l = lag_window_32k[strength][1]; - BREAK; + assert( m <= 16 ); + wnd_h = lag_window_32k[strength][0]; + wnd_l = lag_window_32k[strength][1]; + BREAK; case 48000: - assert(m <= 16); - assert(strength == LAGW_STRONG); - wnd_h = lag_window_48k[0]; - wnd_l = lag_window_48k[1]; - BREAK; + assert( m <= 16 ); + assert( strength == LAGW_STRONG ); + wnd_h = lag_window_48k[0]; + wnd_l = lag_window_48k[1]; + BREAK; default: - assert(!"Lag window not implemented for this sampling rate"); - return; - } - - FOR(i = 1; i <= m; i++) - { - tmp = Mpy_32(r_h[i], r_l[i], wnd_h[i - 1], wnd_l[i - 1]); - L_Extract(tmp, &r_h[i], &r_l[i]); - } + assert( !"Lag window not implemented for this sampling rate" ); + return; + } + FOR( i = 1; i <= m; i++ ) + { + tmp = Mpy_32( r_h[i], r_l[i], wnd_h[i - 1], wnd_l[i - 1] ); + L_Extract( tmp, &r_h[i], &r_l[i] ); + } } void lag_wind_32( - Word32 r[], /* in/out: autocorrelations */ - Word16 m, /* input : order of LP filter */ - Word32 sr_core, /* input : sampling rate */ - Word16 strength /* input : LAGW_WEAK, LAGW_MEDIUM, or LAGW_STRONG */ + Word32 r[], /* in/out: autocorrelations */ + Word16 m, /* input : order of LP filter */ + Word32 sr_core, /* input : sampling rate */ + Word16 strength /* input : LAGW_WEAK, LAGW_MEDIUM, or LAGW_STRONG */ ) { - Word16 i; - const Word32* wnd; + Word16 i; + const Word32 *wnd; - assert(0 <= strength && strength <= NUM_LAGW_STRENGTHS); - SWITCH(sr_core) - { + assert( 0 <= strength && strength <= NUM_LAGW_STRENGTHS ); + SWITCH( sr_core ) + { case 8000: - assert(m <= 16); - assert(strength == LAGW_STRONG); - wnd = lag_window_8k_32; - BREAK; + assert( m <= 16 ); + assert( strength == LAGW_STRONG ); + wnd = lag_window_8k_32; + BREAK; case 12800: - assert(m <= 16); - wnd = lag_window_12k8_32[strength]; - BREAK; + assert( m <= 16 ); + wnd = lag_window_12k8_32[strength]; + BREAK; case 16000: - assert(m <= 16); - wnd = lag_window_16k_32[strength]; - BREAK; + assert( m <= 16 ); + wnd = lag_window_16k_32[strength]; + BREAK; case 24000: case 25600: - assert(m <= 16); - wnd = lag_window_25k6_32[strength]; - BREAK; + assert( m <= 16 ); + wnd = lag_window_25k6_32[strength]; + BREAK; case 32000: - assert(m <= 16); - wnd = lag_window_32k_32[strength]; - BREAK; + assert( m <= 16 ); + wnd = lag_window_32k_32[strength]; + BREAK; case 48000: - assert(m <= 16); - assert(strength == LAGW_STRONG); - wnd = lag_window_48k_32; - BREAK; + assert( m <= 16 ); + assert( strength == LAGW_STRONG ); + wnd = lag_window_48k_32; + BREAK; default: - assert(!"Lag window not implemented for this sampling rate"); - return; - } - - FOR(i = 1; i <= m; i++) - { - r[i] = Mpy_32_32(r[i], wnd[i - 1]); - } + assert( !"Lag window not implemented for this sampling rate" ); + return; + } + FOR( i = 1; i <= m; i++ ) + { + r[i] = Mpy_32_32( r[i], wnd[i - 1] ); + } } void adapt_lag_wind( - Word16 r_h[], /* in/out: autocorrelations */ - Word16 r_l[], /* in/out: autocorrelations */ - Word16 m, /* input : order of LP filter */ - const Word16 Top, /* input : open loop pitch lag */ - const Word16 Tnc, /* input : open loop pitch gain */ - Word32 sr_core /* input : sampling rate */ + Word16 r_h[], /* in/out: autocorrelations */ + Word16 r_l[], /* in/out: autocorrelations */ + Word16 m, /* input : order of LP filter */ + const Word16 Top, /* input : open loop pitch lag */ + const Word16 Tnc, /* input : open loop pitch gain */ + Word32 sr_core /* input : sampling rate */ ) { - Word16 strength, pitch_lag; - Word16 pitch_gain; + Word16 strength, pitch_lag; + Word16 pitch_gain; - pitch_lag = Top; - move16(); - pitch_gain = Tnc; - move16(); - - IF(LT_16(pitch_lag, 80)) - { - strength = LAGW_STRONG; + pitch_lag = Top; + move16(); + pitch_gain = Tnc; move16(); - if (LE_16(pitch_gain, kLagWinThGain1)) + + IF( LT_16( pitch_lag, 80 ) ) { - strength = LAGW_MEDIUM; - move16(); + strength = LAGW_STRONG; + move16(); + if ( LE_16( pitch_gain, kLagWinThGain1 ) ) + { + strength = LAGW_MEDIUM; + move16(); + } } - } - ELSE IF(LT_16(pitch_lag, 160)) - { - strength = LAGW_MEDIUM; - move16(); - if (LE_16(pitch_gain, kLagWinThGain2)) + ELSE IF( LT_16( pitch_lag, 160 ) ) { - strength = LAGW_WEAK; - move16(); + strength = LAGW_MEDIUM; + move16(); + if ( LE_16( pitch_gain, kLagWinThGain2 ) ) + { + strength = LAGW_WEAK; + move16(); + } } - } - ELSE - { - strength = LAGW_WEAK; - move16(); - } - - lag_wind(r_h, r_l, m, sr_core, strength); + ELSE + { + strength = LAGW_WEAK; + move16(); + } + + lag_wind( r_h, r_l, m, sr_core, strength ); } diff --git a/lib_com/lerp.c b/lib_com/lerp.c index 5bbc1b1c4..b559650fc 100644 --- a/lib_com/lerp.c +++ b/lib_com/lerp.c @@ -189,13 +189,13 @@ static void lerp_proc_flt( * Local constants *-------------------------------------------------------------*/ -#define shift_e (16-1) -#define pos_e (16-1) - /*-------------------------------------------------------------* - * Local function prototypes - *-------------------------------------------------------------*/ +#define shift_e ( 16 - 1 ) +#define pos_e ( 16 - 1 ) +/*-------------------------------------------------------------* + * Local function prototypes + *-------------------------------------------------------------*/ -static void lerp_proc(const Word16 *f, Word16 *f_out, Word16 bufferNewSize, Word16 bufferOldSize); +static void lerp_proc( const Word16 *f, Word16 *f_out, Word16 bufferNewSize, Word16 bufferOldSize ); /*-------------------------------------------------------------* * procedure lerp() * @@ -203,63 +203,63 @@ static void lerp_proc(const Word16 *f, Word16 *f_out, Word16 bufferNewSize, Word * * *-------------------------------------------------------------*/ -void lerp(const Word16 *f, Word16 *f_out, Word16 bufferNewSize, Word16 bufferOldSize) +void lerp( const Word16 *f, Word16 *f_out, Word16 bufferNewSize, Word16 bufferOldSize ) { - Word16 tmp1, tmp2, tmpexp; - BASOP_Util_Divide_MantExp(bufferNewSize, 0, bufferOldSize, 0, &tmp1, &tmpexp); - tmp1 = shr(tmp1, 3); /*Q12*/ - tmp1 = shl(tmp1, tmpexp); - - BASOP_Util_Divide_MantExp(bufferOldSize, 0, bufferNewSize, 0, &tmp2, &tmpexp); - tmp2 = shr(tmp2, 3); /*Q12*/ - tmp2 = shl(tmp2, tmpexp); - test(); - test(); - IF(GT_16(tmp1, 16224 /*3,9609375 in Q12*/)) - { - Word16 tmpNewSize = shl(bufferOldSize, 1); - WHILE(GT_16(bufferNewSize, bufferOldSize)) - { - BASOP_Util_Divide_MantExp(bufferNewSize, 0, bufferOldSize, 0, &tmp1, &tmpexp); - tmp1 = shr(tmp1, 3); /*Q12*/ - tmp1 = shl(tmp1, tmpexp); - test(); - IF(LE_16(tmp1, 16224 /*3,9609375 in Q12*/)) - { - tmpNewSize = bufferNewSize; - } - - lerp_proc(f, f_out, tmpNewSize, bufferOldSize); - - f = f_out; - bufferOldSize = tmpNewSize; - tmpNewSize = shl(tmpNewSize, 1); - } - } - ELSE IF(GT_16(tmp2, 16224 /*3,9609375 in Q12*/)) - { - Word16 tmpNewSize = shr(bufferOldSize, 1); - WHILE(LT_16(bufferNewSize, bufferOldSize)) - { - BASOP_Util_Divide_MantExp(bufferOldSize, 0, bufferNewSize, 0, &tmp2, &tmpexp); - tmp2 = shr(tmp2, 3); /*Q12*/ - tmp2 = shl(tmp2, tmpexp); - test(); - IF(LE_16(tmp2, 16224 /*3,9609375 in Q12*/)) - { - tmpNewSize = bufferNewSize; - } - - lerp_proc(f, f_out, tmpNewSize, bufferOldSize); - - f = f_out; - bufferOldSize = tmpNewSize; - tmpNewSize = shr(tmpNewSize, 1); - } - } + Word16 tmp1, tmp2, tmpexp; + BASOP_Util_Divide_MantExp( bufferNewSize, 0, bufferOldSize, 0, &tmp1, &tmpexp ); + tmp1 = shr( tmp1, 3 ); /*Q12*/ + tmp1 = shl( tmp1, tmpexp ); + + BASOP_Util_Divide_MantExp( bufferOldSize, 0, bufferNewSize, 0, &tmp2, &tmpexp ); + tmp2 = shr( tmp2, 3 ); /*Q12*/ + tmp2 = shl( tmp2, tmpexp ); + test(); + test(); + IF( GT_16( tmp1, 16224 /*3,9609375 in Q12*/ ) ) + { + Word16 tmpNewSize = shl( bufferOldSize, 1 ); + WHILE( GT_16( bufferNewSize, bufferOldSize ) ) + { + BASOP_Util_Divide_MantExp( bufferNewSize, 0, bufferOldSize, 0, &tmp1, &tmpexp ); + tmp1 = shr( tmp1, 3 ); /*Q12*/ + tmp1 = shl( tmp1, tmpexp ); + test(); + IF( LE_16( tmp1, 16224 /*3,9609375 in Q12*/ ) ) + { + tmpNewSize = bufferNewSize; + } + + lerp_proc( f, f_out, tmpNewSize, bufferOldSize ); + + f = f_out; + bufferOldSize = tmpNewSize; + tmpNewSize = shl( tmpNewSize, 1 ); + } + } + ELSE IF( GT_16( tmp2, 16224 /*3,9609375 in Q12*/ ) ) + { + Word16 tmpNewSize = shr( bufferOldSize, 1 ); + WHILE( LT_16( bufferNewSize, bufferOldSize ) ) + { + BASOP_Util_Divide_MantExp( bufferOldSize, 0, bufferNewSize, 0, &tmp2, &tmpexp ); + tmp2 = shr( tmp2, 3 ); /*Q12*/ + tmp2 = shl( tmp2, tmpexp ); + test(); + IF( LE_16( tmp2, 16224 /*3,9609375 in Q12*/ ) ) + { + tmpNewSize = bufferNewSize; + } + + lerp_proc( f, f_out, tmpNewSize, bufferOldSize ); + + f = f_out; + bufferOldSize = tmpNewSize; + tmpNewSize = shr( tmpNewSize, 1 ); + } + } else { - lerp_proc(f, f_out, bufferNewSize, bufferOldSize); + lerp_proc( f, f_out, bufferNewSize, bufferOldSize ); } } /*-------------------------------------------------------------* @@ -267,217 +267,214 @@ void lerp(const Word16 *f, Word16 *f_out, Word16 bufferNewSize, Word16 bufferOld * * * * *-------------------------------------------------------------*/ -static void lerp_proc(const Word16 *f, Word16 *f_out, Word16 bufferNewSize, Word16 bufferOldSize) +static void lerp_proc( const Word16 *f, Word16 *f_out, Word16 bufferNewSize, Word16 bufferOldSize ) { - Word16 i, idx, n; - Word16 diff; - Word32 pos, shift; - Word16 buf[2 * L_FRAME_MAX]; - Word16 *ptr; - - ptr = f_out; - test(); - test(); - test(); - if (((f <= f_out) && (f + bufferOldSize >= f_out)) || ((f_out <= f) && (f_out + bufferNewSize >= f))) - { - ptr = buf; - move16(); - } + Word16 i, idx, n; + Word16 diff; + Word32 pos, shift; + Word16 buf[2 * L_FRAME_MAX]; + Word16 *ptr; + + ptr = f_out; + test(); + test(); + test(); + if ( ( ( f <= f_out ) && ( f + bufferOldSize >= f_out ) ) || ( ( f_out <= f ) && ( f_out + bufferNewSize >= f ) ) ) + { + ptr = buf; + move16(); + } - IF(EQ_16(bufferNewSize, bufferOldSize)) - { - Copy(f, f_out, bufferNewSize); - return; - } + IF( EQ_16( bufferNewSize, bufferOldSize ) ) + { + Copy( f, f_out, bufferNewSize ); + return; + } - shift = L_shl(L_deposit_l(div_s(bufferOldSize, shl(bufferNewSize, 4))), 4 - shift_e + 16); + shift = L_shl( L_deposit_l( div_s( bufferOldSize, shl( bufferNewSize, 4 ) ) ), 4 - shift_e + 16 ); - pos = L_sub(L_shr(shift, 1), 32768l/*1.0f Q15*/); + pos = L_sub( L_shr( shift, 1 ), 32768l /*1.0f Q15*/ ); - /* Adjust interpolation shift to avoid accessing beyond end of input buffer. */ - if (LT_32(shift, 19661l/*0.3f Q16*/)) - { - pos = L_sub(pos, 8520l/*0.13f Q16*/); - } + /* Adjust interpolation shift to avoid accessing beyond end of input buffer. */ + if ( LT_32( shift, 19661l /*0.3f Q16*/ ) ) + { + pos = L_sub( pos, 8520l /*0.13f Q16*/ ); + } - assert(pos_e == shift_e); + assert( pos_e == shift_e ); - /* first point of interpolation */ - IF(pos < 0) - { + /* first point of interpolation */ + IF( pos < 0 ) + { - diff = shr(extract_l(pos), 1); - /*buf[0]=f[0]+pos*(f[1]-f[0]);*/ - move16(); + diff = shr( extract_l( pos ), 1 ); + /*buf[0]=f[0]+pos*(f[1]-f[0]);*/ + move16(); #ifdef BASOP_NOGLOB - *ptr++ = add_sat(f[0], msu_r(L_mult(diff, f[1]), diff, f[0])); + *ptr++ = add_sat( f[0], msu_r( L_mult( diff, f[1] ), diff, f[0] ) ); #else - *ptr++ = add(f[0], msu_r(L_mult(diff, f[1]), diff, f[0])); + *ptr++ = add( f[0], msu_r( L_mult( diff, f[1] ), diff, f[0] ) ); #endif - } - ELSE - { + } + ELSE + { - idx = extract_h(pos); + idx = extract_h( pos ); - diff = lshr(extract_l(pos), 1); + diff = lshr( extract_l( pos ), 1 ); - move16(); + move16(); #ifdef BASOP_NOGLOB - *ptr++ = add_sat(f[idx], msu_r_sat(L_mult(diff, f[idx + 1]), diff, f[idx])); + *ptr++ = add_sat( f[idx], msu_r_sat( L_mult( diff, f[idx + 1] ), diff, f[idx] ) ); #else - *ptr++ = add(f[idx], msu_r(L_mult(diff, f[idx + 1]), diff, f[idx])); + *ptr++ = add( f[idx], msu_r( L_mult( diff, f[idx + 1] ), diff, f[idx] ) ); #endif - } + } - pos = L_add(pos, shift); - idx = s_max(0, extract_h(pos)); + pos = L_add( pos, shift ); + idx = s_max( 0, extract_h( pos ) ); - n = sub(bufferNewSize, 1); - FOR(i = 1; i < n; i++) - { - diff = lshr(extract_l(pos), 1); - if (pos < 0) + n = sub( bufferNewSize, 1 ); + FOR( i = 1; i < n; i++ ) { - diff = sub(16384/*0.5f Q15*/, diff); - } - move16(); + diff = lshr( extract_l( pos ), 1 ); + if ( pos < 0 ) + { + diff = sub( 16384 /*0.5f Q15*/, diff ); + } + move16(); #ifdef BASOP_NOGLOB - *ptr++ = add_sat(f[idx], msu_r_sat(L_mult(diff, f[idx + 1]), diff, f[idx])); -#else - *ptr++ = add(f[idx], msu_r(L_mult(diff, f[idx + 1]), diff, f[idx])); + *ptr++ = add_sat( f[idx], msu_r_sat( L_mult( diff, f[idx + 1] ), diff, f[idx] ) ); +#else + *ptr++ = add( f[idx], msu_r( L_mult( diff, f[idx + 1] ), diff, f[idx] ) ); #endif + pos = L_add( pos, shift ); + idx = extract_h( pos ); + } - pos = L_add(pos, shift); - idx = extract_h(pos); - } - - /* last point */ + /* last point */ - if (GT_32(pos, L_deposit_h(sub(bufferOldSize, 1)))) - { - idx = sub(bufferOldSize, 2); - } - assert(idx <= 2 * L_FRAME_MAX); + if ( GT_32( pos, L_deposit_h( sub( bufferOldSize, 1 ) ) ) ) + { + idx = sub( bufferOldSize, 2 ); + } + assert( idx <= 2 * L_FRAME_MAX ); - /* diff = t - point;*/ - diff = lshr(extract_l(L_shr(L_sub(pos, L_deposit_h(idx)), 1)), 1); + /* diff = t - point;*/ + diff = lshr( extract_l( L_shr( L_sub( pos, L_deposit_h( idx ) ), 1 ) ), 1 ); - move16(); + move16(); #ifdef BASOP_NOGLOB - *ptr++ = add_sat(f[idx], shl_sat(msu_r_sat(L_mult(diff, f[idx + 1]), diff, f[idx]), 1)); + *ptr++ = add_sat( f[idx], shl_sat( msu_r_sat( L_mult( diff, f[idx + 1] ), diff, f[idx] ), 1 ) ); #else - *ptr++ = add(f[idx], shl(msu_r(L_mult(diff, f[idx + 1]), diff, f[idx]), 1)); + *ptr++ = add( f[idx], shl( msu_r( L_mult( diff, f[idx + 1] ), diff, f[idx] ), 1 ) ); #endif - test(); - test(); - test(); - IF(((f <= f_out) && (f + bufferOldSize >= f_out)) || ((f_out <= f) && (f_out + bufferNewSize >= f))) - { - Copy(buf, f_out, bufferNewSize); - } - + test(); + test(); + test(); + IF( ( ( f <= f_out ) && ( f + bufferOldSize >= f_out ) ) || ( ( f_out <= f ) && ( f_out + bufferNewSize >= f ) ) ) + { + Copy( buf, f_out, bufferNewSize ); + } } #ifdef IVAS_FLOAT_FIXED -static void lerp_proc32(Word32 *f, Word32 *f_out, Word16 bufferNewSize, Word16 bufferOldSize) +static void lerp_proc32( Word32 *f, Word32 *f_out, Word16 bufferNewSize, Word16 bufferOldSize ) { - Word16 i, idx, n; - Word16 diff; - Word32 pos, shift; - Word32 buf[2 * L_FRAME_MAX]; - Word32 *ptr; - - ptr = f_out; - test(); - test(); - test(); - IF (((f <= f_out) && (f + bufferOldSize >= f_out)) || ((f_out <= f) && (f_out + bufferNewSize >= f))) - { - ptr = buf; - move16(); - } + Word16 i, idx, n; + Word16 diff; + Word32 pos, shift; + Word32 buf[2 * L_FRAME_MAX]; + Word32 *ptr; + + ptr = f_out; + test(); + test(); + test(); + IF( ( ( f <= f_out ) && ( f + bufferOldSize >= f_out ) ) || ( ( f_out <= f ) && ( f_out + bufferNewSize >= f ) ) ) + { + ptr = buf; + move16(); + } - IF(EQ_16(bufferNewSize, bufferOldSize)) - { - Copy32(f, f_out, bufferNewSize); - return; - } + IF( EQ_16( bufferNewSize, bufferOldSize ) ) + { + Copy32( f, f_out, bufferNewSize ); + return; + } + + shift = L_shl( L_deposit_l( div_s( bufferOldSize, shl( bufferNewSize, 4 ) ) ), 4 - shift_e + 16 ); - shift = L_shl(L_deposit_l(div_s(bufferOldSize, shl(bufferNewSize, 4))), 4 - shift_e + 16); + pos = L_sub( L_shr( shift, 1 ), 32768l /*1.0f Q15*/ ); - pos = L_sub(L_shr(shift, 1), 32768l/*1.0f Q15*/); + /* Adjust interpolation shift to avoid accessing beyond end of input buffer. */ + if ( LT_32( shift, 19661l /*0.3f Q16*/ ) ) + { + pos = L_sub( pos, 8520l /*0.13f Q16*/ ); + } - /* Adjust interpolation shift to avoid accessing beyond end of input buffer. */ - if (LT_32(shift, 19661l/*0.3f Q16*/)) - { - pos = L_sub(pos, 8520l/*0.13f Q16*/); - } + assert( pos_e == shift_e ); - assert(pos_e == shift_e); + /* first point of interpolation */ + IF( pos < 0 ) + { - /* first point of interpolation */ - IF(pos < 0) - { + diff = shr( extract_l( pos ), 1 ); + /*buf[0]=f[0]+pos*(f[1]-f[0]);*/ + move16(); + *ptr++ = L_add_sat( f[0], Mpy_32_16_1( L_sub( f[1], f[0] ), diff ) ); + } + ELSE + { - diff = shr(extract_l(pos), 1); - /*buf[0]=f[0]+pos*(f[1]-f[0]);*/ - move16(); - *ptr++ = L_add_sat(f[0], Mpy_32_16_1(L_sub(f[1], f[0]), diff)); - } - ELSE - { + idx = extract_h( pos ); + diff = lshr( extract_l( pos ), 1 ); + move16(); + *ptr++ = L_add_sat( f[idx], Mpy_32_16_1( L_sub( f[idx + 1], f[idx] ), diff ) ); + } - idx = extract_h(pos); - diff = lshr(extract_l(pos), 1); - move16(); - *ptr++ = L_add_sat(f[idx], Mpy_32_16_1(L_sub(f[idx + 1], f[idx]), diff)); - } + pos = L_add( pos, shift ); + idx = s_max( 0, extract_h( pos ) ); - pos = L_add(pos, shift); - idx = s_max(0, extract_h(pos)); + n = sub( bufferNewSize, 1 ); + FOR( i = 1; i < n; i++ ) + { + diff = lshr( extract_l( pos ), 1 ); + IF( LT_32( pos, 0 ) ) + { + diff = sub( 16384 /*0.5f Q15*/, diff ); + } + move16(); + *ptr++ = L_add_sat( f[idx], Mpy_32_16_1( L_sub( f[idx + 1], f[idx] ), diff ) ); + pos = L_add( pos, shift ); + idx = extract_h( pos ); + } - n = sub(bufferNewSize, 1); - FOR(i = 1; i < n; i++) - { - diff = lshr(extract_l(pos), 1); - IF (LT_32(pos , 0)) + /* last point */ + + IF( GT_32( pos, L_deposit_h( sub( bufferOldSize, 1 ) ) ) ) { - diff = sub(16384/*0.5f Q15*/, diff); + idx = sub( bufferOldSize, 2 ); } - move16(); - *ptr++ = L_add_sat(f[idx], Mpy_32_16_1(L_sub(f[idx + 1], f[idx]), diff)); - pos = L_add(pos, shift); - idx = extract_h(pos); - } - - /* last point */ - - IF (GT_32(pos, L_deposit_h(sub(bufferOldSize, 1)))) - { - idx = sub(bufferOldSize, 2); - } - assert(idx <= 2 * L_FRAME_MAX); - - /* diff = t - point;*/ - diff = lshr(extract_l(L_shr(L_sub(pos, L_deposit_h(idx)), 1)), 1); - - move16(); - *ptr++ = L_add_sat(f[idx], L_shl_sat(Mpy_32_16_1(L_sub(f[idx + 1], f[idx]), diff), 1)); - test(); - test(); - test(); - IF(((f <= f_out) && (f + bufferOldSize >= f_out)) || ((f_out <= f) && (f_out + bufferNewSize >= f))) - { - Copy32(buf, f_out, bufferNewSize); - } + assert( idx <= 2 * L_FRAME_MAX ); + /* diff = t - point;*/ + diff = lshr( extract_l( L_shr( L_sub( pos, L_deposit_h( idx ) ), 1 ) ), 1 ); + + move16(); + *ptr++ = L_add_sat( f[idx], L_shl_sat( Mpy_32_16_1( L_sub( f[idx + 1], f[idx] ), diff ), 1 ) ); + test(); + test(); + test(); + IF( ( ( f <= f_out ) && ( f + bufferOldSize >= f_out ) ) || ( ( f_out <= f ) && ( f_out + bufferNewSize >= f ) ) ) + { + Copy32( buf, f_out, bufferNewSize ); + } } @@ -492,20 +489,22 @@ static void L_lerp_proc_fx( const Word32 *f_fx, Word32 *f_out_fx, const Word16 b void L_lerp_fx( Word32 *f, Word32 *f_out, Word16 bufferNewSize, Word16 bufferOldSize, Word16 *q ) { Word16 tmpNewSize; - Word16 guard_bits = s_max(find_guarded_bits_fx(bufferNewSize / bufferOldSize), find_guarded_bits_fx(bufferOldSize / bufferNewSize)) + 1; - IF (getScaleFactor32(f, bufferOldSize) < guard_bits) + Word16 guard_bits = s_max( find_guarded_bits_fx( bufferNewSize / bufferOldSize ), find_guarded_bits_fx( bufferOldSize / bufferNewSize ) ) + 1; + IF( getScaleFactor32( f, bufferOldSize ) < guard_bits ) { *q -= guard_bits; - FOR(Word16 ind = 0; ind < bufferNewSize; ind++) f[ind] = L_shr(f[ind], guard_bits); - FOR(Word16 ind = 0; ind < bufferNewSize; ind++) f_out[ind] = L_shr(f_out[ind], guard_bits); + FOR( Word16 ind = 0; ind < bufferNewSize; ind++ ) + f[ind] = L_shr( f[ind], guard_bits ); + FOR( Word16 ind = 0; ind < bufferNewSize; ind++ ) + f_out[ind] = L_shr( f_out[ind], guard_bits ); } - IF ( 128 * bufferNewSize > bufferOldSize * 507 ) + IF( 128 * bufferNewSize > bufferOldSize * 507 ) { tmpNewSize = bufferOldSize * 2; - WHILE ( bufferNewSize > bufferOldSize ) + WHILE( bufferNewSize > bufferOldSize ) { - IF ( 128 * bufferNewSize <= 507 * bufferOldSize ) + IF( 128 * bufferNewSize <= 507 * bufferOldSize ) { tmpNewSize = bufferNewSize; } @@ -517,12 +516,12 @@ void L_lerp_fx( Word32 *f, Word32 *f_out, Word16 bufferNewSize, Word16 bufferOld tmpNewSize *= 2; } } - ELSE IF ( 128 * bufferOldSize > bufferNewSize * 507 ) + ELSE IF( 128 * bufferOldSize > bufferNewSize * 507 ) { tmpNewSize = bufferOldSize / 2; - WHILE ( bufferNewSize < bufferOldSize ) + WHILE( bufferNewSize < bufferOldSize ) { - IF ( 128 * bufferOldSize <= 507 * bufferNewSize ) + IF( 128 * bufferOldSize <= 507 * bufferNewSize ) { tmpNewSize = bufferNewSize; } @@ -545,12 +544,12 @@ void L_lerp_fx_q11( Word32 *f, Word32 *f_out, Word16 bufferNewSize, Word16 buffe { Word16 tmpNewSize; - IF ( 128 * bufferNewSize > bufferOldSize * 507 ) + IF( 128 * bufferNewSize > bufferOldSize * 507 ) { tmpNewSize = bufferOldSize * 2; - WHILE ( bufferNewSize > bufferOldSize ) + WHILE( bufferNewSize > bufferOldSize ) { - IF ( 128 * bufferNewSize <= 507 * bufferOldSize ) + IF( 128 * bufferNewSize <= 507 * bufferOldSize ) { tmpNewSize = bufferNewSize; } @@ -562,12 +561,12 @@ void L_lerp_fx_q11( Word32 *f, Word32 *f_out, Word16 bufferNewSize, Word16 buffe tmpNewSize *= 2; } } - ELSE IF ( 128 * bufferOldSize > bufferNewSize * 507 ) + ELSE IF( 128 * bufferOldSize > bufferNewSize * 507 ) { tmpNewSize = bufferOldSize / 2; - WHILE ( bufferNewSize < bufferOldSize ) + WHILE( bufferNewSize < bufferOldSize ) { - IF ( 128 * bufferOldSize <= 507 * bufferNewSize ) + IF( 128 * bufferOldSize <= 507 * bufferNewSize ) { tmpNewSize = bufferNewSize; } @@ -581,7 +580,7 @@ void L_lerp_fx_q11( Word32 *f, Word32 *f_out, Word16 bufferNewSize, Word16 buffe } ELSE { - lerp_proc32(f, f_out, bufferNewSize, bufferOldSize); + lerp_proc32( f, f_out, bufferNewSize, bufferOldSize ); } return; @@ -596,15 +595,14 @@ static void L_lerp_proc_fx( const Word32 *f_fx, Word32 *f_out_fx, const Word16 bufferNewSize, - const Word16 bufferOldSize -) + const Word16 bufferOldSize ) { Word16 i, idx; Word32 pos_fx, shift_fx, diff_fx; Word32 buf_fx[2 * L_FRAME_MAX]; Word16 tmp; - IF ( bufferNewSize == bufferOldSize ) + IF( bufferNewSize == bufferOldSize ) { Copy32( f_fx, buf_fx, bufferNewSize ); Copy32( buf_fx, f_out_fx, bufferNewSize ); @@ -616,13 +614,13 @@ static void L_lerp_proc_fx( shift_fx = L_shl( L_deposit_l( tmp ), 4 - 15 + 21 ); // q =21 pos_fx = Mpy_32_32( L_sub( shift_fx, 1 << 21 ), 1073741824 ); - IF ( shift_fx < L_shr( 644245094, 31 - 21 ) ) + IF( shift_fx < L_shr( 644245094, 31 - 21 ) ) { pos_fx = L_sub( pos_fx, L_shr( 279172874, 31 - 21 ) ); } /* first point of interpolation */ - IF ( pos_fx < 0 ) + IF( pos_fx < 0 ) { buf_fx[0] = L_add( f_fx[0], L_shl( Mpy_32_32( pos_fx, L_sub( f_fx[1], f_fx[0] ) ), 31 - 21 ) ); } @@ -635,7 +633,7 @@ static void L_lerp_proc_fx( pos_fx = L_add( pos_fx, shift_fx ); - FOR ( i = 1; i < bufferNewSize - 1; i++ ) + FOR( i = 1; i < bufferNewSize - 1; i++ ) { idx = (Word16) L_shr( pos_fx, 21 ); diff_fx = pos_fx - L_shl( idx, 21 ); @@ -648,7 +646,7 @@ static void L_lerp_proc_fx( /* last point */ idx = (Word16) L_shr( pos_fx, 21 ); - IF ( pos_fx > L_shl( bufferOldSize - 1, 21 ) ) + IF( pos_fx > L_shl( bufferOldSize - 1, 21 ) ) { idx = bufferOldSize - 2; } @@ -661,4 +659,4 @@ static void L_lerp_proc_fx( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_com/limit_t0_fx.c b/lib_com/limit_t0_fx.c index 462bc6c66..97aa4fd8f 100644 --- a/lib_com/limit_t0_fx.c +++ b/lib_com/limit_t0_fx.c @@ -3,10 +3,10 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ #include "rom_com.h" @@ -14,8 +14,8 @@ * Local constants *-------------------------------------------------*/ -#define LIMIT_PIT_REL_LOWER 2 /* delta interval to extend pitch coding in relative Q */ -#define LIMIT_PIT_REL_UPPER 0 +#define LIMIT_PIT_REL_LOWER 2 /* delta interval to extend pitch coding in relative Q */ +#define LIMIT_PIT_REL_UPPER 0 /*-------------------------------------------------* * limit_T0() @@ -25,24 +25,24 @@ void limit_T0_fx( - const Word16 L_frame, /* i : length of the frame */ - const Word16 delta, /* i : Half the close-loop searched interval */ - const Word16 pit_flag, /* i : selecting absolute(0) or delta(1) pitch quantization */ - const Word16 limit_flag, /* i : flag for Q limits (0=restrained, 1=extended) */ - const Word16 T0, /* i : rough pitch estimate around which the search is done */ - const Word16 T0_frac, /* i : pitch estimate fractional part */ - Word16 *T0_min, /* o : lower pitch limit */ - Word16 *T0_max /* o : higher pitch limit */ + const Word16 L_frame, /* i : length of the frame */ + const Word16 delta, /* i : Half the close-loop searched interval */ + const Word16 pit_flag, /* i : selecting absolute(0) or delta(1) pitch quantization */ + const Word16 limit_flag, /* i : flag for Q limits (0=restrained, 1=extended) */ + const Word16 T0, /* i : rough pitch estimate around which the search is done */ + const Word16 T0_frac, /* i : pitch estimate fractional part */ + Word16 *T0_min, /* o : lower pitch limit */ + Word16 *T0_max /* o : higher pitch limit */ ) { - Word16 delta2,T1; + Word16 delta2, T1; Word16 pit_min, pit_max; - IF( limit_flag == 0 ) /* restrained Q limits */ + IF( limit_flag == 0 ) /* restrained Q limits */ { /* set limits */ - IF( EQ_16(L_frame,L_FRAME)) + IF( EQ_16( L_frame, L_FRAME ) ) { pit_max = PIT_MAX; move16(); @@ -57,41 +57,41 @@ void limit_T0_fx( move16(); } - delta2 = sub(shl(delta,1),1); + delta2 = sub( shl( delta, 1 ), 1 ); T1 = T0; move16(); - if( GE_16(T0_frac,2)) + if ( GE_16( T0_frac, 2 ) ) { - T1 = add(T1,1); + T1 = add( T1, 1 ); } - *T0_min = sub(T1,delta); + *T0_min = sub( T1, delta ); move16(); - *T0_min = s_max(*T0_min,pit_min); + *T0_min = s_max( *T0_min, pit_min ); - *T0_max = add(*T0_min,delta2); + *T0_max = add( *T0_min, delta2 ); move16(); - IF( GT_16(*T0_max,pit_max)) + IF( GT_16( *T0_max, pit_max ) ) { *T0_max = pit_max; move16(); - *T0_min = sub(*T0_max,delta2); + *T0_min = sub( *T0_max, delta2 ); move16(); } } - ELSE /* extended Q limits */ + ELSE /* extended Q limits */ { /* set limits */ - IF( EQ_16(L_frame, L_FRAME)) + IF( EQ_16( L_frame, L_FRAME ) ) { pit_max = PIT_MAX; move16(); pit_min = PIT_MIN_EXTEND; move16(); - if( EQ_16(limit_flag, 2)) + if ( EQ_16( limit_flag, 2 ) ) { pit_min = PIT_MIN_DOUBLEEXTEND; move16(); @@ -105,46 +105,46 @@ void limit_T0_fx( move16(); } - delta2 = sub(shl(delta,1),1) ; + delta2 = sub( shl( delta, 1 ), 1 ); move16(); T1 = T0; move16(); - if( GE_16(T0_frac,2)) + if ( GE_16( T0_frac, 2 ) ) { - T1 = add(T1,1); + T1 = add( T1, 1 ); } - *T0_min = sub(T1, delta); + *T0_min = sub( T1, delta ); move16(); IF( pit_flag == 0 ) { /* subframes with absolute search: keep Q range */ - *T0_min = s_max(*T0_min,pit_min); + *T0_min = s_max( *T0_min, pit_min ); - *T0_max = add(*T0_min, delta2); + *T0_max = add( *T0_min, delta2 ); move16(); - IF( GT_16(*T0_max,pit_max)) + IF( GT_16( *T0_max, pit_max ) ) { *T0_max = pit_max; move16(); - *T0_min = sub(*T0_max, delta2); + *T0_min = sub( *T0_max, delta2 ); move16(); } } ELSE { /* subframes with relative search: extend Q range */ - *T0_min = s_max(*T0_min,sub(pit_min, LIMIT_PIT_REL_LOWER)); + *T0_min = s_max( *T0_min, sub( pit_min, LIMIT_PIT_REL_LOWER ) ); move16(); - *T0_min = s_max(*T0_min,L_INTERPOL); + *T0_min = s_max( *T0_min, L_INTERPOL ); *T0_max = *T0_min + delta2; move16(); - IF( GT_16(*T0_max, add(pit_max, LIMIT_PIT_REL_UPPER))) + IF( GT_16( *T0_max, add( pit_max, LIMIT_PIT_REL_UPPER ) ) ) { - *T0_max = add(pit_max, LIMIT_PIT_REL_UPPER); + *T0_max = add( pit_max, LIMIT_PIT_REL_UPPER ); move16(); - *T0_min = sub(*T0_max, delta2); + *T0_min = sub( *T0_max, delta2 ); move16(); } } @@ -156,60 +156,60 @@ void limit_T0_fx( #define inv_T0_res InvIntTable /*-------------------------------------------------* -* Routine limit_T0_voiced() -* -* Close-loop pitch lag search limitation -*-------------------------------------------------*/ + * Routine limit_T0_voiced() + * + * Close-loop pitch lag search limitation + *-------------------------------------------------*/ void limit_T0_voiced( const Word16 nbits, const Word16 res, - const Word16 T0, /* i : rough pitch estimate around which the search is done */ - const Word16 T0_frac, /* i : pitch estimate fractional part */ - const Word16 T0_res, /* i : pitch resolution */ - Word16 *T0_min, /* o : lower pitch limit */ - Word16 *T0_min_frac, /* o : lower pitch limit */ - Word16 *T0_max, /* o : higher pitch limit */ - Word16 *T0_max_frac, /* o : higher pitch limit */ - const Word16 pit_min, /* i : Minimum pitch lag */ - const Word16 pit_max /* i : Maximum pitch lag */ + const Word16 T0, /* i : rough pitch estimate around which the search is done */ + const Word16 T0_frac, /* i : pitch estimate fractional part */ + const Word16 T0_res, /* i : pitch resolution */ + Word16 *T0_min, /* o : lower pitch limit */ + Word16 *T0_min_frac, /* o : lower pitch limit */ + Word16 *T0_max, /* o : higher pitch limit */ + Word16 *T0_max_frac, /* o : higher pitch limit */ + const Word16 pit_min, /* i : Minimum pitch lag */ + const Word16 pit_max /* i : Maximum pitch lag */ ) { Word16 T1, temp1, temp2, res2; - assert(res > 1 && res<=6); + assert( res > 1 && res <= 6 ); - res2 = res; + res2 = res; move16(); - if(EQ_16(res,6)) + if ( EQ_16( res, 6 ) ) { - res2 = shr(res2,1); + res2 = shr( res2, 1 ); } /* Mid-point */ T1 = T0; test(); - if( GT_16(T0_res,1)&&GE_16(T0_frac,(shr(T0_res,1)))) + if ( GT_16( T0_res, 1 ) && GE_16( T0_frac, ( shr( T0_res, 1 ) ) ) ) { - T1 = add(T1,1); + T1 = add( T1, 1 ); } /* Lower-bound */ - temp1 = sub(i_mult(T1,res),shl(1,sub(nbits,1))); + temp1 = sub( i_mult( T1, res ), shl( 1, sub( nbits, 1 ) ) ); - temp2 = mult(temp1,inv_T0_res[res2]); - if(EQ_16(res,6)) + temp2 = mult( temp1, inv_T0_res[res2] ); + if ( EQ_16( res, 6 ) ) { - temp2 = shr(temp2,1); + temp2 = shr( temp2, 1 ); } *T0_min = temp2; move16(); - *T0_min_frac = sub(temp1,i_mult(temp2,res)); + *T0_min_frac = sub( temp1, i_mult( temp2, res ) ); move16(); - IF ( LT_16(*T0_min,pit_min)) + IF( LT_16( *T0_min, pit_min ) ) { *T0_min = pit_min; move16(); @@ -218,39 +218,39 @@ void limit_T0_voiced( } /* Higher-bound */ - temp1 = add(i_mult(*T0_min,res),add(*T0_min_frac,sub(shl(1,nbits),1))); + temp1 = add( i_mult( *T0_min, res ), add( *T0_min_frac, sub( shl( 1, nbits ), 1 ) ) ); - temp2 = mult(temp1,inv_T0_res[res2]); - if(EQ_16(res,6)) + temp2 = mult( temp1, inv_T0_res[res2] ); + if ( EQ_16( res, 6 ) ) { - temp2 = shr(temp2,1); + temp2 = shr( temp2, 1 ); } *T0_max = temp2; move16(); - *T0_max_frac = sub(temp1,i_mult(temp2,res)); + *T0_max_frac = sub( temp1, i_mult( temp2, res ) ); move16(); - IF ( GT_16(*T0_max,pit_max)) + IF( GT_16( *T0_max, pit_max ) ) { *T0_max = pit_max; move16(); - *T0_max_frac = sub(res,1); + *T0_max_frac = sub( res, 1 ); move16(); - temp1 = add(i_mult(*T0_max,res),sub(*T0_max_frac,sub(shl(1,nbits),1))); + temp1 = add( i_mult( *T0_max, res ), sub( *T0_max_frac, sub( shl( 1, nbits ), 1 ) ) ); - temp2 = mult(temp1,inv_T0_res[res2]); - if(EQ_16(res,6)) + temp2 = mult( temp1, inv_T0_res[res2] ); + if ( EQ_16( res, 6 ) ) { - temp2 = shr(temp2,1); + temp2 = shr( temp2, 1 ); } move16(); *T0_min = temp2; - *T0_min_frac = sub(temp1, i_mult(temp2,res)); + *T0_min_frac = sub( temp1, i_mult( temp2, res ) ); move16(); } diff --git a/lib_com/log2.c b/lib_com/log2.c index 424580a03..739dd8e5e 100644 --- a/lib_com/log2.c +++ b/lib_com/log2.c @@ -1,11 +1,11 @@ /******************************************************************************** -* -* File : log2.c -* Purpose : Computes log2(L_x) -* -******************************************************************************** -*/ - + * + * File : log2.c + * Purpose : Computes log2(L_x) + * + ******************************************************************************** + */ + /* ******************************************************************************** * INCLUDE FILES @@ -17,15 +17,15 @@ #include "rom_basic_math.h" #include "options.h" -#define LW_SIGN (Word32)0x80000000 /* sign bit */ -#define LW_MIN (Word32)0x80000000 -#define LW_MAX (Word32)0x7fffffff +#define LW_SIGN (Word32) 0x80000000 /* sign bit */ +#define LW_MIN (Word32) 0x80000000 +#define LW_MAX (Word32) 0x7fffffff + +#define SW_SIGN (Word16) 0x8000 /* sign bit for Word16 type */ +#define SW_MIN (Word16) 0x8000 /* smallest Ram */ +#define SW_MAX (Word16) 0x7fff /* largest Ram */ -#define SW_SIGN (Word16)0x8000 /* sign bit for Word16 type */ -#define SW_MIN (Word16)0x8000 /* smallest Ram */ -#define SW_MAX (Word16)0x7fff /* largest Ram */ - /* ******************************************************************************** * PUBLIC PROGRAM CODE @@ -51,168 +51,172 @@ * 5- fraction = table[i]<<16 - (table[i] - table[i+1]) * a * 2 * *************************************************************************/ -Word16 Log2_norm_lc ( /* (o) : Fractional part of Log2. (range: 0<=val<1) */ - Word32 L_x /* (i) : input value (normalized) */ +Word16 Log2_norm_lc( /* (o) : Fractional part of Log2. (range: 0<=val<1) */ + Word32 L_x /* (i) : input value (normalized) */ ) { Word16 i, a; Word16 y; - if (L_x <= 0) - L_x = L_deposit_h(0x4000); + if ( L_x <= 0 ) + L_x = L_deposit_h( 0x4000 ); - L_x = L_shr (L_x, 9); - a = extract_l (L_x); /* Extract b10-b24 of fraction */ - a = lshr(a, 1); + L_x = L_shr( L_x, 9 ); + a = extract_l( L_x ); /* Extract b10-b24 of fraction */ + a = lshr( a, 1 ); - i = mac_r(L_x, -32*2-1, 16384); /* Extract b25-b31 minus 32 */ + i = mac_r( L_x, -32 * 2 - 1, 16384 ); /* Extract b25-b31 minus 32 */ - y = mac_r(L_table_Log2_norm_lc[i], table_diff_Log2_norm_lc[i], a); /* table[i] << 16 - diff*a*2 */ + y = mac_r( L_table_Log2_norm_lc[i], table_diff_Log2_norm_lc[i], a ); /* table[i] << 16 - diff*a*2 */ return y; } -Word32 log10_fx(Word32 Linput) +Word32 log10_fx( Word32 Linput ) { - Word16 n1, frac, p1, p2, q1; - Word32 Ltemp1, Ltemp2; - Word32 L_tmp; - - if (Linput<=0) return(LW_MIN); - n1=norm_l(Linput); - Ltemp1=(Word32)L_shl(Linput,n1); - - Ltemp2=L_mult(extract_h(Ltemp1),0x40); - frac=extract_l(Ltemp2); - - p1=log2_tab[sub(extract_h(Ltemp2),0x20)]; - p2=log2_tab[sub(extract_h(Ltemp2),0x1F)]; - Ltemp2=L_mult(n1,0x200); - n1=extract_l(Ltemp2); - - Ltemp1=L_add(L_deposit_h(p1),0x8000); /* Add rounding bit */ - - IF(frac >= 0) - { - Ltemp1=L_sub(Ltemp1,(Word32)L_mult0(p1,frac)); - Ltemp1=L_add(Ltemp1,(Word32)L_mult0(p2,frac)); - } - ELSE - { - L_tmp = L_add(65536,frac); - L_tmp = L_tmp*p1; - Ltemp1=L_sub(Ltemp1,L_tmp); - - L_tmp = L_add(65536,frac); - L_tmp = L_tmp*p2; - Ltemp1=L_add(Ltemp1,L_tmp); - } - q1=extract_h(Ltemp1); - Ltemp1=L_mult(q1,0x6054); - Ltemp1=L_msu(Ltemp1,0x6054,n1); - return(L_shr(Ltemp1,1)); - + Word16 n1, frac, p1, p2, q1; + Word32 Ltemp1, Ltemp2; + Word32 L_tmp; + + if ( Linput <= 0 ) + return ( LW_MIN ); + n1 = norm_l( Linput ); + Ltemp1 = (Word32) L_shl( Linput, n1 ); + + Ltemp2 = L_mult( extract_h( Ltemp1 ), 0x40 ); + frac = extract_l( Ltemp2 ); + + p1 = log2_tab[sub( extract_h( Ltemp2 ), 0x20 )]; + p2 = log2_tab[sub( extract_h( Ltemp2 ), 0x1F )]; + Ltemp2 = L_mult( n1, 0x200 ); + n1 = extract_l( Ltemp2 ); + + Ltemp1 = L_add( L_deposit_h( p1 ), 0x8000 ); /* Add rounding bit */ + + IF( frac >= 0 ) + { + Ltemp1 = L_sub( Ltemp1, (Word32) L_mult0( p1, frac ) ); + Ltemp1 = L_add( Ltemp1, (Word32) L_mult0( p2, frac ) ); + } + ELSE + { + L_tmp = L_add( 65536, frac ); + L_tmp = L_tmp * p1; + Ltemp1 = L_sub( Ltemp1, L_tmp ); + + L_tmp = L_add( 65536, frac ); + L_tmp = L_tmp * p2; + Ltemp1 = L_add( Ltemp1, L_tmp ); + } + q1 = extract_h( Ltemp1 ); + Ltemp1 = L_mult( q1, 0x6054 ); + Ltemp1 = L_msu( Ltemp1, 0x6054, n1 ); + return ( L_shr( Ltemp1, 1 ) ); } -Word32 pow_10(Word32 x , Word16 *Q) +Word32 pow_10( Word32 x, Word16 *Q ) { - Word16 xl,xh, t1, t2, n; - Word32 Ltemp1; - Word32 Lacc; - Word32 L_tmp; - Word16 n1,i; - Word16 count = 0; + Word16 xl, xh, t1, t2, n; + Word32 Ltemp1; + Word32 Lacc; + Word32 L_tmp; + Word16 n1, i; + Word16 count = 0; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; + Flag Overflow = 0; #endif - move16();; - - xl=extract_l(x); - xh=extract_h(x); - - IF(xl < 0) - { - L_tmp = L_add(65536,xl); - Ltemp1=(Word32) (0x6a4d*L_tmp ); - } - ELSE - { - Ltemp1=L_mult0(0x6a4d,xl); - } - Ltemp1=L_add(L_shr(Ltemp1,16),L_shr(L_mult(xh,0x6a4d),1)); - - - Lacc=L_sub(-1L, Ltemp1); /* Lacc=~Lacc, 1's complement */ - t1=extract_l(L_shr(Lacc,7)); - - Ltemp1=L_shr(Ltemp1,7); - n1 = extract_h(Ltemp1); - n=sub(n1,14); - *Q = 14; move16(); - IF(t1<0) - { - L_tmp = L_add(65536,t1); - t2=extract_h(L_tmp*L_tmp); - } - ELSE - { - t2=extract_h(L_mult0(t1,t1)); - } - - Lacc = L_deposit_h(0x1FEF); - IF(t2 < 0) - { - L_tmp = L_add(65536,t2); - Lacc = L_add(Lacc,(Word32)(L_tmp*0x057C)); - } - ELSE - { - Lacc = L_add(Lacc,(Word32)L_mult0(t2,0x057C)); - } - - IF(t1 < 0) - { - L_tmp = L_add(65536,t1); - Lacc = L_sub(Lacc,(Word32)(L_tmp*0x155C)); - } - ELSE - { - Lacc = L_sub(Lacc,(Word32)L_mult0(t1,0x155C)); - } - - L_tmp = Lacc; - FOR(i =1 ;i <= n ;i++) - { - Overflow = 0; move16(); -#ifdef BASOP_NOGLOB /* Critical Overflow */ - L_tmp = L_shl_o(L_tmp,i, &Overflow); + move16(); + ; + + xl = extract_l( x ); + xh = extract_h( x ); + + IF( xl < 0 ) + { + L_tmp = L_add( 65536, xl ); + Ltemp1 = (Word32) ( 0x6a4d * L_tmp ); + } + ELSE + { + Ltemp1 = L_mult0( 0x6a4d, xl ); + } + Ltemp1 = L_add( L_shr( Ltemp1, 16 ), L_shr( L_mult( xh, 0x6a4d ), 1 ) ); + + + Lacc = L_sub( -1L, Ltemp1 ); /* Lacc=~Lacc, 1's complement */ + t1 = extract_l( L_shr( Lacc, 7 ) ); + + Ltemp1 = L_shr( Ltemp1, 7 ); + n1 = extract_h( Ltemp1 ); + n = sub( n1, 14 ); + *Q = 14; + move16(); + IF( t1 < 0 ) + { + L_tmp = L_add( 65536, t1 ); + t2 = extract_h( L_tmp * L_tmp ); + } + ELSE + { + t2 = extract_h( L_mult0( t1, t1 ) ); + } + + Lacc = L_deposit_h( 0x1FEF ); + IF( t2 < 0 ) + { + L_tmp = L_add( 65536, t2 ); + Lacc = L_add( Lacc, (Word32) ( L_tmp * 0x057C ) ); + } + ELSE + { + Lacc = L_add( Lacc, (Word32) L_mult0( t2, 0x057C ) ); + } + + IF( t1 < 0 ) + { + L_tmp = L_add( 65536, t1 ); + Lacc = L_sub( Lacc, (Word32) ( L_tmp * 0x155C ) ); + } + ELSE + { + Lacc = L_sub( Lacc, (Word32) L_mult0( t1, 0x155C ) ); + } + + L_tmp = Lacc; + FOR( i = 1; i <= n; i++ ) + { + Overflow = 0; + move16(); +#ifdef BASOP_NOGLOB /* Critical Overflow */ + L_tmp = L_shl_o( L_tmp, i, &Overflow ); #else - L_tmp = L_shl(L_tmp,i); + L_tmp = L_shl( L_tmp, i ); #endif - IF(Overflow) - { - count = add(count,1); - } - } - *Q = sub(*Q,count); move16(); - - return(L_shl(Lacc,sub(n,count))); - + IF( Overflow ) + { + count = add( count, 1 ); + } + } + *Q = sub( *Q, count ); + move16(); + + return ( L_shl( Lacc, sub( n, count ) ) ); } -Word16 Log2_lc( /* (o) : Fractional part of Log2. (range: 0<=val<1) */ - Word32 L_x, /* (i) : input value */ - Word16 *exponent /* (o) : Integer part of Log2. (range: 0<=val<=30) */ +Word16 Log2_lc( /* (o) : Fractional part of Log2. (range: 0<=val<1) */ + Word32 L_x, /* (i) : input value */ + Word16 *exponent /* (o) : Integer part of Log2. (range: 0<=val<=30) */ ) { Word16 exp; - if (L_x <= 0) - L_x = L_deposit_l(0x1); + if ( L_x <= 0 ) + L_x = L_deposit_l( 0x1 ); - exp = norm_l (L_x); - *exponent = sub(30, exp); move16(); + exp = norm_l( L_x ); + *exponent = sub( 30, exp ); + move16(); - return Log2_norm_lc(L_shl(L_x, exp)); + return Log2_norm_lc( L_shl( L_x, exp ) ); } diff --git a/lib_com/log2.h b/lib_com/log2.h index a8ff32e65..ade28f994 100644 --- a/lib_com/log2.h +++ b/lib_com/log2.h @@ -1,13 +1,13 @@ /******************************************************************************** -* -* File : log2.h -* Purpose : Computes log2(L_x) -* -******************************************************************************** -*/ + * + * File : log2.h + * Purpose : Computes log2(L_x) + * + ******************************************************************************** + */ #ifndef log2_h #define log2_h "$Id $" - + /* ******************************************************************************** * INCLUDE FILES @@ -15,26 +15,26 @@ */ #include "typedef.h" #include "log2.h" - + /* ******************************************************************************** * DEFINITION OF DATA TYPES ******************************************************************************** */ - + /* ******************************************************************************** * DECLARATION OF PROTOTYPES ******************************************************************************** */ -Word16 Log2_norm_lc ( /* (o) : Fractional part of Log2. (range: 0<=val<1) */ - Word32 L_x /* (i) : input value (normalized) */ +Word16 Log2_norm_lc( /* (o) : Fractional part of Log2. (range: 0<=val<1) */ + Word32 L_x /* (i) : input value (normalized) */ ); -Word32 log10_fx(Word32 Linput); -Word32 pow_10(Word32 x, Word16 *Q); -Word16 Log2_lc( /* (o) : Fractional part of Log2. (range: 0<=val<1) */ - Word32 L_x, /* (i) : input value */ - Word16 *exponent /* (o) : Integer part of Log2. (range: 0<=val<=30) */ +Word32 log10_fx( Word32 Linput ); +Word32 pow_10( Word32 x, Word16 *Q ); +Word16 Log2_lc( /* (o) : Fractional part of Log2. (range: 0<=val<1) */ + Word32 L_x, /* (i) : input value */ + Word16 *exponent /* (o) : Integer part of Log2. (range: 0<=val<=30) */ ); #endif diff --git a/lib_com/logqnorm_fx.c b/lib_com/logqnorm_fx.c index 67372fe72..678517ae2 100644 --- a/lib_com/logqnorm_fx.c +++ b/lib_com/logqnorm_fx.c @@ -31,156 +31,156 @@ *******************************************************************************************************/ #include -#include "options.h" /* Compilation switches */ -#include "prot_fx2.h" /* Function prototypes */ -#include "rom_com.h" /* Static table prototypes */ -#include "cnst.h" /* Common constants */ +#include "options.h" /* Compilation switches */ +#include "prot_fx2.h" /* Function prototypes */ +#include "rom_com.h" /* Static table prototypes */ +#include "cnst.h" /* Common constants */ - /*--------------------------------------------------------------------------* - * Local constants - *--------------------------------------------------------------------------*/ +/*--------------------------------------------------------------------------* + * Local constants + *--------------------------------------------------------------------------*/ -#define THREN2POW 1518500250L +#define THREN2POW 1518500250L - /*--------------------------------------------------------------------------* - * logqnorm_fx - * - * Log quantization for norms of sub-vectors - *--------------------------------------------------------------------------*/ +/*--------------------------------------------------------------------------* + * logqnorm_fx + * + * Log quantization for norms of sub-vectors + *--------------------------------------------------------------------------*/ void logqnorm_fx( - const Word32 *L_x, /* i : coefficient vector Qx */ - const Word16 qx, /* i : Q value of input */ - Word16 *k, /* o : index Q0 */ - const Word16 L, /* i : codebook length Q0 */ - const Word16 N, /* i : sub-vector size Q0 */ - const Word16 hvq_flag /* i : HVQ flag Q0 */ + const Word32 *L_x, /* i : coefficient vector Qx */ + const Word16 qx, /* i : Q value of input */ + Word16 *k, /* o : index Q0 */ + const Word16 L, /* i : codebook length Q0 */ + const Word16 N, /* i : sub-vector size Q0 */ + const Word16 hvq_flag /* i : HVQ flag Q0 */ ) { - Word16 i, m; - Word16 coefs_shift, power_shift, temp_shift; - Word32 L_temp, L_temp1, L_temp2; - Word16 coefs16[MAX_SFM_LEN_FX]; - UWord16 lsb; - - Word16 offset = add(3, shl(qx, 1)); /* 3 + 2*qx */ - - lsb = 0U; /* to avoid compilation warnings */ - - L_temp1 = L_deposit_l(1); - FOR(i = 0; i < N; i++) - { - L_temp2 = L_abs(L_x[i]); - L_temp1 = L_max(L_temp1, L_temp2); - } - coefs_shift = sub(norm_l(L_temp1), sqac_headroom_fx[N]); - L_temp = L_deposit_l(0); - - FOR(i = 0; i < N; i++) - { - coefs16[i] = extract_h(L_shl(L_x[i], coefs_shift)); - L_temp = L_mac0(L_temp, coefs16[i], coefs16[i]); - } - - if (GT_16(N, 1)) - { - Mpy_32_16_ss(L_temp, inv_tbl_fx[N], &L_temp, &lsb); - } - power_shift = shl(sub(coefs_shift, 16), 1); - - temp_shift = norm_l(L_temp); - m = add(temp_shift, power_shift); - - L_temp1 = L_add(L_shl(L_temp, temp_shift), lshr(lsb, sub(16, temp_shift))); - - m = add(offset, m); - test(); - IF(m < 5 && hvq_flag) - { - m = shl(m, 1); - IF(LT_32(L_temp1, 1276901417L /* 2^0.25 Q30 */)) - { - m = add(m, 2); - } - ELSE if (LT_32(L_temp1, 1805811301L /* 2^0.75 Q30 */)) - { - m = add(m, 1); - } - } - ELSE - { - if (LT_32(L_temp1, THREN2POW /* 2^0.5 Q30 */)) - { - m = add(m, 1); - } - if (hvq_flag) - { - m = add(m, 5); /* offset, 5 extra levels in HVQ codebook */ - } - } - *k = s_max(m, 0); - i = sub(L, 1); - *k = s_min(*k, i); - - return; + Word16 i, m; + Word16 coefs_shift, power_shift, temp_shift; + Word32 L_temp, L_temp1, L_temp2; + Word16 coefs16[MAX_SFM_LEN_FX]; + UWord16 lsb; + + Word16 offset = add( 3, shl( qx, 1 ) ); /* 3 + 2*qx */ + + lsb = 0U; /* to avoid compilation warnings */ + + L_temp1 = L_deposit_l( 1 ); + FOR( i = 0; i < N; i++ ) + { + L_temp2 = L_abs( L_x[i] ); + L_temp1 = L_max( L_temp1, L_temp2 ); + } + coefs_shift = sub( norm_l( L_temp1 ), sqac_headroom_fx[N] ); + L_temp = L_deposit_l( 0 ); + + FOR( i = 0; i < N; i++ ) + { + coefs16[i] = extract_h( L_shl( L_x[i], coefs_shift ) ); + L_temp = L_mac0( L_temp, coefs16[i], coefs16[i] ); + } + + if ( GT_16( N, 1 ) ) + { + Mpy_32_16_ss( L_temp, inv_tbl_fx[N], &L_temp, &lsb ); + } + power_shift = shl( sub( coefs_shift, 16 ), 1 ); + + temp_shift = norm_l( L_temp ); + m = add( temp_shift, power_shift ); + + L_temp1 = L_add( L_shl( L_temp, temp_shift ), lshr( lsb, sub( 16, temp_shift ) ) ); + + m = add( offset, m ); + test(); + IF( m < 5 && hvq_flag ) + { + m = shl( m, 1 ); + IF( LT_32( L_temp1, 1276901417L /* 2^0.25 Q30 */ ) ) + { + m = add( m, 2 ); + } + ELSE if ( LT_32( L_temp1, 1805811301L /* 2^0.75 Q30 */ ) ) + { + m = add( m, 1 ); + } + } + ELSE + { + if ( LT_32( L_temp1, THREN2POW /* 2^0.5 Q30 */ ) ) + { + m = add( m, 1 ); + } + if ( hvq_flag ) + { + m = add( m, 5 ); /* offset, 5 extra levels in HVQ codebook */ + } + } + *k = s_max( m, 0 ); + i = sub( L, 1 ); + *k = s_min( *k, i ); + + return; } void logqnorm_2_fx( - const Word32 *env_fl, /* o, Q10 : index */ - const Word16 L, /* i : codebook length */ - const Word16 n_env_band, /* i : sub-vector size */ - const Word16 nb_sfm, /* i : sub-vector size */ - Word16 *ynrm, /* o : norm indices */ - Word16* normqlg2, /* o : quantized norm values */ - const Word32 *thren /* i, Q10 : quantization thresholds */ + const Word32 *env_fl, /* o, Q10 : index */ + const Word16 L, /* i : codebook length */ + const Word16 n_env_band, /* i : sub-vector size */ + const Word16 nb_sfm, /* i : sub-vector size */ + Word16 *ynrm, /* o : norm indices */ + Word16 *normqlg2, /* o : quantized norm values */ + const Word32 *thren /* i, Q10 : quantization thresholds */ ) { - Word16 i, j, j1, j2; - Word32 temp, power; - - FOR(i = n_env_band; i < nb_sfm; i++) - { - temp = env_fl[sub(i, n_env_band)]; - IF(LE_32(thren[0], temp)) - { - *ynrm = 0; - move16(); - } - ELSE IF(GT_32(thren[sub(L, 2)], temp)) - { - *ynrm = sub(L, 1); - } - ELSE - { - power = temp; - move16(); - j1 = 0; - move16(); - j2 = sub(L, 1); - WHILE(GT_16(sub(j2,j1),1)) - { - j = shr(add(j1 , j2), 1); - IF(GE_32(power,thren[j])) - { - j2 = j; - move16(); - } - ELSE - { - j1 = j; - move16(); - } - } - *ynrm = j2; - move16(); - } - *normqlg2 = dicnlg2[*ynrm]; - move16(); - normqlg2++; - ynrm++; - } - - return; + Word16 i, j, j1, j2; + Word32 temp, power; + + FOR( i = n_env_band; i < nb_sfm; i++ ) + { + temp = env_fl[sub( i, n_env_band )]; + IF( LE_32( thren[0], temp ) ) + { + *ynrm = 0; + move16(); + } + ELSE IF( GT_32( thren[sub( L, 2 )], temp ) ) + { + *ynrm = sub( L, 1 ); + } + ELSE + { + power = temp; + move16(); + j1 = 0; + move16(); + j2 = sub( L, 1 ); + WHILE( GT_16( sub( j2, j1 ), 1 ) ) + { + j = shr( add( j1, j2 ), 1 ); + IF( GE_32( power, thren[j] ) ) + { + j2 = j; + move16(); + } + ELSE + { + j1 = j; + move16(); + } + } + *ynrm = j2; + move16(); + } + *normqlg2 = dicnlg2[*ynrm]; + move16(); + normqlg2++; + ynrm++; + } + + return; } /*-------------------------------------------------------------------------- @@ -190,37 +190,37 @@ void logqnorm_2_fx( *--------------------------------------------------------------------------*/ void calc_norm_fx( - const Word32 *L_x, /* i : Input vector. Qx */ - const Word16 qx, /* i : Q value of input */ - Word16 *norm, /* o : Quantization indices for norms Q0 */ - Word16 *normlg, /* o : Quantized norms in log2 Q0 */ - const Word16 start_band, /* i : Indice of band to start coding Q0 */ - const Word16 num_bands, /* i : Number of bands Q0 */ - const Word16 *band_len, /* i : Length of bands Q0 */ - const Word16 *band_start /* i : Start of bands Q0 */ + const Word32 *L_x, /* i : Input vector. Qx */ + const Word16 qx, /* i : Q value of input */ + Word16 *norm, /* o : Quantization indices for norms Q0 */ + Word16 *normlg, /* o : Quantized norms in log2 Q0 */ + const Word16 start_band, /* i : Indice of band to start coding Q0 */ + const Word16 num_bands, /* i : Number of bands Q0 */ + const Word16 *band_len, /* i : Length of bands Q0 */ + const Word16 *band_start /* i : Start of bands Q0 */ ) { - Word16 nrm; - Word16 band; - Word16 tmp; - - set16_fx(norm, 0, start_band); - logqnorm_fx(&L_x[band_start[start_band]], qx, &nrm, 32, band_len[start_band], 0); - norm[start_band] = nrm; - move16(); - normlg[start_band] = dicnlg2[nrm]; - move16(); - - tmp = add(start_band, num_bands); - FOR(band = add(start_band, 1); band < tmp; band++) - { - logqnorm_fx(&L_x[band_start[band]], qx, &nrm, 40, band_len[band], 0); - - norm[band] = nrm; - move16(); - normlg[band] = dicnlg2[nrm]; - move16(); - } - - return; + Word16 nrm; + Word16 band; + Word16 tmp; + + set16_fx( norm, 0, start_band ); + logqnorm_fx( &L_x[band_start[start_band]], qx, &nrm, 32, band_len[start_band], 0 ); + norm[start_band] = nrm; + move16(); + normlg[start_band] = dicnlg2[nrm]; + move16(); + + tmp = add( start_band, num_bands ); + FOR( band = add( start_band, 1 ); band < tmp; band++ ) + { + logqnorm_fx( &L_x[band_start[band]], qx, &nrm, 40, band_len[band], 0 ); + + norm[band] = nrm; + move16(); + normlg[band] = dicnlg2[nrm]; + move16(); + } + + return; } diff --git a/lib_com/longarith.c b/lib_com/longarith.c index cdca65cc6..2617034d9 100644 --- a/lib_com/longarith.c +++ b/lib_com/longarith.c @@ -138,26 +138,25 @@ void longshiftright( #ifdef IVAS_FLOAT_FIXED void longshr( - UWord32 a[], - Word16 bits, - Word16 len -) + UWord32 a[], + Word16 bits, + Word16 len ) { - Word16 fracb_u, k; + Word16 fracb_u, k; - assert((bits > 0) && (bits < 32)); + assert( ( bits > 0 ) && ( bits < 32 ) ); - fracb_u = sub(32, bits); - len = sub(len, 1); - FOR(k = 0; k < len; k++) - { - a[k] = L_or(L_lshr(a[k], bits), L_lshl(a[k + 1], fracb_u)); + fracb_u = sub( 32, bits ); + len = sub( len, 1 ); + FOR( k = 0; k < len; k++ ) + { + a[k] = L_or( L_lshr( a[k], bits ), L_lshl( a[k + 1], fracb_u ) ); + move32(); + } + a[k] = L_lshr( a[k], bits ); move32(); - } - a[k] = L_lshr(a[k], bits); - move32(); - return; + return; } #endif diff --git a/lib_com/low_rate_band_att_fx.c b/lib_com/low_rate_band_att_fx.c index e4889c395..0df807523 100644 --- a/lib_com/low_rate_band_att_fx.c +++ b/lib_com/low_rate_band_att_fx.c @@ -3,8 +3,8 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "rom_com.h" /* Static table prototypes */ +#include "options.h" /* Compilation switches */ +#include "rom_com.h" /* Static table prototypes */ #include "prot_fx1.h" #include "prot_fx2.h" #ifdef IVAS_FLOAT_FIXED @@ -137,18 +137,18 @@ void ivas_fine_gain_pred_fx( #endif void fine_gain_pred_fx( - const Word16 *sfm_start, /* i : Sub band start indices */ - const Word16 *sfm_end, /* i : Sub band end indices */ - const Word16 *sfm_size, /* i : Sub band bandwidths */ - const Word16 *i_sort, /* i : Energy sorting indices */ - const Word16 *K, /* i : Number of pulses per band */ - const Word16 *maxpulse, /* i : Maximum pulse per band */ - const Word16 *R, /* i : Bits per sub band Q3 */ - const Word16 num_sfm, /* i : Number of sub bands */ - Word16 *xq, /* i/o: Quantized vector /quantized vector with finegain adj Q15*/ - Word16 *y, /* i/o: Quantized vector (int) */ - Word16 *fg_pred, /* o : Predicted fine gains Q12 */ - const Word16 core /* i : Core */ + const Word16 *sfm_start, /* i : Sub band start indices */ + const Word16 *sfm_end, /* i : Sub band end indices */ + const Word16 *sfm_size, /* i : Sub band bandwidths */ + const Word16 *i_sort, /* i : Energy sorting indices */ + const Word16 *K, /* i : Number of pulses per band */ + const Word16 *maxpulse, /* i : Maximum pulse per band */ + const Word16 *R, /* i : Bits per sub band Q3 */ + const Word16 num_sfm, /* i : Number of sub bands */ + Word16 *xq, /* i/o: Quantized vector /quantized vector with finegain adj Q15*/ + Word16 *y, /* i/o: Quantized vector (int) */ + Word16 *fg_pred, /* o : Predicted fine gains Q12 */ + const Word16 core /* i : Core */ ) { Word16 i, band; @@ -165,64 +165,64 @@ void fine_gain_pred_fx( Flag Overflow = 0; #endif - FOR( band = 0; band < num_sfm; band++) + FOR( band = 0; band < num_sfm; band++ ) { - k = K[i_sort[band]]; + k = K[i_sort[band]]; move16(); - IF( k > 0) + IF( k > 0 ) { /* bw, bw_idx only used if k>0 */ - bw = sfm_size[i_sort[band]]; - move16(); /* allowed. 8, 16, 24,32,48,64,80,96 */ - bw_idx = band_len_idx[ shr(bw,3) ]; - move16(); /* bw_idx= 0: 7 */ - xx = L_deposit_l(0); + bw = sfm_size[i_sort[band]]; + move16(); /* allowed. 8, 16, 24,32,48,64,80,96 */ + bw_idx = band_len_idx[shr( bw, 3 )]; + move16(); /* bw_idx= 0: 7 */ + xx = L_deposit_l( 0 ); shift = band_len_ener_shift[bw_idx]; - FOR(i = sfm_start[i_sort[band]]; i < sfm_end[i_sort[band]]; i++) + FOR( i = sfm_start[i_sort[band]]; i < sfm_end[i_sort[band]]; i++ ) { /*xx += xq[i] * xq[i]; */ - tmp = shr(xq[i], shift); /*15-shift */ - xx = L_mac0(xx, tmp, tmp); /*30-2*shift */ + tmp = shr( xq[i], shift ); /*15-shift */ + xx = L_mac0( xx, tmp, tmp ); /*30-2*shift */ } - IF ( xx > 0) + IF( xx > 0 ) { /* Normalize synthesis to RMS=1.0 */ /*gp = (float) sqrt(bw / xx); */ - exp = norm_l(xx); - L_tmp = L_shl(xx, exp); /*2*(15-shift)+exp */ - exp = sub(31, add(exp, sub(30, shl(shift,1)))); - L_tmp = Isqrt_lc(L_tmp, &exp); /*31 - exp */ - Mpy_32_16_ss(L_tmp, fine_gain_pred_sqrt_bw[bw_idx], &L_tmp, &lsb); /*31-exp+11-15=27-exp */ + exp = norm_l( xx ); + L_tmp = L_shl( xx, exp ); /*2*(15-shift)+exp */ + exp = sub( 31, add( exp, sub( 30, shl( shift, 1 ) ) ) ); + L_tmp = Isqrt_lc( L_tmp, &exp ); /*31 - exp */ + Mpy_32_16_ss( L_tmp, fine_gain_pred_sqrt_bw[bw_idx], &L_tmp, &lsb ); /*31-exp+11-15=27-exp */ #ifdef BASOP_NOGLOB - gp = round_fx_o(L_shl_o(L_tmp, add(1, exp), &Overflow), &Overflow); /*27-exp+1+exp-16=12 */ + gp = round_fx_o( L_shl_o( L_tmp, add( 1, exp ), &Overflow ), &Overflow ); /*27-exp+1+exp-16=12 */ #else - gp = round_fx(L_shl(L_tmp, add(1, exp))); /*27-exp+1+exp-16=12 */ + gp = round_fx( L_shl( L_tmp, add( 1, exp ) ) ); /*27-exp+1+exp-16=12 */ #endif test(); test(); - IF (EQ_16(core, HQ_CORE)&&R!=NULL&&LE_16(R[i_sort[band]],256)) /* 256 is 32 in Q3 */ + IF( EQ_16( core, HQ_CORE ) && R != NULL && LE_16( R[i_sort[band]], 256 ) ) /* 256 is 32 in Q3 */ { /*accuracy = ((float)k/(float)bw)*maxpulse[i_sort[band]]; */ - L_tmp = L_mult(k, inv_tbl_fx[bw]); /*0+15+1 */ - exp2 = norm_l(L_tmp); - tmp = round_fx(L_shl(L_tmp, exp2)); /*16+exp2-16 */ - L_tmp = L_mult0(maxpulse[i_sort[band]], tmp); /*0+exp2 */ - exp = norm_l(L_tmp); - accuracy = round_fx(L_shl(L_tmp, exp)); /*exp2+exp-16=exp-16 */ - exp = add(exp, exp2); + L_tmp = L_mult( k, inv_tbl_fx[bw] ); /*0+15+1 */ + exp2 = norm_l( L_tmp ); + tmp = round_fx( L_shl( L_tmp, exp2 ) ); /*16+exp2-16 */ + L_tmp = L_mult0( maxpulse[i_sort[band]], tmp ); /*0+exp2 */ + exp = norm_l( L_tmp ); + accuracy = round_fx( L_shl( L_tmp, exp ) ); /*exp2+exp-16=exp-16 */ + exp = add( exp, exp2 ); /*gp *= 1.0f - 0.05f / accuracy; */ - tmp = div_s(13107, accuracy); /* 0.05 in Q18 */ + tmp = div_s( 13107, accuracy ); /* 0.05 in Q18 */ #ifdef BASOP_NOGLOB - tmp = shr_o(tmp, sub(34, exp), &Overflow); /*15+18-exp+16-15=34-exp */ -#else /* BASOP_NOGLOB */ - tmp = shr(tmp, sub(34, exp)); /*15+18-exp+16-15=34-exp */ + tmp = shr_o( tmp, sub( 34, exp ), &Overflow ); /*15+18-exp+16-15=34-exp */ +#else /* BASOP_NOGLOB */ + tmp = shr( tmp, sub( 34, exp ) ); /*15+18-exp+16-15=34-exp */ #endif - tmp = sub(32767, tmp); - tmp = s_max(27554, tmp); /* Limit attenuation to norm quantizer error, 2^-0.25 in Q15 */ - gp = mult_r(tmp, gp); /*15+12+1-16=12 */ + tmp = sub( 32767, tmp ); + tmp = s_max( 27554, tmp ); /* Limit attenuation to norm quantizer error, 2^-0.25 in Q15 */ + gp = mult_r( tmp, gp ); /*15+12+1-16=12 */ } fg_pred[band] = gp; @@ -238,7 +238,7 @@ void fine_gain_pred_fx( { fg_pred[band] = 0; move16(); - FOR(i = sfm_start[i_sort[band]]; i < sfm_end[i_sort[band]]; i++) + FOR( i = sfm_start[i_sort[band]]; i < sfm_end[i_sort[band]]; i++ ) { y[i] = 0; move16(); @@ -258,13 +258,13 @@ void fine_gain_pred_fx( *--------------------------------------------------------------------------*/ void get_max_pulses_fx( - const Word16 *band_start, /* i : Sub band start indices */ - const Word16 *band_end, /* i : Sub band end indices */ - const Word16 *k_sort, /* i : Indices for sorting by energy */ - const Word16 *npulses, /* i : Pulses per sub band */ - const Word16 BANDS, /* i : Number of bands */ - Word16 *inp_vector, /* i/o: Encoded shape vectors (int)*/ - Word16 *maxpulse /* o : Maximum pulse height per band */ + const Word16 *band_start, /* i : Sub band start indices */ + const Word16 *band_end, /* i : Sub band end indices */ + const Word16 *k_sort, /* i : Indices for sorting by energy */ + const Word16 *npulses, /* i : Pulses per sub band */ + const Word16 BANDS, /* i : Number of bands */ + Word16 *inp_vector, /* i/o: Encoded shape vectors (int)*/ + Word16 *maxpulse /* o : Maximum pulse height per band */ ) { Word16 i, k; @@ -272,18 +272,18 @@ void get_max_pulses_fx( Word16 maxp; Word16 tmp; - FOR (k = 0; k < BANDS; k++) + FOR( k = 0; k < BANDS; k++ ) { npul = npulses[k_sort[k]]; move16(); maxp = 0; move16(); - IF (npul > 0) + IF( npul > 0 ) { - FOR (i = band_start[k_sort[k]]; i < band_end[k_sort[k]]; i++) + FOR( i = band_start[k_sort[k]]; i < band_end[k_sort[k]]; i++ ) { - tmp = abs_s(inp_vector[i]); - if (GT_16(tmp, maxp)) + tmp = abs_s( inp_vector[i] ); + if ( GT_16( tmp, maxp ) ) { maxp = tmp; move16(); @@ -304,13 +304,12 @@ void get_max_pulses_fx( * predicted fine gains *--------------------------------------------------------------------------*/ -void fine_gain_dec_fx -( +void fine_gain_dec_fx( Decoder_State *st, - const Word16 *ord, /* i : Indices for energy order */ - const Word16 num_sfm, /* i : Number of bands */ - const Word16 *gain_bits, /* i : Gain adjustment bits per sub band */ - Word16 *fg_pred /* i/o: Predicted gains / Corrected gains */ + const Word16 *ord, /* i : Indices for energy order */ + const Word16 num_sfm, /* i : Number of bands */ + const Word16 *gain_bits, /* i : Gain adjustment bits per sub band */ + Word16 *fg_pred /* i/o: Predicted gains / Corrected gains */ ) { Word16 band; @@ -320,31 +319,29 @@ void fine_gain_dec_fx Word32 L_tmp; - FOR ( band = 0; band < num_sfm; band++) + FOR( band = 0; band < num_sfm; band++ ) { gbits = gain_bits[ord[band]]; - IF (gbits > 0) + IF( gbits > 0 ) { - IF (fg_pred[band] != 0) + IF( fg_pred[band] != 0 ) { idx = get_next_indice( st, gbits ); - gain_dbq = finegain_fx[gbits-1][idx]; + gain_dbq = finegain_fx[gbits - 1][idx]; /* Update predicted gain with quantized correction */ - L_tmp = L_mult0(gain_dbq, 21771); /* 21771=0.05*log2(10) */ /* 14+17=31 */ - L_tmp = L_shr(L_tmp, 15); - tmp1 = L_Extract_lc(L_tmp, &exp1); - tmp1 = abs_s(tmp1); - tmp1 = extract_l(Pow2(14, tmp1)); - exp1 = sub(14, exp1); - - L_tmp = L_mult0(fg_pred[band], tmp1); /*12+exp1 */ - fg_pred[band] = round_fx_sat(L_shl_sat(L_tmp, sub(16, exp1))); /*12+exp1+16-exp1-16=12 */ + L_tmp = L_mult0( gain_dbq, 21771 ); /* 21771=0.05*log2(10) */ /* 14+17=31 */ + L_tmp = L_shr( L_tmp, 15 ); + tmp1 = L_Extract_lc( L_tmp, &exp1 ); + tmp1 = abs_s( tmp1 ); + tmp1 = extract_l( Pow2( 14, tmp1 ) ); + exp1 = sub( 14, exp1 ); + + L_tmp = L_mult0( fg_pred[band], tmp1 ); /*12+exp1 */ + fg_pred[band] = round_fx_sat( L_shl_sat( L_tmp, sub( 16, exp1 ) ) ); /*12+exp1+16-exp1-16=12 */ } } } return; } - - diff --git a/lib_com/lpc_tools.c b/lib_com/lpc_tools.c index e4f0e5038..bcf0a5d9a 100644 --- a/lib_com/lpc_tools.c +++ b/lib_com/lpc_tools.c @@ -195,13 +195,12 @@ int16_t lev_dur( } #ifdef IVAS_FLOAT_FIXED Word16 lev_dur_fx( - Word32 *a_fx, /* o : LP coefficients (a[0] = 1.0) */ - const Word32 *r_fx, /* i : vector of autocorrelations */ - const Word16 m, /* i : order of LP filter */ - Word32 epsP[], /* o : prediction error energy */ + Word32 *a_fx, /* o : LP coefficients (a[0] = 1.0) */ + const Word32 *r_fx, /* i : vector of autocorrelations */ + const Word16 m, /* i : order of LP filter */ + Word32 epsP[], /* o : prediction error energy */ Word16 q_a, - Word16 q_r -) + Word16 q_r ) { Word16 i, j, l; Word16 buf_fx[TCXLTP_LTP_ORDER]; @@ -211,11 +210,11 @@ Word16 lev_dur_fx( Word16 flag = 0; rc_fx = &buf_fx[0]; - rc_fx[0] = divide3232( L_negate(r_fx[1]), r_fx[0]); //Q(31) - a_fx[0] = L_shl(1, q_a); - a_fx[1] = L_shl(rc_fx[0], sub(q_a, 15)); - err = L_add(r_fx[0], Mpy_32_16_1(r_fx[1], rc_fx[0])); // Q(q_r) - IF ( epsP != NULL ) + rc_fx[0] = divide3232( L_negate( r_fx[1] ), r_fx[0] ); // Q(31) + a_fx[0] = L_shl( 1, q_a ); + a_fx[1] = L_shl( rc_fx[0], sub( q_a, 15 ) ); + err = L_add( r_fx[0], Mpy_32_16_1( r_fx[1], rc_fx[0] ) ); // Q(q_r) + IF( epsP != NULL ) { epsP[0] = r_fx[0]; move32(); @@ -223,39 +222,39 @@ Word16 lev_dur_fx( move32(); } - FOR ( i = 2; i <= m; i++ ) + FOR( i = 2; i <= m; i++ ) { - s = 0; // Q(q_a + q_r - 31) - FOR ( j = 0; j < i; j++ ) + s = 0; // Q(q_a + q_r - 31) + FOR( j = 0; j < i; j++ ) { - s = L_add(s, Mpy_32_32(r_fx[i - j], a_fx[j])); + s = L_add( s, Mpy_32_32( r_fx[i - j], a_fx[j] ) ); } - rc_fx[i - 1] = divide3232( L_negate( s ), L_shr(err, sub(31, q_a))); + rc_fx[i - 1] = divide3232( L_negate( s ), L_shr( err, sub( 31, q_a ) ) ); - IF ( abs_s( rc_fx[i - 1] ) > 32749 ) // 32749 = 0.99945 in Q15 + IF( abs_s( rc_fx[i - 1] ) > 32749 ) // 32749 = 0.99945 in Q15 { flag = 1; /* Test for unstable filter. If unstable keep old A(z) */ } - FOR ( j = 1; j <= shr(i, 1); j++ ) + FOR( j = 1; j <= shr( i, 1 ); j++ ) { - l = sub(i, j); - at = L_add(a_fx[j], Mpy_32_16_1(a_fx[l], rc_fx[i - 1])); // Q(q_a) - a_fx[l] = L_add(a_fx[l], Mpy_32_16_1(a_fx[j], rc_fx[i - 1])); + l = sub( i, j ); + at = L_add( a_fx[j], Mpy_32_16_1( a_fx[l], rc_fx[i - 1] ) ); // Q(q_a) + a_fx[l] = L_add( a_fx[l], Mpy_32_16_1( a_fx[j], rc_fx[i - 1] ) ); a_fx[j] = at; move32(); } - a_fx[i] = L_shl(rc_fx[i - 1], sub(q_a, 15)); + a_fx[i] = L_shl( rc_fx[i - 1], sub( q_a, 15 ) ); - err = L_add(err, L_shl(Mpy_32_16_1(s, rc_fx[i - 1]), sub(31, q_a))); // q_err - q_s - IF ( LE_32(err, 0) ) + err = L_add( err, L_shl( Mpy_32_16_1( s, rc_fx[i - 1] ), sub( 31, q_a ) ) ); // q_err - q_s + IF( LE_32( err, 0 ) ) { - err = L_shr(327, 31 - q_r); // 327 = 0.01 in Q15 + err = L_shr( 327, 31 - q_r ); // 327 = 0.01 in Q15 } - IF ( epsP != NULL ) + IF( epsP != NULL ) { epsP[i] = err; move32(); diff --git a/lib_com/lpc_tools_fx.c b/lib_com/lpc_tools_fx.c index 3059e4a45..c5849e930 100644 --- a/lib_com/lpc_tools_fx.c +++ b/lib_com/lpc_tools_fx.c @@ -31,104 +31,104 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include #include -#include "options.h" /* Compilation switches */ -#include "ivas_cnst.h" /* Common constants */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "ivas_cnst.h" /* Common constants */ +#include "prot_fx2.h" /* Function prototypes */ #include "rom_com.h" #include "basop_util.h" - /*-----------------------------------------------------------------* - * Local constants - *-----------------------------------------------------------------*/ +/*-----------------------------------------------------------------* + * Local constants + *-----------------------------------------------------------------*/ -#define MAX_LEN_LP 960 /* maximum length in samples of the LP analysis window */ +#define MAX_LEN_LP 960 /* maximum length in samples of the LP analysis window */ /*-----------------------------------------------------------------* -* Local functions -*-----------------------------------------------------------------*/ + * Local functions + *-----------------------------------------------------------------*/ - /*---------------------------------------------------------------------* - * autocorr() - * - * Compute autocorrelations of input signal - *---------------------------------------------------------------------*/ +/*---------------------------------------------------------------------* + * autocorr() + * + * Compute autocorrelations of input signal + *---------------------------------------------------------------------*/ void autocorr_fx( - const Word16 x[], /* i : Input signal */ - const Word16 m, /* i : LPC order Q0 */ - Word16 r_h[], /* o : Autocorrelations (msb) Q15 */ - Word16 r_l[], /* o : Autocorrelations (lsb) */ - Word16 *Q_r, /* o : normalisation shift of r Q0 */ - const Word16 len, /* i : Frame lenght */ - const Word16* wind, /* i : Window used */ + const Word16 x[], /* i : Input signal */ + const Word16 m, /* i : LPC order Q0 */ + Word16 r_h[], /* o : Autocorrelations (msb) Q15 */ + Word16 r_l[], /* o : Autocorrelations (lsb) */ + Word16 *Q_r, /* o : normalisation shift of r Q0 */ + const Word16 len, /* i : Frame lenght */ + const Word16 *wind, /* i : Window used */ Word16 rev_flag, - const Word16 sym_flag /* i : symmetric window flag */ + const Word16 sym_flag /* i : symmetric window flag */ ) { Word16 i, j, norm, shift, y[MAX_LEN_LP]; Word16 fact; Word32 L_sum, L_tmp; - IF(EQ_16(rev_flag,1)) + IF( EQ_16( rev_flag, 1 ) ) { /* Windowing of signal */ - FOR (i = 0; i < len; i++) + FOR( i = 0; i < len; i++ ) { - y[i] = mult_r(x[i], wind[len-i-1]); + y[i] = mult_r( x[i], wind[len - i - 1] ); move16(); } } - ELSE IF( EQ_16(sym_flag,1)) + ELSE IF( EQ_16( sym_flag, 1 ) ) { /* symmetric window of even length */ - FOR( i=0; i 0) + IF( shift > 0 ) { - fact = lshr(-32768, shift); - FOR (i = 0; i < len; i++) + fact = lshr( -32768, shift ); + FOR( i = 0; i < len; i++ ) { - y[i] = mult_r(y[i], fact); + y[i] = mult_r( y[i], fact ); move16(); } } @@ -139,101 +139,101 @@ void autocorr_fx( } /* Compute and normalize r[0] */ - L_sum = L_mac(1, y[0], y[0]); - FOR (i = 1; i < len; i++) + L_sum = L_mac( 1, y[0], y[0] ); + FOR( i = 1; i < len; i++ ) { - L_sum = L_mac(L_sum, y[i], y[i]); + L_sum = L_mac( L_sum, y[i], y[i] ); } - norm = norm_l(L_sum); - L_sum = L_shl(L_sum, norm); - L_Extract(L_sum, &r_h[0], &r_l[0]); /* Put in DPF format (see oper_32b) */ + norm = norm_l( L_sum ); + L_sum = L_shl( L_sum, norm ); + L_Extract( L_sum, &r_h[0], &r_l[0] ); /* Put in DPF format (see oper_32b) */ /* Compute r[1] to r[m] */ - FOR (i = 1; i <= m; i++) + FOR( i = 1; i <= m; i++ ) { - L_sum = L_mult(y[0],y[i]); - FOR (j = 1; j < len - i; j++) + L_sum = L_mult( y[0], y[i] ); + FOR( j = 1; j < len - i; j++ ) { - L_sum = L_mac(L_sum, y[j], y[j + i]); + L_sum = L_mac( L_sum, y[j], y[j + i] ); } - L_sum = L_shl(L_sum, norm); - L_Extract(L_sum, &r_h[i], &r_l[i]); /* Put in DPF format (see oper_32b) */ + L_sum = L_shl( L_sum, norm ); + L_Extract( L_sum, &r_h[i], &r_l[i] ); /* Put in DPF format (see oper_32b) */ } - *Q_r = sub(norm, shl(shift, 1)); + *Q_r = sub( norm, shl( shift, 1 ) ); move16(); } #ifdef IVAS_FLOAT_FIXED void autocorr_fx_32( - const Word16 x[], /* i : Input signal */ - const Word16 m, /* i : LPC order Q0 */ - Word32 r[], /* o : Autocorrelations (msb) */ - Word16 *Q_r, /* o : normalisation shift of r Q0 */ - const Word16 len, /* i : Frame lenght */ - const Word16* wind, /* i : Window used */ + const Word16 x[], /* i : Input signal */ + const Word16 m, /* i : LPC order Q0 */ + Word32 r[], /* o : Autocorrelations (msb) */ + Word16 *Q_r, /* o : normalisation shift of r Q0 */ + const Word16 len, /* i : Frame lenght */ + const Word16 *wind, /* i : Window used */ Word16 rev_flag, - const Word16 sym_flag /* i : symmetric window flag */ + const Word16 sym_flag /* i : symmetric window flag */ ) { Word16 i, j, norm, shift, y[MAX_LEN_LP]; Word16 fact; Word32 L_sum, L_tmp; - IF(EQ_16(rev_flag,1)) + IF( EQ_16( rev_flag, 1 ) ) { /* Windowing of signal */ - FOR (i = 0; i < len; i++) + FOR( i = 0; i < len; i++ ) { - y[i] = mult_r(x[i], wind[len-i-1]); + y[i] = mult_r( x[i], wind[len - i - 1] ); move16(); } } - ELSE IF( EQ_16(sym_flag,1)) + ELSE IF( EQ_16( sym_flag, 1 ) ) { /* symmetric window of even length */ - FOR( i=0; i 0) + IF( shift > 0 ) { - fact = lshr(-32768, shift); - FOR (i = 0; i < len; i++) + fact = lshr( -32768, shift ); + FOR( i = 0; i < len; i++ ) { - y[i] = mult_r(y[i], fact); + y[i] = mult_r( y[i], fact ); move16(); } } @@ -244,31 +244,31 @@ void autocorr_fx_32( } /* Compute and normalize r[0] */ - L_sum = L_mac(1, y[0], y[0]); - FOR (i = 1; i < len; i++) + L_sum = L_mac( 1, y[0], y[0] ); + FOR( i = 1; i < len; i++ ) { - L_sum = L_mac(L_sum, y[i], y[i]); + L_sum = L_mac( L_sum, y[i], y[i] ); } - norm = norm_l(L_sum); - L_sum = L_shl(L_sum, norm); + norm = norm_l( L_sum ); + L_sum = L_shl( L_sum, norm ); r[0] = L_sum; move32(); /* Compute r[1] to r[m] */ - FOR (i = 1; i <= m; i++) + FOR( i = 1; i <= m; i++ ) { - L_sum = L_mult(y[0],y[i]); - FOR (j = 1; j < len - i; j++) + L_sum = L_mult( y[0], y[i] ); + FOR( j = 1; j < len - i; j++ ) { - L_sum = L_mac(L_sum, y[j], y[j + i]); + L_sum = L_mac( L_sum, y[j], y[j + i] ); } - L_sum = L_shl(L_sum, norm); + L_sum = L_shl( L_sum, norm ); r[i] = L_sum; move32(); } - *Q_r = sub(norm, shl(shift, 1)); + *Q_r = sub( norm, shl( shift, 1 ) ); move16(); } #endif @@ -313,9 +313,8 @@ void autocorr_fx_32( * * * - result = L_num * (1/L_denom) * ***************************************************************************** -*/ -static -Word32 Div_32_opt (Word32 L_num, Word16 denom_hi, Word16 denom_lo) + */ +static Word32 Div_32_opt( Word32 L_num, Word16 denom_hi, Word16 denom_lo ) { Word16 approx /*, hi, lo, n_hi , n_lo*/; Word32 L_32; @@ -325,25 +324,25 @@ Word32 Div_32_opt (Word32 L_num, Word16 denom_hi, Word16 denom_lo) /* First approximation: 1 / L_denom = 1/denom_hi */ - approx = div_s ((Word16) 0x3fff, denom_hi); + approx = div_s( (Word16) 0x3fff, denom_hi ); /* 1/L_denom = approx * (2.0 - L_denom * approx) */ - L_32 = Msu_32_16 ((Word32) 0x7fffffffL, denom_hi, denom_lo, approx); + L_32 = Msu_32_16( (Word32) 0x7fffffffL, denom_hi, denom_lo, approx ); - L_32 = Mpy_32_16_1(L_32, approx); + L_32 = Mpy_32_16_1( L_32, approx ); /* L_num * (1/L_denom) */ - L_32 = Mpy_32_32(L_num, L_32); + L_32 = Mpy_32_32( L_num, L_32 ); #ifdef BASOP_NOGLOB - L_32 = L_shl_o (L_32, 2, &Overflow); -#else /* BASOP_NOGLOB */ - L_32 = L_shl (L_32, 2); + L_32 = L_shl_o( L_32, 2, &Overflow ); +#else /* BASOP_NOGLOB */ + L_32 = L_shl( L_32, 2 ); #endif /* BASOP_NOGLOB */ - return (L_32); + return ( L_32 ); } /* @@ -363,135 +362,129 @@ Word32 Div_32_opt (Word32 L_num, Word16 denom_hi, Word16 denom_lo) * Returns: * void */ -Word16 E_LPC_lev_dur(const Word16 Rh[], const Word16 Rl[], Word16 A[], - Word32 epsP[], const Word16 order - ,Word16 *mem - ) +Word16 E_LPC_lev_dur( const Word16 Rh[], const Word16 Rl[], Word16 A[], Word32 epsP[], const Word16 order, Word16 *mem ) { - return(E_LPC_lev_dur_stab(Rh, Rl, A, epsP, order, mem, 32750)); /* 0.99945 in Q15 */ + return ( E_LPC_lev_dur_stab( Rh, Rl, A, epsP, order, mem, 32750 ) ); /* 0.99945 in Q15 */ } -Word16 E_LPC_lev_dur_stab(const Word16 Rh[], const Word16 Rl[], Word16 A[], - Word32 epsP[], const Word16 order, - Word16 *mem, Word16 k_max - ) +Word16 E_LPC_lev_dur_stab( const Word16 Rh[], const Word16 Rl[], Word16 A[], Word32 epsP[], const Word16 order, Word16 *mem, Word16 k_max ) { Word16 i, j, k; Word16 hi, lo; - Word16 Kh, Kl; /* reflection coefficient; hi and lo */ - Word16 alp_h, alp_l, alp_exp; /* Prediction gain; hi lo and exponent */ - Word32 t0, t1, t2; /* temporary variables */ + Word16 Kh, Kl; /* reflection coefficient; hi and lo */ + Word16 alp_h, alp_l, alp_exp; /* Prediction gain; hi lo and exponent */ + Word32 t0, t1, t2; /* temporary variables */ Word16 flag; - Word16 Ah[TCXLTP_LTP_ORDER + 1], Al[TCXLTP_LTP_ORDER + 1]; /* LPC coef. in double prec. */ + Word16 Ah[TCXLTP_LTP_ORDER + 1], Al[TCXLTP_LTP_ORDER + 1]; /* LPC coef. in double prec. */ #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif BASOP_SATURATE_WARNING_OFF_EVS - if(epsP!=NULL) + if ( epsP != NULL ) { - epsP[0] = L_Comp(Rh[0], Rl[0]); + epsP[0] = L_Comp( Rh[0], Rl[0] ); move32(); } - flag=0; + flag = 0; move16(); /* K = A[1] = -R[1] / R[0] */ - t1 = L_Comp(Rh[1], Rl[1]); /* R[1] in Q31 */ - t2 = L_abs(t1); /* abs R[1] */ - t0 = L_deposit_l(0); - IF (Rh[0] != 0) + t1 = L_Comp( Rh[1], Rl[1] ); /* R[1] in Q31 */ + t2 = L_abs( t1 ); /* abs R[1] */ + t0 = L_deposit_l( 0 ); + IF( Rh[0] != 0 ) { - t0 = Div_32_opt(t2, Rh[0], Rl[0]); /* R[1]/R[0] in Q31 */ + t0 = Div_32_opt( t2, Rh[0], Rl[0] ); /* R[1]/R[0] in Q31 */ /* Cause a difference in MODE1 due to different implementation of div32*/ } - if (t1 > 0) + if ( t1 > 0 ) { - t0 = L_negate(t0); /* -R[1]/R[0] */ + t0 = L_negate( t0 ); /* -R[1]/R[0] */ } - Kl = L_Extract_lc(t0, &Kh); /* K in DPF */ - t0 = L_shr(t0, 4); /* A[1] in Q27 */ - L_Extract(t0, &Ah[1], &Al[1]); /* A[1] in DPF */ + Kl = L_Extract_lc( t0, &Kh ); /* K in DPF */ + t0 = L_shr( t0, 4 ); /* A[1] in Q27 */ + L_Extract( t0, &Ah[1], &Al[1] ); /* A[1] in DPF */ /* Alpha = R[0] * (1-K**2) */ - t0 = Sqr_32(Kh, Kl); /* K*K in Q31 */ - t0 = L_abs(t0); /* Some case <0 !! */ - t0 = L_sub((Word32) 0x7fffffffL, t0); /* 1 - K*K in Q31 */ - lo = L_Extract_lc(t0, &hi); /* DPF format */ - t0 = Mpy_32(Rh[0], Rl[0], hi, lo); /* Alpha in Q31 */ - if(epsP!=NULL) + t0 = Sqr_32( Kh, Kl ); /* K*K in Q31 */ + t0 = L_abs( t0 ); /* Some case <0 !! */ + t0 = L_sub( (Word32) 0x7fffffffL, t0 ); /* 1 - K*K in Q31 */ + lo = L_Extract_lc( t0, &hi ); /* DPF format */ + t0 = Mpy_32( Rh[0], Rl[0], hi, lo ); /* Alpha in Q31 */ + if ( epsP != NULL ) { epsP[1] = t0; move32(); } /* Normalize Alpha */ - alp_exp = norm_l(t0); - t0 = L_shl(t0, alp_exp); - alp_l = L_Extract_lc(t0, &alp_h); + alp_exp = norm_l( t0 ); + t0 = L_shl( t0, alp_exp ); + alp_l = L_Extract_lc( t0, &alp_h ); /* DPF format */ /*--------------------------------------* * ITERATIONS I=2 to m *--------------------------------------*/ - FOR (i = 2; i <= order; i++) + FOR( i = 2; i <= order; i++ ) { /* t0 = SUM(R[j]*A[i-j], j=1, i-1) + R[i] */ - t0 = L_deposit_l(0); - FOR (j = 1; j < i; j++) + t0 = L_deposit_l( 0 ); + FOR( j = 1; j < i; j++ ) { - t0 = Mac_32(t0, Rh[j], Rl[j], Ah[i - j], Al[i - j]); + t0 = Mac_32( t0, Rh[j], Rl[j], Ah[i - j], Al[i - j] ); } #ifdef BASOP_NOGLOB - t0 = L_shl_o(t0, 4, &Overflow); /* result in Q27 -> convert to Q31 */ -#else /* BASOP_NOGLOB */ - t0 = L_shl(t0, 4); /* result in Q27 -> convert to Q31 */ -#endif /* BASOP_NOGLOB */ - /* No overflow possible */ + t0 = L_shl_o( t0, 4, &Overflow ); /* result in Q27 -> convert to Q31 */ +#else /* BASOP_NOGLOB */ + t0 = L_shl( t0, 4 ); /* result in Q27 -> convert to Q31 */ +#endif /* BASOP_NOGLOB */ + /* No overflow possible */ /* Compose and add R[i] in Q3 */ #ifdef BASOP_NOGLOB - t0 = L_mac_o(t0, Rl[i], 1, &Overflow); - t0 = L_msu_o(t0, Rh[i], -32768, &Overflow); -#else /* BASOP_NOGLOB */ - t0 = L_mac(t0, Rl[i], 1); - t0 = L_msu(t0, Rh[i], -32768); + t0 = L_mac_o( t0, Rl[i], 1, &Overflow ); + t0 = L_msu_o( t0, Rh[i], -32768, &Overflow ); +#else /* BASOP_NOGLOB */ + t0 = L_mac( t0, Rl[i], 1 ); + t0 = L_msu( t0, Rh[i], -32768 ); #endif /* BASOP_NOGLOB */ /* K = -t0 / Alpha */ - t1 = L_abs(t0); - t2 = L_deposit_l(0); - IF (alp_h != 0) + t1 = L_abs( t0 ); + t2 = L_deposit_l( 0 ); + IF( alp_h != 0 ) { - t2 = Div_32_opt(t1, alp_h, alp_l); /* abs(t0)/Alpha */ + t2 = Div_32_opt( t1, alp_h, alp_l ); /* abs(t0)/Alpha */ /* Cause a difference in MODE1 due to different implementation of div32*/ } - if (t0 > 0) + if ( t0 > 0 ) { - t2 = L_negate(t2); /* K =-t0/Alpha */ + t2 = L_negate( t2 ); /* K =-t0/Alpha */ } #ifdef BASOP_NOGLOB - t2 = L_shl_o(t2, alp_exp, &Overflow); /* denormalize; compare to Alpha */ -#else /* BASOP_NOGLOB */ - t2 = L_shl(t2, alp_exp); /* denormalize; compare to Alpha */ -#endif /* BASOP_NOGLOB */ + t2 = L_shl_o( t2, alp_exp, &Overflow ); /* denormalize; compare to Alpha */ +#else /* BASOP_NOGLOB */ + t2 = L_shl( t2, alp_exp ); /* denormalize; compare to Alpha */ +#endif /* BASOP_NOGLOB */ test(); - if ((mem!=NULL) && ((GT_16(abs_s(extract_h(t2)), k_max)))) + if ( ( mem != NULL ) && ( ( GT_16( abs_s( extract_h( t2 ) ), k_max ) ) ) ) { - flag=1; - move16();/* Test for unstable filter. If unstable keep old A(z) */ + flag = 1; + move16(); /* Test for unstable filter. If unstable keep old A(z) */ } - if ((mem!=NULL) && ((LT_32(L_abs(t2), 5)))) + if ( ( mem != NULL ) && ( ( LT_32( L_abs( t2 ), 5 ) ) ) ) { - flag=1; + flag = 1; move16(); /*R matrix not reliable (R saturated for many coeff), keep old A(z) */ } - Kl = L_Extract_lc(t2, &Kh); /* K in DPF */ + Kl = L_Extract_lc( t2, &Kh ); /* K in DPF */ /*------------------------------------------* * Compute new LPC coeff. -> An[i] @@ -499,307 +492,301 @@ Word16 E_LPC_lev_dur_stab(const Word16 Rh[], const Word16 Rl[], Word16 A[], * An[i]= K *------------------------------------------*/ - k = mult_r(i, 16384); - FOR (j = 1; j < k; j++) + k = mult_r( i, 16384 ); + FOR( j = 1; j < k; j++ ) { /* Do two Iterations Together to Allow Direct Update of Ah & Al */ - t0 = Mac_32(L_Comp(Ah[j], Al[j]), Kh, Kl, Ah[i-j], Al[i-j]); - t1 = Mac_32(L_Comp(Ah[i-j], Al[i-j]), Kh, Kl, Ah[j], Al[j]); - L_Extract(t0, &Ah[j], &Al[j]); - L_Extract(t1, &Ah[i-j], &Al[i-j]); + t0 = Mac_32( L_Comp( Ah[j], Al[j] ), Kh, Kl, Ah[i - j], Al[i - j] ); + t1 = Mac_32( L_Comp( Ah[i - j], Al[i - j] ), Kh, Kl, Ah[j], Al[j] ); + L_Extract( t0, &Ah[j], &Al[j] ); + L_Extract( t1, &Ah[i - j], &Al[i - j] ); } - IF (s_and(i, 1) == 0) + IF( s_and( i, 1 ) == 0 ) { - t0 = Mac_32(L_Comp(Ah[j], Al[j]), Kh, Kl, Ah[i-j], Al[i-j]); - L_Extract(t0, &Ah[j], &Al[j]); + t0 = Mac_32( L_Comp( Ah[j], Al[j] ), Kh, Kl, Ah[i - j], Al[i - j] ); + L_Extract( t0, &Ah[j], &Al[j] ); } - t2 = L_shr(t2, 4); /* t2 = K in Q31 ->convert to Q27 */ - L_Extract(t2, &Ah[i], &Al[i]); /* An[i] in Q27 */ + t2 = L_shr( t2, 4 ); /* t2 = K in Q31 ->convert to Q27 */ + L_Extract( t2, &Ah[i], &Al[i] ); /* An[i] in Q27 */ /* Alpha = Alpha * (1-K**2) */ #ifdef BASOP_NOGLOB - t1 = L_mult_o(Kh, Kh, &Overflow); /* K*K in Q31 */ -#else /* BASOP_NOGLOB */ - t1 = L_mult(Kh, Kh); /* K*K in Q31 */ -#endif /* BASOP_NOGLOB */ - t0 = L_mac(t1, mult(Kh, Kl), 2); - t0 = L_abs(t0); /* Some case <0 !! */ - t0 = L_sub((Word32) 0x7fffffffL, t0); /* 1 - K*K in Q31 */ - lo = L_Extract_lc(t0, &hi); /* DPF format */ - t0 = Mpy_32(alp_h, alp_l, hi, lo); /* Alpha in Q31 */ + t1 = L_mult_o( Kh, Kh, &Overflow ); /* K*K in Q31 */ +#else /* BASOP_NOGLOB */ + t1 = L_mult( Kh, Kh ); /* K*K in Q31 */ +#endif /* BASOP_NOGLOB */ + t0 = L_mac( t1, mult( Kh, Kl ), 2 ); + t0 = L_abs( t0 ); /* Some case <0 !! */ + t0 = L_sub( (Word32) 0x7fffffffL, t0 ); /* 1 - K*K in Q31 */ + lo = L_Extract_lc( t0, &hi ); /* DPF format */ + t0 = Mpy_32( alp_h, alp_l, hi, lo ); /* Alpha in Q31 */ /* store denormalized alpha in epsP */ - t1 = L_shr(t0, alp_exp); - if(epsP!=NULL) + t1 = L_shr( t0, alp_exp ); + if ( epsP != NULL ) { epsP[i] = t1; move32(); } /* Normalize Alpha */ - j = norm_l(t0); - t0 = L_shl(t0, j); - alp_l = L_Extract_lc(t0, &alp_h);/* DPF format */ - alp_exp = add(alp_exp, j); /* Add normalization to alp_exp */ + j = norm_l( t0 ); + t0 = L_shl( t0, j ); + alp_l = L_Extract_lc( t0, &alp_h ); /* DPF format */ + alp_exp = add( alp_exp, j ); /* Add normalization to alp_exp */ } /* Adaptive scaling */ - t1 = L_deposit_l(0); - FOR (i = 1; i <= order; i++) + t1 = L_deposit_l( 0 ); + FOR( i = 1; i <= order; i++ ) { - t0 = L_Comp(Ah[i], Al[i]); - t1 = L_max( t1, L_abs(t0) ); + t0 = L_Comp( Ah[i], Al[i] ); + t1 = L_max( t1, L_abs( t0 ) ); } - k = s_min( norm_l( t1 ), 3 ); + k = s_min( norm_l( t1 ), 3 ); A[0] = shl( 2048, k ); move16(); - FOR (i = 1; i <= order; i++) + FOR( i = 1; i <= order; i++ ) { - t0 = L_Comp(Ah[i], Al[i]); + t0 = L_Comp( Ah[i], Al[i] ); #ifdef BASOP_NOGLOB - A[i] = round_fx_o(L_shl_o(t0, k, &Overflow), &Overflow); + A[i] = round_fx_o( L_shl_o( t0, k, &Overflow ), &Overflow ); #else - A[i] = round_fx(L_shl(t0, k)); + A[i] = round_fx( L_shl( t0, k ) ); #endif } BASOP_SATURATE_WARNING_ON_EVS - IF (mem != NULL) + IF( mem != NULL ) { /* Enforce stable LPC filter - parcorr[0] and parcorr[1] are not LPC coeffiecients */ - IF(flag) + IF( flag ) { - Copy(mem, A, order + 1); + Copy( mem, A, order + 1 ); } ELSE /* If stable LPC filter, store into memories */ { - Copy(A, mem, order + 1); + Copy( A, mem, order + 1 ); } } - return(flag); + return ( flag ); } -Word16 E_LPC_lev_dur_fx(const Word16 Rh[], const Word16 Rl[], Word32 A[], - Word32 epsP[], const Word16 order - , Word32 *mem -) +Word16 E_LPC_lev_dur_fx( const Word16 Rh[], const Word16 Rl[], Word32 A[], Word32 epsP[], const Word16 order, Word32 *mem ) { - return(E_LPC_lev_dur_stab_fx(Rh, Rl, A, epsP, order, mem, 32750)); /* 0.99945 in Q15 */ + return ( E_LPC_lev_dur_stab_fx( Rh, Rl, A, epsP, order, mem, 32750 ) ); /* 0.99945 in Q15 */ } -Word16 E_LPC_lev_dur_stab_fx(const Word16 Rh[], const Word16 Rl[], Word32 A[], - Word32 epsP[], const Word16 order, - Word32 *mem, Word16 k_max -) +Word16 E_LPC_lev_dur_stab_fx( const Word16 Rh[], const Word16 Rl[], Word32 A[], Word32 epsP[], const Word16 order, Word32 *mem, Word16 k_max ) { - Word16 i, j, k; - Word16 hi, lo; - Word16 Kh, Kl; /* reflection coefficient; hi and lo */ - Word16 alp_h, alp_l, alp_exp; /* Prediction gain; hi lo and exponent */ - Word32 t0, t1, t2; /* temporary variables */ - Word16 flag; - Word16 Ah[TCXLTP_LTP_ORDER + 1], Al[TCXLTP_LTP_ORDER + 1]; /* LPC coef. in double prec. */ + Word16 i, j, k; + Word16 hi, lo; + Word16 Kh, Kl; /* reflection coefficient; hi and lo */ + Word16 alp_h, alp_l, alp_exp; /* Prediction gain; hi lo and exponent */ + Word32 t0, t1, t2; /* temporary variables */ + Word16 flag; + Word16 Ah[TCXLTP_LTP_ORDER + 1], Al[TCXLTP_LTP_ORDER + 1]; /* LPC coef. in double prec. */ #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; + Flag Overflow = 0; #endif - BASOP_SATURATE_WARNING_OFF_EVS - if (epsP != NULL) + BASOP_SATURATE_WARNING_OFF_EVS + if ( epsP != NULL ) { - epsP[0] = L_Comp(Rh[0], Rl[0]); - move32(); + epsP[0] = L_Comp( Rh[0], Rl[0] ); + move32(); } - flag = 0; - move16(); - - /* K = A[1] = -R[1] / R[0] */ - t1 = L_Comp(Rh[1], Rl[1]); /* R[1] in Q31 */ - t2 = L_abs(t1); /* abs R[1] */ - t0 = L_deposit_l(0); - IF(Rh[0] != 0) - { - t0 = Div_32_opt(t2, Rh[0], Rl[0]); /* R[1]/R[0] in Q31 */ - /* Cause a difference in MODE1 due to different implementation of div32*/ - } - if (t1 > 0) - { - t0 = L_negate(t0); /* -R[1]/R[0] */ - } - Kl = L_Extract_lc(t0, &Kh); /* K in DPF */ - t0 = L_shr(t0, 4); /* A[1] in Q27 */ - L_Extract(t0, &Ah[1], &Al[1]); /* A[1] in DPF */ - - /* Alpha = R[0] * (1-K**2) */ - t0 = Sqr_32(Kh, Kl); /* K*K in Q31 */ - t0 = L_abs(t0); /* Some case <0 !! */ - t0 = L_sub((Word32)0x7fffffffL, t0); /* 1 - K*K in Q31 */ - lo = L_Extract_lc(t0, &hi); /* DPF format */ - t0 = Mpy_32(Rh[0], Rl[0], hi, lo); /* Alpha in Q31 */ - if (epsP != NULL) - { - epsP[1] = t0; - move32(); - } - - /* Normalize Alpha */ - alp_exp = norm_l(t0); - t0 = L_shl(t0, alp_exp); - alp_l = L_Extract_lc(t0, &alp_h); - /* DPF format */ - - /*--------------------------------------* - * ITERATIONS I=2 to m - *--------------------------------------*/ - - FOR(i = 2; i <= order; i++) - { - /* t0 = SUM(R[j]*A[i-j], j=1, i-1) + R[i] */ - t0 = L_deposit_l(0); - FOR(j = 1; j < i; j++) + flag = 0; + move16(); + + /* K = A[1] = -R[1] / R[0] */ + t1 = L_Comp( Rh[1], Rl[1] ); /* R[1] in Q31 */ + t2 = L_abs( t1 ); /* abs R[1] */ + t0 = L_deposit_l( 0 ); + IF( Rh[0] != 0 ) { - t0 = Mac_32(t0, Rh[j], Rl[j], Ah[i - j], Al[i - j]); + t0 = Div_32_opt( t2, Rh[0], Rl[0] ); /* R[1]/R[0] in Q31 */ + /* Cause a difference in MODE1 due to different implementation of div32*/ + } + if ( t1 > 0 ) + { + t0 = L_negate( t0 ); /* -R[1]/R[0] */ + } + Kl = L_Extract_lc( t0, &Kh ); /* K in DPF */ + t0 = L_shr( t0, 4 ); /* A[1] in Q27 */ + L_Extract( t0, &Ah[1], &Al[1] ); /* A[1] in DPF */ + + /* Alpha = R[0] * (1-K**2) */ + t0 = Sqr_32( Kh, Kl ); /* K*K in Q31 */ + t0 = L_abs( t0 ); /* Some case <0 !! */ + t0 = L_sub( (Word32) 0x7fffffffL, t0 ); /* 1 - K*K in Q31 */ + lo = L_Extract_lc( t0, &hi ); /* DPF format */ + t0 = Mpy_32( Rh[0], Rl[0], hi, lo ); /* Alpha in Q31 */ + if ( epsP != NULL ) + { + epsP[1] = t0; + move32(); } + /* Normalize Alpha */ + alp_exp = norm_l( t0 ); + t0 = L_shl( t0, alp_exp ); + alp_l = L_Extract_lc( t0, &alp_h ); + /* DPF format */ + + /*--------------------------------------* + * ITERATIONS I=2 to m + *--------------------------------------*/ + + FOR( i = 2; i <= order; i++ ) + { + /* t0 = SUM(R[j]*A[i-j], j=1, i-1) + R[i] */ + t0 = L_deposit_l( 0 ); + FOR( j = 1; j < i; j++ ) + { + t0 = Mac_32( t0, Rh[j], Rl[j], Ah[i - j], Al[i - j] ); + } + #ifdef BASOP_NOGLOB - t0 = L_shl_o(t0, 4, &Overflow); /* result in Q27 -> convert to Q31 */ -#else /* BASOP_NOGLOB */ - t0 = L_shl(t0, 4); /* result in Q27 -> convert to Q31 */ -#endif /* BASOP_NOGLOB */ - /* No overflow possible */ + t0 = L_shl_o( t0, 4, &Overflow ); /* result in Q27 -> convert to Q31 */ +#else /* BASOP_NOGLOB */ + t0 = L_shl( t0, 4 ); /* result in Q27 -> convert to Q31 */ +#endif /* BASOP_NOGLOB */ + /* No overflow possible */ /* Compose and add R[i] in Q3 */ #ifdef BASOP_NOGLOB - t0 = L_mac_o(t0, Rl[i], 1, &Overflow); - t0 = L_msu_o(t0, Rh[i], -32768, &Overflow); -#else /* BASOP_NOGLOB */ - t0 = L_mac(t0, Rl[i], 1); - t0 = L_msu(t0, Rh[i], -32768); + t0 = L_mac_o( t0, Rl[i], 1, &Overflow ); + t0 = L_msu_o( t0, Rh[i], -32768, &Overflow ); +#else /* BASOP_NOGLOB */ + t0 = L_mac( t0, Rl[i], 1 ); + t0 = L_msu( t0, Rh[i], -32768 ); #endif /* BASOP_NOGLOB */ - /* K = -t0 / Alpha */ - t1 = L_abs(t0); - t2 = L_deposit_l(0); - IF(alp_h != 0) - { - t2 = Div_32_opt(t1, alp_h, alp_l); /* abs(t0)/Alpha */ - /* Cause a difference in MODE1 due to different implementation of div32*/ - } + /* K = -t0 / Alpha */ + t1 = L_abs( t0 ); + t2 = L_deposit_l( 0 ); + IF( alp_h != 0 ) + { + t2 = Div_32_opt( t1, alp_h, alp_l ); /* abs(t0)/Alpha */ + /* Cause a difference in MODE1 due to different implementation of div32*/ + } - if (t0 > 0) - { - t2 = L_negate(t2); /* K =-t0/Alpha */ - } + if ( t0 > 0 ) + { + t2 = L_negate( t2 ); /* K =-t0/Alpha */ + } #ifdef BASOP_NOGLOB - t2 = L_shl_o(t2, alp_exp, &Overflow); /* denormalize; compare to Alpha */ -#else /* BASOP_NOGLOB */ - t2 = L_shl(t2, alp_exp); /* denormalize; compare to Alpha */ -#endif /* BASOP_NOGLOB */ - test(); - if ((mem != NULL) && ((GT_16(abs_s(extract_h(t2)), k_max)))) - { - flag = 1; - move16();/* Test for unstable filter. If unstable keep old A(z) */ - } - if ((mem != NULL) && ((LT_32(L_abs(t2), 5)))) - { - flag = 1; - move16(); /*R matrix not reliable (R saturated for many coeff), keep old A(z) */ - } - Kl = L_Extract_lc(t2, &Kh); /* K in DPF */ + t2 = L_shl_o( t2, alp_exp, &Overflow ); /* denormalize; compare to Alpha */ +#else /* BASOP_NOGLOB */ + t2 = L_shl( t2, alp_exp ); /* denormalize; compare to Alpha */ +#endif /* BASOP_NOGLOB */ + test(); + if ( ( mem != NULL ) && ( ( GT_16( abs_s( extract_h( t2 ) ), k_max ) ) ) ) + { + flag = 1; + move16(); /* Test for unstable filter. If unstable keep old A(z) */ + } + if ( ( mem != NULL ) && ( ( LT_32( L_abs( t2 ), 5 ) ) ) ) + { + flag = 1; + move16(); /*R matrix not reliable (R saturated for many coeff), keep old A(z) */ + } + Kl = L_Extract_lc( t2, &Kh ); /* K in DPF */ - /*------------------------------------------* - * Compute new LPC coeff. -> An[i] - * An[j]= A[j] + K*A[i-j] , j=1 to i-1 - * An[i]= K - *------------------------------------------*/ + /*------------------------------------------* + * Compute new LPC coeff. -> An[i] + * An[j]= A[j] + K*A[i-j] , j=1 to i-1 + * An[i]= K + *------------------------------------------*/ - k = mult_r(i, 16384); - FOR(j = 1; j < k; j++) - { - /* Do two Iterations Together to Allow Direct Update of Ah & Al */ - t0 = Mac_32(L_Comp(Ah[j], Al[j]), Kh, Kl, Ah[i - j], Al[i - j]); - t1 = Mac_32(L_Comp(Ah[i - j], Al[i - j]), Kh, Kl, Ah[j], Al[j]); - L_Extract(t0, &Ah[j], &Al[j]); - L_Extract(t1, &Ah[i - j], &Al[i - j]); - } - IF(s_and(i, 1) == 0) - { - t0 = Mac_32(L_Comp(Ah[j], Al[j]), Kh, Kl, Ah[i - j], Al[i - j]); - L_Extract(t0, &Ah[j], &Al[j]); - } - t2 = L_shr(t2, 4); /* t2 = K in Q31 ->convert to Q27 */ - L_Extract(t2, &Ah[i], &Al[i]); /* An[i] in Q27 */ + k = mult_r( i, 16384 ); + FOR( j = 1; j < k; j++ ) + { + /* Do two Iterations Together to Allow Direct Update of Ah & Al */ + t0 = Mac_32( L_Comp( Ah[j], Al[j] ), Kh, Kl, Ah[i - j], Al[i - j] ); + t1 = Mac_32( L_Comp( Ah[i - j], Al[i - j] ), Kh, Kl, Ah[j], Al[j] ); + L_Extract( t0, &Ah[j], &Al[j] ); + L_Extract( t1, &Ah[i - j], &Al[i - j] ); + } + IF( s_and( i, 1 ) == 0 ) + { + t0 = Mac_32( L_Comp( Ah[j], Al[j] ), Kh, Kl, Ah[i - j], Al[i - j] ); + L_Extract( t0, &Ah[j], &Al[j] ); + } + t2 = L_shr( t2, 4 ); /* t2 = K in Q31 ->convert to Q27 */ + L_Extract( t2, &Ah[i], &Al[i] ); /* An[i] in Q27 */ - /* Alpha = Alpha * (1-K**2) */ + /* Alpha = Alpha * (1-K**2) */ #ifdef BASOP_NOGLOB - t1 = L_mult_o(Kh, Kh, &Overflow); /* K*K in Q31 */ -#else /* BASOP_NOGLOB */ - t1 = L_mult(Kh, Kh); /* K*K in Q31 */ -#endif /* BASOP_NOGLOB */ - t0 = L_mac(t1, mult(Kh, Kl), 2); - t0 = L_abs(t0); /* Some case <0 !! */ - t0 = L_sub((Word32)0x7fffffffL, t0); /* 1 - K*K in Q31 */ - lo = L_Extract_lc(t0, &hi); /* DPF format */ - t0 = Mpy_32(alp_h, alp_l, hi, lo); /* Alpha in Q31 */ + t1 = L_mult_o( Kh, Kh, &Overflow ); /* K*K in Q31 */ +#else /* BASOP_NOGLOB */ + t1 = L_mult( Kh, Kh ); /* K*K in Q31 */ +#endif /* BASOP_NOGLOB */ + t0 = L_mac( t1, mult( Kh, Kl ), 2 ); + t0 = L_abs( t0 ); /* Some case <0 !! */ + t0 = L_sub( (Word32) 0x7fffffffL, t0 ); /* 1 - K*K in Q31 */ + lo = L_Extract_lc( t0, &hi ); /* DPF format */ + t0 = Mpy_32( alp_h, alp_l, hi, lo ); /* Alpha in Q31 */ - /* store denormalized alpha in epsP */ - t1 = L_shr(t0, alp_exp); - if (epsP != NULL) - { - epsP[i] = t1; - move32(); + /* store denormalized alpha in epsP */ + t1 = L_shr( t0, alp_exp ); + if ( epsP != NULL ) + { + epsP[i] = t1; + move32(); + } + + /* Normalize Alpha */ + j = norm_l( t0 ); + t0 = L_shl( t0, j ); + alp_l = L_Extract_lc( t0, &alp_h ); /* DPF format */ + alp_exp = add( alp_exp, j ); /* Add normalization to alp_exp */ } - /* Normalize Alpha */ - j = norm_l(t0); - t0 = L_shl(t0, j); - alp_l = L_Extract_lc(t0, &alp_h);/* DPF format */ - alp_exp = add(alp_exp, j); /* Add normalization to alp_exp */ - } - - /* Adaptive scaling */ - t1 = L_deposit_l(0); - FOR(i = 1; i <= order; i++) - { - t0 = L_Comp(Ah[i], Al[i]); - t1 = L_max(t1, L_abs(t0)); - } - k = s_min(norm_l(t1), 3); - A[0] = L_shl(2048, k + 16); - move16(); - FOR(i = 1; i <= order; i++) - { - t0 = L_Comp(Ah[i], Al[i]); + /* Adaptive scaling */ + t1 = L_deposit_l( 0 ); + FOR( i = 1; i <= order; i++ ) + { + t0 = L_Comp( Ah[i], Al[i] ); + t1 = L_max( t1, L_abs( t0 ) ); + } + k = s_min( norm_l( t1 ), 3 ); + A[0] = L_shl( 2048, k + 16 ); + move16(); + FOR( i = 1; i <= order; i++ ) + { + t0 = L_Comp( Ah[i], Al[i] ); #ifdef BASOP_NOGLOB - A[i] = L_shl_o(t0, k, &Overflow); + A[i] = L_shl_o( t0, k, &Overflow ); #else A[i] = L_shl(t0, k)); #endif - } - - BASOP_SATURATE_WARNING_ON_EVS - IF(mem != NULL) - { - /* Enforce stable LPC filter - parcorr[0] and parcorr[1] are not LPC coeffiecients */ - IF(flag) - { - Copy32(mem, A, order + 1); } - ELSE /* If stable LPC filter, store into memories */ + + BASOP_SATURATE_WARNING_ON_EVS + IF( mem != NULL ) { - Copy32(A, mem, order + 1); + /* Enforce stable LPC filter - parcorr[0] and parcorr[1] are not LPC coeffiecients */ + IF( flag ) + { + Copy32( mem, A, order + 1 ); + } + ELSE /* If stable LPC filter, store into memories */ + { + Copy32( A, mem, order + 1 ); + } } - } - return(flag); + return ( flag ); } @@ -818,60 +805,56 @@ Word16 E_LPC_lev_dur_stab_fx(const Word16 Rh[], const Word16 Rl[], Word32 A[], * Returns: * void */ -void E_LPC_a_add_tilt(const Word16 *a, Word16 *ap, Word16 gamma, Word16 m) +void E_LPC_a_add_tilt( const Word16 *a, Word16 *ap, Word16 gamma, Word16 m ) { Word16 i; - Word32 Amax, Atmp[M+2]; + Word32 Amax, Atmp[M + 2]; Word16 shift; - - Amax = L_mult( 16384, a[0] ); - FOR (i = 1; i <= m; i++) + FOR( i = 1; i <= m; i++ ) { - Atmp[i] = L_sub( L_mult(16384, a[i]), L_mult0(gamma, a[i-1]) ); + Atmp[i] = L_sub( L_mult( 16384, a[i] ), L_mult0( gamma, a[i - 1] ) ); move32(); Amax = L_max( Amax, L_abs( Atmp[i] ) ); } - Atmp[m+1] = L_negate( L_mult0(gamma, a[m]) ); + Atmp[m + 1] = L_negate( L_mult0( gamma, a[m] ) ); move32(); - Amax = L_max( Amax, L_abs( Atmp[m+1] ) ); + Amax = L_max( Amax, L_abs( Atmp[m + 1] ) ); shift = norm_l( Amax ); - ap[0] = shl( a[0], sub(shift,1) ); + ap[0] = shl( a[0], sub( shift, 1 ) ); move16(); - FOR (i = 1; i <= m; i++) + FOR( i = 1; i <= m; i++ ) { ap[i] = round_fx( L_shl( Atmp[i], shift ) ); } - ap[m+1] = round_fx( L_shl( Atmp[m+1], shift ) ); - + ap[m + 1] = round_fx( L_shl( Atmp[m + 1], shift ) ); } -void E_LPC_int_lpc_tcx(const Word16 lsp_old[], /* input : LSPs from past frame Q15 */ - const Word16 lsp_new[], /* input : LSPs from present frame Q15 */ - Word16 a[] /* output: interpolated LP coefficients Q12 */ - ) +void E_LPC_int_lpc_tcx( const Word16 lsp_old[], /* input : LSPs from past frame Q15 */ + const Word16 lsp_new[], /* input : LSPs from present frame Q15 */ + Word16 a[] /* output: interpolated LP coefficients Q12 */ +) { Word16 i, lsp[M]; - - FOR (i = 0; i < M; i++) + FOR( i = 0; i < M; i++ ) { /*lsp[i] = lsp_old[i]*0.125f + lsp_new[i]*0.875f;*/ - lsp[i] = round_fx(L_mac(L_mult(lsp_old[i],4096),lsp_new[i],28672)); + lsp[i] = round_fx( L_mac( L_mult( lsp_old[i], 4096 ), lsp_new[i], 28672 ) ); } - E_LPC_f_lsp_a_conversion(lsp, a, M); + E_LPC_f_lsp_a_conversion( lsp, a, M ); return; } static void lsp_reorder( - Word16 *lsp, /* (I/O): LSP vector (acos() domain) Q13*1.2732 */ - Word16 min_dist, /* (I): minimum required distance Q13*1.2732 */ - Word16 lpcorder /* (I): LPC order Q0 */ + Word16 *lsp, /* (I/O): LSP vector (acos() domain) Q13*1.2732 */ + Word16 min_dist, /* (I): minimum required distance Q13*1.2732 */ + Word16 lpcorder /* (I): LPC order Q0 */ ) { Word16 i; @@ -881,29 +864,28 @@ static void lsp_reorder( /* Verify the LSF ordering and minimum GAP */ lsp_min = min_dist; move16(); - FOR (i=0; i=0; --i) + FOR( i = lpcorder; i >= 0; --i ) { - lsp[i] = s_min(lsp[i], lsp_max); + lsp[i] = s_min( lsp[i], lsp_max ); move16(); - lsp_max = sub(lsp[i], min_dist); + lsp_max = sub( lsp[i], min_dist ); } } - } /* Approximate unweighting */ @@ -919,25 +901,25 @@ Word16 E_LPC_lsp_unweight( const lsp_unw_triplet *unw_coeffs = NULL; Word16 i; - step = 0; /* to avoid compilation warnings */ + step = 0; /* to avoid compilation warnings */ - assert(lpcorder == 16); + assert( lpcorder == 16 ); /* Table selection */ - IF (EQ_16(inv_gamma, GAMMA16k_INV)) + IF( EQ_16( inv_gamma, GAMMA16k_INV ) ) { unw_coeffs = p16_gamma0_94to1; move16(); } - ELSE IF (EQ_16(inv_gamma, GAMMA1_INV)) + ELSE IF( EQ_16( inv_gamma, GAMMA1_INV ) ) { unw_coeffs = p16_gamma0_92to1; move16(); } ELSE { - assert(0); + assert( 0 ); } /* step = M_PI/(float)(lpcorder+1); */ @@ -947,34 +929,34 @@ Word16 E_LPC_lsp_unweight( move16(); /* Apply acos() and get mean removed version */ - FOR (i=0; i 0.01f*2^27/2^30 */ - Word32 tmp_epsP; + Word16 i, j, temp16, mM1, mMi, s; + Word32 g0[M], *g1, tmp32; + const Word32 min_epsP = 1; /* > 0.01f*2^27/2^30 */ + Word32 tmp_epsP; + mM1 = sub( m, 1 ); - mM1 = sub(m,1); - - s = getScaleFactor32(r,add(m,1)); - IF (s!=0) + s = getScaleFactor32( r, add( m, 1 ) ); + IF( s != 0 ) { - scale_sig32(r,add(m,1),s); /* scale in-place */ + scale_sig32( r, add( m, 1 ), s ); /* scale in-place */ } g1 = r; - Copy32(r+1,g0,m); + Copy32( r + 1, g0, m ); /* compute g0[0]/g1[0], where g0[0] < g1[0] */ - temp16 = negate(divide3232(g0[0], g1[0])); + temp16 = negate( divide3232( g0[0], g1[0] ) ); reflCoeff[0] = temp16; move16(); move32(); epsP[0] = r[0]; - FOR (i=0; i= 0; specix++);*/ - WHILE (mult(s,spec_r[specix]) >= 0) specix = add(specix, 1); + WHILE( mult( s, spec_r[specix] ) >= 0 ) + specix = add( specix, 1 ); - tmp = divide1616(spec_r[specix-1], sub(spec_r[specix-1],spec_r[specix] ) ); + tmp = divide1616( spec_r[specix - 1], sub( spec_r[specix - 1], spec_r[specix] ) ); move16(); /*lsf[lsfix] = L_add(L_deposit_h(sub(specix,1)) , L_shl(L_deposit_l(tmp),1));*/ /*Q16*/ - lsf[lsfix] = add(shl(sub(specix,1),7) , shr((tmp),8)); /*7Q8*/ + lsf[lsfix] = add( shl( sub( specix, 1 ), 7 ), shr( ( tmp ), 8 ) ); /*7Q8*/ lsfix++; /*check for the next zero crossing*/ /*for (; s*spec_i[specix] >= 0; specix++);*/ - WHILE (mult(s,spec_i[specix]) >= 0) specix = add(specix, 1); + WHILE( mult( s, spec_i[specix] ) >= 0 ) + specix = add( specix, 1 ); - tmp = divide1616(spec_i[specix-1], sub(spec_i[specix-1],spec_i[specix]) ); + tmp = divide1616( spec_i[specix - 1], sub( spec_i[specix - 1], spec_i[specix] ) ); move16(); /*lsf[lsfix] = L_add(L_deposit_h(sub(specix,1)) , L_shl(L_deposit_l(tmp),1));*/ /*Q16*/ - lsf[lsfix] = add(shl(sub(specix,1),7) , shr((tmp),8)); /*7Q8*/ + lsf[lsfix] = add( shl( sub( specix, 1 ), 7 ), shr( ( tmp ), 8 ) ); /*7Q8*/ lsfix++; @@ -1132,12 +1114,12 @@ void spec2isf( spec_i[speclen] = s; move16(); - s = negate(s); + s = negate( s ); } - IF (LT_16(lsfix,16)) + IF( LT_16( lsfix, 16 ) ) { - FOR(i=0; i<16; i++) + FOR( i = 0; i < 16; i++ ) { lsf[i] = old_lsf[i]; move16(); @@ -1147,7 +1129,7 @@ void spec2isf( return; } -void E_LPC_a_lsf_isf_conversion(Word16 *lpcCoeffs, Word16 *lsf, const Word16 *old_lsf, Word16 lpcOrder, Word8 lpcRep) +void E_LPC_a_lsf_isf_conversion( Word16 *lpcCoeffs, Word16 *lsf, const Word16 *old_lsf, Word16 lpcOrder, Word8 lpcRep ) { Word32 RealFFT[128]; Word32 ImagFFT[128]; @@ -1168,136 +1150,135 @@ void E_LPC_a_lsf_isf_conversion(Word16 *lpcCoeffs, Word16 *lsf, const Word16 * #endif /* half length FFT */ - scale = add(norm_s(lpcCoeffs[0]),1)+5; + scale = add( norm_s( lpcCoeffs[0] ), 1 ) + 5; move16(); /*s = [sum(a) ((-1).^(1:length(a)))*a];*/ - L_tmp = L_deposit_h(0); - FOR(j=0; j<=lpcOrder; j++) + L_tmp = L_deposit_h( 0 ); + FOR( j = 0; j <= lpcOrder; j++ ) { - L_tmp = L_mac(L_tmp, lpcCoeffs[j], 0x800); + L_tmp = L_mac( L_tmp, lpcCoeffs[j], 0x800 ); } /*s[1] = round_fx(L_tmp); move16();*/ - L_tmp1 = L_deposit_h(0); - FOR(j=0; jv.re), lpc[2*j+1],ptwiddle->v.im),scale); + ptrReal[j * 8] = L_shl( L_msu( L_mult( lpc[2 * j], ptwiddle->v.re ), lpc[2 * j + 1], ptwiddle->v.im ), scale ); move32(); - ptrImag[j*8] = L_shl(L_mac(L_mult(lpc[2*j+1],ptwiddle->v.re), lpc[2*j],ptwiddle->v.im),scale); + ptrImag[j * 8] = L_shl( L_mac( L_mult( lpc[2 * j + 1], ptwiddle->v.re ), lpc[2 * j], ptwiddle->v.im ), scale ); move32(); ptwiddle++; } - ptrReal[j*8] = L_shl(L_mac(0,lpc[2*j],ptwiddle->v.re),scale); + ptrReal[j * 8] = L_shl( L_mac( 0, lpc[2 * j], ptwiddle->v.re ), scale ); move32(); - ptrImag[j*8] = L_shl(L_mac(0, lpc[2*j],ptwiddle->v.im),scale); + ptrImag[j * 8] = L_shl( L_mac( 0, lpc[2 * j], ptwiddle->v.im ), scale ); move32(); ptwiddle++; j++; - FOR(; j<16; j++) + FOR( ; j < 16; j++ ) { - ptrReal[j*8] = L_deposit_h(0); - ptrImag[j*8] = L_deposit_h(0); + ptrReal[j * 8] = L_deposit_h( 0 ); + ptrImag[j * 8] = L_deposit_h( 0 ); ptwiddle++; } - fft16(ptrReal, ptrImag, 8, 0); + fft16( ptrReal, ptrImag, 8, 0 ); ptrReal++; ptrImag++; - } /* pre-twiddle */ - BASOP_getTables(NULL, &ptwiddle, &step, 128); - IF (lpcRep != 0) + BASOP_getTables( NULL, &ptwiddle, &step, 128 ); + IF( lpcRep != 0 ) { pwn17i = &w19N[126]; pwn17 = w19N; @@ -1311,46 +1292,46 @@ void E_LPC_a_lsf_isf_conversion(Word16 *lpcCoeffs, Word16 *lsf, const Word16 * pwn15 = &tmpw15; pwn15i = &tmpw15; - RealOut[0] = round_fx(2*L_add(RealFFT[0], ImagFFT[0])); - ImagOut[0] = 0; + RealOut[0] = round_fx( 2 * L_add( RealFFT[0], ImagFFT[0] ) ); + ImagOut[0] = 0; move16(); RealOut[128] = 0; move16(); - ImagOut[128] = round_fx(L_sub(L_add(RealFFT[0],RealFFT[0]), L_add(ImagFFT[0], ImagFFT[0]))); + ImagOut[128] = round_fx( L_sub( L_add( RealFFT[0], RealFFT[0] ), L_add( ImagFFT[0], ImagFFT[0] ) ) ); ptwiddle += 8; - FOR(i=1; i<=N/2/4; i++) + FOR( i = 1; i <= N / 2 / 4; i++ ) { - Word16 ReAr = extract_h(L_add(RealFFT[i],RealFFT[N/2-i])); - Word16 ReBr = extract_h(L_sub(RealFFT[N/2-i], RealFFT[i])); - Word16 ImAr = extract_h(L_sub(ImagFFT[i], ImagFFT[N/2-i])); - Word16 ImBr = extract_h(L_add(ImagFFT[i], ImagFFT[N/2-i])); + Word16 ReAr = extract_h( L_add( RealFFT[i], RealFFT[N / 2 - i] ) ); + Word16 ReBr = extract_h( L_sub( RealFFT[N / 2 - i], RealFFT[i] ) ); + Word16 ImAr = extract_h( L_sub( ImagFFT[i], ImagFFT[N / 2 - i] ) ); + Word16 ImBr = extract_h( L_add( ImagFFT[i], ImagFFT[N / 2 - i] ) ); BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB - tmpw15.v.re = mac_ro(L_mult(ptwiddle->v.re, pwn17->v.re), ptwiddle->v.im, pwn17->v.im, &Overflow); - tmpw15.v.im = msu_ro(L_mult(ptwiddle->v.re, pwn17->v.im), ptwiddle->v.im, pwn17->v.re, &Overflow); -#else /* BASOP_NOGLOB */ - tmpw15.v.re = mac_r(L_mult(ptwiddle->v.re, pwn17->v.re), ptwiddle->v.im, pwn17->v.im); - tmpw15.v.im = msu_r(L_mult(ptwiddle->v.re, pwn17->v.im), ptwiddle->v.im, pwn17->v.re); + tmpw15.v.re = mac_ro( L_mult( ptwiddle->v.re, pwn17->v.re ), ptwiddle->v.im, pwn17->v.im, &Overflow ); + tmpw15.v.im = msu_ro( L_mult( ptwiddle->v.re, pwn17->v.im ), ptwiddle->v.im, pwn17->v.re, &Overflow ); +#else /* BASOP_NOGLOB */ + tmpw15.v.re = mac_r( L_mult( ptwiddle->v.re, pwn17->v.re ), ptwiddle->v.im, pwn17->v.im ); + tmpw15.v.im = msu_r( L_mult( ptwiddle->v.re, pwn17->v.im ), ptwiddle->v.im, pwn17->v.re ); #endif /* BASOP_NOGLOB */ BASOP_SATURATE_WARNING_ON_EVS - RealOut[i] = mac_r(L_msu(L_msu(L_mult(ReAr, pwn17->v.re),ImAr, pwn17->v.im), ReBr, pwn15->v.im), ImBr, pwn15->v.re); + RealOut[i] = mac_r( L_msu( L_msu( L_mult( ReAr, pwn17->v.re ), ImAr, pwn17->v.im ), ReBr, pwn15->v.im ), ImBr, pwn15->v.re ); move16(); - ImagOut[i] = mac_r(L_mac(L_mac(L_mult(ReAr, pwn17->v.im), ImAr, pwn17->v.re), ReBr, pwn15->v.re), ImBr, pwn15->v.im); + ImagOut[i] = mac_r( L_mac( L_mac( L_mult( ReAr, pwn17->v.im ), ImAr, pwn17->v.re ), ReBr, pwn15->v.re ), ImBr, pwn15->v.im ); move16(); BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB - tmpw15.v.re = msu_ro(L_mult(ptwiddle->v.im, pwn17i->v.im), ptwiddle->v.re, pwn17i->v.re, &Overflow); - tmpw15.v.im = mac_ro(L_mult(ptwiddle->v.re, pwn17i->v.im), ptwiddle->v.im, pwn17i->v.re, &Overflow); -#else /* BASOP_NOGLOB */ - tmpw15.v.re = msu_r(L_mult(ptwiddle->v.im, pwn17i->v.im), ptwiddle->v.re, pwn17i->v.re); - tmpw15.v.im = mac_r(L_mult(ptwiddle->v.re, pwn17i->v.im), ptwiddle->v.im, pwn17i->v.re); + tmpw15.v.re = msu_ro( L_mult( ptwiddle->v.im, pwn17i->v.im ), ptwiddle->v.re, pwn17i->v.re, &Overflow ); + tmpw15.v.im = mac_ro( L_mult( ptwiddle->v.re, pwn17i->v.im ), ptwiddle->v.im, pwn17i->v.re, &Overflow ); +#else /* BASOP_NOGLOB */ + tmpw15.v.re = msu_r( L_mult( ptwiddle->v.im, pwn17i->v.im ), ptwiddle->v.re, pwn17i->v.re ); + tmpw15.v.im = mac_r( L_mult( ptwiddle->v.re, pwn17i->v.im ), ptwiddle->v.im, pwn17i->v.re ); #endif /* BASOP_NOGLOB */ BASOP_SATURATE_WARNING_ON_EVS - RealOut[N/2-i] = msu_r(L_mac(L_mac(L_mult(ReAr, pwn17i->v.re), ImAr, pwn17i->v.im), ImBr, pwn15i->v.re), ReBr, pwn15i->v.im); + RealOut[N / 2 - i] = msu_r( L_mac( L_mac( L_mult( ReAr, pwn17i->v.re ), ImAr, pwn17i->v.im ), ImBr, pwn15i->v.re ), ReBr, pwn15i->v.im ); move16(); - ImagOut[N/2-i] = msu_r(L_msu(L_msu(L_mult(ReAr, pwn17i->v.im), ImAr, pwn17i->v.re), ReBr, pwn15i->v.re), ImBr, pwn15i->v.im); + ImagOut[N / 2 - i] = msu_r( L_msu( L_msu( L_mult( ReAr, pwn17i->v.im ), ImAr, pwn17i->v.re ), ReBr, pwn15i->v.re ), ImBr, pwn15i->v.im ); move16(); ptwiddle += 8; @@ -1360,37 +1341,37 @@ void E_LPC_a_lsf_isf_conversion(Word16 *lpcCoeffs, Word16 *lsf, const Word16 * ptwiddle -= 16; /*change real with imaginary for ptwiddle*/ - FOR(; iv.im, pwn17->v.re), ptwiddle->v.re, pwn17->v.im, &Overflow); - tmpw15.v.im = msu_ro(L_mult(ptwiddle->v.im, pwn17->v.im), ptwiddle->v.re, pwn17->v.re, &Overflow); -#else /* BASOP_NOGLOB */ - tmpw15.v.re = mac_r(L_mult(ptwiddle->v.im, pwn17->v.re), ptwiddle->v.re, pwn17->v.im); - tmpw15.v.im = msu_r(L_mult(ptwiddle->v.im, pwn17->v.im), ptwiddle->v.re, pwn17->v.re); + tmpw15.v.re = mac_ro( L_mult( ptwiddle->v.im, pwn17->v.re ), ptwiddle->v.re, pwn17->v.im, &Overflow ); + tmpw15.v.im = msu_ro( L_mult( ptwiddle->v.im, pwn17->v.im ), ptwiddle->v.re, pwn17->v.re, &Overflow ); +#else /* BASOP_NOGLOB */ + tmpw15.v.re = mac_r( L_mult( ptwiddle->v.im, pwn17->v.re ), ptwiddle->v.re, pwn17->v.im ); + tmpw15.v.im = msu_r( L_mult( ptwiddle->v.im, pwn17->v.im ), ptwiddle->v.re, pwn17->v.re ); #endif /* BASOP_NOGLOB */ BASOP_SATURATE_WARNING_ON_EVS - RealOut[i] = mac_r(L_msu(L_msu(L_mult(ReAr, pwn17->v.re),ImAr, pwn17->v.im), ReBr, pwn15->v.im), ImBr, pwn15->v.re); + RealOut[i] = mac_r( L_msu( L_msu( L_mult( ReAr, pwn17->v.re ), ImAr, pwn17->v.im ), ReBr, pwn15->v.im ), ImBr, pwn15->v.re ); move16(); - ImagOut[i] = mac_r(L_mac(L_mac(L_mult(ReAr, pwn17->v.im), ImAr, pwn17->v.re), ReBr, pwn15->v.re), ImBr, pwn15->v.im); + ImagOut[i] = mac_r( L_mac( L_mac( L_mult( ReAr, pwn17->v.im ), ImAr, pwn17->v.re ), ReBr, pwn15->v.re ), ImBr, pwn15->v.im ); move16(); BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB - tmpw15.v.re = msu_ro(L_mult(ptwiddle->v.re, pwn17i->v.im), ptwiddle->v.im, pwn17i->v.re, &Overflow); - tmpw15.v.im = mac_ro(L_mult(ptwiddle->v.im, pwn17i->v.im), ptwiddle->v.re, pwn17i->v.re, &Overflow); + tmpw15.v.re = msu_ro( L_mult( ptwiddle->v.re, pwn17i->v.im ), ptwiddle->v.im, pwn17i->v.re, &Overflow ); + tmpw15.v.im = mac_ro( L_mult( ptwiddle->v.im, pwn17i->v.im ), ptwiddle->v.re, pwn17i->v.re, &Overflow ); #else /* BASOP_NOGLOB */ - tmpw15.v.re = msu_r(L_mult(ptwiddle->v.re, pwn17i->v.im), ptwiddle->v.im, pwn17i->v.re); - tmpw15.v.im = mac_r(L_mult(ptwiddle->v.im, pwn17i->v.im), ptwiddle->v.re, pwn17i->v.re); + tmpw15.v.re = msu_r( L_mult( ptwiddle->v.re, pwn17i->v.im ), ptwiddle->v.im, pwn17i->v.re ); + tmpw15.v.im = mac_r( L_mult( ptwiddle->v.im, pwn17i->v.im ), ptwiddle->v.re, pwn17i->v.re ); #endif BASOP_SATURATE_WARNING_ON_EVS - RealOut[N/2-i] = msu_r(L_mac(L_mac(L_mult(ReAr, pwn17i->v.re), ImAr, pwn17i->v.im), ImBr, pwn15i->v.re), ReBr, pwn15i->v.im); + RealOut[N / 2 - i] = msu_r( L_mac( L_mac( L_mult( ReAr, pwn17i->v.re ), ImAr, pwn17i->v.im ), ImBr, pwn15i->v.re ), ReBr, pwn15i->v.im ); move16(); - ImagOut[N/2-i] = msu_r(L_msu(L_msu(L_mult(ReAr, pwn17i->v.im), ImAr, pwn17i->v.re), ReBr, pwn15i->v.re), ImBr, pwn15i->v.im); + ImagOut[N / 2 - i] = msu_r( L_msu( L_msu( L_mult( ReAr, pwn17i->v.im ), ImAr, pwn17i->v.re ), ReBr, pwn15i->v.re ), ImBr, pwn15i->v.im ); move16(); ptwiddle -= 8; @@ -1399,34 +1380,33 @@ void E_LPC_a_lsf_isf_conversion(Word16 *lpcCoeffs, Word16 *lsf, const Word16 * } ptwiddle += 0; { - Word16 ReAr = extract_h(L_add(RealFFT[i],RealFFT[N/2-i])); - Word16 ReBr = extract_h(L_sub(RealFFT[N/2-i], RealFFT[i])); - Word16 ImAr = extract_h(L_sub(ImagFFT[i], ImagFFT[N/2-i])); - Word16 ImBr = extract_h((L_negate(L_add(ImagFFT[i], ImagFFT[N/2-i])))); + Word16 ReAr = extract_h( L_add( RealFFT[i], RealFFT[N / 2 - i] ) ); + Word16 ReBr = extract_h( L_sub( RealFFT[N / 2 - i], RealFFT[i] ) ); + Word16 ImAr = extract_h( L_sub( ImagFFT[i], ImagFFT[N / 2 - i] ) ); + Word16 ImBr = extract_h( ( L_negate( L_add( ImagFFT[i], ImagFFT[N / 2 - i] ) ) ) ); BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB tmpw15.v.re = mac_r_sat( L_mult( ptwiddle->v.im, pwn17->v.re ), ptwiddle->v.re, pwn17->v.im ); - tmpw15.v.im = msu_r_sat(L_mult(ptwiddle->v.im, pwn17->v.im), ptwiddle->v.re, pwn17->v.re); + tmpw15.v.im = msu_r_sat( L_mult( ptwiddle->v.im, pwn17->v.im ), ptwiddle->v.re, pwn17->v.re ); #else - tmpw15.v.re = mac_r(L_mult(ptwiddle->v.im, pwn17->v.re), ptwiddle->v.re, pwn17->v.im); - tmpw15.v.im = msu_r(L_mult(ptwiddle->v.im, pwn17->v.im), ptwiddle->v.re, pwn17->v.re); + tmpw15.v.re = mac_r( L_mult( ptwiddle->v.im, pwn17->v.re ), ptwiddle->v.re, pwn17->v.im ); + tmpw15.v.im = msu_r( L_mult( ptwiddle->v.im, pwn17->v.im ), ptwiddle->v.re, pwn17->v.re ); #endif BASOP_SATURATE_WARNING_ON_EVS - RealOut[i] = msu_r(L_msu(L_msu(L_mult(ReAr, pwn17->v.re), ImAr, pwn17->v.im), ReBr, pwn15->v.im), ImBr, pwn15->v.re); + RealOut[i] = msu_r( L_msu( L_msu( L_mult( ReAr, pwn17->v.re ), ImAr, pwn17->v.im ), ReBr, pwn15->v.im ), ImBr, pwn15->v.re ); move16(); - ImagOut[i] = msu_r(L_mac(L_mac(L_mult(ReAr, pwn17->v.im), ImAr, pwn17->v.re), ReBr, pwn15->v.re), ImBr, pwn15->v.im); + ImagOut[i] = msu_r( L_mac( L_mac( L_mult( ReAr, pwn17->v.im ), ImAr, pwn17->v.re ), ReBr, pwn15->v.re ), ImBr, pwn15->v.im ); move16(); } - spec2isf(RealOut, ImagOut, 128, lsf, old_lsf); - IF (lpcRep == 0) + spec2isf( RealOut, ImagOut, 128, lsf, old_lsf ); + IF( lpcRep == 0 ) { - lsf[lpcOrder - 1] = shl(lpcCoeffs[lpcOrder], add(norm_s(lpcCoeffs[0]),1)); + lsf[lpcOrder - 1] = shl( lpcCoeffs[lpcOrder], add( norm_s( lpcCoeffs[0] ), 1 ) ); move16(); /* From Qx to Q15 with saturation */ - lsf[lpcOrder - 1] = xsp_to_xsf(lsf[lpcOrder - 1]); + lsf[lpcOrder - 1] = xsp_to_xsf( lsf[lpcOrder - 1] ); move16(); - lsf[lpcOrder - 1] = shr(lsf[lpcOrder - 1], 1); + lsf[lpcOrder - 1] = shr( lsf[lpcOrder - 1], 1 ); move16(); } - } diff --git a/lib_com/lsf_dec_bfi_fx.c b/lib_com/lsf_dec_bfi_fx.c index 45a3bb1d7..147c40846 100644 --- a/lib_com/lsf_dec_bfi_fx.c +++ b/lib_com/lsf_dec_bfi_fx.c @@ -13,59 +13,59 @@ /*---------------------------------------------------------------------* -* routine: lsf_dec_bfi() -* -* Estimate the LSFs in case of FER -* Bad frame, all active speech coders -*---------------------------------------------------------------------*/ + * routine: lsf_dec_bfi() + * + * Estimate the LSFs in case of FER + * Bad frame, all active speech coders + *---------------------------------------------------------------------*/ void lsf_dec_bfi( - const Word16 codec_mode, /* i: : codec mode: MODE1 | MODE2 */ - Word16*lsf, /*!< o : 14Q1*1.28 quantized ISFs */ - const Word16*lsfold, /*!< i : 14Q1*1.28 past quantized ISF */ - Word16*lsf_adaptive_mean, /*!< i : 14Q1*1.28 ISF adaptive mean, updated when BFI==0 */ - const Word16 lsfBase[], /* i : base for differential lsf coding */ - Word16*mem_MA, /*!< i/o: 14Q1*1.28 quantizer memory for MA model */ - Word16*mem_AR, /*!< i/o: 14Q1*1.28 quantizer memory for MA model */ - Word16 stab_fac, /*!< i : ISF stability factor (shifted right by 1) */ - const Word16 last_coder_type,/*!< i : coding type in last good received fr. */ + const Word16 codec_mode, /* i: : codec mode: MODE1 | MODE2 */ + Word16 *lsf, /*!< o : 14Q1*1.28 quantized ISFs */ + const Word16 *lsfold, /*!< i : 14Q1*1.28 past quantized ISF */ + Word16 *lsf_adaptive_mean, /*!< i : 14Q1*1.28 ISF adaptive mean, updated when BFI==0 */ + const Word16 lsfBase[], /* i : base for differential lsf coding */ + Word16 *mem_MA, /*!< i/o: 14Q1*1.28 quantizer memory for MA model */ + Word16 *mem_AR, /*!< i/o: 14Q1*1.28 quantizer memory for MA model */ + Word16 stab_fac, /*!< i : ISF stability factor (shifted right by 1) */ + const Word16 last_coder_type, /*!< i : coding type in last good received fr. */ Word16 L_frame, - const Word16 last_good, /*!< i : last good received frame */ - const Word16 nbLostCmpt, /*!< i : counter of consecutive bad frames */ - const Word8 plcBackgroundNoiseUpdated, /* i : background noise already updated?*/ - Word16 *lsf_q_cng, /* o : quantized ISFs for background noise (14Q1*1.28) */ + const Word16 last_good, /*!< i : last good received frame */ + const Word16 nbLostCmpt, /*!< i : counter of consecutive bad frames */ + const Word8 plcBackgroundNoiseUpdated, /* i : background noise already updated?*/ + Word16 *lsf_q_cng, /* o : quantized ISFs for background noise (14Q1*1.28) */ Word16 *lsf_cng, - Word16 *old_lsf_q_cng, /* o : old quantized ISFs for background noise */ + Word16 *old_lsf_q_cng, /* o : old quantized ISFs for background noise */ const Word16 Last_GSC_pit_band_idx, - const Word16 Opt_AMR_WB, /* i : IO flag */ - const Word8 tcxonly, - const short bwidth /* i: coded bandwidth */ + const Word16 Opt_AMR_WB, /* i : IO flag */ + const Word8 tcxonly, + const short bwidth /* i: coded bandwidth */ ) { Word16 i; Word16 alpha; Word32 tmp; Word16 lsf_mean[M]; - const Word16* pt_meansForFading; - const Word16* pt_meansForMemUpdate; + const Word16 *pt_meansForFading; + const Word16 *pt_meansForMemUpdate; Word16 beta; Word16 gap; - IF (EQ_16(codec_mode,MODE1)) + IF( EQ_16( codec_mode, MODE1 ) ) { pt_meansForMemUpdate = lsf_mean; /* Update inital guess to something stable, with proper sampling frequency and format (ISF/LSF)*/ - IF ( Opt_AMR_WB) + IF( Opt_AMR_WB ) { pt_meansForFading = Mean_isf_wb; } ELSE { /* 12.8kHz ACELP sampling */ - IF( EQ_16(L_frame,L_FRAME)) + IF( EQ_16( L_frame, L_FRAME ) ) { pt_meansForFading = GEWB_Ave_fx; - if (EQ_16(bwidth,NB)) + if ( EQ_16( bwidth, NB ) ) { pt_meansForFading = GENB_Ave_fx; } @@ -81,198 +81,194 @@ void lsf_dec_bfi( { pt_meansForFading = pt_meansForMemUpdate = lsfBase; test(); - if (lsf_cng != NULL && plcBackgroundNoiseUpdated) + if ( lsf_cng != NULL && plcBackgroundNoiseUpdated ) { pt_meansForFading = lsf_cng; } } - IF( LE_16(nbLostCmpt, 3)) + IF( LE_16( nbLostCmpt, 3 ) ) { test(); test(); - IF( (EQ_16(last_coder_type, UNVOICED))) /* Clear unvoiced last good frame */ + IF( ( EQ_16( last_coder_type, UNVOICED ) ) ) /* Clear unvoiced last good frame */ { move16(); alpha = _ALPHA_UU_FX; } - ELSE IF( EQ_16(last_coder_type,AUDIO)||EQ_16(last_good,INACTIVE_CLAS)) + ELSE IF( EQ_16( last_coder_type, AUDIO ) || EQ_16( last_good, INACTIVE_CLAS ) ) { - alpha = 32604/*0.995f Q15*/; + alpha = 32604 /*0.995f Q15*/; move16(); test(); - if( Last_GSC_pit_band_idx > 0 && GT_16(nbLostCmpt, 1)) + if ( Last_GSC_pit_band_idx > 0 && GT_16( nbLostCmpt, 1 ) ) { - alpha = 26214/*0.8f Q15*/; + alpha = 26214 /*0.8f Q15*/; move16(); } } - ELSE IF( EQ_16(last_good,UNVOICED_CLAS)) + ELSE IF( EQ_16( last_good, UNVOICED_CLAS ) ) { - IF( LE_16(nbLostCmpt,1)) + IF( LE_16( nbLostCmpt, 1 ) ) { /* If stable, do not flatten the spectrum in the 1st erased frame */ - alpha = add(mult(stab_fac, 32768 - _ALPHA_U_FX_X_2), _ALPHA_U_FX_X_2); + alpha = add( mult( stab_fac, 32768 - _ALPHA_U_FX_X_2 ), _ALPHA_U_FX_X_2 ); } - ELSE IF(EQ_16(nbLostCmpt,2)) + ELSE IF( EQ_16( nbLostCmpt, 2 ) ) { - alpha = sub(_ALPHA_U_FX_X_2,shr(_ALPHA_U_FX,1)); /* 0.6 */ + alpha = sub( _ALPHA_U_FX_X_2, shr( _ALPHA_U_FX, 1 ) ); /* 0.6 */ } ELSE { alpha = _ALPHA_U_FX; - move16(); /* go rapidly to CNG spectrum */ + move16(); /* go rapidly to CNG spectrum */ } } - ELSE IF( EQ_16(last_good ,UNVOICED_TRANSITION)) + ELSE IF( EQ_16( last_good, UNVOICED_TRANSITION ) ) { alpha = _ALPHA_UT_FX; move16(); } - ELSE IF( (EQ_16(last_good,VOICED_CLAS))||(EQ_16(last_good,ONSET))) + ELSE IF( ( EQ_16( last_good, VOICED_CLAS ) ) || ( EQ_16( last_good, ONSET ) ) ) { /* clearly voiced - mild convergence to the CNG spectrum for the first 3 erased frames */ move16(); alpha = _ALPHA_V_FX; } - ELSE IF( EQ_16(last_good ,SIN_ONSET)) + ELSE IF( EQ_16( last_good, SIN_ONSET ) ) { alpha = _ALPHA_S_FX; move16(); } ELSE { - alpha = _ALPHA_VT_FX; /* rapid convergence to the CNG spectrum (long erasure, ONSETS) */ + alpha = _ALPHA_VT_FX; /* rapid convergence to the CNG spectrum (long erasure, ONSETS) */ } } ELSE { Word16 exp = 15; - alpha = Inv16(nbLostCmpt, &exp); /*1.f/bfi_cnt;*/ - alpha = shl(alpha,exp); + alpha = Inv16( nbLostCmpt, &exp ); /*1.f/bfi_cnt;*/ + alpha = shl( alpha, exp ); } - IF(EQ_16(codec_mode,MODE1)) + IF( EQ_16( codec_mode, MODE1 ) ) { beta = BETA_FEC_FX; move16(); } ELSE { - beta = 8192/*0.25f Q15*/; + beta = 8192 /*0.25f Q15*/; move16(); - if (plcBackgroundNoiseUpdated) + if ( plcBackgroundNoiseUpdated ) { - beta = 0/*0.f Q15*/; + beta = 0 /*0.f Q15*/; move16(); } } - FOR (i=0; iQ(x2.56+14)*/ - L_tmp = L_mac(L_tmp, ratio[idx*M+j], qlsf1[j]); /*Q(x2.56+14)*/ - qlsf[j] = round_fx(L_shl(L_tmp,2)); /*Q(x2.56)*/ + L_tmp = L_mult( sub( 0x2000, ratio[idx * M + j] ), qlsf0[j] ); /*Q(x2.56+13+1)->Q(x2.56+14)*/ + L_tmp = L_mac( L_tmp, ratio[idx * M + j], qlsf1[j] ); /*Q(x2.56+14)*/ + qlsf[j] = round_fx( L_shl( L_tmp, 2 ) ); /*Q(x2.56)*/ } - IF(mid_lsf_int != NULL) /*at the decoder*/ + IF( mid_lsf_int != NULL ) /*at the decoder*/ { /* check for incorrect LSF ordering */ - IF ( EQ_16(*mid_lsf_int, 1)) + IF( EQ_16( *mid_lsf_int, 1 ) ) { - FOR (j=1; j 0 && LT_16(j, M)&<_16(qlsf[j],add(qlsf[j-1],LSF_GAP_MID_FX))) + IF( j > 0 && LT_16( j, M ) && LT_16( qlsf[j], add( qlsf[j - 1], LSF_GAP_MID_FX ) ) ) { - qlsf[j] = add(qlsf[j-1], LSF_GAP_MID_FX); + qlsf[j] = add( qlsf[j - 1], LSF_GAP_MID_FX ); move16(); } - } } ELSE { /* otherwise, use regular LSF spacing and ordering as in the encoder */ - FOR (j=0; j 0 && LT_16(j, M)&<_16(qlsf[j],add(qlsf[j-1],LSF_GAP_MID_FX))) + IF( j > 0 && LT_16( j, M ) && LT_16( qlsf[j], add( qlsf[j - 1], LSF_GAP_MID_FX ) ) ) { - qlsf[j] = add(qlsf[j-1], LSF_GAP_MID_FX); + qlsf[j] = add( qlsf[j - 1], LSF_GAP_MID_FX ); move16(); } } @@ -118,13 +123,13 @@ void midlsf_dec( ELSE { /* use regular LSF spacing */ - FOR (j=0; j 0 && LT_16(j, M)&<_16(qlsf[j],add(qlsf[j-1],LSF_GAP_MID_FX))) + IF( j > 0 && LT_16( j, M ) && LT_16( qlsf[j], add( qlsf[j - 1], LSF_GAP_MID_FX ) ) ) { - qlsf[j] = add(qlsf[j-1], LSF_GAP_MID_FX); + qlsf[j] = add( qlsf[j - 1], LSF_GAP_MID_FX ); move16(); } } @@ -136,23 +141,21 @@ Word16 lsf_ind_is_active( const Word16 lsf_q_ind[], const Word16 means[], const Word16 narrowband, - const Word16 cdk -) + const Word16 cdk ) { Word16 lsf[2], min_distance; - lsf[0] = add(lsf_q_ind[0], means[0]); + lsf[0] = add( lsf_q_ind[0], means[0] ); move16(); - lsf[1] = add(lsf_q_ind[1], means[1]); + lsf[1] = add( lsf_q_ind[1], means[1] ); move16(); min_distance = lsf[0]; move16(); - min_distance = s_min(min_distance, sub(lsf[1], lsf[0])); + min_distance = s_min( min_distance, sub( lsf[1], lsf[0] ) ); - assert(narrowband == 0 || narrowband == 1); - assert(cdk == 0 || cdk == 1); + assert( narrowband == 0 || narrowband == 1 ); + assert( cdk == 0 || cdk == 1 ); - return sub(min_distance, min_distance_thr[narrowband][cdk]) < 0; + return sub( min_distance, min_distance_thr[narrowband][cdk] ) < 0; } - diff --git a/lib_com/lsf_tools.c b/lib_com/lsf_tools.c index 6b4e9943e..127cee7e9 100644 --- a/lib_com/lsf_tools.c +++ b/lib_com/lsf_tools.c @@ -1643,7 +1643,7 @@ void lsf2lsp_32_fx( lsp_fx[i] = getCosWord16R2( div_l( L_shr( lsf_fx[i], lsf_q_fx - 13 ), div_l( Fs, shl( 2, 1 ) ) ) ); } *lsp_q_fx = 15; - return; + return; } #endif @@ -2325,9 +2325,8 @@ void msvq_dec_fx( { uq[k] = L_shr( uq[k], guard_bits ); } - } - + IF( i == 0 && applyIDCT_flag != 0 ) { assert( start == 0 ); @@ -2912,9 +2911,9 @@ void create_IDCT_N_Matrix( #ifdef IVAS_FLOAT_FIXED void create_IDCT_N_Matrix_fx( Word32 *inv_matrixFloatQ, /* i/o: RAM buffer */ - const Word16 N, /* i : DCT length, number of time samples */ - const Word16 n_cols, /* i : number of dct coeffs (as DCT may be truncated) */ - const Word16 alloc_size /* i : RAM buffer size in elements */ + const Word16 N, /* i : DCT length, number of time samples */ + const Word16 n_cols, /* i : number of dct coeffs (as DCT may be truncated) */ + const Word16 alloc_size /* i : RAM buffer size in elements */ ) { Word16 c, c1, r, r_flip, W16_val; @@ -2929,7 +2928,7 @@ void create_IDCT_N_Matrix_fx( idx_ptr = idctT2_24_compressed_idx; len = FDCNG_VQ_MAX_LEN; - IF ( N == FDCNG_VQ_MAX_LEN_WB ) + IF( N == FDCNG_VQ_MAX_LEN_WB ) { absval_ptr = unique_idctT2_21coeffsQ16; idx_ptr = idctT2_21_compressed_idx; @@ -2941,17 +2940,17 @@ void create_IDCT_N_Matrix_fx( mat_cpy_size = ( n_cols ) * ( len >> 1 ); /* NB integer division of "len" */ - IF ( NE_16( ( len & 1 ), 0 ) ) + IF( NE_16( ( len & 1 ), 0 ) ) { /* odd sized DCT with a non-reflected center row */ mat_cpy_size = add( mat_cpy_size, n_cols ); } - FOR ( c = 0; c < mat_cpy_size; c++ ) + FOR( c = 0; c < mat_cpy_size; c++ ) { idx = (Word16) ( idx_ptr[c] ); W16_val = absval_ptr[abs( idx )]; - IF ( idx < 0 ) + IF( idx < 0 ) { W16_val = -( W16_val ); } @@ -2966,11 +2965,11 @@ void create_IDCT_N_Matrix_fx( assert( n_cols == FDCNG_VQ_DCT_MAXTRUNC ); assert( ( n_cols & 1 ) == 0 ); - FOR ( c = 0; c < ( n_cols ); c += 2 ) + FOR( c = 0; c < ( n_cols ); c += 2 ) { c1 = c + 1; r_flip = len - 1; - FOR ( r = 0; r < ( len / 2 ); r_flip-- ) + FOR( r = 0; r < ( len / 2 ); r_flip-- ) { #define WMC_TOOL_SKIP ptr[r_flip][c] = ptr[r][c]; /* flipped */ @@ -2984,4 +2983,4 @@ void create_IDCT_N_Matrix_fx( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_com/lsf_tools_fx.c b/lib_com/lsf_tools_fx.c index 05934803f..9454e80f5 100644 --- a/lib_com/lsf_tools_fx.c +++ b/lib_com/lsf_tools_fx.c @@ -32,7 +32,7 @@ #include #include -#include "options.h" /* Compilation switches */ +#include "options.h" /* Compilation switches */ #include "basop_util.h" #include "rom_com.h" #include "ivas_cnst.h" @@ -40,453 +40,451 @@ #include "ivas_error.h" - /*-------------------------------------------------------------------* - * Local constants - *-------------------------------------------------------------------*/ -#define NC_MAX 8 +/*-------------------------------------------------------------------* + * Local constants + *-------------------------------------------------------------------*/ +#define NC_MAX 8 #define GUESS_TBL_SZ 256 -#define depack_4_values(cbp, val0, val1, val2, val3) \ - val0 = shr((cbp)[0], 4); \ - val1 = shr((cbp)[1], 4); \ - val2 = shr((cbp)[2], 4); \ - val3 = add(add(shr(lshl((cbp)[2],12),4),lshr(lshl((cbp)[1],12),8)),s_and((cbp)[0],0xF)); - -#define SPC 0.0234952f -#define SPC_plus SPC * 1.001f - /*-------------------------------------------------------------------* - * Local functions - *-------------------------------------------------------------------*/ -Word16 root_search_fx(Word16 low, Word16 high, Word32 *v_low, Word32 *coef, Word16 order); -Word32 calc_weight(Word16 delta1, Word16 delta2, Word16 *n1); -Word32 polynomial_eval_fx(Word16 f, Word32 *coef, Word16 order); -void E_LPC_isf_isp_conversion(const Word16 isf[], Word16 isp[], const Word16 m); -void E_LPC_lsp_lsf_conversion(const Word16 lsp[], Word16 lsf[], const Word16 m); -Word16 E_LPC_f_lsp_pol_get(const Word16 lsp[], Word32 f[], const Word16 n, const Word16 past_Ovf, const Word16 isMODE1); - -static Word16 chebyshev(Word16 x, Word32 *f, const Word16 n, const Word16 shift) +#define depack_4_values( cbp, val0, val1, val2, val3 ) \ + val0 = shr( ( cbp )[0], 4 ); \ + val1 = shr( ( cbp )[1], 4 ); \ + val2 = shr( ( cbp )[2], 4 ); \ + val3 = add( add( shr( lshl( ( cbp )[2], 12 ), 4 ), lshr( lshl( ( cbp )[1], 12 ), 8 ) ), s_and( ( cbp )[0], 0xF ) ); + +#define SPC 0.0234952f +#define SPC_plus SPC * 1.001f +/*-------------------------------------------------------------------* + * Local functions + *-------------------------------------------------------------------*/ +Word16 root_search_fx( Word16 low, Word16 high, Word32 *v_low, Word32 *coef, Word16 order ); +Word32 calc_weight( Word16 delta1, Word16 delta2, Word16 *n1 ); +Word32 polynomial_eval_fx( Word16 f, Word32 *coef, Word16 order ); +void E_LPC_isf_isp_conversion( const Word16 isf[], Word16 isp[], const Word16 m ); +void E_LPC_lsp_lsf_conversion( const Word16 lsp[], Word16 lsf[], const Word16 m ); +Word16 E_LPC_f_lsp_pol_get( const Word16 lsp[], Word32 f[], const Word16 n, const Word16 past_Ovf, const Word16 isMODE1 ); + +static Word16 chebyshev( Word16 x, Word32 *f, const Word16 n, const Word16 shift ) { - Word16 cheb; - Word32 t0, b1, b2; + Word16 cheb; + Word32 t0, b1, b2; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; + Flag Overflow = 0; #endif - cheb = norm_s(x); - if (cheb) - { - x = shl(x, 1); - } - t0 = Mpy_32_16_1(*f++, x); /* t0 = x*b2 */ - if (!cheb) - t0 = L_shl(t0, 1); /* t0 = 2*x*b2 */ - b1 = L_add(t0, *f++); /* b1 = 2*x*b2 + f[1] */ - - /* i = 2 */ - t0 = Mpy_32_16_1(b1, x); /* t0 = x*b1 */ - if (!cheb) - t0 = L_shl(t0, 1); /* t0 = 2*x*b1 */ - b2 = L_add(t0, *f++); /* b0 = 2*x*b1 - b2 + f[i] */ - - /* i = 3 */ - t0 = Mpy_32_16_1(b2, x); /* t0 = x*b1 */ - if (!cheb) - t0 = L_shl(t0, 1); /* t0 = 2*x*b1 */ - t0 = L_sub(t0, b1); /* t0 = 2*x*b1 - b2 */ - b1 = L_add(t0, *f++); /* b0 = 2*x*b1 - b2 + f[i] */ - - /* i = 4 */ - t0 = Mpy_32_16_1(b1, x); /* t0 = x*b1 */ - if (!cheb) - t0 = L_shl(t0, 1); /* t0 = 2*x*b1 */ - t0 = L_sub(t0, b2); /* t0 = 2*x*b1 - b2 */ - - /* If the LP order is greater than 10 */ - IF(GT_16(n, 5)) - { - b2 = L_add(t0, *f++); /* b0 = 2*x*b1 - b2 + f[i] */ - /* i = 5 */ - t0 = Mpy_32_16_1(b2, x); /* t0 = x*b1 */ - if (!cheb) + cheb = norm_s( x ); + if ( cheb ) + { + x = shl( x, 1 ); + } + t0 = Mpy_32_16_1( *f++, x ); /* t0 = x*b2 */ + if ( !cheb ) + t0 = L_shl( t0, 1 ); /* t0 = 2*x*b2 */ + b1 = L_add( t0, *f++ ); /* b1 = 2*x*b2 + f[1] */ + + /* i = 2 */ + t0 = Mpy_32_16_1( b1, x ); /* t0 = x*b1 */ + if ( !cheb ) + t0 = L_shl( t0, 1 ); /* t0 = 2*x*b1 */ + b2 = L_add( t0, *f++ ); /* b0 = 2*x*b1 - b2 + f[i] */ + + /* i = 3 */ + t0 = Mpy_32_16_1( b2, x ); /* t0 = x*b1 */ + if ( !cheb ) + t0 = L_shl( t0, 1 ); /* t0 = 2*x*b1 */ + t0 = L_sub( t0, b1 ); /* t0 = 2*x*b1 - b2 */ + b1 = L_add( t0, *f++ ); /* b0 = 2*x*b1 - b2 + f[i] */ + + /* i = 4 */ + t0 = Mpy_32_16_1( b1, x ); /* t0 = x*b1 */ + if ( !cheb ) + t0 = L_shl( t0, 1 ); /* t0 = 2*x*b1 */ + t0 = L_sub( t0, b2 ); /* t0 = 2*x*b1 - b2 */ + + /* If the LP order is greater than 10 */ + IF( GT_16( n, 5 ) ) + { + b2 = L_add( t0, *f++ ); /* b0 = 2*x*b1 - b2 + f[i] */ + /* i = 5 */ + t0 = Mpy_32_16_1( b2, x ); /* t0 = x*b1 */ + if ( !cheb ) #ifdef BASOP_NOGLOB - t0 = L_shl_o(t0, 1, &Overflow); /* t0 = 2*x*b1 */ -#else /* BASOP_NOGLOB */ - t0 = L_shl(t0, 1); /* t0 = 2*x*b1 */ -#endif /* BASOP_NOGLOB */ - t0 = L_sub(t0, b1); /* t0 = 2*x*b1 - b2 */ - b1 = L_add(t0, *f++); /* b0 = 2*x*b1 - b2 + f[i] */ - - /* i = 6 */ - t0 = Mpy_32_16_1(b1, x); /* t0 = x*b1 */ - if (!cheb) + t0 = L_shl_o( t0, 1, &Overflow ); /* t0 = 2*x*b1 */ +#else /* BASOP_NOGLOB */ + t0 = L_shl( t0, 1 ); /* t0 = 2*x*b1 */ +#endif /* BASOP_NOGLOB */ + t0 = L_sub( t0, b1 ); /* t0 = 2*x*b1 - b2 */ + b1 = L_add( t0, *f++ ); /* b0 = 2*x*b1 - b2 + f[i] */ + + /* i = 6 */ + t0 = Mpy_32_16_1( b1, x ); /* t0 = x*b1 */ + if ( !cheb ) #ifdef BASOP_NOGLOB - t0 = L_shl_o(t0, 1, &Overflow); /* t0 = 2*x*b1 */ -#else /* BASOP_NOGLOB */ - t0 = L_shl(t0, 1); /* t0 = 2*x*b1 */ -#endif /* BASOP_NOGLOB */ - t0 = L_sub(t0, b2); /* t0 = 2*x*b1 - b2 */ - } - /* IF (sub(n,8) == 0) */ - IF(n == 8) - { - b2 = L_add(t0, *f++); /* b0 = 2*x*b1 - b2 + f[i] */ - /* i = 7 */ - t0 = Mpy_32_16_1(b2, x); /* t0 = x*b1 */ - if (!cheb) + t0 = L_shl_o( t0, 1, &Overflow ); /* t0 = 2*x*b1 */ +#else /* BASOP_NOGLOB */ + t0 = L_shl( t0, 1 ); /* t0 = 2*x*b1 */ +#endif /* BASOP_NOGLOB */ + t0 = L_sub( t0, b2 ); /* t0 = 2*x*b1 - b2 */ + } + /* IF (sub(n,8) == 0) */ + IF( n == 8 ) + { + b2 = L_add( t0, *f++ ); /* b0 = 2*x*b1 - b2 + f[i] */ + /* i = 7 */ + t0 = Mpy_32_16_1( b2, x ); /* t0 = x*b1 */ + if ( !cheb ) #ifdef BASOP_NOGLOB - t0 = L_shl_o(t0, 1, &Overflow); /* t0 = 2*x*b1 */ -#else /* BASOP_NOGLOB */ - t0 = L_shl(t0, 1); /* t0 = 2*x*b1 */ -#endif /* BASOP_NOGLOB */ - t0 = L_sub(t0, b1); /* t0 = 2*x*b1 - b2 */ - /*b1 = L_add(b2,0);*/ - } - ELSE - { - b2 = b1; - move32(); - } - - t0/*b2*/ = L_add(t0, *f++); /* b0 = 2*x*b1 - b2 + f[i] */ - - t0 = Mpy_32_16_1(t0/*b2*/, x);/* t0 = x*b1 */ - if (cheb) - t0 = L_shr(t0, 1); - t0 = L_sub(t0, /*b1*/b2); /* t0 = x*b1 - b2 */ - t0 = L_add(t0, *f++); /* t0 = x*b1 - b2 + 0.5*f[n] */ - - - BASOP_SATURATE_WARNING_OFF_EVS + t0 = L_shl_o( t0, 1, &Overflow ); /* t0 = 2*x*b1 */ +#else /* BASOP_NOGLOB */ + t0 = L_shl( t0, 1 ); /* t0 = 2*x*b1 */ +#endif /* BASOP_NOGLOB */ + t0 = L_sub( t0, b1 ); /* t0 = 2*x*b1 - b2 */ + /*b1 = L_add(b2,0);*/ + } + ELSE + { + b2 = b1; + move32(); + } + + t0 /*b2*/ = L_add( t0, *f++ ); /* b0 = 2*x*b1 - b2 + f[i] */ + + t0 = Mpy_32_16_1( t0 /*b2*/, x ); /* t0 = x*b1 */ + if ( cheb ) + t0 = L_shr( t0, 1 ); + t0 = L_sub( t0, /*b1*/ b2 ); /* t0 = x*b1 - b2 */ + t0 = L_add( t0, *f++ ); /* t0 = x*b1 - b2 + 0.5*f[n] */ + + + BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB - t0 = L_shl_o(t0, shift, &Overflow); /* Qx to Q30 with saturation */ - cheb = round_fx_o(t0, &Overflow); /* Result in Q14 */ -#else /* BASOP_NOGLOB */ - t0 = L_shl(t0, shift); /* Qx to Q30 with saturation */ - cheb = round_fx(t0); /* Result in Q14 */ -#endif /* BASOP_NOGLOB */ - cheb = s_max(-32767, cheb); /* to avoid saturation */ - BASOP_SATURATE_WARNING_ON_EVS - return (cheb); + t0 = L_shl_o( t0, shift, &Overflow ); /* Qx to Q30 with saturation */ + cheb = round_fx_o( t0, &Overflow ); /* Result in Q14 */ +#else /* BASOP_NOGLOB */ + t0 = L_shl( t0, shift ); /* Qx to Q30 with saturation */ + cheb = round_fx( t0 ); /* Result in Q14 */ +#endif /* BASOP_NOGLOB */ + cheb = s_max( -32767, cheb ); /* to avoid saturation */ + BASOP_SATURATE_WARNING_ON_EVS + return ( cheb ); } -void E_LPC_a_isp_conversion(const Word16 a[], Word16 isp[], const Word16 old_isp[], const Word16 m) +void E_LPC_a_isp_conversion( const Word16 a[], Word16 isp[], const Word16 old_isp[], const Word16 m ) { - Word16 i, nf, ip, order, nc; - Word16 xlow, ylow, xhigh, yhigh; - Word16 x, y, tmp, exp; - Word32 f[2][NC_MAX + 1]; - Word32 t0, t1; - Word16 scale = 1024; + Word16 i, nf, ip, order, nc; + Word16 xlow, ylow, xhigh, yhigh; + Word16 x, y, tmp, exp; + Word32 f[2][NC_MAX + 1]; + Word32 t0, t1; + Word16 scale = 1024; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; + Flag Overflow = 0; #endif - /*-------------------------------------------------------------* - * find the sum and diff polynomials F1(z) and F2(z) - * F1(z) = [A(z) + z^M A(z^-1)] - * F2(z) = [A(z) - z^M A(z^-1)]/(1-z^-2) - * - * for (i=0; i 1; i--) - { - /* f2[i] -= f2[i-2]; */ - f2[i] = L_sub(f2[i], f2[i - 2]); - move32(); - } - - /*----------------------------------------------------------* - * Scale F1(z) by (1+isp[m-1]) and F2(z) by (1-isp[m-1]) * - *----------------------------------------------------------*/ - - FOR(i = 0; i < nc; i++) - { - /* f1[i] *= (1.0 + isp[m-1]); */ - f1[i] = Madd_32_16(f1[i], f1[i], isp[m - 1]); - move32(); - - /* f2[i] *= (1.0 - isp[m-1]); */ - f2[i] = Msub_32_16(f2[i], f2[i], isp[m - 1]); - move32(); - } - - /*-----------------------------------------------------* - * A(z) = (F1(z)+F2(z))/2 * - * F1(z) is symmetric and F2(z) is antisymmetric * - *-----------------------------------------------------*/ - - /* Maximum LPC */ - tmax = L_deposit_l(1); - FOR(i = 1; i < nc; i++) - { - t0 = L_add(f1[i], f2[i]); - tmax = L_max(tmax, L_abs(t0)); - t0 = L_sub(f1[i], f2[i]); - tmax = L_max(tmax, L_abs(t0)); - } - q = s_min(norm_l(tmax), 6); - - DO - { - - /* a[0] = 1.0 */ - a[0] = shl(256,q); - move16(); - j = sub(m, 1); - FOR(i = 1; i < nc; i++) - { - /* a[i] = 0.5*(f1[i] + f2[i]) */ - t0 = L_add(f1[i], f2[i]); /* f1[i] + f2[i] */ - t0 = L_shl(t0, q); - a[i] = round_fx(t0); /* from Q23 to Q12 and * 0.5 */ - - /* a[j] = 0.5*(f1[i] - f2[i]) */ - t0 = L_sub(f1[i], f2[i]); /* f1[i] - f2[i] */ - t0 = L_shl(t0, q); - a[j] = round_fx(t0); /* from Q23 to Q12 and * 0.5 */ - - j = sub(j,1); - } - - /* a[NC] = 0.5*f1[NC]*(1.0 + isp[m-1]) */ - t0 = Madd_32_16(f1[nc], f1[nc], isp[m - 1]); - - BASOP_SATURATE_WARNING_OFF_EVS /*overflow handling in loop expression*/ + nc = shr( m, 1 ); -#ifdef BASOP_NOGLOB - t0 = L_shl_o(t0, q, &Overflow); - t0n = L_sub_o(t0 , 0x7FFFFFFF, &Overflow); /*check for positive overflow*/ - t0p = L_sub_o(t0, 0x80000000, &Overflow); /*check for negative overflow*/ -#else /* BASOP_NOGLOB */ - t0 = L_shl(t0, q); - t0n = L_sub(t0 , 0x7FFFFFFF); /*check for positive overflow*/ - t0p = L_sub(t0, 0x80000000); /*check for negative overflow*/ -#endif /* BASOP_NOGLOB */ - BASOP_SATURATE_WARNING_ON_EVS + E_LPC_f_lsp_pol_get( &isp[0], f1, nc, 0, 0 ); + E_LPC_f_lsp_pol_get( &isp[1], f2, sub( nc, 1 ), 0, 0 ); + /*-----------------------------------------------------* + * Multiply F2(z) by (1 - z^-2) * + *-----------------------------------------------------*/ + + FOR( i = sub( nc, 1 ); i > 1; i-- ) + { + /* f2[i] -= f2[i-2]; */ + f2[i] = L_sub( f2[i], f2[i - 2] ); + move32(); + } + + /*----------------------------------------------------------* + * Scale F1(z) by (1+isp[m-1]) and F2(z) by (1-isp[m-1]) * + *----------------------------------------------------------*/ + + FOR( i = 0; i < nc; i++ ) + { + /* f1[i] *= (1.0 + isp[m-1]); */ + f1[i] = Madd_32_16( f1[i], f1[i], isp[m - 1] ); + move32(); + + /* f2[i] *= (1.0 - isp[m-1]); */ + f2[i] = Msub_32_16( f2[i], f2[i], isp[m - 1] ); + move32(); + } - q = sub(q,1); /*decrease q in case of overflow*/ - } WHILE(t0n == 0 || t0p == 0); /*in case of overflow, recalculate coefficients*/ + /*-----------------------------------------------------* + * A(z) = (F1(z)+F2(z))/2 * + * F1(z) is symmetric and F2(z) is antisymmetric * + *-----------------------------------------------------*/ - a[nc] = round_fx(t0); /* from Q23 to Q12 and * 0.5 */ + /* Maximum LPC */ + tmax = L_deposit_l( 1 ); + FOR( i = 1; i < nc; i++ ) + { + t0 = L_add( f1[i], f2[i] ); + tmax = L_max( tmax, L_abs( t0 ) ); + t0 = L_sub( f1[i], f2[i] ); + tmax = L_max( tmax, L_abs( t0 ) ); + } + q = s_min( norm_l( tmax ), 6 ); + + DO + { + + /* a[0] = 1.0 */ + a[0] = shl( 256, q ); + move16(); + j = sub( m, 1 ); + FOR( i = 1; i < nc; i++ ) + { + /* a[i] = 0.5*(f1[i] + f2[i]) */ + t0 = L_add( f1[i], f2[i] ); /* f1[i] + f2[i] */ + t0 = L_shl( t0, q ); + a[i] = round_fx( t0 ); /* from Q23 to Q12 and * 0.5 */ + + /* a[j] = 0.5*(f1[i] - f2[i]) */ + t0 = L_sub( f1[i], f2[i] ); /* f1[i] - f2[i] */ + t0 = L_shl( t0, q ); + a[j] = round_fx( t0 ); /* from Q23 to Q12 and * 0.5 */ + + j = sub( j, 1 ); + } + + /* a[NC] = 0.5*f1[NC]*(1.0 + isp[m-1]) */ + t0 = Madd_32_16( f1[nc], f1[nc], isp[m - 1] ); + + BASOP_SATURATE_WARNING_OFF_EVS /*overflow handling in loop expression*/ + +#ifdef BASOP_NOGLOB + t0 = L_shl_o( t0, q, &Overflow ); + t0n = L_sub_o( t0, 0x7FFFFFFF, &Overflow ); /*check for positive overflow*/ + t0p = L_sub_o( t0, 0x80000000, &Overflow ); /*check for negative overflow*/ +#else /* BASOP_NOGLOB */ + t0 = L_shl( t0, q ); + t0n = L_sub( t0, 0x7FFFFFFF ); /*check for positive overflow*/ + t0p = L_sub( t0, 0x80000000 ); /*check for negative overflow*/ +#endif /* BASOP_NOGLOB */ + BASOP_SATURATE_WARNING_ON_EVS + + q = sub( q, 1 ); /*decrease q in case of overflow*/ + } + WHILE( t0n == 0 || t0p == 0 ); /*in case of overflow, recalculate coefficients*/ + + a[nc] = round_fx( t0 ); /* from Q23 to Q12 and * 0.5 */ - /* a[m] = isp[m-1] */ - t0 = L_mult(a[0], isp[m - 1]); /* from Q15 to Q12 */ - a[m] = round_fx(t0); + /* a[m] = isp[m-1] */ + t0 = L_mult( a[0], isp[m - 1] ); /* from Q15 to Q12 */ + a[m] = round_fx( t0 ); - return; + return; } /*===================================================================*/ @@ -510,126 +508,125 @@ void E_LPC_f_isp_a_conversion(const Word16 *isp, Word16 *a, const Word16 m) /* _ (Word16) flag: 1 means all 10 LSPs are found, 0 otherwise */ /*===================================================================*/ Word16 lpc2lsp_fx( - Word32* a, - Word16* freq, - Word16* old_freq, - Word16 order -) + Word32 *a, + Word16 *freq, + Word16 *old_freq, + Word16 order ) { - Word16 i; - Word16 rt, low, high, prev_rt, rc; - Word32 p[11], q[11]; /* Q26 */ - Word32 Ltemp, v_low; - Word32 Lacc; - Word16 tfreq[21]; - - /* First construct the P,Q polynomial */ - /* p[0] = q[0] = 1 */ - /* p[i] = -lpcCoeff[i] - lpcCoeff[11-i] - p[i-1] ( 1<=i<=5)*/ - /* q[i] = -lpcCoeff[i] + lpcCoeff[11-i] + q[i-1] ( 1<=i<=5)*/ - Ltemp = L_deposit_h(0x400); /* Ltemp is 1.0 in Q26 */ - - p[0] = Ltemp; - move32(); - q[0] = Ltemp; - move32(); - - FOR(i = 1; i < (order / 2) + 1; i++) - { - Lacc = a[order - i]; - move32();/* Q27 */ - Lacc = L_sub(Lacc, a[i - 1]); /* Lacc=-lpcCoeff[i-1] + lpcCoeff[order-i]//Q27 */ - q[i] = L_add(L_shr(Lacc, 1), q[i - 1]); - move32();/* Q26 */ - - Lacc = L_add(Lacc, L_shl(a[i - 1], 1));/* Lacc=lpcCoeff[i-1] + lpcCoeff[order-i]//Q27 */ - - p[i] = L_sub(L_negate(L_shr(Lacc, 1)), p[i - 1]); - move32();/* Q26 */ - } - - /* Search roots of the P and Q polynomials */ - - v_low = polynomial_eval_fx(0, p, order); /* Q25 */ - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - low = 0; - high = 8; - prev_rt = 0; - rc = 0; /* root counter */ - FOR(i = 0; i < 32; i++) - { - rt = root_search_fx(low, high, &v_low, p, order); - low = high; - move16(); - high = add(high, 8); - - IF(GE_16(rt, prev_rt)) - { - tfreq[rc] = rt; - move16(); - rc = add(rc, 2); - } - prev_rt = add(rt, 6); - } /* End for P roots */ - - tfreq[rc] = 0x3f80; - move16(); /* Set a high enough value as fake root for Q search */ - - IF(LT_16(rc, order)) - { - /* lost P root */ - /* copy from previous LSP and return */ - FOR(i = 0; i < order; i++) - { - move16(); - freq[i] = old_freq[i]; - } - return (0); - } - ELSE - { - /* Search for Q roots between P roots */ - v_low = L_deposit_h(0x800); /* Init a positive value for v_low */ - rc = 1; - move16(); - FOR(i = 0; i < order / 2; i++) - { - low = shr(tfreq[rc - 1], 6); - high = add(shr(tfreq[rc + 1], 6), 1); - rt = root_search_fx(low, high, &v_low, q, order); - - IF(rt < 0) - { - /* No Q root in this interval */ - /* copy from previous LSP and return */ - FOR(i = 0; i < order; i++) - { - move16(); - freq[i] = old_freq[i]; - } - return (0); - } - ELSE - { - move16(); - tfreq[rc] = rt; - rc = add(rc, 2); - } /* end else, find Q root */ - } /* end for */ - } /* end else */ - - FOR(i = 0; i < order; i++) - { - freq[i] = tfreq[i]; - move16(); - } - - return (1); + Word16 i; + Word16 rt, low, high, prev_rt, rc; + Word32 p[11], q[11]; /* Q26 */ + Word32 Ltemp, v_low; + Word32 Lacc; + Word16 tfreq[21]; + + /* First construct the P,Q polynomial */ + /* p[0] = q[0] = 1 */ + /* p[i] = -lpcCoeff[i] - lpcCoeff[11-i] - p[i-1] ( 1<=i<=5)*/ + /* q[i] = -lpcCoeff[i] + lpcCoeff[11-i] + q[i-1] ( 1<=i<=5)*/ + Ltemp = L_deposit_h( 0x400 ); /* Ltemp is 1.0 in Q26 */ + + p[0] = Ltemp; + move32(); + q[0] = Ltemp; + move32(); + + FOR( i = 1; i < ( order / 2 ) + 1; i++ ) + { + Lacc = a[order - i]; + move32(); /* Q27 */ + Lacc = L_sub( Lacc, a[i - 1] ); /* Lacc=-lpcCoeff[i-1] + lpcCoeff[order-i]//Q27 */ + q[i] = L_add( L_shr( Lacc, 1 ), q[i - 1] ); + move32(); /* Q26 */ + + Lacc = L_add( Lacc, L_shl( a[i - 1], 1 ) ); /* Lacc=lpcCoeff[i-1] + lpcCoeff[order-i]//Q27 */ + + p[i] = L_sub( L_negate( L_shr( Lacc, 1 ) ), p[i - 1] ); + move32(); /* Q26 */ + } + + /* Search roots of the P and Q polynomials */ + + v_low = polynomial_eval_fx( 0, p, order ); /* Q25 */ + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + low = 0; + high = 8; + prev_rt = 0; + rc = 0; /* root counter */ + FOR( i = 0; i < 32; i++ ) + { + rt = root_search_fx( low, high, &v_low, p, order ); + low = high; + move16(); + high = add( high, 8 ); + + IF( GE_16( rt, prev_rt ) ) + { + tfreq[rc] = rt; + move16(); + rc = add( rc, 2 ); + } + prev_rt = add( rt, 6 ); + } /* End for P roots */ + + tfreq[rc] = 0x3f80; + move16(); /* Set a high enough value as fake root for Q search */ + + IF( LT_16( rc, order ) ) + { + /* lost P root */ + /* copy from previous LSP and return */ + FOR( i = 0; i < order; i++ ) + { + move16(); + freq[i] = old_freq[i]; + } + return ( 0 ); + } + ELSE + { + /* Search for Q roots between P roots */ + v_low = L_deposit_h( 0x800 ); /* Init a positive value for v_low */ + rc = 1; + move16(); + FOR( i = 0; i < order / 2; i++ ) + { + low = shr( tfreq[rc - 1], 6 ); + high = add( shr( tfreq[rc + 1], 6 ), 1 ); + rt = root_search_fx( low, high, &v_low, q, order ); + + IF( rt < 0 ) + { + /* No Q root in this interval */ + /* copy from previous LSP and return */ + FOR( i = 0; i < order; i++ ) + { + move16(); + freq[i] = old_freq[i]; + } + return ( 0 ); + } + ELSE + { + move16(); + tfreq[rc] = rt; + rc = add( rc, 2 ); + } /* end else, find Q root */ + } /* end for */ + } /* end else */ + + FOR( i = 0; i < order; i++ ) + { + freq[i] = tfreq[i]; + move16(); + } + + return ( 1 ); } /*===================================================================*/ @@ -653,185 +650,181 @@ Word16 lpc2lsp_fx( /* _ None */ /*===================================================================*/ void lsp2lpc_fx( - Word16 *a, - Word16 *freq, - Word16 *prev_a, - Word16 order -) + Word16 *a, + Word16 *freq, + Word16 *prev_a, + Word16 order ) { - Word16 i; - Word32 pq[LPC_SHB_ORDER]; - Word32 p[LPC_SHB_ORDER], q[LPC_SHB_ORDER]; - Word32 Ltemp; - Word32 Lacc; - Word16 tmp_pci[M + 1]; - Word16 giOverflow; + Word16 i; + Word32 pq[LPC_SHB_ORDER]; + Word32 p[LPC_SHB_ORDER], q[LPC_SHB_ORDER]; + Word32 Ltemp; + Word32 Lacc; + Word16 tmp_pci[M + 1]; + Word16 giOverflow; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; + Flag Overflow = 0; #endif - FOR(i = 0; i < order; i++) - { - tmp_pci[i] = prev_a[i]; - move16(); - } - - compute_poly_product_fx(freq, pq, order); - /*This change is to get funtionality if L_sub_sat*/ - giOverflow = 0; - move16(); /* clear overflow flag */ - Overflow = 0; - move16(); - FOR(i = 0; i < order / 2; i++) - { -#ifdef BASOP_NOGLOB /* Critical Overflow */ - Ltemp = L_add_o(pq[i], pq[i + 1], &Overflow); + FOR( i = 0; i < order; i++ ) + { + tmp_pci[i] = prev_a[i]; + move16(); + } + + compute_poly_product_fx( freq, pq, order ); + /*This change is to get funtionality if L_sub_sat*/ + giOverflow = 0; + move16(); /* clear overflow flag */ + Overflow = 0; + move16(); + FOR( i = 0; i < order / 2; i++ ) + { +#ifdef BASOP_NOGLOB /* Critical Overflow */ + Ltemp = L_add_o( pq[i], pq[i + 1], &Overflow ); #else - Ltemp = L_add(pq[i], pq[i + 1]); + Ltemp = L_add( pq[i], pq[i + 1] ); #endif - giOverflow = (Word16)Overflow; - move16(); - IF(EQ_16(giOverflow, 1)) - { - BREAK; - } - - p[i] = Ltemp; - move32(); - } - - IF(EQ_16(giOverflow, 1)) - { - FOR(i = 0; i < order; i++) - { - a[i] = mult_r(prev_a[i], pwAlpha[i]); - move16(); - } - return; - } - - compute_poly_product_fx(freq + 1, pq, order); - - - giOverflow = 0; - move16(); - Overflow = 0; - move16(); - - FOR(i = 0; i < order / 2; i++) - { -#ifdef BASOP_NOGLOB /* Critical Overflow */ - Ltemp = L_sub_o(pq[i + 1], pq[i], &Overflow); + giOverflow = (Word16) Overflow; + move16(); + IF( EQ_16( giOverflow, 1 ) ) + { + BREAK; + } + + p[i] = Ltemp; + move32(); + } + + IF( EQ_16( giOverflow, 1 ) ) + { + FOR( i = 0; i < order; i++ ) + { + a[i] = mult_r( prev_a[i], pwAlpha[i] ); + move16(); + } + return; + } + + compute_poly_product_fx( freq + 1, pq, order ); + + + giOverflow = 0; + move16(); + Overflow = 0; + move16(); + + FOR( i = 0; i < order / 2; i++ ) + { +#ifdef BASOP_NOGLOB /* Critical Overflow */ + Ltemp = L_sub_o( pq[i + 1], pq[i], &Overflow ); #else - Ltemp = L_sub(pq[i + 1], pq[i]); + Ltemp = L_sub( pq[i + 1], pq[i] ); #endif - giOverflow = (Word16)Overflow; - move16(); - IF(EQ_16(giOverflow, 1)) - { - BREAK; - } - - q[i] = Ltemp; - move32(); - } - - IF(EQ_16(giOverflow, 1)) - { - FOR(i = 0; i < order; i++) - { - a[i] = mult_r(prev_a[i], pwAlpha[i]); - move16(); - } - } - ELSE - { - FOR(i = 0; i < order / 2; i++) - { - Overflow = 0; - move16(); -#ifdef BASOP_NOGLOB /* Critical Overflow */ - Lacc = L_add_o(p[i], q[i], &Overflow); /* p[i], q[i] in Q24 */ + giOverflow = (Word16) Overflow; + move16(); + IF( EQ_16( giOverflow, 1 ) ) + { + BREAK; + } + + q[i] = Ltemp; + move32(); + } + + IF( EQ_16( giOverflow, 1 ) ) + { + FOR( i = 0; i < order; i++ ) + { + a[i] = mult_r( prev_a[i], pwAlpha[i] ); + move16(); + } + } + ELSE + { + FOR( i = 0; i < order / 2; i++ ) + { + Overflow = 0; + move16(); +#ifdef BASOP_NOGLOB /* Critical Overflow */ + Lacc = L_add_o( p[i], q[i], &Overflow ); /* p[i], q[i] in Q24 */ #else - Lacc = L_add(p[i], q[i]); /* p[i], q[i] in Q24 */ + Lacc = L_add( p[i], q[i] ); /* p[i], q[i] in Q24 */ #endif - if (Overflow) - { - giOverflow = 1; - move16(); - } - - Lacc = L_negate(Lacc); /* Lacc=-(p[i]-q[i])/2 in Q25 */ - Overflow = 0; - move16(); -#ifdef BASOP_NOGLOB /* Critical Overflow */ - Lacc = L_add_o(L_shl_o(Lacc, 3, &Overflow), 0x08000, &Overflow); /* rounding */ + if ( Overflow ) + { + giOverflow = 1; + move16(); + } + + Lacc = L_negate( Lacc ); /* Lacc=-(p[i]-q[i])/2 in Q25 */ + Overflow = 0; + move16(); +#ifdef BASOP_NOGLOB /* Critical Overflow */ + Lacc = L_add_o( L_shl_o( Lacc, 3, &Overflow ), 0x08000, &Overflow ); /* rounding */ #else - Lacc = L_add(L_shl(Lacc, 3), 0x08000); /* rounding */ + Lacc = L_add( L_shl( Lacc, 3 ), 0x08000 ); /* rounding */ #endif - if (Overflow) - { - giOverflow = 1; - move16(); - } - - a[i] = extract_h(Lacc); /* a[i] in Q12 */ - - IF(EQ_16(giOverflow,1)) - { - BREAK; - } - - } - FOR(i = 0; i < order / 2; i++) - { - Overflow = 0; - move16(); -#ifdef BASOP_NOGLOB /* Critical Overflow */ - Lacc = L_sub_o(q[i], p[i], &Overflow); /* p[i], q[i] in Q24 */ + if ( Overflow ) + { + giOverflow = 1; + move16(); + } + + a[i] = extract_h( Lacc ); /* a[i] in Q12 */ + + IF( EQ_16( giOverflow, 1 ) ) + { + BREAK; + } + } + FOR( i = 0; i < order / 2; i++ ) + { + Overflow = 0; + move16(); +#ifdef BASOP_NOGLOB /* Critical Overflow */ + Lacc = L_sub_o( q[i], p[i], &Overflow ); /* p[i], q[i] in Q24 */ #else - Lacc = L_sub(q[i], p[i]); /* p[i], q[i] in Q24 */ + Lacc = L_sub( q[i], p[i] ); /* p[i], q[i] in Q24 */ #endif - if (Overflow) - { - giOverflow = 1; - move16(); - } - Overflow = 0; - move16(); -#ifdef BASOP_NOGLOB /* Critical Overflow */ - Lacc = L_add_o(L_shl_o(Lacc, 3, &Overflow), 0x08000, &Overflow); /* rounding */ + if ( Overflow ) + { + giOverflow = 1; + move16(); + } + Overflow = 0; + move16(); +#ifdef BASOP_NOGLOB /* Critical Overflow */ + Lacc = L_add_o( L_shl_o( Lacc, 3, &Overflow ), 0x08000, &Overflow ); /* rounding */ #else - Lacc = L_add(L_shl(Lacc, 3), 0x08000); /* rounding */ + Lacc = L_add( L_shl( Lacc, 3 ), 0x08000 ); /* rounding */ #endif - if (Overflow) - { - giOverflow = 1; - move16(); - } - - a[order - 1 - i] = extract_h(Lacc); + if ( Overflow ) + { + giOverflow = 1; + move16(); + } + a[order - 1 - i] = extract_h( Lacc ); - IF(EQ_16(giOverflow,1)) - { - BREAK; - } - - } - } + IF( EQ_16( giOverflow, 1 ) ) + { + BREAK; + } + } + } - IF(EQ_16(giOverflow, 1)) - { - FOR(i = 0; i < order; i++) - { - a[i] = mult_r(tmp_pci[i], pwAlpha[i]); - move16(); - } - } + IF( EQ_16( giOverflow, 1 ) ) + { + FOR( i = 0; i < order; i++ ) + { + a[i] = mult_r( tmp_pci[i], pwAlpha[i] ); + move16(); + } + } } /* @@ -861,277 +854,278 @@ void lsp2lpc_fx( * R.A.Salami October 1990 * *-----------------------------------------------------------* */ -Word16 E_LPC_f_lsp_pol_get(const Word16 lsp[], Word32 f[], const Word16 n, const Word16 past_Ovf, const Word16 isMODE1) +Word16 E_LPC_f_lsp_pol_get( const Word16 lsp[], Word32 f[], const Word16 n, const Word16 past_Ovf, const Word16 isMODE1 ) { - /* All computation in Q23 */ - const Word16 *plsp; - Word16 i, j; - Word16 b; - Word32 b32; - Word16 Ovf = 0; - Word16 Q_out; - Word16 m2; + /* All computation in Q23 */ + const Word16 *plsp; + Word16 i, j; + Word16 b; + Word32 b32; + Word16 Ovf = 0; + Word16 Q_out; + Word16 m2; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; + Flag Overflow = 0; #endif - Q_out = 31 - 23; - move16(); - Ovf = past_Ovf; - move16(); - - test(); - if (past_Ovf && isMODE1) /* Currently this feature is implemented only in MODE1 */ - { - /* In some NB cases, overflow where detectected - in f1 or f2 polynomial computation when it - happen we reduce the precision of the computing - to limit the risk of saturation*/ - Q_out = add(Q_out, past_Ovf); - } - Overflow = 0; - move16(); - plsp = lsp; -#ifdef BASOP_NOGLOB /* Critical Overflow and all those below*/ - f[0] = L_shl_o(1, sub(31, Q_out), &Overflow); + Q_out = 31 - 23; + move16(); + Ovf = past_Ovf; + move16(); + + test(); + if ( past_Ovf && isMODE1 ) /* Currently this feature is implemented only in MODE1 */ + { + /* In some NB cases, overflow where detectected + in f1 or f2 polynomial computation when it + happen we reduce the precision of the computing + to limit the risk of saturation*/ + Q_out = add( Q_out, past_Ovf ); + } + Overflow = 0; + move16(); + plsp = lsp; +#ifdef BASOP_NOGLOB /* Critical Overflow and all those below*/ + f[0] = L_shl_o( 1, sub( 31, Q_out ), &Overflow ); #else - f[0] = L_shl(1, sub(31, Q_out)); + f[0] = L_shl( 1, sub( 31, Q_out ) ); #endif - move32(); - /*b = -2.0f * *plsp;*/ - b = *plsp; - move16(); -#ifdef BASOP_NOGLOB /* Critical Overflow */ - m2 = shl_o(-2, sub(15, Q_out), &Overflow); - f[1] = L_mult_o(b, m2, &Overflow); + move32(); + /*b = -2.0f * *plsp;*/ + b = *plsp; + move16(); +#ifdef BASOP_NOGLOB /* Critical Overflow */ + m2 = shl_o( -2, sub( 15, Q_out ), &Overflow ); + f[1] = L_mult_o( b, m2, &Overflow ); #else - m2 = shl(-2, sub(15, Q_out)); - f[1] = L_mult(b, m2); + m2 = shl( -2, sub( 15, Q_out ) ); + f[1] = L_mult( b, m2 ); #endif - move32(); - - FOR(i = 2; i <= n; i++) - { - plsp += 2; - /*b = 2.0f * *plsp;*/ - move16(); - b = *plsp; -#ifdef BASOP_NOGLOB /* Critical Overflow */ - b32 = L_mult_o(b, m2, &Overflow); + move32(); + + FOR( i = 2; i <= n; i++ ) + { + plsp += 2; + /*b = 2.0f * *plsp;*/ + move16(); + b = *plsp; +#ifdef BASOP_NOGLOB /* Critical Overflow */ + b32 = L_mult_o( b, m2, &Overflow ); #else - b32 = L_mult(b, m2); + b32 = L_mult( b, m2 ); #endif - /*f[i] = -b*f[i-1] + 2.0f*f[i-2];*/ - move32(); -#ifdef BASOP_NOGLOB /* Critical Overflow */ - f[i] = L_shl_o(L_sub_o(f[i - 2], Mpy_32_16_1(f[i - 1], b), &Overflow), 1, &Overflow); + /*f[i] = -b*f[i-1] + 2.0f*f[i-2];*/ + move32(); +#ifdef BASOP_NOGLOB /* Critical Overflow */ + f[i] = L_shl_o( L_sub_o( f[i - 2], Mpy_32_16_1( f[i - 1], b ), &Overflow ), 1, &Overflow ); #else - f[i] = L_shl(L_sub(f[i - 2], Mpy_32_16_1(f[i - 1], b)), 1); + f[i] = L_shl( L_sub( f[i - 2], Mpy_32_16_1( f[i - 1], b ) ), 1 ); #endif - FOR(j = i - 1; j > 1; j--) - { - /*f[j] += b*f[j-1] + f[j-2];*/ - move32(); -#ifdef BASOP_NOGLOB /* Critical Overflow */ - f[j] = L_add_o(f[j], L_sub_o(f[j - 2], L_shl_o(Mpy_32_16_1(f[j - 1], b), 1, &Overflow), &Overflow), &Overflow); + FOR( j = i - 1; j > 1; j-- ) + { + /*f[j] += b*f[j-1] + f[j-2];*/ + move32(); +#ifdef BASOP_NOGLOB /* Critical Overflow */ + f[j] = L_add_o( f[j], L_sub_o( f[j - 2], L_shl_o( Mpy_32_16_1( f[j - 1], b ), 1, &Overflow ), &Overflow ), &Overflow ); #else - f[j] = L_add(f[j], L_sub(f[j - 2], L_shl(Mpy_32_16_1(f[j - 1], b), 1))); + f[j] = L_add( f[j], L_sub( f[j - 2], L_shl( Mpy_32_16_1( f[j - 1], b ), 1 ) ) ); #endif - } - move32(); -#ifdef BASOP_NOGLOB /* Critical Overflow */ - f[1] = L_add_o(f[1], b32, &Overflow); + } + move32(); +#ifdef BASOP_NOGLOB /* Critical Overflow */ + f[1] = L_add_o( f[1], b32, &Overflow ); #else - f[1] = L_add(f[1], b32); + f[1] = L_add( f[1], b32 ); #endif - } + } - test(); - IF(Overflow > 0 && isMODE1) - { - /* If an overflow is detected, redo the computation with 1 bit less */ - Ovf = add(Ovf, 1); - Ovf = E_LPC_f_lsp_pol_get(lsp, f, n, Ovf, isMODE1); - } - return Ovf; + test(); + IF( Overflow > 0 && isMODE1 ) + { + /* If an overflow is detected, redo the computation with 1 bit less */ + Ovf = add( Ovf, 1 ); + Ovf = E_LPC_f_lsp_pol_get( lsp, f, n, Ovf, isMODE1 ); + } + return Ovf; } void E_LPC_a_lsp_conversion( - const Word16 *a, /* input : LP filter coefficients (Qx) */ - Word16 *lsp, /* output: Line spectral pairs (in the cosine domain)(0Q15) */ - const Word16 *old_lsp, /* input : LSP vector from past frame (0Q15) */ - const Word16 m /* input : length of the LP filter coefficients */ + const Word16 *a, /* input : LP filter coefficients (Qx) */ + Word16 *lsp, /* output: Line spectral pairs (in the cosine domain)(0Q15) */ + const Word16 *old_lsp, /* input : LSP vector from past frame (0Q15) */ + const Word16 m /* input : length of the LP filter coefficients */ ) { - Word16 i, nf, ip, nc; - Word16 xlow, ylow, xhigh, yhigh; - Word16 x, y, tmp, exp; - Word32 f[2][NC_MAX + 1]; - Word32 t0, t1; - Word32 sum, diff; - Word16 scale; - - - - nc = shr(m, 1); - - scale = shl(128, norm_s(a[0])); - - /*-------------------------------------------------------------* - * find the sum and diff polynomials F1(z) and F2(z) * - * F1(z) = [A(z) + z^11 A(z^-1)]/(1+z^-1) * - * F2(z) = [A(z) - z^11 A(z^-1)]/(1-z^-1) * - *-------------------------------------------------------------*/ - - f[0][0] = L_mult(a[0], scale); /*1.0f in Q23*/ move32(); - f[1][0] = L_mult(a[0], scale); /*1.0f in Q23*/ move32(); - FOR(i = 1; i < nc; i++) - { - t0 = L_mult(a[i], scale); /*Q23*/ - sum = L_mac(t0, a[m + 1 - i], scale); - diff = L_msu(t0, a[m + 1 - i], scale); - f[0][i] = L_sub(sum, f[0][i - 1]); - move32(); /*Q23*/ - f[1][i] = L_add(diff, f[1][i - 1]); - move32(); /*Q23*/ - } - t1 = L_mult0(a[i], scale); /*Q23-1*/ - sum = L_mac0(t1, a[m + 1 - i], scale); - diff = L_msu0(t1, a[m + 1 - i], scale); - f[0][nc] = L_sub(sum, L_shr(f[0][i - 1], 1)); - move32(); /*Q23-1*/ - f[1][nc] = L_add(diff, L_shr(f[1][i - 1], 1)); - move32(); /*Q23-1*/ - - /* Precalculate difference to index 0 for index 2 */ - f[0][2] = L_sub(f[0][2], f[0][0]); - move32(); - f[1][2] = L_sub(f[1][2], f[1][0]); - move32(); - - /*---------------------------------------------------------------------* - * Find the LSPs (roots of F1(z) and F2(z) ) using the * - * Chebyshev polynomial evaluation. * - * The roots of F1(z) and F2(z) are alternatively searched. * - * We start by finding the first root of F1(z) then we switch * - * to F2(z) then back to F1(z) and so on until all roots are found. * - * * - * - Evaluate Chebyshev pol. at grid points and check for sign change.* - * - If sign change track the root by subdividing the interval * - * 4 times and ckecking sign change. * - *---------------------------------------------------------------------*/ - nf = 0; - move16(); /* number of found frequencies */ - ip = 0; - move16(); /* indicator for f1 or f2 */ - - xlow = Grid[0]; - move16(); - ylow = chebyshev(xlow, f[ip], nc, 8); - - FOR(i = 1; i <= GRID100_POINTS; i++) - { - xhigh = xlow; - move16(); - yhigh = ylow; - move16(); - xlow = Grid[i]; - move16(); - ylow = chebyshev(xlow, f[ip], nc, 8); - - IF(L_mult(ylow, yhigh) <= 0) - { - t0 = L_mult(xhigh, 0x4000); - /* divide 2 times the interval */ - x = mac_r(t0, xlow, 0x4000); /* xmid = (xlow + xhigh)/2 */ - y = chebyshev(x, f[ip], nc, 8); - - IF(L_mult(ylow, y) <= 0) - { - yhigh = y; - move16(); - xhigh = x; - move16(); - y = ylow; - move16(); - x = xlow; - move16(); - /* 'xhigh' has changed, update 't0' */ - t0 = L_mult(xhigh, 0x4000); - } - xlow = mac_r(t0, x, 0x4000); /* xmid = (xlow + xhigh)/2 */ - ylow = chebyshev(xlow, f[ip], nc, 8); - - IF(L_mult(y, ylow) <= 0) - { - yhigh = ylow; - move16(); - xhigh = xlow; - move16(); - ylow = y; - move16(); - xlow = x; - move16(); - } - - /*--------------------------------------------------------* - * Linear interpolation - * xint = xlow - ylow*(xhigh-xlow)/(yhigh-ylow) - *--------------------------------------------------------*/ - y = msu_r(L_mult(yhigh, 0x4000), ylow, 0x4000); - - IF(y != 0) - { - x = sub(xhigh, xlow); - BASOP_SATURATE_WARNING_OFF_EVS - tmp = abs_s(y); - BASOP_SATURATE_WARNING_ON_EVS - exp = norm_s(tmp); - if (exp) - tmp = shl(tmp, exp); - tmp = div_s((Word16)16383 / 2, tmp); - t0 = L_mult(x, tmp); - t0 = L_shr(t0, sub(20, exp)); - tmp = extract_l(t0); /* y = (xhigh-xlow)/(yhigh-ylow) in Q11 */ - - /* Restore Sign */ - if (y < 0) - tmp = negate(tmp); - - t0 = L_mult(ylow, tmp); /* result in Q26 */ - t0 = L_shr(t0, 11); /* result in Q15 */ - xlow = sub(xlow, extract_l(t0));/* xint = xlow - ylow*y */ - } - lsp[nf++] = xlow; - move16(); - - IF(GE_16(nf, m)) - { - BREAK; - } - - ip = s_xor(ip, 1); - ylow = chebyshev(xlow, f[ip], nc, 8); - } - } - - /* Check if m roots found */ - /* if not use the LSPs from previous frame */ - - IF(LT_16(nf, m)) - { - FOR(i = 0; i < m; i++) - { - lsp[i] = old_lsp[i]; - move16(); - } - } - - - return; + Word16 i, nf, ip, nc; + Word16 xlow, ylow, xhigh, yhigh; + Word16 x, y, tmp, exp; + Word32 f[2][NC_MAX + 1]; + Word32 t0, t1; + Word32 sum, diff; + Word16 scale; + + + nc = shr( m, 1 ); + + scale = shl( 128, norm_s( a[0] ) ); + + /*-------------------------------------------------------------* + * find the sum and diff polynomials F1(z) and F2(z) * + * F1(z) = [A(z) + z^11 A(z^-1)]/(1+z^-1) * + * F2(z) = [A(z) - z^11 A(z^-1)]/(1-z^-1) * + *-------------------------------------------------------------*/ + + f[0][0] = L_mult( a[0], scale ); /*1.0f in Q23*/ + move32(); + f[1][0] = L_mult( a[0], scale ); /*1.0f in Q23*/ + move32(); + FOR( i = 1; i < nc; i++ ) + { + t0 = L_mult( a[i], scale ); /*Q23*/ + sum = L_mac( t0, a[m + 1 - i], scale ); + diff = L_msu( t0, a[m + 1 - i], scale ); + f[0][i] = L_sub( sum, f[0][i - 1] ); + move32(); /*Q23*/ + f[1][i] = L_add( diff, f[1][i - 1] ); + move32(); /*Q23*/ + } + t1 = L_mult0( a[i], scale ); /*Q23-1*/ + sum = L_mac0( t1, a[m + 1 - i], scale ); + diff = L_msu0( t1, a[m + 1 - i], scale ); + f[0][nc] = L_sub( sum, L_shr( f[0][i - 1], 1 ) ); + move32(); /*Q23-1*/ + f[1][nc] = L_add( diff, L_shr( f[1][i - 1], 1 ) ); + move32(); /*Q23-1*/ + + /* Precalculate difference to index 0 for index 2 */ + f[0][2] = L_sub( f[0][2], f[0][0] ); + move32(); + f[1][2] = L_sub( f[1][2], f[1][0] ); + move32(); + + /*---------------------------------------------------------------------* + * Find the LSPs (roots of F1(z) and F2(z) ) using the * + * Chebyshev polynomial evaluation. * + * The roots of F1(z) and F2(z) are alternatively searched. * + * We start by finding the first root of F1(z) then we switch * + * to F2(z) then back to F1(z) and so on until all roots are found. * + * * + * - Evaluate Chebyshev pol. at grid points and check for sign change.* + * - If sign change track the root by subdividing the interval * + * 4 times and ckecking sign change. * + *---------------------------------------------------------------------*/ + nf = 0; + move16(); /* number of found frequencies */ + ip = 0; + move16(); /* indicator for f1 or f2 */ + + xlow = Grid[0]; + move16(); + ylow = chebyshev( xlow, f[ip], nc, 8 ); + + FOR( i = 1; i <= GRID100_POINTS; i++ ) + { + xhigh = xlow; + move16(); + yhigh = ylow; + move16(); + xlow = Grid[i]; + move16(); + ylow = chebyshev( xlow, f[ip], nc, 8 ); + + IF( L_mult( ylow, yhigh ) <= 0 ) + { + t0 = L_mult( xhigh, 0x4000 ); + /* divide 2 times the interval */ + x = mac_r( t0, xlow, 0x4000 ); /* xmid = (xlow + xhigh)/2 */ + y = chebyshev( x, f[ip], nc, 8 ); + + IF( L_mult( ylow, y ) <= 0 ) + { + yhigh = y; + move16(); + xhigh = x; + move16(); + y = ylow; + move16(); + x = xlow; + move16(); + /* 'xhigh' has changed, update 't0' */ + t0 = L_mult( xhigh, 0x4000 ); + } + xlow = mac_r( t0, x, 0x4000 ); /* xmid = (xlow + xhigh)/2 */ + ylow = chebyshev( xlow, f[ip], nc, 8 ); + + IF( L_mult( y, ylow ) <= 0 ) + { + yhigh = ylow; + move16(); + xhigh = xlow; + move16(); + ylow = y; + move16(); + xlow = x; + move16(); + } + + /*--------------------------------------------------------* + * Linear interpolation + * xint = xlow - ylow*(xhigh-xlow)/(yhigh-ylow) + *--------------------------------------------------------*/ + y = msu_r( L_mult( yhigh, 0x4000 ), ylow, 0x4000 ); + + IF( y != 0 ) + { + x = sub( xhigh, xlow ); + BASOP_SATURATE_WARNING_OFF_EVS + tmp = abs_s( y ); + BASOP_SATURATE_WARNING_ON_EVS + exp = norm_s( tmp ); + if ( exp ) + tmp = shl( tmp, exp ); + tmp = div_s( (Word16) 16383 / 2, tmp ); + t0 = L_mult( x, tmp ); + t0 = L_shr( t0, sub( 20, exp ) ); + tmp = extract_l( t0 ); /* y = (xhigh-xlow)/(yhigh-ylow) in Q11 */ + + /* Restore Sign */ + if ( y < 0 ) + tmp = negate( tmp ); + + t0 = L_mult( ylow, tmp ); /* result in Q26 */ + t0 = L_shr( t0, 11 ); /* result in Q15 */ + xlow = sub( xlow, extract_l( t0 ) ); /* xint = xlow - ylow*y */ + } + lsp[nf++] = xlow; + move16(); + + IF( GE_16( nf, m ) ) + { + BREAK; + } + + ip = s_xor( ip, 1 ); + ylow = chebyshev( xlow, f[ip], nc, 8 ); + } + } + + /* Check if m roots found */ + /* if not use the LSPs from previous frame */ + + IF( LT_16( nf, m ) ) + { + FOR( i = 0; i < m; i++ ) + { + lsp[i] = old_lsp[i]; + move16(); + } + } + + + return; } /* @@ -1148,230 +1142,229 @@ void E_LPC_a_lsp_conversion( * Returns: * void */ -void E_LPC_f_lsp_a_conversion(const Word16 *lsp, Word16 *a, const Word16 m) +void E_LPC_f_lsp_a_conversion( const Word16 *lsp, Word16 *a, const Word16 m ) { - Word16 i, j, k; - Word32 f1[NC_MAX + 1], f2[NC_MAX + 1]; - Word16 nc; - Word32 t0; - Word16 Ovf, Ovf2; + Word16 i, j, k; + Word32 f1[NC_MAX + 1], f2[NC_MAX + 1]; + Word16 nc; + Word32 t0; + Word16 Ovf, Ovf2; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; + Flag Overflow = 0; #endif - /*-----------------------------------------------------* - * Find the polynomials F1(z) and F2(z) * - *-----------------------------------------------------*/ - - nc = shr(m, 1); - - assert(m == 16 || m == 10); - - Ovf = 0; - move16(); - Ovf = E_LPC_f_lsp_pol_get(&lsp[0], f1, nc, Ovf, 1); - Ovf2 = E_LPC_f_lsp_pol_get(&lsp[1], f2, nc, Ovf, 1); - IF(NE_16(Ovf2, Ovf)) - { - /* to ensure similar scaling for f1 and f2 in case - an overflow would be detected only in f2, - but this case never happen on my dtb */ - E_LPC_f_lsp_pol_get(&lsp[0], f1, nc, s_max(Ovf2, Ovf), 1); - } - /*-----------------------------------------------------* - * Multiply F1(z) by (1+z^-1) and F2(z) by (1-z^-1) * - *-----------------------------------------------------*/ - /*modification*/ - k = sub(nc, 1); - FOR(i = 0; i <= k; i++) - { - f1[nc - i] = L_add(f1[nc - i], f1[nc - i - 1]); - move32(); + /*-----------------------------------------------------* + * Find the polynomials F1(z) and F2(z) * + *-----------------------------------------------------*/ + + nc = shr( m, 1 ); + + assert( m == 16 || m == 10 ); + + Ovf = 0; + move16(); + Ovf = E_LPC_f_lsp_pol_get( &lsp[0], f1, nc, Ovf, 1 ); + Ovf2 = E_LPC_f_lsp_pol_get( &lsp[1], f2, nc, Ovf, 1 ); + IF( NE_16( Ovf2, Ovf ) ) + { + /* to ensure similar scaling for f1 and f2 in case + an overflow would be detected only in f2, + but this case never happen on my dtb */ + E_LPC_f_lsp_pol_get( &lsp[0], f1, nc, s_max( Ovf2, Ovf ), 1 ); + } + /*-----------------------------------------------------* + * Multiply F1(z) by (1+z^-1) and F2(z) by (1-z^-1) * + *-----------------------------------------------------*/ + /*modification*/ + k = sub( nc, 1 ); + FOR( i = 0; i <= k; i++ ) + { + f1[nc - i] = L_add( f1[nc - i], f1[nc - i - 1] ); + move32(); #ifdef BASOP_NOGLOB - f2[nc - i] = L_sub_o(f2[nc - i], f2[nc - i - 1], &Overflow); + f2[nc - i] = L_sub_o( f2[nc - i], f2[nc - i - 1], &Overflow ); #else - f2[nc - i] = L_sub(f2[nc - i], f2[nc - i - 1]); + f2[nc - i] = L_sub( f2[nc - i], f2[nc - i - 1] ); #endif - move32(); - } + move32(); + } - /*-----------------------------------------------------* - * A(z) = (F1(z)+F2(z))/2 * - * F1(z) is symmetric and F2(z) is antisymmetric * - *-----------------------------------------------------*/ + /*-----------------------------------------------------* + * A(z) = (F1(z)+F2(z))/2 * + * F1(z) is symmetric and F2(z) is antisymmetric * + *-----------------------------------------------------*/ - t0 = L_deposit_l(0); - FOR(i = 1; i <= nc; i++) - { + t0 = L_deposit_l( 0 ); + FOR( i = 1; i <= nc; i++ ) + { #ifdef BASOP_NOGLOB - t0 = L_max(t0, L_abs(L_add_o(f1[i], f2[i], &Overflow))); - t0 = L_max(t0, L_abs(L_sub_o(f1[i], f2[i], &Overflow))); + t0 = L_max( t0, L_abs( L_add_o( f1[i], f2[i], &Overflow ) ) ); + t0 = L_max( t0, L_abs( L_sub_o( f1[i], f2[i], &Overflow ) ) ); #else - t0 = L_max(t0, L_abs(L_add(f1[i], f2[i]))); - t0 = L_max(t0, L_abs(L_sub(f1[i], f2[i]))); + t0 = L_max( t0, L_abs( L_add( f1[i], f2[i] ) ) ); + t0 = L_max( t0, L_abs( L_sub( f1[i], f2[i] ) ) ); #endif - - } - k = s_min(norm_l(t0), 6); - a[0] = shl(256, k); - move16(); - test(); - IF(Ovf || Ovf2) - { - a[0] = shl(256, sub(k, Ovf)); - move16(); - } - j = m; - FOR(i = 1; i <= nc; i++) - { - /* a[i] = 0.5*(f1[i] + f2[i]) */ + } + k = s_min( norm_l( t0 ), 6 ); + a[0] = shl( 256, k ); + move16(); + test(); + IF( Ovf || Ovf2 ) + { + a[0] = shl( 256, sub( k, Ovf ) ); + move16(); + } + j = m; + FOR( i = 1; i <= nc; i++ ) + { + /* a[i] = 0.5*(f1[i] + f2[i]) */ #ifdef BASOP_NOGLOB - t0 = L_add_o(f1[i], f2[i], &Overflow); + t0 = L_add_o( f1[i], f2[i], &Overflow ); #else - t0 = L_add(f1[i], f2[i]); + t0 = L_add( f1[i], f2[i] ); #endif - t0 = L_shl(t0, k); + t0 = L_shl( t0, k ); #ifdef BASOP_NOGLOB - a[i] = round_fx_o(t0, &Overflow); /* from Q23 to Qx and * 0.5 */ + a[i] = round_fx_o( t0, &Overflow ); /* from Q23 to Qx and * 0.5 */ #else - a[i] = round_fx(t0); /* from Q23 to Qx and * 0.5 */ + a[i] = round_fx( t0 ); /* from Q23 to Qx and * 0.5 */ #endif - /* a[j] = 0.5*(f1[i] - f2[i]) */ + /* a[j] = 0.5*(f1[i] - f2[i]) */ #ifdef BASOP_NOGLOB - t0 = L_sub_o(f1[i], f2[i], &Overflow); + t0 = L_sub_o( f1[i], f2[i], &Overflow ); #else - t0 = L_sub(f1[i], f2[i]); + t0 = L_sub( f1[i], f2[i] ); #endif - t0 = L_shl(t0, k); + t0 = L_shl( t0, k ); #ifdef BASOP_NOGLOB - a[j] = round_fx_o(t0, &Overflow); /* from Q23 to Qx and * 0.5 */ + a[j] = round_fx_o( t0, &Overflow ); /* from Q23 to Qx and * 0.5 */ #else - a[j] = round_fx(t0); /* from Q23 to Qx and * 0.5 */ + a[j] = round_fx( t0 ); /* from Q23 to Qx and * 0.5 */ #endif - j--; - } + j--; + } - return; + return; } /*--------------------------------------------------------------------------- - * reorder_lsf() - * - * To make sure that the LSFs are properly ordered and to keep a certain - * minimum distance between consecutive LSFs. - *--------------------------------------------------------------------------*/ + * reorder_lsf() + * + * To make sure that the LSFs are properly ordered and to keep a certain + * minimum distance between consecutive LSFs. + *--------------------------------------------------------------------------*/ void reorder_lsf_fx( - Word16 *lsf, /* i/o: LSFs in the frequency domain (0..0.5) Q(x2.56)*/ - const Word16 min_dist, /* i : minimum required distance x2.56*/ - const Word16 n, /* i : LPC order */ - const Word32 fs /* i : sampling frequency */ + Word16 *lsf, /* i/o: LSFs in the frequency domain (0..0.5) Q(x2.56)*/ + const Word16 min_dist, /* i : minimum required distance x2.56*/ + const Word16 n, /* i : LPC order */ + const Word32 fs /* i : sampling frequency */ ) { - Word16 i, lsf_min, n_m_1; - Word16 lsf_max; - - lsf_min = min_dist; - move16(); - - /*-----------------------------------------------------------------------* - * Verify the LSF ordering and minimum GAP - *-----------------------------------------------------------------------*/ - - FOR(i = 0; i < n; i++) - { - if (LT_16(lsf[i], lsf_min)) - { - lsf[i] = lsf_min; - move16(); - } - lsf_min = add(lsf[i], min_dist); - } - - /*-----------------------------------------------------------------------* - * Reverify the LSF ordering and minimum GAP in the reverse order (security) - *-----------------------------------------------------------------------*/ - lsf_max = round_fx(L_sub(L_shr(L_mult0(extract_l(L_shr(fs, 1)), 1311), 9 - 16), L_deposit_h(min_dist))); /* Q0 + Q9 , 1311 is 2.56 in Q9 */ - n_m_1 = sub(n, 1); - IF(GT_16(lsf[n_m_1], lsf_max)) /* If danger of unstable filter in case of resonance in HF */ - { - FOR(i = n_m_1; i >= 0; i--) /* Reverify the minimum LSF gap in the reverse direction */ - { - if (GT_16(lsf[i], lsf_max)) - { - lsf[i] = lsf_max; - move16(); - } - lsf_max = sub(lsf[i], min_dist); - } - } + Word16 i, lsf_min, n_m_1; + Word16 lsf_max; + + lsf_min = min_dist; + move16(); + + /*-----------------------------------------------------------------------* + * Verify the LSF ordering and minimum GAP + *-----------------------------------------------------------------------*/ + + FOR( i = 0; i < n; i++ ) + { + if ( LT_16( lsf[i], lsf_min ) ) + { + lsf[i] = lsf_min; + move16(); + } + lsf_min = add( lsf[i], min_dist ); + } + + /*-----------------------------------------------------------------------* + * Reverify the LSF ordering and minimum GAP in the reverse order (security) + *-----------------------------------------------------------------------*/ + lsf_max = round_fx( L_sub( L_shr( L_mult0( extract_l( L_shr( fs, 1 ) ), 1311 ), 9 - 16 ), L_deposit_h( min_dist ) ) ); /* Q0 + Q9 , 1311 is 2.56 in Q9 */ + n_m_1 = sub( n, 1 ); + IF( GT_16( lsf[n_m_1], lsf_max ) ) /* If danger of unstable filter in case of resonance in HF */ + { + FOR( i = n_m_1; i >= 0; i-- ) /* Reverify the minimum LSF gap in the reverse direction */ + { + if ( GT_16( lsf[i], lsf_max ) ) + { + lsf[i] = lsf_max; + move16(); + } + lsf_max = sub( lsf[i], min_dist ); + } + } } void space_lsfs_fx( - Word16* lsfs, /* i/o: Line spectral frequencies */ - const Word16 order /* i : order of LP analysis */ + Word16 *lsfs, /* i/o: Line spectral frequencies */ + const Word16 order /* i : order of LP analysis */ ) { - Word16 delta; /* Q1.15 */ - Word16 i, flag = 1; - - WHILE(flag == 1) - { - flag = 0; - move16(); - FOR(i = 0; i <= order; i++) - { - IF(i == 0) - { - delta = lsfs[0]; - move16(); - } - ELSE - { - IF(EQ_16(i,order)) - { - delta = sub(HALF_POINT_FX, lsfs[i - 1]); - move16(); - } - ELSE - { - delta = sub(lsfs[i], lsfs[i - 1]); - move16(); - } - } - IF(LT_16(delta, SPC_FX)) - { - flag = 1; - move16(); - delta = sub(delta, SPC_PLUS_FX); - - IF(i == order) - { - lsfs[i - 1] = add(lsfs[i - 1], delta); - move16(); - } - ELSE - { - IF(i == 0) - { - lsfs[i] = sub(lsfs[i], delta); - move16(); - } - ELSE - { - delta = mult_r(delta, HALF_POINT_FX); - lsfs[i - 1] = add(lsfs[i - 1], delta); - move16(); - lsfs[i] = sub(lsfs[i], delta); - move16(); - } - } - } - } - } - - return; + Word16 delta; /* Q1.15 */ + Word16 i, flag = 1; + + WHILE( flag == 1 ) + { + flag = 0; + move16(); + FOR( i = 0; i <= order; i++ ) + { + IF( i == 0 ) + { + delta = lsfs[0]; + move16(); + } + ELSE + { + IF( EQ_16( i, order ) ) + { + delta = sub( HALF_POINT_FX, lsfs[i - 1] ); + move16(); + } + ELSE + { + delta = sub( lsfs[i], lsfs[i - 1] ); + move16(); + } + } + IF( LT_16( delta, SPC_FX ) ) + { + flag = 1; + move16(); + delta = sub( delta, SPC_PLUS_FX ); + + IF( i == order ) + { + lsfs[i - 1] = add( lsfs[i - 1], delta ); + move16(); + } + ELSE + { + IF( i == 0 ) + { + lsfs[i] = sub( lsfs[i], delta ); + move16(); + } + ELSE + { + delta = mult_r( delta, HALF_POINT_FX ); + lsfs[i - 1] = add( lsfs[i - 1], delta ); + move16(); + lsfs[i] = sub( lsfs[i], delta ); + move16(); + } + } + } + } + } + + return; } /*=================================================================== */ @@ -1396,68 +1389,67 @@ _ (Word16 []) lsp_nq_fx: input unquantized lsp vector */ /*=================================================================== */ void lsp_weights_fx( - Word16 lsp_nq_fx[], - Word16 w[], - Word16 Order, - Word16* Qout -) + Word16 lsp_nq_fx[], + Word16 w[], + Word16 Order, + Word16 *Qout ) { - Word16 lpcOrder = Order; - - Word16 i, n1, tmp_loop; - Word16 norm[20]; - Word32 Lsum1[20]; - Word16 delta1, delta2, temp; - Word16 n_max = -32768; - move16(); - - temp = 0; - move16(); - - tmp_loop = sub(lpcOrder, 1); - FOR(i = 0; i < tmp_loop; i++) - { - delta1 = sub(lsp_nq_fx[i], temp); - delta2 = sub(lsp_nq_fx[i + 1], lsp_nq_fx[i]); - Lsum1[i] = calc_weight(delta1, delta2, &n1); - move32();/* Q( 26-n1) */ - norm[i] = n1; - move16(); - - if (GT_16(norm[i], n_max)) - { - n_max = norm[i]; - move16(); - } - temp = lsp_nq_fx[i]; - move16(); - } - delta1 = sub(lsp_nq_fx[i], temp); - delta2 = sub(16384, lsp_nq_fx[i]); - - Lsum1[i] = calc_weight(delta1, delta2, &n1); - move32(); /* Q( 26-n1) */ - norm[i] = n1; - move16(); - - if (GT_16(norm[i], n_max)) - { - n_max = norm[i]; - move16(); - } - FOR(i = 0; i < lpcOrder; i++) - { - w[i] = round_fx(L_shl(Lsum1[i], sub(norm[i], n_max + 1))); /* Q( 9-n_max) */ - } - - IF(lpcOrder != LPC_SHB_ORDER_WB) - { - w[3] = round_fx(L_shl(L_mult(w[3], 18022), 1)); /* Q( 9-n_max) */ - w[4] = round_fx(L_shl(L_mult(w[4], 18022), 1)); /* Q( 9-n_max) */ - } - - *Qout = 9 - n_max; - move16(); + Word16 lpcOrder = Order; + + Word16 i, n1, tmp_loop; + Word16 norm[20]; + Word32 Lsum1[20]; + Word16 delta1, delta2, temp; + Word16 n_max = -32768; + move16(); + + temp = 0; + move16(); + + tmp_loop = sub( lpcOrder, 1 ); + FOR( i = 0; i < tmp_loop; i++ ) + { + delta1 = sub( lsp_nq_fx[i], temp ); + delta2 = sub( lsp_nq_fx[i + 1], lsp_nq_fx[i] ); + Lsum1[i] = calc_weight( delta1, delta2, &n1 ); + move32(); /* Q( 26-n1) */ + norm[i] = n1; + move16(); + + if ( GT_16( norm[i], n_max ) ) + { + n_max = norm[i]; + move16(); + } + temp = lsp_nq_fx[i]; + move16(); + } + delta1 = sub( lsp_nq_fx[i], temp ); + delta2 = sub( 16384, lsp_nq_fx[i] ); + + Lsum1[i] = calc_weight( delta1, delta2, &n1 ); + move32(); /* Q( 26-n1) */ + norm[i] = n1; + move16(); + + if ( GT_16( norm[i], n_max ) ) + { + n_max = norm[i]; + move16(); + } + FOR( i = 0; i < lpcOrder; i++ ) + { + w[i] = round_fx( L_shl( Lsum1[i], sub( norm[i], n_max + 1 ) ) ); /* Q( 9-n_max) */ + } + + IF( lpcOrder != LPC_SHB_ORDER_WB ) + { + w[3] = round_fx( L_shl( L_mult( w[3], 18022 ), 1 ) ); /* Q( 9-n_max) */ + w[4] = round_fx( L_shl( L_mult( w[4], 18022 ), 1 ) ); /* Q( 9-n_max) */ + } + + *Qout = 9 - n_max; + move16(); } /* @@ -1477,23 +1469,23 @@ void lsp_weights_fx( * Returns: * void */ -void E_LPC_isf_isp_conversion(const Word16 isf[], Word16 isp[], const Word16 m) +void E_LPC_isf_isp_conversion( const Word16 isf[], Word16 isp[], const Word16 m ) { - Word16 i; + Word16 i; - assert(m == 16 || m == 10); + assert( m == 16 || m == 10 ); - FOR(i = 1; i < m; i++) - { - *isp++ = xsf_to_xsp(*isf++); - move16(); - } - *isp = xsf_to_xsp(shl(*isf, 1)); - move16(); + FOR( i = 1; i < m; i++ ) + { + *isp++ = xsf_to_xsp( *isf++ ); + move16(); + } + *isp = xsf_to_xsp( shl( *isf, 1 ) ); + move16(); - return; + return; } /* @@ -1513,88 +1505,87 @@ void E_LPC_isf_isp_conversion(const Word16 isf[], Word16 isp[], const Word16 m) * Returns: * energy of prediction error */ -void E_LPC_isp_isf_conversion(const Word16 isp[], Word16 isf[], const Word16 m) +void E_LPC_isp_isf_conversion( const Word16 isp[], Word16 isf[], const Word16 m ) { - Word16 i; - - assert(m == 16 || m == 10); + Word16 i; + assert( m == 16 || m == 10 ); - FOR(i = 0; i < m; i++) - { - isf[i] = xsp_to_xsf(isp[i]); - move16(); - } + FOR( i = 0; i < m; i++ ) + { + isf[i] = xsp_to_xsf( isp[i] ); + move16(); + } - isf[m - 1] = shr(isf[m - 1], 1); - move16(); + isf[m - 1] = shr( isf[m - 1], 1 ); + move16(); - return; + return; } -Word16 xsf_to_xsp(Word16 lsf) +Word16 xsf_to_xsp( Word16 lsf ) { - /* lsp = cos(lsf * 3.1415/6400); */ - return getCosWord16R2(lsf); + /* lsp = cos(lsf * 3.1415/6400); */ + return getCosWord16R2( lsf ); } -Word16 xsp_to_xsf(Word16 lsp) +Word16 xsp_to_xsf( Word16 lsp ) { - Word16 ind, tmp; - Word32 L_tmp; - - - /*------------------------------------------------------* - * find value in table that is just greater than lsp - *------------------------------------------------------*/ - - /* Retrieve Index Guess */ - /* Based on lsp */ - ind = mac_r(GUESS_TBL_SZ / 2 * 65536 - 0x8000, lsp, GUESS_TBL_SZ / 2); - ind = Ind_Guess[ind]; - move16(); - - /* Correct Index so that */ - /* cos_table_129[ind] > isp[i] */ - tmp = sub(lsp, cos_table_129[ind]); - /* - 69%: (Final Index - Index Guess) is <= 1 - 28%: (Final Index - Index Guess) is 2 - 2%: (Final Index - Index Guess) is >= 3 - <1%: ... - */ - IF(tmp > 0) /* possible range 0 to -5 (-1-2-2) */ - { - ind = sub(ind, 1); - tmp = sub(lsp, cos_table_129[ind]); - - IF(tmp > 0) - { - ind = sub(ind, 2); - tmp = sub(lsp, cos_table_129[ind]); - if (tmp > 0) - { - ind = sub(ind, 2); - } - tmp = sub(lsp, cos_table_129[ind + 1]); - if (tmp <= 0) - { - ind = add(ind, 1); - } - tmp = sub(lsp, cos_table_129[ind]); - } - } - - /* acos(lsp)= ind*128 + (lsp-cos_table_129[ind]) * acos_slope[ind] / 2048 */ - L_tmp = L_mac(1L << 11, tmp, acos_slope[ind]); - L_tmp = L_shr(L_tmp, 12); /* (lsp-cos_table_129[ind]) * acos_slope[ind]) >> 11 */ - L_tmp = L_mac0(L_tmp, ind, 128); - - - return extract_l(L_tmp); + Word16 ind, tmp; + Word32 L_tmp; + + + /*------------------------------------------------------* + * find value in table that is just greater than lsp + *------------------------------------------------------*/ + + /* Retrieve Index Guess */ + /* Based on lsp */ + ind = mac_r( GUESS_TBL_SZ / 2 * 65536 - 0x8000, lsp, GUESS_TBL_SZ / 2 ); + ind = Ind_Guess[ind]; + move16(); + + /* Correct Index so that */ + /* cos_table_129[ind] > isp[i] */ + tmp = sub( lsp, cos_table_129[ind] ); + /* + 69%: (Final Index - Index Guess) is <= 1 + 28%: (Final Index - Index Guess) is 2 + 2%: (Final Index - Index Guess) is >= 3 + <1%: ... + */ + IF( tmp > 0 ) /* possible range 0 to -5 (-1-2-2) */ + { + ind = sub( ind, 1 ); + tmp = sub( lsp, cos_table_129[ind] ); + + IF( tmp > 0 ) + { + ind = sub( ind, 2 ); + tmp = sub( lsp, cos_table_129[ind] ); + if ( tmp > 0 ) + { + ind = sub( ind, 2 ); + } + tmp = sub( lsp, cos_table_129[ind + 1] ); + if ( tmp <= 0 ) + { + ind = add( ind, 1 ); + } + tmp = sub( lsp, cos_table_129[ind] ); + } + } + + /* acos(lsp)= ind*128 + (lsp-cos_table_129[ind]) * acos_slope[ind] / 2048 */ + L_tmp = L_mac( 1L << 11, tmp, acos_slope[ind] ); + L_tmp = L_shr( L_tmp, 12 ); /* (lsp-cos_table_129[ind]) * acos_slope[ind]) >> 11 */ + L_tmp = L_mac0( L_tmp, ind, 128 ); + + + return extract_l( L_tmp ); } /*-------------------------------------------------------------------* @@ -1603,185 +1594,182 @@ Word16 xsp_to_xsf(Word16 lsp) * Convert from LPC to reflection coeff *-------------------------------------------------------------------*/ -void a2rc_fx(const Word16* a, /* i: can be any Q */ - Word16* refl, /* o: Q15 */ - Word16 lpcorder -) +void a2rc_fx( const Word16 *a, /* i: can be any Q */ + Word16 *refl, /* o: Q15 */ + Word16 lpcorder ) { - Word16 f_fx[M]; - Word16 km_fx; - Word32 L_tmp1, L_tmp2; - Word16 tmp; - Word16 denom_mant, exp; - Word32 new_mant; - Word16 temp; - Word16 m, j, n; - Word16 q, q_a, q_a2, One_Qx; - Word32 One_Qx2; + Word16 f_fx[M]; + Word16 km_fx; + Word32 L_tmp1, L_tmp2; + Word16 tmp; + Word16 denom_mant, exp; + Word32 new_mant; + Word16 temp; + Word16 m, j, n; + Word16 q, q_a, q_a2, One_Qx; + Word32 One_Qx2; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; + Flag Overflow = 0; #endif - q = add(norm_s(a[-1]), 1); - q_a = sub(15, q); - q_a2 = add(shl(q_a, 1), 1); - /* copy into internal vars so they can be changed */ - - FOR(m = 0; m < lpcorder; m++) - { - /* f_fx[m] = p_fx[m]; */ - f_fx[m] = negate(a[m]); - move16(); - } - One_Qx = shl(1, q_a); - One_Qx2 = L_shl(1, q_a2); - FOR(m = lpcorder - 1; m >= 0; m--) - { - km_fx = f_fx[m]; - move16(); - - test(); - IF(LE_16(km_fx, negate(One_Qx)) || GE_16(km_fx, One_Qx)) - { - FOR(j = 0; j < lpcorder; j++) - { - refl[j] = 0; - move16(); - } - - return; - } - - refl[m] = negate(km_fx); - move16(); - L_tmp1 = One_Qx2; /* 1 in 2xq_a+1 */ - move32(); - L_tmp1 = L_msu(L_tmp1, km_fx, km_fx); /* 1-km*km in Q25 */ - - /* new_mant = invert_dp(L_tmp1,4, &tmp_denom_exp,1); sum in Q61-Q25-n=Q36-n */ - exp = norm_l(L_tmp1); - tmp = extract_h(L_shl(L_tmp1, exp)); - exp = sub(sub(30, exp), q_a2); - IF(tmp) - { - tmp = div_s(16384, tmp); /* 15+exp */ - } - ELSE - { - tmp = 0; - } - new_mant = L_deposit_h(tmp); - temp = round_fx(L_shl(new_mant, 0)); /* in Q14 */ - denom_mant = temp; - move16(); - L_tmp1 = L_mult(km_fx, denom_mant); /* km*denom. Q12*Q14 = Q27 */ - L_tmp1 = L_shl(L_tmp1, q); /* change to Q31. simulation showed no overflow */ - tmp = round_fx(L_tmp1); /* extract in Q15 */ - - FOR(j = 0; j < m / 2; j++) - { - n = sub(sub(m, (Word16)1), j); - L_tmp1 = L_mult(denom_mant, f_fx[j]); /* denom*f[j]. Q15*Q12 = Q28 (floating with exp) */ + q = add( norm_s( a[-1] ), 1 ); + q_a = sub( 15, q ); + q_a2 = add( shl( q_a, 1 ), 1 ); + /* copy into internal vars so they can be changed */ + + FOR( m = 0; m < lpcorder; m++ ) + { + /* f_fx[m] = p_fx[m]; */ + f_fx[m] = negate( a[m] ); + move16(); + } + One_Qx = shl( 1, q_a ); + One_Qx2 = L_shl( 1, q_a2 ); + FOR( m = lpcorder - 1; m >= 0; m-- ) + { + km_fx = f_fx[m]; + move16(); + + test(); + IF( LE_16( km_fx, negate( One_Qx ) ) || GE_16( km_fx, One_Qx ) ) + { + FOR( j = 0; j < lpcorder; j++ ) + { + refl[j] = 0; + move16(); + } + + return; + } + + refl[m] = negate( km_fx ); + move16(); + L_tmp1 = One_Qx2; /* 1 in 2xq_a+1 */ + move32(); + L_tmp1 = L_msu( L_tmp1, km_fx, km_fx ); /* 1-km*km in Q25 */ + + /* new_mant = invert_dp(L_tmp1,4, &tmp_denom_exp,1); sum in Q61-Q25-n=Q36-n */ + exp = norm_l( L_tmp1 ); + tmp = extract_h( L_shl( L_tmp1, exp ) ); + exp = sub( sub( 30, exp ), q_a2 ); + IF( tmp ) + { + tmp = div_s( 16384, tmp ); /* 15+exp */ + } + ELSE + { + tmp = 0; + } + new_mant = L_deposit_h( tmp ); + temp = round_fx( L_shl( new_mant, 0 ) ); /* in Q14 */ + denom_mant = temp; + move16(); + L_tmp1 = L_mult( km_fx, denom_mant ); /* km*denom. Q12*Q14 = Q27 */ + L_tmp1 = L_shl( L_tmp1, q ); /* change to Q31. simulation showed no overflow */ + tmp = round_fx( L_tmp1 ); /* extract in Q15 */ + + FOR( j = 0; j < m / 2; j++ ) + { + n = sub( sub( m, (Word16) 1 ), j ); + L_tmp1 = L_mult( denom_mant, f_fx[j] ); /* denom*f[j]. Q15*Q12 = Q28 (floating with exp) */ #ifdef BASOP_NOGLOB - L_tmp1 = L_mac_o(L_tmp1, tmp, f_fx[n], &Overflow); /* denom*f[j]+km*denom*f[n] in Q28 (floating with exp) */ + L_tmp1 = L_mac_o( L_tmp1, tmp, f_fx[n], &Overflow ); /* denom*f[j]+km*denom*f[n] in Q28 (floating with exp) */ #else - L_tmp1 = L_mac(L_tmp1, tmp, f_fx[n]); /* denom*f[j]+km*denom*f[n] in Q28 (floating with exp) */ + L_tmp1 = L_mac( L_tmp1, tmp, f_fx[n] ); /* denom*f[j]+km*denom*f[n] in Q28 (floating with exp) */ #endif - L_tmp2 = L_mult(denom_mant, f_fx[n]); /* denom*f[n]. Q15*Q12 = Q28 (floating with exp) */ + L_tmp2 = L_mult( denom_mant, f_fx[n] ); /* denom*f[n]. Q15*Q12 = Q28 (floating with exp) */ #ifdef BASOP_NOGLOB - L_tmp2 = L_mac_o(L_tmp2, tmp, f_fx[j], &Overflow); /* denom*f[n]+km*denom*f[j] in Q28 (floating with exp) */ - L_tmp1 = L_shr_o(L_tmp1, exp, &Overflow); /* bringing to true Q28 */ - L_tmp2 = L_shr_o(L_tmp2, exp, &Overflow); /* bringing to true Q28 */ - f_fx[j] = round_fx_o(L_tmp1, &Overflow); /* extracting in q_a */ - f_fx[n] = round_fx_o(L_tmp2, &Overflow); /* extracting in q_a */ + L_tmp2 = L_mac_o( L_tmp2, tmp, f_fx[j], &Overflow ); /* denom*f[n]+km*denom*f[j] in Q28 (floating with exp) */ + L_tmp1 = L_shr_o( L_tmp1, exp, &Overflow ); /* bringing to true Q28 */ + L_tmp2 = L_shr_o( L_tmp2, exp, &Overflow ); /* bringing to true Q28 */ + f_fx[j] = round_fx_o( L_tmp1, &Overflow ); /* extracting in q_a */ + f_fx[n] = round_fx_o( L_tmp2, &Overflow ); /* extracting in q_a */ #else - L_tmp2 = L_mac(L_tmp2, tmp, f_fx[j]); /* denom*f[n]+km*denom*f[j] in Q28 (floating with exp) */ - L_tmp1 = L_shr(L_tmp1, exp); /* bringing to true Q28 */ - L_tmp2 = L_shr(L_tmp2, exp); /* bringing to true Q28 */ - f_fx[j] = round_fx(L_tmp1); /* extracting in q_a */ - f_fx[n] = round_fx(L_tmp2); /* extracting in q_a */ + L_tmp2 = L_mac( L_tmp2, tmp, f_fx[j] ); /* denom*f[n]+km*denom*f[j] in Q28 (floating with exp) */ + L_tmp1 = L_shr( L_tmp1, exp ); /* bringing to true Q28 */ + L_tmp2 = L_shr( L_tmp2, exp ); /* bringing to true Q28 */ + f_fx[j] = round_fx( L_tmp1 ); /* extracting in q_a */ + f_fx[n] = round_fx( L_tmp2 ); /* extracting in q_a */ #endif - } + } - IF(m & 1) - { - L_tmp1 = L_mult(denom_mant, f_fx[j]); /* denom*f[j]. Q15*Q12 = Q28 (floating with exp) */ + IF( m & 1 ) + { + L_tmp1 = L_mult( denom_mant, f_fx[j] ); /* denom*f[j]. Q15*Q12 = Q28 (floating with exp) */ #ifdef BASOP_NOGLOB - L_tmp1 = L_mac_o(L_tmp1, tmp, f_fx[j], &Overflow); /* denom*f[j]+km*denom*f[j] in Q28 (floating with exp) */ - L_tmp1 = L_shr_o(L_tmp1, exp, &Overflow); /* bringing to true Q28 */ - f_fx[j] = round_fx_o(L_tmp1, &Overflow); /* extracting in q_a */ -#else - L_tmp1 = L_mac(L_tmp1, tmp, f_fx[j]); /* denom*f[j]+km*denom*f[j] in Q28 (floating with exp) */ - L_tmp1 = L_shr(L_tmp1, exp); /* bringing to true Q28 */ - f_fx[j] = round_fx(L_tmp1); /* extracting in q_a */ + L_tmp1 = L_mac_o( L_tmp1, tmp, f_fx[j], &Overflow ); /* denom*f[j]+km*denom*f[j] in Q28 (floating with exp) */ + L_tmp1 = L_shr_o( L_tmp1, exp, &Overflow ); /* bringing to true Q28 */ + f_fx[j] = round_fx_o( L_tmp1, &Overflow ); /* extracting in q_a */ +#else + L_tmp1 = L_mac( L_tmp1, tmp, f_fx[j] ); /* denom*f[j]+km*denom*f[j] in Q28 (floating with exp) */ + L_tmp1 = L_shr( L_tmp1, exp ); /* bringing to true Q28 */ + f_fx[j] = round_fx( L_tmp1 ); /* extracting in q_a */ #endif - } - } + } + } - FOR(j = 0; j < lpcorder; j++) - { - refl[j] = shl(refl[j], q); - move16(); - } + FOR( j = 0; j < lpcorder; j++ ) + { + refl[j] = shl( refl[j], q ); + move16(); + } - return; + return; } Word16 vq_dec_lvq_fx( - Word16 sf_flag, /* i : safety net flag */ - Word16 x[], /* o : Decoded vector Q(x2.56)*/ - Word16 indices[], /* i : Indices */ - Word16 stages, /* i : Number of stages */ - Word16 N, /* i : Vector dimension */ - Word16 mode, /* (i): mode_lvq, or mode_lvq_p */ - Word16 no_bits, /* (i): no. bits for lattice */ - Word32 *p_offset_scale1, - Word32 *p_offset_scale2, - Word32 *p_offset_scale1_p, - Word32 *p_offset_scale2_p, - Word16 *p_no_scales, - Word16 *p_no_scales_p -) + Word16 sf_flag, /* i : safety net flag */ + Word16 x[], /* o : Decoded vector Q(x2.56)*/ + Word16 indices[], /* i : Indices */ + Word16 stages, /* i : Number of stages */ + Word16 N, /* i : Vector dimension */ + Word16 mode, /* (i): mode_lvq, or mode_lvq_p */ + Word16 no_bits, /* (i): no. bits for lattice */ + Word32 *p_offset_scale1, + Word32 *p_offset_scale2, + Word32 *p_offset_scale1_p, + Word32 *p_offset_scale2_p, + Word16 *p_no_scales, + Word16 *p_no_scales_p ) { - Word16 x_lvq[M]; - Word16 i, stagesm1; - Word16 pt_fx; - Word16 ber_flag; - - /* clear vector */ - set16_fx(x, 0, N); - - /*-----------------------------------------------* - * add contribution of each stage - *-----------------------------------------------*/ - stagesm1 = sub(stages, 1); - IF(EQ_16(sf_flag, 1)) - { - FOR(i = 0; i < stagesm1; i++) - { - pt_fx = i_mult2(indices[i], N); - Vr_add(x, &Quantizers_fx[CB_lsf[mode] + i][pt_fx], x, N); - } - - ber_flag = - deindex_lvq_fx(&indices[stagesm1], x_lvq, mode, sf_flag, no_bits, p_offset_scale1, p_offset_scale2, p_no_scales); - - } - ELSE - { - FOR(i = 0; i < stagesm1; i++) - { - pt_fx = i_mult2(indices[i], N); - Vr_add(x, &Quantizers_p_fx[CB_p_lsf[mode] + i][pt_fx], x, N); - } - - ber_flag = - deindex_lvq_fx(&indices[stagesm1], x_lvq, mode, sf_flag, no_bits, p_offset_scale1_p, p_offset_scale2_p, p_no_scales_p); - } - - Vr_add(x, x_lvq, x, N); - - return ber_flag; + Word16 x_lvq[M]; + Word16 i, stagesm1; + Word16 pt_fx; + Word16 ber_flag; + + /* clear vector */ + set16_fx( x, 0, N ); + + /*-----------------------------------------------* + * add contribution of each stage + *-----------------------------------------------*/ + stagesm1 = sub( stages, 1 ); + IF( EQ_16( sf_flag, 1 ) ) + { + FOR( i = 0; i < stagesm1; i++ ) + { + pt_fx = i_mult2( indices[i], N ); + Vr_add( x, &Quantizers_fx[CB_lsf[mode] + i][pt_fx], x, N ); + } + + ber_flag = + deindex_lvq_fx( &indices[stagesm1], x_lvq, mode, sf_flag, no_bits, p_offset_scale1, p_offset_scale2, p_no_scales ); + } + ELSE + { + FOR( i = 0; i < stagesm1; i++ ) + { + pt_fx = i_mult2( indices[i], N ); + Vr_add( x, &Quantizers_p_fx[CB_p_lsf[mode] + i][pt_fx], x, N ); + } + + ber_flag = + deindex_lvq_fx( &indices[stagesm1], x_lvq, mode, sf_flag, no_bits, p_offset_scale1_p, p_offset_scale2_p, p_no_scales_p ); + } + + Vr_add( x, x_lvq, x, N ); + + return ber_flag; } Word16 vq_dec_lvq_ivas_fx( @@ -1837,245 +1825,245 @@ Word16 vq_dec_lvq_ivas_fx( } ivas_error lsf_allocate_fx( - const Word16 nBits, /* i : Number of bits to use for quantization */ - const Word16 framemode, /* i : ISF quantizer mode */ - const Word16 framemode_p, /* i : ISF quantizer mode predmode (mode_lvq_p) */ - Word16 *stages0, /* o : Number of stages for safety-net quantizer */ - Word16 *stages1, /* o : Number of stages for predictive quantizer */ - Word16 levels0[], /* o : Number of vectors for each stage for SFNET */ - Word16 levels1[], /* o : Number of vectors for each stage for pred */ - Word16 bits0[], /* o : Number of bits for each stage safety net */ - Word16 bits1[] /* o : Number of bits for each stage pred */ + const Word16 nBits, /* i : Number of bits to use for quantization */ + const Word16 framemode, /* i : ISF quantizer mode */ + const Word16 framemode_p, /* i : ISF quantizer mode predmode (mode_lvq_p) */ + Word16 *stages0, /* o : Number of stages for safety-net quantizer */ + Word16 *stages1, /* o : Number of stages for predictive quantizer */ + Word16 levels0[], /* o : Number of vectors for each stage for SFNET */ + Word16 levels1[], /* o : Number of vectors for each stage for pred */ + Word16 bits0[], /* o : Number of bits for each stage safety net */ + Word16 bits1[] /* o : Number of bits for each stage pred */ ) { - Word16 i; - Word16 cumleft; - Word16 bits_lvq, n_stages, nbits0; - ivas_error error; - - error = IVAS_ERR_OK; - - cumleft = nBits; - move16(); - - /*---------------------------------------------------* - * Calculate bit allocation for safety-net quantizer - *---------------------------------------------------*/ - - cumleft = BitsVQ[framemode]; - move16(); - bits_lvq = sub(nBits, cumleft); - nbits0 = CBbits[framemode]; - move16(); - IF(GT_16(nbits0, -1)) - { - IF(nbits0 > 0) - { - n_stages = 2; - move16(); - levels0[0] = CBsizes[nbits0]; - move16(); - bits0[0] = nbits0; - move16(); - bits0[1] = sub(cumleft, nbits0); - - IF(bits0[1] == 0) - { - n_stages = sub(n_stages, 1); - } - ELSE - { - levels0[1] = CBsizes[sub(cumleft,nbits0)]; - move16(); - } - } - ELSE /* no bits for VQ stage */ - { - n_stages = 0; - move16(); - } - - *stages0 = n_stages; - move16(); - IF(bits_lvq > 0) - { - bits0[n_stages] = bits_lvq; - move16(); - levels0[n_stages] = bits_lvq; - move16();/* this is number of bits, not levels */ - *stages0 = add(n_stages, 1); - move16(); - } - } - ELSE - { - *stages0 = 0; - move16(); - } - - /*---------------------------------------------------* - * Calculate bit allocation for predictive quantizer - *---------------------------------------------------*/ - IF(GT_16(framemode_p, -1)) - { - cumleft = BitsVQ_p[framemode_p]; - move16(); - bits_lvq = sub(nBits, cumleft); - nbits0 = CBbits_p[framemode_p]; - move16(); - - IF(GT_16(nbits0, -1)) - { - IF(nbits0 > 0) - { - IF(EQ_16(framemode_p, 7)) - { - /* for UNVOICED_WB only */ - n_stages = 3; - move16(); - FOR(i = 0; i < n_stages; i++) - { - levels1[i] = CBsizes[nbits0]; - move16(); - bits1[i] = nbits0; - move16(); - } - bits1[n_stages] = bits_lvq; - move16(); - levels1[n_stages] = bits_lvq; - move16(); - *stages1 = add(n_stages, 1); - } - ELSE - { - n_stages = 1; - move16(); - levels1[0] = CBsizes[nbits0]; - move16(); - bits1[0] = nbits0; - move16(); - nbits0 = sub(cumleft, nbits0); - IF(nbits0 > 0) - { - levels1[1] = CBsizes[nbits0]; - move16(); - bits1[1] = nbits0; - move16(); - n_stages = 2; - move16(); - } - - levels1[n_stages] = bits_lvq; - move16();/* this is number of bits, not levels */ - bits1[n_stages] = bits_lvq; - move16(); - *stages1 = add(n_stages ,1); - } - } - ELSE - { - *stages1 = 1; - move16(); - bits1[0] = bits_lvq; - move16(); - levels1[0] = bits_lvq; - move16(); - } - } + Word16 i; + Word16 cumleft; + Word16 bits_lvq, n_stages, nbits0; + ivas_error error; + + error = IVAS_ERR_OK; + + cumleft = nBits; + move16(); + + /*---------------------------------------------------* + * Calculate bit allocation for safety-net quantizer + *---------------------------------------------------*/ + + cumleft = BitsVQ[framemode]; + move16(); + bits_lvq = sub( nBits, cumleft ); + nbits0 = CBbits[framemode]; + move16(); + IF( GT_16( nbits0, -1 ) ) + { + IF( nbits0 > 0 ) + { + n_stages = 2; + move16(); + levels0[0] = CBsizes[nbits0]; + move16(); + bits0[0] = nbits0; + move16(); + bits0[1] = sub( cumleft, nbits0 ); + + IF( bits0[1] == 0 ) + { + n_stages = sub( n_stages, 1 ); + } + ELSE + { + levels0[1] = CBsizes[sub( cumleft, nbits0 )]; + move16(); + } + } + ELSE /* no bits for VQ stage */ + { + n_stages = 0; + move16(); + } + + *stages0 = n_stages; + move16(); + IF( bits_lvq > 0 ) + { + bits0[n_stages] = bits_lvq; + move16(); + levels0[n_stages] = bits_lvq; + move16(); /* this is number of bits, not levels */ + *stages0 = add( n_stages, 1 ); + move16(); + } + } + ELSE + { + *stages0 = 0; + move16(); + } + + /*---------------------------------------------------* + * Calculate bit allocation for predictive quantizer + *---------------------------------------------------*/ + IF( GT_16( framemode_p, -1 ) ) + { + cumleft = BitsVQ_p[framemode_p]; + move16(); + bits_lvq = sub( nBits, cumleft ); + nbits0 = CBbits_p[framemode_p]; + move16(); + + IF( GT_16( nbits0, -1 ) ) + { + IF( nbits0 > 0 ) + { + IF( EQ_16( framemode_p, 7 ) ) + { + /* for UNVOICED_WB only */ + n_stages = 3; + move16(); + FOR( i = 0; i < n_stages; i++ ) + { + levels1[i] = CBsizes[nbits0]; + move16(); + bits1[i] = nbits0; + move16(); + } + bits1[n_stages] = bits_lvq; + move16(); + levels1[n_stages] = bits_lvq; + move16(); + *stages1 = add( n_stages, 1 ); + } + ELSE + { + n_stages = 1; + move16(); + levels1[0] = CBsizes[nbits0]; + move16(); + bits1[0] = nbits0; + move16(); + nbits0 = sub( cumleft, nbits0 ); + IF( nbits0 > 0 ) + { + levels1[1] = CBsizes[nbits0]; + move16(); + bits1[1] = nbits0; + move16(); + n_stages = 2; + move16(); + } + + levels1[n_stages] = bits_lvq; + move16(); /* this is number of bits, not levels */ + bits1[n_stages] = bits_lvq; + move16(); + *stages1 = add( n_stages, 1 ); + } + } + ELSE + { + *stages1 = 1; + move16(); + bits1[0] = bits_lvq; + move16(); + levels1[0] = bits_lvq; + move16(); + } + } #ifdef DEBUGGING - ELSE - { - return IVAS_ERROR(IVAS_ERR_INTERNAL_FATAL, "lsf_allocate(): invalid number of bits in used predictive mode\n"); - } + ELSE + { + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "lsf_allocate(): invalid number of bits in used predictive mode\n" ); + } #endif - } + } - return error; + return error; } ivas_error find_pred_mode( - Word16* predmode, /* o: prediction mode */ - const Word16 coder_type, /* i: coding type */ - const Word16 bwidth, /* i: bandwidth index */ - const Word32 int_fs, /* i: sampling frequency */ - Word16 * p_mode_lvq, /* o: index of LSF codebooks in safety net mode */ - Word16 * p_mode_lvq_p, /* o: index of LSF codebooks in predictive mode (AR or MA) */ - Word32 core_brate /* i: core bit rate */ + Word16 *predmode, /* o: prediction mode */ + const Word16 coder_type, /* i: coding type */ + const Word16 bwidth, /* i: bandwidth index */ + const Word32 int_fs, /* i: sampling frequency */ + Word16 *p_mode_lvq, /* o: index of LSF codebooks in safety net mode */ + Word16 *p_mode_lvq_p, /* o: index of LSF codebooks in predictive mode (AR or MA) */ + Word32 core_brate /* i: core bit rate */ ) { - Word16 idx; - ivas_error error; - - error = IVAS_ERR_OK; - - /* bwidth = 0(NB), 1 (WB), 2(WB2); line index in predmode_tab[][] */ - idx = bwidth; - move16(); - if (GT_16(idx, 1)) - { - idx = 1; - } - IF(EQ_32(int_fs, INT_FS_16k)) - { - /* WB2 is actually used if sampling frequency is 16kHz */ - idx = 2; - move16(); - } - ELSE - { - test(); - test(); - if ((GE_32(core_brate, GENERIC_MA_LIMIT)) && (EQ_16(coder_type,GENERIC)) && (EQ_16(idx,1))) - { - idx = 3; - move16(); - } - } - *predmode = predmode_tab[idx][coder_type]; - move16(); - IF(LE_16(idx, 2)) - { - *p_mode_lvq = add(i_mult2(NO_CODING_MODES, idx), coder_type); - IF(*predmode > 0) - { - *p_mode_lvq_p = *p_mode_lvq; - move16(); - } - ELSE - { - *p_mode_lvq_p = -1; - move16(); - } - } - ELSE /* WB 12.8 with MA pred in GENERIC*/ - { - *p_mode_lvq = add(NO_CODING_MODES, coder_type); - IF(EQ_16(coder_type, GENERIC)) - { - *p_mode_lvq_p = 18; - move16(); - } - ELSE - { - IF(*predmode > 0) - { - *p_mode_lvq_p = *p_mode_lvq; - } - ELSE - { - *p_mode_lvq_p = -1; - } - } - } + Word16 idx; + ivas_error error; + + error = IVAS_ERR_OK; + + /* bwidth = 0(NB), 1 (WB), 2(WB2); line index in predmode_tab[][] */ + idx = bwidth; + move16(); + if ( GT_16( idx, 1 ) ) + { + idx = 1; + } + IF( EQ_32( int_fs, INT_FS_16k ) ) + { + /* WB2 is actually used if sampling frequency is 16kHz */ + idx = 2; + move16(); + } + ELSE + { + test(); + test(); + if ( ( GE_32( core_brate, GENERIC_MA_LIMIT ) ) && ( EQ_16( coder_type, GENERIC ) ) && ( EQ_16( idx, 1 ) ) ) + { + idx = 3; + move16(); + } + } + *predmode = predmode_tab[idx][coder_type]; + move16(); + IF( LE_16( idx, 2 ) ) + { + *p_mode_lvq = add( i_mult2( NO_CODING_MODES, idx ), coder_type ); + IF( *predmode > 0 ) + { + *p_mode_lvq_p = *p_mode_lvq; + move16(); + } + ELSE + { + *p_mode_lvq_p = -1; + move16(); + } + } + ELSE /* WB 12.8 with MA pred in GENERIC*/ + { + *p_mode_lvq = add( NO_CODING_MODES, coder_type ); + IF( EQ_16( coder_type, GENERIC ) ) + { + *p_mode_lvq_p = 18; + move16(); + } + ELSE + { + IF( *predmode > 0 ) + { + *p_mode_lvq_p = *p_mode_lvq; + } + ELSE + { + *p_mode_lvq_p = -1; + } + } + } #ifdef DEBUGGING - if (*predmode == -1) - { - return IVAS_ERROR(IVAS_ERR_INTERNAL_FATAL, "\nfind_pred_mode(): incorrect coder_type specification: %d\n", coder_type); - } + if ( *predmode == -1 ) + { + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "\nfind_pred_mode(): incorrect coder_type specification: %d\n", coder_type ); + } #endif - return error; + return error; } /*---------------------------------------------------------------------------* @@ -2085,51 +2073,51 @@ ivas_error find_pred_mode( * minimum distance between consecutive isfs. *--------------------------------------------------------------------------*/ void reorder_isf_fx( - Word16 *isf, /* i/o: ISFs in the frequency domain (0..0.5) */ - const Word16 min_dist, /* i : minimum required distance */ - const Word16 n, /* i : LPC order */ - const Word16 fs /* i : sampling frequency */ + Word16 *isf, /* i/o: ISFs in the frequency domain (0..0.5) */ + const Word16 min_dist, /* i : minimum required distance */ + const Word16 n, /* i : LPC order */ + const Word16 fs /* i : sampling frequency */ ) { - Word16 i, isf_min; - Word16 isf_max; - - isf_min = min_dist; - move16(); - - /*-----------------------------------------------------------------------* - * Verify the ISF ordering and minimum GAP - *-----------------------------------------------------------------------*/ - - FOR(i = 0; i < n - 1; i++) - { - if (LT_16(isf[i], isf_min)) - { - isf[i] = isf_min; - move16(); - } - isf_min = add(isf[i], min_dist); - } - - /*-----------------------------------------------------------------------* - * Reverify the ISF ordering and minimum GAP in the reverse order (security) - *-----------------------------------------------------------------------*/ - - /*isf_max = sub(shr(fs,1), min_dist);*/ - isf_max = sub(fs, min_dist); /* Fs already divide per 2 */ - - IF(GT_16(isf[n - 2], isf_max)) /* If danger of unstable filter in case of resonance in HF */ - { - FOR(i = sub(n, 2); i >= 0; i--) /* Reverify the minimum ISF gap in the reverse direction */ - { - if (GT_16(isf[i], isf_max)) - { - isf[i] = isf_max; - move16(); - } - isf_max = sub(isf[i], min_dist); - } - } + Word16 i, isf_min; + Word16 isf_max; + + isf_min = min_dist; + move16(); + + /*-----------------------------------------------------------------------* + * Verify the ISF ordering and minimum GAP + *-----------------------------------------------------------------------*/ + + FOR( i = 0; i < n - 1; i++ ) + { + if ( LT_16( isf[i], isf_min ) ) + { + isf[i] = isf_min; + move16(); + } + isf_min = add( isf[i], min_dist ); + } + + /*-----------------------------------------------------------------------* + * Reverify the ISF ordering and minimum GAP in the reverse order (security) + *-----------------------------------------------------------------------*/ + + /*isf_max = sub(shr(fs,1), min_dist);*/ + isf_max = sub( fs, min_dist ); /* Fs already divide per 2 */ + + IF( GT_16( isf[n - 2], isf_max ) ) /* If danger of unstable filter in case of resonance in HF */ + { + FOR( i = sub( n, 2 ); i >= 0; i-- ) /* Reverify the minimum ISF gap in the reverse direction */ + { + if ( GT_16( isf[i], isf_max ) ) + { + isf[i] = isf_max; + move16(); + } + isf_max = sub( isf[i], min_dist ); + } + } } /*========================================================================*/ @@ -2152,79 +2140,79 @@ void reorder_isf_fx( /* RETURN ARGUMENTS : */ /* _ (Word16) stab_fac_fx : LP filter stability Q15 */ /*========================================================================*/ -Word16 lsf_stab_fx( /* o : LP filter stability Q15*/ - const Word16 *lsf, /* i : LSF vector Q(x2.56)*/ - const Word16 *lsfold, /* i : old LSF vector Q(x2.56)*/ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame /* i : frame length */ +Word16 lsf_stab_fx( /* o : LP filter stability Q15*/ + const Word16 *lsf, /* i : LSF vector Q(x2.56)*/ + const Word16 *lsfold, /* i : old LSF vector Q(x2.56)*/ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const Word16 L_frame /* i : frame length */ ) { - Word16 i, m; - Word32 L_tmp; - Word16 tmp, e; + Word16 i, m; + Word32 L_tmp; + Word16 tmp, e; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; + Flag Overflow = 0; #endif - /*-------------------------------------------------------------------* - * Check stability on lsf: distance between old lsf and current lsf - *-------------------------------------------------------------------*/ - IF(Opt_AMR_WB) - { - m = M - 1; - move16(); - tmp = sub(lsf[0], lsfold[0]); - L_tmp = L_mult(tmp, tmp); /* Q1 */ - FOR(i = 1; i < m; i++) - { - tmp = sub(lsf[i], lsfold[i]); - L_tmp = L_mac(L_tmp, tmp, tmp); /* Q1 */ - } - } - ELSE - { - m = M; - move16(); - L_tmp = 0; - move32(); - FOR(i = 0; i < m; i++) - { - tmp = sub(lsf[i], lsfold[i]); - L_tmp = L_mac(L_tmp, tmp, tmp); /* Q1 */ - } - } - - e = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, e); /*Q(1+e)*/ - - IF(L_frame == L_FRAME16k) - { - /*stab_fac = (float)(1.25f - (tmp/625000.0f));*/ - L_tmp = Mpy_32_16_1(L_tmp, 16777); /* 30-eQ(1+e)*-21Q36 = 30-21-eQ31-9+e */ - } - ELSE - { - /* stab_fac = (float)(1.25f - (tmp1/400000.0f*2.56=1024000)) */ - L_tmp = Mpy_32_16_1(L_tmp, 26214); /* 30-eQ(1+e)*-21Q36 = 30-21-eQ31-9+e */ - } - - e = sub(30 - 21 - 1, e); + /*-------------------------------------------------------------------* + * Check stability on lsf: distance between old lsf and current lsf + *-------------------------------------------------------------------*/ + IF( Opt_AMR_WB ) + { + m = M - 1; + move16(); + tmp = sub( lsf[0], lsfold[0] ); + L_tmp = L_mult( tmp, tmp ); /* Q1 */ + FOR( i = 1; i < m; i++ ) + { + tmp = sub( lsf[i], lsfold[i] ); + L_tmp = L_mac( L_tmp, tmp, tmp ); /* Q1 */ + } + } + ELSE + { + m = M; + move16(); + L_tmp = 0; + move32(); + FOR( i = 0; i < m; i++ ) + { + tmp = sub( lsf[i], lsfold[i] ); + L_tmp = L_mac( L_tmp, tmp, tmp ); /* Q1 */ + } + } + + e = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, e ); /*Q(1+e)*/ + + IF( L_frame == L_FRAME16k ) + { + /*stab_fac = (float)(1.25f - (tmp/625000.0f));*/ + L_tmp = Mpy_32_16_1( L_tmp, 16777 ); /* 30-eQ(1+e)*-21Q36 = 30-21-eQ31-9+e */ + } + ELSE + { + /* stab_fac = (float)(1.25f - (tmp1/400000.0f*2.56=1024000)) */ + L_tmp = Mpy_32_16_1( L_tmp, 26214 ); /* 30-eQ(1+e)*-21Q36 = 30-21-eQ31-9+e */ + } + + e = sub( 30 - 21 - 1, e ); #ifdef BASOP_NOGLOB - tmp = round_fx_o(L_shl_o(L_tmp, e, &Overflow), &Overflow); /*Q14*/ -#else /* BASOP_NOGLOB */ - tmp = round_fx(L_shl(L_tmp, e)); /*Q14*/ -#endif /* BASOP_NOGLOB */ + tmp = round_fx_o( L_shl_o( L_tmp, e, &Overflow ), &Overflow ); /*Q14*/ +#else /* BASOP_NOGLOB */ + tmp = round_fx( L_shl( L_tmp, e ) ); /*Q14*/ +#endif /* BASOP_NOGLOB */ - tmp = sub(20480, tmp); /* 1.25 - tmp in Q14 */ + tmp = sub( 20480, tmp ); /* 1.25 - tmp in Q14 */ #ifdef BASOP_NOGLOB - tmp = shl_o(tmp, 1, &Overflow); /* Q14 -> Q15 with saturation */ -#else /* BASOP_NOGLOB */ - tmp = shl(tmp, 1); /* Q14 -> Q15 with saturation */ + tmp = shl_o( tmp, 1, &Overflow ); /* Q14 -> Q15 with saturation */ +#else /* BASOP_NOGLOB */ + tmp = shl( tmp, 1 ); /* Q14 -> Q15 with saturation */ #endif - tmp = s_max(tmp, 0); + tmp = s_max( tmp, 0 ); - return tmp; + return tmp; } /*========================================================================*/ @@ -2247,11 +2235,11 @@ Word16 lsf_stab_fx( /* o : LP filter stability Q15*/ /* RETURN ARGUMENTS : */ /* _ (Word16) stab_fac_fx : LP filter stability Q15 */ /*========================================================================*/ -Word16 lsf_stab_ivas_fx( /* o : LP filter stability Q15*/ - const Word16 *lsf, /* i : LSF vector Q(x2.56)*/ - const Word16 *lsfold, /* i : old LSF vector Q(x2.56)*/ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame /* i : frame length */ +Word16 lsf_stab_ivas_fx( /* o : LP filter stability Q15*/ + const Word16 *lsf, /* i : LSF vector Q(x2.56)*/ + const Word16 *lsfold, /* i : old LSF vector Q(x2.56)*/ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const Word16 L_frame /* i : frame length */ ) { Word16 i, m; @@ -2264,20 +2252,20 @@ Word16 lsf_stab_ivas_fx( /* o : LP filter stability Q15*/ /*-------------------------------------------------------------------* * Check stability on lsf: distance between old lsf and current lsf *-------------------------------------------------------------------*/ - IF(Opt_AMR_WB) + IF( Opt_AMR_WB ) { m = M - 1; move16(); - //tmp = sub(lsf[0], lsfold[0]); - tmp = extract_l(L_sub(lsf[0], (UWord16)lsfold[0])); - //L_tmp = L_mult(tmp, tmp); /* Q1 */ - L_tmp = L_mult0(shr(tmp, 1), tmp); /* Q-1 */ - FOR(i = 1; i < m; i++) + // tmp = sub(lsf[0], lsfold[0]); + tmp = extract_l( L_sub( lsf[0], (UWord16) lsfold[0] ) ); + // L_tmp = L_mult(tmp, tmp); /* Q1 */ + L_tmp = L_mult0( shr( tmp, 1 ), tmp ); /* Q-1 */ + FOR( i = 1; i < m; i++ ) { - //tmp = sub(lsf[i], lsfold[i]); - tmp = extract_l(L_sub(lsf[i], (UWord16)lsfold[i])); - //L_tmp = L_mac(L_tmp, tmp, tmp); /* Q1 */ - L_tmp = L_mac0(L_tmp, shr(tmp, 1), tmp); /* Q-1 */ + // tmp = sub(lsf[i], lsfold[i]); + tmp = extract_l( L_sub( lsf[i], (UWord16) lsfold[i] ) ); + // L_tmp = L_mac(L_tmp, tmp, tmp); /* Q1 */ + L_tmp = L_mac0( L_tmp, shr( tmp, 1 ), tmp ); /* Q-1 */ } } ELSE @@ -2286,155 +2274,155 @@ Word16 lsf_stab_ivas_fx( /* o : LP filter stability Q15*/ move16(); L_tmp = 0; move32(); - FOR(i = 0; i < m; i++) + FOR( i = 0; i < m; i++ ) { - //tmp = sub(lsf[i], lsfold[i]); - tmp = extract_l(L_sub(lsf[i], (UWord16)lsfold[i])); - //L_tmp = L_mac(L_tmp, tmp, tmp); /* Q1 */ - L_tmp = L_mac0(L_tmp, shr(tmp, 1), tmp); /* Q-1 */ + // tmp = sub(lsf[i], lsfold[i]); + tmp = extract_l( L_sub( lsf[i], (UWord16) lsfold[i] ) ); + // L_tmp = L_mac(L_tmp, tmp, tmp); /* Q1 */ + L_tmp = L_mac0( L_tmp, shr( tmp, 1 ), tmp ); /* Q-1 */ } } - e = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, e); /*Q(0+e)*/ + e = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, e ); /*Q(0+e)*/ - IF(L_frame == L_FRAME16k) + IF( L_frame == L_FRAME16k ) { /*stab_fac = (float)(1.25f - (tmp/625000.0f));*/ - L_tmp = Mpy_32_16_1(L_tmp, 16777); /* 30-eQ(-1+e)*-21Q36 = 30-21-eQ31-9+e */ + L_tmp = Mpy_32_16_1( L_tmp, 16777 ); /* 30-eQ(-1+e)*-21Q36 = 30-21-eQ31-9+e */ } ELSE { /* stab_fac = (float)(1.25f - (tmp1/400000.0f*2.56=1024000)) */ - L_tmp = Mpy_32_16_1(L_tmp, 26214); /* 30-eQ(-1+e)*-21Q36 = 30-21-eQ31-9+e */ + L_tmp = Mpy_32_16_1( L_tmp, 26214 ); /* 30-eQ(-1+e)*-21Q36 = 30-21-eQ31-9+e */ } - e = sub(30 - 21 - 1, e); + e = sub( 30 - 21 - 1, e ); #ifdef BASOP_NOGLOB - tmp = round_fx_o(L_shl_o(L_tmp, e, &Overflow), &Overflow); /*Q12*/ -#else /* BASOP_NOGLOB */ - tmp = round_fx(L_shl(L_tmp, e)); /*Q14*/ -#endif /* BASOP_NOGLOB */ + tmp = round_fx_o( L_shl_o( L_tmp, e, &Overflow ), &Overflow ); /*Q12*/ +#else /* BASOP_NOGLOB */ + tmp = round_fx( L_shl( L_tmp, e ) ); /*Q14*/ +#endif /* BASOP_NOGLOB */ - //tmp = sub(20480, tmp); /* 1.25 - tmp in Q14 */ - tmp = sub(5120, tmp); /* 1.25 - tmp in Q12 */ + // tmp = sub(20480, tmp); /* 1.25 - tmp in Q14 */ + tmp = sub( 5120, tmp ); /* 1.25 - tmp in Q12 */ #ifdef BASOP_NOGLOB - //tmp = shl_o(tmcp, 1, &Overflow); /* Q14 -> Q15 with saturation */ - tmp = shl_sat(tmp, 3); /* Q12 -> Q15 with saturation */ -#else /* BASOP_NOGLOB */ - tmp = shl(tmp, 1); /* Q14 -> Q15 with saturation */ + // tmp = shl_o(tmcp, 1, &Overflow); /* Q14 -> Q15 with saturation */ + tmp = shl_sat( tmp, 3 ); /* Q12 -> Q15 with saturation */ +#else /* BASOP_NOGLOB */ + tmp = shl( tmp, 1 ); /* Q14 -> Q15 with saturation */ #endif - tmp = s_max(tmp, 0); + tmp = s_max( tmp, 0 ); return tmp; } /*-------------------------------------------------------------------* - * lsp2isp() - * - * Convert LSPs to ISPs via predictor coefficients A[] - *-------------------------------------------------------------------*/ + * lsp2isp() + * + * Convert LSPs to ISPs via predictor coefficients A[] + *-------------------------------------------------------------------*/ void lsp2isp_fx( - const Word16 *lsp, /* i : LSP vector */ - Word16 *isp, /* o : ISP filter coefficients */ - Word16 *stable_isp, /* i/o: ISP filter coefficients */ - const Word16 m /* i : order of LP analysis */ + const Word16 *lsp, /* i : LSP vector */ + Word16 *isp, /* o : ISP filter coefficients */ + Word16 *stable_isp, /* i/o: ISP filter coefficients */ + const Word16 m /* i : order of LP analysis */ ) { - Word16 a[M + 1]; + Word16 a[M + 1]; - /* LSP --> A */ - /*lsp2a_stab( lsp, a, m );*/ - E_LPC_f_lsp_a_conversion(lsp, a, m); + /* LSP --> A */ + /*lsp2a_stab( lsp, a, m );*/ + E_LPC_f_lsp_a_conversion( lsp, a, m ); - /* A --> ISP */ - /*a2isp( a, isp, stable_isp, grid );*/ - E_LPC_a_isp_conversion(a, isp, stable_isp, m); + /* A --> ISP */ + /*a2isp( a, isp, stable_isp, grid );*/ + E_LPC_a_isp_conversion( a, isp, stable_isp, m ); - /* Update to latest stable ISP */ - Copy(isp, stable_isp, M); + /* Update to latest stable ISP */ + Copy( isp, stable_isp, M ); } /*-------------------------------------------------------------------* - * isp2lsp() - * - * Convert ISPs to LSPs via predictor coefficients A[] - *-------------------------------------------------------------------*/ + * isp2lsp() + * + * Convert ISPs to LSPs via predictor coefficients A[] + *-------------------------------------------------------------------*/ void isp2lsp_fx( - const Word16 *isp, /* i : LSP vector */ - Word16 *lsp, /* o : ISP filter coefficients */ - Word16 *stable_lsp, /* i/o: stable LSP filter coefficients */ - const Word16 m /* i : order of LP analysis */ + const Word16 *isp, /* i : LSP vector */ + Word16 *lsp, /* o : ISP filter coefficients */ + Word16 *stable_lsp, /* i/o: stable LSP filter coefficients */ + const Word16 m /* i : order of LP analysis */ ) { - Word16 a[M + 1]; - - /* ISP --> A */ - /*isp2a( isp, a, m );*/ - E_LPC_f_isp_a_conversion(isp, a, m); - /* A --> LSP */ - /*a2lsp_stab( a, lsp, stable_lsp, grid );*/ - E_LPC_a_lsp_conversion(a, lsp, stable_lsp, m); - /* Update to latest stable LSP */ - Copy(lsp, stable_lsp, M); + Word16 a[M + 1]; + + /* ISP --> A */ + /*isp2a( isp, a, m );*/ + E_LPC_f_isp_a_conversion( isp, a, m ); + /* A --> LSP */ + /*a2lsp_stab( a, lsp, stable_lsp, grid );*/ + E_LPC_a_lsp_conversion( a, lsp, stable_lsp, m ); + /* Update to latest stable LSP */ + Copy( lsp, stable_lsp, M ); } /*-------------------------------------------------------------------* - * lsf2isf() - * - * Convert LSPs to ISPs - *-------------------------------------------------------------------*/ + * lsf2isf() + * + * Convert LSPs to ISPs + *-------------------------------------------------------------------*/ void lsf2isf_fx( - const Word16 *lsf, /* i : LSF vector */ - Word16 *isf, /* o : ISF vector */ - Word16 *stable_isp, /* i/o: stable ISP filter coefficients */ - const Word16 m /* i : order of LP analysis */ + const Word16 *lsf, /* i : LSF vector */ + Word16 *isf, /* o : ISF vector */ + Word16 *stable_isp, /* i/o: stable ISP filter coefficients */ + const Word16 m /* i : order of LP analysis */ ) { - Word16 tmp_lsp[M]; - Word16 tmp_isp[M]; + Word16 tmp_lsp[M]; + Word16 tmp_isp[M]; - /* LSF --> LSP */ - /*lsf2lsp( lsf, tmp_lsp, m, int_fs );*/ - E_LPC_lsf_lsp_conversion(lsf, tmp_lsp, m); + /* LSF --> LSP */ + /*lsf2lsp( lsf, tmp_lsp, m, int_fs );*/ + E_LPC_lsf_lsp_conversion( lsf, tmp_lsp, m ); - /* LSP --> ISP */ - lsp2isp_fx(tmp_lsp, tmp_isp, stable_isp, m); + /* LSP --> ISP */ + lsp2isp_fx( tmp_lsp, tmp_isp, stable_isp, m ); - /* ISP --> ISF */ - /*isp2isf( tmp_isp, isf, m, int_fs );*/ - E_LPC_isp_isf_conversion(tmp_isp, isf, m); + /* ISP --> ISF */ + /*isp2isf( tmp_isp, isf, m, int_fs );*/ + E_LPC_isp_isf_conversion( tmp_isp, isf, m ); - return; + return; } /*-------------------------------------------------------------------* - * isf2lsf() - * - * Convert ISFs to LSFs - *-------------------------------------------------------------------*/ + * isf2lsf() + * + * Convert ISFs to LSFs + *-------------------------------------------------------------------*/ void isf2lsf_fx( - const Word16 *isf, /* i : ISF vector */ - Word16 *lsf, /* o : LSF vector */ - Word16 *stable_lsp /* i/o: stable LSP filter coefficients */ + const Word16 *isf, /* i : ISF vector */ + Word16 *lsf, /* o : LSF vector */ + Word16 *stable_lsp /* i/o: stable LSP filter coefficients */ ) { - Word16 tmp_isp[M]; - Word16 tmp_lsp[M]; - - /* ISF --> ISP */ - /*isf2isp( isf, tmp_isp, m, int_fs );*/ - E_LPC_isf_isp_conversion(isf, tmp_isp, M); - /* ISP --> LSP */ - isp2lsp_fx(tmp_isp, tmp_lsp, stable_lsp, M); - - /* LSP --> LSF */ - /*lsp2lsf( tmp_lsp, lsf, m, int_fs );*/ - E_LPC_lsp_lsf_conversion(tmp_lsp, lsf, M); - return; + Word16 tmp_isp[M]; + Word16 tmp_lsp[M]; + + /* ISF --> ISP */ + /*isf2isp( isf, tmp_isp, m, int_fs );*/ + E_LPC_isf_isp_conversion( isf, tmp_isp, M ); + /* ISP --> LSP */ + isp2lsp_fx( tmp_isp, tmp_lsp, stable_lsp, M ); + + /* LSP --> LSF */ + /*lsp2lsf( tmp_lsp, lsf, m, int_fs );*/ + E_LPC_lsp_lsf_conversion( tmp_lsp, lsf, M ); + return; } /*==========================================================================*/ /* FUNCTION : void lsp2lsf_fx () */ @@ -2459,30 +2447,30 @@ void isf2lsf_fx( /* CALLED FROM : */ /*==========================================================================*/ void lsp2lsf_fx( - const Word16 lsp[], /* i : lsp[m] (range: -1<=val<1) Q15*/ - Word16 lsf[], /* o : lsf[m] normalized (range: 0.0<=val<=0.5) Q(x2.56)*/ - const Word16 m, /* i : LPC order Q0*/ - const Word32 int_fs /* i : internal sampling frequency */ + const Word16 lsp[], /* i : lsp[m] (range: -1<=val<1) Q15*/ + Word16 lsf[], /* o : lsf[m] normalized (range: 0.0<=val<=0.5) Q(x2.56)*/ + const Word16 m, /* i : LPC order Q0*/ + const Word32 int_fs /* i : internal sampling frequency */ ) { - Word16 i; - Word32 L_tmp; - - FOR(i = 0; i < m; i++) - { - /*------------------------------------------------------* - * find value in table that is just greater than lsp[i] - *------------------------------------------------------*/ - - /* Retrieve Index Guess */ - /* Based on lsp[i] */ - L_tmp = sub_lsp2lsf_fx(lsp[i]); - IF(EQ_32(int_fs, INT_FS_16k_FX)) - { - L_tmp = L_shr(L_mult0(extract_l(L_tmp), 5), 2); - } - lsf[i] = extract_l(L_tmp); - } + Word16 i; + Word32 L_tmp; + + FOR( i = 0; i < m; i++ ) + { + /*------------------------------------------------------* + * find value in table that is just greater than lsp[i] + *------------------------------------------------------*/ + + /* Retrieve Index Guess */ + /* Based on lsp[i] */ + L_tmp = sub_lsp2lsf_fx( lsp[i] ); + IF( EQ_32( int_fs, INT_FS_16k_FX ) ) + { + L_tmp = L_shr( L_mult0( extract_l( L_tmp ), 5 ), 2 ); + } + lsf[i] = extract_l( L_tmp ); + } } /*===========================================================================*/ /* FUNCTION : lsf2lsp_fx() */ @@ -2499,286 +2487,284 @@ void lsp2lsf_fx( /* _ (Word16*) lsp : lsp[m] (range: -1<=val<1) Q15 */ /*---------------------------------------------------------------------------*/ -/*---------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*===========================================================================*/ -void lsf2lsp_fx( - const Word16 lsf[], /* i : lsf[m] normalized (range: 0.0<=val<=0.5) x2.56 */ - Word16 lsp[], /* o : lsp[m] (range: -1<=val<1) Q15 */ - const Word16 m, /* i : LPC order Q0 */ - const Word32 int_fs /* i : internal sampling frequency */ -) -{ - Word16 i, ind, offset; - Word32 L_tmp; - Word16 c, ind2; - Word16 const add_prec = 4; - Word16 lsf_tmp; - - - /* 0.75 = (1<hLPDmem; - - *clip_var = st_fx->clip_var_fx[0]; - move16(); - - FOR(i = 0; i < M; i++) - { - mem_AR[i] = st_fx->mem_AR_fx[i]; - move16(); - mem_MA[i] = st_fx->mem_MA_fx[i]; - move16(); - lsp_new_bck[i] = lsp_new[i]; - move16(); - lsf_new_bck[i] = lsf_new[i]; - move16(); - lsp_mid_bck[i] = lsp_mid[i]; - move16(); - } - - *mCb1 = st_fx->mCb1_fx; - move16(); - *streaklimit = st_fx->streaklimit_fx; - move16(); - *pstreaklen = st_fx->pstreaklen_fx; - move16(); - - FOR(i = 0; i < L_FFT; i++) - { - Bin_E[i] = st_fx->Bin_E_fx[i]; - move32(); - } - - FOR(i = 0; i < (L_FFT / 2); i++) - { - Bin_E_old[i] = st_fx->Bin_E_old_fx[i]; - move32(); - } - - /* back-up memories */ - FOR(i = 0; i < M; i++) - { - mem_syn_bck[i] = hLPDmem->mem_syn[i]; - move16(); - } - - *mem_w0_bck = hLPDmem->mem_w0; - move16(); - - - *btilt_code_fx = hLPDmem->tilt_code; - *gc_threshold_fx = hLPDmem->gc_threshold; - Copy(st_fx->clip_var_fx, clip_var_bck_fx, 6); - *next_force_sf_bck_fx = st_fx->next_force_safety_net_fx; - - - return; + Word16 i; + LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; + + *clip_var = st_fx->clip_var_fx[0]; + move16(); + + FOR( i = 0; i < M; i++ ) + { + mem_AR[i] = st_fx->mem_AR_fx[i]; + move16(); + mem_MA[i] = st_fx->mem_MA_fx[i]; + move16(); + lsp_new_bck[i] = lsp_new[i]; + move16(); + lsf_new_bck[i] = lsf_new[i]; + move16(); + lsp_mid_bck[i] = lsp_mid[i]; + move16(); + } + + *mCb1 = st_fx->mCb1_fx; + move16(); + *streaklimit = st_fx->streaklimit_fx; + move16(); + *pstreaklen = st_fx->pstreaklen_fx; + move16(); + + FOR( i = 0; i < L_FFT; i++ ) + { + Bin_E[i] = st_fx->Bin_E_fx[i]; + move32(); + } + + FOR( i = 0; i < ( L_FFT / 2 ); i++ ) + { + Bin_E_old[i] = st_fx->Bin_E_old_fx[i]; + move32(); + } + + /* back-up memories */ + FOR( i = 0; i < M; i++ ) + { + mem_syn_bck[i] = hLPDmem->mem_syn[i]; + move16(); + } + + *mem_w0_bck = hLPDmem->mem_w0; + move16(); + + + *btilt_code_fx = hLPDmem->tilt_code; + *gc_threshold_fx = hLPDmem->gc_threshold; + Copy( st_fx->clip_var_fx, clip_var_bck_fx, 6 ); + *next_force_sf_bck_fx = st_fx->next_force_safety_net_fx; + + + return; } void lsf_update_memory( - Word16 narrowband, /* i : narrowband flag */ - const Word16 qlsf[], /* i : quantized lsf coefficients */ - Word16 old_mem_MA[], /* i : MA memory */ - Word16 mem_MA[], /* o : updated MA memory */ - Word16 lpcorder /* i : LPC order */ + Word16 narrowband, /* i : narrowband flag */ + const Word16 qlsf[], /* i : quantized lsf coefficients */ + Word16 old_mem_MA[], /* i : MA memory */ + Word16 mem_MA[], /* o : updated MA memory */ + Word16 lpcorder /* i : LPC order */ ) { - Word16 i; - - FOR(i = 0; i < lpcorder; ++i) - { - move16(); - mem_MA[i] = sub(sub(qlsf[i], lsf_means[narrowband][i]), mult_r(MU_MA_FX, old_mem_MA[i])); - } + Word16 i; + FOR( i = 0; i < lpcorder; ++i ) + { + move16(); + mem_MA[i] = sub( sub( qlsf[i], lsf_means[narrowband][i] ), mult_r( MU_MA_FX, old_mem_MA[i] ) ); + } } /*======================================================================*/ @@ -2955,107 +2939,107 @@ void lsf_update_memory( /* _ None */ /*=======================================================================*/ void lsf_syn_mem_restore_fx( - Encoder_State *st_fx, /* o: state structure */ - Word16 btilt_code_fx, /* i: */ - Word32 gc_threshold_fx, /* i: */ - Word16 *clip_var_bck_fx, /* i: */ - Word16 next_force_sf_bck_fx, /* i: */ - - Word16 *lsp_new, /* o: LSP vector to quantize */ - Word16 *lsf_new, /* o: quantized LSF vector */ - Word16 *lsp_mid, /* o: mid-frame LSP vector */ - Word16 clip_var, /* i: pitch clipping state var */ - Word16 *mem_AR, /* i: quantizer memory for AR model */ - Word16 *mem_MA, /* i: quantizer memory for MA model */ - Word16 *lsp_new_bck, /* i: LSP vector to quantize- backup */ - Word16 *lsf_new_bck, /* i: quantized LSF vector - backup */ - Word16 *lsp_mid_bck, /* i: mid-frame LSP vector - backup */ - Word16 mCb1, /* i: counter for stationary frame after a transition frame */ - Word32 *Bin_E, /* i: FFT Bin energy 128 *2 sets */ - Word32 *Bin_E_old, /* i: FFT Bin energy 128 sets */ - Word16 *mem_syn_bck, /* i: synthesis filter memory */ - Word16 mem_w0_bck, /* i: memory of the weighting filter */ - Word16 streaklimit, /* i:LSF quantizer */ - Word16 pstreaklen /* i:LSF quantizer */ + Encoder_State *st_fx, /* o: state structure */ + Word16 btilt_code_fx, /* i: */ + Word32 gc_threshold_fx, /* i: */ + Word16 *clip_var_bck_fx, /* i: */ + Word16 next_force_sf_bck_fx, /* i: */ + + Word16 *lsp_new, /* o: LSP vector to quantize */ + Word16 *lsf_new, /* o: quantized LSF vector */ + Word16 *lsp_mid, /* o: mid-frame LSP vector */ + Word16 clip_var, /* i: pitch clipping state var */ + Word16 *mem_AR, /* i: quantizer memory for AR model */ + Word16 *mem_MA, /* i: quantizer memory for MA model */ + Word16 *lsp_new_bck, /* i: LSP vector to quantize- backup */ + Word16 *lsf_new_bck, /* i: quantized LSF vector - backup */ + Word16 *lsp_mid_bck, /* i: mid-frame LSP vector - backup */ + Word16 mCb1, /* i: counter for stationary frame after a transition frame */ + Word32 *Bin_E, /* i: FFT Bin energy 128 *2 sets */ + Word32 *Bin_E_old, /* i: FFT Bin energy 128 sets */ + Word16 *mem_syn_bck, /* i: synthesis filter memory */ + Word16 mem_w0_bck, /* i: memory of the weighting filter */ + Word16 streaklimit, /* i:LSF quantizer */ + Word16 pstreaklen /* i:LSF quantizer */ ) { - Word16 i; - LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; - - /* restore lsf memories */ - st_fx->clip_var_fx[0] = clip_var; - move16(); - - FOR(i = 0; i < M; i++) - { - st_fx->mem_AR_fx[i] = mem_AR[i]; - move16(); - st_fx->mem_MA_fx[i] = mem_MA[i]; - move16(); - lsp_new[i] = lsp_new_bck[i]; - move16(); - lsf_new[i] = lsf_new_bck[i]; - move16(); - lsp_mid[i] = lsp_mid_bck[i]; - move16(); - } - - st_fx->mCb1_fx = mCb1; - move16(); - st_fx->streaklimit_fx = streaklimit; - move16(); - st_fx->pstreaklen_fx = pstreaklen; - move16(); - - FOR(i = 0; i < L_FFT; i++) - { - st_fx->Bin_E_fx[i] = Bin_E[i]; - move16(); - } - - FOR(i = 0; i < (L_FFT / 2); i++) - { - st_fx->Bin_E_old_fx[i] = Bin_E_old[i]; - move32(); - } - - /* restoring memories */ - hLPDmem->mem_w0 = mem_w0_bck; - move16(); - - FOR(i = 0; i < M; i++) - { - hLPDmem->mem_syn[i] = mem_syn_bck[i]; - move16(); - } - - move16(); - move32(); - move16(); - hLPDmem->tilt_code = btilt_code_fx; - hLPDmem->gc_threshold = gc_threshold_fx; - Copy(clip_var_bck_fx, st_fx->clip_var_fx, 6); - st_fx->next_force_safety_net_fx = next_force_sf_bck_fx; - - return; + Word16 i; + LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; + + /* restore lsf memories */ + st_fx->clip_var_fx[0] = clip_var; + move16(); + + FOR( i = 0; i < M; i++ ) + { + st_fx->mem_AR_fx[i] = mem_AR[i]; + move16(); + st_fx->mem_MA_fx[i] = mem_MA[i]; + move16(); + lsp_new[i] = lsp_new_bck[i]; + move16(); + lsf_new[i] = lsf_new_bck[i]; + move16(); + lsp_mid[i] = lsp_mid_bck[i]; + move16(); + } + + st_fx->mCb1_fx = mCb1; + move16(); + st_fx->streaklimit_fx = streaklimit; + move16(); + st_fx->pstreaklen_fx = pstreaklen; + move16(); + + FOR( i = 0; i < L_FFT; i++ ) + { + st_fx->Bin_E_fx[i] = Bin_E[i]; + move16(); + } + + FOR( i = 0; i < ( L_FFT / 2 ); i++ ) + { + st_fx->Bin_E_old_fx[i] = Bin_E_old[i]; + move32(); + } + + /* restoring memories */ + hLPDmem->mem_w0 = mem_w0_bck; + move16(); + + FOR( i = 0; i < M; i++ ) + { + hLPDmem->mem_syn[i] = mem_syn_bck[i]; + move16(); + } + + move16(); + move32(); + move16(); + hLPDmem->tilt_code = btilt_code_fx; + hLPDmem->gc_threshold = gc_threshold_fx; + Copy( clip_var_bck_fx, st_fx->clip_var_fx, 6 ); + st_fx->next_force_safety_net_fx = next_force_sf_bck_fx; + + return; } /* Returns: codebook index */ Word16 tcxlpc_get_cdk( - Word16 acelp_ext_mode /* (I) GC/VC indicator */ + Word16 acelp_ext_mode /* (I) GC/VC indicator */ ) { - Word16 cdk; + Word16 cdk; - move16(); - cdk = 0; - if (EQ_16(acelp_ext_mode, VOICED)) - { - cdk = 1; - move16(); - } + move16(); + cdk = 0; + if ( EQ_16( acelp_ext_mode, VOICED ) ) + { + cdk = 1; + move16(); + } - return cdk; + return cdk; } #ifdef IVAS_MSVQ @@ -3066,148 +3050,148 @@ Word16 tcxlpc_get_cdk( *--------------------------------------------------------------------------*/ void dec_FDCNG_MSVQ_stage1( - int16_t j_full, /* i : index full range */ - int16_t n, /* i : dimension to generate */ - const float* invTrfMatrix, /* i : IDCT matrix for synthesis */ - const DCTTYPE idcttype, /* i : specify which IDCT */ - float* uq, /* o : synthesized stage1 vector */ - Word16* uq_ind /* o : synthesized stage1 vector in BASOP */ + int16_t j_full, /* i : index full range */ + int16_t n, /* i : dimension to generate */ + const float *invTrfMatrix, /* i : IDCT matrix for synthesis */ + const DCTTYPE idcttype, /* i : specify which IDCT */ + float *uq, /* o : synthesized stage1 vector */ + Word16 *uq_ind /* o : synthesized stage1 vector in BASOP */ ) { - int16_t col, segm_ind, j; - float dct_vec[FDCNG_VQ_MAX_LEN]; - float idct_vec[FDCNG_VQ_MAX_LEN]; - const Word8* cbpW8; - const Word16* dct_col_shift_tab; - - assert(n <= FDCNG_VQ_MAX_LEN); - assert(n >= FDCNG_VQ_DCT_MINTRUNC); - - segm_ind = 0; - for (col = 1; col <= FDCNG_VQ_DCT_NSEGM; col++) - { - if (j_full >= cdk1_ivas_cum_entries_per_segment[col]) - { - segm_ind++; - } - } - - j = j_full - cdk1_ivas_cum_entries_per_segment[segm_ind]; /* j is the local segment index */ - - assert(j < cdk1_ivas_entries_per_segment[segm_ind]); - - /* Word8 column variable Qx storage*/ - cbpW8 = cdk_37bits_ivas_stage1_W8Qx_dct_sections[segm_ind]; /* Word8 storage fixed ptr_init */ - cbpW8 += j * cdk1_ivas_cols_per_segment[segm_ind]; /* adaptive ptr init */ - dct_col_shift_tab = stage1_dct_col_syn_shift[segm_ind]; - - for (col = 0; col < cdk1_ivas_cols_per_segment[segm_ind]; col++) - { - dct_vec[col] = (float)shl((Word16)cbpW8[col], dct_col_shift_tab[col]); - /* LOGIC( 1 ) , SHIFT( 1 ); - in BASOP: s_and(for W8->W16), shl() - */ - } - dctT2_N_apply_matrix((const float*)dct_vec, idct_vec, cdk1_ivas_cols_per_segment[segm_ind], n, invTrfMatrix, FDCNG_VQ_DCT_MAXTRUNC, idcttype); - - /*scale down to original fdcngvq domain and move to Q0 */ - v_multc(idct_vec, fdcng_dct_scaleF[1], idct_vec, n); - /* fdcng_dct_scaleF[1] --> 0.0625-->scale down from search Q4 domain to Q0 , - not really relevant for BASOP loop */ - - /*add common mid fdcng vector, in fdcng bands domain */ - v_add(idct_vec, cdk1r_tr_midQ_truncQ, uq, n); - assert(uq_ind == NULL); - - return; + int16_t col, segm_ind, j; + float dct_vec[FDCNG_VQ_MAX_LEN]; + float idct_vec[FDCNG_VQ_MAX_LEN]; + const Word8 *cbpW8; + const Word16 *dct_col_shift_tab; + + assert( n <= FDCNG_VQ_MAX_LEN ); + assert( n >= FDCNG_VQ_DCT_MINTRUNC ); + + segm_ind = 0; + for ( col = 1; col <= FDCNG_VQ_DCT_NSEGM; col++ ) + { + if ( j_full >= cdk1_ivas_cum_entries_per_segment[col] ) + { + segm_ind++; + } + } + + j = j_full - cdk1_ivas_cum_entries_per_segment[segm_ind]; /* j is the local segment index */ + + assert( j < cdk1_ivas_entries_per_segment[segm_ind] ); + + /* Word8 column variable Qx storage*/ + cbpW8 = cdk_37bits_ivas_stage1_W8Qx_dct_sections[segm_ind]; /* Word8 storage fixed ptr_init */ + cbpW8 += j * cdk1_ivas_cols_per_segment[segm_ind]; /* adaptive ptr init */ + dct_col_shift_tab = stage1_dct_col_syn_shift[segm_ind]; + + for ( col = 0; col < cdk1_ivas_cols_per_segment[segm_ind]; col++ ) + { + dct_vec[col] = (float) shl( (Word16) cbpW8[col], dct_col_shift_tab[col] ); + /* LOGIC( 1 ) , SHIFT( 1 ); + in BASOP: s_and(for W8->W16), shl() + */ + } + dctT2_N_apply_matrix( (const float *) dct_vec, idct_vec, cdk1_ivas_cols_per_segment[segm_ind], n, invTrfMatrix, FDCNG_VQ_DCT_MAXTRUNC, idcttype ); + + /*scale down to original fdcngvq domain and move to Q0 */ + v_multc( idct_vec, fdcng_dct_scaleF[1], idct_vec, n ); + /* fdcng_dct_scaleF[1] --> 0.0625-->scale down from search Q4 domain to Q0 , + not really relevant for BASOP loop */ + + /*add common mid fdcng vector, in fdcng bands domain */ + v_add( idct_vec, cdk1r_tr_midQ_truncQ, uq, n ); + assert( uq_ind == NULL ); + + return; } #endif -void msvq_dec -( - const Word16 *const*cb, /* i : Codebook (indexed cb[*stages][levels][p]) (14Q1*1.28)*/ - const Word16 dims[], /* i : Dimension of each codebook stage (NULL: full dim.) */ - const Word16 offs[], /* i : Starting dimension of each codebook stage (NULL: 0) */ - const Word16 stages, /* i : Number of stages */ - const Word16 N, /* i : Vector dimension */ - const Word16 maxN, /* i : Codebook dimension */ - const Word16 Idx[], /* i : Indices */ +void msvq_dec( + const Word16 *const *cb, /* i : Codebook (indexed cb[*stages][levels][p]) (14Q1*1.28)*/ + const Word16 dims[], /* i : Dimension of each codebook stage (NULL: full dim.) */ + const Word16 offs[], /* i : Starting dimension of each codebook stage (NULL: 0) */ + const Word16 stages, /* i : Number of stages */ + const Word16 N, /* i : Vector dimension */ + const Word16 maxN, /* i : Codebook dimension */ + const Word16 Idx[], /* i : Indices */ #ifdef IVAS_MSVQ - const int16_t applyIDCT_flag, /* i : applyIDCT flag */ - const float* invTrfMatrix, /* i : matrix for IDCT synthesis */ + const int16_t applyIDCT_flag, /* i : applyIDCT flag */ + const float *invTrfMatrix, /* i : matrix for IDCT synthesis */ #endif - Word16 *uq /* o : quantized vector (14Q1*1.28)*/ + Word16 *uq /* o : quantized vector (14Q1*1.28)*/ ) { - Word16 i, j, offset; - Word16 N34; - Word16 n, maxn, start; - - - - set16_fx(uq, 0, N); - - FOR(i = 0; i < stages; i++) - { - n = N; - move16(); - maxn = maxN; - move16(); - if (dims) - { - n = dims[i]; - move16(); - } - if (dims) - { - maxn = n; - move16(); - } - if(maxn % 4) - {n = n; } - assert((maxn % 4) == 0); - N34 = mult(maxn, 24576/*0.75 Q15*/); - - start = 0; - move16(); - if (offs) - { - start = offs[i]; - move16(); - } + Word16 i, j, offset; + Word16 N34; + Word16 n, maxn, start; + + + set16_fx( uq, 0, N ); + + FOR( i = 0; i < stages; i++ ) + { + n = N; + move16(); + maxn = maxN; + move16(); + if ( dims ) + { + n = dims[i]; + move16(); + } + if ( dims ) + { + maxn = n; + move16(); + } + if ( maxn % 4 ) + { + n = n; + } + assert( ( maxn % 4 ) == 0 ); + N34 = mult( maxn, 24576 /*0.75 Q15*/ ); + + start = 0; + move16(); + if ( offs ) + { + start = offs[i]; + move16(); + } #ifdef IVAS_MSVQ - test(); - IF(i == 0 && applyIDCT_flag != 0) - { - assert(start == 0); - dec_FDCNG_MSVQ_stage1(Idx[0], N, invTrfMatrix, IDCT_T2_XX_24, uq, uq_ind); /* IDCT_T2 N=24 used for all synthesis */ - } - ELSE + test(); + IF( i == 0 && applyIDCT_flag != 0 ) + { + assert( start == 0 ); + dec_FDCNG_MSVQ_stage1( Idx[0], N, invTrfMatrix, IDCT_T2_XX_24, uq, uq_ind ); /* IDCT_T2 N=24 used for all synthesis */ + } + ELSE #endif - { - /*vr_add( uq+start, cb[i]+Idx[i]*maxn, uq+start, n );, where uq = a zero vector*/ - offset = i_mult2(Idx[i], N34); - - FOR(j = 0; j < n; j += 4) - { - Word16 val0, val1, val2, val3; - - depack_4_values(cb[i] + offset + i_mult(3, (shr(j, 2))), val0, val1, val2, val3); - - uq[start + j + 0] = add(uq[start + j + 0], val0); - move16(); /*14Q1*1.28*/ - uq[start + j + 1] = add(uq[start + j + 1], val1); - move16(); /*14Q1*1.28*/ - uq[start + j + 2] = add(uq[start + j + 2], val2); - move16(); /*14Q1*1.28*/ - uq[start + j + 3] = add(uq[start + j + 3], val3); - move16(); /*14Q1*1.28*/ - } - } - } - - - return; + { + /*vr_add( uq+start, cb[i]+Idx[i]*maxn, uq+start, n );, where uq = a zero vector*/ + offset = i_mult2( Idx[i], N34 ); + + FOR( j = 0; j < n; j += 4 ) + { + Word16 val0, val1, val2, val3; + + depack_4_values( cb[i] + offset + i_mult( 3, ( shr( j, 2 ) ) ), val0, val1, val2, val3 ); + + uq[start + j + 0] = add( uq[start + j + 0], val0 ); + move16(); /*14Q1*1.28*/ + uq[start + j + 1] = add( uq[start + j + 1], val1 ); + move16(); /*14Q1*1.28*/ + uq[start + j + 2] = add( uq[start + j + 2], val2 ); + move16(); /*14Q1*1.28*/ + uq[start + j + 3] = add( uq[start + j + 3], val3 ); + move16(); /*14Q1*1.28*/ + } + } + } + + + return; } /* @@ -3227,22 +3211,21 @@ void msvq_dec * Returns: * energy of prediction error */ -void E_LPC_lsp_lsf_conversion(const Word16 lsp[], Word16 lsf[], const Word16 m) +void E_LPC_lsp_lsf_conversion( const Word16 lsp[], Word16 lsf[], const Word16 m ) { - Word16 i; - - assert(m == 16 || m == 10); + Word16 i; + assert( m == 16 || m == 10 ); - FOR(i = 0; i < m; i++) - { - lsf[i] = xsp_to_xsf(lsp[i]); - move16(); - } + FOR( i = 0; i < m; i++ ) + { + lsf[i] = xsp_to_xsf( lsp[i] ); + move16(); + } - return; + return; } /* @@ -3262,21 +3245,21 @@ void E_LPC_lsp_lsf_conversion(const Word16 lsp[], Word16 lsf[], const Word16 m) * Returns: * void */ -void E_LPC_lsf_lsp_conversion(const Word16 lsf[], Word16 lsp[], const Word16 m) +void E_LPC_lsf_lsp_conversion( const Word16 lsf[], Word16 lsp[], const Word16 m ) { - Word16 i; + Word16 i; - assert(m == 16 || m == 10); + assert( m == 16 || m == 10 ); - /* convert ISFs to the cosine domain */ - FOR(i = 0; i < m; i++) - { - *lsp++ = xsf_to_xsp(*lsf++); - move16(); - } + /* convert ISFs to the cosine domain */ + FOR( i = 0; i < m; i++ ) + { + *lsp++ = xsf_to_xsp( *lsf++ ); + move16(); + } - return; + return; } /*==========================================================================*/ @@ -3302,58 +3285,58 @@ void E_LPC_lsf_lsp_conversion(const Word16 lsf[], Word16 lsp[], const Word16 m) /* CALLED FROM : */ /*==========================================================================*/ Word32 sub_lsp2lsf_fx( - const Word16 lsp_i /* i : lsp[m] (range: -1<=val<1) Q15*/ + const Word16 lsp_i /* i : lsp[m] (range: -1<=val<1) Q15*/ ) { - Word16 ind, tmp; - Word32 L_tmp; - - /*------------------------------------------------------* - * find value in table that is just greater than lsp[i] - *------------------------------------------------------*/ - - /* Retrieve Index Guess */ - /* Based on lsp[i] */ - ind = mac_r(GUESS_TBL_SZ / 2 * 65536 - 0x8000, lsp_i, GUESS_TBL_SZ / 2); - ind = Ind_Guess[ind]; - move16(); - - /* Correct Index so that */ - /* table[ind] > lsp[i] */ - tmp = sub(lsp_i, cos_table_129[ind]); - /* - 69%: (Final Index - Index Guess) is <= 1 - 28%: (Final Index - Index Guess) is 2 - 2%: (Final Index - Index Guess) is >= 3 - <1%: ... - */ - IF(tmp > 0) /* possible range 0 to -5 (-1-2-2) */ - { - ind = sub(ind, 1); - tmp = sub(lsp_i, cos_table_129[ind]); - IF(tmp > 0) - { - ind = sub(ind, 2); - tmp = sub(lsp_i, cos_table_129[ind]); - if (tmp > 0) - { - ind = sub(ind, 2); - } - tmp = sub(lsp_i, cos_table_129[ind + 1]); - if (tmp <= 0) - { - ind = add(ind, 1); - } - tmp = sub(lsp_i, cos_table_129[ind]); - } - } - - /* acos(lsp[i])= ind*128 + (lsp[i]-table[ind]) * acos_slope[ind] / 2048 */ - L_tmp = L_mac(1L << 11, tmp, acos_slope[ind]); - L_tmp = L_shr(L_tmp, 12); /* (lsp[i]-table[ind]) * acos_slope[ind]) >> 11 */ - L_tmp = L_mac0(L_tmp, ind, 128); - - return L_tmp; + Word16 ind, tmp; + Word32 L_tmp; + + /*------------------------------------------------------* + * find value in table that is just greater than lsp[i] + *------------------------------------------------------*/ + + /* Retrieve Index Guess */ + /* Based on lsp[i] */ + ind = mac_r( GUESS_TBL_SZ / 2 * 65536 - 0x8000, lsp_i, GUESS_TBL_SZ / 2 ); + ind = Ind_Guess[ind]; + move16(); + + /* Correct Index so that */ + /* table[ind] > lsp[i] */ + tmp = sub( lsp_i, cos_table_129[ind] ); + /* + 69%: (Final Index - Index Guess) is <= 1 + 28%: (Final Index - Index Guess) is 2 + 2%: (Final Index - Index Guess) is >= 3 + <1%: ... + */ + IF( tmp > 0 ) /* possible range 0 to -5 (-1-2-2) */ + { + ind = sub( ind, 1 ); + tmp = sub( lsp_i, cos_table_129[ind] ); + IF( tmp > 0 ) + { + ind = sub( ind, 2 ); + tmp = sub( lsp_i, cos_table_129[ind] ); + if ( tmp > 0 ) + { + ind = sub( ind, 2 ); + } + tmp = sub( lsp_i, cos_table_129[ind + 1] ); + if ( tmp <= 0 ) + { + ind = add( ind, 1 ); + } + tmp = sub( lsp_i, cos_table_129[ind] ); + } + } + + /* acos(lsp[i])= ind*128 + (lsp[i]-table[ind]) * acos_slope[ind] / 2048 */ + L_tmp = L_mac( 1L << 11, tmp, acos_slope[ind] ); + L_tmp = L_shr( L_tmp, 12 ); /* (lsp[i]-table[ind]) * acos_slope[ind]) >> 11 */ + L_tmp = L_mac0( L_tmp, ind, 128 ); + + return L_tmp; } /*===================================================================*/ @@ -3381,55 +3364,54 @@ Word32 sub_lsp2lsf_fx( /* Q(z)=(1-z^-1)*PI(j=1to(order/2)) (1 - 2*z^-1*cos(2*pi*w(2j)) + z^-2) */ /*===================================================================*/ void compute_poly_product_fx( - Word16* coef, /* i : LSP coefficients, Q15 */ - Word32* p, /* o : output sequence, Q24 */ - Word16 order /* i : order */ + Word16 *coef, /* i : LSP coefficients, Q15 */ + Word32 *p, /* o : output sequence, Q24 */ + Word16 order /* i : order */ ) { - Word16 i, len; - Word32 lspcos[LPC_SHB_ORDER]; - Word32 p2[LPC_SHB_ORDER]; /* intermediate product, Q24*/ - Word32* p_in, *p_out, *p_temp; - - FOR(i = 0; i < order / 2; i++) - { - lspcos[i] = poscos_fx(coef[i * 2]); - move32(); /* lspcos =-cos(lsp) in Q30*/ - } - - /* Set up first polynomial for convolution (1 -2cos(w5) 1) */ - /* First element of output is 1, all in Q24 */ - p[0] = L_deposit_h(0x100); /* 1.0 in Q24 */ - p[2] = L_deposit_h(0x100); /* 1.0 in Q24 */ - p[1] = L_shr(lspcos[order / 2 - 1], 5); /* p2[1]=-2cos(w5), Q24 */ - p2[0] = L_deposit_h(0x100); /* 1.0 in Q24 */ - - len = 1; - move16(); - - len = 1; - p_in = p + 1; /* 2nd entry of input sequence */ - p_out = p2 + 1; /* 2nd entry of output sequence */ - FOR(i = 0; i < (order / 2 - 1); i++) - { - lsp_convolve_fx(L_shr(lspcos[i], 5), p_in, p_out, len); - - p_temp = p_in; - p_in = p_out; - p_out = p_temp; /* swap input/output buffer */ - len = add(len, 1); - } - - /* if((order/2 - 1)%2 != 0) */ - IF(s_and((order / 2 - 1), 1) != 0) - { - FOR(i = 1; i <= order / 2; i++) - { - p[i] = p_in[i - 1]; - move32(); - } - } + Word16 i, len; + Word32 lspcos[LPC_SHB_ORDER]; + Word32 p2[LPC_SHB_ORDER]; /* intermediate product, Q24*/ + Word32 *p_in, *p_out, *p_temp; + + FOR( i = 0; i < order / 2; i++ ) + { + lspcos[i] = poscos_fx( coef[i * 2] ); + move32(); /* lspcos =-cos(lsp) in Q30*/ + } + + /* Set up first polynomial for convolution (1 -2cos(w5) 1) */ + /* First element of output is 1, all in Q24 */ + p[0] = L_deposit_h( 0x100 ); /* 1.0 in Q24 */ + p[2] = L_deposit_h( 0x100 ); /* 1.0 in Q24 */ + p[1] = L_shr( lspcos[order / 2 - 1], 5 ); /* p2[1]=-2cos(w5), Q24 */ + p2[0] = L_deposit_h( 0x100 ); /* 1.0 in Q24 */ + + len = 1; + move16(); + + len = 1; + p_in = p + 1; /* 2nd entry of input sequence */ + p_out = p2 + 1; /* 2nd entry of output sequence */ + FOR( i = 0; i < ( order / 2 - 1 ); i++ ) + { + lsp_convolve_fx( L_shr( lspcos[i], 5 ), p_in, p_out, len ); + + p_temp = p_in; + p_in = p_out; + p_out = p_temp; /* swap input/output buffer */ + len = add( len, 1 ); + } + /* if((order/2 - 1)%2 != 0) */ + IF( s_and( ( order / 2 - 1 ), 1 ) != 0 ) + { + FOR( i = 1; i <= order / 2; i++ ) + { + p[i] = p_in[i - 1]; + move32(); + } + } } /*===================================================================*/ @@ -3463,48 +3445,46 @@ void compute_poly_product_fx( /* Final output sequence is ( 1 X1 X2 X3 X4 X5 X4) */ /*===================================================================*/ void lsp_convolve_fx( - Word32 x, - Word32* p1, - Word32* p2, - Word16 len -) + Word32 x, + Word32 *p1, + Word32 *p2, + Word16 len ) { - Word16 i, d1h, d1l, d2h, d2l; - Word32 Ltemp; - Word32 Lacc; - - d1h = extract_h(x); /* d1h in Q8 */ - d1l = extract_l(x); /* d1l in Q24 */ - - Ltemp = L_add(x, p1[0]); /* first output is p1[0]+x, Q24 */ - - p2[0] = Ltemp; - move32(); - Ltemp = L_deposit_h(0x100); /* Ltemp=1.0, Q24 */ - FOR(i = 0; i < len; i++) - { - Ltemp = L_add(Ltemp, p1[i + 1]); /* Ltemp2=p1[i-1]+p1[i+1], Q24 */ - d2h = extract_h(p1[i]); - d2l = extract_l(p1[i]); - - /* Lacc=L_mult_su( d1h,d2l); */ - Lacc = L_mult0(d1h, (UWord16)d2l); - Lacc = L_mac0(Lacc, d2h, d1l); - Lacc = L_add(L_shr(Lacc, 16), L_shr(L_mult(d1h, d2h), 1)); - /* Lacc=p1[i]* x, Q16 */ - Lacc = L_add(L_shl(Lacc, 8), Ltemp); /* Lacc=p1[i-1]+p1[i+1]+p1[i]*x, Q24 */ - - p2[i + 1] = Lacc; - move32(); - - Ltemp = p1[i]; - move32(); - } /* end for */ - - p2[i + 1] = p2[i - 1]; - move32(); -} + Word16 i, d1h, d1l, d2h, d2l; + Word32 Ltemp; + Word32 Lacc; + + d1h = extract_h( x ); /* d1h in Q8 */ + d1l = extract_l( x ); /* d1l in Q24 */ + + Ltemp = L_add( x, p1[0] ); /* first output is p1[0]+x, Q24 */ + + p2[0] = Ltemp; + move32(); + Ltemp = L_deposit_h( 0x100 ); /* Ltemp=1.0, Q24 */ + FOR( i = 0; i < len; i++ ) + { + Ltemp = L_add( Ltemp, p1[i + 1] ); /* Ltemp2=p1[i-1]+p1[i+1], Q24 */ + d2h = extract_h( p1[i] ); + d2l = extract_l( p1[i] ); + + /* Lacc=L_mult_su( d1h,d2l); */ + Lacc = L_mult0( d1h, (UWord16) d2l ); + Lacc = L_mac0( Lacc, d2h, d1l ); + Lacc = L_add( L_shr( Lacc, 16 ), L_shr( L_mult( d1h, d2h ), 1 ) ); + /* Lacc=p1[i]* x, Q16 */ + Lacc = L_add( L_shl( Lacc, 8 ), Ltemp ); /* Lacc=p1[i-1]+p1[i+1]+p1[i]*x, Q24 */ + + p2[i + 1] = Lacc; + move32(); + + Ltemp = p1[i]; + move32(); + } /* end for */ + p2[i + 1] = p2[i - 1]; + move32(); +} /*===================================================================*/ @@ -3532,41 +3512,41 @@ void lsp_convolve_fx( /*===================================================================*/ -Word32 poscos_fx(Word16 w) +Word32 poscos_fx( Word16 w ) { - Word16 a, z, z2, z3, z5, z7, z9; - Word32 Ltemp; - Word32 Lacc; - - IF(w == 0) - { - return (0xc0000004); /* -1.0 in Q30 */ - } - ELSE - { - z = 0x2000; - move16(); /* z=0.5 in Q14 */ - z = shl(sub(z, w), 2); /* z = 0.5-w in Q16 */ - - a = 0x6488; - move16(); /* a=pi in Q13 */ - z = mult_r(z, a); /* z=pi*( 0.5-w), Q14 */ - z2 = mult_r(z, z); /* z2=z^2, Q13 */ - z3 = round_fx(L_shl(L_mult0(z, z2), 0)); /* z3=z^3, Q11 */ - z5 = mult_r(z2, z3); /* z5=z^5, Q9 */ - z7 = round_fx(L_shl(L_mult0(z2, z5), 0)); /* z7=z^7, Q6 */ - z9 = round_fx(L_shl(L_mult0(z2, z7), 0)); /* z9=z^9, Q3 */ - - Lacc = L_mult(z9, cos_coef_new[0]); /* Lacc=c4*z^9, Q31, c4 in Q28 */ - Lacc = L_mac0(Lacc, z7, cos_coef_new[1]); /* c3 in Q25 */ - Ltemp = L_shl(L_mult(z3, cos_coef_new[3]), 1); /* Ltemp=c1*z^3, Q31, c1 in Q17 */ - Lacc = L_add(L_shr(Lacc, 1), Ltemp); /* Lacc=c1*z^3+c3*z^7+c4*^z9, Q30 */ - Lacc = L_add(Lacc, L_deposit_h(z)); - Ltemp = L_mult(z5, cos_coef_new[2]); /* Ltemp=-c2*z^5, Q29, cos_coef[2]=-c2 in Q19 */ - Lacc = L_sub(Lacc, L_shl(Ltemp, 1)); /* Lacc=cos( w) in Q30 */ - - return L_negate(Lacc); /* return -cos( w), Q30 */ - } /* end else */ + Word16 a, z, z2, z3, z5, z7, z9; + Word32 Ltemp; + Word32 Lacc; + + IF( w == 0 ) + { + return ( 0xc0000004 ); /* -1.0 in Q30 */ + } + ELSE + { + z = 0x2000; + move16(); /* z=0.5 in Q14 */ + z = shl( sub( z, w ), 2 ); /* z = 0.5-w in Q16 */ + + a = 0x6488; + move16(); /* a=pi in Q13 */ + z = mult_r( z, a ); /* z=pi*( 0.5-w), Q14 */ + z2 = mult_r( z, z ); /* z2=z^2, Q13 */ + z3 = round_fx( L_shl( L_mult0( z, z2 ), 0 ) ); /* z3=z^3, Q11 */ + z5 = mult_r( z2, z3 ); /* z5=z^5, Q9 */ + z7 = round_fx( L_shl( L_mult0( z2, z5 ), 0 ) ); /* z7=z^7, Q6 */ + z9 = round_fx( L_shl( L_mult0( z2, z7 ), 0 ) ); /* z9=z^9, Q3 */ + + Lacc = L_mult( z9, cos_coef_new[0] ); /* Lacc=c4*z^9, Q31, c4 in Q28 */ + Lacc = L_mac0( Lacc, z7, cos_coef_new[1] ); /* c3 in Q25 */ + Ltemp = L_shl( L_mult( z3, cos_coef_new[3] ), 1 ); /* Ltemp=c1*z^3, Q31, c1 in Q17 */ + Lacc = L_add( L_shr( Lacc, 1 ), Ltemp ); /* Lacc=c1*z^3+c3*z^7+c4*^z9, Q30 */ + Lacc = L_add( Lacc, L_deposit_h( z ) ); + Ltemp = L_mult( z5, cos_coef_new[2] ); /* Ltemp=-c2*z^5, Q29, cos_coef[2]=-c2 in Q19 */ + Lacc = L_sub( Lacc, L_shl( Ltemp, 1 ) ); /* Lacc=cos( w) in Q30 */ + + return L_negate( Lacc ); /* return -cos( w), Q30 */ + } /* end else */ } /*===================================================================*/ /* FUNCTION : root_search_fx ( ) */ @@ -3590,109 +3570,108 @@ Word32 poscos_fx(Word16 w) /* _ ( Word16) root in Q15, or 0xffff if no root is found */ /*===================================================================*/ -Word16 root_search_fx(Word16 low, - Word16 high, - Word32* v_low, - Word32* coef, - Word16 order -) +Word16 root_search_fx( Word16 low, + Word16 high, + Word32 *v_low, + Word32 *coef, + Word16 order ) { - Word16 f; - Word32 v_high, vh; - Word32 Ltemp, L_tmp1, L_tmp, Ltmp; - Word16 exp1, tmp; + Word16 f; + Word32 v_high, vh; + Word32 Ltemp, L_tmp1, L_tmp, Ltmp; + Word16 exp1, tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; + Flag Overflow = 0; #endif - v_high = polynomial_eval_fx(high, coef, order); /* v_high has the value at high index */ - - IF(v_high != 0) - { - /* No exact root found */ - test(); - IF((v_high ^ (*v_low)) >= 0) - { - /* No root in this interval ( low high] */ - *v_low = v_high; - move32(); - return (-1); - } - ELSE - { - /* there is a root in this interval */ - /* Do binary search for root */ - vh = v_high; - move16(); - - WHILE(GE_16(sub(high, low), 2)) - { - /* high-low>=2 */ - f = shr(add(high, low), 1); /* f=( high+low)/2 */ - Ltemp = polynomial_eval_fx(f, coef, order); - IF(Ltemp == 0) - { - *v_low = v_high; - move32();/* Set low value for next root search call */ - return (shl(f, 6)); - } - ELSE - { - test(); - IF((Ltemp ^ (*v_low)) < 0) - { - /* root between f & low */ - high = f; - move16(); - vh = Ltemp; - move32(); - } - ELSE - { - *v_low = Ltemp; - move32(); - low = f; - move16(); - } - } - } /* end while */ - - /* do interpolation for root in between high and low */ - /* Lacc=divide_dp( *v_low, L_sub( *v_low,vh),2,1); // Lacc in Q31 */ - L_tmp = L_sub(*v_low, vh); - - if (LT_32(*v_low, vh)) - { - L_tmp = L_negate(L_tmp); - } - - exp1 = norm_l(L_tmp); - L_tmp1 = L_shl(L_tmp, exp1); - tmp = extract_h(L_tmp1); - exp1 = sub(30 - 25, exp1); - tmp = div_s(16384, tmp); /* 15+exp1 */ - Ltmp = Mult_32_16(*v_low, tmp); /* 15+exp1+25-15 */ + v_high = polynomial_eval_fx( high, coef, order ); /* v_high has the value at high index */ + + IF( v_high != 0 ) + { + /* No exact root found */ + test(); + IF( ( v_high ^ ( *v_low ) ) >= 0 ) + { + /* No root in this interval ( low high] */ + *v_low = v_high; + move32(); + return ( -1 ); + } + ELSE + { + /* there is a root in this interval */ + /* Do binary search for root */ + vh = v_high; + move16(); + + WHILE( GE_16( sub( high, low ), 2 ) ) + { + /* high-low>=2 */ + f = shr( add( high, low ), 1 ); /* f=( high+low)/2 */ + Ltemp = polynomial_eval_fx( f, coef, order ); + IF( Ltemp == 0 ) + { + *v_low = v_high; + move32(); /* Set low value for next root search call */ + return ( shl( f, 6 ) ); + } + ELSE + { + test(); + IF( ( Ltemp ^ ( *v_low ) ) < 0 ) + { + /* root between f & low */ + high = f; + move16(); + vh = Ltemp; + move32(); + } + ELSE + { + *v_low = Ltemp; + move32(); + low = f; + move16(); + } + } + } /* end while */ + + /* do interpolation for root in between high and low */ + /* Lacc=divide_dp( *v_low, L_sub( *v_low,vh),2,1); // Lacc in Q31 */ + L_tmp = L_sub( *v_low, vh ); + + if ( LT_32( *v_low, vh ) ) + { + L_tmp = L_negate( L_tmp ); + } + + exp1 = norm_l( L_tmp ); + L_tmp1 = L_shl( L_tmp, exp1 ); + tmp = extract_h( L_tmp1 ); + exp1 = sub( 30 - 25, exp1 ); + tmp = div_s( 16384, tmp ); /* 15+exp1 */ + Ltmp = Mult_32_16( *v_low, tmp ); /* 15+exp1+25-15 */ #ifdef BASOP_NOGLOB - Ltemp = L_shl_o(Ltmp, (6 - exp1), &Overflow); /* Q31 */ + Ltemp = L_shl_o( Ltmp, ( 6 - exp1 ), &Overflow ); /* Q31 */ #else - Ltemp = L_shl(Ltmp, (6 - exp1)); /* Q31 */ + Ltemp = L_shl( Ltmp, ( 6 - exp1 ) ); /* Q31 */ #endif - if (LT_32(*v_low, vh)) - { - Ltemp = L_negate(Ltemp); - } - Ltemp = L_shr(Ltemp, 9); /* Ltemp =quotient*1.0 in Q31 */ - - *v_low = v_high; - move16(); - return (add(round_fx(Ltemp), shl(low, 6))); - } /* end else ( root in interval) */ - } /* end else ( exact root at high) */ - - /* find the exact root */ - *v_low = v_high; - move32(); /* Set low value for next root search call */ - return (shl(high, 6)); /* return exact root at high in Q15 */ + if ( LT_32( *v_low, vh ) ) + { + Ltemp = L_negate( Ltemp ); + } + Ltemp = L_shr( Ltemp, 9 ); /* Ltemp =quotient*1.0 in Q31 */ + + *v_low = v_high; + move16(); + return ( add( round_fx( Ltemp ), shl( low, 6 ) ) ); + } /* end else ( root in interval) */ + } /* end else ( exact root at high) */ + + /* find the exact root */ + *v_low = v_high; + move32(); /* Set low value for next root search call */ + return ( shl( high, 6 ) ); /* return exact root at high in Q15 */ } /*===================================================================*/ @@ -3717,28 +3696,27 @@ and delta2 */ /*===================================================================*/ Word32 calc_weight( - Word16 delta1, - Word16 delta2, - Word16* n1 -) + Word16 delta1, + Word16 delta2, + Word16 *n1 ) { - Word16 n; - Word32 L_tmp; - Word16 alpha = 0x4F94; - move16(); /* ( 0.5*250/( 2*pi)) in Q10*/ + Word16 n; + Word32 L_tmp; + Word16 alpha = 0x4F94; + move16(); /* ( 0.5*250/( 2*pi)) in Q10*/ - L_tmp = L_mult0(delta1, delta2); /* Q30 */ - n = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, n); - n = sub(1, n); - L_tmp = Isqrt_lc(L_tmp, &n); /* Q( 31-n)*/ + L_tmp = L_mult0( delta1, delta2 ); /* Q30 */ + n = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, n ); + n = sub( 1, n ); + L_tmp = Isqrt_lc( L_tmp, &n ); /* Q( 31-n)*/ - L_tmp = Mult_32_16(L_tmp, alpha); /* Q( 26-n) */ + L_tmp = Mult_32_16( L_tmp, alpha ); /* Q( 26-n) */ - *n1 = n; - move16(); + *n1 = n; + move16(); - return L_tmp; + return L_tmp; } /*===================================================================*/ @@ -3769,91 +3747,91 @@ Word32 calc_weight( /*===================================================================*/ /* 40-32 bit conversion */ -Word32 polynomial_eval_fx(Word16 f, - Word32* coef, - Word16 order -) +Word32 polynomial_eval_fx( Word16 f, + Word32 *coef, + Word16 order ) { - Word16 i, idx; - Word16 dh, dl, coslut; - Word32 Ltemp, L_tmp1, L_tmp; - Word32 Lacc; - idx = f; - move16(); - dh = extract_h(coef[order / 2]); /* Q10 */ - dl = extract_l(coef[order / 2]); /* Q16 */ - - coslut = 0x4000; - move16(); /* coslut=0.5 in Q15 */ - Ltemp = L_mult0(coslut, dh); /* Ltemp=MSW, coef[5]/2 in Q25 */ - - Lacc = L_mult0(coslut, dl); /* Lacc=LSW, coef[5]/2 in Q41 //Q31 */ - Lacc = L_shr(Lacc, 1); /* Q30 */ - FOR(i = (order / 2) - 1; i > 0; i--) - { - coslut = cos_table[idx]; - move16(); /* coslut=cos( ( ( order/2)-i)f), Q15 */ - dh = extract_h(coef[i]);/* Q10 */ - dl = extract_l(coef[i]);/* Q16 */ - - Ltemp = L_add(Ltemp, L_mult0(dh, coslut)); /* Q25 */ - IF(dl < 0) - { - L_tmp1 = L_shl(L_add(65536, dl), 14); - L_tmp = Mult_32_16(L_tmp1, coslut); - Lacc = L_add(Lacc, L_tmp); - } - ELSE - { - Lacc = L_add(Lacc, L_shr(L_mult0(coslut, dl), 1));/* Q30 */ - } - - idx += f; - if (GE_16(idx, 512)) idx = sub(idx, 512); /* modulo of 512 */ - } - - coslut = cos_table[idx]; - move16(); /* coslut=cos( 5f), Q15 */ - Ltemp = L_add(Ltemp, L_mult0(0x400, coslut)); /* coef[0]=1.0, Q25 */ - - return (L_add(Ltemp, L_shr(Lacc, 15))); /* Q25 */ + Word16 i, idx; + Word16 dh, dl, coslut; + Word32 Ltemp, L_tmp1, L_tmp; + Word32 Lacc; + idx = f; + move16(); + dh = extract_h( coef[order / 2] ); /* Q10 */ + dl = extract_l( coef[order / 2] ); /* Q16 */ + + coslut = 0x4000; + move16(); /* coslut=0.5 in Q15 */ + Ltemp = L_mult0( coslut, dh ); /* Ltemp=MSW, coef[5]/2 in Q25 */ + + Lacc = L_mult0( coslut, dl ); /* Lacc=LSW, coef[5]/2 in Q41 //Q31 */ + Lacc = L_shr( Lacc, 1 ); /* Q30 */ + FOR( i = ( order / 2 ) - 1; i > 0; i-- ) + { + coslut = cos_table[idx]; + move16(); /* coslut=cos( ( ( order/2)-i)f), Q15 */ + dh = extract_h( coef[i] ); /* Q10 */ + dl = extract_l( coef[i] ); /* Q16 */ + + Ltemp = L_add( Ltemp, L_mult0( dh, coslut ) ); /* Q25 */ + IF( dl < 0 ) + { + L_tmp1 = L_shl( L_add( 65536, dl ), 14 ); + L_tmp = Mult_32_16( L_tmp1, coslut ); + Lacc = L_add( Lacc, L_tmp ); + } + ELSE + { + Lacc = L_add( Lacc, L_shr( L_mult0( coslut, dl ), 1 ) ); /* Q30 */ + } + + idx += f; + if ( GE_16( idx, 512 ) ) + idx = sub( idx, 512 ); /* modulo of 512 */ + } + + coslut = cos_table[idx]; + move16(); /* coslut=cos( 5f), Q15 */ + Ltemp = L_add( Ltemp, L_mult0( 0x400, coslut ) ); /* coef[0]=1.0, Q25 */ + + return ( L_add( Ltemp, L_shr( Lacc, 15 ) ) ); /* Q25 */ } /*----------------------------------------------------------------------------------* -* v_sort: -* -* This is very fast with almost ordered vectors. The first 15 ISF values -* are almost always sorted. -*----------------------------------------------------------------------------------*/ + * v_sort: + * + * This is very fast with almost ordered vectors. The first 15 ISF values + * are almost always sorted. + *----------------------------------------------------------------------------------*/ void v_sort( - Word16 *r, /* i/o: Vector to be sorted in place */ - const Word16 lo, /* i : Low limit of sorting range */ - const Word16 up /* I : High limit of sorting range */ + Word16 *r, /* i/o: Vector to be sorted in place */ + const Word16 lo, /* i : Low limit of sorting range */ + const Word16 up /* I : High limit of sorting range */ ) { - Word16 i, j; - Word16 tempr; - - - FOR(i = sub(up, 1); i >= lo; i--) - { - tempr = r[i]; - move16(); - FOR(j = i; j < up; j++) - { - IF(LE_16(tempr, r[j + 1])) - { - BREAK; - } - r[j] = r[j + 1]; - move16(); - } - r[j] = tempr; - move16(); - } - - - return; + Word16 i, j; + Word16 tempr; + + + FOR( i = sub( up, 1 ); i >= lo; i-- ) + { + tempr = r[i]; + move16(); + FOR( j = i; j < up; j++ ) + { + IF( LE_16( tempr, r[j + 1] ) ) + { + BREAK; + } + r[j] = r[j + 1]; + move16(); + } + r[j] = tempr; + move16(); + } + + + return; } #ifdef IVAS_MSVQ @@ -3864,74 +3842,74 @@ void v_sort( *-------------------------------------------------------------------*/ void dctT2_N_apply_matrix( - const float* input, /* i : input in fdcng or DCT(fdcng) domain */ - float* output, /* o : output in DCT(fdcng) or fdcng ordomain */ - const int16_t dct_dim, /* i : dct processing dim possibly truncated */ - const int16_t fdcngvq_dim, /* i : fdcng domain length */ - const float* matrix, /* i : IDCT matrix */ - const int16_t matrix_row_dim, /* i : */ - const DCTTYPE dcttype /* i : matrix operation type */ + const float *input, /* i : input in fdcng or DCT(fdcng) domain */ + float *output, /* o : output in DCT(fdcng) or fdcng ordomain */ + const int16_t dct_dim, /* i : dct processing dim possibly truncated */ + const int16_t fdcngvq_dim, /* i : fdcng domain length */ + const float *matrix, /* i : IDCT matrix */ + const int16_t matrix_row_dim, /* i : */ + const DCTTYPE dcttype /* i : matrix operation type */ ) { - int16_t i, j, dim_in, dim_out; - int16_t mat_step_col, mat_step_row, mat_step_col_flag; - const float* pt_x, *pt_A; - float tmp_y[FDCNG_VQ_MAX_LEN]; - float* pt_y; - - /* non-square DCT_N and IDCT_N matrix application, - using a stored format of an IDCT_Nx(FDCNG_VQ_DCT_MAXTRUNC) matrix */ - /* efficiently parallelized in SIMD */ - - assert(dct_dim <= FDCNG_VQ_DCT_MAXTRUNC); - assert(fdcngvq_dim <= FDCNG_VQ_MAX_LEN); - - if ((dcttype & 1) == 0) /* even entries are DCTs */ - { - /* DCT_typeII 24,21 -> XX in worst case */ - dim_in = fdcngvq_dim; - dim_out = dct_dim; - mat_step_col = matrix_row_dim; /* matrix maximum storage size dependent, width of first row in matrix */ - mat_step_row = 0; - mat_step_col_flag = 1; - assert(dcttype == DCT_T2_21_XX || dcttype == DCT_T2_24_XX); - } - else - { - assert((dcttype & 1) != 0); /* idct */ - dim_in = dct_dim; - dim_out = fdcngvq_dim; - mat_step_col = 1; - mat_step_row = matrix_row_dim; - mat_step_col_flag = 0; - assert(dcttype == IDCT_T2_XX_24); - } - - pt_y = tmp_y; - for (i = 0; i < dim_out; i++) - { - pt_x = input; - *pt_y = 0; - - /* +i(DCT) or +i*maxTrunc(IDCT) */ + int16_t i, j, dim_in, dim_out; + int16_t mat_step_col, mat_step_row, mat_step_col_flag; + const float *pt_x, *pt_A; + float tmp_y[FDCNG_VQ_MAX_LEN]; + float *pt_y; + + /* non-square DCT_N and IDCT_N matrix application, + using a stored format of an IDCT_Nx(FDCNG_VQ_DCT_MAXTRUNC) matrix */ + /* efficiently parallelized in SIMD */ + + assert( dct_dim <= FDCNG_VQ_DCT_MAXTRUNC ); + assert( fdcngvq_dim <= FDCNG_VQ_MAX_LEN ); + + if ( ( dcttype & 1 ) == 0 ) /* even entries are DCTs */ + { + /* DCT_typeII 24,21 -> XX in worst case */ + dim_in = fdcngvq_dim; + dim_out = dct_dim; + mat_step_col = matrix_row_dim; /* matrix maximum storage size dependent, width of first row in matrix */ + mat_step_row = 0; + mat_step_col_flag = 1; + assert( dcttype == DCT_T2_21_XX || dcttype == DCT_T2_24_XX ); + } + else + { + assert( ( dcttype & 1 ) != 0 ); /* idct */ + dim_in = dct_dim; + dim_out = fdcngvq_dim; + mat_step_col = 1; + mat_step_row = matrix_row_dim; + mat_step_col_flag = 0; + assert( dcttype == IDCT_T2_XX_24 ); + } + + pt_y = tmp_y; + for ( i = 0; i < dim_out; i++ ) + { + pt_x = input; + *pt_y = 0; + + /* +i(DCT) or +i*maxTrunc(IDCT) */ #define WMC_TOOL_SKIP - pt_A = &(matrix[i * (mat_step_row + mat_step_col_flag)]); /* ptr indexing */ - PTR_INIT(1); + pt_A = &( matrix[i * ( mat_step_row + mat_step_col_flag )] ); /* ptr indexing */ + PTR_INIT( 1 ); #undef WMC_TOOL_SKIP - for (j = 0; j < dim_in; j++) - { + for ( j = 0; j < dim_in; j++ ) + { #define WMC_TOOL_SKIP - * pt_y += (*pt_x++) * (*pt_A); - pt_A += mat_step_col; /* step +maxtrunc or +1 */ /* ptr indexing*/ - MAC(1); + *pt_y += ( *pt_x++ ) * ( *pt_A ); + pt_A += mat_step_col; /* step +maxtrunc or +1 */ /* ptr indexing*/ + MAC( 1 ); #undef WMC_TOOL_SKIP - } - pt_y++; - } + } + pt_y++; + } - mvr2r(tmp_y, output, dim_out); + mvr2r( tmp_y, output, dim_out ); - return; + return; } @@ -3943,49 +3921,49 @@ void dctT2_N_apply_matrix( *-------------------------------------------------------------------*/ void extend_dctN_input( - const float* input, /* i : input in fdcng domain */ - const float* dct_input, /* i : input in dctN(fdcng) domain */ - const int16_t in_dim, /* i : in_dim == N */ - float* ext_sig, /* o : extended output in fdcng domain */ - const int16_t out_dim, /* i : output total dim */ - float* matrix, /* i : idct synthesis matrix N rows, n_cols columns */ - const int16_t n_cols, /* i : number of columns == DCT truncation length */ - const DCTTYPE dcttype /* i : matrix operation type */ + const float *input, /* i : input in fdcng domain */ + const float *dct_input, /* i : input in dctN(fdcng) domain */ + const int16_t in_dim, /* i : in_dim == N */ + float *ext_sig, /* o : extended output in fdcng domain */ + const int16_t out_dim, /* i : output total dim */ + float *matrix, /* i : idct synthesis matrix N rows, n_cols columns */ + const int16_t n_cols, /* i : number of columns == DCT truncation length */ + const DCTTYPE dcttype /* i : matrix operation type */ ) { - int16_t i, j, i_rev; - const float(*ptr)[FDCNG_VQ_DCT_MAXTRUNC] = (void*)matrix; - - /* stored format is an IDCT_Nx(FDCNG_VQ_DCT_MAXTRUNC) matrix */ - assert(in_dim < FDCNG_VQ_MAX_LEN); - assert(out_dim <= FDCNG_VQ_MAX_LEN); - assert(out_dim > in_dim); - assert(n_cols == FDCNG_VQ_DCT_MAXTRUNC); /* for *ptr[MAX_TRUNC] adressing*/ - assert((dcttype & 1) != 0); /* idct tables always in use for this basis vector extension */ - - mvr2r(input, ext_sig, in_dim); /* copy initial part, i.e. only last/tail parts are extended */ - set_f(&(ext_sig[in_dim]), 0.0, out_dim - in_dim); - - i_rev = in_dim; /*ptr init*/ - for (i = in_dim; i < out_dim; i++) - { /* for each extension sample */ - /* i = 21 22 23; - i_rev = 20 19 18; for odd dctII reflect basis vector - */ - i_rev--; - - for (j = 0; j < n_cols; j++) /* for each available DCT coeff */ - { - /* DCTcoeff * reflected basis vector */ + int16_t i, j, i_rev; + const float( *ptr )[FDCNG_VQ_DCT_MAXTRUNC] = (void *) matrix; + + /* stored format is an IDCT_Nx(FDCNG_VQ_DCT_MAXTRUNC) matrix */ + assert( in_dim < FDCNG_VQ_MAX_LEN ); + assert( out_dim <= FDCNG_VQ_MAX_LEN ); + assert( out_dim > in_dim ); + assert( n_cols == FDCNG_VQ_DCT_MAXTRUNC ); /* for *ptr[MAX_TRUNC] adressing*/ + assert( ( dcttype & 1 ) != 0 ); /* idct tables always in use for this basis vector extension */ + + mvr2r( input, ext_sig, in_dim ); /* copy initial part, i.e. only last/tail parts are extended */ + set_f( &( ext_sig[in_dim] ), 0.0, out_dim - in_dim ); + + i_rev = in_dim; /*ptr init*/ + for ( i = in_dim; i < out_dim; i++ ) + { /* for each extension sample */ + /* i = 21 22 23; + i_rev = 20 19 18; for odd dctII reflect basis vector + */ + i_rev--; + + for ( j = 0; j < n_cols; j++ ) /* for each available DCT coeff */ + { + /* DCTcoeff * reflected basis vector */ #define WMC_TOOL_SKIP - /* pure ptr MAC operations */ - ext_sig[i] += dct_input[j] * ptr[i_rev][j]; /* sum up scaled and extended basis vector */ - MAC(1); + /* pure ptr MAC operations */ + ext_sig[i] += dct_input[j] * ptr[i_rev][j]; /* sum up scaled and extended basis vector */ + MAC( 1 ); #undef WMC_TOOL_SKIP - } - } + } + } - return; + return; } @@ -3997,75 +3975,75 @@ void extend_dctN_input( *-------------------------------------------------------------------*/ void create_IDCT_N_Matrix( - float* inv_matrixFloatQ, /* i/o: RAM buffer */ - const int16_t N, /* i : DCT length, number of time samples */ - const int16_t n_cols, /* i : number of dct coeffs (as DCT may be truncated) */ - const int16_t alloc_size /* i : RAM buffer size in elements */ + float *inv_matrixFloatQ, /* i/o: RAM buffer */ + const int16_t N, /* i : DCT length, number of time samples */ + const int16_t n_cols, /* i : number of dct coeffs (as DCT may be truncated) */ + const int16_t alloc_size /* i : RAM buffer size in elements */ ) { - int16_t c, c1, r, r_flip, W16_val; - int16_t len; - int16_t mat_cpy_size; - const Word16* absval_ptr; - const Word8* idx_ptr; - Word16 idx; - float(*ptr)[FDCNG_VQ_DCT_MAXTRUNC] = (void*)inv_matrixFloatQ; /* fixed number of columns pointers, to simplifies adressing in ANSIC */ - - absval_ptr = unique_idctT2_24coeffsQ16; - idx_ptr = idctT2_24_compressed_idx; - len = FDCNG_VQ_MAX_LEN; - - if (N == FDCNG_VQ_MAX_LEN_WB) - { - absval_ptr = unique_idctT2_21coeffsQ16; - idx_ptr = idctT2_21_compressed_idx; - len = N; - } - - assert(alloc_size >= (n_cols * len)); /* enough space for the full expanded IDCT matrix */ - assert(N <= len); - - mat_cpy_size = (n_cols) * (len >> 1); /* NB integer division of "len" */ - - if ((len & 1) != 0) - { /* odd sized DCT with a non-reflected center row */ - mat_cpy_size += n_cols; - } - - for (c = 0; c < mat_cpy_size; c++) - { - idx = (Word16)(idx_ptr[c]); - W16_val = absval_ptr[abs(idx)]; - - if (idx < 0) - { - W16_val = -(W16_val); - } - inv_matrixFloatQ[c] = (+1.52587890625e-05f) * ((float)W16_val); /* 1.0/2.^16 scaling to a float-"Q0" , a scaling that is not done in BASOP */ - } - - /* for even number of coeffs DCT24, - flip symmetry for odd, even is used to save 50% IDCT Table ROM */ - /* for an odd DCT center is not flipped e.g for DCT21 */ - - assert(n_cols == FDCNG_VQ_DCT_MAXTRUNC); - assert((n_cols & 1) == 0); - - for (c = 0; c < (n_cols); c += 2) - { - c1 = c + 1; - r_flip = len - 1; - for (r = 0; r < (len / 2); r++, r_flip--) - { + int16_t c, c1, r, r_flip, W16_val; + int16_t len; + int16_t mat_cpy_size; + const Word16 *absval_ptr; + const Word8 *idx_ptr; + Word16 idx; + float( *ptr )[FDCNG_VQ_DCT_MAXTRUNC] = (void *) inv_matrixFloatQ; /* fixed number of columns pointers, to simplifies adressing in ANSIC */ + + absval_ptr = unique_idctT2_24coeffsQ16; + idx_ptr = idctT2_24_compressed_idx; + len = FDCNG_VQ_MAX_LEN; + + if ( N == FDCNG_VQ_MAX_LEN_WB ) + { + absval_ptr = unique_idctT2_21coeffsQ16; + idx_ptr = idctT2_21_compressed_idx; + len = N; + } + + assert( alloc_size >= ( n_cols * len ) ); /* enough space for the full expanded IDCT matrix */ + assert( N <= len ); + + mat_cpy_size = ( n_cols ) * ( len >> 1 ); /* NB integer division of "len" */ + + if ( ( len & 1 ) != 0 ) + { /* odd sized DCT with a non-reflected center row */ + mat_cpy_size += n_cols; + } + + for ( c = 0; c < mat_cpy_size; c++ ) + { + idx = (Word16) ( idx_ptr[c] ); + W16_val = absval_ptr[abs( idx )]; + + if ( idx < 0 ) + { + W16_val = -( W16_val ); + } + inv_matrixFloatQ[c] = ( +1.52587890625e-05f ) * ( (float) W16_val ); /* 1.0/2.^16 scaling to a float-"Q0" , a scaling that is not done in BASOP */ + } + + /* for even number of coeffs DCT24, + flip symmetry for odd, even is used to save 50% IDCT Table ROM */ + /* for an odd DCT center is not flipped e.g for DCT21 */ + + assert( n_cols == FDCNG_VQ_DCT_MAXTRUNC ); + assert( ( n_cols & 1 ) == 0 ); + + for ( c = 0; c < ( n_cols ); c += 2 ) + { + c1 = c + 1; + r_flip = len - 1; + for ( r = 0; r < ( len / 2 ); r++, r_flip-- ) + { #define WMC_TOOL_SKIP - ptr[r_flip][c] = ptr[r][c]; /* flipped */ - ptr[r_flip][c1] = -(ptr[r][c1]); /* flipped and sign swapped */ - MOVE(2); - MULT(1); /* for negate */ + ptr[r_flip][c] = ptr[r][c]; /* flipped */ + ptr[r_flip][c1] = -( ptr[r][c1] ); /* flipped and sign swapped */ + MOVE( 2 ); + MULT( 1 ); /* for negate */ #undef WMC_TOOL_SKIP - } - } + } + } - return; + return; } #endif diff --git a/lib_com/lsp_conv_poly_fx.c b/lib_com/lsp_conv_poly_fx.c index 5a54c093c..2685a127e 100644 --- a/lib_com/lsp_conv_poly_fx.c +++ b/lib_com/lsp_conv_poly_fx.c @@ -902,4 +902,4 @@ static void cheb2poly_fx( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_com/math_32.h b/lib_com/math_32.h index 539284d5a..aa3bc1f27 100644 --- a/lib_com/math_32.h +++ b/lib_com/math_32.h @@ -5,6 +5,6 @@ #include "basop32.h" #include "enh32.h" -#define Mult_32_16(A,B) Mpy_32_16_1(A,B) -#define Mult_32_32(A,B) Mpy_32_32(A,B) -#endif /* #ifndef _MATH_32_H_ */ +#define Mult_32_16( A, B ) Mpy_32_16_1( A, B ) +#define Mult_32_32( A, B ) Mpy_32_32( A, B ) +#endif /* #ifndef _MATH_32_H_ */ diff --git a/lib_com/math_op.c b/lib_com/math_op.c index 1ad5a328a..ea0a7ef6c 100644 --- a/lib_com/math_op.c +++ b/lib_com/math_op.c @@ -37,22 +37,22 @@ | 3- L_y = L_x << exponant | |___________________________________________________________________________| */ -Word32 Isqrt( /* (o) Q31 : output value (range: 0<=val<1) */ - Word32 L_x /* (i) Q0 : input value (range: 0<=val<=7fffffff) */ +Word32 Isqrt( /* (o) Q31 : output value (range: 0<=val<1) */ + Word32 L_x /* (i) Q0 : input value (range: 0<=val<=7fffffff) */ ) { Word16 exp; Word32 L_y; - exp = norm_l(L_x); - L_x = L_shl(L_x, exp); /* L_x is normalized */ - exp = sub(31, exp); + exp = norm_l( L_x ); + L_x = L_shl( L_x, exp ); /* L_x is normalized */ + exp = sub( 31, exp ); - L_x = Isqrt_lc(L_x, &exp); + L_x = Isqrt_lc( L_x, &exp ); - L_y = L_shl(L_x, exp); /* denormalization */ + L_y = L_shl( L_x, exp ); /* denormalization */ - return (L_y); + return ( L_y ); } /*___________________________________________________________________________ @@ -76,21 +76,22 @@ Word32 Isqrt( /* (o) Q31 : output value (range: 0<= |___________________________________________________________________________| */ Word32 Isqrt_lc( - Word32 frac, /* (i) Q31: normalized value (1.0 < frac <= 0.5) */ - Word16 * exp /* (i/o) : exponent (value = frac x 2^exponent) */ + Word32 frac, /* (i) Q31: normalized value (1.0 < frac <= 0.5) */ + Word16 *exp /* (i/o) : exponent (value = frac x 2^exponent) */ ) { Word16 i, a; Word32 L_tmp; - IF (frac <= (Word32) 0) + IF( frac <= (Word32) 0 ) { - *exp = 0; move16(); + *exp = 0; + move16(); return 0x7fffffff; /*0x7fffffff*/ } /* If exponant odd -> shift right by 10 (otherwise 9) */ - L_tmp = L_shr(frac, shift_Isqrt_lc[s_and(*exp, 1)]); + L_tmp = L_shr( frac, shift_Isqrt_lc[s_and( *exp, 1 )] ); /* 1) -16384 to shift left and change sign */ /* 2) 32768 to Add 1 to Exponent like it was divided by 2 */ @@ -99,14 +100,15 @@ Word32 Isqrt_lc( /* not be rounded towards negative infinity. */ /* It replaces: */ /* *exp = negate(shr(sub(*exp, 1), 1)); move16(); */ - *exp = mac_r(32768, *exp, -16384); move16(); + *exp = mac_r( 32768, *exp, -16384 ); + move16(); - a = extract_l(L_tmp); /* Extract b10-b24 */ - a = lshr(a, 1); + a = extract_l( L_tmp ); /* Extract b10-b24 */ + a = lshr( a, 1 ); - i = mac_r(L_tmp, -16*2-1, 16384); /* Extract b25-b31 minus 16 */ - - L_tmp = L_msu(L_table_isqrt[i], table_isqrt_diff[i], a);/* table[i] << 16 - diff*a*2 */ + i = mac_r( L_tmp, -16 * 2 - 1, 16384 ); /* Extract b25-b31 minus 16 */ + + L_tmp = L_msu( L_table_isqrt[i], table_isqrt_diff[i], a ); /* table[i] << 16 - diff*a*2 */ return L_tmp; } @@ -130,25 +132,24 @@ Word32 Isqrt_lc( |___________________________________________________________________________| */ -Word32 Pow2( /* (o) Q0 : result (range: 0<=val<=0x7fffffff) */ - Word16 exponant, /* (i) Q0 : Integer part. (range: 0<=val<=30) */ - Word16 fraction /* (i) Q15 : Fractionnal part. (range: 0.0<=val<1.0) */ +Word32 Pow2( /* (o) Q0 : result (range: 0<=val<=0x7fffffff) */ + Word16 exponant, /* (i) Q0 : Integer part. (range: 0<=val<=30) */ + Word16 fraction /* (i) Q15 : Fractionnal part. (range: 0.0<=val<1.0) */ ) { Word16 exp, i, a; Word32 L_x; + i = mac_r( -32768, fraction, 32 ); /* Extract b10-b16 of fraction */ + a = s_and( fraction, 0x3ff ); /* Extract b0-b9 of fraction */ - i = mac_r(-32768, fraction, 32); /* Extract b10-b16 of fraction */ - a = s_and(fraction, 0x3ff); /* Extract b0-b9 of fraction */ - - L_x = L_deposit_h(table_pow2[i]); /* table[i] << 16 */ - L_x = L_mac(L_x, table_pow2_diff_x32[i], a);/* L_x -= diff*a*2 */ + L_x = L_deposit_h( table_pow2[i] ); /* table[i] << 16 */ + L_x = L_mac( L_x, table_pow2_diff_x32[i], a ); /* L_x -= diff*a*2 */ - exp = sub(30, exponant); + exp = sub( 30, exponant ); - L_x = L_shr_r(L_x, exp); + L_x = L_shr_r( L_x, exp ); return L_x; @@ -169,19 +170,19 @@ Word32 Pow2( /* (o) Q0 : result (range: 0<=v */ #ifdef BASOP_NOGLOB -Word32 Dot_product12_o( /* (o) Q31: normalized result (1 < val <= -1) */ - const Word16 x[], /* (i) 12bits: x vector */ - const Word16 y[], /* (i) 12bits: y vector */ - const Word16 lg, /* (i) : vector length */ - Word16* exp, /* (o) : exponent of result (0..+30) */ - Flag* Overflow_out /* o : propagating the Overflow flag to upper level, set to NULL to ignore internal overflows */ +Word32 Dot_product12_o( /* (o) Q31: normalized result (1 < val <= -1) */ + const Word16 x[], /* (i) 12bits: x vector */ + const Word16 y[], /* (i) 12bits: y vector */ + const Word16 lg, /* (i) : vector length */ + Word16 *exp, /* (o) : exponent of result (0..+30) */ + Flag *Overflow_out /* o : propagating the Overflow flag to upper level, set to NULL to ignore internal overflows */ ) -#else /* BASOP_NOGLOB */ -Word32 Dot_product12( /* (o) Q31: normalized result (1 < val <= -1) */ - const Word16 x[], /* (i) 12bits: x vector */ - const Word16 y[], /* (i) 12bits: y vector */ - const Word16 lg, /* (i) : vector length */ - Word16 * exp /* (o) : exponent of result (0..+30) */ +#else /* BASOP_NOGLOB */ +Word32 Dot_product12( /* (o) Q31: normalized result (1 < val <= -1) */ + const Word16 x[], /* (i) 12bits: x vector */ + const Word16 y[], /* (i) 12bits: y vector */ + const Word16 lg, /* (i) : vector length */ + Word16 *exp /* (o) : exponent of result (0..+30) */ ) #endif /* BASOP_NOGLOB */ { @@ -192,39 +193,40 @@ Word32 Dot_product12( /* (o) Q31: normalized result (1 < va #endif /* BASOP_NOGLOB */ #ifdef BASOP_NOGLOB - L_sum = L_mac_o(1, x[0], y[0], &Overflow_ignored); + L_sum = L_mac_o( 1, x[0], y[0], &Overflow_ignored ); #else - L_sum = L_mac(1, x[0], y[0]); + L_sum = L_mac( 1, x[0], y[0] ); #endif - FOR (i = 1; i < lg; i++) + FOR( i = 1; i < lg; i++ ) { #ifdef BASOP_NOGLOB - L_sum = L_mac_o(L_sum, x[i], y[i], Overflow_out ? Overflow_out : &Overflow_ignored); -#else /* BASOP_NOGLOB */ - L_sum = L_mac(L_sum, x[i], y[i]); + L_sum = L_mac_o( L_sum, x[i], y[i], Overflow_out ? Overflow_out : &Overflow_ignored ); +#else /* BASOP_NOGLOB */ + L_sum = L_mac( L_sum, x[i], y[i] ); #endif /* BASOP_NOGLOB */ } /* Normalize acc in Q31 */ - sft = norm_l(L_sum); - L_sum = L_shl(L_sum, sft); + sft = norm_l( L_sum ); + L_sum = L_shl( L_sum, sft ); - *exp = sub(30, sft); move16(); /* exponent = 0..30 */ + *exp = sub( 30, sft ); + move16(); /* exponent = 0..30 */ return L_sum; } #ifdef BASOP_NOGLOB -Word32 Dot_product12( /* (o) Q31: normalized result (1 < val <= -1) */ - const Word16 x[], /* (i) 12bits: x vector */ - const Word16 y[], /* (i) 12bits: y vector */ - const Word16 lg, /* (i) : vector length */ - Word16 * exp /* (o) : exponent of result (0..+30) */ +Word32 Dot_product12( /* (o) Q31: normalized result (1 < val <= -1) */ + const Word16 x[], /* (i) 12bits: x vector */ + const Word16 y[], /* (i) 12bits: y vector */ + const Word16 lg, /* (i) : vector length */ + Word16 *exp /* (o) : exponent of result (0..+30) */ ) { /* Ignore internal overflows */ - return Dot_product12_o(x, y, lg, exp, NULL); + return Dot_product12_o( x, y, lg, exp, NULL ); } #endif /* BASOP_NOGLOB */ @@ -238,11 +240,11 @@ Word32 Dot_product12( /* (o) Q31: normalized result (1 < va |___________________________________________________________________________| */ -Word32 Energy_scale( /* (o) : Q31: normalized result (1 < val <= -1) */ - const Word16 x[], /* (i) : input vector x */ - const Word16 lg, /* (i) : vector length */ - Word16 expi, /* (i) : exponent of input */ - Word16 *exp /* (o) : exponent of result (0..+30) */ +Word32 Energy_scale( /* (o) : Q31: normalized result (1 < val <= -1) */ + const Word16 x[], /* (i) : input vector x */ + const Word16 lg, /* (i) : vector length */ + Word16 expi, /* (i) : exponent of input */ + Word16 *exp /* (o) : exponent of result (0..+30) */ ) { Word16 i, sft, tmp; @@ -252,74 +254,75 @@ Word32 Energy_scale( /* (o) : Q31: normalized result (1 < #endif - L_sum = 0; /* just to avoid superflous compiler warning about uninitialized use of L_sum */ + L_sum = 0; /* just to avoid superflous compiler warning about uninitialized use of L_sum */ - IF (expi == 0) + IF( expi == 0 ) { #ifdef BASOP_NOGLOB - L_sum = L_mac_o(1, x[0], x[0], &Overflow); + L_sum = L_mac_o( 1, x[0], x[0], &Overflow ); #else - L_sum = L_mac(1, x[0], x[0]); + L_sum = L_mac( 1, x[0], x[0] ); #endif - FOR (i = 1; i < lg; i++) + FOR( i = 1; i < lg; i++ ) { #ifdef BASOP_NOGLOB - L_sum = L_mac_o(L_sum, x[i], x[i], &Overflow); + L_sum = L_mac_o( L_sum, x[i], x[i], &Overflow ); #else /* BASOP_NOGLOB */ - L_sum = L_mac(L_sum, x[i], x[i]); + L_sum = L_mac( L_sum, x[i], x[i] ); #endif } } - IF (expi < 0) + IF( expi < 0 ) { - sft = lshl(-32768 /* 0x8000 */, expi); - tmp = mult_r(x[0], sft); - L_sum = L_mac(1, tmp, tmp); - FOR (i = 1; i < lg; i++) + sft = lshl( -32768 /* 0x8000 */, expi ); + tmp = mult_r( x[0], sft ); + L_sum = L_mac( 1, tmp, tmp ); + FOR( i = 1; i < lg; i++ ) { - tmp = mult_r(x[i], sft); + tmp = mult_r( x[i], sft ); #ifdef BASOP_NOGLOB - L_sum = L_mac_o(L_sum, tmp, tmp, &Overflow); + L_sum = L_mac_o( L_sum, tmp, tmp, &Overflow ); #else - L_sum = L_mac(L_sum, tmp, tmp); + L_sum = L_mac( L_sum, tmp, tmp ); #endif } } - IF (expi > 0) + IF( expi > 0 ) { #ifdef BASOP_NOGLOB - tmp = shl_o(x[0], expi, &Overflow); - L_sum = L_mac_o(1, tmp, tmp, &Overflow); - FOR (i = 1; i < lg; i++) + tmp = shl_o( x[0], expi, &Overflow ); + L_sum = L_mac_o( 1, tmp, tmp, &Overflow ); + FOR( i = 1; i < lg; i++ ) { - tmp = shl_o(x[i], expi, &Overflow); - L_sum = L_mac_o(L_sum, tmp, tmp, &Overflow); + tmp = shl_o( x[i], expi, &Overflow ); + L_sum = L_mac_o( L_sum, tmp, tmp, &Overflow ); } #else - tmp = shl(x[0], expi); - L_sum = L_mac(1, tmp, tmp); - FOR (i = 1; i < lg; i++) + tmp = shl( x[0], expi ); + L_sum = L_mac( 1, tmp, tmp ); + FOR( i = 1; i < lg; i++ ) { - tmp = shl(x[i], expi); - L_sum = L_mac(L_sum, tmp, tmp); + tmp = shl( x[i], expi ); + L_sum = L_mac( L_sum, tmp, tmp ); } #endif } /* Normalize acc in Q31 */ - sft = norm_l(L_sum); - L_sum = L_shl(L_sum, sft); + sft = norm_l( L_sum ); + L_sum = L_shl( L_sum, sft ); - *exp = sub(30, sft); move16(); /* exponent = 0..30 */ + *exp = sub( 30, sft ); + move16(); /* exponent = 0..30 */ return L_sum; } -Word32 Sqrt_l( /* o : output value, Q31 */ - Word32 L_x, /* i : input value, Q31 */ - Word16 *exp /* o : right shift to be applied to result, Q1 */ +Word32 Sqrt_l( /* o : output value, Q31 */ + Word32 L_x, /* i : input value, Q31 */ + Word16 *exp /* o : right shift to be applied to result, Q1 */ ) { /* @@ -327,40 +330,42 @@ Word32 Sqrt_l( /* o : output value, Q31 */ x = f * 2^-e, 0.5 <= f < 1 (normalization) - y = sqrt(f) * 2^(-e/2) + y = sqrt(f) * 2^(-e/2) a) e = 2k --> y = sqrt(f) * 2^-k (k = e div 2, 0.707 <= sqrt(f) < 1) b) e = 2k+1 --> y = sqrt(f/2) * 2^-k (k = e div 2, 0.5 <= sqrt(f/2) < 0.707) */ - + Word16 e, i, a, tmp; Word32 L_y; - if (L_x <= 0) + if ( L_x <= 0 ) { - *exp = 0; move16 (); - return L_deposit_l(0); + *exp = 0; + move16(); + return L_deposit_l( 0 ); } - e = s_and(norm_l(L_x), 0x7FFE); /* get next lower EVEN norm. exp */ - L_x = L_shl(L_x, e); /* L_x is normalized to [0.25..1) */ - *exp = e; move16 (); /* return 2*exponent (or Q1) */ + e = s_and( norm_l( L_x ), 0x7FFE ); /* get next lower EVEN norm. exp */ + L_x = L_shl( L_x, e ); /* L_x is normalized to [0.25..1) */ + *exp = e; + move16(); /* return 2*exponent (or Q1) */ - L_x = L_shr(L_x, 9); - a = extract_l(L_x); /* Extract b10-b24 */ - a = lshr(a, 1); + L_x = L_shr( L_x, 9 ); + a = extract_l( L_x ); /* Extract b10-b24 */ + a = lshr( a, 1 ); - i = mac_r(L_x, -16*2-1, 16384); /* Extract b25-b31 minus 16 */ + i = mac_r( L_x, -16 * 2 - 1, 16384 ); /* Extract b25-b31 minus 16 */ - L_y = L_deposit_h(sqrt_table[i]); /* table[i] << 16 */ - tmp = sub(sqrt_table[i], sqrt_table[i + 1]); /* table[i] - table[i+1]) */ - L_y = L_msu(L_y, tmp, a); /* L_y -= tmp*a*2 */ - - /* L_y = L_shr (L_y, *exp); */ /* denormalization done by caller */ + L_y = L_deposit_h( sqrt_table[i] ); /* table[i] << 16 */ + tmp = sub( sqrt_table[i], sqrt_table[i + 1] ); /* table[i] - table[i+1]) */ + L_y = L_msu( L_y, tmp, a ); /* L_y -= tmp*a*2 */ - return (L_y); + /* L_y = L_shr (L_y, *exp); */ /* denormalization done by caller */ + + return ( L_y ); } /*---------------------------------------------------------------------------* @@ -369,25 +374,25 @@ Word32 Sqrt_l( /* o : output value, Q31 */ * Calculate square root from fractional values (Q31 -> Q31) * Uses 32 bit internal representation for precision *---------------------------------------------------------------------------*/ -Word32 L_Frac_sqrtQ31( /* o : Square root if input */ - const Word32 x /* i : Input */ +Word32 L_Frac_sqrtQ31( /* o : Square root if input */ + const Word32 x /* i : Input */ ) { Word32 log2_work; Word16 log2_int, log2_frac; test(); - if (x > 0) + if ( x > 0 ) { - log2_int = norm_l(x); - log2_frac = Log2_norm_lc(L_shl(x, log2_int)); + log2_int = norm_l( x ); + log2_frac = Log2_norm_lc( L_shl( x, log2_int ) ); - log2_work = L_msu((31+30)*65536L/2, 16384, log2_int); - log2_work = L_mac0(log2_work, log2_frac, 1); + log2_work = L_msu( ( 31 + 30 ) * 65536L / 2, 16384, log2_int ); + log2_work = L_mac0( log2_work, log2_frac, 1 ); - log2_frac = L_Extract_lc(log2_work, &log2_int); + log2_frac = L_Extract_lc( log2_work, &log2_int ); - return Pow2(log2_int, log2_frac); + return Pow2( log2_int, log2_frac ); } return 0; } @@ -397,11 +402,11 @@ Word32 L_Frac_sqrtQ31( /* o : Square root if input */ * * Calculate square root from fractional values (Q15 -> Q15) *----------------------------------------------------------------------------------*/ -Word16 Frac_sqrt( /* o : Square root if input */ - const Word16 x /* i : Input */ +Word16 Frac_sqrt( /* o : Square root if input */ + const Word16 x /* i : Input */ ) { - return round_fx(L_Frac_sqrtQ31(L_deposit_h(x))); + return round_fx( L_Frac_sqrtQ31( L_deposit_h( x ) ) ); } @@ -411,10 +416,7 @@ Word16 Frac_sqrt( /* o : Square root if input */ * Faster Integer Multiplication *----------------------------------------------------------------------------------*/ -Word16 i_mult2 (Word16 a, Word16 b) +Word16 i_mult2( Word16 a, Word16 b ) { - return extract_l(L_mult0(a, b)); + return extract_l( L_mult0( a, b ) ); } - - - diff --git a/lib_com/math_op.h b/lib_com/math_op.h index 28d72147f..0e5fa825b 100644 --- a/lib_com/math_op.h +++ b/lib_com/math_op.h @@ -6,50 +6,48 @@ #include "oper_32b.h" #include "log2.h" -Word32 Isqrt( /* (o) Q31 : output value (range: 0<=val<1) */ - Word32 L_x /* (i) Q0 : input value (range: 0<=val<=7fffffff) */ +Word32 Isqrt( /* (o) Q31 : output value (range: 0<=val<1) */ + Word32 L_x /* (i) Q0 : input value (range: 0<=val<=7fffffff) */ ); Word32 Isqrt_lc( - Word32 frac, /* (i/o) Q31: normalized value (1.0 < frac <= 0.5) */ - Word16 * exp /* (i/o) : exponent (value = frac x 2^exponent) */ + Word32 frac, /* (i/o) Q31: normalized value (1.0 < frac <= 0.5) */ + Word16 *exp /* (i/o) : exponent (value = frac x 2^exponent) */ ); -Word32 Pow2( /* (o) Q0 : result (range: 0<=val<=0x7fffffff) */ - Word16 exponant, /* (i) Q0 : Integer part. (range: 0<=val<=30) */ - Word16 fraction /* (i) Q15 : Fractionnal part. (range: 0.0<=val<1.0) */ +Word32 Pow2( /* (o) Q0 : result (range: 0<=val<=0x7fffffff) */ + Word16 exponant, /* (i) Q0 : Integer part. (range: 0<=val<=30) */ + Word16 fraction /* (i) Q15 : Fractionnal part. (range: 0.0<=val<1.0) */ ); -Word32 Dot_product12( /* (o) Q31: normalized result (1 < val <= -1) */ - const Word16 x[], /* (i) 12bits: x vector */ - const Word16 y[], /* (i) 12bits: y vector */ - const Word16 lg, /* (i) : vector length */ - Word16 * exp /* (o) : exponent of result (0..+30) */ +Word32 Dot_product12( /* (o) Q31: normalized result (1 < val <= -1) */ + const Word16 x[], /* (i) 12bits: x vector */ + const Word16 y[], /* (i) 12bits: y vector */ + const Word16 lg, /* (i) : vector length */ + Word16 *exp /* (o) : exponent of result (0..+30) */ ); -Word32 Energy_scale( /* (o) Q31: normalized result (1 < val <= -1) */ - const Word16 x[], /* (i) 12bits: x vector */ - const Word16 lg, /* (i) : vector length */ - Word16 expi, /* (i) : exponent of input */ - Word16 *exp /* (o) : exponent of result (0..+30) */ +Word32 Energy_scale( /* (o) Q31: normalized result (1 < val <= -1) */ + const Word16 x[], /* (i) 12bits: x vector */ + const Word16 lg, /* (i) : vector length */ + Word16 expi, /* (i) : exponent of input */ + Word16 *exp /* (o) : exponent of result (0..+30) */ ); -Word32 Sqrt_l(Word32 L_x, Word16 *exp); +Word32 Sqrt_l( Word32 L_x, Word16 *exp ); -Word32 L_Frac_sqrtQ31( /* o : Square root if input */ - const Word32 x /* i : Input */ +Word32 L_Frac_sqrtQ31( /* o : Square root if input */ + const Word32 x /* i : Input */ ); -Word16 Frac_sqrt( /* o : Square root if input */ - const Word16 x /* i : Input */ +Word16 Frac_sqrt( /* o : Square root if input */ + const Word16 x /* i : Input */ ); -Word16 i_mult2 (Word16 a, Word16 b); +Word16 i_mult2( Word16 a, Word16 b ); -Word32 Dot_product12_o( /* (o) Q31: normalized result (1 < val <= -1) */ - const Word16 x[], /* (i) 12bits: x vector */ - const Word16 y[], /* (i) 12bits: y vector */ - const Word16 lg, /* (i) : vector length */ - Word16* exp, /* (o) : exponent of result (0..+30) */ - Flag* Overflow_out /* o : propagating the Overflow flag to upper level */ +Word32 Dot_product12_o( /* (o) Q31: normalized result (1 < val <= -1) */ + const Word16 x[], /* (i) 12bits: x vector */ + const Word16 y[], /* (i) 12bits: y vector */ + const Word16 lg, /* (i) : vector length */ + Word16 *exp, /* (o) : exponent of result (0..+30) */ + Flag *Overflow_out /* o : propagating the Overflow flag to upper level */ ); - - diff --git a/lib_com/modif_fs.c b/lib_com/modif_fs.c index caa84ae75..e07eb02aa 100644 --- a/lib_com/modif_fs.c +++ b/lib_com/modif_fs.c @@ -540,35 +540,35 @@ void Interpolate_allpass_steep_32( /* upper allpass filter chain */ FOR( k = 0; k < N; k++ ) { - temp_fx[0] = L_add(mem_fx[0] , Mpy_32_16_1( in_fx[k], AP2_STEEP_FX[0] )); - mem_fx[0] = L_sub(in_fx[k] , Mpy_32_16_1( temp_fx[0], AP2_STEEP_FX[0] )); + temp_fx[0] = L_add( mem_fx[0], Mpy_32_16_1( in_fx[k], AP2_STEEP_FX[0] ) ); + mem_fx[0] = L_sub( in_fx[k], Mpy_32_16_1( temp_fx[0], AP2_STEEP_FX[0] ) ); /* for better performance, unroll this loop */ FOR( n = 1; n < ALLPASSSECTIONS_STEEP - 1; n++ ) { - temp_fx[n] = L_add(mem_fx[n] , Mpy_32_16_1( temp_fx[n - 1], AP2_STEEP_FX[n] )); - mem_fx[n] = L_sub(temp_fx[n - 1] , Mpy_32_16_1( temp_fx[n], AP2_STEEP_FX[n] )); + temp_fx[n] = L_add( mem_fx[n], Mpy_32_16_1( temp_fx[n - 1], AP2_STEEP_FX[n] ) ); + mem_fx[n] = L_sub( temp_fx[n - 1], Mpy_32_16_1( temp_fx[n], AP2_STEEP_FX[n] ) ); } - out_fx[2 * k + 1] = L_add(mem_fx[ALLPASSSECTIONS_STEEP - 1] , Mpy_32_16_1( temp_fx[ALLPASSSECTIONS_STEEP - 2], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] )); - mem_fx[ALLPASSSECTIONS_STEEP - 1] = L_sub(temp_fx[ALLPASSSECTIONS_STEEP - 2] , Mpy_32_16_1( out_fx[2 * k + 1], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] )); + out_fx[2 * k + 1] = L_add( mem_fx[ALLPASSSECTIONS_STEEP - 1], Mpy_32_16_1( temp_fx[ALLPASSSECTIONS_STEEP - 2], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); + mem_fx[ALLPASSSECTIONS_STEEP - 1] = L_sub( temp_fx[ALLPASSSECTIONS_STEEP - 2], Mpy_32_16_1( out_fx[2 * k + 1], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); } /* lower allpass filter chain */ FOR( k = 0; k < N; k++ ) { - temp_fx[0] = L_add(mem_fx[ALLPASSSECTIONS_STEEP] , Mpy_32_16_1( in_fx[k], AP1_STEEP_FX[0] )); - mem_fx[ALLPASSSECTIONS_STEEP] = L_sub(in_fx[k] , Mpy_32_16_1( temp_fx[0], AP1_STEEP_FX[0] )); + temp_fx[0] = L_add( mem_fx[ALLPASSSECTIONS_STEEP], Mpy_32_16_1( in_fx[k], AP1_STEEP_FX[0] ) ); + mem_fx[ALLPASSSECTIONS_STEEP] = L_sub( in_fx[k], Mpy_32_16_1( temp_fx[0], AP1_STEEP_FX[0] ) ); /* for better performance, unroll this loop */ FOR( n = 1; n < ALLPASSSECTIONS_STEEP - 1; n++ ) { - temp_fx[n] = L_add(mem_fx[ALLPASSSECTIONS_STEEP + n] , Mpy_32_16_1( temp_fx[n - 1], AP1_STEEP_FX[n] )); - mem_fx[ALLPASSSECTIONS_STEEP + n] = L_sub(temp_fx[n - 1] , Mpy_32_16_1( temp_fx[n], AP1_STEEP_FX[n] )); + temp_fx[n] = L_add( mem_fx[ALLPASSSECTIONS_STEEP + n], Mpy_32_16_1( temp_fx[n - 1], AP1_STEEP_FX[n] ) ); + mem_fx[ALLPASSSECTIONS_STEEP + n] = L_sub( temp_fx[n - 1], Mpy_32_16_1( temp_fx[n], AP1_STEEP_FX[n] ) ); } - out_fx[2 * k] = L_add(mem_fx[2 * ALLPASSSECTIONS_STEEP - 1] , Mpy_32_16_1( temp_fx[ALLPASSSECTIONS_STEEP - 2], AP1_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] )); - mem_fx[2 * ALLPASSSECTIONS_STEEP - 1] = L_sub(temp_fx[ALLPASSSECTIONS_STEEP - 2] , Mpy_32_16_1( out_fx[2 * k], AP1_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] )); + out_fx[2 * k] = L_add( mem_fx[2 * ALLPASSSECTIONS_STEEP - 1], Mpy_32_16_1( temp_fx[ALLPASSSECTIONS_STEEP - 2], AP1_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); + mem_fx[2 * ALLPASSSECTIONS_STEEP - 1] = L_sub( temp_fx[ALLPASSSECTIONS_STEEP - 2], Mpy_32_16_1( out_fx[2 * k], AP1_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); } return; diff --git a/lib_com/modif_fs_fx.c b/lib_com/modif_fs_fx.c index c426b5556..85be57a43 100644 --- a/lib_com/modif_fs_fx.c +++ b/lib_com/modif_fs_fx.c @@ -3,13 +3,13 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ #include "prot_fx1.h" #include "prot_fx2.h" -#include "rom_com.h" /* Static table prototypes */ +#include "rom_com.h" /* Static table prototypes */ #include -#include "rom_enc.h" /* prototypes */ +#include "rom_enc.h" /* prototypes */ #include "basop_util.h" #include "ivas_prot_fx.h" @@ -18,7 +18,6 @@ *-----------------------------------------------------------------*/ - /*==============================================================================*/ /* FUNCTION : modify_Fs_fx ( ) */ /*------------------------------------------------------------------------------*/ @@ -41,14 +40,14 @@ /*------------------------------------------------------------------------------*/ /* CALLED FROM : TX/RX */ /*==============================================================================*/ -Word16 modify_Fs_fx( /* o : length of output Q0 */ - const Word16 sigIn_fx[], /* i : signal to decimate Q0 */ - Word16 lg, /* i : length of input Q0 */ - const Word32 fin, /* i : frequency of input Q0 */ - Word16 sigOut_fx[], /* o : decimated signal Q0 */ - const Word32 fout, /* i : frequency of output Q0 */ - Word16 mem_fx[], /* i/o: filter memory Q0 */ - const Word16 nblp /* i : flag indicating if NB low-pass is applied */ +Word16 modify_Fs_fx( /* o : length of output Q0 */ + const Word16 sigIn_fx[], /* i : signal to decimate Q0 */ + Word16 lg, /* i : length of input Q0 */ + const Word32 fin, /* i : frequency of input Q0 */ + Word16 sigOut_fx[], /* o : decimated signal Q0 */ + const Word32 fout, /* i : frequency of output Q0 */ + Word16 mem_fx[], /* i/o: filter memory Q0 */ + const Word16 nblp /* i : flag indicating if NB low-pass is applied */ ) { Word16 i; @@ -57,8 +56,8 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ Word16 num_den; Word16 datastep, fracstep; Word16 *sigIn_ptr, *sigPtr; - Word16 signal_tab_fx[3*L_FILT_MAX + L_FRAME48k], *signal_fx, *signal_ana_fx; /* 3* as 2* for memory and 1* for future prediction */ - Word16 A_fx[M+1], r_fx_h[M+1], r_fx_l[M+1]; + Word16 signal_tab_fx[3 * L_FILT_MAX + L_FRAME48k], *signal_fx, *signal_ana_fx; /* 3* as 2* for memory and 1* for future prediction */ + Word16 A_fx[M + 1], r_fx_h[M + 1], r_fx_l[M + 1]; Word16 mem_len_ana; Word16 plus_sample_in; Word16 j; @@ -66,13 +65,13 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ Word16 mem_preemph_fx; Word16 Q_r; Word16 mem_lev_fx[18]; - Word32 t0, t1, t2, L_tmp; /* temporary variables */ - Word32 LepsP[M+1]; + Word32 t0, t1, t2, L_tmp; /* temporary variables */ + Word32 LepsP[M + 1]; Word16 flag_low_order = 0; Word16 filt_len_tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; -#endif +#endif const Resampling_cfg *cfg_ptr_fx; /*-------------------------------------------------------------------* @@ -80,10 +79,10 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ *-------------------------------------------------------------------*/ /* check if fin and fout are the same */ - IF (EQ_32(fin,fout)) + IF( EQ_32( fin, fout ) ) { /* just copy the signal_fx and quit */ - Copy(sigIn_fx, sigOut_fx, lg); + Copy( sigIn_fx, sigOut_fx, lg ); return lg; } @@ -91,7 +90,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ { /* find the resampling configuration in the lookup table */ cfg_ptr_fx = &resampling_cfg_tbl[0]; - WHILE ( (cfg_ptr_fx->fin_fx != 0) && !(EQ_32(cfg_ptr_fx->fin_fx,fin)&&EQ_32(cfg_ptr_fx->fout_fx,fout))) + WHILE( ( cfg_ptr_fx->fin_fx != 0 ) && !( EQ_32( cfg_ptr_fx->fin_fx, fin ) && EQ_32( cfg_ptr_fx->fout_fx, fout ) ) ) { test(); test(); @@ -102,12 +101,12 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ /* find config with NB 4kHz low-pass */ test(); test(); - IF ( nblp && (GT_32(fin, 8000))&&(EQ_32(fout,12800))) + IF( nblp && ( GT_32( fin, 8000 ) ) && ( EQ_32( fout, 12800 ) ) ) { flag_low_order = 1; move16(); cfg_ptr_fx++; - WHILE ( (cfg_ptr_fx->fin_fx != 0) && !( (EQ_32(cfg_ptr_fx->fin_fx, fin))&&(EQ_32(cfg_ptr_fx->fout_fx,fout)))) + WHILE( ( cfg_ptr_fx->fin_fx != 0 ) && !( ( EQ_32( cfg_ptr_fx->fin_fx, fin ) ) && ( EQ_32( cfg_ptr_fx->fout_fx, fout ) ) ) ) { test(); test(); @@ -119,28 +118,28 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ * Retrieve and/or calculate the resampling parameters *-------------------------------------------------------------------*/ fac_num = cfg_ptr_fx->fac_num_fx; - move16();/*Q0*/ + move16(); /*Q0*/ fac_den = cfg_ptr_fx->fac_den_fx; move16(); - IF(GE_16(lg,L_FRAME)) + IF( GE_16( lg, L_FRAME ) ) { - lg_out = cfg_ptr_fx->lg_out ; + lg_out = cfg_ptr_fx->lg_out; move16(); } ELSE { - lg_out = idiv1616(i_mult2(lg, fac_num), fac_den); + lg_out = idiv1616( i_mult2( lg, fac_num ), fac_den ); } filt_len = cfg_ptr_fx->filt_len_fx; move16(); plus_sample_in = 0; - move16();/*default, regular delay*/ + move16(); /*default, regular delay*/ frac = 0; move16(); test(); - IF ( (EQ_32(fin, 8000))&&(EQ_32(fout,12800))) + IF( ( EQ_32( fin, 8000 ) ) && ( EQ_32( fout, 12800 ) ) ) { plus_sample_in = 7; move16(); @@ -148,8 +147,8 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ move16(); } - mem_len = shl(filt_len,1); - signal_fx = signal_tab_fx+2*L_FILT_MAX + sub(L_FRAME48k, add(mem_len, lg)); + mem_len = shl( filt_len, 1 ); + signal_fx = signal_tab_fx + 2 * L_FILT_MAX + sub( L_FRAME48k, add( mem_len, lg ) ); signal_ana_fx = signal_fx; mem_len_ana = mem_len; move16(); @@ -160,165 +159,165 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ * Resample *-------------------------------------------------------------------*/ /* append filter memory */ - Copy(mem_fx, signal_fx, mem_len); + Copy( mem_fx, signal_fx, mem_len ); sigPtr = signal_fx + mem_len; - Copy(sigIn_fx, sigPtr, lg); + Copy( sigIn_fx, sigPtr, lg ); - IF(plus_sample_in > 0) + IF( plus_sample_in > 0 ) { - autocorr_fx( signal_ana_fx+mem_len_ana+lg-LEN_WIN_SSS, 1, r_fx_h, r_fx_l, &Q_r, LEN_WIN_SSS, wind_sss_fx, 0, 0 ); + autocorr_fx( signal_ana_fx + mem_len_ana + lg - LEN_WIN_SSS, 1, r_fx_h, r_fx_l, &Q_r, LEN_WIN_SSS, wind_sss_fx, 0, 0 ); - t1 = L_Comp(r_fx_h[1], r_fx_l[1]); /* R[1] in Q31 */ - t2 = L_abs(t1); /* abs R[1] */ - t0 = L_deposit_l(0); - IF (r_fx_h[0] != 0) + t1 = L_Comp( r_fx_h[1], r_fx_l[1] ); /* R[1] in Q31 */ + t2 = L_abs( t1 ); /* abs R[1] */ + t0 = L_deposit_l( 0 ); + IF( r_fx_h[0] != 0 ) { - t0 = Div_32(t2, r_fx_h[0], r_fx_l[0]); /* R[1]/R[0] in Q31 */ + t0 = Div_32( t2, r_fx_h[0], r_fx_l[0] ); /* R[1]/R[0] in Q31 */ } - if (t1 < 0) + if ( t1 < 0 ) { - t0 = L_negate(t0); /* R[1]/R[0] */ + t0 = L_negate( t0 ); /* R[1]/R[0] */ } - - mu_preemph_fx = extract_h(t0); /*r_fx[1] / r_fx[0]; */ - mem_preemph_fx = signal_ana_fx[mem_len_ana+lg-LEN_WIN_SSS - 1]; + mu_preemph_fx = extract_h( t0 ); /*r_fx[1] / r_fx[0]; */ + mem_preemph_fx = signal_ana_fx[mem_len_ana + lg - LEN_WIN_SSS - 1]; move16(); - preemph_fx(signal_ana_fx+mem_len_ana+lg-LEN_WIN_SSS, mu_preemph_fx, LEN_WIN_SSS, &mem_preemph_fx); + preemph_fx( signal_ana_fx + mem_len_ana + lg - LEN_WIN_SSS, mu_preemph_fx, LEN_WIN_SSS, &mem_preemph_fx ); /* Autocorrelations */ - autocorr_fx( signal_ana_fx+mem_len_ana+lg-LEN_WIN_SSS, M, r_fx_h, r_fx_l, &Q_r, + autocorr_fx( signal_ana_fx + mem_len_ana + lg - LEN_WIN_SSS, M, r_fx_h, r_fx_l, &Q_r, LEN_WIN_SSS, wind_sss_fx, 0, 0 ); /* Lag windowing */ lag_wind( r_fx_h, r_fx_l, M, fin, LAGW_STRONG ); /* Levinson-Durbin */ - set16_fx(mem_lev_fx, 0, 18 ); - E_LPC_lev_dur(r_fx_h, r_fx_l, A_fx, LepsP, M, NULL); + set16_fx( mem_lev_fx, 0, 18 ); + E_LPC_lev_dur( r_fx_h, r_fx_l, A_fx, LepsP, M, NULL ); - Copy_Scale_sig( A_fx, A_fx, M+1, sub(norm_s(A_fx[0]),2) ); + Copy_Scale_sig( A_fx, A_fx, M + 1, sub( norm_s( A_fx[0] ), 2 ) ); - FOR (i=0; ifilter_fx, frac, fac_num, filt_len_tmp ) ); #else - sigOut_fx[i] = round_fx(Interpol_lc_fx( sigIn_ptr, cfg_ptr_fx->filter_fx, frac, fac_num, filt_len_tmp )); + sigOut_fx[i] = round_fx( Interpol_lc_fx( sigIn_ptr, cfg_ptr_fx->filter_fx, frac, fac_num, filt_len_tmp ) ); #endif - frac = add(frac,fracstep); + frac = add( frac, fracstep ); - j = sub(fac_num, frac); - if (j < 0) + j = sub( fac_num, frac ); + if ( j < 0 ) { - frac = sub(frac,fac_num); + frac = sub( frac, fac_num ); } - sigIn_ptr += add(lshr(j, 15), datastep); + sigIn_ptr += add( lshr( j, 15 ), datastep ); } /* rescaling */ test(); - IF ((GT_16(fac_num,fac_den))==((cfg_ptr_fx->flags_fx&RS_INV_FAC)!=0)) + IF( ( GT_16( fac_num, fac_den ) ) == ( ( cfg_ptr_fx->flags_fx & RS_INV_FAC ) != 0 ) ) { - IF(LT_16(fac_num, fac_den)) + IF( LT_16( fac_num, fac_den ) ) { - num_den = div_s(fac_num,fac_den);/*Q15*/ + num_den = div_s( fac_num, fac_den ); /*Q15*/ test(); - IF( GT_32(fin, 16000)&&EQ_16(lg_out,512)) + IF( GT_32( fin, 16000 ) && EQ_16( lg_out, 512 ) ) { - FOR( i=0; iflags_fx&RS_INV_FAC)!=0)) + ELSE IF( ( LT_16( fac_num, fac_den ) ) && ( ( cfg_ptr_fx->flags_fx & RS_INV_FAC ) != 0 ) ) { - FOR( i=0; i Q(-QSR) */ + sigin_sr[i] = shr( sigIn[i], QSR ); + move16(); /* shift right : Q0 -> Q(-QSR) */ } /* length of the interpolated signal */ @@ -388,165 +387,164 @@ Word16 modify_Fs_intcub3m_sup_fx( /* o : length of output */ /* coef inits using memory (indexes < 0) */ /* cc[2][] : indexes -2 -1 0 1 */ - cptr = &(cc[2][0]); - cptr[0] = mult_r(sigin_sr[-1], 10923); + cptr = &( cc[2][0] ); + cptr[0] = mult_r( sigin_sr[-1], 10923 ); move16(); /* sigIn[-1]/3 */ - cptr[2] = sub(shr(add(sigin_sr[-2], sigin_sr[0]), 1), sigin_sr[-1]); - move16(); /* (sigIn[-2]+sigIn[0])/2-sigIn[-1]; */ - cptr[3] = sub(mult_r(sub(add(sigin_sr[-2], sigin_sr[1]), add(sigin_sr[-1], sigin_sr[0])), 5461), mult_r(cptr[2],21845)); + cptr[2] = sub( shr( add( sigin_sr[-2], sigin_sr[0] ), 1 ), sigin_sr[-1] ); + move16(); /* (sigIn[-2]+sigIn[0])/2-sigIn[-1]; */ + cptr[3] = sub( mult_r( sub( add( sigin_sr[-2], sigin_sr[1] ), add( sigin_sr[-1], sigin_sr[0] ) ), 5461 ), mult_r( cptr[2], 21845 ) ); move16(); /*(sigIn[-2]+sigIn[1]-sigIn[-1]-sigIn[0]) / 6 - 4/6*cc[2][2]);*/ - cptr[1] = sub(sub(sigin_sr[0], sigin_sr[-1]), add(cptr[3], cptr[2])); + cptr[1] = sub( sub( sigin_sr[0], sigin_sr[-1] ), add( cptr[3], cptr[2] ) ); move16(); /* cc[3][] : indexes -1 0 1 2 */ - cptr = &(cc[3][0]); - cptr[0] = mult_r(sigin_sr[0], 10923); - move16();/* sigIn[-1]/3 */ - cptr[2] = sub(shr(add(sigin_sr[-1], sigin_sr[1]), 1), sigin_sr[0]); - move16(); /* (sigIn[-1]+sigIn[1])/2-sigIn[0]; */ - cptr[3] = sub(mult_r(sub(add(sigin_sr[-1], sigin_sr[2]), add(sigin_sr[0], sigin_sr[1])), 5461), mult_r(cptr[2],21845)); + cptr = &( cc[3][0] ); + cptr[0] = mult_r( sigin_sr[0], 10923 ); + move16(); /* sigIn[-1]/3 */ + cptr[2] = sub( shr( add( sigin_sr[-1], sigin_sr[1] ), 1 ), sigin_sr[0] ); + move16(); /* (sigIn[-1]+sigIn[1])/2-sigIn[0]; */ + cptr[3] = sub( mult_r( sub( add( sigin_sr[-1], sigin_sr[2] ), add( sigin_sr[0], sigin_sr[1] ) ), 5461 ), mult_r( cptr[2], 21845 ) ); move16(); /*(sigIn[-2]+sigIn[1]-sigIn[-1]-sigIn[0]) / 6 - 4/6*cc[2][2]);*/ - cptr[1] = sub(sub(sigin_sr[1], sigin_sr[0]), add(cptr[3], cptr[2])); + cptr[1] = sub( sub( sigin_sr[1], sigin_sr[0] ), add( cptr[3], cptr[2] ) ); move16(); sigOutptr = sigOut; cind = -1; move16(); move16(); /* for the move */ - IF( EQ_32(fin, 12800)) + IF( EQ_32( fin, 12800 ) ) { - if( EQ_32(fout, 8000)) + if ( EQ_32( fout, 8000 ) ) { cind = 0; move16(); } - if( EQ_32(fout, 16000)) + if ( EQ_32( fout, 16000 ) ) { cind = 1; move16(); } - if( EQ_32(fout, 32000)) + if ( EQ_32( fout, 32000 ) ) { cind = 2; move16(); } - if( EQ_32(fout, 48000)) + if ( EQ_32( fout, 48000 ) ) { cind = 3; move16(); } } - IF( EQ_32(fin, 16000)) + IF( EQ_32( fin, 16000 ) ) { - if( EQ_32(fout, 12800)) + if ( EQ_32( fout, 12800 ) ) { cind = 4; move16(); } - if( EQ_32(fout, 32000)) + if ( EQ_32( fout, 32000 ) ) { cind = 5; move16(); } - if( EQ_32(fout, 48000)) + if ( EQ_32( fout, 48000 ) ) { cind = 6; move16(); } - } - ctptr = &(ct2_fx[cind][0]); - lg_out = mult_r(shl(lg,2),ctptr[13]); + ctptr = &( ct2_fx[cind][0] ); + lg_out = mult_r( shl( lg, 2 ), ctptr[13] ); *delayout = ctptr[9]; move16(); - if( EQ_16(ctptr[12], 15)) + if ( EQ_16( ctptr[12], 15 ) ) { cu = cu15_fx; - move16();/*pointer*/ + move16(); /*pointer*/ } - if( EQ_16(ctptr[12],4)) + if ( EQ_16( ctptr[12], 4 ) ) { cu = cu4_fx; - move16();/*pointer*/ + move16(); /*pointer*/ } - k2d = sub(ctptr[12], 1); /* shift of index in cu with respect to the next sample (ex 1.25 -> 0.25 ) */ - fk1 = shl(k2d, 1); - k3d = sub(fk1, 1); /* to compurte index in cu with respect to the last sample with - sign (ex 1.25 -> -0.75 ) */ + k2d = sub( ctptr[12], 1 ); /* shift of index in cu with respect to the next sample (ex 1.25 -> 0.25 ) */ + fk1 = shl( k2d, 1 ); + k3d = sub( fk1, 1 ); /* to compurte index in cu with respect to the last sample with - sign (ex 1.25 -> -0.75 ) */ kk = 0; move16(); i = 0; move16(); - lim = sub(lg, ctptr[11]); - lim2 = sub(lg, 3); + lim = sub( lg, ctptr[11] ); + lim2 = sub( lg, 3 ); lim3 = ctptr[10]; move16(); - WHILE(LT_16(i, lim2)) + WHILE( LT_16( i, lim2 ) ) { - if(GE_16(i, lim)) + if ( GE_16( i, lim ) ) { - lim3 = sub(ctptr[11], 3); /* last, incomplete period*/ + lim3 = sub( ctptr[11], 3 ); /* last, incomplete period*/ } *sigOutptr++ = sigIn[i]; move16(); - FOR(k = 0; k < lim3; k++) + FOR( k = 0; k < lim3; k++ ) { - cptr = &(cc[kk][0]); - cptr[0] = mult_r(sigin_sr[i+1], 10923); - move16();/* sigIn[-1]/3 */ - cptr[2] = sub(shr(add(sigin_sr[i], sigin_sr[i+2]), 1), sigin_sr[i+1]); - move16(); /* (sigIn[-1]+sigIn[1])/2-sigIn[0]; */ - cptr[3] = sub(mult_r(sub(add(sigin_sr[i], sigin_sr[i+3]), add(sigin_sr[i+1], sigin_sr[i+2])), 5461), mult_r(cptr[2],21845)); + cptr = &( cc[kk][0] ); + cptr[0] = mult_r( sigin_sr[i + 1], 10923 ); + move16(); /* sigIn[-1]/3 */ + cptr[2] = sub( shr( add( sigin_sr[i], sigin_sr[i + 2] ), 1 ), sigin_sr[i + 1] ); + move16(); /* (sigIn[-1]+sigIn[1])/2-sigIn[0]; */ + cptr[3] = sub( mult_r( sub( add( sigin_sr[i], sigin_sr[i + 3] ), add( sigin_sr[i + 1], sigin_sr[i + 2] ) ), 5461 ), mult_r( cptr[2], 21845 ) ); move16(); /*(sigIn[-1]+sigIn[1]-sigIn[0]-sigIn[1]) / 6 - 4/6*cc[3][2]);*/ - cptr[1] = sub(sub(sigin_sr[i+2], sigin_sr[i+1]), add(cptr[3], cptr[2])); + cptr[1] = sub( sub( sigin_sr[i + 2], sigin_sr[i + 1] ), add( cptr[3], cptr[2] ) ); move16(); - i = add(i,1); + i = add( i, 1 ); - i2 = sub(kk, 2); - i1 = sub(kk, 1); - if( i1 < 0 ) + i2 = sub( kk, 2 ); + i1 = sub( kk, 1 ); + if ( i1 < 0 ) { - i1 = add(i1, 4); + i1 = add( i1, 4 ); } - if( i2 < 0 ) + if ( i2 < 0 ) { - i2 = add(i2, 4); + i2 = add( i2, 4 ); } inc = ctptr[8]; move16(); - FOR(k1 = ctptr[k]; k1 < fk1; k1 += inc) + FOR( k1 = ctptr[k]; k1 < fk1; k1 += inc ) { - k2 = sub(k1, k2d); - k3 = sub(k3d, k1); - cptr = &(cc[i2][0]); - uptr = &(cu[k1][0]); - vv32 = L_mult( 8192, *cptr++); - vv32 = L_mac(vv32, *uptr++, *cptr++); - vv32 = L_mac(vv32, *uptr++, *cptr++); - vv32 = L_mac(vv32, *uptr++, *cptr++); /* Q13*Q(-QSR) -> Q(13-QSR+1) 32 bits*/ - cptr = &(cc[i1][0]); - uptr = &(cu[k2][0]); - vv32 = L_mac(vv32, 8192, *cptr++); - vv32 = L_mac(vv32, *uptr++, *cptr++); - vv32 = L_mac(vv32, *uptr++, *cptr++); - vv32 = L_mac(vv32, *uptr++, *cptr++); - cptr = &(cc[kk][0]); - uptr = &(cu[k3][0]); - vv32 = L_mac(vv32, 8192, *cptr++); - vv32 = L_msu(vv32, *uptr++, *cptr++); - vv32 = L_mac(vv32, *uptr++, *cptr++); - vv32 = L_msu(vv32, *uptr++, *cptr++); - vv32 = L_shl(vv32, (QSR+2)); /* Q(13-QSR+1) -> Q16 */ - *sigOutptr++ = round_fx(vv32); /* Q16 -> Q0*/ + k2 = sub( k1, k2d ); + k3 = sub( k3d, k1 ); + cptr = &( cc[i2][0] ); + uptr = &( cu[k1][0] ); + vv32 = L_mult( 8192, *cptr++ ); + vv32 = L_mac( vv32, *uptr++, *cptr++ ); + vv32 = L_mac( vv32, *uptr++, *cptr++ ); + vv32 = L_mac( vv32, *uptr++, *cptr++ ); /* Q13*Q(-QSR) -> Q(13-QSR+1) 32 bits*/ + cptr = &( cc[i1][0] ); + uptr = &( cu[k2][0] ); + vv32 = L_mac( vv32, 8192, *cptr++ ); + vv32 = L_mac( vv32, *uptr++, *cptr++ ); + vv32 = L_mac( vv32, *uptr++, *cptr++ ); + vv32 = L_mac( vv32, *uptr++, *cptr++ ); + cptr = &( cc[kk][0] ); + uptr = &( cu[k3][0] ); + vv32 = L_mac( vv32, 8192, *cptr++ ); + vv32 = L_msu( vv32, *uptr++, *cptr++ ); + vv32 = L_mac( vv32, *uptr++, *cptr++ ); + vv32 = L_msu( vv32, *uptr++, *cptr++ ); + vv32 = L_shl( vv32, ( QSR + 2 ) ); /* Q(13-QSR+1) -> Q16 */ + *sigOutptr++ = round_fx( vv32 ); /* Q16 -> Q0*/ } - kk = add(kk, 1); - if( EQ_16(kk, 4)) + kk = add( kk, 1 ); + if ( EQ_16( kk, 4 ) ) { kk = 0; move16(); @@ -555,61 +553,61 @@ Word16 modify_Fs_intcub3m_sup_fx( /* o : length of output */ } - kk = sub(kk, 1); - if( kk < 0 ) + kk = sub( kk, 1 ); + if ( kk < 0 ) { kk = 3; move16(); } - if( EQ_16(ctptr[10], 1)) + if ( EQ_16( ctptr[10], 1 ) ) { *sigOutptr++ = sigIn[i]; move16(); } - FOR(k1 = ctptr[k]; k1 < fk1; k1 += inc) + FOR( k1 = ctptr[k]; k1 < fk1; k1 += inc ) { - k2 = sub(k1, k2d); - - cptr = &(cc[kk][0]); - uptr = &(cu[k2][0]); - vv32 = L_mult( 8192, *cptr++); - vv32 = L_mac(vv32, *uptr++, *cptr++); - vv32 = L_mac(vv32, *uptr++, *cptr++); - vv32 = L_mac(vv32, *uptr++, *cptr++); /* Q13*Q(-QSR) -> Q(13-QSR+1) 32 bits*/ - vv32 = L_shl(vv32, (QSR+2)); /* Q(13-QSR+1) -> Q16 */ - *sigOutptr++ = i_mult(round_fx(vv32), 3); - move16();/* Q16 -> Q0*/ + k2 = sub( k1, k2d ); + + cptr = &( cc[kk][0] ); + uptr = &( cu[k2][0] ); + vv32 = L_mult( 8192, *cptr++ ); + vv32 = L_mac( vv32, *uptr++, *cptr++ ); + vv32 = L_mac( vv32, *uptr++, *cptr++ ); + vv32 = L_mac( vv32, *uptr++, *cptr++ ); /* Q13*Q(-QSR) -> Q(13-QSR+1) 32 bits*/ + vv32 = L_shl( vv32, ( QSR + 2 ) ); /* Q(13-QSR+1) -> Q16 */ + *sigOutptr++ = i_mult( round_fx( vv32 ), 3 ); + move16(); /* Q16 -> Q0*/ } - if( LT_16(ctptr[10], 3)) + if ( LT_16( ctptr[10], 3 ) ) { - *sigOutptr++ = sigIn[add(i, 1)]; + *sigOutptr++ = sigIn[add( i, 1 )]; move16(); } - FOR( k1 = ctptr[add(k, 1)]; k1 < fk1; k1 += inc ) + FOR( k1 = ctptr[add( k, 1 )]; k1 < fk1; k1 += inc ) { - cptr = &(cc[kk][0]); - uptr = &(cu[k1][0]); - vv32 = L_mult( 8192, *cptr++); - vv32 = L_mac(vv32, *uptr++, *cptr++); - vv32 = L_mac(vv32, *uptr++, *cptr++); - vv32 = L_mac(vv32, *uptr++, *cptr++); /* Q13*Q(-QSR) -> Q(13-QSR+1) 32 bits*/ - vv32 = L_shl(vv32, (QSR+2)); /* Q(13-QSR+1) -> Q16 */ - *sigOutptr++ = i_mult(round_fx(vv32), 3); - move16();/* Q16 -> Q0*/ + cptr = &( cc[kk][0] ); + uptr = &( cu[k1][0] ); + vv32 = L_mult( 8192, *cptr++ ); + vv32 = L_mac( vv32, *uptr++, *cptr++ ); + vv32 = L_mac( vv32, *uptr++, *cptr++ ); + vv32 = L_mac( vv32, *uptr++, *cptr++ ); /* Q13*Q(-QSR) -> Q(13-QSR+1) 32 bits*/ + vv32 = L_shl( vv32, ( QSR + 2 ) ); /* Q(13-QSR+1) -> Q16 */ + *sigOutptr++ = i_mult( round_fx( vv32 ), 3 ); + move16(); /* Q16 -> Q0*/ } - if( EQ_16(ctptr[10], 1)) + if ( EQ_16( ctptr[10], 1 ) ) { - *sigOutptr = sigIn[add(i, 2)]; + *sigOutptr = sigIn[add( i, 2 )]; move16(); } } - free(sigin_sr_tab); + free( sigin_sr_tab ); return lg_out; } @@ -636,15 +634,15 @@ Word16 modify_Fs_intcub3m_sup_fx( /* o : length of output */ /*===================================================================*/ -void Decimate_allpass_steep_fx( +void Decimate_allpass_steep_fx( const Word16 *in_fx, - Word16 mem[], /* array of size: 2*ALLPASSSECTIONS_STEEP+1 */ - Word16 N, /* number of input samples */ - Word16 out_fx[]) /* array of size N/2 */ + Word16 mem[], /* array of size: 2*ALLPASSSECTIONS_STEEP+1 */ + Word16 N, /* number of input samples */ + Word16 out_fx[] ) /* array of size N/2 */ { - Word16 k; - Word16 temp[ ALLPASSSECTIONS_STEEP ]; + Word16 k; + Word16 temp[ALLPASSSECTIONS_STEEP]; Word32 Lacc, Lacc1; Word16 temp1, temp2; Word16 sum = 0; @@ -656,185 +654,181 @@ void Decimate_allpass_steep_fx( /*upper allpass filter chain */ - FOR ( k = 0; k < N/2; k++ ) + FOR( k = 0; k < N / 2; k++ ) { - Lacc = L_deposit_h( mem[0] ); /* Q(16+x) */ + Lacc = L_deposit_h( mem[0] ); /* Q(16+x) */ #ifdef BASOP_NOGLOB - Lacc = L_mac_o(Lacc, AP1_STEEP_FX[0], in_fx[2 * k], &Overflow); /* Q(16+x) */ + Lacc = L_mac_o( Lacc, AP1_STEEP_FX[0], in_fx[2 * k], &Overflow ); /* Q(16+x) */ #else - Lacc = L_mac( Lacc, AP1_STEEP_FX[0], in_fx[2*k] ); /* Q(16+x) */ + Lacc = L_mac( Lacc, AP1_STEEP_FX[0], in_fx[2 * k] ); /* Q(16+x) */ #endif - Lacc1 = L_deposit_h( in_fx[2*k] ); /* Q16+Qx */ - temp1 = extract_h( Lacc ); /* Qx */ + Lacc1 = L_deposit_h( in_fx[2 * k] ); /* Q16+Qx */ + temp1 = extract_h( Lacc ); /* Qx */ #ifdef BASOP_NOGLOB - Lacc1 = L_msu_o( Lacc1, AP1_STEEP_FX[0], temp1, &Overflow ); /* Q16+Qx */ + Lacc1 = L_msu_o( Lacc1, AP1_STEEP_FX[0], temp1, &Overflow ); /* Q16+Qx */ #else - Lacc1 = L_msu( Lacc1, AP1_STEEP_FX[0], temp1 ); /* Q16+Qx */ + Lacc1 = L_msu( Lacc1, AP1_STEEP_FX[0], temp1 ); /* Q16+Qx */ #endif - mem[0] = extract_h( Lacc1 ); /* Qx */ + mem[0] = extract_h( Lacc1 ); /* Qx */ temp[0] = temp1; move16(); - Lacc1 = L_deposit_h( mem[1] ); /* Q16+Qx */ + Lacc1 = L_deposit_h( mem[1] ); /* Q16+Qx */ #ifdef BASOP_NOGLOB - Lacc1 = ( L_mac_o( Lacc1, AP1_STEEP_FX[1], temp1, &Overflow )); /* Q16+Qx */ + Lacc1 = ( L_mac_o( Lacc1, AP1_STEEP_FX[1], temp1, &Overflow ) ); /* Q16+Qx */ #else - Lacc1 = ( L_mac( Lacc1, AP1_STEEP_FX[1], temp1 )); /* Q16+Qx */ + Lacc1 = ( L_mac( Lacc1, AP1_STEEP_FX[1], temp1 ) ); /* Q16+Qx */ #endif - temp2 = extract_h( Lacc1 ); /* Qx */ + temp2 = extract_h( Lacc1 ); /* Qx */ #ifdef BASOP_NOGLOB - Lacc = L_msu_o( Lacc, AP1_STEEP_FX[1], temp2 , &Overflow); /* Q16+Qx */ + Lacc = L_msu_o( Lacc, AP1_STEEP_FX[1], temp2, &Overflow ); /* Q16+Qx */ #else - Lacc = L_msu( Lacc, AP1_STEEP_FX[1], temp2 ); /* Q16+Qx */ + Lacc = L_msu( Lacc, AP1_STEEP_FX[1], temp2 ); /* Q16+Qx */ #endif - mem[1] = extract_h(Lacc); /* Qx */ + mem[1] = extract_h( Lacc ); /* Qx */ temp[1] = temp2; move16(); - Lacc = L_deposit_h( mem[ ALLPASSSECTIONS_STEEP-1 ] ); /* Q(16+x) */ + Lacc = L_deposit_h( mem[ALLPASSSECTIONS_STEEP - 1] ); /* Q(16+x) */ #ifdef BASOP_NOGLOB - out_fx[ k ] = extract_h( L_mac_o( Lacc, AP1_STEEP_FX[ ALLPASSSECTIONS_STEEP-1 ], temp2, &Overflow )); /* Qx format */ - mem[ALLPASSSECTIONS_STEEP - 1] = extract_h(L_msu_o(Lacc1, AP1_STEEP_FX[ALLPASSSECTIONS_STEEP - 1], out_fx[k], &Overflow)); /* Qx */ + out_fx[k] = extract_h( L_mac_o( Lacc, AP1_STEEP_FX[ALLPASSSECTIONS_STEEP - 1], temp2, &Overflow ) ); /* Qx format */ + mem[ALLPASSSECTIONS_STEEP - 1] = extract_h( L_msu_o( Lacc1, AP1_STEEP_FX[ALLPASSSECTIONS_STEEP - 1], out_fx[k], &Overflow ) ); /* Qx */ #else - out_fx[ k ] = extract_h( L_mac( Lacc, AP1_STEEP_FX[ ALLPASSSECTIONS_STEEP-1 ], temp2 )); /* Qx format */ - mem[ALLPASSSECTIONS_STEEP - 1] = extract_h(L_msu(Lacc1, AP1_STEEP_FX[ALLPASSSECTIONS_STEEP - 1], out_fx[k])); /* Qx */ + out_fx[k] = extract_h( L_mac( Lacc, AP1_STEEP_FX[ALLPASSSECTIONS_STEEP - 1], temp2 ) ); /* Qx format */ + mem[ALLPASSSECTIONS_STEEP - 1] = extract_h( L_msu( Lacc1, AP1_STEEP_FX[ALLPASSSECTIONS_STEEP - 1], out_fx[k] ) ); /* Qx */ #endif - } /* lower allpass filter chain */ - Lacc = L_deposit_h( mem[ ALLPASSSECTIONS_STEEP ] ); /* Q(16+x) */ + Lacc = L_deposit_h( mem[ALLPASSSECTIONS_STEEP] ); /* Q(16+x) */ #ifdef BASOP_NOGLOB - Lacc = L_mac_o( Lacc, AP2_STEEP_FX[0], mem[2*ALLPASSSECTIONS_STEEP], &Overflow ); /*Q(16+x) */ + Lacc = L_mac_o( Lacc, AP2_STEEP_FX[0], mem[2 * ALLPASSSECTIONS_STEEP], &Overflow ); /*Q(16+x) */ #else - Lacc = L_mac( Lacc, AP2_STEEP_FX[0], mem[2*ALLPASSSECTIONS_STEEP] ); /*Q(16+x) */ + Lacc = L_mac( Lacc, AP2_STEEP_FX[0], mem[2 * ALLPASSSECTIONS_STEEP] ); /*Q(16+x) */ #endif - Lacc1 = L_deposit_h( mem[2*ALLPASSSECTIONS_STEEP] ); /* Q(16+x) */ - temp1 = extract_h( Lacc ); /* Qx */ + Lacc1 = L_deposit_h( mem[2 * ALLPASSSECTIONS_STEEP] ); /* Q(16+x) */ + temp1 = extract_h( Lacc ); /* Qx */ #ifdef BASOP_NOGLOB - Lacc1 = L_msu_o( Lacc1, AP2_STEEP_FX[0], temp1, &Overflow ); /* Q(16+x) */ + Lacc1 = L_msu_o( Lacc1, AP2_STEEP_FX[0], temp1, &Overflow ); /* Q(16+x) */ #else - Lacc1 = L_msu( Lacc1, AP2_STEEP_FX[0], temp1 ); /* Q(16+x) */ + Lacc1 = L_msu( Lacc1, AP2_STEEP_FX[0], temp1 ); /* Q(16+x) */ #endif - mem[ ALLPASSSECTIONS_STEEP ] = extract_h( Lacc1 ); + mem[ALLPASSSECTIONS_STEEP] = extract_h( Lacc1 ); temp[0] = temp1; move16(); - Lacc1 = L_deposit_h( mem[ ALLPASSSECTIONS_STEEP+1 ] ); /* Q(16+x) */ + Lacc1 = L_deposit_h( mem[ALLPASSSECTIONS_STEEP + 1] ); /* Q(16+x) */ #ifdef BASOP_NOGLOB - Lacc1 = L_mac_o( Lacc1, AP2_STEEP_FX[1], temp1, &Overflow); /* Q(16+x) */ + Lacc1 = L_mac_o( Lacc1, AP2_STEEP_FX[1], temp1, &Overflow ); /* Q(16+x) */ #else - Lacc1 = L_mac( Lacc1, AP2_STEEP_FX[1], temp1 ); /* Q(16+x) */ + Lacc1 = L_mac( Lacc1, AP2_STEEP_FX[1], temp1 ); /* Q(16+x) */ #endif - temp2 = extract_h( Lacc1 ); /* Qx */ + temp2 = extract_h( Lacc1 ); /* Qx */ temp[1] = temp2; move16(); #ifdef BASOP_NOGLOB - Lacc = L_msu_o( Lacc, AP2_STEEP_FX[1], temp2, &Overflow ); /* Q(16+x) */ + Lacc = L_msu_o( Lacc, AP2_STEEP_FX[1], temp2, &Overflow ); /* Q(16+x) */ #else - Lacc = L_msu( Lacc, AP2_STEEP_FX[1], temp2 ); /* Q(16+x) */ + Lacc = L_msu( Lacc, AP2_STEEP_FX[1], temp2 ); /* Q(16+x) */ #endif - mem[ALLPASSSECTIONS_STEEP+1] = extract_h( Lacc ); /* Qx */ + mem[ALLPASSSECTIONS_STEEP + 1] = extract_h( Lacc ); /* Qx */ - Lacc = L_deposit_h( mem[2*ALLPASSSECTIONS_STEEP-1] ); /* Q(16+x) */ + Lacc = L_deposit_h( mem[2 * ALLPASSSECTIONS_STEEP - 1] ); /* Q(16+x) */ #ifdef BASOP_NOGLOB - Lacc = L_mac_o( Lacc, AP2_STEEP_FX[ALLPASSSECTIONS_STEEP-1], temp2, &Overflow); /* Q(16+x) temp[ALLPASSSECTIONS_STEEP-1] */ + Lacc = L_mac_o( Lacc, AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1], temp2, &Overflow ); /* Q(16+x) temp[ALLPASSSECTIONS_STEEP-1] */ #else - Lacc = L_mac( Lacc, AP2_STEEP_FX[ALLPASSSECTIONS_STEEP-1], temp2 ); /* Q(16+x) temp[ALLPASSSECTIONS_STEEP-1] */ + Lacc = L_mac( Lacc, AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1], temp2 ); /* Q(16+x) temp[ALLPASSSECTIONS_STEEP-1] */ #endif - temp[2] = extract_h( Lacc ); /* temp[2] in Qx */ + temp[2] = extract_h( Lacc ); /* temp[2] in Qx */ #ifdef BASOP_NOGLOB - Lacc1 = L_msu_o( Lacc1, AP2_STEEP_FX[ALLPASSSECTIONS_STEEP-1], temp[2], &Overflow ); /* Q(16+x) */ + Lacc1 = L_msu_o( Lacc1, AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1], temp[2], &Overflow ); /* Q(16+x) */ #else - Lacc1 = L_msu( Lacc1, AP2_STEEP_FX[ALLPASSSECTIONS_STEEP-1], temp[2] ); /* Q(16+x) */ + Lacc1 = L_msu( Lacc1, AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1], temp[2] ); /* Q(16+x) */ #endif - mem[ 2*ALLPASSSECTIONS_STEEP-1 ] = extract_h( Lacc1 ); /* Qx */ + mem[2 * ALLPASSSECTIONS_STEEP - 1] = extract_h( Lacc1 ); /* Qx */ sum = mult_r( out_fx[0], 16384 ); /* Qx */ #ifdef BASOP_NOGLOB out_fx[0] = add_sat( sum, mult_r( temp[ALLPASSSECTIONS_STEEP - 1], 16384 ) ); /* Qx */ #else - out_fx[0] = add( sum, mult_r( temp[ALLPASSSECTIONS_STEEP - 1], 16384 ) ); /* Qx */ + out_fx[0] = add( sum, mult_r( temp[ALLPASSSECTIONS_STEEP - 1], 16384 ) ); /* Qx */ #endif move16(); - FOR ( k = 1; k < N/2; k++) + FOR( k = 1; k < N / 2; k++ ) { - Lacc = L_deposit_h( mem[ ALLPASSSECTIONS_STEEP ] ); /* Q(16+x) */ + Lacc = L_deposit_h( mem[ALLPASSSECTIONS_STEEP] ); /* Q(16+x) */ #ifdef BASOP_NOGLOB - Lacc = L_mac_o(Lacc, AP2_STEEP_FX[0], in_fx[2*k-1], &Overflow); /* Q(16+x):temp[0] */ + Lacc = L_mac_o( Lacc, AP2_STEEP_FX[0], in_fx[2 * k - 1], &Overflow ); /* Q(16+x):temp[0] */ #else - Lacc = L_mac(Lacc, AP2_STEEP_FX[0], in_fx[2*k-1] ); /* Q(16+x):temp[0] */ + Lacc = L_mac( Lacc, AP2_STEEP_FX[0], in_fx[2 * k - 1] ); /* Q(16+x):temp[0] */ #endif - Lacc1 = L_deposit_h( in_fx[ 2*k-1 ] ); /* Q(16+x) */ - temp1 = extract_h( Lacc ); /* Qx */ + Lacc1 = L_deposit_h( in_fx[2 * k - 1] ); /* Q(16+x) */ + temp1 = extract_h( Lacc ); /* Qx */ #ifdef BASOP_NOGLOB - Lacc1 = L_msu_o( Lacc1, AP2_STEEP_FX[0], temp1, &Overflow ); /* Q(16+x) */ + Lacc1 = L_msu_o( Lacc1, AP2_STEEP_FX[0], temp1, &Overflow ); /* Q(16+x) */ #else - Lacc1 = L_msu( Lacc1, AP2_STEEP_FX[0], temp1 ); /* Q(16+x) */ + Lacc1 = L_msu( Lacc1, AP2_STEEP_FX[0], temp1 ); /* Q(16+x) */ #endif - mem[ALLPASSSECTIONS_STEEP] = extract_h( Lacc1 ); /* Qx */ + mem[ALLPASSSECTIONS_STEEP] = extract_h( Lacc1 ); /* Qx */ temp[0] = temp1; move16(); - Lacc1 = L_deposit_h( mem[ ALLPASSSECTIONS_STEEP+1 ] ); /* Q(16+x) */ + Lacc1 = L_deposit_h( mem[ALLPASSSECTIONS_STEEP + 1] ); /* Q(16+x) */ #ifdef BASOP_NOGLOB - Lacc1 = L_mac_o(Lacc1,AP2_STEEP_FX[1],temp1, &Overflow); /* Q(16+x) */ + Lacc1 = L_mac_o( Lacc1, AP2_STEEP_FX[1], temp1, &Overflow ); /* Q(16+x) */ #else - Lacc1 = L_mac(Lacc1,AP2_STEEP_FX[1],temp1); /* Q(16+x) */ + Lacc1 = L_mac( Lacc1, AP2_STEEP_FX[1], temp1 ); /* Q(16+x) */ #endif - temp2 = extract_h( Lacc1 ); /* Qx */ + temp2 = extract_h( Lacc1 ); /* Qx */ temp[1] = temp2; move16(); #ifdef BASOP_NOGLOB - Lacc = L_msu_o(Lacc,AP2_STEEP_FX[1],temp2, &Overflow); /* Q(16+x) */ -#else - Lacc = L_msu(Lacc,AP2_STEEP_FX[1],temp2); /* Q(16+x) */ + Lacc = L_msu_o( Lacc, AP2_STEEP_FX[1], temp2, &Overflow ); /* Q(16+x) */ +#else + Lacc = L_msu( Lacc, AP2_STEEP_FX[1], temp2 ); /* Q(16+x) */ #endif - mem[ALLPASSSECTIONS_STEEP+1]= extract_h(Lacc); /* Qx */ + mem[ALLPASSSECTIONS_STEEP + 1] = extract_h( Lacc ); /* Qx */ - Lacc = L_deposit_h( mem[2*ALLPASSSECTIONS_STEEP-1] ); /* Q(16+x) */ + Lacc = L_deposit_h( mem[2 * ALLPASSSECTIONS_STEEP - 1] ); /* Q(16+x) */ #ifdef BASOP_NOGLOB - Lacc = L_mac_o( Lacc, AP2_STEEP_FX[ALLPASSSECTIONS_STEEP-1], temp[1], &Overflow); /* Q(16+x) temp[ALLPASSSECTIONS_STEEP-1] */ + Lacc = L_mac_o( Lacc, AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1], temp[1], &Overflow ); /* Q(16+x) temp[ALLPASSSECTIONS_STEEP-1] */ #else - Lacc = L_mac( Lacc, AP2_STEEP_FX[ALLPASSSECTIONS_STEEP-1], temp[1] ); /* Q(16+x) temp[ALLPASSSECTIONS_STEEP-1] */ + Lacc = L_mac( Lacc, AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1], temp[1] ); /* Q(16+x) temp[ALLPASSSECTIONS_STEEP-1] */ #endif - temp[2] = extract_h( Lacc ); /*temp[2] in Qx */ + temp[2] = extract_h( Lacc ); /*temp[2] in Qx */ #ifdef BASOP_NOGLOB - Lacc1 = L_msu_o( Lacc1, AP2_STEEP_FX[ALLPASSSECTIONS_STEEP-1], temp[2], &Overflow ); /* Q(16+x) */ + Lacc1 = L_msu_o( Lacc1, AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1], temp[2], &Overflow ); /* Q(16+x) */ #else - Lacc1 = L_msu( Lacc1, AP2_STEEP_FX[ALLPASSSECTIONS_STEEP-1], temp[2] ); /* Q(16+x) */ + Lacc1 = L_msu( Lacc1, AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1], temp[2] ); /* Q(16+x) */ #endif - mem[2*ALLPASSSECTIONS_STEEP-1] = extract_h( Lacc1 ); /* Qx */ + mem[2 * ALLPASSSECTIONS_STEEP - 1] = extract_h( Lacc1 ); /* Qx */ - - sum = mult_r( out_fx[k], 16384 ); /* Qx */ + sum = mult_r( out_fx[k], 16384 ); /* Qx */ #ifdef BASOP_NOGLOB out_fx[k] = add_sat( sum, mult_r( temp[ALLPASSSECTIONS_STEEP - 1], 16384 ) ); #else - out_fx[k] = add( sum, mult_r( temp[ALLPASSSECTIONS_STEEP-1], 16384 ) ); + out_fx[k] = add( sum, mult_r( temp[ALLPASSSECTIONS_STEEP - 1], 16384 ) ); #endif - move16(); /* Qx */ - + move16(); /* Qx */ } /* z^(-1) */ - mem[ 2*ALLPASSSECTIONS_STEEP ] = in_fx[ N-1 ]; - move16(); /* Qx */ - + mem[2 * ALLPASSSECTIONS_STEEP] = in_fx[N - 1]; + move16(); /* Qx */ } @@ -846,13 +840,13 @@ void Decimate_allpass_steep_fx( void Interpolate_allpass_steep_fx( const Word16 *in_fx, - Word16 mem[], /* array of size: 2*ALLPASSSECTIONS_STEEP+1 */ - Word16 N, /* number of input samples */ - Word16 out_fx[]) /* array of size 2*N */ + Word16 mem[], /* array of size: 2*ALLPASSSECTIONS_STEEP+1 */ + Word16 N, /* number of input samples */ + Word16 out_fx[] ) /* array of size 2*N */ { Word16 k; - Word32 Lacc=0, Lacc1=0; + Word32 Lacc = 0, Lacc1 = 0; Word16 temp1, temp2; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; @@ -860,107 +854,106 @@ void Interpolate_allpass_steep_fx( /*** State in Q0,in_fx Q0, AP1_STEEP in Q15 AP2_STEEP in Q15 OP in Q0 ************/ /*upper allpass filter chain */ - FOR (k=0; k 0); + assert( loop_len > 0 ); mem_fx_11 = mem_fx[11]; move16(); @@ -1428,23 +1432,23 @@ void decimate_2_over_3_allpass_fx( move16(); mem_fx_3 = mem_fx[3]; move16(); - FOR (i = 0; i < loop_len; i++ ) + FOR( i = 0; i < loop_len; i++ ) { /* Lower branch */ /*Vl0 = mem[8] + filt_coeff[6] * (*in - mem[9]); Vl1 = mem[9] + filt_coeff[7] * (Vl0 - mem[10]); mem[11] = mem[10] + filt_coeff[8] * (Vl1 - mem[11]); */ - tmp = mult_r(filt_coeff_fx[6], sub(*in++, mem_fx[9])); - if (i == 0) + tmp = mult_r( filt_coeff_fx[6], sub( *in++, mem_fx[9] ) ); + if ( i == 0 ) { - Vl0 = add(mem_fx[8] , tmp); + Vl0 = add( mem_fx[8], tmp ); } - if (i != 0) + if ( i != 0 ) { - Vl0 = add(*(in-4) , tmp); + Vl0 = add( *( in - 4 ), tmp ); } - Vl1 = add(mem_fx[9] , mult_r(filt_coeff_fx[7], sub(Vl0, mem_fx[10]))); - mem_fx_11 = add(mem_fx[10], mult_r(filt_coeff_fx[8], sub(Vl1, mem_fx_11))); + Vl1 = add( mem_fx[9], mult_r( filt_coeff_fx[7], sub( Vl0, mem_fx[10] ) ) ); + mem_fx_11 = add( mem_fx[10], mult_r( filt_coeff_fx[8], sub( Vl1, mem_fx_11 ) ) ); /* mem[8] = *in++; mem[9] = Vl0; @@ -1460,52 +1464,52 @@ void decimate_2_over_3_allpass_fx( /* Vm0 = mem[4] + filt_coeff[3] * (*in - mem[5]); Vm1 = mem[5] + filt_coeff[4] * (Vm0-mem[6]); mem[7] = mem[6] + filt_coeff[5] * (Vm1-mem[7]); */ - tmp = mult_r(filt_coeff_fx[3], sub(*in++, mem_fx[5])); - if (i == 0) + tmp = mult_r( filt_coeff_fx[3], sub( *in++, mem_fx[5] ) ); + if ( i == 0 ) { - Vm0 = add(mem_fx[4] , tmp); + Vm0 = add( mem_fx[4], tmp ); } - if (i != 0) + if ( i != 0 ) { - Vm0 = add(*(in-4), tmp); + Vm0 = add( *( in - 4 ), tmp ); } - Vm1 = add(mem_fx[5] , mult_r(filt_coeff_fx[4], sub(Vm0, mem_fx[6]))); - mem_fx_7 = add(mem_fx[6], mult_r(filt_coeff_fx[5], sub(Vm1, mem_fx_7))); + Vm1 = add( mem_fx[5], mult_r( filt_coeff_fx[4], sub( Vm0, mem_fx[6] ) ) ); + mem_fx_7 = add( mem_fx[6], mult_r( filt_coeff_fx[5], sub( Vm1, mem_fx_7 ) ) ); mem_fx[5] = Vm0; move16(); mem_fx[6] = Vm1; move16(); - out = add(mem_fx_11, mem_fx_7); + out = add( mem_fx_11, mem_fx_7 ); /* Upper branch */ /* Vu0 = mem[0] + filt_coeff[0] * ( *in - mem[1] ); Vu1 = mem[1] + filt_coeff[1] * ( Vu0 - mem[2] ); mem[3] = mem[2] + filt_coeff[2] * ( Vu1 - mem[3] ); */ - tmp = mult_r(filt_coeff_fx[0], sub(*in++, mem_fx[1])); - if (i == 0) + tmp = mult_r( filt_coeff_fx[0], sub( *in++, mem_fx[1] ) ); + if ( i == 0 ) { - Vu0 = add(mem_fx[0] , tmp); + Vu0 = add( mem_fx[0], tmp ); } - if (i != 0) + if ( i != 0 ) { - Vu0 = add(*(in-4), tmp); + Vu0 = add( *( in - 4 ), tmp ); } - Vu1 = add(mem_fx[1] , mult_r(filt_coeff_fx[1], sub(Vu0, mem_fx[2]))); - mem_fx_3 = add(mem_fx[2] , mult_r(filt_coeff_fx[2], sub(Vu1, mem_fx_3))); + Vu1 = add( mem_fx[1], mult_r( filt_coeff_fx[1], sub( Vu0, mem_fx[2] ) ) ); + mem_fx_3 = add( mem_fx[2], mult_r( filt_coeff_fx[2], sub( Vu1, mem_fx_3 ) ) ); mem_fx[1] = Vu0; move16(); mem_fx[2] = Vu1; move16(); - *out1++ = add(out, mem_fx_3); + *out1++ = add( out, mem_fx_3 ); move16(); } - mem_fx[8] = *(in-3); + mem_fx[8] = *( in - 3 ); move16(); - mem_fx[4] = *(in-2); + mem_fx[4] = *( in - 2 ); move16(); - mem_fx[0] = *(in-1); + mem_fx[0] = *( in - 1 ); move16(); mem_fx[11] = mem_fx_11; move16(); @@ -1514,9 +1518,9 @@ void decimate_2_over_3_allpass_fx( mem_fx[3] = mem_fx_3; move16(); - Scale_sig(mem_fx, 12, negate(sc)); - Scale_sig(out_fx, loop_len, negate(sc)); - Scale_sig(lp_mem_fx, 6, negate(sc)); + Scale_sig( mem_fx, 12, negate( sc ) ); + Scale_sig( out_fx, loop_len, negate( sc ) ); + Scale_sig( lp_mem_fx, 6, negate( sc ) ); return; } @@ -1529,46 +1533,45 @@ void decimate_2_over_3_allpass_fx( void retro_interp4_5_fx( const Word16 *syn_fx, - Word16 *pst_old_syn_fx -) + Word16 *pst_old_syn_fx ) { Word16 *pf5, *pf4; Word16 c; /* resample st->pst_old_syn in a reverse way to preserve time-alignment */ - pf4 = (Word16*) &pst_old_syn_fx[58]; - pf5 = (Word16*) pst_old_syn_fx; - FOR (c=0; c<57; c++) + pf4 = (Word16 *) &pst_old_syn_fx[58]; + pf5 = (Word16 *) pst_old_syn_fx; + FOR( c = 0; c < 57; c++ ) { *pf5++ = pf4[0]; move16(); /* *pf5++ = 0.2f * pf4[0] + 0.8f * pf4[1]; */ - *pf5++ = mac_r(L_mult(6554, pf4[0]), 26214, pf4[1]); + *pf5++ = mac_r( L_mult( 6554, pf4[0] ), 26214, pf4[1] ); move16(); /* *pf5++ = 0.4f * pf4[1] + 0.6f * pf4[2]; */ - *pf5++ = mac_r(L_mult(13107, pf4[1]), 19661, pf4[2]); + *pf5++ = mac_r( L_mult( 13107, pf4[1] ), 19661, pf4[2] ); move16(); /* *pf5++ = 0.6f * pf4[2] + 0.4f * pf4[3]; */ - *pf5++ = mac_r(L_mult(19661, pf4[2]), 13107, pf4[3]); + *pf5++ = mac_r( L_mult( 19661, pf4[2] ), 13107, pf4[3] ); move16(); /* *pf5++ = 0.8f * pf4[3] + 0.2f * pf4[4]; */ - *pf5++ = mac_r(L_mult(26214, pf4[3]), 6554, pf4[4]); + *pf5++ = mac_r( L_mult( 26214, pf4[3] ), 6554, pf4[4] ); move16(); - pf4+=4; + pf4 += 4; } *pf5++ = pf4[0]; move16(); /* *pf5++ = 0.2f * pf4[0] + 0.8f * pf4[1]; */ - *pf5++ = mac_r(L_mult(6554, pf4[0]), 26214, pf4[1]); + *pf5++ = mac_r( L_mult( 6554, pf4[0] ), 26214, pf4[1] ); move16(); /* *pf5++ = 0.4f * pf4[1] + 0.6f * pf4[2]; */ - *pf5++ = mac_r(L_mult(13107, pf4[1]), 19661, pf4[2]); + *pf5++ = mac_r( L_mult( 13107, pf4[1] ), 19661, pf4[2] ); move16(); /* *pf5++ = 0.6f * pf4[2] + 0.4f * pf4[3]; */ - *pf5++ = mac_r(L_mult(19661, pf4[2]), 13107, pf4[3]); + *pf5++ = mac_r( L_mult( 19661, pf4[2] ), 13107, pf4[3] ); move16(); /* *pf5++ = 0.8f * pf4[3] + 0.2f * syn[0]; */ - *pf5++ = mac_r(L_mult(26214, pf4[3]), 6554, syn_fx[0]); + *pf5++ = mac_r( L_mult( 26214, pf4[3] ), 6554, syn_fx[0] ); move16(); /* all samples processed: NBPSF_PIT_MAX = 290 = (58*5) */ @@ -1582,33 +1585,31 @@ void retro_interp4_5_fx( * *-------------------------------------------------------------------*/ -void retro_interp5_4_fx( - Word16 *pst_old_syn_fx -) +void retro_interp5_4_fx( + Word16 *pst_old_syn_fx ) { Word16 *pf5, *pf4; Word16 c; /* resample st->pst_old_syn in a reverse way to preserve time-alignment */ - pf4 = (Word16*) &pst_old_syn_fx[NBPSF_PIT_MAX-1]; + pf4 = (Word16 *) &pst_old_syn_fx[NBPSF_PIT_MAX - 1]; pf5 = pf4; - FOR (c=0; c<58; c++) + FOR( c = 0; c < 58; c++ ) { /* *pf4-- = 0.75f * pf5[0] + 0.25f * pf5[-1]; */ - *pf4-- = mac_r(L_mult(24576, pf5[0]), 8192, pf5[-1]); + *pf4-- = mac_r( L_mult( 24576, pf5[0] ), 8192, pf5[-1] ); move16(); /* *pf4-- = 0.50f * pf5[-1] + 0.50f * pf5[-2]; */ - *pf4-- = mac_r(L_mult(16384, pf5[-1]), 16384, pf5[-2]); + *pf4-- = mac_r( L_mult( 16384, pf5[-1] ), 16384, pf5[-2] ); move16(); /* *pf4-- = 0.25f * pf5[-2] + 0.75f * pf5[-3]; */ - *pf4-- = mac_r(L_mult(8192, pf5[-2]), 24576, pf5[-3]); + *pf4-- = mac_r( L_mult( 8192, pf5[-2] ), 24576, pf5[-3] ); move16(); *pf4-- = pf5[-4]; move16(); - pf5-=5; + pf5 -= 5; } /* all samples processed: NBPSF_PIT_MAX = 290 = (58*5) */ return; } - diff --git a/lib_com/move.h b/lib_com/move.h index adf234ef4..2afeb1ccb 100644 --- a/lib_com/move.h +++ b/lib_com/move.h @@ -39,7 +39,7 @@ #include "stl.h" /* BASOP -> FLC brigde: data move counting */ -#if (WMOPS) +#if ( WMOPS ) extern BASIC_OP multiCounter[MAXCOUNTERS]; extern int currCounter; #endif /* ifdef WMOPS */ @@ -59,9 +59,10 @@ static __inline void move32( void ) } #ifdef ENH_64_BIT_OPERATOR -static __inline void move64(void) { +static __inline void move64( void ) +{ #ifdef WMOPS - multiCounter[currCounter].move64++; + multiCounter[currCounter].move64++; #endif /* if WMOPS */ } #endif /* #ifdef ENH_64_BIT_OPERATOR */ diff --git a/lib_com/mslvq_com.c b/lib_com/mslvq_com.c index d5ae13697..00b77cebf 100644 --- a/lib_com/mslvq_com.c +++ b/lib_com/mslvq_com.c @@ -795,20 +795,20 @@ void sort_desc_ind_32_fx( Word16 i, k, sorted, a; Word32 t; - FOR(i = 0; i < len; i++) + FOR( i = 0; i < len; i++ ) { ind[i] = i; move16(); } sorted = 0; move16(); - FOR(k = len - 1; k && !sorted; k--) + FOR( k = len - 1; k && !sorted; k-- ) { sorted = 1; move16(); - FOR(i = 0; i < k; i++) + FOR( i = 0; i < k; i++ ) { - IF(LT_32(s[i], s[i + 1])) + IF( LT_32( s[i], s[i + 1] ) ) { sorted = 0; move16(); diff --git a/lib_com/mslvq_com_fx.c b/lib_com/mslvq_com_fx.c index 748685130..cad23d0fb 100644 --- a/lib_com/mslvq_com_fx.c +++ b/lib_com/mslvq_com_fx.c @@ -41,31 +41,27 @@ * Local functions *-----------------------------------------------------------------*/ -static void make_offset_scale_fx(Word16 j, const Word32 tab_no_cv[], const Word16 no_ld[], - Word16 no_scl, Word32 offset_scale[][MAX_NO_SCALES + 1]); -static void init_offset_fx(Word32 offset_scale1[][MAX_NO_SCALES + 1], Word32 offset_scale2[][MAX_NO_SCALES + 1], - Word32 offset_scale1_p[][MAX_NO_SCALES + 1], Word32 offset_scale2_p[][MAX_NO_SCALES + 1], - Word16 no_scales[][2], Word16 no_scales_p[][2]); -static void decode_comb_fx(Word32 index, Word16 *cv, Word16 idx_lead); -static void decode_sign_pc1_fx(Word16 *c, Word16 idx_sign, Word16 parity); -static void put_value_fx(Word16 *cv, Word16 *p, Word16 val, Word16 dim, Word16 no_new_val); -static void decode_leaders_fx(Word16 index, Word16 idx_lead, Word16 *cv); -static void idx2c_fx(Word16 n, Word16 *p, Word16 k, Word16 val); -static void divide_64_32_fx(Word16 *xs, Word32 y, Word32 *result, Word32 *rem); +static void make_offset_scale_fx( Word16 j, const Word32 tab_no_cv[], const Word16 no_ld[], Word16 no_scl, Word32 offset_scale[][MAX_NO_SCALES + 1] ); +static void init_offset_fx( Word32 offset_scale1[][MAX_NO_SCALES + 1], Word32 offset_scale2[][MAX_NO_SCALES + 1], Word32 offset_scale1_p[][MAX_NO_SCALES + 1], Word32 offset_scale2_p[][MAX_NO_SCALES + 1], Word16 no_scales[][2], Word16 no_scales_p[][2] ); +static void decode_comb_fx( Word32 index, Word16 *cv, Word16 idx_lead ); +static void decode_sign_pc1_fx( Word16 *c, Word16 idx_sign, Word16 parity ); +static void put_value_fx( Word16 *cv, Word16 *p, Word16 val, Word16 dim, Word16 no_new_val ); +static void decode_leaders_fx( Word16 index, Word16 idx_lead, Word16 *cv ); +static void idx2c_fx( Word16 n, Word16 *p, Word16 k, Word16 val ); +static void divide_64_32_fx( Word16 *xs, Word32 y, Word32 *result, Word32 *rem ); static Word16 -decode_indexes_fx(Word16 * index, Word16 no_bits, const Word16 * p_scales, Word16 * p_no_scales, - Word32 * p_offset_scale1, Word32 * p_offset_scale2, Word16 * x_lvq, Word16 mode_glb, Word16 *scales); +decode_indexes_fx( Word16 *index, Word16 no_bits, const Word16 *p_scales, Word16 *p_no_scales, Word32 *p_offset_scale1, Word32 *p_offset_scale2, Word16 *x_lvq, Word16 mode_glb, Word16 *scales ); static int16_t decode_indexes_ivas_fx( Word16 *index, const Word16 no_bits, - const Word16 *p_scales, //Q11 + const Word16 *p_scales, // Q11 const Word16 prediction_flag, - Word16 *x_lvq, //Q0 + Word16 *x_lvq, // Q0 const Word16 mode_glb, - Word16 * scales_mslvq /* o: scale values for the decoded MSLVQ LSF codevector Q11*/ + Word16 *scales_mslvq /* o: scale values for the decoded MSLVQ LSF codevector Q11*/ ); -static Word32 divide_32_32_fx(Word32 y, Word32 x, Word32 * rem); -static Word16 divide_16_16_fx(Word16 y, Word16 x, Word16 *rem); +static Word32 divide_32_32_fx( Word32 y, Word32 x, Word32 *rem ); +static Word16 divide_16_16_fx( Word16 y, Word16 x, Word16 *rem ); static int16_t decode_indexes_ivas_fx( Word16 *index, const Word16 no_bits, @@ -78,296 +74,295 @@ static int16_t decode_indexes_ivas_fx( /* used in CNG-LP coding */ void permute_fx( - Word16 *pTmp1, /* i/o: vector whose components are to be permuted */ - const Word16 *perm /* i : permutation info (indexes that should be interchanged), max two perms */ + Word16 *pTmp1, /* i/o: vector whose components are to be permuted */ + const Word16 *perm /* i : permutation info (indexes that should be interchanged), max two perms */ ) { - Word16 p1, p2; - Word16 tmp; - - p1 = perm[0]; - move16(); - p2 = perm[1]; - move16(); - tmp = pTmp1[p1]; - move16(); - pTmp1[p1] = pTmp1[p2]; - move16(); - move16(); - pTmp1[p2] = tmp; - move16(); - p1 = perm[2]; - move16(); - - IF(GT_16(p1, -1)) - { - p2 = perm[3]; - move16(); - tmp = pTmp1[p1]; - move16(); - pTmp1[p1] = pTmp1[p2]; - move16(); - move16(); - pTmp1[p2] = tmp; - move16(); - } - - return; + Word16 p1, p2; + Word16 tmp; + + p1 = perm[0]; + move16(); + p2 = perm[1]; + move16(); + tmp = pTmp1[p1]; + move16(); + pTmp1[p1] = pTmp1[p2]; + move16(); + move16(); + pTmp1[p2] = tmp; + move16(); + p1 = perm[2]; + move16(); + + IF( GT_16( p1, -1 ) ) + { + p2 = perm[3]; + move16(); + tmp = pTmp1[p1]; + move16(); + pTmp1[p1] = pTmp1[p2]; + move16(); + move16(); + pTmp1[p2] = tmp; + move16(); + } + + return; } void init_lvq_fx( - Word32 offset_scale1[][MAX_NO_SCALES + 1], /* o: lattice truncation index offset for the first LSF subvector - safety net structures*/ - Word32 offset_scale2[][MAX_NO_SCALES + 1], /* o: lattice truncation index offset for the second LSF subvector - safety net structures*/ - Word32 offset_scale1_p[][MAX_NO_SCALES + 1], /* o: lattice truncation index offset for the first LSF subvector - predictive structures*/ - Word32 offset_scale2_p[][MAX_NO_SCALES + 1], /* o: lattice truncation index offset for the second LSF subvector - predictive structures*/ - Word16 no_scales[][2], /* o: number of truncations for each LSF subvector at each MSLVQ structure - safety net */ - Word16 no_scales_p[][2] /* o: number of truncations for each LSF subvector at each MSLVQ structure - predictive */ + Word32 offset_scale1[][MAX_NO_SCALES + 1], /* o: lattice truncation index offset for the first LSF subvector - safety net structures*/ + Word32 offset_scale2[][MAX_NO_SCALES + 1], /* o: lattice truncation index offset for the second LSF subvector - safety net structures*/ + Word32 offset_scale1_p[][MAX_NO_SCALES + 1], /* o: lattice truncation index offset for the first LSF subvector - predictive structures*/ + Word32 offset_scale2_p[][MAX_NO_SCALES + 1], /* o: lattice truncation index offset for the second LSF subvector - predictive structures*/ + Word16 no_scales[][2], /* o: number of truncations for each LSF subvector at each MSLVQ structure - safety net */ + Word16 no_scales_p[][2] /* o: number of truncations for each LSF subvector at each MSLVQ structure - predictive */ ) { - Word16 i, j; - /* safety-net mode */ - FOR(i = 0; i < MAX_NO_MODES; i++) - { - j = 0; - move16(); - test(); - WHILE((LT_16(j, MAX_NO_SCALES)) && (no_lead_fx[i][j] > 0)) - { - j++; - } - no_scales[i][0] = j; - move16(); - j = MAX_NO_SCALES; - move16(); - test(); - WHILE((LT_16(j, shl(MAX_NO_SCALES, 1))) && (no_lead_fx[i][j] > 0)) - { - j++; - } - no_scales[i][1] = sub(j, MAX_NO_SCALES); - move16(); - } - /* predictive mode */ - FOR(i = 0; i < MAX_NO_MODES_p; i++) - { - j = 0; - move16(); - WHILE((LT_16(j, MAX_NO_SCALES)) && (no_lead_p_fx[i][j] > 0)) - { - j++; - } - no_scales_p[i][0] = j; - move16(); - j = MAX_NO_SCALES; - move16(); - WHILE((LT_16(j, shl(MAX_NO_SCALES, 1))) && (no_lead_p_fx[i][j] > 0)) - { - j++; - } - no_scales_p[i][1] = sub(j, MAX_NO_SCALES); - move16(); - } - /* index offsets for each truncation */ - init_offset_fx(offset_scale1, offset_scale2, offset_scale1_p, offset_scale2_p, no_scales, no_scales_p); + Word16 i, j; + /* safety-net mode */ + FOR( i = 0; i < MAX_NO_MODES; i++ ) + { + j = 0; + move16(); + test(); + WHILE( ( LT_16( j, MAX_NO_SCALES ) ) && ( no_lead_fx[i][j] > 0 ) ) + { + j++; + } + no_scales[i][0] = j; + move16(); + j = MAX_NO_SCALES; + move16(); + test(); + WHILE( ( LT_16( j, shl( MAX_NO_SCALES, 1 ) ) ) && ( no_lead_fx[i][j] > 0 ) ) + { + j++; + } + no_scales[i][1] = sub( j, MAX_NO_SCALES ); + move16(); + } + /* predictive mode */ + FOR( i = 0; i < MAX_NO_MODES_p; i++ ) + { + j = 0; + move16(); + WHILE( ( LT_16( j, MAX_NO_SCALES ) ) && ( no_lead_p_fx[i][j] > 0 ) ) + { + j++; + } + no_scales_p[i][0] = j; + move16(); + j = MAX_NO_SCALES; + move16(); + WHILE( ( LT_16( j, shl( MAX_NO_SCALES, 1 ) ) ) && ( no_lead_p_fx[i][j] > 0 ) ) + { + j++; + } + no_scales_p[i][1] = sub( j, MAX_NO_SCALES ); + move16(); + } + /* index offsets for each truncation */ + init_offset_fx( offset_scale1, offset_scale2, offset_scale1_p, offset_scale2_p, no_scales, no_scales_p ); } /* make_offset_scale_fx() - calculates scale offset values for a particular MSLVQ structure */ -static -void make_offset_scale_fx( - Word16 j, /* i: MSLVQ structure index */ - const Word32 tab_no_cv[], /* i: cummulated number of codevectors in each leader class */ - const Word16 no_ld[], /* i: number of leaders in each truncation for the MSLVQ structure j*/ - Word16 no_scl, /* i: number of truncations in the MSLVQ structure j */ - Word32 offset_scale[][MAX_NO_SCALES + 1]/* o: offset values */ +static void make_offset_scale_fx( + Word16 j, /* i: MSLVQ structure index */ + const Word32 tab_no_cv[], /* i: cummulated number of codevectors in each leader class */ + const Word16 no_ld[], /* i: number of leaders in each truncation for the MSLVQ structure j*/ + Word16 no_scl, /* i: number of truncations in the MSLVQ structure j */ + Word32 offset_scale[][MAX_NO_SCALES + 1] /* o: offset values */ ) { - Word16 i; + Word16 i; - offset_scale[j][0] = L_deposit_l(1); - FOR(i = 1; i <= no_scl; i++) - { - offset_scale[j][i] = L_add(offset_scale[j][sub(i, 1)], tab_no_cv[no_ld[sub(i, 1)]]); - move32(); - } + offset_scale[j][0] = L_deposit_l( 1 ); + FOR( i = 1; i <= no_scl; i++ ) + { + offset_scale[j][i] = L_add( offset_scale[j][sub( i, 1 )], tab_no_cv[no_ld[sub( i, 1 )]] ); + move32(); + } - return; + return; } void init_offset_fx( - Word32 offset_scale1[][MAX_NO_SCALES + 1], /* o: lattice truncation index offset for the first LSF subvector - safety net structures*/ - Word32 offset_scale2[][MAX_NO_SCALES + 1], /* o: lattice truncation index offset for the second LSF subvector - safety net structures*/ - Word32 offset_scale1_p[][MAX_NO_SCALES + 1],/* o: lattice truncation index offset for the first LSF subvector - predictive structures*/ - Word32 offset_scale2_p[][MAX_NO_SCALES + 1],/* o: lattice truncation index offset for the second LSF subvector - predictive structures*/ - Word16 no_scales[][2], /* i: number of truncations for each LSF subvector at each MSLVQ structure - safety net */ - Word16 no_scales_p[][2] /* i: number of truncations for each LSF subvector at each MSLVQ structure - predictive */ + Word32 offset_scale1[][MAX_NO_SCALES + 1], /* o: lattice truncation index offset for the first LSF subvector - safety net structures*/ + Word32 offset_scale2[][MAX_NO_SCALES + 1], /* o: lattice truncation index offset for the second LSF subvector - safety net structures*/ + Word32 offset_scale1_p[][MAX_NO_SCALES + 1], /* o: lattice truncation index offset for the first LSF subvector - predictive structures*/ + Word32 offset_scale2_p[][MAX_NO_SCALES + 1], /* o: lattice truncation index offset for the second LSF subvector - predictive structures*/ + Word16 no_scales[][2], /* i: number of truncations for each LSF subvector at each MSLVQ structure - safety net */ + Word16 no_scales_p[][2] /* i: number of truncations for each LSF subvector at each MSLVQ structure - predictive */ ) { - Word16 j; - /* safety-net */ - FOR(j = 0; j < MAX_NO_MODES; j++) - { - make_offset_scale_fx(j, table_no_cv_fx, no_lead_fx[j], no_scales[j][0], offset_scale1); - make_offset_scale_fx(j, table_no_cv_fx, &no_lead_fx[j][MAX_NO_SCALES], no_scales[j][1], offset_scale2); - } - /* predictive modes AR and MA */ - FOR(j = 0; j < MAX_NO_MODES_p; j++) - { - make_offset_scale_fx(j, table_no_cv_fx, no_lead_p_fx[j], no_scales_p[j][0], offset_scale1_p); - make_offset_scale_fx(j, table_no_cv_fx, &no_lead_p_fx[j][MAX_NO_SCALES], no_scales_p[j][1], offset_scale2_p); - } - - offset_scale1[MAX_NO_MODES][0] = 1; - move32(); - offset_scale2[MAX_NO_MODES][0] = 1; - move32(); - offset_scale1_p[MAX_NO_MODES_p][0] = 1; - move32(); - offset_scale2_p[MAX_NO_MODES_p][0] = 1; - move32(); - - return; + Word16 j; + /* safety-net */ + FOR( j = 0; j < MAX_NO_MODES; j++ ) + { + make_offset_scale_fx( j, table_no_cv_fx, no_lead_fx[j], no_scales[j][0], offset_scale1 ); + make_offset_scale_fx( j, table_no_cv_fx, &no_lead_fx[j][MAX_NO_SCALES], no_scales[j][1], offset_scale2 ); + } + /* predictive modes AR and MA */ + FOR( j = 0; j < MAX_NO_MODES_p; j++ ) + { + make_offset_scale_fx( j, table_no_cv_fx, no_lead_p_fx[j], no_scales_p[j][0], offset_scale1_p ); + make_offset_scale_fx( j, table_no_cv_fx, &no_lead_p_fx[j][MAX_NO_SCALES], no_scales_p[j][1], offset_scale2_p ); + } + + offset_scale1[MAX_NO_MODES][0] = 1; + move32(); + offset_scale2[MAX_NO_MODES][0] = 1; + move32(); + offset_scale1_p[MAX_NO_MODES_p][0] = 1; + move32(); + offset_scale2_p[MAX_NO_MODES_p][0] = 1; + move32(); + + return; } static Word16 decode_indexes_fx( - Word16 * index, /* i: LSF vector index, written as array of Word16 because it generally uses more than 16 bits */ - Word16 no_bits, /* i: number of bits for the index */ - const Word16 * p_scales, /* i: scale values for the MSLVQ structures */ - Word16 * p_no_scales, /* i: number of truncations for each MSLVQ structure */ - Word32 * p_offset_scale1, /* i: scale index offset for first LSF subvector */ - Word32 * p_offset_scale2, /* i: scale index offset for second LSF subvector */ - Word16 * x_lvq, /* o: decoded LSF vector in Q1 */ - Word16 mode_glb, /* i: index of LSLVQ structure */ - //note_ : renamed from scales - Word16 * scales_mslvq /* o: scale values for the decoded MSLVQ LSF codevector */ + Word16 *index, /* i: LSF vector index, written as array of Word16 because it generally uses more than 16 bits */ + Word16 no_bits, /* i: number of bits for the index */ + const Word16 *p_scales, /* i: scale values for the MSLVQ structures */ + Word16 *p_no_scales, /* i: number of truncations for each MSLVQ structure */ + Word32 *p_offset_scale1, /* i: scale index offset for first LSF subvector */ + Word32 *p_offset_scale2, /* i: scale index offset for second LSF subvector */ + Word16 *x_lvq, /* o: decoded LSF vector in Q1 */ + Word16 mode_glb, /* i: index of LSLVQ structure */ + // note_ : renamed from scales + Word16 *scales_mslvq /* o: scale values for the decoded MSLVQ LSF codevector */ ) { - Word32 index1 = 0, index2 = 0; - Word16 len_scales = MAX_NO_SCALES * 2, no_modes; - Word16 i, im1, idx_scale; - Word16 tmp; - - no_modes = MAX_NO_SCALES + 1; - move16(); - - IF(LE_16(no_bits, shl(LEN_INDICE, 1))) /* the third short is not used */ - { - index[2] = 0; - move16(); - if (LE_16(no_bits, LEN_INDICE)) - { - index[1] = 0; - move16(); - } - } - - /* safety check in case of bit errors */ - FOR(i = 0; i < 3; i++) - { - IF(index[i] < 0) - { - set16_fx(x_lvq, 0, 2 * LATTICE_DIM); - scales_mslvq[0] = 0; - scales_mslvq[1] = 0; - index[i] = 0; - return 1; - } - } - - /* first subvector */ - tmp = i_mult2(mode_glb, no_modes); - - IF(p_offset_scale2[add(tmp, p_no_scales[add(shl(mode_glb, 1), 1)])] > 0) - { - divide_64_32_fx(index, p_offset_scale2[tmp + p_no_scales[add(shl(mode_glb, 1), 1)]], &index1, &index2); - } - ELSE - { - index1 = L_deposit_l(index[0]); /* this is for very low bitrates, so there is no loss in truncation */ - index2 = L_deposit_l(0); - } - IF(index1 == 0) - { - FOR(i = 0; i < LATTICE_DIM; i++) - { - x_lvq[i] = 0; - move16(); - } - scales_mslvq[0] = 0; - } - ELSE - { - IF(GE_32(index1, p_offset_scale1[mode_glb*no_modes + p_no_scales[mode_glb * 2]])) - { - /* safety check in case of bit errors */ - set16_fx(x_lvq, 0, 2 * LATTICE_DIM); - scales_mslvq[0] = 0; - scales_mslvq[1] = 0; - return 1; - } - - /* find idx_scale */ - i = 1; - move16(); - WHILE(LE_16(i, p_no_scales[mode_glb * 2]) && GE_32(index1,p_offset_scale1[mode_glb*no_modes + i])) - { - i = add(i,1); - } - idx_scale = sub(i,1); - move16(); - index1 = L_sub(index1, p_offset_scale1[tmp + idx_scale]); - - /* find idx_leader */ - i = 1; - move16(); - - WHILE(GE_32(index1, table_no_cv_fx[i])) - { - i = add(i, 1); - } - im1 = sub(i,1); - decode_comb_fx(L_sub(index1,table_no_cv_fx[im1]), x_lvq, im1); - scales_mslvq[0] = p_scales[mode_glb*len_scales + idx_scale]; - } - - /* second subvector */ - IF(index2 == 0) - { - FOR(i = LATTICE_DIM; i < 2 * LATTICE_DIM; i++) - { - x_lvq[i] = 0; - move16(); - } - scales_mslvq[1] = 0; - move16(); - } - ELSE - { - /* find the index for the scale/truncation */ - i = 1; - move16(); - WHILE(GE_32(index2, p_offset_scale2[tmp + i])) - { - i = add(i, 1); - } - - idx_scale = sub(i,1); - index2 = L_sub(index2, p_offset_scale2[add(tmp,idx_scale)]); - /* find the index of the leader vector */ - i = 1; - move16(); - WHILE(GE_32(index2, table_no_cv_fx[i])) - { - i = add(i, 1); - } - im1 = sub(i,1); - decode_comb_fx(index2 - table_no_cv_fx[im1], &x_lvq[LATTICE_DIM], im1); - scales_mslvq[1] = p_scales[add(i_mult2(mode_glb,len_scales),add(MAX_NO_SCALES,idx_scale))]; - move16(); - } - - return 0; + Word32 index1 = 0, index2 = 0; + Word16 len_scales = MAX_NO_SCALES * 2, no_modes; + Word16 i, im1, idx_scale; + Word16 tmp; + + no_modes = MAX_NO_SCALES + 1; + move16(); + + IF( LE_16( no_bits, shl( LEN_INDICE, 1 ) ) ) /* the third short is not used */ + { + index[2] = 0; + move16(); + if ( LE_16( no_bits, LEN_INDICE ) ) + { + index[1] = 0; + move16(); + } + } + + /* safety check in case of bit errors */ + FOR( i = 0; i < 3; i++ ) + { + IF( index[i] < 0 ) + { + set16_fx( x_lvq, 0, 2 * LATTICE_DIM ); + scales_mslvq[0] = 0; + scales_mslvq[1] = 0; + index[i] = 0; + return 1; + } + } + + /* first subvector */ + tmp = i_mult2( mode_glb, no_modes ); + + IF( p_offset_scale2[add( tmp, p_no_scales[add( shl( mode_glb, 1 ), 1 )] )] > 0 ) + { + divide_64_32_fx( index, p_offset_scale2[tmp + p_no_scales[add( shl( mode_glb, 1 ), 1 )]], &index1, &index2 ); + } + ELSE + { + index1 = L_deposit_l( index[0] ); /* this is for very low bitrates, so there is no loss in truncation */ + index2 = L_deposit_l( 0 ); + } + IF( index1 == 0 ) + { + FOR( i = 0; i < LATTICE_DIM; i++ ) + { + x_lvq[i] = 0; + move16(); + } + scales_mslvq[0] = 0; + } + ELSE + { + IF( GE_32( index1, p_offset_scale1[mode_glb * no_modes + p_no_scales[mode_glb * 2]] ) ) + { + /* safety check in case of bit errors */ + set16_fx( x_lvq, 0, 2 * LATTICE_DIM ); + scales_mslvq[0] = 0; + scales_mslvq[1] = 0; + return 1; + } + + /* find idx_scale */ + i = 1; + move16(); + WHILE( LE_16( i, p_no_scales[mode_glb * 2] ) && GE_32( index1, p_offset_scale1[mode_glb * no_modes + i] ) ) + { + i = add( i, 1 ); + } + idx_scale = sub( i, 1 ); + move16(); + index1 = L_sub( index1, p_offset_scale1[tmp + idx_scale] ); + + /* find idx_leader */ + i = 1; + move16(); + + WHILE( GE_32( index1, table_no_cv_fx[i] ) ) + { + i = add( i, 1 ); + } + im1 = sub( i, 1 ); + decode_comb_fx( L_sub( index1, table_no_cv_fx[im1] ), x_lvq, im1 ); + scales_mslvq[0] = p_scales[mode_glb * len_scales + idx_scale]; + } + + /* second subvector */ + IF( index2 == 0 ) + { + FOR( i = LATTICE_DIM; i < 2 * LATTICE_DIM; i++ ) + { + x_lvq[i] = 0; + move16(); + } + scales_mslvq[1] = 0; + move16(); + } + ELSE + { + /* find the index for the scale/truncation */ + i = 1; + move16(); + WHILE( GE_32( index2, p_offset_scale2[tmp + i] ) ) + { + i = add( i, 1 ); + } + + idx_scale = sub( i, 1 ); + index2 = L_sub( index2, p_offset_scale2[add( tmp, idx_scale )] ); + /* find the index of the leader vector */ + i = 1; + move16(); + WHILE( GE_32( index2, table_no_cv_fx[i] ) ) + { + i = add( i, 1 ); + } + im1 = sub( i, 1 ); + decode_comb_fx( index2 - table_no_cv_fx[im1], &x_lvq[LATTICE_DIM], im1 ); + scales_mslvq[1] = p_scales[add( i_mult2( mode_glb, len_scales ), add( MAX_NO_SCALES, idx_scale ) )]; + move16(); + } + + return 0; } static int16_t decode_indexes_ivas_fx( @@ -530,91 +525,90 @@ static int16_t decode_indexes_ivas_fx( } Word16 deindex_lvq_fx( - Word16 *index, /* i : index to be decoded, as an array of 3 Word16 */ - Word16 *x_lvq, /* o : decoded codevector Q(x2.56) */ - Word16 mode, /* i : LVQ coding mode/MSLVQ structure index (select scales & no_lead ), or idx_cv for CNG case */ - Word16 sf_flag, /* i : safety net flag */ - Word16 no_bits, /* i : number of bits for lattice */ - Word32 *p_offset_scale1, /* i : offset for first subvector */ - Word32 *p_offset_scale2, /* i : offset for the second subvector */ - Word16 *p_no_scales /* i : number of scales for each truncation and each MSLVQ structure */ + Word16 *index, /* i : index to be decoded, as an array of 3 Word16 */ + Word16 *x_lvq, /* o : decoded codevector Q(x2.56) */ + Word16 mode, /* i : LVQ coding mode/MSLVQ structure index (select scales & no_lead ), or idx_cv for CNG case */ + Word16 sf_flag, /* i : safety net flag */ + Word16 no_bits, /* i : number of bits for lattice */ + Word32 *p_offset_scale1, /* i : offset for first subvector */ + Word32 *p_offset_scale2, /* i : offset for the second subvector */ + Word16 *p_no_scales /* i : number of scales for each truncation and each MSLVQ structure */ ) { - Word16 i; - const Word16 * p_scales; - Word16 mode_glb; - Word32 L_tmp; - //note_ : renamed from scales - Word16 scales_mslvq[2]; - Word16 ber_flag; - - IF(EQ_16(sf_flag, 1)) - { - mode_glb = add(offset_lvq_modes_SN_fx[mode], offset_in_lvq_mode_SN_fx[mode][sub(no_bits, min_lat_bits_SN_fx[mode])]); - p_scales = &scales_fx[0][0]; - move16(); - } - ELSE - { - mode_glb = add(offset_lvq_modes_pred_fx[mode], offset_in_lvq_mode_pred_fx[mode][sub(no_bits,min_lat_bits_pred_fx[mode])]); - p_scales = &scales_p_fx[0][0]; - move16(); - } - - /* decode the lattice index into the lattice codevectors for the two subvectors */ - ber_flag = - decode_indexes_fx(index, no_bits, p_scales, p_no_scales, p_offset_scale1, - p_offset_scale2, x_lvq, mode_glb, scales_mslvq); /* x_lvq is here Q1 */ - - - IF(EQ_16(sf_flag, 1)) - { - /* safety-net case*/ - IF(scales_mslvq[0]) - { - FOR(i = 0; i < LATTICE_DIM; i++) - { - L_tmp = L_mult(x_lvq[i], scales_mslvq[0]); /* Q1+Q11+Q1 = Q13 */ - /* Increase calculation accuracy by shifting more to the left and using rounding instead of truncation*/ - L_tmp = L_shl(Mult_32_16(L_tmp, shl(sigma_MSLVQ_fx[mode][i], 3)), 15); /* Q13 + Q2 +x2.56 -Q15 */ - x_lvq[i] = round_fx(L_tmp); - } - } - IF(scales_mslvq[1]) - { - FOR(i = LATTICE_DIM; i < 2 * LATTICE_DIM; i++) - { - L_tmp = L_mult(x_lvq[i], scales_mslvq[1]); /* Q1+Q11+Q1 = Q13 */ - L_tmp = L_shl(Mult_32_16(L_tmp, shl(sigma_MSLVQ_fx[mode][i], 3)), 15); /* Q13 + Q2 +x2.56 -Q15 */ - x_lvq[i] = round_fx(L_tmp); - } - } - } - ELSE - { - /* predictive mode AR or MA */ - IF(scales_mslvq[0]) - { - FOR(i = 0; i < LATTICE_DIM; i++) - { - L_tmp = L_mult(x_lvq[i],scales_mslvq[0]); /* Q1+Q11+Q1 = Q13 */ - L_tmp = L_shl(Mult_32_16(L_tmp,shl(sigma_p_fx[mode][i],3)),15); /* Q13 + Q2 +x2.56 -Q15 */ - x_lvq[i] = round_fx(L_tmp); - - } - } - IF(scales_mslvq[1]) - { - FOR(i = LATTICE_DIM; i < 2 * LATTICE_DIM; i++) - { - L_tmp = L_mult(x_lvq[i],scales_mslvq[1]); /* Q1+Q11+Q1 = Q13 */ - L_tmp = L_shl(Mult_32_16(L_tmp,shl(sigma_p_fx[mode][i],3)),15); /* Q13 + Q2 +x2.56 -Q15 */ - x_lvq[i] = round_fx(L_tmp); - } - } - } - - return ber_flag; + Word16 i; + const Word16 *p_scales; + Word16 mode_glb; + Word32 L_tmp; + // note_ : renamed from scales + Word16 scales_mslvq[2]; + Word16 ber_flag; + + IF( EQ_16( sf_flag, 1 ) ) + { + mode_glb = add( offset_lvq_modes_SN_fx[mode], offset_in_lvq_mode_SN_fx[mode][sub( no_bits, min_lat_bits_SN_fx[mode] )] ); + p_scales = &scales_fx[0][0]; + move16(); + } + ELSE + { + mode_glb = add( offset_lvq_modes_pred_fx[mode], offset_in_lvq_mode_pred_fx[mode][sub( no_bits, min_lat_bits_pred_fx[mode] )] ); + p_scales = &scales_p_fx[0][0]; + move16(); + } + + /* decode the lattice index into the lattice codevectors for the two subvectors */ + ber_flag = + decode_indexes_fx( index, no_bits, p_scales, p_no_scales, p_offset_scale1, + p_offset_scale2, x_lvq, mode_glb, scales_mslvq ); /* x_lvq is here Q1 */ + + + IF( EQ_16( sf_flag, 1 ) ) + { + /* safety-net case*/ + IF( scales_mslvq[0] ) + { + FOR( i = 0; i < LATTICE_DIM; i++ ) + { + L_tmp = L_mult( x_lvq[i], scales_mslvq[0] ); /* Q1+Q11+Q1 = Q13 */ + /* Increase calculation accuracy by shifting more to the left and using rounding instead of truncation*/ + L_tmp = L_shl( Mult_32_16( L_tmp, shl( sigma_MSLVQ_fx[mode][i], 3 ) ), 15 ); /* Q13 + Q2 +x2.56 -Q15 */ + x_lvq[i] = round_fx( L_tmp ); + } + } + IF( scales_mslvq[1] ) + { + FOR( i = LATTICE_DIM; i < 2 * LATTICE_DIM; i++ ) + { + L_tmp = L_mult( x_lvq[i], scales_mslvq[1] ); /* Q1+Q11+Q1 = Q13 */ + L_tmp = L_shl( Mult_32_16( L_tmp, shl( sigma_MSLVQ_fx[mode][i], 3 ) ), 15 ); /* Q13 + Q2 +x2.56 -Q15 */ + x_lvq[i] = round_fx( L_tmp ); + } + } + } + ELSE + { + /* predictive mode AR or MA */ + IF( scales_mslvq[0] ) + { + FOR( i = 0; i < LATTICE_DIM; i++ ) + { + L_tmp = L_mult( x_lvq[i], scales_mslvq[0] ); /* Q1+Q11+Q1 = Q13 */ + L_tmp = L_shl( Mult_32_16( L_tmp, shl( sigma_p_fx[mode][i], 3 ) ), 15 ); /* Q13 + Q2 +x2.56 -Q15 */ + x_lvq[i] = round_fx( L_tmp ); + } + } + IF( scales_mslvq[1] ) + { + FOR( i = LATTICE_DIM; i < 2 * LATTICE_DIM; i++ ) + { + L_tmp = L_mult( x_lvq[i], scales_mslvq[1] ); /* Q1+Q11+Q1 = Q13 */ + L_tmp = L_shl( Mult_32_16( L_tmp, shl( sigma_p_fx[mode][i], 3 ) ), 15 ); /* Q13 + Q2 +x2.56 -Q15 */ + x_lvq[i] = round_fx( L_tmp ); + } + } + } + + return ber_flag; } Word16 deindex_lvq_ivas_fx( @@ -703,7 +697,7 @@ Word16 deindex_lvq_ivas_fx( { FOR( i = 0; i < LATTICE_DIM; i++ ) { - L_tmp = L_mult( x_lvq[i], scales_mslvq[0] ); /* Q1+Q11+Q1 = Q13 */ + L_tmp = L_mult( x_lvq[i], scales_mslvq[0] ); /* Q1+Q11+Q1 = Q13 */ L_tmp = L_shl( Mult_32_16( L_tmp, shl( sigma_p_ivas_fx[mode][i], 3 ) ), 15 ); /* Q13 + Q2 +x2.56 -Q15 */ x_lvq[i] = round_fx( L_tmp ); } @@ -712,7 +706,7 @@ Word16 deindex_lvq_ivas_fx( { FOR( i = LATTICE_DIM; i < 2 * LATTICE_DIM; i++ ) { - L_tmp = L_mult( x_lvq[i], scales_mslvq[1] ); /* Q1+Q11+Q1 = Q13 */ + L_tmp = L_mult( x_lvq[i], scales_mslvq[1] ); /* Q1+Q11+Q1 = Q13 */ L_tmp = L_shl( Mult_32_16( L_tmp, shl( sigma_p_ivas_fx[mode][i], 3 ) ), 15 ); /* Q13 + Q2 +x2.56 -Q15 */ x_lvq[i] = round_fx( L_tmp ); } @@ -731,53 +725,53 @@ Word16 deindex_lvq_ivas_fx( *----------------------------------------------------------------------------------------------------*/ Word16 deindex_lvq_cng_fx( - Word16 *index, /* i: index to be decoded, as an array of 3 short */ - Word16 *x_lvq, /* o: decoded codevector Q9 */ - Word16 idx_cv, /* i: relative mode_lvq, wrt START_CNG */ - Word16 no_bits, /* i: number of bits for lattice */ - Word32 * p_offset_scale1, /* i: scale index offset for first LSF subvector */ - Word32 * p_offset_scale2, /* i: scale index offset for second LSF subvector */ - Word16 * p_no_scales /* i: number of scales for each MSLVQ structure and each subvector */ + Word16 *index, /* i: index to be decoded, as an array of 3 short */ + Word16 *x_lvq, /* o: decoded codevector Q9 */ + Word16 idx_cv, /* i: relative mode_lvq, wrt START_CNG */ + Word16 no_bits, /* i: number of bits for lattice */ + Word32 *p_offset_scale1, /* i: scale index offset for first LSF subvector */ + Word32 *p_offset_scale2, /* i: scale index offset for second LSF subvector */ + Word16 *p_no_scales /* i: number of scales for each MSLVQ structure and each subvector */ ) { - Word16 i; - Word32 L_tmp; - const Word16 *p_scales; - Word16 mode_glb, mode; - //note_ : renamed from scales as global declaration of scales is causing warning - Word16 scales_mslvq[2]; - Word16 ber_flag; - - /* the MSLVQ structure in the second LP-CNG stage depends on the index from the first stage */ - mode_glb = add(START_CNG, idx_cv); - - mode = add(LVQ_COD_MODES, idx_cv); - - p_scales = &scales_fx[0][0]; - move16(); - ber_flag = - decode_indexes_fx(index, no_bits, p_scales, p_no_scales, p_offset_scale1, p_offset_scale2, x_lvq, mode_glb, scales_mslvq); - - FOR(i = 0; i < LATTICE_DIM; i++) - { - L_tmp = L_mult(x_lvq[i], scales_mslvq[0]); /* Q1+Q11+Q1 = Q13 */ - L_tmp = L_shl(Mult_32_16(L_tmp, shl(sigma_MSLVQ_fx[mode][i], 3)), 15); /* Q13 + Q2 +x2.56 -Q15 */ - x_lvq[i] = round_fx(L_tmp); - } - FOR(i = LATTICE_DIM; i < 2 * LATTICE_DIM; i++) - { - L_tmp = L_mult(x_lvq[i], scales_mslvq[1]); /* Q1+Q11+Q1 = Q13 */ - L_tmp = L_shl(Mult_32_16(L_tmp, shl(sigma_MSLVQ_fx[mode][i], 3)), 15); /* Q13 + Q2 +x2.56 -Q15 */ - x_lvq[i] = round_fx(L_tmp); - } - - /* check if permutting needed */ - IF(cng_sort[idx_cv]) - { - permute_fx(x_lvq, perm_MSLVQ[idx_cv]); - } - - return ber_flag; + Word16 i; + Word32 L_tmp; + const Word16 *p_scales; + Word16 mode_glb, mode; + // note_ : renamed from scales as global declaration of scales is causing warning + Word16 scales_mslvq[2]; + Word16 ber_flag; + + /* the MSLVQ structure in the second LP-CNG stage depends on the index from the first stage */ + mode_glb = add( START_CNG, idx_cv ); + + mode = add( LVQ_COD_MODES, idx_cv ); + + p_scales = &scales_fx[0][0]; + move16(); + ber_flag = + decode_indexes_fx( index, no_bits, p_scales, p_no_scales, p_offset_scale1, p_offset_scale2, x_lvq, mode_glb, scales_mslvq ); + + FOR( i = 0; i < LATTICE_DIM; i++ ) + { + L_tmp = L_mult( x_lvq[i], scales_mslvq[0] ); /* Q1+Q11+Q1 = Q13 */ + L_tmp = L_shl( Mult_32_16( L_tmp, shl( sigma_MSLVQ_fx[mode][i], 3 ) ), 15 ); /* Q13 + Q2 +x2.56 -Q15 */ + x_lvq[i] = round_fx( L_tmp ); + } + FOR( i = LATTICE_DIM; i < 2 * LATTICE_DIM; i++ ) + { + L_tmp = L_mult( x_lvq[i], scales_mslvq[1] ); /* Q1+Q11+Q1 = Q13 */ + L_tmp = L_shl( Mult_32_16( L_tmp, shl( sigma_MSLVQ_fx[mode][i], 3 ) ), 15 ); /* Q13 + Q2 +x2.56 -Q15 */ + x_lvq[i] = round_fx( L_tmp ); + } + + /* check if permutting needed */ + IF( cng_sort[idx_cv] ) + { + permute_fx( x_lvq, perm_MSLVQ[idx_cv] ); + } + + return ber_flag; } @@ -790,49 +784,49 @@ Word16 deindex_lvq_cng_fx( *----------------------------------------------------------------------------------------------------*/ Word16 deindex_lvq_cng_ivas_fx( - Word16 *index, /* i: index to be decoded, as an array of 3 short */ - Word16 *x_lvq, /* o: decoded codevector Q9 */ - Word16 idx_cv, /* i: relative mode_lvq, wrt START_CNG */ - Word16 no_bits /* i: number of bits for lattice */ + Word16 *index, /* i: index to be decoded, as an array of 3 short */ + Word16 *x_lvq, /* o: decoded codevector Q9 */ + Word16 idx_cv, /* i: relative mode_lvq, wrt START_CNG */ + Word16 no_bits /* i: number of bits for lattice */ ) { Word16 i; Word32 L_tmp; const Word16 *p_scales; Word16 mode_glb, mode; - //note_ : renamed from scales as global declaration of scales is causing warning + // note_ : renamed from scales as global declaration of scales is causing warning Word16 scales_mslvq[2]; Word16 ber_flag; /* the MSLVQ structure in the second LP-CNG stage depends on the index from the first stage */ - mode_glb = add(START_CNG_IVAS, idx_cv); + mode_glb = add( START_CNG_IVAS, idx_cv ); - mode = add(LVQ_COD_MODES, idx_cv); + mode = add( LVQ_COD_MODES, idx_cv ); p_scales = &scales_ivas_fx[0][0]; move16(); - //ber_flag = - // decode_indexes_fx(index, no_bits, p_scales, p_no_scales, p_offset_scale1, p_offset_scale2, x_lvq, mode_glb, scales_mslvq); + // ber_flag = + // decode_indexes_fx(index, no_bits, p_scales, p_no_scales, p_offset_scale1, p_offset_scale2, x_lvq, mode_glb, scales_mslvq); ber_flag = - decode_indexes_ivas_fx(index, no_bits, p_scales, 0, x_lvq, mode_glb, scales_mslvq); + decode_indexes_ivas_fx( index, no_bits, p_scales, 0, x_lvq, mode_glb, scales_mslvq ); - FOR(i = 0; i < LATTICE_DIM; i++) + FOR( i = 0; i < LATTICE_DIM; i++ ) { - L_tmp = L_mult(x_lvq[i], scales_mslvq[0]); /* Q1+Q11+Q1 = Q13 */ - L_tmp = L_shl(Mult_32_16(L_tmp, shl(sigma_MSLVQ_fx[mode][i], 3)), 15); /* Q13 + Q2 +x2.56 -Q15 */ - x_lvq[i] = round_fx(L_tmp); + L_tmp = L_mult( x_lvq[i], scales_mslvq[0] ); /* Q1+Q11+Q1 = Q13 */ + L_tmp = L_shl( Mult_32_16( L_tmp, shl( sigma_MSLVQ_fx[mode][i], 3 ) ), 15 ); /* Q13 + Q2 +x2.56 -Q15 */ + x_lvq[i] = round_fx( L_tmp ); } - FOR(i = LATTICE_DIM; i < 2 * LATTICE_DIM; i++) + FOR( i = LATTICE_DIM; i < 2 * LATTICE_DIM; i++ ) { - L_tmp = L_mult(x_lvq[i], scales_mslvq[1]); /* Q1+Q11+Q1 = Q13 */ - L_tmp = L_shl(Mult_32_16(L_tmp, shl(sigma_MSLVQ_fx[mode][i], 3)), 15); /* Q13 + Q2 +x2.56 -Q15 */ - x_lvq[i] = round_fx(L_tmp); + L_tmp = L_mult( x_lvq[i], scales_mslvq[1] ); /* Q1+Q11+Q1 = Q13 */ + L_tmp = L_shl( Mult_32_16( L_tmp, shl( sigma_MSLVQ_fx[mode][i], 3 ) ), 15 ); /* Q13 + Q2 +x2.56 -Q15 */ + x_lvq[i] = round_fx( L_tmp ); } /* check if permutting needed */ - IF(cng_sort[idx_cv]) + IF( cng_sort[idx_cv] ) { - permute_fx(x_lvq, perm_MSLVQ[idx_cv]); + permute_fx( x_lvq, perm_MSLVQ[idx_cv] ); } return ber_flag; @@ -840,392 +834,392 @@ Word16 deindex_lvq_cng_ivas_fx( /* combinatorial indexing */ static void idx2c_fx( - Word16 n, /* i : total number of positions (components)*/ - Word16 *p, /* o : array with positions of the k components */ - Word16 k, /* i : number of components whose position is to be determined */ - Word16 val /* i : index to be decoded */ + Word16 n, /* i : total number of positions (components)*/ + Word16 *p, /* o : array with positions of the k components */ + Word16 k, /* i : number of components whose position is to be determined */ + Word16 val /* i : index to be decoded */ ) { - Word16 i, skip, pos, k1; - - skip = 0; - move16(); - pos = 0; - move16(); - k1 = sub(k, 1); - move16(); - WHILE(LT_16(add(skip, sub(C_VQ[n - pos - 1][k1], 1)), val)) - { - skip = add(skip, C_VQ[n - pos - 1][k1]); - move16(); - pos++; - move16(); - } - - p[0] = pos; - move16(); - n = sub(n, add(pos, 1)); - val = sub(val, skip); - IF(EQ_16(k, 1)) - { - return; - } - - idx2c_fx(n, p + 1, k1, val); - - /* pos+1 */ - FOR(i = 1; i < k; i++) - { - p[i] = add(p[i], add(pos, 1)); - move16(); - } - - return; + Word16 i, skip, pos, k1; + + skip = 0; + move16(); + pos = 0; + move16(); + k1 = sub( k, 1 ); + move16(); + WHILE( LT_16( add( skip, sub( C_VQ[n - pos - 1][k1], 1 ) ), val ) ) + { + skip = add( skip, C_VQ[n - pos - 1][k1] ); + move16(); + pos++; + move16(); + } + + p[0] = pos; + move16(); + n = sub( n, add( pos, 1 ) ); + val = sub( val, skip ); + IF( EQ_16( k, 1 ) ) + { + return; + } + + idx2c_fx( n, p + 1, k1, val ); + + /* pos+1 */ + FOR( i = 1; i < k; i++ ) + { + p[i] = add( p[i], add( pos, 1 ) ); + move16(); + } + + return; } /* combinatorial deindexing */ static void decode_comb_fx( - Word32 index, /* i : index to be decoded */ - Word16 *cv, /* o : decoded codevector Q1*/ - Word16 idx_lead /* i : leader class index */ + Word32 index, /* i : index to be decoded */ + Word16 *cv, /* o : decoded codevector Q1*/ + Word16 idx_lead /* i : leader class index */ ) { - Word16 idx_sign; + Word16 idx_sign; - idx_sign = extract_l(div_l(L_shl(index, 1), pi0[idx_lead])); /*(index/pi0_fx[idx_lead]); */ - index = L_sub(index, L_mult0(idx_sign, pi0[idx_lead])); - decode_leaders_fx(extract_l(index), idx_lead, cv); - decode_sign_pc1_fx(cv, idx_sign, pl_par[idx_lead]); + idx_sign = extract_l( div_l( L_shl( index, 1 ), pi0[idx_lead] ) ); /*(index/pi0_fx[idx_lead]); */ + index = L_sub( index, L_mult0( idx_sign, pi0[idx_lead] ) ); + decode_leaders_fx( extract_l( index ), idx_lead, cv ); + decode_sign_pc1_fx( cv, idx_sign, pl_par[idx_lead] ); - return; + return; } void decode_sign_pc1_fx( - Word16 *c, /* o : decoded codevector Q1*/ - Word16 idx_sign, /* i : sign index */ - Word16 parity /* i : parity flag (+1/-1/0) */ + Word16 *c, /* o : decoded codevector Q1*/ + Word16 idx_sign, /* i : sign index */ + Word16 parity /* i : parity flag (+1/-1/0) */ ) { - Word16 i, len = LATTICE_DIM, cnt_neg = 1; - - if (parity) - { - len = sub(len, 1); - } - - FOR(i = 0; i < len; i++) - { - IF(c[i] > 0) - { - /*if (idx_sign % 2) */ - IF(s_and(idx_sign, 1)) - { - c[i] = negate(c[i]); - move16(); - cnt_neg = negate(cnt_neg); - move16(); - } - idx_sign = shr(idx_sign, 1); /* >>= 1; */ - } - } - - IF(LT_16(len, LATTICE_DIM)) - { - IF(NE_16(cnt_neg, parity)) - { - c[len] = negate(c[len]); - move16(); - } - } - - return; + Word16 i, len = LATTICE_DIM, cnt_neg = 1; + + if ( parity ) + { + len = sub( len, 1 ); + } + + FOR( i = 0; i < len; i++ ) + { + IF( c[i] > 0 ) + { + /*if (idx_sign % 2) */ + IF( s_and( idx_sign, 1 ) ) + { + c[i] = negate( c[i] ); + move16(); + cnt_neg = negate( cnt_neg ); + move16(); + } + idx_sign = shr( idx_sign, 1 ); /* >>= 1; */ + } + } + + IF( LT_16( len, LATTICE_DIM ) ) + { + IF( NE_16( cnt_neg, parity ) ) + { + c[len] = negate( c[len] ); + move16(); + } + } + + return; } static void decode_leaders_fx( - Word16 index, /* i : index to be decoded */ - Word16 idx_lead, /* i : leader class index */ - Word16 *cv /* o : decoded codevector Q1*/ + Word16 index, /* i : index to be decoded */ + Word16 idx_lead, /* i : leader class index */ + Word16 *cv /* o : decoded codevector Q1*/ ) { - Word16 i, no_vals_loc, no_vals_last, p[LATTICE_DIM], dim_loc, n_crt; - Word16 index1; - Word16 val_crt; - - no_vals_loc = no_vals[idx_lead]; - move16(); - val_crt = vals_fx[idx_lead][no_vals_loc - 1]; - move16(); /*Q1 */ - no_vals_last = no_vals_ind[idx_lead][no_vals_loc - 1]; - move16(); - - FOR(i = 0; i < no_vals_last; i++) - { - cv[i] = val_crt; - move16(); /*Q1 */ - } - - val_crt = 1; - move16(); - dim_loc = no_vals_last; - move16(); - - SWITCH(no_vals_loc) - { - case 1: - BREAK; - case 2: - idx2c_fx(LATTICE_DIM, p, no_vals_ind[idx_lead][0], index); - put_value_fx(cv, p, vals_fx[idx_lead][0], no_vals_last, no_vals_ind[idx_lead][0]); - BREAK; - case 4: - dim_loc = add(dim_loc, no_vals_ind[idx_lead][2]); - n_crt = no_vals_ind[idx_lead][2]; - index1 = divide_16_16_fx(index, C_VQ[dim_loc][n_crt], &index); /* index1 = index/C_VQ_fx[dim_loc][n_crt]; */ - /*index = sub(index, i_mult2(index1, C_VQ_fx[dim_loc][n_crt]) ); */ /* index-= index1*C_VQ_fx[dim_loc][n_crt]; */ move16(); - idx2c_fx(dim_loc, p, n_crt, index); - put_value_fx(cv, p, vals_fx[idx_lead][2], no_vals_last, no_vals_ind[idx_lead][2]); /* Q1 */ - index = index1; - move16(); - /* no break */ - case 3: - dim_loc = add(dim_loc, no_vals_ind[idx_lead][1]); - n_crt = no_vals_ind[idx_lead][1]; - move16(); - index1 = divide_16_16_fx(index, C_VQ[dim_loc][n_crt], &index); - /*index = sub(index, i_mult2(index1, C_VQ_fx[dim_loc][n_crt]));move16(); */ - idx2c_fx(dim_loc, p, n_crt, index); - put_value_fx(cv, p, vals_fx[idx_lead][1], sub(dim_loc, n_crt), n_crt); - idx2c_fx(LATTICE_DIM, p, no_vals_ind[idx_lead][0], index1); - move16(); - put_value_fx(cv, p, vals_fx[idx_lead][0], dim_loc, no_vals_ind[idx_lead][0]); - BREAK; - } - - return; + Word16 i, no_vals_loc, no_vals_last, p[LATTICE_DIM], dim_loc, n_crt; + Word16 index1; + Word16 val_crt; + + no_vals_loc = no_vals[idx_lead]; + move16(); + val_crt = vals_fx[idx_lead][no_vals_loc - 1]; + move16(); /*Q1 */ + no_vals_last = no_vals_ind[idx_lead][no_vals_loc - 1]; + move16(); + + FOR( i = 0; i < no_vals_last; i++ ) + { + cv[i] = val_crt; + move16(); /*Q1 */ + } + + val_crt = 1; + move16(); + dim_loc = no_vals_last; + move16(); + + SWITCH( no_vals_loc ) + { + case 1: + BREAK; + case 2: + idx2c_fx( LATTICE_DIM, p, no_vals_ind[idx_lead][0], index ); + put_value_fx( cv, p, vals_fx[idx_lead][0], no_vals_last, no_vals_ind[idx_lead][0] ); + BREAK; + case 4: + dim_loc = add( dim_loc, no_vals_ind[idx_lead][2] ); + n_crt = no_vals_ind[idx_lead][2]; + index1 = divide_16_16_fx( index, C_VQ[dim_loc][n_crt], &index ); /* index1 = index/C_VQ_fx[dim_loc][n_crt]; */ + /*index = sub(index, i_mult2(index1, C_VQ_fx[dim_loc][n_crt]) ); */ /* index-= index1*C_VQ_fx[dim_loc][n_crt]; */ move16(); + idx2c_fx( dim_loc, p, n_crt, index ); + put_value_fx( cv, p, vals_fx[idx_lead][2], no_vals_last, no_vals_ind[idx_lead][2] ); /* Q1 */ + index = index1; + move16(); + /* no break */ + case 3: + dim_loc = add( dim_loc, no_vals_ind[idx_lead][1] ); + n_crt = no_vals_ind[idx_lead][1]; + move16(); + index1 = divide_16_16_fx( index, C_VQ[dim_loc][n_crt], &index ); + /*index = sub(index, i_mult2(index1, C_VQ_fx[dim_loc][n_crt]));move16(); */ + idx2c_fx( dim_loc, p, n_crt, index ); + put_value_fx( cv, p, vals_fx[idx_lead][1], sub( dim_loc, n_crt ), n_crt ); + idx2c_fx( LATTICE_DIM, p, no_vals_ind[idx_lead][0], index1 ); + move16(); + put_value_fx( cv, p, vals_fx[idx_lead][0], dim_loc, no_vals_ind[idx_lead][0] ); + BREAK; + } + + return; } /* divide_32_32_fx() :Division reminder - rem is the reminder of the division between y and x. */ -static Word32 divide_32_32_fx(Word32 y, /* i */ - Word32 x, /* i */ - Word32 *rem /* o */ +static Word32 divide_32_32_fx( Word32 y, /* i */ + Word32 x, /* i */ + Word32 *rem /* o */ ) { - Word32 result, t, L_tmp; - Word16 i, ny, nx, nyx; - - - IF(LT_32(y, x)) - { - result = L_deposit_l(0); - *rem = y; - move32(); - } - ELSE - { - - result = L_deposit_l(0); - IF(y == 0) - { - ny = 0; - move16(); - } - ELSE - { - ny = sub(31, norm_l(y)); - } - IF(x == 0) - { - nx = 0; - move16(); - } - ELSE - { - nx = sub(31, norm_l(x)); - } - - nyx = sub(ny,nx); - - /*t = L_and(L_shr(y, add(nyx,1)),sub(shl(1,sub(nx,1)),1)); */ - t = L_shr(y,add(nyx,1)); - FOR(i = 0; i <= nyx; i++) - { - t = L_add(L_shl(t,1), L_and(L_shr(y,sub(nyx,i)),1)); /* L_and(y,L_shl(1, sub(nyx,i)))); */ - result = L_shl(result,1); - L_tmp = L_sub(t,x); - IF(L_tmp >= 0) - { - result = L_add(result,1); - t = L_add(L_tmp, 0); - } - } - *rem = t; - move32(); - } - return result; + Word32 result, t, L_tmp; + Word16 i, ny, nx, nyx; + + + IF( LT_32( y, x ) ) + { + result = L_deposit_l( 0 ); + *rem = y; + move32(); + } + ELSE + { + + result = L_deposit_l( 0 ); + IF( y == 0 ) + { + ny = 0; + move16(); + } + ELSE + { + ny = sub( 31, norm_l( y ) ); + } + IF( x == 0 ) + { + nx = 0; + move16(); + } + ELSE + { + nx = sub( 31, norm_l( x ) ); + } + + nyx = sub( ny, nx ); + + /*t = L_and(L_shr(y, add(nyx,1)),sub(shl(1,sub(nx,1)),1)); */ + t = L_shr( y, add( nyx, 1 ) ); + FOR( i = 0; i <= nyx; i++ ) + { + t = L_add( L_shl( t, 1 ), L_and( L_shr( y, sub( nyx, i ) ), 1 ) ); /* L_and(y,L_shl(1, sub(nyx,i)))); */ + result = L_shl( result, 1 ); + L_tmp = L_sub( t, x ); + IF( L_tmp >= 0 ) + { + result = L_add( result, 1 ); + t = L_add( L_tmp, 0 ); + } + } + *rem = t; + move32(); + } + return result; } /* divide_32_32_fx() :Division reminder for Word16 - rem is the reminder of the division between y and x. */ -static Word16 divide_16_16_fx(Word16 y, /* i */ - Word16 x, /* i */ - Word16 *rem /* o */ +static Word16 divide_16_16_fx( Word16 y, /* i */ + Word16 x, /* i */ + Word16 *rem /* o */ ) { - Word16 result, t, tmp; - Word16 i, ny, nx, nyx; - - - IF(LT_32(y, x)) - { - result = 0; - move16(); - *rem = y; - move16(); - } - ELSE - { - - result = 0; - move16(); - IF(y == 0) - { - ny = 0; - move16(); - } - ELSE - { - ny = sub(15, norm_s(y)); - } - IF(x == 0) - { - nx = 0; - move16(); - } - ELSE - { - nx = sub(15, norm_s(x)); - } - - nyx = sub(ny,nx); - - t = s_and(shr(y, add(nyx,1)),sub(shl(1,sub(nx,1)),1)); - FOR(i = 0; i <= nyx; i++) - { - t = add(shl(t,1), s_and(shr(y,sub(nyx,i)),1)); /* L_and(y,L_shl(1, sub(nyx,i)))); */ - result = shl(result,1); - tmp = sub(t,x); - IF(tmp >= 0) - { - result = add(result,1); - t = tmp; - move16(); - } - } - *rem = t; - move16(); - } - return result; + Word16 result, t, tmp; + Word16 i, ny, nx, nyx; + + + IF( LT_32( y, x ) ) + { + result = 0; + move16(); + *rem = y; + move16(); + } + ELSE + { + + result = 0; + move16(); + IF( y == 0 ) + { + ny = 0; + move16(); + } + ELSE + { + ny = sub( 15, norm_s( y ) ); + } + IF( x == 0 ) + { + nx = 0; + move16(); + } + ELSE + { + nx = sub( 15, norm_s( x ) ); + } + + nyx = sub( ny, nx ); + + t = s_and( shr( y, add( nyx, 1 ) ), sub( shl( 1, sub( nx, 1 ) ), 1 ) ); + FOR( i = 0; i <= nyx; i++ ) + { + t = add( shl( t, 1 ), s_and( shr( y, sub( nyx, i ) ), 1 ) ); /* L_and(y,L_shl(1, sub(nyx,i)))); */ + result = shl( result, 1 ); + tmp = sub( t, x ); + IF( tmp >= 0 ) + { + result = add( result, 1 ); + t = tmp; + move16(); + } + } + *rem = t; + move16(); + } + return result; } static void divide_64_32_fx( - Word16 *xs, /* i : denominator as array of two int32 */ - Word32 y, /* i : nominator on 32 bits */ - Word32 *result, /* o : integer division result on 32 bits */ - Word32 *rem /* o : integer division reminder on 32 bits */ + Word16 *xs, /* i : denominator as array of two int32 */ + Word32 y, /* i : nominator on 32 bits */ + Word32 *result, /* o : integer division result on 32 bits */ + Word32 *rem /* o : integer division reminder on 32 bits */ ) { - Word16 nb_x1; - Word32 r, x_tmp, x[2], q, q1; - - x[0] = L_add(L_add(L_shl(L_deposit_l(s_and(xs[2], 1)), 2 * LEN_INDICE), L_shl(L_deposit_l(xs[1]), LEN_INDICE)), L_deposit_l(xs[0])); - move32(); - x[1] = L_shr(L_deposit_l(xs[2]), 1); - move32(); - - /*x[0] = (((xs[2])&(1)<<(LEN_INDICE*2)) + (xs[1]<>1; */ - - IF(x[1] == 0) - { - nb_x1 = 0; - move16(); - } - ELSE - { - nb_x1 = sub(31, norm_l(x[1])); /*get_no_bits_fx(x[1]); */ - } - /* take the first 31 bits */ - IF(nb_x1 > 0) - { - x_tmp = L_add(L_shl(x[1], sub(31, nb_x1)), L_shr(x[0], nb_x1)); - /* x_tmp = (x[1]<<(32-nb_x1)) + (x[0]>>nb_x1); */ - - q = divide_32_32_fx(x_tmp, y, &r); /* q = x_tmp/y, reminder r */ - r = L_add(L_shl(r, nb_x1), L_and(x[0], L_deposit_l(sub(shl(1, nb_x1), 1)))); /* this is the first reminder */ - /* r = (r<>1; */ + + IF( x[1] == 0 ) + { + nb_x1 = 0; + move16(); + } + ELSE + { + nb_x1 = sub( 31, norm_l( x[1] ) ); /*get_no_bits_fx(x[1]); */ + } + /* take the first 31 bits */ + IF( nb_x1 > 0 ) + { + x_tmp = L_add( L_shl( x[1], sub( 31, nb_x1 ) ), L_shr( x[0], nb_x1 ) ); + /* x_tmp = (x[1]<<(32-nb_x1)) + (x[0]>>nb_x1); */ + + q = divide_32_32_fx( x_tmp, y, &r ); /* q = x_tmp/y, reminder r */ + r = L_add( L_shl( r, nb_x1 ), L_and( x[0], L_deposit_l( sub( shl( 1, nb_x1 ), 1 ) ) ) ); /* this is the first reminder */ + /* r = (r<= offsets[idx_scale]) + WHILE( (Word16) i <= MAX_NO_SCALES && index >= offsets[idx_scale] ) { idx_scale++; } @@ -1270,21 +1264,21 @@ void deindex_lvq_SHB_fx( /* find idx_leader */ i = 1; - WHILE (index > table_no_cv[i]) + WHILE( index > table_no_cv[i] ) { i++; } i = i - 1; - decode_comb_fx((Word32)(index - table_no_cv[i] - 1), out, i); + decode_comb_fx( (Word32) ( index - table_no_cv[i] - 1 ), out, i ); scale = p_scales[idx_scale]; - FOR (i = 0; i < LATTICE_DIM; i++) + FOR( i = 0; i < LATTICE_DIM; i++ ) { - Word32 temp = Mpy_32_16_1(sigma_BWE_fx[mode * LATTICE_DIM + i], scale); - temp = Mpy_32_16_1(temp, out[i]); - out[i] = extract_h(temp); - //out[i] *= scale * sigma_BWE_fx[mode * LATTICE_DIM + i]; + Word32 temp = Mpy_32_16_1( sigma_BWE_fx[mode * LATTICE_DIM + i], scale ); + temp = Mpy_32_16_1( temp, out[i] ); + out[i] = extract_h( temp ); + // out[i] *= scale * sigma_BWE_fx[mode * LATTICE_DIM + i]; } } diff --git a/lib_com/nelp_fx.c b/lib_com/nelp_fx.c index 04d1e1308..841280fa0 100644 --- a/lib_com/nelp_fx.c +++ b/lib_com/nelp_fx.c @@ -36,13 +36,12 @@ #include "prot_fx2.h" - /*===================================================================*/ /* FUNCTION : dequantize_uvg_fx() */ /*-------------------------------------------------------------------*/ /* PURPOSE : This function returns the quantized gain - vector given the indices in the gain - quantization tables */ + vector given the indices in the gain + quantization tables */ /*-------------------------------------------------------------------*/ /* INPUT ARGUMENTS : */ /* _ (Word16) iG1 : index into UVG1CB_fx table (Q0) */ @@ -59,94 +58,93 @@ /* _ None. */ /*===================================================================*/ Word16 dequantize_uvg_fx( - const Word16 iG1, /* i: gain 1 index */ - const Word16* iG2, /* i: gain 2 index */ - Word16* G, /* o: quantized gain */ - const Word16 bwidth_fx, /* i: bandwidth */ - const Word16 do_scale -) + const Word16 iG1, /* i: gain 1 index */ + const Word16 *iG2, /* i: gain 2 index */ + Word16 *G, /* o: quantized gain */ + const Word16 bwidth_fx, /* i: bandwidth */ + const Word16 do_scale ) { - Word16 i, k; - const Word16(*UVG1CB)[2] = NULL; - const Word16(*UVG2CB1)[5] = NULL; - const Word16(*UVG2CB2)[5] = NULL; - Word16 frac, exp, sc; - Word32 L_tmp; - Word16 Q_gain = 0; - - IF(EQ_16(bwidth_fx, NB)) - { - UVG1CB = UVG1CB_NB_FX; - move16(); - UVG2CB1 = UVG2CB1_NB_FX; - move16(); - UVG2CB2 = UVG2CB2_NB_FX; - move16(); - } - ELSE IF(EQ_16(bwidth_fx, WB) || EQ_16(bwidth_fx, SWB)) - { - test(); - UVG1CB = UVG1CB_WB_FX; - move16(); - UVG2CB1 = UVG2CB1_WB_FX; - move16(); - UVG2CB2 = UVG2CB2_WB_FX; - move16(); - } - - IF(!do_scale) - { - sc = 11; - move16(); - } - ELSE - { - test(); - IF((LT_16(UVG1CB[iG1][0], 4096)) && (LT_16(UVG1CB[iG1][1],4096))) /* if x < 1, where 10^x is used for gain computation */ - { - sc = 8; - move16(); - Q_gain = 3; - move16(); - } - ELSE - { - sc = 11; - move16(); - } - } - - FOR(i = 0; i < 2; i++) - { - FOR(k = 0; k < 5; k++) - { - IF(i == 0) - { - /* pow(10.0, UVG1CB[iG1][i]) = pow(2.0,UVG1CB[iG1][i]*3.321928 */ - L_tmp = L_mult(UVG1CB[iG1][i], 27213); /* Q(13+13+1)->Q27 */ - L_tmp = L_shr_r(L_tmp, 11); /* Q16 */ - frac = L_Extract_lc(L_tmp, &exp); - frac = extract_l(Pow2(14, frac)); - G[i * 5 + k] = round_fx(L_shl(L_mult(frac, UVG2CB1[iG2[i]][k]), exp - sc)); /* Q0 */ - } - ELSE IF(EQ_16(i, 1)) - { - L_tmp = L_mult(UVG1CB[iG1][i], 27213); /* Q(13+13+1)->Q27 */ - L_tmp = L_shr_r(L_tmp, 11); /* Q16 */ - frac = L_Extract_lc(L_tmp, &exp); - frac = extract_l(Pow2(14, frac)); - G[i * 5 + k] = round_fx(L_shl(L_mult(frac, UVG2CB2[iG2[i]][k]), exp - sc)); /* Q0 */ - } - } - } - return Q_gain; + Word16 i, k; + const Word16( *UVG1CB )[2] = NULL; + const Word16( *UVG2CB1 )[5] = NULL; + const Word16( *UVG2CB2 )[5] = NULL; + Word16 frac, exp, sc; + Word32 L_tmp; + Word16 Q_gain = 0; + + IF( EQ_16( bwidth_fx, NB ) ) + { + UVG1CB = UVG1CB_NB_FX; + move16(); + UVG2CB1 = UVG2CB1_NB_FX; + move16(); + UVG2CB2 = UVG2CB2_NB_FX; + move16(); + } + ELSE IF( EQ_16( bwidth_fx, WB ) || EQ_16( bwidth_fx, SWB ) ) + { + test(); + UVG1CB = UVG1CB_WB_FX; + move16(); + UVG2CB1 = UVG2CB1_WB_FX; + move16(); + UVG2CB2 = UVG2CB2_WB_FX; + move16(); + } + + IF( !do_scale ) + { + sc = 11; + move16(); + } + ELSE + { + test(); + IF( ( LT_16( UVG1CB[iG1][0], 4096 ) ) && ( LT_16( UVG1CB[iG1][1], 4096 ) ) ) /* if x < 1, where 10^x is used for gain computation */ + { + sc = 8; + move16(); + Q_gain = 3; + move16(); + } + ELSE + { + sc = 11; + move16(); + } + } + + FOR( i = 0; i < 2; i++ ) + { + FOR( k = 0; k < 5; k++ ) + { + IF( i == 0 ) + { + /* pow(10.0, UVG1CB[iG1][i]) = pow(2.0,UVG1CB[iG1][i]*3.321928 */ + L_tmp = L_mult( UVG1CB[iG1][i], 27213 ); /* Q(13+13+1)->Q27 */ + L_tmp = L_shr_r( L_tmp, 11 ); /* Q16 */ + frac = L_Extract_lc( L_tmp, &exp ); + frac = extract_l( Pow2( 14, frac ) ); + G[i * 5 + k] = round_fx( L_shl( L_mult( frac, UVG2CB1[iG2[i]][k] ), exp - sc ) ); /* Q0 */ + } + ELSE IF( EQ_16( i, 1 ) ) + { + L_tmp = L_mult( UVG1CB[iG1][i], 27213 ); /* Q(13+13+1)->Q27 */ + L_tmp = L_shr_r( L_tmp, 11 ); /* Q16 */ + frac = L_Extract_lc( L_tmp, &exp ); + frac = extract_l( Pow2( 14, frac ) ); + G[i * 5 + k] = round_fx( L_shl( L_mult( frac, UVG2CB2[iG2[i]][k] ), exp - sc ) ); /* Q0 */ + } + } + } + return Q_gain; } /*===================================================================*/ /* FUNCTION : generate_nelp_excitation_fx */ /*-------------------------------------------------------------------*/ /* PURPOSE : This function computes the random - excitation scaled by gain */ + excitation scaled by gain */ /*-------------------------------------------------------------------*/ /* INPUT ARGUMENTS : */ /* _ (Word16*) Gains : Gain vector (Q_exc) */ @@ -163,85 +161,85 @@ Word16 dequantize_uvg_fx( /* _ None. */ /*===================================================================*/ void generate_nelp_excitation_fx( - Word16 *seed, /* i/o: random number seed */ - const Word16 *Gains, /* i : excitation gains Q_exc*/ - Word16 *output, /* o : excitation output */ - const Word16 gain_fac /* i : gain factor */ + Word16 *seed, /* i/o: random number seed */ + const Word16 *Gains, /* i : excitation gains Q_exc*/ + Word16 *output, /* o : excitation output */ + const Word16 gain_fac /* i : gain factor */ ) { - Word16 i, len, j; - Word16 tmp[31], tmp1[31], tmpf, L16; - Word16 k1, k2, I[31], tmpi; - Word32 L32; - Word16 cnt; - - FOR(i = 0; i < 10; i++) - { - IF(EQ_16(i, 9)) - { - len = 31; - move16(); - cnt = 8; - move16(); - } - ELSE - { - len = 25; - move16(); - cnt = 6; - move16(); - } - - FOR(j = 0; j < len; j++) - { - L32 = L_mult0(*seed, 0x0209); /* L32 = *seed*521; */ - - L16 = extract_l(L_add(L32, 259)); - *seed = L16; - move16(); /* Q0 */ - tmp[j] = *seed; - move16(); /* Q15, tmp[j]=*seed/32768 */ - - tmp1[j] = abs_s(tmp[j]); - I[j] = j; - move16(); - } - - j = sub(len, 1); - FOR(k1 = 0; k1 < j; k1++) - { - FOR(k2 = add(k1, 1); k2 < len; k2++) - { - IF(GT_16(tmp1[k2], tmp1[k1])) - { - tmpi = I[k2]; - move16(); - tmpf = tmp1[k2]; - move16(); - tmp1[k2] = tmp1[k1]; - move16(); - I[k2] = I[k1]; - move16(); - tmp1[k1] = tmpf; - move16(); - I[k1] = tmpi; - move16(); - } - } - } - - /*using a factor of 1.37 to compensate for the ~ 2.5 ( or 2.73) dB diff between this scheme and EVS-UV */ - FOR(j = 0; j < cnt; j++) - { - L16 = mult_r(tmp[I[j]], gain_fac); /* Q14 */ - L16 = mult_r(L16, 0x6EDA); /* Q13 */ - - output[i * 25 + I[j]] = round_fx(L_shl(L_mult(L16, Gains[i]), 2)); /* Q_exc */ - } - FOR(; j < len; j++) - { - output[i * 25 + I[j]] = 0; - move16(); - } - } + Word16 i, len, j; + Word16 tmp[31], tmp1[31], tmpf, L16; + Word16 k1, k2, I[31], tmpi; + Word32 L32; + Word16 cnt; + + FOR( i = 0; i < 10; i++ ) + { + IF( EQ_16( i, 9 ) ) + { + len = 31; + move16(); + cnt = 8; + move16(); + } + ELSE + { + len = 25; + move16(); + cnt = 6; + move16(); + } + + FOR( j = 0; j < len; j++ ) + { + L32 = L_mult0( *seed, 0x0209 ); /* L32 = *seed*521; */ + + L16 = extract_l( L_add( L32, 259 ) ); + *seed = L16; + move16(); /* Q0 */ + tmp[j] = *seed; + move16(); /* Q15, tmp[j]=*seed/32768 */ + + tmp1[j] = abs_s( tmp[j] ); + I[j] = j; + move16(); + } + + j = sub( len, 1 ); + FOR( k1 = 0; k1 < j; k1++ ) + { + FOR( k2 = add( k1, 1 ); k2 < len; k2++ ) + { + IF( GT_16( tmp1[k2], tmp1[k1] ) ) + { + tmpi = I[k2]; + move16(); + tmpf = tmp1[k2]; + move16(); + tmp1[k2] = tmp1[k1]; + move16(); + I[k2] = I[k1]; + move16(); + tmp1[k1] = tmpf; + move16(); + I[k1] = tmpi; + move16(); + } + } + } + + /*using a factor of 1.37 to compensate for the ~ 2.5 ( or 2.73) dB diff between this scheme and EVS-UV */ + FOR( j = 0; j < cnt; j++ ) + { + L16 = mult_r( tmp[I[j]], gain_fac ); /* Q14 */ + L16 = mult_r( L16, 0x6EDA ); /* Q13 */ + + output[i * 25 + I[j]] = round_fx( L_shl( L_mult( L16, Gains[i] ), 2 ) ); /* Q_exc */ + } + FOR( ; j < len; j++ ) + { + output[i * 25 + I[j]] = 0; + move16(); + } + } } diff --git a/lib_com/oper_32b.c b/lib_com/oper_32b.c index f08783a2e..9f1ce2157 100644 --- a/lib_com/oper_32b.c +++ b/lib_com/oper_32b.c @@ -20,7 +20,7 @@ * We will use DPF (Double Precision Format) in this file to specify * * this special format. * ***************************************************************************** -*/ + */ #include "stl.h" #include "basop32.h" @@ -38,12 +38,12 @@ * hi : b16 to b31 of L_32 * * lo : (L_32 - hi<<16)>>1 * ***************************************************************************** -*/ + */ -void L_Extract (Word32 L_32, Word16 *hi, Word16 *lo) +void L_Extract( Word32 L_32, Word16 *hi, Word16 *lo ) { - *hi = extract_h (L_32); - *lo = extract_l (L_msu (L_shr (L_32, 1), *hi, 16384)); + *hi = extract_h( L_32 ); + *lo = extract_l( L_msu( L_shr( L_32, 1 ), *hi, 16384 ) ); return; } @@ -61,13 +61,13 @@ void L_Extract (Word32 L_32, Word16 *hi, Word16 *lo) * hi : b16 to b31 of L_32 * * lo : (L_32 - hi<<16)>>1 * ***************************************************************************** -*/ + */ -Word16 L_Extract_lc (Word32 L_32, Word16 *hi) +Word16 L_Extract_lc( Word32 L_32, Word16 *hi ) { - *hi = extract_h (L_32); + *hi = extract_h( L_32 ); - return lshr(extract_l(L_32), 1); + return lshr( extract_l( L_32 ), 1 ); } /***************************************************************************** @@ -89,14 +89,14 @@ Word16 L_Extract_lc (Word32 L_32, Word16 *hi) * range : 0x8000 0000 <= L_32 <= 0x7fff fff0. * * * ***************************************************************************** -*/ + */ -Word32 L_Comp (Word16 hi, Word16 lo) +Word32 L_Comp( Word16 hi, Word16 lo ) { Word32 L_32; - L_32 = L_deposit_h (hi); - return (L_mac (L_32, lo, 1)); /* = hi<<16 + lo<<1 */ + L_32 = L_deposit_h( hi ); + return ( L_mac( L_32, lo, 1 ) ); /* = hi<<16 + lo<<1 */ } /***************************************************************************** @@ -117,9 +117,9 @@ Word32 L_Comp (Word16 hi, Word16 lo) * lo2 lo part of second number * * * ***************************************************************************** -*/ + */ -Word32 Mpy_32 (Word16 hi1, Word16 lo1, Word16 hi2, Word16 lo2) +Word32 Mpy_32( Word16 hi1, Word16 lo1, Word16 hi2, Word16 lo2 ) { Word32 L_32; #ifdef BASOP_NOGLOB_DECLARE_LOCAL @@ -127,16 +127,16 @@ Word32 Mpy_32 (Word16 hi1, Word16 lo1, Word16 hi2, Word16 lo2) #endif #ifdef BASOP_NOGLOB - L_32 = L_mult (hi1, hi2); - L_32 = L_mac_o (L_32, mult (hi1, lo2), 1, &Overflow); - L_32 = L_mac_o (L_32, mult (lo1, hi2), 1, &Overflow); + L_32 = L_mult( hi1, hi2 ); + L_32 = L_mac_o( L_32, mult( hi1, lo2 ), 1, &Overflow ); + L_32 = L_mac_o( L_32, mult( lo1, hi2 ), 1, &Overflow ); #else - L_32 = L_mult (hi1, hi2); - L_32 = L_mac (L_32, mult (hi1, lo2), 1); - L_32 = L_mac (L_32, mult (lo1, hi2), 1); + L_32 = L_mult( hi1, hi2 ); + L_32 = L_mac( L_32, mult( hi1, lo2 ), 1 ); + L_32 = L_mac( L_32, mult( lo1, hi2 ), 1 ); #endif - return (L_32); + return ( L_32 ); } /***************************************************************************** @@ -158,9 +158,9 @@ Word32 Mpy_32 (Word16 hi1, Word16 lo1, Word16 hi2, Word16 lo2) * lo2 lo part of second number * * * ***************************************************************************** -*/ + */ -Word32 Mac_32 (Word32 L_num, Word16 hi1, Word16 lo1, Word16 hi2, Word16 lo2) +Word32 Mac_32( Word32 L_num, Word16 hi1, Word16 lo1, Word16 hi2, Word16 lo2 ) { Word32 L_32; #ifdef BASOP_NOGLOB_DECLARE_LOCAL @@ -168,16 +168,16 @@ Word32 Mac_32 (Word32 L_num, Word16 hi1, Word16 lo1, Word16 hi2, Word16 lo2) #endif #ifdef BASOP_NOGLOB - L_32 = L_mac_o (L_num, hi1, hi2, &Overflow); - L_32 = L_mac_o(L_32, mult (hi1, lo2), 1, &Overflow); - L_32 = L_mac_o(L_32, mult (lo1, hi2), 1, &Overflow); + L_32 = L_mac_o( L_num, hi1, hi2, &Overflow ); + L_32 = L_mac_o( L_32, mult( hi1, lo2 ), 1, &Overflow ); + L_32 = L_mac_o( L_32, mult( lo1, hi2 ), 1, &Overflow ); #else - L_32 = L_mac (L_num, hi1, hi2); - L_32 = L_mac (L_32, mult (hi1, lo2), 1); - L_32 = L_mac (L_32, mult (lo1, hi2), 1); + L_32 = L_mac( L_num, hi1, hi2 ); + L_32 = L_mac( L_32, mult( hi1, lo2 ), 1 ); + L_32 = L_mac( L_32, mult( lo1, hi2 ), 1 ); #endif - return (L_32); + return ( L_32 ); } /***************************************************************************** @@ -198,9 +198,9 @@ Word32 Mac_32 (Word32 L_num, Word16 hi1, Word16 lo1, Word16 hi2, Word16 lo2) * lo2 lo part of second number * * * ***************************************************************************** -*/ + */ -Word32 Sqr_32 (Word16 hi, Word16 lo) +Word32 Sqr_32( Word16 hi, Word16 lo ) { Word32 L_32; #ifdef BASOP_NOGLOB_DECLARE_LOCAL @@ -208,14 +208,14 @@ Word32 Sqr_32 (Word16 hi, Word16 lo) #endif #ifdef BASOP_NOGLOB - L_32 = L_mult_o (hi, hi, &Overflow); - L_32 = L_mac_o (L_32, mult (hi, lo), 2, &Overflow); -#else - L_32 = L_mult (hi, hi); - L_32 = L_mac (L_32, mult (hi, lo), 2); + L_32 = L_mult_o( hi, hi, &Overflow ); + L_32 = L_mac_o( L_32, mult( hi, lo ), 2, &Overflow ); +#else + L_32 = L_mult( hi, hi ); + L_32 = L_mac( L_32, mult( hi, lo ), 2 ); #endif - return (L_32); + return ( L_32 ); } /***************************************************************************** @@ -237,16 +237,16 @@ Word32 Sqr_32 (Word16 hi, Word16 lo) * lo2 lo part of second number * * * ***************************************************************************** -*/ + */ -Word32 Sad_32 (Word32 L_num, Word16 hi, Word16 lo) +Word32 Sad_32( Word32 L_num, Word16 hi, Word16 lo ) { Word32 L_32; - L_32 = L_mac (L_num, hi, hi); - L_32 = L_mac (L_32, mult (hi, lo), 2); + L_32 = L_mac( L_num, hi, hi ); + L_32 = L_mac( L_32, mult( hi, lo ), 2 ); - return (L_32); + return ( L_32 ); } /***************************************************************************** @@ -265,16 +265,16 @@ Word32 Sad_32 (Word32 L_num, Word16 hi, Word16 lo) * n 16 bit number. * * * ***************************************************************************** -*/ + */ -Word32 Mpy_32_16 (Word16 hi, Word16 lo, Word16 n) +Word32 Mpy_32_16( Word16 hi, Word16 lo, Word16 n ) { Word32 L_32; - L_32 = L_mult (hi, n); - L_32 = L_mac (L_32, mult (lo, n), 1); + L_32 = L_mult( hi, n ); + L_32 = L_mac( L_32, mult( lo, n ), 1 ); - return (L_32); + return ( L_32 ); } /***************************************************************************** @@ -295,16 +295,16 @@ Word32 Mpy_32_16 (Word16 hi, Word16 lo, Word16 n) * n 16 bit number. * * * ***************************************************************************** -*/ + */ -Word32 Mac_32_16 (Word32 L_num, Word16 hi, Word16 lo, Word16 n) +Word32 Mac_32_16( Word32 L_num, Word16 hi, Word16 lo, Word16 n ) { Word32 L_32; - L_32 = L_mac (L_num, hi, n); - L_32 = L_mac (L_32, mult (lo, n), 1); + L_32 = L_mac( L_num, hi, n ); + L_32 = L_mac( L_32, mult( lo, n ), 1 ); - return (L_32); + return ( L_32 ); } /***************************************************************************** @@ -325,16 +325,16 @@ Word32 Mac_32_16 (Word32 L_num, Word16 hi, Word16 lo, Word16 n) * n 16 bit number. * * * ***************************************************************************** -*/ + */ -Word32 Msu_32_16 (Word32 L_num, Word16 hi, Word16 lo, Word16 n) +Word32 Msu_32_16( Word32 L_num, Word16 hi, Word16 lo, Word16 n ) { Word32 L_32; - L_32 = L_msu (L_num, hi, n); - L_32 = L_msu (L_32, mult (lo, n), 1); + L_32 = L_msu( L_num, hi, n ); + L_32 = L_msu( L_32, mult( lo, n ), 1 ); - return (L_32); + return ( L_32 ); } /***************************************************************************** @@ -377,34 +377,33 @@ Word32 Msu_32_16 (Word32 L_num, Word16 hi, Word16 lo, Word16 n) * * * - result = L_num * (1/L_denom) * ***************************************************************************** -*/ + */ -Word32 Div_32 (Word32 L_num, Word16 denom_hi, Word16 denom_lo) +Word32 Div_32( Word32 L_num, Word16 denom_hi, Word16 denom_lo ) { Word16 approx, hi, lo, n_hi, n_lo; Word32 L_32; /* First approximation: 1 / L_denom = 1/denom_hi */ - approx = div_s ((Word16) 0x3fff, denom_hi); + approx = div_s( (Word16) 0x3fff, denom_hi ); /* 1/L_denom = approx * (2.0 - L_denom * approx) */ - L_32 = Msu_32_16 ((Word32) 0x7fffffffL, denom_hi, denom_lo, approx); + L_32 = Msu_32_16( (Word32) 0x7fffffffL, denom_hi, denom_lo, approx ); - lo = L_Extract_lc (L_32, &hi); - L_32 = Mpy_32_16 (hi, lo, approx); + lo = L_Extract_lc( L_32, &hi ); + L_32 = Mpy_32_16( hi, lo, approx ); /* L_num * (1/L_denom) */ - lo = L_Extract_lc (L_32, &hi); - n_lo = L_Extract_lc (L_num, &n_hi); - L_32 = Mpy_32 (n_hi, n_lo, hi, lo); + lo = L_Extract_lc( L_32, &hi ); + n_lo = L_Extract_lc( L_num, &n_hi ); + L_32 = Mpy_32( n_hi, n_lo, hi, lo ); #ifdef BASOP_NOGLOB L_32 = L_shl_sat( L_32, 2 ); #else - L_32 = L_shl (L_32, 2); + L_32 = L_shl( L_32, 2 ); #endif - return (L_32); + return ( L_32 ); } - diff --git a/lib_com/oper_32b.h b/lib_com/oper_32b.h index 70d1c59db..a874bc10e 100644 --- a/lib_com/oper_32b.h +++ b/lib_com/oper_32b.h @@ -3,16 +3,16 @@ #ifndef _OPER_32b_H #define _OPER_32b_H -void L_Extract (Word32 L_32, Word16 *hi, Word16 *lo); -Word16 L_Extract_lc (Word32 L_32, Word16 *hi); -Word32 L_Comp (Word16 hi, Word16 lo); -Word32 Mpy_32 (Word16 hi1, Word16 lo1, Word16 hi2, Word16 lo2); -Word32 Mac_32 (Word32 L_num, Word16 hi1, Word16 lo1, Word16 hi2, Word16 lo2); -Word32 Sqr_32 (Word16 hi, Word16 lo); -Word32 Sad_32 (Word32 L_num, Word16 hi, Word16 lo); -Word32 Mpy_32_16 (Word16 hi, Word16 lo, Word16 n); -Word32 Mac_32_16 (Word32 L_num, Word16 hi, Word16 lo, Word16 n); -Word32 Msu_32_16 (Word32 L_num, Word16 hi, Word16 lo, Word16 n); -Word32 Div_32 (Word32 L_num, Word16 denom_hi, Word16 denom_lo); +void L_Extract( Word32 L_32, Word16 *hi, Word16 *lo ); +Word16 L_Extract_lc( Word32 L_32, Word16 *hi ); +Word32 L_Comp( Word16 hi, Word16 lo ); +Word32 Mpy_32( Word16 hi1, Word16 lo1, Word16 hi2, Word16 lo2 ); +Word32 Mac_32( Word32 L_num, Word16 hi1, Word16 lo1, Word16 hi2, Word16 lo2 ); +Word32 Sqr_32( Word16 hi, Word16 lo ); +Word32 Sad_32( Word32 L_num, Word16 hi, Word16 lo ); +Word32 Mpy_32_16( Word16 hi, Word16 lo, Word16 n ); +Word32 Mac_32_16( Word32 L_num, Word16 hi, Word16 lo, Word16 n ); +Word32 Msu_32_16( Word32 L_num, Word16 hi, Word16 lo, Word16 n ); +Word32 Div_32( Word32 L_num, Word16 denom_hi, Word16 denom_lo ); #endif diff --git a/lib_com/options.h b/lib_com/options.h index 3d29e6459..626ec73ff 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -143,6 +143,6 @@ /* clang-format on */ #define NONBE_FIX_1010_STEREO_CNG_DIV_BY_ZERO -#define UNUSED_PARAM(...) (void)(__VA_ARGS__) +#define UNUSED_PARAM( ... ) (void) ( __VA_ARGS__ ) #endif diff --git a/lib_com/parameter_bitmaping_fx.c b/lib_com/parameter_bitmaping_fx.c index bedb40394..ee5dd7d73 100644 --- a/lib_com/parameter_bitmaping_fx.c +++ b/lib_com/parameter_bitmaping_fx.c @@ -57,7 +57,7 @@ void ReadFromBitstream_fx( param = ¶msBitMap->params[iParam]; test(); test(); - fShiftValue = s_and( (Word16)EQ_16( param->fZeroAllowed, 0 ), param->EncodeValue == NULL ); + fShiftValue = s_and( (Word16) EQ_16( param->fZeroAllowed, 0 ), param->EncodeValue == NULL ); value = GetFromBitstream( st, param->DecodeValue, index, param->nBits, pStream ); IF( fShiftValue ) { @@ -73,4 +73,4 @@ void ReadFromBitstream_fx( } move16(); *pnSize = add( *pnSize, i_mult( nParams, nArrayLength ) ); -} \ No newline at end of file +} diff --git a/lib_com/phase_dispersion_fx.c b/lib_com/phase_dispersion_fx.c index 3c01533c6..5a1c3d510 100644 --- a/lib_com/phase_dispersion_fx.c +++ b/lib_com/phase_dispersion_fx.c @@ -3,7 +3,7 @@ ====================================================================================*/ #include -#include "options.h" /* EV-VBR compilation switches */ +#include "options.h" /* EV-VBR compilation switches */ #include "prot_fx1.h" #include "prot_fx2.h" #include "basop_util.h" @@ -16,19 +16,19 @@ *-----------------------------------------------------------------------*/ void phase_dispersion( - const Word32 gain_code, /* i : gain of code 15Q16 */ - const Word16 gain_pit, /* i : gain of pitch Q14 */ - Word16 code[], /* i/o: code vector */ - Word16 *code_exp, /* i/o: exponent of code */ - const Word16 mode, /* i : level, 0=hi, 1=lo, 2=off */ - Word32 *prev_gain_code, /* i/o: static memory 15Q16 */ - Word16 prev_gain_pit[], /* i/o: static memory Q14, size=6 */ - Word16 *prev_state, /* i/o: static memory Q0 */ - Word16 L_subfr /* i : subframe length [40,64,80]*/ + const Word32 gain_code, /* i : gain of code 15Q16 */ + const Word16 gain_pit, /* i : gain of pitch Q14 */ + Word16 code[], /* i/o: code vector */ + Word16 *code_exp, /* i/o: exponent of code */ + const Word16 mode, /* i : level, 0=hi, 1=lo, 2=off */ + Word32 *prev_gain_code, /* i/o: static memory 15Q16 */ + Word16 prev_gain_pit[], /* i/o: static memory Q14, size=6 */ + Word16 *prev_state, /* i/o: static memory Q0 */ + Word16 L_subfr /* i : subframe length [40,64,80]*/ ) { Word16 i, j, state, scale2; - Word32 x32[2*L_SUBFR]; + Word32 x32[2 * L_SUBFR]; Word16 *code_real, *code_imag; const Word16 *h_real, *h_imag; #ifdef BASOP_NOGLOB_DECLARE_LOCAL @@ -39,57 +39,57 @@ void phase_dispersion( move16(); state = 2; - if ( LT_16(gain_pit,14746/*0.9f Q14*/)) + if ( LT_16( gain_pit, 14746 /*0.9f Q14*/ ) ) { move16(); state = 1; } - if ( LT_16(gain_pit, 9830/*0.6f Q14*/)) + if ( LT_16( gain_pit, 9830 /*0.6f Q14*/ ) ) { move16(); state = 0; } - FOR (i=5; i>0; i--) + FOR( i = 5; i > 0; i-- ) { move16(); - prev_gain_pit[i] = prev_gain_pit[i-1]; + prev_gain_pit[i] = prev_gain_pit[i - 1]; } move16(); prev_gain_pit[0] = gain_pit; #ifdef BASOP_NOGLOB - IF ( GT_32(gain_code, L_add_o(*prev_gain_code, L_shl_o(*prev_gain_code,1, &Overflow), &Overflow))) + IF( GT_32( gain_code, L_add_o( *prev_gain_code, L_shl_o( *prev_gain_code, 1, &Overflow ), &Overflow ) ) ) #else - IF ( GT_32(gain_code, L_add(*prev_gain_code, L_shl(*prev_gain_code,1)))) + IF( GT_32( gain_code, L_add( *prev_gain_code, L_shl( *prev_gain_code, 1 ) ) ) ) #endif { - if (LT_16(state,2)) + if ( LT_16( state, 2 ) ) { - state = add(state, 1); + state = add( state, 1 ); } } ELSE { - j=0; - FOR (i=0; i<6; i++) + j = 0; + FOR( i = 0; i < 6; i++ ) { - if ( LT_32(prev_gain_pit[i], 9830/*0.6f Q14*/)) + if ( LT_32( prev_gain_pit[i], 9830 /*0.6f Q14*/ ) ) { - j = add(j,1); + j = add( j, 1 ); } } - if (GT_16(j,2)) + if ( GT_16( j, 2 ) ) { move16(); state = 0; } - if ( GT_16(sub(state, *prev_state),1)) + if ( GT_16( sub( state, *prev_state ), 1 ) ) { - state = sub(state,1); + state = sub( state, 1 ); } } @@ -102,48 +102,48 @@ void phase_dispersion( * circular convolution *-----------------------------------------------------------------*/ - state = add(state, mode); /* level of dispersion */ + state = add( state, mode ); /* level of dispersion */ j = *code_exp; move16(); - IF( LT_16(state,2)) + IF( LT_16( state, 2 ) ) { - FOR(i=0; i -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ /*-------------------------------------------------------------------* @@ -22,18 +22,18 @@ *-------------------------------------------------------------------*/ void pred_lt4( - const Word16 excI[], /* in : excitation buffer */ - Word16 excO[], /* out: excitation buffer */ - const Word16 T0, /* input : integer pitch lag */ - Word16 frac, /* input : fraction of lag */ - const Word16 L_subfr, /* input : subframe size */ - const Word16 *win, /* i : interpolation window */ - const Word16 nb_coef, /* i : nb of filter coef */ - const Word16 up_sample /* i : up_sample */ + const Word16 excI[], /* in : excitation buffer */ + Word16 excO[], /* out: excitation buffer */ + const Word16 T0, /* input : integer pitch lag */ + Word16 frac, /* input : fraction of lag */ + const Word16 L_subfr, /* input : subframe size */ + const Word16 *win, /* i : interpolation window */ + const Word16 nb_coef, /* i : nb of filter coef */ + const Word16 up_sample /* i : up_sample */ ) { - Word16 i, j; - Word32 s; + Word16 i, j; + Word32 s; const Word16 *x0, *x1, *x2, *c1, *c2; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; @@ -41,47 +41,47 @@ void pred_lt4( x0 = &excI[-T0]; - frac = negate(frac); + frac = negate( frac ); - IF ( frac < 0 ) + IF( frac < 0 ) { - frac = add(frac,up_sample); + frac = add( frac, up_sample ); x0--; } - FOR (j=0; j 0) + IF( frac > 0 ) { - frac = sub(frac,UP_SAMP); + frac = sub( frac, UP_SAMP ); x0--; } - l = add(UP_SAMP-1, frac); - FOR (j = T0; j < L_SUBFR+1; j++) + l = add( UP_SAMP - 1, frac ); + FOR( j = T0; j < L_SUBFR + 1; j++ ) { k = l; move16(); - L_sum = L_mult(x0[0], win[k]); - FOR (i = 1; i < 2 * L_INTERPOL2; i++) + L_sum = L_mult( x0[0], win[k] ); + FOR( i = 1; i < 2 * L_INTERPOL2; i++ ) { /* * Here, additions with UP_SAMP are not counted @@ -159,30 +159,29 @@ void pred_lt4_tc_fx( * so that the values needed are contiguous. */ k += UP_SAMP; - L_sum = L_mac(L_sum, x0[i], win[k]); /*Q1 */ + L_sum = L_mac( L_sum, x0[i], win[k] ); /*Q1 */ } #ifdef BASOP_NOGLOB - L_sum = L_shl_o(L_sum, 1, &Overflow); /*Q0h */ - excO[j] = round_fx_o(L_sum, &Overflow); + L_sum = L_shl_o( L_sum, 1, &Overflow ); /*Q0h */ + excO[j] = round_fx_o( L_sum, &Overflow ); #else - L_sum = L_shl(L_sum, 1); /*Q0h */ + L_sum = L_shl( L_sum, 1 ); /*Q0h */ - excO[j] = round_fx(L_sum); + excO[j] = round_fx( L_sum ); #endif x0++; } - FOR (i = T0; i < L_SUBFR; i++) + FOR( i = T0; i < L_SUBFR; i++ ) { #ifdef BASOP_NOGLOB - exc[i+i_subfr] = add_o(exc[i+i_subfr], mult_r(PIT_SHARP_fx, excO[i]), &Overflow); + exc[i + i_subfr] = add_o( exc[i + i_subfr], mult_r( PIT_SHARP_fx, excO[i] ), &Overflow ); #else - exc[i+i_subfr] = add(exc[i+i_subfr], mult_r(PIT_SHARP_fx, excO[i])); + exc[i + i_subfr] = add( exc[i + i_subfr], mult_r( PIT_SHARP_fx, excO[i] ) ); #endif move16(); } } return; - } diff --git a/lib_com/preemph.c b/lib_com/preemph.c index d1ae2de52..89064782f 100644 --- a/lib_com/preemph.c +++ b/lib_com/preemph.c @@ -94,4 +94,4 @@ void preemph_ivas_fx( *mem = temp; return; -} \ No newline at end of file +} diff --git a/lib_com/preemph_fx.c b/lib_com/preemph_fx.c index 8fc92a9ef..21dd047ce 100644 --- a/lib_com/preemph_fx.c +++ b/lib_com/preemph_fx.c @@ -2,7 +2,7 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ +#include "options.h" /* Compilation switches */ #include "prot_fx1.h" #include "prot_fx2.h" /*-------------------------------------------------------------* @@ -11,11 +11,11 @@ * Preemphasis: filtering through 1 - mu z^-1 *-------------------------------------------------------------*/ void preemph_copy_fx( - const Word16 x[], /* i : input signal Qx */ - Word16 y[], /* o : output signal Qx */ - const Word16 mu, /* i : preemphasis coefficient Q15 */ - const Word16 lg, /* i : vector size Q0 */ - Word16 *mem /* i/o: memory (x[-1]) Qx */ + const Word16 x[], /* i : input signal Qx */ + Word16 y[], /* o : output signal Qx */ + const Word16 mu, /* i : preemphasis coefficient Q15 */ + const Word16 lg, /* i : vector size Q0 */ + Word16 *mem /* i/o: memory (x[-1]) Qx */ ) { Word16 i, temp; @@ -24,19 +24,19 @@ void preemph_copy_fx( #endif temp = x[lg - 1]; move16(); - FOR (i = sub(lg, 1); i > 0; i--) + FOR( i = sub( lg, 1 ); i > 0; i-- ) { #ifdef BASOP_NOGLOB - y[i] = msu_ro(L_deposit_h(x[i]), x[i - 1], mu, &Overflow); + y[i] = msu_ro( L_deposit_h( x[i] ), x[i - 1], mu, &Overflow ); #else - y[i] = msu_r(L_deposit_h(x[i]), x[i - 1], mu); + y[i] = msu_r( L_deposit_h( x[i] ), x[i - 1], mu ); #endif move16(); } #ifdef BASOP_NOGLOB - y[0] = msu_ro(L_deposit_h(x[0]), *mem, mu, &Overflow); + y[0] = msu_ro( L_deposit_h( x[0] ), *mem, mu, &Overflow ); #else - y[0] = msu_r(L_deposit_h(x[0]), *mem, mu); + y[0] = msu_r( L_deposit_h( x[0] ), *mem, mu ); #endif move16(); @@ -60,7 +60,7 @@ void preemph_copy_fx( * Returns: * void */ -void E_UTIL_f_preemph2(Word16 shift, Word16 *signal, const Word16 mu, const Word16 lg, Word16 *mem) +void E_UTIL_f_preemph2( Word16 shift, Word16 *signal, const Word16 mu, const Word16 lg, Word16 *mem ) { Word16 i, temp; Word32 L_tmp; @@ -70,29 +70,29 @@ void E_UTIL_f_preemph2(Word16 shift, Word16 *signal, const Word16 mu, const Word temp = signal[lg - 1]; move16(); - FOR (i = sub(lg, 1); i > 0; i--) + FOR( i = sub( lg, 1 ); i > 0; i-- ) { - L_tmp = L_mult(signal[i], 16384); + L_tmp = L_mult( signal[i], 16384 ); #ifdef BASOP_NOGLOB - L_tmp = L_msu0_o(L_tmp, signal[i - 1], mu, &Overflow); - L_tmp = L_shl_o(L_tmp, add(shift,1), &Overflow); - signal[i] = round_fx_o(L_tmp, &Overflow); + L_tmp = L_msu0_o( L_tmp, signal[i - 1], mu, &Overflow ); + L_tmp = L_shl_o( L_tmp, add( shift, 1 ), &Overflow ); + signal[i] = round_fx_o( L_tmp, &Overflow ); #else - L_tmp = L_msu0(L_tmp, signal[i - 1], mu); - L_tmp = L_shl(L_tmp, add(shift,1)); - signal[i] = round_fx(L_tmp); + L_tmp = L_msu0( L_tmp, signal[i - 1], mu ); + L_tmp = L_shl( L_tmp, add( shift, 1 ) ); + signal[i] = round_fx( L_tmp ); #endif } - L_tmp = L_mult(signal[0], 16384); + L_tmp = L_mult( signal[0], 16384 ); #ifdef BASOP_NOGLOB - L_tmp = L_msu0_o(L_tmp, *mem, mu, &Overflow); - L_tmp = L_shl_o(L_tmp, add(shift,1), &Overflow); - signal[0] = round_fx_o(L_tmp, &Overflow); + L_tmp = L_msu0_o( L_tmp, *mem, mu, &Overflow ); + L_tmp = L_shl_o( L_tmp, add( shift, 1 ), &Overflow ); + signal[0] = round_fx_o( L_tmp, &Overflow ); #else - L_tmp = L_msu0(L_tmp, *mem, mu); - L_tmp = L_shl(L_tmp, add(shift,1)); - signal[0] = round_fx(L_tmp); + L_tmp = L_msu0( L_tmp, *mem, mu ); + L_tmp = L_shl( L_tmp, add( shift, 1 ) ); + signal[0] = round_fx( L_tmp ); #endif *mem = temp; @@ -102,58 +102,56 @@ void E_UTIL_f_preemph2(Word16 shift, Word16 *signal, const Word16 mu, const Word } -Word16 E_UTIL_f_preemph3(Word16 *signal, const Word16 mu, const Word16 lg, Word16 *mem, Word16 bits) +Word16 E_UTIL_f_preemph3( Word16 *signal, const Word16 mu, const Word16 lg, Word16 *mem, Word16 bits ) { Word16 i, QVal, mus, tmp_fixed, Q_new; Word32 L_tmp, L_maxloc; + QVal = shl( 1, sub( 15, bits ) ); + mus = shr( mu, bits ); - QVal = shl(1, sub(15,bits)); - mus = shr(mu, bits); + L_tmp = L_mult( signal[0], QVal ); + L_tmp = L_msu( L_tmp, *mem, mus ); + L_maxloc = L_abs( L_tmp ); - L_tmp = L_mult(signal[0], QVal); - L_tmp = L_msu(L_tmp, *mem, mus); - L_maxloc = L_abs(L_tmp); - - FOR (i = 1; i < lg; i++) + FOR( i = 1; i < lg; i++ ) { - L_tmp = L_mult(signal[i], QVal); - L_tmp = L_msu(L_tmp, signal[i - 1], mus); - L_tmp = L_abs(L_tmp); - L_maxloc = L_max(L_tmp, L_maxloc); + L_tmp = L_mult( signal[i], QVal ); + L_tmp = L_msu( L_tmp, signal[i - 1], mus ); + L_tmp = L_abs( L_tmp ); + L_maxloc = L_max( L_tmp, L_maxloc ); } - tmp_fixed = extract_h(L_maxloc); + tmp_fixed = extract_h( L_maxloc ); Q_new = Q_MAX; move16(); - IF (tmp_fixed != 0) + IF( tmp_fixed != 0 ) { - Q_new = sub(norm_s(tmp_fixed), bits); - Q_new = s_max(Q_new, 0); - Q_new = s_min(Q_new, Q_MAX); + Q_new = sub( norm_s( tmp_fixed ), bits ); + Q_new = s_max( Q_new, 0 ); + Q_new = s_min( Q_new, Q_MAX ); } tmp_fixed = signal[lg - 1]; move16(); - FOR (i = sub(lg,1); i > 0; i--) + FOR( i = sub( lg, 1 ); i > 0; i-- ) { - L_tmp = L_mult(signal[i], QVal); - L_tmp = L_msu(L_tmp, signal[i - 1], mus); - L_tmp = L_shl(L_tmp, Q_new); - signal[i] = round_fx(L_tmp); + L_tmp = L_mult( signal[i], QVal ); + L_tmp = L_msu( L_tmp, signal[i - 1], mus ); + L_tmp = L_shl( L_tmp, Q_new ); + signal[i] = round_fx( L_tmp ); } - L_tmp = L_mult(signal[0], QVal); - L_tmp = L_msu(L_tmp, *mem, mus); - L_tmp = L_shl(L_tmp, Q_new); - signal[0] = round_fx(L_tmp); + L_tmp = L_mult( signal[0], QVal ); + L_tmp = L_msu( L_tmp, *mem, mus ); + L_tmp = L_shl( L_tmp, Q_new ); + signal[0] = round_fx( L_tmp ); *mem = tmp_fixed; move16(); return Q_new; } - diff --git a/lib_com/prot.h b/lib_com/prot.h index 18a0d52b9..866d3aa79 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -170,8 +170,7 @@ float sum2_f( Word32 sum2_f_32_fx( const Word32 *vec, /* i : input vector */ const int16_t lvec, /* i : length of input vector */ - Word16 gb -); + Word16 gb ); #endif void set_c( @@ -199,7 +198,7 @@ void set_f( ); void set_zero_fx( - Word32 *vec, /* o : input vector */ + Word32 *vec, /* o : input vector */ const Word16 lvec /* i : length of the vector */ ); @@ -337,7 +336,7 @@ void v_mult_fixed( const Word32 x1[], /* i : Input vector 1 */ const Word32 x2[], /* i : Input vector 2 */ Word32 y[], /* o : Output vector that contains vector 1 .* vector 2 */ - const Word16 N /* i : Vector length */ + const Word16 N /* i : Vector length */ ); #endif @@ -497,19 +496,18 @@ void delay_signal_float( #ifdef IVAS_FLOAT_FIXED void delay_signal_fx( - Word32 x[], /* i/o: signal to be delayed */ + Word32 x[], /* i/o: signal to be delayed */ const int16_t len, /* i : length of the input signal */ - Word32 mem[], /* i/o: synchronization memory */ + Word32 mem[], /* i/o: synchronization memory */ const int16_t delay /* i : delay in samples */ ); void delay_signal_q_adj_fx( Word32 x[], /* i/o: signal to be delayed */ - const int16_t len, /* i : length of the input signal */ + const int16_t len, /* i : length of the input signal */ Word32 mem[], /* i/o: synchronization memory */ const int16_t delay, /* i : delay in samples */ const Word16 q_x, - const Word16 q_mem -); + const Word16 q_mem ); #endif ivas_error push_indice( @@ -538,8 +536,8 @@ int16_t get_ivas_max_num_indices( ); Word16 get_ivas_max_num_indices_fx( - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const Word32 ivas_total_brate /* i : IVAS total bitrate */ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const Word32 ivas_total_brate /* i : IVAS total bitrate */ ); /*! r: maximum number of indices */ @@ -554,8 +552,8 @@ int16_t get_ivas_max_num_indices_metadata( ); Word16 get_ivas_max_num_indices_metadata_fx( - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const Word32 ivas_total_brate /* i : IVAS total bitrate */ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const Word32 ivas_total_brate /* i : IVAS total bitrate */ ); ivas_error ind_list_realloc( INDICE_HANDLE old_ind_list, /* i : pointer to the beginning of the old buffer of indices */ @@ -824,22 +822,21 @@ void hf_synth( #ifdef IVAS_FLOAT_FIXED void hf_synth_ivas_fx( - ZERO_BWE_DEC_HANDLE hBWE_zero, /* i/o: handle to 0 bit BWE parameters */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 output_frame, /* i : output frame length */ - const Word16 *Aq, /* i : quantized Az */ - const Word16 *exc, /* i : excitation at 12.8 kHz */ - Word16 *synth, /* i : 12.8kHz synthesis signal */ - Word16 *synth16k, /* o : 16kHz synthesis signal */ - const Word16 Q_exc, /* i : excitation scaling */ - const Word16 Q_syn2, /* i : synthesis scaling */ - Word16 *delay_syn_hf, /*i/o: HF synthesis memory */ - Word16 *memExp1, /* o : HF excitation exponent */ - Word16 *mem_hp_interp, /* i/o: interpol. memory */ - const Word16 extl, /* i : flag indicating BWE */ - const Word16 CNG_mode, /* i : CNG_mode */ - Word16 element_mode -); + ZERO_BWE_DEC_HANDLE hBWE_zero, /* i/o: handle to 0 bit BWE parameters */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 output_frame, /* i : output frame length */ + const Word16 *Aq, /* i : quantized Az */ + const Word16 *exc, /* i : excitation at 12.8 kHz */ + Word16 *synth, /* i : 12.8kHz synthesis signal */ + Word16 *synth16k, /* o : 16kHz synthesis signal */ + const Word16 Q_exc, /* i : excitation scaling */ + const Word16 Q_syn2, /* i : synthesis scaling */ + Word16 *delay_syn_hf, /*i/o: HF synthesis memory */ + Word16 *memExp1, /* o : HF excitation exponent */ + Word16 *mem_hp_interp, /* i/o: interpol. memory */ + const Word16 extl, /* i : flag indicating BWE */ + const Word16 CNG_mode, /* i : CNG_mode */ + Word16 element_mode ); #endif int16_t lsp_convert_poly( float w[], /* i/o: LSP or ISP parameters */ @@ -1798,8 +1795,8 @@ void hq_configure( /*! r: Consumed bits */ int16_t hvq_enc( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const int16_t bwidth, /* i : audio bandwidth */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const int16_t bwidth, /* i : audio bandwidth */ const int32_t core_brate, /* i : core bitrate */ const int16_t hvq_bits, /* i : HVQ bit budget */ const int16_t Npeaks, /* i : Number of peaks */ @@ -2252,13 +2249,13 @@ void bit_allocation_second_fx2( const Word16 input_frame ); void io_ini_enc( - const int32_t argc, /* i : command line arguments number */ - char *argv[], /* i : command line arguments */ - FILE **f_input, /* o : input signal file */ - FILE **f_stream, /* o : output bitstream file */ - FILE **f_rate, /* o : bitrate switching profile (0 if N/A) */ - FILE **f_bwidth, /* o : bandwidth switching profile (0 if N/A) */ - FILE **f_metadata, /* o : metadata files (NULL if N/A) */ + const int32_t argc, /* i : command line arguments number */ + char *argv[], /* i : command line arguments */ + FILE **f_input, /* o : input signal file */ + FILE **f_stream, /* o : output bitstream file */ + FILE **f_rate, /* o : bitrate switching profile (0 if N/A) */ + FILE **f_bwidth, /* o : bandwidth switching profile (0 if N/A) */ + FILE **f_metadata, /* o : metadata files (NULL if N/A) */ FILE **f_rf, /* o : channel aware configuration file */ int16_t *quietMode, /* o : limit printouts */ int16_t *noDelayCmp, /* o : turn off delay compensation */ @@ -2303,14 +2300,14 @@ ivas_error init_encoder( ); ivas_error init_encoder_ivas_fx( - Encoder_State *st, /* i/o: state structure */ - Encoder_Struct *st_ivas, /* i/o: encoder state structure */ - const Word16 idchan, /* i : channel ID */ - const Word16 var_SID_rate_flag, /* i : flag for variable SID update rate */ - const Word16 interval_SID, /* i : interval for SID update */ - const Word16 vad_only_flag, /* i : flag to indicate front-VAD structure */ - const ISM_MODE ism_mode, /* i : ISM mode */ - const Word32 element_brate /* i : element bitrate */ + Encoder_State *st, /* i/o: state structure */ + Encoder_Struct *st_ivas, /* i/o: encoder state structure */ + const Word16 idchan, /* i : channel ID */ + const Word16 var_SID_rate_flag, /* i : flag for variable SID update rate */ + const Word16 interval_SID, /* i : interval for SID update */ + const Word16 vad_only_flag, /* i : flag to indicate front-VAD structure */ + const ISM_MODE ism_mode, /* i : ISM mode */ + const Word32 element_brate /* i : element bitrate */ ); void LPDmem_enc_init( @@ -2342,14 +2339,14 @@ void amr_wb_enc_init( ); void pre_proc( - Encoder_State *st, /* i/o: encoder state structure */ - const int16_t input_frame, /* i : frame length */ - float old_inp_12k8[], /* i/o: buffer of old input signal */ - float old_inp_16k[], /* i/o: buffer of old input signal @ 16kHz */ - float **inp, /* o : ptr. to inp. signal in the current frame*/ - float fr_bands[2 * NB_BANDS], /* i : energy in frequency bands */ - float *ener, /* o : residual energy from Levinson-Durbin */ - int16_t pitch_orig[3], /* o : open-loop pitch values for quantization */ + Encoder_State *st, /* i/o: encoder state structure */ + const int16_t input_frame, /* i : frame length */ + float old_inp_12k8[], /* i/o: buffer of old input signal */ + float old_inp_16k[], /* i/o: buffer of old input signal @ 16kHz */ + float **inp, /* o : ptr. to inp. signal in the current frame*/ + float fr_bands[2 * NB_BANDS], /* i : energy in frequency bands */ + float *ener, /* o : residual energy from Levinson-Durbin */ + int16_t pitch_orig[3], /* o : open-loop pitch values for quantization */ float A[NB_SUBFR16k * ( M + 1 )], /* i/o: A(z) unquantized for the 4 subframes */ float Aw[NB_SUBFR16k * ( M + 1 )], /* i/o: weighted A(z) unquantized for subframes */ float epsP[M + 1], /* i/o: LP prediction errors */ @@ -2406,7 +2403,7 @@ ivas_error acelp_core_enc( float pitch_buf[NB_SUBFR16k], /* o : floating pitch for each subframe */ int16_t *unbits, /* o : number of unused bits */ STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ - float tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ + float tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ ); ivas_error acelp_core_switch_dec_bfi( @@ -2711,13 +2708,13 @@ void flip_and_downmix_generic( int16_t *phase_state /* i/o: Phase state in case frequency isn't multiple of 50 Hz */ ); void flip_and_downmix_generic_fx_32( - Word32 input[], /* i : input spectrum Qx*/ - Word32 output[], /* o : output spectrum Qx*/ - const Word16 length, /* i : length of spectra */ - Word32 mem1_ext[HILBERT_ORDER1], /* i/o: memory Qx*/ - Word32 mem2_ext[2 * HILBERT_ORDER2], /* i/o: memory Qx*/ - Word32 mem3_ext[2 * HILBERT_ORDER2], /* i/o: memory Qx*/ - Word16* phase_state /* i/o: Phase state in case frequency isn't multiple of 50 Hz */ + Word32 input[], /* i : input spectrum Qx*/ + Word32 output[], /* o : output spectrum Qx*/ + const Word16 length, /* i : length of spectra */ + Word32 mem1_ext[HILBERT_ORDER1], /* i/o: memory Qx*/ + Word32 mem2_ext[2 * HILBERT_ORDER2], /* i/o: memory Qx*/ + Word32 mem3_ext[2 * HILBERT_ORDER2], /* i/o: memory Qx*/ + Word16 *phase_state /* i/o: Phase state in case frequency isn't multiple of 50 Hz */ ); void non_linearity( const float input[], /* i : input signal */ @@ -2809,13 +2806,13 @@ void GenTransition( void GenTransition_fixed( - TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ - Word32 *outputHB_fx, /* o : synthesized HB transitions signal */ - const int32_t output_Fs, /* i : output sampling rate */ - const int16_t element_mode, /* i : element mode */ - const int16_t L_frame, /* i : ACELP frame length */ - const int16_t rf_flag, /* i : RF flag */ - const int32_t total_brate /* i : total bitrate */ + TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ + Word32 *outputHB_fx, /* o : synthesized HB transitions signal */ + const int32_t output_Fs, /* i : output sampling rate */ + const int16_t element_mode, /* i : element mode */ + const int16_t L_frame, /* i : ACELP frame length */ + const int16_t rf_flag, /* i : RF flag */ + const int32_t total_brate /* i : total bitrate */ ); void GenTransition_WB( @@ -2825,9 +2822,9 @@ void GenTransition_WB( ); void GenTransition_WB_fixed( - TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ - Word32 *outputHB_fx, /* o : synthesized HB transitions signal */ - const int32_t output_Fs /* i : output sampling rate */ + TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ + Word32 *outputHB_fx, /* o : synthesized HB transitions signal */ + const int32_t output_Fs /* i : output sampling rate */ ); void td_bwe_dec_init( @@ -2941,12 +2938,12 @@ void swb_bwe_dec_flt( #ifdef IVAS_FLOAT_FIXED Word16 swb_bwe_dec_fx32( - Decoder_State *st, /* i/o: decoder state structure */ - Word32 output[], /* i : synthesis @internal Fs Q11 */ - Word32 *synth, /* i : ACELP core synthesis/final synthesis Q11 */ - Word32 *hb_synth, /* o : SHB synthesis/final synthesis */ - Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ - Word16 output_frame /* i : frame length */ + Decoder_State *st, /* i/o: decoder state structure */ + Word32 output[], /* i : synthesis @internal Fs Q11 */ + Word32 *synth, /* i : ACELP core synthesis/final synthesis Q11 */ + Word32 *hb_synth, /* o : SHB synthesis/final synthesis */ + Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ + Word16 output_frame /* i : frame length */ ); #endif // IVAS_FLOAT_FIXED @@ -4631,46 +4628,46 @@ void signaling_enc_rf( #ifndef IVAS_FLOAT_FIXED ivas_error acelp_core_dec( - Decoder_State *st, /* i/o: Decoder state structure */ - float output[], /* o : synthesis @internal Fs */ - float synth[], /* o : synthesis */ - float save_hb_synth[], /* o : HB synthesis */ - float bwe_exc_extended[], /* i/o: bandwidth extended excitation */ - float *voice_factors, /* o : voicing factors */ - float old_syn_12k8_16k[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE */ - const int16_t sharpFlag, /* i : formant sharpening flag */ - float pitch_buf[NB_SUBFR16k], /* o : floating pitch for each subframe */ - int16_t *unbits, /* o : number of unused bits */ - int16_t *sid_bw, /* o : 0-NB/WB, 1-SWB SID */ - STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle */ - const float tdm_lspQ_PCh[M], /* i : Q LSPs for primary channel */ - const float tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */ - const int16_t use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ - const int16_t last_element_mode, /* i : last element mode */ - const int32_t last_element_brate, /* i : last element bitrate */ - const int16_t flag_sec_CNA, /* i : CNA flag for secondary channel */ - const int16_t nchan_out, /* i : number of output channels */ - STEREO_CNG_DEC_HANDLE hStereoCng, /* i : stereo CNG handle */ - const int16_t read_sid_info /* i : read SID info flag */ + Decoder_State *st, /* i/o: Decoder state structure */ + float output[], /* o : synthesis @internal Fs */ + float synth[], /* o : synthesis */ + float save_hb_synth[], /* o : HB synthesis */ + float bwe_exc_extended[], /* i/o: bandwidth extended excitation */ + float *voice_factors, /* o : voicing factors */ + float old_syn_12k8_16k[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE */ + const int16_t sharpFlag, /* i : formant sharpening flag */ + float pitch_buf[NB_SUBFR16k], /* o : floating pitch for each subframe */ + int16_t *unbits, /* o : number of unused bits */ + int16_t *sid_bw, /* o : 0-NB/WB, 1-SWB SID */ + STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle */ + const float tdm_lspQ_PCh[M], /* i : Q LSPs for primary channel */ + const float tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */ + const int16_t use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ + const int16_t last_element_mode, /* i : last element mode */ + const int32_t last_element_brate, /* i : last element bitrate */ + const int16_t flag_sec_CNA, /* i : CNA flag for secondary channel */ + const int16_t nchan_out, /* i : number of output channels */ + STEREO_CNG_DEC_HANDLE hStereoCng, /* i : stereo CNG handle */ + const int16_t read_sid_info /* i : read SID info flag */ ); #endif #ifdef IVAS_FLOAT_FIXED ivas_error acelp_core_dec_ivas_fx( Decoder_State *st, /* i/o: decoder state structure */ - Word16 output[], /* o : synthesis @internal Fs */ - Word16 synth[], /* o : synthesis */ - Word16 save_hb_synth[], /* o : HB synthesis */ - Word32 bwe_exc_extended[], /* i/o: bandwidth extended excitation */ - Word16 *voice_factors, /* o : voicing factors */ - Word16 old_syn_12k8_16k[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE */ + Word16 output[], /* o : synthesis @internal Fs */ + Word16 synth[], /* o : synthesis */ + Word16 save_hb_synth[], /* o : HB synthesis */ + Word32 bwe_exc_extended[], /* i/o: bandwidth extended excitation */ + Word16 *voice_factors, /* o : voicing factors */ + Word16 old_syn_12k8_16k[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE */ const int16_t sharpFlag, /* i : formant sharpening flag */ - Word16 pitch_buf[NB_SUBFR16k], /* o : floating pitch for each subframe */ + Word16 pitch_buf[NB_SUBFR16k], /* o : floating pitch for each subframe */ int16_t *unbits, /* o : number of unused bits */ int16_t *sid_bw, /* o : 0-NB/WB, 1-SWB SID */ STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle */ - const Word16 tdm_lspQ_PCh[M], /* i : Q LSPs for primary channel */ - const Word16 tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */ + const Word16 tdm_lspQ_PCh[M], /* i : Q LSPs for primary channel */ + const Word16 tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */ const int16_t use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ const int16_t last_element_mode, /* i : last element mode */ const int32_t last_element_brate, /* i : last element bitrate */ @@ -5380,12 +5377,12 @@ void wtda( #ifdef IVAS_FLOAT_FIXED void wtda_fx32( - const Word32 *new_audio, /* i : input audio Q11 */ - Word32 *wtda_audio, /* o : windowed audio Q11 */ - Word32 *old_wtda, /* i/o: windowed audio from previous frame Q11 */ - const Word16 left_mode, /* i : window overlap of previous frame (0: full, 2: none, or 3: half) */ - const Word16 right_mode, /* i : window overlap of current frame (0: full, 2: none, or 3: half) */ - const Word16 L /* i : length */ + const Word32 *new_audio, /* i : input audio Q11 */ + Word32 *wtda_audio, /* o : windowed audio Q11 */ + Word32 *old_wtda, /* i/o: windowed audio from previous frame Q11 */ + const Word16 left_mode, /* i : window overlap of previous frame (0: full, 2: none, or 3: half) */ + const Word16 right_mode, /* i : window overlap of current frame (0: full, 2: none, or 3: half) */ + const Word16 L /* i : length */ ); #endif @@ -6076,9 +6073,9 @@ ivas_error core_switching_pre_dec_ivas_fx( const Word32 last_core_brate_st0, /* i : channel 0 last core bitrate */ const Word16 nchan_out, /* i : number of output channels */ const Word16 last_element_mode, /* i : last_element_mode */ - const Word32 last_element_brate, /* i : last element bitrate */ + const Word32 last_element_brate, /* i : last element bitrate */ Word16 Q_old_synthFB, - Word16 *Q_olapBufferSynth , + Word16 *Q_olapBufferSynth, Word16 *Q_olapBufferSynth2 ); #endif // IVAS_FLOAT_FIXED @@ -6184,7 +6181,7 @@ void synthesise_fb_high_band( const float excitation_in[], /* i : full band excitation */ float output[], /* o : high band speech - 14.0 to 20 kHz */ const float fb_exc_energy, /* i : full band excitation energy */ - const float ratio_float, /* i : energy ratio */ + const float ratio_float, /* i : energy ratio */ const int16_t L_frame, /* i : ACELP frame length */ const int16_t bfi, /* i : BFI flag */ float *prev_fbbwe_ratio, /* o : previous frame energy for FEC */ @@ -6369,8 +6366,8 @@ void reverse_transient_frame_energies( ); int16_t peak_vq_enc( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const int16_t bwidth, /* i : audio bandwidth */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const int16_t bwidth, /* i : audio bandwidth */ const float *coefs, /* i : Input coefficient vector */ float *coefs_out, /* o : Quantized output vector */ const int32_t core_brate, /* i : Core bitrate */ @@ -6920,10 +6917,10 @@ void hp20_flt( #ifdef IVAS_FLOAT_FIXED void hp20_fix32( - Word32 signal_fx[], - const Word16 lg, - Word32 mem_fx[], - const Word32 Fs); + Word32 signal_fx[], + const Word16 lg, + Word32 mem_fx[], + const Word32 Fs ); #endif // IVAS_FLOAT_FIXED void ham_cos_window_flt( @@ -6966,8 +6963,8 @@ void enc_acelp_tcx_main( ); void getTCXMode_ivas( - Decoder_State *st, /* i/o: decoder memory state */ - Decoder_State *st0, /* i : bitstream */ + Decoder_State *st, /* i/o: decoder memory state */ + Decoder_State *st0, /* i : bitstream */ const Word16 MCT_flag /* i : hMCT handle allocated (1) or not (0)*/ ); @@ -6975,8 +6972,8 @@ void getTCXWindowing_ivas( const Word16 core, /* i : current frame mode */ const Word16 last_core, /* i : last frame mode */ const Word16 element_mode, /* i : element mode */ - TCX_CONFIG_HANDLE hTcxCfg, /* i/o: TCX configuration handle */ - Decoder_State *st0 /* i : bitstream */ + TCX_CONFIG_HANDLE hTcxCfg, /* i/o: TCX configuration handle */ + Decoder_State *st0 /* i : bitstream */ ); void getLPCparam_ivas( @@ -7847,9 +7844,8 @@ int16_t ari_start_decoding_14bits_prm_ivas( #ifdef IVAS_FLOAT_FIXED Word16 ari_start_decoding_14bits_prm_ivas_fx( const Word16 *ptr, - Word16 bp, - Tastat *s -); + Word16 bp, + Tastat *s ); #endif void ari_decode_14bits_s17_ext_ivas( @@ -7998,11 +7994,11 @@ void UnmapIndex_ivas( void UnmapIndex_fx( const Word16 PeriodicityIndex, - const Word16 Bandwidth, + const Word16 Bandwidth, const Word16 LtpPitchLag, - const Word8 SmallerLags, + const Word8 SmallerLags, Word16 *FractionalResolution, - Word32 *Lag); + Word32 *Lag ); /*! r: PeriodicityIndex */ int16_t SearchPeriodicityIndex( @@ -8033,7 +8029,7 @@ int16_t CountIndexBits_ivas( const int16_t PeriodicityIndex ); Word16 CountIndexBits_fx( - Word16 Bandwidth, /* 0: NB, 1: (S)WB */ + Word16 Bandwidth, /* 0: NB, 1: (S)WB */ Word16 PeriodicityIndex ); int16_t DecodeIndex( @@ -8820,8 +8816,7 @@ void deleteFdCngCom_flt( void initFdCngCom_flt( HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ - const float scale -); + const float scale ); void initPartitions_flt( @@ -8897,13 +8892,13 @@ void generate_masking_noise_ivas_fx( Word32 *timeDomainBuffer, /* i/o: time-domain signal */ Word16 *exp_out, /* o : time-domain signal exp */ HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ - const Word16 length, /* i : frame size */ - const Word16 core, /* i : core */ - const Word16 return_noise, /* i : noise is returned instead of added */ - const Word16 secondary, /* i : flag to indicate secondary noise generation */ - const Word16 element_mode, /* i : element mode */ + const Word16 length, /* i : frame size */ + const Word16 core, /* i : core */ + const Word16 return_noise, /* i : noise is returned instead of added */ + const Word16 secondary, /* i : flag to indicate secondary noise generation */ + const Word16 element_mode, /* i : element mode */ STEREO_CNG_DEC_HANDLE hStereoCng, /* i : stereo CNG handle */ - const Word16 nchan_out /* i : number of output channels */ + const Word16 nchan_out /* i : number of output channels */ ); #endif @@ -8957,7 +8952,7 @@ void generate_stereo_masking_noise( #ifdef IVAS_FLOAT_FIXED void generate_stereo_masking_noise_fx( - Word16 *syn, /* i/o: time-domain signal */ + Word16 *syn, /* i/o: time-domain signal */ Word16 Q_syn, Decoder_State *st, /* i/o: decoder state structure */ STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i : TD stereo structure */ @@ -8987,12 +8982,12 @@ void expand_range_flt( const int16_t len ); void bandcombinepow_flt( - const float *bandpow, /* i : Power for each band */ - const int16_t nband, /* i : Number of bands */ - int16_t *part, /* i : Partition upper boundaries (band indices starting from 0) */ - const int16_t npart, /* i : Number of partitions */ + const float *bandpow, /* i : Power for each band */ + const int16_t nband, /* i : Number of bands */ + int16_t *part, /* i : Partition upper boundaries (band indices starting from 0) */ + const int16_t npart, /* i : Number of partitions */ const float *psize_inv_flt, /* i : Inverse partition sizes */ - float *partpow /* o : Power for each partition */ + float *partpow /* o : Power for each partition */ ); void scalebands_flt( @@ -9197,43 +9192,43 @@ void ReadFromBitstream( int16_t **pStream, int16_t *pnSize ); -//void const *GetTnsFilterOrder_flt( void const *p, const int16_t index, int16_t *pValue ); -//void *SetTnsFilterOrder_flt( void *p, const int16_t index, const int16_t value ); -void const *GetNumOfTnsFilters_flt (void const *p, const int16_t index, int16_t *pValue); +// void const *GetTnsFilterOrder_flt( void const *p, const int16_t index, int16_t *pValue ); +// void *SetTnsFilterOrder_flt( void *p, const int16_t index, const int16_t value ); +void const *GetNumOfTnsFilters_flt( void const *p, const int16_t index, int16_t *pValue ); void *SetNumOfTnsFilters_flt( void *p, const int16_t index, const int16_t value ); -//void const *GetTnsEnabled_flt( void const *p, const int16_t index, int16_t *pValue ); -//void *SetTnsEnabled_flt( void *p, const int16_t index, const int16_t value ); -//void const *GetTnsEnabledSingleFilter_flt( void const *p, const int16_t index, int16_t *pValue ); -//void *SetTnsEnabledSingleFilter_flt( void *p, const int16_t index, const int16_t value ); -//void const *GetTnsFilterCoeff_flt( void const *p, const int16_t index, int16_t *pValue ); -//void *SetTnsFilterCoeff_flt( void *p, const int16_t index, const int16_t value ); +// void const *GetTnsEnabled_flt( void const *p, const int16_t index, int16_t *pValue ); +// void *SetTnsEnabled_flt( void *p, const int16_t index, const int16_t value ); +// void const *GetTnsEnabledSingleFilter_flt( void const *p, const int16_t index, int16_t *pValue ); +// void *SetTnsEnabledSingleFilter_flt( void *p, const int16_t index, const int16_t value ); +// void const *GetTnsFilterCoeff_flt( void const *p, const int16_t index, int16_t *pValue ); +// void *SetTnsFilterCoeff_flt( void *p, const int16_t index, const int16_t value ); void const *GetTnsOnWhite( void const *p, const int16_t index, int16_t *pValue ); void *SetTnsOnWhite( void *p, const int16_t index, const int16_t value ); -//int16_t GetSWBTCX10TnsFilterCoeffBits_flt( const int16_t value, const int16_t index ); -//int16_t EncodeSWBTCX10TnsFilterCoeff_flt( const int16_t value, const int16_t index ); +// int16_t GetSWBTCX10TnsFilterCoeffBits_flt( const int16_t value, const int16_t index ); +// int16_t EncodeSWBTCX10TnsFilterCoeff_flt( const int16_t value, const int16_t index ); int16_t DecodeSWBTCX10TnsFilterCoeff_flt( Decoder_State *st, const int16_t index, int16_t *pValue ); -//int16_t GetSWBTCX20TnsFilterCoeffBits_flt( const int16_t value, const int16_t index ); -//int16_t EncodeSWBTCX20TnsFilterCoeff_flt( const int16_t value, const int16_t index ); +// int16_t GetSWBTCX20TnsFilterCoeffBits_flt( const int16_t value, const int16_t index ); +// int16_t EncodeSWBTCX20TnsFilterCoeff_flt( const int16_t value, const int16_t index ); int16_t DecodeSWBTCX20TnsFilterCoeff_flt( Decoder_State *st, const int16_t index, int16_t *pValue ); -//int16_t GetWBTCX20TnsFilterCoeffBits_flt( const int16_t value, const int16_t index ); -//int16_t EncodeWBTCX20TnsFilterCoeff_flt( const int16_t, const int16_t index ); +// int16_t GetWBTCX20TnsFilterCoeffBits_flt( const int16_t value, const int16_t index ); +// int16_t EncodeWBTCX20TnsFilterCoeff_flt( const int16_t, const int16_t index ); int16_t DecodeWBTCX20TnsFilterCoeff_flt( Decoder_State *st, const int16_t index, int16_t *pValue ); -//int16_t GetTnsFilterOrderBitsSWBTCX10_flt( const int16_t value, const int16_t index ); -//int16_t EncodeTnsFilterOrderSWBTCX10_flt( const int16_t value, const int16_t index ); +// int16_t GetTnsFilterOrderBitsSWBTCX10_flt( const int16_t value, const int16_t index ); +// int16_t EncodeTnsFilterOrderSWBTCX10_flt( const int16_t value, const int16_t index ); int16_t DecodeTnsFilterOrderSWBTCX10_flt( Decoder_State *st, const int16_t index, int16_t *pValue ); -//int16_t GetTnsFilterOrderBitsSWBTCX20_flt( const int16_t value, const int16_t index ); -//int16_t EncodeTnsFilterOrderSWBTCX20_flt( const int16_t value, const int16_t index ); +// int16_t GetTnsFilterOrderBitsSWBTCX20_flt( const int16_t value, const int16_t index ); +// int16_t EncodeTnsFilterOrderSWBTCX20_flt( const int16_t value, const int16_t index ); int16_t DecodeTnsFilterOrderSWBTCX20_flt( Decoder_State *st, const int16_t index, int16_t *pValue ); -int16_t EncodeTnsFilterOrderSWBTCX10_flt(const int16_t value, const int16_t index); +int16_t EncodeTnsFilterOrderSWBTCX10_flt( const int16_t value, const int16_t index ); -int16_t GetTnsFilterOrderBitsSWBTCX10_flt(const int16_t value, const int16_t index); -//int16_t GetTnsFilterOrderBits_flt( const int16_t value, const int16_t index ); -//int16_t EncodeTnsFilterOrder_flt( const int16_t value, const int16_t index ); +int16_t GetTnsFilterOrderBitsSWBTCX10_flt( const int16_t value, const int16_t index ); +// int16_t GetTnsFilterOrderBits_flt( const int16_t value, const int16_t index ); +// int16_t EncodeTnsFilterOrder_flt( const int16_t value, const int16_t index ); int16_t DecodeTnsFilterOrder_flt( Decoder_State *st, const int16_t index, int16_t *pValue ); void ResetTnsData_flt( diff --git a/lib_com/prot_fx1.h b/lib_com/prot_fx1.h index 87e20a37d..db593758b 100644 --- a/lib_com/prot_fx1.h +++ b/lib_com/prot_fx1.h @@ -40,8 +40,8 @@ #include "typedef.h" #include "cnst.h" #include "stl.h" -#define mvr2r_Word32(x,y,n) Copy32(x,y,n) -#define mvr2r_Word16(x,y,n) Copy(x,y,n) +#define mvr2r_Word32( x, y, n ) Copy32( x, y, n ) +#define mvr2r_Word16( x, y, n ) Copy( x, y, n ) int16_t norm_ul( uint32_t UL_var1 ); Word16 usdequant_fx( /* Qx*/ @@ -169,39 +169,39 @@ void sort_fx( Word16 up /* I : High limit of sorting range */ ); void sort_32_fx( - Word32 *r, /* i/o: Vector to be sorted in place */ - const Word16 lo, /* i : Low limit of sorting range */ - const Word16 up /* I : High limit of sorting range */ + Word32 *r, /* i/o: Vector to be sorted in place */ + const Word16 lo, /* i : Low limit of sorting range */ + const Word16 up /* I : High limit of sorting range */ ); -Word16 minimum_fx( /* o : index of the minimum value in the input vector */ - const Word16 *vec_fx, /* i : input vector */ - const Word16 lvec_fx, /* i : length of input vector */ - Word16 *min_fx /* o : minimum value in the input vector */ +Word16 minimum_fx( /* o : index of the minimum value in the input vector */ + const Word16 *vec_fx, /* i : input vector */ + const Word16 lvec_fx, /* i : length of input vector */ + Word16 *min_fx /* o : minimum value in the input vector */ ); -Word16 maximum_fx( /* o : index of the maximum value in the input vector */ - const Word16 *vec_fx, /* i : input vector */ - const Word16 lvec_fx, /* i : length of input vector */ - Word16 *max_fx /* o : maximum value in the input vector */ +Word16 maximum_fx( /* o : index of the maximum value in the input vector */ + const Word16 *vec_fx, /* i : input vector */ + const Word16 lvec_fx, /* i : length of input vector */ + Word16 *max_fx /* o : maximum value in the input vector */ ); Word16 minimum_abs32_fx( /* o : index of the minimum value in the input vector */ - const Word32 *vec_fx, /* i : input vector */ - const Word16 lvec_fx, /* i : length of input vector */ - Word32 *min_fx /* o : minimum value in the input vector */ + const Word32 *vec_fx, /* i : input vector */ + const Word16 lvec_fx, /* i : length of input vector */ + Word32 *min_fx /* o : minimum value in the input vector */ ); Word16 minimum_32_fx( /* o : index of the minimum value in the input vector */ const Word32 *vec_fx, /* i : input vector */ const Word16 lvec_fx, /* i : length of input vector */ Word32 *min_fx /* o : minimum value in the input vector */ ); -Word16 maximum_32_fx( /* o : index of the maximum value in the input vector */ - const Word32 *vec, /* i : input vector */ - const Word16 lvec, /* i : length of input vector */ - Word32 *max_val /* o : maximum value in the input vector */ +Word16 maximum_32_fx( /* o : index of the maximum value in the input vector */ + const Word32 *vec, /* i : input vector */ + const Word16 lvec, /* i : length of input vector */ + Word32 *max_val /* o : maximum value in the input vector */ ); -Word16 maximum_abs_32_fx( /* o : index of the maximum value in the input vector */ - const Word32 *vec, /* i : input vector */ - const Word16 lvec, /* i : length of input vector */ - Word32 *max_val /* o : maximum value in the input vector */ +Word16 maximum_abs_32_fx( /* o : index of the maximum value in the input vector */ + const Word32 *vec, /* i : input vector */ + const Word16 lvec, /* i : length of input vector */ + Word32 *max_val /* o : maximum value in the input vector */ ); #ifdef IVAS_FLOAT_FIXED /*! r: index of the maximum value in the input vector */ @@ -223,30 +223,30 @@ Word16 Exp16Array( const Word16 *sx /* (i): Data array */ ); Word16 Exp32Array( - const Word16 n, /* (i): Array size */ - const Word32 *sx /* (i): Data array */ + const Word16 n, /* (i): Array size */ + const Word32 *sx /* (i): Data array */ ); -Word32 sum16_32_fx( /* o : sum of all vector elements Qx*/ - const Word16 *vec, /* i : input vector Qx*/ - const Word16 lvec /* i : length of input vector */ +Word32 sum16_32_fx( /* o : sum of all vector elements Qx*/ + const Word16 *vec, /* i : input vector Qx*/ + const Word16 lvec /* i : length of input vector */ ); -Word32 sum32_sat( /* o : sum of all vector elements Qx*/ - const Word32 *vec, /* i : input vector Qx*/ - const Word16 lvec /* i : length of input vector */ +Word32 sum32_sat( /* o : sum of all vector elements Qx*/ + const Word32 *vec, /* i : input vector Qx*/ + const Word16 lvec /* i : length of input vector */ ); -Word32 var_fx_32( /* o: variance of vector Qx+16*/ - const Word16 *x, /* i: input vector Qx*/ +Word32 var_fx_32( /* o: variance of vector Qx+16*/ + const Word16 *x, /* i: input vector Qx*/ const Word16 Qx, - const Word16 len /* i: length of inputvector */ + const Word16 len /* i: length of inputvector */ ); -Word16 var_fx( /* o: variance of vector Qx*/ - const Word16 *x, /* i: input vector Qx*/ +Word16 var_fx( /* o: variance of vector Qx*/ + const Word16 *x, /* i: input vector Qx*/ const Word16 Qx, - const Word16 len /* i: length of inputvector */ + const Word16 len /* i: length of inputvector */ ); -Word16 std_fx( /* o: standard deviation */ - const Word16 x[], /* i: input vector */ - const Word16 len /* i: length of the input vector */ +Word16 std_fx( /* o: standard deviation */ + const Word16 x[], /* i: input vector */ + const Word16 len /* i: length of the input vector */ ); Word32 dot_product_mat_fx( /* o : the dot product x'*A*x */ const Word16 *x, /* i : vector x Q15 */ @@ -255,10 +255,10 @@ Word32 dot_product_mat_fx( /* o : the dot product x'*A*x ); void Vr_subt( - const Word16 x1[], /* i : Input vector 1 */ - const Word16 x2[], /* i : Input vector 2 */ - Word16 y[], /* o : Output vector that contains vector 1 - vector 2 */ - Word16 N /* i : Vector lenght */ + const Word16 x1[], /* i : Input vector 1 */ + const Word16 x2[], /* i : Input vector 2 */ + Word16 y[], /* o : Output vector that contains vector 1 - vector 2 */ + Word16 N /* i : Vector lenght */ ); Word16 vquant_fx( /* o: index of the winning codevector */ Word16 x[], /* i: vector to quantize Q13 */ @@ -269,13 +269,13 @@ Word16 vquant_fx( /* o: index of the winning codevector const Word16 cbsize /* i: codebook size */ ); Word16 w_vquant_fx( - Word16 x[], /* i: vector to quantize in Q10 */ + Word16 x[], /* i: vector to quantize in Q10 */ Word16 Qx, - const Word16 weights[], /* i: error weights in Q0 */ - Word16 xq[], /* o: quantized vector in Q15 */ - const Word16 cb[], /* i: codebook in Q15 */ - const Word16 cbsize, /* i: codebook size */ - const Word16 rev_vect /* i: reverse codebook vectors */ + const Word16 weights[], /* i: error weights in Q0 */ + Word16 xq[], /* o: quantized vector in Q15 */ + const Word16 cb[], /* i: codebook in Q15 */ + const Word16 cbsize, /* i: codebook size */ + const Word16 rev_vect /* i: reverse codebook vectors */ ); Word16 emaximum_fx( /* o : return index with max energy value in vector Q0 */ const Word16 Qvec, /* i : Q of input vector Q0 */ @@ -289,20 +289,20 @@ Word16 emaximum_32fx( /* o : return index with max energy va const Word16 lvec, /* i : length of input vector Q0 */ Word32 *ener_max /* o : maximum energy value Q0 */ ); -Word32 Mean32( /* o : mean of the elements of the vector */ - const Word32 in[], /* i : input vector */ - const Word16 L /* i : length of input vector */ +Word32 Mean32( /* o : mean of the elements of the vector */ + const Word32 in[], /* i : input vector */ + const Word16 L /* i : length of input vector */ ); -Word32 sum32_fx( /* o : sum of all vector elements Qx*/ - const Word32 *vec, /* i : input vector Qx*/ - const Word16 lvec /* i : length of input vector */ +Word32 sum32_fx( /* o : sum of all vector elements Qx*/ + const Word32 *vec, /* i : input vector Qx*/ + const Word16 lvec /* i : length of input vector */ ); -Word16 sum16_fx( /* o : sum of all vector elements Qx*/ - const Word16 *vec, /* i : input vector Qx*/ - const Word16 lvec /* i : length of input vector */ +Word16 sum16_fx( /* o : sum of all vector elements Qx*/ + const Word16 *vec, /* i : input vector Qx*/ + const Word16 lvec /* i : length of input vector */ ); -Word16 Random( /* o : output random value */ - Word16 *seed /* i/o: random seed */ +Word16 Random( /* o : output random value */ + Word16 *seed /* i/o: random seed */ ); Word16 own_random2_fx( Word16 seed ); void iDiv_and_mod_32( @@ -332,69 +332,70 @@ Word32 root_a_over_b_fx( Word32 b, Word16 Q_b, Word16 *exp_out ); -void fir_fx( const Word16 x[], /* i : input vector Qx*/ - const Word16 h[], /* i : impulse response of the FIR filter Q12*/ - Word16 y[], /* o : output vector (result of filtering) Qx*/ - Word16 mem[], /* i/o: memory of the input signal (L samples) Qx*/ - const Word16 L, /* i : input vector size */ - const Word16 K, /* i : order of the FIR filter (K+1 coefs.) */ - const Word16 upd /* i : 1 = update the memory, 0 = not */ +void fir_fx( const Word16 x[], /* i : input vector Qx*/ + const Word16 h[], /* i : impulse response of the FIR filter Q12*/ + Word16 y[], /* o : output vector (result of filtering) Qx*/ + Word16 mem[], /* i/o: memory of the input signal (L samples) Qx*/ + const Word16 L, /* i : input vector size */ + const Word16 K, /* i : order of the FIR filter (K+1 coefs.) */ + const Word16 upd /* i : 1 = update the memory, 0 = not */ , - Word16 shift /* i : difference between Q15 and scaling of h[] */ + Word16 shift /* i : difference between Q15 and scaling of h[] */ ); -void fir_fx(const Word16 x[], /* i : input vector Qx*/ - const Word16 h[], /* i : impulse response of the FIR filter Q12*/ - Word16 y[], /* o : output vector (result of filtering) Qx*/ - Word16 mem[], /* i/o: memory of the input signal (L samples) Qx*/ - const Word16 L, /* i : input vector size */ - const Word16 K, /* i : order of the FIR filter (K+1 coefs.) */ - const Word16 upd /* i : 1 = update the memory, 0 = not */ - , Word16 shift /* i : difference between Q15 and scaling of h[] */ +void fir_fx( const Word16 x[], /* i : input vector Qx*/ + const Word16 h[], /* i : impulse response of the FIR filter Q12*/ + Word16 y[], /* o : output vector (result of filtering) Qx*/ + Word16 mem[], /* i/o: memory of the input signal (L samples) Qx*/ + const Word16 L, /* i : input vector size */ + const Word16 K, /* i : order of the FIR filter (K+1 coefs.) */ + const Word16 upd /* i : 1 = update the memory, 0 = not */ + , + Word16 shift /* i : difference between Q15 and scaling of h[] */ ); void v_add_32( - const Word32 x1[], /* i : Input vector 1 */ - const Word32 x2[], /* i : Input vector 2 */ - Word32 y[], /* o : Output vector that contains vector 1 + vector 2 */ - const Word16 N /* i : Vector length */ + const Word32 x1[], /* i : Input vector 1 */ + const Word32 x2[], /* i : Input vector 2 */ + Word32 y[], /* o : Output vector that contains vector 1 + vector 2 */ + const Word16 N /* i : Vector length */ ); void v_shr_32( - Word32 x1[], /* i : Input vector 1 */ - Word32 y[], /* o : Output vector that contains vector 1 + vector 2 */ - const Word16 N, /* i : Vector length */ - Word16 shift /*shift value*/ + Word32 x1[], /* i : Input vector 1 */ + Word32 y[], /* o : Output vector that contains vector 1 + vector 2 */ + const Word16 N, /* i : Vector length */ + Word16 shift /*shift value*/ ); void v_sub_32( - const Word32 x1[], /* i : Input vector 1 */ - const Word32 x2[], /* i : Input vector 2 */ - Word32 y[], /* o : Output vector that contains vector 1 - vector 2 */ - const Word16 N /* i : Vector length */ + const Word32 x1[], /* i : Input vector 1 */ + const Word32 x2[], /* i : Input vector 2 */ + Word32 y[], /* o : Output vector that contains vector 1 - vector 2 */ + const Word16 N /* i : Vector length */ ); void v_add_16( - const Word16 x1[], /* i : Input vector 1 */ - const Word16 x2[], /* i : Input vector 2 */ - Word16 y[], /* o : Output vector that contains vector 1 + vector 2 */ - const Word16 N /* i : Vector length */ + const Word16 x1[], /* i : Input vector 1 */ + const Word16 x2[], /* i : Input vector 2 */ + Word16 y[], /* o : Output vector that contains vector 1 + vector 2 */ + const Word16 N /* i : Vector length */ ); void v_sub_16( - const Word16 x1[], /* i : Input vector 1 */ - const Word16 x2[], /* i : Input vector 2 */ - Word16 y[], /* o : Output vector that contains vector 1 - vector 2 */ - const Word16 N /* i : Vector length */ + const Word16 x1[], /* i : Input vector 1 */ + const Word16 x2[], /* i : Input vector 2 */ + Word16 y[], /* o : Output vector that contains vector 1 - vector 2 */ + const Word16 N /* i : Vector length */ ); -Word16 squant_fx( /* o: index of the winning codeword */ - const Word16 x, /* i: scalar value to quantize */ - Word16* xq, /* o: quantized value */ - const Word16 cb[], /* i: codebook */ - const Word16 cbsize /* i: codebook size */ +Word16 squant_fx( /* o: index of the winning codeword */ + const Word16 x, /* i: scalar value to quantize */ + Word16 *xq, /* o: quantized value */ + const Word16 cb[], /* i: codebook */ + const Word16 cbsize /* i: codebook size */ ); void pz_filter_dp_fx( const Word16 b[], @@ -425,10 +426,10 @@ void v_multc_att32( const Word16 N /* i : Vector length */ ); void v_multc_att3232( - const Word32 x[], /* i : Input vector Qx */ - const Word32 att, /* i : Constant Q32, <= MAX_32 */ - Word32 y[], /* o : Output vector that contains att*x */ - const Word16 N /* i : Vector length */ + const Word32 x[], /* i : Input vector Qx */ + const Word32 att, /* i : Constant Q32, <= MAX_32 */ + Word32 y[], /* o : Output vector that contains att*x */ + const Word16 N /* i : Vector length */ ); void v_L_mult_1616( const Word16 x1[], /* i : Input vector 1 */ @@ -443,32 +444,32 @@ void v_L_mult_3216( const Word16 N /* i : Vector length */ ); void add_vec_fx( - const Word16 x1[], /* i : Input vector 1 */ - const Word16 Qx1, /* i : SCaling of input 1 */ - const Word16 x2[], /* i : Input vector 2 */ - const Word16 Qx2, /* i : SCaling of input 1 */ - Word16 y[], /* o : Output vector that contains vector 1 + vector 2 */ - const Word16 Qy, /* i : SCaling of output 1 */ - const Word16 N /* i : Vector lenght */ -); -Word32 Add_flt32_flt32( /* o: Result (Normalized) */ - Word32 a, /* i: 1st Value */ - Word16 exp_a, /* i: Exponent of 1st Value (Q of Value) */ - Word32 b, /* i: 2nd Value */ - Word16 exp_b, /* i: Exponent of 2nd Value (Q of Value) */ - Word16 *exp_out /* o: Exponent of Result */ -); -Word32 Mul_flt32_Q15( /* o: Result (Normalized) */ - Word32 value, /* i: Pseudo_float Value */ - Word16 *exp_v, /*i/o: Exponent of Value (Q of Value) */ - Word16 frac /* i: Q15 value */ -); -Word32 Div_flt32_flt32( /* o: Result (Normalized) */ - Word32 a, /* i: 1st Value */ - Word16 exp_a, /* i: Exponent of 1st Value (Q of Value) */ - Word32 b, /* i: 2nd Value */ - Word16 exp_b, /* i: Exponent of 2nd Value (Q of Value) */ - Word16 *exp_out /* o: Exponent of Result */ + const Word16 x1[], /* i : Input vector 1 */ + const Word16 Qx1, /* i : SCaling of input 1 */ + const Word16 x2[], /* i : Input vector 2 */ + const Word16 Qx2, /* i : SCaling of input 1 */ + Word16 y[], /* o : Output vector that contains vector 1 + vector 2 */ + const Word16 Qy, /* i : SCaling of output 1 */ + const Word16 N /* i : Vector lenght */ +); +Word32 Add_flt32_flt32( /* o: Result (Normalized) */ + Word32 a, /* i: 1st Value */ + Word16 exp_a, /* i: Exponent of 1st Value (Q of Value) */ + Word32 b, /* i: 2nd Value */ + Word16 exp_b, /* i: Exponent of 2nd Value (Q of Value) */ + Word16 *exp_out /* o: Exponent of Result */ +); +Word32 Mul_flt32_Q15( /* o: Result (Normalized) */ + Word32 value, /* i: Pseudo_float Value */ + Word16 *exp_v, /*i/o: Exponent of Value (Q of Value) */ + Word16 frac /* i: Q15 value */ +); +Word32 Div_flt32_flt32( /* o: Result (Normalized) */ + Word32 a, /* i: 1st Value */ + Word16 exp_a, /* i: Exponent of 1st Value (Q of Value) */ + Word32 b, /* i: 2nd Value */ + Word16 exp_b, /* i: Exponent of 2nd Value (Q of Value) */ + Word16 *exp_out /* o: Exponent of Result */ ); Word32 Calc_Energy_Autoscaled( /* o: Result (Energy) */ const Word16 *signal, /* i: Signal */ @@ -552,26 +553,26 @@ void fft_fx( #endif void delay_signal( - Word16 x[], /* i/o: signal to be delayed */ - const Word16 len, /* i : length of the input signal */ - Word16 mem[], /* i/o: synchronization memory */ - const Word16 delay /* i : delay in samples */ + Word16 x[], /* i/o: signal to be delayed */ + const Word16 len, /* i : length of the input signal */ + Word16 mem[], /* i/o: synchronization memory */ + const Word16 delay /* i : delay in samples */ ); void delay_signal32( - Word32 x[], /* i/o: signal to be delayed */ - const Word16 len, /* i : length of the input signal */ - Word32 mem[], /* i/o: synchronization memory */ - const Word16 delay /* i : delay in samples */ + Word32 x[], /* i/o: signal to be delayed */ + const Word16 len, /* i : length of the input signal */ + Word32 mem[], /* i/o: synchronization memory */ + const Word16 delay /* i : delay in samples */ ); Word16 lin_interp_fx( - const Word16 x, /* i : the value to be mapped */ - const Word16 x1, /* i : source range interval: low end */ - const Word16 y1, /* i : source range interval: high end */ - const Word16 x2, /* i : target range interval: low */ - const Word16 y2, /* i : target range interval: high */ - const Word16 flag_sat /* i : flag to indicate whether to apply saturation */ + const Word16 x, /* i : the value to be mapped */ + const Word16 x1, /* i : source range interval: low end */ + const Word16 y1, /* i : source range interval: high end */ + const Word16 x2, /* i : target range interval: low */ + const Word16 y2, /* i : target range interval: high */ + const Word16 flag_sat /* i : flag to indicate whether to apply saturation */ ); Word16 ceil_log_2( UWord64 val ); @@ -626,4 +627,4 @@ void dctT2_N_apply_matrix_fx( ); #endif -#endif \ No newline at end of file +#endif diff --git a/lib_com/prot_fx2.h b/lib_com/prot_fx2.h index 0e0b04047..8c897e5a9 100644 --- a/lib_com/prot_fx2.h +++ b/lib_com/prot_fx2.h @@ -57,7 +57,7 @@ #include "ivas_error.h" #include "ivas_error_utils.h" #include "complex_basop.h" -#define TCX_IMDCT_SCALE 15 +#define TCX_IMDCT_SCALE 15 #define TCX_IMDCT_HEADROOM 1 /* conversion functions: */ @@ -71,48 +71,48 @@ Word16 float_to_fix16( float number, Word16 Q ); // Word16 to Float float fix16_to_float( Word16 number, Word16 Q ); -Word16 float_to_fix16_thrld(float number, Word16 Q); - -void floatToFixed_arrL( float * f, Word32* i, Word16 Q, Word16 l); -void floatToFixed_arr( float * f, Word16* i, Word16 Q, Word16 l); -void fixedToFloat_arrL( Word32 *i, float * f, Word16 Q, Word16 l); -void fixedToFloat_arr( Word16 *i, float * f, Word16 Q, Word16 l); -void floatToFixed_arrL32(float * f, Word32* i, Word16 Q, Word16 l); -void fixedToFloat_arrL32(Word32 *i, float * f, Word16 Q, Word16 l); -Word16 Q_factor(float x); -Word16 Q_factor_L(float x); -Word16 Q_factor_arr(float* x, Word16 l); -Word16 Q_factor_arrL(float* x, Word16 l); +Word16 float_to_fix16_thrld( float number, Word16 Q ); + +void floatToFixed_arrL( float *f, Word32 *i, Word16 Q, Word16 l ); +void floatToFixed_arr( float *f, Word16 *i, Word16 Q, Word16 l ); +void fixedToFloat_arrL( Word32 *i, float *f, Word16 Q, Word16 l ); +void fixedToFloat_arr( Word16 *i, float *f, Word16 Q, Word16 l ); +void floatToFixed_arrL32( float *f, Word32 *i, Word16 Q, Word16 l ); +void fixedToFloat_arrL32( Word32 *i, float *f, Word16 Q, Word16 l ); +Word16 Q_factor( float x ); +Word16 Q_factor_L( float x ); +Word16 Q_factor_arr( float *x, Word16 l ); +Word16 Q_factor_arrL( float *x, Word16 l ); Word16 Q_factor_L_32( Word32 x ); - //Handles the cases where Q is negative -Word32 floatToFixed( float f, Word16 Q); -float fixedToFloat( Word32 i, Word16 Q); -Word32 floatToFixed_32(float f, Word16 Q); -float fixedToFloat_32(Word32 i, Word16 Q); - -void floatToFixed_arr16(float *f, Word16 *i, Word16 Q, Word16 l); -void floatToFixed_arr32(float *f, Word32 *i, Word16 Q, Word16 l); +// Handles the cases where Q is negative +Word32 floatToFixed( float f, Word16 Q ); +float fixedToFloat( Word32 i, Word16 Q ); +Word32 floatToFixed_32( float f, Word16 Q ); +float fixedToFloat_32( Word32 i, Word16 Q ); + +void floatToFixed_arr16( float *f, Word16 *i, Word16 Q, Word16 l ); +void floatToFixed_arr32( float *f, Word32 *i, Word16 Q, Word16 l ); // Float to 32-bit Mantissa and Exponent using frexp -void f2me(float n, Word32 *mantissa, Word16 *expo); +void f2me( float n, Word32 *mantissa, Word16 *expo ); // 32-bit Mantissa and Exponent to Float using ldexp -float me2f(Word32 m, Word16 expo); +float me2f( Word32 m, Word16 expo ); // Float to 32-bit Mantissa Array and Exponent -void f2me_buf(const float *x, Word32 *m, Word16 *e, const Word32 n); +void f2me_buf( const float *x, Word32 *m, Word16 *e, const Word32 n ); // 32-bit Mantissa Array and Exponent to Float -void me2f_buf(const Word32 *m, const Word16 e, float *out, const Word32 n); +void me2f_buf( const Word32 *m, const Word16 e, float *out, const Word32 n ); // Float to 16-bit Mantissa and Exponent using frexp -void f2me_16(float n, Word16 *mantissa, Word16 *expo); +void f2me_16( float n, Word16 *mantissa, Word16 *expo ); // 16-bit Mantissa and Exponent to Float using ldexp -float me2f_16(Word16 m, Word16 expo); +float me2f_16( Word16 m, Word16 expo ); // Float to 16-bit Mantissa Array and Exponent -void f2me_buf_16(const float *x, Word16 *m, Word16 *e, const Word32 n); +void f2me_buf_16( const float *x, Word16 *m, Word16 *e, const Word32 n ); // 16-bit Mantissa Array and Exponent to Float -void me2f_buf_16(const Word16 *m, const Word16 e, float *out, const Word32 n); +void me2f_buf_16( const Word16 *m, const Word16 e, float *out, const Word32 n ); -void f2fix_16(float *var_flt, Word16 *var_fix, Word32 expo); -void fix2f_16(Word16 *var_fix, float *var_flt, Word32 expo); -void f2fix(float *var_flt, Word32 *var_fix, Word32 expo); -void fix2f(Word32 *var_fix, float *var_flt, Word32 expo); +void f2fix_16( float *var_flt, Word16 *var_fix, Word32 expo ); +void fix2f_16( Word16 *var_fix, float *var_flt, Word32 expo ); +void f2fix( float *var_flt, Word32 *var_fix, Word32 expo ); +void fix2f( Word32 *var_fix, float *var_flt, Word32 expo ); #ifdef IVAS_FLOAT_FIXED // Get max Q factor for a float value before sat in 32-bit @@ -124,60 +124,60 @@ Word16 L_get_q_buf1( float *ptr_flt, Word16 length ); #endif Word32 Mult_32_16( - Word32 a, - Word16 b); + Word32 a, + Word16 b ); Word32 Mult_32_32( - Word32 a, - Word32 b); + Word32 a, + Word32 b ); void Copy32( - const Word32 x[], /* i : i vector */ - Word32 y[], /* o : output vector */ - const Word16 L /* i : vector length */ + const Word32 x[], /* i : i vector */ + Word32 y[], /* o : output vector */ + const Word16 L /* i : vector length */ ); void Vr_add( - const Word16 *in1, /* i : Input vector 1 */ - const Word16 *in2, /* i : Input vector 2 */ - Word16 *out, /* o : Output vector that contains vector 1 + vector 2 */ - Word16 Len /* i : Vector lenght */ + const Word16 *in1, /* i : Input vector 1 */ + const Word16 *in2, /* i : Input vector 2 */ + Word16 *out, /* o : Output vector that contains vector 1 + vector 2 */ + Word16 Len /* i : Vector lenght */ ); void set16_fx( - Word16 y[], /* i/o: Vector to set */ - const Word16 a, /* i : Value to set the vector to */ - const Word16 N /* i : Lenght of the vector */ + Word16 y[], /* i/o: Vector to set */ + const Word16 a, /* i : Value to set the vector to */ + const Word16 N /* i : Lenght of the vector */ ); void set32_fx( - Word32 y[], /* i/o: Vector to set */ - const Word32 a, /* i : Value to set the vector to */ - const Word16 N /* i : Lenght of the vector */ + Word32 y[], /* i/o: Vector to set */ + const Word32 a, /* i : Value to set the vector to */ + const Word16 N /* i : Lenght of the vector */ ); -//tools.c +// tools.c Word16 Random( /* o : output random value */ - Word16 *seed /* i/o: random seed */ + Word16 *seed /* i/o: random seed */ ); -//tools.c +// tools.c void Copy( - const Word16 x[], /* i : i vector */ - Word16 y[], /* o : output vector */ - const Word16 L /* i : vector length */ + const Word16 x[], /* i : i vector */ + Word16 y[], /* o : output vector */ + const Word16 L /* i : vector length */ ); void set64_fx( - Word64 y[], /* i/o: Vector to set */ - const Word64 a, /* i : Value to set the vector to */ - const Word16 N /* i : Lenght of the vector */ + Word64 y[], /* i/o: Vector to set */ + const Word64 a, /* i : Value to set the vector to */ + const Word16 N /* i : Lenght of the vector */ ); void Copy64( - const Word64 x[], /* i : input vector */ - Word64 y[], /* o : output vector */ - const Word16 L /* i : vector length */ + const Word64 x[], /* i : input vector */ + Word64 y[], /* o : output vector */ + const Word16 L /* i : vector length */ ); void Copy_pword( @@ -186,212 +186,202 @@ void Copy_pword( const Word16 L /* i : vector length */ ); -//tools.c +// tools.c void Scale_sig( - Word16 x[], /* i/o: signal to scale Qx */ - const Word16 lg, /* i : size of x[] Q0 */ - const Word16 exp0 /* i : exponent: x = round(x << exp) Qx ?exp */ + Word16 x[], /* i/o: signal to scale Qx */ + const Word16 lg, /* i : size of x[] Q0 */ + const Word16 exp0 /* i : exponent: x = round(x << exp) Qx ?exp */ ); -//tools.c -Word32 sum2_fx( /* o : sum of all squared vector elements Q(2x+1)*/ - const Word16 *vec, /* i : i vector Qx*/ - const Word16 lvec /* i : length of i vector */ +// tools.c +Word32 sum2_fx( /* o : sum of all squared vector elements Q(2x+1)*/ + const Word16 *vec, /* i : i vector Qx*/ + const Word16 lvec /* i : length of i vector */ ); /*========================================================================================================/ mslvq_com_fx.c /========================================================================================================*/ -//mslvq_com_fx +// mslvq_com_fx Word16 deindex_lvq_fx( - Word16 *index, /* i : index to be decoded, as an array of 3 short */ - Word16 *x_lvq, /* o : decoded codevector Q(x2.56)*/ - Word16 mode, /* i : LVQ coding mode (select scales & no_lead ), or idx_cv */ - Word16 sf_flag, /* i : safety net flag */ - Word16 no_bits, /* i : number of bits for lattice */ - Word32 *p_offset_scale1, /* i : offset for first subvector */ - Word32 *p_offset_scale2, /* i : offset for the second subvector */ - Word16 *p_no_scales -); + Word16 *index, /* i : index to be decoded, as an array of 3 short */ + Word16 *x_lvq, /* o : decoded codevector Q(x2.56)*/ + Word16 mode, /* i : LVQ coding mode (select scales & no_lead ), or idx_cv */ + Word16 sf_flag, /* i : safety net flag */ + Word16 no_bits, /* i : number of bits for lattice */ + Word32 *p_offset_scale1, /* i : offset for first subvector */ + Word32 *p_offset_scale2, /* i : offset for the second subvector */ + Word16 *p_no_scales ); void deindex_lvq_SHB_fx( UWord32 index, Word16 *out, const Word16 nbits, - const Word16 mode -); + const Word16 mode ); void permute_fx( - Word16 *pTmp1, /* i/o: vector whose components are to be permuted */ - const Word16 *perm /* i : permutation info (indexes that should be interchanged), max two perms */ + Word16 *pTmp1, /* i/o: vector whose components are to be permuted */ + const Word16 *perm /* i : permutation info (indexes that should be interchanged), max two perms */ ); void init_lvq_fx( - Word32 offset_scale1[][MAX_NO_SCALES + 1], - Word32 offset_scale2[][MAX_NO_SCALES + 1], - Word32 offset_scale1_p[][MAX_NO_SCALES + 1], - Word32 offset_scale2_p[][MAX_NO_SCALES + 1], - Word16 no_scales[][2], - Word16 no_scales_p[][2] -); + Word32 offset_scale1[][MAX_NO_SCALES + 1], + Word32 offset_scale2[][MAX_NO_SCALES + 1], + Word32 offset_scale1_p[][MAX_NO_SCALES + 1], + Word32 offset_scale2_p[][MAX_NO_SCALES + 1], + Word16 no_scales[][2], + Word16 no_scales_p[][2] ); Word16 deindex_lvq_cng_fx( - Word16 *index, /* i : index to be decoded, as an array of 3 short */ - Word16 *x_lvq, /* o : decoded codevector Q9*/ - Word16 idx_cv, /* i : relative mode_lvq, wrt START_CNG */ - Word16 no_bits, /* i : number of bits for lattice */ - Word32 * p_offset_scale1, - Word32 * p_offset_scale2, - Word16 * p_no_scales -); + Word16 *index, /* i : index to be decoded, as an array of 3 short */ + Word16 *x_lvq, /* o : decoded codevector Q9*/ + Word16 idx_cv, /* i : relative mode_lvq, wrt START_CNG */ + Word16 no_bits, /* i : number of bits for lattice */ + Word32 *p_offset_scale1, + Word32 *p_offset_scale2, + Word16 *p_no_scales ); /*========================================================================================================/ swb_bwe_com_fx.c /========================================================================================================*/ void calc_normal_length_fx( - const Word16 core, /* i : core */ - const Word16 *sp, /* i : i signal */ - const Word16 mode, /* i : i mode */ - const Word16 extl, /* i : extension layer */ - Word16 *L_swb_norm, /* o : normalize length */ - Word16 *prev_L_swb_norm, /*i/o : last normalize length */ - Word16 Q_syn -); + const Word16 core, /* i : core */ + const Word16 *sp, /* i : i signal */ + const Word16 mode, /* i : i mode */ + const Word16 extl, /* i : extension layer */ + Word16 *L_swb_norm, /* o : normalize length */ + Word16 *prev_L_swb_norm, /*i/o : last normalize length */ + Word16 Q_syn ); void calc_normal_length_fx_32( - const Word16 core, /* i : core : Q0 */ - const Word32 *sp, /* i : i signal : Q12 */ - const Word16 mode, /* i : i mode : Q0 */ - const Word16 extl, /* i : extension layer : Q0 */ - Word16 *L_swb_norm, /* o : normalize length : Q0 */ - Word16 *prev_L_swb_norm /*i/o : last normalize length : Q0 */ + const Word16 core, /* i : core : Q0 */ + const Word32 *sp, /* i : i signal : Q12 */ + const Word16 mode, /* i : i mode : Q0 */ + const Word16 extl, /* i : extension layer : Q0 */ + Word16 *L_swb_norm, /* o : normalize length : Q0 */ + Word16 *prev_L_swb_norm /*i/o : last normalize length : Q0 */ ); void hq_generic_decoding_fx( - const Word16 HQ_mode, /* i : HQ mode */ - Word32 *coeff_out1_fx, /* i/o: BWE i & temporary buffer */ - const Word16 *hq_generic_fenv_fx, /* i : SWB frequency envelopes */ - Word32 *coeff_out_fx, /* o : SWB signal in MDCT domain */ - const Word16 hq_generic_offset, /* i : frequency offset for representing hq generic*/ - Word16 *prev_L_swb_norm, /* i/o: last normalize length */ - const Word16 hq_generic_exc_clas, /* i : bwe excitation class */ - const Word16 *R -); + const Word16 HQ_mode, /* i : HQ mode */ + Word32 *coeff_out1_fx, /* i/o: BWE i & temporary buffer */ + const Word16 *hq_generic_fenv_fx, /* i : SWB frequency envelopes */ + Word32 *coeff_out_fx, /* o : SWB signal in MDCT domain */ + const Word16 hq_generic_offset, /* i : frequency offset for representing hq generic*/ + Word16 *prev_L_swb_norm, /* i/o: last normalize length */ + const Word16 hq_generic_exc_clas, /* i : bwe excitation class */ + const Word16 *R ); Word16 WB_BWE_gain_pred_fx( - Word16 *WB_fenv, /* o : WB frequency envelopes */ - const Word16 *core_dec_freq, /* i : Frequency domain core decoded signal */ - const Word16 coder_type, /* i : coding type */ - Word16 prev_coder_type, /* i : coding type of last frame */ - Word16 prev_WB_fenv, /* i : envelope for last frame */ - Word16 *voice_factors, /* i : voicing factors Q15 */ - const Word16 pitch_buf[], /* i : pitch buffer Q6 */ - Word32 last_core_brate, /* i : previous frame core bitrate */ - Word16 last_wb_bwe_ener, /* i : previous frame wb bwe signal energy */ - Word16 Q_syn - , Word16 last_extl_fx, - Word16 tilt_wb_fx -); - -Word32 calc_tilt_bwe_fx( /* o : Tilt in Q24 */ - const Word16 *sp0, /* i : i signal */ - const Word16 exp, /* i : Exp of inp signal */ - const Word16 N /* i : signal length */ + Word16 *WB_fenv, /* o : WB frequency envelopes */ + const Word16 *core_dec_freq, /* i : Frequency domain core decoded signal */ + const Word16 coder_type, /* i : coding type */ + Word16 prev_coder_type, /* i : coding type of last frame */ + Word16 prev_WB_fenv, /* i : envelope for last frame */ + Word16 *voice_factors, /* i : voicing factors Q15 */ + const Word16 pitch_buf[], /* i : pitch buffer Q6 */ + Word32 last_core_brate, /* i : previous frame core bitrate */ + Word16 last_wb_bwe_ener, /* i : previous frame wb bwe signal energy */ + Word16 Q_syn, + Word16 last_extl_fx, + Word16 tilt_wb_fx ); + +Word32 calc_tilt_bwe_fx( /* o : Tilt in Q24 */ + const Word16 *sp0, /* i : i signal */ + const Word16 exp, /* i : Exp of inp signal */ + const Word16 N /* i : signal length */ ); void calc_norm_envelop_fx( - const Word16 SWB_signal[], /* i : SWB spectrum Q_syn*/ - Word32 *envelope, /* o : normalized envelope Q_syn*/ - const Word16 L_swb_norm, /* i : length of envelope Q0 */ - const Word16 SWB_flength, /* i : Length of i /output */ - const Word16 st_offset /* i : offset */ + const Word16 SWB_signal[], /* i : SWB spectrum Q_syn*/ + Word32 *envelope, /* o : normalized envelope Q_syn*/ + const Word16 L_swb_norm, /* i : length of envelope Q0 */ + const Word16 SWB_flength, /* i : Length of i /output */ + const Word16 st_offset /* i : offset */ ); void WB_BWE_decoding_fx( - const Word16 *core_dec_freq, /* i : Frequency domain core decoded signal */ - Word16 *WB_fenv, /* i : WB frequency envelopes */ - Word32 *WB_signal32, /* o : WB signal in MDCT domain */ - const Word16 WB_flength, /* i : Length of i /output */ - const Word16 mode, /* i : classification for WB signal */ - const Word16 last_extl, /* i : extl. layer for last frame */ - Word32 *prev_Energy, /* i/o: energy for last frame */ - Word16 *prev_WB_fenv, /* i/o: envelope for last frame */ - Word16 *prev_L_wb_norm, /* i/o: length for last frame wb norm */ - const Word16 extl, /* i : extension layer */ - const Word16 coder_type, /* i : coding type */ - const Word32 total_brate, /* i : core layer bitrate */ - Word16 *Seed, /* i/o: random generator seed */ - Word16 *prev_flag, /* i/o: attenu flag of last frame */ - Word16 prev_coder_type, /* i : coding type of last frame */ - Word16 Q_syn, - Word16 *Q_syn_hb /*o : Q value of WB_signal_32 */ + const Word16 *core_dec_freq, /* i : Frequency domain core decoded signal */ + Word16 *WB_fenv, /* i : WB frequency envelopes */ + Word32 *WB_signal32, /* o : WB signal in MDCT domain */ + const Word16 WB_flength, /* i : Length of i /output */ + const Word16 mode, /* i : classification for WB signal */ + const Word16 last_extl, /* i : extl. layer for last frame */ + Word32 *prev_Energy, /* i/o: energy for last frame */ + Word16 *prev_WB_fenv, /* i/o: envelope for last frame */ + Word16 *prev_L_wb_norm, /* i/o: length for last frame wb norm */ + const Word16 extl, /* i : extension layer */ + const Word16 coder_type, /* i : coding type */ + const Word32 total_brate, /* i : core layer bitrate */ + Word16 *Seed, /* i/o: random generator seed */ + Word16 *prev_flag, /* i/o: attenu flag of last frame */ + Word16 prev_coder_type, /* i : coding type of last frame */ + Word16 Q_syn, + Word16 *Q_syn_hb /*o : Q value of WB_signal_32 */ ); void SWB_BWE_decoding_fx( - const Word16 *core_dec_freq, /* i : Frequency domain core decoded signal */ - Word16 *SWB_fenv, /* i/o: SWB frequency envelopes */ - Word32 *SWB_signal, /* o : SWB signal in MDCT domain */ - const Word16 SWB_flength, /* i : Length of i /output */ - const Word16 mode, /* i : classification for SWB signal */ - Word16 *frica_flag, /* o : fricative signal flag */ - Word16 *prev_Energy, /* i/o: energy for last frame */ - Word16 *prev_SWB_fenv, /* i/o: envelope for last frame */ - Word16 *prev_L_swb_norm, /* i/o: length for last frame wb norm */ - const Word16 tilt_nb, /* i : tilt of synthesis wb signal */ - Word16 *Seed, /* i/o: random generator seed */ - const Word16 st_offset, /* i : offset value due to different core */ - Word16 *prev_weight, /* i/o: excitation weight value of last frame */ - const Word16 extl, /* i : extension layer */ - Word16 Q_syn - , const Word16 last_extl, /* i : extension layer of last frame */ - Word16 element_mode /* i : element mode */ + const Word16 *core_dec_freq, /* i : Frequency domain core decoded signal */ + Word16 *SWB_fenv, /* i/o: SWB frequency envelopes */ + Word32 *SWB_signal, /* o : SWB signal in MDCT domain */ + const Word16 SWB_flength, /* i : Length of i /output */ + const Word16 mode, /* i : classification for SWB signal */ + Word16 *frica_flag, /* o : fricative signal flag */ + Word16 *prev_Energy, /* i/o: energy for last frame */ + Word16 *prev_SWB_fenv, /* i/o: envelope for last frame */ + Word16 *prev_L_swb_norm, /* i/o: length for last frame wb norm */ + const Word16 tilt_nb, /* i : tilt of synthesis wb signal */ + Word16 *Seed, /* i/o: random generator seed */ + const Word16 st_offset, /* i : offset value due to different core */ + Word16 *prev_weight, /* i/o: excitation weight value of last frame */ + const Word16 extl, /* i : extension layer */ + Word16 Q_syn, + const Word16 last_extl, /* i : extension layer of last frame */ + Word16 element_mode /* i : element mode */ ); void time_envelop_shaping_fx( - Word16 werr[], /* i/o: SHB synthesis Q_synth*/ - Word32 SWB_tenv[], /* i/o: frequency envelope Q15*/ - const Word16 L, /* i : frame length */ - Word16 *Q_synth -); + Word16 werr[], /* i/o: SHB synthesis Q_synth*/ + Word32 SWB_tenv[], /* i/o: frequency envelope Q15*/ + const Word16 L, /* i : frame length */ + Word16 *Q_synth ); void time_reduce_pre_echo_fx( - const Word16 *synth, /* i : ACELP core synthesis Q_syn*/ - Word16 *error, /* i/o: SHB BWE synthesis Q0*/ - Word16 prev_td_energy, /* o : last td energy Q0*/ - const Word16 L, /* i : subframe length */ - Word16 Q_syn, - Word16 Q_synth -); + const Word16 *synth, /* i : ACELP core synthesis Q_syn*/ + Word16 *error, /* i/o: SHB BWE synthesis Q0*/ + Word16 prev_td_energy, /* o : last td energy Q0*/ + const Word16 L, /* i : subframe length */ + Word16 Q_syn, + Word16 Q_synth ); void calc_norm_envelop_fx_32( - const Word32 SWB_signal_fx[], /* i : SWB spectrum : Q12 */ - Word32 *envelope_fx, /* o : normalized envelope : Q16 */ - const Word16 L_swb_norm, /* i : length of envelope : Q0 */ - const Word16 SWB_flength, /* i : Length of i /output : Q0 */ - const Word16 st_offset /* i : offset : Q0 */ + const Word32 SWB_signal_fx[], /* i : SWB spectrum : Q12 */ + Word32 *envelope_fx, /* o : normalized envelope : Q16 */ + const Word16 L_swb_norm, /* i : length of envelope : Q0 */ + const Word16 SWB_flength, /* i : Length of i /output : Q0 */ + const Word16 st_offset /* i : offset : Q0 */ ); void hq_generic_decoding_fx( - const Word16 HQ_mode, /* i : HQ mode */ - Word32 *coeff_out1_fx, /* i/o: BWE i & temporary buffer */ - const Word16 *hq_generic_fenv_fx, /* i : SWB frequency envelopes */ - Word32 *coeff_out_fx, /* o : SWB signal in MDCT domain */ - const Word16 hq_generic_offset, /* i : frequency offset for representing hq generic*/ - Word16 *prev_L_swb_norm, /* i/o: last normalize length */ - const Word16 hq_generic_exc_clas, /* i : bwe excitation class */ - const Word16 *R -); + const Word16 HQ_mode, /* i : HQ mode */ + Word32 *coeff_out1_fx, /* i/o: BWE i & temporary buffer */ + const Word16 *hq_generic_fenv_fx, /* i : SWB frequency envelopes */ + Word32 *coeff_out_fx, /* o : SWB signal in MDCT domain */ + const Word16 hq_generic_offset, /* i : frequency offset for representing hq generic*/ + Word16 *prev_L_swb_norm, /* i/o: last normalize length */ + const Word16 hq_generic_exc_clas, /* i : bwe excitation class */ + const Word16 *R ); void save_old_syn_fx( - const Word16 L_frame, /* i : frame length */ - const Word16 syn[], /* i : ACELP synthesis */ - Word16 old_syn[], /* o : old synthesis buffer */ - Word16 old_syn_mem[], /* i/o: old synthesis buffer memory */ - const Word16 preemph_fac, /* i : preemphasis factor */ - Word16 *mem_deemph /* i/o: deemphasis filter memory */ + const Word16 L_frame, /* i : frame length */ + const Word16 syn[], /* i : ACELP synthesis */ + Word16 old_syn[], /* o : old synthesis buffer */ + Word16 old_syn_mem[], /* i/o: old synthesis buffer memory */ + const Word16 preemph_fac, /* i : preemphasis factor */ + Word16 *mem_deemph /* i/o: deemphasis filter memory */ ); /*========================================================================================================/ @@ -399,33 +389,33 @@ lognorm_fx.c /========================================================================================================*/ void logqnorm_fx( - const Word32 *x, /* i : coefficient vector Qx */ - const Word16 qx, /* i : Q value of i */ - Word16 *k, /* o : index Q0 */ - const Word16 L, /* i : codebook length Q0 */ - const Word16 N, /* i : sub-vector size Q0 */ - const Word16 hvq_flag /* i : HVQ flag Q0 */ + const Word32 *x, /* i : coefficient vector Qx */ + const Word16 qx, /* i : Q value of i */ + Word16 *k, /* o : index Q0 */ + const Word16 L, /* i : codebook length Q0 */ + const Word16 N, /* i : sub-vector size Q0 */ + const Word16 hvq_flag /* i : HVQ flag Q0 */ ); void logqnorm_2_fx( - const Word32 *env_fl, /* o : index */ - const Word16 L, /* i : codebook length */ - const Word16 n_env_band, /* i : sub-vector size */ - const Word16 nb_sfm, /* i : sub-vector size */ - Word16 *ynrm, - Word16 *normqlg2, - const Word32 *thren /* i : quantization thresholds */ + const Word32 *env_fl, /* o : index */ + const Word16 L, /* i : codebook length */ + const Word16 n_env_band, /* i : sub-vector size */ + const Word16 nb_sfm, /* i : sub-vector size */ + Word16 *ynrm, + Word16 *normqlg2, + const Word32 *thren /* i : quantization thresholds */ ); void calc_norm_fx( - const Word32 *L_x, /* i : Input vector. Qx */ - const Word16 qx, /* i : Q value of i */ - Word16 *norm, /* o : Quantization indices for norms Q0 */ - Word16 *normlg, /* o : Quantized norms in log2 Q0 */ - const Word16 start_band, /* i : Indice of band to start coding Q0 */ - const Word16 num_bands, /* i : Number of bands Q0 */ - const Word16 *band_len, /* i : Length of bands Q0 */ - const Word16 *band_start /* i : Start of bands Q0 */ + const Word32 *L_x, /* i : Input vector. Qx */ + const Word16 qx, /* i : Q value of i */ + Word16 *norm, /* o : Quantization indices for norms Q0 */ + Word16 *normlg, /* o : Quantized norms in log2 Q0 */ + const Word16 start_band, /* i : Indice of band to start coding Q0 */ + const Word16 num_bands, /* i : Number of bands Q0 */ + const Word16 *band_len, /* i : Length of bands Q0 */ + const Word16 *band_start /* i : Start of bands Q0 */ ); /*========================================================================================================/ @@ -433,553 +423,536 @@ hq_tools_fx.c /========================================================================================================*/ void hq_swb_harmonic_calc_norm_envelop_fx( - const Word32* L_SWB_signal, /* i : i signal Q=12*/ - Word32* L_envelope, /* o : output envelope Q=12*/ - const Word16 L_swb_norm, /* i : length of normaliztion */ - const Word16 SWB_flength /* i : length of i signal */ + const Word32 *L_SWB_signal, /* i : i signal Q=12*/ + Word32 *L_envelope, /* o : output envelope Q=12*/ + const Word16 L_swb_norm, /* i : length of normaliztion */ + const Word16 SWB_flength /* i : length of i signal */ ); -Word16 build_nf_codebook_fx( /* o : Number of coefficients in nf codebook */ - const Word16 flag_32K_env_ho, /* i : Envelope attenuation hangover flag */ - const Word16 *coeff, /* i : Coded spectral coefficients */ - const Word16 *sfm_start, /* i : Subband start indices */ - const Word16 *sfmsize, /* i : Subband widths */ - const Word16 *sfm_end, /* i : Subband end indices */ - const Word16 last_sfm, /* i : Last coded band */ - const Word16 *R, /* i : Per-band bit allocation */ - Word16 *CodeBook, /* o : Noise-fill codebook */ - Word16 *CodeBook_mod /* o : Densified noise-fill codebook */ +Word16 build_nf_codebook_fx( /* o : Number of coefficients in nf codebook */ + const Word16 flag_32K_env_ho, /* i : Envelope attenuation hangover flag */ + const Word16 *coeff, /* i : Coded spectral coefficients */ + const Word16 *sfm_start, /* i : Subband start indices */ + const Word16 *sfmsize, /* i : Subband widths */ + const Word16 *sfm_end, /* i : Subband end indices */ + const Word16 last_sfm, /* i : Last coded band */ + const Word16 *R, /* i : Per-band bit allocation */ + Word16 *CodeBook, /* o : Noise-fill codebook */ + Word16 *CodeBook_mod /* o : Densified noise-fill codebook */ ); void limit_band_noise_level_calc_fx( - const Word16 *wnorm, /* i : reordered norm of sub-vectors */ - Word16 *limit, /* o : highest band of bit allocation */ - const Word32 core_brate, /* i : bit rate */ - Word16 *noise_level /* o : noise level Q15 */ + const Word16 *wnorm, /* i : reordered norm of sub-vectors */ + Word16 *limit, /* o : highest band of bit allocation */ + const Word32 core_brate, /* i : bit rate */ + Word16 *noise_level /* o : noise level Q15 */ ); -Word16 find_last_band_fx( /* o : index of last band */ - const Word16 *bitalloc, /* i : bit allocation */ - const Word16 nb_sfm /* i : number of possibly coded bands */ +Word16 find_last_band_fx( /* o : index of last band */ + const Word16 *bitalloc, /* i : bit allocation */ + const Word16 nb_sfm /* i : number of possibly coded bands */ ); void apply_noisefill_HQ_fx( - const Word16 *R, /* i : bit allocation */ - const Word16 length, /* i : i frame length */ - const Word16 flag_32K_env_ho,/* i : envelope stability hangover flag*/ - const Word32 L_core_brate, /* i : core bit rate */ - const Word16 last_sfm, /* i : last coded subband */ - const Word16 *CodeBook, /* i : Noise-fill codebook */ - const Word16 *CodeBook_mod, /* i : Densified noise-fill codebook */ - const Word16 cb_size, /* i : Codebook length */ - const Word16 *sfm_start, /* i : Subband start coefficient */ - const Word16 *sfm_end, /* i : Subband end coefficient */ - const Word16 *sfmsize, /* i : Subband band width */ - Word16 *coeff /* i/o: coded/noisefilled spectrum */ + const Word16 *R, /* i : bit allocation */ + const Word16 length, /* i : i frame length */ + const Word16 flag_32K_env_ho, /* i : envelope stability hangover flag*/ + const Word32 L_core_brate, /* i : core bit rate */ + const Word16 last_sfm, /* i : last coded subband */ + const Word16 *CodeBook, /* i : Noise-fill codebook */ + const Word16 *CodeBook_mod, /* i : Densified noise-fill codebook */ + const Word16 cb_size, /* i : Codebook length */ + const Word16 *sfm_start, /* i : Subband start coefficient */ + const Word16 *sfm_end, /* i : Subband end coefficient */ + const Word16 *sfmsize, /* i : Subband band width */ + Word16 *coeff /* i/o: coded/noisefilled spectrum */ ); void harm_bwe_fine_fx( - const Word16 *R, /* i : bit allocation */ - const Word16 last_sfm, /* i : last coded subband */ - const Word16 high_sfm, /* i : higher transition band to BWE */ - const Word16 num_sfm, /* i : total number of bands */ - const Word16 *norm, /* i : quantization indices for norms */ - const Word16 *sfm_start, /* i : Subband start coefficient */ - const Word16 *sfm_end, /* i : Subband end coefficient */ - Word16 *prev_L_swb_norm, /* i/o: last normalize length */ - Word16 *coeff, /* i/o: coded/noisefilled normalized spectrum */ - Word32 *coeff_out, /* o : coded/noisefilled spectrum */ - Word16 *coeff_fine /* o : BWE fine structure */ + const Word16 *R, /* i : bit allocation */ + const Word16 last_sfm, /* i : last coded subband */ + const Word16 high_sfm, /* i : higher transition band to BWE */ + const Word16 num_sfm, /* i : total number of bands */ + const Word16 *norm, /* i : quantization indices for norms */ + const Word16 *sfm_start, /* i : Subband start coefficient */ + const Word16 *sfm_end, /* i : Subband end coefficient */ + Word16 *prev_L_swb_norm, /* i/o: last normalize length */ + Word16 *coeff, /* i/o: coded/noisefilled normalized spectrum */ + Word32 *coeff_out, /* o : coded/noisefilled spectrum */ + Word16 *coeff_fine /* o : BWE fine structure */ ); void hvq_bwe_fine_fx( - const Word16 last_sfm, /* i : last coded subband */ - const Word16 num_sfm, /* i : total number of bands */ - const Word16 *sfm_end, /* i : Subband end coefficient */ - const Word16 *peak_idx, /* i : Peak index */ - const Word16 Npeaks, /* i : Number of peaks */ - Word16 *peak_pos, /* o : Peak positions */ - Word16 *prev_L_swb_norm, /* i/o: last normalize length */ - Word32 *L_coeff, /* i/o: coded/noisefilled normalized spectrum */ - Word16 *bwe_peaks, /* o : Positions of peaks in BWE */ - Word16 *coeff_fine /* o : HVQ BWE fine structure */ + const Word16 last_sfm, /* i : last coded subband */ + const Word16 num_sfm, /* i : total number of bands */ + const Word16 *sfm_end, /* i : Subband end coefficient */ + const Word16 *peak_idx, /* i : Peak index */ + const Word16 Npeaks, /* i : Number of peaks */ + Word16 *peak_pos, /* o : Peak positions */ + Word16 *prev_L_swb_norm, /* i/o: last normalize length */ + Word32 *L_coeff, /* i/o: coded/noisefilled normalized spectrum */ + Word16 *bwe_peaks, /* o : Positions of peaks in BWE */ + Word16 *coeff_fine /* o : HVQ BWE fine structure */ ); void harm_bwe_fx( - const Word16* coeff_fine, /* i : fine structure for BWE */ - const Word16* coeff, /* i : coded/noisefilled normalized spectrum */ - const Word16 num_sfm, /* i : Number of subbands */ - const Word16* sfm_start, /* i : Subband start coefficient */ - const Word16* sfm_end, /* i : Subband end coefficient */ - const Word16 last_sfm, /* i : last coded subband */ - const Word16* R, /* i : bit allocation */ - const Word16 prev_hq_mode, /* i : previous hq mode */ - Word16* norm, /* i/o: quantization indices for norms */ - Word16* noise_level, /* i/o: noise levels for harmonic modes */ - Word16* prev_noise_level, /* i/o: noise factor in previous frame */ - Word16* bwe_seed, /* i/o: random seed for generating BWE i */ - Word32* coeff_out, /* o : coded/noisefilled spectrum */ - const Word16 element_mode /* i : IVAS element mode */ + const Word16 *coeff_fine, /* i : fine structure for BWE */ + const Word16 *coeff, /* i : coded/noisefilled normalized spectrum */ + const Word16 num_sfm, /* i : Number of subbands */ + const Word16 *sfm_start, /* i : Subband start coefficient */ + const Word16 *sfm_end, /* i : Subband end coefficient */ + const Word16 last_sfm, /* i : last coded subband */ + const Word16 *R, /* i : bit allocation */ + const Word16 prev_hq_mode, /* i : previous hq mode */ + Word16 *norm, /* i/o: quantization indices for norms */ + Word16 *noise_level, /* i/o: noise levels for harmonic modes */ + Word16 *prev_noise_level, /* i/o: noise factor in previous frame */ + Word16 *bwe_seed, /* i/o: random seed for generating BWE i */ + Word32 *coeff_out, /* o : coded/noisefilled spectrum */ + const Word16 element_mode /* i : IVAS element mode */ ); void hq_fold_bwe_fx( - const Word16 last_sfm, /* i : last coded subband Q0 */ - const Word16 *sfm_end, /* i : Subband end coefficient Q0 */ - const Word16 num_sfm, /* i : Number of subbands Q0 */ - Word16 *coeff /* i/o: coded/noisefilled normalized spectrum Q12 */ + const Word16 last_sfm, /* i : last coded subband Q0 */ + const Word16 *sfm_end, /* i : Subband end coefficient Q0 */ + const Word16 num_sfm, /* i : Number of subbands Q0 */ + Word16 *coeff /* i/o: coded/noisefilled normalized spectrum Q12 */ ); void apply_nf_gain_fx( - const Word16 nf_idx, /* i : noise fill gain index Q0 */ - const Word16 last_sfm, /* i : last coded subband Q0 */ - const Word16 *R, /* i : bit allocation Q0 */ - const Word16 *sfm_start, /* i : Subband start coefficient Q0 */ - const Word16 *sfm_end, /* i : Subband end coefficient Q0 */ - Word16 *coeff /* i/o: coded/noisefilled normalized spectrum Q12 */ + const Word16 nf_idx, /* i : noise fill gain index Q0 */ + const Word16 last_sfm, /* i : last coded subband Q0 */ + const Word16 *R, /* i : bit allocation Q0 */ + const Word16 *sfm_start, /* i : Subband start coefficient Q0 */ + const Word16 *sfm_end, /* i : Subband end coefficient Q0 */ + Word16 *coeff /* i/o: coded/noisefilled normalized spectrum Q12 */ ); void hvq_bwe_fx( - const Word32 *coeff, - const Word16 *coeff_fine, /* i : coded/noisefilled normalized spectrum Qin */ - const Word16 *sfm_start, /* i : Subband start coefficient Q0 */ - const Word16 *sfm_end, /* i : Subband end coefficient Q0 */ - const Word16 *sfm_len, /* i : Subband length Q0 */ - const Word16 last_sfm, /* i : last coded subband Q0 */ - const Word16 prev_hq_mode, /* i : previous hq mode Q0 */ - const Word16 *bwe_peaks, /* i : HVQ bwe peaks Q0 */ - const Word16 bin_th, /* i : HVQ transition bin Q0 */ - const Word16 num_sfm, /* i : Number of bands Q0 */ - const Word32 core_brate, /* i : Core bit-rate Q0 */ - const Word16 *R, /* i : Bit allocation */ - Word16 *norm, /* i/o: quantization indices for norms Q0 */ - Word16 *noise_level, /* i/o: noise levels for harmonic modes Q15 */ - Word16 *prev_noise_level, /* i/o: noise factor in previous frame Q15 */ - Word16 *bwe_seed, /* i/o: random seed for generating BWE i Q0 */ - Word32 *L_coeff_out, /* o : coded/noisefilled spectrum Qout*/ - const Word16 qin, - const Word16 qout -); - -void hvq_concat_bands_fx -( - const Word16 pvq_bands, /* i : Number of bands in concatenated PVQ target */ - const Word16 *sel_bnds, /* i : Array of selected high bands */ - const Word16 n_sel_bnds, /* i : Number of selected high bands */ - Word16 *hvq_band_start, /* i : Band start indices */ - Word16 *hvq_band_width, /* i : Band widths */ - Word16 *hvq_band_end /* i : Band end indices */ + const Word32 *coeff, + const Word16 *coeff_fine, /* i : coded/noisefilled normalized spectrum Qin */ + const Word16 *sfm_start, /* i : Subband start coefficient Q0 */ + const Word16 *sfm_end, /* i : Subband end coefficient Q0 */ + const Word16 *sfm_len, /* i : Subband length Q0 */ + const Word16 last_sfm, /* i : last coded subband Q0 */ + const Word16 prev_hq_mode, /* i : previous hq mode Q0 */ + const Word16 *bwe_peaks, /* i : HVQ bwe peaks Q0 */ + const Word16 bin_th, /* i : HVQ transition bin Q0 */ + const Word16 num_sfm, /* i : Number of bands Q0 */ + const Word32 core_brate, /* i : Core bit-rate Q0 */ + const Word16 *R, /* i : Bit allocation */ + Word16 *norm, /* i/o: quantization indices for norms Q0 */ + Word16 *noise_level, /* i/o: noise levels for harmonic modes Q15 */ + Word16 *prev_noise_level, /* i/o: noise factor in previous frame Q15 */ + Word16 *bwe_seed, /* i/o: random seed for generating BWE i Q0 */ + Word32 *L_coeff_out, /* o : coded/noisefilled spectrum Qout*/ + const Word16 qin, + const Word16 qout ); + +void hvq_concat_bands_fx( + const Word16 pvq_bands, /* i : Number of bands in concatenated PVQ target */ + const Word16 *sel_bnds, /* i : Array of selected high bands */ + const Word16 n_sel_bnds, /* i : Number of selected high bands */ + Word16 *hvq_band_start, /* i : Band start indices */ + Word16 *hvq_band_width, /* i : Band widths */ + Word16 *hvq_band_end /* i : Band end indices */ ); void noise_mix_fx( - const Word16 *coeff_fine, /* i : normalized fine structure spectrum Qin */ - const Word32 L_E, /* i : normalization factor Q17 */ - const Word32 L_normq, /* i : quantized norm Q14 */ - Word16 *seed, /* i/o: random seed Q0 */ - const Word16 istart, /* i : start coefficient Q0 */ - const Word16 iend, /* i : end coefficient Q0 */ - const Word16 noise_level, /* i : noise_level Q0 */ - Word32 *L_coeff_out, /* o : noisemixed spectrum Qout */ - const Word16 qin, - const Word16 qout -); + const Word16 *coeff_fine, /* i : normalized fine structure spectrum Qin */ + const Word32 L_E, /* i : normalization factor Q17 */ + const Word32 L_normq, /* i : quantized norm Q14 */ + Word16 *seed, /* i/o: random seed Q0 */ + const Word16 istart, /* i : start coefficient Q0 */ + const Word16 iend, /* i : end coefficient Q0 */ + const Word16 noise_level, /* i : noise_level Q0 */ + Word32 *L_coeff_out, /* o : noisemixed spectrum Qout */ + const Word16 qin, + const Word16 qout ); void hq_generic_fine_fx( - Word16 *coeff, /* i : coded/noisefilled normalized spectrum */ - const Word16 last_sfm, /* i : Last coded band */ - const Word16 *sfm_start, /* i : Subband start coefficient */ - const Word16 *sfm_end, /* i : Subband end coefficient */ - Word16 *bwe_seed, /* i/o: random seed for generating BWE i */ - Word16 *coeff_out1 /* o : HQ Generic i */ + Word16 *coeff, /* i : coded/noisefilled normalized spectrum */ + const Word16 last_sfm, /* i : Last coded band */ + const Word16 *sfm_start, /* i : Subband start coefficient */ + const Word16 *sfm_end, /* i : Subband end coefficient */ + Word16 *bwe_seed, /* i/o: random seed for generating BWE i */ + Word16 *coeff_out1 /* o : HQ Generic i */ ); void map_hq_generic_fenv_norm_fx( - const Word16 hqswb_clas, - const Word16 *hq_generic_fenv, /* Q1, frequency-domain BWE envelope */ - Word16 *ynrm, - Word16 *normqlg2, - const Word16 num_env_bands, - const Word16 nb_sfm, - const Word16 hq_generic_offset -); + const Word16 hqswb_clas, + const Word16 *hq_generic_fenv, /* Q1, frequency-domain BWE envelope */ + Word16 *ynrm, + Word16 *normqlg2, + const Word16 num_env_bands, + const Word16 nb_sfm, + const Word16 hq_generic_offset ); Word16 get_nor_delta_hf_fx( - Decoder_State *st, - Word16 *ynrm, - Word16 *Rsubband, /* Q3 */ - const Word16 num_env_bands, - const Word16 nb_sfm, - const Word16 core_sfm -); + Decoder_State *st, + Word16 *ynrm, + Word16 *Rsubband, /* Q3 */ + const Word16 num_env_bands, + const Word16 nb_sfm, + const Word16 core_sfm ); Word16 calc_nor_delta_hf_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word32* t_audio, /* i : transform-domain coefficients */ - Word16* ynrm, /* i/o: norm indices */ - Word16* Rsubband, /* i/o: sub-band bit allocation */ - const Word16 num_env_bands, /* i : Number coded envelope bands */ - const Word16 nb_sfm, /* i : Number of envelope bands */ - const Word16* sfmsize, /* i : band length */ - const Word16* sfm_start, /* i : Start index of bands */ - const Word16 core_sfm /* i : index of the end band for core */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word32 *t_audio, /* i : transform-domain coefficients */ + Word16 *ynrm, /* i/o: norm indices */ + Word16 *Rsubband, /* i/o: sub-band bit allocation */ + const Word16 num_env_bands, /* i : Number coded envelope bands */ + const Word16 nb_sfm, /* i : Number of envelope bands */ + const Word16 *sfmsize, /* i : band length */ + const Word16 *sfm_start, /* i : Start index of bands */ + const Word16 core_sfm /* i : index of the end band for core */ ); void hq_bwe_fx( - const Word16 HQ_mode, /* i : HQ mode */ - Word32 *coeff_out1, /* i/o: BWE i & temporary buffer */ - const Word16 *hq_generic_fenv, /* i : SWB frequency envelopes */ - Word32 *coeff_out, /* o : SWB signal in MDCT domain */ - const Word16 hq_generic_offset, /* i : frequency offset for representing hq generic bwe*/ - Word16 *prev_L_swb_norm, /*i/o : last normalize length */ - const Word16 hq_generic_exc_clas,/* i : bwe excitation class */ - const Word16 *sfm_end, /* i : End of bands */ - const Word16 num_sfm, - const Word16 num_env_bands, - const Word16 *R -); + const Word16 HQ_mode, /* i : HQ mode */ + Word32 *coeff_out1, /* i/o: BWE i & temporary buffer */ + const Word16 *hq_generic_fenv, /* i : SWB frequency envelopes */ + Word32 *coeff_out, /* o : SWB signal in MDCT domain */ + const Word16 hq_generic_offset, /* i : frequency offset for representing hq generic bwe*/ + Word16 *prev_L_swb_norm, /*i/o : last normalize length */ + const Word16 hq_generic_exc_clas, /* i : bwe excitation class */ + const Word16 *sfm_end, /* i : End of bands */ + const Word16 num_sfm, + const Word16 num_env_bands, + const Word16 *R ); void hq_wb_nf_bwe_fx( - const Word16 *coeff_fx, /* i : coded/noisefilled normalized spectrum */ - const Word16 is_transient, - const Word16 prev_bfi, /* i : previous bad frame indicator */ - const Word32 *L_normq_v, - const Word16 num_sfm, /* i : Number of subbands */ - const Word16 *sfm_start, /* i : Subband start coefficient */ - const Word16 *sfm_end, /* i : Subband end coefficient */ - const Word16 *sfmsize, /* i : Subband band width */ - const Word16 last_sfm, /* i : last coded subband */ - const Word16 *R, /* i : bit allocation */ - const Word16 prev_is_transient, /* i : previous transient flag */ - Word32 *prev_normq_fx, /* i/o: previous norms */ - Word32 *prev_env_fx, /* i/o: previous noise envelopes */ - Word16 *bwe_seed, /* i/o: random seed for generating BWE i */ - Word32 *prev_coeff_out_fx, /* i/o: decoded spectrum in previous frame */ - Word16 *prev_R, /* i/o: bit allocation info. in previous frame */ - Word32 *L_coeff_out, /* o : coded/noisefilled spectrum */ - Word16 *prev_env_Q -); + const Word16 *coeff_fx, /* i : coded/noisefilled normalized spectrum */ + const Word16 is_transient, + const Word16 prev_bfi, /* i : previous bad frame indicator */ + const Word32 *L_normq_v, + const Word16 num_sfm, /* i : Number of subbands */ + const Word16 *sfm_start, /* i : Subband start coefficient */ + const Word16 *sfm_end, /* i : Subband end coefficient */ + const Word16 *sfmsize, /* i : Subband band width */ + const Word16 last_sfm, /* i : last coded subband */ + const Word16 *R, /* i : bit allocation */ + const Word16 prev_is_transient, /* i : previous transient flag */ + Word32 *prev_normq_fx, /* i/o: previous norms */ + Word32 *prev_env_fx, /* i/o: previous noise envelopes */ + Word16 *bwe_seed, /* i/o: random seed for generating BWE i */ + Word32 *prev_coeff_out_fx, /* i/o: decoded spectrum in previous frame */ + Word16 *prev_R, /* i/o: bit allocation info. in previous frame */ + Word32 *L_coeff_out, /* o : coded/noisefilled spectrum */ + Word16 *prev_env_Q ); void enforce_zero_for_min_envelope_fx( - const Word16 hqswb_clas, /* i : HQ coding mode Q0 */ - const Word16 *ynrm, /* i : Envelope indices Q0 */ - Word32 *L_coefsq, /* i/o: Quantized spectrum/zeroed spectrum Q12 */ - const Word16 nb_sfm, /* i : Number of coded sub bands Q0 */ - const Word16 *sfm_start, /* i : Sub band start indices Q0 */ - const Word16 *sfm_end /* i : Sub band end indices Q0 */ + const Word16 hqswb_clas, /* i : HQ coding mode Q0 */ + const Word16 *ynrm, /* i : Envelope indices Q0 */ + Word32 *L_coefsq, /* i/o: Quantized spectrum/zeroed spectrum Q12 */ + const Word16 nb_sfm, /* i : Number of coded sub bands Q0 */ + const Word16 *sfm_start, /* i : Sub band start indices Q0 */ + const Word16 *sfm_end /* i : Sub band end indices Q0 */ ); void apply_envelope_fx( - const Word16 *coeff, /* i : Coded/noisefilled normalized spectrum Q12 */ - const Word16 *norm, /* i : Envelope */ - const Word16 *norm_adj, /* i : Envelope adjustment Q15 */ - const Word16 num_sfm, /* i : Total number of bands */ - const Word16 last_sfm, /* i : Last coded band */ - const Word16 HQ_mode, /* i : HQ mode */ - const Word16 length, /* i : Frame length */ - const Word16 *sfm_start, /* i : Sub band start indices */ - const Word16 *sfm_end, /* i : Sub band end indices */ - Word32 *normq_v, /* o : Envelope with adjustment Q14 */ - Word32 *coeff_out, /* o : coded/noisefilled spectrum */ - const Word16 *coeff1, /* i : coded/noisefilled spectrum Q12 */ - Word32 *coeff_out1 /* o : coded/noisefilled spectrum Q12 */ + const Word16 *coeff, /* i : Coded/noisefilled normalized spectrum Q12 */ + const Word16 *norm, /* i : Envelope */ + const Word16 *norm_adj, /* i : Envelope adjustment Q15 */ + const Word16 num_sfm, /* i : Total number of bands */ + const Word16 last_sfm, /* i : Last coded band */ + const Word16 HQ_mode, /* i : HQ mode */ + const Word16 length, /* i : Frame length */ + const Word16 *sfm_start, /* i : Sub band start indices */ + const Word16 *sfm_end, /* i : Sub band end indices */ + Word32 *normq_v, /* o : Envelope with adjustment Q14 */ + Word32 *coeff_out, /* o : coded/noisefilled spectrum */ + const Word16 *coeff1, /* i : coded/noisefilled spectrum Q12 */ + Word32 *coeff_out1 /* o : coded/noisefilled spectrum Q12 */ ); /*========================================================================================================/ lsf_tools_fx.c /========================================================================================================*/ -void compute_poly_product_fx(Word16 *coef, Word32 *p, Word16 order); +void compute_poly_product_fx( Word16 *coef, Word32 *p, Word16 order ); Word16 xsp_to_xsf( - Word16 lsp -); + Word16 lsp ); Word16 xsf_to_xsp( - Word16 lsf -); + Word16 lsf ); -void lsp_convolve_fx(Word32 x, Word32 *p1, Word32 *p2, Word16 len); -Word32 poscos_fx(Word16 w); +void lsp_convolve_fx( Word32 x, Word32 *p1, Word32 *p2, Word16 len ); +Word32 poscos_fx( Word16 w ); Word32 sub_lsp2lsf_fx( - const Word16 lsp_i /* i : lsp[m] (range: -1<=val<1) Q15*/ + const Word16 lsp_i /* i : lsp[m] (range: -1<=val<1) Q15*/ ); void E_LPC_lsp_lsf_conversion( - const Word16 lsp[], /* i : lsp[m] (range: -1<=val<1) */ - Word16 lsf[], /* output : lsf[m] normalized (range: 0<=val<=6400) */ - const Word16 m /* i : LPC order */ + const Word16 lsp[], /* i : lsp[m] (range: -1<=val<1) */ + Word16 lsf[], /* output : lsf[m] normalized (range: 0<=val<=6400) */ + const Word16 m /* i : LPC order */ ); void E_LPC_lsf_lsp_conversion( - const Word16 lsf[], /* i : lsf[m] normalized (range: 0<=val<=6400) */ - Word16 lsp[], /* o : lsp[m] (range: -1<=val<1) */ - const Word16 m /* i : LPC order */ + const Word16 lsf[], /* i : lsf[m] normalized (range: 0<=val<=6400) */ + Word16 lsp[], /* o : lsp[m] (range: -1<=val<1) */ + const Word16 m /* i : LPC order */ ); -void E_LPC_f_lsp_a_conversion(const Word16 *lsp, Word16 *a, const Word16 m); +void E_LPC_f_lsp_a_conversion( const Word16 *lsp, Word16 *a, const Word16 m ); void E_LPC_a_isp_conversion( - const Word16 *a, /* i : LP filter coefficients */ - Word16 *isp, /* o : Line spectral pairs (in the cosine domain) */ - const Word16 *old_isp,/* i : LSP vector from past frame */ - const Word16 m /* i : LPC order */ + const Word16 *a, /* i : LP filter coefficients */ + Word16 *isp, /* o : Line spectral pairs (in the cosine domain) */ + const Word16 *old_isp, /* i : LSP vector from past frame */ + const Word16 m /* i : LPC order */ ); -void E_LPC_isp_isf_conversion(const Word16 isp[], Word16 isf[], const Word16 m); -void E_LPC_isf_isp_conversion(const Word16 isf[], Word16 isp[], const Word16 m); -void E_LPC_f_isp_a_conversion(const Word16 *isp, Word16 *a, const Word16 m); +void E_LPC_isp_isf_conversion( const Word16 isp[], Word16 isf[], const Word16 m ); +void E_LPC_isf_isp_conversion( const Word16 isf[], Word16 isp[], const Word16 m ); +void E_LPC_f_isp_a_conversion( const Word16 *isp, Word16 *a, const Word16 m ); void E_LPC_a_lsp_conversion( - const Word16 *a, /* i : LP filter coefficients */ - Word16 *lsp, /* o : Line spectral pairs (in the cosine domain) */ - const Word16 *old_lsp, /* i : LSP vector from past frame */ - const Word16 m /* i : LPC order */ + const Word16 *a, /* i : LP filter coefficients */ + Word16 *lsp, /* o : Line spectral pairs (in the cosine domain) */ + const Word16 *old_lsp, /* i : LSP vector from past frame */ + const Word16 m /* i : LPC order */ ); Word16 lpc2lsp_fx( - Word32 *a, - Word16 *freq, - Word16 *old_freq, - Word16 order -); + Word32 *a, + Word16 *freq, + Word16 *old_freq, + Word16 order ); void lsp2lpc_fx( - Word16 *a, - Word16 *freq, - Word16 *prev_a, - Word16 order -); + Word16 *a, + Word16 *freq, + Word16 *prev_a, + Word16 order ); void E_LPC_a_lsp_conversion( - const Word16 *a, /* i : LP filter coefficients */ - Word16 *lsp, /* o : Line spectral pairs (in the cosine domain) */ - const Word16 *old_lsp, /* i : LSP vector from past frame */ - const Word16 m /* i : LPC order */ + const Word16 *a, /* i : LP filter coefficients */ + Word16 *lsp, /* o : Line spectral pairs (in the cosine domain) */ + const Word16 *old_lsp, /* i : LSP vector from past frame */ + const Word16 m /* i : LPC order */ ); -void v_sort(Word16 *r, const Word16 lo, const Word16 up); +void v_sort( Word16 *r, const Word16 lo, const Word16 up ); -void compute_poly_product_fx(Word16 *coef, Word32 *p, Word16 order); +void compute_poly_product_fx( Word16 *coef, Word32 *p, Word16 order ); void dec_prm_hm_fx( - Decoder_State *st, - Word16 *prm_hm, - const Word16 L_frame -); -void msvq_dec -( - const Word16 *const*cb, /* i : Codebook (indexed cb[*stages][levels][p]) (0Q15) */ - const Word16 dims[], /* i : Dimension of each codebook stage (NULL: full dim.) */ - const Word16 offs[], /* i : Starting dimension of each codebook stage (NULL: 0) */ - const Word16 stages, /* i : Number of stages */ - const Word16 N, /* i : Vector dimension */ - const Word16 maxN, /* i : Codebook dimension */ - const Word16 Idx[], /* i : Indices */ + Decoder_State *st, + Word16 *prm_hm, + const Word16 L_frame ); +void msvq_dec( + const Word16 *const *cb, /* i : Codebook (indexed cb[*stages][levels][p]) (0Q15) */ + const Word16 dims[], /* i : Dimension of each codebook stage (NULL: full dim.) */ + const Word16 offs[], /* i : Starting dimension of each codebook stage (NULL: 0) */ + const Word16 stages, /* i : Number of stages */ + const Word16 N, /* i : Vector dimension */ + const Word16 maxN, /* i : Codebook dimension */ + const Word16 Idx[], /* i : Indices */ #ifdef IVAS_MSVQ - const int16_t applyIDCT_flag, /* i : applyIDCT flag */ - const float* invTrfMatrix, /* i : matrix for IDCT synthesis */ + const int16_t applyIDCT_flag, /* i : applyIDCT flag */ + const float *invTrfMatrix, /* i : matrix for IDCT synthesis */ #endif - Word16 *uq /* o : quantized vector (3Q12) */ + Word16 *uq /* o : quantized vector (3Q12) */ ); Word16 tcxlpc_get_cdk( - Word16 coder_type /* (I) VOICED indicator */ + Word16 coder_type /* (I) VOICED indicator */ ); void lsf_syn_mem_restore_fx( - Encoder_State *st_fx, /* o: state structure */ - Word16 btilt_code_fx, /* i: */ - Word32 gc_threshold_fx, /* i: */ - Word16 *clip_var_bck_fx, /* i: */ - Word16 next_force_sf_bck_fx, /* i: */ - Word16 *lsp_new, /* o: LSP vector to quantize */ - Word16 *lsf_new, /* o: quantized LSF vector */ - Word16 *lsp_mid, /* o: mid-frame LSP vector */ - Word16 clip_var, /* i: pitch clipping state var */ - Word16 *mem_AR, /* i: quantizer memory for AR model */ - Word16 *mem_MA, /* i: quantizer memory for MA model */ - Word16 *lsp_new_bck, /* i: LSP vector to quantize- backup */ - Word16 *lsf_new_bck, /* i: quantized LSF vector - backup */ - Word16 *lsp_mid_bck, /* i: mid-frame LSP vector - backup */ - Word16 mCb1, /* i: counter for stationary frame after a transition frame */ - Word32 *Bin_E, /* i: FFT Bin energy 128 *2 sets */ - Word32 *Bin_E_old, /* i: FFT Bin energy 128 sets */ - Word16 *mem_syn_bck, /* i: synthesis filter memory */ - Word16 mem_w0_bck, /* i: memory of the weighting filter */ - Word16 streaklimit, /* i:LSF quantizer */ - Word16 pstreaklen /* i:LSF quantizer */ + Encoder_State *st_fx, /* o: state structure */ + Word16 btilt_code_fx, /* i: */ + Word32 gc_threshold_fx, /* i: */ + Word16 *clip_var_bck_fx, /* i: */ + Word16 next_force_sf_bck_fx, /* i: */ + Word16 *lsp_new, /* o: LSP vector to quantize */ + Word16 *lsf_new, /* o: quantized LSF vector */ + Word16 *lsp_mid, /* o: mid-frame LSP vector */ + Word16 clip_var, /* i: pitch clipping state var */ + Word16 *mem_AR, /* i: quantizer memory for AR model */ + Word16 *mem_MA, /* i: quantizer memory for MA model */ + Word16 *lsp_new_bck, /* i: LSP vector to quantize- backup */ + Word16 *lsf_new_bck, /* i: quantized LSF vector - backup */ + Word16 *lsp_mid_bck, /* i: mid-frame LSP vector - backup */ + Word16 mCb1, /* i: counter for stationary frame after a transition frame */ + Word32 *Bin_E, /* i: FFT Bin energy 128 *2 sets */ + Word32 *Bin_E_old, /* i: FFT Bin energy 128 sets */ + Word16 *mem_syn_bck, /* i: synthesis filter memory */ + Word16 mem_w0_bck, /* i: memory of the weighting filter */ + Word16 streaklimit, /* i:LSF quantizer */ + Word16 pstreaklen /* i:LSF quantizer */ ); void lsf_update_memory( - Word16 narrowband, /* i : narrowband flag */ - const Word16 qisf[], /* i : quantized xSF coefficients */ - Word16 old_mem_MA[], /* i : MA memory */ - Word16 mem_MA[], /* o : updated MA memory */ - Word16 lpcorder /* i : LPC order */ + Word16 narrowband, /* i : narrowband flag */ + const Word16 qisf[], /* i : quantized xSF coefficients */ + Word16 old_mem_MA[], /* i : MA memory */ + Word16 mem_MA[], /* o : updated MA memory */ + Word16 lpcorder /* i : LPC order */ ); void lsf_syn_mem_backup_fx( - Encoder_State *st_fx, /* i: state structure */ - Word16 *btilt_code, /* i: tilt code */ - Word32 *bgc_threshold, /* i: */ - Word16 *clip_var_bck, /* o: */ - Word16 *next_force_sf_bck, /* o: */ - Word16 *lsp_new, /* i: LSP vector to quantize */ - Word16 *lsf_new, /* i: quantized LSF vector */ - Word16 *lsp_mid, /* i: mid-frame LSP vector */ - Word16 *clip_var, /* o: pitch clipping state var */ - Word16 *mem_AR, /* o: quantizer memory for AR model */ - Word16 *mem_MA, /* o: quantizer memory for AR model */ - Word16 *lsp_new_bck, /* o: LSP vector to quantize- backup */ - Word16 *lsf_new_bck, /* o: quantized LSF vector - backup */ - Word16 *lsp_mid_bck, /* o: mid-frame LSP vector - backup */ - Word16 *mCb1, /* o: counter for stationary frame after a transition frame */ - Word32 *Bin_E, /* o: FFT Bin energy 128 *2 sets */ - Word32 *Bin_E_old, /* o: FFT Bin energy 128 sets */ - Word16 *mem_syn_bck, /* o: synthesis filter memory */ - Word16 *mem_w0_bck, /* o: memory of the weighting filter */ - Word16 *streaklimit, - Word16 *pstreaklen -); + Encoder_State *st_fx, /* i: state structure */ + Word16 *btilt_code, /* i: tilt code */ + Word32 *bgc_threshold, /* i: */ + Word16 *clip_var_bck, /* o: */ + Word16 *next_force_sf_bck, /* o: */ + Word16 *lsp_new, /* i: LSP vector to quantize */ + Word16 *lsf_new, /* i: quantized LSF vector */ + Word16 *lsp_mid, /* i: mid-frame LSP vector */ + Word16 *clip_var, /* o: pitch clipping state var */ + Word16 *mem_AR, /* o: quantizer memory for AR model */ + Word16 *mem_MA, /* o: quantizer memory for AR model */ + Word16 *lsp_new_bck, /* o: LSP vector to quantize- backup */ + Word16 *lsf_new_bck, /* o: quantized LSF vector - backup */ + Word16 *lsp_mid_bck, /* o: mid-frame LSP vector - backup */ + Word16 *mCb1, /* o: counter for stationary frame after a transition frame */ + Word32 *Bin_E, /* o: FFT Bin energy 128 *2 sets */ + Word32 *Bin_E_old, /* o: FFT Bin energy 128 sets */ + Word16 *mem_syn_bck, /* o: synthesis filter memory */ + Word16 *mem_w0_bck, /* o: memory of the weighting filter */ + Word16 *streaklimit, + Word16 *pstreaklen ); void tcvq_Dec_fx( - Word16* ind, - Word16* d_out_fx, - const Word16 safety_net -); + Word16 *ind, + Word16 *d_out_fx, + const Word16 safety_net ); Word16 qlsf_ARSN_tcvq_Dec_16k_fx( - Word16 *y_fx, /* o : Quantized LSF vector */ - Word16 *indice, /* i : Indices */ - const Word16 nBits /* i : number of bits */ + Word16 *y_fx, /* o : Quantized LSF vector */ + Word16 *indice, /* i : Indices */ + const Word16 nBits /* i : number of bits */ ); void lsf2lsp_fx( - const Word16 lsf[], /* i : lsf[m] normalized (range: 0.0<=val<=0.5) x2.56 */ - Word16 lsp[], /* o : lsp[m] (range: -1<=val<1) Q15 */ - const Word16 m, /* i : LPC order Q0 */ - const Word32 int_fs /* i : internal sampling frequency */ + const Word16 lsf[], /* i : lsf[m] normalized (range: 0.0<=val<=0.5) x2.56 */ + Word16 lsp[], /* o : lsp[m] (range: -1<=val<1) Q15 */ + const Word16 m, /* i : LPC order Q0 */ + const Word32 int_fs /* i : internal sampling frequency */ ); void lsp2lsf_fx( - const Word16 lsp[], /* i : lsp[m] (range: -1<=val<1) Q15*/ - Word16 lsf[], /* o : lsf[m] normalized (range: 0.0<=val<=0.5) Q(x2.56)*/ - const Word16 m, /* i : LPC order Q0*/ - const Word32 int_fs /* i : internal sampling frequency */ + const Word16 lsp[], /* i : lsp[m] (range: -1<=val<1) Q15*/ + Word16 lsf[], /* o : lsf[m] normalized (range: 0.0<=val<=0.5) Q(x2.56)*/ + const Word16 m, /* i : LPC order Q0*/ + const Word32 int_fs /* i : internal sampling frequency */ ); void isf2lsf_fx( - const Word16 *isf, /* i : ISF vector */ - Word16 *lsf, /* o : LSF vector */ - Word16 *stable_lsp /* i/o: stable LSP filter coefficients */ + const Word16 *isf, /* i : ISF vector */ + Word16 *lsf, /* o : LSF vector */ + Word16 *stable_lsp /* i/o: stable LSP filter coefficients */ ); void lsf2isf_fx( - const Word16 *lsf, /* i : LSF vector */ - Word16 *isf, /* o : ISF vector */ - Word16 *stable_isp, /* i/o: stable ISP filter coefficients */ - const Word16 m /* i : order of LP analysis */ + const Word16 *lsf, /* i : LSF vector */ + Word16 *isf, /* o : ISF vector */ + Word16 *stable_isp, /* i/o: stable ISP filter coefficients */ + const Word16 m /* i : order of LP analysis */ ); void isp2lsp_fx( - const Word16 *isp, /* i : LSP vector */ - Word16 *lsp, /* o : ISP filter coefficients */ - Word16 *stable_lsp, /* i/o: stable LSP filter coefficients */ - const Word16 m /* i : order of LP analysis */ + const Word16 *isp, /* i : LSP vector */ + Word16 *lsp, /* o : ISP filter coefficients */ + Word16 *stable_lsp, /* i/o: stable LSP filter coefficients */ + const Word16 m /* i : order of LP analysis */ ); void lsp2isp_fx( - const Word16 *lsp, /* i : LSP vector */ - Word16 *isp, /* o : ISP filter coefficients */ - Word16 *stable_isp, /* i/o: ISP filter coefficients */ - const Word16 m /* i : order of LP analysis */ + const Word16 *lsp, /* i : LSP vector */ + Word16 *isp, /* o : ISP filter coefficients */ + Word16 *stable_isp, /* i/o: ISP filter coefficients */ + const Word16 m /* i : order of LP analysis */ ); -Word16 lsf_stab_fx( /* o : LP filter stability Q15*/ - const Word16 *lsf, /* i : LSF vector Q(x2.56)*/ - const Word16 *lsfold, /* i : old LSF vector Q(x2.56)*/ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame /* i : frame length */ +Word16 lsf_stab_fx( /* o : LP filter stability Q15*/ + const Word16 *lsf, /* i : LSF vector Q(x2.56)*/ + const Word16 *lsfold, /* i : old LSF vector Q(x2.56)*/ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const Word16 L_frame /* i : frame length */ ); -Word16 lsf_stab_ivas_fx( /* o : LP filter stability Q15*/ - const Word16 *lsf, /* i : LSF vector Q(x2.56)*/ - const Word16 *lsfold, /* i : old LSF vector Q(x2.56)*/ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame /* i : frame length */ +Word16 lsf_stab_ivas_fx( /* o : LP filter stability Q15*/ + const Word16 *lsf, /* i : LSF vector Q(x2.56)*/ + const Word16 *lsfold, /* i : old LSF vector Q(x2.56)*/ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const Word16 L_frame /* i : frame length */ ); void reorder_isf_fx( - Word16 *isf, /* i/o: ISFs in the frequency domain (0..0.5) */ - const Word16 min_dist, /* i : minimum required distance */ - const Word16 n, /* i : LPC order */ - const Word16 fs /* i : sampling frequency */ + Word16 *isf, /* i/o: ISFs in the frequency domain (0..0.5) */ + const Word16 min_dist, /* i : minimum required distance */ + const Word16 n, /* i : LPC order */ + const Word16 fs /* i : sampling frequency */ ); ivas_error find_pred_mode( - Word16* predmode, /* o: prediction mode */ - const Word16 coder_type, /* i: coding type */ - const Word16 bwidth, /* i: bandwidth index */ - const Word32 int_fs, /* i: sampling frequency */ - Word16* p_mode_lvq, /* o: index of LSF codebooks in safety net mode */ - Word16* p_mode_lvq_p, /* o: index of LSF codebooks in predictive mode (AR or MA) */ - Word32 core_brate /* i: core bit rate */ + Word16 *predmode, /* o: prediction mode */ + const Word16 coder_type, /* i: coding type */ + const Word16 bwidth, /* i: bandwidth index */ + const Word32 int_fs, /* i: sampling frequency */ + Word16 *p_mode_lvq, /* o: index of LSF codebooks in safety net mode */ + Word16 *p_mode_lvq_p, /* o: index of LSF codebooks in predictive mode (AR or MA) */ + Word32 core_brate /* i: core bit rate */ ); ivas_error lsf_allocate_fx( - const Word16 nBits, /* i : Number of bits to use for quantization */ - const Word16 framemode, /* i : ISF quantizer mode */ - const Word16 framemode_p, /* i : ISF quantizer mode predmode (mode_lvq_p) */ - Word16* stages0, /* o : Number of stages for safety-net quantizer */ - Word16* stages1, /* o : Number of stages for predictive quantizer */ - Word16 levels0[], /* o : Number of vectors for each stage for SFNET */ - Word16 levels1[], /* o : Number of vectors for each stage for pred */ - Word16 bits0[], /* o : Number of bits for each stage safety net */ - Word16 bits1[] /* o : Number of bits for each stage pred */ + const Word16 nBits, /* i : Number of bits to use for quantization */ + const Word16 framemode, /* i : ISF quantizer mode */ + const Word16 framemode_p, /* i : ISF quantizer mode predmode (mode_lvq_p) */ + Word16 *stages0, /* o : Number of stages for safety-net quantizer */ + Word16 *stages1, /* o : Number of stages for predictive quantizer */ + Word16 levels0[], /* o : Number of vectors for each stage for SFNET */ + Word16 levels1[], /* o : Number of vectors for each stage for pred */ + Word16 bits0[], /* o : Number of bits for each stage safety net */ + Word16 bits1[] /* o : Number of bits for each stage pred */ ); Word16 vq_dec_lvq_fx( - Word16 sf_flag, /* i : safety net flag */ - Word16 x[], /* o : Decoded vector Q(x2.56)*/ - Word16 indices[], /* i : Indices */ - Word16 stages, /* i : Number of stages */ - Word16 N, /* i : Vector dimension */ - Word16 mode, /* (i): mode_lvq, or mode_lvq_p */ - Word16 no_bits, /* (i): no. bits for lattice */ - Word32 *p_offset_scale1, - Word32 *p_offset_scale2, - Word32 *p_offset_scale1_p, - Word32 *p_offset_scale2_p, - Word16 *p_no_scales, - Word16 *p_no_scales_p -); + Word16 sf_flag, /* i : safety net flag */ + Word16 x[], /* o : Decoded vector Q(x2.56)*/ + Word16 indices[], /* i : Indices */ + Word16 stages, /* i : Number of stages */ + Word16 N, /* i : Vector dimension */ + Word16 mode, /* (i): mode_lvq, or mode_lvq_p */ + Word16 no_bits, /* (i): no. bits for lattice */ + Word32 *p_offset_scale1, + Word32 *p_offset_scale2, + Word32 *p_offset_scale1_p, + Word32 *p_offset_scale2_p, + Word16 *p_no_scales, + Word16 *p_no_scales_p ); Word16 vq_dec_lvq_ivas_fx( - Word16 sf_flag, /* i : safety net flag */ - Word16 x[], /* o : Decoded vector Q(x2.56)*/ - Word16 indices[], /* i : Indices */ - Word16 stages, /* i : Number of stages */ - Word16 N, /* i : Vector dimension */ - Word16 mode, /* (i): mode_lvq, or mode_lvq_p */ - Word16 no_bits /* (i): no. bits for lattice */ + Word16 sf_flag, /* i : safety net flag */ + Word16 x[], /* o : Decoded vector Q(x2.56)*/ + Word16 indices[], /* i : Indices */ + Word16 stages, /* i : Number of stages */ + Word16 N, /* i : Vector dimension */ + Word16 mode, /* (i): mode_lvq, or mode_lvq_p */ + Word16 no_bits /* (i): no. bits for lattice */ ); -void a2rc_fx(const Word16 *a, Word16 *refl, Word16 lpcorder); +void a2rc_fx( const Word16 *a, Word16 *refl, Word16 lpcorder ); void lsp_weights_fx( - Word16 lsp_nq_fx[], - Word16 w[], - Word16 Order, - Word16 *Qout -); + Word16 lsp_nq_fx[], + Word16 w[], + Word16 Order, + Word16 *Qout ); void space_lsfs_fx( - Word16 *lsfs, /* i/o: Line spectral frequencies */ - const Word16 order /* i : order of LP analysis */ + Word16 *lsfs, /* i/o: Line spectral frequencies */ + const Word16 order /* i : order of LP analysis */ ); void reorder_lsf_fx( - Word16 *lsf, /* i/o: LSFs in the frequency domain (0..0.5) Q(x2.56)*/ - const Word16 min_dist, /* i : minimum required distance x2.56*/ - const Word16 n, /* i : LPC order */ - const Word32 fs /* i : sampling frequency */ + Word16 *lsf, /* i/o: LSFs in the frequency domain (0..0.5) Q(x2.56)*/ + const Word16 min_dist, /* i : minimum required distance x2.56*/ + const Word16 n, /* i : LPC order */ + const Word32 fs /* i : sampling frequency */ ); /*========================================================================================================/ @@ -987,78 +960,67 @@ lpc_tools_fx.c /========================================================================================================*/ void autocorr_fx( - const Word16 x[], /* i : Input signal */ - const Word16 m, /* i : LPC order Q0 */ - Word16 r_h[], /* o : Autocorrelations (msb) Q15 */ - Word16 r_l[], /* o : Autocorrelations (lsb) */ - Word16 *Q_r, /* o : normailsation shift of r Q0 */ - const Word16 len, /* i : Frame lenght */ - const Word16* wind, /* i : Window used */ - Word16 rev_flag, - const Word16 sym_flag /* i : symmetric window flag */ + const Word16 x[], /* i : Input signal */ + const Word16 m, /* i : LPC order Q0 */ + Word16 r_h[], /* o : Autocorrelations (msb) Q15 */ + Word16 r_l[], /* o : Autocorrelations (lsb) */ + Word16 *Q_r, /* o : normailsation shift of r Q0 */ + const Word16 len, /* i : Frame lenght */ + const Word16 *wind, /* i : Window used */ + Word16 rev_flag, + const Word16 sym_flag /* i : symmetric window flag */ ); void autocorr_fx_32( - const Word16 x[], /* i : Input signal */ - const Word16 m, /* i : LPC order Q0 */ - Word32 r[], /* o : Autocorrelations (msb) */ - Word16 *Q_r, /* o : normalisation shift of r Q0 */ - const Word16 len, /* i : Frame lenght */ - const Word16* wind, /* i : Window used */ + const Word16 x[], /* i : Input signal */ + const Word16 m, /* i : LPC order Q0 */ + Word32 r[], /* o : Autocorrelations (msb) */ + Word16 *Q_r, /* o : normalisation shift of r Q0 */ + const Word16 len, /* i : Frame lenght */ + const Word16 *wind, /* i : Window used */ Word16 rev_flag, - const Word16 sym_flag /* i : symmetric window flag */ + const Word16 sym_flag /* i : symmetric window flag */ ); -Word16 E_LPC_lev_dur(const Word16 Rh[], const Word16 Rl[], Word16 A[], - Word32 epsP[], const Word16 order, Word16 *parcorr -); -Word16 E_LPC_lev_dur_stab(const Word16 Rh[], const Word16 Rl[], Word16 A[], - Word32 epsP[], const Word16 order, Word16 *parcorr, Word16 k_max -); +Word16 E_LPC_lev_dur( const Word16 Rh[], const Word16 Rl[], Word16 A[], Word32 epsP[], const Word16 order, Word16 *parcorr ); +Word16 E_LPC_lev_dur_stab( const Word16 Rh[], const Word16 Rl[], Word16 A[], Word32 epsP[], const Word16 order, Word16 *parcorr, Word16 k_max ); -Word16 E_LPC_lev_dur_fx(const Word16 Rh[], const Word16 Rl[], Word32 A[], - Word32 epsP[], const Word16 order - , Word32 *mem -); -Word16 E_LPC_lev_dur_stab_fx(const Word16 Rh[], const Word16 Rl[], Word32 A[], - Word32 epsP[], const Word16 order, - Word32 *mem, Word16 k_max -); +Word16 E_LPC_lev_dur_fx( const Word16 Rh[], const Word16 Rl[], Word32 A[], Word32 epsP[], const Word16 order, Word32 *mem ); +Word16 E_LPC_lev_dur_stab_fx( const Word16 Rh[], const Word16 Rl[], Word32 A[], Word32 epsP[], const Word16 order, Word32 *mem, Word16 k_max ); Word16 lev_dur_fx( - Word32 *a_fx, /* o : LP coefficients (a[0] = 1.0) */ - const Word32 *r_fx, /* i : vector of autocorrelations */ - const Word16 m, /* i : order of LP filter */ - Word32 epsP[], /* o : prediction error energy */ + Word32 *a_fx, /* o : LP coefficients (a[0] = 1.0) */ + const Word32 *r_fx, /* i : vector of autocorrelations */ + const Word16 m, /* i : order of LP filter */ + Word32 epsP[], /* o : prediction error energy */ Word16 q_a, - Word16 q_r -); + Word16 q_r ); -void E_LPC_a_add_tilt(const Word16 *a, Word16 *ap, Word16 gamma, Word16 m); -void E_LPC_int_lpc_tcx(const Word16 lsp_old[], /* i : LSPs from past frame (1Q14) */ - const Word16 lsp_new[], /* i : LSPs from present frame (1Q14) */ - Word16 a[] /* o : interpolated LP coefficients (4Q11) */ +void E_LPC_a_add_tilt( const Word16 *a, Word16 *ap, Word16 gamma, Word16 m ); +void E_LPC_int_lpc_tcx( const Word16 lsp_old[], /* i : LSPs from past frame (1Q14) */ + const Word16 lsp_new[], /* i : LSPs from present frame (1Q14) */ + Word16 a[] /* o : interpolated LP coefficients (4Q11) */ ); Word16 E_LPC_lsp_unweight( - /* const */ Word16 xsp_w[], /* (I): weighted xSP */ - Word16 xsp_uw[], /* (O): unweighted xSP */ - Word16 xsf_uw[], /* (O): unweighted xSF */ - Word16 inv_gamma, /* (I): inverse weighting factor */ - Word16 lpcorder /* (I): prediction order */ + /* const */ Word16 xsp_w[], /* (I): weighted xSP */ + Word16 xsp_uw[], /* (O): unweighted xSP */ + Word16 xsf_uw[], /* (O): unweighted xSF */ + Word16 inv_gamma, /* (I): inverse weighting factor */ + Word16 lpcorder /* (I): prediction order */ ); -Word32 E_LPC_schur(Word32 r[], Word16 reflCoeff[], Word32 epsP[], const Word16 m); -void E_LPC_a_lsf_isf_conversion(Word16 *lpcCoeffs, Word16 *lsf, const Word16 *old_lsf, Word16 lpcOrder, Word8 lpcRep); +Word32 E_LPC_schur( Word32 r[], Word16 reflCoeff[], Word32 epsP[], const Word16 m ); +void E_LPC_a_lsf_isf_conversion( Word16 *lpcCoeffs, Word16 *lsf, const Word16 *old_lsf, Word16 lpcOrder, Word8 lpcRep ); /*========================================================================================================/ bitstream_fx.c /========================================================================================================*/ -UWord16 get_next_indice( /* o : value of the indice */ - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 nb_bits /* i : number of bits that were used to quantize the indice */ +UWord16 get_next_indice( /* o : value of the indice */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 nb_bits /* i : number of bits that were used to quantize the indice */ ); UWord16 get_next_indice_fx( /* o : value of the indice */ @@ -1067,85 +1029,86 @@ UWord16 get_next_indice_fx( /* o : value of the indice */ ); void push_indice_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - Word16 id, /* i : ID of the indice */ - UWord16 value, /* i : value of the quantized indice */ - Word16 nb_bits /* i : number of bits used to quantize the indice */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 id, /* i : ID of the indice */ + UWord16 value, /* i : value of the quantized indice */ + Word16 nb_bits /* i : number of bits used to quantize the indice */ ); void push_next_indice_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - UWord16 value, /* i : value of the quantized indice */ - Word16 nb_bits /* i : number of bits used to quantize the indice */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + UWord16 value, /* i : value of the quantized indice */ + Word16 nb_bits /* i : number of bits used to quantize the indice */ ); Word16 rate2EVSmode( - const Word32 brate, /* i : bitrate */ - Word16* is_amr_wb /* o : (flag) does the bitrate belong to AMR-WB? Can be NULL */ + const Word32 brate, /* i : bitrate */ + Word16 *is_amr_wb /* o : (flag) does the bitrate belong to AMR-WB? Can be NULL */ ); void push_next_bits_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - Word16 bits[], /* i : bit buffer to pack, sequence of single bits */ - Word16 nb_bits /* i : number of bits to pack */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 bits[], /* i : bit buffer to pack, sequence of single bits */ + Word16 nb_bits /* i : number of bits to pack */ ); -UWord16 get_indice_fx( /* o : value of the indice */ - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 pos, /* i : absolute position in the bitstream */ - Word16 nb_bits /* i : number of bits that were used to quantize the indice */ +UWord16 get_indice_fx( /* o : value of the indice */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 pos, /* i : absolute position in the bitstream */ + Word16 nb_bits /* i : number of bits that were used to quantize the indice */ ); -UWord16 get_next_indice_1_fx( /* o : value of the indice */ - Decoder_State *st_fx /* i/o: decoder state structure */ +UWord16 get_next_indice_1_fx( /* o : value of the indice */ + Decoder_State *st_fx /* i/o: decoder state structure */ ); -//UWord16 get_next_indice( /* o : value of the indice */ +// UWord16 get_next_indice( /* o : value of the indice */ // Decoder_State *st_fx, /* i/o: decoder state structure */ // Word16 nb_bits /* i : number of bits that were used to quantize the indice */ //); -UWord16 get_next_indice_1( /* o : value of the indice */ - Decoder_State *st_fx /* i/o: decoder state structure */ +UWord16 get_next_indice_1( /* o : value of the indice */ + Decoder_State *st_fx /* i/o: decoder state structure */ ); -UWord16 get_next_indice_1_fx( /* o : value of the indice */ - Decoder_State *st_fx /* i/o: decoder state structure */ +UWord16 get_next_indice_1_fx( /* o : value of the indice */ + Decoder_State *st_fx /* i/o: decoder state structure */ ); -UWord16 get_next_indice_1_fx( /* o : value of the indice */ - Decoder_State *st_fx /* i/o: decoder state structure */ +UWord16 get_next_indice_1_fx( /* o : value of the indice */ + Decoder_State *st_fx /* i/o: decoder state structure */ ); void get_next_indice_tmp_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 nb_bits /* i : number of bits that were used to quantize the indice */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 nb_bits /* i : number of bits that were used to quantize the indice */ ); -UWord16 get_indice( /* o : value of the indice */ - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 pos, /* i : absolute position in the bitstream */ - Word16 nb_bits /* i : number of bits that were used to quantize the indice */ +UWord16 get_indice( /* o : value of the indice */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 pos, /* i : absolute position in the bitstream */ + Word16 nb_bits /* i : number of bits that were used to quantize the indice */ ); -UWord16 get_indice_1_fx( /* o : value of the indice */ - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 pos /* i : absolute position in the bitstream */ +UWord16 get_indice_1_fx( /* o : value of the indice */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 pos /* i : absolute position in the bitstream */ ); void reset_indices_enc_fx( - BSTR_ENC_HANDLE hBstr /* i/o: encoder state structure */ + BSTR_ENC_HANDLE hBstr /* i/o: encoder state structure */ ); void reset_indices_dec_fx( - Decoder_State *st_fx /* i/o: decoder state structure */ + Decoder_State *st_fx /* i/o: decoder state structure */ ); void write_indices_fx( - Encoder_State* st_fx, /* i/o: encoder state structure */ - BSTR_ENC_HANDLE hBstr, /* i/o: encoder state structure */ - FILE* file /* i : output bitstream file */ - , UWord8* pFrame, /* i: byte array with bit packet and byte aligned coded speech data */ - Word16 pFrame_size /* i: size of the binary encoded access unit [bits] */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder state structure */ + FILE *file /* i : output bitstream file */ + , + UWord8 *pFrame, /* i: byte array with bit packet and byte aligned coded speech data */ + Word16 pFrame_size /* i: size of the binary encoded access unit [bits] */ ); void write_indices_buf_fx( @@ -1153,99 +1116,97 @@ void write_indices_buf_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder state structure */ UWord16 *out_buf, /* i : output bitstream file */ UWord8 *pFrame, /* i: byte array with bit packet and byte aligned coded speech data */ - Word16 pFrame_size, /* i: size of the binary encoded access unit [bits] */ - UWord16 *num_bits -); + Word16 pFrame_size, /* i: size of the binary encoded access unit [bits] */ + UWord16 *num_bits ); void indices_to_serial( - const Encoder_State* st_fx, /* i: encoder state structure */ - BSTR_ENC_HANDLE hBstr, /* i/o: encoder state structure */ - UWord8* pFrame, /* o: byte array with bit packet and byte aligned coded speech data */ - Word16* pFrame_size /* o: size of the binary encoded access unit [bits] */ + const Encoder_State *st_fx, /* i: encoder state structure */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder state structure */ + UWord8 *pFrame, /* o: byte array with bit packet and byte aligned coded speech data */ + Word16 *pFrame_size /* o: size of the binary encoded access unit [bits] */ ); void indices_to_serial_generic( - const Indice *ind_list, /* i: indices list */ - const Word16 num_indices, /* i: number of indices to write */ - UWord8 *pFrame, /* o: byte array with bit packet and byte aligned coded speech data */ - Word16 *pFrame_size /* i/o: number of bits in the binary encoded access unit [bits] */ + const Indice *ind_list, /* i: indices list */ + const Word16 num_indices, /* i: number of indices to write */ + UWord8 *pFrame, /* o: byte array with bit packet and byte aligned coded speech data */ + Word16 *pFrame_size /* i/o: number of bits in the binary encoded access unit [bits] */ ); void dec_prm_core( - Decoder_State *st -); + Decoder_State *st ); void decision_matrix_core_dec( - Decoder_State *st /* i/o: decoder state structure */ + Decoder_State *st /* i/o: decoder state structure */ ); -Word16 BRATE2IDX_fx(Word32 brate); -Word16 BRATE2IDX16k_fx(Word32 brate); +Word16 BRATE2IDX_fx( Word32 brate ); +Word16 BRATE2IDX16k_fx( Word32 brate ); -Word32 BIT_ALLOC_IDX_fx(Word32 brate, Word16 ctype, Word16 sfrm, Word16 tc); -Word32 BIT_ALLOC_IDX_16KHZ_fx(Word32 brate, Word16 ctype, Word16 sfrm, Word16 tc); +Word32 BIT_ALLOC_IDX_fx( Word32 brate, Word16 ctype, Word16 sfrm, Word16 tc ); +Word32 BIT_ALLOC_IDX_16KHZ_fx( Word32 brate, Word16 ctype, Word16 sfrm, Word16 tc ); -Word16 read_indices_fx( /* o : 1 = OK, 0 = something wrong */ - Decoder_State *st_fx, /* i/o: decoder state structure */ - FILE *file, /* i : bitstream file */ - Word16 rew_flag /* i : rewind flag (rewind file after reading) */ +Word16 read_indices_fx( /* o : 1 = OK, 0 = something wrong */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + FILE *file, /* i : bitstream file */ + Word16 rew_flag /* i : rewind flag (rewind file after reading) */ ); -Word16 read_indices_mime( /* o : 1 = reading OK, 0 = problem */ - Decoder_State *st, /* i/o: decoder state structure */ - FILE *file, /* i : bitstream file */ - Word16 rew_flag /* i : rewind flag (rewind file after reading)*/ +Word16 read_indices_mime( /* o : 1 = reading OK, 0 = problem */ + Decoder_State *st, /* i/o: decoder state structure */ + FILE *file, /* i : bitstream file */ + Word16 rew_flag /* i : rewind flag (rewind file after reading)*/ ); void getPartialCopyInfo( - Decoder_State *st, /* i : decoder state structure */ - Word16 *coder_type, - Word16 *sharpFlag -); + Decoder_State *st, /* i : decoder state structure */ + Word16 *coder_type, + Word16 *sharpFlag ); void get_rfFlag( - Decoder_State *st, /* i : decoder state structure */ - Word16 *rf_flag, /* o : check for the RF flag */ - Word16 *nBits, - Word16 *ind -); + Decoder_State *st, /* i : decoder state structure */ + Word16 *rf_flag, /* o : check for the RF flag */ + Word16 *nBits, + Word16 *ind ); void get_rfFrameType( - Decoder_State *st, /* i : decoder state structure */ - Word16 *rf_frame_type /* o : RF frame type */ + Decoder_State *st, /* i : decoder state structure */ + Word16 *rf_frame_type /* o : RF frame type */ ); void get_rf_fec_offset( - Decoder_State *st, /* i : decoder state structure */ - Word16 *rf_fec_offset /* o : RF fec offset */ + Decoder_State *st, /* i : decoder state structure */ + Word16 *rf_fec_offset /* o : RF fec offset */ ); void get_rfTargetBits( - Word16 rf_frame_type, /* i : RF frame type */ - Word16 *rf_target_bits /* o : Number of RF target bits */ + Word16 rf_frame_type, /* i : RF frame type */ + Word16 *rf_target_bits /* o : Number of RF target bits */ ); void get_NextCoderType_fx( - UWord8 *bitsteam, /* i : bitstream */ - Word16 *next_coder_type /* o : next coder type */ + UWord8 *bitsteam, /* i : bitstream */ + Word16 *next_coder_type /* o : next coder type */ ); void read_indices_from_djb_fx( - Decoder_State *st, /* i/o: decoder state structure */ - UWord8 *pt_stream, /* i : bitstream file */ - Word16 nbits /* i : number of bits */ - , Word16 isAMRWB_IOmode - , Word16 core_mode - , Word16 qbit - , Word16 partialframe /* i : partial frame information */ - , Word16 next_coder_type /* i : next coder type information */ + Decoder_State *st, /* i/o: decoder state structure */ + UWord8 *pt_stream, /* i : bitstream file */ + Word16 nbits /* i : number of bits */ + , + Word16 isAMRWB_IOmode, + Word16 core_mode, + Word16 qbit, + Word16 partialframe /* i : partial frame information */ + , + Word16 next_coder_type /* i : next coder type information */ ); void evs_dec_previewFrame( - UWord8 *bitstream, /* i : bitstream pointer */ - Word16 bitstreamSize, /* i : bitstream size */ - Word16 *partialCopyFrameType, /* o : frame type of the partial copy */ - Word16 *partialCopyOffset /* o : offset of the partial copy relative to the primary copy */ + UWord8 *bitstream, /* i : bitstream pointer */ + Word16 bitstreamSize, /* i : bitstream size */ + Word16 *partialCopyFrameType, /* o : frame type of the partial copy */ + Word16 *partialCopyOffset /* o : offset of the partial copy relative to the primary copy */ ); /*========================================================================================================/ @@ -1253,162 +1214,161 @@ scale_mem_fx.c /========================================================================================================*/ Word16 Rescale_exc( - Word16 dct_post_old_exc_fx[], /* i/o: Music post processing memory */ - Word16 exc[], /* i/o: excitation to rescale Q_exc */ - Word16 bwe_exc[], - Word16 *last_exc_dct_in, - Word16 lg, /* i : frame size */ - Word16 lg32, - Word32 L_gain_code, /* i : decoded codebook gain Q16 */ - Word16 *sQ_exc, /* i/o: Excitation scaling factor */ - Word16 *sQsubfr, /* i/o: Past excitation scaling factors */ - Word16 exc2[], /* o : local excitation vector */ - Word16 i_subfr, /* i : subframe number */ - const Word16 coder_type -); + Word16 dct_post_old_exc_fx[], /* i/o: Music post processing memory */ + Word16 exc[], /* i/o: excitation to rescale Q_exc */ + Word16 bwe_exc[], + Word16 *last_exc_dct_in, + Word16 lg, /* i : frame size */ + Word16 lg32, + Word32 L_gain_code, /* i : decoded codebook gain Q16 */ + Word16 *sQ_exc, /* i/o: Excitation scaling factor */ + Word16 *sQsubfr, /* i/o: Past excitation scaling factors */ + Word16 exc2[], /* o : local excitation vector */ + Word16 i_subfr, /* i : subframe number */ + const Word16 coder_type ); void Rescale_mem( - const Word16 Q_exc, /* i : current excitation scaling (>=0) */ - Word16 *prev_Q_syn, /* i/o : scaling factor of previous frame */ - Word16 *Q_syn, /* i/o : scaling factor of frame */ - Word16 *mem_syn2, /* i/o : modified synthesis memory */ - Word16 *mem_syn_clas_estim_fx, /* i/o : old 12k8 core memory for classification */ - const Word16 MaxScaling, /* i: Minimal difference between excitation scaling and synthesis scaling */ - Word16 *mem_deemph, /* i/o: speech deemph filter memory */ - Word16 *pst_old_syn, /* i/o: psfiler */ - Word16 *pst_mem_deemp_err, /* i/o: psfiler */ - Word16 *mem_agc, - PFSTAT_HANDLE hPFstat, /* i/o: All memories related to NB post filter */ - const Word16 Vad_flag, - const Word16 Cna_flag, - const Word16 *tmp_buffer /* tmp_buffer in Q-1 */ + const Word16 Q_exc, /* i : current excitation scaling (>=0) */ + Word16 *prev_Q_syn, /* i/o : scaling factor of previous frame */ + Word16 *Q_syn, /* i/o : scaling factor of frame */ + Word16 *mem_syn2, /* i/o : modified synthesis memory */ + Word16 *mem_syn_clas_estim_fx, /* i/o : old 12k8 core memory for classification */ + const Word16 MaxScaling, /* i: Minimal difference between excitation scaling and synthesis scaling */ + Word16 *mem_deemph, /* i/o: speech deemph filter memory */ + Word16 *pst_old_syn, /* i/o: psfiler */ + Word16 *pst_mem_deemp_err, /* i/o: psfiler */ + Word16 *mem_agc, + PFSTAT_HANDLE hPFstat, /* i/o: All memories related to NB post filter */ + const Word16 Vad_flag, + const Word16 Cna_flag, + const Word16 *tmp_buffer /* tmp_buffer in Q-1 */ ); void scale_sig32( - Word32 x[], /* i/o: signal to scale Qx */ - const Word16 lg, /* i : size of x[] Q0 */ - const Word16 exp0 /* i : exponent: x = round(x << exp) Qx xx exp */ + Word32 x[], /* i/o: signal to scale Qx */ + const Word16 lg, /* i : size of x[] Q0 */ + const Word16 exp0 /* i : exponent: x = round(x << exp) Qx xx exp */ ); Word16 rescale_mem( - const Word16 *Q_exc, /* i : current excitation scaling (>=0) */ - Word16 *prev_Q_syn, /* i/o : scaling factor of previous frame */ - Word16 *Q_syn, /* i/o : scaling factor of frame */ - Word16 *mem_syn2, /* i/o : modified synthesis memory */ - Word16 *syn, /* i/o : synthesis to rescale Q_syn */ - Word16 mem_len, /* i : lenght of modified synthesis memory */ - Word16 i_subfr /* i : subframe number */ + const Word16 *Q_exc, /* i : current excitation scaling (>=0) */ + Word16 *prev_Q_syn, /* i/o : scaling factor of previous frame */ + Word16 *Q_syn, /* i/o : scaling factor of frame */ + Word16 *mem_syn2, /* i/o : modified synthesis memory */ + Word16 *syn, /* i/o : synthesis to rescale Q_syn */ + Word16 mem_len, /* i : lenght of modified synthesis memory */ + Word16 i_subfr /* i : subframe number */ ); -//hq_conf.c +// hq_conf.c void hq_configure_fx( - const Word16 length, /* i : Frame length Q0 */ - const Word16 hqswb_clas, /* i : HQ SWB class Q0 */ - const Word32 core_brate, /* i : Codec bitrate Q0 */ - Word16 *num_sfm, /* o : Total number of subbands Q0 */ - Word16 *nb_sfm, /* o : Total number of coded bands Q0 */ - Word16 *start_norm, /* o : First norm to be SDE encoded Q0 */ - Word16 *num_env_bands, /* o : Number coded envelope bands Q0 */ - Word16 *numnrmibits, /* o : Number of bits in fall-back norm encoding Q0 */ - Word16 *hq_generic_offset, /* o : Freq offset for HQ GENERIC Q0 */ - Word16 *sfmsize, /* o : Subband bandwidths Q0 */ - Word16 *sfm_start, /* o : Subband start coefficients Q0 */ - Word16 *sfm_end /* o : Subband end coefficients Q0 */ + const Word16 length, /* i : Frame length Q0 */ + const Word16 hqswb_clas, /* i : HQ SWB class Q0 */ + const Word32 core_brate, /* i : Codec bitrate Q0 */ + Word16 *num_sfm, /* o : Total number of subbands Q0 */ + Word16 *nb_sfm, /* o : Total number of coded bands Q0 */ + Word16 *start_norm, /* o : First norm to be SDE encoded Q0 */ + Word16 *num_env_bands, /* o : Number coded envelope bands Q0 */ + Word16 *numnrmibits, /* o : Number of bits in fall-back norm encoding Q0 */ + Word16 *hq_generic_offset, /* o : Freq offset for HQ GENERIC Q0 */ + Word16 *sfmsize, /* o : Subband bandwidths Q0 */ + Word16 *sfm_start, /* o : Subband start coefficients Q0 */ + Word16 *sfm_end /* o : Subband end coefficients Q0 */ ); void hq_configure_evs_fx( - const Word16 length, /* i : Frame length Q0 */ - const Word16 hqswb_clas, /* i : HQ SWB class Q0 */ - const Word32 core_brate, /* i : Codec bitrate Q0 */ - Word16 *num_sfm, /* o : Total number of subbands Q0 */ - Word16 *nb_sfm, /* o : Total number of coded bands Q0 */ - Word16 *start_norm, /* o : First norm to be SDE encoded Q0 */ - Word16 *num_env_bands, /* o : Number coded envelope bands Q0 */ - Word16 *numnrmibits, /* o : Number of bits in fall-back norm encoding Q0 */ - Word16 *hq_generic_offset, /* o : Freq offset for HQ GENERIC Q0 */ - Word16 *sfmsize, /* o : Subband bandwidths Q0 */ - Word16 *sfm_start, /* o : Subband start coefficients Q0 */ - Word16 *sfm_end /* o : Subband end coefficients Q0 */ -); - -//hp50.c -void hp20(Word16 signal[], /* i/o: signal to filter any */ - const Word16 stride, /* i : stride to be applied accessing signal */ - const Word16 lg, /* i : length of signal (integer) Q0 */ - Word32 mem[5], /* i/o: static filter memory with this layout: */ - /* mem[0]: y[-2] (32-bit) */ - /* mem[1]; y[-1] (32-bit) */ - /* mem[2]: x[-2] << 16 */ - /* mem[3]: x[-1] << 16 */ - /* Note: mem[0..3] need to be scaled per frame */ - /* mem[4]: states scale */ - const Word32 sFreq); - -//get_gain.c -Word32 get_gain( /* encoder side; enc = 0 -> decoder side */ - Word16 *sign /* i/o: sign of the maximum */ +Word16 findpulse_fx( /* o : pulse position */ + const Word16 L_frame, /* i : length of the frame */ + const Word16 res[], /* i : Residual signal <12 bits */ + const Word16 T0, /* i : Pitch estimation Q0 */ + const Word16 enc, /* i : enc = 1 -> encoder side; enc = 0 -> decoder side */ + Word16 *sign /* i/o: sign of the maximum */ ); -//env_stab_trans.c +// env_stab_trans.c void env_stab_transient_detect_fx( - const Word16 is_transient, /* i: Transient flag */ - const Word16 length, /* i : Length of spectrum (32 or 48 kHz) */ - const Word16 norm[], /* i : quantization indices for norms */ - Word16 *no_att_hangover, /* i/o: Frame counter for attenuation hangover (Q0) */ - Word32 *L_energy_lt, /* i/o: Long-term energy measure for transient detection (Q13) */ - const Word16 HQ_mode, /* i : HQ coding mode */ - const Word16 bin_th, /* i : HVQ cross-over frequency bin */ - const Word32 *L_coeff, /* i : Coded spectral coefficients */ - const Word16 Qcoeff /* i : Q of coded spectral coefficients */ + const Word16 is_transient, /* i: Transient flag */ + const Word16 length, /* i : Length of spectrum (32 or 48 kHz) */ + const Word16 norm[], /* i : quantization indices for norms */ + Word16 *no_att_hangover, /* i/o: Frame counter for attenuation hangover (Q0) */ + Word32 *L_energy_lt, /* i/o: Long-term energy measure for transient detection (Q13) */ + const Word16 HQ_mode, /* i : HQ coding mode */ + const Word16 bin_th, /* i : HVQ cross-over frequency bin */ + const Word32 *L_coeff, /* i : Coded spectral coefficients */ + const Word16 Qcoeff /* i : Q of coded spectral coefficients */ ); -//env_adj.c -void env_adj_fx -( - const Word16 *pulses, /* i : number of pulses per band Q0 */ - const Word16 length, /* i : length of spectrum Q0 */ - const Word16 last_sfm, /* i : index of the last band Q0 */ - Word16 *adj, /* o : adjustment factors for the envelope Q15 */ - const Word16 env_stab, /* i : envelope stability Q15 */ - const Word16 *sfmsize /* i : subband sizes Q0 */ +// env_adj.c +void env_adj_fx( + const Word16 *pulses, /* i : number of pulses per band Q0 */ + const Word16 length, /* i : length of spectrum Q0 */ + const Word16 last_sfm, /* i : index of the last band Q0 */ + Word16 *adj, /* o : adjustment factors for the envelope Q15 */ + const Word16 env_stab, /* i : envelope stability Q15 */ + const Word16 *sfmsize /* i : subband sizes Q0 */ ); -//env_stab.c +// env_stab.c -Word16 env_stability_fx( /* in Q15 */ - const Word16 *ynrm, /*i: Norm vector for current frame */ - const Word16 nb_sfm, /*i: Number of sub-bands */ - Word16 *mem_norm, /*i/o: Norm vector memory from past frame */ - Word16 *mem_env_delta, /*i/o: Envelope stability memory for smoothing in Q11 */ - const Word16 core_switching_flag/* i : Core switching flag */ +Word16 env_stability_fx( /* in Q15 */ + const Word16 *ynrm, /*i: Norm vector for current frame */ + const Word16 nb_sfm, /*i: Number of sub-bands */ + Word16 *mem_norm, /*i/o: Norm vector memory from past frame */ + Word16 *mem_env_delta, /*i/o: Envelope stability memory for smoothing in Q11 */ + const Word16 core_switching_flag /* i : Core switching flag */ ); -Word16 env_stab_smo_fx( /* Q0 */ - Word16 env_stab, /*i : env_stab value Q15 */ - Word16 *env_stab_state_p, /*i/o: env_stab state probabilities Q15 */ - Word16 *ho_cnt /*i/o: hangover counter for speech state */ +Word16 env_stab_smo_fx( /* Q0 */ + Word16 env_stab, /*i : env_stab value Q15 */ + Word16 *env_stab_state_p, /*i/o: env_stab state probabilities Q15 */ + Word16 *ho_cnt /*i/o: hangover counter for speech state */ ); -//enr_1_az.c -Word16 Enr_1_Az_fx( /* o : impulse response energy Q3 */ - const Word16 Aq[], /* i : LP filter coefs Qx based on the fact that Aq[0] == 1.0 */ - const Word16 len /* i : impulse response length Q0 */ +// enr_1_az.c +Word16 Enr_1_Az_fx( /* o : impulse response energy Q3 */ + const Word16 Aq[], /* i : LP filter coefs Qx based on the fact that Aq[0] == 1.0 */ + const Word16 len /* i : impulse response length Q0 */ ); #ifdef BASOP_NOGLOB -Word16 Enr_1_Az_fx_o( /* o : impulse response energy Q3 */ - const Word16 Aq[], /* i : LP filter coefs Qx based on the fact that Aq[0] == 1.0 */ - const Word16 len, /* i : impulse response length Q0 */ - Flag* Overflow_out /* o : propagating the Overflow flag to upper level */ +Word16 Enr_1_Az_fx_o( /* o : impulse response energy Q3 */ + const Word16 Aq[], /* i : LP filter coefs Qx based on the fact that Aq[0] == 1.0 */ + const Word16 len, /* i : impulse response length Q0 */ + Flag *Overflow_out /* o : propagating the Overflow flag to upper level */ ); #endif -//gs_gains_fx.c +// gs_gains_fx.c void Ener_per_band_comp_fx( - const Word16 exc_diff[], /* i : target signal Q_exc_diff */ - Word16 y_gain4[], /* o : Energy per band to quantize Q12 */ - const Word16 Q_exc_diff, - const Word16 Mband, /* i : Max band */ - const Word16 Eflag -); + const Word16 exc_diff[], /* i : target signal Q_exc_diff */ + Word16 y_gain4[], /* o : Energy per band to quantize Q12 */ + const Word16 Q_exc_diff, + const Word16 Mband, /* i : Max band */ + const Word16 Eflag ); void Ener_per_band_comp_ivas_fx( - const Word16 exc_diff_fx[], /* i : target signal Q_exc_diff */ - Word16 y_gain4_fx[], /* o : Energy per band to quantize Q12 */ - const Word16 Q_exc, /* i : frame length */ - const Word16 Mband, /* i : Max band */ - const Word16 Eflag, /* i : flag of highest band */ - const int16_t L_frame /* i : frame length */ + const Word16 exc_diff_fx[], /* i : target signal Q_exc_diff */ + Word16 y_gain4_fx[], /* o : Energy per band to quantize Q12 */ + const Word16 Q_exc, /* i : frame length */ + const Word16 Mband, /* i : Max band */ + const Word16 Eflag, /* i : flag of highest band */ + const int16_t L_frame /* i : frame length */ ); void Comp_and_apply_gain_fx( - Word16 exc_diffQ[], /* i/o: Quantized excitation */ - Word16 Ener_per_bd_iQ[], /* i : Target ener per band Q13 */ - Word16 Ener_per_bd_yQ[], /* i/o : Ener per band for norm vector i->Q13/o->Q13 */ - Word16 Mbands_gn, /* i : number of bands */ - const Word16 ReUseGain, /* i : Reuse the gain in Ener_per_bd_yQ */ - Word16 Qexc_diff, - Word16 Q_exc -); - -//gs_preech.c + Word16 exc_diffQ[], /* i/o: Quantized excitation */ + Word16 Ener_per_bd_iQ[], /* i : Target ener per band Q13 */ + Word16 Ener_per_bd_yQ[], /* i/o : Ener per band for norm vector i->Q13/o->Q13 */ + Word16 Mbands_gn, /* i : number of bands */ + const Word16 ReUseGain, /* i : Reuse the gain in Ener_per_bd_yQ */ + Word16 Qexc_diff, + Word16 Q_exc ); + +// gs_preech.c void pre_echo_att_fx( - Word32* Last_frame_ener_fx, /* i/o: Energy of the last frame 2*Q_new+1*/ - Word16* exc_fx, /* i/o: Excitation of the current frame Q_new*/ - const Word16 gsc_attack_flag_fx, /* i : flag signalling attack encoded by AC mode (GSC) */ - const Word16 Q_new, - const Word16 last_coder_type, /* i : Last coding mode */ - const Word16 L_frame /* i : Frame length*/ + Word32 *Last_frame_ener_fx, /* i/o: Energy of the last frame 2*Q_new+1*/ + Word16 *exc_fx, /* i/o: Excitation of the current frame Q_new*/ + const Word16 gsc_attack_flag_fx, /* i : flag signalling attack encoded by AC mode (GSC) */ + const Word16 Q_new, + const Word16 last_coder_type, /* i : Last coding mode */ + const Word16 L_frame /* i : Frame length*/ ); -//wtda_fx.c +// wtda_fx.c void tcx_get_windows_mode1( const Word16 left_mode, /* i: overlap mode of left window half */ const Word16 right_mode, /* i: overlap mode of right window half */ @@ -1623,14 +1580,14 @@ void tcx_get_windows_mode1( ); void wtda_fx( - Word16* new_audio, /* i : i audio Q0 */ - Word16* Q, /* i/o : Q of i /Output Audio */ - Word32* wtda_audio, /* o : windowed audio Qout */ - Word16* old_wtda, /* i/o: windowed audio from previous frame Qout */ - Word16* Qold_wtda, - const Word16 left_mode, /* i : window overlap of previous frame (0: full, 2: none, or 3: half) */ - const Word16 right_mode, /* i : window overlap of current frame (0: full, 2: none, or 3: half) */ - const Word16 L /* i : length */ + Word16 *new_audio, /* i : i audio Q0 */ + Word16 *Q, /* i/o : Q of i /Output Audio */ + Word32 *wtda_audio, /* o : windowed audio Qout */ + Word16 *old_wtda, /* i/o: windowed audio from previous frame Qout */ + Word16 *Qold_wtda, + const Word16 left_mode, /* i : window overlap of previous frame (0: full, 2: none, or 3: half) */ + const Word16 right_mode, /* i : window overlap of current frame (0: full, 2: none, or 3: half) */ + const Word16 L /* i : length */ ); /*========================================================================================================/ @@ -1639,298 +1596,294 @@ swb_bwe_com_lr_fx.c typedef struct GainItemStr_fx { - Word16 nmrValue_fx; - Word16 gainIndex_fx; + Word16 nmrValue_fx; + Word16 gainIndex_fx; } GainItem_fx; void GetPredictedSignal_fx( - const Word16 *predBuf_fx, /* i: Q8 */ - Word32 *L_outBuf, /* o: Q9 */ - const Word16 lag_fx, /* i: Q0 */ - const Word16 fLen_fx, /* i: Q0 */ - const Word16 lagGains_fx, /* i: Qgain */ - const Word16 Qgain /* i: Q0 */ + const Word16 *predBuf_fx, /* i: Q8 */ + Word32 *L_outBuf, /* o: Q9 */ + const Word16 lag_fx, /* i: Q0 */ + const Word16 fLen_fx, /* i: Q0 */ + const Word16 lagGains_fx, /* i: Qgain */ + const Word16 Qgain /* i: Q0 */ ); void Get20Log10Spec_fx( - const Word32 *L_inBuf, /* i : i Q_inBuf */ - Word16 *outBuf_fx, /* o : output Q7 */ - const Word16 fLen, /* i : loop length */ - const Word16 Q_inBuf /* i : Qvalue of L_inBuf */ + const Word32 *L_inBuf, /* i : i Q_inBuf */ + Word16 *outBuf_fx, /* o : output Q7 */ + const Word16 fLen, /* i : loop length */ + const Word16 Q_inBuf /* i : Qvalue of L_inBuf */ ); void GetSynthesizedSpecThinOut_fx( - const Word16 *predBuf_fx, /* i : Qss: prediction buffer (i.e., lowband) */ - const Word16 Qss, /* i : Q value of i vector */ - Word32 *L_outBuf, /* o : QsL: synthesized spectrum */ - Word16 QsL, /* o : Q value of synthesized spectrum */ - const Word16 nBands_fx, /* i : Q0: number of subbands calculated */ - const Word16 *sbWidth_fx, /* i : Q0: subband lengths */ - const Word16 *lagIndices_fx, /* i : Q0: lowband index for each subband */ - const Word16 *lagGains_fx, /* i : Qgain: lagGain for each subband */ - const Word16 *QlagGains_fx, /* i : Q0: Q value of lagGains_fx */ - const Word16 predBufLen_fx /* i : Q0: lowband length */ + const Word16 *predBuf_fx, /* i : Qss: prediction buffer (i.e., lowband) */ + const Word16 Qss, /* i : Q value of i vector */ + Word32 *L_outBuf, /* o : QsL: synthesized spectrum */ + Word16 QsL, /* o : Q value of synthesized spectrum */ + const Word16 nBands_fx, /* i : Q0: number of subbands calculated */ + const Word16 *sbWidth_fx, /* i : Q0: subband lengths */ + const Word16 *lagIndices_fx, /* i : Q0: lowband index for each subband */ + const Word16 *lagGains_fx, /* i : Qgain: lagGain for each subband */ + const Word16 *QlagGains_fx, /* i : Q0: Q value of lagGains_fx */ + const Word16 predBufLen_fx /* i : Q0: lowband length */ ); void GetlagGains_fx( - const Word16 *predBuf_fx, /* i: Qss Low freq. Smoothed Spectrum */ - const Word16 Qss, /* i: Q0 Q value of predBuf */ - const Word32 *L_band_energy, /* i: Qbe Band Energy */ - const Word16 Qbe, /* i: Q0 Q value of band energy */ - const Word16 nBands, /* i: Q0 number of SWB subbands */ - const Word16 *sbWidth, /* i: Q0 width of SWB subbands */ - const Word16 *lagIndices, /* i: Q0 lagIndices */ - const Word16 predBufLen, /* i: Q0 length of predBuf */ - Word16 *lagGains_fx, /* o: QlagGains lagGains */ - Word16 *QlagGains /* o: Q0 Q value of lagGains */ -); - -void Gettonl_scalfact_fx -( - Word32 *L_outBuf, /* i/o: QsL synthesized spectrum */ - Word16 QsL, /* i : Q0 Q value for outBuf */ - const Word32 *L_codbuf, /* i : QsL core coder */ - const Word16 fLenLow, /* i : Q0 lowband length */ - const Word16 fLenHigh, /* i : Q0 highband length */ - const Word16 harmonic_band, /* i : Q0 total number of Low frequency bands */ - const Word16 bands, /* i : Q0 total number of subbands in a frame */ - Word32 *L_band_energy, /* i : Qbe band energy of each subband */ - Word16 Qbe, /* i : Q0 Q value for band_energy */ - const Word16 *band_start, /* i : Q0 subband start indices */ - const Word16 *band_end, /* i : Q0 subband end indices */ - const Word16 p2aflags[], /* i : Q0 missing bands in the core coder */ - Word32 L_be_tonal[], /* i : QbeL tonal energy */ - Word16 QbeL, /* i : Q0 Q value for be_tonal */ - GainItem_fx *pk_sf_fx, /* i : toanl information for Sparse filling */ - Word16 Qss, /* i : Q0 Q value for pk_sf.nmrValue */ - Word16 *pul_res_pk /* i : Q0 pulse resolution information */ + const Word16 *predBuf_fx, /* i: Qss Low freq. Smoothed Spectrum */ + const Word16 Qss, /* i: Q0 Q value of predBuf */ + const Word32 *L_band_energy, /* i: Qbe Band Energy */ + const Word16 Qbe, /* i: Q0 Q value of band energy */ + const Word16 nBands, /* i: Q0 number of SWB subbands */ + const Word16 *sbWidth, /* i: Q0 width of SWB subbands */ + const Word16 *lagIndices, /* i: Q0 lagIndices */ + const Word16 predBufLen, /* i: Q0 length of predBuf */ + Word16 *lagGains_fx, /* o: QlagGains lagGains */ + Word16 *QlagGains /* o: Q0 Q value of lagGains */ +); + +void Gettonl_scalfact_fx( + Word32 *L_outBuf, /* i/o: QsL synthesized spectrum */ + Word16 QsL, /* i : Q0 Q value for outBuf */ + const Word32 *L_codbuf, /* i : QsL core coder */ + const Word16 fLenLow, /* i : Q0 lowband length */ + const Word16 fLenHigh, /* i : Q0 highband length */ + const Word16 harmonic_band, /* i : Q0 total number of Low frequency bands */ + const Word16 bands, /* i : Q0 total number of subbands in a frame */ + Word32 *L_band_energy, /* i : Qbe band energy of each subband */ + Word16 Qbe, /* i : Q0 Q value for band_energy */ + const Word16 *band_start, /* i : Q0 subband start indices */ + const Word16 *band_end, /* i : Q0 subband end indices */ + const Word16 p2aflags[], /* i : Q0 missing bands in the core coder */ + Word32 L_be_tonal[], /* i : QbeL tonal energy */ + Word16 QbeL, /* i : Q0 Q value for be_tonal */ + GainItem_fx *pk_sf_fx, /* i : toanl information for Sparse filling */ + Word16 Qss, /* i : Q0 Q value for pk_sf.nmrValue */ + Word16 *pul_res_pk /* i : Q0 pulse resolution information */ ); void SpectrumSmoothing_fx( - const Word32 *L_inBuf, /* i : Qs Low band MDCT */ - Word16 *outBuf_fx, /* o : Qss output */ - Word16 *Qss, /* o : Q0 Q value of output vector */ - const Word16 fLen, /* i : Q0 length */ - const Word16 th_cut_fx /* i : Qss threshold of cut */ + const Word32 *L_inBuf, /* i : Qs Low band MDCT */ + Word16 *outBuf_fx, /* o : Qss output */ + Word16 *Qss, /* o : Q0 Q value of output vector */ + const Word16 fLen, /* i : Q0 length */ + const Word16 th_cut_fx /* i : Qss threshold of cut */ ); void SpectrumSmoothing_nss_fx( - const Word32 *L_inBuf, /* i : lowband MDCT */ - Word16 *outBuf_fx, /* o : output */ - Word16 *Qss, /* o : Q value for output vector */ - const Word16 fLen /* i : length */ + const Word32 *L_inBuf, /* i : lowband MDCT */ + Word16 *outBuf_fx, /* o : output */ + Word16 *Qss, /* o : Q value for output vector */ + const Word16 fLen /* i : length */ ); void hf_parinitiz_fx( - const Word32 L_total_brate, - const Word16 hqswb_clas_fx, - Word16 lowlength_fx, - Word16 highlength_fx, - Word16 wBands_fx[], - const Word16 **subband_search_offset_fx, - const Word16 **subband_offsets_fx, - Word16 *nBands_fx, - Word16 *nBands_search_fx, - Word16 *swb_lowband_fx, - Word16 *swb_highband_fx -); + const Word32 L_total_brate, + const Word16 hqswb_clas_fx, + Word16 lowlength_fx, + Word16 highlength_fx, + Word16 wBands_fx[], + const Word16 **subband_search_offset_fx, + const Word16 **subband_offsets_fx, + Word16 *nBands_fx, + Word16 *nBands_search_fx, + Word16 *swb_lowband_fx, + Word16 *swb_highband_fx ); void noise_extr_corcod_fx( - Word32 L_spectra[], /* i : QsL core coder */ - const Word32 L_spectra_ni[], /* i : QsL core coder with sparse filling */ - Word16 sspectra_fx[], /* o : Qss Smoothed tonal information from core coder */ - Word16 sspectra_diff_fx[], /* o : Qss non tonal infomration for gap filling */ - Word16 sspectra_ni_fx[], /* o : Qss smoothed core coder */ - const Word16 fLenLow_fx, /* i : Q0 low frequency bands width */ - Word16 prev_hqswb_clas, /* i : Q0 classification information */ - Word16 *prev_ni_ratio_fx, /* i : Q15 noise paraemeter */ - Word16 *Qss /* o : Q0 Q value for sspectra_*_fx */ + Word32 L_spectra[], /* i : QsL core coder */ + const Word32 L_spectra_ni[], /* i : QsL core coder with sparse filling */ + Word16 sspectra_fx[], /* o : Qss Smoothed tonal information from core coder */ + Word16 sspectra_diff_fx[], /* o : Qss non tonal infomration for gap filling */ + Word16 sspectra_ni_fx[], /* o : Qss smoothed core coder */ + const Word16 fLenLow_fx, /* i : Q0 low frequency bands width */ + Word16 prev_hqswb_clas, /* i : Q0 classification information */ + Word16 *prev_ni_ratio_fx, /* i : Q15 noise paraemeter */ + Word16 *Qss /* o : Q0 Q value for sspectra_*_fx */ ); void sqrt_32n_16_fx( - Word32 L_in, /* i : i vector (Word32) */ - Word16 Qin, /* i : Q value for L_in */ - Word16 *out_fx, /* o : sqrt i vector (Word16) */ - Word16 *Qout /* o : Q value for out_fx */ + Word32 L_in, /* i : i vector (Word32) */ + Word16 Qin, /* i : Q value for L_in */ + Word16 *out_fx, /* o : sqrt i vector (Word16) */ + Word16 *Qout /* o : Q value for out_fx */ ); -Word16 div_s_ss( /* o: result of division (Word16 Q0) */ - const Word16 n, /* i: numerator (Word16 Q0 */ - const Word16 d /* i: denominator (Word16 Q0) */ +Word16 div_s_ss( /* o: result of division (Word16 Q0) */ + const Word16 n, /* i: numerator (Word16 Q0 */ + const Word16 d /* i: denominator (Word16 Q0) */ ); void noiseinj_hf_fx( - Word32 L_xSynth_har[], /* i/o : Qs gap filled information */ - Word16 Qs, /* i : Q0 Q value for xSynth_har */ - Word32 L_th_g[], /* i : Qs level adjustment information */ - Word32 L_band_energy[], /* i : Qbe subband energies */ - Word16 Qbe, /* i : Q0 Q value for band_energy */ - Word16 *prev_En_sb_fx, /* i/o : QsEn smoothed sqrt band Energies */ - const Word16 p2a_flags_fx[], /* i : Q0 Missing bands in the core coder */ - const Word16 BANDS_fx, /* i : Q0 total bands */ - const Word16 band_start_fx[], /* i : Q0 band start indices */ - const Word16 band_end_fx[], /* i : Q0 band end indices */ - const Word16 fLenLow_fx, /* i : Q0 low frequency bandwidth */ - const Word16 fLenHigh_fx /* i : Q0 SWB frequency bandwidth */ -); - -void post_hq2_swb_fx -( - const Word32 L_m[], /* i : input_signal */ - const Word16 lowlength_fx, /* i : lowband length */ - const Word16 highlength_fx, /* i : highband length */ - const Word16 hqswb_clas_fx, /* i : HQ2 class information */ - const Word16 har_bands_fx, /* i : Number of LF harmonic bands */ - const Word16 bands_fx, /* i : Total number of Subbands in a frame */ - const Word16 p2a_flags_fx[], /* i : HF tonal indicator */ - const Word16 band_start_fx[], /* i : band start of each SB */ - const Word16 band_end_fx[], /* i : band end of each SB */ - Word32 L_y2[], /* o : output signal */ - Word16 npulses_fx[] /* i/o : Number of coded spectrum */ -); - -void preset_hq2_swb_fx -( - const Word16 hqswb_clas_fx, /* i : HQ2 class information */ - const Word16 band_end_fx[], /* i : band end of each SB */ - Word16 *har_bands_fx, /* i/o : Number of LF harmonic bands */ - Word16 p2a_bands_fx, /* i : flag for peakness */ - const Word16 length_fx, /* i : processed band length */ - const Word16 bands_fx, /* i : Total number of Subbands in a frame */ - Word16 *lowlength_fx, /* o : lowband length */ - Word16 *highlength_fx, /* o : highband length */ - Word32 L_m[] /* o : MDCT */ + Word32 L_xSynth_har[], /* i/o : Qs gap filled information */ + Word16 Qs, /* i : Q0 Q value for xSynth_har */ + Word32 L_th_g[], /* i : Qs level adjustment information */ + Word32 L_band_energy[], /* i : Qbe subband energies */ + Word16 Qbe, /* i : Q0 Q value for band_energy */ + Word16 *prev_En_sb_fx, /* i/o : QsEn smoothed sqrt band Energies */ + const Word16 p2a_flags_fx[], /* i : Q0 Missing bands in the core coder */ + const Word16 BANDS_fx, /* i : Q0 total bands */ + const Word16 band_start_fx[], /* i : Q0 band start indices */ + const Word16 band_end_fx[], /* i : Q0 band end indices */ + const Word16 fLenLow_fx, /* i : Q0 low frequency bandwidth */ + const Word16 fLenHigh_fx /* i : Q0 SWB frequency bandwidth */ +); + +void post_hq2_swb_fx( + const Word32 L_m[], /* i : input_signal */ + const Word16 lowlength_fx, /* i : lowband length */ + const Word16 highlength_fx, /* i : highband length */ + const Word16 hqswb_clas_fx, /* i : HQ2 class information */ + const Word16 har_bands_fx, /* i : Number of LF harmonic bands */ + const Word16 bands_fx, /* i : Total number of Subbands in a frame */ + const Word16 p2a_flags_fx[], /* i : HF tonal indicator */ + const Word16 band_start_fx[], /* i : band start of each SB */ + const Word16 band_end_fx[], /* i : band end of each SB */ + Word32 L_y2[], /* o : output signal */ + Word16 npulses_fx[] /* i/o : Number of coded spectrum */ +); + +void preset_hq2_swb_fx( + const Word16 hqswb_clas_fx, /* i : HQ2 class information */ + const Word16 band_end_fx[], /* i : band end of each SB */ + Word16 *har_bands_fx, /* i/o : Number of LF harmonic bands */ + Word16 p2a_bands_fx, /* i : flag for peakness */ + const Word16 length_fx, /* i : processed band length */ + const Word16 bands_fx, /* i : Total number of Subbands in a frame */ + Word16 *lowlength_fx, /* o : lowband length */ + Word16 *highlength_fx, /* o : highband length */ + Word32 L_m[] /* o : MDCT */ ); void return_bits_normal2_fx( - Word16 *bit_budget_fx, /* i/o : bit budget */ - const Word16 p2a_flags_fx[], /* i : HF tonal indicator */ - const Word16 bands_fx, /* i : Total number of Subbands in a frame */ - const Word16 bits_lagIndices_fx[] /* i : bits for lagIndices */ + Word16 *bit_budget_fx, /* i/o : bit budget */ + const Word16 p2a_flags_fx[], /* i : HF tonal indicator */ + const Word16 bands_fx, /* i : Total number of Subbands in a frame */ + const Word16 bits_lagIndices_fx[] /* i : bits for lagIndices */ ); -Word16 spectrumsmooth_noiseton_fx( /* o : Qss ss_min */ - Word32 L_spectra[], /* i : Qs core coder */ - /*Word16 Qs,*/ /* i : Q0 Q value for spectra, spectra_ni */ - const Word32 L_spectra_ni[], /* i : Qs core coder with sparse filling */ - Word16 sspectra_fx[], /* o : Qss Smoothed tonal information from core coder */ - Word16 sspectra_diff_fx[], /* o : Qss non tonal infomration for gap filling */ - Word16 sspectra_ni_fx[], /* o : Qss smoothed core coder */ - Word16 *Qss, /* o : Q0 Q value for sspectra* */ - const Word16 fLenLow_fx, /* i : Q0 low frequency boundaries */ - Word16 *ni_seed_fx /* io : Q0 random seed */ +Word16 spectrumsmooth_noiseton_fx( /* o : Qss ss_min */ + Word32 L_spectra[], /* i : Qs core coder */ + /*Word16 Qs,*/ /* i : Q0 Q value for spectra, spectra_ni */ + const Word32 L_spectra_ni[], /* i : Qs core coder with sparse filling */ + Word16 sspectra_fx[], /* o : Qss Smoothed tonal information from core coder */ + Word16 sspectra_diff_fx[], /* o : Qss non tonal infomration for gap filling */ + Word16 sspectra_ni_fx[], /* o : Qss smoothed core coder */ + Word16 *Qss, /* o : Q0 Q value for sspectra* */ + const Word16 fLenLow_fx, /* i : Q0 low frequency boundaries */ + Word16 *ni_seed_fx /* io : Q0 random seed */ ); void ton_ene_est_fx( - Word32 L_xSynth_har[], /* i/o: QsL buffer with non tonal compoents */ - const Word16 QsL, /* i : Q0 Q value for xSynth_har */ - Word32 L_be_tonal[], /* o : QbeL tonal energy of the missing bands */ - Word16* QbeL, /* o : Q0 Q value for be_tonal */ - const Word32 L_band_energy[], /* i : Qbe subband energies */ - const Word16 Qbe, /* i : Q0 Q value for band_energy */ - const Word16 band_start[], /* i : Q0 subband start indices */ - const Word16 band_end[], /* i : Q0 subband end indices */ - const Word16 band_width[], /* i : Q0 subband widths */ - const Word16 fLenLow, /* i : Q0 low frequency width */ - const Word16 fLenHigh, /* i : Q0 High frequency width */ - const Word16 bands, /* i : Q0 total subbands */ - const Word16 har_bands, /* i : Q0 total number of harmonics bands */ - const Word16 ni_lvl_fx, /* i : Q11 noise enve for the hf bands */ - GainItem_fx pk_sf_fx[], /* i : */ - const Word16 Qss, /* i : Q0 Q value for GainItem_fx->nmrValue */ - const Word16* pul_res /* i : Q0 tonal resolution */ + Word32 L_xSynth_har[], /* i/o: QsL buffer with non tonal compoents */ + const Word16 QsL, /* i : Q0 Q value for xSynth_har */ + Word32 L_be_tonal[], /* o : QbeL tonal energy of the missing bands */ + Word16 *QbeL, /* o : Q0 Q value for be_tonal */ + const Word32 L_band_energy[], /* i : Qbe subband energies */ + const Word16 Qbe, /* i : Q0 Q value for band_energy */ + const Word16 band_start[], /* i : Q0 subband start indices */ + const Word16 band_end[], /* i : Q0 subband end indices */ + const Word16 band_width[], /* i : Q0 subband widths */ + const Word16 fLenLow, /* i : Q0 low frequency width */ + const Word16 fLenHigh, /* i : Q0 High frequency width */ + const Word16 bands, /* i : Q0 total subbands */ + const Word16 har_bands, /* i : Q0 total number of harmonics bands */ + const Word16 ni_lvl_fx, /* i : Q11 noise enve for the hf bands */ + GainItem_fx pk_sf_fx[], /* i : */ + const Word16 Qss, /* i : Q0 Q value for GainItem_fx->nmrValue */ + const Word16 *pul_res /* i : Q0 tonal resolution */ ); void norm_vec_32_16_scale_fx( - Word32 *L_vec_in, /* i : i vector */ - Word16 Qin, /* i : Q value for i vector */ - Word16 length_fx, /* i :vector size */ - Word16 *vec_out_fx, /* o : output vectror */ - Word16 *Qout, /* o : Q value for output vectro */ - Word16 exp_safe /* i : suppress left shift: for prevend overflow on sum */ + Word32 *L_vec_in, /* i : i vector */ + Word16 Qin, /* i : Q value for i vector */ + Word16 length_fx, /* i :vector size */ + Word16 *vec_out_fx, /* o : output vectror */ + Word16 *Qout, /* o : Q value for output vectro */ + Word16 exp_safe /* i : suppress left shift: for prevend overflow on sum */ ); void updat_prev_frm_fx( - Word32 L_y2[], /* i/o: core coder buffer */ - Word32 L_t_audio[], /* o: core coder buffer */ - Word32 L_bwe_br, /* i: core bitrate */ - Word16 length_fx, /* i: frame length coded bw */ - const Word16 inner_frame_fx, /* i: i frame length */ - Word16 bands_fx, /* i: sub band resolution */ - Word16 bwidth_fx, /* i: NB/WB/SWB indicator */ - const Word16 is_transient_fx, /* i: signal class information */ - Word16 hqswb_clas_fx, /* i: signal class information */ - Word16 *prev_hqswb_clas, /* o: update signal class information */ - Word16 prev_SWB_peak_pos_fx[], /* o: update core coder last coded peaks*/ - Word16 prev_SWB_peak_pos_tmp_fx[], /* o: update core coder last coded peaks*/ - Word16 *prev_frm_hfe2, /* o: update harmonics */ - Word16 *prev_stab_hfe2, /* o: update harmonics */ - Word16 bws_cnt /* i: band width detector */ + Word32 L_y2[], /* i/o: core coder buffer */ + Word32 L_t_audio[], /* o: core coder buffer */ + Word32 L_bwe_br, /* i: core bitrate */ + Word16 length_fx, /* i: frame length coded bw */ + const Word16 inner_frame_fx, /* i: i frame length */ + Word16 bands_fx, /* i: sub band resolution */ + Word16 bwidth_fx, /* i: NB/WB/SWB indicator */ + const Word16 is_transient_fx, /* i: signal class information */ + Word16 hqswb_clas_fx, /* i: signal class information */ + Word16 *prev_hqswb_clas, /* o: update signal class information */ + Word16 prev_SWB_peak_pos_fx[], /* o: update core coder last coded peaks*/ + Word16 prev_SWB_peak_pos_tmp_fx[], /* o: update core coder last coded peaks*/ + Word16 *prev_frm_hfe2, /* o: update harmonics */ + Word16 *prev_stab_hfe2, /* o: update harmonics */ + Word16 bws_cnt /* i: band width detector */ ); void convert_lagIndices_pls2smp_fx( - Word16 lagIndices_in_fx[], - Word16 nBands_search_fx, - Word16 lagIndices_out_fx[], - const Word16 sspectra_fx[], - const Word16 sbWidth_fx[], - const Word16 fLenLow_fx -); + Word16 lagIndices_in_fx[], + Word16 nBands_search_fx, + Word16 lagIndices_out_fx[], + const Word16 sspectra_fx[], + const Word16 sbWidth_fx[], + const Word16 fLenLow_fx ); void get_sigma_fx_har( - const Word32 L_x_abs[], /* i: Qi absolute i */ - const Word16 Qi, /* i: Q0 Q value of x_abs */ - const Word16 avg_fx, /* i: Qavg average of x_abs */ - const Word16 Qavg, /* i: Q0 Q value of avg */ - const Word16 length_fx, /* i: Q0 length */ - Word16 *sigma_fx, /* o: Qsigma sigma */ - Word16 *Qsigma /* o: Q0 Q value of sigma */ + const Word32 L_x_abs[], /* i: Qi absolute i */ + const Word16 Qi, /* i: Q0 Q value of x_abs */ + const Word16 avg_fx, /* i: Qavg average of x_abs */ + const Word16 Qavg, /* i: Q0 Q value of avg */ + const Word16 length_fx, /* i: Q0 length */ + Word16 *sigma_fx, /* o: Qsigma sigma */ + Word16 *Qsigma /* o: Q0 Q value of sigma */ ); void genhf_noise_fx( - const Word16 noise_flr_fx[], /* i : Qss smoothed non tonal */ /* sspectra_diff_fx:Qss */ - const Word16 Qss, /* i : Q0 Q value */ - Word32 L_xSynth_har[], /* o : QsL hf non tonal components */ /* xSynth_har:QsL */ - const Word16 QsL, /* i : Q0 Q value */ - const Word16* predBuf_fx, /* i : Qss smoothed tonal compone */ /* sspectra:Qss */ - const Word16 bands, /* i : Q0 total number of subbands in a frame */ - const Word16 harmonic_band, /* i : Q0 Number of LF harmonic frames */ - const Word16 har_freq_est2, /* i : Q0 harmonic signal parameter */ - const Word16 pos_max_hfe2, /* i : Q0 last pulse in core coder */ - Word16* pul_res, /* o : Q0 pulse resolution */ - GainItem_fx pk_sf_fx[], /* o : representative region */ - const Word16 fLenLow, /* i : Q0 low frequency length */ - const Word16 fLenHigh, /* i : Q0 high frequency length */ - const Word16 sbWidth[], /* i : Q0 bandwidth for high bands */ - const Word16 lagIndices[], /* i : Q0 correlation indices for most representative */ - const Word16 subband_offsets[], /* i : Q0 band offsets for HF reconstruction */ - const Word16 subband_search_offset[]/* i : Q0 most representative regions offsets in LF */ + const Word16 noise_flr_fx[], + /* i : Qss smoothed non tonal */ /* sspectra_diff_fx:Qss */ + const Word16 Qss, /* i : Q0 Q value */ + Word32 L_xSynth_har[], + /* o : QsL hf non tonal components */ /* xSynth_har:QsL */ + const Word16 QsL, /* i : Q0 Q value */ + const Word16 *predBuf_fx, + /* i : Qss smoothed tonal compone */ /* sspectra:Qss */ + const Word16 bands, /* i : Q0 total number of subbands in a frame */ + const Word16 harmonic_band, /* i : Q0 Number of LF harmonic frames */ + const Word16 har_freq_est2, /* i : Q0 harmonic signal parameter */ + const Word16 pos_max_hfe2, /* i : Q0 last pulse in core coder */ + Word16 *pul_res, /* o : Q0 pulse resolution */ + GainItem_fx pk_sf_fx[], /* o : representative region */ + const Word16 fLenLow, /* i : Q0 low frequency length */ + const Word16 fLenHigh, /* i : Q0 high frequency length */ + const Word16 sbWidth[], /* i : Q0 bandwidth for high bands */ + const Word16 lagIndices[], /* i : Q0 correlation indices for most representative */ + const Word16 subband_offsets[], /* i : Q0 band offsets for HF reconstruction */ + const Word16 subband_search_offset[] /* i : Q0 most representative regions offsets in LF */ ); Word16 har_est_fx( - Word32 L_spectra[], /* i : coded spectrum */ - Word16 N, /* i : length of the desired spectrum */ - Word16 *har_freq_est1, /* i/o: Estimation harmonics 1 */ - Word16 *har_freq_est2, /* o : Estimation harmonics 2 */ - Word16 *flag_dis, /* i/o: flag for BWE reconstruction */ - Word16 *prev_frm_hfe2, /* i/o: Estimated harmonic update */ - const Word16 subband_search_offset[], /* i : Subband Search range */ - const Word16 sbWidth[], /* i : Subband Search range */ - Word16 *prev_stab_hfe2 /* i/o: Estimated harmonic position */ + Word32 L_spectra[], /* i : coded spectrum */ + Word16 N, /* i : length of the desired spectrum */ + Word16 *har_freq_est1, /* i/o: Estimation harmonics 1 */ + Word16 *har_freq_est2, /* o : Estimation harmonics 2 */ + Word16 *flag_dis, /* i/o: flag for BWE reconstruction */ + Word16 *prev_frm_hfe2, /* i/o: Estimated harmonic update */ + const Word16 subband_search_offset[], /* i : Subband Search range */ + const Word16 sbWidth[], /* i : Subband Search range */ + Word16 *prev_stab_hfe2 /* i/o: Estimated harmonic position */ ); void FindNBiggest2_simple_fx_har( - const Word32 *L_inBuf, /* i : i buffer (searched) */ - const Word16 Qabs_in, /* i : Q value of i buffer */ - GainItem_fx *pk_sf_fx, /* o : N biggest components found */ - const Word16 nIdx_fx, /* i : search length */ - Word16 *n_fx, /* i : number of components searched (N biggest) */ - Word16 n_nbiggestsearch -); + const Word32 *L_inBuf, /* i : i buffer (searched) */ + const Word16 Qabs_in, /* i : Q value of i buffer */ + GainItem_fx *pk_sf_fx, /* o : N biggest components found */ + const Word16 nIdx_fx, /* i : search length */ + Word16 *n_fx, /* i : number of components searched (N biggest) */ + Word16 n_nbiggestsearch ); Word16 get_usebit_npswb_fx( - Word16 hqswb_clas_fx -); + Word16 hqswb_clas_fx ); /*========================================================================================================/ @@ -1938,31 +1891,30 @@ isf_dec_amr_wb_fx.c /========================================================================================================*/ void disf_2s_36b_fx( - Word16 *indice, /* i : quantized indices (use indice[0] = -1 in the decoder) */ - Word16 *isf_q, /* o : quantized ISFs in the cosine domain */ - Word16 *mem_AR, /* i/o: quantizer memory for AR model */ - Word16 *mem_MA, /* i/o: quantizer memory for MA model */ - const Word16 enc_dec /* i : encoder (0), decoder (1) G722.2 FER */ + Word16 *indice, /* i : quantized indices (use indice[0] = -1 in the decoder) */ + Word16 *isf_q, /* o : quantized ISFs in the cosine domain */ + Word16 *mem_AR, /* i/o: quantizer memory for AR model */ + Word16 *mem_MA, /* i/o: quantizer memory for MA model */ + const Word16 enc_dec /* i : encoder (0), decoder (1) G722.2 FER */ ); void disf_2s_46b_fx( - Word16 *indice, /* i : quantized indices (use indice[0] = -1 in the decoder) */ - Word16 *isf_q, /* o : quantized ISFs in the cosine domain */ - Word16 *mem_AR, /* o : quantizer memory for AR model */ - Word16 *mem_MA, /* i/o: quantizer memory for MA model */ - const Word16 enc_dec /* i : encoder (0), decoder (1) G722.2 FER */ + Word16 *indice, /* i : quantized indices (use indice[0] = -1 in the decoder) */ + Word16 *isf_q, /* o : quantized ISFs in the cosine domain */ + Word16 *mem_AR, /* o : quantizer memory for AR model */ + Word16 *mem_MA, /* i/o: quantizer memory for MA model */ + const Word16 enc_dec /* i : encoder (0), decoder (1) G722.2 FER */ ); void disf_ns_28b_fx( - Word16 *indice, - Word16 *isf_q -); + Word16 *indice, + Word16 *isf_q ); void isf_dec_amr_wb_fx( - Decoder_State *st, /* i/o: State structure */ - Word16 *Aq, /* o : quantized A(z) for 4 subframes */ - Word16 *isf_new, /* o : de-quantized ISF vector */ - Word16 *isp_new /* o : de-quantized ISP vector */ + Decoder_State *st, /* i/o: State structure */ + Word16 *Aq, /* o : quantized A(z) for 4 subframes */ + Word16 *isf_new, /* o : de-quantized ISF vector */ + Word16 *isp_new /* o : de-quantized ISP vector */ ); /*========================================================================================================/ @@ -1970,73 +1922,72 @@ hq2_noise_inject.c fix part /========================================================================================================*/ void hq2_noise_inject_fx( - Word32 L_y2[], - const Word16 band_start[], - const Word16 band_end[], - const Word16 band_width[], - Word32 Ep_fx[], - Word32 Rk_fx[], - const Word16 npulses[], - Word16 ni_seed, - const Word16 bands, - const Word16 ni_start_band, - const Word16 bw_low, - const Word16 bw_high, - const Word32 enerL_fx, - const Word32 enerH_fx, - Word32 last_ni_gain_fx[], - Word16 last_env_fx[], - Word16 *last_max_pos_pulse, - Word16 *p2a_flags, - Word16 p2a_bands, - const Word16 hqswb_clas, - const Word16 bwidth, - const Word32 bwe_br -); + Word32 L_y2[], + const Word16 band_start[], + const Word16 band_end[], + const Word16 band_width[], + Word32 Ep_fx[], + Word32 Rk_fx[], + const Word16 npulses[], + Word16 ni_seed, + const Word16 bands, + const Word16 ni_start_band, + const Word16 bw_low, + const Word16 bw_high, + const Word32 enerL_fx, + const Word32 enerH_fx, + Word32 last_ni_gain_fx[], + Word16 last_env_fx[], + Word16 *last_max_pos_pulse, + Word16 *p2a_flags, + Word16 p2a_bands, + const Word16 hqswb_clas, + const Word16 bwidth, + const Word32 bwe_br ); /*========================================================================================================/ hq2_bit_alloc_fx.c /========================================================================================================*/ void Bits2indvsb_fx( - const Word32 *L_be, /* i : Q14 Band Energy of sub-band */ - const Word16 start_band, /* i : Q0 start band indices */ - const Word16 end_band, /* i : Q0 end band indices */ - const Word16 Bits, /* i : Q0 Total number of bits allocated to a group */ - const Word32 L_Bits_needed, /* i : Q0 smallest bit number for allocation in group */ - Word32 *L_Rsubband, /* o : Q18 bit allocation of sub-band */ - Word16 *p2aflags_fx /* i/o: Q0 peaky/noise subband flag */ + const Word32 *L_be, /* i : Q14 Band Energy of sub-band */ + const Word16 start_band, /* i : Q0 start band indices */ + const Word16 end_band, /* i : Q0 end band indices */ + const Word16 Bits, /* i : Q0 Total number of bits allocated to a group */ + const Word32 L_Bits_needed, /* i : Q0 smallest bit number for allocation in group */ + Word32 *L_Rsubband, /* o : Q18 bit allocation of sub-band */ + Word16 *p2aflags_fx /* i/o: Q0 peaky/noise subband flag */ ); void hq2_bit_alloc_har_fx( - const Word32 *L_y, /* i : Q14 band energy of sub-vectors */ - Word16 B_fx, /* i : Q0 number of available bits */ - const Word16 N_fx, /* i : Q0 number of sub-vectors */ - Word32 *L_Rsubband, /* o : Q18 sub-band bit-allocation vector */ - Word16 p2a_bands_fx, /* i : Q0 highfreq bands */ - const Word32 L_core_brate, /* i : Q0 core bit rate */ - Word16 p2a_flags_fx[], /* i/o: Q0 p2a_flags */ - const Word16 band_width_fx[] /* i : Q0 table of band_width */ + const Word32 *L_y, /* i : Q14 band energy of sub-vectors */ + Word16 B_fx, /* i : Q0 number of available bits */ + const Word16 N_fx, /* i : Q0 number of sub-vectors */ + Word32 *L_Rsubband, /* o : Q18 sub-band bit-allocation vector */ + Word16 p2a_bands_fx, /* i : Q0 highfreq bands */ + const Word32 L_core_brate, /* i : Q0 core bit rate */ + Word16 p2a_flags_fx[], /* i/o: Q0 p2a_flags */ + const Word16 band_width_fx[] /* i : Q0 table of band_width */ ); Word32 hq2_bit_alloc_fx( - const Word32 L_band_energy[], /* i : band energy of each subband */ - const Word16 bands, /* i : total number of subbands in a frame */ - Word32 L_Rk[], /* i/o: Bit allocation/Adjusted bit alloc. */ - Word16 *bit_budget_fx, /* i/o: bit bugdet */ - Word16 *p2a_flags, /* i : HF tonal indicator */ - const Word16 weight_fx, /* i : weight */ - const Word16 band_width[], /* i : Sub band bandwidth */ - const Word16 num_bits, /* i : available bits */ - const Word16 hqswb_clas, /* i : HQ2 class information */ - const Word16 bwidth, /* i : i bandwidth */ - const Word16 is_transient /* i : indicator HQ_TRANSIENT or not */ + const Word32 L_band_energy[], /* i : band energy of each subband */ + const Word16 bands, /* i : total number of subbands in a frame */ + Word32 L_Rk[], /* i/o: Bit allocation/Adjusted bit alloc. */ + Word16 *bit_budget_fx, /* i/o: bit bugdet */ + Word16 *p2a_flags, /* i : HF tonal indicator */ + const Word16 weight_fx, /* i : weight */ + const Word16 band_width[], /* i : Sub band bandwidth */ + const Word16 num_bits, /* i : available bits */ + const Word16 hqswb_clas, /* i : HQ2 class information */ + const Word16 bwidth, /* i : i bandwidth */ + const Word16 is_transient /* i : indicator HQ_TRANSIENT or not */ ); void reordvct_fx( - Word16 *y, /* i/o: vector to rearrange */ - const Word16 N, /* i : dimensions */ - Word16 *idx /* o : reordered vector index */ + Word16 *y, /* i/o: vector to rearrange */ + const Word16 N, /* i : dimensions */ + Word16 *idx /* o : reordered vector index */ ); /*========================================================================================================/ @@ -2044,18 +1995,17 @@ nelp_fx.c /========================================================================================================*/ Word16 dequantize_uvg_fx( - const Word16 iG1, /* i: gain 1 index */ - const Word16* iG2, /* i: gain 2 index */ - Word16* G, /* o: quantized gain */ - const Word16 bandwidth, /* i: bandwidth */ - const Word16 do_scale -); + const Word16 iG1, /* i: gain 1 index */ + const Word16 *iG2, /* i: gain 2 index */ + Word16 *G, /* o: quantized gain */ + const Word16 bandwidth, /* i: bandwidth */ + const Word16 do_scale ); void generate_nelp_excitation_fx( - Word16* seed, /* i/o: random number seed */ - const Word16* Gains, /* i : excitation gains Q_exc*/ - Word16* output, /* o : excitation output */ - const Word16 gain_fac /* i : gain factor */ + Word16 *seed, /* i/o: random number seed */ + const Word16 *Gains, /* i : excitation gains Q_exc*/ + Word16 *output, /* o : excitation output */ + const Word16 gain_fac /* i : gain factor */ ); /*========================================================================================================/ @@ -2063,159 +2013,151 @@ ppp_fx.c /========================================================================================================*/ void Interpol_delay_fx( - Word16 *out_fx, - Word16 last_fx, - Word16 current_fx, - Word16 SubNum, - const Word16* frac_fx -); + Word16 *out_fx, + Word16 last_fx, + Word16 current_fx, + Word16 SubNum, + const Word16 *frac_fx ); void deemph_lpc_fx( - const Word16* p_Aq_curr_fx, /* i : LP coefficients current frame */ - const Word16* p_Aq_old_fx, /* i : LP coefficients previous frame */ - Word16* LPC_de_curr_fx, /* o : De-emphasized LP coefficients current frame in Q12 */ - Word16* LPC_de_old_fx, /* o : De-emphasized LP coefficients previous frame in Q12 */ - const Word16 deemph_old -); + const Word16 *p_Aq_curr_fx, /* i : LP coefficients current frame */ + const Word16 *p_Aq_old_fx, /* i : LP coefficients previous frame */ + Word16 *LPC_de_curr_fx, /* o : De-emphasized LP coefficients current frame in Q12 */ + Word16 *LPC_de_old_fx, /* o : De-emphasized LP coefficients previous frame in Q12 */ + const Word16 deemph_old ); /*========================================================================================================/ hq2_core_com_fx.c /========================================================================================================*/ void mdct_spectrum_denorm_fx( - const Word16 inp_vector[], /* i : Q0 : */ - Word32 L_y2[], /* i/o : Qs : decoded spectrum */ - const Word16 band_start[], /* i : Q0 : table of start freq for every subband */ - const Word16 band_end[], /* i : Q0 : table of end freq for every subband */ - const Word16 band_width[], /* i : Q0 : table of bandwidth for every subband */ - const Word32 L_band_energy[], /* i : Qbe : band energy */ - const Word16 npulses[], /* i : Q0 : number of coded spectrum */ - const Word16 bands, /* i : Q0 : numbers of subbands */ - const Word16 ld_slope_fx, /* i : Q15 : */ - const Word16 pd_thresh_fx /* i : Q15 : */ + const Word16 inp_vector[], /* i : Q0 : */ + Word32 L_y2[], /* i/o : Qs : decoded spectrum */ + const Word16 band_start[], /* i : Q0 : table of start freq for every subband */ + const Word16 band_end[], /* i : Q0 : table of end freq for every subband */ + const Word16 band_width[], /* i : Q0 : table of bandwidth for every subband */ + const Word32 L_band_energy[], /* i : Qbe : band energy */ + const Word16 npulses[], /* i : Q0 : number of coded spectrum */ + const Word16 bands, /* i : Q0 : numbers of subbands */ + const Word16 ld_slope_fx, /* i : Q15 : */ + const Word16 pd_thresh_fx /* i : Q15 : */ ); void hq2_core_configure_fx( - const Word16 frame_length, - const Word16 num_bits, - const Word16 is_transient, - Word16 *bands, - Word16 *length, - Word16 band_width[], - Word16 band_start[], - Word16 band_end[], - Word32 *L_qint, - Word16 *eref, - Word16 *bit_alloc_weight, - Word16 *gqlevs, - Word16 *Ngq, - Word16 *p2a_bands, - Word16 *p2a_th, - Word16 *pd_thresh, - Word16 *ld_slope, - Word16 *ni_coef, - Word32 L_bwe_br -); + const Word16 frame_length, + const Word16 num_bits, + const Word16 is_transient, + Word16 *bands, + Word16 *length, + Word16 band_width[], + Word16 band_start[], + Word16 band_end[], + Word32 *L_qint, + Word16 *eref, + Word16 *bit_alloc_weight, + Word16 *gqlevs, + Word16 *Ngq, + Word16 *p2a_bands, + Word16 *p2a_th, + Word16 *pd_thresh, + Word16 *ld_slope, + Word16 *ni_coef, + Word32 L_bwe_br ); void reverse_transient_frame_energies_fx( - Word32 L_band_energy[], /* o : Q14 : band energies */ - const Word16 bands /* i : Q0 : number of bands */ + Word32 L_band_energy[], /* o : Q14 : band energies */ + const Word16 bands /* i : Q0 : number of bands */ ); void spt_shorten_domain_pre_fx( - const Word16 band_start[], /* i: Starting position of sub band */ - const Word16 band_end[], /* i: End position of sub band */ - const Word16 prev_SWB_peak_pos[], /* i: Spectral peak */ - const Word16 BANDS, /* i: total number of bands */ - const Word32 L_bwe_br, /* i: bitrate information */ - Word16 new_band_start[], /* o: Starting position of new shorten sub band */ - Word16 new_band_end[], /* o: End position of new shorten sub band */ - Word16 new_band_width[] /* o: new sub band bandwidth */ + const Word16 band_start[], /* i: Starting position of sub band */ + const Word16 band_end[], /* i: End position of sub band */ + const Word16 prev_SWB_peak_pos[], /* i: Spectral peak */ + const Word16 BANDS, /* i: total number of bands */ + const Word32 L_bwe_br, /* i: bitrate information */ + Word16 new_band_start[], /* o: Starting position of new shorten sub band */ + Word16 new_band_end[], /* o: End position of new shorten sub band */ + Word16 new_band_width[] /* o: new sub band bandwidth */ ); void spt_shorten_domain_band_save_fx( - const Word16 bands, /* i: total subband */ - const Word16 band_start[], /* i: starting position of subband */ - const Word16 band_end[], /* i: end position of subband */ - const Word16 band_width[], /* i: band width of subband */ - Word16 org_band_start[], /* o: starting position of subband */ - Word16 org_band_end[], /* o: end position of subband */ - Word16 org_band_width[] /* o: band width of subband */ + const Word16 bands, /* i: total subband */ + const Word16 band_start[], /* i: starting position of subband */ + const Word16 band_end[], /* i: end position of subband */ + const Word16 band_width[], /* i: band width of subband */ + Word16 org_band_start[], /* o: starting position of subband */ + Word16 org_band_end[], /* o: end position of subband */ + Word16 org_band_width[] /* o: band width of subband */ ); void spt_shorten_domain_band_restore_fx( - const Word16 bands, /* i: total subband */ - Word16 band_start[], /* i/o: starting position of subband */ - Word16 band_end[], /* i/o: end position of subband */ - Word16 band_width[], /* i/o: band width of subband */ - const Word16 org_band_start[], /* o: starting position of subband */ - const Word16 org_band_end[], /* o: end position of subband */ - const Word16 org_band_width[] /* o: band width of subband */ + const Word16 bands, /* i: total subband */ + Word16 band_start[], /* i/o: starting position of subband */ + Word16 band_end[], /* i/o: end position of subband */ + Word16 band_width[], /* i/o: band width of subband */ + const Word16 org_band_start[], /* o: starting position of subband */ + const Word16 org_band_end[], /* o: end position of subband */ + const Word16 org_band_width[] /* o: band width of subband */ ); void spt_swb_peakpos_tmp_save_fx( - const Word32 L_y2[], /* i: coded spectral information */ - const Word16 bands, /* i: total number of bands */ - const Word16 band_start[], /* i: starting position of subband */ - const Word16 band_end[], /* i: end position of subband */ - Word16 prev_SWB_peak_pos_tmp[] /* o: spectral peaks */ + const Word32 L_y2[], /* i: coded spectral information */ + const Word16 bands, /* i: total number of bands */ + const Word16 band_start[], /* i: starting position of subband */ + const Word16 band_end[], /* i: end position of subband */ + Word16 prev_SWB_peak_pos_tmp[] /* o: spectral peaks */ ); void bit_allocation_second_fx( - Word32 *Rk, - Word32 *Rk_sort, - Word16 BANDS, - const Word16 *band_width, - Word16 *k_sort, - Word16 *k_num, - const Word16 *p2a_flags, - const Word16 p2a_bands, - const Word16 *last_bitalloc, - const Word16 input_frame -); - -//synth_filt_fix.c + Word32 *Rk, + Word32 *Rk_sort, + Word16 BANDS, + const Word16 *band_width, + Word16 *k_sort, + Word16 *k_num, + const Word16 *p2a_flags, + const Word16 p2a_bands, + const Word16 *last_bitalloc, + const Word16 input_frame ); + +// synth_filt_fix.c Word32 syn_kern_16( - Word32 L_tmp, - const Word16 a[], - const Word16 y[] -); + Word32 L_tmp, + const Word16 a[], + const Word16 y[] ); void syn_filt_s_lc_fx( - const Word16 shift, /* i : scaling to apply Q0 */ - const Word16 a[], /* i : LP filter coefficients Q12 */ - const Word16 x[], /* i : i signal Qx */ - Word16 y[], /* o : output signal Qx-s */ - const Word16 lg /* i : size of filtering Q0 */ + const Word16 shift, /* i : scaling to apply Q0 */ + const Word16 a[], /* i : LP filter coefficients Q12 */ + const Word16 x[], /* i : i signal Qx */ + Word16 y[], /* o : output signal Qx-s */ + const Word16 lg /* i : size of filtering Q0 */ ); void Syn_filt_s( - const Word16 shift, /* i : scaling to apply Q0 */ - const Word16 a[], /* i : LP filter coefficients Q12 */ - const Word16 m, /* i : order of LP filter Q0 */ - const Word16 x[], /* i : i signal Qx */ - Word16 y[], /* o : output signal Qx-s */ - const Word16 lg, /* i : size of filtering Q0 */ - Word16 mem[], /* i/o: memory associated with this filtering. Qx-s */ - const Word16 update /* i : 0=no update, 1=update of memory. Q0 */ + const Word16 shift, /* i : scaling to apply Q0 */ + const Word16 a[], /* i : LP filter coefficients Q12 */ + const Word16 m, /* i : order of LP filter Q0 */ + const Word16 x[], /* i : i signal Qx */ + Word16 y[], /* o : output signal Qx-s */ + const Word16 lg, /* i : size of filtering Q0 */ + Word16 mem[], /* i/o: memory associated with this filtering. Qx-s */ + const Word16 update /* i : 0=no update, 1=update of memory. Q0 */ ); -void E_UTIL_synthesis(const Word16 shift, const Word16 a[], const Word16 x[], Word16 y[], - const Word16 lg, Word16 mem[], const Word16 update, const Word16 m); +void E_UTIL_synthesis( const Word16 shift, const Word16 a[], const Word16 x[], Word16 y[], const Word16 lg, Word16 mem[], const Word16 update, const Word16 m ); -void E_UTIL_synthesis_fx(const Word16 shift, const Word32 a[], const Word32 x[], Word32 y[], - const Word16 lg, Word32 mem[], const Word16 update, const Word16 m -); +void E_UTIL_synthesis_fx( const Word16 shift, const Word32 a[], const Word32 x[], Word32 y[], const Word16 lg, Word32 mem[], const Word16 update, const Word16 m ); void synth_mem_updt2( - const Word16 L_frame, /* i : frame length */ - const Word16 last_L_frame, /* i : frame length */ - Word16 old_exc[], /* i/o: excitation buffer */ - Word16 mem_syn_r[], /* i/o: synthesis filter memory */ - Word16 mem_syn2[], /* o : synthesis filter memory for find_target */ - Word16 mem_syn[], /* o : synthesis filter memory for find_target */ - const Word16 dec /* i : flag for decoder indication */ + const Word16 L_frame, /* i : frame length */ + const Word16 last_L_frame, /* i : frame length */ + Word16 old_exc[], /* i/o: excitation buffer */ + Word16 mem_syn_r[], /* i/o: synthesis filter memory */ + Word16 mem_syn2[], /* o : synthesis filter memory for find_target */ + Word16 mem_syn[], /* o : synthesis filter memory for find_target */ + const Word16 dec /* i : flag for decoder indication */ ); #ifdef IVAS_FLOAT_FIXED void ivas_synth_mem_updt2_fx( @@ -2230,1040 +2172,1016 @@ void ivas_synth_mem_updt2_fx( #endif -//lerp.c -void lerp(const Word16 *f, Word16 *f_out, Word16 bufferNewSize, Word16 bufferOldSize); +// lerp.c +void lerp( const Word16 *f, Word16 *f_out, Word16 bufferNewSize, Word16 bufferOldSize ); void L_lerp_fx_q11( Word32 *f, Word32 *f_out, Word16 bufferNewSize, Word16 bufferOldSize ); void L_lerp_fx( Word32 *f, Word32 *f_out, Word16 bufferNewSize, Word16 bufferOldSize, Word16 *q ); -//index_pvq_opt.c +// index_pvq_opt.c -PvqEntry mpvq_encode_vec_fx( /* o : leading_sign_index, index, size, k_val */ - const Word16* vec_in, /* i : signed pulse train */ - Word16 dim_in, /* i : dimension */ - Word16 k_val_local /* i : nb unit pulses */ +PvqEntry mpvq_encode_vec_fx( /* o : leading_sign_index, index, size, k_val */ + const Word16 *vec_in, /* i : signed pulse train */ + Word16 dim_in, /* i : dimension */ + Word16 k_val_local /* i : nb unit pulses */ ); -PvqEntry get_size_mpvq_calc_offset_fx( /* o : size, dim, k_val */ - Word16 dim_in, /* i : dimension */ - Word16 k_val_in, /* i : nb unit pulses */ - UWord32* h_mem /* o : offsets */ +PvqEntry get_size_mpvq_calc_offset_fx( /* o : size, dim, k_val */ + Word16 dim_in, /* i : dimension */ + Word16 k_val_in, /* i : nb unit pulses */ + UWord32 *h_mem /* o : offsets */ ); -void mpvq_decode_vec_fx( /* o : void */ - const PvqEntry* entry, /* i : sign_ind, index, dim, k_val */ - UWord32* h_mem, /* i : A/U offsets */ - Word16* vec_out /* o : pulse train */ +void mpvq_decode_vec_fx( /* o : void */ + const PvqEntry *entry, /* i : sign_ind, index, dim, k_val */ + UWord32 *h_mem, /* i : A/U offsets */ + Word16 *vec_out /* o : pulse train */ ); -//weight_a_fx.c +// weight_a_fx.c void weight_a_subfr_fx( - const Word16 nb_subfr, /* i : number of subframes */ - const Word16 *A, /* i : LP filter coefficients Q12 */ - Word16 *Aw, /* o : weighted LP filter coefficients Q12 */ - const Word16 gamma, /* i : weighting factor */ - const Word16 m /* i : order of LP filter */ + const Word16 nb_subfr, /* i : number of subframes */ + const Word16 *A, /* i : LP filter coefficients Q12 */ + Word16 *Aw, /* o : weighted LP filter coefficients Q12 */ + const Word16 gamma, /* i : weighting factor */ + const Word16 m /* i : order of LP filter */ ); void weight_a_lc_fx( - const Word16 a[], /* i: LP filter coefficients Q12 */ - Word16 ap[], /* o: weighted LP filter coefficients Q12 */ - const Word16 *gammatbl, /* i: weighting factor Q15 */ - const Word16 m /* i: order of LP filter Q0 */ + const Word16 a[], /* i: LP filter coefficients Q12 */ + Word16 ap[], /* o: weighted LP filter coefficients Q12 */ + const Word16 *gammatbl, /* i: weighting factor Q15 */ + const Word16 m /* i: order of LP filter Q0 */ ); void weight_a_fx( - const Word16 a[], /* i: LP filter coefficients Q12 */ - Word16 ap[], /* o: weighted LP filter coefficients Q12 */ - const Word16 gamma, /* i: weighting factor Q15 */ - const Word16 m /* i: order of LP filter Q0 */ + const Word16 a[], /* i: LP filter coefficients Q12 */ + Word16 ap[], /* o: weighted LP filter coefficients Q12 */ + const Word16 gamma, /* i: weighting factor Q15 */ + const Word16 m /* i: order of LP filter Q0 */ ); -void E_LPC_a_weight_inv(const Word16 *a, Word16 *ap, const Word16 gamma, const Word16 m); +void E_LPC_a_weight_inv( const Word16 *a, Word16 *ap, const Word16 gamma, const Word16 m ); -//residu_fx.c +// residu_fx.c void Residu3_lc_fx( - const Word16 a[], /* i : prediction coefficients Q12 */ - const Word16 m, /* i : order of LP filter Q0 */ - const Word16 x[], /* i : input signal (usually speech) Qx */ - Word16 y[], /* o : output signal (usually residual) Qx */ - const Word16 lg, /* i : vector size Q0 */ - const Word16 shift -); + const Word16 a[], /* i : prediction coefficients Q12 */ + const Word16 m, /* i : order of LP filter Q0 */ + const Word16 x[], /* i : input signal (usually speech) Qx */ + Word16 y[], /* o : output signal (usually residual) Qx */ + const Word16 lg, /* i : vector size Q0 */ + const Word16 shift ); void Residu3_10_fx( - const Word16 a[], /* i : prediction coefficients Q12 */ - const Word16 x[], /* i : input signal (usually speech) Qx */ + const Word16 a[], /* i : prediction coefficients Q12 */ + const Word16 x[], /* i : input signal (usually speech) Qx */ /* (note that values x[-10..-1] are needed) */ - Word16 y[], /* o : output signal (usually residual) Qx */ - const Word16 lg, /* i : vector size Q0 */ - const Word16 shift -); + Word16 y[], /* o : output signal (usually residual) Qx */ + const Word16 lg, /* i : vector size Q0 */ + const Word16 shift ); void Residu3_fx( - const Word16 a[], /* i : prediction coefficients Q12 */ - const Word16 x[], /* i : input signal (usually speech) Qx */ + const Word16 a[], /* i : prediction coefficients Q12 */ + const Word16 x[], /* i : input signal (usually speech) Qx */ /* (note that values x[-M..-1] are needed) */ - Word16 y[], /* o : output signal (usually residual) Qx */ - const Word16 lg, /* i : vector size Q0 */ - const Word16 shift -); + Word16 y[], /* o : output signal (usually residual) Qx */ + const Word16 lg, /* i : vector size Q0 */ + const Word16 shift ); void calc_residu_fx( - Encoder_State *st, /* i/o: state structure */ - const Word16 *speech, /* i : weighted speech signal */ - Word16 *res, /* o : residual signal */ - const Word16 *p_Aq /* i : quantized LP filter coefficients */ + Encoder_State *st, /* i/o: state structure */ + const Word16 *speech, /* i : weighted speech signal */ + Word16 *res, /* o : residual signal */ + const Word16 *p_Aq /* i : quantized LP filter coefficients */ ); -//inerpol_lc.c -Word32 Interpol_lc_fx( /* o : interpolated value Qx+16 */ - const Word16 *x, /* i : input vector Q0 */ - const Word16 *win, /* i : interpolation window Q14 */ - const Word16 frac, /* i : fraction (0..up_samp) Q0 */ - const Word16 up_samp, /* i : upsampling factor Q0 */ - const Word16 nb_coef /* i : number of coefficients Q0 */ +// inerpol_lc.c +Word32 Interpol_lc_fx( /* o : interpolated value Qx+16 */ + const Word16 *x, /* i : input vector Q0 */ + const Word16 *win, /* i : interpolation window Q14 */ + const Word16 frac, /* i : fraction (0..up_samp) Q0 */ + const Word16 up_samp, /* i : upsampling factor Q0 */ + const Word16 nb_coef /* i : number of coefficients Q0 */ ); -//modif_fs_fx.c -Word16 modify_Fs_fx( /* o : length of output Q0 */ - const Word16 sigIn_fx[], /* i : signal to decimate Q0 */ - Word16 lg, /* i : length of input Q0 */ - const Word32 fin, /* i : frequency of input Q0 */ - Word16 sigOut_fx[], /* o : decimated signal Q0 */ - const Word32 fout, /* i : frequency of output Q0 */ - Word16 mem_fx[], /* i/o: filter memory Q0 */ - const Word16 nblp /* i : flag indicating if NB low-pass is applied */ +// modif_fs_fx.c +Word16 modify_Fs_fx( /* o : length of output Q0 */ + const Word16 sigIn_fx[], /* i : signal to decimate Q0 */ + Word16 lg, /* i : length of input Q0 */ + const Word32 fin, /* i : frequency of input Q0 */ + Word16 sigOut_fx[], /* o : decimated signal Q0 */ + const Word32 fout, /* i : frequency of output Q0 */ + Word16 mem_fx[], /* i/o: filter memory Q0 */ + const Word16 nblp /* i : flag indicating if NB low-pass is applied */ ); -Word16 modify_Fs_intcub3m_sup_fx( /* o : length of output */ - const Word16 sigIn[], /* i : signal to decimate with memory of 2 samples (indexes -2 & -1) */ - const Word16 lg, /* i : length of input (suppose that lg is such that lg_out is integer, ex multiple of 5 in case of 16kHz to 12.8 kHz) */ - const Word32 fin, /* i : frequency of input */ - Word16 sigOut[], /* o : decimated signal */ - const Word32 fout, /* i : frequency of output */ - Word16 *delayout /* o : delay of output */ +Word16 modify_Fs_intcub3m_sup_fx( /* o : length of output */ + const Word16 sigIn[], /* i : signal to decimate with memory of 2 samples (indexes -2 & -1) */ + const Word16 lg, /* i : length of input (suppose that lg is such that lg_out is integer, ex multiple of 5 in case of 16kHz to 12.8 kHz) */ + const Word32 fin, /* i : frequency of input */ + Word16 sigOut[], /* o : decimated signal */ + const Word32 fout, /* i : frequency of output */ + Word16 *delayout /* o : delay of output */ ); void Decimate_allpass_steep_fx( - const Word16 *in_fx, - Word16 mem[], /* array of size: 2*ALLPASSSECTIONS_STEEP+1 */ - Word16 N, /* number of input samples */ - Word16 out_fx[]); + const Word16 *in_fx, + Word16 mem[], /* array of size: 2*ALLPASSSECTIONS_STEEP+1 */ + Word16 N, /* number of input samples */ + Word16 out_fx[] ); void Interpolate_allpass_steep_fx( - const Word16 *in_fx, - Word16 mem[], /* array of size: 2*ALLPASSSECTIONS_STEEP+1 */ - Word16 N, /* number of input samples */ - Word16 out_fx[]); + const Word16 *in_fx, + Word16 mem[], /* array of size: 2*ALLPASSSECTIONS_STEEP+1 */ + Word16 N, /* number of input samples */ + Word16 out_fx[] ); void interpolate_3_over_2_allpass_fx( - const Word16 *input_fx, /* i : input signal */ /* Q_input */ - const Word16 len, /* i : number of input samples */ - Word16 *out_fx, /* o : output signal */ /* Q_input */ - Word16 *mem_fx, /* i/o: memory */ /* Q_input */ - const Word16 *filt_coeff_fx /* i : filter coefficients */ /* Q15*/ + const Word16 *input_fx, + /* i : input signal */ /* Q_input */ + const Word16 len, /* i : number of input samples */ + Word16 *out_fx, + /* o : output signal */ /* Q_input */ + Word16 *mem_fx, + /* i/o: memory */ /* Q_input */ + const Word16 *filt_coeff_fx /* i : filter coefficients */ /* Q15*/ ); void interpolate_3_over_1_allpass_fx( - const Word16 *input_fx, /* i : input signal */ /* Q_input */ - const Word16 len, /* i : number of input samples */ - Word16 *out_fx, /* o : output signal */ /* Q_input */ - Word16 *mem_fx /* i/o: memory */ /* Q_input */ + const Word16 *input_fx, + /* i : input signal */ /* Q_input */ + const Word16 len, /* i : number of input samples */ + Word16 *out_fx, + /* o : output signal */ /* Q_input */ + Word16 *mem_fx /* i/o: memory */ /* Q_input */ ); void decimate_2_over_3_allpass_fx( - const Word16 *input, /* i : input signal */ /* Q_input */ - const Word16 len, /* i : number of input samples */ - Word16 *out_fx, /* o : output signal */ /* Q_input */ - Word16 *mem_fx, /* i/o: memory */ /* Q_input */ - const Word16 *filt_coeff_fx, /* i : filter coefficients */ /* Q15*/ - const Word16 *lp_num_fx, /* i : Num Coefficients : Q15 */ - const Word16 *lp_den_fx, /* o : Den Coefficients : Q15 */ - Word16 *lp_mem_fx /* o : Filter memories : Q_input */ + const Word16 *input, + /* i : input signal */ /* Q_input */ + const Word16 len, /* i : number of input samples */ + Word16 *out_fx, + /* o : output signal */ /* Q_input */ + Word16 *mem_fx, + /* i/o: memory */ /* Q_input */ + const Word16 *filt_coeff_fx, + /* i : filter coefficients */ /* Q15*/ + const Word16 *lp_num_fx, /* i : Num Coefficients : Q15 */ + const Word16 *lp_den_fx, /* o : Den Coefficients : Q15 */ + Word16 *lp_mem_fx /* o : Filter memories : Q_input */ ); void retro_interp4_5_fx( - const Word16 *syn_fx, - Word16 *pst_old_syn_fx -); + const Word16 *syn_fx, + Word16 *pst_old_syn_fx ); void retro_interp5_4_fx( - Word16 *pst_old_syn_fx -); + Word16 *pst_old_syn_fx ); -//lag_wind.c +// lag_wind.c void adapt_lag_wind( - Word16 r_h[], /* in/out: autocorrelations */ - Word16 r_l[], /* in/out: autocorrelations */ - Word16 m, /* i : order of LP filter */ - const Word16 Top, /* i : open loop pitch lag */ - const Word16 Tnc, /* i : open loop pitch gain */ - Word32 sr_core /* i : sampling rate */ + Word16 r_h[], /* in/out: autocorrelations */ + Word16 r_l[], /* in/out: autocorrelations */ + Word16 m, /* i : order of LP filter */ + const Word16 Top, /* i : open loop pitch lag */ + const Word16 Tnc, /* i : open loop pitch gain */ + Word32 sr_core /* i : sampling rate */ ); void lag_wind( - Word16 r_h[], /* in/out: autocorrelations */ - Word16 r_l[], /* in/out: autocorrelations */ - Word16 m, /* i : order of LP filter */ - Word32 sr_core, /* i : sampling rate */ - Word16 strength /* i : LAGW_WEAK, LAGW_MEDIUM, or LAGW_STRONG */ + Word16 r_h[], /* in/out: autocorrelations */ + Word16 r_l[], /* in/out: autocorrelations */ + Word16 m, /* i : order of LP filter */ + Word32 sr_core, /* i : sampling rate */ + Word16 strength /* i : LAGW_WEAK, LAGW_MEDIUM, or LAGW_STRONG */ ); void lag_wind_32( - Word32 r[], /* in/out: autocorrelations */ - Word16 m, /* input : order of LP filter */ - Word32 sr_core, /* input : sampling rate */ - Word16 strength /* input : LAGW_WEAK, LAGW_MEDIUM, or LAGW_STRONG */ + Word32 r[], /* in/out: autocorrelations */ + Word16 m, /* input : order of LP filter */ + Word32 sr_core, /* input : sampling rate */ + Word16 strength /* input : LAGW_WEAK, LAGW_MEDIUM, or LAGW_STRONG */ ); -//preemp_fx.c -#define preemph_fx(signal,mu,L,mem) preemph_copy_fx((signal),(signal),(mu),(L),(mem)) +// preemp_fx.c +#define preemph_fx( signal, mu, L, mem ) preemph_copy_fx( ( signal ), ( signal ), ( mu ), ( L ), ( mem ) ) void preemph_copy_fx( - const Word16 x[], /* i : i signal Qx */ - Word16 y[], /* o : output signal Qx */ - const Word16 mu, /* i : preemphasis coefficient Q15 */ - const Word16 lg, /* i : vector size Q0 */ - Word16 *mem /* i/o: memory (x[-1]) Qx */ + const Word16 x[], /* i : i signal Qx */ + Word16 y[], /* o : output signal Qx */ + const Word16 mu, /* i : preemphasis coefficient Q15 */ + const Word16 lg, /* i : vector size Q0 */ + Word16 *mem /* i/o: memory (x[-1]) Qx */ ); -void E_UTIL_f_preemph2(Word16 shift, Word16 *signal, const Word16 mu, const Word16 lg, Word16 *mem); +void E_UTIL_f_preemph2( Word16 shift, Word16 *signal, const Word16 mu, const Word16 lg, Word16 *mem ); -Word16 E_UTIL_f_preemph3(Word16 *signal, const Word16 mu, const Word16 lg, Word16 *mem, Word16 bits); -//swb_bwe_com_fx.c +Word16 E_UTIL_f_preemph3( Word16 *signal, const Word16 mu, const Word16 lg, Word16 *mem, Word16 bits ); +// swb_bwe_com_fx.c Word16 WB_BWE_gain_pred_fx( - Word16 *WB_fenv, /* o : WB frequency envelopes */ - const Word16 *core_dec_freq, /* i : Frequency domain core decoded signal */ - const Word16 coder_type, /* i : coding type */ - Word16 prev_coder_type, /* i : coding type of last frame */ - Word16 prev_WB_fenv, /* i : envelope for last frame */ - Word16 *voice_factors, /* i : voicing factors Q15 */ - const Word16 pitch_buf[], /* i : pitch buffer Q6 */ - Word32 last_core_brate, /* i : previous frame core bitrate */ - Word16 last_wb_bwe_ener, /* i : previous frame wb bwe signal energy */ - Word16 Q_syn - , Word16 last_extl_fx, - Word16 tilt_wb_fx -); + Word16 *WB_fenv, /* o : WB frequency envelopes */ + const Word16 *core_dec_freq, /* i : Frequency domain core decoded signal */ + const Word16 coder_type, /* i : coding type */ + Word16 prev_coder_type, /* i : coding type of last frame */ + Word16 prev_WB_fenv, /* i : envelope for last frame */ + Word16 *voice_factors, /* i : voicing factors Q15 */ + const Word16 pitch_buf[], /* i : pitch buffer Q6 */ + Word32 last_core_brate, /* i : previous frame core bitrate */ + Word16 last_wb_bwe_ener, /* i : previous frame wb bwe signal energy */ + Word16 Q_syn, + Word16 last_extl_fx, + Word16 tilt_wb_fx ); void calc_normal_length_fx( - const Word16 core, /* i : core */ - const Word16 *sp, /* i : i signal */ - const Word16 mode, /* i : i mode */ - const Word16 extl, /* i : extension layer */ - Word16 *L_swb_norm, /* o : normalize length */ - Word16 *prev_L_swb_norm, /*i/o : last normalize length */ - Word16 Q_syn -); + const Word16 core, /* i : core */ + const Word16 *sp, /* i : i signal */ + const Word16 mode, /* i : i mode */ + const Word16 extl, /* i : extension layer */ + Word16 *L_swb_norm, /* o : normalize length */ + Word16 *prev_L_swb_norm, /*i/o : last normalize length */ + Word16 Q_syn ); -Word16 ivas_calc_tilt_bwe_fx( /* o : Tilt in Q24 */ - const Word32 *sp, /* i : i signal */ - const Word16 exp_sp, /* i : Exp of inp signal */ - const Word16 N /* i : signal length */ +Word16 ivas_calc_tilt_bwe_fx( /* o : Tilt in Q24 */ + const Word32 *sp, /* i : i signal */ + const Word16 exp_sp, /* i : Exp of inp signal */ + const Word16 N /* i : signal length */ ); void calc_norm_envelop_fx( - const Word16 SWB_signal[], /* i : SWB spectrum Q_syn*/ - Word32 *envelope, /* o : normalized envelope Q_syn*/ - const Word16 L_swb_norm, /* i : length of envelope Q0 */ - const Word16 SWB_flength, /* i : Length of i /output */ - const Word16 st_offset /* i : offset */ + const Word16 SWB_signal[], /* i : SWB spectrum Q_syn*/ + Word32 *envelope, /* o : normalized envelope Q_syn*/ + const Word16 L_swb_norm, /* i : length of envelope Q0 */ + const Word16 SWB_flength, /* i : Length of i /output */ + const Word16 st_offset /* i : offset */ ); void WB_BWE_decoding_fx( - const Word16 *core_dec_freq, /* i : Frequency domain core decoded signal */ - Word16 *WB_fenv, /* i : WB frequency envelopes */ - Word32 *WB_signal32, /* o : WB signal in MDCT domain */ - const Word16 WB_flength, /* i : Length of i /output */ - const Word16 mode, /* i : classification for WB signal */ - const Word16 last_extl, /* i : extl. layer for last frame */ - Word32 *prev_Energy, /* i/o: energy for last frame */ - Word16 *prev_WB_fenv, /* i/o: envelope for last frame */ - Word16 *prev_L_wb_norm, /* i/o: length for last frame wb norm */ - const Word16 extl, /* i : extension layer */ - const Word16 coder_type, /* i : coding type */ - const Word32 total_brate, /* i : core layer bitrate */ - Word16 *Seed, /* i/o: random generator seed */ - Word16 *prev_flag, /* i/o: attenu flag of last frame */ - Word16 prev_coder_type, /* i : coding type of last frame */ - Word16 Q_syn, - Word16 *Q_syn_hb /*o : Q value of WB_signal_32 */ + const Word16 *core_dec_freq, /* i : Frequency domain core decoded signal */ + Word16 *WB_fenv, /* i : WB frequency envelopes */ + Word32 *WB_signal32, /* o : WB signal in MDCT domain */ + const Word16 WB_flength, /* i : Length of i /output */ + const Word16 mode, /* i : classification for WB signal */ + const Word16 last_extl, /* i : extl. layer for last frame */ + Word32 *prev_Energy, /* i/o: energy for last frame */ + Word16 *prev_WB_fenv, /* i/o: envelope for last frame */ + Word16 *prev_L_wb_norm, /* i/o: length for last frame wb norm */ + const Word16 extl, /* i : extension layer */ + const Word16 coder_type, /* i : coding type */ + const Word32 total_brate, /* i : core layer bitrate */ + Word16 *Seed, /* i/o: random generator seed */ + Word16 *prev_flag, /* i/o: attenu flag of last frame */ + Word16 prev_coder_type, /* i : coding type of last frame */ + Word16 Q_syn, + Word16 *Q_syn_hb /*o : Q value of WB_signal_32 */ ); void SWB_BWE_decoding_fx( - const Word16 *core_dec_freq, /* i : Frequency domain core decoded signal */ - Word16 *SWB_fenv, /* i/o: SWB frequency envelopes */ - Word32 *SWB_signal, /* o : SWB signal in MDCT domain */ - const Word16 SWB_flength, /* i : Length of i /output */ - const Word16 mode, /* i : classification for SWB signal */ - Word16 *frica_flag, /* o : fricative signal flag */ - Word16 *prev_Energy, /* i/o: energy for last frame */ - Word16 *prev_SWB_fenv, /* i/o: envelope for last frame */ - Word16 *prev_L_swb_norm, /* i/o: length for last frame wb norm */ - const Word16 tilt_nb, /* i : tilt of synthesis wb signal */ - Word16 *Seed, /* i/o: random generator seed */ - const Word16 st_offset, /* i : offset value due to different core */ - Word16 *prev_weight, /* i/o: excitation weight value of last frame */ - const Word16 extl, /* i : extension layer */ - Word16 Q_syn - , const Word16 last_extl, /* i : extension layer of last frame */ - Word16 element_mode /* i : element mode */ + const Word16 *core_dec_freq, /* i : Frequency domain core decoded signal */ + Word16 *SWB_fenv, /* i/o: SWB frequency envelopes */ + Word32 *SWB_signal, /* o : SWB signal in MDCT domain */ + const Word16 SWB_flength, /* i : Length of i /output */ + const Word16 mode, /* i : classification for SWB signal */ + Word16 *frica_flag, /* o : fricative signal flag */ + Word16 *prev_Energy, /* i/o: energy for last frame */ + Word16 *prev_SWB_fenv, /* i/o: envelope for last frame */ + Word16 *prev_L_swb_norm, /* i/o: length for last frame wb norm */ + const Word16 tilt_nb, /* i : tilt of synthesis wb signal */ + Word16 *Seed, /* i/o: random generator seed */ + const Word16 st_offset, /* i : offset value due to different core */ + Word16 *prev_weight, /* i/o: excitation weight value of last frame */ + const Word16 extl, /* i : extension layer */ + Word16 Q_syn, + const Word16 last_extl, /* i : extension layer of last frame */ + Word16 element_mode /* i : element mode */ ); void time_envelop_shaping_fx( - Word16 werr[], /* i/o: SHB synthesis Q_synth*/ - Word32 SWB_tenv[], /* i/o: frequency envelope Q15*/ - const Word16 L, /* i : frame length */ - Word16 *Q_synth -); + Word16 werr[], /* i/o: SHB synthesis Q_synth*/ + Word32 SWB_tenv[], /* i/o: frequency envelope Q15*/ + const Word16 L, /* i : frame length */ + Word16 *Q_synth ); void time_reduce_pre_echo_fx( - const Word16 *synth, /* i : ACELP core synthesis Q_syn*/ - Word16 *error, /* i/o: SHB BWE synthesis Q0*/ - Word16 prev_td_energy, /* o : last td energy Q0*/ - const Word16 L, /* i : subframe length */ - Word16 Q_syn, - Word16 Q_synth -); + const Word16 *synth, /* i : ACELP core synthesis Q_syn*/ + Word16 *error, /* i/o: SHB BWE synthesis Q0*/ + Word16 prev_td_energy, /* o : last td energy Q0*/ + const Word16 L, /* i : subframe length */ + Word16 Q_syn, + Word16 Q_synth ); void calc_normal_length_fx_32( - const Word16 core, /* i : core : Q0 */ - const Word32 *sp, /* i : i signal : Q12 */ - const Word16 mode, /* i : i mode : Q0 */ - const Word16 extl, /* i : extension layer : Q0 */ - Word16 *L_swb_norm, /* o : normalize length : Q0 */ - Word16 *prev_L_swb_norm /*i/o : last normalize length : Q0 */ + const Word16 core, /* i : core : Q0 */ + const Word32 *sp, /* i : i signal : Q12 */ + const Word16 mode, /* i : i mode : Q0 */ + const Word16 extl, /* i : extension layer : Q0 */ + Word16 *L_swb_norm, /* o : normalize length : Q0 */ + Word16 *prev_L_swb_norm /*i/o : last normalize length : Q0 */ ); void calc_norm_envelop_fx_32( - const Word32 SWB_signal_fx[], /* i : SWB spectrum : Q12 */ - Word32 *envelope_fx, /* o : normalized envelope : Q16 */ - const Word16 L_swb_norm, /* i : length of envelope : Q0 */ - const Word16 SWB_flength, /* i : Length of i /output : Q0 */ - const Word16 st_offset /* i : offset : Q0 */ + const Word32 SWB_signal_fx[], /* i : SWB spectrum : Q12 */ + Word32 *envelope_fx, /* o : normalized envelope : Q16 */ + const Word16 L_swb_norm, /* i : length of envelope : Q0 */ + const Word16 SWB_flength, /* i : Length of i /output : Q0 */ + const Word16 st_offset /* i : offset : Q0 */ ); void hq_generic_decoding_fx( - const Word16 HQ_mode, /* i : HQ mode */ - Word32 *coeff_out1_fx, /* i/o: BWE i & temporary buffer */ - const Word16 *hq_generic_fenv_fx, /* i : SWB frequency envelopes */ - Word32 *coeff_out_fx, /* o : SWB signal in MDCT domain */ - const Word16 hq_generic_offset, /* i : frequency offset for representing hq generic*/ - Word16 *prev_L_swb_norm, /* i/o: last normalize length */ - const Word16 hq_generic_exc_clas, /* i : bwe excitation class */ - const Word16 *R -); + const Word16 HQ_mode, /* i : HQ mode */ + Word32 *coeff_out1_fx, /* i/o: BWE i & temporary buffer */ + const Word16 *hq_generic_fenv_fx, /* i : SWB frequency envelopes */ + Word32 *coeff_out_fx, /* o : SWB signal in MDCT domain */ + const Word16 hq_generic_offset, /* i : frequency offset for representing hq generic*/ + Word16 *prev_L_swb_norm, /* i/o: last normalize length */ + const Word16 hq_generic_exc_clas, /* i : bwe excitation class */ + const Word16 *R ); void save_old_syn_fx( - const Word16 L_frame, /* i : frame length */ - const Word16 syn[], /* i : ACELP synthesis */ - Word16 old_syn[], /* o : old synthesis buffer */ - Word16 old_syn_mem[], /* i/o: old synthesis buffer memory */ - const Word16 preemph_fac, /* i : preemphasis factor */ - Word16 *mem_deemph /* i/o: deemphasis filter memory */ + const Word16 L_frame, /* i : frame length */ + const Word16 syn[], /* i : ACELP synthesis */ + Word16 old_syn[], /* o : old synthesis buffer */ + Word16 old_syn_mem[], /* i/o: old synthesis buffer memory */ + const Word16 preemph_fac, /* i : preemphasis factor */ + Word16 *mem_deemph /* i/o: deemphasis filter memory */ ); -//swb_tbe_com_fx.c +// swb_tbe_com_fx.c void swb_tbe_reset_fx( - Word32 mem_csfilt[], - Word16 mem_genSHBexc_filt_down_shb[], - Word16 state_lpc_syn[], - Word16 syn_overlap[], - Word16 state_syn_shbexc[], - Word16 *tbe_demph, - Word16 *tbe_premph, - Word16 mem_stp_swb[], - Word16 *gain_prec_swb -); + Word32 mem_csfilt[], + Word16 mem_genSHBexc_filt_down_shb[], + Word16 state_lpc_syn[], + Word16 syn_overlap[], + Word16 state_syn_shbexc[], + Word16 *tbe_demph, + Word16 *tbe_premph, + Word16 mem_stp_swb[], + Word16 *gain_prec_swb ); void swb_tbe_reset_synth_fx( - Word32 genSHBsynth_Hilbert_Mem[], - Word16 genSHBsynth_state_lsyn_filt_shb_local_fx[] -); + Word32 genSHBsynth_Hilbert_Mem[], + Word16 genSHBsynth_state_lsyn_filt_shb_local_fx[] ); void fb_tbe_reset_synth_fx( - Word32 fbbwe_hpf_mem_fx[][4], - Word16 fbbwe_hpf_mem_fx_Q[], - Word16 *prev_fbbwe_ratio_fx -); + Word32 fbbwe_hpf_mem_fx[][4], + Word16 fbbwe_hpf_mem_fx_Q[], + Word16 *prev_fbbwe_ratio_fx ); Word16 tbe_celp_exc_offset( - const Word16 T0_fx, /* i : Integer pitch */ - const Word16 T0_frac_fx, /* i : Fractional part of the pitch */ - const Word16 L_frame /* i : frame lenght */ + const Word16 T0_fx, /* i : Integer pitch */ + const Word16 T0_frac_fx, /* i : Fractional part of the pitch */ + const Word16 L_frame /* i : frame lenght */ ); void tbe_celp_exc( - const Word16 L_frame_fx, /* i : Frame lenght */ - const Word16 i_subfr_fx, /* i : sub frame */ - const Word16 T0_fx, /* i : Integer pitch */ - const Word16 T0_frac_fx, /* i : Fractional part of the pitch */ - Word16 *error_fx, /* i/o: Error */ - Word16 *bwe_exc_fx /* i/o: bandwitdh extension signal */ + const Word16 L_frame_fx, /* i : Frame lenght */ + const Word16 i_subfr_fx, /* i : sub frame */ + const Word16 T0_fx, /* i : Integer pitch */ + const Word16 T0_frac_fx, /* i : Fractional part of the pitch */ + Word16 *error_fx, /* i/o: Error */ + Word16 *bwe_exc_fx /* i/o: bandwitdh extension signal */ ); void tbe_celp_exc_ivas( const int16_t element_mode, /* i : element mode */ const int16_t idchan, /* i : channel ID */ - const Word16 L_frame_fx, /* i : Frame lenght */ + const Word16 L_frame_fx, /* i : Frame lenght */ const int16_t L_subfr, /* i : subframe length */ - const Word16 i_subfr_fx, /* i : sub frame */ - const Word16 T0_fx, /* i : Integer pitch */ - const Word16 T0_frac_fx, /* i : Fractional part of the pitch */ + const Word16 i_subfr_fx, /* i : sub frame */ + const Word16 T0_fx, /* i : Integer pitch */ + const Word16 T0_frac_fx, /* i : Fractional part of the pitch */ Word16 *error_fx, /* i/o: Error */ - Word16 *bwe_exc_fx, /* i/o: bandwitdh extension signal */ + Word16 *bwe_exc_fx, /* i/o: bandwitdh extension signal */ const int16_t tdm_LRTD_flag /* i : LRTD stereo mode flag */ ); void flip_and_downmix_generic_fx( - Word16 i[], /* i : i spectrum */ - Word16 output[], /* o : output spectrum */ - const Word16 length, /* i : length of spectra */ - Word32 mem1_ext[HILBERT_ORDER1], /* i/o: Hilbert filter memory */ - Word32 mem2_ext[2 * HILBERT_ORDER2], /* i/o: memory */ - Word32 mem3_ext[2 * HILBERT_ORDER2], /* i/o: memory */ - Word16 *phase_state /* i/o: Phase state in case frequency isn't multiple of 50 Hz */ + Word16 i[], /* i : i spectrum */ + Word16 output[], /* o : output spectrum */ + const Word16 length, /* i : length of spectra */ + Word32 mem1_ext[HILBERT_ORDER1], /* i/o: Hilbert filter memory */ + Word32 mem2_ext[2 * HILBERT_ORDER2], /* i/o: memory */ + Word32 mem3_ext[2 * HILBERT_ORDER2], /* i/o: memory */ + Word16 *phase_state /* i/o: Phase state in case frequency isn't multiple of 50 Hz */ ); void Calc_rc0_h( - Word16 * h, /* i : impulse response of composed filter */ - Word16 * rc0 /* o : 1st parcor */ + Word16 *h, /* i : impulse response of composed filter */ + Word16 *rc0 /* o : 1st parcor */ ); void PostShortTerm_fx( - Word16 *sig_in, /* i : i signal (pointer to current subframe */ - Word16 *lpccoeff, /* i : LPC coefficients for current subframe */ - Word16 *sig_out, /* o : postfiltered output */ - Word16 *mem_stp, /* i/o: postfilter memory*/ - Word16 *ptr_mem_stp, /* i/o: pointer to postfilter memory*/ - Word16 *ptr_gain_prec, /* i/o: for gain adjustment*/ - Word16 *mem_zero, /* i/o: null memory to compute h_st*/ - const Word16 formant_fac_fx /* i : Strength of post-filter*/ + Word16 *sig_in, /* i : i signal (pointer to current subframe */ + Word16 *lpccoeff, /* i : LPC coefficients for current subframe */ + Word16 *sig_out, /* o : postfiltered output */ + Word16 *mem_stp, /* i/o: postfilter memory*/ + Word16 *ptr_mem_stp, /* i/o: pointer to postfilter memory*/ + Word16 *ptr_gain_prec, /* i/o: for gain adjustment*/ + Word16 *mem_zero, /* i/o: null memory to compute h_st*/ + const Word16 formant_fac_fx /* i : Strength of post-filter*/ ); void flip_spectrum_and_decimby4_fx( - const Word16 i[], /* i : i spectrum */ - Word16 output[], /* o : output spectrum */ - const Word16 length, /* i : vector length */ - Word16 mem1[], /* i/o : memory */ - Word16 mem2[], /* i/o : memory */ - const Word16 ramp_flag /* i : flag to trigger slow ramp-up of output following change of core */ + const Word16 i[], /* i : i spectrum */ + Word16 output[], /* o : output spectrum */ + const Word16 length, /* i : vector length */ + Word16 mem1[], /* i/o : memory */ + Word16 mem2[], /* i/o : memory */ + const Word16 ramp_flag /* i : flag to trigger slow ramp-up of output following change of core */ ); void GenShapedWBExcitation_fx( - Word16 *excSHB, /* o : synthesized shaped shb exctiation */ - const Word16 *lpc_shb, /* i : lpc coefficients */ - Word16 *exc4kWhtnd, /* o : whitened synthesized shb excitation */ - Word32 *mem_csfilt, /* i/o : memory */ - Word16 *mem_genSHBexc_filt_down1, /* i/o : memory */ - Word16 *mem_genSHBexc_filt_down2, /* i/o : memory */ - Word16 *mem_genSHBexc_filt_down3, /* i/o : memory */ - Word16 *state_lpc_syn, /* i/o : memory */ - const Word16 coder_type, /* i : coding type */ - const Word16 *bwe_exc_extended, /* i : bandwidth extended exciatation */ - const Word16 Q_bwe_exc, - Word16 bwe_seed[], /* i/o : random number generator seed */ - const Word16 voice_factors[], /* i : voicing factor */ - const Word16 signal_type - , const Word16 igf_flag -); + Word16 *excSHB, /* o : synthesized shaped shb exctiation */ + const Word16 *lpc_shb, /* i : lpc coefficients */ + Word16 *exc4kWhtnd, /* o : whitened synthesized shb excitation */ + Word32 *mem_csfilt, /* i/o : memory */ + Word16 *mem_genSHBexc_filt_down1, /* i/o : memory */ + Word16 *mem_genSHBexc_filt_down2, /* i/o : memory */ + Word16 *mem_genSHBexc_filt_down3, /* i/o : memory */ + Word16 *state_lpc_syn, /* i/o : memory */ + const Word16 coder_type, /* i : coding type */ + const Word16 *bwe_exc_extended, /* i : bandwidth extended exciatation */ + const Word16 Q_bwe_exc, + Word16 bwe_seed[], /* i/o : random number generator seed */ + const Word16 voice_factors[], /* i : voicing factor */ + const Word16 signal_type, + const Word16 igf_flag ); void GenWBSynth_fx( - const Word16 *input_synspeech, /* i : i synthesized speech */ - Word16 *shb_syn_speech_16k, /* o : output highband compnent */ - Word16 *state_lsyn_filt_shb1, /* i/o: memory */ - Word16 *state_lsyn_filt_shb2 /* i/o: memory */ + const Word16 *input_synspeech, /* i : i synthesized speech */ + Word16 *shb_syn_speech_16k, /* o : output highband compnent */ + Word16 *state_lsyn_filt_shb1, /* i/o: memory */ + Word16 *state_lsyn_filt_shb2 /* i/o: memory */ ); void GenShapedSHBExcitation_fx( - Word16* excSHB, /* o : synthesized shaped shb excitation Q_bwe_exc*/ - const Word16* lpc_shb, /* i : lpc coefficients Q12*/ - Word16* White_exc16k_FB, /* o : white excitation for the Fullband extension Q_bwe_exc */ - Word32* mem_csfilt, /* i/o: memory */ - Word16* mem_genSHBexc_filt_down_shb, /* i/o: memory */ - Word16* state_lpc_syn, /* i/o: memory */ - const Word16 coder_type, /* i : coding type */ - const Word16* bwe_exc_extended, /* i : bandwidth extended excitation */ - Word16 bwe_seed[], /* i/o: random number generator seed */ - Word16 voice_factors[], /* i : voicing factor*/ - const Word16 extl, /* i : extension layer */ - Word16* tbe_demph, /* i/o: de-emphasis memory */ - Word16* tbe_premph, /* i/o: pre-emphasis memory */ - Word16* lpc_shb_sf, /* i: LP coefficients */ - const Word32 shb_ener_sf_32, /* i: i shb ener, Q31 */ - Word16* shb_res_gshape, /* i: i res gain shape, Q14 */ - Word16* shb_res, - Word16* vf_ind, - const Word16 formant_fac, /* i : Formant sharpening factor [0..1] */ - Word16 fb_state_lpc_syn[], /* i/o: memory */ - Word16* fb_tbe_demph, /* i/o: fb de-emphasis memory */ - Word16* Q_bwe_exc, - Word16* Q_bwe_exc_fb, - const Word16 Q_shb, - Word16 n_mem2, /* i : n_mem2 scale factor to adjust 24.4/32kbps memories */ - Word16 prev_Q_bwe_syn, /* i : st_fx->prev_Q_bwe_syn */ - const Word32 bitrate, - const Word16 prev_bfi + Word16 *excSHB, /* o : synthesized shaped shb excitation Q_bwe_exc*/ + const Word16 *lpc_shb, /* i : lpc coefficients Q12*/ + Word16 *White_exc16k_FB, /* o : white excitation for the Fullband extension Q_bwe_exc */ + Word32 *mem_csfilt, /* i/o: memory */ + Word16 *mem_genSHBexc_filt_down_shb, /* i/o: memory */ + Word16 *state_lpc_syn, /* i/o: memory */ + const Word16 coder_type, /* i : coding type */ + const Word16 *bwe_exc_extended, /* i : bandwidth extended excitation */ + Word16 bwe_seed[], /* i/o: random number generator seed */ + Word16 voice_factors[], /* i : voicing factor*/ + const Word16 extl, /* i : extension layer */ + Word16 *tbe_demph, /* i/o: de-emphasis memory */ + Word16 *tbe_premph, /* i/o: pre-emphasis memory */ + Word16 *lpc_shb_sf, /* i: LP coefficients */ + const Word32 shb_ener_sf_32, /* i: i shb ener, Q31 */ + Word16 *shb_res_gshape, /* i: i res gain shape, Q14 */ + Word16 *shb_res, + Word16 *vf_ind, + const Word16 formant_fac, /* i : Formant sharpening factor [0..1] */ + Word16 fb_state_lpc_syn[], /* i/o: memory */ + Word16 *fb_tbe_demph, /* i/o: fb de-emphasis memory */ + Word16 *Q_bwe_exc, + Word16 *Q_bwe_exc_fb, + const Word16 Q_shb, + Word16 n_mem2, /* i : n_mem2 scale factor to adjust 24.4/32kbps memories */ + Word16 prev_Q_bwe_syn, /* i : st_fx->prev_Q_bwe_syn */ + const Word32 bitrate, + const Word16 prev_bfi #ifdef ADD_IVAS_TBE_CODE - , /* i : previous frame was concealed */ - const Word16 element_mode, /* i : element mode */ - const Word16 flag_ACELP16k, /* i : ACELP@16kHz flag */ - Word16* nlExc16k, /* i/o: NL exc for IC-BWE */ - Word16* mixExc16k, /* i/o: exc spreading for IC-BWE */ - const Word32 extl_brate, /* i : extension layer bitarte */ - const Word16 MSFlag, /* i : Multi Source flag */ - Word16 EnvSHBres_4k[], /* i/o: TD envelope of the SHB residual signal */ - Word16* prev_pow_exc16kWhtnd, /* i/o: power of the LB excitation signal in the previous frame */ - Word16* prev_mix_factor, /* i/o: mixing factor in the previous frame */ - Word16* Env_error, /* o : error in SHB residual envelope modelling*/ - Word16 Env_error_part[] /* o : per-segment error in SHB residual envelope modelling */ + , /* i : previous frame was concealed */ + const Word16 element_mode, /* i : element mode */ + const Word16 flag_ACELP16k, /* i : ACELP@16kHz flag */ + Word16 *nlExc16k, /* i/o: NL exc for IC-BWE */ + Word16 *mixExc16k, /* i/o: exc spreading for IC-BWE */ + const Word32 extl_brate, /* i : extension layer bitarte */ + const Word16 MSFlag, /* i : Multi Source flag */ + Word16 EnvSHBres_4k[], /* i/o: TD envelope of the SHB residual signal */ + Word16 *prev_pow_exc16kWhtnd, /* i/o: power of the LB excitation signal in the previous frame */ + Word16 *prev_mix_factor, /* i/o: mixing factor in the previous frame */ + Word16 *Env_error, /* o : error in SHB residual envelope modelling*/ + Word16 Env_error_part[] /* o : per-segment error in SHB residual envelope modelling */ #endif ); void GenShapedSHBExcitation_ivas_fx( - Word16 *excSHB, /* o : synthesized shaped shb excitation Q_bwe_exc*/ - const Word16 *lpc_shb, /* i : lpc coefficients Q12*/ - Word16 *White_exc16k_FB, /* o : white excitation for the Fullband extension Q_bwe_exc */ - Word32 *mem_csfilt, /* i/o: memory */ - Word16 *mem_genSHBexc_filt_down_shb, /* i/o: memory */ - Word16 *state_lpc_syn, /* i/o: memory */ - const Word16 coder_type, /* i : coding type */ - const Word16 *bwe_exc_extended, /* i : bwidth extended excitation */ - Word16 bwe_seed[], /* i/o: random number generator seed */ - Word16 voice_factors[], /* i : voicing factor*/ - const Word16 extl, /* i : extension layer */ - Word16 *tbe_demph, /* i/o: de-emphasis memory */ - Word16 *tbe_premph, /* i/o: pre-emphasis memory */ - Word16 *lpc_shb_sf, /* i: LP coefficients */ - const Word32 shb_ener_sf_32, /* i: input shb ener, Q31 */ - Word16 *shb_res_gshape, /* i: input res gain shape, Q14 */ + Word16 *excSHB, /* o : synthesized shaped shb excitation Q_bwe_exc*/ + const Word16 *lpc_shb, /* i : lpc coefficients Q12*/ + Word16 *White_exc16k_FB, /* o : white excitation for the Fullband extension Q_bwe_exc */ + Word32 *mem_csfilt, /* i/o: memory */ + Word16 *mem_genSHBexc_filt_down_shb, /* i/o: memory */ + Word16 *state_lpc_syn, /* i/o: memory */ + const Word16 coder_type, /* i : coding type */ + const Word16 *bwe_exc_extended, /* i : bwidth extended excitation */ + Word16 bwe_seed[], /* i/o: random number generator seed */ + Word16 voice_factors[], /* i : voicing factor*/ + const Word16 extl, /* i : extension layer */ + Word16 *tbe_demph, /* i/o: de-emphasis memory */ + Word16 *tbe_premph, /* i/o: pre-emphasis memory */ + Word16 *lpc_shb_sf, /* i: LP coefficients */ + const Word32 shb_ener_sf_32, /* i: input shb ener, Q31 */ + Word16 *shb_res_gshape, /* i: input res gain shape, Q14 */ Word16 *shb_res, Word16 *vf_ind, - const Word16 formant_fac, /* i : Formant sharpening factor [0..1] */ - Word16 fb_state_lpc_syn[], /* i/o: memory */ - Word16 *fb_tbe_demph, /* i/o: fb de-emphasis memory */ + const Word16 formant_fac, /* i : Formant sharpening factor [0..1] */ + Word16 fb_state_lpc_syn[], /* i/o: memory */ + Word16 *fb_tbe_demph, /* i/o: fb de-emphasis memory */ Word16 *Q_bwe_exc, Word16 *Q_bwe_exc_fb, const Word16 Q_shb, - Word16 n_mem2, /* i : n_mem2 scale factor to adjust 24.4/32kbps memories */ - Word16 prev_Q_bwe_syn, /* i : st_fx->prev_Q_bwe_syn */ + Word16 n_mem2, /* i : n_mem2 scale factor to adjust 24.4/32kbps memories */ + Word16 prev_Q_bwe_syn, /* i : st_fx->prev_Q_bwe_syn */ const Word32 bitrate, const Word16 prev_bfi -#if 1//def ADD_IVAS_TBE_CODE - , /* i : previous frame was concealed */ - const Word16 element_mode, /* i : element mode */ - const Word16 flag_ACELP16k, /* i : ACELP@16kHz flag */ - Word16* nlExc16k, /* i/o: NL exc for IC-BWE */ - Word16* mixExc16k, /* i/o: exc spreading for IC-BWE */ - const Word32 extl_brate, /* i : extension layer bitarte */ - const Word16 MSFlag, /* i : Multi Source flag */ - Word16 EnvSHBres_4k[], /* i/o: TD envelope of the SHB residual signal */ - Word32* prev_pow_exc16kWhtnd, /* i/o: power of the LB excitation signal in the previous frame */ - Word16* prev_mix_factor, /* i/o: mixing factor in the previous frame */ - Word16* Env_error, /* o : error in SHB residual envelope modelling*/ - Word16 Env_error_part[] /* o : per-segment error in SHB residual envelope modelling */ +#if 1 // def ADD_IVAS_TBE_CODE + , /* i : previous frame was concealed */ + const Word16 element_mode, /* i : element mode */ + const Word16 flag_ACELP16k, /* i : ACELP@16kHz flag */ + Word16 *nlExc16k, /* i/o: NL exc for IC-BWE */ + Word16 *mixExc16k, /* i/o: exc spreading for IC-BWE */ + const Word32 extl_brate, /* i : extension layer bitarte */ + const Word16 MSFlag, /* i : Multi Source flag */ + Word16 EnvSHBres_4k[], /* i/o: TD envelope of the SHB residual signal */ + Word32 *prev_pow_exc16kWhtnd, /* i/o: power of the LB excitation signal in the previous frame */ + Word16 *prev_mix_factor, /* i/o: mixing factor in the previous frame */ + Word16 *Env_error, /* o : error in SHB residual envelope modelling*/ + Word16 Env_error_part[] /* o : per-segment error in SHB residual envelope modelling */ #endif ); void GenSHBSynth_fx( - const Word16 *shb_target_speech, /* i : i synthesized speech */ - Word16 *shb_syn_speech_32k, /* o : output highband component */ - Word32 Hilbert_Mem[], /* i/o: memory */ - Word16 genSHBsynth_allpass_mem[], /* i/o: memory */ - const Word16 L_frame, /* i : ACELP Frame length */ - Word16 *syn_dm_phase -); + const Word16 *shb_target_speech, /* i : i synthesized speech */ + Word16 *shb_syn_speech_32k, /* o : output highband component */ + Word32 Hilbert_Mem[], /* i/o: memory */ + Word16 genSHBsynth_allpass_mem[], /* i/o: memory */ + const Word16 L_frame, /* i : ACELP Frame length */ + Word16 *syn_dm_phase ); void GenSHBSynth_fx_32( - const Word32 *input_synspeech, /* i : input synthesized speech */ - Word32 *shb_syn_speech_32k, /* o : output highband component */ - Word32 Hilbert_Mem[], /* i/o: memory */ - Word32 state_lsyn_filt_shb_local[], /* i/o: memory */ - const int16_t L_frame, /* i : ACELP frame length */ - int16_t *syn_dm_phase); + const Word32 *input_synspeech, /* i : input synthesized speech */ + Word32 *shb_syn_speech_32k, /* o : output highband component */ + Word32 Hilbert_Mem[], /* i/o: memory */ + Word32 state_lsyn_filt_shb_local[], /* i/o: memory */ + const int16_t L_frame, /* i : ACELP frame length */ + int16_t *syn_dm_phase ); void ScaleShapedSHB_fx( - const Word16 length, /* i : SHB overlap length */ - Word16 *synSHB, /* i/o: synthesized shb signal */ - Word16 *overlap, /* i/o: buffer for overlap-add */ - const Word16 *subgain, /* i : subframe gain */ - const Word32 frame_gain, /* i : frame gain */ - const Word16 *win, /* i : window */ - const Word16 *subwin, /* i : subframes window */ - Word16 *Q_bwe_exc - , Word16 *Qx - , Word16 n_mem3 - , Word16 prev_Q_bwe_syn2 -); + const Word16 length, /* i : SHB overlap length */ + Word16 *synSHB, /* i/o: synthesized shb signal */ + Word16 *overlap, /* i/o: buffer for overlap-add */ + const Word16 *subgain, /* i : subframe gain */ + const Word32 frame_gain, /* i : frame gain */ + const Word16 *win, /* i : window */ + const Word16 *subwin, /* i : subframes window */ + Word16 *Q_bwe_exc, + Word16 *Qx, + Word16 n_mem3, + Word16 prev_Q_bwe_syn2 ); void ScaleShapedSHB_32( - const int16_t length, /* i : SHB overlap length */ - Word32 *synSHB_fx, /* i/o: synthesized shb signal Qx */ - Word32 *overlap_fx, /* i/o: buffer for overlap-add Qx */ - const Word16 *subgain_fx, /* i : subframe gain Q15 */ - const Word32 frame_gain_fx, /* i : frame gain */ - const Word16 *win_fx, /* i : window Q15 */ - const Word16 *subwin_fx, /* i : subframes window Q15 */ - Word16 *Q_inp, - Word16 *Q_new - ); + const int16_t length, /* i : SHB overlap length */ + Word32 *synSHB_fx, /* i/o: synthesized shb signal Qx */ + Word32 *overlap_fx, /* i/o: buffer for overlap-add Qx */ + const Word16 *subgain_fx, /* i : subframe gain Q15 */ + const Word32 frame_gain_fx, /* i : frame gain */ + const Word16 *win_fx, /* i : window Q15 */ + const Word16 *subwin_fx, /* i : subframes window Q15 */ + Word16 *Q_inp, + Word16 *Q_new ); void ScaleShapedWB_fx( - const Word16 length, /* i : SHB overlap length */ - Word16* synSHB, /* i/o : synthesized shb signal */ - Word16* overlap, /* i/o : buffer for overlap-add */ - const Word16* subgain, /* i : subframe gain */ - const Word32 frame_gain, /* i : frame gain */ - const Word16* win, /* i : window */ - const Word16* subwin, /* i : subframes window */ - const Word16 Q_bwe_exc - , Word16 L_frame /* i : Frame length - determines whether 12.8 or 16kHz core in-use */ - , Word16 dynQ /* i : indicate whether output is dynamic Q, or Q0 */ - , Word16* Qx /* o : newly computed Q factor for synSHB */ - , Word16 prev_Qx /* i : prev_Qx for memory scaling */ - , Word32* Hilbert_Mem /* i : Hilbert memory used for computing Qx */ + const Word16 length, /* i : SHB overlap length */ + Word16 *synSHB, /* i/o : synthesized shb signal */ + Word16 *overlap, /* i/o : buffer for overlap-add */ + const Word16 *subgain, /* i : subframe gain */ + const Word32 frame_gain, /* i : frame gain */ + const Word16 *win, /* i : window */ + const Word16 *subwin, /* i : subframes window */ + const Word16 Q_bwe_exc, + Word16 L_frame /* i : Frame length - determines whether 12.8 or 16kHz core in-use */ + , + Word16 dynQ /* i : indicate whether output is dynamic Q, or Q0 */ + , + Word16 *Qx /* o : newly computed Q factor for synSHB */ + , + Word16 prev_Qx /* i : prev_Qx for memory scaling */ + , + Word32 *Hilbert_Mem /* i : Hilbert memory used for computing Qx */ ); void non_linearity_fx( - const Word16 i[], /* i : i signal Q_inp */ - Word32 output[], /* o : output signal 2*Q_inp */ - const Word16 length, /* i : i length */ - Word32 *prev_scale, /* i/o: memory Q30 */ - Word16 Q_inp, - Word16 coder_type, /* i : Coder Type */ - Word16 *voice_factors, /* i : Voice Factors */ - const Word16 L_frame /* i : ACELP frame length */ + const Word16 i[], /* i : i signal Q_inp */ + Word32 output[], /* o : output signal 2*Q_inp */ + const Word16 length, /* i : i length */ + Word32 *prev_scale, /* i/o: memory Q30 */ + Word16 Q_inp, + Word16 coder_type, /* i : Coder Type */ + Word16 *voice_factors, /* i : Voice Factors */ + const Word16 L_frame /* i : ACELP frame length */ ); void non_linearity_ivas_fx( - const Word16 i[], /* i : i signal Q_inp */ - Word32 output[], /* o : output signal 2*Q_inp */ - const Word16 length, /* i : i length */ - Word32 *prev_scale, /* i/o: memory Q30 */ + const Word16 i[], /* i : i signal Q_inp */ + Word32 output[], /* o : output signal 2*Q_inp */ + const Word16 length, /* i : i length */ + Word32 *prev_scale, /* i/o: memory Q30 */ Word16 Q_inp, - Word16 coder_type, /* i : Coder Type */ - Word16 *voice_factors, /* i : Voice Factors */ - const Word16 L_frame /* i : ACELP frame length */ + Word16 coder_type, /* i : Coder Type */ + Word16 *voice_factors, /* i : Voice Factors */ + const Word16 L_frame /* i : ACELP frame length */ ); void interp_code_5over2_fx( - const Word16 inp_code[], /* i : i vector */ - Word16 interp_code[], /* o : output vector */ - const Word16 inp_length /* i : length of i vector */ + const Word16 inp_code[], /* i : i vector */ + Word16 interp_code[], /* o : output vector */ + const Word16 inp_length /* i : length of i vector */ ); void interp_code_4over2_fx( - const Word16 inp_code_fx[], /* i : i vector Qx */ - Word16 interp_code_fx[], /* o : output vector Qx */ - const Word16 inp_length /* i : length of i vector */ + const Word16 inp_code_fx[], /* i : i vector Qx */ + Word16 interp_code_fx[], /* o : output vector Qx */ + const Word16 inp_length /* i : length of i vector */ ); -void wb_tbe_extras_reset_synth_fx(Word16 state_lsyn_filt_shb[], Word16 state_lsyn_filt_dwn_shb[], - Word16 state_32and48k_WB_upsample[] - , Word16 state_resamp_HB[] -); +void wb_tbe_extras_reset_synth_fx( Word16 state_lsyn_filt_shb[], Word16 state_lsyn_filt_dwn_shb[], Word16 state_32and48k_WB_upsample[], Word16 state_resamp_HB[] ); void elliptic_bpf_48k_generic_fx( - const Word16 input_fx[], /* i : i signal */ - Word16 *Q_input_fx, - Word16 output_fx[], /* o : output signal */ - Word32 memory_fx[][4], /* i/o: 4 arrays of 4 for memory */ - Word16 memory_fx_Q[], - const Word16 full_band_bpf[][5] /* i : filter coefficients b0,b1,b2,a0,a1,a2 Q13 */ + const Word16 input_fx[], /* i : i signal */ + Word16 *Q_input_fx, + Word16 output_fx[], /* o : output signal */ + Word32 memory_fx[][4], /* i/o: 4 arrays of 4 for memory */ + Word16 memory_fx_Q[], + const Word16 full_band_bpf[][5] /* i : filter coefficients b0,b1,b2,a0,a1,a2 Q13 */ ); void synthesise_fb_high_band_fx( - const Word16 excitation_in[], /* i : full band excitation */ - Word16 Q_fb_exc, - Word16 output[], /* o : high band speech - 14.0 to 20 kHz */ - const Word32 fb_exc_energy, /* i : full band excitation energy */ - const Word16 ratio, /* i : energy ratio */ - const Word16 L_frame, /* i : ACELP frame length */ - const Word16 bfi, /* i : fec flag */ - Word16 *prev_fbbwe_ratio, /* o : previous frame energy for FEC */ - Word32 bpf_memory[][4], /* i/o: memory for elliptic bpf 48k */ - Word16 bpf_memory_Q[], - Word16 Qout -); + const Word16 excitation_in[], /* i : full band excitation */ + Word16 Q_fb_exc, + Word16 output[], /* o : high band speech - 14.0 to 20 kHz */ + const Word32 fb_exc_energy, /* i : full band excitation energy */ + const Word16 ratio, /* i : energy ratio */ + const Word16 L_frame, /* i : ACELP frame length */ + const Word16 bfi, /* i : fec flag */ + Word16 *prev_fbbwe_ratio, /* o : previous frame energy for FEC */ + Word32 bpf_memory[][4], /* i/o: memory for elliptic bpf 48k */ + Word16 bpf_memory_Q[], + Word16 Qout ); void prep_tbe_exc_fx( - const Word16 L_frame_fx, /* i : length of the frame */ + const Word16 L_frame_fx, /* i : length of the frame */ #ifdef ADD_IVAS_TBE_CODE - const Word16 L_subfr, + const Word16 L_subfr, #endif - const Word16 i_subfr_fx, /* i : subframe index */ - const Word16 gain_pit_fx, /* i : Pitch gain Q14*/ - const Word32 gain_code_fx, /* i : algebraic codebook gain 16+Q_exc*/ - const Word16 code_fx[], /* i : algebraic excitation Q9*/ - const Word16 voice_fac_fx, /* i : voicing factor Q15*/ - Word16 *voice_factors_fx, /* o : TBE voicing factor Q15*/ - Word16 bwe_exc_fx[], /* i/o: excitation for TBE Q_exc*/ - const Word16 gain_preQ_fx, /* i : prequantizer excitation gain */ - const Word16 code_preQ_fx[],/* i : prequantizer excitation */ - const Word16 Q_exc, /* i : Excitation, bwe_exc Q-factor */ - Word16 T0, /* i : integer pitch variables Q0 */ - Word16 T0_frac, /* i : Fractional pitch variables Q0*/ - const Word16 coder_type, /* i : coding type */ - Word32 core_brate /* i :core bitrate */ + const Word16 i_subfr_fx, /* i : subframe index */ + const Word16 gain_pit_fx, /* i : Pitch gain Q14*/ + const Word32 gain_code_fx, /* i : algebraic codebook gain 16+Q_exc*/ + const Word16 code_fx[], /* i : algebraic excitation Q9*/ + const Word16 voice_fac_fx, /* i : voicing factor Q15*/ + Word16 *voice_factors_fx, /* o : TBE voicing factor Q15*/ + Word16 bwe_exc_fx[], /* i/o: excitation for TBE Q_exc*/ + const Word16 gain_preQ_fx, /* i : prequantizer excitation gain */ + const Word16 code_preQ_fx[], /* i : prequantizer excitation */ + const Word16 Q_exc, /* i : Excitation, bwe_exc Q-factor */ + Word16 T0, /* i : integer pitch variables Q0 */ + Word16 T0_frac, /* i : Fractional pitch variables Q0*/ + const Word16 coder_type, /* i : coding type */ + Word32 core_brate /* i :core bitrate */ #ifdef ADD_IVAS_TBE_CODE - , const Word16 element_mode, /* i : element mode */ - const Word16 idchan, /* i : channel ID */ - const Word16 flag_TD_BWE, /* i : flag indicating whether hTD_BWE exists */ - const Word16 tdm_LRTD_flag /* i : LRTD stereo mode flag */ + , + const Word16 element_mode, /* i : element mode */ + const Word16 idchan, /* i : channel ID */ + const Word16 flag_TD_BWE, /* i : flag indicating whether hTD_BWE exists */ + const Word16 tdm_LRTD_flag /* i : LRTD stereo mode flag */ #endif ); void prep_tbe_exc_ivas_fx( - const Word16 L_frame_fx, /* i : length of the frame */ -#if 1//def ADD_IVAS_TBE_CODE + const Word16 L_frame_fx, /* i : length of the frame */ +#if 1 // def ADD_IVAS_TBE_CODE const Word16 L_subfr, #endif - const Word16 i_subfr_fx, /* i : subframe index */ - const Word16 gain_pit_fx, /* i : Pitch gain Q14*/ - const Word32 gain_code_fx, /* i : algebraic codebook gain 16+Q_exc*/ - const Word16 code_fx[], /* i : algebraic excitation Q9*/ - const Word16 voice_fac_fx, /* i : voicing factor Q15*/ - Word16 *voice_factors_fx, /* o : TBE voicing factor Q15*/ - Word16 bwe_exc_fx[], /* i/o: excitation for TBE Q_exc*/ - const Word16 gain_preQ_fx, /* i : prequantizer excitation gain */ - const Word16 code_preQ_fx[], /* i : prequantizer excitation */ - const Word16 Q_exc, /* i : Excitation, bwe_exc Q-factor */ - Word16 T0, /* i : integer pitch variables Q0 */ - Word16 T0_frac, /* i : Fractional pitch variables Q0*/ - const Word16 coder_type, /* i : coding type */ + const Word16 i_subfr_fx, /* i : subframe index */ + const Word16 gain_pit_fx, /* i : Pitch gain Q14*/ + const Word32 gain_code_fx, /* i : algebraic codebook gain 16+Q_exc*/ + const Word16 code_fx[], /* i : algebraic excitation Q9*/ + const Word16 voice_fac_fx, /* i : voicing factor Q15*/ + Word16 *voice_factors_fx, /* o : TBE voicing factor Q15*/ + Word16 bwe_exc_fx[], /* i/o: excitation for TBE Q_exc*/ + const Word16 gain_preQ_fx, /* i : prequantizer excitation gain */ + const Word16 code_preQ_fx[], /* i : prequantizer excitation */ + const Word16 Q_exc, /* i : Excitation, bwe_exc Q-factor */ + Word16 T0, /* i : integer pitch variables Q0 */ + Word16 T0_frac, /* i : Fractional pitch variables Q0*/ + const Word16 coder_type, /* i : coding type */ Word32 core_brate -#if 1//def ADD_IVAS_TBE_CODE - , /* i : core bitrate */ - const Word16 element_mode, /* i : element mode */ - const Word16 idchan, /* i : channel ID */ - const Word16 flag_TD_BWE, /* i : flag indicating whether hTD_BWE exists */ - const Word16 tdm_LRTD_flag /* i : LRTD stereo mode flag */ +#if 1 // def ADD_IVAS_TBE_CODE + , /* i : core bitrate */ + const Word16 element_mode, /* i : element mode */ + const Word16 idchan, /* i : channel ID */ + const Word16 flag_TD_BWE, /* i : flag indicating whether hTD_BWE exists */ + const Word16 tdm_LRTD_flag /* i : LRTD stereo mode flag */ #endif ); -Word16 swb_formant_fac_fx( /* o : Formant filter strength [0,1] */ - const Word16 lpc_shb2, /* Q12 i : 2nd HB LPC coefficient */ - Word16* tilt_mem /* i/o: Tilt smoothing memory */ +Word16 swb_formant_fac_fx( /* o : Formant filter strength [0,1] */ + const Word16 lpc_shb2, /* Q12 i : 2nd HB LPC coefficient */ + Word16 *tilt_mem /* i/o: Tilt smoothing memory */ ); void wb_tbe_extras_reset_fx( - Word16 mem_genSHBexc_filt_down_wb2[], - Word16 mem_genSHBexc_filt_down_wb3[] -); + Word16 mem_genSHBexc_filt_down_wb2[], + Word16 mem_genSHBexc_filt_down_wb3[] ); Word16 get_tbe_bits_fx( - const Word32 total_brate, /* o : TBE bit consumption per frame */ - const Word16 bwidth, /* i : overall bitrate */ - const Word16 rf_mode /* i : bandwidht mode */ + const Word32 total_brate, /* o : TBE bit consumption per frame */ + const Word16 bwidth, /* i : overall bitrate */ + const Word16 rf_mode /* i : bandwidht mode */ ); -//pvq_com_fx +// pvq_com_fx UWord32 intLimCDivPos_fx( - UWord32 NUM, - Word16 DEN -); + UWord32 NUM, + Word16 DEN ); -Word16 shrtCDivSignedApprox( - const Word16 num, - const Word16 den -); +Word16 shrtCDivSignedApprox( + const Word16 num, + const Word16 den ); void obtainEnergyQuantizerDensity_fx( - const Word16 L, - const Word16 R, - Word16 *Density -); + const Word16 L, + const Word16 R, + Word16 *Density ); void dsDirac2Dirac_fx( - const Word16 dsDiracIndex, - Word16 *diracs -); + const Word16 dsDiracIndex, + Word16 *diracs ); void dsDiracPerQuanta_fx( - const Word16 td, - const Word16 t_quanta, - const Word16 dsm, - const unsigned char* const *frQuanta, - Word16 *DsIdx -); + const Word16 td, + const Word16 t_quanta, + const Word16 dsm, + const unsigned char *const *frQuanta, + Word16 *DsIdx ); void QuantaPerDsDirac_fx( - const Word16 td, /* i : Length of vector segment */ - const Word16 dsDiracIndex, /* i : Quanta table index */ - const unsigned char* const* dimFrQuanta, /* i : Quanta lookup table */ - Word16* Quanta /* i : Quanta */ + const Word16 td, /* i : Length of vector segment */ + const Word16 dsDiracIndex, /* i : Quanta table index */ + const unsigned char *const *dimFrQuanta, /* i : Quanta lookup table */ + Word16 *Quanta /* i : Quanta */ ); void conservativeL1Norm_fx( - const Word16 L, /* i : Length of vector segment */ - const Word16 Qvec, /* i : Assigned number of quanta */ - const Word16 Fcons, /* i : Conservative rounding flag */ - const Word16 Qavail, /* i : Input quanta remaining */ - const Word16 Qreserv, /* i : Input quanta in reservoir */ - const Word16 Dspec, /* i : assigned diracs from bitalloc */ - Word16* Dvec, /* o : actual number of diracs */ - Word16* Qspare, /* o : Output quanta remaining */ - Word16* Qreservplus, /* o : Output quanta in reservoir */ - Word16* Dspecplus /* o : Output number of diracs */ + const Word16 L, /* i : Length of vector segment */ + const Word16 Qvec, /* i : Assigned number of quanta */ + const Word16 Fcons, /* i : Conservative rounding flag */ + const Word16 Qavail, /* i : Input quanta remaining */ + const Word16 Qreserv, /* i : Input quanta in reservoir */ + const Word16 Dspec, /* i : assigned diracs from bitalloc */ + Word16 *Dvec, /* o : actual number of diracs */ + Word16 *Qspare, /* o : Output quanta remaining */ + Word16 *Qreservplus, /* o : Output quanta in reservoir */ + Word16 *Dspecplus /* o : Output number of diracs */ ); void bandBitsAdjustment_fx( - const Word16 Brc, /* i : Current number of read quanta in range coder */ - const UWord32 INTrc, /* i : Range coder state */ - const Word16 Bavail, /* i : Available number of quanta */ - const Word16 Nbands, /* i : Number of bands */ - const Word16 D, /* i : Remaining number of bands to encode */ - const Word16 L, /* i : Size of current band */ - const Word16 Bband, /* i : Quanta allocation for current band */ - const Word16 Breserv, /* i : Quanta reservoir */ - Word16* Bband_adj, /* o : Actual used number of quanta */ - Word16* Brem, /* o : Quanta remaining */ - Word16* Breservplus /* o : Quanta pool size */ + const Word16 Brc, /* i : Current number of read quanta in range coder */ + const UWord32 INTrc, /* i : Range coder state */ + const Word16 Bavail, /* i : Available number of quanta */ + const Word16 Nbands, /* i : Number of bands */ + const Word16 D, /* i : Remaining number of bands to encode */ + const Word16 L, /* i : Size of current band */ + const Word16 Bband, /* i : Quanta allocation for current band */ + const Word16 Breserv, /* i : Quanta reservoir */ + Word16 *Bband_adj, /* o : Actual used number of quanta */ + Word16 *Brem, /* o : Quanta remaining */ + Word16 *Breservplus /* o : Quanta pool size */ ); void densityAngle2RmsProjDec_fx( - const Word16 D, /* i : density */ - const Word16 indexphi, /* i : decoded index from AR dec */ - Word16* oppQ15, /* o : opposite */ - Word16* nearQ15, /* o : near */ - Word16* oppRatioQ3 /* o : ratio */ + const Word16 D, /* i : density */ + const Word16 indexphi, /* i : decoded index from AR dec */ + Word16 *oppQ15, /* o : opposite */ + Word16 *nearQ15, /* o : near */ + Word16 *oppRatioQ3 /* o : ratio */ ); void densityAngle2RmsProjEnc_fx( - const Word16 D, /* i : density */ - const Word16 phiQ14uq, /* i : angle */ - Word16* indexphi, /* o : index */ - Word16* oppQ15, /* o : opposite */ - Word16* nearQ15, /* o : near */ - Word16* oppRatioQ3 /* o : ratio */ + const Word16 D, /* i : density */ + const Word16 phiQ14uq, /* i : angle */ + Word16 *indexphi, /* o : index */ + Word16 *oppQ15, /* o : opposite */ + Word16 *nearQ15, /* o : near */ + Word16 *oppRatioQ3 /* o : ratio */ ); void NearOppSplitAdjustment_fx( - const Word16 qband, - const Word16 qzero, - const Word16 Qac, - const UWord32 INTac, - const Word16 qglobal, - const Word16 FlagCons, - const Word16 Np, - const Word16 Nhead, - const Word16 Ntail, - const Word16 Nnear, - const Word16 Nopp, - Word16 oppRQ3, - Word16 *qnear, - Word16 *qopp, - Word16 *qglobalupd -); + const Word16 qband, + const Word16 qzero, + const Word16 Qac, + const UWord32 INTac, + const Word16 qglobal, + const Word16 FlagCons, + const Word16 Np, + const Word16 Nhead, + const Word16 Ntail, + const Word16 Nnear, + const Word16 Nopp, + Word16 oppRQ3, + Word16 *qnear, + Word16 *qopp, + Word16 *qglobalupd ); void apply_gain_fx( - const Word16 *ord, /* i : Indices for energy order */ - const Word16 *band_start, /* i : Sub band start indices */ - const Word16 *band_end, /* i : Sub band end indices */ - const Word16 num_sfm, /* i : Number of bands */ - const Word16 *gains, /* i : Band gain vector Q12 */ - Word16 *xq /* i/o: Float synthesis / Gain adjusted synth Q15/Q12 */ + const Word16 *ord, /* i : Indices for energy order */ + const Word16 *band_start, /* i : Sub band start indices */ + const Word16 *band_end, /* i : Sub band end indices */ + const Word16 num_sfm, /* i : Number of bands */ + const Word16 *gains, /* i : Band gain vector Q12 */ + Word16 *xq /* i/o: Float synthesis / Gain adjusted synth Q15/Q12 */ ); void fine_gain_quant_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 *ord, /* i : Indices for energy order */ - const Word16 num_sfm, /* i : Number of bands */ - const Word16 *gain_bits, /* i : Gain adjustment bits per sub band */ - Word16 *fg_pred, /* i/o: Predicted gains / Corrected gains Q12 */ - const Word16 *gopt /* i : Optimal gains Q12 */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 *ord, /* i : Indices for energy order */ + const Word16 num_sfm, /* i : Number of bands */ + const Word16 *gain_bits, /* i : Gain adjustment bits per sub band */ + Word16 *fg_pred, /* i/o: Predicted gains / Corrected gains Q12 */ + const Word16 *gopt /* i : Optimal gains Q12 */ ); void srt_vec_ind16_fx( - const Word16 *linear, /* linear i */ - Word16 *srt, /* sorted output*/ - Word16 *I, /* index for sorted output */ - Word16 length -); + const Word16 *linear, /* linear i */ + Word16 *srt, /* sorted output*/ + Word16 *I, /* index for sorted output */ + Word16 length ); Word16 atan2_fx( - const Word32, - const Word32 -); + const Word32, + const Word32 ); -//rang_com_fx.c -Word16 rc_get_bits2_fx( /* o: Number of bits needed */ - const Word16 N, /* i: Number of bits currently used */ - const UWord32 range /* i: Range of range coder */ +// rang_com_fx.c +Word16 rc_get_bits2_fx( /* o: Number of bits needed */ + const Word16 N, /* i: Number of bits currently used */ + const UWord32 range /* i: Range of range coder */ ); void rangeCoderFinalizationFBits_fx( - Word16 Brc, /* i : Current number of decoded bits */ - UWord32 INTrc, /* i : Range coder state */ - Word16* FBits /* i : Fractional finalization bits */ + Word16 Brc, /* i : Current number of decoded bits */ + UWord32 INTrc, /* i : Range coder state */ + Word16 *FBits /* i : Fractional finalization bits */ ); -//wi_fx.c +// wi_fx.c -ivas_error DTFS_new_fx(DTFS_STRUCTURE** dtfs_out); +ivas_error DTFS_new_fx( DTFS_STRUCTURE **dtfs_out ); void DTFS_copy_fx( - DTFS_STRUCTURE *Xout_fx, /* o: DTFS structure */ - DTFS_STRUCTURE Xinp_fx /* i: DTFS structure */ + DTFS_STRUCTURE *Xout_fx, /* o: DTFS structure */ + DTFS_STRUCTURE Xinp_fx /* i: DTFS structure */ ); void DTFS_sub_fx( - DTFS_STRUCTURE* tmp,/* o: X1 - X2 */ - DTFS_STRUCTURE X1, /* i: DTFS i 1 */ - DTFS_STRUCTURE X2 /* i: DTFS i 2 */ + DTFS_STRUCTURE *tmp, /* o: X1 - X2 */ + DTFS_STRUCTURE X1, /* i: DTFS i 1 */ + DTFS_STRUCTURE X2 /* i: DTFS i 2 */ ); Word16 DTFS_alignment_full_fx( - DTFS_STRUCTURE X1_DTFS_fx, /* i : reference DTFS */ - DTFS_STRUCTURE X2_DTFS_fx, /* i : DTFS to shift */ - Word16 ph_offset_fx, /* i : resolution */ - Word16 *S_fx, - Word16 *C_fx - , Word16 FR_flag -); + DTFS_STRUCTURE X1_DTFS_fx, /* i : reference DTFS */ + DTFS_STRUCTURE X2_DTFS_fx, /* i : DTFS to shift */ + Word16 ph_offset_fx, /* i : resolution */ + Word16 *S_fx, + Word16 *C_fx, + Word16 FR_flag ); -void DTFS_phaseShift_fx(DTFS_STRUCTURE *X_fx, Word16 ph, Word16 Lag, Word16 *S_fx, Word16 *C_fx); +void DTFS_phaseShift_fx( DTFS_STRUCTURE *X_fx, Word16 ph, Word16 Lag, Word16 *S_fx, Word16 *C_fx ); -void Q2phaseShift_fx(DTFS_STRUCTURE *X_fx, Word16 ph, Word16 Lag, Word16 *S_fx, Word16 *C_fx); +void Q2phaseShift_fx( DTFS_STRUCTURE *X_fx, Word16 ph, Word16 Lag, Word16 *S_fx, Word16 *C_fx ); -void DTFS_zeroPadd_fx(Word16 N_fx, DTFS_STRUCTURE *X_fx); +void DTFS_zeroPadd_fx( Word16 N_fx, DTFS_STRUCTURE *X_fx ); void DTFS_to_fs_fx( - const Word16* x, /* i : time domain signal */ - Word16 N, /* i : Length of i vector */ - DTFS_STRUCTURE* X_fx, /* o : DTFS structure with a, b, lag */ - const Word16 Fs, /* i : sampling rate */ - const Word16 FR_flag, /* i : FR flag */ - Word16* S_fx, - Word16* C_fx -); + const Word16 *x, /* i : time domain signal */ + Word16 N, /* i : Length of i vector */ + DTFS_STRUCTURE *X_fx, /* o : DTFS structure with a, b, lag */ + const Word16 Fs, /* i : sampling rate */ + const Word16 FR_flag, /* i : FR flag */ + Word16 *S_fx, + Word16 *C_fx ); void DTFS_zeroFilter_fx( - DTFS_STRUCTURE *X_fx, - Word16 *LPC, - Word16 N, - Word16 *S_fx, - Word16 *C_fx -); + DTFS_STRUCTURE *X_fx, + Word16 *LPC, + Word16 N, + Word16 *S_fx, + Word16 *C_fx ); -void DTFS_poleFilter_fx_9(DTFS_STRUCTURE *X_fx, Word16 *pf_temp1, Word16 *pf_temp2, Word16 *pf_temp, Word16 *pf_n2_temp1); +void DTFS_poleFilter_fx_9( DTFS_STRUCTURE *X_fx, Word16 *pf_temp1, Word16 *pf_temp2, Word16 *pf_temp, Word16 *pf_n2_temp1 ); void DTFS_adjustLag_fx( - DTFS_STRUCTURE *X_DTFS_FX, /* i/o : DTFS to adjust lag for */ - Word16 N_fx /* i : Target lag */ + DTFS_STRUCTURE *X_DTFS_FX, /* i/o : DTFS to adjust lag for */ + Word16 N_fx /* i : Target lag */ ); -Word32 DTFS_getEngy_fx(DTFS_STRUCTURE *X_fx); +Word32 DTFS_getEngy_fx( DTFS_STRUCTURE *X_fx ); -Word32 DTFS_getEngy_P2A_fx(DTFS_STRUCTURE *X_fx); +Word32 DTFS_getEngy_P2A_fx( DTFS_STRUCTURE *X_fx ); void DTFS_car2pol_fx( - DTFS_STRUCTURE *X_fx /* i/o : DTFS structure a, b, lag */ + DTFS_STRUCTURE *X_fx /* i/o : DTFS structure a, b, lag */ ); Word32 DTFS_setEngyHarm_fx( - Word16 f1_fx, /* i : lower band freq of i to control energy */ - Word16 f2_fx, /* i : upper band freq of i to control energy */ - Word16 g1_fx, /* i : lower band freq of output to control energy */ - Word16 g2_fx, /* i : upper band freq of output to control energy */ - Word32 en2_fx, /* i : Target Energy to set the DTFS to */ - Word16 Qen2_fx, /* i : Input Q format for en2 */ - Word16 *Qa_fx, /* i : Output Q format for x->a */ - DTFS_STRUCTURE *X_fx /* i/o: DTFS to adjust the energy of */ + Word16 f1_fx, /* i : lower band freq of i to control energy */ + Word16 f2_fx, /* i : upper band freq of i to control energy */ + Word16 g1_fx, /* i : lower band freq of output to control energy */ + Word16 g2_fx, /* i : upper band freq of output to control energy */ + Word32 en2_fx, /* i : Target Energy to set the DTFS to */ + Word16 Qen2_fx, /* i : Input Q format for en2 */ + Word16 *Qa_fx, /* i : Output Q format for x->a */ + DTFS_STRUCTURE *X_fx /* i/o: DTFS to adjust the energy of */ ); void DTFS_to_erb_fx( - const DTFS_STRUCTURE X_fx, /* i : DTFS i */ - Word16 *out_fx /* o : ERB output */ + const DTFS_STRUCTURE X_fx, /* i : DTFS i */ + Word16 *out_fx /* o : ERB output */ ); void erb_slot_fx( - Word16 lag_fx, /* i : i lag */ - Word16 *out_fx, /* o : ERB slots */ - Word16 *mfreq_fx, /* i : ERB frequencies */ - Word16 num_erb_fx /* i : number of ERBs */ + Word16 lag_fx, /* i : i lag */ + Word16 *out_fx, /* o : ERB slots */ + Word16 *mfreq_fx, /* i : ERB frequencies */ + Word16 num_erb_fx /* i : number of ERBs */ ); void DTFS_erb_inv_fx( - Word16 *in_fx, /* i : ERB inpt */ - Word16 *slot_fx, /* i : ERB slots filled based on lag */ - Word16 *mfreq_fx, /* i : erb frequence edges */ - DTFS_STRUCTURE *X_fx, /* o : DTFS after erb-inv */ - Word16 num_erb_fx /* i : Number of ERB bands */ + Word16 *in_fx, /* i : ERB inpt */ + Word16 *slot_fx, /* i : ERB slots filled based on lag */ + Word16 *mfreq_fx, /* i : erb frequence edges */ + DTFS_STRUCTURE *X_fx, /* o : DTFS after erb-inv */ + Word16 num_erb_fx /* i : Number of ERB bands */ ); void erb_add_fx( - Word16 *curr_erb_fx, /* i/o: current ERB */ - Word16 l_fx, /* i : current lag */ - const Word16 *prev_erb_fx, /* i : previous ERB */ - Word16 pl_fx, /* i : previous lag */ - const Word16 *index_fx, /* i : ERB index */ - Word16 num_erb_fx /* i : number of ERBs */ + Word16 *curr_erb_fx, /* i/o: current ERB */ + Word16 l_fx, /* i : current lag */ + const Word16 *prev_erb_fx, /* i : previous ERB */ + Word16 pl_fx, /* i : previous lag */ + const Word16 *index_fx, /* i : ERB index */ + Word16 num_erb_fx /* i : number of ERBs */ ); -void quant_target_fx(DTFS_STRUCTURE *X_fx, const Word16 *curr_lpc, Word16 *w, Word16 *target, - Word16 *sin_tab, Word16 *cos_tab); +void quant_target_fx( DTFS_STRUCTURE *X_fx, const Word16 *curr_lpc, Word16 *w, Word16 *target, Word16 *sin_tab, Word16 *cos_tab ); ivas_error WIsyn_fx( - DTFS_STRUCTURE PREVCW_FX, /* i : Prev frame DTFS */ - DTFS_STRUCTURE* CURR_CW_DTFS_FX, /* i/o: Curr frame DTFS */ - const Word16* curr_lpc_fx, /* i : LPC */ - Word16* ph_offset_fx, /* i/o: Phase offset to line up at end of frame */ - Word16* out_fx, /* o : Waveform Interpolated time domain signal */ - const Word16 N, /* i : Number of output samples to generate */ - const Word16 FR_flag, /* i : called for post-smoothing in FR */ - Word16* S_fx, - Word16* C_fx, - Word16* pf_temp1, - Word16* pf_temp2, - Word16* pf_temp, - Word16* pf_n2 -); + DTFS_STRUCTURE PREVCW_FX, /* i : Prev frame DTFS */ + DTFS_STRUCTURE *CURR_CW_DTFS_FX, /* i/o: Curr frame DTFS */ + const Word16 *curr_lpc_fx, /* i : LPC */ + Word16 *ph_offset_fx, /* i/o: Phase offset to line up at end of frame */ + Word16 *out_fx, /* o : Waveform Interpolated time domain signal */ + const Word16 N, /* i : Number of output samples to generate */ + const Word16 FR_flag, /* i : called for post-smoothing in FR */ + Word16 *S_fx, + Word16 *C_fx, + Word16 *pf_temp1, + Word16 *pf_temp2, + Word16 *pf_temp, + Word16 *pf_n2 ); Word16 ppp_extract_pitch_period_fx( - const Word16 *in, /* i : i residual */ - Word16 *out, /* o : output residual */ - Word16 l, /* i : lag */ - Word16 *out_of_bound, /* o : out of bound flag */ - Word16 Qres + const Word16 *in, /* i : i residual */ + Word16 *out, /* o : output residual */ + Word16 l, /* i : lag */ + Word16 *out_of_bound, /* o : out of bound flag */ + Word16 Qres ); void DTFS_peaktoaverage_fx( - DTFS_STRUCTURE X_fx, /* i : DTFS */ - Word32 *pos_fx, /* o : positive peak to ave */ - Word16 *Qpos, /* o : positive peak to ave Q format */ - Word32 *neg_fx, /* o : negative peak to ave */ - Word16 *Qneg /* o : negative peak to ave Q format */ + DTFS_STRUCTURE X_fx, /* i : DTFS */ + Word32 *pos_fx, /* o : positive peak to ave */ + Word16 *Qpos, /* o : positive peak to ave Q format */ + Word32 *neg_fx, /* o : negative peak to ave */ + Word16 *Qneg /* o : negative peak to ave Q format */ ); -void rshiftHarmBand_fx(DTFS_STRUCTURE *X_fx, Word16 lband_fx, Word16 hband_fx, Word16 shift_fx); +void rshiftHarmBand_fx( DTFS_STRUCTURE *X_fx, Word16 lband_fx, Word16 hband_fx, Word16 shift_fx ); -void GetSinCosTab_fx(Word16 L, Word16 *sinTab, Word16 *cosTab); +void GetSinCosTab_fx( Word16 L, Word16 *sinTab, Word16 *cosTab ); -void r_fft_4_fx(Word16 * farray_ptr_fx, Word16 size, Word16 stage, Word16 isign); +void r_fft_4_fx( Word16 *farray_ptr_fx, Word16 size, Word16 stage, Word16 isign ); -void copy_phase_fx(DTFS_STRUCTURE *X1_fx, DTFS_STRUCTURE X2_fx, DTFS_STRUCTURE *retX_fx); +void copy_phase_fx( DTFS_STRUCTURE *X1_fx, DTFS_STRUCTURE X2_fx, DTFS_STRUCTURE *retX_fx ); -Word32 getSpEngyFromResAmp_fx(DTFS_STRUCTURE *X_fx, Word16 lband, Word16 hband, - const Word16 *curr_lpc, Word16 *sin_tab, - Word16 *cos_tab); +Word32 getSpEngyFromResAmp_fx( DTFS_STRUCTURE *X_fx, Word16 lband, Word16 hband, const Word16 *curr_lpc, Word16 *sin_tab, Word16 *cos_tab ); -void DTFS_poleFilter_fx(DTFS_STRUCTURE *X_fx, Word16 *LPC, Word16 N, Word16 *S_fx, Word16 *C_fx); +void DTFS_poleFilter_fx( DTFS_STRUCTURE *X_fx, Word16 *LPC, Word16 N, Word16 *S_fx, Word16 *C_fx ); -void poleFilter_setup_fx(const Word16 *LPC, Word16 N, DTFS_STRUCTURE X_fx, Word16 *S_fx, Word16 *C_fx, Word16 *pf_temp1, Word16 *pf_temp2, Word16 *pf_temp, Word16 *pf_n2_temp1); +void poleFilter_setup_fx( const Word16 *LPC, Word16 N, DTFS_STRUCTURE X_fx, Word16 *S_fx, Word16 *C_fx, Word16 *pf_temp1, Word16 *pf_temp2, Word16 *pf_temp, Word16 *pf_n2_temp1 ); Word32 DTFS_getEngy_band_wb_fx( - DTFS_STRUCTURE X_fx, - Word16 lband, - Word16 hband -); + DTFS_STRUCTURE X_fx, + Word16 lband, + Word16 hband ); -//tns_base.c +// tns_base.c /** Init TNS configuration. * Fills STnsConfig structure with sensible content. * @param nSampleRate Sampling rate of the i . @@ -3272,14 +3190,13 @@ Word32 DTFS_getEngy_band_wb_fx( * @return 0 on success, otherwise 1. */ void InitTnsConfiguration( - const Word16 bwidth, - const Word16 frameLength, - STnsConfig* pTnsConfig, - const Word16 igfStopFreq, - const Word32 total_brate, - const Word16 element_mode, - const Word16 is_mct -); + const Word16 bwidth, + const Word16 frameLength, + STnsConfig *pTnsConfig, + const Word16 igfStopFreq, + const Word32 total_brate, + const Word16 element_mode, + const Word16 is_mct ); /** Modify spectrum using TNS filter. * Modifies spectrum unsing TNS filter defined by pTnsData. @@ -3295,157 +3212,157 @@ void InitTnsConfiguration( * @return 0 on success, otherwise 1. */ void ApplyTnsFilter( - STnsConfig const * pTnsConfig, - STnsData const * pTnsData, - Word32 spectrum[], - const Word8 fIsAnalysis -); - -Word16 ITF_Detect_fx(Word32 const pSpectrum[], - const Word16 startLine, - const Word16 stopLine, - const Word16 maxOrder, - Word16* A, - Word16* Q_A, - Word16* predictionGain, - Word16* curr_order, - Word16 Q); + STnsConfig const *pTnsConfig, + STnsData const *pTnsData, + Word32 spectrum[], + const Word8 fIsAnalysis ); + +Word16 ITF_Detect_fx( Word32 const pSpectrum[], + const Word16 startLine, + const Word16 stopLine, + const Word16 maxOrder, + Word16 *A, + Word16 *Q_A, + Word16 *predictionGain, + Word16 *curr_order, + Word16 Q ); Word16 ITF_Detect_ivas_fx( const Word32 pSpectrum[], const Word16 startLine, const Word16 stopLine, const Word16 maxOrder, - Word16* A, - Word16* Q_A, - Word16* predictionGain, - Word16* curr_order, - Word16 Q -); + Word16 *A, + Word16 *Q_A, + Word16 *predictionGain, + Word16 *curr_order, + Word16 Q ); -void ITF_Apply_fx(Word32 spectrum[], - Word16 startLine, Word16 stopLine, const Word16* A, - Word16 Q_A, - Word16 curr_order); +void ITF_Apply_fx( Word32 spectrum[], + Word16 startLine, + Word16 stopLine, + const Word16 *A, + Word16 Q_A, + Word16 curr_order ); -void const * GetTnsFilterCoeff(void const * p, const Word16 index, Word16 * pValue); +void const *GetTnsFilterCoeff( void const *p, const Word16 index, Word16 *pValue ); -void * SetTnsFilterCoeff(void * p, const Word16 index, const Word16 value); +void *SetTnsFilterCoeff( void *p, const Word16 index, const Word16 value ); -Word16 GetSWBTCX20TnsFilterCoeffBits(const Word16 value, const Word16 index); +Word16 GetSWBTCX20TnsFilterCoeffBits( const Word16 value, const Word16 index ); -Word16 EncodeSWBTCX20TnsFilterCoeff(const Word16 value, const Word16 index); +Word16 EncodeSWBTCX20TnsFilterCoeff( const Word16 value, const Word16 index ); -Word16 DecodeSWBTCX20TnsFilterCoeff(Decoder_State *st, const Word16 index, Word16 * pValue); +Word16 DecodeSWBTCX20TnsFilterCoeff( Decoder_State *st, const Word16 index, Word16 *pValue ); -Word16 GetSWBTCX10TnsFilterCoeffBits(const Word16 value, const Word16 index); +Word16 GetSWBTCX10TnsFilterCoeffBits( const Word16 value, const Word16 index ); -Word16 EncodeSWBTCX10TnsFilterCoeff(const Word16 value, const Word16 index); +Word16 EncodeSWBTCX10TnsFilterCoeff( const Word16 value, const Word16 index ); -Word16 DecodeSWBTCX10TnsFilterCoeff(Decoder_State *st, const Word16 index, Word16 * pValue); +Word16 DecodeSWBTCX10TnsFilterCoeff( Decoder_State *st, const Word16 index, Word16 *pValue ); -Word16 GetWBTCX20TnsFilterCoeffBits(const Word16 value, const Word16 index); +Word16 GetWBTCX20TnsFilterCoeffBits( const Word16 value, const Word16 index ); -Word16 EncodeWBTCX20TnsFilterCoeff(const Word16 value, const Word16 index); +Word16 EncodeWBTCX20TnsFilterCoeff( const Word16 value, const Word16 index ); -Word16 DecodeWBTCX20TnsFilterCoeff(Decoder_State *st, const Word16 index, Word16 * pValue); +Word16 DecodeWBTCX20TnsFilterCoeff( Decoder_State *st, const Word16 index, Word16 *pValue ); -void const * GetTnsFilterOrder(void const * p, const Word16 index, Word16 * pValue); +void const *GetTnsFilterOrder( void const *p, const Word16 index, Word16 *pValue ); -void * SetTnsFilterOrder(void * p, const Word16 index, const Word16 value); +void *SetTnsFilterOrder( void *p, const Word16 index, const Word16 value ); -Word16 GetTnsFilterOrderBitsSWBTCX20(const Word16 value, const Word16 index); +Word16 GetTnsFilterOrderBitsSWBTCX20( const Word16 value, const Word16 index ); -Word16 EncodeTnsFilterOrderSWBTCX20(const Word16 value, const Word16 index); +Word16 EncodeTnsFilterOrderSWBTCX20( const Word16 value, const Word16 index ); -Word16 DecodeTnsFilterOrderSWBTCX20(Decoder_State *st, const Word16 index, Word16 * pValue); +Word16 DecodeTnsFilterOrderSWBTCX20( Decoder_State *st, const Word16 index, Word16 *pValue ); -Word16 GetTnsFilterOrderBitsSWBTCX10(const Word16 value, const Word16 index); +Word16 GetTnsFilterOrderBitsSWBTCX10( const Word16 value, const Word16 index ); -Word16 EncodeTnsFilterOrderSWBTCX10(const Word16 value, const Word16 index); +Word16 EncodeTnsFilterOrderSWBTCX10( const Word16 value, const Word16 index ); -Word16 DecodeTnsFilterOrderSWBTCX10(Decoder_State *st, const Word16 index, Word16 * pValue); +Word16 DecodeTnsFilterOrderSWBTCX10( Decoder_State *st, const Word16 index, Word16 *pValue ); -Word16 GetTnsFilterOrderBits(const Word16 value, const Word16 index); +Word16 GetTnsFilterOrderBits( const Word16 value, const Word16 index ); -Word16 EncodeTnsFilterOrder(const Word16 value, const Word16 index); +Word16 EncodeTnsFilterOrder( const Word16 value, const Word16 index ); -Word16 DecodeTnsFilterOrder(Decoder_State *st, const Word16 index, Word16 * pValue); +Word16 DecodeTnsFilterOrder( Decoder_State *st, const Word16 index, Word16 *pValue ); -void const * GetNumOfTnsFilters(void const * p, const Word16 index, Word16 * pValue); +void const *GetNumOfTnsFilters( void const *p, const Word16 index, Word16 *pValue ); -void * SetNumOfTnsFilters(void * p, const Word16 index, Word16 value); +void *SetNumOfTnsFilters( void *p, const Word16 index, Word16 value ); -void const * GetTnsEnabled(void const * p, const Word16 index, Word16 * pValue); +void const *GetTnsEnabled( void const *p, const Word16 index, Word16 *pValue ); -void * SetTnsEnabled(void * p, const Word16 index, const Word16 value); +void *SetTnsEnabled( void *p, const Word16 index, const Word16 value ); -void const * GetTnsEnabledSingleFilter(void const * p, const Word16 index, Word16 * pValue); +void const *GetTnsEnabledSingleFilter( void const *p, const Word16 index, Word16 *pValue ); -void * SetTnsEnabledSingleFilter(void * p, const Word16 index, const Word16 value); +void *SetTnsEnabledSingleFilter( void *p, const Word16 index, const Word16 value ); /*tns_base.h*/ /** Reset TNS data. * Resets TNS data to the initial state. * @param pTnsData pointer to a TNS data to be reset. */ -void ResetTnsData(STnsData * pTnsData); +void ResetTnsData( STnsData *pTnsData ); /** Clear TNS filter data. * Resets TNS filter order and all coefficients to 0. * @param pTnsFilter pointer to a TNS filter to be cleared. */ -void ClearTnsFilterCoefficients(STnsFilter * pTnsFilter); +void ClearTnsFilterCoefficients( STnsFilter *pTnsFilter ); /*========================================================================================================/ gp_clips_fx.c /========================================================================================================*/ void init_gp_clip_fx( - Word16 mem[] /* o : memory of gain of pitch clipping algorithm */ + Word16 mem[] /* o : memory of gain of pitch clipping algorithm */ ); Word16 gp_clip_fx( - const Word16 element_mode, /* i : element mode */ - const Word32 core_brate, /* i : core bitrate */ - const Word16* voicing, /* i : normalized correlations (from OL pitch) */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 coder_type, /* i : type of coder */ - const Word16 xn[], /* i : target vector */ - Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm */ - const Word16 Q_new /* i : scaling factor */ + const Word16 element_mode, /* i : element mode */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 *voicing, /* i : normalized correlations (from OL pitch) */ + const Word16 i_subfr, /* i : subframe index */ + const Word16 coder_type, /* i : type of coder */ + const Word16 xn[], /* i : target vector */ + Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm */ + const Word16 Q_new /* i : scaling factor */ ); void gp_clip_test_isf_fx( - const Word16 element_mode, /* i : element mode */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 isf[], /* i : isf values (in frequency domain) */ - Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm */ - const Word16 Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ + const Word16 element_mode, /* i : element mode */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 isf[], /* i : isf values (in frequency domain) */ + Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm */ + const Word16 Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ ); void gp_clip_test_gain_pit_fx( - const Word16 element_mode, /* i : element mode */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 gain_pit, /* i : gain of quantized pitch Q14 */ - Word16 mem[] /* i/o: memory of gain of pitch clipping algorithm 1Q14 */ + const Word16 element_mode, /* i : element mode */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 gain_pit, /* i : gain of quantized pitch Q14 */ + Word16 mem[] /* i/o: memory of gain of pitch clipping algorithm 1Q14 */ ); Word16 Mode2_gp_clip( - const Word16 *voicing, /* i : normalized correlations (from OL pitch) */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 coder_type, /* i : type of coder */ - const Word16 xn[], /* i : target vector */ - Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm */ - const Word16 L_subfr, - const Word16 Q_xn /* i : xn data format */ + const Word16 *voicing, /* i : normalized correlations (from OL pitch) */ + const Word16 i_subfr, /* i : subframe index */ + const Word16 coder_type, /* i : type of coder */ + const Word16 xn[], /* i : target vector */ + Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm */ + const Word16 L_subfr, + const Word16 Q_xn /* i : xn data format */ ); void gp_clip_test_lsf_fx( - const Word16 element_mode, /* i : element mode */ - const Word16 lsf[], /* i : lsf values (in frequency domain) 14Q1*1.28 */ - Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm */ - const Word16 m /* i : dimension of lsf */ + const Word16 element_mode, /* i : element mode */ + const Word16 lsf[], /* i : lsf values (in frequency domain) 14Q1*1.28 */ + Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm */ + const Word16 m /* i : dimension of lsf */ ); /*========================================================================================================/ @@ -3453,48 +3370,46 @@ nelp_enc_fx.c /========================================================================================================*/ void quantize_uvg_fx( - Word16 *G, - Word16 *iG1, - Word16 *iG2, - Word16 *quantG, - Word16 bandwidth -); + Word16 *G, + Word16 *iG1, + Word16 *iG2, + Word16 *quantG, + Word16 bandwidth ); void nelp_encoder_fx( - Encoder_State *st_fx, /* i/o: encoder state */ - Word16 *in_fx, /* i : residual signal */ - Word16 *exc_fx, /* o : NELP quantized excitation signal */ - Word16 *qIn1 - , Word16 reduce_gains -); + Encoder_State *st_fx, /* i/o: encoder state */ + Word16 *in_fx, /* i : residual signal */ + Word16 *exc_fx, /* o : NELP quantized excitation signal */ + Word16 *qIn1, + Word16 reduce_gains ); /*========================================================================================================/ swb_bwe_enc_lr_fx.c /========================================================================================================*/ void swb_bwe_enc_lr_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word32 L_m_core[], /* i : lowband synthesis */ - Word16 QsL, - const Word32 L_m_orig[], /* i/o: scaled orig signal (MDCT) */ - Word32 L_m[], /* o : highband synthesis with lowband zeroed */ - const Word32 L_total_brate, /* i : total bitrate for selecting subband pattern */ - Word16 BANDS_fx, /* i : Total number of Subbands in a frame */ - Word16 *band_start_fx, /* i : band start of each SB */ - Word16 *band_end_fx, /* i : band end of each SB */ - Word32 *L_band_energy, /* i : band_energy of each SB */ - Word16 Qbe, /* i : Q value of band energy */ - Word16 *p2a_flags_fx, /* i : HF tonal indicator */ - const Word16 hqswb_clas_fx, /* i : HQ_NORMAL2 or HQ_HARMONIC mode */ - Word16 lowlength_fx, /* i : lowband length */ - Word16 highlength_fx, /* i : highband length */ - Word16 *prev_frm_index_fx, /* i/o: previous frame lag index for harmonic mode */ - const Word16 har_bands_fx, /* i : Number of LF harmonic bands */ - Word16 *prev_frm_hfe2, /* i/o: */ - Word16 *prev_stab_hfe2, /* i/o: */ - const Word16 band_width_fx[], /* i : band_width information */ - const Word32 L_y2_ni[], /* i : band_width information */ - Word16 *ni_seed_fx /* i/o: random seed for search buffer NI */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word32 L_m_core[], /* i : lowband synthesis */ + Word16 QsL, + const Word32 L_m_orig[], /* i/o: scaled orig signal (MDCT) */ + Word32 L_m[], /* o : highband synthesis with lowband zeroed */ + const Word32 L_total_brate, /* i : total bitrate for selecting subband pattern */ + Word16 BANDS_fx, /* i : Total number of Subbands in a frame */ + Word16 *band_start_fx, /* i : band start of each SB */ + Word16 *band_end_fx, /* i : band end of each SB */ + Word32 *L_band_energy, /* i : band_energy of each SB */ + Word16 Qbe, /* i : Q value of band energy */ + Word16 *p2a_flags_fx, /* i : HF tonal indicator */ + const Word16 hqswb_clas_fx, /* i : HQ_NORMAL2 or HQ_HARMONIC mode */ + Word16 lowlength_fx, /* i : lowband length */ + Word16 highlength_fx, /* i : highband length */ + Word16 *prev_frm_index_fx, /* i/o: previous frame lag index for harmonic mode */ + const Word16 har_bands_fx, /* i : Number of LF harmonic bands */ + Word16 *prev_frm_hfe2, /* i/o: */ + Word16 *prev_stab_hfe2, /* i/o: */ + const Word16 band_width_fx[], /* i : band_width information */ + const Word32 L_y2_ni[], /* i : band_width information */ + Word16 *ni_seed_fx /* i/o: random seed for search buffer NI */ ); /*========================================================================================================/ @@ -3502,10 +3417,10 @@ isf_enc_amr_wb_fx.c /========================================================================================================*/ void isf_enc_amr_wb_fx( - Encoder_State* st, /* i/o: state structure */ - Word16* isf_new, /* i/o: quantized ISF vector */ - Word16* isp_new, /* i/o: ISP vector to quantize/quantized */ - Word16* Aq /* o : quantized A(z) for 4 subframes */ + Encoder_State *st, /* i/o: state structure */ + Word16 *isf_new, /* i/o: quantized ISF vector */ + Word16 *isp_new, /* i/o: ISP vector to quantize/quantized */ + Word16 *Aq /* o : quantized A(z) for 4 subframes */ ); /*========================================================================================================/ @@ -3513,33 +3428,30 @@ detect_transient_fx.c /========================================================================================================*/ Word16 detect_transient_fx( - const Word16 *in_fx, /*Q_new */ - const Word16 L, - Word16 Q_new, - Encoder_State *st_fx -); + const Word16 *in_fx, /*Q_new */ + const Word16 L, + Word16 Q_new, + Encoder_State *st_fx ); /*========================================================================================================/ codec_tcx_common.c /========================================================================================================*/ Word16 tcxGetNoiseFillingTilt( - const Word16 A[], - const Word16 lpcorder, - const Word16 L_frame, - const Word16 mode, - Word16* noiseTiltFactor -); + const Word16 A[], + const Word16 lpcorder, + const Word16 L_frame, + const Word16 mode, + Word16 *noiseTiltFactor ); void tcxFormantEnhancement( - Word16 xn_buf[], - const Word16 gainlpc[], - const Word16 gainlpc_e[], - Word32 spectrum[], - Word16* spectrum_e, - const Word16 L_frame, - const Word16 L_frameTCX -); + Word16 xn_buf[], + const Word16 gainlpc[], + const Word16 gainlpc_e[], + Word32 spectrum[], + Word16 *spectrum_e, + const Word16 L_frame, + const Word16 L_frameTCX ); void tcxFormantEnhancement_with_shift( Word16 xn_buf[], @@ -3552,169 +3464,167 @@ void tcxFormantEnhancement_with_shift( const Word16 L_frameTCX ); void tcxInvertWindowGrouping( - TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */ - Word32 xn_buf[], - Word32 spectrum[], - const Word16 L_frame, - const Word8 fUseTns, - const Word16 last_core, - const Word16 index, - const Word16 frame_cnt, - const Word16 bfi -); - -//mslvq_com + TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */ + Word32 xn_buf[], + Word32 spectrum[], + const Word16 L_frame, + const Word8 fUseTns, + const Word16 last_core, + const Word16 index, + const Word16 frame_cnt, + const Word16 bfi ); + +// mslvq_com void permute_fx( - Word16 *pTmp1, /* i/o: vector whose components are to be permuted */ - const Word16 *perm /* i : permutation info (indexes that should be interchanged), max two perms */ + Word16 *pTmp1, /* i/o: vector whose components are to be permuted */ + const Word16 *perm /* i : permutation info (indexes that should be interchanged), max two perms */ ); void init_lvq_fx( - Word32 offset_scale1[][MAX_NO_SCALES + 1], - Word32 offset_scale2[][MAX_NO_SCALES + 1], - Word32 offset_scale1_p[][MAX_NO_SCALES + 1], - Word32 offset_scale2_p[][MAX_NO_SCALES + 1], - Word16 no_scales[][2], - Word16 no_scales_p[][2] -); + Word32 offset_scale1[][MAX_NO_SCALES + 1], + Word32 offset_scale2[][MAX_NO_SCALES + 1], + Word32 offset_scale1_p[][MAX_NO_SCALES + 1], + Word32 offset_scale2_p[][MAX_NO_SCALES + 1], + Word16 no_scales[][2], + Word16 no_scales_p[][2] ); Word16 deindex_lvq_fx( - Word16 *index, /* i : index to be decoded, as an array of 3 short */ - Word16 *x_lvq, /* o : decoded codevector Q(x2.56)*/ - Word16 mode, /* i : LVQ coding mode (select scales & no_lead ), or idx_cv */ - Word16 sf_flag, /* i : safety net flag */ - Word16 no_bits, /* i : number of bits for lattice */ - Word32 *p_offset_scale1, /* i : offset for first subvector */ - Word32 *p_offset_scale2, /* i : offset for the second subvector */ - Word16 *p_no_scales -); + Word16 *index, /* i : index to be decoded, as an array of 3 short */ + Word16 *x_lvq, /* o : decoded codevector Q(x2.56)*/ + Word16 mode, /* i : LVQ coding mode (select scales & no_lead ), or idx_cv */ + Word16 sf_flag, /* i : safety net flag */ + Word16 no_bits, /* i : number of bits for lattice */ + Word32 *p_offset_scale1, /* i : offset for first subvector */ + Word32 *p_offset_scale2, /* i : offset for the second subvector */ + Word16 *p_no_scales ); Word16 deindex_lvq_ivas_fx( - Word16 *index, /* i : index to be decoded, as an array of 3 Word16 */ - Word16 *x_lvq, /* o : decoded codevector Q(x2.56) */ - Word16 mode, /* i : LVQ coding mode/MSLVQ structure index (select scales & no_lead ), or idx_cv for CNG case */ - Word16 sf_flag, /* i : safety net flag */ - Word16 no_bits /* i : number of bits for lattice */ + Word16 *index, /* i : index to be decoded, as an array of 3 Word16 */ + Word16 *x_lvq, /* o : decoded codevector Q(x2.56) */ + Word16 mode, /* i : LVQ coding mode/MSLVQ structure index (select scales & no_lead ), or idx_cv for CNG case */ + Word16 sf_flag, /* i : safety net flag */ + Word16 no_bits /* i : number of bits for lattice */ ); Word16 deindex_lvq_cng_fx( - Word16 *index, /* i : index to be decoded, as an array of 3 short */ - Word16 *x_lvq, /* o : decoded codevector Q9*/ - Word16 idx_cv, /* i : relative mode_lvq, wrt START_CNG */ - Word16 no_bits, /* i : number of bits for lattice */ - Word32 * p_offset_scale1, - Word32 * p_offset_scale2, - Word16 * p_no_scales -); + Word16 *index, /* i : index to be decoded, as an array of 3 short */ + Word16 *x_lvq, /* o : decoded codevector Q9*/ + Word16 idx_cv, /* i : relative mode_lvq, wrt START_CNG */ + Word16 no_bits, /* i : number of bits for lattice */ + Word32 *p_offset_scale1, + Word32 *p_offset_scale2, + Word16 *p_no_scales ); Word16 deindex_lvq_cng_ivas_fx( - Word16 *index, /* i: index to be decoded, as an array of 3 short */ - Word16 *x_lvq, /* o: decoded codevector Q9 */ - Word16 idx_cv, /* i: relative mode_lvq, wrt START_CNG */ - Word16 no_bits /* i: number of bits for lattice */ + Word16 *index, /* i: index to be decoded, as an array of 3 short */ + Word16 *x_lvq, /* o: decoded codevector Q9 */ + Word16 idx_cv, /* i: relative mode_lvq, wrt START_CNG */ + Word16 no_bits /* i: number of bits for lattice */ ); -//lsp_convert_poly_fx.c +// lsp_convert_poly_fx.c Word16 lsp_convert_poly_fx( - Word16 w[], /* i/o: LSP or ISP parameters */ - const Word16 L_frame, /* i : flag for up or down conversion */ - const Word16 Opt_AMRWB /* i : flag for the AMR-WB IO mode */ + Word16 w[], /* i/o: LSP or ISP parameters */ + const Word16 L_frame, /* i : flag for up or down conversion */ + const Word16 Opt_AMRWB /* i : flag for the AMR-WB IO mode */ ); -//cng_exe.c +// cng_exe.c void CNG_exc_fx( - const Word32 core_brate, /* i : core bitrate */ - const Word16 L_frame, /* i : length of the frame */ - Word32* Enew, /* i/o: decoded SID energy Q6 */ - Word16* seed, /* i/o: random generator seed */ - Word16 exc[], /* o : current non-enhanced excitation Q_new */ - Word16 exc2[], /* o : current enhanced excitation Q_new */ - Word32* lp_ener, /* i/o: LP filtered E */ - const Word32 last_core_brate,/* i : previous frame core bitrate */ - Word16* first_CNG, /* i/o: first CNG frame flag for energy init. */ - Word16* cng_ener_seed, /* i/o: random generator seed for CNG energy */ - Word16 bwe_exc[], /* o : excitation for SWB TBE */ - const Word16 allow_cn_step, /* i : allow CN step */ - Word16* last_allow_cn_step, /* i/o: last allow step */ - const Word16 OldQ_exc, /* i : Old excitation scaling */ - const Word16 Q_exc, /* i : excitation scaling */ - const Word16 num_ho, /* i : number of selected hangover frames */ - Word32 q_env[], - Word32* lp_env, - Word32* old_env, - Word16* exc_mem, - Word16* exc_mem1, - Word16* sid_bw, - Word16* cng_ener_seed1, - Word16 exc3[], - Word16 Opt_AMR_WB, - const Word16 element_mode /* i : IVAS Element mode */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 L_frame, /* i : length of the frame */ + Word32 *Enew, /* i/o: decoded SID energy Q6 */ + Word16 *seed, /* i/o: random generator seed */ + Word16 exc[], /* o : current non-enhanced excitation Q_new */ + Word16 exc2[], /* o : current enhanced excitation Q_new */ + Word32 *lp_ener, /* i/o: LP filtered E */ + const Word32 last_core_brate, /* i : previous frame core bitrate */ + Word16 *first_CNG, /* i/o: first CNG frame flag for energy init. */ + Word16 *cng_ener_seed, /* i/o: random generator seed for CNG energy */ + Word16 bwe_exc[], /* o : excitation for SWB TBE */ + const Word16 allow_cn_step, /* i : allow CN step */ + Word16 *last_allow_cn_step, /* i/o: last allow step */ + const Word16 OldQ_exc, /* i : Old excitation scaling */ + const Word16 Q_exc, /* i : excitation scaling */ + const Word16 num_ho, /* i : number of selected hangover frames */ + Word32 q_env[], + Word32 *lp_env, + Word32 *old_env, + Word16 *exc_mem, + Word16 *exc_mem1, + Word16 *sid_bw, + Word16 *cng_ener_seed1, + Word16 exc3[], + Word16 Opt_AMR_WB, + const Word16 element_mode /* i : IVAS Element mode */ ); void cng_params_postupd_fx( - const Word16 ho_circ_ptr, /* i : pointer for CNG averaging buffers Q0 */ - Word16 *cng_buf_cnt, /* i/o: counter for CNG store buffers Q0 */ - const Word16 *const cng_exc2_buf, /* i : Excitation buffer Q_exc */ - const Word16 *const cng_Qexc_buf, /* i : Q_exc buffer Q0 */ - const Word32 *const cng_brate_buf, /* i : bit rate buffer Q0 */ - Word32 ho_env_circ[] /* i/o: Envelope buffer */ + const Word16 ho_circ_ptr, /* i : pointer for CNG averaging buffers Q0 */ + Word16 *cng_buf_cnt, /* i/o: counter for CNG store buffers Q0 */ + const Word16 *const cng_exc2_buf, /* i : Excitation buffer Q_exc */ + const Word16 *const cng_Qexc_buf, /* i : Q_exc buffer Q0 */ + const Word32 *const cng_brate_buf, /* i : bit rate buffer Q0 */ + Word32 ho_env_circ[] /* i/o: Envelope buffer */ ); void cng_params_upd_fx( - const Word16 lsp_new[], /* i : LSP parameters Q15 */ - const Word16 exc2[], /* i : current enhanced excitation Q_exc */ - const Word16 L_frame, /* i : frame length Q0 */ - Word16 *ho_circ_ptr, /* i/o: pointer for CNG averaging buffers Q0 */ - Word32 ho_ener_circ[], /* o : energy buffer for CNG averaging Q6 */ - Word16 *ho_circ_size, /* i/o: size of DTX hangover history buffer for averaging Q0 */ - Word16 ho_lsp_circ[], /* o : old LSP buffer for CNG averaging Q15 */ - const Word16 Q_exc, /* i : Q value of excitation */ - const Word16 enc_dec_flag, /* i : Flag indicating encoder or decoder (ENC,DEC) */ - Word32 ho_env_circ[], /* i/o: Envelope buffer */ - Word16 *cng_buf_cnt, /* i/o: Counter of postponed FFT-processing instances */ - Word16 cng_exc2_buf[], /* i/o: Excitation buffer Q_exc */ - Word16 cng_Qexc_buf[], /* i/o: Q_exc buffer Q0 */ - Word32 cng_brate_buf[], /* i/o: last_active_brate buffer Q0 */ - const Word32 last_active_brate /* i : Last active bit rate Q0 */ + const Word16 lsp_new[], /* i : LSP parameters Q15 */ + const Word16 exc2[], /* i : current enhanced excitation Q_exc */ + const Word16 L_frame, /* i : frame length Q0 */ + Word16 *ho_circ_ptr, /* i/o: pointer for CNG averaging buffers Q0 */ + Word32 ho_ener_circ[], /* o : energy buffer for CNG averaging Q6 */ + Word16 *ho_circ_size, /* i/o: size of DTX hangover history buffer for averaging Q0 */ + Word16 ho_lsp_circ[], /* o : old LSP buffer for CNG averaging Q15 */ + const Word16 Q_exc, /* i : Q value of excitation */ + const Word16 enc_dec_flag, /* i : Flag indicating encoder or decoder (ENC,DEC) */ + Word32 ho_env_circ[], /* i/o: Envelope buffer */ + Word16 *cng_buf_cnt, /* i/o: Counter of postponed FFT-processing instances */ + Word16 cng_exc2_buf[], /* i/o: Excitation buffer Q_exc */ + Word16 cng_Qexc_buf[], /* i/o: Q_exc buffer Q0 */ + Word32 cng_brate_buf[], /* i/o: last_active_brate buffer Q0 */ + const Word32 last_active_brate /* i : Last active bit rate Q0 */ ); void cng_params_upd_ivas_fx( - const Word16 lsp_new[], /* i : LSP aprameters Q15 */ - const Word16 exc2[], /* i : current enhanced excitation Q_exc */ - const Word16 L_frame, /* i : frame length Q0 */ - Word16 *ho_circ_ptr, /* i/o: pointer for CNG averaging buffers Q0 */ - Word32 ho_ener_circ[], /* o : energy buffer for CNG averaging Q6 */ - Word16 *ho_circ_size, /* i/o: size of DTX hangover history buffer for averaging Q0 */ - Word16 ho_lsp_circ[], /* o : old LSP buffer for CNG averaging Q15 */ - const Word16 Q_exc, /* i : Q value of excitation */ - const Word16 enc_dec_flag,/* i : Flag indicating encoder or decoder (ENC,DEC) */ - Word32 ho_env_circ[], /* i/o: Envelope buffer */ - Word16 *cng_buf_cnt, /* i/o: Counter of postponed FFT-processing instances */ - Word16 cng_exc2_buf[], /* i/o: Excitation buffer Q_exc */ - Word16 cng_Qexc_buf[], /* i/o: Q_exc buffer Q0 */ - Word32 cng_brate_buf[], /* i/o: last_active_brate buffer Q0 */ + const Word16 lsp_new[], /* i : LSP aprameters Q15 */ + const Word16 exc2[], /* i : current enhanced excitation Q_exc */ + const Word16 L_frame, /* i : frame length Q0 */ + Word16 *ho_circ_ptr, /* i/o: pointer for CNG averaging buffers Q0 */ + Word32 ho_ener_circ[], /* o : energy buffer for CNG averaging Q6 */ + Word16 *ho_circ_size, /* i/o: size of DTX hangover history buffer for averaging Q0 */ + Word16 ho_lsp_circ[], /* o : old LSP buffer for CNG averaging Q15 */ + const Word16 Q_exc, /* i : Q value of excitation */ + const Word16 enc_dec_flag, /* i : Flag indicating encoder or decoder (ENC,DEC) */ + Word32 ho_env_circ[], /* i/o: Envelope buffer */ + Word16 *cng_buf_cnt, /* i/o: Counter of postponed FFT-processing instances */ + Word16 cng_exc2_buf[], /* i/o: Excitation buffer Q_exc */ + Word16 cng_Qexc_buf[], /* i/o: Q_exc buffer Q0 */ + Word32 cng_brate_buf[], /* i/o: last_active_brate buffer Q0 */ const Word32 last_active_brate /* i : Last active bit rate Q0 */ - , const Word16 element_mode, /* i : Element mode */ - const Word16 bwidth /* i : Audio bandwidth */ + , + const Word16 element_mode, /* i : Element mode */ + const Word16 bwidth /* i : Audio bandwidth */ ); int16_t get_cng_mode( - const int32_t last_active_brate /* i : last active bitrate */ + const int32_t last_active_brate /* i : last active bitrate */ ); -//core_com_config.c +// core_com_config.c Word16 get_codec_mode( - const Word32 total_brate /* i : total bitrate */ + const Word32 total_brate /* i : total bitrate */ ); Word16 getTcxonly( #ifdef IVAS_CODE_SWITCHING - const Word16 element_mode, /* i : IVAS element mode */ + const Word16 element_mode, /* i : IVAS element mode */ #endif - const Word32 total_brate /* i : total bitrate */ + const Word32 total_brate /* i : total bitrate */ #ifdef IVAS_CODE_SWITCHING - , const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0)*/ - const int16_t is_ism_format /* i : flag indicating ISM format */ + , + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0)*/ + const int16_t is_ism_format /* i : flag indicating ISM format */ #endif ); @@ -3725,158 +3635,154 @@ Word16 getTcxonly_fx( const Word16 is_ism_format /* i : flag indicating ISM format */ ); Word16 getCtxHm( - const Word16 element_mode, /* i : IVAS element mode */ - const Word32 total_brate, /* i : total bitrate */ - const Word16 rf_flag /* i : flag to signal the RF mode */ + const Word16 element_mode, /* i : IVAS element mode */ + const Word32 total_brate, /* i : total bitrate */ + const Word16 rf_flag /* i : flag to signal the RF mode */ ); Word16 getResq( - const Word32 total_brate /* i : total bitrate */ + const Word32 total_brate /* i : total bitrate */ ); Word16 getTnsAllowed( - const Word32 total_brate, /* i : total bitrate */ - const Word16 igf, /* i : flag indicating IGF activity*/ - const Word16 element_mode /* i : IVAS element mode */ + const Word32 total_brate, /* i : total bitrate */ + const Word16 igf, /* i : flag indicating IGF activity*/ + const Word16 element_mode /* i : IVAS element mode */ ); int16_t getRestrictedMode( - const int16_t element_mode, /* i : IVAS element mode */ - const int32_t total_brate, /* i : total bitrate */ - const int16_t Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ + const int16_t element_mode, /* i : IVAS element mode */ + const int32_t total_brate, /* i : total bitrate */ + const int16_t Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ ); Word16 getMdctWindowLength_fx( - const Word16 fscale ); + const Word16 fscale ); Word16 sr2fscale_fx( -const Word32 sr_core /* i : internal sampling rate */ + const Word32 sr_core /* i : internal sampling rate */ ); Word32 getCoreSamplerateMode2( - const Word16 element_mode, /* i : IVAS element mode */ - const Word32 total_brate, /* i : total bitrate */ - const Word16 bwidth, /* i : audio bandwidth */ - const Word16 flag_ACELP16k, /* i : ACELP@16kHz flag */ - const Word16 rf_mode, /* i : flag to signal the RF mode */ - const IVAS_FORMAT is_ism_format /* i : flag indicating ISM format */ + const Word16 element_mode, /* i : IVAS element mode */ + const Word32 total_brate, /* i : total bitrate */ + const Word16 bwidth, /* i : audio bandwidth */ + const Word16 flag_ACELP16k, /* i : ACELP@16kHz flag */ + const Word16 rf_mode, /* i : flag to signal the RF mode */ + const IVAS_FORMAT is_ism_format /* i : flag indicating ISM format */ ); -Word16 getTcxBandwidth(const Word16 bandwidth); +Word16 getTcxBandwidth( const Word16 bandwidth ); Word16 getIgfPresent_fx( - const Word16 element_mode, /* i : IVAS element mode */ - const Word32 total_brate, /* i : total bitrate */ - const Word16 bwidth, /* i : audio bandwidth */ - const Word16 rf_mode /* i : flag to signal the RF mode */ + const Word16 element_mode, /* i : IVAS element mode */ + const Word32 total_brate, /* i : total bitrate */ + const Word16 bwidth, /* i : audio bandwidth */ + const Word16 rf_mode /* i : flag to signal the RF mode */ ); Word16 getCnaPresent_fx( - const Word16 element_mode, /* i : element mode */ - const Word32 element_brate, /* i : element bitrate */ - const Word32 total_brate, /* i : total bitrate */ - const Word16 bwidth /* i : audio bandwidth */ + const Word16 element_mode, /* i : element mode */ + const Word32 element_brate, /* i : element bitrate */ + const Word32 total_brate, /* i : total bitrate */ + const Word16 bwidth /* i : audio bandwidth */ ); Word16 getTcxLtp( - const Word32 sr_core /* i : internal sampling rate */ + const Word32 sr_core /* i : internal sampling rate */ ); Word16 initPitchLagParameters( - const Word32 sr_core, - Word16 *pit_min, - Word16 *pit_fr1, - Word16 *pit_fr1b, - Word16 *pit_fr2, - Word16 *pit_max -); + const Word32 sr_core, + Word16 *pit_min, + Word16 *pit_fr1, + Word16 *pit_fr1b, + Word16 *pit_fr2, + Word16 *pit_max ); -Word16 getNumTcxCodedLines(const Word16 bwidth); +Word16 getNumTcxCodedLines( const Word16 bwidth ); Word16 getTcxLpcShapedAri( - const Word32 total_brate, /* i : total bitrate */ - const Word16 rf_mode, /* i : flag to signal the RF mode */ - const Word16 element_mode /* i : IVAS element mode */ + const Word32 total_brate, /* i : total bitrate */ + const Word16 rf_mode, /* i : flag to signal the RF mode */ + const Word16 element_mode /* i : IVAS element mode */ ); -//tcx_mdct_window.c -void mdct_window_sine(PWord16 *window, Word16 n); +// tcx_mdct_window.c +void mdct_window_sine( PWord16 *window, Word16 n ); void mdct_window_sine_IVAS_updated( - PWord16 *window, - const int32_t Fs, - const int16_t n, - const int16_t window_type, - const int16_t element_mode); + PWord16 *window, + const int32_t Fs, + const int16_t n, + const int16_t window_type, + const int16_t element_mode ); void mdct_window_aldo( - Word16 *window1, - PWord16 *window1_trunc, - PWord16 *window2, - Word16 n -); + Word16 *window1, + PWord16 *window1_trunc, + PWord16 *window2, + Word16 n ); -//tcx_utils.c -Word16 getInvFrameLen(const Word16 L_frame); /* returns 1/L_frame in Q21 format */ +// tcx_utils.c +Word16 getInvFrameLen( const Word16 L_frame ); /* returns 1/L_frame in Q21 format */ void WindowSignal( - TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */ - Word16 offset, /* i : left folding point offset relative to the i signal pointer */ - const Word16 left_overlap_mode, /* i : overlap mode of left window half */ - Word16 right_overlap_mode, /* i : overlap mode of right window half */ - Word16* left_overlap_length, /* o : TCX window left overlap length */ - Word16* right_overlap_length, /* o : TCX window right overlap length */ - const Word16 in[], /* i : i signal */ - Word16* L_frame, /* i/o: frame length */ - Word16 out[], /* o : output windowed signal */ - const Word16 truncate_aldo, /* i : nonzero to truncate long ALDO slope */ - const Word8 fullband /* i : fullband flag */ + TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */ + Word16 offset, /* i : left folding point offset relative to the i signal pointer */ + const Word16 left_overlap_mode, /* i : overlap mode of left window half */ + Word16 right_overlap_mode, /* i : overlap mode of right window half */ + Word16 *left_overlap_length, /* o : TCX window left overlap length */ + Word16 *right_overlap_length, /* o : TCX window right overlap length */ + const Word16 in[], /* i : i signal */ + Word16 *L_frame, /* i/o: frame length */ + Word16 out[], /* o : output windowed signal */ + const Word16 truncate_aldo, /* i : nonzero to truncate long ALDO slope */ + const Word8 fullband /* i : fullband flag */ ); void tcx_windowing_synthesis_current_frame( - Word16* signal, /* i/o: signal vector */ - const PWord16* window, /* i: TCX window vector */ - const PWord16* window_half, /* i: TCX window vector for half-overlap window */ - const PWord16* window_min, /* i: TCX minimum overlap window */ - const Word16 window_length, /* i: TCX window length */ - const Word16 window_half_length, /* i: TCX half window length */ - const Word16 window_min_length, /* i: TCX minimum overlap length */ - const Word16 left_rect, /* i: left part is rectangular */ - const Word16 left_mode, /* i: overlap mode of left window half */ - Word16* acelp_zir, /* i: acelp ZIR */ - const Word16* old_syn, - const Word16* syn_overl, - const Word16* A_zir, - const PWord16* window_trans, - Word16 acelp_zir_len, - const Word16 acelp_mem_len, - const Word16 last_core_bfi, /* i : last core */ - const Word8 last_is_cng, - const Word16 fullbandScale -); + Word16 *signal, /* i/o: signal vector */ + const PWord16 *window, /* i: TCX window vector */ + const PWord16 *window_half, /* i: TCX window vector for half-overlap window */ + const PWord16 *window_min, /* i: TCX minimum overlap window */ + const Word16 window_length, /* i: TCX window length */ + const Word16 window_half_length, /* i: TCX half window length */ + const Word16 window_min_length, /* i: TCX minimum overlap length */ + const Word16 left_rect, /* i: left part is rectangular */ + const Word16 left_mode, /* i: overlap mode of left window half */ + Word16 *acelp_zir, /* i: acelp ZIR */ + const Word16 *old_syn, + const Word16 *syn_overl, + const Word16 *A_zir, + const PWord16 *window_trans, + Word16 acelp_zir_len, + const Word16 acelp_mem_len, + const Word16 last_core_bfi, /* i : last core */ + const Word8 last_is_cng, + const Word16 fullbandScale ); void tcx_windowing_synthesis_past_frame( - Word16 *signal, /* i/o: signal vector */ - const PWord16 *window, /* i: TCX window vector */ - const PWord16 *window_half, /* i: TCX window vector for half-overlap window */ - const PWord16 *window_min, /* i: TCX minimum overlap window */ - const Word16 window_length, /* i: TCX window length */ - const Word16 window_half_length, /* i: TCX half window length */ - const Word16 window_min_length, /* i: TCX minimum overlap length */ - const Word16 right_mode /* i: overlap mode (left_mode of current frame) */ + Word16 *signal, /* i/o: signal vector */ + const PWord16 *window, /* i: TCX window vector */ + const PWord16 *window_half, /* i: TCX window vector for half-overlap window */ + const PWord16 *window_min, /* i: TCX minimum overlap window */ + const Word16 window_length, /* i: TCX window length */ + const Word16 window_half_length, /* i: TCX half window length */ + const Word16 window_min_length, /* i: TCX minimum overlap length */ + const Word16 right_mode /* i: overlap mode (left_mode of current frame) */ ); void lpc2mdct( - Word16* lpcCoeffs, - const Word16 lpcOrder, - Word16* mdct_gains, - Word16* mdct_gains_exp, - Word16* mdct_inv_gains, - Word16* mdct_inv_gains_exp, - const Word16 length, - const Word16 noInverse -); + Word16 *lpcCoeffs, + const Word16 lpcOrder, + Word16 *mdct_gains, + Word16 *mdct_gains_exp, + Word16 *mdct_inv_gains, + Word16 *mdct_inv_gains_exp, + const Word16 length, + const Word16 noInverse ); void lpc2mdct_2( Word16 *lpcCoeffs, @@ -3888,65 +3794,57 @@ void lpc2mdct_2( const int16_t length ); void mdct_shaping( - Word32 x[], - const Word16 lg, - const Word16 gains[], - const Word16 gains_exp[] -); + Word32 x[], + const Word16 lg, + const Word16 gains[], + const Word16 gains_exp[] ); void mdct_shaping_16( - const Word16 x[], - const Word16 lg, - const Word16 lg_total, - const Word16 gains[], - const Word16 gains_exp[], - Word16 gains_max_exp, Word32 y[] -); + const Word16 x[], + const Word16 lg, + const Word16 lg_total, + const Word16 gains[], + const Word16 gains_exp[], + Word16 gains_max_exp, + Word32 y[] ); void mdct_noiseShaping_ivas_fx( Word32 x_fx[], Word16 *x_e, const Word16 lg, const Word16 gains_fx[], - const Word16 gains_exp[] -); + const Word16 gains_exp[] ); void mdct_noiseShaping_interp( - Word32 x[], - const Word16 lg, - Word16 gains[], - Word16 gains_exp[] -); + Word32 x[], + const Word16 lg, + Word16 gains[], + Word16 gains_exp[] ); -void PsychAdaptLowFreqDeemph(Word32 x[], - const Word16 lpcGains[], const Word16 lpcGains_e[], - Word16 lf_deemph_factors[] -); +void PsychAdaptLowFreqDeemph( Word32 x[], + const Word16 lpcGains[], + const Word16 lpcGains_e[], + Word16 lf_deemph_factors[] ); -void AdaptLowFreqDeemph(Word32 x[], Word16 x_e, - Word16 tcx_lpc_shaped_ari, - Word16 lpcGains[], Word16 lpcGains_e[], - const Word16 lg, - Word16 lf_deemph_factors[] -); +void AdaptLowFreqDeemph( Word32 x[], Word16 x_e, Word16 tcx_lpc_shaped_ari, Word16 lpcGains[], Word16 lpcGains_e[], const Word16 lg, Word16 lf_deemph_factors[] ); void tcx_noise_filling( - Word32* Q, - Word16 Q_e, - Word16 seed, - const Word16 iFirstLine, - const Word16 lowpassLine, - const Word16 nTransWidth, - const Word16 L_frame, - const Word16 tiltCompFactor, - Word16 fac_ns, - Word16* infoTCXNoise, - const Word16 element_mode /* i : IVAS element mode */ + Word32 *Q, + Word16 Q_e, + Word16 seed, + const Word16 iFirstLine, + const Word16 lowpassLine, + const Word16 nTransWidth, + const Word16 L_frame, + const Word16 tiltCompFactor, + Word16 fac_ns, + Word16 *infoTCXNoise, + const Word16 element_mode /* i : IVAS element mode */ ); void tcx_noise_filling_with_shift( - Word32* Q, - Word16* Q_e, + Word32 *Q, + Word16 *Q_e, Word16 seed, const Word16 iFirstLine, const Word16 lowpassLine, @@ -3954,19 +3852,18 @@ void tcx_noise_filling_with_shift( const Word16 L_frame, const Word16 tiltCompFactor, Word16 fac_ns, - Word16* infoTCXNoise, + Word16 *infoTCXNoise, const Word16 element_mode /* i : IVAS element mode */ ); void InitTnsConfigs( - const Word16 bwidth, - const Word16 L_frame, - STnsConfig tnsConfig[2][2], - const Word16 igfStopFreq, - const Word32 total_brate, - const Word16 element_mode, - const Word16 is_mct -); + const Word16 bwidth, + const Word16 L_frame, + STnsConfig tnsConfig[2][2], + const Word16 igfStopFreq, + const Word32 total_brate, + const Word16 element_mode, + const Word16 is_mct ); #define IVAS_CODE_TCX_UTIL #ifdef IVAS_CODE_TCX_UTIL @@ -3977,123 +3874,111 @@ void SetAllowTnsOnWhite( #undef IVAS_CODE_TCX_UTIL void SetTnsConfig( - TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */ - const Word16 isTCX20, - const Word16 isAfterACELP -); + TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */ + const Word16 isTCX20, + const Word16 isAfterACELP ); -void tcx_get_gain(Word32 *x, /* i: spectrum 1 */ - Word16 x_e, /* i: spectrum 1 exponent */ - Word32 *y, /* i: spectrum 2 */ - Word16 y_e, /* i: spectrum 2 exponent */ - Word16 n, /* i: length */ - Word16 *gain, /* o: gain */ - Word16 *gain_e, /* o: gain exponent */ - Word32 *en_y, /* o: energy of y (optional) */ - Word16 *en_y_e /* o: energy of y exponent (optional) */ +void tcx_get_gain( Word32 *x, /* i: spectrum 1 */ + Word16 x_e, /* i: spectrum 1 exponent */ + Word32 *y, /* i: spectrum 2 */ + Word16 y_e, /* i: spectrum 2 exponent */ + Word16 n, /* i: length */ + Word16 *gain, /* o: gain */ + Word16 *gain_e, /* o: gain exponent */ + Word32 *en_y, /* o: energy of y (optional) */ + Word16 *en_y_e /* o: energy of y exponent (optional) */ ); void init_TCX_config( - TCX_CONFIG_HANDLE hTcxCfg, - Word16 L_frame, - Word16 fscale - , Word16 L_frameTCX - , Word16 fscaleFB -); + TCX_CONFIG_HANDLE hTcxCfg, + Word16 L_frame, + Word16 fscale, + Word16 L_frameTCX, + Word16 fscaleFB ); -//tec_com.c -void -resetTecDec_Fx( - TEC_DEC_HANDLE hTecDec -); +// tec_com.c +void resetTecDec_Fx( + TEC_DEC_HANDLE hTecDec ); void resetTecEnc_Fx( - TEC_ENC_HANDLE hTECEnc, - Word16 flag -); + TEC_ENC_HANDLE hTECEnc, + Word16 flag ); void calcGainTemp_TBE_Fx( - Word32** pCldfbRealSrc_Fx, - Word32** pCldfbImagSrc_Fx, - Word16 cldfb_exp, - Word16* loBuffer_Fx, - const Word16 startPos, /*!< Start position of the current envelope. */ - const Word16 stopPos, /*!< Stop position of the current envelope. */ - const Word16 lowSubband, /* lowSubband */ - Word16* pGainTemp_m, - Word16* pGainTemp_e, - const Word16 code -); - -Word16 procTecTfa_TBE_Fx(Word16 *hb_synth_Fx, - Word16 hb_synth_fx_exp, - Word16 *gain_m, - Word16 *gain_e, - Word16 flat_flag, - Word16 last_core - , Word16 l_subfr - , Word16 code -); + Word32 **pCldfbRealSrc_Fx, + Word32 **pCldfbImagSrc_Fx, + Word16 cldfb_exp, + Word16 *loBuffer_Fx, + const Word16 startPos, /*!< Start position of the current envelope. */ + const Word16 stopPos, /*!< Stop position of the current envelope. */ + const Word16 lowSubband, /* lowSubband */ + Word16 *pGainTemp_m, + Word16 *pGainTemp_e, + const Word16 code ); + +Word16 procTecTfa_TBE_Fx( Word16 *hb_synth_Fx, + Word16 hb_synth_fx_exp, + Word16 *gain_m, + Word16 *gain_e, + Word16 flat_flag, + Word16 last_core, + Word16 l_subfr, + Word16 code ); void calcHiEnvLoBuff_Fix( - const Word16 noCols, - const Word16* pFreqBandTable, /*!< freqbandTable. */ - const Word16 nSfb, /*!< Number of scalefactors. */ - Word32** pCldfbPow_Fix /*float** pCldfbPow*/, - Word16* loBuffer_Fix /*float* loBuffer Q8*/, - Word16* hiTempEnvOrig_Fix /*float* hiTempEnvOrig*/, - Word16 pCldfbPow_FixScale -); + const Word16 noCols, + const Word16 *pFreqBandTable, /*!< freqbandTable. */ + const Word16 nSfb, /*!< Number of scalefactors. */ + Word32 **pCldfbPow_Fix /*float** pCldfbPow*/, + Word16 *loBuffer_Fix /*float* loBuffer Q8*/, + Word16 *hiTempEnvOrig_Fix /*float* hiTempEnvOrig*/, + Word16 pCldfbPow_FixScale ); void calcLoEnvCheckCorrHiLo_Fix( - const Word16 noCols, - const Word16* pFreqBandTable, /*!< freqbandTable. */ - Word16* loBuffer_Fix /*float* loBuffer Q8*/, - Word16* loTempEnv_Fix /*float* loTempEnv Q7*/, - Word16* loTempEnv_ns_Fix /* float* loTempEnv_ns*/, - Word16* hiTempEnvOrig_Fix /*float* hiTempEnvOrig*/, - Word16* corrFlag /*int* corrFlag*/ + const Word16 noCols, + const Word16 *pFreqBandTable, /*!< freqbandTable. */ + Word16 *loBuffer_Fix /*float* loBuffer Q8*/, + Word16 *loTempEnv_Fix /*float* loTempEnv Q7*/, + Word16 *loTempEnv_ns_Fix /* float* loTempEnv_ns*/, + Word16 *hiTempEnvOrig_Fix /*float* hiTempEnvOrig*/, + Word16 *corrFlag /*int* corrFlag*/ ); void tecEnc_TBE_fx( - Word16* corrFlag, - const Word16* voicing, - const Word16 coder_type -); + Word16 *corrFlag, + const Word16 *voicing, + const Word16 coder_type ); -void set_TEC_TFA_code_fx(const Word16 corrFlag, Word16* tec_flag, Word16* tfa_flag); +void set_TEC_TFA_code_fx( const Word16 corrFlag, Word16 *tec_flag, Word16 *tfa_flag ); -//tcx_mdct_fx.c +// tcx_mdct_fx.c void TCX_MDCT( - const Word16* x, - Word32* y, - Word16* y_e, - const Word16 l, - const Word16 m, - const Word16 r, - const Word16 element_mode -); + const Word16 *x, + Word32 *y, + Word16 *y_e, + const Word16 l, + const Word16 m, + const Word16 r, + const Word16 element_mode ); void TCX_MDST( - const Word16* x, - Word32* y, - Word16* y_e, - const Word16 l, - const Word16 m, - const Word16 r, - const Word16 element_mode -); + const Word16 *x, + Word32 *y, + Word16 *y_e, + const Word16 l, + const Word16 m, + const Word16 r, + const Word16 element_mode ); void TCX_MDCT_Inverse( - Word32* x, - Word16 x_e, - Word16* y, - const Word16 l, - const Word16 m, - const Word16 r, - const Word16 element_mode -); + Word32 *x, + Word16 x_e, + Word16 *y, + const Word16 l, + const Word16 m, + const Word16 r, + const Word16 element_mode ); void TCX_MDST_Inverse_fx( Word32 *x, @@ -4112,35 +3997,34 @@ void TCX_MDXT_Inverse_fx( const Word16 r, const UWord16 kernel_type ); -//edct_fx.c +// edct_fx.c #define EDCT_FACTOR_SCALE 2 void edct_fx( - const Word32 *x, /* i : i signal Qq */ - Word32 *y, /* o : output transform Qq */ - Word16 length, /* i : length */ - Word16 *q /* i : Q value of i signal */ + const Word32 *x, /* i : i signal Qq */ + Word32 *y, /* o : output transform Qq */ + Word16 length, /* i : length */ + Word16 *q /* i : Q value of i signal */ ); void edst_fx( - const Word32 *x, /* i : i signal Qq */ - Word32 *y, /* o : output transform Qq */ - Word16 length, /* i : length */ - Word16 *q /* i : Q value of i signal */ + const Word32 *x, /* i : i signal Qq */ + Word32 *y, /* o : output transform Qq */ + Word16 length, /* i : length */ + Word16 *q /* i : Q value of i signal */ ); void edct_16fx( - const Word16 *x, /* i : i signal Qx */ - Word16 *y, /* o : output transform Qx */ - Word16 length, /* i : length */ - Word16 bh, /* bit-headroom */ - const Word16 element_mode -); + const Word16 *x, /* i : i signal Qx */ + Word16 *y, /* o : output transform Qx */ + Word16 length, /* i : length */ + Word16 bh, /* bit-headroom */ + const Word16 element_mode ); void iedct_short_fx( - const Word32 *in, /* i : i vector */ - Word16 *Q, /* i/o: Q value of i */ - Word32 *out, /* o : output vector */ - const Word16 segment_length /* i : length */ + const Word32 *in, /* i : i vector */ + Word16 *Q, /* i/o: Q value of i */ + Word32 *out, /* o : output vector */ + const Word16 segment_length /* i : length */ ); void edxt_fx( @@ -4151,16 +4035,16 @@ void edxt_fx( const UWord16 synthesis /* i : nonzero for inverse */ ); -//fft_evs.c -void fft16(Word32 *re, Word32 *im, Word16 s, Word16 bScale); -void BASOP_cfft(cmplx *pComplexBuf, Word16 sizeOfFft, Word16 *scale, Word32 workBuffer[2 * BASOP_CFFT_MAX_LENGTH]); -void BASOP_rfft(Word32 *x, Word16 sizeOfFft, Word16 *scale, Word16 isign); +// fft_evs.c +void fft16( Word32 *re, Word32 *im, Word16 s, Word16 bScale ); +void BASOP_cfft( cmplx *pComplexBuf, Word16 sizeOfFft, Word16 *scale, Word32 workBuffer[2 * BASOP_CFFT_MAX_LENGTH] ); +void BASOP_rfft( Word32 *x, Word16 sizeOfFft, Word16 *scale, Word16 isign ); -//fft_fx_evs.c +// fft_fx_evs.c void DoRTFTn_fx( - Word32 *x, /* i/o : real part of i and output data */ - Word32 *y, /* i/o : imaginary part of i and output data */ - const Word16 n /* i : size of the FFT up to 1024 */ + Word32 *x, /* i/o : real part of i and output data */ + Word32 *y, /* i/o : imaginary part of i and output data */ + const Word16 n /* i : size of the FFT up to 1024 */ ); void DoRTFT480_fx( @@ -4207,14 +4091,12 @@ Word16 RFFTN_fx( Word32 *data, const Word16 *sine_table, const Word16 len, - const Word16 sign -); + const Word16 sign ); void DoFFT_fx( Word32 *re2, Word32 *im2, - const Word16 length -); + const Word16 length ); void fft_fx( Word32 *re, /* i/o: real part */ @@ -4224,10 +4106,10 @@ void fft_fx( ); void rfft_fx( - Word32 *x, /* i/o: values */ - const Word16 *w, /* i : window */ - const Word16 length, /* i : length of fft */ - const Word16 isign /* i : sign */ + Word32 *x, /* i/o: values */ + const Word16 *w, /* i : window */ + const Word16 length, /* i : length of fft */ + const Word16 isign /* i : sign */ ); void DoRTFTn_fx_ivas( @@ -4236,10 +4118,10 @@ void DoRTFTn_fx_ivas( const Word16 n /* i : size of the FFT up to 1024 */ ); - -Word16 find_guarded_bits_fx(Word32 n); -Word16 L_norm_arr(Word32* arr, Word16 size); +Word16 find_guarded_bits_fx( Word32 n ); + +Word16 L_norm_arr( Word32 *arr, Word16 size ); Word16 get_min_scalefactor( Word32 x, Word32 y ); @@ -4249,33 +4131,31 @@ void edct2_fx_ivas( Word32 *in, Word32 *a, const Word16 *ip, - const Word16 *w -); + const Word16 *w ); void edct2_fx( - Word16 n, - Word16 isgn, - Word16 *in, - Word32 *a, - Word16 *q, - const Word16 *ip, - const Word16 *w -); + Word16 n, + Word16 isgn, + Word16 *in, + Word32 *a, + Word16 *q, + const Word16 *ip, + const Word16 *w ); void DoRTFT160_16fx( - Word16 x[], /* i/o : real part of i and output data */ - Word16 y[] /* i/o : imaginary part of i and output data */ + Word16 x[], /* i/o : real part of i and output data */ + Word16 y[] /* i/o : imaginary part of i and output data */ ); void DoRTFT320_16fx( - Word16 *x, /* i/o : real part of i and output data */ - Word16 *y /* i/o : imaginary part of i and output data */ + Word16 *x, /* i/o : real part of i and output data */ + Word16 *y /* i/o : imaginary part of i and output data */ ); void DoRTFT128_16fx( - Word16 *x, /* i/o : real part of i and output data Q(Qx+Q_edct)*/ - Word16 *y /* i/o : imaginary part of i and output data Q(Qx+Q_edct)*/ + Word16 *x, /* i/o : real part of i and output data Q(Qx+Q_edct)*/ + Word16 *y /* i/o : imaginary part of i and output data Q(Qx+Q_edct)*/ ); -void fft3_fx(const Word16[], Word16[], const Word16); -void ifft3_fx(const Word16[], Word16[], const Word16); +void fft3_fx( const Word16[], Word16[], const Word16 ); +void ifft3_fx( const Word16[], Word16[], const Word16 ); void fft3_fx_ivas( const Word32 X[], @@ -4286,557 +4166,543 @@ void ifft3_fx_ivas( Word32 Y[], const Word16 n ); -//fft_rel_fx.c +// fft_rel_fx.c void r_fft_fx_lc( - const Word16 *phs_tbl, /* i : Table of phase */ - const Word16 SIZE, /* i : Size of the FFT */ - const Word16 SIZE2, /* i : Size / 2 */ - const Word16 NUM_STAGE, /* i : Number of stage */ - const Word16 *in_ptr, /* i : coeffients in the order re[0], re[1], ... re[n/2], im[1], im[2], ..., im[n/2-1] */ - Word16 *out_ptr, /* o : coeffients in the order re[0], re[1], ... re[n/2], im[1], im[2], ..., im[n/2-1] */ - const Word16 isign /* i : 1=fft, otherwize it's ifft */ -); - -//cldfb_evs -void -cldfbAnalysisFiltering(HANDLE_CLDFB_FILTER_BANK anaCldfb, /*!< Handle of Cldfb Analysis Bank */ - Word32 **cldfbReal, /*!< Pointer to real subband slots */ - Word32 **cldfbImag, /*!< Pointer to imag subband slots */ - CLDFB_SCALE_FACTOR *scaleFactor, /*!< Scale factors of CLDFB data */ - const Word16 *timeIn, /*!< Time signal */ - const Word16 timeIn_e, /*!< Time signal */ - const Word16 nTimeSlots, /*!< Time slots to be processed */ - Word32 *pWorkBuffer /*!< pointer to temporal working buffer */ -); - -void -cldfbSynthesisFiltering(HANDLE_CLDFB_FILTER_BANK synCldfb, /*!< Handle of Cldfb Synthesis Bank */ - Word32 **CldfbBufferReal, /*!< Pointer to 32 bit real subband slots */ - Word32 **CldfbBufferImag, /*!< Pointer to 32 bit imag subband slots */ - const CLDFB_SCALE_FACTOR *scaleFactor, /*!< Scale factors of CLDFB data */ - Word16 *timeOut, /*!< Time signal */ - const Word16 timeOut_e, /*!< Target exponent for output signal */ - const Word16 nTimeSlots, /*!< number of time slots to be processed */ - Word32 *pWorkBuffer /*!< pointer to temporal working buffer */ -); - -void configureCldfb(HANDLE_CLDFB_FILTER_BANK h_cldfb, /*!< CLDFB Handle */ - const Word16 no_channels, /*!< Number of critically sampled bands */ - const Word16 frameSize /*!< FrameSize */ -); - -ivas_error openCldfb(HANDLE_CLDFB_FILTER_BANK *h_cldfb, /*!< CLDFB Handle */ - const Word16 type, /*!< analysis or synthesis */ - const Word16 maxCldfbBands, /*!< number of cldfb bands */ - const Word16 frameSize /*!< FrameSize */ + const Word16 *phs_tbl, /* i : Table of phase */ + const Word16 SIZE, /* i : Size of the FFT */ + const Word16 SIZE2, /* i : Size / 2 */ + const Word16 NUM_STAGE, /* i : Number of stage */ + const Word16 *in_ptr, /* i : coeffients in the order re[0], re[1], ... re[n/2], im[1], im[2], ..., im[n/2-1] */ + Word16 *out_ptr, /* o : coeffients in the order re[0], re[1], ... re[n/2], im[1], im[2], ..., im[n/2-1] */ + const Word16 isign /* i : 1=fft, otherwize it's ifft */ +); + +// cldfb_evs +void cldfbAnalysisFiltering( HANDLE_CLDFB_FILTER_BANK anaCldfb, /*!< Handle of Cldfb Analysis Bank */ + Word32 **cldfbReal, /*!< Pointer to real subband slots */ + Word32 **cldfbImag, /*!< Pointer to imag subband slots */ + CLDFB_SCALE_FACTOR *scaleFactor, /*!< Scale factors of CLDFB data */ + const Word16 *timeIn, /*!< Time signal */ + const Word16 timeIn_e, /*!< Time signal */ + const Word16 nTimeSlots, /*!< Time slots to be processed */ + Word32 *pWorkBuffer /*!< pointer to temporal working buffer */ +); + +void cldfbSynthesisFiltering( HANDLE_CLDFB_FILTER_BANK synCldfb, /*!< Handle of Cldfb Synthesis Bank */ + Word32 **CldfbBufferReal, /*!< Pointer to 32 bit real subband slots */ + Word32 **CldfbBufferImag, /*!< Pointer to 32 bit imag subband slots */ + const CLDFB_SCALE_FACTOR *scaleFactor, /*!< Scale factors of CLDFB data */ + Word16 *timeOut, /*!< Time signal */ + const Word16 timeOut_e, /*!< Target exponent for output signal */ + const Word16 nTimeSlots, /*!< number of time slots to be processed */ + Word32 *pWorkBuffer /*!< pointer to temporal working buffer */ +); + +void configureCldfb( HANDLE_CLDFB_FILTER_BANK h_cldfb, /*!< CLDFB Handle */ + const Word16 no_channels, /*!< Number of critically sampled bands */ + const Word16 frameSize /*!< FrameSize */ +); + +ivas_error openCldfb( HANDLE_CLDFB_FILTER_BANK *h_cldfb, /*!< CLDFB Handle */ + const Word16 type, /*!< analysis or synthesis */ + const Word16 maxCldfbBands, /*!< number of cldfb bands */ + const Word16 frameSize /*!< FrameSize */ ); void resampleCldfb( - HANDLE_CLDFB_FILTER_BANK hs, /*!< CLDFB Handle */ - const Word16 newCldfbBands, /*!< number of cldfb bands */ - const Word16 frameSize, /*!< FrameSize */ - const Word8 firstFrame -); + HANDLE_CLDFB_FILTER_BANK hs, /*!< CLDFB Handle */ + const Word16 newCldfbBands, /*!< number of cldfb bands */ + const Word16 frameSize, /*!< FrameSize */ + const Word8 firstFrame ); Word16 -AnalysisPostSpectrumScaling_Fx(HANDLE_CLDFB_FILTER_BANK cldfbBank, - Word32 **rSubband32, - Word32 **iSubband32, - Word16 **rSubband16, - Word16 **iSubband16, - Word16 *cldfbScale -); +AnalysisPostSpectrumScaling_Fx( HANDLE_CLDFB_FILTER_BANK cldfbBank, + Word32 **rSubband32, + Word32 **iSubband32, + Word16 **rSubband16, + Word16 **iSubband16, + Word16 *cldfbScale ); void analysisCldfbEncoder_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 *timeIn, - Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], - Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], - Word16 realBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], - Word16 imagBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], - Word32 enerBuffSum[CLDFB_NO_CHANNELS_MAX], - Word16 *enerBuffSum_exp, - CLDFB_SCALE_FACTOR * scale -); - -void -GetEnergyCldfb(Word32 *energyLookahead, /*!< o: Q31 | pointer to the result in the core look-ahead slot */ - Word16 *sf_energyLookahead, /*!< o: pointer to the scalefactor of the result in the core look-ahead slot - apply as negative exponent*/ - const Word16 numLookahead, /*!< i: Q0 the number of look-ahead time-slots */ - Word16 **realValues, /*!< i: Q15 | the real part of the CLDFB subsamples */ - Word16 **imagValues, /*!< i: Q15 | the imaginary part of the CLDFB subsamples */ - Word16 sf_Values, /*!< i: scalefactor of the CLDFB subcamples - apply as a negated Exponent */ - Word16 numberBands, /*!< i: Q0 | number of CLDFB bands */ - Word16 numberCols, /*!< i: Q0 | number of CLDFB subsamples */ - Word32 *energyHF, /*!< o: Q31 | pointer to HF energy */ - Word16 *energyHF_Exp, /*!< o: pointer to exponent of HF energy */ - Word32 *energyValuesSum, /*!< o: Q31 | pointer to sum array of energy values, not initialized*/ - Word16 *energyValuesSum_Exp, /*!< o: pointer to exponents of energyValuesSum, not initialized */ - TEC_ENC_HANDLE hTECEnc -); + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word16 *timeIn, + Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], + Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], + Word16 realBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], + Word16 imagBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], + Word32 enerBuffSum[CLDFB_NO_CHANNELS_MAX], + Word16 *enerBuffSum_exp, + CLDFB_SCALE_FACTOR *scale ); + +void GetEnergyCldfb( Word32 *energyLookahead, /*!< o: Q31 | pointer to the result in the core look-ahead slot */ + Word16 *sf_energyLookahead, /*!< o: pointer to the scalefactor of the result in the core look-ahead slot - apply as negative exponent*/ + const Word16 numLookahead, /*!< i: Q0 the number of look-ahead time-slots */ + Word16 **realValues, /*!< i: Q15 | the real part of the CLDFB subsamples */ + Word16 **imagValues, /*!< i: Q15 | the imaginary part of the CLDFB subsamples */ + Word16 sf_Values, /*!< i: scalefactor of the CLDFB subcamples - apply as a negated Exponent */ + Word16 numberBands, /*!< i: Q0 | number of CLDFB bands */ + Word16 numberCols, /*!< i: Q0 | number of CLDFB subsamples */ + Word32 *energyHF, /*!< o: Q31 | pointer to HF energy */ + Word16 *energyHF_Exp, /*!< o: pointer to exponent of HF energy */ + Word32 *energyValuesSum, /*!< o: Q31 | pointer to sum array of energy values, not initialized*/ + Word16 *energyValuesSum_Exp, /*!< o: pointer to exponents of energyValuesSum, not initialized */ + TEC_ENC_HANDLE hTECEnc ); Word16 -CLDFB_getNumChannels(Word32 sampleRate); +CLDFB_getNumChannels( Word32 sampleRate ); -void -deleteCldfb(HANDLE_CLDFB_FILTER_BANK * h_cldfb); /*!< CLDFB Handle */ +void deleteCldfb( HANDLE_CLDFB_FILTER_BANK *h_cldfb ); /*!< CLDFB Handle */ -ivas_error cldfb_save_memory(HANDLE_CLDFB_FILTER_BANK hs); /* i/o: cldfb handle */ -void cldfb_restore_memory(HANDLE_CLDFB_FILTER_BANK hs); /* i/o: cldfb handle */ -void cldfb_reset_memory(HANDLE_CLDFB_FILTER_BANK hs); /* i/o: cldfb handle */ +ivas_error cldfb_save_memory( HANDLE_CLDFB_FILTER_BANK hs ); /* i/o: cldfb handle */ +void cldfb_restore_memory( HANDLE_CLDFB_FILTER_BANK hs ); /* i/o: cldfb handle */ +void cldfb_reset_memory( HANDLE_CLDFB_FILTER_BANK hs ); /* i/o: cldfb handle */ -//bits_alloc.c from IVAS +// bits_alloc.c from IVAS void BITS_ALLOC_init_config_acelp( - const Word32 bit_rate, - const Word16 narrowBand, - const Word16 nb_subfr, - ACELP_config *pConfigAcelp /*o: configuration structure of ACELP*/ + const Word32 bit_rate, + const Word16 narrowBand, + const Word16 nb_subfr, + ACELP_config *pConfigAcelp /*o: configuration structure of ACELP*/ ); Word16 BITS_ALLOC_config_acelp( - const Word16 bits_frame, /*i: remaining bit budget for the frame */ - const Word16 coder_type, /*i: coder type */ - ACELP_config *pConfigAcelp, /*i/o: configuration structure of ACELP*/ - const Word16 narrowband, - const Word16 nb_subfr -); + const Word16 bits_frame, /*i: remaining bit budget for the frame */ + const Word16 coder_type, /*i: coder type */ + ACELP_config *pConfigAcelp, /*i/o: configuration structure of ACELP*/ + const Word16 narrowband, + const Word16 nb_subfr ); ivas_error config_acelp1( - const Word16 enc_dec, /* i : encoder/decoder flag */ - const Word32 total_brate, /* i : total bitrate */ - const Word32 core_brate_inp, /* i : core bitrate */ - const Word16 core, /* i : core */ - const Word16 extl, /* i : extension layer */ - const Word32 extl_brate, /* i : extension layer bitrate */ - const Word16 L_frame, /* i : frame length at internal Fs */ - const Word16 GSC_noisy_speech, /* i : GSC on SWB noisy speech flag */ - ACELP_config* acelp_cfg, /* i : ACELP bit-allocation */ - const Word16 signalling_bits, /* i : number of signalling bits */ - const Word16 coder_type, /* i : coder type */ - const Word16 tc_subfr, /* i : TC subfr ID */ - const Word16 tc_call, /* i : TC call number (0,1,2,3,5(DEC)) */ - Word16* nBits_es_Pred, /* o : number of bits for Es_pred Q */ - Word16* unbits, /* o : number of unused bits */ - const Word16 element_mode, /* i : element mode */ - Word16* uc_two_stage_flag, /* o : flag undicating two-stage UC */ - const Word16 tdm_lp_reuse_flag, /* i : LPC reuse flag (can be 1 only with secondary channel */ - const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag */ - const Word16 idchan, /* i : stereo channel ID */ - const Word16 active_cnt, /* i : Active frame counter */ - const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag*/ - const Word16 tdm_LRTD_flag, /* i : LRTD stereo mode flag */ - const Word16 GSC_IVAS_mode /* i : GSC IVAS mode */ + const Word16 enc_dec, /* i : encoder/decoder flag */ + const Word32 total_brate, /* i : total bitrate */ + const Word32 core_brate_inp, /* i : core bitrate */ + const Word16 core, /* i : core */ + const Word16 extl, /* i : extension layer */ + const Word32 extl_brate, /* i : extension layer bitrate */ + const Word16 L_frame, /* i : frame length at internal Fs */ + const Word16 GSC_noisy_speech, /* i : GSC on SWB noisy speech flag */ + ACELP_config *acelp_cfg, /* i : ACELP bit-allocation */ + const Word16 signalling_bits, /* i : number of signalling bits */ + const Word16 coder_type, /* i : coder type */ + const Word16 tc_subfr, /* i : TC subfr ID */ + const Word16 tc_call, /* i : TC call number (0,1,2,3,5(DEC)) */ + Word16 *nBits_es_Pred, /* o : number of bits for Es_pred Q */ + Word16 *unbits, /* o : number of unused bits */ + const Word16 element_mode, /* i : element mode */ + Word16 *uc_two_stage_flag, /* o : flag undicating two-stage UC */ + const Word16 tdm_lp_reuse_flag, /* i : LPC reuse flag (can be 1 only with secondary channel */ + const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag */ + const Word16 idchan, /* i : stereo channel ID */ + const Word16 active_cnt, /* i : Active frame counter */ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag*/ + const Word16 tdm_LRTD_flag, /* i : LRTD stereo mode flag */ + const Word16 GSC_IVAS_mode /* i : GSC IVAS mode */ ); Word16 set_ACELP_flag( - const Word16 element_mode, /* i : element mode */ - const Word32 element_brate, /* i : element bitrate */ - const Word32 total_brate, /* i : total bitrate per channel */ - const Word16 idchan, /* i : Channel id */ - const Word16 tdm_LRTD_flag, /* i : LRTD stereo mode flag */ - const Word16 bwidth, /* i : audio bandwidth */ - const Word16 cng_type /* i : CNG type */ -); -//syn_128_fx.c + const Word16 element_mode, /* i : element mode */ + const Word32 element_brate, /* i : element bitrate */ + const Word32 total_brate, /* i : total bitrate per channel */ + const Word16 idchan, /* i : Channel id */ + const Word16 tdm_LRTD_flag, /* i : LRTD stereo mode flag */ + const Word16 bwidth, /* i : audio bandwidth */ + const Word16 cng_type /* i : CNG type */ +); +// syn_128_fx.c void syn_12k8_fx( - Word16 L_frame, - const Word16 *Aq, /* i : LP filter coefficients Q12 */ - const Word16 *exc, /* i : i signal Q_exc */ - Word16 *synth, /* o : output signal Q_syn */ - Word16 *mem, /* i/o: initial filter states Q_syn */ - const Word16 update_m, /* i : update memory flag: 0 --> no memory update Q0 */ - /* 1 --> update of memory */ - const Word16 Q_exc, /* i : Excitation scaling Q0 */ - const Word16 Q_syn /* i : Synthesis scaling Q0 */ -); -//est_tilt_fx.c + Word16 L_frame, + const Word16 *Aq, /* i : LP filter coefficients Q12 */ + const Word16 *exc, /* i : i signal Q_exc */ + Word16 *synth, /* o : output signal Q_syn */ + Word16 *mem, /* i/o: initial filter states Q_syn */ + const Word16 update_m, /* i : update memory flag: 0 --> no memory update Q0 */ + /* 1 --> update of memory */ + const Word16 Q_exc, /* i : Excitation scaling Q0 */ + const Word16 Q_syn /* i : Synthesis scaling Q0 */ +); +// est_tilt_fx.c Word16 est_tilt_fx( /* o : tilt of the code Q15 */ - const Word16 *exc, /* i : adaptive excitation vector Qx */ - const Word16 gain_pit, /* i : adaptive gain Q14 */ - const Word16 *code, /* i : algebraic exctitation vector Q9 */ - const Word32 gain_code, /* i : algebraic code gain Q16 */ - Word16 *voice_fac, /* o : voicing factor Q15 */ - const Word16 Q_exc /* i : Scaling factor of excitation Q0 */ + const Word16 *exc, /* i : adaptive excitation vector Qx */ + const Word16 gain_pit, /* i : adaptive gain Q14 */ + const Word16 *code, /* i : algebraic exctitation vector Q9 */ + const Word32 gain_code, /* i : algebraic code gain Q16 */ + Word16 *voice_fac, /* o : voicing factor Q15 */ + const Word16 Q_exc /* i : Scaling factor of excitation Q0 */ #ifdef ADD_LRTD - , const Word16 L_subfr /* i : Sub frame lenght */ + , + const Word16 L_subfr /* i : Sub frame lenght */ #endif ); -Word16 est_tilt_ivas_fx( /* o : tilt of the code Q15 */ - const Word16 *exc, /* i : adaptive excitation vector Qx */ - const Word16 gain_pit, /* i : adaptive gain Q14 */ - const Word16 *code, /* i : algebraic excitation vector Q9 */ - const Word32 gain_code, /* i : algebraic code gain Q16 */ - Word16 *voice_fac, /* o : voicing factor Q15 */ - const Word16 Q_exc /* i : Scaling factor of excitation Q0 */ -#if 1//def ADD_LRTD - , const Word16 L_subfr, /* i : Sub frame length */ - const Word16 flag_tilt /* i : flag for special tilt */ +Word16 est_tilt_ivas_fx( /* o : tilt of the code Q15 */ + const Word16 *exc, /* i : adaptive excitation vector Qx */ + const Word16 gain_pit, /* i : adaptive gain Q14 */ + const Word16 *code, /* i : algebraic excitation vector Q9 */ + const Word32 gain_code, /* i : algebraic code gain Q16 */ + Word16 *voice_fac, /* o : voicing factor Q15 */ + const Word16 Q_exc /* i : Scaling factor of excitation Q0 */ +#if 1 // def ADD_LRTD + , + const Word16 L_subfr, /* i : Sub frame length */ + const Word16 flag_tilt /* i : flag for special tilt */ #endif ); -Word16 Est_tilt2( /* o : tilt of the code */ - const Word16 *exc, /* i : adaptive excitation vector Qx */ - const Word16 gain_pit, /* i : adaptive gain Q14 */ - const Word16 *code, /* i : algebraic exctitation vector Q9 */ - const Word32 gain_code, /* i : algebraic code gain Q16 */ - Word16 *voice_fac, /* o : voicing factor Q15 */ - const Word16 Q_exc /* i : Scaling factor of excitation Q0 */ +Word16 Est_tilt2( /* o : tilt of the code */ + const Word16 *exc, /* i : adaptive excitation vector Qx */ + const Word16 gain_pit, /* i : adaptive gain Q14 */ + const Word16 *code, /* i : algebraic exctitation vector Q9 */ + const Word32 gain_code, /* i : algebraic code gain Q16 */ + Word16 *voice_fac, /* o : voicing factor Q15 */ + const Word16 Q_exc /* i : Scaling factor of excitation Q0 */ ); -void E_UTIL_voice_factor(Word16 *exc, /* i : pointer to the excitation frame Q_new */ - Word16 i_subfr, /* i : subframe index */ - Word16 *code, /* i : innovative codebook Q9 */ - Word16 gain_pit, /* i : adaptive codebook gain 1Q14 */ - Word32 gain_code, /* i : innovative cb. gain 15Q16 */ - Word16 *voice_fac, /* o : subframe voicing estimation Q15 */ - Word16 *tilt_code, /* o : tilt factor Q15 */ - Word16 L_subfr, /* i : subframe length */ - Word16 flag_tilt, /* i : Flag for triggering new voice factor tilt*/ - Word16 Q_new, /* i : excitation buffer format */ - Word16 shift /* i : scaling to get 12bit */ +void E_UTIL_voice_factor( Word16 *exc, /* i : pointer to the excitation frame Q_new */ + Word16 i_subfr, /* i : subframe index */ + Word16 *code, /* i : innovative codebook Q9 */ + Word16 gain_pit, /* i : adaptive codebook gain 1Q14 */ + Word32 gain_code, /* i : innovative cb. gain 15Q16 */ + Word16 *voice_fac, /* o : subframe voicing estimation Q15 */ + Word16 *tilt_code, /* o : tilt factor Q15 */ + Word16 L_subfr, /* i : subframe length */ + Word16 flag_tilt, /* i : Flag for triggering new voice factor tilt*/ + Word16 Q_new, /* i : excitation buffer format */ + Word16 shift /* i : scaling to get 12bit */ ); -//window_ola_fx.c +// window_ola_fx.c void sinq_fx( - const Word16 tmp, /* i : sinus factor cos(tmp*i+phi) Q15*/ - const Word16 phi, /* i : sinus phase cos(tmp*i+phi) Q15*/ - const Word16 N, /* i : size of output */ - Word16 x[] /* o : output vector Q15*/ + const Word16 tmp, /* i : sinus factor cos(tmp*i+phi) Q15*/ + const Word16 phi, /* i : sinus phase cos(tmp*i+phi) Q15*/ + const Word16 N, /* i : size of output */ + Word16 x[] /* o : output vector Q15*/ ); void window_ola_fx( - Word32 *ImdctOut, - Word16 *auOut, - Word16 *Q_sig, - Word16 *OldauOut, - Word16 *Q_old, - const Word16 L, - const Word16 right_mode, - const Word16 left_mode, - const Word16 old_bfi, - const Word16 oldHqVoicing, - Word16 *oldgapsynth); + Word32 *ImdctOut, + Word16 *auOut, + Word16 *Q_sig, + Word16 *OldauOut, + Word16 *Q_old, + const Word16 L, + const Word16 right_mode, + const Word16 left_mode, + const Word16 old_bfi, + const Word16 oldHqVoicing, + Word16 *oldgapsynth ); void core_switching_OLA_fx( - Word16 *mem_over_hp, /* i : upsampling filter memory Q0 */ - const Word16 last_L_frame, /* i : last L_frame lengthture */ - const Word32 output_Fs, /* i : output sampling rate */ - Word16 *synth, /* i/o: synthesized signal from HQ core Q0 */ - Word16 *synth_subfr_out, /* i : synthesized signal from ACELP core Q0 */ - Word16 *synth_subfr_bwe, /* i : synthesized BWE from ACELP core Q0 */ - const Word16 output_frame, /* i : output frame length */ - const Word16 bwidth, /* i : output bandwidth */ - Word16* Qsynth, - Word16* Qsubfr -); + Word16 *mem_over_hp, /* i : upsampling filter memory Q0 */ + const Word16 last_L_frame, /* i : last L_frame lengthture */ + const Word32 output_Fs, /* i : output sampling rate */ + Word16 *synth, /* i/o: synthesized signal from HQ core Q0 */ + Word16 *synth_subfr_out, /* i : synthesized signal from ACELP core Q0 */ + Word16 *synth_subfr_bwe, /* i : synthesized BWE from ACELP core Q0 */ + const Word16 output_frame, /* i : output frame length */ + const Word16 bwidth, /* i : output bandwidth */ + Word16 *Qsynth, + Word16 *Qsubfr ); void window_ola_ext_fx( - const Word32 *ImdstOut, /* i : input */ - Word32 *auOut, /* o : output audio */ - Word32 *OldauOut, /* i/o: audio from previous frame */ - const Word16 L, /* i : length */ - const Word16 right_mode, - const Word16 left_mode, /* i : window overlap of current frame (0: full, 2: none, or 3: half) */ - const UWord16 kernel_type /* i : transform kernel type */ + const Word32 *ImdstOut, /* i : input */ + Word32 *auOut, /* o : output audio */ + Word32 *OldauOut, /* i/o: audio from previous frame */ + const Word16 L, /* i : length */ + const Word16 right_mode, + const Word16 left_mode, /* i : window overlap of current frame (0: full, 2: none, or 3: half) */ + const UWord16 kernel_type /* i : transform kernel type */ ); -//cb_shape_fx.c +// cb_shape_fx.c void cb_shape_fx( - const Word16 preemphFlag, /* i : flag for pre-emphasis */ - const Word16 pitchFlag, /* i : flag for pitch sharpening */ - const Word16 scramblingFlag, /* i : flag for phase scrambling */ - const Word16 sharpFlag, /* i : flag for formant sharpening */ - const Word16 formantTiltFlag, /* i : flag for formant tilt */ - const Word16 g1, /* i : formant sharpening numerator weighting */ - const Word16 g2, /* i : formant sharpening denominator weighting */ - const Word16 *p_Aq, /* i : LP filter coefficients */ - Word16 *code, /* i/o: signal to shape */ - const Word16 tilt_code, /* i : tilt of code */ - const Word16 pt_pitch, /* i : pointer to current subframe fractional pitch */ - const Word16 shift - , const Word16 L_subfr /* i : subframe lenght */ -); - -//longarith.c + const Word16 preemphFlag, /* i : flag for pre-emphasis */ + const Word16 pitchFlag, /* i : flag for pitch sharpening */ + const Word16 scramblingFlag, /* i : flag for phase scrambling */ + const Word16 sharpFlag, /* i : flag for formant sharpening */ + const Word16 formantTiltFlag, /* i : flag for formant tilt */ + const Word16 g1, /* i : formant sharpening numerator weighting */ + const Word16 g2, /* i : formant sharpening denominator weighting */ + const Word16 *p_Aq, /* i : LP filter coefficients */ + Word16 *code, /* i/o: signal to shape */ + const Word16 tilt_code, /* i : tilt of code */ + const Word16 pt_pitch, /* i : pointer to current subframe fractional pitch */ + const Word16 shift, + const Word16 L_subfr /* i : subframe lenght */ +); + +// longarith.c void longadd( - uint16_t a[], /* i/o: vector of the length lena */ - const uint16_t b[], /* i/o: vector of the length lenb */ - const int16_t lena, /* i/o: length of vector a[] */ - const int16_t lenb /* i/o: length of vector b[] */ + uint16_t a[], /* i/o: vector of the length lena */ + const uint16_t b[], /* i/o: vector of the length lenb */ + const int16_t lena, /* i/o: length of vector a[] */ + const int16_t lenb /* i/o: length of vector b[] */ ); void longshiftright( - uint16_t a[], /* i : vector of the length lena */ - const int16_t b, /* i : number of bit positions to shift right */ - uint16_t d[], /* o : vector of the length lend */ - int16_t lena, /* i : length of vector a[] */ - const int16_t lend /* i : length of vector d[] */ + uint16_t a[], /* i : vector of the length lena */ + const int16_t b, /* i : number of bit positions to shift right */ + uint16_t d[], /* o : vector of the length lend */ + int16_t lena, /* i : length of vector a[] */ + const int16_t lend /* i : length of vector d[] */ ); void longshiftleft( - const uint16_t a[], /* i : vector of the length len */ - const int16_t b, /* i : number of bit positions to shift left */ - uint16_t d[], /* o : vector of the length len */ - const int16_t len /* i : length of vector a[] and d[] */ + const uint16_t a[], /* i : vector of the length len */ + const int16_t b, /* i : number of bit positions to shift left */ + uint16_t d[], /* o : vector of the length len */ + const int16_t len /* i : length of vector a[] and d[] */ ); #ifdef IVAS_FLOAT_FIXED void longshr( - UWord32 a[], - Word16 bits, - Word16 len -); + UWord32 a[], + Word16 bits, + Word16 len ); #endif // IVAS_FLOAT_FIXED -//gs_bitallocation.c +// gs_bitallocation.c void bands_and_bit_alloc_fx( - const Word16 cor_strong_limit, /* i : HF correlation */ - const Word16 noise_lev, /* i : dwn scaling factor */ - const Word32 core_brate, /* i : core bit rate */ - const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral)*/ - const Word16 bits_used, /* i : Number of bit used before frequency Q */ - Word16* bit, /* i/o: Number of bit allowed for frequency quantization */ - const Word16* Ener_per_bd_iQ, /* i/o: Quantized energy vector */ - Word16* max_ener_band, /* o : Sorted order */ - Word16* out_bits_per_bands, /* i/o: Number of bit allowed per allowed subband Q3 */ - Word16* nb_subbands, /* o : Number of subband allowed */ - const Word16* exc_diff, /* i : Difference signal to quantize (encoder side only) */ - Word16* concat_in, /* o : Concatened PVQ's i vector (encoder side only) */ - Word16* pvq_len, /* o : Number of bin covered with the PVQ */ - const Word16 coder_type, /* i : coding type */ - const Word16 bwidth, /* i : i signal bandwidth */ - const Word16 GSC_noisy_speech, /* i : GSC noisy speech flag */ - const Word16 L_frame, /* i : frame length */ - const Word16 element_mode, /* i : element mode */ - const Word16 GSC_IVAS_mode /* i : GSC IVAS mode */ -); - -//low_rate_band_att_fx.c + const Word16 cor_strong_limit, /* i : HF correlation */ + const Word16 noise_lev, /* i : dwn scaling factor */ + const Word32 core_brate, /* i : core bit rate */ + const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral)*/ + const Word16 bits_used, /* i : Number of bit used before frequency Q */ + Word16 *bit, /* i/o: Number of bit allowed for frequency quantization */ + const Word16 *Ener_per_bd_iQ, /* i/o: Quantized energy vector */ + Word16 *max_ener_band, /* o : Sorted order */ + Word16 *out_bits_per_bands, /* i/o: Number of bit allowed per allowed subband Q3 */ + Word16 *nb_subbands, /* o : Number of subband allowed */ + const Word16 *exc_diff, /* i : Difference signal to quantize (encoder side only) */ + Word16 *concat_in, /* o : Concatened PVQ's i vector (encoder side only) */ + Word16 *pvq_len, /* o : Number of bin covered with the PVQ */ + const Word16 coder_type, /* i : coding type */ + const Word16 bwidth, /* i : i signal bandwidth */ + const Word16 GSC_noisy_speech, /* i : GSC noisy speech flag */ + const Word16 L_frame, /* i : frame length */ + const Word16 element_mode, /* i : element mode */ + const Word16 GSC_IVAS_mode /* i : GSC IVAS mode */ +); + +// low_rate_band_att_fx.c void fine_gain_pred_fx( - const Word16 *sfm_start, /* i : Sub band start indices */ - const Word16 *sfm_end, /* i : Sub band end indices */ - const Word16 *sfm_size, /* i : Sub band bandwidths */ - const Word16 *i_sort, /* i : Energy sorting indices */ - const Word16 *K, /* i : Number of pulses per band */ - const Word16 *maxpulse, /* i : Maximum pulse per band */ - const Word16 *R, /* i : Bits per sub band Q3 */ - const Word16 num_sfm, /* i : Number of sub bands */ - Word16 *xq, /* i/o: Quantized vector /quantized vector with finegain adj Q15*/ - Word16 *y, /* i/o: Quantized vector (int) */ - Word16 *fg_pred, /* o : Predicted fine gains Q12 */ - const Word16 core /* i : Core */ + const Word16 *sfm_start, /* i : Sub band start indices */ + const Word16 *sfm_end, /* i : Sub band end indices */ + const Word16 *sfm_size, /* i : Sub band bandwidths */ + const Word16 *i_sort, /* i : Energy sorting indices */ + const Word16 *K, /* i : Number of pulses per band */ + const Word16 *maxpulse, /* i : Maximum pulse per band */ + const Word16 *R, /* i : Bits per sub band Q3 */ + const Word16 num_sfm, /* i : Number of sub bands */ + Word16 *xq, /* i/o: Quantized vector /quantized vector with finegain adj Q15*/ + Word16 *y, /* i/o: Quantized vector (int) */ + Word16 *fg_pred, /* o : Predicted fine gains Q12 */ + const Word16 core /* i : Core */ ); void fine_gain_quant_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 *ord, /* i : Indices for energy order */ - const Word16 num_sfm, /* i : Number of bands */ - const Word16 *gain_bits, /* i : Gain adjustment bits per sub band */ - Word16 *fg_pred, /* i/o: Predicted gains / Corrected gains Q12 */ - const Word16 *gopt /* i : Optimal gains Q12 */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 *ord, /* i : Indices for energy order */ + const Word16 num_sfm, /* i : Number of bands */ + const Word16 *gain_bits, /* i : Gain adjustment bits per sub band */ + Word16 *fg_pred, /* i/o: Predicted gains / Corrected gains Q12 */ + const Word16 *gopt /* i : Optimal gains Q12 */ ); void get_max_pulses_fx( - const Word16 *band_start, /* i : Sub band start indices */ - const Word16 *band_end, /* i : Sub band end indices */ - const Word16 *k_sort, /* i : Indices for sorting by energy */ - const Word16 *npulses, /* i : Pulses per sub band */ - const Word16 BANDS, /* i : Number of bands */ - Word16 *inp_vector, /* i/o: Encoded shape vectors (int)*/ - Word16 *maxpulse /* o : Maximum pulse height per band */ -); -void fine_gain_dec_fx -( - Decoder_State *st, - const Word16 *ord, /* i : Indices for energy order */ - const Word16 num_sfm, /* i : Number of bands */ - const Word16 *gain_bits, /* i : Gain adjustment bits per sub band */ - Word16 *fg_pred /* i/o: Predicted gains / Corrected gains */ -); - -//fine_gain_bits_fx.c -Word16 assign_gain_bits_fx( /* o : Number of assigned gain bits */ - const Word16 core, /* i : HQ core */ - const Word16 BANDS, /* i : Number of bands */ - const Word16 *band_width, /* i : Sub band bandwidth */ - Word16 *Rk, /* i/o: Bit allocation/Adjusted bit alloc. Q3 */ - Word16 *gain_bits_array, /* o : Assigned gain bits */ - Word16 *Rcalc /* o : Bit budget for shape quantizer Q3 */ -); - -//gs_noisefill.c + const Word16 *band_start, /* i : Sub band start indices */ + const Word16 *band_end, /* i : Sub band end indices */ + const Word16 *k_sort, /* i : Indices for sorting by energy */ + const Word16 *npulses, /* i : Pulses per sub band */ + const Word16 BANDS, /* i : Number of bands */ + Word16 *inp_vector, /* i/o: Encoded shape vectors (int)*/ + Word16 *maxpulse /* o : Maximum pulse height per band */ +); +void fine_gain_dec_fx( + Decoder_State *st, + const Word16 *ord, /* i : Indices for energy order */ + const Word16 num_sfm, /* i : Number of bands */ + const Word16 *gain_bits, /* i : Gain adjustment bits per sub band */ + Word16 *fg_pred /* i/o: Predicted gains / Corrected gains */ +); + +// fine_gain_bits_fx.c +Word16 assign_gain_bits_fx( /* o : Number of assigned gain bits */ + const Word16 core, /* i : HQ core */ + const Word16 BANDS, /* i : Number of bands */ + const Word16 *band_width, /* i : Sub band bandwidth */ + Word16 *Rk, /* i/o: Bit allocation/Adjusted bit alloc. Q3 */ + Word16 *gain_bits_array, /* o : Assigned gain bits */ + Word16 *Rcalc /* o : Bit budget for shape quantizer Q3 */ +); + +// gs_noisefill.c void freq_dnw_scaling_fx( - const Word16 cor_strong_limit, /* i : HF correlation */ - const Word16 coder_type, /* i : coder type */ - const Word16 noise_lev, /* i : Noise level */ - const Word32 core_brate, /* i : Core bitrate */ - Word16 fy_norm[], /* i/o: Frequency quantized parameter */ - Word16 Qx, /* Q format of fy_norm*/ - const Word16 L_frame /* i : frame length */ + const Word16 cor_strong_limit, /* i : HF correlation */ + const Word16 coder_type, /* i : coder type */ + const Word16 noise_lev, /* i : Noise level */ + const Word32 core_brate, /* i : Core bitrate */ + Word16 fy_norm[], /* i/o: Frequency quantized parameter */ + Word16 Qx, /* Q format of fy_norm*/ + const Word16 L_frame /* i : frame length */ ); void highband_exc_dct_in_fx( - const Word32 core_brate, /* i : core bitrate */ - const Word16* mfreq_bindiv, /* i : bin per bands tables */ - Word16 last_bin, /* i : last bin of bit allocation */ - Word16 Diff_len, /* i : number of bin before cut-off frequency */ - Word16 noise_lev, /* i : pulses dynamic */ - Word16 pit_band_idx, /* i : bin position of the cut-off frequency */ - Word16* exc_diffQ, /* i : frequency coefficients of per band */ - Word16* seed_tcx, /* i : Seed for noise */ - Word16* Ener_per_bd_iQ, /* i : Quantized energy of targeted vector */ - Word16 nb_subfr, /* i : Number of subframe considered */ - Word16* exc_dct_in, /* o : dct of residual signal */ - Word16 last_coder_type, /* i : coding type of last frame */ - Word16* bitallocation_band, /* i : bit allocation flag of each band */ - const Word16* lsf_new, /* i : LSFs at the end of the frame */ - Word16* last_exc_dct_in, /* i : dct of residual signal of last frame */ - Word16* last_ener, /* i : frequency energy of last frame */ - Word16* last_bitallocation_band, /* i : bit allocation flag of each band of last frame */ - Word16* bitallocation_exc, /* i : flag of decoded coefficients */ - Word16 bfi, /* i : bad frame indicator */ - const Word16 coder_type, /* i : coder type */ - Word16 bwidth, - Word16* exc_wo_nf, /* o : temporal excitation (in f domain) without noisefill */ - Word16 Qexc_diffQ, - Word16 Q_exc, - const Word16 GSC_noisy_speech - , Word16* lt_ener_per_band_fx, /* i/o: Average per band energy */ - const Word16 L_frame, /* i : frame length */ - const Word16 element_mode, /* i : IVAS element mode */ - const Word16 GSC_IVAS_mode /* i : GSC IVAS mode */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 *mfreq_bindiv, /* i : bin per bands tables */ + Word16 last_bin, /* i : last bin of bit allocation */ + Word16 Diff_len, /* i : number of bin before cut-off frequency */ + Word16 noise_lev, /* i : pulses dynamic */ + Word16 pit_band_idx, /* i : bin position of the cut-off frequency */ + Word16 *exc_diffQ, /* i : frequency coefficients of per band */ + Word16 *seed_tcx, /* i : Seed for noise */ + Word16 *Ener_per_bd_iQ, /* i : Quantized energy of targeted vector */ + Word16 nb_subfr, /* i : Number of subframe considered */ + Word16 *exc_dct_in, /* o : dct of residual signal */ + Word16 last_coder_type, /* i : coding type of last frame */ + Word16 *bitallocation_band, /* i : bit allocation flag of each band */ + const Word16 *lsf_new, /* i : LSFs at the end of the frame */ + Word16 *last_exc_dct_in, /* i : dct of residual signal of last frame */ + Word16 *last_ener, /* i : frequency energy of last frame */ + Word16 *last_bitallocation_band, /* i : bit allocation flag of each band of last frame */ + Word16 *bitallocation_exc, /* i : flag of decoded coefficients */ + Word16 bfi, /* i : bad frame indicator */ + const Word16 coder_type, /* i : coder type */ + Word16 bwidth, + Word16 *exc_wo_nf, /* o : temporal excitation (in f domain) without noisefill */ + Word16 Qexc_diffQ, + Word16 Q_exc, + const Word16 GSC_noisy_speech, + Word16 *lt_ener_per_band_fx, /* i/o: Average per band energy */ + const Word16 L_frame, /* i : frame length */ + const Word16 element_mode, /* i : IVAS element mode */ + const Word16 GSC_IVAS_mode /* i : GSC IVAS mode */ ); #ifdef IVAS_FLOAT_FIXED void highband_exc_dct_in_ivas_fx( - const Word32 core_brate, /* i : core bitrate */ - const Word16 *mfreq_bindiv, /* i : bin per bands tables */ - Word16 last_bin, /* i : last bin of bit allocation */ - Word16 Diff_len, /* i : number of bin before cut-off frequency */ - Word16 noise_lev, /* i : pulses dynamic */ - Word16 pit_band_idx, /* i : bin position of the cut-off frequency */ - Word16 *exc_diffQ, /* i : frequency coefficients of per band */ - Word16 *seed_tcx, /* i : Seed for noise */ - Word16 *Ener_per_bd_iQ, /* i : Quantized energy of targeted vector */ - Word16 nb_subfr, /* i : Number of subframe considered */ - Word16 *exc_dct_in, /* o : dct of residual signal */ - Word16 last_coder_type, /* i : coding type of last frame */ - Word16 *bitallocation_band, /* i : bit allocation flag of each band */ - const Word16 *lsf_new, /* i : LSFs at the end of the frame */ - Word16 *last_exc_dct_in, /* i : dct of residual signal of last frame */ - Word16 *last_ener, /* i : frequency energy of last frame */ - Word16 *last_bitallocation_band, /* i : bit allocation flag of each band of last frame */ - Word16 *bitallocation_exc, /* i : flag of decoded coefficients */ - Word16 bfi, /* i : bad frame indicator */ - const Word16 coder_type, /* i : coder type */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 *mfreq_bindiv, /* i : bin per bands tables */ + Word16 last_bin, /* i : last bin of bit allocation */ + Word16 Diff_len, /* i : number of bin before cut-off frequency */ + Word16 noise_lev, /* i : pulses dynamic */ + Word16 pit_band_idx, /* i : bin position of the cut-off frequency */ + Word16 *exc_diffQ, /* i : frequency coefficients of per band */ + Word16 *seed_tcx, /* i : Seed for noise */ + Word16 *Ener_per_bd_iQ, /* i : Quantized energy of targeted vector */ + Word16 nb_subfr, /* i : Number of subframe considered */ + Word16 *exc_dct_in, /* o : dct of residual signal */ + Word16 last_coder_type, /* i : coding type of last frame */ + Word16 *bitallocation_band, /* i : bit allocation flag of each band */ + const Word16 *lsf_new, /* i : LSFs at the end of the frame */ + Word16 *last_exc_dct_in, /* i : dct of residual signal of last frame */ + Word16 *last_ener, /* i : frequency energy of last frame */ + Word16 *last_bitallocation_band, /* i : bit allocation flag of each band of last frame */ + Word16 *bitallocation_exc, /* i : flag of decoded coefficients */ + Word16 bfi, /* i : bad frame indicator */ + const Word16 coder_type, /* i : coder type */ Word16 bwidth, - Word16 *exc_wo_nf, /* o : temporal excitation (in f domain) without noisefill */ + Word16 *exc_wo_nf, /* o : temporal excitation (in f domain) without noisefill */ Word16 Qexc_diffQ, Word16 Q_exc, - const Word16 GSC_noisy_speech - , Word16 *lt_ener_per_band_fx, /* i/o: Average per band energy */ - const Word16 L_frame, /* i : frame length */ - const Word16 element_mode, /* i : IVAS element mode */ - const Word16 GSC_IVAS_mode /* i : GSC IVAS mode */ + const Word16 GSC_noisy_speech, + Word16 *lt_ener_per_band_fx, /* i/o: Average per band energy */ + const Word16 L_frame, /* i : frame length */ + const Word16 element_mode, /* i : IVAS element mode */ + const Word16 GSC_IVAS_mode /* i : GSC IVAS mode */ ); #endif -//lsf_dec_bfi_fx.c +// lsf_dec_bfi_fx.c void lsf_dec_bfi( - const Word16 codec_mode, /* i: : codec mode: MODE1 | MODE2 */ - Word16* lsf, /*!< o : 14Q1*1.28 quantized ISFs */ - const Word16* lsfold, /*!< i : 14Q1*1.28 past quantized ISF */ - Word16* lsf_adaptive_mean, /*!< i : 14Q1*1.28 ISF adaptive mean, updated when BFI==0 */ - const Word16 lsfBase[], /* i : base for differential lsf coding */ - Word16* mem_MA, /*!< i/o: 14Q1*1.28 quantizer memory for MA model */ - Word16* mem_AR, /*!< i/o: 14Q1*1.28 quantizer memory for MA model */ - Word16 stab_fac, /*!< i : ISF stability factor (shifted right by 1) */ - const Word16 last_coder_type,/*!< i : coding type in last good received fr. */ - Word16 L_frame, - const Word16 last_good, /*!< i : last good received frame */ - const Word16 nbLostCmpt, /*!< i : counter of consecutive bad frames */ - const Word8 plcBackgroundNoiseUpdated, /* i : background noise already updated?*/ - Word16* lsf_q_cng, /* o : quantized ISFs for background noise (14Q1*1.28) */ - Word16* lsf_cng, - Word16* old_lsf_q_cng, /* o : old quantized ISFs for background noise */ - const Word16 Last_GSC_pit_band_idx, - const Word16 Opt_AMR_WB, /* i : IO flag */ - const Word8 tcxonly, - const short bwidth /* i: coded bandwidth */ -); - -Word16 const * PlcGetLsfBase(Word16 const lpcQuantization, - Word16 const narrowBand, - Word32 const sr_core); - -//fd_cng_com.c + const Word16 codec_mode, /* i: : codec mode: MODE1 | MODE2 */ + Word16 *lsf, /*!< o : 14Q1*1.28 quantized ISFs */ + const Word16 *lsfold, /*!< i : 14Q1*1.28 past quantized ISF */ + Word16 *lsf_adaptive_mean, /*!< i : 14Q1*1.28 ISF adaptive mean, updated when BFI==0 */ + const Word16 lsfBase[], /* i : base for differential lsf coding */ + Word16 *mem_MA, /*!< i/o: 14Q1*1.28 quantizer memory for MA model */ + Word16 *mem_AR, /*!< i/o: 14Q1*1.28 quantizer memory for MA model */ + Word16 stab_fac, /*!< i : ISF stability factor (shifted right by 1) */ + const Word16 last_coder_type, /*!< i : coding type in last good received fr. */ + Word16 L_frame, + const Word16 last_good, /*!< i : last good received frame */ + const Word16 nbLostCmpt, /*!< i : counter of consecutive bad frames */ + const Word8 plcBackgroundNoiseUpdated, /* i : background noise already updated?*/ + Word16 *lsf_q_cng, /* o : quantized ISFs for background noise (14Q1*1.28) */ + Word16 *lsf_cng, + Word16 *old_lsf_q_cng, /* o : old quantized ISFs for background noise */ + const Word16 Last_GSC_pit_band_idx, + const Word16 Opt_AMR_WB, /* i : IO flag */ + const Word8 tcxonly, + const short bwidth /* i: coded bandwidth */ +); + +Word16 const *PlcGetLsfBase( Word16 const lpcQuantization, + Word16 const narrowBand, + Word32 const sr_core ); + +// fd_cng_com.c /* Create an instance of type FD_CNG */ -ivas_error createFdCngCom(HANDLE_FD_CNG_COM* hFdCngCom); +ivas_error createFdCngCom( HANDLE_FD_CNG_COM *hFdCngCom ); -void initFdCngCom(HANDLE_FD_CNG_COM hFdCngCom, Word16 scale); +void initFdCngCom( HANDLE_FD_CNG_COM hFdCngCom, Word16 scale ); /* Delete the instance of type FD_CNG */ -void deleteFdCngCom(HANDLE_FD_CNG_COM * hFdCngCom); +void deleteFdCngCom( HANDLE_FD_CNG_COM *hFdCngCom ); /* Initialize the spectral partitioning */ void initPartitions( - const Word16* part_in, - const Word16 npart_in, - const Word16 startBand, - const Word16 stopBand, - Word16* part_out, - Word16* npart_out, - Word16* midband, - Word16* psize, - Word16* psize_norm, - Word16* psize_norm_exp, - Word16* psize_inv, - const Word16 stopBandFR -); + const Word16 *part_in, + const Word16 npart_in, + const Word16 startBand, + const Word16 stopBand, + Word16 *part_out, + Word16 *npart_out, + Word16 *midband, + Word16 *psize, + Word16 *psize_norm, + Word16 *psize_norm_exp, + Word16 *psize_inv, + const Word16 stopBandFR ); /* Noise estimation using Minimum Statistics (MS) */ void compress_range( - Word32* in, - Word16 in_exp, - Word16* out, - const Word16 len -); + Word32 *in, + Word16 in_exp, + Word16 *out, + const Word16 len ); void expand_range( - Word16* in, - Word32* out, - Word16* out_exp, - const Word16 len -); + Word16 *in, + Word32 *out, + Word16 *out_exp, + const Word16 len ); void expand_range_var_exp( Word16 *in, Word16 in_exp, Word32 *out, Word16 *out_exp, - const Word16 len -); - -void minimum_statistics(Word16 len, /* i : Total number of partitions (CLDFB or FFT) */ - Word16 lenFFT, /* i : Number of FFT partitions */ - Word16 *psize, /* i : Partition sizes, fractional */ - Word16 *msPeriodog, /* i : Periodogram (energies) */ - Word16 *msNoiseFloor, /* i/o: Noise floors (energies) */ - Word16 *msNoiseEst, /* i/o: Noise estimates (energies) */ - Word32 *msAlpha, /* i/o: Forgetting factors */ - Word16 *msPsd, /* i/o: Power Spectral Density (smoothed periodogram => energies) */ - Word16 *msPsdFirstMoment, /* i/o: PSD statistics of 1st order (energy means) */ - Word32 *msPsdSecondMoment, /* i/o: PSD statistics of 2nd order (energy variances) */ - Word32 *msMinBuf, /* i/o: Buffer of minima (energies) */ - Word32 *msBminWin, /* o : Bias correction factors */ - Word32 *msBminSubWin, /* o : Bias correction factors */ - Word32 *msCurrentMin, /* i/o: Local minima (energies) */ - Word32 *msCurrentMinOut, /* i/o: Local minima (energies) */ - Word32 *msCurrentMinSubWindow, /* i/o: Local minima (energies) */ - Word16 *msLocalMinFlag, /* i : Binary flag */ - Word16 *msNewMinFlag, /* i : Binary flag */ - Word16 *msPeriodogBuf, /* i/o: Buffer of periodograms (energies) */ - Word16 *msPeriodogBufPtr, /* i/o: Counter */ - HANDLE_FD_CNG_COM st /* i/o: FD_CNG structure containing buffers and variables */ + const Word16 len ); + +void minimum_statistics( Word16 len, /* i : Total number of partitions (CLDFB or FFT) */ + Word16 lenFFT, /* i : Number of FFT partitions */ + Word16 *psize, /* i : Partition sizes, fractional */ + Word16 *msPeriodog, /* i : Periodogram (energies) */ + Word16 *msNoiseFloor, /* i/o: Noise floors (energies) */ + Word16 *msNoiseEst, /* i/o: Noise estimates (energies) */ + Word32 *msAlpha, /* i/o: Forgetting factors */ + Word16 *msPsd, /* i/o: Power Spectral Density (smoothed periodogram => energies) */ + Word16 *msPsdFirstMoment, /* i/o: PSD statistics of 1st order (energy means) */ + Word32 *msPsdSecondMoment, /* i/o: PSD statistics of 2nd order (energy variances) */ + Word32 *msMinBuf, /* i/o: Buffer of minima (energies) */ + Word32 *msBminWin, /* o : Bias correction factors */ + Word32 *msBminSubWin, /* o : Bias correction factors */ + Word32 *msCurrentMin, /* i/o: Local minima (energies) */ + Word32 *msCurrentMinOut, /* i/o: Local minima (energies) */ + Word32 *msCurrentMinSubWindow, /* i/o: Local minima (energies) */ + Word16 *msLocalMinFlag, /* i : Binary flag */ + Word16 *msNewMinFlag, /* i : Binary flag */ + Word16 *msPeriodogBuf, /* i/o: Buffer of periodograms (energies) */ + Word16 *msPeriodogBufPtr, /* i/o: Counter */ + HANDLE_FD_CNG_COM st /* i/o: FD_CNG structure containing buffers and variables */ ); #ifdef IVAS_FLOAT_FIXED @@ -4869,11 +4735,11 @@ void minimum_statistics_fx( /* Apply bitrate-dependant scale */ void apply_scale( - Word32* scale, /* o : scalefactor */ - const Word16 bwmode, /* i : audio bandwidth */ - const Word32 bitrate, /* i : Bit rate */ - const SCALE_SETUP* scaleTable, /* i : Scale table */ - const Word16 scaleTableSize /* i : Size of scale table */ + Word32 *scale, /* o : scalefactor */ + const Word16 bwmode, /* i : audio bandwidth */ + const Word32 bitrate, /* i : Bit rate */ + const SCALE_SETUP *scaleTable, /* i : Scale table */ + const Word16 scaleTableSize /* i : Size of scale table */ ); Word16 apply_scale_ind( @@ -4884,37 +4750,34 @@ Word16 apply_scale_ind( const Word16 scaleTableSize /* i : Size of scale table */ ); void apply_scale_ivas_fx( - Word32 *scale, /* o : scalefactor */ - const Word16 bwmode, /* i : audio bandwidth */ - const Word32 bitrate, /* i : Bit rate */ - const SCALE_SETUP* scaleTable, /* i : Scale table */ - const Word16 scaleTableSize, /* i : Size of scale table */ - Word16 *index -); + Word32 *scale, /* o : scalefactor */ + const Word16 bwmode, /* i : audio bandwidth */ + const Word32 bitrate, /* i : Bit rate */ + const SCALE_SETUP *scaleTable, /* i : Scale table */ + const Word16 scaleTableSize, /* i : Size of scale table */ + Word16 *index ); /* Compute the power for each partition */ void bandcombinepow( - const Word32* bandpow, /* i : Power for each band */ - const Word16 exp_bandpow, /* i : exponent of bandpow */ - const Word16 nband, /* i : Number of bands */ - Word16* part, /* i : Partition upper boundaries (band indices starting from 0) */ - const Word16 npart, /* i : Number of partitions */ - const Word16* psize_inv, /* i : Inverse partition sizes */ - Word32* partpow, /* o : Power for each partition */ - Word16* exp_partpow -); + const Word32 *bandpow, /* i : Power for each band */ + const Word16 exp_bandpow, /* i : exponent of bandpow */ + const Word16 nband, /* i : Number of bands */ + Word16 *part, /* i : Partition upper boundaries (band indices starting from 0) */ + const Word16 npart, /* i : Number of partitions */ + const Word16 *psize_inv, /* i : Inverse partition sizes */ + Word32 *partpow, /* o : Power for each partition */ + Word16 *exp_partpow ); /* Scale partitions (with smoothing) */ void scalebands( - const Word32* partpow, /* i : Power for each partition */ - Word16* part, /* i : Partition upper boundaries (band indices starting from 0) */ - const Word16 npart, /* i : Number of partitions */ - Word16* midband, /* i : Central band of each partition */ - const Word16 nFFTpart, /* i : Number of FFT partitions */ - const Word16 nband, /* i : Number of bands */ - Word32* bandpow, /* o : Power for each band */ - const Word16 flag_fft_en -); + const Word32 *partpow, /* i : Power for each partition */ + Word16 *part, /* i : Partition upper boundaries (band indices starting from 0) */ + const Word16 npart, /* i : Number of partitions */ + Word16 *midband, /* i : Central band of each partition */ + const Word16 nFFTpart, /* i : Number of FFT partitions */ + const Word16 nband, /* i : Number of bands */ + Word32 *bandpow, /* o : Power for each band */ + const Word16 flag_fft_en ); void scalebands_fx( const Word32 *partpow, /* i : Power for each partition */ Word16 *part, /* i : Partition upper boundaries (band indices starting from 0) */ @@ -4927,39 +4790,39 @@ void scalebands_fx( /* STFT analysis filterbank */ void AnalysisSTFT( - const Word16* timeDomainInput, /* i : pointer to time signal */ - Word16 Q, - Word32* fftBuffer, /* o : FFT bins */ - Word16* fftBuffer_exp, /* i : exponent of FFT bins */ - HANDLE_FD_CNG_COM hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */ + const Word16 *timeDomainInput, /* i : pointer to time signal */ + Word16 Q, + Word32 *fftBuffer, /* o : FFT bins */ + Word16 *fftBuffer_exp, /* i : exponent of FFT bins */ + HANDLE_FD_CNG_COM hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */ ); void AnalysisSTFT_fx( - const Word16 *timeDomainInput, - Word16 Q, - Word32 *fftBuffer, /* o : FFT bins */ - Word16 *fftBuffer_exp, /* i : exponent of FFT bins */ - HANDLE_FD_CNG_COM hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */ + const Word16 *timeDomainInput, + Word16 Q, + Word32 *fftBuffer, /* o : FFT bins */ + Word16 *fftBuffer_exp, /* i : exponent of FFT bins */ + HANDLE_FD_CNG_COM hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */ ); /* STFT synthesis filterbank */ void SynthesisSTFT( - Word32* fftBuffer, /* i : pointer to FFT bins */ - Word16 fftBufferExp, /* i : exponent of FFT bins */ - Word16* timeDomainOutput, /* o : pointer to time domain signal */ - Word16* olapBuffer, /* i/o : pointer to overlap buffer */ - const PWord16* olapWin, /* i : pointer to overlap window */ - Word16 tcx_transition, - HANDLE_FD_CNG_COM hFdCngCom, /* i/o : pointer to FD_CNG structure containing all buffers and variables */ - Word16 gen_exc, - Word16* Q_new, - const Word16 element_mode, /* i : element mode */ - const Word16 nchan_out /* i : number of output channels */ + Word32 *fftBuffer, /* i : pointer to FFT bins */ + Word16 fftBufferExp, /* i : exponent of FFT bins */ + Word16 *timeDomainOutput, /* o : pointer to time domain signal */ + Word16 *olapBuffer, /* i/o : pointer to overlap buffer */ + const PWord16 *olapWin, /* i : pointer to overlap window */ + Word16 tcx_transition, + HANDLE_FD_CNG_COM hFdCngCom, /* i/o : pointer to FD_CNG structure containing all buffers and variables */ + Word16 gen_exc, + Word16 *Q_new, + const Word16 element_mode, /* i : element mode */ + const Word16 nchan_out /* i : number of output channels */ ); void mhvals( - const Word16 d, - Word16* m /*, float * h*/ + const Word16 d, + Word16 *m /*, float * h*/ ); Word32 sign_l( @@ -4967,360 +4830,348 @@ Word32 sign_l( ); void ivas_updt_dec_common_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 hq_core_type_fx, /* i : HQ core type */ - const Word16 concealWholeFrameTmp, /* i : concealWholeFrameTmp flag */ - const Word32 *synth, /* i : decoded synthesis */ - const Word16 Qpostd /* i : Synthesis Q value */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 hq_core_type_fx, /* i : HQ core type */ + const Word16 concealWholeFrameTmp, /* i : concealWholeFrameTmp flag */ + const Word32 *synth, /* i : decoded synthesis */ + const Word16 Qpostd /* i : Synthesis Q value */ ); /* Random generator with Gaussian distribution with mean 0 and std 1 */ -Word32 rand_gauss(Word16 *seed); +Word32 rand_gauss( Word16 *seed ); -Word16 rand_gauss_fix(Word16 *x, Word16 *seed); +Word16 rand_gauss_fix( Word16 *x, Word16 *seed ); void lpc_from_spectrum( - HANDLE_FD_CNG_COM hFdCngCom, - const Word16 start, /*i : start band*/ - const Word16 stop, /*i : stop band*/ - const Word16 preemph_fac /*i : preemphase factor format Q1.15*/ + HANDLE_FD_CNG_COM hFdCngCom, + const Word16 start, /*i : start band*/ + const Word16 stop, /*i : stop band*/ + const Word16 preemph_fac /*i : preemphase factor format Q1.15*/ ); void msvq_decoder( - const Word16* const cb[], /* i : Codebook (indexed cb[*stages][levels][p]) */ - const Word16 stages, /* i : Number of stages */ - const Word16 N, /* i : Vector dimension */ - const Word16 maxN, /* i : Codebook vector dimension */ - const Word16 Idx[], /* i : Indices */ - Word16* uq /* o : quantized vector */ + const Word16 *const cb[], /* i : Codebook (indexed cb[*stages][levels][p]) */ + const Word16 stages, /* i : Number of stages */ + const Word16 N, /* i : Vector dimension */ + const Word16 maxN, /* i : Codebook vector dimension */ + const Word16 Idx[], /* i : Indices */ + Word16 *uq /* o : quantized vector */ ); void FdCng_exc( - HANDLE_FD_CNG_COM hs, - Word16 *CNG_mode, - Word16 L_frame, - Word16 *lsp_old, - Word16 first_CNG, - Word16 *lsp_CNG, - Word16 *Aq, /* o: LPC coeffs */ - Word16 *lsp_new, /* o: lsp */ - Word16 *lsf_new, /* o: lsf */ - Word16 *exc, /* o: LP excitation */ - Word16 *exc2, /* o: LP excitation */ - Word16 *bwe_exc /* o: LP excitation for BWE */ -); - -//trans_direct + HANDLE_FD_CNG_COM hs, + Word16 *CNG_mode, + Word16 L_frame, + Word16 *lsp_old, + Word16 first_CNG, + Word16 *lsp_CNG, + Word16 *Aq, /* o: LPC coeffs */ + Word16 *lsp_new, /* o: lsp */ + Word16 *lsf_new, /* o: lsf */ + Word16 *exc, /* o: LP excitation */ + Word16 *exc2, /* o: LP excitation */ + Word16 *bwe_exc /* o: LP excitation for BWE */ +); + +// trans_direct void direct_transform_fx( - const Word32 in32_fx[], - Word32 out32_fx[], - const Word16 is_transient, - const Word16 L, - Word16 *Q, - const Word16 element_mode -); + const Word32 in32_fx[], + Word32 out32_fx[], + const Word16 is_transient, + const Word16 L, + Word16 *Q, + const Word16 element_mode ); -//trans_inv_fx.c +// trans_inv_fx.c void preecho_sb_fx( - const Word32 brate, /* i Q0 : core bit-rate */ - Word32 *wtda_audio_fx, /* i q_sig32 : imdct signal */ - Word16 q_sig32, /* i Q value for wtda_audio_fx */ - Word16 *rec_sig_fx, /* i q_sig16 : reconstructed signal, output of the imdct transform */ - Word16 q_sig16, /* i Q value for rec_sig_fx and imdct_mem_fx */ - const Word16 framelength, /* i Q0 : frame length */ - Word16 *memfilt_lb_fx, /* i/o Q0 : memory */ - Word32 *mean_prev_hb_fx, /* i/o Q0 : memory */ - Word16 *smoothmem_fx, /* i/o Q15 : memory */ - Word32 *mean_prev_fx, /* i/o Q0 : memory */ - Word32 *mean_prev_nc_fx, /* i/o Q0 : memory */ - Word16 *wmold_hb_fx, /* i/o Q15 : memory */ - Word16 *prevflag, /* i/o Q0 : flag */ - Word16 *pastpre, /* i/o Q0 : flag */ - const Word16 bwidth /* i Q0 : bandwidth */ + const Word32 brate, /* i Q0 : core bit-rate */ + Word32 *wtda_audio_fx, /* i q_sig32 : imdct signal */ + Word16 q_sig32, /* i Q value for wtda_audio_fx */ + Word16 *rec_sig_fx, /* i q_sig16 : reconstructed signal, output of the imdct transform */ + Word16 q_sig16, /* i Q value for rec_sig_fx and imdct_mem_fx */ + const Word16 framelength, /* i Q0 : frame length */ + Word16 *memfilt_lb_fx, /* i/o Q0 : memory */ + Word32 *mean_prev_hb_fx, /* i/o Q0 : memory */ + Word16 *smoothmem_fx, /* i/o Q15 : memory */ + Word32 *mean_prev_fx, /* i/o Q0 : memory */ + Word32 *mean_prev_nc_fx, /* i/o Q0 : memory */ + Word16 *wmold_hb_fx, /* i/o Q15 : memory */ + Word16 *prevflag, /* i/o Q0 : flag */ + Word16 *pastpre, /* i/o Q0 : flag */ + const Word16 bwidth /* i Q0 : bandwidth */ ); void Inverse_Transform( - const Word32 *in_mdct, /* i : i MDCT vector */ - Word16 *Q, /* i/o: Q value of i */ - Word32 *out, /* o : output vector */ - const Word16 is_transient, /* i : transient flag */ - const Word16 L, /* i : output frame length */ - const Word16 L_inner, /* i : length of the transform */ - const Word16 element_mode /* i : IVAS element mode */ + const Word32 *in_mdct, /* i : i MDCT vector */ + Word16 *Q, /* i/o: Q value of i */ + Word32 *out, /* o : output vector */ + const Word16 is_transient, /* i : transient flag */ + const Word16 L, /* i : output frame length */ + const Word16 L_inner, /* i : length of the transform */ + const Word16 element_mode /* i : IVAS element mode */ ); -//recovernorm +// recovernorm void recovernorm_fx( - const Word16* idxbuf, /* i : reordered quantization indices */ - Word16* ynrm, /* o : recovered quantization indices */ - Word16* normqlg2, /* o : recovered quantized norms */ - const Word16 nb_sfm /* i : number of SFMs */ + const Word16 *idxbuf, /* i : reordered quantization indices */ + Word16 *ynrm, /* o : recovered quantization indices */ + Word16 *normqlg2, /* o : recovered quantized norms */ + const Word16 nb_sfm /* i : number of SFMs */ ); -//tcq_poition_qeith.c -Word32 ar_div(Word32 num, Word32 denum); +// tcq_poition_qeith.c +Word32 ar_div( Word32 num, Word32 denum ); -void ar_encoder_start_fx(PARCODEC arInst, TCQ_PBITSTREAM bsInst, const Word32 max_bits); -void ar_encoder_done_fx(PARCODEC arInst); -void ar_decoder_start_fx(PARCODEC arInst, TCQ_PBITSTREAM bsInst); -void ar_decoder_done_fx(PARCODEC arInst); -Word32 GetISCScale_fx(Word32 *quants_fx, Word16 size, Word32 bits_fx, Word16 *magn_fx, Word32 *qscale_fx, Word32 *surplus_fx, Word16 *pulses, Word32* savedstates, Word32 noTCQ, Word16 *nzpout - , Word16 *bcount, Word32 *abuffer, Word16 *mbuffer, Word32 *sbuffer); +void ar_encoder_start_fx( PARCODEC arInst, TCQ_PBITSTREAM bsInst, const Word32 max_bits ); +void ar_encoder_done_fx( PARCODEC arInst ); +void ar_decoder_start_fx( PARCODEC arInst, TCQ_PBITSTREAM bsInst ); +void ar_decoder_done_fx( PARCODEC arInst ); +Word32 GetISCScale_fx( Word32 *quants_fx, Word16 size, Word32 bits_fx, Word16 *magn_fx, Word32 *qscale_fx, Word32 *surplus_fx, Word16 *pulses, Word32 *savedstates, Word32 noTCQ, Word16 *nzpout, Word16 *bcount, Word32 *abuffer, Word16 *mbuffer, Word32 *sbuffer ); void TCQLSB_fx( - Word16 bcount, - Word32 *abuffer_fx, - Word16 *mbuffer_fx, - Word32 *sbuffer_fx, - Word16 *dpath -); + Word16 bcount, + Word32 *abuffer_fx, + Word16 *mbuffer_fx, + Word32 *sbuffer_fx, + Word16 *dpath ); void TCQLSBdec_fx( - Word16 *dpath, - Word16 *mbuffer, - Word16 bcount -); + Word16 *dpath, + Word16 *mbuffer, + Word16 bcount ); void RestoreTCQ_fx( - Word16 * magn, - Word16 size, - Word16 *bcount, - Word16 *mbuffer -); + Word16 *magn, + Word16 size, + Word16 *bcount, + Word16 *mbuffer ); void RestoreTCQdec_fx( - Word16 * magn, - Word16 size, - Word16 *bcount, - Word16 *mbuffer -); + Word16 *magn, + Word16 size, + Word16 *bcount, + Word16 *mbuffer ); void InitLSBTCQ_fx( - Word16 *bcount -); + Word16 *bcount ); void SaveTCQdata_fx( - PARCODEC arInst, - Word16 *dpath, - Word16 bcount -); + PARCODEC arInst, + Word16 *dpath, + Word16 bcount ); void LoadTCQdata_fx( - PARCODEC arInst, - Word16 *dpath, - Word16 bcount -); + PARCODEC arInst, + Word16 *dpath, + Word16 bcount ); -Word32 encode_position_ari_fx(PARCODEC parenc, Word16* quants, Word16 size, Word32* est_bits_frame_fx); -Word32 encode_magnitude_usq_fx(ARCODEC* parenc, Word16* magn, Word16 size, Word16 npulses, Word16 nzpos, Word32* est_frame_bits_fx); -Word32 encode_magnitude_tcq_fx(ARCODEC* parenc, Word16* magn, Word16 size, Word16 npulses, Word16 nzpos, Word32* savedstates, Word32* est_frame_bits_fx); +Word32 encode_position_ari_fx( PARCODEC parenc, Word16 *quants, Word16 size, Word32 *est_bits_frame_fx ); +Word32 encode_magnitude_usq_fx( ARCODEC *parenc, Word16 *magn, Word16 size, Word16 npulses, Word16 nzpos, Word32 *est_frame_bits_fx ); +Word32 encode_magnitude_tcq_fx( ARCODEC *parenc, Word16 *magn, Word16 size, Word16 npulses, Word16 nzpos, Word32 *savedstates, Word32 *est_frame_bits_fx ); -Word32 encode_signs_fx(ARCODEC* parenc, Word16* magn, Word16 size, Word16 npos, Word32* est_frame_bits_fx); +Word32 encode_signs_fx( ARCODEC *parenc, Word16 *magn, Word16 size, Word16 npos, Word32 *est_frame_bits_fx ); -void decode_position_ari_fx(PARCODEC pardec, Word16 size, Word16 npulses, Word16* nz, Word16* position); -void decode_magnitude_usq_fx(ARCODEC* pardec, Word16 size, Word16 npulses, Word16 nzpos, Word16* positions, Word16* out); -void decode_mangitude_tcq_fx(ARCODEC* pardec, Word16 size, Word16 npulses, Word16 nzpos, Word16* positions, Word16* out, Word32* surplus_fx); -void decode_signs_fx(ARCODEC* pardec, Word16 size, Word16* out); +void decode_position_ari_fx( PARCODEC pardec, Word16 size, Word16 npulses, Word16 *nz, Word16 *position ); +void decode_magnitude_usq_fx( ARCODEC *pardec, Word16 size, Word16 npulses, Word16 nzpos, Word16 *positions, Word16 *out ); +void decode_mangitude_tcq_fx( ARCODEC *pardec, Word16 size, Word16 npulses, Word16 nzpos, Word16 *positions, Word16 *out, Word32 *surplus_fx ); +void decode_signs_fx( ARCODEC *pardec, Word16 size, Word16 *out ); -Word16 GetScale_fx(Word16 blen, Word32 bits_fx, Word32 *surplus_fx); +Word16 GetScale_fx( Word16 blen, Word32 bits_fx, Word32 *surplus_fx ); -void srt_vec_ind_fx(const Word32 *linear, Word32 *srt, Word16 *I, Word16 length); +void srt_vec_ind_fx( const Word32 *linear, Word32 *srt, Word16 *I, Word16 length ); -//fill_spectrum +// fill_spectrum void fill_spectrum_fx( - Word16 *coeff, /* i/o: normalized MLT spectrum / nf spectrum Q12 */ - Word32 *L_coeff_out, /* i/o: Noisefilled MLT spectrum Q12 */ - const Word16 *R, /* i : number of pulses per band Q0 */ - const Word16 is_transient, /* i : transient flag Q0 */ - Word16 norm[], /* i : quantization indices for norms Q0 */ - const Word16 *hq_generic_fenv, /* i : HQ GENERIC envelope Q1 */ - const Word16 hq_generic_offset, /* i : HQ GENERIC offset Q0 */ - const Word16 nf_idx, /* i : noise fill index Q0 */ - const Word16 length, /* i : Length of spectrum (32 or 48 kHz) Q0 */ - const Word16 env_stab, /* i : Envelope stability measure [0..1] Q15 */ - Word16 *no_att_hangover, /* i/o: Frame counter for attenuation hangover Q0 */ - Word32 *L_energy_lt, /* i/o: Long-term energy measure for transient detection Q13 */ - Word16 *bwe_seed, /* i/o: random seed for generating BWE i Q0 */ - const Word16 hq_generic_exc_clas, /* i : BWE excitation class Q0 */ - const Word16 core_sfm, /* i : index of the end band for core Q0 */ - const Word16 HQ_mode, /* i : HQ mode Q0 */ - Word16 noise_level[], /* i : noise levels for harmonic modes Q15 */ - const Word32 L_core_brate, /* i : target bit-rate Q0 */ - Word16 prev_noise_level[], /* i/o: noise factor in previous frame Q15 */ - Word16 *prev_R, /* i/o: bit allocation info. in previous frame Q0 */ - Word32 *prev_coeff_out, /* i/o: decoded spectrum in previous frame Q12 */ - const Word16 *peak_idx, /* i : peak indices for hvq Q0 */ - const Word16 Npeaks, /* i : number of peaks in hvq Q0 */ - const Word16 *npulses, /* i : number of pulses per band Q0 */ - const Word16 prev_is_transient, /* i : previous transient flag Q0 */ - Word32 *prev_normq, /* i/o: previous norms Q14 */ - Word32 *prev_env, /* i/o: previous noise envelopes Q(prev_env_Q) */ - const Word16 prev_bfi, /* i : previous bad frame indicator Q0 */ - const Word16 *sfmsize, /* i : Length of bands Q0 */ - const Word16 *sfm_start, /* i : Start of bands Q0 */ - const Word16 *sfm_end, /* i : End of bands Q0 */ - Word16 *prev_L_swb_norm, /* i/o: HVQ/Harmonic mode normalization length Q0 */ - const Word16 prev_hq_mode, /* i : Previous HQ mode Q0 */ - const Word16 num_sfm, /* i : Total number of bands Q0 */ - Word16 *prev_env_Q, - const Word16 num_env_bands, - const Word16 element_mode -); -//hq_bit_allocation_fx.c" + Word16 *coeff, /* i/o: normalized MLT spectrum / nf spectrum Q12 */ + Word32 *L_coeff_out, /* i/o: Noisefilled MLT spectrum Q12 */ + const Word16 *R, /* i : number of pulses per band Q0 */ + const Word16 is_transient, /* i : transient flag Q0 */ + Word16 norm[], /* i : quantization indices for norms Q0 */ + const Word16 *hq_generic_fenv, /* i : HQ GENERIC envelope Q1 */ + const Word16 hq_generic_offset, /* i : HQ GENERIC offset Q0 */ + const Word16 nf_idx, /* i : noise fill index Q0 */ + const Word16 length, /* i : Length of spectrum (32 or 48 kHz) Q0 */ + const Word16 env_stab, /* i : Envelope stability measure [0..1] Q15 */ + Word16 *no_att_hangover, /* i/o: Frame counter for attenuation hangover Q0 */ + Word32 *L_energy_lt, /* i/o: Long-term energy measure for transient detection Q13 */ + Word16 *bwe_seed, /* i/o: random seed for generating BWE i Q0 */ + const Word16 hq_generic_exc_clas, /* i : BWE excitation class Q0 */ + const Word16 core_sfm, /* i : index of the end band for core Q0 */ + const Word16 HQ_mode, /* i : HQ mode Q0 */ + Word16 noise_level[], /* i : noise levels for harmonic modes Q15 */ + const Word32 L_core_brate, /* i : target bit-rate Q0 */ + Word16 prev_noise_level[], /* i/o: noise factor in previous frame Q15 */ + Word16 *prev_R, /* i/o: bit allocation info. in previous frame Q0 */ + Word32 *prev_coeff_out, /* i/o: decoded spectrum in previous frame Q12 */ + const Word16 *peak_idx, /* i : peak indices for hvq Q0 */ + const Word16 Npeaks, /* i : number of peaks in hvq Q0 */ + const Word16 *npulses, /* i : number of pulses per band Q0 */ + const Word16 prev_is_transient, /* i : previous transient flag Q0 */ + Word32 *prev_normq, /* i/o: previous norms Q14 */ + Word32 *prev_env, /* i/o: previous noise envelopes Q(prev_env_Q) */ + const Word16 prev_bfi, /* i : previous bad frame indicator Q0 */ + const Word16 *sfmsize, /* i : Length of bands Q0 */ + const Word16 *sfm_start, /* i : Start of bands Q0 */ + const Word16 *sfm_end, /* i : End of bands Q0 */ + Word16 *prev_L_swb_norm, /* i/o: HVQ/Harmonic mode normalization length Q0 */ + const Word16 prev_hq_mode, /* i : Previous HQ mode Q0 */ + const Word16 num_sfm, /* i : Total number of bands Q0 */ + Word16 *prev_env_Q, + const Word16 num_env_bands, + const Word16 element_mode ); +// hq_bit_allocation_fx.c" void hq_bit_allocation_fx( - const Word32 core_brate, /* i : Core bit-rate */ - const Word16 length, /* i : Frame length */ - const Word16 hqswb_clas, /* i : HQ class */ - Word16 *num_bits, /* i/o: Remaining bit budget */ - const Word16 *normqlg2, /* i : Quantized norms */ - const Word16 nb_sfm, /* i : Number sub bands to be encoded */ - const Word16 *sfmsize, /* i : Sub band bandwidths */ - Word16 *noise_level, /* o : HVQ noise level */ - Word16 *R, /* o : Bit allocation per sub band */ - Word16 *Rsubband, /* o : Fractional bit allocation */ - Word16 *sum, /* o : Sum of allocated shape bits */ - Word16 *core_sfm, /* o : Last coded band in core */ - const Word16 num_env_bands /* i : Number sub bands to be encoded for HQ_SWB_BWE */ -); - -//weight_fx.c + const Word32 core_brate, /* i : Core bit-rate */ + const Word16 length, /* i : Frame length */ + const Word16 hqswb_clas, /* i : HQ class */ + Word16 *num_bits, /* i/o: Remaining bit budget */ + const Word16 *normqlg2, /* i : Quantized norms */ + const Word16 nb_sfm, /* i : Number sub bands to be encoded */ + const Word16 *sfmsize, /* i : Sub band bandwidths */ + Word16 *noise_level, /* o : HVQ noise level */ + Word16 *R, /* o : Bit allocation per sub band */ + Word16 *Rsubband, /* o : Fractional bit allocation */ + Word16 *sum, /* o : Sum of allocated shape bits */ + Word16 *core_sfm, /* o : Last coded band in core */ + const Word16 num_env_bands /* i : Number sub bands to be encoded for HQ_SWB_BWE */ +); + +// weight_fx.c void map_quant_weight_fx( - const Word16 normqlg2[], /* i : quantized norms */ - Word16 wnorm[], /* o : weighted norm */ - const Word16 is_transient /* i : transient flag */ + const Word16 normqlg2[], /* i : quantized norms */ + Word16 wnorm[], /* o : weighted norm */ + const Word16 is_transient /* i : transient flag */ ); -//bitalloc_fx.c +// bitalloc_fx.c void bitalloc_fx( - Word16 *y, /* i : reordered norm of sub-vectors Q0 */ - Word16 *idx, /* i : reordered sub-vector indices Q0 */ - Word16 sum, /* i : number of available bits Q0 */ - Word16 N, /* i : number of norms Q0 */ - Word16 K, /* i : maximum number of bits per dimension Q0 */ - Word16 *r, /* o : bit-allacation vector Q0 */ - const Word16 *sfmsize, /* i : band length Q0 */ - const Word16 hqswb_clas /* i : signal classification flag Q0 */ + Word16 *y, /* i : reordered norm of sub-vectors Q0 */ + Word16 *idx, /* i : reordered sub-vector indices Q0 */ + Word16 sum, /* i : number of available bits Q0 */ + Word16 N, /* i : number of norms Q0 */ + Word16 K, /* i : maximum number of bits per dimension Q0 */ + Word16 *r, /* o : bit-allacation vector Q0 */ + const Word16 *sfmsize, /* i : band length Q0 */ + const Word16 hqswb_clas /* i : signal classification flag Q0 */ ); Word16 BitAllocF_fx( - Word16 *y, /* i : norm of sub-vectors :Q0 */ - Word32 bit_rate, /* i : bitrate :Q0 */ - Word16 B, /* i : number of available bits :Q0 */ - Word16 N, /* i : number of sub-vectors :Q0 */ - Word16 *R, /* o : bit-allocation indicator :Q0 */ - Word16 *Rsubband_fx, /* o : sub-band bit-allocation vector :Q3 */ - const Word16 hqswb_clas, /* i : hq swb class */ - const Word16 num_env_bands /* i : Number sub bands to be encoded for HQ_SWB_BWE */ -); -Word16 BitAllocWB_fx( /* o : t Q0*/ - Word16 *y, /* i : norm of sub-vectors Q0*/ - Word16 B, /* i : number of available bits Q0*/ - Word16 N, /* i : number of sub-vectors Q0*/ - Word16 *R, /* o : bit-allocation indicator Q0*/ - Word16 *Rsubband_fx /* o : sub-band bit-allocation vector Q3*/ -); -//bitallocsum_fx.c + Word16 *y, /* i : norm of sub-vectors :Q0 */ + Word32 bit_rate, /* i : bitrate :Q0 */ + Word16 B, /* i : number of available bits :Q0 */ + Word16 N, /* i : number of sub-vectors :Q0 */ + Word16 *R, /* o : bit-allocation indicator :Q0 */ + Word16 *Rsubband_fx, /* o : sub-band bit-allocation vector :Q3 */ + const Word16 hqswb_clas, /* i : hq swb class */ + const Word16 num_env_bands /* i : Number sub bands to be encoded for HQ_SWB_BWE */ +); +Word16 BitAllocWB_fx( /* o : t Q0*/ + Word16 *y, /* i : norm of sub-vectors Q0*/ + Word16 B, /* i : number of available bits Q0*/ + Word16 N, /* i : number of sub-vectors Q0*/ + Word16 *R, /* o : bit-allocation indicator Q0*/ + Word16 *Rsubband_fx /* o : sub-band bit-allocation vector Q3*/ +); +// bitallocsum_fx.c void bitallocsum_fx( - Word16 *R, /* i : bit-allocation vector Q0 */ - const Word16 nb_sfm, /* i : number of sub-vectors Q0 */ - Word16 *sum, /* o : total number of bits allocated Q0 */ - Word16 *Rsubband, /* o : rate per subband Q3 */ - const Word16 num_bits,/* i : number of bits Q0 */ - const Word16 length, /* i : length of spectrum (32 or 48 kHz samplerate) Q0 */ - const Word16 *sfmsize /* i : band length Q0 */ + Word16 *R, /* i : bit-allocation vector Q0 */ + const Word16 nb_sfm, /* i : number of sub-vectors Q0 */ + Word16 *sum, /* o : total number of bits allocated Q0 */ + Word16 *Rsubband, /* o : rate per subband Q3 */ + const Word16 num_bits, /* i : number of bits Q0 */ + const Word16 length, /* i : length of spectrum (32 or 48 kHz samplerate) Q0 */ + const Word16 *sfmsize /* i : band length Q0 */ ); -//stab_est_fx.c +// stab_est_fx.c Word16 stab_est_fx( - Word16 etot, /* i : Total energy of the current frame */ - Word16 *lt_diff_etot, /* i/o : Long term total energy variation */ - Word16 *mem_etot, /* i/o : Total energy memory */ - Word16 *nb_thr_3, /* i/o : Number of consecutives frames of level 3 */ - Word16 *nb_thr_1, /* i/o : Number of consecutives frames of level 1 */ - Word16 *thresh, /* i/o : Detection thresold */ - Word16 *last_music_flag,/* i/o : Previous music detection ouptut */ - const Word16 vad_flag /* i : VAD flag */ + Word16 etot, /* i : Total energy of the current frame */ + Word16 *lt_diff_etot, /* i/o : Long term total energy variation */ + Word16 *mem_etot, /* i/o : Total energy memory */ + Word16 *nb_thr_3, /* i/o : Number of consecutives frames of level 3 */ + Word16 *nb_thr_1, /* i/o : Number of consecutives frames of level 1 */ + Word16 *thresh, /* i/o : Detection thresold */ + Word16 *last_music_flag, /* i/o : Previous music detection ouptut */ + const Word16 vad_flag /* i : VAD flag */ ); -//enhancer_fx.c +// enhancer_fx.c void enhancer_fx( - const Word32 core_brate, /* i : decoder bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 coder_type, /* i : coder type */ - const Word16 i_subfr, /* i : subframe number */ - const Word16 L_frame, /* i : frame size */ - const Word16 voice_fac, /* i : subframe voicing estimation Q15 */ - const Word16 stab_fac, /* i : LP filter stablility measure Q15 */ - Word32 norm_gain_code,/* i : normalised innovative cb. gain Q16 */ - const Word16 gain_inov, /* i : gain of the unscaled innovation Q12 */ - Word32 *gc_threshold, /* i/o: gain code threshold Q16 */ - Word16 *code, /* i/o: innovation Q12 */ - Word16 *exc2, /* i/o: adapt. excitation/total exc. Q_exc*/ - const Word16 gain_pit, /* i : quantized pitch gain Q14 */ - struct dispMem_fx *dm_fx, /* i/o: phase dispersion algorithm memory */ - const Word16 Q_exc /* i : Q of the excitation */ + const Word32 core_brate, /* i : decoder bitrate */ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const Word16 coder_type, /* i : coder type */ + const Word16 i_subfr, /* i : subframe number */ + const Word16 L_frame, /* i : frame size */ + const Word16 voice_fac, /* i : subframe voicing estimation Q15 */ + const Word16 stab_fac, /* i : LP filter stablility measure Q15 */ + Word32 norm_gain_code, /* i : normalised innovative cb. gain Q16 */ + const Word16 gain_inov, /* i : gain of the unscaled innovation Q12 */ + Word32 *gc_threshold, /* i/o: gain code threshold Q16 */ + Word16 *code, /* i/o: innovation Q12 */ + Word16 *exc2, /* i/o: adapt. excitation/total exc. Q_exc*/ + const Word16 gain_pit, /* i : quantized pitch gain Q14 */ + struct dispMem_fx *dm_fx, /* i/o: phase dispersion algorithm memory */ + const Word16 Q_exc /* i : Q of the excitation */ ); void enhancer_ivas_fx( - const Word16 codec_mode, /* i : flag indicating Codec Mode */ - const Word32 core_brate, /* i : decoder bitrate */ - const int16_t cbk_index, /* i : */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 coder_type, /* i : coder type */ - const Word16 i_subfr, /* i : subframe number */ - const Word16 L_frame, /* i : frame size */ - const Word16 voice_fac, /* i : subframe voicing estimation Q15 */ - const Word16 stab_fac, /* i : LP filter stablility measure Q15 */ - Word32 norm_gain_code, /* i : normalised innovative cb. gain Q16 */ - const Word16 gain_inov, /* i : gain of the unscaled innovation Q12 */ - Word32 *gc_threshold,/* i/o: gain code threshold Q16 */ - Word16 *code, /* i/o: innovation Q12 */ - Word16 *exc2, /* i/o: adapt. excitation/total exc. Q_exc*/ - const Word16 gain_pit, /* i : quantized pitch gain Q14 */ - struct dispMem_fx *dm_fx, /* i/o: phase dispersion algorithm memory */ - const Word16 Q_exc /* i : Q of the excitation */ + const Word16 codec_mode, /* i : flag indicating Codec Mode */ + const Word32 core_brate, /* i : decoder bitrate */ + const int16_t cbk_index, /* i : */ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const Word16 coder_type, /* i : coder type */ + const Word16 i_subfr, /* i : subframe number */ + const Word16 L_frame, /* i : frame size */ + const Word16 voice_fac, /* i : subframe voicing estimation Q15 */ + const Word16 stab_fac, /* i : LP filter stablility measure Q15 */ + Word32 norm_gain_code, /* i : normalised innovative cb. gain Q16 */ + const Word16 gain_inov, /* i : gain of the unscaled innovation Q12 */ + Word32 *gc_threshold, /* i/o: gain code threshold Q16 */ + Word16 *code, /* i/o: innovation Q12 */ + Word16 *exc2, /* i/o: adapt. excitation/total exc. Q_exc*/ + const Word16 gain_pit, /* i : quantized pitch gain Q14 */ + struct dispMem_fx *dm_fx, /* i/o: phase dispersion algorithm memory */ + const Word16 Q_exc /* i : Q of the excitation */ ); Word16 E_UTIL_enhancer( - Word16 voice_fac, /* i : subframe voicing estimation Q15 */ - Word16 stab_fac, /* i : LP filter stability measure Q15 */ - Word32 gain_code, /* i : innovative cb. gain 15Q16 */ - Word16 gain_inov, /* i : gain of the unscaled innovation Q12 */ - Word32 *gc_threshold, /* i/o: gain code threshold 15Q16 */ - Word16 *code, /* i/o: innovation(in: Q9) code_exp */ - Word16 *exc2, /* i/o: adapt. excitation/total exc. Q15 */ - Word16 gain_pit, /* i : Quantized pitch gain 1Q14 */ - Word32 *prev_gain_code, /* i/o: previous codebook gain 15Q16 */ - Word16 prev_gain_pit[], /* i/o: previous pitch gain, size=6 1Q14 */ - Word16 *prev_state, /* i/o: Phase dispersion algorithm memory Q0 */ - Word16 coder_type, /* i : coder type */ - Word16 cdk_index, /* i : */ - Word16 L_subfr, /* i : */ - Word16 L_frame, /* i : frame size */ - Word16 Q_new -); - - -//phase_dispersion_fx.c + Word16 voice_fac, /* i : subframe voicing estimation Q15 */ + Word16 stab_fac, /* i : LP filter stability measure Q15 */ + Word32 gain_code, /* i : innovative cb. gain 15Q16 */ + Word16 gain_inov, /* i : gain of the unscaled innovation Q12 */ + Word32 *gc_threshold, /* i/o: gain code threshold 15Q16 */ + Word16 *code, /* i/o: innovation(in: Q9) code_exp */ + Word16 *exc2, /* i/o: adapt. excitation/total exc. Q15 */ + Word16 gain_pit, /* i : Quantized pitch gain 1Q14 */ + Word32 *prev_gain_code, /* i/o: previous codebook gain 15Q16 */ + Word16 prev_gain_pit[], /* i/o: previous pitch gain, size=6 1Q14 */ + Word16 *prev_state, /* i/o: Phase dispersion algorithm memory Q0 */ + Word16 coder_type, /* i : coder type */ + Word16 cdk_index, /* i : */ + Word16 L_subfr, /* i : */ + Word16 L_frame, /* i : frame size */ + Word16 Q_new ); + + +// phase_dispersion_fx.c void phase_dispersion( - const Word32 gain_code, /* i : gain of code 15Q16 */ - const Word16 gain_pit, /* i : gain of pitch Q14 */ - Word16 code[], /* i/o: code vector */ - Word16 *code_e, /* i/o: exponent of code */ - const Word16 mode, /* i : level, 0=hi, 1=lo, 2=off */ - Word32 *prev_gain_code, /* i/o: static memory 15Q16 */ - Word16 prev_gain_pit[], /* i/o: static memory Q14, size=6 */ - Word16 *prev_state, /* i/o: static memory Q0 */ - Word16 L_subfr /* i : subframe length [40,64] */ -); - -//tcx_ltp_fx.c + const Word32 gain_code, /* i : gain of code 15Q16 */ + const Word16 gain_pit, /* i : gain of pitch Q14 */ + Word16 code[], /* i/o: code vector */ + Word16 *code_e, /* i/o: exponent of code */ + const Word16 mode, /* i : level, 0=hi, 1=lo, 2=off */ + Word32 *prev_gain_code, /* i/o: static memory 15Q16 */ + Word16 prev_gain_pit[], /* i/o: static memory Q14, size=6 */ + Word16 *prev_state, /* i/o: static memory Q0 */ + Word16 L_subfr /* i : subframe length [40,64] */ +); + +// tcx_ltp_fx.c void tcx_ltp_get_lpc( - Word16* x, - const Word16 L, - Word16* A, - const Word16 order -); + Word16 *x, + const Word16 L, + Word16 *A, + const Word16 order ); void tcx_ltp_get_lpc_fx( Word32 *x, @@ -5329,75 +5180,77 @@ void tcx_ltp_get_lpc_fx( const Word16 order ); void predict_signal( - const Word16 excI[], /* i : i excitation buffer */ - Word16 excO[], /* o : output excitation buffer */ - const Word16 T0, /* i : integer pitch lag */ - Word16 frac, /* i : fraction of lag */ - const Word16 frac_max, /* i : max fraction */ - const Word16 L_subfr /* i : subframe size */ -); - -Word16 tcx_ltp_decode_params(Word16 *ltp_param, - Word16 *pitch_int, - Word16 *pitch_fr, - Word16 *gain, - const Word16 pitmin, - const Word16 pitfr1, - const Word16 pitfr2, - const Word16 pitmax, - const Word16 pitres -); + const Word16 excI[], /* i : i excitation buffer */ + Word16 excO[], /* o : output excitation buffer */ + const Word16 T0, /* i : integer pitch lag */ + Word16 frac, /* i : fraction of lag */ + const Word16 frac_max, /* i : max fraction */ + const Word16 L_subfr /* i : subframe size */ +); + +Word16 tcx_ltp_decode_params( Word16 *ltp_param, + Word16 *pitch_int, + Word16 *pitch_fr, + Word16 *gain, + const Word16 pitmin, + const Word16 pitfr1, + const Word16 pitfr2, + const Word16 pitmax, + const Word16 pitres ); void tcx_ltp_post( - Decoder_State* st, - TCX_LTP_DEC_HANDLE hTcxLtpDec, - Word16 core, - Word16 output_frame, - Word16 delay, - Word16* sig, - Word16* tcx_buf -); + Decoder_State *st, + TCX_LTP_DEC_HANDLE hTcxLtpDec, + Word16 core, + Word16 output_frame, + Word16 delay, + Word16 *sig, + Word16 *tcx_buf ); void tcx_ltp_post32( - Decoder_State* st, - TCX_LTP_DEC_HANDLE hTcxLtpDec, - Word16 core, - Word16 output_frame, - Word16 delay, - Word32* sig, - Word32* tcx_buf -); - -//gs_inact_switching_fx.c + Decoder_State *st, + TCX_LTP_DEC_HANDLE hTcxLtpDec, + Word16 core, + Word16 output_frame, + Word16 delay, + Word32 *sig, + Word32 *tcx_buf ); + +// gs_inact_switching_fx.c void Inac_swtch_ematch_fx( - Word16 exc2[], /* i/o: CELP/GSC excitation buffer Q_exc*/ - Word16 dct_exc_tmp[], /* i : GSC excitation in DCT domain */ - Word16 lt_ener_per_band[], /* i/o: Long term energy per band Q12 */ - const Word16 coder_type, /* i : Coding mode */ - const Word16 L_frame, /* i : Frame lenght */ - const Word32 core_brate, /* i : Core bit rate */ - const Word16 Q_exc /* i : i and output format of exc2 */ - , const Word16 bfi /* i : frame lost indicator */ - , const short last_core, /* i : Last core used */ - const short last_codec_mode /* i : Last codec mode */ + Word16 exc2[], /* i/o: CELP/GSC excitation buffer Q_exc*/ + Word16 dct_exc_tmp[], /* i : GSC excitation in DCT domain */ + Word16 lt_ener_per_band[], /* i/o: Long term energy per band Q12 */ + const Word16 coder_type, /* i : Coding mode */ + const Word16 L_frame, /* i : Frame lenght */ + const Word32 core_brate, /* i : Core bit rate */ + const Word16 Q_exc /* i : i and output format of exc2 */ + , + const Word16 bfi /* i : frame lost indicator */ + , + const short last_core, /* i : Last core used */ + const short last_codec_mode /* i : Last codec mode */ ); void Inac_switch_ematch_ivas_fx( - Word16 exc2[], /* i/o: CELP/GSC excitation buffer Q_exc*/ - Word16 dct_exc_tmp[], /* i : GSC excitation in DCT domain */ - Word16 lt_ener_per_band[], /* i/o: Long term energy per band Q12 */ - const Word16 coder_type, /* i : Coding mode */ - const Word16 L_frame, /* i : Frame lenght */ - const Word32 core_brate, /* i : Core bit rate */ - const Word16 Q_exc /* i : input and output format of exc2 */ - , const Word16 bfi /* i : frame lost indicator */ - , const Word16 last_core, /* i : Last core used */ - const Word16 last_codec_mode /* i : Last codec mode */ - , const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag*/ + Word16 exc2[], /* i/o: CELP/GSC excitation buffer Q_exc*/ + Word16 dct_exc_tmp[], /* i : GSC excitation in DCT domain */ + Word16 lt_ener_per_band[], /* i/o: Long term energy per band Q12 */ + const Word16 coder_type, /* i : Coding mode */ + const Word16 L_frame, /* i : Frame lenght */ + const Word32 core_brate, /* i : Core bit rate */ + const Word16 Q_exc /* i : input and output format of exc2 */ + , + const Word16 bfi /* i : frame lost indicator */ + , + const Word16 last_core, /* i : Last core used */ + const Word16 last_codec_mode /* i : Last codec mode */ + , + const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag*/ const Word16 element_mode /* i : element mode */ ); -//igf_base_fx.c +// igf_base_fx.c Word16 IGF_ApplyTransFac( /**< out: Q0 | multiplication factor */ const Word16 val, /**< in: Q15 | input value for multiplication, Q15 */ const Word16 transFac /**< in: Q14 | multiplicator for variable val, Q14: 1.25f=0x5000, 1.0f=0x4000, 0.5f=0x2000 */ @@ -5410,155 +5263,153 @@ Word16 IGF_MapBitRateToIndex( const Word16 rf_mode /* i : flag to signal the RF mode */ ); -void IGFCommonFuncsCalcSfbEnergyPowerSpec(const Word16 startSfb, /**< in: Q0 | start sfb index */ - const Word16 stopSfb, /**< in: Q0 | stop sfb index */ - const Word16 *swb_offset, /**< in: Q0 | IGF swb offset table */ - Word32 *pPowerSpectrum, /**< in: Q31 | power spectrum */ - Word16 *pPowerSpectrum_exp, /**< in: | Exponent of PowerSpectrum */ - Word32 *sfbEnergy, /**< out:Q31 | SFB energies , will be initialized inside this function */ - Word16 *sfbEnergy_exp /**< out: | Exponent of PowerSpectrum */ +void IGFCommonFuncsCalcSfbEnergyPowerSpec( const Word16 startSfb, /**< in: Q0 | start sfb index */ + const Word16 stopSfb, /**< in: Q0 | stop sfb index */ + const Word16 *swb_offset, /**< in: Q0 | IGF swb offset table */ + Word32 *pPowerSpectrum, /**< in: Q31 | power spectrum */ + Word16 *pPowerSpectrum_exp, /**< in: | Exponent of PowerSpectrum */ + Word32 *sfbEnergy, /**< out:Q31 | SFB energies , will be initialized inside this function */ + Word16 *sfbEnergy_exp /**< out: | Exponent of PowerSpectrum */ ); -void IGFCommonFuncsMDCTSquareSpec(const Word16 sqrtBgn, /**< in: Q0 | start MDCT subband index */ - const Word16 sqrtEnd, /**< in: Q0 | stop MDCT subband index */ - const Word32 *mdctSpec, /**< in: Q31 | MDCT spectrum to square */ - const Word16 mdctSpec_e, /**< in: | exponent of mdctSpectrum */ - Word32 *mdctSquareSpec, /**< out:Q31 | MDCT square spectrum */ - Word16 *mdctSquareSpec_e, /**< out: | exponent of mdctSquareSpec */ - Word16 indexOffset /**< in: Q0 | index offset */ +void IGFCommonFuncsMDCTSquareSpec( const Word16 sqrtBgn, /**< in: Q0 | start MDCT subband index */ + const Word16 sqrtEnd, /**< in: Q0 | stop MDCT subband index */ + const Word32 *mdctSpec, /**< in: Q31 | MDCT spectrum to square */ + const Word16 mdctSpec_e, /**< in: | exponent of mdctSpectrum */ + Word32 *mdctSquareSpec, /**< out:Q31 | MDCT square spectrum */ + Word16 *mdctSquareSpec_e, /**< out: | exponent of mdctSquareSpec */ + Word16 indexOffset /**< in: Q0 | index offset */ ); void IGFCommonFuncsMDCTSquareSpec_ivas( - const Word16 sqrtBgn, /**< in: Q0 | start MDCT subband index */ - const Word16 sqrtEnd, /**< in: Q0 | stop MDCT subband index */ - const Word32 *mdctSpec, /**< in: Q31 | MDCT spectrum to square */ - const Word16 mdctSpec_e, /**< in: | exponent of mdctSpectrum */ - Word32 *mdctSquareSpec, /**< out:Q31 | MDCT square spectrum */ - Word16 *mdctSquareSpec_e, /**< out: | exponent of mdctSquareSpec */ - Word16 indexOffset /**< in: Q0 | index offset */ + const Word16 sqrtBgn, /**< in: Q0 | start MDCT subband index */ + const Word16 sqrtEnd, /**< in: Q0 | stop MDCT subband index */ + const Word32 *mdctSpec, /**< in: Q31 | MDCT spectrum to square */ + const Word16 mdctSpec_e, /**< in: | exponent of mdctSpectrum */ + Word32 *mdctSquareSpec, /**< out:Q31 | MDCT square spectrum */ + Word16 *mdctSquareSpec_e, /**< out: | exponent of mdctSquareSpec */ + Word16 indexOffset /**< in: Q0 | index offset */ ); void IGFCommonFuncsWriteSerialBit( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - Word16* pBitOffset, /**< out: Q0 | bit offset */ - Word16 bit /**< in: Q0 | value of bit */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 *pBitOffset, /**< out: Q0 | bit offset */ + Word16 bit /**< in: Q0 | value of bit */ ); Word16 IGFCommonFuncsIGFConfiguration( - const Word32 total_brate, /* i : bitrate in bs e.g. 9600 for 9.6kbs */ - const Word16 bwidth, /* i : audio bandwidth */ - const Word16 element_mode, /* i : element mode */ - H_IGF_INFO hIGFInfo, /* o : IGF info handle */ - const Word16 rf_mode /* i : flag to signal the RF mode */ + const Word32 total_brate, /* i : bitrate in bs e.g. 9600 for 9.6kbs */ + const Word16 bwidth, /* i : audio bandwidth */ + const Word16 element_mode, /* i : element mode */ + H_IGF_INFO hIGFInfo, /* o : IGF info handle */ + const Word16 rf_mode /* i : flag to signal the RF mode */ ); #ifdef IVAS_FLOAT_FIXED Word16 IGFCommonFuncsIGFConfiguration_ivas_fx( - const Word32 total_brate, /* i : bitrate in bs e.g. 9600 for 9.6kbs */ - const Word16 bwidth, /* i : audio bandwidth */ - const Word16 element_mode, /* i : element mode */ - H_IGF_INFO hIGFInfo, /* o : IGF info handle */ - const Word16 rf_mode /* i : flag to signal the RF mode */ + const Word32 total_brate, /* i : bitrate in bs e.g. 9600 for 9.6kbs */ + const Word16 bwidth, /* i : audio bandwidth */ + const Word16 element_mode, /* i : element mode */ + H_IGF_INFO hIGFInfo, /* o : IGF info handle */ + const Word16 rf_mode /* i : flag to signal the RF mode */ ); #endif // IVAS_FOAT_FIXED Word16 IGFCommonFuncsIGFGetCFTables( - const Word32 total_brate, /* i : bitrate in bs e.g. 9600 for 9.6kbs */ - const Word16 bwidth, /* i : audio bandwidth */ - const Word16 element_mode, /* i : element mode */ - const Word16 rf_mode, /* i : flag to signal the RF mode */ - const uint16_t** cf_se00, /* o : CF table for t == 0 and f == 0 */ - const uint16_t** cf_se01, /* o : CF table for t == 0 and f == 1 */ - Word16* cf_off_se01, /* o : offset for CF table above */ - const uint16_t** cf_se02, /* o : CF tables for t == 0 and f >= 2 */ - const Word16** cf_off_se02, /* o : offsets for CF tables above */ - const uint16_t** cf_se10, /* o : CF table for t == 1 and f == 0 */ - Word16* cf_off_se10, /* o : offset for CF table above */ - const uint16_t** cf_se11, /* o : CF tables for t == 1 and f >= 1 */ - const Word16** cf_off_se11 /* o : offsets for CF tables above */ -); -//ari_fx.c -Word32 L_multi31x16_X2(Word16 xh, Word16 xl, Word16 y); -Word32 mul_sbc_14bits(Word32 r, Word16 c); - -//window.c -void ham_cos_window(Word16 *fh, const Word16 n1, const Word16 n2); - -void ham_cos_window_ivas(Word16 *fh, const Word16 n1, const Word16 n2); - -//arith_coder_fx.c -Word32 expfp( /* o: Q31 */ - const Word16 x, /* i: mantissa Q-e */ - const Word16 x_e); /* i: exponent Q0 */ + const Word32 total_brate, /* i : bitrate in bs e.g. 9600 for 9.6kbs */ + const Word16 bwidth, /* i : audio bandwidth */ + const Word16 element_mode, /* i : element mode */ + const Word16 rf_mode, /* i : flag to signal the RF mode */ + const uint16_t **cf_se00, /* o : CF table for t == 0 and f == 0 */ + const uint16_t **cf_se01, /* o : CF table for t == 0 and f == 1 */ + Word16 *cf_off_se01, /* o : offset for CF table above */ + const uint16_t **cf_se02, /* o : CF tables for t == 0 and f >= 2 */ + const Word16 **cf_off_se02, /* o : offsets for CF tables above */ + const uint16_t **cf_se10, /* o : CF table for t == 1 and f == 0 */ + Word16 *cf_off_se10, /* o : offset for CF table above */ + const uint16_t **cf_se11, /* o : CF tables for t == 1 and f >= 1 */ + const Word16 **cf_off_se11 /* o : offsets for CF tables above */ +); +// ari_fx.c +Word32 L_multi31x16_X2( Word16 xh, Word16 xl, Word16 y ); +Word32 mul_sbc_14bits( Word32 r, Word16 c ); + +// window.c +void ham_cos_window( Word16 *fh, const Word16 n1, const Word16 n2 ); + +void ham_cos_window_ivas( Word16 *fh, const Word16 n1, const Word16 n2 ); + +// arith_coder_fx.c +Word32 expfp( /* o: Q31 */ + const Word16 x, /* i: mantissa Q-e */ + const Word16 x_e ); /* i: exponent Q0 */ void powfp_odd2( - const Word16 base, /* Q15 */ - const Word16 exp, /* Q0 */ - Word16 *pout1, /* Q15 */ - Word16 *pout2); /* Q15 */ + const Word16 base, /* Q15 */ + const Word16 exp, /* Q0 */ + Word16 *pout1, /* Q15 */ + Word16 *pout2 ); /* Q15 */ void tcx_arith_scale_envelope( - const Word16 L_spec_core, /* i: number of lines to scale Q0 */ - Word16 L_frame, /* i: number of lines Q0 */ - const Word32 env[], /* i: unscaled envelope Q16 */ - Word16 target_bits, /* i: number of available bits Q0 */ - const Word16 low_complexity,/* i: low-complexity flag Q0 */ - Word16 s_env[], /* o: scaled envelope Q15-e */ - Word16 *s_env_e /* o: scaled envelope exponent Q0 */ + const Word16 L_spec_core, /* i: number of lines to scale Q0 */ + Word16 L_frame, /* i: number of lines Q0 */ + const Word32 env[], /* i: unscaled envelope Q16 */ + Word16 target_bits, /* i: number of available bits Q0 */ + const Word16 low_complexity, /* i: low-complexity flag Q0 */ + Word16 s_env[], /* o: scaled envelope Q15-e */ + Word16 *s_env_e /* o: scaled envelope exponent Q0 */ ); void tcx_arith_render_envelope( - const Word16 A_ind[], /* i: LPC coefficients of signal envelope */ - const Word16 L_frame, /* i: number of spectral lines */ - const Word16 L_spec, - const Word16 preemph_fac, /* i: pre-emphasis factor */ - const Word16 gamma_w, /* i: A_ind -> weighted envelope factor */ - const Word16 gamma_uw, /* i: A_ind -> non-weighted envelope factor */ - Word32 env[] /* o: shaped signal envelope */ + const Word16 A_ind[], /* i: LPC coefficients of signal envelope */ + const Word16 L_frame, /* i: number of spectral lines */ + const Word16 L_spec, + const Word16 preemph_fac, /* i: pre-emphasis factor */ + const Word16 gamma_w, /* i: A_ind -> weighted envelope factor */ + const Word16 gamma_uw, /* i: A_ind -> non-weighted envelope factor */ + Word32 env[] /* o: shaped signal envelope */ ); -//gain_inov_fx.c -Word32 calc_gain_inov( /* returns innovation gain Q16 */ - const Word16 *code, /* i : algebraic excitation Q9 */ - const Word16 lcode, /* i : Subframe size Q0 */ - Word32 *dotp, /* o : intermediate result Q31-e */ - Word16 *dotp_e /* o : intermediate result exponent Q0 */ +// gain_inov_fx.c +Word32 calc_gain_inov( /* returns innovation gain Q16 */ + const Word16 *code, /* i : algebraic excitation Q9 */ + const Word16 lcode, /* i : Subframe size Q0 */ + Word32 *dotp, /* o : intermediate result Q31-e */ + Word16 *dotp_e /* o : intermediate result exponent Q0 */ ); /////////////////////////////////// /* Lib_dec */ ////////////////////////////////// -//swb_tbe_dec.c +// swb_tbe_dec.c void InitSWBdecBuffer_fx( - Decoder_State *swb_dnc_fx /* i/o: SHB decoder structure */ + Decoder_State *swb_dnc_fx /* i/o: SHB decoder structure */ ); void ResetSHBbuffer_Dec_fx( - Decoder_State *st_fx /* i/o: decoder state structure */ + Decoder_State *st_fx /* i/o: decoder state structure */ ); void wb_tbe_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 coder_type, /* i : coding type */ - Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation */ - const Word16 Q_exc, - const Word16 voice_factors[], /* i : voicing factors */ - Word16 *synth, /* i/o: ACELP core synthesis/final synthesis */ - Word16 *Q_synth -); + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 coder_type, /* i : coding type */ + Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation */ + const Word16 Q_exc, + const Word16 voice_factors[], /* i : voicing factors */ + Word16 *synth, /* i/o: ACELP core synthesis/final synthesis */ + Word16 *Q_synth ); void swb_tbe_dec_fx( - Decoder_State* st_fx, /* i/o: decoder state structure */ - const Word16 coder_type, /* i : coding type */ - Word32* bwe_exc_extended, /* i : bandwidth extended exciatation 2*Q_exc*/ - Word16 Q_exc, - const Word16 voice_factors[], /* i : voicing factors */ - const Word16 old_syn_12k8_16k[], /* i : low band synthesis*/ - Word16* White_exc16k, /* o : shaped white excitation for the FB TBE */ - Word16* Q_white_exc, - Word16* synth, /* o : SHB synthesis/final synthesis */ - Word16* Q_synth, - Word16* pitch_buf -); + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 coder_type, /* i : coding type */ + Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation 2*Q_exc*/ + Word16 Q_exc, + const Word16 voice_factors[], /* i : voicing factors */ + const Word16 old_syn_12k8_16k[], /* i : low band synthesis*/ + Word16 *White_exc16k, /* o : shaped white excitation for the FB TBE */ + Word16 *Q_white_exc, + Word16 *synth, /* o : SHB synthesis/final synthesis */ + Word16 *Q_synth, + Word16 *pitch_buf ); void ivas_dequantizeSHBparams_fx_9_1( Decoder_State *st_fx, @@ -5570,58 +5421,54 @@ void ivas_dequantizeSHBparams_fx_9_1( Word16 *uv_flag, /* o : unvoiced flag*/ Word32 *Q_shb_ener_sf, /* o : Q15 */ Word16 *Q_shb_res_gshape, /* o : Q14 */ - Word16 *Q_mixFactors, /* o : Q15 */ - Word16 *MSFlag -); + Word16 *Q_mixFactors, /* o : Q15 */ + Word16 *MSFlag ); void fb_tbe_dec_fx( - Decoder_State *st, /* i/o: encoder state structure */ - const Word16 fb_exc[], /* i : FB excitation from the SWB part */ - Word16 Q_fb_exc, - Word16 *hb_synth, /* o : high-band synthesis */ - Word16 hb_synth_exp -); + Decoder_State *st, /* i/o: encoder state structure */ + const Word16 fb_exc[], /* i : FB excitation from the SWB part */ + Word16 Q_fb_exc, + Word16 *hb_synth, /* o : high-band synthesis */ + Word16 hb_synth_exp ); void fb_tbe_dec_ivas_fx( - Decoder_State *st, /* i/o: encoder state structure */ - const Word16 fb_exc[], /* i : FB excitation from the SWB part */ - Word16 Q_fb_exc, - Word32 *hb_synth, /* o : high-band synthesis */ - Word16 hb_synth_exp, - Word16 *fb_synth_ref, - Word16 Q_fb_synth_ref, - Word16 output_frame); + Decoder_State *st, /* i/o: encoder state structure */ + const Word16 fb_exc[], /* i : FB excitation from the SWB part */ + Word16 Q_fb_exc, + Word32 *hb_synth, /* o : high-band synthesis */ + Word16 hb_synth_exp, + Word16 *fb_synth_ref, + Word16 Q_fb_synth_ref, + Word16 output_frame ); void tbe_read_bitstream_fx( - Decoder_State *st_fx /* i/o: encoder state structure */ + Decoder_State *st_fx /* i/o: encoder state structure */ ); void GenTransition_fx( - const Word16 *i, /* i : gain shape overlap buffer */ - const Word16 *old_hb_synth, /* i : synthesized HB from previous frame */ - Word16 length, /* i : targeted length of transition signal */ - Word16 *output, /* o : synthesized transitions signal */ - Word32 Hilbert_Mem[], /* i/o: memory */ - Word16 state_lsyn_filt_shb_local[],/* i/o: memory */ - Word16 mem_resamp_HB_32k[], /* i/o: memory */ - Word16 *syn_dm_phase, - Word32 output_Fs, - Word16 *up_mem, - Word16 rf_flag - , Word32 bitrate -); + const Word16 *i, /* i : gain shape overlap buffer */ + const Word16 *old_hb_synth, /* i : synthesized HB from previous frame */ + Word16 length, /* i : targeted length of transition signal */ + Word16 *output, /* o : synthesized transitions signal */ + Word32 Hilbert_Mem[], /* i/o: memory */ + Word16 state_lsyn_filt_shb_local[], /* i/o: memory */ + Word16 mem_resamp_HB_32k[], /* i/o: memory */ + Word16 *syn_dm_phase, + Word32 output_Fs, + Word16 *up_mem, + Word16 rf_flag, + Word32 bitrate ); void GenTransition_WB_fx( - const Word16 *i, /* i : gain shape overlap buffer */ - const Word16 *old_hb_synth, /* i : synthesized HB from previous frame */ - const Word16 prev_Qx, /* i : scaling of old_hb_synth */ - Word16 length, /* i : targeted length of transition signal */ - Word16 *output, /* o : synthesized transitions signal */ - Word16 state_lsyn_filt_shb1[], - Word16 state_lsyn_filt_shb2[], - Word32 output_Fs, - Word16 *up_mem -); + const Word16 *i, /* i : gain shape overlap buffer */ + const Word16 *old_hb_synth, /* i : synthesized HB from previous frame */ + const Word16 prev_Qx, /* i : scaling of old_hb_synth */ + Word16 length, /* i : targeted length of transition signal */ + Word16 *output, /* o : synthesized transitions signal */ + Word16 state_lsyn_filt_shb1[], + Word16 state_lsyn_filt_shb2[], + Word32 output_Fs, + Word16 *up_mem ); #ifdef IVAS_FLOAT_FIXED void TBEreset_dec_ivas_fx( Decoder_State *st /* i/o: decoder state structure */ @@ -5629,31 +5476,32 @@ void TBEreset_dec_ivas_fx( #endif // IVAS_FLOAT_FIXED void TBEreset_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 bandwidth /* i : bandwidth mode */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 bandwidth /* i : bandwidth mode */ ); void td_bwe_dec_init_fx( - Decoder_State* st_fx, /* i/o: SHB decoder structure */ - TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ -#ifdef ADD_IVAS_BWE - const Word16 extl, /* i : BWE extension layer */ + Decoder_State *st_fx, /* i/o: SHB decoder structure */ + TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ +#ifdef ADD_IVAS_BWE + const Word16 extl, /* i : BWE extension layer */ #endif - const Word32 output_Fs /* i : output sampling rate */ + const Word32 output_Fs /* i : output sampling rate */ ); -//lsf_dec_fx.c +// lsf_dec_fx.c void lsf_dec_fx( - Decoder_State* st_fx, /* i/o: State structure */ - const Word16 tc_subfr, /* i : TC subframe index */ - Word16* Aq, /* o : quantized A(z) for 4 subframes */ - Word16* LSF_Q_prediction, /* o : LSF prediction mode */ - Word16* lsf_new, /* o : de-quantized LSF vector */ - Word16* lsp_new, /* o : de-quantized LSP vector */ - Word16* lsp_mid, /* o : de-quantized mid-frame LSP vector */ - const Word16 tdm_low_rate_mode /* i : secondary channel low rate mode flag */ + Decoder_State *st_fx, /* i/o: State structure */ + const Word16 tc_subfr, /* i : TC subframe index */ + Word16 *Aq, /* o : quantized A(z) for 4 subframes */ + Word16 *LSF_Q_prediction, /* o : LSF prediction mode */ + Word16 *lsf_new, /* o : de-quantized LSF vector */ + Word16 *lsp_new, /* o : de-quantized LSP vector */ + Word16 *lsp_mid, /* o : de-quantized mid-frame LSP vector */ + const Word16 tdm_low_rate_mode /* i : secondary channel low rate mode flag */ #ifdef LSF_RE_USE_SECONDARY_CHANNEL - , const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ + , + const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ #endif ); @@ -5742,9 +5590,9 @@ Word32 dotp_fixed( /*! r: dot product of x[] and y[] in case of overflow*/ Word32 dotp_fixed_o( - const Word32 x[], /* i : vector x[] */ - const Word32 y[], /* i : vector y[] */ - const Word16 n, /* i : vector length */ + const Word32 x[], /* i : vector x[] */ + const Word32 y[], /* i : vector y[] */ + const Word16 n, /* i : vector length */ const Word16 log_len, /* i : max factor added to result q after dot product (equal to log2(n)) */ Word16 *res_q ); #ifdef IVAS_FLOAT_FIXED @@ -5756,157 +5604,156 @@ Word32 dotp_fixed_guarded( #endif void lsf_end_dec_fx( - Decoder_State* st, /* i/o: decoder state structure */ - Word16 mode2_flag, - const Word16 coder_type_org, /* i : coding type */ - const Word16 bwidth, /* i : i signal bandwidth */ - const Word16 nBits_in, /* i : number of bits used for ISF quantization*/ - Word16* qlsf, /* o : quantized LSFs in the cosine domain */ - Word16* lpc_param, - Word16* LSF_Q_prediction, /* o : LSF prediction mode */ - Word16* nb_indices + Decoder_State *st, /* i/o: decoder state structure */ + Word16 mode2_flag, + const Word16 coder_type_org, /* i : coding type */ + const Word16 bwidth, /* i : i signal bandwidth */ + const Word16 nBits_in, /* i : number of bits used for ISF quantization*/ + Word16 *qlsf, /* o : quantized LSFs in the cosine domain */ + Word16 *lpc_param, + Word16 *LSF_Q_prediction, /* o : LSF prediction mode */ + Word16 *nb_indices #ifdef LSF_RE_USE_SECONDARY_CHANNEL - , const float tdm_lsfQ_PCh[M] + , + const float tdm_lsfQ_PCh[M] #endif ); void lsf_mid_dec_fx( - Decoder_State* st_fx, /* i/o: decoder state structure */ - Word16 lsp_new[], /* i : quantized LSPs from frame endSQ15*/ - Word16 coder_type, /* i : Coder type */ - Word16 lsp_mid[] /* o : quantized LSPs Q15*/ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 lsp_new[], /* i : quantized LSPs from frame endSQ15*/ + Word16 coder_type, /* i : Coder type */ + Word16 lsp_mid[] /* o : quantized LSPs Q15*/ ); -//cng_dec_fx.c +// cng_dec_fx.c void CNG_dec_fx( - Decoder_State* st_fx, /* i/o: State structure */ - const Word16 last_element_mode, /* i : last element mode Q0 */ - Word16 Aq[], /* o : LP coefficients Q12 */ - Word16* lsp_new, /* i/o: current frame LSPs Q15 */ - Word16* lsf_new, /* i/o: current frame LSFs Qlog2(2.56) */ - Word16* allow_cn_step, /* o : allow CN step Q0 */ - Word16* sid_bw /* i : 0-NB/WB, 1-SWB SID */ - , Word32* q_env -); + Decoder_State *st_fx, /* i/o: State structure */ + const Word16 last_element_mode, /* i : last element mode Q0 */ + Word16 Aq[], /* o : LP coefficients Q12 */ + Word16 *lsp_new, /* i/o: current frame LSPs Q15 */ + Word16 *lsf_new, /* i/o: current frame LSFs Qlog2(2.56) */ + Word16 *allow_cn_step, /* o : allow CN step Q0 */ + Word16 *sid_bw /* i : 0-NB/WB, 1-SWB SID */ + , + Word32 *q_env ); void swb_CNG_dec_fx( - Decoder_State *st_fx, /* i/o: State structure */ - const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz */ - Word16 *shb_synth_fx, /* o : high-band CNG synthesis */ - const Word16 sid_bw, /* i : 0-NB/WB, 1-SWB SID */ - const Word16 Qsyn /* i : Q value of ACELP core synthesis */ + Decoder_State *st_fx, /* i/o: State structure */ + const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz */ + Word16 *shb_synth_fx, /* o : high-band CNG synthesis */ + const Word16 sid_bw, /* i : 0-NB/WB, 1-SWB SID */ + const Word16 Qsyn /* i : Q value of ACELP core synthesis */ ); void swb_CNG_dec_ivas_fx( - Decoder_State *st_fx, /* i/o: State structure */ - const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz */ - Word16 *shb_synth_fx, /* o : high-band CNG synthesis */ - const Word16 sid_bw, /* i : 0-NB/WB, 1-SWB SID */ - const Word16 Qsyn /* i : Q value of ACELP core synthesis */ + Decoder_State *st_fx, /* i/o: State structure */ + const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz */ + Word16 *shb_synth_fx, /* o : high-band CNG synthesis */ + const Word16 sid_bw, /* i : 0-NB/WB, 1-SWB SID */ + const Word16 Qsyn /* i : Q value of ACELP core synthesis */ ); void td_cng_dec_init_fx( - DEC_CORE_HANDLE st /* i/o: decoder state structure */ + DEC_CORE_HANDLE st /* i/o: decoder state structure */ ); void td_cng_dec_init_ivas_fx( DEC_CORE_HANDLE st /* i/o: decoder state structure */ ); -//wavadjust_fec_dec_fx.c -void set_state(Word16 *state, Word16 num, Word16 N); -void concealment_init_x(Word16 N, void *_plcInfo); +// wavadjust_fec_dec_fx.c +void set_state( Word16 *state, Word16 num, Word16 N ); +void concealment_init_x( Word16 N, void *_plcInfo ); void concealment_init_ivas_fx( const Word16 L_frameTCX, T_PLCInfo_HANDLE hPlcInfo ); -void concealment_update_x(Word16 bfi, Word16 curr_mode, Word16 harmonic, Word32 *invkoef, Word16 *invkoef_scale, void *_plcInfo); -Word16 Sqrt_x_fast(Word32 value); +void concealment_update_x( Word16 bfi, Word16 curr_mode, Word16 harmonic, Word32 *invkoef, Word16 *invkoef_scale, void *_plcInfo ); +Word16 Sqrt_x_fast( Word32 value ); -Word32 dot_w32_accuracy_x(Word16 *s1, Word16 *s2, Word16 nbits, Word16 N); +Word32 dot_w32_accuracy_x( Word16 *s1, Word16 *s2, Word16 nbits, Word16 N ); -Word16 int_div_s_x(Word16 a, Word16 b); +Word16 int_div_s_x( Word16 a, Word16 b ); -Word16 GetW32Norm_x(Word32 *s, Word16 N); +Word16 GetW32Norm_x( Word32 *s, Word16 N ); -Word16 harmo_x(Word32 *X, Word16 Framesize, Word16 pitch); +Word16 harmo_x( Word32 *X, Word16 Framesize, Word16 pitch ); -void LpFilter2_x(Word16 *x, Word16 *y, Word16 N); +void LpFilter2_x( Word16 *x, Word16 *y, Word16 N ); -void sig_tilt_x(Word16 *s, Word16 FrameSize, Word32 *enr1, Word32 *enr2); +void sig_tilt_x( Word16 *s, Word16 FrameSize, Word32 *enr1, Word32 *enr2 ); -void get_maxConv_and_pitch_x(Word16 *s_LP, Word16 s, Word16 e, Word16 N, - Word32 *maxConv, Word16 *maxConv_bits, Word16 *pitch); +void get_maxConv_and_pitch_x( Word16 *s_LP, Word16 s, Word16 e, Word16 N, Word32 *maxConv, Word16 *maxConv_bits, Word16 *pitch ); -Word16 get_voicing_x(Word16 *s_LP, Word16 pitch, Word32 covMax, Word16 maxConv_bits, Word16 Framesize); +Word16 get_voicing_x( Word16 *s_LP, Word16 pitch, Word32 covMax, Word16 maxConv_bits, Word16 Framesize ); -void pitch_modify_x(Word16 *s_LP, Word16 *voicing, Word16 *pitch, Word16 FrameSize); +void pitch_modify_x( Word16 *s_LP, Word16 *voicing, Word16 *pitch, Word16 FrameSize ); -Word16 Is_Periodic_x(Word32 *mdct_data, Word16 cov_max, Word16 zp, Word32 ener, - Word32 ener_mean, Word16 pitch, Word16 Framesize); +Word16 Is_Periodic_x( Word32 *mdct_data, Word16 cov_max, Word16 zp, Word32 ener, Word32 ener_mean, Word16 pitch, Word16 Framesize ); -Word16 get_conv_relation_x(Word16 *s_LP, Word16 shift, Word16 N); +Word16 get_conv_relation_x( Word16 *s_LP, Word16 shift, Word16 N ); -void concealment_decode_fix(Word16 curr_mode, Word32 *invkoef, Word16 *invkoef_scale, void *_plcInfo); +void concealment_decode_fix( Word16 curr_mode, Word32 *invkoef, Word16 *invkoef_scale, void *_plcInfo ); -Word32 Spl_Energy_x(const Word16* vector, const Word16 vector_length, Word16* scale_factor); +Word32 Spl_Energy_x( const Word16 *vector, const Word16 vector_length, Word16 *scale_factor ); -void Log10OfEnergy_x(const Word16 *s, Word32 *enerlogval, const Word16 len); +void Log10OfEnergy_x( const Word16 *s, Word32 *enerlogval, const Word16 len ); -void concealment_update2_x(const Word16 *outx_new, void *_plcInfo, const Word16 FrameSize); +void concealment_update2_x( const Word16 *outx_new, void *_plcInfo, const Word16 FrameSize ); -Word16 ffr_getSfWord16(Word16 *vector, /*!< Pointer to i vector */ - Word16 len); +Word16 ffr_getSfWord16( Word16 *vector, /*!< Pointer to i vector */ + Word16 len ); -void waveform_adj2_fix(Word16 *overlapbuf, - Word16 *outx_new, - Word16 *data_noise, - Word16 *outx_new_n1, - Word16 *nsapp_gain, - Word16 *nsapp_gain_n, - Word16 *recovery_gain, - Word16 step_concealgain, - Word16 pitch, - Word16 Framesize, - Word16 delay, - Word16 bfi_cnt, - Word16 bfi -); +void waveform_adj2_fix( Word16 *overlapbuf, + Word16 *outx_new, + Word16 *data_noise, + Word16 *outx_new_n1, + Word16 *nsapp_gain, + Word16 *nsapp_gain_n, + Word16 *recovery_gain, + Word16 step_concealgain, + Word16 pitch, + Word16 Framesize, + Word16 delay, + Word16 bfi_cnt, + Word16 bfi ); -void concealment_signal_tuning_fx(Word16 bfi, - Word16 curr_mode, - Word16 *outx_new_fx, - void *_plcInfo, - Word16 nbLostCmpt, - Word16 pre_bfi, - Word16 *OverlapBuf_fx, - Word16 past_core_mode, - Word16 *outdata2_fx, - Decoder_State *st); +void concealment_signal_tuning_fx( Word16 bfi, + Word16 curr_mode, + Word16 *outx_new_fx, + void *_plcInfo, + Word16 nbLostCmpt, + Word16 pre_bfi, + Word16 *OverlapBuf_fx, + Word16 past_core_mode, + Word16 *outdata2_fx, + Decoder_State *st ); -//TonalComponentDetect.c +// TonalComponentDetect.c /* Detect tonal components in the lastMDCTSpectrum, use * secondLastPowerSpectrum for the precise location of the peaks and * store them in indexOfTonalPeak. Updates lowerIndex, upperIndex, * pNumIndexes accordingly. */ -void DetectTonalComponents( - Word16 indexOfTonalPeak[], - Word16 lowerIndex[], - Word16 upperIndex[], - Word16* pNumIndexes, - const Word32 lastPitchLag, - const Word32 currentPitchLag, - const Word16 lastMDCTSpectrum[], - const Word16 lastMDCTSpectrum_exp, - const Word16 scaleFactors[], - const Word16 scaleFactors_exp[], - const Word16 scaleFactors_max_e, - const Word32 secondLastPowerSpectrum[], - const Word16 nSamples, - const Word16 nSamplesCore, - Word16 floorPowerSpectrum, /* i: lower limit for power spectrum bins */ - Word16 element_mode +void DetectTonalComponents( + Word16 indexOfTonalPeak[], + Word16 lowerIndex[], + Word16 upperIndex[], + Word16 *pNumIndexes, + const Word32 lastPitchLag, + const Word32 currentPitchLag, + const Word16 lastMDCTSpectrum[], + const Word16 lastMDCTSpectrum_exp, + const Word16 scaleFactors[], + const Word16 scaleFactors_exp[], + const Word16 scaleFactors_max_e, + const Word32 secondLastPowerSpectrum[], + const Word16 nSamples, + const Word16 nSamplesCore, + Word16 floorPowerSpectrum, /* i: lower limit for power spectrum bins */ + Word16 element_mode #ifdef IVAS_CODE_MDCT_GSHAPE - , const PsychoacousticParameters* psychParamsCurrent + , + const PsychoacousticParameters *psychParamsCurrent #endif ); @@ -5917,65 +5764,67 @@ void DetectTonalComponents( * again detected Updates indexOfTonalPeak, lowerIndex, upperIndex, * phaseDiff, phases, pNumIndexes accordingly. */ void RefineTonalComponents( - Word16 indexOfTonalPeak[], - Word16 lowerIndex[], - Word16 upperIndex[], - Word16 phaseDiff[], - Word16 phases[], - Word16* pNumIndexes, - const Word32 lastPitchLag, - const Word32 currentPitchLag, - const Word16 lastMDCTSpectrum[], - const Word16 lastMDCTSpectrum_exp, - const Word16 scaleFactors[], - const Word16 scaleFactors_exp[], - const Word16 scaleFactors_max_e, - const Word32 secondLastPowerSpectrum[], - const Word16 nSamples, - const Word16 nSamplesCore, - const Word16 floorPowerSpectrum, /* i: lower limit for power spectrum bins */ - Word16 element_mode + Word16 indexOfTonalPeak[], + Word16 lowerIndex[], + Word16 upperIndex[], + Word16 phaseDiff[], + Word16 phases[], + Word16 *pNumIndexes, + const Word32 lastPitchLag, + const Word32 currentPitchLag, + const Word16 lastMDCTSpectrum[], + const Word16 lastMDCTSpectrum_exp, + const Word16 scaleFactors[], + const Word16 scaleFactors_exp[], + const Word16 scaleFactors_max_e, + const Word32 secondLastPowerSpectrum[], + const Word16 nSamples, + const Word16 nSamplesCore, + const Word16 floorPowerSpectrum, /* i: lower limit for power spectrum bins */ + Word16 element_mode #ifdef IVAS_CODE_MDCT_GSHAPE - , const PsychoacousticParameters* psychParamsCurrent + , + const PsychoacousticParameters *psychParamsCurrent #endif ); ivas_error PsychoacousticParameters_Init( - const Word32 sr_core, /* i : sampling rate of core-coder */ - const Word16 nBins, /* i : Number of bins (spectral lines) */ - const Word8 nBands, /* i : Number of spectrum subbands */ - const Word16 isTCX20, /* i : Flag indicating if the subband division is for TCX20 or TCX10 */ - const Word16 isWarped, /* i : Flag indicating if the scale is linear or warped */ - PsychoacousticParameters *pPsychParams ); - -//TonalIMDCTconcealment_fx.c + const Word32 sr_core, /* i : sampling rate of core-coder */ + const Word16 nBins, /* i : Number of bins (spectral lines) */ + const Word8 nBands, /* i : Number of spectrum subbands */ + const Word16 isTCX20, /* i : Flag indicating if the subband division is for TCX20 or TCX10 */ + const Word16 isWarped, /* i : Flag indicating if the scale is linear or warped */ + PsychoacousticParameters *pPsychParams ); + +// TonalIMDCTconcealment_fx.c ivas_error TonalMDCTConceal_Init( - TonalMDCTConcealPtr self, - const Word16 nSamples, - const Word16 nSamplesCore, - const Word16 nScaleFactors, - TCX_CONFIG_HANDLE hTcxCfg /* TCX config */ + TonalMDCTConcealPtr self, + const Word16 nSamples, + const Word16 nSamplesCore, + const Word16 nScaleFactors, + TCX_CONFIG_HANDLE hTcxCfg /* TCX config */ ); ivas_error TonalMDCTConceal_Init_ivas_fx( - TonalMDCTConcealPtr hTonalMDCTConc, - const UWord16 nSamples, - const UWord16 nSamplesCore, - const UWord16 nScaleFactors, - TCX_CONFIG_HANDLE hTcxCfg /* TCX config */ + TonalMDCTConcealPtr hTonalMDCTConc, + const UWord16 nSamples, + const UWord16 nSamplesCore, + const UWord16 nScaleFactors, + TCX_CONFIG_HANDLE hTcxCfg /* TCX config */ ); /* Must be called only when a good frame is recieved - concealment is inactive */ void TonalMDCTConceal_SaveFreqSignal( TonalMDCTConcealPtr self, - const Word32* mdctSpectrum, + const Word32 *mdctSpectrum, const Word16 mdctSpectrum_exp, Word16 nNewSamples, Word16 nNewSamplesCore, - const Word16* scaleFactors, - const Word16* scaleFactors_exp, + const Word16 *scaleFactors, + const Word16 *scaleFactors_exp, const Word16 gain_tcx_exp #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - ,const Word16 infoIGFStartLine + , + const Word16 infoIGFStartLine #endif ); @@ -5988,23 +5837,21 @@ void TonalMDCTConceal_SaveFreqSignal_ivas_fx( const Word16 *scaleFactors, const Word16 *scaleFactors_exp, const Word16 gain_tcx_exp, - const Word16 infoIGFStartLine); + const Word16 infoIGFStartLine ); /* The call to TonalMDCTConceal_UpdateState() should be called after TonalMDCTConceal_Apply. */ -TONALMDCTCONCEAL_ERROR TonalMDCTConceal_UpdateState(TonalMDCTConcealPtr self, - Word16 nNewSamples, - Word32 pitchLag, - Word16 badBlock, - Word8 tonalConcealmentActive - ); +TONALMDCTCONCEAL_ERROR TonalMDCTConceal_UpdateState( TonalMDCTConcealPtr self, + Word16 nNewSamples, + Word32 pitchLag, + Word16 badBlock, + Word8 tonalConcealmentActive ); /* The call to TonalMDCTConceal_SaveTimeSignal() should be at the * place where the TD signal corresponds to the FD signal stored with TonalMDCTConceal_SaveFreqSignal. */ -void TonalMDCTConceal_SaveTimeSignal( +void TonalMDCTConceal_SaveTimeSignal( TonalMDCTConcealPtr hTonalMDCTConc, - Word16 * timeSignal, - Word16 nNewSamples -); + Word16 *timeSignal, + Word16 nNewSamples ); /* Calculates MDST, power spectrum and performs peak detection. * Uses the TD signal in pastTimeSignal; if pastTimeSignal is NULL, uses the @@ -6012,13 +5859,14 @@ void TonalMDCTConceal_SaveTimeSignal( * second last frame was also lost, it is expected that pastTimeSignal * could hold a signal somewhat different from the one stored in * TonalMDCTConceal_SaveTimeSignal (e.g. including fade-out).*/ -void TonalMDCTConceal_Detect( - const TonalMDCTConcealPtr self, /*IN */ - const Word32 pitchLag, /*IN */ - Word16 * umIndices, /*OUT*/ - Word16 element_mode /* IN */ +void TonalMDCTConceal_Detect( + const TonalMDCTConcealPtr self, /*IN */ + const Word32 pitchLag, /*IN */ + Word16 *umIndices, /*OUT*/ + Word16 element_mode /* IN */ #ifdef IVAS_CODE_MDCT_GSHAPE - , const PsychoacousticParameters* psychParamsCurrent + , + const PsychoacousticParameters *psychParamsCurrent #endif ); @@ -6036,10 +5884,9 @@ void TonalMDCTConceal_Apply( void TonalMDCTConceal_Apply_ivas_fx( TonalMDCTConcealPtr hTonalMDCTConc, /*IN */ - Word32 *mdctSpectrum, /*IN/OUT*/ + Word32 *mdctSpectrum, /*IN/OUT*/ Word16 *mdctSpectrum_exp, /*IN */ - const PsychoacousticParameters *psychParamsCurrent -); + const PsychoacousticParameters *psychParamsCurrent ); /* Conceals the lost frame using the FD signal previously stored using * TonalMDCTConceal_SaveFreqSignal. Stores the concealed noise part of @@ -6063,18 +5910,17 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( * TonalMDCTConceal_SaveFreqSignal. Stores the concealed noise part of * the signal in mdctSpectrum, the rest of the spectrum is unchanged. */ void TonalMDCTConceal_InsertNoise( - const TonalMDCTConcealPtr hTonalMDCTConc, /*IN */ - Word32* mdctSpectrum, /*OUT*/ - Word16* mdctSpectrum_exp, /*OUT*/ - const Word16 tonalConcealmentActive, - Word16* pSeed, /*IN/OUT*/ - const Word16 tiltCompFactor, - Word16 crossfadeGain, + const TonalMDCTConcealPtr hTonalMDCTConc, /*IN */ + Word32 *mdctSpectrum, /*OUT*/ + Word16 *mdctSpectrum_exp, /*OUT*/ + const Word16 tonalConcealmentActive, + Word16 *pSeed, /*IN/OUT*/ + const Word16 tiltCompFactor, + Word16 crossfadeGain, #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT const Word16concealment_noise[L_FRAME48k], #endif - const Word16 crossOverFreq -); + const Word16 crossOverFreq ); /* Conceals the lost frame using the FD signal previously stored using * TonalMDCTConceal_SaveFreqSignal. Stores the concealed harmonic part of * the signal in mdctSpectrum, the rest of the spectrum is unchanged. */ @@ -6087,157 +5933,154 @@ void TonalMDCTConceal_Apply( #endif ); - /* The call to TonalMDCTConceal_SaveTimeSignal() should be at the +/* The call to TonalMDCTConceal_SaveTimeSignal() should be at the * place where the TD signal corresponds to the FD signal stored with TonalMDCTConceal_SaveFreqSignal. */ - void TonalMDCTConceal_SaveTimeSignal( - TonalMDCTConcealPtr hTonalMDCTConc, - Word16 * timeSignal, - Word16 nNewSamples - ); - - - //decision_matrix_dec_fx.c - void decision_matrix_dec_fx( - Decoder_State *st, /* i/o: decoder state structure */ - Word16 *sharpFlag, /* o : formant sharpening flag */ - Word16 *hq_core_type, /* o : HQ core type */ - Word16 *core_switching_flag/* o : ACELP->HQ switching frame flag */ - ); - - //hf_synth_fx.c - void hf_synth_init_fx( - ZERO_BWE_DEC_HANDLE hBWE_zero /* o : zero BWE decoder handle */ - ); - void hf_synth_reset_fx( - ZERO_BWE_DEC_HANDLE hBWE_zero /* o : zero BWE decoder handle */ - ); - - void hf_synth_fx( - ZERO_BWE_DEC_HANDLE hBWE_zero, /* i/o: handle to 0 bit BWE parameters */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 output_frame, /* i : output frame length */ - const Word16* Aq, /* i : quantized Az */ - const Word16* exc, /* i : excitation at 12.8 kHz */ - Word16* synth, /* i : 12.8kHz synthesis signal */ - Word16* synth16k, /* o : 16kHz synthesis signal */ - const Word16 Q_exc, /* i : excitation scaling */ - const Word16 Q_syn2, /* i : synthesis scaling */ - Word16* delay_syn_hf, /*i/o: HF synthesis memory */ - Word16* memExp1, /* o : HF excitation exponent */ - Word16* mem_hp_interp, /* i/o: interpol. memory */ - const Word16 extl, /* i : flag indicating BWE */ - const Word16 CNG_mode /* i : CNG_mode */ - ); - - void hf_synth_amr_wb_init_fx( - AMRWB_IO_DEC_HANDLE hAmrwb_IO /* i/o: AMR-WB IO data handle */ - ); - - void hf_synth_amr_wb_reset_fx( - ZERO_BWE_DEC_HANDLE hBWE_zero, /* o : zero BWE decoder handle */ - AMRWB_IO_DEC_HANDLE hAmrwb_IO /* i/o: AMR-WB IO data handle */ - ); - - void hf_synth_amr_wb_fx( - AMRWB_IO_DEC_HANDLE hAmrwb_IO, /* i/o: AMR-WB IO data handle */ - ZERO_BWE_DEC_HANDLE hBWE_zero, /* o : zero BWE decoder handle */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 output_frame, /* i : output frame length */ - const Word16* Aq, /* i : quantized Az : Q12 */ - const Word16* exc, /* i : excitation at 12.8 kHz : Q_exc */ - Word16* synth, /* i/o: synthesis signal at 12.8k : Q_syn */ - Word16* amr_io_class, /* i : signal class (determined by FEC algorithm) */ - Word16* synth_out, /* i/o: output signal at output Fs : Q_out */ - Word16 fmerit, /* i : classify parameter from FEC : Q14 */ - const Word16* hf_gain, /* i : decoded HF gain */ - const Word16* voice_factors, /* i : voicing factors : Q15 */ - const Word16 pitch_buf[], /* i : pitch buffer : Q5 */ - const Word16 ng_ener_ST, /* i : Noise gate - short-term energy : Q8 */ - const Word16* lsf_new, /* i : ISF vector : Q2 */ - const Word16 Q_exc, /* i : exc scaling */ - const Word16 Q_out /* i : Q_syn2-1 */ - ); - - //dec_post_fx - void Init_post_filter_fx( - PFSTAT_HANDLE hPFstat /* i : core decoder parameters */ - ); /* (i) : core decoder parameters */ - - - void nb_post_filt_fx( - const Word16 L_frame, /* i : frame length */ - PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ - Word16* psf_lp_noise, /* i : Long term noise Q8 */ - const Word16 tmp_noise, /* i : noise energy Q0 */ - Word16* Synth, /* i : 12k8 synthesis Qsyn */ - const Word16* Aq, /* i : LP filter coefficient Q12 */ - const Word16* Pitch_buf, /* i : Fractionnal subframe pitch buffer Q6 */ - const Word16 coder_type, /* i : coder_type */ - const Word16 BER_detect, /* i : BER detect flag */ - const Word16 disable_hpf /* i : flag to diabled HPF */ - ); - - void formant_post_filt_fx( - PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ - Word16 *synth_in, /* i : 12k8 synthesis */ - Word16 *Aq, /* i : LP filter coefficient */ - Word16 *synth_out, /* i/o: i signal */ - Word16 L_frame, - Word32 lp_noise, /* (i) : background noise energy (15Q16) */ - Word32 rate, /* (i) : bit-rate */ - const Word16 off_flag /* i : off flag */ - ); +void TonalMDCTConceal_SaveTimeSignal( + TonalMDCTConcealPtr hTonalMDCTConc, + Word16 *timeSignal, + Word16 nNewSamples ); + + +// decision_matrix_dec_fx.c +void decision_matrix_dec_fx( + Decoder_State *st, /* i/o: decoder state structure */ + Word16 *sharpFlag, /* o : formant sharpening flag */ + Word16 *hq_core_type, /* o : HQ core type */ + Word16 *core_switching_flag /* o : ACELP->HQ switching frame flag */ +); + +// hf_synth_fx.c +void hf_synth_init_fx( + ZERO_BWE_DEC_HANDLE hBWE_zero /* o : zero BWE decoder handle */ +); +void hf_synth_reset_fx( + ZERO_BWE_DEC_HANDLE hBWE_zero /* o : zero BWE decoder handle */ +); + +void hf_synth_fx( + ZERO_BWE_DEC_HANDLE hBWE_zero, /* i/o: handle to 0 bit BWE parameters */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 output_frame, /* i : output frame length */ + const Word16 *Aq, /* i : quantized Az */ + const Word16 *exc, /* i : excitation at 12.8 kHz */ + Word16 *synth, /* i : 12.8kHz synthesis signal */ + Word16 *synth16k, /* o : 16kHz synthesis signal */ + const Word16 Q_exc, /* i : excitation scaling */ + const Word16 Q_syn2, /* i : synthesis scaling */ + Word16 *delay_syn_hf, /*i/o: HF synthesis memory */ + Word16 *memExp1, /* o : HF excitation exponent */ + Word16 *mem_hp_interp, /* i/o: interpol. memory */ + const Word16 extl, /* i : flag indicating BWE */ + const Word16 CNG_mode /* i : CNG_mode */ +); + +void hf_synth_amr_wb_init_fx( + AMRWB_IO_DEC_HANDLE hAmrwb_IO /* i/o: AMR-WB IO data handle */ +); + +void hf_synth_amr_wb_reset_fx( + ZERO_BWE_DEC_HANDLE hBWE_zero, /* o : zero BWE decoder handle */ + AMRWB_IO_DEC_HANDLE hAmrwb_IO /* i/o: AMR-WB IO data handle */ +); + +void hf_synth_amr_wb_fx( + AMRWB_IO_DEC_HANDLE hAmrwb_IO, /* i/o: AMR-WB IO data handle */ + ZERO_BWE_DEC_HANDLE hBWE_zero, /* o : zero BWE decoder handle */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 output_frame, /* i : output frame length */ + const Word16 *Aq, /* i : quantized Az : Q12 */ + const Word16 *exc, /* i : excitation at 12.8 kHz : Q_exc */ + Word16 *synth, /* i/o: synthesis signal at 12.8k : Q_syn */ + Word16 *amr_io_class, /* i : signal class (determined by FEC algorithm) */ + Word16 *synth_out, /* i/o: output signal at output Fs : Q_out */ + Word16 fmerit, /* i : classify parameter from FEC : Q14 */ + const Word16 *hf_gain, /* i : decoded HF gain */ + const Word16 *voice_factors, /* i : voicing factors : Q15 */ + const Word16 pitch_buf[], /* i : pitch buffer : Q5 */ + const Word16 ng_ener_ST, /* i : Noise gate - short-term energy : Q8 */ + const Word16 *lsf_new, /* i : ISF vector : Q2 */ + const Word16 Q_exc, /* i : exc scaling */ + const Word16 Q_out /* i : Q_syn2-1 */ +); + +// dec_post_fx +void Init_post_filter_fx( + PFSTAT_HANDLE hPFstat /* i : core decoder parameters */ +); /* (i) : core decoder parameters */ + + +void nb_post_filt_fx( + const Word16 L_frame, /* i : frame length */ + PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ + Word16 *psf_lp_noise, /* i : Long term noise Q8 */ + const Word16 tmp_noise, /* i : noise energy Q0 */ + Word16 *Synth, /* i : 12k8 synthesis Qsyn */ + const Word16 *Aq, /* i : LP filter coefficient Q12 */ + const Word16 *Pitch_buf, /* i : Fractionnal subframe pitch buffer Q6 */ + const Word16 coder_type, /* i : coder_type */ + const Word16 BER_detect, /* i : BER detect flag */ + const Word16 disable_hpf /* i : flag to diabled HPF */ +); + +void formant_post_filt_fx( + PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ + Word16 *synth_in, /* i : 12k8 synthesis */ + Word16 *Aq, /* i : LP filter coefficient */ + Word16 *synth_out, /* i/o: i signal */ + Word16 L_frame, + Word32 lp_noise, /* (i) : background noise energy (15Q16) */ + Word32 rate, /* (i) : bit-rate */ + const Word16 off_flag /* i : off flag */ +); #ifdef IVAS_FLOAT_FIXED - void formant_post_filt_ivas_fx( - PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ - Word16 *synth_in, /* i : 12k8 synthesis */ - Word16 *Aq, /* i : LP filter coefficient */ - Word16 *synth_out, /* i/o: i signal */ - Word16 L_frame, - Word32 lp_noise, /* (i) : background noise energy (15Q16) */ - Word32 rate, /* (i) : bit-rate */ - const Word16 off_flag /* i : off flag */ - ); +void formant_post_filt_ivas_fx( + PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ + Word16 *synth_in, /* i : 12k8 synthesis */ + Word16 *Aq, /* i : LP filter coefficient */ + Word16 *synth_out, /* i/o: i signal */ + Word16 L_frame, + Word32 lp_noise, /* (i) : background noise energy (15Q16) */ + Word32 rate, /* (i) : bit-rate */ + const Word16 off_flag /* i : off flag */ +); #endif - void Filt_mu_fx( - Word16 * sig_in, /* i : signal (beginning at sample -1) */ - Word16 * sig_out, /* o : signal with tilt */ - Word16 parcor0, /* i : parcor0 (mu = parcor0 * gamma3) */ - Word16 L_subfr /* i : the length of subframe */ - ); +void Filt_mu_fx( + Word16 *sig_in, /* i : signal (beginning at sample -1) */ + Word16 *sig_out, /* o : signal with tilt */ + Word16 parcor0, /* i : parcor0 (mu = parcor0 * gamma3) */ + Word16 L_subfr /* i : the length of subframe */ +); #ifdef IVAS_FLOAT_FIXED - void Filt_mu_ivas_fx( - Word16 * sig_in, /* i : signal (beginning at sample -1) */ - Word16 * sig_out, /* o : signal with tilt */ - Word16 parcor0, /* i : parcor0 (mu = parcor0 * gamma3) */ - Word16 L_subfr, /* i : the length of subframe */ - const Word16 extl - ); +void Filt_mu_ivas_fx( + Word16 *sig_in, /* i : signal (beginning at sample -1) */ + Word16 *sig_out, /* o : signal with tilt */ + Word16 parcor0, /* i : parcor0 (mu = parcor0 * gamma3) */ + Word16 L_subfr, /* i : the length of subframe */ + const Word16 extl ); #endif - void scale_st_fx( - const Word16 * sig_in, /* i : postfilter i signal */ - Word16 * sig_out, /* i/o: postfilter o signal */ - Word16 * gain_prec, /* i/o: last value of gain for subframe */ - Word16 L_subfr - ); - - void blend_subfr2_fx( - Word16 *sigIn1, /* i : i signal for fade-out */ - Word16 *sigIn2, /* i : i signal for fade-in */ - Word16 *sigOut /* o : output signal */ - ); +void scale_st_fx( + const Word16 *sig_in, /* i : postfilter i signal */ + Word16 *sig_out, /* i/o: postfilter o signal */ + Word16 *gain_prec, /* i/o: last value of gain for subframe */ + Word16 L_subfr ); + +void blend_subfr2_fx( + Word16 *sigIn1, /* i : i signal for fade-out */ + Word16 *sigIn2, /* i : i signal for fade-in */ + Word16 *sigOut /* o : output signal */ +); void init_tcx_window_cfg_fx( - TCX_CONFIG_HANDLE hTcxCfg, /* i : TCX Config handle */ - const Word32 sr_core, /* i : SR core */ - const Word32 input_Fs, /* i : input/output SR */ - const Word16 L_frame, /* i : L_frame at sr_core */ - const Word16 L_frameTCX, /* i : L_frame at i/o SR */ - const Word16 mdctWindowLength, /* i : window length at sr_core */ - const Word16 mdctWindowLengthFB, /* i : window length at i/o SR */ - const Word16 element_mode /* i : mode of CPE/SCE */ - ); + TCX_CONFIG_HANDLE hTcxCfg, /* i : TCX Config handle */ + const Word32 sr_core, /* i : SR core */ + const Word32 input_Fs, /* i : input/output SR */ + const Word16 L_frame, /* i : L_frame at sr_core */ + const Word16 L_frameTCX, /* i : L_frame at i/o SR */ + const Word16 mdctWindowLength, /* i : window length at sr_core */ + const Word16 mdctWindowLengthFB, /* i : window length at i/o SR */ + const Word16 element_mode /* i : mode of CPE/SCE */ +); void init_tcx_cfg_fx( TCX_CONFIG_HANDLE hTcxCfg, @@ -6256,2097 +6099,2100 @@ void init_tcx_cfg_fx( const Word16 element_mode, const Word16 ini_frame, const Word16 MCT_flag /* i : hMCT handle allocated (1) or not (0) */, - const Word16 fscaleFB - ); - - //syn_outp_fx.c - - void syn_output_fx( - const Word16 codec_mode, /* i : MODE1 or MODE2 */ - Word16 *synth, /* i/o: float synthesis signal */ - const Word16 output_frame, /* i : output frame length */ - Word16 *synth_out, /* o : integer 16 bits synthesis signal */ - const Word16 Q_syn2 /* i : Synthesis scaling factor */ - ); - - void unscale_AGC( - const Word16 x[], - const Word16 Qx, - Word16 y[], - Word16 mem[], - const Word16 n - ); - - //bass_psfilter_fx.c - void bass_psfilter_init_fx( - BPF_DEC_HANDLE hBPF /* o : BPF data handle */ - ); - - void bass_psfilter_fx( - BPF_DEC_HANDLE hBPF, /* i/o: BPF data handle */ - const Word16 Opt_AMR_WB, /* i : AMR-WB IO flag */ - Word16 synth_in_fx[], /* i : i synthesis (at 16kHz) */ - const Word16 L_frame, /* i : length of the last frame */ - Word16 pitch_buf_fx[], /* i : pitch for every subfr [0,1,2,3] */ - const Word16 bpf_off, /* i : do not use BPF when set to 1 */ - Word16 v_stab_fx, /* i : stability factor */ - Word16* v_stab_smooth_fx, /* i/o: smoothed stability factor */ - const Word16 coder_type, /* i : coder_type */ - Word16 Q_syn, - Word16 bpf_noise_buf[] /* o : BPF error signal (at int_fs) */ - ); - void addBassPostFilter_fx( - const Word16 *harm_timeIn_Fx, - Word32 **rAnalysis_Fx, - Word32 **iAnalysis_Fx, - HANDLE_CLDFB_FILTER_BANK cldfbBank_bpf_Fx, - Word32 *workBuffer, - const Word16 timeIn_e, - const Word16 nTimeSlots, - const Word16 nTimeSlotsTotal, - const Word16 nBandsTotal, - CLDFB_SCALE_FACTOR *cldfb_scale - ); - - //FEC_fx.c - void FEC_exc_estim_fx( - Decoder_State *st_fx, /* i/o: Decoder static memory */ - const Word16 L_frame, /* i : length of the frame */ - Word16 *exc, /* o : pointer to excitation buffer (with past) */ - Word16 *exc2, /* o : total excitation (for synthesis) */ - Word16 dct_exc_tmp[], /* o : GSC excitation in DCT domain */ - Word16 *pitch_buf, /* o : Floating pitch for each subframe */ - Word16 *voice_factors, /* o : voicing factors */ - Word16 *tmp_tc, /* o : FEC pitch Q6 */ - Word16 *bwe_exc, /* o : excitation for SWB TBE */ - Word16 *lsf_new, /* i : ISFs at the end of the frame */ - Word16 *Q_exc, - Word16 *tmp_noise /* o : long-term noise energy Q0 */ - ); - - //pitch_extr_fx.c - void pitch_pred_linear_fit( - const Word16 /*short*/ bfi_cnt, /* i: bfi counter */ /*Q0 */ - const Word16 /*short*/ last_good, /* i: last classification type */ /*Q0 */ - Word32 /*float*/ *old_pitch_buf, /* i: pitch lag buffer */ /*Q16*/ - Word32 /*float*/ *old_fpitch, /* i: */ /*Q16*/ - Word32 /*float*/ *T0_out, /* o: estimated close loop pitch */ /*Q16*/ - Word16 /* int*/ pit_min, /* i: Minimum pitch lag */ /*Q0 */ - Word16 /* int*/ pit_max, /* i: Maximum pitch lag */ /*Q0 */ - Word16 /*float*/ *mem_pitch_gain, /* i: pitch gain [0] is the most recent subfr gain */ /*Q0*/ - Word16 /* int*/ limitation, - Word16 /*short*/ plc_use_future_lag, /* i: */ /*Q0 */ - Word16 /*short*/ *extrapolationFailed, /* o: flag if extrap decides not to change the pitch *//*Q0 */ - Word16 nb_subfr /* i: number of ACELP subframes */ - ); - - void get_subframe_pitch( - Word16 nSubframes, /* i: number of subframes */ /* Q0 */ - Word32 pitchStart, /* i: starting pitch lag (in subframe -1) */ /*15Q16*/ - Word32 pitchEnd, /* i: ending pitch lag (in subframe nSubframes-1) */ /*15Q16*/ - Word32 *pitchBuf /* o: interpolated pitch lag per subframe */ /*15Q16*/ - ); - - //er_sync_exc_fx.c - void PulseResynchronization_fx( - Word16 /*float*/ const * const src_exc, /*i Q15*/ - Word16 /*float*/ * const dst_exc, /*o Q15*/ - Word16 /*int*/ const nFrameLength, /*i Q0 */ - Word16 /*int*/ const nSubframes, /*i Q0 */ - Word32 /*float*/ const pitchStart, /*i Q16*/ - Word32 /*float*/ const pitchEnd /*i Q16*/ - ); - - //gs_dec_fx.c - void decod_audio_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - Word16 dct_epit[], /* o : GSC excitation in DCT domain */ - const Word16 *Aq, /* i : LP filter coefficient */ - Word16 *pitch_buf, /* o : floating pitch values for each subframe */ - Word16 *voice_factors, /* o : voicing factors */ - Word16 *exc, /* i/o: adapt. excitation exc */ - Word16 *exc2, /* i/o: adapt. excitation/total exc */ - Word16 *bwe_exc, /* o : excitation for SWB TBE */ - Word16 *lsf_new /* i : ISFs at the end of the frame */ - , Word16 *gain_buf /*Q14*/ - ); - - void decod_audio_ivas_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - Word16 dct_epit[], /* o : GSC excitation in DCT domain */ - const Word16 *Aq, /* i : LP filter coefficient */ - Word16 *pitch_buf, /* o : floating pitch values for each subframe */ - Word16 *voice_factors, /* o : voicing factors */ - Word16 *exc, /* i/o: adapt. excitation exc */ - Word16 *exc2, /* i/o: adapt. excitation/total exc */ - Word16 *bwe_exc, /* o : excitation for SWB TBE */ - Word16 *lsf_new /* i : ISFs at the end of the frame */ - , Word16 *gain_buf, /*Q14*/ - const Word16 tdm_lp_reuse_flag, /* i : LPC reuse flag */ - const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag */ - const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ - const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ - ); - - void gsc_dec_fx( - Decoder_State *st_fx, /* i/o: State structure */ - Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation */ - const Word16 pit_band_idx, /* i : bin position of the cut-off frequency */ - const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral)*/ - const Word16 bits_used, /* i : Number of bit used before frequency Q */ - const Word16 nb_subfr, /* i : Number of subframe considered */ - const Word16 coder_type, /* i : coding type */ - Word16 *last_bin, /* i : last bin of bit allocation */ - const Word16 *lsf_new, /* i : ISFs at the end of the frame */ - Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill */ - Word16 Q_exc - ); - - void gsc_dec_ivas_fx( - Decoder_State *st_fx, /* i/o: State structure */ - Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation */ - const Word16 pit_band_idx, /* i : bin position of the cut-off frequency */ - const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral)*/ - const Word16 bits_used, /* i : Number of bit used before frequency Q */ - const Word16 nb_subfr, /* i : Number of subframe considered */ - const Word16 coder_type, /* i : coding type */ - Word16 *last_bin, /* i : last bin of bit allocation */ - const Word16 *lsf_new, /* i : ISFs at the end of the frame */ - Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill */ - Word16 Q_exc - ); - - void GSC_dec_init( - GSC_DEC_HANDLE hGSCDec /* i/o: GSC data handle */ - ); + const Word16 fscaleFB ); + +// syn_outp_fx.c + +void syn_output_fx( + const Word16 codec_mode, /* i : MODE1 or MODE2 */ + Word16 *synth, /* i/o: float synthesis signal */ + const Word16 output_frame, /* i : output frame length */ + Word16 *synth_out, /* o : integer 16 bits synthesis signal */ + const Word16 Q_syn2 /* i : Synthesis scaling factor */ +); + +void unscale_AGC( + const Word16 x[], + const Word16 Qx, + Word16 y[], + Word16 mem[], + const Word16 n ); + +// bass_psfilter_fx.c +void bass_psfilter_init_fx( + BPF_DEC_HANDLE hBPF /* o : BPF data handle */ +); + +void bass_psfilter_fx( + BPF_DEC_HANDLE hBPF, /* i/o: BPF data handle */ + const Word16 Opt_AMR_WB, /* i : AMR-WB IO flag */ + Word16 synth_in_fx[], /* i : i synthesis (at 16kHz) */ + const Word16 L_frame, /* i : length of the last frame */ + Word16 pitch_buf_fx[], /* i : pitch for every subfr [0,1,2,3] */ + const Word16 bpf_off, /* i : do not use BPF when set to 1 */ + Word16 v_stab_fx, /* i : stability factor */ + Word16 *v_stab_smooth_fx, /* i/o: smoothed stability factor */ + const Word16 coder_type, /* i : coder_type */ + Word16 Q_syn, + Word16 bpf_noise_buf[] /* o : BPF error signal (at int_fs) */ +); +void addBassPostFilter_fx( + const Word16 *harm_timeIn_Fx, + Word32 **rAnalysis_Fx, + Word32 **iAnalysis_Fx, + HANDLE_CLDFB_FILTER_BANK cldfbBank_bpf_Fx, + Word32 *workBuffer, + const Word16 timeIn_e, + const Word16 nTimeSlots, + const Word16 nTimeSlotsTotal, + const Word16 nBandsTotal, + CLDFB_SCALE_FACTOR *cldfb_scale ); + +// FEC_fx.c +void FEC_exc_estim_fx( + Decoder_State *st_fx, /* i/o: Decoder static memory */ + const Word16 L_frame, /* i : length of the frame */ + Word16 *exc, /* o : pointer to excitation buffer (with past) */ + Word16 *exc2, /* o : total excitation (for synthesis) */ + Word16 dct_exc_tmp[], /* o : GSC excitation in DCT domain */ + Word16 *pitch_buf, /* o : Floating pitch for each subframe */ + Word16 *voice_factors, /* o : voicing factors */ + Word16 *tmp_tc, /* o : FEC pitch Q6 */ + Word16 *bwe_exc, /* o : excitation for SWB TBE */ + Word16 *lsf_new, /* i : ISFs at the end of the frame */ + Word16 *Q_exc, + Word16 *tmp_noise /* o : long-term noise energy Q0 */ +); + +// pitch_extr_fx.c +void pitch_pred_linear_fit( + const Word16 /*short*/ bfi_cnt, + /* i: bfi counter */ /*Q0 */ + const Word16 /*short*/ last_good, + /* i: last classification type */ /*Q0 */ + Word32 /*float*/ *old_pitch_buf, + /* i: pitch lag buffer */ /*Q16*/ + Word32 /*float*/ *old_fpitch, + /* i: */ /*Q16*/ + Word32 /*float*/ *T0_out, + /* o: estimated close loop pitch */ /*Q16*/ + Word16 /* int*/ pit_min, + /* i: Minimum pitch lag */ /*Q0 */ + Word16 /* int*/ pit_max, + /* i: Maximum pitch lag */ /*Q0 */ + Word16 /*float*/ *mem_pitch_gain, + /* i: pitch gain [0] is the most recent subfr gain */ /*Q0*/ + Word16 /* int*/ limitation, + Word16 /*short*/ plc_use_future_lag, + /* i: */ /*Q0 */ + Word16 /*short*/ *extrapolationFailed, + /* o: flag if extrap decides not to change the pitch */ /*Q0 */ + Word16 nb_subfr /* i: number of ACELP subframes */ +); + +void get_subframe_pitch( + Word16 nSubframes, + /* i: number of subframes */ /* Q0 */ + Word32 pitchStart, + /* i: starting pitch lag (in subframe -1) */ /*15Q16*/ + Word32 pitchEnd, + /* i: ending pitch lag (in subframe nSubframes-1) */ /*15Q16*/ + Word32 *pitchBuf /* o: interpolated pitch lag per subframe */ /*15Q16*/ +); + +// er_sync_exc_fx.c +void PulseResynchronization_fx( + Word16 /*float*/ const *const src_exc, /*i Q15*/ + Word16 /*float*/ *const dst_exc, /*o Q15*/ + Word16 /*int*/ const nFrameLength, /*i Q0 */ + Word16 /*int*/ const nSubframes, /*i Q0 */ + Word32 /*float*/ const pitchStart, /*i Q16*/ + Word32 /*float*/ const pitchEnd /*i Q16*/ +); + +// gs_dec_fx.c +void decod_audio_fx( + Decoder_State *st_fx, /* i/o: decoder static memory */ + Word16 dct_epit[], /* o : GSC excitation in DCT domain */ + const Word16 *Aq, /* i : LP filter coefficient */ + Word16 *pitch_buf, /* o : floating pitch values for each subframe */ + Word16 *voice_factors, /* o : voicing factors */ + Word16 *exc, /* i/o: adapt. excitation exc */ + Word16 *exc2, /* i/o: adapt. excitation/total exc */ + Word16 *bwe_exc, /* o : excitation for SWB TBE */ + Word16 *lsf_new /* i : ISFs at the end of the frame */ + , + Word16 *gain_buf /*Q14*/ +); + +void decod_audio_ivas_fx( + Decoder_State *st_fx, /* i/o: decoder static memory */ + Word16 dct_epit[], /* o : GSC excitation in DCT domain */ + const Word16 *Aq, /* i : LP filter coefficient */ + Word16 *pitch_buf, /* o : floating pitch values for each subframe */ + Word16 *voice_factors, /* o : voicing factors */ + Word16 *exc, /* i/o: adapt. excitation exc */ + Word16 *exc2, /* i/o: adapt. excitation/total exc */ + Word16 *bwe_exc, /* o : excitation for SWB TBE */ + Word16 *lsf_new /* i : ISFs at the end of the frame */ + , + Word16 *gain_buf, /*Q14*/ + const Word16 tdm_lp_reuse_flag, /* i : LPC reuse flag */ + const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag */ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ +); + +void gsc_dec_fx( + Decoder_State *st_fx, /* i/o: State structure */ + Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation */ + const Word16 pit_band_idx, /* i : bin position of the cut-off frequency */ + const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral)*/ + const Word16 bits_used, /* i : Number of bit used before frequency Q */ + const Word16 nb_subfr, /* i : Number of subframe considered */ + const Word16 coder_type, /* i : coding type */ + Word16 *last_bin, /* i : last bin of bit allocation */ + const Word16 *lsf_new, /* i : ISFs at the end of the frame */ + Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill */ + Word16 Q_exc ); + +void gsc_dec_ivas_fx( + Decoder_State *st_fx, /* i/o: State structure */ + Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation */ + const Word16 pit_band_idx, /* i : bin position of the cut-off frequency */ + const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral)*/ + const Word16 bits_used, /* i : Number of bit used before frequency Q */ + const Word16 nb_subfr, /* i : Number of subframe considered */ + const Word16 coder_type, /* i : coding type */ + Word16 *last_bin, /* i : last bin of bit allocation */ + const Word16 *lsf_new, /* i : ISFs at the end of the frame */ + Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill */ + Word16 Q_exc ); + +void GSC_dec_init( + GSC_DEC_HANDLE hGSCDec /* i/o: GSC data handle */ +); #ifdef IVAS_FLOAT_FIXED void GSC_dec_init_ivas_fx( - GSC_DEC_HANDLE hGSCDec /* i/o: GSC data handle */ + GSC_DEC_HANDLE hGSCDec /* i/o: GSC data handle */ ); #endif // IVAS_FIXED - //gain_dec_fx.c - - void Es_pred_dec_fx( - Word16* Es_pred, /* o : predicited scaled innovation energy Q8*/ - const Word16 enr_idx, /* i : indice */ - const Word16 nb_bits, /* i : number of bits */ - const Word16 no_ltp /* i : no LTP flag */ - ); - - void gain_dec_tc_fx( - Decoder_State* st_fx, /* i/o: decoder state structure */ - const Word16* code_fx, /* i : algebraic code excitation */ - const Word16 i_subfr_fx, /* i : subframe number */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - Word16* gain_pit_fx, /* o : pitch gain */ - Word32* gain_code_fx, /* o : Quantized codeebook gain */ - Word16* gain_inov_fx, /* o : unscaled innovation gain */ - Word32* norm_gain_code_fx /* o : norm. gain of the codebook excit. */ - ); - - void gain_dec_tc_ivas_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 *code_fx, /* i : algebraic code excitation */ - const Word16 i_subfr_fx, /* i : subframe number */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - Word16 *gain_pit_fx, /* o : pitch gain */ - Word32 *gain_code_fx, /* o : Quantized codeebook gain */ - Word16 *gain_inov_fx, /* o : unscaled innovation gain */ - Word32 *norm_gain_code_fx /* o : norm. gain of the codebook excit. */ - ); - - void gain_dec_mless_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 L_frame_fx, /* i : length of the frame */ - const Word16 coder_type, /* i : coding type */ - const Word16 i_subfr_fx, /* i : subframe number */ - const Word16 tc_subfr_fx, /* i : TC subframe index */ - const Word16 *code_fx, /* i : algebraic code excitation */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - Word16 *gain_pit_fx, /* o : Quantized pitch gain Q14*/ - Word32 *gain_code_fx, /* o : Quantized codeebook gain Q16*/ - Word16 *gain_inov_fx, /* o : unscaled innovation gain Q12*/ - Word32 *norm_gain_code_fx /* o : norm. gain of the codebook excitation Q16*/ - ); - - void gain_dec_lbr_fx( - Decoder_State* st_fx, /* i/o: decoder state structure */ - const Word16 coder_type, /* i : coding type */ - const Word16 i_subfr, /* i : subframe index */ - const Word16* code_fx, /* i : algebraic excitation Q9 */ - Word16* gain_pit_fx, /* o : quantized pitch gain Q14*/ - Word32* gain_code_fx, /* o : quantized codebook gain Q16*/ - Word16* gain_inov_fx, /* o : gain of the innovation (used for normalization) Q12*/ - Word32* norm_gain_code_fx, /* o : norm. gain of the codebook excitation Q16*/ - Word32 gc_mem[], /* i/o: gain_code from previous subframes */ - Word16 gp_mem[] /* i/o: gain_pitch from previous subframes */ - , const Word16 L_subfr /* i : subfr lenght */ - ); - - void lp_gain_updt_fx( - const Word16 i_subfr, /* i : subframe number Q0 */ - const Word16 gain_pit, /* i : Decoded gain pitch Q14 */ - const Word32 norm_gain_code, /* i : Normalised gain code Q16 */ - Word16 *lp_gainp, /* i/o: LP-filtered pitch gain(FEC) Q14 */ - Word16 *lp_gainc, /* i/o: LP-filtered code gain (FEC) Q3 */ - const Word16 L_frame /* i : length of the frame */ - ); - Word32 gain_dec_gaus_fx( /* o : quantized codebook gain Q16 */ - Word16 index, /* i : quantization index */ - const Word16 bits, /* i : number of bits to quantize */ - const Word16 lowBound, /* i : lower bound of quantizer (dB) */ - const Word16 topBound, /* i : upper bound of quantizer (dB) */ - const Word16 inv_gain_inov, /* o : unscaled innovation gain Q12 */ - Word32 *L_norm_gain_code /* o : gain of normalized gaussian excitation Q16 */ - ); - - void gain_dec_SQ_fx( - Decoder_State* st_fx, /* i/o: decoder state structure */ - const Word16 i_subfr, /* i : subframe number */ - const Word16* code, /* i : algebraic code excitation Q9*/ - const Word16 Es_pred, /* i : predicted scaled innov. energy Q8 */ - Word16* gain_pit, /* o : Quantized pitch gain Q14*/ - Word32* gain_code, /* o : Quantized codeebook gain Q16*/ - Word16* gain_inov, /* o : unscaled innovation gain Q12*/ - Word32* norm_gain_code /* o : norm. gain of the codebook excitation Q16*/ - ); - - void gain_dec_amr_wb_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - Word16 *gain_pit, /* o : Quantized pitch gain */ - Word32 *gain_code, /* o : Quantized codeebook gain */ - Word16 *past_qua_en, /* i/o: gain quantization memory (4 words) */ - Word16 *gain_inov, /* o : unscaled innovation gain */ - const Word16 *code, /* i : algebraic code excitation */ - Word32 *norm_gain_code /* o : norm. gain of the codebook excitation */ - ); - - //dec_higher_acelp_fx.c - void transf_cdbk_dec_fx( - Decoder_State* st_fx, /* i/o: decoder state structure */ - const Word16 harm_flag_acelp,/* i : harmonic flag for higher rates ACELP */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 Es_pred, /* i : predicited scaled innovation energy (Q8) */ - const Word32 gain_code, /* i : innovative excitation gain (Q16) */ - Word16* gain_preQ, /* o : prequantizer excitation gain (Q2) */ - Word32* norm_gain_preQ,/* o : normalized prequantizer excitation gain (Q16) */ - Word16 code_preQ[], /* o : prequantizer excitation (Q8) */ - Word16* unbits /* o : number of AVQ unused bits */ - ); - Word16 gain_dequant_fx( /* o: decoded gain */ - Word16 index, /* i: quantization index */ - const Word16 min, /* i: value of lower limit */ - const Word16 max, /* i: value of upper limit */ - const Word16 bits, /* i: number of bits to dequantize */ - Word16 *expg - ); - - //avq_dec_fx.c - - void AVQ_demuxdec_fx( - Decoder_State *st, /* i/o: decoder state structure */ - Word16 xriq[], /* o : decoded subvectors [0..8*Nsv-1]*/ - Word16 *nb_bits, /* i/o: number of allocated bits */ - const Word16 Nsv, /* i : number of subvectors */ - Word16 nq[], /* i/o: AVQ nq index */ - Word16 avq_bit_sFlag, /* i : flag for AVQ bit saving solution */ - Word16 trgtSvPos /* i : target SV for AVQ bit savings */ - ); - - void AVQ_dec_lpc( - Word16 *indx, /* i : index[] (4 bits per words) */ - Word16 *nvecq, /* o : vector quantized */ - Word16 Nsv); /* i : number of subvectors (lg=Nsv*8) */ - - - //re8_dec_fx.c - void re8_dec_fx( - Word16 n, /* i : codebook number (*n is an integer defined in {0,2,3,4,..,n_max}) */ - const UWord16 I, /* i : index of c (pointer to unsigned 16-bit word) */ - const Word16 k[], /* i : index of v (8-dimensional vector of binary indices) = Voronoi index */ - Word16 y[] /* o : point in RE8 (8-dimensional integer vector) */ - ); - - //lead_deindexing_fx.c - - void re8_decode_base_index_fx(const Word16 n, UWord16 I, Word16 *x); - - //re8_utils_fx.c - void re8_k2y_fx( - const Word16 *k, /* i : Voronoi index k[0..7] */ - const Word16 m, /* i : Voronoi modulo (m = 2^r = 1<=2) */ - Word16 *y /* o : 8-dimensional point y[0..7] in RE8 */ - ); - - void re8_vor_fx( - const Word16 y[], /* i : point in RE8 (8-dimensional integer vector) */ - Word16 *n, /* o : codebook number n=0,2,3,4,... (scalar integer) */ - Word16 k[], /* o : Voronoi index (integer vector of dimension 8) used only if n>4*/ - Word16 c[], /* o : codevector in Q0, Q2, Q3, or Q4 if n<=4, y=c */ - Word16 *ka /* o : identifier of absolute leader (to index c) */ - ); - - //re8_PPV_fx.c - void re8_PPV_fx( - const Word32 x[], /* i : point in R^8Q15 */ - Word16 y[] /* o : point in RE8 (8-dimensional integer vector) */ - ); - - //dec_pit_exc_fx.c - void dec_pit_exc_fx( - Decoder_State* st_fx, /* i/o: decoder static memory */ - const Word16* Aq_fx, /* i : LP filter coefficient */ - const Word16 coder_type, /* i : coding type */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - Word16* pitch_buf_fx, /* o : floating pitch values for each subframe */ - Word16* code_fx, /* o : innovation */ - Word16* exc_fx, /* i/o: adapt. excitation exc */ - Word16* bwe_exc_fx, /* o : excitation for SWB TBE */ - const Word16 nb_subfr_fx /* i : Number of subframe considered */ - , Word16* gain_buf /*Q14*/ +// gain_dec_fx.c + +void Es_pred_dec_fx( + Word16 *Es_pred, /* o : predicited scaled innovation energy Q8*/ + const Word16 enr_idx, /* i : indice */ + const Word16 nb_bits, /* i : number of bits */ + const Word16 no_ltp /* i : no LTP flag */ +); + +void gain_dec_tc_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 *code_fx, /* i : algebraic code excitation */ + const Word16 i_subfr_fx, /* i : subframe number */ + const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ + Word16 *gain_pit_fx, /* o : pitch gain */ + Word32 *gain_code_fx, /* o : Quantized codeebook gain */ + Word16 *gain_inov_fx, /* o : unscaled innovation gain */ + Word32 *norm_gain_code_fx /* o : norm. gain of the codebook excit. */ +); + +void gain_dec_tc_ivas_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 *code_fx, /* i : algebraic code excitation */ + const Word16 i_subfr_fx, /* i : subframe number */ + const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ + Word16 *gain_pit_fx, /* o : pitch gain */ + Word32 *gain_code_fx, /* o : Quantized codeebook gain */ + Word16 *gain_inov_fx, /* o : unscaled innovation gain */ + Word32 *norm_gain_code_fx /* o : norm. gain of the codebook excit. */ +); + +void gain_dec_mless_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 L_frame_fx, /* i : length of the frame */ + const Word16 coder_type, /* i : coding type */ + const Word16 i_subfr_fx, /* i : subframe number */ + const Word16 tc_subfr_fx, /* i : TC subframe index */ + const Word16 *code_fx, /* i : algebraic code excitation */ + const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ + Word16 *gain_pit_fx, /* o : Quantized pitch gain Q14*/ + Word32 *gain_code_fx, /* o : Quantized codeebook gain Q16*/ + Word16 *gain_inov_fx, /* o : unscaled innovation gain Q12*/ + Word32 *norm_gain_code_fx /* o : norm. gain of the codebook excitation Q16*/ +); + +void gain_dec_lbr_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 coder_type, /* i : coding type */ + const Word16 i_subfr, /* i : subframe index */ + const Word16 *code_fx, /* i : algebraic excitation Q9 */ + Word16 *gain_pit_fx, /* o : quantized pitch gain Q14*/ + Word32 *gain_code_fx, /* o : quantized codebook gain Q16*/ + Word16 *gain_inov_fx, /* o : gain of the innovation (used for normalization) Q12*/ + Word32 *norm_gain_code_fx, /* o : norm. gain of the codebook excitation Q16*/ + Word32 gc_mem[], /* i/o: gain_code from previous subframes */ + Word16 gp_mem[] /* i/o: gain_pitch from previous subframes */ + , + const Word16 L_subfr /* i : subfr lenght */ +); + +void lp_gain_updt_fx( + const Word16 i_subfr, /* i : subframe number Q0 */ + const Word16 gain_pit, /* i : Decoded gain pitch Q14 */ + const Word32 norm_gain_code, /* i : Normalised gain code Q16 */ + Word16 *lp_gainp, /* i/o: LP-filtered pitch gain(FEC) Q14 */ + Word16 *lp_gainc, /* i/o: LP-filtered code gain (FEC) Q3 */ + const Word16 L_frame /* i : length of the frame */ +); +Word32 gain_dec_gaus_fx( /* o : quantized codebook gain Q16 */ + Word16 index, /* i : quantization index */ + const Word16 bits, /* i : number of bits to quantize */ + const Word16 lowBound, /* i : lower bound of quantizer (dB) */ + const Word16 topBound, /* i : upper bound of quantizer (dB) */ + const Word16 inv_gain_inov, /* o : unscaled innovation gain Q12 */ + Word32 *L_norm_gain_code /* o : gain of normalized gaussian excitation Q16 */ +); + +void gain_dec_SQ_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 i_subfr, /* i : subframe number */ + const Word16 *code, /* i : algebraic code excitation Q9*/ + const Word16 Es_pred, /* i : predicted scaled innov. energy Q8 */ + Word16 *gain_pit, /* o : Quantized pitch gain Q14*/ + Word32 *gain_code, /* o : Quantized codeebook gain Q16*/ + Word16 *gain_inov, /* o : unscaled innovation gain Q12*/ + Word32 *norm_gain_code /* o : norm. gain of the codebook excitation Q16*/ +); + +void gain_dec_amr_wb_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word32 core_brate, /* i : core bitrate */ + Word16 *gain_pit, /* o : Quantized pitch gain */ + Word32 *gain_code, /* o : Quantized codeebook gain */ + Word16 *past_qua_en, /* i/o: gain quantization memory (4 words) */ + Word16 *gain_inov, /* o : unscaled innovation gain */ + const Word16 *code, /* i : algebraic code excitation */ + Word32 *norm_gain_code /* o : norm. gain of the codebook excitation */ +); + +// dec_higher_acelp_fx.c +void transf_cdbk_dec_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 harm_flag_acelp, /* i : harmonic flag for higher rates ACELP */ + const Word16 i_subfr, /* i : subframe index */ + const Word16 Es_pred, /* i : predicited scaled innovation energy (Q8) */ + const Word32 gain_code, /* i : innovative excitation gain (Q16) */ + Word16 *gain_preQ, /* o : prequantizer excitation gain (Q2) */ + Word32 *norm_gain_preQ, /* o : normalized prequantizer excitation gain (Q16) */ + Word16 code_preQ[], /* o : prequantizer excitation (Q8) */ + Word16 *unbits /* o : number of AVQ unused bits */ +); +Word16 gain_dequant_fx( /* o: decoded gain */ + Word16 index, /* i: quantization index */ + const Word16 min, /* i: value of lower limit */ + const Word16 max, /* i: value of upper limit */ + const Word16 bits, /* i: number of bits to dequantize */ + Word16 *expg ); + +// avq_dec_fx.c + +void AVQ_demuxdec_fx( + Decoder_State *st, /* i/o: decoder state structure */ + Word16 xriq[], /* o : decoded subvectors [0..8*Nsv-1]*/ + Word16 *nb_bits, /* i/o: number of allocated bits */ + const Word16 Nsv, /* i : number of subvectors */ + Word16 nq[], /* i/o: AVQ nq index */ + Word16 avq_bit_sFlag, /* i : flag for AVQ bit saving solution */ + Word16 trgtSvPos /* i : target SV for AVQ bit savings */ +); + +void AVQ_dec_lpc( + Word16 *indx, /* i : index[] (4 bits per words) */ + Word16 *nvecq, /* o : vector quantized */ + Word16 Nsv ); /* i : number of subvectors (lg=Nsv*8) */ + + +// re8_dec_fx.c +void re8_dec_fx( + Word16 n, /* i : codebook number (*n is an integer defined in {0,2,3,4,..,n_max}) */ + const UWord16 I, /* i : index of c (pointer to unsigned 16-bit word) */ + const Word16 k[], /* i : index of v (8-dimensional vector of binary indices) = Voronoi index */ + Word16 y[] /* o : point in RE8 (8-dimensional integer vector) */ +); + +// lead_deindexing_fx.c + +void re8_decode_base_index_fx( const Word16 n, UWord16 I, Word16 *x ); + +// re8_utils_fx.c +void re8_k2y_fx( + const Word16 *k, /* i : Voronoi index k[0..7] */ + const Word16 m, /* i : Voronoi modulo (m = 2^r = 1<=2) */ + Word16 *y /* o : 8-dimensional point y[0..7] in RE8 */ +); + +void re8_vor_fx( + const Word16 y[], /* i : point in RE8 (8-dimensional integer vector) */ + Word16 *n, /* o : codebook number n=0,2,3,4,... (scalar integer) */ + Word16 k[], /* o : Voronoi index (integer vector of dimension 8) used only if n>4*/ + Word16 c[], /* o : codevector in Q0, Q2, Q3, or Q4 if n<=4, y=c */ + Word16 *ka /* o : identifier of absolute leader (to index c) */ +); + +// re8_PPV_fx.c +void re8_PPV_fx( + const Word32 x[], /* i : point in R^8Q15 */ + Word16 y[] /* o : point in RE8 (8-dimensional integer vector) */ +); + +// dec_pit_exc_fx.c +void dec_pit_exc_fx( + Decoder_State *st_fx, /* i/o: decoder static memory */ + const Word16 *Aq_fx, /* i : LP filter coefficient */ + const Word16 coder_type, /* i : coding type */ + const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ + Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ + Word16 *code_fx, /* o : innovation */ + Word16 *exc_fx, /* i/o: adapt. excitation exc */ + Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ + const Word16 nb_subfr_fx /* i : Number of subframe considered */ + , + Word16 *gain_buf /*Q14*/ #ifdef ADD_LRTD - , const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ - const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ + , + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ #endif - ); - - void dec_pit_exc_ivas_fx( - Decoder_State* st_fx, /* i/o: decoder static memory */ - const Word16* Aq_fx, /* i : LP filter coefficient */ - const Word16 coder_type, /* i : coding type */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - Word16* pitch_buf_fx, /* o : floating pitch values for each subframe */ - Word16* code_fx, /* o : innovation */ - Word16* exc_fx, /* i/o: adapt. excitation exc */ - Word16* bwe_exc_fx, /* o : excitation for SWB TBE */ - const Word16 nb_subfr_fx /* i : Number of subframe considered */ - , Word16* gain_buf /*Q14*/ -#if 1//def ADD_LRTD - , const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ - const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ +); + +void dec_pit_exc_ivas_fx( + Decoder_State *st_fx, /* i/o: decoder static memory */ + const Word16 *Aq_fx, /* i : LP filter coefficient */ + const Word16 coder_type, /* i : coding type */ + const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ + Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ + Word16 *code_fx, /* o : innovation */ + Word16 *exc_fx, /* i/o: adapt. excitation exc */ + Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ + const Word16 nb_subfr_fx /* i : Number of subframe considered */ + , + Word16 *gain_buf /*Q14*/ +#if 1 // def ADD_LRTD + , + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ #endif - ); - - //pit_dec_fx.c - - Word32 Mode2_pit_decode( /* o: floating pitch value */ - const Word16 coder_type, /* i: coding model */ - Word16 i_subfr, /* i: subframe index */ - Word16 L_subfr, - Word16 **pt_indice, /* i/o: quantization indices pointer */ - Word16 *T0, /* i/o: close loop integer pitch */ - Word16 *T0_frac, /* o: close loop fractional part of the pitch */ - Word16 *T0_res, /* i/o: pitch resolution */ - Word16 *T0_min, /* i/o: lower limit for close-loop search */ - Word16 *T0_min_frac, /* i/o: lower limit for close-loop search */ - Word16 *T0_max, /* i/o: higher limit for close-loop search */ - Word16 *T0_max_frac, /* i/o: higher limit for close-loop search */ - Word16 pit_min, - Word16 pit_fr1, - Word16 pit_fr1b, - Word16 pit_fr2, - Word16 pit_max, - Word16 pit_res_max - ); - - void Mode2_abs_pit_dec( - Word16 *T0, /* o: integer pitch lag */ - Word16 *T0_frac, /* o: pitch fraction */ - Word16 *T0_res, /* o: pitch resolution */ - Word16 **pt_indice, /* i/o: pointer to Vector of Q indexes */ - Word16 pit_min, - Word16 pit_fr1, - Word16 pit_fr2, - Word16 pit_res_max - ); - - void Mode2_delta_pit_dec( - Word16 *T0, /* o: integer pitch lag */ - Word16 *T0_frac, /* o: pitch fraction */ - Word16 T0_res, /* i: pitch resolution */ - Word16 *T0_min, /* i: delta search min */ - Word16 *T0_min_frac, /* i: delta search min */ - Word16 **pt_indice /* i/o: pointer to Vector of Q indexes */ - ); - - Word16 pit_decode_fx( /* o : floating pitch value */ - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - Word16 i_subfr, /* i : subframe index */ - const Word16 coder_type, /* i : coding type */ - Word16 *limit_flag, /* i/o: restrained(0) or extended(1) Q limits */ - Word16 *T0, /* o : close loop integer pitch */ - Word16 *T0_frac, /* o : close loop fractional part of the pitch */ - Word16 *T0_min, /* i/o: delta search min for sf 2 & 4 */ - Word16 *T0_max, /* i/o: delta search max for sf 2 & 4 */ - const Word16 L_subfr /* i : subframe length */ +); + +// pit_dec_fx.c + +Word32 Mode2_pit_decode( /* o: floating pitch value */ + const Word16 coder_type, /* i: coding model */ + Word16 i_subfr, /* i: subframe index */ + Word16 L_subfr, + Word16 **pt_indice, /* i/o: quantization indices pointer */ + Word16 *T0, /* i/o: close loop integer pitch */ + Word16 *T0_frac, /* o: close loop fractional part of the pitch */ + Word16 *T0_res, /* i/o: pitch resolution */ + Word16 *T0_min, /* i/o: lower limit for close-loop search */ + Word16 *T0_min_frac, /* i/o: lower limit for close-loop search */ + Word16 *T0_max, /* i/o: higher limit for close-loop search */ + Word16 *T0_max_frac, /* i/o: higher limit for close-loop search */ + Word16 pit_min, + Word16 pit_fr1, + Word16 pit_fr1b, + Word16 pit_fr2, + Word16 pit_max, + Word16 pit_res_max ); + +void Mode2_abs_pit_dec( + Word16 *T0, /* o: integer pitch lag */ + Word16 *T0_frac, /* o: pitch fraction */ + Word16 *T0_res, /* o: pitch resolution */ + Word16 **pt_indice, /* i/o: pointer to Vector of Q indexes */ + Word16 pit_min, + Word16 pit_fr1, + Word16 pit_fr2, + Word16 pit_res_max ); + +void Mode2_delta_pit_dec( + Word16 *T0, /* o: integer pitch lag */ + Word16 *T0_frac, /* o: pitch fraction */ + Word16 T0_res, /* i: pitch resolution */ + Word16 *T0_min, /* i: delta search min */ + Word16 *T0_min_frac, /* i: delta search min */ + Word16 **pt_indice /* i/o: pointer to Vector of Q indexes */ +); + +Word16 pit_decode_fx( /* o : floating pitch value */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const Word16 L_frame, /* i : length of the frame */ + Word16 i_subfr, /* i : subframe index */ + const Word16 coder_type, /* i : coding type */ + Word16 *limit_flag, /* i/o: restrained(0) or extended(1) Q limits */ + Word16 *T0, /* o : close loop integer pitch */ + Word16 *T0_frac, /* o : close loop fractional part of the pitch */ + Word16 *T0_min, /* i/o: delta search min for sf 2 & 4 */ + Word16 *T0_max, /* i/o: delta search max for sf 2 & 4 */ + const Word16 L_subfr /* i : subframe length */ #ifdef ADD_LRTD - , const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ - const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ + , + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ #endif - ); - - Word16 pit_decode_ivas_fx( /* o : floating pitch value */ - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - Word16 i_subfr, /* i : subframe index */ - const Word16 coder_type, /* i : coding type */ - Word16 *limit_flag, /* i/o: restrained(0) or extended(1) Q limits */ - Word16 *T0, /* o : close loop integer pitch */ - Word16 *T0_frac, /* o : close loop fractional part of the pitch */ - Word16 *T0_min, /* i/o: delta search min for sf 2 & 4 */ - Word16 *T0_max, /* i/o: delta search max for sf 2 & 4 */ - const Word16 L_subfr /* i : subframe length */ -#if 1//def ADD_LRTD - , const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ - const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ +); + +Word16 pit_decode_ivas_fx( /* o : floating pitch value */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const Word16 L_frame, /* i : length of the frame */ + Word16 i_subfr, /* i : subframe index */ + const Word16 coder_type, /* i : coding type */ + Word16 *limit_flag, /* i/o: restrained(0) or extended(1) Q limits */ + Word16 *T0, /* o : close loop integer pitch */ + Word16 *T0_frac, /* o : close loop fractional part of the pitch */ + Word16 *T0_min, /* i/o: delta search min for sf 2 & 4 */ + Word16 *T0_max, /* i/o: delta search max for sf 2 & 4 */ + const Word16 L_subfr /* i : subframe length */ +#if 1 // def ADD_LRTD + , + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ #endif - ); - - void pit_Q_dec_fx( - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 pitch_index, /* i : pitch index */ - const Word16 nBits, /* i : # of Q bits */ - const Word16 delta, /* i : Half the CL searched interval */ - const Word16 pit_flag, /* i : absolute(0) or delta(1) pitch Q */ - const Word16 limit_flag, /* i : restrained(0) or extended(1) Q limits */ - Word16 *T0, /* o : integer pitch lag */ - Word16 *T0_frac, /* o : pitch fraction */ - Word16 *T0_min, /* i/o: delta search min */ - Word16 *T0_max /* i/o: delta search max */ - , Word16 *BER_detect /* o : BER detect flag */ - ); - - void pit16k_Q_dec_fx( - const Word16 pitch_index, /* i : pitch index */ - const Word16 nBits, /* i : # of Q bits */ - const Word16 limit_flag, /* i : restrained(0) or extended(1) limits */ - Word16 *T0, /* o : integer pitch lag */ - Word16 *T0_frac, /* o : pitch fraction */ - Word16 *T0_min, /* i/o: delta search min */ - Word16 *T0_max /* i/o: delta search max */ - , Word16 *BER_detect /* o : BER detect flag */ - ); - - void abs_pit_dec_fx( - const Word16 fr_steps, /* i: fractional resolution steps (0, 2, 4) */ - Word16 pitch_index, /* i: pitch index */ - const Word16 limit_flag, /* i : restrained(0) or extended(1) limits */ - Word16 *T0, /* o: integer pitch lag */ - Word16 *T0_frac /* o: pitch fraction */ - ); - - void delta_pit_dec_fx( - const Word16 fr_steps, /* i : fractional resolution steps (0, 2, 4) */ - const Word16 pitch_index, /* i : pitch index */ - Word16 *T0, /* o : integer pitch lag */ - Word16 *T0_frac, /* o : pitch fraction */ - const Word16 T0_min /* i : delta search min */ - ); - - //limit_t0_fx.c - void limit_T0_fx( - const Word16 L_frame, /* i : length of the frame */ - const Word16 delta, /* i : Half the close-loop searched interval */ - const Word16 pit_flag, /* i : selecting absolute(0) or delta(1) pitch quantization */ - const Word16 limit_flag, /* i : flag for Q limits (0=restrained, 1=extended) */ - const Word16 T0, /* i : rough pitch estimate around which the search is done */ - const Word16 T0_frac, /* i : pitch estimate fractional part */ - Word16 *T0_min, /* o : lower pitch limit */ - Word16 *T0_max /* o : higher pitch limit */ - ); - - void limit_T0_voiced( - const Word16 nbits, - const Word16 res, - const Word16 T0, /* i : rough pitch estimate around which the search is done */ - const Word16 T0_frac, /* i : pitch estimate fractional part */ - const Word16 T0_res, /* i : pitch resolution */ - Word16 *T0_min, /* o : lower pitch limit */ - Word16 *T0_min_frac, /* o : lower pitch limit */ - Word16 *T0_max, /* o : higher pitch limit */ - Word16 *T0_max_frac, /* o : higher pitch limit */ - const Word16 pit_min, /* i : Minimum pitch lag */ - const Word16 pit_max /* i : Maximum pitch lag */ - ); - - //inov_dec.c - void inov_decode_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 sharpFlag, /* i : formant sharpening flag */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 *p_Aq, /* i : LP filter coefficients Q12 */ - const Word16 tilt_code, /* i : tilt of the excitation of previous subframe Q15 */ - const Word16 pt_pitch, /* i : pointer to current subframe fractional pitch Q6*/ - Word16 *code /* o : algebraic excitation */ - , const Word16 L_subfr /* i : subframe length */ - ); +); + +void pit_Q_dec_fx( + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const Word16 pitch_index, /* i : pitch index */ + const Word16 nBits, /* i : # of Q bits */ + const Word16 delta, /* i : Half the CL searched interval */ + const Word16 pit_flag, /* i : absolute(0) or delta(1) pitch Q */ + const Word16 limit_flag, /* i : restrained(0) or extended(1) Q limits */ + Word16 *T0, /* o : integer pitch lag */ + Word16 *T0_frac, /* o : pitch fraction */ + Word16 *T0_min, /* i/o: delta search min */ + Word16 *T0_max /* i/o: delta search max */ + , + Word16 *BER_detect /* o : BER detect flag */ +); + +void pit16k_Q_dec_fx( + const Word16 pitch_index, /* i : pitch index */ + const Word16 nBits, /* i : # of Q bits */ + const Word16 limit_flag, /* i : restrained(0) or extended(1) limits */ + Word16 *T0, /* o : integer pitch lag */ + Word16 *T0_frac, /* o : pitch fraction */ + Word16 *T0_min, /* i/o: delta search min */ + Word16 *T0_max /* i/o: delta search max */ + , + Word16 *BER_detect /* o : BER detect flag */ +); + +void abs_pit_dec_fx( + const Word16 fr_steps, /* i: fractional resolution steps (0, 2, 4) */ + Word16 pitch_index, /* i: pitch index */ + const Word16 limit_flag, /* i : restrained(0) or extended(1) limits */ + Word16 *T0, /* o: integer pitch lag */ + Word16 *T0_frac /* o: pitch fraction */ +); + +void delta_pit_dec_fx( + const Word16 fr_steps, /* i : fractional resolution steps (0, 2, 4) */ + const Word16 pitch_index, /* i : pitch index */ + Word16 *T0, /* o : integer pitch lag */ + Word16 *T0_frac, /* o : pitch fraction */ + const Word16 T0_min /* i : delta search min */ +); + +// limit_t0_fx.c +void limit_T0_fx( + const Word16 L_frame, /* i : length of the frame */ + const Word16 delta, /* i : Half the close-loop searched interval */ + const Word16 pit_flag, /* i : selecting absolute(0) or delta(1) pitch quantization */ + const Word16 limit_flag, /* i : flag for Q limits (0=restrained, 1=extended) */ + const Word16 T0, /* i : rough pitch estimate around which the search is done */ + const Word16 T0_frac, /* i : pitch estimate fractional part */ + Word16 *T0_min, /* o : lower pitch limit */ + Word16 *T0_max /* o : higher pitch limit */ +); + +void limit_T0_voiced( + const Word16 nbits, + const Word16 res, + const Word16 T0, /* i : rough pitch estimate around which the search is done */ + const Word16 T0_frac, /* i : pitch estimate fractional part */ + const Word16 T0_res, /* i : pitch resolution */ + Word16 *T0_min, /* o : lower pitch limit */ + Word16 *T0_min_frac, /* o : lower pitch limit */ + Word16 *T0_max, /* o : higher pitch limit */ + Word16 *T0_max_frac, /* o : higher pitch limit */ + const Word16 pit_min, /* i : Minimum pitch lag */ + const Word16 pit_max /* i : Maximum pitch lag */ +); + +// inov_dec.c +void inov_decode_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const Word16 L_frame, /* i : length of the frame */ + const Word16 sharpFlag, /* i : formant sharpening flag */ + const Word16 i_subfr, /* i : subframe index */ + const Word16 *p_Aq, /* i : LP filter coefficients Q12 */ + const Word16 tilt_code, /* i : tilt of the excitation of previous subframe Q15 */ + const Word16 pt_pitch, /* i : pointer to current subframe fractional pitch Q6*/ + Word16 *code /* o : algebraic excitation */ + , + const Word16 L_subfr /* i : subframe length */ +); #ifdef IVAS_FLOAT_FIXED - void inov_decode_ivas_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 sharpFlag, /* i : formant sharpening flag */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 *p_Aq, /* i : LP filter coefficients Q12 */ - const Word16 tilt_code, /* i : tilt of the excitation of previous subframe Q15 */ - const Word16 pt_pitch, /* i : pointer to current subframe fractional pitch Q6*/ - Word16 *code, /* o : algebraic excitation */ - const Word16 L_subfr /* i : subframe length */ - ); +void inov_decode_ivas_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const Word16 L_frame, /* i : length of the frame */ + const Word16 sharpFlag, /* i : formant sharpening flag */ + const Word16 i_subfr, /* i : subframe index */ + const Word16 *p_Aq, /* i : LP filter coefficients Q12 */ + const Word16 tilt_code, /* i : tilt of the excitation of previous subframe Q15 */ + const Word16 pt_pitch, /* i : pointer to current subframe fractional pitch Q6*/ + Word16 *code, /* o : algebraic excitation */ + const Word16 L_subfr /* i : subframe length */ +); #endif #ifdef IVAS_FLOAT_FIXED - //dec4t64_fx.c - void dec_acelp_4t64_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 nbbits, /* i : number of bits per codebook */ - Word16 code[], /* o : algebraic (fixed) codebook excitation Q9*/ - const Word16 Opt_AMR_WB - ); +// dec4t64_fx.c +void dec_acelp_4t64_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 nbbits, /* i : number of bits per codebook */ + Word16 code[], /* o : algebraic (fixed) codebook excitation Q9*/ + const Word16 Opt_AMR_WB ); #endif - void D_ACELP_decode_43bit_fx(UWord16 idxs[], Word16 code[], Word16 *pulsestrack); +void D_ACELP_decode_43bit_fx( UWord16 idxs[], Word16 code[], Word16 *pulsestrack ); #ifdef IVAS_FLOAT_FIXED - //dec_acelp_fx.c - void D_ACELP_indexing_fx( - Word16 code[], - PulseConfig config, - Word16 num_tracks, - Word16 index[] - , Word16 *BER_detect - ); - - void fcb_pulse_track_joint_decode_fx(UWord16 *idxs, Word16 wordcnt, UWord32 *index_n, Word16 *pulse_num, Word16 track_num); +// dec_acelp_fx.c +void D_ACELP_indexing_fx( + Word16 code[], + PulseConfig config, + Word16 num_tracks, + Word16 index[], + Word16 *BER_detect ); + +void fcb_pulse_track_joint_decode_fx( UWord16 *idxs, Word16 wordcnt, UWord32 *index_n, Word16 *pulse_num, Word16 track_num ); #endif - //dec2t32_fx.c - void dec_acelp_2t32_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 code[] /* o: algebraic (fixed) codebook excitation */ - ); - - void dec_acelp_1t64_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 code[] /* o: algebraic (fixed) codebook excitation Q12*/ - , const Word16 L_subfr /* i : sub frame lenght*/ - ); - - //acelp_core_switch)dec_fx.c - ivas_error acelp_core_switch_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *synth_subfr_out, /* o : synthesized ACELP subframe Q_syn*/ - Word16 *tmp_synth_bwe, /* o : synthesized ACELP subframe BWE Q_syn*/ - const Word16 output_frame, /* i : input frame length */ - const Word16 core_switching_flag, /* i : core switching flag */ - Word16 *mem_synth, /* o : synthesis to overlap */ - Word16 *Q_syn - ); - - ivas_error acelp_core_switch_dec_bfi_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 synth_out[], /* o : synthesis Q_syn */ - const Word16 coder_type /* i : coder type */ - ); - - ivas_error acelp_core_switch_dec_bfi_ivas_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 synth_out[], /* o : synthesis Q_syn */ - const Word16 coder_type /* i : coder type */ - ); - - //pred_lt4_fx.c - void pred_lt4( - const Word16 excI[], /* in : excitation buffer */ - Word16 excO[], /* out: excitation buffer */ - const Word16 T0, /* i : integer pitch lag */ - Word16 frac, /* i : fraction of lag */ - const Word16 L_subfr, /* i : subframe size */ - const Word16* win, /* i : interpolation window */ - const Word16 nb_coef, /* i : nb of filter coef */ - const Word16 up_sample /* i : up_sample */ - ); - - - void pred_lt4_tc_fx( - Word16 exc[], /* i/o: excitation buffer */ - const Word16 T0, /* i : integer pitch lag */ - Word16 frac, /* i: fraction of lag */ - const Word16 *win, /* i : interpolation window */ - const Word16 imp_pos, /* i : glottal impulse position */ - const Word16 i_subfr /* i : subframe index */ - ); - - //pvq_cored_dec - void pvq_decode_frame_fx( - Decoder_State *st_fx, - Word16 *coefs_quant, /* o : quantized coefficients */ - Word16 *npulses, /* o : number of pulses per band */ - Word16 *pulse_vector, /* o : non-normalized pulse shapes */ - const Word16 *sfm_start, /* i : indices of first coefficients in the bands */ - const Word16 *sfm_end, /* i : indices of last coefficients in the bands */ - const Word16 *sfmsize, /* i : band sizes */ - const Word16 nb_sfm, /* i : total number of bands */ - const Word16 *R, /* i : bitallocation per band */ - const Word16 pvq_bits, /* i : number of bits avaiable */ - const Word16 core /* i : core */ - ); - - Word16 pvq_core_dec_fx( - Decoder_State *st_fx, - const Word16 *sfm_start, - const Word16 *sfm_end, - const Word16 *sfmsize, - Word16 coefs_quant[], /* o : output MDCT */ - Word16 *Q_coefs, - Word16 bits_tot, - Word16 nb_sfm, - Word16 *R, - Word16 *Rs, - Word16 *npulses, - Word16 *maxpulse, - const Word16 core - ); +// dec2t32_fx.c +void dec_acelp_2t32_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 code[] /* o: algebraic (fixed) codebook excitation */ +); + +void dec_acelp_1t64_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 code[] /* o: algebraic (fixed) codebook excitation Q12*/ + , + const Word16 L_subfr /* i : sub frame lenght*/ +); + +// acelp_core_switch)dec_fx.c +ivas_error acelp_core_switch_dec_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *synth_subfr_out, /* o : synthesized ACELP subframe Q_syn*/ + Word16 *tmp_synth_bwe, /* o : synthesized ACELP subframe BWE Q_syn*/ + const Word16 output_frame, /* i : input frame length */ + const Word16 core_switching_flag, /* i : core switching flag */ + Word16 *mem_synth, /* o : synthesis to overlap */ + Word16 *Q_syn ); + +ivas_error acelp_core_switch_dec_bfi_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 synth_out[], /* o : synthesis Q_syn */ + const Word16 coder_type /* i : coder type */ +); + +ivas_error acelp_core_switch_dec_bfi_ivas_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 synth_out[], /* o : synthesis Q_syn */ + const Word16 coder_type /* i : coder type */ +); + +// pred_lt4_fx.c +void pred_lt4( + const Word16 excI[], /* in : excitation buffer */ + Word16 excO[], /* out: excitation buffer */ + const Word16 T0, /* i : integer pitch lag */ + Word16 frac, /* i : fraction of lag */ + const Word16 L_subfr, /* i : subframe size */ + const Word16 *win, /* i : interpolation window */ + const Word16 nb_coef, /* i : nb of filter coef */ + const Word16 up_sample /* i : up_sample */ +); + + +void pred_lt4_tc_fx( + Word16 exc[], /* i/o: excitation buffer */ + const Word16 T0, /* i : integer pitch lag */ + Word16 frac, /* i: fraction of lag */ + const Word16 *win, /* i : interpolation window */ + const Word16 imp_pos, /* i : glottal impulse position */ + const Word16 i_subfr /* i : subframe index */ +); + +// pvq_cored_dec +void pvq_decode_frame_fx( + Decoder_State *st_fx, + Word16 *coefs_quant, /* o : quantized coefficients */ + Word16 *npulses, /* o : number of pulses per band */ + Word16 *pulse_vector, /* o : non-normalized pulse shapes */ + const Word16 *sfm_start, /* i : indices of first coefficients in the bands */ + const Word16 *sfm_end, /* i : indices of last coefficients in the bands */ + const Word16 *sfmsize, /* i : band sizes */ + const Word16 nb_sfm, /* i : total number of bands */ + const Word16 *R, /* i : bitallocation per band */ + const Word16 pvq_bits, /* i : number of bits avaiable */ + const Word16 core /* i : core */ +); + +Word16 pvq_core_dec_fx( + Decoder_State *st_fx, + const Word16 *sfm_start, + const Word16 *sfm_end, + const Word16 *sfmsize, + Word16 coefs_quant[], /* o : output MDCT */ + Word16 *Q_coefs, + Word16 bits_tot, + Word16 nb_sfm, + Word16 *R, + Word16 *Rs, + Word16 *npulses, + Word16 *maxpulse, + const Word16 core ); #ifdef IVAS_FLOAT_FIXED - Word16 ivas_pvq_core_dec_fx( - Decoder_State *st_fx, - const Word16 *sfm_start, - const Word16 *sfm_end, - const Word16 *sfmsize, - Word16 coefs_quant[], /* o : output MDCT */ - Word16 *Q_coefs, - Word16 bits_tot, - Word16 nb_sfm, - Word16 *R, /* Q3 */ - Word16 *Rs, - Word16 *npulses, - Word16 *maxpulse, - const Word16 core); +Word16 ivas_pvq_core_dec_fx( + Decoder_State *st_fx, + const Word16 *sfm_start, + const Word16 *sfm_end, + const Word16 *sfmsize, + Word16 coefs_quant[], /* o : output MDCT */ + Word16 *Q_coefs, + Word16 bits_tot, + Word16 nb_sfm, + Word16 *R, /* Q3 */ + Word16 *Rs, + Word16 *npulses, + Word16 *maxpulse, + const Word16 core ); #endif - void decode_energies_fx( - Decoder_State *st_fx, - PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ - Word16 Np, - Word16 *dim_part, - Word16 *bits_part, - Word16 *g_part, /* Q15 */ - Word16 qband, - Word16 *bits_left, - Word16 dim, - const Word16 strict_bits - ); - - //range_drc_fx.c - void rc_dec_init_fx( - Decoder_State *st_fx, /* i/o: Decoder State */ - PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ - Word16 tot_bits /* i : Total bit budget */ - ); - - UWord32 rc_decode_fx( /* o : Decoded cumulative frequency */ - Word16* BER_detect, /* o : Bit error detection flag */ - PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ - UWord32 tot /* i : Total cumulative frequency */ - ); - - void rc_dec_update_fx( - Decoder_State *st_fx, /* i/o: Decoder State */ - PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ - - UWord32 cum_freq, /* i : Cumulative frequency */ - UWord32 sym_freq /* i : Symbol frequency */ - ); - - Word32 rc_dec_bits_fx( /* i : Decoded value */ - Decoder_State *st_fx, /* i/o: Decoder State */ - PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ - Word16 bits /* i : Number of bits */ - ); - - UWord32 rc_dec_uniform_fx( /* i : Decoded value */ - Decoder_State *st_fx, /* i/o: Decoder State */ - PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ - - UWord32 tot /* i : Maximum value */ - ); - - void rc_dec_finish_fx( - Decoder_State *st_fx, - PVQ_DEC_HANDLE hPVQ /* i/o: PVQ decoder handle */ - ); - - //pvq_decode_fx.c - void pvq_decode_fx( - Decoder_State *st_fx, - PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ - Word16 *xq, /* o: decoded vector (Q15) */ - Word16 *y, /* o: decoded vector (non-scaled int) */ - const Word16 k_val, /* i: number of allocated pulses */ - const Word16 dim, /* i: Length of vector */ - const Word16 neg_gain /* i: Gain (negated to fit 1.0 in Q15 as -1.0) */ - ); - - //nelp_dec_fx.c - void nelp_decoder_fx( - Decoder_State *st, /* i/o: decoder static memory */ - Word16 *exc_nelp, /* o : adapt. excitation/total exc */ - Word16 *exc, /* o : adapt. excitation exc */ - Word16 *Q_exc, - Word16 bfi, /* i : frame error rate */ - const Word16 coder_type /* i : coding type */ - , Word16 *gain_buf /*Q14*/ - ); - - //dec_nelp_fx.c - void decod_nelp_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - Word16 *tmp_noise_fx, /* o : long term temporary noise energy */ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe*/ - Word16 *exc_fx, /* o : adapt. excitation exc */ - Word16 *exc2_fx, /* o : adapt. excitation/total exc */ - Word16 *voice_factors, /* o : Voice factor */ - Word16 *bwe_exc, - Word16 *Q_exc, - Word16 bfi /* i : frame error rate */ - , Word16 *gain_buf /*Q14*/ - ); - - //lp_filt_exc_dec_fx - void lp_filt_exc_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 codec_mode, /* i : coder mode */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 L_subfr, /* i : subframe size */ - const Word16 L_frame, /* i : frame size */ - Word16 lp_flag, /* i : operation mode signalling */ - Word16 *exc - ); - - //FEC_lsf_estim_fx.c - void FEC_lsf2lsp_interp( - Decoder_State *st, /* i/o: Decoder static memory */ - const Word16 L_frame, /* i : length of the frame */ - Word16 *Aq, /* o : calculated A(z) for 4 subframes */ - Word16 *lsf, /* o : estimated LSF vector */ - Word16 *lsp /* o : estimated LSP vector */ - ); - - - //fd_cng_dec_fx.c - ivas_error createFdCngDec_fx(HANDLE_FD_CNG_DEC* hFdCngDec); - - void initFdCngDec_fx( - DEC_CORE_HANDLE st, /* i/o: decoder state structure */ - Word16 scale - ); - - /* Delete the instance of type FD_CNG */ - void deleteFdCngDec_fx(HANDLE_FD_CNG_DEC* hFdCngDec); - - /* Configure CLDFB-CNG */ - void configureFdCngDec_fx( - HANDLE_FD_CNG_DEC hFdCngDec, /* i/o: Contains the variables related to the CLDFB-based CNG process */ - Word16 bandwidth, - Word32 bitrate, - Word16 L_frame, - const Word16 Last_L_frame, - const Word16 element_mode - ); - - /* Apply the CLDFB-based CNG */ - Word16 ApplyFdCng_fx( - Word16* timeDomainInput, /* i : pointer to time domain i */ - Word16 Q, +void decode_energies_fx( + Decoder_State *st_fx, + PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ + Word16 Np, + Word16 *dim_part, + Word16 *bits_part, + Word16 *g_part, /* Q15 */ + Word16 qband, + Word16 *bits_left, + Word16 dim, + const Word16 strict_bits ); + +// range_drc_fx.c +void rc_dec_init_fx( + Decoder_State *st_fx, /* i/o: Decoder State */ + PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ + Word16 tot_bits /* i : Total bit budget */ +); + +UWord32 rc_decode_fx( /* o : Decoded cumulative frequency */ + Word16 *BER_detect, /* o : Bit error detection flag */ + PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ + UWord32 tot /* i : Total cumulative frequency */ +); + +void rc_dec_update_fx( + Decoder_State *st_fx, /* i/o: Decoder State */ + PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ + + UWord32 cum_freq, /* i : Cumulative frequency */ + UWord32 sym_freq /* i : Symbol frequency */ +); + +Word32 rc_dec_bits_fx( /* i : Decoded value */ + Decoder_State *st_fx, /* i/o: Decoder State */ + PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ + Word16 bits /* i : Number of bits */ +); + +UWord32 rc_dec_uniform_fx( /* i : Decoded value */ + Decoder_State *st_fx, /* i/o: Decoder State */ + PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ + + UWord32 tot /* i : Maximum value */ +); + +void rc_dec_finish_fx( + Decoder_State *st_fx, + PVQ_DEC_HANDLE hPVQ /* i/o: PVQ decoder handle */ +); + +// pvq_decode_fx.c +void pvq_decode_fx( + Decoder_State *st_fx, + PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ + Word16 *xq, /* o: decoded vector (Q15) */ + Word16 *y, /* o: decoded vector (non-scaled int) */ + const Word16 k_val, /* i: number of allocated pulses */ + const Word16 dim, /* i: Length of vector */ + const Word16 neg_gain /* i: Gain (negated to fit 1.0 in Q15 as -1.0) */ +); + +// nelp_dec_fx.c +void nelp_decoder_fx( + Decoder_State *st, /* i/o: decoder static memory */ + Word16 *exc_nelp, /* o : adapt. excitation/total exc */ + Word16 *exc, /* o : adapt. excitation exc */ + Word16 *Q_exc, + Word16 bfi, /* i : frame error rate */ + const Word16 coder_type /* i : coding type */ + , + Word16 *gain_buf /*Q14*/ +); + +// dec_nelp_fx.c +void decod_nelp_fx( + Decoder_State *st_fx, /* i/o: decoder static memory */ + Word16 *tmp_noise_fx, /* o : long term temporary noise energy */ + Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe*/ + Word16 *exc_fx, /* o : adapt. excitation exc */ + Word16 *exc2_fx, /* o : adapt. excitation/total exc */ + Word16 *voice_factors, /* o : Voice factor */ + Word16 *bwe_exc, + Word16 *Q_exc, + Word16 bfi /* i : frame error rate */ + , + Word16 *gain_buf /*Q14*/ +); + +// lp_filt_exc_dec_fx +void lp_filt_exc_dec_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 codec_mode, /* i : coder mode */ + const Word16 i_subfr, /* i : subframe index */ + const Word16 L_subfr, /* i : subframe size */ + const Word16 L_frame, /* i : frame size */ + Word16 lp_flag, /* i : operation mode signalling */ + Word16 *exc ); + +// FEC_lsf_estim_fx.c +void FEC_lsf2lsp_interp( + Decoder_State *st, /* i/o: Decoder static memory */ + const Word16 L_frame, /* i : length of the frame */ + Word16 *Aq, /* o : calculated A(z) for 4 subframes */ + Word16 *lsf, /* o : estimated LSF vector */ + Word16 *lsp /* o : estimated LSP vector */ +); + + +// fd_cng_dec_fx.c +ivas_error createFdCngDec_fx( HANDLE_FD_CNG_DEC *hFdCngDec ); + +void initFdCngDec_fx( + DEC_CORE_HANDLE st, /* i/o: decoder state structure */ + Word16 scale ); + +/* Delete the instance of type FD_CNG */ +void deleteFdCngDec_fx( HANDLE_FD_CNG_DEC *hFdCngDec ); + +/* Configure CLDFB-CNG */ +void configureFdCngDec_fx( + HANDLE_FD_CNG_DEC hFdCngDec, /* i/o: Contains the variables related to the CLDFB-based CNG process */ + Word16 bandwidth, + Word32 bitrate, + Word16 L_frame, + const Word16 Last_L_frame, + const Word16 element_mode ); + +/* Apply the CLDFB-based CNG */ +Word16 ApplyFdCng_fx( + Word16 *timeDomainInput, /* i : pointer to time domain i */ + Word16 Q, #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - Word16* powerSpectrum, + Word16 *powerSpectrum, #endif - Word32** cldfbBufferReal, /* i/o: real part of the CLDFB buffer */ - Word32** cldfbBufferImag, /* i/o: imaginary part of the CLDFB buffer */ - Word16* cldfbBufferScale, /* o : pointer to the scalefactor for real and imaginary part of the CLDFB buffer */ - Decoder_State* st, - const Word16 concealWholeFrame, /* i : binary flag indicating frame loss */ - Word16 is_music - ); - - Word16 ApplyFdCng_ivas_fx( - Word16 *timeDomainInput, /* i : pointer to time domain input */ - Word16 Q, - Word32 *powerSpectrum, - Word16 Q_power_spectrum, - Word32 **cldfbBufferReal, /* i/o: real part of the CLDFB buffer */ - Word32 **cldfbBufferImag, /* i/o: imaginary part of the CLDFB buffer */ - Word16 *cldfbBufferScale, /* o : pointer to the scalefactor for real and imaginary part of the CLDFB buffer */ - Decoder_State *st, - const Word16 concealWholeFrame, /* i : binary flag indicating frame loss */ - Word16 is_music -); - - /* Perform noise estimation */ - void perform_noise_estimation_dec_fx( - const Word16* timeDomainInput, /* i: pointer to time domain i */ - const Word16 Q, + Word32 **cldfbBufferReal, /* i/o: real part of the CLDFB buffer */ + Word32 **cldfbBufferImag, /* i/o: imaginary part of the CLDFB buffer */ + Word16 *cldfbBufferScale, /* o : pointer to the scalefactor for real and imaginary part of the CLDFB buffer */ + Decoder_State *st, + const Word16 concealWholeFrame, /* i : binary flag indicating frame loss */ + Word16 is_music ); + +Word16 ApplyFdCng_ivas_fx( + Word16 *timeDomainInput, /* i : pointer to time domain input */ + Word16 Q, + Word32 *powerSpectrum, + Word16 Q_power_spectrum, + Word32 **cldfbBufferReal, /* i/o: real part of the CLDFB buffer */ + Word32 **cldfbBufferImag, /* i/o: imaginary part of the CLDFB buffer */ + Word16 *cldfbBufferScale, /* o : pointer to the scalefactor for real and imaginary part of the CLDFB buffer */ + Decoder_State *st, + const Word16 concealWholeFrame, /* i : binary flag indicating frame loss */ + Word16 is_music ); + +/* Perform noise estimation */ +void perform_noise_estimation_dec_fx( + const Word16 *timeDomainInput, /* i: pointer to time domain i */ + const Word16 Q, #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - float* power_spectrum, + float *power_spectrum, #endif - HANDLE_FD_CNG_DEC hFdCngDec /* i/o: FD_CNG structure containing all buffers and variables */ + HANDLE_FD_CNG_DEC hFdCngDec /* i/o: FD_CNG structure containing all buffers and variables */ #ifdef IVAS_CODE_CNG - , const Word16 element_mode, /* i : element mode */ - const Word16 bwidth, /* i : audio bandwidth */ - const Word16 L_frame, /* i : frame length at internal Fs */ - const Word16 last_L_frame, /* i : frame length of the last frame at internal Fs */ - const Word32 last_core_brate, /* i : previous frame core bitrate */ - const Word16 VAD /* i : VAD flag in the decoder */ + , + const Word16 element_mode, /* i : element mode */ + const Word16 bwidth, /* i : audio bandwidth */ + const Word16 L_frame, /* i : frame length at internal Fs */ + const Word16 last_L_frame, /* i : frame length of the last frame at internal Fs */ + const Word32 last_core_brate, /* i : previous frame core bitrate */ + const Word16 VAD /* i : VAD flag in the decoder */ #endif - ); - - void perform_noise_estimation_dec_ivas_fx( - const Word16 *timeDomainInput, /* i: pointer to time domain input */ - const Word16 Q, - Word32 *power_spectrum, - Word16 Q_power_spectrum, - HANDLE_FD_CNG_DEC hFdCngDec, /* i/o: FD_CNG structure containing all buffers and variables */ - const Word16 element_mode, /* i : element mode */ - const Word16 bwidth, /* i : audio bandwidth */ - const Word16 L_frame, /* i : frame length at internal Fs */ - const Word16 last_L_frame, /* i : frame length of the last frame at internal Fs */ - const Word32 last_core_brate, /* i : previous frame core bitrate */ - const Word16 VAD /* i : VAD flag in the decoder */ - ); - - /* Decode the CLDFB-CNG bitstream */ - void FdCng_decodeSID_fx(HANDLE_FD_CNG_COM st, /* i/o: FD_CNG structure containing all buffers and variables */ - Decoder_State *corest); /* i/o: decoder state structure */ - - void noisy_speech_detection_fx( - HANDLE_FD_CNG_DEC hFdCngDec,/* i/o: FD_CNG structure */ - const Word16 vad, /* i : VAD flag */ - const Word16* syn, /* i : i time-domain frame */ - const Word16 Q - ); - - void generate_comfort_noise_dec_fx( - Word32 **bufferReal, /* o : matrix to real part of i bands */ - Word32 **bufferImag, /* o : matrix to imaginary part of i bands */ - Word16 *bufferScale, /* o : pointer to scalefactor for real and imaginary part of i bands */ - Decoder_State *stdec, - Word16 *Q_new, - Word16 gen_exc - , const Word16 nchan_out /* i : number of output channels */ - ); - - void - generate_comfort_noise_dec_hf_fx(Word32 **bufferReal, /* o : matrix to real part of i bands */ - Word32 **bufferImag, /* o : matrix to imaginary part of i bands */ - Word16 *bufferScale, /* o : pointer to scalefactor for real and imaginary part of i bands */ - Decoder_State *stdec - ); +); + +void perform_noise_estimation_dec_ivas_fx( + const Word16 *timeDomainInput, /* i: pointer to time domain input */ + const Word16 Q, + Word32 *power_spectrum, + Word16 Q_power_spectrum, + HANDLE_FD_CNG_DEC hFdCngDec, /* i/o: FD_CNG structure containing all buffers and variables */ + const Word16 element_mode, /* i : element mode */ + const Word16 bwidth, /* i : audio bandwidth */ + const Word16 L_frame, /* i : frame length at internal Fs */ + const Word16 last_L_frame, /* i : frame length of the last frame at internal Fs */ + const Word32 last_core_brate, /* i : previous frame core bitrate */ + const Word16 VAD /* i : VAD flag in the decoder */ +); + +/* Decode the CLDFB-CNG bitstream */ +void FdCng_decodeSID_fx( HANDLE_FD_CNG_COM st, /* i/o: FD_CNG structure containing all buffers and variables */ + Decoder_State *corest ); /* i/o: decoder state structure */ + +void noisy_speech_detection_fx( + HANDLE_FD_CNG_DEC hFdCngDec, /* i/o: FD_CNG structure */ + const Word16 vad, /* i : VAD flag */ + const Word16 *syn, /* i : i time-domain frame */ + const Word16 Q ); + +void generate_comfort_noise_dec_fx( + Word32 **bufferReal, /* o : matrix to real part of i bands */ + Word32 **bufferImag, /* o : matrix to imaginary part of i bands */ + Word16 *bufferScale, /* o : pointer to scalefactor for real and imaginary part of i bands */ + Decoder_State *stdec, + Word16 *Q_new, + Word16 gen_exc, + const Word16 nchan_out /* i : number of output channels */ +); + +void generate_comfort_noise_dec_hf_fx( Word32 **bufferReal, /* o : matrix to real part of i bands */ + Word32 **bufferImag, /* o : matrix to imaginary part of i bands */ + Word16 *bufferScale, /* o : pointer to scalefactor for real and imaginary part of i bands */ + Decoder_State *stdec ); void generate_comfort_noise_dec_hf_ivas_fx( - Word32 **bufferReal, /* o : matrix to real part of input bands */ - Word32 **bufferImag, /* o : matrix to imaginary part of input bands */ - Word16 *bufferScale, /* o : pointer to scalefactor for real and imaginary part of input bands */ - HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ - const Word16 cng_coh_flag /* i : CNG Flag for coherence handling */ - ); - - /* Generate the comfort noise based on the target noise level */ - void generate_masking_noise_fx(Word16 *timeDomainBuffer, /* i/o: time-domain signal */ - Word16 Q, - HANDLE_FD_CNG_COM st /* i/o: FD_CNG structure containing all buffers and variables */ - , Word16 length - , Word16 core - ); - - void generate_masking_noise_update_seed_fx( - HANDLE_FD_CNG_COM st /* i/o : pointer to FD_CNG_COM structure */ - ); - - void generate_masking_noise_mdct_fx(Word32 *mdctBuffer, /* i/o: time-domain signal */ - Word16 *mdctBuffer_e, /* i/o: exponent time-domain signal */ - HANDLE_FD_CNG_COM st /* i/o: FD_CNG structure containing all buffers and variables */ - , Word16 L_frame - ); - -//init_dec_fx.c - ivas_error init_decoder_fx( - Decoder_State *st_fx, /* o: Decoder static variables structure */ - const Word16 idchan /* i : channel ID */ - ); - - ivas_error init_decoder_ivas_fx( - Decoder_State *st_fx, /* o: Decoder static variables structure */ - const Word16 idchan, /* i : channel ID */ - const MC_MODE mc_mode /* i : MC mode */ - ); - - void reset_preecho_dec_fx( - HQ_DEC_HANDLE hHQ_core /* i/o: HQ core data handle */ - ); - - void destroy_cldfb_decoder_fx( - Decoder_State *st_fx /* o: Decoder static variables structure */ - ); - - //swb_bwe_dec_fx.c - Word16 WB_BWE_gain_deq_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *WB_fenv - ); - - - Word16 wb_bwe_dec_fx( + Word32 **bufferReal, /* o : matrix to real part of input bands */ + Word32 **bufferImag, /* o : matrix to imaginary part of input bands */ + Word16 *bufferScale, /* o : pointer to scalefactor for real and imaginary part of input bands */ + HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ + const Word16 cng_coh_flag /* i : CNG Flag for coherence handling */ +); + +/* Generate the comfort noise based on the target noise level */ +void generate_masking_noise_fx( Word16 *timeDomainBuffer, /* i/o: time-domain signal */ + Word16 Q, + HANDLE_FD_CNG_COM st /* i/o: FD_CNG structure containing all buffers and variables */ + , + Word16 length, + Word16 core ); + +void generate_masking_noise_update_seed_fx( + HANDLE_FD_CNG_COM st /* i/o : pointer to FD_CNG_COM structure */ +); + +void generate_masking_noise_mdct_fx( Word32 *mdctBuffer, /* i/o: time-domain signal */ + Word16 *mdctBuffer_e, /* i/o: exponent time-domain signal */ + HANDLE_FD_CNG_COM st /* i/o: FD_CNG structure containing all buffers and variables */ + , + Word16 L_frame ); + +// init_dec_fx.c +ivas_error init_decoder_fx( + Decoder_State *st_fx, /* o: Decoder static variables structure */ + const Word16 idchan /* i : channel ID */ +); + +ivas_error init_decoder_ivas_fx( + Decoder_State *st_fx, /* o: Decoder static variables structure */ + const Word16 idchan, /* i : channel ID */ + const MC_MODE mc_mode /* i : MC mode */ +); + +void reset_preecho_dec_fx( + HQ_DEC_HANDLE hHQ_core /* i/o: HQ core data handle */ +); + +void destroy_cldfb_decoder_fx( + Decoder_State *st_fx /* o: Decoder static variables structure */ +); + +// swb_bwe_dec_fx.c +Word16 WB_BWE_gain_deq_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *WB_fenv ); + + +Word16 wb_bwe_dec_fx( #ifdef ADD_IVAS_BWE - const Word16 output[], /* i : suntehsis @ internal Fs */ + const Word16 output[], /* i : suntehsis @ internal Fs */ #endif - Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis */ - Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis */ + Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis */ + Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis */ #ifdef ADD_IVAS_BWE - const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ + const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ #endif - const Word16 output_frame, /* i : frame length */ - Word16 *voice_factors_fx, /* i : voicing factors */ - const Word16 pitch_buf_fx[],/* i : pitch buffer */ - Decoder_State *st_fx /* i/o: decoder state structure */ - , Word16 * Qpost - ); - - Word16 swb_bwe_gain_deq_fx( /* o : BWE class */ - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 core, /* i : core */ - Word16 *SWB_tenv, /* o : Q0, time-domain BWE envelope */ - Word16 *SWB_fenv, /* o : Q1, frequency-domain BWE envelope */ - const Word16 hr_flag, /* i : high rate flag */ - const Word16 hqswb_clas /* i : HQ BWE class */ - ); - - Word16 swb_bwe_dec_fx( + const Word16 output_frame, /* i : frame length */ + Word16 *voice_factors_fx, /* i : voicing factors */ + const Word16 pitch_buf_fx[], /* i : pitch buffer */ + Decoder_State *st_fx /* i/o: decoder state structure */ + , + Word16 *Qpost ); + +Word16 swb_bwe_gain_deq_fx( /* o : BWE class */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 core, /* i : core */ + Word16 *SWB_tenv, /* o : Q0, time-domain BWE envelope */ + Word16 *SWB_fenv, /* o : Q1, frequency-domain BWE envelope */ + const Word16 hr_flag, /* i : high rate flag */ + const Word16 hqswb_clas /* i : HQ BWE class */ +); + +Word16 swb_bwe_dec_fx( #ifdef ADD_IVAS_BWE - const Word16 output[], /* i : suntehsis @ internal Fs */ + const Word16 output[], /* i : suntehsis @ internal Fs */ #endif - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *synth_fx, /* i : ACELP core synthesis/final synthesis */ - Word16 *hb_synth, /* o : SHB synthesis/final synthesis */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *synth_fx, /* i : ACELP core synthesis/final synthesis */ + Word16 *hb_synth, /* o : SHB synthesis/final synthesis */ #ifdef ADD_IVAS_BWE - const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ + const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ #endif - const Word16 output_frame /* i : frame length */ - , Word16 * Qpost - ); - - void fd_bwe_dec_init( - Decoder_State* st_fx, /* i/o: decoder state structure */ - FD_BWE_DEC_HANDLE hBWE_FD /* i/o: FD BWE data handle */ - ); - - //hq_core_dec_fx.c - void hq_core_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure fx */ - Word16 synth[], /* o : output synthesis */ - Word16 *Q_synth, /* o : Q value of synth */ - const Word16 output_frame, /* i : output frame length */ - const Word16 hq_core_type, /* i : HQ core type */ - const Word16 core_switching_flag /* i : ACELP->HQ switching frame flag */ - ); - void HQ_core_dec_init_fx( - HQ_DEC_HANDLE hHQ_core /* i/o: HQ core data handle */ - ); - void HQ_nbfec_init_fx( - HQ_NBFEC_HANDLE hHQ_nbfec /* i/o: HQ NB FEC data handle */ - ); - - - //FEC_HQ_phase_ecu_fx.c - void hq_ecu_fx( - const Word16 *prevsynth, /* i : buffer of previously synthesized signal */ - Word32 *ecu_rec, /* o : reconstructed frame in tda domain */ - Word16 *time_offs, - Word16 *X_sav, - Word16 *Q_spec, /* i/o : Q value of stored spectrum */ - Word16 *num_p, - Word16 *plocs, - Word32 *plocsi, /* o : Interpolated positions of the identified peaks (Q16) */ - const Word16 env_stab, - Word16 *last_fec, - const Word16 ph_ecu_HqVoicing, - Word16 *ph_ecu_active, /* i : Phase ECU active flag */ - Word16 *gapsynth, - const Word16 prev_bfi, /* i : indicating burst frame error */ - const Word16 old_is_transient[2], /* i : flags indicating previous transient frames */ - Word16 *mag_chg_1st, /* i/o: per band magnitude modifier for transients*/ - Word16 *Xavg, /* i/o: Frequency group average gain to fade to */ - Word16 *beta_mute, /* o : Factor for long-term mute */ - const Word16 output_frame, /* i : frame length */ - Decoder_State *st_fx /* i/o: decoder state structure */ - ); - - - //hq_lr_dec_fx.c - void hq_lr_dec_fx( - Decoder_State *st_fx, /* i/o: : decoder state structure */ - Word32 L_yout[], /* o : Q12 : transform-domain output coefs. */ - const Word16 inner_frame, /* i : Q0 : inner frame length */ - Word16 num_bits, /* i : Q0 : number of available bits */ - Word16 *is_transient_fx /* o : Q0 : transient flag */ - ); - - //gq_env_dec_fx.c - Word16 decode_envelope_indices_fx( /* o : Number of bits */ - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 start_norm, /* i : starting band index */ - const Word16 num_sfm, /* i : Number of subbands */ - const Word16 numnrmibits, /* i : Bitrate of fall-back coding mode */ - Word16 *difidx, /* o : Diff indices/encoded diff indices */ - const Word16 flag_HQ2 /* i : indicator of HQ2 core */ - , - const Word16 is_transient /* i : indicator of HQ_TRANSIENT */ - ); - - void dequantize_norms_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 start_norm, /* i : First SDE encoded norm */ - const Word16 num_sfm, /* i : Number of norms */ - const Word16 is_transient, /* i : Transient flag */ - Word16 *ynrm, /* o : Decoded norm indices */ - Word16 *normqlg2 /* o : Log2 of decoded norms */ - ); - - //hdecnrm_fx.c - void hdecnrm_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 numNorms, /* (i) number of norms */ - Word16 *index); /* (o) indices of quantized norms */ - - - Word16 decode_huff_context_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 *hufftab, - Word16 *rbits - ); - - void hdecnrm_context_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 N, - Word16 *index, - Word16 *n_length - ); - - void hdecnrm_resize_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 N, /* (i) number of SFMs */ - Word16 *index /* (o) norm quantization index vector */ - ); - - void huff_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 N, /* i : Number of codewords to decode */ - const Word16 buffer_len, /* i : Number of bits to read */ - const Word16 num_lengths, /* i : Number of different huffman codeword lengths */ - const Word16 *thres, /* i : Threshold of first codeword of each length */ - const Word16 *offset, /* i : Offset for first codeword */ - const Word16 *huff_tab, /* i : Huffman table order by codeword lengths */ - Word16 *index /* o : Decoded index */ - ); - - void hdecnrm_tran_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 N, /* i : number of norms */ - Word16 *index /* o : indices of quantized norms */ - ); - - //tcq_core_dec_fx.c - void tcq_core_LR_dec_fx( - Decoder_State *st_fx, - Word16 *inp_vector_fx, - const Word16 bit_budget, - const Word16 bands, - const Word16 *band_start, - const Word16 *band_width, - Word32 *Rk_fx, - Word16 *npulses, - Word16 *k_sort, - const Word16 *p2a_flags, - const Word16 p2a_bands, - const Word16 *last_bitalloc, - const Word16 input_frame, - const Word16 adjustFlag, - const Word16 *is_transient - ); - - //FEC_HQ_core_fx.c - void HQ_FEC_processing_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word32 *t_audio_q_fx, /* o : MDCT coeffs. (for synthesis) Q12 */ - Word16 is_transient, /* i : Old flag for transient */ - Word32 ynrm_values_fx[][MAX_PGF], /* i : Old average Norm values for each group of bands Q12 */ - Word32 r_p_values_fx[][MAX_ROW], /* i : Computed y-intercept and slope by Regression Q5 */ - Word16 num_Sb, /* i : Number of sub-band group */ - Word16 nb_sfm, /* i : Number of sub-band */ - Word16 *Num_bands_p, /* i : Number of coeffs. for each sub-band */ - Word16 output_frame, /* i : Frame size */ - const Word16 *sfm_start, /* i : Start of bands */ - const Word16 *sfm_end /* i : End of bands */ - ); - - void HQ_FEC_Mem_update_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word32 *t_audio_q_fx, /*Q12*/ - Word32 *normq_fx, /*Q14*/ - Word16 *ynrm, - Word16 *Num_bands_p, - Word16 is_transient, - Word16 hqswb_clas, - Word16 c_switching_flag, - Word16 nb_sfm, - Word16 num_Sb, - Word16 *mean_en_high_fx, /*Q5*/ - Word16 hq_core_type, /* i : normal or low-rate MDCT(HQ) core */ - Word16 output_frame - ); - - void time_domain_FEC_HQ_fx( - Decoder_State *st_fx, /* i : Decoder State */ - Word32 *wtda_audio_fx, /* i : i */ - Word16 *out_fx, /* o : output audio */ - Word16 mean_en_high_fx, /* i : transient flag */ - const Word16 output_frame, - Word16 *Q_synth - ); - - //hq_hr_dec_fx.c - void hq_pred_hb_bws_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 *ynrm, /* i : norm quantization index vector */ - const Word16 length, /* i : frame length */ - const Word16 hqswb_clas, /* i : HQ SWB class */ - const Word16 *SWB_fenv /* i : SWB frequency envelopes Q1 */ - ); - - void hq_hr_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure fx */ - Word32 *L_coefsq, /* o : transform-domain coefficients Q12 */ - const Word16 length, /* i : frame length Q0 */ - Word16 num_bits, /* i : number of available bits Q0 */ - Word16 *ynrm, /* o : norm quantization index vector Q0 */ - Word16 *is_transient, /* o : transient flag Q0 */ - Word16 *hqswb_clas, /* o : HQ SWB class Q0 */ - Word16 *SWB_fenv, /* o : SWB frequency envelopes Q1 */ - const Word16 core_switching_flag /* i : Core switching flag */ - ); - - //hq_classifier_dec_fx.c - Word16 hq_classifier_dec_fx( /* o : Consumed bits Q0 */ - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : Core bit rate Q0 */ - const Word16 length, /* i : Frame length Q0 */ - Word16 *is_transient, /* o : Transient flag Q0 */ - Word16 *hqswb_clas /* o : HQ class Q0 */ - ); - - //peak_vq_dec_fx.c - void hvq_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 num_bits, /* i : Number of available bits */ - const Word32 core_brate, /* i : Core bit-rate */ - const Word16 *ynrm, /* i : Envelope coefficients */ - Word16 *R, /* i/o: Bit allocation/updated bit allocation */ - Word16 *noise_level, /* o : Noise level in Q15 */ - Word16 *peak_idx, /* o : Peak position vector */ - Word16 *Npeaks, /* o : Total number of peaks */ - Word32 *coefsq_norm, /* o : Output vector in Q12 */ - const Word16 core - ); - - //hvq_pvq_bitalloc_fx.c - Word16 hvq_pvq_bitalloc_fx( - Word16 num_bits, /* i/o: Number of available bits (including gain bits) */ - const Word32 brate, /* i : bitrate */ - const Word16 bwidth_fx, /* i : Encoded bandwidth */ - const Word16 *ynrm, /* i : Envelope coefficients */ - const Word32 manE_peak, /* i : Peak energy mantissa */ - const Word16 expE_peak, /* i : Peak energy exponent */ - Word16 *Rk, /* o : bit allocation for concatenated vector */ - Word16 *R, /* i/o: Global bit allocation */ - Word16 *sel_bands, /* o : Selected bands for encoding */ - Word16 *n_sel_bands /* o : No. of selected bands for encoding */ - ); - - //hq_conf_fec_fx.c - void hq_configure_bfi_fx( - Word16* nb_sfm, /* o : Number of sub bands Q0 */ - Word16* num_Sb, /* o : Number of FEC sub bands ? Q0 */ - Word16* num_bands_p, /* o : FEC sub bands Q0 */ - const Word16** sfmsize, /* o : Subband bandwidths */ - const Word16** sfm_start, /* o : Subband start coefficients */ - const Word16** sfm_end /* o : Subband end coefficients */ - ); - - //core_switching_dec_fx.c - void bandwidth_switching_detect_fx( - Decoder_State *st_fx /* i/o: encoder state structure */ - ); - - void bandwidth_switching_detect_ivas_fx( - Decoder_State *st_fx /* i/o: encoder state structure */ - ); - - void bw_switching_pre_proc_fx( - const Word16 *old_syn_12k8_16k_fx, /* i : ACELP core synthesis at 12.8kHz or 16kHz */ - Decoder_State *st_fx /* i/o: decoder state structure */ - ); - - ivas_error core_switching_pre_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 output_frame /* i : frame length */ - ); - - ivas_error core_switching_post_dec_fx( - Decoder_State * st_fx, /* i/o: decoder state structure */ - Word16* synth, /* i/o: output synthesis Qsynth */ + const Word16 output_frame /* i : frame length */ + , + Word16 *Qpost ); + +void fd_bwe_dec_init( + Decoder_State *st_fx, /* i/o: decoder state structure */ + FD_BWE_DEC_HANDLE hBWE_FD /* i/o: FD BWE data handle */ +); + +// hq_core_dec_fx.c +void hq_core_dec_fx( + Decoder_State *st_fx, /* i/o: decoder state structure fx */ + Word16 synth[], /* o : output synthesis */ + Word16 *Q_synth, /* o : Q value of synth */ + const Word16 output_frame, /* i : output frame length */ + const Word16 hq_core_type, /* i : HQ core type */ + const Word16 core_switching_flag /* i : ACELP->HQ switching frame flag */ +); +void HQ_core_dec_init_fx( + HQ_DEC_HANDLE hHQ_core /* i/o: HQ core data handle */ +); +void HQ_nbfec_init_fx( + HQ_NBFEC_HANDLE hHQ_nbfec /* i/o: HQ NB FEC data handle */ +); + + +// FEC_HQ_phase_ecu_fx.c +void hq_ecu_fx( + const Word16 *prevsynth, /* i : buffer of previously synthesized signal */ + Word32 *ecu_rec, /* o : reconstructed frame in tda domain */ + Word16 *time_offs, + Word16 *X_sav, + Word16 *Q_spec, /* i/o : Q value of stored spectrum */ + Word16 *num_p, + Word16 *plocs, + Word32 *plocsi, /* o : Interpolated positions of the identified peaks (Q16) */ + const Word16 env_stab, + Word16 *last_fec, + const Word16 ph_ecu_HqVoicing, + Word16 *ph_ecu_active, /* i : Phase ECU active flag */ + Word16 *gapsynth, + const Word16 prev_bfi, /* i : indicating burst frame error */ + const Word16 old_is_transient[2], /* i : flags indicating previous transient frames */ + Word16 *mag_chg_1st, /* i/o: per band magnitude modifier for transients*/ + Word16 *Xavg, /* i/o: Frequency group average gain to fade to */ + Word16 *beta_mute, /* o : Factor for long-term mute */ + const Word16 output_frame, /* i : frame length */ + Decoder_State *st_fx /* i/o: decoder state structure */ +); + + +// hq_lr_dec_fx.c +void hq_lr_dec_fx( + Decoder_State *st_fx, /* i/o: : decoder state structure */ + Word32 L_yout[], /* o : Q12 : transform-domain output coefs. */ + const Word16 inner_frame, /* i : Q0 : inner frame length */ + Word16 num_bits, /* i : Q0 : number of available bits */ + Word16 *is_transient_fx /* o : Q0 : transient flag */ +); + +// gq_env_dec_fx.c +Word16 decode_envelope_indices_fx( /* o : Number of bits */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 start_norm, /* i : starting band index */ + const Word16 num_sfm, /* i : Number of subbands */ + const Word16 numnrmibits, /* i : Bitrate of fall-back coding mode */ + Word16 *difidx, /* o : Diff indices/encoded diff indices */ + const Word16 flag_HQ2 /* i : indicator of HQ2 core */ + , + const Word16 is_transient /* i : indicator of HQ_TRANSIENT */ +); + +void dequantize_norms_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 start_norm, /* i : First SDE encoded norm */ + const Word16 num_sfm, /* i : Number of norms */ + const Word16 is_transient, /* i : Transient flag */ + Word16 *ynrm, /* o : Decoded norm indices */ + Word16 *normqlg2 /* o : Log2 of decoded norms */ +); + +// hdecnrm_fx.c +void hdecnrm_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 numNorms, /* (i) number of norms */ + Word16 *index ); /* (o) indices of quantized norms */ + + +Word16 decode_huff_context_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 *hufftab, + Word16 *rbits ); + +void hdecnrm_context_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 N, + Word16 *index, + Word16 *n_length ); + +void hdecnrm_resize_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 N, /* (i) number of SFMs */ + Word16 *index /* (o) norm quantization index vector */ +); + +void huff_dec_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 N, /* i : Number of codewords to decode */ + const Word16 buffer_len, /* i : Number of bits to read */ + const Word16 num_lengths, /* i : Number of different huffman codeword lengths */ + const Word16 *thres, /* i : Threshold of first codeword of each length */ + const Word16 *offset, /* i : Offset for first codeword */ + const Word16 *huff_tab, /* i : Huffman table order by codeword lengths */ + Word16 *index /* o : Decoded index */ +); + +void hdecnrm_tran_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 N, /* i : number of norms */ + Word16 *index /* o : indices of quantized norms */ +); + +// tcq_core_dec_fx.c +void tcq_core_LR_dec_fx( + Decoder_State *st_fx, + Word16 *inp_vector_fx, + const Word16 bit_budget, + const Word16 bands, + const Word16 *band_start, + const Word16 *band_width, + Word32 *Rk_fx, + Word16 *npulses, + Word16 *k_sort, + const Word16 *p2a_flags, + const Word16 p2a_bands, + const Word16 *last_bitalloc, + const Word16 input_frame, + const Word16 adjustFlag, + const Word16 *is_transient ); + +// FEC_HQ_core_fx.c +void HQ_FEC_processing_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word32 *t_audio_q_fx, /* o : MDCT coeffs. (for synthesis) Q12 */ + Word16 is_transient, /* i : Old flag for transient */ + Word32 ynrm_values_fx[][MAX_PGF], /* i : Old average Norm values for each group of bands Q12 */ + Word32 r_p_values_fx[][MAX_ROW], /* i : Computed y-intercept and slope by Regression Q5 */ + Word16 num_Sb, /* i : Number of sub-band group */ + Word16 nb_sfm, /* i : Number of sub-band */ + Word16 *Num_bands_p, /* i : Number of coeffs. for each sub-band */ + Word16 output_frame, /* i : Frame size */ + const Word16 *sfm_start, /* i : Start of bands */ + const Word16 *sfm_end /* i : End of bands */ +); + +void HQ_FEC_Mem_update_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word32 *t_audio_q_fx, /*Q12*/ + Word32 *normq_fx, /*Q14*/ + Word16 *ynrm, + Word16 *Num_bands_p, + Word16 is_transient, + Word16 hqswb_clas, + Word16 c_switching_flag, + Word16 nb_sfm, + Word16 num_Sb, + Word16 *mean_en_high_fx, /*Q5*/ + Word16 hq_core_type, /* i : normal or low-rate MDCT(HQ) core */ + Word16 output_frame ); + +void time_domain_FEC_HQ_fx( + Decoder_State *st_fx, /* i : Decoder State */ + Word32 *wtda_audio_fx, /* i : i */ + Word16 *out_fx, /* o : output audio */ + Word16 mean_en_high_fx, /* i : transient flag */ + const Word16 output_frame, + Word16 *Q_synth ); + +// hq_hr_dec_fx.c +void hq_pred_hb_bws_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 *ynrm, /* i : norm quantization index vector */ + const Word16 length, /* i : frame length */ + const Word16 hqswb_clas, /* i : HQ SWB class */ + const Word16 *SWB_fenv /* i : SWB frequency envelopes Q1 */ +); + +void hq_hr_dec_fx( + Decoder_State *st_fx, /* i/o: decoder state structure fx */ + Word32 *L_coefsq, /* o : transform-domain coefficients Q12 */ + const Word16 length, /* i : frame length Q0 */ + Word16 num_bits, /* i : number of available bits Q0 */ + Word16 *ynrm, /* o : norm quantization index vector Q0 */ + Word16 *is_transient, /* o : transient flag Q0 */ + Word16 *hqswb_clas, /* o : HQ SWB class Q0 */ + Word16 *SWB_fenv, /* o : SWB frequency envelopes Q1 */ + const Word16 core_switching_flag /* i : Core switching flag */ +); + +// hq_classifier_dec_fx.c +Word16 hq_classifier_dec_fx( /* o : Consumed bits Q0 */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word32 core_brate, /* i : Core bit rate Q0 */ + const Word16 length, /* i : Frame length Q0 */ + Word16 *is_transient, /* o : Transient flag Q0 */ + Word16 *hqswb_clas /* o : HQ class Q0 */ +); + +// peak_vq_dec_fx.c +void hvq_dec_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 num_bits, /* i : Number of available bits */ + const Word32 core_brate, /* i : Core bit-rate */ + const Word16 *ynrm, /* i : Envelope coefficients */ + Word16 *R, /* i/o: Bit allocation/updated bit allocation */ + Word16 *noise_level, /* o : Noise level in Q15 */ + Word16 *peak_idx, /* o : Peak position vector */ + Word16 *Npeaks, /* o : Total number of peaks */ + Word32 *coefsq_norm, /* o : Output vector in Q12 */ + const Word16 core ); + +// hvq_pvq_bitalloc_fx.c +Word16 hvq_pvq_bitalloc_fx( + Word16 num_bits, /* i/o: Number of available bits (including gain bits) */ + const Word32 brate, /* i : bitrate */ + const Word16 bwidth_fx, /* i : Encoded bandwidth */ + const Word16 *ynrm, /* i : Envelope coefficients */ + const Word32 manE_peak, /* i : Peak energy mantissa */ + const Word16 expE_peak, /* i : Peak energy exponent */ + Word16 *Rk, /* o : bit allocation for concatenated vector */ + Word16 *R, /* i/o: Global bit allocation */ + Word16 *sel_bands, /* o : Selected bands for encoding */ + Word16 *n_sel_bands /* o : No. of selected bands for encoding */ +); + +// hq_conf_fec_fx.c +void hq_configure_bfi_fx( + Word16 *nb_sfm, /* o : Number of sub bands Q0 */ + Word16 *num_Sb, /* o : Number of FEC sub bands ? Q0 */ + Word16 *num_bands_p, /* o : FEC sub bands Q0 */ + const Word16 **sfmsize, /* o : Subband bandwidths */ + const Word16 **sfm_start, /* o : Subband start coefficients */ + const Word16 **sfm_end /* o : Subband end coefficients */ +); + +// core_switching_dec_fx.c +void bandwidth_switching_detect_fx( + Decoder_State *st_fx /* i/o: encoder state structure */ +); + +void bandwidth_switching_detect_ivas_fx( + Decoder_State *st_fx /* i/o: encoder state structure */ +); + +void bw_switching_pre_proc_fx( + const Word16 *old_syn_12k8_16k_fx, /* i : ACELP core synthesis at 12.8kHz or 16kHz */ + Decoder_State *st_fx /* i/o: decoder state structure */ +); + +ivas_error core_switching_pre_dec_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 output_frame /* i : frame length */ +); + +ivas_error core_switching_post_dec_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *synth, /* i/o: output synthesis Qsynth */ #ifdef IVAS_CODE_SWITCHING - float* output, /* i/o: LB synth/upsampled LB synth */ - float output_mem[], /* i : OLA memory from last TCX/HQ frame */ - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ + float *output, /* i/o: LB synth/upsampled LB synth */ + float output_mem[], /* i : OLA memory from last TCX/HQ frame */ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ #endif - const Word16 output_frame, /* i : frame length */ - const Word16 core_switching_flag, /* i : ACELP->HQ switching flag */ + const Word16 output_frame, /* i : frame length */ + const Word16 core_switching_flag, /* i : ACELP->HQ switching flag */ #ifdef IVAS_CODE_SWITCHING - const Word16 sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC */ - const Word16 nchan_out, /* i : number of output channels */ + const Word16 sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC */ + const Word16 nchan_out, /* i : number of output channels */ #endif - const Word16 last_element_mode, /* i : element mode of previous frame */ - Word16* Qsynth /* i/o: Scaling of ACELP exit (Q_syn2-1) or HQ exit (Qsynth); changes after this function */ - ); - - ivas_error core_switching_post_dec_ivas_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *synth, /* i/o: output synthesis Qsynth */ - Word32 *output_fx, /* i/o: LB synth/upsampled LB synth */ - Word16 output_mem_fx[], /* i : OLA memory from last TCX/HQ frame */ - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ - const Word16 output_frame, /* i : frame length */ - const Word16 core_switching_flag, /* i : ACELP->HQ switching flag */ - const Word16 sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC */ - const Word16 nchan_out, /* i : number of output channels */ - const Word16 last_element_mode, /* i : element mode of previous frame */ - Word16 *Qsynth /* i/o: Scaling of ACELP exit (Q_syn2-1) or HQ exit (Qsynth); changes after this function */ - ); - - void core_switching_hq_prepare_dec_fx( - Decoder_State *st_fx, /* i/o: encoder state structure */ - Word16 *num_bits, /* i/o: bit budget update */ - const Word16 output_frame /* i : output frame length */ - ); - - //amr_wb_dec_fx.c - ivas_error amr_wb_dec_fx( - Word16 output_sp[], /* o : synthesis output */ - Decoder_State *st_fx /* o : Decoder static variables structure */ - ); - - void amr_wb_dec_init_fx( - AMRWB_IO_DEC_HANDLE hAmrwb_IO /* i/o: AMR-WB IO data handle */ - ); - - //updt_dec_fx.c - void updt_dec_fx( - Decoder_State *st_fx, /* i/o: state structure */ - const Word16 *old_exc_fx, /* i : buffer of excitation */ - const Word16 *pitch_buf_fx, /* i : floating pitch values for each subframe */ - const Word16 Es_pred, /* i : predicited scaled innovation energy */ - const Word16 *Aq, /* i : A(z) quantized for all subframes */ - const Word16 *lsf_new_fx, /* i : current frame LSF vector */ - const Word16 *lsp_new_fx, /* i : current frame LSP vector */ - const Word16 voice_factors[], /* i : voicing factors */ - const Word16 *old_bwe_exc_fx /* i : buffer of excitation */ - , const Word16 *gain_buf /*Q14*/ - ); - - void updt_IO_switch_dec_fx( - const Word16 output_frame, /* i : output frame length */ - Decoder_State *st_fx /* o : Decoder static variables structure */ - ); - - void updt_bw_switching_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 *synth, /* i : float synthesis signal */ - const Word16 Qpost - ); - - void updt_dec_common_fx( - Decoder_State* st_fx, /* i/o: decoder state structure */ - Word16 hq_core_type_fx, /* i : HQ core type */ - const Word16 concealWholeFrameTmp, /* i : concealWholeFrameTmp flag */ - const Word16* synth, /* i : decoded synthesis */ - const Word16 Qpostd /* i : Synthesis Q value */ - ); - - void update_decoder_LPD_cng( - Decoder_State *st, - Word16 coder_type, - Word16 *timeDomainBuffer, - Word16 *A, - Word16 *bpf_noise_buf - ); - - //FEC_clas_estim_fx - void FEC_clas_estim_fx( - Decoder_State *st_fx, /* i/o: decoder state handle */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ /*A*/ - const Word16 L_frame, /* i : length of the frame */ - Word16 *clas, /* i/o: frame classification */ - const Word16 coder_type, /* i : coder type */ - const Word16 *pitch, /* i : pitch values for each subframe (Q6) */ - Word16 *syn, /* i : synthesis buffer */ - Word16 *lp_speech, /* i/o: long term active speech energy average Q8 */ - Word16 *decision_hyst, /* i/o: hysteresis of the music/speech decision */ /*A*/ - Word16 *UV_cnt, /* i/o: number of consecutives frames classified as UV */ /*A*/ - Word16 *LT_UV_cnt, /* i/o: long term consecutives frames classified as UV */ /*A*/ - Word16 *Last_ener, /* i/o: last_energy frame */ /*A*/ - Word16 *locattack, /* i/o: detection of attack (mainly to localized speech burst) */ /*A*/ - Word16 *lt_diff_etot, /* i/o: long-term total energy variation */ /*A*/ - Word16 *amr_io_class, /* i/o: classification for AMR-WB IO mode */ /*A*/ - const Word32 bitrate, /* i : Decoded bitrate */ /*A*/ - Word16 Q_syn, /* i : Synthesis scaling */ - Word16 *class_para, /* o : classification para. fmerit1 */ /*A*/ - Word16 *mem_syn_clas_estim, /* i/o: memory of the synthesis signal for frame class estimation */ - Word16 *Q_mem_syn, /*i/o : exponent for memory of synthesis signal for frame class estimation */ /*B*/ - Word16 LTP_Gain, /* i : LTP gain is 0..0.6 or negative Q15*/ /*B*/ - Word16 mode, /* i : signal classifier mode *//*B*/ - Word16 bfi, /* i : bad frame indicator *//*B*/ - Word32 last_core_brate, /* i : bitrate of previous frame */ - const Word16 FEC_mode /* i : ACELP FEC mode */ - ); - - Word16 FEC_pos_dec_fx( - Decoder_State* st_fx, /* i/o: decoder state structure */ - Word16* last_pulse_pos, /* o : last glotal pulse position in the lost ACB */ - Word32* enr_q, /* o : decoded energy in Q0 */ - const Word16 nBits_es_Pred /* i : number of bits for Es_pred Q */ - ); - - // post_dec.h - void post_decoder( - Decoder_State *st, - Word16 synth_buf[], - Word16 pit_gain[], - Word16 pitch[], - Word16 signal_out[], - Word16 * bpf_noise_buf - ); - - void post_decoder_ivas_fx( - Decoder_State *st, - Word16 synth_buf[], - Word16 pit_gain[], - Word16 pitch[], - Word16 signal_out[], - Word16 *bpf_noise_buf - ); - - void cldfb_synth_set_bandsToZero( - Decoder_State *st, - Word32 **rAnalysis, - Word32 **iAnalysis, - const Word16 nTimeSlots, - const CLDFB_SCALE_FACTOR scaleFactor - ); - - //FEC_pitch_estim_fx.c - void FEC_pitch_estim_fx( - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 last_core, /* i : last core */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 clas, /* i : current frame classification */ - const Word16 last_good, /* i : last good clas information */ - const Word16 pitch_buf[], /* i : Floating pitch for each subframe */ - const Word32 old_pitch_buf[], /* i : buffer of old subframe pitch values 15Q16 */ - Word16 *bfi_pitch, /* i/o: update of the estimated pitch for FEC */ - Word16 *bfi_pitch_frame, /* o : frame length when pitch was updated */ - Word16 *upd_cnt /* i/o: update counter */ - , const Word16 coder_type, /* i : coder_type */ - Word16 element_mode /* i : element mode */ - ); - - //FEC_scale_sync_fx.c - void FEC_scale_syn_fx( - const Word16 L_frame, /* i : length of the frame */ - Word16* update_flg, /* o: flag indicating re-synthesis after scaling*/ - Word16 clas, /* i/o: frame classification */ - const Word16 last_good, /* i: last good frame classification */ - Word16* synth, /* i/o: synthesized speech at Fs = 12k8 Hz */ - const Word16* pitch, /* i: pitch values for each subframe */ - Word32 L_enr_old, /* i: energy at the end of previous frame */ - Word32 L_enr_q, /* i: transmitted energy for current frame */ - const Word16 coder_type, /* i: coder type */ - const Word16 LSF_Q_prediction, /* i : LSF prediction mode */ - Word16* scaling_flag, /* i/o: flag to indicate energy control of syn */ - Word32* lp_ener_FEC_av, /* i/o: averaged voiced signal energy */ - Word32* lp_ener_FEC_max, /* i/o: averaged voiced signal energy */ - const Word16 bfi, /* i: current frame BFI */ - const Word32 total_brate, /* i: total bitrate */ - const Word16 prev_bfi, /* i: previous frame BFI */ - const Word32 last_core_brate, /* i: previous frame core bitrate */ - Word16* exc, /* i/o: excitation signal without enhancement */ - Word16* exc2, /* i/o: excitation signal with enhancement */ - Word16 Aq[], /* i/o: LP filter coefs (can be modified if BR) */ - Word16* old_enr_LP, /* i/o: LP filter E of last good voiced frame */ - const Word16* mem_tmp, /* i: temp. initial synthesis filter states */ - Word16* mem_syn, /* o: initial synthesis filter states */ - Word16 Q_exc, - Word16 Q_syn, - const Word16 avoid_lpc_burst_on_recovery, /* i : if true the excitation energy is limited if LP has big gain */ - const Word16 force_scaling /* i: force scaling */ - ); - - //LD_music_post_filter_fx.c - void LD_music_post_filter_fx - ( - MUSIC_POSTFILT_HANDLE hMusicPF, /* i/o: LD music postfilter handle */ - const Word16 dtc_in[], /* i : i synthesis Qdct */ - Word16 dtc_out[], /* o : output synthesis Qdct */ - const Word32 core_brate, /* i : core bitrate Q0 */ - Word16* Old_ener_Q, /* i/o : Old energy scaling factor */ - const Word16 coder_type, /* i : Coder type : -1 in case of IO Q0 */ - const Word16 Last_coder_type, /* i : i scaling Q0 */ - const Word16 Qdct /* i : i scaling Q0 */ - ); - - void Prep_music_postP_fx( - Word16 exc_buffer_in[], /* i/o: excitation buffer Q_exc*/ - Word16 dct_buffer_out[], /* o : DCT output buffer (qdct)*/ - Word16 filt_lfE[], /* i/o: long term spectrum energy Q15 */ - const Word16 last_core, /* i : last core */ - const Word16 element_mode, /* i : element mode */ - const Word16 *pitch_buf, /* i : current frame pitch information Q6*/ - Word16 *LDm_enh_lp_gbin, /* o : smoothed suppression gain, per bin FFT Q15*/ - const Word16 Q_exc, /* i : excitation scaling */ - Word16 *qdct /* o : Scaling factor of dct coefficient */ - ); - - void Post_music_postP_fx( - Word16 dct_buffer_in[], /* i/o: excitation buffer */ - Word16 *exc2, /* i/o: Current excitation to be overwriten */ - const Word16 *mem_tmp, /* i : previous frame synthesis memory */ - Word16 *st_mem_syn2, /* i/o: current frame synthesis memory */ - const Word16 *Aq, /* i : LPC filter coefficients */ - Word16 *syn, /* i/o: 12k8 synthesis */ - Word16 *Q_exc, /* i : excitation scaling */ - Word16 *prev_Q_syn, /* i : previsous frame synthesis scaling */ - Word16 *Q_syn, /* i : Current frame synthesis scaling */ - Word16 *mem_syn_clas_estim_fx, /* i : old 12k8 synthesis used for frame classification*/ - const Word16 IsIO, /* i: Flag to indicate IO mode */ - Word16 *mem_deemph, /* i/o: speech deemph filter memory */ - Word16 *st_pst_old_syn_fx, /* i/o: psfiler */ - Word16 *st_pst_mem_deemp_err_fx, /* i/o: psfiler */ - Word16 *mem_agc, - PFSTAT *pf_stat, /* i/o: All memories related to NB post filter */ - const Word16 *tmp_buffer /* tmp_buffer in Q-1 */ - , Word16 *mem_tmp2 /* Temporary memory used with scale_syn */ - ); - - void music_postfilt_init( - MUSIC_POSTFILT_HANDLE hMusicPF /* i/o: LD music postfilter handle */ - ); - - //gs_dec_amr_wb.c - void improv_amr_wb_gs_fx( - const Word16 clas, /* i : signal frame class */ - const Word16 coder_type, /* i : coder type */ - const Word32 core_brate, /* i : bitrate allocated to the core */ - Word16 *seed_tcx, /* i/o: Seed used for noise generation */ - Word16 *old_Aq_fx, /* i/o: old LPC filter coefficient */ - Word16 *mem_syn2_fx, /* i/o: synthesis memory */ - const Word16 lt_voice_fac_fx, /* i/o: long term voice factor Q15 */ - const Word16 locattack, /* i : Flag for a detected attack */ - Word16 *Aq_fx, /* i/o: Decoded LP filter coefficient */ - Word16 *exc2_fx, /* i/o: Decoded complete excitation */ - const Word16 Q_exc2, /* i : Exponent of Exc2 */ - Word16 *mem_tmp_fx, /* i/o: synthesis temporary memory */ - Word16 *syn_fx, /* o: Decoded synthesis to be updated */ - const Word16 Q_syn, /* i : Synthesis scaling Q0 */ - const Word16 *pitch_buf_fx, /* i : Decoded pitch buffer */ - const Word16 Last_ener_fx, /* i : Last energy (Q8) */ - const Word16 rate_switching_reset, /* i : rate switching reset flag */ - const Word16 last_coder_type /* i : Last coder_type */ + const Word16 last_element_mode, /* i : element mode of previous frame */ + Word16 *Qsynth /* i/o: Scaling of ACELP exit (Q_syn2-1) or HQ exit (Qsynth); changes after this function */ +); + +ivas_error core_switching_post_dec_ivas_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *synth, /* i/o: output synthesis Qsynth */ + Word32 *output_fx, /* i/o: LB synth/upsampled LB synth */ + Word16 output_mem_fx[], /* i : OLA memory from last TCX/HQ frame */ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ + const Word16 output_frame, /* i : frame length */ + const Word16 core_switching_flag, /* i : ACELP->HQ switching flag */ + const Word16 sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC */ + const Word16 nchan_out, /* i : number of output channels */ + const Word16 last_element_mode, /* i : element mode of previous frame */ + Word16 *Qsynth /* i/o: Scaling of ACELP exit (Q_syn2-1) or HQ exit (Qsynth); changes after this function */ +); + +void core_switching_hq_prepare_dec_fx( + Decoder_State *st_fx, /* i/o: encoder state structure */ + Word16 *num_bits, /* i/o: bit budget update */ + const Word16 output_frame /* i : output frame length */ +); + +// amr_wb_dec_fx.c +ivas_error amr_wb_dec_fx( + Word16 output_sp[], /* o : synthesis output */ + Decoder_State *st_fx /* o : Decoder static variables structure */ +); + +void amr_wb_dec_init_fx( + AMRWB_IO_DEC_HANDLE hAmrwb_IO /* i/o: AMR-WB IO data handle */ +); + +// updt_dec_fx.c +void updt_dec_fx( + Decoder_State *st_fx, /* i/o: state structure */ + const Word16 *old_exc_fx, /* i : buffer of excitation */ + const Word16 *pitch_buf_fx, /* i : floating pitch values for each subframe */ + const Word16 Es_pred, /* i : predicited scaled innovation energy */ + const Word16 *Aq, /* i : A(z) quantized for all subframes */ + const Word16 *lsf_new_fx, /* i : current frame LSF vector */ + const Word16 *lsp_new_fx, /* i : current frame LSP vector */ + const Word16 voice_factors[], /* i : voicing factors */ + const Word16 *old_bwe_exc_fx /* i : buffer of excitation */ + , + const Word16 *gain_buf /*Q14*/ +); + +void updt_IO_switch_dec_fx( + const Word16 output_frame, /* i : output frame length */ + Decoder_State *st_fx /* o : Decoder static variables structure */ +); + +void updt_bw_switching_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 *synth, /* i : float synthesis signal */ + const Word16 Qpost ); + +void updt_dec_common_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 hq_core_type_fx, /* i : HQ core type */ + const Word16 concealWholeFrameTmp, /* i : concealWholeFrameTmp flag */ + const Word16 *synth, /* i : decoded synthesis */ + const Word16 Qpostd /* i : Synthesis Q value */ +); + +void update_decoder_LPD_cng( + Decoder_State *st, + Word16 coder_type, + Word16 *timeDomainBuffer, + Word16 *A, + Word16 *bpf_noise_buf ); + +// FEC_clas_estim_fx +void FEC_clas_estim_fx( + Decoder_State *st_fx, /* i/o: decoder state handle */ + const Word16 Opt_AMR_WB, + /* i : flag indicating AMR-WB IO mode */ /*A*/ + const Word16 L_frame, /* i : length of the frame */ + Word16 *clas, /* i/o: frame classification */ + const Word16 coder_type, /* i : coder type */ + const Word16 *pitch, /* i : pitch values for each subframe (Q6) */ + Word16 *syn, /* i : synthesis buffer */ + Word16 *lp_speech, /* i/o: long term active speech energy average Q8 */ + Word16 *decision_hyst, + /* i/o: hysteresis of the music/speech decision */ /*A*/ + Word16 *UV_cnt, + /* i/o: number of consecutives frames classified as UV */ /*A*/ + Word16 *LT_UV_cnt, + /* i/o: long term consecutives frames classified as UV */ /*A*/ + Word16 *Last_ener, + /* i/o: last_energy frame */ /*A*/ + Word16 *locattack, + /* i/o: detection of attack (mainly to localized speech burst) */ /*A*/ + Word16 *lt_diff_etot, + /* i/o: long-term total energy variation */ /*A*/ + Word16 *amr_io_class, + /* i/o: classification for AMR-WB IO mode */ /*A*/ + const Word32 bitrate, + /* i : Decoded bitrate */ /*A*/ + Word16 Q_syn, /* i : Synthesis scaling */ + Word16 *class_para, + /* o : classification para. fmerit1 */ /*A*/ + Word16 *mem_syn_clas_estim, /* i/o: memory of the synthesis signal for frame class estimation */ + Word16 *Q_mem_syn, + /*i/o : exponent for memory of synthesis signal for frame class estimation */ /*B*/ + Word16 LTP_Gain, + /* i : LTP gain is 0..0.6 or negative Q15*/ /*B*/ + Word16 mode, + /* i : signal classifier mode */ /*B*/ + Word16 bfi, + /* i : bad frame indicator */ /*B*/ + Word32 last_core_brate, /* i : bitrate of previous frame */ + const Word16 FEC_mode /* i : ACELP FEC mode */ +); + +Word16 FEC_pos_dec_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *last_pulse_pos, /* o : last glotal pulse position in the lost ACB */ + Word32 *enr_q, /* o : decoded energy in Q0 */ + const Word16 nBits_es_Pred /* i : number of bits for Es_pred Q */ +); + +// post_dec.h +void post_decoder( + Decoder_State *st, + Word16 synth_buf[], + Word16 pit_gain[], + Word16 pitch[], + Word16 signal_out[], + Word16 *bpf_noise_buf ); + +void post_decoder_ivas_fx( + Decoder_State *st, + Word16 synth_buf[], + Word16 pit_gain[], + Word16 pitch[], + Word16 signal_out[], + Word16 *bpf_noise_buf ); + +void cldfb_synth_set_bandsToZero( + Decoder_State *st, + Word32 **rAnalysis, + Word32 **iAnalysis, + const Word16 nTimeSlots, + const CLDFB_SCALE_FACTOR scaleFactor ); + +// FEC_pitch_estim_fx.c +void FEC_pitch_estim_fx( + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const Word16 last_core, /* i : last core */ + const Word16 L_frame, /* i : length of the frame */ + const Word16 clas, /* i : current frame classification */ + const Word16 last_good, /* i : last good clas information */ + const Word16 pitch_buf[], /* i : Floating pitch for each subframe */ + const Word32 old_pitch_buf[], /* i : buffer of old subframe pitch values 15Q16 */ + Word16 *bfi_pitch, /* i/o: update of the estimated pitch for FEC */ + Word16 *bfi_pitch_frame, /* o : frame length when pitch was updated */ + Word16 *upd_cnt /* i/o: update counter */ + , + const Word16 coder_type, /* i : coder_type */ + Word16 element_mode /* i : element mode */ +); + +// FEC_scale_sync_fx.c +void FEC_scale_syn_fx( + const Word16 L_frame, /* i : length of the frame */ + Word16 *update_flg, /* o: flag indicating re-synthesis after scaling*/ + Word16 clas, /* i/o: frame classification */ + const Word16 last_good, /* i: last good frame classification */ + Word16 *synth, /* i/o: synthesized speech at Fs = 12k8 Hz */ + const Word16 *pitch, /* i: pitch values for each subframe */ + Word32 L_enr_old, /* i: energy at the end of previous frame */ + Word32 L_enr_q, /* i: transmitted energy for current frame */ + const Word16 coder_type, /* i: coder type */ + const Word16 LSF_Q_prediction, /* i : LSF prediction mode */ + Word16 *scaling_flag, /* i/o: flag to indicate energy control of syn */ + Word32 *lp_ener_FEC_av, /* i/o: averaged voiced signal energy */ + Word32 *lp_ener_FEC_max, /* i/o: averaged voiced signal energy */ + const Word16 bfi, /* i: current frame BFI */ + const Word32 total_brate, /* i: total bitrate */ + const Word16 prev_bfi, /* i: previous frame BFI */ + const Word32 last_core_brate, /* i: previous frame core bitrate */ + Word16 *exc, /* i/o: excitation signal without enhancement */ + Word16 *exc2, /* i/o: excitation signal with enhancement */ + Word16 Aq[], /* i/o: LP filter coefs (can be modified if BR) */ + Word16 *old_enr_LP, /* i/o: LP filter E of last good voiced frame */ + const Word16 *mem_tmp, /* i: temp. initial synthesis filter states */ + Word16 *mem_syn, /* o: initial synthesis filter states */ + Word16 Q_exc, + Word16 Q_syn, + const Word16 avoid_lpc_burst_on_recovery, /* i : if true the excitation energy is limited if LP has big gain */ + const Word16 force_scaling /* i: force scaling */ +); + +// LD_music_post_filter_fx.c +void LD_music_post_filter_fx( + MUSIC_POSTFILT_HANDLE hMusicPF, /* i/o: LD music postfilter handle */ + const Word16 dtc_in[], /* i : i synthesis Qdct */ + Word16 dtc_out[], /* o : output synthesis Qdct */ + const Word32 core_brate, /* i : core bitrate Q0 */ + Word16 *Old_ener_Q, /* i/o : Old energy scaling factor */ + const Word16 coder_type, /* i : Coder type : -1 in case of IO Q0 */ + const Word16 Last_coder_type, /* i : i scaling Q0 */ + const Word16 Qdct /* i : i scaling Q0 */ +); + +void Prep_music_postP_fx( + Word16 exc_buffer_in[], /* i/o: excitation buffer Q_exc*/ + Word16 dct_buffer_out[], /* o : DCT output buffer (qdct)*/ + Word16 filt_lfE[], /* i/o: long term spectrum energy Q15 */ + const Word16 last_core, /* i : last core */ + const Word16 element_mode, /* i : element mode */ + const Word16 *pitch_buf, /* i : current frame pitch information Q6*/ + Word16 *LDm_enh_lp_gbin, /* o : smoothed suppression gain, per bin FFT Q15*/ + const Word16 Q_exc, /* i : excitation scaling */ + Word16 *qdct /* o : Scaling factor of dct coefficient */ +); + +void Post_music_postP_fx( + Word16 dct_buffer_in[], /* i/o: excitation buffer */ + Word16 *exc2, /* i/o: Current excitation to be overwriten */ + const Word16 *mem_tmp, /* i : previous frame synthesis memory */ + Word16 *st_mem_syn2, /* i/o: current frame synthesis memory */ + const Word16 *Aq, /* i : LPC filter coefficients */ + Word16 *syn, /* i/o: 12k8 synthesis */ + Word16 *Q_exc, /* i : excitation scaling */ + Word16 *prev_Q_syn, /* i : previsous frame synthesis scaling */ + Word16 *Q_syn, /* i : Current frame synthesis scaling */ + Word16 *mem_syn_clas_estim_fx, /* i : old 12k8 synthesis used for frame classification*/ + const Word16 IsIO, /* i: Flag to indicate IO mode */ + Word16 *mem_deemph, /* i/o: speech deemph filter memory */ + Word16 *st_pst_old_syn_fx, /* i/o: psfiler */ + Word16 *st_pst_mem_deemp_err_fx, /* i/o: psfiler */ + Word16 *mem_agc, + PFSTAT *pf_stat, /* i/o: All memories related to NB post filter */ + const Word16 *tmp_buffer /* tmp_buffer in Q-1 */ + , + Word16 *mem_tmp2 /* Temporary memory used with scale_syn */ +); + +void music_postfilt_init( + MUSIC_POSTFILT_HANDLE hMusicPF /* i/o: LD music postfilter handle */ +); + +// gs_dec_amr_wb.c +void improv_amr_wb_gs_fx( + const Word16 clas, /* i : signal frame class */ + const Word16 coder_type, /* i : coder type */ + const Word32 core_brate, /* i : bitrate allocated to the core */ + Word16 *seed_tcx, /* i/o: Seed used for noise generation */ + Word16 *old_Aq_fx, /* i/o: old LPC filter coefficient */ + Word16 *mem_syn2_fx, /* i/o: synthesis memory */ + const Word16 lt_voice_fac_fx, /* i/o: long term voice factor Q15 */ + const Word16 locattack, /* i : Flag for a detected attack */ + Word16 *Aq_fx, /* i/o: Decoded LP filter coefficient */ + Word16 *exc2_fx, /* i/o: Decoded complete excitation */ + const Word16 Q_exc2, /* i : Exponent of Exc2 */ + Word16 *mem_tmp_fx, /* i/o: synthesis temporary memory */ + Word16 *syn_fx, /* o: Decoded synthesis to be updated */ + const Word16 Q_syn, /* i : Synthesis scaling Q0 */ + const Word16 *pitch_buf_fx, /* i : Decoded pitch buffer */ + const Word16 Last_ener_fx, /* i : Last energy (Q8) */ + const Word16 rate_switching_reset, /* i : rate switching reset flag */ + const Word16 last_coder_type /* i : Last coder_type */ #ifdef ADD_IVAS_GS_DEC_IMPR - , const Word16 VeryLowRateSTflag /* i : Enable the noise enhancement for very low rate stereo generic mode */ + , + const Word16 VeryLowRateSTflag /* i : Enable the noise enhancement for very low rate stereo generic mode */ #endif - ); +); #ifdef IVAS_FLOAT_FIXED - //dec_amr_wb_fx.c - void decod_amr_wb_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - const Word16 *Aq_fx, /* i : LP filter coefficients */ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ - Word16 *exc_fx, /* i/o: adapt. excitation exc */ - Word16 *exc2_fx, /* i/o: adapt. excitation/total exc */ - Word16 hf_gain_fx[NB_SUBFR], /* o : decoded HF gain */ - Word16 *voice_factors_fx, /* o : voicing factors */ - Word16 *gain_buf /* o : floating pitch gain for each subframe Q14 */ - ); +// dec_amr_wb_fx.c +void decod_amr_wb_fx( + Decoder_State *st_fx, /* i/o: decoder static memory */ + const Word16 *Aq_fx, /* i : LP filter coefficients */ + Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ + Word16 *exc_fx, /* i/o: adapt. excitation exc */ + Word16 *exc2_fx, /* i/o: adapt. excitation/total exc */ + Word16 hf_gain_fx[NB_SUBFR], /* o : decoded HF gain */ + Word16 *voice_factors_fx, /* o : voicing factors */ + Word16 *gain_buf /* o : floating pitch gain for each subframe Q14 */ +); #endif - //rst_dec_fx.c - void CNG_reset_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *pitch_buf, /* o : floating pitch for each subframe */ - Word16 *voice_factors /* o : voicing factors */ - ); - - //voiced_dec_fx.c - ivas_error ppp_voiced_decoder_fx( - Decoder_State *st_fx, /* i/o: state structure */ - Word16 *out_fx, /* o : residual signal */ - const Word16 *lpc2_fx, /* i : current frame LPC */ - Word16 *exc_fx, /* i : previous frame excitation */ - Word16 *pitch, /* o : floating pitch values for each subframe */ - Word16 bfi /* i : Frame error rate */ - ); - void sc_vbr_dec_init( - SC_VBR_DEC_HANDLE hSC_VBR /* i/o: SC-VBR decoder handle */ - ); - -//ppp_dec_fx.c - ivas_error ppp_quarter_decoder_fx( - DTFS_STRUCTURE *CURRCW_Q_DTFS_FX, /* i/o: Current CW DTFS */ - Word16 prevCW_lag_fx, /* i : Previous lag */ - Word16 *lastLgainD_fx, /* i/o: Last gain lowband Q11 */ - Word16 *lastHgainD_fx, /* i/o: Last gain highwband Q11 */ - Word16 *lasterbD_fx, /* i/o: Last ERB vector Q13 */ - Word16 bfi, /* i : FER flag */ - Word16 *S_fx, /* i : sine table, Q15 */ - Word16 *C_fx, /* i : cosine table, Q15 */ - DTFS_STRUCTURE PREV_CW_D_FX, /* i : Previous DTFS */ - Decoder_State *st_fx - ); - - //core_dec_init_fx.c - void open_decoder_LPD_fx( - Decoder_State* st, - const Word32 total_brate, +// rst_dec_fx.c +void CNG_reset_dec_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *pitch_buf, /* o : floating pitch for each subframe */ + Word16 *voice_factors /* o : voicing factors */ +); + +// voiced_dec_fx.c +ivas_error ppp_voiced_decoder_fx( + Decoder_State *st_fx, /* i/o: state structure */ + Word16 *out_fx, /* o : residual signal */ + const Word16 *lpc2_fx, /* i : current frame LPC */ + Word16 *exc_fx, /* i : previous frame excitation */ + Word16 *pitch, /* o : floating pitch values for each subframe */ + Word16 bfi /* i : Frame error rate */ +); +void sc_vbr_dec_init( + SC_VBR_DEC_HANDLE hSC_VBR /* i/o: SC-VBR decoder handle */ +); + +// ppp_dec_fx.c +ivas_error ppp_quarter_decoder_fx( + DTFS_STRUCTURE *CURRCW_Q_DTFS_FX, /* i/o: Current CW DTFS */ + Word16 prevCW_lag_fx, /* i : Previous lag */ + Word16 *lastLgainD_fx, /* i/o: Last gain lowband Q11 */ + Word16 *lastHgainD_fx, /* i/o: Last gain highwband Q11 */ + Word16 *lasterbD_fx, /* i/o: Last ERB vector Q13 */ + Word16 bfi, /* i : FER flag */ + Word16 *S_fx, /* i : sine table, Q15 */ + Word16 *C_fx, /* i : cosine table, Q15 */ + DTFS_STRUCTURE PREV_CW_D_FX, /* i : Previous DTFS */ + Decoder_State *st_fx ); + +// core_dec_init_fx.c +void open_decoder_LPD_fx( + Decoder_State *st, + const Word32 total_brate, #ifdef NEW_IVAS_OPEN_DEC - const Word32 last_total_brate, + const Word32 last_total_brate, #endif - const Word16 bwidth + const Word16 bwidth #ifdef NEW_IVAS_OPEN_DEC - , const Word16 is_mct, /* i : MCT mode flag */ + , + const Word16 is_mct, /* i : MCT mode flag */ #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - const Word16 last_element_mode, + const Word16 last_element_mode, #endif - const Word16 is_init /* i : indicate call from init_decoder() to avoid double TC initialization */ + const Word16 is_init /* i : indicate call from init_decoder() to avoid double TC initialization */ #endif - ); +); #ifdef IVAS_FLOAT_FIXED - void open_decoder_LPD_ivas_fx( - Decoder_State *st, /* i/o: decoder state structure */ - const Word32 total_brate, /* i : total bitrate */ - const Word32 last_total_brate, /* i : last total bitrate */ - const Word16 bwidth, /* i : audio bandwidth */ - const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ - const Word16 last_element_mode, /* i : last element mode */ - const Word16 is_init, /* i : indicate call from init_decoder() to avoid double TC initialization */ - Word16* Q_syn_Overl_TDAC, - Word16* Q_fer_samples, - Word16* Q_syn_Overl, - Word16* Q_syn_Overl_TDACFB, - Word16* Q_syn_OverlFB, - Word16* Q_old_out, - Word16* Q_old_outLB, - Word16* Q_old_Aq_12_8); +void open_decoder_LPD_ivas_fx( + Decoder_State *st, /* i/o: decoder state structure */ + const Word32 total_brate, /* i : total bitrate */ + const Word32 last_total_brate, /* i : last total bitrate */ + const Word16 bwidth, /* i : audio bandwidth */ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ + const Word16 last_element_mode, /* i : last element mode */ + const Word16 is_init, /* i : indicate call from init_decoder() to avoid double TC initialization */ + Word16 *Q_syn_Overl_TDAC, + Word16 *Q_fer_samples, + Word16 *Q_syn_Overl, + Word16 *Q_syn_Overl_TDACFB, + Word16 *Q_syn_OverlFB, + Word16 *Q_old_out, + Word16 *Q_old_outLB, + Word16 *Q_old_Aq_12_8 ); #endif // IVAS_FLOAT_FIXED - void reset_tcx_overl_buf_fx( - TCX_DEC_HANDLE hTcxDec /* i/o: TCX decoder handle */ - ); - void acelp_plc_mdct_transition_fx( - Decoder_State *st /* i/o: Decoder state */ - ); - void cldfb_reset_memory_fx( - HANDLE_CLDFB_FILTER_BANK hs /* i/o: filter bank handle */); - void tcxltp_dec_init_fx( - TCX_LTP_DEC_HANDLE hTcxLtpDec, - const Word16 ini_frame, - const Word16 last_codec_mode, - const Word16 element_mode, - const Word16 pit_max, - const Word32 sr_core ); - //swb_bwe_dec_hr_fx.c - - Word16 swb_bwe_dec_hr_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 *syn_12k8_16k_fx, /* i : ACELP core synthesis @16kHz */ - const Word16 old_syn_exp, /* i : Exponent of core synthesis */ - Word16 *hb_synth_fx, /* o : SHB synthesis */ - const Word16 output_frame, /* i : frame length */ - const Word16 unbits, /* i : number of core unused bits */ - const Word16 pitch_buf[] /* i : pitch buffer */ - ); - - void hr_bwe_dec_init( - HR_BWE_DEC_HANDLE hBWE_FD_HR /* i/o: HR BWE data handle */ - ); - - //swb_bwe_com_hr_fx.c - void swb_hr_noise_fill_fx( - const Word16 is_transient, /* i : transient flag */ - const Word16 spect_start, /* i : spectrum start point */ - const Word16 spect_end, /* i : spectrum end point */ - const Word16 tilt_wb, /* i : tilt of wideband signal */ - const Word16 pitch, /* i : pitch value */ - const Word16 nq[], /* i : AVQ nq index */ - Word16 Nsv, /* i : number of subband */ - Word16 *bwe_highrate_seed, /* i/o: seed of random noise */ - Word16 *t_audio, /* i/o: mdct spectrum */ - Word16 Q_audio - ); - - //stat_noise_uv_dec_fx.c - void stat_noise_uv_dec_fx( - Decoder_State *st_fx, /* i/o: Decoder static memory */ - Word16 *lsp_new, /* i : end-frame LSP vector */ - Word16 *lsp_mid, /* i : mid-frame LSP vector */ - Word16 *Aq, /* o : A(z) quantized for the 4 subframes */ - Word16 *exc2 /* i/o: excitation buffer */ - , const Word16 uc_two_stage_flag /* i : flag indicating two-stage UC */ - ); - - //stat_noise_uv_mod_fx.c - void stat_noise_uv_mod_fx( - const Word16 coder_type, /* i : Coder type */ - Word16 noisiness, /* i : noisiness parameter */ - const Word16 *lsp_old, /* i : old LSP vector at 4th sfr */ - const Word16 *lsp_new, /* i : LSP vector at 4th sfr */ - const Word16 *lsp_mid, /* i : LSP vector at 2nd sfr */ - Word16 *Aq, /* o : A(z) quantized for the 4 subframes */ - Word16 *exc2, /* i/o: excitation buffer */ - Word16 Q_exc, /* i : Q of exc2 excitation buffer [11..-1] expected */ - const Word16 bfi, /* i : Bad frame indicator */ - Word32 *ge_sm, /* i/o: smoothed excitation gain */ - Word16 *uv_count, /* i/o: unvoiced counter */ - Word16 *act_count, /* i/o: activation counter */ - Word16 lspold_s[], /* i/o: old LSP */ - Word16 *noimix_seed, /* i/o: mixture seed */ - Word16 *st_min_alpha, /* i/o: minimum alpha */ - Word16 *exc_pe, /* i/o: scale Q_stat_noise */ - const Word32 bitrate, /* i : core bitrate */ - const Word16 bwidth_fx, /* i : i bandwidth */ - Word16 *Q_stat_noise, /* i/o: noise scaling */ - Word16 *Q_stat_noise_ge /* i/o: noise scaling */ - ); - - //FEC_adao_codebook_fx.c - Word16 FEC_SinOnset_fx( - Word16 *exc, /* i/o : exc vector to modify */ - Word16 puls_pos, /* i : last pulse position desired */ - const Word16 T0, /* i : Pitch information of the 1 subfr */ - Word32 enr_q, /* i : energy provide by the encoder */ - Word16 *Aq, /* i : A(z) filter Q12 */ - const Word16 L_frame /* i : frame length */ - , const Word16 Qold - ); - - Word16 FEC_enhACB_fx( - const Word16 L_frame, /* i : frame length */ - const Word16 last_L_frame, /* i : frame length of previous frame */ - Word16 *exc_io, /* i/o : adaptive codebook memory */ - const Word16 new_pit, /* i : decoded first frame pitch */ - const Word16 puls_pos, /* i : decoder position of the last glottal pulses decoded in the previous frame */ - const Word16 bfi_pitch /* i : Q6 pitch used for concealment */ - ); - Word16 FEC_synchro_exc_fx( /* o : do_WI flag */ - const Word16 L_frame, /* i : length of the frame */ - Word16 *exc, /* i/o: exc vector to modify */ - const Word16 desire_puls_pos, /* i : Pulse position send by the encoder */ - const Word16 true_puls_pos, /* i : Present pulse location */ - const Word16 Old_pitch /* i : Pitch use to create temporary adaptive codebook */ - ); - - //dec_uv_fx.c - void decod_unvoiced_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - const Word16 *Aq_fx, /* Q12 i : LP filter coefficient */ - const Word16 coder_type, /* Q0 i : coding type */ - Word16 *tmp_noise_fx, /* Q5 o : long term temporary noise energy */ - Word16 *pitch_buf_fx, /* Q6 o : floating pitch values for each subframe */ - Word16 *voice_factors_fx, /* Q15 o : voicing factors */ - Word16 *exc_fx, /* Q_X o : adapt. excitation exc */ - Word16 *exc2_fx, /* Q_X o : adapt. excitation/total exc */ - Word16 *bwe_exc_fx, /* Q_X i/o: excitation for SWB TBE */ - Word16 *gain_buf - ); - - void decod_unvoiced_ivas_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - const Word16 *Aq_fx, /* Q12 i : LP filter coefficient */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - const int16_t uc_two_stage_flag, /* i : flag indicating two-stage UC */ - const Word16 coder_type, /* Q0 i : coding type */ - Word16 *tmp_noise_fx, /* Q0 o : long term temporary noise energy */ - Word16 *pitch_buf_fx, /* Q6 o : floating pitch values for each subframe*/ - Word16 *voice_factors_fx, /* Q15 o : voicing factors */ - Word16 *exc_fx, /* Q_X o : adapt. excitation exc */ - Word16 *exc2_fx, /* Q_X o : adapt. excitation/total exc */ - Word16 *bwe_exc_fx, /* Q_X i/o: excitation for SWB TBE */ - Word16 *gain_buf - ); - - //gaus_dec_fx.c - void gaus_dec_fx( - Decoder_State* st_fx, /* i/o: decoder static memory */ - const Word16 i_subfr, /* i : subframe index */ - Word16* code, /* o : unvoiced excitation Q12 */ - Word32* L_norm_gain_code, /* o : gain of normalized gaussian excitation Q16 */ - Word16* lp_gainp, /* i/o : lp filtered pitch gain(FER) Q14 */ - Word16* lp_gainc, /* i/o : lp filtered code gain (FER) Q3 */ - Word16* inv_gain_inov, /* o : unscaled innovation gain Q12 */ - Word16* tilt_code, /* o : synthesis excitation spectrum tilt Q15 */ - Word16* voice_fac, /* o : estimated voicing factor Q15 */ - Word16* gain_pit, /* o : pitch gain Q14 */ - Word16* pt_pitch_1, /* o : floating pitch buffer Q6 */ - Word16* exc, /* o : excitation signal frame */ - Word32* L_gain_code, /* o : gain of the gaussian excitation Q16 */ - Word16* exc2, /* o : Scaled excitation signal frame */ - Word16* bwe_exc_fx, - Word16* sQ_exc, /* i/o : Excitation scaling factor (Decoder state) */ - Word16* sQsubfr /* i/o : Past excitation scaling factors (Decoder State) */ - ); - - void gaus_L2_dec( - Word16 *code, /* o : decoded gaussian codevector Q9 */ - Word16 tilt_code, /* i : tilt of code Q15 */ - const Word16 *A, /* i : quantized LPCs Q12 */ - Word16 formant_enh, /* i : formant enhancement factor Q15 */ - Word16 *seed_acelp /*i/o : random seed Q0 */ - ); - - //dec_gen_voic_fx.c - ivas_error decod_gen_voic_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - const Word16 L_frame_fx, /* i : length of the frame */ - const Word16 sharpFlag_fx, /* i : formant sharpening flag */ - const Word16 *Aq_fx, /* i : LP filter coefficient */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - const Word16 do_WI_fx, /* i : do interpolation after a FER */ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ - Word16 *voice_factors_fx, /* o : voicing factors */ - Word16 *exc_fx, /* i/o: adapt. excitation exc */ - Word16 *exc2_fx, /* i/o: adapt. excitation/total exc */ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ - Word16 *unbits, /* number of unused bits */ - Word16* gain_buf /*Q14*/ - ); - - ivas_error decod_gen_voic_ivas_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 sharpFlag_fx, /* i : formant sharpening flag */ - const Word16 *Aq_fx, /* i : LP filter coefficient */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - const Word16 do_WI_fx, /* i : do interpolation after a FER */ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ - Word16 *voice_factors_fx, /* o : voicing factors */ - Word16 *exc_fx, /* i/o: adapt. excitation exc */ - Word16 *exc2_fx, /* i/o: adapt. excitation/total exc */ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ - Word16 *unbits, /* number of unused bits */ - Word16 *gain_buf, - const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ - const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ - ); - - //dec_tran_fx.c - void decod_tran_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - const Word16 L_frame_fx, /* i : length of the frame */ - const Word16 tc_subfr_fx, /* i : TC subframe index */ - const Word16 *Aq_fx, /* i : LP filter coefficient */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ - Word16 *voice_factors_fx, /* o : voicing factors */ - Word16 *exc_fx, /* i/o: adapt. excitation exc */ - Word16 *exc2_fx, /* i/o: adapt. excitation/total exc */ - Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE */ - Word16 *unbits, /* i/o: number of unused bits */ - const Word16 sharpFlag, /* i : formant sharpening flag */ - Word16 *gain_buf /*Q14*/ - ); - - //transition_dec_fx.c - void transition_dec_fx( - Decoder_State* st_fx, /* i/o: decoder state structure */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 tc_subfr, /* i : TC subframe index */ - Word16* Jopt_flag, /* i : joint optimization flag */ - Word16* exc, /* o : excitation signal */ - Word16* T0, /* o : close loop integer pitch */ - Word16* T0_frac, /* o : close loop fractional part of the pitch */ - Word16* T0_min, /* i/o: delta search min for sf 2 & 4 */ - Word16* T0_max, /* i/o: delta search max for sf 2 & 4 */ - Word16** pt_pitch, /* o : floating pitch values */ - Word16* position, /* i/o: first glottal impulse position in frame */ - Word16* bwe_exc, /* o : excitation for SWB TBE */ - Word16* Q_exc /*i/o : scaling of excitation */ - ); - - Word16 tc_classif_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 L_frame /* i : length of the frame */ - ); - - //dec_ppp_fx.c - ivas_error decod_ppp_fx( - Decoder_State *st_fx, /* i/o: state structure */ - const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ - Word16 *pitch_buf_fx, /* i/o: fixed pitch values for each subframe */ - Word16 *exc_fx, /* i/o: current non-enhanced excitation */ - Word16 *exc2_fx, /* i/o: current enhanced excitation */ - Word16 bfi /* i : bad frame indicator */ - , Word16 *gain_buf /*Q14*/ - , Word16 *voice_factors, /* o : voicing factors */ - Word16 *bwe_exc_fx /* o : excitation for SWB TBE */ - ); - - //swb_bwe_dec_lr_fx.c - void swb_bwe_dec_lr_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word32 L_m_core[], /* i : lowband synthesis */ - const Word16 QsL, /* i : Q value of m_core */ - Word32 L_m[], /* o : highband synthesis with lowband zeroed */ - const Word32 L_total_brate, /* i : total bitrate for selecting subband pattern */ - Word16 BANDS_fx, /* i : Number subbands/Frame */ - Word16 *band_start_fx, /* i : Band Start of each SB */ - Word16 *band_end_fx, /* i : Band end of each SB */ - Word32 *L_band_energy, /* i : Band energy of each SB : Qbe */ - Word16 Qbe, /* i : Q value of band energy */ - Word16 *p2a_flags_fx, /* i : HF tonal Indicator */ - const Word16 hqswb_clas_fx, /* i : class information */ - Word16 lowlength_fx, /* i : Lowband Length */ - Word16 highlength_fx, /* i : Highband Length */ - const Word16 har_bands_fx, /* i : Number of LF harmonic bands */ - Word16 *prev_frm_hfe2, /* i/o: */ - Word16 *prev_stab_hfe2, /* i/o: */ - Word16 band_width_fx[], /* i : subband bandwidth */ - const Word32 L_y2_ni[], /* i/o: Sparse filled corecoder */ - Word16 *ni_seed_fx /* i/o: random seed */ - ); +void reset_tcx_overl_buf_fx( + TCX_DEC_HANDLE hTcxDec /* i/o: TCX decoder handle */ +); +void acelp_plc_mdct_transition_fx( + Decoder_State *st /* i/o: Decoder state */ +); +void cldfb_reset_memory_fx( + HANDLE_CLDFB_FILTER_BANK hs /* i/o: filter bank handle */ ); +void tcxltp_dec_init_fx( + TCX_LTP_DEC_HANDLE hTcxLtpDec, + const Word16 ini_frame, + const Word16 last_codec_mode, + const Word16 element_mode, + const Word16 pit_max, + const Word32 sr_core ); +// swb_bwe_dec_hr_fx.c + +Word16 swb_bwe_dec_hr_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 *syn_12k8_16k_fx, /* i : ACELP core synthesis @16kHz */ + const Word16 old_syn_exp, /* i : Exponent of core synthesis */ + Word16 *hb_synth_fx, /* o : SHB synthesis */ + const Word16 output_frame, /* i : frame length */ + const Word16 unbits, /* i : number of core unused bits */ + const Word16 pitch_buf[] /* i : pitch buffer */ +); + +void hr_bwe_dec_init( + HR_BWE_DEC_HANDLE hBWE_FD_HR /* i/o: HR BWE data handle */ +); + +// swb_bwe_com_hr_fx.c +void swb_hr_noise_fill_fx( + const Word16 is_transient, /* i : transient flag */ + const Word16 spect_start, /* i : spectrum start point */ + const Word16 spect_end, /* i : spectrum end point */ + const Word16 tilt_wb, /* i : tilt of wideband signal */ + const Word16 pitch, /* i : pitch value */ + const Word16 nq[], /* i : AVQ nq index */ + Word16 Nsv, /* i : number of subband */ + Word16 *bwe_highrate_seed, /* i/o: seed of random noise */ + Word16 *t_audio, /* i/o: mdct spectrum */ + Word16 Q_audio ); + +// stat_noise_uv_dec_fx.c +void stat_noise_uv_dec_fx( + Decoder_State *st_fx, /* i/o: Decoder static memory */ + Word16 *lsp_new, /* i : end-frame LSP vector */ + Word16 *lsp_mid, /* i : mid-frame LSP vector */ + Word16 *Aq, /* o : A(z) quantized for the 4 subframes */ + Word16 *exc2 /* i/o: excitation buffer */ + , + const Word16 uc_two_stage_flag /* i : flag indicating two-stage UC */ +); + +// stat_noise_uv_mod_fx.c +void stat_noise_uv_mod_fx( + const Word16 coder_type, /* i : Coder type */ + Word16 noisiness, /* i : noisiness parameter */ + const Word16 *lsp_old, /* i : old LSP vector at 4th sfr */ + const Word16 *lsp_new, /* i : LSP vector at 4th sfr */ + const Word16 *lsp_mid, /* i : LSP vector at 2nd sfr */ + Word16 *Aq, /* o : A(z) quantized for the 4 subframes */ + Word16 *exc2, /* i/o: excitation buffer */ + Word16 Q_exc, /* i : Q of exc2 excitation buffer [11..-1] expected */ + const Word16 bfi, /* i : Bad frame indicator */ + Word32 *ge_sm, /* i/o: smoothed excitation gain */ + Word16 *uv_count, /* i/o: unvoiced counter */ + Word16 *act_count, /* i/o: activation counter */ + Word16 lspold_s[], /* i/o: old LSP */ + Word16 *noimix_seed, /* i/o: mixture seed */ + Word16 *st_min_alpha, /* i/o: minimum alpha */ + Word16 *exc_pe, /* i/o: scale Q_stat_noise */ + const Word32 bitrate, /* i : core bitrate */ + const Word16 bwidth_fx, /* i : i bandwidth */ + Word16 *Q_stat_noise, /* i/o: noise scaling */ + Word16 *Q_stat_noise_ge /* i/o: noise scaling */ +); + +// FEC_adao_codebook_fx.c +Word16 FEC_SinOnset_fx( + Word16 *exc, /* i/o : exc vector to modify */ + Word16 puls_pos, /* i : last pulse position desired */ + const Word16 T0, /* i : Pitch information of the 1 subfr */ + Word32 enr_q, /* i : energy provide by the encoder */ + Word16 *Aq, /* i : A(z) filter Q12 */ + const Word16 L_frame /* i : frame length */ + , + const Word16 Qold ); + +Word16 FEC_enhACB_fx( + const Word16 L_frame, /* i : frame length */ + const Word16 last_L_frame, /* i : frame length of previous frame */ + Word16 *exc_io, /* i/o : adaptive codebook memory */ + const Word16 new_pit, /* i : decoded first frame pitch */ + const Word16 puls_pos, /* i : decoder position of the last glottal pulses decoded in the previous frame */ + const Word16 bfi_pitch /* i : Q6 pitch used for concealment */ +); +Word16 FEC_synchro_exc_fx( /* o : do_WI flag */ + const Word16 L_frame, /* i : length of the frame */ + Word16 *exc, /* i/o: exc vector to modify */ + const Word16 desire_puls_pos, /* i : Pulse position send by the encoder */ + const Word16 true_puls_pos, /* i : Present pulse location */ + const Word16 Old_pitch /* i : Pitch use to create temporary adaptive codebook */ +); + +// dec_uv_fx.c +void decod_unvoiced_fx( + Decoder_State *st_fx, /* i/o: decoder static memory */ + const Word16 *Aq_fx, /* Q12 i : LP filter coefficient */ + const Word16 coder_type, /* Q0 i : coding type */ + Word16 *tmp_noise_fx, /* Q5 o : long term temporary noise energy */ + Word16 *pitch_buf_fx, /* Q6 o : floating pitch values for each subframe */ + Word16 *voice_factors_fx, /* Q15 o : voicing factors */ + Word16 *exc_fx, /* Q_X o : adapt. excitation exc */ + Word16 *exc2_fx, /* Q_X o : adapt. excitation/total exc */ + Word16 *bwe_exc_fx, /* Q_X i/o: excitation for SWB TBE */ + Word16 *gain_buf ); + +void decod_unvoiced_ivas_fx( + Decoder_State *st_fx, /* i/o: decoder static memory */ + const Word16 *Aq_fx, /* Q12 i : LP filter coefficient */ + const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ + const int16_t uc_two_stage_flag, /* i : flag indicating two-stage UC */ + const Word16 coder_type, /* Q0 i : coding type */ + Word16 *tmp_noise_fx, /* Q0 o : long term temporary noise energy */ + Word16 *pitch_buf_fx, /* Q6 o : floating pitch values for each subframe*/ + Word16 *voice_factors_fx, /* Q15 o : voicing factors */ + Word16 *exc_fx, /* Q_X o : adapt. excitation exc */ + Word16 *exc2_fx, /* Q_X o : adapt. excitation/total exc */ + Word16 *bwe_exc_fx, /* Q_X i/o: excitation for SWB TBE */ + Word16 *gain_buf ); + +// gaus_dec_fx.c +void gaus_dec_fx( + Decoder_State *st_fx, /* i/o: decoder static memory */ + const Word16 i_subfr, /* i : subframe index */ + Word16 *code, /* o : unvoiced excitation Q12 */ + Word32 *L_norm_gain_code, /* o : gain of normalized gaussian excitation Q16 */ + Word16 *lp_gainp, /* i/o : lp filtered pitch gain(FER) Q14 */ + Word16 *lp_gainc, /* i/o : lp filtered code gain (FER) Q3 */ + Word16 *inv_gain_inov, /* o : unscaled innovation gain Q12 */ + Word16 *tilt_code, /* o : synthesis excitation spectrum tilt Q15 */ + Word16 *voice_fac, /* o : estimated voicing factor Q15 */ + Word16 *gain_pit, /* o : pitch gain Q14 */ + Word16 *pt_pitch_1, /* o : floating pitch buffer Q6 */ + Word16 *exc, /* o : excitation signal frame */ + Word32 *L_gain_code, /* o : gain of the gaussian excitation Q16 */ + Word16 *exc2, /* o : Scaled excitation signal frame */ + Word16 *bwe_exc_fx, + Word16 *sQ_exc, /* i/o : Excitation scaling factor (Decoder state) */ + Word16 *sQsubfr /* i/o : Past excitation scaling factors (Decoder State) */ +); + +void gaus_L2_dec( + Word16 *code, /* o : decoded gaussian codevector Q9 */ + Word16 tilt_code, /* i : tilt of code Q15 */ + const Word16 *A, /* i : quantized LPCs Q12 */ + Word16 formant_enh, /* i : formant enhancement factor Q15 */ + Word16 *seed_acelp /*i/o : random seed Q0 */ +); + +// dec_gen_voic_fx.c +ivas_error decod_gen_voic_fx( + Decoder_State *st_fx, /* i/o: decoder static memory */ + const Word16 L_frame_fx, /* i : length of the frame */ + const Word16 sharpFlag_fx, /* i : formant sharpening flag */ + const Word16 *Aq_fx, /* i : LP filter coefficient */ + const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ + const Word16 do_WI_fx, /* i : do interpolation after a FER */ + Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ + Word16 *voice_factors_fx, /* o : voicing factors */ + Word16 *exc_fx, /* i/o: adapt. excitation exc */ + Word16 *exc2_fx, /* i/o: adapt. excitation/total exc */ + Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ + Word16 *unbits, /* number of unused bits */ + Word16 *gain_buf /*Q14*/ +); + +ivas_error decod_gen_voic_ivas_fx( + Decoder_State *st_fx, /* i/o: decoder static memory */ + const Word16 L_frame, /* i : length of the frame */ + const Word16 sharpFlag_fx, /* i : formant sharpening flag */ + const Word16 *Aq_fx, /* i : LP filter coefficient */ + const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ + const Word16 do_WI_fx, /* i : do interpolation after a FER */ + Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ + Word16 *voice_factors_fx, /* o : voicing factors */ + Word16 *exc_fx, /* i/o: adapt. excitation exc */ + Word16 *exc2_fx, /* i/o: adapt. excitation/total exc */ + Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ + Word16 *unbits, /* number of unused bits */ + Word16 *gain_buf, + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ +); + +// dec_tran_fx.c +void decod_tran_fx( + Decoder_State *st_fx, /* i/o: decoder static memory */ + const Word16 L_frame_fx, /* i : length of the frame */ + const Word16 tc_subfr_fx, /* i : TC subframe index */ + const Word16 *Aq_fx, /* i : LP filter coefficient */ + const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ + Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ + Word16 *voice_factors_fx, /* o : voicing factors */ + Word16 *exc_fx, /* i/o: adapt. excitation exc */ + Word16 *exc2_fx, /* i/o: adapt. excitation/total exc */ + Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE */ + Word16 *unbits, /* i/o: number of unused bits */ + const Word16 sharpFlag, /* i : formant sharpening flag */ + Word16 *gain_buf /*Q14*/ +); + +// transition_dec_fx.c +void transition_dec_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const Word16 L_frame, /* i : length of the frame */ + const Word16 i_subfr, /* i : subframe index */ + const Word16 tc_subfr, /* i : TC subframe index */ + Word16 *Jopt_flag, /* i : joint optimization flag */ + Word16 *exc, /* o : excitation signal */ + Word16 *T0, /* o : close loop integer pitch */ + Word16 *T0_frac, /* o : close loop fractional part of the pitch */ + Word16 *T0_min, /* i/o: delta search min for sf 2 & 4 */ + Word16 *T0_max, /* i/o: delta search max for sf 2 & 4 */ + Word16 **pt_pitch, /* o : floating pitch values */ + Word16 *position, /* i/o: first glottal impulse position in frame */ + Word16 *bwe_exc, /* o : excitation for SWB TBE */ + Word16 *Q_exc /*i/o : scaling of excitation */ +); + +Word16 tc_classif_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 L_frame /* i : length of the frame */ +); + +// dec_ppp_fx.c +ivas_error decod_ppp_fx( + Decoder_State *st_fx, /* i/o: state structure */ + const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ + Word16 *pitch_buf_fx, /* i/o: fixed pitch values for each subframe */ + Word16 *exc_fx, /* i/o: current non-enhanced excitation */ + Word16 *exc2_fx, /* i/o: current enhanced excitation */ + Word16 bfi /* i : bad frame indicator */ + , + Word16 *gain_buf /*Q14*/ + , + Word16 *voice_factors, /* o : voicing factors */ + Word16 *bwe_exc_fx /* o : excitation for SWB TBE */ +); + +// swb_bwe_dec_lr_fx.c +void swb_bwe_dec_lr_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word32 L_m_core[], /* i : lowband synthesis */ + const Word16 QsL, /* i : Q value of m_core */ + Word32 L_m[], /* o : highband synthesis with lowband zeroed */ + const Word32 L_total_brate, /* i : total bitrate for selecting subband pattern */ + Word16 BANDS_fx, /* i : Number subbands/Frame */ + Word16 *band_start_fx, /* i : Band Start of each SB */ + Word16 *band_end_fx, /* i : Band end of each SB */ + Word32 *L_band_energy, /* i : Band energy of each SB : Qbe */ + Word16 Qbe, /* i : Q value of band energy */ + Word16 *p2a_flags_fx, /* i : HF tonal Indicator */ + const Word16 hqswb_clas_fx, /* i : class information */ + Word16 lowlength_fx, /* i : Lowband Length */ + Word16 highlength_fx, /* i : Highband Length */ + const Word16 har_bands_fx, /* i : Number of LF harmonic bands */ + Word16 *prev_frm_hfe2, /* i/o: */ + Word16 *prev_stab_hfe2, /* i/o: */ + Word16 band_width_fx[], /* i : subband bandwidth */ + const Word32 L_y2_ni[], /* i/o: Sparse filled corecoder */ + Word16 *ni_seed_fx /* i/o: random seed */ +); #ifdef IVAS_FLOAT_FIXED - //dec_acelp_tck_main_fx.c - Word16 dec_acelp_tcx_frame_fx( - Decoder_State* st, /* i/o: decoder state structure */ - Word16* concealWholeFrame, /* i/o: concealment flag */ - Word16* pcmBuf, /* o : synthesis */ - Word16* bpf_noise_buf, /* i/o: BPF noise buffer */ - Word16* pcmbufFB, /* o : synthesis @output_FS */ - Word32 bwe_exc_extended[], /* i/o: bandwidth extended excitation */ - Word16* voice_factors, /* o : voicing factors */ - Word16 pitch_buf[] /* o : floating pitch for each subframe */ -#ifdef IVAS_CODE_CNG - , STEREO_CNG_DEC_HANDLE hStereoCng /* i : stereo CNG handle */ +// dec_acelp_tck_main_fx.c +Word16 dec_acelp_tcx_frame_fx( + Decoder_State *st, /* i/o: decoder state structure */ + Word16 *concealWholeFrame, /* i/o: concealment flag */ + Word16 *pcmBuf, /* o : synthesis */ + Word16 *bpf_noise_buf, /* i/o: BPF noise buffer */ + Word16 *pcmbufFB, /* o : synthesis @output_FS */ + Word32 bwe_exc_extended[], /* i/o: bandwidth extended excitation */ + Word16 *voice_factors, /* o : voicing factors */ + Word16 pitch_buf[] /* o : floating pitch for each subframe */ +#ifdef IVAS_CODE_CNG + , + STEREO_CNG_DEC_HANDLE hStereoCng /* i : stereo CNG handle */ #endif - ); +); #endif - //dec_LPD_fx.c - void decoder_LPD_fx( - Word16 signal_out[], /* o : signal with LPD delay (7 subfrs) */ - Word16 signal_outFB[], /* o : synthesis @output_FS */ - Word16* total_nbbits, /* i/o: number of bits / decoded bits */ - Decoder_State* st, /* i/o: decoder memory state pointer */ - Word16* bpf_noise_buf, /* i/o: BPF noise buffer */ - Word16 bfi, /* i : BFI flag */ - Word16* bitsRead, /* o : number of read bits */ - Word16 param[], /* o : buffer of parameters */ - Word16* pitch_buf, /* i/o: floating pitch values for each subfr*/ - Word16* voice_factors, /* o : voicing factors */ - Word16* ptr_bwe_exc /* o : excitation for SWB TBE */ - ); - - //core_dec_switch_fx.c - void mode_switch_decoder_LPD_fx(Decoder_State *st, Word16 bandwidth_in, Word32 bitrate, Word16 frame_size_index - ); +// dec_LPD_fx.c +void decoder_LPD_fx( + Word16 signal_out[], /* o : signal with LPD delay (7 subfrs) */ + Word16 signal_outFB[], /* o : synthesis @output_FS */ + Word16 *total_nbbits, /* i/o: number of bits / decoded bits */ + Decoder_State *st, /* i/o: decoder memory state pointer */ + Word16 *bpf_noise_buf, /* i/o: BPF noise buffer */ + Word16 bfi, /* i : BFI flag */ + Word16 *bitsRead, /* o : number of read bits */ + Word16 param[], /* o : buffer of parameters */ + Word16 *pitch_buf, /* i/o: floating pitch values for each subfr*/ + Word16 *voice_factors, /* o : voicing factors */ + Word16 *ptr_bwe_exc /* o : excitation for SWB TBE */ +); + +// core_dec_switch_fx.c +void mode_switch_decoder_LPD_fx( Decoder_State *st, Word16 bandwidth_in, Word32 bitrate, Word16 frame_size_index ); #ifdef IVAS_FLOAT_FIXED - void mode_switch_decoder_LPD_ivas_fx( - Decoder_State *st, /* i/o: decoder state structure */ - const Word16 bwidth, /* i : audio bandwidth */ - const Word32 total_brate, /* i : total bitrate */ - const Word32 last_total_brate, /* i : last frame total bitrate */ - const Word16 frame_size_index, /* i : index determining the frame size */ - const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0)*/ - const Word16 last_element_mode, /* i : last element mode */ - Word16 *Q_syn_Overl_TDAC, - Word16 *Q_fer_samples, - Word16 *Q_syn_Overl, - Word16 *Q_syn_Overl_TDACFB, - Word16 *Q_syn_OverlFB, - Word16 *Q_old_out, - Word16 *Q_old_outLB, - Word16 *Q_old_Aq_12_8 - ); +void mode_switch_decoder_LPD_ivas_fx( + Decoder_State *st, /* i/o: decoder state structure */ + const Word16 bwidth, /* i : audio bandwidth */ + const Word32 total_brate, /* i : total bitrate */ + const Word32 last_total_brate, /* i : last frame total bitrate */ + const Word16 frame_size_index, /* i : index determining the frame size */ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0)*/ + const Word16 last_element_mode, /* i : last element mode */ + Word16 *Q_syn_Overl_TDAC, + Word16 *Q_fer_samples, + Word16 *Q_syn_Overl, + Word16 *Q_syn_Overl_TDACFB, + Word16 *Q_syn_OverlFB, + Word16 *Q_old_out, + Word16 *Q_old_outLB, + Word16 *Q_old_Aq_12_8 ); #endif // IVAS_FLOAT_FIXED - //ari_hm_dec.c - - int16_t DecodeIndex( - Decoder_State *st, - const int16_t Bandwidth, /* o : NB, 1: (S)WB */ - int16_t *PeriodicityIndex); - Word16 - DecodeIndex_fx( - Decoder_State *st, - const Word16 Bandwidth, - Word16 *PeriodicityIndex); - void tcx_hm_decode( - const Word16 L_frame, /* i : number of spectral lines */ - Word32 env[], /* i/o: envelope shape (Q16) */ - const Word16 targetBits, /* i : target bit budget */ - const Word16 coder_type, /* i : GC/VC coder type */ - const Word16 prm_hm[], /* i : HM parameters */ - const Word16 LtpPitchLag, /* i : LTP pitch lag or -1 if none */ - Word16 *hm_bits /* o : bit consumption */ - ); - - //lsf_msvq_ma_dec_fx.c - Word16 lsf_msvq_ma_decprm(Decoder_State *st, Word16 *param_lpc); - - Word16 lsf_bctcvq_decprm( - Decoder_State * st, - Word16 *param_lpc - - ); - Word16 D_lsf_tcxlpc( - const Word16 indices[], /* (I) VQ indices */ - Word16 xsf_q[], /* (O) quantized xSF */ - Word16 xsf_q_ind[], /* (O) quantized xSF (w/o MA prediction) */ - Word16 narrowband, /* (I) narrowband flag */ - Word16 cdk, /* (I) codebook selector */ - Word16 mem_MA[] /* (I) MA memory */ - ); - - Word16 dec_lsf_tcxlpc( - Decoder_State *st, /* (I/O) Decoder state */ - Word16 **indices, /* (O) Ptr to VQ indices */ - Word16 narrowband, /* (I) narrowband flag */ - Word16 cdk /* (I) codebook selector */ - ); - - //lsf_msvq_ma_fx.c +// ari_hm_dec.c + +int16_t DecodeIndex( + Decoder_State *st, + const int16_t Bandwidth, /* o : NB, 1: (S)WB */ + int16_t *PeriodicityIndex ); +Word16 +DecodeIndex_fx( + Decoder_State *st, + const Word16 Bandwidth, + Word16 *PeriodicityIndex ); +void tcx_hm_decode( + const Word16 L_frame, /* i : number of spectral lines */ + Word32 env[], /* i/o: envelope shape (Q16) */ + const Word16 targetBits, /* i : target bit budget */ + const Word16 coder_type, /* i : GC/VC coder type */ + const Word16 prm_hm[], /* i : HM parameters */ + const Word16 LtpPitchLag, /* i : LTP pitch lag or -1 if none */ + Word16 *hm_bits /* o : bit consumption */ +); + +// lsf_msvq_ma_dec_fx.c +Word16 lsf_msvq_ma_decprm( Decoder_State *st, Word16 *param_lpc ); + +Word16 lsf_bctcvq_decprm( + Decoder_State *st, + Word16 *param_lpc + +); +Word16 D_lsf_tcxlpc( + const Word16 indices[], /* (I) VQ indices */ + Word16 xsf_q[], /* (O) quantized xSF */ + Word16 xsf_q_ind[], /* (O) quantized xSF (w/o MA prediction) */ + Word16 narrowband, /* (I) narrowband flag */ + Word16 cdk, /* (I) codebook selector */ + Word16 mem_MA[] /* (I) MA memory */ +); + +Word16 dec_lsf_tcxlpc( + Decoder_State *st, /* (I/O) Decoder state */ + Word16 **indices, /* (O) Ptr to VQ indices */ + Word16 narrowband, /* (I) narrowband flag */ + Word16 cdk /* (I) codebook selector */ +); + +// lsf_msvq_ma_fx.c void midlsf_dec( - const Word16 qlsf0[], /* i: quantized lsf coefficients (3Q12) */ - const Word16 qlsf1[], /* i: quantized lsf coefficients (3Q12) */ - const Word16 idx, /* i: codebook index */ - Word16 qlsf[], /* o: decoded lsf coefficients (3Q12) */ + const Word16 qlsf0[], /* i: quantized lsf coefficients (3Q12) */ + const Word16 qlsf1[], /* i: quantized lsf coefficients (3Q12) */ + const Word16 idx, /* i: codebook index */ + Word16 qlsf[], /* o: decoded lsf coefficients (3Q12) */ const Word16 coder_type, Word16 *mid_lsf_int, const Word16 prev_bfi, - const Word16 safety_net -); + const Word16 safety_net ); Word16 lsf_ind_is_active( - const Word16 lsf_q_ind[], - const Word16 means[], - const Word16 narrowband, - const Word16 cdk - ); + const Word16 lsf_q_ind[], + const Word16 means[], + const Word16 narrowband, + const Word16 cdk ); // IGFSCFDecoder.c void IGFSCFDecoderOpen( - IGFSCFDEC_INSTANCE_HANDLE hPublicData, /* i : handle to public data */ - H_IGF_INFO hIgfInfo, /* i : IGF info handle */ - const Word32 total_brate, - const Word16 bwidth, - const Word16 element_mode, - const Word16 rf_mode -); + IGFSCFDEC_INSTANCE_HANDLE hPublicData, /* i : handle to public data */ + H_IGF_INFO hIgfInfo, /* i : IGF info handle */ + const Word32 total_brate, + const Word16 bwidth, + const Word16 element_mode, + const Word16 rf_mode ); void IGFSCFDecoderReset( - IGFSCFDEC_INSTANCE_HANDLE hPublicData /* i/o: handle to public data */ + IGFSCFDEC_INSTANCE_HANDLE hPublicData /* i/o: handle to public data */ ); void IGFSCFDecoderDecode( - IGFSCFDEC_INSTANCE_HANDLE hPublicData, /* i/o: handle to public data or NULL in case there was no instance created */ - Decoder_State* st, /* i/o: pointer to decoder state */ - int16_t* sfe, /* o : ptr to an array which will contain the decoded quantized coefficients */ - const Word16 igfGridIdx, /* i : igf grid index see declaration of IGF_GRID_IDX for details */ - const Word16 indepFlag /* i : if 1 on input the decoder will be forced to reset, - if 0 on input the decoder will be forced to encode without a reset */ + IGFSCFDEC_INSTANCE_HANDLE hPublicData, /* i/o: handle to public data or NULL in case there was no instance created */ + Decoder_State *st, /* i/o: pointer to decoder state */ + int16_t *sfe, /* o : ptr to an array which will contain the decoded quantized coefficients */ + const Word16 igfGridIdx, /* i : igf grid index see declaration of IGF_GRID_IDX for details */ + const Word16 indepFlag /* i : if 1 on input the decoder will be forced to reset, + if 0 on input the decoder will be forced to encode without a reset */ ); -//ari_dec_fx.c -Word16 ari_decode_overflow_fx(Tastat *s); +// ari_dec_fx.c +Word16 ari_decode_overflow_fx( Tastat *s ); void ari_start_decoding_14bits_fx( - Decoder_State *st, - Tastat *s -); + Decoder_State *st, + Tastat *s ); -Word16 ari_start_decoding_14bits_prm_fx(const Word16 *ptr, Word16 bp, Tastat *s); +Word16 ari_start_decoding_14bits_prm_fx( const Word16 *ptr, Word16 bp, Tastat *s ); Word16 ari_decode_14bits_s17_ext_fx( - Decoder_State *st, - Tastat *s, - UWord16 const *cum_freq -); + Decoder_State *st, + Tastat *s, + UWord16 const *cum_freq ); Word16 ari_decode_14bits_s27_ext_fx( - Decoder_State *st, - Tastat *s, - UWord16 const *cum_freq -); + Decoder_State *st, + Tastat *s, + UWord16 const *cum_freq ); Word16 ari_decode_14bits_bit_ext_fx( - Decoder_State *st, - Tastat *s -); + Decoder_State *st, + Tastat *s ); -Word16 ari_decode_14bits_pow_fx(Word16 *ptr, Word16 bp, Word16 bits, Word16 *res, Tastat *s, Word16 base); +Word16 ari_decode_14bits_pow_fx( Word16 *ptr, Word16 bp, Word16 bits, Word16 *res, Tastat *s, Word16 base ); -Word16 ari_decode_14bits_sign_fx(Word16 *ptr, Word16 bp, Word16 bits, Word16 *res, Tastat *s); +Word16 ari_decode_14bits_sign_fx( Word16 *ptr, Word16 bp, Word16 bits, Word16 *res, Tastat *s ); -//dec_prm_fx.c +// dec_prm_fx.c void getTCXparam_fx( - Decoder_State *st, /* i/o: Decoder State handle */ - Decoder_State *st0, /* i : bitstream */ - CONTEXT_HM_CONFIG hm_cfg, /* i/o: HM config */ - Word16 param[], /* o : decoded parameters */ - const Word16 bits_common, /* i : number of common bits */ - const Word16 start_bit_pos, /* i : position of the start bit */ - const Word16 *no_param_tns, /* i : number of TNS parameters per subframe */ - Word16 p_param[2], /* o : pointer to parameters for next round of bs reading*/ - Word16 nTnsBitsTCX10[2], - const Word16 pre_past_flag -); + Decoder_State *st, /* i/o: Decoder State handle */ + Decoder_State *st0, /* i : bitstream */ + CONTEXT_HM_CONFIG hm_cfg, /* i/o: HM config */ + Word16 param[], /* o : decoded parameters */ + const Word16 bits_common, /* i : number of common bits */ + const Word16 start_bit_pos, /* i : position of the start bit */ + const Word16 *no_param_tns, /* i : number of TNS parameters per subframe */ + Word16 p_param[2], /* o : pointer to parameters for next round of bs reading*/ + Word16 nTnsBitsTCX10[2], + const Word16 pre_past_flag ); void dec_prm_fx( - Word16 *coder_type, - Word16 param[], /* (o) : decoded parameters */ - Word16 param_lpc[], /* (o) : LPC parameters */ - Word16 *total_nbbits, /* i/o : number of bits / decoded bits */ - Decoder_State *st, - Word16 L_frame, - Word16 *bitsRead -); + Word16 *coder_type, + Word16 param[], /* (o) : decoded parameters */ + Word16 param_lpc[], /* (o) : LPC parameters */ + Word16 *total_nbbits, /* i/o : number of bits / decoded bits */ + Decoder_State *st, + Word16 L_frame, + Word16 *bitsRead ); void getLPCparam_fx( Decoder_State *st, /* i/o: decoder memory state */ @@ -8355,71 +8201,71 @@ void getLPCparam_fx( const Word16 ch, /* i : channel */ const Word16 sns_low_br_mode /* i : SNS low-bitrate mode */ ); -//ari_hm_fx.c +// ari_hm_fx.c void UnmapIndex( - const Word16 PeriodicityIndex, - const Word16 Bandwidth, - const Word16 LtpPitchLag, - const Word16 SmallerLags, - Word16 *FractionalResolution, - Word32 *Lag); + const Word16 PeriodicityIndex, + const Word16 Bandwidth, + const Word16 LtpPitchLag, + const Word16 SmallerLags, + Word16 *FractionalResolution, + Word32 *Lag ); void ConfigureContextHm( - const Word16 NumCoeffs, /* (I) Number of coefficients */ - const Word16 TargetBits, /* (I) Target bit budget (excl. Done flag) */ - const Word16 PeriodicityIndex, /* (I) Pitch related index */ - const Word16 LtpPitchLag, /* (I) TCX-LTP pitch in F.D. */ - CONTEXT_HM_CONFIG *hm_cfg /* (O) Context-based harmonic model configuration */ + const Word16 NumCoeffs, /* (I) Number of coefficients */ + const Word16 TargetBits, /* (I) Target bit budget (excl. Done flag) */ + const Word16 PeriodicityIndex, /* (I) Pitch related index */ + const Word16 LtpPitchLag, /* (I) TCX-LTP pitch in F.D. */ + CONTEXT_HM_CONFIG *hm_cfg /* (O) Context-based harmonic model configuration */ ); Word16 CountIndexBits( - Word16 Bandwidth, /* 0: NB, 1: (S)WB */ - Word16 PeriodicityIndex); + Word16 Bandwidth, /* 0: NB, 1: (S)WB */ + Word16 PeriodicityIndex ); int tcx_hm_render( - Word32 lag, /* i: pitch lag Q0 */ - Word16 fract_res, /* i: fractional resolution of the lag Q0 */ - Word16 p[] /* o: harmonic model Q13 */ + Word32 lag, /* i: pitch lag Q0 */ + Word16 fract_res, /* i: fractional resolution of the lag Q0 */ + Word16 p[] /* o: harmonic model Q13 */ ); void tcx_hm_modify_envelope( - Word16 gain, /* i: HM gain Q11 */ - Word32 lag, /* i: pitch lag Q0 */ - Word16 fract_res, /* i: fractional resolution of the lag Q0 */ - Word16 p[], /* i: harmonic model Q13 */ - Word32 env[], /* i/o: envelope Q16 */ - Word16 L_frame /* i: number of spectral lines Q0 */ + Word16 gain, /* i: HM gain Q11 */ + Word32 lag, /* i: pitch lag Q0 */ + Word16 fract_res, /* i: fractional resolution of the lag Q0 */ + Word16 p[], /* i: harmonic model Q13 */ + Word32 env[], /* i/o: envelope Q16 */ + Word16 L_frame /* i: number of spectral lines Q0 */ ); -//tns_base_dec_fx.c +// tns_base_dec_fx.c #ifdef IVAS_CODE void #else Word16 #endif -ReadTnsData(STnsConfig const * pTnsConfig, - Decoder_State *st, - Word16 * pnBits, - Word16 * stream, - Word16 * pnSize); +ReadTnsData( STnsConfig const *pTnsConfig, + Decoder_State *st, + Word16 *pnBits, + Word16 *stream, + Word16 *pnSize ); #define IVAS_CODE #ifdef IVAS_CODE void #else Word16 #endif -ReadTnsData_ivas_fx(STnsConfig const * pTnsConfig, - Decoder_State *st, - Word16 * pnBits, - Word16 * stream, - Word16 * pnSize); +ReadTnsData_ivas_fx( STnsConfig const *pTnsConfig, + Decoder_State *st, + Word16 *pnBits, + Word16 *stream, + Word16 *pnSize ); #undef IVAS_CODE -Word16 DecodeTnsData(STnsConfig const * pTnsConfig, - Word16 const * stream, - Word16 * pnSize, - STnsData * pTnsData); +Word16 DecodeTnsData( STnsConfig const *pTnsConfig, + Word16 const *stream, + Word16 *pnSize, + STnsData *pTnsData ); Word16 DecodeTnsData_ivas_fx( STnsConfig const *pTnsConfig, @@ -8427,21 +8273,21 @@ Word16 DecodeTnsData_ivas_fx( Word16 *pnSize, STnsData *pTnsData ); -//parametr_bitmapping.c using ivas +// parametr_bitmapping.c using ivas void GetParameters( - ParamsBitMap const *paramsBitMap, - const int16_t nParams, - void const *pParameter, - int16_t **pStream, - int16_t *pnSize, - int16_t *pnBits); + ParamsBitMap const *paramsBitMap, + const int16_t nParams, + void const *pParameter, + int16_t **pStream, + int16_t *pnSize, + int16_t *pnBits ); void SetParameters( - ParamsBitMap const *paramsBitMap, - const int16_t nParams, - void *pParameter, - const int16_t **pStream, - int16_t *pnSize); + ParamsBitMap const *paramsBitMap, + const int16_t nParams, + void *pParameter, + const int16_t **pStream, + int16_t *pnSize ); void SetParameters_fx( ParamsBitMap const *paramsBitMap, @@ -8451,55 +8297,54 @@ void SetParameters_fx( Word16 *pnSize ); void WriteToBitstream( - ParamsBitMap const *paramsBitMap, - const int16_t nParams, - const int16_t **pStream, - int16_t *pnSize, - BSTR_ENC_HANDLE hBstr, - int16_t *pnBits); + ParamsBitMap const *paramsBitMap, + const int16_t nParams, + const int16_t **pStream, + int16_t *pnSize, + BSTR_ENC_HANDLE hBstr, + int16_t *pnBits ); void ReadFromBitstream( - ParamsBitMap const *paramsBitMap, - const int16_t nArrayLength, - Decoder_State *st, - int16_t **pStream, - int16_t *pnSize); + ParamsBitMap const *paramsBitMap, + const int16_t nArrayLength, + Decoder_State *st, + int16_t **pStream, + int16_t *pnSize ); void ReadFromBitstream_fx( - ParamsBitMap const *paramsBitMap, - const Word16 nArrayLength, - Decoder_State *st, - Word16 **pStream, - Word16 *pnSize -); -//igf_dec_fx.c -void IGFDecReadData(const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Deccoder */ - Decoder_State *st, /**< in: | decoder state */ - const Word16 igfGridIdx, /**< in: Q0 | in case of CELP->TCX switching, use 1.25 framelength */ - const Word16 isIndepFrame /**< in: Q0 | if 1: arith dec force reset, if 0: no reset */ + ParamsBitMap const *paramsBitMap, + const Word16 nArrayLength, + Decoder_State *st, + Word16 **pStream, + Word16 *pnSize ); +// igf_dec_fx.c +void IGFDecReadData( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Deccoder */ + Decoder_State *st, /**< in: | decoder state */ + const Word16 igfGridIdx, /**< in: Q0 | in case of CELP->TCX switching, use 1.25 framelength */ + const Word16 isIndepFrame /**< in: Q0 | if 1: arith dec force reset, if 0: no reset */ ); -void IGFDecReadLevel(const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Deccoder */ - Decoder_State *st, /**< in: | decoder state */ - const Word16 igfGridIdx, /**< in: Q0 | in case of CELP->TCX switching, use 1.25 framelength */ - const Word16 isIndepFrame /**< in: Q0 | if 1: arith dec force reset, if 0: no reset */ +void IGFDecReadLevel( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Deccoder */ + Decoder_State *st, /**< in: | decoder state */ + const Word16 igfGridIdx, /**< in: Q0 | in case of CELP->TCX switching, use 1.25 framelength */ + const Word16 isIndepFrame /**< in: Q0 | if 1: arith dec force reset, if 0: no reset */ ); -void IGFDecApplyMono(const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ - Word32 *spectrum, /**< in/out: | MDCT spectrum */ - Word16 *spectrum_e, /**< in/out: | exponent of spectrum */ - const Word16 igfGridIdx, /**< in: | in case of CELP->TCX switching, use 1.25 framelength */ - Word16 bfi /**< in: | frame loss == 1, frame good == 0 */ +void IGFDecApplyMono( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ + Word32 *spectrum, /**< in/out: | MDCT spectrum */ + Word16 *spectrum_e, /**< in/out: | exponent of spectrum */ + const Word16 igfGridIdx, /**< in: | in case of CELP->TCX switching, use 1.25 framelength */ + Word16 bfi /**< in: | frame loss == 1, frame good == 0 */ ); void IGFDecApplyMono_ivas( - const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ - Word32 *spectrum, /**< in/out: | MDCT spectrum */ - Word16 *spectrum_e, /**< in/out: | exponent of spectrum */ - const Word16 igfGridIdx, /**< in: | in case of CELP->TCX switching, use 1.25 framelength */ - Word16 bfi, /**< in: | frame loss == 1, frame good == 0 */ - Word16 element_mode /**< in: | IVAS element mode */ + const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ + Word32 *spectrum, /**< in/out: | MDCT spectrum */ + Word16 *spectrum_e, /**< in/out: | exponent of spectrum */ + const Word16 igfGridIdx, /**< in: | in case of CELP->TCX switching, use 1.25 framelength */ + Word16 bfi, /**< in: | frame loss == 1, frame good == 0 */ + Word16 element_mode /**< in: | IVAS element mode */ ); void IGFDecApplyStereo( @@ -8513,32 +8358,31 @@ void IGFDecApplyStereo( const Word16 *coreMsMask, const Word16 restrict_hopsize, const Word16 bfi, /* i : frame loss == 1, frame good == 0 */ - const Word16 bfi_apply_damping -); + const Word16 bfi_apply_damping ); void IGFDecSetMode( - const IGF_DEC_INSTANCE_HANDLE hIGFDec, /* o : instance handle of IGF Decoder */ - const Word32 total_brate, /* i : bitrate */ - const Word16 bwidth, /* i : audio bandwidth */ - const Word16 element_mode, /* i : IVAS element mode */ - const Word16 defaultStartLine, /* i : default start subband index */ - const Word16 defaultStopLine, /* i : default stop subband index */ - const Word16 rf_mode /* i : flag to signal the RF mode */ + const IGF_DEC_INSTANCE_HANDLE hIGFDec, /* o : instance handle of IGF Decoder */ + const Word32 total_brate, /* i : bitrate */ + const Word16 bwidth, /* i : audio bandwidth */ + const Word16 element_mode, /* i : IVAS element mode */ + const Word16 defaultStartLine, /* i : default start subband index */ + const Word16 defaultStopLine, /* i : default stop subband index */ + const Word16 rf_mode /* i : flag to signal the RF mode */ ); #ifdef IVAS_FLOAT_FIXED void IGFDecSetMode_ivas_fx( - const IGF_DEC_INSTANCE_HANDLE hIGFDec, /* i : instance handle of IGF Decoder */ - const Word32 total_brate, /* i : bitrate */ - const Word16 bwidth, /* i : audio bandwidth */ - const Word16 element_mode, /* i : IVAS element mode */ - const Word16 defaultStartLine, /* i : default start subband index */ - const Word16 defaultStopLine, /* i : default stop subband index */ - const Word16 rf_mode /* i : flag to signal the RF mode */ + const IGF_DEC_INSTANCE_HANDLE hIGFDec, /* i : instance handle of IGF Decoder */ + const Word32 total_brate, /* i : bitrate */ + const Word16 bwidth, /* i : audio bandwidth */ + const Word16 element_mode, /* i : IVAS element mode */ + const Word16 defaultStartLine, /* i : default start subband index */ + const Word16 defaultStopLine, /* i : default stop subband index */ + const Word16 rf_mode /* i : flag to signal the RF mode */ ); #endif // IVAS_FLOAT_FIXED -void IGFDecUpdateInfo(const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ - const Word16 igfGridIdx /**< in: | IGF grid index */ +void IGFDecUpdateInfo( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ + const Word16 igfGridIdx /**< in: | IGF grid index */ ); void IGFDecUpdateInfo_ivas_fx( @@ -8547,10 +8391,10 @@ void IGFDecUpdateInfo_ivas_fx( const Word16 igfGridIdx /* i : IGF grid index */ ); -void IGFDecCopyLPCFlatSpectrum(const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ - const Word32 *pSpectrumFlat, /**< in: Q31 | LPC flattend spectrum from TCX dec */ - const Word16 pSpectrumFlat_exp, /**< in: | exponent of pSpectrumFlat */ - const Word16 igfGridIdx /**< in: Q0 | IGF grid index */ +void IGFDecCopyLPCFlatSpectrum( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ + const Word32 *pSpectrumFlat, /**< in: Q31 | LPC flattend spectrum from TCX dec */ + const Word16 pSpectrumFlat_exp, /**< in: | exponent of pSpectrumFlat */ + const Word16 igfGridIdx /**< in: Q0 | IGF grid index */ ); void IGFDecCopyLPCFlatSpectrum_fx( @@ -8560,12 +8404,12 @@ void IGFDecCopyLPCFlatSpectrum_fx( const Word16 igfGridIdx /**< in: Q0 | IGF grid index */ ); -void IGFDecStoreTCX10SubFrameData(const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ - const Word16 subFrameIdx /**< in: Q0 | index of subframe */ +void IGFDecStoreTCX10SubFrameData( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ + const Word16 subFrameIdx /**< in: Q0 | index of subframe */ ); -void IGFDecRestoreTCX10SubFrameData(const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ - const Word16 subFrameIdx /**< in: Q0 | index of subframe */ +void IGFDecRestoreTCX10SubFrameData( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ + const Word16 subFrameIdx /**< in: Q0 | index of subframe */ ); void IGFDecRestoreTCX10SubFrameData_fx( @@ -8575,28 +8419,28 @@ void IGFDecRestoreTCX10SubFrameData_fx( void init_igf_dec( - IGF_DEC_INSTANCE_HANDLE hIGFDec /* i/o: IGF decoder handle */ + IGF_DEC_INSTANCE_HANDLE hIGFDec /* i/o: IGF decoder handle */ ); -//dlpc_avq_fx.c +// dlpc_avq_fx.c Word16 dlpc_avq_fx( - Word16 *index, /* (i) Quantization indices */ - Word16 *LSF_Q, /* (o) Quantized LSF vectors */ - Word16 numlpc, /* (i) Number of sets of lpc */ - Word32 sr_core -); + Word16 *index, /* (i) Quantization indices */ + Word16 *LSF_Q, /* (o) Quantized LSF vectors */ + Word16 numlpc, /* (i) Number of sets of lpc */ + Word32 sr_core ); Word16 decode_lpc_avq_fx( - Decoder_State* st, /* i/o: decoder state structure */ - const Word16 numlpc, /* i : Number of sets of lpc */ - Word16* param_lpc /* o : lpc parameters */ + Decoder_State *st, /* i/o: decoder state structure */ + const Word16 numlpc, /* i : Number of sets of lpc */ + Word16 *param_lpc /* o : lpc parameters */ #ifdef IVAS_CODE_AVQ_LPC - , const Word16 ch, /* i : channel */ - const Word16 element_mode, /* i : element mode */ - const Word16 sns_low_br_mode /* i : SNS low-bitrate mode */ + , + const Word16 ch, /* i : channel */ + const Word16 element_mode, /* i : element mode */ + const Word16 sns_low_br_mode /* i : SNS low-bitrate mode */ #endif ); -//decode_lpc_avq_ivas_fx declaration with IVAS_CODE_AVQ_LPC enabled +// decode_lpc_avq_ivas_fx declaration with IVAS_CODE_AVQ_LPC enabled Word16 decode_lpc_avq_ivas_fx( Decoder_State *st, /* i/o: decoder state structure */ const Word16 numlpc, /* i : Number of sets of lpc */ @@ -8606,242 +8450,243 @@ Word16 decode_lpc_avq_ivas_fx( const Word16 element_mode, /* i : element mode */ const Word16 sns_low_br_mode /* i : SNS low-bitrate mode */ ); -//vlpc_1st_dec_fx.c +// vlpc_1st_dec_fx.c void vlpc_1st_dec( - Word16 index, /* i : codebook index */ - Word16 *lsfq); /* i/o: i:prediction o:quantized lsf */ + Word16 index, /* i : codebook index */ + Word16 *lsfq ); /* i/o: i:prediction o:quantized lsf */ -//vlpc_2st_dec_fx.c +// vlpc_2st_dec_fx.c void vlpc_2st_dec( - Word16 *lsfq, /* i/o: i:1st stage o:1st+2nd stage */ - Word16 *indx, /* i : index[] (4 bits per words) */ - Word16 mode, /* i : 0=abs, >0=rel */ - Word32 sr_core); + Word16 *lsfq, /* i/o: i:1st stage o:1st+2nd stage */ + Word16 *indx, /* i : index[] (4 bits per words) */ + Word16 mode, /* i : 0=abs, >0=rel */ + Word32 sr_core ); -//vlpc_2st_com_fx.c -void lsf_weight_2st(const Word16 *lsfq, /* i : quantized lsf coefficients (3Q12) */ - Word16 *w, /* o : weighting function (0Q15) */ - const Word16 mode /* i : operational mode */ +// vlpc_2st_com_fx.c +void lsf_weight_2st( const Word16 *lsfq, /* i : quantized lsf coefficients (3Q12) */ + Word16 *w, /* o : weighting function (0Q15) */ + const Word16 mode /* i : operational mode */ ); -//ACcontextMapping_fx.c +// ACcontextMapping_fx.c /* Returns: index of next coefficient */ Word16 get_next_coeff_mapped( - Word16 ii[2], /* i/o: coefficient indexes */ - Word16 *pp, /* o : peak(1)/hole(0) indicator */ - Word16 *idx, /* o : index in unmapped domain */ - CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ + Word16 ii[2], /* i/o: coefficient indexes */ + Word16 *pp, /* o : peak(1)/hole(0) indicator */ + Word16 *idx, /* o : index in unmapped domain */ + CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ ); /* Returns: index of next coefficient */ Word16 get_next_coeff_unmapped( - Word16 ii[2], /* i/o: coefficient indexes */ - Word16 *pp, /* o : peak(1)/hole(0) indicator */ - Word16 *idx, /* o : index in unmapped domain */ - CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ + Word16 ii[2], /* i/o: coefficient indexes */ + Word16 *pp, /* o : peak(1)/hole(0) indicator */ + Word16 *idx, /* o : index in unmapped domain */ + CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ ); -Word16 update_mixed_context(Word16 ctx, Word16 a); - +Word16 update_mixed_context( Word16 ctx, Word16 a ); -//ACcontextMapping_dec_fx.c +// ACcontextMapping_dec_fx.c -typedef Word16(*get_next_coeff_function)( - Word16 ii[2], /* i/o: coefficient indexes */ - Word16 *pp, /* o : peak(1)/hole(0) indicator */ - Word16 *idx, /* o : index in unmapped domain */ - CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ - ); +typedef Word16 ( *get_next_coeff_function )( + Word16 ii[2], /* i/o: coefficient indexes */ + Word16 *pp, /* o : peak(1)/hole(0) indicator */ + Word16 *idx, /* o : index in unmapped domain */ + CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ +); Word16 ACcontextMapping_decode2_no_mem_s17_LC( - Decoder_State *st,/* i/o: decoder state */ - Word16 *x, /* o: decoded spectrum */ - Word16 nt, /* i: size of spectrum */ - Word16 nbbits, /* i: bit budget */ - Word16 resQMaxBits, /* i: residual coding maximum bits*/ - CONTEXT_HM_CONFIG *hm_cfg /* i: context-based harmonic model configuration */ + Decoder_State *st, /* i/o: decoder state */ + Word16 *x, /* o: decoded spectrum */ + Word16 nt, /* i: size of spectrum */ + Word16 nbbits, /* i: bit budget */ + Word16 resQMaxBits, /* i: residual coding maximum bits*/ + CONTEXT_HM_CONFIG *hm_cfg /* i: context-based harmonic model configuration */ ); Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx( - Decoder_State *st, /* i/o: decoder state */ - Word16 *x, /* o : decoded spectrum */ - const Word16 nt, /* i : size of spectrum */ - const Word16 nbbits, /* i : bit budget */ - const Word16 resQMaxBits, /* i : residual coding maximum bits */ - CONTEXT_HM_CONFIG *hm_cfg /* i : context-based harmonic model configuration*/ + Decoder_State *st, /* i/o: decoder state */ + Word16 *x, /* o : decoded spectrum */ + const Word16 nt, /* i : size of spectrum */ + const Word16 nbbits, /* i : bit budget */ + const Word16 resQMaxBits, /* i : residual coding maximum bits */ + CONTEXT_HM_CONFIG *hm_cfg /* i : context-based harmonic model configuration*/ ); -//core_dec_reconf_fx.c -void reconfig_decoder_LPD_fx(Decoder_State *st, Word16 bits_frame, Word16 bandwidth_mode, Word32 bitrate, Word16 L_frame_old); +// core_dec_reconf_fx.c +void reconfig_decoder_LPD_fx( Decoder_State *st, Word16 bits_frame, Word16 bandwidth_mode, Word32 bitrate, Word16 L_frame_old ); #ifdef IVAS_FLOAT_FIXED void reconfig_decoder_LPD_ivas_fx( - Decoder_State *st, /* i/o: decoder state structure */ - const Word16 bits_frame, /* i : bit budget */ - const Word16 bwidth, /* i : audio bandwidth */ - const Word32 total_brate, /* i : total bitrate */ - const Word16 L_frame_old /* i : frame length */ + Decoder_State *st, /* i/o: decoder state structure */ + const Word16 bits_frame, /* i : bit budget */ + const Word16 bwidth, /* i : audio bandwidth */ + const Word32 total_brate, /* i : total bitrate */ + const Word16 L_frame_old /* i : frame length */ ); #endif // IVAS_FLOAT_FIXED -//er_utils_fx.c -void minimumStatistics_fx(Word16* noiseLevelMemory, /* Q15, internal state */ - Word16* noiseLevelIndex, /* Q0, internal state */ - Word16* currLevelIndex, /* Q0, internal state (circular buffer) */ - Word16* noiseEstimate, /* Q15, previous estimate of background noise */ - Word16* lastFrameLevel, /* Q15, level of the last frame */ - Word16 currentFrameLevel, /* Q15, level of the current frame */ - Word16* noiseLevelMemory_e, /* scaling factor for noiseLevelMemory */ - Word16 const noiseEstimate_e, /* exponent of noiseEstimate */ - Word16* new_noiseEstimate_e, /* new exponent of noise Estimate*/ - Word16* const lastFrameLevel_e, /* exponent of lastFrameLevel */ - Word16 currentFrameLevel_e); /* exponent of currentFrameLevel */ +// er_utils_fx.c +void minimumStatistics_fx( Word16 *noiseLevelMemory, /* Q15, internal state */ + Word16 *noiseLevelIndex, /* Q0, internal state */ + Word16 *currLevelIndex, /* Q0, internal state (circular buffer) */ + Word16 *noiseEstimate, /* Q15, previous estimate of background noise */ + Word16 *lastFrameLevel, /* Q15, level of the last frame */ + Word16 currentFrameLevel, /* Q15, level of the current frame */ + Word16 *noiseLevelMemory_e, /* scaling factor for noiseLevelMemory */ + Word16 const noiseEstimate_e, /* exponent of noiseEstimate */ + Word16 *new_noiseEstimate_e, /* new exponent of noise Estimate*/ + Word16 *const lastFrameLevel_e, /* exponent of lastFrameLevel */ + Word16 currentFrameLevel_e ); /* exponent of currentFrameLevel */ Word16 getLevelSynDeemph_fx( /*10Q5*/ - Word16 h1Init[], /* i: i value or vector to be processed */ /* Q15 */ - Word16 const A[], /* i: LPC coefficients */ /* Qx */ - Word16 const lpcorder, /* i: LPC order */ /* Q0 */ - Word16 const lenLpcExc, /* i: length of the LPC excitation buffer */ /* Q0 */ - Word16 const preemph_fac, /* i: preemphasis factor */ /* Q15 */ - Word16 const numLoops, /* i: number of loops */ /* Q0 */ - Word16 *Exp /* o: exponent of return value Q15 */ + Word16 h1Init[], + /* i: i value or vector to be processed */ /* Q15 */ + Word16 const A[], + /* i: LPC coefficients */ /* Qx */ + Word16 const lpcorder, + /* i: LPC order */ /* Q0 */ + Word16 const lenLpcExc, + /* i: length of the LPC excitation buffer */ /* Q0 */ + Word16 const preemph_fac, + /* i: preemphasis factor */ /* Q15 */ + Word16 const numLoops, + /* i: number of loops */ /* Q0 */ + Word16 *Exp /* o: exponent of return value Q15 */ ); void genPlcFiltBWAdap_fx( - Word32 const sr_core, /*mem_syn >rescaling done */ - , Word16 *pitch_buffer - , Word16 *voice_factors - , Word16 *bwe_exc -); + const Word16 A[], /*mem_syn >rescaling done */ + , + Word16 *pitch_buffer, + Word16 *voice_factors, + Word16 *bwe_exc ); #ifdef IVAS_FLOAT_FIXED -//dec_ace_fx.c +// dec_ace_fx.c void decoder_acelp_fx( - Decoder_State *st, - Word16 prm[], /* i : parameters */ - Word16 A[], /* i : coefficients NxAz[M+1] */ - ACELP_config acelp_cfg, /* i : ACELP config */ - Word16 synth[], /* i/o: synth[-2*LFAC..L_DIV] Q0 */ - Word16 *pT, /* out: pitch for all subframe Q0 */ - Word16 *pgainT, /* out: pitch gain for all subfr 1Q14 */ - Word16 stab_fac, /* i : stability of isf */ - Word16 *pitch_buffer, /* out: pitch values for each subfr.*/ - Word16 *voice_factors, /* out: voicing factors */ - const Word16 LSF_Q_prediction,/* i : LSF prediction mode */ - Word16 *bwe_exc /* out: excitation for SWB TBE */ + Decoder_State *st, + Word16 prm[], /* i : parameters */ + Word16 A[], /* i : coefficients NxAz[M+1] */ + ACELP_config acelp_cfg, /* i : ACELP config */ + Word16 synth[], /* i/o: synth[-2*LFAC..L_DIV] Q0 */ + Word16 *pT, /* out: pitch for all subframe Q0 */ + Word16 *pgainT, /* out: pitch gain for all subfr 1Q14 */ + Word16 stab_fac, /* i : stability of isf */ + Word16 *pitch_buffer, /* out: pitch values for each subfr.*/ + Word16 *voice_factors, /* out: voicing factors */ + const Word16 LSF_Q_prediction, /* i : LSF prediction mode */ + Word16 *bwe_exc /* out: excitation for SWB TBE */ ); #endif -//d_gain2p.c +// d_gain2p.c #ifdef IVAS_FLOAT_FIXED void decode_acelp_gains_fx( - Word16 *code, - Word16 gains_mode, - Word16 mean_ener_code, - Word16 *gain_pit, - Word32 *gain_code, - Word16 **pt_indice, - Word16 *past_gpit, - Word32 *past_gcode, - Word16 *gain_inov, - Word16 L_subfr, - Word16 *code2, - Word32 *gain_code2 -); + Word16 *code, + Word16 gains_mode, + Word16 mean_ener_code, + Word16 *gain_pit, + Word32 *gain_code, + Word16 **pt_indice, + Word16 *past_gpit, + Word32 *past_gcode, + Word16 *gain_inov, + Word16 L_subfr, + Word16 *code2, + Word32 *gain_code2 ); #endif void d_gain_pred_fx( - Word16 nrg_mode, /* i : NRG mode */ - Word16 *Es_pred, /* o : predicited scaled innovation energy */ - Word16 **pt_indice /* i/o: pointer to the buffer of indices */ + Word16 nrg_mode, /* i : NRG mode */ + Word16 *Es_pred, /* o : predicited scaled innovation energy */ + Word16 **pt_indice /* i/o: pointer to the buffer of indices */ ); -//acelp_core_dec_fx.c +// acelp_core_dec_fx.c ivas_error acelp_core_dec_fx( - Decoder_State* st_fx, /* i/o: decoder state structure */ - Word16 output[], /* o : synthesis @internal Fs */ - Word16 synth_out[], /* o : synthesis */ - Word16 save_hb_synth[], /* o : HB synthesis */ - Word32 bwe_exc_extended[], /* i/o: bandwidth extended excitation */ - Word16* voice_factors, /* o : voicing factors */ - Word16 old_syn_12k8_16k[], /* o : intermediate ACELP synthesis for SWB BWE */ - Word16 sharpFlag, - Word16 pitch_buf_fx[NB_SUBFR16k], /* o : floating pitch for each subframe */ - Word16* unbits, /* o : number of unused bits */ - Word16* sid_bw /* o : 0-NB/WB, 1-SWB SID */ - , STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle */ - const Word16 tdm_lspQ_PCh[M], /* i : Q LSPs for primary channel */ - const Word16 tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */ - const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ - const Word16 last_element_mode, /* i : last element mode */ - const Word32 last_element_brate, /* i : last element bitrate */ - const Word16 flag_sec_CNA, /* i : CNA flag for secondary channel */ - const Word16 nchan_out, /* i : number of output channels */ - STEREO_CNG_DEC_HANDLE hStereoCng, /* i : stereo CNG handle */ - const Word16 read_sid_info /* i : read SID info flag */ -); - -//evs_dec_fx.c + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 output[], /* o : synthesis @internal Fs */ + Word16 synth_out[], /* o : synthesis */ + Word16 save_hb_synth[], /* o : HB synthesis */ + Word32 bwe_exc_extended[], /* i/o: bandwidth extended excitation */ + Word16 *voice_factors, /* o : voicing factors */ + Word16 old_syn_12k8_16k[], /* o : intermediate ACELP synthesis for SWB BWE */ + Word16 sharpFlag, + Word16 pitch_buf_fx[NB_SUBFR16k], /* o : floating pitch for each subframe */ + Word16 *unbits, /* o : number of unused bits */ + Word16 *sid_bw /* o : 0-NB/WB, 1-SWB SID */ + , + STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle */ + const Word16 tdm_lspQ_PCh[M], /* i : Q LSPs for primary channel */ + const Word16 tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */ + const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ + const Word16 last_element_mode, /* i : last element mode */ + const Word32 last_element_brate, /* i : last element bitrate */ + const Word16 flag_sec_CNA, /* i : CNA flag for secondary channel */ + const Word16 nchan_out, /* i : number of output channels */ + STEREO_CNG_DEC_HANDLE hStereoCng, /* i : stereo CNG handle */ + const Word16 read_sid_info /* i : read SID info flag */ +); + +// evs_dec_fx.c ivas_error evs_dec_fx( - Decoder_State *st_fx, /* i/o : Decoder state structure */ - Word16 output_sp[], /* o : output synthesis signal */ - frameMode_fx frameMode /* i : Decoder frame mode */ + Decoder_State *st_fx, /* i/o : Decoder state structure */ + Word16 output_sp[], /* o : output synthesis signal */ + frameMode_fx frameMode /* i : Decoder frame mode */ ); void fft_cldfb_fx( - Word32 *data, /* i/o: input/output vector */ - const Word16 size /* size of fft operation */ + Word32 *data, /* i/o: input/output vector */ + const Word16 size /* size of fft operation */ ); void stereo_dft_dec_analyze_fx( @@ -9026,8 +8868,7 @@ void stereo_dft_dec_analyze_fx( const int16_t k_offset, /* i : offset of DFT */ const int16_t delay, /* i : delay in samples for input signal */ Word16 *q, - Word16 *q_DFT -); + Word16 *q_DFT ); void set32_fx( Word32 y[], /* i/o: Vector to set */ @@ -9043,7 +8884,7 @@ void delay_signal_fx( ); Word32 anint_fixed( - Word32 x, /* i: Round to the nearest integer */ + Word32 x, /* i: Round to the nearest integer */ Word16 exp /* i: Exponent for round step */ ); @@ -9056,41 +8897,42 @@ void v_add_fx( const Word32 x1[], /* i : Input vector 1 */ const Word32 x2[], /* i : Input vector 2 */ Word32 y[], /* o : Output vector that contains vector 1 + vector 2 */ - const int16_t N /* i : Vector length */ + const int16_t N /* i : Vector length */ ); void v_shr_16( - const Word16 x[], /* i : Input vector */ - const Word16 shift, /* i : Constant */ - Word16 y[], /* o : Output vector that contains x >> shift */ - const Word16 N /* i : Vector length */ + const Word16 x[], /* i : Input vector */ + const Word16 shift, /* i : Constant */ + Word16 y[], /* o : Output vector that contains x >> shift */ + const Word16 N /* i : Vector length */ ); void v_shr( - const Word32 x[], /* i : Input vector */ - const Word16 shift, /* i : Constant */ - Word32 y[], /* o : Output vector that contains x >> shift */ - const Word16 N /* i : Vector length */ + const Word32 x[], /* i : Input vector */ + const Word16 shift, /* i : Constant */ + Word32 y[], /* o : Output vector that contains x >> shift */ + const Word16 N /* i : Vector length */ ); void cldfbAnalysis_ts_fx( const Word32 *timeIn_fx, /* i : time buffer */ Word32 realBuffer_fx[CLDFB_NO_CHANNELS_MAX], /* o : real value buffer */ Word32 imagBuffer_fx[CLDFB_NO_CHANNELS_MAX], /* o : imag value buffer */ - const Word16 samplesToProcess, /* i : samples to process */ - HANDLE_CLDFB_FILTER_BANK h_cldfb , - Word16* q_cldfb -); -Word16 floor_log_2(Word32 num); + const Word16 samplesToProcess, /* i : samples to process */ + HANDLE_CLDFB_FILTER_BANK h_cldfb, + Word16 *q_cldfb ); +Word16 floor_log_2( Word32 num ); void cldfbAnalysis_ts_fx_fixed_q( - const Word32 *timeIn_fx, /* i : time buffer */ // q - Word32 realBuffer_fx[CLDFB_NO_CHANNELS_MAX], /* o : real value buffer */ // q - 5 - Word32 imagBuffer_fx[CLDFB_NO_CHANNELS_MAX], /* o : imag value buffer */ // q - 5 - const Word16 samplesToProcess, /* i : samples to process */ - HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i : filterbank state */ - Word16* q_cldfb -); + const Word32 *timeIn_fx, + /* i : time buffer */ // q + Word32 realBuffer_fx[CLDFB_NO_CHANNELS_MAX], + /* o : real value buffer */ // q - 5 + Word32 imagBuffer_fx[CLDFB_NO_CHANNELS_MAX], + /* o : imag value buffer */ // q - 5 + const Word16 samplesToProcess, /* i : samples to process */ + HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i : filterbank state */ + Word16 *q_cldfb ); void configureCldfb_ivas_fx( HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i/o: filter bank handle */ @@ -9133,9 +8975,9 @@ void bpf_pitch_coherence_ivas_fx( /* fft_rel.c */ -#define SIZE_256 256 -#define NUM_STAGE_256 7 -#define SIZE2_256 (SIZE_256/2) +#define SIZE_256 256 +#define NUM_STAGE_256 7 +#define SIZE2_256 ( SIZE_256 / 2 ) void cldfbAnalysis_ivas_fx( const Word32 *timeIn_fx, /* i : time buffer Qx */ @@ -9159,20 +9001,19 @@ void addBassPostFilter_ivas_fx( const int16_t samplesToProcess, Word32 **rAnalysis_fx, Word32 **iAnalysis_fx, - HANDLE_CLDFB_FILTER_BANK cldfb -); + HANDLE_CLDFB_FILTER_BANK cldfb ); Word32 ism_dequant_meta_fx( - const Word16 idx, /* i : quantizer index */ + const Word16 idx, /* i : quantizer index */ const Word32 borders_fx[], /* i : level borders */ const Word32 q_step_fx, /* i : quantization step */ const Word32 q_step_border_fx, /* i : quantization step at the border */ - const Word16 cbsize /* i : codebook size */ + const Word16 cbsize /* i : codebook size */ ); void save_synthesis_hq_fec_fx( Decoder_State *st, /* i/o: decoder state structure */ - const Word32 output_fx[], /* i : decoded synthesis */ + const Word32 output_fx[], /* i : decoded synthesis */ const Word16 output_frame, /* i : decoded synthesis */ CPE_DEC_HANDLE hCPE /* i : CPE decoder structure */ ); @@ -9194,60 +9035,57 @@ void ivas_get_stereo_panning_gains_fx( ivas_error openCldfb_ivas_fx( HANDLE_CLDFB_FILTER_BANK *h_cldfb, /* i/o: filter bank handle */ CLDFB_TYPE type, /* i : analysis or synthesis */ - const Word32 sampling_rate, /* i : sampling rate */ + const Word32 sampling_rate, /* i : sampling rate */ CLDFB_PROTOTYPE prototype /* i : CLDFB version (1.25ms/5ms delay) */ ); Word32 rand_gauss_fx( Word32 *x, Word16 *seed, - Word16 q -); + Word16 q ); void resampleCldfb_ivas_fx( HANDLE_CLDFB_FILTER_BANK hs, /* i/o: filter bank handle */ - const Word32 newSamplerate -); + const Word32 newSamplerate ); void generate_masking_noise_dirac_ivas_fx( - HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ - HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i : filterbank state */ - Word32 *tdBuffer_fx, /* i/o: time-domain signal, if NULL no LB-CNA */ - Word32 *Cldfb_RealBuffer_fx, /* o : CLDFD real buffer */ - Word32 *Cldfb_ImagBuffer_fx, /* o : CLDFD imaginary buffer */ - const Word16 slot_index, /* i : CLDFB slot index */ - const Word16 cna_flag, /* i : CNA flag for LB and HB */ - const Word16 fd_cng_flag, /* i : FD-CNG flag for HB */ - Word16 q_input, - Word16 *q_cldfb -); -//modif_fs/c + HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ + HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i : filterbank state */ + Word32 *tdBuffer_fx, /* i/o: time-domain signal, if NULL no LB-CNA */ + Word32 *Cldfb_RealBuffer_fx, /* o : CLDFD real buffer */ + Word32 *Cldfb_ImagBuffer_fx, /* o : CLDFD imaginary buffer */ + const Word16 slot_index, /* i : CLDFB slot index */ + const Word16 cna_flag, /* i : CNA flag for LB and HB */ + const Word16 fd_cng_flag, /* i : FD-CNG flag for HB */ + Word16 q_input, + Word16 *q_cldfb ); +// modif_fs/c void interpolate_3_over_2_allpass_32( - const Word32 *input, /* i : input signal */ - const int16_t len, /* i : number of input samples */ - Word32 *out, /* o : output signal */ - Word32 *mem /* i/o: memory */ + const Word32 *input, /* i : input signal */ + const int16_t len, /* i : number of input samples */ + Word32 *out, /* o : output signal */ + Word32 *mem /* i/o: memory */ ); void interpolate_3_over_1_allpass_32( - const Word32 *input, /* i : input signal */ - const int16_t len, /* i : number of input samples */ - Word32 *out, /* o : output signal */ - Word32 *mem /* i/o: memory */ + const Word32 *input, /* i : input signal */ + const int16_t len, /* i : number of input samples */ + Word32 *out, /* o : output signal */ + Word32 *mem /* i/o: memory */ ); void Decimate_allpass_steep_fx32( - const Word32 *in, /* i : input array of size N */ - Word32 *mem, /* i/o: memory */ - const Word16 N, /* i : number of input samples */ - Word32 *out /* o : output array of size N/2 */ + const Word32 *in, /* i : input array of size N */ + Word32 *mem, /* i/o: memory */ + const Word16 N, /* i : number of input samples */ + Word32 *out /* o : output array of size N/2 */ ); void Interpolate_allpass_steep_32( - const Word32 *in_fx, /* i : input array of size N */ - Word32 *mem_fx, /* i/o: memory */ - const int16_t N, /* i : number of input samples */ - Word32 *out_fx /* o : output array of size 2*N */ + const Word32 *in_fx, /* i : input array of size N */ + Word32 *mem_fx, /* i/o: memory */ + const int16_t N, /* i : number of input samples */ + Word32 *out_fx /* o : output array of size 2*N */ ); void IMDCT_fx( Word32 *x, Word16 x_e, Word16 *old_syn_overl, Word16 *syn_Overl_TDAC, Word16 *xn_buf, const Word16 *tcx_aldo_window_1, const PWord16 *tcx_aldo_window_1_trunc, const PWord16 *tcx_aldo_window_2, const PWord16 *tcx_mdct_window_half, const PWord16 *tcx_mdct_window_minimum, const PWord16 *tcx_mdct_window_trans, Word16 tcx_mdct_window_half_length, Word16 tcx_mdct_window_min_length, Word16 index, Word16 left_rect, Word16 tcx_offset, Word16 overlap, Word16 L_frame, Word16 L_frameTCX, Word16 L_spec_TCX5, Word16 L_frame_glob, Word16 frame_cnt, Word16 bfi, Word16 *old_out, Word16 *Q_old_wtda, Decoder_State *st, Word16 fullbandScale, Word16 *acelp_zir ); @@ -9282,7 +9120,7 @@ void IMDCT_ivas_fx( Decoder_State *st, const Word16 fullbandScale, Word16 *acelp_zir_fx, - Word16 q_win); + Word16 q_win ); void v_mult16_fixed( const Word16 x1[], /* i : Input vector 1 */ @@ -9302,7 +9140,7 @@ void configureFdCngDec_fx( Word32 sum2_f_16_fx( const Word16 *vec, /* i : input vector */ - const Word16 lvec /* i : length of input vector */ + const Word16 lvec /* i : length of input vector */ ); Word16 vq_dec_lvq_ivas_fx( @@ -9340,44 +9178,44 @@ void stereo_dft_dec_open( ); void ivas_bw_switching_pre_proc_fx( - Decoder_State *st, /* i/o: decoder state structure */ + Decoder_State *st, /* i/o: decoder state structure */ const Word32 last_element_brate, /* i : last element bitrate */ - const Word16 nchan_out /* i : number of output channels */, + const Word16 nchan_out /* i : number of output channels */, Word32 *old_syn_12k8_16k_fx, Word16 Q, - Word16 Q_audio -); + Word16 Q_audio ); uint32_t mvl2s_r( const Word32 x[], /* i : input vector */ const Word16 q, - int16_t y[], /* o : output vector */ - const int16_t n /* i : vector size */ + int16_t y[], /* o : output vector */ + const int16_t n /* i : vector size */ ); -void decoder_tcx_post_ivas_fx(Decoder_State *st_fx, - Word16 *synth, - Word16 *synthFB, - Word16 *A, - Word16 bfi, - Word16 MCT_flag -); +void decoder_tcx_post_ivas_fx( Decoder_State *st_fx, + Word16 *synth, + Word16 *synthFB, + Word16 *A, + Word16 bfi, + Word16 MCT_flag ); void con_tcx_ivas_fx( - Decoder_State *st, /* i/o: coder memory state */ - Word16 synth[], /* i/o: synth[] *//*Q0 */ - const Word16 coh, /* i : coherence of stereo signal */ - Word16 * noise_seed, /* i/o: noise seed for stereo */ - const Word16 only_left, /* i : TD-PLC only in left channel */ - const Word16* A_cng /* i : CNG LP filter coefficients */ + Decoder_State *st, /* i/o: coder memory state */ + Word16 synth[], + /* i/o: synth[] */ /*Q0 */ + const Word16 coh, /* i : coherence of stereo signal */ + Word16 *noise_seed, /* i/o: noise seed for stereo */ + const Word16 only_left, /* i : TD-PLC only in left channel */ + const Word16 *A_cng /* i : CNG LP filter coefficients */ ); void ivas_mdct_core_reconstruct_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *x_fx[][NB_DIV], /* i/o: synthesis @internal_FS */ // Q(q_x) - Word16 signal_outFB_fx[CPE_CHANNELS][L_FRAME_PLUS], /* o : synthesis @output_FS */ // e_sig + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 *x_fx[][NB_DIV], + /* i/o: synthesis @internal_FS */ // Q(q_x) + Word16 signal_outFB_fx[CPE_CHANNELS][L_FRAME_PLUS], + /* o : synthesis @output_FS */ // e_sig Word16 fUseTns[CPE_CHANNELS][NB_DIV], /* i : flage TNS enabled */ - const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0)*/ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0)*/ Word16 q_x, - Word16 e_sig -); + Word16 e_sig ); diff --git a/lib_com/pvq_com.c b/lib_com/pvq_com.c index 623f1da6e..cf8859c3c 100644 --- a/lib_com/pvq_com.c +++ b/lib_com/pvq_com.c @@ -753,8 +753,8 @@ uint32_t UL_inverse_float( { uint32_t UL_tmp; - *exp = norm_ul_float( UL_val ); /* aligned to BASOP */ - UL_tmp = UL_val << ( *exp ); /* Q32*/ + *exp = norm_ul_float( UL_val ); /* aligned to BASOP */ + UL_tmp = UL_val << ( *exp ); /* Q32*/ *exp = 32 + 31 - *exp; @@ -816,8 +816,8 @@ Word16 atan2_fx_flt( { return 25736; /* EVS_PI/2 in Q14 */ } - man = ratio_float( y, x, &expo ); /* man in Q14 */ - expo = sub( expo, ( 15 - 14 ) ); /* Now, man is considered in Q15 */ + man = ratio_float( y, x, &expo ); /* man in Q14 */ + expo = sub( expo, ( 15 - 14 ) ); /* Now, man is considered in Q15 */ arg = L_shr( (Word32) man, expo ); IF( L_shr( arg, 3 + 15 ) != 0 ) diff --git a/lib_com/pvq_com_fx.c b/lib_com/pvq_com_fx.c index 3fd4f8800..fe4842a05 100644 --- a/lib_com/pvq_com_fx.c +++ b/lib_com/pvq_com_fx.c @@ -2,73 +2,70 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ +#include "options.h" /* Compilation switches */ #include "prot_fx1.h" -#include "prot_fx2.h" /* Function prototypes */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ - /*! r: Approximate integer division for positive input using lookup table */ +/*! r: Approximate integer division for positive input using lookup table */ UWord32 intLimCDivPos_fx( UWord32 NUM, - Word16 DEN -) + Word16 DEN ) { UWord32 UL_ru, UL_rl; - Mpy_32_32_uu(UL_lshl(NUM, 1), intLimCDivInvDQ31[DEN], &UL_ru, &UL_rl); + Mpy_32_32_uu( UL_lshl( NUM, 1 ), intLimCDivInvDQ31[DEN], &UL_ru, &UL_rl ); return UL_ru; } /*! r: Approximate integer division for signed input using lookup table */ static Word32 intLimCDivSigned_fx( Word32 NUM, - Word16 DEN -) + Word16 DEN ) { Word32 L_tmp; - L_tmp = intLimCDivPos_fx( L_abs(NUM) , DEN); - if (NUM < 0) + L_tmp = intLimCDivPos_fx( L_abs( NUM ), DEN ); + if ( NUM < 0 ) { - L_tmp= L_negate(L_tmp); /* one op */ + L_tmp = L_negate( L_tmp ); /* one op */ } return L_tmp; } /*! r: Approximate integer division for negative input */ -Word16 shrtCDivSignedApprox( - const Word16 num, - const Word16 den -) +Word16 shrtCDivSignedApprox( + const Word16 num, + const Word16 den ) { Word16 pool_part; - pool_part = extract_h( L_mult( negate(abs_s(num)), lim_neg_inv_tbl_fx[den] )); + pool_part = extract_h( L_mult( negate( abs_s( num ) ), lim_neg_inv_tbl_fx[den] ) ); /* neg_in always, positive out always, so that positive truncation(rounding) is used */ if ( num < 0 ) { - pool_part = negate(pool_part); /* make negative, one op */ + pool_part = negate( pool_part ); /* make negative, one op */ } return pool_part; } -static void nearProjQ15_fx( - const Word16 x, /* i : input coefficient */ - Word16* result /* o : projection */ +static void nearProjQ15_fx( + const Word16 x, /* i : input coefficient */ + Word16 *result /* o : projection */ ) { - const Word16 a[4] = {14967, -25518, 3415, 32351}; + const Word16 a[4] = { 14967, -25518, 3415, 32351 }; Word32 b; UWord16 lsb; - b = L_deposit_l(a[0]); - b = L_shl((Word32)add(a[1], extract_h(L_mult0((Word16)b, x))), 1); - Mpy_32_16_ss(b, x, &b, &lsb); - b = L_add((Word32)a[2], b); - Mpy_32_16_ss(b, x, &b, &lsb); - b = L_add((Word32)a[3], b); - *result = extract_l(b); - return ; + b = L_deposit_l( a[0] ); + b = L_shl( (Word32) add( a[1], extract_h( L_mult0( (Word16) b, x ) ) ), 1 ); + Mpy_32_16_ss( b, x, &b, &lsb ); + b = L_add( (Word32) a[2], b ); + Mpy_32_16_ss( b, x, &b, &lsb ); + b = L_add( (Word32) a[3], b ); + *result = extract_l( b ); + return; } /*-------------------------------------------------------------------* @@ -77,29 +74,29 @@ static void nearProjQ15_fx( * *-------------------------------------------------------------------*/ void obtainEnergyQuantizerDensity_fx( - const Word16 L, /* i : left vector energy */ - const Word16 R, /* i : right vector energy */ - Word16* Density /* o : quantizer density */ + const Word16 L, /* i : left vector energy */ + const Word16 R, /* i : right vector energy */ + Word16 *Density /* o : quantizer density */ ) { Word16 Rnrg, den, n; - den = sub(shl(L, 1), 1); + den = sub( shl( L, 1 ), 1 ); IF( den <= 67 ) { - Rnrg = extract_l(intLimCDivPos_fx( L_deposit_l(R) , den)); + Rnrg = extract_l( intLimCDivPos_fx( L_deposit_l( R ), den ) ); } ELSE { - n = norm_s(den); - Rnrg = shr(div_s(R, shl(den, n)), sub(15, n)); + n = norm_s( den ); + Rnrg = shr( div_s( R, shl( den, n ) ), sub( 15, n ) ); } - Rnrg = add(Rnrg, 28); + Rnrg = add( Rnrg, 28 ); - Rnrg = s_min(Rnrg, 56); - Rnrg = s_min(Rnrg, sub(R, 96)); + Rnrg = s_min( Rnrg, 56 ); + Rnrg = s_min( Rnrg, sub( R, 96 ) ); - Rnrg = s_max(Rnrg, 3); + Rnrg = s_max( Rnrg, 3 ); *Density = obtainEnergyQuantizerDensity_f[Rnrg]; return; } @@ -110,9 +107,9 @@ void obtainEnergyQuantizerDensity_fx( * * *-------------------------------------------------------------------*/ -void dsDirac2Dirac_fx( - const Word16 dsDiracIndex, /* i : input index */ - Word16* diracs /* o : number of diracs */ +void dsDirac2Dirac_fx( + const Word16 dsDiracIndex, /* i : input index */ + Word16 *diracs /* o : number of diracs */ ) { *diracs = dsDiracsTab[dsDiracIndex]; @@ -120,11 +117,11 @@ void dsDirac2Dirac_fx( } void dsDiracPerQuanta_fx( - const Word16 td, /* i : Length of vector segment */ - const Word16 t_quanta, /* i : Assigned number of quanta */ - const Word16 dsm, /* i : Conservative rounding flag */ - const unsigned char* const* frQuanta, /* i : Quanta lookup table */ - Word16* DsIdx /* o : Lookup table index */ + const Word16 td, /* i : Length of vector segment */ + const Word16 t_quanta, /* i : Assigned number of quanta */ + const Word16 dsm, /* i : Conservative rounding flag */ + const unsigned char *const *frQuanta, /* i : Quanta lookup table */ + Word16 *DsIdx /* o : Lookup table index */ ) { const unsigned char *sv; @@ -136,74 +133,75 @@ void dsDiracPerQuanta_fx( sv = frQuanta[td]; nsv = sv[0]; - t_quanta_o = sub(t_quanta, QUANTAQ3OFFSET); + t_quanta_o = sub( t_quanta, QUANTAQ3OFFSET ); - IF (GE_16(t_quanta_o, sv[nsv])) + IF( GE_16( t_quanta_o, sv[nsv] ) ) { *DsIdx = nsv; move16(); - return ; + return; } - IF (LE_16(t_quanta_o, sv[1])) + IF( LE_16( t_quanta_o, sv[1] ) ) { *DsIdx = 1; move16(); - return ; + return; } - dsIndex = shl(1, frQuanta[0][td]); - if (GT_16(t_quanta_o, sv[shr(nsv, 1) ])) + dsIndex = shl( 1, frQuanta[0][td] ); + if ( GT_16( t_quanta_o, sv[shr( nsv, 1 )] ) ) { - dsIndex = sub(nsv, dsIndex ); + dsIndex = sub( nsv, dsIndex ); } - FOR (i = sub(frQuanta[0][td], 1); i >= 0; i--) + FOR( i = sub( frQuanta[0][td], 1 ); i >= 0; i-- ) { - dsIndex = add(dsIndex, shl(sub(shl(lshr(sub(sv[dsIndex], t_quanta_o), 15), 1), 1), i)); + dsIndex = add( dsIndex, shl( sub( shl( lshr( sub( sv[dsIndex], t_quanta_o ), 15 ), 1 ), 1 ), i ) ); } - dsIndex = add(dsIndex, lshr(sub(sv[dsIndex], t_quanta_o), 15)); - dsIndex = sub(dsIndex, lshr(sub(1, dsIndex), 15)); + dsIndex = add( dsIndex, lshr( sub( sv[dsIndex], t_quanta_o ), 15 ) ); + dsIndex = sub( dsIndex, lshr( sub( 1, dsIndex ), 15 ) ); - IF (EQ_16(dsm, PVQ_CONS)) + IF( EQ_16( dsm, PVQ_CONS ) ) { - *DsIdx=dsIndex; + *DsIdx = dsIndex; move16(); return; } - *DsIdx = add(dsIndex, lshr(sub(add(sv[add(dsIndex,1)], sv[dsIndex]), shl(t_quanta_o, 1)), 15)); + *DsIdx = add( dsIndex, lshr( sub( add( sv[add( dsIndex, 1 )], sv[dsIndex] ), shl( t_quanta_o, 1 ) ), 15 ) ); return; } void QuantaPerDsDirac_fx( - const Word16 td, /* i : Length of vector segment */ - const Word16 dsDiracIndex, /* i : Quanta table index */ - const unsigned char* const* dimFrQuanta, /* i : Quanta lookup table */ - Word16* Quanta /* i : Quanta */ + const Word16 td, /* i : Length of vector segment */ + const Word16 dsDiracIndex, /* i : Quanta table index */ + const unsigned char *const *dimFrQuanta, /* i : Quanta lookup table */ + Word16 *Quanta /* i : Quanta */ ) { *Quanta = dimFrQuanta[td][dsDiracIndex]; move16(); - if(dsDiracIndex == 0) + if ( dsDiracIndex == 0 ) { - *Quanta = -1; /* single op */ move16(); + *Quanta = -1; /* single op */ + move16(); } - *Quanta = add(*Quanta, QUANTAQ3OFFSET); - return ; + *Quanta = add( *Quanta, QUANTAQ3OFFSET ); + return; } void conservativeL1Norm_fx( - const Word16 L, /* i : Length of vector segment */ - const Word16 Qvec, /* i : Assigned number of quanta */ - const Word16 Fcons, /* i : Conservative rounding flag */ - const Word16 Qavail, /* i : Input quanta remaining */ - const Word16 Qreserv, /* i : Input quanta in reservoir */ - const Word16 Dspec, /* i : assigned diracs from bitalloc */ - Word16* Dvec, /* o : actual number of diracs */ - Word16* Qspare, /* o : Output quanta remaining */ - Word16* Qreservplus, /* o : Output quanta in reservoir */ - Word16* Dspecplus /* o : Output number of diracs */ + const Word16 L, /* i : Length of vector segment */ + const Word16 Qvec, /* i : Assigned number of quanta */ + const Word16 Fcons, /* i : Conservative rounding flag */ + const Word16 Qavail, /* i : Input quanta remaining */ + const Word16 Qreserv, /* i : Input quanta in reservoir */ + const Word16 Dspec, /* i : assigned diracs from bitalloc */ + Word16 *Dvec, /* o : actual number of diracs */ + Word16 *Qspare, /* o : Output quanta remaining */ + Word16 *Qreservplus, /* o : Output quanta in reservoir */ + Word16 *Dspecplus /* o : Output number of diracs */ ) { @@ -211,191 +209,189 @@ void conservativeL1Norm_fx( Word16 Qtestminus; const unsigned char *frQuantaL; - frQuantaL = hBitsN[L]; + frQuantaL = hBitsN[L]; - *Qreservplus = add(Qreserv, sub(Qvec, QUANTAQ3OFFSET)); + *Qreservplus = add( Qreserv, sub( Qvec, QUANTAQ3OFFSET ) ); - dsDiracPerQuanta_fx(L, Qvec, Fcons, hBitsN, &Minit); + dsDiracPerQuanta_fx( L, Qvec, Fcons, hBitsN, &Minit ); Mprime = Minit; move16(); DO { - Qtestminus = (short)frQuantaL[Mprime]; + Qtestminus = (short) frQuantaL[Mprime]; move16(); - *Qspare = sub(Qavail, Qtestminus); - Mprime = sub(Mprime, 1); + *Qspare = sub( Qavail, Qtestminus ); + Mprime = sub( Mprime, 1 ); } - WHILE ( (Mprime >= 0) && LT_16(*Qspare, QUANTAQ3OFFSET )); + WHILE( ( Mprime >= 0 ) && LT_16( *Qspare, QUANTAQ3OFFSET ) ); - if(Mprime < 0) + if ( Mprime < 0 ) { - *Qspare = add(Qavail, QUANTAQ3OFFSET); /* single op */ + *Qspare = add( Qavail, QUANTAQ3OFFSET ); /* single op */ } - dsDirac2Dirac_fx(add(Mprime, 1), Dvec); + dsDirac2Dirac_fx( add( Mprime, 1 ), Dvec ); - *Dspecplus = add(Dspec, *Dvec); - *Qreservplus = sub(*Qreservplus, (short)frQuantaL[Minit]); - *Qspare = sub(*Qspare, QUANTAQ3OFFSET); + *Dspecplus = add( Dspec, *Dvec ); + *Qreservplus = sub( *Qreservplus, (short) frQuantaL[Minit] ); + *Qspare = sub( *Qspare, QUANTAQ3OFFSET ); return; } - - - void bandBitsAdjustment_fx( - const Word16 Brc, /* i : Current number of read quanta in range coder */ - const UWord32 INTrc, /* i : Range coder state */ - const Word16 Bavail, /* i : Available number of quanta */ - const Word16 Nbands, /* i : Number of bands */ - const Word16 D, /* i : Remaining number of bands to encode */ - const Word16 L, /* i : Size of current band */ - const Word16 Bband, /* i : Quanta allocation for current band */ - const Word16 Breserv, /* i : Quanta reservoir */ - Word16* Bband_adj, /* o : Actual used number of quanta */ - Word16* Brem, /* o : Quanta remaining */ - Word16* Breservplus /* o : Quanta pool size */ + const Word16 Brc, /* i : Current number of read quanta in range coder */ + const UWord32 INTrc, /* i : Range coder state */ + const Word16 Bavail, /* i : Available number of quanta */ + const Word16 Nbands, /* i : Number of bands */ + const Word16 D, /* i : Remaining number of bands to encode */ + const Word16 L, /* i : Size of current band */ + const Word16 Bband, /* i : Quanta allocation for current band */ + const Word16 Breserv, /* i : Quanta reservoir */ + Word16 *Bband_adj, /* o : Actual used number of quanta */ + Word16 *Brem, /* o : Quanta remaining */ + Word16 *Breservplus /* o : Quanta pool size */ ) { Word16 Btemp; Word16 Bff; Word32 L_tmp; - rangeCoderFinalizationFBits_fx(Brc, INTrc, &Bff); + rangeCoderFinalizationFBits_fx( Brc, INTrc, &Bff ); - IF(LT_16(D, Nbands)) + IF( LT_16( D, Nbands ) ) { - L_tmp = L_deposit_l(sub(Breserv, Bff)); - Btemp = extract_l(intLimCDivSigned_fx(L_tmp, s_min(D, 3))); /* result always fits in Word16 */ - *Breservplus = add(Bband, Breserv); + L_tmp = L_deposit_l( sub( Breserv, Bff ) ); + Btemp = extract_l( intLimCDivSigned_fx( L_tmp, s_min( D, 3 ) ) ); /* result always fits in Word16 */ + *Breservplus = add( Bband, Breserv ); } ELSE { - Btemp = 0; + Btemp = 0; move16(); - *Breservplus = add(Bband, Bff); + *Breservplus = add( Bband, Bff ); } - *Bband_adj = s_min(extract_l(L_mult(L, 40)), Bband); - *Brem = sub(Bavail, Bff); - *Bband_adj = s_min(*Brem, add(*Bband_adj, Btemp)); - *Bband_adj = s_max(0, *Bband_adj); + *Bband_adj = s_min( extract_l( L_mult( L, 40 ) ), Bband ); + *Brem = sub( Bavail, Bff ); + *Bband_adj = s_min( *Brem, add( *Bband_adj, Btemp ) ); + *Bband_adj = s_max( 0, *Bband_adj ); return; } - -static Word16 Ratio_base2Q11_fx( /* o : Q11 */ - const Word16 opp, /* i : opposite Q15 */ - const Word16 near /* i : near Q15 */ +static Word16 Ratio_base2Q11_fx( /* o : Q11 */ + const Word16 opp, /* i : opposite Q15 */ + const Word16 near /* i : near Q15 */ ) { Word16 mc, nc, ms, ns, d, z; Word16 result; Word32 acc; - ns = norm_s(opp ); /* exponent */ - nc = norm_s(near ); /* exponent */ + ns = norm_s( opp ); /* exponent */ + nc = norm_s( near ); /* exponent */ - ms = shl(opp, ns); /* mantissa */ - mc = shl(near, nc); /* mantissa */ + ms = shl( opp, ns ); /* mantissa */ + mc = shl( near, nc ); /* mantissa */ - acc = L_mac(538500224L, mc, -2776); /* a0*mc + a1, acc(Q27), a0(Q11), a1(Q27) */ - z = mac_r(acc, ms, -2776); /* z in Q11, a0 in Q11 */ - d = sub(ms, mc); /* d in Q15 */ - z = mult_r(z, d); /* z in Q11 */ + acc = L_mac( 538500224L, mc, -2776 ); /* a0*mc + a1, acc(Q27), a0(Q11), a1(Q27) */ + z = mac_r( acc, ms, -2776 ); /* z in Q11, a0 in Q11 */ + d = sub( ms, mc ); /* d in Q15 */ + z = mult_r( z, d ); /* z in Q11 */ - result = add(z, shl(sub(nc, ns), 11)); + result = add( z, shl( sub( nc, ns ), 11 ) ); return result; } -static void Ratio_rQ3_fx( - Word16 opp, /* i : opposite */ - Word16 near, /* i : near */ - Word16* result /* o : ratio */ +static void Ratio_rQ3_fx( + Word16 opp, /* i : opposite */ + Word16 near, /* i : near */ + Word16 *result /* o : ratio */ ) { Word16 tmp; - tmp = add(1<<7 , Ratio_base2Q11_fx(opp, near)); - *result = shr(tmp, 8); - return ; + tmp = add( 1 << 7, Ratio_base2Q11_fx( opp, near ) ); + *result = shr( tmp, 8 ); + return; } void densityAngle2RmsProjDec_fx( - const Word16 D, /* i : density */ - const Word16 indexphi, /* i : decoded index from AR dec */ - Word16* oppQ15, /* o : opposite */ - Word16* nearQ15, /* o : near */ - Word16* oppRatioQ3 /* o : ratio */ + const Word16 D, /* i : density */ + const Word16 indexphi, /* i : decoded index from AR dec */ + Word16 *oppQ15, /* o : opposite */ + Word16 *nearQ15, /* o : near */ + Word16 *oppRatioQ3 /* o : ratio */ ) { Word16 phiQ14q; Word16 oppTail, nearTail; - phiQ14q = (Word16)intLimCDivPos_fx(L_shl(L_deposit_l(indexphi), 13), shr(D, 1)); - if (indexphi < 0) + phiQ14q = (Word16) intLimCDivPos_fx( L_shl( L_deposit_l( indexphi ), 13 ), shr( D, 1 ) ); + if ( indexphi < 0 ) { - phiQ14q = 1 << 13; /* one op */ move16(); + phiQ14q = 1 << 13; /* one op */ + move16(); } - oppTail = shr(sub(16320, phiQ14q), 15); - nearTail = shr(sub(phiQ14q, 64), 15); + oppTail = shr( sub( 16320, phiQ14q ), 15 ); + nearTail = shr( sub( phiQ14q, 64 ), 15 ); - IF (s_or(oppTail, nearTail) < 0) + IF( s_or( oppTail, nearTail ) < 0 ) { - *oppQ15 = s_and(oppTail, (1 << 15) - 1); - *nearQ15 = s_and(nearTail, (1 << 15) - 1); - *oppRatioQ3 = shl(add(1, shl(nearTail, 1)), 14); + *oppQ15 = s_and( oppTail, ( 1 << 15 ) - 1 ); + *nearQ15 = s_and( nearTail, ( 1 << 15 ) - 1 ); + *oppRatioQ3 = shl( add( 1, shl( nearTail, 1 ) ), 14 ); } ELSE { - nearProjQ15_fx( shl(sub(1 << 14, phiQ14q), 1), oppQ15); - nearProjQ15_fx(shl(phiQ14q, 1), nearQ15); - Ratio_rQ3_fx(*oppQ15, *nearQ15, oppRatioQ3); + nearProjQ15_fx( shl( sub( 1 << 14, phiQ14q ), 1 ), oppQ15 ); + nearProjQ15_fx( shl( phiQ14q, 1 ), nearQ15 ); + Ratio_rQ3_fx( *oppQ15, *nearQ15, oppRatioQ3 ); } return; } void densityAngle2RmsProjEnc_fx( - const Word16 D, /* i : density */ - const Word16 phiQ14uq, /* i : angle */ - Word16* indexphi, /* o : index */ - Word16* oppQ15, /* o : opposite */ - Word16* nearQ15, /* o : near */ - Word16* oppRatioQ3 /* o : ratio */ + const Word16 D, /* i : density */ + const Word16 phiQ14uq, /* i : angle */ + Word16 *indexphi, /* o : index */ + Word16 *oppQ15, /* o : opposite */ + Word16 *nearQ15, /* o : near */ + Word16 *oppRatioQ3 /* o : ratio */ ) { - *indexphi = mult_r(shl(D, 1), phiQ14uq); - if (s_and(D, 1) > 0) + *indexphi = mult_r( shl( D, 1 ), phiQ14uq ); + if ( s_and( D, 1 ) > 0 ) { - *indexphi = -1; /* one op */ move16(); + *indexphi = -1; /* one op */ + move16(); } - densityAngle2RmsProjDec_fx(D, *indexphi, oppQ15, nearQ15, oppRatioQ3); + densityAngle2RmsProjDec_fx( D, *indexphi, oppQ15, nearQ15, oppRatioQ3 ); return; } void NearOppSplitAdjustment_fx( - const Word16 qband, /* i : quanta for current band */ - const Word16 qzero, /* i : range coder finalization quanta */ - const Word16 Qac, /* i : range coder current quanta */ - const UWord32 INTac, /* i : range coder state */ - const Word16 qglobal, /* i : quanta input */ - const Word16 FlagCons, /* i : conservative rounding flag */ - const Word16 Np, /* i : number of parts */ - const Word16 Nhead, /* i : first part */ - const Word16 Ntail, /* i : remaining parts */ - const Word16 Nnear, /* i : length of near component */ - const Word16 Nopp, /* i : length of opposite component */ - Word16 oppRQ3, /* i : ratio */ - Word16* qnear, /* o : quantized near */ - Word16* qopp, /* o : quantized opposite */ - Word16* qglobalupd /* o : quanta remaining */ + const Word16 qband, /* i : quanta for current band */ + const Word16 qzero, /* i : range coder finalization quanta */ + const Word16 Qac, /* i : range coder current quanta */ + const UWord32 INTac, /* i : range coder state */ + const Word16 qglobal, /* i : quanta input */ + const Word16 FlagCons, /* i : conservative rounding flag */ + const Word16 Np, /* i : number of parts */ + const Word16 Nhead, /* i : first part */ + const Word16 Ntail, /* i : remaining parts */ + const Word16 Nnear, /* i : length of near component */ + const Word16 Nopp, /* i : length of opposite component */ + Word16 oppRQ3, /* i : ratio */ + Word16 *qnear, /* o : quantized near */ + Word16 *qopp, /* o : quantized opposite */ + Word16 *qglobalupd /* o : quanta remaining */ ) { @@ -406,40 +402,40 @@ void NearOppSplitAdjustment_fx( Flag Overflow = 0; #endif - rangeCoderFinalizationFBits_fx(Qac, INTac, &qac); - qboth = sub(qband, sub(qac, qzero)); + rangeCoderFinalizationFBits_fx( Qac, INTac, &qac ); + qboth = sub( qband, sub( qac, qzero ) ); /* skew calc code */ - qskew = 0 ; + qskew = 0; move16(); - IF (GT_16(Nhead, 1)) + IF( GT_16( Nhead, 1 ) ) { - qavg = extract_h(L_shl(intLimCDivSigned_fx((Word32)qboth, Np),16)); /* qboth may be negative */ - dsDiracPerQuanta_fx(Ntail, qavg, FlagCons, hBitsN, &Midx ); - QuantaPerDsDirac_fx(Nhead, Midx, hBitsN, &qmin); - qskew = sub(qavg, qmin); - qskew = s_max(0, qskew); - } /* end of skew calc code*/ - - QIa = add(extract_l(intLimCDivPos_fx((UWord32)L_deposit_l(Nopp), Nnear)), 1); /* always positive Word16 out */ - L_qnum = L_sub( L_deposit_l(sub(sub(add(qband, qzero), qac), qskew)), L_mult0(Nopp, oppRQ3)); - - L_QIb = L_deposit_l(0); - IF (L_qnum > 0) + qavg = extract_h( L_shl( intLimCDivSigned_fx( (Word32) qboth, Np ), 16 ) ); /* qboth may be negative */ + dsDiracPerQuanta_fx( Ntail, qavg, FlagCons, hBitsN, &Midx ); + QuantaPerDsDirac_fx( Nhead, Midx, hBitsN, &qmin ); + qskew = sub( qavg, qmin ); + qskew = s_max( 0, qskew ); + } /* end of skew calc code*/ + + QIa = add( extract_l( intLimCDivPos_fx( (UWord32) L_deposit_l( Nopp ), Nnear ) ), 1 ); /* always positive Word16 out */ + L_qnum = L_sub( L_deposit_l( sub( sub( add( qband, qzero ), qac ), qskew ) ), L_mult0( Nopp, oppRQ3 ) ); + + L_QIb = L_deposit_l( 0 ); + IF( L_qnum > 0 ) { - L_QIb = (Word32) intLimCDivPos_fx(L_qnum, QIa); + L_QIb = (Word32) intLimCDivPos_fx( L_qnum, QIa ); } - *qnear = qboth; + *qnear = qboth; #ifdef BASOP_NOGLOB - QIb = extract_h(L_shl_o(L_QIb, 16, &Overflow)); /* may saturate */ + QIb = extract_h( L_shl_o( L_QIb, 16, &Overflow ) ); /* may saturate */ #else - QIb = extract_h(L_shl(L_QIb, 16)); /* may saturate */ + QIb = extract_h( L_shl( L_QIb, 16 ) ); /* may saturate */ #endif - if (LE_16(QIb, qboth)) + if ( LE_16( QIb, qboth ) ) { *qnear = QIb; } - *qopp = sub(qboth, *qnear); - *qglobalupd = sub(qglobal, sub(qac, qzero)); + *qopp = sub( qboth, *qnear ); + *qglobalupd = sub( qglobal, sub( qac, qzero ) ); return; } @@ -452,26 +448,26 @@ void NearOppSplitAdjustment_fx( *--------------------------------------------------------------------------*/ void apply_gain_fx( - const Word16 *ord, /* i : Indices for energy order */ - const Word16 *band_start, /* i : Sub band start indices */ - const Word16 *band_end, /* i : Sub band end indices */ - const Word16 num_sfm, /* i : Number of bands */ - const Word16 *gains, /* i : Band gain vector Q12 */ - Word16 *xq /* i/o: Float synthesis / Gain adjusted synth Q15/Q12 */ + const Word16 *ord, /* i : Indices for energy order */ + const Word16 *band_start, /* i : Sub band start indices */ + const Word16 *band_end, /* i : Sub band end indices */ + const Word16 num_sfm, /* i : Number of bands */ + const Word16 *gains, /* i : Band gain vector Q12 */ + Word16 *xq /* i/o: Float synthesis / Gain adjusted synth Q15/Q12 */ ) { - Word16 band,i; - Word16 g; /* Q12 */ + Word16 band, i; + Word16 g; /* Q12 */ - FOR ( band = 0; band < num_sfm; band++) + FOR( band = 0; band < num_sfm; band++ ) { g = gains[ord[band]]; - FOR( i = band_start[band]; i < band_end[band]; i++) + FOR( i = band_start[band]; i < band_end[band]; i++ ) { /*xq[i] *= g; */ - xq[i] = mult_r(g, xq[i]); - move16(); /*12+15+1-16=12 */ + xq[i] = mult_r( g, xq[i] ); + move16(); /*12+15+1-16=12 */ } } @@ -486,17 +482,17 @@ void apply_gain_fx( void fine_gain_quant_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 *ord, /* i : Indices for energy order */ - const Word16 num_sfm, /* i : Number of bands */ - const Word16 *gain_bits, /* i : Gain adjustment bits per sub band */ - Word16 *fg_pred, /* i/o: Predicted gains / Corrected gains Q12 */ - const Word16 *gopt /* i : Optimal gains Q12 */ + const Word16 *ord, /* i : Indices for energy order */ + const Word16 num_sfm, /* i : Number of bands */ + const Word16 *gain_bits, /* i : Gain adjustment bits per sub band */ + Word16 *fg_pred, /* i/o: Predicted gains / Corrected gains Q12 */ + const Word16 *gopt /* i : Optimal gains Q12 */ ) { Word16 band; Word16 gbits; Word16 idx; - Word16 gain_db,gain_dbq; + Word16 gain_db, gain_dbq; Word16 err; Word16 tmp1, tmp2, exp1, exp2; @@ -506,43 +502,43 @@ void fine_gain_quant_fx( Flag Overflow = 0; #endif - FOR ( band = 0; band < num_sfm; band++) + FOR( band = 0; band < num_sfm; band++ ) { gbits = gain_bits[ord[band]]; test(); - IF ( fg_pred[band] != 0 && gbits > 0 ) + IF( fg_pred[band] != 0 && gbits > 0 ) { - exp1 = norm_s(gopt[band]); - exp1 = sub(exp1, 1); - tmp1 = shl(gopt[band], exp1); - exp2 = norm_s(fg_pred[band]); - tmp2 = shl(fg_pred[band], exp2); - exp1 = add(15, sub(exp1, exp2)); - err = div_s(tmp1, tmp2); - tmp1 = norm_s(err); - exp2 = Log2_norm_lc(L_deposit_h(shl(err, tmp1))); - tmp1 = sub(14, tmp1); - tmp1 = sub(tmp1, exp1); - L_tmp = L_Comp(tmp1, exp2); - Mpy_32_16_ss(L_tmp, 24660, &L_tmp, &lsb); /* 24660 = 20*log10(2) in Q12 */ /*16+12-15=13 */ + exp1 = norm_s( gopt[band] ); + exp1 = sub( exp1, 1 ); + tmp1 = shl( gopt[band], exp1 ); + exp2 = norm_s( fg_pred[band] ); + tmp2 = shl( fg_pred[band], exp2 ); + exp1 = add( 15, sub( exp1, exp2 ) ); + err = div_s( tmp1, tmp2 ); + tmp1 = norm_s( err ); + exp2 = Log2_norm_lc( L_deposit_h( shl( err, tmp1 ) ) ); + tmp1 = sub( 14, tmp1 ); + tmp1 = sub( tmp1, exp1 ); + L_tmp = L_Comp( tmp1, exp2 ); + Mpy_32_16_ss( L_tmp, 24660, &L_tmp, &lsb ); /* 24660 = 20*log10(2) in Q12 */ /*16+12-15=13 */ #ifdef BASOP_NOGLOB - gain_db = round_fx_sat(L_shl_o(L_tmp, 17, &Overflow)); + gain_db = round_fx_sat( L_shl_o( L_tmp, 17, &Overflow ) ); #else /* BASOP_NOGLOB */ - gain_db = round_fx(L_shl(L_tmp, 17)); + gain_db = round_fx( L_shl( L_tmp, 17 ) ); #endif - idx = squant_fx(gain_db, &gain_dbq, finegain_fx[gbits-1], gain_cb_size[gbits-1]); + idx = squant_fx( gain_db, &gain_dbq, finegain_fx[gbits - 1], gain_cb_size[gbits - 1] ); push_indice_fx( hBstr, IND_PVQ_FINE_GAIN, idx, gbits ); - L_tmp = L_mult0(gain_dbq, 21771); /* 21771=0.05*log2(10) */ /* 14+17=31 */ - L_tmp = L_shr(L_tmp, 15); - tmp1 = L_Extract_lc(L_tmp, &exp1); - tmp1 = abs_s(tmp1); - tmp1 = extract_l(Pow2(14, tmp1)); - exp1 = sub(14, exp1); + L_tmp = L_mult0( gain_dbq, 21771 ); /* 21771=0.05*log2(10) */ /* 14+17=31 */ + L_tmp = L_shr( L_tmp, 15 ); + tmp1 = L_Extract_lc( L_tmp, &exp1 ); + tmp1 = abs_s( tmp1 ); + tmp1 = extract_l( Pow2( 14, tmp1 ) ); + exp1 = sub( 14, exp1 ); - L_tmp = L_mult0(fg_pred[band], tmp1); /*12+exp1 */ - fg_pred[band] = round_fx(L_shl(L_tmp, sub(16, exp1))); /*12+exp1+16-exp1-16=12 */ + L_tmp = L_mult0( fg_pred[band], tmp1 ); /*12+exp1 */ + fg_pred[band] = round_fx( L_shl( L_tmp, sub( 16, exp1 ) ) ); /*12+exp1+16-exp1-16=12 */ } } @@ -555,43 +551,42 @@ void fine_gain_quant_fx( * sort vector and save sorting indeces *-------------------------------------------------------------------*/ -void srt_vec_ind16_fx ( - const Word16 *linear,/* linear input */ - Word16 *srt, /* sorted output*/ - Word16 *I, /* index for sorted output */ - Word16 length -) +void srt_vec_ind16_fx( + const Word16 *linear, /* linear input */ + Word16 *srt, /* sorted output*/ + Word16 *I, /* index for sorted output */ + Word16 length ) { - Word16 pos,npos; + Word16 pos, npos; Word16 idxMem; Word16 valMem; /*initilize */ - FOR (pos = 0; pos < length; pos++) + FOR( pos = 0; pos < length; pos++ ) { I[pos] = pos; move16(); } - Copy(linear, srt,length); + Copy( linear, srt, length ); /* now iterate */ - FOR (pos = 0; pos < (length - 1); pos++) + FOR( pos = 0; pos < ( length - 1 ); pos++ ) { - FOR (npos = (pos + 1); npos < length; npos++) + FOR( npos = ( pos + 1 ); npos < length; npos++ ) { - IF (LT_16(srt[npos], srt[pos])) + IF( LT_16( srt[npos], srt[pos] ) ) { - idxMem = I[pos]; + idxMem = I[pos]; move16(); - I[pos] = I[npos]; + I[pos] = I[npos]; move16(); - I[npos] = idxMem; + I[npos] = idxMem; move16(); - valMem = srt[pos]; + valMem = srt[pos]; move16(); - srt[pos] = srt[npos]; + srt[pos] = srt[npos]; move16(); srt[npos] = valMem; move16(); @@ -613,24 +608,24 @@ void srt_vec_ind16_fx ( * - 4.0 to 8.0 * - 8.0 to infinity *---------------------------------------------------------------------------*/ -Word16 atan2_fx( /* o: Angle between 0 and PI/2 radian (Q14) */ - const Word32 y, /* i : near side (Argument must be positive) (Q15) */ - const Word32 x /* i : opposite side (Q15) */ +Word16 atan2_fx( /* o: Angle between 0 and PI/2 radian (Q14) */ + const Word32 y, /* i : near side (Argument must be positive) (Q15) */ + const Word32 x /* i : opposite side (Q15) */ ) { Word32 acc, arg; Word16 man, expo, reciprocal; Word16 angle, w, z; - IF (x == 0) + IF( x == 0 ) { return 25736; /* PI/2 in Q14 */ } - man = ratio(y, x, &expo); /* man in Q14 */ - expo = sub(expo, (15 - 14)); /* Now, man is considered in Q15 */ - arg = L_shr((Word32)man, expo); + man = ratio( y, x, &expo ); /* man in Q14 */ + expo = sub( expo, ( 15 - 14 ) ); /* Now, man is considered in Q15 */ + arg = L_shr( (Word32) man, expo ); - IF (L_shr(arg, 3+15) != 0) + IF( L_shr( arg, 3 + 15 ) != 0 ) /*===============================* * 8.0 <= x < infinity * *===============================*/ @@ -638,22 +633,22 @@ Word16 atan2_fx( /* o: Angle between 0 and PI/2 radian (Q14) */ /* atan(x) = PI/2 - 1/x + 1/(3x^3) - 1/(5x^5) + ... * ~ PI/2 - 1/x, for x >= 8. */ - expo = norm_l(arg); - man = extract_h(L_shl(arg, expo)); - reciprocal = div_s(0x3fff, man); - expo = sub(15 + 1, expo); - reciprocal = shr(reciprocal, expo); /* Q14 */ - angle = sub(25736, reciprocal); /* Q14 (PI/2 - 1/x) */ + expo = norm_l( arg ); + man = extract_h( L_shl( arg, expo ) ); + reciprocal = div_s( 0x3fff, man ); + expo = sub( 15 + 1, expo ); + reciprocal = shr( reciprocal, expo ); /* Q14 */ + angle = sub( 25736, reciprocal ); /* Q14 (PI/2 - 1/x) */ /* For 8.0 <= x < 10.0, 1/(5x^5) is not completely negligible. * For more accurate result, add very small correction term. */ - if (LT_32(L_shr(arg, 15), 10L)) + if ( LT_32( L_shr( arg, 15 ), 10L ) ) { - angle = add(angle, 8); /* Add tiny correction term. */ + angle = add( angle, 8 ); /* Add tiny correction term. */ } } - ELSE IF (L_shr(arg, 2+15) != 0) + ELSE IF( L_shr( arg, 2 + 15 ) != 0 ) /*==========================* * 4.0 <= x < 8.0 * *==========================*/ @@ -668,18 +663,18 @@ Word16 atan2_fx( /* o: Angle between 0 and PI/2 radian (Q14) */ * a2 = -4.64216306484597e-02, a3 = 2.75986060068931e-01, * a4 = 7.49208077809799e-01. */ - w = extract_l(L_shr(arg, 3)); /* Q15 y = x/8 */ - acc = L_add(533625337L, 0); /* Q31 c1 = a1*8^2 */ - z = mac_r(acc, w, -2161); /* Q15 c0 = a0*8^3 */ - acc = L_add(-797517542L, 0); /* Q31 c2 = a2*8 */ - z = mac_r(acc, w, z); /* Q15 */ - acc = L_add(592675551L, 0); /* Q31 c3 = a3 */ - z = mac_r(acc, w, z); /* z (in:Q15, out:Q12) */ - acc = L_add(201114012L, 0); /* Q28 c4 = a4 */ - acc = L_mac(acc, w, z); /* Q28 */ - angle = extract_l(L_shr(acc, (28 - 14))); /* Q14 result of atan(x), where 4 <= x < 8 */ + w = extract_l( L_shr( arg, 3 ) ); /* Q15 y = x/8 */ + acc = L_add( 533625337L, 0 ); /* Q31 c1 = a1*8^2 */ + z = mac_r( acc, w, -2161 ); /* Q15 c0 = a0*8^3 */ + acc = L_add( -797517542L, 0 ); /* Q31 c2 = a2*8 */ + z = mac_r( acc, w, z ); /* Q15 */ + acc = L_add( 592675551L, 0 ); /* Q31 c3 = a3 */ + z = mac_r( acc, w, z ); /* z (in:Q15, out:Q12) */ + acc = L_add( 201114012L, 0 ); /* Q28 c4 = a4 */ + acc = L_mac( acc, w, z ); /* Q28 */ + angle = extract_l( L_shr( acc, ( 28 - 14 ) ) ); /* Q14 result of atan(x), where 4 <= x < 8 */ } - ELSE IF (L_shr(arg, 1+15) != 0) + ELSE IF( L_shr( arg, 1 + 15 ) != 0 ) /*==========================* * 2.0 <= x < 4.0 * *==========================*/ @@ -695,18 +690,18 @@ Word16 atan2_fx( /* o: Angle between 0 and PI/2 radian (Q14) */ * a2 = -0.25631148958325911, a3 = 0.81685854627399479, * a4 = 0.21358070563097167 * */ - w = extract_l(L_shr(arg, 2)); /* Q15 y = x/4 */ - acc = L_add(702602883L, 0); /* Q31 c1 = a1*8 */ - z = mac_r(acc, w, -2751); /* Q15 c0 = a0*32 */ - acc = L_add(-1100849465L, 0); /* Q31 c2 = a2*2 */ - z = mac_r(acc, w, z); /* z (in:Q15, out:Q14) */ - acc = L_add(877095185L, 0); /* Q30 c3 = a3 */ - z = mac_r(acc, w, z); /* z (in:Q14, out:Q12) */ - acc = L_add(57332634L, 0); /* Q28 c4 = a4 */ - acc = L_mac(acc, w, z); /* Q28 */ - angle = extract_l(L_shr(acc, (28 - 14))); /* Q14 result of atan(x) where 2 <= x < 4 */ + w = extract_l( L_shr( arg, 2 ) ); /* Q15 y = x/4 */ + acc = L_add( 702602883L, 0 ); /* Q31 c1 = a1*8 */ + z = mac_r( acc, w, -2751 ); /* Q15 c0 = a0*32 */ + acc = L_add( -1100849465L, 0 ); /* Q31 c2 = a2*2 */ + z = mac_r( acc, w, z ); /* z (in:Q15, out:Q14) */ + acc = L_add( 877095185L, 0 ); /* Q30 c3 = a3 */ + z = mac_r( acc, w, z ); /* z (in:Q14, out:Q12) */ + acc = L_add( 57332634L, 0 ); /* Q28 c4 = a4 */ + acc = L_mac( acc, w, z ); /* Q28 */ + angle = extract_l( L_shr( acc, ( 28 - 14 ) ) ); /* Q14 result of atan(x) where 2 <= x < 4 */ } - ELSE IF (L_shr(arg, 15) != 0) + ELSE IF( L_shr( arg, 15 ) != 0 ) /*==========================* * 1.0 <= x < 2.0 * *==========================*/ @@ -722,16 +717,16 @@ Word16 atan2_fx( /* o: Angle between 0 and PI/2 radian (Q14) */ * a2 = -0.6123208404800871, a3 = 1.3307896976322915, * a4 = -0.0697089375247448 */ - w = extract_l(L_shr(arg, 1)); /* Q15 y= x/2 */ - acc = L_add(655887249L, 0); /* Q31 c1 = a1*2 */ - z = mac_r(acc, w, -2106); /* Q15 c0 = a0*4 */ - acc = L_add(-1314948992L, 0); /* Q31 c2 = a2 */ - z = mac_r(acc, w, z); - acc = L_add(1428924557L, 0); /* Q31 c3 = a3/2 */ - z = mac_r(acc, w, z); /* z (in:Q15, out:Q13) */ - acc = L_add(-37424701L, 0); /* Q29 c4 = a4 */ - acc = L_mac(acc, w, z); /* Q29 */ - angle = extract_l(L_shr(acc, (29 - 14))); /* Q14 result of atan(x) where 1 <= x < 2 */ + w = extract_l( L_shr( arg, 1 ) ); /* Q15 y= x/2 */ + acc = L_add( 655887249L, 0 ); /* Q31 c1 = a1*2 */ + z = mac_r( acc, w, -2106 ); /* Q15 c0 = a0*4 */ + acc = L_add( -1314948992L, 0 ); /* Q31 c2 = a2 */ + z = mac_r( acc, w, z ); + acc = L_add( 1428924557L, 0 ); /* Q31 c3 = a3/2 */ + z = mac_r( acc, w, z ); /* z (in:Q15, out:Q13) */ + acc = L_add( -37424701L, 0 ); /* Q29 c4 = a4 */ + acc = L_mac( acc, w, z ); /* Q29 */ + angle = extract_l( L_shr( acc, ( 29 - 14 ) ) ); /* Q14 result of atan(x) where 1 <= x < 2 */ } ELSE /*==========================* @@ -747,22 +742,19 @@ Word16 atan2_fx( /* o: Angle between 0 and PI/2 radian (Q14) */ * a2 = -4.63358392562492e-01, a3 = 2.87188466598566e-02, * a4 = 9.97438122814383e-01, a5 = 5.36158556179092e-05. */ - w = extract_l(arg); /* Q15 */ - acc = L_add(1188376431L, 0); /* Q31 c1 = a1*2 */ - z = mac_r(acc, w, -3547); /* Q15 c0 = a0*2 */ - acc = L_add(-995054571L, 0); /* Q31 c2 = a2 */ - z = extract_h(L_mac0(acc, w, z)); /* Q15 non-fractional mode multiply */ - acc = L_add(61673254L, 0); /* Q31 c3 = a3 */ - z = mac_r(acc, w, z); - acc = L_add(2141982059L, 0); /* Q31 c4 = a4 */ - z = mac_r(acc, w, z); - acc = L_add(115139L, 0); /* Q31 c5 = a5 */ - acc = L_mac(acc, w, z); /* Q31 */ - angle = extract_l(L_shr(acc, 31 - 14)); /* Q14 result of atan(x), where 0 <= x < 1 */ + w = extract_l( arg ); /* Q15 */ + acc = L_add( 1188376431L, 0 ); /* Q31 c1 = a1*2 */ + z = mac_r( acc, w, -3547 ); /* Q15 c0 = a0*2 */ + acc = L_add( -995054571L, 0 ); /* Q31 c2 = a2 */ + z = extract_h( L_mac0( acc, w, z ) ); /* Q15 non-fractional mode multiply */ + acc = L_add( 61673254L, 0 ); /* Q31 c3 = a3 */ + z = mac_r( acc, w, z ); + acc = L_add( 2141982059L, 0 ); /* Q31 c4 = a4 */ + z = mac_r( acc, w, z ); + acc = L_add( 115139L, 0 ); /* Q31 c5 = a5 */ + acc = L_mac( acc, w, z ); /* Q31 */ + angle = extract_l( L_shr( acc, 31 - 14 ) ); /* Q14 result of atan(x), where 0 <= x < 1 */ } - return angle; /* Q14 between 0 and PI/2 radian. */ + return angle; /* Q14 between 0 and PI/2 radian. */ } - - - diff --git a/lib_com/range_com_fx.c b/lib_com/range_com_fx.c index 4caa38392..4fb29bd58 100644 --- a/lib_com/range_com_fx.c +++ b/lib_com/range_com_fx.c @@ -3,10 +3,10 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ +#include "options.h" /* Compilation switches */ #include "cnst.h" /* Common constants */ #include "prot_fx1.h" -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ /*-------------------------------------------------------------------* @@ -15,12 +15,12 @@ * Get number of bits needed to finalize range coder *-------------------------------------------------------------------*/ -Word16 rc_get_bits2_fx( /* o: Number of bits needed */ - const Word16 N, /* i: Number of bits currently used */ - const UWord32 range /* i: Range of range coder */ +Word16 rc_get_bits2_fx( /* o: Number of bits needed */ + const Word16 N, /* i: Number of bits currently used */ + const UWord32 range /* i: Range of range coder */ ) { - return add(add(N, 2), norm_ul(range)); + return add( add( N, 2 ), norm_ul( range ) ); } /*-------------------------------------------------------------------* @@ -30,39 +30,38 @@ Word16 rc_get_bits2_fx( /* o: Number of bits needed */ *-------------------------------------------------------------------*/ void rangeCoderFinalizationFBits_fx( - Word16 Brc, /* i : Current number of decoded bits */ - UWord32 INTrc, /* i : Range coder state */ - Word16* FBits /* i : Fractional finalization bits */ + Word16 Brc, /* i : Current number of decoded bits */ + UWord32 INTrc, /* i : Range coder state */ + Word16 *FBits /* i : Fractional finalization bits */ ) { Word32 L_Bq15; UWord32 h, UL_tmp; UWord16 Bq15ui16, l; Word16 B, E, x, k; - *FBits = shl(add(Brc, 32), 3); + *FBits = shl( add( Brc, 32 ), 3 ); - B = sub(30, norm_ul(INTrc)); - x = sub(B, RCF_INIT_SHIFT ); + B = sub( 30, norm_ul( INTrc ) ); + x = sub( B, RCF_INIT_SHIFT ); L_Bq15 = 0; move16(); - if (x >= 0) + if ( x >= 0 ) { - L_Bq15 = (Word32)UL_lshr(INTrc, x); + L_Bq15 = (Word32) UL_lshr( INTrc, x ); } E = 2; move16(); - FOR(k = 1; k < 4; k++) + FOR( k = 1; k < 4; k++ ) { - Bq15ui16 = u_extract_l(L_shr(L_Bq15, s_and(E, 1))); - UL_tmp = UL_lshl(UL_deposit_l(Bq15ui16), 1); - Mpy_32_16_uu(UL_tmp, Bq15ui16, &h , &l); - L_Bq15 = (Word32) h; - E = add(shl(B, 1), extract_l(L_lshr(L_sub(((1L << 16) - 1L), L_Bq15), 31))); - B = E; + Bq15ui16 = u_extract_l( L_shr( L_Bq15, s_and( E, 1 ) ) ); + UL_tmp = UL_lshl( UL_deposit_l( Bq15ui16 ), 1 ); + Mpy_32_16_uu( UL_tmp, Bq15ui16, &h, &l ); + L_Bq15 = (Word32) h; + E = add( shl( B, 1 ), extract_l( L_lshr( L_sub( ( ( 1L << 16 ) - 1L ), L_Bq15 ), 31 ) ) ); + B = E; move16(); } - *FBits = sub(*FBits, B); + *FBits = sub( *FBits, B ); return; } - diff --git a/lib_com/re8_ppv_fx.c b/lib_com/re8_ppv_fx.c index aa13af059..a786f9936 100644 --- a/lib_com/re8_ppv_fx.c +++ b/lib_com/re8_ppv_fx.c @@ -2,15 +2,15 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ #include "stl.h" /*-------------------------------------------------------------------* - * Local function prototypes - *-------------------------------------------------------------------*/ + * Local function prototypes + *-------------------------------------------------------------------*/ static void nearest_neighbor_2D8_fx( const Word32 x[], Word16 y[] ); static Word32 compute_error_2D8_fx( const Word32 x[], const Word16 y[] ); @@ -25,8 +25,8 @@ static Word32 compute_error_2D8_fx( const Word32 x[], const Word16 y[] ); * --------------------------------------------------------------*/ void re8_PPV_fx( - const Word32 x[], /* i : point in R^8Q15 */ - Word16 y[] /* o : point in RE8 (8-dimensional integer vector) */ + const Word32 x[], /* i : point in R^8Q15 */ + Word16 y[] /* o : point in RE8 (8-dimensional integer vector) */ ) { Word16 i, y0[8]; @@ -38,19 +38,19 @@ void re8_PPV_fx( nearest_neighbor_2D8_fx( x, y0 ); /*--------------------------------------------------------------* - * find the nearest neighbor y1 of x in 2D8+(1,...,1) (by coset decoding) - *--------------------------------------------------------------*/ + * find the nearest neighbor y1 of x in 2D8+(1,...,1) (by coset decoding) + *--------------------------------------------------------------*/ - FOR( i=0; i<8; i++ ) + FOR( i = 0; i < 8; i++ ) { - x1[i] = L_sub(x[i], QR); + x1[i] = L_sub( x[i], QR ); move32(); } nearest_neighbor_2D8_fx( x1, y ); - FOR ( i = 0; i < 8; i++ ) + FOR( i = 0; i < 8; i++ ) { - y[i] = add(y[i], 1); + y[i] = add( y[i], 1 ); move16(); } @@ -65,7 +65,7 @@ void re8_PPV_fx( /*--------------------------------------------------------------* * select best candidate y0 or y1 to minimize distortion *--------------------------------------------------------------*/ - IF( LT_32(e0, e1)) + IF( LT_32( e0, e1 ) ) { Copy( y0, y, 8 ); } @@ -84,11 +84,11 @@ void re8_PPV_fx( --------------------------------------------------------------*/ static void nearest_neighbor_2D8_fx( - const Word32 x[], /* i : point in R^8 */ - Word16 y[] /* o : point in 2D8 (8-dimensional integer vector) */ + const Word32 x[], /* i : point in R^8 */ + Word16 y[] /* o : point in 2D8 (8-dimensional integer vector) */ ) { - Word16 i,j; + Word16 i, j; Word16 sum, tmp16, tmp16b; Word32 s, e, em; @@ -100,14 +100,14 @@ static void nearest_neighbor_2D8_fx( sum = 0; move16(); - FOR( i=0; i<8; i++ ) + FOR( i = 0; i < 8; i++ ) { /* round to ..., -2, 0, 2, ... ([-1..1[ --> 0) */ - tmp16 = round_fx(L_add(x[i], L_shr(x[i], 31))); - y[i] = shl(tmp16, 1); + tmp16 = round_fx( L_add( x[i], L_shr( x[i], 31 ) ) ); + y[i] = shl( tmp16, 1 ); move16(); /* sum += y[i] */ - sum = add(sum, y[i]); + sum = add( sum, y[i] ); } /*--------------------------------------------------------------* @@ -116,39 +116,39 @@ static void nearest_neighbor_2D8_fx( * j = arg max_i | xi -yi| * (this is called the Wagner rule) *--------------------------------------------------------------*/ - IF( s_and(sum, 2) != 0 ) + IF( s_and( sum, 2 ) != 0 ) { /* find j = arg max_i | xi -yi| */ - em = L_deposit_l(0); + em = L_deposit_l( 0 ); j = 0; move16(); - FOR( i=0; i<8; i++ ) + FOR( i = 0; i < 8; i++ ) { /* compute ei = xi-yi */ /* e[i]=x[i]-y[i] */ - e = L_msu(x[i], y[i], QR/2); + e = L_msu( x[i], y[i], QR / 2 ); /* compute |ei| = | xi-yi | */ - s = L_abs(e); + s = L_abs( e ); /* check if |ei| is maximal, if so, set j=i */ - if( LT_32(em, s)) + if ( LT_32( em, s ) ) { j = i; move16(); } - em = L_max(s, em); + em = L_max( s, em ); } /* round xj in the "wrong way" */ - e = L_msu(x[j], y[j], QR/2); - tmp16 = extract_h(e); - tmp16b = add(y[j], 2); + e = L_msu( x[j], y[j], QR / 2 ); + tmp16 = extract_h( e ); + tmp16b = add( y[j], 2 ); - if( tmp16 < 0 ) + if ( tmp16 < 0 ) { - tmp16b = sub(tmp16b, 2+2); + tmp16b = sub( tmp16b, 2 + 2 ); } y[j] = tmp16b; move16(); @@ -165,30 +165,30 @@ static void nearest_neighbor_2D8_fx( * (quantized) point in 2D8. --------------------------------------------------------------*/ -static Word32 compute_error_2D8_fx( /* o : mean squared error */ - const Word32 x[], /* i : input vector */ - const Word16 y[] /* i : point in 2D8 (8-dimensional integer vector) */ +static Word32 compute_error_2D8_fx( /* o : mean squared error */ + const Word32 x[], /* i : input vector */ + const Word16 y[] /* i : point in 2D8 (8-dimensional integer vector) */ ) { Word16 i, hi, lo; Word32 err, Ltmp; - err = L_deposit_l(0); - FOR( i=0; i<8; i++ ) + err = L_deposit_l( 0 ); + FOR( i = 0; i < 8; i++ ) { /*tmp = x[i]-y[i];*/ - Ltmp = L_msu(x[i], y[i], 16384); - hi = extract_h(L_shl(Ltmp, 1)); - lo = extract_l(L_msu(Ltmp, hi, 16384)); + Ltmp = L_msu( x[i], y[i], 16384 ); + hi = extract_h( L_shl( Ltmp, 1 ) ); + lo = extract_l( L_msu( Ltmp, hi, 16384 ) ); - Ltmp = L_mult(hi, hi); - Ltmp = L_shl(Ltmp, 14); - Ltmp = L_mac(Ltmp, hi, lo); - Ltmp = L_mac0(Ltmp, mult(lo, lo), 1); + Ltmp = L_mult( hi, hi ); + Ltmp = L_shl( Ltmp, 14 ); + Ltmp = L_mac( Ltmp, hi, lo ); + Ltmp = L_mac0( Ltmp, mult( lo, lo ), 1 ); /* err+=tmp*tmp */ - err = L_add(Ltmp, err); + err = L_add( Ltmp, err ); } - return( err ); + return ( err ); } diff --git a/lib_com/re8_util_fx.c b/lib_com/re8_util_fx.c index aea7581da..db58c3fae 100644 --- a/lib_com/re8_util_fx.c +++ b/lib_com/re8_util_fx.c @@ -3,11 +3,11 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ /*-------------------------------------------------------------------* @@ -15,7 +15,7 @@ *-------------------------------------------------------------------*/ static Word16 re8_identify_absolute_leader_fx( const Word16 y[] ); -static void re8_coord_fx( const Word16 *y, Word16 *k) ; +static void re8_coord_fx( const Word16 *y, Word16 *k ); /*----------------------------------------------------------------* @@ -24,11 +24,11 @@ static void re8_coord_fx( const Word16 *y, Word16 *k) ; * MULTI-RATE RE8 INDEXING BY VORONOI EXTENSION *----------------------------------------------------------------*/ void re8_vor_fx( - const Word16 y[], /* i : point in RE8 (8-dimensional integer vector) */ - Word16 *n, /* o : codebook number n=0,2,3,4,... (scalar integer) */ - Word16 k[], /* o : Voronoi index (integer vector of dimension 8) used only if n>4*/ - Word16 c[], /* o : codevector in Q0, Q2, Q3, or Q4 if n<=4, y=c */ - Word16 *ka /* o : identifier of absolute leader (to index c) */ + const Word16 y[], /* i : point in RE8 (8-dimensional integer vector) */ + Word16 *n, /* o : codebook number n=0,2,3,4,... (scalar integer) */ + Word16 k[], /* o : Voronoi index (integer vector of dimension 8) used only if n>4*/ + Word16 c[], /* o : codevector in Q0, Q2, Q3, or Q4 if n<=4, y=c */ + Word16 *ka /* o : identifier of absolute leader (to index c) */ ) { Word16 i, r, iter, ka_tmp, n_tmp, mask; @@ -69,7 +69,7 @@ void re8_vor_fx( * and replace n by n = n' + 2r where n' = 3 or 4 (c is in Qn') and r is defined above *----------------------------------------------------------------*/ - IF( LE_16(*n, 4)) + IF( LE_16( *n, 4 ) ) { Copy( y, c, 8 ); } @@ -78,76 +78,76 @@ void re8_vor_fx( /*------------------------------------------------------------* * initialize r and m=2^r based on || y ||^2/8 *------------------------------------------------------------*/ - Ltmp = L_mult(y[0], y[0]); + Ltmp = L_mult( y[0], y[0] ); FOR( i = 1; i < 8; i++ ) { - Ltmp = L_mac( Ltmp, y[i], y[i]); + Ltmp = L_mac( Ltmp, y[i], y[i] ); } - Lsphere = L_shr(Ltmp, 5+1); /* *0.125*0.25 / 2 to remove L_mac effect */ + Lsphere = L_shr( Ltmp, 5 + 1 ); /* *0.125*0.25 / 2 to remove L_mac effect */ r = 1; move16(); FOR( ; Lsphere > 11; Lsphere >>= 2 ) { - r = add(r, 1); + r = add( r, 1 ); } /*------------------------------------------------------------* - * compute the coordinates of y in the RE8 basis - *------------------------------------------------------------*/ + * compute the coordinates of y in the RE8 basis + *------------------------------------------------------------*/ re8_coord_fx( y, k_mod ); /*------------------------------------------------------------* - * compute m and the mask needed for modulo m (for Voronoi coding) - *------------------------------------------------------------*/ - mask = sub(shl(1, r), 1); /* 0x0..011...1 */ + * compute m and the mask needed for modulo m (for Voronoi coding) + *------------------------------------------------------------*/ + mask = sub( shl( 1, r ), 1 ); /* 0x0..011...1 */ /*------------------------------------------------------------* - * find the minimal value of r (or equivalently of m) in 2 iterations - *------------------------------------------------------------*/ + * find the minimal value of r (or equivalently of m) in 2 iterations + *------------------------------------------------------------*/ - FOR( iter=0; iter<2; iter++ ) + FOR( iter = 0; iter < 2; iter++ ) { /*--------------------------------------------------------* - * compute v such that y is in m RE_8 +v (by Voronoi coding) - *--------------------------------------------------------*/ - FOR( i=0; i<8; i++ ) + * compute v such that y is in m RE_8 +v (by Voronoi coding) + *--------------------------------------------------------*/ + FOR( i = 0; i < 8; i++ ) { - k_tmp[i] = s_and( k_mod[i], mask); + k_tmp[i] = s_and( k_mod[i], mask ); move16(); } re8_k2y_fx( k_tmp, r, v ); /*--------------------------------------------------------* - * compute c = (y-v)/m - * (y is in RE8, c is also in RE8 by definition of v) - *--------------------------------------------------------*/ + * compute c = (y-v)/m + * (y is in RE8, c is also in RE8 by definition of v) + *--------------------------------------------------------*/ - FOR( i=0; i<8; i++ ) + FOR( i = 0; i < 8; i++ ) { - c_tmp[i] = shr(sub(y[i], v[i]), r); + c_tmp[i] = shr( sub( y[i], v[i] ), r ); move16(); } /*--------------------------------------------------------* - * verify if c_tmp is in Q2, Q3 or Q4 - *--------------------------------------------------------*/ + * verify if c_tmp is in Q2, Q3 or Q4 + *--------------------------------------------------------*/ ka_tmp = re8_identify_absolute_leader_fx( c_tmp ); /*--------------------------------------------------------* - * at this stage, n_tmp=2,3,4 or out = 100 -- n=0 is not possible - *--------------------------------------------------------*/ + * at this stage, n_tmp=2,3,4 or out = 100 -- n=0 is not possible + *--------------------------------------------------------*/ n_tmp = Da_nq[ka_tmp]; move16(); - IF( GT_16(n_tmp, 4)) + IF( GT_16( n_tmp, 4 ) ) { /*--------------------------------------------------------* - * if c is not in Q2, Q3, or Q4 (i.e. n_tmp>4), use m = 2^(r+1) instead of 2^r - *--------------------------------------------------------*/ - r = add(r, 1); - mask = add(shl(mask, 1), 1); /* mask = m-1 <- this is less complex */ + * if c is not in Q2, Q3, or Q4 (i.e. n_tmp>4), use m = 2^(r+1) instead of 2^r + *--------------------------------------------------------*/ + r = add( r, 1 ); + mask = add( shl( mask, 1 ), 1 ); /* mask = m-1 <- this is less complex */ } ELSE { @@ -157,14 +157,14 @@ void re8_vor_fx( * since Q2 is a subset of Q3, indicate n=3 instead of n=2 (this is because * for n>4, n=n'+2r with n'=3 or 4, so n'=2 is not valid) *--------------------------------------------------------*/ - n_tmp = s_max(n_tmp, 3); + n_tmp = s_max( n_tmp, 3 ); /*--------------------------------------------------------* * save current values into ka, n, k and c *--------------------------------------------------------*/ *ka = ka_tmp; move16(); - *n = add(n_tmp, shl(r, 1)); + *n = add( n_tmp, shl( r, 1 ) ); move16(); Copy( k_tmp, k, 8 ); Copy( c_tmp, c, 8 ); @@ -172,8 +172,8 @@ void re8_vor_fx( /*--------------------------------------------------------* * try m = 2^(r-1) instead of 2^r to be sure that m is minimal *--------------------------------------------------------*/ - r = sub(r, 1); - mask = shr(mask, 1); + r = sub( r, 1 ); + mask = shr( mask, 1 ); } } } @@ -188,13 +188,13 @@ void re8_vor_fx( * VORONOI INDEXING (INDEX DECODING) k -> y -------------------------------------------------------------------------*/ void re8_k2y_fx( - const Word16 *k, /* i : Voronoi index k[0..7] */ - const Word16 m, /* i : Voronoi modulo (m = 2^r = 1<=2) */ - Word16 *y /* o : 8-dimensional point y[0..7] in RE8 */ + const Word16 *k, /* i : Voronoi index k[0..7] */ + const Word16 m, /* i : Voronoi modulo (m = 2^r = 1<=2) */ + Word16 *y /* o : 8-dimensional point y[0..7] in RE8 */ ) { Word16 i, v[8], *ptr1, *ptr2, m_tmp, mm; - Word32 ytp[8], z[8], Ltmp, Lsum ; + Word32 ytp[8], z[8], Ltmp, Lsum; /*---------------------------------------------------------------* * compute y = k M and z=(y-a)/m, where @@ -205,29 +205,29 @@ void re8_k2y_fx( * [1 1 _ 1 1] * a=(2,0,...,0) *---------------------------------------------------------------*/ - m_tmp = sub(15, m); + m_tmp = sub( 15, m ); - Lsum = L_deposit_l(k[7]); + Lsum = L_deposit_l( k[7] ); ytp[7] = Lsum; move32(); - z[7] = L_shl(Lsum, m_tmp); - move32(); /* (int)(floor(y[7]*QR+0.5))>>m */ + z[7] = L_shl( Lsum, m_tmp ); + move32(); /* (int)(floor(y[7]*QR+0.5))>>m */ - FOR( i=6; i>=1; i-- ) + FOR( i = 6; i >= 1; i-- ) { - Ltmp = L_deposit_l( shl(k[i],1) ); - Lsum = L_add (Lsum, Ltmp); - ytp[i] = L_add(ytp[7], Ltmp); + Ltmp = L_deposit_l( shl( k[i], 1 ) ); + Lsum = L_add( Lsum, Ltmp ); + ytp[i] = L_add( ytp[7], Ltmp ); move32(); - z[i] = L_shl(ytp[i], m_tmp); - move32(); /* (int)(floor(y[7]*QR+0.5))>>m */ + z[i] = L_shl( ytp[i], m_tmp ); + move32(); /* (int)(floor(y[7]*QR+0.5))>>m */ } - Lsum = L_add( Lsum, L_deposit_l(shl(k[0],2) )); + Lsum = L_add( Lsum, L_deposit_l( shl( k[0], 2 ) ) ); ytp[0] = Lsum; move32(); - z[0] = L_shl(L_sub(Lsum, 2), m_tmp); - move32(); /* (int)(floor(y[7]*QR+0.5))>>m */ + z[0] = L_shl( L_sub( Lsum, 2 ), m_tmp ); + move32(); /* (int)(floor(y[7]*QR+0.5))>>m */ /*---------------------------------------------------------------* * find nearest neighbor v of z in infinite RE8 @@ -237,15 +237,15 @@ void re8_k2y_fx( /*---------------------------------------------------------------* * compute y -= m v *---------------------------------------------------------------*/ - ptr1=y; - ptr2=v; + ptr1 = y; + ptr2 = v; - mm = shr(shl(1, m), 1); /* shr to remove effect of L_mult in L_msu */ + mm = shr( shl( 1, m ), 1 ); /* shr to remove effect of L_mult in L_msu */ - FOR( i=0; i<8; i++ ) + FOR( i = 0; i < 8; i++ ) { - Ltmp = L_msu(ytp[i], *ptr2++, mm); - *ptr1++ = extract_l(Ltmp); + Ltmp = L_msu( ytp[i], *ptr2++, mm ); + *ptr1++ = extract_l( Ltmp ); } return; @@ -259,11 +259,11 @@ void re8_k2y_fx( * SPECIFIES THE CODEBOOKS Q0, Q2, Q3 and Q4 -----------------------------------------------------------------------*/ -static Word16 re8_identify_absolute_leader_fx( /* o : integer indicating if y if in Q0, Q2, Q3 or Q4 (or if y is an outlier) */ - const Word16 y[] /* i : point in RE8 (8-dimensional integer vector) */ +static Word16 re8_identify_absolute_leader_fx( /* o : integer indicating if y if in Q0, Q2, Q3 or Q4 (or if y is an outlier) */ + const Word16 y[] /* i : point in RE8 (8-dimensional integer vector) */ ) { - Word16 i,s,id,nb,pos,ka, tmp16; + Word16 i, s, id, nb, pos, ka, tmp16; Word32 Ltmp, Ls; Word32 C; const Word16 *ptr; @@ -271,15 +271,15 @@ static Word16 re8_identify_absolute_leader_fx( /* o : integer indicating if y i /*-----------------------------------------------------------------------* * compute the RE8 shell number s = (y1^2+...+y8^2)/8 and C=(y1^2, ..., y8^2) *-----------------------------------------------------------------------*/ - Ls = L_mult(y[0], y[0]); + Ls = L_mult( y[0], y[0] ); FOR( i = 1; i < 8; i++ ) { - Ls = L_mac( Ls, y[i], y[i]); + Ls = L_mac( Ls, y[i], y[i] ); } #ifdef BASOP_NOGLOB s = extract_h( L_shl_sat( Ls, 16 - ( 3 + 1 ) ) ); /* s can saturate here */ #else - s = extract_h(L_shl(Ls, 16-(3+1))); /* s can saturate here */ + s = extract_h( L_shl( Ls, 16 - ( 3 + 1 ) ) ); /* s can saturate here */ #endif /*-----------------------------------------------------------------------* * compute the index 0 <= ka <= NB_LEADER+1 which identifies an absolute leader of Q0, Q2, Q3 or Q4 @@ -293,28 +293,28 @@ static Word16 re8_identify_absolute_leader_fx( /* o : integer indicating if y i move16(); IF( s != 0 ) { - ka = NB_LEADER+1; + ka = NB_LEADER + 1; move16(); /*-------------------------------------------------------------------* * the maximal value of s for y in Q0, Q2, Q3 or Q4 is NB_SPHERE * if s> NB_SPHERE, y is an outlier (the value of ka is set correctly) *-------------------------------------------------------------------*/ - IF( LE_16(s, NB_SPHERE)) + IF( LE_16( s, NB_SPHERE ) ) { /*---------------------------------------------------------------* * compute the unique identifier id of the absolute leader related to y: - * s = (y1^4 + ... + y8^4)/8 - *---------------------------------------------------------------*/ - C = L_mult(y[0], y[0]); - tmp16 = extract_h(L_shl(C, 16-1)); - Ltmp = L_mult(tmp16, tmp16); - FOR( i=1; i<8; i++ ) + * s = (y1^4 + ... + y8^4)/8 + *---------------------------------------------------------------*/ + C = L_mult( y[0], y[0] ); + tmp16 = extract_h( L_shl( C, 16 - 1 ) ); + Ltmp = L_mult( tmp16, tmp16 ); + FOR( i = 1; i < 8; i++ ) { - C = L_mult(y[i], y[i]); - tmp16 = extract_h(L_shl(C, 16-1)); - Ltmp = L_mac(Ltmp, tmp16, tmp16); + C = L_mult( y[i], y[i] ); + tmp16 = extract_h( L_shl( C, 16 - 1 ) ); + Ltmp = L_mac( Ltmp, tmp16, tmp16 ); } - id = extract_h(L_shl(Ltmp, 16-(3+1))); /* id can saturate to 8192 */ + id = extract_h( L_shl( Ltmp, 16 - ( 3 + 1 ) ) ); /* id can saturate to 8192 */ /*---------------------------------------------------------------* * search for id in table Da_id @@ -323,28 +323,28 @@ static Word16 re8_identify_absolute_leader_fx( /* o : integer indicating if y i * only the id's related to the shell of number s are checked *---------------------------------------------------------------*/ - nb = Da_nb[s - 1]; /* get the number of absolute leaders used on the shell of number s */ - pos = Da_pos[s - 1]; /* get the position of the first absolute leader of shell s in Da_id */ + nb = Da_nb[s - 1]; /* get the number of absolute leaders used on the shell of number s */ + pos = Da_pos[s - 1]; /* get the position of the first absolute leader of shell s in Da_id */ move16(); move16(); ptr = &Da_id[pos]; move16(); - FOR( i=0; i=1; i-- ) + FOR( i = 6; i >= 1; i-- ) { /* apply factor 2/4 from M^-1 */ - k[i] = shr(sub(y[i], tmp), 1); + k[i] = shr( sub( y[i], tmp ), 1 ); move16(); - sum = sub(sum, y[i]); + sum = sub( sum, y[i] ); } /* apply factor 1/4 from M^-1 */ - k[0]= shr(add(y[0], sum), 2); + k[0] = shr( add( y[0], sum ), 2 ); move16(); return; diff --git a/lib_com/recovernorm_fx.c b/lib_com/recovernorm_fx.c index bcce460e3..e5b72fc51 100644 --- a/lib_com/recovernorm_fx.c +++ b/lib_com/recovernorm_fx.c @@ -2,11 +2,11 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ +#include "options.h" /* Compilation switches */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ /*--------------------------------------------------------------------------* * recovernorm_fx() @@ -15,37 +15,37 @@ *--------------------------------------------------------------------------*/ void recovernorm_fx( - const Word16 *idxbuf, /* i : reordered quantization indices */ - Word16 *ynrm, /* o : recovered quantization indices */ - Word16 *normqlg2, /* o : recovered quantized norms */ - const Word16 nb_sfm /* i : number of SFMs */ + const Word16 *idxbuf, /* i : reordered quantization indices */ + Word16 *ynrm, /* o : recovered quantization indices */ + Word16 *normqlg2, /* o : recovered quantized norms */ + const Word16 nb_sfm /* i : number of SFMs */ ) { - Word16 i,j,k; + Word16 i, j, k; const Word16 *order = NULL; move16(); - SWITCH (nb_sfm) + SWITCH( nb_sfm ) { - case NB_SFM: - order = norm_order_48; - move16(); - BREAK; - case SFM_N_SWB: - order = norm_order_32; - move16(); - BREAK; - case SFM_N_WB: - order = norm_order_16; - move16(); - BREAK; - default: - order = norm_order_48; - move16(); - BREAK; + case NB_SFM: + order = norm_order_48; + move16(); + BREAK; + case SFM_N_SWB: + order = norm_order_32; + move16(); + BREAK; + case SFM_N_WB: + order = norm_order_16; + move16(); + BREAK; + default: + order = norm_order_48; + move16(); + BREAK; } - FOR (i = 0; i < nb_sfm; i++) + FOR( i = 0; i < nb_sfm; i++ ) { j = order[i]; move16(); @@ -59,4 +59,3 @@ void recovernorm_fx( return; } - diff --git a/lib_com/reordvct_fx.c b/lib_com/reordvct_fx.c index b36f5e090..a26480626 100644 --- a/lib_com/reordvct_fx.c +++ b/lib_com/reordvct_fx.c @@ -31,56 +31,54 @@ *******************************************************************************************************/ #include -#include "options.h" /* Compilation switches */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "prot_fx2.h" /* Function prototypes */ - /*--------------------------------------------------------------------------* - * reordvct() - * - * Rearrange a vector in decreasing order - *--------------------------------------------------------------------------*/ +/*--------------------------------------------------------------------------* + * reordvct() + * + * Rearrange a vector in decreasing order + *--------------------------------------------------------------------------*/ void reordvct_fx( - Word16 *y, /* i/o: vector to rearrange */ - const Word16 N, /* i : dimensions */ - Word16 *idx /* o : reordered vector index */ + Word16 *y, /* i/o: vector to rearrange */ + const Word16 N, /* i : dimensions */ + Word16 *idx /* o : reordered vector index */ ) { - Word16 i, j, k, n, im, temp; + Word16 i, j, k, n, im, temp; - n = sub(N, 1); - move16(); - FOR(i = 0; i < n; i++) - { - im = i; - move16(); - k = add(i, 1); - move16(); - FOR(j = k; j < N; j++) - { - if (LT_16(y[im], y[j])) - { - im = j; - move16(); - } - } + n = sub( N, 1 ); + move16(); + FOR( i = 0; i < n; i++ ) + { + im = i; + move16(); + k = add( i, 1 ); + move16(); + FOR( j = k; j < N; j++ ) + { + if ( LT_16( y[im], y[j] ) ) + { + im = j; + move16(); + } + } - temp = y[i]; - move16(); - y[i] = y[im]; - move16(); - y[im] = temp; - move16(); - j = idx[i]; - move16(); - idx[i] = idx[im]; - move16(); - idx[im] = j; - move16(); - } + temp = y[i]; + move16(); + y[i] = y[im]; + move16(); + y[im] = temp; + move16(); + j = idx[i]; + move16(); + idx[i] = idx[im]; + move16(); + idx[im] = j; + move16(); + } - return; + return; } - - diff --git a/lib_com/residu_fx.c b/lib_com/residu_fx.c index bf076d4d0..5849fb815 100644 --- a/lib_com/residu_fx.c +++ b/lib_com/residu_fx.c @@ -3,9 +3,9 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ #include "prot_fx1.h" #include "prot_fx2.h" @@ -18,13 +18,12 @@ * Optimized Version: Use when Past[0..m-1] is 0 & a[0] is 1 (in Q12) *--------------------------------------------------------------------*/ void Residu3_lc_fx( - const Word16 a[], /* i : prediction coefficients Q12 */ - const Word16 m, /* i : order of LP filter Q0 */ - const Word16 x[], /* i : input signal (usually speech) Qx */ - Word16 y[], /* o : output signal (usually residual) Qx */ - const Word16 lg, /* i : vector size Q0 */ - const Word16 shift -) + const Word16 a[], /* i : prediction coefficients Q12 */ + const Word16 m, /* i : order of LP filter Q0 */ + const Word16 x[], /* i : input signal (usually speech) Qx */ + Word16 y[], /* o : output signal (usually residual) Qx */ + const Word16 lg, /* i : vector size Q0 */ + const Word16 shift ) { Word16 i, j; Word32 s; @@ -33,66 +32,66 @@ void Residu3_lc_fx( Flag Overflow = 0; #endif - q = add( norm_s(a[0]), 1 ); - if (shift > 0) + q = add( norm_s( a[0] ), 1 ); + if ( shift > 0 ) { - q = add(q, shift); + q = add( q, shift ); } #ifdef BASOP_NOGLOB - *y++ = shl_o(x[0], shift, &Overflow); + *y++ = shl_o( x[0], shift, &Overflow ); #else - *y++ = shl(x[0], shift); + *y++ = shl( x[0], shift ); #endif move16(); - FOR (i = 1; i < m; i++) + FOR( i = 1; i < m; i++ ) { #ifdef BASOP_NOGLOB - s = L_mult_o(x[i], a[0], &Overflow); + s = L_mult_o( x[i], a[0], &Overflow ); #else - s = L_mult(x[i], a[0]); + s = L_mult( x[i], a[0] ); #endif /* Stop at i to Avoid Mults with Zeros */ - FOR (j = 1; j <= i; j++) + FOR( j = 1; j <= i; j++ ) { #ifdef BASOP_NOGLOB - s = L_mac_o(s, x[i-j], a[j], &Overflow); + s = L_mac_o( s, x[i - j], a[j], &Overflow ); #else - s = L_mac(s, x[i-j], a[j]); + s = L_mac( s, x[i - j], a[j] ); #endif } #ifdef BASOP_NOGLOB - s = L_shl_o(s, q, &Overflow); - *y++ = round_fx_o(s, &Overflow); + s = L_shl_o( s, q, &Overflow ); + *y++ = round_fx_o( s, &Overflow ); #else - s = L_shl(s, q); - *y++ = round_fx(s); + s = L_shl( s, q ); + *y++ = round_fx( s ); #endif } - FOR (; i < lg; i++) + FOR( ; i < lg; i++ ) { #ifdef BASOP_NOGLOB - s = L_mult_o(x[i], a[0], &Overflow); + s = L_mult_o( x[i], a[0], &Overflow ); #else - s = L_mult(x[i], a[0]); + s = L_mult( x[i], a[0] ); #endif - FOR (j = 1; j <= m; j++) + FOR( j = 1; j <= m; j++ ) { #ifdef BASOP_NOGLOB - s = L_mac_o(s, x[i-j], a[j], &Overflow); + s = L_mac_o( s, x[i - j], a[j], &Overflow ); #else - s = L_mac(s, x[i-j], a[j]); + s = L_mac( s, x[i - j], a[j] ); #endif } #ifdef BASOP_NOGLOB - s = L_shl_o(s, q, &Overflow); - *y++ = round_fx_o(s, &Overflow); + s = L_shl_o( s, q, &Overflow ); + *y++ = round_fx_o( s, &Overflow ); #else - s = L_shl(s, q); - *y++ = round_fx(s); + s = L_shl( s, q ); + *y++ = round_fx( s ); #endif } } @@ -104,33 +103,32 @@ void Residu3_lc_fx( * Output is in Qx *--------------------------------------------------------------------*/ void Residu3_10_fx( - const Word16 a[], /* i : prediction coefficients Q12 */ - const Word16 x[], /* i : input signal (usually speech) Qx */ - /* (note that values x[-10..-1] are needed) */ - Word16 y[], /* o : output signal (usually residual) Qx */ - const Word16 lg, /* i : vector size Q0 */ - const Word16 shift -) + const Word16 a[], /* i : prediction coefficients Q12 */ + const Word16 x[], /* i : input signal (usually speech) Qx */ + /* (note that values x[-10..-1] are needed) */ + Word16 y[], /* o : output signal (usually residual) Qx */ + const Word16 lg, /* i : vector size Q0 */ + const Word16 shift ) { - Word16 i,j; + Word16 i, j; Word32 s; - Word64 s64; + Word64 s64; Word16 q; - q = add( norm_s(a[0]), 1 ); - if (shift != 0) - q = add(q, shift); - FOR (i = 0; i < lg; i++) + q = add( norm_s( a[0] ), 1 ); + if ( shift != 0 ) + q = add( q, shift ); + FOR( i = 0; i < lg; i++ ) { s64 = 0; - FOR (j = 0; j <= 10; j++) - { - s64 = W_mac_16_16(s64, x[i-j], a[j]); - } - s = W_shl_sat_l(s64, q); + FOR( j = 0; j <= 10; j++ ) + { + s64 = W_mac_16_16( s64, x[i - j], a[j] ); + } + s = W_shl_sat_l( s64, q ); #ifdef BASOP_NOGLOB y[i] = round_fx_sat( s ); #else - y[i] = round_fx(s); + y[i] = round_fx( s ); #endif } } @@ -141,33 +139,32 @@ void Residu3_10_fx( * Output is in Qx *--------------------------------------------------------------------*/ void Residu3_fx( - const Word16 a[], /* i : prediction coefficients Q12 */ - const Word16 x[], /* i : input signal (usually speech) Qx */ - /* (note that values x[-M..-1] are needed) */ - Word16 y[], /* o : output signal (usually residual) Qx */ - const Word16 lg, /* i : vector size Q0 */ - const Word16 shift -) + const Word16 a[], /* i : prediction coefficients Q12 */ + const Word16 x[], /* i : input signal (usually speech) Qx */ + /* (note that values x[-M..-1] are needed) */ + Word16 y[], /* o : output signal (usually residual) Qx */ + const Word16 lg, /* i : vector size Q0 */ + const Word16 shift ) { Word16 i, j; Word64 s64; - Word32 s32; + Word32 s32; Word16 q; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - q = add( norm_s(a[0]), 1 ); - if (shift != 0) - q = add(q, shift); - FOR (i = 0; i < lg; i++) + q = add( norm_s( a[0] ), 1 ); + if ( shift != 0 ) + q = add( q, shift ); + FOR( i = 0; i < lg; i++ ) { s64 = 0; - FOR (j = 0; j <= 15; j++) - { - s64 = W_mac_16_16(s64, x[i-j], a[j]); - } - s64 = W_mac_16_16(s64, x[i-16], a[16]); - s32 = W_shl_sat_l(s64, q); + FOR( j = 0; j <= 15; j++ ) + { + s64 = W_mac_16_16( s64, x[i - j], a[j] ); + } + s64 = W_mac_16_16( s64, x[i - 16], a[16] ); + s32 = W_shl_sat_l( s64, q ); #ifdef BASOP_NOGLOB y[i] = round_fx_o( s32, &Overflow ); #else /* BASOP_NOGLOB */ @@ -198,10 +195,10 @@ void Residu3_fx( /*==========================================================================*/ void calc_residu_fx( - Encoder_State *st, /* i/o: state structure */ - const Word16 *speech, /* i : weighted speech signal */ - Word16 *res, /* o : residual signal */ - const Word16 *p_Aq /* i : quantized LP filter coefficients */ + Encoder_State *st, /* i/o: state structure */ + const Word16 *speech, /* i : weighted speech signal */ + Word16 *res, /* o : residual signal */ + const Word16 *p_Aq /* i : quantized LP filter coefficients */ ) { Word16 i_subfr; @@ -212,8 +209,7 @@ void calc_residu_fx( Residu3_fx( p_Aq, &speech[i_subfr], &res[i_subfr], L_SUBFR, 1 ); /* next subframe */ - p_Aq += (M+1); + p_Aq += ( M + 1 ); } return; } - diff --git a/lib_com/rom_basic_math.c b/lib_com/rom_basic_math.c index ac3e9623e..ceb89163f 100644 --- a/lib_com/rom_basic_math.c +++ b/lib_com/rom_basic_math.c @@ -1,39 +1,36 @@ -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Decoder static structure */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Decoder static structure */ #include "stl.h" /* math_op.c */ -const Word32 L_table_isqrt[48] = -{ - 2147418112L, 2083389440L, 2024669184L, 1970667520L, - 1920794624L, 1874460672L, 1831403520L, 1791098880L, - 1753415680L, 1717960704L, 1684602880L, 1653145600L, - 1623326720L, 1595080704L, 1568276480L, 1542782976L, - 1518469120L, 1495334912L, 1473183744L, 1451950080L, - 1431633920L, 1412169728L, 1393491968L, 1375469568L, - 1358168064L, 1341521920L, 1325465600L, 1309933568L, - 1294991360L, 1280507904L, 1266548736L, 1252982784L, - 1239875584L, 1227161600L, 1214775296L, 1202847744L, - 1191182336L, 1179910144L, 1168965632L, 1158283264L, - 1147863040L, 1137770496L, 1127940096L, 1118306304L, - 1108934656L, 1099825152L, 1090912256L, 1082261504L +const Word32 L_table_isqrt[48] = { + 2147418112L, 2083389440L, 2024669184L, 1970667520L, + 1920794624L, 1874460672L, 1831403520L, 1791098880L, + 1753415680L, 1717960704L, 1684602880L, 1653145600L, + 1623326720L, 1595080704L, 1568276480L, 1542782976L, + 1518469120L, 1495334912L, 1473183744L, 1451950080L, + 1431633920L, 1412169728L, 1393491968L, 1375469568L, + 1358168064L, 1341521920L, 1325465600L, 1309933568L, + 1294991360L, 1280507904L, 1266548736L, 1252982784L, + 1239875584L, 1227161600L, 1214775296L, 1202847744L, + 1191182336L, 1179910144L, 1168965632L, 1158283264L, + 1147863040L, 1137770496L, 1127940096L, 1118306304L, + 1108934656L, 1099825152L, 1090912256L, 1082261504L }; /* table of table_isqrt[i] - table_isqrt[i+1] */ -const Word16 table_isqrt_diff[48] = -{ - 977, 896, 824, 761, 707, 657, 615, 575, - 541, 509, 480, 455, 431, 409, 389, 371, - 353, 338, 324, 310, 297, 285, 275, 264, - 254, 245, 237, 228, 221, 213, 207, 200, - 194, 189, 182, 178, 172, 167, 163, 159, - 154, 150, 147, 143, 139, 136, 132, 130 +const Word16 table_isqrt_diff[48] = { + 977, 896, 824, 761, 707, 657, 615, 575, + 541, 509, 480, 455, 431, 409, 389, 371, + 353, 338, 324, 310, 297, 285, 275, 264, + 254, 245, 237, 228, 221, 213, 207, 200, + 194, 189, 182, 178, 172, 167, 163, 159, + 154, 150, 147, 143, 139, 136, 132, 130 }; -const Word16 shift_Isqrt_lc[] = {9,10}; +const Word16 shift_Isqrt_lc[] = { 9, 10 }; -const Word16 table_pow2[32] = -{ +const Word16 table_pow2[32] = { 16384, 16743, 17109, 17484, 17867, 18258, 18658, 19066, 19484, 19911, 20347, 20792, 21247, 21713, 22188, 22674, 23170, 23678, 24196, 24726, 25268, 25821, 26386, 26964, 27554, 28158, 28774, 29405, 30048, 30706, @@ -41,16 +38,14 @@ const Word16 table_pow2[32] = }; /* table of table_pow2[i+1] - table_pow2[i] */ -const Word16 table_pow2_diff_x32[32] = -{ +const Word16 table_pow2_diff_x32[32] = { 11488, 11712, 12000, 12256, 12512, 12800, 13056, 13376, 13664, 13952, 14240, 14560, 14912, 15200, 15552, 15872, 16256, 16576, 16960, 17344, 17696, 18080, 18496, 18880, 19328, 19712, 20192, 20576, 21056, 21536, 21984, 22432 }; -const Word16 sqrt_table[49] = -{ +const Word16 sqrt_table[49] = { 16384, 16888, 17378, 17854, 18318, 18770, 19212, 19644, 20066, 20480, 20886, 21283, 21674, 22058, 22435, 22806, 23170, 23530, 23884, 24232, 24576, @@ -61,31 +56,28 @@ const Word16 sqrt_table[49] = }; /* log2.c */ -const Word32 L_table_Log2_norm_lc[32] = -{ - -32768L, 95322112L, 187793408L, 277577728L, - 364871680L, 449740800L, 532381696L, 612859904L, - 691306496L, 767787008L, 842432512L, 915308544L, - 986546176L, 1056210944L, 1124302848L, 1190887424L, +const Word32 L_table_Log2_norm_lc[32] = { + -32768L, 95322112L, 187793408L, 277577728L, + 364871680L, 449740800L, 532381696L, 612859904L, + 691306496L, 767787008L, 842432512L, 915308544L, + 986546176L, 1056210944L, 1124302848L, 1190887424L, 1256095744L, 1319993344L, 1382580224L, 1443921920L, 1504083968L, 1563131904L, 1621000192L, 1677885440L, 1733722112L, 1788510208L, 1842380800L, 1895399424L, 1947435008L, 1998618624L, 2049015808L, 2098626560L }; - -const Word16 table_diff_Log2_norm_lc[32] = -{ - 1455, 1411, 1370, 1332, 1295, 1261, 1228, 1197, - 1167, 1139, 1112, 1087, 1063, 1039, 1016, 995, - 975, 955, 936, 918, 901, 883, 868, 852, - 836, 822, 809, 794, 781, 769, 757, 744 + +const Word16 table_diff_Log2_norm_lc[32] = { + 1455, 1411, 1370, 1332, 1295, 1261, 1228, 1197, + 1167, 1139, 1112, 1087, 1063, 1039, 1016, 995, + 975, 955, 936, 918, 901, 883, 868, 852, + 836, 822, 809, 794, 781, 769, 757, 744 }; - -const Word16 log2_tab[33]={ + +const Word16 log2_tab[33] = { 0x7800, 0x782D, 0x785A, 0x7884, 0x78AE, 0x78D6, 0x78FE, 0x7924, 0x794A, 0x796E, 0x7992, 0x79B4, 0x79D6, 0x79F8, 0x7A18, 0x7A38, 0x7A57, 0x7A75, 0x7A93, 0x7AB1, 0x7ACD, 0x7AE9, 0x7B05, 0x7B20, - 0x7B3B, 0x7B55, 0x7B6F, 0x7B88, 0x7BA1, 0x7BB9, 0x7BD1, 0x7BE9, + 0x7B3B, 0x7B55, 0x7B6F, 0x7B88, 0x7BA1, 0x7BB9, 0x7BD1, 0x7BE9, 0x7C00 }; - diff --git a/lib_com/rom_basic_math.h b/lib_com/rom_basic_math.h index 7c7fec415..0cf6d6dd3 100644 --- a/lib_com/rom_basic_math.h +++ b/lib_com/rom_basic_math.h @@ -1,5 +1,5 @@ -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Decoder static structure */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Decoder static structure */ #include "stl.h" @@ -20,7 +20,7 @@ extern const Word16 sqrt_table[49]; /* log2.c */ extern const Word32 L_table_Log2_norm_lc[32]; - + extern const Word16 table_diff_Log2_norm_lc[32]; - + extern const Word16 log2_tab[33]; diff --git a/lib_com/rom_basop_util.c b/lib_com/rom_basop_util.c index ee454fb9d..9c5fd7552 100644 --- a/lib_com/rom_basop_util.c +++ b/lib_com/rom_basop_util.c @@ -37,780 +37,1509 @@ #include "options.h" -#define STC(x) WORD322WORD16(x) +#define STC( x ) WORD322WORD16( x ) -#define STCP(a,b) { { STC(a), STC(b) } } +#define STCP( a, b ) \ + { \ + { \ + STC( a ), STC( b ) \ + } \ + } -const PWord16 SineTable512[] = -{ - STCP(0x7fffffff, 0x00000000), STCP(0x7fffd886, 0x006487e3), STCP(0x7fff6216, 0x00c90f88), STCP(0x7ffe9cb2, 0x012d96b1), - STCP(0x7ffd885a, 0x01921d20), STCP(0x7ffc250f, 0x01f6a297), STCP(0x7ffa72d1, 0x025b26d7), STCP(0x7ff871a2, 0x02bfa9a4), - STCP(0x7ff62182, 0x03242abf), STCP(0x7ff38274, 0x0388a9ea), STCP(0x7ff09478, 0x03ed26e6), STCP(0x7fed5791, 0x0451a177), - STCP(0x7fe9cbc0, 0x04b6195d), STCP(0x7fe5f108, 0x051a8e5c), STCP(0x7fe1c76b, 0x057f0035), STCP(0x7fdd4eec, 0x05e36ea9), - STCP(0x7fd8878e, 0x0647d97c), STCP(0x7fd37153, 0x06ac406f), STCP(0x7fce0c3e, 0x0710a345), STCP(0x7fc85854, 0x077501be), - STCP(0x7fc25596, 0x07d95b9e), STCP(0x7fbc040a, 0x083db0a7), STCP(0x7fb563b3, 0x08a2009a), STCP(0x7fae7495, 0x09064b3a), - STCP(0x7fa736b4, 0x096a9049), STCP(0x7f9faa15, 0x09cecf89), STCP(0x7f97cebd, 0x0a3308bd), STCP(0x7f8fa4b0, 0x0a973ba5), - STCP(0x7f872bf3, 0x0afb6805), STCP(0x7f7e648c, 0x0b5f8d9f), STCP(0x7f754e80, 0x0bc3ac35), STCP(0x7f6be9d4, 0x0c27c389), - STCP(0x7f62368f, 0x0c8bd35e), STCP(0x7f5834b7, 0x0cefdb76), STCP(0x7f4de451, 0x0d53db92), STCP(0x7f434563, 0x0db7d376), - STCP(0x7f3857f6, 0x0e1bc2e4), STCP(0x7f2d1c0e, 0x0e7fa99e), STCP(0x7f2191b4, 0x0ee38766), STCP(0x7f15b8ee, 0x0f475bff), - STCP(0x7f0991c4, 0x0fab272b), STCP(0x7efd1c3c, 0x100ee8ad), STCP(0x7ef05860, 0x1072a048), STCP(0x7ee34636, 0x10d64dbd), - STCP(0x7ed5e5c6, 0x1139f0cf), STCP(0x7ec8371a, 0x119d8941), STCP(0x7eba3a39, 0x120116d5), STCP(0x7eabef2c, 0x1264994e), - STCP(0x7e9d55fc, 0x12c8106f), STCP(0x7e8e6eb2, 0x132b7bf9), STCP(0x7e7f3957, 0x138edbb1), STCP(0x7e6fb5f4, 0x13f22f58), - STCP(0x7e5fe493, 0x145576b1), STCP(0x7e4fc53e, 0x14b8b17f), STCP(0x7e3f57ff, 0x151bdf86), STCP(0x7e2e9cdf, 0x157f0086), - STCP(0x7e1d93ea, 0x15e21445), STCP(0x7e0c3d29, 0x16451a83), STCP(0x7dfa98a8, 0x16a81305), STCP(0x7de8a670, 0x170afd8d), - STCP(0x7dd6668f, 0x176dd9de), STCP(0x7dc3d90d, 0x17d0a7bc), STCP(0x7db0fdf8, 0x183366e9), STCP(0x7d9dd55a, 0x18961728), - STCP(0x7d8a5f40, 0x18f8b83c), STCP(0x7d769bb5, 0x195b49ea), STCP(0x7d628ac6, 0x19bdcbf3), STCP(0x7d4e2c7f, 0x1a203e1b), - STCP(0x7d3980ec, 0x1a82a026), STCP(0x7d24881b, 0x1ae4f1d6), STCP(0x7d0f4218, 0x1b4732ef), STCP(0x7cf9aef0, 0x1ba96335), - STCP(0x7ce3ceb2, 0x1c0b826a), STCP(0x7ccda169, 0x1c6d9053), STCP(0x7cb72724, 0x1ccf8cb3), STCP(0x7ca05ff1, 0x1d31774d), - STCP(0x7c894bde, 0x1d934fe5), STCP(0x7c71eaf9, 0x1df5163f), STCP(0x7c5a3d50, 0x1e56ca1e), STCP(0x7c4242f2, 0x1eb86b46), - STCP(0x7c29fbee, 0x1f19f97b), STCP(0x7c116853, 0x1f7b7481), STCP(0x7bf88830, 0x1fdcdc1b), STCP(0x7bdf5b94, 0x203e300d), - STCP(0x7bc5e290, 0x209f701c), STCP(0x7bac1d31, 0x21009c0c), STCP(0x7b920b89, 0x2161b3a0), STCP(0x7b77ada8, 0x21c2b69c), - STCP(0x7b5d039e, 0x2223a4c5), STCP(0x7b420d7a, 0x22847de0), STCP(0x7b26cb4f, 0x22e541af), STCP(0x7b0b3d2c, 0x2345eff8), - STCP(0x7aef6323, 0x23a6887f), STCP(0x7ad33d45, 0x24070b08), STCP(0x7ab6cba4, 0x24677758), STCP(0x7a9a0e50, 0x24c7cd33), - STCP(0x7a7d055b, 0x25280c5e), STCP(0x7a5fb0d8, 0x2588349d), STCP(0x7a4210d8, 0x25e845b6), STCP(0x7a24256f, 0x26483f6c), - STCP(0x7a05eead, 0x26a82186), STCP(0x79e76ca7, 0x2707ebc7), STCP(0x79c89f6e, 0x27679df4), STCP(0x79a98715, 0x27c737d3), - STCP(0x798a23b1, 0x2826b928), STCP(0x796a7554, 0x288621b9), STCP(0x794a7c12, 0x28e5714b), STCP(0x792a37fe, 0x2944a7a2), - STCP(0x7909a92d, 0x29a3c485), STCP(0x78e8cfb2, 0x2a02c7b8), STCP(0x78c7aba2, 0x2a61b101), STCP(0x78a63d11, 0x2ac08026), - STCP(0x78848414, 0x2b1f34eb), STCP(0x786280bf, 0x2b7dcf17), STCP(0x78403329, 0x2bdc4e6f), STCP(0x781d9b65, 0x2c3ab2b9), - STCP(0x77fab989, 0x2c98fbba), STCP(0x77d78daa, 0x2cf72939), STCP(0x77b417df, 0x2d553afc), STCP(0x7790583e, 0x2db330c7), - STCP(0x776c4edb, 0x2e110a62), STCP(0x7747fbce, 0x2e6ec792), STCP(0x77235f2d, 0x2ecc681e), STCP(0x76fe790e, 0x2f29ebcc), - STCP(0x76d94989, 0x2f875262), STCP(0x76b3d0b4, 0x2fe49ba7), STCP(0x768e0ea6, 0x3041c761), STCP(0x76680376, 0x309ed556), - STCP(0x7641af3d, 0x30fbc54d), STCP(0x761b1211, 0x3158970e), STCP(0x75f42c0b, 0x31b54a5e), STCP(0x75ccfd42, 0x3211df04), - STCP(0x75a585cf, 0x326e54c7), STCP(0x757dc5ca, 0x32caab6f), STCP(0x7555bd4c, 0x3326e2c3), STCP(0x752d6c6c, 0x3382fa88), - STCP(0x7504d345, 0x33def287), STCP(0x74dbf1ef, 0x343aca87), STCP(0x74b2c884, 0x34968250), STCP(0x7489571c, 0x34f219a8), - STCP(0x745f9dd1, 0x354d9057), STCP(0x74359cbd, 0x35a8e625), STCP(0x740b53fb, 0x36041ad9), STCP(0x73e0c3a3, 0x365f2e3b), - STCP(0x73b5ebd1, 0x36ba2014), STCP(0x738acc9e, 0x3714f02a), STCP(0x735f6626, 0x376f9e46), STCP(0x7333b883, 0x37ca2a30), - STCP(0x7307c3d0, 0x382493b0), STCP(0x72db8828, 0x387eda8e), STCP(0x72af05a7, 0x38d8fe93), STCP(0x72823c67, 0x3932ff87), - STCP(0x72552c85, 0x398cdd32), STCP(0x7227d61c, 0x39e6975e), STCP(0x71fa3949, 0x3a402dd2), STCP(0x71cc5626, 0x3a99a057), - STCP(0x719e2cd2, 0x3af2eeb7), STCP(0x716fbd68, 0x3b4c18ba), STCP(0x71410805, 0x3ba51e29), STCP(0x71120cc5, 0x3bfdfecd), - STCP(0x70e2cbc6, 0x3c56ba70), STCP(0x70b34525, 0x3caf50da), STCP(0x708378ff, 0x3d07c1d6), STCP(0x70536771, 0x3d600d2c), - STCP(0x7023109a, 0x3db832a6), STCP(0x6ff27497, 0x3e10320d), STCP(0x6fc19385, 0x3e680b2c), STCP(0x6f906d84, 0x3ebfbdcd), - STCP(0x6f5f02b2, 0x3f1749b8), STCP(0x6f2d532c, 0x3f6eaeb8), STCP(0x6efb5f12, 0x3fc5ec98), STCP(0x6ec92683, 0x401d0321), - STCP(0x6e96a99d, 0x4073f21d), STCP(0x6e63e87f, 0x40cab958), STCP(0x6e30e34a, 0x4121589b), STCP(0x6dfd9a1c, 0x4177cfb1), - STCP(0x6dca0d14, 0x41ce1e65), STCP(0x6d963c54, 0x42244481), STCP(0x6d6227fa, 0x427a41d0), STCP(0x6d2dd027, 0x42d0161e), - STCP(0x6cf934fc, 0x4325c135), STCP(0x6cc45698, 0x437b42e1), STCP(0x6c8f351c, 0x43d09aed), STCP(0x6c59d0a9, 0x4425c923), - STCP(0x6c242960, 0x447acd50), STCP(0x6bee3f62, 0x44cfa740), STCP(0x6bb812d1, 0x452456bd), STCP(0x6b81a3cd, 0x4578db93), - STCP(0x6b4af279, 0x45cd358f), STCP(0x6b13fef5, 0x4621647d), STCP(0x6adcc964, 0x46756828), STCP(0x6aa551e9, 0x46c9405c), - STCP(0x6a6d98a4, 0x471cece7), STCP(0x6a359db9, 0x47706d93), STCP(0x69fd614a, 0x47c3c22f), STCP(0x69c4e37a, 0x4816ea86), - STCP(0x698c246c, 0x4869e665), STCP(0x69532442, 0x48bcb599), STCP(0x6919e320, 0x490f57ee), STCP(0x68e06129, 0x4961cd33), - STCP(0x68a69e81, 0x49b41533), STCP(0x686c9b4b, 0x4a062fbd), STCP(0x683257ab, 0x4a581c9e), STCP(0x67f7d3c5, 0x4aa9dba2), - STCP(0x67bd0fbd, 0x4afb6c98), STCP(0x67820bb7, 0x4b4ccf4d), STCP(0x6746c7d8, 0x4b9e0390), STCP(0x670b4444, 0x4bef092d), - STCP(0x66cf8120, 0x4c3fdff4), STCP(0x66937e91, 0x4c9087b1), STCP(0x66573cbb, 0x4ce10034), STCP(0x661abbc5, 0x4d31494b), - STCP(0x65ddfbd3, 0x4d8162c4), STCP(0x65a0fd0b, 0x4dd14c6e), STCP(0x6563bf92, 0x4e210617), STCP(0x6526438f, 0x4e708f8f), - STCP(0x64e88926, 0x4ebfe8a5), STCP(0x64aa907f, 0x4f0f1126), STCP(0x646c59bf, 0x4f5e08e3), STCP(0x642de50d, 0x4faccfab), - STCP(0x63ef3290, 0x4ffb654d), STCP(0x63b0426d, 0x5049c999), STCP(0x637114cc, 0x5097fc5e), STCP(0x6331a9d4, 0x50e5fd6d), - STCP(0x62f201ac, 0x5133cc94), STCP(0x62b21c7b, 0x518169a5), STCP(0x6271fa69, 0x51ced46e), STCP(0x62319b9d, 0x521c0cc2), - STCP(0x61f1003f, 0x5269126e), STCP(0x61b02876, 0x52b5e546), STCP(0x616f146c, 0x53028518), STCP(0x612dc447, 0x534ef1b5), - STCP(0x60ec3830, 0x539b2af0), STCP(0x60aa7050, 0x53e73097), STCP(0x60686ccf, 0x5433027d), STCP(0x60262dd6, 0x547ea073), - STCP(0x5fe3b38d, 0x54ca0a4b), STCP(0x5fa0fe1f, 0x55153fd4), STCP(0x5f5e0db3, 0x556040e2), STCP(0x5f1ae274, 0x55ab0d46), - STCP(0x5ed77c8a, 0x55f5a4d2), STCP(0x5e93dc1f, 0x56400758), STCP(0x5e50015d, 0x568a34a9), STCP(0x5e0bec6e, 0x56d42c99), - STCP(0x5dc79d7c, 0x571deefa), STCP(0x5d8314b1, 0x57677b9d), STCP(0x5d3e5237, 0x57b0d256), STCP(0x5cf95638, 0x57f9f2f8), - STCP(0x5cb420e0, 0x5842dd54), STCP(0x5c6eb258, 0x588b9140), STCP(0x5c290acc, 0x58d40e8c), STCP(0x5be32a67, 0x591c550e), - STCP(0x5b9d1154, 0x59646498), STCP(0x5b56bfbd, 0x59ac3cfd), STCP(0x5b1035cf, 0x59f3de12), STCP(0x5ac973b5, 0x5a3b47ab), - STCP(0x5a82799a, 0x5a82799a), +const PWord16 SineTable512[] = { + STCP( 0x7fffffff, 0x00000000 ), + STCP( 0x7fffd886, 0x006487e3 ), + STCP( 0x7fff6216, 0x00c90f88 ), + STCP( 0x7ffe9cb2, 0x012d96b1 ), + STCP( 0x7ffd885a, 0x01921d20 ), + STCP( 0x7ffc250f, 0x01f6a297 ), + STCP( 0x7ffa72d1, 0x025b26d7 ), + STCP( 0x7ff871a2, 0x02bfa9a4 ), + STCP( 0x7ff62182, 0x03242abf ), + STCP( 0x7ff38274, 0x0388a9ea ), + STCP( 0x7ff09478, 0x03ed26e6 ), + STCP( 0x7fed5791, 0x0451a177 ), + STCP( 0x7fe9cbc0, 0x04b6195d ), + STCP( 0x7fe5f108, 0x051a8e5c ), + STCP( 0x7fe1c76b, 0x057f0035 ), + STCP( 0x7fdd4eec, 0x05e36ea9 ), + STCP( 0x7fd8878e, 0x0647d97c ), + STCP( 0x7fd37153, 0x06ac406f ), + STCP( 0x7fce0c3e, 0x0710a345 ), + STCP( 0x7fc85854, 0x077501be ), + STCP( 0x7fc25596, 0x07d95b9e ), + STCP( 0x7fbc040a, 0x083db0a7 ), + STCP( 0x7fb563b3, 0x08a2009a ), + STCP( 0x7fae7495, 0x09064b3a ), + STCP( 0x7fa736b4, 0x096a9049 ), + STCP( 0x7f9faa15, 0x09cecf89 ), + STCP( 0x7f97cebd, 0x0a3308bd ), + STCP( 0x7f8fa4b0, 0x0a973ba5 ), + STCP( 0x7f872bf3, 0x0afb6805 ), + STCP( 0x7f7e648c, 0x0b5f8d9f ), + STCP( 0x7f754e80, 0x0bc3ac35 ), + STCP( 0x7f6be9d4, 0x0c27c389 ), + STCP( 0x7f62368f, 0x0c8bd35e ), + STCP( 0x7f5834b7, 0x0cefdb76 ), + STCP( 0x7f4de451, 0x0d53db92 ), + STCP( 0x7f434563, 0x0db7d376 ), + STCP( 0x7f3857f6, 0x0e1bc2e4 ), + STCP( 0x7f2d1c0e, 0x0e7fa99e ), + STCP( 0x7f2191b4, 0x0ee38766 ), + STCP( 0x7f15b8ee, 0x0f475bff ), + STCP( 0x7f0991c4, 0x0fab272b ), + STCP( 0x7efd1c3c, 0x100ee8ad ), + STCP( 0x7ef05860, 0x1072a048 ), + STCP( 0x7ee34636, 0x10d64dbd ), + STCP( 0x7ed5e5c6, 0x1139f0cf ), + STCP( 0x7ec8371a, 0x119d8941 ), + STCP( 0x7eba3a39, 0x120116d5 ), + STCP( 0x7eabef2c, 0x1264994e ), + STCP( 0x7e9d55fc, 0x12c8106f ), + STCP( 0x7e8e6eb2, 0x132b7bf9 ), + STCP( 0x7e7f3957, 0x138edbb1 ), + STCP( 0x7e6fb5f4, 0x13f22f58 ), + STCP( 0x7e5fe493, 0x145576b1 ), + STCP( 0x7e4fc53e, 0x14b8b17f ), + STCP( 0x7e3f57ff, 0x151bdf86 ), + STCP( 0x7e2e9cdf, 0x157f0086 ), + STCP( 0x7e1d93ea, 0x15e21445 ), + STCP( 0x7e0c3d29, 0x16451a83 ), + STCP( 0x7dfa98a8, 0x16a81305 ), + STCP( 0x7de8a670, 0x170afd8d ), + STCP( 0x7dd6668f, 0x176dd9de ), + STCP( 0x7dc3d90d, 0x17d0a7bc ), + STCP( 0x7db0fdf8, 0x183366e9 ), + STCP( 0x7d9dd55a, 0x18961728 ), + STCP( 0x7d8a5f40, 0x18f8b83c ), + STCP( 0x7d769bb5, 0x195b49ea ), + STCP( 0x7d628ac6, 0x19bdcbf3 ), + STCP( 0x7d4e2c7f, 0x1a203e1b ), + STCP( 0x7d3980ec, 0x1a82a026 ), + STCP( 0x7d24881b, 0x1ae4f1d6 ), + STCP( 0x7d0f4218, 0x1b4732ef ), + STCP( 0x7cf9aef0, 0x1ba96335 ), + STCP( 0x7ce3ceb2, 0x1c0b826a ), + STCP( 0x7ccda169, 0x1c6d9053 ), + STCP( 0x7cb72724, 0x1ccf8cb3 ), + STCP( 0x7ca05ff1, 0x1d31774d ), + STCP( 0x7c894bde, 0x1d934fe5 ), + STCP( 0x7c71eaf9, 0x1df5163f ), + STCP( 0x7c5a3d50, 0x1e56ca1e ), + STCP( 0x7c4242f2, 0x1eb86b46 ), + STCP( 0x7c29fbee, 0x1f19f97b ), + STCP( 0x7c116853, 0x1f7b7481 ), + STCP( 0x7bf88830, 0x1fdcdc1b ), + STCP( 0x7bdf5b94, 0x203e300d ), + STCP( 0x7bc5e290, 0x209f701c ), + STCP( 0x7bac1d31, 0x21009c0c ), + STCP( 0x7b920b89, 0x2161b3a0 ), + STCP( 0x7b77ada8, 0x21c2b69c ), + STCP( 0x7b5d039e, 0x2223a4c5 ), + STCP( 0x7b420d7a, 0x22847de0 ), + STCP( 0x7b26cb4f, 0x22e541af ), + STCP( 0x7b0b3d2c, 0x2345eff8 ), + STCP( 0x7aef6323, 0x23a6887f ), + STCP( 0x7ad33d45, 0x24070b08 ), + STCP( 0x7ab6cba4, 0x24677758 ), + STCP( 0x7a9a0e50, 0x24c7cd33 ), + STCP( 0x7a7d055b, 0x25280c5e ), + STCP( 0x7a5fb0d8, 0x2588349d ), + STCP( 0x7a4210d8, 0x25e845b6 ), + STCP( 0x7a24256f, 0x26483f6c ), + STCP( 0x7a05eead, 0x26a82186 ), + STCP( 0x79e76ca7, 0x2707ebc7 ), + STCP( 0x79c89f6e, 0x27679df4 ), + STCP( 0x79a98715, 0x27c737d3 ), + STCP( 0x798a23b1, 0x2826b928 ), + STCP( 0x796a7554, 0x288621b9 ), + STCP( 0x794a7c12, 0x28e5714b ), + STCP( 0x792a37fe, 0x2944a7a2 ), + STCP( 0x7909a92d, 0x29a3c485 ), + STCP( 0x78e8cfb2, 0x2a02c7b8 ), + STCP( 0x78c7aba2, 0x2a61b101 ), + STCP( 0x78a63d11, 0x2ac08026 ), + STCP( 0x78848414, 0x2b1f34eb ), + STCP( 0x786280bf, 0x2b7dcf17 ), + STCP( 0x78403329, 0x2bdc4e6f ), + STCP( 0x781d9b65, 0x2c3ab2b9 ), + STCP( 0x77fab989, 0x2c98fbba ), + STCP( 0x77d78daa, 0x2cf72939 ), + STCP( 0x77b417df, 0x2d553afc ), + STCP( 0x7790583e, 0x2db330c7 ), + STCP( 0x776c4edb, 0x2e110a62 ), + STCP( 0x7747fbce, 0x2e6ec792 ), + STCP( 0x77235f2d, 0x2ecc681e ), + STCP( 0x76fe790e, 0x2f29ebcc ), + STCP( 0x76d94989, 0x2f875262 ), + STCP( 0x76b3d0b4, 0x2fe49ba7 ), + STCP( 0x768e0ea6, 0x3041c761 ), + STCP( 0x76680376, 0x309ed556 ), + STCP( 0x7641af3d, 0x30fbc54d ), + STCP( 0x761b1211, 0x3158970e ), + STCP( 0x75f42c0b, 0x31b54a5e ), + STCP( 0x75ccfd42, 0x3211df04 ), + STCP( 0x75a585cf, 0x326e54c7 ), + STCP( 0x757dc5ca, 0x32caab6f ), + STCP( 0x7555bd4c, 0x3326e2c3 ), + STCP( 0x752d6c6c, 0x3382fa88 ), + STCP( 0x7504d345, 0x33def287 ), + STCP( 0x74dbf1ef, 0x343aca87 ), + STCP( 0x74b2c884, 0x34968250 ), + STCP( 0x7489571c, 0x34f219a8 ), + STCP( 0x745f9dd1, 0x354d9057 ), + STCP( 0x74359cbd, 0x35a8e625 ), + STCP( 0x740b53fb, 0x36041ad9 ), + STCP( 0x73e0c3a3, 0x365f2e3b ), + STCP( 0x73b5ebd1, 0x36ba2014 ), + STCP( 0x738acc9e, 0x3714f02a ), + STCP( 0x735f6626, 0x376f9e46 ), + STCP( 0x7333b883, 0x37ca2a30 ), + STCP( 0x7307c3d0, 0x382493b0 ), + STCP( 0x72db8828, 0x387eda8e ), + STCP( 0x72af05a7, 0x38d8fe93 ), + STCP( 0x72823c67, 0x3932ff87 ), + STCP( 0x72552c85, 0x398cdd32 ), + STCP( 0x7227d61c, 0x39e6975e ), + STCP( 0x71fa3949, 0x3a402dd2 ), + STCP( 0x71cc5626, 0x3a99a057 ), + STCP( 0x719e2cd2, 0x3af2eeb7 ), + STCP( 0x716fbd68, 0x3b4c18ba ), + STCP( 0x71410805, 0x3ba51e29 ), + STCP( 0x71120cc5, 0x3bfdfecd ), + STCP( 0x70e2cbc6, 0x3c56ba70 ), + STCP( 0x70b34525, 0x3caf50da ), + STCP( 0x708378ff, 0x3d07c1d6 ), + STCP( 0x70536771, 0x3d600d2c ), + STCP( 0x7023109a, 0x3db832a6 ), + STCP( 0x6ff27497, 0x3e10320d ), + STCP( 0x6fc19385, 0x3e680b2c ), + STCP( 0x6f906d84, 0x3ebfbdcd ), + STCP( 0x6f5f02b2, 0x3f1749b8 ), + STCP( 0x6f2d532c, 0x3f6eaeb8 ), + STCP( 0x6efb5f12, 0x3fc5ec98 ), + STCP( 0x6ec92683, 0x401d0321 ), + STCP( 0x6e96a99d, 0x4073f21d ), + STCP( 0x6e63e87f, 0x40cab958 ), + STCP( 0x6e30e34a, 0x4121589b ), + STCP( 0x6dfd9a1c, 0x4177cfb1 ), + STCP( 0x6dca0d14, 0x41ce1e65 ), + STCP( 0x6d963c54, 0x42244481 ), + STCP( 0x6d6227fa, 0x427a41d0 ), + STCP( 0x6d2dd027, 0x42d0161e ), + STCP( 0x6cf934fc, 0x4325c135 ), + STCP( 0x6cc45698, 0x437b42e1 ), + STCP( 0x6c8f351c, 0x43d09aed ), + STCP( 0x6c59d0a9, 0x4425c923 ), + STCP( 0x6c242960, 0x447acd50 ), + STCP( 0x6bee3f62, 0x44cfa740 ), + STCP( 0x6bb812d1, 0x452456bd ), + STCP( 0x6b81a3cd, 0x4578db93 ), + STCP( 0x6b4af279, 0x45cd358f ), + STCP( 0x6b13fef5, 0x4621647d ), + STCP( 0x6adcc964, 0x46756828 ), + STCP( 0x6aa551e9, 0x46c9405c ), + STCP( 0x6a6d98a4, 0x471cece7 ), + STCP( 0x6a359db9, 0x47706d93 ), + STCP( 0x69fd614a, 0x47c3c22f ), + STCP( 0x69c4e37a, 0x4816ea86 ), + STCP( 0x698c246c, 0x4869e665 ), + STCP( 0x69532442, 0x48bcb599 ), + STCP( 0x6919e320, 0x490f57ee ), + STCP( 0x68e06129, 0x4961cd33 ), + STCP( 0x68a69e81, 0x49b41533 ), + STCP( 0x686c9b4b, 0x4a062fbd ), + STCP( 0x683257ab, 0x4a581c9e ), + STCP( 0x67f7d3c5, 0x4aa9dba2 ), + STCP( 0x67bd0fbd, 0x4afb6c98 ), + STCP( 0x67820bb7, 0x4b4ccf4d ), + STCP( 0x6746c7d8, 0x4b9e0390 ), + STCP( 0x670b4444, 0x4bef092d ), + STCP( 0x66cf8120, 0x4c3fdff4 ), + STCP( 0x66937e91, 0x4c9087b1 ), + STCP( 0x66573cbb, 0x4ce10034 ), + STCP( 0x661abbc5, 0x4d31494b ), + STCP( 0x65ddfbd3, 0x4d8162c4 ), + STCP( 0x65a0fd0b, 0x4dd14c6e ), + STCP( 0x6563bf92, 0x4e210617 ), + STCP( 0x6526438f, 0x4e708f8f ), + STCP( 0x64e88926, 0x4ebfe8a5 ), + STCP( 0x64aa907f, 0x4f0f1126 ), + STCP( 0x646c59bf, 0x4f5e08e3 ), + STCP( 0x642de50d, 0x4faccfab ), + STCP( 0x63ef3290, 0x4ffb654d ), + STCP( 0x63b0426d, 0x5049c999 ), + STCP( 0x637114cc, 0x5097fc5e ), + STCP( 0x6331a9d4, 0x50e5fd6d ), + STCP( 0x62f201ac, 0x5133cc94 ), + STCP( 0x62b21c7b, 0x518169a5 ), + STCP( 0x6271fa69, 0x51ced46e ), + STCP( 0x62319b9d, 0x521c0cc2 ), + STCP( 0x61f1003f, 0x5269126e ), + STCP( 0x61b02876, 0x52b5e546 ), + STCP( 0x616f146c, 0x53028518 ), + STCP( 0x612dc447, 0x534ef1b5 ), + STCP( 0x60ec3830, 0x539b2af0 ), + STCP( 0x60aa7050, 0x53e73097 ), + STCP( 0x60686ccf, 0x5433027d ), + STCP( 0x60262dd6, 0x547ea073 ), + STCP( 0x5fe3b38d, 0x54ca0a4b ), + STCP( 0x5fa0fe1f, 0x55153fd4 ), + STCP( 0x5f5e0db3, 0x556040e2 ), + STCP( 0x5f1ae274, 0x55ab0d46 ), + STCP( 0x5ed77c8a, 0x55f5a4d2 ), + STCP( 0x5e93dc1f, 0x56400758 ), + STCP( 0x5e50015d, 0x568a34a9 ), + STCP( 0x5e0bec6e, 0x56d42c99 ), + STCP( 0x5dc79d7c, 0x571deefa ), + STCP( 0x5d8314b1, 0x57677b9d ), + STCP( 0x5d3e5237, 0x57b0d256 ), + STCP( 0x5cf95638, 0x57f9f2f8 ), + STCP( 0x5cb420e0, 0x5842dd54 ), + STCP( 0x5c6eb258, 0x588b9140 ), + STCP( 0x5c290acc, 0x58d40e8c ), + STCP( 0x5be32a67, 0x591c550e ), + STCP( 0x5b9d1154, 0x59646498 ), + STCP( 0x5b56bfbd, 0x59ac3cfd ), + STCP( 0x5b1035cf, 0x59f3de12 ), + STCP( 0x5ac973b5, 0x5a3b47ab ), + STCP( 0x5a82799a, 0x5a82799a ), }; -const PWord16 SineTable320[] = -{ - STCP(0x7fffffff, 0x00000000), STCP(0x7fff9aef, 0x00a0d951), - STCP(0x7ffe6bbf, 0x0141b1a5), STCP(0x7ffc726f, 0x01e287fc), - STCP(0x7ff9af04, 0x02835b5a), STCP(0x7ff62182, 0x03242abf), - STCP(0x7ff1c9ef, 0x03c4f52f), STCP(0x7feca851, 0x0465b9aa), - STCP(0x7fe6bcb0, 0x05067734), STCP(0x7fe00716, 0x05a72ccf), - STCP(0x7fd8878e, 0x0647d97c), STCP(0x7fd03e23, 0x06e87c3f), - STCP(0x7fc72ae2, 0x07891418), STCP(0x7fbd4dda, 0x0829a00c), - STCP(0x7fb2a71b, 0x08ca1f1b), STCP(0x7fa736b4, 0x096a9049), - STCP(0x7f9afcb9, 0x0a0af299), STCP(0x7f8df93c, 0x0aab450d), - STCP(0x7f802c52, 0x0b4b86a8), STCP(0x7f719611, 0x0bebb66c), - STCP(0x7f62368f, 0x0c8bd35e), STCP(0x7f520de6, 0x0d2bdc80), - STCP(0x7f411c2f, 0x0dcbd0d5), STCP(0x7f2f6183, 0x0e6baf61), - STCP(0x7f1cde01, 0x0f0b7727), STCP(0x7f0991c4, 0x0fab272b), - STCP(0x7ef57cea, 0x104abe71), STCP(0x7ee09f95, 0x10ea3bfd), - STCP(0x7ecaf9e5, 0x11899ed3), STCP(0x7eb48bfb, 0x1228e5f8), - STCP(0x7e9d55fc, 0x12c8106f), STCP(0x7e85580c, 0x13671d3d), - STCP(0x7e6c9251, 0x14060b68), STCP(0x7e5304f2, 0x14a4d9f4), - STCP(0x7e38b017, 0x154387e6), STCP(0x7e1d93ea, 0x15e21445), - STCP(0x7e01b096, 0x16807e15), STCP(0x7de50646, 0x171ec45c), - STCP(0x7dc79529, 0x17bce621), STCP(0x7da95d6c, 0x185ae269), - STCP(0x7d8a5f40, 0x18f8b83c), STCP(0x7d6a9ad5, 0x199666a0), - STCP(0x7d4a105d, 0x1a33ec9c), STCP(0x7d28c00c, 0x1ad14938), - STCP(0x7d06aa16, 0x1b6e7b7a), STCP(0x7ce3ceb2, 0x1c0b826a), - STCP(0x7cc02e15, 0x1ca85d12), STCP(0x7c9bc87a, 0x1d450a78), - STCP(0x7c769e18, 0x1de189a6), STCP(0x7c50af2b, 0x1e7dd9a4), - STCP(0x7c29fbee, 0x1f19f97b), STCP(0x7c02849f, 0x1fb5e836), - STCP(0x7bda497d, 0x2051a4dd), STCP(0x7bb14ac5, 0x20ed2e7b), - STCP(0x7b8788ba, 0x2188841a), STCP(0x7b5d039e, 0x2223a4c5), - STCP(0x7b31bbb2, 0x22be8f87), STCP(0x7b05b13d, 0x2359436c), - STCP(0x7ad8e482, 0x23f3bf7e), STCP(0x7aab55ca, 0x248e02cb), - STCP(0x7a7d055b, 0x25280c5e), STCP(0x7a4df380, 0x25c1db44), - STCP(0x7a1e2082, 0x265b6e8a), STCP(0x79ed8cad, 0x26f4c53e), - STCP(0x79bc384d, 0x278dde6e), STCP(0x798a23b1, 0x2826b928), - STCP(0x79574f28, 0x28bf547b), STCP(0x7923bb01, 0x2957af74), - STCP(0x78ef678f, 0x29efc925), STCP(0x78ba5524, 0x2a87a09d), - STCP(0x78848414, 0x2b1f34eb), STCP(0x784df4b3, 0x2bb68522), - STCP(0x7816a759, 0x2c4d9050), STCP(0x77de9c5b, 0x2ce45589), - STCP(0x77a5d413, 0x2d7ad3de), STCP(0x776c4edb, 0x2e110a62), - STCP(0x77320d0d, 0x2ea6f827), STCP(0x76f70f05, 0x2f3c9c40), - STCP(0x76bb5521, 0x2fd1f5c1), STCP(0x767edfbe, 0x306703bf), - STCP(0x7641af3d, 0x30fbc54d), STCP(0x7603c3fd, 0x31903982), - STCP(0x75c51e61, 0x32245f72), STCP(0x7585becb, 0x32b83634), - STCP(0x7545a5a0, 0x334bbcde), STCP(0x7504d345, 0x33def287), - STCP(0x74c34820, 0x3471d647), STCP(0x74810499, 0x35046736), - STCP(0x743e0918, 0x3596a46c), STCP(0x73fa5607, 0x36288d03), - STCP(0x73b5ebd1, 0x36ba2014), STCP(0x7370cae2, 0x374b5cb9), - STCP(0x732af3a7, 0x37dc420c), STCP(0x72e4668f, 0x386ccf2a), - STCP(0x729d2409, 0x38fd032d), STCP(0x72552c85, 0x398cdd32), - STCP(0x720c8075, 0x3a1c5c57), STCP(0x71c3204c, 0x3aab7fb7), - STCP(0x71790c7e, 0x3b3a4672), STCP(0x712e457f, 0x3bc8afa5), - STCP(0x70e2cbc6, 0x3c56ba70), STCP(0x70969fca, 0x3ce465f3), - STCP(0x7049c203, 0x3d71b14d), STCP(0x6ffc32eb, 0x3dfe9ba1), - STCP(0x6fadf2fc, 0x3e8b240e), STCP(0x6f5f02b2, 0x3f1749b8), - STCP(0x6f0f6289, 0x3fa30bc1), STCP(0x6ebf12ff, 0x402e694c), - STCP(0x6e6e1492, 0x40b9617d), STCP(0x6e1c67c4, 0x4143f379), - STCP(0x6dca0d14, 0x41ce1e65), STCP(0x6d770506, 0x4257e166), - STCP(0x6d23501b, 0x42e13ba4), STCP(0x6cceeed8, 0x436a2c45), - STCP(0x6c79e1c2, 0x43f2b271), STCP(0x6c242960, 0x447acd50), - STCP(0x6bcdc639, 0x45027c0c), STCP(0x6b76b8d6, 0x4589bdcf), - STCP(0x6b1f01c0, 0x461091c2), STCP(0x6ac6a180, 0x4696f710), - STCP(0x6a6d98a4, 0x471cece7), STCP(0x6a13e7b8, 0x47a27271), - STCP(0x69b98f48, 0x482786dc), STCP(0x695e8fe5, 0x48ac2957), - STCP(0x6902ea1d, 0x4930590f), STCP(0x68a69e81, 0x49b41533), - STCP(0x6849ada3, 0x4a375cf5), STCP(0x67ec1817, 0x4aba2f84), - STCP(0x678dde6e, 0x4b3c8c12), STCP(0x672f013f, 0x4bbe71d1), - STCP(0x66cf8120, 0x4c3fdff4), STCP(0x666f5ea6, 0x4cc0d5ae), - STCP(0x660e9a6a, 0x4d415234), STCP(0x65ad3505, 0x4dc154bb), - STCP(0x654b2f10, 0x4e40dc79), STCP(0x64e88926, 0x4ebfe8a5), - STCP(0x648543e4, 0x4f3e7875), STCP(0x64215fe5, 0x4fbc8b22), - STCP(0x63bcddc7, 0x503a1fe5), STCP(0x6357be2a, 0x50b735f8), - STCP(0x62f201ac, 0x5133cc94), STCP(0x628ba8ef, 0x51afe2f6), - STCP(0x6224b495, 0x522b7859), STCP(0x61bd253f, 0x52a68bfb), - STCP(0x6154fb91, 0x53211d18), STCP(0x60ec3830, 0x539b2af0), - STCP(0x6082dbc1, 0x5414b4c1), STCP(0x6018e6eb, 0x548db9cb), - STCP(0x5fae5a55, 0x55063951), STCP(0x5f4336a7, 0x557e3292), - STCP(0x5ed77c8a, 0x55f5a4d2), STCP(0x5e6b2ca8, 0x566c8f55), - STCP(0x5dfe47ad, 0x56e2f15d), STCP(0x5d90ce45, 0x5758ca31), - STCP(0x5d22c11c, 0x57ce1917), STCP(0x5cb420e0, 0x5842dd54), - STCP(0x5c44ee40, 0x58b71632), STCP(0x5bd529eb, 0x592ac2f7), - STCP(0x5b64d492, 0x599de2ee), STCP(0x5af3eee6, 0x5a107561), - STCP(0x5a82799a, 0x5a82799a) +const PWord16 SineTable320[] = { + STCP( 0x7fffffff, 0x00000000 ), STCP( 0x7fff9aef, 0x00a0d951 ), + STCP( 0x7ffe6bbf, 0x0141b1a5 ), STCP( 0x7ffc726f, 0x01e287fc ), + STCP( 0x7ff9af04, 0x02835b5a ), STCP( 0x7ff62182, 0x03242abf ), + STCP( 0x7ff1c9ef, 0x03c4f52f ), STCP( 0x7feca851, 0x0465b9aa ), + STCP( 0x7fe6bcb0, 0x05067734 ), STCP( 0x7fe00716, 0x05a72ccf ), + STCP( 0x7fd8878e, 0x0647d97c ), STCP( 0x7fd03e23, 0x06e87c3f ), + STCP( 0x7fc72ae2, 0x07891418 ), STCP( 0x7fbd4dda, 0x0829a00c ), + STCP( 0x7fb2a71b, 0x08ca1f1b ), STCP( 0x7fa736b4, 0x096a9049 ), + STCP( 0x7f9afcb9, 0x0a0af299 ), STCP( 0x7f8df93c, 0x0aab450d ), + STCP( 0x7f802c52, 0x0b4b86a8 ), STCP( 0x7f719611, 0x0bebb66c ), + STCP( 0x7f62368f, 0x0c8bd35e ), STCP( 0x7f520de6, 0x0d2bdc80 ), + STCP( 0x7f411c2f, 0x0dcbd0d5 ), STCP( 0x7f2f6183, 0x0e6baf61 ), + STCP( 0x7f1cde01, 0x0f0b7727 ), STCP( 0x7f0991c4, 0x0fab272b ), + STCP( 0x7ef57cea, 0x104abe71 ), STCP( 0x7ee09f95, 0x10ea3bfd ), + STCP( 0x7ecaf9e5, 0x11899ed3 ), STCP( 0x7eb48bfb, 0x1228e5f8 ), + STCP( 0x7e9d55fc, 0x12c8106f ), STCP( 0x7e85580c, 0x13671d3d ), + STCP( 0x7e6c9251, 0x14060b68 ), STCP( 0x7e5304f2, 0x14a4d9f4 ), + STCP( 0x7e38b017, 0x154387e6 ), STCP( 0x7e1d93ea, 0x15e21445 ), + STCP( 0x7e01b096, 0x16807e15 ), STCP( 0x7de50646, 0x171ec45c ), + STCP( 0x7dc79529, 0x17bce621 ), STCP( 0x7da95d6c, 0x185ae269 ), + STCP( 0x7d8a5f40, 0x18f8b83c ), STCP( 0x7d6a9ad5, 0x199666a0 ), + STCP( 0x7d4a105d, 0x1a33ec9c ), STCP( 0x7d28c00c, 0x1ad14938 ), + STCP( 0x7d06aa16, 0x1b6e7b7a ), STCP( 0x7ce3ceb2, 0x1c0b826a ), + STCP( 0x7cc02e15, 0x1ca85d12 ), STCP( 0x7c9bc87a, 0x1d450a78 ), + STCP( 0x7c769e18, 0x1de189a6 ), STCP( 0x7c50af2b, 0x1e7dd9a4 ), + STCP( 0x7c29fbee, 0x1f19f97b ), STCP( 0x7c02849f, 0x1fb5e836 ), + STCP( 0x7bda497d, 0x2051a4dd ), STCP( 0x7bb14ac5, 0x20ed2e7b ), + STCP( 0x7b8788ba, 0x2188841a ), STCP( 0x7b5d039e, 0x2223a4c5 ), + STCP( 0x7b31bbb2, 0x22be8f87 ), STCP( 0x7b05b13d, 0x2359436c ), + STCP( 0x7ad8e482, 0x23f3bf7e ), STCP( 0x7aab55ca, 0x248e02cb ), + STCP( 0x7a7d055b, 0x25280c5e ), STCP( 0x7a4df380, 0x25c1db44 ), + STCP( 0x7a1e2082, 0x265b6e8a ), STCP( 0x79ed8cad, 0x26f4c53e ), + STCP( 0x79bc384d, 0x278dde6e ), STCP( 0x798a23b1, 0x2826b928 ), + STCP( 0x79574f28, 0x28bf547b ), STCP( 0x7923bb01, 0x2957af74 ), + STCP( 0x78ef678f, 0x29efc925 ), STCP( 0x78ba5524, 0x2a87a09d ), + STCP( 0x78848414, 0x2b1f34eb ), STCP( 0x784df4b3, 0x2bb68522 ), + STCP( 0x7816a759, 0x2c4d9050 ), STCP( 0x77de9c5b, 0x2ce45589 ), + STCP( 0x77a5d413, 0x2d7ad3de ), STCP( 0x776c4edb, 0x2e110a62 ), + STCP( 0x77320d0d, 0x2ea6f827 ), STCP( 0x76f70f05, 0x2f3c9c40 ), + STCP( 0x76bb5521, 0x2fd1f5c1 ), STCP( 0x767edfbe, 0x306703bf ), + STCP( 0x7641af3d, 0x30fbc54d ), STCP( 0x7603c3fd, 0x31903982 ), + STCP( 0x75c51e61, 0x32245f72 ), STCP( 0x7585becb, 0x32b83634 ), + STCP( 0x7545a5a0, 0x334bbcde ), STCP( 0x7504d345, 0x33def287 ), + STCP( 0x74c34820, 0x3471d647 ), STCP( 0x74810499, 0x35046736 ), + STCP( 0x743e0918, 0x3596a46c ), STCP( 0x73fa5607, 0x36288d03 ), + STCP( 0x73b5ebd1, 0x36ba2014 ), STCP( 0x7370cae2, 0x374b5cb9 ), + STCP( 0x732af3a7, 0x37dc420c ), STCP( 0x72e4668f, 0x386ccf2a ), + STCP( 0x729d2409, 0x38fd032d ), STCP( 0x72552c85, 0x398cdd32 ), + STCP( 0x720c8075, 0x3a1c5c57 ), STCP( 0x71c3204c, 0x3aab7fb7 ), + STCP( 0x71790c7e, 0x3b3a4672 ), STCP( 0x712e457f, 0x3bc8afa5 ), + STCP( 0x70e2cbc6, 0x3c56ba70 ), STCP( 0x70969fca, 0x3ce465f3 ), + STCP( 0x7049c203, 0x3d71b14d ), STCP( 0x6ffc32eb, 0x3dfe9ba1 ), + STCP( 0x6fadf2fc, 0x3e8b240e ), STCP( 0x6f5f02b2, 0x3f1749b8 ), + STCP( 0x6f0f6289, 0x3fa30bc1 ), STCP( 0x6ebf12ff, 0x402e694c ), + STCP( 0x6e6e1492, 0x40b9617d ), STCP( 0x6e1c67c4, 0x4143f379 ), + STCP( 0x6dca0d14, 0x41ce1e65 ), STCP( 0x6d770506, 0x4257e166 ), + STCP( 0x6d23501b, 0x42e13ba4 ), STCP( 0x6cceeed8, 0x436a2c45 ), + STCP( 0x6c79e1c2, 0x43f2b271 ), STCP( 0x6c242960, 0x447acd50 ), + STCP( 0x6bcdc639, 0x45027c0c ), STCP( 0x6b76b8d6, 0x4589bdcf ), + STCP( 0x6b1f01c0, 0x461091c2 ), STCP( 0x6ac6a180, 0x4696f710 ), + STCP( 0x6a6d98a4, 0x471cece7 ), STCP( 0x6a13e7b8, 0x47a27271 ), + STCP( 0x69b98f48, 0x482786dc ), STCP( 0x695e8fe5, 0x48ac2957 ), + STCP( 0x6902ea1d, 0x4930590f ), STCP( 0x68a69e81, 0x49b41533 ), + STCP( 0x6849ada3, 0x4a375cf5 ), STCP( 0x67ec1817, 0x4aba2f84 ), + STCP( 0x678dde6e, 0x4b3c8c12 ), STCP( 0x672f013f, 0x4bbe71d1 ), + STCP( 0x66cf8120, 0x4c3fdff4 ), STCP( 0x666f5ea6, 0x4cc0d5ae ), + STCP( 0x660e9a6a, 0x4d415234 ), STCP( 0x65ad3505, 0x4dc154bb ), + STCP( 0x654b2f10, 0x4e40dc79 ), STCP( 0x64e88926, 0x4ebfe8a5 ), + STCP( 0x648543e4, 0x4f3e7875 ), STCP( 0x64215fe5, 0x4fbc8b22 ), + STCP( 0x63bcddc7, 0x503a1fe5 ), STCP( 0x6357be2a, 0x50b735f8 ), + STCP( 0x62f201ac, 0x5133cc94 ), STCP( 0x628ba8ef, 0x51afe2f6 ), + STCP( 0x6224b495, 0x522b7859 ), STCP( 0x61bd253f, 0x52a68bfb ), + STCP( 0x6154fb91, 0x53211d18 ), STCP( 0x60ec3830, 0x539b2af0 ), + STCP( 0x6082dbc1, 0x5414b4c1 ), STCP( 0x6018e6eb, 0x548db9cb ), + STCP( 0x5fae5a55, 0x55063951 ), STCP( 0x5f4336a7, 0x557e3292 ), + STCP( 0x5ed77c8a, 0x55f5a4d2 ), STCP( 0x5e6b2ca8, 0x566c8f55 ), + STCP( 0x5dfe47ad, 0x56e2f15d ), STCP( 0x5d90ce45, 0x5758ca31 ), + STCP( 0x5d22c11c, 0x57ce1917 ), STCP( 0x5cb420e0, 0x5842dd54 ), + STCP( 0x5c44ee40, 0x58b71632 ), STCP( 0x5bd529eb, 0x592ac2f7 ), + STCP( 0x5b64d492, 0x599de2ee ), STCP( 0x5af3eee6, 0x5a107561 ), + STCP( 0x5a82799a, 0x5a82799a ) }; -#define WTC(x) WORD322WORD16(x) +#define WTC( x ) WORD322WORD16( x ) -#define WTCP(a,b) { { WTC(a), WTC(b) } } +#define WTCP( a, b ) \ + { \ + { \ + WTC( a ), WTC( b ) \ + } \ + } -const PWord16 SineWindow10[5] = -{ - WTCP(0x7f9afcb9, 0x0a0af299), WTCP(0x7c769e18, 0x1de189a6), WTCP(0x7641af3d, 0x30fbc54d), WTCP(0x6d23501b, 0x42e13ba4), - WTCP(0x6154fb91, 0x53211d18), +const PWord16 SineWindow10[5] = { + WTCP( 0x7f9afcb9, 0x0a0af299 ), + WTCP( 0x7c769e18, 0x1de189a6 ), + WTCP( 0x7641af3d, 0x30fbc54d ), + WTCP( 0x6d23501b, 0x42e13ba4 ), + WTCP( 0x6154fb91, 0x53211d18 ), }; -const PWord16 SineWindow16[8] = -{ - WTCP(0x7fd8878e, 0x0647d97c), WTCP(0x7e9d55fc, 0x12c8106f), WTCP(0x7c29fbee, 0x1f19f97b), WTCP(0x78848414, 0x2b1f34eb), - WTCP(0x73b5ebd1, 0x36ba2014), WTCP(0x6dca0d14, 0x41ce1e65), WTCP(0x66cf8120, 0x4c3fdff4), WTCP(0x5ed77c8a, 0x55f5a4d2), +const PWord16 SineWindow16[8] = { + WTCP( 0x7fd8878e, 0x0647d97c ), + WTCP( 0x7e9d55fc, 0x12c8106f ), + WTCP( 0x7c29fbee, 0x1f19f97b ), + WTCP( 0x78848414, 0x2b1f34eb ), + WTCP( 0x73b5ebd1, 0x36ba2014 ), + WTCP( 0x6dca0d14, 0x41ce1e65 ), + WTCP( 0x66cf8120, 0x4c3fdff4 ), + WTCP( 0x5ed77c8a, 0x55f5a4d2 ), }; -const PWord16 SineWindow20[10] = -{ - WTCP(0x7fe6bcb0, 0x05067734), WTCP(0x7f1cde01, 0x0f0b7727), WTCP(0x7d8a5f40, 0x18f8b83c), WTCP(0x7b31bbb2, 0x22be8f87), - WTCP(0x7816a759, 0x2c4d9050), WTCP(0x743e0918, 0x3596a46c), WTCP(0x6fadf2fc, 0x3e8b240e), WTCP(0x6a6d98a4, 0x471cece7), - WTCP(0x648543e4, 0x4f3e7875), WTCP(0x5dfe47ad, 0x56e2f15d), +const PWord16 SineWindow20[10] = { + WTCP( 0x7fe6bcb0, 0x05067734 ), + WTCP( 0x7f1cde01, 0x0f0b7727 ), + WTCP( 0x7d8a5f40, 0x18f8b83c ), + WTCP( 0x7b31bbb2, 0x22be8f87 ), + WTCP( 0x7816a759, 0x2c4d9050 ), + WTCP( 0x743e0918, 0x3596a46c ), + WTCP( 0x6fadf2fc, 0x3e8b240e ), + WTCP( 0x6a6d98a4, 0x471cece7 ), + WTCP( 0x648543e4, 0x4f3e7875 ), + WTCP( 0x5dfe47ad, 0x56e2f15d ), }; -const PWord16 SineWindow30[15] = -{ - WTCP(0x7ff4c56f, 0x0359c428), WTCP(0x7f9afcb9, 0x0a0af299), WTCP(0x7ee7aa4c, 0x10b5150f), WTCP(0x7ddb4bfc, 0x17537e63), - WTCP(0x7c769e18, 0x1de189a6), WTCP(0x7aba9ae6, 0x245a9d65), WTCP(0x78a879f4, 0x2aba2ee4), WTCP(0x7641af3d, 0x30fbc54d), - WTCP(0x7387ea23, 0x371afcd5), WTCP(0x707d1443, 0x3d1389cb), WTCP(0x6d23501b, 0x42e13ba4), WTCP(0x697cf78a, 0x487fffe4), - WTCP(0x658c9a2d, 0x4debe4fe), WTCP(0x6154fb91, 0x53211d18), WTCP(0x5cd91140, 0x581c00b3), +const PWord16 SineWindow30[15] = { + WTCP( 0x7ff4c56f, 0x0359c428 ), + WTCP( 0x7f9afcb9, 0x0a0af299 ), + WTCP( 0x7ee7aa4c, 0x10b5150f ), + WTCP( 0x7ddb4bfc, 0x17537e63 ), + WTCP( 0x7c769e18, 0x1de189a6 ), + WTCP( 0x7aba9ae6, 0x245a9d65 ), + WTCP( 0x78a879f4, 0x2aba2ee4 ), + WTCP( 0x7641af3d, 0x30fbc54d ), + WTCP( 0x7387ea23, 0x371afcd5 ), + WTCP( 0x707d1443, 0x3d1389cb ), + WTCP( 0x6d23501b, 0x42e13ba4 ), + WTCP( 0x697cf78a, 0x487fffe4 ), + WTCP( 0x658c9a2d, 0x4debe4fe ), + WTCP( 0x6154fb91, 0x53211d18 ), + WTCP( 0x5cd91140, 0x581c00b3 ), }; -const PWord16 SineWindow32[16] = -{ - WTCP(0x7ff62182, 0x03242abf), WTCP(0x7fa736b4, 0x096a9049), WTCP(0x7f0991c4, 0x0fab272b), WTCP(0x7e1d93ea, 0x15e21445), - WTCP(0x7ce3ceb2, 0x1c0b826a), WTCP(0x7b5d039e, 0x2223a4c5), WTCP(0x798a23b1, 0x2826b928), WTCP(0x776c4edb, 0x2e110a62), - WTCP(0x7504d345, 0x33def287), WTCP(0x72552c85, 0x398cdd32), WTCP(0x6f5f02b2, 0x3f1749b8), WTCP(0x6c242960, 0x447acd50), - WTCP(0x68a69e81, 0x49b41533), WTCP(0x64e88926, 0x4ebfe8a5), WTCP(0x60ec3830, 0x539b2af0), WTCP(0x5cb420e0, 0x5842dd54) +const PWord16 SineWindow32[16] = { + WTCP( 0x7ff62182, 0x03242abf ), WTCP( 0x7fa736b4, 0x096a9049 ), WTCP( 0x7f0991c4, 0x0fab272b ), WTCP( 0x7e1d93ea, 0x15e21445 ), + WTCP( 0x7ce3ceb2, 0x1c0b826a ), WTCP( 0x7b5d039e, 0x2223a4c5 ), WTCP( 0x798a23b1, 0x2826b928 ), WTCP( 0x776c4edb, 0x2e110a62 ), + WTCP( 0x7504d345, 0x33def287 ), WTCP( 0x72552c85, 0x398cdd32 ), WTCP( 0x6f5f02b2, 0x3f1749b8 ), WTCP( 0x6c242960, 0x447acd50 ), + WTCP( 0x68a69e81, 0x49b41533 ), WTCP( 0x64e88926, 0x4ebfe8a5 ), WTCP( 0x60ec3830, 0x539b2af0 ), WTCP( 0x5cb420e0, 0x5842dd54 ) }; -const PWord16 SineWindow40[20] = -{ - WTCP(0x7ff9af04, 0x02835b5a), WTCP(0x7fc72ae2, 0x07891418), WTCP(0x7f62368f, 0x0c8bd35e), WTCP(0x7ecaf9e5, 0x11899ed3), - WTCP(0x7e01b096, 0x16807e15), WTCP(0x7d06aa16, 0x1b6e7b7a), WTCP(0x7bda497d, 0x2051a4dd), WTCP(0x7a7d055b, 0x25280c5e), - WTCP(0x78ef678f, 0x29efc925), WTCP(0x77320d0d, 0x2ea6f827), WTCP(0x7545a5a0, 0x334bbcde), WTCP(0x732af3a7, 0x37dc420c), - WTCP(0x70e2cbc6, 0x3c56ba70), WTCP(0x6e6e1492, 0x40b9617d), WTCP(0x6bcdc639, 0x45027c0c), WTCP(0x6902ea1d, 0x4930590f), - WTCP(0x660e9a6a, 0x4d415234), WTCP(0x62f201ac, 0x5133cc94), WTCP(0x5fae5a55, 0x55063951), WTCP(0x5c44ee40, 0x58b71632), +const PWord16 SineWindow40[20] = { + WTCP( 0x7ff9af04, 0x02835b5a ), + WTCP( 0x7fc72ae2, 0x07891418 ), + WTCP( 0x7f62368f, 0x0c8bd35e ), + WTCP( 0x7ecaf9e5, 0x11899ed3 ), + WTCP( 0x7e01b096, 0x16807e15 ), + WTCP( 0x7d06aa16, 0x1b6e7b7a ), + WTCP( 0x7bda497d, 0x2051a4dd ), + WTCP( 0x7a7d055b, 0x25280c5e ), + WTCP( 0x78ef678f, 0x29efc925 ), + WTCP( 0x77320d0d, 0x2ea6f827 ), + WTCP( 0x7545a5a0, 0x334bbcde ), + WTCP( 0x732af3a7, 0x37dc420c ), + WTCP( 0x70e2cbc6, 0x3c56ba70 ), + WTCP( 0x6e6e1492, 0x40b9617d ), + WTCP( 0x6bcdc639, 0x45027c0c ), + WTCP( 0x6902ea1d, 0x4930590f ), + WTCP( 0x660e9a6a, 0x4d415234 ), + WTCP( 0x62f201ac, 0x5133cc94 ), + WTCP( 0x5fae5a55, 0x55063951 ), + WTCP( 0x5c44ee40, 0x58b71632 ), }; -const PWord16 SineWindow48[24] = -{ - WTCP(0x7ffb9d15, 0x02182427), WTCP(0x7fd8878e, 0x0647d97c), WTCP(0x7f92661d, 0x0a75d60e), WTCP(0x7f294bfd, 0x0ea0f48c), - WTCP(0x7e9d55fc, 0x12c8106f), WTCP(0x7deeaa7a, 0x16ea0646), WTCP(0x7d1d7958, 0x1b05b40f), WTCP(0x7c29fbee, 0x1f19f97b), - WTCP(0x7b1474fd, 0x2325b847), WTCP(0x79dd3098, 0x2727d486), WTCP(0x78848414, 0x2b1f34eb), WTCP(0x770acdec, 0x2f0ac320), - WTCP(0x757075ac, 0x32e96c09), WTCP(0x73b5ebd1, 0x36ba2014), WTCP(0x71dba9ab, 0x3a7bd382), WTCP(0x6fe2313c, 0x3e2d7eb1), - WTCP(0x6dca0d14, 0x41ce1e65), WTCP(0x6b93d02e, 0x455cb40c), WTCP(0x694015c3, 0x48d84609), WTCP(0x66cf8120, 0x4c3fdff4), - WTCP(0x6442bd7e, 0x4f9292dc), WTCP(0x619a7dce, 0x52cf758f), WTCP(0x5ed77c8a, 0x55f5a4d2), WTCP(0x5bfa7b82, 0x590443a7) +const PWord16 SineWindow48[24] = { + WTCP( 0x7ffb9d15, 0x02182427 ), WTCP( 0x7fd8878e, 0x0647d97c ), WTCP( 0x7f92661d, 0x0a75d60e ), WTCP( 0x7f294bfd, 0x0ea0f48c ), + WTCP( 0x7e9d55fc, 0x12c8106f ), WTCP( 0x7deeaa7a, 0x16ea0646 ), WTCP( 0x7d1d7958, 0x1b05b40f ), WTCP( 0x7c29fbee, 0x1f19f97b ), + WTCP( 0x7b1474fd, 0x2325b847 ), WTCP( 0x79dd3098, 0x2727d486 ), WTCP( 0x78848414, 0x2b1f34eb ), WTCP( 0x770acdec, 0x2f0ac320 ), + WTCP( 0x757075ac, 0x32e96c09 ), WTCP( 0x73b5ebd1, 0x36ba2014 ), WTCP( 0x71dba9ab, 0x3a7bd382 ), WTCP( 0x6fe2313c, 0x3e2d7eb1 ), + WTCP( 0x6dca0d14, 0x41ce1e65 ), WTCP( 0x6b93d02e, 0x455cb40c ), WTCP( 0x694015c3, 0x48d84609 ), WTCP( 0x66cf8120, 0x4c3fdff4 ), + WTCP( 0x6442bd7e, 0x4f9292dc ), WTCP( 0x619a7dce, 0x52cf758f ), WTCP( 0x5ed77c8a, 0x55f5a4d2 ), WTCP( 0x5bfa7b82, 0x590443a7 ) }; -const PWord16 SineWindow60[60] = -{ - WTCP(0x7ffd3154, 0x01aceb7c), WTCP(0x7fe6bcb0, 0x05067734), WTCP(0x7fb9d759, 0x085f2137), WTCP(0x7f76892f, 0x0bb65336), - WTCP(0x7f1cde01, 0x0f0b7727), WTCP(0x7eace58a, 0x125df75b), WTCP(0x7e26b371, 0x15ad3e9a), WTCP(0x7d8a5f40, 0x18f8b83c), - WTCP(0x7cd80464, 0x1c3fd045), WTCP(0x7c0fc22a, 0x1f81f37c), WTCP(0x7b31bbb2, 0x22be8f87), WTCP(0x7a3e17f2, 0x25f51307), - WTCP(0x793501a9, 0x2924edac), WTCP(0x7816a759, 0x2c4d9050), WTCP(0x76e33b3f, 0x2f6e6d16), WTCP(0x759af34c, 0x3286f779), - WTCP(0x743e0918, 0x3596a46c), WTCP(0x72ccb9db, 0x389cea72), WTCP(0x71474660, 0x3b9941b1), WTCP(0x6fadf2fc, 0x3e8b240e), - WTCP(0x6e010780, 0x41720d46), WTCP(0x6c40cf2c, 0x444d7aff), WTCP(0x6a6d98a4, 0x471cece7), WTCP(0x6887b5e2, 0x49dfe4c2), - WTCP(0x668f7c25, 0x4c95e688), WTCP(0x648543e4, 0x4f3e7875), WTCP(0x626968be, 0x51d92321), WTCP(0x603c496c, 0x54657194), - WTCP(0x5dfe47ad, 0x56e2f15d), WTCP(0x5bafc837, 0x595132a2), +const PWord16 SineWindow60[60] = { + WTCP( 0x7ffd3154, 0x01aceb7c ), + WTCP( 0x7fe6bcb0, 0x05067734 ), + WTCP( 0x7fb9d759, 0x085f2137 ), + WTCP( 0x7f76892f, 0x0bb65336 ), + WTCP( 0x7f1cde01, 0x0f0b7727 ), + WTCP( 0x7eace58a, 0x125df75b ), + WTCP( 0x7e26b371, 0x15ad3e9a ), + WTCP( 0x7d8a5f40, 0x18f8b83c ), + WTCP( 0x7cd80464, 0x1c3fd045 ), + WTCP( 0x7c0fc22a, 0x1f81f37c ), + WTCP( 0x7b31bbb2, 0x22be8f87 ), + WTCP( 0x7a3e17f2, 0x25f51307 ), + WTCP( 0x793501a9, 0x2924edac ), + WTCP( 0x7816a759, 0x2c4d9050 ), + WTCP( 0x76e33b3f, 0x2f6e6d16 ), + WTCP( 0x759af34c, 0x3286f779 ), + WTCP( 0x743e0918, 0x3596a46c ), + WTCP( 0x72ccb9db, 0x389cea72 ), + WTCP( 0x71474660, 0x3b9941b1 ), + WTCP( 0x6fadf2fc, 0x3e8b240e ), + WTCP( 0x6e010780, 0x41720d46 ), + WTCP( 0x6c40cf2c, 0x444d7aff ), + WTCP( 0x6a6d98a4, 0x471cece7 ), + WTCP( 0x6887b5e2, 0x49dfe4c2 ), + WTCP( 0x668f7c25, 0x4c95e688 ), + WTCP( 0x648543e4, 0x4f3e7875 ), + WTCP( 0x626968be, 0x51d92321 ), + WTCP( 0x603c496c, 0x54657194 ), + WTCP( 0x5dfe47ad, 0x56e2f15d ), + WTCP( 0x5bafc837, 0x595132a2 ), }; -const PWord16 SineWindow64[32] = -{ - WTCP(0x7ffd885a, 0x01921d20), WTCP(0x7fe9cbc0, 0x04b6195d), WTCP(0x7fc25596, 0x07d95b9e), WTCP(0x7f872bf3, 0x0afb6805), - WTCP(0x7f3857f6, 0x0e1bc2e4), WTCP(0x7ed5e5c6, 0x1139f0cf), WTCP(0x7e5fe493, 0x145576b1), WTCP(0x7dd6668f, 0x176dd9de), - WTCP(0x7d3980ec, 0x1a82a026), WTCP(0x7c894bde, 0x1d934fe5), WTCP(0x7bc5e290, 0x209f701c), WTCP(0x7aef6323, 0x23a6887f), - WTCP(0x7a05eead, 0x26a82186), WTCP(0x7909a92d, 0x29a3c485), WTCP(0x77fab989, 0x2c98fbba), WTCP(0x76d94989, 0x2f875262), - WTCP(0x75a585cf, 0x326e54c7), WTCP(0x745f9dd1, 0x354d9057), WTCP(0x7307c3d0, 0x382493b0), WTCP(0x719e2cd2, 0x3af2eeb7), - WTCP(0x7023109a, 0x3db832a6), WTCP(0x6e96a99d, 0x4073f21d), WTCP(0x6cf934fc, 0x4325c135), WTCP(0x6b4af279, 0x45cd358f), - WTCP(0x698c246c, 0x4869e665), WTCP(0x67bd0fbd, 0x4afb6c98), WTCP(0x65ddfbd3, 0x4d8162c4), WTCP(0x63ef3290, 0x4ffb654d), - WTCP(0x61f1003f, 0x5269126e), WTCP(0x5fe3b38d, 0x54ca0a4b), WTCP(0x5dc79d7c, 0x571deefa), WTCP(0x5b9d1154, 0x59646498), +const PWord16 SineWindow64[32] = { + WTCP( 0x7ffd885a, 0x01921d20 ), + WTCP( 0x7fe9cbc0, 0x04b6195d ), + WTCP( 0x7fc25596, 0x07d95b9e ), + WTCP( 0x7f872bf3, 0x0afb6805 ), + WTCP( 0x7f3857f6, 0x0e1bc2e4 ), + WTCP( 0x7ed5e5c6, 0x1139f0cf ), + WTCP( 0x7e5fe493, 0x145576b1 ), + WTCP( 0x7dd6668f, 0x176dd9de ), + WTCP( 0x7d3980ec, 0x1a82a026 ), + WTCP( 0x7c894bde, 0x1d934fe5 ), + WTCP( 0x7bc5e290, 0x209f701c ), + WTCP( 0x7aef6323, 0x23a6887f ), + WTCP( 0x7a05eead, 0x26a82186 ), + WTCP( 0x7909a92d, 0x29a3c485 ), + WTCP( 0x77fab989, 0x2c98fbba ), + WTCP( 0x76d94989, 0x2f875262 ), + WTCP( 0x75a585cf, 0x326e54c7 ), + WTCP( 0x745f9dd1, 0x354d9057 ), + WTCP( 0x7307c3d0, 0x382493b0 ), + WTCP( 0x719e2cd2, 0x3af2eeb7 ), + WTCP( 0x7023109a, 0x3db832a6 ), + WTCP( 0x6e96a99d, 0x4073f21d ), + WTCP( 0x6cf934fc, 0x4325c135 ), + WTCP( 0x6b4af279, 0x45cd358f ), + WTCP( 0x698c246c, 0x4869e665 ), + WTCP( 0x67bd0fbd, 0x4afb6c98 ), + WTCP( 0x65ddfbd3, 0x4d8162c4 ), + WTCP( 0x63ef3290, 0x4ffb654d ), + WTCP( 0x61f1003f, 0x5269126e ), + WTCP( 0x5fe3b38d, 0x54ca0a4b ), + WTCP( 0x5dc79d7c, 0x571deefa ), + WTCP( 0x5b9d1154, 0x59646498 ), }; -const PWord16 SineWindow80[40] = -{ - WTCP(0x7ffe6bbf, 0x0141b1a5), WTCP(0x7ff1c9ef, 0x03c4f52f), WTCP(0x7fd8878e, 0x0647d97c), WTCP(0x7fb2a71b, 0x08ca1f1b), - WTCP(0x7f802c52, 0x0b4b86a8), WTCP(0x7f411c2f, 0x0dcbd0d5), WTCP(0x7ef57cea, 0x104abe71), WTCP(0x7e9d55fc, 0x12c8106f), - WTCP(0x7e38b017, 0x154387e6), WTCP(0x7dc79529, 0x17bce621), WTCP(0x7d4a105d, 0x1a33ec9c), WTCP(0x7cc02e15, 0x1ca85d12), - WTCP(0x7c29fbee, 0x1f19f97b), WTCP(0x7b8788ba, 0x2188841a), WTCP(0x7ad8e482, 0x23f3bf7e), WTCP(0x7a1e2082, 0x265b6e8a), - WTCP(0x79574f28, 0x28bf547b), WTCP(0x78848414, 0x2b1f34eb), WTCP(0x77a5d413, 0x2d7ad3de), WTCP(0x76bb5521, 0x2fd1f5c1), - WTCP(0x75c51e61, 0x32245f72), WTCP(0x74c34820, 0x3471d647), WTCP(0x73b5ebd1, 0x36ba2014), WTCP(0x729d2409, 0x38fd032d), - WTCP(0x71790c7e, 0x3b3a4672), WTCP(0x7049c203, 0x3d71b14d), WTCP(0x6f0f6289, 0x3fa30bc1), WTCP(0x6dca0d14, 0x41ce1e65), - WTCP(0x6c79e1c2, 0x43f2b271), WTCP(0x6b1f01c0, 0x461091c2), WTCP(0x69b98f48, 0x482786dc), WTCP(0x6849ada3, 0x4a375cf5), - WTCP(0x66cf8120, 0x4c3fdff4), WTCP(0x654b2f10, 0x4e40dc79), WTCP(0x63bcddc7, 0x503a1fe5), WTCP(0x6224b495, 0x522b7859), - WTCP(0x6082dbc1, 0x5414b4c1), WTCP(0x5ed77c8a, 0x55f5a4d2), WTCP(0x5d22c11c, 0x57ce1917), WTCP(0x5b64d492, 0x599de2ee), +const PWord16 SineWindow80[40] = { + WTCP( 0x7ffe6bbf, 0x0141b1a5 ), + WTCP( 0x7ff1c9ef, 0x03c4f52f ), + WTCP( 0x7fd8878e, 0x0647d97c ), + WTCP( 0x7fb2a71b, 0x08ca1f1b ), + WTCP( 0x7f802c52, 0x0b4b86a8 ), + WTCP( 0x7f411c2f, 0x0dcbd0d5 ), + WTCP( 0x7ef57cea, 0x104abe71 ), + WTCP( 0x7e9d55fc, 0x12c8106f ), + WTCP( 0x7e38b017, 0x154387e6 ), + WTCP( 0x7dc79529, 0x17bce621 ), + WTCP( 0x7d4a105d, 0x1a33ec9c ), + WTCP( 0x7cc02e15, 0x1ca85d12 ), + WTCP( 0x7c29fbee, 0x1f19f97b ), + WTCP( 0x7b8788ba, 0x2188841a ), + WTCP( 0x7ad8e482, 0x23f3bf7e ), + WTCP( 0x7a1e2082, 0x265b6e8a ), + WTCP( 0x79574f28, 0x28bf547b ), + WTCP( 0x78848414, 0x2b1f34eb ), + WTCP( 0x77a5d413, 0x2d7ad3de ), + WTCP( 0x76bb5521, 0x2fd1f5c1 ), + WTCP( 0x75c51e61, 0x32245f72 ), + WTCP( 0x74c34820, 0x3471d647 ), + WTCP( 0x73b5ebd1, 0x36ba2014 ), + WTCP( 0x729d2409, 0x38fd032d ), + WTCP( 0x71790c7e, 0x3b3a4672 ), + WTCP( 0x7049c203, 0x3d71b14d ), + WTCP( 0x6f0f6289, 0x3fa30bc1 ), + WTCP( 0x6dca0d14, 0x41ce1e65 ), + WTCP( 0x6c79e1c2, 0x43f2b271 ), + WTCP( 0x6b1f01c0, 0x461091c2 ), + WTCP( 0x69b98f48, 0x482786dc ), + WTCP( 0x6849ada3, 0x4a375cf5 ), + WTCP( 0x66cf8120, 0x4c3fdff4 ), + WTCP( 0x654b2f10, 0x4e40dc79 ), + WTCP( 0x63bcddc7, 0x503a1fe5 ), + WTCP( 0x6224b495, 0x522b7859 ), + WTCP( 0x6082dbc1, 0x5414b4c1 ), + WTCP( 0x5ed77c8a, 0x55f5a4d2 ), + WTCP( 0x5d22c11c, 0x57ce1917 ), + WTCP( 0x5b64d492, 0x599de2ee ), }; -const PWord16 SineWindow70[35] = -{ - WTCP(0x7ffdeffe, 0x016fa5fd), WTCP(0x7fed7058, 0x044ec292), WTCP(0x7fcc732b, 0x072d5101), WTCP(0x7f9afcb9, 0x0a0af299), - WTCP(0x7f591361, 0x0ce748ca), WTCP(0x7f06bfa3, 0x0fc1f52d), WTCP(0x7ea40c1b, 0x129a9991), WTCP(0x7e310583, 0x1570d80b), - WTCP(0x7dadbaaf, 0x184452fd), WTCP(0x7d1a3c8a, 0x1b14ad24), WTCP(0x7c769e18, 0x1de189a6), WTCP(0x7bc2f470, 0x20aa8c19), - WTCP(0x7aff56bc, 0x236f5896), WTCP(0x7a2bde32, 0x262f93be), WTCP(0x7948a614, 0x28eae2cb), WTCP(0x7855cbae, 0x2ba0eb97), - WTCP(0x77536e4c, 0x2e5154ac), WTCP(0x7641af3d, 0x30fbc54d), WTCP(0x7520b1ca, 0x339fe582), WTCP(0x73f09b33, 0x363d5e23), - WTCP(0x72b192ac, 0x38d3d8e3), WTCP(0x7163c154, 0x3b63005e), WTCP(0x70075233, 0x3dea8020), WTCP(0x6e9c7233, 0x406a04b2), - WTCP(0x6d23501b, 0x42e13ba4), WTCP(0x6b9c1c87, 0x454fd398), WTCP(0x6a0709e6, 0x47b57c4e), WTCP(0x68644c6e, 0x4a11e6aa), - WTCP(0x66b41a1a, 0x4c64c4c4), WTCP(0x64f6aa9f, 0x4eadc9ee), WTCP(0x632c3769, 0x50ecaabd), WTCP(0x6154fb91, 0x53211d18), - WTCP(0x5f7133d4, 0x554ad83c), WTCP(0x5d811e90, 0x576994c8), WTCP(0x5b84fbb6, 0x597d0cc7) +const PWord16 SineWindow70[35] = { + WTCP( 0x7ffdeffe, 0x016fa5fd ), WTCP( 0x7fed7058, 0x044ec292 ), WTCP( 0x7fcc732b, 0x072d5101 ), WTCP( 0x7f9afcb9, 0x0a0af299 ), + WTCP( 0x7f591361, 0x0ce748ca ), WTCP( 0x7f06bfa3, 0x0fc1f52d ), WTCP( 0x7ea40c1b, 0x129a9991 ), WTCP( 0x7e310583, 0x1570d80b ), + WTCP( 0x7dadbaaf, 0x184452fd ), WTCP( 0x7d1a3c8a, 0x1b14ad24 ), WTCP( 0x7c769e18, 0x1de189a6 ), WTCP( 0x7bc2f470, 0x20aa8c19 ), + WTCP( 0x7aff56bc, 0x236f5896 ), WTCP( 0x7a2bde32, 0x262f93be ), WTCP( 0x7948a614, 0x28eae2cb ), WTCP( 0x7855cbae, 0x2ba0eb97 ), + WTCP( 0x77536e4c, 0x2e5154ac ), WTCP( 0x7641af3d, 0x30fbc54d ), WTCP( 0x7520b1ca, 0x339fe582 ), WTCP( 0x73f09b33, 0x363d5e23 ), + WTCP( 0x72b192ac, 0x38d3d8e3 ), WTCP( 0x7163c154, 0x3b63005e ), WTCP( 0x70075233, 0x3dea8020 ), WTCP( 0x6e9c7233, 0x406a04b2 ), + WTCP( 0x6d23501b, 0x42e13ba4 ), WTCP( 0x6b9c1c87, 0x454fd398 ), WTCP( 0x6a0709e6, 0x47b57c4e ), WTCP( 0x68644c6e, 0x4a11e6aa ), + WTCP( 0x66b41a1a, 0x4c64c4c4 ), WTCP( 0x64f6aa9f, 0x4eadc9ee ), WTCP( 0x632c3769, 0x50ecaabd ), WTCP( 0x6154fb91, 0x53211d18 ), + WTCP( 0x5f7133d4, 0x554ad83c ), WTCP( 0x5d811e90, 0x576994c8 ), WTCP( 0x5b84fbb6, 0x597d0cc7 ) }; -const PWord16 SineWindow96[48] = -{ - WTCP(0x7ffee744, 0x010c1460), WTCP(0x7ff62182, 0x03242abf), WTCP(0x7fe49698, 0x053c0a01), WTCP(0x7fca47b9, 0x07538d6b), - WTCP(0x7fa736b4, 0x096a9049), WTCP(0x7f7b65ef, 0x0b80edf1), WTCP(0x7f46d86c, 0x0d9681c2), WTCP(0x7f0991c4, 0x0fab272b), - WTCP(0x7ec3962a, 0x11beb9aa), WTCP(0x7e74ea6a, 0x13d114d0), WTCP(0x7e1d93ea, 0x15e21445), WTCP(0x7dbd98a4, 0x17f193c5), - WTCP(0x7d54ff2e, 0x19ff6f2a), WTCP(0x7ce3ceb2, 0x1c0b826a), WTCP(0x7c6a0ef2, 0x1e15a99a), WTCP(0x7be7c847, 0x201dc0ef), - WTCP(0x7b5d039e, 0x2223a4c5), WTCP(0x7ac9ca7a, 0x2427319d), WTCP(0x7a2e26f2, 0x26284422), WTCP(0x798a23b1, 0x2826b928), - WTCP(0x78ddcbf5, 0x2a226db5), WTCP(0x78292b8d, 0x2c1b3efb), WTCP(0x776c4edb, 0x2e110a62), WTCP(0x76a742d1, 0x3003ad85), - WTCP(0x75da14ef, 0x31f30638), WTCP(0x7504d345, 0x33def287), WTCP(0x74278c72, 0x35c750bc), WTCP(0x73424fa0, 0x37abff5d), - WTCP(0x72552c85, 0x398cdd32), WTCP(0x71603361, 0x3b69c947), WTCP(0x706374ff, 0x3d42a2ec), WTCP(0x6f5f02b2, 0x3f1749b8), - WTCP(0x6e52ee52, 0x40e79d8c), WTCP(0x6d3f4a40, 0x42b37e96), WTCP(0x6c242960, 0x447acd50), WTCP(0x6b019f1a, 0x463d6a87), - WTCP(0x69d7bf57, 0x47fb3757), WTCP(0x68a69e81, 0x49b41533), WTCP(0x676e5183, 0x4b67e5e4), WTCP(0x662eedc3, 0x4d168b8b), - WTCP(0x64e88926, 0x4ebfe8a5), WTCP(0x639b3a0b, 0x5063e008), WTCP(0x62471749, 0x520254ef), WTCP(0x60ec3830, 0x539b2af0), - WTCP(0x5f8ab487, 0x552e4605), WTCP(0x5e22a487, 0x56bb8a90), WTCP(0x5cb420e0, 0x5842dd54), WTCP(0x5b3f42ae, 0x59c42381) +const PWord16 SineWindow96[48] = { + WTCP( 0x7ffee744, 0x010c1460 ), WTCP( 0x7ff62182, 0x03242abf ), WTCP( 0x7fe49698, 0x053c0a01 ), WTCP( 0x7fca47b9, 0x07538d6b ), + WTCP( 0x7fa736b4, 0x096a9049 ), WTCP( 0x7f7b65ef, 0x0b80edf1 ), WTCP( 0x7f46d86c, 0x0d9681c2 ), WTCP( 0x7f0991c4, 0x0fab272b ), + WTCP( 0x7ec3962a, 0x11beb9aa ), WTCP( 0x7e74ea6a, 0x13d114d0 ), WTCP( 0x7e1d93ea, 0x15e21445 ), WTCP( 0x7dbd98a4, 0x17f193c5 ), + WTCP( 0x7d54ff2e, 0x19ff6f2a ), WTCP( 0x7ce3ceb2, 0x1c0b826a ), WTCP( 0x7c6a0ef2, 0x1e15a99a ), WTCP( 0x7be7c847, 0x201dc0ef ), + WTCP( 0x7b5d039e, 0x2223a4c5 ), WTCP( 0x7ac9ca7a, 0x2427319d ), WTCP( 0x7a2e26f2, 0x26284422 ), WTCP( 0x798a23b1, 0x2826b928 ), + WTCP( 0x78ddcbf5, 0x2a226db5 ), WTCP( 0x78292b8d, 0x2c1b3efb ), WTCP( 0x776c4edb, 0x2e110a62 ), WTCP( 0x76a742d1, 0x3003ad85 ), + WTCP( 0x75da14ef, 0x31f30638 ), WTCP( 0x7504d345, 0x33def287 ), WTCP( 0x74278c72, 0x35c750bc ), WTCP( 0x73424fa0, 0x37abff5d ), + WTCP( 0x72552c85, 0x398cdd32 ), WTCP( 0x71603361, 0x3b69c947 ), WTCP( 0x706374ff, 0x3d42a2ec ), WTCP( 0x6f5f02b2, 0x3f1749b8 ), + WTCP( 0x6e52ee52, 0x40e79d8c ), WTCP( 0x6d3f4a40, 0x42b37e96 ), WTCP( 0x6c242960, 0x447acd50 ), WTCP( 0x6b019f1a, 0x463d6a87 ), + WTCP( 0x69d7bf57, 0x47fb3757 ), WTCP( 0x68a69e81, 0x49b41533 ), WTCP( 0x676e5183, 0x4b67e5e4 ), WTCP( 0x662eedc3, 0x4d168b8b ), + WTCP( 0x64e88926, 0x4ebfe8a5 ), WTCP( 0x639b3a0b, 0x5063e008 ), WTCP( 0x62471749, 0x520254ef ), WTCP( 0x60ec3830, 0x539b2af0 ), + WTCP( 0x5f8ab487, 0x552e4605 ), WTCP( 0x5e22a487, 0x56bb8a90 ), WTCP( 0x5cb420e0, 0x5842dd54 ), WTCP( 0x5b3f42ae, 0x59c42381 ) }; -const PWord16 SineWindow112[56] = -{ - WTCP(0x7fff31bf, 0x00e5c87e), WTCP(0x7ff8bfc7, 0x02b14de9), WTCP(0x7febdc2a, 0x047cb09e), WTCP(0x7fd8878e, 0x0647d97c), - WTCP(0x7fbec2ec, 0x0812b164), WTCP(0x7f9e8f91, 0x09dd213a), WTCP(0x7f77ef1c, 0x0ba711ea), WTCP(0x7f4ae37e, 0x0d706c64), - WTCP(0x7f176efc, 0x0f3919a0), WTCP(0x7edd942d, 0x110102a0), WTCP(0x7e9d55fc, 0x12c8106f), WTCP(0x7e56b7a4, 0x148e2c22), - WTCP(0x7e09bcb4, 0x16533edc), WTCP(0x7db6690c, 0x181731cd), WTCP(0x7d5cc0df, 0x19d9ee32), WTCP(0x7cfcc8af, 0x1b9b5d5a), - WTCP(0x7c968552, 0x1d5b68a2), WTCP(0x7c29fbee, 0x1f19f97b), WTCP(0x7bb731fb, 0x20d6f969), WTCP(0x7b3e2d40, 0x22925203), - WTCP(0x7abef3d5, 0x244becf6), WTCP(0x7a398c22, 0x2603b406), WTCP(0x79adfcdf, 0x27b9910e), WTCP(0x791c4d13, 0x296d6e00), - WTCP(0x78848414, 0x2b1f34eb), WTCP(0x77e6a986, 0x2ccecff7), WTCP(0x7742c55c, 0x2e7c2969), WTCP(0x7698dfd8, 0x30272ba0), - WTCP(0x75e90186, 0x31cfc11e), WTCP(0x75333343, 0x3375d481), WTCP(0x74777e35, 0x35195088), WTCP(0x73b5ebd1, 0x36ba2014), - WTCP(0x72ee85d5, 0x38582e27), WTCP(0x7221564d, 0x39f365e9), WTCP(0x714e678c, 0x3b8bb2a3), WTCP(0x7075c433, 0x3d20ffc8), - WTCP(0x6f977729, 0x3eb338ef), WTCP(0x6eb38ba1, 0x404249d5), WTCP(0x6dca0d14, 0x41ce1e65), WTCP(0x6cdb0745, 0x4356a2ad), - WTCP(0x6be6863c, 0x44dbc2ec), WTCP(0x6aec9649, 0x465d6b89), WTCP(0x69ed4403, 0x47db8918), WTCP(0x68e89c43, 0x4956085b), - WTCP(0x67deac2c, 0x4accd644), WTCP(0x66cf8120, 0x4c3fdff4), WTCP(0x65bb28c7, 0x4daf12ba), WTCP(0x64a1b10b, 0x4f1a5c1a), - WTCP(0x6383281a, 0x5081a9c9), WTCP(0x625f9c5f, 0x51e4e9ae), WTCP(0x61371c8b, 0x534409e8), WTCP(0x6009b78a, 0x549ef8c6), - WTCP(0x5ed77c8a, 0x55f5a4d2), WTCP(0x5da07af6, 0x5747fcca), WTCP(0x5c64c278, 0x5895efa4), WTCP(0x5b2462f5, 0x59df6c8f) +const PWord16 SineWindow112[56] = { + WTCP( 0x7fff31bf, 0x00e5c87e ), WTCP( 0x7ff8bfc7, 0x02b14de9 ), WTCP( 0x7febdc2a, 0x047cb09e ), WTCP( 0x7fd8878e, 0x0647d97c ), + WTCP( 0x7fbec2ec, 0x0812b164 ), WTCP( 0x7f9e8f91, 0x09dd213a ), WTCP( 0x7f77ef1c, 0x0ba711ea ), WTCP( 0x7f4ae37e, 0x0d706c64 ), + WTCP( 0x7f176efc, 0x0f3919a0 ), WTCP( 0x7edd942d, 0x110102a0 ), WTCP( 0x7e9d55fc, 0x12c8106f ), WTCP( 0x7e56b7a4, 0x148e2c22 ), + WTCP( 0x7e09bcb4, 0x16533edc ), WTCP( 0x7db6690c, 0x181731cd ), WTCP( 0x7d5cc0df, 0x19d9ee32 ), WTCP( 0x7cfcc8af, 0x1b9b5d5a ), + WTCP( 0x7c968552, 0x1d5b68a2 ), WTCP( 0x7c29fbee, 0x1f19f97b ), WTCP( 0x7bb731fb, 0x20d6f969 ), WTCP( 0x7b3e2d40, 0x22925203 ), + WTCP( 0x7abef3d5, 0x244becf6 ), WTCP( 0x7a398c22, 0x2603b406 ), WTCP( 0x79adfcdf, 0x27b9910e ), WTCP( 0x791c4d13, 0x296d6e00 ), + WTCP( 0x78848414, 0x2b1f34eb ), WTCP( 0x77e6a986, 0x2ccecff7 ), WTCP( 0x7742c55c, 0x2e7c2969 ), WTCP( 0x7698dfd8, 0x30272ba0 ), + WTCP( 0x75e90186, 0x31cfc11e ), WTCP( 0x75333343, 0x3375d481 ), WTCP( 0x74777e35, 0x35195088 ), WTCP( 0x73b5ebd1, 0x36ba2014 ), + WTCP( 0x72ee85d5, 0x38582e27 ), WTCP( 0x7221564d, 0x39f365e9 ), WTCP( 0x714e678c, 0x3b8bb2a3 ), WTCP( 0x7075c433, 0x3d20ffc8 ), + WTCP( 0x6f977729, 0x3eb338ef ), WTCP( 0x6eb38ba1, 0x404249d5 ), WTCP( 0x6dca0d14, 0x41ce1e65 ), WTCP( 0x6cdb0745, 0x4356a2ad ), + WTCP( 0x6be6863c, 0x44dbc2ec ), WTCP( 0x6aec9649, 0x465d6b89 ), WTCP( 0x69ed4403, 0x47db8918 ), WTCP( 0x68e89c43, 0x4956085b ), + WTCP( 0x67deac2c, 0x4accd644 ), WTCP( 0x66cf8120, 0x4c3fdff4 ), WTCP( 0x65bb28c7, 0x4daf12ba ), WTCP( 0x64a1b10b, 0x4f1a5c1a ), + WTCP( 0x6383281a, 0x5081a9c9 ), WTCP( 0x625f9c5f, 0x51e4e9ae ), WTCP( 0x61371c8b, 0x534409e8 ), WTCP( 0x6009b78a, 0x549ef8c6 ), + WTCP( 0x5ed77c8a, 0x55f5a4d2 ), WTCP( 0x5da07af6, 0x5747fcca ), WTCP( 0x5c64c278, 0x5895efa4 ), WTCP( 0x5b2462f5, 0x59df6c8f ) }; -const PWord16 SineWindow120[60] = -{ - WTCP(0x7fff4c54, 0x00d676eb), WTCP(0x7ff9af04, 0x02835b5a), WTCP(0x7fee74a2, 0x0430238f), WTCP(0x7fdd9dad, 0x05dcbcbe), - WTCP(0x7fc72ae2, 0x07891418), WTCP(0x7fab1d3d, 0x093516d4), WTCP(0x7f8975f9, 0x0ae0b22c), WTCP(0x7f62368f, 0x0c8bd35e), - WTCP(0x7f3560b9, 0x0e3667ad), WTCP(0x7f02f66f, 0x0fe05c64), WTCP(0x7ecaf9e5, 0x11899ed3), WTCP(0x7e8d6d91, 0x13321c53), - WTCP(0x7e4a5426, 0x14d9c245), WTCP(0x7e01b096, 0x16807e15), WTCP(0x7db3860f, 0x18263d36), WTCP(0x7d5fd801, 0x19caed29), - WTCP(0x7d06aa16, 0x1b6e7b7a), WTCP(0x7ca80038, 0x1d10d5c2), WTCP(0x7c43de8e, 0x1eb1e9a7), WTCP(0x7bda497d, 0x2051a4dd), - WTCP(0x7b6b45a5, 0x21eff528), WTCP(0x7af6d7e6, 0x238cc85d), WTCP(0x7a7d055b, 0x25280c5e), WTCP(0x79fdd35c, 0x26c1af22), - WTCP(0x7979477d, 0x28599eb0), WTCP(0x78ef678f, 0x29efc925), WTCP(0x7860399e, 0x2b841caf), WTCP(0x77cbc3f2, 0x2d168792), - WTCP(0x77320d0d, 0x2ea6f827), WTCP(0x76931bae, 0x30355cdd), WTCP(0x75eef6ce, 0x31c1a43b), WTCP(0x7545a5a0, 0x334bbcde), - WTCP(0x74972f92, 0x34d3957e), WTCP(0x73e39c49, 0x36591cea), WTCP(0x732af3a7, 0x37dc420c), WTCP(0x726d3dc6, 0x395cf3e9), - WTCP(0x71aa82f7, 0x3adb21a1), WTCP(0x70e2cbc6, 0x3c56ba70), WTCP(0x701620f5, 0x3dcfadb0), WTCP(0x6f448b7e, 0x3f45ead8), - WTCP(0x6e6e1492, 0x40b9617d), WTCP(0x6d92c59b, 0x422a0154), WTCP(0x6cb2a837, 0x4397ba32), WTCP(0x6bcdc639, 0x45027c0c), - WTCP(0x6ae429ae, 0x466a36f9), WTCP(0x69f5dcd3, 0x47cedb31), WTCP(0x6902ea1d, 0x4930590f), WTCP(0x680b5c33, 0x4a8ea111), - WTCP(0x670f3df3, 0x4be9a3db), WTCP(0x660e9a6a, 0x4d415234), WTCP(0x65097cdb, 0x4e959d08), WTCP(0x63fff0ba, 0x4fe6756a), - WTCP(0x62f201ac, 0x5133cc94), WTCP(0x61dfbb8a, 0x527d93e6), WTCP(0x60c92a5a, 0x53c3bcea), WTCP(0x5fae5a55, 0x55063951), - WTCP(0x5e8f57e2, 0x5644faf4), WTCP(0x5d6c2f99, 0x577ff3da), WTCP(0x5c44ee40, 0x58b71632), WTCP(0x5b19a0c8, 0x59ea5454), +const PWord16 SineWindow120[60] = { + WTCP( 0x7fff4c54, 0x00d676eb ), + WTCP( 0x7ff9af04, 0x02835b5a ), + WTCP( 0x7fee74a2, 0x0430238f ), + WTCP( 0x7fdd9dad, 0x05dcbcbe ), + WTCP( 0x7fc72ae2, 0x07891418 ), + WTCP( 0x7fab1d3d, 0x093516d4 ), + WTCP( 0x7f8975f9, 0x0ae0b22c ), + WTCP( 0x7f62368f, 0x0c8bd35e ), + WTCP( 0x7f3560b9, 0x0e3667ad ), + WTCP( 0x7f02f66f, 0x0fe05c64 ), + WTCP( 0x7ecaf9e5, 0x11899ed3 ), + WTCP( 0x7e8d6d91, 0x13321c53 ), + WTCP( 0x7e4a5426, 0x14d9c245 ), + WTCP( 0x7e01b096, 0x16807e15 ), + WTCP( 0x7db3860f, 0x18263d36 ), + WTCP( 0x7d5fd801, 0x19caed29 ), + WTCP( 0x7d06aa16, 0x1b6e7b7a ), + WTCP( 0x7ca80038, 0x1d10d5c2 ), + WTCP( 0x7c43de8e, 0x1eb1e9a7 ), + WTCP( 0x7bda497d, 0x2051a4dd ), + WTCP( 0x7b6b45a5, 0x21eff528 ), + WTCP( 0x7af6d7e6, 0x238cc85d ), + WTCP( 0x7a7d055b, 0x25280c5e ), + WTCP( 0x79fdd35c, 0x26c1af22 ), + WTCP( 0x7979477d, 0x28599eb0 ), + WTCP( 0x78ef678f, 0x29efc925 ), + WTCP( 0x7860399e, 0x2b841caf ), + WTCP( 0x77cbc3f2, 0x2d168792 ), + WTCP( 0x77320d0d, 0x2ea6f827 ), + WTCP( 0x76931bae, 0x30355cdd ), + WTCP( 0x75eef6ce, 0x31c1a43b ), + WTCP( 0x7545a5a0, 0x334bbcde ), + WTCP( 0x74972f92, 0x34d3957e ), + WTCP( 0x73e39c49, 0x36591cea ), + WTCP( 0x732af3a7, 0x37dc420c ), + WTCP( 0x726d3dc6, 0x395cf3e9 ), + WTCP( 0x71aa82f7, 0x3adb21a1 ), + WTCP( 0x70e2cbc6, 0x3c56ba70 ), + WTCP( 0x701620f5, 0x3dcfadb0 ), + WTCP( 0x6f448b7e, 0x3f45ead8 ), + WTCP( 0x6e6e1492, 0x40b9617d ), + WTCP( 0x6d92c59b, 0x422a0154 ), + WTCP( 0x6cb2a837, 0x4397ba32 ), + WTCP( 0x6bcdc639, 0x45027c0c ), + WTCP( 0x6ae429ae, 0x466a36f9 ), + WTCP( 0x69f5dcd3, 0x47cedb31 ), + WTCP( 0x6902ea1d, 0x4930590f ), + WTCP( 0x680b5c33, 0x4a8ea111 ), + WTCP( 0x670f3df3, 0x4be9a3db ), + WTCP( 0x660e9a6a, 0x4d415234 ), + WTCP( 0x65097cdb, 0x4e959d08 ), + WTCP( 0x63fff0ba, 0x4fe6756a ), + WTCP( 0x62f201ac, 0x5133cc94 ), + WTCP( 0x61dfbb8a, 0x527d93e6 ), + WTCP( 0x60c92a5a, 0x53c3bcea ), + WTCP( 0x5fae5a55, 0x55063951 ), + WTCP( 0x5e8f57e2, 0x5644faf4 ), + WTCP( 0x5d6c2f99, 0x577ff3da ), + WTCP( 0x5c44ee40, 0x58b71632 ), + WTCP( 0x5b19a0c8, 0x59ea5454 ), }; -const PWord16 SineWindow128[64] = -{ - WTCP(0x7fff6216, 0x00c90f88), WTCP(0x7ffa72d1, 0x025b26d7), WTCP(0x7ff09478, 0x03ed26e6), WTCP(0x7fe1c76b, 0x057f0035), - WTCP(0x7fce0c3e, 0x0710a345), WTCP(0x7fb563b3, 0x08a2009a), WTCP(0x7f97cebd, 0x0a3308bd), WTCP(0x7f754e80, 0x0bc3ac35), - WTCP(0x7f4de451, 0x0d53db92), WTCP(0x7f2191b4, 0x0ee38766), WTCP(0x7ef05860, 0x1072a048), WTCP(0x7eba3a39, 0x120116d5), - WTCP(0x7e7f3957, 0x138edbb1), WTCP(0x7e3f57ff, 0x151bdf86), WTCP(0x7dfa98a8, 0x16a81305), WTCP(0x7db0fdf8, 0x183366e9), - WTCP(0x7d628ac6, 0x19bdcbf3), WTCP(0x7d0f4218, 0x1b4732ef), WTCP(0x7cb72724, 0x1ccf8cb3), WTCP(0x7c5a3d50, 0x1e56ca1e), - WTCP(0x7bf88830, 0x1fdcdc1b), WTCP(0x7b920b89, 0x2161b3a0), WTCP(0x7b26cb4f, 0x22e541af), WTCP(0x7ab6cba4, 0x24677758), - WTCP(0x7a4210d8, 0x25e845b6), WTCP(0x79c89f6e, 0x27679df4), WTCP(0x794a7c12, 0x28e5714b), WTCP(0x78c7aba2, 0x2a61b101), - WTCP(0x78403329, 0x2bdc4e6f), WTCP(0x77b417df, 0x2d553afc), WTCP(0x77235f2d, 0x2ecc681e), WTCP(0x768e0ea6, 0x3041c761), - WTCP(0x75f42c0b, 0x31b54a5e), WTCP(0x7555bd4c, 0x3326e2c3), WTCP(0x74b2c884, 0x34968250), WTCP(0x740b53fb, 0x36041ad9), - WTCP(0x735f6626, 0x376f9e46), WTCP(0x72af05a7, 0x38d8fe93), WTCP(0x71fa3949, 0x3a402dd2), WTCP(0x71410805, 0x3ba51e29), - WTCP(0x708378ff, 0x3d07c1d6), WTCP(0x6fc19385, 0x3e680b2c), WTCP(0x6efb5f12, 0x3fc5ec98), WTCP(0x6e30e34a, 0x4121589b), - WTCP(0x6d6227fa, 0x427a41d0), WTCP(0x6c8f351c, 0x43d09aed), WTCP(0x6bb812d1, 0x452456bd), WTCP(0x6adcc964, 0x46756828), - WTCP(0x69fd614a, 0x47c3c22f), WTCP(0x6919e320, 0x490f57ee), WTCP(0x683257ab, 0x4a581c9e), WTCP(0x6746c7d8, 0x4b9e0390), - WTCP(0x66573cbb, 0x4ce10034), WTCP(0x6563bf92, 0x4e210617), WTCP(0x646c59bf, 0x4f5e08e3), WTCP(0x637114cc, 0x5097fc5e), - WTCP(0x6271fa69, 0x51ced46e), WTCP(0x616f146c, 0x53028518), WTCP(0x60686ccf, 0x5433027d), WTCP(0x5f5e0db3, 0x556040e2), - WTCP(0x5e50015d, 0x568a34a9), WTCP(0x5d3e5237, 0x57b0d256), WTCP(0x5c290acc, 0x58d40e8c), WTCP(0x5b1035cf, 0x59f3de12), +const PWord16 SineWindow128[64] = { + WTCP( 0x7fff6216, 0x00c90f88 ), + WTCP( 0x7ffa72d1, 0x025b26d7 ), + WTCP( 0x7ff09478, 0x03ed26e6 ), + WTCP( 0x7fe1c76b, 0x057f0035 ), + WTCP( 0x7fce0c3e, 0x0710a345 ), + WTCP( 0x7fb563b3, 0x08a2009a ), + WTCP( 0x7f97cebd, 0x0a3308bd ), + WTCP( 0x7f754e80, 0x0bc3ac35 ), + WTCP( 0x7f4de451, 0x0d53db92 ), + WTCP( 0x7f2191b4, 0x0ee38766 ), + WTCP( 0x7ef05860, 0x1072a048 ), + WTCP( 0x7eba3a39, 0x120116d5 ), + WTCP( 0x7e7f3957, 0x138edbb1 ), + WTCP( 0x7e3f57ff, 0x151bdf86 ), + WTCP( 0x7dfa98a8, 0x16a81305 ), + WTCP( 0x7db0fdf8, 0x183366e9 ), + WTCP( 0x7d628ac6, 0x19bdcbf3 ), + WTCP( 0x7d0f4218, 0x1b4732ef ), + WTCP( 0x7cb72724, 0x1ccf8cb3 ), + WTCP( 0x7c5a3d50, 0x1e56ca1e ), + WTCP( 0x7bf88830, 0x1fdcdc1b ), + WTCP( 0x7b920b89, 0x2161b3a0 ), + WTCP( 0x7b26cb4f, 0x22e541af ), + WTCP( 0x7ab6cba4, 0x24677758 ), + WTCP( 0x7a4210d8, 0x25e845b6 ), + WTCP( 0x79c89f6e, 0x27679df4 ), + WTCP( 0x794a7c12, 0x28e5714b ), + WTCP( 0x78c7aba2, 0x2a61b101 ), + WTCP( 0x78403329, 0x2bdc4e6f ), + WTCP( 0x77b417df, 0x2d553afc ), + WTCP( 0x77235f2d, 0x2ecc681e ), + WTCP( 0x768e0ea6, 0x3041c761 ), + WTCP( 0x75f42c0b, 0x31b54a5e ), + WTCP( 0x7555bd4c, 0x3326e2c3 ), + WTCP( 0x74b2c884, 0x34968250 ), + WTCP( 0x740b53fb, 0x36041ad9 ), + WTCP( 0x735f6626, 0x376f9e46 ), + WTCP( 0x72af05a7, 0x38d8fe93 ), + WTCP( 0x71fa3949, 0x3a402dd2 ), + WTCP( 0x71410805, 0x3ba51e29 ), + WTCP( 0x708378ff, 0x3d07c1d6 ), + WTCP( 0x6fc19385, 0x3e680b2c ), + WTCP( 0x6efb5f12, 0x3fc5ec98 ), + WTCP( 0x6e30e34a, 0x4121589b ), + WTCP( 0x6d6227fa, 0x427a41d0 ), + WTCP( 0x6c8f351c, 0x43d09aed ), + WTCP( 0x6bb812d1, 0x452456bd ), + WTCP( 0x6adcc964, 0x46756828 ), + WTCP( 0x69fd614a, 0x47c3c22f ), + WTCP( 0x6919e320, 0x490f57ee ), + WTCP( 0x683257ab, 0x4a581c9e ), + WTCP( 0x6746c7d8, 0x4b9e0390 ), + WTCP( 0x66573cbb, 0x4ce10034 ), + WTCP( 0x6563bf92, 0x4e210617 ), + WTCP( 0x646c59bf, 0x4f5e08e3 ), + WTCP( 0x637114cc, 0x5097fc5e ), + WTCP( 0x6271fa69, 0x51ced46e ), + WTCP( 0x616f146c, 0x53028518 ), + WTCP( 0x60686ccf, 0x5433027d ), + WTCP( 0x5f5e0db3, 0x556040e2 ), + WTCP( 0x5e50015d, 0x568a34a9 ), + WTCP( 0x5d3e5237, 0x57b0d256 ), + WTCP( 0x5c290acc, 0x58d40e8c ), + WTCP( 0x5b1035cf, 0x59f3de12 ), }; -const PWord16 SineWindow140[70] = -{ - WTCP(0x7fff7bff, 0x00b7d3bc), WTCP(0x7ffb5c00, 0x02277547), WTCP(0x7ff31c25, 0x0397050d), WTCP(0x7fe6bcb0, 0x05067734), - WTCP(0x7fd63e09, 0x0675bfe7), WTCP(0x7fc1a0b6, 0x07e4d34d), WTCP(0x7fa8e564, 0x0953a594), WTCP(0x7f8c0cdc, 0x0ac22ae8), - WTCP(0x7f6b180f, 0x0c30577a), WTCP(0x7f46080a, 0x0d9e1f7d), WTCP(0x7f1cde01, 0x0f0b7727), WTCP(0x7eef9b46, 0x107852b2), - WTCP(0x7ebe414f, 0x11e4a65c), WTCP(0x7e88d1b4, 0x13506668), WTCP(0x7e4f4e2c, 0x14bb871b), WTCP(0x7e11b894, 0x1625fcc3), - WTCP(0x7dd012e6, 0x178fbbb1), WTCP(0x7d8a5f40, 0x18f8b83c), WTCP(0x7d409fe1, 0x1a60e6c3), WTCP(0x7cf2d72b, 0x1bc83baa), - WTCP(0x7ca1079d, 0x1d2eab5d), WTCP(0x7c4b33dc, 0x1e942a4d), WTCP(0x7bf15eac, 0x1ff8acf7), WTCP(0x7b938af1, 0x215c27dc), - WTCP(0x7b31bbb2, 0x22be8f87), WTCP(0x7acbf416, 0x241fd88e), WTCP(0x7a623764, 0x257ff78e), WTCP(0x79f48904, 0x26dee12c), - WTCP(0x7982ec80, 0x283c8a1b), WTCP(0x790d6581, 0x2998e716), WTCP(0x7893f7d1, 0x2af3ece2), WTCP(0x7816a759, 0x2c4d9050), - WTCP(0x77957822, 0x2da5c63e), WTCP(0x77106e58, 0x2efc8393), WTCP(0x76878e43, 0x3051bd43), WTCP(0x75fadc4d, 0x31a56850), - WTCP(0x756a5cff, 0x32f779c7), WTCP(0x74d61500, 0x3447e6c3), WTCP(0x743e0918, 0x3596a46c), WTCP(0x73a23e2d, 0x36e3a7fa), - WTCP(0x7302b945, 0x382ee6b0), WTCP(0x725f7f84, 0x397855e1), WTCP(0x71b8962b, 0x3abfeaf1), WTCP(0x710e029e, 0x3c059b4f), - WTCP(0x705fca59, 0x3d495c7e), WTCP(0x6fadf2fc, 0x3e8b240e), WTCP(0x6ef88241, 0x3fcae7a1), WTCP(0x6e3f7e01, 0x41089ce8), - WTCP(0x6d82ec32, 0x424439a6), WTCP(0x6cc2d2e9, 0x437db3b0), WTCP(0x6bff3855, 0x44b500eb), WTCP(0x6b3822c6, 0x45ea1750), - WTCP(0x6a6d98a4, 0x471cece7), WTCP(0x699fa078, 0x484d77ce), WTCP(0x68ce40e4, 0x497bae33), WTCP(0x67f980a8, 0x4aa7865b), - WTCP(0x6721669f, 0x4bd0f69b), WTCP(0x6645f9c0, 0x4cf7f55d), WTCP(0x6567411d, 0x4e1c791f), WTCP(0x648543e4, 0x4f3e7875), - WTCP(0x63a0095c, 0x505dea05), WTCP(0x62b798ea, 0x517ac48c), WTCP(0x61cbfa0b, 0x5294fedd), WTCP(0x60dd3457, 0x53ac8fde), - WTCP(0x5feb4f7f, 0x54c16e8e), WTCP(0x5ef6534f, 0x55d391ff), WTCP(0x5dfe47ad, 0x56e2f15d), WTCP(0x5d033497, 0x57ef83e9), - WTCP(0x5c052224, 0x58f940fa), WTCP(0x5b041885, 0x5a002001) +const PWord16 SineWindow140[70] = { + WTCP( 0x7fff7bff, 0x00b7d3bc ), WTCP( 0x7ffb5c00, 0x02277547 ), WTCP( 0x7ff31c25, 0x0397050d ), WTCP( 0x7fe6bcb0, 0x05067734 ), + WTCP( 0x7fd63e09, 0x0675bfe7 ), WTCP( 0x7fc1a0b6, 0x07e4d34d ), WTCP( 0x7fa8e564, 0x0953a594 ), WTCP( 0x7f8c0cdc, 0x0ac22ae8 ), + WTCP( 0x7f6b180f, 0x0c30577a ), WTCP( 0x7f46080a, 0x0d9e1f7d ), WTCP( 0x7f1cde01, 0x0f0b7727 ), WTCP( 0x7eef9b46, 0x107852b2 ), + WTCP( 0x7ebe414f, 0x11e4a65c ), WTCP( 0x7e88d1b4, 0x13506668 ), WTCP( 0x7e4f4e2c, 0x14bb871b ), WTCP( 0x7e11b894, 0x1625fcc3 ), + WTCP( 0x7dd012e6, 0x178fbbb1 ), WTCP( 0x7d8a5f40, 0x18f8b83c ), WTCP( 0x7d409fe1, 0x1a60e6c3 ), WTCP( 0x7cf2d72b, 0x1bc83baa ), + WTCP( 0x7ca1079d, 0x1d2eab5d ), WTCP( 0x7c4b33dc, 0x1e942a4d ), WTCP( 0x7bf15eac, 0x1ff8acf7 ), WTCP( 0x7b938af1, 0x215c27dc ), + WTCP( 0x7b31bbb2, 0x22be8f87 ), WTCP( 0x7acbf416, 0x241fd88e ), WTCP( 0x7a623764, 0x257ff78e ), WTCP( 0x79f48904, 0x26dee12c ), + WTCP( 0x7982ec80, 0x283c8a1b ), WTCP( 0x790d6581, 0x2998e716 ), WTCP( 0x7893f7d1, 0x2af3ece2 ), WTCP( 0x7816a759, 0x2c4d9050 ), + WTCP( 0x77957822, 0x2da5c63e ), WTCP( 0x77106e58, 0x2efc8393 ), WTCP( 0x76878e43, 0x3051bd43 ), WTCP( 0x75fadc4d, 0x31a56850 ), + WTCP( 0x756a5cff, 0x32f779c7 ), WTCP( 0x74d61500, 0x3447e6c3 ), WTCP( 0x743e0918, 0x3596a46c ), WTCP( 0x73a23e2d, 0x36e3a7fa ), + WTCP( 0x7302b945, 0x382ee6b0 ), WTCP( 0x725f7f84, 0x397855e1 ), WTCP( 0x71b8962b, 0x3abfeaf1 ), WTCP( 0x710e029e, 0x3c059b4f ), + WTCP( 0x705fca59, 0x3d495c7e ), WTCP( 0x6fadf2fc, 0x3e8b240e ), WTCP( 0x6ef88241, 0x3fcae7a1 ), WTCP( 0x6e3f7e01, 0x41089ce8 ), + WTCP( 0x6d82ec32, 0x424439a6 ), WTCP( 0x6cc2d2e9, 0x437db3b0 ), WTCP( 0x6bff3855, 0x44b500eb ), WTCP( 0x6b3822c6, 0x45ea1750 ), + WTCP( 0x6a6d98a4, 0x471cece7 ), WTCP( 0x699fa078, 0x484d77ce ), WTCP( 0x68ce40e4, 0x497bae33 ), WTCP( 0x67f980a8, 0x4aa7865b ), + WTCP( 0x6721669f, 0x4bd0f69b ), WTCP( 0x6645f9c0, 0x4cf7f55d ), WTCP( 0x6567411d, 0x4e1c791f ), WTCP( 0x648543e4, 0x4f3e7875 ), + WTCP( 0x63a0095c, 0x505dea05 ), WTCP( 0x62b798ea, 0x517ac48c ), WTCP( 0x61cbfa0b, 0x5294fedd ), WTCP( 0x60dd3457, 0x53ac8fde ), + WTCP( 0x5feb4f7f, 0x54c16e8e ), WTCP( 0x5ef6534f, 0x55d391ff ), WTCP( 0x5dfe47ad, 0x56e2f15d ), WTCP( 0x5d033497, 0x57ef83e9 ), + WTCP( 0x5c052224, 0x58f940fa ), WTCP( 0x5b041885, 0x5a002001 ) }; -const PWord16 SineWindow160[80] = -{ - WTCP(0x7fff9aef, 0x00a0d951), WTCP(0x7ffc726f, 0x01e287fc), WTCP(0x7ff62182, 0x03242abf), WTCP(0x7feca851, 0x0465b9aa), - WTCP(0x7fe00716, 0x05a72ccf), WTCP(0x7fd03e23, 0x06e87c3f), WTCP(0x7fbd4dda, 0x0829a00c), WTCP(0x7fa736b4, 0x096a9049), - WTCP(0x7f8df93c, 0x0aab450d), WTCP(0x7f719611, 0x0bebb66c), WTCP(0x7f520de6, 0x0d2bdc80), WTCP(0x7f2f6183, 0x0e6baf61), - WTCP(0x7f0991c4, 0x0fab272b), WTCP(0x7ee09f95, 0x10ea3bfd), WTCP(0x7eb48bfb, 0x1228e5f8), WTCP(0x7e85580c, 0x13671d3d), - WTCP(0x7e5304f2, 0x14a4d9f4), WTCP(0x7e1d93ea, 0x15e21445), WTCP(0x7de50646, 0x171ec45c), WTCP(0x7da95d6c, 0x185ae269), - WTCP(0x7d6a9ad5, 0x199666a0), WTCP(0x7d28c00c, 0x1ad14938), WTCP(0x7ce3ceb2, 0x1c0b826a), WTCP(0x7c9bc87a, 0x1d450a78), - WTCP(0x7c50af2b, 0x1e7dd9a4), WTCP(0x7c02849f, 0x1fb5e836), WTCP(0x7bb14ac5, 0x20ed2e7b), WTCP(0x7b5d039e, 0x2223a4c5), - WTCP(0x7b05b13d, 0x2359436c), WTCP(0x7aab55ca, 0x248e02cb), WTCP(0x7a4df380, 0x25c1db44), WTCP(0x79ed8cad, 0x26f4c53e), - WTCP(0x798a23b1, 0x2826b928), WTCP(0x7923bb01, 0x2957af74), WTCP(0x78ba5524, 0x2a87a09d), WTCP(0x784df4b3, 0x2bb68522), - WTCP(0x77de9c5b, 0x2ce45589), WTCP(0x776c4edb, 0x2e110a62), WTCP(0x76f70f05, 0x2f3c9c40), WTCP(0x767edfbe, 0x306703bf), - WTCP(0x7603c3fd, 0x31903982), WTCP(0x7585becb, 0x32b83634), WTCP(0x7504d345, 0x33def287), WTCP(0x74810499, 0x35046736), - WTCP(0x73fa5607, 0x36288d03), WTCP(0x7370cae2, 0x374b5cb9), WTCP(0x72e4668f, 0x386ccf2a), WTCP(0x72552c85, 0x398cdd32), - WTCP(0x71c3204c, 0x3aab7fb7), WTCP(0x712e457f, 0x3bc8afa5), WTCP(0x70969fca, 0x3ce465f3), WTCP(0x6ffc32eb, 0x3dfe9ba1), - WTCP(0x6f5f02b2, 0x3f1749b8), WTCP(0x6ebf12ff, 0x402e694c), WTCP(0x6e1c67c4, 0x4143f379), WTCP(0x6d770506, 0x4257e166), - WTCP(0x6cceeed8, 0x436a2c45), WTCP(0x6c242960, 0x447acd50), WTCP(0x6b76b8d6, 0x4589bdcf), WTCP(0x6ac6a180, 0x4696f710), - WTCP(0x6a13e7b8, 0x47a27271), WTCP(0x695e8fe5, 0x48ac2957), WTCP(0x68a69e81, 0x49b41533), WTCP(0x67ec1817, 0x4aba2f84), - WTCP(0x672f013f, 0x4bbe71d1), WTCP(0x666f5ea6, 0x4cc0d5ae), WTCP(0x65ad3505, 0x4dc154bb), WTCP(0x64e88926, 0x4ebfe8a5), - WTCP(0x64215fe5, 0x4fbc8b22), WTCP(0x6357be2a, 0x50b735f8), WTCP(0x628ba8ef, 0x51afe2f6), WTCP(0x61bd253f, 0x52a68bfb), - WTCP(0x60ec3830, 0x539b2af0), WTCP(0x6018e6eb, 0x548db9cb), WTCP(0x5f4336a7, 0x557e3292), WTCP(0x5e6b2ca8, 0x566c8f55), - WTCP(0x5d90ce45, 0x5758ca31), WTCP(0x5cb420e0, 0x5842dd54), WTCP(0x5bd529eb, 0x592ac2f7), WTCP(0x5af3eee6, 0x5a107561), +const PWord16 SineWindow160[80] = { + WTCP( 0x7fff9aef, 0x00a0d951 ), + WTCP( 0x7ffc726f, 0x01e287fc ), + WTCP( 0x7ff62182, 0x03242abf ), + WTCP( 0x7feca851, 0x0465b9aa ), + WTCP( 0x7fe00716, 0x05a72ccf ), + WTCP( 0x7fd03e23, 0x06e87c3f ), + WTCP( 0x7fbd4dda, 0x0829a00c ), + WTCP( 0x7fa736b4, 0x096a9049 ), + WTCP( 0x7f8df93c, 0x0aab450d ), + WTCP( 0x7f719611, 0x0bebb66c ), + WTCP( 0x7f520de6, 0x0d2bdc80 ), + WTCP( 0x7f2f6183, 0x0e6baf61 ), + WTCP( 0x7f0991c4, 0x0fab272b ), + WTCP( 0x7ee09f95, 0x10ea3bfd ), + WTCP( 0x7eb48bfb, 0x1228e5f8 ), + WTCP( 0x7e85580c, 0x13671d3d ), + WTCP( 0x7e5304f2, 0x14a4d9f4 ), + WTCP( 0x7e1d93ea, 0x15e21445 ), + WTCP( 0x7de50646, 0x171ec45c ), + WTCP( 0x7da95d6c, 0x185ae269 ), + WTCP( 0x7d6a9ad5, 0x199666a0 ), + WTCP( 0x7d28c00c, 0x1ad14938 ), + WTCP( 0x7ce3ceb2, 0x1c0b826a ), + WTCP( 0x7c9bc87a, 0x1d450a78 ), + WTCP( 0x7c50af2b, 0x1e7dd9a4 ), + WTCP( 0x7c02849f, 0x1fb5e836 ), + WTCP( 0x7bb14ac5, 0x20ed2e7b ), + WTCP( 0x7b5d039e, 0x2223a4c5 ), + WTCP( 0x7b05b13d, 0x2359436c ), + WTCP( 0x7aab55ca, 0x248e02cb ), + WTCP( 0x7a4df380, 0x25c1db44 ), + WTCP( 0x79ed8cad, 0x26f4c53e ), + WTCP( 0x798a23b1, 0x2826b928 ), + WTCP( 0x7923bb01, 0x2957af74 ), + WTCP( 0x78ba5524, 0x2a87a09d ), + WTCP( 0x784df4b3, 0x2bb68522 ), + WTCP( 0x77de9c5b, 0x2ce45589 ), + WTCP( 0x776c4edb, 0x2e110a62 ), + WTCP( 0x76f70f05, 0x2f3c9c40 ), + WTCP( 0x767edfbe, 0x306703bf ), + WTCP( 0x7603c3fd, 0x31903982 ), + WTCP( 0x7585becb, 0x32b83634 ), + WTCP( 0x7504d345, 0x33def287 ), + WTCP( 0x74810499, 0x35046736 ), + WTCP( 0x73fa5607, 0x36288d03 ), + WTCP( 0x7370cae2, 0x374b5cb9 ), + WTCP( 0x72e4668f, 0x386ccf2a ), + WTCP( 0x72552c85, 0x398cdd32 ), + WTCP( 0x71c3204c, 0x3aab7fb7 ), + WTCP( 0x712e457f, 0x3bc8afa5 ), + WTCP( 0x70969fca, 0x3ce465f3 ), + WTCP( 0x6ffc32eb, 0x3dfe9ba1 ), + WTCP( 0x6f5f02b2, 0x3f1749b8 ), + WTCP( 0x6ebf12ff, 0x402e694c ), + WTCP( 0x6e1c67c4, 0x4143f379 ), + WTCP( 0x6d770506, 0x4257e166 ), + WTCP( 0x6cceeed8, 0x436a2c45 ), + WTCP( 0x6c242960, 0x447acd50 ), + WTCP( 0x6b76b8d6, 0x4589bdcf ), + WTCP( 0x6ac6a180, 0x4696f710 ), + WTCP( 0x6a13e7b8, 0x47a27271 ), + WTCP( 0x695e8fe5, 0x48ac2957 ), + WTCP( 0x68a69e81, 0x49b41533 ), + WTCP( 0x67ec1817, 0x4aba2f84 ), + WTCP( 0x672f013f, 0x4bbe71d1 ), + WTCP( 0x666f5ea6, 0x4cc0d5ae ), + WTCP( 0x65ad3505, 0x4dc154bb ), + WTCP( 0x64e88926, 0x4ebfe8a5 ), + WTCP( 0x64215fe5, 0x4fbc8b22 ), + WTCP( 0x6357be2a, 0x50b735f8 ), + WTCP( 0x628ba8ef, 0x51afe2f6 ), + WTCP( 0x61bd253f, 0x52a68bfb ), + WTCP( 0x60ec3830, 0x539b2af0 ), + WTCP( 0x6018e6eb, 0x548db9cb ), + WTCP( 0x5f4336a7, 0x557e3292 ), + WTCP( 0x5e6b2ca8, 0x566c8f55 ), + WTCP( 0x5d90ce45, 0x5758ca31 ), + WTCP( 0x5cb420e0, 0x5842dd54 ), + WTCP( 0x5bd529eb, 0x592ac2f7 ), + WTCP( 0x5af3eee6, 0x5a107561 ), }; -const PWord16 SineWindow180[90] = -{ - WTCP(0x7fffb026, 0x008efa17), WTCP(0x7ffd3154, 0x01aceb7c), WTCP(0x7ff833bd, 0x02cad485), WTCP(0x7ff0b77a, 0x03e8af9e), - WTCP(0x7fe6bcb0, 0x05067734), WTCP(0x7fda4391, 0x062425b6), WTCP(0x7fcb4c5b, 0x0741b592), WTCP(0x7fb9d759, 0x085f2137), - WTCP(0x7fa5e4e1, 0x097c6313), WTCP(0x7f8f7559, 0x0a997598), WTCP(0x7f76892f, 0x0bb65336), WTCP(0x7f5b20df, 0x0cd2f660), - WTCP(0x7f3d3cf4, 0x0def598a), WTCP(0x7f1cde01, 0x0f0b7727), WTCP(0x7efa04a8, 0x102749af), WTCP(0x7ed4b198, 0x1142cb98), - WTCP(0x7eace58a, 0x125df75b), WTCP(0x7e82a146, 0x1378c774), WTCP(0x7e55e59e, 0x1493365f), WTCP(0x7e26b371, 0x15ad3e9a), - WTCP(0x7df50bab, 0x16c6daa6), WTCP(0x7dc0ef44, 0x17e00505), WTCP(0x7d8a5f40, 0x18f8b83c), WTCP(0x7d515caf, 0x1a10eed3), - WTCP(0x7d15e8ad, 0x1b28a351), WTCP(0x7cd80464, 0x1c3fd045), WTCP(0x7c97b109, 0x1d56703c), WTCP(0x7c54efdc, 0x1e6c7dc7), - WTCP(0x7c0fc22a, 0x1f81f37c), WTCP(0x7bc8294d, 0x2096cbf1), WTCP(0x7b7e26aa, 0x21ab01c0), WTCP(0x7b31bbb2, 0x22be8f87), - WTCP(0x7ae2e9e4, 0x23d16fe8), WTCP(0x7a91b2c7, 0x24e39d85), WTCP(0x7a3e17f2, 0x25f51307), WTCP(0x79e81b06, 0x2705cb19), - WTCP(0x798fbdb0, 0x2815c06a), WTCP(0x793501a9, 0x2924edac), WTCP(0x78d7e8b6, 0x2a334d96), WTCP(0x787874a7, 0x2b40dae2), - WTCP(0x7816a759, 0x2c4d9050), WTCP(0x77b282b3, 0x2d5968a3), WTCP(0x774c08ab, 0x2e645ea1), WTCP(0x76e33b3f, 0x2f6e6d16), - WTCP(0x76781c7a, 0x30778ed2), WTCP(0x760aae73, 0x317fbeab), WTCP(0x759af34c, 0x3286f779), WTCP(0x7528ed32, 0x338d341b), - WTCP(0x74b49e5f, 0x34926f74), WTCP(0x743e0918, 0x3596a46c), WTCP(0x73c52fab, 0x3699cdf2), WTCP(0x734a1475, 0x379be6f6), - WTCP(0x72ccb9db, 0x389cea72), WTCP(0x724d224f, 0x399cd362), WTCP(0x71cb504e, 0x3a9b9cca), WTCP(0x71474660, 0x3b9941b1), - WTCP(0x70c10718, 0x3c95bd26), WTCP(0x70389514, 0x3d910a3c), WTCP(0x6fadf2fc, 0x3e8b240e), WTCP(0x6f212385, 0x3f8405bc), - WTCP(0x6e92296e, 0x407baa6a), WTCP(0x6e010780, 0x41720d46), WTCP(0x6d6dc08f, 0x42672981), WTCP(0x6cd8577a, 0x435afa54), - WTCP(0x6c40cf2c, 0x444d7aff), WTCP(0x6ba72a98, 0x453ea6c7), WTCP(0x6b0b6cbd, 0x462e78f9), WTCP(0x6a6d98a4, 0x471cece7), - WTCP(0x69cdb162, 0x4809fdeb), WTCP(0x692bba14, 0x48f5a767), WTCP(0x6887b5e2, 0x49dfe4c2), WTCP(0x67e1a7ff, 0x4ac8b16b), - WTCP(0x673993a9, 0x4bb008d9), WTCP(0x668f7c25, 0x4c95e688), WTCP(0x65e364c4, 0x4d7a45fe), WTCP(0x653550e2, 0x4e5d22c6), - WTCP(0x648543e4, 0x4f3e7875), WTCP(0x63d34137, 0x501e42a5), WTCP(0x631f4c54, 0x50fc7cfb), WTCP(0x626968be, 0x51d92321), - WTCP(0x61b19a00, 0x52b430c9), WTCP(0x60f7e3b0, 0x538da1ae), WTCP(0x603c496c, 0x54657194), WTCP(0x5f7ecedd, 0x553b9c45), - WTCP(0x5ebf77b5, 0x56101d94), WTCP(0x5dfe47ad, 0x56e2f15d), WTCP(0x5d3b428c, 0x57b41384), WTCP(0x5c766c1c, 0x58837ff4), - WTCP(0x5bafc837, 0x595132a2), WTCP(0x5ae75ab9, 0x5a1d278d), +const PWord16 SineWindow180[90] = { + WTCP( 0x7fffb026, 0x008efa17 ), + WTCP( 0x7ffd3154, 0x01aceb7c ), + WTCP( 0x7ff833bd, 0x02cad485 ), + WTCP( 0x7ff0b77a, 0x03e8af9e ), + WTCP( 0x7fe6bcb0, 0x05067734 ), + WTCP( 0x7fda4391, 0x062425b6 ), + WTCP( 0x7fcb4c5b, 0x0741b592 ), + WTCP( 0x7fb9d759, 0x085f2137 ), + WTCP( 0x7fa5e4e1, 0x097c6313 ), + WTCP( 0x7f8f7559, 0x0a997598 ), + WTCP( 0x7f76892f, 0x0bb65336 ), + WTCP( 0x7f5b20df, 0x0cd2f660 ), + WTCP( 0x7f3d3cf4, 0x0def598a ), + WTCP( 0x7f1cde01, 0x0f0b7727 ), + WTCP( 0x7efa04a8, 0x102749af ), + WTCP( 0x7ed4b198, 0x1142cb98 ), + WTCP( 0x7eace58a, 0x125df75b ), + WTCP( 0x7e82a146, 0x1378c774 ), + WTCP( 0x7e55e59e, 0x1493365f ), + WTCP( 0x7e26b371, 0x15ad3e9a ), + WTCP( 0x7df50bab, 0x16c6daa6 ), + WTCP( 0x7dc0ef44, 0x17e00505 ), + WTCP( 0x7d8a5f40, 0x18f8b83c ), + WTCP( 0x7d515caf, 0x1a10eed3 ), + WTCP( 0x7d15e8ad, 0x1b28a351 ), + WTCP( 0x7cd80464, 0x1c3fd045 ), + WTCP( 0x7c97b109, 0x1d56703c ), + WTCP( 0x7c54efdc, 0x1e6c7dc7 ), + WTCP( 0x7c0fc22a, 0x1f81f37c ), + WTCP( 0x7bc8294d, 0x2096cbf1 ), + WTCP( 0x7b7e26aa, 0x21ab01c0 ), + WTCP( 0x7b31bbb2, 0x22be8f87 ), + WTCP( 0x7ae2e9e4, 0x23d16fe8 ), + WTCP( 0x7a91b2c7, 0x24e39d85 ), + WTCP( 0x7a3e17f2, 0x25f51307 ), + WTCP( 0x79e81b06, 0x2705cb19 ), + WTCP( 0x798fbdb0, 0x2815c06a ), + WTCP( 0x793501a9, 0x2924edac ), + WTCP( 0x78d7e8b6, 0x2a334d96 ), + WTCP( 0x787874a7, 0x2b40dae2 ), + WTCP( 0x7816a759, 0x2c4d9050 ), + WTCP( 0x77b282b3, 0x2d5968a3 ), + WTCP( 0x774c08ab, 0x2e645ea1 ), + WTCP( 0x76e33b3f, 0x2f6e6d16 ), + WTCP( 0x76781c7a, 0x30778ed2 ), + WTCP( 0x760aae73, 0x317fbeab ), + WTCP( 0x759af34c, 0x3286f779 ), + WTCP( 0x7528ed32, 0x338d341b ), + WTCP( 0x74b49e5f, 0x34926f74 ), + WTCP( 0x743e0918, 0x3596a46c ), + WTCP( 0x73c52fab, 0x3699cdf2 ), + WTCP( 0x734a1475, 0x379be6f6 ), + WTCP( 0x72ccb9db, 0x389cea72 ), + WTCP( 0x724d224f, 0x399cd362 ), + WTCP( 0x71cb504e, 0x3a9b9cca ), + WTCP( 0x71474660, 0x3b9941b1 ), + WTCP( 0x70c10718, 0x3c95bd26 ), + WTCP( 0x70389514, 0x3d910a3c ), + WTCP( 0x6fadf2fc, 0x3e8b240e ), + WTCP( 0x6f212385, 0x3f8405bc ), + WTCP( 0x6e92296e, 0x407baa6a ), + WTCP( 0x6e010780, 0x41720d46 ), + WTCP( 0x6d6dc08f, 0x42672981 ), + WTCP( 0x6cd8577a, 0x435afa54 ), + WTCP( 0x6c40cf2c, 0x444d7aff ), + WTCP( 0x6ba72a98, 0x453ea6c7 ), + WTCP( 0x6b0b6cbd, 0x462e78f9 ), + WTCP( 0x6a6d98a4, 0x471cece7 ), + WTCP( 0x69cdb162, 0x4809fdeb ), + WTCP( 0x692bba14, 0x48f5a767 ), + WTCP( 0x6887b5e2, 0x49dfe4c2 ), + WTCP( 0x67e1a7ff, 0x4ac8b16b ), + WTCP( 0x673993a9, 0x4bb008d9 ), + WTCP( 0x668f7c25, 0x4c95e688 ), + WTCP( 0x65e364c4, 0x4d7a45fe ), + WTCP( 0x653550e2, 0x4e5d22c6 ), + WTCP( 0x648543e4, 0x4f3e7875 ), + WTCP( 0x63d34137, 0x501e42a5 ), + WTCP( 0x631f4c54, 0x50fc7cfb ), + WTCP( 0x626968be, 0x51d92321 ), + WTCP( 0x61b19a00, 0x52b430c9 ), + WTCP( 0x60f7e3b0, 0x538da1ae ), + WTCP( 0x603c496c, 0x54657194 ), + WTCP( 0x5f7ecedd, 0x553b9c45 ), + WTCP( 0x5ebf77b5, 0x56101d94 ), + WTCP( 0x5dfe47ad, 0x56e2f15d ), + WTCP( 0x5d3b428c, 0x57b41384 ), + WTCP( 0x5c766c1c, 0x58837ff4 ), + WTCP( 0x5bafc837, 0x595132a2 ), + WTCP( 0x5ae75ab9, 0x5a1d278d ), }; -const PWord16 SineWindow224[112] = -{ - WTCP(0x7fffcc70, 0x0072e46e), WTCP(0x7ffe2fee, 0x0158abd6), WTCP(0x7ffaf6f1, 0x023e6ee8), WTCP(0x7ff62182, 0x03242abf), - WTCP(0x7fefafb1, 0x0409dc76), WTCP(0x7fe7a192, 0x04ef8129), WTCP(0x7fddf741, 0x05d515f5), WTCP(0x7fd2b0da, 0x06ba97f4), - WTCP(0x7fc5ce84, 0x07a00445), WTCP(0x7fb75068, 0x08855802), WTCP(0x7fa736b4, 0x096a9049), WTCP(0x7f95819c, 0x0a4faa38), - WTCP(0x7f82315a, 0x0b34a2ec), WTCP(0x7f6d462b, 0x0c197784), WTCP(0x7f56c053, 0x0cfe251d), WTCP(0x7f3ea01a, 0x0de2a8d7), - WTCP(0x7f24e5cf, 0x0ec6ffd1), WTCP(0x7f0991c4, 0x0fab272b), WTCP(0x7eeca451, 0x108f1c07), WTCP(0x7ece1dd3, 0x1172db86), - WTCP(0x7eadfeae, 0x125662c9), WTCP(0x7e8c4748, 0x1339aef3), WTCP(0x7e68f80e, 0x141cbd28), WTCP(0x7e441171, 0x14ff8a8c), - WTCP(0x7e1d93ea, 0x15e21445), WTCP(0x7df57ff3, 0x16c45777), WTCP(0x7dcbd60e, 0x17a6514a), WTCP(0x7da096c2, 0x1887fee6), - WTCP(0x7d73c299, 0x19695d74), WTCP(0x7d455a24, 0x1a4a6a1c), WTCP(0x7d155df9, 0x1b2b220b), WTCP(0x7ce3ceb2, 0x1c0b826a), - WTCP(0x7cb0acef, 0x1ceb8869), WTCP(0x7c7bf954, 0x1dcb3134), WTCP(0x7c45b48d, 0x1eaa79fa), WTCP(0x7c0ddf47, 0x1f895fed), - WTCP(0x7bd47a36, 0x2067e03e), WTCP(0x7b998614, 0x2145f81f), WTCP(0x7b5d039e, 0x2223a4c5), WTCP(0x7b1ef397, 0x2300e366), - WTCP(0x7adf56c8, 0x23ddb139), WTCP(0x7a9e2dfd, 0x24ba0b76), WTCP(0x7a5b7a09, 0x2595ef56), WTCP(0x7a173bc2, 0x26715a16), - WTCP(0x79d17405, 0x274c48f2), WTCP(0x798a23b1, 0x2826b928), WTCP(0x79414bae, 0x2900a7f9), WTCP(0x78f6ece5, 0x29da12a7), - WTCP(0x78ab0847, 0x2ab2f674), WTCP(0x785d9ec8, 0x2b8b50a5), WTCP(0x780eb161, 0x2c631e82), WTCP(0x77be4111, 0x2d3a5d53), - WTCP(0x776c4edb, 0x2e110a62), WTCP(0x7718dbc8, 0x2ee722fb), WTCP(0x76c3e8e3, 0x2fbca46d), WTCP(0x766d773f, 0x30918c08), - WTCP(0x761587f3, 0x3165d71c), WTCP(0x75bc1c1a, 0x323982ff), WTCP(0x756134d4, 0x330c8d05), WTCP(0x7504d345, 0x33def287), - WTCP(0x74a6f899, 0x34b0b0df), WTCP(0x7447a5fc, 0x3581c569), WTCP(0x73e6dca3, 0x36522d83), WTCP(0x73849dc5, 0x3721e68d), - WTCP(0x7320ea9f, 0x37f0edea), WTCP(0x72bbc472, 0x38bf40ff), WTCP(0x72552c85, 0x398cdd32), WTCP(0x71ed2421, 0x3a59bfee), - WTCP(0x7183ac96, 0x3b25e69e), WTCP(0x7118c739, 0x3bf14eaf), WTCP(0x70ac7560, 0x3cbbf594), WTCP(0x703eb86a, 0x3d85d8bd), - WTCP(0x6fcf91b9, 0x3e4ef5a1), WTCP(0x6f5f02b2, 0x3f1749b8), WTCP(0x6eed0cc0, 0x3fded27c), WTCP(0x6e79b152, 0x40a58d69), - WTCP(0x6e04f1dd, 0x416b7801), WTCP(0x6d8ecfd8, 0x42308fc4), WTCP(0x6d174cc0, 0x42f4d237), WTCP(0x6c9e6a16, 0x43b83ce3), - WTCP(0x6c242960, 0x447acd50), WTCP(0x6ba88c28, 0x453c810d), WTCP(0x6b2b93fd, 0x45fd55a9), WTCP(0x6aad4270, 0x46bd48b7), - WTCP(0x6a2d9919, 0x477c57cb), WTCP(0x69ac9994, 0x483a807f), WTCP(0x692a4580, 0x48f7c06d), WTCP(0x68a69e81, 0x49b41533), - WTCP(0x6821a640, 0x4a6f7c74), WTCP(0x679b5e68, 0x4b29f3d1), WTCP(0x6713c8ac, 0x4be378f4), WTCP(0x668ae6bf, 0x4c9c0985), - WTCP(0x6600ba5b, 0x4d53a332), WTCP(0x6575453d, 0x4e0a43ab), WTCP(0x64e88926, 0x4ebfe8a5), WTCP(0x645a87dd, 0x4f748fd4), - WTCP(0x63cb432a, 0x502836f4), WTCP(0x633abcdc, 0x50dadbc1), WTCP(0x62a8f6c4, 0x518c7bfb), WTCP(0x6215f2b9, 0x523d1567), - WTCP(0x6181b292, 0x52eca5ca), WTCP(0x60ec3830, 0x539b2af0), WTCP(0x60558573, 0x5448a2a5), WTCP(0x5fbd9c41, 0x54f50abb), - WTCP(0x5f247e83, 0x55a06106), WTCP(0x5e8a2e27, 0x564aa35d), WTCP(0x5deead1f, 0x56f3cf9d), WTCP(0x5d51fd5e, 0x579be3a4), - WTCP(0x5cb420e0, 0x5842dd54), WTCP(0x5c15199f, 0x58e8ba94), WTCP(0x5b74e99d, 0x598d794c), WTCP(0x5ad392de, 0x5a31176a) +const PWord16 SineWindow224[112] = { + WTCP( 0x7fffcc70, 0x0072e46e ), WTCP( 0x7ffe2fee, 0x0158abd6 ), WTCP( 0x7ffaf6f1, 0x023e6ee8 ), WTCP( 0x7ff62182, 0x03242abf ), + WTCP( 0x7fefafb1, 0x0409dc76 ), WTCP( 0x7fe7a192, 0x04ef8129 ), WTCP( 0x7fddf741, 0x05d515f5 ), WTCP( 0x7fd2b0da, 0x06ba97f4 ), + WTCP( 0x7fc5ce84, 0x07a00445 ), WTCP( 0x7fb75068, 0x08855802 ), WTCP( 0x7fa736b4, 0x096a9049 ), WTCP( 0x7f95819c, 0x0a4faa38 ), + WTCP( 0x7f82315a, 0x0b34a2ec ), WTCP( 0x7f6d462b, 0x0c197784 ), WTCP( 0x7f56c053, 0x0cfe251d ), WTCP( 0x7f3ea01a, 0x0de2a8d7 ), + WTCP( 0x7f24e5cf, 0x0ec6ffd1 ), WTCP( 0x7f0991c4, 0x0fab272b ), WTCP( 0x7eeca451, 0x108f1c07 ), WTCP( 0x7ece1dd3, 0x1172db86 ), + WTCP( 0x7eadfeae, 0x125662c9 ), WTCP( 0x7e8c4748, 0x1339aef3 ), WTCP( 0x7e68f80e, 0x141cbd28 ), WTCP( 0x7e441171, 0x14ff8a8c ), + WTCP( 0x7e1d93ea, 0x15e21445 ), WTCP( 0x7df57ff3, 0x16c45777 ), WTCP( 0x7dcbd60e, 0x17a6514a ), WTCP( 0x7da096c2, 0x1887fee6 ), + WTCP( 0x7d73c299, 0x19695d74 ), WTCP( 0x7d455a24, 0x1a4a6a1c ), WTCP( 0x7d155df9, 0x1b2b220b ), WTCP( 0x7ce3ceb2, 0x1c0b826a ), + WTCP( 0x7cb0acef, 0x1ceb8869 ), WTCP( 0x7c7bf954, 0x1dcb3134 ), WTCP( 0x7c45b48d, 0x1eaa79fa ), WTCP( 0x7c0ddf47, 0x1f895fed ), + WTCP( 0x7bd47a36, 0x2067e03e ), WTCP( 0x7b998614, 0x2145f81f ), WTCP( 0x7b5d039e, 0x2223a4c5 ), WTCP( 0x7b1ef397, 0x2300e366 ), + WTCP( 0x7adf56c8, 0x23ddb139 ), WTCP( 0x7a9e2dfd, 0x24ba0b76 ), WTCP( 0x7a5b7a09, 0x2595ef56 ), WTCP( 0x7a173bc2, 0x26715a16 ), + WTCP( 0x79d17405, 0x274c48f2 ), WTCP( 0x798a23b1, 0x2826b928 ), WTCP( 0x79414bae, 0x2900a7f9 ), WTCP( 0x78f6ece5, 0x29da12a7 ), + WTCP( 0x78ab0847, 0x2ab2f674 ), WTCP( 0x785d9ec8, 0x2b8b50a5 ), WTCP( 0x780eb161, 0x2c631e82 ), WTCP( 0x77be4111, 0x2d3a5d53 ), + WTCP( 0x776c4edb, 0x2e110a62 ), WTCP( 0x7718dbc8, 0x2ee722fb ), WTCP( 0x76c3e8e3, 0x2fbca46d ), WTCP( 0x766d773f, 0x30918c08 ), + WTCP( 0x761587f3, 0x3165d71c ), WTCP( 0x75bc1c1a, 0x323982ff ), WTCP( 0x756134d4, 0x330c8d05 ), WTCP( 0x7504d345, 0x33def287 ), + WTCP( 0x74a6f899, 0x34b0b0df ), WTCP( 0x7447a5fc, 0x3581c569 ), WTCP( 0x73e6dca3, 0x36522d83 ), WTCP( 0x73849dc5, 0x3721e68d ), + WTCP( 0x7320ea9f, 0x37f0edea ), WTCP( 0x72bbc472, 0x38bf40ff ), WTCP( 0x72552c85, 0x398cdd32 ), WTCP( 0x71ed2421, 0x3a59bfee ), + WTCP( 0x7183ac96, 0x3b25e69e ), WTCP( 0x7118c739, 0x3bf14eaf ), WTCP( 0x70ac7560, 0x3cbbf594 ), WTCP( 0x703eb86a, 0x3d85d8bd ), + WTCP( 0x6fcf91b9, 0x3e4ef5a1 ), WTCP( 0x6f5f02b2, 0x3f1749b8 ), WTCP( 0x6eed0cc0, 0x3fded27c ), WTCP( 0x6e79b152, 0x40a58d69 ), + WTCP( 0x6e04f1dd, 0x416b7801 ), WTCP( 0x6d8ecfd8, 0x42308fc4 ), WTCP( 0x6d174cc0, 0x42f4d237 ), WTCP( 0x6c9e6a16, 0x43b83ce3 ), + WTCP( 0x6c242960, 0x447acd50 ), WTCP( 0x6ba88c28, 0x453c810d ), WTCP( 0x6b2b93fd, 0x45fd55a9 ), WTCP( 0x6aad4270, 0x46bd48b7 ), + WTCP( 0x6a2d9919, 0x477c57cb ), WTCP( 0x69ac9994, 0x483a807f ), WTCP( 0x692a4580, 0x48f7c06d ), WTCP( 0x68a69e81, 0x49b41533 ), + WTCP( 0x6821a640, 0x4a6f7c74 ), WTCP( 0x679b5e68, 0x4b29f3d1 ), WTCP( 0x6713c8ac, 0x4be378f4 ), WTCP( 0x668ae6bf, 0x4c9c0985 ), + WTCP( 0x6600ba5b, 0x4d53a332 ), WTCP( 0x6575453d, 0x4e0a43ab ), WTCP( 0x64e88926, 0x4ebfe8a5 ), WTCP( 0x645a87dd, 0x4f748fd4 ), + WTCP( 0x63cb432a, 0x502836f4 ), WTCP( 0x633abcdc, 0x50dadbc1 ), WTCP( 0x62a8f6c4, 0x518c7bfb ), WTCP( 0x6215f2b9, 0x523d1567 ), + WTCP( 0x6181b292, 0x52eca5ca ), WTCP( 0x60ec3830, 0x539b2af0 ), WTCP( 0x60558573, 0x5448a2a5 ), WTCP( 0x5fbd9c41, 0x54f50abb ), + WTCP( 0x5f247e83, 0x55a06106 ), WTCP( 0x5e8a2e27, 0x564aa35d ), WTCP( 0x5deead1f, 0x56f3cf9d ), WTCP( 0x5d51fd5e, 0x579be3a4 ), + WTCP( 0x5cb420e0, 0x5842dd54 ), WTCP( 0x5c15199f, 0x58e8ba94 ), WTCP( 0x5b74e99d, 0x598d794c ), WTCP( 0x5ad392de, 0x5a31176a ) }; -const PWord16 SineWindow256[128] = -{ - WTCP(0x7fffd886, 0x006487e3), WTCP(0x7ffe9cb2, 0x012d96b1), WTCP(0x7ffc250f, 0x01f6a297), WTCP(0x7ff871a2, 0x02bfa9a4), - WTCP(0x7ff38274, 0x0388a9ea), WTCP(0x7fed5791, 0x0451a177), WTCP(0x7fe5f108, 0x051a8e5c), WTCP(0x7fdd4eec, 0x05e36ea9), - WTCP(0x7fd37153, 0x06ac406f), WTCP(0x7fc85854, 0x077501be), WTCP(0x7fbc040a, 0x083db0a7), WTCP(0x7fae7495, 0x09064b3a), - WTCP(0x7f9faa15, 0x09cecf89), WTCP(0x7f8fa4b0, 0x0a973ba5), WTCP(0x7f7e648c, 0x0b5f8d9f), WTCP(0x7f6be9d4, 0x0c27c389), - WTCP(0x7f5834b7, 0x0cefdb76), WTCP(0x7f434563, 0x0db7d376), WTCP(0x7f2d1c0e, 0x0e7fa99e), WTCP(0x7f15b8ee, 0x0f475bff), - WTCP(0x7efd1c3c, 0x100ee8ad), WTCP(0x7ee34636, 0x10d64dbd), WTCP(0x7ec8371a, 0x119d8941), WTCP(0x7eabef2c, 0x1264994e), - WTCP(0x7e8e6eb2, 0x132b7bf9), WTCP(0x7e6fb5f4, 0x13f22f58), WTCP(0x7e4fc53e, 0x14b8b17f), WTCP(0x7e2e9cdf, 0x157f0086), - WTCP(0x7e0c3d29, 0x16451a83), WTCP(0x7de8a670, 0x170afd8d), WTCP(0x7dc3d90d, 0x17d0a7bc), WTCP(0x7d9dd55a, 0x18961728), - WTCP(0x7d769bb5, 0x195b49ea), WTCP(0x7d4e2c7f, 0x1a203e1b), WTCP(0x7d24881b, 0x1ae4f1d6), WTCP(0x7cf9aef0, 0x1ba96335), - WTCP(0x7ccda169, 0x1c6d9053), WTCP(0x7ca05ff1, 0x1d31774d), WTCP(0x7c71eaf9, 0x1df5163f), WTCP(0x7c4242f2, 0x1eb86b46), - WTCP(0x7c116853, 0x1f7b7481), WTCP(0x7bdf5b94, 0x203e300d), WTCP(0x7bac1d31, 0x21009c0c), WTCP(0x7b77ada8, 0x21c2b69c), - WTCP(0x7b420d7a, 0x22847de0), WTCP(0x7b0b3d2c, 0x2345eff8), WTCP(0x7ad33d45, 0x24070b08), WTCP(0x7a9a0e50, 0x24c7cd33), - WTCP(0x7a5fb0d8, 0x2588349d), WTCP(0x7a24256f, 0x26483f6c), WTCP(0x79e76ca7, 0x2707ebc7), WTCP(0x79a98715, 0x27c737d3), - WTCP(0x796a7554, 0x288621b9), WTCP(0x792a37fe, 0x2944a7a2), WTCP(0x78e8cfb2, 0x2a02c7b8), WTCP(0x78a63d11, 0x2ac08026), - WTCP(0x786280bf, 0x2b7dcf17), WTCP(0x781d9b65, 0x2c3ab2b9), WTCP(0x77d78daa, 0x2cf72939), WTCP(0x7790583e, 0x2db330c7), - WTCP(0x7747fbce, 0x2e6ec792), WTCP(0x76fe790e, 0x2f29ebcc), WTCP(0x76b3d0b4, 0x2fe49ba7), WTCP(0x76680376, 0x309ed556), - WTCP(0x761b1211, 0x3158970e), WTCP(0x75ccfd42, 0x3211df04), WTCP(0x757dc5ca, 0x32caab6f), WTCP(0x752d6c6c, 0x3382fa88), - WTCP(0x74dbf1ef, 0x343aca87), WTCP(0x7489571c, 0x34f219a8), WTCP(0x74359cbd, 0x35a8e625), WTCP(0x73e0c3a3, 0x365f2e3b), - WTCP(0x738acc9e, 0x3714f02a), WTCP(0x7333b883, 0x37ca2a30), WTCP(0x72db8828, 0x387eda8e), WTCP(0x72823c67, 0x3932ff87), - WTCP(0x7227d61c, 0x39e6975e), WTCP(0x71cc5626, 0x3a99a057), WTCP(0x716fbd68, 0x3b4c18ba), WTCP(0x71120cc5, 0x3bfdfecd), - WTCP(0x70b34525, 0x3caf50da), WTCP(0x70536771, 0x3d600d2c), WTCP(0x6ff27497, 0x3e10320d), WTCP(0x6f906d84, 0x3ebfbdcd), - WTCP(0x6f2d532c, 0x3f6eaeb8), WTCP(0x6ec92683, 0x401d0321), WTCP(0x6e63e87f, 0x40cab958), WTCP(0x6dfd9a1c, 0x4177cfb1), - WTCP(0x6d963c54, 0x42244481), WTCP(0x6d2dd027, 0x42d0161e), WTCP(0x6cc45698, 0x437b42e1), WTCP(0x6c59d0a9, 0x4425c923), - WTCP(0x6bee3f62, 0x44cfa740), WTCP(0x6b81a3cd, 0x4578db93), WTCP(0x6b13fef5, 0x4621647d), WTCP(0x6aa551e9, 0x46c9405c), - WTCP(0x6a359db9, 0x47706d93), WTCP(0x69c4e37a, 0x4816ea86), WTCP(0x69532442, 0x48bcb599), WTCP(0x68e06129, 0x4961cd33), - WTCP(0x686c9b4b, 0x4a062fbd), WTCP(0x67f7d3c5, 0x4aa9dba2), WTCP(0x67820bb7, 0x4b4ccf4d), WTCP(0x670b4444, 0x4bef092d), - WTCP(0x66937e91, 0x4c9087b1), WTCP(0x661abbc5, 0x4d31494b), WTCP(0x65a0fd0b, 0x4dd14c6e), WTCP(0x6526438f, 0x4e708f8f), - WTCP(0x64aa907f, 0x4f0f1126), WTCP(0x642de50d, 0x4faccfab), WTCP(0x63b0426d, 0x5049c999), WTCP(0x6331a9d4, 0x50e5fd6d), - WTCP(0x62b21c7b, 0x518169a5), WTCP(0x62319b9d, 0x521c0cc2), WTCP(0x61b02876, 0x52b5e546), WTCP(0x612dc447, 0x534ef1b5), - WTCP(0x60aa7050, 0x53e73097), WTCP(0x60262dd6, 0x547ea073), WTCP(0x5fa0fe1f, 0x55153fd4), WTCP(0x5f1ae274, 0x55ab0d46), - WTCP(0x5e93dc1f, 0x56400758), WTCP(0x5e0bec6e, 0x56d42c99), WTCP(0x5d8314b1, 0x57677b9d), WTCP(0x5cf95638, 0x57f9f2f8), - WTCP(0x5c6eb258, 0x588b9140), WTCP(0x5be32a67, 0x591c550e), WTCP(0x5b56bfbd, 0x59ac3cfd), WTCP(0x5ac973b5, 0x5a3b47ab), +const PWord16 SineWindow256[128] = { + WTCP( 0x7fffd886, 0x006487e3 ), + WTCP( 0x7ffe9cb2, 0x012d96b1 ), + WTCP( 0x7ffc250f, 0x01f6a297 ), + WTCP( 0x7ff871a2, 0x02bfa9a4 ), + WTCP( 0x7ff38274, 0x0388a9ea ), + WTCP( 0x7fed5791, 0x0451a177 ), + WTCP( 0x7fe5f108, 0x051a8e5c ), + WTCP( 0x7fdd4eec, 0x05e36ea9 ), + WTCP( 0x7fd37153, 0x06ac406f ), + WTCP( 0x7fc85854, 0x077501be ), + WTCP( 0x7fbc040a, 0x083db0a7 ), + WTCP( 0x7fae7495, 0x09064b3a ), + WTCP( 0x7f9faa15, 0x09cecf89 ), + WTCP( 0x7f8fa4b0, 0x0a973ba5 ), + WTCP( 0x7f7e648c, 0x0b5f8d9f ), + WTCP( 0x7f6be9d4, 0x0c27c389 ), + WTCP( 0x7f5834b7, 0x0cefdb76 ), + WTCP( 0x7f434563, 0x0db7d376 ), + WTCP( 0x7f2d1c0e, 0x0e7fa99e ), + WTCP( 0x7f15b8ee, 0x0f475bff ), + WTCP( 0x7efd1c3c, 0x100ee8ad ), + WTCP( 0x7ee34636, 0x10d64dbd ), + WTCP( 0x7ec8371a, 0x119d8941 ), + WTCP( 0x7eabef2c, 0x1264994e ), + WTCP( 0x7e8e6eb2, 0x132b7bf9 ), + WTCP( 0x7e6fb5f4, 0x13f22f58 ), + WTCP( 0x7e4fc53e, 0x14b8b17f ), + WTCP( 0x7e2e9cdf, 0x157f0086 ), + WTCP( 0x7e0c3d29, 0x16451a83 ), + WTCP( 0x7de8a670, 0x170afd8d ), + WTCP( 0x7dc3d90d, 0x17d0a7bc ), + WTCP( 0x7d9dd55a, 0x18961728 ), + WTCP( 0x7d769bb5, 0x195b49ea ), + WTCP( 0x7d4e2c7f, 0x1a203e1b ), + WTCP( 0x7d24881b, 0x1ae4f1d6 ), + WTCP( 0x7cf9aef0, 0x1ba96335 ), + WTCP( 0x7ccda169, 0x1c6d9053 ), + WTCP( 0x7ca05ff1, 0x1d31774d ), + WTCP( 0x7c71eaf9, 0x1df5163f ), + WTCP( 0x7c4242f2, 0x1eb86b46 ), + WTCP( 0x7c116853, 0x1f7b7481 ), + WTCP( 0x7bdf5b94, 0x203e300d ), + WTCP( 0x7bac1d31, 0x21009c0c ), + WTCP( 0x7b77ada8, 0x21c2b69c ), + WTCP( 0x7b420d7a, 0x22847de0 ), + WTCP( 0x7b0b3d2c, 0x2345eff8 ), + WTCP( 0x7ad33d45, 0x24070b08 ), + WTCP( 0x7a9a0e50, 0x24c7cd33 ), + WTCP( 0x7a5fb0d8, 0x2588349d ), + WTCP( 0x7a24256f, 0x26483f6c ), + WTCP( 0x79e76ca7, 0x2707ebc7 ), + WTCP( 0x79a98715, 0x27c737d3 ), + WTCP( 0x796a7554, 0x288621b9 ), + WTCP( 0x792a37fe, 0x2944a7a2 ), + WTCP( 0x78e8cfb2, 0x2a02c7b8 ), + WTCP( 0x78a63d11, 0x2ac08026 ), + WTCP( 0x786280bf, 0x2b7dcf17 ), + WTCP( 0x781d9b65, 0x2c3ab2b9 ), + WTCP( 0x77d78daa, 0x2cf72939 ), + WTCP( 0x7790583e, 0x2db330c7 ), + WTCP( 0x7747fbce, 0x2e6ec792 ), + WTCP( 0x76fe790e, 0x2f29ebcc ), + WTCP( 0x76b3d0b4, 0x2fe49ba7 ), + WTCP( 0x76680376, 0x309ed556 ), + WTCP( 0x761b1211, 0x3158970e ), + WTCP( 0x75ccfd42, 0x3211df04 ), + WTCP( 0x757dc5ca, 0x32caab6f ), + WTCP( 0x752d6c6c, 0x3382fa88 ), + WTCP( 0x74dbf1ef, 0x343aca87 ), + WTCP( 0x7489571c, 0x34f219a8 ), + WTCP( 0x74359cbd, 0x35a8e625 ), + WTCP( 0x73e0c3a3, 0x365f2e3b ), + WTCP( 0x738acc9e, 0x3714f02a ), + WTCP( 0x7333b883, 0x37ca2a30 ), + WTCP( 0x72db8828, 0x387eda8e ), + WTCP( 0x72823c67, 0x3932ff87 ), + WTCP( 0x7227d61c, 0x39e6975e ), + WTCP( 0x71cc5626, 0x3a99a057 ), + WTCP( 0x716fbd68, 0x3b4c18ba ), + WTCP( 0x71120cc5, 0x3bfdfecd ), + WTCP( 0x70b34525, 0x3caf50da ), + WTCP( 0x70536771, 0x3d600d2c ), + WTCP( 0x6ff27497, 0x3e10320d ), + WTCP( 0x6f906d84, 0x3ebfbdcd ), + WTCP( 0x6f2d532c, 0x3f6eaeb8 ), + WTCP( 0x6ec92683, 0x401d0321 ), + WTCP( 0x6e63e87f, 0x40cab958 ), + WTCP( 0x6dfd9a1c, 0x4177cfb1 ), + WTCP( 0x6d963c54, 0x42244481 ), + WTCP( 0x6d2dd027, 0x42d0161e ), + WTCP( 0x6cc45698, 0x437b42e1 ), + WTCP( 0x6c59d0a9, 0x4425c923 ), + WTCP( 0x6bee3f62, 0x44cfa740 ), + WTCP( 0x6b81a3cd, 0x4578db93 ), + WTCP( 0x6b13fef5, 0x4621647d ), + WTCP( 0x6aa551e9, 0x46c9405c ), + WTCP( 0x6a359db9, 0x47706d93 ), + WTCP( 0x69c4e37a, 0x4816ea86 ), + WTCP( 0x69532442, 0x48bcb599 ), + WTCP( 0x68e06129, 0x4961cd33 ), + WTCP( 0x686c9b4b, 0x4a062fbd ), + WTCP( 0x67f7d3c5, 0x4aa9dba2 ), + WTCP( 0x67820bb7, 0x4b4ccf4d ), + WTCP( 0x670b4444, 0x4bef092d ), + WTCP( 0x66937e91, 0x4c9087b1 ), + WTCP( 0x661abbc5, 0x4d31494b ), + WTCP( 0x65a0fd0b, 0x4dd14c6e ), + WTCP( 0x6526438f, 0x4e708f8f ), + WTCP( 0x64aa907f, 0x4f0f1126 ), + WTCP( 0x642de50d, 0x4faccfab ), + WTCP( 0x63b0426d, 0x5049c999 ), + WTCP( 0x6331a9d4, 0x50e5fd6d ), + WTCP( 0x62b21c7b, 0x518169a5 ), + WTCP( 0x62319b9d, 0x521c0cc2 ), + WTCP( 0x61b02876, 0x52b5e546 ), + WTCP( 0x612dc447, 0x534ef1b5 ), + WTCP( 0x60aa7050, 0x53e73097 ), + WTCP( 0x60262dd6, 0x547ea073 ), + WTCP( 0x5fa0fe1f, 0x55153fd4 ), + WTCP( 0x5f1ae274, 0x55ab0d46 ), + WTCP( 0x5e93dc1f, 0x56400758 ), + WTCP( 0x5e0bec6e, 0x56d42c99 ), + WTCP( 0x5d8314b1, 0x57677b9d ), + WTCP( 0x5cf95638, 0x57f9f2f8 ), + WTCP( 0x5c6eb258, 0x588b9140 ), + WTCP( 0x5be32a67, 0x591c550e ), + WTCP( 0x5b56bfbd, 0x59ac3cfd ), + WTCP( 0x5ac973b5, 0x5a3b47ab ), }; -const PWord16 SineWindow280[140] = -{ - WTCP(0x7fffdf00, 0x005be9f6), WTCP(0x7ffed6ff, 0x0113bd23), WTCP(0x7ffcc6ff, 0x01cb8e18), WTCP(0x7ff9af04, 0x02835b5a), - WTCP(0x7ff58f15, 0x033b236c), WTCP(0x7ff0673a, 0x03f2e4d4), WTCP(0x7fea377e, 0x04aa9e17), WTCP(0x7fe2ffee, 0x05624dba), - WTCP(0x7fdac098, 0x0619f243), WTCP(0x7fd1798e, 0x06d18a36), WTCP(0x7fc72ae2, 0x07891418), WTCP(0x7fbbd4aa, 0x08408e70), - WTCP(0x7faf76fe, 0x08f7f7c3), WTCP(0x7fa211f6, 0x09af4e96), WTCP(0x7f93a5af, 0x0a66916f), WTCP(0x7f843246, 0x0b1dbed5), - WTCP(0x7f73b7da, 0x0bd4d54d), WTCP(0x7f62368f, 0x0c8bd35e), WTCP(0x7f4fae88, 0x0d42b78f), WTCP(0x7f3c1fec, 0x0df98066), - WTCP(0x7f278ae1, 0x0eb02c6a), WTCP(0x7f11ef95, 0x0f66ba22), WTCP(0x7efb4e31, 0x101d2817), WTCP(0x7ee3a6e7, 0x10d374cf), - WTCP(0x7ecaf9e5, 0x11899ed3), WTCP(0x7eb1475f, 0x123fa4ab), WTCP(0x7e968f8b, 0x12f584e0), WTCP(0x7e7ad29e, 0x13ab3dfa), - WTCP(0x7e5e10d3, 0x1460ce82), WTCP(0x7e404a65, 0x15163503), WTCP(0x7e217f90, 0x15cb7006), WTCP(0x7e01b096, 0x16807e15), - WTCP(0x7de0ddb6, 0x17355dba), WTCP(0x7dbf0736, 0x17ea0d81), WTCP(0x7d9c2d5a, 0x189e8bf6), WTCP(0x7d78506a, 0x1952d7a3), - WTCP(0x7d5370b2, 0x1a06ef15), WTCP(0x7d2d8e7b, 0x1abad0d8), WTCP(0x7d06aa16, 0x1b6e7b7a), WTCP(0x7cdec3d2, 0x1c21ed87), - WTCP(0x7cb5dc00, 0x1cd5258f), WTCP(0x7c8bf2f7, 0x1d88221e), WTCP(0x7c61090b, 0x1e3ae1c5), WTCP(0x7c351e96, 0x1eed6311), - WTCP(0x7c0833f3, 0x1f9fa494), WTCP(0x7bda497d, 0x2051a4dd), WTCP(0x7bab5f93, 0x2103627d), WTCP(0x7b7b7697, 0x21b4dc06), - WTCP(0x7b4a8eeb, 0x2266100a), WTCP(0x7b18a8f4, 0x2316fd1b), WTCP(0x7ae5c518, 0x23c7a1cc), WTCP(0x7ab1e3c2, 0x2477fcb1), - WTCP(0x7a7d055b, 0x25280c5e), WTCP(0x7a472a51, 0x25d7cf68), WTCP(0x7a105313, 0x26874464), WTCP(0x79d88013, 0x273669e9), - WTCP(0x799fb1c2, 0x27e53e8e), WTCP(0x7965e897, 0x2893c0e9), WTCP(0x792b2508, 0x2941ef93), WTCP(0x78ef678f, 0x29efc925), - WTCP(0x78b2b0a7, 0x2a9d4c38), WTCP(0x787500ce, 0x2b4a7766), WTCP(0x78365881, 0x2bf7494a), WTCP(0x77f6b844, 0x2ca3c07f), - WTCP(0x77b62098, 0x2d4fdba2), WTCP(0x77749203, 0x2dfb9950), WTCP(0x77320d0d, 0x2ea6f827), WTCP(0x76ee923e, 0x2f51f6c4), - WTCP(0x76aa2222, 0x2ffc93c9), WTCP(0x7664bd46, 0x30a6cdd3), WTCP(0x761e6439, 0x3150a385), WTCP(0x75d7178c, 0x31fa1381), - WTCP(0x758ed7d2, 0x32a31c68), WTCP(0x7545a5a0, 0x334bbcde), WTCP(0x74fb818e, 0x33f3f387), WTCP(0x74b06c33, 0x349bbf09), - WTCP(0x7464662c, 0x35431e09), WTCP(0x74177014, 0x35ea0f2e), WTCP(0x73c98a8a, 0x36909120), WTCP(0x737ab630, 0x3736a287), - WTCP(0x732af3a7, 0x37dc420c), WTCP(0x72da4395, 0x38816e5b), WTCP(0x7288a69f, 0x3926261e), WTCP(0x72361d6e, 0x39ca6802), - WTCP(0x71e2a8ad, 0x3a6e32b4), WTCP(0x718e4907, 0x3b1184e2), WTCP(0x7138ff2a, 0x3bb45d3b), WTCP(0x70e2cbc6, 0x3c56ba70), - WTCP(0x708baf8d, 0x3cf89b31), WTCP(0x7033ab34, 0x3d99fe31), WTCP(0x6fdabf6e, 0x3e3ae223), WTCP(0x6f80ecf4, 0x3edb45ba), - WTCP(0x6f26347f, 0x3f7b27ac), WTCP(0x6eca96ca, 0x401a86b0), WTCP(0x6e6e1492, 0x40b9617d), WTCP(0x6e10ae96, 0x4157b6ca), - WTCP(0x6db26597, 0x41f58552), WTCP(0x6d533a56, 0x4292cbcf), WTCP(0x6cf32d99, 0x432f88fc), WTCP(0x6c924024, 0x43cbbb97), - WTCP(0x6c3072c1, 0x4467625d), WTCP(0x6bcdc639, 0x45027c0c), WTCP(0x6b6a3b58, 0x459d0766), WTCP(0x6b05d2ea, 0x4637032c), - WTCP(0x6aa08dbf, 0x46d06e1f), WTCP(0x6a3a6ca8, 0x47694703), WTCP(0x69d37078, 0x48018c9e), WTCP(0x696b9a02, 0x48993db5), - WTCP(0x6902ea1d, 0x4930590f), WTCP(0x689961a1, 0x49c6dd74), WTCP(0x682f0167, 0x4a5cc9af), WTCP(0x67c3ca4c, 0x4af21c89), - WTCP(0x6757bd2b, 0x4b86d4cf), WTCP(0x66eadae5, 0x4c1af14f), WTCP(0x667d2459, 0x4cae70d6), WTCP(0x660e9a6a, 0x4d415234), - WTCP(0x659f3dfc, 0x4dd3943b), WTCP(0x652f0ff4, 0x4e6535bd), WTCP(0x64be113a, 0x4ef6358d), WTCP(0x644c42b8, 0x4f869280), - WTCP(0x63d9a556, 0x50164b6d), WTCP(0x63663a03, 0x50a55f2c), WTCP(0x62f201ac, 0x5133cc94), WTCP(0x627cfd41, 0x51c19281), - WTCP(0x62072db3, 0x524eafce), WTCP(0x619093f5, 0x52db2357), WTCP(0x611930fc, 0x5366ebfc), WTCP(0x60a105be, 0x53f2089b), - WTCP(0x60281333, 0x547c7817), WTCP(0x5fae5a55, 0x55063951), WTCP(0x5f33dc1d, 0x558f4b2d), WTCP(0x5eb8998a, 0x5617ac90), - WTCP(0x5e3c9399, 0x569f5c62), WTCP(0x5dbfcb4a, 0x5726598b), WTCP(0x5d42419f, 0x57aca2f3), WTCP(0x5cc3f79a, 0x58323787), - WTCP(0x5c44ee40, 0x58b71632), WTCP(0x5bc52696, 0x593b3de2), WTCP(0x5b44a1a5, 0x59bead87), WTCP(0x5ac36076, 0x5a416413) +const PWord16 SineWindow280[140] = { + WTCP( 0x7fffdf00, 0x005be9f6 ), WTCP( 0x7ffed6ff, 0x0113bd23 ), WTCP( 0x7ffcc6ff, 0x01cb8e18 ), WTCP( 0x7ff9af04, 0x02835b5a ), + WTCP( 0x7ff58f15, 0x033b236c ), WTCP( 0x7ff0673a, 0x03f2e4d4 ), WTCP( 0x7fea377e, 0x04aa9e17 ), WTCP( 0x7fe2ffee, 0x05624dba ), + WTCP( 0x7fdac098, 0x0619f243 ), WTCP( 0x7fd1798e, 0x06d18a36 ), WTCP( 0x7fc72ae2, 0x07891418 ), WTCP( 0x7fbbd4aa, 0x08408e70 ), + WTCP( 0x7faf76fe, 0x08f7f7c3 ), WTCP( 0x7fa211f6, 0x09af4e96 ), WTCP( 0x7f93a5af, 0x0a66916f ), WTCP( 0x7f843246, 0x0b1dbed5 ), + WTCP( 0x7f73b7da, 0x0bd4d54d ), WTCP( 0x7f62368f, 0x0c8bd35e ), WTCP( 0x7f4fae88, 0x0d42b78f ), WTCP( 0x7f3c1fec, 0x0df98066 ), + WTCP( 0x7f278ae1, 0x0eb02c6a ), WTCP( 0x7f11ef95, 0x0f66ba22 ), WTCP( 0x7efb4e31, 0x101d2817 ), WTCP( 0x7ee3a6e7, 0x10d374cf ), + WTCP( 0x7ecaf9e5, 0x11899ed3 ), WTCP( 0x7eb1475f, 0x123fa4ab ), WTCP( 0x7e968f8b, 0x12f584e0 ), WTCP( 0x7e7ad29e, 0x13ab3dfa ), + WTCP( 0x7e5e10d3, 0x1460ce82 ), WTCP( 0x7e404a65, 0x15163503 ), WTCP( 0x7e217f90, 0x15cb7006 ), WTCP( 0x7e01b096, 0x16807e15 ), + WTCP( 0x7de0ddb6, 0x17355dba ), WTCP( 0x7dbf0736, 0x17ea0d81 ), WTCP( 0x7d9c2d5a, 0x189e8bf6 ), WTCP( 0x7d78506a, 0x1952d7a3 ), + WTCP( 0x7d5370b2, 0x1a06ef15 ), WTCP( 0x7d2d8e7b, 0x1abad0d8 ), WTCP( 0x7d06aa16, 0x1b6e7b7a ), WTCP( 0x7cdec3d2, 0x1c21ed87 ), + WTCP( 0x7cb5dc00, 0x1cd5258f ), WTCP( 0x7c8bf2f7, 0x1d88221e ), WTCP( 0x7c61090b, 0x1e3ae1c5 ), WTCP( 0x7c351e96, 0x1eed6311 ), + WTCP( 0x7c0833f3, 0x1f9fa494 ), WTCP( 0x7bda497d, 0x2051a4dd ), WTCP( 0x7bab5f93, 0x2103627d ), WTCP( 0x7b7b7697, 0x21b4dc06 ), + WTCP( 0x7b4a8eeb, 0x2266100a ), WTCP( 0x7b18a8f4, 0x2316fd1b ), WTCP( 0x7ae5c518, 0x23c7a1cc ), WTCP( 0x7ab1e3c2, 0x2477fcb1 ), + WTCP( 0x7a7d055b, 0x25280c5e ), WTCP( 0x7a472a51, 0x25d7cf68 ), WTCP( 0x7a105313, 0x26874464 ), WTCP( 0x79d88013, 0x273669e9 ), + WTCP( 0x799fb1c2, 0x27e53e8e ), WTCP( 0x7965e897, 0x2893c0e9 ), WTCP( 0x792b2508, 0x2941ef93 ), WTCP( 0x78ef678f, 0x29efc925 ), + WTCP( 0x78b2b0a7, 0x2a9d4c38 ), WTCP( 0x787500ce, 0x2b4a7766 ), WTCP( 0x78365881, 0x2bf7494a ), WTCP( 0x77f6b844, 0x2ca3c07f ), + WTCP( 0x77b62098, 0x2d4fdba2 ), WTCP( 0x77749203, 0x2dfb9950 ), WTCP( 0x77320d0d, 0x2ea6f827 ), WTCP( 0x76ee923e, 0x2f51f6c4 ), + WTCP( 0x76aa2222, 0x2ffc93c9 ), WTCP( 0x7664bd46, 0x30a6cdd3 ), WTCP( 0x761e6439, 0x3150a385 ), WTCP( 0x75d7178c, 0x31fa1381 ), + WTCP( 0x758ed7d2, 0x32a31c68 ), WTCP( 0x7545a5a0, 0x334bbcde ), WTCP( 0x74fb818e, 0x33f3f387 ), WTCP( 0x74b06c33, 0x349bbf09 ), + WTCP( 0x7464662c, 0x35431e09 ), WTCP( 0x74177014, 0x35ea0f2e ), WTCP( 0x73c98a8a, 0x36909120 ), WTCP( 0x737ab630, 0x3736a287 ), + WTCP( 0x732af3a7, 0x37dc420c ), WTCP( 0x72da4395, 0x38816e5b ), WTCP( 0x7288a69f, 0x3926261e ), WTCP( 0x72361d6e, 0x39ca6802 ), + WTCP( 0x71e2a8ad, 0x3a6e32b4 ), WTCP( 0x718e4907, 0x3b1184e2 ), WTCP( 0x7138ff2a, 0x3bb45d3b ), WTCP( 0x70e2cbc6, 0x3c56ba70 ), + WTCP( 0x708baf8d, 0x3cf89b31 ), WTCP( 0x7033ab34, 0x3d99fe31 ), WTCP( 0x6fdabf6e, 0x3e3ae223 ), WTCP( 0x6f80ecf4, 0x3edb45ba ), + WTCP( 0x6f26347f, 0x3f7b27ac ), WTCP( 0x6eca96ca, 0x401a86b0 ), WTCP( 0x6e6e1492, 0x40b9617d ), WTCP( 0x6e10ae96, 0x4157b6ca ), + WTCP( 0x6db26597, 0x41f58552 ), WTCP( 0x6d533a56, 0x4292cbcf ), WTCP( 0x6cf32d99, 0x432f88fc ), WTCP( 0x6c924024, 0x43cbbb97 ), + WTCP( 0x6c3072c1, 0x4467625d ), WTCP( 0x6bcdc639, 0x45027c0c ), WTCP( 0x6b6a3b58, 0x459d0766 ), WTCP( 0x6b05d2ea, 0x4637032c ), + WTCP( 0x6aa08dbf, 0x46d06e1f ), WTCP( 0x6a3a6ca8, 0x47694703 ), WTCP( 0x69d37078, 0x48018c9e ), WTCP( 0x696b9a02, 0x48993db5 ), + WTCP( 0x6902ea1d, 0x4930590f ), WTCP( 0x689961a1, 0x49c6dd74 ), WTCP( 0x682f0167, 0x4a5cc9af ), WTCP( 0x67c3ca4c, 0x4af21c89 ), + WTCP( 0x6757bd2b, 0x4b86d4cf ), WTCP( 0x66eadae5, 0x4c1af14f ), WTCP( 0x667d2459, 0x4cae70d6 ), WTCP( 0x660e9a6a, 0x4d415234 ), + WTCP( 0x659f3dfc, 0x4dd3943b ), WTCP( 0x652f0ff4, 0x4e6535bd ), WTCP( 0x64be113a, 0x4ef6358d ), WTCP( 0x644c42b8, 0x4f869280 ), + WTCP( 0x63d9a556, 0x50164b6d ), WTCP( 0x63663a03, 0x50a55f2c ), WTCP( 0x62f201ac, 0x5133cc94 ), WTCP( 0x627cfd41, 0x51c19281 ), + WTCP( 0x62072db3, 0x524eafce ), WTCP( 0x619093f5, 0x52db2357 ), WTCP( 0x611930fc, 0x5366ebfc ), WTCP( 0x60a105be, 0x53f2089b ), + WTCP( 0x60281333, 0x547c7817 ), WTCP( 0x5fae5a55, 0x55063951 ), WTCP( 0x5f33dc1d, 0x558f4b2d ), WTCP( 0x5eb8998a, 0x5617ac90 ), + WTCP( 0x5e3c9399, 0x569f5c62 ), WTCP( 0x5dbfcb4a, 0x5726598b ), WTCP( 0x5d42419f, 0x57aca2f3 ), WTCP( 0x5cc3f79a, 0x58323787 ), + WTCP( 0x5c44ee40, 0x58b71632 ), WTCP( 0x5bc52696, 0x593b3de2 ), WTCP( 0x5b44a1a5, 0x59bead87 ), WTCP( 0x5ac36076, 0x5a416413 ) }; -const PWord16 SineWindow320[160] = -{ - WTCP(0x7fffe6bc, 0x00506cb9), WTCP(0x7fff1c9b, 0x00f145ab), WTCP(0x7ffd885a, 0x01921d20), WTCP(0x7ffb29fd, 0x0232f21a), - WTCP(0x7ff80186, 0x02d3c39b), WTCP(0x7ff40efa, 0x037490a5), WTCP(0x7fef5260, 0x0415583b), WTCP(0x7fe9cbc0, 0x04b6195d), - WTCP(0x7fe37b22, 0x0556d30f), WTCP(0x7fdc608f, 0x05f78453), WTCP(0x7fd47c14, 0x06982c2b), WTCP(0x7fcbcdbc, 0x0738c998), - WTCP(0x7fc25596, 0x07d95b9e), WTCP(0x7fb813b0, 0x0879e140), WTCP(0x7fad081b, 0x091a597e), WTCP(0x7fa132e8, 0x09bac35d), - WTCP(0x7f949429, 0x0a5b1dde), WTCP(0x7f872bf3, 0x0afb6805), WTCP(0x7f78fa5b, 0x0b9ba0d5), WTCP(0x7f69ff76, 0x0c3bc74f), - WTCP(0x7f5a3b5e, 0x0cdbda79), WTCP(0x7f49ae2a, 0x0d7bd954), WTCP(0x7f3857f6, 0x0e1bc2e4), WTCP(0x7f2638db, 0x0ebb962c), - WTCP(0x7f1350f8, 0x0f5b5231), WTCP(0x7effa069, 0x0ffaf5f6), WTCP(0x7eeb274d, 0x109a807e), WTCP(0x7ed5e5c6, 0x1139f0cf), - WTCP(0x7ebfdbf5, 0x11d945eb), WTCP(0x7ea909fc, 0x12787ed8), WTCP(0x7e917000, 0x13179a9b), WTCP(0x7e790e25, 0x13b69836), - WTCP(0x7e5fe493, 0x145576b1), WTCP(0x7e45f371, 0x14f43510), WTCP(0x7e2b3ae8, 0x1592d257), WTCP(0x7e0fbb22, 0x16314d8e), - WTCP(0x7df3744b, 0x16cfa5b9), WTCP(0x7dd6668f, 0x176dd9de), WTCP(0x7db8921c, 0x180be904), WTCP(0x7d99f721, 0x18a9d231), - WTCP(0x7d7a95cf, 0x1947946c), WTCP(0x7d5a6e57, 0x19e52ebb), WTCP(0x7d3980ec, 0x1a82a026), WTCP(0x7d17cdc2, 0x1b1fe7b3), - WTCP(0x7cf5550e, 0x1bbd046c), WTCP(0x7cd21707, 0x1c59f557), WTCP(0x7cae13e4, 0x1cf6b97c), WTCP(0x7c894bde, 0x1d934fe5), - WTCP(0x7c63bf2f, 0x1e2fb79a), WTCP(0x7c3d6e13, 0x1ecbefa4), WTCP(0x7c1658c5, 0x1f67f70b), WTCP(0x7bee7f85, 0x2003ccdb), - WTCP(0x7bc5e290, 0x209f701c), WTCP(0x7b9c8226, 0x213adfda), WTCP(0x7b725e8a, 0x21d61b1e), WTCP(0x7b4777fe, 0x227120f3), - WTCP(0x7b1bcec4, 0x230bf065), WTCP(0x7aef6323, 0x23a6887f), WTCP(0x7ac23561, 0x2440e84d), WTCP(0x7a9445c5, 0x24db0edb), - WTCP(0x7a659496, 0x2574fb36), WTCP(0x7a362220, 0x260eac6a), WTCP(0x7a05eead, 0x26a82186), WTCP(0x79d4fa89, 0x27415996), - WTCP(0x79a34602, 0x27da53a9), WTCP(0x7970d165, 0x28730ecd), WTCP(0x793d9d03, 0x290b8a12), WTCP(0x7909a92d, 0x29a3c485), - WTCP(0x78d4f634, 0x2a3bbd37), WTCP(0x789f846b, 0x2ad37338), WTCP(0x78695428, 0x2b6ae598), WTCP(0x783265c0, 0x2c021369), - WTCP(0x77fab989, 0x2c98fbba), WTCP(0x77c24fdb, 0x2d2f9d9f), WTCP(0x77892910, 0x2dc5f829), WTCP(0x774f4581, 0x2e5c0a6b), - WTCP(0x7714a58b, 0x2ef1d377), WTCP(0x76d94989, 0x2f875262), WTCP(0x769d31d9, 0x301c863f), WTCP(0x76605edb, 0x30b16e23), - WTCP(0x7622d0ef, 0x31460922), WTCP(0x75e48874, 0x31da5651), WTCP(0x75a585cf, 0x326e54c7), WTCP(0x7565c962, 0x3302039b), - WTCP(0x75255392, 0x339561e1), WTCP(0x74e424c5, 0x34286eb3), WTCP(0x74a23d62, 0x34bb2927), WTCP(0x745f9dd1, 0x354d9057), - WTCP(0x741c467b, 0x35dfa35a), WTCP(0x73d837ca, 0x3671614b), WTCP(0x7393722a, 0x3702c942), WTCP(0x734df607, 0x3793da5b), - WTCP(0x7307c3d0, 0x382493b0), WTCP(0x72c0dbf3, 0x38b4f45d), WTCP(0x72793edf, 0x3944fb7e), WTCP(0x7230ed07, 0x39d4a82f), - WTCP(0x71e7e6dc, 0x3a63f98d), WTCP(0x719e2cd2, 0x3af2eeb7), WTCP(0x7153bf5d, 0x3b8186ca), WTCP(0x71089ef2, 0x3c0fc0e6), - WTCP(0x70bccc09, 0x3c9d9c28), WTCP(0x70704718, 0x3d2b17b3), WTCP(0x7023109a, 0x3db832a6), WTCP(0x6fd52907, 0x3e44ec22), - WTCP(0x6f8690db, 0x3ed14349), WTCP(0x6f374891, 0x3f5d373e), WTCP(0x6ee750a8, 0x3fe8c724), WTCP(0x6e96a99d, 0x4073f21d), - WTCP(0x6e4553ef, 0x40feb74f), WTCP(0x6df35020, 0x418915de), WTCP(0x6da09eb1, 0x42130cf0), WTCP(0x6d4d4023, 0x429c9bab), - WTCP(0x6cf934fc, 0x4325c135), WTCP(0x6ca47dbf, 0x43ae7cb7), WTCP(0x6c4f1af2, 0x4436cd58), WTCP(0x6bf90d1d, 0x44beb240), - WTCP(0x6ba254c7, 0x45462a9a), WTCP(0x6b4af279, 0x45cd358f), WTCP(0x6af2e6bc, 0x4653d24b), WTCP(0x6a9a321d, 0x46d9fff8), - WTCP(0x6a40d527, 0x475fbdc3), WTCP(0x69e6d067, 0x47e50ad8), WTCP(0x698c246c, 0x4869e665), WTCP(0x6930d1c4, 0x48ee4f98), - WTCP(0x68d4d900, 0x497245a1), WTCP(0x68783ab1, 0x49f5c7ae), WTCP(0x681af76a, 0x4a78d4f0), WTCP(0x67bd0fbd, 0x4afb6c98), - WTCP(0x675e843e, 0x4b7d8dd8), WTCP(0x66ff5584, 0x4bff37e2), WTCP(0x669f8425, 0x4c8069ea), WTCP(0x663f10b7, 0x4d012324), - WTCP(0x65ddfbd3, 0x4d8162c4), WTCP(0x657c4613, 0x4e012800), WTCP(0x6519f010, 0x4e80720e), WTCP(0x64b6fa66, 0x4eff4025), - WTCP(0x645365b2, 0x4f7d917c), WTCP(0x63ef3290, 0x4ffb654d), WTCP(0x638a619e, 0x5078bad1), WTCP(0x6324f37d, 0x50f59141), - WTCP(0x62bee8cc, 0x5171e7d9), WTCP(0x6258422c, 0x51edbdd4), WTCP(0x61f1003f, 0x5269126e), WTCP(0x618923a9, 0x52e3e4e6), - WTCP(0x6120ad0d, 0x535e3479), WTCP(0x60b79d10, 0x53d80065), WTCP(0x604df459, 0x545147eb), WTCP(0x5fe3b38d, 0x54ca0a4b), - WTCP(0x5f78db56, 0x554246c6), WTCP(0x5f0d6c5b, 0x55b9fc9e), WTCP(0x5ea16747, 0x56312b17), WTCP(0x5e34ccc3, 0x56a7d174), - WTCP(0x5dc79d7c, 0x571deefa), WTCP(0x5d59da1e, 0x579382ee), WTCP(0x5ceb8355, 0x58088c96), WTCP(0x5c7c99d1, 0x587d0b3b), - WTCP(0x5c0d1e41, 0x58f0fe23), WTCP(0x5b9d1154, 0x59646498), WTCP(0x5b2c73bb, 0x59d73de3), WTCP(0x5abb4629, 0x5a498950), +const PWord16 SineWindow320[160] = { + WTCP( 0x7fffe6bc, 0x00506cb9 ), + WTCP( 0x7fff1c9b, 0x00f145ab ), + WTCP( 0x7ffd885a, 0x01921d20 ), + WTCP( 0x7ffb29fd, 0x0232f21a ), + WTCP( 0x7ff80186, 0x02d3c39b ), + WTCP( 0x7ff40efa, 0x037490a5 ), + WTCP( 0x7fef5260, 0x0415583b ), + WTCP( 0x7fe9cbc0, 0x04b6195d ), + WTCP( 0x7fe37b22, 0x0556d30f ), + WTCP( 0x7fdc608f, 0x05f78453 ), + WTCP( 0x7fd47c14, 0x06982c2b ), + WTCP( 0x7fcbcdbc, 0x0738c998 ), + WTCP( 0x7fc25596, 0x07d95b9e ), + WTCP( 0x7fb813b0, 0x0879e140 ), + WTCP( 0x7fad081b, 0x091a597e ), + WTCP( 0x7fa132e8, 0x09bac35d ), + WTCP( 0x7f949429, 0x0a5b1dde ), + WTCP( 0x7f872bf3, 0x0afb6805 ), + WTCP( 0x7f78fa5b, 0x0b9ba0d5 ), + WTCP( 0x7f69ff76, 0x0c3bc74f ), + WTCP( 0x7f5a3b5e, 0x0cdbda79 ), + WTCP( 0x7f49ae2a, 0x0d7bd954 ), + WTCP( 0x7f3857f6, 0x0e1bc2e4 ), + WTCP( 0x7f2638db, 0x0ebb962c ), + WTCP( 0x7f1350f8, 0x0f5b5231 ), + WTCP( 0x7effa069, 0x0ffaf5f6 ), + WTCP( 0x7eeb274d, 0x109a807e ), + WTCP( 0x7ed5e5c6, 0x1139f0cf ), + WTCP( 0x7ebfdbf5, 0x11d945eb ), + WTCP( 0x7ea909fc, 0x12787ed8 ), + WTCP( 0x7e917000, 0x13179a9b ), + WTCP( 0x7e790e25, 0x13b69836 ), + WTCP( 0x7e5fe493, 0x145576b1 ), + WTCP( 0x7e45f371, 0x14f43510 ), + WTCP( 0x7e2b3ae8, 0x1592d257 ), + WTCP( 0x7e0fbb22, 0x16314d8e ), + WTCP( 0x7df3744b, 0x16cfa5b9 ), + WTCP( 0x7dd6668f, 0x176dd9de ), + WTCP( 0x7db8921c, 0x180be904 ), + WTCP( 0x7d99f721, 0x18a9d231 ), + WTCP( 0x7d7a95cf, 0x1947946c ), + WTCP( 0x7d5a6e57, 0x19e52ebb ), + WTCP( 0x7d3980ec, 0x1a82a026 ), + WTCP( 0x7d17cdc2, 0x1b1fe7b3 ), + WTCP( 0x7cf5550e, 0x1bbd046c ), + WTCP( 0x7cd21707, 0x1c59f557 ), + WTCP( 0x7cae13e4, 0x1cf6b97c ), + WTCP( 0x7c894bde, 0x1d934fe5 ), + WTCP( 0x7c63bf2f, 0x1e2fb79a ), + WTCP( 0x7c3d6e13, 0x1ecbefa4 ), + WTCP( 0x7c1658c5, 0x1f67f70b ), + WTCP( 0x7bee7f85, 0x2003ccdb ), + WTCP( 0x7bc5e290, 0x209f701c ), + WTCP( 0x7b9c8226, 0x213adfda ), + WTCP( 0x7b725e8a, 0x21d61b1e ), + WTCP( 0x7b4777fe, 0x227120f3 ), + WTCP( 0x7b1bcec4, 0x230bf065 ), + WTCP( 0x7aef6323, 0x23a6887f ), + WTCP( 0x7ac23561, 0x2440e84d ), + WTCP( 0x7a9445c5, 0x24db0edb ), + WTCP( 0x7a659496, 0x2574fb36 ), + WTCP( 0x7a362220, 0x260eac6a ), + WTCP( 0x7a05eead, 0x26a82186 ), + WTCP( 0x79d4fa89, 0x27415996 ), + WTCP( 0x79a34602, 0x27da53a9 ), + WTCP( 0x7970d165, 0x28730ecd ), + WTCP( 0x793d9d03, 0x290b8a12 ), + WTCP( 0x7909a92d, 0x29a3c485 ), + WTCP( 0x78d4f634, 0x2a3bbd37 ), + WTCP( 0x789f846b, 0x2ad37338 ), + WTCP( 0x78695428, 0x2b6ae598 ), + WTCP( 0x783265c0, 0x2c021369 ), + WTCP( 0x77fab989, 0x2c98fbba ), + WTCP( 0x77c24fdb, 0x2d2f9d9f ), + WTCP( 0x77892910, 0x2dc5f829 ), + WTCP( 0x774f4581, 0x2e5c0a6b ), + WTCP( 0x7714a58b, 0x2ef1d377 ), + WTCP( 0x76d94989, 0x2f875262 ), + WTCP( 0x769d31d9, 0x301c863f ), + WTCP( 0x76605edb, 0x30b16e23 ), + WTCP( 0x7622d0ef, 0x31460922 ), + WTCP( 0x75e48874, 0x31da5651 ), + WTCP( 0x75a585cf, 0x326e54c7 ), + WTCP( 0x7565c962, 0x3302039b ), + WTCP( 0x75255392, 0x339561e1 ), + WTCP( 0x74e424c5, 0x34286eb3 ), + WTCP( 0x74a23d62, 0x34bb2927 ), + WTCP( 0x745f9dd1, 0x354d9057 ), + WTCP( 0x741c467b, 0x35dfa35a ), + WTCP( 0x73d837ca, 0x3671614b ), + WTCP( 0x7393722a, 0x3702c942 ), + WTCP( 0x734df607, 0x3793da5b ), + WTCP( 0x7307c3d0, 0x382493b0 ), + WTCP( 0x72c0dbf3, 0x38b4f45d ), + WTCP( 0x72793edf, 0x3944fb7e ), + WTCP( 0x7230ed07, 0x39d4a82f ), + WTCP( 0x71e7e6dc, 0x3a63f98d ), + WTCP( 0x719e2cd2, 0x3af2eeb7 ), + WTCP( 0x7153bf5d, 0x3b8186ca ), + WTCP( 0x71089ef2, 0x3c0fc0e6 ), + WTCP( 0x70bccc09, 0x3c9d9c28 ), + WTCP( 0x70704718, 0x3d2b17b3 ), + WTCP( 0x7023109a, 0x3db832a6 ), + WTCP( 0x6fd52907, 0x3e44ec22 ), + WTCP( 0x6f8690db, 0x3ed14349 ), + WTCP( 0x6f374891, 0x3f5d373e ), + WTCP( 0x6ee750a8, 0x3fe8c724 ), + WTCP( 0x6e96a99d, 0x4073f21d ), + WTCP( 0x6e4553ef, 0x40feb74f ), + WTCP( 0x6df35020, 0x418915de ), + WTCP( 0x6da09eb1, 0x42130cf0 ), + WTCP( 0x6d4d4023, 0x429c9bab ), + WTCP( 0x6cf934fc, 0x4325c135 ), + WTCP( 0x6ca47dbf, 0x43ae7cb7 ), + WTCP( 0x6c4f1af2, 0x4436cd58 ), + WTCP( 0x6bf90d1d, 0x44beb240 ), + WTCP( 0x6ba254c7, 0x45462a9a ), + WTCP( 0x6b4af279, 0x45cd358f ), + WTCP( 0x6af2e6bc, 0x4653d24b ), + WTCP( 0x6a9a321d, 0x46d9fff8 ), + WTCP( 0x6a40d527, 0x475fbdc3 ), + WTCP( 0x69e6d067, 0x47e50ad8 ), + WTCP( 0x698c246c, 0x4869e665 ), + WTCP( 0x6930d1c4, 0x48ee4f98 ), + WTCP( 0x68d4d900, 0x497245a1 ), + WTCP( 0x68783ab1, 0x49f5c7ae ), + WTCP( 0x681af76a, 0x4a78d4f0 ), + WTCP( 0x67bd0fbd, 0x4afb6c98 ), + WTCP( 0x675e843e, 0x4b7d8dd8 ), + WTCP( 0x66ff5584, 0x4bff37e2 ), + WTCP( 0x669f8425, 0x4c8069ea ), + WTCP( 0x663f10b7, 0x4d012324 ), + WTCP( 0x65ddfbd3, 0x4d8162c4 ), + WTCP( 0x657c4613, 0x4e012800 ), + WTCP( 0x6519f010, 0x4e80720e ), + WTCP( 0x64b6fa66, 0x4eff4025 ), + WTCP( 0x645365b2, 0x4f7d917c ), + WTCP( 0x63ef3290, 0x4ffb654d ), + WTCP( 0x638a619e, 0x5078bad1 ), + WTCP( 0x6324f37d, 0x50f59141 ), + WTCP( 0x62bee8cc, 0x5171e7d9 ), + WTCP( 0x6258422c, 0x51edbdd4 ), + WTCP( 0x61f1003f, 0x5269126e ), + WTCP( 0x618923a9, 0x52e3e4e6 ), + WTCP( 0x6120ad0d, 0x535e3479 ), + WTCP( 0x60b79d10, 0x53d80065 ), + WTCP( 0x604df459, 0x545147eb ), + WTCP( 0x5fe3b38d, 0x54ca0a4b ), + WTCP( 0x5f78db56, 0x554246c6 ), + WTCP( 0x5f0d6c5b, 0x55b9fc9e ), + WTCP( 0x5ea16747, 0x56312b17 ), + WTCP( 0x5e34ccc3, 0x56a7d174 ), + WTCP( 0x5dc79d7c, 0x571deefa ), + WTCP( 0x5d59da1e, 0x579382ee ), + WTCP( 0x5ceb8355, 0x58088c96 ), + WTCP( 0x5c7c99d1, 0x587d0b3b ), + WTCP( 0x5c0d1e41, 0x58f0fe23 ), + WTCP( 0x5b9d1154, 0x59646498 ), + WTCP( 0x5b2c73bb, 0x59d73de3 ), + WTCP( 0x5abb4629, 0x5a498950 ), }; -const PWord16 SineWindow420[210] = -{ - WTCP(0x7ffff155, 0x003d46a7), WTCP(0x7fff7bff, 0x00b7d3bc), WTCP(0x7ffe9154, 0x01326029), WTCP(0x7ffd3154, 0x01aceb7c), - WTCP(0x7ffb5c00, 0x02277547), WTCP(0x7ff9115b, 0x02a1fd18), WTCP(0x7ff65166, 0x031c8280), WTCP(0x7ff31c25, 0x0397050d), - WTCP(0x7fef7199, 0x0411844f), WTCP(0x7feb51c6, 0x048bffd7), WTCP(0x7fe6bcb0, 0x05067734), WTCP(0x7fe1b25b, 0x0580e9f6), - WTCP(0x7fdc32cc, 0x05fb57ac), WTCP(0x7fd63e09, 0x0675bfe7), WTCP(0x7fcfd415, 0x06f02235), WTCP(0x7fc8f4f7, 0x076a7e27), - WTCP(0x7fc1a0b6, 0x07e4d34d), WTCP(0x7fb9d759, 0x085f2137), WTCP(0x7fb198e5, 0x08d96773), WTCP(0x7fa8e564, 0x0953a594), - WTCP(0x7f9fbcdc, 0x09cddb27), WTCP(0x7f961f57, 0x0a4807be), WTCP(0x7f8c0cdc, 0x0ac22ae8), WTCP(0x7f818577, 0x0b3c4435), - WTCP(0x7f76892f, 0x0bb65336), WTCP(0x7f6b180f, 0x0c30577a), WTCP(0x7f5f3221, 0x0caa5092), WTCP(0x7f52d771, 0x0d243e0d), - WTCP(0x7f46080a, 0x0d9e1f7d), WTCP(0x7f38c3f7, 0x0e17f471), WTCP(0x7f2b0b45, 0x0e91bc79), WTCP(0x7f1cde01, 0x0f0b7727), - WTCP(0x7f0e3c36, 0x0f85240a), WTCP(0x7eff25f3, 0x0ffec2b3), WTCP(0x7eef9b46, 0x107852b2), WTCP(0x7edf9c3c, 0x10f1d398), - WTCP(0x7ecf28e5, 0x116b44f6), WTCP(0x7ebe414f, 0x11e4a65c), WTCP(0x7eace58a, 0x125df75b), WTCP(0x7e9b15a6, 0x12d73784), - WTCP(0x7e88d1b4, 0x13506668), WTCP(0x7e7619c3, 0x13c98397), WTCP(0x7e62ede5, 0x14428ea2), WTCP(0x7e4f4e2c, 0x14bb871b), - WTCP(0x7e3b3aaa, 0x15346c93), WTCP(0x7e26b371, 0x15ad3e9a), WTCP(0x7e11b894, 0x1625fcc3), WTCP(0x7dfc4a26, 0x169ea69e), - WTCP(0x7de6683a, 0x17173bbd), WTCP(0x7dd012e6, 0x178fbbb1), WTCP(0x7db94a3c, 0x1808260c), WTCP(0x7da20e53, 0x18807a5f), - WTCP(0x7d8a5f40, 0x18f8b83c), WTCP(0x7d723d18, 0x1970df36), WTCP(0x7d59a7f1, 0x19e8eedd), WTCP(0x7d409fe1, 0x1a60e6c3), - WTCP(0x7d272501, 0x1ad8c67c), WTCP(0x7d0d3767, 0x1b508d98), WTCP(0x7cf2d72b, 0x1bc83baa), WTCP(0x7cd80464, 0x1c3fd045), - WTCP(0x7cbcbf2d, 0x1cb74afa), WTCP(0x7ca1079d, 0x1d2eab5d), WTCP(0x7c84ddcf, 0x1da5f0ff), WTCP(0x7c6841db, 0x1e1d1b73), - WTCP(0x7c4b33dc, 0x1e942a4d), WTCP(0x7c2db3ee, 0x1f0b1d1f), WTCP(0x7c0fc22a, 0x1f81f37c), WTCP(0x7bf15eac, 0x1ff8acf7), - WTCP(0x7bd28991, 0x206f4923), WTCP(0x7bb342f3, 0x20e5c793), WTCP(0x7b938af1, 0x215c27dc), WTCP(0x7b7361a7, 0x21d2698f), - WTCP(0x7b52c733, 0x22488c42), WTCP(0x7b31bbb2, 0x22be8f87), WTCP(0x7b103f43, 0x233472f3), WTCP(0x7aee5205, 0x23aa361a), - WTCP(0x7acbf416, 0x241fd88e), WTCP(0x7aa92596, 0x249559e6), WTCP(0x7a85e6a5, 0x250ab9b4), WTCP(0x7a623764, 0x257ff78e), - WTCP(0x7a3e17f2, 0x25f51307), WTCP(0x7a198872, 0x266a0bb5), WTCP(0x79f48904, 0x26dee12c), WTCP(0x79cf19cb, 0x27539302), - WTCP(0x79a93ae9, 0x27c820ca), WTCP(0x7982ec80, 0x283c8a1b), WTCP(0x795c2eb5, 0x28b0ce8a), WTCP(0x793501a9, 0x2924edac), - WTCP(0x790d6581, 0x2998e716), WTCP(0x78e55a62, 0x2a0cba5e), WTCP(0x78bce070, 0x2a80671b), WTCP(0x7893f7d1, 0x2af3ece2), - WTCP(0x786aa0a9, 0x2b674b49), WTCP(0x7840db1f, 0x2bda81e6), WTCP(0x7816a759, 0x2c4d9050), WTCP(0x77ec057d, 0x2cc0761e), - WTCP(0x77c0f5b3, 0x2d3332e5), WTCP(0x77957822, 0x2da5c63e), WTCP(0x77698cf3, 0x2e182fbe), WTCP(0x773d344d, 0x2e8a6efd), - WTCP(0x77106e58, 0x2efc8393), WTCP(0x76e33b3f, 0x2f6e6d16), WTCP(0x76b59b2a, 0x2fe02b1e), WTCP(0x76878e43, 0x3051bd43), - WTCP(0x765914b5, 0x30c3231d), WTCP(0x762a2eaa, 0x31345c44), WTCP(0x75fadc4d, 0x31a56850), WTCP(0x75cb1dca, 0x321646d9), - WTCP(0x759af34c, 0x3286f779), WTCP(0x756a5cff, 0x32f779c7), WTCP(0x75395b10, 0x3367cd5d), WTCP(0x7507edac, 0x33d7f1d3), - WTCP(0x74d61500, 0x3447e6c3), WTCP(0x74a3d13a, 0x34b7abc6), WTCP(0x74712288, 0x35274076), WTCP(0x743e0918, 0x3596a46c), - WTCP(0x740a8519, 0x3605d743), WTCP(0x73d696bb, 0x3674d894), WTCP(0x73a23e2d, 0x36e3a7fa), WTCP(0x736d7b9f, 0x3752450f), - WTCP(0x73384f41, 0x37c0af6d), WTCP(0x7302b945, 0x382ee6b0), WTCP(0x72ccb9db, 0x389cea72), WTCP(0x72965134, 0x390aba4f), - WTCP(0x725f7f84, 0x397855e1), WTCP(0x722844fb, 0x39e5bcc5), WTCP(0x71f0a1cc, 0x3a52ee96), WTCP(0x71b8962b, 0x3abfeaf1), - WTCP(0x7180224b, 0x3b2cb170), WTCP(0x71474660, 0x3b9941b1), WTCP(0x710e029e, 0x3c059b4f), WTCP(0x70d45738, 0x3c71bde8), - WTCP(0x709a4465, 0x3cdda919), WTCP(0x705fca59, 0x3d495c7e), WTCP(0x7024e94b, 0x3db4d7b5), WTCP(0x6fe9a16f, 0x3e201a5b), - WTCP(0x6fadf2fc, 0x3e8b240e), WTCP(0x6f71de2a, 0x3ef5f46c), WTCP(0x6f35632e, 0x3f608b13), WTCP(0x6ef88241, 0x3fcae7a1), - WTCP(0x6ebb3b9a, 0x403509b4), WTCP(0x6e7d8f72, 0x409ef0ed), WTCP(0x6e3f7e01, 0x41089ce8), WTCP(0x6e010780, 0x41720d46), - WTCP(0x6dc22c28, 0x41db41a5), WTCP(0x6d82ec32, 0x424439a6), WTCP(0x6d4347da, 0x42acf4e8), WTCP(0x6d033f58, 0x4315730c), - WTCP(0x6cc2d2e9, 0x437db3b0), WTCP(0x6c8202c6, 0x43e5b676), WTCP(0x6c40cf2c, 0x444d7aff), WTCP(0x6bff3855, 0x44b500eb), - WTCP(0x6bbd3e7f, 0x451c47dc), WTCP(0x6b7ae1e6, 0x45834f72), WTCP(0x6b3822c6, 0x45ea1750), WTCP(0x6af5015c, 0x46509f16), - WTCP(0x6ab17de7, 0x46b6e668), WTCP(0x6a6d98a4, 0x471cece7), WTCP(0x6a2951d2, 0x4782b236), WTCP(0x69e4a9ae, 0x47e835f7), - WTCP(0x699fa078, 0x484d77ce), WTCP(0x695a366f, 0x48b2775d), WTCP(0x69146bd3, 0x49173448), WTCP(0x68ce40e4, 0x497bae33), - WTCP(0x6887b5e2, 0x49dfe4c2), WTCP(0x6840cb0e, 0x4a43d799), WTCP(0x67f980a8, 0x4aa7865b), WTCP(0x67b1d6f3, 0x4b0af0ae), - WTCP(0x6769ce2f, 0x4b6e1637), WTCP(0x6721669f, 0x4bd0f69b), WTCP(0x66d8a085, 0x4c33917f), WTCP(0x668f7c25, 0x4c95e688), - WTCP(0x6645f9c0, 0x4cf7f55d), WTCP(0x65fc199a, 0x4d59bda3), WTCP(0x65b1dbf8, 0x4dbb3f02), WTCP(0x6567411d, 0x4e1c791f), - WTCP(0x651c494d, 0x4e7d6ba2), WTCP(0x64d0f4ce, 0x4ede1631), WTCP(0x648543e4, 0x4f3e7875), WTCP(0x643936d4, 0x4f9e9214), - WTCP(0x63eccde5, 0x4ffe62b6), WTCP(0x63a0095c, 0x505dea05), WTCP(0x6352e980, 0x50bd27a7), WTCP(0x63056e98, 0x511c1b47), - WTCP(0x62b798ea, 0x517ac48c), WTCP(0x626968be, 0x51d92321), WTCP(0x621ade5c, 0x523736ae), WTCP(0x61cbfa0b, 0x5294fedd), - WTCP(0x617cbc14, 0x52f27b58), WTCP(0x612d24c0, 0x534fabcb), WTCP(0x60dd3457, 0x53ac8fde), WTCP(0x608ceb22, 0x5409273e), - WTCP(0x603c496c, 0x54657194), WTCP(0x5feb4f7f, 0x54c16e8e), WTCP(0x5f99fda4, 0x551d1dd5), WTCP(0x5f485426, 0x55787f17), - WTCP(0x5ef6534f, 0x55d391ff), WTCP(0x5ea3fb6c, 0x562e563a), WTCP(0x5e514cc8, 0x5688cb75), WTCP(0x5dfe47ad, 0x56e2f15d), - WTCP(0x5daaec6a, 0x573cc79f), WTCP(0x5d573b49, 0x57964de9), WTCP(0x5d033497, 0x57ef83e9), WTCP(0x5caed8a2, 0x5848694d), - WTCP(0x5c5a27b8, 0x58a0fdc3), WTCP(0x5c052224, 0x58f940fa), WTCP(0x5bafc837, 0x595132a2), WTCP(0x5b5a1a3d, 0x59a8d26a), - WTCP(0x5b041885, 0x5a002001), WTCP(0x5aadc35e, 0x5a571b18) +const PWord16 SineWindow420[210] = { + WTCP( 0x7ffff155, 0x003d46a7 ), WTCP( 0x7fff7bff, 0x00b7d3bc ), WTCP( 0x7ffe9154, 0x01326029 ), WTCP( 0x7ffd3154, 0x01aceb7c ), + WTCP( 0x7ffb5c00, 0x02277547 ), WTCP( 0x7ff9115b, 0x02a1fd18 ), WTCP( 0x7ff65166, 0x031c8280 ), WTCP( 0x7ff31c25, 0x0397050d ), + WTCP( 0x7fef7199, 0x0411844f ), WTCP( 0x7feb51c6, 0x048bffd7 ), WTCP( 0x7fe6bcb0, 0x05067734 ), WTCP( 0x7fe1b25b, 0x0580e9f6 ), + WTCP( 0x7fdc32cc, 0x05fb57ac ), WTCP( 0x7fd63e09, 0x0675bfe7 ), WTCP( 0x7fcfd415, 0x06f02235 ), WTCP( 0x7fc8f4f7, 0x076a7e27 ), + WTCP( 0x7fc1a0b6, 0x07e4d34d ), WTCP( 0x7fb9d759, 0x085f2137 ), WTCP( 0x7fb198e5, 0x08d96773 ), WTCP( 0x7fa8e564, 0x0953a594 ), + WTCP( 0x7f9fbcdc, 0x09cddb27 ), WTCP( 0x7f961f57, 0x0a4807be ), WTCP( 0x7f8c0cdc, 0x0ac22ae8 ), WTCP( 0x7f818577, 0x0b3c4435 ), + WTCP( 0x7f76892f, 0x0bb65336 ), WTCP( 0x7f6b180f, 0x0c30577a ), WTCP( 0x7f5f3221, 0x0caa5092 ), WTCP( 0x7f52d771, 0x0d243e0d ), + WTCP( 0x7f46080a, 0x0d9e1f7d ), WTCP( 0x7f38c3f7, 0x0e17f471 ), WTCP( 0x7f2b0b45, 0x0e91bc79 ), WTCP( 0x7f1cde01, 0x0f0b7727 ), + WTCP( 0x7f0e3c36, 0x0f85240a ), WTCP( 0x7eff25f3, 0x0ffec2b3 ), WTCP( 0x7eef9b46, 0x107852b2 ), WTCP( 0x7edf9c3c, 0x10f1d398 ), + WTCP( 0x7ecf28e5, 0x116b44f6 ), WTCP( 0x7ebe414f, 0x11e4a65c ), WTCP( 0x7eace58a, 0x125df75b ), WTCP( 0x7e9b15a6, 0x12d73784 ), + WTCP( 0x7e88d1b4, 0x13506668 ), WTCP( 0x7e7619c3, 0x13c98397 ), WTCP( 0x7e62ede5, 0x14428ea2 ), WTCP( 0x7e4f4e2c, 0x14bb871b ), + WTCP( 0x7e3b3aaa, 0x15346c93 ), WTCP( 0x7e26b371, 0x15ad3e9a ), WTCP( 0x7e11b894, 0x1625fcc3 ), WTCP( 0x7dfc4a26, 0x169ea69e ), + WTCP( 0x7de6683a, 0x17173bbd ), WTCP( 0x7dd012e6, 0x178fbbb1 ), WTCP( 0x7db94a3c, 0x1808260c ), WTCP( 0x7da20e53, 0x18807a5f ), + WTCP( 0x7d8a5f40, 0x18f8b83c ), WTCP( 0x7d723d18, 0x1970df36 ), WTCP( 0x7d59a7f1, 0x19e8eedd ), WTCP( 0x7d409fe1, 0x1a60e6c3 ), + WTCP( 0x7d272501, 0x1ad8c67c ), WTCP( 0x7d0d3767, 0x1b508d98 ), WTCP( 0x7cf2d72b, 0x1bc83baa ), WTCP( 0x7cd80464, 0x1c3fd045 ), + WTCP( 0x7cbcbf2d, 0x1cb74afa ), WTCP( 0x7ca1079d, 0x1d2eab5d ), WTCP( 0x7c84ddcf, 0x1da5f0ff ), WTCP( 0x7c6841db, 0x1e1d1b73 ), + WTCP( 0x7c4b33dc, 0x1e942a4d ), WTCP( 0x7c2db3ee, 0x1f0b1d1f ), WTCP( 0x7c0fc22a, 0x1f81f37c ), WTCP( 0x7bf15eac, 0x1ff8acf7 ), + WTCP( 0x7bd28991, 0x206f4923 ), WTCP( 0x7bb342f3, 0x20e5c793 ), WTCP( 0x7b938af1, 0x215c27dc ), WTCP( 0x7b7361a7, 0x21d2698f ), + WTCP( 0x7b52c733, 0x22488c42 ), WTCP( 0x7b31bbb2, 0x22be8f87 ), WTCP( 0x7b103f43, 0x233472f3 ), WTCP( 0x7aee5205, 0x23aa361a ), + WTCP( 0x7acbf416, 0x241fd88e ), WTCP( 0x7aa92596, 0x249559e6 ), WTCP( 0x7a85e6a5, 0x250ab9b4 ), WTCP( 0x7a623764, 0x257ff78e ), + WTCP( 0x7a3e17f2, 0x25f51307 ), WTCP( 0x7a198872, 0x266a0bb5 ), WTCP( 0x79f48904, 0x26dee12c ), WTCP( 0x79cf19cb, 0x27539302 ), + WTCP( 0x79a93ae9, 0x27c820ca ), WTCP( 0x7982ec80, 0x283c8a1b ), WTCP( 0x795c2eb5, 0x28b0ce8a ), WTCP( 0x793501a9, 0x2924edac ), + WTCP( 0x790d6581, 0x2998e716 ), WTCP( 0x78e55a62, 0x2a0cba5e ), WTCP( 0x78bce070, 0x2a80671b ), WTCP( 0x7893f7d1, 0x2af3ece2 ), + WTCP( 0x786aa0a9, 0x2b674b49 ), WTCP( 0x7840db1f, 0x2bda81e6 ), WTCP( 0x7816a759, 0x2c4d9050 ), WTCP( 0x77ec057d, 0x2cc0761e ), + WTCP( 0x77c0f5b3, 0x2d3332e5 ), WTCP( 0x77957822, 0x2da5c63e ), WTCP( 0x77698cf3, 0x2e182fbe ), WTCP( 0x773d344d, 0x2e8a6efd ), + WTCP( 0x77106e58, 0x2efc8393 ), WTCP( 0x76e33b3f, 0x2f6e6d16 ), WTCP( 0x76b59b2a, 0x2fe02b1e ), WTCP( 0x76878e43, 0x3051bd43 ), + WTCP( 0x765914b5, 0x30c3231d ), WTCP( 0x762a2eaa, 0x31345c44 ), WTCP( 0x75fadc4d, 0x31a56850 ), WTCP( 0x75cb1dca, 0x321646d9 ), + WTCP( 0x759af34c, 0x3286f779 ), WTCP( 0x756a5cff, 0x32f779c7 ), WTCP( 0x75395b10, 0x3367cd5d ), WTCP( 0x7507edac, 0x33d7f1d3 ), + WTCP( 0x74d61500, 0x3447e6c3 ), WTCP( 0x74a3d13a, 0x34b7abc6 ), WTCP( 0x74712288, 0x35274076 ), WTCP( 0x743e0918, 0x3596a46c ), + WTCP( 0x740a8519, 0x3605d743 ), WTCP( 0x73d696bb, 0x3674d894 ), WTCP( 0x73a23e2d, 0x36e3a7fa ), WTCP( 0x736d7b9f, 0x3752450f ), + WTCP( 0x73384f41, 0x37c0af6d ), WTCP( 0x7302b945, 0x382ee6b0 ), WTCP( 0x72ccb9db, 0x389cea72 ), WTCP( 0x72965134, 0x390aba4f ), + WTCP( 0x725f7f84, 0x397855e1 ), WTCP( 0x722844fb, 0x39e5bcc5 ), WTCP( 0x71f0a1cc, 0x3a52ee96 ), WTCP( 0x71b8962b, 0x3abfeaf1 ), + WTCP( 0x7180224b, 0x3b2cb170 ), WTCP( 0x71474660, 0x3b9941b1 ), WTCP( 0x710e029e, 0x3c059b4f ), WTCP( 0x70d45738, 0x3c71bde8 ), + WTCP( 0x709a4465, 0x3cdda919 ), WTCP( 0x705fca59, 0x3d495c7e ), WTCP( 0x7024e94b, 0x3db4d7b5 ), WTCP( 0x6fe9a16f, 0x3e201a5b ), + WTCP( 0x6fadf2fc, 0x3e8b240e ), WTCP( 0x6f71de2a, 0x3ef5f46c ), WTCP( 0x6f35632e, 0x3f608b13 ), WTCP( 0x6ef88241, 0x3fcae7a1 ), + WTCP( 0x6ebb3b9a, 0x403509b4 ), WTCP( 0x6e7d8f72, 0x409ef0ed ), WTCP( 0x6e3f7e01, 0x41089ce8 ), WTCP( 0x6e010780, 0x41720d46 ), + WTCP( 0x6dc22c28, 0x41db41a5 ), WTCP( 0x6d82ec32, 0x424439a6 ), WTCP( 0x6d4347da, 0x42acf4e8 ), WTCP( 0x6d033f58, 0x4315730c ), + WTCP( 0x6cc2d2e9, 0x437db3b0 ), WTCP( 0x6c8202c6, 0x43e5b676 ), WTCP( 0x6c40cf2c, 0x444d7aff ), WTCP( 0x6bff3855, 0x44b500eb ), + WTCP( 0x6bbd3e7f, 0x451c47dc ), WTCP( 0x6b7ae1e6, 0x45834f72 ), WTCP( 0x6b3822c6, 0x45ea1750 ), WTCP( 0x6af5015c, 0x46509f16 ), + WTCP( 0x6ab17de7, 0x46b6e668 ), WTCP( 0x6a6d98a4, 0x471cece7 ), WTCP( 0x6a2951d2, 0x4782b236 ), WTCP( 0x69e4a9ae, 0x47e835f7 ), + WTCP( 0x699fa078, 0x484d77ce ), WTCP( 0x695a366f, 0x48b2775d ), WTCP( 0x69146bd3, 0x49173448 ), WTCP( 0x68ce40e4, 0x497bae33 ), + WTCP( 0x6887b5e2, 0x49dfe4c2 ), WTCP( 0x6840cb0e, 0x4a43d799 ), WTCP( 0x67f980a8, 0x4aa7865b ), WTCP( 0x67b1d6f3, 0x4b0af0ae ), + WTCP( 0x6769ce2f, 0x4b6e1637 ), WTCP( 0x6721669f, 0x4bd0f69b ), WTCP( 0x66d8a085, 0x4c33917f ), WTCP( 0x668f7c25, 0x4c95e688 ), + WTCP( 0x6645f9c0, 0x4cf7f55d ), WTCP( 0x65fc199a, 0x4d59bda3 ), WTCP( 0x65b1dbf8, 0x4dbb3f02 ), WTCP( 0x6567411d, 0x4e1c791f ), + WTCP( 0x651c494d, 0x4e7d6ba2 ), WTCP( 0x64d0f4ce, 0x4ede1631 ), WTCP( 0x648543e4, 0x4f3e7875 ), WTCP( 0x643936d4, 0x4f9e9214 ), + WTCP( 0x63eccde5, 0x4ffe62b6 ), WTCP( 0x63a0095c, 0x505dea05 ), WTCP( 0x6352e980, 0x50bd27a7 ), WTCP( 0x63056e98, 0x511c1b47 ), + WTCP( 0x62b798ea, 0x517ac48c ), WTCP( 0x626968be, 0x51d92321 ), WTCP( 0x621ade5c, 0x523736ae ), WTCP( 0x61cbfa0b, 0x5294fedd ), + WTCP( 0x617cbc14, 0x52f27b58 ), WTCP( 0x612d24c0, 0x534fabcb ), WTCP( 0x60dd3457, 0x53ac8fde ), WTCP( 0x608ceb22, 0x5409273e ), + WTCP( 0x603c496c, 0x54657194 ), WTCP( 0x5feb4f7f, 0x54c16e8e ), WTCP( 0x5f99fda4, 0x551d1dd5 ), WTCP( 0x5f485426, 0x55787f17 ), + WTCP( 0x5ef6534f, 0x55d391ff ), WTCP( 0x5ea3fb6c, 0x562e563a ), WTCP( 0x5e514cc8, 0x5688cb75 ), WTCP( 0x5dfe47ad, 0x56e2f15d ), + WTCP( 0x5daaec6a, 0x573cc79f ), WTCP( 0x5d573b49, 0x57964de9 ), WTCP( 0x5d033497, 0x57ef83e9 ), WTCP( 0x5caed8a2, 0x5848694d ), + WTCP( 0x5c5a27b8, 0x58a0fdc3 ), WTCP( 0x5c052224, 0x58f940fa ), WTCP( 0x5bafc837, 0x595132a2 ), WTCP( 0x5b5a1a3d, 0x59a8d26a ), + WTCP( 0x5b041885, 0x5a002001 ), WTCP( 0x5aadc35e, 0x5a571b18 ) }; -const PWord16 *const windowSlopes[1][2][8] = -{ - { /* Sine */ - { /* Radix 2 */ - NULL, - NULL, - SineWindow16, - SineWindow32, - SineWindow64, - SineWindow128, - SineWindow256, - NULL - }, - { /* 640 raster */ - NULL, /* 2.5 */ - NULL, /* 5 */ - SineWindow10, - SineWindow20, - SineWindow40, - SineWindow80, - SineWindow160, - SineWindow320 - }, - } +const PWord16 *const windowSlopes[1][2][8] = { + { + /* Sine */ + { /* Radix 2 */ + NULL, + NULL, + SineWindow16, + SineWindow32, + SineWindow64, + SineWindow128, + SineWindow256, + NULL }, + { /* 640 raster */ + NULL, /* 2.5 */ + NULL, /* 5 */ + SineWindow10, + SineWindow20, + SineWindow40, + SineWindow80, + SineWindow160, + SineWindow320 }, + } }; -#define DCTIV_SINETABLE SineTable512 +#define DCTIV_SINETABLE SineTable512 #define DCTIV_SINETABLE_SIZE_LD 9 -#define DCTIV_SINETABLE320 SineTable320 +#define DCTIV_SINETABLE320 SineTable320 #define DCTIV_SINETABLE320_SIZE_LD 8 -void BASOP_getTables(const PWord16 **ptwiddle, const PWord16 **sin_twiddle, Word16 *psin_step, Word16 length) +void BASOP_getTables( const PWord16 **ptwiddle, const PWord16 **sin_twiddle, Word16 *psin_step, Word16 length ) { - const PWord16 *twiddle; - const PWord16 *sine; - Word16 ld2_length, sin_step; - - /* Get ld2 of length - 2 + 1 - -2: because first table entry is window of size 4 - +1: because we already include +1 because of ceil(log2(length)) */ - ld2_length = sub(16 - 1 - 1, norm_s(length)); - - /* Extract sort of "eigenvalue" (the 5 left most bits) of length. */ - SWITCH((unsigned short)lshl(length, sub(15, ld2_length))) - { - case 0xa000: /* 640 */ - move16(); - move16(); - sine = DCTIV_SINETABLE320; - sin_step = shl(1, sub(DCTIV_SINETABLE320_SIZE_LD + 1, ld2_length)); - twiddle = windowSlopes[0][1][sub(ld2_length, 1)]; - BREAK; - - case 0x8000: /* radix 2 */ - move16(); - move16(); - sine = DCTIV_SINETABLE; - sin_step = shl(1, sub(DCTIV_SINETABLE_SIZE_LD + 1, ld2_length)); - twiddle = windowSlopes[0][0][sub(ld2_length, 2)]; - BREAK; - - default: /* not instrumented, probably obsolete */ - sine = NULL; - sin_step = 0; - twiddle = NULL; - BREAK; - } - - if (ptwiddle != NULL) - { - assert(twiddle != NULL || length == 0); - move16(); - *ptwiddle = twiddle; - } - - if (sin_twiddle != NULL) - { - move16(); - *sin_twiddle = sine; - } - if (psin_step != NULL) - { - assert(sin_step > 0 || length == 0); - move16(); - *psin_step = sin_step; - } + const PWord16 *twiddle; + const PWord16 *sine; + Word16 ld2_length, sin_step; + + /* Get ld2 of length - 2 + 1 + -2: because first table entry is window of size 4 + +1: because we already include +1 because of ceil(log2(length)) */ + ld2_length = sub( 16 - 1 - 1, norm_s( length ) ); + + /* Extract sort of "eigenvalue" (the 5 left most bits) of length. */ + SWITCH( (unsigned short) lshl( length, sub( 15, ld2_length ) ) ) + { + case 0xa000: /* 640 */ + move16(); + move16(); + sine = DCTIV_SINETABLE320; + sin_step = shl( 1, sub( DCTIV_SINETABLE320_SIZE_LD + 1, ld2_length ) ); + twiddle = windowSlopes[0][1][sub( ld2_length, 1 )]; + BREAK; + + case 0x8000: /* radix 2 */ + move16(); + move16(); + sine = DCTIV_SINETABLE; + sin_step = shl( 1, sub( DCTIV_SINETABLE_SIZE_LD + 1, ld2_length ) ); + twiddle = windowSlopes[0][0][sub( ld2_length, 2 )]; + BREAK; + + default: /* not instrumented, probably obsolete */ + sine = NULL; + sin_step = 0; + twiddle = NULL; + BREAK; + } + + if ( ptwiddle != NULL ) + { + assert( twiddle != NULL || length == 0 ); + move16(); + *ptwiddle = twiddle; + } + + if ( sin_twiddle != NULL ) + { + move16(); + *sin_twiddle = sine; + } + if ( psin_step != NULL ) + { + assert( sin_step > 0 || length == 0 ); + move16(); + *psin_step = sin_step; + } } -const PWord16* getSineWindowTable(Word16 length) +const PWord16 *getSineWindowTable( Word16 length ) { - const PWord16 *p = NULL; - - switch (length) - { - case 10: - p = SineWindow10; - BREAK; - case 16: - p = SineWindow16; - BREAK; - case 20: - p = SineWindow20; - BREAK; - case 30: - p = SineWindow30; - BREAK; - case 32: - p = SineWindow32; - BREAK; - case 40: - p = SineWindow40; - BREAK; - case 48: - p = SineWindow48; - BREAK; - case 60: - p = SineWindow60; - BREAK; - case 70: - p = SineWindow70; - BREAK; - case 96: - p = SineWindow96; - BREAK; - case 112: - p = SineWindow112; - BREAK; - case 120: - p = SineWindow120; - BREAK; - case 140: - p = SineWindow140; - BREAK; - case 180: - p = SineWindow180; - BREAK; - case 224: - p = SineWindow224; - BREAK; - case 280: - p = SineWindow280; - BREAK; - case 420: - p = SineWindow420; - BREAK; - } - - assert(p != NULL); - - return p; + const PWord16 *p = NULL; + + switch ( length ) + { + case 10: + p = SineWindow10; + BREAK; + case 16: + p = SineWindow16; + BREAK; + case 20: + p = SineWindow20; + BREAK; + case 30: + p = SineWindow30; + BREAK; + case 32: + p = SineWindow32; + BREAK; + case 40: + p = SineWindow40; + BREAK; + case 48: + p = SineWindow48; + BREAK; + case 60: + p = SineWindow60; + BREAK; + case 70: + p = SineWindow70; + BREAK; + case 96: + p = SineWindow96; + BREAK; + case 112: + p = SineWindow112; + BREAK; + case 120: + p = SineWindow120; + BREAK; + case 140: + p = SineWindow140; + BREAK; + case 180: + p = SineWindow180; + BREAK; + case 224: + p = SineWindow224; + BREAK; + case 280: + p = SineWindow280; + BREAK; + case 420: + p = SineWindow420; + BREAK; + } + + assert( p != NULL ); + + return p; } diff --git a/lib_com/rom_basop_util.h b/lib_com/rom_basop_util.h index 1f31eea20..e32ce0cc7 100644 --- a/lib_com/rom_basop_util.h +++ b/lib_com/rom_basop_util.h @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #ifndef __BASOP_UTIL_ROM_H__ @@ -48,7 +48,7 @@ extern const PWord16 SineTable320[161]; * \ brief Lookup for sine tables and windows. */ -void BASOP_getTables(const PWord16 **ptwiddle, const PWord16 **sin_twiddle, Word16 *sin_step, Word16 length); -const PWord16* getSineWindowTable(Word16 length); +void BASOP_getTables( const PWord16 **ptwiddle, const PWord16 **sin_twiddle, Word16 *sin_step, Word16 length ); +const PWord16 *getSineWindowTable( Word16 length ); #endif diff --git a/lib_com/rom_com.c b/lib_com/rom_com.c index 256fc16d7..9590726d1 100644 --- a/lib_com/rom_com.c +++ b/lib_com/rom_com.c @@ -40095,468 +40095,462 @@ const Word16 TecSC_Fx[] = const float TecSC[] = { 0.3662f, 0.1078f, 0.1194f, 0.1289f, 0.1365f, 0.1412f }; /* clang-format on */ -const Word16 sqrt_table_pitch_search[256 + 1] = /* Q11 */ -{ - 0, 2048, 2896, 3547, 4096, 4579, 5017, 5418, - 5793, 6144, 6476, 6792, 7094, 7384, 7663, 7932, - 8192, 8444, 8689, 8927, 9159, 9385, 9606, 9822, - 10033, 10240, 10443, 10642, 10837, 11029, 11217, 11403, - 11585, 11765, 11942, 12116, 12288, 12457, 12625, 12790, - 12953, 13114, 13273, 13430, 13585, 13738, 13890, 14040, - 14189, 14336, 14482, 14626, 14768, 14910, 15050, 15188, - 15326, 15462, 15597, 15731, 15864, 15995, 16126, 16255, - 16384, 16512, 16638, 16764, 16888, 17012, 17135, 17257, - 17378, 17498, 17618, 17736, 17854, 17971, 18087, 18203, - 18318, 18432, 18545, 18658, 18770, 18882, 18992, 19102, - 19212, 19321, 19429, 19537, 19644, 19750, 19856, 19961, - 20066, 20170, 20274, 20377, 20480, 20582, 20684, 20785, - 20886, 20986, 21085, 21185, 21283, 21382, 21480, 21577, - 21674, 21771, 21867, 21962, 22058, 22153, 22247, 22341, - 22435, 22528, 22621, 22713, 22806, 22897, 22989, 23080, - 23170, 23261, 23351, 23440, 23530, 23619, 23707, 23796, - 23884, 23971, 24059, 24146, 24232, 24319, 24405, 24491, - 24576, 24661, 24746, 24831, 24915, 24999, 25083, 25166, - 25249, 25332, 25415, 25497, 25580, 25661, 25743, 25824, - 25905, 25986, 26067, 26147, 26227, 26307, 26387, 26466, - 26545, 26624, 26703, 26781, 26859, 26937, 27015, 27092, - 27170, 27247, 27324, 27400, 27477, 27553, 27629, 27705, - 27780, 27856, 27931, 28006, 28081, 28155, 28230, 28304, - 28378, 28452, 28525, 28599, 28672, 28745, 28818, 28891, - 28963, 29035, 29108, 29180, 29251, 29323, 29394, 29466, - 29537, 29608, 29678, 29749, 29819, 29890, 29960, 30030, - 30099, 30169, 30238, 30308, 30377, 30446, 30515, 30583, - 30652, 30720, 30788, 30856, 30924, 30992, 31059, 31127, - 31194, 31261, 31328, 31395, 31462, 31529, 31595, 31661, - 31727, 31794, 31859, 31925, 31991, 32056, 32122, 32187, - 32252, 32317, 32382, 32446, 32511, 32575, 32640, 32704, - 32766 -}; - -//fft_evs.c -const Word16 RotVector_32[2 * 20] = -{ - /** - * \brief Twiddle factors are unscaled - */ - SHC(0x7d8a), SHC(0xe707), SHC(0x7642), SHC(0xcf04), SHC(0x6a6e), SHC(0xb8e3), SHC(0x5a82), SHC(0xa57e), - SHC(0x471d), SHC(0x9592), SHC(0x30fc), SHC(0x89be), SHC(0x18f9), SHC(0x8276), SHC(0x7642), SHC(0xcf04), - SHC(0x5a82), SHC(0xa57e), SHC(0x30fc), SHC(0x89be), SHC(0xcf04), SHC(0x89be), SHC(0xa57e), SHC(0xa57e), - SHC(0x89be), SHC(0xcf04), SHC(0x6a6e), SHC(0xb8e3), SHC(0x30fc), SHC(0x89be), SHC(0xe707), SHC(0x8276), - SHC(0xa57e), SHC(0xa57e), SHC(0x8276), SHC(0xe707), SHC(0x89be), SHC(0x30fc), SHC(0xb8e3), SHC(0x6a6e) +const Word16 sqrt_table_pitch_search[256 + 1] = /* Q11 */ + { + 0, 2048, 2896, 3547, 4096, 4579, 5017, 5418, + 5793, 6144, 6476, 6792, 7094, 7384, 7663, 7932, + 8192, 8444, 8689, 8927, 9159, 9385, 9606, 9822, + 10033, 10240, 10443, 10642, 10837, 11029, 11217, 11403, + 11585, 11765, 11942, 12116, 12288, 12457, 12625, 12790, + 12953, 13114, 13273, 13430, 13585, 13738, 13890, 14040, + 14189, 14336, 14482, 14626, 14768, 14910, 15050, 15188, + 15326, 15462, 15597, 15731, 15864, 15995, 16126, 16255, + 16384, 16512, 16638, 16764, 16888, 17012, 17135, 17257, + 17378, 17498, 17618, 17736, 17854, 17971, 18087, 18203, + 18318, 18432, 18545, 18658, 18770, 18882, 18992, 19102, + 19212, 19321, 19429, 19537, 19644, 19750, 19856, 19961, + 20066, 20170, 20274, 20377, 20480, 20582, 20684, 20785, + 20886, 20986, 21085, 21185, 21283, 21382, 21480, 21577, + 21674, 21771, 21867, 21962, 22058, 22153, 22247, 22341, + 22435, 22528, 22621, 22713, 22806, 22897, 22989, 23080, + 23170, 23261, 23351, 23440, 23530, 23619, 23707, 23796, + 23884, 23971, 24059, 24146, 24232, 24319, 24405, 24491, + 24576, 24661, 24746, 24831, 24915, 24999, 25083, 25166, + 25249, 25332, 25415, 25497, 25580, 25661, 25743, 25824, + 25905, 25986, 26067, 26147, 26227, 26307, 26387, 26466, + 26545, 26624, 26703, 26781, 26859, 26937, 27015, 27092, + 27170, 27247, 27324, 27400, 27477, 27553, 27629, 27705, + 27780, 27856, 27931, 28006, 28081, 28155, 28230, 28304, + 28378, 28452, 28525, 28599, 28672, 28745, 28818, 28891, + 28963, 29035, 29108, 29180, 29251, 29323, 29394, 29466, + 29537, 29608, 29678, 29749, 29819, 29890, 29960, 30030, + 30099, 30169, 30238, 30308, 30377, 30446, 30515, 30583, + 30652, 30720, 30788, 30856, 30924, 30992, 31059, 31127, + 31194, 31261, 31328, 31395, 31462, 31529, 31595, 31661, + 31727, 31794, 31859, 31925, 31991, 32056, 32122, 32187, + 32252, 32317, 32382, 32446, 32511, 32575, 32640, 32704, + 32766 + }; + +// fft_evs.c +const Word16 RotVector_32[2 * 20] = { + /** + * \brief Twiddle factors are unscaled + */ + SHC( 0x7d8a ), SHC( 0xe707 ), SHC( 0x7642 ), SHC( 0xcf04 ), SHC( 0x6a6e ), SHC( 0xb8e3 ), SHC( 0x5a82 ), SHC( 0xa57e ), + SHC( 0x471d ), SHC( 0x9592 ), SHC( 0x30fc ), SHC( 0x89be ), SHC( 0x18f9 ), SHC( 0x8276 ), SHC( 0x7642 ), SHC( 0xcf04 ), + SHC( 0x5a82 ), SHC( 0xa57e ), SHC( 0x30fc ), SHC( 0x89be ), SHC( 0xcf04 ), SHC( 0x89be ), SHC( 0xa57e ), SHC( 0xa57e ), + SHC( 0x89be ), SHC( 0xcf04 ), SHC( 0x6a6e ), SHC( 0xb8e3 ), SHC( 0x30fc ), SHC( 0x89be ), SHC( 0xe707 ), SHC( 0x8276 ), + SHC( 0xa57e ), SHC( 0xa57e ), SHC( 0x8276 ), SHC( 0xe707 ), SHC( 0x89be ), SHC( 0x30fc ), SHC( 0xb8e3 ), SHC( 0x6a6e ) }; /** * \brief Twiddle factors are unscaled */ -const Word16 RotVector_480[2 * (480 - 30)] = -{ - SHC(0x7fff), SHC(0x0000), SHC(0x7ff5), SHC(0xfca6), - SHC(0x7fd3), SHC(0xf94d), SHC(0x7f9b), SHC(0xf5f5), SHC(0x7f4c), SHC(0xf29f), SHC(0x7ee8), SHC(0xef4b), - SHC(0x7e6d), SHC(0xebfa), SHC(0x7ddb), SHC(0xe8ad), SHC(0x7d34), SHC(0xe563), SHC(0x7c77), SHC(0xe21e), - SHC(0x7ba3), SHC(0xdedf), SHC(0x7abb), SHC(0xdba5), SHC(0x79bc), SHC(0xd872), SHC(0x78a8), SHC(0xd546), - SHC(0x7780), SHC(0xd221), SHC(0x7642), SHC(0xcf04), SHC(0x74ef), SHC(0xcbf0), SHC(0x7388), SHC(0xc8e5), - SHC(0x720d), SHC(0xc5e4), SHC(0x707d), SHC(0xc2ec), SHC(0x6eda), SHC(0xc000), SHC(0x6d23), SHC(0xbd1f), - SHC(0x6b5a), SHC(0xba49), SHC(0x697d), SHC(0xb780), SHC(0x678e), SHC(0xb4c3), SHC(0x658d), SHC(0xb214), - SHC(0x637a), SHC(0xaf72), SHC(0x6155), SHC(0xacdf), SHC(0x5f1f), SHC(0xaa5a), SHC(0x5cd9), SHC(0xa7e4), - SHC(0x7fff), SHC(0x0000), SHC(0x7fd3), SHC(0xf94d), SHC(0x7f4c), SHC(0xf29f), SHC(0x7e6d), SHC(0xebfa), - SHC(0x7d34), SHC(0xe563), SHC(0x7ba3), SHC(0xdedf), SHC(0x79bc), SHC(0xd872), SHC(0x7780), SHC(0xd221), - SHC(0x74ef), SHC(0xcbf0), SHC(0x720d), SHC(0xc5e4), SHC(0x6eda), SHC(0xc000), SHC(0x6b5a), SHC(0xba49), - SHC(0x678e), SHC(0xb4c3), SHC(0x637a), SHC(0xaf72), SHC(0x5f1f), SHC(0xaa5a), SHC(0x5a82), SHC(0xa57e), - SHC(0x55a6), SHC(0xa0e1), SHC(0x508e), SHC(0x9c86), SHC(0x4b3d), SHC(0x9872), SHC(0x45b7), SHC(0x94a6), - SHC(0x4000), SHC(0x9126), SHC(0x3a1c), SHC(0x8df3), SHC(0x3410), SHC(0x8b11), SHC(0x2ddf), SHC(0x8880), - SHC(0x278e), SHC(0x8644), SHC(0x2121), SHC(0x845d), SHC(0x1a9d), SHC(0x82cc), SHC(0x1406), SHC(0x8193), - SHC(0x0d61), SHC(0x80b4), SHC(0x06b3), SHC(0x802d), SHC(0x7fff), SHC(0x0000), SHC(0x7f9b), SHC(0xf5f5), - SHC(0x7e6d), SHC(0xebfa), SHC(0x7c77), SHC(0xe21e), SHC(0x79bc), SHC(0xd872), SHC(0x7642), SHC(0xcf04), - SHC(0x720d), SHC(0xc5e4), SHC(0x6d23), SHC(0xbd1f), SHC(0x678e), SHC(0xb4c3), SHC(0x6155), SHC(0xacdf), - SHC(0x5a82), SHC(0xa57e), SHC(0x5321), SHC(0x9eab), SHC(0x4b3d), SHC(0x9872), SHC(0x42e1), SHC(0x92dd), - SHC(0x3a1c), SHC(0x8df3), SHC(0x30fc), SHC(0x89be), SHC(0x278e), SHC(0x8644), SHC(0x1de2), SHC(0x8389), - SHC(0x1406), SHC(0x8193), SHC(0x0a0b), SHC(0x8065), SHC(0x0000), SHC(0x8000), SHC(0xf5f5), SHC(0x8065), - SHC(0xebfa), SHC(0x8193), SHC(0xe21e), SHC(0x8389), SHC(0xd872), SHC(0x8644), SHC(0xcf04), SHC(0x89be), - SHC(0xc5e4), SHC(0x8df3), SHC(0xbd1f), SHC(0x92dd), SHC(0xb4c3), SHC(0x9872), SHC(0xacdf), SHC(0x9eab), - SHC(0x7fff), SHC(0x0000), SHC(0x7f4c), SHC(0xf29f), SHC(0x7d34), SHC(0xe563), SHC(0x79bc), SHC(0xd872), - SHC(0x74ef), SHC(0xcbf0), SHC(0x6eda), SHC(0xc000), SHC(0x678e), SHC(0xb4c3), SHC(0x5f1f), SHC(0xaa5a), - SHC(0x55a6), SHC(0xa0e1), SHC(0x4b3d), SHC(0x9872), SHC(0x4000), SHC(0x9126), SHC(0x3410), SHC(0x8b11), - SHC(0x278e), SHC(0x8644), SHC(0x1a9d), SHC(0x82cc), SHC(0x0d61), SHC(0x80b4), SHC(0x0000), SHC(0x8000), - SHC(0xf29f), SHC(0x80b4), SHC(0xe563), SHC(0x82cc), SHC(0xd872), SHC(0x8644), SHC(0xcbf0), SHC(0x8b11), - SHC(0xc000), SHC(0x9126), SHC(0xb4c3), SHC(0x9872), SHC(0xaa5a), SHC(0xa0e1), SHC(0xa0e1), SHC(0xaa5a), - SHC(0x9872), SHC(0xb4c3), SHC(0x9126), SHC(0xc000), SHC(0x8b11), SHC(0xcbf0), SHC(0x8644), SHC(0xd872), - SHC(0x82cc), SHC(0xe563), SHC(0x80b4), SHC(0xf29f), SHC(0x7fff), SHC(0x0000), SHC(0x7ee8), SHC(0xef4b), - SHC(0x7ba3), SHC(0xdedf), SHC(0x7642), SHC(0xcf04), SHC(0x6eda), SHC(0xc000), SHC(0x658d), SHC(0xb214), - SHC(0x5a82), SHC(0xa57e), SHC(0x4dec), SHC(0x9a73), SHC(0x4000), SHC(0x9126), SHC(0x30fc), SHC(0x89be), - SHC(0x2121), SHC(0x845d), SHC(0x10b5), SHC(0x8118), SHC(0x0000), SHC(0x8000), SHC(0xef4b), SHC(0x8118), - SHC(0xdedf), SHC(0x845d), SHC(0xcf04), SHC(0x89be), SHC(0xc000), SHC(0x9126), SHC(0xb214), SHC(0x9a73), - SHC(0xa57e), SHC(0xa57e), SHC(0x9a73), SHC(0xb214), SHC(0x9126), SHC(0xc000), SHC(0x89be), SHC(0xcf04), - SHC(0x845d), SHC(0xdedf), SHC(0x8118), SHC(0xef4b), SHC(0x8000), SHC(0x0000), SHC(0x8118), SHC(0x10b5), - SHC(0x845d), SHC(0x2121), SHC(0x89be), SHC(0x30fc), SHC(0x9126), SHC(0x4000), SHC(0x9a73), SHC(0x4dec), - SHC(0x7fff), SHC(0x0000), SHC(0x7e6d), SHC(0xebfa), SHC(0x79bc), SHC(0xd872), SHC(0x720d), SHC(0xc5e4), - SHC(0x678e), SHC(0xb4c3), SHC(0x5a82), SHC(0xa57e), SHC(0x4b3d), SHC(0x9872), SHC(0x3a1c), SHC(0x8df3), - SHC(0x278e), SHC(0x8644), SHC(0x1406), SHC(0x8193), SHC(0x0000), SHC(0x8000), SHC(0xebfa), SHC(0x8193), - SHC(0xd872), SHC(0x8644), SHC(0xc5e4), SHC(0x8df3), SHC(0xb4c3), SHC(0x9872), SHC(0xa57e), SHC(0xa57e), - SHC(0x9872), SHC(0xb4c3), SHC(0x8df3), SHC(0xc5e4), SHC(0x8644), SHC(0xd872), SHC(0x8193), SHC(0xebfa), - SHC(0x8000), SHC(0x0000), SHC(0x8193), SHC(0x1406), SHC(0x8644), SHC(0x278e), SHC(0x8df3), SHC(0x3a1c), - SHC(0x9872), SHC(0x4b3d), SHC(0xa57e), SHC(0x5a82), SHC(0xb4c3), SHC(0x678e), SHC(0xc5e4), SHC(0x720d), - SHC(0xd872), SHC(0x79bc), SHC(0xebfa), SHC(0x7e6d), SHC(0x7fff), SHC(0x0000), SHC(0x7ddb), SHC(0xe8ad), - SHC(0x7780), SHC(0xd221), SHC(0x6d23), SHC(0xbd1f), SHC(0x5f1f), SHC(0xaa5a), SHC(0x4dec), SHC(0x9a73), - SHC(0x3a1c), SHC(0x8df3), SHC(0x245b), SHC(0x8545), SHC(0x0d61), SHC(0x80b4), SHC(0xf5f5), SHC(0x8065), - SHC(0xdedf), SHC(0x845d), SHC(0xc8e5), SHC(0x8c78), SHC(0xb4c3), SHC(0x9872), SHC(0xa327), SHC(0xa7e4), - SHC(0x94a6), SHC(0xba49), SHC(0x89be), SHC(0xcf04), SHC(0x82cc), SHC(0xe563), SHC(0x800b), SHC(0xfca6), - SHC(0x8193), SHC(0x1406), SHC(0x8758), SHC(0x2aba), SHC(0x9126), SHC(0x4000), SHC(0x9eab), SHC(0x5321), - SHC(0xaf72), SHC(0x637a), SHC(0xc2ec), SHC(0x707d), SHC(0xd872), SHC(0x79bc), SHC(0xef4b), SHC(0x7ee8), - SHC(0x06b3), SHC(0x7fd3), SHC(0x1de2), SHC(0x7c77), SHC(0x3410), SHC(0x74ef), SHC(0x4880), SHC(0x697d), - SHC(0x7fff), SHC(0x0000), SHC(0x7ffd), SHC(0xfe53), SHC(0x7ff5), SHC(0xfca6), SHC(0x7fe7), SHC(0xfafa), - SHC(0x7fd3), SHC(0xf94d), SHC(0x7fba), SHC(0xf7a1), SHC(0x7f9b), SHC(0xf5f5), SHC(0x7f77), SHC(0xf44a), - SHC(0x7f4c), SHC(0xf29f), SHC(0x7f1d), SHC(0xf0f5), SHC(0x7ee8), SHC(0xef4b), SHC(0x7ead), SHC(0xeda2), - SHC(0x7e6d), SHC(0xebfa), SHC(0x7e27), SHC(0xea53), SHC(0x7ddb), SHC(0xe8ad), SHC(0x7d8a), SHC(0xe707), - SHC(0x7d34), SHC(0xe563), SHC(0x7cd8), SHC(0xe3c0), SHC(0x7c77), SHC(0xe21e), SHC(0x7c10), SHC(0xe07e), - SHC(0x7ba3), SHC(0xdedf), SHC(0x7b32), SHC(0xdd41), SHC(0x7abb), SHC(0xdba5), SHC(0x7a3e), SHC(0xda0b), - SHC(0x79bc), SHC(0xd872), SHC(0x7935), SHC(0xd6db), SHC(0x78a8), SHC(0xd546), SHC(0x7817), SHC(0xd3b2), - SHC(0x7780), SHC(0xd221), SHC(0x76e3), SHC(0xd092), SHC(0x7fff), SHC(0x0000), SHC(0x7fe7), SHC(0xfafa), - SHC(0x7f9b), SHC(0xf5f5), SHC(0x7f1d), SHC(0xf0f5), SHC(0x7e6d), SHC(0xebfa), SHC(0x7d8a), SHC(0xe707), - SHC(0x7c77), SHC(0xe21e), SHC(0x7b32), SHC(0xdd41), SHC(0x79bc), SHC(0xd872), SHC(0x7817), SHC(0xd3b2), - SHC(0x7642), SHC(0xcf04), SHC(0x743e), SHC(0xca69), SHC(0x720d), SHC(0xc5e4), SHC(0x6fae), SHC(0xc175), - SHC(0x6d23), SHC(0xbd1f), SHC(0x6a6e), SHC(0xb8e3), SHC(0x678e), SHC(0xb4c3), SHC(0x6485), SHC(0xb0c2), - SHC(0x6155), SHC(0xacdf), SHC(0x5dfe), SHC(0xa91d), SHC(0x5a82), SHC(0xa57e), SHC(0x56e3), SHC(0xa202), - SHC(0x5321), SHC(0x9eab), SHC(0x4f3e), SHC(0x9b7b), SHC(0x4b3d), SHC(0x9872), SHC(0x471d), SHC(0x9592), - SHC(0x42e1), SHC(0x92dd), SHC(0x3e8b), SHC(0x9052), SHC(0x3a1c), SHC(0x8df3), SHC(0x3597), SHC(0x8bc2), - SHC(0x7fff), SHC(0x0000), SHC(0x7fba), SHC(0xf7a1), SHC(0x7ee8), SHC(0xef4b), SHC(0x7d8a), SHC(0xe707), - SHC(0x7ba3), SHC(0xdedf), SHC(0x7935), SHC(0xd6db), SHC(0x7642), SHC(0xcf04), SHC(0x72cd), SHC(0xc763), - SHC(0x6eda), SHC(0xc000), SHC(0x6a6e), SHC(0xb8e3), SHC(0x658d), SHC(0xb214), SHC(0x603c), SHC(0xab9b), - SHC(0x5a82), SHC(0xa57e), SHC(0x5465), SHC(0x9fc4), SHC(0x4dec), SHC(0x9a73), SHC(0x471d), SHC(0x9592), - SHC(0x4000), SHC(0x9126), SHC(0x389d), SHC(0x8d33), SHC(0x30fc), SHC(0x89be), SHC(0x2925), SHC(0x86cb), - SHC(0x2121), SHC(0x845d), SHC(0x18f9), SHC(0x8276), SHC(0x10b5), SHC(0x8118), SHC(0x085f), SHC(0x8046), - SHC(0x0000), SHC(0x8000), SHC(0xf7a1), SHC(0x8046), SHC(0xef4b), SHC(0x8118), SHC(0xe707), SHC(0x8276), - SHC(0xdedf), SHC(0x845d), SHC(0xd6db), SHC(0x86cb), SHC(0x7fff), SHC(0x0000), SHC(0x7f77), SHC(0xf44a), - SHC(0x7ddb), SHC(0xe8ad), SHC(0x7b32), SHC(0xdd41), SHC(0x7780), SHC(0xd221), SHC(0x72cd), SHC(0xc763), - SHC(0x6d23), SHC(0xbd1f), SHC(0x668f), SHC(0xb36a), SHC(0x5f1f), SHC(0xaa5a), SHC(0x56e3), SHC(0xa202), - SHC(0x4dec), SHC(0x9a73), SHC(0x444d), SHC(0x93bf), SHC(0x3a1c), SHC(0x8df3), SHC(0x2f6e), SHC(0x891d), - SHC(0x245b), SHC(0x8545), SHC(0x18f9), SHC(0x8276), SHC(0x0d61), SHC(0x80b4), SHC(0x01ad), SHC(0x8003), - SHC(0xf5f5), SHC(0x8065), SHC(0xea53), SHC(0x81d9), SHC(0xdedf), SHC(0x845d), SHC(0xd3b2), SHC(0x87e9), - SHC(0xc8e5), SHC(0x8c78), SHC(0xbe8e), SHC(0x91ff), SHC(0xb4c3), SHC(0x9872), SHC(0xab9b), SHC(0x9fc4), - SHC(0xa327), SHC(0xa7e4), SHC(0x9b7b), SHC(0xb0c2), SHC(0x94a6), SHC(0xba49), SHC(0x8eb9), SHC(0xc467), - SHC(0x7fff), SHC(0x0000), SHC(0x7f1d), SHC(0xf0f5), SHC(0x7c77), SHC(0xe21e), SHC(0x7817), SHC(0xd3b2), - SHC(0x720d), SHC(0xc5e4), SHC(0x6a6e), SHC(0xb8e3), SHC(0x6155), SHC(0xacdf), SHC(0x56e3), SHC(0xa202), - SHC(0x4b3d), SHC(0x9872), SHC(0x3e8b), SHC(0x9052), SHC(0x30fc), SHC(0x89be), SHC(0x22bf), SHC(0x84ce), - SHC(0x1406), SHC(0x8193), SHC(0x0506), SHC(0x8019), SHC(0xf5f5), SHC(0x8065), SHC(0xe707), SHC(0x8276), - SHC(0xd872), SHC(0x8644), SHC(0xca69), SHC(0x8bc2), SHC(0xbd1f), SHC(0x92dd), SHC(0xb0c2), SHC(0x9b7b), - SHC(0xa57e), SHC(0xa57e), SHC(0x9b7b), SHC(0xb0c2), SHC(0x92dd), SHC(0xbd1f), SHC(0x8bc2), SHC(0xca69), - SHC(0x8644), SHC(0xd872), SHC(0x8276), SHC(0xe707), SHC(0x8065), SHC(0xf5f5), SHC(0x8019), SHC(0x0506), - SHC(0x8193), SHC(0x1406), SHC(0x84ce), SHC(0x22bf), SHC(0x7fff), SHC(0x0000), SHC(0x7ead), SHC(0xeda2), - SHC(0x7abb), SHC(0xdba5), SHC(0x743e), SHC(0xca69), SHC(0x6b5a), SHC(0xba49), SHC(0x603c), SHC(0xab9b), - SHC(0x5321), SHC(0x9eab), SHC(0x444d), SHC(0x93bf), SHC(0x3410), SHC(0x8b11), SHC(0x22bf), SHC(0x84ce), - SHC(0x10b5), SHC(0x8118), SHC(0xfe53), SHC(0x8003), SHC(0xebfa), SHC(0x8193), SHC(0xda0b), SHC(0x85c2), - SHC(0xc8e5), SHC(0x8c78), SHC(0xb8e3), SHC(0x9592), SHC(0xaa5a), SHC(0xa0e1), SHC(0x9d97), SHC(0xae27), - SHC(0x92dd), SHC(0xbd1f), SHC(0x8a65), SHC(0xcd79), SHC(0x845d), SHC(0xdedf), SHC(0x80e3), SHC(0xf0f5), - SHC(0x800b), SHC(0x035a), SHC(0x81d9), SHC(0x15ad), SHC(0x8644), SHC(0x278e), SHC(0x8d33), SHC(0x389d), - SHC(0x9683), SHC(0x4880), SHC(0xa202), SHC(0x56e3), SHC(0xaf72), SHC(0x637a), SHC(0xbe8e), SHC(0x6e01), - SHC(0x7fff), SHC(0x0000), SHC(0x7e27), SHC(0xea53), SHC(0x78a8), SHC(0xd546), SHC(0x6fae), SHC(0xc175), - SHC(0x637a), SHC(0xaf72), SHC(0x5465), SHC(0x9fc4), SHC(0x42e1), SHC(0x92dd), SHC(0x2f6e), SHC(0x891d), - SHC(0x1a9d), SHC(0x82cc), SHC(0x0506), SHC(0x8019), SHC(0xef4b), SHC(0x8118), SHC(0xda0b), SHC(0x85c2), - SHC(0xc5e4), SHC(0x8df3), SHC(0xb36a), SHC(0x9971), SHC(0xa327), SHC(0xa7e4), SHC(0x9592), SHC(0xb8e3), - SHC(0x8b11), SHC(0xcbf0), SHC(0x83f0), SHC(0xe07e), SHC(0x8065), SHC(0xf5f5), SHC(0x8089), SHC(0x0bb6), - SHC(0x845d), SHC(0x2121), SHC(0x8bc2), SHC(0x3597), SHC(0x9683), SHC(0x4880), SHC(0xa450), SHC(0x5951), - SHC(0xb4c3), SHC(0x678e), SHC(0xc763), SHC(0x72cd), SHC(0xdba5), SHC(0x7abb), SHC(0xf0f5), SHC(0x7f1d), - SHC(0x06b3), SHC(0x7fd3), SHC(0x1c40), SHC(0x7cd8), SHC(0x7fff), SHC(0x0000), SHC(0x7d8a), SHC(0xe707), - SHC(0x7642), SHC(0xcf04), SHC(0x6a6e), SHC(0xb8e3), SHC(0x5a82), SHC(0xa57e), SHC(0x471d), SHC(0x9592), - SHC(0x30fc), SHC(0x89be), SHC(0x18f9), SHC(0x8276), SHC(0x0000), SHC(0x8000), SHC(0xe707), SHC(0x8276), - SHC(0xcf04), SHC(0x89be), SHC(0xb8e3), SHC(0x9592), SHC(0xa57e), SHC(0xa57e), SHC(0x9592), SHC(0xb8e3), - SHC(0x89be), SHC(0xcf04), SHC(0x8276), SHC(0xe707), SHC(0x8000), SHC(0x0000), SHC(0x8276), SHC(0x18f9), - SHC(0x89be), SHC(0x30fc), SHC(0x9592), SHC(0x471d), SHC(0xa57e), SHC(0x5a82), SHC(0xb8e3), SHC(0x6a6e), - SHC(0xcf04), SHC(0x7642), SHC(0xe707), SHC(0x7d8a), SHC(0x0000), SHC(0x7fff), SHC(0x18f9), SHC(0x7d8a), - SHC(0x30fc), SHC(0x7642), SHC(0x471d), SHC(0x6a6e), SHC(0x5a82), SHC(0x5a82), SHC(0x6a6e), SHC(0x471d) -}; - -const Word16 RotVector_600[2 * (600 - 30)] = -{ - SHC(0x7fff), SHC(0x0000), SHC(0x7ff9), SHC(0xfd52), - SHC(0x7fe3), SHC(0xfaa4), SHC(0x7fbf), SHC(0xf7f6), SHC(0x7f8d), SHC(0xf54a), SHC(0x7f4c), SHC(0xf29f), - SHC(0x7efe), SHC(0xeff5), SHC(0x7ea0), SHC(0xed4d), SHC(0x7e35), SHC(0xeaa7), SHC(0x7dbc), SHC(0xe804), - SHC(0x7d34), SHC(0xe563), SHC(0x7c9e), SHC(0xe2c5), SHC(0x7bfb), SHC(0xe02b), SHC(0x7b49), SHC(0xdd94), - SHC(0x7a89), SHC(0xdb01), SHC(0x79bc), SHC(0xd872), SHC(0x78e1), SHC(0xd5e8), SHC(0x77f9), SHC(0xd362), - SHC(0x7703), SHC(0xd0e1), SHC(0x7600), SHC(0xce66), SHC(0x74ef), SHC(0xcbf0), SHC(0x73d1), SHC(0xc980), - SHC(0x72a7), SHC(0xc716), SHC(0x716f), SHC(0xc4b3), SHC(0x702b), SHC(0xc256), SHC(0x6eda), SHC(0xc000), - SHC(0x6d7d), SHC(0xbdb1), SHC(0x6c13), SHC(0xbb6a), SHC(0x6a9d), SHC(0xb92a), SHC(0x691b), SHC(0xb6f3), - SHC(0x7fff), SHC(0x0000), SHC(0x7fe3), SHC(0xfaa4), SHC(0x7f8d), SHC(0xf54a), SHC(0x7efe), SHC(0xeff5), - SHC(0x7e35), SHC(0xeaa7), SHC(0x7d34), SHC(0xe563), SHC(0x7bfb), SHC(0xe02b), SHC(0x7a89), SHC(0xdb01), - SHC(0x78e1), SHC(0xd5e8), SHC(0x7703), SHC(0xd0e1), SHC(0x74ef), SHC(0xcbf0), SHC(0x72a7), SHC(0xc716), - SHC(0x702b), SHC(0xc256), SHC(0x6d7d), SHC(0xbdb1), SHC(0x6a9d), SHC(0xb92a), SHC(0x678e), SHC(0xb4c3), - SHC(0x6450), SHC(0xb07e), SHC(0x60e5), SHC(0xac5d), SHC(0x5d4f), SHC(0xa861), SHC(0x598f), SHC(0xa48c), - SHC(0x55a6), SHC(0xa0e1), SHC(0x5197), SHC(0x9d60), SHC(0x4d64), SHC(0x9a0b), SHC(0x490d), SHC(0x96e5), - SHC(0x4496), SHC(0x93ed), SHC(0x4000), SHC(0x9126), SHC(0x3b4d), SHC(0x8e91), SHC(0x3680), SHC(0x8c2f), - SHC(0x319a), SHC(0x8a00), SHC(0x2c9e), SHC(0x8807), SHC(0x7fff), SHC(0x0000), SHC(0x7fbf), SHC(0xf7f6), - SHC(0x7efe), SHC(0xeff5), SHC(0x7dbc), SHC(0xe804), SHC(0x7bfb), SHC(0xe02b), SHC(0x79bc), SHC(0xd872), - SHC(0x7703), SHC(0xd0e1), SHC(0x73d1), SHC(0xc980), SHC(0x702b), SHC(0xc256), SHC(0x6c13), SHC(0xbb6a), - SHC(0x678e), SHC(0xb4c3), SHC(0x62a0), SHC(0xae69), SHC(0x5d4f), SHC(0xa861), SHC(0x579f), SHC(0xa2b1), - SHC(0x5197), SHC(0x9d60), SHC(0x4b3d), SHC(0x9872), SHC(0x4496), SHC(0x93ed), SHC(0x3daa), SHC(0x8fd5), - SHC(0x3680), SHC(0x8c2f), SHC(0x2f1f), SHC(0x88fd), SHC(0x278e), SHC(0x8644), SHC(0x1fd5), SHC(0x8405), - SHC(0x17fc), SHC(0x8244), SHC(0x100b), SHC(0x8102), SHC(0x080a), SHC(0x8041), SHC(0x0000), SHC(0x8000), - SHC(0xf7f6), SHC(0x8041), SHC(0xeff5), SHC(0x8102), SHC(0xe804), SHC(0x8244), SHC(0xe02b), SHC(0x8405), - SHC(0x7fff), SHC(0x0000), SHC(0x7f8d), SHC(0xf54a), SHC(0x7e35), SHC(0xeaa7), SHC(0x7bfb), SHC(0xe02b), - SHC(0x78e1), SHC(0xd5e8), SHC(0x74ef), SHC(0xcbf0), SHC(0x702b), SHC(0xc256), SHC(0x6a9d), SHC(0xb92a), - SHC(0x6450), SHC(0xb07e), SHC(0x5d4f), SHC(0xa861), SHC(0x55a6), SHC(0xa0e1), SHC(0x4d64), SHC(0x9a0b), - SHC(0x4496), SHC(0x93ed), SHC(0x3b4d), SHC(0x8e91), SHC(0x319a), SHC(0x8a00), SHC(0x278e), SHC(0x8644), - SHC(0x1d3b), SHC(0x8362), SHC(0x12b3), SHC(0x8160), SHC(0x080a), SHC(0x8041), SHC(0xfd52), SHC(0x8007), - SHC(0xf29f), SHC(0x80b4), SHC(0xe804), SHC(0x8244), SHC(0xdd94), SHC(0x84b7), SHC(0xd362), SHC(0x8807), - SHC(0xc980), SHC(0x8c2f), SHC(0xc000), SHC(0x9126), SHC(0xb6f3), SHC(0x96e5), SHC(0xae69), SHC(0x9d60), - SHC(0xa671), SHC(0xa48c), SHC(0x9f1b), SHC(0xac5d), SHC(0x7fff), SHC(0x0000), SHC(0x7f4c), SHC(0xf29f), - SHC(0x7d34), SHC(0xe563), SHC(0x79bc), SHC(0xd872), SHC(0x74ef), SHC(0xcbf0), SHC(0x6eda), SHC(0xc000), - SHC(0x678e), SHC(0xb4c3), SHC(0x5f1f), SHC(0xaa5a), SHC(0x55a6), SHC(0xa0e1), SHC(0x4b3d), SHC(0x9872), - SHC(0x4000), SHC(0x9126), SHC(0x3410), SHC(0x8b11), SHC(0x278e), SHC(0x8644), SHC(0x1a9d), SHC(0x82cc), - SHC(0x0d61), SHC(0x80b4), SHC(0x0000), SHC(0x8000), SHC(0xf29f), SHC(0x80b4), SHC(0xe563), SHC(0x82cc), - SHC(0xd872), SHC(0x8644), SHC(0xcbf0), SHC(0x8b11), SHC(0xc000), SHC(0x9126), SHC(0xb4c3), SHC(0x9872), - SHC(0xaa5a), SHC(0xa0e1), SHC(0xa0e1), SHC(0xaa5a), SHC(0x9872), SHC(0xb4c3), SHC(0x9126), SHC(0xc000), - SHC(0x8b11), SHC(0xcbf0), SHC(0x8644), SHC(0xd872), SHC(0x82cc), SHC(0xe563), SHC(0x80b4), SHC(0xf29f), - SHC(0x7fff), SHC(0x0000), SHC(0x7efe), SHC(0xeff5), SHC(0x7bfb), SHC(0xe02b), SHC(0x7703), SHC(0xd0e1), - SHC(0x702b), SHC(0xc256), SHC(0x678e), SHC(0xb4c3), SHC(0x5d4f), SHC(0xa861), SHC(0x5197), SHC(0x9d60), - SHC(0x4496), SHC(0x93ed), SHC(0x3680), SHC(0x8c2f), SHC(0x278e), SHC(0x8644), SHC(0x17fc), SHC(0x8244), - SHC(0x080a), SHC(0x8041), SHC(0xf7f6), SHC(0x8041), SHC(0xe804), SHC(0x8244), SHC(0xd872), SHC(0x8644), - SHC(0xc980), SHC(0x8c2f), SHC(0xbb6a), SHC(0x93ed), SHC(0xae69), SHC(0x9d60), SHC(0xa2b1), SHC(0xa861), - SHC(0x9872), SHC(0xb4c3), SHC(0x8fd5), SHC(0xc256), SHC(0x88fd), SHC(0xd0e1), SHC(0x8405), SHC(0xe02b), - SHC(0x8102), SHC(0xeff5), SHC(0x8000), SHC(0x0000), SHC(0x8102), SHC(0x100b), SHC(0x8405), SHC(0x1fd5), - SHC(0x88fd), SHC(0x2f1f), SHC(0x8fd5), SHC(0x3daa), SHC(0x7fff), SHC(0x0000), SHC(0x7ea0), SHC(0xed4d), - SHC(0x7a89), SHC(0xdb01), SHC(0x73d1), SHC(0xc980), SHC(0x6a9d), SHC(0xb92a), SHC(0x5f1f), SHC(0xaa5a), - SHC(0x5197), SHC(0x9d60), SHC(0x424f), SHC(0x9283), SHC(0x319a), SHC(0x8a00), SHC(0x1fd5), SHC(0x8405), - SHC(0x0d61), SHC(0x80b4), SHC(0xfaa4), SHC(0x801d), SHC(0xe804), SHC(0x8244), SHC(0xd5e8), SHC(0x871f), - SHC(0xc4b3), SHC(0x8e91), SHC(0xb4c3), SHC(0x9872), SHC(0xa671), SHC(0xa48c), SHC(0x9a0b), SHC(0xb29c), - SHC(0x8fd5), SHC(0xc256), SHC(0x8807), SHC(0xd362), SHC(0x82cc), SHC(0xe563), SHC(0x8041), SHC(0xf7f6), - SHC(0x8073), SHC(0x0ab6), SHC(0x8362), SHC(0x1d3b), SHC(0x88fd), SHC(0x2f1f), SHC(0x9126), SHC(0x4000), - SHC(0x9bb0), SHC(0x4f82), SHC(0xa861), SHC(0x5d4f), SHC(0xb6f3), SHC(0x691b), SHC(0xc716), SHC(0x72a7), - SHC(0x7fff), SHC(0x0000), SHC(0x7e35), SHC(0xeaa7), SHC(0x78e1), SHC(0xd5e8), SHC(0x702b), SHC(0xc256), - SHC(0x6450), SHC(0xb07e), SHC(0x55a6), SHC(0xa0e1), SHC(0x4496), SHC(0x93ed), SHC(0x319a), SHC(0x8a00), - SHC(0x1d3b), SHC(0x8362), SHC(0x080a), SHC(0x8041), SHC(0xf29f), SHC(0x80b4), SHC(0xdd94), SHC(0x84b7), - SHC(0xc980), SHC(0x8c2f), SHC(0xb6f3), SHC(0x96e5), SHC(0xa671), SHC(0xa48c), SHC(0x9872), SHC(0xb4c3), - SHC(0x8d59), SHC(0xc716), SHC(0x8577), SHC(0xdb01), SHC(0x8102), SHC(0xeff5), SHC(0x801d), SHC(0x055c), - SHC(0x82cc), SHC(0x1a9d), SHC(0x88fd), SHC(0x2f1f), SHC(0x9283), SHC(0x424f), SHC(0x9f1b), SHC(0x53a3), - SHC(0xae69), SHC(0x62a0), SHC(0xc000), SHC(0x6eda), SHC(0xd362), SHC(0x77f9), SHC(0xe804), SHC(0x7dbc), - SHC(0xfd52), SHC(0x7ff9), SHC(0x12b3), SHC(0x7ea0), SHC(0x7fff), SHC(0x0000), SHC(0x7dbc), SHC(0xe804), - SHC(0x7703), SHC(0xd0e1), SHC(0x6c13), SHC(0xbb6a), SHC(0x5d4f), SHC(0xa861), SHC(0x4b3d), SHC(0x9872), - SHC(0x3680), SHC(0x8c2f), SHC(0x1fd5), SHC(0x8405), SHC(0x080a), SHC(0x8041), SHC(0xeff5), SHC(0x8102), - SHC(0xd872), SHC(0x8644), SHC(0xc256), SHC(0x8fd5), SHC(0xae69), SHC(0x9d60), SHC(0x9d60), SHC(0xae69), - SHC(0x8fd5), SHC(0xc256), SHC(0x8644), SHC(0xd872), SHC(0x8102), SHC(0xeff5), SHC(0x8041), SHC(0x080a), - SHC(0x8405), SHC(0x1fd5), SHC(0x8c2f), SHC(0x3680), SHC(0x9872), SHC(0x4b3d), SHC(0xa861), SHC(0x5d4f), - SHC(0xbb6a), SHC(0x6c13), SHC(0xd0e1), SHC(0x7703), SHC(0xe804), SHC(0x7dbc), SHC(0x0000), SHC(0x7fff), - SHC(0x17fc), SHC(0x7dbc), SHC(0x2f1f), SHC(0x7703), SHC(0x4496), SHC(0x6c13), SHC(0x579f), SHC(0x5d4f), - SHC(0x7fff), SHC(0x0000), SHC(0x7ffe), SHC(0xfea9), SHC(0x7ff9), SHC(0xfd52), SHC(0x7ff0), SHC(0xfbfb), - SHC(0x7fe3), SHC(0xfaa4), SHC(0x7fd3), SHC(0xf94d), SHC(0x7fbf), SHC(0xf7f6), SHC(0x7fa8), SHC(0xf6a0), - SHC(0x7f8d), SHC(0xf54a), SHC(0x7f6f), SHC(0xf3f4), SHC(0x7f4c), SHC(0xf29f), SHC(0x7f27), SHC(0xf14a), - SHC(0x7efe), SHC(0xeff5), SHC(0x7ed1), SHC(0xeea1), SHC(0x7ea0), SHC(0xed4d), SHC(0x7e6d), SHC(0xebfa), - SHC(0x7e35), SHC(0xeaa7), SHC(0x7dfa), SHC(0xe955), SHC(0x7dbc), SHC(0xe804), SHC(0x7d7a), SHC(0xe6b3), - SHC(0x7d34), SHC(0xe563), SHC(0x7ceb), SHC(0xe414), SHC(0x7c9e), SHC(0xe2c5), SHC(0x7c4e), SHC(0xe178), - SHC(0x7bfb), SHC(0xe02b), SHC(0x7ba3), SHC(0xdedf), SHC(0x7b49), SHC(0xdd94), SHC(0x7aeb), SHC(0xdc4a), - SHC(0x7a89), SHC(0xdb01), SHC(0x7a25), SHC(0xd9b9), SHC(0x7fff), SHC(0x0000), SHC(0x7ff0), SHC(0xfbfb), - SHC(0x7fbf), SHC(0xf7f6), SHC(0x7f6f), SHC(0xf3f4), SHC(0x7efe), SHC(0xeff5), SHC(0x7e6d), SHC(0xebfa), - SHC(0x7dbc), SHC(0xe804), SHC(0x7ceb), SHC(0xe414), SHC(0x7bfb), SHC(0xe02b), SHC(0x7aeb), SHC(0xdc4a), - SHC(0x79bc), SHC(0xd872), SHC(0x786f), SHC(0xd4a4), SHC(0x7703), SHC(0xd0e1), SHC(0x7579), SHC(0xcd2a), - SHC(0x73d1), SHC(0xc980), SHC(0x720d), SHC(0xc5e4), SHC(0x702b), SHC(0xc256), SHC(0x6e2d), SHC(0xbed8), - SHC(0x6c13), SHC(0xbb6a), SHC(0x69de), SHC(0xb80e), SHC(0x678e), SHC(0xb4c3), SHC(0x6524), SHC(0xb18c), - SHC(0x62a0), SHC(0xae69), SHC(0x6004), SHC(0xab5a), SHC(0x5d4f), SHC(0xa861), SHC(0x5a82), SHC(0xa57e), - SHC(0x579f), SHC(0xa2b1), SHC(0x54a6), SHC(0x9ffc), SHC(0x5197), SHC(0x9d60), SHC(0x4e74), SHC(0x9adc), - SHC(0x7fff), SHC(0x0000), SHC(0x7fd3), SHC(0xf94d), SHC(0x7f4c), SHC(0xf29f), SHC(0x7e6d), SHC(0xebfa), - SHC(0x7d34), SHC(0xe563), SHC(0x7ba3), SHC(0xdedf), SHC(0x79bc), SHC(0xd872), SHC(0x7780), SHC(0xd221), - SHC(0x74ef), SHC(0xcbf0), SHC(0x720d), SHC(0xc5e4), SHC(0x6eda), SHC(0xc000), SHC(0x6b5a), SHC(0xba49), - SHC(0x678e), SHC(0xb4c3), SHC(0x637a), SHC(0xaf72), SHC(0x5f1f), SHC(0xaa5a), SHC(0x5a82), SHC(0xa57e), - SHC(0x55a6), SHC(0xa0e1), SHC(0x508e), SHC(0x9c86), SHC(0x4b3d), SHC(0x9872), SHC(0x45b7), SHC(0x94a6), - SHC(0x4000), SHC(0x9126), SHC(0x3a1c), SHC(0x8df3), SHC(0x3410), SHC(0x8b11), SHC(0x2ddf), SHC(0x8880), - SHC(0x278e), SHC(0x8644), SHC(0x2121), SHC(0x845d), SHC(0x1a9d), SHC(0x82cc), SHC(0x1406), SHC(0x8193), - SHC(0x0d61), SHC(0x80b4), SHC(0x06b3), SHC(0x802d), SHC(0x7fff), SHC(0x0000), SHC(0x7fa8), SHC(0xf6a0), - SHC(0x7ea0), SHC(0xed4d), SHC(0x7ceb), SHC(0xe414), SHC(0x7a89), SHC(0xdb01), SHC(0x7780), SHC(0xd221), - SHC(0x73d1), SHC(0xc980), SHC(0x6f84), SHC(0xc12a), SHC(0x6a9d), SHC(0xb92a), SHC(0x6524), SHC(0xb18c), - SHC(0x5f1f), SHC(0xaa5a), SHC(0x5898), SHC(0xa39d), SHC(0x5197), SHC(0x9d60), SHC(0x4a26), SHC(0x97aa), - SHC(0x424f), SHC(0x9283), SHC(0x3a1c), SHC(0x8df3), SHC(0x319a), SHC(0x8a00), SHC(0x28d4), SHC(0x86b0), - SHC(0x1fd5), SHC(0x8405), SHC(0x16ab), SHC(0x8206), SHC(0x0d61), SHC(0x80b4), SHC(0x0405), SHC(0x8010), - SHC(0xfaa4), SHC(0x801d), SHC(0xf14a), SHC(0x80d9), SHC(0xe804), SHC(0x8244), SHC(0xdedf), SHC(0x845d), - SHC(0xd5e8), SHC(0x871f), SHC(0xcd2a), SHC(0x8a87), SHC(0xc4b3), SHC(0x8e91), SHC(0xbc8d), SHC(0x9337), - SHC(0x7fff), SHC(0x0000), SHC(0x7f6f), SHC(0xf3f4), SHC(0x7dbc), SHC(0xe804), SHC(0x7aeb), SHC(0xdc4a), - SHC(0x7703), SHC(0xd0e1), SHC(0x720d), SHC(0xc5e4), SHC(0x6c13), SHC(0xbb6a), SHC(0x6524), SHC(0xb18c), - SHC(0x5d4f), SHC(0xa861), SHC(0x54a6), SHC(0x9ffc), SHC(0x4b3d), SHC(0x9872), SHC(0x4128), SHC(0x91d3), - SHC(0x3680), SHC(0x8c2f), SHC(0x2b5c), SHC(0x8791), SHC(0x1fd5), SHC(0x8405), SHC(0x1406), SHC(0x8193), - SHC(0x080a), SHC(0x8041), SHC(0xfbfb), SHC(0x8010), SHC(0xeff5), SHC(0x8102), SHC(0xe414), SHC(0x8315), - SHC(0xd872), SHC(0x8644), SHC(0xcd2a), SHC(0x8a87), SHC(0xc256), SHC(0x8fd5), SHC(0xb80e), SHC(0x9622), - SHC(0xae69), SHC(0x9d60), SHC(0xa57e), SHC(0xa57e), SHC(0x9d60), SHC(0xae69), SHC(0x9622), SHC(0xb80e), - SHC(0x8fd5), SHC(0xc256), SHC(0x8a87), SHC(0xcd2a), SHC(0x7fff), SHC(0x0000), SHC(0x7f27), SHC(0xf14a), - SHC(0x7c9e), SHC(0xe2c5), SHC(0x786f), SHC(0xd4a4), SHC(0x72a7), SHC(0xc716), SHC(0x6b5a), SHC(0xba49), - SHC(0x62a0), SHC(0xae69), SHC(0x5898), SHC(0xa39d), SHC(0x4d64), SHC(0x9a0b), SHC(0x4128), SHC(0x91d3), - SHC(0x3410), SHC(0x8b11), SHC(0x2647), SHC(0x85db), SHC(0x17fc), SHC(0x8244), SHC(0x0960), SHC(0x8058), - SHC(0xfaa4), SHC(0x801d), SHC(0xebfa), SHC(0x8193), SHC(0xdd94), SHC(0x84b7), SHC(0xcfa3), SHC(0x897d), - SHC(0xc256), SHC(0x8fd5), SHC(0xb5da), SHC(0x97aa), SHC(0xaa5a), SHC(0xa0e1), SHC(0x9ffc), SHC(0xab5a), - SHC(0x96e5), SHC(0xb6f3), SHC(0x8f31), SHC(0xc383), SHC(0x88fd), SHC(0xd0e1), SHC(0x845d), SHC(0xdedf), - SHC(0x8160), SHC(0xed4d), SHC(0x8010), SHC(0xfbfb), SHC(0x8073), SHC(0x0ab6), SHC(0x8286), SHC(0x194d), - SHC(0x7fff), SHC(0x0000), SHC(0x7ed1), SHC(0xeea1), SHC(0x7b49), SHC(0xdd94), SHC(0x7579), SHC(0xcd2a), - SHC(0x6d7d), SHC(0xbdb1), SHC(0x637a), SHC(0xaf72), SHC(0x579f), SHC(0xa2b1), SHC(0x4a26), SHC(0x97aa), - SHC(0x3b4d), SHC(0x8e91), SHC(0x2b5c), SHC(0x8791), SHC(0x1a9d), SHC(0x82cc), SHC(0x0960), SHC(0x8058), - SHC(0xf7f6), SHC(0x8041), SHC(0xe6b3), SHC(0x8286), SHC(0xd5e8), SHC(0x871f), SHC(0xc5e4), SHC(0x8df3), - SHC(0xb6f3), SHC(0x96e5), SHC(0xa95c), SHC(0xa1c8), SHC(0x9d60), SHC(0xae69), SHC(0x9337), SHC(0xbc8d), - SHC(0x8b11), SHC(0xcbf0), SHC(0x8515), SHC(0xdc4a), SHC(0x8160), SHC(0xed4d), SHC(0x8002), SHC(0xfea9), - SHC(0x8102), SHC(0x100b), SHC(0x845d), SHC(0x2121), SHC(0x8a00), SHC(0x319a), SHC(0x91d3), SHC(0x4128), - SHC(0x9bb0), SHC(0x4f82), SHC(0xa768), SHC(0x5c63), SHC(0x7fff), SHC(0x0000), SHC(0x7e6d), SHC(0xebfa), - SHC(0x79bc), SHC(0xd872), SHC(0x720d), SHC(0xc5e4), SHC(0x678e), SHC(0xb4c3), SHC(0x5a82), SHC(0xa57e), - SHC(0x4b3d), SHC(0x9872), SHC(0x3a1c), SHC(0x8df3), SHC(0x278e), SHC(0x8644), SHC(0x1406), SHC(0x8193), - SHC(0x0000), SHC(0x8000), SHC(0xebfa), SHC(0x8193), SHC(0xd872), SHC(0x8644), SHC(0xc5e4), SHC(0x8df3), - SHC(0xb4c3), SHC(0x9872), SHC(0xa57e), SHC(0xa57e), SHC(0x9872), SHC(0xb4c3), SHC(0x8df3), SHC(0xc5e4), - SHC(0x8644), SHC(0xd872), SHC(0x8193), SHC(0xebfa), SHC(0x8000), SHC(0x0000), SHC(0x8193), SHC(0x1406), - SHC(0x8644), SHC(0x278e), SHC(0x8df3), SHC(0x3a1c), SHC(0x9872), SHC(0x4b3d), SHC(0xa57e), SHC(0x5a82), - SHC(0xb4c3), SHC(0x678e), SHC(0xc5e4), SHC(0x720d), SHC(0xd872), SHC(0x79bc), SHC(0xebfa), SHC(0x7e6d), - SHC(0x7fff), SHC(0x0000), SHC(0x7dfa), SHC(0xe955), SHC(0x77f9), SHC(0xd362), SHC(0x6e2d), SHC(0xbed8), - SHC(0x60e5), SHC(0xac5d), SHC(0x508e), SHC(0x9c86), SHC(0x3daa), SHC(0x8fd5), SHC(0x28d4), SHC(0x86b0), - SHC(0x12b3), SHC(0x8160), SHC(0xfbfb), SHC(0x8010), SHC(0xe563), SHC(0x82cc), SHC(0xcfa3), SHC(0x897d), - SHC(0xbb6a), SHC(0x93ed), SHC(0xa95c), SHC(0xa1c8), SHC(0x9a0b), SHC(0xb29c), SHC(0x8df3), SHC(0xc5e4), - SHC(0x8577), SHC(0xdb01), SHC(0x80d9), SHC(0xf14a), SHC(0x8041), SHC(0x080a), SHC(0x83b2), SHC(0x1e88), - SHC(0x8b11), SHC(0x3410), SHC(0x9622), SHC(0x47f2), SHC(0xa48c), SHC(0x598f), SHC(0xb5da), SHC(0x6856), - SHC(0xc980), SHC(0x73d1), SHC(0xdedf), SHC(0x7ba3), SHC(0xf54a), SHC(0x7f8d), SHC(0x0c0c), SHC(0x7f6f), - SHC(0x226c), SHC(0x7b49), SHC(0x37b6), SHC(0x733e), SHC(0x7fff), SHC(0x0000), SHC(0x7d7a), SHC(0xe6b3), - SHC(0x7600), SHC(0xce66), SHC(0x69de), SHC(0xb80e), SHC(0x598f), SHC(0xa48c), SHC(0x45b7), SHC(0x94a6), - SHC(0x2f1f), SHC(0x88fd), SHC(0x16ab), SHC(0x8206), SHC(0xfd52), SHC(0x8007), SHC(0xe414), SHC(0x8315), - SHC(0xcbf0), SHC(0x8b11), SHC(0xb5da), SHC(0x97aa), SHC(0xa2b1), SHC(0xa861), SHC(0x9337), SHC(0xbc8d), - SHC(0x8807), SHC(0xd362), SHC(0x8193), SHC(0xebfa), SHC(0x801d), SHC(0x055c), SHC(0x83b2), SHC(0x1e88), - SHC(0x8c2f), SHC(0x3680), SHC(0x993d), SHC(0x4c51), SHC(0xaa5a), SHC(0x5f1f), SHC(0xbed8), SHC(0x6e2d), - SHC(0xd5e8), SHC(0x78e1), SHC(0xeea1), SHC(0x7ed1), SHC(0x080a), SHC(0x7fbf), SHC(0x2121), SHC(0x7ba3), - SHC(0x38ea), SHC(0x72a7), SHC(0x4e74), SHC(0x6524), SHC(0x60e5), SHC(0x53a3), SHC(0x6f84), SHC(0x3ed6) +const Word16 RotVector_480[2 * ( 480 - 30 )] = { + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7ff5 ), SHC( 0xfca6 ), + SHC( 0x7fd3 ), SHC( 0xf94d ), SHC( 0x7f9b ), SHC( 0xf5f5 ), SHC( 0x7f4c ), SHC( 0xf29f ), SHC( 0x7ee8 ), SHC( 0xef4b ), + SHC( 0x7e6d ), SHC( 0xebfa ), SHC( 0x7ddb ), SHC( 0xe8ad ), SHC( 0x7d34 ), SHC( 0xe563 ), SHC( 0x7c77 ), SHC( 0xe21e ), + SHC( 0x7ba3 ), SHC( 0xdedf ), SHC( 0x7abb ), SHC( 0xdba5 ), SHC( 0x79bc ), SHC( 0xd872 ), SHC( 0x78a8 ), SHC( 0xd546 ), + SHC( 0x7780 ), SHC( 0xd221 ), SHC( 0x7642 ), SHC( 0xcf04 ), SHC( 0x74ef ), SHC( 0xcbf0 ), SHC( 0x7388 ), SHC( 0xc8e5 ), + SHC( 0x720d ), SHC( 0xc5e4 ), SHC( 0x707d ), SHC( 0xc2ec ), SHC( 0x6eda ), SHC( 0xc000 ), SHC( 0x6d23 ), SHC( 0xbd1f ), + SHC( 0x6b5a ), SHC( 0xba49 ), SHC( 0x697d ), SHC( 0xb780 ), SHC( 0x678e ), SHC( 0xb4c3 ), SHC( 0x658d ), SHC( 0xb214 ), + SHC( 0x637a ), SHC( 0xaf72 ), SHC( 0x6155 ), SHC( 0xacdf ), SHC( 0x5f1f ), SHC( 0xaa5a ), SHC( 0x5cd9 ), SHC( 0xa7e4 ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7fd3 ), SHC( 0xf94d ), SHC( 0x7f4c ), SHC( 0xf29f ), SHC( 0x7e6d ), SHC( 0xebfa ), + SHC( 0x7d34 ), SHC( 0xe563 ), SHC( 0x7ba3 ), SHC( 0xdedf ), SHC( 0x79bc ), SHC( 0xd872 ), SHC( 0x7780 ), SHC( 0xd221 ), + SHC( 0x74ef ), SHC( 0xcbf0 ), SHC( 0x720d ), SHC( 0xc5e4 ), SHC( 0x6eda ), SHC( 0xc000 ), SHC( 0x6b5a ), SHC( 0xba49 ), + SHC( 0x678e ), SHC( 0xb4c3 ), SHC( 0x637a ), SHC( 0xaf72 ), SHC( 0x5f1f ), SHC( 0xaa5a ), SHC( 0x5a82 ), SHC( 0xa57e ), + SHC( 0x55a6 ), SHC( 0xa0e1 ), SHC( 0x508e ), SHC( 0x9c86 ), SHC( 0x4b3d ), SHC( 0x9872 ), SHC( 0x45b7 ), SHC( 0x94a6 ), + SHC( 0x4000 ), SHC( 0x9126 ), SHC( 0x3a1c ), SHC( 0x8df3 ), SHC( 0x3410 ), SHC( 0x8b11 ), SHC( 0x2ddf ), SHC( 0x8880 ), + SHC( 0x278e ), SHC( 0x8644 ), SHC( 0x2121 ), SHC( 0x845d ), SHC( 0x1a9d ), SHC( 0x82cc ), SHC( 0x1406 ), SHC( 0x8193 ), + SHC( 0x0d61 ), SHC( 0x80b4 ), SHC( 0x06b3 ), SHC( 0x802d ), SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7f9b ), SHC( 0xf5f5 ), + SHC( 0x7e6d ), SHC( 0xebfa ), SHC( 0x7c77 ), SHC( 0xe21e ), SHC( 0x79bc ), SHC( 0xd872 ), SHC( 0x7642 ), SHC( 0xcf04 ), + SHC( 0x720d ), SHC( 0xc5e4 ), SHC( 0x6d23 ), SHC( 0xbd1f ), SHC( 0x678e ), SHC( 0xb4c3 ), SHC( 0x6155 ), SHC( 0xacdf ), + SHC( 0x5a82 ), SHC( 0xa57e ), SHC( 0x5321 ), SHC( 0x9eab ), SHC( 0x4b3d ), SHC( 0x9872 ), SHC( 0x42e1 ), SHC( 0x92dd ), + SHC( 0x3a1c ), SHC( 0x8df3 ), SHC( 0x30fc ), SHC( 0x89be ), SHC( 0x278e ), SHC( 0x8644 ), SHC( 0x1de2 ), SHC( 0x8389 ), + SHC( 0x1406 ), SHC( 0x8193 ), SHC( 0x0a0b ), SHC( 0x8065 ), SHC( 0x0000 ), SHC( 0x8000 ), SHC( 0xf5f5 ), SHC( 0x8065 ), + SHC( 0xebfa ), SHC( 0x8193 ), SHC( 0xe21e ), SHC( 0x8389 ), SHC( 0xd872 ), SHC( 0x8644 ), SHC( 0xcf04 ), SHC( 0x89be ), + SHC( 0xc5e4 ), SHC( 0x8df3 ), SHC( 0xbd1f ), SHC( 0x92dd ), SHC( 0xb4c3 ), SHC( 0x9872 ), SHC( 0xacdf ), SHC( 0x9eab ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7f4c ), SHC( 0xf29f ), SHC( 0x7d34 ), SHC( 0xe563 ), SHC( 0x79bc ), SHC( 0xd872 ), + SHC( 0x74ef ), SHC( 0xcbf0 ), SHC( 0x6eda ), SHC( 0xc000 ), SHC( 0x678e ), SHC( 0xb4c3 ), SHC( 0x5f1f ), SHC( 0xaa5a ), + SHC( 0x55a6 ), SHC( 0xa0e1 ), SHC( 0x4b3d ), SHC( 0x9872 ), SHC( 0x4000 ), SHC( 0x9126 ), SHC( 0x3410 ), SHC( 0x8b11 ), + SHC( 0x278e ), SHC( 0x8644 ), SHC( 0x1a9d ), SHC( 0x82cc ), SHC( 0x0d61 ), SHC( 0x80b4 ), SHC( 0x0000 ), SHC( 0x8000 ), + SHC( 0xf29f ), SHC( 0x80b4 ), SHC( 0xe563 ), SHC( 0x82cc ), SHC( 0xd872 ), SHC( 0x8644 ), SHC( 0xcbf0 ), SHC( 0x8b11 ), + SHC( 0xc000 ), SHC( 0x9126 ), SHC( 0xb4c3 ), SHC( 0x9872 ), SHC( 0xaa5a ), SHC( 0xa0e1 ), SHC( 0xa0e1 ), SHC( 0xaa5a ), + SHC( 0x9872 ), SHC( 0xb4c3 ), SHC( 0x9126 ), SHC( 0xc000 ), SHC( 0x8b11 ), SHC( 0xcbf0 ), SHC( 0x8644 ), SHC( 0xd872 ), + SHC( 0x82cc ), SHC( 0xe563 ), SHC( 0x80b4 ), SHC( 0xf29f ), SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7ee8 ), SHC( 0xef4b ), + SHC( 0x7ba3 ), SHC( 0xdedf ), SHC( 0x7642 ), SHC( 0xcf04 ), SHC( 0x6eda ), SHC( 0xc000 ), SHC( 0x658d ), SHC( 0xb214 ), + SHC( 0x5a82 ), SHC( 0xa57e ), SHC( 0x4dec ), SHC( 0x9a73 ), SHC( 0x4000 ), SHC( 0x9126 ), SHC( 0x30fc ), SHC( 0x89be ), + SHC( 0x2121 ), SHC( 0x845d ), SHC( 0x10b5 ), SHC( 0x8118 ), SHC( 0x0000 ), SHC( 0x8000 ), SHC( 0xef4b ), SHC( 0x8118 ), + SHC( 0xdedf ), SHC( 0x845d ), SHC( 0xcf04 ), SHC( 0x89be ), SHC( 0xc000 ), SHC( 0x9126 ), SHC( 0xb214 ), SHC( 0x9a73 ), + SHC( 0xa57e ), SHC( 0xa57e ), SHC( 0x9a73 ), SHC( 0xb214 ), SHC( 0x9126 ), SHC( 0xc000 ), SHC( 0x89be ), SHC( 0xcf04 ), + SHC( 0x845d ), SHC( 0xdedf ), SHC( 0x8118 ), SHC( 0xef4b ), SHC( 0x8000 ), SHC( 0x0000 ), SHC( 0x8118 ), SHC( 0x10b5 ), + SHC( 0x845d ), SHC( 0x2121 ), SHC( 0x89be ), SHC( 0x30fc ), SHC( 0x9126 ), SHC( 0x4000 ), SHC( 0x9a73 ), SHC( 0x4dec ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7e6d ), SHC( 0xebfa ), SHC( 0x79bc ), SHC( 0xd872 ), SHC( 0x720d ), SHC( 0xc5e4 ), + SHC( 0x678e ), SHC( 0xb4c3 ), SHC( 0x5a82 ), SHC( 0xa57e ), SHC( 0x4b3d ), SHC( 0x9872 ), SHC( 0x3a1c ), SHC( 0x8df3 ), + SHC( 0x278e ), SHC( 0x8644 ), SHC( 0x1406 ), SHC( 0x8193 ), SHC( 0x0000 ), SHC( 0x8000 ), SHC( 0xebfa ), SHC( 0x8193 ), + SHC( 0xd872 ), SHC( 0x8644 ), SHC( 0xc5e4 ), SHC( 0x8df3 ), SHC( 0xb4c3 ), SHC( 0x9872 ), SHC( 0xa57e ), SHC( 0xa57e ), + SHC( 0x9872 ), SHC( 0xb4c3 ), SHC( 0x8df3 ), SHC( 0xc5e4 ), SHC( 0x8644 ), SHC( 0xd872 ), SHC( 0x8193 ), SHC( 0xebfa ), + SHC( 0x8000 ), SHC( 0x0000 ), SHC( 0x8193 ), SHC( 0x1406 ), SHC( 0x8644 ), SHC( 0x278e ), SHC( 0x8df3 ), SHC( 0x3a1c ), + SHC( 0x9872 ), SHC( 0x4b3d ), SHC( 0xa57e ), SHC( 0x5a82 ), SHC( 0xb4c3 ), SHC( 0x678e ), SHC( 0xc5e4 ), SHC( 0x720d ), + SHC( 0xd872 ), SHC( 0x79bc ), SHC( 0xebfa ), SHC( 0x7e6d ), SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7ddb ), SHC( 0xe8ad ), + SHC( 0x7780 ), SHC( 0xd221 ), SHC( 0x6d23 ), SHC( 0xbd1f ), SHC( 0x5f1f ), SHC( 0xaa5a ), SHC( 0x4dec ), SHC( 0x9a73 ), + SHC( 0x3a1c ), SHC( 0x8df3 ), SHC( 0x245b ), SHC( 0x8545 ), SHC( 0x0d61 ), SHC( 0x80b4 ), SHC( 0xf5f5 ), SHC( 0x8065 ), + SHC( 0xdedf ), SHC( 0x845d ), SHC( 0xc8e5 ), SHC( 0x8c78 ), SHC( 0xb4c3 ), SHC( 0x9872 ), SHC( 0xa327 ), SHC( 0xa7e4 ), + SHC( 0x94a6 ), SHC( 0xba49 ), SHC( 0x89be ), SHC( 0xcf04 ), SHC( 0x82cc ), SHC( 0xe563 ), SHC( 0x800b ), SHC( 0xfca6 ), + SHC( 0x8193 ), SHC( 0x1406 ), SHC( 0x8758 ), SHC( 0x2aba ), SHC( 0x9126 ), SHC( 0x4000 ), SHC( 0x9eab ), SHC( 0x5321 ), + SHC( 0xaf72 ), SHC( 0x637a ), SHC( 0xc2ec ), SHC( 0x707d ), SHC( 0xd872 ), SHC( 0x79bc ), SHC( 0xef4b ), SHC( 0x7ee8 ), + SHC( 0x06b3 ), SHC( 0x7fd3 ), SHC( 0x1de2 ), SHC( 0x7c77 ), SHC( 0x3410 ), SHC( 0x74ef ), SHC( 0x4880 ), SHC( 0x697d ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7ffd ), SHC( 0xfe53 ), SHC( 0x7ff5 ), SHC( 0xfca6 ), SHC( 0x7fe7 ), SHC( 0xfafa ), + SHC( 0x7fd3 ), SHC( 0xf94d ), SHC( 0x7fba ), SHC( 0xf7a1 ), SHC( 0x7f9b ), SHC( 0xf5f5 ), SHC( 0x7f77 ), SHC( 0xf44a ), + SHC( 0x7f4c ), SHC( 0xf29f ), SHC( 0x7f1d ), SHC( 0xf0f5 ), SHC( 0x7ee8 ), SHC( 0xef4b ), SHC( 0x7ead ), SHC( 0xeda2 ), + SHC( 0x7e6d ), SHC( 0xebfa ), SHC( 0x7e27 ), SHC( 0xea53 ), SHC( 0x7ddb ), SHC( 0xe8ad ), SHC( 0x7d8a ), SHC( 0xe707 ), + SHC( 0x7d34 ), SHC( 0xe563 ), SHC( 0x7cd8 ), SHC( 0xe3c0 ), SHC( 0x7c77 ), SHC( 0xe21e ), SHC( 0x7c10 ), SHC( 0xe07e ), + SHC( 0x7ba3 ), SHC( 0xdedf ), SHC( 0x7b32 ), SHC( 0xdd41 ), SHC( 0x7abb ), SHC( 0xdba5 ), SHC( 0x7a3e ), SHC( 0xda0b ), + SHC( 0x79bc ), SHC( 0xd872 ), SHC( 0x7935 ), SHC( 0xd6db ), SHC( 0x78a8 ), SHC( 0xd546 ), SHC( 0x7817 ), SHC( 0xd3b2 ), + SHC( 0x7780 ), SHC( 0xd221 ), SHC( 0x76e3 ), SHC( 0xd092 ), SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7fe7 ), SHC( 0xfafa ), + SHC( 0x7f9b ), SHC( 0xf5f5 ), SHC( 0x7f1d ), SHC( 0xf0f5 ), SHC( 0x7e6d ), SHC( 0xebfa ), SHC( 0x7d8a ), SHC( 0xe707 ), + SHC( 0x7c77 ), SHC( 0xe21e ), SHC( 0x7b32 ), SHC( 0xdd41 ), SHC( 0x79bc ), SHC( 0xd872 ), SHC( 0x7817 ), SHC( 0xd3b2 ), + SHC( 0x7642 ), SHC( 0xcf04 ), SHC( 0x743e ), SHC( 0xca69 ), SHC( 0x720d ), SHC( 0xc5e4 ), SHC( 0x6fae ), SHC( 0xc175 ), + SHC( 0x6d23 ), SHC( 0xbd1f ), SHC( 0x6a6e ), SHC( 0xb8e3 ), SHC( 0x678e ), SHC( 0xb4c3 ), SHC( 0x6485 ), SHC( 0xb0c2 ), + SHC( 0x6155 ), SHC( 0xacdf ), SHC( 0x5dfe ), SHC( 0xa91d ), SHC( 0x5a82 ), SHC( 0xa57e ), SHC( 0x56e3 ), SHC( 0xa202 ), + SHC( 0x5321 ), SHC( 0x9eab ), SHC( 0x4f3e ), SHC( 0x9b7b ), SHC( 0x4b3d ), SHC( 0x9872 ), SHC( 0x471d ), SHC( 0x9592 ), + SHC( 0x42e1 ), SHC( 0x92dd ), SHC( 0x3e8b ), SHC( 0x9052 ), SHC( 0x3a1c ), SHC( 0x8df3 ), SHC( 0x3597 ), SHC( 0x8bc2 ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7fba ), SHC( 0xf7a1 ), SHC( 0x7ee8 ), SHC( 0xef4b ), SHC( 0x7d8a ), SHC( 0xe707 ), + SHC( 0x7ba3 ), SHC( 0xdedf ), SHC( 0x7935 ), SHC( 0xd6db ), SHC( 0x7642 ), SHC( 0xcf04 ), SHC( 0x72cd ), SHC( 0xc763 ), + SHC( 0x6eda ), SHC( 0xc000 ), SHC( 0x6a6e ), SHC( 0xb8e3 ), SHC( 0x658d ), SHC( 0xb214 ), SHC( 0x603c ), SHC( 0xab9b ), + SHC( 0x5a82 ), SHC( 0xa57e ), SHC( 0x5465 ), SHC( 0x9fc4 ), SHC( 0x4dec ), SHC( 0x9a73 ), SHC( 0x471d ), SHC( 0x9592 ), + SHC( 0x4000 ), SHC( 0x9126 ), SHC( 0x389d ), SHC( 0x8d33 ), SHC( 0x30fc ), SHC( 0x89be ), SHC( 0x2925 ), SHC( 0x86cb ), + SHC( 0x2121 ), SHC( 0x845d ), SHC( 0x18f9 ), SHC( 0x8276 ), SHC( 0x10b5 ), SHC( 0x8118 ), SHC( 0x085f ), SHC( 0x8046 ), + SHC( 0x0000 ), SHC( 0x8000 ), SHC( 0xf7a1 ), SHC( 0x8046 ), SHC( 0xef4b ), SHC( 0x8118 ), SHC( 0xe707 ), SHC( 0x8276 ), + SHC( 0xdedf ), SHC( 0x845d ), SHC( 0xd6db ), SHC( 0x86cb ), SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7f77 ), SHC( 0xf44a ), + SHC( 0x7ddb ), SHC( 0xe8ad ), SHC( 0x7b32 ), SHC( 0xdd41 ), SHC( 0x7780 ), SHC( 0xd221 ), SHC( 0x72cd ), SHC( 0xc763 ), + SHC( 0x6d23 ), SHC( 0xbd1f ), SHC( 0x668f ), SHC( 0xb36a ), SHC( 0x5f1f ), SHC( 0xaa5a ), SHC( 0x56e3 ), SHC( 0xa202 ), + SHC( 0x4dec ), SHC( 0x9a73 ), SHC( 0x444d ), SHC( 0x93bf ), SHC( 0x3a1c ), SHC( 0x8df3 ), SHC( 0x2f6e ), SHC( 0x891d ), + SHC( 0x245b ), SHC( 0x8545 ), SHC( 0x18f9 ), SHC( 0x8276 ), SHC( 0x0d61 ), SHC( 0x80b4 ), SHC( 0x01ad ), SHC( 0x8003 ), + SHC( 0xf5f5 ), SHC( 0x8065 ), SHC( 0xea53 ), SHC( 0x81d9 ), SHC( 0xdedf ), SHC( 0x845d ), SHC( 0xd3b2 ), SHC( 0x87e9 ), + SHC( 0xc8e5 ), SHC( 0x8c78 ), SHC( 0xbe8e ), SHC( 0x91ff ), SHC( 0xb4c3 ), SHC( 0x9872 ), SHC( 0xab9b ), SHC( 0x9fc4 ), + SHC( 0xa327 ), SHC( 0xa7e4 ), SHC( 0x9b7b ), SHC( 0xb0c2 ), SHC( 0x94a6 ), SHC( 0xba49 ), SHC( 0x8eb9 ), SHC( 0xc467 ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7f1d ), SHC( 0xf0f5 ), SHC( 0x7c77 ), SHC( 0xe21e ), SHC( 0x7817 ), SHC( 0xd3b2 ), + SHC( 0x720d ), SHC( 0xc5e4 ), SHC( 0x6a6e ), SHC( 0xb8e3 ), SHC( 0x6155 ), SHC( 0xacdf ), SHC( 0x56e3 ), SHC( 0xa202 ), + SHC( 0x4b3d ), SHC( 0x9872 ), SHC( 0x3e8b ), SHC( 0x9052 ), SHC( 0x30fc ), SHC( 0x89be ), SHC( 0x22bf ), SHC( 0x84ce ), + SHC( 0x1406 ), SHC( 0x8193 ), SHC( 0x0506 ), SHC( 0x8019 ), SHC( 0xf5f5 ), SHC( 0x8065 ), SHC( 0xe707 ), SHC( 0x8276 ), + SHC( 0xd872 ), SHC( 0x8644 ), SHC( 0xca69 ), SHC( 0x8bc2 ), SHC( 0xbd1f ), SHC( 0x92dd ), SHC( 0xb0c2 ), SHC( 0x9b7b ), + SHC( 0xa57e ), SHC( 0xa57e ), SHC( 0x9b7b ), SHC( 0xb0c2 ), SHC( 0x92dd ), SHC( 0xbd1f ), SHC( 0x8bc2 ), SHC( 0xca69 ), + SHC( 0x8644 ), SHC( 0xd872 ), SHC( 0x8276 ), SHC( 0xe707 ), SHC( 0x8065 ), SHC( 0xf5f5 ), SHC( 0x8019 ), SHC( 0x0506 ), + SHC( 0x8193 ), SHC( 0x1406 ), SHC( 0x84ce ), SHC( 0x22bf ), SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7ead ), SHC( 0xeda2 ), + SHC( 0x7abb ), SHC( 0xdba5 ), SHC( 0x743e ), SHC( 0xca69 ), SHC( 0x6b5a ), SHC( 0xba49 ), SHC( 0x603c ), SHC( 0xab9b ), + SHC( 0x5321 ), SHC( 0x9eab ), SHC( 0x444d ), SHC( 0x93bf ), SHC( 0x3410 ), SHC( 0x8b11 ), SHC( 0x22bf ), SHC( 0x84ce ), + SHC( 0x10b5 ), SHC( 0x8118 ), SHC( 0xfe53 ), SHC( 0x8003 ), SHC( 0xebfa ), SHC( 0x8193 ), SHC( 0xda0b ), SHC( 0x85c2 ), + SHC( 0xc8e5 ), SHC( 0x8c78 ), SHC( 0xb8e3 ), SHC( 0x9592 ), SHC( 0xaa5a ), SHC( 0xa0e1 ), SHC( 0x9d97 ), SHC( 0xae27 ), + SHC( 0x92dd ), SHC( 0xbd1f ), SHC( 0x8a65 ), SHC( 0xcd79 ), SHC( 0x845d ), SHC( 0xdedf ), SHC( 0x80e3 ), SHC( 0xf0f5 ), + SHC( 0x800b ), SHC( 0x035a ), SHC( 0x81d9 ), SHC( 0x15ad ), SHC( 0x8644 ), SHC( 0x278e ), SHC( 0x8d33 ), SHC( 0x389d ), + SHC( 0x9683 ), SHC( 0x4880 ), SHC( 0xa202 ), SHC( 0x56e3 ), SHC( 0xaf72 ), SHC( 0x637a ), SHC( 0xbe8e ), SHC( 0x6e01 ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7e27 ), SHC( 0xea53 ), SHC( 0x78a8 ), SHC( 0xd546 ), SHC( 0x6fae ), SHC( 0xc175 ), + SHC( 0x637a ), SHC( 0xaf72 ), SHC( 0x5465 ), SHC( 0x9fc4 ), SHC( 0x42e1 ), SHC( 0x92dd ), SHC( 0x2f6e ), SHC( 0x891d ), + SHC( 0x1a9d ), SHC( 0x82cc ), SHC( 0x0506 ), SHC( 0x8019 ), SHC( 0xef4b ), SHC( 0x8118 ), SHC( 0xda0b ), SHC( 0x85c2 ), + SHC( 0xc5e4 ), SHC( 0x8df3 ), SHC( 0xb36a ), SHC( 0x9971 ), SHC( 0xa327 ), SHC( 0xa7e4 ), SHC( 0x9592 ), SHC( 0xb8e3 ), + SHC( 0x8b11 ), SHC( 0xcbf0 ), SHC( 0x83f0 ), SHC( 0xe07e ), SHC( 0x8065 ), SHC( 0xf5f5 ), SHC( 0x8089 ), SHC( 0x0bb6 ), + SHC( 0x845d ), SHC( 0x2121 ), SHC( 0x8bc2 ), SHC( 0x3597 ), SHC( 0x9683 ), SHC( 0x4880 ), SHC( 0xa450 ), SHC( 0x5951 ), + SHC( 0xb4c3 ), SHC( 0x678e ), SHC( 0xc763 ), SHC( 0x72cd ), SHC( 0xdba5 ), SHC( 0x7abb ), SHC( 0xf0f5 ), SHC( 0x7f1d ), + SHC( 0x06b3 ), SHC( 0x7fd3 ), SHC( 0x1c40 ), SHC( 0x7cd8 ), SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7d8a ), SHC( 0xe707 ), + SHC( 0x7642 ), SHC( 0xcf04 ), SHC( 0x6a6e ), SHC( 0xb8e3 ), SHC( 0x5a82 ), SHC( 0xa57e ), SHC( 0x471d ), SHC( 0x9592 ), + SHC( 0x30fc ), SHC( 0x89be ), SHC( 0x18f9 ), SHC( 0x8276 ), SHC( 0x0000 ), SHC( 0x8000 ), SHC( 0xe707 ), SHC( 0x8276 ), + SHC( 0xcf04 ), SHC( 0x89be ), SHC( 0xb8e3 ), SHC( 0x9592 ), SHC( 0xa57e ), SHC( 0xa57e ), SHC( 0x9592 ), SHC( 0xb8e3 ), + SHC( 0x89be ), SHC( 0xcf04 ), SHC( 0x8276 ), SHC( 0xe707 ), SHC( 0x8000 ), SHC( 0x0000 ), SHC( 0x8276 ), SHC( 0x18f9 ), + SHC( 0x89be ), SHC( 0x30fc ), SHC( 0x9592 ), SHC( 0x471d ), SHC( 0xa57e ), SHC( 0x5a82 ), SHC( 0xb8e3 ), SHC( 0x6a6e ), + SHC( 0xcf04 ), SHC( 0x7642 ), SHC( 0xe707 ), SHC( 0x7d8a ), SHC( 0x0000 ), SHC( 0x7fff ), SHC( 0x18f9 ), SHC( 0x7d8a ), + SHC( 0x30fc ), SHC( 0x7642 ), SHC( 0x471d ), SHC( 0x6a6e ), SHC( 0x5a82 ), SHC( 0x5a82 ), SHC( 0x6a6e ), SHC( 0x471d ) +}; + +const Word16 RotVector_600[2 * ( 600 - 30 )] = { + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7ff9 ), SHC( 0xfd52 ), + SHC( 0x7fe3 ), SHC( 0xfaa4 ), SHC( 0x7fbf ), SHC( 0xf7f6 ), SHC( 0x7f8d ), SHC( 0xf54a ), SHC( 0x7f4c ), SHC( 0xf29f ), + SHC( 0x7efe ), SHC( 0xeff5 ), SHC( 0x7ea0 ), SHC( 0xed4d ), SHC( 0x7e35 ), SHC( 0xeaa7 ), SHC( 0x7dbc ), SHC( 0xe804 ), + SHC( 0x7d34 ), SHC( 0xe563 ), SHC( 0x7c9e ), SHC( 0xe2c5 ), SHC( 0x7bfb ), SHC( 0xe02b ), SHC( 0x7b49 ), SHC( 0xdd94 ), + SHC( 0x7a89 ), SHC( 0xdb01 ), SHC( 0x79bc ), SHC( 0xd872 ), SHC( 0x78e1 ), SHC( 0xd5e8 ), SHC( 0x77f9 ), SHC( 0xd362 ), + SHC( 0x7703 ), SHC( 0xd0e1 ), SHC( 0x7600 ), SHC( 0xce66 ), SHC( 0x74ef ), SHC( 0xcbf0 ), SHC( 0x73d1 ), SHC( 0xc980 ), + SHC( 0x72a7 ), SHC( 0xc716 ), SHC( 0x716f ), SHC( 0xc4b3 ), SHC( 0x702b ), SHC( 0xc256 ), SHC( 0x6eda ), SHC( 0xc000 ), + SHC( 0x6d7d ), SHC( 0xbdb1 ), SHC( 0x6c13 ), SHC( 0xbb6a ), SHC( 0x6a9d ), SHC( 0xb92a ), SHC( 0x691b ), SHC( 0xb6f3 ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7fe3 ), SHC( 0xfaa4 ), SHC( 0x7f8d ), SHC( 0xf54a ), SHC( 0x7efe ), SHC( 0xeff5 ), + SHC( 0x7e35 ), SHC( 0xeaa7 ), SHC( 0x7d34 ), SHC( 0xe563 ), SHC( 0x7bfb ), SHC( 0xe02b ), SHC( 0x7a89 ), SHC( 0xdb01 ), + SHC( 0x78e1 ), SHC( 0xd5e8 ), SHC( 0x7703 ), SHC( 0xd0e1 ), SHC( 0x74ef ), SHC( 0xcbf0 ), SHC( 0x72a7 ), SHC( 0xc716 ), + SHC( 0x702b ), SHC( 0xc256 ), SHC( 0x6d7d ), SHC( 0xbdb1 ), SHC( 0x6a9d ), SHC( 0xb92a ), SHC( 0x678e ), SHC( 0xb4c3 ), + SHC( 0x6450 ), SHC( 0xb07e ), SHC( 0x60e5 ), SHC( 0xac5d ), SHC( 0x5d4f ), SHC( 0xa861 ), SHC( 0x598f ), SHC( 0xa48c ), + SHC( 0x55a6 ), SHC( 0xa0e1 ), SHC( 0x5197 ), SHC( 0x9d60 ), SHC( 0x4d64 ), SHC( 0x9a0b ), SHC( 0x490d ), SHC( 0x96e5 ), + SHC( 0x4496 ), SHC( 0x93ed ), SHC( 0x4000 ), SHC( 0x9126 ), SHC( 0x3b4d ), SHC( 0x8e91 ), SHC( 0x3680 ), SHC( 0x8c2f ), + SHC( 0x319a ), SHC( 0x8a00 ), SHC( 0x2c9e ), SHC( 0x8807 ), SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7fbf ), SHC( 0xf7f6 ), + SHC( 0x7efe ), SHC( 0xeff5 ), SHC( 0x7dbc ), SHC( 0xe804 ), SHC( 0x7bfb ), SHC( 0xe02b ), SHC( 0x79bc ), SHC( 0xd872 ), + SHC( 0x7703 ), SHC( 0xd0e1 ), SHC( 0x73d1 ), SHC( 0xc980 ), SHC( 0x702b ), SHC( 0xc256 ), SHC( 0x6c13 ), SHC( 0xbb6a ), + SHC( 0x678e ), SHC( 0xb4c3 ), SHC( 0x62a0 ), SHC( 0xae69 ), SHC( 0x5d4f ), SHC( 0xa861 ), SHC( 0x579f ), SHC( 0xa2b1 ), + SHC( 0x5197 ), SHC( 0x9d60 ), SHC( 0x4b3d ), SHC( 0x9872 ), SHC( 0x4496 ), SHC( 0x93ed ), SHC( 0x3daa ), SHC( 0x8fd5 ), + SHC( 0x3680 ), SHC( 0x8c2f ), SHC( 0x2f1f ), SHC( 0x88fd ), SHC( 0x278e ), SHC( 0x8644 ), SHC( 0x1fd5 ), SHC( 0x8405 ), + SHC( 0x17fc ), SHC( 0x8244 ), SHC( 0x100b ), SHC( 0x8102 ), SHC( 0x080a ), SHC( 0x8041 ), SHC( 0x0000 ), SHC( 0x8000 ), + SHC( 0xf7f6 ), SHC( 0x8041 ), SHC( 0xeff5 ), SHC( 0x8102 ), SHC( 0xe804 ), SHC( 0x8244 ), SHC( 0xe02b ), SHC( 0x8405 ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7f8d ), SHC( 0xf54a ), SHC( 0x7e35 ), SHC( 0xeaa7 ), SHC( 0x7bfb ), SHC( 0xe02b ), + SHC( 0x78e1 ), SHC( 0xd5e8 ), SHC( 0x74ef ), SHC( 0xcbf0 ), SHC( 0x702b ), SHC( 0xc256 ), SHC( 0x6a9d ), SHC( 0xb92a ), + SHC( 0x6450 ), SHC( 0xb07e ), SHC( 0x5d4f ), SHC( 0xa861 ), SHC( 0x55a6 ), SHC( 0xa0e1 ), SHC( 0x4d64 ), SHC( 0x9a0b ), + SHC( 0x4496 ), SHC( 0x93ed ), SHC( 0x3b4d ), SHC( 0x8e91 ), SHC( 0x319a ), SHC( 0x8a00 ), SHC( 0x278e ), SHC( 0x8644 ), + SHC( 0x1d3b ), SHC( 0x8362 ), SHC( 0x12b3 ), SHC( 0x8160 ), SHC( 0x080a ), SHC( 0x8041 ), SHC( 0xfd52 ), SHC( 0x8007 ), + SHC( 0xf29f ), SHC( 0x80b4 ), SHC( 0xe804 ), SHC( 0x8244 ), SHC( 0xdd94 ), SHC( 0x84b7 ), SHC( 0xd362 ), SHC( 0x8807 ), + SHC( 0xc980 ), SHC( 0x8c2f ), SHC( 0xc000 ), SHC( 0x9126 ), SHC( 0xb6f3 ), SHC( 0x96e5 ), SHC( 0xae69 ), SHC( 0x9d60 ), + SHC( 0xa671 ), SHC( 0xa48c ), SHC( 0x9f1b ), SHC( 0xac5d ), SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7f4c ), SHC( 0xf29f ), + SHC( 0x7d34 ), SHC( 0xe563 ), SHC( 0x79bc ), SHC( 0xd872 ), SHC( 0x74ef ), SHC( 0xcbf0 ), SHC( 0x6eda ), SHC( 0xc000 ), + SHC( 0x678e ), SHC( 0xb4c3 ), SHC( 0x5f1f ), SHC( 0xaa5a ), SHC( 0x55a6 ), SHC( 0xa0e1 ), SHC( 0x4b3d ), SHC( 0x9872 ), + SHC( 0x4000 ), SHC( 0x9126 ), SHC( 0x3410 ), SHC( 0x8b11 ), SHC( 0x278e ), SHC( 0x8644 ), SHC( 0x1a9d ), SHC( 0x82cc ), + SHC( 0x0d61 ), SHC( 0x80b4 ), SHC( 0x0000 ), SHC( 0x8000 ), SHC( 0xf29f ), SHC( 0x80b4 ), SHC( 0xe563 ), SHC( 0x82cc ), + SHC( 0xd872 ), SHC( 0x8644 ), SHC( 0xcbf0 ), SHC( 0x8b11 ), SHC( 0xc000 ), SHC( 0x9126 ), SHC( 0xb4c3 ), SHC( 0x9872 ), + SHC( 0xaa5a ), SHC( 0xa0e1 ), SHC( 0xa0e1 ), SHC( 0xaa5a ), SHC( 0x9872 ), SHC( 0xb4c3 ), SHC( 0x9126 ), SHC( 0xc000 ), + SHC( 0x8b11 ), SHC( 0xcbf0 ), SHC( 0x8644 ), SHC( 0xd872 ), SHC( 0x82cc ), SHC( 0xe563 ), SHC( 0x80b4 ), SHC( 0xf29f ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7efe ), SHC( 0xeff5 ), SHC( 0x7bfb ), SHC( 0xe02b ), SHC( 0x7703 ), SHC( 0xd0e1 ), + SHC( 0x702b ), SHC( 0xc256 ), SHC( 0x678e ), SHC( 0xb4c3 ), SHC( 0x5d4f ), SHC( 0xa861 ), SHC( 0x5197 ), SHC( 0x9d60 ), + SHC( 0x4496 ), SHC( 0x93ed ), SHC( 0x3680 ), SHC( 0x8c2f ), SHC( 0x278e ), SHC( 0x8644 ), SHC( 0x17fc ), SHC( 0x8244 ), + SHC( 0x080a ), SHC( 0x8041 ), SHC( 0xf7f6 ), SHC( 0x8041 ), SHC( 0xe804 ), SHC( 0x8244 ), SHC( 0xd872 ), SHC( 0x8644 ), + SHC( 0xc980 ), SHC( 0x8c2f ), SHC( 0xbb6a ), SHC( 0x93ed ), SHC( 0xae69 ), SHC( 0x9d60 ), SHC( 0xa2b1 ), SHC( 0xa861 ), + SHC( 0x9872 ), SHC( 0xb4c3 ), SHC( 0x8fd5 ), SHC( 0xc256 ), SHC( 0x88fd ), SHC( 0xd0e1 ), SHC( 0x8405 ), SHC( 0xe02b ), + SHC( 0x8102 ), SHC( 0xeff5 ), SHC( 0x8000 ), SHC( 0x0000 ), SHC( 0x8102 ), SHC( 0x100b ), SHC( 0x8405 ), SHC( 0x1fd5 ), + SHC( 0x88fd ), SHC( 0x2f1f ), SHC( 0x8fd5 ), SHC( 0x3daa ), SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7ea0 ), SHC( 0xed4d ), + SHC( 0x7a89 ), SHC( 0xdb01 ), SHC( 0x73d1 ), SHC( 0xc980 ), SHC( 0x6a9d ), SHC( 0xb92a ), SHC( 0x5f1f ), SHC( 0xaa5a ), + SHC( 0x5197 ), SHC( 0x9d60 ), SHC( 0x424f ), SHC( 0x9283 ), SHC( 0x319a ), SHC( 0x8a00 ), SHC( 0x1fd5 ), SHC( 0x8405 ), + SHC( 0x0d61 ), SHC( 0x80b4 ), SHC( 0xfaa4 ), SHC( 0x801d ), SHC( 0xe804 ), SHC( 0x8244 ), SHC( 0xd5e8 ), SHC( 0x871f ), + SHC( 0xc4b3 ), SHC( 0x8e91 ), SHC( 0xb4c3 ), SHC( 0x9872 ), SHC( 0xa671 ), SHC( 0xa48c ), SHC( 0x9a0b ), SHC( 0xb29c ), + SHC( 0x8fd5 ), SHC( 0xc256 ), SHC( 0x8807 ), SHC( 0xd362 ), SHC( 0x82cc ), SHC( 0xe563 ), SHC( 0x8041 ), SHC( 0xf7f6 ), + SHC( 0x8073 ), SHC( 0x0ab6 ), SHC( 0x8362 ), SHC( 0x1d3b ), SHC( 0x88fd ), SHC( 0x2f1f ), SHC( 0x9126 ), SHC( 0x4000 ), + SHC( 0x9bb0 ), SHC( 0x4f82 ), SHC( 0xa861 ), SHC( 0x5d4f ), SHC( 0xb6f3 ), SHC( 0x691b ), SHC( 0xc716 ), SHC( 0x72a7 ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7e35 ), SHC( 0xeaa7 ), SHC( 0x78e1 ), SHC( 0xd5e8 ), SHC( 0x702b ), SHC( 0xc256 ), + SHC( 0x6450 ), SHC( 0xb07e ), SHC( 0x55a6 ), SHC( 0xa0e1 ), SHC( 0x4496 ), SHC( 0x93ed ), SHC( 0x319a ), SHC( 0x8a00 ), + SHC( 0x1d3b ), SHC( 0x8362 ), SHC( 0x080a ), SHC( 0x8041 ), SHC( 0xf29f ), SHC( 0x80b4 ), SHC( 0xdd94 ), SHC( 0x84b7 ), + SHC( 0xc980 ), SHC( 0x8c2f ), SHC( 0xb6f3 ), SHC( 0x96e5 ), SHC( 0xa671 ), SHC( 0xa48c ), SHC( 0x9872 ), SHC( 0xb4c3 ), + SHC( 0x8d59 ), SHC( 0xc716 ), SHC( 0x8577 ), SHC( 0xdb01 ), SHC( 0x8102 ), SHC( 0xeff5 ), SHC( 0x801d ), SHC( 0x055c ), + SHC( 0x82cc ), SHC( 0x1a9d ), SHC( 0x88fd ), SHC( 0x2f1f ), SHC( 0x9283 ), SHC( 0x424f ), SHC( 0x9f1b ), SHC( 0x53a3 ), + SHC( 0xae69 ), SHC( 0x62a0 ), SHC( 0xc000 ), SHC( 0x6eda ), SHC( 0xd362 ), SHC( 0x77f9 ), SHC( 0xe804 ), SHC( 0x7dbc ), + SHC( 0xfd52 ), SHC( 0x7ff9 ), SHC( 0x12b3 ), SHC( 0x7ea0 ), SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7dbc ), SHC( 0xe804 ), + SHC( 0x7703 ), SHC( 0xd0e1 ), SHC( 0x6c13 ), SHC( 0xbb6a ), SHC( 0x5d4f ), SHC( 0xa861 ), SHC( 0x4b3d ), SHC( 0x9872 ), + SHC( 0x3680 ), SHC( 0x8c2f ), SHC( 0x1fd5 ), SHC( 0x8405 ), SHC( 0x080a ), SHC( 0x8041 ), SHC( 0xeff5 ), SHC( 0x8102 ), + SHC( 0xd872 ), SHC( 0x8644 ), SHC( 0xc256 ), SHC( 0x8fd5 ), SHC( 0xae69 ), SHC( 0x9d60 ), SHC( 0x9d60 ), SHC( 0xae69 ), + SHC( 0x8fd5 ), SHC( 0xc256 ), SHC( 0x8644 ), SHC( 0xd872 ), SHC( 0x8102 ), SHC( 0xeff5 ), SHC( 0x8041 ), SHC( 0x080a ), + SHC( 0x8405 ), SHC( 0x1fd5 ), SHC( 0x8c2f ), SHC( 0x3680 ), SHC( 0x9872 ), SHC( 0x4b3d ), SHC( 0xa861 ), SHC( 0x5d4f ), + SHC( 0xbb6a ), SHC( 0x6c13 ), SHC( 0xd0e1 ), SHC( 0x7703 ), SHC( 0xe804 ), SHC( 0x7dbc ), SHC( 0x0000 ), SHC( 0x7fff ), + SHC( 0x17fc ), SHC( 0x7dbc ), SHC( 0x2f1f ), SHC( 0x7703 ), SHC( 0x4496 ), SHC( 0x6c13 ), SHC( 0x579f ), SHC( 0x5d4f ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7ffe ), SHC( 0xfea9 ), SHC( 0x7ff9 ), SHC( 0xfd52 ), SHC( 0x7ff0 ), SHC( 0xfbfb ), + SHC( 0x7fe3 ), SHC( 0xfaa4 ), SHC( 0x7fd3 ), SHC( 0xf94d ), SHC( 0x7fbf ), SHC( 0xf7f6 ), SHC( 0x7fa8 ), SHC( 0xf6a0 ), + SHC( 0x7f8d ), SHC( 0xf54a ), SHC( 0x7f6f ), SHC( 0xf3f4 ), SHC( 0x7f4c ), SHC( 0xf29f ), SHC( 0x7f27 ), SHC( 0xf14a ), + SHC( 0x7efe ), SHC( 0xeff5 ), SHC( 0x7ed1 ), SHC( 0xeea1 ), SHC( 0x7ea0 ), SHC( 0xed4d ), SHC( 0x7e6d ), SHC( 0xebfa ), + SHC( 0x7e35 ), SHC( 0xeaa7 ), SHC( 0x7dfa ), SHC( 0xe955 ), SHC( 0x7dbc ), SHC( 0xe804 ), SHC( 0x7d7a ), SHC( 0xe6b3 ), + SHC( 0x7d34 ), SHC( 0xe563 ), SHC( 0x7ceb ), SHC( 0xe414 ), SHC( 0x7c9e ), SHC( 0xe2c5 ), SHC( 0x7c4e ), SHC( 0xe178 ), + SHC( 0x7bfb ), SHC( 0xe02b ), SHC( 0x7ba3 ), SHC( 0xdedf ), SHC( 0x7b49 ), SHC( 0xdd94 ), SHC( 0x7aeb ), SHC( 0xdc4a ), + SHC( 0x7a89 ), SHC( 0xdb01 ), SHC( 0x7a25 ), SHC( 0xd9b9 ), SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7ff0 ), SHC( 0xfbfb ), + SHC( 0x7fbf ), SHC( 0xf7f6 ), SHC( 0x7f6f ), SHC( 0xf3f4 ), SHC( 0x7efe ), SHC( 0xeff5 ), SHC( 0x7e6d ), SHC( 0xebfa ), + SHC( 0x7dbc ), SHC( 0xe804 ), SHC( 0x7ceb ), SHC( 0xe414 ), SHC( 0x7bfb ), SHC( 0xe02b ), SHC( 0x7aeb ), SHC( 0xdc4a ), + SHC( 0x79bc ), SHC( 0xd872 ), SHC( 0x786f ), SHC( 0xd4a4 ), SHC( 0x7703 ), SHC( 0xd0e1 ), SHC( 0x7579 ), SHC( 0xcd2a ), + SHC( 0x73d1 ), SHC( 0xc980 ), SHC( 0x720d ), SHC( 0xc5e4 ), SHC( 0x702b ), SHC( 0xc256 ), SHC( 0x6e2d ), SHC( 0xbed8 ), + SHC( 0x6c13 ), SHC( 0xbb6a ), SHC( 0x69de ), SHC( 0xb80e ), SHC( 0x678e ), SHC( 0xb4c3 ), SHC( 0x6524 ), SHC( 0xb18c ), + SHC( 0x62a0 ), SHC( 0xae69 ), SHC( 0x6004 ), SHC( 0xab5a ), SHC( 0x5d4f ), SHC( 0xa861 ), SHC( 0x5a82 ), SHC( 0xa57e ), + SHC( 0x579f ), SHC( 0xa2b1 ), SHC( 0x54a6 ), SHC( 0x9ffc ), SHC( 0x5197 ), SHC( 0x9d60 ), SHC( 0x4e74 ), SHC( 0x9adc ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7fd3 ), SHC( 0xf94d ), SHC( 0x7f4c ), SHC( 0xf29f ), SHC( 0x7e6d ), SHC( 0xebfa ), + SHC( 0x7d34 ), SHC( 0xe563 ), SHC( 0x7ba3 ), SHC( 0xdedf ), SHC( 0x79bc ), SHC( 0xd872 ), SHC( 0x7780 ), SHC( 0xd221 ), + SHC( 0x74ef ), SHC( 0xcbf0 ), SHC( 0x720d ), SHC( 0xc5e4 ), SHC( 0x6eda ), SHC( 0xc000 ), SHC( 0x6b5a ), SHC( 0xba49 ), + SHC( 0x678e ), SHC( 0xb4c3 ), SHC( 0x637a ), SHC( 0xaf72 ), SHC( 0x5f1f ), SHC( 0xaa5a ), SHC( 0x5a82 ), SHC( 0xa57e ), + SHC( 0x55a6 ), SHC( 0xa0e1 ), SHC( 0x508e ), SHC( 0x9c86 ), SHC( 0x4b3d ), SHC( 0x9872 ), SHC( 0x45b7 ), SHC( 0x94a6 ), + SHC( 0x4000 ), SHC( 0x9126 ), SHC( 0x3a1c ), SHC( 0x8df3 ), SHC( 0x3410 ), SHC( 0x8b11 ), SHC( 0x2ddf ), SHC( 0x8880 ), + SHC( 0x278e ), SHC( 0x8644 ), SHC( 0x2121 ), SHC( 0x845d ), SHC( 0x1a9d ), SHC( 0x82cc ), SHC( 0x1406 ), SHC( 0x8193 ), + SHC( 0x0d61 ), SHC( 0x80b4 ), SHC( 0x06b3 ), SHC( 0x802d ), SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7fa8 ), SHC( 0xf6a0 ), + SHC( 0x7ea0 ), SHC( 0xed4d ), SHC( 0x7ceb ), SHC( 0xe414 ), SHC( 0x7a89 ), SHC( 0xdb01 ), SHC( 0x7780 ), SHC( 0xd221 ), + SHC( 0x73d1 ), SHC( 0xc980 ), SHC( 0x6f84 ), SHC( 0xc12a ), SHC( 0x6a9d ), SHC( 0xb92a ), SHC( 0x6524 ), SHC( 0xb18c ), + SHC( 0x5f1f ), SHC( 0xaa5a ), SHC( 0x5898 ), SHC( 0xa39d ), SHC( 0x5197 ), SHC( 0x9d60 ), SHC( 0x4a26 ), SHC( 0x97aa ), + SHC( 0x424f ), SHC( 0x9283 ), SHC( 0x3a1c ), SHC( 0x8df3 ), SHC( 0x319a ), SHC( 0x8a00 ), SHC( 0x28d4 ), SHC( 0x86b0 ), + SHC( 0x1fd5 ), SHC( 0x8405 ), SHC( 0x16ab ), SHC( 0x8206 ), SHC( 0x0d61 ), SHC( 0x80b4 ), SHC( 0x0405 ), SHC( 0x8010 ), + SHC( 0xfaa4 ), SHC( 0x801d ), SHC( 0xf14a ), SHC( 0x80d9 ), SHC( 0xe804 ), SHC( 0x8244 ), SHC( 0xdedf ), SHC( 0x845d ), + SHC( 0xd5e8 ), SHC( 0x871f ), SHC( 0xcd2a ), SHC( 0x8a87 ), SHC( 0xc4b3 ), SHC( 0x8e91 ), SHC( 0xbc8d ), SHC( 0x9337 ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7f6f ), SHC( 0xf3f4 ), SHC( 0x7dbc ), SHC( 0xe804 ), SHC( 0x7aeb ), SHC( 0xdc4a ), + SHC( 0x7703 ), SHC( 0xd0e1 ), SHC( 0x720d ), SHC( 0xc5e4 ), SHC( 0x6c13 ), SHC( 0xbb6a ), SHC( 0x6524 ), SHC( 0xb18c ), + SHC( 0x5d4f ), SHC( 0xa861 ), SHC( 0x54a6 ), SHC( 0x9ffc ), SHC( 0x4b3d ), SHC( 0x9872 ), SHC( 0x4128 ), SHC( 0x91d3 ), + SHC( 0x3680 ), SHC( 0x8c2f ), SHC( 0x2b5c ), SHC( 0x8791 ), SHC( 0x1fd5 ), SHC( 0x8405 ), SHC( 0x1406 ), SHC( 0x8193 ), + SHC( 0x080a ), SHC( 0x8041 ), SHC( 0xfbfb ), SHC( 0x8010 ), SHC( 0xeff5 ), SHC( 0x8102 ), SHC( 0xe414 ), SHC( 0x8315 ), + SHC( 0xd872 ), SHC( 0x8644 ), SHC( 0xcd2a ), SHC( 0x8a87 ), SHC( 0xc256 ), SHC( 0x8fd5 ), SHC( 0xb80e ), SHC( 0x9622 ), + SHC( 0xae69 ), SHC( 0x9d60 ), SHC( 0xa57e ), SHC( 0xa57e ), SHC( 0x9d60 ), SHC( 0xae69 ), SHC( 0x9622 ), SHC( 0xb80e ), + SHC( 0x8fd5 ), SHC( 0xc256 ), SHC( 0x8a87 ), SHC( 0xcd2a ), SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7f27 ), SHC( 0xf14a ), + SHC( 0x7c9e ), SHC( 0xe2c5 ), SHC( 0x786f ), SHC( 0xd4a4 ), SHC( 0x72a7 ), SHC( 0xc716 ), SHC( 0x6b5a ), SHC( 0xba49 ), + SHC( 0x62a0 ), SHC( 0xae69 ), SHC( 0x5898 ), SHC( 0xa39d ), SHC( 0x4d64 ), SHC( 0x9a0b ), SHC( 0x4128 ), SHC( 0x91d3 ), + SHC( 0x3410 ), SHC( 0x8b11 ), SHC( 0x2647 ), SHC( 0x85db ), SHC( 0x17fc ), SHC( 0x8244 ), SHC( 0x0960 ), SHC( 0x8058 ), + SHC( 0xfaa4 ), SHC( 0x801d ), SHC( 0xebfa ), SHC( 0x8193 ), SHC( 0xdd94 ), SHC( 0x84b7 ), SHC( 0xcfa3 ), SHC( 0x897d ), + SHC( 0xc256 ), SHC( 0x8fd5 ), SHC( 0xb5da ), SHC( 0x97aa ), SHC( 0xaa5a ), SHC( 0xa0e1 ), SHC( 0x9ffc ), SHC( 0xab5a ), + SHC( 0x96e5 ), SHC( 0xb6f3 ), SHC( 0x8f31 ), SHC( 0xc383 ), SHC( 0x88fd ), SHC( 0xd0e1 ), SHC( 0x845d ), SHC( 0xdedf ), + SHC( 0x8160 ), SHC( 0xed4d ), SHC( 0x8010 ), SHC( 0xfbfb ), SHC( 0x8073 ), SHC( 0x0ab6 ), SHC( 0x8286 ), SHC( 0x194d ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7ed1 ), SHC( 0xeea1 ), SHC( 0x7b49 ), SHC( 0xdd94 ), SHC( 0x7579 ), SHC( 0xcd2a ), + SHC( 0x6d7d ), SHC( 0xbdb1 ), SHC( 0x637a ), SHC( 0xaf72 ), SHC( 0x579f ), SHC( 0xa2b1 ), SHC( 0x4a26 ), SHC( 0x97aa ), + SHC( 0x3b4d ), SHC( 0x8e91 ), SHC( 0x2b5c ), SHC( 0x8791 ), SHC( 0x1a9d ), SHC( 0x82cc ), SHC( 0x0960 ), SHC( 0x8058 ), + SHC( 0xf7f6 ), SHC( 0x8041 ), SHC( 0xe6b3 ), SHC( 0x8286 ), SHC( 0xd5e8 ), SHC( 0x871f ), SHC( 0xc5e4 ), SHC( 0x8df3 ), + SHC( 0xb6f3 ), SHC( 0x96e5 ), SHC( 0xa95c ), SHC( 0xa1c8 ), SHC( 0x9d60 ), SHC( 0xae69 ), SHC( 0x9337 ), SHC( 0xbc8d ), + SHC( 0x8b11 ), SHC( 0xcbf0 ), SHC( 0x8515 ), SHC( 0xdc4a ), SHC( 0x8160 ), SHC( 0xed4d ), SHC( 0x8002 ), SHC( 0xfea9 ), + SHC( 0x8102 ), SHC( 0x100b ), SHC( 0x845d ), SHC( 0x2121 ), SHC( 0x8a00 ), SHC( 0x319a ), SHC( 0x91d3 ), SHC( 0x4128 ), + SHC( 0x9bb0 ), SHC( 0x4f82 ), SHC( 0xa768 ), SHC( 0x5c63 ), SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7e6d ), SHC( 0xebfa ), + SHC( 0x79bc ), SHC( 0xd872 ), SHC( 0x720d ), SHC( 0xc5e4 ), SHC( 0x678e ), SHC( 0xb4c3 ), SHC( 0x5a82 ), SHC( 0xa57e ), + SHC( 0x4b3d ), SHC( 0x9872 ), SHC( 0x3a1c ), SHC( 0x8df3 ), SHC( 0x278e ), SHC( 0x8644 ), SHC( 0x1406 ), SHC( 0x8193 ), + SHC( 0x0000 ), SHC( 0x8000 ), SHC( 0xebfa ), SHC( 0x8193 ), SHC( 0xd872 ), SHC( 0x8644 ), SHC( 0xc5e4 ), SHC( 0x8df3 ), + SHC( 0xb4c3 ), SHC( 0x9872 ), SHC( 0xa57e ), SHC( 0xa57e ), SHC( 0x9872 ), SHC( 0xb4c3 ), SHC( 0x8df3 ), SHC( 0xc5e4 ), + SHC( 0x8644 ), SHC( 0xd872 ), SHC( 0x8193 ), SHC( 0xebfa ), SHC( 0x8000 ), SHC( 0x0000 ), SHC( 0x8193 ), SHC( 0x1406 ), + SHC( 0x8644 ), SHC( 0x278e ), SHC( 0x8df3 ), SHC( 0x3a1c ), SHC( 0x9872 ), SHC( 0x4b3d ), SHC( 0xa57e ), SHC( 0x5a82 ), + SHC( 0xb4c3 ), SHC( 0x678e ), SHC( 0xc5e4 ), SHC( 0x720d ), SHC( 0xd872 ), SHC( 0x79bc ), SHC( 0xebfa ), SHC( 0x7e6d ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7dfa ), SHC( 0xe955 ), SHC( 0x77f9 ), SHC( 0xd362 ), SHC( 0x6e2d ), SHC( 0xbed8 ), + SHC( 0x60e5 ), SHC( 0xac5d ), SHC( 0x508e ), SHC( 0x9c86 ), SHC( 0x3daa ), SHC( 0x8fd5 ), SHC( 0x28d4 ), SHC( 0x86b0 ), + SHC( 0x12b3 ), SHC( 0x8160 ), SHC( 0xfbfb ), SHC( 0x8010 ), SHC( 0xe563 ), SHC( 0x82cc ), SHC( 0xcfa3 ), SHC( 0x897d ), + SHC( 0xbb6a ), SHC( 0x93ed ), SHC( 0xa95c ), SHC( 0xa1c8 ), SHC( 0x9a0b ), SHC( 0xb29c ), SHC( 0x8df3 ), SHC( 0xc5e4 ), + SHC( 0x8577 ), SHC( 0xdb01 ), SHC( 0x80d9 ), SHC( 0xf14a ), SHC( 0x8041 ), SHC( 0x080a ), SHC( 0x83b2 ), SHC( 0x1e88 ), + SHC( 0x8b11 ), SHC( 0x3410 ), SHC( 0x9622 ), SHC( 0x47f2 ), SHC( 0xa48c ), SHC( 0x598f ), SHC( 0xb5da ), SHC( 0x6856 ), + SHC( 0xc980 ), SHC( 0x73d1 ), SHC( 0xdedf ), SHC( 0x7ba3 ), SHC( 0xf54a ), SHC( 0x7f8d ), SHC( 0x0c0c ), SHC( 0x7f6f ), + SHC( 0x226c ), SHC( 0x7b49 ), SHC( 0x37b6 ), SHC( 0x733e ), SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7d7a ), SHC( 0xe6b3 ), + SHC( 0x7600 ), SHC( 0xce66 ), SHC( 0x69de ), SHC( 0xb80e ), SHC( 0x598f ), SHC( 0xa48c ), SHC( 0x45b7 ), SHC( 0x94a6 ), + SHC( 0x2f1f ), SHC( 0x88fd ), SHC( 0x16ab ), SHC( 0x8206 ), SHC( 0xfd52 ), SHC( 0x8007 ), SHC( 0xe414 ), SHC( 0x8315 ), + SHC( 0xcbf0 ), SHC( 0x8b11 ), SHC( 0xb5da ), SHC( 0x97aa ), SHC( 0xa2b1 ), SHC( 0xa861 ), SHC( 0x9337 ), SHC( 0xbc8d ), + SHC( 0x8807 ), SHC( 0xd362 ), SHC( 0x8193 ), SHC( 0xebfa ), SHC( 0x801d ), SHC( 0x055c ), SHC( 0x83b2 ), SHC( 0x1e88 ), + SHC( 0x8c2f ), SHC( 0x3680 ), SHC( 0x993d ), SHC( 0x4c51 ), SHC( 0xaa5a ), SHC( 0x5f1f ), SHC( 0xbed8 ), SHC( 0x6e2d ), + SHC( 0xd5e8 ), SHC( 0x78e1 ), SHC( 0xeea1 ), SHC( 0x7ed1 ), SHC( 0x080a ), SHC( 0x7fbf ), SHC( 0x2121 ), SHC( 0x7ba3 ), + SHC( 0x38ea ), SHC( 0x72a7 ), SHC( 0x4e74 ), SHC( 0x6524 ), SHC( 0x60e5 ), SHC( 0x53a3 ), SHC( 0x6f84 ), SHC( 0x3ed6 ) }; - /** * \brief Twiddle factors are unscaled */ -const Word16 RotVector_256[2 * (256 - 32)] = -{ - SHC(0x7fff), SHC(0x0000), SHC(0x7ff6), SHC(0xfcdc), SHC(0x7fd9), SHC(0xf9b8), SHC(0x7fa7), SHC(0xf695), - SHC(0x7f62), SHC(0xf374), SHC(0x7f0a), SHC(0xf055), SHC(0x7e9d), SHC(0xed38), SHC(0x7e1e), SHC(0xea1e), - SHC(0x7d8a), SHC(0xe707), SHC(0x7ce4), SHC(0xe3f4), SHC(0x7c2a), SHC(0xe0e6), SHC(0x7b5d), SHC(0xdddc), - SHC(0x7a7d), SHC(0xdad8), SHC(0x798a), SHC(0xd7d9), SHC(0x7885), SHC(0xd4e1), SHC(0x776c), SHC(0xd1ef), - SHC(0x7642), SHC(0xcf04), SHC(0x7505), SHC(0xcc21), SHC(0x73b6), SHC(0xc946), SHC(0x7255), SHC(0xc673), - SHC(0x70e3), SHC(0xc3a9), SHC(0x6f5f), SHC(0xc0e9), SHC(0x6dca), SHC(0xbe32), SHC(0x6c24), SHC(0xbb85), - SHC(0x6a6e), SHC(0xb8e3), SHC(0x68a7), SHC(0xb64c), SHC(0x66d0), SHC(0xb3c0), SHC(0x64e9), SHC(0xb140), - SHC(0x62f2), SHC(0xaecc), SHC(0x60ec), SHC(0xac65), SHC(0x5ed7), SHC(0xaa0a), SHC(0x5cb4), SHC(0xa7bd), - SHC(0x7fff), SHC(0x0000), SHC(0x7fd9), SHC(0xf9b8), SHC(0x7f62), SHC(0xf374), SHC(0x7e9d), SHC(0xed38), - SHC(0x7d8a), SHC(0xe707), SHC(0x7c2a), SHC(0xe0e6), SHC(0x7a7d), SHC(0xdad8), SHC(0x7885), SHC(0xd4e1), - SHC(0x7642), SHC(0xcf04), SHC(0x73b6), SHC(0xc946), SHC(0x70e3), SHC(0xc3a9), SHC(0x6dca), SHC(0xbe32), - SHC(0x6a6e), SHC(0xb8e3), SHC(0x66d0), SHC(0xb3c0), SHC(0x62f2), SHC(0xaecc), SHC(0x5ed7), SHC(0xaa0a), - SHC(0x5a82), SHC(0xa57e), SHC(0x55f6), SHC(0xa129), SHC(0x5134), SHC(0x9d0e), SHC(0x4c40), SHC(0x9930), - SHC(0x471d), SHC(0x9592), SHC(0x41ce), SHC(0x9236), SHC(0x3c57), SHC(0x8f1d), SHC(0x36ba), SHC(0x8c4a), - SHC(0x30fc), SHC(0x89be), SHC(0x2b1f), SHC(0x877b), SHC(0x2528), SHC(0x8583), SHC(0x1f1a), SHC(0x83d6), - SHC(0x18f9), SHC(0x8276), SHC(0x12c8), SHC(0x8163), SHC(0x0c8c), SHC(0x809e), SHC(0x0648), SHC(0x8027), - SHC(0x7fff), SHC(0x0000), SHC(0x7fa7), SHC(0xf695), SHC(0x7e9d), SHC(0xed38), SHC(0x7ce4), SHC(0xe3f4), - SHC(0x7a7d), SHC(0xdad8), SHC(0x776c), SHC(0xd1ef), SHC(0x73b6), SHC(0xc946), SHC(0x6f5f), SHC(0xc0e9), - SHC(0x6a6e), SHC(0xb8e3), SHC(0x64e9), SHC(0xb140), SHC(0x5ed7), SHC(0xaa0a), SHC(0x5843), SHC(0xa34c), - SHC(0x5134), SHC(0x9d0e), SHC(0x49b4), SHC(0x9759), SHC(0x41ce), SHC(0x9236), SHC(0x398d), SHC(0x8dab), - SHC(0x30fc), SHC(0x89be), SHC(0x2827), SHC(0x8676), SHC(0x1f1a), SHC(0x83d6), SHC(0x15e2), SHC(0x81e2), - SHC(0x0c8c), SHC(0x809e), SHC(0x0324), SHC(0x800a), SHC(0xf9b8), SHC(0x8027), SHC(0xf055), SHC(0x80f6), - SHC(0xe707), SHC(0x8276), SHC(0xdddc), SHC(0x84a3), SHC(0xd4e1), SHC(0x877b), SHC(0xcc21), SHC(0x8afb), - SHC(0xc3a9), SHC(0x8f1d), SHC(0xbb85), SHC(0x93dc), SHC(0xb3c0), SHC(0x9930), SHC(0xac65), SHC(0x9f14), - SHC(0x7fff), SHC(0x0000), SHC(0x7f62), SHC(0xf374), SHC(0x7d8a), SHC(0xe707), SHC(0x7a7d), SHC(0xdad8), - SHC(0x7642), SHC(0xcf04), SHC(0x70e3), SHC(0xc3a9), SHC(0x6a6e), SHC(0xb8e3), SHC(0x62f2), SHC(0xaecc), - SHC(0x5a82), SHC(0xa57e), SHC(0x5134), SHC(0x9d0e), SHC(0x471d), SHC(0x9592), SHC(0x3c57), SHC(0x8f1d), - SHC(0x30fc), SHC(0x89be), SHC(0x2528), SHC(0x8583), SHC(0x18f9), SHC(0x8276), SHC(0x0c8c), SHC(0x809e), - SHC(0x0000), SHC(0x8000), SHC(0xf374), SHC(0x809e), SHC(0xe707), SHC(0x8276), SHC(0xdad8), SHC(0x8583), - SHC(0xcf04), SHC(0x89be), SHC(0xc3a9), SHC(0x8f1d), SHC(0xb8e3), SHC(0x9592), SHC(0xaecc), SHC(0x9d0e), - SHC(0xa57e), SHC(0xa57e), SHC(0x9d0e), SHC(0xaecc), SHC(0x9592), SHC(0xb8e3), SHC(0x8f1d), SHC(0xc3a9), - SHC(0x89be), SHC(0xcf04), SHC(0x8583), SHC(0xdad8), SHC(0x8276), SHC(0xe707), SHC(0x809e), SHC(0xf374), - SHC(0x7fff), SHC(0x0000), SHC(0x7f0a), SHC(0xf055), SHC(0x7c2a), SHC(0xe0e6), SHC(0x776c), SHC(0xd1ef), - SHC(0x70e3), SHC(0xc3a9), SHC(0x68a7), SHC(0xb64c), SHC(0x5ed7), SHC(0xaa0a), SHC(0x539b), SHC(0x9f14), - SHC(0x471d), SHC(0x9592), SHC(0x398d), SHC(0x8dab), SHC(0x2b1f), SHC(0x877b), SHC(0x1c0c), SHC(0x831c), - SHC(0x0c8c), SHC(0x809e), SHC(0xfcdc), SHC(0x800a), SHC(0xed38), SHC(0x8163), SHC(0xdddc), SHC(0x84a3), - SHC(0xcf04), SHC(0x89be), SHC(0xc0e9), SHC(0x90a1), SHC(0xb3c0), SHC(0x9930), SHC(0xa7bd), SHC(0xa34c), - SHC(0x9d0e), SHC(0xaecc), SHC(0x93dc), SHC(0xbb85), SHC(0x8c4a), SHC(0xc946), SHC(0x8676), SHC(0xd7d9), - SHC(0x8276), SHC(0xe707), SHC(0x8059), SHC(0xf695), SHC(0x8027), SHC(0x0648), SHC(0x81e2), SHC(0x15e2), - SHC(0x8583), SHC(0x2528), SHC(0x8afb), SHC(0x33df), SHC(0x9236), SHC(0x41ce), SHC(0x9b17), SHC(0x4ec0), - SHC(0x7fff), SHC(0x0000), SHC(0x7e9d), SHC(0xed38), SHC(0x7a7d), SHC(0xdad8), SHC(0x73b6), SHC(0xc946), - SHC(0x6a6e), SHC(0xb8e3), SHC(0x5ed7), SHC(0xaa0a), SHC(0x5134), SHC(0x9d0e), SHC(0x41ce), SHC(0x9236), - SHC(0x30fc), SHC(0x89be), SHC(0x1f1a), SHC(0x83d6), SHC(0x0c8c), SHC(0x809e), SHC(0xf9b8), SHC(0x8027), - SHC(0xe707), SHC(0x8276), SHC(0xd4e1), SHC(0x877b), SHC(0xc3a9), SHC(0x8f1d), SHC(0xb3c0), SHC(0x9930), - SHC(0xa57e), SHC(0xa57e), SHC(0x9930), SHC(0xb3c0), SHC(0x8f1d), SHC(0xc3a9), SHC(0x877b), SHC(0xd4e1), - SHC(0x8276), SHC(0xe707), SHC(0x8027), SHC(0xf9b8), SHC(0x809e), SHC(0x0c8c), SHC(0x83d6), SHC(0x1f1a), - SHC(0x89be), SHC(0x30fc), SHC(0x9236), SHC(0x41ce), SHC(0x9d0e), SHC(0x5134), SHC(0xaa0a), SHC(0x5ed7), - SHC(0xb8e3), SHC(0x6a6e), SHC(0xc946), SHC(0x73b6), SHC(0xdad8), SHC(0x7a7d), SHC(0xed38), SHC(0x7e9d), - SHC(0x7fff), SHC(0x0000), SHC(0x7e1e), SHC(0xea1e), SHC(0x7885), SHC(0xd4e1), SHC(0x6f5f), SHC(0xc0e9), - SHC(0x62f2), SHC(0xaecc), SHC(0x539b), SHC(0x9f14), SHC(0x41ce), SHC(0x9236), SHC(0x2e11), SHC(0x8894), - SHC(0x18f9), SHC(0x8276), SHC(0x0324), SHC(0x800a), SHC(0xed38), SHC(0x8163), SHC(0xd7d9), SHC(0x8676), - SHC(0xc3a9), SHC(0x8f1d), SHC(0xb140), SHC(0x9b17), SHC(0xa129), SHC(0xaa0a), SHC(0x93dc), SHC(0xbb85), - SHC(0x89be), SHC(0xcf04), SHC(0x831c), SHC(0xe3f4), SHC(0x8027), SHC(0xf9b8), SHC(0x80f6), SHC(0x0fab), - SHC(0x8583), SHC(0x2528), SHC(0x8dab), SHC(0x398d), SHC(0x9930), SHC(0x4c40), SHC(0xa7bd), SHC(0x5cb4), - SHC(0xb8e3), SHC(0x6a6e), SHC(0xcc21), SHC(0x7505), SHC(0xe0e6), SHC(0x7c2a), SHC(0xf695), SHC(0x7fa7), - SHC(0x0c8c), SHC(0x7f62), SHC(0x2224), SHC(0x7b5d), SHC(0x36ba), SHC(0x73b6), SHC(0x49b4), SHC(0x68a7) +const Word16 RotVector_256[2 * ( 256 - 32 )] = { + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7ff6 ), SHC( 0xfcdc ), SHC( 0x7fd9 ), SHC( 0xf9b8 ), SHC( 0x7fa7 ), SHC( 0xf695 ), + SHC( 0x7f62 ), SHC( 0xf374 ), SHC( 0x7f0a ), SHC( 0xf055 ), SHC( 0x7e9d ), SHC( 0xed38 ), SHC( 0x7e1e ), SHC( 0xea1e ), + SHC( 0x7d8a ), SHC( 0xe707 ), SHC( 0x7ce4 ), SHC( 0xe3f4 ), SHC( 0x7c2a ), SHC( 0xe0e6 ), SHC( 0x7b5d ), SHC( 0xdddc ), + SHC( 0x7a7d ), SHC( 0xdad8 ), SHC( 0x798a ), SHC( 0xd7d9 ), SHC( 0x7885 ), SHC( 0xd4e1 ), SHC( 0x776c ), SHC( 0xd1ef ), + SHC( 0x7642 ), SHC( 0xcf04 ), SHC( 0x7505 ), SHC( 0xcc21 ), SHC( 0x73b6 ), SHC( 0xc946 ), SHC( 0x7255 ), SHC( 0xc673 ), + SHC( 0x70e3 ), SHC( 0xc3a9 ), SHC( 0x6f5f ), SHC( 0xc0e9 ), SHC( 0x6dca ), SHC( 0xbe32 ), SHC( 0x6c24 ), SHC( 0xbb85 ), + SHC( 0x6a6e ), SHC( 0xb8e3 ), SHC( 0x68a7 ), SHC( 0xb64c ), SHC( 0x66d0 ), SHC( 0xb3c0 ), SHC( 0x64e9 ), SHC( 0xb140 ), + SHC( 0x62f2 ), SHC( 0xaecc ), SHC( 0x60ec ), SHC( 0xac65 ), SHC( 0x5ed7 ), SHC( 0xaa0a ), SHC( 0x5cb4 ), SHC( 0xa7bd ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7fd9 ), SHC( 0xf9b8 ), SHC( 0x7f62 ), SHC( 0xf374 ), SHC( 0x7e9d ), SHC( 0xed38 ), + SHC( 0x7d8a ), SHC( 0xe707 ), SHC( 0x7c2a ), SHC( 0xe0e6 ), SHC( 0x7a7d ), SHC( 0xdad8 ), SHC( 0x7885 ), SHC( 0xd4e1 ), + SHC( 0x7642 ), SHC( 0xcf04 ), SHC( 0x73b6 ), SHC( 0xc946 ), SHC( 0x70e3 ), SHC( 0xc3a9 ), SHC( 0x6dca ), SHC( 0xbe32 ), + SHC( 0x6a6e ), SHC( 0xb8e3 ), SHC( 0x66d0 ), SHC( 0xb3c0 ), SHC( 0x62f2 ), SHC( 0xaecc ), SHC( 0x5ed7 ), SHC( 0xaa0a ), + SHC( 0x5a82 ), SHC( 0xa57e ), SHC( 0x55f6 ), SHC( 0xa129 ), SHC( 0x5134 ), SHC( 0x9d0e ), SHC( 0x4c40 ), SHC( 0x9930 ), + SHC( 0x471d ), SHC( 0x9592 ), SHC( 0x41ce ), SHC( 0x9236 ), SHC( 0x3c57 ), SHC( 0x8f1d ), SHC( 0x36ba ), SHC( 0x8c4a ), + SHC( 0x30fc ), SHC( 0x89be ), SHC( 0x2b1f ), SHC( 0x877b ), SHC( 0x2528 ), SHC( 0x8583 ), SHC( 0x1f1a ), SHC( 0x83d6 ), + SHC( 0x18f9 ), SHC( 0x8276 ), SHC( 0x12c8 ), SHC( 0x8163 ), SHC( 0x0c8c ), SHC( 0x809e ), SHC( 0x0648 ), SHC( 0x8027 ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7fa7 ), SHC( 0xf695 ), SHC( 0x7e9d ), SHC( 0xed38 ), SHC( 0x7ce4 ), SHC( 0xe3f4 ), + SHC( 0x7a7d ), SHC( 0xdad8 ), SHC( 0x776c ), SHC( 0xd1ef ), SHC( 0x73b6 ), SHC( 0xc946 ), SHC( 0x6f5f ), SHC( 0xc0e9 ), + SHC( 0x6a6e ), SHC( 0xb8e3 ), SHC( 0x64e9 ), SHC( 0xb140 ), SHC( 0x5ed7 ), SHC( 0xaa0a ), SHC( 0x5843 ), SHC( 0xa34c ), + SHC( 0x5134 ), SHC( 0x9d0e ), SHC( 0x49b4 ), SHC( 0x9759 ), SHC( 0x41ce ), SHC( 0x9236 ), SHC( 0x398d ), SHC( 0x8dab ), + SHC( 0x30fc ), SHC( 0x89be ), SHC( 0x2827 ), SHC( 0x8676 ), SHC( 0x1f1a ), SHC( 0x83d6 ), SHC( 0x15e2 ), SHC( 0x81e2 ), + SHC( 0x0c8c ), SHC( 0x809e ), SHC( 0x0324 ), SHC( 0x800a ), SHC( 0xf9b8 ), SHC( 0x8027 ), SHC( 0xf055 ), SHC( 0x80f6 ), + SHC( 0xe707 ), SHC( 0x8276 ), SHC( 0xdddc ), SHC( 0x84a3 ), SHC( 0xd4e1 ), SHC( 0x877b ), SHC( 0xcc21 ), SHC( 0x8afb ), + SHC( 0xc3a9 ), SHC( 0x8f1d ), SHC( 0xbb85 ), SHC( 0x93dc ), SHC( 0xb3c0 ), SHC( 0x9930 ), SHC( 0xac65 ), SHC( 0x9f14 ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7f62 ), SHC( 0xf374 ), SHC( 0x7d8a ), SHC( 0xe707 ), SHC( 0x7a7d ), SHC( 0xdad8 ), + SHC( 0x7642 ), SHC( 0xcf04 ), SHC( 0x70e3 ), SHC( 0xc3a9 ), SHC( 0x6a6e ), SHC( 0xb8e3 ), SHC( 0x62f2 ), SHC( 0xaecc ), + SHC( 0x5a82 ), SHC( 0xa57e ), SHC( 0x5134 ), SHC( 0x9d0e ), SHC( 0x471d ), SHC( 0x9592 ), SHC( 0x3c57 ), SHC( 0x8f1d ), + SHC( 0x30fc ), SHC( 0x89be ), SHC( 0x2528 ), SHC( 0x8583 ), SHC( 0x18f9 ), SHC( 0x8276 ), SHC( 0x0c8c ), SHC( 0x809e ), + SHC( 0x0000 ), SHC( 0x8000 ), SHC( 0xf374 ), SHC( 0x809e ), SHC( 0xe707 ), SHC( 0x8276 ), SHC( 0xdad8 ), SHC( 0x8583 ), + SHC( 0xcf04 ), SHC( 0x89be ), SHC( 0xc3a9 ), SHC( 0x8f1d ), SHC( 0xb8e3 ), SHC( 0x9592 ), SHC( 0xaecc ), SHC( 0x9d0e ), + SHC( 0xa57e ), SHC( 0xa57e ), SHC( 0x9d0e ), SHC( 0xaecc ), SHC( 0x9592 ), SHC( 0xb8e3 ), SHC( 0x8f1d ), SHC( 0xc3a9 ), + SHC( 0x89be ), SHC( 0xcf04 ), SHC( 0x8583 ), SHC( 0xdad8 ), SHC( 0x8276 ), SHC( 0xe707 ), SHC( 0x809e ), SHC( 0xf374 ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7f0a ), SHC( 0xf055 ), SHC( 0x7c2a ), SHC( 0xe0e6 ), SHC( 0x776c ), SHC( 0xd1ef ), + SHC( 0x70e3 ), SHC( 0xc3a9 ), SHC( 0x68a7 ), SHC( 0xb64c ), SHC( 0x5ed7 ), SHC( 0xaa0a ), SHC( 0x539b ), SHC( 0x9f14 ), + SHC( 0x471d ), SHC( 0x9592 ), SHC( 0x398d ), SHC( 0x8dab ), SHC( 0x2b1f ), SHC( 0x877b ), SHC( 0x1c0c ), SHC( 0x831c ), + SHC( 0x0c8c ), SHC( 0x809e ), SHC( 0xfcdc ), SHC( 0x800a ), SHC( 0xed38 ), SHC( 0x8163 ), SHC( 0xdddc ), SHC( 0x84a3 ), + SHC( 0xcf04 ), SHC( 0x89be ), SHC( 0xc0e9 ), SHC( 0x90a1 ), SHC( 0xb3c0 ), SHC( 0x9930 ), SHC( 0xa7bd ), SHC( 0xa34c ), + SHC( 0x9d0e ), SHC( 0xaecc ), SHC( 0x93dc ), SHC( 0xbb85 ), SHC( 0x8c4a ), SHC( 0xc946 ), SHC( 0x8676 ), SHC( 0xd7d9 ), + SHC( 0x8276 ), SHC( 0xe707 ), SHC( 0x8059 ), SHC( 0xf695 ), SHC( 0x8027 ), SHC( 0x0648 ), SHC( 0x81e2 ), SHC( 0x15e2 ), + SHC( 0x8583 ), SHC( 0x2528 ), SHC( 0x8afb ), SHC( 0x33df ), SHC( 0x9236 ), SHC( 0x41ce ), SHC( 0x9b17 ), SHC( 0x4ec0 ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7e9d ), SHC( 0xed38 ), SHC( 0x7a7d ), SHC( 0xdad8 ), SHC( 0x73b6 ), SHC( 0xc946 ), + SHC( 0x6a6e ), SHC( 0xb8e3 ), SHC( 0x5ed7 ), SHC( 0xaa0a ), SHC( 0x5134 ), SHC( 0x9d0e ), SHC( 0x41ce ), SHC( 0x9236 ), + SHC( 0x30fc ), SHC( 0x89be ), SHC( 0x1f1a ), SHC( 0x83d6 ), SHC( 0x0c8c ), SHC( 0x809e ), SHC( 0xf9b8 ), SHC( 0x8027 ), + SHC( 0xe707 ), SHC( 0x8276 ), SHC( 0xd4e1 ), SHC( 0x877b ), SHC( 0xc3a9 ), SHC( 0x8f1d ), SHC( 0xb3c0 ), SHC( 0x9930 ), + SHC( 0xa57e ), SHC( 0xa57e ), SHC( 0x9930 ), SHC( 0xb3c0 ), SHC( 0x8f1d ), SHC( 0xc3a9 ), SHC( 0x877b ), SHC( 0xd4e1 ), + SHC( 0x8276 ), SHC( 0xe707 ), SHC( 0x8027 ), SHC( 0xf9b8 ), SHC( 0x809e ), SHC( 0x0c8c ), SHC( 0x83d6 ), SHC( 0x1f1a ), + SHC( 0x89be ), SHC( 0x30fc ), SHC( 0x9236 ), SHC( 0x41ce ), SHC( 0x9d0e ), SHC( 0x5134 ), SHC( 0xaa0a ), SHC( 0x5ed7 ), + SHC( 0xb8e3 ), SHC( 0x6a6e ), SHC( 0xc946 ), SHC( 0x73b6 ), SHC( 0xdad8 ), SHC( 0x7a7d ), SHC( 0xed38 ), SHC( 0x7e9d ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7e1e ), SHC( 0xea1e ), SHC( 0x7885 ), SHC( 0xd4e1 ), SHC( 0x6f5f ), SHC( 0xc0e9 ), + SHC( 0x62f2 ), SHC( 0xaecc ), SHC( 0x539b ), SHC( 0x9f14 ), SHC( 0x41ce ), SHC( 0x9236 ), SHC( 0x2e11 ), SHC( 0x8894 ), + SHC( 0x18f9 ), SHC( 0x8276 ), SHC( 0x0324 ), SHC( 0x800a ), SHC( 0xed38 ), SHC( 0x8163 ), SHC( 0xd7d9 ), SHC( 0x8676 ), + SHC( 0xc3a9 ), SHC( 0x8f1d ), SHC( 0xb140 ), SHC( 0x9b17 ), SHC( 0xa129 ), SHC( 0xaa0a ), SHC( 0x93dc ), SHC( 0xbb85 ), + SHC( 0x89be ), SHC( 0xcf04 ), SHC( 0x831c ), SHC( 0xe3f4 ), SHC( 0x8027 ), SHC( 0xf9b8 ), SHC( 0x80f6 ), SHC( 0x0fab ), + SHC( 0x8583 ), SHC( 0x2528 ), SHC( 0x8dab ), SHC( 0x398d ), SHC( 0x9930 ), SHC( 0x4c40 ), SHC( 0xa7bd ), SHC( 0x5cb4 ), + SHC( 0xb8e3 ), SHC( 0x6a6e ), SHC( 0xcc21 ), SHC( 0x7505 ), SHC( 0xe0e6 ), SHC( 0x7c2a ), SHC( 0xf695 ), SHC( 0x7fa7 ), + SHC( 0x0c8c ), SHC( 0x7f62 ), SHC( 0x2224 ), SHC( 0x7b5d ), SHC( 0x36ba ), SHC( 0x73b6 ), SHC( 0x49b4 ), SHC( 0x68a7 ) }; /** * \brief Twiddle factors are unscaled */ -const Word16 RotVector_320[2 * (320 - 20)] = -{ - SHC(0x7fff), SHC(0x0000), SHC(0x7fe7), SHC(0xfafa), SHC(0x7f9b), SHC(0xf5f5), SHC(0x7f1d), SHC(0xf0f5), - SHC(0x7e6d), SHC(0xebfa), SHC(0x7d8a), SHC(0xe707), SHC(0x7c77), SHC(0xe21e), SHC(0x7b32), SHC(0xdd41), - SHC(0x79bc), SHC(0xd872), SHC(0x7817), SHC(0xd3b2), SHC(0x7642), SHC(0xcf04), SHC(0x743e), SHC(0xca69), - SHC(0x720d), SHC(0xc5e4), SHC(0x6fae), SHC(0xc175), SHC(0x6d23), SHC(0xbd1f), SHC(0x6a6e), SHC(0xb8e3), - SHC(0x678e), SHC(0xb4c3), SHC(0x6485), SHC(0xb0c2), SHC(0x6155), SHC(0xacdf), SHC(0x5dfe), SHC(0xa91d), - SHC(0x7fff), SHC(0x0000), SHC(0x7f9b), SHC(0xf5f5), SHC(0x7e6d), SHC(0xebfa), SHC(0x7c77), SHC(0xe21e), - SHC(0x79bc), SHC(0xd872), SHC(0x7642), SHC(0xcf04), SHC(0x720d), SHC(0xc5e4), SHC(0x6d23), SHC(0xbd1f), - SHC(0x678e), SHC(0xb4c3), SHC(0x6155), SHC(0xacdf), SHC(0x5a82), SHC(0xa57e), SHC(0x5321), SHC(0x9eab), - SHC(0x4b3d), SHC(0x9872), SHC(0x42e1), SHC(0x92dd), SHC(0x3a1c), SHC(0x8df3), SHC(0x30fc), SHC(0x89be), - SHC(0x278e), SHC(0x8644), SHC(0x1de2), SHC(0x8389), SHC(0x1406), SHC(0x8193), SHC(0x0a0b), SHC(0x8065), - SHC(0x7fff), SHC(0x0000), SHC(0x7f1d), SHC(0xf0f5), SHC(0x7c77), SHC(0xe21e), SHC(0x7817), SHC(0xd3b2), - SHC(0x720d), SHC(0xc5e4), SHC(0x6a6e), SHC(0xb8e3), SHC(0x6155), SHC(0xacdf), SHC(0x56e3), SHC(0xa202), - SHC(0x4b3d), SHC(0x9872), SHC(0x3e8b), SHC(0x9052), SHC(0x30fc), SHC(0x89be), SHC(0x22bf), SHC(0x84ce), - SHC(0x1406), SHC(0x8193), SHC(0x0506), SHC(0x8019), SHC(0xf5f5), SHC(0x8065), SHC(0xe707), SHC(0x8276), - SHC(0xd872), SHC(0x8644), SHC(0xca69), SHC(0x8bc2), SHC(0xbd1f), SHC(0x92dd), SHC(0xb0c2), SHC(0x9b7b), - SHC(0x7fff), SHC(0x0000), SHC(0x7e6d), SHC(0xebfa), SHC(0x79bc), SHC(0xd872), SHC(0x720d), SHC(0xc5e4), - SHC(0x678e), SHC(0xb4c3), SHC(0x5a82), SHC(0xa57e), SHC(0x4b3d), SHC(0x9872), SHC(0x3a1c), SHC(0x8df3), - SHC(0x278e), SHC(0x8644), SHC(0x1406), SHC(0x8193), SHC(0x0000), SHC(0x8000), SHC(0xebfa), SHC(0x8193), - SHC(0xd872), SHC(0x8644), SHC(0xc5e4), SHC(0x8df3), SHC(0xb4c3), SHC(0x9872), SHC(0xa57e), SHC(0xa57e), - SHC(0x9872), SHC(0xb4c3), SHC(0x8df3), SHC(0xc5e4), SHC(0x8644), SHC(0xd872), SHC(0x8193), SHC(0xebfa), - SHC(0x7fff), SHC(0x0000), SHC(0x7d8a), SHC(0xe707), SHC(0x7642), SHC(0xcf04), SHC(0x6a6e), SHC(0xb8e3), - SHC(0x5a82), SHC(0xa57e), SHC(0x471d), SHC(0x9592), SHC(0x30fc), SHC(0x89be), SHC(0x18f9), SHC(0x8276), - SHC(0x0000), SHC(0x8000), SHC(0xe707), SHC(0x8276), SHC(0xcf04), SHC(0x89be), SHC(0xb8e3), SHC(0x9592), - SHC(0xa57e), SHC(0xa57e), SHC(0x9592), SHC(0xb8e3), SHC(0x89be), SHC(0xcf04), SHC(0x8276), SHC(0xe707), - SHC(0x8000), SHC(0x0000), SHC(0x8276), SHC(0x18f9), SHC(0x89be), SHC(0x30fc), SHC(0x9592), SHC(0x471d), - SHC(0x7fff), SHC(0x0000), SHC(0x7c77), SHC(0xe21e), SHC(0x720d), SHC(0xc5e4), SHC(0x6155), SHC(0xacdf), - SHC(0x4b3d), SHC(0x9872), SHC(0x30fc), SHC(0x89be), SHC(0x1406), SHC(0x8193), SHC(0xf5f5), SHC(0x8065), - SHC(0xd872), SHC(0x8644), SHC(0xbd1f), SHC(0x92dd), SHC(0xa57e), SHC(0xa57e), SHC(0x92dd), SHC(0xbd1f), - SHC(0x8644), SHC(0xd872), SHC(0x8065), SHC(0xf5f5), SHC(0x8193), SHC(0x1406), SHC(0x89be), SHC(0x30fc), - SHC(0x9872), SHC(0x4b3d), SHC(0xacdf), SHC(0x6155), SHC(0xc5e4), SHC(0x720d), SHC(0xe21e), SHC(0x7c77), - SHC(0x7fff), SHC(0x0000), SHC(0x7b32), SHC(0xdd41), SHC(0x6d23), SHC(0xbd1f), SHC(0x56e3), SHC(0xa202), - SHC(0x3a1c), SHC(0x8df3), SHC(0x18f9), SHC(0x8276), SHC(0xf5f5), SHC(0x8065), SHC(0xd3b2), SHC(0x87e9), - SHC(0xb4c3), SHC(0x9872), SHC(0x9b7b), SHC(0xb0c2), SHC(0x89be), SHC(0xcf04), SHC(0x80e3), SHC(0xf0f5), - SHC(0x8193), SHC(0x1406), SHC(0x8bc2), SHC(0x3597), SHC(0x9eab), SHC(0x5321), SHC(0xb8e3), SHC(0x6a6e), - SHC(0xd872), SHC(0x79bc), SHC(0xfafa), SHC(0x7fe7), SHC(0x1de2), SHC(0x7c77), SHC(0x3e8b), SHC(0x6fae), - SHC(0x7fff), SHC(0x0000), SHC(0x7ffa), SHC(0xfd7d), SHC(0x7fe7), SHC(0xfafa), SHC(0x7fc7), SHC(0xf877), - SHC(0x7f9b), SHC(0xf5f5), SHC(0x7f62), SHC(0xf374), SHC(0x7f1d), SHC(0xf0f5), SHC(0x7ecb), SHC(0xee76), - SHC(0x7e6d), SHC(0xebfa), SHC(0x7e02), SHC(0xe980), SHC(0x7d8a), SHC(0xe707), SHC(0x7d07), SHC(0xe492), - SHC(0x7c77), SHC(0xe21e), SHC(0x7bda), SHC(0xdfae), SHC(0x7b32), SHC(0xdd41), SHC(0x7a7d), SHC(0xdad8), - SHC(0x79bc), SHC(0xd872), SHC(0x78ef), SHC(0xd610), SHC(0x7817), SHC(0xd3b2), SHC(0x7732), SHC(0xd159), - SHC(0x7fff), SHC(0x0000), SHC(0x7fc7), SHC(0xf877), SHC(0x7f1d), SHC(0xf0f5), SHC(0x7e02), SHC(0xe980), - SHC(0x7c77), SHC(0xe21e), SHC(0x7a7d), SHC(0xdad8), SHC(0x7817), SHC(0xd3b2), SHC(0x7546), SHC(0xccb4), - SHC(0x720d), SHC(0xc5e4), SHC(0x6e6e), SHC(0xbf47), SHC(0x6a6e), SHC(0xb8e3), SHC(0x660f), SHC(0xb2bf), - SHC(0x6155), SHC(0xacdf), SHC(0x5c45), SHC(0xa749), SHC(0x56e3), SHC(0xa202), SHC(0x5134), SHC(0x9d0e), - SHC(0x4b3d), SHC(0x9872), SHC(0x4502), SHC(0x9432), SHC(0x3e8b), SHC(0x9052), SHC(0x37dc), SHC(0x8cd5), - SHC(0x7fff), SHC(0x0000), SHC(0x7f62), SHC(0xf374), SHC(0x7d8a), SHC(0xe707), SHC(0x7a7d), SHC(0xdad8), - SHC(0x7642), SHC(0xcf04), SHC(0x70e3), SHC(0xc3a9), SHC(0x6a6e), SHC(0xb8e3), SHC(0x62f2), SHC(0xaecc), - SHC(0x5a82), SHC(0xa57e), SHC(0x5134), SHC(0x9d0e), SHC(0x471d), SHC(0x9592), SHC(0x3c57), SHC(0x8f1d), - SHC(0x30fc), SHC(0x89be), SHC(0x2528), SHC(0x8583), SHC(0x18f9), SHC(0x8276), SHC(0x0c8c), SHC(0x809e), - SHC(0x0000), SHC(0x8000), SHC(0xf374), SHC(0x809e), SHC(0xe707), SHC(0x8276), SHC(0xdad8), SHC(0x8583), - SHC(0x7fff), SHC(0x0000), SHC(0x7ecb), SHC(0xee76), SHC(0x7b32), SHC(0xdd41), SHC(0x7546), SHC(0xccb4), - SHC(0x6d23), SHC(0xbd1f), SHC(0x62f2), SHC(0xaecc), SHC(0x56e3), SHC(0xa202), SHC(0x4930), SHC(0x96fd), - SHC(0x3a1c), SHC(0x8df3), SHC(0x29f0), SHC(0x8711), SHC(0x18f9), SHC(0x8276), SHC(0x0789), SHC(0x8039), - SHC(0xf5f5), SHC(0x8065), SHC(0xe492), SHC(0x82f9), SHC(0xd3b2), SHC(0x87e9), SHC(0xc3a9), SHC(0x8f1d), - SHC(0xb4c3), SHC(0x9872), SHC(0xa749), SHC(0xa3bb), SHC(0x9b7b), SHC(0xb0c2), SHC(0x9192), SHC(0xbf47), - SHC(0x7fff), SHC(0x0000), SHC(0x7e02), SHC(0xe980), SHC(0x7817), SHC(0xd3b2), SHC(0x6e6e), SHC(0xbf47), - SHC(0x6155), SHC(0xacdf), SHC(0x5134), SHC(0x9d0e), SHC(0x3e8b), SHC(0x9052), SHC(0x29f0), SHC(0x8711), - SHC(0x1406), SHC(0x8193), SHC(0xfd7d), SHC(0x8006), SHC(0xe707), SHC(0x8276), SHC(0xd159), SHC(0x88ce), - SHC(0xbd1f), SHC(0x92dd), SHC(0xaafa), SHC(0xa052), SHC(0x9b7b), SHC(0xb0c2), SHC(0x8f1d), SHC(0xc3a9), - SHC(0x8644), SHC(0xd872), SHC(0x8135), SHC(0xee76), SHC(0x8019), SHC(0x0506), SHC(0x82f9), SHC(0x1b6e), - SHC(0x7fff), SHC(0x0000), SHC(0x7d07), SHC(0xe492), SHC(0x743e), SHC(0xca69), SHC(0x660f), SHC(0xb2bf), - SHC(0x5321), SHC(0x9eab), SHC(0x3c57), SHC(0x8f1d), SHC(0x22bf), SHC(0x84ce), SHC(0x0789), SHC(0x8039), - SHC(0xebfa), SHC(0x8193), SHC(0xd159), SHC(0x88ce), SHC(0xb8e3), SHC(0x9592), SHC(0xa3bb), SHC(0xa749), - SHC(0x92dd), SHC(0xbd1f), SHC(0x8711), SHC(0xd610), SHC(0x80e3), SHC(0xf0f5), SHC(0x809e), SHC(0x0c8c), - SHC(0x8644), SHC(0x278e), SHC(0x9192), SHC(0x40b9), SHC(0xa202), SHC(0x56e3), SHC(0xb6d0), SHC(0x6903), - SHC(0x7fff), SHC(0x0000), SHC(0x7bda), SHC(0xdfae), SHC(0x6fae), SHC(0xc175), SHC(0x5c45), SHC(0xa749), - SHC(0x42e1), SHC(0x92dd), SHC(0x2528), SHC(0x8583), SHC(0x0506), SHC(0x8019), SHC(0xe492), SHC(0x82f9), - SHC(0xc5e4), SHC(0x8df3), SHC(0xaafa), SHC(0xa052), SHC(0x9592), SHC(0xb8e3), SHC(0x8711), SHC(0xd610), - SHC(0x8065), SHC(0xf5f5), SHC(0x81fe), SHC(0x1680), SHC(0x8bc2), SHC(0x3597), SHC(0x9d0e), SHC(0x5134), - SHC(0xb4c3), SHC(0x678e), SHC(0xd159), SHC(0x7732), SHC(0xf0f5), SHC(0x7f1d), SHC(0x118a), SHC(0x7ecb), - SHC(0x7fff), SHC(0x0000), SHC(0x7a7d), SHC(0xdad8), SHC(0x6a6e), SHC(0xb8e3), SHC(0x5134), SHC(0x9d0e), - SHC(0x30fc), SHC(0x89be), SHC(0x0c8c), SHC(0x809e), SHC(0xe707), SHC(0x8276), SHC(0xc3a9), SHC(0x8f1d), - SHC(0xa57e), SHC(0xa57e), SHC(0x8f1d), SHC(0xc3a9), SHC(0x8276), SHC(0xe707), SHC(0x809e), SHC(0x0c8c), - SHC(0x89be), SHC(0x30fc), SHC(0x9d0e), SHC(0x5134), SHC(0xb8e3), SHC(0x6a6e), SHC(0xdad8), SHC(0x7a7d), - SHC(0x0000), SHC(0x7fff), SHC(0x2528), SHC(0x7a7d), SHC(0x471d), SHC(0x6a6e), SHC(0x62f2), SHC(0x5134) +const Word16 RotVector_320[2 * ( 320 - 20 )] = { + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7fe7 ), SHC( 0xfafa ), SHC( 0x7f9b ), SHC( 0xf5f5 ), SHC( 0x7f1d ), SHC( 0xf0f5 ), + SHC( 0x7e6d ), SHC( 0xebfa ), SHC( 0x7d8a ), SHC( 0xe707 ), SHC( 0x7c77 ), SHC( 0xe21e ), SHC( 0x7b32 ), SHC( 0xdd41 ), + SHC( 0x79bc ), SHC( 0xd872 ), SHC( 0x7817 ), SHC( 0xd3b2 ), SHC( 0x7642 ), SHC( 0xcf04 ), SHC( 0x743e ), SHC( 0xca69 ), + SHC( 0x720d ), SHC( 0xc5e4 ), SHC( 0x6fae ), SHC( 0xc175 ), SHC( 0x6d23 ), SHC( 0xbd1f ), SHC( 0x6a6e ), SHC( 0xb8e3 ), + SHC( 0x678e ), SHC( 0xb4c3 ), SHC( 0x6485 ), SHC( 0xb0c2 ), SHC( 0x6155 ), SHC( 0xacdf ), SHC( 0x5dfe ), SHC( 0xa91d ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7f9b ), SHC( 0xf5f5 ), SHC( 0x7e6d ), SHC( 0xebfa ), SHC( 0x7c77 ), SHC( 0xe21e ), + SHC( 0x79bc ), SHC( 0xd872 ), SHC( 0x7642 ), SHC( 0xcf04 ), SHC( 0x720d ), SHC( 0xc5e4 ), SHC( 0x6d23 ), SHC( 0xbd1f ), + SHC( 0x678e ), SHC( 0xb4c3 ), SHC( 0x6155 ), SHC( 0xacdf ), SHC( 0x5a82 ), SHC( 0xa57e ), SHC( 0x5321 ), SHC( 0x9eab ), + SHC( 0x4b3d ), SHC( 0x9872 ), SHC( 0x42e1 ), SHC( 0x92dd ), SHC( 0x3a1c ), SHC( 0x8df3 ), SHC( 0x30fc ), SHC( 0x89be ), + SHC( 0x278e ), SHC( 0x8644 ), SHC( 0x1de2 ), SHC( 0x8389 ), SHC( 0x1406 ), SHC( 0x8193 ), SHC( 0x0a0b ), SHC( 0x8065 ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7f1d ), SHC( 0xf0f5 ), SHC( 0x7c77 ), SHC( 0xe21e ), SHC( 0x7817 ), SHC( 0xd3b2 ), + SHC( 0x720d ), SHC( 0xc5e4 ), SHC( 0x6a6e ), SHC( 0xb8e3 ), SHC( 0x6155 ), SHC( 0xacdf ), SHC( 0x56e3 ), SHC( 0xa202 ), + SHC( 0x4b3d ), SHC( 0x9872 ), SHC( 0x3e8b ), SHC( 0x9052 ), SHC( 0x30fc ), SHC( 0x89be ), SHC( 0x22bf ), SHC( 0x84ce ), + SHC( 0x1406 ), SHC( 0x8193 ), SHC( 0x0506 ), SHC( 0x8019 ), SHC( 0xf5f5 ), SHC( 0x8065 ), SHC( 0xe707 ), SHC( 0x8276 ), + SHC( 0xd872 ), SHC( 0x8644 ), SHC( 0xca69 ), SHC( 0x8bc2 ), SHC( 0xbd1f ), SHC( 0x92dd ), SHC( 0xb0c2 ), SHC( 0x9b7b ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7e6d ), SHC( 0xebfa ), SHC( 0x79bc ), SHC( 0xd872 ), SHC( 0x720d ), SHC( 0xc5e4 ), + SHC( 0x678e ), SHC( 0xb4c3 ), SHC( 0x5a82 ), SHC( 0xa57e ), SHC( 0x4b3d ), SHC( 0x9872 ), SHC( 0x3a1c ), SHC( 0x8df3 ), + SHC( 0x278e ), SHC( 0x8644 ), SHC( 0x1406 ), SHC( 0x8193 ), SHC( 0x0000 ), SHC( 0x8000 ), SHC( 0xebfa ), SHC( 0x8193 ), + SHC( 0xd872 ), SHC( 0x8644 ), SHC( 0xc5e4 ), SHC( 0x8df3 ), SHC( 0xb4c3 ), SHC( 0x9872 ), SHC( 0xa57e ), SHC( 0xa57e ), + SHC( 0x9872 ), SHC( 0xb4c3 ), SHC( 0x8df3 ), SHC( 0xc5e4 ), SHC( 0x8644 ), SHC( 0xd872 ), SHC( 0x8193 ), SHC( 0xebfa ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7d8a ), SHC( 0xe707 ), SHC( 0x7642 ), SHC( 0xcf04 ), SHC( 0x6a6e ), SHC( 0xb8e3 ), + SHC( 0x5a82 ), SHC( 0xa57e ), SHC( 0x471d ), SHC( 0x9592 ), SHC( 0x30fc ), SHC( 0x89be ), SHC( 0x18f9 ), SHC( 0x8276 ), + SHC( 0x0000 ), SHC( 0x8000 ), SHC( 0xe707 ), SHC( 0x8276 ), SHC( 0xcf04 ), SHC( 0x89be ), SHC( 0xb8e3 ), SHC( 0x9592 ), + SHC( 0xa57e ), SHC( 0xa57e ), SHC( 0x9592 ), SHC( 0xb8e3 ), SHC( 0x89be ), SHC( 0xcf04 ), SHC( 0x8276 ), SHC( 0xe707 ), + SHC( 0x8000 ), SHC( 0x0000 ), SHC( 0x8276 ), SHC( 0x18f9 ), SHC( 0x89be ), SHC( 0x30fc ), SHC( 0x9592 ), SHC( 0x471d ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7c77 ), SHC( 0xe21e ), SHC( 0x720d ), SHC( 0xc5e4 ), SHC( 0x6155 ), SHC( 0xacdf ), + SHC( 0x4b3d ), SHC( 0x9872 ), SHC( 0x30fc ), SHC( 0x89be ), SHC( 0x1406 ), SHC( 0x8193 ), SHC( 0xf5f5 ), SHC( 0x8065 ), + SHC( 0xd872 ), SHC( 0x8644 ), SHC( 0xbd1f ), SHC( 0x92dd ), SHC( 0xa57e ), SHC( 0xa57e ), SHC( 0x92dd ), SHC( 0xbd1f ), + SHC( 0x8644 ), SHC( 0xd872 ), SHC( 0x8065 ), SHC( 0xf5f5 ), SHC( 0x8193 ), SHC( 0x1406 ), SHC( 0x89be ), SHC( 0x30fc ), + SHC( 0x9872 ), SHC( 0x4b3d ), SHC( 0xacdf ), SHC( 0x6155 ), SHC( 0xc5e4 ), SHC( 0x720d ), SHC( 0xe21e ), SHC( 0x7c77 ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7b32 ), SHC( 0xdd41 ), SHC( 0x6d23 ), SHC( 0xbd1f ), SHC( 0x56e3 ), SHC( 0xa202 ), + SHC( 0x3a1c ), SHC( 0x8df3 ), SHC( 0x18f9 ), SHC( 0x8276 ), SHC( 0xf5f5 ), SHC( 0x8065 ), SHC( 0xd3b2 ), SHC( 0x87e9 ), + SHC( 0xb4c3 ), SHC( 0x9872 ), SHC( 0x9b7b ), SHC( 0xb0c2 ), SHC( 0x89be ), SHC( 0xcf04 ), SHC( 0x80e3 ), SHC( 0xf0f5 ), + SHC( 0x8193 ), SHC( 0x1406 ), SHC( 0x8bc2 ), SHC( 0x3597 ), SHC( 0x9eab ), SHC( 0x5321 ), SHC( 0xb8e3 ), SHC( 0x6a6e ), + SHC( 0xd872 ), SHC( 0x79bc ), SHC( 0xfafa ), SHC( 0x7fe7 ), SHC( 0x1de2 ), SHC( 0x7c77 ), SHC( 0x3e8b ), SHC( 0x6fae ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7ffa ), SHC( 0xfd7d ), SHC( 0x7fe7 ), SHC( 0xfafa ), SHC( 0x7fc7 ), SHC( 0xf877 ), + SHC( 0x7f9b ), SHC( 0xf5f5 ), SHC( 0x7f62 ), SHC( 0xf374 ), SHC( 0x7f1d ), SHC( 0xf0f5 ), SHC( 0x7ecb ), SHC( 0xee76 ), + SHC( 0x7e6d ), SHC( 0xebfa ), SHC( 0x7e02 ), SHC( 0xe980 ), SHC( 0x7d8a ), SHC( 0xe707 ), SHC( 0x7d07 ), SHC( 0xe492 ), + SHC( 0x7c77 ), SHC( 0xe21e ), SHC( 0x7bda ), SHC( 0xdfae ), SHC( 0x7b32 ), SHC( 0xdd41 ), SHC( 0x7a7d ), SHC( 0xdad8 ), + SHC( 0x79bc ), SHC( 0xd872 ), SHC( 0x78ef ), SHC( 0xd610 ), SHC( 0x7817 ), SHC( 0xd3b2 ), SHC( 0x7732 ), SHC( 0xd159 ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7fc7 ), SHC( 0xf877 ), SHC( 0x7f1d ), SHC( 0xf0f5 ), SHC( 0x7e02 ), SHC( 0xe980 ), + SHC( 0x7c77 ), SHC( 0xe21e ), SHC( 0x7a7d ), SHC( 0xdad8 ), SHC( 0x7817 ), SHC( 0xd3b2 ), SHC( 0x7546 ), SHC( 0xccb4 ), + SHC( 0x720d ), SHC( 0xc5e4 ), SHC( 0x6e6e ), SHC( 0xbf47 ), SHC( 0x6a6e ), SHC( 0xb8e3 ), SHC( 0x660f ), SHC( 0xb2bf ), + SHC( 0x6155 ), SHC( 0xacdf ), SHC( 0x5c45 ), SHC( 0xa749 ), SHC( 0x56e3 ), SHC( 0xa202 ), SHC( 0x5134 ), SHC( 0x9d0e ), + SHC( 0x4b3d ), SHC( 0x9872 ), SHC( 0x4502 ), SHC( 0x9432 ), SHC( 0x3e8b ), SHC( 0x9052 ), SHC( 0x37dc ), SHC( 0x8cd5 ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7f62 ), SHC( 0xf374 ), SHC( 0x7d8a ), SHC( 0xe707 ), SHC( 0x7a7d ), SHC( 0xdad8 ), + SHC( 0x7642 ), SHC( 0xcf04 ), SHC( 0x70e3 ), SHC( 0xc3a9 ), SHC( 0x6a6e ), SHC( 0xb8e3 ), SHC( 0x62f2 ), SHC( 0xaecc ), + SHC( 0x5a82 ), SHC( 0xa57e ), SHC( 0x5134 ), SHC( 0x9d0e ), SHC( 0x471d ), SHC( 0x9592 ), SHC( 0x3c57 ), SHC( 0x8f1d ), + SHC( 0x30fc ), SHC( 0x89be ), SHC( 0x2528 ), SHC( 0x8583 ), SHC( 0x18f9 ), SHC( 0x8276 ), SHC( 0x0c8c ), SHC( 0x809e ), + SHC( 0x0000 ), SHC( 0x8000 ), SHC( 0xf374 ), SHC( 0x809e ), SHC( 0xe707 ), SHC( 0x8276 ), SHC( 0xdad8 ), SHC( 0x8583 ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7ecb ), SHC( 0xee76 ), SHC( 0x7b32 ), SHC( 0xdd41 ), SHC( 0x7546 ), SHC( 0xccb4 ), + SHC( 0x6d23 ), SHC( 0xbd1f ), SHC( 0x62f2 ), SHC( 0xaecc ), SHC( 0x56e3 ), SHC( 0xa202 ), SHC( 0x4930 ), SHC( 0x96fd ), + SHC( 0x3a1c ), SHC( 0x8df3 ), SHC( 0x29f0 ), SHC( 0x8711 ), SHC( 0x18f9 ), SHC( 0x8276 ), SHC( 0x0789 ), SHC( 0x8039 ), + SHC( 0xf5f5 ), SHC( 0x8065 ), SHC( 0xe492 ), SHC( 0x82f9 ), SHC( 0xd3b2 ), SHC( 0x87e9 ), SHC( 0xc3a9 ), SHC( 0x8f1d ), + SHC( 0xb4c3 ), SHC( 0x9872 ), SHC( 0xa749 ), SHC( 0xa3bb ), SHC( 0x9b7b ), SHC( 0xb0c2 ), SHC( 0x9192 ), SHC( 0xbf47 ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7e02 ), SHC( 0xe980 ), SHC( 0x7817 ), SHC( 0xd3b2 ), SHC( 0x6e6e ), SHC( 0xbf47 ), + SHC( 0x6155 ), SHC( 0xacdf ), SHC( 0x5134 ), SHC( 0x9d0e ), SHC( 0x3e8b ), SHC( 0x9052 ), SHC( 0x29f0 ), SHC( 0x8711 ), + SHC( 0x1406 ), SHC( 0x8193 ), SHC( 0xfd7d ), SHC( 0x8006 ), SHC( 0xe707 ), SHC( 0x8276 ), SHC( 0xd159 ), SHC( 0x88ce ), + SHC( 0xbd1f ), SHC( 0x92dd ), SHC( 0xaafa ), SHC( 0xa052 ), SHC( 0x9b7b ), SHC( 0xb0c2 ), SHC( 0x8f1d ), SHC( 0xc3a9 ), + SHC( 0x8644 ), SHC( 0xd872 ), SHC( 0x8135 ), SHC( 0xee76 ), SHC( 0x8019 ), SHC( 0x0506 ), SHC( 0x82f9 ), SHC( 0x1b6e ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7d07 ), SHC( 0xe492 ), SHC( 0x743e ), SHC( 0xca69 ), SHC( 0x660f ), SHC( 0xb2bf ), + SHC( 0x5321 ), SHC( 0x9eab ), SHC( 0x3c57 ), SHC( 0x8f1d ), SHC( 0x22bf ), SHC( 0x84ce ), SHC( 0x0789 ), SHC( 0x8039 ), + SHC( 0xebfa ), SHC( 0x8193 ), SHC( 0xd159 ), SHC( 0x88ce ), SHC( 0xb8e3 ), SHC( 0x9592 ), SHC( 0xa3bb ), SHC( 0xa749 ), + SHC( 0x92dd ), SHC( 0xbd1f ), SHC( 0x8711 ), SHC( 0xd610 ), SHC( 0x80e3 ), SHC( 0xf0f5 ), SHC( 0x809e ), SHC( 0x0c8c ), + SHC( 0x8644 ), SHC( 0x278e ), SHC( 0x9192 ), SHC( 0x40b9 ), SHC( 0xa202 ), SHC( 0x56e3 ), SHC( 0xb6d0 ), SHC( 0x6903 ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7bda ), SHC( 0xdfae ), SHC( 0x6fae ), SHC( 0xc175 ), SHC( 0x5c45 ), SHC( 0xa749 ), + SHC( 0x42e1 ), SHC( 0x92dd ), SHC( 0x2528 ), SHC( 0x8583 ), SHC( 0x0506 ), SHC( 0x8019 ), SHC( 0xe492 ), SHC( 0x82f9 ), + SHC( 0xc5e4 ), SHC( 0x8df3 ), SHC( 0xaafa ), SHC( 0xa052 ), SHC( 0x9592 ), SHC( 0xb8e3 ), SHC( 0x8711 ), SHC( 0xd610 ), + SHC( 0x8065 ), SHC( 0xf5f5 ), SHC( 0x81fe ), SHC( 0x1680 ), SHC( 0x8bc2 ), SHC( 0x3597 ), SHC( 0x9d0e ), SHC( 0x5134 ), + SHC( 0xb4c3 ), SHC( 0x678e ), SHC( 0xd159 ), SHC( 0x7732 ), SHC( 0xf0f5 ), SHC( 0x7f1d ), SHC( 0x118a ), SHC( 0x7ecb ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7a7d ), SHC( 0xdad8 ), SHC( 0x6a6e ), SHC( 0xb8e3 ), SHC( 0x5134 ), SHC( 0x9d0e ), + SHC( 0x30fc ), SHC( 0x89be ), SHC( 0x0c8c ), SHC( 0x809e ), SHC( 0xe707 ), SHC( 0x8276 ), SHC( 0xc3a9 ), SHC( 0x8f1d ), + SHC( 0xa57e ), SHC( 0xa57e ), SHC( 0x8f1d ), SHC( 0xc3a9 ), SHC( 0x8276 ), SHC( 0xe707 ), SHC( 0x809e ), SHC( 0x0c8c ), + SHC( 0x89be ), SHC( 0x30fc ), SHC( 0x9d0e ), SHC( 0x5134 ), SHC( 0xb8e3 ), SHC( 0x6a6e ), SHC( 0xdad8 ), SHC( 0x7a7d ), + SHC( 0x0000 ), SHC( 0x7fff ), SHC( 0x2528 ), SHC( 0x7a7d ), SHC( 0x471d ), SHC( 0x6a6e ), SHC( 0x62f2 ), SHC( 0x5134 ) }; @@ -40565,737 +40559,726 @@ const Word16 RotVector_320[2 * (320 - 20)] = * Rotation factor table, real and imaginary part interleaved, for dim1=20,dim2=20 */ -const Word16 RotVector_400[2 * (400 - 20)] = -{ - SHC(0x7fff), SHC(0x0000), SHC(0x7ff0), SHC(0xfbfb), SHC(0x7fbf), SHC(0xf7f6), SHC(0x7f6f), SHC(0xf3f4), - SHC(0x7efe), SHC(0xeff5), SHC(0x7e6d), SHC(0xebfa), SHC(0x7dbc), SHC(0xe804), SHC(0x7ceb), SHC(0xe414), - SHC(0x7bfb), SHC(0xe02b), SHC(0x7aeb), SHC(0xdc4a), SHC(0x79bc), SHC(0xd872), SHC(0x786f), SHC(0xd4a4), - SHC(0x7703), SHC(0xd0e1), SHC(0x7579), SHC(0xcd2a), SHC(0x73d1), SHC(0xc980), SHC(0x720d), SHC(0xc5e4), - SHC(0x702b), SHC(0xc256), SHC(0x6e2d), SHC(0xbed8), SHC(0x6c13), SHC(0xbb6a), SHC(0x69de), SHC(0xb80e), - SHC(0x7fff), SHC(0x0000), SHC(0x7fbf), SHC(0xf7f6), SHC(0x7efe), SHC(0xeff5), SHC(0x7dbc), SHC(0xe804), - SHC(0x7bfb), SHC(0xe02b), SHC(0x79bc), SHC(0xd872), SHC(0x7703), SHC(0xd0e1), SHC(0x73d1), SHC(0xc980), - SHC(0x702b), SHC(0xc256), SHC(0x6c13), SHC(0xbb6a), SHC(0x678e), SHC(0xb4c3), SHC(0x62a0), SHC(0xae69), - SHC(0x5d4f), SHC(0xa861), SHC(0x579f), SHC(0xa2b1), SHC(0x5197), SHC(0x9d60), SHC(0x4b3d), SHC(0x9872), - SHC(0x4496), SHC(0x93ed), SHC(0x3daa), SHC(0x8fd5), SHC(0x3680), SHC(0x8c2f), SHC(0x2f1f), SHC(0x88fd), - SHC(0x7fff), SHC(0x0000), SHC(0x7f6f), SHC(0xf3f4), SHC(0x7dbc), SHC(0xe804), SHC(0x7aeb), SHC(0xdc4a), - SHC(0x7703), SHC(0xd0e1), SHC(0x720d), SHC(0xc5e4), SHC(0x6c13), SHC(0xbb6a), SHC(0x6524), SHC(0xb18c), - SHC(0x5d4f), SHC(0xa861), SHC(0x54a6), SHC(0x9ffc), SHC(0x4b3d), SHC(0x9872), SHC(0x4128), SHC(0x91d3), - SHC(0x3680), SHC(0x8c2f), SHC(0x2b5c), SHC(0x8791), SHC(0x1fd5), SHC(0x8405), SHC(0x1406), SHC(0x8193), - SHC(0x080a), SHC(0x8041), SHC(0xfbfb), SHC(0x8010), SHC(0xeff5), SHC(0x8102), SHC(0xe414), SHC(0x8315), - SHC(0x7fff), SHC(0x0000), SHC(0x7efe), SHC(0xeff5), SHC(0x7bfb), SHC(0xe02b), SHC(0x7703), SHC(0xd0e1), - SHC(0x702b), SHC(0xc256), SHC(0x678e), SHC(0xb4c3), SHC(0x5d4f), SHC(0xa861), SHC(0x5197), SHC(0x9d60), - SHC(0x4496), SHC(0x93ed), SHC(0x3680), SHC(0x8c2f), SHC(0x278e), SHC(0x8644), SHC(0x17fc), SHC(0x8244), - SHC(0x080a), SHC(0x8041), SHC(0xf7f6), SHC(0x8041), SHC(0xe804), SHC(0x8244), SHC(0xd872), SHC(0x8644), - SHC(0xc980), SHC(0x8c2f), SHC(0xbb6a), SHC(0x93ed), SHC(0xae69), SHC(0x9d60), SHC(0xa2b1), SHC(0xa861), - SHC(0x7fff), SHC(0x0000), SHC(0x7e6d), SHC(0xebfa), SHC(0x79bc), SHC(0xd872), SHC(0x720d), SHC(0xc5e4), - SHC(0x678e), SHC(0xb4c3), SHC(0x5a82), SHC(0xa57e), SHC(0x4b3d), SHC(0x9872), SHC(0x3a1c), SHC(0x8df3), - SHC(0x278e), SHC(0x8644), SHC(0x1406), SHC(0x8193), SHC(0x0000), SHC(0x8000), SHC(0xebfa), SHC(0x8193), - SHC(0xd872), SHC(0x8644), SHC(0xc5e4), SHC(0x8df3), SHC(0xb4c3), SHC(0x9872), SHC(0xa57e), SHC(0xa57e), - SHC(0x9872), SHC(0xb4c3), SHC(0x8df3), SHC(0xc5e4), SHC(0x8644), SHC(0xd872), SHC(0x8193), SHC(0xebfa), - SHC(0x7fff), SHC(0x0000), SHC(0x7dbc), SHC(0xe804), SHC(0x7703), SHC(0xd0e1), SHC(0x6c13), SHC(0xbb6a), - SHC(0x5d4f), SHC(0xa861), SHC(0x4b3d), SHC(0x9872), SHC(0x3680), SHC(0x8c2f), SHC(0x1fd5), SHC(0x8405), - SHC(0x080a), SHC(0x8041), SHC(0xeff5), SHC(0x8102), SHC(0xd872), SHC(0x8644), SHC(0xc256), SHC(0x8fd5), - SHC(0xae69), SHC(0x9d60), SHC(0x9d60), SHC(0xae69), SHC(0x8fd5), SHC(0xc256), SHC(0x8644), SHC(0xd872), - SHC(0x8102), SHC(0xeff5), SHC(0x8041), SHC(0x080a), SHC(0x8405), SHC(0x1fd5), SHC(0x8c2f), SHC(0x3680), - SHC(0x7fff), SHC(0x0000), SHC(0x7ceb), SHC(0xe414), SHC(0x73d1), SHC(0xc980), SHC(0x6524), SHC(0xb18c), - SHC(0x5197), SHC(0x9d60), SHC(0x3a1c), SHC(0x8df3), SHC(0x1fd5), SHC(0x8405), SHC(0x0405), SHC(0x8010), - SHC(0xe804), SHC(0x8244), SHC(0xcd2a), SHC(0x8a87), SHC(0xb4c3), SHC(0x9872), SHC(0x9ffc), SHC(0xab5a), - SHC(0x8fd5), SHC(0xc256), SHC(0x8515), SHC(0xdc4a), SHC(0x8041), SHC(0xf7f6), SHC(0x8193), SHC(0x1406), - SHC(0x88fd), SHC(0x2f1f), SHC(0x9622), SHC(0x47f2), SHC(0xa861), SHC(0x5d4f), SHC(0xbed8), SHC(0x6e2d), - SHC(0x7fff), SHC(0x0000), SHC(0x7bfb), SHC(0xe02b), SHC(0x702b), SHC(0xc256), SHC(0x5d4f), SHC(0xa861), - SHC(0x4496), SHC(0x93ed), SHC(0x278e), SHC(0x8644), SHC(0x080a), SHC(0x8041), SHC(0xe804), SHC(0x8244), - SHC(0xc980), SHC(0x8c2f), SHC(0xae69), SHC(0x9d60), SHC(0x9872), SHC(0xb4c3), SHC(0x88fd), SHC(0xd0e1), - SHC(0x8102), SHC(0xeff5), SHC(0x8102), SHC(0x100b), SHC(0x88fd), SHC(0x2f1f), SHC(0x9872), SHC(0x4b3d), - SHC(0xae69), SHC(0x62a0), SHC(0xc980), SHC(0x73d1), SHC(0xe804), SHC(0x7dbc), SHC(0x080a), SHC(0x7fbf), - SHC(0x7fff), SHC(0x0000), SHC(0x7aeb), SHC(0xdc4a), SHC(0x6c13), SHC(0xbb6a), SHC(0x54a6), SHC(0x9ffc), - SHC(0x3680), SHC(0x8c2f), SHC(0x1406), SHC(0x8193), SHC(0xeff5), SHC(0x8102), SHC(0xcd2a), SHC(0x8a87), - SHC(0xae69), SHC(0x9d60), SHC(0x9622), SHC(0xb80e), SHC(0x8644), SHC(0xd872), SHC(0x8010), SHC(0xfbfb), - SHC(0x8405), SHC(0x1fd5), SHC(0x91d3), SHC(0x4128), SHC(0xa861), SHC(0x5d4f), SHC(0xc5e4), SHC(0x720d), - SHC(0xe804), SHC(0x7dbc), SHC(0x0c0c), SHC(0x7f6f), SHC(0x2f1f), SHC(0x7703), SHC(0x4e74), SHC(0x6524), - SHC(0x7fff), SHC(0x0000), SHC(0x7ffc), SHC(0xfdfd), SHC(0x7ff0), SHC(0xfbfb), SHC(0x7fdc), SHC(0xf9f8), - SHC(0x7fbf), SHC(0xf7f6), SHC(0x7f9b), SHC(0xf5f5), SHC(0x7f6f), SHC(0xf3f4), SHC(0x7f3a), SHC(0xf1f4), - SHC(0x7efe), SHC(0xeff5), SHC(0x7eb9), SHC(0xedf7), SHC(0x7e6d), SHC(0xebfa), SHC(0x7e18), SHC(0xe9fe), - SHC(0x7dbc), SHC(0xe804), SHC(0x7d57), SHC(0xe60b), SHC(0x7ceb), SHC(0xe414), SHC(0x7c77), SHC(0xe21e), - SHC(0x7bfb), SHC(0xe02b), SHC(0x7b77), SHC(0xde39), SHC(0x7aeb), SHC(0xdc4a), SHC(0x7a57), SHC(0xda5d), - SHC(0x7fff), SHC(0x0000), SHC(0x7fdc), SHC(0xf9f8), SHC(0x7f6f), SHC(0xf3f4), SHC(0x7eb9), SHC(0xedf7), - SHC(0x7dbc), SHC(0xe804), SHC(0x7c77), SHC(0xe21e), SHC(0x7aeb), SHC(0xdc4a), SHC(0x7919), SHC(0xd68a), - SHC(0x7703), SHC(0xd0e1), SHC(0x74a9), SHC(0xcb53), SHC(0x720d), SHC(0xc5e4), SHC(0x6f2f), SHC(0xc095), - SHC(0x6c13), SHC(0xbb6a), SHC(0x68b9), SHC(0xb666), SHC(0x6524), SHC(0xb18c), SHC(0x6155), SHC(0xacdf), - SHC(0x5d4f), SHC(0xa861), SHC(0x5914), SHC(0xa414), SHC(0x54a6), SHC(0x9ffc), SHC(0x5008), SHC(0x9c1b), - SHC(0x7fff), SHC(0x0000), SHC(0x7f9b), SHC(0xf5f5), SHC(0x7e6d), SHC(0xebfa), SHC(0x7c77), SHC(0xe21e), - SHC(0x79bc), SHC(0xd872), SHC(0x7642), SHC(0xcf04), SHC(0x720d), SHC(0xc5e4), SHC(0x6d23), SHC(0xbd1f), - SHC(0x678e), SHC(0xb4c3), SHC(0x6155), SHC(0xacdf), SHC(0x5a82), SHC(0xa57e), SHC(0x5321), SHC(0x9eab), - SHC(0x4b3d), SHC(0x9872), SHC(0x42e1), SHC(0x92dd), SHC(0x3a1c), SHC(0x8df3), SHC(0x30fc), SHC(0x89be), - SHC(0x278e), SHC(0x8644), SHC(0x1de2), SHC(0x8389), SHC(0x1406), SHC(0x8193), SHC(0x0a0b), SHC(0x8065), - SHC(0x7fff), SHC(0x0000), SHC(0x7f3a), SHC(0xf1f4), SHC(0x7ceb), SHC(0xe414), SHC(0x7919), SHC(0xd68a), - SHC(0x73d1), SHC(0xc980), SHC(0x6d23), SHC(0xbd1f), SHC(0x6524), SHC(0xb18c), SHC(0x5bec), SHC(0xa6ec), - SHC(0x5197), SHC(0x9d60), SHC(0x4646), SHC(0x9504), SHC(0x3a1c), SHC(0x8df3), SHC(0x2d3f), SHC(0x8843), - SHC(0x1fd5), SHC(0x8405), SHC(0x1209), SHC(0x8147), SHC(0x0405), SHC(0x8010), SHC(0xf5f5), SHC(0x8065), - SHC(0xe804), SHC(0x8244), SHC(0xda5d), SHC(0x85a9), SHC(0xcd2a), SHC(0x8a87), SHC(0xc095), SHC(0x90d1), - SHC(0x7fff), SHC(0x0000), SHC(0x7eb9), SHC(0xedf7), SHC(0x7aeb), SHC(0xdc4a), SHC(0x74a9), SHC(0xcb53), - SHC(0x6c13), SHC(0xbb6a), SHC(0x6155), SHC(0xacdf), SHC(0x54a6), SHC(0x9ffc), SHC(0x4646), SHC(0x9504), - SHC(0x3680), SHC(0x8c2f), SHC(0x25a3), SHC(0x85a9), SHC(0x1406), SHC(0x8193), SHC(0x0203), SHC(0x8004), - SHC(0xeff5), SHC(0x8102), SHC(0xde39), SHC(0x8489), SHC(0xcd2a), SHC(0x8a87), SHC(0xbd1f), SHC(0x92dd), - SHC(0xae69), SHC(0x9d60), SHC(0xa154), SHC(0xa9db), SHC(0x9622), SHC(0xb80e), SHC(0x8d0d), SHC(0xc7b0), - SHC(0x7fff), SHC(0x0000), SHC(0x7e18), SHC(0xe9fe), SHC(0x786f), SHC(0xd4a4), SHC(0x6f2f), SHC(0xc095), - SHC(0x62a0), SHC(0xae69), SHC(0x5321), SHC(0x9eab), SHC(0x4128), SHC(0x91d3), SHC(0x2d3f), SHC(0x8843), - SHC(0x17fc), SHC(0x8244), SHC(0x0203), SHC(0x8004), SHC(0xebfa), SHC(0x8193), SHC(0xd68a), SHC(0x86e7), - SHC(0xc256), SHC(0x8fd5), SHC(0xaff8), SHC(0x9c1b), SHC(0x9ffc), SHC(0xab5a), SHC(0x92dd), SHC(0xbd1f), - SHC(0x88fd), SHC(0xd0e1), SHC(0x82a9), SHC(0xe60b), SHC(0x8010), SHC(0xfbfb), SHC(0x8147), SHC(0x1209), - SHC(0x7fff), SHC(0x0000), SHC(0x7d57), SHC(0xe60b), SHC(0x7579), SHC(0xcd2a), SHC(0x68b9), SHC(0xb666), - SHC(0x579f), SHC(0xa2b1), SHC(0x42e1), SHC(0x92dd), SHC(0x2b5c), SHC(0x8791), SHC(0x1209), SHC(0x8147), - SHC(0xf7f6), SHC(0x8041), SHC(0xde39), SHC(0x8489), SHC(0xc5e4), SHC(0x8df3), SHC(0xaff8), SHC(0x9c1b), - SHC(0x9d60), SHC(0xae69), SHC(0x8ee1), SHC(0xc41b), SHC(0x8515), SHC(0xdc4a), SHC(0x8065), SHC(0xf5f5), - SHC(0x8102), SHC(0x100b), SHC(0x86e7), SHC(0x2976), SHC(0x91d3), SHC(0x4128), SHC(0xa154), SHC(0x5625), - SHC(0x7fff), SHC(0x0000), SHC(0x7c77), SHC(0xe21e), SHC(0x720d), SHC(0xc5e4), SHC(0x6155), SHC(0xacdf), - SHC(0x4b3d), SHC(0x9872), SHC(0x30fc), SHC(0x89be), SHC(0x1406), SHC(0x8193), SHC(0xf5f5), SHC(0x8065), - SHC(0xd872), SHC(0x8644), SHC(0xbd1f), SHC(0x92dd), SHC(0xa57e), SHC(0xa57e), SHC(0x92dd), SHC(0xbd1f), - SHC(0x8644), SHC(0xd872), SHC(0x8065), SHC(0xf5f5), SHC(0x8193), SHC(0x1406), SHC(0x89be), SHC(0x30fc), - SHC(0x9872), SHC(0x4b3d), SHC(0xacdf), SHC(0x6155), SHC(0xc5e4), SHC(0x720d), SHC(0xe21e), SHC(0x7c77), - SHC(0x7fff), SHC(0x0000), SHC(0x7b77), SHC(0xde39), SHC(0x6e2d), SHC(0xbed8), SHC(0x5914), SHC(0xa414), - SHC(0x3daa), SHC(0x8fd5), SHC(0x1de2), SHC(0x8389), SHC(0xfbfb), SHC(0x8010), SHC(0xda5d), SHC(0x85a9), - SHC(0xbb6a), SHC(0x93ed), SHC(0xa154), SHC(0xa9db), SHC(0x8df3), SHC(0xc5e4), SHC(0x82a9), SHC(0xe60b), - SHC(0x8041), SHC(0x080a), SHC(0x86e7), SHC(0x2976), SHC(0x9622), SHC(0x47f2), SHC(0xacdf), SHC(0x6155), - SHC(0xc980), SHC(0x73d1), SHC(0xe9fe), SHC(0x7e18), SHC(0x0c0c), SHC(0x7f6f), SHC(0x2d3f), SHC(0x77bd), - SHC(0x7fff), SHC(0x0000), SHC(0x7a57), SHC(0xda5d), SHC(0x69de), SHC(0xb80e), SHC(0x5008), SHC(0x9c1b), - SHC(0x2f1f), SHC(0x88fd), SHC(0x0a0b), SHC(0x8065), SHC(0xe414), SHC(0x8315), SHC(0xc095), SHC(0x90d1), - SHC(0xa2b1), SHC(0xa861), SHC(0x8d0d), SHC(0xc7b0), SHC(0x8193), SHC(0xebfa), SHC(0x8147), SHC(0x1209), - SHC(0x8c2f), SHC(0x3680), SHC(0xa154), SHC(0x5625), SHC(0xbed8), SHC(0x6e2d), SHC(0xe21e), SHC(0x7c77), - SHC(0x080a), SHC(0x7fbf), SHC(0x2d3f), SHC(0x77bd), SHC(0x4e74), SHC(0x6524), SHC(0x68b9), SHC(0x499a) -}; - -const Word16 FFT_W64[(64 * 2) * 2] = -{ - 16384, 0, 16364, -804, 16305, -1606, 16207, -2404, - 16069, -3196, 15893, -3981, 15679, -4756, 15426, -5520, - 15137, -6270, 14811, -7005, 14449, -7723, 14053, -8423, - 13623, -9102, 13160, -9760, 12665, -10394, 12140, -11003, - 11585, -11585, 11003, -12140, 10394, -12665, 9760, -13160, - 9102, -13623, 8423, -14053, 7723, -14449, 7005, -14811, - 6270, -15137, 5520, -15426, 4756, -15679, 3981, -15893, - 3196, -16069, 2404, -16207, 1606, -16305, 804, -16364, - 0, -16384, -804, -16364, -1606, -16305, -2404, -16207, - -3196, -16069, -3981, -15893, -4756, -15679, -5520, -15426, - -6270, -15137, -7005, -14811, -7723, -14449, -8423, -14053, - -9102, -13623, -9760, -13160, -10394, -12665, -11003, -12140, - -11585, -11585, -12140, -11003, -12665, -10394, -13160, -9760, - -13623, -9102, -14053, -8423, -14449, -7723, -14811, -7005, - -15137, -6270, -15426, -5520, -15679, -4756, -15893, -3981, - -16069, -3196, -16207, -2404, -16305, -1606, -16364, -804, +const Word16 RotVector_400[2 * ( 400 - 20 )] = { + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7ff0 ), SHC( 0xfbfb ), SHC( 0x7fbf ), SHC( 0xf7f6 ), SHC( 0x7f6f ), SHC( 0xf3f4 ), + SHC( 0x7efe ), SHC( 0xeff5 ), SHC( 0x7e6d ), SHC( 0xebfa ), SHC( 0x7dbc ), SHC( 0xe804 ), SHC( 0x7ceb ), SHC( 0xe414 ), + SHC( 0x7bfb ), SHC( 0xe02b ), SHC( 0x7aeb ), SHC( 0xdc4a ), SHC( 0x79bc ), SHC( 0xd872 ), SHC( 0x786f ), SHC( 0xd4a4 ), + SHC( 0x7703 ), SHC( 0xd0e1 ), SHC( 0x7579 ), SHC( 0xcd2a ), SHC( 0x73d1 ), SHC( 0xc980 ), SHC( 0x720d ), SHC( 0xc5e4 ), + SHC( 0x702b ), SHC( 0xc256 ), SHC( 0x6e2d ), SHC( 0xbed8 ), SHC( 0x6c13 ), SHC( 0xbb6a ), SHC( 0x69de ), SHC( 0xb80e ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7fbf ), SHC( 0xf7f6 ), SHC( 0x7efe ), SHC( 0xeff5 ), SHC( 0x7dbc ), SHC( 0xe804 ), + SHC( 0x7bfb ), SHC( 0xe02b ), SHC( 0x79bc ), SHC( 0xd872 ), SHC( 0x7703 ), SHC( 0xd0e1 ), SHC( 0x73d1 ), SHC( 0xc980 ), + SHC( 0x702b ), SHC( 0xc256 ), SHC( 0x6c13 ), SHC( 0xbb6a ), SHC( 0x678e ), SHC( 0xb4c3 ), SHC( 0x62a0 ), SHC( 0xae69 ), + SHC( 0x5d4f ), SHC( 0xa861 ), SHC( 0x579f ), SHC( 0xa2b1 ), SHC( 0x5197 ), SHC( 0x9d60 ), SHC( 0x4b3d ), SHC( 0x9872 ), + SHC( 0x4496 ), SHC( 0x93ed ), SHC( 0x3daa ), SHC( 0x8fd5 ), SHC( 0x3680 ), SHC( 0x8c2f ), SHC( 0x2f1f ), SHC( 0x88fd ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7f6f ), SHC( 0xf3f4 ), SHC( 0x7dbc ), SHC( 0xe804 ), SHC( 0x7aeb ), SHC( 0xdc4a ), + SHC( 0x7703 ), SHC( 0xd0e1 ), SHC( 0x720d ), SHC( 0xc5e4 ), SHC( 0x6c13 ), SHC( 0xbb6a ), SHC( 0x6524 ), SHC( 0xb18c ), + SHC( 0x5d4f ), SHC( 0xa861 ), SHC( 0x54a6 ), SHC( 0x9ffc ), SHC( 0x4b3d ), SHC( 0x9872 ), SHC( 0x4128 ), SHC( 0x91d3 ), + SHC( 0x3680 ), SHC( 0x8c2f ), SHC( 0x2b5c ), SHC( 0x8791 ), SHC( 0x1fd5 ), SHC( 0x8405 ), SHC( 0x1406 ), SHC( 0x8193 ), + SHC( 0x080a ), SHC( 0x8041 ), SHC( 0xfbfb ), SHC( 0x8010 ), SHC( 0xeff5 ), SHC( 0x8102 ), SHC( 0xe414 ), SHC( 0x8315 ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7efe ), SHC( 0xeff5 ), SHC( 0x7bfb ), SHC( 0xe02b ), SHC( 0x7703 ), SHC( 0xd0e1 ), + SHC( 0x702b ), SHC( 0xc256 ), SHC( 0x678e ), SHC( 0xb4c3 ), SHC( 0x5d4f ), SHC( 0xa861 ), SHC( 0x5197 ), SHC( 0x9d60 ), + SHC( 0x4496 ), SHC( 0x93ed ), SHC( 0x3680 ), SHC( 0x8c2f ), SHC( 0x278e ), SHC( 0x8644 ), SHC( 0x17fc ), SHC( 0x8244 ), + SHC( 0x080a ), SHC( 0x8041 ), SHC( 0xf7f6 ), SHC( 0x8041 ), SHC( 0xe804 ), SHC( 0x8244 ), SHC( 0xd872 ), SHC( 0x8644 ), + SHC( 0xc980 ), SHC( 0x8c2f ), SHC( 0xbb6a ), SHC( 0x93ed ), SHC( 0xae69 ), SHC( 0x9d60 ), SHC( 0xa2b1 ), SHC( 0xa861 ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7e6d ), SHC( 0xebfa ), SHC( 0x79bc ), SHC( 0xd872 ), SHC( 0x720d ), SHC( 0xc5e4 ), + SHC( 0x678e ), SHC( 0xb4c3 ), SHC( 0x5a82 ), SHC( 0xa57e ), SHC( 0x4b3d ), SHC( 0x9872 ), SHC( 0x3a1c ), SHC( 0x8df3 ), + SHC( 0x278e ), SHC( 0x8644 ), SHC( 0x1406 ), SHC( 0x8193 ), SHC( 0x0000 ), SHC( 0x8000 ), SHC( 0xebfa ), SHC( 0x8193 ), + SHC( 0xd872 ), SHC( 0x8644 ), SHC( 0xc5e4 ), SHC( 0x8df3 ), SHC( 0xb4c3 ), SHC( 0x9872 ), SHC( 0xa57e ), SHC( 0xa57e ), + SHC( 0x9872 ), SHC( 0xb4c3 ), SHC( 0x8df3 ), SHC( 0xc5e4 ), SHC( 0x8644 ), SHC( 0xd872 ), SHC( 0x8193 ), SHC( 0xebfa ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7dbc ), SHC( 0xe804 ), SHC( 0x7703 ), SHC( 0xd0e1 ), SHC( 0x6c13 ), SHC( 0xbb6a ), + SHC( 0x5d4f ), SHC( 0xa861 ), SHC( 0x4b3d ), SHC( 0x9872 ), SHC( 0x3680 ), SHC( 0x8c2f ), SHC( 0x1fd5 ), SHC( 0x8405 ), + SHC( 0x080a ), SHC( 0x8041 ), SHC( 0xeff5 ), SHC( 0x8102 ), SHC( 0xd872 ), SHC( 0x8644 ), SHC( 0xc256 ), SHC( 0x8fd5 ), + SHC( 0xae69 ), SHC( 0x9d60 ), SHC( 0x9d60 ), SHC( 0xae69 ), SHC( 0x8fd5 ), SHC( 0xc256 ), SHC( 0x8644 ), SHC( 0xd872 ), + SHC( 0x8102 ), SHC( 0xeff5 ), SHC( 0x8041 ), SHC( 0x080a ), SHC( 0x8405 ), SHC( 0x1fd5 ), SHC( 0x8c2f ), SHC( 0x3680 ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7ceb ), SHC( 0xe414 ), SHC( 0x73d1 ), SHC( 0xc980 ), SHC( 0x6524 ), SHC( 0xb18c ), + SHC( 0x5197 ), SHC( 0x9d60 ), SHC( 0x3a1c ), SHC( 0x8df3 ), SHC( 0x1fd5 ), SHC( 0x8405 ), SHC( 0x0405 ), SHC( 0x8010 ), + SHC( 0xe804 ), SHC( 0x8244 ), SHC( 0xcd2a ), SHC( 0x8a87 ), SHC( 0xb4c3 ), SHC( 0x9872 ), SHC( 0x9ffc ), SHC( 0xab5a ), + SHC( 0x8fd5 ), SHC( 0xc256 ), SHC( 0x8515 ), SHC( 0xdc4a ), SHC( 0x8041 ), SHC( 0xf7f6 ), SHC( 0x8193 ), SHC( 0x1406 ), + SHC( 0x88fd ), SHC( 0x2f1f ), SHC( 0x9622 ), SHC( 0x47f2 ), SHC( 0xa861 ), SHC( 0x5d4f ), SHC( 0xbed8 ), SHC( 0x6e2d ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7bfb ), SHC( 0xe02b ), SHC( 0x702b ), SHC( 0xc256 ), SHC( 0x5d4f ), SHC( 0xa861 ), + SHC( 0x4496 ), SHC( 0x93ed ), SHC( 0x278e ), SHC( 0x8644 ), SHC( 0x080a ), SHC( 0x8041 ), SHC( 0xe804 ), SHC( 0x8244 ), + SHC( 0xc980 ), SHC( 0x8c2f ), SHC( 0xae69 ), SHC( 0x9d60 ), SHC( 0x9872 ), SHC( 0xb4c3 ), SHC( 0x88fd ), SHC( 0xd0e1 ), + SHC( 0x8102 ), SHC( 0xeff5 ), SHC( 0x8102 ), SHC( 0x100b ), SHC( 0x88fd ), SHC( 0x2f1f ), SHC( 0x9872 ), SHC( 0x4b3d ), + SHC( 0xae69 ), SHC( 0x62a0 ), SHC( 0xc980 ), SHC( 0x73d1 ), SHC( 0xe804 ), SHC( 0x7dbc ), SHC( 0x080a ), SHC( 0x7fbf ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7aeb ), SHC( 0xdc4a ), SHC( 0x6c13 ), SHC( 0xbb6a ), SHC( 0x54a6 ), SHC( 0x9ffc ), + SHC( 0x3680 ), SHC( 0x8c2f ), SHC( 0x1406 ), SHC( 0x8193 ), SHC( 0xeff5 ), SHC( 0x8102 ), SHC( 0xcd2a ), SHC( 0x8a87 ), + SHC( 0xae69 ), SHC( 0x9d60 ), SHC( 0x9622 ), SHC( 0xb80e ), SHC( 0x8644 ), SHC( 0xd872 ), SHC( 0x8010 ), SHC( 0xfbfb ), + SHC( 0x8405 ), SHC( 0x1fd5 ), SHC( 0x91d3 ), SHC( 0x4128 ), SHC( 0xa861 ), SHC( 0x5d4f ), SHC( 0xc5e4 ), SHC( 0x720d ), + SHC( 0xe804 ), SHC( 0x7dbc ), SHC( 0x0c0c ), SHC( 0x7f6f ), SHC( 0x2f1f ), SHC( 0x7703 ), SHC( 0x4e74 ), SHC( 0x6524 ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7ffc ), SHC( 0xfdfd ), SHC( 0x7ff0 ), SHC( 0xfbfb ), SHC( 0x7fdc ), SHC( 0xf9f8 ), + SHC( 0x7fbf ), SHC( 0xf7f6 ), SHC( 0x7f9b ), SHC( 0xf5f5 ), SHC( 0x7f6f ), SHC( 0xf3f4 ), SHC( 0x7f3a ), SHC( 0xf1f4 ), + SHC( 0x7efe ), SHC( 0xeff5 ), SHC( 0x7eb9 ), SHC( 0xedf7 ), SHC( 0x7e6d ), SHC( 0xebfa ), SHC( 0x7e18 ), SHC( 0xe9fe ), + SHC( 0x7dbc ), SHC( 0xe804 ), SHC( 0x7d57 ), SHC( 0xe60b ), SHC( 0x7ceb ), SHC( 0xe414 ), SHC( 0x7c77 ), SHC( 0xe21e ), + SHC( 0x7bfb ), SHC( 0xe02b ), SHC( 0x7b77 ), SHC( 0xde39 ), SHC( 0x7aeb ), SHC( 0xdc4a ), SHC( 0x7a57 ), SHC( 0xda5d ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7fdc ), SHC( 0xf9f8 ), SHC( 0x7f6f ), SHC( 0xf3f4 ), SHC( 0x7eb9 ), SHC( 0xedf7 ), + SHC( 0x7dbc ), SHC( 0xe804 ), SHC( 0x7c77 ), SHC( 0xe21e ), SHC( 0x7aeb ), SHC( 0xdc4a ), SHC( 0x7919 ), SHC( 0xd68a ), + SHC( 0x7703 ), SHC( 0xd0e1 ), SHC( 0x74a9 ), SHC( 0xcb53 ), SHC( 0x720d ), SHC( 0xc5e4 ), SHC( 0x6f2f ), SHC( 0xc095 ), + SHC( 0x6c13 ), SHC( 0xbb6a ), SHC( 0x68b9 ), SHC( 0xb666 ), SHC( 0x6524 ), SHC( 0xb18c ), SHC( 0x6155 ), SHC( 0xacdf ), + SHC( 0x5d4f ), SHC( 0xa861 ), SHC( 0x5914 ), SHC( 0xa414 ), SHC( 0x54a6 ), SHC( 0x9ffc ), SHC( 0x5008 ), SHC( 0x9c1b ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7f9b ), SHC( 0xf5f5 ), SHC( 0x7e6d ), SHC( 0xebfa ), SHC( 0x7c77 ), SHC( 0xe21e ), + SHC( 0x79bc ), SHC( 0xd872 ), SHC( 0x7642 ), SHC( 0xcf04 ), SHC( 0x720d ), SHC( 0xc5e4 ), SHC( 0x6d23 ), SHC( 0xbd1f ), + SHC( 0x678e ), SHC( 0xb4c3 ), SHC( 0x6155 ), SHC( 0xacdf ), SHC( 0x5a82 ), SHC( 0xa57e ), SHC( 0x5321 ), SHC( 0x9eab ), + SHC( 0x4b3d ), SHC( 0x9872 ), SHC( 0x42e1 ), SHC( 0x92dd ), SHC( 0x3a1c ), SHC( 0x8df3 ), SHC( 0x30fc ), SHC( 0x89be ), + SHC( 0x278e ), SHC( 0x8644 ), SHC( 0x1de2 ), SHC( 0x8389 ), SHC( 0x1406 ), SHC( 0x8193 ), SHC( 0x0a0b ), SHC( 0x8065 ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7f3a ), SHC( 0xf1f4 ), SHC( 0x7ceb ), SHC( 0xe414 ), SHC( 0x7919 ), SHC( 0xd68a ), + SHC( 0x73d1 ), SHC( 0xc980 ), SHC( 0x6d23 ), SHC( 0xbd1f ), SHC( 0x6524 ), SHC( 0xb18c ), SHC( 0x5bec ), SHC( 0xa6ec ), + SHC( 0x5197 ), SHC( 0x9d60 ), SHC( 0x4646 ), SHC( 0x9504 ), SHC( 0x3a1c ), SHC( 0x8df3 ), SHC( 0x2d3f ), SHC( 0x8843 ), + SHC( 0x1fd5 ), SHC( 0x8405 ), SHC( 0x1209 ), SHC( 0x8147 ), SHC( 0x0405 ), SHC( 0x8010 ), SHC( 0xf5f5 ), SHC( 0x8065 ), + SHC( 0xe804 ), SHC( 0x8244 ), SHC( 0xda5d ), SHC( 0x85a9 ), SHC( 0xcd2a ), SHC( 0x8a87 ), SHC( 0xc095 ), SHC( 0x90d1 ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7eb9 ), SHC( 0xedf7 ), SHC( 0x7aeb ), SHC( 0xdc4a ), SHC( 0x74a9 ), SHC( 0xcb53 ), + SHC( 0x6c13 ), SHC( 0xbb6a ), SHC( 0x6155 ), SHC( 0xacdf ), SHC( 0x54a6 ), SHC( 0x9ffc ), SHC( 0x4646 ), SHC( 0x9504 ), + SHC( 0x3680 ), SHC( 0x8c2f ), SHC( 0x25a3 ), SHC( 0x85a9 ), SHC( 0x1406 ), SHC( 0x8193 ), SHC( 0x0203 ), SHC( 0x8004 ), + SHC( 0xeff5 ), SHC( 0x8102 ), SHC( 0xde39 ), SHC( 0x8489 ), SHC( 0xcd2a ), SHC( 0x8a87 ), SHC( 0xbd1f ), SHC( 0x92dd ), + SHC( 0xae69 ), SHC( 0x9d60 ), SHC( 0xa154 ), SHC( 0xa9db ), SHC( 0x9622 ), SHC( 0xb80e ), SHC( 0x8d0d ), SHC( 0xc7b0 ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7e18 ), SHC( 0xe9fe ), SHC( 0x786f ), SHC( 0xd4a4 ), SHC( 0x6f2f ), SHC( 0xc095 ), + SHC( 0x62a0 ), SHC( 0xae69 ), SHC( 0x5321 ), SHC( 0x9eab ), SHC( 0x4128 ), SHC( 0x91d3 ), SHC( 0x2d3f ), SHC( 0x8843 ), + SHC( 0x17fc ), SHC( 0x8244 ), SHC( 0x0203 ), SHC( 0x8004 ), SHC( 0xebfa ), SHC( 0x8193 ), SHC( 0xd68a ), SHC( 0x86e7 ), + SHC( 0xc256 ), SHC( 0x8fd5 ), SHC( 0xaff8 ), SHC( 0x9c1b ), SHC( 0x9ffc ), SHC( 0xab5a ), SHC( 0x92dd ), SHC( 0xbd1f ), + SHC( 0x88fd ), SHC( 0xd0e1 ), SHC( 0x82a9 ), SHC( 0xe60b ), SHC( 0x8010 ), SHC( 0xfbfb ), SHC( 0x8147 ), SHC( 0x1209 ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7d57 ), SHC( 0xe60b ), SHC( 0x7579 ), SHC( 0xcd2a ), SHC( 0x68b9 ), SHC( 0xb666 ), + SHC( 0x579f ), SHC( 0xa2b1 ), SHC( 0x42e1 ), SHC( 0x92dd ), SHC( 0x2b5c ), SHC( 0x8791 ), SHC( 0x1209 ), SHC( 0x8147 ), + SHC( 0xf7f6 ), SHC( 0x8041 ), SHC( 0xde39 ), SHC( 0x8489 ), SHC( 0xc5e4 ), SHC( 0x8df3 ), SHC( 0xaff8 ), SHC( 0x9c1b ), + SHC( 0x9d60 ), SHC( 0xae69 ), SHC( 0x8ee1 ), SHC( 0xc41b ), SHC( 0x8515 ), SHC( 0xdc4a ), SHC( 0x8065 ), SHC( 0xf5f5 ), + SHC( 0x8102 ), SHC( 0x100b ), SHC( 0x86e7 ), SHC( 0x2976 ), SHC( 0x91d3 ), SHC( 0x4128 ), SHC( 0xa154 ), SHC( 0x5625 ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7c77 ), SHC( 0xe21e ), SHC( 0x720d ), SHC( 0xc5e4 ), SHC( 0x6155 ), SHC( 0xacdf ), + SHC( 0x4b3d ), SHC( 0x9872 ), SHC( 0x30fc ), SHC( 0x89be ), SHC( 0x1406 ), SHC( 0x8193 ), SHC( 0xf5f5 ), SHC( 0x8065 ), + SHC( 0xd872 ), SHC( 0x8644 ), SHC( 0xbd1f ), SHC( 0x92dd ), SHC( 0xa57e ), SHC( 0xa57e ), SHC( 0x92dd ), SHC( 0xbd1f ), + SHC( 0x8644 ), SHC( 0xd872 ), SHC( 0x8065 ), SHC( 0xf5f5 ), SHC( 0x8193 ), SHC( 0x1406 ), SHC( 0x89be ), SHC( 0x30fc ), + SHC( 0x9872 ), SHC( 0x4b3d ), SHC( 0xacdf ), SHC( 0x6155 ), SHC( 0xc5e4 ), SHC( 0x720d ), SHC( 0xe21e ), SHC( 0x7c77 ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7b77 ), SHC( 0xde39 ), SHC( 0x6e2d ), SHC( 0xbed8 ), SHC( 0x5914 ), SHC( 0xa414 ), + SHC( 0x3daa ), SHC( 0x8fd5 ), SHC( 0x1de2 ), SHC( 0x8389 ), SHC( 0xfbfb ), SHC( 0x8010 ), SHC( 0xda5d ), SHC( 0x85a9 ), + SHC( 0xbb6a ), SHC( 0x93ed ), SHC( 0xa154 ), SHC( 0xa9db ), SHC( 0x8df3 ), SHC( 0xc5e4 ), SHC( 0x82a9 ), SHC( 0xe60b ), + SHC( 0x8041 ), SHC( 0x080a ), SHC( 0x86e7 ), SHC( 0x2976 ), SHC( 0x9622 ), SHC( 0x47f2 ), SHC( 0xacdf ), SHC( 0x6155 ), + SHC( 0xc980 ), SHC( 0x73d1 ), SHC( 0xe9fe ), SHC( 0x7e18 ), SHC( 0x0c0c ), SHC( 0x7f6f ), SHC( 0x2d3f ), SHC( 0x77bd ), + SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7a57 ), SHC( 0xda5d ), SHC( 0x69de ), SHC( 0xb80e ), SHC( 0x5008 ), SHC( 0x9c1b ), + SHC( 0x2f1f ), SHC( 0x88fd ), SHC( 0x0a0b ), SHC( 0x8065 ), SHC( 0xe414 ), SHC( 0x8315 ), SHC( 0xc095 ), SHC( 0x90d1 ), + SHC( 0xa2b1 ), SHC( 0xa861 ), SHC( 0x8d0d ), SHC( 0xc7b0 ), SHC( 0x8193 ), SHC( 0xebfa ), SHC( 0x8147 ), SHC( 0x1209 ), + SHC( 0x8c2f ), SHC( 0x3680 ), SHC( 0xa154 ), SHC( 0x5625 ), SHC( 0xbed8 ), SHC( 0x6e2d ), SHC( 0xe21e ), SHC( 0x7c77 ), + SHC( 0x080a ), SHC( 0x7fbf ), SHC( 0x2d3f ), SHC( 0x77bd ), SHC( 0x4e74 ), SHC( 0x6524 ), SHC( 0x68b9 ), SHC( 0x499a ) +}; + +const Word16 FFT_W64[( 64 * 2 ) * 2] = { + 16384, 0, 16364, -804, 16305, -1606, 16207, -2404, + 16069, -3196, 15893, -3981, 15679, -4756, 15426, -5520, + 15137, -6270, 14811, -7005, 14449, -7723, 14053, -8423, + 13623, -9102, 13160, -9760, 12665, -10394, 12140, -11003, + 11585, -11585, 11003, -12140, 10394, -12665, 9760, -13160, + 9102, -13623, 8423, -14053, 7723, -14449, 7005, -14811, + 6270, -15137, 5520, -15426, 4756, -15679, 3981, -15893, + 3196, -16069, 2404, -16207, 1606, -16305, 804, -16364, + 0, -16384, -804, -16364, -1606, -16305, -2404, -16207, + -3196, -16069, -3981, -15893, -4756, -15679, -5520, -15426, + -6270, -15137, -7005, -14811, -7723, -14449, -8423, -14053, + -9102, -13623, -9760, -13160, -10394, -12665, -11003, -12140, + -11585, -11585, -12140, -11003, -12665, -10394, -13160, -9760, + -13623, -9102, -14053, -8423, -14449, -7723, -14811, -7005, + -15137, -6270, -15426, -5520, -15679, -4756, -15893, -3981, + -16069, -3196, -16207, -2404, -16305, -1606, -16364, -804, /* The following is a duplication of the above but scaled up by a factor of 2. * This save one operation in inverse FFT inner loops */ - 32767, 0, 32729, -1608, 32610, -3212, 32413, -4808, - 32138, -6393, 31786, -7962, 31357, -9512, 30853, -11039, - 30274, -12540, 29622, -14010, 28899, -15447, 28106, -16846, - 27246, -18205, 26320, -19520, 25330, -20788, 24279, -22006, - 23170, -23170, 22006, -24279, 20788, -25330, 19520, -26320, - 18205, -27246, 16846, -28106, 15447, -28899, 14010, -29622, - 12540, -30274, 11039, -30853, 9512, -31357, 7962, -31786, - 6393, -32138, 4808, -32413, 3212, -32610, 1608, -32729, - 0, -32768, -1608, -32729, -3212, -32610, -4808, -32413, - -6393, -32138, -7962, -31786, -9512, -31357, -11039, -30853, - -12540, -30274, -14010, -29622, -15447, -28899, -16846, -28106, - -18205, -27246, -19520, -26320, -20788, -25330, -22006, -24279, - -23170, -23170, -24279, -22006, -25330, -20788, -26320, -19520, - -27246, -18205, -28106, -16846, -28899, -15447, -29622, -14010, - -30274, -12540, -30853, -11039, -31357, -9512, -31786, -7962, - -32138, -6393, -32413, -4808, -32610, -3212, -32729, -1608 -}; - -const Word16 FFT_W128[] = -{ - /* part of table that is not scaled by 2 */ - 16384, 0, 16379, -402, 16364, -804, 16339, -1205, - 16305, -1606, 16260, -2006, 16206, -2404, 16142, -2801, - 16069, -3196, 15985, -3590, 15893, -3981, 15790, -4370, - 15678, -4756, 15557, -5139, 15426, -5519, 15286, -5896, - 15136, -6270, 14978, -6639, 14811, -7005, 14634, -7366, - 14449, -7723, 14255, -8075, 14053, -8423, 13842, -8765, - 13622, -9102, 13395, -9434, 13159, -9760, 12916, -10080, - 12665, -10394, 12406, -10701, 12139, -11002, 11866, -11297, - 11585, -11585, 11297, -11866, 11002, -12139, 10701, -12406, - 10394, -12665, 10080, -12916, 9760, -13159, 9434, -13395, - 9102, -13622, 8765, -13842, 8423, -14053, 8075, -14255, - 7723, -14449, 7366, -14634, 7005, -14811, 6639, -14978, - 6270, -15136, 5896, -15286, 5519, -15426, 5139, -15557, - 4756, -15678, 4370, -15790, 3981, -15893, 3590, -15985, - 3196, -16069, 2801, -16142, 2404, -16206, 2006, -16260, - 1606, -16305, 1205, -16339, 804, -16364, 402, -16379, - 0, -16384, -402, -16379, -804, -16364, -1205, -16339, - -1606, -16305, -2006, -16260, -2404, -16206, -2801, -16142, - -3196, -16069, -3590, -15985, -3981, -15893, -4370, -15790, - -4756, -15678, -5139, -15557, -5519, -15426, -5896, -15286, - -6270, -15136, -6639, -14978, -7005, -14811, -7366, -14634, - -7723, -14449, -8075, -14255, -8423, -14053, -8765, -13842, - -9102, -13622, -9434, -13395, -9760, -13159, -10080, -12916, - -10394, -12665, -10701, -12406, -11002, -12139, -11297, -11866, - -11585, -11585, -11866, -11297, -12139, -11002, -12406, -10701, - -12665, -10394, -12916, -10080, -13159, -9760, -13395, -9434, - -13622, -9102, -13842, -8765, -14053, -8423, -14255, -8075, - -14449, -7723, -14634, -7366, -14811, -7005, -14978, -6639, - -15136, -6270, -15286, -5896, -15426, -5519, -15557, -5139, - -15678, -4756, -15790, -4370, -15893, -3981, -15985, -3590, - -16069, -3196, -16142, -2801, -16206, -2404, -16260, -2006, - -16305, -1606, -16339, -1205, -16364, -804, -16379, -402, - /* part of table that is scaled by 2 (this save one operation in FFT inner loops) */ - 32767, 0, 32758, -804, 32728, -1608, 32678, -2410, - 32610, -3212, 32520, -4012, 32412, -4808, 32284, -5602, - 32138, -6392, 31970, -7180, 31786, -7962, 31580, -8740, - 31356, -9512, 31114, -10278, 30852, -11038, 30572, -11792, - 30272, -12540, 29956, -13278, 29622, -14010, 29268, -14732, - 28898, -15446, 28510, -16150, 28106, -16846, 27684, -17530, - 27244, -18204, 26790, -18868, 26318, -19520, 25832, -20160, - 25330, -20788, 24812, -21402, 24278, -22004, 23732, -22594, - 23170, -23170, 22594, -23732, 22004, -24278, 21402, -24812, - 20788, -25330, 20160, -25832, 19520, -26318, 18868, -26790, - 18204, -27244, 17530, -27684, 16846, -28106, 16150, -28510, - 15446, -28898, 14732, -29268, 14010, -29622, 13278, -29956, - 12540, -30272, 11792, -30572, 11038, -30852, 10278, -31114, - 9512, -31356, 8740, -31580, 7962, -31786, 7180, -31970, - 6392, -32138, 5602, -32284, 4808, -32412, 4012, -32520, - 3212, -32610, 2410, -32678, 1608, -32728, 804, -32758, - 0, -32768, -804, -32758, -1608, -32728, -2410, -32678, - -3212, -32610, -4012, -32520, -4808, -32412, -5602, -32284, - -6392, -32138, -7180, -31970, -7962, -31786, -8740, -31580, - -9512, -31356, -10278, -31114, -11038, -30852, -11792, -30572, - -12540, -30272, -13278, -29956, -14010, -29622, -14732, -29268, - -15446, -28898, -16150, -28510, -16846, -28106, -17530, -27684, - -18204, -27244, -18868, -26790, -19520, -26318, -20160, -25832, - -20788, -25330, -21402, -24812, -22004, -24278, -22594, -23732, - -23170, -23170, -23732, -22594, -24278, -22004, -24812, -21402, - -25330, -20788, -25832, -20160, -26318, -19520, -26790, -18868, - -27244, -18204, -27684, -17530, -28106, -16846, -28510, -16150, - -28898, -15446, -29268, -14732, -29622, -14010, -29956, -13278, - -30272, -12540, -30572, -11792, -30852, -11038, -31114, -10278, - -31356, -9512, -31580, -8740, -31786, -7962, -31970, -7180, - -32138, -6392, -32284, -5602, -32412, -4808, -32520, -4012, - -32610, -3212, -32678, -2410, -32728, -1608, -32758, -804 -}; - -const Word16 FFT_W256[(256 * 2) * 2] = -{ - /* Each adjacent pair represents the real and imaginary part of a complex number: */ - /* W = exp{-j*(PI*n/256)} = cos(PI*n/256)*16384 -j*sin(PI*n/256)*16384 for n=0, 1, ..., 255. */ - 16384, 0, 16383, -201, 16379, -402, 16373, -603, - 16364, -804, 16353, -1005, 16340, -1205, 16324, -1406, - 16305, -1606, 16284, -1806, 16261, -2006, 16235, -2205, - 16207, -2404, 16176, -2603, 16143, -2801, 16107, -2999, - 16069, -3196, 16029, -3393, 15986, -3590, 15941, -3786, - 15893, -3981, 15843, -4176, 15791, -4370, 15736, -4563, - 15679, -4756, 15619, -4948, 15557, -5139, 15493, -5330, - 15426, -5520, 15357, -5708, 15286, -5897, 15213, -6084, - 15137, -6270, 15059, -6455, 14978, -6639, 14896, -6823, - 14811, -7005, 14724, -7186, 14635, -7366, 14543, -7545, - 14449, -7723, 14354, -7900, 14256, -8076, 14155, -8250, - 14053, -8423, 13949, -8595, 13842, -8765, 13733, -8935, - 13623, -9102, 13510, -9269, 13395, -9434, 13279, -9598, - 13160, -9760, 13039, -9921, 12916, -10080, 12792, -10238, - 12665, -10394, 12537, -10549, 12406, -10702, 12274, -10853, - 12140, -11003, 12004, -11151, 11866, -11297, 11727, -11442, - 11585, -11585, 11442, -11727, 11297, -11866, 11151, -12004, - 11003, -12140, 10853, -12274, 10702, -12406, 10549, -12537, - 10394, -12665, 10238, -12792, 10080, -12916, 9921, -13039, - 9760, -13160, 9598, -13279, 9434, -13395, 9269, -13510, - 9102, -13623, 8935, -13733, 8765, -13842, 8595, -13949, - 8423, -14053, 8250, -14155, 8076, -14256, 7900, -14354, - 7723, -14449, 7545, -14543, 7366, -14635, 7186, -14724, - 7005, -14811, 6823, -14896, 6639, -14978, 6455, -15059, - 6270, -15137, 6084, -15213, 5897, -15286, 5708, -15357, - 5520, -15426, 5330, -15493, 5139, -15557, 4948, -15619, - 4756, -15679, 4563, -15736, 4370, -15791, 4176, -15843, - 3981, -15893, 3786, -15941, 3590, -15986, 3393, -16029, - 3196, -16069, 2999, -16107, 2801, -16143, 2603, -16176, - 2404, -16207, 2205, -16235, 2006, -16261, 1806, -16284, - 1606, -16305, 1406, -16324, 1205, -16340, 1005, -16353, - 804, -16364, 603, -16373, 402, -16379, 201, -16383, - 0, -16384, -201, -16383, -402, -16379, -603, -16373, - -804, -16364, -1005, -16353, -1205, -16340, -1406, -16324, - -1606, -16305, -1806, -16284, -2006, -16261, -2205, -16235, - -2404, -16207, -2603, -16176, -2801, -16143, -2999, -16107, - -3196, -16069, -3393, -16029, -3590, -15986, -3786, -15941, - -3981, -15893, -4176, -15843, -4370, -15791, -4563, -15736, - -4756, -15679, -4948, -15619, -5139, -15557, -5330, -15493, - -5520, -15426, -5708, -15357, -5897, -15286, -6084, -15213, - -6270, -15137, -6455, -15059, -6639, -14978, -6823, -14896, - -7005, -14811, -7186, -14724, -7366, -14635, -7545, -14543, - -7723, -14449, -7900, -14354, -8076, -14256, -8250, -14155, - -8423, -14053, -8595, -13949, -8765, -13842, -8935, -13733, - -9102, -13623, -9269, -13510, -9434, -13395, -9598, -13279, - -9760, -13160, -9921, -13039, -10080, -12916, -10238, -12792, - -10394, -12665, -10549, -12537, -10702, -12406, -10853, -12274, - -11003, -12140, -11151, -12004, -11297, -11866, -11442, -11727, - -11585, -11585, -11727, -11442, -11866, -11297, -12004, -11151, - -12140, -11003, -12274, -10853, -12406, -10702, -12537, -10549, - -12665, -10394, -12792, -10238, -12916, -10080, -13039, -9921, - -13160, -9760, -13279, -9598, -13395, -9434, -13510, -9269, - -13623, -9102, -13733, -8935, -13842, -8765, -13949, -8595, - -14053, -8423, -14155, -8250, -14256, -8076, -14354, -7900, - -14449, -7723, -14543, -7545, -14635, -7366, -14724, -7186, - -14811, -7005, -14896, -6823, -14978, -6639, -15059, -6455, - -15137, -6270, -15213, -6084, -15286, -5897, -15357, -5708, - -15426, -5520, -15493, -5330, -15557, -5139, -15619, -4948, - -15679, -4756, -15736, -4563, -15791, -4370, -15843, -4176, - -15893, -3981, -15941, -3786, -15986, -3590, -16029, -3393, - -16069, -3196, -16107, -2999, -16143, -2801, -16176, -2603, - -16207, -2404, -16235, -2205, -16261, -2006, -16284, -1806, - -16305, -1606, -16324, -1406, -16340, -1205, -16353, -1005, - -16364, -804, -16373, -603, -16379, -402, -16383, -201, - - /* The following is a duplication of the above but scaled up by a factor of 2. - * This save one operation in inverse FFT inner loops */ - 32767, 0, 32766, -402, 32758, -804, 32746, -1206, - 32729, -1608, 32706, -2009, 32679, -2411, 32647, -2811, - 32610, -3212, 32568, -3612, 32522, -4011, 32470, -4410, - 32413, -4808, 32352, -5205, 32286, -5602, 32214, -5998, - 32138, -6393, 32058, -6787, 31972, -7180, 31881, -7571, - 31786, -7962, 31686, -8351, 31581, -8740, 31471, -9127, - 31357, -9512, 31238, -9896, 31114, -10279, 30986, -10660, - 30853, -11039, 30715, -11417, 30572, -11793, 30425, -12167, - 30274, -12540, 30118, -12910, 29957, -13279, 29792, -13646, - 29622, -14010, 29448, -14373, 29269, -14733, 29086, -15091, - 28899, -15447, 28707, -15800, 28511, -16151, 28311, -16500, - 28106, -16846, 27897, -17190, 27684, -17531, 27467, -17869, - 27246, -18205, 27020, -18538, 26791, -18868, 26557, -19195, - 26320, -19520, 26078, -19841, 25833, -20160, 25583, -20475, - 25330, -20788, 25073, -21097, 24812, -21403, 24548, -21706, - 24279, -22006, 24008, -22302, 23732, -22595, 23453, -22884, - 23170, -23170, 22884, -23453, 22595, -23732, 22302, -24008, - 22006, -24279, 21706, -24548, 21403, -24812, 21097, -25073, - 20788, -25330, 20475, -25583, 20160, -25833, 19841, -26078, - 19520, -26320, 19195, -26557, 18868, -26791, 18538, -27020, - 18205, -27246, 17869, -27467, 17531, -27684, 17190, -27897, - 16846, -28106, 16500, -28311, 16151, -28511, 15800, -28707, - 15447, -28899, 15091, -29086, 14733, -29269, 14373, -29448, - 14010, -29622, 13646, -29792, 13279, -29957, 12910, -30118, - 12540, -30274, 12167, -30425, 11793, -30572, 11417, -30715, - 11039, -30853, 10660, -30986, 10279, -31114, 9896, -31238, - 9512, -31357, 9127, -31471, 8740, -31581, 8351, -31686, - 7962, -31786, 7571, -31881, 7180, -31972, 6787, -32058, - 6393, -32138, 5998, -32214, 5602, -32286, 5205, -32352, - 4808, -32413, 4410, -32470, 4011, -32522, 3612, -32568, - 3212, -32610, 2811, -32647, 2411, -32679, 2009, -32706, - 1608, -32729, 1206, -32746, 804, -32758, 402, -32766, - 0, -32768, -402, -32766, -804, -32758, -1206, -32746, - -1608, -32729, -2009, -32706, -2411, -32679, -2811, -32647, - -3212, -32610, -3612, -32568, -4011, -32522, -4410, -32470, - -4808, -32413, -5205, -32352, -5602, -32286, -5998, -32214, - -6393, -32138, -6787, -32058, -7180, -31972, -7571, -31881, - -7962, -31786, -8351, -31686, -8740, -31581, -9127, -31471, - -9512, -31357, -9896, -31238, -10279, -31114, -10660, -30986, - -11039, -30853, -11417, -30715, -11793, -30572, -12167, -30425, - -12540, -30274, -12910, -30118, -13279, -29957, -13646, -29792, - -14010, -29622, -14373, -29448, -14733, -29269, -15091, -29086, - -15447, -28899, -15800, -28707, -16151, -28511, -16500, -28311, - -16846, -28106, -17190, -27897, -17531, -27684, -17869, -27467, - -18205, -27246, -18538, -27020, -18868, -26791, -19195, -26557, - -19520, -26320, -19841, -26078, -20160, -25833, -20475, -25583, - -20788, -25330, -21097, -25073, -21403, -24812, -21706, -24548, - -22006, -24279, -22302, -24008, -22595, -23732, -22884, -23453, - -23170, -23170, -23453, -22884, -23732, -22595, -24008, -22302, - -24279, -22006, -24548, -21706, -24812, -21403, -25073, -21097, - -25330, -20788, -25583, -20475, -25833, -20160, -26078, -19841, - -26320, -19520, -26557, -19195, -26791, -18868, -27020, -18538, - -27246, -18205, -27467, -17869, -27684, -17531, -27897, -17190, - -28106, -16846, -28311, -16500, -28511, -16151, -28707, -15800, - -28899, -15447, -29086, -15091, -29269, -14733, -29448, -14373, - -29622, -14010, -29792, -13646, -29957, -13279, -30118, -12910, - -30274, -12540, -30425, -12167, -30572, -11793, -30715, -11417, - -30853, -11039, -30986, -10660, -31114, -10279, -31238, -9896, - -31357, -9512, -31471, -9127, -31581, -8740, -31686, -8351, - -31786, -7962, -31881, -7571, -31972, -7180, -32058, -6787, - -32138, -6393, -32214, -5998, -32286, -5602, -32352, -5205, - -32413, -4808, -32470, -4410, -32522, -4011, -32568, -3612, - -32610, -3212, -32647, -2811, -32679, -2411, -32706, -2009, - -32729, -1608, -32746, -1206, -32758, -804, -32766, -402 -}; - -const Word16 FFT_W512[(512 * 2) * 2] = -{ - 16384, 0, 16384, -101, 16383, -201, 16381, -302, - 16379, -402, 16376, -503, 16373, -603, 16369, -704, - 16364, -804, 16359, -904, 16353, -1005, 16347, -1105, - 16340, -1205, 16332, -1306, 16324, -1406, 16315, -1506, - 16305, -1606, 16295, -1706, 16284, -1806, 16273, -1906, - 16261, -2006, 16248, -2105, 16235, -2205, 16221, -2305, - 16207, -2404, 16192, -2503, 16176, -2603, 16160, -2702, - 16143, -2801, 16125, -2900, 16107, -2999, 16088, -3098, - 16069, -3196, 16049, -3295, 16029, -3393, 16008, -3492, - 15986, -3590, 15964, -3688, 15941, -3786, 15917, -3883, - 15893, -3981, 15868, -4078, 15843, -4176, 15817, -4273, - 15791, -4370, 15763, -4467, 15736, -4563, 15707, -4660, - 15679, -4756, 15649, -4852, 15619, -4948, 15588, -5044, - 15557, -5139, 15525, -5235, 15493, -5330, 15460, -5425, - 15426, -5520, 15392, -5614, 15357, -5708, 15322, -5803, - 15286, -5897, 15250, -5990, 15213, -6084, 15175, -6177, - 15137, -6270, 15098, -6363, 15059, -6455, 15019, -6547, - 14978, -6639, 14937, -6731, 14896, -6823, 14854, -6914, - 14811, -7005, 14768, -7096, 14724, -7186, 14680, -7276, - 14635, -7366, 14589, -7456, 14543, -7545, 14497, -7635, - 14449, -7723, 14402, -7812, 14354, -7900, 14305, -7988, - 14256, -8076, 14206, -8163, 14155, -8250, 14104, -8337, - 14053, -8423, 14001, -8509, 13949, -8595, 13896, -8680, - 13842, -8765, 13788, -8850, 13733, -8935, 13678, -9019, - 13623, -9102, 13567, -9186, 13510, -9269, 13453, -9352, - 13395, -9434, 13337, -9516, 13279, -9598, 13219, -9679, - 13160, -9760, 13100, -9841, 13039, -9921, 12978, -10001, - 12916, -10080, 12854, -10159, 12792, -10238, 12729, -10316, - 12665, -10394, 12601, -10471, 12537, -10549, 12472, -10625, - 12406, -10702, 12340, -10778, 12274, -10853, 12207, -10928, - 12140, -11003, 12072, -11077, 12004, -11151, 11935, -11224, - 11866, -11297, 11797, -11370, 11727, -11442, 11656, -11514, - 11585, -11585, 11514, -11656, 11442, -11727, 11370, -11797, - 11297, -11866, 11224, -11935, 11151, -12004, 11077, -12072, - 11003, -12140, 10928, -12207, 10853, -12274, 10778, -12340, - 10702, -12406, 10625, -12472, 10549, -12537, 10471, -12601, - 10394, -12665, 10316, -12729, 10238, -12792, 10159, -12854, - 10080, -12916, 10001, -12978, 9921, -13039, 9841, -13100, - 9760, -13160, 9679, -13219, 9598, -13279, 9516, -13337, - 9434, -13395, 9352, -13453, 9269, -13510, 9186, -13567, - 9102, -13623, 9019, -13678, 8935, -13733, 8850, -13788, - 8765, -13842, 8680, -13896, 8595, -13949, 8509, -14001, - 8423, -14053, 8337, -14104, 8250, -14155, 8163, -14206, - 8076, -14256, 7988, -14305, 7900, -14354, 7812, -14402, - 7723, -14449, 7635, -14497, 7545, -14543, 7456, -14589, - 7366, -14635, 7276, -14680, 7186, -14724, 7096, -14768, - 7005, -14811, 6914, -14854, 6823, -14896, 6731, -14937, - 6639, -14978, 6547, -15019, 6455, -15059, 6363, -15098, - 6270, -15137, 6177, -15175, 6084, -15213, 5990, -15250, - 5897, -15286, 5803, -15322, 5708, -15357, 5614, -15392, - 5520, -15426, 5425, -15460, 5330, -15493, 5235, -15525, - 5139, -15557, 5044, -15588, 4948, -15619, 4852, -15649, - 4756, -15679, 4660, -15707, 4563, -15736, 4467, -15763, - 4370, -15791, 4273, -15817, 4176, -15843, 4078, -15868, - 3981, -15893, 3883, -15917, 3786, -15941, 3688, -15964, - 3590, -15986, 3492, -16008, 3393, -16029, 3295, -16049, - 3196, -16069, 3098, -16088, 2999, -16107, 2900, -16125, - 2801, -16143, 2702, -16160, 2603, -16176, 2503, -16192, - 2404, -16207, 2305, -16221, 2205, -16235, 2105, -16248, - 2006, -16261, 1906, -16273, 1806, -16284, 1706, -16295, - 1606, -16305, 1506, -16315, 1406, -16324, 1306, -16332, - 1205, -16340, 1105, -16347, 1005, -16353, 904, -16359, - 804, -16364, 703, -16369, 603, -16373, 503, -16376, - 402, -16379, 302, -16381, 201, -16383, 101, -16384, - 0, -16384, -101, -16384, -201, -16383, -302, -16381, - -402, -16379, -503, -16376, -603, -16373, -704, -16369, - -804, -16364, -904, -16359, -1005, -16353, -1105, -16347, - -1205, -16340, -1306, -16332, -1406, -16324, -1506, -16315, - -1606, -16305, -1706, -16295, -1806, -16284, -1906, -16273, - -2006, -16261, -2105, -16248, -2205, -16235, -2305, -16221, - -2404, -16207, -2503, -16192, -2603, -16176, -2702, -16160, - -2801, -16143, -2900, -16125, -2999, -16107, -3098, -16088, - -3196, -16069, -3295, -16049, -3393, -16029, -3492, -16008, - -3590, -15986, -3688, -15964, -3786, -15941, -3883, -15917, - -3981, -15893, -4078, -15868, -4176, -15843, -4273, -15817, - -4370, -15791, -4467, -15763, -4563, -15736, -4660, -15707, - -4756, -15679, -4852, -15649, -4948, -15619, -5044, -15588, - -5139, -15557, -5235, -15525, -5330, -15493, -5425, -15460, - -5520, -15426, -5614, -15392, -5708, -15357, -5803, -15322, - -5897, -15286, -5990, -15250, -6084, -15213, -6177, -15175, - -6270, -15137, -6363, -15098, -6455, -15059, -6547, -15019, - -6639, -14978, -6731, -14937, -6823, -14896, -6914, -14854, - -7005, -14811, -7096, -14768, -7186, -14724, -7276, -14680, - -7366, -14635, -7456, -14589, -7545, -14543, -7635, -14497, - -7723, -14449, -7812, -14402, -7900, -14354, -7988, -14305, - -8076, -14256, -8163, -14206, -8250, -14155, -8337, -14104, - -8423, -14053, -8509, -14001, -8595, -13949, -8680, -13896, - -8765, -13842, -8850, -13788, -8935, -13733, -9019, -13678, - -9102, -13623, -9186, -13567, -9269, -13510, -9352, -13453, - -9434, -13395, -9516, -13337, -9598, -13279, -9679, -13219, - -9760, -13160, -9841, -13100, -9921, -13039, -10001, -12978, - -10080, -12916, -10159, -12854, -10238, -12792, -10316, -12729, - -10394, -12665, -10471, -12601, -10549, -12537, -10625, -12472, - -10702, -12406, -10778, -12340, -10853, -12274, -10928, -12207, - -11003, -12140, -11077, -12072, -11151, -12004, -11224, -11935, - -11297, -11866, -11370, -11797, -11442, -11727, -11514, -11656, - -11585, -11585, -11656, -11514, -11727, -11442, -11797, -11370, - -11866, -11297, -11935, -11224, -12004, -11151, -12072, -11077, - -12140, -11003, -12207, -10928, -12274, -10853, -12340, -10778, - -12406, -10702, -12472, -10625, -12537, -10549, -12601, -10471, - -12665, -10394, -12729, -10316, -12792, -10238, -12854, -10159, - -12916, -10080, -12978, -10001, -13039, -9921, -13100, -9840, - -13160, -9760, -13219, -9679, -13279, -9598, -13337, -9516, - -13395, -9434, -13453, -9352, -13510, -9269, -13567, -9186, - -13623, -9102, -13678, -9019, -13733, -8935, -13788, -8850, - -13842, -8765, -13896, -8680, -13949, -8595, -14001, -8509, - -14053, -8423, -14104, -8337, -14155, -8250, -14206, -8163, - -14256, -8076, -14305, -7988, -14354, -7900, -14402, -7812, - -14449, -7723, -14497, -7635, -14543, -7545, -14589, -7456, - -14635, -7366, -14680, -7276, -14724, -7186, -14768, -7096, - -14811, -7005, -14854, -6914, -14896, -6823, -14937, -6731, - -14978, -6639, -15019, -6547, -15059, -6455, -15098, -6363, - -15137, -6270, -15175, -6177, -15213, -6084, -15250, -5990, - -15286, -5897, -15322, -5803, -15357, -5708, -15392, -5614, - -15426, -5520, -15460, -5425, -15493, -5330, -15525, -5235, - -15557, -5139, -15588, -5044, -15619, -4948, -15649, -4852, - -15679, -4756, -15707, -4660, -15736, -4563, -15763, -4467, - -15791, -4370, -15817, -4273, -15843, -4176, -15868, -4078, - -15893, -3981, -15917, -3883, -15941, -3786, -15964, -3688, - -15986, -3590, -16008, -3492, -16029, -3393, -16049, -3295, - -16069, -3196, -16088, -3098, -16107, -2999, -16125, -2900, - -16143, -2801, -16160, -2702, -16176, -2603, -16192, -2503, - -16207, -2404, -16221, -2305, -16235, -2205, -16248, -2105, - -16261, -2006, -16273, -1906, -16284, -1806, -16295, -1706, - -16305, -1606, -16315, -1506, -16324, -1406, -16332, -1306, - -16340, -1205, -16347, -1105, -16353, -1005, -16359, -904, - -16364, -804, -16369, -703, -16373, -603, -16376, -503, - -16379, -402, -16381, -302, -16383, -201, -16384, -101, + 32767, 0, 32729, -1608, 32610, -3212, 32413, -4808, + 32138, -6393, 31786, -7962, 31357, -9512, 30853, -11039, + 30274, -12540, 29622, -14010, 28899, -15447, 28106, -16846, + 27246, -18205, 26320, -19520, 25330, -20788, 24279, -22006, + 23170, -23170, 22006, -24279, 20788, -25330, 19520, -26320, + 18205, -27246, 16846, -28106, 15447, -28899, 14010, -29622, + 12540, -30274, 11039, -30853, 9512, -31357, 7962, -31786, + 6393, -32138, 4808, -32413, 3212, -32610, 1608, -32729, + 0, -32768, -1608, -32729, -3212, -32610, -4808, -32413, + -6393, -32138, -7962, -31786, -9512, -31357, -11039, -30853, + -12540, -30274, -14010, -29622, -15447, -28899, -16846, -28106, + -18205, -27246, -19520, -26320, -20788, -25330, -22006, -24279, + -23170, -23170, -24279, -22006, -25330, -20788, -26320, -19520, + -27246, -18205, -28106, -16846, -28899, -15447, -29622, -14010, + -30274, -12540, -30853, -11039, -31357, -9512, -31786, -7962, + -32138, -6393, -32413, -4808, -32610, -3212, -32729, -1608 +}; + +const Word16 FFT_W128[] = { + /* part of table that is not scaled by 2 */ + 16384, 0, 16379, -402, 16364, -804, 16339, -1205, + 16305, -1606, 16260, -2006, 16206, -2404, 16142, -2801, + 16069, -3196, 15985, -3590, 15893, -3981, 15790, -4370, + 15678, -4756, 15557, -5139, 15426, -5519, 15286, -5896, + 15136, -6270, 14978, -6639, 14811, -7005, 14634, -7366, + 14449, -7723, 14255, -8075, 14053, -8423, 13842, -8765, + 13622, -9102, 13395, -9434, 13159, -9760, 12916, -10080, + 12665, -10394, 12406, -10701, 12139, -11002, 11866, -11297, + 11585, -11585, 11297, -11866, 11002, -12139, 10701, -12406, + 10394, -12665, 10080, -12916, 9760, -13159, 9434, -13395, + 9102, -13622, 8765, -13842, 8423, -14053, 8075, -14255, + 7723, -14449, 7366, -14634, 7005, -14811, 6639, -14978, + 6270, -15136, 5896, -15286, 5519, -15426, 5139, -15557, + 4756, -15678, 4370, -15790, 3981, -15893, 3590, -15985, + 3196, -16069, 2801, -16142, 2404, -16206, 2006, -16260, + 1606, -16305, 1205, -16339, 804, -16364, 402, -16379, + 0, -16384, -402, -16379, -804, -16364, -1205, -16339, + -1606, -16305, -2006, -16260, -2404, -16206, -2801, -16142, + -3196, -16069, -3590, -15985, -3981, -15893, -4370, -15790, + -4756, -15678, -5139, -15557, -5519, -15426, -5896, -15286, + -6270, -15136, -6639, -14978, -7005, -14811, -7366, -14634, + -7723, -14449, -8075, -14255, -8423, -14053, -8765, -13842, + -9102, -13622, -9434, -13395, -9760, -13159, -10080, -12916, + -10394, -12665, -10701, -12406, -11002, -12139, -11297, -11866, + -11585, -11585, -11866, -11297, -12139, -11002, -12406, -10701, + -12665, -10394, -12916, -10080, -13159, -9760, -13395, -9434, + -13622, -9102, -13842, -8765, -14053, -8423, -14255, -8075, + -14449, -7723, -14634, -7366, -14811, -7005, -14978, -6639, + -15136, -6270, -15286, -5896, -15426, -5519, -15557, -5139, + -15678, -4756, -15790, -4370, -15893, -3981, -15985, -3590, + -16069, -3196, -16142, -2801, -16206, -2404, -16260, -2006, + -16305, -1606, -16339, -1205, -16364, -804, -16379, -402, + /* part of table that is scaled by 2 (this save one operation in FFT inner loops) */ + 32767, 0, 32758, -804, 32728, -1608, 32678, -2410, + 32610, -3212, 32520, -4012, 32412, -4808, 32284, -5602, + 32138, -6392, 31970, -7180, 31786, -7962, 31580, -8740, + 31356, -9512, 31114, -10278, 30852, -11038, 30572, -11792, + 30272, -12540, 29956, -13278, 29622, -14010, 29268, -14732, + 28898, -15446, 28510, -16150, 28106, -16846, 27684, -17530, + 27244, -18204, 26790, -18868, 26318, -19520, 25832, -20160, + 25330, -20788, 24812, -21402, 24278, -22004, 23732, -22594, + 23170, -23170, 22594, -23732, 22004, -24278, 21402, -24812, + 20788, -25330, 20160, -25832, 19520, -26318, 18868, -26790, + 18204, -27244, 17530, -27684, 16846, -28106, 16150, -28510, + 15446, -28898, 14732, -29268, 14010, -29622, 13278, -29956, + 12540, -30272, 11792, -30572, 11038, -30852, 10278, -31114, + 9512, -31356, 8740, -31580, 7962, -31786, 7180, -31970, + 6392, -32138, 5602, -32284, 4808, -32412, 4012, -32520, + 3212, -32610, 2410, -32678, 1608, -32728, 804, -32758, + 0, -32768, -804, -32758, -1608, -32728, -2410, -32678, + -3212, -32610, -4012, -32520, -4808, -32412, -5602, -32284, + -6392, -32138, -7180, -31970, -7962, -31786, -8740, -31580, + -9512, -31356, -10278, -31114, -11038, -30852, -11792, -30572, + -12540, -30272, -13278, -29956, -14010, -29622, -14732, -29268, + -15446, -28898, -16150, -28510, -16846, -28106, -17530, -27684, + -18204, -27244, -18868, -26790, -19520, -26318, -20160, -25832, + -20788, -25330, -21402, -24812, -22004, -24278, -22594, -23732, + -23170, -23170, -23732, -22594, -24278, -22004, -24812, -21402, + -25330, -20788, -25832, -20160, -26318, -19520, -26790, -18868, + -27244, -18204, -27684, -17530, -28106, -16846, -28510, -16150, + -28898, -15446, -29268, -14732, -29622, -14010, -29956, -13278, + -30272, -12540, -30572, -11792, -30852, -11038, -31114, -10278, + -31356, -9512, -31580, -8740, -31786, -7962, -31970, -7180, + -32138, -6392, -32284, -5602, -32412, -4808, -32520, -4012, + -32610, -3212, -32678, -2410, -32728, -1608, -32758, -804 +}; + +const Word16 FFT_W256[( 256 * 2 ) * 2] = { + /* Each adjacent pair represents the real and imaginary part of a complex number: */ + /* W = exp{-j*(PI*n/256)} = cos(PI*n/256)*16384 -j*sin(PI*n/256)*16384 for n=0, 1, ..., 255. */ + 16384, 0, 16383, -201, 16379, -402, 16373, -603, + 16364, -804, 16353, -1005, 16340, -1205, 16324, -1406, + 16305, -1606, 16284, -1806, 16261, -2006, 16235, -2205, + 16207, -2404, 16176, -2603, 16143, -2801, 16107, -2999, + 16069, -3196, 16029, -3393, 15986, -3590, 15941, -3786, + 15893, -3981, 15843, -4176, 15791, -4370, 15736, -4563, + 15679, -4756, 15619, -4948, 15557, -5139, 15493, -5330, + 15426, -5520, 15357, -5708, 15286, -5897, 15213, -6084, + 15137, -6270, 15059, -6455, 14978, -6639, 14896, -6823, + 14811, -7005, 14724, -7186, 14635, -7366, 14543, -7545, + 14449, -7723, 14354, -7900, 14256, -8076, 14155, -8250, + 14053, -8423, 13949, -8595, 13842, -8765, 13733, -8935, + 13623, -9102, 13510, -9269, 13395, -9434, 13279, -9598, + 13160, -9760, 13039, -9921, 12916, -10080, 12792, -10238, + 12665, -10394, 12537, -10549, 12406, -10702, 12274, -10853, + 12140, -11003, 12004, -11151, 11866, -11297, 11727, -11442, + 11585, -11585, 11442, -11727, 11297, -11866, 11151, -12004, + 11003, -12140, 10853, -12274, 10702, -12406, 10549, -12537, + 10394, -12665, 10238, -12792, 10080, -12916, 9921, -13039, + 9760, -13160, 9598, -13279, 9434, -13395, 9269, -13510, + 9102, -13623, 8935, -13733, 8765, -13842, 8595, -13949, + 8423, -14053, 8250, -14155, 8076, -14256, 7900, -14354, + 7723, -14449, 7545, -14543, 7366, -14635, 7186, -14724, + 7005, -14811, 6823, -14896, 6639, -14978, 6455, -15059, + 6270, -15137, 6084, -15213, 5897, -15286, 5708, -15357, + 5520, -15426, 5330, -15493, 5139, -15557, 4948, -15619, + 4756, -15679, 4563, -15736, 4370, -15791, 4176, -15843, + 3981, -15893, 3786, -15941, 3590, -15986, 3393, -16029, + 3196, -16069, 2999, -16107, 2801, -16143, 2603, -16176, + 2404, -16207, 2205, -16235, 2006, -16261, 1806, -16284, + 1606, -16305, 1406, -16324, 1205, -16340, 1005, -16353, + 804, -16364, 603, -16373, 402, -16379, 201, -16383, + 0, -16384, -201, -16383, -402, -16379, -603, -16373, + -804, -16364, -1005, -16353, -1205, -16340, -1406, -16324, + -1606, -16305, -1806, -16284, -2006, -16261, -2205, -16235, + -2404, -16207, -2603, -16176, -2801, -16143, -2999, -16107, + -3196, -16069, -3393, -16029, -3590, -15986, -3786, -15941, + -3981, -15893, -4176, -15843, -4370, -15791, -4563, -15736, + -4756, -15679, -4948, -15619, -5139, -15557, -5330, -15493, + -5520, -15426, -5708, -15357, -5897, -15286, -6084, -15213, + -6270, -15137, -6455, -15059, -6639, -14978, -6823, -14896, + -7005, -14811, -7186, -14724, -7366, -14635, -7545, -14543, + -7723, -14449, -7900, -14354, -8076, -14256, -8250, -14155, + -8423, -14053, -8595, -13949, -8765, -13842, -8935, -13733, + -9102, -13623, -9269, -13510, -9434, -13395, -9598, -13279, + -9760, -13160, -9921, -13039, -10080, -12916, -10238, -12792, + -10394, -12665, -10549, -12537, -10702, -12406, -10853, -12274, + -11003, -12140, -11151, -12004, -11297, -11866, -11442, -11727, + -11585, -11585, -11727, -11442, -11866, -11297, -12004, -11151, + -12140, -11003, -12274, -10853, -12406, -10702, -12537, -10549, + -12665, -10394, -12792, -10238, -12916, -10080, -13039, -9921, + -13160, -9760, -13279, -9598, -13395, -9434, -13510, -9269, + -13623, -9102, -13733, -8935, -13842, -8765, -13949, -8595, + -14053, -8423, -14155, -8250, -14256, -8076, -14354, -7900, + -14449, -7723, -14543, -7545, -14635, -7366, -14724, -7186, + -14811, -7005, -14896, -6823, -14978, -6639, -15059, -6455, + -15137, -6270, -15213, -6084, -15286, -5897, -15357, -5708, + -15426, -5520, -15493, -5330, -15557, -5139, -15619, -4948, + -15679, -4756, -15736, -4563, -15791, -4370, -15843, -4176, + -15893, -3981, -15941, -3786, -15986, -3590, -16029, -3393, + -16069, -3196, -16107, -2999, -16143, -2801, -16176, -2603, + -16207, -2404, -16235, -2205, -16261, -2006, -16284, -1806, + -16305, -1606, -16324, -1406, -16340, -1205, -16353, -1005, + -16364, -804, -16373, -603, -16379, -402, -16383, -201, + /* The following is a duplication of the above but scaled up by a factor of 2. * This save one operation in inverse FFT inner loops */ - 32767, 0, 32767, -201, 32766, -402, 32762, -603, - 32758, -804, 32753, -1005, 32746, -1206, 32738, -1407, - 32729, -1608, 32718, -1809, 32706, -2009, 32693, -2210, - 32679, -2411, 32664, -2611, 32647, -2811, 32629, -3012, - 32610, -3212, 32590, -3412, 32568, -3612, 32546, -3812, - 32522, -4011, 32496, -4211, 32470, -4410, 32442, -4609, - 32413, -4808, 32383, -5007, 32352, -5205, 32319, -5404, - 32286, -5602, 32251, -5800, 32214, -5998, 32177, -6195, - 32138, -6393, 32099, -6590, 32058, -6787, 32015, -6983, - 31972, -7180, 31927, -7376, 31881, -7571, 31834, -7767, - 31786, -7962, 31737, -8157, 31686, -8351, 31634, -8546, - 31581, -8740, 31527, -8933, 31471, -9127, 31415, -9319, - 31357, -9512, 31298, -9704, 31238, -9896, 31177, -10088, - 31114, -10279, 31050, -10469, 30986, -10660, 30920, -10850, - 30853, -11039, 30784, -11228, 30715, -11417, 30644, -11605, - 30572, -11793, 30499, -11980, 30425, -12167, 30350, -12354, - 30274, -12540, 30196, -12725, 30118, -12910, 30038, -13095, - 29957, -13279, 29875, -13463, 29792, -13646, 29707, -13828, - 29622, -14010, 29535, -14192, 29448, -14373, 29359, -14553, - 29269, -14733, 29178, -14912, 29086, -15091, 28993, -15269, - 28899, -15447, 28803, -15624, 28707, -15800, 28610, -15976, - 28511, -16151, 28411, -16326, 28311, -16500, 28209, -16673, - 28106, -16846, 28002, -17018, 27897, -17190, 27791, -17361, - 27684, -17531, 27576, -17700, 27467, -17869, 27357, -18037, - 27246, -18205, 27133, -18372, 27020, -18538, 26906, -18703, - 26791, -18868, 26674, -19032, 26557, -19195, 26439, -19358, - 26320, -19520, 26199, -19681, 26078, -19841, 25956, -20001, - 25833, -20160, 25708, -20318, 25583, -20475, 25457, -20632, - 25330, -20788, 25202, -20943, 25073, -21097, 24943, -21251, - 24812, -21403, 24680, -21555, 24548, -21706, 24414, -21856, - 24279, -22006, 24144, -22154, 24008, -22302, 23870, -22449, - 23732, -22595, 23593, -22740, 23453, -22884, 23312, -23028, - 23170, -23170, 23028, -23312, 22884, -23453, 22740, -23593, - 22595, -23732, 22449, -23870, 22302, -24008, 22154, -24144, - 22006, -24279, 21856, -24414, 21706, -24548, 21555, -24680, - 21403, -24812, 21251, -24943, 21097, -25073, 20943, -25202, - 20788, -25330, 20632, -25457, 20475, -25583, 20318, -25708, - 20160, -25833, 20001, -25956, 19841, -26078, 19681, -26199, - 19520, -26320, 19358, -26439, 19195, -26557, 19032, -26674, - 18868, -26791, 18703, -26906, 18538, -27020, 18372, -27133, - 18205, -27246, 18037, -27357, 17869, -27467, 17700, -27576, - 17531, -27684, 17361, -27791, 17190, -27897, 17018, -28002, - 16846, -28106, 16673, -28209, 16500, -28311, 16326, -28411, - 16151, -28511, 15976, -28610, 15800, -28707, 15624, -28803, - 15447, -28899, 15269, -28993, 15091, -29086, 14912, -29178, - 14733, -29269, 14553, -29359, 14373, -29448, 14192, -29535, - 14010, -29622, 13828, -29707, 13646, -29792, 13463, -29875, - 13279, -29957, 13095, -30038, 12910, -30118, 12725, -30196, - 12540, -30274, 12354, -30350, 12167, -30425, 11980, -30499, - 11793, -30572, 11605, -30644, 11417, -30715, 11228, -30784, - 11039, -30853, 10850, -30920, 10660, -30986, 10469, -31050, - 10279, -31114, 10088, -31177, 9896, -31238, 9704, -31298, - 9512, -31357, 9319, -31415, 9127, -31471, 8933, -31527, - 8740, -31581, 8546, -31634, 8351, -31686, 8157, -31737, - 7962, -31786, 7767, -31834, 7571, -31881, 7376, -31927, - 7180, -31972, 6983, -32015, 6787, -32058, 6590, -32099, - 6393, -32138, 6195, -32177, 5998, -32214, 5800, -32251, - 5602, -32286, 5404, -32319, 5205, -32352, 5007, -32383, - 4808, -32413, 4609, -32442, 4410, -32470, 4211, -32496, - 4011, -32522, 3812, -32546, 3612, -32568, 3412, -32590, - 3212, -32610, 3012, -32629, 2811, -32647, 2611, -32664, - 2411, -32679, 2210, -32693, 2009, -32706, 1809, -32718, - 1608, -32729, 1407, -32738, 1206, -32746, 1005, -32753, - 804, -32758, 603, -32762, 402, -32766, 201, -32767, - 0, -32768, -201, -32767, -402, -32766, -603, -32762, - -804, -32758, -1005, -32753, -1206, -32746, -1407, -32738, - -1608, -32729, -1809, -32718, -2009, -32706, -2210, -32693, - -2411, -32679, -2611, -32664, -2811, -32647, -3012, -32629, - -3212, -32610, -3412, -32590, -3612, -32568, -3812, -32546, - -4011, -32522, -4211, -32496, -4410, -32470, -4609, -32442, - -4808, -32413, -5007, -32383, -5205, -32352, -5404, -32319, - -5602, -32286, -5800, -32251, -5998, -32214, -6195, -32177, - -6393, -32138, -6590, -32099, -6787, -32058, -6983, -32015, - -7180, -31972, -7376, -31927, -7571, -31881, -7767, -31834, - -7962, -31786, -8157, -31737, -8351, -31686, -8546, -31634, - -8740, -31581, -8933, -31527, -9127, -31471, -9319, -31415, - -9512, -31357, -9704, -31298, -9896, -31238, -10088, -31177, - -10279, -31114, -10469, -31050, -10660, -30986, -10850, -30920, - -11039, -30853, -11228, -30784, -11417, -30715, -11605, -30644, - -11793, -30572, -11980, -30499, -12167, -30425, -12354, -30350, - -12540, -30274, -12725, -30196, -12910, -30118, -13095, -30038, - -13279, -29957, -13463, -29875, -13646, -29792, -13828, -29707, - -14010, -29622, -14192, -29535, -14373, -29448, -14553, -29359, - -14733, -29269, -14912, -29178, -15091, -29086, -15269, -28993, - -15447, -28899, -15624, -28803, -15800, -28707, -15976, -28610, - -16151, -28511, -16326, -28411, -16500, -28311, -16673, -28209, - -16846, -28106, -17018, -28002, -17190, -27897, -17361, -27791, - -17531, -27684, -17700, -27576, -17869, -27467, -18037, -27357, - -18205, -27246, -18372, -27133, -18538, -27020, -18703, -26906, - -18868, -26791, -19032, -26674, -19195, -26557, -19358, -26439, - -19520, -26320, -19681, -26199, -19841, -26078, -20001, -25956, - -20160, -25833, -20318, -25708, -20475, -25583, -20632, -25457, - -20788, -25330, -20943, -25202, -21097, -25073, -21251, -24943, - -21403, -24812, -21555, -24680, -21706, -24548, -21856, -24414, - -22006, -24279, -22154, -24144, -22302, -24008, -22449, -23870, - -22595, -23732, -22740, -23593, -22884, -23453, -23028, -23312, - -23170, -23170, -23312, -23028, -23453, -22884, -23593, -22740, - -23732, -22595, -23870, -22449, -24008, -22302, -24144, -22154, - -24279, -22006, -24414, -21856, -24548, -21706, -24680, -21555, - -24812, -21403, -24943, -21251, -25073, -21097, -25202, -20943, - -25330, -20788, -25457, -20632, -25583, -20475, -25708, -20318, - -25833, -20160, -25956, -20001, -26078, -19841, -26199, -19681, - -26320, -19520, -26439, -19358, -26557, -19195, -26674, -19032, - -26791, -18868, -26906, -18703, -27020, -18538, -27133, -18372, - -27246, -18205, -27357, -18037, -27467, -17869, -27576, -17700, - -27684, -17531, -27791, -17361, -27897, -17190, -28002, -17018, - -28106, -16846, -28209, -16673, -28311, -16500, -28411, -16326, - -28511, -16151, -28610, -15976, -28707, -15800, -28803, -15624, - -28899, -15447, -28993, -15269, -29086, -15091, -29178, -14912, - -29269, -14733, -29359, -14553, -29448, -14373, -29535, -14192, - -29622, -14010, -29707, -13828, -29792, -13646, -29875, -13463, - -29957, -13279, -30038, -13095, -30118, -12910, -30196, -12725, - -30274, -12540, -30350, -12354, -30425, -12167, -30499, -11980, - -30572, -11793, -30644, -11605, -30715, -11417, -30784, -11228, - -30853, -11039, -30920, -10850, -30986, -10660, -31050, -10469, - -31114, -10279, -31177, -10088, -31238, -9896, -31298, -9704, - -31357, -9512, -31415, -9319, -31471, -9127, -31527, -8933, - -31581, -8740, -31634, -8546, -31686, -8351, -31737, -8157, - -31786, -7962, -31834, -7767, -31881, -7571, -31927, -7376, - -31972, -7180, -32015, -6983, -32058, -6787, -32099, -6590, - -32138, -6393, -32177, -6195, -32214, -5998, -32251, -5800, - -32286, -5602, -32319, -5404, -32352, -5205, -32383, -5007, - -32413, -4808, -32442, -4609, -32470, -4410, -32496, -4211, - -32522, -4011, -32546, -3812, -32568, -3612, -32590, -3412, - -32610, -3212, -32629, -3012, -32647, -2811, -32664, -2611, - -32679, -2411, -32693, -2210, -32706, -2009, -32718, -1809, - -32729, -1608, -32738, -1407, -32746, -1206, -32753, -1005, - -32758, -804, -32762, -603, -32766, -402, -32767, -201 -}; - -const Word16 FFT_REORDER_1024[512] = -{ - 0, 512, 256, 768, 128, 640, 384, 896, - 64, 576, 320, 832, 192, 704, 448, 960, - 32, 544, 288, 800, 160, 672, 416, 928, - 96, 608, 352, 864, 224, 736, 480, 992, - 16, 528, 272, 784, 144, 656, 400, 912, - 80, 592, 336, 848, 208, 720, 464, 976, - 48, 560, 304, 816, 176, 688, 432, 944, - 112, 624, 368, 880, 240, 752, 496, 1008, - 8, 520, 264, 776, 136, 648, 392, 904, - 72, 584, 328, 840, 200, 712, 456, 968, - 40, 552, 296, 808, 168, 680, 424, 936, - 104, 616, 360, 872, 232, 744, 488, 1000, - 24, 536, 280, 792, 152, 664, 408, 920, - 88, 600, 344, 856, 216, 728, 472, 984, - 56, 568, 312, 824, 184, 696, 440, 952, - 120, 632, 376, 888, 248, 760, 504, 1016, - 4, 516, 260, 772, 132, 644, 388, 900, - 68, 580, 324, 836, 196, 708, 452, 964, - 36, 548, 292, 804, 164, 676, 420, 932, - 100, 612, 356, 868, 228, 740, 484, 996, - 20, 532, 276, 788, 148, 660, 404, 916, - 84, 596, 340, 852, 212, 724, 468, 980, - 52, 564, 308, 820, 180, 692, 436, 948, - 116, 628, 372, 884, 244, 756, 500, 1012, - 12, 524, 268, 780, 140, 652, 396, 908, - 76, 588, 332, 844, 204, 716, 460, 972, - 44, 556, 300, 812, 172, 684, 428, 940, - 108, 620, 364, 876, 236, 748, 492, 1004, - 28, 540, 284, 796, 156, 668, 412, 924, - 92, 604, 348, 860, 220, 732, 476, 988, - 60, 572, 316, 828, 188, 700, 444, 956, - 124, 636, 380, 892, 252, 764, 508, 1020, - 2, 514, 258, 770, 130, 642, 386, 898, - 66, 578, 322, 834, 194, 706, 450, 962, - 34, 546, 290, 802, 162, 674, 418, 930, - 98, 610, 354, 866, 226, 738, 482, 994, - 18, 530, 274, 786, 146, 658, 402, 914, - 82, 594, 338, 850, 210, 722, 466, 978, - 50, 562, 306, 818, 178, 690, 434, 946, - 114, 626, 370, 882, 242, 754, 498, 1010, - 10, 522, 266, 778, 138, 650, 394, 906, - 74, 586, 330, 842, 202, 714, 458, 970, - 42, 554, 298, 810, 170, 682, 426, 938, - 106, 618, 362, 874, 234, 746, 490, 1002, - 26, 538, 282, 794, 154, 666, 410, 922, - 90, 602, 346, 858, 218, 730, 474, 986, - 58, 570, 314, 826, 186, 698, 442, 954, - 122, 634, 378, 890, 250, 762, 506, 1018, - 6, 518, 262, 774, 134, 646, 390, 902, - 70, 582, 326, 838, 198, 710, 454, 966, - 38, 550, 294, 806, 166, 678, 422, 934, - 102, 614, 358, 870, 230, 742, 486, 998, - 22, 534, 278, 790, 150, 662, 406, 918, - 86, 598, 342, 854, 214, 726, 470, 982, - 54, 566, 310, 822, 182, 694, 438, 950, - 118, 630, 374, 886, 246, 758, 502, 1014, - 14, 526, 270, 782, 142, 654, 398, 910, - 78, 590, 334, 846, 206, 718, 462, 974, - 46, 558, 302, 814, 174, 686, 430, 942, - 110, 622, 366, 878, 238, 750, 494, 1006, - 30, 542, 286, 798, 158, 670, 414, 926, - 94, 606, 350, 862, 222, 734, 478, 990, - 62, 574, 318, 830, 190, 702, 446, 958, - 126, 638, 382, 894, 254, 766, 510, 1022 -}; - -const Word16 Gamma_19661_Tbl_fx[] = -{ + 32767, 0, 32766, -402, 32758, -804, 32746, -1206, + 32729, -1608, 32706, -2009, 32679, -2411, 32647, -2811, + 32610, -3212, 32568, -3612, 32522, -4011, 32470, -4410, + 32413, -4808, 32352, -5205, 32286, -5602, 32214, -5998, + 32138, -6393, 32058, -6787, 31972, -7180, 31881, -7571, + 31786, -7962, 31686, -8351, 31581, -8740, 31471, -9127, + 31357, -9512, 31238, -9896, 31114, -10279, 30986, -10660, + 30853, -11039, 30715, -11417, 30572, -11793, 30425, -12167, + 30274, -12540, 30118, -12910, 29957, -13279, 29792, -13646, + 29622, -14010, 29448, -14373, 29269, -14733, 29086, -15091, + 28899, -15447, 28707, -15800, 28511, -16151, 28311, -16500, + 28106, -16846, 27897, -17190, 27684, -17531, 27467, -17869, + 27246, -18205, 27020, -18538, 26791, -18868, 26557, -19195, + 26320, -19520, 26078, -19841, 25833, -20160, 25583, -20475, + 25330, -20788, 25073, -21097, 24812, -21403, 24548, -21706, + 24279, -22006, 24008, -22302, 23732, -22595, 23453, -22884, + 23170, -23170, 22884, -23453, 22595, -23732, 22302, -24008, + 22006, -24279, 21706, -24548, 21403, -24812, 21097, -25073, + 20788, -25330, 20475, -25583, 20160, -25833, 19841, -26078, + 19520, -26320, 19195, -26557, 18868, -26791, 18538, -27020, + 18205, -27246, 17869, -27467, 17531, -27684, 17190, -27897, + 16846, -28106, 16500, -28311, 16151, -28511, 15800, -28707, + 15447, -28899, 15091, -29086, 14733, -29269, 14373, -29448, + 14010, -29622, 13646, -29792, 13279, -29957, 12910, -30118, + 12540, -30274, 12167, -30425, 11793, -30572, 11417, -30715, + 11039, -30853, 10660, -30986, 10279, -31114, 9896, -31238, + 9512, -31357, 9127, -31471, 8740, -31581, 8351, -31686, + 7962, -31786, 7571, -31881, 7180, -31972, 6787, -32058, + 6393, -32138, 5998, -32214, 5602, -32286, 5205, -32352, + 4808, -32413, 4410, -32470, 4011, -32522, 3612, -32568, + 3212, -32610, 2811, -32647, 2411, -32679, 2009, -32706, + 1608, -32729, 1206, -32746, 804, -32758, 402, -32766, + 0, -32768, -402, -32766, -804, -32758, -1206, -32746, + -1608, -32729, -2009, -32706, -2411, -32679, -2811, -32647, + -3212, -32610, -3612, -32568, -4011, -32522, -4410, -32470, + -4808, -32413, -5205, -32352, -5602, -32286, -5998, -32214, + -6393, -32138, -6787, -32058, -7180, -31972, -7571, -31881, + -7962, -31786, -8351, -31686, -8740, -31581, -9127, -31471, + -9512, -31357, -9896, -31238, -10279, -31114, -10660, -30986, + -11039, -30853, -11417, -30715, -11793, -30572, -12167, -30425, + -12540, -30274, -12910, -30118, -13279, -29957, -13646, -29792, + -14010, -29622, -14373, -29448, -14733, -29269, -15091, -29086, + -15447, -28899, -15800, -28707, -16151, -28511, -16500, -28311, + -16846, -28106, -17190, -27897, -17531, -27684, -17869, -27467, + -18205, -27246, -18538, -27020, -18868, -26791, -19195, -26557, + -19520, -26320, -19841, -26078, -20160, -25833, -20475, -25583, + -20788, -25330, -21097, -25073, -21403, -24812, -21706, -24548, + -22006, -24279, -22302, -24008, -22595, -23732, -22884, -23453, + -23170, -23170, -23453, -22884, -23732, -22595, -24008, -22302, + -24279, -22006, -24548, -21706, -24812, -21403, -25073, -21097, + -25330, -20788, -25583, -20475, -25833, -20160, -26078, -19841, + -26320, -19520, -26557, -19195, -26791, -18868, -27020, -18538, + -27246, -18205, -27467, -17869, -27684, -17531, -27897, -17190, + -28106, -16846, -28311, -16500, -28511, -16151, -28707, -15800, + -28899, -15447, -29086, -15091, -29269, -14733, -29448, -14373, + -29622, -14010, -29792, -13646, -29957, -13279, -30118, -12910, + -30274, -12540, -30425, -12167, -30572, -11793, -30715, -11417, + -30853, -11039, -30986, -10660, -31114, -10279, -31238, -9896, + -31357, -9512, -31471, -9127, -31581, -8740, -31686, -8351, + -31786, -7962, -31881, -7571, -31972, -7180, -32058, -6787, + -32138, -6393, -32214, -5998, -32286, -5602, -32352, -5205, + -32413, -4808, -32470, -4410, -32522, -4011, -32568, -3612, + -32610, -3212, -32647, -2811, -32679, -2411, -32706, -2009, + -32729, -1608, -32746, -1206, -32758, -804, -32766, -402 +}; + +const Word16 FFT_W512[( 512 * 2 ) * 2] = { + 16384, 0, 16384, -101, 16383, -201, 16381, -302, + 16379, -402, 16376, -503, 16373, -603, 16369, -704, + 16364, -804, 16359, -904, 16353, -1005, 16347, -1105, + 16340, -1205, 16332, -1306, 16324, -1406, 16315, -1506, + 16305, -1606, 16295, -1706, 16284, -1806, 16273, -1906, + 16261, -2006, 16248, -2105, 16235, -2205, 16221, -2305, + 16207, -2404, 16192, -2503, 16176, -2603, 16160, -2702, + 16143, -2801, 16125, -2900, 16107, -2999, 16088, -3098, + 16069, -3196, 16049, -3295, 16029, -3393, 16008, -3492, + 15986, -3590, 15964, -3688, 15941, -3786, 15917, -3883, + 15893, -3981, 15868, -4078, 15843, -4176, 15817, -4273, + 15791, -4370, 15763, -4467, 15736, -4563, 15707, -4660, + 15679, -4756, 15649, -4852, 15619, -4948, 15588, -5044, + 15557, -5139, 15525, -5235, 15493, -5330, 15460, -5425, + 15426, -5520, 15392, -5614, 15357, -5708, 15322, -5803, + 15286, -5897, 15250, -5990, 15213, -6084, 15175, -6177, + 15137, -6270, 15098, -6363, 15059, -6455, 15019, -6547, + 14978, -6639, 14937, -6731, 14896, -6823, 14854, -6914, + 14811, -7005, 14768, -7096, 14724, -7186, 14680, -7276, + 14635, -7366, 14589, -7456, 14543, -7545, 14497, -7635, + 14449, -7723, 14402, -7812, 14354, -7900, 14305, -7988, + 14256, -8076, 14206, -8163, 14155, -8250, 14104, -8337, + 14053, -8423, 14001, -8509, 13949, -8595, 13896, -8680, + 13842, -8765, 13788, -8850, 13733, -8935, 13678, -9019, + 13623, -9102, 13567, -9186, 13510, -9269, 13453, -9352, + 13395, -9434, 13337, -9516, 13279, -9598, 13219, -9679, + 13160, -9760, 13100, -9841, 13039, -9921, 12978, -10001, + 12916, -10080, 12854, -10159, 12792, -10238, 12729, -10316, + 12665, -10394, 12601, -10471, 12537, -10549, 12472, -10625, + 12406, -10702, 12340, -10778, 12274, -10853, 12207, -10928, + 12140, -11003, 12072, -11077, 12004, -11151, 11935, -11224, + 11866, -11297, 11797, -11370, 11727, -11442, 11656, -11514, + 11585, -11585, 11514, -11656, 11442, -11727, 11370, -11797, + 11297, -11866, 11224, -11935, 11151, -12004, 11077, -12072, + 11003, -12140, 10928, -12207, 10853, -12274, 10778, -12340, + 10702, -12406, 10625, -12472, 10549, -12537, 10471, -12601, + 10394, -12665, 10316, -12729, 10238, -12792, 10159, -12854, + 10080, -12916, 10001, -12978, 9921, -13039, 9841, -13100, + 9760, -13160, 9679, -13219, 9598, -13279, 9516, -13337, + 9434, -13395, 9352, -13453, 9269, -13510, 9186, -13567, + 9102, -13623, 9019, -13678, 8935, -13733, 8850, -13788, + 8765, -13842, 8680, -13896, 8595, -13949, 8509, -14001, + 8423, -14053, 8337, -14104, 8250, -14155, 8163, -14206, + 8076, -14256, 7988, -14305, 7900, -14354, 7812, -14402, + 7723, -14449, 7635, -14497, 7545, -14543, 7456, -14589, + 7366, -14635, 7276, -14680, 7186, -14724, 7096, -14768, + 7005, -14811, 6914, -14854, 6823, -14896, 6731, -14937, + 6639, -14978, 6547, -15019, 6455, -15059, 6363, -15098, + 6270, -15137, 6177, -15175, 6084, -15213, 5990, -15250, + 5897, -15286, 5803, -15322, 5708, -15357, 5614, -15392, + 5520, -15426, 5425, -15460, 5330, -15493, 5235, -15525, + 5139, -15557, 5044, -15588, 4948, -15619, 4852, -15649, + 4756, -15679, 4660, -15707, 4563, -15736, 4467, -15763, + 4370, -15791, 4273, -15817, 4176, -15843, 4078, -15868, + 3981, -15893, 3883, -15917, 3786, -15941, 3688, -15964, + 3590, -15986, 3492, -16008, 3393, -16029, 3295, -16049, + 3196, -16069, 3098, -16088, 2999, -16107, 2900, -16125, + 2801, -16143, 2702, -16160, 2603, -16176, 2503, -16192, + 2404, -16207, 2305, -16221, 2205, -16235, 2105, -16248, + 2006, -16261, 1906, -16273, 1806, -16284, 1706, -16295, + 1606, -16305, 1506, -16315, 1406, -16324, 1306, -16332, + 1205, -16340, 1105, -16347, 1005, -16353, 904, -16359, + 804, -16364, 703, -16369, 603, -16373, 503, -16376, + 402, -16379, 302, -16381, 201, -16383, 101, -16384, + 0, -16384, -101, -16384, -201, -16383, -302, -16381, + -402, -16379, -503, -16376, -603, -16373, -704, -16369, + -804, -16364, -904, -16359, -1005, -16353, -1105, -16347, + -1205, -16340, -1306, -16332, -1406, -16324, -1506, -16315, + -1606, -16305, -1706, -16295, -1806, -16284, -1906, -16273, + -2006, -16261, -2105, -16248, -2205, -16235, -2305, -16221, + -2404, -16207, -2503, -16192, -2603, -16176, -2702, -16160, + -2801, -16143, -2900, -16125, -2999, -16107, -3098, -16088, + -3196, -16069, -3295, -16049, -3393, -16029, -3492, -16008, + -3590, -15986, -3688, -15964, -3786, -15941, -3883, -15917, + -3981, -15893, -4078, -15868, -4176, -15843, -4273, -15817, + -4370, -15791, -4467, -15763, -4563, -15736, -4660, -15707, + -4756, -15679, -4852, -15649, -4948, -15619, -5044, -15588, + -5139, -15557, -5235, -15525, -5330, -15493, -5425, -15460, + -5520, -15426, -5614, -15392, -5708, -15357, -5803, -15322, + -5897, -15286, -5990, -15250, -6084, -15213, -6177, -15175, + -6270, -15137, -6363, -15098, -6455, -15059, -6547, -15019, + -6639, -14978, -6731, -14937, -6823, -14896, -6914, -14854, + -7005, -14811, -7096, -14768, -7186, -14724, -7276, -14680, + -7366, -14635, -7456, -14589, -7545, -14543, -7635, -14497, + -7723, -14449, -7812, -14402, -7900, -14354, -7988, -14305, + -8076, -14256, -8163, -14206, -8250, -14155, -8337, -14104, + -8423, -14053, -8509, -14001, -8595, -13949, -8680, -13896, + -8765, -13842, -8850, -13788, -8935, -13733, -9019, -13678, + -9102, -13623, -9186, -13567, -9269, -13510, -9352, -13453, + -9434, -13395, -9516, -13337, -9598, -13279, -9679, -13219, + -9760, -13160, -9841, -13100, -9921, -13039, -10001, -12978, + -10080, -12916, -10159, -12854, -10238, -12792, -10316, -12729, + -10394, -12665, -10471, -12601, -10549, -12537, -10625, -12472, + -10702, -12406, -10778, -12340, -10853, -12274, -10928, -12207, + -11003, -12140, -11077, -12072, -11151, -12004, -11224, -11935, + -11297, -11866, -11370, -11797, -11442, -11727, -11514, -11656, + -11585, -11585, -11656, -11514, -11727, -11442, -11797, -11370, + -11866, -11297, -11935, -11224, -12004, -11151, -12072, -11077, + -12140, -11003, -12207, -10928, -12274, -10853, -12340, -10778, + -12406, -10702, -12472, -10625, -12537, -10549, -12601, -10471, + -12665, -10394, -12729, -10316, -12792, -10238, -12854, -10159, + -12916, -10080, -12978, -10001, -13039, -9921, -13100, -9840, + -13160, -9760, -13219, -9679, -13279, -9598, -13337, -9516, + -13395, -9434, -13453, -9352, -13510, -9269, -13567, -9186, + -13623, -9102, -13678, -9019, -13733, -8935, -13788, -8850, + -13842, -8765, -13896, -8680, -13949, -8595, -14001, -8509, + -14053, -8423, -14104, -8337, -14155, -8250, -14206, -8163, + -14256, -8076, -14305, -7988, -14354, -7900, -14402, -7812, + -14449, -7723, -14497, -7635, -14543, -7545, -14589, -7456, + -14635, -7366, -14680, -7276, -14724, -7186, -14768, -7096, + -14811, -7005, -14854, -6914, -14896, -6823, -14937, -6731, + -14978, -6639, -15019, -6547, -15059, -6455, -15098, -6363, + -15137, -6270, -15175, -6177, -15213, -6084, -15250, -5990, + -15286, -5897, -15322, -5803, -15357, -5708, -15392, -5614, + -15426, -5520, -15460, -5425, -15493, -5330, -15525, -5235, + -15557, -5139, -15588, -5044, -15619, -4948, -15649, -4852, + -15679, -4756, -15707, -4660, -15736, -4563, -15763, -4467, + -15791, -4370, -15817, -4273, -15843, -4176, -15868, -4078, + -15893, -3981, -15917, -3883, -15941, -3786, -15964, -3688, + -15986, -3590, -16008, -3492, -16029, -3393, -16049, -3295, + -16069, -3196, -16088, -3098, -16107, -2999, -16125, -2900, + -16143, -2801, -16160, -2702, -16176, -2603, -16192, -2503, + -16207, -2404, -16221, -2305, -16235, -2205, -16248, -2105, + -16261, -2006, -16273, -1906, -16284, -1806, -16295, -1706, + -16305, -1606, -16315, -1506, -16324, -1406, -16332, -1306, + -16340, -1205, -16347, -1105, -16353, -1005, -16359, -904, + -16364, -804, -16369, -703, -16373, -603, -16376, -503, + -16379, -402, -16381, -302, -16383, -201, -16384, -101, + /* The following is a duplication of the above but scaled up by a factor of 2. + * This save one operation in inverse FFT inner loops */ + 32767, 0, 32767, -201, 32766, -402, 32762, -603, + 32758, -804, 32753, -1005, 32746, -1206, 32738, -1407, + 32729, -1608, 32718, -1809, 32706, -2009, 32693, -2210, + 32679, -2411, 32664, -2611, 32647, -2811, 32629, -3012, + 32610, -3212, 32590, -3412, 32568, -3612, 32546, -3812, + 32522, -4011, 32496, -4211, 32470, -4410, 32442, -4609, + 32413, -4808, 32383, -5007, 32352, -5205, 32319, -5404, + 32286, -5602, 32251, -5800, 32214, -5998, 32177, -6195, + 32138, -6393, 32099, -6590, 32058, -6787, 32015, -6983, + 31972, -7180, 31927, -7376, 31881, -7571, 31834, -7767, + 31786, -7962, 31737, -8157, 31686, -8351, 31634, -8546, + 31581, -8740, 31527, -8933, 31471, -9127, 31415, -9319, + 31357, -9512, 31298, -9704, 31238, -9896, 31177, -10088, + 31114, -10279, 31050, -10469, 30986, -10660, 30920, -10850, + 30853, -11039, 30784, -11228, 30715, -11417, 30644, -11605, + 30572, -11793, 30499, -11980, 30425, -12167, 30350, -12354, + 30274, -12540, 30196, -12725, 30118, -12910, 30038, -13095, + 29957, -13279, 29875, -13463, 29792, -13646, 29707, -13828, + 29622, -14010, 29535, -14192, 29448, -14373, 29359, -14553, + 29269, -14733, 29178, -14912, 29086, -15091, 28993, -15269, + 28899, -15447, 28803, -15624, 28707, -15800, 28610, -15976, + 28511, -16151, 28411, -16326, 28311, -16500, 28209, -16673, + 28106, -16846, 28002, -17018, 27897, -17190, 27791, -17361, + 27684, -17531, 27576, -17700, 27467, -17869, 27357, -18037, + 27246, -18205, 27133, -18372, 27020, -18538, 26906, -18703, + 26791, -18868, 26674, -19032, 26557, -19195, 26439, -19358, + 26320, -19520, 26199, -19681, 26078, -19841, 25956, -20001, + 25833, -20160, 25708, -20318, 25583, -20475, 25457, -20632, + 25330, -20788, 25202, -20943, 25073, -21097, 24943, -21251, + 24812, -21403, 24680, -21555, 24548, -21706, 24414, -21856, + 24279, -22006, 24144, -22154, 24008, -22302, 23870, -22449, + 23732, -22595, 23593, -22740, 23453, -22884, 23312, -23028, + 23170, -23170, 23028, -23312, 22884, -23453, 22740, -23593, + 22595, -23732, 22449, -23870, 22302, -24008, 22154, -24144, + 22006, -24279, 21856, -24414, 21706, -24548, 21555, -24680, + 21403, -24812, 21251, -24943, 21097, -25073, 20943, -25202, + 20788, -25330, 20632, -25457, 20475, -25583, 20318, -25708, + 20160, -25833, 20001, -25956, 19841, -26078, 19681, -26199, + 19520, -26320, 19358, -26439, 19195, -26557, 19032, -26674, + 18868, -26791, 18703, -26906, 18538, -27020, 18372, -27133, + 18205, -27246, 18037, -27357, 17869, -27467, 17700, -27576, + 17531, -27684, 17361, -27791, 17190, -27897, 17018, -28002, + 16846, -28106, 16673, -28209, 16500, -28311, 16326, -28411, + 16151, -28511, 15976, -28610, 15800, -28707, 15624, -28803, + 15447, -28899, 15269, -28993, 15091, -29086, 14912, -29178, + 14733, -29269, 14553, -29359, 14373, -29448, 14192, -29535, + 14010, -29622, 13828, -29707, 13646, -29792, 13463, -29875, + 13279, -29957, 13095, -30038, 12910, -30118, 12725, -30196, + 12540, -30274, 12354, -30350, 12167, -30425, 11980, -30499, + 11793, -30572, 11605, -30644, 11417, -30715, 11228, -30784, + 11039, -30853, 10850, -30920, 10660, -30986, 10469, -31050, + 10279, -31114, 10088, -31177, 9896, -31238, 9704, -31298, + 9512, -31357, 9319, -31415, 9127, -31471, 8933, -31527, + 8740, -31581, 8546, -31634, 8351, -31686, 8157, -31737, + 7962, -31786, 7767, -31834, 7571, -31881, 7376, -31927, + 7180, -31972, 6983, -32015, 6787, -32058, 6590, -32099, + 6393, -32138, 6195, -32177, 5998, -32214, 5800, -32251, + 5602, -32286, 5404, -32319, 5205, -32352, 5007, -32383, + 4808, -32413, 4609, -32442, 4410, -32470, 4211, -32496, + 4011, -32522, 3812, -32546, 3612, -32568, 3412, -32590, + 3212, -32610, 3012, -32629, 2811, -32647, 2611, -32664, + 2411, -32679, 2210, -32693, 2009, -32706, 1809, -32718, + 1608, -32729, 1407, -32738, 1206, -32746, 1005, -32753, + 804, -32758, 603, -32762, 402, -32766, 201, -32767, + 0, -32768, -201, -32767, -402, -32766, -603, -32762, + -804, -32758, -1005, -32753, -1206, -32746, -1407, -32738, + -1608, -32729, -1809, -32718, -2009, -32706, -2210, -32693, + -2411, -32679, -2611, -32664, -2811, -32647, -3012, -32629, + -3212, -32610, -3412, -32590, -3612, -32568, -3812, -32546, + -4011, -32522, -4211, -32496, -4410, -32470, -4609, -32442, + -4808, -32413, -5007, -32383, -5205, -32352, -5404, -32319, + -5602, -32286, -5800, -32251, -5998, -32214, -6195, -32177, + -6393, -32138, -6590, -32099, -6787, -32058, -6983, -32015, + -7180, -31972, -7376, -31927, -7571, -31881, -7767, -31834, + -7962, -31786, -8157, -31737, -8351, -31686, -8546, -31634, + -8740, -31581, -8933, -31527, -9127, -31471, -9319, -31415, + -9512, -31357, -9704, -31298, -9896, -31238, -10088, -31177, + -10279, -31114, -10469, -31050, -10660, -30986, -10850, -30920, + -11039, -30853, -11228, -30784, -11417, -30715, -11605, -30644, + -11793, -30572, -11980, -30499, -12167, -30425, -12354, -30350, + -12540, -30274, -12725, -30196, -12910, -30118, -13095, -30038, + -13279, -29957, -13463, -29875, -13646, -29792, -13828, -29707, + -14010, -29622, -14192, -29535, -14373, -29448, -14553, -29359, + -14733, -29269, -14912, -29178, -15091, -29086, -15269, -28993, + -15447, -28899, -15624, -28803, -15800, -28707, -15976, -28610, + -16151, -28511, -16326, -28411, -16500, -28311, -16673, -28209, + -16846, -28106, -17018, -28002, -17190, -27897, -17361, -27791, + -17531, -27684, -17700, -27576, -17869, -27467, -18037, -27357, + -18205, -27246, -18372, -27133, -18538, -27020, -18703, -26906, + -18868, -26791, -19032, -26674, -19195, -26557, -19358, -26439, + -19520, -26320, -19681, -26199, -19841, -26078, -20001, -25956, + -20160, -25833, -20318, -25708, -20475, -25583, -20632, -25457, + -20788, -25330, -20943, -25202, -21097, -25073, -21251, -24943, + -21403, -24812, -21555, -24680, -21706, -24548, -21856, -24414, + -22006, -24279, -22154, -24144, -22302, -24008, -22449, -23870, + -22595, -23732, -22740, -23593, -22884, -23453, -23028, -23312, + -23170, -23170, -23312, -23028, -23453, -22884, -23593, -22740, + -23732, -22595, -23870, -22449, -24008, -22302, -24144, -22154, + -24279, -22006, -24414, -21856, -24548, -21706, -24680, -21555, + -24812, -21403, -24943, -21251, -25073, -21097, -25202, -20943, + -25330, -20788, -25457, -20632, -25583, -20475, -25708, -20318, + -25833, -20160, -25956, -20001, -26078, -19841, -26199, -19681, + -26320, -19520, -26439, -19358, -26557, -19195, -26674, -19032, + -26791, -18868, -26906, -18703, -27020, -18538, -27133, -18372, + -27246, -18205, -27357, -18037, -27467, -17869, -27576, -17700, + -27684, -17531, -27791, -17361, -27897, -17190, -28002, -17018, + -28106, -16846, -28209, -16673, -28311, -16500, -28411, -16326, + -28511, -16151, -28610, -15976, -28707, -15800, -28803, -15624, + -28899, -15447, -28993, -15269, -29086, -15091, -29178, -14912, + -29269, -14733, -29359, -14553, -29448, -14373, -29535, -14192, + -29622, -14010, -29707, -13828, -29792, -13646, -29875, -13463, + -29957, -13279, -30038, -13095, -30118, -12910, -30196, -12725, + -30274, -12540, -30350, -12354, -30425, -12167, -30499, -11980, + -30572, -11793, -30644, -11605, -30715, -11417, -30784, -11228, + -30853, -11039, -30920, -10850, -30986, -10660, -31050, -10469, + -31114, -10279, -31177, -10088, -31238, -9896, -31298, -9704, + -31357, -9512, -31415, -9319, -31471, -9127, -31527, -8933, + -31581, -8740, -31634, -8546, -31686, -8351, -31737, -8157, + -31786, -7962, -31834, -7767, -31881, -7571, -31927, -7376, + -31972, -7180, -32015, -6983, -32058, -6787, -32099, -6590, + -32138, -6393, -32177, -6195, -32214, -5998, -32251, -5800, + -32286, -5602, -32319, -5404, -32352, -5205, -32383, -5007, + -32413, -4808, -32442, -4609, -32470, -4410, -32496, -4211, + -32522, -4011, -32546, -3812, -32568, -3612, -32590, -3412, + -32610, -3212, -32629, -3012, -32647, -2811, -32664, -2611, + -32679, -2411, -32693, -2210, -32706, -2009, -32718, -1809, + -32729, -1608, -32738, -1407, -32746, -1206, -32753, -1005, + -32758, -804, -32762, -603, -32766, -402, -32767, -201 +}; + +const Word16 FFT_REORDER_1024[512] = { + 0, 512, 256, 768, 128, 640, 384, 896, + 64, 576, 320, 832, 192, 704, 448, 960, + 32, 544, 288, 800, 160, 672, 416, 928, + 96, 608, 352, 864, 224, 736, 480, 992, + 16, 528, 272, 784, 144, 656, 400, 912, + 80, 592, 336, 848, 208, 720, 464, 976, + 48, 560, 304, 816, 176, 688, 432, 944, + 112, 624, 368, 880, 240, 752, 496, 1008, + 8, 520, 264, 776, 136, 648, 392, 904, + 72, 584, 328, 840, 200, 712, 456, 968, + 40, 552, 296, 808, 168, 680, 424, 936, + 104, 616, 360, 872, 232, 744, 488, 1000, + 24, 536, 280, 792, 152, 664, 408, 920, + 88, 600, 344, 856, 216, 728, 472, 984, + 56, 568, 312, 824, 184, 696, 440, 952, + 120, 632, 376, 888, 248, 760, 504, 1016, + 4, 516, 260, 772, 132, 644, 388, 900, + 68, 580, 324, 836, 196, 708, 452, 964, + 36, 548, 292, 804, 164, 676, 420, 932, + 100, 612, 356, 868, 228, 740, 484, 996, + 20, 532, 276, 788, 148, 660, 404, 916, + 84, 596, 340, 852, 212, 724, 468, 980, + 52, 564, 308, 820, 180, 692, 436, 948, + 116, 628, 372, 884, 244, 756, 500, 1012, + 12, 524, 268, 780, 140, 652, 396, 908, + 76, 588, 332, 844, 204, 716, 460, 972, + 44, 556, 300, 812, 172, 684, 428, 940, + 108, 620, 364, 876, 236, 748, 492, 1004, + 28, 540, 284, 796, 156, 668, 412, 924, + 92, 604, 348, 860, 220, 732, 476, 988, + 60, 572, 316, 828, 188, 700, 444, 956, + 124, 636, 380, 892, 252, 764, 508, 1020, + 2, 514, 258, 770, 130, 642, 386, 898, + 66, 578, 322, 834, 194, 706, 450, 962, + 34, 546, 290, 802, 162, 674, 418, 930, + 98, 610, 354, 866, 226, 738, 482, 994, + 18, 530, 274, 786, 146, 658, 402, 914, + 82, 594, 338, 850, 210, 722, 466, 978, + 50, 562, 306, 818, 178, 690, 434, 946, + 114, 626, 370, 882, 242, 754, 498, 1010, + 10, 522, 266, 778, 138, 650, 394, 906, + 74, 586, 330, 842, 202, 714, 458, 970, + 42, 554, 298, 810, 170, 682, 426, 938, + 106, 618, 362, 874, 234, 746, 490, 1002, + 26, 538, 282, 794, 154, 666, 410, 922, + 90, 602, 346, 858, 218, 730, 474, 986, + 58, 570, 314, 826, 186, 698, 442, 954, + 122, 634, 378, 890, 250, 762, 506, 1018, + 6, 518, 262, 774, 134, 646, 390, 902, + 70, 582, 326, 838, 198, 710, 454, 966, + 38, 550, 294, 806, 166, 678, 422, 934, + 102, 614, 358, 870, 230, 742, 486, 998, + 22, 534, 278, 790, 150, 662, 406, 918, + 86, 598, 342, 854, 214, 726, 470, 982, + 54, 566, 310, 822, 182, 694, 438, 950, + 118, 630, 374, 886, 246, 758, 502, 1014, + 14, 526, 270, 782, 142, 654, 398, 910, + 78, 590, 334, 846, 206, 718, 462, 974, + 46, 558, 302, 814, 174, 686, 430, 942, + 110, 622, 366, 878, 238, 750, 494, 1006, + 30, 542, 286, 798, 158, 670, 414, 926, + 94, 606, 350, 862, 222, 734, 478, 990, + 62, 574, 318, 830, 190, 702, 446, 958, + 126, 638, 382, 894, 254, 766, 510, 1022 +}; + +const Word16 Gamma_19661_Tbl_fx[] = { 19661, 11797, 7078, 4247, 2548, 1529, 917, 550, 330, 198, 119, 71, 43, 26, 16, 10 -};/*Q15 */ +}; /*Q15 */ -const Word16 Gamma_29491_Tbl[] = -{ +const Word16 Gamma_29491_Tbl[] = { 29491, 26542, 23888, 21499, 19349, 17414, 15672, 14105, - 12694, 11425, 10282, 9254, 8329, 7496, 6746, 6071 + 12694, 11425, 10282, 9254, 8329, 7496, 6746, 6071 }; /*---------------------------------------------------------------------* * NB post-filter tables *---------------------------------------------------------------------*/ -const Word16 Tab_hup_s[SIZ_TAB_HUP_S] = -{ - -188, 2873, 31650, -1597, -484, 7041, 28469, -2147, -933, 12266, - 23705, -1992, -1492, 18050, 18050, -1492, -1992, 23705, 12266, -933, - -2147, 28469, 7041, -484, -1597, 31650, 2873, -188 -}; - -const Word16 Tab_hup_l[SIZ_TAB_HUP_L] = -{ - -40, 72, -156, 315, -579, 1023, -1874, 4439, - 31915, -3390, 1595, -887, 501, -266, 130, -59, - -77, 147, -317, 631, -1150, 2030, -3773, 9639, - 29436, -5579, 2727, -1527, 859, -453, 218, -101, - -106, 212, -455, 892, -1614, 2850, -5392, 15206, - 25569, -6549, 3303, -1860, 1041, -543, 258, -122, - -123, 253, -538, 1044, -1876, 3319, -6414, 20676, - 20676, -6414, 3319, -1876, 1044, -538, 253, -123, - -122, 258, -543, 1041, -1860, 3303, -6549, 25569, - 15206, -5392, 2850, -1614, 892, -455, 212, -106, - -101, 218, -453, 859, -1527, 2727, -5579, 29436, - 9639, -3773, 2030, -1150, 631, -317, 147, -77, - -59, 130, -266, 501, -887, 1595, -3390, 31915, - 4439, -1874, 1023, -579, 315, -156, 72, -40 -}; - -const Word16 mfreq_loc_Q2fx[] = { 700, 1500, 3100, 4700, 6300, 7900, 9500, 11100, 12700, 14300, 15900, 17500, 19100, 20700, 22300, 25500, 28700, 31900 }; -const Word16 mfreq_loc_div_25[] = { 7, 15, 31, 47, 63, 79, 95, 111, 127, 143, 159, 175, 191, 207, 223, 255, 287, 319 }; - -//low_rate_band_att_fx.c +const Word16 Tab_hup_s[SIZ_TAB_HUP_S] = { + -188, 2873, 31650, -1597, -484, 7041, 28469, -2147, -933, 12266, + 23705, -1992, -1492, 18050, 18050, -1492, -1992, 23705, 12266, -933, + -2147, 28469, 7041, -484, -1597, 31650, 2873, -188 +}; + +const Word16 Tab_hup_l[SIZ_TAB_HUP_L] = { + -40, 72, -156, 315, -579, 1023, -1874, 4439, + 31915, -3390, 1595, -887, 501, -266, 130, -59, + -77, 147, -317, 631, -1150, 2030, -3773, 9639, + 29436, -5579, 2727, -1527, 859, -453, 218, -101, + -106, 212, -455, 892, -1614, 2850, -5392, 15206, + 25569, -6549, 3303, -1860, 1041, -543, 258, -122, + -123, 253, -538, 1044, -1876, 3319, -6414, 20676, + 20676, -6414, 3319, -1876, 1044, -538, 253, -123, + -122, 258, -543, 1041, -1860, 3303, -6549, 25569, + 15206, -5392, 2850, -1614, 892, -455, 212, -106, + -101, 218, -453, 859, -1527, 2727, -5579, 29436, + 9639, -3773, 2030, -1150, 631, -317, 147, -77, + -59, 130, -266, 501, -887, 1595, -3390, 31915, + 4439, -1874, 1023, -579, 315, -156, 72, -40 +}; + +const Word16 mfreq_loc_Q2fx[] = { 700, 1500, 3100, 4700, 6300, 7900, 9500, 11100, 12700, 14300, 15900, 17500, 19100, 20700, 22300, 25500, 28700, 31900 }; +const Word16 mfreq_loc_div_25[] = { 7, 15, 31, 47, 63, 79, 95, 111, 127, 143, 159, 175, 191, 207, 223, 255, 287, 319 }; + +// low_rate_band_att_fx.c /* %* lowered Table ROM, call with band_len_idx[sfm_size>>3] */ /* % sfms =[ 8, 16, 24, 32, 48, 64, 80, 96 ], */ /* sfm/8= [ 1 2 3 4 6 8 10 12]; */ /* % idx= 0 1 2 3 4 5 6 7; */ /* call with band_len_idx[sfm_size>>3] */ -const Word16 band_len_idx[1 + (MAX_SFM_LEN_FX / 8)] = -{ - /*sfm/8*/ /*1*/ /*2 */ /*3 */ /*4 */ /*6 */ /*8 */ /*10*/ /*12*/ - -1 , 0/*8*/, 1/*16*/,2/*24*/,3/*32*/,-1, 4/*48 */,-1, 5/*64 */,-1, 6/*80*/,-1, 7/*96*/ +const Word16 band_len_idx[1 + ( MAX_SFM_LEN_FX / 8 )] = { + /*sfm/8*/ /*1*/ /*2 */ /*3 */ /*4 */ /*6 */ /*8 */ /*10*/ /*12*/ + -1, 0 /*8*/, 1 /*16*/, 2 /*24*/, 3 /*32*/, -1, 4 /*48 */, -1, 5 /*64 */, -1, 6 /*80*/, -1, 7 /*96*/ }; -const Word16 band_len_ener_shift[8] = { 1, 2, 2, 2, 3, 3 , 4/*sfm==80*/, 4 /*sfm==96*/ }; /* 96 requires 1 bit more than 48 */ +const Word16 band_len_ener_shift[8] = { 1, 2, 2, 2, 3, 3, 4 /*sfm==80*/, 4 /*sfm==96*/ }; /* 96 requires 1 bit more than 48 */ /*% sfms=[8,16,24,32,48,64,80,96], round(sqrt(sfms)*2^11) */ -const Word16 fine_gain_pred_sqrt_bw[8] = { 5793, 8192, 10033, 11585, 14189, 16384, 18318 , 20066 }; /* (Q11) */ +const Word16 fine_gain_pred_sqrt_bw[8] = { 5793, 8192, 10033, 11585, 14189, 16384, 18318, 20066 }; /* (Q11) */ #ifdef IVAS_FLOAT_FIXED const Word16 ivas_band_len_idx[1 + ( MAX_SFM_LEN_FX / 8 )] = { /*sfm/8*/ /*1*/ /*2 */ /*3 */ /*4 */ /*6 */ /*8 */ /*10*/ /*12*/ @@ -41308,29 +41291,27 @@ const Word16 ivas_fine_gain_pred_sqrt_bw[9] = { 5793, 8192, 10033, 11585, 12953, /*----------------------------------------------------------------------------------* * means of ISFs for WB active speech *----------------------------------------------------------------------------------*/ -const Word16 Mean_isf_wb[M] = /* G722.2 active speech ISF's means */ -{ - 738, 1326, 2336, 3578, 4596, 5662, 6711, 7730, - 8750, 9753,10705, 11728, 12833, 13971,15043, 4037 -}; +const Word16 Mean_isf_wb[M] = /* G722.2 active speech ISF's means */ + { + 738, 1326, 2336, 3578, 4596, 5662, 6711, 7730, + 8750, 9753, 10705, 11728, 12833, 13971, 15043, 4037 + }; -const Word16 lsp_shb_prev_tbl_fx[LPC_SHB_ORDER] = -{ - /*Q15 */ - 0, - 1638, - 3277, - 4915, - 6554, - 8192, - 9830, - 11469, - 13107, - 14746 +const Word16 lsp_shb_prev_tbl_fx[LPC_SHB_ORDER] = { + /*Q15 */ + 0, + 1638, + 3277, + 4915, + 6554, + 8192, + 9830, + 11469, + 13107, + 14746 }; #ifdef IVAS_FLOAT_FIXED -const Word16 ivas_lsp_shb_prev_tbl_fx[LPC_SHB_ORDER] = -{ +const Word16 ivas_lsp_shb_prev_tbl_fx[LPC_SHB_ORDER] = { /* Q15 */ 1489, 2979, @@ -41349,129 +41330,124 @@ const Word16 ivas_lsp_shb_prev_tbl_fx[LPC_SHB_ORDER] = /* The value 0x0CCC should never be referenced, low is less/equal high */ /* The value 0x0BBB should never be referenced, loop must break instead. */ /* Refer to this table with indices: tab_ari_qnew[msb_high][msb_low] */ -const -Word16 tab_ari_qnew[4][4] = { { 0x0000, 0x0CCC, 0x0CCC, 0x0CCC }, - { 0x0000, 0x0000, 0x0CCC, 0x0CCC }, - { 0x0BBB, 0x2000, 0x4000, 0x0CCC }, - { 0x0BBB, 0x0BBB, 0x4000, 0x4000 } -}; - -const Word16 phs_tbl_dec[64 * 2] = -{ - /* part of table that is not scaled by 2 */ - 16384, 0, 16305, -1606, 16069, -3196, 15678, -4756, 15136, -6270, - 14449, -7723, 13622, -9102, 12665, -10394, 11585, -11585, 10394, -12665, - 9102, -13622, 7723, -14449, 6270, -15136, 4756, -15678, 3196, -16069, - 1606, -16305, 0, -16384, -1606, -16305, -3196, -16069, -4756, -15678, - -6270, -15136, -7723, -14449, -9102, -13622, -10394, -12665, -11585, -11585, - -12665, -10394, -13622, -9102, -14449, -7723, -15136, -6270, -15678, -4756, - -16069, -3196, -16305, -1606, - /* part of table that is scaled by 2 (this save one operation in FFT inner loops) */ - 32767, 0, 32610, -3212, 32138, -6392, 31356, -9512, 30272, -12540, - 28898, -15446, 27244, -18204, 25330, -20788, 23170, -23170, 20788, -25330, - 18204, -27244, 15446, -28898, 12540, -30272, 9512, -31356, 6392, -32138, - 3212, -32610, 0, -32768, -3212, -32610, -6392, -32138, -9512, -31356, - -12540, -30272, -15446, -28898, -18204, -27244, -20788, -25330, -23170, -23170, - -25330, -20788, -27244, -18204, -28898, -15446, -30272, -12540, -31356, -9512, - -32138, -6392, -32610, -3212 +const Word16 tab_ari_qnew[4][4] = { { 0x0000, 0x0CCC, 0x0CCC, 0x0CCC }, + { 0x0000, 0x0000, 0x0CCC, 0x0CCC }, + { 0x0BBB, 0x2000, 0x4000, 0x0CCC }, + { 0x0BBB, 0x0BBB, 0x4000, 0x4000 } }; + +const Word16 phs_tbl_dec[64 * 2] = { + /* part of table that is not scaled by 2 */ + 16384, 0, 16305, -1606, 16069, -3196, 15678, -4756, 15136, -6270, + 14449, -7723, 13622, -9102, 12665, -10394, 11585, -11585, 10394, -12665, + 9102, -13622, 7723, -14449, 6270, -15136, 4756, -15678, 3196, -16069, + 1606, -16305, 0, -16384, -1606, -16305, -3196, -16069, -4756, -15678, + -6270, -15136, -7723, -14449, -9102, -13622, -10394, -12665, -11585, -11585, + -12665, -10394, -13622, -9102, -14449, -7723, -15136, -6270, -15678, -4756, + -16069, -3196, -16305, -1606, + /* part of table that is scaled by 2 (this save one operation in FFT inner loops) */ + 32767, 0, 32610, -3212, 32138, -6392, 31356, -9512, 30272, -12540, + 28898, -15446, 27244, -18204, 25330, -20788, 23170, -23170, 20788, -25330, + 18204, -27244, 15446, -28898, 12540, -30272, 9512, -31356, 6392, -32138, + 3212, -32610, 0, -32768, -3212, -32610, -6392, -32138, -9512, -31356, + -12540, -30272, -15446, -28898, -18204, -27244, -20788, -25330, -23170, -23170, + -25330, -20788, -27244, -18204, -28898, -15446, -30272, -12540, -31356, -9512, + -32138, -6392, -32610, -3212 }; /* 2.0 - 6.4 kHz phase dispersion */ -const Word16 Low_H_phasedisp[L_SUBFR] = -{ - 16389, 16381, 16386, 16382, 16382, 16383, 16381, 16384, 16385, 10265, - 10154, 9894, 14052, 16343, -531, 13216, 16373, 15510, 9407, 15949, - 4726, 14593, 10404, 9796, -16336, -1815,-10623, 12647, 14556,-12683, - 11389, 8176, 16382,-14197, 11781, 10379, 7516, 10424,-12472, 16285, - -1200,-13137, 12659, -7446, 15684, -3763,-13418, -5280, 521, -9685, - -16375, -1219, 8436,-13059, -12861,-12775, 0, 3, 0, -2, - -1, -1, -1, 2 +const Word16 Low_H_phasedisp[L_SUBFR] = { + 16389, 16381, 16386, 16382, 16382, 16383, 16381, 16384, 16385, 10265, + 10154, 9894, 14052, 16343, -531, 13216, 16373, 15510, 9407, 15949, + 4726, 14593, 10404, 9796, -16336, -1815, -10623, 12647, 14556, -12683, + 11389, 8176, 16382, -14197, 11781, 10379, 7516, 10424, -12472, 16285, + -1200, -13137, 12659, -7446, 15684, -3763, -13418, -5280, 521, -9685, + -16375, -1219, 8436, -13059, -12861, -12775, 0, 3, 0, -2, + -1, -1, -1, 2 }; /* 3.2 - 6.4 kHz phase dispersion */ -const Word16 Mid_H_phasedisp[L_SUBFR] = -{ - 16382, 16382, 16384, 16385, 16386, 16388, 16387, 16383, 16387, 16383, - 16386, 16386, 16386, 16384, 16382, 16388, 14847, 9629, 13249, 14487, - 10995, 643, 13818, 13779, 6468, 8665, 11634, 9781,-14636, -982, - 11746, -722, 16386,-16365, -11422, 16354, 7363, 13148,-11538,-13903, - -15051, -8862, 8812,-16371, -12146, 7661, -9637,-13253, -6922, 4, - -4, -1, -5, 1, 7, 6, -7, -1, 4, -4, - 0, -1, -3, 3 -}; - -//ACcontextMapping_dec_fx.c -const Word16 Tab_esc_nb[4] = { 0 << (NBITS_CONTEXT + NBITS_RATEQ), - 1 << (NBITS_CONTEXT + NBITS_RATEQ), - 2 << (NBITS_CONTEXT + NBITS_RATEQ), - 3 << (NBITS_CONTEXT + NBITS_RATEQ) -}; +const Word16 Mid_H_phasedisp[L_SUBFR] = { + 16382, 16382, 16384, 16385, 16386, 16388, 16387, 16383, 16387, 16383, + 16386, 16386, 16386, 16384, 16382, 16388, 14847, 9629, 13249, 14487, + 10995, 643, 13818, 13779, 6468, 8665, 11634, 9781, -14636, -982, + 11746, -722, 16386, -16365, -11422, 16354, 7363, 13148, -11538, -13903, + -15051, -8862, 8812, -16371, -12146, 7661, -9637, -13253, -6922, 4, + -4, -1, -5, 1, 7, 6, -7, -1, 4, -4, + 0, -1, -3, 3 +}; + +// ACcontextMapping_dec_fx.c +const Word16 Tab_esc_nb[4] = { 0 << ( NBITS_CONTEXT + NBITS_RATEQ ), + 1 << ( NBITS_CONTEXT + NBITS_RATEQ ), + 2 << ( NBITS_CONTEXT + NBITS_RATEQ ), + 3 << ( NBITS_CONTEXT + NBITS_RATEQ ) }; const Word16 pow2tab[15] = { 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080, 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 }; -const Word32 pow2[] = -{ +const Word32 pow2[] = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576 }; -//d_gain2p.c -const Word16 Es_pred_qua[8] = -{ - 1521/* 5.9422f Q8*/, - 3909/*15.2711f Q8*/, - 5987/*23.3857f Q8*/, - 7816/*30.5310f Q8*/, - 9477/*37.0190f Q8*/, - 11124/*43.4539f Q8*/, - 12863/*50.2442f Q8*/, - 15031/*58.7164f Q8*/ -}; - -const Word16 Es_pred_qua_2[16] = -{ - -1280/*-5.f Q8*/, - 0/* 0.f Q8*/, - 1280/* 5.f Q8*/, - 2560/*10.f Q8*/, - 3840/*15.f Q8*/, - 5120/*20.f Q8*/, - 6400/*25.f Q8*/, - 7680/*30.f Q8*/, - 8960/*35.f Q8*/, - 10240/*40.f Q8*/, - 11520/*45.f Q8*/, - 12800/*50.f Q8*/, - 14080/*55.f Q8*/, - 15360/*60.f Q8*/, - 16640/*65.f Q8*/, - 17920/*70.f Q8*/ -}; -const Word16 T_DIV_L_Frame[] = /*0Q15 * 2^-7 */ -{ - 26214 /*160*/ - ,16384 /*256*/ - ,13107 /*320*/ - ,8738 /*480*/ - ,8192 /*512*/ - ,6553 /*640*/ -}; +// d_gain2p.c +const Word16 Es_pred_qua[8] = { + 1521 /* 5.9422f Q8*/, + 3909 /*15.2711f Q8*/, + 5987 /*23.3857f Q8*/, + 7816 /*30.5310f Q8*/, + 9477 /*37.0190f Q8*/, + 11124 /*43.4539f Q8*/, + 12863 /*50.2442f Q8*/, + 15031 /*58.7164f Q8*/ +}; + +const Word16 Es_pred_qua_2[16] = { + -1280 /*-5.f Q8*/, + 0 /* 0.f Q8*/, + 1280 /* 5.f Q8*/, + 2560 /*10.f Q8*/, + 3840 /*15.f Q8*/, + 5120 /*20.f Q8*/, + 6400 /*25.f Q8*/, + 7680 /*30.f Q8*/, + 8960 /*35.f Q8*/, + 10240 /*40.f Q8*/, + 11520 /*45.f Q8*/, + 12800 /*50.f Q8*/, + 14080 /*55.f Q8*/, + 15360 /*60.f Q8*/, + 16640 /*65.f Q8*/, + 17920 /*70.f Q8*/ +}; +const Word16 T_DIV_L_Frame[] = /*0Q15 * 2^-7 */ + { + 26214 /*160*/ + , + 16384 /*256*/ + , + 13107 /*320*/ + , + 8738 /*480*/ + , + 8192 /*512*/ + , + 6553 /*640*/ + }; /* order 8 LPF for nelp frames when non-native sampling freq inputs used with -max_band NB */ /* used to suppress frequencies above 4kHz present at the output of filters in pre_proc() */ -const Word16 num_nelp_lp_fx[NELP_LP_ORDER + 1] = /*Q13*/ -{ - 727, - 3506, - 8988, - 15029, - 17732, - 15022, - 8979, - 3501, - 726 -}; +const Word16 num_nelp_lp_fx[NELP_LP_ORDER + 1] = /*Q13*/ + { + 727, + 3506, + 8988, + 15029, + 17732, + 15022, + 8979, + 3501, + 726 + }; -const Word16 den_nelp_lp_fx[NELP_LP_ORDER + 1] = -{ +const Word16 den_nelp_lp_fx[NELP_LP_ORDER + 1] = { 8192, 8819, 21618, @@ -41486,164 +41462,267 @@ const Word16 den_nelp_lp_fx[NELP_LP_ORDER + 1] = /*----------------------------------------------------------------------------------* * AMR-WB IO WB BWE - band-pass 6-8kHz FIR filter, values in Q15: *----------------------------------------------------------------------------------*/ -const Word16 fir_6k_8k_fx[31] = -{ +const Word16 fir_6k_8k_fx[31] = { 44, -155, 323, -482, 563, -590, 726, -1180, 1986, -2818, 3028, -1991, -423, 3583, -6281, 7342, -6281, 3583, -423, -1991, 3028, -2818, 1986, -1180, 726, -590, 563, -482, 323, -155, 44 }; -const Word16 pwf78_fx[17] = { 25559, 19936, 15550, 12129, 9460, 7379, 5755, 4489, - 3501, 2731, 2130, 1661, 1296, 1011, 788, 615, - 479 -}; /* 0.78^i (i=1,...,17), Q15 */ +const Word16 pwf78_fx[17] = { 25559, 19936, 15550, 12129, 9460, 7379, 5755, 4489, + 3501, 2731, 2130, 1661, 1296, 1011, 788, 615, + 479 }; /* 0.78^i (i=1,...,17), Q15 */ /*------------------------------------------------------------------------------* * lag window for windowing the autocorrelations in LP analysis * Used in lib_enc\analy_lp_fx.c *------------------------------------------------------------------------------*/ -const Word16 Hamcos_Window[L_LP_AMR_WB] = -{ - 2621, 2622, 2626, 2632, 2640, 2650, 2662, 2677, - 2694, 2714, 2735, 2759, 2785, 2814, 2844, 2877, - 2912, 2949, 2989, 3031, 3075, 3121, 3169, 3220, - 3273, 3328, 3385, 3444, 3506, 3569, 3635, 3703, - 3773, 3845, 3919, 3996, 4074, 4155, 4237, 4321, - 4408, 4496, 4587, 4680, 4774, 4870, 4969, 5069, - 5171, 5275, 5381, 5489, 5599, 5710, 5824, 5939, - 6056, 6174, 6295, 6417, 6541, 6666, 6793, 6922, - 7052, 7185, 7318, 7453, 7590, 7728, 7868, 8009, - 8152, 8296, 8442, 8589, 8737, 8887, 9038, 9191, - 9344, 9499, 9655, 9813, 9971, 10131, 10292, 10454, - 10617, 10781, 10946, 11113, 11280, 11448, 11617, 11787, - 11958, 12130, 12303, 12476, 12650, 12825, 13001, 13178, - 13355, 13533, 13711, 13890, 14070, 14250, 14431, 14612, - 14793, 14975, 15158, 15341, 15524, 15708, 15891, 16076, - 16260, 16445, 16629, 16814, 16999, 17185, 17370, 17555, - 17740, 17926, 18111, 18296, 18481, 18666, 18851, 19036, - 19221, 19405, 19589, 19773, 19956, 20139, 20322, 20504, - 20686, 20867, 21048, 21229, 21408, 21588, 21767, 21945, - 22122, 22299, 22475, 22651, 22825, 22999, 23172, 23344, - 23516, 23686, 23856, 24025, 24192, 24359, 24525, 24689, - 24853, 25016, 25177, 25337, 25496, 25654, 25811, 25967, - 26121, 26274, 26426, 26576, 26725, 26873, 27019, 27164, - 27308, 27450, 27590, 27729, 27867, 28003, 28137, 28270, - 28401, 28531, 28659, 28785, 28910, 29033, 29154, 29274, - 29391, 29507, 29622, 29734, 29845, 29953, 30060, 30165, - 30268, 30370, 30469, 30566, 30662, 30755, 30847, 30936, - 31024, 31109, 31193, 31274, 31354, 31431, 31506, 31579, - 31651, 31719, 31786, 31851, 31914, 31974, 32032, 32088, - 32142, 32194, 32243, 32291, 32336, 32379, 32419, 32458, - 32494, 32528, 32560, 32589, 32617, 32642, 32664, 32685, - 32703, 32719, 32733, 32744, 32753, 32760, 32764, 32767, - 32767, 32765, 32757, 32745, 32727, 32705, 32678, 32646, - 32609, 32567, 32520, 32468, 32411, 32349, 32283, 32211, - 32135, 32054, 31968, 31877, 31781, 31681, 31575, 31465, - 31351, 31231, 31107, 30978, 30844, 30706, 30563, 30415, - 30263, 30106, 29945, 29779, 29609, 29434, 29255, 29071, - 28883, 28691, 28494, 28293, 28087, 27878, 27664, 27446, - 27224, 26997, 26767, 26533, 26294, 26052, 25806, 25555, - 25301, 25043, 24782, 24516, 24247, 23974, 23698, 23418, - 23134, 22847, 22557, 22263, 21965, 21665, 21361, 21054, - 20743, 20430, 20113, 19794, 19471, 19146, 18817, 18486, - 18152, 17815, 17476, 17134, 16789, 16442, 16092, 15740, - 15385, 15028, 14669, 14308, 13944, 13579, 13211, 12841, - 12470, 12096, 11721, 11344, 10965, 10584, 10202, 9819, - 9433, 9047, 8659, 8270, 7879, 7488, 7095, 6701, - 6306, 5910, 5514, 5116, 4718, 4319, 3919, 3519, - 3118, 2716, 2315, 1913, 1510, 1108, 705, 302 -}; - - -const Word16 CNG_burst_att_fx[6][8] = -{ - {30076, 27793, 25832, 24129, 22637, 21319, 20146, 19095}, - {29714, 27181, 25046, 23222, 21646, 20270, 20205, 20205}, - {29415, 26685, 24418, 22506, 22410, 22410, 22410, 22410}, - {29310, 26512, 24201, 23198, 23198, 23198, 23198, 23198}, - {29310, 26512, 24201, 23198, 23198, 23198, 23198, 23198}, - {29789, 27307, 25206, 23406, 21845, 20480, 19661, 19661} -}; - -const Word16 lpc_weights_fx[LPC_SHB_ORDER + 1] = -{ - 32767, 31948, 31150, 30371, 29612, - 28871, 28149, 27446, 26760, 26091, 25438 -}; - -const Word16 SHBCB_SubGain5bit_12_fx[128] = -{ - /*Q12 */ - -597, -1952, -1644, -1506, -1767, -1357, -1249, -874, - -4181, -3836, -240, -1985, -6573, -1480, -1229, -1094, - -381, -1655, -2119, -2406, -2012, -1022, -2235, -761, - -908, -1282, -1241, -1845, -68, -4666, -6058, -6355, - -2311, -1888, -1396, -513, -523, -1155, -2300, -3657, - -1161, -549, -2564, -2424, -609, -2346, -2934, -1142, - -3591, -2859, -2063, -205, -4048, -4083, -4261, -56, - -1352, -2147, -1894, -574, -6577, -5483, -1881, -628, - -815, -1061, -1987, -1654, -455, -1380, -3818, -4941, - -926, -934, -1463, -2630, -2520, -1013, -1016, -1250, - -977, -2477, -720, -2401, -130, -2789, -3155, -3192, - -1135, -1287, -1552, -1115, -1217, -1918, -1059, -1102, - -2291, -3353, -744, -979, -3067, -1892, -961, -707, - -1795, -1229, -652, -2348, -1569, -717, -1490, -1628, - -3240, -258, -2129, -2748, -2062, -1902, -625, -1257, - -1453, -1250, -965, -1445, -4227, -1494, -1108, -819, - - -}; - - -const Word16 E_ROM_inter4_1_fx[UP_SAMP * L_INTERPOL1 + 1] = -{ - /* cut-off frequency at 0.9*fs/2 */ - 14746/*0.900000F Q14*/, - 13418/*0.818959F Q14*/, 9910/*0.604850F Q14*/, 5429/*0.331379F Q14*/, 1376/*0.083958F Q14*/, - -1242/*-0.075795F Q14*/, -2142/*-0.130717F Q14*/, -1732/*-0.105685F Q14*/, -766/*-0.046774F Q14*/, - 73/*0.004467F Q14*/, 455/*0.027789F Q14*/, 420/*0.025642F Q14*/, 206/*0.012571F Q14*/, - 32/*0.001927F Q14*/, -26/*-0.001571F Q14*/, -12/*-0.000753F Q14*/, 0/*0.000000f Q14*/ -}; -const Word16 E_ROM_inter6_1_fx[PIT_UP_SAMP6 * L_INTERPOL1 + 1] = -{ - 14759/*0.900848F Q14*/, - 14158/*0.864136F Q14*/, - 12453/*0.760071F Q14*/, - 9919/*0.605408F Q14*/, - 6948/*0.424072F Q14*/, - 3972/*0.242462F Q14*/, - 1377/*0.0840759F Q14*/, - -563/*-0.0343933F Q14*/, - -1729/*-0.105560F Q14*/, - -2152/*-0.131348F Q14*/, - -1984/*-0.121124F Q14*/, - -1450/*-0.0884705F Q14*/, - -780/*-0.0476379F Q14*/, - -168/*-0.0102539F Q14*/, - 267/*0.0162964F Q14*/, - 485/*0.0296021F Q14*/, - 512/*0.0312195F Q14*/, - 412/*0.0251160F Q14*/, - 258/*0.0157471F Q14*/, - 110/*0.00671387F Q14*/, - 0/*0.000000F Q14*/, - -65/*-0.00399780F Q14*/, - -97/*-0.00592041F Q14*/, - -108/*-0.00656128F Q14*/, - 0/*0.000000F Q14*/ -}; -const Word16 kLog2TableFrac_x[256] = -{ - 0, 1, 3, 4, 6, 7, 9, 10, - 11, 13, 14, 16, 17, 18, 20, 21, - 22, 24, 25, 26, 28, 29, 30, 32, - 33, 34, 36, 37, 38, 40, 41, 42, - 44, 45, 46, 47, 49, 50, 51, 52, - 54, 55, 56, 57, 59, 60, 61, 62, - 63, 65, 66, 67, 68, 69, 71, 72, - 73, 74, 75, 77, 78, 79, 80, 81, - 82, 84, 85, 86, 87, 88, 89, 90, - 92, 93, 94, 95, 96, 97, 98, 99, +const Word16 Hamcos_Window[L_LP_AMR_WB] = { + 2621, 2622, 2626, 2632, 2640, 2650, 2662, 2677, + 2694, 2714, 2735, 2759, 2785, 2814, 2844, 2877, + 2912, 2949, 2989, 3031, 3075, 3121, 3169, 3220, + 3273, 3328, 3385, 3444, 3506, 3569, 3635, 3703, + 3773, 3845, 3919, 3996, 4074, 4155, 4237, 4321, + 4408, 4496, 4587, 4680, 4774, 4870, 4969, 5069, + 5171, 5275, 5381, 5489, 5599, 5710, 5824, 5939, + 6056, 6174, 6295, 6417, 6541, 6666, 6793, 6922, + 7052, 7185, 7318, 7453, 7590, 7728, 7868, 8009, + 8152, 8296, 8442, 8589, 8737, 8887, 9038, 9191, + 9344, 9499, 9655, 9813, 9971, 10131, 10292, 10454, + 10617, 10781, 10946, 11113, 11280, 11448, 11617, 11787, + 11958, 12130, 12303, 12476, 12650, 12825, 13001, 13178, + 13355, 13533, 13711, 13890, 14070, 14250, 14431, 14612, + 14793, 14975, 15158, 15341, 15524, 15708, 15891, 16076, + 16260, 16445, 16629, 16814, 16999, 17185, 17370, 17555, + 17740, 17926, 18111, 18296, 18481, 18666, 18851, 19036, + 19221, 19405, 19589, 19773, 19956, 20139, 20322, 20504, + 20686, 20867, 21048, 21229, 21408, 21588, 21767, 21945, + 22122, 22299, 22475, 22651, 22825, 22999, 23172, 23344, + 23516, 23686, 23856, 24025, 24192, 24359, 24525, 24689, + 24853, 25016, 25177, 25337, 25496, 25654, 25811, 25967, + 26121, 26274, 26426, 26576, 26725, 26873, 27019, 27164, + 27308, 27450, 27590, 27729, 27867, 28003, 28137, 28270, + 28401, 28531, 28659, 28785, 28910, 29033, 29154, 29274, + 29391, 29507, 29622, 29734, 29845, 29953, 30060, 30165, + 30268, 30370, 30469, 30566, 30662, 30755, 30847, 30936, + 31024, 31109, 31193, 31274, 31354, 31431, 31506, 31579, + 31651, 31719, 31786, 31851, 31914, 31974, 32032, 32088, + 32142, 32194, 32243, 32291, 32336, 32379, 32419, 32458, + 32494, 32528, 32560, 32589, 32617, 32642, 32664, 32685, + 32703, 32719, 32733, 32744, 32753, 32760, 32764, 32767, + 32767, 32765, 32757, 32745, 32727, 32705, 32678, 32646, + 32609, 32567, 32520, 32468, 32411, 32349, 32283, 32211, + 32135, 32054, 31968, 31877, 31781, 31681, 31575, 31465, + 31351, 31231, 31107, 30978, 30844, 30706, 30563, 30415, + 30263, 30106, 29945, 29779, 29609, 29434, 29255, 29071, + 28883, 28691, 28494, 28293, 28087, 27878, 27664, 27446, + 27224, 26997, 26767, 26533, 26294, 26052, 25806, 25555, + 25301, 25043, 24782, 24516, 24247, 23974, 23698, 23418, + 23134, 22847, 22557, 22263, 21965, 21665, 21361, 21054, + 20743, 20430, 20113, 19794, 19471, 19146, 18817, 18486, + 18152, 17815, 17476, 17134, 16789, 16442, 16092, 15740, + 15385, 15028, 14669, 14308, 13944, 13579, 13211, 12841, + 12470, 12096, 11721, 11344, 10965, 10584, 10202, 9819, + 9433, 9047, 8659, 8270, 7879, 7488, 7095, 6701, + 6306, 5910, 5514, 5116, 4718, 4319, 3919, 3519, + 3118, 2716, 2315, 1913, 1510, 1108, 705, 302 +}; + + +const Word16 CNG_burst_att_fx[6][8] = { + { 30076, 27793, 25832, 24129, 22637, 21319, 20146, 19095 }, + { 29714, 27181, 25046, 23222, 21646, 20270, 20205, 20205 }, + { 29415, 26685, 24418, 22506, 22410, 22410, 22410, 22410 }, + { 29310, 26512, 24201, 23198, 23198, 23198, 23198, 23198 }, + { 29310, 26512, 24201, 23198, 23198, 23198, 23198, 23198 }, + { 29789, 27307, 25206, 23406, 21845, 20480, 19661, 19661 } +}; + +const Word16 lpc_weights_fx[LPC_SHB_ORDER + 1] = { + 32767, 31948, 31150, 30371, 29612, + 28871, 28149, 27446, 26760, 26091, 25438 +}; + +const Word16 SHBCB_SubGain5bit_12_fx[128] = { + /*Q12 */ + -597, + -1952, + -1644, + -1506, + -1767, + -1357, + -1249, + -874, + -4181, + -3836, + -240, + -1985, + -6573, + -1480, + -1229, + -1094, + -381, + -1655, + -2119, + -2406, + -2012, + -1022, + -2235, + -761, + -908, + -1282, + -1241, + -1845, + -68, + -4666, + -6058, + -6355, + -2311, + -1888, + -1396, + -513, + -523, + -1155, + -2300, + -3657, + -1161, + -549, + -2564, + -2424, + -609, + -2346, + -2934, + -1142, + -3591, + -2859, + -2063, + -205, + -4048, + -4083, + -4261, + -56, + -1352, + -2147, + -1894, + -574, + -6577, + -5483, + -1881, + -628, + -815, + -1061, + -1987, + -1654, + -455, + -1380, + -3818, + -4941, + -926, + -934, + -1463, + -2630, + -2520, + -1013, + -1016, + -1250, + -977, + -2477, + -720, + -2401, + -130, + -2789, + -3155, + -3192, + -1135, + -1287, + -1552, + -1115, + -1217, + -1918, + -1059, + -1102, + -2291, + -3353, + -744, + -979, + -3067, + -1892, + -961, + -707, + -1795, + -1229, + -652, + -2348, + -1569, + -717, + -1490, + -1628, + -3240, + -258, + -2129, + -2748, + -2062, + -1902, + -625, + -1257, + -1453, + -1250, + -965, + -1445, + -4227, + -1494, + -1108, + -819, + + +}; + + +const Word16 E_ROM_inter4_1_fx[UP_SAMP * L_INTERPOL1 + 1] = { + /* cut-off frequency at 0.9*fs/2 */ + 14746 /*0.900000F Q14*/, + 13418 /*0.818959F Q14*/, 9910 /*0.604850F Q14*/, 5429 /*0.331379F Q14*/, 1376 /*0.083958F Q14*/, + -1242 /*-0.075795F Q14*/, -2142 /*-0.130717F Q14*/, -1732 /*-0.105685F Q14*/, -766 /*-0.046774F Q14*/, + 73 /*0.004467F Q14*/, 455 /*0.027789F Q14*/, 420 /*0.025642F Q14*/, 206 /*0.012571F Q14*/, + 32 /*0.001927F Q14*/, -26 /*-0.001571F Q14*/, -12 /*-0.000753F Q14*/, 0 /*0.000000f Q14*/ +}; +const Word16 E_ROM_inter6_1_fx[PIT_UP_SAMP6 * L_INTERPOL1 + 1] = { + 14759 /*0.900848F Q14*/, + 14158 /*0.864136F Q14*/, + 12453 /*0.760071F Q14*/, + 9919 /*0.605408F Q14*/, + 6948 /*0.424072F Q14*/, + 3972 /*0.242462F Q14*/, + 1377 /*0.0840759F Q14*/, + -563 /*-0.0343933F Q14*/, + -1729 /*-0.105560F Q14*/, + -2152 /*-0.131348F Q14*/, + -1984 /*-0.121124F Q14*/, + -1450 /*-0.0884705F Q14*/, + -780 /*-0.0476379F Q14*/, + -168 /*-0.0102539F Q14*/, + 267 /*0.0162964F Q14*/, + 485 /*0.0296021F Q14*/, + 512 /*0.0312195F Q14*/, + 412 /*0.0251160F Q14*/, + 258 /*0.0157471F Q14*/, + 110 /*0.00671387F Q14*/, + 0 /*0.000000F Q14*/, + -65 /*-0.00399780F Q14*/, + -97 /*-0.00592041F Q14*/, + -108 /*-0.00656128F Q14*/, + 0 /*0.000000F Q14*/ +}; +const Word16 kLog2TableFrac_x[256] = { + 0, 1, 3, 4, 6, 7, 9, 10, + 11, 13, 14, 16, 17, 18, 20, 21, + 22, 24, 25, 26, 28, 29, 30, 32, + 33, 34, 36, 37, 38, 40, 41, 42, + 44, 45, 46, 47, 49, 50, 51, 52, + 54, 55, 56, 57, 59, 60, 61, 62, + 63, 65, 66, 67, 68, 69, 71, 72, + 73, 74, 75, 77, 78, 79, 80, 81, + 82, 84, 85, 86, 87, 88, 89, 90, + 92, 93, 94, 95, 96, 97, 98, 99, 100, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, @@ -41668,64 +41747,64 @@ const Word16 kLog2TableFrac_x[256] = 250, 251, 252, 252, 253, 254, 255, 255 }; -const Word16 kExp2TableFrac_x[256] = /* Q15 */ -{ - 32767, 32678, 32590, 32502, 32414, 32326, 32239, 32152, - 32065, 31978, 31892, 31805, 31719, 31634, 31548, 31463, - 31378, 31293, 31208, 31124, 31040, 30956, 30872, 30789, - 30705, 30622, 30540, 30457, 30375, 30293, 30211, 30129, - 30047, 29966, 29885, 29804, 29724, 29643, 29563, 29483, - 29404, 29324, 29245, 29166, 29087, 29008, 28930, 28852, - 28774, 28696, 28618, 28541, 28464, 28387, 28310, 28233, - 28157, 28081, 28005, 27929, 27854, 27778, 27703, 27628, - 27554, 27479, 27405, 27331, 27257, 27183, 27110, 27036, - 26963, 26890, 26818, 26745, 26673, 26601, 26529, 26457, - 26385, 26314, 26243, 26172, 26101, 26031, 25960, 25890, - 25820, 25750, 25681, 25611, 25542, 25473, 25404, 25335, - 25267, 25198, 25130, 25062, 24995, 24927, 24860, 24792, - 24725, 24659, 24592, 24525, 24459, 24393, 24327, 24261, - 24196, 24130, 24065, 24000, 23935, 23870, 23806, 23741, - 23677, 23613, 23549, 23486, 23422, 23359, 23296, 23233, - 23170, 23107, 23045, 22982, 22920, 22858, 22796, 22735, - 22673, 22612, 22551, 22490, 22429, 22368, 22308, 22248, - 22187, 22127, 22068, 22008, 21948, 21889, 21830, 21771, - 21712, 21653, 21595, 21536, 21478, 21420, 21362, 21304, - 21247, 21189, 21132, 21075, 21018, 20961, 20904, 20848, - 20791, 20735, 20679, 20623, 20568, 20512, 20456, 20401, - 20346, 20291, 20236, 20181, 20127, 20072, 20018, 19964, - 19910, 19856, 19802, 19749, 19696, 19642, 19589, 19536, - 19483, 19431, 19378, 19326, 19274, 19221, 19169, 19118, - 19066, 19014, 18963, 18912, 18861, 18810, 18759, 18708, - 18657, 18607, 18557, 18506, 18456, 18406, 18357, 18307, - 18258, 18208, 18159, 18110, 18061, 18012, 17963, 17915, - 17866, 17818, 17770, 17722, 17674, 17626, 17578, 17531, - 17483, 17436, 17389, 17342, 17295, 17248, 17202, 17155, - 17109, 17063, 17016, 16970, 16925, 16879, 16833, 16788, - 16742, 16697, 16652, 16607, 16562, 16517, 16472, 16428 -}; +const Word16 kExp2TableFrac_x[256] = /* Q15 */ + { + 32767, 32678, 32590, 32502, 32414, 32326, 32239, 32152, + 32065, 31978, 31892, 31805, 31719, 31634, 31548, 31463, + 31378, 31293, 31208, 31124, 31040, 30956, 30872, 30789, + 30705, 30622, 30540, 30457, 30375, 30293, 30211, 30129, + 30047, 29966, 29885, 29804, 29724, 29643, 29563, 29483, + 29404, 29324, 29245, 29166, 29087, 29008, 28930, 28852, + 28774, 28696, 28618, 28541, 28464, 28387, 28310, 28233, + 28157, 28081, 28005, 27929, 27854, 27778, 27703, 27628, + 27554, 27479, 27405, 27331, 27257, 27183, 27110, 27036, + 26963, 26890, 26818, 26745, 26673, 26601, 26529, 26457, + 26385, 26314, 26243, 26172, 26101, 26031, 25960, 25890, + 25820, 25750, 25681, 25611, 25542, 25473, 25404, 25335, + 25267, 25198, 25130, 25062, 24995, 24927, 24860, 24792, + 24725, 24659, 24592, 24525, 24459, 24393, 24327, 24261, + 24196, 24130, 24065, 24000, 23935, 23870, 23806, 23741, + 23677, 23613, 23549, 23486, 23422, 23359, 23296, 23233, + 23170, 23107, 23045, 22982, 22920, 22858, 22796, 22735, + 22673, 22612, 22551, 22490, 22429, 22368, 22308, 22248, + 22187, 22127, 22068, 22008, 21948, 21889, 21830, 21771, + 21712, 21653, 21595, 21536, 21478, 21420, 21362, 21304, + 21247, 21189, 21132, 21075, 21018, 20961, 20904, 20848, + 20791, 20735, 20679, 20623, 20568, 20512, 20456, 20401, + 20346, 20291, 20236, 20181, 20127, 20072, 20018, 19964, + 19910, 19856, 19802, 19749, 19696, 19642, 19589, 19536, + 19483, 19431, 19378, 19326, 19274, 19221, 19169, 19118, + 19066, 19014, 18963, 18912, 18861, 18810, 18759, 18708, + 18657, 18607, 18557, 18506, 18456, 18406, 18357, 18307, + 18258, 18208, 18159, 18110, 18061, 18012, 17963, 17915, + 17866, 17818, 17770, 17722, 17674, 17626, 17578, 17531, + 17483, 17436, 17389, 17342, 17295, 17248, 17202, 17155, + 17109, 17063, 17016, 16970, 16925, 16879, 16833, 16788, + 16742, 16697, 16652, 16607, 16562, 16517, 16472, 16428 + }; /*-------------------------------------------------------------------* * inverse (reciprocal) of integer, used in FEC_fx.c, pitch_extr and in pitchDoubling_det * 1/n = One_div[n-1] *-------------------------------------------------------------------*/ -const Word16 One_div_fx[] = /* in Q15 */ -{ - 32767, /* 1/1 */ - 16384, /* 1/2 */ - 10923, /* 1/3 */ - 8192, /* 1/4 */ - 6554, /* 1/5 */ - 5461, /* 1/6 */ - 4681, /* 1/7 */ - 4096 /* 1/8 */ -}; +const Word16 One_div_fx[] = /* in Q15 */ + { + 32767, /* 1/1 */ + 16384, /* 1/2 */ + 10923, /* 1/3 */ + 8192, /* 1/4 */ + 6554, /* 1/5 */ + 5461, /* 1/6 */ + 4681, /* 1/7 */ + 4096 /* 1/8 */ + }; const Word32 tbl_two_pow_shift_by_4[35] = { - 1073741824, 902905664, 759250112, 638450688, 536870912, 451452832, 379625056, 319225344, - 268435456, 225726416, 189812528, 159612672, 134217728, 112863208, 94906264, 79806336, - 67108864, 56431604, 47453132, 39903168, 33554432, 28215802, 23726566, 19951584, - 16777216, 14107901, 11863283, 9975792, 8388608, 7053950, 5931641, 4987896, - 4194304, 3526975, 2965820 + 1073741824, 902905664, 759250112, 638450688, 536870912, 451452832, 379625056, 319225344, + 268435456, 225726416, 189812528, 159612672, 134217728, 112863208, 94906264, 79806336, + 67108864, 56431604, 47453132, 39903168, 33554432, 28215802, 23726566, 19951584, + 16777216, 14107901, 11863283, 9975792, 8388608, 7053950, 5931641, 4987896, + 4194304, 3526975, 2965820 }; @@ -42810,927 +42889,3769 @@ const Word16 cos_scale_tbl_512[512] = /* Q15 */ }; const Word16 sin_scale_tbl_1200[1200] = { /* Q15 */ - 0, 42, 85, 128, 171, 214, 257, 300, - 343, 386, 428, 471, 514, 557, 600, 643, - 686, 729, 771, 814, 857, 900, 943, 986, - 1029, 1072, 1114, 1157, 1200, 1243, 1286, 1329, - 1372, 1414, 1457, 1500, 1543, 1586, 1629, 1672, - 1714, 1757, 1800, 1843, 1886, 1929, 1971, 2014, - 2057, 2100, 2143, 2185, 2228, 2271, 2314, 2357, - 2399, 2442, 2485, 2528, 2570, 2613, 2656, 2699, - 2741, 2784, 2827, 2870, 2912, 2955, 2998, 3040, - 3083, 3126, 3169, 3211, 3254, 3297, 3339, 3382, - 3425, 3467, 3510, 3553, 3595, 3638, 3680, 3723, - 3766, 3808, 3851, 3893, 3936, 3979, 4021, 4064, - 4106, 4149, 4191, 4234, 4276, 4319, 4361, 4404, - 4446, 4489, 4531, 4574, 4616, 4659, 4701, 4744, - 4786, 4829, 4871, 4913, 4956, 4998, 5041, 5083, - 5125, 5168, 5210, 5252, 5295, 5337, 5379, 5422, - 5464, 5506, 5549, 5591, 5633, 5675, 5718, 5760, - 5802, 5844, 5886, 5929, 5971, 6013, 6055, 6097, - 6139, 6182, 6224, 6266, 6308, 6350, 6392, 6434, - 6476, 6518, 6560, 6602, 6644, 6686, 6728, 6770, - 6812, 6854, 6896, 6938, 6980, 7022, 7064, 7106, - 7147, 7189, 7231, 7273, 7315, 7357, 7398, 7440, - 7482, 7524, 7565, 7607, 7649, 7691, 7732, 7774, - 7816, 7857, 7899, 7940, 7982, 8024, 8065, 8107, - 8148, 8190, 8231, 8273, 8314, 8356, 8397, 8439, - 8480, 8522, 8563, 8604, 8646, 8687, 8729, 8770, - 8811, 8853, 8894, 8935, 8976, 9018, 9059, 9100, - 9141, 9182, 9224, 9265, 9306, 9347, 9388, 9429, - 9470, 9511, 9552, 9593, 9634, 9675, 9716, 9757, - 9798, 9839, 9880, 9921, 9962, 10003, 10043, 10084, - 10125, 10166, 10207, 10247, 10288, 10329, 10370, 10410, - 10451, 10491, 10532, 10573, 10613, 10654, 10694, 10735, - 10775, 10816, 10856, 10897, 10937, 10978, 11018, 11059, - 11099, 11139, 11180, 11220, 11260, 11300, 11341, 11381, - 11421, 11461, 11502, 11542, 11582, 11622, 11662, 11702, - 11742, 11782, 11822, 11862, 11902, 11942, 11982, 12022, - 12062, 12102, 12142, 12181, 12221, 12261, 12301, 12340, - 12380, 12420, 12460, 12499, 12539, 12579, 12618, 12658, - 12697, 12737, 12776, 12816, 12855, 12895, 12934, 12973, - 13013, 13052, 13092, 13131, 13170, 13209, 13249, 13288, - 13327, 13366, 13405, 13444, 13484, 13523, 13562, 13601, - 13640, 13679, 13718, 13757, 13796, 13834, 13873, 13912, - 13951, 13990, 14029, 14067, 14106, 14145, 14183, 14222, - 14261, 14299, 14338, 14376, 14415, 14453, 14492, 14530, - 14569, 14607, 14646, 14684, 14722, 14761, 14799, 14837, - 14875, 14914, 14952, 14990, 15028, 15066, 15104, 15142, - 15180, 15218, 15256, 15294, 15332, 15370, 15408, 15446, - 15484, 15521, 15559, 15597, 15635, 15672, 15710, 15748, - 15785, 15823, 15860, 15898, 15935, 15973, 16010, 16048, - 16085, 16122, 16160, 16197, 16234, 16271, 16309, 16346, - 16383, 16420, 16457, 16494, 16531, 16568, 16605, 16642, - 16679, 16716, 16753, 16790, 16827, 16863, 16900, 16937, - 16974, 17010, 17047, 17084, 17120, 17157, 17193, 17230, - 17266, 17303, 17339, 17375, 17412, 17448, 17484, 17521, - 17557, 17593, 17629, 17665, 17702, 17738, 17774, 17810, - 17846, 17882, 17918, 17953, 17989, 18025, 18061, 18097, - 18132, 18168, 18204, 18240, 18275, 18311, 18346, 18382, - 18417, 18453, 18488, 18524, 18559, 18594, 18630, 18665, - 18700, 18735, 18770, 18806, 18841, 18876, 18911, 18946, - 18981, 19016, 19051, 19086, 19120, 19155, 19190, 19225, - 19259, 19294, 19329, 19363, 19398, 19433, 19467, 19502, - 19536, 19570, 19605, 19639, 19673, 19708, 19742, 19776, - 19810, 19845, 19879, 19913, 19947, 19981, 20015, 20049, - 20083, 20117, 20150, 20184, 20218, 20252, 20285, 20319, - 20353, 20386, 20420, 20453, 20487, 20520, 20554, 20587, - 20620, 20654, 20687, 20720, 20753, 20787, 20820, 20853, - 20886, 20919, 20952, 20985, 21018, 21051, 21084, 21116, - 21149, 21182, 21215, 21247, 21280, 21313, 21345, 21378, - 21410, 21443, 21475, 21507, 21540, 21572, 21604, 21637, - 21669, 21701, 21733, 21765, 21797, 21829, 21861, 21893, - 21925, 21957, 21989, 22020, 22052, 22084, 22115, 22147, - 22179, 22210, 22242, 22273, 22305, 22336, 22367, 22399, - 22430, 22461, 22493, 22524, 22555, 22586, 22617, 22648, - 22679, 22710, 22741, 22772, 22802, 22833, 22864, 22895, - 22925, 22956, 22987, 23017, 23048, 23078, 23109, 23139, - 23169, 23200, 23230, 23260, 23290, 23320, 23351, 23381, - 23411, 23441, 23471, 23500, 23530, 23560, 23590, 23620, - 23649, 23679, 23709, 23738, 23768, 23797, 23827, 23856, - 23886, 23915, 23944, 23974, 24003, 24032, 24061, 24090, - 24119, 24148, 24177, 24206, 24235, 24264, 24293, 24321, - 24350, 24379, 24407, 24436, 24465, 24493, 24522, 24550, - 24578, 24607, 24635, 24663, 24692, 24720, 24748, 24776, - 24804, 24832, 24860, 24888, 24916, 24944, 24971, 24999, - 25027, 25054, 25082, 25110, 25137, 25165, 25192, 25220, - 25247, 25274, 25302, 25329, 25356, 25383, 25410, 25437, - 25464, 25491, 25518, 25545, 25572, 25599, 25625, 25652, - 25679, 25705, 25732, 25759, 25785, 25811, 25838, 25864, - 25891, 25917, 25943, 25969, 25995, 26021, 26047, 26073, - 26099, 26125, 26151, 26177, 26203, 26228, 26254, 26280, - 26305, 26331, 26356, 26382, 26407, 26433, 26458, 26483, - 26509, 26534, 26559, 26584, 26609, 26634, 26659, 26684, - 26709, 26734, 26758, 26783, 26808, 26832, 26857, 26882, - 26906, 26931, 26955, 26979, 27004, 27028, 27052, 27076, - 27100, 27125, 27149, 27173, 27197, 27220, 27244, 27268, - 27292, 27316, 27339, 27363, 27386, 27410, 27433, 27457, - 27480, 27504, 27527, 27550, 27573, 27596, 27620, 27643, - 27666, 27689, 27711, 27734, 27757, 27780, 27803, 27825, - 27848, 27871, 27893, 27916, 27938, 27960, 27983, 28005, - 28027, 28049, 28072, 28094, 28116, 28138, 28160, 28182, - 28203, 28225, 28247, 28269, 28290, 28312, 28334, 28355, - 28377, 28398, 28419, 28441, 28462, 28483, 28504, 28525, - 28547, 28568, 28589, 28610, 28630, 28651, 28672, 28693, - 28713, 28734, 28755, 28775, 28796, 28816, 28837, 28857, - 28877, 28897, 28918, 28938, 28958, 28978, 28998, 29018, - 29038, 29058, 29077, 29097, 29117, 29136, 29156, 29176, - 29195, 29215, 29234, 29253, 29273, 29292, 29311, 29330, - 29349, 29368, 29387, 29406, 29425, 29444, 29463, 29482, - 29500, 29519, 29537, 29556, 29575, 29593, 29611, 29630, - 29648, 29666, 29684, 29703, 29721, 29739, 29757, 29775, - 29792, 29810, 29828, 29846, 29863, 29881, 29899, 29916, - 29934, 29951, 29968, 29986, 30003, 30020, 30037, 30055, - 30072, 30089, 30106, 30122, 30139, 30156, 30173, 30190, - 30206, 30223, 30239, 30256, 30272, 30289, 30305, 30321, - 30338, 30354, 30370, 30386, 30402, 30418, 30434, 30450, - 30465, 30481, 30497, 30513, 30528, 30544, 30559, 30575, - 30590, 30605, 30621, 30636, 30651, 30666, 30681, 30696, - 30711, 30726, 30741, 30756, 30771, 30786, 30800, 30815, - 30829, 30844, 30858, 30873, 30887, 30901, 30916, 30930, - 30944, 30958, 30972, 30986, 31000, 31014, 31028, 31041, - 31055, 31069, 31082, 31096, 31109, 31123, 31136, 31149, - 31163, 31176, 31189, 31202, 31215, 31228, 31241, 31254, - 31267, 31280, 31293, 31305, 31318, 31331, 31343, 31356, - 31368, 31380, 31393, 31405, 31417, 31429, 31441, 31453, - 31465, 31477, 31489, 31501, 31513, 31525, 31536, 31548, - 31559, 31571, 31582, 31594, 31605, 31616, 31628, 31639, - 31650, 31661, 31672, 31683, 31694, 31705, 31716, 31726, - 31737, 31748, 31758, 31769, 31779, 31790, 31800, 31810, - 31821, 31831, 31841, 31851, 31861, 31871, 31881, 31891, - 31901, 31911, 31920, 31930, 31940, 31949, 31959, 31968, - 31977, 31987, 31996, 32005, 32014, 32023, 32033, 32042, - 32050, 32059, 32068, 32077, 32086, 32094, 32103, 32112, - 32120, 32128, 32137, 32145, 32154, 32162, 32170, 32178, - 32186, 32194, 32202, 32210, 32218, 32226, 32233, 32241, - 32249, 32256, 32264, 32271, 32279, 32286, 32293, 32300, - 32308, 32315, 32322, 32329, 32336, 32343, 32350, 32356, - 32363, 32370, 32376, 32383, 32389, 32396, 32402, 32409, - 32415, 32421, 32427, 32434, 32440, 32446, 32452, 32457, - 32463, 32469, 32475, 32481, 32486, 32492, 32497, 32503, - 32508, 32513, 32519, 32524, 32529, 32534, 32539, 32544, - 32549, 32554, 32559, 32564, 32569, 32573, 32578, 32582, - 32587, 32591, 32596, 32600, 32604, 32609, 32613, 32617, - 32621, 32625, 32629, 32633, 32637, 32641, 32644, 32648, - 32652, 32655, 32659, 32662, 32665, 32669, 32672, 32675, - 32679, 32682, 32685, 32688, 32691, 32694, 32696, 32699, - 32702, 32705, 32707, 32710, 32712, 32715, 32717, 32719, - 32722, 32724, 32726, 32728, 32730, 32732, 32734, 32736, - 32738, 32740, 32741, 32743, 32744, 32746, 32748, 32749, - 32750, 32752, 32753, 32754, 32755, 32756, 32757, 32758, - 32759, 32760, 32761, 32762, 32762, 32763, 32764, 32764, - 32765, 32765, 32765, 32766, 32766, 32766, 32766, 32766 + 0, 42, 85, 128, 171, 214, 257, 300, + 343, 386, 428, 471, 514, 557, 600, 643, + 686, 729, 771, 814, 857, 900, 943, 986, + 1029, 1072, 1114, 1157, 1200, 1243, 1286, 1329, + 1372, 1414, 1457, 1500, 1543, 1586, 1629, 1672, + 1714, 1757, 1800, 1843, 1886, 1929, 1971, 2014, + 2057, 2100, 2143, 2185, 2228, 2271, 2314, 2357, + 2399, 2442, 2485, 2528, 2570, 2613, 2656, 2699, + 2741, 2784, 2827, 2870, 2912, 2955, 2998, 3040, + 3083, 3126, 3169, 3211, 3254, 3297, 3339, 3382, + 3425, 3467, 3510, 3553, 3595, 3638, 3680, 3723, + 3766, 3808, 3851, 3893, 3936, 3979, 4021, 4064, + 4106, 4149, 4191, 4234, 4276, 4319, 4361, 4404, + 4446, 4489, 4531, 4574, 4616, 4659, 4701, 4744, + 4786, 4829, 4871, 4913, 4956, 4998, 5041, 5083, + 5125, 5168, 5210, 5252, 5295, 5337, 5379, 5422, + 5464, 5506, 5549, 5591, 5633, 5675, 5718, 5760, + 5802, 5844, 5886, 5929, 5971, 6013, 6055, 6097, + 6139, 6182, 6224, 6266, 6308, 6350, 6392, 6434, + 6476, 6518, 6560, 6602, 6644, 6686, 6728, 6770, + 6812, 6854, 6896, 6938, 6980, 7022, 7064, 7106, + 7147, 7189, 7231, 7273, 7315, 7357, 7398, 7440, + 7482, 7524, 7565, 7607, 7649, 7691, 7732, 7774, + 7816, 7857, 7899, 7940, 7982, 8024, 8065, 8107, + 8148, 8190, 8231, 8273, 8314, 8356, 8397, 8439, + 8480, 8522, 8563, 8604, 8646, 8687, 8729, 8770, + 8811, 8853, 8894, 8935, 8976, 9018, 9059, 9100, + 9141, 9182, 9224, 9265, 9306, 9347, 9388, 9429, + 9470, 9511, 9552, 9593, 9634, 9675, 9716, 9757, + 9798, 9839, 9880, 9921, 9962, 10003, 10043, 10084, + 10125, 10166, 10207, 10247, 10288, 10329, 10370, 10410, + 10451, 10491, 10532, 10573, 10613, 10654, 10694, 10735, + 10775, 10816, 10856, 10897, 10937, 10978, 11018, 11059, + 11099, 11139, 11180, 11220, 11260, 11300, 11341, 11381, + 11421, 11461, 11502, 11542, 11582, 11622, 11662, 11702, + 11742, 11782, 11822, 11862, 11902, 11942, 11982, 12022, + 12062, 12102, 12142, 12181, 12221, 12261, 12301, 12340, + 12380, 12420, 12460, 12499, 12539, 12579, 12618, 12658, + 12697, 12737, 12776, 12816, 12855, 12895, 12934, 12973, + 13013, 13052, 13092, 13131, 13170, 13209, 13249, 13288, + 13327, 13366, 13405, 13444, 13484, 13523, 13562, 13601, + 13640, 13679, 13718, 13757, 13796, 13834, 13873, 13912, + 13951, 13990, 14029, 14067, 14106, 14145, 14183, 14222, + 14261, 14299, 14338, 14376, 14415, 14453, 14492, 14530, + 14569, 14607, 14646, 14684, 14722, 14761, 14799, 14837, + 14875, 14914, 14952, 14990, 15028, 15066, 15104, 15142, + 15180, 15218, 15256, 15294, 15332, 15370, 15408, 15446, + 15484, 15521, 15559, 15597, 15635, 15672, 15710, 15748, + 15785, 15823, 15860, 15898, 15935, 15973, 16010, 16048, + 16085, 16122, 16160, 16197, 16234, 16271, 16309, 16346, + 16383, 16420, 16457, 16494, 16531, 16568, 16605, 16642, + 16679, 16716, 16753, 16790, 16827, 16863, 16900, 16937, + 16974, 17010, 17047, 17084, 17120, 17157, 17193, 17230, + 17266, 17303, 17339, 17375, 17412, 17448, 17484, 17521, + 17557, 17593, 17629, 17665, 17702, 17738, 17774, 17810, + 17846, 17882, 17918, 17953, 17989, 18025, 18061, 18097, + 18132, 18168, 18204, 18240, 18275, 18311, 18346, 18382, + 18417, 18453, 18488, 18524, 18559, 18594, 18630, 18665, + 18700, 18735, 18770, 18806, 18841, 18876, 18911, 18946, + 18981, 19016, 19051, 19086, 19120, 19155, 19190, 19225, + 19259, 19294, 19329, 19363, 19398, 19433, 19467, 19502, + 19536, 19570, 19605, 19639, 19673, 19708, 19742, 19776, + 19810, 19845, 19879, 19913, 19947, 19981, 20015, 20049, + 20083, 20117, 20150, 20184, 20218, 20252, 20285, 20319, + 20353, 20386, 20420, 20453, 20487, 20520, 20554, 20587, + 20620, 20654, 20687, 20720, 20753, 20787, 20820, 20853, + 20886, 20919, 20952, 20985, 21018, 21051, 21084, 21116, + 21149, 21182, 21215, 21247, 21280, 21313, 21345, 21378, + 21410, 21443, 21475, 21507, 21540, 21572, 21604, 21637, + 21669, 21701, 21733, 21765, 21797, 21829, 21861, 21893, + 21925, 21957, 21989, 22020, 22052, 22084, 22115, 22147, + 22179, 22210, 22242, 22273, 22305, 22336, 22367, 22399, + 22430, 22461, 22493, 22524, 22555, 22586, 22617, 22648, + 22679, 22710, 22741, 22772, 22802, 22833, 22864, 22895, + 22925, 22956, 22987, 23017, 23048, 23078, 23109, 23139, + 23169, 23200, 23230, 23260, 23290, 23320, 23351, 23381, + 23411, 23441, 23471, 23500, 23530, 23560, 23590, 23620, + 23649, 23679, 23709, 23738, 23768, 23797, 23827, 23856, + 23886, 23915, 23944, 23974, 24003, 24032, 24061, 24090, + 24119, 24148, 24177, 24206, 24235, 24264, 24293, 24321, + 24350, 24379, 24407, 24436, 24465, 24493, 24522, 24550, + 24578, 24607, 24635, 24663, 24692, 24720, 24748, 24776, + 24804, 24832, 24860, 24888, 24916, 24944, 24971, 24999, + 25027, 25054, 25082, 25110, 25137, 25165, 25192, 25220, + 25247, 25274, 25302, 25329, 25356, 25383, 25410, 25437, + 25464, 25491, 25518, 25545, 25572, 25599, 25625, 25652, + 25679, 25705, 25732, 25759, 25785, 25811, 25838, 25864, + 25891, 25917, 25943, 25969, 25995, 26021, 26047, 26073, + 26099, 26125, 26151, 26177, 26203, 26228, 26254, 26280, + 26305, 26331, 26356, 26382, 26407, 26433, 26458, 26483, + 26509, 26534, 26559, 26584, 26609, 26634, 26659, 26684, + 26709, 26734, 26758, 26783, 26808, 26832, 26857, 26882, + 26906, 26931, 26955, 26979, 27004, 27028, 27052, 27076, + 27100, 27125, 27149, 27173, 27197, 27220, 27244, 27268, + 27292, 27316, 27339, 27363, 27386, 27410, 27433, 27457, + 27480, 27504, 27527, 27550, 27573, 27596, 27620, 27643, + 27666, 27689, 27711, 27734, 27757, 27780, 27803, 27825, + 27848, 27871, 27893, 27916, 27938, 27960, 27983, 28005, + 28027, 28049, 28072, 28094, 28116, 28138, 28160, 28182, + 28203, 28225, 28247, 28269, 28290, 28312, 28334, 28355, + 28377, 28398, 28419, 28441, 28462, 28483, 28504, 28525, + 28547, 28568, 28589, 28610, 28630, 28651, 28672, 28693, + 28713, 28734, 28755, 28775, 28796, 28816, 28837, 28857, + 28877, 28897, 28918, 28938, 28958, 28978, 28998, 29018, + 29038, 29058, 29077, 29097, 29117, 29136, 29156, 29176, + 29195, 29215, 29234, 29253, 29273, 29292, 29311, 29330, + 29349, 29368, 29387, 29406, 29425, 29444, 29463, 29482, + 29500, 29519, 29537, 29556, 29575, 29593, 29611, 29630, + 29648, 29666, 29684, 29703, 29721, 29739, 29757, 29775, + 29792, 29810, 29828, 29846, 29863, 29881, 29899, 29916, + 29934, 29951, 29968, 29986, 30003, 30020, 30037, 30055, + 30072, 30089, 30106, 30122, 30139, 30156, 30173, 30190, + 30206, 30223, 30239, 30256, 30272, 30289, 30305, 30321, + 30338, 30354, 30370, 30386, 30402, 30418, 30434, 30450, + 30465, 30481, 30497, 30513, 30528, 30544, 30559, 30575, + 30590, 30605, 30621, 30636, 30651, 30666, 30681, 30696, + 30711, 30726, 30741, 30756, 30771, 30786, 30800, 30815, + 30829, 30844, 30858, 30873, 30887, 30901, 30916, 30930, + 30944, 30958, 30972, 30986, 31000, 31014, 31028, 31041, + 31055, 31069, 31082, 31096, 31109, 31123, 31136, 31149, + 31163, 31176, 31189, 31202, 31215, 31228, 31241, 31254, + 31267, 31280, 31293, 31305, 31318, 31331, 31343, 31356, + 31368, 31380, 31393, 31405, 31417, 31429, 31441, 31453, + 31465, 31477, 31489, 31501, 31513, 31525, 31536, 31548, + 31559, 31571, 31582, 31594, 31605, 31616, 31628, 31639, + 31650, 31661, 31672, 31683, 31694, 31705, 31716, 31726, + 31737, 31748, 31758, 31769, 31779, 31790, 31800, 31810, + 31821, 31831, 31841, 31851, 31861, 31871, 31881, 31891, + 31901, 31911, 31920, 31930, 31940, 31949, 31959, 31968, + 31977, 31987, 31996, 32005, 32014, 32023, 32033, 32042, + 32050, 32059, 32068, 32077, 32086, 32094, 32103, 32112, + 32120, 32128, 32137, 32145, 32154, 32162, 32170, 32178, + 32186, 32194, 32202, 32210, 32218, 32226, 32233, 32241, + 32249, 32256, 32264, 32271, 32279, 32286, 32293, 32300, + 32308, 32315, 32322, 32329, 32336, 32343, 32350, 32356, + 32363, 32370, 32376, 32383, 32389, 32396, 32402, 32409, + 32415, 32421, 32427, 32434, 32440, 32446, 32452, 32457, + 32463, 32469, 32475, 32481, 32486, 32492, 32497, 32503, + 32508, 32513, 32519, 32524, 32529, 32534, 32539, 32544, + 32549, 32554, 32559, 32564, 32569, 32573, 32578, 32582, + 32587, 32591, 32596, 32600, 32604, 32609, 32613, 32617, + 32621, 32625, 32629, 32633, 32637, 32641, 32644, 32648, + 32652, 32655, 32659, 32662, 32665, 32669, 32672, 32675, + 32679, 32682, 32685, 32688, 32691, 32694, 32696, 32699, + 32702, 32705, 32707, 32710, 32712, 32715, 32717, 32719, + 32722, 32724, 32726, 32728, 32730, 32732, 32734, 32736, + 32738, 32740, 32741, 32743, 32744, 32746, 32748, 32749, + 32750, 32752, 32753, 32754, 32755, 32756, 32757, 32758, + 32759, 32760, 32761, 32762, 32762, 32763, 32764, 32764, + 32765, 32765, 32765, 32766, 32766, 32766, 32766, 32766 }; const Word16 cos_scale_tbl_1200[1200] = { /* Q15 */ - 0, 42, 85, 128, 171, 214, 257, 300, - 343, 386, 428, 471, 514, 557, 600, 643, - 686, 729, 771, 814, 857, 900, 943, 986, - 1029, 1072, 1114, 1157, 1200, 1243, 1286, 1329, - 1372, 1414, 1457, 1500, 1543, 1586, 1629, 1672, - 1714, 1757, 1800, 1843, 1886, 1929, 1971, 2014, - 2057, 2100, 2143, 2185, 2228, 2271, 2314, 2357, - 2399, 2442, 2485, 2528, 2570, 2613, 2656, 2699, - 2741, 2784, 2827, 2870, 2912, 2955, 2998, 3040, - 3083, 3126, 3169, 3211, 3254, 3297, 3339, 3382, - 3425, 3467, 3510, 3553, 3595, 3638, 3680, 3723, - 3766, 3808, 3851, 3893, 3936, 3979, 4021, 4064, - 4106, 4149, 4191, 4234, 4276, 4319, 4361, 4404, - 4446, 4489, 4531, 4574, 4616, 4659, 4701, 4744, - 4786, 4829, 4871, 4913, 4956, 4998, 5041, 5083, - 5125, 5168, 5210, 5252, 5295, 5337, 5379, 5422, - 5464, 5506, 5549, 5591, 5633, 5675, 5718, 5760, - 5802, 5844, 5886, 5929, 5971, 6013, 6055, 6097, - 6139, 6182, 6224, 6266, 6308, 6350, 6392, 6434, - 6476, 6518, 6560, 6602, 6644, 6686, 6728, 6770, - 6812, 6854, 6896, 6938, 6980, 7022, 7064, 7106, - 7147, 7189, 7231, 7273, 7315, 7357, 7398, 7440, - 7482, 7524, 7565, 7607, 7649, 7691, 7732, 7774, - 7816, 7857, 7899, 7940, 7982, 8024, 8065, 8107, - 8148, 8190, 8231, 8273, 8314, 8356, 8397, 8439, - 8480, 8522, 8563, 8604, 8646, 8687, 8729, 8770, - 8811, 8853, 8894, 8935, 8976, 9018, 9059, 9100, - 9141, 9182, 9224, 9265, 9306, 9347, 9388, 9429, - 9470, 9511, 9552, 9593, 9634, 9675, 9716, 9757, - 9798, 9839, 9880, 9921, 9962, 10003, 10043, 10084, - 10125, 10166, 10207, 10247, 10288, 10329, 10370, 10410, - 10451, 10491, 10532, 10573, 10613, 10654, 10694, 10735, - 10775, 10816, 10856, 10897, 10937, 10978, 11018, 11059, - 11099, 11139, 11180, 11220, 11260, 11300, 11341, 11381, - 11421, 11461, 11502, 11542, 11582, 11622, 11662, 11702, - 11742, 11782, 11822, 11862, 11902, 11942, 11982, 12022, - 12062, 12102, 12142, 12181, 12221, 12261, 12301, 12340, - 12380, 12420, 12460, 12499, 12539, 12579, 12618, 12658, - 12697, 12737, 12776, 12816, 12855, 12895, 12934, 12973, - 13013, 13052, 13092, 13131, 13170, 13209, 13249, 13288, - 13327, 13366, 13405, 13444, 13484, 13523, 13562, 13601, - 13640, 13679, 13718, 13757, 13796, 13834, 13873, 13912, - 13951, 13990, 14029, 14067, 14106, 14145, 14183, 14222, - 14261, 14299, 14338, 14376, 14415, 14453, 14492, 14530, - 14569, 14607, 14646, 14684, 14722, 14761, 14799, 14837, - 14875, 14914, 14952, 14990, 15028, 15066, 15104, 15142, - 15180, 15218, 15256, 15294, 15332, 15370, 15408, 15446, - 15484, 15521, 15559, 15597, 15635, 15672, 15710, 15748, - 15785, 15823, 15860, 15898, 15935, 15973, 16010, 16048, - 16085, 16122, 16160, 16197, 16234, 16271, 16309, 16346, - 16383, 16420, 16457, 16494, 16531, 16568, 16605, 16642, - 16679, 16716, 16753, 16790, 16827, 16863, 16900, 16937, - 16974, 17010, 17047, 17084, 17120, 17157, 17193, 17230, - 17266, 17303, 17339, 17375, 17412, 17448, 17484, 17521, - 17557, 17593, 17629, 17665, 17702, 17738, 17774, 17810, - 17846, 17882, 17918, 17953, 17989, 18025, 18061, 18097, - 18132, 18168, 18204, 18240, 18275, 18311, 18346, 18382, - 18417, 18453, 18488, 18524, 18559, 18594, 18630, 18665, - 18700, 18735, 18770, 18806, 18841, 18876, 18911, 18946, - 18981, 19016, 19051, 19086, 19120, 19155, 19190, 19225, - 19259, 19294, 19329, 19363, 19398, 19433, 19467, 19502, - 19536, 19570, 19605, 19639, 19673, 19708, 19742, 19776, - 19810, 19845, 19879, 19913, 19947, 19981, 20015, 20049, - 20083, 20117, 20150, 20184, 20218, 20252, 20285, 20319, - 20353, 20386, 20420, 20453, 20487, 20520, 20554, 20587, - 20620, 20654, 20687, 20720, 20753, 20787, 20820, 20853, - 20886, 20919, 20952, 20985, 21018, 21051, 21084, 21116, - 21149, 21182, 21215, 21247, 21280, 21313, 21345, 21378, - 21410, 21443, 21475, 21507, 21540, 21572, 21604, 21637, - 21669, 21701, 21733, 21765, 21797, 21829, 21861, 21893, - 21925, 21957, 21989, 22020, 22052, 22084, 22115, 22147, - 22179, 22210, 22242, 22273, 22305, 22336, 22367, 22399, - 22430, 22461, 22493, 22524, 22555, 22586, 22617, 22648, - 22679, 22710, 22741, 22772, 22802, 22833, 22864, 22895, - 22925, 22956, 22987, 23017, 23048, 23078, 23109, 23139, - 23169, 23200, 23230, 23260, 23290, 23320, 23351, 23381, - 23411, 23441, 23471, 23500, 23530, 23560, 23590, 23620, - 23649, 23679, 23709, 23738, 23768, 23797, 23827, 23856, - 23886, 23915, 23944, 23974, 24003, 24032, 24061, 24090, - 24119, 24148, 24177, 24206, 24235, 24264, 24293, 24321, - 24350, 24379, 24407, 24436, 24465, 24493, 24522, 24550, - 24578, 24607, 24635, 24663, 24692, 24720, 24748, 24776, - 24804, 24832, 24860, 24888, 24916, 24944, 24971, 24999, - 25027, 25054, 25082, 25110, 25137, 25165, 25192, 25220, - 25247, 25274, 25302, 25329, 25356, 25383, 25410, 25437, - 25464, 25491, 25518, 25545, 25572, 25599, 25625, 25652, - 25679, 25705, 25732, 25759, 25785, 25811, 25838, 25864, - 25891, 25917, 25943, 25969, 25995, 26021, 26047, 26073, - 26099, 26125, 26151, 26177, 26203, 26228, 26254, 26280, - 26305, 26331, 26356, 26382, 26407, 26433, 26458, 26483, - 26509, 26534, 26559, 26584, 26609, 26634, 26659, 26684, - 26709, 26734, 26758, 26783, 26808, 26832, 26857, 26882, - 26906, 26931, 26955, 26979, 27004, 27028, 27052, 27076, - 27100, 27125, 27149, 27173, 27197, 27220, 27244, 27268, - 27292, 27316, 27339, 27363, 27386, 27410, 27433, 27457, - 27480, 27504, 27527, 27550, 27573, 27596, 27620, 27643, - 27666, 27689, 27711, 27734, 27757, 27780, 27803, 27825, - 27848, 27871, 27893, 27916, 27938, 27960, 27983, 28005, - 28027, 28049, 28072, 28094, 28116, 28138, 28160, 28182, - 28203, 28225, 28247, 28269, 28290, 28312, 28334, 28355, - 28377, 28398, 28419, 28441, 28462, 28483, 28504, 28525, - 28547, 28568, 28589, 28610, 28630, 28651, 28672, 28693, - 28713, 28734, 28755, 28775, 28796, 28816, 28837, 28857, - 28877, 28897, 28918, 28938, 28958, 28978, 28998, 29018, - 29038, 29058, 29077, 29097, 29117, 29136, 29156, 29176, - 29195, 29215, 29234, 29253, 29273, 29292, 29311, 29330, - 29349, 29368, 29387, 29406, 29425, 29444, 29463, 29482, - 29500, 29519, 29537, 29556, 29575, 29593, 29611, 29630, - 29648, 29666, 29684, 29703, 29721, 29739, 29757, 29775, - 29792, 29810, 29828, 29846, 29863, 29881, 29899, 29916, - 29934, 29951, 29968, 29986, 30003, 30020, 30037, 30055, - 30072, 30089, 30106, 30122, 30139, 30156, 30173, 30190, - 30206, 30223, 30239, 30256, 30272, 30289, 30305, 30321, - 30338, 30354, 30370, 30386, 30402, 30418, 30434, 30450, - 30465, 30481, 30497, 30513, 30528, 30544, 30559, 30575, - 30590, 30605, 30621, 30636, 30651, 30666, 30681, 30696, - 30711, 30726, 30741, 30756, 30771, 30786, 30800, 30815, - 30829, 30844, 30858, 30873, 30887, 30901, 30916, 30930, - 30944, 30958, 30972, 30986, 31000, 31014, 31028, 31041, - 31055, 31069, 31082, 31096, 31109, 31123, 31136, 31149, - 31163, 31176, 31189, 31202, 31215, 31228, 31241, 31254, - 31267, 31280, 31293, 31305, 31318, 31331, 31343, 31356, - 31368, 31380, 31393, 31405, 31417, 31429, 31441, 31453, - 31465, 31477, 31489, 31501, 31513, 31525, 31536, 31548, - 31559, 31571, 31582, 31594, 31605, 31616, 31628, 31639, - 31650, 31661, 31672, 31683, 31694, 31705, 31716, 31726, - 31737, 31748, 31758, 31769, 31779, 31790, 31800, 31810, - 31821, 31831, 31841, 31851, 31861, 31871, 31881, 31891, - 31901, 31911, 31920, 31930, 31940, 31949, 31959, 31968, - 31977, 31987, 31996, 32005, 32014, 32023, 32033, 32042, - 32050, 32059, 32068, 32077, 32086, 32094, 32103, 32112, - 32120, 32128, 32137, 32145, 32154, 32162, 32170, 32178, - 32186, 32194, 32202, 32210, 32218, 32226, 32233, 32241, - 32249, 32256, 32264, 32271, 32279, 32286, 32293, 32300, - 32308, 32315, 32322, 32329, 32336, 32343, 32350, 32356, - 32363, 32370, 32376, 32383, 32389, 32396, 32402, 32409, - 32415, 32421, 32427, 32434, 32440, 32446, 32452, 32457, - 32463, 32469, 32475, 32481, 32486, 32492, 32497, 32503, - 32508, 32513, 32519, 32524, 32529, 32534, 32539, 32544, - 32549, 32554, 32559, 32564, 32569, 32573, 32578, 32582, - 32587, 32591, 32596, 32600, 32604, 32609, 32613, 32617, - 32621, 32625, 32629, 32633, 32637, 32641, 32644, 32648, - 32652, 32655, 32659, 32662, 32665, 32669, 32672, 32675, - 32679, 32682, 32685, 32688, 32691, 32694, 32696, 32699, - 32702, 32705, 32707, 32710, 32712, 32715, 32717, 32719, - 32722, 32724, 32726, 32728, 32730, 32732, 32734, 32736, - 32738, 32740, 32741, 32743, 32744, 32746, 32748, 32749, - 32750, 32752, 32753, 32754, 32755, 32756, 32757, 32758, - 32759, 32760, 32761, 32762, 32762, 32763, 32764, 32764, - 32765, 32765, 32765, 32766, 32766, 32766, 32766, 32766 + 0, 42, 85, 128, 171, 214, 257, 300, + 343, 386, 428, 471, 514, 557, 600, 643, + 686, 729, 771, 814, 857, 900, 943, 986, + 1029, 1072, 1114, 1157, 1200, 1243, 1286, 1329, + 1372, 1414, 1457, 1500, 1543, 1586, 1629, 1672, + 1714, 1757, 1800, 1843, 1886, 1929, 1971, 2014, + 2057, 2100, 2143, 2185, 2228, 2271, 2314, 2357, + 2399, 2442, 2485, 2528, 2570, 2613, 2656, 2699, + 2741, 2784, 2827, 2870, 2912, 2955, 2998, 3040, + 3083, 3126, 3169, 3211, 3254, 3297, 3339, 3382, + 3425, 3467, 3510, 3553, 3595, 3638, 3680, 3723, + 3766, 3808, 3851, 3893, 3936, 3979, 4021, 4064, + 4106, 4149, 4191, 4234, 4276, 4319, 4361, 4404, + 4446, 4489, 4531, 4574, 4616, 4659, 4701, 4744, + 4786, 4829, 4871, 4913, 4956, 4998, 5041, 5083, + 5125, 5168, 5210, 5252, 5295, 5337, 5379, 5422, + 5464, 5506, 5549, 5591, 5633, 5675, 5718, 5760, + 5802, 5844, 5886, 5929, 5971, 6013, 6055, 6097, + 6139, 6182, 6224, 6266, 6308, 6350, 6392, 6434, + 6476, 6518, 6560, 6602, 6644, 6686, 6728, 6770, + 6812, 6854, 6896, 6938, 6980, 7022, 7064, 7106, + 7147, 7189, 7231, 7273, 7315, 7357, 7398, 7440, + 7482, 7524, 7565, 7607, 7649, 7691, 7732, 7774, + 7816, 7857, 7899, 7940, 7982, 8024, 8065, 8107, + 8148, 8190, 8231, 8273, 8314, 8356, 8397, 8439, + 8480, 8522, 8563, 8604, 8646, 8687, 8729, 8770, + 8811, 8853, 8894, 8935, 8976, 9018, 9059, 9100, + 9141, 9182, 9224, 9265, 9306, 9347, 9388, 9429, + 9470, 9511, 9552, 9593, 9634, 9675, 9716, 9757, + 9798, 9839, 9880, 9921, 9962, 10003, 10043, 10084, + 10125, 10166, 10207, 10247, 10288, 10329, 10370, 10410, + 10451, 10491, 10532, 10573, 10613, 10654, 10694, 10735, + 10775, 10816, 10856, 10897, 10937, 10978, 11018, 11059, + 11099, 11139, 11180, 11220, 11260, 11300, 11341, 11381, + 11421, 11461, 11502, 11542, 11582, 11622, 11662, 11702, + 11742, 11782, 11822, 11862, 11902, 11942, 11982, 12022, + 12062, 12102, 12142, 12181, 12221, 12261, 12301, 12340, + 12380, 12420, 12460, 12499, 12539, 12579, 12618, 12658, + 12697, 12737, 12776, 12816, 12855, 12895, 12934, 12973, + 13013, 13052, 13092, 13131, 13170, 13209, 13249, 13288, + 13327, 13366, 13405, 13444, 13484, 13523, 13562, 13601, + 13640, 13679, 13718, 13757, 13796, 13834, 13873, 13912, + 13951, 13990, 14029, 14067, 14106, 14145, 14183, 14222, + 14261, 14299, 14338, 14376, 14415, 14453, 14492, 14530, + 14569, 14607, 14646, 14684, 14722, 14761, 14799, 14837, + 14875, 14914, 14952, 14990, 15028, 15066, 15104, 15142, + 15180, 15218, 15256, 15294, 15332, 15370, 15408, 15446, + 15484, 15521, 15559, 15597, 15635, 15672, 15710, 15748, + 15785, 15823, 15860, 15898, 15935, 15973, 16010, 16048, + 16085, 16122, 16160, 16197, 16234, 16271, 16309, 16346, + 16383, 16420, 16457, 16494, 16531, 16568, 16605, 16642, + 16679, 16716, 16753, 16790, 16827, 16863, 16900, 16937, + 16974, 17010, 17047, 17084, 17120, 17157, 17193, 17230, + 17266, 17303, 17339, 17375, 17412, 17448, 17484, 17521, + 17557, 17593, 17629, 17665, 17702, 17738, 17774, 17810, + 17846, 17882, 17918, 17953, 17989, 18025, 18061, 18097, + 18132, 18168, 18204, 18240, 18275, 18311, 18346, 18382, + 18417, 18453, 18488, 18524, 18559, 18594, 18630, 18665, + 18700, 18735, 18770, 18806, 18841, 18876, 18911, 18946, + 18981, 19016, 19051, 19086, 19120, 19155, 19190, 19225, + 19259, 19294, 19329, 19363, 19398, 19433, 19467, 19502, + 19536, 19570, 19605, 19639, 19673, 19708, 19742, 19776, + 19810, 19845, 19879, 19913, 19947, 19981, 20015, 20049, + 20083, 20117, 20150, 20184, 20218, 20252, 20285, 20319, + 20353, 20386, 20420, 20453, 20487, 20520, 20554, 20587, + 20620, 20654, 20687, 20720, 20753, 20787, 20820, 20853, + 20886, 20919, 20952, 20985, 21018, 21051, 21084, 21116, + 21149, 21182, 21215, 21247, 21280, 21313, 21345, 21378, + 21410, 21443, 21475, 21507, 21540, 21572, 21604, 21637, + 21669, 21701, 21733, 21765, 21797, 21829, 21861, 21893, + 21925, 21957, 21989, 22020, 22052, 22084, 22115, 22147, + 22179, 22210, 22242, 22273, 22305, 22336, 22367, 22399, + 22430, 22461, 22493, 22524, 22555, 22586, 22617, 22648, + 22679, 22710, 22741, 22772, 22802, 22833, 22864, 22895, + 22925, 22956, 22987, 23017, 23048, 23078, 23109, 23139, + 23169, 23200, 23230, 23260, 23290, 23320, 23351, 23381, + 23411, 23441, 23471, 23500, 23530, 23560, 23590, 23620, + 23649, 23679, 23709, 23738, 23768, 23797, 23827, 23856, + 23886, 23915, 23944, 23974, 24003, 24032, 24061, 24090, + 24119, 24148, 24177, 24206, 24235, 24264, 24293, 24321, + 24350, 24379, 24407, 24436, 24465, 24493, 24522, 24550, + 24578, 24607, 24635, 24663, 24692, 24720, 24748, 24776, + 24804, 24832, 24860, 24888, 24916, 24944, 24971, 24999, + 25027, 25054, 25082, 25110, 25137, 25165, 25192, 25220, + 25247, 25274, 25302, 25329, 25356, 25383, 25410, 25437, + 25464, 25491, 25518, 25545, 25572, 25599, 25625, 25652, + 25679, 25705, 25732, 25759, 25785, 25811, 25838, 25864, + 25891, 25917, 25943, 25969, 25995, 26021, 26047, 26073, + 26099, 26125, 26151, 26177, 26203, 26228, 26254, 26280, + 26305, 26331, 26356, 26382, 26407, 26433, 26458, 26483, + 26509, 26534, 26559, 26584, 26609, 26634, 26659, 26684, + 26709, 26734, 26758, 26783, 26808, 26832, 26857, 26882, + 26906, 26931, 26955, 26979, 27004, 27028, 27052, 27076, + 27100, 27125, 27149, 27173, 27197, 27220, 27244, 27268, + 27292, 27316, 27339, 27363, 27386, 27410, 27433, 27457, + 27480, 27504, 27527, 27550, 27573, 27596, 27620, 27643, + 27666, 27689, 27711, 27734, 27757, 27780, 27803, 27825, + 27848, 27871, 27893, 27916, 27938, 27960, 27983, 28005, + 28027, 28049, 28072, 28094, 28116, 28138, 28160, 28182, + 28203, 28225, 28247, 28269, 28290, 28312, 28334, 28355, + 28377, 28398, 28419, 28441, 28462, 28483, 28504, 28525, + 28547, 28568, 28589, 28610, 28630, 28651, 28672, 28693, + 28713, 28734, 28755, 28775, 28796, 28816, 28837, 28857, + 28877, 28897, 28918, 28938, 28958, 28978, 28998, 29018, + 29038, 29058, 29077, 29097, 29117, 29136, 29156, 29176, + 29195, 29215, 29234, 29253, 29273, 29292, 29311, 29330, + 29349, 29368, 29387, 29406, 29425, 29444, 29463, 29482, + 29500, 29519, 29537, 29556, 29575, 29593, 29611, 29630, + 29648, 29666, 29684, 29703, 29721, 29739, 29757, 29775, + 29792, 29810, 29828, 29846, 29863, 29881, 29899, 29916, + 29934, 29951, 29968, 29986, 30003, 30020, 30037, 30055, + 30072, 30089, 30106, 30122, 30139, 30156, 30173, 30190, + 30206, 30223, 30239, 30256, 30272, 30289, 30305, 30321, + 30338, 30354, 30370, 30386, 30402, 30418, 30434, 30450, + 30465, 30481, 30497, 30513, 30528, 30544, 30559, 30575, + 30590, 30605, 30621, 30636, 30651, 30666, 30681, 30696, + 30711, 30726, 30741, 30756, 30771, 30786, 30800, 30815, + 30829, 30844, 30858, 30873, 30887, 30901, 30916, 30930, + 30944, 30958, 30972, 30986, 31000, 31014, 31028, 31041, + 31055, 31069, 31082, 31096, 31109, 31123, 31136, 31149, + 31163, 31176, 31189, 31202, 31215, 31228, 31241, 31254, + 31267, 31280, 31293, 31305, 31318, 31331, 31343, 31356, + 31368, 31380, 31393, 31405, 31417, 31429, 31441, 31453, + 31465, 31477, 31489, 31501, 31513, 31525, 31536, 31548, + 31559, 31571, 31582, 31594, 31605, 31616, 31628, 31639, + 31650, 31661, 31672, 31683, 31694, 31705, 31716, 31726, + 31737, 31748, 31758, 31769, 31779, 31790, 31800, 31810, + 31821, 31831, 31841, 31851, 31861, 31871, 31881, 31891, + 31901, 31911, 31920, 31930, 31940, 31949, 31959, 31968, + 31977, 31987, 31996, 32005, 32014, 32023, 32033, 32042, + 32050, 32059, 32068, 32077, 32086, 32094, 32103, 32112, + 32120, 32128, 32137, 32145, 32154, 32162, 32170, 32178, + 32186, 32194, 32202, 32210, 32218, 32226, 32233, 32241, + 32249, 32256, 32264, 32271, 32279, 32286, 32293, 32300, + 32308, 32315, 32322, 32329, 32336, 32343, 32350, 32356, + 32363, 32370, 32376, 32383, 32389, 32396, 32402, 32409, + 32415, 32421, 32427, 32434, 32440, 32446, 32452, 32457, + 32463, 32469, 32475, 32481, 32486, 32492, 32497, 32503, + 32508, 32513, 32519, 32524, 32529, 32534, 32539, 32544, + 32549, 32554, 32559, 32564, 32569, 32573, 32578, 32582, + 32587, 32591, 32596, 32600, 32604, 32609, 32613, 32617, + 32621, 32625, 32629, 32633, 32637, 32641, 32644, 32648, + 32652, 32655, 32659, 32662, 32665, 32669, 32672, 32675, + 32679, 32682, 32685, 32688, 32691, 32694, 32696, 32699, + 32702, 32705, 32707, 32710, 32712, 32715, 32717, 32719, + 32722, 32724, 32726, 32728, 32730, 32732, 32734, 32736, + 32738, 32740, 32741, 32743, 32744, 32746, 32748, 32749, + 32750, 32752, 32753, 32754, 32755, 32756, 32757, 32758, + 32759, 32760, 32761, 32762, 32762, 32763, 32764, 32764, + 32765, 32765, 32765, 32766, 32766, 32766, 32766, 32766 }; const Word16 sin_scale_tbl_800[800] = { /* Q15 */ - 0, 64, 128, 193, 257, 321, 386, 450, - 514, 579, 643, 707, 771, 836, 900, 964, - 1029, 1093, 1157, 1222, 1286, 1350, 1414, 1479, - 1543, 1607, 1672, 1736, 1800, 1864, 1929, 1993, - 2057, 2121, 2185, 2250, 2314, 2378, 2442, 2506, - 2570, 2635, 2699, 2763, 2827, 2891, 2955, 3019, - 3083, 3147, 3211, 3275, 3339, 3403, 3467, 3531, - 3595, 3659, 3723, 3787, 3851, 3915, 3979, 4042, - 4106, 4170, 4234, 4298, 4361, 4425, 4489, 4553, - 4616, 4680, 4744, 4807, 4871, 4935, 4998, 5062, - 5125, 5189, 5252, 5316, 5379, 5443, 5506, 5570, - 5633, 5696, 5760, 5823, 5886, 5950, 6013, 6076, - 6139, 6203, 6266, 6329, 6392, 6455, 6518, 6581, - 6644, 6707, 6770, 6833, 6896, 6959, 7022, 7085, - 7147, 7210, 7273, 7336, 7398, 7461, 7524, 7586, - 7649, 7711, 7774, 7836, 7899, 7961, 8024, 8086, - 8148, 8211, 8273, 8335, 8397, 8460, 8522, 8584, - 8646, 8708, 8770, 8832, 8894, 8956, 9018, 9079, - 9141, 9203, 9265, 9326, 9388, 9450, 9511, 9573, - 9634, 9696, 9757, 9819, 9880, 9941, 10003, 10064, - 10125, 10186, 10247, 10308, 10370, 10431, 10491, 10552, - 10613, 10674, 10735, 10796, 10856, 10917, 10978, 11038, - 11099, 11159, 11220, 11280, 11341, 11401, 11461, 11522, - 11582, 11642, 11702, 11762, 11822, 11882, 11942, 12002, - 12062, 12122, 12181, 12241, 12301, 12360, 12420, 12479, - 12539, 12598, 12658, 12717, 12776, 12835, 12895, 12954, - 13013, 13072, 13131, 13190, 13249, 13307, 13366, 13425, - 13484, 13542, 13601, 13659, 13718, 13776, 13834, 13893, - 13951, 14009, 14067, 14125, 14183, 14241, 14299, 14357, - 14415, 14473, 14530, 14588, 14646, 14703, 14761, 14818, - 14875, 14933, 14990, 15047, 15104, 15161, 15218, 15275, - 15332, 15389, 15446, 15502, 15559, 15616, 15672, 15729, - 15785, 15841, 15898, 15954, 16010, 16066, 16122, 16178, - 16234, 16290, 16346, 16402, 16457, 16513, 16568, 16624, - 16679, 16735, 16790, 16845, 16900, 16955, 17010, 17065, - 17120, 17175, 17230, 17284, 17339, 17394, 17448, 17503, - 17557, 17611, 17665, 17720, 17774, 17828, 17882, 17936, - 17989, 18043, 18097, 18150, 18204, 18257, 18311, 18364, - 18417, 18470, 18524, 18577, 18630, 18682, 18735, 18788, - 18841, 18893, 18946, 18998, 19051, 19103, 19155, 19207, - 19259, 19311, 19363, 19415, 19467, 19519, 19570, 19622, - 19673, 19725, 19776, 19827, 19879, 19930, 19981, 20032, - 20083, 20133, 20184, 20235, 20285, 20336, 20386, 20437, - 20487, 20537, 20587, 20637, 20687, 20737, 20787, 20836, - 20886, 20936, 20985, 21034, 21084, 21133, 21182, 21231, - 21280, 21329, 21378, 21426, 21475, 21524, 21572, 21620, - 21669, 21717, 21765, 21813, 21861, 21909, 21957, 22004, - 22052, 22100, 22147, 22194, 22242, 22289, 22336, 22383, - 22430, 22477, 22524, 22570, 22617, 22663, 22710, 22756, - 22802, 22849, 22895, 22941, 22987, 23032, 23078, 23124, - 23169, 23215, 23260, 23305, 23351, 23396, 23441, 23486, - 23530, 23575, 23620, 23664, 23709, 23753, 23797, 23842, - 23886, 23930, 23974, 24017, 24061, 24105, 24148, 24192, - 24235, 24278, 24321, 24364, 24407, 24450, 24493, 24536, - 24578, 24621, 24663, 24706, 24748, 24790, 24832, 24874, - 24916, 24957, 24999, 25041, 25082, 25123, 25165, 25206, - 25247, 25288, 25329, 25370, 25410, 25451, 25491, 25532, - 25572, 25612, 25652, 25692, 25732, 25772, 25811, 25851, - 25891, 25930, 25969, 26008, 26047, 26086, 26125, 26164, - 26203, 26241, 26280, 26318, 26356, 26395, 26433, 26471, - 26509, 26546, 26584, 26622, 26659, 26696, 26734, 26771, - 26808, 26845, 26882, 26918, 26955, 26991, 27028, 27064, - 27100, 27137, 27173, 27208, 27244, 27280, 27316, 27351, - 27386, 27422, 27457, 27492, 27527, 27562, 27596, 27631, - 27666, 27700, 27734, 27769, 27803, 27837, 27871, 27904, - 27938, 27972, 28005, 28038, 28072, 28105, 28138, 28171, - 28203, 28236, 28269, 28301, 28334, 28366, 28398, 28430, - 28462, 28494, 28525, 28557, 28589, 28620, 28651, 28682, - 28713, 28744, 28775, 28806, 28837, 28867, 28897, 28928, - 28958, 28988, 29018, 29048, 29077, 29107, 29136, 29166, - 29195, 29224, 29253, 29282, 29311, 29340, 29368, 29397, - 29425, 29453, 29482, 29510, 29537, 29565, 29593, 29621, - 29648, 29675, 29703, 29730, 29757, 29784, 29810, 29837, - 29863, 29890, 29916, 29942, 29968, 29994, 30020, 30046, - 30072, 30097, 30122, 30148, 30173, 30198, 30223, 30248, - 30272, 30297, 30321, 30346, 30370, 30394, 30418, 30442, - 30465, 30489, 30513, 30536, 30559, 30582, 30605, 30628, - 30651, 30674, 30696, 30719, 30741, 30763, 30786, 30807, - 30829, 30851, 30873, 30894, 30916, 30937, 30958, 30979, - 31000, 31021, 31041, 31062, 31082, 31103, 31123, 31143, - 31163, 31183, 31202, 31222, 31241, 31261, 31280, 31299, - 31318, 31337, 31356, 31374, 31393, 31411, 31429, 31447, - 31465, 31483, 31501, 31519, 31536, 31554, 31571, 31588, - 31605, 31622, 31639, 31656, 31672, 31689, 31705, 31721, - 31737, 31753, 31769, 31785, 31800, 31816, 31831, 31846, - 31861, 31876, 31891, 31906, 31920, 31935, 31949, 31963, - 31977, 31991, 32005, 32019, 32033, 32046, 32059, 32073, - 32086, 32099, 32112, 32124, 32137, 32149, 32162, 32174, - 32186, 32198, 32210, 32222, 32233, 32245, 32256, 32267, - 32279, 32290, 32300, 32311, 32322, 32332, 32343, 32353, - 32363, 32373, 32383, 32393, 32402, 32412, 32421, 32430, - 32440, 32449, 32457, 32466, 32475, 32483, 32492, 32500, - 32508, 32516, 32524, 32532, 32539, 32547, 32554, 32561, - 32569, 32576, 32582, 32589, 32596, 32602, 32609, 32615, - 32621, 32627, 32633, 32639, 32644, 32650, 32655, 32660, - 32665, 32670, 32675, 32680, 32685, 32689, 32694, 32698, - 32702, 32706, 32710, 32713, 32717, 32720, 32724, 32727, - 32730, 32733, 32736, 32739, 32741, 32744, 32746, 32748, - 32750, 32752, 32754, 32756, 32757, 32759, 32760, 32761, - 32762, 32763, 32764, 32765, 32765, 32766, 32766, 32766 + 0, 64, 128, 193, 257, 321, 386, 450, + 514, 579, 643, 707, 771, 836, 900, 964, + 1029, 1093, 1157, 1222, 1286, 1350, 1414, 1479, + 1543, 1607, 1672, 1736, 1800, 1864, 1929, 1993, + 2057, 2121, 2185, 2250, 2314, 2378, 2442, 2506, + 2570, 2635, 2699, 2763, 2827, 2891, 2955, 3019, + 3083, 3147, 3211, 3275, 3339, 3403, 3467, 3531, + 3595, 3659, 3723, 3787, 3851, 3915, 3979, 4042, + 4106, 4170, 4234, 4298, 4361, 4425, 4489, 4553, + 4616, 4680, 4744, 4807, 4871, 4935, 4998, 5062, + 5125, 5189, 5252, 5316, 5379, 5443, 5506, 5570, + 5633, 5696, 5760, 5823, 5886, 5950, 6013, 6076, + 6139, 6203, 6266, 6329, 6392, 6455, 6518, 6581, + 6644, 6707, 6770, 6833, 6896, 6959, 7022, 7085, + 7147, 7210, 7273, 7336, 7398, 7461, 7524, 7586, + 7649, 7711, 7774, 7836, 7899, 7961, 8024, 8086, + 8148, 8211, 8273, 8335, 8397, 8460, 8522, 8584, + 8646, 8708, 8770, 8832, 8894, 8956, 9018, 9079, + 9141, 9203, 9265, 9326, 9388, 9450, 9511, 9573, + 9634, 9696, 9757, 9819, 9880, 9941, 10003, 10064, + 10125, 10186, 10247, 10308, 10370, 10431, 10491, 10552, + 10613, 10674, 10735, 10796, 10856, 10917, 10978, 11038, + 11099, 11159, 11220, 11280, 11341, 11401, 11461, 11522, + 11582, 11642, 11702, 11762, 11822, 11882, 11942, 12002, + 12062, 12122, 12181, 12241, 12301, 12360, 12420, 12479, + 12539, 12598, 12658, 12717, 12776, 12835, 12895, 12954, + 13013, 13072, 13131, 13190, 13249, 13307, 13366, 13425, + 13484, 13542, 13601, 13659, 13718, 13776, 13834, 13893, + 13951, 14009, 14067, 14125, 14183, 14241, 14299, 14357, + 14415, 14473, 14530, 14588, 14646, 14703, 14761, 14818, + 14875, 14933, 14990, 15047, 15104, 15161, 15218, 15275, + 15332, 15389, 15446, 15502, 15559, 15616, 15672, 15729, + 15785, 15841, 15898, 15954, 16010, 16066, 16122, 16178, + 16234, 16290, 16346, 16402, 16457, 16513, 16568, 16624, + 16679, 16735, 16790, 16845, 16900, 16955, 17010, 17065, + 17120, 17175, 17230, 17284, 17339, 17394, 17448, 17503, + 17557, 17611, 17665, 17720, 17774, 17828, 17882, 17936, + 17989, 18043, 18097, 18150, 18204, 18257, 18311, 18364, + 18417, 18470, 18524, 18577, 18630, 18682, 18735, 18788, + 18841, 18893, 18946, 18998, 19051, 19103, 19155, 19207, + 19259, 19311, 19363, 19415, 19467, 19519, 19570, 19622, + 19673, 19725, 19776, 19827, 19879, 19930, 19981, 20032, + 20083, 20133, 20184, 20235, 20285, 20336, 20386, 20437, + 20487, 20537, 20587, 20637, 20687, 20737, 20787, 20836, + 20886, 20936, 20985, 21034, 21084, 21133, 21182, 21231, + 21280, 21329, 21378, 21426, 21475, 21524, 21572, 21620, + 21669, 21717, 21765, 21813, 21861, 21909, 21957, 22004, + 22052, 22100, 22147, 22194, 22242, 22289, 22336, 22383, + 22430, 22477, 22524, 22570, 22617, 22663, 22710, 22756, + 22802, 22849, 22895, 22941, 22987, 23032, 23078, 23124, + 23169, 23215, 23260, 23305, 23351, 23396, 23441, 23486, + 23530, 23575, 23620, 23664, 23709, 23753, 23797, 23842, + 23886, 23930, 23974, 24017, 24061, 24105, 24148, 24192, + 24235, 24278, 24321, 24364, 24407, 24450, 24493, 24536, + 24578, 24621, 24663, 24706, 24748, 24790, 24832, 24874, + 24916, 24957, 24999, 25041, 25082, 25123, 25165, 25206, + 25247, 25288, 25329, 25370, 25410, 25451, 25491, 25532, + 25572, 25612, 25652, 25692, 25732, 25772, 25811, 25851, + 25891, 25930, 25969, 26008, 26047, 26086, 26125, 26164, + 26203, 26241, 26280, 26318, 26356, 26395, 26433, 26471, + 26509, 26546, 26584, 26622, 26659, 26696, 26734, 26771, + 26808, 26845, 26882, 26918, 26955, 26991, 27028, 27064, + 27100, 27137, 27173, 27208, 27244, 27280, 27316, 27351, + 27386, 27422, 27457, 27492, 27527, 27562, 27596, 27631, + 27666, 27700, 27734, 27769, 27803, 27837, 27871, 27904, + 27938, 27972, 28005, 28038, 28072, 28105, 28138, 28171, + 28203, 28236, 28269, 28301, 28334, 28366, 28398, 28430, + 28462, 28494, 28525, 28557, 28589, 28620, 28651, 28682, + 28713, 28744, 28775, 28806, 28837, 28867, 28897, 28928, + 28958, 28988, 29018, 29048, 29077, 29107, 29136, 29166, + 29195, 29224, 29253, 29282, 29311, 29340, 29368, 29397, + 29425, 29453, 29482, 29510, 29537, 29565, 29593, 29621, + 29648, 29675, 29703, 29730, 29757, 29784, 29810, 29837, + 29863, 29890, 29916, 29942, 29968, 29994, 30020, 30046, + 30072, 30097, 30122, 30148, 30173, 30198, 30223, 30248, + 30272, 30297, 30321, 30346, 30370, 30394, 30418, 30442, + 30465, 30489, 30513, 30536, 30559, 30582, 30605, 30628, + 30651, 30674, 30696, 30719, 30741, 30763, 30786, 30807, + 30829, 30851, 30873, 30894, 30916, 30937, 30958, 30979, + 31000, 31021, 31041, 31062, 31082, 31103, 31123, 31143, + 31163, 31183, 31202, 31222, 31241, 31261, 31280, 31299, + 31318, 31337, 31356, 31374, 31393, 31411, 31429, 31447, + 31465, 31483, 31501, 31519, 31536, 31554, 31571, 31588, + 31605, 31622, 31639, 31656, 31672, 31689, 31705, 31721, + 31737, 31753, 31769, 31785, 31800, 31816, 31831, 31846, + 31861, 31876, 31891, 31906, 31920, 31935, 31949, 31963, + 31977, 31991, 32005, 32019, 32033, 32046, 32059, 32073, + 32086, 32099, 32112, 32124, 32137, 32149, 32162, 32174, + 32186, 32198, 32210, 32222, 32233, 32245, 32256, 32267, + 32279, 32290, 32300, 32311, 32322, 32332, 32343, 32353, + 32363, 32373, 32383, 32393, 32402, 32412, 32421, 32430, + 32440, 32449, 32457, 32466, 32475, 32483, 32492, 32500, + 32508, 32516, 32524, 32532, 32539, 32547, 32554, 32561, + 32569, 32576, 32582, 32589, 32596, 32602, 32609, 32615, + 32621, 32627, 32633, 32639, 32644, 32650, 32655, 32660, + 32665, 32670, 32675, 32680, 32685, 32689, 32694, 32698, + 32702, 32706, 32710, 32713, 32717, 32720, 32724, 32727, + 32730, 32733, 32736, 32739, 32741, 32744, 32746, 32748, + 32750, 32752, 32754, 32756, 32757, 32759, 32760, 32761, + 32762, 32763, 32764, 32765, 32765, 32766, 32766, 32766 }; const Word16 cos_scale_tbl_800[800] = { /* Q15 */ - 0, 64, 128, 193, 257, 321, 386, 450, - 514, 579, 643, 707, 771, 836, 900, 964, - 1029, 1093, 1157, 1222, 1286, 1350, 1414, 1479, - 1543, 1607, 1672, 1736, 1800, 1864, 1929, 1993, - 2057, 2121, 2185, 2250, 2314, 2378, 2442, 2506, - 2570, 2635, 2699, 2763, 2827, 2891, 2955, 3019, - 3083, 3147, 3211, 3275, 3339, 3403, 3467, 3531, - 3595, 3659, 3723, 3787, 3851, 3915, 3979, 4042, - 4106, 4170, 4234, 4298, 4361, 4425, 4489, 4553, - 4616, 4680, 4744, 4807, 4871, 4935, 4998, 5062, - 5125, 5189, 5252, 5316, 5379, 5443, 5506, 5570, - 5633, 5696, 5760, 5823, 5886, 5950, 6013, 6076, - 6139, 6203, 6266, 6329, 6392, 6455, 6518, 6581, - 6644, 6707, 6770, 6833, 6896, 6959, 7022, 7085, - 7147, 7210, 7273, 7336, 7398, 7461, 7524, 7586, - 7649, 7711, 7774, 7836, 7899, 7961, 8024, 8086, - 8148, 8211, 8273, 8335, 8397, 8460, 8522, 8584, - 8646, 8708, 8770, 8832, 8894, 8956, 9018, 9079, - 9141, 9203, 9265, 9326, 9388, 9450, 9511, 9573, - 9634, 9696, 9757, 9819, 9880, 9941, 10003, 10064, - 10125, 10186, 10247, 10308, 10370, 10431, 10491, 10552, - 10613, 10674, 10735, 10796, 10856, 10917, 10978, 11038, - 11099, 11159, 11220, 11280, 11341, 11401, 11461, 11522, - 11582, 11642, 11702, 11762, 11822, 11882, 11942, 12002, - 12062, 12122, 12181, 12241, 12301, 12360, 12420, 12479, - 12539, 12598, 12658, 12717, 12776, 12835, 12895, 12954, - 13013, 13072, 13131, 13190, 13249, 13307, 13366, 13425, - 13484, 13542, 13601, 13659, 13718, 13776, 13834, 13893, - 13951, 14009, 14067, 14125, 14183, 14241, 14299, 14357, - 14415, 14473, 14530, 14588, 14646, 14703, 14761, 14818, - 14875, 14933, 14990, 15047, 15104, 15161, 15218, 15275, - 15332, 15389, 15446, 15502, 15559, 15616, 15672, 15729, - 15785, 15841, 15898, 15954, 16010, 16066, 16122, 16178, - 16234, 16290, 16346, 16402, 16457, 16513, 16568, 16624, - 16679, 16735, 16790, 16845, 16900, 16955, 17010, 17065, - 17120, 17175, 17230, 17284, 17339, 17394, 17448, 17503, - 17557, 17611, 17665, 17720, 17774, 17828, 17882, 17936, - 17989, 18043, 18097, 18150, 18204, 18257, 18311, 18364, - 18417, 18470, 18524, 18577, 18630, 18682, 18735, 18788, - 18841, 18893, 18946, 18998, 19051, 19103, 19155, 19207, - 19259, 19311, 19363, 19415, 19467, 19519, 19570, 19622, - 19673, 19725, 19776, 19827, 19879, 19930, 19981, 20032, - 20083, 20133, 20184, 20235, 20285, 20336, 20386, 20437, - 20487, 20537, 20587, 20637, 20687, 20737, 20787, 20836, - 20886, 20936, 20985, 21034, 21084, 21133, 21182, 21231, - 21280, 21329, 21378, 21426, 21475, 21524, 21572, 21620, - 21669, 21717, 21765, 21813, 21861, 21909, 21957, 22004, - 22052, 22100, 22147, 22194, 22242, 22289, 22336, 22383, - 22430, 22477, 22524, 22570, 22617, 22663, 22710, 22756, - 22802, 22849, 22895, 22941, 22987, 23032, 23078, 23124, - 23169, 23215, 23260, 23305, 23351, 23396, 23441, 23486, - 23530, 23575, 23620, 23664, 23709, 23753, 23797, 23842, - 23886, 23930, 23974, 24017, 24061, 24105, 24148, 24192, - 24235, 24278, 24321, 24364, 24407, 24450, 24493, 24536, - 24578, 24621, 24663, 24706, 24748, 24790, 24832, 24874, - 24916, 24957, 24999, 25041, 25082, 25123, 25165, 25206, - 25247, 25288, 25329, 25370, 25410, 25451, 25491, 25532, - 25572, 25612, 25652, 25692, 25732, 25772, 25811, 25851, - 25891, 25930, 25969, 26008, 26047, 26086, 26125, 26164, - 26203, 26241, 26280, 26318, 26356, 26395, 26433, 26471, - 26509, 26546, 26584, 26622, 26659, 26696, 26734, 26771, - 26808, 26845, 26882, 26918, 26955, 26991, 27028, 27064, - 27100, 27137, 27173, 27208, 27244, 27280, 27316, 27351, - 27386, 27422, 27457, 27492, 27527, 27562, 27596, 27631, - 27666, 27700, 27734, 27769, 27803, 27837, 27871, 27904, - 27938, 27972, 28005, 28038, 28072, 28105, 28138, 28171, - 28203, 28236, 28269, 28301, 28334, 28366, 28398, 28430, - 28462, 28494, 28525, 28557, 28589, 28620, 28651, 28682, - 28713, 28744, 28775, 28806, 28837, 28867, 28897, 28928, - 28958, 28988, 29018, 29048, 29077, 29107, 29136, 29166, - 29195, 29224, 29253, 29282, 29311, 29340, 29368, 29397, - 29425, 29453, 29482, 29510, 29537, 29565, 29593, 29621, - 29648, 29675, 29703, 29730, 29757, 29784, 29810, 29837, - 29863, 29890, 29916, 29942, 29968, 29994, 30020, 30046, - 30072, 30097, 30122, 30148, 30173, 30198, 30223, 30248, - 30272, 30297, 30321, 30346, 30370, 30394, 30418, 30442, - 30465, 30489, 30513, 30536, 30559, 30582, 30605, 30628, - 30651, 30674, 30696, 30719, 30741, 30763, 30786, 30807, - 30829, 30851, 30873, 30894, 30916, 30937, 30958, 30979, - 31000, 31021, 31041, 31062, 31082, 31103, 31123, 31143, - 31163, 31183, 31202, 31222, 31241, 31261, 31280, 31299, - 31318, 31337, 31356, 31374, 31393, 31411, 31429, 31447, - 31465, 31483, 31501, 31519, 31536, 31554, 31571, 31588, - 31605, 31622, 31639, 31656, 31672, 31689, 31705, 31721, - 31737, 31753, 31769, 31785, 31800, 31816, 31831, 31846, - 31861, 31876, 31891, 31906, 31920, 31935, 31949, 31963, - 31977, 31991, 32005, 32019, 32033, 32046, 32059, 32073, - 32086, 32099, 32112, 32124, 32137, 32149, 32162, 32174, - 32186, 32198, 32210, 32222, 32233, 32245, 32256, 32267, - 32279, 32290, 32300, 32311, 32322, 32332, 32343, 32353, - 32363, 32373, 32383, 32393, 32402, 32412, 32421, 32430, - 32440, 32449, 32457, 32466, 32475, 32483, 32492, 32500, - 32508, 32516, 32524, 32532, 32539, 32547, 32554, 32561, - 32569, 32576, 32582, 32589, 32596, 32602, 32609, 32615, - 32621, 32627, 32633, 32639, 32644, 32650, 32655, 32660, - 32665, 32670, 32675, 32680, 32685, 32689, 32694, 32698, - 32702, 32706, 32710, 32713, 32717, 32720, 32724, 32727, - 32730, 32733, 32736, 32739, 32741, 32744, 32746, 32748, - 32750, 32752, 32754, 32756, 32757, 32759, 32760, 32761, - 32762, 32763, 32764, 32765, 32765, 32766, 32766, 32766 + 0, 64, 128, 193, 257, 321, 386, 450, + 514, 579, 643, 707, 771, 836, 900, 964, + 1029, 1093, 1157, 1222, 1286, 1350, 1414, 1479, + 1543, 1607, 1672, 1736, 1800, 1864, 1929, 1993, + 2057, 2121, 2185, 2250, 2314, 2378, 2442, 2506, + 2570, 2635, 2699, 2763, 2827, 2891, 2955, 3019, + 3083, 3147, 3211, 3275, 3339, 3403, 3467, 3531, + 3595, 3659, 3723, 3787, 3851, 3915, 3979, 4042, + 4106, 4170, 4234, 4298, 4361, 4425, 4489, 4553, + 4616, 4680, 4744, 4807, 4871, 4935, 4998, 5062, + 5125, 5189, 5252, 5316, 5379, 5443, 5506, 5570, + 5633, 5696, 5760, 5823, 5886, 5950, 6013, 6076, + 6139, 6203, 6266, 6329, 6392, 6455, 6518, 6581, + 6644, 6707, 6770, 6833, 6896, 6959, 7022, 7085, + 7147, 7210, 7273, 7336, 7398, 7461, 7524, 7586, + 7649, 7711, 7774, 7836, 7899, 7961, 8024, 8086, + 8148, 8211, 8273, 8335, 8397, 8460, 8522, 8584, + 8646, 8708, 8770, 8832, 8894, 8956, 9018, 9079, + 9141, 9203, 9265, 9326, 9388, 9450, 9511, 9573, + 9634, 9696, 9757, 9819, 9880, 9941, 10003, 10064, + 10125, 10186, 10247, 10308, 10370, 10431, 10491, 10552, + 10613, 10674, 10735, 10796, 10856, 10917, 10978, 11038, + 11099, 11159, 11220, 11280, 11341, 11401, 11461, 11522, + 11582, 11642, 11702, 11762, 11822, 11882, 11942, 12002, + 12062, 12122, 12181, 12241, 12301, 12360, 12420, 12479, + 12539, 12598, 12658, 12717, 12776, 12835, 12895, 12954, + 13013, 13072, 13131, 13190, 13249, 13307, 13366, 13425, + 13484, 13542, 13601, 13659, 13718, 13776, 13834, 13893, + 13951, 14009, 14067, 14125, 14183, 14241, 14299, 14357, + 14415, 14473, 14530, 14588, 14646, 14703, 14761, 14818, + 14875, 14933, 14990, 15047, 15104, 15161, 15218, 15275, + 15332, 15389, 15446, 15502, 15559, 15616, 15672, 15729, + 15785, 15841, 15898, 15954, 16010, 16066, 16122, 16178, + 16234, 16290, 16346, 16402, 16457, 16513, 16568, 16624, + 16679, 16735, 16790, 16845, 16900, 16955, 17010, 17065, + 17120, 17175, 17230, 17284, 17339, 17394, 17448, 17503, + 17557, 17611, 17665, 17720, 17774, 17828, 17882, 17936, + 17989, 18043, 18097, 18150, 18204, 18257, 18311, 18364, + 18417, 18470, 18524, 18577, 18630, 18682, 18735, 18788, + 18841, 18893, 18946, 18998, 19051, 19103, 19155, 19207, + 19259, 19311, 19363, 19415, 19467, 19519, 19570, 19622, + 19673, 19725, 19776, 19827, 19879, 19930, 19981, 20032, + 20083, 20133, 20184, 20235, 20285, 20336, 20386, 20437, + 20487, 20537, 20587, 20637, 20687, 20737, 20787, 20836, + 20886, 20936, 20985, 21034, 21084, 21133, 21182, 21231, + 21280, 21329, 21378, 21426, 21475, 21524, 21572, 21620, + 21669, 21717, 21765, 21813, 21861, 21909, 21957, 22004, + 22052, 22100, 22147, 22194, 22242, 22289, 22336, 22383, + 22430, 22477, 22524, 22570, 22617, 22663, 22710, 22756, + 22802, 22849, 22895, 22941, 22987, 23032, 23078, 23124, + 23169, 23215, 23260, 23305, 23351, 23396, 23441, 23486, + 23530, 23575, 23620, 23664, 23709, 23753, 23797, 23842, + 23886, 23930, 23974, 24017, 24061, 24105, 24148, 24192, + 24235, 24278, 24321, 24364, 24407, 24450, 24493, 24536, + 24578, 24621, 24663, 24706, 24748, 24790, 24832, 24874, + 24916, 24957, 24999, 25041, 25082, 25123, 25165, 25206, + 25247, 25288, 25329, 25370, 25410, 25451, 25491, 25532, + 25572, 25612, 25652, 25692, 25732, 25772, 25811, 25851, + 25891, 25930, 25969, 26008, 26047, 26086, 26125, 26164, + 26203, 26241, 26280, 26318, 26356, 26395, 26433, 26471, + 26509, 26546, 26584, 26622, 26659, 26696, 26734, 26771, + 26808, 26845, 26882, 26918, 26955, 26991, 27028, 27064, + 27100, 27137, 27173, 27208, 27244, 27280, 27316, 27351, + 27386, 27422, 27457, 27492, 27527, 27562, 27596, 27631, + 27666, 27700, 27734, 27769, 27803, 27837, 27871, 27904, + 27938, 27972, 28005, 28038, 28072, 28105, 28138, 28171, + 28203, 28236, 28269, 28301, 28334, 28366, 28398, 28430, + 28462, 28494, 28525, 28557, 28589, 28620, 28651, 28682, + 28713, 28744, 28775, 28806, 28837, 28867, 28897, 28928, + 28958, 28988, 29018, 29048, 29077, 29107, 29136, 29166, + 29195, 29224, 29253, 29282, 29311, 29340, 29368, 29397, + 29425, 29453, 29482, 29510, 29537, 29565, 29593, 29621, + 29648, 29675, 29703, 29730, 29757, 29784, 29810, 29837, + 29863, 29890, 29916, 29942, 29968, 29994, 30020, 30046, + 30072, 30097, 30122, 30148, 30173, 30198, 30223, 30248, + 30272, 30297, 30321, 30346, 30370, 30394, 30418, 30442, + 30465, 30489, 30513, 30536, 30559, 30582, 30605, 30628, + 30651, 30674, 30696, 30719, 30741, 30763, 30786, 30807, + 30829, 30851, 30873, 30894, 30916, 30937, 30958, 30979, + 31000, 31021, 31041, 31062, 31082, 31103, 31123, 31143, + 31163, 31183, 31202, 31222, 31241, 31261, 31280, 31299, + 31318, 31337, 31356, 31374, 31393, 31411, 31429, 31447, + 31465, 31483, 31501, 31519, 31536, 31554, 31571, 31588, + 31605, 31622, 31639, 31656, 31672, 31689, 31705, 31721, + 31737, 31753, 31769, 31785, 31800, 31816, 31831, 31846, + 31861, 31876, 31891, 31906, 31920, 31935, 31949, 31963, + 31977, 31991, 32005, 32019, 32033, 32046, 32059, 32073, + 32086, 32099, 32112, 32124, 32137, 32149, 32162, 32174, + 32186, 32198, 32210, 32222, 32233, 32245, 32256, 32267, + 32279, 32290, 32300, 32311, 32322, 32332, 32343, 32353, + 32363, 32373, 32383, 32393, 32402, 32412, 32421, 32430, + 32440, 32449, 32457, 32466, 32475, 32483, 32492, 32500, + 32508, 32516, 32524, 32532, 32539, 32547, 32554, 32561, + 32569, 32576, 32582, 32589, 32596, 32602, 32609, 32615, + 32621, 32627, 32633, 32639, 32644, 32650, 32655, 32660, + 32665, 32670, 32675, 32680, 32685, 32689, 32694, 32698, + 32702, 32706, 32710, 32713, 32717, 32720, 32724, 32727, + 32730, 32733, 32736, 32739, 32741, 32744, 32746, 32748, + 32750, 32752, 32754, 32756, 32757, 32759, 32760, 32761, + 32762, 32763, 32764, 32765, 32765, 32766, 32766, 32766 }; #endif // IVAS_FLOAT_FIXED const Word16 scales_ivas_fx[][MAX_NO_SCALES * 2] = /* 2 subvectors */ -{ - {3129, 0, 0, 3137, 0, 0, }, - {3287, 0, 0, 3137, 0, 0, }, - {2611, 5033, 0, 3137, 0, 0, }, - {2611, 5033, 0, 3340, 0, 0, }, - {2164, 3674, 5931, 2363, 3809, 6281, }, - {1898, 2985, 4745, 2115, 3667, 7045, }, - {2629, 5480, 0, 2971, 0, 0, }, - {2801, 0, 0, 2869, 5072, 0, }, - {1763, 2545, 3723, 2514, 4558, 21108, }, - {2195, 3960, 7440, 2500, 6017, 21960, }, - {1841, 2902, 1386, 2115, 3762, 22308, }, - {1699, 2709, 1288, 1865, 3246, 20660, }, - {3221, 0, 0, 3391, 0, 0, }, - {2537, 4923, 0, 3186, 0, 0, }, - {2816, 4229, 6397, 3676, 0, 0, }, - {2816, 4229, 6397, 3893, 0, 0, }, - {2160, 3481, 9091, 3391, 0, 0, }, - {2560, 4923, 8462, 2775, 4835, 0, }, - {2551, 3803, 5619, 3072, 5537, 0, }, - {2545, 4206, 7450, 3229, 0, 0, }, - {2162, 3655, 9263, 2699, 5296, 0, }, - {2039, 3082, 6871, 2426, 3637, 5586, }, - {1902, 2840, 6875, 2211, 3483, 5908, }, - {1888, 3057, 6899, 2211, 3483, 5908, }, - {1888, 3057, 6899, 2183, 3469, 6420, }, - {1888, 3057, 6899, 1970, 3174, 8081, }, - {2633, 1855, 4960, 2301, 3477, 5083, }, - {1527, 2269, 5875, 1964, 3033, 8001, }, - {1576, 2445, 5781, 1857, 2871, 4333, }, - {1531, 2258, 5869, 2420, 1660, 6823, }, - {1566, 2318, 3776, 2543, 3876, 1888, }, - {1568, 2320, 3780, 2183, 3360, 1665, }, - {1386, 1972, 4356, 1486, 2215, 4513, }, - {3356, 0, 0, 2494, 4425, 0, }, - {2633, 5009, 0, 2887, 0, 0, }, - {2224, 3538, 7696, 2494, 4425, 0, }, - {2119, 3225, 9861, 2494, 4425, 0, }, - {1974, 3139, 10121, 2494, 4425, 0, }, - {1722, 2453, 4059, 2494, 4425, 0, }, - {1839, 2658, 4472, 2490, 5455, 0, }, - {1722, 2533, 4581, 2037, 3393, 5808, }, - {1427, 2009, 4184, 1914, 3082, 1349, }, - {1370, 1861, 2719, 2017, 1339, 3913, }, - {2482, 3885, 0, 0, 0, 0, }, - {2375, 3827, 6975, 0, 0, 0, }, - {3395, 0, 0, 3883, 0, 0, }, - {3563, 0, 0, 3883, 0, 0, }, - {3346, 0, 0, 3418, 0, 0, }, - {3563, 0, 0, 4128, 0, 0, }, - {2820, 5218, 0, 3883, 0, 0, }, - {2637, 4962, 0, 3418, 0, 0, }, - {2482, 3885, 0, 3418, 0, 0, }, - {2217, 3616, 6502, 3418, 0, 0, }, - {2123, 3295, 8658, 3418, 0, 0, }, - {2242, 3397, 5562, 2693, 5132, 0, }, - {2387, 4024, 7483, 3452, 0, 0, }, - {1927, 2838, 4548, 2693, 5132, 0, }, - {1859, 2674, 3893, 2703, 5371, 0, }, - {2201, 3618, 1617, 2703, 5371, 0, }, - {2093, 3135, 1554, 2273, 3594, 5312, }, - {2201, 3618, 1617, 2238, 3895, 6172, }, - {1828, 3014, 1382, 2258, 3624, 5820, }, - {1863, 3170, 1402, 2113, 3381, 5146, }, - {1691, 2572, 1294, 2009, 3158, 4540, }, - {2424, 3706, 5654, 0, 0, 0, }, - {3299, 0, 0, 3313, 0, 0, }, - {2424, 3706, 5654, 3174, 0, 0, }, - {2424, 3706, 5654, 3313, 0, 0, }, - {2177, 3557, 6113, 3313, 0, 0, }, - {2207, 3737, 6475, 3008, 4605, 0, }, - {2816, 1873, 4263, 3008, 4605, 0, }, - {1966, 2914, 1433, 2682, 4366, 0, }, - {2301, 1626, 3895, 2627, 4714, 0, }, - {2205, 3536, 1570, 2560, 3995, 6105, }, - {1910, 3012, 1402, 2560, 3995, 6105, }, - {1898, 3276, 1380, 2363, 3637, 5844, }, - {2144, 1478, 3655, 2162, 3362, 5531, }, - {1988, 1409, 3090, 2136, 3543, 6002, }, - {1882, 1355, 2799, 2164, 3702, 6285, }, - {3311, 0, 0, 3393, 0, 0, }, - {2611, 4706, 0, 3201, 0, 0, }, - {2820, 5218, 0, 4128, 0, 0, }, - {2660, 4134, 0, 4128, 0, 0, }, - {2678, 4820, 0, 2840, 0, 0, }, - {2643, 4952, 0, 2775, 5003, 0, }, - {2402, 3618, 5726, 3252, 6201, 0, }, - {2209, 3622, 6168, 2840, 0, 0, }, - {2209, 3622, 6168, 2713, 5232, 0, }, - {1992, 2850, 4124, 3262, 6518, 0, }, - {2353, 3835, 1736, 3262, 6518, 0, }, - {1837, 2744, 5332, 2191, 3459, 5175, }, - {2353, 3835, 1736, 2701, 4685, 7550, }, - {1837, 2744, 5332, 1923, 2977, 4265, }, - {1853, 2717, 5322, 2271, 1591, 3491, }, - {1560, 2254, 4831, 1923, 2977, 4265, }, - {1626, 2510, 6512, 2271, 1591, 3491, }, - {3336, 0, 0, 2439, 4528, 0, }, - {2615, 5236, 0, 2799, 0, 0, }, - {2215, 3606, 8046, 2439, 4528, 0, }, - {2084, 3143, 5750, 2439, 4528, 0, }, - {1933, 3024, 5658, 2439, 4528, 0, }, - {1863, 3571, 6793, 2439, 4528, 0, }, - {1884, 3375, 6283, 1984, 3446, 8095, }, - {1513, 2275, 5517, 1800, 2889, 4720, }, - {1452, 2113, 5564, 1658, 2549, 3735, }, - {1552, 2285, 4022, 4139, 1634, 2496, }, - {1431, 2117, 4050, 4139, 1634, 2496, }, - {1486, 2150, 3778, 2775, 1761, 4515, }, - {1386, 2041, 3418, 2775, 1761, 4515, }, - {3371, 0, 0, 2568, 5036, 0, }, - {3031, 6023, 0, 3733, 0, 0, }, - {2801, 4704, 0, 3733, 0, 0, }, - {2801, 4704, 0, 4065, 0, 0, }, - {2197, 3815, 6617, 3436, 0, 0, }, - {2197, 3815, 6617, 2568, 5036, 0, }, - {2162, 3229, 5052, 3698, 6123, 0, }, - {2314, 3723, 1712, 4065, 0, 0, }, - {1947, 3055, 5111, 2570, 6084, 0, }, - {2351, 3770, 1665, 2570, 6084, 0, }, - {2351, 1656, 3932, 3133, 5603, 0, }, - {2469, 1742, 4464, 3098, 6504, 0, }, - {1646, 2457, 4046, 3080, 6574, 0, }, - {2336, 1650, 3921, 4040, 2387, 7604, }, - {2289, 1593, 4149, 2537, 4380, 7731, }, - {1576, 2322, 3921, 2521, 4706, 7946, }, - {2099, 1452, 3545, 2521, 4706, 7946, }, - {1980, 1460, 3385, 3768, 2252, 5793, }, - {2025, 1429, 3278, 2224, 4022, 5902, }, - {1232, 1779, 2904, 2588, 1564, 4542, }, - {1746, 3622, 9062, 2048, 2048, 2048, }, - {2070, 3405, 9017, 3231, 0, 0, }, - {2070, 3405, 9017, 2461, 4964, 0, }, - {1804, 3313, 8470, 2461, 4964, 0, }, - {1734, 3667, 9146, 2461, 4964, 0, }, - {1372, 2277, 4892, 2461, 4964, 0, }, - {2316, 3717, 1630, 2590, 5722, 0, }, - {1167, 1646, 2451, 2379, 3991, 1490, }, - {2140, 3248, 7688, 3418, 0, 0, }, - {2252, 3284, 4700, 2732, 4962, 0, }, - {2234, 3588, 6479, 2881, 0, 0, }, - {2234, 3588, 6479, 2756, 5171, 0, }, - {2234, 3588, 6479, 2230, 3448, 5167, }, - {1925, 2762, 3897, 2455, 3665, 5251, }, - {1802, 2621, 5783, 2250, 3553, 0, }, - {1701, 2488, 5994, 2230, 3497, 5076, }, - {1781, 2717, 5951, 2183, 3520, 5480, }, - {1566, 6379, 3723, 2299, 4728, 9779, }, - {1581, 2297, 4814, 2961, 1933, 4243, }, - {1435, 2000, 3559, 1939, 2975, 4263, }, - {1472, 2091, 3483, 2291, 1626, 3473, }, - {1718, 1310, 3117, 2289, 3475, 1630, }, - {1718, 1310, 3117, 1968, 3008, 1447, }, - {1310, 1810, 3547, 1546, 2232, 3170, }, - {2494, 1630, 4675, 2641, 6809, 0, }, - {3256, 1710, 9084, 2246, 6287, 0, }, - {2035, 5359, 0, 2234, 4573, 7079, }, - {1816, 3221, 7256, 2228, 3741, 6281, }, - {1714, 2535, 3897, 2658, 5728, 0, }, - {2330, 5787, 0, 2265, 5726, 8992, }, - {1927, 3954, 9160, 1394, 2592, 4767, }, - {2768, 8871, 0, 1679, 3164, 8550, }, - {2750, 7387, 0, 1759, 2975, 5304, }, - {2473, 5611, 0, 1554, 2539, 4468, }, - {2299, 5603, 0, 1789, 3067, 5296, }, - {1882, 5060, 0, 1259, 2195, 4292, }, - {3170, 9232, 0, 1689, 4460, 8816, }, - {2492, 5935, 0, 1509, 2492, 3952, }, - {1998, 4485, 11706, 3084, 1314, 8624, }, - {2267, 5314, 0, 2666, 1236, 1802, } -}; + { + { + 3129, + 0, + 0, + 3137, + 0, + 0, + }, + { + 3287, + 0, + 0, + 3137, + 0, + 0, + }, + { + 2611, + 5033, + 0, + 3137, + 0, + 0, + }, + { + 2611, + 5033, + 0, + 3340, + 0, + 0, + }, + { + 2164, + 3674, + 5931, + 2363, + 3809, + 6281, + }, + { + 1898, + 2985, + 4745, + 2115, + 3667, + 7045, + }, + { + 2629, + 5480, + 0, + 2971, + 0, + 0, + }, + { + 2801, + 0, + 0, + 2869, + 5072, + 0, + }, + { + 1763, + 2545, + 3723, + 2514, + 4558, + 21108, + }, + { + 2195, + 3960, + 7440, + 2500, + 6017, + 21960, + }, + { + 1841, + 2902, + 1386, + 2115, + 3762, + 22308, + }, + { + 1699, + 2709, + 1288, + 1865, + 3246, + 20660, + }, + { + 3221, + 0, + 0, + 3391, + 0, + 0, + }, + { + 2537, + 4923, + 0, + 3186, + 0, + 0, + }, + { + 2816, + 4229, + 6397, + 3676, + 0, + 0, + }, + { + 2816, + 4229, + 6397, + 3893, + 0, + 0, + }, + { + 2160, + 3481, + 9091, + 3391, + 0, + 0, + }, + { + 2560, + 4923, + 8462, + 2775, + 4835, + 0, + }, + { + 2551, + 3803, + 5619, + 3072, + 5537, + 0, + }, + { + 2545, + 4206, + 7450, + 3229, + 0, + 0, + }, + { + 2162, + 3655, + 9263, + 2699, + 5296, + 0, + }, + { + 2039, + 3082, + 6871, + 2426, + 3637, + 5586, + }, + { + 1902, + 2840, + 6875, + 2211, + 3483, + 5908, + }, + { + 1888, + 3057, + 6899, + 2211, + 3483, + 5908, + }, + { + 1888, + 3057, + 6899, + 2183, + 3469, + 6420, + }, + { + 1888, + 3057, + 6899, + 1970, + 3174, + 8081, + }, + { + 2633, + 1855, + 4960, + 2301, + 3477, + 5083, + }, + { + 1527, + 2269, + 5875, + 1964, + 3033, + 8001, + }, + { + 1576, + 2445, + 5781, + 1857, + 2871, + 4333, + }, + { + 1531, + 2258, + 5869, + 2420, + 1660, + 6823, + }, + { + 1566, + 2318, + 3776, + 2543, + 3876, + 1888, + }, + { + 1568, + 2320, + 3780, + 2183, + 3360, + 1665, + }, + { + 1386, + 1972, + 4356, + 1486, + 2215, + 4513, + }, + { + 3356, + 0, + 0, + 2494, + 4425, + 0, + }, + { + 2633, + 5009, + 0, + 2887, + 0, + 0, + }, + { + 2224, + 3538, + 7696, + 2494, + 4425, + 0, + }, + { + 2119, + 3225, + 9861, + 2494, + 4425, + 0, + }, + { + 1974, + 3139, + 10121, + 2494, + 4425, + 0, + }, + { + 1722, + 2453, + 4059, + 2494, + 4425, + 0, + }, + { + 1839, + 2658, + 4472, + 2490, + 5455, + 0, + }, + { + 1722, + 2533, + 4581, + 2037, + 3393, + 5808, + }, + { + 1427, + 2009, + 4184, + 1914, + 3082, + 1349, + }, + { + 1370, + 1861, + 2719, + 2017, + 1339, + 3913, + }, + { + 2482, + 3885, + 0, + 0, + 0, + 0, + }, + { + 2375, + 3827, + 6975, + 0, + 0, + 0, + }, + { + 3395, + 0, + 0, + 3883, + 0, + 0, + }, + { + 3563, + 0, + 0, + 3883, + 0, + 0, + }, + { + 3346, + 0, + 0, + 3418, + 0, + 0, + }, + { + 3563, + 0, + 0, + 4128, + 0, + 0, + }, + { + 2820, + 5218, + 0, + 3883, + 0, + 0, + }, + { + 2637, + 4962, + 0, + 3418, + 0, + 0, + }, + { + 2482, + 3885, + 0, + 3418, + 0, + 0, + }, + { + 2217, + 3616, + 6502, + 3418, + 0, + 0, + }, + { + 2123, + 3295, + 8658, + 3418, + 0, + 0, + }, + { + 2242, + 3397, + 5562, + 2693, + 5132, + 0, + }, + { + 2387, + 4024, + 7483, + 3452, + 0, + 0, + }, + { + 1927, + 2838, + 4548, + 2693, + 5132, + 0, + }, + { + 1859, + 2674, + 3893, + 2703, + 5371, + 0, + }, + { + 2201, + 3618, + 1617, + 2703, + 5371, + 0, + }, + { + 2093, + 3135, + 1554, + 2273, + 3594, + 5312, + }, + { + 2201, + 3618, + 1617, + 2238, + 3895, + 6172, + }, + { + 1828, + 3014, + 1382, + 2258, + 3624, + 5820, + }, + { + 1863, + 3170, + 1402, + 2113, + 3381, + 5146, + }, + { + 1691, + 2572, + 1294, + 2009, + 3158, + 4540, + }, + { + 2424, + 3706, + 5654, + 0, + 0, + 0, + }, + { + 3299, + 0, + 0, + 3313, + 0, + 0, + }, + { + 2424, + 3706, + 5654, + 3174, + 0, + 0, + }, + { + 2424, + 3706, + 5654, + 3313, + 0, + 0, + }, + { + 2177, + 3557, + 6113, + 3313, + 0, + 0, + }, + { + 2207, + 3737, + 6475, + 3008, + 4605, + 0, + }, + { + 2816, + 1873, + 4263, + 3008, + 4605, + 0, + }, + { + 1966, + 2914, + 1433, + 2682, + 4366, + 0, + }, + { + 2301, + 1626, + 3895, + 2627, + 4714, + 0, + }, + { + 2205, + 3536, + 1570, + 2560, + 3995, + 6105, + }, + { + 1910, + 3012, + 1402, + 2560, + 3995, + 6105, + }, + { + 1898, + 3276, + 1380, + 2363, + 3637, + 5844, + }, + { + 2144, + 1478, + 3655, + 2162, + 3362, + 5531, + }, + { + 1988, + 1409, + 3090, + 2136, + 3543, + 6002, + }, + { + 1882, + 1355, + 2799, + 2164, + 3702, + 6285, + }, + { + 3311, + 0, + 0, + 3393, + 0, + 0, + }, + { + 2611, + 4706, + 0, + 3201, + 0, + 0, + }, + { + 2820, + 5218, + 0, + 4128, + 0, + 0, + }, + { + 2660, + 4134, + 0, + 4128, + 0, + 0, + }, + { + 2678, + 4820, + 0, + 2840, + 0, + 0, + }, + { + 2643, + 4952, + 0, + 2775, + 5003, + 0, + }, + { + 2402, + 3618, + 5726, + 3252, + 6201, + 0, + }, + { + 2209, + 3622, + 6168, + 2840, + 0, + 0, + }, + { + 2209, + 3622, + 6168, + 2713, + 5232, + 0, + }, + { + 1992, + 2850, + 4124, + 3262, + 6518, + 0, + }, + { + 2353, + 3835, + 1736, + 3262, + 6518, + 0, + }, + { + 1837, + 2744, + 5332, + 2191, + 3459, + 5175, + }, + { + 2353, + 3835, + 1736, + 2701, + 4685, + 7550, + }, + { + 1837, + 2744, + 5332, + 1923, + 2977, + 4265, + }, + { + 1853, + 2717, + 5322, + 2271, + 1591, + 3491, + }, + { + 1560, + 2254, + 4831, + 1923, + 2977, + 4265, + }, + { + 1626, + 2510, + 6512, + 2271, + 1591, + 3491, + }, + { + 3336, + 0, + 0, + 2439, + 4528, + 0, + }, + { + 2615, + 5236, + 0, + 2799, + 0, + 0, + }, + { + 2215, + 3606, + 8046, + 2439, + 4528, + 0, + }, + { + 2084, + 3143, + 5750, + 2439, + 4528, + 0, + }, + { + 1933, + 3024, + 5658, + 2439, + 4528, + 0, + }, + { + 1863, + 3571, + 6793, + 2439, + 4528, + 0, + }, + { + 1884, + 3375, + 6283, + 1984, + 3446, + 8095, + }, + { + 1513, + 2275, + 5517, + 1800, + 2889, + 4720, + }, + { + 1452, + 2113, + 5564, + 1658, + 2549, + 3735, + }, + { + 1552, + 2285, + 4022, + 4139, + 1634, + 2496, + }, + { + 1431, + 2117, + 4050, + 4139, + 1634, + 2496, + }, + { + 1486, + 2150, + 3778, + 2775, + 1761, + 4515, + }, + { + 1386, + 2041, + 3418, + 2775, + 1761, + 4515, + }, + { + 3371, + 0, + 0, + 2568, + 5036, + 0, + }, + { + 3031, + 6023, + 0, + 3733, + 0, + 0, + }, + { + 2801, + 4704, + 0, + 3733, + 0, + 0, + }, + { + 2801, + 4704, + 0, + 4065, + 0, + 0, + }, + { + 2197, + 3815, + 6617, + 3436, + 0, + 0, + }, + { + 2197, + 3815, + 6617, + 2568, + 5036, + 0, + }, + { + 2162, + 3229, + 5052, + 3698, + 6123, + 0, + }, + { + 2314, + 3723, + 1712, + 4065, + 0, + 0, + }, + { + 1947, + 3055, + 5111, + 2570, + 6084, + 0, + }, + { + 2351, + 3770, + 1665, + 2570, + 6084, + 0, + }, + { + 2351, + 1656, + 3932, + 3133, + 5603, + 0, + }, + { + 2469, + 1742, + 4464, + 3098, + 6504, + 0, + }, + { + 1646, + 2457, + 4046, + 3080, + 6574, + 0, + }, + { + 2336, + 1650, + 3921, + 4040, + 2387, + 7604, + }, + { + 2289, + 1593, + 4149, + 2537, + 4380, + 7731, + }, + { + 1576, + 2322, + 3921, + 2521, + 4706, + 7946, + }, + { + 2099, + 1452, + 3545, + 2521, + 4706, + 7946, + }, + { + 1980, + 1460, + 3385, + 3768, + 2252, + 5793, + }, + { + 2025, + 1429, + 3278, + 2224, + 4022, + 5902, + }, + { + 1232, + 1779, + 2904, + 2588, + 1564, + 4542, + }, + { + 1746, + 3622, + 9062, + 2048, + 2048, + 2048, + }, + { + 2070, + 3405, + 9017, + 3231, + 0, + 0, + }, + { + 2070, + 3405, + 9017, + 2461, + 4964, + 0, + }, + { + 1804, + 3313, + 8470, + 2461, + 4964, + 0, + }, + { + 1734, + 3667, + 9146, + 2461, + 4964, + 0, + }, + { + 1372, + 2277, + 4892, + 2461, + 4964, + 0, + }, + { + 2316, + 3717, + 1630, + 2590, + 5722, + 0, + }, + { + 1167, + 1646, + 2451, + 2379, + 3991, + 1490, + }, + { + 2140, + 3248, + 7688, + 3418, + 0, + 0, + }, + { + 2252, + 3284, + 4700, + 2732, + 4962, + 0, + }, + { + 2234, + 3588, + 6479, + 2881, + 0, + 0, + }, + { + 2234, + 3588, + 6479, + 2756, + 5171, + 0, + }, + { + 2234, + 3588, + 6479, + 2230, + 3448, + 5167, + }, + { + 1925, + 2762, + 3897, + 2455, + 3665, + 5251, + }, + { + 1802, + 2621, + 5783, + 2250, + 3553, + 0, + }, + { + 1701, + 2488, + 5994, + 2230, + 3497, + 5076, + }, + { + 1781, + 2717, + 5951, + 2183, + 3520, + 5480, + }, + { + 1566, + 6379, + 3723, + 2299, + 4728, + 9779, + }, + { + 1581, + 2297, + 4814, + 2961, + 1933, + 4243, + }, + { + 1435, + 2000, + 3559, + 1939, + 2975, + 4263, + }, + { + 1472, + 2091, + 3483, + 2291, + 1626, + 3473, + }, + { + 1718, + 1310, + 3117, + 2289, + 3475, + 1630, + }, + { + 1718, + 1310, + 3117, + 1968, + 3008, + 1447, + }, + { + 1310, + 1810, + 3547, + 1546, + 2232, + 3170, + }, + { + 2494, + 1630, + 4675, + 2641, + 6809, + 0, + }, + { + 3256, + 1710, + 9084, + 2246, + 6287, + 0, + }, + { + 2035, + 5359, + 0, + 2234, + 4573, + 7079, + }, + { + 1816, + 3221, + 7256, + 2228, + 3741, + 6281, + }, + { + 1714, + 2535, + 3897, + 2658, + 5728, + 0, + }, + { + 2330, + 5787, + 0, + 2265, + 5726, + 8992, + }, + { + 1927, + 3954, + 9160, + 1394, + 2592, + 4767, + }, + { + 2768, + 8871, + 0, + 1679, + 3164, + 8550, + }, + { + 2750, + 7387, + 0, + 1759, + 2975, + 5304, + }, + { + 2473, + 5611, + 0, + 1554, + 2539, + 4468, + }, + { + 2299, + 5603, + 0, + 1789, + 3067, + 5296, + }, + { + 1882, + 5060, + 0, + 1259, + 2195, + 4292, + }, + { + 3170, + 9232, + 0, + 1689, + 4460, + 8816, + }, + { + 2492, + 5935, + 0, + 1509, + 2492, + 3952, + }, + { + 1998, + 4485, + 11706, + 3084, + 1314, + 8624, + }, + { + 2267, + 5314, + 0, + 2666, + 1236, + 1802, + } + }; const Word16 scales_p_ivas_fx[][MAX_NO_SCALES * 2] = /* 2 subvectors 20 modes Q11 */ -{ - {2998, 4861, 0, 0, 0, 0, }, - { 2629, 4421, 0, 0, 0, 0, }, - { 2549, 5304, 0, 0, 0, 0, }, - { 2338, 3805, 5994, 0, 0, 0, }, - { 2125, 3762, 6162, 0, 0, 0, }, - { 3102, 0, 0, 3153, 0, 0, }, - { 3244, 0, 0, 3153, 0, 0, }, - { 3244, 0, 0, 3317, 0, 0, }, - { 2629, 4421, 0, 3317, 0, 0, }, - { 2549, 5304, 0, 3153, 0, 0, }, - { 2590, 5251, 0, 3354, 0, 0, }, - { 2338, 3805, 5994, 3317, 0, 0, }, - { 2125, 3762, 6162, 3317, 0, 0, }, - { 2023, 3401, 5199, 3317, 0, 0, }, - { 2177, 3487, 5744, 2650, 4818, 0, }, - { 2177, 3926, 6273, 2795, 0, 0, }, - { 1871, 2891, 4552, 2650, 4818, 0, }, - { 1843, 2887, 4616, 2658, 4941, 0, }, - { 1806, 2869, 4919, 2689, 4999, 0, }, - { 2777, 1775, 4868, 2191, 3452, 5214, }, - { 1732, 2760, 5214, 2203, 3567, 5443, }, - { 1730, 2824, 5255, 2086, 3229, 5003, }, - { 1548, 2435, 5732, 2220, 3694, 5648, }, - { 1546, 2494, 5777, 1933, 2934, 4040, }, - { 1525, 2451, 5935, 2543, 1726, 3997, }, - { 1482, 2529, 6025, 2570, 1736, 4096, }, - { 1406, 2279, 4788, 1746, 2719, 3981, }, - { 1327, 2107, 3760, 1748, 2777, 4016, }, - { 1243, 1912, 3106, 1603, 2484, 3141, }, - { 1226, 1853, 3131, 1497, 2275, 3072, }, - { 1327, 2107, 3760, 1406, 2166, 3891, }, - { 3303, 0, 0, 0, 0, 0, }, - { 2594, 5068, 0, 3315, 0, 0, }, - { 2076, 3338, 5046, 2631, 4405, 0, }, - { 1828, 2846, 4739, 3000, 4708, 0, }, - { 1904, 2869, 4403, 2621, 4616, 0, }, - { 1828, 2846, 4739, 2613, 4517, 6111, }, - { 1828, 2846, 4739, 2121, 3371, 5060, }, - { 1755, 2738, 5046, 2136, 3543, 5376, }, - { 1566, 2496, 3180, 2121, 3371, 5060, }, - { 1615, 2719, 3383, 2154, 3653, 5541, }, - { 1564, 2506, 3184, 1884, 2955, 4167, }, - { 1357, 2172, 2535, 2824, 1839, 3995, }, - { 1378, 2260, 2674, 2578, 1695, 4001, }, - { 1363, 2193, 2557, 1644, 2541, 3540, }, - { 1347, 2127, 2486, 1945, 1333, 2926, }, - { 3276, 0, 0, 3180, 0, 0, }, - { 2674, 4970, 0, 3235, 0, 0, }, - { 2674, 4970, 0, 3432, 0, 0, }, - { 2560, 5926, 0, 3235, 0, 0, }, - { 2322, 4067, 6748, 3180, 0, 0, }, - { 2340, 4202, 6850, 3432, 0, 0, }, - { 2138, 4159, 7141, 3432, 0, 0, }, - { 2021, 3661, 5445, 3373, 0, 0, }, - { 1841, 3280, 5281, 3373, 0, 0, }, - { 1632, 2650, 4382, 3373, 0, 0, }, - { 1632, 2650, 4382, 2734, 4556, 0, }, - { 1517, 2357, 3719, 2734, 4556, 0, }, - { 2007, 3485, 1445, 2697, 5382, 0, }, - { 1632, 2650, 4382, 2428, 3956, 0, }, - { 1517, 2357, 3719, 2383, 3733, 5670, }, - { 1449, 2306, 3999, 2203, 3543, 5687, }, - { 1351, 2148, 3217, 2203, 3543, 5687, }, - { 1355, 2101, 3182, 2199, 3917, 6189, }, - { 1351, 2148, 3217, 2947, 1896, 4364, }, - { 1290, 1978, 3117, 2686, 1804, 4519, }, - { 1263, 1886, 2963, 2113, 3172, 1548, }, - { 3266, 0, 0, 3076, 0, 0, }, - { 2299, 3985, 7643, 3076, 0, 0, }, - { 2115, 4249, 8886, 2906, 5009, 0, }, - { 2017, 3672, 12216, 2623, 4759, 0, }, - { 1804, 3289, 14325, 2906, 5009, 0, }, - { 1728, 3239, 14376, 2623, 4759, 0, }, - { 1615, 3112, 14751, 2623, 4759, 0, }, - { 1779, 3168, 14325, 2109, 3592, 6352, }, - { 1673, 3055, 14581, 2109, 3592, 6352, }, - { 1546, 2830, 14608, 2109, 3592, 6352, }, - { 1445, 2693, 14796, 2109, 3592, 6352, }, - { 1411, 2654, 14929, 2080, 3840, 6633, }, - { 1429, 2611, 14764, 1871, 3170, 4982, }, - { 1390, 2693, 14929, 2516, 3778, 1665, }, - { 1390, 2693, 14929, 2433, 1581, 4003, }, - { 2070, 3639, 5652, 3305, 0, 0, }, - { 1974, 3235, 8183, 3540, 0, 0, }, - { 1798, 2949, 4687, 3540, 0, 0, }, - { 1744, 3364, 4974, 3540, 0, 0, }, - { 1746, 2830, 4231, 2549, 5486, 0, }, - { 2471, 1593, 4521, 2549, 5486, 0, }, - { 1646, 2772, 5421, 2883, 5355, 0, }, - { 1601, 2568, 5732, 2822, 5545, 0, }, - { 2471, 1593, 4521, 2074, 3751, 6252, }, - { 2471, 1593, 4521, 2908, 1785, 4771, }, - { 1398, 2080, 3661, 2306, 3862, 5988, }, - { 1284, 1878, 2965, 2306, 3862, 5988, }, - { 1347, 2105, 3188, 3035, 1996, 4397, }, - { 1626, 1187, 2725, 3035, 1996, 4397, }, - { 1685, 1212, 2709, 2756, 1832, 4726, }, - { 2248, 1511, 1136, 1779, 2641, 3813, }, - { 1552, 2275, 1126, 1783, 2799, 3903, }, - { 1128, 1568, 2285, 1619, 2459, 3405, }, - { 1128, 1568, 2285, 1972, 1427, 2709, }, - { 1075, 1576, 2197, 1669, 2533, 1161, }, - { 2191, 3667, 7993, 3274, 0, 0, }, - { 1679, 2492, 4278, 2570, 4689, 0, }, - { 1597, 2394, 5109, 2570, 4689, 0, }, - { 2201, 1480, 4835, 2273, 4016, 7149, }, - { 1415, 2107, 4786, 2117, 3667, 8200, }, - { 1374, 2203, 5337, 1955, 3168, 5148, }, - { 2424, 1589, 4335, 2164, 3420, 1380, }, - { 1937, 2965, 5576, 2854, 5416, 9381, }, - { 1941, 2977, 5576, 4034, 2404, 7135, }, - { 1812, 2879, 5658, 4034, 2404, 7135, }, - { 2549, 1724, 4870, 4093, 2392, 7540, }, - { 1781, 2756, 5763, 3571, 2166, 5933, }, - { 1693, 2496, 4456, 3252, 5324, 2037, }, - { 1673, 2428, 4079, 3262, 1994, 5363, }, - { 1683, 2467, 4298, 2998, 1851, 4911, }, - { 1683, 2467, 4298, 4204, 1714, 2783, }, - { 1067, 1529, 2115, 1630, 2729, 1110, }, - { 3438, 0, 0, 2625, 5060, 0, }, - { 2228, 3786, 6543, 3454, 0, 0, }, - { 2228, 3786, 6543, 2625, 5060, 0, }, - { 2306, 3459, 1617, 2625, 5060, 0, }, - { 1904, 2830, 1396, 2625, 5060, 0, }, - { 2283, 1626, 3792, 2623, 6211, 0, }, - { 1720, 2818, 1275, 1638, 2899, 8724, }, - { 1640, 2351, 3690, 0, 0, 0, }, - { 2752, 5380, 0, 3223, 0, 0, }, - { 2580, 4188, 0, 3223, 0, 0, }, - { 2580, 4188, 0, 3430, 0, 0, }, - { 2230, 3710, 6496, 3434, 0, 0, }, - { 2230, 3899, 6596, 3115, 5396, 0, }, - { 1972, 2949, 4335, 3430, 0, 0, }, - { 1972, 2949, 4335, 2666, 4935, 0, }, - { 1730, 2482, 3960, 2689, 4954, 0, }, - { 1595, 2242, 3481, 2689, 4954, 0, }, - { 1480, 2078, 3407, 2689, 4954, 0, }, - { 2066, 3414, 1540, 2676, 6187, 0, }, - { 2058, 3373, 1533, 2179, 3831, 6856, }, - { 1832, 3051, 1396, 2179, 3831, 6856, }, - { 1611, 2605, 1245, 2179, 3831, 6856, }, - { 1763, 1327, 2988, 2179, 3831, 6856, }, - { 1697, 1292, 2738, 2168, 4161, 7020, }, - { 1763, 1327, 2988, 3155, 1884, 5142, }, - { 1736, 1296, 2781, 2883, 1800, 5552, }, - { 1828, 1335, 2945, 2203, 1474, 3674, }, - { 2783, 4722, 0, 3418, 0, 0, }, - { 2205, 3946, 7262, 3418, 0, 0, }, - { 2205, 4161, 7327, 2926, 5552, 0, }, - { 1705, 2566, 4311, 2627, 5234, 0, }, - { 1589, 2359, 3805, 2627, 5234, 0, }, - { 1472, 2183, 3547, 2627, 5234, 0, }, - { 1927, 1333, 3205, 1478, 2437, 3973, }, - { 2646, 5076, 0, 3155, 0, 0, }, - { 2461, 3897, 0, 3155, 0, 0, }, - { 2105, 3360, 5027, 3375, 0, 0, }, - { 2553, 1798, 4769, 3375, 0, 0, }, - { 1767, 2781, 5165, 3375, 0, 0, }, - { 1673, 2502, 4116, 2199, 3655, 5597, }, - { 1669, 1253, 2623, 2160, 3530, 6045, }, - { 3164, 0, 0, 3170, 0, 0, }, - { 3358, 0, 0, 3170, 0, 0, }, - { 2723, 0, 0, 3270, 0, 0, }, - { 2529, 4743, 0, 3270, 0, 0, }, - { 2635, 5629, 0, 3170, 0, 0, }, - { 2635, 5629, 0, 3387, 0, 0, }, - { 2437, 4149, 0, 3387, 0, 0, }, - { 1949, 3428, 5656, 3270, 0, 0, }, - { 1880, 3217, 6574, 3270, 0, 0, }, - { 2572, 1622, 4255, 3270, 0, 0, }, - { 1550, 2463, 3837, 3270, 0, 0, }, - { 1906, 2985, 5017, 2650, 5615, 0, }, - { 2287, 1507, 3840, 2562, 5257, 0, }, - { 1581, 2531, 3934, 2562, 5257, 0, }, - { 1796, 2859, 5605, 2213, 3719, 6881, }, - { 2316, 3350, 0, 2807, 0, 0, }, - { 1826, 3260, 7012, 2658, 6565, 0, }, - { 1792, 3168, 7084, 2631, 5937, 8499, }, - { 1732, 3379, 6772, 2611, 5009, 8202, }, - { 1654, 6285, 3514, 2611, 5009, 8202, }, - { 1566, 6406, 3733, 2611, 5009, 8202, }, - { 1912, 2615, 1490, 2369, 3475, 0, }, - { 1705, 2379, 1347, 2357, 3454, 0, }, - { 1538, 2113, 1224, 2357, 3454, 0, }, - { 1554, 6426, 3778, 1888, 3088, 6369, }, - { 1452, 2058, 1167, 2170, 3629, 5568, }, - { 1527, 2050, 1230, 2056, 3692, 5922, }, - { 1521, 2048, 1226, 1916, 3811, 5885, }, - { 1536, 6492, 3942, 1509, 2914, 5502, }, - { 1536, 6492, 3942, 1349, 2168, 4044, }, - { 1587, 1257, 2123, 1630, 2670, 3901, }, - { 1830, 2742, 5220, 2678, 5326, 0, }, - { 1703, 2568, 3966, 2676, 5353, 0, }, - { 1703, 2523, 3923, 2371, 4048, 0, }, - { 1689, 2580, 4081, 2095, 3561, 5726, }, - { 1536, 2281, 3201, 2140, 3690, 5490, }, - { 1417, 2048, 2930, 2095, 3561, 5726, }, - { 1474, 2072, 3272, 3096, 1896, 4376, }, - { 1394, 1992, 3377, 2828, 1794, 4360, }, - { 1400, 1974, 3358, 2392, 3637, 1611, }, - { 1368, 1914, 3176, 2080, 3108, 1458, }, - { 1349, 1865, 2918, 2738, 1820, 1314, }, - { 1349, 1865, 2918, 1718, 2635, 1243, }, - { 3344, 0, 0, 3454, 0, 0, }, - { 3463, 0, 0, 3428, 0, 0, }, - { 2719, 5251, 0, 3180, 0, 0, }, - { 2560, 4079, 0, 3180, 0, 0, }, - { 2560, 4079, 0, 3428, 0, 0, }, - { 2203, 3665, 6025, 3454, 0, 0, }, - { 2183, 3446, 8349, 3428, 0, 0, }, - { 2621, 1865, 5072, 3428, 0, 0, }, - { 1708, 2516, 3870, 3454, 0, 0, }, - { 1921, 2875, 4409, 2674, 5386, 0, }, - { 2744, 1814, 4751, 2674, 5386, 0, }, - { 1705, 2560, 3907, 2674, 5386, 0, }, - { 1705, 2484, 3835, 2304, 3766, 5773, }, - { 1748, 2594, 3743, 2138, 3604, 5902, }, - { 1566, 2379, 3461, 2097, 3559, 5812, }, - { 1484, 2150, 3667, 3031, 1888, 6356, }, - { 1458, 2072, 3172, 3059, 1849, 6889, }, - { 1349, 1898, 2779, 3059, 1849, 6889, }, - { 1683, 1257, 2637, 1863, 3090, 4618, }, - { 1722, 1277, 2617, 2377, 1560, 3702, }, - { 1716, 1273, 2592, 2211, 1456, 3502, }, - { 1703, 1267, 2611, 1921, 2928, 1318, }, - { 1810, 2762, 5263, 2691, 5343, 0, }, - { 2009, 3016, 5701, 3461, 6844, 0, }, - { 1976, 3100, 5500, 2885, 5089, 8081, }, - { 1998, 2983, 5453, 4405, 2603, 8552, }, - { 2029, 3080, 6320, 5091, 2693, 9277, }, - { 1937, 2965, 5576, 2854, 5416, 9381, }, - { 1456, 2084, 3307, 3035, 1886, 7026, }, - { 1390, 1994, 3397, 1941, 3172, 7061, }, - { 1701, 1265, 3033, 1910, 3100, 4730, }, - { 1671, 1249, 2871, 2920, 1796, 4638, }, - { 1611, 2574, 1220, 1759, 2963, 4978, }, - { 1611, 2574, 1220, 2265, 1505, 3397, } -}; + { + { + 2998, + 4861, + 0, + 0, + 0, + 0, + }, + { + 2629, + 4421, + 0, + 0, + 0, + 0, + }, + { + 2549, + 5304, + 0, + 0, + 0, + 0, + }, + { + 2338, + 3805, + 5994, + 0, + 0, + 0, + }, + { + 2125, + 3762, + 6162, + 0, + 0, + 0, + }, + { + 3102, + 0, + 0, + 3153, + 0, + 0, + }, + { + 3244, + 0, + 0, + 3153, + 0, + 0, + }, + { + 3244, + 0, + 0, + 3317, + 0, + 0, + }, + { + 2629, + 4421, + 0, + 3317, + 0, + 0, + }, + { + 2549, + 5304, + 0, + 3153, + 0, + 0, + }, + { + 2590, + 5251, + 0, + 3354, + 0, + 0, + }, + { + 2338, + 3805, + 5994, + 3317, + 0, + 0, + }, + { + 2125, + 3762, + 6162, + 3317, + 0, + 0, + }, + { + 2023, + 3401, + 5199, + 3317, + 0, + 0, + }, + { + 2177, + 3487, + 5744, + 2650, + 4818, + 0, + }, + { + 2177, + 3926, + 6273, + 2795, + 0, + 0, + }, + { + 1871, + 2891, + 4552, + 2650, + 4818, + 0, + }, + { + 1843, + 2887, + 4616, + 2658, + 4941, + 0, + }, + { + 1806, + 2869, + 4919, + 2689, + 4999, + 0, + }, + { + 2777, + 1775, + 4868, + 2191, + 3452, + 5214, + }, + { + 1732, + 2760, + 5214, + 2203, + 3567, + 5443, + }, + { + 1730, + 2824, + 5255, + 2086, + 3229, + 5003, + }, + { + 1548, + 2435, + 5732, + 2220, + 3694, + 5648, + }, + { + 1546, + 2494, + 5777, + 1933, + 2934, + 4040, + }, + { + 1525, + 2451, + 5935, + 2543, + 1726, + 3997, + }, + { + 1482, + 2529, + 6025, + 2570, + 1736, + 4096, + }, + { + 1406, + 2279, + 4788, + 1746, + 2719, + 3981, + }, + { + 1327, + 2107, + 3760, + 1748, + 2777, + 4016, + }, + { + 1243, + 1912, + 3106, + 1603, + 2484, + 3141, + }, + { + 1226, + 1853, + 3131, + 1497, + 2275, + 3072, + }, + { + 1327, + 2107, + 3760, + 1406, + 2166, + 3891, + }, + { + 3303, + 0, + 0, + 0, + 0, + 0, + }, + { + 2594, + 5068, + 0, + 3315, + 0, + 0, + }, + { + 2076, + 3338, + 5046, + 2631, + 4405, + 0, + }, + { + 1828, + 2846, + 4739, + 3000, + 4708, + 0, + }, + { + 1904, + 2869, + 4403, + 2621, + 4616, + 0, + }, + { + 1828, + 2846, + 4739, + 2613, + 4517, + 6111, + }, + { + 1828, + 2846, + 4739, + 2121, + 3371, + 5060, + }, + { + 1755, + 2738, + 5046, + 2136, + 3543, + 5376, + }, + { + 1566, + 2496, + 3180, + 2121, + 3371, + 5060, + }, + { + 1615, + 2719, + 3383, + 2154, + 3653, + 5541, + }, + { + 1564, + 2506, + 3184, + 1884, + 2955, + 4167, + }, + { + 1357, + 2172, + 2535, + 2824, + 1839, + 3995, + }, + { + 1378, + 2260, + 2674, + 2578, + 1695, + 4001, + }, + { + 1363, + 2193, + 2557, + 1644, + 2541, + 3540, + }, + { + 1347, + 2127, + 2486, + 1945, + 1333, + 2926, + }, + { + 3276, + 0, + 0, + 3180, + 0, + 0, + }, + { + 2674, + 4970, + 0, + 3235, + 0, + 0, + }, + { + 2674, + 4970, + 0, + 3432, + 0, + 0, + }, + { + 2560, + 5926, + 0, + 3235, + 0, + 0, + }, + { + 2322, + 4067, + 6748, + 3180, + 0, + 0, + }, + { + 2340, + 4202, + 6850, + 3432, + 0, + 0, + }, + { + 2138, + 4159, + 7141, + 3432, + 0, + 0, + }, + { + 2021, + 3661, + 5445, + 3373, + 0, + 0, + }, + { + 1841, + 3280, + 5281, + 3373, + 0, + 0, + }, + { + 1632, + 2650, + 4382, + 3373, + 0, + 0, + }, + { + 1632, + 2650, + 4382, + 2734, + 4556, + 0, + }, + { + 1517, + 2357, + 3719, + 2734, + 4556, + 0, + }, + { + 2007, + 3485, + 1445, + 2697, + 5382, + 0, + }, + { + 1632, + 2650, + 4382, + 2428, + 3956, + 0, + }, + { + 1517, + 2357, + 3719, + 2383, + 3733, + 5670, + }, + { + 1449, + 2306, + 3999, + 2203, + 3543, + 5687, + }, + { + 1351, + 2148, + 3217, + 2203, + 3543, + 5687, + }, + { + 1355, + 2101, + 3182, + 2199, + 3917, + 6189, + }, + { + 1351, + 2148, + 3217, + 2947, + 1896, + 4364, + }, + { + 1290, + 1978, + 3117, + 2686, + 1804, + 4519, + }, + { + 1263, + 1886, + 2963, + 2113, + 3172, + 1548, + }, + { + 3266, + 0, + 0, + 3076, + 0, + 0, + }, + { + 2299, + 3985, + 7643, + 3076, + 0, + 0, + }, + { + 2115, + 4249, + 8886, + 2906, + 5009, + 0, + }, + { + 2017, + 3672, + 12216, + 2623, + 4759, + 0, + }, + { + 1804, + 3289, + 14325, + 2906, + 5009, + 0, + }, + { + 1728, + 3239, + 14376, + 2623, + 4759, + 0, + }, + { + 1615, + 3112, + 14751, + 2623, + 4759, + 0, + }, + { + 1779, + 3168, + 14325, + 2109, + 3592, + 6352, + }, + { + 1673, + 3055, + 14581, + 2109, + 3592, + 6352, + }, + { + 1546, + 2830, + 14608, + 2109, + 3592, + 6352, + }, + { + 1445, + 2693, + 14796, + 2109, + 3592, + 6352, + }, + { + 1411, + 2654, + 14929, + 2080, + 3840, + 6633, + }, + { + 1429, + 2611, + 14764, + 1871, + 3170, + 4982, + }, + { + 1390, + 2693, + 14929, + 2516, + 3778, + 1665, + }, + { + 1390, + 2693, + 14929, + 2433, + 1581, + 4003, + }, + { + 2070, + 3639, + 5652, + 3305, + 0, + 0, + }, + { + 1974, + 3235, + 8183, + 3540, + 0, + 0, + }, + { + 1798, + 2949, + 4687, + 3540, + 0, + 0, + }, + { + 1744, + 3364, + 4974, + 3540, + 0, + 0, + }, + { + 1746, + 2830, + 4231, + 2549, + 5486, + 0, + }, + { + 2471, + 1593, + 4521, + 2549, + 5486, + 0, + }, + { + 1646, + 2772, + 5421, + 2883, + 5355, + 0, + }, + { + 1601, + 2568, + 5732, + 2822, + 5545, + 0, + }, + { + 2471, + 1593, + 4521, + 2074, + 3751, + 6252, + }, + { + 2471, + 1593, + 4521, + 2908, + 1785, + 4771, + }, + { + 1398, + 2080, + 3661, + 2306, + 3862, + 5988, + }, + { + 1284, + 1878, + 2965, + 2306, + 3862, + 5988, + }, + { + 1347, + 2105, + 3188, + 3035, + 1996, + 4397, + }, + { + 1626, + 1187, + 2725, + 3035, + 1996, + 4397, + }, + { + 1685, + 1212, + 2709, + 2756, + 1832, + 4726, + }, + { + 2248, + 1511, + 1136, + 1779, + 2641, + 3813, + }, + { + 1552, + 2275, + 1126, + 1783, + 2799, + 3903, + }, + { + 1128, + 1568, + 2285, + 1619, + 2459, + 3405, + }, + { + 1128, + 1568, + 2285, + 1972, + 1427, + 2709, + }, + { + 1075, + 1576, + 2197, + 1669, + 2533, + 1161, + }, + { + 2191, + 3667, + 7993, + 3274, + 0, + 0, + }, + { + 1679, + 2492, + 4278, + 2570, + 4689, + 0, + }, + { + 1597, + 2394, + 5109, + 2570, + 4689, + 0, + }, + { + 2201, + 1480, + 4835, + 2273, + 4016, + 7149, + }, + { + 1415, + 2107, + 4786, + 2117, + 3667, + 8200, + }, + { + 1374, + 2203, + 5337, + 1955, + 3168, + 5148, + }, + { + 2424, + 1589, + 4335, + 2164, + 3420, + 1380, + }, + { + 1937, + 2965, + 5576, + 2854, + 5416, + 9381, + }, + { + 1941, + 2977, + 5576, + 4034, + 2404, + 7135, + }, + { + 1812, + 2879, + 5658, + 4034, + 2404, + 7135, + }, + { + 2549, + 1724, + 4870, + 4093, + 2392, + 7540, + }, + { + 1781, + 2756, + 5763, + 3571, + 2166, + 5933, + }, + { + 1693, + 2496, + 4456, + 3252, + 5324, + 2037, + }, + { + 1673, + 2428, + 4079, + 3262, + 1994, + 5363, + }, + { + 1683, + 2467, + 4298, + 2998, + 1851, + 4911, + }, + { + 1683, + 2467, + 4298, + 4204, + 1714, + 2783, + }, + { + 1067, + 1529, + 2115, + 1630, + 2729, + 1110, + }, + { + 3438, + 0, + 0, + 2625, + 5060, + 0, + }, + { + 2228, + 3786, + 6543, + 3454, + 0, + 0, + }, + { + 2228, + 3786, + 6543, + 2625, + 5060, + 0, + }, + { + 2306, + 3459, + 1617, + 2625, + 5060, + 0, + }, + { + 1904, + 2830, + 1396, + 2625, + 5060, + 0, + }, + { + 2283, + 1626, + 3792, + 2623, + 6211, + 0, + }, + { + 1720, + 2818, + 1275, + 1638, + 2899, + 8724, + }, + { + 1640, + 2351, + 3690, + 0, + 0, + 0, + }, + { + 2752, + 5380, + 0, + 3223, + 0, + 0, + }, + { + 2580, + 4188, + 0, + 3223, + 0, + 0, + }, + { + 2580, + 4188, + 0, + 3430, + 0, + 0, + }, + { + 2230, + 3710, + 6496, + 3434, + 0, + 0, + }, + { + 2230, + 3899, + 6596, + 3115, + 5396, + 0, + }, + { + 1972, + 2949, + 4335, + 3430, + 0, + 0, + }, + { + 1972, + 2949, + 4335, + 2666, + 4935, + 0, + }, + { + 1730, + 2482, + 3960, + 2689, + 4954, + 0, + }, + { + 1595, + 2242, + 3481, + 2689, + 4954, + 0, + }, + { + 1480, + 2078, + 3407, + 2689, + 4954, + 0, + }, + { + 2066, + 3414, + 1540, + 2676, + 6187, + 0, + }, + { + 2058, + 3373, + 1533, + 2179, + 3831, + 6856, + }, + { + 1832, + 3051, + 1396, + 2179, + 3831, + 6856, + }, + { + 1611, + 2605, + 1245, + 2179, + 3831, + 6856, + }, + { + 1763, + 1327, + 2988, + 2179, + 3831, + 6856, + }, + { + 1697, + 1292, + 2738, + 2168, + 4161, + 7020, + }, + { + 1763, + 1327, + 2988, + 3155, + 1884, + 5142, + }, + { + 1736, + 1296, + 2781, + 2883, + 1800, + 5552, + }, + { + 1828, + 1335, + 2945, + 2203, + 1474, + 3674, + }, + { + 2783, + 4722, + 0, + 3418, + 0, + 0, + }, + { + 2205, + 3946, + 7262, + 3418, + 0, + 0, + }, + { + 2205, + 4161, + 7327, + 2926, + 5552, + 0, + }, + { + 1705, + 2566, + 4311, + 2627, + 5234, + 0, + }, + { + 1589, + 2359, + 3805, + 2627, + 5234, + 0, + }, + { + 1472, + 2183, + 3547, + 2627, + 5234, + 0, + }, + { + 1927, + 1333, + 3205, + 1478, + 2437, + 3973, + }, + { + 2646, + 5076, + 0, + 3155, + 0, + 0, + }, + { + 2461, + 3897, + 0, + 3155, + 0, + 0, + }, + { + 2105, + 3360, + 5027, + 3375, + 0, + 0, + }, + { + 2553, + 1798, + 4769, + 3375, + 0, + 0, + }, + { + 1767, + 2781, + 5165, + 3375, + 0, + 0, + }, + { + 1673, + 2502, + 4116, + 2199, + 3655, + 5597, + }, + { + 1669, + 1253, + 2623, + 2160, + 3530, + 6045, + }, + { + 3164, + 0, + 0, + 3170, + 0, + 0, + }, + { + 3358, + 0, + 0, + 3170, + 0, + 0, + }, + { + 2723, + 0, + 0, + 3270, + 0, + 0, + }, + { + 2529, + 4743, + 0, + 3270, + 0, + 0, + }, + { + 2635, + 5629, + 0, + 3170, + 0, + 0, + }, + { + 2635, + 5629, + 0, + 3387, + 0, + 0, + }, + { + 2437, + 4149, + 0, + 3387, + 0, + 0, + }, + { + 1949, + 3428, + 5656, + 3270, + 0, + 0, + }, + { + 1880, + 3217, + 6574, + 3270, + 0, + 0, + }, + { + 2572, + 1622, + 4255, + 3270, + 0, + 0, + }, + { + 1550, + 2463, + 3837, + 3270, + 0, + 0, + }, + { + 1906, + 2985, + 5017, + 2650, + 5615, + 0, + }, + { + 2287, + 1507, + 3840, + 2562, + 5257, + 0, + }, + { + 1581, + 2531, + 3934, + 2562, + 5257, + 0, + }, + { + 1796, + 2859, + 5605, + 2213, + 3719, + 6881, + }, + { + 2316, + 3350, + 0, + 2807, + 0, + 0, + }, + { + 1826, + 3260, + 7012, + 2658, + 6565, + 0, + }, + { + 1792, + 3168, + 7084, + 2631, + 5937, + 8499, + }, + { + 1732, + 3379, + 6772, + 2611, + 5009, + 8202, + }, + { + 1654, + 6285, + 3514, + 2611, + 5009, + 8202, + }, + { + 1566, + 6406, + 3733, + 2611, + 5009, + 8202, + }, + { + 1912, + 2615, + 1490, + 2369, + 3475, + 0, + }, + { + 1705, + 2379, + 1347, + 2357, + 3454, + 0, + }, + { + 1538, + 2113, + 1224, + 2357, + 3454, + 0, + }, + { + 1554, + 6426, + 3778, + 1888, + 3088, + 6369, + }, + { + 1452, + 2058, + 1167, + 2170, + 3629, + 5568, + }, + { + 1527, + 2050, + 1230, + 2056, + 3692, + 5922, + }, + { + 1521, + 2048, + 1226, + 1916, + 3811, + 5885, + }, + { + 1536, + 6492, + 3942, + 1509, + 2914, + 5502, + }, + { + 1536, + 6492, + 3942, + 1349, + 2168, + 4044, + }, + { + 1587, + 1257, + 2123, + 1630, + 2670, + 3901, + }, + { + 1830, + 2742, + 5220, + 2678, + 5326, + 0, + }, + { + 1703, + 2568, + 3966, + 2676, + 5353, + 0, + }, + { + 1703, + 2523, + 3923, + 2371, + 4048, + 0, + }, + { + 1689, + 2580, + 4081, + 2095, + 3561, + 5726, + }, + { + 1536, + 2281, + 3201, + 2140, + 3690, + 5490, + }, + { + 1417, + 2048, + 2930, + 2095, + 3561, + 5726, + }, + { + 1474, + 2072, + 3272, + 3096, + 1896, + 4376, + }, + { + 1394, + 1992, + 3377, + 2828, + 1794, + 4360, + }, + { + 1400, + 1974, + 3358, + 2392, + 3637, + 1611, + }, + { + 1368, + 1914, + 3176, + 2080, + 3108, + 1458, + }, + { + 1349, + 1865, + 2918, + 2738, + 1820, + 1314, + }, + { + 1349, + 1865, + 2918, + 1718, + 2635, + 1243, + }, + { + 3344, + 0, + 0, + 3454, + 0, + 0, + }, + { + 3463, + 0, + 0, + 3428, + 0, + 0, + }, + { + 2719, + 5251, + 0, + 3180, + 0, + 0, + }, + { + 2560, + 4079, + 0, + 3180, + 0, + 0, + }, + { + 2560, + 4079, + 0, + 3428, + 0, + 0, + }, + { + 2203, + 3665, + 6025, + 3454, + 0, + 0, + }, + { + 2183, + 3446, + 8349, + 3428, + 0, + 0, + }, + { + 2621, + 1865, + 5072, + 3428, + 0, + 0, + }, + { + 1708, + 2516, + 3870, + 3454, + 0, + 0, + }, + { + 1921, + 2875, + 4409, + 2674, + 5386, + 0, + }, + { + 2744, + 1814, + 4751, + 2674, + 5386, + 0, + }, + { + 1705, + 2560, + 3907, + 2674, + 5386, + 0, + }, + { + 1705, + 2484, + 3835, + 2304, + 3766, + 5773, + }, + { + 1748, + 2594, + 3743, + 2138, + 3604, + 5902, + }, + { + 1566, + 2379, + 3461, + 2097, + 3559, + 5812, + }, + { + 1484, + 2150, + 3667, + 3031, + 1888, + 6356, + }, + { + 1458, + 2072, + 3172, + 3059, + 1849, + 6889, + }, + { + 1349, + 1898, + 2779, + 3059, + 1849, + 6889, + }, + { + 1683, + 1257, + 2637, + 1863, + 3090, + 4618, + }, + { + 1722, + 1277, + 2617, + 2377, + 1560, + 3702, + }, + { + 1716, + 1273, + 2592, + 2211, + 1456, + 3502, + }, + { + 1703, + 1267, + 2611, + 1921, + 2928, + 1318, + }, + { + 1810, + 2762, + 5263, + 2691, + 5343, + 0, + }, + { + 2009, + 3016, + 5701, + 3461, + 6844, + 0, + }, + { + 1976, + 3100, + 5500, + 2885, + 5089, + 8081, + }, + { + 1998, + 2983, + 5453, + 4405, + 2603, + 8552, + }, + { + 2029, + 3080, + 6320, + 5091, + 2693, + 9277, + }, + { + 1937, + 2965, + 5576, + 2854, + 5416, + 9381, + }, + { + 1456, + 2084, + 3307, + 3035, + 1886, + 7026, + }, + { + 1390, + 1994, + 3397, + 1941, + 3172, + 7061, + }, + { + 1701, + 1265, + 3033, + 1910, + 3100, + 4730, + }, + { + 1671, + 1249, + 2871, + 2920, + 1796, + 4638, + }, + { + 1611, + 2574, + 1220, + 1759, + 2963, + 4978, + }, + { + 1611, + 2574, + 1220, + 2265, + 1505, + 3397, + } + }; diff --git a/lib_com/rom_com.h b/lib_com/rom_com.h index 4093dbbfa..0d5c159c5 100644 --- a/lib_com/rom_com.h +++ b/lib_com/rom_com.h @@ -44,32 +44,32 @@ #include "stl.h" #include "basop_util.h" -#define MINSFTAB 7 -#define MAXSFTAB 25 +#define MINSFTAB 7 +#define MAXSFTAB 25 #define INTERP_EXP 0 typedef struct { - int32_t fin; /* input frequency */ - Word32 fin_fx; /* input frequency Q0 */ - - int32_t fout; /* output frequency */ - Word32 fout_fx; /* output frequency Q0 */ - - int16_t fac_num; /* numerator of resampling factor */ - Word16 fac_num_fx; /* numerator of resampling factor Q0 */ - - Word16 fac_den_fx; /* denominator of resampling factor Q0 */ - Word16 lg_out; /* denominator of resampling factor Q15 */ - - const float *filter; /* resampling filter coefficients */ - const Word16 *filter_fx; /* resampling filter coefficients Q14 */ - - int16_t filt_len; /* number of filter coeff. */ - Word16 filt_len_fx; /* number of filter coeff. Q0 */ - - uint16_t flags; /* flags from config. table */ - UWord16 flags_fx; /* flags from config. table Q0 */ - //UNS_Word16 flags_fx; /* flags from config. table Q0 */ + int32_t fin; /* input frequency */ + Word32 fin_fx; /* input frequency Q0 */ + + int32_t fout; /* output frequency */ + Word32 fout_fx; /* output frequency Q0 */ + + int16_t fac_num; /* numerator of resampling factor */ + Word16 fac_num_fx; /* numerator of resampling factor Q0 */ + + Word16 fac_den_fx; /* denominator of resampling factor Q0 */ + Word16 lg_out; /* denominator of resampling factor Q15 */ + + const float *filter; /* resampling filter coefficients */ + const Word16 *filter_fx; /* resampling filter coefficients Q14 */ + + int16_t filt_len; /* number of filter coeff. */ + Word16 filt_len_fx; /* number of filter coeff. Q0 */ + + uint16_t flags; /* flags from config. table */ + UWord16 flags_fx; /* flags from config. table Q0 */ + // UNS_Word16 flags_fx; /* flags from config. table Q0 */ } Resampling_cfg; @@ -79,39 +79,39 @@ typedef struct int16_t bw; const int16_t *band_width; Word32 L_qint; - - Word16 eref_fx; - Word16 eref; - - Word16 bit_alloc_weight_fx; - Word16 bit_alloc_weight; + + Word16 eref_fx; + Word16 eref; + + Word16 bit_alloc_weight_fx; + Word16 bit_alloc_weight; int16_t gqlevs; int16_t Ngq; int16_t p2a_bands; - - float p2a_th_float; - Word16 p2a_th; - - float pd_thresh_float; - Word16 pd_thresh; - - float ld_slope_float; - Word16 ld_slope; - - float ni_coef_float; - Word16 ni_coef; - - float ni_pd_th; - + + float p2a_th_float; + Word16 p2a_th; + + float pd_thresh_float; + Word16 pd_thresh; + + float ld_slope_float; + Word16 ld_slope; + + float ni_coef_float; + Word16 ni_coef; + + float ni_pd_th; + } Xcore_Config; -extern const Word16 filter_LP15_180H_fx[]; /* Sincfilt.m: N=180*2+1, Fmin=0, Fmax=1/15, hann( N )' */ -extern const Word16 filter_LP3_90H_fx[]; /* Sincfilt.m: N=90*2+1, Fmin=0, Fmax=1/3, hann( N )' */ -extern const Word16 filter_LP12_180H_13b_fx[]; /* Sincfilt.m: N=180*2+1, Fmin=0, Fmax=1/12, hann( N )' */ -extern const Word16 filter_LP15_180H_13b_fx[]; /* Sincfilt.m: N=180*2+1, Fmin=0, Fmax=1/15, hann( N )' */ -extern const Word16 filter_LP15_360H_13b_fx[]; /* Sincfilt.m: N=360*2+1, Fmin=0, Fmax=1/15, hann( N )' */ +extern const Word16 filter_LP15_180H_fx[]; /* Sincfilt.m: N=180*2+1, Fmin=0, Fmax=1/15, hann( N )' */ +extern const Word16 filter_LP3_90H_fx[]; /* Sincfilt.m: N=90*2+1, Fmin=0, Fmax=1/3, hann( N )' */ +extern const Word16 filter_LP12_180H_13b_fx[]; /* Sincfilt.m: N=180*2+1, Fmin=0, Fmax=1/12, hann( N )' */ +extern const Word16 filter_LP15_180H_13b_fx[]; /* Sincfilt.m: N=180*2+1, Fmin=0, Fmax=1/15, hann( N )' */ +extern const Word16 filter_LP15_360H_13b_fx[]; /* Sincfilt.m: N=360*2+1, Fmin=0, Fmax=1/15, hann( N )' */ extern const Word16 filter_LP24_90H_13b_fx[]; extern const Word16 filter_LP24_90H_fx[]; @@ -182,7 +182,7 @@ extern const Word16 dicnlg2[40]; extern const Resampling_cfg resampling_cfg_tbl[]; /* table of resampling configurations */ extern const FrameSizeParams FrameSizeConfig[FRAME_SIZE_NB]; -extern const float h_high[]; /* HP filter for filtering random part of excitation in FEC */ +extern const float h_high[]; /* HP filter for filtering random part of excitation in FEC */ extern const Word16 h_high_fx[5]; extern const float crit_bands[]; /* Table of critical bands */ extern const float sincos_t[]; /* FFT - sinus and cosinus tables */ @@ -193,27 +193,27 @@ extern const float sincos_t_rad3[]; extern const Word16 sincos_t_rad3_fx[]; extern const int16_t fft256_read_indexes[]; /* FFT */ extern const float inter4_2[]; /* 1/4 resolution interpolation filter */ -extern const Word16 inter4_2_fx_Q15[]; /* 1/4 resolution interpolation filter */ +extern const Word16 inter4_2_fx_Q15[]; /* 1/4 resolution interpolation filter */ extern const Word16 inter4_2_fx[]; extern const Word16 pitch_inter4_1[UP_SAMP * L_INTERPOL1 + 1]; /*1Q14*/ extern const Word16 pitch_inter4_2[PIT_FIR_SIZE2]; /*1Q14*/ -extern const float LP_assym_window[]; /* Assymetric window for LP analysis @12.8kHz */ -extern const float LP_assym_window_16k[]; /* Assymetric window for LP analysis @16kHz */ +extern const float LP_assym_window[]; /* Assymetric window for LP analysis @12.8kHz */ +extern const float LP_assym_window_16k[]; /* Assymetric window for LP analysis @16kHz */ extern const Word16 Assym_window_W16fx[]; extern const Word16 assym_window_16k_fx[]; -extern const float hamcos_window[]; /* Hamming-Cosinus window */ -extern const float grid50[]; /* Table of grid points for evaluating Chebyshev polynomials */ -extern const float grid40[]; /* Table of grid points for evaluating Chebyshev polynomials */ +extern const float hamcos_window[]; /* Hamming-Cosinus window */ +extern const float grid50[]; /* Table of grid points for evaluating Chebyshev polynomials */ +extern const float grid40[]; /* Table of grid points for evaluating Chebyshev polynomials */ #ifdef IVAS_FLOAT_FIXED -extern const Word16 grid50_fx[(GRID50_POINTS - 1) / 2 - 1]; -extern const Word16 grid40_fx[(GRID40_POINTS - 1) / 2 - 1]; +extern const Word16 grid50_fx[( GRID50_POINTS - 1 ) / 2 - 1]; +extern const Word16 grid40_fx[( GRID40_POINTS - 1 ) / 2 - 1]; #endif -extern const float grid100[]; /* Table of 100 grid points for evaluating Chebyshev polynomials */ +extern const float grid100[]; /* Table of 100 grid points for evaluating Chebyshev polynomials */ -extern const float wind_sss[LEN_WIN_SSS]; /* window for modify_sf ana */ -extern const Word16 wind_sss_fx[LEN_WIN_SSS]; /*window for modify_sf ana*/ +extern const float wind_sss[LEN_WIN_SSS]; /* window for modify_sf ana */ +extern const Word16 wind_sss_fx[LEN_WIN_SSS]; /*window for modify_sf ana*/ -extern const float filter5_39s320_120[]; /* LP FIR filter for 8kHz signal resampling */ +extern const float filter5_39s320_120[]; /* LP FIR filter for 8kHz signal resampling */ extern const Word16 filter5_39s320_120_fx[]; @@ -236,28 +236,28 @@ extern const Word32 lag_window_16k_32[NUM_LAGW_STRENGTHS][16]; extern const Word32 lag_window_25k6_32[NUM_LAGW_STRENGTHS][16]; extern const Word32 lag_window_32k_32[NUM_LAGW_STRENGTHS][16]; extern const Word32 lag_window_48k_32[16]; -extern const float interpol_frac2[]; /* LPC interpolation coefficients for two-subframe mode */ -extern const Word16 interpol_frac2_fx[]; /* LPC interpolation coefficients for two-subframe mode */ -extern const float interpol_frac2_mid[]; /* LPC interpolation coefficients with mid-ISFs for two-subframe mode */ -extern const float interpol_frac_12k8[]; /* LPC interpolation coefficients */ +extern const float interpol_frac2[]; /* LPC interpolation coefficients for two-subframe mode */ +extern const Word16 interpol_frac2_fx[]; /* LPC interpolation coefficients for two-subframe mode */ +extern const float interpol_frac2_mid[]; /* LPC interpolation coefficients with mid-ISFs for two-subframe mode */ +extern const float interpol_frac_12k8[]; /* LPC interpolation coefficients */ extern const Word16 interpol_frac_fx[NB_SUBFR]; -extern const float interpol_isp_amr_wb[]; /* LPC interpolation coefficients for AMR-WB interoperable mode */ +extern const float interpol_isp_amr_wb[]; /* LPC interpolation coefficients for AMR-WB interoperable mode */ extern const Word16 interpol_isp_amr_wb_fx[]; -extern const float interpol_frac_16k[]; /* LPC interpolation coefficients @ 16kHz */ +extern const float interpol_frac_16k[]; /* LPC interpolation coefficients @ 16kHz */ extern const Word16 interpol_frac_16k_fx[NB_SUBFR16k]; -extern const float interpol_frac_mid[]; /* LPC interpolation coefficients with mid-ISFs */ -extern const Word16 interpol_frac_mid_fx[NB_SUBFR * 3]; -extern const float interpol_frac_mid_16k[]; /* LPC interpolation coefficients with mid-ISFs @ 16kHz */ +extern const float interpol_frac_mid[]; /* LPC interpolation coefficients with mid-ISFs */ +extern const Word16 interpol_frac_mid_fx[NB_SUBFR * 3]; +extern const float interpol_frac_mid_16k[]; /* LPC interpolation coefficients with mid-ISFs @ 16kHz */ extern const Word16 interpol_frac_mid_16k_fx[NB_SUBFR16k * 3]; extern const float interpol_frac_mid_relaxprev_12k8[]; /* LPC interpolation coefficients with mid-ISFs @ 16kHz - relaxed prev frame interp */ extern const Word16 interpol_frac_mid_relaxprev_12k8_fx[NB_SUBFR * 3]; -extern const float interpol_frac_mid_FEC[]; /* LPC interpolation coefficients with mid-ISFs - FEC */ +extern const float interpol_frac_mid_FEC[]; /* LPC interpolation coefficients with mid-ISFs - FEC */ extern const Word16 interpol_frac_mid_FEC_fx[NB_SUBFR * 3]; -extern const float interpol_frac_mid_relaxprev_16k[]; /* LPC interpolation coefficients with mid-ISFs @ 16kHz - relaxed prev frame interp */ +extern const float interpol_frac_mid_relaxprev_16k[]; /* LPC interpolation coefficients with mid-ISFs @ 16kHz - relaxed prev frame interp */ extern const Word16 interpol_frac_mid_relaxprev_16k_fx[NB_SUBFR16k * 3]; -extern const float interpol_frac_mid_16k_FEC[]; /* LPC interpolation coefficients with mid-ISFs @ 16kHz - FEC */ +extern const float interpol_frac_mid_16k_FEC[]; /* LPC interpolation coefficients with mid-ISFs @ 16kHz - FEC */ extern const Word16 interpol_frac_mid_16k_FEC_fx[NB_SUBFR16k * 3]; extern const float interpol_frac_mid_relaxprev_pred_12k8[]; extern const Word16 interpol_frac_mid_relaxprev_pred_12k8_fx[NB_SUBFR * 3]; @@ -265,7 +265,7 @@ extern const float interpol_frac_mid_relaxprev_pred_16k[]; extern const Word16 interpol_frac_mid_relaxprev_pred_16k_fx[NB_SUBFR16k * 3]; extern const float inter6_2[PIT_FIR_SIZE6_2]; -extern const Word16 pitch_inter6_2[PIT_FIR_SIZE6_2]; /*1Q14*/ +extern const Word16 pitch_inter6_2[PIT_FIR_SIZE6_2]; /*1Q14*/ extern const float inter4_2tcx2_flt[4][4]; extern const float inter6_2tcx2_flt[6][4]; @@ -279,31 +279,31 @@ typedef struct TCX_LTP_FILTER_FLT extern const TCX_LTP_FILTER_FLT tcxLtpFilters_flt[12]; typedef struct TCX_LTP_FILTER { - const Word16 *filt; - Word16 length; + const Word16 *filt; + Word16 length; } TCX_LTP_FILTER; extern const TCX_LTP_FILTER tcxLtpFilters[12]; -extern const float gain_qua_mless_7b[]; /* Gain quantization - gain quantization table */ -extern const float gain_qua_mless_6b_stereo[]; /* Gain quantization - gain quantization table in IVAS */ +extern const float gain_qua_mless_7b[]; /* Gain quantization - gain quantization table */ +extern const float gain_qua_mless_6b_stereo[]; /* Gain quantization - gain quantization table in IVAS */ extern const Word16 gain_qua_mless_6b_stereo_fx[]; /* Gain quantization - gain quantization table in IVAS */ -extern const float gain_qua_mless_6b[]; /* Gain quantization - gain quantization table */ -extern const float gain_qua_mless_5b[]; /* Gain quantization - gain quantization table */ +extern const float gain_qua_mless_6b[]; /* Gain quantization - gain quantization table */ +extern const float gain_qua_mless_5b[]; /* Gain quantization - gain quantization table */ extern const Word16 gain_qua_mless_7b_fx[]; extern const Word16 gain_qua_mless_6b_fx[]; extern const Word16 gain_qua_mless_5b_fx[]; -extern const float pred_gain[]; /* Gain quantization - MA predicition coefficients for gain quantizer */ -extern const float t_qua_gain6b[]; /* Gain quantization - gain quantization table for AMR-WB interoperable mode */ -extern const float t_qua_gain7b[]; /* Gain quantization - gain quantization table for AMR-WB interoperable mode */ +extern const float pred_gain[]; /* Gain quantization - MA predicition coefficients for gain quantizer */ +extern const float t_qua_gain6b[]; /* Gain quantization - gain quantization table for AMR-WB interoperable mode */ +extern const float t_qua_gain7b[]; /* Gain quantization - gain quantization table for AMR-WB interoperable mode */ extern const Word16 pred_gain_fx[GAIN_PRED_ORDER]; extern const Word16 t_qua_gain6b_fx[64 * 2]; extern const Word16 t_qua_gain7b_fx[128 * 2]; -extern const float Es_pred_qua_5b[]; /* Gain quantization - quantization table for scaled innovation energy prediciton */ -extern const float Es_pred_qua_4b[]; /* Gain quantization - quantization table for scaled innovation energy prediciton */ -extern const float Es_pred_qua_3b[]; /* Gain quantization - quantization table for scaled innovation energy prediciton */ -extern const float Es_pred_qua_4b_no_ltp[]; /* Gain quantization - quantization table for scaled innovation energy prediciton */ +extern const float Es_pred_qua_5b[]; /* Gain quantization - quantization table for scaled innovation energy prediciton */ +extern const float Es_pred_qua_4b[]; /* Gain quantization - quantization table for scaled innovation energy prediciton */ +extern const float Es_pred_qua_3b[]; /* Gain quantization - quantization table for scaled innovation energy prediciton */ +extern const float Es_pred_qua_4b_no_ltp[]; /* Gain quantization - quantization table for scaled innovation energy prediciton */ extern const Word16 Es_pred_qua_5b_fx[32]; extern const Word16 Es_pred_qua_4b_fx[16]; extern const Word16 Es_pred_qua_3b_fx[8]; @@ -347,7 +347,7 @@ extern const int16_t E_ROM_qua_gain7b_const[]; extern const float gain_qua_mless[]; -extern const float tbl_gain_code_tc[]; /* TC - code gain quantization table */ +extern const float tbl_gain_code_tc[]; /* TC - code gain quantization table */ extern const Word16 tbl_gain_code_tc_fx[N_GAIN_CODE_TC]; extern const Word16 tbl_gain_code_tc_quant_mean[N_GAIN_CODE_TC - 1]; @@ -377,7 +377,7 @@ extern const float exp_tab_p[]; /* HF BWE - Table of values exp(-j*w*i) */ extern const Word16 exp_tab_p_fx[]; extern const float exp_tab_q[]; /* HF BWE - Table of values exp(-j*w*i) */ extern const Word16 exp_tab_q_fx[]; -extern const float HP_gain[]; /* HF BWE - quantization table for 23.85 */ +extern const float HP_gain[]; /* HF BWE - quantization table for 23.85 */ extern const Word16 HP_gain_fx[]; extern const float fir_6k_8k[]; /* HF BWE - band-pass filter coefficients */ @@ -418,17 +418,17 @@ extern const float edct_table_200[]; extern const float edct_table_240[]; extern const float edct_table_256[]; extern const float edct_table_400[]; -extern const float edct_table_600[]; /* EDCT */ -extern const Word16 edct_table_80_fx[]; /* EDCT */ -extern const Word16 edct_table_120_fx[]; /* EDCT */ -extern const Word16 edct_table_100_fx[]; /* EDCT */ -extern const Word16 edct_table_320_fx[]; /* EDCT */ -extern const Word16 edct_table_480_fx[]; /* EDCT */ -extern const Word16 edct_table_600_fx[]; /* EDCT */ -extern const Word16 edct_table_128_fx[]; /* EDCT */ -extern const Word16 edct_table_160_fx[]; /* EDCT */ -extern const Word16 edct_table_40_fx[]; /* EDCT */ -extern const Word16 edct_table_20_fx[]; /* EDCT */ +extern const float edct_table_600[]; /* EDCT */ +extern const Word16 edct_table_80_fx[]; /* EDCT */ +extern const Word16 edct_table_120_fx[]; /* EDCT */ +extern const Word16 edct_table_100_fx[]; /* EDCT */ +extern const Word16 edct_table_320_fx[]; /* EDCT */ +extern const Word16 edct_table_480_fx[]; /* EDCT */ +extern const Word16 edct_table_600_fx[]; /* EDCT */ +extern const Word16 edct_table_128_fx[]; /* EDCT */ +extern const Word16 edct_table_160_fx[]; /* EDCT */ +extern const Word16 edct_table_40_fx[]; /* EDCT */ +extern const Word16 edct_table_20_fx[]; /* EDCT */ extern const Word16 edct_table_64_fx[]; extern const Word16 edct_table_200_fx[]; extern const Word16 edct_table_240_fx[]; @@ -444,7 +444,7 @@ extern const float crit_bins_corr[CRIT_NOIS_BAND]; extern const Word16 crit_bins_corr_fx[]; extern const float crit_bands_loc[]; /* (used only in AMR-WB IO mode) */ extern const Word16 crit_bands_loc_fx[]; -extern const float mfreq_loc_LD[]; /* LD music post-filter */ +extern const float mfreq_loc_LD[]; /* LD music post-filter */ extern const Word16 mfreq_loc_LD_fx[]; extern const int16_t mfreq_bindiv_LD[]; extern const float post_dct_wind[OFFSET2]; @@ -472,26 +472,26 @@ extern const int16_t hq_swb_bwe_nb_bits[]; *----------------------------------------------------------------------------------*/ extern const Word16 Indirect_dico1[SIZE_BK1]; -extern const float mean_isf_amr_wb[M]; /* Mean ISF vector (only in AMR-WB IO mode) */ +extern const float mean_isf_amr_wb[M]; /* Mean ISF vector (only in AMR-WB IO mode) */ -extern const Word16 mean_isf_amr_wb_fx[M]; /* Mean ISF vector (only in AMR-WB IO mode) */ +extern const Word16 mean_isf_amr_wb_fx[M]; /* Mean ISF vector (only in AMR-WB IO mode) */ extern const float mean_isf_noise_amr_wb[]; /* Mean ISF vector for SID frame (only in AMR-WB IO mode) */ -extern const Word16 mean_isf_noise_amr_wb_fx[]; /* Mean ISF vector for SID frame (only in AMR-WB IO mode) */ +extern const Word16 mean_isf_noise_amr_wb_fx[]; /* Mean ISF vector for SID frame (only in AMR-WB IO mode) */ -extern const float gaus_dico[]; /* Gaussian codebook */ +extern const float gaus_dico[]; /* Gaussian codebook */ extern const Word16 gaus_dico_fx[]; -extern const float gaus_dico_swb[]; /* Gaussian codebook for SWB TBE */ +extern const float gaus_dico_swb[]; /* Gaussian codebook for SWB TBE */ extern const Word16 gaus_dico_swb_fx[]; extern const float dico1_isf[]; /* ISF codebook - common 1st stage, 1st split (only in AMR-WB IO mode) */ -extern const Word16 dico1_isf_fx[]; /* ISF codebook - common 1st stage, 1st split (only in AMR-WB IO mode) */ +extern const Word16 dico1_isf_fx[]; /* ISF codebook - common 1st stage, 1st split (only in AMR-WB IO mode) */ extern const float dico2_isf[]; /* ISF codebook - common 1st stage, 2nd split (only in AMR-WB IO mode) */ -extern const Word16 dico2_isf_fx[]; /* ISF codebook - common 1st stage, 2nd split (only in AMR-WB IO mode) */ +extern const Word16 dico2_isf_fx[]; /* ISF codebook - common 1st stage, 2nd split (only in AMR-WB IO mode) */ extern const float dico21_isf_46b[]; /* ISF codebook - 46b, 2nd stage, 1st split (only in AMR-WB IO mode) */ extern const float dico22_isf_46b[]; /* ISF codebook - 46b, 2nd stage, 2st split (only in AMR-WB IO mode) */ @@ -499,23 +499,23 @@ extern const float dico23_isf_46b[]; /* ISF codebook - 46b, 2nd stage, 3rd split extern const float dico24_isf_46b[]; /* ISF codebook - 46b, 2nd stage, 4th split (only in AMR-WB IO mode) */ extern const float dico25_isf_46b[]; /* ISF codebook - 46b, 2nd stage, 5th split (only in AMR-WB IO mode) */ -extern const Word16 dico21_isf_46b_fx[]; /* ISF codebook - 46b, 2nd stage, 1st split (only in AMR-WB IO mode) */ -extern const Word16 dico22_isf_46b_fx[]; /* ISF codebook - 46b, 2nd stage, 2st split (only in AMR-WB IO mode) */ -extern const Word16 dico23_isf_46b_fx[]; /* ISF codebook - 46b, 2nd stage, 3rd split (only in AMR-WB IO mode) */ -extern const Word16 dico24_isf_46b_fx[]; /* ISF codebook - 46b, 2nd stage, 4th split (only in AMR-WB IO mode) */ -extern const Word16 dico25_isf_46b_fx[]; /* ISF codebook - 46b, 2nd stage, 5th split (only in AMR-WB IO mode) */ +extern const Word16 dico21_isf_46b_fx[]; /* ISF codebook - 46b, 2nd stage, 1st split (only in AMR-WB IO mode) */ +extern const Word16 dico22_isf_46b_fx[]; /* ISF codebook - 46b, 2nd stage, 2st split (only in AMR-WB IO mode) */ +extern const Word16 dico23_isf_46b_fx[]; /* ISF codebook - 46b, 2nd stage, 3rd split (only in AMR-WB IO mode) */ +extern const Word16 dico24_isf_46b_fx[]; /* ISF codebook - 46b, 2nd stage, 4th split (only in AMR-WB IO mode) */ +extern const Word16 dico25_isf_46b_fx[]; /* ISF codebook - 46b, 2nd stage, 5th split (only in AMR-WB IO mode) */ extern const float dico21_isf_36b[]; /* ISF codebook - 36b, 2nd stage, 1st split (only in AMR-WB IO mode) */ -extern const Word16 dico21_isf_36b_fx[]; /* ISF codebook - 36b, 2nd stage, 1st split (only in AMR-WB IO mode) */ +extern const Word16 dico21_isf_36b_fx[]; /* ISF codebook - 36b, 2nd stage, 1st split (only in AMR-WB IO mode) */ extern const float dico22_isf_36b[]; /* ISF codebook - 36b, 2nd stage, 2nd split (only in AMR-WB IO mode) */ -extern const Word16 dico22_isf_36b_fx[]; /* ISF codebook - 36b, 2nd stage, 2nd split (only in AMR-WB IO mode) */ +extern const Word16 dico22_isf_36b_fx[]; /* ISF codebook - 36b, 2nd stage, 2nd split (only in AMR-WB IO mode) */ extern const float dico23_isf_36b[]; /* ISF codebook - 36b, 2nd stage, 3rd split (only in AMR-WB IO mode) */ -extern const Word16 dico23_isf_36b_fx[]; /* ISF codebook - 36b, 2nd stage, 3rd split (only in AMR-WB IO mode) */ +extern const Word16 dico23_isf_36b_fx[]; /* ISF codebook - 36b, 2nd stage, 3rd split (only in AMR-WB IO mode) */ extern const float dico1_ns_28b[]; /* ISF codebook for SID frames - 28b, 1st split */ extern const float dico2_ns_28b[]; /* ISF codebook for SID frames - 28b, 2nd spilt */ @@ -523,11 +523,11 @@ extern const float dico3_ns_28b[]; /* ISF codebook for SID frames - 28b, 3rd spi extern const float dico4_ns_28b[]; /* ISF codebook for SID frames - 28b, 4th spilt */ extern const float dico5_ns_28b[]; /* ISF codebook for SID frames - 28b, 5th spilt */ -extern const Word16 dico1_ns_28b_fx[]; /* ISF codebook for SID frames - 28b, 1st split */ -extern const Word16 dico2_ns_28b_fx[]; /* ISF codebook for SID frames - 28b, 2nd spilt */ -extern const Word16 dico3_ns_28b_fx[]; /* ISF codebook for SID frames - 28b, 3rd spilt */ -extern const Word16 dico4_ns_28b_fx[]; /* ISF codebook for SID frames - 28b, 4th spilt */ -extern const Word16 dico5_ns_28b_fx[]; /* ISF codebook for SID frames - 28b, 5th spilt */ +extern const Word16 dico1_ns_28b_fx[]; /* ISF codebook for SID frames - 28b, 1st split */ +extern const Word16 dico2_ns_28b_fx[]; /* ISF codebook for SID frames - 28b, 2nd spilt */ +extern const Word16 dico3_ns_28b_fx[]; /* ISF codebook for SID frames - 28b, 3rd spilt */ +extern const Word16 dico4_ns_28b_fx[]; /* ISF codebook for SID frames - 28b, 4th spilt */ +extern const Word16 dico5_ns_28b_fx[]; /* ISF codebook for SID frames - 28b, 5th spilt */ extern const float dico1_cng_ev[]; extern const float dico2_cng_ev[]; @@ -603,8 +603,8 @@ extern const int16_t CB_lsf[]; extern const int16_t CB_p_lsf[]; extern const float *const ModeMeans[]; extern const float *const Predictors[]; -extern const Word16 * const ModeMeans_fx[]; -extern const Word16 * const Predictors_fx[]; +extern const Word16 *const ModeMeans_fx[]; +extern const Word16 *const Predictors_fx[]; extern const int16_t CBsizes[]; extern const int16_t CBbits[]; @@ -613,13 +613,13 @@ extern const float vals[NO_LEADERS][MAX_NO_VALS]; extern const Word16 vals_fx[NO_LEADERS][MAX_NO_VALS]; extern const int16_t no_vals[NO_LEADERS]; -//extern const Word16 no_vals_fx[NO_LEADERS]; +// extern const Word16 no_vals_fx[NO_LEADERS]; extern const int16_t no_vals_ind[NO_LEADERS][MAX_NO_VALS]; -//extern const Word16 no_vals_ind_fx[NO_LEADERS][MAX_NO_VALS]; +// extern const Word16 no_vals_ind_fx[NO_LEADERS][MAX_NO_VALS]; extern const int16_t C_VQ[LATTICE_DIM + 1][LATTICE_DIM + 1]; -//extern const Word16 C_VQ_fx[LATTICE_DIM + 1][LATTICE_DIM + 1]; +// extern const Word16 C_VQ_fx[LATTICE_DIM + 1][LATTICE_DIM + 1]; extern const int16_t BitsVQ[]; extern const int16_t BitsVQ_p[]; @@ -645,24 +645,24 @@ extern const float pl_HQ[]; extern const Word16 pl_HQ_fx[]; extern const int16_t pi0[]; -//extern const Word16 pi0_fx[]; +// extern const Word16 pi0_fx[]; extern const UWord32 table_no_cv[]; extern const Word32 table_no_cv_fx[]; extern const int16_t pl_par[]; -//extern const Word16 pl_par_fx[]; /* 1 if even number of signs */ +// extern const Word16 pl_par_fx[]; /* 1 if even number of signs */ extern const float *const Quantizers[]; extern const float *const Quantizers_p[]; -extern const Word16 * const Quantizers_p_fx[]; -extern const Word16 * const Quantizers_fx[]; +extern const Word16 *const Quantizers_p_fx[]; +extern const Word16 *const Quantizers_fx[]; extern const int16_t cng_sort[]; -//extern const Word16 cng_sort_fx[]; +// extern const Word16 cng_sort_fx[]; extern const int16_t perm_MSLVQ[][4]; -//extern const Word16 perm_MSLVQ_fx[][4]; +// extern const Word16 perm_MSLVQ_fx[][4]; extern const int16_t min_lat_bits_SN[]; extern const Word16 min_lat_bits_SN_fx[]; @@ -809,7 +809,6 @@ extern const Word16 lsf_cdk_wb_vc_stg3[]; extern const Word16 lsf_ind_cdk_wb_vc_stg4[]; - extern const float *const lsf_ind_codebook_flt[2][2][TCXLPC_IND_NUMSTAGES]; extern const Word16 *const lsf_ind_codebook[2][2][TCXLPC_IND_NUMSTAGES]; extern const int16_t lsf_ind_numbits[TCXLPC_IND_NUMSTAGES]; @@ -852,33 +851,33 @@ extern const int16_t skip_bands_WB_TBE[]; /* bands for WB TBE quantisation */ extern const float interpol_frac_shb_flt[]; extern const Word16 interpol_frac_shb[NB_SUBFR * 2]; -extern const float AP1_STEEP[]; /* All pass filter coeffs for interpolation and decimation by a factor of 2 */ -extern const float AP2_STEEP[]; /* All pass filter coeffs for interpolation and decimation by a factor of 2 */ -extern const Word16 AP1_STEEP_FX[]; /* All pass filter coeffs for interpolation and decimation by a factor of 2 */ -extern const Word16 AP2_STEEP_FX[]; /* All pass filter coeffs for interpolation and decimation by a factor of 2 */ +extern const float AP1_STEEP[]; /* All pass filter coeffs for interpolation and decimation by a factor of 2 */ +extern const float AP2_STEEP[]; /* All pass filter coeffs for interpolation and decimation by a factor of 2 */ +extern const Word16 AP1_STEEP_FX[]; /* All pass filter coeffs for interpolation and decimation by a factor of 2 */ +extern const Word16 AP2_STEEP_FX[]; /* All pass filter coeffs for interpolation and decimation by a factor of 2 */ -extern const float STEPS[]; /* Granuality in conversion from lpc to lsp */ +extern const float STEPS[]; /* Granuality in conversion from lpc to lsp */ extern const float cos_fb_exc[]; extern const Word16 cos_fb_exc_fx[32]; extern const float recip_order[]; -extern const float win_lpc_shb[]; /* Window for calculating SHB LPC coeffs */ +extern const float win_lpc_shb[]; /* Window for calculating SHB LPC coeffs */ extern const Word16 win_lpc_shb_fx[]; /* Window for calculating SHB LPC coeffs */ extern const float win_lpc_hb_wb[]; extern const Word16 win_lpc_hb_wb_fx[]; extern const float ola_win_shb_switch_fold[]; extern const Word16 ola_win_shb_switch_fold_fx[]; -extern const float win_flatten[]; /* Window for calculating whitening filter for SHB excitation */ +extern const float win_flatten[]; /* Window for calculating whitening filter for SHB excitation */ extern const Word16 win_flatten_fx[]; extern const float win_flatten_4k[]; /* Window for calculating whitening filter for WB excitation */ extern const Word16 win_flatten_4k_fx[]; -extern const float window_shb[]; /* Overlap add window for SHB excitation used in anal and synth */ +extern const float window_shb[]; /* Overlap add window for SHB excitation used in anal and synth */ extern const Word16 window_shb_fx[]; extern const float window_shb_32k[]; /* Upsampled overlap add window for SHB excitation used transition generation */ extern const Word16 window_shb_32k_fx[]; extern const float subwin_shb[]; /* Short overlap add window for SHB excitation used in anal and synth */ -extern const Word16 subwin_shb_fx[]; /* Short overlap add window for SHB excitation used in anal and synth */ +extern const Word16 subwin_shb_fx[]; /* Short overlap add window for SHB excitation used in anal and synth */ extern const float window_wb[]; extern const float subwin_wb[]; /* Short overlap add window for SHB excitation used in anal and synth */ extern const Word16 window_wb_fx[]; @@ -900,7 +899,7 @@ extern const float swb_tbe_lsfvq_cbook_8b_flt[]; extern const Word16 swb_tbe_lsfvq_cbook_8b[]; extern const float SHBCB_SubGain5bit[]; /* 5 bit Quantizer table for SHB gain shapes */ extern const Word16 SHBCB_SubGain5bit_fx[]; -extern const float HBCB_SubGain5bit[]; /* 5-bit TD WB BWE temporal shaping codebook */ +extern const float HBCB_SubGain5bit[]; /* 5-bit TD WB BWE temporal shaping codebook */ extern const Word16 HBCB_SubGain5bit_fx[]; extern const float SHBCB_FrameGain64[]; /* 6 bit Quantizer table for SHB overall gain */ extern const Word32 SHBCB_FrameGain64_fx[]; @@ -913,27 +912,27 @@ extern const Word16 full_band_bpf_1_fx[][5]; extern const Word16 full_band_bpf_2_fx[][5]; extern const Word16 full_band_bpf_3_fx[][5]; -extern const float lsf_q_cb_4b[]; /* 4 bit differential scalar quantizer table for TD SWB BWE LSFs 1 and 2*/ -extern const float lsf_q_cb_3b[]; /* 3 bit differential scalar quantizer table for TD SWB BWE LSFs 3, 4 and 5*/ -extern const float *const lsf_q_cb[]; /* Codebook array for each LSF */ -extern const Word16 * const lsf_q_cb_fx[]; +extern const float lsf_q_cb_4b[]; /* 4 bit differential scalar quantizer table for TD SWB BWE LSFs 1 and 2*/ +extern const float lsf_q_cb_3b[]; /* 3 bit differential scalar quantizer table for TD SWB BWE LSFs 3, 4 and 5*/ +extern const float *const lsf_q_cb[]; /* Codebook array for each LSF */ +extern const Word16 *const lsf_q_cb_fx[]; extern const int16_t lsf_q_cb_size[]; /* Size of each element of the above */ extern const int16_t lsf_q_num_bits[]; /* Size of each element of the above, in bits */ extern const float mirror_point_q_cb[]; /* LSF mirroring point codebook */ extern const Word16 mirror_point_q_cb_fx[]; -extern const float lsf_grid[4][5]; /* LSF mirroring adjustment grid */ +extern const float lsf_grid[4][5]; /* LSF mirroring adjustment grid */ extern const Word16 lsf_grid_fx[4][5]; -extern const float grid_smoothing[]; /* LSF mirroring smoothing table */ -extern const Word16 grid_smoothing_fx[]; /* LSF mirroring smoothing table */ +extern const float grid_smoothing[]; /* LSF mirroring smoothing table */ +extern const Word16 grid_smoothing_fx[]; /* LSF mirroring smoothing table */ -extern const float overlap_coefs[]; /* HR SWB BWE - overlap coefficients */ -extern const float overlap_coefs_48kHz[]; /* HR SWB BWE - overlap coefficients @48kHz */ -extern const Word16 overlap_coefs_fx[NSV_OVERLAP*WIDTH_BAND]; /* in Q15 */ -extern const Word16 overlap_coefs_48kHz_fx[NSV_OVERLAP*WIDTH_BAND]; /* in Q15 */ +extern const float overlap_coefs[]; /* HR SWB BWE - overlap coefficients */ +extern const float overlap_coefs_48kHz[]; /* HR SWB BWE - overlap coefficients @48kHz */ +extern const Word16 overlap_coefs_fx[NSV_OVERLAP * WIDTH_BAND]; /* in Q15 */ +extern const Word16 overlap_coefs_48kHz_fx[NSV_OVERLAP * WIDTH_BAND]; /* in Q15 */ -extern const float swb_hr_env_code1[]; /* HR SWB BWE - envelope Q table - first two subabnds in non-transient frames */ -extern const float swb_hr_env_code2[]; /* HR SWB BWE - envelope Q table - second two subabnds in non-transient frames*/ -extern const float swb_hr_env_code3[]; /* HR SWB BWE - envelope Q table - two subabnds in transient frames */ +extern const float swb_hr_env_code1[]; /* HR SWB BWE - envelope Q table - first two subabnds in non-transient frames */ +extern const float swb_hr_env_code2[]; /* HR SWB BWE - envelope Q table - second two subabnds in non-transient frames*/ +extern const float swb_hr_env_code3[]; /* HR SWB BWE - envelope Q table - two subabnds in transient frames */ extern const Word16 swb_hr_env_code1_fx[]; /* HR SWB BWE - envelope Q table - first two subabnds in non-transient frames */ extern const Word16 swb_hr_env_code2_fx[]; /* HR SWB BWE - envelope Q table - second two subabnds in non-transient frames*/ extern const Word16 swb_hr_env_code3_fx[]; /* HR SWB BWE - envelope Q table - two subands in transient frames */ @@ -1191,7 +1190,7 @@ extern const int16_t nextstate[STATES][2]; extern const int16_t fine_gain_bits[]; extern const float *const finegain[]; -extern const Word16* finegain_fx[5]; +extern const Word16 *finegain_fx[5]; extern const uint8_t hBitsMinus1_N01[2]; extern const uint8_t hBitsMinus1_N02[65]; extern const uint8_t hBitsMinus1_N03[65]; @@ -1377,13 +1376,13 @@ extern const Word16 erb_NB_fx[NUM_ERB_NB + 1]; extern const float AmpCB1_WB[64][10]; extern const Word16 AmpCB1_WB_fx[640]; extern const float AmpCB2_WB[64][NUM_ERB_WB - 11]; -extern const Word16 AmpCB2_WB_fx[64 * (NUM_ERB_WB - 13)]; +extern const Word16 AmpCB2_WB_fx[64 * ( NUM_ERB_WB - 13 )]; extern const float AmpCB1_NB[64][10]; extern const Word16 AmpCB1_NB_fx[640]; extern const float AmpCB2_NB[64][NUM_ERB_NB - 11]; -extern const Word16 AmpCB2_NB_fx[64 * (NUM_ERB_NB - 13)]; +extern const Word16 AmpCB2_NB_fx[64 * ( NUM_ERB_NB - 13 )]; extern const float PowerCB_WB[64][2]; extern const float PowerCB_NB[64][2]; @@ -1460,8 +1459,8 @@ extern const float YGain_dic1_LR[]; extern const float YGain_dic2_LR[]; extern const float YGain_dic3_LR[]; extern const Word16 YGain_dic1_LR_fx[]; -extern const Word16 YGain_dic2_LR_fx[];/*Q13 */ -extern const Word16 YGain_dic3_LR_fx[];/*Q13 */ +extern const Word16 YGain_dic2_LR_fx[]; /*Q13 */ +extern const Word16 YGain_dic3_LR_fx[]; /*Q13 */ extern const float Gain_dic2_NBHR[]; extern const float Gain_dic3_NBHR[]; extern const Word16 Gain_dic3_NBHR_fx[]; @@ -1530,7 +1529,7 @@ extern const float w_fft256[128]; extern const int16_t Ip_fft512[18]; extern const float w_fft512[256]; extern const Word16 w_fft512_fx_evs[256]; -//extern const Word16 w_fft512_fx[256]; +// extern const Word16 w_fft512_fx[256]; extern const int16_t Idx_dortft40[40]; extern const int16_t Odx_fft8_5[8]; extern const int16_t ip_edct2_64[6]; @@ -1634,7 +1633,6 @@ extern const Word16 *cldfb_protoFilter_2_5ms[]; extern const Word16 cldfb_scale_2_5ms[7]; - extern const float rot_vec_syn_re_L10[5]; extern const float rot_vec_syn_im_L10[5]; extern const float rot_vec_syn_re_L16[8]; @@ -1692,7 +1690,7 @@ extern const SCALE_SETUP scaleTable_cn_only[SIZE_SCALE_TABLE_CN]; extern const SCALE_SETUP scaleTable_cn_dirac[15]; extern const float scaleTable_cn_only_amrwbio_flt[SIZE_SCALE_TABLE_CN_AMRWB][2]; extern const Word16 scaleTable_cn_only_amrwbio[SIZE_SCALE_TABLE_CN_AMRWB][2]; -extern const Word32 scaleTable_cn_only_amrwbio_fx_by_10f[SIZE_SCALE_TABLE_CN_AMRWB][2]; +extern const Word32 scaleTable_cn_only_amrwbio_fx_by_10f[SIZE_SCALE_TABLE_CN_AMRWB][2]; extern const int16_t sidparts_encoder_noise_est[SIZE_SIDPARTS_ENC_NOISE_EST]; @@ -1709,8 +1707,8 @@ extern const int16_t levels_37bits[FD_CNG_stages_37bits]; extern const int16_t bits_37bits[FD_CNG_stages_37bits]; extern const float *const cdk_37bits_flt[]; extern const float *const cdk_37bits_ivas[]; -extern Word16 const * const cdk_37bits[]; -extern Word16 const * const ivas_cdk_37bits_fx[]; +extern Word16 const *const cdk_37bits[]; +extern Word16 const *const ivas_cdk_37bits_fx[]; extern const float fftSineTab640[321]; extern const Word16 fftSineTab640_fx[321]; @@ -1719,7 +1717,7 @@ extern const float olapWinAna640[640]; #ifdef IVAS_FLOAT_FIXED extern const Word32 olapWinAna512_fx[512]; // Q30 extern const Word32 olapWinAna640_fx[640]; // Q30 -#endif // IVAS_FLOAT_FIXED +#endif // IVAS_FLOAT_FIXED extern const float olapWinSyn256[256]; extern const Word16 olapWinSyn256_fx[256]; @@ -1781,8 +1779,8 @@ extern const float cdk_37bits_6[]; extern const float gain_corr_fac_flt[]; extern const float gain_corr_inv_fac_flt[]; -extern const Word16 gain_corr_fac[]; /*pow(10,2^(-n-2)/28)*/ -extern const Word16 gain_corr_inv_fac[];/*pow(10,-2^(-n-2)/28)*/ +extern const Word16 gain_corr_fac[]; /*pow(10,2^(-n-2)/28)*/ +extern const Word16 gain_corr_inv_fac[]; /*pow(10,-2^(-n-2)/28)*/ extern const SCALE_TCX_SETUP scaleTcxTable[SIZE_SCALE_TABLE_TCX]; @@ -2018,9 +2016,9 @@ extern const Word32 LastCoefPred_1bit_fx[36]; extern const int16_t config_LSF_BWE[]; -//basops +// basops extern const Word32 BASOP_util_normReciprocal[CHEAP_NORM_SIZE]; -extern const Word16 f_atan_expand_range[MAXSFTAB - (MINSFTAB - 1)]; +extern const Word16 f_atan_expand_range[MAXSFTAB - ( MINSFTAB - 1 )]; extern const Word16 Grid[]; @@ -2037,7 +2035,7 @@ extern const Word16 sin_switch_16[30]; extern const Word16 sin_switch_32[60]; extern const Word16 sin_switch_48[90]; -extern const Word16 one_on_win_48k_fx[210]; /*Q14 */ +extern const Word16 one_on_win_48k_fx[210]; /*Q14 */ extern const Word16 one_on_win_8k_16k_48k_fx[70]; /*Q14 */ extern const Word16 window_8_16_32kHz_fx[]; @@ -2071,11 +2069,11 @@ extern const float TecSC[]; extern const Word16 sqrt_table_pitch_search[256 + 1]; /* fft_evs.c */ extern const Word16 RotVector_32[2 * 20]; -extern const Word16 RotVector_256[2 * (256 - 32)]; -extern const Word16 RotVector_320[2 * (320 - 20)]; -extern const Word16 RotVector_400[2 * (400 - 20)]; -extern const Word16 RotVector_480[2 * (480 - 30)]; -extern const Word16 RotVector_600[2 * (600 - 30)]; +extern const Word16 RotVector_256[2 * ( 256 - 32 )]; +extern const Word16 RotVector_320[2 * ( 320 - 20 )]; +extern const Word16 RotVector_400[2 * ( 400 - 20 )]; +extern const Word16 RotVector_480[2 * ( 480 - 30 )]; +extern const Word16 RotVector_600[2 * ( 600 - 30 )]; extern const Word16 FFT_REORDER_1024[]; extern const Word16 FFT_W64[]; extern const Word16 FFT_W128[]; @@ -2108,59 +2106,60 @@ extern const Word16 ivas_lsp_shb_prev_tbl_fx[]; #endif extern const Word16 tab_ari_qnew[4][4]; -//enhancer.c +// enhancer.c extern const Word16 phs_tbl_dec[]; extern const Word16 Low_H_phasedisp[L_SUBFR]; extern const Word16 Mid_H_phasedisp[L_SUBFR]; -//ACcontextMapping_dec_fx.c +// ACcontextMapping_dec_fx.c extern const Word16 Tab_esc_nb[4]; extern const Word16 pow2tab[15]; extern const Word32 pow2[]; extern const Word16 Es_pred_qua[8]; extern const Word16 Es_pred_qua_2[16]; -extern const Word16 T_DIV_L_Frame[];/*0Q15 * 2^-7 */ +extern const Word16 T_DIV_L_Frame[]; /*0Q15 * 2^-7 */ -//ivas_sns_com_fx.c +// ivas_sns_com_fx.c extern const Word16 pow_tilt_16k[64]; /* Q7 */ extern const Word16 pow_tilt_25_6k[64]; /* Q7 */ extern const Word16 pow_tilt_32k[64]; /* Q7 */ /*EVS basop*/ -extern const Word16 num_nelp_lp_fx[NELP_LP_ORDER + 1]; -extern const Word16 den_nelp_lp_fx[NELP_LP_ORDER + 1]; +extern const Word16 num_nelp_lp_fx[NELP_LP_ORDER + 1]; +extern const Word16 den_nelp_lp_fx[NELP_LP_ORDER + 1]; -extern const Word16 fir_6k_8k_fx[]; /* HF BWE - band-pass filter coefficients */ +extern const Word16 fir_6k_8k_fx[]; /* HF BWE - band-pass filter coefficients */ extern const Word16 pwf78_fx[17]; enum FUNC_GAIN_ENC { - FUNC_GAIN_ENC_MLESS = 0, /* Memory-less gain coding */ - FUNC_GAIN_ENC_2 = 1, /* AMR-WB gains quantizer (6bits/subfr (mode 4) or 7bits/subfr (mode 5)) */ /* !!! to be removed !!! */ - FUNC_GAIN_ENC_UV, /* UV gains quantizer (5bits/subfr) */ - FUNC_GAIN_ENC_GACELP_UV /* UV GACELP gain quantizer ((7=5-2bits/subfr) */ + FUNC_GAIN_ENC_MLESS = 0, /* Memory-less gain coding */ + FUNC_GAIN_ENC_2 = 1, + /* AMR-WB gains quantizer (6bits/subfr (mode 4) or 7bits/subfr (mode 5)) */ /* !!! to be removed !!! */ + FUNC_GAIN_ENC_UV, /* UV gains quantizer (5bits/subfr) */ + FUNC_GAIN_ENC_GACELP_UV /* UV GACELP gain quantizer ((7=5-2bits/subfr) */ }; extern const Word16 Hamcos_Window[]; extern const Word16 CNG_burst_att_fx[6][8]; extern const Word16 lpc_weights_fx[]; -extern const Word16 SHBCB_SubGain5bit_12_fx[]; /* 5 bit Quantizer table for SHB gain shapes */ +extern const Word16 SHBCB_SubGain5bit_12_fx[]; /* 5 bit Quantizer table for SHB gain shapes */ extern const Word16 E_ROM_inter4_1_fx[PIT_UP_SAMP * L_INTERPOL1 + 1]; extern const Word16 E_ROM_inter6_1_fx[PIT_UP_SAMP6 * L_INTERPOL1 + 1]; extern const Word16 kLog2TableFrac_x[256]; extern const Word16 kExp2TableFrac_x[256]; extern const Word16 One_div_fx[]; -//ivas_lfe_dec_fx.c +// ivas_lfe_dec_fx.c extern const Word32 tbl_two_pow_shift_by_4[35]; /* Q30 */ extern const Word16 ivas_tan_panning_gain_tbl_fx[601]; extern const Word16 ivas_sine_panning_tbl_fx[601]; extern const Word16 ivas_sin_az_fx[361]; -//edct_fx.c +// edct_fx.c extern const Word16 sin_scale_tbl_960[960]; extern const Word16 cos_scale_tbl_960[960]; extern const Word16 cos_scale_tbl_640[640]; diff --git a/lib_com/rom_com_fx.c b/lib_com/rom_com_fx.c index b4ff1eff7..d9c3822d7 100644 --- a/lib_com/rom_com_fx.c +++ b/lib_com/rom_com_fx.c @@ -43,838 +43,6144 @@ #include "wmc_auto.h" #include "rom_com_fx.h" -#define SHC( x ) ( (Word16) x ) +#define SHC( x ) ( (Word16) x ) -const Word16 w_fft4_fx[ 2 ] = { - SHC( 0x7fff ), SHC( 0x0000 ), +const Word16 w_fft4_fx[2] = { + SHC( 0x7fff ), + SHC( 0x0000 ), }; -const Word16 w_fft8_fx[ 8 ] = { - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x5a82 ), SHC( 0x5a82 ), SHC( 0x0000 ), SHC( 0x0000 ), SHC( 0x0000 ), SHC( 0x0000 ), - +const Word16 w_fft8_fx[8] = { + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x5a82 ), + SHC( 0x5a82 ), + SHC( 0x0000 ), + SHC( 0x0000 ), + SHC( 0x0000 ), + SHC( 0x0000 ), + }; -const Word16 w_fft16_fx[ 8 ] = { - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x5a82 ), SHC( 0x5a82 ), SHC( 0x7641 ), SHC( 0x30fb ), SHC( 0x30fb ), SHC( 0x7641 ), - +const Word16 w_fft16_fx[8] = { + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x5a82 ), + SHC( 0x5a82 ), + SHC( 0x7641 ), + SHC( 0x30fb ), + SHC( 0x30fb ), + SHC( 0x7641 ), + }; -const Word16 w_fft32_fx[ 16 ] = { - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x5a82 ), SHC( 0x5a82 ), SHC( 0x7641 ), SHC( 0x30fb ), SHC( 0x30fb ), SHC( 0x7641 ), - SHC( 0x7d8a ), SHC( 0x18f8 ), SHC( 0x471c ), SHC( 0x6a6d ), SHC( 0x6a6d ), SHC( 0x471c ), SHC( 0x18f8 ), SHC( 0x7d8a ), - +const Word16 w_fft32_fx[16] = { + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x5a82 ), + SHC( 0x5a82 ), + SHC( 0x7641 ), + SHC( 0x30fb ), + SHC( 0x30fb ), + SHC( 0x7641 ), + SHC( 0x7d8a ), + SHC( 0x18f8 ), + SHC( 0x471c ), + SHC( 0x6a6d ), + SHC( 0x6a6d ), + SHC( 0x471c ), + SHC( 0x18f8 ), + SHC( 0x7d8a ), + }; -const Word16 w_fft64_fx[ 32 ] = { - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x5a82 ), SHC( 0x5a82 ), SHC( 0x7641 ), SHC( 0x30fb ), SHC( 0x30fb ), SHC( 0x7641 ), - SHC( 0x7d8a ), SHC( 0x18f8 ), SHC( 0x471c ), SHC( 0x6a6d ), SHC( 0x6a6d ), SHC( 0x471c ), SHC( 0x18f8 ), SHC( 0x7d8a ), - SHC( 0x7f62 ), SHC( 0x0c8b ), SHC( 0x5133 ), SHC( 0x62f2 ), SHC( 0x70e2 ), SHC( 0x3c56 ), SHC( 0x2528 ), SHC( 0x7a7d ), - SHC( 0x7a7d ), SHC( 0x2528 ), SHC( 0x3c56 ), SHC( 0x70e2 ), SHC( 0x62f2 ), SHC( 0x5133 ), SHC( 0x0c8b ), SHC( 0x7f62 ), - +const Word16 w_fft64_fx[32] = { + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x5a82 ), + SHC( 0x5a82 ), + SHC( 0x7641 ), + SHC( 0x30fb ), + SHC( 0x30fb ), + SHC( 0x7641 ), + SHC( 0x7d8a ), + SHC( 0x18f8 ), + SHC( 0x471c ), + SHC( 0x6a6d ), + SHC( 0x6a6d ), + SHC( 0x471c ), + SHC( 0x18f8 ), + SHC( 0x7d8a ), + SHC( 0x7f62 ), + SHC( 0x0c8b ), + SHC( 0x5133 ), + SHC( 0x62f2 ), + SHC( 0x70e2 ), + SHC( 0x3c56 ), + SHC( 0x2528 ), + SHC( 0x7a7d ), + SHC( 0x7a7d ), + SHC( 0x2528 ), + SHC( 0x3c56 ), + SHC( 0x70e2 ), + SHC( 0x62f2 ), + SHC( 0x5133 ), + SHC( 0x0c8b ), + SHC( 0x7f62 ), + }; -const Word16 w_fft128_fx[ 64 ] = { - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x5a82 ), SHC( 0x5a82 ), SHC( 0x7641 ), SHC( 0x30fb ), SHC( 0x30fb ), SHC( 0x7641 ), - SHC( 0x7d8a ), SHC( 0x18f8 ), SHC( 0x471c ), SHC( 0x6a6d ), SHC( 0x6a6d ), SHC( 0x471c ), SHC( 0x18f8 ), SHC( 0x7d8a ), - SHC( 0x7f62 ), SHC( 0x0c8b ), SHC( 0x5133 ), SHC( 0x62f2 ), SHC( 0x70e2 ), SHC( 0x3c56 ), SHC( 0x2528 ), SHC( 0x7a7d ), - SHC( 0x7a7d ), SHC( 0x2528 ), SHC( 0x3c56 ), SHC( 0x70e2 ), SHC( 0x62f2 ), SHC( 0x5133 ), SHC( 0x0c8b ), SHC( 0x7f62 ), - SHC( 0x7fd8 ), SHC( 0x0647 ), SHC( 0x55f5 ), SHC( 0x5ed7 ), SHC( 0x73b5 ), SHC( 0x36ba ), SHC( 0x2b1f ), SHC( 0x7884 ), - SHC( 0x7c29 ), SHC( 0x1f19 ), SHC( 0x41ce ), SHC( 0x6dca ), SHC( 0x66cf ), SHC( 0x4c3f ), SHC( 0x12c8 ), SHC( 0x7e9d ), - SHC( 0x7e9d ), SHC( 0x12c8 ), SHC( 0x4c3f ), SHC( 0x66cf ), SHC( 0x6dca ), SHC( 0x41ce ), SHC( 0x1f19 ), SHC( 0x7c29 ), - SHC( 0x7884 ), SHC( 0x2b1f ), SHC( 0x36ba ), SHC( 0x73b5 ), SHC( 0x5ed7 ), SHC( 0x55f5 ), SHC( 0x0647 ), SHC( 0x7fd8 ), - +const Word16 w_fft128_fx[64] = { + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x5a82 ), + SHC( 0x5a82 ), + SHC( 0x7641 ), + SHC( 0x30fb ), + SHC( 0x30fb ), + SHC( 0x7641 ), + SHC( 0x7d8a ), + SHC( 0x18f8 ), + SHC( 0x471c ), + SHC( 0x6a6d ), + SHC( 0x6a6d ), + SHC( 0x471c ), + SHC( 0x18f8 ), + SHC( 0x7d8a ), + SHC( 0x7f62 ), + SHC( 0x0c8b ), + SHC( 0x5133 ), + SHC( 0x62f2 ), + SHC( 0x70e2 ), + SHC( 0x3c56 ), + SHC( 0x2528 ), + SHC( 0x7a7d ), + SHC( 0x7a7d ), + SHC( 0x2528 ), + SHC( 0x3c56 ), + SHC( 0x70e2 ), + SHC( 0x62f2 ), + SHC( 0x5133 ), + SHC( 0x0c8b ), + SHC( 0x7f62 ), + SHC( 0x7fd8 ), + SHC( 0x0647 ), + SHC( 0x55f5 ), + SHC( 0x5ed7 ), + SHC( 0x73b5 ), + SHC( 0x36ba ), + SHC( 0x2b1f ), + SHC( 0x7884 ), + SHC( 0x7c29 ), + SHC( 0x1f19 ), + SHC( 0x41ce ), + SHC( 0x6dca ), + SHC( 0x66cf ), + SHC( 0x4c3f ), + SHC( 0x12c8 ), + SHC( 0x7e9d ), + SHC( 0x7e9d ), + SHC( 0x12c8 ), + SHC( 0x4c3f ), + SHC( 0x66cf ), + SHC( 0x6dca ), + SHC( 0x41ce ), + SHC( 0x1f19 ), + SHC( 0x7c29 ), + SHC( 0x7884 ), + SHC( 0x2b1f ), + SHC( 0x36ba ), + SHC( 0x73b5 ), + SHC( 0x5ed7 ), + SHC( 0x55f5 ), + SHC( 0x0647 ), + SHC( 0x7fd8 ), + }; -const Word16 w_fft256_fx[ 128 ] = { - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x5a82 ), SHC( 0x5a82 ), SHC( 0x7641 ), SHC( 0x30fb ), SHC( 0x30fb ), SHC( 0x7641 ), - SHC( 0x7d8a ), SHC( 0x18f8 ), SHC( 0x471c ), SHC( 0x6a6d ), SHC( 0x6a6d ), SHC( 0x471c ), SHC( 0x18f8 ), SHC( 0x7d8a ), - SHC( 0x7f62 ), SHC( 0x0c8b ), SHC( 0x5133 ), SHC( 0x62f2 ), SHC( 0x70e2 ), SHC( 0x3c56 ), SHC( 0x2528 ), SHC( 0x7a7d ), - SHC( 0x7a7d ), SHC( 0x2528 ), SHC( 0x3c56 ), SHC( 0x70e2 ), SHC( 0x62f2 ), SHC( 0x5133 ), SHC( 0x0c8b ), SHC( 0x7f62 ), - SHC( 0x7fd8 ), SHC( 0x0647 ), SHC( 0x55f5 ), SHC( 0x5ed7 ), SHC( 0x73b5 ), SHC( 0x36ba ), SHC( 0x2b1f ), SHC( 0x7884 ), - SHC( 0x7c29 ), SHC( 0x1f19 ), SHC( 0x41ce ), SHC( 0x6dca ), SHC( 0x66cf ), SHC( 0x4c3f ), SHC( 0x12c8 ), SHC( 0x7e9d ), - SHC( 0x7e9d ), SHC( 0x12c8 ), SHC( 0x4c3f ), SHC( 0x66cf ), SHC( 0x6dca ), SHC( 0x41ce ), SHC( 0x1f19 ), SHC( 0x7c29 ), - SHC( 0x7884 ), SHC( 0x2b1f ), SHC( 0x36ba ), SHC( 0x73b5 ), SHC( 0x5ed7 ), SHC( 0x55f5 ), SHC( 0x0647 ), SHC( 0x7fd8 ), - SHC( 0x7ff6 ), SHC( 0x0324 ), SHC( 0x5842 ), SHC( 0x5cb4 ), SHC( 0x7504 ), SHC( 0x33de ), SHC( 0x2e11 ), SHC( 0x776c ), - SHC( 0x7ce3 ), SHC( 0x1c0b ), SHC( 0x447a ), SHC( 0x6c24 ), SHC( 0x68a6 ), SHC( 0x49b4 ), SHC( 0x15e2 ), SHC( 0x7e1d ), - SHC( 0x7f09 ), SHC( 0x0fab ), SHC( 0x4ebf ), SHC( 0x64e8 ), SHC( 0x6f5f ), SHC( 0x3f17 ), SHC( 0x2223 ), SHC( 0x7b5d ), - SHC( 0x798a ), SHC( 0x2826 ), SHC( 0x398c ), SHC( 0x7255 ), SHC( 0x60ec ), SHC( 0x539b ), SHC( 0x096a ), SHC( 0x7fa7 ), - SHC( 0x7fa7 ), SHC( 0x096a ), SHC( 0x539b ), SHC( 0x60ec ), SHC( 0x7255 ), SHC( 0x398c ), SHC( 0x2826 ), SHC( 0x798a ), - SHC( 0x7b5d ), SHC( 0x2223 ), SHC( 0x3f17 ), SHC( 0x6f5f ), SHC( 0x64e8 ), SHC( 0x4ebf ), SHC( 0x0fab ), SHC( 0x7f09 ), - SHC( 0x7e1d ), SHC( 0x15e2 ), SHC( 0x49b4 ), SHC( 0x68a6 ), SHC( 0x6c24 ), SHC( 0x447a ), SHC( 0x1c0b ), SHC( 0x7ce3 ), - SHC( 0x776c ), SHC( 0x2e11 ), SHC( 0x33de ), SHC( 0x7504 ), SHC( 0x5cb4 ), SHC( 0x5842 ), SHC( 0x0324 ), SHC( 0x7ff6 ), - +const Word16 w_fft256_fx[128] = { + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x5a82 ), + SHC( 0x5a82 ), + SHC( 0x7641 ), + SHC( 0x30fb ), + SHC( 0x30fb ), + SHC( 0x7641 ), + SHC( 0x7d8a ), + SHC( 0x18f8 ), + SHC( 0x471c ), + SHC( 0x6a6d ), + SHC( 0x6a6d ), + SHC( 0x471c ), + SHC( 0x18f8 ), + SHC( 0x7d8a ), + SHC( 0x7f62 ), + SHC( 0x0c8b ), + SHC( 0x5133 ), + SHC( 0x62f2 ), + SHC( 0x70e2 ), + SHC( 0x3c56 ), + SHC( 0x2528 ), + SHC( 0x7a7d ), + SHC( 0x7a7d ), + SHC( 0x2528 ), + SHC( 0x3c56 ), + SHC( 0x70e2 ), + SHC( 0x62f2 ), + SHC( 0x5133 ), + SHC( 0x0c8b ), + SHC( 0x7f62 ), + SHC( 0x7fd8 ), + SHC( 0x0647 ), + SHC( 0x55f5 ), + SHC( 0x5ed7 ), + SHC( 0x73b5 ), + SHC( 0x36ba ), + SHC( 0x2b1f ), + SHC( 0x7884 ), + SHC( 0x7c29 ), + SHC( 0x1f19 ), + SHC( 0x41ce ), + SHC( 0x6dca ), + SHC( 0x66cf ), + SHC( 0x4c3f ), + SHC( 0x12c8 ), + SHC( 0x7e9d ), + SHC( 0x7e9d ), + SHC( 0x12c8 ), + SHC( 0x4c3f ), + SHC( 0x66cf ), + SHC( 0x6dca ), + SHC( 0x41ce ), + SHC( 0x1f19 ), + SHC( 0x7c29 ), + SHC( 0x7884 ), + SHC( 0x2b1f ), + SHC( 0x36ba ), + SHC( 0x73b5 ), + SHC( 0x5ed7 ), + SHC( 0x55f5 ), + SHC( 0x0647 ), + SHC( 0x7fd8 ), + SHC( 0x7ff6 ), + SHC( 0x0324 ), + SHC( 0x5842 ), + SHC( 0x5cb4 ), + SHC( 0x7504 ), + SHC( 0x33de ), + SHC( 0x2e11 ), + SHC( 0x776c ), + SHC( 0x7ce3 ), + SHC( 0x1c0b ), + SHC( 0x447a ), + SHC( 0x6c24 ), + SHC( 0x68a6 ), + SHC( 0x49b4 ), + SHC( 0x15e2 ), + SHC( 0x7e1d ), + SHC( 0x7f09 ), + SHC( 0x0fab ), + SHC( 0x4ebf ), + SHC( 0x64e8 ), + SHC( 0x6f5f ), + SHC( 0x3f17 ), + SHC( 0x2223 ), + SHC( 0x7b5d ), + SHC( 0x798a ), + SHC( 0x2826 ), + SHC( 0x398c ), + SHC( 0x7255 ), + SHC( 0x60ec ), + SHC( 0x539b ), + SHC( 0x096a ), + SHC( 0x7fa7 ), + SHC( 0x7fa7 ), + SHC( 0x096a ), + SHC( 0x539b ), + SHC( 0x60ec ), + SHC( 0x7255 ), + SHC( 0x398c ), + SHC( 0x2826 ), + SHC( 0x798a ), + SHC( 0x7b5d ), + SHC( 0x2223 ), + SHC( 0x3f17 ), + SHC( 0x6f5f ), + SHC( 0x64e8 ), + SHC( 0x4ebf ), + SHC( 0x0fab ), + SHC( 0x7f09 ), + SHC( 0x7e1d ), + SHC( 0x15e2 ), + SHC( 0x49b4 ), + SHC( 0x68a6 ), + SHC( 0x6c24 ), + SHC( 0x447a ), + SHC( 0x1c0b ), + SHC( 0x7ce3 ), + SHC( 0x776c ), + SHC( 0x2e11 ), + SHC( 0x33de ), + SHC( 0x7504 ), + SHC( 0x5cb4 ), + SHC( 0x5842 ), + SHC( 0x0324 ), + SHC( 0x7ff6 ), + }; -const Word16 w_fft512_fx[ 256 ] = { - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x5a82 ), SHC( 0x5a82 ), SHC( 0x7641 ), SHC( 0x30fb ), SHC( 0x30fb ), SHC( 0x7641 ), - SHC( 0x7d8a ), SHC( 0x18f8 ), SHC( 0x471c ), SHC( 0x6a6d ), SHC( 0x6a6d ), SHC( 0x471c ), SHC( 0x18f8 ), SHC( 0x7d8a ), - SHC( 0x7f62 ), SHC( 0x0c8b ), SHC( 0x5133 ), SHC( 0x62f2 ), SHC( 0x70e2 ), SHC( 0x3c56 ), SHC( 0x2528 ), SHC( 0x7a7d ), - SHC( 0x7a7d ), SHC( 0x2528 ), SHC( 0x3c56 ), SHC( 0x70e2 ), SHC( 0x62f2 ), SHC( 0x5133 ), SHC( 0x0c8b ), SHC( 0x7f62 ), - SHC( 0x7fd8 ), SHC( 0x0647 ), SHC( 0x55f5 ), SHC( 0x5ed7 ), SHC( 0x73b5 ), SHC( 0x36ba ), SHC( 0x2b1f ), SHC( 0x7884 ), - SHC( 0x7c29 ), SHC( 0x1f19 ), SHC( 0x41ce ), SHC( 0x6dca ), SHC( 0x66cf ), SHC( 0x4c3f ), SHC( 0x12c8 ), SHC( 0x7e9d ), - SHC( 0x7e9d ), SHC( 0x12c8 ), SHC( 0x4c3f ), SHC( 0x66cf ), SHC( 0x6dca ), SHC( 0x41ce ), SHC( 0x1f19 ), SHC( 0x7c29 ), - SHC( 0x7884 ), SHC( 0x2b1f ), SHC( 0x36ba ), SHC( 0x73b5 ), SHC( 0x5ed7 ), SHC( 0x55f5 ), SHC( 0x0647 ), SHC( 0x7fd8 ), - SHC( 0x7ff6 ), SHC( 0x0324 ), SHC( 0x5842 ), SHC( 0x5cb4 ), SHC( 0x7504 ), SHC( 0x33de ), SHC( 0x2e11 ), SHC( 0x776c ), - SHC( 0x7ce3 ), SHC( 0x1c0b ), SHC( 0x447a ), SHC( 0x6c24 ), SHC( 0x68a6 ), SHC( 0x49b4 ), SHC( 0x15e2 ), SHC( 0x7e1d ), - SHC( 0x7f09 ), SHC( 0x0fab ), SHC( 0x4ebf ), SHC( 0x64e8 ), SHC( 0x6f5f ), SHC( 0x3f17 ), SHC( 0x2223 ), SHC( 0x7b5d ), - SHC( 0x798a ), SHC( 0x2826 ), SHC( 0x398c ), SHC( 0x7255 ), SHC( 0x60ec ), SHC( 0x539b ), SHC( 0x096a ), SHC( 0x7fa7 ), - SHC( 0x7fa7 ), SHC( 0x096a ), SHC( 0x539b ), SHC( 0x60ec ), SHC( 0x7255 ), SHC( 0x398c ), SHC( 0x2826 ), SHC( 0x798a ), - SHC( 0x7b5d ), SHC( 0x2223 ), SHC( 0x3f17 ), SHC( 0x6f5f ), SHC( 0x64e8 ), SHC( 0x4ebf ), SHC( 0x0fab ), SHC( 0x7f09 ), - SHC( 0x7e1d ), SHC( 0x15e2 ), SHC( 0x49b4 ), SHC( 0x68a6 ), SHC( 0x6c24 ), SHC( 0x447a ), SHC( 0x1c0b ), SHC( 0x7ce3 ), - SHC( 0x776c ), SHC( 0x2e11 ), SHC( 0x33de ), SHC( 0x7504 ), SHC( 0x5cb4 ), SHC( 0x5842 ), SHC( 0x0324 ), SHC( 0x7ff6 ), - SHC( 0x7ffd ), SHC( 0x0192 ), SHC( 0x5964 ), SHC( 0x5b9d ), SHC( 0x75a5 ), SHC( 0x326e ), SHC( 0x2f87 ), SHC( 0x76d9 ), - SHC( 0x7d39 ), SHC( 0x1a82 ), SHC( 0x45cd ), SHC( 0x6b4a ), SHC( 0x698c ), SHC( 0x4869 ), SHC( 0x176d ), SHC( 0x7dd6 ), - SHC( 0x7f38 ), SHC( 0x0e1b ), SHC( 0x4ffb ), SHC( 0x63ef ), SHC( 0x7023 ), SHC( 0x3db8 ), SHC( 0x23a6 ), SHC( 0x7aef ), - SHC( 0x7a05 ), SHC( 0x26a8 ), SHC( 0x3af2 ), SHC( 0x719e ), SHC( 0x61f1 ), SHC( 0x5269 ), SHC( 0x0afb ), SHC( 0x7f87 ), - SHC( 0x7fc2 ), SHC( 0x07d9 ), SHC( 0x54ca ), SHC( 0x5fe3 ), SHC( 0x7307 ), SHC( 0x3824 ), SHC( 0x29a3 ), SHC( 0x7909 ), - SHC( 0x7bc5 ), SHC( 0x209f ), SHC( 0x4073 ), SHC( 0x6e96 ), SHC( 0x65dd ), SHC( 0x4d81 ), SHC( 0x1139 ), SHC( 0x7ed5 ), - SHC( 0x7e5f ), SHC( 0x1455 ), SHC( 0x4afb ), SHC( 0x67bd ), SHC( 0x6cf9 ), SHC( 0x4325 ), SHC( 0x1d93 ), SHC( 0x7c89 ), - SHC( 0x77fa ), SHC( 0x2c98 ), SHC( 0x354d ), SHC( 0x745f ), SHC( 0x5dc7 ), SHC( 0x571d ), SHC( 0x04b6 ), SHC( 0x7fe9 ), - SHC( 0x7fe9 ), SHC( 0x04b6 ), SHC( 0x571d ), SHC( 0x5dc7 ), SHC( 0x745f ), SHC( 0x354d ), SHC( 0x2c98 ), SHC( 0x77fa ), - SHC( 0x7c89 ), SHC( 0x1d93 ), SHC( 0x4325 ), SHC( 0x6cf9 ), SHC( 0x67bd ), SHC( 0x4afb ), SHC( 0x1455 ), SHC( 0x7e5f ), - SHC( 0x7ed5 ), SHC( 0x1139 ), SHC( 0x4d81 ), SHC( 0x65dd ), SHC( 0x6e96 ), SHC( 0x4073 ), SHC( 0x209f ), SHC( 0x7bc5 ), - SHC( 0x7909 ), SHC( 0x29a3 ), SHC( 0x3824 ), SHC( 0x7307 ), SHC( 0x5fe3 ), SHC( 0x54ca ), SHC( 0x07d9 ), SHC( 0x7fc2 ), - SHC( 0x7f87 ), SHC( 0x0afb ), SHC( 0x5269 ), SHC( 0x61f1 ), SHC( 0x719e ), SHC( 0x3af2 ), SHC( 0x26a8 ), SHC( 0x7a05 ), - SHC( 0x7aef ), SHC( 0x23a6 ), SHC( 0x3db8 ), SHC( 0x7023 ), SHC( 0x63ef ), SHC( 0x4ffb ), SHC( 0x0e1b ), SHC( 0x7f38 ), - SHC( 0x7dd6 ), SHC( 0x176d ), SHC( 0x4869 ), SHC( 0x698c ), SHC( 0x6b4a ), SHC( 0x45cd ), SHC( 0x1a82 ), SHC( 0x7d39 ), - SHC( 0x76d9 ), SHC( 0x2f87 ), SHC( 0x326e ), SHC( 0x75a5 ), SHC( 0x5b9d ), SHC( 0x5964 ), SHC( 0x0192 ), SHC( 0x7ffd ), - +const Word16 w_fft512_fx[256] = { + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x5a82 ), + SHC( 0x5a82 ), + SHC( 0x7641 ), + SHC( 0x30fb ), + SHC( 0x30fb ), + SHC( 0x7641 ), + SHC( 0x7d8a ), + SHC( 0x18f8 ), + SHC( 0x471c ), + SHC( 0x6a6d ), + SHC( 0x6a6d ), + SHC( 0x471c ), + SHC( 0x18f8 ), + SHC( 0x7d8a ), + SHC( 0x7f62 ), + SHC( 0x0c8b ), + SHC( 0x5133 ), + SHC( 0x62f2 ), + SHC( 0x70e2 ), + SHC( 0x3c56 ), + SHC( 0x2528 ), + SHC( 0x7a7d ), + SHC( 0x7a7d ), + SHC( 0x2528 ), + SHC( 0x3c56 ), + SHC( 0x70e2 ), + SHC( 0x62f2 ), + SHC( 0x5133 ), + SHC( 0x0c8b ), + SHC( 0x7f62 ), + SHC( 0x7fd8 ), + SHC( 0x0647 ), + SHC( 0x55f5 ), + SHC( 0x5ed7 ), + SHC( 0x73b5 ), + SHC( 0x36ba ), + SHC( 0x2b1f ), + SHC( 0x7884 ), + SHC( 0x7c29 ), + SHC( 0x1f19 ), + SHC( 0x41ce ), + SHC( 0x6dca ), + SHC( 0x66cf ), + SHC( 0x4c3f ), + SHC( 0x12c8 ), + SHC( 0x7e9d ), + SHC( 0x7e9d ), + SHC( 0x12c8 ), + SHC( 0x4c3f ), + SHC( 0x66cf ), + SHC( 0x6dca ), + SHC( 0x41ce ), + SHC( 0x1f19 ), + SHC( 0x7c29 ), + SHC( 0x7884 ), + SHC( 0x2b1f ), + SHC( 0x36ba ), + SHC( 0x73b5 ), + SHC( 0x5ed7 ), + SHC( 0x55f5 ), + SHC( 0x0647 ), + SHC( 0x7fd8 ), + SHC( 0x7ff6 ), + SHC( 0x0324 ), + SHC( 0x5842 ), + SHC( 0x5cb4 ), + SHC( 0x7504 ), + SHC( 0x33de ), + SHC( 0x2e11 ), + SHC( 0x776c ), + SHC( 0x7ce3 ), + SHC( 0x1c0b ), + SHC( 0x447a ), + SHC( 0x6c24 ), + SHC( 0x68a6 ), + SHC( 0x49b4 ), + SHC( 0x15e2 ), + SHC( 0x7e1d ), + SHC( 0x7f09 ), + SHC( 0x0fab ), + SHC( 0x4ebf ), + SHC( 0x64e8 ), + SHC( 0x6f5f ), + SHC( 0x3f17 ), + SHC( 0x2223 ), + SHC( 0x7b5d ), + SHC( 0x798a ), + SHC( 0x2826 ), + SHC( 0x398c ), + SHC( 0x7255 ), + SHC( 0x60ec ), + SHC( 0x539b ), + SHC( 0x096a ), + SHC( 0x7fa7 ), + SHC( 0x7fa7 ), + SHC( 0x096a ), + SHC( 0x539b ), + SHC( 0x60ec ), + SHC( 0x7255 ), + SHC( 0x398c ), + SHC( 0x2826 ), + SHC( 0x798a ), + SHC( 0x7b5d ), + SHC( 0x2223 ), + SHC( 0x3f17 ), + SHC( 0x6f5f ), + SHC( 0x64e8 ), + SHC( 0x4ebf ), + SHC( 0x0fab ), + SHC( 0x7f09 ), + SHC( 0x7e1d ), + SHC( 0x15e2 ), + SHC( 0x49b4 ), + SHC( 0x68a6 ), + SHC( 0x6c24 ), + SHC( 0x447a ), + SHC( 0x1c0b ), + SHC( 0x7ce3 ), + SHC( 0x776c ), + SHC( 0x2e11 ), + SHC( 0x33de ), + SHC( 0x7504 ), + SHC( 0x5cb4 ), + SHC( 0x5842 ), + SHC( 0x0324 ), + SHC( 0x7ff6 ), + SHC( 0x7ffd ), + SHC( 0x0192 ), + SHC( 0x5964 ), + SHC( 0x5b9d ), + SHC( 0x75a5 ), + SHC( 0x326e ), + SHC( 0x2f87 ), + SHC( 0x76d9 ), + SHC( 0x7d39 ), + SHC( 0x1a82 ), + SHC( 0x45cd ), + SHC( 0x6b4a ), + SHC( 0x698c ), + SHC( 0x4869 ), + SHC( 0x176d ), + SHC( 0x7dd6 ), + SHC( 0x7f38 ), + SHC( 0x0e1b ), + SHC( 0x4ffb ), + SHC( 0x63ef ), + SHC( 0x7023 ), + SHC( 0x3db8 ), + SHC( 0x23a6 ), + SHC( 0x7aef ), + SHC( 0x7a05 ), + SHC( 0x26a8 ), + SHC( 0x3af2 ), + SHC( 0x719e ), + SHC( 0x61f1 ), + SHC( 0x5269 ), + SHC( 0x0afb ), + SHC( 0x7f87 ), + SHC( 0x7fc2 ), + SHC( 0x07d9 ), + SHC( 0x54ca ), + SHC( 0x5fe3 ), + SHC( 0x7307 ), + SHC( 0x3824 ), + SHC( 0x29a3 ), + SHC( 0x7909 ), + SHC( 0x7bc5 ), + SHC( 0x209f ), + SHC( 0x4073 ), + SHC( 0x6e96 ), + SHC( 0x65dd ), + SHC( 0x4d81 ), + SHC( 0x1139 ), + SHC( 0x7ed5 ), + SHC( 0x7e5f ), + SHC( 0x1455 ), + SHC( 0x4afb ), + SHC( 0x67bd ), + SHC( 0x6cf9 ), + SHC( 0x4325 ), + SHC( 0x1d93 ), + SHC( 0x7c89 ), + SHC( 0x77fa ), + SHC( 0x2c98 ), + SHC( 0x354d ), + SHC( 0x745f ), + SHC( 0x5dc7 ), + SHC( 0x571d ), + SHC( 0x04b6 ), + SHC( 0x7fe9 ), + SHC( 0x7fe9 ), + SHC( 0x04b6 ), + SHC( 0x571d ), + SHC( 0x5dc7 ), + SHC( 0x745f ), + SHC( 0x354d ), + SHC( 0x2c98 ), + SHC( 0x77fa ), + SHC( 0x7c89 ), + SHC( 0x1d93 ), + SHC( 0x4325 ), + SHC( 0x6cf9 ), + SHC( 0x67bd ), + SHC( 0x4afb ), + SHC( 0x1455 ), + SHC( 0x7e5f ), + SHC( 0x7ed5 ), + SHC( 0x1139 ), + SHC( 0x4d81 ), + SHC( 0x65dd ), + SHC( 0x6e96 ), + SHC( 0x4073 ), + SHC( 0x209f ), + SHC( 0x7bc5 ), + SHC( 0x7909 ), + SHC( 0x29a3 ), + SHC( 0x3824 ), + SHC( 0x7307 ), + SHC( 0x5fe3 ), + SHC( 0x54ca ), + SHC( 0x07d9 ), + SHC( 0x7fc2 ), + SHC( 0x7f87 ), + SHC( 0x0afb ), + SHC( 0x5269 ), + SHC( 0x61f1 ), + SHC( 0x719e ), + SHC( 0x3af2 ), + SHC( 0x26a8 ), + SHC( 0x7a05 ), + SHC( 0x7aef ), + SHC( 0x23a6 ), + SHC( 0x3db8 ), + SHC( 0x7023 ), + SHC( 0x63ef ), + SHC( 0x4ffb ), + SHC( 0x0e1b ), + SHC( 0x7f38 ), + SHC( 0x7dd6 ), + SHC( 0x176d ), + SHC( 0x4869 ), + SHC( 0x698c ), + SHC( 0x6b4a ), + SHC( 0x45cd ), + SHC( 0x1a82 ), + SHC( 0x7d39 ), + SHC( 0x76d9 ), + SHC( 0x2f87 ), + SHC( 0x326e ), + SHC( 0x75a5 ), + SHC( 0x5b9d ), + SHC( 0x5964 ), + SHC( 0x0192 ), + SHC( 0x7ffd ), + }; -const Word16 FFT_RotVector_960_fx[ 1860 ] = { - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7ffd ), SHC( 0xfe54 ), SHC( 0x7ff4 ), SHC( 0xfca7 ), SHC( 0x7fe6 ), SHC( 0xfafa ), - SHC( 0x7fd3 ), SHC( 0xf94e ), SHC( 0x7fb9 ), SHC( 0xf7a1 ), SHC( 0x7f9a ), SHC( 0xf5f6 ), SHC( 0x7f76 ), SHC( 0xf44a ), - SHC( 0x7f4c ), SHC( 0xf29f ), SHC( 0x7f1c ), SHC( 0xf0f5 ), SHC( 0x7ee7 ), SHC( 0xef4b ), SHC( 0x7eac ), SHC( 0xeda3 ), - SHC( 0x7e6c ), SHC( 0xebfa ), SHC( 0x7e26 ), SHC( 0xea53 ), SHC( 0x7ddb ), SHC( 0xe8ad ), SHC( 0x7d8a ), SHC( 0xe708 ), - SHC( 0x7d33 ), SHC( 0xe564 ), SHC( 0x7cd8 ), SHC( 0xe3c1 ), SHC( 0x7c76 ), SHC( 0xe21f ), SHC( 0x7c0f ), SHC( 0xe07f ), - SHC( 0x7ba3 ), SHC( 0xdee0 ), SHC( 0x7b31 ), SHC( 0xdd42 ), SHC( 0x7aba ), SHC( 0xdba6 ), SHC( 0x7a3e ), SHC( 0xda0b ), - SHC( 0x79bc ), SHC( 0xd873 ), SHC( 0x7935 ), SHC( 0xd6dc ), SHC( 0x78a8 ), SHC( 0xd546 ), SHC( 0x7816 ), SHC( 0xd3b3 ), - SHC( 0x777f ), SHC( 0xd221 ), SHC( 0x76e3 ), SHC( 0xd092 ), SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7ff4 ), SHC( 0xfca7 ), - SHC( 0x7fd3 ), SHC( 0xf94e ), SHC( 0x7f9a ), SHC( 0xf5f6 ), SHC( 0x7f4c ), SHC( 0xf29f ), SHC( 0x7ee7 ), SHC( 0xef4b ), - SHC( 0x7e6c ), SHC( 0xebfa ), SHC( 0x7ddb ), SHC( 0xe8ad ), SHC( 0x7d33 ), SHC( 0xe564 ), SHC( 0x7c76 ), SHC( 0xe21f ), - SHC( 0x7ba3 ), SHC( 0xdee0 ), SHC( 0x7aba ), SHC( 0xdba6 ), SHC( 0x79bc ), SHC( 0xd873 ), SHC( 0x78a8 ), SHC( 0xd546 ), - SHC( 0x777f ), SHC( 0xd221 ), SHC( 0x7641 ), SHC( 0xcf05 ), SHC( 0x74ef ), SHC( 0xcbf1 ), SHC( 0x7387 ), SHC( 0xc8e6 ), - SHC( 0x720c ), SHC( 0xc5e4 ), SHC( 0x707d ), SHC( 0xc2ed ), SHC( 0x6ed9 ), SHC( 0xc000 ), SHC( 0x6d23 ), SHC( 0xbd1f ), - SHC( 0x6b59 ), SHC( 0xba4a ), SHC( 0x697c ), SHC( 0xb780 ), SHC( 0x678d ), SHC( 0xb4c4 ), SHC( 0x658c ), SHC( 0xb215 ), - SHC( 0x6379 ), SHC( 0xaf73 ), SHC( 0x6154 ), SHC( 0xacdf ), SHC( 0x5f1f ), SHC( 0xaa5a ), SHC( 0x5cd9 ), SHC( 0xa7e4 ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7fe6 ), SHC( 0xfafa ), SHC( 0x7f9a ), SHC( 0xf5f6 ), SHC( 0x7f1c ), SHC( 0xf0f5 ), - SHC( 0x7e6c ), SHC( 0xebfa ), SHC( 0x7d8a ), SHC( 0xe708 ), SHC( 0x7c76 ), SHC( 0xe21f ), SHC( 0x7b31 ), SHC( 0xdd42 ), - SHC( 0x79bc ), SHC( 0xd873 ), SHC( 0x7816 ), SHC( 0xd3b3 ), SHC( 0x7641 ), SHC( 0xcf05 ), SHC( 0x743e ), SHC( 0xca6a ), - SHC( 0x720c ), SHC( 0xc5e4 ), SHC( 0x6fad ), SHC( 0xc175 ), SHC( 0x6d23 ), SHC( 0xbd1f ), SHC( 0x6a6d ), SHC( 0xb8e4 ), - SHC( 0x678d ), SHC( 0xb4c4 ), SHC( 0x6485 ), SHC( 0xb0c2 ), SHC( 0x6154 ), SHC( 0xacdf ), SHC( 0x5dfe ), SHC( 0xa91e ), - SHC( 0x5a82 ), SHC( 0xa57e ), SHC( 0x56e2 ), SHC( 0xa202 ), SHC( 0x5321 ), SHC( 0x9eac ), SHC( 0x4f3e ), SHC( 0x9b7b ), - SHC( 0x4b3c ), SHC( 0x9873 ), SHC( 0x471c ), SHC( 0x9593 ), SHC( 0x42e1 ), SHC( 0x92dd ), SHC( 0x3e8b ), SHC( 0x9053 ), - SHC( 0x3a1c ), SHC( 0x8df4 ), SHC( 0x3596 ), SHC( 0x8bc2 ), SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7fd3 ), SHC( 0xf94e ), - SHC( 0x7f4c ), SHC( 0xf29f ), SHC( 0x7e6c ), SHC( 0xebfa ), SHC( 0x7d33 ), SHC( 0xe564 ), SHC( 0x7ba3 ), SHC( 0xdee0 ), - SHC( 0x79bc ), SHC( 0xd873 ), SHC( 0x777f ), SHC( 0xd221 ), SHC( 0x74ef ), SHC( 0xcbf1 ), SHC( 0x720c ), SHC( 0xc5e4 ), - SHC( 0x6ed9 ), SHC( 0xc000 ), SHC( 0x6b59 ), SHC( 0xba4a ), SHC( 0x678d ), SHC( 0xb4c4 ), SHC( 0x6379 ), SHC( 0xaf73 ), - SHC( 0x5f1f ), SHC( 0xaa5a ), SHC( 0x5a82 ), SHC( 0xa57e ), SHC( 0x55a6 ), SHC( 0xa0e1 ), SHC( 0x508d ), SHC( 0x9c87 ), - SHC( 0x4b3c ), SHC( 0x9873 ), SHC( 0x45b6 ), SHC( 0x94a7 ), SHC( 0x4000 ), SHC( 0x9127 ), SHC( 0x3a1c ), SHC( 0x8df4 ), - SHC( 0x340f ), SHC( 0x8b11 ), SHC( 0x2ddf ), SHC( 0x8881 ), SHC( 0x278d ), SHC( 0x8644 ), SHC( 0x2120 ), SHC( 0x845d ), - SHC( 0x1a9c ), SHC( 0x82cd ), SHC( 0x1406 ), SHC( 0x8194 ), SHC( 0x0d61 ), SHC( 0x80b4 ), SHC( 0x06b2 ), SHC( 0x802d ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7fb9 ), SHC( 0xf7a1 ), SHC( 0x7ee7 ), SHC( 0xef4b ), SHC( 0x7d8a ), SHC( 0xe708 ), - SHC( 0x7ba3 ), SHC( 0xdee0 ), SHC( 0x7935 ), SHC( 0xd6dc ), SHC( 0x7641 ), SHC( 0xcf05 ), SHC( 0x72cc ), SHC( 0xc764 ), - SHC( 0x6ed9 ), SHC( 0xc000 ), SHC( 0x6a6d ), SHC( 0xb8e4 ), SHC( 0x658c ), SHC( 0xb215 ), SHC( 0x603c ), SHC( 0xab9b ), - SHC( 0x5a82 ), SHC( 0xa57e ), SHC( 0x5465 ), SHC( 0x9fc4 ), SHC( 0x4deb ), SHC( 0x9a74 ), SHC( 0x471c ), SHC( 0x9593 ), - SHC( 0x4000 ), SHC( 0x9127 ), SHC( 0x389c ), SHC( 0x8d34 ), SHC( 0x30fb ), SHC( 0x89bf ), SHC( 0x2924 ), SHC( 0x86cb ), - SHC( 0x2120 ), SHC( 0x845d ), SHC( 0x18f8 ), SHC( 0x8276 ), SHC( 0x10b5 ), SHC( 0x8119 ), SHC( 0x085f ), SHC( 0x8047 ), - SHC( 0x0000 ), SHC( 0x8000 ), SHC( 0xf7a1 ), SHC( 0x8047 ), SHC( 0xef4b ), SHC( 0x8119 ), SHC( 0xe708 ), SHC( 0x8276 ), - SHC( 0xdee0 ), SHC( 0x845d ), SHC( 0xd6dc ), SHC( 0x86cb ), SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7f9a ), SHC( 0xf5f6 ), - SHC( 0x7e6c ), SHC( 0xebfa ), SHC( 0x7c76 ), SHC( 0xe21f ), SHC( 0x79bc ), SHC( 0xd873 ), SHC( 0x7641 ), SHC( 0xcf05 ), - SHC( 0x720c ), SHC( 0xc5e4 ), SHC( 0x6d23 ), SHC( 0xbd1f ), SHC( 0x678d ), SHC( 0xb4c4 ), SHC( 0x6154 ), SHC( 0xacdf ), - SHC( 0x5a82 ), SHC( 0xa57e ), SHC( 0x5321 ), SHC( 0x9eac ), SHC( 0x4b3c ), SHC( 0x9873 ), SHC( 0x42e1 ), SHC( 0x92dd ), - SHC( 0x3a1c ), SHC( 0x8df4 ), SHC( 0x30fb ), SHC( 0x89bf ), SHC( 0x278d ), SHC( 0x8644 ), SHC( 0x1de1 ), SHC( 0x838a ), - SHC( 0x1406 ), SHC( 0x8194 ), SHC( 0x0a0a ), SHC( 0x8066 ), SHC( 0x0000 ), SHC( 0x8000 ), SHC( 0xf5f6 ), SHC( 0x8066 ), - SHC( 0xebfa ), SHC( 0x8194 ), SHC( 0xe21f ), SHC( 0x838a ), SHC( 0xd873 ), SHC( 0x8644 ), SHC( 0xcf05 ), SHC( 0x89bf ), - SHC( 0xc5e4 ), SHC( 0x8df4 ), SHC( 0xbd1f ), SHC( 0x92dd ), SHC( 0xb4c4 ), SHC( 0x9873 ), SHC( 0xacdf ), SHC( 0x9eac ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7f76 ), SHC( 0xf44a ), SHC( 0x7ddb ), SHC( 0xe8ad ), SHC( 0x7b31 ), SHC( 0xdd42 ), - SHC( 0x777f ), SHC( 0xd221 ), SHC( 0x72cc ), SHC( 0xc764 ), SHC( 0x6d23 ), SHC( 0xbd1f ), SHC( 0x668f ), SHC( 0xb36b ), - SHC( 0x5f1f ), SHC( 0xaa5a ), SHC( 0x56e2 ), SHC( 0xa202 ), SHC( 0x4deb ), SHC( 0x9a74 ), SHC( 0x444d ), SHC( 0x93c0 ), - SHC( 0x3a1c ), SHC( 0x8df4 ), SHC( 0x2f6e ), SHC( 0x891d ), SHC( 0x245a ), SHC( 0x8546 ), SHC( 0x18f8 ), SHC( 0x8276 ), - SHC( 0x0d61 ), SHC( 0x80b4 ), SHC( 0x01ac ), SHC( 0x8003 ), SHC( 0xf5f6 ), SHC( 0x8066 ), SHC( 0xea53 ), SHC( 0x81da ), - SHC( 0xdee0 ), SHC( 0x845d ), SHC( 0xd3b3 ), SHC( 0x87ea ), SHC( 0xc8e6 ), SHC( 0x8c79 ), SHC( 0xbe8e ), SHC( 0x91ff ), - SHC( 0xb4c4 ), SHC( 0x9873 ), SHC( 0xab9b ), SHC( 0x9fc4 ), SHC( 0xa327 ), SHC( 0xa7e4 ), SHC( 0x9b7b ), SHC( 0xb0c2 ), - SHC( 0x94a7 ), SHC( 0xba4a ), SHC( 0x8eb9 ), SHC( 0xc467 ), SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7f4c ), SHC( 0xf29f ), - SHC( 0x7d33 ), SHC( 0xe564 ), SHC( 0x79bc ), SHC( 0xd873 ), SHC( 0x74ef ), SHC( 0xcbf1 ), SHC( 0x6ed9 ), SHC( 0xc000 ), - SHC( 0x678d ), SHC( 0xb4c4 ), SHC( 0x5f1f ), SHC( 0xaa5a ), SHC( 0x55a6 ), SHC( 0xa0e1 ), SHC( 0x4b3c ), SHC( 0x9873 ), - SHC( 0x4000 ), SHC( 0x9127 ), SHC( 0x340f ), SHC( 0x8b11 ), SHC( 0x278d ), SHC( 0x8644 ), SHC( 0x1a9c ), SHC( 0x82cd ), - SHC( 0x0d61 ), SHC( 0x80b4 ), SHC( 0x0000 ), SHC( 0x8000 ), SHC( 0xf29f ), SHC( 0x80b4 ), SHC( 0xe564 ), SHC( 0x82cd ), - SHC( 0xd873 ), SHC( 0x8644 ), SHC( 0xcbf1 ), SHC( 0x8b11 ), SHC( 0xc000 ), SHC( 0x9127 ), SHC( 0xb4c4 ), SHC( 0x9873 ), - SHC( 0xaa5a ), SHC( 0xa0e1 ), SHC( 0xa0e1 ), SHC( 0xaa5a ), SHC( 0x9873 ), SHC( 0xb4c4 ), SHC( 0x9127 ), SHC( 0xc000 ), - SHC( 0x8b11 ), SHC( 0xcbf1 ), SHC( 0x8644 ), SHC( 0xd873 ), SHC( 0x82cd ), SHC( 0xe564 ), SHC( 0x80b4 ), SHC( 0xf29f ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7f1c ), SHC( 0xf0f5 ), SHC( 0x7c76 ), SHC( 0xe21f ), SHC( 0x7816 ), SHC( 0xd3b3 ), - SHC( 0x720c ), SHC( 0xc5e4 ), SHC( 0x6a6d ), SHC( 0xb8e4 ), SHC( 0x6154 ), SHC( 0xacdf ), SHC( 0x56e2 ), SHC( 0xa202 ), - SHC( 0x4b3c ), SHC( 0x9873 ), SHC( 0x3e8b ), SHC( 0x9053 ), SHC( 0x30fb ), SHC( 0x89bf ), SHC( 0x22be ), SHC( 0x84cf ), - SHC( 0x1406 ), SHC( 0x8194 ), SHC( 0x0506 ), SHC( 0x801a ), SHC( 0xf5f6 ), SHC( 0x8066 ), SHC( 0xe708 ), SHC( 0x8276 ), - SHC( 0xd873 ), SHC( 0x8644 ), SHC( 0xca6a ), SHC( 0x8bc2 ), SHC( 0xbd1f ), SHC( 0x92dd ), SHC( 0xb0c2 ), SHC( 0x9b7b ), - SHC( 0xa57e ), SHC( 0xa57e ), SHC( 0x9b7b ), SHC( 0xb0c2 ), SHC( 0x92dd ), SHC( 0xbd1f ), SHC( 0x8bc2 ), SHC( 0xca6a ), - SHC( 0x8644 ), SHC( 0xd873 ), SHC( 0x8276 ), SHC( 0xe708 ), SHC( 0x8066 ), SHC( 0xf5f6 ), SHC( 0x801a ), SHC( 0x0506 ), - SHC( 0x8194 ), SHC( 0x1406 ), SHC( 0x84cf ), SHC( 0x22be ), SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7ee7 ), SHC( 0xef4b ), - SHC( 0x7ba3 ), SHC( 0xdee0 ), SHC( 0x7641 ), SHC( 0xcf05 ), SHC( 0x6ed9 ), SHC( 0xc000 ), SHC( 0x658c ), SHC( 0xb215 ), - SHC( 0x5a82 ), SHC( 0xa57e ), SHC( 0x4deb ), SHC( 0x9a74 ), SHC( 0x4000 ), SHC( 0x9127 ), SHC( 0x30fb ), SHC( 0x89bf ), - SHC( 0x2120 ), SHC( 0x845d ), SHC( 0x10b5 ), SHC( 0x8119 ), SHC( 0x0000 ), SHC( 0x8000 ), SHC( 0xef4b ), SHC( 0x8119 ), - SHC( 0xdee0 ), SHC( 0x845d ), SHC( 0xcf05 ), SHC( 0x89bf ), SHC( 0xc000 ), SHC( 0x9127 ), SHC( 0xb215 ), SHC( 0x9a74 ), - SHC( 0xa57e ), SHC( 0xa57e ), SHC( 0x9a74 ), SHC( 0xb215 ), SHC( 0x9127 ), SHC( 0xc000 ), SHC( 0x89bf ), SHC( 0xcf05 ), - SHC( 0x845d ), SHC( 0xdee0 ), SHC( 0x8119 ), SHC( 0xef4b ), SHC( 0x8000 ), SHC( 0x0000 ), SHC( 0x8119 ), SHC( 0x10b5 ), - SHC( 0x845d ), SHC( 0x2120 ), SHC( 0x89bf ), SHC( 0x30fb ), SHC( 0x9127 ), SHC( 0x4000 ), SHC( 0x9a74 ), SHC( 0x4deb ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7eac ), SHC( 0xeda3 ), SHC( 0x7aba ), SHC( 0xdba6 ), SHC( 0x743e ), SHC( 0xca6a ), - SHC( 0x6b59 ), SHC( 0xba4a ), SHC( 0x603c ), SHC( 0xab9b ), SHC( 0x5321 ), SHC( 0x9eac ), SHC( 0x444d ), SHC( 0x93c0 ), - SHC( 0x340f ), SHC( 0x8b11 ), SHC( 0x22be ), SHC( 0x84cf ), SHC( 0x10b5 ), SHC( 0x8119 ), SHC( 0xfe54 ), SHC( 0x8003 ), - SHC( 0xebfa ), SHC( 0x8194 ), SHC( 0xda0b ), SHC( 0x85c2 ), SHC( 0xc8e6 ), SHC( 0x8c79 ), SHC( 0xb8e4 ), SHC( 0x9593 ), - SHC( 0xaa5a ), SHC( 0xa0e1 ), SHC( 0x9d97 ), SHC( 0xae27 ), SHC( 0x92dd ), SHC( 0xbd1f ), SHC( 0x8a66 ), SHC( 0xcd7a ), - SHC( 0x845d ), SHC( 0xdee0 ), SHC( 0x80e4 ), SHC( 0xf0f5 ), SHC( 0x800c ), SHC( 0x0359 ), SHC( 0x81da ), SHC( 0x15ad ), - SHC( 0x8644 ), SHC( 0x278d ), SHC( 0x8d34 ), SHC( 0x389c ), SHC( 0x9684 ), SHC( 0x4880 ), SHC( 0xa202 ), SHC( 0x56e2 ), - SHC( 0xaf73 ), SHC( 0x6379 ), SHC( 0xbe8e ), SHC( 0x6e01 ), SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7e6c ), SHC( 0xebfa ), - SHC( 0x79bc ), SHC( 0xd873 ), SHC( 0x720c ), SHC( 0xc5e4 ), SHC( 0x678d ), SHC( 0xb4c4 ), SHC( 0x5a82 ), SHC( 0xa57e ), - SHC( 0x4b3c ), SHC( 0x9873 ), SHC( 0x3a1c ), SHC( 0x8df4 ), SHC( 0x278d ), SHC( 0x8644 ), SHC( 0x1406 ), SHC( 0x8194 ), - SHC( 0x0000 ), SHC( 0x8000 ), SHC( 0xebfa ), SHC( 0x8194 ), SHC( 0xd873 ), SHC( 0x8644 ), SHC( 0xc5e4 ), SHC( 0x8df4 ), - SHC( 0xb4c4 ), SHC( 0x9873 ), SHC( 0xa57e ), SHC( 0xa57e ), SHC( 0x9873 ), SHC( 0xb4c4 ), SHC( 0x8df4 ), SHC( 0xc5e4 ), - SHC( 0x8644 ), SHC( 0xd873 ), SHC( 0x8194 ), SHC( 0xebfa ), SHC( 0x8000 ), SHC( 0x0000 ), SHC( 0x8194 ), SHC( 0x1406 ), - SHC( 0x8644 ), SHC( 0x278d ), SHC( 0x8df4 ), SHC( 0x3a1c ), SHC( 0x9873 ), SHC( 0x4b3c ), SHC( 0xa57e ), SHC( 0x5a82 ), - SHC( 0xb4c4 ), SHC( 0x678d ), SHC( 0xc5e4 ), SHC( 0x720c ), SHC( 0xd873 ), SHC( 0x79bc ), SHC( 0xebfa ), SHC( 0x7e6c ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7e26 ), SHC( 0xea53 ), SHC( 0x78a8 ), SHC( 0xd546 ), SHC( 0x6fad ), SHC( 0xc175 ), - SHC( 0x6379 ), SHC( 0xaf73 ), SHC( 0x5465 ), SHC( 0x9fc4 ), SHC( 0x42e1 ), SHC( 0x92dd ), SHC( 0x2f6e ), SHC( 0x891d ), - SHC( 0x1a9c ), SHC( 0x82cd ), SHC( 0x0506 ), SHC( 0x801a ), SHC( 0xef4b ), SHC( 0x8119 ), SHC( 0xda0b ), SHC( 0x85c2 ), - SHC( 0xc5e4 ), SHC( 0x8df4 ), SHC( 0xb36b ), SHC( 0x9971 ), SHC( 0xa327 ), SHC( 0xa7e4 ), SHC( 0x9593 ), SHC( 0xb8e4 ), - SHC( 0x8b11 ), SHC( 0xcbf1 ), SHC( 0x83f1 ), SHC( 0xe07f ), SHC( 0x8066 ), SHC( 0xf5f6 ), SHC( 0x808a ), SHC( 0x0bb6 ), - SHC( 0x845d ), SHC( 0x2120 ), SHC( 0x8bc2 ), SHC( 0x3596 ), SHC( 0x9684 ), SHC( 0x4880 ), SHC( 0xa451 ), SHC( 0x5951 ), - SHC( 0xb4c4 ), SHC( 0x678d ), SHC( 0xc764 ), SHC( 0x72cc ), SHC( 0xdba6 ), SHC( 0x7aba ), SHC( 0xf0f5 ), SHC( 0x7f1c ), - SHC( 0x06b2 ), SHC( 0x7fd3 ), SHC( 0x1c3f ), SHC( 0x7cd8 ), SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7ddb ), SHC( 0xe8ad ), - SHC( 0x777f ), SHC( 0xd221 ), SHC( 0x6d23 ), SHC( 0xbd1f ), SHC( 0x5f1f ), SHC( 0xaa5a ), SHC( 0x4deb ), SHC( 0x9a74 ), - SHC( 0x3a1c ), SHC( 0x8df4 ), SHC( 0x245a ), SHC( 0x8546 ), SHC( 0x0d61 ), SHC( 0x80b4 ), SHC( 0xf5f6 ), SHC( 0x8066 ), - SHC( 0xdee0 ), SHC( 0x845d ), SHC( 0xc8e6 ), SHC( 0x8c79 ), SHC( 0xb4c4 ), SHC( 0x9873 ), SHC( 0xa327 ), SHC( 0xa7e4 ), - SHC( 0x94a7 ), SHC( 0xba4a ), SHC( 0x89bf ), SHC( 0xcf05 ), SHC( 0x82cd ), SHC( 0xe564 ), SHC( 0x800c ), SHC( 0xfca7 ), - SHC( 0x8194 ), SHC( 0x1406 ), SHC( 0x8758 ), SHC( 0x2aba ), SHC( 0x9127 ), SHC( 0x4000 ), SHC( 0x9eac ), SHC( 0x5321 ), - SHC( 0xaf73 ), SHC( 0x6379 ), SHC( 0xc2ed ), SHC( 0x707d ), SHC( 0xd873 ), SHC( 0x79bc ), SHC( 0xef4b ), SHC( 0x7ee7 ), - SHC( 0x06b2 ), SHC( 0x7fd3 ), SHC( 0x1de1 ), SHC( 0x7c76 ), SHC( 0x340f ), SHC( 0x74ef ), SHC( 0x4880 ), SHC( 0x697c ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7d8a ), SHC( 0xe708 ), SHC( 0x7641 ), SHC( 0xcf05 ), SHC( 0x6a6d ), SHC( 0xb8e4 ), - SHC( 0x5a82 ), SHC( 0xa57e ), SHC( 0x471c ), SHC( 0x9593 ), SHC( 0x30fb ), SHC( 0x89bf ), SHC( 0x18f8 ), SHC( 0x8276 ), - SHC( 0x0000 ), SHC( 0x8000 ), SHC( 0xe708 ), SHC( 0x8276 ), SHC( 0xcf05 ), SHC( 0x89bf ), SHC( 0xb8e4 ), SHC( 0x9593 ), - SHC( 0xa57e ), SHC( 0xa57e ), SHC( 0x9593 ), SHC( 0xb8e4 ), SHC( 0x89bf ), SHC( 0xcf05 ), SHC( 0x8276 ), SHC( 0xe708 ), - SHC( 0x8000 ), SHC( 0x0000 ), SHC( 0x8276 ), SHC( 0x18f8 ), SHC( 0x89bf ), SHC( 0x30fb ), SHC( 0x9593 ), SHC( 0x471c ), - SHC( 0xa57e ), SHC( 0x5a82 ), SHC( 0xb8e4 ), SHC( 0x6a6d ), SHC( 0xcf05 ), SHC( 0x7641 ), SHC( 0xe708 ), SHC( 0x7d8a ), - SHC( 0x0000 ), SHC( 0x7fff ), SHC( 0x18f8 ), SHC( 0x7d8a ), SHC( 0x30fb ), SHC( 0x7641 ), SHC( 0x471c ), SHC( 0x6a6d ), - SHC( 0x5a82 ), SHC( 0x5a82 ), SHC( 0x6a6d ), SHC( 0x471c ), SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7fff ), SHC( 0xff2a ), - SHC( 0x7ffd ), SHC( 0xfe54 ), SHC( 0x7ff9 ), SHC( 0xfd7d ), SHC( 0x7ff4 ), SHC( 0xfca7 ), SHC( 0x7fee ), SHC( 0xfbd0 ), - SHC( 0x7fe6 ), SHC( 0xfafa ), SHC( 0x7fdd ), SHC( 0xfa24 ), SHC( 0x7fd3 ), SHC( 0xf94e ), SHC( 0x7fc7 ), SHC( 0xf877 ), - SHC( 0x7fb9 ), SHC( 0xf7a1 ), SHC( 0x7fab ), SHC( 0xf6cb ), SHC( 0x7f9a ), SHC( 0xf5f6 ), SHC( 0x7f89 ), SHC( 0xf520 ), - SHC( 0x7f76 ), SHC( 0xf44a ), SHC( 0x7f62 ), SHC( 0xf375 ), SHC( 0x7f4c ), SHC( 0xf29f ), SHC( 0x7f35 ), SHC( 0xf1ca ), - SHC( 0x7f1c ), SHC( 0xf0f5 ), SHC( 0x7f02 ), SHC( 0xf020 ), SHC( 0x7ee7 ), SHC( 0xef4b ), SHC( 0x7eca ), SHC( 0xee77 ), - SHC( 0x7eac ), SHC( 0xeda3 ), SHC( 0x7e8d ), SHC( 0xecce ), SHC( 0x7e6c ), SHC( 0xebfa ), SHC( 0x7e4a ), SHC( 0xeb27 ), - SHC( 0x7e26 ), SHC( 0xea53 ), SHC( 0x7e01 ), SHC( 0xe980 ), SHC( 0x7ddb ), SHC( 0xe8ad ), SHC( 0x7db3 ), SHC( 0xe7da ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7ff9 ), SHC( 0xfd7d ), SHC( 0x7fe6 ), SHC( 0xfafa ), SHC( 0x7fc7 ), SHC( 0xf877 ), - SHC( 0x7f9a ), SHC( 0xf5f6 ), SHC( 0x7f62 ), SHC( 0xf375 ), SHC( 0x7f1c ), SHC( 0xf0f5 ), SHC( 0x7eca ), SHC( 0xee77 ), - SHC( 0x7e6c ), SHC( 0xebfa ), SHC( 0x7e01 ), SHC( 0xe980 ), SHC( 0x7d8a ), SHC( 0xe708 ), SHC( 0x7d06 ), SHC( 0xe492 ), - SHC( 0x7c76 ), SHC( 0xe21f ), SHC( 0x7bda ), SHC( 0xdfaf ), SHC( 0x7b31 ), SHC( 0xdd42 ), SHC( 0x7a7d ), SHC( 0xdad8 ), - SHC( 0x79bc ), SHC( 0xd873 ), SHC( 0x78ef ), SHC( 0xd611 ), SHC( 0x7816 ), SHC( 0xd3b3 ), SHC( 0x7732 ), SHC( 0xd15a ), - SHC( 0x7641 ), SHC( 0xcf05 ), SHC( 0x7545 ), SHC( 0xccb5 ), SHC( 0x743e ), SHC( 0xca6a ), SHC( 0x732a ), SHC( 0xc824 ), - SHC( 0x720c ), SHC( 0xc5e4 ), SHC( 0x70e2 ), SHC( 0xc3aa ), SHC( 0x6fad ), SHC( 0xc175 ), SHC( 0x6e6e ), SHC( 0xbf47 ), - SHC( 0x6d23 ), SHC( 0xbd1f ), SHC( 0x6bcd ), SHC( 0xbafe ), SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7fee ), SHC( 0xfbd0 ), - SHC( 0x7fb9 ), SHC( 0xf7a1 ), SHC( 0x7f62 ), SHC( 0xf375 ), SHC( 0x7ee7 ), SHC( 0xef4b ), SHC( 0x7e4a ), SHC( 0xeb27 ), - SHC( 0x7d8a ), SHC( 0xe708 ), SHC( 0x7ca8 ), SHC( 0xe2f0 ), SHC( 0x7ba3 ), SHC( 0xdee0 ), SHC( 0x7a7d ), SHC( 0xdad8 ), - SHC( 0x7935 ), SHC( 0xd6dc ), SHC( 0x77cb ), SHC( 0xd2ea ), SHC( 0x7641 ), SHC( 0xcf05 ), SHC( 0x7497 ), SHC( 0xcb2d ), - SHC( 0x72cc ), SHC( 0xc764 ), SHC( 0x70e2 ), SHC( 0xc3aa ), SHC( 0x6ed9 ), SHC( 0xc000 ), SHC( 0x6cb2 ), SHC( 0xbc69 ), - SHC( 0x6a6d ), SHC( 0xb8e4 ), SHC( 0x680b ), SHC( 0xb572 ), SHC( 0x658c ), SHC( 0xb215 ), SHC( 0x62f2 ), SHC( 0xaecd ), - SHC( 0x603c ), SHC( 0xab9b ), SHC( 0x5d6c ), SHC( 0xa881 ), SHC( 0x5a82 ), SHC( 0xa57e ), SHC( 0x577f ), SHC( 0xa294 ), - SHC( 0x5465 ), SHC( 0x9fc4 ), SHC( 0x5133 ), SHC( 0x9d0e ), SHC( 0x4deb ), SHC( 0x9a74 ), SHC( 0x4a8e ), SHC( 0x97f5 ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7fdd ), SHC( 0xfa24 ), SHC( 0x7f76 ), SHC( 0xf44a ), SHC( 0x7eca ), SHC( 0xee77 ), - SHC( 0x7ddb ), SHC( 0xe8ad ), SHC( 0x7ca8 ), SHC( 0xe2f0 ), SHC( 0x7b31 ), SHC( 0xdd42 ), SHC( 0x7979 ), SHC( 0xd7a7 ), - SHC( 0x777f ), SHC( 0xd221 ), SHC( 0x7545 ), SHC( 0xccb5 ), SHC( 0x72cc ), SHC( 0xc764 ), SHC( 0x7016 ), SHC( 0xc231 ), - SHC( 0x6d23 ), SHC( 0xbd1f ), SHC( 0x69f5 ), SHC( 0xb832 ), SHC( 0x668f ), SHC( 0xb36b ), SHC( 0x62f2 ), SHC( 0xaecd ), - SHC( 0x5f1f ), SHC( 0xaa5a ), SHC( 0x5b19 ), SHC( 0xa616 ), SHC( 0x56e2 ), SHC( 0xa202 ), SHC( 0x527d ), SHC( 0x9e21 ), - SHC( 0x4deb ), SHC( 0x9a74 ), SHC( 0x4930 ), SHC( 0x96fe ), SHC( 0x444d ), SHC( 0x93c0 ), SHC( 0x3f45 ), SHC( 0x90bc ), - SHC( 0x3a1c ), SHC( 0x8df4 ), SHC( 0x34d3 ), SHC( 0x8b69 ), SHC( 0x2f6e ), SHC( 0x891d ), SHC( 0x29ef ), SHC( 0x8711 ), - SHC( 0x245a ), SHC( 0x8546 ), SHC( 0x1eb1 ), SHC( 0x83bd ), SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7fc7 ), SHC( 0xf877 ), - SHC( 0x7f1c ), SHC( 0xf0f5 ), SHC( 0x7e01 ), SHC( 0xe980 ), SHC( 0x7c76 ), SHC( 0xe21f ), SHC( 0x7a7d ), SHC( 0xdad8 ), - SHC( 0x7816 ), SHC( 0xd3b3 ), SHC( 0x7545 ), SHC( 0xccb5 ), SHC( 0x720c ), SHC( 0xc5e4 ), SHC( 0x6e6e ), SHC( 0xbf47 ), - SHC( 0x6a6d ), SHC( 0xb8e4 ), SHC( 0x660e ), SHC( 0xb2bf ), SHC( 0x6154 ), SHC( 0xacdf ), SHC( 0x5c44 ), SHC( 0xa749 ), - SHC( 0x56e2 ), SHC( 0xa202 ), SHC( 0x5133 ), SHC( 0x9d0e ), SHC( 0x4b3c ), SHC( 0x9873 ), SHC( 0x4502 ), SHC( 0x9433 ), - SHC( 0x3e8b ), SHC( 0x9053 ), SHC( 0x37dc ), SHC( 0x8cd6 ), SHC( 0x30fb ), SHC( 0x89bf ), SHC( 0x29ef ), SHC( 0x8711 ), - SHC( 0x22be ), SHC( 0x84cf ), SHC( 0x1b6e ), SHC( 0x82fa ), SHC( 0x1406 ), SHC( 0x8194 ), SHC( 0x0c8b ), SHC( 0x809e ), - SHC( 0x0506 ), SHC( 0x801a ), SHC( 0xfd7d ), SHC( 0x8007 ), SHC( 0xf5f6 ), SHC( 0x8066 ), SHC( 0xee77 ), SHC( 0x8136 ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7fab ), SHC( 0xf6cb ), SHC( 0x7eac ), SHC( 0xeda3 ), SHC( 0x7d06 ), SHC( 0xe492 ), - SHC( 0x7aba ), SHC( 0xdba6 ), SHC( 0x77cb ), SHC( 0xd2ea ), SHC( 0x743e ), SHC( 0xca6a ), SHC( 0x7016 ), SHC( 0xc231 ), - SHC( 0x6b59 ), SHC( 0xba4a ), SHC( 0x660e ), SHC( 0xb2bf ), SHC( 0x603c ), SHC( 0xab9b ), SHC( 0x59ea ), SHC( 0xa4e7 ), - SHC( 0x5321 ), SHC( 0x9eac ), SHC( 0x4be9 ), SHC( 0x98f1 ), SHC( 0x444d ), SHC( 0x93c0 ), SHC( 0x3c56 ), SHC( 0x8f1e ), - SHC( 0x340f ), SHC( 0x8b11 ), SHC( 0x2b84 ), SHC( 0x87a0 ), SHC( 0x22be ), SHC( 0x84cf ), SHC( 0x19ca ), SHC( 0x82a1 ), - SHC( 0x10b5 ), SHC( 0x8119 ), SHC( 0x0789 ), SHC( 0x8039 ), SHC( 0xfe54 ), SHC( 0x8003 ), SHC( 0xf520 ), SHC( 0x8077 ), - SHC( 0xebfa ), SHC( 0x8194 ), SHC( 0xe2f0 ), SHC( 0x8358 ), SHC( 0xda0b ), SHC( 0x85c2 ), SHC( 0xd15a ), SHC( 0x88ce ), - SHC( 0xc8e6 ), SHC( 0x8c79 ), SHC( 0xc0bb ), SHC( 0x90bc ), SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7f89 ), SHC( 0xf520 ), - SHC( 0x7e26 ), SHC( 0xea53 ), SHC( 0x7bda ), SHC( 0xdfaf ), SHC( 0x78a8 ), SHC( 0xd546 ), SHC( 0x7497 ), SHC( 0xcb2d ), - SHC( 0x6fad ), SHC( 0xc175 ), SHC( 0x69f5 ), SHC( 0xb832 ), SHC( 0x6379 ), SHC( 0xaf73 ), SHC( 0x5c44 ), SHC( 0xa749 ), - SHC( 0x5465 ), SHC( 0x9fc4 ), SHC( 0x4be9 ), SHC( 0x98f1 ), SHC( 0x42e1 ), SHC( 0x92dd ), SHC( 0x395c ), SHC( 0x8d93 ), - SHC( 0x2f6e ), SHC( 0x891d ), SHC( 0x2528 ), SHC( 0x8583 ), SHC( 0x1a9c ), SHC( 0x82cd ), SHC( 0x0fe0 ), SHC( 0x80fe ), - SHC( 0x0506 ), SHC( 0x801a ), SHC( 0xfa24 ), SHC( 0x8023 ), SHC( 0xef4b ), SHC( 0x8119 ), SHC( 0xe492 ), SHC( 0x82fa ), - SHC( 0xda0b ), SHC( 0x85c2 ), SHC( 0xcfcb ), SHC( 0x896d ), SHC( 0xc5e4 ), SHC( 0x8df4 ), SHC( 0xbc69 ), SHC( 0x934e ), - SHC( 0xb36b ), SHC( 0x9971 ), SHC( 0xaafa ), SHC( 0xa052 ), SHC( 0xa327 ), SHC( 0xa7e4 ), SHC( 0x9c01 ), SHC( 0xb01a ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7f62 ), SHC( 0xf375 ), SHC( 0x7d8a ), SHC( 0xe708 ), SHC( 0x7a7d ), SHC( 0xdad8 ), - SHC( 0x7641 ), SHC( 0xcf05 ), SHC( 0x70e2 ), SHC( 0xc3aa ), SHC( 0x6a6d ), SHC( 0xb8e4 ), SHC( 0x62f2 ), SHC( 0xaecd ), - SHC( 0x5a82 ), SHC( 0xa57e ), SHC( 0x5133 ), SHC( 0x9d0e ), SHC( 0x471c ), SHC( 0x9593 ), SHC( 0x3c56 ), SHC( 0x8f1e ), - SHC( 0x30fb ), SHC( 0x89bf ), SHC( 0x2528 ), SHC( 0x8583 ), SHC( 0x18f8 ), SHC( 0x8276 ), SHC( 0x0c8b ), SHC( 0x809e ), - SHC( 0x0000 ), SHC( 0x8000 ), SHC( 0xf375 ), SHC( 0x809e ), SHC( 0xe708 ), SHC( 0x8276 ), SHC( 0xdad8 ), SHC( 0x8583 ), - SHC( 0xcf05 ), SHC( 0x89bf ), SHC( 0xc3aa ), SHC( 0x8f1e ), SHC( 0xb8e4 ), SHC( 0x9593 ), SHC( 0xaecd ), SHC( 0x9d0e ), - SHC( 0xa57e ), SHC( 0xa57e ), SHC( 0x9d0e ), SHC( 0xaecd ), SHC( 0x9593 ), SHC( 0xb8e4 ), SHC( 0x8f1e ), SHC( 0xc3aa ), - SHC( 0x89bf ), SHC( 0xcf05 ), SHC( 0x8583 ), SHC( 0xdad8 ), SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7f35 ), SHC( 0xf1ca ), - SHC( 0x7cd8 ), SHC( 0xe3c1 ), SHC( 0x78ef ), SHC( 0xd611 ), SHC( 0x7387 ), SHC( 0xc8e6 ), SHC( 0x6cb2 ), SHC( 0xbc69 ), - SHC( 0x6485 ), SHC( 0xb0c2 ), SHC( 0x5b19 ), SHC( 0xa616 ), SHC( 0x508d ), SHC( 0x9c87 ), SHC( 0x4502 ), SHC( 0x9433 ), - SHC( 0x389c ), SHC( 0x8d34 ), SHC( 0x2b84 ), SHC( 0x87a0 ), SHC( 0x1de1 ), SHC( 0x838a ), SHC( 0x0fe0 ), SHC( 0x80fe ), - SHC( 0x01ac ), SHC( 0x8003 ), SHC( 0xf375 ), SHC( 0x809e ), SHC( 0xe564 ), SHC( 0x82cd ), SHC( 0xd7a7 ), SHC( 0x8687 ), - SHC( 0xca6a ), SHC( 0x8bc2 ), SHC( 0xbdd6 ), SHC( 0x926e ), SHC( 0xb215 ), SHC( 0x9a74 ), SHC( 0xa749 ), SHC( 0xa3bc ), - SHC( 0x9d97 ), SHC( 0xae27 ), SHC( 0x951c ), SHC( 0xb996 ), SHC( 0x8df4 ), SHC( 0xc5e4 ), SHC( 0x8835 ), SHC( 0xd2ea ), - SHC( 0x83f1 ), SHC( 0xe07f ), SHC( 0x8136 ), SHC( 0xee77 ), SHC( 0x800c ), SHC( 0xfca7 ), SHC( 0x8077 ), SHC( 0x0ae0 ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7f02 ), SHC( 0xf020 ), SHC( 0x7c0f ), SHC( 0xe07f ), SHC( 0x7732 ), SHC( 0xd15a ), - SHC( 0x707d ), SHC( 0xc2ed ), SHC( 0x680b ), SHC( 0xb572 ), SHC( 0x5dfe ), SHC( 0xa91e ), SHC( 0x527d ), SHC( 0x9e21 ), - SHC( 0x45b6 ), SHC( 0x94a7 ), SHC( 0x37dc ), SHC( 0x8cd6 ), SHC( 0x2924 ), SHC( 0x86cb ), SHC( 0x19ca ), SHC( 0x82a1 ), - SHC( 0x0a0a ), SHC( 0x8066 ), SHC( 0xfa24 ), SHC( 0x8023 ), SHC( 0xea53 ), SHC( 0x81da ), SHC( 0xdad8 ), SHC( 0x8583 ), - SHC( 0xcbf1 ), SHC( 0x8b11 ), SHC( 0xbdd6 ), SHC( 0x926e ), SHC( 0xb0c2 ), SHC( 0x9b7b ), SHC( 0xa4e7 ), SHC( 0xa616 ), - SHC( 0x9a74 ), SHC( 0xb215 ), SHC( 0x9192 ), SHC( 0xbf47 ), SHC( 0x8a66 ), SHC( 0xcd7a ), SHC( 0x850a ), SHC( 0xdc74 ), - SHC( 0x8194 ), SHC( 0xebfa ), SHC( 0x8012 ), SHC( 0xfbd0 ), SHC( 0x808a ), SHC( 0x0bb6 ), SHC( 0x82fa ), SHC( 0x1b6e ), - SHC( 0x8758 ), SHC( 0x2aba ), SHC( 0x8d93 ), SHC( 0x395c ), SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7eca ), SHC( 0xee77 ), - SHC( 0x7b31 ), SHC( 0xdd42 ), SHC( 0x7545 ), SHC( 0xccb5 ), SHC( 0x6d23 ), SHC( 0xbd1f ), SHC( 0x62f2 ), SHC( 0xaecd ), - SHC( 0x56e2 ), SHC( 0xa202 ), SHC( 0x4930 ), SHC( 0x96fe ), SHC( 0x3a1c ), SHC( 0x8df4 ), SHC( 0x29ef ), SHC( 0x8711 ), - SHC( 0x18f8 ), SHC( 0x8276 ), SHC( 0x0789 ), SHC( 0x8039 ), SHC( 0xf5f6 ), SHC( 0x8066 ), SHC( 0xe492 ), SHC( 0x82fa ), - SHC( 0xd3b3 ), SHC( 0x87ea ), SHC( 0xc3aa ), SHC( 0x8f1e ), SHC( 0xb4c4 ), SHC( 0x9873 ), SHC( 0xa749 ), SHC( 0xa3bc ), - SHC( 0x9b7b ), SHC( 0xb0c2 ), SHC( 0x9192 ), SHC( 0xbf47 ), SHC( 0x89bf ), SHC( 0xcf05 ), SHC( 0x8426 ), SHC( 0xdfaf ), - SHC( 0x80e4 ), SHC( 0xf0f5 ), SHC( 0x8007 ), SHC( 0x0283 ), SHC( 0x8194 ), SHC( 0x1406 ), SHC( 0x8583 ), SHC( 0x2528 ), - SHC( 0x8bc2 ), SHC( 0x3596 ), SHC( 0x9433 ), SHC( 0x4502 ), SHC( 0x9eac ), SHC( 0x5321 ), SHC( 0xaafa ), SHC( 0x5fae ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7e8d ), SHC( 0xecce ), SHC( 0x7a3e ), SHC( 0xda0b ), SHC( 0x732a ), SHC( 0xc824 ), - SHC( 0x697c ), SHC( 0xb780 ), SHC( 0x5d6c ), SHC( 0xa881 ), SHC( 0x4f3e ), SHC( 0x9b7b ), SHC( 0x3f45 ), SHC( 0x90bc ), - SHC( 0x2ddf ), SHC( 0x8881 ), SHC( 0x1b6e ), SHC( 0x82fa ), SHC( 0x085f ), SHC( 0x8047 ), SHC( 0xf520 ), SHC( 0x8077 ), - SHC( 0xe21f ), SHC( 0x838a ), SHC( 0xcfcb ), SHC( 0x896d ), SHC( 0xbe8e ), SHC( 0x91ff ), SHC( 0xaecd ), SHC( 0x9d0e ), - SHC( 0xa0e1 ), SHC( 0xaa5a ), SHC( 0x951c ), SHC( 0xb996 ), SHC( 0x8bc2 ), SHC( 0xca6a ), SHC( 0x850a ), SHC( 0xdc74 ), - SHC( 0x8119 ), SHC( 0xef4b ), SHC( 0x8007 ), SHC( 0x0283 ), SHC( 0x81da ), SHC( 0x15ad ), SHC( 0x8687 ), SHC( 0x2859 ), - SHC( 0x8df4 ), SHC( 0x3a1c ), SHC( 0x97f5 ), SHC( 0x4a8e ), SHC( 0xa451 ), SHC( 0x5951 ), SHC( 0xb2bf ), SHC( 0x660e ), - SHC( 0xc2ed ), SHC( 0x707d ), SHC( 0xd47c ), SHC( 0x7860 ), SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7e4a ), SHC( 0xeb27 ), - SHC( 0x7935 ), SHC( 0xd6dc ), SHC( 0x70e2 ), SHC( 0xc3aa ), SHC( 0x658c ), SHC( 0xb215 ), SHC( 0x577f ), SHC( 0xa294 ), - SHC( 0x471c ), SHC( 0x9593 ), SHC( 0x34d3 ), SHC( 0x8b69 ), SHC( 0x2120 ), SHC( 0x845d ), SHC( 0x0c8b ), SHC( 0x809e ), - SHC( 0xf7a1 ), SHC( 0x8047 ), SHC( 0xe2f0 ), SHC( 0x8358 ), SHC( 0xcf05 ), SHC( 0x89bf ), SHC( 0xbc69 ), SHC( 0x934e ), - SHC( 0xab9b ), SHC( 0x9fc4 ), SHC( 0x9d0e ), SHC( 0xaecd ), SHC( 0x9127 ), SHC( 0xc000 ), SHC( 0x8835 ), SHC( 0xd2ea ), - SHC( 0x8276 ), SHC( 0xe708 ), SHC( 0x8012 ), SHC( 0xfbd0 ), SHC( 0x8119 ), SHC( 0x10b5 ), SHC( 0x8583 ), SHC( 0x2528 ), - SHC( 0x8d34 ), SHC( 0x389c ), SHC( 0x97f5 ), SHC( 0x4a8e ), SHC( 0xa57e ), SHC( 0x5a82 ), SHC( 0xb572 ), SHC( 0x680b ), - SHC( 0xc764 ), SHC( 0x72cc ), SHC( 0xdad8 ), SHC( 0x7a7d ), SHC( 0xef4b ), SHC( 0x7ee7 ), SHC( 0x0430 ), SHC( 0x7fee ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7e01 ), SHC( 0xe980 ), SHC( 0x7816 ), SHC( 0xd3b3 ), SHC( 0x6e6e ), SHC( 0xbf47 ), - SHC( 0x6154 ), SHC( 0xacdf ), SHC( 0x5133 ), SHC( 0x9d0e ), SHC( 0x3e8b ), SHC( 0x9053 ), SHC( 0x29ef ), SHC( 0x8711 ), - SHC( 0x1406 ), SHC( 0x8194 ), SHC( 0xfd7d ), SHC( 0x8007 ), SHC( 0xe708 ), SHC( 0x8276 ), SHC( 0xd15a ), SHC( 0x88ce ), - SHC( 0xbd1f ), SHC( 0x92dd ), SHC( 0xaafa ), SHC( 0xa052 ), SHC( 0x9b7b ), SHC( 0xb0c2 ), SHC( 0x8f1e ), SHC( 0xc3aa ), - SHC( 0x8644 ), SHC( 0xd873 ), SHC( 0x8136 ), SHC( 0xee77 ), SHC( 0x801a ), SHC( 0x0506 ), SHC( 0x82fa ), SHC( 0x1b6e ), - SHC( 0x89bf ), SHC( 0x30fb ), SHC( 0x9433 ), SHC( 0x4502 ), SHC( 0xa202 ), SHC( 0x56e2 ), SHC( 0xb2bf ), SHC( 0x660e ), - SHC( 0xc5e4 ), SHC( 0x720c ), SHC( 0xdad8 ), SHC( 0x7a7d ), SHC( 0xf0f5 ), SHC( 0x7f1c ), SHC( 0x0789 ), SHC( 0x7fc7 ), - SHC( 0x1de1 ), SHC( 0x7c76 ), SHC( 0x334b ), SHC( 0x7545 ), SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7db3 ), SHC( 0xe7da ), - SHC( 0x76e3 ), SHC( 0xd092 ), SHC( 0x6bcd ), SHC( 0xbafe ), SHC( 0x5cd9 ), SHC( 0xa7e4 ), SHC( 0x4a8e ), SHC( 0x97f5 ), - SHC( 0x3596 ), SHC( 0x8bc2 ), SHC( 0x1eb1 ), SHC( 0x83bd ), SHC( 0x06b2 ), SHC( 0x802d ), SHC( 0xee77 ), SHC( 0x8136 ), - SHC( 0xd6dc ), SHC( 0x86cb ), SHC( 0xc0bb ), SHC( 0x90bc ), SHC( 0xacdf ), SHC( 0x9eac ), SHC( 0x9c01 ), SHC( 0xb01a ), - SHC( 0x8eb9 ), SHC( 0xc467 ), SHC( 0x8583 ), SHC( 0xdad8 ), SHC( 0x80b4 ), SHC( 0xf29f ), SHC( 0x8077 ), SHC( 0x0ae0 ), - SHC( 0x84cf ), SHC( 0x22be ), SHC( 0x8d93 ), SHC( 0x395c ), SHC( 0x9a74 ), SHC( 0x4deb ), SHC( 0xaafa ), SHC( 0x5fae ), - SHC( 0xbe8e ), SHC( 0x6e01 ), SHC( 0xd47c ), SHC( 0x7860 ), SHC( 0xebfa ), SHC( 0x7e6c ), SHC( 0x0430 ), SHC( 0x7fee ), - SHC( 0x1c3f ), SHC( 0x7cd8 ), SHC( 0x334b ), SHC( 0x7545 ), SHC( 0x4880 ), SHC( 0x697c ), SHC( 0x5b19 ), SHC( 0x59ea ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7d5f ), SHC( 0xe636 ), SHC( 0x759a ), SHC( 0xcd7a ), SHC( 0x6902 ), SHC( 0xb6d0 ), - SHC( 0x581c ), SHC( 0xa327 ), SHC( 0x4397 ), SHC( 0x934e ), SHC( 0x2c4d ), SHC( 0x87ea ), SHC( 0x1332 ), SHC( 0x8173 ), - SHC( 0xf94e ), SHC( 0x802d ), SHC( 0xdfaf ), SHC( 0x8426 ), SHC( 0xc764 ), SHC( 0x8d34 ), SHC( 0xb16b ), SHC( 0x9af7 ), - SHC( 0x9eac ), SHC( 0xacdf ), SHC( 0x8fea ), SHC( 0xc231 ), SHC( 0x85c2 ), SHC( 0xda0b ), SHC( 0x809e ), SHC( 0xf375 ), - SHC( 0x80b4 ), SHC( 0x0d61 ), SHC( 0x8603 ), SHC( 0x26c1 ), SHC( 0x9053 ), SHC( 0x3e8b ), SHC( 0x9f37 ), SHC( 0x53c3 ), - SHC( 0xb215 ), SHC( 0x658c ), SHC( 0xc824 ), SHC( 0x732a ), SHC( 0xe07f ), SHC( 0x7c0f ), SHC( 0xfa24 ), SHC( 0x7fdd ), - SHC( 0x1406 ), SHC( 0x7e6c ), SHC( 0x2d16 ), SHC( 0x77cb ), SHC( 0x444d ), SHC( 0x6c40 ), SHC( 0x58b7 ), SHC( 0x5c44 ), - SHC( 0x697c ), SHC( 0x4880 ), SHC( 0x75ee ), SHC( 0x31c1 ), +const Word16 FFT_RotVector_960_fx[1860] = { + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7ffd ), + SHC( 0xfe54 ), + SHC( 0x7ff4 ), + SHC( 0xfca7 ), + SHC( 0x7fe6 ), + SHC( 0xfafa ), + SHC( 0x7fd3 ), + SHC( 0xf94e ), + SHC( 0x7fb9 ), + SHC( 0xf7a1 ), + SHC( 0x7f9a ), + SHC( 0xf5f6 ), + SHC( 0x7f76 ), + SHC( 0xf44a ), + SHC( 0x7f4c ), + SHC( 0xf29f ), + SHC( 0x7f1c ), + SHC( 0xf0f5 ), + SHC( 0x7ee7 ), + SHC( 0xef4b ), + SHC( 0x7eac ), + SHC( 0xeda3 ), + SHC( 0x7e6c ), + SHC( 0xebfa ), + SHC( 0x7e26 ), + SHC( 0xea53 ), + SHC( 0x7ddb ), + SHC( 0xe8ad ), + SHC( 0x7d8a ), + SHC( 0xe708 ), + SHC( 0x7d33 ), + SHC( 0xe564 ), + SHC( 0x7cd8 ), + SHC( 0xe3c1 ), + SHC( 0x7c76 ), + SHC( 0xe21f ), + SHC( 0x7c0f ), + SHC( 0xe07f ), + SHC( 0x7ba3 ), + SHC( 0xdee0 ), + SHC( 0x7b31 ), + SHC( 0xdd42 ), + SHC( 0x7aba ), + SHC( 0xdba6 ), + SHC( 0x7a3e ), + SHC( 0xda0b ), + SHC( 0x79bc ), + SHC( 0xd873 ), + SHC( 0x7935 ), + SHC( 0xd6dc ), + SHC( 0x78a8 ), + SHC( 0xd546 ), + SHC( 0x7816 ), + SHC( 0xd3b3 ), + SHC( 0x777f ), + SHC( 0xd221 ), + SHC( 0x76e3 ), + SHC( 0xd092 ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7ff4 ), + SHC( 0xfca7 ), + SHC( 0x7fd3 ), + SHC( 0xf94e ), + SHC( 0x7f9a ), + SHC( 0xf5f6 ), + SHC( 0x7f4c ), + SHC( 0xf29f ), + SHC( 0x7ee7 ), + SHC( 0xef4b ), + SHC( 0x7e6c ), + SHC( 0xebfa ), + SHC( 0x7ddb ), + SHC( 0xe8ad ), + SHC( 0x7d33 ), + SHC( 0xe564 ), + SHC( 0x7c76 ), + SHC( 0xe21f ), + SHC( 0x7ba3 ), + SHC( 0xdee0 ), + SHC( 0x7aba ), + SHC( 0xdba6 ), + SHC( 0x79bc ), + SHC( 0xd873 ), + SHC( 0x78a8 ), + SHC( 0xd546 ), + SHC( 0x777f ), + SHC( 0xd221 ), + SHC( 0x7641 ), + SHC( 0xcf05 ), + SHC( 0x74ef ), + SHC( 0xcbf1 ), + SHC( 0x7387 ), + SHC( 0xc8e6 ), + SHC( 0x720c ), + SHC( 0xc5e4 ), + SHC( 0x707d ), + SHC( 0xc2ed ), + SHC( 0x6ed9 ), + SHC( 0xc000 ), + SHC( 0x6d23 ), + SHC( 0xbd1f ), + SHC( 0x6b59 ), + SHC( 0xba4a ), + SHC( 0x697c ), + SHC( 0xb780 ), + SHC( 0x678d ), + SHC( 0xb4c4 ), + SHC( 0x658c ), + SHC( 0xb215 ), + SHC( 0x6379 ), + SHC( 0xaf73 ), + SHC( 0x6154 ), + SHC( 0xacdf ), + SHC( 0x5f1f ), + SHC( 0xaa5a ), + SHC( 0x5cd9 ), + SHC( 0xa7e4 ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7fe6 ), + SHC( 0xfafa ), + SHC( 0x7f9a ), + SHC( 0xf5f6 ), + SHC( 0x7f1c ), + SHC( 0xf0f5 ), + SHC( 0x7e6c ), + SHC( 0xebfa ), + SHC( 0x7d8a ), + SHC( 0xe708 ), + SHC( 0x7c76 ), + SHC( 0xe21f ), + SHC( 0x7b31 ), + SHC( 0xdd42 ), + SHC( 0x79bc ), + SHC( 0xd873 ), + SHC( 0x7816 ), + SHC( 0xd3b3 ), + SHC( 0x7641 ), + SHC( 0xcf05 ), + SHC( 0x743e ), + SHC( 0xca6a ), + SHC( 0x720c ), + SHC( 0xc5e4 ), + SHC( 0x6fad ), + SHC( 0xc175 ), + SHC( 0x6d23 ), + SHC( 0xbd1f ), + SHC( 0x6a6d ), + SHC( 0xb8e4 ), + SHC( 0x678d ), + SHC( 0xb4c4 ), + SHC( 0x6485 ), + SHC( 0xb0c2 ), + SHC( 0x6154 ), + SHC( 0xacdf ), + SHC( 0x5dfe ), + SHC( 0xa91e ), + SHC( 0x5a82 ), + SHC( 0xa57e ), + SHC( 0x56e2 ), + SHC( 0xa202 ), + SHC( 0x5321 ), + SHC( 0x9eac ), + SHC( 0x4f3e ), + SHC( 0x9b7b ), + SHC( 0x4b3c ), + SHC( 0x9873 ), + SHC( 0x471c ), + SHC( 0x9593 ), + SHC( 0x42e1 ), + SHC( 0x92dd ), + SHC( 0x3e8b ), + SHC( 0x9053 ), + SHC( 0x3a1c ), + SHC( 0x8df4 ), + SHC( 0x3596 ), + SHC( 0x8bc2 ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7fd3 ), + SHC( 0xf94e ), + SHC( 0x7f4c ), + SHC( 0xf29f ), + SHC( 0x7e6c ), + SHC( 0xebfa ), + SHC( 0x7d33 ), + SHC( 0xe564 ), + SHC( 0x7ba3 ), + SHC( 0xdee0 ), + SHC( 0x79bc ), + SHC( 0xd873 ), + SHC( 0x777f ), + SHC( 0xd221 ), + SHC( 0x74ef ), + SHC( 0xcbf1 ), + SHC( 0x720c ), + SHC( 0xc5e4 ), + SHC( 0x6ed9 ), + SHC( 0xc000 ), + SHC( 0x6b59 ), + SHC( 0xba4a ), + SHC( 0x678d ), + SHC( 0xb4c4 ), + SHC( 0x6379 ), + SHC( 0xaf73 ), + SHC( 0x5f1f ), + SHC( 0xaa5a ), + SHC( 0x5a82 ), + SHC( 0xa57e ), + SHC( 0x55a6 ), + SHC( 0xa0e1 ), + SHC( 0x508d ), + SHC( 0x9c87 ), + SHC( 0x4b3c ), + SHC( 0x9873 ), + SHC( 0x45b6 ), + SHC( 0x94a7 ), + SHC( 0x4000 ), + SHC( 0x9127 ), + SHC( 0x3a1c ), + SHC( 0x8df4 ), + SHC( 0x340f ), + SHC( 0x8b11 ), + SHC( 0x2ddf ), + SHC( 0x8881 ), + SHC( 0x278d ), + SHC( 0x8644 ), + SHC( 0x2120 ), + SHC( 0x845d ), + SHC( 0x1a9c ), + SHC( 0x82cd ), + SHC( 0x1406 ), + SHC( 0x8194 ), + SHC( 0x0d61 ), + SHC( 0x80b4 ), + SHC( 0x06b2 ), + SHC( 0x802d ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7fb9 ), + SHC( 0xf7a1 ), + SHC( 0x7ee7 ), + SHC( 0xef4b ), + SHC( 0x7d8a ), + SHC( 0xe708 ), + SHC( 0x7ba3 ), + SHC( 0xdee0 ), + SHC( 0x7935 ), + SHC( 0xd6dc ), + SHC( 0x7641 ), + SHC( 0xcf05 ), + SHC( 0x72cc ), + SHC( 0xc764 ), + SHC( 0x6ed9 ), + SHC( 0xc000 ), + SHC( 0x6a6d ), + SHC( 0xb8e4 ), + SHC( 0x658c ), + SHC( 0xb215 ), + SHC( 0x603c ), + SHC( 0xab9b ), + SHC( 0x5a82 ), + SHC( 0xa57e ), + SHC( 0x5465 ), + SHC( 0x9fc4 ), + SHC( 0x4deb ), + SHC( 0x9a74 ), + SHC( 0x471c ), + SHC( 0x9593 ), + SHC( 0x4000 ), + SHC( 0x9127 ), + SHC( 0x389c ), + SHC( 0x8d34 ), + SHC( 0x30fb ), + SHC( 0x89bf ), + SHC( 0x2924 ), + SHC( 0x86cb ), + SHC( 0x2120 ), + SHC( 0x845d ), + SHC( 0x18f8 ), + SHC( 0x8276 ), + SHC( 0x10b5 ), + SHC( 0x8119 ), + SHC( 0x085f ), + SHC( 0x8047 ), + SHC( 0x0000 ), + SHC( 0x8000 ), + SHC( 0xf7a1 ), + SHC( 0x8047 ), + SHC( 0xef4b ), + SHC( 0x8119 ), + SHC( 0xe708 ), + SHC( 0x8276 ), + SHC( 0xdee0 ), + SHC( 0x845d ), + SHC( 0xd6dc ), + SHC( 0x86cb ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7f9a ), + SHC( 0xf5f6 ), + SHC( 0x7e6c ), + SHC( 0xebfa ), + SHC( 0x7c76 ), + SHC( 0xe21f ), + SHC( 0x79bc ), + SHC( 0xd873 ), + SHC( 0x7641 ), + SHC( 0xcf05 ), + SHC( 0x720c ), + SHC( 0xc5e4 ), + SHC( 0x6d23 ), + SHC( 0xbd1f ), + SHC( 0x678d ), + SHC( 0xb4c4 ), + SHC( 0x6154 ), + SHC( 0xacdf ), + SHC( 0x5a82 ), + SHC( 0xa57e ), + SHC( 0x5321 ), + SHC( 0x9eac ), + SHC( 0x4b3c ), + SHC( 0x9873 ), + SHC( 0x42e1 ), + SHC( 0x92dd ), + SHC( 0x3a1c ), + SHC( 0x8df4 ), + SHC( 0x30fb ), + SHC( 0x89bf ), + SHC( 0x278d ), + SHC( 0x8644 ), + SHC( 0x1de1 ), + SHC( 0x838a ), + SHC( 0x1406 ), + SHC( 0x8194 ), + SHC( 0x0a0a ), + SHC( 0x8066 ), + SHC( 0x0000 ), + SHC( 0x8000 ), + SHC( 0xf5f6 ), + SHC( 0x8066 ), + SHC( 0xebfa ), + SHC( 0x8194 ), + SHC( 0xe21f ), + SHC( 0x838a ), + SHC( 0xd873 ), + SHC( 0x8644 ), + SHC( 0xcf05 ), + SHC( 0x89bf ), + SHC( 0xc5e4 ), + SHC( 0x8df4 ), + SHC( 0xbd1f ), + SHC( 0x92dd ), + SHC( 0xb4c4 ), + SHC( 0x9873 ), + SHC( 0xacdf ), + SHC( 0x9eac ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7f76 ), + SHC( 0xf44a ), + SHC( 0x7ddb ), + SHC( 0xe8ad ), + SHC( 0x7b31 ), + SHC( 0xdd42 ), + SHC( 0x777f ), + SHC( 0xd221 ), + SHC( 0x72cc ), + SHC( 0xc764 ), + SHC( 0x6d23 ), + SHC( 0xbd1f ), + SHC( 0x668f ), + SHC( 0xb36b ), + SHC( 0x5f1f ), + SHC( 0xaa5a ), + SHC( 0x56e2 ), + SHC( 0xa202 ), + SHC( 0x4deb ), + SHC( 0x9a74 ), + SHC( 0x444d ), + SHC( 0x93c0 ), + SHC( 0x3a1c ), + SHC( 0x8df4 ), + SHC( 0x2f6e ), + SHC( 0x891d ), + SHC( 0x245a ), + SHC( 0x8546 ), + SHC( 0x18f8 ), + SHC( 0x8276 ), + SHC( 0x0d61 ), + SHC( 0x80b4 ), + SHC( 0x01ac ), + SHC( 0x8003 ), + SHC( 0xf5f6 ), + SHC( 0x8066 ), + SHC( 0xea53 ), + SHC( 0x81da ), + SHC( 0xdee0 ), + SHC( 0x845d ), + SHC( 0xd3b3 ), + SHC( 0x87ea ), + SHC( 0xc8e6 ), + SHC( 0x8c79 ), + SHC( 0xbe8e ), + SHC( 0x91ff ), + SHC( 0xb4c4 ), + SHC( 0x9873 ), + SHC( 0xab9b ), + SHC( 0x9fc4 ), + SHC( 0xa327 ), + SHC( 0xa7e4 ), + SHC( 0x9b7b ), + SHC( 0xb0c2 ), + SHC( 0x94a7 ), + SHC( 0xba4a ), + SHC( 0x8eb9 ), + SHC( 0xc467 ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7f4c ), + SHC( 0xf29f ), + SHC( 0x7d33 ), + SHC( 0xe564 ), + SHC( 0x79bc ), + SHC( 0xd873 ), + SHC( 0x74ef ), + SHC( 0xcbf1 ), + SHC( 0x6ed9 ), + SHC( 0xc000 ), + SHC( 0x678d ), + SHC( 0xb4c4 ), + SHC( 0x5f1f ), + SHC( 0xaa5a ), + SHC( 0x55a6 ), + SHC( 0xa0e1 ), + SHC( 0x4b3c ), + SHC( 0x9873 ), + SHC( 0x4000 ), + SHC( 0x9127 ), + SHC( 0x340f ), + SHC( 0x8b11 ), + SHC( 0x278d ), + SHC( 0x8644 ), + SHC( 0x1a9c ), + SHC( 0x82cd ), + SHC( 0x0d61 ), + SHC( 0x80b4 ), + SHC( 0x0000 ), + SHC( 0x8000 ), + SHC( 0xf29f ), + SHC( 0x80b4 ), + SHC( 0xe564 ), + SHC( 0x82cd ), + SHC( 0xd873 ), + SHC( 0x8644 ), + SHC( 0xcbf1 ), + SHC( 0x8b11 ), + SHC( 0xc000 ), + SHC( 0x9127 ), + SHC( 0xb4c4 ), + SHC( 0x9873 ), + SHC( 0xaa5a ), + SHC( 0xa0e1 ), + SHC( 0xa0e1 ), + SHC( 0xaa5a ), + SHC( 0x9873 ), + SHC( 0xb4c4 ), + SHC( 0x9127 ), + SHC( 0xc000 ), + SHC( 0x8b11 ), + SHC( 0xcbf1 ), + SHC( 0x8644 ), + SHC( 0xd873 ), + SHC( 0x82cd ), + SHC( 0xe564 ), + SHC( 0x80b4 ), + SHC( 0xf29f ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7f1c ), + SHC( 0xf0f5 ), + SHC( 0x7c76 ), + SHC( 0xe21f ), + SHC( 0x7816 ), + SHC( 0xd3b3 ), + SHC( 0x720c ), + SHC( 0xc5e4 ), + SHC( 0x6a6d ), + SHC( 0xb8e4 ), + SHC( 0x6154 ), + SHC( 0xacdf ), + SHC( 0x56e2 ), + SHC( 0xa202 ), + SHC( 0x4b3c ), + SHC( 0x9873 ), + SHC( 0x3e8b ), + SHC( 0x9053 ), + SHC( 0x30fb ), + SHC( 0x89bf ), + SHC( 0x22be ), + SHC( 0x84cf ), + SHC( 0x1406 ), + SHC( 0x8194 ), + SHC( 0x0506 ), + SHC( 0x801a ), + SHC( 0xf5f6 ), + SHC( 0x8066 ), + SHC( 0xe708 ), + SHC( 0x8276 ), + SHC( 0xd873 ), + SHC( 0x8644 ), + SHC( 0xca6a ), + SHC( 0x8bc2 ), + SHC( 0xbd1f ), + SHC( 0x92dd ), + SHC( 0xb0c2 ), + SHC( 0x9b7b ), + SHC( 0xa57e ), + SHC( 0xa57e ), + SHC( 0x9b7b ), + SHC( 0xb0c2 ), + SHC( 0x92dd ), + SHC( 0xbd1f ), + SHC( 0x8bc2 ), + SHC( 0xca6a ), + SHC( 0x8644 ), + SHC( 0xd873 ), + SHC( 0x8276 ), + SHC( 0xe708 ), + SHC( 0x8066 ), + SHC( 0xf5f6 ), + SHC( 0x801a ), + SHC( 0x0506 ), + SHC( 0x8194 ), + SHC( 0x1406 ), + SHC( 0x84cf ), + SHC( 0x22be ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7ee7 ), + SHC( 0xef4b ), + SHC( 0x7ba3 ), + SHC( 0xdee0 ), + SHC( 0x7641 ), + SHC( 0xcf05 ), + SHC( 0x6ed9 ), + SHC( 0xc000 ), + SHC( 0x658c ), + SHC( 0xb215 ), + SHC( 0x5a82 ), + SHC( 0xa57e ), + SHC( 0x4deb ), + SHC( 0x9a74 ), + SHC( 0x4000 ), + SHC( 0x9127 ), + SHC( 0x30fb ), + SHC( 0x89bf ), + SHC( 0x2120 ), + SHC( 0x845d ), + SHC( 0x10b5 ), + SHC( 0x8119 ), + SHC( 0x0000 ), + SHC( 0x8000 ), + SHC( 0xef4b ), + SHC( 0x8119 ), + SHC( 0xdee0 ), + SHC( 0x845d ), + SHC( 0xcf05 ), + SHC( 0x89bf ), + SHC( 0xc000 ), + SHC( 0x9127 ), + SHC( 0xb215 ), + SHC( 0x9a74 ), + SHC( 0xa57e ), + SHC( 0xa57e ), + SHC( 0x9a74 ), + SHC( 0xb215 ), + SHC( 0x9127 ), + SHC( 0xc000 ), + SHC( 0x89bf ), + SHC( 0xcf05 ), + SHC( 0x845d ), + SHC( 0xdee0 ), + SHC( 0x8119 ), + SHC( 0xef4b ), + SHC( 0x8000 ), + SHC( 0x0000 ), + SHC( 0x8119 ), + SHC( 0x10b5 ), + SHC( 0x845d ), + SHC( 0x2120 ), + SHC( 0x89bf ), + SHC( 0x30fb ), + SHC( 0x9127 ), + SHC( 0x4000 ), + SHC( 0x9a74 ), + SHC( 0x4deb ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7eac ), + SHC( 0xeda3 ), + SHC( 0x7aba ), + SHC( 0xdba6 ), + SHC( 0x743e ), + SHC( 0xca6a ), + SHC( 0x6b59 ), + SHC( 0xba4a ), + SHC( 0x603c ), + SHC( 0xab9b ), + SHC( 0x5321 ), + SHC( 0x9eac ), + SHC( 0x444d ), + SHC( 0x93c0 ), + SHC( 0x340f ), + SHC( 0x8b11 ), + SHC( 0x22be ), + SHC( 0x84cf ), + SHC( 0x10b5 ), + SHC( 0x8119 ), + SHC( 0xfe54 ), + SHC( 0x8003 ), + SHC( 0xebfa ), + SHC( 0x8194 ), + SHC( 0xda0b ), + SHC( 0x85c2 ), + SHC( 0xc8e6 ), + SHC( 0x8c79 ), + SHC( 0xb8e4 ), + SHC( 0x9593 ), + SHC( 0xaa5a ), + SHC( 0xa0e1 ), + SHC( 0x9d97 ), + SHC( 0xae27 ), + SHC( 0x92dd ), + SHC( 0xbd1f ), + SHC( 0x8a66 ), + SHC( 0xcd7a ), + SHC( 0x845d ), + SHC( 0xdee0 ), + SHC( 0x80e4 ), + SHC( 0xf0f5 ), + SHC( 0x800c ), + SHC( 0x0359 ), + SHC( 0x81da ), + SHC( 0x15ad ), + SHC( 0x8644 ), + SHC( 0x278d ), + SHC( 0x8d34 ), + SHC( 0x389c ), + SHC( 0x9684 ), + SHC( 0x4880 ), + SHC( 0xa202 ), + SHC( 0x56e2 ), + SHC( 0xaf73 ), + SHC( 0x6379 ), + SHC( 0xbe8e ), + SHC( 0x6e01 ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7e6c ), + SHC( 0xebfa ), + SHC( 0x79bc ), + SHC( 0xd873 ), + SHC( 0x720c ), + SHC( 0xc5e4 ), + SHC( 0x678d ), + SHC( 0xb4c4 ), + SHC( 0x5a82 ), + SHC( 0xa57e ), + SHC( 0x4b3c ), + SHC( 0x9873 ), + SHC( 0x3a1c ), + SHC( 0x8df4 ), + SHC( 0x278d ), + SHC( 0x8644 ), + SHC( 0x1406 ), + SHC( 0x8194 ), + SHC( 0x0000 ), + SHC( 0x8000 ), + SHC( 0xebfa ), + SHC( 0x8194 ), + SHC( 0xd873 ), + SHC( 0x8644 ), + SHC( 0xc5e4 ), + SHC( 0x8df4 ), + SHC( 0xb4c4 ), + SHC( 0x9873 ), + SHC( 0xa57e ), + SHC( 0xa57e ), + SHC( 0x9873 ), + SHC( 0xb4c4 ), + SHC( 0x8df4 ), + SHC( 0xc5e4 ), + SHC( 0x8644 ), + SHC( 0xd873 ), + SHC( 0x8194 ), + SHC( 0xebfa ), + SHC( 0x8000 ), + SHC( 0x0000 ), + SHC( 0x8194 ), + SHC( 0x1406 ), + SHC( 0x8644 ), + SHC( 0x278d ), + SHC( 0x8df4 ), + SHC( 0x3a1c ), + SHC( 0x9873 ), + SHC( 0x4b3c ), + SHC( 0xa57e ), + SHC( 0x5a82 ), + SHC( 0xb4c4 ), + SHC( 0x678d ), + SHC( 0xc5e4 ), + SHC( 0x720c ), + SHC( 0xd873 ), + SHC( 0x79bc ), + SHC( 0xebfa ), + SHC( 0x7e6c ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7e26 ), + SHC( 0xea53 ), + SHC( 0x78a8 ), + SHC( 0xd546 ), + SHC( 0x6fad ), + SHC( 0xc175 ), + SHC( 0x6379 ), + SHC( 0xaf73 ), + SHC( 0x5465 ), + SHC( 0x9fc4 ), + SHC( 0x42e1 ), + SHC( 0x92dd ), + SHC( 0x2f6e ), + SHC( 0x891d ), + SHC( 0x1a9c ), + SHC( 0x82cd ), + SHC( 0x0506 ), + SHC( 0x801a ), + SHC( 0xef4b ), + SHC( 0x8119 ), + SHC( 0xda0b ), + SHC( 0x85c2 ), + SHC( 0xc5e4 ), + SHC( 0x8df4 ), + SHC( 0xb36b ), + SHC( 0x9971 ), + SHC( 0xa327 ), + SHC( 0xa7e4 ), + SHC( 0x9593 ), + SHC( 0xb8e4 ), + SHC( 0x8b11 ), + SHC( 0xcbf1 ), + SHC( 0x83f1 ), + SHC( 0xe07f ), + SHC( 0x8066 ), + SHC( 0xf5f6 ), + SHC( 0x808a ), + SHC( 0x0bb6 ), + SHC( 0x845d ), + SHC( 0x2120 ), + SHC( 0x8bc2 ), + SHC( 0x3596 ), + SHC( 0x9684 ), + SHC( 0x4880 ), + SHC( 0xa451 ), + SHC( 0x5951 ), + SHC( 0xb4c4 ), + SHC( 0x678d ), + SHC( 0xc764 ), + SHC( 0x72cc ), + SHC( 0xdba6 ), + SHC( 0x7aba ), + SHC( 0xf0f5 ), + SHC( 0x7f1c ), + SHC( 0x06b2 ), + SHC( 0x7fd3 ), + SHC( 0x1c3f ), + SHC( 0x7cd8 ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7ddb ), + SHC( 0xe8ad ), + SHC( 0x777f ), + SHC( 0xd221 ), + SHC( 0x6d23 ), + SHC( 0xbd1f ), + SHC( 0x5f1f ), + SHC( 0xaa5a ), + SHC( 0x4deb ), + SHC( 0x9a74 ), + SHC( 0x3a1c ), + SHC( 0x8df4 ), + SHC( 0x245a ), + SHC( 0x8546 ), + SHC( 0x0d61 ), + SHC( 0x80b4 ), + SHC( 0xf5f6 ), + SHC( 0x8066 ), + SHC( 0xdee0 ), + SHC( 0x845d ), + SHC( 0xc8e6 ), + SHC( 0x8c79 ), + SHC( 0xb4c4 ), + SHC( 0x9873 ), + SHC( 0xa327 ), + SHC( 0xa7e4 ), + SHC( 0x94a7 ), + SHC( 0xba4a ), + SHC( 0x89bf ), + SHC( 0xcf05 ), + SHC( 0x82cd ), + SHC( 0xe564 ), + SHC( 0x800c ), + SHC( 0xfca7 ), + SHC( 0x8194 ), + SHC( 0x1406 ), + SHC( 0x8758 ), + SHC( 0x2aba ), + SHC( 0x9127 ), + SHC( 0x4000 ), + SHC( 0x9eac ), + SHC( 0x5321 ), + SHC( 0xaf73 ), + SHC( 0x6379 ), + SHC( 0xc2ed ), + SHC( 0x707d ), + SHC( 0xd873 ), + SHC( 0x79bc ), + SHC( 0xef4b ), + SHC( 0x7ee7 ), + SHC( 0x06b2 ), + SHC( 0x7fd3 ), + SHC( 0x1de1 ), + SHC( 0x7c76 ), + SHC( 0x340f ), + SHC( 0x74ef ), + SHC( 0x4880 ), + SHC( 0x697c ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7d8a ), + SHC( 0xe708 ), + SHC( 0x7641 ), + SHC( 0xcf05 ), + SHC( 0x6a6d ), + SHC( 0xb8e4 ), + SHC( 0x5a82 ), + SHC( 0xa57e ), + SHC( 0x471c ), + SHC( 0x9593 ), + SHC( 0x30fb ), + SHC( 0x89bf ), + SHC( 0x18f8 ), + SHC( 0x8276 ), + SHC( 0x0000 ), + SHC( 0x8000 ), + SHC( 0xe708 ), + SHC( 0x8276 ), + SHC( 0xcf05 ), + SHC( 0x89bf ), + SHC( 0xb8e4 ), + SHC( 0x9593 ), + SHC( 0xa57e ), + SHC( 0xa57e ), + SHC( 0x9593 ), + SHC( 0xb8e4 ), + SHC( 0x89bf ), + SHC( 0xcf05 ), + SHC( 0x8276 ), + SHC( 0xe708 ), + SHC( 0x8000 ), + SHC( 0x0000 ), + SHC( 0x8276 ), + SHC( 0x18f8 ), + SHC( 0x89bf ), + SHC( 0x30fb ), + SHC( 0x9593 ), + SHC( 0x471c ), + SHC( 0xa57e ), + SHC( 0x5a82 ), + SHC( 0xb8e4 ), + SHC( 0x6a6d ), + SHC( 0xcf05 ), + SHC( 0x7641 ), + SHC( 0xe708 ), + SHC( 0x7d8a ), + SHC( 0x0000 ), + SHC( 0x7fff ), + SHC( 0x18f8 ), + SHC( 0x7d8a ), + SHC( 0x30fb ), + SHC( 0x7641 ), + SHC( 0x471c ), + SHC( 0x6a6d ), + SHC( 0x5a82 ), + SHC( 0x5a82 ), + SHC( 0x6a6d ), + SHC( 0x471c ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7fff ), + SHC( 0xff2a ), + SHC( 0x7ffd ), + SHC( 0xfe54 ), + SHC( 0x7ff9 ), + SHC( 0xfd7d ), + SHC( 0x7ff4 ), + SHC( 0xfca7 ), + SHC( 0x7fee ), + SHC( 0xfbd0 ), + SHC( 0x7fe6 ), + SHC( 0xfafa ), + SHC( 0x7fdd ), + SHC( 0xfa24 ), + SHC( 0x7fd3 ), + SHC( 0xf94e ), + SHC( 0x7fc7 ), + SHC( 0xf877 ), + SHC( 0x7fb9 ), + SHC( 0xf7a1 ), + SHC( 0x7fab ), + SHC( 0xf6cb ), + SHC( 0x7f9a ), + SHC( 0xf5f6 ), + SHC( 0x7f89 ), + SHC( 0xf520 ), + SHC( 0x7f76 ), + SHC( 0xf44a ), + SHC( 0x7f62 ), + SHC( 0xf375 ), + SHC( 0x7f4c ), + SHC( 0xf29f ), + SHC( 0x7f35 ), + SHC( 0xf1ca ), + SHC( 0x7f1c ), + SHC( 0xf0f5 ), + SHC( 0x7f02 ), + SHC( 0xf020 ), + SHC( 0x7ee7 ), + SHC( 0xef4b ), + SHC( 0x7eca ), + SHC( 0xee77 ), + SHC( 0x7eac ), + SHC( 0xeda3 ), + SHC( 0x7e8d ), + SHC( 0xecce ), + SHC( 0x7e6c ), + SHC( 0xebfa ), + SHC( 0x7e4a ), + SHC( 0xeb27 ), + SHC( 0x7e26 ), + SHC( 0xea53 ), + SHC( 0x7e01 ), + SHC( 0xe980 ), + SHC( 0x7ddb ), + SHC( 0xe8ad ), + SHC( 0x7db3 ), + SHC( 0xe7da ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7ff9 ), + SHC( 0xfd7d ), + SHC( 0x7fe6 ), + SHC( 0xfafa ), + SHC( 0x7fc7 ), + SHC( 0xf877 ), + SHC( 0x7f9a ), + SHC( 0xf5f6 ), + SHC( 0x7f62 ), + SHC( 0xf375 ), + SHC( 0x7f1c ), + SHC( 0xf0f5 ), + SHC( 0x7eca ), + SHC( 0xee77 ), + SHC( 0x7e6c ), + SHC( 0xebfa ), + SHC( 0x7e01 ), + SHC( 0xe980 ), + SHC( 0x7d8a ), + SHC( 0xe708 ), + SHC( 0x7d06 ), + SHC( 0xe492 ), + SHC( 0x7c76 ), + SHC( 0xe21f ), + SHC( 0x7bda ), + SHC( 0xdfaf ), + SHC( 0x7b31 ), + SHC( 0xdd42 ), + SHC( 0x7a7d ), + SHC( 0xdad8 ), + SHC( 0x79bc ), + SHC( 0xd873 ), + SHC( 0x78ef ), + SHC( 0xd611 ), + SHC( 0x7816 ), + SHC( 0xd3b3 ), + SHC( 0x7732 ), + SHC( 0xd15a ), + SHC( 0x7641 ), + SHC( 0xcf05 ), + SHC( 0x7545 ), + SHC( 0xccb5 ), + SHC( 0x743e ), + SHC( 0xca6a ), + SHC( 0x732a ), + SHC( 0xc824 ), + SHC( 0x720c ), + SHC( 0xc5e4 ), + SHC( 0x70e2 ), + SHC( 0xc3aa ), + SHC( 0x6fad ), + SHC( 0xc175 ), + SHC( 0x6e6e ), + SHC( 0xbf47 ), + SHC( 0x6d23 ), + SHC( 0xbd1f ), + SHC( 0x6bcd ), + SHC( 0xbafe ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7fee ), + SHC( 0xfbd0 ), + SHC( 0x7fb9 ), + SHC( 0xf7a1 ), + SHC( 0x7f62 ), + SHC( 0xf375 ), + SHC( 0x7ee7 ), + SHC( 0xef4b ), + SHC( 0x7e4a ), + SHC( 0xeb27 ), + SHC( 0x7d8a ), + SHC( 0xe708 ), + SHC( 0x7ca8 ), + SHC( 0xe2f0 ), + SHC( 0x7ba3 ), + SHC( 0xdee0 ), + SHC( 0x7a7d ), + SHC( 0xdad8 ), + SHC( 0x7935 ), + SHC( 0xd6dc ), + SHC( 0x77cb ), + SHC( 0xd2ea ), + SHC( 0x7641 ), + SHC( 0xcf05 ), + SHC( 0x7497 ), + SHC( 0xcb2d ), + SHC( 0x72cc ), + SHC( 0xc764 ), + SHC( 0x70e2 ), + SHC( 0xc3aa ), + SHC( 0x6ed9 ), + SHC( 0xc000 ), + SHC( 0x6cb2 ), + SHC( 0xbc69 ), + SHC( 0x6a6d ), + SHC( 0xb8e4 ), + SHC( 0x680b ), + SHC( 0xb572 ), + SHC( 0x658c ), + SHC( 0xb215 ), + SHC( 0x62f2 ), + SHC( 0xaecd ), + SHC( 0x603c ), + SHC( 0xab9b ), + SHC( 0x5d6c ), + SHC( 0xa881 ), + SHC( 0x5a82 ), + SHC( 0xa57e ), + SHC( 0x577f ), + SHC( 0xa294 ), + SHC( 0x5465 ), + SHC( 0x9fc4 ), + SHC( 0x5133 ), + SHC( 0x9d0e ), + SHC( 0x4deb ), + SHC( 0x9a74 ), + SHC( 0x4a8e ), + SHC( 0x97f5 ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7fdd ), + SHC( 0xfa24 ), + SHC( 0x7f76 ), + SHC( 0xf44a ), + SHC( 0x7eca ), + SHC( 0xee77 ), + SHC( 0x7ddb ), + SHC( 0xe8ad ), + SHC( 0x7ca8 ), + SHC( 0xe2f0 ), + SHC( 0x7b31 ), + SHC( 0xdd42 ), + SHC( 0x7979 ), + SHC( 0xd7a7 ), + SHC( 0x777f ), + SHC( 0xd221 ), + SHC( 0x7545 ), + SHC( 0xccb5 ), + SHC( 0x72cc ), + SHC( 0xc764 ), + SHC( 0x7016 ), + SHC( 0xc231 ), + SHC( 0x6d23 ), + SHC( 0xbd1f ), + SHC( 0x69f5 ), + SHC( 0xb832 ), + SHC( 0x668f ), + SHC( 0xb36b ), + SHC( 0x62f2 ), + SHC( 0xaecd ), + SHC( 0x5f1f ), + SHC( 0xaa5a ), + SHC( 0x5b19 ), + SHC( 0xa616 ), + SHC( 0x56e2 ), + SHC( 0xa202 ), + SHC( 0x527d ), + SHC( 0x9e21 ), + SHC( 0x4deb ), + SHC( 0x9a74 ), + SHC( 0x4930 ), + SHC( 0x96fe ), + SHC( 0x444d ), + SHC( 0x93c0 ), + SHC( 0x3f45 ), + SHC( 0x90bc ), + SHC( 0x3a1c ), + SHC( 0x8df4 ), + SHC( 0x34d3 ), + SHC( 0x8b69 ), + SHC( 0x2f6e ), + SHC( 0x891d ), + SHC( 0x29ef ), + SHC( 0x8711 ), + SHC( 0x245a ), + SHC( 0x8546 ), + SHC( 0x1eb1 ), + SHC( 0x83bd ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7fc7 ), + SHC( 0xf877 ), + SHC( 0x7f1c ), + SHC( 0xf0f5 ), + SHC( 0x7e01 ), + SHC( 0xe980 ), + SHC( 0x7c76 ), + SHC( 0xe21f ), + SHC( 0x7a7d ), + SHC( 0xdad8 ), + SHC( 0x7816 ), + SHC( 0xd3b3 ), + SHC( 0x7545 ), + SHC( 0xccb5 ), + SHC( 0x720c ), + SHC( 0xc5e4 ), + SHC( 0x6e6e ), + SHC( 0xbf47 ), + SHC( 0x6a6d ), + SHC( 0xb8e4 ), + SHC( 0x660e ), + SHC( 0xb2bf ), + SHC( 0x6154 ), + SHC( 0xacdf ), + SHC( 0x5c44 ), + SHC( 0xa749 ), + SHC( 0x56e2 ), + SHC( 0xa202 ), + SHC( 0x5133 ), + SHC( 0x9d0e ), + SHC( 0x4b3c ), + SHC( 0x9873 ), + SHC( 0x4502 ), + SHC( 0x9433 ), + SHC( 0x3e8b ), + SHC( 0x9053 ), + SHC( 0x37dc ), + SHC( 0x8cd6 ), + SHC( 0x30fb ), + SHC( 0x89bf ), + SHC( 0x29ef ), + SHC( 0x8711 ), + SHC( 0x22be ), + SHC( 0x84cf ), + SHC( 0x1b6e ), + SHC( 0x82fa ), + SHC( 0x1406 ), + SHC( 0x8194 ), + SHC( 0x0c8b ), + SHC( 0x809e ), + SHC( 0x0506 ), + SHC( 0x801a ), + SHC( 0xfd7d ), + SHC( 0x8007 ), + SHC( 0xf5f6 ), + SHC( 0x8066 ), + SHC( 0xee77 ), + SHC( 0x8136 ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7fab ), + SHC( 0xf6cb ), + SHC( 0x7eac ), + SHC( 0xeda3 ), + SHC( 0x7d06 ), + SHC( 0xe492 ), + SHC( 0x7aba ), + SHC( 0xdba6 ), + SHC( 0x77cb ), + SHC( 0xd2ea ), + SHC( 0x743e ), + SHC( 0xca6a ), + SHC( 0x7016 ), + SHC( 0xc231 ), + SHC( 0x6b59 ), + SHC( 0xba4a ), + SHC( 0x660e ), + SHC( 0xb2bf ), + SHC( 0x603c ), + SHC( 0xab9b ), + SHC( 0x59ea ), + SHC( 0xa4e7 ), + SHC( 0x5321 ), + SHC( 0x9eac ), + SHC( 0x4be9 ), + SHC( 0x98f1 ), + SHC( 0x444d ), + SHC( 0x93c0 ), + SHC( 0x3c56 ), + SHC( 0x8f1e ), + SHC( 0x340f ), + SHC( 0x8b11 ), + SHC( 0x2b84 ), + SHC( 0x87a0 ), + SHC( 0x22be ), + SHC( 0x84cf ), + SHC( 0x19ca ), + SHC( 0x82a1 ), + SHC( 0x10b5 ), + SHC( 0x8119 ), + SHC( 0x0789 ), + SHC( 0x8039 ), + SHC( 0xfe54 ), + SHC( 0x8003 ), + SHC( 0xf520 ), + SHC( 0x8077 ), + SHC( 0xebfa ), + SHC( 0x8194 ), + SHC( 0xe2f0 ), + SHC( 0x8358 ), + SHC( 0xda0b ), + SHC( 0x85c2 ), + SHC( 0xd15a ), + SHC( 0x88ce ), + SHC( 0xc8e6 ), + SHC( 0x8c79 ), + SHC( 0xc0bb ), + SHC( 0x90bc ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7f89 ), + SHC( 0xf520 ), + SHC( 0x7e26 ), + SHC( 0xea53 ), + SHC( 0x7bda ), + SHC( 0xdfaf ), + SHC( 0x78a8 ), + SHC( 0xd546 ), + SHC( 0x7497 ), + SHC( 0xcb2d ), + SHC( 0x6fad ), + SHC( 0xc175 ), + SHC( 0x69f5 ), + SHC( 0xb832 ), + SHC( 0x6379 ), + SHC( 0xaf73 ), + SHC( 0x5c44 ), + SHC( 0xa749 ), + SHC( 0x5465 ), + SHC( 0x9fc4 ), + SHC( 0x4be9 ), + SHC( 0x98f1 ), + SHC( 0x42e1 ), + SHC( 0x92dd ), + SHC( 0x395c ), + SHC( 0x8d93 ), + SHC( 0x2f6e ), + SHC( 0x891d ), + SHC( 0x2528 ), + SHC( 0x8583 ), + SHC( 0x1a9c ), + SHC( 0x82cd ), + SHC( 0x0fe0 ), + SHC( 0x80fe ), + SHC( 0x0506 ), + SHC( 0x801a ), + SHC( 0xfa24 ), + SHC( 0x8023 ), + SHC( 0xef4b ), + SHC( 0x8119 ), + SHC( 0xe492 ), + SHC( 0x82fa ), + SHC( 0xda0b ), + SHC( 0x85c2 ), + SHC( 0xcfcb ), + SHC( 0x896d ), + SHC( 0xc5e4 ), + SHC( 0x8df4 ), + SHC( 0xbc69 ), + SHC( 0x934e ), + SHC( 0xb36b ), + SHC( 0x9971 ), + SHC( 0xaafa ), + SHC( 0xa052 ), + SHC( 0xa327 ), + SHC( 0xa7e4 ), + SHC( 0x9c01 ), + SHC( 0xb01a ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7f62 ), + SHC( 0xf375 ), + SHC( 0x7d8a ), + SHC( 0xe708 ), + SHC( 0x7a7d ), + SHC( 0xdad8 ), + SHC( 0x7641 ), + SHC( 0xcf05 ), + SHC( 0x70e2 ), + SHC( 0xc3aa ), + SHC( 0x6a6d ), + SHC( 0xb8e4 ), + SHC( 0x62f2 ), + SHC( 0xaecd ), + SHC( 0x5a82 ), + SHC( 0xa57e ), + SHC( 0x5133 ), + SHC( 0x9d0e ), + SHC( 0x471c ), + SHC( 0x9593 ), + SHC( 0x3c56 ), + SHC( 0x8f1e ), + SHC( 0x30fb ), + SHC( 0x89bf ), + SHC( 0x2528 ), + SHC( 0x8583 ), + SHC( 0x18f8 ), + SHC( 0x8276 ), + SHC( 0x0c8b ), + SHC( 0x809e ), + SHC( 0x0000 ), + SHC( 0x8000 ), + SHC( 0xf375 ), + SHC( 0x809e ), + SHC( 0xe708 ), + SHC( 0x8276 ), + SHC( 0xdad8 ), + SHC( 0x8583 ), + SHC( 0xcf05 ), + SHC( 0x89bf ), + SHC( 0xc3aa ), + SHC( 0x8f1e ), + SHC( 0xb8e4 ), + SHC( 0x9593 ), + SHC( 0xaecd ), + SHC( 0x9d0e ), + SHC( 0xa57e ), + SHC( 0xa57e ), + SHC( 0x9d0e ), + SHC( 0xaecd ), + SHC( 0x9593 ), + SHC( 0xb8e4 ), + SHC( 0x8f1e ), + SHC( 0xc3aa ), + SHC( 0x89bf ), + SHC( 0xcf05 ), + SHC( 0x8583 ), + SHC( 0xdad8 ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7f35 ), + SHC( 0xf1ca ), + SHC( 0x7cd8 ), + SHC( 0xe3c1 ), + SHC( 0x78ef ), + SHC( 0xd611 ), + SHC( 0x7387 ), + SHC( 0xc8e6 ), + SHC( 0x6cb2 ), + SHC( 0xbc69 ), + SHC( 0x6485 ), + SHC( 0xb0c2 ), + SHC( 0x5b19 ), + SHC( 0xa616 ), + SHC( 0x508d ), + SHC( 0x9c87 ), + SHC( 0x4502 ), + SHC( 0x9433 ), + SHC( 0x389c ), + SHC( 0x8d34 ), + SHC( 0x2b84 ), + SHC( 0x87a0 ), + SHC( 0x1de1 ), + SHC( 0x838a ), + SHC( 0x0fe0 ), + SHC( 0x80fe ), + SHC( 0x01ac ), + SHC( 0x8003 ), + SHC( 0xf375 ), + SHC( 0x809e ), + SHC( 0xe564 ), + SHC( 0x82cd ), + SHC( 0xd7a7 ), + SHC( 0x8687 ), + SHC( 0xca6a ), + SHC( 0x8bc2 ), + SHC( 0xbdd6 ), + SHC( 0x926e ), + SHC( 0xb215 ), + SHC( 0x9a74 ), + SHC( 0xa749 ), + SHC( 0xa3bc ), + SHC( 0x9d97 ), + SHC( 0xae27 ), + SHC( 0x951c ), + SHC( 0xb996 ), + SHC( 0x8df4 ), + SHC( 0xc5e4 ), + SHC( 0x8835 ), + SHC( 0xd2ea ), + SHC( 0x83f1 ), + SHC( 0xe07f ), + SHC( 0x8136 ), + SHC( 0xee77 ), + SHC( 0x800c ), + SHC( 0xfca7 ), + SHC( 0x8077 ), + SHC( 0x0ae0 ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7f02 ), + SHC( 0xf020 ), + SHC( 0x7c0f ), + SHC( 0xe07f ), + SHC( 0x7732 ), + SHC( 0xd15a ), + SHC( 0x707d ), + SHC( 0xc2ed ), + SHC( 0x680b ), + SHC( 0xb572 ), + SHC( 0x5dfe ), + SHC( 0xa91e ), + SHC( 0x527d ), + SHC( 0x9e21 ), + SHC( 0x45b6 ), + SHC( 0x94a7 ), + SHC( 0x37dc ), + SHC( 0x8cd6 ), + SHC( 0x2924 ), + SHC( 0x86cb ), + SHC( 0x19ca ), + SHC( 0x82a1 ), + SHC( 0x0a0a ), + SHC( 0x8066 ), + SHC( 0xfa24 ), + SHC( 0x8023 ), + SHC( 0xea53 ), + SHC( 0x81da ), + SHC( 0xdad8 ), + SHC( 0x8583 ), + SHC( 0xcbf1 ), + SHC( 0x8b11 ), + SHC( 0xbdd6 ), + SHC( 0x926e ), + SHC( 0xb0c2 ), + SHC( 0x9b7b ), + SHC( 0xa4e7 ), + SHC( 0xa616 ), + SHC( 0x9a74 ), + SHC( 0xb215 ), + SHC( 0x9192 ), + SHC( 0xbf47 ), + SHC( 0x8a66 ), + SHC( 0xcd7a ), + SHC( 0x850a ), + SHC( 0xdc74 ), + SHC( 0x8194 ), + SHC( 0xebfa ), + SHC( 0x8012 ), + SHC( 0xfbd0 ), + SHC( 0x808a ), + SHC( 0x0bb6 ), + SHC( 0x82fa ), + SHC( 0x1b6e ), + SHC( 0x8758 ), + SHC( 0x2aba ), + SHC( 0x8d93 ), + SHC( 0x395c ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7eca ), + SHC( 0xee77 ), + SHC( 0x7b31 ), + SHC( 0xdd42 ), + SHC( 0x7545 ), + SHC( 0xccb5 ), + SHC( 0x6d23 ), + SHC( 0xbd1f ), + SHC( 0x62f2 ), + SHC( 0xaecd ), + SHC( 0x56e2 ), + SHC( 0xa202 ), + SHC( 0x4930 ), + SHC( 0x96fe ), + SHC( 0x3a1c ), + SHC( 0x8df4 ), + SHC( 0x29ef ), + SHC( 0x8711 ), + SHC( 0x18f8 ), + SHC( 0x8276 ), + SHC( 0x0789 ), + SHC( 0x8039 ), + SHC( 0xf5f6 ), + SHC( 0x8066 ), + SHC( 0xe492 ), + SHC( 0x82fa ), + SHC( 0xd3b3 ), + SHC( 0x87ea ), + SHC( 0xc3aa ), + SHC( 0x8f1e ), + SHC( 0xb4c4 ), + SHC( 0x9873 ), + SHC( 0xa749 ), + SHC( 0xa3bc ), + SHC( 0x9b7b ), + SHC( 0xb0c2 ), + SHC( 0x9192 ), + SHC( 0xbf47 ), + SHC( 0x89bf ), + SHC( 0xcf05 ), + SHC( 0x8426 ), + SHC( 0xdfaf ), + SHC( 0x80e4 ), + SHC( 0xf0f5 ), + SHC( 0x8007 ), + SHC( 0x0283 ), + SHC( 0x8194 ), + SHC( 0x1406 ), + SHC( 0x8583 ), + SHC( 0x2528 ), + SHC( 0x8bc2 ), + SHC( 0x3596 ), + SHC( 0x9433 ), + SHC( 0x4502 ), + SHC( 0x9eac ), + SHC( 0x5321 ), + SHC( 0xaafa ), + SHC( 0x5fae ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7e8d ), + SHC( 0xecce ), + SHC( 0x7a3e ), + SHC( 0xda0b ), + SHC( 0x732a ), + SHC( 0xc824 ), + SHC( 0x697c ), + SHC( 0xb780 ), + SHC( 0x5d6c ), + SHC( 0xa881 ), + SHC( 0x4f3e ), + SHC( 0x9b7b ), + SHC( 0x3f45 ), + SHC( 0x90bc ), + SHC( 0x2ddf ), + SHC( 0x8881 ), + SHC( 0x1b6e ), + SHC( 0x82fa ), + SHC( 0x085f ), + SHC( 0x8047 ), + SHC( 0xf520 ), + SHC( 0x8077 ), + SHC( 0xe21f ), + SHC( 0x838a ), + SHC( 0xcfcb ), + SHC( 0x896d ), + SHC( 0xbe8e ), + SHC( 0x91ff ), + SHC( 0xaecd ), + SHC( 0x9d0e ), + SHC( 0xa0e1 ), + SHC( 0xaa5a ), + SHC( 0x951c ), + SHC( 0xb996 ), + SHC( 0x8bc2 ), + SHC( 0xca6a ), + SHC( 0x850a ), + SHC( 0xdc74 ), + SHC( 0x8119 ), + SHC( 0xef4b ), + SHC( 0x8007 ), + SHC( 0x0283 ), + SHC( 0x81da ), + SHC( 0x15ad ), + SHC( 0x8687 ), + SHC( 0x2859 ), + SHC( 0x8df4 ), + SHC( 0x3a1c ), + SHC( 0x97f5 ), + SHC( 0x4a8e ), + SHC( 0xa451 ), + SHC( 0x5951 ), + SHC( 0xb2bf ), + SHC( 0x660e ), + SHC( 0xc2ed ), + SHC( 0x707d ), + SHC( 0xd47c ), + SHC( 0x7860 ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7e4a ), + SHC( 0xeb27 ), + SHC( 0x7935 ), + SHC( 0xd6dc ), + SHC( 0x70e2 ), + SHC( 0xc3aa ), + SHC( 0x658c ), + SHC( 0xb215 ), + SHC( 0x577f ), + SHC( 0xa294 ), + SHC( 0x471c ), + SHC( 0x9593 ), + SHC( 0x34d3 ), + SHC( 0x8b69 ), + SHC( 0x2120 ), + SHC( 0x845d ), + SHC( 0x0c8b ), + SHC( 0x809e ), + SHC( 0xf7a1 ), + SHC( 0x8047 ), + SHC( 0xe2f0 ), + SHC( 0x8358 ), + SHC( 0xcf05 ), + SHC( 0x89bf ), + SHC( 0xbc69 ), + SHC( 0x934e ), + SHC( 0xab9b ), + SHC( 0x9fc4 ), + SHC( 0x9d0e ), + SHC( 0xaecd ), + SHC( 0x9127 ), + SHC( 0xc000 ), + SHC( 0x8835 ), + SHC( 0xd2ea ), + SHC( 0x8276 ), + SHC( 0xe708 ), + SHC( 0x8012 ), + SHC( 0xfbd0 ), + SHC( 0x8119 ), + SHC( 0x10b5 ), + SHC( 0x8583 ), + SHC( 0x2528 ), + SHC( 0x8d34 ), + SHC( 0x389c ), + SHC( 0x97f5 ), + SHC( 0x4a8e ), + SHC( 0xa57e ), + SHC( 0x5a82 ), + SHC( 0xb572 ), + SHC( 0x680b ), + SHC( 0xc764 ), + SHC( 0x72cc ), + SHC( 0xdad8 ), + SHC( 0x7a7d ), + SHC( 0xef4b ), + SHC( 0x7ee7 ), + SHC( 0x0430 ), + SHC( 0x7fee ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7e01 ), + SHC( 0xe980 ), + SHC( 0x7816 ), + SHC( 0xd3b3 ), + SHC( 0x6e6e ), + SHC( 0xbf47 ), + SHC( 0x6154 ), + SHC( 0xacdf ), + SHC( 0x5133 ), + SHC( 0x9d0e ), + SHC( 0x3e8b ), + SHC( 0x9053 ), + SHC( 0x29ef ), + SHC( 0x8711 ), + SHC( 0x1406 ), + SHC( 0x8194 ), + SHC( 0xfd7d ), + SHC( 0x8007 ), + SHC( 0xe708 ), + SHC( 0x8276 ), + SHC( 0xd15a ), + SHC( 0x88ce ), + SHC( 0xbd1f ), + SHC( 0x92dd ), + SHC( 0xaafa ), + SHC( 0xa052 ), + SHC( 0x9b7b ), + SHC( 0xb0c2 ), + SHC( 0x8f1e ), + SHC( 0xc3aa ), + SHC( 0x8644 ), + SHC( 0xd873 ), + SHC( 0x8136 ), + SHC( 0xee77 ), + SHC( 0x801a ), + SHC( 0x0506 ), + SHC( 0x82fa ), + SHC( 0x1b6e ), + SHC( 0x89bf ), + SHC( 0x30fb ), + SHC( 0x9433 ), + SHC( 0x4502 ), + SHC( 0xa202 ), + SHC( 0x56e2 ), + SHC( 0xb2bf ), + SHC( 0x660e ), + SHC( 0xc5e4 ), + SHC( 0x720c ), + SHC( 0xdad8 ), + SHC( 0x7a7d ), + SHC( 0xf0f5 ), + SHC( 0x7f1c ), + SHC( 0x0789 ), + SHC( 0x7fc7 ), + SHC( 0x1de1 ), + SHC( 0x7c76 ), + SHC( 0x334b ), + SHC( 0x7545 ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7db3 ), + SHC( 0xe7da ), + SHC( 0x76e3 ), + SHC( 0xd092 ), + SHC( 0x6bcd ), + SHC( 0xbafe ), + SHC( 0x5cd9 ), + SHC( 0xa7e4 ), + SHC( 0x4a8e ), + SHC( 0x97f5 ), + SHC( 0x3596 ), + SHC( 0x8bc2 ), + SHC( 0x1eb1 ), + SHC( 0x83bd ), + SHC( 0x06b2 ), + SHC( 0x802d ), + SHC( 0xee77 ), + SHC( 0x8136 ), + SHC( 0xd6dc ), + SHC( 0x86cb ), + SHC( 0xc0bb ), + SHC( 0x90bc ), + SHC( 0xacdf ), + SHC( 0x9eac ), + SHC( 0x9c01 ), + SHC( 0xb01a ), + SHC( 0x8eb9 ), + SHC( 0xc467 ), + SHC( 0x8583 ), + SHC( 0xdad8 ), + SHC( 0x80b4 ), + SHC( 0xf29f ), + SHC( 0x8077 ), + SHC( 0x0ae0 ), + SHC( 0x84cf ), + SHC( 0x22be ), + SHC( 0x8d93 ), + SHC( 0x395c ), + SHC( 0x9a74 ), + SHC( 0x4deb ), + SHC( 0xaafa ), + SHC( 0x5fae ), + SHC( 0xbe8e ), + SHC( 0x6e01 ), + SHC( 0xd47c ), + SHC( 0x7860 ), + SHC( 0xebfa ), + SHC( 0x7e6c ), + SHC( 0x0430 ), + SHC( 0x7fee ), + SHC( 0x1c3f ), + SHC( 0x7cd8 ), + SHC( 0x334b ), + SHC( 0x7545 ), + SHC( 0x4880 ), + SHC( 0x697c ), + SHC( 0x5b19 ), + SHC( 0x59ea ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7d5f ), + SHC( 0xe636 ), + SHC( 0x759a ), + SHC( 0xcd7a ), + SHC( 0x6902 ), + SHC( 0xb6d0 ), + SHC( 0x581c ), + SHC( 0xa327 ), + SHC( 0x4397 ), + SHC( 0x934e ), + SHC( 0x2c4d ), + SHC( 0x87ea ), + SHC( 0x1332 ), + SHC( 0x8173 ), + SHC( 0xf94e ), + SHC( 0x802d ), + SHC( 0xdfaf ), + SHC( 0x8426 ), + SHC( 0xc764 ), + SHC( 0x8d34 ), + SHC( 0xb16b ), + SHC( 0x9af7 ), + SHC( 0x9eac ), + SHC( 0xacdf ), + SHC( 0x8fea ), + SHC( 0xc231 ), + SHC( 0x85c2 ), + SHC( 0xda0b ), + SHC( 0x809e ), + SHC( 0xf375 ), + SHC( 0x80b4 ), + SHC( 0x0d61 ), + SHC( 0x8603 ), + SHC( 0x26c1 ), + SHC( 0x9053 ), + SHC( 0x3e8b ), + SHC( 0x9f37 ), + SHC( 0x53c3 ), + SHC( 0xb215 ), + SHC( 0x658c ), + SHC( 0xc824 ), + SHC( 0x732a ), + SHC( 0xe07f ), + SHC( 0x7c0f ), + SHC( 0xfa24 ), + SHC( 0x7fdd ), + SHC( 0x1406 ), + SHC( 0x7e6c ), + SHC( 0x2d16 ), + SHC( 0x77cb ), + SHC( 0x444d ), + SHC( 0x6c40 ), + SHC( 0x58b7 ), + SHC( 0x5c44 ), + SHC( 0x697c ), + SHC( 0x4880 ), + SHC( 0x75ee ), + SHC( 0x31c1 ), }; -const Word16 FFT_RotVector_640_fx[ 1240 ] = { - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7ff9 ), SHC( 0xfd7d ), SHC( 0x7fe6 ), SHC( 0xfafa ), SHC( 0x7fc7 ), SHC( 0xf877 ), - SHC( 0x7f9a ), SHC( 0xf5f6 ), SHC( 0x7f62 ), SHC( 0xf375 ), SHC( 0x7f1c ), SHC( 0xf0f5 ), SHC( 0x7eca ), SHC( 0xee77 ), - SHC( 0x7e6c ), SHC( 0xebfa ), SHC( 0x7e01 ), SHC( 0xe980 ), SHC( 0x7d8a ), SHC( 0xe708 ), SHC( 0x7d06 ), SHC( 0xe492 ), - SHC( 0x7c76 ), SHC( 0xe21f ), SHC( 0x7bda ), SHC( 0xdfaf ), SHC( 0x7b31 ), SHC( 0xdd42 ), SHC( 0x7a7d ), SHC( 0xdad8 ), - SHC( 0x79bc ), SHC( 0xd873 ), SHC( 0x78ef ), SHC( 0xd611 ), SHC( 0x7816 ), SHC( 0xd3b3 ), SHC( 0x7732 ), SHC( 0xd15a ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7fe6 ), SHC( 0xfafa ), SHC( 0x7f9a ), SHC( 0xf5f6 ), SHC( 0x7f1c ), SHC( 0xf0f5 ), - SHC( 0x7e6c ), SHC( 0xebfa ), SHC( 0x7d8a ), SHC( 0xe708 ), SHC( 0x7c76 ), SHC( 0xe21f ), SHC( 0x7b31 ), SHC( 0xdd42 ), - SHC( 0x79bc ), SHC( 0xd873 ), SHC( 0x7816 ), SHC( 0xd3b3 ), SHC( 0x7641 ), SHC( 0xcf05 ), SHC( 0x743e ), SHC( 0xca6a ), - SHC( 0x720c ), SHC( 0xc5e4 ), SHC( 0x6fad ), SHC( 0xc175 ), SHC( 0x6d23 ), SHC( 0xbd1f ), SHC( 0x6a6d ), SHC( 0xb8e4 ), - SHC( 0x678d ), SHC( 0xb4c4 ), SHC( 0x6485 ), SHC( 0xb0c2 ), SHC( 0x6154 ), SHC( 0xacdf ), SHC( 0x5dfe ), SHC( 0xa91e ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7fc7 ), SHC( 0xf877 ), SHC( 0x7f1c ), SHC( 0xf0f5 ), SHC( 0x7e01 ), SHC( 0xe980 ), - SHC( 0x7c76 ), SHC( 0xe21f ), SHC( 0x7a7d ), SHC( 0xdad8 ), SHC( 0x7816 ), SHC( 0xd3b3 ), SHC( 0x7545 ), SHC( 0xccb5 ), - SHC( 0x720c ), SHC( 0xc5e4 ), SHC( 0x6e6e ), SHC( 0xbf47 ), SHC( 0x6a6d ), SHC( 0xb8e4 ), SHC( 0x660e ), SHC( 0xb2bf ), - SHC( 0x6154 ), SHC( 0xacdf ), SHC( 0x5c44 ), SHC( 0xa749 ), SHC( 0x56e2 ), SHC( 0xa202 ), SHC( 0x5133 ), SHC( 0x9d0e ), - SHC( 0x4b3c ), SHC( 0x9873 ), SHC( 0x4502 ), SHC( 0x9433 ), SHC( 0x3e8b ), SHC( 0x9053 ), SHC( 0x37dc ), SHC( 0x8cd6 ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7f9a ), SHC( 0xf5f6 ), SHC( 0x7e6c ), SHC( 0xebfa ), SHC( 0x7c76 ), SHC( 0xe21f ), - SHC( 0x79bc ), SHC( 0xd873 ), SHC( 0x7641 ), SHC( 0xcf05 ), SHC( 0x720c ), SHC( 0xc5e4 ), SHC( 0x6d23 ), SHC( 0xbd1f ), - SHC( 0x678d ), SHC( 0xb4c4 ), SHC( 0x6154 ), SHC( 0xacdf ), SHC( 0x5a82 ), SHC( 0xa57e ), SHC( 0x5321 ), SHC( 0x9eac ), - SHC( 0x4b3c ), SHC( 0x9873 ), SHC( 0x42e1 ), SHC( 0x92dd ), SHC( 0x3a1c ), SHC( 0x8df4 ), SHC( 0x30fb ), SHC( 0x89bf ), - SHC( 0x278d ), SHC( 0x8644 ), SHC( 0x1de1 ), SHC( 0x838a ), SHC( 0x1406 ), SHC( 0x8194 ), SHC( 0x0a0a ), SHC( 0x8066 ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7f62 ), SHC( 0xf375 ), SHC( 0x7d8a ), SHC( 0xe708 ), SHC( 0x7a7d ), SHC( 0xdad8 ), - SHC( 0x7641 ), SHC( 0xcf05 ), SHC( 0x70e2 ), SHC( 0xc3aa ), SHC( 0x6a6d ), SHC( 0xb8e4 ), SHC( 0x62f2 ), SHC( 0xaecd ), - SHC( 0x5a82 ), SHC( 0xa57e ), SHC( 0x5133 ), SHC( 0x9d0e ), SHC( 0x471c ), SHC( 0x9593 ), SHC( 0x3c56 ), SHC( 0x8f1e ), - SHC( 0x30fb ), SHC( 0x89bf ), SHC( 0x2528 ), SHC( 0x8583 ), SHC( 0x18f8 ), SHC( 0x8276 ), SHC( 0x0c8b ), SHC( 0x809e ), - SHC( 0x0000 ), SHC( 0x8000 ), SHC( 0xf375 ), SHC( 0x809e ), SHC( 0xe708 ), SHC( 0x8276 ), SHC( 0xdad8 ), SHC( 0x8583 ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7f1c ), SHC( 0xf0f5 ), SHC( 0x7c76 ), SHC( 0xe21f ), SHC( 0x7816 ), SHC( 0xd3b3 ), - SHC( 0x720c ), SHC( 0xc5e4 ), SHC( 0x6a6d ), SHC( 0xb8e4 ), SHC( 0x6154 ), SHC( 0xacdf ), SHC( 0x56e2 ), SHC( 0xa202 ), - SHC( 0x4b3c ), SHC( 0x9873 ), SHC( 0x3e8b ), SHC( 0x9053 ), SHC( 0x30fb ), SHC( 0x89bf ), SHC( 0x22be ), SHC( 0x84cf ), - SHC( 0x1406 ), SHC( 0x8194 ), SHC( 0x0506 ), SHC( 0x801a ), SHC( 0xf5f6 ), SHC( 0x8066 ), SHC( 0xe708 ), SHC( 0x8276 ), - SHC( 0xd873 ), SHC( 0x8644 ), SHC( 0xca6a ), SHC( 0x8bc2 ), SHC( 0xbd1f ), SHC( 0x92dd ), SHC( 0xb0c2 ), SHC( 0x9b7b ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7eca ), SHC( 0xee77 ), SHC( 0x7b31 ), SHC( 0xdd42 ), SHC( 0x7545 ), SHC( 0xccb5 ), - SHC( 0x6d23 ), SHC( 0xbd1f ), SHC( 0x62f2 ), SHC( 0xaecd ), SHC( 0x56e2 ), SHC( 0xa202 ), SHC( 0x4930 ), SHC( 0x96fe ), - SHC( 0x3a1c ), SHC( 0x8df4 ), SHC( 0x29ef ), SHC( 0x8711 ), SHC( 0x18f8 ), SHC( 0x8276 ), SHC( 0x0789 ), SHC( 0x8039 ), - SHC( 0xf5f6 ), SHC( 0x8066 ), SHC( 0xe492 ), SHC( 0x82fa ), SHC( 0xd3b3 ), SHC( 0x87ea ), SHC( 0xc3aa ), SHC( 0x8f1e ), - SHC( 0xb4c4 ), SHC( 0x9873 ), SHC( 0xa749 ), SHC( 0xa3bc ), SHC( 0x9b7b ), SHC( 0xb0c2 ), SHC( 0x9192 ), SHC( 0xbf47 ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7e6c ), SHC( 0xebfa ), SHC( 0x79bc ), SHC( 0xd873 ), SHC( 0x720c ), SHC( 0xc5e4 ), - SHC( 0x678d ), SHC( 0xb4c4 ), SHC( 0x5a82 ), SHC( 0xa57e ), SHC( 0x4b3c ), SHC( 0x9873 ), SHC( 0x3a1c ), SHC( 0x8df4 ), - SHC( 0x278d ), SHC( 0x8644 ), SHC( 0x1406 ), SHC( 0x8194 ), SHC( 0x0000 ), SHC( 0x8000 ), SHC( 0xebfa ), SHC( 0x8194 ), - SHC( 0xd873 ), SHC( 0x8644 ), SHC( 0xc5e4 ), SHC( 0x8df4 ), SHC( 0xb4c4 ), SHC( 0x9873 ), SHC( 0xa57e ), SHC( 0xa57e ), - SHC( 0x9873 ), SHC( 0xb4c4 ), SHC( 0x8df4 ), SHC( 0xc5e4 ), SHC( 0x8644 ), SHC( 0xd873 ), SHC( 0x8194 ), SHC( 0xebfa ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7e01 ), SHC( 0xe980 ), SHC( 0x7816 ), SHC( 0xd3b3 ), SHC( 0x6e6e ), SHC( 0xbf47 ), - SHC( 0x6154 ), SHC( 0xacdf ), SHC( 0x5133 ), SHC( 0x9d0e ), SHC( 0x3e8b ), SHC( 0x9053 ), SHC( 0x29ef ), SHC( 0x8711 ), - SHC( 0x1406 ), SHC( 0x8194 ), SHC( 0xfd7d ), SHC( 0x8007 ), SHC( 0xe708 ), SHC( 0x8276 ), SHC( 0xd15a ), SHC( 0x88ce ), - SHC( 0xbd1f ), SHC( 0x92dd ), SHC( 0xaafa ), SHC( 0xa052 ), SHC( 0x9b7b ), SHC( 0xb0c2 ), SHC( 0x8f1e ), SHC( 0xc3aa ), - SHC( 0x8644 ), SHC( 0xd873 ), SHC( 0x8136 ), SHC( 0xee77 ), SHC( 0x801a ), SHC( 0x0506 ), SHC( 0x82fa ), SHC( 0x1b6e ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7d8a ), SHC( 0xe708 ), SHC( 0x7641 ), SHC( 0xcf05 ), SHC( 0x6a6d ), SHC( 0xb8e4 ), - SHC( 0x5a82 ), SHC( 0xa57e ), SHC( 0x471c ), SHC( 0x9593 ), SHC( 0x30fb ), SHC( 0x89bf ), SHC( 0x18f8 ), SHC( 0x8276 ), - SHC( 0x0000 ), SHC( 0x8000 ), SHC( 0xe708 ), SHC( 0x8276 ), SHC( 0xcf05 ), SHC( 0x89bf ), SHC( 0xb8e4 ), SHC( 0x9593 ), - SHC( 0xa57e ), SHC( 0xa57e ), SHC( 0x9593 ), SHC( 0xb8e4 ), SHC( 0x89bf ), SHC( 0xcf05 ), SHC( 0x8276 ), SHC( 0xe708 ), - SHC( 0x8000 ), SHC( 0x0000 ), SHC( 0x8276 ), SHC( 0x18f8 ), SHC( 0x89bf ), SHC( 0x30fb ), SHC( 0x9593 ), SHC( 0x471c ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7d06 ), SHC( 0xe492 ), SHC( 0x743e ), SHC( 0xca6a ), SHC( 0x660e ), SHC( 0xb2bf ), - SHC( 0x5321 ), SHC( 0x9eac ), SHC( 0x3c56 ), SHC( 0x8f1e ), SHC( 0x22be ), SHC( 0x84cf ), SHC( 0x0789 ), SHC( 0x8039 ), - SHC( 0xebfa ), SHC( 0x8194 ), SHC( 0xd15a ), SHC( 0x88ce ), SHC( 0xb8e4 ), SHC( 0x9593 ), SHC( 0xa3bc ), SHC( 0xa749 ), - SHC( 0x92dd ), SHC( 0xbd1f ), SHC( 0x8711 ), SHC( 0xd611 ), SHC( 0x80e4 ), SHC( 0xf0f5 ), SHC( 0x809e ), SHC( 0x0c8b ), - SHC( 0x8644 ), SHC( 0x278d ), SHC( 0x9192 ), SHC( 0x40b9 ), SHC( 0xa202 ), SHC( 0x56e2 ), SHC( 0xb6d0 ), SHC( 0x6902 ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7c76 ), SHC( 0xe21f ), SHC( 0x720c ), SHC( 0xc5e4 ), SHC( 0x6154 ), SHC( 0xacdf ), - SHC( 0x4b3c ), SHC( 0x9873 ), SHC( 0x30fb ), SHC( 0x89bf ), SHC( 0x1406 ), SHC( 0x8194 ), SHC( 0xf5f6 ), SHC( 0x8066 ), - SHC( 0xd873 ), SHC( 0x8644 ), SHC( 0xbd1f ), SHC( 0x92dd ), SHC( 0xa57e ), SHC( 0xa57e ), SHC( 0x92dd ), SHC( 0xbd1f ), - SHC( 0x8644 ), SHC( 0xd873 ), SHC( 0x8066 ), SHC( 0xf5f6 ), SHC( 0x8194 ), SHC( 0x1406 ), SHC( 0x89bf ), SHC( 0x30fb ), - SHC( 0x9873 ), SHC( 0x4b3c ), SHC( 0xacdf ), SHC( 0x6154 ), SHC( 0xc5e4 ), SHC( 0x720c ), SHC( 0xe21f ), SHC( 0x7c76 ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7bda ), SHC( 0xdfaf ), SHC( 0x6fad ), SHC( 0xc175 ), SHC( 0x5c44 ), SHC( 0xa749 ), - SHC( 0x42e1 ), SHC( 0x92dd ), SHC( 0x2528 ), SHC( 0x8583 ), SHC( 0x0506 ), SHC( 0x801a ), SHC( 0xe492 ), SHC( 0x82fa ), - SHC( 0xc5e4 ), SHC( 0x8df4 ), SHC( 0xaafa ), SHC( 0xa052 ), SHC( 0x9593 ), SHC( 0xb8e4 ), SHC( 0x8711 ), SHC( 0xd611 ), - SHC( 0x8066 ), SHC( 0xf5f6 ), SHC( 0x81ff ), SHC( 0x1680 ), SHC( 0x8bc2 ), SHC( 0x3596 ), SHC( 0x9d0e ), SHC( 0x5133 ), - SHC( 0xb4c4 ), SHC( 0x678d ), SHC( 0xd15a ), SHC( 0x7732 ), SHC( 0xf0f5 ), SHC( 0x7f1c ), SHC( 0x1189 ), SHC( 0x7eca ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7b31 ), SHC( 0xdd42 ), SHC( 0x6d23 ), SHC( 0xbd1f ), SHC( 0x56e2 ), SHC( 0xa202 ), - SHC( 0x3a1c ), SHC( 0x8df4 ), SHC( 0x18f8 ), SHC( 0x8276 ), SHC( 0xf5f6 ), SHC( 0x8066 ), SHC( 0xd3b3 ), SHC( 0x87ea ), - SHC( 0xb4c4 ), SHC( 0x9873 ), SHC( 0x9b7b ), SHC( 0xb0c2 ), SHC( 0x89bf ), SHC( 0xcf05 ), SHC( 0x80e4 ), SHC( 0xf0f5 ), - SHC( 0x8194 ), SHC( 0x1406 ), SHC( 0x8bc2 ), SHC( 0x3596 ), SHC( 0x9eac ), SHC( 0x5321 ), SHC( 0xb8e4 ), SHC( 0x6a6d ), - SHC( 0xd873 ), SHC( 0x79bc ), SHC( 0xfafa ), SHC( 0x7fe6 ), SHC( 0x1de1 ), SHC( 0x7c76 ), SHC( 0x3e8b ), SHC( 0x6fad ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7a7d ), SHC( 0xdad8 ), SHC( 0x6a6d ), SHC( 0xb8e4 ), SHC( 0x5133 ), SHC( 0x9d0e ), - SHC( 0x30fb ), SHC( 0x89bf ), SHC( 0x0c8b ), SHC( 0x809e ), SHC( 0xe708 ), SHC( 0x8276 ), SHC( 0xc3aa ), SHC( 0x8f1e ), - SHC( 0xa57e ), SHC( 0xa57e ), SHC( 0x8f1e ), SHC( 0xc3aa ), SHC( 0x8276 ), SHC( 0xe708 ), SHC( 0x809e ), SHC( 0x0c8b ), - SHC( 0x89bf ), SHC( 0x30fb ), SHC( 0x9d0e ), SHC( 0x5133 ), SHC( 0xb8e4 ), SHC( 0x6a6d ), SHC( 0xdad8 ), SHC( 0x7a7d ), - SHC( 0x0000 ), SHC( 0x7fff ), SHC( 0x2528 ), SHC( 0x7a7d ), SHC( 0x471c ), SHC( 0x6a6d ), SHC( 0x62f2 ), SHC( 0x5133 ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7ffe ), SHC( 0xfebf ), SHC( 0x7ff9 ), SHC( 0xfd7d ), SHC( 0x7ff1 ), SHC( 0xfc3c ), - SHC( 0x7fe6 ), SHC( 0xfafa ), SHC( 0x7fd8 ), SHC( 0xf9b9 ), SHC( 0x7fc7 ), SHC( 0xf877 ), SHC( 0x7fb2 ), SHC( 0xf736 ), - SHC( 0x7f9a ), SHC( 0xf5f6 ), SHC( 0x7f80 ), SHC( 0xf4b5 ), SHC( 0x7f62 ), SHC( 0xf375 ), SHC( 0x7f41 ), SHC( 0xf235 ), - SHC( 0x7f1c ), SHC( 0xf0f5 ), SHC( 0x7ef5 ), SHC( 0xefb6 ), SHC( 0x7eca ), SHC( 0xee77 ), SHC( 0x7e9d ), SHC( 0xed38 ), - SHC( 0x7e6c ), SHC( 0xebfa ), SHC( 0x7e38 ), SHC( 0xeabd ), SHC( 0x7e01 ), SHC( 0xe980 ), SHC( 0x7dc7 ), SHC( 0xe844 ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7ff1 ), SHC( 0xfc3c ), SHC( 0x7fc7 ), SHC( 0xf877 ), SHC( 0x7f80 ), SHC( 0xf4b5 ), - SHC( 0x7f1c ), SHC( 0xf0f5 ), SHC( 0x7e9d ), SHC( 0xed38 ), SHC( 0x7e01 ), SHC( 0xe980 ), SHC( 0x7d4a ), SHC( 0xe5cd ), - SHC( 0x7c76 ), SHC( 0xe21f ), SHC( 0x7b87 ), SHC( 0xde78 ), SHC( 0x7a7d ), SHC( 0xdad8 ), SHC( 0x7957 ), SHC( 0xd741 ), - SHC( 0x7816 ), SHC( 0xd3b3 ), SHC( 0x76bb ), SHC( 0xd02f ), SHC( 0x7545 ), SHC( 0xccb5 ), SHC( 0x73b5 ), SHC( 0xc946 ), - SHC( 0x720c ), SHC( 0xc5e4 ), SHC( 0x7049 ), SHC( 0xc28f ), SHC( 0x6e6e ), SHC( 0xbf47 ), SHC( 0x6c79 ), SHC( 0xbc0e ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7fd8 ), SHC( 0xf9b9 ), SHC( 0x7f62 ), SHC( 0xf375 ), SHC( 0x7e9d ), SHC( 0xed38 ), - SHC( 0x7d8a ), SHC( 0xe708 ), SHC( 0x7c29 ), SHC( 0xe0e7 ), SHC( 0x7a7d ), SHC( 0xdad8 ), SHC( 0x7884 ), SHC( 0xd4e1 ), - SHC( 0x7641 ), SHC( 0xcf05 ), SHC( 0x73b5 ), SHC( 0xc946 ), SHC( 0x70e2 ), SHC( 0xc3aa ), SHC( 0x6dca ), SHC( 0xbe32 ), - SHC( 0x6a6d ), SHC( 0xb8e4 ), SHC( 0x66cf ), SHC( 0xb3c1 ), SHC( 0x62f2 ), SHC( 0xaecd ), SHC( 0x5ed7 ), SHC( 0xaa0b ), - SHC( 0x5a82 ), SHC( 0xa57e ), SHC( 0x55f5 ), SHC( 0xa129 ), SHC( 0x5133 ), SHC( 0x9d0e ), SHC( 0x4c3f ), SHC( 0x9931 ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7fb2 ), SHC( 0xf736 ), SHC( 0x7eca ), SHC( 0xee77 ), SHC( 0x7d4a ), SHC( 0xe5cd ), - SHC( 0x7b31 ), SHC( 0xdd42 ), SHC( 0x7884 ), SHC( 0xd4e1 ), SHC( 0x7545 ), SHC( 0xccb5 ), SHC( 0x7179 ), SHC( 0xc4c6 ), - SHC( 0x6d23 ), SHC( 0xbd1f ), SHC( 0x6849 ), SHC( 0xb5c9 ), SHC( 0x62f2 ), SHC( 0xaecd ), SHC( 0x5d22 ), SHC( 0xa832 ), - SHC( 0x56e2 ), SHC( 0xa202 ), SHC( 0x503a ), SHC( 0x9c44 ), SHC( 0x4930 ), SHC( 0x96fe ), SHC( 0x41ce ), SHC( 0x9236 ), - SHC( 0x3a1c ), SHC( 0x8df4 ), SHC( 0x3224 ), SHC( 0x8a3b ), SHC( 0x29ef ), SHC( 0x8711 ), SHC( 0x2188 ), SHC( 0x8479 ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7f80 ), SHC( 0xf4b5 ), SHC( 0x7e01 ), SHC( 0xe980 ), SHC( 0x7b87 ), SHC( 0xde78 ), - SHC( 0x7816 ), SHC( 0xd3b3 ), SHC( 0x73b5 ), SHC( 0xc946 ), SHC( 0x6e6e ), SHC( 0xbf47 ), SHC( 0x6849 ), SHC( 0xb5c9 ), - SHC( 0x6154 ), SHC( 0xacdf ), SHC( 0x599d ), SHC( 0xa49c ), SHC( 0x5133 ), SHC( 0x9d0e ), SHC( 0x4827 ), SHC( 0x9647 ), - SHC( 0x3e8b ), SHC( 0x9053 ), SHC( 0x3471 ), SHC( 0x8b3d ), SHC( 0x29ef ), SHC( 0x8711 ), SHC( 0x1f19 ), SHC( 0x83d7 ), - SHC( 0x1406 ), SHC( 0x8194 ), SHC( 0x08ca ), SHC( 0x804e ), SHC( 0xfd7d ), SHC( 0x8007 ), SHC( 0xf235 ), SHC( 0x80bf ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7f41 ), SHC( 0xf235 ), SHC( 0x7d06 ), SHC( 0xe492 ), SHC( 0x7957 ), SHC( 0xd741 ), - SHC( 0x743e ), SHC( 0xca6a ), SHC( 0x6dca ), SHC( 0xbe32 ), SHC( 0x660e ), SHC( 0xb2bf ), SHC( 0x5d22 ), SHC( 0xa832 ), - SHC( 0x5321 ), SHC( 0x9eac ), SHC( 0x4827 ), SHC( 0x9647 ), SHC( 0x3c56 ), SHC( 0x8f1e ), SHC( 0x2fd1 ), SHC( 0x8945 ), - SHC( 0x22be ), SHC( 0x84cf ), SHC( 0x1543 ), SHC( 0x81c8 ), SHC( 0x0789 ), SHC( 0x8039 ), SHC( 0xf9b9 ), SHC( 0x8028 ), - SHC( 0xebfa ), SHC( 0x8194 ), SHC( 0xde78 ), SHC( 0x8479 ), SHC( 0xd15a ), SHC( 0x88ce ), SHC( 0xc4c6 ), SHC( 0x8e87 ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7ef5 ), SHC( 0xefb6 ), SHC( 0x7bda ), SHC( 0xdfaf ), SHC( 0x76bb ), SHC( 0xd02f ), - SHC( 0x6fad ), SHC( 0xc175 ), SHC( 0x66cf ), SHC( 0xb3c1 ), SHC( 0x5c44 ), SHC( 0xa749 ), SHC( 0x503a ), SHC( 0x9c44 ), - SHC( 0x42e1 ), SHC( 0x92dd ), SHC( 0x3471 ), SHC( 0x8b3d ), SHC( 0x2528 ), SHC( 0x8583 ), SHC( 0x1543 ), SHC( 0x81c8 ), - SHC( 0x0506 ), SHC( 0x801a ), SHC( 0xf4b5 ), SHC( 0x8080 ), SHC( 0xe492 ), SHC( 0x82fa ), SHC( 0xd4e1 ), SHC( 0x877c ), - SHC( 0xc5e4 ), SHC( 0x8df4 ), SHC( 0xb7d9 ), SHC( 0x9647 ), SHC( 0xaafa ), SHC( 0xa052 ), SHC( 0x9f7e ), SHC( 0xabec ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7e9d ), SHC( 0xed38 ), SHC( 0x7a7d ), SHC( 0xdad8 ), SHC( 0x73b5 ), SHC( 0xc946 ), - SHC( 0x6a6d ), SHC( 0xb8e4 ), SHC( 0x5ed7 ), SHC( 0xaa0b ), SHC( 0x5133 ), SHC( 0x9d0e ), SHC( 0x41ce ), SHC( 0x9236 ), - SHC( 0x30fb ), SHC( 0x89bf ), SHC( 0x1f19 ), SHC( 0x83d7 ), SHC( 0x0c8b ), SHC( 0x809e ), SHC( 0xf9b9 ), SHC( 0x8028 ), - SHC( 0xe708 ), SHC( 0x8276 ), SHC( 0xd4e1 ), SHC( 0x877c ), SHC( 0xc3aa ), SHC( 0x8f1e ), SHC( 0xb3c1 ), SHC( 0x9931 ), - SHC( 0xa57e ), SHC( 0xa57e ), SHC( 0x9931 ), SHC( 0xb3c1 ), SHC( 0x8f1e ), SHC( 0xc3aa ), SHC( 0x877c ), SHC( 0xd4e1 ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7e38 ), SHC( 0xeabd ), SHC( 0x78ef ), SHC( 0xd611 ), SHC( 0x7049 ), SHC( 0xc28f ), - SHC( 0x6485 ), SHC( 0xb0c2 ), SHC( 0x55f5 ), SHC( 0xa129 ), SHC( 0x4502 ), SHC( 0x9433 ), SHC( 0x3224 ), SHC( 0x8a3b ), - SHC( 0x1de1 ), SHC( 0x838a ), SHC( 0x08ca ), SHC( 0x804e ), SHC( 0xf375 ), SHC( 0x809e ), SHC( 0xde78 ), SHC( 0x8479 ), - SHC( 0xca6a ), SHC( 0x8bc2 ), SHC( 0xb7d9 ), SHC( 0x9647 ), SHC( 0xa749 ), SHC( 0xa3bc ), SHC( 0x9931 ), SHC( 0xb3c1 ), - SHC( 0x8df4 ), SHC( 0xc5e4 ), SHC( 0x85e2 ), SHC( 0xd9a5 ), SHC( 0x8136 ), SHC( 0xee77 ), SHC( 0x800f ), SHC( 0x03c4 ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7dc7 ), SHC( 0xe844 ), SHC( 0x7732 ), SHC( 0xd15a ), SHC( 0x6c79 ), SHC( 0xbc0e ), - SHC( 0x5dfe ), SHC( 0xa91e ), SHC( 0x4c3f ), SHC( 0x9931 ), SHC( 0x37dc ), SHC( 0x8cd6 ), SHC( 0x2188 ), SHC( 0x8479 ), - SHC( 0x0a0a ), SHC( 0x8066 ), SHC( 0xf235 ), SHC( 0x80bf ), SHC( 0xdad8 ), SHC( 0x8583 ), SHC( 0xc4c6 ), SHC( 0x8e87 ), - SHC( 0xb0c2 ), SHC( 0x9b7b ), SHC( 0x9f7e ), SHC( 0xabec ), SHC( 0x9192 ), SHC( 0xbf47 ), SHC( 0x877c ), SHC( 0xd4e1 ), - SHC( 0x8194 ), SHC( 0xebfa ), SHC( 0x800f ), SHC( 0x03c4 ), SHC( 0x82fa ), SHC( 0x1b6e ), SHC( 0x8a3b ), SHC( 0x3224 ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7d4a ), SHC( 0xe5cd ), SHC( 0x7545 ), SHC( 0xccb5 ), SHC( 0x6849 ), SHC( 0xb5c9 ), - SHC( 0x56e2 ), SHC( 0xa202 ), SHC( 0x41ce ), SHC( 0x9236 ), SHC( 0x29ef ), SHC( 0x8711 ), SHC( 0x104a ), SHC( 0x810b ), - SHC( 0xf5f6 ), SHC( 0x8066 ), SHC( 0xdc0d ), SHC( 0x8528 ), SHC( 0xc3aa ), SHC( 0x8f1e ), SHC( 0xadd5 ), SHC( 0x9ddc ), - SHC( 0x9b7b ), SHC( 0xb0c2 ), SHC( 0x8d63 ), SHC( 0xc703 ), SHC( 0x8426 ), SHC( 0xdfaf ), SHC( 0x8028 ), SHC( 0xf9b9 ), - SHC( 0x8194 ), SHC( 0x1406 ), SHC( 0x885b ), SHC( 0x2d7a ), SHC( 0x9433 ), SHC( 0x4502 ), SHC( 0xa49c ), SHC( 0x599d ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7cc0 ), SHC( 0xe358 ), SHC( 0x732a ), SHC( 0xc824 ), SHC( 0x63bc ), SHC( 0xafc6 ), - SHC( 0x4f3e ), SHC( 0x9b7b ), SHC( 0x36ba ), SHC( 0x8c4b ), SHC( 0x1b6e ), SHC( 0x82fa ), SHC( 0xfebf ), SHC( 0x8002 ), - SHC( 0xe21f ), SHC( 0x838a ), SHC( 0xc703 ), SHC( 0x8d63 ), SHC( 0xaecd ), SHC( 0x9d0e ), SHC( 0x9ab5 ), SHC( 0xb1c0 ), - SHC( 0x8bc2 ), SHC( 0xca6a ), SHC( 0x82b6 ), SHC( 0xe5cd ), SHC( 0x8007 ), SHC( 0x0283 ), SHC( 0x83d7 ), SHC( 0x1f19 ), - SHC( 0x8df4 ), SHC( 0x3a1c ), SHC( 0x9ddc ), SHC( 0x522b ), SHC( 0xb2bf ), SHC( 0x660e ), SHC( 0xcb8f ), SHC( 0x74c3 ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7c29 ), SHC( 0xe0e7 ), SHC( 0x70e2 ), SHC( 0xc3aa ), SHC( 0x5ed7 ), SHC( 0xaa0b ), - SHC( 0x471c ), SHC( 0x9593 ), SHC( 0x2b1f ), SHC( 0x877c ), SHC( 0x0c8b ), SHC( 0x809e ), SHC( 0xed38 ), SHC( 0x8163 ), - SHC( 0xcf05 ), SHC( 0x89bf ), SHC( 0xb3c1 ), SHC( 0x9931 ), SHC( 0x9d0e ), SHC( 0xaecd ), SHC( 0x8c4b ), SHC( 0xc946 ), - SHC( 0x8276 ), SHC( 0xe708 ), SHC( 0x8028 ), SHC( 0x0647 ), SHC( 0x8583 ), SHC( 0x2528 ), SHC( 0x9236 ), SHC( 0x41ce ), - SHC( 0xa57e ), SHC( 0x5a82 ), SHC( 0xbe32 ), SHC( 0x6dca ), SHC( 0xdad8 ), SHC( 0x7a7d ), SHC( 0xf9b9 ), SHC( 0x7fd8 ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7b87 ), SHC( 0xde78 ), SHC( 0x6e6e ), SHC( 0xbf47 ), SHC( 0x599d ), SHC( 0xa49c ), - SHC( 0x3e8b ), SHC( 0x9053 ), SHC( 0x1f19 ), SHC( 0x83d7 ), SHC( 0xfd7d ), SHC( 0x8007 ), SHC( 0xdc0d ), SHC( 0x8528 ), - SHC( 0xbd1f ), SHC( 0x92dd ), SHC( 0xa2de ), SHC( 0xa832 ), SHC( 0x8f1e ), SHC( 0xc3aa ), SHC( 0x8340 ), SHC( 0xe358 ), - SHC( 0x801a ), SHC( 0x0506 ), SHC( 0x85e2 ), SHC( 0x265b ), SHC( 0x9433 ), SHC( 0x4502 ), SHC( 0xaa0b ), SHC( 0x5ed7 ), - SHC( 0xc5e4 ), SHC( 0x720c ), SHC( 0xe5cd ), SHC( 0x7d4a ), SHC( 0x0789 ), SHC( 0x7fc7 ), SHC( 0x28bf ), SHC( 0x7957 ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7ad8 ), SHC( 0xdc0d ), SHC( 0x6bcd ), SHC( 0xbafe ), SHC( 0x5414 ), SHC( 0x9f7e ), - SHC( 0x3596 ), SHC( 0x8bc2 ), SHC( 0x12c8 ), SHC( 0x8163 ), SHC( 0xee77 ), SHC( 0x8136 ), SHC( 0xcb8f ), SHC( 0x8b3d ), - SHC( 0xacdf ), SHC( 0x9eac ), SHC( 0x94e1 ), SHC( 0xb9f0 ), SHC( 0x8583 ), SHC( 0xdad8 ), SHC( 0x8002 ), SHC( 0xfebf ), - SHC( 0x84cf ), SHC( 0x22be ), SHC( 0x9387 ), SHC( 0x43f2 ), SHC( 0xaafa ), SHC( 0x5fae ), SHC( 0xc946 ), SHC( 0x73b5 ), - SHC( 0xebfa ), SHC( 0x7e6c ), SHC( 0x104a ), SHC( 0x7ef5 ), SHC( 0x334b ), SHC( 0x7545 ), SHC( 0x522b ), SHC( 0x6224 ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7a1e ), SHC( 0xd9a5 ), SHC( 0x6902 ), SHC( 0xb6d0 ), SHC( 0x4e40 ), SHC( 0x9ab5 ), - SHC( 0x2c4d ), SHC( 0x87ea ), SHC( 0x0647 ), SHC( 0x8028 ), SHC( 0xdfaf ), SHC( 0x8426 ), SHC( 0xbc0e ), SHC( 0x9387 ), - SHC( 0x9eac ), SHC( 0xacdf ), SHC( 0x8a3b ), SHC( 0xcddc ), SHC( 0x809e ), SHC( 0xf375 ), SHC( 0x82b6 ), SHC( 0x1a33 ), - SHC( 0x9053 ), SHC( 0x3e8b ), SHC( 0xa832 ), SHC( 0x5d22 ), SHC( 0xc824 ), SHC( 0x732a ), SHC( 0xed38 ), SHC( 0x7e9d ), - SHC( 0x1406 ), SHC( 0x7e6c ), SHC( 0x38fd ), SHC( 0x729d ), SHC( 0x58b7 ), SHC( 0x5c44 ), SHC( 0x7049 ), SHC( 0x3d71 ), +const Word16 FFT_RotVector_640_fx[1240] = { + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7ff9 ), + SHC( 0xfd7d ), + SHC( 0x7fe6 ), + SHC( 0xfafa ), + SHC( 0x7fc7 ), + SHC( 0xf877 ), + SHC( 0x7f9a ), + SHC( 0xf5f6 ), + SHC( 0x7f62 ), + SHC( 0xf375 ), + SHC( 0x7f1c ), + SHC( 0xf0f5 ), + SHC( 0x7eca ), + SHC( 0xee77 ), + SHC( 0x7e6c ), + SHC( 0xebfa ), + SHC( 0x7e01 ), + SHC( 0xe980 ), + SHC( 0x7d8a ), + SHC( 0xe708 ), + SHC( 0x7d06 ), + SHC( 0xe492 ), + SHC( 0x7c76 ), + SHC( 0xe21f ), + SHC( 0x7bda ), + SHC( 0xdfaf ), + SHC( 0x7b31 ), + SHC( 0xdd42 ), + SHC( 0x7a7d ), + SHC( 0xdad8 ), + SHC( 0x79bc ), + SHC( 0xd873 ), + SHC( 0x78ef ), + SHC( 0xd611 ), + SHC( 0x7816 ), + SHC( 0xd3b3 ), + SHC( 0x7732 ), + SHC( 0xd15a ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7fe6 ), + SHC( 0xfafa ), + SHC( 0x7f9a ), + SHC( 0xf5f6 ), + SHC( 0x7f1c ), + SHC( 0xf0f5 ), + SHC( 0x7e6c ), + SHC( 0xebfa ), + SHC( 0x7d8a ), + SHC( 0xe708 ), + SHC( 0x7c76 ), + SHC( 0xe21f ), + SHC( 0x7b31 ), + SHC( 0xdd42 ), + SHC( 0x79bc ), + SHC( 0xd873 ), + SHC( 0x7816 ), + SHC( 0xd3b3 ), + SHC( 0x7641 ), + SHC( 0xcf05 ), + SHC( 0x743e ), + SHC( 0xca6a ), + SHC( 0x720c ), + SHC( 0xc5e4 ), + SHC( 0x6fad ), + SHC( 0xc175 ), + SHC( 0x6d23 ), + SHC( 0xbd1f ), + SHC( 0x6a6d ), + SHC( 0xb8e4 ), + SHC( 0x678d ), + SHC( 0xb4c4 ), + SHC( 0x6485 ), + SHC( 0xb0c2 ), + SHC( 0x6154 ), + SHC( 0xacdf ), + SHC( 0x5dfe ), + SHC( 0xa91e ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7fc7 ), + SHC( 0xf877 ), + SHC( 0x7f1c ), + SHC( 0xf0f5 ), + SHC( 0x7e01 ), + SHC( 0xe980 ), + SHC( 0x7c76 ), + SHC( 0xe21f ), + SHC( 0x7a7d ), + SHC( 0xdad8 ), + SHC( 0x7816 ), + SHC( 0xd3b3 ), + SHC( 0x7545 ), + SHC( 0xccb5 ), + SHC( 0x720c ), + SHC( 0xc5e4 ), + SHC( 0x6e6e ), + SHC( 0xbf47 ), + SHC( 0x6a6d ), + SHC( 0xb8e4 ), + SHC( 0x660e ), + SHC( 0xb2bf ), + SHC( 0x6154 ), + SHC( 0xacdf ), + SHC( 0x5c44 ), + SHC( 0xa749 ), + SHC( 0x56e2 ), + SHC( 0xa202 ), + SHC( 0x5133 ), + SHC( 0x9d0e ), + SHC( 0x4b3c ), + SHC( 0x9873 ), + SHC( 0x4502 ), + SHC( 0x9433 ), + SHC( 0x3e8b ), + SHC( 0x9053 ), + SHC( 0x37dc ), + SHC( 0x8cd6 ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7f9a ), + SHC( 0xf5f6 ), + SHC( 0x7e6c ), + SHC( 0xebfa ), + SHC( 0x7c76 ), + SHC( 0xe21f ), + SHC( 0x79bc ), + SHC( 0xd873 ), + SHC( 0x7641 ), + SHC( 0xcf05 ), + SHC( 0x720c ), + SHC( 0xc5e4 ), + SHC( 0x6d23 ), + SHC( 0xbd1f ), + SHC( 0x678d ), + SHC( 0xb4c4 ), + SHC( 0x6154 ), + SHC( 0xacdf ), + SHC( 0x5a82 ), + SHC( 0xa57e ), + SHC( 0x5321 ), + SHC( 0x9eac ), + SHC( 0x4b3c ), + SHC( 0x9873 ), + SHC( 0x42e1 ), + SHC( 0x92dd ), + SHC( 0x3a1c ), + SHC( 0x8df4 ), + SHC( 0x30fb ), + SHC( 0x89bf ), + SHC( 0x278d ), + SHC( 0x8644 ), + SHC( 0x1de1 ), + SHC( 0x838a ), + SHC( 0x1406 ), + SHC( 0x8194 ), + SHC( 0x0a0a ), + SHC( 0x8066 ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7f62 ), + SHC( 0xf375 ), + SHC( 0x7d8a ), + SHC( 0xe708 ), + SHC( 0x7a7d ), + SHC( 0xdad8 ), + SHC( 0x7641 ), + SHC( 0xcf05 ), + SHC( 0x70e2 ), + SHC( 0xc3aa ), + SHC( 0x6a6d ), + SHC( 0xb8e4 ), + SHC( 0x62f2 ), + SHC( 0xaecd ), + SHC( 0x5a82 ), + SHC( 0xa57e ), + SHC( 0x5133 ), + SHC( 0x9d0e ), + SHC( 0x471c ), + SHC( 0x9593 ), + SHC( 0x3c56 ), + SHC( 0x8f1e ), + SHC( 0x30fb ), + SHC( 0x89bf ), + SHC( 0x2528 ), + SHC( 0x8583 ), + SHC( 0x18f8 ), + SHC( 0x8276 ), + SHC( 0x0c8b ), + SHC( 0x809e ), + SHC( 0x0000 ), + SHC( 0x8000 ), + SHC( 0xf375 ), + SHC( 0x809e ), + SHC( 0xe708 ), + SHC( 0x8276 ), + SHC( 0xdad8 ), + SHC( 0x8583 ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7f1c ), + SHC( 0xf0f5 ), + SHC( 0x7c76 ), + SHC( 0xe21f ), + SHC( 0x7816 ), + SHC( 0xd3b3 ), + SHC( 0x720c ), + SHC( 0xc5e4 ), + SHC( 0x6a6d ), + SHC( 0xb8e4 ), + SHC( 0x6154 ), + SHC( 0xacdf ), + SHC( 0x56e2 ), + SHC( 0xa202 ), + SHC( 0x4b3c ), + SHC( 0x9873 ), + SHC( 0x3e8b ), + SHC( 0x9053 ), + SHC( 0x30fb ), + SHC( 0x89bf ), + SHC( 0x22be ), + SHC( 0x84cf ), + SHC( 0x1406 ), + SHC( 0x8194 ), + SHC( 0x0506 ), + SHC( 0x801a ), + SHC( 0xf5f6 ), + SHC( 0x8066 ), + SHC( 0xe708 ), + SHC( 0x8276 ), + SHC( 0xd873 ), + SHC( 0x8644 ), + SHC( 0xca6a ), + SHC( 0x8bc2 ), + SHC( 0xbd1f ), + SHC( 0x92dd ), + SHC( 0xb0c2 ), + SHC( 0x9b7b ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7eca ), + SHC( 0xee77 ), + SHC( 0x7b31 ), + SHC( 0xdd42 ), + SHC( 0x7545 ), + SHC( 0xccb5 ), + SHC( 0x6d23 ), + SHC( 0xbd1f ), + SHC( 0x62f2 ), + SHC( 0xaecd ), + SHC( 0x56e2 ), + SHC( 0xa202 ), + SHC( 0x4930 ), + SHC( 0x96fe ), + SHC( 0x3a1c ), + SHC( 0x8df4 ), + SHC( 0x29ef ), + SHC( 0x8711 ), + SHC( 0x18f8 ), + SHC( 0x8276 ), + SHC( 0x0789 ), + SHC( 0x8039 ), + SHC( 0xf5f6 ), + SHC( 0x8066 ), + SHC( 0xe492 ), + SHC( 0x82fa ), + SHC( 0xd3b3 ), + SHC( 0x87ea ), + SHC( 0xc3aa ), + SHC( 0x8f1e ), + SHC( 0xb4c4 ), + SHC( 0x9873 ), + SHC( 0xa749 ), + SHC( 0xa3bc ), + SHC( 0x9b7b ), + SHC( 0xb0c2 ), + SHC( 0x9192 ), + SHC( 0xbf47 ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7e6c ), + SHC( 0xebfa ), + SHC( 0x79bc ), + SHC( 0xd873 ), + SHC( 0x720c ), + SHC( 0xc5e4 ), + SHC( 0x678d ), + SHC( 0xb4c4 ), + SHC( 0x5a82 ), + SHC( 0xa57e ), + SHC( 0x4b3c ), + SHC( 0x9873 ), + SHC( 0x3a1c ), + SHC( 0x8df4 ), + SHC( 0x278d ), + SHC( 0x8644 ), + SHC( 0x1406 ), + SHC( 0x8194 ), + SHC( 0x0000 ), + SHC( 0x8000 ), + SHC( 0xebfa ), + SHC( 0x8194 ), + SHC( 0xd873 ), + SHC( 0x8644 ), + SHC( 0xc5e4 ), + SHC( 0x8df4 ), + SHC( 0xb4c4 ), + SHC( 0x9873 ), + SHC( 0xa57e ), + SHC( 0xa57e ), + SHC( 0x9873 ), + SHC( 0xb4c4 ), + SHC( 0x8df4 ), + SHC( 0xc5e4 ), + SHC( 0x8644 ), + SHC( 0xd873 ), + SHC( 0x8194 ), + SHC( 0xebfa ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7e01 ), + SHC( 0xe980 ), + SHC( 0x7816 ), + SHC( 0xd3b3 ), + SHC( 0x6e6e ), + SHC( 0xbf47 ), + SHC( 0x6154 ), + SHC( 0xacdf ), + SHC( 0x5133 ), + SHC( 0x9d0e ), + SHC( 0x3e8b ), + SHC( 0x9053 ), + SHC( 0x29ef ), + SHC( 0x8711 ), + SHC( 0x1406 ), + SHC( 0x8194 ), + SHC( 0xfd7d ), + SHC( 0x8007 ), + SHC( 0xe708 ), + SHC( 0x8276 ), + SHC( 0xd15a ), + SHC( 0x88ce ), + SHC( 0xbd1f ), + SHC( 0x92dd ), + SHC( 0xaafa ), + SHC( 0xa052 ), + SHC( 0x9b7b ), + SHC( 0xb0c2 ), + SHC( 0x8f1e ), + SHC( 0xc3aa ), + SHC( 0x8644 ), + SHC( 0xd873 ), + SHC( 0x8136 ), + SHC( 0xee77 ), + SHC( 0x801a ), + SHC( 0x0506 ), + SHC( 0x82fa ), + SHC( 0x1b6e ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7d8a ), + SHC( 0xe708 ), + SHC( 0x7641 ), + SHC( 0xcf05 ), + SHC( 0x6a6d ), + SHC( 0xb8e4 ), + SHC( 0x5a82 ), + SHC( 0xa57e ), + SHC( 0x471c ), + SHC( 0x9593 ), + SHC( 0x30fb ), + SHC( 0x89bf ), + SHC( 0x18f8 ), + SHC( 0x8276 ), + SHC( 0x0000 ), + SHC( 0x8000 ), + SHC( 0xe708 ), + SHC( 0x8276 ), + SHC( 0xcf05 ), + SHC( 0x89bf ), + SHC( 0xb8e4 ), + SHC( 0x9593 ), + SHC( 0xa57e ), + SHC( 0xa57e ), + SHC( 0x9593 ), + SHC( 0xb8e4 ), + SHC( 0x89bf ), + SHC( 0xcf05 ), + SHC( 0x8276 ), + SHC( 0xe708 ), + SHC( 0x8000 ), + SHC( 0x0000 ), + SHC( 0x8276 ), + SHC( 0x18f8 ), + SHC( 0x89bf ), + SHC( 0x30fb ), + SHC( 0x9593 ), + SHC( 0x471c ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7d06 ), + SHC( 0xe492 ), + SHC( 0x743e ), + SHC( 0xca6a ), + SHC( 0x660e ), + SHC( 0xb2bf ), + SHC( 0x5321 ), + SHC( 0x9eac ), + SHC( 0x3c56 ), + SHC( 0x8f1e ), + SHC( 0x22be ), + SHC( 0x84cf ), + SHC( 0x0789 ), + SHC( 0x8039 ), + SHC( 0xebfa ), + SHC( 0x8194 ), + SHC( 0xd15a ), + SHC( 0x88ce ), + SHC( 0xb8e4 ), + SHC( 0x9593 ), + SHC( 0xa3bc ), + SHC( 0xa749 ), + SHC( 0x92dd ), + SHC( 0xbd1f ), + SHC( 0x8711 ), + SHC( 0xd611 ), + SHC( 0x80e4 ), + SHC( 0xf0f5 ), + SHC( 0x809e ), + SHC( 0x0c8b ), + SHC( 0x8644 ), + SHC( 0x278d ), + SHC( 0x9192 ), + SHC( 0x40b9 ), + SHC( 0xa202 ), + SHC( 0x56e2 ), + SHC( 0xb6d0 ), + SHC( 0x6902 ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7c76 ), + SHC( 0xe21f ), + SHC( 0x720c ), + SHC( 0xc5e4 ), + SHC( 0x6154 ), + SHC( 0xacdf ), + SHC( 0x4b3c ), + SHC( 0x9873 ), + SHC( 0x30fb ), + SHC( 0x89bf ), + SHC( 0x1406 ), + SHC( 0x8194 ), + SHC( 0xf5f6 ), + SHC( 0x8066 ), + SHC( 0xd873 ), + SHC( 0x8644 ), + SHC( 0xbd1f ), + SHC( 0x92dd ), + SHC( 0xa57e ), + SHC( 0xa57e ), + SHC( 0x92dd ), + SHC( 0xbd1f ), + SHC( 0x8644 ), + SHC( 0xd873 ), + SHC( 0x8066 ), + SHC( 0xf5f6 ), + SHC( 0x8194 ), + SHC( 0x1406 ), + SHC( 0x89bf ), + SHC( 0x30fb ), + SHC( 0x9873 ), + SHC( 0x4b3c ), + SHC( 0xacdf ), + SHC( 0x6154 ), + SHC( 0xc5e4 ), + SHC( 0x720c ), + SHC( 0xe21f ), + SHC( 0x7c76 ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7bda ), + SHC( 0xdfaf ), + SHC( 0x6fad ), + SHC( 0xc175 ), + SHC( 0x5c44 ), + SHC( 0xa749 ), + SHC( 0x42e1 ), + SHC( 0x92dd ), + SHC( 0x2528 ), + SHC( 0x8583 ), + SHC( 0x0506 ), + SHC( 0x801a ), + SHC( 0xe492 ), + SHC( 0x82fa ), + SHC( 0xc5e4 ), + SHC( 0x8df4 ), + SHC( 0xaafa ), + SHC( 0xa052 ), + SHC( 0x9593 ), + SHC( 0xb8e4 ), + SHC( 0x8711 ), + SHC( 0xd611 ), + SHC( 0x8066 ), + SHC( 0xf5f6 ), + SHC( 0x81ff ), + SHC( 0x1680 ), + SHC( 0x8bc2 ), + SHC( 0x3596 ), + SHC( 0x9d0e ), + SHC( 0x5133 ), + SHC( 0xb4c4 ), + SHC( 0x678d ), + SHC( 0xd15a ), + SHC( 0x7732 ), + SHC( 0xf0f5 ), + SHC( 0x7f1c ), + SHC( 0x1189 ), + SHC( 0x7eca ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7b31 ), + SHC( 0xdd42 ), + SHC( 0x6d23 ), + SHC( 0xbd1f ), + SHC( 0x56e2 ), + SHC( 0xa202 ), + SHC( 0x3a1c ), + SHC( 0x8df4 ), + SHC( 0x18f8 ), + SHC( 0x8276 ), + SHC( 0xf5f6 ), + SHC( 0x8066 ), + SHC( 0xd3b3 ), + SHC( 0x87ea ), + SHC( 0xb4c4 ), + SHC( 0x9873 ), + SHC( 0x9b7b ), + SHC( 0xb0c2 ), + SHC( 0x89bf ), + SHC( 0xcf05 ), + SHC( 0x80e4 ), + SHC( 0xf0f5 ), + SHC( 0x8194 ), + SHC( 0x1406 ), + SHC( 0x8bc2 ), + SHC( 0x3596 ), + SHC( 0x9eac ), + SHC( 0x5321 ), + SHC( 0xb8e4 ), + SHC( 0x6a6d ), + SHC( 0xd873 ), + SHC( 0x79bc ), + SHC( 0xfafa ), + SHC( 0x7fe6 ), + SHC( 0x1de1 ), + SHC( 0x7c76 ), + SHC( 0x3e8b ), + SHC( 0x6fad ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7a7d ), + SHC( 0xdad8 ), + SHC( 0x6a6d ), + SHC( 0xb8e4 ), + SHC( 0x5133 ), + SHC( 0x9d0e ), + SHC( 0x30fb ), + SHC( 0x89bf ), + SHC( 0x0c8b ), + SHC( 0x809e ), + SHC( 0xe708 ), + SHC( 0x8276 ), + SHC( 0xc3aa ), + SHC( 0x8f1e ), + SHC( 0xa57e ), + SHC( 0xa57e ), + SHC( 0x8f1e ), + SHC( 0xc3aa ), + SHC( 0x8276 ), + SHC( 0xe708 ), + SHC( 0x809e ), + SHC( 0x0c8b ), + SHC( 0x89bf ), + SHC( 0x30fb ), + SHC( 0x9d0e ), + SHC( 0x5133 ), + SHC( 0xb8e4 ), + SHC( 0x6a6d ), + SHC( 0xdad8 ), + SHC( 0x7a7d ), + SHC( 0x0000 ), + SHC( 0x7fff ), + SHC( 0x2528 ), + SHC( 0x7a7d ), + SHC( 0x471c ), + SHC( 0x6a6d ), + SHC( 0x62f2 ), + SHC( 0x5133 ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7ffe ), + SHC( 0xfebf ), + SHC( 0x7ff9 ), + SHC( 0xfd7d ), + SHC( 0x7ff1 ), + SHC( 0xfc3c ), + SHC( 0x7fe6 ), + SHC( 0xfafa ), + SHC( 0x7fd8 ), + SHC( 0xf9b9 ), + SHC( 0x7fc7 ), + SHC( 0xf877 ), + SHC( 0x7fb2 ), + SHC( 0xf736 ), + SHC( 0x7f9a ), + SHC( 0xf5f6 ), + SHC( 0x7f80 ), + SHC( 0xf4b5 ), + SHC( 0x7f62 ), + SHC( 0xf375 ), + SHC( 0x7f41 ), + SHC( 0xf235 ), + SHC( 0x7f1c ), + SHC( 0xf0f5 ), + SHC( 0x7ef5 ), + SHC( 0xefb6 ), + SHC( 0x7eca ), + SHC( 0xee77 ), + SHC( 0x7e9d ), + SHC( 0xed38 ), + SHC( 0x7e6c ), + SHC( 0xebfa ), + SHC( 0x7e38 ), + SHC( 0xeabd ), + SHC( 0x7e01 ), + SHC( 0xe980 ), + SHC( 0x7dc7 ), + SHC( 0xe844 ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7ff1 ), + SHC( 0xfc3c ), + SHC( 0x7fc7 ), + SHC( 0xf877 ), + SHC( 0x7f80 ), + SHC( 0xf4b5 ), + SHC( 0x7f1c ), + SHC( 0xf0f5 ), + SHC( 0x7e9d ), + SHC( 0xed38 ), + SHC( 0x7e01 ), + SHC( 0xe980 ), + SHC( 0x7d4a ), + SHC( 0xe5cd ), + SHC( 0x7c76 ), + SHC( 0xe21f ), + SHC( 0x7b87 ), + SHC( 0xde78 ), + SHC( 0x7a7d ), + SHC( 0xdad8 ), + SHC( 0x7957 ), + SHC( 0xd741 ), + SHC( 0x7816 ), + SHC( 0xd3b3 ), + SHC( 0x76bb ), + SHC( 0xd02f ), + SHC( 0x7545 ), + SHC( 0xccb5 ), + SHC( 0x73b5 ), + SHC( 0xc946 ), + SHC( 0x720c ), + SHC( 0xc5e4 ), + SHC( 0x7049 ), + SHC( 0xc28f ), + SHC( 0x6e6e ), + SHC( 0xbf47 ), + SHC( 0x6c79 ), + SHC( 0xbc0e ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7fd8 ), + SHC( 0xf9b9 ), + SHC( 0x7f62 ), + SHC( 0xf375 ), + SHC( 0x7e9d ), + SHC( 0xed38 ), + SHC( 0x7d8a ), + SHC( 0xe708 ), + SHC( 0x7c29 ), + SHC( 0xe0e7 ), + SHC( 0x7a7d ), + SHC( 0xdad8 ), + SHC( 0x7884 ), + SHC( 0xd4e1 ), + SHC( 0x7641 ), + SHC( 0xcf05 ), + SHC( 0x73b5 ), + SHC( 0xc946 ), + SHC( 0x70e2 ), + SHC( 0xc3aa ), + SHC( 0x6dca ), + SHC( 0xbe32 ), + SHC( 0x6a6d ), + SHC( 0xb8e4 ), + SHC( 0x66cf ), + SHC( 0xb3c1 ), + SHC( 0x62f2 ), + SHC( 0xaecd ), + SHC( 0x5ed7 ), + SHC( 0xaa0b ), + SHC( 0x5a82 ), + SHC( 0xa57e ), + SHC( 0x55f5 ), + SHC( 0xa129 ), + SHC( 0x5133 ), + SHC( 0x9d0e ), + SHC( 0x4c3f ), + SHC( 0x9931 ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7fb2 ), + SHC( 0xf736 ), + SHC( 0x7eca ), + SHC( 0xee77 ), + SHC( 0x7d4a ), + SHC( 0xe5cd ), + SHC( 0x7b31 ), + SHC( 0xdd42 ), + SHC( 0x7884 ), + SHC( 0xd4e1 ), + SHC( 0x7545 ), + SHC( 0xccb5 ), + SHC( 0x7179 ), + SHC( 0xc4c6 ), + SHC( 0x6d23 ), + SHC( 0xbd1f ), + SHC( 0x6849 ), + SHC( 0xb5c9 ), + SHC( 0x62f2 ), + SHC( 0xaecd ), + SHC( 0x5d22 ), + SHC( 0xa832 ), + SHC( 0x56e2 ), + SHC( 0xa202 ), + SHC( 0x503a ), + SHC( 0x9c44 ), + SHC( 0x4930 ), + SHC( 0x96fe ), + SHC( 0x41ce ), + SHC( 0x9236 ), + SHC( 0x3a1c ), + SHC( 0x8df4 ), + SHC( 0x3224 ), + SHC( 0x8a3b ), + SHC( 0x29ef ), + SHC( 0x8711 ), + SHC( 0x2188 ), + SHC( 0x8479 ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7f80 ), + SHC( 0xf4b5 ), + SHC( 0x7e01 ), + SHC( 0xe980 ), + SHC( 0x7b87 ), + SHC( 0xde78 ), + SHC( 0x7816 ), + SHC( 0xd3b3 ), + SHC( 0x73b5 ), + SHC( 0xc946 ), + SHC( 0x6e6e ), + SHC( 0xbf47 ), + SHC( 0x6849 ), + SHC( 0xb5c9 ), + SHC( 0x6154 ), + SHC( 0xacdf ), + SHC( 0x599d ), + SHC( 0xa49c ), + SHC( 0x5133 ), + SHC( 0x9d0e ), + SHC( 0x4827 ), + SHC( 0x9647 ), + SHC( 0x3e8b ), + SHC( 0x9053 ), + SHC( 0x3471 ), + SHC( 0x8b3d ), + SHC( 0x29ef ), + SHC( 0x8711 ), + SHC( 0x1f19 ), + SHC( 0x83d7 ), + SHC( 0x1406 ), + SHC( 0x8194 ), + SHC( 0x08ca ), + SHC( 0x804e ), + SHC( 0xfd7d ), + SHC( 0x8007 ), + SHC( 0xf235 ), + SHC( 0x80bf ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7f41 ), + SHC( 0xf235 ), + SHC( 0x7d06 ), + SHC( 0xe492 ), + SHC( 0x7957 ), + SHC( 0xd741 ), + SHC( 0x743e ), + SHC( 0xca6a ), + SHC( 0x6dca ), + SHC( 0xbe32 ), + SHC( 0x660e ), + SHC( 0xb2bf ), + SHC( 0x5d22 ), + SHC( 0xa832 ), + SHC( 0x5321 ), + SHC( 0x9eac ), + SHC( 0x4827 ), + SHC( 0x9647 ), + SHC( 0x3c56 ), + SHC( 0x8f1e ), + SHC( 0x2fd1 ), + SHC( 0x8945 ), + SHC( 0x22be ), + SHC( 0x84cf ), + SHC( 0x1543 ), + SHC( 0x81c8 ), + SHC( 0x0789 ), + SHC( 0x8039 ), + SHC( 0xf9b9 ), + SHC( 0x8028 ), + SHC( 0xebfa ), + SHC( 0x8194 ), + SHC( 0xde78 ), + SHC( 0x8479 ), + SHC( 0xd15a ), + SHC( 0x88ce ), + SHC( 0xc4c6 ), + SHC( 0x8e87 ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7ef5 ), + SHC( 0xefb6 ), + SHC( 0x7bda ), + SHC( 0xdfaf ), + SHC( 0x76bb ), + SHC( 0xd02f ), + SHC( 0x6fad ), + SHC( 0xc175 ), + SHC( 0x66cf ), + SHC( 0xb3c1 ), + SHC( 0x5c44 ), + SHC( 0xa749 ), + SHC( 0x503a ), + SHC( 0x9c44 ), + SHC( 0x42e1 ), + SHC( 0x92dd ), + SHC( 0x3471 ), + SHC( 0x8b3d ), + SHC( 0x2528 ), + SHC( 0x8583 ), + SHC( 0x1543 ), + SHC( 0x81c8 ), + SHC( 0x0506 ), + SHC( 0x801a ), + SHC( 0xf4b5 ), + SHC( 0x8080 ), + SHC( 0xe492 ), + SHC( 0x82fa ), + SHC( 0xd4e1 ), + SHC( 0x877c ), + SHC( 0xc5e4 ), + SHC( 0x8df4 ), + SHC( 0xb7d9 ), + SHC( 0x9647 ), + SHC( 0xaafa ), + SHC( 0xa052 ), + SHC( 0x9f7e ), + SHC( 0xabec ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7e9d ), + SHC( 0xed38 ), + SHC( 0x7a7d ), + SHC( 0xdad8 ), + SHC( 0x73b5 ), + SHC( 0xc946 ), + SHC( 0x6a6d ), + SHC( 0xb8e4 ), + SHC( 0x5ed7 ), + SHC( 0xaa0b ), + SHC( 0x5133 ), + SHC( 0x9d0e ), + SHC( 0x41ce ), + SHC( 0x9236 ), + SHC( 0x30fb ), + SHC( 0x89bf ), + SHC( 0x1f19 ), + SHC( 0x83d7 ), + SHC( 0x0c8b ), + SHC( 0x809e ), + SHC( 0xf9b9 ), + SHC( 0x8028 ), + SHC( 0xe708 ), + SHC( 0x8276 ), + SHC( 0xd4e1 ), + SHC( 0x877c ), + SHC( 0xc3aa ), + SHC( 0x8f1e ), + SHC( 0xb3c1 ), + SHC( 0x9931 ), + SHC( 0xa57e ), + SHC( 0xa57e ), + SHC( 0x9931 ), + SHC( 0xb3c1 ), + SHC( 0x8f1e ), + SHC( 0xc3aa ), + SHC( 0x877c ), + SHC( 0xd4e1 ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7e38 ), + SHC( 0xeabd ), + SHC( 0x78ef ), + SHC( 0xd611 ), + SHC( 0x7049 ), + SHC( 0xc28f ), + SHC( 0x6485 ), + SHC( 0xb0c2 ), + SHC( 0x55f5 ), + SHC( 0xa129 ), + SHC( 0x4502 ), + SHC( 0x9433 ), + SHC( 0x3224 ), + SHC( 0x8a3b ), + SHC( 0x1de1 ), + SHC( 0x838a ), + SHC( 0x08ca ), + SHC( 0x804e ), + SHC( 0xf375 ), + SHC( 0x809e ), + SHC( 0xde78 ), + SHC( 0x8479 ), + SHC( 0xca6a ), + SHC( 0x8bc2 ), + SHC( 0xb7d9 ), + SHC( 0x9647 ), + SHC( 0xa749 ), + SHC( 0xa3bc ), + SHC( 0x9931 ), + SHC( 0xb3c1 ), + SHC( 0x8df4 ), + SHC( 0xc5e4 ), + SHC( 0x85e2 ), + SHC( 0xd9a5 ), + SHC( 0x8136 ), + SHC( 0xee77 ), + SHC( 0x800f ), + SHC( 0x03c4 ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7dc7 ), + SHC( 0xe844 ), + SHC( 0x7732 ), + SHC( 0xd15a ), + SHC( 0x6c79 ), + SHC( 0xbc0e ), + SHC( 0x5dfe ), + SHC( 0xa91e ), + SHC( 0x4c3f ), + SHC( 0x9931 ), + SHC( 0x37dc ), + SHC( 0x8cd6 ), + SHC( 0x2188 ), + SHC( 0x8479 ), + SHC( 0x0a0a ), + SHC( 0x8066 ), + SHC( 0xf235 ), + SHC( 0x80bf ), + SHC( 0xdad8 ), + SHC( 0x8583 ), + SHC( 0xc4c6 ), + SHC( 0x8e87 ), + SHC( 0xb0c2 ), + SHC( 0x9b7b ), + SHC( 0x9f7e ), + SHC( 0xabec ), + SHC( 0x9192 ), + SHC( 0xbf47 ), + SHC( 0x877c ), + SHC( 0xd4e1 ), + SHC( 0x8194 ), + SHC( 0xebfa ), + SHC( 0x800f ), + SHC( 0x03c4 ), + SHC( 0x82fa ), + SHC( 0x1b6e ), + SHC( 0x8a3b ), + SHC( 0x3224 ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7d4a ), + SHC( 0xe5cd ), + SHC( 0x7545 ), + SHC( 0xccb5 ), + SHC( 0x6849 ), + SHC( 0xb5c9 ), + SHC( 0x56e2 ), + SHC( 0xa202 ), + SHC( 0x41ce ), + SHC( 0x9236 ), + SHC( 0x29ef ), + SHC( 0x8711 ), + SHC( 0x104a ), + SHC( 0x810b ), + SHC( 0xf5f6 ), + SHC( 0x8066 ), + SHC( 0xdc0d ), + SHC( 0x8528 ), + SHC( 0xc3aa ), + SHC( 0x8f1e ), + SHC( 0xadd5 ), + SHC( 0x9ddc ), + SHC( 0x9b7b ), + SHC( 0xb0c2 ), + SHC( 0x8d63 ), + SHC( 0xc703 ), + SHC( 0x8426 ), + SHC( 0xdfaf ), + SHC( 0x8028 ), + SHC( 0xf9b9 ), + SHC( 0x8194 ), + SHC( 0x1406 ), + SHC( 0x885b ), + SHC( 0x2d7a ), + SHC( 0x9433 ), + SHC( 0x4502 ), + SHC( 0xa49c ), + SHC( 0x599d ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7cc0 ), + SHC( 0xe358 ), + SHC( 0x732a ), + SHC( 0xc824 ), + SHC( 0x63bc ), + SHC( 0xafc6 ), + SHC( 0x4f3e ), + SHC( 0x9b7b ), + SHC( 0x36ba ), + SHC( 0x8c4b ), + SHC( 0x1b6e ), + SHC( 0x82fa ), + SHC( 0xfebf ), + SHC( 0x8002 ), + SHC( 0xe21f ), + SHC( 0x838a ), + SHC( 0xc703 ), + SHC( 0x8d63 ), + SHC( 0xaecd ), + SHC( 0x9d0e ), + SHC( 0x9ab5 ), + SHC( 0xb1c0 ), + SHC( 0x8bc2 ), + SHC( 0xca6a ), + SHC( 0x82b6 ), + SHC( 0xe5cd ), + SHC( 0x8007 ), + SHC( 0x0283 ), + SHC( 0x83d7 ), + SHC( 0x1f19 ), + SHC( 0x8df4 ), + SHC( 0x3a1c ), + SHC( 0x9ddc ), + SHC( 0x522b ), + SHC( 0xb2bf ), + SHC( 0x660e ), + SHC( 0xcb8f ), + SHC( 0x74c3 ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7c29 ), + SHC( 0xe0e7 ), + SHC( 0x70e2 ), + SHC( 0xc3aa ), + SHC( 0x5ed7 ), + SHC( 0xaa0b ), + SHC( 0x471c ), + SHC( 0x9593 ), + SHC( 0x2b1f ), + SHC( 0x877c ), + SHC( 0x0c8b ), + SHC( 0x809e ), + SHC( 0xed38 ), + SHC( 0x8163 ), + SHC( 0xcf05 ), + SHC( 0x89bf ), + SHC( 0xb3c1 ), + SHC( 0x9931 ), + SHC( 0x9d0e ), + SHC( 0xaecd ), + SHC( 0x8c4b ), + SHC( 0xc946 ), + SHC( 0x8276 ), + SHC( 0xe708 ), + SHC( 0x8028 ), + SHC( 0x0647 ), + SHC( 0x8583 ), + SHC( 0x2528 ), + SHC( 0x9236 ), + SHC( 0x41ce ), + SHC( 0xa57e ), + SHC( 0x5a82 ), + SHC( 0xbe32 ), + SHC( 0x6dca ), + SHC( 0xdad8 ), + SHC( 0x7a7d ), + SHC( 0xf9b9 ), + SHC( 0x7fd8 ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7b87 ), + SHC( 0xde78 ), + SHC( 0x6e6e ), + SHC( 0xbf47 ), + SHC( 0x599d ), + SHC( 0xa49c ), + SHC( 0x3e8b ), + SHC( 0x9053 ), + SHC( 0x1f19 ), + SHC( 0x83d7 ), + SHC( 0xfd7d ), + SHC( 0x8007 ), + SHC( 0xdc0d ), + SHC( 0x8528 ), + SHC( 0xbd1f ), + SHC( 0x92dd ), + SHC( 0xa2de ), + SHC( 0xa832 ), + SHC( 0x8f1e ), + SHC( 0xc3aa ), + SHC( 0x8340 ), + SHC( 0xe358 ), + SHC( 0x801a ), + SHC( 0x0506 ), + SHC( 0x85e2 ), + SHC( 0x265b ), + SHC( 0x9433 ), + SHC( 0x4502 ), + SHC( 0xaa0b ), + SHC( 0x5ed7 ), + SHC( 0xc5e4 ), + SHC( 0x720c ), + SHC( 0xe5cd ), + SHC( 0x7d4a ), + SHC( 0x0789 ), + SHC( 0x7fc7 ), + SHC( 0x28bf ), + SHC( 0x7957 ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7ad8 ), + SHC( 0xdc0d ), + SHC( 0x6bcd ), + SHC( 0xbafe ), + SHC( 0x5414 ), + SHC( 0x9f7e ), + SHC( 0x3596 ), + SHC( 0x8bc2 ), + SHC( 0x12c8 ), + SHC( 0x8163 ), + SHC( 0xee77 ), + SHC( 0x8136 ), + SHC( 0xcb8f ), + SHC( 0x8b3d ), + SHC( 0xacdf ), + SHC( 0x9eac ), + SHC( 0x94e1 ), + SHC( 0xb9f0 ), + SHC( 0x8583 ), + SHC( 0xdad8 ), + SHC( 0x8002 ), + SHC( 0xfebf ), + SHC( 0x84cf ), + SHC( 0x22be ), + SHC( 0x9387 ), + SHC( 0x43f2 ), + SHC( 0xaafa ), + SHC( 0x5fae ), + SHC( 0xc946 ), + SHC( 0x73b5 ), + SHC( 0xebfa ), + SHC( 0x7e6c ), + SHC( 0x104a ), + SHC( 0x7ef5 ), + SHC( 0x334b ), + SHC( 0x7545 ), + SHC( 0x522b ), + SHC( 0x6224 ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7a1e ), + SHC( 0xd9a5 ), + SHC( 0x6902 ), + SHC( 0xb6d0 ), + SHC( 0x4e40 ), + SHC( 0x9ab5 ), + SHC( 0x2c4d ), + SHC( 0x87ea ), + SHC( 0x0647 ), + SHC( 0x8028 ), + SHC( 0xdfaf ), + SHC( 0x8426 ), + SHC( 0xbc0e ), + SHC( 0x9387 ), + SHC( 0x9eac ), + SHC( 0xacdf ), + SHC( 0x8a3b ), + SHC( 0xcddc ), + SHC( 0x809e ), + SHC( 0xf375 ), + SHC( 0x82b6 ), + SHC( 0x1a33 ), + SHC( 0x9053 ), + SHC( 0x3e8b ), + SHC( 0xa832 ), + SHC( 0x5d22 ), + SHC( 0xc824 ), + SHC( 0x732a ), + SHC( 0xed38 ), + SHC( 0x7e9d ), + SHC( 0x1406 ), + SHC( 0x7e6c ), + SHC( 0x38fd ), + SHC( 0x729d ), + SHC( 0x58b7 ), + SHC( 0x5c44 ), + SHC( 0x7049 ), + SHC( 0x3d71 ), }; -const Word16 FFT_RotVector_600_fx[ 1140 ] = { - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7ff8 ), SHC( 0xfd52 ), SHC( 0x7fe3 ), SHC( 0xfaa4 ), SHC( 0x7fbf ), SHC( 0xf7f7 ), - SHC( 0x7f8d ), SHC( 0xf54b ), SHC( 0x7f4c ), SHC( 0xf29f ), SHC( 0x7efd ), SHC( 0xeff6 ), SHC( 0x7ea0 ), SHC( 0xed4e ), - SHC( 0x7e35 ), SHC( 0xeaa8 ), SHC( 0x7dbb ), SHC( 0xe804 ), SHC( 0x7d33 ), SHC( 0xe564 ), SHC( 0x7c9e ), SHC( 0xe2c6 ), - SHC( 0x7bfa ), SHC( 0xe02b ), SHC( 0x7b48 ), SHC( 0xdd95 ), SHC( 0x7a89 ), SHC( 0xdb02 ), SHC( 0x79bc ), SHC( 0xd873 ), - SHC( 0x78e1 ), SHC( 0xd5e8 ), SHC( 0x77f8 ), SHC( 0xd362 ), SHC( 0x7702 ), SHC( 0xd0e2 ), SHC( 0x75ff ), SHC( 0xce66 ), - SHC( 0x74ef ), SHC( 0xcbf1 ), SHC( 0x73d1 ), SHC( 0xc981 ), SHC( 0x72a6 ), SHC( 0xc717 ), SHC( 0x716f ), SHC( 0xc4b3 ), - SHC( 0x702a ), SHC( 0xc256 ), SHC( 0x6ed9 ), SHC( 0xc000 ), SHC( 0x6d7c ), SHC( 0xbdb2 ), SHC( 0x6c12 ), SHC( 0xbb6b ), - SHC( 0x6a9d ), SHC( 0xb92b ), SHC( 0x691b ), SHC( 0xb6f3 ), SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7fe3 ), SHC( 0xfaa4 ), - SHC( 0x7f8d ), SHC( 0xf54b ), SHC( 0x7efd ), SHC( 0xeff6 ), SHC( 0x7e35 ), SHC( 0xeaa8 ), SHC( 0x7d33 ), SHC( 0xe564 ), - SHC( 0x7bfa ), SHC( 0xe02b ), SHC( 0x7a89 ), SHC( 0xdb02 ), SHC( 0x78e1 ), SHC( 0xd5e8 ), SHC( 0x7702 ), SHC( 0xd0e2 ), - SHC( 0x74ef ), SHC( 0xcbf1 ), SHC( 0x72a6 ), SHC( 0xc717 ), SHC( 0x702a ), SHC( 0xc256 ), SHC( 0x6d7c ), SHC( 0xbdb2 ), - SHC( 0x6a9d ), SHC( 0xb92b ), SHC( 0x678d ), SHC( 0xb4c4 ), SHC( 0x6450 ), SHC( 0xb07f ), SHC( 0x60e5 ), SHC( 0xac5d ), - SHC( 0x5d4e ), SHC( 0xa861 ), SHC( 0x598e ), SHC( 0xa48d ), SHC( 0x55a6 ), SHC( 0xa0e1 ), SHC( 0x5197 ), SHC( 0x9d60 ), - SHC( 0x4d63 ), SHC( 0x9a0c ), SHC( 0x490d ), SHC( 0x96e5 ), SHC( 0x4495 ), SHC( 0x93ee ), SHC( 0x4000 ), SHC( 0x9127 ), - SHC( 0x3b4d ), SHC( 0x8e91 ), SHC( 0x367f ), SHC( 0x8c2f ), SHC( 0x319a ), SHC( 0x8a01 ), SHC( 0x2c9e ), SHC( 0x8808 ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7fbf ), SHC( 0xf7f7 ), SHC( 0x7efd ), SHC( 0xeff6 ), SHC( 0x7dbb ), SHC( 0xe804 ), - SHC( 0x7bfa ), SHC( 0xe02b ), SHC( 0x79bc ), SHC( 0xd873 ), SHC( 0x7702 ), SHC( 0xd0e2 ), SHC( 0x73d1 ), SHC( 0xc981 ), - SHC( 0x702a ), SHC( 0xc256 ), SHC( 0x6c12 ), SHC( 0xbb6b ), SHC( 0x678d ), SHC( 0xb4c4 ), SHC( 0x62a0 ), SHC( 0xae69 ), - SHC( 0x5d4e ), SHC( 0xa861 ), SHC( 0x579f ), SHC( 0xa2b2 ), SHC( 0x5197 ), SHC( 0x9d60 ), SHC( 0x4b3c ), SHC( 0x9873 ), - SHC( 0x4495 ), SHC( 0x93ee ), SHC( 0x3daa ), SHC( 0x8fd6 ), SHC( 0x367f ), SHC( 0x8c2f ), SHC( 0x2f1e ), SHC( 0x88fe ), - SHC( 0x278d ), SHC( 0x8644 ), SHC( 0x1fd5 ), SHC( 0x8406 ), SHC( 0x17fc ), SHC( 0x8245 ), SHC( 0x100a ), SHC( 0x8103 ), - SHC( 0x0809 ), SHC( 0x8041 ), SHC( 0x0000 ), SHC( 0x8000 ), SHC( 0xf7f7 ), SHC( 0x8041 ), SHC( 0xeff6 ), SHC( 0x8103 ), - SHC( 0xe804 ), SHC( 0x8245 ), SHC( 0xe02b ), SHC( 0x8406 ), SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7f8d ), SHC( 0xf54b ), - SHC( 0x7e35 ), SHC( 0xeaa8 ), SHC( 0x7bfa ), SHC( 0xe02b ), SHC( 0x78e1 ), SHC( 0xd5e8 ), SHC( 0x74ef ), SHC( 0xcbf1 ), - SHC( 0x702a ), SHC( 0xc256 ), SHC( 0x6a9d ), SHC( 0xb92b ), SHC( 0x6450 ), SHC( 0xb07f ), SHC( 0x5d4e ), SHC( 0xa861 ), - SHC( 0x55a6 ), SHC( 0xa0e1 ), SHC( 0x4d63 ), SHC( 0x9a0c ), SHC( 0x4495 ), SHC( 0x93ee ), SHC( 0x3b4d ), SHC( 0x8e91 ), - SHC( 0x319a ), SHC( 0x8a01 ), SHC( 0x278d ), SHC( 0x8644 ), SHC( 0x1d3a ), SHC( 0x8362 ), SHC( 0x12b2 ), SHC( 0x8160 ), - SHC( 0x0809 ), SHC( 0x8041 ), SHC( 0xfd52 ), SHC( 0x8008 ), SHC( 0xf29f ), SHC( 0x80b4 ), SHC( 0xe804 ), SHC( 0x8245 ), - SHC( 0xdd95 ), SHC( 0x84b8 ), SHC( 0xd362 ), SHC( 0x8808 ), SHC( 0xc981 ), SHC( 0x8c2f ), SHC( 0xc000 ), SHC( 0x9127 ), - SHC( 0xb6f3 ), SHC( 0x96e5 ), SHC( 0xae69 ), SHC( 0x9d60 ), SHC( 0xa672 ), SHC( 0xa48d ), SHC( 0x9f1b ), SHC( 0xac5d ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7f4c ), SHC( 0xf29f ), SHC( 0x7d33 ), SHC( 0xe564 ), SHC( 0x79bc ), SHC( 0xd873 ), - SHC( 0x74ef ), SHC( 0xcbf1 ), SHC( 0x6ed9 ), SHC( 0xc000 ), SHC( 0x678d ), SHC( 0xb4c4 ), SHC( 0x5f1f ), SHC( 0xaa5a ), - SHC( 0x55a6 ), SHC( 0xa0e1 ), SHC( 0x4b3c ), SHC( 0x9873 ), SHC( 0x4000 ), SHC( 0x9127 ), SHC( 0x340f ), SHC( 0x8b11 ), - SHC( 0x278d ), SHC( 0x8644 ), SHC( 0x1a9c ), SHC( 0x82cd ), SHC( 0x0d61 ), SHC( 0x80b4 ), SHC( 0x0000 ), SHC( 0x8000 ), - SHC( 0xf29f ), SHC( 0x80b4 ), SHC( 0xe564 ), SHC( 0x82cd ), SHC( 0xd873 ), SHC( 0x8644 ), SHC( 0xcbf1 ), SHC( 0x8b11 ), - SHC( 0xc000 ), SHC( 0x9127 ), SHC( 0xb4c4 ), SHC( 0x9873 ), SHC( 0xaa5a ), SHC( 0xa0e1 ), SHC( 0xa0e1 ), SHC( 0xaa5a ), - SHC( 0x9873 ), SHC( 0xb4c4 ), SHC( 0x9127 ), SHC( 0xc000 ), SHC( 0x8b11 ), SHC( 0xcbf1 ), SHC( 0x8644 ), SHC( 0xd873 ), - SHC( 0x82cd ), SHC( 0xe564 ), SHC( 0x80b4 ), SHC( 0xf29f ), SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7efd ), SHC( 0xeff6 ), - SHC( 0x7bfa ), SHC( 0xe02b ), SHC( 0x7702 ), SHC( 0xd0e2 ), SHC( 0x702a ), SHC( 0xc256 ), SHC( 0x678d ), SHC( 0xb4c4 ), - SHC( 0x5d4e ), SHC( 0xa861 ), SHC( 0x5197 ), SHC( 0x9d60 ), SHC( 0x4495 ), SHC( 0x93ee ), SHC( 0x367f ), SHC( 0x8c2f ), - SHC( 0x278d ), SHC( 0x8644 ), SHC( 0x17fc ), SHC( 0x8245 ), SHC( 0x0809 ), SHC( 0x8041 ), SHC( 0xf7f7 ), SHC( 0x8041 ), - SHC( 0xe804 ), SHC( 0x8245 ), SHC( 0xd873 ), SHC( 0x8644 ), SHC( 0xc981 ), SHC( 0x8c2f ), SHC( 0xbb6b ), SHC( 0x93ee ), - SHC( 0xae69 ), SHC( 0x9d60 ), SHC( 0xa2b2 ), SHC( 0xa861 ), SHC( 0x9873 ), SHC( 0xb4c4 ), SHC( 0x8fd6 ), SHC( 0xc256 ), - SHC( 0x88fe ), SHC( 0xd0e2 ), SHC( 0x8406 ), SHC( 0xe02b ), SHC( 0x8103 ), SHC( 0xeff6 ), SHC( 0x8000 ), SHC( 0x0000 ), - SHC( 0x8103 ), SHC( 0x100a ), SHC( 0x8406 ), SHC( 0x1fd5 ), SHC( 0x88fe ), SHC( 0x2f1e ), SHC( 0x8fd6 ), SHC( 0x3daa ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7ea0 ), SHC( 0xed4e ), SHC( 0x7a89 ), SHC( 0xdb02 ), SHC( 0x73d1 ), SHC( 0xc981 ), - SHC( 0x6a9d ), SHC( 0xb92b ), SHC( 0x5f1f ), SHC( 0xaa5a ), SHC( 0x5197 ), SHC( 0x9d60 ), SHC( 0x424e ), SHC( 0x9284 ), - SHC( 0x319a ), SHC( 0x8a01 ), SHC( 0x1fd5 ), SHC( 0x8406 ), SHC( 0x0d61 ), SHC( 0x80b4 ), SHC( 0xfaa4 ), SHC( 0x801d ), - SHC( 0xe804 ), SHC( 0x8245 ), SHC( 0xd5e8 ), SHC( 0x871f ), SHC( 0xc4b3 ), SHC( 0x8e91 ), SHC( 0xb4c4 ), SHC( 0x9873 ), - SHC( 0xa672 ), SHC( 0xa48d ), SHC( 0x9a0c ), SHC( 0xb29d ), SHC( 0x8fd6 ), SHC( 0xc256 ), SHC( 0x8808 ), SHC( 0xd362 ), - SHC( 0x82cd ), SHC( 0xe564 ), SHC( 0x8041 ), SHC( 0xf7f7 ), SHC( 0x8073 ), SHC( 0x0ab5 ), SHC( 0x8362 ), SHC( 0x1d3a ), - SHC( 0x88fe ), SHC( 0x2f1e ), SHC( 0x9127 ), SHC( 0x4000 ), SHC( 0x9bb0 ), SHC( 0x4f81 ), SHC( 0xa861 ), SHC( 0x5d4e ), - SHC( 0xb6f3 ), SHC( 0x691b ), SHC( 0xc717 ), SHC( 0x72a6 ), SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7e35 ), SHC( 0xeaa8 ), - SHC( 0x78e1 ), SHC( 0xd5e8 ), SHC( 0x702a ), SHC( 0xc256 ), SHC( 0x6450 ), SHC( 0xb07f ), SHC( 0x55a6 ), SHC( 0xa0e1 ), - SHC( 0x4495 ), SHC( 0x93ee ), SHC( 0x319a ), SHC( 0x8a01 ), SHC( 0x1d3a ), SHC( 0x8362 ), SHC( 0x0809 ), SHC( 0x8041 ), - SHC( 0xf29f ), SHC( 0x80b4 ), SHC( 0xdd95 ), SHC( 0x84b8 ), SHC( 0xc981 ), SHC( 0x8c2f ), SHC( 0xb6f3 ), SHC( 0x96e5 ), - SHC( 0xa672 ), SHC( 0xa48d ), SHC( 0x9873 ), SHC( 0xb4c4 ), SHC( 0x8d5a ), SHC( 0xc717 ), SHC( 0x8577 ), SHC( 0xdb02 ), - SHC( 0x8103 ), SHC( 0xeff6 ), SHC( 0x801d ), SHC( 0x055c ), SHC( 0x82cd ), SHC( 0x1a9c ), SHC( 0x88fe ), SHC( 0x2f1e ), - SHC( 0x9284 ), SHC( 0x424e ), SHC( 0x9f1b ), SHC( 0x53a3 ), SHC( 0xae69 ), SHC( 0x62a0 ), SHC( 0xc000 ), SHC( 0x6ed9 ), - SHC( 0xd362 ), SHC( 0x77f8 ), SHC( 0xe804 ), SHC( 0x7dbb ), SHC( 0xfd52 ), SHC( 0x7ff8 ), SHC( 0x12b2 ), SHC( 0x7ea0 ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7dbb ), SHC( 0xe804 ), SHC( 0x7702 ), SHC( 0xd0e2 ), SHC( 0x6c12 ), SHC( 0xbb6b ), - SHC( 0x5d4e ), SHC( 0xa861 ), SHC( 0x4b3c ), SHC( 0x9873 ), SHC( 0x367f ), SHC( 0x8c2f ), SHC( 0x1fd5 ), SHC( 0x8406 ), - SHC( 0x0809 ), SHC( 0x8041 ), SHC( 0xeff6 ), SHC( 0x8103 ), SHC( 0xd873 ), SHC( 0x8644 ), SHC( 0xc256 ), SHC( 0x8fd6 ), - SHC( 0xae69 ), SHC( 0x9d60 ), SHC( 0x9d60 ), SHC( 0xae69 ), SHC( 0x8fd6 ), SHC( 0xc256 ), SHC( 0x8644 ), SHC( 0xd873 ), - SHC( 0x8103 ), SHC( 0xeff6 ), SHC( 0x8041 ), SHC( 0x0809 ), SHC( 0x8406 ), SHC( 0x1fd5 ), SHC( 0x8c2f ), SHC( 0x367f ), - SHC( 0x9873 ), SHC( 0x4b3c ), SHC( 0xa861 ), SHC( 0x5d4e ), SHC( 0xbb6b ), SHC( 0x6c12 ), SHC( 0xd0e2 ), SHC( 0x7702 ), - SHC( 0xe804 ), SHC( 0x7dbb ), SHC( 0x0000 ), SHC( 0x7fff ), SHC( 0x17fc ), SHC( 0x7dbb ), SHC( 0x2f1e ), SHC( 0x7702 ), - SHC( 0x4495 ), SHC( 0x6c12 ), SHC( 0x579f ), SHC( 0x5d4e ), SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7ffe ), SHC( 0xfea9 ), - SHC( 0x7ff8 ), SHC( 0xfd52 ), SHC( 0x7fef ), SHC( 0xfbfb ), SHC( 0x7fe3 ), SHC( 0xfaa4 ), SHC( 0x7fd3 ), SHC( 0xf94e ), - SHC( 0x7fbf ), SHC( 0xf7f7 ), SHC( 0x7fa8 ), SHC( 0xf6a1 ), SHC( 0x7f8d ), SHC( 0xf54b ), SHC( 0x7f6e ), SHC( 0xf3f5 ), - SHC( 0x7f4c ), SHC( 0xf29f ), SHC( 0x7f26 ), SHC( 0xf14a ), SHC( 0x7efd ), SHC( 0xeff6 ), SHC( 0x7ed0 ), SHC( 0xeea1 ), - SHC( 0x7ea0 ), SHC( 0xed4e ), SHC( 0x7e6c ), SHC( 0xebfa ), SHC( 0x7e35 ), SHC( 0xeaa8 ), SHC( 0x7dfa ), SHC( 0xe956 ), - SHC( 0x7dbb ), SHC( 0xe804 ), SHC( 0x7d79 ), SHC( 0xe6b4 ), SHC( 0x7d33 ), SHC( 0xe564 ), SHC( 0x7cea ), SHC( 0xe414 ), - SHC( 0x7c9e ), SHC( 0xe2c6 ), SHC( 0x7c4e ), SHC( 0xe178 ), SHC( 0x7bfa ), SHC( 0xe02b ), SHC( 0x7ba3 ), SHC( 0xdee0 ), - SHC( 0x7b48 ), SHC( 0xdd95 ), SHC( 0x7aea ), SHC( 0xdc4b ), SHC( 0x7a89 ), SHC( 0xdb02 ), SHC( 0x7a24 ), SHC( 0xd9ba ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7fef ), SHC( 0xfbfb ), SHC( 0x7fbf ), SHC( 0xf7f7 ), SHC( 0x7f6e ), SHC( 0xf3f5 ), - SHC( 0x7efd ), SHC( 0xeff6 ), SHC( 0x7e6c ), SHC( 0xebfa ), SHC( 0x7dbb ), SHC( 0xe804 ), SHC( 0x7cea ), SHC( 0xe414 ), - SHC( 0x7bfa ), SHC( 0xe02b ), SHC( 0x7aea ), SHC( 0xdc4b ), SHC( 0x79bc ), SHC( 0xd873 ), SHC( 0x786e ), SHC( 0xd4a5 ), - SHC( 0x7702 ), SHC( 0xd0e2 ), SHC( 0x7578 ), SHC( 0xcd2b ), SHC( 0x73d1 ), SHC( 0xc981 ), SHC( 0x720c ), SHC( 0xc5e4 ), - SHC( 0x702a ), SHC( 0xc256 ), SHC( 0x6e2c ), SHC( 0xbed8 ), SHC( 0x6c12 ), SHC( 0xbb6b ), SHC( 0x69dd ), SHC( 0xb80e ), - SHC( 0x678d ), SHC( 0xb4c4 ), SHC( 0x6523 ), SHC( 0xb18d ), SHC( 0x62a0 ), SHC( 0xae69 ), SHC( 0x6003 ), SHC( 0xab5b ), - SHC( 0x5d4e ), SHC( 0xa861 ), SHC( 0x5a82 ), SHC( 0xa57e ), SHC( 0x579f ), SHC( 0xa2b2 ), SHC( 0x54a5 ), SHC( 0x9ffd ), - SHC( 0x5197 ), SHC( 0x9d60 ), SHC( 0x4e73 ), SHC( 0x9add ), SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7fd3 ), SHC( 0xf94e ), - SHC( 0x7f4c ), SHC( 0xf29f ), SHC( 0x7e6c ), SHC( 0xebfa ), SHC( 0x7d33 ), SHC( 0xe564 ), SHC( 0x7ba3 ), SHC( 0xdee0 ), - SHC( 0x79bc ), SHC( 0xd873 ), SHC( 0x777f ), SHC( 0xd221 ), SHC( 0x74ef ), SHC( 0xcbf1 ), SHC( 0x720c ), SHC( 0xc5e4 ), - SHC( 0x6ed9 ), SHC( 0xc000 ), SHC( 0x6b59 ), SHC( 0xba4a ), SHC( 0x678d ), SHC( 0xb4c4 ), SHC( 0x6379 ), SHC( 0xaf73 ), - SHC( 0x5f1f ), SHC( 0xaa5a ), SHC( 0x5a82 ), SHC( 0xa57e ), SHC( 0x55a6 ), SHC( 0xa0e1 ), SHC( 0x508d ), SHC( 0x9c87 ), - SHC( 0x4b3c ), SHC( 0x9873 ), SHC( 0x45b6 ), SHC( 0x94a7 ), SHC( 0x4000 ), SHC( 0x9127 ), SHC( 0x3a1c ), SHC( 0x8df4 ), - SHC( 0x340f ), SHC( 0x8b11 ), SHC( 0x2ddf ), SHC( 0x8881 ), SHC( 0x278d ), SHC( 0x8644 ), SHC( 0x2120 ), SHC( 0x845d ), - SHC( 0x1a9c ), SHC( 0x82cd ), SHC( 0x1406 ), SHC( 0x8194 ), SHC( 0x0d61 ), SHC( 0x80b4 ), SHC( 0x06b2 ), SHC( 0x802d ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7fa8 ), SHC( 0xf6a1 ), SHC( 0x7ea0 ), SHC( 0xed4e ), SHC( 0x7cea ), SHC( 0xe414 ), - SHC( 0x7a89 ), SHC( 0xdb02 ), SHC( 0x777f ), SHC( 0xd221 ), SHC( 0x73d1 ), SHC( 0xc981 ), SHC( 0x6f83 ), SHC( 0xc12b ), - SHC( 0x6a9d ), SHC( 0xb92b ), SHC( 0x6523 ), SHC( 0xb18d ), SHC( 0x5f1f ), SHC( 0xaa5a ), SHC( 0x5898 ), SHC( 0xa39e ), - SHC( 0x5197 ), SHC( 0x9d60 ), SHC( 0x4a25 ), SHC( 0x97aa ), SHC( 0x424e ), SHC( 0x9284 ), SHC( 0x3a1c ), SHC( 0x8df4 ), - SHC( 0x319a ), SHC( 0x8a01 ), SHC( 0x28d3 ), SHC( 0x86b0 ), SHC( 0x1fd5 ), SHC( 0x8406 ), SHC( 0x16aa ), SHC( 0x8206 ), - SHC( 0x0d61 ), SHC( 0x80b4 ), SHC( 0x0405 ), SHC( 0x8011 ), SHC( 0xfaa4 ), SHC( 0x801d ), SHC( 0xf14a ), SHC( 0x80da ), - SHC( 0xe804 ), SHC( 0x8245 ), SHC( 0xdee0 ), SHC( 0x845d ), SHC( 0xd5e8 ), SHC( 0x871f ), SHC( 0xcd2b ), SHC( 0x8a88 ), - SHC( 0xc4b3 ), SHC( 0x8e91 ), SHC( 0xbc8d ), SHC( 0x9337 ), SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7f6e ), SHC( 0xf3f5 ), - SHC( 0x7dbb ), SHC( 0xe804 ), SHC( 0x7aea ), SHC( 0xdc4b ), SHC( 0x7702 ), SHC( 0xd0e2 ), SHC( 0x720c ), SHC( 0xc5e4 ), - SHC( 0x6c12 ), SHC( 0xbb6b ), SHC( 0x6523 ), SHC( 0xb18d ), SHC( 0x5d4e ), SHC( 0xa861 ), SHC( 0x54a5 ), SHC( 0x9ffd ), - SHC( 0x4b3c ), SHC( 0x9873 ), SHC( 0x4128 ), SHC( 0x91d4 ), SHC( 0x367f ), SHC( 0x8c2f ), SHC( 0x2b5b ), SHC( 0x8792 ), - SHC( 0x1fd5 ), SHC( 0x8406 ), SHC( 0x1406 ), SHC( 0x8194 ), SHC( 0x0809 ), SHC( 0x8041 ), SHC( 0xfbfb ), SHC( 0x8011 ), - SHC( 0xeff6 ), SHC( 0x8103 ), SHC( 0xe414 ), SHC( 0x8316 ), SHC( 0xd873 ), SHC( 0x8644 ), SHC( 0xcd2b ), SHC( 0x8a88 ), - SHC( 0xc256 ), SHC( 0x8fd6 ), SHC( 0xb80e ), SHC( 0x9623 ), SHC( 0xae69 ), SHC( 0x9d60 ), SHC( 0xa57e ), SHC( 0xa57e ), - SHC( 0x9d60 ), SHC( 0xae69 ), SHC( 0x9623 ), SHC( 0xb80e ), SHC( 0x8fd6 ), SHC( 0xc256 ), SHC( 0x8a88 ), SHC( 0xcd2b ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7f26 ), SHC( 0xf14a ), SHC( 0x7c9e ), SHC( 0xe2c6 ), SHC( 0x786e ), SHC( 0xd4a5 ), - SHC( 0x72a6 ), SHC( 0xc717 ), SHC( 0x6b59 ), SHC( 0xba4a ), SHC( 0x62a0 ), SHC( 0xae69 ), SHC( 0x5898 ), SHC( 0xa39e ), - SHC( 0x4d63 ), SHC( 0x9a0c ), SHC( 0x4128 ), SHC( 0x91d4 ), SHC( 0x340f ), SHC( 0x8b11 ), SHC( 0x2646 ), SHC( 0x85dc ), - SHC( 0x17fc ), SHC( 0x8245 ), SHC( 0x095f ), SHC( 0x8058 ), SHC( 0xfaa4 ), SHC( 0x801d ), SHC( 0xebfa ), SHC( 0x8194 ), - SHC( 0xdd95 ), SHC( 0x84b8 ), SHC( 0xcfa3 ), SHC( 0x897e ), SHC( 0xc256 ), SHC( 0x8fd6 ), SHC( 0xb5db ), SHC( 0x97aa ), - SHC( 0xaa5a ), SHC( 0xa0e1 ), SHC( 0x9ffd ), SHC( 0xab5b ), SHC( 0x96e5 ), SHC( 0xb6f3 ), SHC( 0x8f32 ), SHC( 0xc384 ), - SHC( 0x88fe ), SHC( 0xd0e2 ), SHC( 0x845d ), SHC( 0xdee0 ), SHC( 0x8160 ), SHC( 0xed4e ), SHC( 0x8011 ), SHC( 0xfbfb ), - SHC( 0x8073 ), SHC( 0x0ab5 ), SHC( 0x8287 ), SHC( 0x194c ), SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7ed0 ), SHC( 0xeea1 ), - SHC( 0x7b48 ), SHC( 0xdd95 ), SHC( 0x7578 ), SHC( 0xcd2b ), SHC( 0x6d7c ), SHC( 0xbdb2 ), SHC( 0x6379 ), SHC( 0xaf73 ), - SHC( 0x579f ), SHC( 0xa2b2 ), SHC( 0x4a25 ), SHC( 0x97aa ), SHC( 0x3b4d ), SHC( 0x8e91 ), SHC( 0x2b5b ), SHC( 0x8792 ), - SHC( 0x1a9c ), SHC( 0x82cd ), SHC( 0x095f ), SHC( 0x8058 ), SHC( 0xf7f7 ), SHC( 0x8041 ), SHC( 0xe6b4 ), SHC( 0x8287 ), - SHC( 0xd5e8 ), SHC( 0x871f ), SHC( 0xc5e4 ), SHC( 0x8df4 ), SHC( 0xb6f3 ), SHC( 0x96e5 ), SHC( 0xa95d ), SHC( 0xa1c8 ), - SHC( 0x9d60 ), SHC( 0xae69 ), SHC( 0x9337 ), SHC( 0xbc8d ), SHC( 0x8b11 ), SHC( 0xcbf1 ), SHC( 0x8516 ), SHC( 0xdc4b ), - SHC( 0x8160 ), SHC( 0xed4e ), SHC( 0x8002 ), SHC( 0xfea9 ), SHC( 0x8103 ), SHC( 0x100a ), SHC( 0x845d ), SHC( 0x2120 ), - SHC( 0x8a01 ), SHC( 0x319a ), SHC( 0x91d4 ), SHC( 0x4128 ), SHC( 0x9bb0 ), SHC( 0x4f81 ), SHC( 0xa768 ), SHC( 0x5c62 ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7e6c ), SHC( 0xebfa ), SHC( 0x79bc ), SHC( 0xd873 ), SHC( 0x720c ), SHC( 0xc5e4 ), - SHC( 0x678d ), SHC( 0xb4c4 ), SHC( 0x5a82 ), SHC( 0xa57e ), SHC( 0x4b3c ), SHC( 0x9873 ), SHC( 0x3a1c ), SHC( 0x8df4 ), - SHC( 0x278d ), SHC( 0x8644 ), SHC( 0x1406 ), SHC( 0x8194 ), SHC( 0x0000 ), SHC( 0x8000 ), SHC( 0xebfa ), SHC( 0x8194 ), - SHC( 0xd873 ), SHC( 0x8644 ), SHC( 0xc5e4 ), SHC( 0x8df4 ), SHC( 0xb4c4 ), SHC( 0x9873 ), SHC( 0xa57e ), SHC( 0xa57e ), - SHC( 0x9873 ), SHC( 0xb4c4 ), SHC( 0x8df4 ), SHC( 0xc5e4 ), SHC( 0x8644 ), SHC( 0xd873 ), SHC( 0x8194 ), SHC( 0xebfa ), - SHC( 0x8000 ), SHC( 0x0000 ), SHC( 0x8194 ), SHC( 0x1406 ), SHC( 0x8644 ), SHC( 0x278d ), SHC( 0x8df4 ), SHC( 0x3a1c ), - SHC( 0x9873 ), SHC( 0x4b3c ), SHC( 0xa57e ), SHC( 0x5a82 ), SHC( 0xb4c4 ), SHC( 0x678d ), SHC( 0xc5e4 ), SHC( 0x720c ), - SHC( 0xd873 ), SHC( 0x79bc ), SHC( 0xebfa ), SHC( 0x7e6c ), SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7dfa ), SHC( 0xe956 ), - SHC( 0x77f8 ), SHC( 0xd362 ), SHC( 0x6e2c ), SHC( 0xbed8 ), SHC( 0x60e5 ), SHC( 0xac5d ), SHC( 0x508d ), SHC( 0x9c87 ), - SHC( 0x3daa ), SHC( 0x8fd6 ), SHC( 0x28d3 ), SHC( 0x86b0 ), SHC( 0x12b2 ), SHC( 0x8160 ), SHC( 0xfbfb ), SHC( 0x8011 ), - SHC( 0xe564 ), SHC( 0x82cd ), SHC( 0xcfa3 ), SHC( 0x897e ), SHC( 0xbb6b ), SHC( 0x93ee ), SHC( 0xa95d ), SHC( 0xa1c8 ), - SHC( 0x9a0c ), SHC( 0xb29d ), SHC( 0x8df4 ), SHC( 0xc5e4 ), SHC( 0x8577 ), SHC( 0xdb02 ), SHC( 0x80da ), SHC( 0xf14a ), - SHC( 0x8041 ), SHC( 0x0809 ), SHC( 0x83b2 ), SHC( 0x1e88 ), SHC( 0x8b11 ), SHC( 0x340f ), SHC( 0x9623 ), SHC( 0x47f2 ), - SHC( 0xa48d ), SHC( 0x598e ), SHC( 0xb5db ), SHC( 0x6856 ), SHC( 0xc981 ), SHC( 0x73d1 ), SHC( 0xdee0 ), SHC( 0x7ba3 ), - SHC( 0xf54b ), SHC( 0x7f8d ), SHC( 0x0c0b ), SHC( 0x7f6e ), SHC( 0x226b ), SHC( 0x7b48 ), SHC( 0x37b5 ), SHC( 0x733d ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7d79 ), SHC( 0xe6b4 ), SHC( 0x75ff ), SHC( 0xce66 ), SHC( 0x69dd ), SHC( 0xb80e ), - SHC( 0x598e ), SHC( 0xa48d ), SHC( 0x45b6 ), SHC( 0x94a7 ), SHC( 0x2f1e ), SHC( 0x88fe ), SHC( 0x16aa ), SHC( 0x8206 ), - SHC( 0xfd52 ), SHC( 0x8008 ), SHC( 0xe414 ), SHC( 0x8316 ), SHC( 0xcbf1 ), SHC( 0x8b11 ), SHC( 0xb5db ), SHC( 0x97aa ), - SHC( 0xa2b2 ), SHC( 0xa861 ), SHC( 0x9337 ), SHC( 0xbc8d ), SHC( 0x8808 ), SHC( 0xd362 ), SHC( 0x8194 ), SHC( 0xebfa ), - SHC( 0x801d ), SHC( 0x055c ), SHC( 0x83b2 ), SHC( 0x1e88 ), SHC( 0x8c2f ), SHC( 0x367f ), SHC( 0x993e ), SHC( 0x4c51 ), - SHC( 0xaa5a ), SHC( 0x5f1f ), SHC( 0xbed8 ), SHC( 0x6e2c ), SHC( 0xd5e8 ), SHC( 0x78e1 ), SHC( 0xeea1 ), SHC( 0x7ed0 ), - SHC( 0x0809 ), SHC( 0x7fbf ), SHC( 0x2120 ), SHC( 0x7ba3 ), SHC( 0x38e9 ), SHC( 0x72a6 ), SHC( 0x4e73 ), SHC( 0x6523 ), - SHC( 0x60e5 ), SHC( 0x53a3 ), SHC( 0x6f83 ), SHC( 0x3ed5 ), +const Word16 FFT_RotVector_600_fx[1140] = { + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7ff8 ), + SHC( 0xfd52 ), + SHC( 0x7fe3 ), + SHC( 0xfaa4 ), + SHC( 0x7fbf ), + SHC( 0xf7f7 ), + SHC( 0x7f8d ), + SHC( 0xf54b ), + SHC( 0x7f4c ), + SHC( 0xf29f ), + SHC( 0x7efd ), + SHC( 0xeff6 ), + SHC( 0x7ea0 ), + SHC( 0xed4e ), + SHC( 0x7e35 ), + SHC( 0xeaa8 ), + SHC( 0x7dbb ), + SHC( 0xe804 ), + SHC( 0x7d33 ), + SHC( 0xe564 ), + SHC( 0x7c9e ), + SHC( 0xe2c6 ), + SHC( 0x7bfa ), + SHC( 0xe02b ), + SHC( 0x7b48 ), + SHC( 0xdd95 ), + SHC( 0x7a89 ), + SHC( 0xdb02 ), + SHC( 0x79bc ), + SHC( 0xd873 ), + SHC( 0x78e1 ), + SHC( 0xd5e8 ), + SHC( 0x77f8 ), + SHC( 0xd362 ), + SHC( 0x7702 ), + SHC( 0xd0e2 ), + SHC( 0x75ff ), + SHC( 0xce66 ), + SHC( 0x74ef ), + SHC( 0xcbf1 ), + SHC( 0x73d1 ), + SHC( 0xc981 ), + SHC( 0x72a6 ), + SHC( 0xc717 ), + SHC( 0x716f ), + SHC( 0xc4b3 ), + SHC( 0x702a ), + SHC( 0xc256 ), + SHC( 0x6ed9 ), + SHC( 0xc000 ), + SHC( 0x6d7c ), + SHC( 0xbdb2 ), + SHC( 0x6c12 ), + SHC( 0xbb6b ), + SHC( 0x6a9d ), + SHC( 0xb92b ), + SHC( 0x691b ), + SHC( 0xb6f3 ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7fe3 ), + SHC( 0xfaa4 ), + SHC( 0x7f8d ), + SHC( 0xf54b ), + SHC( 0x7efd ), + SHC( 0xeff6 ), + SHC( 0x7e35 ), + SHC( 0xeaa8 ), + SHC( 0x7d33 ), + SHC( 0xe564 ), + SHC( 0x7bfa ), + SHC( 0xe02b ), + SHC( 0x7a89 ), + SHC( 0xdb02 ), + SHC( 0x78e1 ), + SHC( 0xd5e8 ), + SHC( 0x7702 ), + SHC( 0xd0e2 ), + SHC( 0x74ef ), + SHC( 0xcbf1 ), + SHC( 0x72a6 ), + SHC( 0xc717 ), + SHC( 0x702a ), + SHC( 0xc256 ), + SHC( 0x6d7c ), + SHC( 0xbdb2 ), + SHC( 0x6a9d ), + SHC( 0xb92b ), + SHC( 0x678d ), + SHC( 0xb4c4 ), + SHC( 0x6450 ), + SHC( 0xb07f ), + SHC( 0x60e5 ), + SHC( 0xac5d ), + SHC( 0x5d4e ), + SHC( 0xa861 ), + SHC( 0x598e ), + SHC( 0xa48d ), + SHC( 0x55a6 ), + SHC( 0xa0e1 ), + SHC( 0x5197 ), + SHC( 0x9d60 ), + SHC( 0x4d63 ), + SHC( 0x9a0c ), + SHC( 0x490d ), + SHC( 0x96e5 ), + SHC( 0x4495 ), + SHC( 0x93ee ), + SHC( 0x4000 ), + SHC( 0x9127 ), + SHC( 0x3b4d ), + SHC( 0x8e91 ), + SHC( 0x367f ), + SHC( 0x8c2f ), + SHC( 0x319a ), + SHC( 0x8a01 ), + SHC( 0x2c9e ), + SHC( 0x8808 ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7fbf ), + SHC( 0xf7f7 ), + SHC( 0x7efd ), + SHC( 0xeff6 ), + SHC( 0x7dbb ), + SHC( 0xe804 ), + SHC( 0x7bfa ), + SHC( 0xe02b ), + SHC( 0x79bc ), + SHC( 0xd873 ), + SHC( 0x7702 ), + SHC( 0xd0e2 ), + SHC( 0x73d1 ), + SHC( 0xc981 ), + SHC( 0x702a ), + SHC( 0xc256 ), + SHC( 0x6c12 ), + SHC( 0xbb6b ), + SHC( 0x678d ), + SHC( 0xb4c4 ), + SHC( 0x62a0 ), + SHC( 0xae69 ), + SHC( 0x5d4e ), + SHC( 0xa861 ), + SHC( 0x579f ), + SHC( 0xa2b2 ), + SHC( 0x5197 ), + SHC( 0x9d60 ), + SHC( 0x4b3c ), + SHC( 0x9873 ), + SHC( 0x4495 ), + SHC( 0x93ee ), + SHC( 0x3daa ), + SHC( 0x8fd6 ), + SHC( 0x367f ), + SHC( 0x8c2f ), + SHC( 0x2f1e ), + SHC( 0x88fe ), + SHC( 0x278d ), + SHC( 0x8644 ), + SHC( 0x1fd5 ), + SHC( 0x8406 ), + SHC( 0x17fc ), + SHC( 0x8245 ), + SHC( 0x100a ), + SHC( 0x8103 ), + SHC( 0x0809 ), + SHC( 0x8041 ), + SHC( 0x0000 ), + SHC( 0x8000 ), + SHC( 0xf7f7 ), + SHC( 0x8041 ), + SHC( 0xeff6 ), + SHC( 0x8103 ), + SHC( 0xe804 ), + SHC( 0x8245 ), + SHC( 0xe02b ), + SHC( 0x8406 ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7f8d ), + SHC( 0xf54b ), + SHC( 0x7e35 ), + SHC( 0xeaa8 ), + SHC( 0x7bfa ), + SHC( 0xe02b ), + SHC( 0x78e1 ), + SHC( 0xd5e8 ), + SHC( 0x74ef ), + SHC( 0xcbf1 ), + SHC( 0x702a ), + SHC( 0xc256 ), + SHC( 0x6a9d ), + SHC( 0xb92b ), + SHC( 0x6450 ), + SHC( 0xb07f ), + SHC( 0x5d4e ), + SHC( 0xa861 ), + SHC( 0x55a6 ), + SHC( 0xa0e1 ), + SHC( 0x4d63 ), + SHC( 0x9a0c ), + SHC( 0x4495 ), + SHC( 0x93ee ), + SHC( 0x3b4d ), + SHC( 0x8e91 ), + SHC( 0x319a ), + SHC( 0x8a01 ), + SHC( 0x278d ), + SHC( 0x8644 ), + SHC( 0x1d3a ), + SHC( 0x8362 ), + SHC( 0x12b2 ), + SHC( 0x8160 ), + SHC( 0x0809 ), + SHC( 0x8041 ), + SHC( 0xfd52 ), + SHC( 0x8008 ), + SHC( 0xf29f ), + SHC( 0x80b4 ), + SHC( 0xe804 ), + SHC( 0x8245 ), + SHC( 0xdd95 ), + SHC( 0x84b8 ), + SHC( 0xd362 ), + SHC( 0x8808 ), + SHC( 0xc981 ), + SHC( 0x8c2f ), + SHC( 0xc000 ), + SHC( 0x9127 ), + SHC( 0xb6f3 ), + SHC( 0x96e5 ), + SHC( 0xae69 ), + SHC( 0x9d60 ), + SHC( 0xa672 ), + SHC( 0xa48d ), + SHC( 0x9f1b ), + SHC( 0xac5d ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7f4c ), + SHC( 0xf29f ), + SHC( 0x7d33 ), + SHC( 0xe564 ), + SHC( 0x79bc ), + SHC( 0xd873 ), + SHC( 0x74ef ), + SHC( 0xcbf1 ), + SHC( 0x6ed9 ), + SHC( 0xc000 ), + SHC( 0x678d ), + SHC( 0xb4c4 ), + SHC( 0x5f1f ), + SHC( 0xaa5a ), + SHC( 0x55a6 ), + SHC( 0xa0e1 ), + SHC( 0x4b3c ), + SHC( 0x9873 ), + SHC( 0x4000 ), + SHC( 0x9127 ), + SHC( 0x340f ), + SHC( 0x8b11 ), + SHC( 0x278d ), + SHC( 0x8644 ), + SHC( 0x1a9c ), + SHC( 0x82cd ), + SHC( 0x0d61 ), + SHC( 0x80b4 ), + SHC( 0x0000 ), + SHC( 0x8000 ), + SHC( 0xf29f ), + SHC( 0x80b4 ), + SHC( 0xe564 ), + SHC( 0x82cd ), + SHC( 0xd873 ), + SHC( 0x8644 ), + SHC( 0xcbf1 ), + SHC( 0x8b11 ), + SHC( 0xc000 ), + SHC( 0x9127 ), + SHC( 0xb4c4 ), + SHC( 0x9873 ), + SHC( 0xaa5a ), + SHC( 0xa0e1 ), + SHC( 0xa0e1 ), + SHC( 0xaa5a ), + SHC( 0x9873 ), + SHC( 0xb4c4 ), + SHC( 0x9127 ), + SHC( 0xc000 ), + SHC( 0x8b11 ), + SHC( 0xcbf1 ), + SHC( 0x8644 ), + SHC( 0xd873 ), + SHC( 0x82cd ), + SHC( 0xe564 ), + SHC( 0x80b4 ), + SHC( 0xf29f ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7efd ), + SHC( 0xeff6 ), + SHC( 0x7bfa ), + SHC( 0xe02b ), + SHC( 0x7702 ), + SHC( 0xd0e2 ), + SHC( 0x702a ), + SHC( 0xc256 ), + SHC( 0x678d ), + SHC( 0xb4c4 ), + SHC( 0x5d4e ), + SHC( 0xa861 ), + SHC( 0x5197 ), + SHC( 0x9d60 ), + SHC( 0x4495 ), + SHC( 0x93ee ), + SHC( 0x367f ), + SHC( 0x8c2f ), + SHC( 0x278d ), + SHC( 0x8644 ), + SHC( 0x17fc ), + SHC( 0x8245 ), + SHC( 0x0809 ), + SHC( 0x8041 ), + SHC( 0xf7f7 ), + SHC( 0x8041 ), + SHC( 0xe804 ), + SHC( 0x8245 ), + SHC( 0xd873 ), + SHC( 0x8644 ), + SHC( 0xc981 ), + SHC( 0x8c2f ), + SHC( 0xbb6b ), + SHC( 0x93ee ), + SHC( 0xae69 ), + SHC( 0x9d60 ), + SHC( 0xa2b2 ), + SHC( 0xa861 ), + SHC( 0x9873 ), + SHC( 0xb4c4 ), + SHC( 0x8fd6 ), + SHC( 0xc256 ), + SHC( 0x88fe ), + SHC( 0xd0e2 ), + SHC( 0x8406 ), + SHC( 0xe02b ), + SHC( 0x8103 ), + SHC( 0xeff6 ), + SHC( 0x8000 ), + SHC( 0x0000 ), + SHC( 0x8103 ), + SHC( 0x100a ), + SHC( 0x8406 ), + SHC( 0x1fd5 ), + SHC( 0x88fe ), + SHC( 0x2f1e ), + SHC( 0x8fd6 ), + SHC( 0x3daa ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7ea0 ), + SHC( 0xed4e ), + SHC( 0x7a89 ), + SHC( 0xdb02 ), + SHC( 0x73d1 ), + SHC( 0xc981 ), + SHC( 0x6a9d ), + SHC( 0xb92b ), + SHC( 0x5f1f ), + SHC( 0xaa5a ), + SHC( 0x5197 ), + SHC( 0x9d60 ), + SHC( 0x424e ), + SHC( 0x9284 ), + SHC( 0x319a ), + SHC( 0x8a01 ), + SHC( 0x1fd5 ), + SHC( 0x8406 ), + SHC( 0x0d61 ), + SHC( 0x80b4 ), + SHC( 0xfaa4 ), + SHC( 0x801d ), + SHC( 0xe804 ), + SHC( 0x8245 ), + SHC( 0xd5e8 ), + SHC( 0x871f ), + SHC( 0xc4b3 ), + SHC( 0x8e91 ), + SHC( 0xb4c4 ), + SHC( 0x9873 ), + SHC( 0xa672 ), + SHC( 0xa48d ), + SHC( 0x9a0c ), + SHC( 0xb29d ), + SHC( 0x8fd6 ), + SHC( 0xc256 ), + SHC( 0x8808 ), + SHC( 0xd362 ), + SHC( 0x82cd ), + SHC( 0xe564 ), + SHC( 0x8041 ), + SHC( 0xf7f7 ), + SHC( 0x8073 ), + SHC( 0x0ab5 ), + SHC( 0x8362 ), + SHC( 0x1d3a ), + SHC( 0x88fe ), + SHC( 0x2f1e ), + SHC( 0x9127 ), + SHC( 0x4000 ), + SHC( 0x9bb0 ), + SHC( 0x4f81 ), + SHC( 0xa861 ), + SHC( 0x5d4e ), + SHC( 0xb6f3 ), + SHC( 0x691b ), + SHC( 0xc717 ), + SHC( 0x72a6 ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7e35 ), + SHC( 0xeaa8 ), + SHC( 0x78e1 ), + SHC( 0xd5e8 ), + SHC( 0x702a ), + SHC( 0xc256 ), + SHC( 0x6450 ), + SHC( 0xb07f ), + SHC( 0x55a6 ), + SHC( 0xa0e1 ), + SHC( 0x4495 ), + SHC( 0x93ee ), + SHC( 0x319a ), + SHC( 0x8a01 ), + SHC( 0x1d3a ), + SHC( 0x8362 ), + SHC( 0x0809 ), + SHC( 0x8041 ), + SHC( 0xf29f ), + SHC( 0x80b4 ), + SHC( 0xdd95 ), + SHC( 0x84b8 ), + SHC( 0xc981 ), + SHC( 0x8c2f ), + SHC( 0xb6f3 ), + SHC( 0x96e5 ), + SHC( 0xa672 ), + SHC( 0xa48d ), + SHC( 0x9873 ), + SHC( 0xb4c4 ), + SHC( 0x8d5a ), + SHC( 0xc717 ), + SHC( 0x8577 ), + SHC( 0xdb02 ), + SHC( 0x8103 ), + SHC( 0xeff6 ), + SHC( 0x801d ), + SHC( 0x055c ), + SHC( 0x82cd ), + SHC( 0x1a9c ), + SHC( 0x88fe ), + SHC( 0x2f1e ), + SHC( 0x9284 ), + SHC( 0x424e ), + SHC( 0x9f1b ), + SHC( 0x53a3 ), + SHC( 0xae69 ), + SHC( 0x62a0 ), + SHC( 0xc000 ), + SHC( 0x6ed9 ), + SHC( 0xd362 ), + SHC( 0x77f8 ), + SHC( 0xe804 ), + SHC( 0x7dbb ), + SHC( 0xfd52 ), + SHC( 0x7ff8 ), + SHC( 0x12b2 ), + SHC( 0x7ea0 ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7dbb ), + SHC( 0xe804 ), + SHC( 0x7702 ), + SHC( 0xd0e2 ), + SHC( 0x6c12 ), + SHC( 0xbb6b ), + SHC( 0x5d4e ), + SHC( 0xa861 ), + SHC( 0x4b3c ), + SHC( 0x9873 ), + SHC( 0x367f ), + SHC( 0x8c2f ), + SHC( 0x1fd5 ), + SHC( 0x8406 ), + SHC( 0x0809 ), + SHC( 0x8041 ), + SHC( 0xeff6 ), + SHC( 0x8103 ), + SHC( 0xd873 ), + SHC( 0x8644 ), + SHC( 0xc256 ), + SHC( 0x8fd6 ), + SHC( 0xae69 ), + SHC( 0x9d60 ), + SHC( 0x9d60 ), + SHC( 0xae69 ), + SHC( 0x8fd6 ), + SHC( 0xc256 ), + SHC( 0x8644 ), + SHC( 0xd873 ), + SHC( 0x8103 ), + SHC( 0xeff6 ), + SHC( 0x8041 ), + SHC( 0x0809 ), + SHC( 0x8406 ), + SHC( 0x1fd5 ), + SHC( 0x8c2f ), + SHC( 0x367f ), + SHC( 0x9873 ), + SHC( 0x4b3c ), + SHC( 0xa861 ), + SHC( 0x5d4e ), + SHC( 0xbb6b ), + SHC( 0x6c12 ), + SHC( 0xd0e2 ), + SHC( 0x7702 ), + SHC( 0xe804 ), + SHC( 0x7dbb ), + SHC( 0x0000 ), + SHC( 0x7fff ), + SHC( 0x17fc ), + SHC( 0x7dbb ), + SHC( 0x2f1e ), + SHC( 0x7702 ), + SHC( 0x4495 ), + SHC( 0x6c12 ), + SHC( 0x579f ), + SHC( 0x5d4e ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7ffe ), + SHC( 0xfea9 ), + SHC( 0x7ff8 ), + SHC( 0xfd52 ), + SHC( 0x7fef ), + SHC( 0xfbfb ), + SHC( 0x7fe3 ), + SHC( 0xfaa4 ), + SHC( 0x7fd3 ), + SHC( 0xf94e ), + SHC( 0x7fbf ), + SHC( 0xf7f7 ), + SHC( 0x7fa8 ), + SHC( 0xf6a1 ), + SHC( 0x7f8d ), + SHC( 0xf54b ), + SHC( 0x7f6e ), + SHC( 0xf3f5 ), + SHC( 0x7f4c ), + SHC( 0xf29f ), + SHC( 0x7f26 ), + SHC( 0xf14a ), + SHC( 0x7efd ), + SHC( 0xeff6 ), + SHC( 0x7ed0 ), + SHC( 0xeea1 ), + SHC( 0x7ea0 ), + SHC( 0xed4e ), + SHC( 0x7e6c ), + SHC( 0xebfa ), + SHC( 0x7e35 ), + SHC( 0xeaa8 ), + SHC( 0x7dfa ), + SHC( 0xe956 ), + SHC( 0x7dbb ), + SHC( 0xe804 ), + SHC( 0x7d79 ), + SHC( 0xe6b4 ), + SHC( 0x7d33 ), + SHC( 0xe564 ), + SHC( 0x7cea ), + SHC( 0xe414 ), + SHC( 0x7c9e ), + SHC( 0xe2c6 ), + SHC( 0x7c4e ), + SHC( 0xe178 ), + SHC( 0x7bfa ), + SHC( 0xe02b ), + SHC( 0x7ba3 ), + SHC( 0xdee0 ), + SHC( 0x7b48 ), + SHC( 0xdd95 ), + SHC( 0x7aea ), + SHC( 0xdc4b ), + SHC( 0x7a89 ), + SHC( 0xdb02 ), + SHC( 0x7a24 ), + SHC( 0xd9ba ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7fef ), + SHC( 0xfbfb ), + SHC( 0x7fbf ), + SHC( 0xf7f7 ), + SHC( 0x7f6e ), + SHC( 0xf3f5 ), + SHC( 0x7efd ), + SHC( 0xeff6 ), + SHC( 0x7e6c ), + SHC( 0xebfa ), + SHC( 0x7dbb ), + SHC( 0xe804 ), + SHC( 0x7cea ), + SHC( 0xe414 ), + SHC( 0x7bfa ), + SHC( 0xe02b ), + SHC( 0x7aea ), + SHC( 0xdc4b ), + SHC( 0x79bc ), + SHC( 0xd873 ), + SHC( 0x786e ), + SHC( 0xd4a5 ), + SHC( 0x7702 ), + SHC( 0xd0e2 ), + SHC( 0x7578 ), + SHC( 0xcd2b ), + SHC( 0x73d1 ), + SHC( 0xc981 ), + SHC( 0x720c ), + SHC( 0xc5e4 ), + SHC( 0x702a ), + SHC( 0xc256 ), + SHC( 0x6e2c ), + SHC( 0xbed8 ), + SHC( 0x6c12 ), + SHC( 0xbb6b ), + SHC( 0x69dd ), + SHC( 0xb80e ), + SHC( 0x678d ), + SHC( 0xb4c4 ), + SHC( 0x6523 ), + SHC( 0xb18d ), + SHC( 0x62a0 ), + SHC( 0xae69 ), + SHC( 0x6003 ), + SHC( 0xab5b ), + SHC( 0x5d4e ), + SHC( 0xa861 ), + SHC( 0x5a82 ), + SHC( 0xa57e ), + SHC( 0x579f ), + SHC( 0xa2b2 ), + SHC( 0x54a5 ), + SHC( 0x9ffd ), + SHC( 0x5197 ), + SHC( 0x9d60 ), + SHC( 0x4e73 ), + SHC( 0x9add ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7fd3 ), + SHC( 0xf94e ), + SHC( 0x7f4c ), + SHC( 0xf29f ), + SHC( 0x7e6c ), + SHC( 0xebfa ), + SHC( 0x7d33 ), + SHC( 0xe564 ), + SHC( 0x7ba3 ), + SHC( 0xdee0 ), + SHC( 0x79bc ), + SHC( 0xd873 ), + SHC( 0x777f ), + SHC( 0xd221 ), + SHC( 0x74ef ), + SHC( 0xcbf1 ), + SHC( 0x720c ), + SHC( 0xc5e4 ), + SHC( 0x6ed9 ), + SHC( 0xc000 ), + SHC( 0x6b59 ), + SHC( 0xba4a ), + SHC( 0x678d ), + SHC( 0xb4c4 ), + SHC( 0x6379 ), + SHC( 0xaf73 ), + SHC( 0x5f1f ), + SHC( 0xaa5a ), + SHC( 0x5a82 ), + SHC( 0xa57e ), + SHC( 0x55a6 ), + SHC( 0xa0e1 ), + SHC( 0x508d ), + SHC( 0x9c87 ), + SHC( 0x4b3c ), + SHC( 0x9873 ), + SHC( 0x45b6 ), + SHC( 0x94a7 ), + SHC( 0x4000 ), + SHC( 0x9127 ), + SHC( 0x3a1c ), + SHC( 0x8df4 ), + SHC( 0x340f ), + SHC( 0x8b11 ), + SHC( 0x2ddf ), + SHC( 0x8881 ), + SHC( 0x278d ), + SHC( 0x8644 ), + SHC( 0x2120 ), + SHC( 0x845d ), + SHC( 0x1a9c ), + SHC( 0x82cd ), + SHC( 0x1406 ), + SHC( 0x8194 ), + SHC( 0x0d61 ), + SHC( 0x80b4 ), + SHC( 0x06b2 ), + SHC( 0x802d ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7fa8 ), + SHC( 0xf6a1 ), + SHC( 0x7ea0 ), + SHC( 0xed4e ), + SHC( 0x7cea ), + SHC( 0xe414 ), + SHC( 0x7a89 ), + SHC( 0xdb02 ), + SHC( 0x777f ), + SHC( 0xd221 ), + SHC( 0x73d1 ), + SHC( 0xc981 ), + SHC( 0x6f83 ), + SHC( 0xc12b ), + SHC( 0x6a9d ), + SHC( 0xb92b ), + SHC( 0x6523 ), + SHC( 0xb18d ), + SHC( 0x5f1f ), + SHC( 0xaa5a ), + SHC( 0x5898 ), + SHC( 0xa39e ), + SHC( 0x5197 ), + SHC( 0x9d60 ), + SHC( 0x4a25 ), + SHC( 0x97aa ), + SHC( 0x424e ), + SHC( 0x9284 ), + SHC( 0x3a1c ), + SHC( 0x8df4 ), + SHC( 0x319a ), + SHC( 0x8a01 ), + SHC( 0x28d3 ), + SHC( 0x86b0 ), + SHC( 0x1fd5 ), + SHC( 0x8406 ), + SHC( 0x16aa ), + SHC( 0x8206 ), + SHC( 0x0d61 ), + SHC( 0x80b4 ), + SHC( 0x0405 ), + SHC( 0x8011 ), + SHC( 0xfaa4 ), + SHC( 0x801d ), + SHC( 0xf14a ), + SHC( 0x80da ), + SHC( 0xe804 ), + SHC( 0x8245 ), + SHC( 0xdee0 ), + SHC( 0x845d ), + SHC( 0xd5e8 ), + SHC( 0x871f ), + SHC( 0xcd2b ), + SHC( 0x8a88 ), + SHC( 0xc4b3 ), + SHC( 0x8e91 ), + SHC( 0xbc8d ), + SHC( 0x9337 ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7f6e ), + SHC( 0xf3f5 ), + SHC( 0x7dbb ), + SHC( 0xe804 ), + SHC( 0x7aea ), + SHC( 0xdc4b ), + SHC( 0x7702 ), + SHC( 0xd0e2 ), + SHC( 0x720c ), + SHC( 0xc5e4 ), + SHC( 0x6c12 ), + SHC( 0xbb6b ), + SHC( 0x6523 ), + SHC( 0xb18d ), + SHC( 0x5d4e ), + SHC( 0xa861 ), + SHC( 0x54a5 ), + SHC( 0x9ffd ), + SHC( 0x4b3c ), + SHC( 0x9873 ), + SHC( 0x4128 ), + SHC( 0x91d4 ), + SHC( 0x367f ), + SHC( 0x8c2f ), + SHC( 0x2b5b ), + SHC( 0x8792 ), + SHC( 0x1fd5 ), + SHC( 0x8406 ), + SHC( 0x1406 ), + SHC( 0x8194 ), + SHC( 0x0809 ), + SHC( 0x8041 ), + SHC( 0xfbfb ), + SHC( 0x8011 ), + SHC( 0xeff6 ), + SHC( 0x8103 ), + SHC( 0xe414 ), + SHC( 0x8316 ), + SHC( 0xd873 ), + SHC( 0x8644 ), + SHC( 0xcd2b ), + SHC( 0x8a88 ), + SHC( 0xc256 ), + SHC( 0x8fd6 ), + SHC( 0xb80e ), + SHC( 0x9623 ), + SHC( 0xae69 ), + SHC( 0x9d60 ), + SHC( 0xa57e ), + SHC( 0xa57e ), + SHC( 0x9d60 ), + SHC( 0xae69 ), + SHC( 0x9623 ), + SHC( 0xb80e ), + SHC( 0x8fd6 ), + SHC( 0xc256 ), + SHC( 0x8a88 ), + SHC( 0xcd2b ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7f26 ), + SHC( 0xf14a ), + SHC( 0x7c9e ), + SHC( 0xe2c6 ), + SHC( 0x786e ), + SHC( 0xd4a5 ), + SHC( 0x72a6 ), + SHC( 0xc717 ), + SHC( 0x6b59 ), + SHC( 0xba4a ), + SHC( 0x62a0 ), + SHC( 0xae69 ), + SHC( 0x5898 ), + SHC( 0xa39e ), + SHC( 0x4d63 ), + SHC( 0x9a0c ), + SHC( 0x4128 ), + SHC( 0x91d4 ), + SHC( 0x340f ), + SHC( 0x8b11 ), + SHC( 0x2646 ), + SHC( 0x85dc ), + SHC( 0x17fc ), + SHC( 0x8245 ), + SHC( 0x095f ), + SHC( 0x8058 ), + SHC( 0xfaa4 ), + SHC( 0x801d ), + SHC( 0xebfa ), + SHC( 0x8194 ), + SHC( 0xdd95 ), + SHC( 0x84b8 ), + SHC( 0xcfa3 ), + SHC( 0x897e ), + SHC( 0xc256 ), + SHC( 0x8fd6 ), + SHC( 0xb5db ), + SHC( 0x97aa ), + SHC( 0xaa5a ), + SHC( 0xa0e1 ), + SHC( 0x9ffd ), + SHC( 0xab5b ), + SHC( 0x96e5 ), + SHC( 0xb6f3 ), + SHC( 0x8f32 ), + SHC( 0xc384 ), + SHC( 0x88fe ), + SHC( 0xd0e2 ), + SHC( 0x845d ), + SHC( 0xdee0 ), + SHC( 0x8160 ), + SHC( 0xed4e ), + SHC( 0x8011 ), + SHC( 0xfbfb ), + SHC( 0x8073 ), + SHC( 0x0ab5 ), + SHC( 0x8287 ), + SHC( 0x194c ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7ed0 ), + SHC( 0xeea1 ), + SHC( 0x7b48 ), + SHC( 0xdd95 ), + SHC( 0x7578 ), + SHC( 0xcd2b ), + SHC( 0x6d7c ), + SHC( 0xbdb2 ), + SHC( 0x6379 ), + SHC( 0xaf73 ), + SHC( 0x579f ), + SHC( 0xa2b2 ), + SHC( 0x4a25 ), + SHC( 0x97aa ), + SHC( 0x3b4d ), + SHC( 0x8e91 ), + SHC( 0x2b5b ), + SHC( 0x8792 ), + SHC( 0x1a9c ), + SHC( 0x82cd ), + SHC( 0x095f ), + SHC( 0x8058 ), + SHC( 0xf7f7 ), + SHC( 0x8041 ), + SHC( 0xe6b4 ), + SHC( 0x8287 ), + SHC( 0xd5e8 ), + SHC( 0x871f ), + SHC( 0xc5e4 ), + SHC( 0x8df4 ), + SHC( 0xb6f3 ), + SHC( 0x96e5 ), + SHC( 0xa95d ), + SHC( 0xa1c8 ), + SHC( 0x9d60 ), + SHC( 0xae69 ), + SHC( 0x9337 ), + SHC( 0xbc8d ), + SHC( 0x8b11 ), + SHC( 0xcbf1 ), + SHC( 0x8516 ), + SHC( 0xdc4b ), + SHC( 0x8160 ), + SHC( 0xed4e ), + SHC( 0x8002 ), + SHC( 0xfea9 ), + SHC( 0x8103 ), + SHC( 0x100a ), + SHC( 0x845d ), + SHC( 0x2120 ), + SHC( 0x8a01 ), + SHC( 0x319a ), + SHC( 0x91d4 ), + SHC( 0x4128 ), + SHC( 0x9bb0 ), + SHC( 0x4f81 ), + SHC( 0xa768 ), + SHC( 0x5c62 ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7e6c ), + SHC( 0xebfa ), + SHC( 0x79bc ), + SHC( 0xd873 ), + SHC( 0x720c ), + SHC( 0xc5e4 ), + SHC( 0x678d ), + SHC( 0xb4c4 ), + SHC( 0x5a82 ), + SHC( 0xa57e ), + SHC( 0x4b3c ), + SHC( 0x9873 ), + SHC( 0x3a1c ), + SHC( 0x8df4 ), + SHC( 0x278d ), + SHC( 0x8644 ), + SHC( 0x1406 ), + SHC( 0x8194 ), + SHC( 0x0000 ), + SHC( 0x8000 ), + SHC( 0xebfa ), + SHC( 0x8194 ), + SHC( 0xd873 ), + SHC( 0x8644 ), + SHC( 0xc5e4 ), + SHC( 0x8df4 ), + SHC( 0xb4c4 ), + SHC( 0x9873 ), + SHC( 0xa57e ), + SHC( 0xa57e ), + SHC( 0x9873 ), + SHC( 0xb4c4 ), + SHC( 0x8df4 ), + SHC( 0xc5e4 ), + SHC( 0x8644 ), + SHC( 0xd873 ), + SHC( 0x8194 ), + SHC( 0xebfa ), + SHC( 0x8000 ), + SHC( 0x0000 ), + SHC( 0x8194 ), + SHC( 0x1406 ), + SHC( 0x8644 ), + SHC( 0x278d ), + SHC( 0x8df4 ), + SHC( 0x3a1c ), + SHC( 0x9873 ), + SHC( 0x4b3c ), + SHC( 0xa57e ), + SHC( 0x5a82 ), + SHC( 0xb4c4 ), + SHC( 0x678d ), + SHC( 0xc5e4 ), + SHC( 0x720c ), + SHC( 0xd873 ), + SHC( 0x79bc ), + SHC( 0xebfa ), + SHC( 0x7e6c ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7dfa ), + SHC( 0xe956 ), + SHC( 0x77f8 ), + SHC( 0xd362 ), + SHC( 0x6e2c ), + SHC( 0xbed8 ), + SHC( 0x60e5 ), + SHC( 0xac5d ), + SHC( 0x508d ), + SHC( 0x9c87 ), + SHC( 0x3daa ), + SHC( 0x8fd6 ), + SHC( 0x28d3 ), + SHC( 0x86b0 ), + SHC( 0x12b2 ), + SHC( 0x8160 ), + SHC( 0xfbfb ), + SHC( 0x8011 ), + SHC( 0xe564 ), + SHC( 0x82cd ), + SHC( 0xcfa3 ), + SHC( 0x897e ), + SHC( 0xbb6b ), + SHC( 0x93ee ), + SHC( 0xa95d ), + SHC( 0xa1c8 ), + SHC( 0x9a0c ), + SHC( 0xb29d ), + SHC( 0x8df4 ), + SHC( 0xc5e4 ), + SHC( 0x8577 ), + SHC( 0xdb02 ), + SHC( 0x80da ), + SHC( 0xf14a ), + SHC( 0x8041 ), + SHC( 0x0809 ), + SHC( 0x83b2 ), + SHC( 0x1e88 ), + SHC( 0x8b11 ), + SHC( 0x340f ), + SHC( 0x9623 ), + SHC( 0x47f2 ), + SHC( 0xa48d ), + SHC( 0x598e ), + SHC( 0xb5db ), + SHC( 0x6856 ), + SHC( 0xc981 ), + SHC( 0x73d1 ), + SHC( 0xdee0 ), + SHC( 0x7ba3 ), + SHC( 0xf54b ), + SHC( 0x7f8d ), + SHC( 0x0c0b ), + SHC( 0x7f6e ), + SHC( 0x226b ), + SHC( 0x7b48 ), + SHC( 0x37b5 ), + SHC( 0x733d ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7d79 ), + SHC( 0xe6b4 ), + SHC( 0x75ff ), + SHC( 0xce66 ), + SHC( 0x69dd ), + SHC( 0xb80e ), + SHC( 0x598e ), + SHC( 0xa48d ), + SHC( 0x45b6 ), + SHC( 0x94a7 ), + SHC( 0x2f1e ), + SHC( 0x88fe ), + SHC( 0x16aa ), + SHC( 0x8206 ), + SHC( 0xfd52 ), + SHC( 0x8008 ), + SHC( 0xe414 ), + SHC( 0x8316 ), + SHC( 0xcbf1 ), + SHC( 0x8b11 ), + SHC( 0xb5db ), + SHC( 0x97aa ), + SHC( 0xa2b2 ), + SHC( 0xa861 ), + SHC( 0x9337 ), + SHC( 0xbc8d ), + SHC( 0x8808 ), + SHC( 0xd362 ), + SHC( 0x8194 ), + SHC( 0xebfa ), + SHC( 0x801d ), + SHC( 0x055c ), + SHC( 0x83b2 ), + SHC( 0x1e88 ), + SHC( 0x8c2f ), + SHC( 0x367f ), + SHC( 0x993e ), + SHC( 0x4c51 ), + SHC( 0xaa5a ), + SHC( 0x5f1f ), + SHC( 0xbed8 ), + SHC( 0x6e2c ), + SHC( 0xd5e8 ), + SHC( 0x78e1 ), + SHC( 0xeea1 ), + SHC( 0x7ed0 ), + SHC( 0x0809 ), + SHC( 0x7fbf ), + SHC( 0x2120 ), + SHC( 0x7ba3 ), + SHC( 0x38e9 ), + SHC( 0x72a6 ), + SHC( 0x4e73 ), + SHC( 0x6523 ), + SHC( 0x60e5 ), + SHC( 0x53a3 ), + SHC( 0x6f83 ), + SHC( 0x3ed5 ), }; -const Word16 FFT_RotVector_400_fx[ 760 ] = { - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7fef ), SHC( 0xfbfb ), SHC( 0x7fbf ), SHC( 0xf7f7 ), SHC( 0x7f6e ), SHC( 0xf3f5 ), - SHC( 0x7efd ), SHC( 0xeff6 ), SHC( 0x7e6c ), SHC( 0xebfa ), SHC( 0x7dbb ), SHC( 0xe804 ), SHC( 0x7cea ), SHC( 0xe414 ), - SHC( 0x7bfa ), SHC( 0xe02b ), SHC( 0x7aea ), SHC( 0xdc4b ), SHC( 0x79bc ), SHC( 0xd873 ), SHC( 0x786e ), SHC( 0xd4a5 ), - SHC( 0x7702 ), SHC( 0xd0e2 ), SHC( 0x7578 ), SHC( 0xcd2b ), SHC( 0x73d1 ), SHC( 0xc981 ), SHC( 0x720c ), SHC( 0xc5e4 ), - SHC( 0x702a ), SHC( 0xc256 ), SHC( 0x6e2c ), SHC( 0xbed8 ), SHC( 0x6c12 ), SHC( 0xbb6b ), SHC( 0x69dd ), SHC( 0xb80e ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7fbf ), SHC( 0xf7f7 ), SHC( 0x7efd ), SHC( 0xeff6 ), SHC( 0x7dbb ), SHC( 0xe804 ), - SHC( 0x7bfa ), SHC( 0xe02b ), SHC( 0x79bc ), SHC( 0xd873 ), SHC( 0x7702 ), SHC( 0xd0e2 ), SHC( 0x73d1 ), SHC( 0xc981 ), - SHC( 0x702a ), SHC( 0xc256 ), SHC( 0x6c12 ), SHC( 0xbb6b ), SHC( 0x678d ), SHC( 0xb4c4 ), SHC( 0x62a0 ), SHC( 0xae69 ), - SHC( 0x5d4e ), SHC( 0xa861 ), SHC( 0x579f ), SHC( 0xa2b2 ), SHC( 0x5197 ), SHC( 0x9d60 ), SHC( 0x4b3c ), SHC( 0x9873 ), - SHC( 0x4495 ), SHC( 0x93ee ), SHC( 0x3daa ), SHC( 0x8fd6 ), SHC( 0x367f ), SHC( 0x8c2f ), SHC( 0x2f1e ), SHC( 0x88fe ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7f6e ), SHC( 0xf3f5 ), SHC( 0x7dbb ), SHC( 0xe804 ), SHC( 0x7aea ), SHC( 0xdc4b ), - SHC( 0x7702 ), SHC( 0xd0e2 ), SHC( 0x720c ), SHC( 0xc5e4 ), SHC( 0x6c12 ), SHC( 0xbb6b ), SHC( 0x6523 ), SHC( 0xb18d ), - SHC( 0x5d4e ), SHC( 0xa861 ), SHC( 0x54a5 ), SHC( 0x9ffd ), SHC( 0x4b3c ), SHC( 0x9873 ), SHC( 0x4128 ), SHC( 0x91d4 ), - SHC( 0x367f ), SHC( 0x8c2f ), SHC( 0x2b5b ), SHC( 0x8792 ), SHC( 0x1fd5 ), SHC( 0x8406 ), SHC( 0x1406 ), SHC( 0x8194 ), - SHC( 0x0809 ), SHC( 0x8041 ), SHC( 0xfbfb ), SHC( 0x8011 ), SHC( 0xeff6 ), SHC( 0x8103 ), SHC( 0xe414 ), SHC( 0x8316 ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7efd ), SHC( 0xeff6 ), SHC( 0x7bfa ), SHC( 0xe02b ), SHC( 0x7702 ), SHC( 0xd0e2 ), - SHC( 0x702a ), SHC( 0xc256 ), SHC( 0x678d ), SHC( 0xb4c4 ), SHC( 0x5d4e ), SHC( 0xa861 ), SHC( 0x5197 ), SHC( 0x9d60 ), - SHC( 0x4495 ), SHC( 0x93ee ), SHC( 0x367f ), SHC( 0x8c2f ), SHC( 0x278d ), SHC( 0x8644 ), SHC( 0x17fc ), SHC( 0x8245 ), - SHC( 0x0809 ), SHC( 0x8041 ), SHC( 0xf7f7 ), SHC( 0x8041 ), SHC( 0xe804 ), SHC( 0x8245 ), SHC( 0xd873 ), SHC( 0x8644 ), - SHC( 0xc981 ), SHC( 0x8c2f ), SHC( 0xbb6b ), SHC( 0x93ee ), SHC( 0xae69 ), SHC( 0x9d60 ), SHC( 0xa2b2 ), SHC( 0xa861 ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7e6c ), SHC( 0xebfa ), SHC( 0x79bc ), SHC( 0xd873 ), SHC( 0x720c ), SHC( 0xc5e4 ), - SHC( 0x678d ), SHC( 0xb4c4 ), SHC( 0x5a82 ), SHC( 0xa57e ), SHC( 0x4b3c ), SHC( 0x9873 ), SHC( 0x3a1c ), SHC( 0x8df4 ), - SHC( 0x278d ), SHC( 0x8644 ), SHC( 0x1406 ), SHC( 0x8194 ), SHC( 0x0000 ), SHC( 0x8000 ), SHC( 0xebfa ), SHC( 0x8194 ), - SHC( 0xd873 ), SHC( 0x8644 ), SHC( 0xc5e4 ), SHC( 0x8df4 ), SHC( 0xb4c4 ), SHC( 0x9873 ), SHC( 0xa57e ), SHC( 0xa57e ), - SHC( 0x9873 ), SHC( 0xb4c4 ), SHC( 0x8df4 ), SHC( 0xc5e4 ), SHC( 0x8644 ), SHC( 0xd873 ), SHC( 0x8194 ), SHC( 0xebfa ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7dbb ), SHC( 0xe804 ), SHC( 0x7702 ), SHC( 0xd0e2 ), SHC( 0x6c12 ), SHC( 0xbb6b ), - SHC( 0x5d4e ), SHC( 0xa861 ), SHC( 0x4b3c ), SHC( 0x9873 ), SHC( 0x367f ), SHC( 0x8c2f ), SHC( 0x1fd5 ), SHC( 0x8406 ), - SHC( 0x0809 ), SHC( 0x8041 ), SHC( 0xeff6 ), SHC( 0x8103 ), SHC( 0xd873 ), SHC( 0x8644 ), SHC( 0xc256 ), SHC( 0x8fd6 ), - SHC( 0xae69 ), SHC( 0x9d60 ), SHC( 0x9d60 ), SHC( 0xae69 ), SHC( 0x8fd6 ), SHC( 0xc256 ), SHC( 0x8644 ), SHC( 0xd873 ), - SHC( 0x8103 ), SHC( 0xeff6 ), SHC( 0x8041 ), SHC( 0x0809 ), SHC( 0x8406 ), SHC( 0x1fd5 ), SHC( 0x8c2f ), SHC( 0x367f ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7cea ), SHC( 0xe414 ), SHC( 0x73d1 ), SHC( 0xc981 ), SHC( 0x6523 ), SHC( 0xb18d ), - SHC( 0x5197 ), SHC( 0x9d60 ), SHC( 0x3a1c ), SHC( 0x8df4 ), SHC( 0x1fd5 ), SHC( 0x8406 ), SHC( 0x0405 ), SHC( 0x8011 ), - SHC( 0xe804 ), SHC( 0x8245 ), SHC( 0xcd2b ), SHC( 0x8a88 ), SHC( 0xb4c4 ), SHC( 0x9873 ), SHC( 0x9ffd ), SHC( 0xab5b ), - SHC( 0x8fd6 ), SHC( 0xc256 ), SHC( 0x8516 ), SHC( 0xdc4b ), SHC( 0x8041 ), SHC( 0xf7f7 ), SHC( 0x8194 ), SHC( 0x1406 ), - SHC( 0x88fe ), SHC( 0x2f1e ), SHC( 0x9623 ), SHC( 0x47f2 ), SHC( 0xa861 ), SHC( 0x5d4e ), SHC( 0xbed8 ), SHC( 0x6e2c ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7bfa ), SHC( 0xe02b ), SHC( 0x702a ), SHC( 0xc256 ), SHC( 0x5d4e ), SHC( 0xa861 ), - SHC( 0x4495 ), SHC( 0x93ee ), SHC( 0x278d ), SHC( 0x8644 ), SHC( 0x0809 ), SHC( 0x8041 ), SHC( 0xe804 ), SHC( 0x8245 ), - SHC( 0xc981 ), SHC( 0x8c2f ), SHC( 0xae69 ), SHC( 0x9d60 ), SHC( 0x9873 ), SHC( 0xb4c4 ), SHC( 0x88fe ), SHC( 0xd0e2 ), - SHC( 0x8103 ), SHC( 0xeff6 ), SHC( 0x8103 ), SHC( 0x100a ), SHC( 0x88fe ), SHC( 0x2f1e ), SHC( 0x9873 ), SHC( 0x4b3c ), - SHC( 0xae69 ), SHC( 0x62a0 ), SHC( 0xc981 ), SHC( 0x73d1 ), SHC( 0xe804 ), SHC( 0x7dbb ), SHC( 0x0809 ), SHC( 0x7fbf ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7aea ), SHC( 0xdc4b ), SHC( 0x6c12 ), SHC( 0xbb6b ), SHC( 0x54a5 ), SHC( 0x9ffd ), - SHC( 0x367f ), SHC( 0x8c2f ), SHC( 0x1406 ), SHC( 0x8194 ), SHC( 0xeff6 ), SHC( 0x8103 ), SHC( 0xcd2b ), SHC( 0x8a88 ), - SHC( 0xae69 ), SHC( 0x9d60 ), SHC( 0x9623 ), SHC( 0xb80e ), SHC( 0x8644 ), SHC( 0xd873 ), SHC( 0x8011 ), SHC( 0xfbfb ), - SHC( 0x8406 ), SHC( 0x1fd5 ), SHC( 0x91d4 ), SHC( 0x4128 ), SHC( 0xa861 ), SHC( 0x5d4e ), SHC( 0xc5e4 ), SHC( 0x720c ), - SHC( 0xe804 ), SHC( 0x7dbb ), SHC( 0x0c0b ), SHC( 0x7f6e ), SHC( 0x2f1e ), SHC( 0x7702 ), SHC( 0x4e73 ), SHC( 0x6523 ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7ffb ), SHC( 0xfdfe ), SHC( 0x7fef ), SHC( 0xfbfb ), SHC( 0x7fdb ), SHC( 0xf9f9 ), - SHC( 0x7fbf ), SHC( 0xf7f7 ), SHC( 0x7f9a ), SHC( 0xf5f6 ), SHC( 0x7f6e ), SHC( 0xf3f5 ), SHC( 0x7f3a ), SHC( 0xf1f5 ), - SHC( 0x7efd ), SHC( 0xeff6 ), SHC( 0x7eb9 ), SHC( 0xedf7 ), SHC( 0x7e6c ), SHC( 0xebfa ), SHC( 0x7e18 ), SHC( 0xe9ff ), - SHC( 0x7dbb ), SHC( 0xe804 ), SHC( 0x7d57 ), SHC( 0xe60c ), SHC( 0x7cea ), SHC( 0xe414 ), SHC( 0x7c76 ), SHC( 0xe21f ), - SHC( 0x7bfa ), SHC( 0xe02b ), SHC( 0x7b76 ), SHC( 0xde3a ), SHC( 0x7aea ), SHC( 0xdc4b ), SHC( 0x7a57 ), SHC( 0xda5d ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7fdb ), SHC( 0xf9f9 ), SHC( 0x7f6e ), SHC( 0xf3f5 ), SHC( 0x7eb9 ), SHC( 0xedf7 ), - SHC( 0x7dbb ), SHC( 0xe804 ), SHC( 0x7c76 ), SHC( 0xe21f ), SHC( 0x7aea ), SHC( 0xdc4b ), SHC( 0x7919 ), SHC( 0xd68a ), - SHC( 0x7702 ), SHC( 0xd0e2 ), SHC( 0x74a8 ), SHC( 0xcb54 ), SHC( 0x720c ), SHC( 0xc5e4 ), SHC( 0x6f2f ), SHC( 0xc095 ), - SHC( 0x6c12 ), SHC( 0xbb6b ), SHC( 0x68b9 ), SHC( 0xb667 ), SHC( 0x6523 ), SHC( 0xb18d ), SHC( 0x6154 ), SHC( 0xacdf ), - SHC( 0x5d4e ), SHC( 0xa861 ), SHC( 0x5913 ), SHC( 0xa415 ), SHC( 0x54a5 ), SHC( 0x9ffd ), SHC( 0x5007 ), SHC( 0x9c1b ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7f9a ), SHC( 0xf5f6 ), SHC( 0x7e6c ), SHC( 0xebfa ), SHC( 0x7c76 ), SHC( 0xe21f ), - SHC( 0x79bc ), SHC( 0xd873 ), SHC( 0x7641 ), SHC( 0xcf05 ), SHC( 0x720c ), SHC( 0xc5e4 ), SHC( 0x6d23 ), SHC( 0xbd1f ), - SHC( 0x678d ), SHC( 0xb4c4 ), SHC( 0x6154 ), SHC( 0xacdf ), SHC( 0x5a82 ), SHC( 0xa57e ), SHC( 0x5321 ), SHC( 0x9eac ), - SHC( 0x4b3c ), SHC( 0x9873 ), SHC( 0x42e1 ), SHC( 0x92dd ), SHC( 0x3a1c ), SHC( 0x8df4 ), SHC( 0x30fb ), SHC( 0x89bf ), - SHC( 0x278d ), SHC( 0x8644 ), SHC( 0x1de1 ), SHC( 0x838a ), SHC( 0x1406 ), SHC( 0x8194 ), SHC( 0x0a0a ), SHC( 0x8066 ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7f3a ), SHC( 0xf1f5 ), SHC( 0x7cea ), SHC( 0xe414 ), SHC( 0x7919 ), SHC( 0xd68a ), - SHC( 0x73d1 ), SHC( 0xc981 ), SHC( 0x6d23 ), SHC( 0xbd1f ), SHC( 0x6523 ), SHC( 0xb18d ), SHC( 0x5beb ), SHC( 0xa6ed ), - SHC( 0x5197 ), SHC( 0x9d60 ), SHC( 0x4646 ), SHC( 0x9505 ), SHC( 0x3a1c ), SHC( 0x8df4 ), SHC( 0x2d3e ), SHC( 0x8844 ), - SHC( 0x1fd5 ), SHC( 0x8406 ), SHC( 0x1209 ), SHC( 0x8147 ), SHC( 0x0405 ), SHC( 0x8011 ), SHC( 0xf5f6 ), SHC( 0x8066 ), - SHC( 0xe804 ), SHC( 0x8245 ), SHC( 0xda5d ), SHC( 0x85a9 ), SHC( 0xcd2b ), SHC( 0x8a88 ), SHC( 0xc095 ), SHC( 0x90d1 ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7eb9 ), SHC( 0xedf7 ), SHC( 0x7aea ), SHC( 0xdc4b ), SHC( 0x74a8 ), SHC( 0xcb54 ), - SHC( 0x6c12 ), SHC( 0xbb6b ), SHC( 0x6154 ), SHC( 0xacdf ), SHC( 0x54a5 ), SHC( 0x9ffd ), SHC( 0x4646 ), SHC( 0x9505 ), - SHC( 0x367f ), SHC( 0x8c2f ), SHC( 0x25a3 ), SHC( 0x85a9 ), SHC( 0x1406 ), SHC( 0x8194 ), SHC( 0x0202 ), SHC( 0x8005 ), - SHC( 0xeff6 ), SHC( 0x8103 ), SHC( 0xde3a ), SHC( 0x848a ), SHC( 0xcd2b ), SHC( 0x8a88 ), SHC( 0xbd1f ), SHC( 0x92dd ), - SHC( 0xae69 ), SHC( 0x9d60 ), SHC( 0xa154 ), SHC( 0xa9db ), SHC( 0x9623 ), SHC( 0xb80e ), SHC( 0x8d0e ), SHC( 0xc7b1 ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7e18 ), SHC( 0xe9ff ), SHC( 0x786e ), SHC( 0xd4a5 ), SHC( 0x6f2f ), SHC( 0xc095 ), - SHC( 0x62a0 ), SHC( 0xae69 ), SHC( 0x5321 ), SHC( 0x9eac ), SHC( 0x4128 ), SHC( 0x91d4 ), SHC( 0x2d3e ), SHC( 0x8844 ), - SHC( 0x17fc ), SHC( 0x8245 ), SHC( 0x0202 ), SHC( 0x8005 ), SHC( 0xebfa ), SHC( 0x8194 ), SHC( 0xd68a ), SHC( 0x86e7 ), - SHC( 0xc256 ), SHC( 0x8fd6 ), SHC( 0xaff9 ), SHC( 0x9c1b ), SHC( 0x9ffd ), SHC( 0xab5b ), SHC( 0x92dd ), SHC( 0xbd1f ), - SHC( 0x88fe ), SHC( 0xd0e2 ), SHC( 0x82a9 ), SHC( 0xe60c ), SHC( 0x8011 ), SHC( 0xfbfb ), SHC( 0x8147 ), SHC( 0x1209 ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7d57 ), SHC( 0xe60c ), SHC( 0x7578 ), SHC( 0xcd2b ), SHC( 0x68b9 ), SHC( 0xb667 ), - SHC( 0x579f ), SHC( 0xa2b2 ), SHC( 0x42e1 ), SHC( 0x92dd ), SHC( 0x2b5b ), SHC( 0x8792 ), SHC( 0x1209 ), SHC( 0x8147 ), - SHC( 0xf7f7 ), SHC( 0x8041 ), SHC( 0xde3a ), SHC( 0x848a ), SHC( 0xc5e4 ), SHC( 0x8df4 ), SHC( 0xaff9 ), SHC( 0x9c1b ), - SHC( 0x9d60 ), SHC( 0xae69 ), SHC( 0x8ee1 ), SHC( 0xc41b ), SHC( 0x8516 ), SHC( 0xdc4b ), SHC( 0x8066 ), SHC( 0xf5f6 ), - SHC( 0x8103 ), SHC( 0x100a ), SHC( 0x86e7 ), SHC( 0x2976 ), SHC( 0x91d4 ), SHC( 0x4128 ), SHC( 0xa154 ), SHC( 0x5625 ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7c76 ), SHC( 0xe21f ), SHC( 0x720c ), SHC( 0xc5e4 ), SHC( 0x6154 ), SHC( 0xacdf ), - SHC( 0x4b3c ), SHC( 0x9873 ), SHC( 0x30fb ), SHC( 0x89bf ), SHC( 0x1406 ), SHC( 0x8194 ), SHC( 0xf5f6 ), SHC( 0x8066 ), - SHC( 0xd873 ), SHC( 0x8644 ), SHC( 0xbd1f ), SHC( 0x92dd ), SHC( 0xa57e ), SHC( 0xa57e ), SHC( 0x92dd ), SHC( 0xbd1f ), - SHC( 0x8644 ), SHC( 0xd873 ), SHC( 0x8066 ), SHC( 0xf5f6 ), SHC( 0x8194 ), SHC( 0x1406 ), SHC( 0x89bf ), SHC( 0x30fb ), - SHC( 0x9873 ), SHC( 0x4b3c ), SHC( 0xacdf ), SHC( 0x6154 ), SHC( 0xc5e4 ), SHC( 0x720c ), SHC( 0xe21f ), SHC( 0x7c76 ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7b76 ), SHC( 0xde3a ), SHC( 0x6e2c ), SHC( 0xbed8 ), SHC( 0x5913 ), SHC( 0xa415 ), - SHC( 0x3daa ), SHC( 0x8fd6 ), SHC( 0x1de1 ), SHC( 0x838a ), SHC( 0xfbfb ), SHC( 0x8011 ), SHC( 0xda5d ), SHC( 0x85a9 ), - SHC( 0xbb6b ), SHC( 0x93ee ), SHC( 0xa154 ), SHC( 0xa9db ), SHC( 0x8df4 ), SHC( 0xc5e4 ), SHC( 0x82a9 ), SHC( 0xe60c ), - SHC( 0x8041 ), SHC( 0x0809 ), SHC( 0x86e7 ), SHC( 0x2976 ), SHC( 0x9623 ), SHC( 0x47f2 ), SHC( 0xacdf ), SHC( 0x6154 ), - SHC( 0xc981 ), SHC( 0x73d1 ), SHC( 0xe9ff ), SHC( 0x7e18 ), SHC( 0x0c0b ), SHC( 0x7f6e ), SHC( 0x2d3e ), SHC( 0x77bc ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7a57 ), SHC( 0xda5d ), SHC( 0x69dd ), SHC( 0xb80e ), SHC( 0x5007 ), SHC( 0x9c1b ), - SHC( 0x2f1e ), SHC( 0x88fe ), SHC( 0x0a0a ), SHC( 0x8066 ), SHC( 0xe414 ), SHC( 0x8316 ), SHC( 0xc095 ), SHC( 0x90d1 ), - SHC( 0xa2b2 ), SHC( 0xa861 ), SHC( 0x8d0e ), SHC( 0xc7b1 ), SHC( 0x8194 ), SHC( 0xebfa ), SHC( 0x8147 ), SHC( 0x1209 ), - SHC( 0x8c2f ), SHC( 0x367f ), SHC( 0xa154 ), SHC( 0x5625 ), SHC( 0xbed8 ), SHC( 0x6e2c ), SHC( 0xe21f ), SHC( 0x7c76 ), - SHC( 0x0809 ), SHC( 0x7fbf ), SHC( 0x2d3e ), SHC( 0x77bc ), SHC( 0x4e73 ), SHC( 0x6523 ), SHC( 0x68b9 ), SHC( 0x4999 ), +const Word16 FFT_RotVector_400_fx[760] = { + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7fef ), + SHC( 0xfbfb ), + SHC( 0x7fbf ), + SHC( 0xf7f7 ), + SHC( 0x7f6e ), + SHC( 0xf3f5 ), + SHC( 0x7efd ), + SHC( 0xeff6 ), + SHC( 0x7e6c ), + SHC( 0xebfa ), + SHC( 0x7dbb ), + SHC( 0xe804 ), + SHC( 0x7cea ), + SHC( 0xe414 ), + SHC( 0x7bfa ), + SHC( 0xe02b ), + SHC( 0x7aea ), + SHC( 0xdc4b ), + SHC( 0x79bc ), + SHC( 0xd873 ), + SHC( 0x786e ), + SHC( 0xd4a5 ), + SHC( 0x7702 ), + SHC( 0xd0e2 ), + SHC( 0x7578 ), + SHC( 0xcd2b ), + SHC( 0x73d1 ), + SHC( 0xc981 ), + SHC( 0x720c ), + SHC( 0xc5e4 ), + SHC( 0x702a ), + SHC( 0xc256 ), + SHC( 0x6e2c ), + SHC( 0xbed8 ), + SHC( 0x6c12 ), + SHC( 0xbb6b ), + SHC( 0x69dd ), + SHC( 0xb80e ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7fbf ), + SHC( 0xf7f7 ), + SHC( 0x7efd ), + SHC( 0xeff6 ), + SHC( 0x7dbb ), + SHC( 0xe804 ), + SHC( 0x7bfa ), + SHC( 0xe02b ), + SHC( 0x79bc ), + SHC( 0xd873 ), + SHC( 0x7702 ), + SHC( 0xd0e2 ), + SHC( 0x73d1 ), + SHC( 0xc981 ), + SHC( 0x702a ), + SHC( 0xc256 ), + SHC( 0x6c12 ), + SHC( 0xbb6b ), + SHC( 0x678d ), + SHC( 0xb4c4 ), + SHC( 0x62a0 ), + SHC( 0xae69 ), + SHC( 0x5d4e ), + SHC( 0xa861 ), + SHC( 0x579f ), + SHC( 0xa2b2 ), + SHC( 0x5197 ), + SHC( 0x9d60 ), + SHC( 0x4b3c ), + SHC( 0x9873 ), + SHC( 0x4495 ), + SHC( 0x93ee ), + SHC( 0x3daa ), + SHC( 0x8fd6 ), + SHC( 0x367f ), + SHC( 0x8c2f ), + SHC( 0x2f1e ), + SHC( 0x88fe ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7f6e ), + SHC( 0xf3f5 ), + SHC( 0x7dbb ), + SHC( 0xe804 ), + SHC( 0x7aea ), + SHC( 0xdc4b ), + SHC( 0x7702 ), + SHC( 0xd0e2 ), + SHC( 0x720c ), + SHC( 0xc5e4 ), + SHC( 0x6c12 ), + SHC( 0xbb6b ), + SHC( 0x6523 ), + SHC( 0xb18d ), + SHC( 0x5d4e ), + SHC( 0xa861 ), + SHC( 0x54a5 ), + SHC( 0x9ffd ), + SHC( 0x4b3c ), + SHC( 0x9873 ), + SHC( 0x4128 ), + SHC( 0x91d4 ), + SHC( 0x367f ), + SHC( 0x8c2f ), + SHC( 0x2b5b ), + SHC( 0x8792 ), + SHC( 0x1fd5 ), + SHC( 0x8406 ), + SHC( 0x1406 ), + SHC( 0x8194 ), + SHC( 0x0809 ), + SHC( 0x8041 ), + SHC( 0xfbfb ), + SHC( 0x8011 ), + SHC( 0xeff6 ), + SHC( 0x8103 ), + SHC( 0xe414 ), + SHC( 0x8316 ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7efd ), + SHC( 0xeff6 ), + SHC( 0x7bfa ), + SHC( 0xe02b ), + SHC( 0x7702 ), + SHC( 0xd0e2 ), + SHC( 0x702a ), + SHC( 0xc256 ), + SHC( 0x678d ), + SHC( 0xb4c4 ), + SHC( 0x5d4e ), + SHC( 0xa861 ), + SHC( 0x5197 ), + SHC( 0x9d60 ), + SHC( 0x4495 ), + SHC( 0x93ee ), + SHC( 0x367f ), + SHC( 0x8c2f ), + SHC( 0x278d ), + SHC( 0x8644 ), + SHC( 0x17fc ), + SHC( 0x8245 ), + SHC( 0x0809 ), + SHC( 0x8041 ), + SHC( 0xf7f7 ), + SHC( 0x8041 ), + SHC( 0xe804 ), + SHC( 0x8245 ), + SHC( 0xd873 ), + SHC( 0x8644 ), + SHC( 0xc981 ), + SHC( 0x8c2f ), + SHC( 0xbb6b ), + SHC( 0x93ee ), + SHC( 0xae69 ), + SHC( 0x9d60 ), + SHC( 0xa2b2 ), + SHC( 0xa861 ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7e6c ), + SHC( 0xebfa ), + SHC( 0x79bc ), + SHC( 0xd873 ), + SHC( 0x720c ), + SHC( 0xc5e4 ), + SHC( 0x678d ), + SHC( 0xb4c4 ), + SHC( 0x5a82 ), + SHC( 0xa57e ), + SHC( 0x4b3c ), + SHC( 0x9873 ), + SHC( 0x3a1c ), + SHC( 0x8df4 ), + SHC( 0x278d ), + SHC( 0x8644 ), + SHC( 0x1406 ), + SHC( 0x8194 ), + SHC( 0x0000 ), + SHC( 0x8000 ), + SHC( 0xebfa ), + SHC( 0x8194 ), + SHC( 0xd873 ), + SHC( 0x8644 ), + SHC( 0xc5e4 ), + SHC( 0x8df4 ), + SHC( 0xb4c4 ), + SHC( 0x9873 ), + SHC( 0xa57e ), + SHC( 0xa57e ), + SHC( 0x9873 ), + SHC( 0xb4c4 ), + SHC( 0x8df4 ), + SHC( 0xc5e4 ), + SHC( 0x8644 ), + SHC( 0xd873 ), + SHC( 0x8194 ), + SHC( 0xebfa ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7dbb ), + SHC( 0xe804 ), + SHC( 0x7702 ), + SHC( 0xd0e2 ), + SHC( 0x6c12 ), + SHC( 0xbb6b ), + SHC( 0x5d4e ), + SHC( 0xa861 ), + SHC( 0x4b3c ), + SHC( 0x9873 ), + SHC( 0x367f ), + SHC( 0x8c2f ), + SHC( 0x1fd5 ), + SHC( 0x8406 ), + SHC( 0x0809 ), + SHC( 0x8041 ), + SHC( 0xeff6 ), + SHC( 0x8103 ), + SHC( 0xd873 ), + SHC( 0x8644 ), + SHC( 0xc256 ), + SHC( 0x8fd6 ), + SHC( 0xae69 ), + SHC( 0x9d60 ), + SHC( 0x9d60 ), + SHC( 0xae69 ), + SHC( 0x8fd6 ), + SHC( 0xc256 ), + SHC( 0x8644 ), + SHC( 0xd873 ), + SHC( 0x8103 ), + SHC( 0xeff6 ), + SHC( 0x8041 ), + SHC( 0x0809 ), + SHC( 0x8406 ), + SHC( 0x1fd5 ), + SHC( 0x8c2f ), + SHC( 0x367f ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7cea ), + SHC( 0xe414 ), + SHC( 0x73d1 ), + SHC( 0xc981 ), + SHC( 0x6523 ), + SHC( 0xb18d ), + SHC( 0x5197 ), + SHC( 0x9d60 ), + SHC( 0x3a1c ), + SHC( 0x8df4 ), + SHC( 0x1fd5 ), + SHC( 0x8406 ), + SHC( 0x0405 ), + SHC( 0x8011 ), + SHC( 0xe804 ), + SHC( 0x8245 ), + SHC( 0xcd2b ), + SHC( 0x8a88 ), + SHC( 0xb4c4 ), + SHC( 0x9873 ), + SHC( 0x9ffd ), + SHC( 0xab5b ), + SHC( 0x8fd6 ), + SHC( 0xc256 ), + SHC( 0x8516 ), + SHC( 0xdc4b ), + SHC( 0x8041 ), + SHC( 0xf7f7 ), + SHC( 0x8194 ), + SHC( 0x1406 ), + SHC( 0x88fe ), + SHC( 0x2f1e ), + SHC( 0x9623 ), + SHC( 0x47f2 ), + SHC( 0xa861 ), + SHC( 0x5d4e ), + SHC( 0xbed8 ), + SHC( 0x6e2c ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7bfa ), + SHC( 0xe02b ), + SHC( 0x702a ), + SHC( 0xc256 ), + SHC( 0x5d4e ), + SHC( 0xa861 ), + SHC( 0x4495 ), + SHC( 0x93ee ), + SHC( 0x278d ), + SHC( 0x8644 ), + SHC( 0x0809 ), + SHC( 0x8041 ), + SHC( 0xe804 ), + SHC( 0x8245 ), + SHC( 0xc981 ), + SHC( 0x8c2f ), + SHC( 0xae69 ), + SHC( 0x9d60 ), + SHC( 0x9873 ), + SHC( 0xb4c4 ), + SHC( 0x88fe ), + SHC( 0xd0e2 ), + SHC( 0x8103 ), + SHC( 0xeff6 ), + SHC( 0x8103 ), + SHC( 0x100a ), + SHC( 0x88fe ), + SHC( 0x2f1e ), + SHC( 0x9873 ), + SHC( 0x4b3c ), + SHC( 0xae69 ), + SHC( 0x62a0 ), + SHC( 0xc981 ), + SHC( 0x73d1 ), + SHC( 0xe804 ), + SHC( 0x7dbb ), + SHC( 0x0809 ), + SHC( 0x7fbf ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7aea ), + SHC( 0xdc4b ), + SHC( 0x6c12 ), + SHC( 0xbb6b ), + SHC( 0x54a5 ), + SHC( 0x9ffd ), + SHC( 0x367f ), + SHC( 0x8c2f ), + SHC( 0x1406 ), + SHC( 0x8194 ), + SHC( 0xeff6 ), + SHC( 0x8103 ), + SHC( 0xcd2b ), + SHC( 0x8a88 ), + SHC( 0xae69 ), + SHC( 0x9d60 ), + SHC( 0x9623 ), + SHC( 0xb80e ), + SHC( 0x8644 ), + SHC( 0xd873 ), + SHC( 0x8011 ), + SHC( 0xfbfb ), + SHC( 0x8406 ), + SHC( 0x1fd5 ), + SHC( 0x91d4 ), + SHC( 0x4128 ), + SHC( 0xa861 ), + SHC( 0x5d4e ), + SHC( 0xc5e4 ), + SHC( 0x720c ), + SHC( 0xe804 ), + SHC( 0x7dbb ), + SHC( 0x0c0b ), + SHC( 0x7f6e ), + SHC( 0x2f1e ), + SHC( 0x7702 ), + SHC( 0x4e73 ), + SHC( 0x6523 ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7ffb ), + SHC( 0xfdfe ), + SHC( 0x7fef ), + SHC( 0xfbfb ), + SHC( 0x7fdb ), + SHC( 0xf9f9 ), + SHC( 0x7fbf ), + SHC( 0xf7f7 ), + SHC( 0x7f9a ), + SHC( 0xf5f6 ), + SHC( 0x7f6e ), + SHC( 0xf3f5 ), + SHC( 0x7f3a ), + SHC( 0xf1f5 ), + SHC( 0x7efd ), + SHC( 0xeff6 ), + SHC( 0x7eb9 ), + SHC( 0xedf7 ), + SHC( 0x7e6c ), + SHC( 0xebfa ), + SHC( 0x7e18 ), + SHC( 0xe9ff ), + SHC( 0x7dbb ), + SHC( 0xe804 ), + SHC( 0x7d57 ), + SHC( 0xe60c ), + SHC( 0x7cea ), + SHC( 0xe414 ), + SHC( 0x7c76 ), + SHC( 0xe21f ), + SHC( 0x7bfa ), + SHC( 0xe02b ), + SHC( 0x7b76 ), + SHC( 0xde3a ), + SHC( 0x7aea ), + SHC( 0xdc4b ), + SHC( 0x7a57 ), + SHC( 0xda5d ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7fdb ), + SHC( 0xf9f9 ), + SHC( 0x7f6e ), + SHC( 0xf3f5 ), + SHC( 0x7eb9 ), + SHC( 0xedf7 ), + SHC( 0x7dbb ), + SHC( 0xe804 ), + SHC( 0x7c76 ), + SHC( 0xe21f ), + SHC( 0x7aea ), + SHC( 0xdc4b ), + SHC( 0x7919 ), + SHC( 0xd68a ), + SHC( 0x7702 ), + SHC( 0xd0e2 ), + SHC( 0x74a8 ), + SHC( 0xcb54 ), + SHC( 0x720c ), + SHC( 0xc5e4 ), + SHC( 0x6f2f ), + SHC( 0xc095 ), + SHC( 0x6c12 ), + SHC( 0xbb6b ), + SHC( 0x68b9 ), + SHC( 0xb667 ), + SHC( 0x6523 ), + SHC( 0xb18d ), + SHC( 0x6154 ), + SHC( 0xacdf ), + SHC( 0x5d4e ), + SHC( 0xa861 ), + SHC( 0x5913 ), + SHC( 0xa415 ), + SHC( 0x54a5 ), + SHC( 0x9ffd ), + SHC( 0x5007 ), + SHC( 0x9c1b ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7f9a ), + SHC( 0xf5f6 ), + SHC( 0x7e6c ), + SHC( 0xebfa ), + SHC( 0x7c76 ), + SHC( 0xe21f ), + SHC( 0x79bc ), + SHC( 0xd873 ), + SHC( 0x7641 ), + SHC( 0xcf05 ), + SHC( 0x720c ), + SHC( 0xc5e4 ), + SHC( 0x6d23 ), + SHC( 0xbd1f ), + SHC( 0x678d ), + SHC( 0xb4c4 ), + SHC( 0x6154 ), + SHC( 0xacdf ), + SHC( 0x5a82 ), + SHC( 0xa57e ), + SHC( 0x5321 ), + SHC( 0x9eac ), + SHC( 0x4b3c ), + SHC( 0x9873 ), + SHC( 0x42e1 ), + SHC( 0x92dd ), + SHC( 0x3a1c ), + SHC( 0x8df4 ), + SHC( 0x30fb ), + SHC( 0x89bf ), + SHC( 0x278d ), + SHC( 0x8644 ), + SHC( 0x1de1 ), + SHC( 0x838a ), + SHC( 0x1406 ), + SHC( 0x8194 ), + SHC( 0x0a0a ), + SHC( 0x8066 ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7f3a ), + SHC( 0xf1f5 ), + SHC( 0x7cea ), + SHC( 0xe414 ), + SHC( 0x7919 ), + SHC( 0xd68a ), + SHC( 0x73d1 ), + SHC( 0xc981 ), + SHC( 0x6d23 ), + SHC( 0xbd1f ), + SHC( 0x6523 ), + SHC( 0xb18d ), + SHC( 0x5beb ), + SHC( 0xa6ed ), + SHC( 0x5197 ), + SHC( 0x9d60 ), + SHC( 0x4646 ), + SHC( 0x9505 ), + SHC( 0x3a1c ), + SHC( 0x8df4 ), + SHC( 0x2d3e ), + SHC( 0x8844 ), + SHC( 0x1fd5 ), + SHC( 0x8406 ), + SHC( 0x1209 ), + SHC( 0x8147 ), + SHC( 0x0405 ), + SHC( 0x8011 ), + SHC( 0xf5f6 ), + SHC( 0x8066 ), + SHC( 0xe804 ), + SHC( 0x8245 ), + SHC( 0xda5d ), + SHC( 0x85a9 ), + SHC( 0xcd2b ), + SHC( 0x8a88 ), + SHC( 0xc095 ), + SHC( 0x90d1 ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7eb9 ), + SHC( 0xedf7 ), + SHC( 0x7aea ), + SHC( 0xdc4b ), + SHC( 0x74a8 ), + SHC( 0xcb54 ), + SHC( 0x6c12 ), + SHC( 0xbb6b ), + SHC( 0x6154 ), + SHC( 0xacdf ), + SHC( 0x54a5 ), + SHC( 0x9ffd ), + SHC( 0x4646 ), + SHC( 0x9505 ), + SHC( 0x367f ), + SHC( 0x8c2f ), + SHC( 0x25a3 ), + SHC( 0x85a9 ), + SHC( 0x1406 ), + SHC( 0x8194 ), + SHC( 0x0202 ), + SHC( 0x8005 ), + SHC( 0xeff6 ), + SHC( 0x8103 ), + SHC( 0xde3a ), + SHC( 0x848a ), + SHC( 0xcd2b ), + SHC( 0x8a88 ), + SHC( 0xbd1f ), + SHC( 0x92dd ), + SHC( 0xae69 ), + SHC( 0x9d60 ), + SHC( 0xa154 ), + SHC( 0xa9db ), + SHC( 0x9623 ), + SHC( 0xb80e ), + SHC( 0x8d0e ), + SHC( 0xc7b1 ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7e18 ), + SHC( 0xe9ff ), + SHC( 0x786e ), + SHC( 0xd4a5 ), + SHC( 0x6f2f ), + SHC( 0xc095 ), + SHC( 0x62a0 ), + SHC( 0xae69 ), + SHC( 0x5321 ), + SHC( 0x9eac ), + SHC( 0x4128 ), + SHC( 0x91d4 ), + SHC( 0x2d3e ), + SHC( 0x8844 ), + SHC( 0x17fc ), + SHC( 0x8245 ), + SHC( 0x0202 ), + SHC( 0x8005 ), + SHC( 0xebfa ), + SHC( 0x8194 ), + SHC( 0xd68a ), + SHC( 0x86e7 ), + SHC( 0xc256 ), + SHC( 0x8fd6 ), + SHC( 0xaff9 ), + SHC( 0x9c1b ), + SHC( 0x9ffd ), + SHC( 0xab5b ), + SHC( 0x92dd ), + SHC( 0xbd1f ), + SHC( 0x88fe ), + SHC( 0xd0e2 ), + SHC( 0x82a9 ), + SHC( 0xe60c ), + SHC( 0x8011 ), + SHC( 0xfbfb ), + SHC( 0x8147 ), + SHC( 0x1209 ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7d57 ), + SHC( 0xe60c ), + SHC( 0x7578 ), + SHC( 0xcd2b ), + SHC( 0x68b9 ), + SHC( 0xb667 ), + SHC( 0x579f ), + SHC( 0xa2b2 ), + SHC( 0x42e1 ), + SHC( 0x92dd ), + SHC( 0x2b5b ), + SHC( 0x8792 ), + SHC( 0x1209 ), + SHC( 0x8147 ), + SHC( 0xf7f7 ), + SHC( 0x8041 ), + SHC( 0xde3a ), + SHC( 0x848a ), + SHC( 0xc5e4 ), + SHC( 0x8df4 ), + SHC( 0xaff9 ), + SHC( 0x9c1b ), + SHC( 0x9d60 ), + SHC( 0xae69 ), + SHC( 0x8ee1 ), + SHC( 0xc41b ), + SHC( 0x8516 ), + SHC( 0xdc4b ), + SHC( 0x8066 ), + SHC( 0xf5f6 ), + SHC( 0x8103 ), + SHC( 0x100a ), + SHC( 0x86e7 ), + SHC( 0x2976 ), + SHC( 0x91d4 ), + SHC( 0x4128 ), + SHC( 0xa154 ), + SHC( 0x5625 ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7c76 ), + SHC( 0xe21f ), + SHC( 0x720c ), + SHC( 0xc5e4 ), + SHC( 0x6154 ), + SHC( 0xacdf ), + SHC( 0x4b3c ), + SHC( 0x9873 ), + SHC( 0x30fb ), + SHC( 0x89bf ), + SHC( 0x1406 ), + SHC( 0x8194 ), + SHC( 0xf5f6 ), + SHC( 0x8066 ), + SHC( 0xd873 ), + SHC( 0x8644 ), + SHC( 0xbd1f ), + SHC( 0x92dd ), + SHC( 0xa57e ), + SHC( 0xa57e ), + SHC( 0x92dd ), + SHC( 0xbd1f ), + SHC( 0x8644 ), + SHC( 0xd873 ), + SHC( 0x8066 ), + SHC( 0xf5f6 ), + SHC( 0x8194 ), + SHC( 0x1406 ), + SHC( 0x89bf ), + SHC( 0x30fb ), + SHC( 0x9873 ), + SHC( 0x4b3c ), + SHC( 0xacdf ), + SHC( 0x6154 ), + SHC( 0xc5e4 ), + SHC( 0x720c ), + SHC( 0xe21f ), + SHC( 0x7c76 ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7b76 ), + SHC( 0xde3a ), + SHC( 0x6e2c ), + SHC( 0xbed8 ), + SHC( 0x5913 ), + SHC( 0xa415 ), + SHC( 0x3daa ), + SHC( 0x8fd6 ), + SHC( 0x1de1 ), + SHC( 0x838a ), + SHC( 0xfbfb ), + SHC( 0x8011 ), + SHC( 0xda5d ), + SHC( 0x85a9 ), + SHC( 0xbb6b ), + SHC( 0x93ee ), + SHC( 0xa154 ), + SHC( 0xa9db ), + SHC( 0x8df4 ), + SHC( 0xc5e4 ), + SHC( 0x82a9 ), + SHC( 0xe60c ), + SHC( 0x8041 ), + SHC( 0x0809 ), + SHC( 0x86e7 ), + SHC( 0x2976 ), + SHC( 0x9623 ), + SHC( 0x47f2 ), + SHC( 0xacdf ), + SHC( 0x6154 ), + SHC( 0xc981 ), + SHC( 0x73d1 ), + SHC( 0xe9ff ), + SHC( 0x7e18 ), + SHC( 0x0c0b ), + SHC( 0x7f6e ), + SHC( 0x2d3e ), + SHC( 0x77bc ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7a57 ), + SHC( 0xda5d ), + SHC( 0x69dd ), + SHC( 0xb80e ), + SHC( 0x5007 ), + SHC( 0x9c1b ), + SHC( 0x2f1e ), + SHC( 0x88fe ), + SHC( 0x0a0a ), + SHC( 0x8066 ), + SHC( 0xe414 ), + SHC( 0x8316 ), + SHC( 0xc095 ), + SHC( 0x90d1 ), + SHC( 0xa2b2 ), + SHC( 0xa861 ), + SHC( 0x8d0e ), + SHC( 0xc7b1 ), + SHC( 0x8194 ), + SHC( 0xebfa ), + SHC( 0x8147 ), + SHC( 0x1209 ), + SHC( 0x8c2f ), + SHC( 0x367f ), + SHC( 0xa154 ), + SHC( 0x5625 ), + SHC( 0xbed8 ), + SHC( 0x6e2c ), + SHC( 0xe21f ), + SHC( 0x7c76 ), + SHC( 0x0809 ), + SHC( 0x7fbf ), + SHC( 0x2d3e ), + SHC( 0x77bc ), + SHC( 0x4e73 ), + SHC( 0x6523 ), + SHC( 0x68b9 ), + SHC( 0x4999 ), }; -const Word16 FFT_RotVector_256_fx[ 448 ] = { - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7ff6 ), SHC( 0xfcdc ), SHC( 0x7fd8 ), SHC( 0xf9b9 ), SHC( 0x7fa7 ), SHC( 0xf696 ), - SHC( 0x7f62 ), SHC( 0xf375 ), SHC( 0x7f09 ), SHC( 0xf055 ), SHC( 0x7e9d ), SHC( 0xed38 ), SHC( 0x7e1d ), SHC( 0xea1e ), - SHC( 0x7d8a ), SHC( 0xe708 ), SHC( 0x7ce3 ), SHC( 0xe3f5 ), SHC( 0x7c29 ), SHC( 0xe0e7 ), SHC( 0x7b5d ), SHC( 0xdddd ), - SHC( 0x7a7d ), SHC( 0xdad8 ), SHC( 0x798a ), SHC( 0xd7da ), SHC( 0x7884 ), SHC( 0xd4e1 ), SHC( 0x776c ), SHC( 0xd1ef ), - SHC( 0x7641 ), SHC( 0xcf05 ), SHC( 0x7504 ), SHC( 0xcc22 ), SHC( 0x73b5 ), SHC( 0xc946 ), SHC( 0x7255 ), SHC( 0xc674 ), - SHC( 0x70e2 ), SHC( 0xc3aa ), SHC( 0x6f5f ), SHC( 0xc0e9 ), SHC( 0x6dca ), SHC( 0xbe32 ), SHC( 0x6c24 ), SHC( 0xbb86 ), - SHC( 0x6a6d ), SHC( 0xb8e4 ), SHC( 0x68a6 ), SHC( 0xb64c ), SHC( 0x66cf ), SHC( 0xb3c1 ), SHC( 0x64e8 ), SHC( 0xb141 ), - SHC( 0x62f2 ), SHC( 0xaecd ), SHC( 0x60ec ), SHC( 0xac65 ), SHC( 0x5ed7 ), SHC( 0xaa0b ), SHC( 0x5cb4 ), SHC( 0xa7be ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7fd8 ), SHC( 0xf9b9 ), SHC( 0x7f62 ), SHC( 0xf375 ), SHC( 0x7e9d ), SHC( 0xed38 ), - SHC( 0x7d8a ), SHC( 0xe708 ), SHC( 0x7c29 ), SHC( 0xe0e7 ), SHC( 0x7a7d ), SHC( 0xdad8 ), SHC( 0x7884 ), SHC( 0xd4e1 ), - SHC( 0x7641 ), SHC( 0xcf05 ), SHC( 0x73b5 ), SHC( 0xc946 ), SHC( 0x70e2 ), SHC( 0xc3aa ), SHC( 0x6dca ), SHC( 0xbe32 ), - SHC( 0x6a6d ), SHC( 0xb8e4 ), SHC( 0x66cf ), SHC( 0xb3c1 ), SHC( 0x62f2 ), SHC( 0xaecd ), SHC( 0x5ed7 ), SHC( 0xaa0b ), - SHC( 0x5a82 ), SHC( 0xa57e ), SHC( 0x55f5 ), SHC( 0xa129 ), SHC( 0x5133 ), SHC( 0x9d0e ), SHC( 0x4c3f ), SHC( 0x9931 ), - SHC( 0x471c ), SHC( 0x9593 ), SHC( 0x41ce ), SHC( 0x9236 ), SHC( 0x3c56 ), SHC( 0x8f1e ), SHC( 0x36ba ), SHC( 0x8c4b ), - SHC( 0x30fb ), SHC( 0x89bf ), SHC( 0x2b1f ), SHC( 0x877c ), SHC( 0x2528 ), SHC( 0x8583 ), SHC( 0x1f19 ), SHC( 0x83d7 ), - SHC( 0x18f8 ), SHC( 0x8276 ), SHC( 0x12c8 ), SHC( 0x8163 ), SHC( 0x0c8b ), SHC( 0x809e ), SHC( 0x0647 ), SHC( 0x8028 ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7fa7 ), SHC( 0xf696 ), SHC( 0x7e9d ), SHC( 0xed38 ), SHC( 0x7ce3 ), SHC( 0xe3f5 ), - SHC( 0x7a7d ), SHC( 0xdad8 ), SHC( 0x776c ), SHC( 0xd1ef ), SHC( 0x73b5 ), SHC( 0xc946 ), SHC( 0x6f5f ), SHC( 0xc0e9 ), - SHC( 0x6a6d ), SHC( 0xb8e4 ), SHC( 0x64e8 ), SHC( 0xb141 ), SHC( 0x5ed7 ), SHC( 0xaa0b ), SHC( 0x5842 ), SHC( 0xa34c ), - SHC( 0x5133 ), SHC( 0x9d0e ), SHC( 0x49b4 ), SHC( 0x975a ), SHC( 0x41ce ), SHC( 0x9236 ), SHC( 0x398c ), SHC( 0x8dab ), - SHC( 0x30fb ), SHC( 0x89bf ), SHC( 0x2826 ), SHC( 0x8676 ), SHC( 0x1f19 ), SHC( 0x83d7 ), SHC( 0x15e2 ), SHC( 0x81e3 ), - SHC( 0x0c8b ), SHC( 0x809e ), SHC( 0x0324 ), SHC( 0x800a ), SHC( 0xf9b9 ), SHC( 0x8028 ), SHC( 0xf055 ), SHC( 0x80f7 ), - SHC( 0xe708 ), SHC( 0x8276 ), SHC( 0xdddd ), SHC( 0x84a3 ), SHC( 0xd4e1 ), SHC( 0x877c ), SHC( 0xcc22 ), SHC( 0x8afc ), - SHC( 0xc3aa ), SHC( 0x8f1e ), SHC( 0xbb86 ), SHC( 0x93dc ), SHC( 0xb3c1 ), SHC( 0x9931 ), SHC( 0xac65 ), SHC( 0x9f14 ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7f62 ), SHC( 0xf375 ), SHC( 0x7d8a ), SHC( 0xe708 ), SHC( 0x7a7d ), SHC( 0xdad8 ), - SHC( 0x7641 ), SHC( 0xcf05 ), SHC( 0x70e2 ), SHC( 0xc3aa ), SHC( 0x6a6d ), SHC( 0xb8e4 ), SHC( 0x62f2 ), SHC( 0xaecd ), - SHC( 0x5a82 ), SHC( 0xa57e ), SHC( 0x5133 ), SHC( 0x9d0e ), SHC( 0x471c ), SHC( 0x9593 ), SHC( 0x3c56 ), SHC( 0x8f1e ), - SHC( 0x30fb ), SHC( 0x89bf ), SHC( 0x2528 ), SHC( 0x8583 ), SHC( 0x18f8 ), SHC( 0x8276 ), SHC( 0x0c8b ), SHC( 0x809e ), - SHC( 0x0000 ), SHC( 0x8000 ), SHC( 0xf375 ), SHC( 0x809e ), SHC( 0xe708 ), SHC( 0x8276 ), SHC( 0xdad8 ), SHC( 0x8583 ), - SHC( 0xcf05 ), SHC( 0x89bf ), SHC( 0xc3aa ), SHC( 0x8f1e ), SHC( 0xb8e4 ), SHC( 0x9593 ), SHC( 0xaecd ), SHC( 0x9d0e ), - SHC( 0xa57e ), SHC( 0xa57e ), SHC( 0x9d0e ), SHC( 0xaecd ), SHC( 0x9593 ), SHC( 0xb8e4 ), SHC( 0x8f1e ), SHC( 0xc3aa ), - SHC( 0x89bf ), SHC( 0xcf05 ), SHC( 0x8583 ), SHC( 0xdad8 ), SHC( 0x8276 ), SHC( 0xe708 ), SHC( 0x809e ), SHC( 0xf375 ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7f09 ), SHC( 0xf055 ), SHC( 0x7c29 ), SHC( 0xe0e7 ), SHC( 0x776c ), SHC( 0xd1ef ), - SHC( 0x70e2 ), SHC( 0xc3aa ), SHC( 0x68a6 ), SHC( 0xb64c ), SHC( 0x5ed7 ), SHC( 0xaa0b ), SHC( 0x539b ), SHC( 0x9f14 ), - SHC( 0x471c ), SHC( 0x9593 ), SHC( 0x398c ), SHC( 0x8dab ), SHC( 0x2b1f ), SHC( 0x877c ), SHC( 0x1c0b ), SHC( 0x831d ), - SHC( 0x0c8b ), SHC( 0x809e ), SHC( 0xfcdc ), SHC( 0x800a ), SHC( 0xed38 ), SHC( 0x8163 ), SHC( 0xdddd ), SHC( 0x84a3 ), - SHC( 0xcf05 ), SHC( 0x89bf ), SHC( 0xc0e9 ), SHC( 0x90a1 ), SHC( 0xb3c1 ), SHC( 0x9931 ), SHC( 0xa7be ), SHC( 0xa34c ), - SHC( 0x9d0e ), SHC( 0xaecd ), SHC( 0x93dc ), SHC( 0xbb86 ), SHC( 0x8c4b ), SHC( 0xc946 ), SHC( 0x8676 ), SHC( 0xd7da ), - SHC( 0x8276 ), SHC( 0xe708 ), SHC( 0x8059 ), SHC( 0xf696 ), SHC( 0x8028 ), SHC( 0x0647 ), SHC( 0x81e3 ), SHC( 0x15e2 ), - SHC( 0x8583 ), SHC( 0x2528 ), SHC( 0x8afc ), SHC( 0x33de ), SHC( 0x9236 ), SHC( 0x41ce ), SHC( 0x9b18 ), SHC( 0x4ebf ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7e9d ), SHC( 0xed38 ), SHC( 0x7a7d ), SHC( 0xdad8 ), SHC( 0x73b5 ), SHC( 0xc946 ), - SHC( 0x6a6d ), SHC( 0xb8e4 ), SHC( 0x5ed7 ), SHC( 0xaa0b ), SHC( 0x5133 ), SHC( 0x9d0e ), SHC( 0x41ce ), SHC( 0x9236 ), - SHC( 0x30fb ), SHC( 0x89bf ), SHC( 0x1f19 ), SHC( 0x83d7 ), SHC( 0x0c8b ), SHC( 0x809e ), SHC( 0xf9b9 ), SHC( 0x8028 ), - SHC( 0xe708 ), SHC( 0x8276 ), SHC( 0xd4e1 ), SHC( 0x877c ), SHC( 0xc3aa ), SHC( 0x8f1e ), SHC( 0xb3c1 ), SHC( 0x9931 ), - SHC( 0xa57e ), SHC( 0xa57e ), SHC( 0x9931 ), SHC( 0xb3c1 ), SHC( 0x8f1e ), SHC( 0xc3aa ), SHC( 0x877c ), SHC( 0xd4e1 ), - SHC( 0x8276 ), SHC( 0xe708 ), SHC( 0x8028 ), SHC( 0xf9b9 ), SHC( 0x809e ), SHC( 0x0c8b ), SHC( 0x83d7 ), SHC( 0x1f19 ), - SHC( 0x89bf ), SHC( 0x30fb ), SHC( 0x9236 ), SHC( 0x41ce ), SHC( 0x9d0e ), SHC( 0x5133 ), SHC( 0xaa0b ), SHC( 0x5ed7 ), - SHC( 0xb8e4 ), SHC( 0x6a6d ), SHC( 0xc946 ), SHC( 0x73b5 ), SHC( 0xdad8 ), SHC( 0x7a7d ), SHC( 0xed38 ), SHC( 0x7e9d ), - SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7e1d ), SHC( 0xea1e ), SHC( 0x7884 ), SHC( 0xd4e1 ), SHC( 0x6f5f ), SHC( 0xc0e9 ), - SHC( 0x62f2 ), SHC( 0xaecd ), SHC( 0x539b ), SHC( 0x9f14 ), SHC( 0x41ce ), SHC( 0x9236 ), SHC( 0x2e11 ), SHC( 0x8894 ), - SHC( 0x18f8 ), SHC( 0x8276 ), SHC( 0x0324 ), SHC( 0x800a ), SHC( 0xed38 ), SHC( 0x8163 ), SHC( 0xd7da ), SHC( 0x8676 ), - SHC( 0xc3aa ), SHC( 0x8f1e ), SHC( 0xb141 ), SHC( 0x9b18 ), SHC( 0xa129 ), SHC( 0xaa0b ), SHC( 0x93dc ), SHC( 0xbb86 ), - SHC( 0x89bf ), SHC( 0xcf05 ), SHC( 0x831d ), SHC( 0xe3f5 ), SHC( 0x8028 ), SHC( 0xf9b9 ), SHC( 0x80f7 ), SHC( 0x0fab ), - SHC( 0x8583 ), SHC( 0x2528 ), SHC( 0x8dab ), SHC( 0x398c ), SHC( 0x9931 ), SHC( 0x4c3f ), SHC( 0xa7be ), SHC( 0x5cb4 ), - SHC( 0xb8e4 ), SHC( 0x6a6d ), SHC( 0xcc22 ), SHC( 0x7504 ), SHC( 0xe0e7 ), SHC( 0x7c29 ), SHC( 0xf696 ), SHC( 0x7fa7 ), - SHC( 0x0c8b ), SHC( 0x7f62 ), SHC( 0x2223 ), SHC( 0x7b5d ), SHC( 0x36ba ), SHC( 0x73b5 ), SHC( 0x49b4 ), SHC( 0x68a6 ), +const Word16 FFT_RotVector_256_fx[448] = { + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7ff6 ), + SHC( 0xfcdc ), + SHC( 0x7fd8 ), + SHC( 0xf9b9 ), + SHC( 0x7fa7 ), + SHC( 0xf696 ), + SHC( 0x7f62 ), + SHC( 0xf375 ), + SHC( 0x7f09 ), + SHC( 0xf055 ), + SHC( 0x7e9d ), + SHC( 0xed38 ), + SHC( 0x7e1d ), + SHC( 0xea1e ), + SHC( 0x7d8a ), + SHC( 0xe708 ), + SHC( 0x7ce3 ), + SHC( 0xe3f5 ), + SHC( 0x7c29 ), + SHC( 0xe0e7 ), + SHC( 0x7b5d ), + SHC( 0xdddd ), + SHC( 0x7a7d ), + SHC( 0xdad8 ), + SHC( 0x798a ), + SHC( 0xd7da ), + SHC( 0x7884 ), + SHC( 0xd4e1 ), + SHC( 0x776c ), + SHC( 0xd1ef ), + SHC( 0x7641 ), + SHC( 0xcf05 ), + SHC( 0x7504 ), + SHC( 0xcc22 ), + SHC( 0x73b5 ), + SHC( 0xc946 ), + SHC( 0x7255 ), + SHC( 0xc674 ), + SHC( 0x70e2 ), + SHC( 0xc3aa ), + SHC( 0x6f5f ), + SHC( 0xc0e9 ), + SHC( 0x6dca ), + SHC( 0xbe32 ), + SHC( 0x6c24 ), + SHC( 0xbb86 ), + SHC( 0x6a6d ), + SHC( 0xb8e4 ), + SHC( 0x68a6 ), + SHC( 0xb64c ), + SHC( 0x66cf ), + SHC( 0xb3c1 ), + SHC( 0x64e8 ), + SHC( 0xb141 ), + SHC( 0x62f2 ), + SHC( 0xaecd ), + SHC( 0x60ec ), + SHC( 0xac65 ), + SHC( 0x5ed7 ), + SHC( 0xaa0b ), + SHC( 0x5cb4 ), + SHC( 0xa7be ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7fd8 ), + SHC( 0xf9b9 ), + SHC( 0x7f62 ), + SHC( 0xf375 ), + SHC( 0x7e9d ), + SHC( 0xed38 ), + SHC( 0x7d8a ), + SHC( 0xe708 ), + SHC( 0x7c29 ), + SHC( 0xe0e7 ), + SHC( 0x7a7d ), + SHC( 0xdad8 ), + SHC( 0x7884 ), + SHC( 0xd4e1 ), + SHC( 0x7641 ), + SHC( 0xcf05 ), + SHC( 0x73b5 ), + SHC( 0xc946 ), + SHC( 0x70e2 ), + SHC( 0xc3aa ), + SHC( 0x6dca ), + SHC( 0xbe32 ), + SHC( 0x6a6d ), + SHC( 0xb8e4 ), + SHC( 0x66cf ), + SHC( 0xb3c1 ), + SHC( 0x62f2 ), + SHC( 0xaecd ), + SHC( 0x5ed7 ), + SHC( 0xaa0b ), + SHC( 0x5a82 ), + SHC( 0xa57e ), + SHC( 0x55f5 ), + SHC( 0xa129 ), + SHC( 0x5133 ), + SHC( 0x9d0e ), + SHC( 0x4c3f ), + SHC( 0x9931 ), + SHC( 0x471c ), + SHC( 0x9593 ), + SHC( 0x41ce ), + SHC( 0x9236 ), + SHC( 0x3c56 ), + SHC( 0x8f1e ), + SHC( 0x36ba ), + SHC( 0x8c4b ), + SHC( 0x30fb ), + SHC( 0x89bf ), + SHC( 0x2b1f ), + SHC( 0x877c ), + SHC( 0x2528 ), + SHC( 0x8583 ), + SHC( 0x1f19 ), + SHC( 0x83d7 ), + SHC( 0x18f8 ), + SHC( 0x8276 ), + SHC( 0x12c8 ), + SHC( 0x8163 ), + SHC( 0x0c8b ), + SHC( 0x809e ), + SHC( 0x0647 ), + SHC( 0x8028 ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7fa7 ), + SHC( 0xf696 ), + SHC( 0x7e9d ), + SHC( 0xed38 ), + SHC( 0x7ce3 ), + SHC( 0xe3f5 ), + SHC( 0x7a7d ), + SHC( 0xdad8 ), + SHC( 0x776c ), + SHC( 0xd1ef ), + SHC( 0x73b5 ), + SHC( 0xc946 ), + SHC( 0x6f5f ), + SHC( 0xc0e9 ), + SHC( 0x6a6d ), + SHC( 0xb8e4 ), + SHC( 0x64e8 ), + SHC( 0xb141 ), + SHC( 0x5ed7 ), + SHC( 0xaa0b ), + SHC( 0x5842 ), + SHC( 0xa34c ), + SHC( 0x5133 ), + SHC( 0x9d0e ), + SHC( 0x49b4 ), + SHC( 0x975a ), + SHC( 0x41ce ), + SHC( 0x9236 ), + SHC( 0x398c ), + SHC( 0x8dab ), + SHC( 0x30fb ), + SHC( 0x89bf ), + SHC( 0x2826 ), + SHC( 0x8676 ), + SHC( 0x1f19 ), + SHC( 0x83d7 ), + SHC( 0x15e2 ), + SHC( 0x81e3 ), + SHC( 0x0c8b ), + SHC( 0x809e ), + SHC( 0x0324 ), + SHC( 0x800a ), + SHC( 0xf9b9 ), + SHC( 0x8028 ), + SHC( 0xf055 ), + SHC( 0x80f7 ), + SHC( 0xe708 ), + SHC( 0x8276 ), + SHC( 0xdddd ), + SHC( 0x84a3 ), + SHC( 0xd4e1 ), + SHC( 0x877c ), + SHC( 0xcc22 ), + SHC( 0x8afc ), + SHC( 0xc3aa ), + SHC( 0x8f1e ), + SHC( 0xbb86 ), + SHC( 0x93dc ), + SHC( 0xb3c1 ), + SHC( 0x9931 ), + SHC( 0xac65 ), + SHC( 0x9f14 ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7f62 ), + SHC( 0xf375 ), + SHC( 0x7d8a ), + SHC( 0xe708 ), + SHC( 0x7a7d ), + SHC( 0xdad8 ), + SHC( 0x7641 ), + SHC( 0xcf05 ), + SHC( 0x70e2 ), + SHC( 0xc3aa ), + SHC( 0x6a6d ), + SHC( 0xb8e4 ), + SHC( 0x62f2 ), + SHC( 0xaecd ), + SHC( 0x5a82 ), + SHC( 0xa57e ), + SHC( 0x5133 ), + SHC( 0x9d0e ), + SHC( 0x471c ), + SHC( 0x9593 ), + SHC( 0x3c56 ), + SHC( 0x8f1e ), + SHC( 0x30fb ), + SHC( 0x89bf ), + SHC( 0x2528 ), + SHC( 0x8583 ), + SHC( 0x18f8 ), + SHC( 0x8276 ), + SHC( 0x0c8b ), + SHC( 0x809e ), + SHC( 0x0000 ), + SHC( 0x8000 ), + SHC( 0xf375 ), + SHC( 0x809e ), + SHC( 0xe708 ), + SHC( 0x8276 ), + SHC( 0xdad8 ), + SHC( 0x8583 ), + SHC( 0xcf05 ), + SHC( 0x89bf ), + SHC( 0xc3aa ), + SHC( 0x8f1e ), + SHC( 0xb8e4 ), + SHC( 0x9593 ), + SHC( 0xaecd ), + SHC( 0x9d0e ), + SHC( 0xa57e ), + SHC( 0xa57e ), + SHC( 0x9d0e ), + SHC( 0xaecd ), + SHC( 0x9593 ), + SHC( 0xb8e4 ), + SHC( 0x8f1e ), + SHC( 0xc3aa ), + SHC( 0x89bf ), + SHC( 0xcf05 ), + SHC( 0x8583 ), + SHC( 0xdad8 ), + SHC( 0x8276 ), + SHC( 0xe708 ), + SHC( 0x809e ), + SHC( 0xf375 ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7f09 ), + SHC( 0xf055 ), + SHC( 0x7c29 ), + SHC( 0xe0e7 ), + SHC( 0x776c ), + SHC( 0xd1ef ), + SHC( 0x70e2 ), + SHC( 0xc3aa ), + SHC( 0x68a6 ), + SHC( 0xb64c ), + SHC( 0x5ed7 ), + SHC( 0xaa0b ), + SHC( 0x539b ), + SHC( 0x9f14 ), + SHC( 0x471c ), + SHC( 0x9593 ), + SHC( 0x398c ), + SHC( 0x8dab ), + SHC( 0x2b1f ), + SHC( 0x877c ), + SHC( 0x1c0b ), + SHC( 0x831d ), + SHC( 0x0c8b ), + SHC( 0x809e ), + SHC( 0xfcdc ), + SHC( 0x800a ), + SHC( 0xed38 ), + SHC( 0x8163 ), + SHC( 0xdddd ), + SHC( 0x84a3 ), + SHC( 0xcf05 ), + SHC( 0x89bf ), + SHC( 0xc0e9 ), + SHC( 0x90a1 ), + SHC( 0xb3c1 ), + SHC( 0x9931 ), + SHC( 0xa7be ), + SHC( 0xa34c ), + SHC( 0x9d0e ), + SHC( 0xaecd ), + SHC( 0x93dc ), + SHC( 0xbb86 ), + SHC( 0x8c4b ), + SHC( 0xc946 ), + SHC( 0x8676 ), + SHC( 0xd7da ), + SHC( 0x8276 ), + SHC( 0xe708 ), + SHC( 0x8059 ), + SHC( 0xf696 ), + SHC( 0x8028 ), + SHC( 0x0647 ), + SHC( 0x81e3 ), + SHC( 0x15e2 ), + SHC( 0x8583 ), + SHC( 0x2528 ), + SHC( 0x8afc ), + SHC( 0x33de ), + SHC( 0x9236 ), + SHC( 0x41ce ), + SHC( 0x9b18 ), + SHC( 0x4ebf ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7e9d ), + SHC( 0xed38 ), + SHC( 0x7a7d ), + SHC( 0xdad8 ), + SHC( 0x73b5 ), + SHC( 0xc946 ), + SHC( 0x6a6d ), + SHC( 0xb8e4 ), + SHC( 0x5ed7 ), + SHC( 0xaa0b ), + SHC( 0x5133 ), + SHC( 0x9d0e ), + SHC( 0x41ce ), + SHC( 0x9236 ), + SHC( 0x30fb ), + SHC( 0x89bf ), + SHC( 0x1f19 ), + SHC( 0x83d7 ), + SHC( 0x0c8b ), + SHC( 0x809e ), + SHC( 0xf9b9 ), + SHC( 0x8028 ), + SHC( 0xe708 ), + SHC( 0x8276 ), + SHC( 0xd4e1 ), + SHC( 0x877c ), + SHC( 0xc3aa ), + SHC( 0x8f1e ), + SHC( 0xb3c1 ), + SHC( 0x9931 ), + SHC( 0xa57e ), + SHC( 0xa57e ), + SHC( 0x9931 ), + SHC( 0xb3c1 ), + SHC( 0x8f1e ), + SHC( 0xc3aa ), + SHC( 0x877c ), + SHC( 0xd4e1 ), + SHC( 0x8276 ), + SHC( 0xe708 ), + SHC( 0x8028 ), + SHC( 0xf9b9 ), + SHC( 0x809e ), + SHC( 0x0c8b ), + SHC( 0x83d7 ), + SHC( 0x1f19 ), + SHC( 0x89bf ), + SHC( 0x30fb ), + SHC( 0x9236 ), + SHC( 0x41ce ), + SHC( 0x9d0e ), + SHC( 0x5133 ), + SHC( 0xaa0b ), + SHC( 0x5ed7 ), + SHC( 0xb8e4 ), + SHC( 0x6a6d ), + SHC( 0xc946 ), + SHC( 0x73b5 ), + SHC( 0xdad8 ), + SHC( 0x7a7d ), + SHC( 0xed38 ), + SHC( 0x7e9d ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7e1d ), + SHC( 0xea1e ), + SHC( 0x7884 ), + SHC( 0xd4e1 ), + SHC( 0x6f5f ), + SHC( 0xc0e9 ), + SHC( 0x62f2 ), + SHC( 0xaecd ), + SHC( 0x539b ), + SHC( 0x9f14 ), + SHC( 0x41ce ), + SHC( 0x9236 ), + SHC( 0x2e11 ), + SHC( 0x8894 ), + SHC( 0x18f8 ), + SHC( 0x8276 ), + SHC( 0x0324 ), + SHC( 0x800a ), + SHC( 0xed38 ), + SHC( 0x8163 ), + SHC( 0xd7da ), + SHC( 0x8676 ), + SHC( 0xc3aa ), + SHC( 0x8f1e ), + SHC( 0xb141 ), + SHC( 0x9b18 ), + SHC( 0xa129 ), + SHC( 0xaa0b ), + SHC( 0x93dc ), + SHC( 0xbb86 ), + SHC( 0x89bf ), + SHC( 0xcf05 ), + SHC( 0x831d ), + SHC( 0xe3f5 ), + SHC( 0x8028 ), + SHC( 0xf9b9 ), + SHC( 0x80f7 ), + SHC( 0x0fab ), + SHC( 0x8583 ), + SHC( 0x2528 ), + SHC( 0x8dab ), + SHC( 0x398c ), + SHC( 0x9931 ), + SHC( 0x4c3f ), + SHC( 0xa7be ), + SHC( 0x5cb4 ), + SHC( 0xb8e4 ), + SHC( 0x6a6d ), + SHC( 0xcc22 ), + SHC( 0x7504 ), + SHC( 0xe0e7 ), + SHC( 0x7c29 ), + SHC( 0xf696 ), + SHC( 0x7fa7 ), + SHC( 0x0c8b ), + SHC( 0x7f62 ), + SHC( 0x2223 ), + SHC( 0x7b5d ), + SHC( 0x36ba ), + SHC( 0x73b5 ), + SHC( 0x49b4 ), + SHC( 0x68a6 ), }; -const Word16 FFT_RotVector_32_fx[ 40 ] = { - SHC( 0x7d8a ), SHC( 0xe708 ), SHC( 0x7641 ), SHC( 0xcf05 ), SHC( 0x6a6d ), SHC( 0xb8e4 ), SHC( 0x5a82 ), SHC( 0xa57e ), - SHC( 0x471c ), SHC( 0x9593 ), SHC( 0x30fb ), SHC( 0x89bf ), SHC( 0x18f8 ), SHC( 0x8276 ), SHC( 0x7641 ), SHC( 0xcf05 ), - SHC( 0x5a82 ), SHC( 0xa57e ), SHC( 0x30fb ), SHC( 0x89bf ), SHC( 0xcf05 ), SHC( 0x89bf ), SHC( 0xa57e ), SHC( 0xa57e ), - SHC( 0x89bf ), SHC( 0xcf05 ), SHC( 0x6a6d ), SHC( 0xb8e4 ), SHC( 0x30fb ), SHC( 0x89bf ), SHC( 0xe708 ), SHC( 0x8276 ), - SHC( 0xa57e ), SHC( 0xa57e ), SHC( 0x8276 ), SHC( 0xe708 ), SHC( 0x89bf ), SHC( 0x30fb ), SHC( 0xb8e4 ), SHC( 0x6a6d ), +const Word16 FFT_RotVector_32_fx[40] = { + SHC( 0x7d8a ), + SHC( 0xe708 ), + SHC( 0x7641 ), + SHC( 0xcf05 ), + SHC( 0x6a6d ), + SHC( 0xb8e4 ), + SHC( 0x5a82 ), + SHC( 0xa57e ), + SHC( 0x471c ), + SHC( 0x9593 ), + SHC( 0x30fb ), + SHC( 0x89bf ), + SHC( 0x18f8 ), + SHC( 0x8276 ), + SHC( 0x7641 ), + SHC( 0xcf05 ), + SHC( 0x5a82 ), + SHC( 0xa57e ), + SHC( 0x30fb ), + SHC( 0x89bf ), + SHC( 0xcf05 ), + SHC( 0x89bf ), + SHC( 0xa57e ), + SHC( 0xa57e ), + SHC( 0x89bf ), + SHC( 0xcf05 ), + SHC( 0x6a6d ), + SHC( 0xb8e4 ), + SHC( 0x30fb ), + SHC( 0x89bf ), + SHC( 0xe708 ), + SHC( 0x8276 ), + SHC( 0xa57e ), + SHC( 0xa57e ), + SHC( 0x8276 ), + SHC( 0xe708 ), + SHC( 0x89bf ), + SHC( 0x30fb ), + SHC( 0xb8e4 ), + SHC( 0x6a6d ), }; -const Word16 cos_twiddle_table_25_5_5[ 25 ] = { - SHC( 0x7fff ), SHC( 0x7fff ), SHC( 0x7fff ), SHC( 0x7fff ), SHC( 0x7fff ), - SHC( 0x7fff ), SHC( 0x7bfa ), SHC( 0x702a ), SHC( 0x5d4e ), SHC( 0x4495 ), - SHC( 0x7fff ), SHC( 0x702a ), SHC( 0x4495 ), SHC( 0x0809 ), SHC( 0xc981 ), - SHC( 0x7fff ), SHC( 0x5d4e ), SHC( 0x0809 ), SHC( 0xae69 ), SHC( 0x8103 ), - SHC( 0x7fff ), SHC( 0x4495 ), SHC( 0xc981 ), SHC( 0x8103 ), SHC( 0xae69 ), +const Word16 cos_twiddle_table_25_5_5[25] = { + SHC( 0x7fff ), + SHC( 0x7fff ), + SHC( 0x7fff ), + SHC( 0x7fff ), + SHC( 0x7fff ), + SHC( 0x7fff ), + SHC( 0x7bfa ), + SHC( 0x702a ), + SHC( 0x5d4e ), + SHC( 0x4495 ), + SHC( 0x7fff ), + SHC( 0x702a ), + SHC( 0x4495 ), + SHC( 0x0809 ), + SHC( 0xc981 ), + SHC( 0x7fff ), + SHC( 0x5d4e ), + SHC( 0x0809 ), + SHC( 0xae69 ), + SHC( 0x8103 ), + SHC( 0x7fff ), + SHC( 0x4495 ), + SHC( 0xc981 ), + SHC( 0x8103 ), + SHC( 0xae69 ), }; -const Word16 sin_twiddle_table_25_5_5[ 25 ] = { - SHC( 0x0000 ), SHC( 0x0000 ), SHC( 0x0000 ), SHC( 0x0000 ), SHC( 0x0000 ), - SHC( 0x0000 ), SHC( 0xe02b ), SHC( 0xc256 ), SHC( 0xa861 ), SHC( 0x93ee ), - SHC( 0x0000 ), SHC( 0xc256 ), SHC( 0x93ee ), SHC( 0x8041 ), SHC( 0x8c2f ), - SHC( 0x0000 ), SHC( 0xa861 ), SHC( 0x8041 ), SHC( 0x9d60 ), SHC( 0xeff6 ), - SHC( 0x0000 ), SHC( 0x93ee ), SHC( 0x8c2f ), SHC( 0xeff6 ), SHC( 0x62a0 ), +const Word16 sin_twiddle_table_25_5_5[25] = { + SHC( 0x0000 ), + SHC( 0x0000 ), + SHC( 0x0000 ), + SHC( 0x0000 ), + SHC( 0x0000 ), + SHC( 0x0000 ), + SHC( 0xe02b ), + SHC( 0xc256 ), + SHC( 0xa861 ), + SHC( 0x93ee ), + SHC( 0x0000 ), + SHC( 0xc256 ), + SHC( 0x93ee ), + SHC( 0x8041 ), + SHC( 0x8c2f ), + SHC( 0x0000 ), + SHC( 0xa861 ), + SHC( 0x8041 ), + SHC( 0x9d60 ), + SHC( 0xeff6 ), + SHC( 0x0000 ), + SHC( 0x93ee ), + SHC( 0x8c2f ), + SHC( 0xeff6 ), + SHC( 0x62a0 ), }; -const Word16 cos_twiddle_table_16_8_2[ 16 ] = { - SHC( 0x7fff ), SHC( 0x7fff ), - SHC( 0x7fff ), SHC( 0x7641 ), - SHC( 0x7fff ), SHC( 0x5a82 ), - SHC( 0x7fff ), SHC( 0x30fb ), - SHC( 0x7fff ), SHC( 0x0000 ), - SHC( 0x7fff ), SHC( 0xcf05 ), - SHC( 0x7fff ), SHC( 0xa57e ), - SHC( 0x7fff ), SHC( 0x89bf ), +const Word16 cos_twiddle_table_16_8_2[16] = { + SHC( 0x7fff ), + SHC( 0x7fff ), + SHC( 0x7fff ), + SHC( 0x7641 ), + SHC( 0x7fff ), + SHC( 0x5a82 ), + SHC( 0x7fff ), + SHC( 0x30fb ), + SHC( 0x7fff ), + SHC( 0x0000 ), + SHC( 0x7fff ), + SHC( 0xcf05 ), + SHC( 0x7fff ), + SHC( 0xa57e ), + SHC( 0x7fff ), + SHC( 0x89bf ), }; -const Word16 sin_twiddle_table_16_8_2[ 16 ] = { - SHC( 0x0000 ), SHC( 0x0000 ), - SHC( 0x0000 ), SHC( 0xcf05 ), - SHC( 0x0000 ), SHC( 0xa57e ), - SHC( 0x0000 ), SHC( 0x89bf ), - SHC( 0x0000 ), SHC( 0x8000 ), - SHC( 0x0000 ), SHC( 0x89bf ), - SHC( 0x0000 ), SHC( 0xa57e ), - SHC( 0x0000 ), SHC( 0xcf05 ), +const Word16 sin_twiddle_table_16_8_2[16] = { + SHC( 0x0000 ), + SHC( 0x0000 ), + SHC( 0x0000 ), + SHC( 0xcf05 ), + SHC( 0x0000 ), + SHC( 0xa57e ), + SHC( 0x0000 ), + SHC( 0x89bf ), + SHC( 0x0000 ), + SHC( 0x8000 ), + SHC( 0x0000 ), + SHC( 0x89bf ), + SHC( 0x0000 ), + SHC( 0xa57e ), + SHC( 0x0000 ), + SHC( 0xcf05 ), }; #if 0 -#define Flt2Word16(a) SHC((Word16) (a * 32768.0)) +#define Flt2Word16( a ) SHC( (Word16) ( a * 32768.0 ) ) const Word16 w_edct2_64_fx[80] = diff --git a/lib_com/rom_com_fx.h b/lib_com/rom_com_fx.h index 20692d0e6..a07774106 100644 --- a/lib_com/rom_com_fx.h +++ b/lib_com/rom_com_fx.h @@ -62,10 +62,10 @@ extern const Word16 FFT_RotVector_32_fx[40]; extern const Word16 sincos_t_rad3_fx[T_SIN_PI_2 + 1]; -extern const Word16 cos_twiddle_table_25_5_5[ 25 ]; -extern const Word16 sin_twiddle_table_25_5_5[ 25 ]; -extern const Word16 cos_twiddle_table_16_8_2[ 16 ]; -extern const Word16 sin_twiddle_table_16_8_2[ 16 ]; +extern const Word16 cos_twiddle_table_25_5_5[25]; +extern const Word16 sin_twiddle_table_25_5_5[25]; +extern const Word16 cos_twiddle_table_16_8_2[16]; +extern const Word16 sin_twiddle_table_16_8_2[16]; extern const Word16 CLDFB80_10_fx[100]; diff --git a/lib_com/scale_mem_fx.c b/lib_com/scale_mem_fx.c index 511d48b96..e6ca64931 100644 --- a/lib_com/scale_mem_fx.c +++ b/lib_com/scale_mem_fx.c @@ -31,152 +31,151 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include "options.h" /* Common prototypes */ -#include "prot_fx2.h" /* Common prototypes */ +#include "options.h" /* Common prototypes */ +#include "prot_fx2.h" /* Common prototypes */ #include "ivas_cnst.h" #include "stl.h" - /*-------------------------------------------------------------------* - * Rescale_exc: - * - * Find absolute maximum of excitation - * Fin scaling factor to apply the excitation and its related memory - * Scale excitation and total excitation (exc2) - *-------------------------------------------------------------------*/ +/*-------------------------------------------------------------------* + * Rescale_exc: + * + * Find absolute maximum of excitation + * Fin scaling factor to apply the excitation and its related memory + * Scale excitation and total excitation (exc2) + *-------------------------------------------------------------------*/ Word16 Rescale_exc( - Word16 dct_post_old_exc_fx[], /* i/o: Music post processing memory */ - Word16 exc[], /* i/o: excitation to rescale Q_exc */ - Word16 bwe_exc[], - Word16 *last_exc_dct_in, - Word16 lg, /* i : frame size */ - Word16 lg32, - Word32 L_gain_code, /* i : decoded codebook gain Q16 */ - Word16 *sQ_exc, /* i/o: Excitation scaling factor */ - Word16 *sQsubfr, /* i/o: Past excitation scaling factors */ - Word16 exc2[], /* o : local excitation vector */ - Word16 i_subfr, /* i : subframe number */ - const Word16 coder_type -) + Word16 dct_post_old_exc_fx[], /* i/o: Music post processing memory */ + Word16 exc[], /* i/o: excitation to rescale Q_exc */ + Word16 bwe_exc[], + Word16 *last_exc_dct_in, + Word16 lg, /* i : frame size */ + Word16 lg32, + Word32 L_gain_code, /* i : decoded codebook gain Q16 */ + Word16 *sQ_exc, /* i/o: Excitation scaling factor */ + Word16 *sQsubfr, /* i/o: Past excitation scaling factors */ + Word16 exc2[], /* o : local excitation vector */ + Word16 i_subfr, /* i : subframe number */ + const Word16 coder_type ) { - Word16 i, tmp, max, new_Q; - - /*------------------------------------------- - * find maximum of absolute excitation - *-------------------------------------------*/ - max = s_max(abs_s(exc[0]), 1); - FOR(i = 1; i < lg; i++) - { - tmp = abs_s(exc[i]); - max = s_max(max, tmp); - } - - /*---------------------------------------------- - * find scaling (tmp) to set max = [2048..4096[ - *----------------------------------------------*/ - tmp = sub(add(norm_s(max), *sQ_exc), 3); - tmp = s_min(tmp, 12); - - /*---------------------------------------------- - * find scaling (new_Q) to keep gain_code < 2048 - *----------------------------------------------*/ - - new_Q = add(tmp, 1); - tmp = sub(norm_l(L_or(L_gain_code, 1)), 3); /* to get to 0x08000000L (L_or with 1 to avoid norm_l(0)) */ - tmp = s_min(tmp, new_Q); - tmp = s_max(tmp, 0); - tmp = sub(tmp, 1); - - /*#define REMOVE_EXCITATION_PER_FRAME_SCALING */ - - /*---------------------------------------------- - * new_Q = smallest Q since 4 subframes (20ms) - *----------------------------------------------*/ - IF(EQ_16(coder_type, TRANSITION)) - { - tmp = s_min(tmp, 7); - } - ELSE IF(EQ_16(coder_type, INACTIVE)) - { - tmp = s_min(tmp, 13); - } - ELSE IF(GT_16(lg, L_SUBFR))/* --> can only happen in AUDIO mode */ - { - tmp = s_min(tmp, 4); /* Limitation of the scaling gain because the frequency domain will add much more energy to the excitation*/ - if (GE_32(L_abs(L_gain_code), 3276800)) /*(1-gain_pit)*past gain code*4 > 50 */ - { - tmp = s_min(tmp, 2); /* Limitation of the scaling gain because the frequency domain might add much more energy to the excitation*/ - } - } - - new_Q = s_min(tmp, sQsubfr[0]); - IF(EQ_16(lg, L_SUBFR)) - { - FOR(i = L_Q_MEM - 1; i >= 1; i--) - { - new_Q = s_min(new_Q, sQsubfr[i]); - sQsubfr[i] = sQsubfr[i - 1]; - move16(); - } - } - ELSE - { - IF(EQ_16(lg, 2 * L_SUBFR)) - { - new_Q = s_min(new_Q, sQsubfr[L_Q_MEM - 1]); - FOR(i = L_Q_MEM - 1; i >= 2; i--) - { - sQsubfr[i] = sQsubfr[1]; - move16(); - } - sQsubfr[1] = tmp; - move16(); - sQsubfr[0] = tmp; - move16(); - } - ELSE - { - set16_fx(sQsubfr, tmp, L_Q_MEM); - } - } - sQsubfr[0] = tmp; - move16(); - - /*---------------------------------------------- - * rescale excitation and associated memories - *----------------------------------------------*/ - - tmp = sub(new_Q, *sQ_exc); - - IF(tmp != 0) - { - - Scale_sig(exc - L_EXC_MEM_DEC, add(L_EXC_MEM_DEC, lg), tmp); - IF(last_exc_dct_in != NULL) - { - Scale_sig(last_exc_dct_in, L_FRAME, tmp); - } - IF(bwe_exc != NULL) - { - Scale_sig(bwe_exc - PIT16k_MAX * 2, add(PIT16k_MAX * 2, lg32), tmp); - } - IF(exc2 != NULL) - { - Scale_sig(exc2, i_subfr, tmp); - } - IF(dct_post_old_exc_fx != NULL) - { - Scale_sig(dct_post_old_exc_fx, DCT_L_POST - OFFSET2, tmp); - } - } - - /* scaling factor of excitation (-1..12) */ - *sQ_exc = new_Q; - move16(); - - return tmp; + Word16 i, tmp, max, new_Q; + + /*------------------------------------------- + * find maximum of absolute excitation + *-------------------------------------------*/ + max = s_max( abs_s( exc[0] ), 1 ); + FOR( i = 1; i < lg; i++ ) + { + tmp = abs_s( exc[i] ); + max = s_max( max, tmp ); + } + + /*---------------------------------------------- + * find scaling (tmp) to set max = [2048..4096[ + *----------------------------------------------*/ + tmp = sub( add( norm_s( max ), *sQ_exc ), 3 ); + tmp = s_min( tmp, 12 ); + + /*---------------------------------------------- + * find scaling (new_Q) to keep gain_code < 2048 + *----------------------------------------------*/ + + new_Q = add( tmp, 1 ); + tmp = sub( norm_l( L_or( L_gain_code, 1 ) ), 3 ); /* to get to 0x08000000L (L_or with 1 to avoid norm_l(0)) */ + tmp = s_min( tmp, new_Q ); + tmp = s_max( tmp, 0 ); + tmp = sub( tmp, 1 ); + + /*#define REMOVE_EXCITATION_PER_FRAME_SCALING */ + + /*---------------------------------------------- + * new_Q = smallest Q since 4 subframes (20ms) + *----------------------------------------------*/ + IF( EQ_16( coder_type, TRANSITION ) ) + { + tmp = s_min( tmp, 7 ); + } + ELSE IF( EQ_16( coder_type, INACTIVE ) ) + { + tmp = s_min( tmp, 13 ); + } + ELSE IF( GT_16( lg, L_SUBFR ) ) /* --> can only happen in AUDIO mode */ + { + tmp = s_min( tmp, 4 ); /* Limitation of the scaling gain because the frequency domain will add much more energy to the excitation*/ + if ( GE_32( L_abs( L_gain_code ), 3276800 ) ) /*(1-gain_pit)*past gain code*4 > 50 */ + { + tmp = s_min( tmp, 2 ); /* Limitation of the scaling gain because the frequency domain might add much more energy to the excitation*/ + } + } + + new_Q = s_min( tmp, sQsubfr[0] ); + IF( EQ_16( lg, L_SUBFR ) ) + { + FOR( i = L_Q_MEM - 1; i >= 1; i-- ) + { + new_Q = s_min( new_Q, sQsubfr[i] ); + sQsubfr[i] = sQsubfr[i - 1]; + move16(); + } + } + ELSE + { + IF( EQ_16( lg, 2 * L_SUBFR ) ) + { + new_Q = s_min( new_Q, sQsubfr[L_Q_MEM - 1] ); + FOR( i = L_Q_MEM - 1; i >= 2; i-- ) + { + sQsubfr[i] = sQsubfr[1]; + move16(); + } + sQsubfr[1] = tmp; + move16(); + sQsubfr[0] = tmp; + move16(); + } + ELSE + { + set16_fx( sQsubfr, tmp, L_Q_MEM ); + } + } + sQsubfr[0] = tmp; + move16(); + + /*---------------------------------------------- + * rescale excitation and associated memories + *----------------------------------------------*/ + + tmp = sub( new_Q, *sQ_exc ); + + IF( tmp != 0 ) + { + + Scale_sig( exc - L_EXC_MEM_DEC, add( L_EXC_MEM_DEC, lg ), tmp ); + IF( last_exc_dct_in != NULL ) + { + Scale_sig( last_exc_dct_in, L_FRAME, tmp ); + } + IF( bwe_exc != NULL ) + { + Scale_sig( bwe_exc - PIT16k_MAX * 2, add( PIT16k_MAX * 2, lg32 ), tmp ); + } + IF( exc2 != NULL ) + { + Scale_sig( exc2, i_subfr, tmp ); + } + IF( dct_post_old_exc_fx != NULL ) + { + Scale_sig( dct_post_old_exc_fx, DCT_L_POST - OFFSET2, tmp ); + } + } + + /* scaling factor of excitation (-1..12) */ + *sQ_exc = new_Q; + move16(); + + return tmp; } /*-------------------------------------------------------------------* @@ -186,129 +185,129 @@ Word16 Rescale_exc( * Rescale excitation related memories *-------------------------------------------------------------------*/ void Rescale_mem( - const Word16 Q_exc, /* i : current excitation scaling (>=0) */ - Word16 *prev_Q_syn, /* i/o : scaling factor of previous frame */ - Word16 *Q_syn, /* i/o : scaling factor of frame */ - Word16 *mem_syn2, /* i/o : modified synthesis memory */ - Word16 *mem_syn_clas_estim_fx, /* i/o : old 12k8 core memory for classification */ - const Word16 MaxScaling, /* i: Minimal difference between excitation scaling and synthesis scaling */ - Word16 *mem_deemph, /* i/o: speech deemph filter memory */ - Word16 *pst_old_syn, /* i/o: psfiler */ - Word16 *pst_mem_deemp_err, /* i/o: psfiler */ - Word16 *mem_agc, - PFSTAT_HANDLE hPFstat, /* i/o: All memories related to NB post filter */ - const Word16 Vad_flag, - const Word16 Cna_flag, - const Word16 *tmp_buffer /* tmp_buffer in Q-1 */ + const Word16 Q_exc, /* i : current excitation scaling (>=0) */ + Word16 *prev_Q_syn, /* i/o : scaling factor of previous frame */ + Word16 *Q_syn, /* i/o : scaling factor of frame */ + Word16 *mem_syn2, /* i/o : modified synthesis memory */ + Word16 *mem_syn_clas_estim_fx, /* i/o : old 12k8 core memory for classification */ + const Word16 MaxScaling, /* i: Minimal difference between excitation scaling and synthesis scaling */ + Word16 *mem_deemph, /* i/o: speech deemph filter memory */ + Word16 *pst_old_syn, /* i/o: psfiler */ + Word16 *pst_mem_deemp_err, /* i/o: psfiler */ + Word16 *mem_agc, + PFSTAT_HANDLE hPFstat, /* i/o: All memories related to NB post filter */ + const Word16 Vad_flag, + const Word16 Cna_flag, + const Word16 *tmp_buffer /* tmp_buffer in Q-1 */ ) { - Word16 exp_scale, new_Q, tmp, i; - - /*-------------------------------------------------------------------* - * find scaling of synthesis (based on min of current frame and last frame) - * scaling factor of synthesis (-1..6) - *-------------------------------------------------------------------*/ - new_Q = sub(Q_exc, MaxScaling); - tmp = 1; - move16(); - IF(tmp_buffer != NULL) - { - /* use the temporary synthesis in Q-1 to estimate the scaling */ - FOR(i = 0; i < L_FRAME; i++) - { - tmp = s_max(abs_s(tmp_buffer[i]), tmp); - } - /* we add Q_syn which represents the actual scaling of the memories prev_Q_syn represents the last potential scaling */ - tmp = sub(add(norm_s(tmp), -1), 3); /* -2 ... 12 */ - } - ELSE IF(hPFstat != NULL) - { - FOR(i = 0; i < M; i++) - { - tmp = s_max(abs_s(mem_syn2[i]), tmp); - tmp = s_max(abs_s(pst_old_syn[i]), tmp); - tmp = s_max(abs_s(mem_syn_clas_estim_fx[i]), tmp); - } - FOR(; i < L_SUBFR; i++) - { - tmp = s_max(abs_s(pst_old_syn[i]), tmp); - tmp = s_max(abs_s(mem_syn_clas_estim_fx[i]), tmp); - } - FOR(; i < L_SYN_MEM_CLAS_ESTIM; i++) - { - tmp = s_max(abs_s(mem_syn_clas_estim_fx[i]), tmp); - tmp = s_max(abs_s(pst_old_syn[i]), tmp); - } - FOR(; i < NBPSF_PIT_MAX; i++) - { - tmp = s_max(abs_s(pst_old_syn[i]), tmp); - } - /* we add Q_syn which represents the actual scaling of the memories prev_Q_syn represents the last potential scaling */ - tmp = sub(add(norm_s(tmp), *Q_syn), 2); /* -2 ... 12 */ - } - - - IF(Vad_flag != 0) - { - new_Q = s_min(sub(Q_exc, 2), tmp); - } - ELSE IF(Cna_flag != 0) - { - new_Q = s_min(Q_exc, sub(tmp, 2)); - } - ELSE - { - new_Q = s_min(Q_exc, tmp); - } - new_Q = s_min(new_Q, 12); /* */ - new_Q = s_max(new_Q, -1); /* */ - - /*#define REMOVE_SYNTHESIS_PER_FRAME_SCALING */ - tmp = s_min(new_Q, *prev_Q_syn); - *prev_Q_syn = new_Q; - move16(); - - exp_scale = sub(tmp, *Q_syn); - *Q_syn = tmp; - move16(); - - /* rescale synthesis memory (mem_syn2) */ - Scale_sig(mem_syn2, M, exp_scale); - Scale_sig(mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM, exp_scale); - /*Scale_sig(core_old_syn, L_SYN_MEM, exp_scale);*/ - Scale_sig(mem_deemph, 1, exp_scale); - IF(hPFstat != NULL) + Word16 exp_scale, new_Q, tmp, i; + + /*-------------------------------------------------------------------* + * find scaling of synthesis (based on min of current frame and last frame) + * scaling factor of synthesis (-1..6) + *-------------------------------------------------------------------*/ + new_Q = sub( Q_exc, MaxScaling ); + tmp = 1; + move16(); + IF( tmp_buffer != NULL ) { - Scale_sig(pst_old_syn, NBPSF_PIT_MAX, exp_scale); - Scale_sig(pst_mem_deemp_err, 1, exp_scale); - Scale_sig(hPFstat->mem_pf_in, L_SUBFR, exp_scale); /* NB post_filter mem */ - Scale_sig(hPFstat->mem_res2, DECMEM_RES2, exp_scale); /* NB post_filter mem */ - Scale_sig(hPFstat->mem_stp, L_SUBFR, exp_scale); /* NB post_filter mem */ + /* use the temporary synthesis in Q-1 to estimate the scaling */ + FOR( i = 0; i < L_FRAME; i++ ) + { + tmp = s_max( abs_s( tmp_buffer[i] ), tmp ); + } + /* we add Q_syn which represents the actual scaling of the memories prev_Q_syn represents the last potential scaling */ + tmp = sub( add( norm_s( tmp ), -1 ), 3 ); /* -2 ... 12 */ } - Scale_sig(mem_agc, 1, exp_scale); /* NB post_filter mem */ - return; + ELSE IF( hPFstat != NULL ) + { + FOR( i = 0; i < M; i++ ) + { + tmp = s_max( abs_s( mem_syn2[i] ), tmp ); + tmp = s_max( abs_s( pst_old_syn[i] ), tmp ); + tmp = s_max( abs_s( mem_syn_clas_estim_fx[i] ), tmp ); + } + FOR( ; i < L_SUBFR; i++ ) + { + tmp = s_max( abs_s( pst_old_syn[i] ), tmp ); + tmp = s_max( abs_s( mem_syn_clas_estim_fx[i] ), tmp ); + } + FOR( ; i < L_SYN_MEM_CLAS_ESTIM; i++ ) + { + tmp = s_max( abs_s( mem_syn_clas_estim_fx[i] ), tmp ); + tmp = s_max( abs_s( pst_old_syn[i] ), tmp ); + } + FOR( ; i < NBPSF_PIT_MAX; i++ ) + { + tmp = s_max( abs_s( pst_old_syn[i] ), tmp ); + } + /* we add Q_syn which represents the actual scaling of the memories prev_Q_syn represents the last potential scaling */ + tmp = sub( add( norm_s( tmp ), *Q_syn ), 2 ); /* -2 ... 12 */ + } + + + IF( Vad_flag != 0 ) + { + new_Q = s_min( sub( Q_exc, 2 ), tmp ); + } + ELSE IF( Cna_flag != 0 ) + { + new_Q = s_min( Q_exc, sub( tmp, 2 ) ); + } + ELSE + { + new_Q = s_min( Q_exc, tmp ); + } + new_Q = s_min( new_Q, 12 ); /* */ + new_Q = s_max( new_Q, -1 ); /* */ + + /*#define REMOVE_SYNTHESIS_PER_FRAME_SCALING */ + tmp = s_min( new_Q, *prev_Q_syn ); + *prev_Q_syn = new_Q; + move16(); + + exp_scale = sub( tmp, *Q_syn ); + *Q_syn = tmp; + move16(); + + /* rescale synthesis memory (mem_syn2) */ + Scale_sig( mem_syn2, M, exp_scale ); + Scale_sig( mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM, exp_scale ); + /*Scale_sig(core_old_syn, L_SYN_MEM, exp_scale);*/ + Scale_sig( mem_deemph, 1, exp_scale ); + IF( hPFstat != NULL ) + { + Scale_sig( pst_old_syn, NBPSF_PIT_MAX, exp_scale ); + Scale_sig( pst_mem_deemp_err, 1, exp_scale ); + Scale_sig( hPFstat->mem_pf_in, L_SUBFR, exp_scale ); /* NB post_filter mem */ + Scale_sig( hPFstat->mem_res2, DECMEM_RES2, exp_scale ); /* NB post_filter mem */ + Scale_sig( hPFstat->mem_stp, L_SUBFR, exp_scale ); /* NB post_filter mem */ + } + Scale_sig( mem_agc, 1, exp_scale ); /* NB post_filter mem */ + return; } -//note_ : also present in tools_fx.c which one to take is an issue? +// note_ : also present in tools_fx.c which one to take is an issue? /*-------------------------------------------------------------------* * Scale_sig32 * Note: In order to save complexity, call function only, if exp0 != 0 * Up/down scale a 32 bits vector *-------------------------------------------------------------------*/ void scale_sig32( - Word32 x[], /* i/o: signal to scale Qx */ - const Word16 lg, /* i : size of x[] Q0 */ - const Word16 exp0 /* i : exponent: x = round(x << exp) Qx exp */ + Word32 x[], /* i/o: signal to scale Qx */ + const Word16 lg, /* i : size of x[] Q0 */ + const Word16 exp0 /* i : exponent: x = round(x << exp) Qx exp */ ) { - Word16 i; - - FOR(i = 0; i < lg; i++) - { - /* saturation can occur here */ - x[i] = L_shl(x[i], exp0); - move32(); - } + Word16 i; + + FOR( i = 0; i < lg; i++ ) + { + /* saturation can occur here */ + x[i] = L_shl( x[i], exp0 ); + move32(); + } } @@ -319,64 +318,64 @@ void scale_sig32( * Rescale excitation related memories *-------------------------------------------------------------------*/ Word16 rescale_mem( - const Word16 *Q_exc, /* i : current excitation scaling (>=0) */ - Word16 *prev_Q_syn, /* i/o : scaling factor of previous frame */ - Word16 *Q_syn, /* i/o : scaling factor of frame */ - Word16 *mem_syn2, /* i/o : modified synthesis memory */ - Word16 *syn, /* i/o : synthesis to rescale Q_syn */ - Word16 mem_len, /* i : lenght of modified synthesis memory */ - Word16 i_subfr /* i : subframe number */ + const Word16 *Q_exc, /* i : current excitation scaling (>=0) */ + Word16 *prev_Q_syn, /* i/o : scaling factor of previous frame */ + Word16 *Q_syn, /* i/o : scaling factor of frame */ + Word16 *mem_syn2, /* i/o : modified synthesis memory */ + Word16 *syn, /* i/o : synthesis to rescale Q_syn */ + Word16 mem_len, /* i : lenght of modified synthesis memory */ + Word16 i_subfr /* i : subframe number */ ) { - Word16 exp_scale, new_Q, tmp; - Word16 i, max16, max_scale; - - max16 = 0; - move16(); - FOR(i = 0; i < mem_len; i++) - { - max16 = s_max(max16, abs_s(mem_syn2[i])); - } - IF(syn != NULL) - { - FOR(i = 0; i < i_subfr; i++) - { - max16 = s_max(max16, abs_s(syn[i])); - } - } - max_scale = 15; - move16(); - IF(max16 > 0) - { - max_scale = add(norm_s(max16), -3); - } - - /*-------------------------------------------------------------------* - * find scaling of synthesis (based on min of current frame and last frame) - * scaling factor of synthesis (-1..6) - *-------------------------------------------------------------------*/ - new_Q = sub(*Q_exc, 3); - new_Q = s_max(new_Q, -1); - - tmp = add(max_scale, *Q_syn); - if (GT_16(s_min(new_Q, *prev_Q_syn), tmp)) - { - new_Q = s_max(tmp, -1); - } - - tmp = s_min(new_Q, *prev_Q_syn); - *prev_Q_syn = new_Q; - move16(); - - exp_scale = sub(tmp, *Q_syn); - *Q_syn = tmp; - move16(); - /* rescale synthesis memory (mem_syn2) */ - Scale_sig(mem_syn2, mem_len, exp_scale); - IF(syn != NULL) - { - Scale_sig(syn, i_subfr, exp_scale); - } - - return exp_scale; + Word16 exp_scale, new_Q, tmp; + Word16 i, max16, max_scale; + + max16 = 0; + move16(); + FOR( i = 0; i < mem_len; i++ ) + { + max16 = s_max( max16, abs_s( mem_syn2[i] ) ); + } + IF( syn != NULL ) + { + FOR( i = 0; i < i_subfr; i++ ) + { + max16 = s_max( max16, abs_s( syn[i] ) ); + } + } + max_scale = 15; + move16(); + IF( max16 > 0 ) + { + max_scale = add( norm_s( max16 ), -3 ); + } + + /*-------------------------------------------------------------------* + * find scaling of synthesis (based on min of current frame and last frame) + * scaling factor of synthesis (-1..6) + *-------------------------------------------------------------------*/ + new_Q = sub( *Q_exc, 3 ); + new_Q = s_max( new_Q, -1 ); + + tmp = add( max_scale, *Q_syn ); + if ( GT_16( s_min( new_Q, *prev_Q_syn ), tmp ) ) + { + new_Q = s_max( tmp, -1 ); + } + + tmp = s_min( new_Q, *prev_Q_syn ); + *prev_Q_syn = new_Q; + move16(); + + exp_scale = sub( tmp, *Q_syn ); + *Q_syn = tmp; + move16(); + /* rescale synthesis memory (mem_syn2) */ + Scale_sig( mem_syn2, mem_len, exp_scale ); + IF( syn != NULL ) + { + Scale_sig( syn, i_subfr, exp_scale ); + } + + return exp_scale; } diff --git a/lib_com/stab_est_fx.c b/lib_com/stab_est_fx.c index a5b36f54a..52998bbae 100644 --- a/lib_com/stab_est_fx.c +++ b/lib_com/stab_est_fx.c @@ -2,28 +2,28 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ +#include "options.h" /* Compilation switches */ #include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ /*-------------------------------------------------------------------* * Local constants *-------------------------------------------------------------------*/ -#define BIN_4000 80 /* The frequency bin corresponding to 4kHz */ -#define MAX_BANDEXC 20 +#define BIN_4000 80 /* The frequency bin corresponding to 4kHz */ +#define MAX_BANDEXC 20 -#define NB_TH3_MIN 30 -#define NB_TH1_MIN 30 +#define NB_TH3_MIN 30 +#define NB_TH1_MIN 30 -#define TH_0_MAX_FX 9600 /* Q11 -> 1.5*3.125 */ -#define TH_1_MAX_FX 8640 /* Q11 -> 1.5*2.8125 */ -#define TH_2_MAX_FX 6720 /* Q11 -> 1.5*2.1875 */ -#define TH_3_MAX_FX 5760 /* Q11 -> 1.5*1.875 */ +#define TH_0_MAX_FX 9600 /* Q11 -> 1.5*3.125 */ +#define TH_1_MAX_FX 8640 /* Q11 -> 1.5*2.8125 */ +#define TH_2_MAX_FX 6720 /* Q11 -> 1.5*2.1875 */ +#define TH_3_MAX_FX 5760 /* Q11 -> 1.5*1.875 */ -#define TH_UP_FX 320 /* Q11 -> 0.15625 */ -#define TH_DW_FX 320 /* Q11 -> 0.15625 */ +#define TH_UP_FX 320 /* Q11 -> 0.15625 */ +#define TH_DW_FX 320 /* Q11 -> 0.15625 */ /*------------------------------------------------------------------------* * stab_est() @@ -32,14 +32,14 @@ *------------------------------------------------------------------------*/ Word16 stab_est_fx( - Word16 etot, /* i : Total energy of the current frame */ - Word16 *lt_diff_etot, /* i/o : Long term total energy variation */ - Word16 *mem_etot, /* i/o : Total energy memory */ - Word16 *nb_thr_3, /* i/o : Number of consecutives frames of level 3 */ - Word16 *nb_thr_1, /* i/o : Number of consecutives frames of level 1 */ - Word16 *thresh, /* i/o : Detection thresold */ - Word16 *last_music_flag,/* i/o : Previous music detection ouptut */ - const Word16 vad_flag /* i : VAD flag */ + Word16 etot, /* i : Total energy of the current frame */ + Word16 *lt_diff_etot, /* i/o : Long term total energy variation */ + Word16 *mem_etot, /* i/o : Total energy memory */ + Word16 *nb_thr_3, /* i/o : Number of consecutives frames of level 3 */ + Word16 *nb_thr_1, /* i/o : Number of consecutives frames of level 1 */ + Word16 *thresh, /* i/o : Detection thresold */ + Word16 *last_music_flag, /* i/o : Previous music detection ouptut */ + const Word16 vad_flag /* i : VAD flag */ ) { Word16 i, music_flag2, tmp16, exp1, exp2; @@ -51,39 +51,39 @@ Word16 stab_est_fx( * Find mean of the past MAX_LT frames energy variation *------------------------------------------------------------------------*/ - L_tmp = L_deposit_l(0); - FOR (i = 1; i 1/25 (1/(MAX_LT-15))*/ + L_tmp = Mpy_32_16_1( L_tmp, 1311 ); /*-> 1/25 (1/(MAX_LT-15))*/ - exp1 = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, exp1); + exp1 = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, exp1 ); #ifdef BASOP_NOGLOB - tmp16 = round_fx_sat(L_tmp); + tmp16 = round_fx_sat( L_tmp ); #else - tmp16 = round_fx(L_tmp); + tmp16 = round_fx( L_tmp ); #endif - exp2 = sub(31, exp1); - L_tmp = Isqrt_lc(L_tmp, &exp2); - L_tmp = Mpy_32_16_1(L_tmp, tmp16); /* we now have sqrt(L_corr) Q24 (8+16)*/ - exp2 = sub(31-15, sub(exp1, exp2)); /* for Q8 (because of -8^2 from Etot)*/ + exp2 = sub( 31, exp1 ); + L_tmp = Isqrt_lc( L_tmp, &exp2 ); + L_tmp = Mpy_32_16_1( L_tmp, tmp16 ); /* we now have sqrt(L_corr) Q24 (8+16)*/ + exp2 = sub( 31 - 15, sub( exp1, exp2 ) ); /* for Q8 (because of -8^2 from Etot)*/ - L_tmp = L_shl(L_tmp, exp2); /* Q8 + Q16*/ + L_tmp = L_shl( L_tmp, exp2 ); /* Q8 + Q16*/ #ifdef BASOP_NOGLOB - dev = extract_h(L_shl_sat(L_tmp, 3 )); /* Q(24+3-16) -> Q11 */ -#else /* BASOP_NOGLOB */ - dev = extract_h(L_shl(L_tmp, 3)); /* Q(24+3-16) -> Q11 */ + dev = extract_h( L_shl_sat( L_tmp, 3 ) ); /* Q(24+3-16) -> Q11 */ +#else /* BASOP_NOGLOB */ + dev = extract_h( L_shl( L_tmp, 3 ) ); /* Q(24+3-16) -> Q11 */ #endif /*------------------------------------------------------------------------* @@ -121,7 +121,7 @@ Word16 stab_est_fx( *------------------------------------------------------------------------*/ music_flag2 = 0; - move16();/* deactivate spectral modification (if music_flag2 != 0 is activated) */ + move16(); /* deactivate spectral modification (if music_flag2 != 0 is activated) */ test(); /*--------------------------------------------------------------------* * statistical deviation < thresh3 and last signal category type >= 3 @@ -130,7 +130,7 @@ Word16 stab_est_fx( test(); test(); test(); - IF ((LT_16(dev, thresh[3]))&&(GE_16(*last_music_flag,3))) + IF( ( LT_16( dev, thresh[3] ) ) && ( GE_16( *last_music_flag, 3 ) ) ) { music_flag2 = 4; move16(); @@ -144,7 +144,7 @@ Word16 stab_est_fx( * statistical deviation < thresh2 and last signal category type >= 2 * (last category was "moderatly tonal" and the new one is a "tonal" ) *--------------------------------------------------------------------*/ - ELSE IF ((LT_16(dev, thresh[2]))&&(GE_16(*last_music_flag,2))) + ELSE IF( ( LT_16( dev, thresh[2] ) ) && ( GE_16( *last_music_flag, 2 ) ) ) { music_flag2 = 3; move16(); @@ -158,7 +158,7 @@ Word16 stab_est_fx( * statistical deviation < thresh1 and last signal category type >= 1 * (last category was "slightly tonal" and the new one is a "moderatly tonal") *--------------------------------------------------------------------*/ - ELSE IF ((LT_16(dev, thresh[1]))&&(GE_16(*last_music_flag,1))) + ELSE IF( ( LT_16( dev, thresh[1] ) ) && ( GE_16( *last_music_flag, 1 ) ) ) { music_flag2 = 2; move16(); @@ -168,10 +168,10 @@ Word16 stab_est_fx( * statistical deviation < thresh0 * (last category was "not tonal" and the new one is "slightly tonal") *--------------------------------------------------------------------*/ - ELSE IF ((LT_16(dev, thresh[0]))) + ELSE IF( ( LT_16( dev, thresh[0] ) ) ) { music_flag2 = 1; - move16();/* [2000, 4000] Hz */ + move16(); /* [2000, 4000] Hz */ } /*--------------------------------------------------------------------* @@ -180,41 +180,39 @@ Word16 stab_est_fx( *--------------------------------------------------------------------*/ ELSE { - *nb_thr_1 = add(*nb_thr_1,1); + *nb_thr_1 = add( *nb_thr_1, 1 ); *nb_thr_3 = 0; move16(); - } /*------------------------------------------------------------------------* * Update the thresholds *------------------------------------------------------------------------*/ - IF (GT_16(*nb_thr_3,NB_TH3_MIN)) + IF( GT_16( *nb_thr_3, NB_TH3_MIN ) ) { /* the number of consecutive categories type 3 or 4 (most tonal and tonal) */ /* is greater than 30 frames ->increase the deviations thresholds to allow more variation */ - thresh[0] = add(thresh[0], TH_UP_FX); - move16(); /*Q11 */ - thresh[1] = add(thresh[1], TH_UP_FX); + thresh[0] = add( thresh[0], TH_UP_FX ); + move16(); /*Q11 */ + thresh[1] = add( thresh[1], TH_UP_FX ); move16(); - thresh[2] = add(thresh[2], TH_UP_FX); + thresh[2] = add( thresh[2], TH_UP_FX ); move16(); - thresh[3] = add(thresh[3], TH_UP_FX); + thresh[3] = add( thresh[3], TH_UP_FX ); move16(); - } - ELSE IF (GT_16(*nb_thr_1,NB_TH1_MIN)) + ELSE IF( GT_16( *nb_thr_1, NB_TH1_MIN ) ) { /* the number of consecutive categories type 0 (non tonal frames) */ /* is greater than 30 frames -> decrease the deviations thresholds to allow less variation */ - thresh[0] = sub(thresh[0], TH_DW_FX); - move16(); /*Q11 */ - thresh[1] = sub(thresh[1], TH_DW_FX); + thresh[0] = sub( thresh[0], TH_DW_FX ); + move16(); /*Q11 */ + thresh[1] = sub( thresh[1], TH_DW_FX ); move16(); - thresh[2] = sub(thresh[2], TH_DW_FX); + thresh[2] = sub( thresh[2], TH_DW_FX ); move16(); - thresh[3] = sub(thresh[3], TH_DW_FX); + thresh[3] = sub( thresh[3], TH_DW_FX ); move16(); } @@ -224,27 +222,27 @@ Word16 stab_est_fx( move16(); move16(); move16(); - thresh[0] = s_max(thresh[0], TH_0_MIN2_FX); - thresh[1] = s_max(thresh[1], TH_1_MIN2_FX); - thresh[2] = s_max(thresh[2], TH_2_MIN2_FX); + thresh[0] = s_max( thresh[0], TH_0_MIN2_FX ); + thresh[1] = s_max( thresh[1], TH_1_MIN2_FX ); + thresh[2] = s_max( thresh[2], TH_2_MIN2_FX ); move16(); move16(); move16(); - thresh[0] = s_min(thresh[0], TH_0_MAX_FX); - thresh[1] = s_min(thresh[1], TH_1_MAX_FX); - thresh[2] = s_min(thresh[2], TH_2_MAX_FX); + thresh[0] = s_min( thresh[0], TH_0_MAX_FX ); + thresh[1] = s_min( thresh[1], TH_1_MAX_FX ); + thresh[2] = s_min( thresh[2], TH_2_MAX_FX ); move16(); move16(); - thresh[3] = s_max(thresh[3], TH_3_MIN2_FX); - thresh[3] = s_min(thresh[3], TH_3_MAX_FX); + thresh[3] = s_max( thresh[3], TH_3_MIN2_FX ); + thresh[3] = s_min( thresh[3], TH_3_MAX_FX ); /*------------------------------------------------------------------------* * Final update *------------------------------------------------------------------------*/ *last_music_flag = music_flag2; move16(); - if (vad_flag == 0) + if ( vad_flag == 0 ) { music_flag2 = 0; diff --git a/lib_com/stat_com.h b/lib_com/stat_com.h index 538d5c934..4b07886f7 100644 --- a/lib_com/stat_com.h +++ b/lib_com/stat_com.h @@ -95,14 +95,14 @@ typedef struct { TCQ_PBITSTREAM bsInst; - Word32 low; - Word32 high; + Word32 low; + Word32 high; - Word32 value; - Word16 bits_to_follow; + Word32 value; + Word16 bits_to_follow; - Word32 num_bits; - Word32 max_bits; + Word32 num_bits; + Word32 max_bits; } ARCODEC, *PARCODEC; @@ -163,8 +163,8 @@ typedef struct { int16_t bits; /* bits per subframe */ int16_t nbiter; /* number of iterations */ - float alp_flt; /* initial energy of all fixed pulses */ - Word16 alp; /* initial energy of all fixed pulses, exponent = ALP_E */ + float alp_flt; /* initial energy of all fixed pulses */ + Word16 alp; /* initial energy of all fixed pulses, exponent = ALP_E */ int16_t nb_pulse; /* number of pulses */ int16_t fixedpulses; /* number of pulses whose position is determined from correlation and not by iteration */ int16_t nbpos[13]; /* number of positions tried in the pair-wise search */ @@ -177,8 +177,8 @@ typedef struct *---------------------------------------------------------------*/ typedef enum { - TNS_NO_ERROR = 0, - TNS_FATAL_ERROR + TNS_NO_ERROR = 0, + TNS_FATAL_ERROR } TNS_ERROR; typedef struct { @@ -196,9 +196,9 @@ typedef struct TNS_filter_structure int16_t spectrumLength; /* Number of subbands covered by the filter. */ int16_t order; /* Filter order. */ int16_t coefIndex[TNS_MAX_FILTER_ORDER]; /* Quantized filter coefficients. */ - float predictionGain_flt; /* Prediction gain. The ratio of a signal and TNS residual energy. */ - float avgSqrCoef_flt; /* Average squared filter coefficient. */ - /** Prediction gain. The ratio of a signal and TNS residual energy. */ + float predictionGain_flt; /* Prediction gain. The ratio of a signal and TNS residual energy. */ + float avgSqrCoef_flt; /* Average squared filter coefficient. */ + /** Prediction gain. The ratio of a signal and TNS residual energy. */ Word16 predictionGain; /* exponent = PRED_GAIN_E */ /** Average squared filter coefficient. */ Word16 avgSqrCoef; /* exponent = 0 */ @@ -273,7 +273,7 @@ typedef struct TCX_config_structure float tcx_mdct_window_minimumFB_flt[L_MDCT_MIN_OVLP_MAX]; float tcx_mdct_window_transFB_flt[L_MDCT_TRANS_OVLP_MAX]; /* transition window for ACELP->TCX */ - /* TCX mdct window */ + /* TCX mdct window */ PWord16 tcx_mdct_windowFB[L_MDCT_OVLP_MAX]; PWord16 tcx_mdct_window_halfFB[L_MDCT_HALF_OVLP_MAX]; PWord16 tcx_mdct_window_minimumFB[L_MDCT_MIN_OVLP_MAX]; @@ -305,13 +305,13 @@ typedef struct TCX_config_structure /*Quantization*/ float sq_rounding_flt; /*set the sq deadzone (no deadzone=0.5f)*/ - Word16 sq_rounding; /*set the sq deadzone (no deadzone=0.5f)*/ + Word16 sq_rounding; /*set the sq deadzone (no deadzone=0.5f)*/ int16_t tcxRateLoopOpt; /*Bandwidth*/ float preemph_fac_flt; /* preemphasis factor */ float bandwidth_flt; - Word16 preemph_fac; /*preemphasis factor*/ + Word16 preemph_fac; /*preemphasis factor*/ Word16 bandwidth; /* Context HM - Residual Quantization*/ @@ -372,7 +372,7 @@ typedef struct int32_t bitrateTo; float scale_flt; - Word16 scale; /* EVS implementation */ + Word16 scale; /* EVS implementation */ Word16 scale_ivas; /* IVAS implementation */ } SCALE_SETUP; @@ -390,12 +390,12 @@ typedef struct int16_t stopFFTbin; /* Total number of FFT subbands */ int16_t frameSize; /* Frame size in samples */ int16_t fftlen; /* FFT length used for the decomposition */ - Word16 fftlenShift; - Word16 fftlenFac; + Word16 fftlenShift; + Word16 fftlenFac; float timeDomainBuffer_flt[L_FRAME16k]; - Word16 timeDomainBuffer[L_FRAME16k]; - + Word16 timeDomainBuffer[L_FRAME16k]; + float fftBuffer_flt[FFTLEN]; float olapBufferAna_flt[FFTLEN]; float olapBufferSynth_flt[FFTLEN]; @@ -416,85 +416,85 @@ typedef struct #ifdef IVAS_FLOAT_FIXED const Word16 *fftSineTab_fx; #endif - Word32 fftBuffer[FFTLEN]; - Word16 fftBuffer_exp; - Word16 *olapBufferAna; /* points to FD_CNG_DEC->olapBufferAna[FFTLEN] in case of decoder */ - Word16 olapBufferAna_fx[FFTLEN]; /* points to FD_CNG_DEC->olapBufferAna[FFTLEN] in case of decoder */ - Word16 olapBufferSynth[FFTLEN]; - Word16 *olapBufferSynth2; /* points to FD_CNG_DEC->olapBufferSynth2[FFTLEN] in case of decoder */ - const PWord16 * olapWinAna; - const PWord16 * olapWinSyn; + Word32 fftBuffer[FFTLEN]; + Word16 fftBuffer_exp; + Word16 *olapBufferAna; /* points to FD_CNG_DEC->olapBufferAna[FFTLEN] in case of decoder */ + Word16 olapBufferAna_fx[FFTLEN]; /* points to FD_CNG_DEC->olapBufferAna[FFTLEN] in case of decoder */ + Word16 olapBufferSynth[FFTLEN]; + Word16 *olapBufferSynth2; /* points to FD_CNG_DEC->olapBufferSynth2[FFTLEN] in case of decoder */ + const PWord16 *olapWinAna; + const PWord16 *olapWinSyn; float msM_win_flt; float msM_subwin_flt; - Word16 msM_win; - Word16 msM_subwin; + Word16 msM_win; + Word16 msM_subwin; int16_t msFrCnt_init_counter; /* Frame counter at initialization */ int16_t msFrCnt_init_thresh; float init_old_flt; - Word16 init_old; + Word16 init_old; - int16_t msFrCnt; /* Frame counter */ + int16_t msFrCnt; /* Frame counter */ float msAlphaCor_flt[2]; /* Correction factor (smoothed) */ float msSlope_flt[2]; float msQeqInvAv_flt[2]; - Word32 msAlphaCor[2]; /* Correction factor (smoothed) */ - Word16 msSlope[2]; - Word32 msQeqInvAv[2]; - Word16 msQeqInvAv_exp[2]; + Word32 msAlphaCor[2]; /* Correction factor (smoothed) */ + Word16 msSlope[2]; + Word32 msQeqInvAv[2]; + Word16 msQeqInvAv_exp[2]; int16_t msMinBufferPtr; float msPsdSum_flt[2]; float msPeriodogSum_flt[2]; - Word32 msPsdSum[2]; - Word32 msPeriodogSum[2]; - Word16 msPeriodogSum_exp[2]; + Word32 msPsdSum[2]; + Word32 msPeriodogSum[2]; + Word16 msPeriodogSum_exp[2]; int16_t offsetflag; float periodog_flt[PERIODOGLEN]; /* Periodogram */ float cngNoiseLevel_flt[FFTCLDFBLEN]; /* Noise level applied for the CNG in each (sub)band */ - Word32 periodog[PERIODOGLEN]; /* Periodogram */ - Word16 periodog_exp; - Word16 exp_cldfb_periodog; - - Word32 cngNoiseLevel[FFTCLDFBLEN]; /* Noise level applied for the CNG in each (sub)band */ - //Word16 q_cngNoiseLevel; - Word16 cngNoiseLevelExp; - - int16_t seed; /* Seed memory (for random function) */ - int16_t seed2; /* Seed for second noise source in MDCT-Stereo DTX */ - int16_t seed3; /* Seed for third noise source in MDCT-Stereo DTX */ - - int16_t npart; /* Number of partitions */ - int16_t midband[NPART]; /* Central band of each partition */ - int16_t nFFTpart; /* Number of hybrid spectral partitions */ - int16_t part[NPART]; /* Partition upper boundaries (band indices starting from 0) */ + Word32 periodog[PERIODOGLEN]; /* Periodogram */ + Word16 periodog_exp; + Word16 exp_cldfb_periodog; + + Word32 cngNoiseLevel[FFTCLDFBLEN]; /* Noise level applied for the CNG in each (sub)band */ + // Word16 q_cngNoiseLevel; + Word16 cngNoiseLevelExp; + + int16_t seed; /* Seed memory (for random function) */ + int16_t seed2; /* Seed for second noise source in MDCT-Stereo DTX */ + int16_t seed3; /* Seed for third noise source in MDCT-Stereo DTX */ + + int16_t npart; /* Number of partitions */ + int16_t midband[NPART]; /* Central band of each partition */ + int16_t nFFTpart; /* Number of hybrid spectral partitions */ + int16_t part[NPART]; /* Partition upper boundaries (band indices starting from 0) */ float psize_flt[NPART]; /* Partition sizes */ float psize_inv_flt[NPART]; /* Inverse of partition sizes */ float FFTscalingFactor_flt; /* Squared ratio between core signal analysis FFT and noise estimator FFT */ float scalingFactor_flt; - Word16 psize[NPART]; /* Partition sizes */ - Word16 psize_norm[NPART]; /* Partition sizes, fractional variable */ - Word16 psize_norm_exp; /* Partition sizes exponent for fractional variable */ - Word16 psize_inv[NPART]; /* Inverse of partition sizes */ - Word16 FFTscalingFactor; /* Squared ratio between core signal analysis FFT and noise estimator FFT */ - Word16 scalingFactor; - Word16 invScalingFactor; - int16_t nCLDFBpart; /* Number of CLDFB spectral partitions */ - int16_t CLDFBpart[NPARTCLDFB]; /* CLDFB Partition upper boundaries (band indices starting from 0 above the core coder bands) */ + Word16 psize[NPART]; /* Partition sizes */ + Word16 psize_norm[NPART]; /* Partition sizes, fractional variable */ + Word16 psize_norm_exp; /* Partition sizes exponent for fractional variable */ + Word16 psize_inv[NPART]; /* Inverse of partition sizes */ + Word16 FFTscalingFactor; /* Squared ratio between core signal analysis FFT and noise estimator FFT */ + Word16 scalingFactor; + Word16 invScalingFactor; + int16_t nCLDFBpart; /* Number of CLDFB spectral partitions */ + int16_t CLDFBpart[NPARTCLDFB]; /* CLDFB Partition upper boundaries (band indices starting from 0 above the core coder bands) */ float CLDFBpsize_inv_flt[NPARTCLDFB]; /* Inverse of CLDFB partition sizes */ - Word16 CLDFBpsize_inv[NPARTCLDFB];/* Inverse of CLDFB partition sizes */ + Word16 CLDFBpsize_inv[NPARTCLDFB]; /* Inverse of CLDFB partition sizes */ int16_t inactive_frame_counter; int16_t sid_frame_counter; int16_t active_frame_counter; /* Active frame counter limited to MSBUFLEN in stereo decoder */ float sidNoiseEst_flt[NPART]; /* Transmitted noise level */ - Word32 sidNoiseEst[NPART]; /* Transmitted noise level */ - Word16 sidNoiseEstExp; + Word32 sidNoiseEst[NPART]; /* Transmitted noise level */ + Word16 sidNoiseEstExp; float sidNoiseEstLp_flt[NPART]; Word32 sidNoiseEstLp[NPART]; @@ -503,10 +503,10 @@ typedef struct float A_cng_flt[M + 1]; float exc_cng_flt[L_FRAME16k]; - Word16 A_cng[M + 1]; - Word16 exc_cng[L_FRAME16k]; + Word16 A_cng[M + 1]; + Word16 exc_cng[L_FRAME16k]; #ifdef IVAS_FLOAT_FIXED - Word32 exc_cng_32fx[L_FRAME16k]; + Word32 exc_cng_32fx[L_FRAME16k]; #endif int32_t CngBitrate; @@ -517,11 +517,11 @@ typedef struct #ifdef IVAS_FLOAT_FIXED Word32 likelihood_noisy_speech_32fx; #endif - Word16 likelihood_noisy_speech; + Word16 likelihood_noisy_speech; - float coherence_flt; /* inter-channel coherence of noise */ - Word16 coherence_fx; /* inter-channel coherence of noise */ /* Q15 */ - int16_t no_side_flag; /* indicates whether the side noise shape should be zeroed-out or not */ + float coherence_flt; /* inter-channel coherence of noise */ + Word16 coherence_fx; /* inter-channel coherence of noise */ /* Q15 */ + int16_t no_side_flag; /* indicates whether the side noise shape should be zeroed-out or not */ } FD_CNG_COM, *HANDLE_FD_CNG_COM; @@ -644,13 +644,13 @@ typedef struct ParamsBitMap struct TnsParameters { /* Parameters for each TNS filter */ - int16_t startLineFrequency; /* Starting lower frequency of the TNS filter [20..16000] */ - int16_t nSubdivisions; /* Number of spectrum subdivisions in which the filter operates [1..8) */ - float minPredictionGain_flt; /* Minimum prediction gain required to turn on the TNS filter */ - float minAvgSqrCoef_flt; /* Minimum average square of coefficients required to turn on the TNS filter */ - float minEnergyChange_flt; /* Minimum energy change required to turn on the TNS filter */ - Word16 minPredictionGain; /* Minimum prediction gain required to turn on the TNS filter. Exponent = PRED_GAIN_E */ - Word16 minAvgSqrCoef; /* Minimum average square of coefficients required to turn on the TNS filter. Exponent = 0 */ + int16_t startLineFrequency; /* Starting lower frequency of the TNS filter [20..16000] */ + int16_t nSubdivisions; /* Number of spectrum subdivisions in which the filter operates [1..8) */ + float minPredictionGain_flt; /* Minimum prediction gain required to turn on the TNS filter */ + float minAvgSqrCoef_flt; /* Minimum average square of coefficients required to turn on the TNS filter */ + float minEnergyChange_flt; /* Minimum energy change required to turn on the TNS filter */ + Word16 minPredictionGain; /* Minimum prediction gain required to turn on the TNS filter. Exponent = PRED_GAIN_E */ + Word16 minAvgSqrCoef; /* Minimum average square of coefficients required to turn on the TNS filter. Exponent = 0 */ }; /**********************************************/ @@ -697,10 +697,10 @@ typedef struct cldfb_filter_bank_struct int16_t no_channels; int16_t no_col; int16_t p_filter_length; - Word16 lsb; /*!< Top of low subbands */ - Word16 usb; /*!< Top of high subbands */ - Word16 zeros; /*!< number of zeros in filter coefficients */ - UWord16 flags; /*!< flags */ + Word16 lsb; /*!< Top of low subbands */ + Word16 usb; /*!< Top of high subbands */ + Word16 zeros; /*!< number of zeros in filter coefficients */ + UWord16 flags; /*!< flags */ CLDFB_TYPE type; int16_t ds; /* delay synthesis */ @@ -708,7 +708,7 @@ typedef struct cldfb_filter_bank_struct CLDFB_PROTOTYPE prototype; const float *p_filter_flt; - const Word16 *p_filter; /*!< Pointer to filter coefficients */ + const Word16 *p_filter; /*!< Pointer to filter coefficients */ Word16 p_filter_sf; @@ -730,7 +730,7 @@ typedef struct cldfb_filter_bank_struct const float *rot_vec_ana_delay_im; const float *rot_vec_syn_delay_re; const float *rot_vec_syn_delay_im; - + #ifdef IVAS_FLOAT_FIXED const Word32 *rot_vec_ana_re_fx; const Word32 *rot_vec_ana_im_fx; @@ -738,14 +738,14 @@ typedef struct cldfb_filter_bank_struct const Word32 *rot_vec_ana_delay_re_fx; const Word32 *rot_vec_ana_delay_im_fx; #endif - //Fix variables - Word16 *FilterStates; /*!< Pointer to buffer of filter states */ - Word16 FilterStates_e[CLDFB_NO_COL_MAX + 9]; /*!< Filter states time slot exponents */ - Word16 FilterStates_eg; /*!< Filter states current exponent */ + // Fix variables + Word16 *FilterStates; /*!< Pointer to buffer of filter states */ + Word16 FilterStates_e[CLDFB_NO_COL_MAX + 9]; /*!< Filter states time slot exponents */ + Word16 FilterStates_eg; /*!< Filter states current exponent */ - const Word16 *rRotVctr; /*!< Modulation tables. */ + const Word16 *rRotVctr; /*!< Modulation tables. */ const Word16 *iRotVctr; - Word16 filterScale; /*!< filter scale */ + Word16 filterScale; /*!< filter scale */ Word16 synGain; /*!< gain for synthesis filterbank */ Word16 anaScalefactor; /*!< Scale factor of analysis cldfb */ @@ -758,8 +758,8 @@ typedef struct cldfb_filter_bank_struct float *memory_flt; Word16 *memory; #ifdef IVAS_FLOAT_FIXED - Word32 *memory32;/*because cldfb_state_fx is word32 which is used to assign values*/ -#endif // IVAS_FLOAT_FIXED + Word32 *memory32; /*because cldfb_state_fx is word32 which is used to assign values*/ +#endif // IVAS_FLOAT_FIXED #if 0 //Can be deleted #endif @@ -780,7 +780,7 @@ typedef struct cldfb_filter_bank_struct int16_t nab; /* number of active bands */ Word16 filtermode; - float scale_flt; /* scaling of frequency domain */ + float scale_flt; /* scaling of frequency domain */ Word16 scale; Word16 q_scale; @@ -811,37 +811,36 @@ typedef enum /*---------------------------------------------------------------* * IGF * *---------------------------------------------------------------*/ - /*----------------------------------------------------------------------------------* - * NB postfilter / formant postfilter static variables - *----------------------------------------------------------------------------------*/ +/*----------------------------------------------------------------------------------* + * NB postfilter / formant postfilter static variables + *----------------------------------------------------------------------------------*/ typedef struct pfstat_structure { - int16_t on; /* On/off flag */ - int16_t reset; /* reset flag */ + int16_t on; /* On/off flag */ + int16_t reset; /* reset flag */ #ifndef IVAS_FLOAT_FIXED - float mem_pf_in_flt[L_SUBFR]; /* Input memory */ - float mem_stp_flt[L_SUBFR]; /* 1/A(gamma1) memory */ - float mem_res2_flt[DECMEM_RES2]; /* A(gamma2) residual */ - float mem_zero_flt[M]; /* null memory to compute i.r. of A(gamma2)/A(gamma1) */ - float gain_prec_flt; /* for gain adjustment */ + float mem_pf_in_flt[L_SUBFR]; /* Input memory */ + float mem_stp_flt[L_SUBFR]; /* 1/A(gamma1) memory */ + float mem_res2_flt[DECMEM_RES2]; /* A(gamma2) residual */ + float mem_zero_flt[M]; /* null memory to compute i.r. of A(gamma2)/A(gamma1) */ + float gain_prec_flt; /* for gain adjustment */ #endif - Word16 mem_pf_in[L_SUBFR]; /* Input memory */ - Word16 mem_stp[L_SUBFR]; /* 1/A(gamma1) memory */ - Word16 mem_res2[DECMEM_RES2]; /* A(gamma2) residual */ - Word16 mem_zero[M]; /* null memory to compute i.r. of A(gamma2)/A(gamma1) */ - Word16 gain_prec; /* for gain adjustment */ + Word16 mem_pf_in[L_SUBFR]; /* Input memory */ + Word16 mem_stp[L_SUBFR]; /* 1/A(gamma1) memory */ + Word16 mem_res2[DECMEM_RES2]; /* A(gamma2) residual */ + Word16 mem_zero[M]; /* null memory to compute i.r. of A(gamma2)/A(gamma1) */ + Word16 gain_prec; /* for gain adjustment */ } PFSTAT, *PFSTAT_HANDLE; - typedef struct { - Word16 lb_scale; /*!< Scale of low band area */ - Word16 lb_scale16; /*!< Scale of low band area */ - Word16 ov_lb_scale; /*!< Scale of adjusted overlap low band area */ - Word16 hb_scale; /*!< Scale of high band area */ - Word16 ov_hb_scale; /*!< Scale of adjusted overlap high band area */ + Word16 lb_scale; /*!< Scale of low band area */ + Word16 lb_scale16; /*!< Scale of low band area */ + Word16 ov_lb_scale; /*!< Scale of adjusted overlap low band area */ + Word16 hb_scale; /*!< Scale of high band area */ + Word16 ov_hb_scale; /*!< Scale of adjusted overlap high band area */ } CLDFB_SCALE_FACTOR; @@ -863,15 +862,15 @@ typedef struct igf_grid_struct int16_t tile[IGF_MAX_TILES + 1]; int16_t infoIsRefined; int16_t infoGranuleLen; - Word16 infoTransFac; + Word16 infoTransFac; float whiteningThreshold_flt[2][IGF_MAX_TILES]; - Word16 whiteningThreshold[2][IGF_MAX_TILES]; /* 2Q13 */ + Word16 whiteningThreshold[2][IGF_MAX_TILES]; /* 2Q13 */ float gFactor_flt; float fFactor_flt; float lFactor_flt; - Word16 gFactor; /* 1Q14 */ - Word16 fFactor; /* 1Q14 */ - Word16 lFactor; /* 1Q14 */ + Word16 gFactor; /* 1Q14 */ + Word16 fFactor; /* 1Q14 */ + Word16 lFactor; /* 1Q14 */ } IGF_GRID, *H_IGF_GRID; diff --git a/lib_com/stat_noise_uv_mod_fx.c b/lib_com/stat_noise_uv_mod_fx.c index 70f083523..8d8949758 100644 --- a/lib_com/stat_noise_uv_mod_fx.c +++ b/lib_com/stat_noise_uv_mod_fx.c @@ -3,26 +3,26 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "cnst.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "cnst.h" /* Function prototypes */ /*---------------------------------------------------------------------* - * Local function prototypes - *---------------------------------------------------------------------*/ + * Local function prototypes + *---------------------------------------------------------------------*/ -#define TILT_COMP_LIM_FX 24576 /* 0.75 in Q15 */ -#define GE_SHIFT 6 -#define P1 (32768-ISP_SMOOTHING_QUANT_A1_FX-1) -#define P9 (32767-P1) +#define TILT_COMP_LIM_FX 24576 /* 0.75 in Q15 */ +#define GE_SHIFT 6 +#define P1 ( 32768 - ISP_SMOOTHING_QUANT_A1_FX - 1 ) +#define P9 ( 32767 - P1 ) /*---------------------------------------------------------* * Local functions *---------------------------------------------------------*/ -static Word16 calc_tilt_fx(const Word16 *x, const Word16 Q_shift, const Word16 len); -Word32 L_Sqrt_Q0(const Word32 x); +static Word16 calc_tilt_fx( const Word16 *x, const Word16 Q_shift, const Word16 len ); +Word32 L_Sqrt_Q0( const Word32 x ); /*--------------------------------------------------------------------* * stat_noise_uv_mod() * @@ -38,7 +38,7 @@ void stat_noise_uv_mod_fx( Word16 *Aq, /* o : A(z) quantized for the 4 subframes */ Word16 *exc2, /* i/o: excitation buffer */ Word16 Q_exc, /* i : Q of exc2 excitation buffer [11..-1] expected */ - const Word16 bfi , /* i : Bad frame indicator */ + const Word16 bfi, /* i : Bad frame indicator */ Word32 *ge_sm, /* i/o: smoothed excitation gain */ Word16 *uv_count, /* i/o: unvoiced counter */ Word16 *act_count, /* i/o: activation counter */ @@ -52,28 +52,28 @@ void stat_noise_uv_mod_fx( Word16 *Q_stat_noise_ge /* i/o: noise scaling */ ) { - Word16 exctilt; /* Q15 */ - Word32 vare; /* Q31 */ - Word16 randval; /* Q?? */ - Word16 alpha; /* Q15 */ - Word16 alpha_m1; /* (1-alpha) Q15 */ - Word16 min_alpha; /* Q15 */ - Word16 lspnew_s[M]; /* Same for all LSP (Q15) */ + Word16 exctilt; /* Q15 */ + Word32 vare; /* Q31 */ + Word16 randval; /* Q?? */ + Word16 alpha; /* Q15 */ + Word16 alpha_m1; /* (1-alpha) Q15 */ + Word16 min_alpha; /* Q15 */ + Word16 lspnew_s[M]; /* Same for all LSP (Q15) */ Word16 oldlsp_mix[M]; Word16 midlsp_mix[M]; Word16 newlsp_mix[M]; - Word16 beta; /* Q15 */ - Word16 Noimix_fract; /* (noimix_fac - 1.0) in Q15 */ + Word16 beta; /* Q15 */ + Word16 Noimix_fract; /* (noimix_fac - 1.0) in Q15 */ /* noimix_fax * x <-> x + Noimix_fract * x */ Word16 i_subfr; Word16 i, k; /* Work variables for div and sqrt */ - Word16 tmp_nom,tmp_den,tmp_shift,tmp_res; - Word16 Qdiff,Q_local; /* new Q to be used for states Exc_pe and Ge_sm, and Exc2_local */ - Word32 L_tmp_res,L_tmp, L_tmp3,L_Ge; + Word16 tmp_nom, tmp_den, tmp_shift, tmp_res; + Word16 Qdiff, Q_local; /* new Q to be used for states Exc_pe and Ge_sm, and Exc2_local */ + Word32 L_tmp_res, L_tmp, L_tmp3, L_Ge; - Word16 En_shift,Tmp; + Word16 En_shift, Tmp; Word16 Exc2_local[L_FRAME]; /* local_copy in scaled Q_local*/ #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; @@ -82,7 +82,7 @@ void stat_noise_uv_mod_fx( /*---------------------------------------------------------* * Init local variables *---------------------------------------------------------*/ - alpha = 32767; + alpha = 32767; move16(); min_alpha = 16384; move16(); @@ -90,34 +90,34 @@ void stat_noise_uv_mod_fx( test(); test(); test(); - IF (EQ_16(coder_type,INACTIVE)&&(EQ_32(bitrate,ACELP_9k60)||(LT_32(bitrate,ACELP_9k60)&>_16(bwidth_fx,NB)))) + IF( EQ_16( coder_type, INACTIVE ) && ( EQ_32( bitrate, ACELP_9k60 ) || ( LT_32( bitrate, ACELP_9k60 ) && GT_16( bwidth_fx, NB ) ) ) ) { min_alpha = *st_min_alpha; move16(); /*---------------------------------------------------------* * decode noisiness parameter *---------------------------------------------------------*/ - IF (bfi == 0) + IF( bfi == 0 ) { tmp_den = 31; move16(); - tmp_shift = norm_s(tmp_den); + tmp_shift = norm_s( tmp_den ); move16(); - L_tmp_res = L_deposit_h(noisiness); - L_tmp_res = L_shl(L_tmp_res,sub(tmp_shift,1)); - tmp_den = shl(tmp_den,tmp_shift); + L_tmp_res = L_deposit_h( noisiness ); + L_tmp_res = L_shl( L_tmp_res, sub( tmp_shift, 1 ) ); + tmp_den = shl( tmp_den, tmp_shift ); move16(); - tmp_res = div_l(L_tmp_res,tmp_den); + tmp_res = div_l( L_tmp_res, tmp_den ); move16(); #ifdef BASOP_NOGLOB - min_alpha = add_o(tmp_res, 16384, &Overflow); -#else /* BASOP_NOGLOB */ - min_alpha = add(tmp_res, 16384); + min_alpha = add_o( tmp_res, 16384, &Overflow ); +#else /* BASOP_NOGLOB */ + min_alpha = add( tmp_res, 16384 ); #endif /* BASOP_NOGLOB */ move16(); /**st_min_alpha = sub(*st_min_alpha, 1638); move16();*/ - min_alpha = s_max(min_alpha, sub(*st_min_alpha, 1638)); + min_alpha = s_max( min_alpha, sub( *st_min_alpha, 1638 ) ); *st_min_alpha = min_alpha; move16(); @@ -130,76 +130,76 @@ void stat_noise_uv_mod_fx( test(); test(); test(); - IF ( EQ_16(coder_type,INACTIVE)&&(EQ_32(bitrate,ACELP_9k60)||(LT_32(bitrate,ACELP_9k60)&>_16(bwidth_fx,NB)))) + IF( EQ_16( coder_type, INACTIVE ) && ( EQ_32( bitrate, ACELP_9k60 ) || ( LT_32( bitrate, ACELP_9k60 ) && GT_16( bwidth_fx, NB ) ) ) ) { /* use a local working copy for scaling and filtering, not needed if input Q-range is fixed */ - Copy(exc2, Exc2_local, L_FRAME); + Copy( exc2, Exc2_local, L_FRAME ); /* bound Q for internal use, optimization possible */ - Q_local = s_min(11, s_max(-1, Q_exc)); + Q_local = s_min( 11, s_max( -1, Q_exc ) ); /* local excitation Q and incoming excitation Q*/ - Qdiff = sub(Q_local, Q_exc); + Qdiff = sub( Q_local, Q_exc ); /* only shift if incoming Q is outside [11..-1] shift is done in energy calculations aswell */ - Scale_sig(Exc2_local, L_FRAME, Qdiff); + Scale_sig( Exc2_local, L_FRAME, Qdiff ); /* current excitation Q and previous stat_noise states Q */ - Qdiff = sub(Q_local, *Q_stat_noise); + Qdiff = sub( Q_local, *Q_stat_noise ); *Q_stat_noise_ge = GE_SHIFT; move16(); /* assign the fixed Q for Ge_sm */ - IF (Qdiff != 0) + IF( Qdiff != 0 ) { - Scale_sig(exc_pe, 1, Qdiff); + Scale_sig( exc_pe, 1, Qdiff ); } En_shift = 0; move16(); - if (GT_16(Q_local, 3)) + if ( GT_16( Q_local, 3 ) ) { /* increase margin for energy accumulation in calc_tilt and vare accumulation */ - En_shift = sub(Q_local, 3); + En_shift = sub( Q_local, 3 ); } - IF (LT_16(min_alpha, TILT_COMP_LIM_FX)) + IF( LT_16( min_alpha, TILT_COMP_LIM_FX ) ) { - FOR (i_subfr=0; i_subfrge_sm = ISP_SMOOTHING_QUANT_A1 * st->ge_sm + (1.0f-ISP_SMOOTHING_QUANT_A1) * ge */ - IF ( EQ_16(*uv_count,1)) + IF( EQ_16( *uv_count, 1 ) ) { - *ge_sm = L_shr(L_Ge,Q_local); + *ge_sm = L_shr( L_Ge, Q_local ); } ELSE { - L_tmp = Mult_32_16(L_Ge,P1); /* 0.1*ge still in Q local */ - L_tmp3 = Mult_32_16(*ge_sm,P9); /* 0.9*ge_sm still in Q_ge */ + L_tmp = Mult_32_16( L_Ge, P1 ); /* 0.1*ge still in Q local */ + L_tmp3 = Mult_32_16( *ge_sm, P9 ); /* 0.9*ge_sm still in Q_ge */ - *ge_sm = L_add(L_shr(L_tmp,Q_local),L_tmp3); + *ge_sm = L_add( L_shr( L_tmp, Q_local ), L_tmp3 ); move32(); /* addition in Q_ge domain*/ } @@ -244,40 +244,40 @@ void stat_noise_uv_mod_fx( * noimix_fac = 1.0f/(float)sqrt(alpha*alpha + (1-alpha)*(1-alpha)) *--------------------------------------------------------------------*/ - beta = shl(sub(alpha, 16384), 1); - alpha_m1 = sub(32767, alpha); - L_tmp_res = L_mac(0, alpha, alpha); - L_tmp_res = L_mac(L_tmp_res, alpha_m1, alpha_m1); - tmp_den = round_fx(L_Frac_sqrtQ31(L_tmp_res)); + beta = shl( sub( alpha, 16384 ), 1 ); + alpha_m1 = sub( 32767, alpha ); + L_tmp_res = L_mac( 0, alpha, alpha ); + L_tmp_res = L_mac( L_tmp_res, alpha_m1, alpha_m1 ); + tmp_den = round_fx( L_Frac_sqrtQ31( L_tmp_res ) ); - tmp_nom = sub(32767, tmp_den); - tmp_shift = norm_s(tmp_den); - tmp_den = shl(tmp_den, tmp_shift); - tmp_res = div_s(tmp_nom, tmp_den); + tmp_nom = sub( 32767, tmp_den ); + tmp_shift = norm_s( tmp_den ); + tmp_den = shl( tmp_den, tmp_shift ); + tmp_res = div_s( tmp_nom, tmp_den ); - Noimix_fract = shr(tmp_res, tmp_shift); /* float value is in range 0.0 to 0.42 */ + Noimix_fract = shr( tmp_res, tmp_shift ); /* float value is in range 0.0 to 0.42 */ /* L_Ge might be 0 in unvoiced WB */ - L_Ge = L_max(L_Ge, 1); - tmp_shift = norm_l(L_Ge); - tmp_den = extract_h(L_shl(L_Ge, tmp_shift)); /* Q_local+Q_ge+tmp_shift-16 */ - tmp_res = div_s(1<<14, tmp_den); /* 15+14-Q_local-tmp_shift-Q_ge+16 */ - L_tmp_res = Mult_32_16(*ge_sm, tmp_res); /* Q_stat_noise_ge+45-Q_local-Q_ge-tmp_shift-15 */ - L_tmp_res = Mult_32_16(L_tmp_res, sub(32767, beta)); /*30-Q_local-tmp_shift+15-15 */ + L_Ge = L_max( L_Ge, 1 ); + tmp_shift = norm_l( L_Ge ); + tmp_den = extract_h( L_shl( L_Ge, tmp_shift ) ); /* Q_local+Q_ge+tmp_shift-16 */ + tmp_res = div_s( 1 << 14, tmp_den ); /* 15+14-Q_local-tmp_shift-Q_ge+16 */ + L_tmp_res = Mult_32_16( *ge_sm, tmp_res ); /* Q_stat_noise_ge+45-Q_local-Q_ge-tmp_shift-15 */ + L_tmp_res = Mult_32_16( L_tmp_res, sub( 32767, beta ) ); /*30-Q_local-tmp_shift+15-15 */ #ifdef BASOP_NOGLOB L_tmp_res = L_add_sat( L_shl_sat( L_tmp_res, sub( add( Q_local, tmp_shift ), 15 ) ), beta ); /* Q15 */ #else - L_tmp_res = L_add(L_shl(L_tmp_res, sub(add(Q_local, tmp_shift), 15)), beta); /* Q15 */ + L_tmp_res = L_add( L_shl( L_tmp_res, sub( add( Q_local, tmp_shift ), 15 ) ), beta ); /* Q15 */ #endif #ifdef BASOP_NOGLOB - tmp_res = extract_h(L_shl_o(L_tmp_res, 15, &Overflow)); /* 15+15-16=14 */ + tmp_res = extract_h( L_shl_o( L_tmp_res, 15, &Overflow ) ); /* 15+15-16=14 */ #else - tmp_res = extract_h(L_shl(L_tmp_res, 15)); /* 15+15-16=14 */ + tmp_res = extract_h( L_shl( L_tmp_res, 15 ) ); /* 15+15-16=14 */ #endif - Noimix_fract = extract_l(Mult_32_16(L_tmp_res, Noimix_fract)); /*15+15-15 */ + Noimix_fract = extract_l( Mult_32_16( L_tmp_res, Noimix_fract ) ); /*15+15-15 */ - FOR (i=0; ige_sm*Rnd*((1.0f)-alpha) @@ -287,34 +287,34 @@ void stat_noise_uv_mod_fx( *--------------------------------------------------------------------*/ /* (1-alpha)*(float)sqrt(12.0f) * ((float)own_random(&(st->noimix_seed))/65536.0f) */ - randval = Random(noimix_seed); /* +/-32767 */ - randval = mult_r(28378, randval); /* Q downscaled by 2 bits ends up in Q14 */ /*sqrt(12.0f) in Q13*/ - randval = extract_l(L_shl(Mult_32_16(L_Ge, randval), 1-*Q_stat_noise_ge)); /*Q_local+Q_ge+14-15+1-Q_ge=Q_local */ + randval = Random( noimix_seed ); /* +/-32767 */ + randval = mult_r( 28378, randval ); /* Q downscaled by 2 bits ends up in Q14 */ /*sqrt(12.0f) in Q13*/ + randval = extract_l( L_shl( Mult_32_16( L_Ge, randval ), 1 - *Q_stat_noise_ge ) ); /*Q_local+Q_ge+14-15+1-Q_ge=Q_local */ - L_tmp = L_mult(Exc2_local[i], alpha); /* Q_local + 16 */ - L_tmp = L_mac(L_tmp, randval, alpha_m1); /* Q_local + 16 */ - L_tmp3 = Mult_32_16(L_tmp, Noimix_fract); /* Q_local+16+15-15 */ + L_tmp = L_mult( Exc2_local[i], alpha ); /* Q_local + 16 */ + L_tmp = L_mac( L_tmp, randval, alpha_m1 ); /* Q_local + 16 */ + L_tmp3 = Mult_32_16( L_tmp, Noimix_fract ); /* Q_local+16+15-15 */ #ifdef BASOP_NOGLOB L_tmp = L_add_sat( L_tmp3, L_shl_sat( Mult_32_16( L_tmp, tmp_res ), 1 ) ); /* Q_local+16+14-15+1 */ #else - L_tmp = L_add(L_tmp3, L_shl(Mult_32_16(L_tmp, tmp_res), 1)); /* Q_local+16+14-15+1 */ + L_tmp = L_add( L_tmp3, L_shl( Mult_32_16( L_tmp, tmp_res ), 1 ) ); /* Q_local+16+14-15+1 */ #endif - Exc2_local[i] = extract_h(L_tmp); /*Q_local */ + Exc2_local[i] = extract_h( L_tmp ); /*Q_local */ } - *Q_stat_noise = Q_local; /* update for next call, routine can only be called once every frame */ - Qdiff = sub(Q_exc, Q_local); /* local excitation and incoming excitation */ - Scale_sig(Exc2_local, L_FRAME, Qdiff); - Copy(Exc2_local, exc2, L_FRAME); + *Q_stat_noise = Q_local; /* update for next call, routine can only be called once every frame */ + Qdiff = sub( Q_exc, Q_local ); /* local excitation and incoming excitation */ + Scale_sig( Exc2_local, L_FRAME, Qdiff ); + Copy( Exc2_local, exc2, L_FRAME ); /*--------------------------------------------------------------------* * Generate low-pass filtered version of ISP coefficients *--------------------------------------------------------------------*/ - FOR (k=0; k correlation loop can be optimized */ #ifdef BASOP_NOGLOB r0 = L_mac_sat( r0, xi, xi ); #else - r0 = L_mac(r0,xi,xi); + r0 = L_mac( r0, xi, xi ); #endif - xi_p1 = shr(x[i+1], Q_shift); + xi_p1 = shr( x[i + 1], Q_shift ); #ifdef BASOP_NOGLOB r1 = L_mac_sat( r1, xi, xi_p1 ); #else - r1 = L_mac(r1, xi, xi_p1); + r1 = L_mac( r1, xi, xi_p1 ); #endif xi = xi_p1; move16(); } - if (r0 == 0) + if ( r0 == 0 ) { - r0 = L_shl(327, 16); + r0 = L_shl( 327, 16 ); } - tmp_shift = norm_l(r0); + tmp_shift = norm_l( r0 ); move16(); - r0 = L_shl(r0,tmp_shift); + r0 = L_shl( r0, tmp_shift ); tmp_sign = 1; move16(); - if (r1 >= 0) + if ( r1 >= 0 ) { tmp_sign = 0; move16(); } - r1 = L_abs(r1); + r1 = L_abs( r1 ); - L_tmp_res = Div_32(r1,extract_h(r0), extract_l(r0)); + L_tmp_res = Div_32( r1, extract_h( r0 ), extract_l( r0 ) ); #ifdef BASOP_NOGLOB L_tmp_res = L_shl_sat( L_tmp_res, tmp_shift ); /*Q31 */ #else L_tmp_res = L_shl( L_tmp_res, tmp_shift ); /*Q31 */ #endif - if (tmp_sign != 0) + if ( tmp_sign != 0 ) { - L_tmp_res = L_negate(L_tmp_res); /*Q31 */ + L_tmp_res = L_negate( L_tmp_res ); /*Q31 */ } - return extract_h(L_tmp_res); /*Q15 */ + return extract_h( L_tmp_res ); /*Q15 */ } /*---------------------------------------------------------------------------* @@ -435,8 +434,8 @@ static Word16 calc_tilt_fx( /* o : Excitation tilt Q15*/ * Calculate square root from fractional values (Q0 -> Q0) * Uses 32 bit internal representation for precision *---------------------------------------------------------------------------*/ -Word32 L_Sqrt_Q0( /* o : Square root of input */ - const Word32 x /* i : Input */ +Word32 L_Sqrt_Q0( /* o : Square root of input */ + const Word32 x /* i : Input */ ) { Word32 log2_work; @@ -444,17 +443,16 @@ Word32 L_Sqrt_Q0( /* o : Square root of input */ Word16 log2_int; Word16 log2_frac; - IF (x > 0) + IF( x > 0 ) { - log2_int = norm_l(x); - log2_frac = Log2_norm_lc(L_shl(x, log2_int)); + log2_int = norm_l( x ); + log2_frac = Log2_norm_lc( L_shl( x, log2_int ) ); - log2_work = L_mac0(30*32768L, log2_frac, 1); - log2_work = L_msu(log2_work, log2_int, 16384); - log2_frac = L_Extract_lc(log2_work, &log2_int); + log2_work = L_mac0( 30 * 32768L, log2_frac, 1 ); + log2_work = L_msu( log2_work, log2_int, 16384 ); + log2_frac = L_Extract_lc( log2_work, &log2_int ); - return Pow2(log2_int, log2_frac); + return Pow2( log2_int, log2_frac ); } return 0; } - diff --git a/lib_com/stl.h b/lib_com/stl.h index 5ffc103a4..ad437e3b2 100644 --- a/lib_com/stl.h +++ b/lib_com/stl.h @@ -74,7 +74,7 @@ //#include "wmc_auto.h" #include "move.h" #include "control.h" -#include "oper_32b.h" +#include "oper_32b.h" #include "enh1632.h" #include "enh40.h" #include "enh64.h" diff --git a/lib_com/swb_bwe_com_fx.c b/lib_com/swb_bwe_com_fx.c index f50094e78..f194355bf 100644 --- a/lib_com/swb_bwe_com_fx.c +++ b/lib_com/swb_bwe_com_fx.c @@ -38,440 +38,441 @@ #include "rom_com.h" - /*==========================================================================*/ - /* FUNCTION : Word16 WB_BWE_gain_pred_fx () */ - /*--------------------------------------------------------------------------*/ - /* PURPOSE : predict WB frequency envelopes for 0b WB BWE */ - /*--------------------------------------------------------------------------*/ - /* INPUT ARGUMENTS : */ - /* _Word16 *core_dec_freq i : Frequency domain core decoded signal */ - /* _Word16 coder_type i : coding type */ - /* _Word16 prev_coder_type i : coding type of last frame */ - /* _Word16 prev_WB_fenv i : envelope for last frame */ - /* _Word16 *voice_factors i : voicing factors //Q15 */ - /* _Word16 pitch_buf[] i : pitch buffer //Q6 */ - /* _Word16 last_core_brate i : previous frame core bitrate */ - /* _Word16 last_wb_bwe_ener i : previous frame wb bwe signal energy */ - /*--------------------------------------------------------------------------*/ - /* OUTPUT ARGUMENTS : */ - /* _Word16 *WB_fenv, o : WB frequency envelopes Q3 */ - /*--------------------------------------------------------------------------*/ - /* INPUT/OUTPUT ARGUMENTS : */ - /*--------------------------------------------------------------------------*/ - /* RETURN ARGUMENTS : */ - /* _Word16 mode */ - /*--------------------------------------------------------------------------*/ - /* CALLED FROM : */ - /*==========================================================================*/ +/*==========================================================================*/ +/* FUNCTION : Word16 WB_BWE_gain_pred_fx () */ +/*--------------------------------------------------------------------------*/ +/* PURPOSE : predict WB frequency envelopes for 0b WB BWE */ +/*--------------------------------------------------------------------------*/ +/* INPUT ARGUMENTS : */ +/* _Word16 *core_dec_freq i : Frequency domain core decoded signal */ +/* _Word16 coder_type i : coding type */ +/* _Word16 prev_coder_type i : coding type of last frame */ +/* _Word16 prev_WB_fenv i : envelope for last frame */ +/* _Word16 *voice_factors i : voicing factors //Q15 */ +/* _Word16 pitch_buf[] i : pitch buffer //Q6 */ +/* _Word16 last_core_brate i : previous frame core bitrate */ +/* _Word16 last_wb_bwe_ener i : previous frame wb bwe signal energy */ +/*--------------------------------------------------------------------------*/ +/* OUTPUT ARGUMENTS : */ +/* _Word16 *WB_fenv, o : WB frequency envelopes Q3 */ +/*--------------------------------------------------------------------------*/ +/* INPUT/OUTPUT ARGUMENTS : */ +/*--------------------------------------------------------------------------*/ +/* RETURN ARGUMENTS : */ +/* _Word16 mode */ +/*--------------------------------------------------------------------------*/ +/* CALLED FROM : */ +/*==========================================================================*/ Word16 WB_BWE_gain_pred_fx( - Word16 *WB_fenv, /* o : WB frequency envelopes */ - const Word16 *core_dec_freq, /* i : Frequency domain core decoded signal */ - const Word16 coder_type, /* i : coding type */ - Word16 prev_coder_type, /* i : coding type of last frame */ - Word16 prev_WB_fenv, /* i : envelope for last frame */ - Word16 *voice_factors, /* i : voicing factors //Q15 */ - const Word16 pitch_buf[], /* i : pitch buffer //Q6 */ - Word32 last_core_brate, /* i : previous frame core bitrate */ - Word16 last_wb_bwe_ener, /* i : previous frame wb bwe signal energy */ - Word16 Q_syn, /* i : synthesis scaling */ - Word16 last_extl_fx, /* i : extl. layer for last frame */ - Word16 tilt_wb_fx -) + Word16 *WB_fenv, /* o : WB frequency envelopes */ + const Word16 *core_dec_freq, /* i : Frequency domain core decoded signal */ + const Word16 coder_type, /* i : coding type */ + Word16 prev_coder_type, /* i : coding type of last frame */ + Word16 prev_WB_fenv, /* i : envelope for last frame */ + Word16 *voice_factors, /* i : voicing factors //Q15 */ + const Word16 pitch_buf[], /* i : pitch buffer //Q6 */ + Word32 last_core_brate, /* i : previous frame core bitrate */ + Word16 last_wb_bwe_ener, /* i : previous frame wb bwe signal energy */ + Word16 Q_syn, /* i : synthesis scaling */ + Word16 last_extl_fx, /* i : extl. layer for last frame */ + Word16 tilt_wb_fx ) { - Word32 enerL; - Word16 n_freq, mode, pitch; - Word16 ener_var_flag = 0; - Word16 voice_factor, enerL_16, enerL_40, enerL_64; - Word16 env_var_flag = 0; - Word16 exp; - Word16 tmp, tmp1; - Word32 L_tmp; - Word32 L_WB_fenv0, L_WB_fenv1; - Word16 pitch_buf_tmp[4]; - Word16 alfa = 32767; - move16(); - - mode = NORMAL; - move16(); - - enerL = L_deposit_l(0); - FOR(n_freq = 128; n_freq < 192; n_freq++) - { + Word32 enerL; + Word16 n_freq, mode, pitch; + Word16 ener_var_flag = 0; + Word16 voice_factor, enerL_16, enerL_40, enerL_64; + Word16 env_var_flag = 0; + Word16 exp; + Word16 tmp, tmp1; + Word32 L_tmp; + Word32 L_WB_fenv0, L_WB_fenv1; + Word16 pitch_buf_tmp[4]; + Word16 alfa = 32767; + move16(); + + mode = NORMAL; + move16(); + + enerL = L_deposit_l( 0 ); + FOR( n_freq = 128; n_freq < 192; n_freq++ ) + { #ifdef BASOP_NOGLOB - enerL = L_mac0_sat(enerL, core_dec_freq[n_freq], core_dec_freq[n_freq]); /*2(Q_syn) */ + enerL = L_mac0_sat( enerL, core_dec_freq[n_freq], core_dec_freq[n_freq] ); /*2(Q_syn) */ #else - enerL = L_mac0(enerL, core_dec_freq[n_freq], core_dec_freq[n_freq]); /*2(Q_syn) */ + enerL = L_mac0( enerL, core_dec_freq[n_freq], core_dec_freq[n_freq] ); /*2(Q_syn) */ #endif - } + } - L_WB_fenv0 = L_deposit_l(0); - FOR(n_freq = 192; n_freq < 224; n_freq++) - { + L_WB_fenv0 = L_deposit_l( 0 ); + FOR( n_freq = 192; n_freq < 224; n_freq++ ) + { #ifdef BASOP_NOGLOB - L_WB_fenv0 = L_mac0_sat(L_WB_fenv0, core_dec_freq[n_freq], core_dec_freq[n_freq]);/*2*Q_syn */ + L_WB_fenv0 = L_mac0_sat( L_WB_fenv0, core_dec_freq[n_freq], core_dec_freq[n_freq] ); /*2*Q_syn */ #else - L_WB_fenv0 = L_mac0(L_WB_fenv0, core_dec_freq[n_freq], core_dec_freq[n_freq]);/*2*Q_syn */ + L_WB_fenv0 = L_mac0( L_WB_fenv0, core_dec_freq[n_freq], core_dec_freq[n_freq] ); /*2*Q_syn */ #endif - } + } - L_WB_fenv1 = L_deposit_l(0); - FOR(n_freq = 224; n_freq < 256; n_freq++) - { + L_WB_fenv1 = L_deposit_l( 0 ); + FOR( n_freq = 224; n_freq < 256; n_freq++ ) + { #ifdef BASOP_NOGLOB - L_WB_fenv1 = L_mac0_sat(L_WB_fenv1, core_dec_freq[n_freq], core_dec_freq[n_freq]);/*2*Q_syn */ + L_WB_fenv1 = L_mac0_sat( L_WB_fenv1, core_dec_freq[n_freq], core_dec_freq[n_freq] ); /*2*Q_syn */ #else - L_WB_fenv1 = L_mac0(L_WB_fenv1, core_dec_freq[n_freq], core_dec_freq[n_freq]);/*2*Q_syn */ + L_WB_fenv1 = L_mac0( L_WB_fenv1, core_dec_freq[n_freq], core_dec_freq[n_freq] ); /*2*Q_syn */ #endif - } - - L_tmp = sum16_32_fx(voice_factors, 4); - voice_factor = extract_l(L_shr(L_tmp, 2));/*Q13 */ - Copy_Scale_sig(pitch_buf, pitch_buf_tmp, 4, -1); - pitch = sum16_fx(pitch_buf_tmp, 4); - move16(); /*Q5 */ - - L_tmp = L_shr(enerL, 4); - test(); - IF(GT_32(L_max(L_WB_fenv1, L_WB_fenv0), L_tmp) && GT_16(9856, pitch)) - { - ener_var_flag = 1; - move16(); - } - - test(); + } + + L_tmp = sum16_32_fx( voice_factors, 4 ); + voice_factor = extract_l( L_shr( L_tmp, 2 ) ); /*Q13 */ + Copy_Scale_sig( pitch_buf, pitch_buf_tmp, 4, -1 ); + pitch = sum16_fx( pitch_buf_tmp, 4 ); + move16(); /*Q5 */ + + L_tmp = L_shr( enerL, 4 ); + test(); + IF( GT_32( L_max( L_WB_fenv1, L_WB_fenv0 ), L_tmp ) && GT_16( 9856, pitch ) ) + { + ener_var_flag = 1; + move16(); + } + + test(); #ifdef BASOP_NOGLOB - IF(GT_32(L_WB_fenv0, L_shl_sat(L_WB_fenv1, 1))) + IF( GT_32( L_WB_fenv0, L_shl_sat( L_WB_fenv1, 1 ) ) ) #else - IF(GT_32(L_WB_fenv0, L_shl(L_WB_fenv1, 1))) + IF( GT_32( L_WB_fenv0, L_shl( L_WB_fenv1, 1 ) ) ) #endif - { - exp = norm_l(L_WB_fenv0); - tmp = extract_h(L_shl(L_WB_fenv0, exp)); - tmp = div_s(16384, tmp); /*Q(15+14-2*Q_syn-exp) */ - L_tmp = L_shr(Mult_32_16(L_shl(L_WB_fenv1, 1), tmp), sub(15, exp));/*2*Q_syn+15+exp-15->2*Q_syn+exp */ - /*L_tmp Q15 */ - tmp = extract_l(L_tmp); - alfa = s_max(tmp, 3277);/*Q15 */ - L_WB_fenv0 = Mult_32_16(L_WB_fenv0, alfa);/*2*Q_syn+15-15->2*Q_syn */ - } + { + exp = norm_l( L_WB_fenv0 ); + tmp = extract_h( L_shl( L_WB_fenv0, exp ) ); + tmp = div_s( 16384, tmp ); /*Q(15+14-2*Q_syn-exp) */ + L_tmp = L_shr( Mult_32_16( L_shl( L_WB_fenv1, 1 ), tmp ), sub( 15, exp ) ); /*2*Q_syn+15+exp-15->2*Q_syn+exp */ + /*L_tmp Q15 */ + tmp = extract_l( L_tmp ); + alfa = s_max( tmp, 3277 ); /*Q15 */ + L_WB_fenv0 = Mult_32_16( L_WB_fenv0, alfa ); /*2*Q_syn+15-15->2*Q_syn */ + } #ifdef BASOP_NOGLOB - ELSE IF(GT_32(L_WB_fenv1, L_shl_sat(L_WB_fenv0, 1)) && NE_16(coder_type, UNVOICED)) + ELSE IF( GT_32( L_WB_fenv1, L_shl_sat( L_WB_fenv0, 1 ) ) && NE_16( coder_type, UNVOICED ) ) #else - ELSE IF(GT_32(L_WB_fenv1, L_shl(L_WB_fenv0, 1)) && NE_16(coder_type, UNVOICED)) + ELSE IF( GT_32( L_WB_fenv1, L_shl( L_WB_fenv0, 1 ) ) && NE_16( coder_type, UNVOICED ) ) #endif - { - exp = norm_l(L_WB_fenv1); - tmp = extract_h(L_shl(L_WB_fenv1, exp)); - tmp = div_s(16384, tmp); /*Q(15+14-2*Q_syn-exp) */ - L_tmp = L_shr(Mult_32_16(L_shl(L_WB_fenv0, 1), tmp), sub(15, exp));/*2*Q_syn+15+exp-15->2*Q_syn+exp */ - /*L_tmp Q15 */ - tmp = extract_l(L_tmp); - alfa = s_max(tmp, 3277);/*Q15 */ - L_WB_fenv1 = Mult_32_16(L_WB_fenv1, alfa);/*2*Q_syn+15-15->2*Q_syn */ - } - - if (L_WB_fenv0 == 0) - { - L_WB_fenv0 = L_deposit_l(1); - } - - if (L_WB_fenv1 == 0) - { - L_WB_fenv1 = L_deposit_l(1); - } - - if (enerL == 0) - { - enerL = L_deposit_l(1); - } + { + exp = norm_l( L_WB_fenv1 ); + tmp = extract_h( L_shl( L_WB_fenv1, exp ) ); + tmp = div_s( 16384, tmp ); /*Q(15+14-2*Q_syn-exp) */ + L_tmp = L_shr( Mult_32_16( L_shl( L_WB_fenv0, 1 ), tmp ), sub( 15, exp ) ); /*2*Q_syn+15+exp-15->2*Q_syn+exp */ + /*L_tmp Q15 */ + tmp = extract_l( L_tmp ); + alfa = s_max( tmp, 3277 ); /*Q15 */ + L_WB_fenv1 = Mult_32_16( L_WB_fenv1, alfa ); /*2*Q_syn+15-15->2*Q_syn */ + } + + if ( L_WB_fenv0 == 0 ) + { + L_WB_fenv0 = L_deposit_l( 1 ); + } + + if ( L_WB_fenv1 == 0 ) + { + L_WB_fenv1 = L_deposit_l( 1 ); + } + + if ( enerL == 0 ) + { + enerL = L_deposit_l( 1 ); + } #ifdef BASOP_NOGLOB - L_tmp = L_add_sat(L_WB_fenv0, L_WB_fenv1); /* In 2*Q_syn */ + L_tmp = L_add_sat( L_WB_fenv0, L_WB_fenv1 ); /* In 2*Q_syn */ #else - L_tmp = L_add(L_WB_fenv0, L_WB_fenv1); /* In 2*Q_syn */ + L_tmp = L_add( L_WB_fenv0, L_WB_fenv1 ); /* In 2*Q_syn */ #endif - exp = norm_l(L_tmp); - tmp = extract_h(L_shl(L_tmp, exp)); - /*exp = sub(exp, 30-(2*Q_syn+6)); //+6(/64) */ - exp = sub(exp, sub(30, add(shl(Q_syn, 1), 6))); /*+6(/64) */ + exp = norm_l( L_tmp ); + tmp = extract_h( L_shl( L_tmp, exp ) ); + /*exp = sub(exp, 30-(2*Q_syn+6)); //+6(/64) */ + exp = sub( exp, sub( 30, add( shl( Q_syn, 1 ), 6 ) ) ); /*+6(/64) */ - tmp = div_s(16384, tmp); - L_tmp = L_deposit_h(tmp); - L_tmp = Isqrt_lc(L_tmp, &exp); + tmp = div_s( 16384, tmp ); + L_tmp = L_deposit_h( tmp ); + L_tmp = Isqrt_lc( L_tmp, &exp ); #ifdef BASOP_NOGLOB - WB_fenv[0] = round_fx_sat(L_shl_sat(L_tmp, sub(exp, 12))); /* Q3 */ + WB_fenv[0] = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 12 ) ) ); /* Q3 */ #else - WB_fenv[0] = round_fx(L_shl(L_tmp, sub(exp, 12))); /* Q3 */ + WB_fenv[0] = round_fx( L_shl( L_tmp, sub( exp, 12 ) ) ); /* Q3 */ #endif - test(); - test(); - IF(NE_16(coder_type, AUDIO) && NE_16(coder_type, UNVOICED) && ener_var_flag == 0) - { + test(); + test(); + IF( NE_16( coder_type, AUDIO ) && NE_16( coder_type, UNVOICED ) && ener_var_flag == 0 ) + { #ifdef BASOP_NOGLOB - WB_fenv[0] = add_sat(WB_fenv[0], mult_r_sat(WB_fenv[0], 16384)); + WB_fenv[0] = add_sat( WB_fenv[0], mult_r_sat( WB_fenv[0], 16384 ) ); #else - WB_fenv[0] = add(WB_fenv[0], mult_r(WB_fenv[0], 16384)); + WB_fenv[0] = add( WB_fenv[0], mult_r( WB_fenv[0], 16384 ) ); #endif - move16(); - } + move16(); + } - exp = norm_l(enerL); - tmp = extract_h(L_shl(enerL, exp)); - exp = sub(exp, sub(30, shl(Q_syn, 1))); + exp = norm_l( enerL ); + tmp = extract_h( L_shl( enerL, exp ) ); + exp = sub( exp, sub( 30, shl( Q_syn, 1 ) ) ); - tmp = div_s(16384, tmp); - L_tmp = L_deposit_h(tmp); - L_tmp = Isqrt_lc(L_tmp, &exp); + tmp = div_s( 16384, tmp ); + L_tmp = L_deposit_h( tmp ); + L_tmp = Isqrt_lc( L_tmp, &exp ); #ifdef BASOP_NOGLOB - enerL_16 = round_fx_sat(L_shl_sat(L_tmp, sub(exp, 15))); /* Q0 */ + enerL_16 = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 15 ) ) ); /* Q0 */ #else - enerL_16 = round_fx(L_shl(L_tmp, sub(exp, 15))); /* Q0 */ + enerL_16 = round_fx( L_shl( L_tmp, sub( exp, 15 ) ) ); /* Q0 */ #endif - enerL_40 = mult_r(6554, enerL_16); /*1/40 in Q18 ->Q3 */ - - test(); - test(); - test(); - test(); - test(); - test(); - IF(NE_16(coder_type, TRANSITION) && NE_16(coder_type, AUDIO) && NE_16(coder_type, UNVOICED) && - GT_16(enerL_40, WB_fenv[0]) && GT_16(alfa, 29491) && !(EQ_16(coder_type, prev_coder_type) && - GT_16(WB_fenv[0], prev_WB_fenv))) - { - IF(WB_fenv[0] != 0) - { - exp = norm_s(WB_fenv[0]); - tmp = div_s(shl(1, sub(14, exp)), WB_fenv[0]); /*Q(29-exp-3) */ - L_tmp = L_mult(enerL_40, tmp); /*Q(30-exp) */ + enerL_40 = mult_r( 6554, enerL_16 ); /*1/40 in Q18 ->Q3 */ + + test(); + test(); + test(); + test(); + test(); + test(); + IF( NE_16( coder_type, TRANSITION ) && NE_16( coder_type, AUDIO ) && NE_16( coder_type, UNVOICED ) && + GT_16( enerL_40, WB_fenv[0] ) && GT_16( alfa, 29491 ) && !( EQ_16( coder_type, prev_coder_type ) && GT_16( WB_fenv[0], prev_WB_fenv ) ) ) + { + IF( WB_fenv[0] != 0 ) + { + exp = norm_s( WB_fenv[0] ); + tmp = div_s( shl( 1, sub( 14, exp ) ), WB_fenv[0] ); /*Q(29-exp-3) */ + L_tmp = L_mult( enerL_40, tmp ); /*Q(30-exp) */ #ifdef BASOP_NOGLOB - tmp = round_fx_sat(L_shl_sat(L_tmp, sub(exp, 2))); /*Q12 */ + tmp = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 2 ) ) ); /*Q12 */ #else - tmp = round_fx(L_shl(L_tmp, sub(exp, 2))); /*Q12 */ + tmp = round_fx( L_shl( L_tmp, sub( exp, 2 ) ) ); /*Q12 */ #endif - tmp = s_min(tmp, 16384); - L_tmp = L_shr(L_mult0(tmp, WB_fenv[0]), 12);/*Q15 */ - WB_fenv[0] = extract_l(L_tmp);/*Q3 */ - } - - IF(GT_16(WB_fenv[0], prev_WB_fenv)) - { - /*WB_fenv[0]= add(mult_r(9830, WB_fenv[0]), mult_r(22938, prev_WB_fenv)); move16();//Q3 */ - WB_fenv[0] = round_fx(L_mac(L_mult(9830, WB_fenv[0]), 22938, prev_WB_fenv));/*Q3 */ - } - } - - L_tmp = L_mult0(voice_factor, 77); - tmp1 = extract_l(L_shr(L_tmp, 13)); - - exp = norm_s(pitch); - tmp = div_s(shl(1, sub(14, exp)), pitch); /*Q(29-exp-5) */ - L_tmp = L_mult0(tmp1, tmp); /*29-exp-5->24-exp */ + tmp = s_min( tmp, 16384 ); + L_tmp = L_shr( L_mult0( tmp, WB_fenv[0] ), 12 ); /*Q15 */ + WB_fenv[0] = extract_l( L_tmp ); /*Q3 */ + } + + IF( GT_16( WB_fenv[0], prev_WB_fenv ) ) + { + /*WB_fenv[0]= add(mult_r(9830, WB_fenv[0]), mult_r(22938, prev_WB_fenv)); move16();//Q3 */ + WB_fenv[0] = round_fx( L_mac( L_mult( 9830, WB_fenv[0] ), 22938, prev_WB_fenv ) ); /*Q3 */ + } + } + + L_tmp = L_mult0( voice_factor, 77 ); + tmp1 = extract_l( L_shr( L_tmp, 13 ) ); + + exp = norm_s( pitch ); + tmp = div_s( shl( 1, sub( 14, exp ) ), pitch ); /*Q(29-exp-5) */ + L_tmp = L_mult0( tmp1, tmp ); /*29-exp-5->24-exp */ #ifdef BASOP_NOGLOB - tmp = round_fx_sat(L_shl_sat(L_tmp, add(exp, 6))); /*14 */ + tmp = round_fx_sat( L_shl_sat( L_tmp, add( exp, 6 ) ) ); /*14 */ #else - tmp = round_fx(L_shl(L_tmp, add(exp, 6))); /*14 */ + tmp = round_fx( L_shl( L_tmp, add( exp, 6 ) ) ); /*14 */ #endif - tmp1 = s_max(tmp, 8192); - alfa = s_min(24576, tmp1);/*Q14 */ + tmp1 = s_max( tmp, 8192 ); + alfa = s_min( 24576, tmp1 ); /*Q14 */ - L_tmp = L_mult0(alfa, WB_fenv[0]);/*Q14+Q3->Q17 */ - L_tmp = L_shr(L_tmp, 14);/*Q3 */ - tmp = extract_l(L_tmp); + L_tmp = L_mult0( alfa, WB_fenv[0] ); /*Q14+Q3->Q17 */ + L_tmp = L_shr( L_tmp, 14 ); /*Q3 */ + tmp = extract_l( L_tmp ); - enerL = L_deposit_l(enerL_16); - enerL = L_shl(enerL, 6); /*Q6 */ + enerL = L_deposit_l( enerL_16 ); + enerL = L_shl( enerL, 6 ); /*Q6 */ #ifdef BASOP_NOGLOB - tmp1 = i_mult_sat(3, WB_fenv[0]);/*Q3 */ + tmp1 = i_mult_sat( 3, WB_fenv[0] ); /*Q3 */ #else - tmp1 = i_mult(3, WB_fenv[0]);/*Q3 */ + tmp1 = i_mult( 3, WB_fenv[0] ); /*Q3 */ #endif - L_tmp = L_mult0(tmp1, WB_fenv[0]); /*Q6 */ - - test(); - test(); - test(); - IF(GT_16(shr(enerL_16, 3), tmp) && GT_32(enerL, L_tmp) && NE_16(prev_coder_type, UNVOICED) && WB_fenv[0] != 0) - { - env_var_flag = 1; - move16(); - enerL_64 = mult_r(4096, enerL_16);/* 1/64 in Q18 ->Q3 */ - - exp = norm_s(WB_fenv[0]); - tmp = div_s(shl(1, sub(14, exp)), WB_fenv[0]); /*Q(29-exp-3) */ - L_tmp = L_mult(enerL_64, tmp); /*Q(30-exp) */ + L_tmp = L_mult0( tmp1, WB_fenv[0] ); /*Q6 */ + + test(); + test(); + test(); + IF( GT_16( shr( enerL_16, 3 ), tmp ) && GT_32( enerL, L_tmp ) && NE_16( prev_coder_type, UNVOICED ) && WB_fenv[0] != 0 ) + { + env_var_flag = 1; + move16(); + enerL_64 = mult_r( 4096, enerL_16 ); /* 1/64 in Q18 ->Q3 */ + + exp = norm_s( WB_fenv[0] ); + tmp = div_s( shl( 1, sub( 14, exp ) ), WB_fenv[0] ); /*Q(29-exp-3) */ + L_tmp = L_mult( enerL_64, tmp ); /*Q(30-exp) */ #ifdef BASOP_NOGLOB - tmp = round_fx_sat(L_shl_sat(L_tmp, sub(exp, 2))); /*Q12 */ + tmp = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 2 ) ) ); /*Q12 */ #else - tmp = round_fx(L_shl(L_tmp, sub(exp, 2))); /*Q12 */ + tmp = round_fx( L_shl( L_tmp, sub( exp, 2 ) ) ); /*Q12 */ #endif - tmp = s_min(tmp, 16384); - L_tmp = L_shr(L_mult0(tmp, WB_fenv[0]), 12);/*Q3 */ - WB_fenv[0] = extract_l(L_tmp);/*Q3 */ - - IF(GT_16(WB_fenv[0], prev_WB_fenv)) - { - /*WB_fenv[0] = add(mult_r(9830, WB_fenv[0]), mult_r(22938, prev_WB_fenv));//Q3 */ - WB_fenv[0] = round_fx(L_mac(L_mult(9830, WB_fenv[0]), 22938, prev_WB_fenv));/*Q3 */ - } - } - - test(); - IF(EQ_16(coder_type, UNVOICED) || EQ_16(prev_coder_type, UNVOICED)) - { - WB_fenv[0] = shr(WB_fenv[0], 1); - move16();/*Q3 */ - } - - IF(NE_16(coder_type, AUDIO)) - { - tmp = mult_r(voice_factor, 19661); /*Q12 */ - tmp = s_max(tmp, 4096); - exp = norm_s(tmp); - tmp = div_s(shl(1, sub(14, exp)), tmp); /*Q(29-exp-12) */ - L_tmp = L_mult(WB_fenv[0], tmp); /*Q(21-exp) */ - - WB_fenv[0] = round_fx(L_shl(L_tmp, sub(exp, 2))); /*Q3 */ - tmp1 = mult_r(328, pitch);/*Q7 */ - tmp = s_min(s_max(tmp1, 16), 256);/*Q7 */ - L_tmp = L_shr(L_mult0(WB_fenv[0], tmp), 7);/*Q3 */ - /*WB_fenv[0] = saturate(L_tmp); //Q3 */ + tmp = s_min( tmp, 16384 ); + L_tmp = L_shr( L_mult0( tmp, WB_fenv[0] ), 12 ); /*Q3 */ + WB_fenv[0] = extract_l( L_tmp ); /*Q3 */ + + IF( GT_16( WB_fenv[0], prev_WB_fenv ) ) + { + /*WB_fenv[0] = add(mult_r(9830, WB_fenv[0]), mult_r(22938, prev_WB_fenv));//Q3 */ + WB_fenv[0] = round_fx( L_mac( L_mult( 9830, WB_fenv[0] ), 22938, prev_WB_fenv ) ); /*Q3 */ + } + } + + test(); + IF( EQ_16( coder_type, UNVOICED ) || EQ_16( prev_coder_type, UNVOICED ) ) + { + WB_fenv[0] = shr( WB_fenv[0], 1 ); + move16(); /*Q3 */ + } + + IF( NE_16( coder_type, AUDIO ) ) + { + tmp = mult_r( voice_factor, 19661 ); /*Q12 */ + tmp = s_max( tmp, 4096 ); + exp = norm_s( tmp ); + tmp = div_s( shl( 1, sub( 14, exp ) ), tmp ); /*Q(29-exp-12) */ + L_tmp = L_mult( WB_fenv[0], tmp ); /*Q(21-exp) */ + + WB_fenv[0] = round_fx( L_shl( L_tmp, sub( exp, 2 ) ) ); /*Q3 */ + tmp1 = mult_r( 328, pitch ); /*Q7 */ + tmp = s_min( s_max( tmp1, 16 ), 256 ); /*Q7 */ + L_tmp = L_shr( L_mult0( WB_fenv[0], tmp ), 7 ); /*Q3 */ + /*WB_fenv[0] = saturate(L_tmp); //Q3 */ #ifdef BASOP_NOGLOB - WB_fenv[0] = round_fx_sat(L_shl_sat(L_tmp, 16)); /*Q3 */ + WB_fenv[0] = round_fx_sat( L_shl_sat( L_tmp, 16 ) ); /*Q3 */ #else - WB_fenv[0] = round_fx(L_shl(L_tmp, 16)); /*Q3 */ + WB_fenv[0] = round_fx( L_shl( L_tmp, 16 ) ); /*Q3 */ #endif - } - test(); - IF(GT_32(last_core_brate, ACELP_8k00) && GT_16(WB_fenv[0], last_wb_bwe_ener)) - { - /*WB_fenv[0]= add(mult_r(29491, last_wb_bwe_ener), mult_r(3277, WB_fenv[0]));//Q3 */ - WB_fenv[0] = round_fx(L_mac(L_mult(29491, last_wb_bwe_ener), 3277, WB_fenv[0]));/*Q3 */ - } - - IF(NE_16(last_extl_fx, WB_BWE) && LT_16(tilt_wb_fx, 128)) - { - WB_fenv[0] = mult_r(s_min(16384, shl(tilt_wb_fx, 8)), WB_fenv[0]); - } - - IF(env_var_flag == 1) - { - WB_fenv[1] = add(WB_fenv[0], mult_r(WB_fenv[0], 16384)); - move16(); - WB_fenv[0] = mult_r(24576, WB_fenv[0]); - move16();/*Q3 */ - } - ELSE - { - WB_fenv[1] = WB_fenv[0]; - move16(); - } - - test(); - IF(EQ_16(coder_type, UNVOICED) || EQ_16(prev_coder_type, UNVOICED)) - { - WB_fenv[1] = shr(WB_fenv[1], 1); - move16();/*Q3 */ - } - - return (mode); + } + test(); + IF( GT_32( last_core_brate, ACELP_8k00 ) && GT_16( WB_fenv[0], last_wb_bwe_ener ) ) + { + /*WB_fenv[0]= add(mult_r(29491, last_wb_bwe_ener), mult_r(3277, WB_fenv[0]));//Q3 */ + WB_fenv[0] = round_fx( L_mac( L_mult( 29491, last_wb_bwe_ener ), 3277, WB_fenv[0] ) ); /*Q3 */ + } + + IF( NE_16( last_extl_fx, WB_BWE ) && LT_16( tilt_wb_fx, 128 ) ) + { + WB_fenv[0] = mult_r( s_min( 16384, shl( tilt_wb_fx, 8 ) ), WB_fenv[0] ); + } + + IF( env_var_flag == 1 ) + { + WB_fenv[1] = add( WB_fenv[0], mult_r( WB_fenv[0], 16384 ) ); + move16(); + WB_fenv[0] = mult_r( 24576, WB_fenv[0] ); + move16(); /*Q3 */ + } + ELSE + { + WB_fenv[1] = WB_fenv[0]; + move16(); + } + + test(); + IF( EQ_16( coder_type, UNVOICED ) || EQ_16( prev_coder_type, UNVOICED ) ) + { + WB_fenv[1] = shr( WB_fenv[1], 1 ); + move16(); /*Q3 */ + } + + return ( mode ); } /*-------------------------------------------------------------------* -* calc_norm_envelop_lf_fx() -* -* calc_envelope of low frequency spectrum -*-------------------------------------------------------------------*/ -static -void calc_norm_envelop_lf_fx( - const Word32 SWB_signal[], /* i : SWB spectrum */ /* Q12 */ - Word32 *envelope, /* o : normalized envelope */ /* Q12 */ - Word16 *L_swb_norm, /* i/o : length of envelope */ - const Word16 HQ_mode, /* i : HQ mode */ /* Q0 */ - const Word16 hq_generic_offset, /* i : frequency offset for representing hq generic */ /* Q0 */ - Word16 *sfreq, /* i : starting frequency index */ - Word16 *efreq /* i : ending frequency index */ + * calc_norm_envelop_lf_fx() + * + * calc_envelope of low frequency spectrum + *-------------------------------------------------------------------*/ +static void calc_norm_envelop_lf_fx( + const Word32 SWB_signal[], + /* i : SWB spectrum */ /* Q12 */ + Word32 *envelope, + /* o : normalized envelope */ /* Q12 */ + Word16 *L_swb_norm, /* i/o : length of envelope */ + const Word16 HQ_mode, + /* i : HQ mode */ /* Q0 */ + const Word16 hq_generic_offset, + /* i : frequency offset for representing hq generic */ /* Q0 */ + Word16 *sfreq, /* i : starting frequency index */ + Word16 *efreq /* i : ending frequency index */ ) { - Word16 lookback, env_index, n_freq, n_lag_now, n_lag; - - *sfreq = 2; - move16(); - IF(EQ_16(hq_generic_offset, HQ_GENERIC_FOFFSET_24K4)) - { - *efreq = 146; - move16(); - if (EQ_16(HQ_mode, HQ_GEN_FB)) - { - *efreq = 306; - move16(); - } - IF(LT_16(add(shl(sub(328, *efreq), 1), 1), *L_swb_norm)) - { - *L_swb_norm = add(shl(sub(328, *efreq), 1), 1); - } - } - ELSE - { - *efreq = 130; - move16(); - if (EQ_16(HQ_mode, HQ_GEN_FB)) - { - *efreq = 290; - move16(); - } - IF(LT_16(add(shl(sub(400,*efreq),1),1),*L_swb_norm)) - { - *L_swb_norm = add(shl(sub(400,*efreq),1),1); - } - } - lookback = shr(*L_swb_norm, 1); - env_index = 0; - move16(); - n_lag_now = *L_swb_norm; - move16(); - - FOR(n_freq = 0; n_freq < lookback; n_freq++) - { - Word16 tmp; - Word32 L_tmp; - - L_tmp = L_deposit_l(1); - tmp = add(lookback, n_freq); - FOR(n_lag = 0; n_lag < tmp; n_lag++) - { + Word16 lookback, env_index, n_freq, n_lag_now, n_lag; + + *sfreq = 2; + move16(); + IF( EQ_16( hq_generic_offset, HQ_GENERIC_FOFFSET_24K4 ) ) + { + *efreq = 146; + move16(); + if ( EQ_16( HQ_mode, HQ_GEN_FB ) ) + { + *efreq = 306; + move16(); + } + IF( LT_16( add( shl( sub( 328, *efreq ), 1 ), 1 ), *L_swb_norm ) ) + { + *L_swb_norm = add( shl( sub( 328, *efreq ), 1 ), 1 ); + } + } + ELSE + { + *efreq = 130; + move16(); + if ( EQ_16( HQ_mode, HQ_GEN_FB ) ) + { + *efreq = 290; + move16(); + } + IF( LT_16( add( shl( sub( 400, *efreq ), 1 ), 1 ), *L_swb_norm ) ) + { + *L_swb_norm = add( shl( sub( 400, *efreq ), 1 ), 1 ); + } + } + lookback = shr( *L_swb_norm, 1 ); + env_index = 0; + move16(); + n_lag_now = *L_swb_norm; + move16(); + + FOR( n_freq = 0; n_freq < lookback; n_freq++ ) + { + Word16 tmp; + Word32 L_tmp; + + L_tmp = L_deposit_l( 1 ); + tmp = add( lookback, n_freq ); + FOR( n_lag = 0; n_lag < tmp; n_lag++ ) + { #ifdef BASOP_NOGLOB L_tmp = L_add_sat( L_tmp, L_abs( SWB_signal[n_lag] ) ); #else - L_tmp = L_add(L_tmp, L_abs(SWB_signal[n_lag])); + L_tmp = L_add( L_tmp, L_abs( SWB_signal[n_lag] ) ); #endif - } - envelope[env_index] = L_tmp; - move32(); - env_index = add(env_index, 1); - } - - FOR(; n_freq < *efreq; n_freq++) - { - /* Apply MA filter */ - Word32 L_tmp = L_deposit_l(1); - FOR(n_lag = 0; n_lag < n_lag_now; n_lag++) - { + } + envelope[env_index] = L_tmp; + move32(); + env_index = add( env_index, 1 ); + } + + FOR( ; n_freq < *efreq; n_freq++ ) + { + /* Apply MA filter */ + Word32 L_tmp = L_deposit_l( 1 ); + FOR( n_lag = 0; n_lag < n_lag_now; n_lag++ ) + { #ifdef BASOP_NOGLOB - L_tmp = L_add_sat(L_tmp, L_abs(SWB_signal[add(sub(n_freq, lookback), n_lag)])); + L_tmp = L_add_sat( L_tmp, L_abs( SWB_signal[add( sub( n_freq, lookback ), n_lag )] ) ); #else - L_tmp = L_add(L_tmp, L_abs(SWB_signal[add(sub(n_freq, lookback), n_lag)])); + L_tmp = L_add( L_tmp, L_abs( SWB_signal[add( sub( n_freq, lookback ), n_lag )] ) ); #endif - } + } - envelope[env_index] = L_tmp; - move32(); - env_index = add(env_index, 1); - } + envelope[env_index] = L_tmp; + move32(); + env_index = add( env_index, 1 ); + } - return; + return; } /*-------------------------------------------------------------------* * calc_normal_length() @@ -479,127 +480,126 @@ void calc_norm_envelop_lf_fx( *-------------------------------------------------------------------*/ void calc_normal_length_fx( - const Word16 core, /* i : core */ - const Word16 *sp, /* i : input signal */ - const Word16 mode, /* i : input mode */ - const Word16 extl, /* i : extension layer */ - Word16 *L_swb_norm, /* o : normalize length */ - Word16 *prev_L_swb_norm, /*i/o : last normalize length */ - Word16 Q_syn -) + const Word16 core, /* i : core */ + const Word16 *sp, /* i : input signal */ + const Word16 mode, /* i : input mode */ + const Word16 extl, /* i : extension layer */ + Word16 *L_swb_norm, /* o : normalize length */ + Word16 *prev_L_swb_norm, /*i/o : last normalize length */ + Word16 Q_syn ) { - Word16 i, n_freq, n_band, THRES; - const Word16 *pit; - Word16 peak, mag; - Word16 L_swb_norm_trans, L_swb_norm_norm, L_swb_norm_harm, L_swb_norm_cur; - Word16 N; - Word32 L_mean, L_tmp, L_tmp1; - - THRES = 4; - move16(); - test(); - test(); - if (EQ_16(core, HQ_CORE) || EQ_16(extl, SWB_BWE) || EQ_16(extl, FB_BWE)) - { - THRES = 8; - move16(); - } - - N = 16; - move16(); - test(); - test(); - if (EQ_16(core, HQ_CORE) && (EQ_16(mode, HQ_HARMONIC) || EQ_16(mode, HQ_HVQ))) - { - N = 13; - move16(); - } - - n_band = 0; - move16(); - pit = sp; - move16();/*Q_syn */ - FOR(i = 0; i < N; i++) - { - peak = 0; - move16(); - L_mean = L_deposit_l(0); - - FOR(n_freq = 0; n_freq < 16; n_freq++) - { - mag = abs_s(*pit); - - peak = s_max(peak, mag); - L_mean = L_add(L_mean, mag);/*Q_syn */ - pit++; - } - - L_tmp = L_mult0(peak, 15 + THRES);/*Q_syn */ - IF(EQ_16(THRES, 8)) - { - L_tmp1 = L_shl(Mult_32_16(L_mean, 32767), 3); - } - ELSE - { - L_tmp1 = L_shl(Mult_32_16(L_mean,32767), 2); - } - - test(); - if (GT_32(L_tmp, L_tmp1) && (GT_16(peak, shl(10, Q_syn)))) - { - n_band = add(1, n_band); - } - } - - IF(EQ_16(core, ACELP_CORE)) - { - L_swb_norm_trans = add(4, mult(n_band, 8192)); - L_swb_norm_norm = add(8, mult(n_band, 16384)); - - L_tmp = L_add(65536, L_mult0(n_band, 4096)); /*Q16 */ - L_swb_norm_harm = s_max(round_fx(L_shl(L_tmp, 5)), 24); /* Q0 */ - - IF(EQ_16(mode, HARMONIC)) - { - L_swb_norm_cur = L_swb_norm_harm; - move16(); - } - ELSE IF(EQ_16(mode, NORMAL)) - { - L_swb_norm_cur = L_swb_norm_norm; - move16(); - } - ELSE - { - L_swb_norm_cur = L_swb_norm_trans; - move16(); - } - *L_swb_norm = shr(add(L_swb_norm_cur, *prev_L_swb_norm), 1); - move16(); - *prev_L_swb_norm = L_swb_norm_cur; - move16(); - } - ELSE - { - test(); - IF(EQ_16(mode,HQ_HARMONIC) || EQ_16(mode,HQ_HVQ)) - { - L_tmp = L_add(65536, L_mult(n_band, 2560)); - L_swb_norm_cur = round_fx(L_shl(L_tmp, 5));/*Q0 */ - } - ELSE - { - L_tmp = L_add(65536, L_mult(n_band, 2048)); /*Q16 */ - L_swb_norm_cur = round_fx(L_shl(L_tmp, 3));/*Q0 */ - } - - /**L_swb_norm = add(mult_r(L_swb_norm_cur, 3277), mult_r(*prev_L_swb_norm, 29491)); */ - *L_swb_norm = round_fx(L_mac(L_mult(L_swb_norm_cur, 3277), *prev_L_swb_norm, 29491)); - *prev_L_swb_norm = L_swb_norm_cur; - move16(); - } - - return; + Word16 i, n_freq, n_band, THRES; + const Word16 *pit; + Word16 peak, mag; + Word16 L_swb_norm_trans, L_swb_norm_norm, L_swb_norm_harm, L_swb_norm_cur; + Word16 N; + Word32 L_mean, L_tmp, L_tmp1; + + THRES = 4; + move16(); + test(); + test(); + if ( EQ_16( core, HQ_CORE ) || EQ_16( extl, SWB_BWE ) || EQ_16( extl, FB_BWE ) ) + { + THRES = 8; + move16(); + } + + N = 16; + move16(); + test(); + test(); + if ( EQ_16( core, HQ_CORE ) && ( EQ_16( mode, HQ_HARMONIC ) || EQ_16( mode, HQ_HVQ ) ) ) + { + N = 13; + move16(); + } + + n_band = 0; + move16(); + pit = sp; + move16(); /*Q_syn */ + FOR( i = 0; i < N; i++ ) + { + peak = 0; + move16(); + L_mean = L_deposit_l( 0 ); + + FOR( n_freq = 0; n_freq < 16; n_freq++ ) + { + mag = abs_s( *pit ); + + peak = s_max( peak, mag ); + L_mean = L_add( L_mean, mag ); /*Q_syn */ + pit++; + } + + L_tmp = L_mult0( peak, 15 + THRES ); /*Q_syn */ + IF( EQ_16( THRES, 8 ) ) + { + L_tmp1 = L_shl( Mult_32_16( L_mean, 32767 ), 3 ); + } + ELSE + { + L_tmp1 = L_shl( Mult_32_16( L_mean, 32767 ), 2 ); + } + + test(); + if ( GT_32( L_tmp, L_tmp1 ) && ( GT_16( peak, shl( 10, Q_syn ) ) ) ) + { + n_band = add( 1, n_band ); + } + } + + IF( EQ_16( core, ACELP_CORE ) ) + { + L_swb_norm_trans = add( 4, mult( n_band, 8192 ) ); + L_swb_norm_norm = add( 8, mult( n_band, 16384 ) ); + + L_tmp = L_add( 65536, L_mult0( n_band, 4096 ) ); /*Q16 */ + L_swb_norm_harm = s_max( round_fx( L_shl( L_tmp, 5 ) ), 24 ); /* Q0 */ + + IF( EQ_16( mode, HARMONIC ) ) + { + L_swb_norm_cur = L_swb_norm_harm; + move16(); + } + ELSE IF( EQ_16( mode, NORMAL ) ) + { + L_swb_norm_cur = L_swb_norm_norm; + move16(); + } + ELSE + { + L_swb_norm_cur = L_swb_norm_trans; + move16(); + } + *L_swb_norm = shr( add( L_swb_norm_cur, *prev_L_swb_norm ), 1 ); + move16(); + *prev_L_swb_norm = L_swb_norm_cur; + move16(); + } + ELSE + { + test(); + IF( EQ_16( mode, HQ_HARMONIC ) || EQ_16( mode, HQ_HVQ ) ) + { + L_tmp = L_add( 65536, L_mult( n_band, 2560 ) ); + L_swb_norm_cur = round_fx( L_shl( L_tmp, 5 ) ); /*Q0 */ + } + ELSE + { + L_tmp = L_add( 65536, L_mult( n_band, 2048 ) ); /*Q16 */ + L_swb_norm_cur = round_fx( L_shl( L_tmp, 3 ) ); /*Q0 */ + } + + /**L_swb_norm = add(mult_r(L_swb_norm_cur, 3277), mult_r(*prev_L_swb_norm, 29491)); */ + *L_swb_norm = round_fx( L_mac( L_mult( L_swb_norm_cur, 3277 ), *prev_L_swb_norm, 29491 ) ); + *prev_L_swb_norm = L_swb_norm_cur; + move16(); + } + + return; } /*-------------------------------------------------------------------* * calc_tilt_bwe() @@ -607,135 +607,135 @@ void calc_normal_length_fx( * calculate tilt parameter *-------------------------------------------------------------------*/ -Word32 calc_tilt_bwe_fx( /* o : Tilt in Q24 */ - const Word16 *sp, /* i : input signal */ - const Word16 exp_sp, /* i : Exp of inp signal */ - const Word16 N /* i : signal length */ +Word32 calc_tilt_bwe_fx( /* o : Tilt in Q24 */ + const Word16 *sp, /* i : input signal */ + const Word16 exp_sp, /* i : Exp of inp signal */ + const Word16 N /* i : signal length */ ) { - Word16 i, j; - Word32 L_ener, L_ener_tot, L_temp; - Word16 tmp1, tmp2; - const Word16 *ptr; - Word16 exp2; + Word16 i, j; + Word32 L_ener, L_ener_tot, L_temp; + Word16 tmp1, tmp2; + const Word16 *ptr; + Word16 exp2; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; + Flag Overflow = 0; #endif - BASOP_SATURATE_WARNING_OFF_EVS + BASOP_SATURATE_WARNING_OFF_EVS - /* this is required for adaptative precision energy summation loop, do not remove */ - Overflow = 0; - move16(); - exp2 = 0; - move16(); + /* this is required for adaptative precision energy summation loop, do not remove */ + Overflow = 0; + move16(); + exp2 = 0; + move16(); - ptr = sp; - move16(); - L_ener_tot = L_deposit_l(1); + ptr = sp; + move16(); + L_ener_tot = L_deposit_l( 1 ); - /* Divide Frame Length by 32 */ - FOR(j = shr(N, 5); j > 0; j--) - { -#ifdef BASOP_NOGLOB /* Critical Overflow and all those below*/ - tmp1 = mult_ro(*ptr++, 8192, &Overflow); /* Divide by 4 */ + /* Divide Frame Length by 32 */ + FOR( j = shr( N, 5 ); j > 0; j-- ) + { +#ifdef BASOP_NOGLOB /* Critical Overflow and all those below*/ + tmp1 = mult_ro( *ptr++, 8192, &Overflow ); /* Divide by 4 */ #else - tmp1 = mult_r(*ptr++, 8192); /* Divide by 4 */ + tmp1 = mult_r( *ptr++, 8192 ); /* Divide by 4 */ #endif - L_ener = L_mult0(tmp1, tmp1); - /* With the shift by 4 and the L_mult0, no overflow possible for 32 samples */ - FOR(i = 1; i < 32; i++) - { -#ifdef BASOP_NOGLOB /* Critical Overflow */ - tmp1 = mult_ro(*ptr++, 8192, &Overflow); /* Divide by 4 */ - L_ener = L_mac0_o(L_ener, tmp1, tmp1, &Overflow); + L_ener = L_mult0( tmp1, tmp1 ); + /* With the shift by 4 and the L_mult0, no overflow possible for 32 samples */ + FOR( i = 1; i < 32; i++ ) + { +#ifdef BASOP_NOGLOB /* Critical Overflow */ + tmp1 = mult_ro( *ptr++, 8192, &Overflow ); /* Divide by 4 */ + L_ener = L_mac0_o( L_ener, tmp1, tmp1, &Overflow ); #else - tmp1 = mult_r(*ptr++, 8192); /* Divide by 4 */ - L_ener = L_mac0(L_ener, tmp1, tmp1); + tmp1 = mult_r( *ptr++, 8192 ); /* Divide by 4 */ + L_ener = L_mac0( L_ener, tmp1, tmp1 ); #endif - } -#ifdef BASOP_NOGLOB /* Critical Overflow */ - L_ener = L_shr_o(L_ener, exp2, &Overflow); - L_temp = L_add_o(L_ener_tot, L_ener, &Overflow); + } +#ifdef BASOP_NOGLOB /* Critical Overflow */ + L_ener = L_shr_o( L_ener, exp2, &Overflow ); + L_temp = L_add_o( L_ener_tot, L_ener, &Overflow ); #else - L_ener = L_shr(L_ener, exp2); - L_temp = L_add(L_ener_tot, L_ener); + L_ener = L_shr( L_ener, exp2 ); + L_temp = L_add( L_ener_tot, L_ener ); #endif - IF(Overflow != 0) - { - L_ener_tot = L_shr(L_ener_tot, 1); - L_ener = L_shr(L_ener, 1); - exp2 = add(exp2, 1); - /* this is required, do not remove */ - Overflow = 0; - move16(); - } -#ifdef BASOP_NOGLOB /* Critical Overflow */ - L_ener_tot = L_add_o(L_ener_tot, L_ener, &Overflow); + IF( Overflow != 0 ) + { + L_ener_tot = L_shr( L_ener_tot, 1 ); + L_ener = L_shr( L_ener, 1 ); + exp2 = add( exp2, 1 ); + /* this is required, do not remove */ + Overflow = 0; + move16(); + } +#ifdef BASOP_NOGLOB /* Critical Overflow */ + L_ener_tot = L_add_o( L_ener_tot, L_ener, &Overflow ); #else - L_ener_tot = L_add(L_ener_tot, L_ener); + L_ener_tot = L_add( L_ener_tot, L_ener ); #endif - } + } #ifdef BASOP_NOGLOB - L_ener = L_deposit_l(abs_s(sub_o(sp[1], sp[0], &Overflow))); + L_ener = L_deposit_l( abs_s( sub_o( sp[1], sp[0], &Overflow ) ) ); #else - L_ener = L_deposit_l(abs_s(sub(sp[1], sp[0]))); + L_ener = L_deposit_l( abs_s( sub( sp[1], sp[0] ) ) ); #endif - FOR(i = 2; i < N; i++) - { - /* Eq to (sp[i] - sp[i-1]) * (sp[i-1] - sp[i-2]) < 0 */ + FOR( i = 2; i < N; i++ ) + { + /* Eq to (sp[i] - sp[i-1]) * (sp[i-1] - sp[i-2]) < 0 */ #ifdef BASOP_NOGLOB - tmp1 = sub_o(sp[i], sp[i - 1], &Overflow); - tmp2 = sub_o(sp[i - 1], sp[i - 2], &Overflow); + tmp1 = sub_o( sp[i], sp[i - 1], &Overflow ); + tmp2 = sub_o( sp[i - 1], sp[i - 2], &Overflow ); #else - tmp1 = sub(sp[i], sp[i - 1]); - tmp2 = sub(sp[i - 1], sp[i - 2]); + tmp1 = sub( sp[i], sp[i - 1] ); + tmp2 = sub( sp[i - 1], sp[i - 2] ); #endif - tmp2 = mult(tmp1, tmp2); - tmp1 = abs_s(tmp1); - /* to Get either 0 or -1 in 'tmp2' */ - tmp2 = shr(tmp2, 15); - /* this allows this code */ - L_ener = L_msu0(L_ener, tmp2, tmp1); - /* instead of this one */ - /* test(); */ - /* if (tmp2 < 0) */ - /* { */ - /* L_ener = L_mac0(L_ener, 1, tmp1); */ - /* } */ - /* it saves one op */ - } - - tmp1 = norm_l(L_ener_tot); - L_temp = L_shl(L_ener_tot, tmp1); - tmp1 = sub(add(31 + 4, exp2), add(tmp1, shl(exp_sp, 1))); - L_temp = Isqrt_lc(L_temp, &tmp1); - - /* *tilt_flt = (float)(r1/sqrt(r0)); */ - exp2 = norm_l(L_ener); + tmp2 = mult( tmp1, tmp2 ); + tmp1 = abs_s( tmp1 ); + /* to Get either 0 or -1 in 'tmp2' */ + tmp2 = shr( tmp2, 15 ); + /* this allows this code */ + L_ener = L_msu0( L_ener, tmp2, tmp1 ); + /* instead of this one */ + /* test(); */ + /* if (tmp2 < 0) */ + /* { */ + /* L_ener = L_mac0(L_ener, 1, tmp1); */ + /* } */ + /* it saves one op */ + } + + tmp1 = norm_l( L_ener_tot ); + L_temp = L_shl( L_ener_tot, tmp1 ); + tmp1 = sub( add( 31 + 4, exp2 ), add( tmp1, shl( exp_sp, 1 ) ) ); + L_temp = Isqrt_lc( L_temp, &tmp1 ); + + /* *tilt_flt = (float)(r1/sqrt(r0)); */ + exp2 = norm_l( L_ener ); #ifdef BASOP_NOGLOB L_temp = Mult_32_16( L_temp, round_fx_sat( L_shl_sat( L_ener, exp2 ) ) ); #else - L_temp = Mult_32_16(L_temp, round_fx(L_shl(L_ener, exp2))); + L_temp = Mult_32_16( L_temp, round_fx( L_shl( L_ener, exp2 ) ) ); #endif - exp2 = sub(exp2, tmp1); - exp2 = add(exp2, exp_sp); + exp2 = sub( exp2, tmp1 ); + exp2 = add( exp2, exp_sp ); - /* Put in Q24 */ + /* Put in Q24 */ #ifdef BASOP_NOGLOB - L_temp = L_shr_sat( L_temp, sub( exp2, 24 ) ); + L_temp = L_shr_sat( L_temp, sub( exp2, 24 ) ); #else - L_temp = L_shr(L_temp, sub(exp2, 24)); + L_temp = L_shr( L_temp, sub( exp2, 24 ) ); #endif - BASOP_SATURATE_WARNING_ON_EVS + BASOP_SATURATE_WARNING_ON_EVS - return L_temp; + return L_temp; } #ifdef IVAS_FLOAT_FIXED -Word16 ivas_calc_tilt_bwe_fx( /* o : Tilt in Q24 */ - const Word32 *sp, /* i : input signal */ - const Word16 exp_sp, /* i : Exp of inp signal */ - const Word16 N /* i : signal length */ +Word16 ivas_calc_tilt_bwe_fx( /* o : Tilt in Q24 */ + const Word32 *sp, /* i : input signal */ + const Word16 exp_sp, /* i : Exp of inp signal */ + const Word16 N /* i : signal length */ ) { Word16 i, j; @@ -754,38 +754,38 @@ Word16 ivas_calc_tilt_bwe_fx( /* o : Tilt in Q24 */ ptr = sp; move16(); - L_ener_tot = L_deposit_l(1); + L_ener_tot = L_deposit_l( 1 ); /* Divide Frame Length by 32 */ - FOR(j = shr(N, 5); j > 0; j--) + FOR( j = shr( N, 5 ); j > 0; j-- ) { Word32 tmp = *ptr++; /* Divide by 4 */ L_ener = Mpy_32_32( tmp, tmp ); /* With the shift by 4 and the L_mult0, no overflow possible for 32 samples */ - FOR(i = 1; i < 32; i++) + FOR( i = 1; i < 32; i++ ) { tmp1 = *ptr++; /* Divide by 4 */ - L_ener = Madd_32_32(L_ener, tmp1, tmp1); + L_ener = Madd_32_32( L_ener, tmp1, tmp1 ); } - L_temp = L_add(L_ener_tot, L_ener); + L_temp = L_add( L_ener_tot, L_ener ); - L_ener_tot = L_add(L_ener_tot, L_ener); + L_ener_tot = L_add( L_ener_tot, L_ener ); } - L_ener = L_abs(L_sub(sp[1], sp[0])); + L_ener = L_abs( L_sub( sp[1], sp[0] ) ); - FOR(i = 2; i < N; i++) + FOR( i = 2; i < N; i++ ) { /* Eq to (sp[i] - sp[i-1]) * (sp[i-1] - sp[i-2]) < 0 */ - tmp1 = L_sub(sp[i], sp[i - 1]); - tmp2 = L_sub(sp[i - 1], sp[i - 2]); + tmp1 = L_sub( sp[i], sp[i - 1] ); + tmp2 = L_sub( sp[i - 1], sp[i - 2] ); - tmp2 = Mpy_32_32(tmp1, tmp2); - tmp1 = L_abs(tmp1); + tmp2 = Mpy_32_32( tmp1, tmp2 ); + tmp1 = L_abs( tmp1 ); /* to Get either 0 or -1 in 'tmp2' */ - tmp2 = L_shr(tmp2, 31); - sign = extract_l(L_shl(tmp2, Q15)); + tmp2 = L_shr( tmp2, 31 ); + sign = extract_l( L_shl( tmp2, Q15 ) ); /* this allows this code */ - L_ener = Msub_32_16(L_ener, tmp1, sign); + L_ener = Msub_32_16( L_ener, tmp1, sign ); /* instead of this one */ /* test(); */ /* if (tmp2 < 0) */ @@ -796,23 +796,23 @@ Word16 ivas_calc_tilt_bwe_fx( /* o : Tilt in Q24 */ } L_temp = L_ener_tot; - tmp_exp = sub(Q31, sub(shl(exp_sp, 1), Q31)); - L_temp = Sqrt32(L_temp, &tmp_exp); - L_temp = L_shl(L_temp, sub(exp_sp, sub(Q31, tmp_exp))); + tmp_exp = sub( Q31, sub( shl( exp_sp, 1 ), Q31 ) ); + L_temp = Sqrt32( L_temp, &tmp_exp ); + L_temp = L_shl( L_temp, sub( exp_sp, sub( Q31, tmp_exp ) ) ); /* *tilt_flt = (float)(r1/sqrt(r0)); */ - L_temp = L_deposit_l(BASOP_Util_Divide3232_Scale(L_ener, L_temp, &exp2)); - IF (GT_16(sub(exp2, 4) , norm_l(L_temp))) + L_temp = L_deposit_l( BASOP_Util_Divide3232_Scale( L_ener, L_temp, &exp2 ) ); + IF( GT_16( sub( exp2, 4 ), norm_l( L_temp ) ) ) { L_temp = MAX_16; } ELSE { - L_temp = L_shl(L_temp, sub(exp2, 4)); // Output is expected in Q11 + L_temp = L_shl( L_temp, sub( exp2, 4 ) ); // Output is expected in Q11 } BASOP_SATURATE_WARNING_ON_EVS - return extract_l(L_temp); + return extract_l( L_temp ); } #endif @@ -823,55 +823,55 @@ Word16 ivas_calc_tilt_bwe_fx( /* o : Tilt in Q24 */ *-------------------------------------------------------------------*/ void calc_norm_envelop_fx( - const Word16 SWB_signal[], /* i : SWB spectrum Q_syn*/ - Word32 *envelope, /* o : normalized envelope Q_syn*/ - const Word16 L_swb_norm, /* i : length of envelope Q0 */ - const Word16 SWB_flength, /* i : Length of input/output */ - const Word16 st_offset /* i : offset */ + const Word16 SWB_signal[], /* i : SWB spectrum Q_syn*/ + Word32 *envelope, /* o : normalized envelope Q_syn*/ + const Word16 L_swb_norm, /* i : length of envelope Q0 */ + const Word16 SWB_flength, /* i : Length of input/output */ + const Word16 st_offset /* i : offset */ ) { - Word16 i, lookback, env_index, n_freq, n_lag_now, n_lag, tmp; - - lookback = shr(L_swb_norm, 1); - move16(); - env_index = add(swb_bwe_subband[0], st_offset); - n_lag_now = L_swb_norm; - move16(); - tmp = sub(add(SWB_flength, st_offset), L_swb_norm); - FOR(n_freq = sub(add(swb_bwe_trans_subband[0], st_offset), lookback); n_freq < tmp; n_freq++) - { - /* Apply MA filter */ - Word32 L_tmp = L_deposit_l(0); - FOR(n_lag = 0; n_lag < n_lag_now; n_lag++) - { - L_tmp = L_add(L_tmp, abs_s(SWB_signal[n_freq + n_lag])); - } - envelope[env_index] = L_tmp; - move32(); - env_index++; - } - - i = 0; - move16(); - tmp = sub(add(SWB_flength, st_offset), lookback); - FOR(n_freq = sub(add(SWB_flength, st_offset), L_swb_norm); n_freq < tmp; n_freq++) - { - Word32 L_tmp; - - n_lag_now = sub(L_swb_norm, i); - /* Apply MA filter */ - L_tmp = L_deposit_l(0); - FOR(n_lag = 0; n_lag < n_lag_now; n_lag++) - { - L_tmp = L_add(L_tmp, abs_s(SWB_signal[n_freq + n_lag])); - } - envelope[env_index] = L_tmp; - move32(); - env_index++; - i++; - } - - return; + Word16 i, lookback, env_index, n_freq, n_lag_now, n_lag, tmp; + + lookback = shr( L_swb_norm, 1 ); + move16(); + env_index = add( swb_bwe_subband[0], st_offset ); + n_lag_now = L_swb_norm; + move16(); + tmp = sub( add( SWB_flength, st_offset ), L_swb_norm ); + FOR( n_freq = sub( add( swb_bwe_trans_subband[0], st_offset ), lookback ); n_freq < tmp; n_freq++ ) + { + /* Apply MA filter */ + Word32 L_tmp = L_deposit_l( 0 ); + FOR( n_lag = 0; n_lag < n_lag_now; n_lag++ ) + { + L_tmp = L_add( L_tmp, abs_s( SWB_signal[n_freq + n_lag] ) ); + } + envelope[env_index] = L_tmp; + move32(); + env_index++; + } + + i = 0; + move16(); + tmp = sub( add( SWB_flength, st_offset ), lookback ); + FOR( n_freq = sub( add( SWB_flength, st_offset ), L_swb_norm ); n_freq < tmp; n_freq++ ) + { + Word32 L_tmp; + + n_lag_now = sub( L_swb_norm, i ); + /* Apply MA filter */ + L_tmp = L_deposit_l( 0 ); + FOR( n_lag = 0; n_lag < n_lag_now; n_lag++ ) + { + L_tmp = L_add( L_tmp, abs_s( SWB_signal[n_freq + n_lag] ) ); + } + envelope[env_index] = L_tmp; + move32(); + env_index++; + i++; + } + + return; } /*==========================================================================*/ @@ -908,1179 +908,1183 @@ void calc_norm_envelop_fx( /* CALLED FROM : */ /*==========================================================================*/ void WB_BWE_decoding_fx( - const Word16 *core_dec_freq,/* i : Frequency domain core decoded signal */ - Word16 *WB_fenv, /* i : WB frequency envelopes */ - Word32 *WB_signal_32, /* o : WB signal in MDCT domain */ - const Word16 WB_flength, /* i : Length of input/output */ - const Word16 mode, /* i : classification for WB signal */ - const Word16 last_extl, /* i : extl. layer for last frame */ - Word32 *prev_Energy, /* i/o: energy for last frame */ - Word16 *prev_WB_fenv, /* i/o: envelope for last frame */ - Word16 *prev_L_wb_norm, /* i/o: length for last frame wb norm */ - const Word16 extl, /* i : extension layer */ - const Word16 coder_type, /* i : coding type */ - const Word32 total_brate, /* i : core layer bitrate */ - Word16 *Seed, /* i/o: random generator seed */ - Word16 *prev_flag, /* i/o: attenu flag of last frame */ - Word16 prev_coder_type, /* i : coding type of last frame */ - Word16 Q_syn, - Word16 *Q_syn_hb /*o : Q value of WB_signal_32 */ + const Word16 *core_dec_freq, /* i : Frequency domain core decoded signal */ + Word16 *WB_fenv, /* i : WB frequency envelopes */ + Word32 *WB_signal_32, /* o : WB signal in MDCT domain */ + const Word16 WB_flength, /* i : Length of input/output */ + const Word16 mode, /* i : classification for WB signal */ + const Word16 last_extl, /* i : extl. layer for last frame */ + Word32 *prev_Energy, /* i/o: energy for last frame */ + Word16 *prev_WB_fenv, /* i/o: envelope for last frame */ + Word16 *prev_L_wb_norm, /* i/o: length for last frame wb norm */ + const Word16 extl, /* i : extension layer */ + const Word16 coder_type, /* i : coding type */ + const Word32 total_brate, /* i : core layer bitrate */ + Word16 *Seed, /* i/o: random generator seed */ + Word16 *prev_flag, /* i/o: attenu flag of last frame */ + Word16 prev_coder_type, /* i : coding type of last frame */ + Word16 Q_syn, + Word16 *Q_syn_hb /*o : Q value of WB_signal_32 */ ) { - Word16 n_freq, n_band; - Word16 i, L; - Word32 envelope[L_FRAME16k]; - Word32 energy, EnergyL; - Word32 *pit1; - Word16 WB_signal[L_FRAME16k]; - Word16 L_wb_norm, wfenv[2]; - Word16 alfa, beta; - Word16 flag = 0; - Word16 core_type = 1; - Word16 tmp, tmp1, exp, tmp2; - Word32 L_tmp, L_tmp1, L_tmp2; - Word32 prev_ener_alpha, prev_ener_beta; - Word16 signum[L_FRAME16k]; - Word16 inv_L_wb_norm, weight; - - calc_normal_length_fx(ACELP_CORE, core_dec_freq, mode, extl, &L_wb_norm, prev_L_wb_norm, Q_syn); - set32_fx(WB_signal_32, 0, L_FRAME16k); - set16_fx(WB_signal, 0, L_FRAME16k); - - /* copy excitation */ - test(); - if (NE_16(coder_type, AUDIO) && LE_32(total_brate, ACELP_8k00)) - { - core_type = 0; - move16(); - } - - IF(core_type == 0) - { - Copy(&core_dec_freq[160], &WB_signal[240], 80); - } - ELSE - { - Copy(&core_dec_freq[80], &WB_signal[240], 80); - } - - /* calculate envelope */ - calc_norm_envelop_fx(WB_signal, envelope, L_wb_norm, WB_flength, 0); - test(); - IF(coder_type != UNVOICED && total_brate <= ACELP_8k00) - { - exp = norm_s(L_wb_norm); - inv_L_wb_norm = shl(div_s(shl(1, sub(14, exp)), L_wb_norm), sub(exp, 14)); /* Q(15) */ - IF(NE_16(mode, HARMONIC)) - { - tmp = add(shl(inv_L_wb_norm, 1), inv_L_wb_norm); - weight = s_max(s_min(tmp, 16384), 8192); - } - ELSE - { - weight = 8192; - move16(); - } - FOR(n_freq = swb_bwe_subband[0]; n_freq < swb_bwe_subband[4]; n_freq++) - { - signum[n_freq] = 1; - IF(WB_signal[n_freq] < 0) - { - signum[n_freq] = -1; - move16(); - WB_signal[n_freq] = negate(WB_signal[n_freq]); - move16(); - } - L_tmp = Mult_32_16(envelope[n_freq], inv_L_wb_norm); /* Q_syn */ - L_tmp = Mult_32_16(L_tmp, 14746); /* Q_syn */ - L_tmp1 = L_deposit_l(WB_signal[n_freq]); /* Q_syn */ - L_tmp = L_sub(L_tmp1, L_tmp); /* Q_syn */ - WB_signal[n_freq] = extract_l(L_tmp); /* Q_syn */ - IF(L_tmp > 0) - { - tmp = sub(18022, weight); /* Q15 */ - WB_signal[n_freq] = extract_l(Mult_32_16(L_tmp, tmp)); /* Q_syn */ - } - - IF(NE_16(signum[n_freq], 1)) - { - WB_signal[n_freq] = negate(WB_signal[n_freq]); - move16(); - } - } - } - - /* Normalize with envelope */ - FOR(n_freq = swb_bwe_subband[0]; n_freq < swb_bwe_subband[4]; n_freq++) - { - IF(envelope[n_freq] != 0) - { - exp = norm_l(envelope[n_freq]); - tmp = extract_h(L_shl(envelope[n_freq], exp)); - exp = sub(sub(30, exp), Q_syn); - tmp = div_s(16384, tmp); - L_tmp = L_shr(L_mult0(WB_signal[n_freq], tmp), add(exp, Q_syn)); /*Q15 */ - WB_signal[n_freq] = extract_l(L_tmp); /*Q15 */ - } - ELSE - { - WB_signal[n_freq] = shl(WB_signal[n_freq],sub(15,Q_syn)); /*Q15 */ move16(); - } - } - - L = 1; - move16(); - if (EQ_16(mode, HARMONIC)) - { - L = 4; - move16(); - } - - IF(EQ_16(coder_type, UNVOICED)) - { - FOR(n_freq = swb_bwe_subband[0]; n_freq < swb_bwe_subband[4]; n_freq++) - { - *Seed = extract_l(L_mac0(20101L, *Seed, 12345)); - L_tmp = L_shl(*Seed, add(Q_syn, 1)); - WB_signal_32[n_freq] = L_tmp; - move32(); - } - } - ELSE - { - FOR(n_band = 0; n_band < 4; n_band += L) - { - energy = L_deposit_l(0); - FOR(n_freq = swb_bwe_subband[n_band]; n_freq < swb_bwe_subband[n_band + L]; n_freq++) - { - L_tmp = L_mult0(WB_signal[n_freq],WB_signal[n_freq]); /*Q30 */ - energy = L_add(energy,L_shr(L_tmp,5)); /*Q25 */ - } - - tmp = sub(swb_bwe_subband[n_band + L] , swb_bwe_subband[n_band]); - tmp = div_s(1,tmp);/*Q15 */ - energy = Mult_32_16(energy,tmp); /*Q(15+25-15)->Q(25) */ - - exp = norm_l(energy); - L_tmp1 = L_shl(energy, exp); - exp = 31 - exp - (25); - move16(); - L_tmp1 = Isqrt_lc(L_tmp1, &exp); /*Q(31-exp) */ - - FOR(n_freq = swb_bwe_subband[n_band]; n_freq < swb_bwe_subband[n_band + L]; n_freq++) - { - L_tmp2 = Mult_32_16(L_tmp1, WB_signal[n_freq]); - WB_signal_32[n_freq] = L_shl(L_tmp2, sub(add(exp, Q_syn), 15)); - move32(); - } - } - } - - EnergyL = L_deposit_l(0); - IF(core_type == 1) - { - test(); - IF(NE_16(prev_coder_type, AUDIO) && LE_32(total_brate, ACELP_8k00)) - { - FOR(i = 160; i < 240; i++) - { - EnergyL = L_add(abs_s(core_dec_freq[i]), EnergyL); - } - } - ELSE - { - FOR(i = 80; i < 240; i++) - { - EnergyL = L_add(abs_s(core_dec_freq[i]),EnergyL); - } - } - - IF(LE_32(total_brate, ACELP_8k00)) - { - alfa = 26214; - move16(); /*0.8f in Q15; */ - beta = 10240; - move16();/*1.25f in Q13; */ - } - ELSE - { - alfa = 16384; - move16();/* 0.5f in Q15; */ - beta = 16384; - move16();/*2.0f in Q13 */ - } - } - ELSE - { - IF(EQ_16(prev_coder_type,AUDIO)) - { - FOR(i = 80; i < 240; i++) - { - EnergyL = L_add(abs_s(core_dec_freq[i]), EnergyL);/*Q_syn */ - } - } - ELSE - { - FOR(i = 160; i < 240; i++) - { - EnergyL = L_add(abs_s(core_dec_freq[i]), EnergyL); - } - } - - test(); - IF(EQ_16(prev_coder_type,coder_type) && GT_16(WB_fenv[0],prev_WB_fenv[0])) - { - alfa = 13107; - move16();/*.4 in Q15 */ - beta = 20480; - move16(); /*2.5 in Q13 */ - } - ELSE - { - alfa = 19661; - move16();/*.6 in Q15 */ - beta = 13681; - move16();/*1.67 in Q13 */ - } - - test(); - test(); - test(); - IF(EQ_16(coder_type,GENERIC) || (GT_32(EnergyL,L_shr(*prev_Energy,1)) && GT_32(*prev_Energy,L_shr(EnergyL,1)) && EQ_16(*prev_flag,1))) - { - WB_fenv[0] = shr(WB_fenv[0], 1); - move16(); - WB_fenv[1] = shr(WB_fenv[1], 1); - move16(); - flag = 1; - move16(); - } - } - L_tmp1 = Mult_32_16(EnergyL, prev_WB_fenv[0]);/*Qsyn+3-15 */ - L_tmp2 = Mult_32_16(*prev_Energy, WB_fenv[0]);/*Q_syn+3-15 */ - prev_ener_alpha = Mult_32_16(*prev_Energy, alfa);/*Q_syn+15-15->Q_syn */ - prev_ener_beta = L_shl(Mult_32_16(*prev_Energy, beta), 2); /*Q_syn+13-15+2 ->Q_syn */ - - test(); - test(); - IF((EQ_16(mode, HARMONIC) && GT_16(shr(WB_fenv[0], 2), WB_fenv[1])) || EQ_16(mode, NORMAL)) - { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF(EQ_16(last_extl, WB_BWE) && - ((EQ_16(prev_coder_type, AUDIO) && NE_16(coder_type, AUDIO)) || - (NE_16(prev_coder_type, AUDIO) && EQ_16(coder_type, AUDIO))) && LE_32(total_brate, ACELP_8k00)) - { - IF(GT_16(WB_fenv[0], prev_WB_fenv[0])) - { - /*wfenv[0]= add(mult_r(9830, WB_fenv[0]), mult_r(22938, prev_WB_fenv[0]));//Q3 */ - wfenv[0] = round_fx(L_mac(L_mult(9830, WB_fenv[0]), 22938, prev_WB_fenv[0]));/*Q3 */ - /*wfenv[1]= add(mult_r(9830, WB_fenv[1]), mult_r(22938, prev_WB_fenv[1]));//Q3 */ - wfenv[1] = round_fx(L_mac(L_mult(9830, WB_fenv[1]), 22938, prev_WB_fenv[1]));/*Q3 */ - } - ELSE - { - /*wfenv[0]= add(mult_r(16384,WB_fenv[0]),mult_r(16384,prev_WB_fenv[0]));//Q3 */ - wfenv[0] = round_fx(L_mac(L_mult(16384,WB_fenv[0]),16384,prev_WB_fenv[0]));/*Q3 */ - /*wfenv[1]= add(mult_r(13108,WB_fenv[1]),mult_r(13108,prev_WB_fenv[1]));//Q3 */ - wfenv[1] = round_fx(L_mac(L_mult(13108,WB_fenv[1]),13108,prev_WB_fenv[1]));/*Q3 */ - } - } - ELSE IF(EQ_16(last_extl, WB_BWE) && LT_32(L_tmp1, L_tmp2) && GT_16(WB_fenv[0], prev_WB_fenv[0]) && - NE_16(coder_type, AUDIO) && NE_16(coder_type, UNVOICED) && LE_32(total_brate, ACELP_8k00)) - { - /*wfenv[0]= add(mult_r(9830,WB_fenv[0]),mult_r(22938,prev_WB_fenv[0]));//Q3 */ - wfenv[0] = round_fx(L_mac(L_mult(9830, WB_fenv[0]), 22938, prev_WB_fenv[0]));/*Q3 */ - /*wfenv[1]= add(mult_r(9830,WB_fenv[1]),mult_r(22938,prev_WB_fenv[1]));//Q3 */ - wfenv[1] = round_fx(L_mac(L_mult(9830, WB_fenv[1]), 22938, prev_WB_fenv[1]));/*Q3 */ - } - ELSE IF(EQ_16(last_extl, WB_BWE) && GT_32(EnergyL, prev_ener_alpha) && GT_32(prev_ener_beta, EnergyL) && - NE_16(prev_coder_type, UNVOICED)) - { - /*wfenv[0] = add(shr(WB_fenv[0],1), shr(prev_WB_fenv[0],1));//Q3 */ - wfenv[0] = round_fx(L_mac(L_mult(WB_fenv[0], 16384), prev_WB_fenv[0], 16384));/*Q3 */ - /*wfenv[1] = add(shr(WB_fenv[1],1), shr(prev_WB_fenv[1],1));//Q3 */ - wfenv[1] = round_fx(L_mac(L_mult(WB_fenv[1], 16384), prev_WB_fenv[1], 16384));/*Q3 */ - } - ELSE - { - wfenv[0] = WB_fenv[0]; - move16(); - wfenv[1] = WB_fenv[1]; - move16(); - } - FOR(n_freq = swb_bwe_subband[0]; n_freq < swb_bwe_subband[2]; n_freq++) - { - WB_signal_32[n_freq] = Mult_32_16(WB_signal_32[n_freq], wfenv[0]); - move32();/* Q_syn+3+1 */ - } - - FOR(n_freq = swb_bwe_subband[2]; n_freq < swb_bwe_subband[4]; n_freq++) - { - WB_signal_32[n_freq] = Mult_32_16(WB_signal_32[n_freq], wfenv[1]); - move32();/* Q_syn+3+1 */ - } - - prev_WB_fenv[0] = wfenv[0]; - move16(); - prev_WB_fenv[1] = wfenv[1]; - move16(); - } - ELSE - { - wfenv[0] = add(shr(WB_fenv[0],1), shr(WB_fenv[1],1));/*Q3 */ - - test(); - test(); - IF(EQ_16(last_extl,WB_BWE) && GT_32(EnergyL,L_shr(*prev_Energy,1)) && GT_32(*prev_Energy,L_shr(EnergyL,1))) - { - L_tmp1 = L_mac(L_mult(8192,wfenv[0]),12288, prev_WB_fenv[0]); - wfenv[0] = round_fx(L_mac(L_tmp1, 12288, prev_WB_fenv[1])); - } - FOR(n_freq = swb_bwe_subband[0]; n_freq < swb_bwe_subband[4]; n_freq++) - { - WB_signal_32[n_freq] = Mult_32_16(WB_signal_32[n_freq], wfenv[0]); - move32();/* Q_syn+3+1 */ - } - prev_WB_fenv[0] = wfenv[0]; - move16(); - prev_WB_fenv[1] = wfenv[0]; - move16(); - } - - *prev_flag = flag; - move16(); - *prev_Energy = EnergyL; - move32(); - pit1 = &WB_signal_32[240]; - - FOR(n_freq = 0; n_freq < 16; n_freq++) - { - tmp1 = extract_l(L_mult0(n_freq, 1638));/*Q15 */ - tmp2 = add(6554, tmp1);/*Q15 */ - L_tmp1 = Mult_32_16(*pit1, tmp2); /*Q_syn+3+1 */ - *(pit1++) = L_tmp1; - move32(); - } - - IF(EQ_16(core_type, 1)) - { - pit1 = &WB_signal_32[280]; - FOR(n_freq = 0; n_freq < 40; n_freq++) - { - tmp1 = extract_l(L_mult0(n_freq, 655));/*Q15 */ - tmp2 = sub(32767, tmp1); - L_tmp1 = Mult_32_16(*pit1, tmp2); /*Q_syn+3+1 */ - *(pit1++) = L_tmp1; - move32(); - } - } - ELSE - { - pit1 = &WB_signal_32[300]; - FOR(n_freq = 0; n_freq < 20; n_freq++) - { - tmp1 = extract_l(L_mult0(n_freq, 1311));/*Q15 */ - tmp2 = sub(32767, tmp1); - L_tmp1 = Mult_32_16(*pit1, tmp2); /*Q_syn+3+1 */ - *(pit1++) = L_tmp1; - move32(); - } - } - pit1 = &WB_signal_32[240]; - tmp = Find_Max_Norm32(pit1, 80); - FOR(i = 0; i < 80; i++) - { - L_tmp = *pit1; - *(pit1++) = L_shl(L_tmp, sub(tmp, 1)); - move32(); - } - *Q_syn_hb = add(Q_syn, add(tmp, 3)); - return; -} + Word16 n_freq, n_band; + Word16 i, L; + Word32 envelope[L_FRAME16k]; + Word32 energy, EnergyL; + Word32 *pit1; + Word16 WB_signal[L_FRAME16k]; + Word16 L_wb_norm, wfenv[2]; + Word16 alfa, beta; + Word16 flag = 0; + Word16 core_type = 1; + Word16 tmp, tmp1, exp, tmp2; + Word32 L_tmp, L_tmp1, L_tmp2; + Word32 prev_ener_alpha, prev_ener_beta; + Word16 signum[L_FRAME16k]; + Word16 inv_L_wb_norm, weight; + + calc_normal_length_fx( ACELP_CORE, core_dec_freq, mode, extl, &L_wb_norm, prev_L_wb_norm, Q_syn ); + set32_fx( WB_signal_32, 0, L_FRAME16k ); + set16_fx( WB_signal, 0, L_FRAME16k ); + + /* copy excitation */ + test(); + if ( NE_16( coder_type, AUDIO ) && LE_32( total_brate, ACELP_8k00 ) ) + { + core_type = 0; + move16(); + } + IF( core_type == 0 ) + { + Copy( &core_dec_freq[160], &WB_signal[240], 80 ); + } + ELSE + { + Copy( &core_dec_freq[80], &WB_signal[240], 80 ); + } -/*==========================================================================*/ -/* FUNCTION : void SWB_BWE_decoding_fx() */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : SWB BWE decoder */ -/*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS */ -/* _(Word16*) core_dec_freq :Frequency domain core decoded signal Q_syn */ -/* _(Word16) SWB_flength :Length of input/output Q0 */ -/* _(Word16) mode :classification for SWB signal */ -/* _(Word16) tilt_nb :tilt of synthesis wb signal Q11 */ -/* _(Word16) st_offset :offset value due to different core */ -/* _(Word16) Q_syn :Q format */ -/*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _(Word16*)SWB_fenv : SWB frequency envelopes Q1 */ -/* _(Word16*)prev_Energy : energy for last frame Q3 */ -/* _(Word16*)prev_SWB_fenv : envelope for last frame Q1 */ -/* _(Word16*)prev_L_swb_norm : length for last frame wb norm Q0 */ -/* _(Word16*)Seed : random generator seed Q0 */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _(Word16*)SWB_signal : SWB signal in MDCT domain Q0 */ -/* _(Word16*)frica_flag : fricative signal flag Q0 */ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*--------------------------------------------------------------------------*/ + /* calculate envelope */ + calc_norm_envelop_fx( WB_signal, envelope, L_wb_norm, WB_flength, 0 ); + test(); + IF( coder_type != UNVOICED && total_brate <= ACELP_8k00 ) + { + exp = norm_s( L_wb_norm ); + inv_L_wb_norm = shl( div_s( shl( 1, sub( 14, exp ) ), L_wb_norm ), sub( exp, 14 ) ); /* Q(15) */ + IF( NE_16( mode, HARMONIC ) ) + { + tmp = add( shl( inv_L_wb_norm, 1 ), inv_L_wb_norm ); + weight = s_max( s_min( tmp, 16384 ), 8192 ); + } + ELSE + { + weight = 8192; + move16(); + } + FOR( n_freq = swb_bwe_subband[0]; n_freq < swb_bwe_subband[4]; n_freq++ ) + { + signum[n_freq] = 1; + IF( WB_signal[n_freq] < 0 ) + { + signum[n_freq] = -1; + move16(); + WB_signal[n_freq] = negate( WB_signal[n_freq] ); + move16(); + } + L_tmp = Mult_32_16( envelope[n_freq], inv_L_wb_norm ); /* Q_syn */ + L_tmp = Mult_32_16( L_tmp, 14746 ); /* Q_syn */ + L_tmp1 = L_deposit_l( WB_signal[n_freq] ); /* Q_syn */ + L_tmp = L_sub( L_tmp1, L_tmp ); /* Q_syn */ + WB_signal[n_freq] = extract_l( L_tmp ); /* Q_syn */ + IF( L_tmp > 0 ) + { + tmp = sub( 18022, weight ); /* Q15 */ + WB_signal[n_freq] = extract_l( Mult_32_16( L_tmp, tmp ) ); /* Q_syn */ + } + + IF( NE_16( signum[n_freq], 1 ) ) + { + WB_signal[n_freq] = negate( WB_signal[n_freq] ); + move16(); + } + } + } -void SWB_BWE_decoding_fx( - const Word16 *core_dec_freq,/* i : Frequency domain core decoded signal */ - Word16 *SWB_fenv, /* i/o: SWB frequency envelopes */ - Word32 *SWB_signal_32, /* o : SWB signal in MDCT domain */ - const Word16 SWB_flength, /* i : Length of input/output */ - const Word16 mode, /* i : classification for SWB signal */ - Word16 *frica_flag, /* o : fricative signal flag */ - Word16 *prev_Energy, /* i/o: energy for last frame */ - Word16 *prev_SWB_fenv, /* i/o: envelope for last frame */ - Word16 *prev_L_swb_norm, /* i/o: length for last frame wb norm */ - const Word16 tilt_nb, /* i : tilt of synthesis wb signal */ - Word16 *Seed, /* i/o: random generator seed */ - const Word16 st_offset, /* i : offset value due to different core */ - Word16 *prev_weight, /* i/o: excitation weight value of last frame */ - const Word16 extl, /* i : extension layer */ - Word16 Q_syn - , const Word16 last_extl, /* i : extension layer of last frame */ - Word16 element_mode /* i : element mode */ -) -{ - Word16 n_freq, n_band, L, L_swb_norm; - Word32 *pit1_32; - Word16 *pit1; - Word32 envelope[L_FRAME32k]; - Word32 fenvL, EnergyL, Energy, energy, L_mean; - Word16 fenvL_16, EnergyL_16, Energy_16, tmp, exp, exp1; - Word16 SWB_signal[L_FRAME32k]; - Word16 mean, factor, factor1, tmp1, tmp2, tmp3, tmp_exp, tmp_ener, weight, wfenv; - Word32 L_tmp, L_tmp3, L_tmp4, Ltmp_ener, L_tmp1; - Word32 L_energy; - Word16 signum[L_FRAME32k]; - Word16 inv_L_swb_norm; - - fenvL = L_deposit_l(0); - EnergyL = L_deposit_l(0); - FOR(n_freq = 224 + st_offset; n_freq < swb_bwe_trans_subband[0] + st_offset; n_freq++) - { -#ifdef BASOP_NOGLOB - fenvL = L_mac0_sat(fenvL, core_dec_freq[n_freq], core_dec_freq[n_freq]); /*2*Q_syn */ -#else - fenvL = L_mac0(fenvL, core_dec_freq[n_freq], core_dec_freq[n_freq]); /*2*Q_syn */ -#endif - } + /* Normalize with envelope */ + FOR( n_freq = swb_bwe_subband[0]; n_freq < swb_bwe_subband[4]; n_freq++ ) + { + IF( envelope[n_freq] != 0 ) + { + exp = norm_l( envelope[n_freq] ); + tmp = extract_h( L_shl( envelope[n_freq], exp ) ); + exp = sub( sub( 30, exp ), Q_syn ); + tmp = div_s( 16384, tmp ); + L_tmp = L_shr( L_mult0( WB_signal[n_freq], tmp ), add( exp, Q_syn ) ); /*Q15 */ + WB_signal[n_freq] = extract_l( L_tmp ); /*Q15 */ + } + ELSE + { + WB_signal[n_freq] = shl( WB_signal[n_freq], sub( 15, Q_syn ) ); /*Q15 */ + move16(); + } + } - FOR(n_freq = 16; n_freq < L_FRAME; n_freq++) - { + L = 1; + move16(); + if ( EQ_16( mode, HARMONIC ) ) + { + L = 4; + move16(); + } + + IF( EQ_16( coder_type, UNVOICED ) ) + { + FOR( n_freq = swb_bwe_subband[0]; n_freq < swb_bwe_subband[4]; n_freq++ ) + { + *Seed = extract_l( L_mac0( 20101L, *Seed, 12345 ) ); + L_tmp = L_shl( *Seed, add( Q_syn, 1 ) ); + WB_signal_32[n_freq] = L_tmp; + move32(); + } + } + ELSE + { + FOR( n_band = 0; n_band < 4; n_band += L ) + { + energy = L_deposit_l( 0 ); + FOR( n_freq = swb_bwe_subband[n_band]; n_freq < swb_bwe_subband[n_band + L]; n_freq++ ) + { + L_tmp = L_mult0( WB_signal[n_freq], WB_signal[n_freq] ); /*Q30 */ + energy = L_add( energy, L_shr( L_tmp, 5 ) ); /*Q25 */ + } + + tmp = sub( swb_bwe_subband[n_band + L], swb_bwe_subband[n_band] ); + tmp = div_s( 1, tmp ); /*Q15 */ + energy = Mult_32_16( energy, tmp ); /*Q(15+25-15)->Q(25) */ + + exp = norm_l( energy ); + L_tmp1 = L_shl( energy, exp ); + exp = 31 - exp - ( 25 ); + move16(); + L_tmp1 = Isqrt_lc( L_tmp1, &exp ); /*Q(31-exp) */ + + FOR( n_freq = swb_bwe_subband[n_band]; n_freq < swb_bwe_subband[n_band + L]; n_freq++ ) + { + L_tmp2 = Mult_32_16( L_tmp1, WB_signal[n_freq] ); + WB_signal_32[n_freq] = L_shl( L_tmp2, sub( add( exp, Q_syn ), 15 ) ); + move32(); + } + } + } + + EnergyL = L_deposit_l( 0 ); + IF( core_type == 1 ) + { + test(); + IF( NE_16( prev_coder_type, AUDIO ) && LE_32( total_brate, ACELP_8k00 ) ) + { + FOR( i = 160; i < 240; i++ ) + { + EnergyL = L_add( abs_s( core_dec_freq[i] ), EnergyL ); + } + } + ELSE + { + FOR( i = 80; i < 240; i++ ) + { + EnergyL = L_add( abs_s( core_dec_freq[i] ), EnergyL ); + } + } + + IF( LE_32( total_brate, ACELP_8k00 ) ) + { + alfa = 26214; + move16(); /*0.8f in Q15; */ + beta = 10240; + move16(); /*1.25f in Q13; */ + } + ELSE + { + alfa = 16384; + move16(); /* 0.5f in Q15; */ + beta = 16384; + move16(); /*2.0f in Q13 */ + } + } + ELSE + { + IF( EQ_16( prev_coder_type, AUDIO ) ) + { + FOR( i = 80; i < 240; i++ ) + { + EnergyL = L_add( abs_s( core_dec_freq[i] ), EnergyL ); /*Q_syn */ + } + } + ELSE + { + FOR( i = 160; i < 240; i++ ) + { + EnergyL = L_add( abs_s( core_dec_freq[i] ), EnergyL ); + } + } + + test(); + IF( EQ_16( prev_coder_type, coder_type ) && GT_16( WB_fenv[0], prev_WB_fenv[0] ) ) + { + alfa = 13107; + move16(); /*.4 in Q15 */ + beta = 20480; + move16(); /*2.5 in Q13 */ + } + ELSE + { + alfa = 19661; + move16(); /*.6 in Q15 */ + beta = 13681; + move16(); /*1.67 in Q13 */ + } + + test(); + test(); + test(); + IF( EQ_16( coder_type, GENERIC ) || ( GT_32( EnergyL, L_shr( *prev_Energy, 1 ) ) && GT_32( *prev_Energy, L_shr( EnergyL, 1 ) ) && EQ_16( *prev_flag, 1 ) ) ) + { + WB_fenv[0] = shr( WB_fenv[0], 1 ); + move16(); + WB_fenv[1] = shr( WB_fenv[1], 1 ); + move16(); + flag = 1; + move16(); + } + } + L_tmp1 = Mult_32_16( EnergyL, prev_WB_fenv[0] ); /*Qsyn+3-15 */ + L_tmp2 = Mult_32_16( *prev_Energy, WB_fenv[0] ); /*Q_syn+3-15 */ + prev_ener_alpha = Mult_32_16( *prev_Energy, alfa ); /*Q_syn+15-15->Q_syn */ + prev_ener_beta = L_shl( Mult_32_16( *prev_Energy, beta ), 2 ); /*Q_syn+13-15+2 ->Q_syn */ + + test(); + test(); + IF( ( EQ_16( mode, HARMONIC ) && GT_16( shr( WB_fenv[0], 2 ), WB_fenv[1] ) ) || EQ_16( mode, NORMAL ) ) + { + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( EQ_16( last_extl, WB_BWE ) && + ( ( EQ_16( prev_coder_type, AUDIO ) && NE_16( coder_type, AUDIO ) ) || + ( NE_16( prev_coder_type, AUDIO ) && EQ_16( coder_type, AUDIO ) ) ) && + LE_32( total_brate, ACELP_8k00 ) ) + { + IF( GT_16( WB_fenv[0], prev_WB_fenv[0] ) ) + { + /*wfenv[0]= add(mult_r(9830, WB_fenv[0]), mult_r(22938, prev_WB_fenv[0]));//Q3 */ + wfenv[0] = round_fx( L_mac( L_mult( 9830, WB_fenv[0] ), 22938, prev_WB_fenv[0] ) ); /*Q3 */ + /*wfenv[1]= add(mult_r(9830, WB_fenv[1]), mult_r(22938, prev_WB_fenv[1]));//Q3 */ + wfenv[1] = round_fx( L_mac( L_mult( 9830, WB_fenv[1] ), 22938, prev_WB_fenv[1] ) ); /*Q3 */ + } + ELSE + { + /*wfenv[0]= add(mult_r(16384,WB_fenv[0]),mult_r(16384,prev_WB_fenv[0]));//Q3 */ + wfenv[0] = round_fx( L_mac( L_mult( 16384, WB_fenv[0] ), 16384, prev_WB_fenv[0] ) ); /*Q3 */ + /*wfenv[1]= add(mult_r(13108,WB_fenv[1]),mult_r(13108,prev_WB_fenv[1]));//Q3 */ + wfenv[1] = round_fx( L_mac( L_mult( 13108, WB_fenv[1] ), 13108, prev_WB_fenv[1] ) ); /*Q3 */ + } + } + ELSE IF( EQ_16( last_extl, WB_BWE ) && LT_32( L_tmp1, L_tmp2 ) && GT_16( WB_fenv[0], prev_WB_fenv[0] ) && + NE_16( coder_type, AUDIO ) && NE_16( coder_type, UNVOICED ) && LE_32( total_brate, ACELP_8k00 ) ) + { + /*wfenv[0]= add(mult_r(9830,WB_fenv[0]),mult_r(22938,prev_WB_fenv[0]));//Q3 */ + wfenv[0] = round_fx( L_mac( L_mult( 9830, WB_fenv[0] ), 22938, prev_WB_fenv[0] ) ); /*Q3 */ + /*wfenv[1]= add(mult_r(9830,WB_fenv[1]),mult_r(22938,prev_WB_fenv[1]));//Q3 */ + wfenv[1] = round_fx( L_mac( L_mult( 9830, WB_fenv[1] ), 22938, prev_WB_fenv[1] ) ); /*Q3 */ + } + ELSE IF( EQ_16( last_extl, WB_BWE ) && GT_32( EnergyL, prev_ener_alpha ) && GT_32( prev_ener_beta, EnergyL ) && + NE_16( prev_coder_type, UNVOICED ) ) + { + /*wfenv[0] = add(shr(WB_fenv[0],1), shr(prev_WB_fenv[0],1));//Q3 */ + wfenv[0] = round_fx( L_mac( L_mult( WB_fenv[0], 16384 ), prev_WB_fenv[0], 16384 ) ); /*Q3 */ + /*wfenv[1] = add(shr(WB_fenv[1],1), shr(prev_WB_fenv[1],1));//Q3 */ + wfenv[1] = round_fx( L_mac( L_mult( WB_fenv[1], 16384 ), prev_WB_fenv[1], 16384 ) ); /*Q3 */ + } + ELSE + { + wfenv[0] = WB_fenv[0]; + move16(); + wfenv[1] = WB_fenv[1]; + move16(); + } + FOR( n_freq = swb_bwe_subband[0]; n_freq < swb_bwe_subband[2]; n_freq++ ) + { + WB_signal_32[n_freq] = Mult_32_16( WB_signal_32[n_freq], wfenv[0] ); + move32(); /* Q_syn+3+1 */ + } + + FOR( n_freq = swb_bwe_subband[2]; n_freq < swb_bwe_subband[4]; n_freq++ ) + { + WB_signal_32[n_freq] = Mult_32_16( WB_signal_32[n_freq], wfenv[1] ); + move32(); /* Q_syn+3+1 */ + } + + prev_WB_fenv[0] = wfenv[0]; + move16(); + prev_WB_fenv[1] = wfenv[1]; + move16(); + } + ELSE + { + wfenv[0] = add( shr( WB_fenv[0], 1 ), shr( WB_fenv[1], 1 ) ); /*Q3 */ + + test(); + test(); + IF( EQ_16( last_extl, WB_BWE ) && GT_32( EnergyL, L_shr( *prev_Energy, 1 ) ) && GT_32( *prev_Energy, L_shr( EnergyL, 1 ) ) ) + { + L_tmp1 = L_mac( L_mult( 8192, wfenv[0] ), 12288, prev_WB_fenv[0] ); + wfenv[0] = round_fx( L_mac( L_tmp1, 12288, prev_WB_fenv[1] ) ); + } + FOR( n_freq = swb_bwe_subband[0]; n_freq < swb_bwe_subband[4]; n_freq++ ) + { + WB_signal_32[n_freq] = Mult_32_16( WB_signal_32[n_freq], wfenv[0] ); + move32(); /* Q_syn+3+1 */ + } + prev_WB_fenv[0] = wfenv[0]; + move16(); + prev_WB_fenv[1] = wfenv[0]; + move16(); + } + + *prev_flag = flag; + move16(); + *prev_Energy = EnergyL; + move32(); + pit1 = &WB_signal_32[240]; + + FOR( n_freq = 0; n_freq < 16; n_freq++ ) + { + tmp1 = extract_l( L_mult0( n_freq, 1638 ) ); /*Q15 */ + tmp2 = add( 6554, tmp1 ); /*Q15 */ + L_tmp1 = Mult_32_16( *pit1, tmp2 ); /*Q_syn+3+1 */ + *( pit1++ ) = L_tmp1; + move32(); + } + + IF( EQ_16( core_type, 1 ) ) + { + pit1 = &WB_signal_32[280]; + FOR( n_freq = 0; n_freq < 40; n_freq++ ) + { + tmp1 = extract_l( L_mult0( n_freq, 655 ) ); /*Q15 */ + tmp2 = sub( 32767, tmp1 ); + L_tmp1 = Mult_32_16( *pit1, tmp2 ); /*Q_syn+3+1 */ + *( pit1++ ) = L_tmp1; + move32(); + } + } + ELSE + { + pit1 = &WB_signal_32[300]; + FOR( n_freq = 0; n_freq < 20; n_freq++ ) + { + tmp1 = extract_l( L_mult0( n_freq, 1311 ) ); /*Q15 */ + tmp2 = sub( 32767, tmp1 ); + L_tmp1 = Mult_32_16( *pit1, tmp2 ); /*Q_syn+3+1 */ + *( pit1++ ) = L_tmp1; + move32(); + } + } + pit1 = &WB_signal_32[240]; + tmp = Find_Max_Norm32( pit1, 80 ); + FOR( i = 0; i < 80; i++ ) + { + L_tmp = *pit1; + *( pit1++ ) = L_shl( L_tmp, sub( tmp, 1 ) ); + move32(); + } + *Q_syn_hb = add( Q_syn, add( tmp, 3 ) ); + return; +} + + +/*==========================================================================*/ +/* FUNCTION : void SWB_BWE_decoding_fx() */ +/*--------------------------------------------------------------------------*/ +/* PURPOSE : SWB BWE decoder */ +/*--------------------------------------------------------------------------*/ +/* INPUT ARGUMENTS */ +/* _(Word16*) core_dec_freq :Frequency domain core decoded signal Q_syn */ +/* _(Word16) SWB_flength :Length of input/output Q0 */ +/* _(Word16) mode :classification for SWB signal */ +/* _(Word16) tilt_nb :tilt of synthesis wb signal Q11 */ +/* _(Word16) st_offset :offset value due to different core */ +/* _(Word16) Q_syn :Q format */ +/*--------------------------------------------------------------------------*/ +/* OUTPUT ARGUMENTS : */ +/* _(Word16*)SWB_fenv : SWB frequency envelopes Q1 */ +/* _(Word16*)prev_Energy : energy for last frame Q3 */ +/* _(Word16*)prev_SWB_fenv : envelope for last frame Q1 */ +/* _(Word16*)prev_L_swb_norm : length for last frame wb norm Q0 */ +/* _(Word16*)Seed : random generator seed Q0 */ +/*--------------------------------------------------------------------------*/ +/* INPUT/OUTPUT ARGUMENTS : */ +/* _(Word16*)SWB_signal : SWB signal in MDCT domain Q0 */ +/* _(Word16*)frica_flag : fricative signal flag Q0 */ +/*--------------------------------------------------------------------------*/ +/* RETURN ARGUMENTS : */ +/* _ None */ +/*--------------------------------------------------------------------------*/ + +void SWB_BWE_decoding_fx( + const Word16 *core_dec_freq, /* i : Frequency domain core decoded signal */ + Word16 *SWB_fenv, /* i/o: SWB frequency envelopes */ + Word32 *SWB_signal_32, /* o : SWB signal in MDCT domain */ + const Word16 SWB_flength, /* i : Length of input/output */ + const Word16 mode, /* i : classification for SWB signal */ + Word16 *frica_flag, /* o : fricative signal flag */ + Word16 *prev_Energy, /* i/o: energy for last frame */ + Word16 *prev_SWB_fenv, /* i/o: envelope for last frame */ + Word16 *prev_L_swb_norm, /* i/o: length for last frame wb norm */ + const Word16 tilt_nb, /* i : tilt of synthesis wb signal */ + Word16 *Seed, /* i/o: random generator seed */ + const Word16 st_offset, /* i : offset value due to different core */ + Word16 *prev_weight, /* i/o: excitation weight value of last frame */ + const Word16 extl, /* i : extension layer */ + Word16 Q_syn, + const Word16 last_extl, /* i : extension layer of last frame */ + Word16 element_mode /* i : element mode */ +) +{ + Word16 n_freq, n_band, L, L_swb_norm; + Word32 *pit1_32; + Word16 *pit1; + Word32 envelope[L_FRAME32k]; + Word32 fenvL, EnergyL, Energy, energy, L_mean; + Word16 fenvL_16, EnergyL_16, Energy_16, tmp, exp, exp1; + Word16 SWB_signal[L_FRAME32k]; + Word16 mean, factor, factor1, tmp1, tmp2, tmp3, tmp_exp, tmp_ener, weight, wfenv; + Word32 L_tmp, L_tmp3, L_tmp4, Ltmp_ener, L_tmp1; + Word32 L_energy; + Word16 signum[L_FRAME32k]; + Word16 inv_L_swb_norm; + + fenvL = L_deposit_l( 0 ); + EnergyL = L_deposit_l( 0 ); + FOR( n_freq = 224 + st_offset; n_freq < swb_bwe_trans_subband[0] + st_offset; n_freq++ ) + { +#ifdef BASOP_NOGLOB + fenvL = L_mac0_sat( fenvL, core_dec_freq[n_freq], core_dec_freq[n_freq] ); /*2*Q_syn */ +#else + fenvL = L_mac0( fenvL, core_dec_freq[n_freq], core_dec_freq[n_freq] ); /*2*Q_syn */ +#endif + } + + FOR( n_freq = 16; n_freq < L_FRAME; n_freq++ ) + { #ifdef BASOP_NOGLOB - EnergyL = L_mac0_sat(EnergyL, core_dec_freq[n_freq], core_dec_freq[n_freq]); /*2*Q_syn */ + EnergyL = L_mac0_sat( EnergyL, core_dec_freq[n_freq], core_dec_freq[n_freq] ); /*2*Q_syn */ #else - EnergyL = L_mac0(EnergyL, core_dec_freq[n_freq], core_dec_freq[n_freq]); /*2*Q_syn */ + EnergyL = L_mac0( EnergyL, core_dec_freq[n_freq], core_dec_freq[n_freq] ); /*2*Q_syn */ #endif - } + } - fenvL_16 = 0; - move16(); - IF(fenvL != 0) - { - exp = norm_l(fenvL); /* In 2*Q_syn */ - tmp = extract_h(L_shl(fenvL, exp)); - exp = sub(exp, sub(30, add(shl(Q_syn, 1), 4))); /*+4(/16) */ + fenvL_16 = 0; + move16(); + IF( fenvL != 0 ) + { + exp = norm_l( fenvL ); /* In 2*Q_syn */ + tmp = extract_h( L_shl( fenvL, exp ) ); + exp = sub( exp, sub( 30, add( shl( Q_syn, 1 ), 4 ) ) ); /*+4(/16) */ - tmp = div_s(16384, tmp); - L_tmp = L_deposit_h(tmp); - L_tmp = Isqrt_lc(L_tmp, &exp); + tmp = div_s( 16384, tmp ); + L_tmp = L_deposit_h( tmp ); + L_tmp = Isqrt_lc( L_tmp, &exp ); #ifdef BASOP_NOGLOB fenvL_16 = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 12 ) ) ); /* Q3 */ #else - fenvL_16 = round_fx( L_shl( L_tmp, sub( exp, 12 ) ) ); /* Q3 */ + fenvL_16 = round_fx( L_shl( L_tmp, sub( exp, 12 ) ) ); /* Q3 */ #endif - } + } #ifdef BASOP_NOGLOB IF( GT_16( fenvL_16, shl_sat( SWB_fenv[0], 5 ) ) ) #else IF( GT_16( fenvL_16, shl( SWB_fenv[0], 5 ) ) ) #endif - { - fenvL_16 = shl(SWB_fenv[0], 2); - move16(); - } - EnergyL = Mult_32_16(EnergyL, 17476); /*2*Q_syn+3; 17476=(1/15) in Q18 */ - EnergyL_16 = 0; - move16(); - IF(EnergyL != 0) - { - exp = norm_l(EnergyL); /* In 2*Q_syn+3 */ - tmp = extract_h(L_shl(EnergyL, exp)); - exp = sub(exp, sub(30, add(shl(Q_syn, 1), 3 + 4))); /*+4(/16) */ - - tmp = div_s(16384, tmp); - L_tmp = L_deposit_h(tmp); - L_tmp = Isqrt_lc(L_tmp, &exp); + { + fenvL_16 = shl( SWB_fenv[0], 2 ); + move16(); + } + EnergyL = Mult_32_16( EnergyL, 17476 ); /*2*Q_syn+3; 17476=(1/15) in Q18 */ + EnergyL_16 = 0; + move16(); + IF( EnergyL != 0 ) + { + exp = norm_l( EnergyL ); /* In 2*Q_syn+3 */ + tmp = extract_h( L_shl( EnergyL, exp ) ); + exp = sub( exp, sub( 30, add( shl( Q_syn, 1 ), 3 + 4 ) ) ); /*+4(/16) */ + + tmp = div_s( 16384, tmp ); + L_tmp = L_deposit_h( tmp ); + L_tmp = Isqrt_lc( L_tmp, &exp ); #ifdef BASOP_NOGLOB - EnergyL_16 = round_fx_sat(L_shl_sat(L_tmp, sub(exp, 12))); /* Q3 */ -#else - EnergyL_16 = round_fx(L_shl(L_tmp, sub(exp, 12))); /* Q3 */ -#endif - } - calc_normal_length_fx(ACELP_CORE, core_dec_freq, mode, extl, &L_swb_norm, prev_L_swb_norm, Q_syn); - - set16_fx(SWB_signal, 0, L_FRAME32k); - IF(EQ_16(mode, TRANSIENT)) - { - Energy = L_deposit_l(0); - FOR(n_band = 0; n_band < SWB_FENV_TRANS; n_band++) - { - Energy = L_mac(Energy, SWB_fenv[n_band], SWB_fenv[n_band]); /*Q(2*1+1)->Q3 */ - } - exp = norm_s(SWB_FENV_TRANS); - tmp = div_s(shl(1, sub(14, exp)), SWB_FENV_TRANS); /*Q(29-exp) */ - L_tmp = Mult_32_16(Energy, tmp); /*Q(3+29-exp+1-16)->Q(17-exp) */ - Energy_16 = round_fx(L_shl(L_tmp, add(exp, 2))); /*Q3 */ - - /* Reconstruct excitation from LF signal */ - Copy(&core_dec_freq[112], &SWB_signal[240 + st_offset], 128); - Copy(&core_dec_freq[112], &SWB_signal[368 + st_offset], 128); - Copy(&core_dec_freq[176], &SWB_signal[496 + st_offset], 64); - - /* calculate envelope */ - calc_norm_envelop_fx(SWB_signal, envelope, L_swb_norm, SWB_flength, st_offset); - - /* Normalize with envelope */ - tmp_exp = sub(15, Q_syn); - FOR(n_freq = swb_bwe_trans_subband[0] + st_offset; n_freq < swb_bwe_trans_subband[SWB_FENV_TRANS] + st_offset; n_freq++) - { - IF(envelope[n_freq] != 0) - { - exp = norm_l(envelope[n_freq]); - tmp = extract_h(L_shl(envelope[n_freq], exp)); - exp = sub(sub(30, exp), Q_syn); - tmp = div_s(16384, tmp); /*Q(15+exp) */ - L_tmp = L_shr(L_mult0(SWB_signal[n_freq], tmp), add(exp, Q_syn)); /*Q15 */ - SWB_signal[n_freq] = extract_l(L_tmp); /*Q15 */ - } - ELSE - { - SWB_signal[n_freq] = shl(SWB_signal[n_freq], tmp_exp); - move16();/*Q15 */ - } - } - - FOR(n_band = 0; n_band < SWB_FENV_TRANS; n_band++) - { - energy = L_deposit_l(0); - tmp = add(swb_bwe_trans_subband[n_band + 1], st_offset); - FOR(n_freq = add(swb_bwe_trans_subband[n_band], st_offset); n_freq < tmp; n_freq++) - { -#ifdef BASOP_NOGLOB - L_tmp = L_mult_sat(SWB_signal[n_freq], SWB_signal[n_freq]); /*Q31 */ - energy = L_add_sat(energy, L_shr(L_tmp, 6)); /*Q25 */ + EnergyL_16 = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 12 ) ) ); /* Q3 */ #else - L_tmp = L_mult(SWB_signal[n_freq], SWB_signal[n_freq]); /*Q31 */ - energy = L_add(energy, L_shr(L_tmp, 6)); /*Q25 */ + EnergyL_16 = round_fx( L_shl( L_tmp, sub( exp, 12 ) ) ); /* Q3 */ #endif - } - - IF(energy == 0) - { - Ltmp_ener = L_mult(sqrt_swb_bwe_trans_subband_width_fx[n_band], SWB_fenv[n_band]);/*Q13 */ - tmp = add(swb_bwe_trans_subband[n_band + 1], st_offset); - FOR(n_freq = add(swb_bwe_trans_subband[n_band], st_offset); n_freq < tmp; n_freq++) - { - SWB_signal_32[n_freq] = L_shl(Mult_32_16(Ltmp_ener, SWB_signal[n_freq]), 2 + Q_syn); - move32();/*15+Qsyn */ - } - } - ELSE - { - exp1 = norm_s(swb_bwe_trans_subband_width[n_band]); - tmp = div_s(shl(1,sub(14,exp1)),swb_bwe_trans_subband_width[n_band]); /*Q(29-exp1) */ - energy = Mult_32_16(energy,tmp); /*Q(29-exp1+25-15)->Q(-exp1+39) */ - - exp = norm_l(energy); - L_tmp = L_shl(energy,exp); - /*exp = 31-exp-(-exp1+39); */ - exp = sub(sub(exp1,exp),8); - L_tmp = Isqrt_lc(L_tmp, &exp); /*Q(31-exp) */ - - Ltmp_ener = Mult_32_16(L_tmp,SWB_fenv[n_band]);/*Q(31-exp+1+1-16)->Q(17-exp) */ - tmp = add(swb_bwe_trans_subband[n_band + 1],st_offset); - tmp_exp = add(Q_syn,sub(exp,2)); - FOR(n_freq = add(swb_bwe_trans_subband[n_band],st_offset); n_freq < tmp; n_freq++) - { - SWB_signal_32[n_freq] = L_shl(Mult_32_16(Ltmp_ener,SWB_signal[n_freq]), tmp_exp); - move32(); /*15+Qsyn */ - } - } - } - - FOR(n_band = 0; n_band < 8; n_band++) - { - L_tmp = L_mult(SWB_fenv[n_band / 4], SWB_fenv[n_band / 4]); /*Q3 */ - prev_SWB_fenv[n_band] = round_fx(L_shl(L_tmp, 14)); /*Q1 */ - } - - FOR(n_band = 0; n_band < 6; n_band++) - { - L_tmp = L_mult(SWB_fenv[2 + n_band / 3], SWB_fenv[2 + n_band / 3]); /*Q3 */ - prev_SWB_fenv[8 + n_band] = round_fx(L_shl(L_tmp, 14)); /*Q1 */ - } - - *prev_weight = 16384; - move16(); - } - ELSE - { - Energy_16 = 0; - move16(); - L_energy = L_deposit_l(0); - FOR(n_band = 0; n_band < SWB_FENV; n_band++) - { - L_energy = L_add(L_energy,SWB_fenv[n_band]); /*Q1 */ - } - exp = norm_s(SWB_FENV); - tmp = div_s(shl(1,sub(14,exp)),SWB_FENV); /*Q(29-exp) */ - L_tmp = Mult_32_16(L_energy,tmp); /*Q(1+29-exp+1)->Q(15-exp) */ - IF(EQ_16(element_mode, EVS_MONO)) + } + calc_normal_length_fx( ACELP_CORE, core_dec_freq, mode, extl, &L_swb_norm, prev_L_swb_norm, Q_syn ); + + set16_fx( SWB_signal, 0, L_FRAME32k ); + IF( EQ_16( mode, TRANSIENT ) ) { + Energy = L_deposit_l( 0 ); + FOR( n_band = 0; n_band < SWB_FENV_TRANS; n_band++ ) + { + Energy = L_mac( Energy, SWB_fenv[n_band], SWB_fenv[n_band] ); /*Q(2*1+1)->Q3 */ + } + exp = norm_s( SWB_FENV_TRANS ); + tmp = div_s( shl( 1, sub( 14, exp ) ), SWB_FENV_TRANS ); /*Q(29-exp) */ + L_tmp = Mult_32_16( Energy, tmp ); /*Q(3+29-exp+1-16)->Q(17-exp) */ + Energy_16 = round_fx( L_shl( L_tmp, add( exp, 2 ) ) ); /*Q3 */ + + /* Reconstruct excitation from LF signal */ + Copy( &core_dec_freq[112], &SWB_signal[240 + st_offset], 128 ); + Copy( &core_dec_freq[112], &SWB_signal[368 + st_offset], 128 ); + Copy( &core_dec_freq[176], &SWB_signal[496 + st_offset], 64 ); + + /* calculate envelope */ + calc_norm_envelop_fx( SWB_signal, envelope, L_swb_norm, SWB_flength, st_offset ); + + /* Normalize with envelope */ + tmp_exp = sub( 15, Q_syn ); + FOR( n_freq = swb_bwe_trans_subband[0] + st_offset; n_freq < swb_bwe_trans_subband[SWB_FENV_TRANS] + st_offset; n_freq++ ) + { + IF( envelope[n_freq] != 0 ) + { + exp = norm_l( envelope[n_freq] ); + tmp = extract_h( L_shl( envelope[n_freq], exp ) ); + exp = sub( sub( 30, exp ), Q_syn ); + tmp = div_s( 16384, tmp ); /*Q(15+exp) */ + L_tmp = L_shr( L_mult0( SWB_signal[n_freq], tmp ), add( exp, Q_syn ) ); /*Q15 */ + SWB_signal[n_freq] = extract_l( L_tmp ); /*Q15 */ + } + ELSE + { + SWB_signal[n_freq] = shl( SWB_signal[n_freq], tmp_exp ); + move16(); /*Q15 */ + } + } + + FOR( n_band = 0; n_band < SWB_FENV_TRANS; n_band++ ) + { + energy = L_deposit_l( 0 ); + tmp = add( swb_bwe_trans_subband[n_band + 1], st_offset ); + FOR( n_freq = add( swb_bwe_trans_subband[n_band], st_offset ); n_freq < tmp; n_freq++ ) + { #ifdef BASOP_NOGLOB - Energy_16 = round_fx_sat(L_shl_sat(L_tmp, add(exp, 4))); + L_tmp = L_mult_sat( SWB_signal[n_freq], SWB_signal[n_freq] ); /*Q31 */ + energy = L_add_sat( energy, L_shr( L_tmp, 6 ) ); /*Q25 */ #else - EnergyL_16 = round_fx( L_shl( L_tmp, add( exp, 4 ) ) ); + L_tmp = L_mult( SWB_signal[n_freq], SWB_signal[n_freq] ); /*Q31 */ + energy = L_add( energy, L_shr( L_tmp, 6 ) ); /*Q25 */ #endif + } + + IF( energy == 0 ) + { + Ltmp_ener = L_mult( sqrt_swb_bwe_trans_subband_width_fx[n_band], SWB_fenv[n_band] ); /*Q13 */ + tmp = add( swb_bwe_trans_subband[n_band + 1], st_offset ); + FOR( n_freq = add( swb_bwe_trans_subband[n_band], st_offset ); n_freq < tmp; n_freq++ ) + { + SWB_signal_32[n_freq] = L_shl( Mult_32_16( Ltmp_ener, SWB_signal[n_freq] ), 2 + Q_syn ); + move32(); /*15+Qsyn */ + } + } + ELSE + { + exp1 = norm_s( swb_bwe_trans_subband_width[n_band] ); + tmp = div_s( shl( 1, sub( 14, exp1 ) ), swb_bwe_trans_subband_width[n_band] ); /*Q(29-exp1) */ + energy = Mult_32_16( energy, tmp ); /*Q(29-exp1+25-15)->Q(-exp1+39) */ + + exp = norm_l( energy ); + L_tmp = L_shl( energy, exp ); + /*exp = 31-exp-(-exp1+39); */ + exp = sub( sub( exp1, exp ), 8 ); + L_tmp = Isqrt_lc( L_tmp, &exp ); /*Q(31-exp) */ + + Ltmp_ener = Mult_32_16( L_tmp, SWB_fenv[n_band] ); /*Q(31-exp+1+1-16)->Q(17-exp) */ + tmp = add( swb_bwe_trans_subband[n_band + 1], st_offset ); + tmp_exp = add( Q_syn, sub( exp, 2 ) ); + FOR( n_freq = add( swb_bwe_trans_subband[n_band], st_offset ); n_freq < tmp; n_freq++ ) + { + SWB_signal_32[n_freq] = L_shl( Mult_32_16( Ltmp_ener, SWB_signal[n_freq] ), tmp_exp ); + move32(); /*15+Qsyn */ + } + } + } + + FOR( n_band = 0; n_band < 8; n_band++ ) + { + L_tmp = L_mult( SWB_fenv[n_band / 4], SWB_fenv[n_band / 4] ); /*Q3 */ + prev_SWB_fenv[n_band] = round_fx( L_shl( L_tmp, 14 ) ); /*Q1 */ + } + + FOR( n_band = 0; n_band < 6; n_band++ ) + { + L_tmp = L_mult( SWB_fenv[2 + n_band / 3], SWB_fenv[2 + n_band / 3] ); /*Q3 */ + prev_SWB_fenv[8 + n_band] = round_fx( L_shl( L_tmp, 14 ) ); /*Q1 */ + } + + *prev_weight = 16384; + move16(); } ELSE { + Energy_16 = 0; + move16(); + L_energy = L_deposit_l( 0 ); + FOR( n_band = 0; n_band < SWB_FENV; n_band++ ) + { + L_energy = L_add( L_energy, SWB_fenv[n_band] ); /*Q1 */ + } + exp = norm_s( SWB_FENV ); + tmp = div_s( shl( 1, sub( 14, exp ) ), SWB_FENV ); /*Q(29-exp) */ + L_tmp = Mult_32_16( L_energy, tmp ); /*Q(1+29-exp+1)->Q(15-exp) */ + IF( EQ_16( element_mode, EVS_MONO ) ) + { #ifdef BASOP_NOGLOB - EnergyL_16 = round_fx_sat(L_shl_sat(L_tmp, add(exp, 4))); /* Q3 */ + Energy_16 = round_fx_sat( L_shl_sat( L_tmp, add( exp, 4 ) ) ); #else - Energy_16 = round_fx(L_shl(L_tmp,add(exp,4))); /*Q3 */ + EnergyL_16 = round_fx( L_shl( L_tmp, add( exp, 4 ) ) ); #endif - } + } + ELSE + { +#ifdef BASOP_NOGLOB + EnergyL_16 = round_fx_sat( L_shl_sat( L_tmp, add( exp, 4 ) ) ); /* Q3 */ +#else + Energy_16 = round_fx( L_shl( L_tmp, add( exp, 4 ) ) ); /*Q3 */ +#endif + } - IF(NE_16(last_extl, SWB_BWE) && NE_16(last_extl,FB_BWE)) - { - IF(Energy_16 < shr(EnergyL_16, 4) && EQ_16(extl, FB_BWE)) - { - FOR(n_band = 0; n_band < SWB_FENV; n_band++) - { - SWB_fenv[n_band] = mult_r(SWB_fenv[n_band], 6554); - } - fenvL_16 = mult_r(fenvL_16, 6554); - } - Copy(SWB_fenv, prev_SWB_fenv, SWB_FENV); - } - - IF(mode == HARMONIC) - { - Copy(core_dec_freq, &SWB_signal[240 + st_offset], 240); - Copy(&core_dec_freq[128], &SWB_signal[480 + st_offset], 80); - /* calculate envelope */ - calc_norm_envelop_fx(SWB_signal, envelope, L_swb_norm, SWB_flength, st_offset); - } - ELSE - { - test(); - test(); - test(); - test(); - test(); - test(); - IF(EQ_16(mode, NOISE) || ((GT_16(Energy_16,EnergyL_16) || (GT_16(tilt_nb,14336) && GT_16(Energy_16,shr(EnergyL_16,1))) || - GT_16(tilt_nb,24576)) && GT_16(Energy_16,600) && GT_16(fenvL_16,200))) - { - tmp = add(swb_bwe_subband[SWB_FENV], st_offset); - FOR(n_freq = add(swb_bwe_subband[0],st_offset); n_freq < tmp; n_freq++) - { - *Seed = extract_l(L_mac0(20101L, 12345,*Seed)); - SWB_signal[n_freq] = mult_r(*Seed, 32767); - move16();/*Q15 */ - } - if (NE_16(mode, NOISE)) - { - *frica_flag = 1; - move16(); - } - } - ELSE - { - /* modify SHB frequency envelopes when SHB spectrum is unflat */ - FOR(n_band = 0; n_band < 13; n_band++) - { - IF(GT_16(mult_r(SWB_fenv[n_band],29491), SWB_fenv[n_band + 1])) - { - tmp = extract_l(L_mac0(26214, n_band, 492)); /*Q15; 0.015 in Q15 = 492 */ - SWB_fenv[n_band + 1] = mult_r(SWB_fenv[n_band + 1], tmp); - move16();/*Q1 */ - } - - IF(GT_16(mult_r(SWB_fenv[n_band + 1],29491),SWB_fenv[n_band])) - { - tmp = extract_l(L_mac0(26214, n_band,492)); /*Q15; 0.015 in Q15 = 492 */ - SWB_fenv[n_band] = mult_r(SWB_fenv[n_band],tmp); - move16();/*Q1 */ - } - } - Copy(&core_dec_freq[112], &SWB_signal[240 + st_offset], 128); - Copy(&core_dec_freq[112], &SWB_signal[368 + st_offset], 128); - Copy(&core_dec_freq[176], &SWB_signal[496 + st_offset], 64); + IF( NE_16( last_extl, SWB_BWE ) && NE_16( last_extl, FB_BWE ) ) + { + IF( Energy_16 < shr( EnergyL_16, 4 ) && EQ_16( extl, FB_BWE ) ) + { + FOR( n_band = 0; n_band < SWB_FENV; n_band++ ) + { + SWB_fenv[n_band] = mult_r( SWB_fenv[n_band], 6554 ); + } + fenvL_16 = mult_r( fenvL_16, 6554 ); + } + Copy( SWB_fenv, prev_SWB_fenv, SWB_FENV ); + } + + IF( mode == HARMONIC ) + { + Copy( core_dec_freq, &SWB_signal[240 + st_offset], 240 ); + Copy( &core_dec_freq[128], &SWB_signal[480 + st_offset], 80 ); + /* calculate envelope */ + calc_norm_envelop_fx( SWB_signal, envelope, L_swb_norm, SWB_flength, st_offset ); + } + ELSE + { + test(); + test(); + test(); + test(); + test(); + test(); + IF( EQ_16( mode, NOISE ) || ( ( GT_16( Energy_16, EnergyL_16 ) || ( GT_16( tilt_nb, 14336 ) && GT_16( Energy_16, shr( EnergyL_16, 1 ) ) ) || + GT_16( tilt_nb, 24576 ) ) && + GT_16( Energy_16, 600 ) && GT_16( fenvL_16, 200 ) ) ) + { + tmp = add( swb_bwe_subband[SWB_FENV], st_offset ); + FOR( n_freq = add( swb_bwe_subband[0], st_offset ); n_freq < tmp; n_freq++ ) + { + *Seed = extract_l( L_mac0( 20101L, 12345, *Seed ) ); + SWB_signal[n_freq] = mult_r( *Seed, 32767 ); + move16(); /*Q15 */ + } + if ( NE_16( mode, NOISE ) ) + { + *frica_flag = 1; + move16(); + } + } + ELSE + { + /* modify SHB frequency envelopes when SHB spectrum is unflat */ + FOR( n_band = 0; n_band < 13; n_band++ ) + { + IF( GT_16( mult_r( SWB_fenv[n_band], 29491 ), SWB_fenv[n_band + 1] ) ) + { + tmp = extract_l( L_mac0( 26214, n_band, 492 ) ); /*Q15; 0.015 in Q15 = 492 */ + SWB_fenv[n_band + 1] = mult_r( SWB_fenv[n_band + 1], tmp ); + move16(); /*Q1 */ + } + + IF( GT_16( mult_r( SWB_fenv[n_band + 1], 29491 ), SWB_fenv[n_band] ) ) + { + tmp = extract_l( L_mac0( 26214, n_band, 492 ) ); /*Q15; 0.015 in Q15 = 492 */ + SWB_fenv[n_band] = mult_r( SWB_fenv[n_band], tmp ); + move16(); /*Q1 */ + } + } + Copy( &core_dec_freq[112], &SWB_signal[240 + st_offset], 128 ); + Copy( &core_dec_freq[112], &SWB_signal[368 + st_offset], 128 ); + Copy( &core_dec_freq[176], &SWB_signal[496 + st_offset], 64 ); #ifdef BASOP_NOGLOB - tmp1 = add_sat(abs_s(SWB_signal[368 + st_offset]), abs_s(SWB_signal[369 + st_offset])); /*Q_syn */ - tmp2 = add_sat(abs_s(SWB_signal[365 + st_offset]), abs_s(SWB_signal[366 + st_offset])); /*Q_syn */ + tmp1 = add_sat( abs_s( SWB_signal[368 + st_offset] ), abs_s( SWB_signal[369 + st_offset] ) ); /*Q_syn */ + tmp2 = add_sat( abs_s( SWB_signal[365 + st_offset] ), abs_s( SWB_signal[366 + st_offset] ) ); /*Q_syn */ #else - tmp1 = add(abs_s(SWB_signal[368 + st_offset]), abs_s(SWB_signal[369 + st_offset])); /*Q_syn */ - tmp2 = add(abs_s(SWB_signal[365 + st_offset]), abs_s(SWB_signal[366 + st_offset])); /*Q_syn */ + tmp1 = add( abs_s( SWB_signal[368 + st_offset] ), abs_s( SWB_signal[369 + st_offset] ) ); /*Q_syn */ + tmp2 = add( abs_s( SWB_signal[365 + st_offset] ), abs_s( SWB_signal[366 + st_offset] ) ); /*Q_syn */ #endif - pit1 = &SWB_signal[368 + st_offset]; - move16(); - - test(); - IF((tmp2 == 0) || (LT_16(tmp2, mult_r(tmp1, 9830)))) - { - tmp3 = 9830; - move16();/*0.3 in Q15 */ - WHILE(LT_16(tmp3,32767)) - { - *pit1 = mult_r(*pit1,tmp3); - move16(); /*Q_syn */ - pit1++; + pit1 = &SWB_signal[368 + st_offset]; + move16(); + + test(); + IF( ( tmp2 == 0 ) || ( LT_16( tmp2, mult_r( tmp1, 9830 ) ) ) ) + { + tmp3 = 9830; + move16(); /*0.3 in Q15 */ + WHILE( LT_16( tmp3, 32767 ) ) + { + *pit1 = mult_r( *pit1, tmp3 ); + move16(); /*Q_syn */ + pit1++; #ifdef BASOP_NOGLOB - tmp3 = add_sat(tmp3, 3277); /*Q15 */ + tmp3 = add_sat( tmp3, 3277 ); /*Q15 */ #else - tmp3 = add(tmp3, 3277); /*Q15 */ + tmp3 = add( tmp3, 3277 ); /*Q15 */ #endif - } - } - ELSE IF(LT_16(tmp2, tmp1)) - { - exp = norm_s(tmp1); - tmp = div_s(shl(1,sub(14,exp)),tmp1); /*Q(29-exp) */ + } + } + ELSE IF( LT_16( tmp2, tmp1 ) ) + { + exp = norm_s( tmp1 ); + tmp = div_s( shl( 1, sub( 14, exp ) ), tmp1 ); /*Q(29-exp) */ #ifdef BASOP_NOGLOB - tmp3 = round_fx_sat(L_shl_sat(L_mult(tmp2,tmp),add(exp,2))); /*Q15 */ + tmp3 = round_fx_sat( L_shl_sat( L_mult( tmp2, tmp ), add( exp, 2 ) ) ); /*Q15 */ #else - tmp3 = round_fx(L_shl(L_mult(tmp2,tmp),add(exp,2))); /*Q15 */ + tmp3 = round_fx( L_shl( L_mult( tmp2, tmp ), add( exp, 2 ) ) ); /*Q15 */ #endif - WHILE(LT_16(tmp3, 32767)) - { - *pit1 = mult_r(*pit1,tmp3); - move16(); /*Q_syn */ - pit1++; + WHILE( LT_16( tmp3, 32767 ) ) + { + *pit1 = mult_r( *pit1, tmp3 ); + move16(); /*Q_syn */ + pit1++; #ifdef BASOP_NOGLOB - tmp3 = add_sat(tmp3,3277); /*Q15 */ + tmp3 = add_sat( tmp3, 3277 ); /*Q15 */ #else - tmp3 = add(tmp3,3277); /*Q15 */ + tmp3 = add( tmp3, 3277 ); /*Q15 */ #endif - } - } - - pit1 = &SWB_signal[367 + st_offset]; - move16(); - IF(GT_16(mult_r(tmp1,6554),tmp2)) - { - /*20480 = 5 in Q12 */ - FOR(tmp3 = 20480; tmp3 > 4096; tmp3 -= 2048) - { + } + } + + pit1 = &SWB_signal[367 + st_offset]; + move16(); + IF( GT_16( mult_r( tmp1, 6554 ), tmp2 ) ) + { + /*20480 = 5 in Q12 */ + FOR( tmp3 = 20480; tmp3 > 4096; tmp3 -= 2048 ) + { #ifdef BASOP_NOGLOB *pit1 = round_fx_sat( L_shl_sat( L_mult( *pit1, tmp3 ), 3 ) ); /*Q_syn */ #else - *pit1 = round_fx(L_shl(L_mult(*pit1,tmp3),3)); /*Q_syn */ + *pit1 = round_fx( L_shl( L_mult( *pit1, tmp3 ), 3 ) ); /*Q_syn */ #endif - pit1--; - } - } + pit1--; + } + } #ifdef BASOP_NOGLOB - tmp1 = add_sat(abs_s(SWB_signal[496 + st_offset]),abs_s(SWB_signal[497 + st_offset])); /*Q_syn */ - tmp2 = add_sat(add_sat(abs_s(SWB_signal[492 + st_offset]),abs_s(SWB_signal[493 + st_offset])),add_sat(abs_s(SWB_signal[494 + st_offset]),abs_s(SWB_signal[495 + st_offset]))); + tmp1 = add_sat( abs_s( SWB_signal[496 + st_offset] ), abs_s( SWB_signal[497 + st_offset] ) ); /*Q_syn */ + tmp2 = add_sat( add_sat( abs_s( SWB_signal[492 + st_offset] ), abs_s( SWB_signal[493 + st_offset] ) ), add_sat( abs_s( SWB_signal[494 + st_offset] ), abs_s( SWB_signal[495 + st_offset] ) ) ); #else - tmp1 = add(abs_s(SWB_signal[496 + st_offset]),abs_s(SWB_signal[497 + st_offset])); /*Q_syn */ - tmp2 = add(add(abs_s(SWB_signal[492 + st_offset]),abs_s(SWB_signal[493 + st_offset])),add(abs_s(SWB_signal[494 + st_offset]),abs_s(SWB_signal[495 + st_offset]))); + tmp1 = add( abs_s( SWB_signal[496 + st_offset] ), abs_s( SWB_signal[497 + st_offset] ) ); /*Q_syn */ + tmp2 = add( add( abs_s( SWB_signal[492 + st_offset] ), abs_s( SWB_signal[493 + st_offset] ) ), add( abs_s( SWB_signal[494 + st_offset] ), abs_s( SWB_signal[495 + st_offset] ) ) ); #endif - pit1 = &SWB_signal[496 + st_offset]; - move16(); - - test(); - IF((tmp2 == 0) || (LT_16(tmp2,mult_r(tmp1,9830)))) - { - tmp3 = 9830; - move16(); /*0.3 in Q15 */ - WHILE(LT_16(tmp3,32767)) - { - *pit1 = mult_r(*pit1,tmp3); - move16(); /*Q_syn */ - pit1++; + pit1 = &SWB_signal[496 + st_offset]; + move16(); + + test(); + IF( ( tmp2 == 0 ) || ( LT_16( tmp2, mult_r( tmp1, 9830 ) ) ) ) + { + tmp3 = 9830; + move16(); /*0.3 in Q15 */ + WHILE( LT_16( tmp3, 32767 ) ) + { + *pit1 = mult_r( *pit1, tmp3 ); + move16(); /*Q_syn */ + pit1++; #ifdef BASOP_NOGLOB - tmp3 = add_sat(tmp3, 3277); /*Q15 */ + tmp3 = add_sat( tmp3, 3277 ); /*Q15 */ #else - tmp3 = add(tmp3, 3277); /*Q15 */ + tmp3 = add( tmp3, 3277 ); /*Q15 */ #endif - } - } - ELSE IF(LT_16(tmp2,tmp1)) - { - exp = norm_s(tmp1); - tmp = div_s(shl(1,sub(14,exp)),tmp1); /*Q(29-exp) */ + } + } + ELSE IF( LT_16( tmp2, tmp1 ) ) + { + exp = norm_s( tmp1 ); + tmp = div_s( shl( 1, sub( 14, exp ) ), tmp1 ); /*Q(29-exp) */ #ifdef BASOP_NOGLOB - tmp3 = round_fx_sat(L_shl_sat(L_mult(tmp2,tmp),add(exp,2))); /*Q15 */ + tmp3 = round_fx_sat( L_shl_sat( L_mult( tmp2, tmp ), add( exp, 2 ) ) ); /*Q15 */ #else - tmp3 = round_fx(L_shl(L_mult(tmp2,tmp),add(exp,2))); /*Q15 */ + tmp3 = round_fx( L_shl( L_mult( tmp2, tmp ), add( exp, 2 ) ) ); /*Q15 */ #endif - WHILE(LT_16(tmp3,32767)) - { - *pit1 = mult_r(*pit1,tmp3); - move16();/*Q_syn */ - pit1++; + WHILE( LT_16( tmp3, 32767 ) ) + { + *pit1 = mult_r( *pit1, tmp3 ); + move16(); /*Q_syn */ + pit1++; #ifdef BASOP_NOGLOB - tmp3 = add_sat(tmp3, 3277); /*Q15 */ + tmp3 = add_sat( tmp3, 3277 ); /*Q15 */ #else - tmp3 = add(tmp3, 3277); /*Q15 */ + tmp3 = add( tmp3, 3277 ); /*Q15 */ #endif - } - } - pit1 = &SWB_signal[495 + st_offset]; - - L_tmp3 = L_deposit_h(tmp1); /*Q17 */ - L_tmp4 = Mult_32_16(L_tmp3,1638); /*Q17 */ - exp = 14; - move16(); - IF(tmp2 != 0) - { - exp = norm_s(tmp2); - tmp = div_s(shl(1,sub(14,exp)),tmp2); /*Q(29-exp) */ - L_tmp3 = L_shr(L_mult(tmp1,tmp),1); /*Q(30-exp+1)->Q(30-exp) (+1) due to *0.5 */ - L_tmp4 = Mult_32_16(L_tmp3,1638); /*Q(30-exp) */ - } - - L_tmp1 = L_shl(1L,sub(30,exp)); - WHILE(GT_32(L_tmp3,L_tmp1)) - { - L_tmp = Mult_32_16(L_tmp3,*pit1); /*Q(16-exp) */ - *pit1-- = round_fx(L_shl(L_tmp,exp)); /*Q_syn */ - L_tmp3 = L_sub(L_tmp3,L_tmp4); - } - - /* calculate envelope */ - calc_norm_envelop_fx(SWB_signal, envelope, L_swb_norm, SWB_flength, st_offset); - } - } - - /* Normalize with envelope */ - test(); - IF(*frica_flag == 0 && NE_16(mode, NOISE)) - { - L = add(swb_bwe_subband[0],st_offset); - exp = norm_s(L_swb_norm); - inv_L_swb_norm = shl(div_s(shl(1,sub(14,exp)),L_swb_norm),sub(exp,14)); /* Q15 */ - - IF(NE_16(mode,HARMONIC)) - { - tmp = add(shl(inv_L_swb_norm,1), inv_L_swb_norm); - weight = s_max(s_min(tmp,16384), 6554); - } - ELSE - { - weight = 6554; - move16(); - } - - weight = mac_r(L_mult(13107,weight) , 19661,(*prev_weight)); - - FOR(n_freq = L; n_freq < swb_bwe_subband[SWB_FENV] + st_offset; n_freq++) - { - signum[n_freq] = 1; - IF(SWB_signal[n_freq] < 0) - { - signum[n_freq] = -1; - move16(); - SWB_signal[n_freq] = negate(SWB_signal[n_freq]); - move16(); - } - L_tmp = Mult_32_16(envelope[n_freq],inv_L_swb_norm); /* Q_syn */ - L_tmp1 = L_deposit_l(SWB_signal[n_freq]); /* Q_syn */ - L_tmp = L_sub(L_tmp1,L_tmp); /* Q_syn */ - IF(L_tmp > 0) - { - tmp = shr(weight,1); /* Q14 */ - tmp = sub(19661,tmp); /* Q14 */ - SWB_signal[n_freq] = extract_l(L_shl(Mult_32_16(L_tmp,tmp),1)); /* Q_syn */ - } - ELSE - { - SWB_signal[n_freq] = extract_l(L_tmp); /* Q_syn */ - } - - IF(NE_16(signum[n_freq],1)) - { - SWB_signal[n_freq] = negate(SWB_signal[n_freq]); - move16(); - } - } - - tmp_exp = sub(15,Q_syn); - FOR(n_freq = L; n_freq < swb_bwe_subband[SWB_FENV] + st_offset; n_freq++) - { - IF(envelope[n_freq] != 0) - { - exp = norm_l(envelope[n_freq]); - tmp = extract_h(L_shl(envelope[n_freq], exp)); - exp = sub(sub(30,exp), Q_syn); - tmp = div_s(16384,tmp); /* Q(15+exp) */ - L_tmp = L_shr(L_mult0(SWB_signal[n_freq],tmp), add(exp,Q_syn)); /* Q15 */ - SWB_signal[n_freq] = extract_l(L_tmp); /* Q15 */ - } - ELSE - { - SWB_signal[n_freq] = shl(SWB_signal[n_freq], tmp_exp); - move16(); /* Q15 */ - } - } - *prev_weight = weight; - } - ELSE - { - exp = norm_s(L_swb_norm); - tmp = shl(div_s(shl(1,sub(14,exp)),L_swb_norm),sub(exp,14)); /* Q15 */ - tmp = add(shl(tmp,1),tmp); - *prev_weight = s_max(s_min(tmp,16384),6554); /* Q15 */ - } - - IF(EQ_16(mode,HARMONIC)) - { - pit1 = &SWB_signal[swb_bwe_subband[0] + st_offset]; - move16(); - FOR(n_band = 0; n_band < 19; n_band++) - { - L_mean = L_deposit_l(0); - FOR(n_freq = 0; n_freq < 16; n_freq++) - { - L_mean = L_add(L_mean,abs_s(*pit1)); /*Q15 */ - pit1++; - } - mean = extract_l(Mult_32_16(L_mean,2048)); /*Q15 */ - pit1 -= 16; - move16(); - FOR(n_freq = 0; n_freq < 16; n_freq++) - { - if (LT_16(abs_s(*pit1),mean)) - { - *pit1 = mult_r(*pit1,6554); /*Q15*/ move16(); - } - pit1++; - } - } - } - - L = 1; - move16(); - if (EQ_16(mode,HARMONIC)) - { - L = 2; - move16(); - } - - FOR(n_band = 0; n_band < SWB_FENV; n_band += L) - { - energy = L_deposit_l(0); - tmp = add(swb_bwe_subband[n_band + L],st_offset); - FOR(n_freq = add(swb_bwe_subband[n_band],st_offset); n_freq < tmp; n_freq++) - { - L_tmp = L_mult(SWB_signal[n_freq],SWB_signal[n_freq]); /*Q31 */ - energy = L_add(energy,L_shr(L_tmp,6)); /*Q25 */ - } - - IF(energy == 0) - { - tmp_ener = sqrt_swb_bwe_subband_fx_L1[n_band];/*Q12 */ move16(); - if (NE_16(L,1)) - { - tmp_ener = sqrt_swb_bwe_subband_fx_L2[shr(n_band, 1)];/*Q12 */ move16(); - } - - tmp = add(swb_bwe_subband[n_band + L],st_offset); - tmp_exp = sub(Q_syn,12); - FOR(n_freq = add(swb_bwe_subband[n_band],st_offset); n_freq < tmp; n_freq++) - { - SWB_signal_32[n_freq] = L_shl(L_mult(tmp_ener,SWB_signal[n_freq]),tmp_exp); /*Qsyn */ - } - } - ELSE - { - tmp = sub(swb_bwe_subband[n_band + L], swb_bwe_subband[n_band]); - exp1 = norm_s(tmp); - tmp = div_s(shl(1,sub(14,exp1)), tmp); /*Q(29-exp1) */ - energy = Mult_32_16(energy, tmp); /*Q(29-exp1+25-15)->Q(-exp1+39) */ - - exp = norm_l(energy); - L_tmp = L_shl(energy, exp); - /*exp = 31-exp-(-exp1+39);move16(); */ - exp = sub(sub(exp1,exp),8); - Ltmp_ener = Isqrt_lc(L_tmp, &exp); /*Q(31-exp) */ - - tmp = add(swb_bwe_subband[n_band + L],st_offset); - tmp_exp = add(Q_syn,sub(exp,15)); - FOR(n_freq = add(swb_bwe_subband[n_band],st_offset); n_freq < tmp; n_freq++) - { - SWB_signal_32[n_freq] = L_shl(Mult_32_16(Ltmp_ener,SWB_signal[n_freq]),tmp_exp); - move32();/*Qsyn+16 */ - } - } - } + } + } + pit1 = &SWB_signal[495 + st_offset]; + + L_tmp3 = L_deposit_h( tmp1 ); /*Q17 */ + L_tmp4 = Mult_32_16( L_tmp3, 1638 ); /*Q17 */ + exp = 14; + move16(); + IF( tmp2 != 0 ) + { + exp = norm_s( tmp2 ); + tmp = div_s( shl( 1, sub( 14, exp ) ), tmp2 ); /*Q(29-exp) */ + L_tmp3 = L_shr( L_mult( tmp1, tmp ), 1 ); /*Q(30-exp+1)->Q(30-exp) (+1) due to *0.5 */ + L_tmp4 = Mult_32_16( L_tmp3, 1638 ); /*Q(30-exp) */ + } + + L_tmp1 = L_shl( 1L, sub( 30, exp ) ); + WHILE( GT_32( L_tmp3, L_tmp1 ) ) + { + L_tmp = Mult_32_16( L_tmp3, *pit1 ); /*Q(16-exp) */ + *pit1-- = round_fx( L_shl( L_tmp, exp ) ); /*Q_syn */ + L_tmp3 = L_sub( L_tmp3, L_tmp4 ); + } + + /* calculate envelope */ + calc_norm_envelop_fx( SWB_signal, envelope, L_swb_norm, SWB_flength, st_offset ); + } + } + + /* Normalize with envelope */ + test(); + IF( *frica_flag == 0 && NE_16( mode, NOISE ) ) + { + L = add( swb_bwe_subband[0], st_offset ); + exp = norm_s( L_swb_norm ); + inv_L_swb_norm = shl( div_s( shl( 1, sub( 14, exp ) ), L_swb_norm ), sub( exp, 14 ) ); /* Q15 */ + + IF( NE_16( mode, HARMONIC ) ) + { + tmp = add( shl( inv_L_swb_norm, 1 ), inv_L_swb_norm ); + weight = s_max( s_min( tmp, 16384 ), 6554 ); + } + ELSE + { + weight = 6554; + move16(); + } + + weight = mac_r( L_mult( 13107, weight ), 19661, ( *prev_weight ) ); + + FOR( n_freq = L; n_freq < swb_bwe_subband[SWB_FENV] + st_offset; n_freq++ ) + { + signum[n_freq] = 1; + IF( SWB_signal[n_freq] < 0 ) + { + signum[n_freq] = -1; + move16(); + SWB_signal[n_freq] = negate( SWB_signal[n_freq] ); + move16(); + } + L_tmp = Mult_32_16( envelope[n_freq], inv_L_swb_norm ); /* Q_syn */ + L_tmp1 = L_deposit_l( SWB_signal[n_freq] ); /* Q_syn */ + L_tmp = L_sub( L_tmp1, L_tmp ); /* Q_syn */ + IF( L_tmp > 0 ) + { + tmp = shr( weight, 1 ); /* Q14 */ + tmp = sub( 19661, tmp ); /* Q14 */ + SWB_signal[n_freq] = extract_l( L_shl( Mult_32_16( L_tmp, tmp ), 1 ) ); /* Q_syn */ + } + ELSE + { + SWB_signal[n_freq] = extract_l( L_tmp ); /* Q_syn */ + } + + IF( NE_16( signum[n_freq], 1 ) ) + { + SWB_signal[n_freq] = negate( SWB_signal[n_freq] ); + move16(); + } + } + + tmp_exp = sub( 15, Q_syn ); + FOR( n_freq = L; n_freq < swb_bwe_subband[SWB_FENV] + st_offset; n_freq++ ){ + IF( envelope[n_freq] != 0 ){ + exp = norm_l( envelope[n_freq] ); + tmp = extract_h( L_shl( envelope[n_freq], exp ) ); + exp = sub( sub( 30, exp ), Q_syn ); + tmp = div_s( 16384, tmp ); /* Q(15+exp) */ + L_tmp = L_shr( L_mult0( SWB_signal[n_freq], tmp ), add( exp, Q_syn ) ); /* Q15 */ + SWB_signal[n_freq] = extract_l( L_tmp ); /* Q15 */ + } + ELSE + { + SWB_signal[n_freq] = shl( SWB_signal[n_freq], tmp_exp ); + move16(); /* Q15 */ + } + } + *prev_weight = weight; +} +ELSE +{ + exp = norm_s( L_swb_norm ); + tmp = shl( div_s( shl( 1, sub( 14, exp ) ), L_swb_norm ), sub( exp, 14 ) ); /* Q15 */ + tmp = add( shl( tmp, 1 ), tmp ); + *prev_weight = s_max( s_min( tmp, 16384 ), 6554 ); /* Q15 */ +} + +IF( EQ_16( mode, HARMONIC ) ) +{ + pit1 = &SWB_signal[swb_bwe_subband[0] + st_offset]; + move16(); + FOR( n_band = 0; n_band < 19; n_band++ ) + { + L_mean = L_deposit_l( 0 ); + FOR( n_freq = 0; n_freq < 16; n_freq++ ) + { + L_mean = L_add( L_mean, abs_s( *pit1 ) ); /*Q15 */ + pit1++; + } + mean = extract_l( Mult_32_16( L_mean, 2048 ) ); /*Q15 */ + pit1 -= 16; + move16(); + FOR( n_freq = 0; n_freq < 16; n_freq++ ) + { + if ( LT_16( abs_s( *pit1 ), mean ) ) + { + *pit1 = mult_r( *pit1, 6554 ); /*Q15*/ + move16(); + } + pit1++; + } + } +} + +L = 1; +move16(); +if ( EQ_16( mode, HARMONIC ) ) +{ + L = 2; + move16(); +} + +FOR( n_band = 0; n_band < SWB_FENV; n_band += L ) +{ + energy = L_deposit_l( 0 ); + tmp = add( swb_bwe_subband[n_band + L], st_offset ); + FOR( n_freq = add( swb_bwe_subband[n_band], st_offset ); n_freq < tmp; n_freq++ ) + { + L_tmp = L_mult( SWB_signal[n_freq], SWB_signal[n_freq] ); /*Q31 */ + energy = L_add( energy, L_shr( L_tmp, 6 ) ); /*Q25 */ + } + + IF( energy == 0 ) + { + tmp_ener = sqrt_swb_bwe_subband_fx_L1[n_band]; /*Q12 */ + move16(); + if ( NE_16( L, 1 ) ) + { + tmp_ener = sqrt_swb_bwe_subband_fx_L2[shr( n_band, 1 )]; /*Q12 */ + move16(); + } + + tmp = add( swb_bwe_subband[n_band + L], st_offset ); + tmp_exp = sub( Q_syn, 12 ); + FOR( n_freq = add( swb_bwe_subband[n_band], st_offset ); n_freq < tmp; n_freq++ ) + { + SWB_signal_32[n_freq] = L_shl( L_mult( tmp_ener, SWB_signal[n_freq] ), tmp_exp ); /*Qsyn */ + } + } + ELSE + { + tmp = sub( swb_bwe_subband[n_band + L], swb_bwe_subband[n_band] ); + exp1 = norm_s( tmp ); + tmp = div_s( shl( 1, sub( 14, exp1 ) ), tmp ); /*Q(29-exp1) */ + energy = Mult_32_16( energy, tmp ); /*Q(29-exp1+25-15)->Q(-exp1+39) */ + + exp = norm_l( energy ); + L_tmp = L_shl( energy, exp ); + /*exp = 31-exp-(-exp1+39);move16(); */ + exp = sub( sub( exp1, exp ), 8 ); + Ltmp_ener = Isqrt_lc( L_tmp, &exp ); /*Q(31-exp) */ + + tmp = add( swb_bwe_subband[n_band + L], st_offset ); + tmp_exp = add( Q_syn, sub( exp, 15 ) ); + FOR( n_freq = add( swb_bwe_subband[n_band], st_offset ); n_freq < tmp; n_freq++ ) + { + SWB_signal_32[n_freq] = L_shl( Mult_32_16( Ltmp_ener, SWB_signal[n_freq] ), tmp_exp ); + move32(); /*Qsyn+16 */ + } + } +} #ifdef BASOP_NOGLOB - IF(GT_16(*prev_Energy,add_sat(Energy_16,shr(Energy_16,2))) && Energy_16 > 0) +IF( GT_16( *prev_Energy, add_sat( Energy_16, shr( Energy_16, 2 ) ) ) && Energy_16 > 0 ) #else - IF(GT_16(*prev_Energy,add(Energy_16,shr(Energy_16,2))) && Energy_16 > 0) +IF( GT_16( *prev_Energy, add( Energy_16, shr( Energy_16, 2 ) ) ) && Energy_16 > 0 ) #endif - { - weight = shr(div_s(Energy_16,*prev_Energy),1); /*Q15 */ - } - ELSE - { - weight = 16384; - move16();/*Q15 */ - } - L_tmp = L_mult(weight, prev_SWB_fenv[0]); /*Q17 */ - L_tmp = L_mac(L_tmp, sub(32767, weight), SWB_fenv[0]);/*Q17 */ - wfenv = round_fx(L_tmp); /*Q1 */ - - tmp = norm_s(wfenv); - IF(GT_16(tmp,4)) - { - tmp = 12; - move16(); - factor = fenvL_16; - move16();/*Q3 */ - factor1 = mult_r(sub(shl(wfenv,2),fenvL_16),4096); /*Q3 */ - } - ELSE - { - tmp = 14; - move16(); - factor = shr(fenvL_16,2);/*Q1 */ - factor1 = mult_r(sub(wfenv,factor), 4096); /*Q1 */ - } - - tmp2 = add(add(swb_bwe_subband[0],8),st_offset); - FOR(n_freq = add(swb_bwe_subband[0],st_offset); n_freq < tmp2; n_freq++) - { - L_tmp1 = Mult_32_16(SWB_signal_32[n_freq], factor); +{ + weight = shr( div_s( Energy_16, *prev_Energy ), 1 ); /*Q15 */ +} +ELSE +{ + weight = 16384; + move16(); /*Q15 */ +} +L_tmp = L_mult( weight, prev_SWB_fenv[0] ); /*Q17 */ +L_tmp = L_mac( L_tmp, sub( 32767, weight ), SWB_fenv[0] ); /*Q17 */ +wfenv = round_fx( L_tmp ); /*Q1 */ + +tmp = norm_s( wfenv ); +IF( GT_16( tmp, 4 ) ) +{ + tmp = 12; + move16(); + factor = fenvL_16; + move16(); /*Q3 */ + factor1 = mult_r( sub( shl( wfenv, 2 ), fenvL_16 ), 4096 ); /*Q3 */ +} +ELSE +{ + tmp = 14; + move16(); + factor = shr( fenvL_16, 2 ); /*Q1 */ + factor1 = mult_r( sub( wfenv, factor ), 4096 ); /*Q1 */ +} + +tmp2 = add( add( swb_bwe_subband[0], 8 ), st_offset ); +FOR( n_freq = add( swb_bwe_subband[0], st_offset ); n_freq < tmp2; n_freq++ ) +{ + L_tmp1 = Mult_32_16( SWB_signal_32[n_freq], factor ); #ifdef BASOP_NOGLOB - SWB_signal_32[n_freq] = L_shl_sat( L_tmp1, tmp - 1 ); + SWB_signal_32[n_freq] = L_shl_sat( L_tmp1, tmp - 1 ); #else - SWB_signal_32[n_freq] = L_shl(L_tmp1, tmp - 1); + SWB_signal_32[n_freq] = L_shl( L_tmp1, tmp - 1 ); #endif - move32();/*15+Qsyn */ - factor = add(factor, factor1); /*Q3 */ - } - - FOR(n_band = 0; n_band < 12; n_band++) - { - L_tmp = L_mult(weight, prev_SWB_fenv[n_band + 1]); /*Q17 */ - L_tmp = L_mac(L_tmp, sub(32767,weight), SWB_fenv[n_band + 1]);/*Q17 */ - wfenv = round_fx(L_tmp); /*Q1 */ - factor = SWB_fenv[n_band]; - move16(); /*Q1 */ - factor1 = mult_r(sub(wfenv,SWB_fenv[n_band]), smooth_factor_fx[n_band]); /*Q1 */ - tmp = norm_s(factor); - IF(GT_16(tmp,4)) - { - tmp = 12; - move16(); - factor = shl(factor, 2); - factor1 = shl(factor1, 2); - } - ELSE - { - tmp = 14; - move16(); - } - - tmp2 = add(swb_bwe_sm_subband[n_band + 1],st_offset); - FOR(; n_freq < tmp2; n_freq++) - { - L_tmp1 = Mult_32_16(SWB_signal_32[n_freq], factor); + move32(); /*15+Qsyn */ + factor = add( factor, factor1 ); /*Q3 */ +} + +FOR( n_band = 0; n_band < 12; n_band++ ) +{ + L_tmp = L_mult( weight, prev_SWB_fenv[n_band + 1] ); /*Q17 */ + L_tmp = L_mac( L_tmp, sub( 32767, weight ), SWB_fenv[n_band + 1] ); /*Q17 */ + wfenv = round_fx( L_tmp ); /*Q1 */ + factor = SWB_fenv[n_band]; + move16(); /*Q1 */ + factor1 = mult_r( sub( wfenv, SWB_fenv[n_band] ), smooth_factor_fx[n_band] ); /*Q1 */ + tmp = norm_s( factor ); + IF( GT_16( tmp, 4 ) ) + { + tmp = 12; + move16(); + factor = shl( factor, 2 ); + factor1 = shl( factor1, 2 ); + } + ELSE + { + tmp = 14; + move16(); + } + + tmp2 = add( swb_bwe_sm_subband[n_band + 1], st_offset ); + FOR( ; n_freq < tmp2; n_freq++ ) + { + L_tmp1 = Mult_32_16( SWB_signal_32[n_freq], factor ); #ifdef BASOP_NOGLOB - SWB_signal_32[n_freq] = L_shl_sat( L_tmp1, tmp - 1 ); + SWB_signal_32[n_freq] = L_shl_sat( L_tmp1, tmp - 1 ); #else - SWB_signal_32[n_freq] = L_shl(L_tmp1, tmp - 1); + SWB_signal_32[n_freq] = L_shl( L_tmp1, tmp - 1 ); #endif - move32(); /*15+Qsyn */ + move32(); /*15+Qsyn */ #ifdef BASOP_NOGLOB - factor = add_sat( factor, factor1 ); /*Q1 */ + factor = add_sat( factor, factor1 ); /*Q1 */ #else - factor = add(factor, factor1); /*Q1 */ + factor = add( factor, factor1 ); /*Q1 */ #endif - } - } - L_tmp = L_mult(weight, prev_SWB_fenv[13]); /*Q17 */ - L_tmp = L_mac(L_tmp,sub(32767,weight), SWB_fenv[13]);/*Q17 */ - wfenv = round_fx(L_tmp); /*Q1 */ - factor = SWB_fenv[12]; - move16();/*Q1 */ - factor1 = mult_r(sub(wfenv, SWB_fenv[12]), smooth_factor_fx[12]); /*Q1 */ - tmp2 = add(swb_bwe_sm_subband[13],st_offset); - FOR(; n_freq < tmp2; n_freq++) - { - L_tmp1 = Mult_32_16(SWB_signal_32[n_freq], factor); + } +} +L_tmp = L_mult( weight, prev_SWB_fenv[13] ); /*Q17 */ +L_tmp = L_mac( L_tmp, sub( 32767, weight ), SWB_fenv[13] ); /*Q17 */ +wfenv = round_fx( L_tmp ); /*Q1 */ +factor = SWB_fenv[12]; +move16(); /*Q1 */ +factor1 = mult_r( sub( wfenv, SWB_fenv[12] ), smooth_factor_fx[12] ); /*Q1 */ +tmp2 = add( swb_bwe_sm_subband[13], st_offset ); +FOR( ; n_freq < tmp2; n_freq++ ) +{ + L_tmp1 = Mult_32_16( SWB_signal_32[n_freq], factor ); #ifdef BASOP_NOGLOB - SWB_signal_32[n_freq] = L_shl_sat( L_tmp1, 13 ); + SWB_signal_32[n_freq] = L_shl_sat( L_tmp1, 13 ); #else - SWB_signal_32[n_freq] = L_shl(L_tmp1,13); + SWB_signal_32[n_freq] = L_shl( L_tmp1, 13 ); #endif - move32();/*15+Qsyn */ - factor = add(factor,factor1); /*Q1 */ - } - - FOR(n_band = 13; n_band < SWB_FENV; n_band++) - { - L_tmp = L_mult(weight, prev_SWB_fenv[n_band]); /*Q17 */ - L_tmp = L_mac(L_tmp,sub(32767, weight), SWB_fenv[n_band]);/*Q17 */ - wfenv = round_fx(L_tmp); /*Q1 */ - tmp2 = add(swb_bwe_subband[n_band + 1],st_offset); - FOR(; n_freq < tmp2; n_freq++) - { - L_tmp1 = Mult_32_16(SWB_signal_32[n_freq], factor); + move32(); /*15+Qsyn */ + factor = add( factor, factor1 ); /*Q1 */ +} + +FOR( n_band = 13; n_band < SWB_FENV; n_band++ ) +{ + L_tmp = L_mult( weight, prev_SWB_fenv[n_band] ); /*Q17 */ + L_tmp = L_mac( L_tmp, sub( 32767, weight ), SWB_fenv[n_band] ); /*Q17 */ + wfenv = round_fx( L_tmp ); /*Q1 */ + tmp2 = add( swb_bwe_subband[n_band + 1], st_offset ); + FOR( ; n_freq < tmp2; n_freq++ ) + { + L_tmp1 = Mult_32_16( SWB_signal_32[n_freq], factor ); #ifdef BASOP_NOGLOB - SWB_signal_32[n_freq] = L_shl_sat( L_tmp1, 13 ); + SWB_signal_32[n_freq] = L_shl_sat( L_tmp1, 13 ); #else - SWB_signal_32[n_freq] = L_shl(L_tmp1,13); + SWB_signal_32[n_freq] = L_shl( L_tmp1, 13 ); #endif - move32(); /*15+Qsyn */ - } - } - FOR(n_band = 0; n_band < SWB_FENV; n_band++) - { - prev_SWB_fenv[n_band] = SWB_fenv[n_band]; - move16();/*Q1 */ - } - } - pit1_32 = &SWB_signal_32[240 + st_offset]; /*15+Qsyn */ - FOR(n_freq = 0; n_freq < 4; n_freq++) - { - L_tmp1 = Mult_32_16(*pit1_32, 16384); /*15+Qsyn */ - *(pit1_32++) = L_tmp1; - move32(); - } - *prev_Energy = Energy_16; - move16(); - - return; + move32(); /*15+Qsyn */ + } +} +FOR( n_band = 0; n_band < SWB_FENV; n_band++ ) +{ + prev_SWB_fenv[n_band] = SWB_fenv[n_band]; + move16(); /*Q1 */ +} +} +pit1_32 = &SWB_signal_32[240 + st_offset]; /*15+Qsyn */ +FOR( n_freq = 0; n_freq < 4; n_freq++ ) +{ + L_tmp1 = Mult_32_16( *pit1_32, 16384 ); /*15+Qsyn */ + *( pit1_32++ ) = L_tmp1; + move32(); +} +*prev_Energy = Energy_16; +move16(); + +return; } /*==========================================================================*/ @@ -2103,95 +2107,94 @@ void SWB_BWE_decoding_fx( /* _ None */ /*--------------------------------------------------------------------------*/ void time_envelop_shaping_fx( - Word16 werr[], /* i/o: SHB synthesis Q_synth*/ - Word32 SWB_tenv[], /* i/o: frequency envelope Q15*/ - const Word16 L, /* i : frame length */ - Word16 *Q_synth -) + Word16 werr[], /* i/o: SHB synthesis Q_synth*/ + Word32 SWB_tenv[], /* i/o: frequency envelope Q15*/ + const Word16 L, /* i : frame length */ + Word16 *Q_synth ) { - Word16 *pit; - Word32 Energy; - Word16 i, j; - Word16 tmp_ener, Energy_16; - Word16 exp_L, exp, frac, tmp, inv_L; - Word32 L_tmp; - - pit = werr; - move16(); - exp_L = norm_s(L); - inv_L = div_s(shl(1, sub(14, exp_L)), L); /*Q(29-exp_L) */ - FOR(i = 0; i < SWB_TENV; i++) - { - Energy = L_deposit_l(0); - FOR(j = 0; j < L / 4; j++) - { -#ifdef BASOP_NOGLOB - Energy = L_mac0_sat(Energy, *pit, *pit); /*(2*Q_synth) */ -#else - Energy = L_mac0(Energy, *pit, *pit); /*(2*Q_synth) */ -#endif - pit++; - } - Energy = Mult_32_16(Energy, inv_L); /*Q(29-exp_L-15) -> Q(-exp_L+14+2*Q_synth) */ - Energy_16 = 0; - move16(); - /*exp = 31-(-exp_L+14 +(2*(*Q_synth))); */ - exp = sub(17, sub(shl((*Q_synth), 1), exp_L)); - - IF(Energy != 0) - { - exp = norm_l(Energy); - frac = extract_h(L_shl(Energy, exp)); - /*exp = sub(exp, 30-(-exp_L+14-2+(2*(*Q_synth)))); */ - exp = sub(exp, sub(30, add(sub(shl((*Q_synth), 1), exp_L), 14 - 2))); - - tmp = div_s(16384, frac); - L_tmp = L_deposit_h(tmp); - Energy = Isqrt_lc(L_tmp, &exp); /*Q(31-exp) */ - Energy_16 = round_fx(L_shl(Energy, sub(exp, 15))); /*Q0 */ - } - - test(); + Word16 *pit; + Word32 Energy; + Word16 i, j; + Word16 tmp_ener, Energy_16; + Word16 exp_L, exp, frac, tmp, inv_L; + Word32 L_tmp; + + pit = werr; + move16(); + exp_L = norm_s( L ); + inv_L = div_s( shl( 1, sub( 14, exp_L ) ), L ); /*Q(29-exp_L) */ + FOR( i = 0; i < SWB_TENV; i++ ) + { + Energy = L_deposit_l( 0 ); + FOR( j = 0; j < L / 4; j++ ) + { #ifdef BASOP_NOGLOB - IF(LT_32(SWB_tenv[i], 65536) && LT_32(Energy, L_shl_sat(SWB_tenv[i], sub(16, exp)))) + Energy = L_mac0_sat( Energy, *pit, *pit ); /*(2*Q_synth) */ #else - IF(LT_32(SWB_tenv[i], 65536) && LT_32(Energy, L_shl(SWB_tenv[i], sub(16, exp)))) + Energy = L_mac0( Energy, *pit, *pit ); /*(2*Q_synth) */ #endif - { - *Q_synth = add(*Q_synth, 3); - move16(); - } - ELSE - { - pit -= L / 4; - move16(); - tmp_ener = 0; - move16(); - exp = 0; - move16(); - - IF(Energy_16 != 0) - { - exp = norm_s(Energy_16); - tmp_ener = div_s(shl(1,sub(14,exp)), Energy_16); /*Q(29-exp) */ - } - - L_tmp = Mult_32_16(SWB_tenv[i], tmp_ener); /*Q(29-exp) */ - tmp = round_fx(L_tmp); /*Q(13-exp) */ - - FOR(j = 0; j < L / 4; j++) - { -#ifdef BASOP_NOGLOB - *pit = round_fx_sat(L_shl_sat(L_mult(tmp, *pit), sub(exp,1))); /*Q(13-exp+1)->Q(14-exp)->Qsyn-3 */ + pit++; + } + Energy = Mult_32_16( Energy, inv_L ); /*Q(29-exp_L-15) -> Q(-exp_L+14+2*Q_synth) */ + Energy_16 = 0; + move16(); + /*exp = 31-(-exp_L+14 +(2*(*Q_synth))); */ + exp = sub( 17, sub( shl( ( *Q_synth ), 1 ), exp_L ) ); + + IF( Energy != 0 ) + { + exp = norm_l( Energy ); + frac = extract_h( L_shl( Energy, exp ) ); + /*exp = sub(exp, 30-(-exp_L+14-2+(2*(*Q_synth)))); */ + exp = sub( exp, sub( 30, add( sub( shl( ( *Q_synth ), 1 ), exp_L ), 14 - 2 ) ) ); + + tmp = div_s( 16384, frac ); + L_tmp = L_deposit_h( tmp ); + Energy = Isqrt_lc( L_tmp, &exp ); /*Q(31-exp) */ + Energy_16 = round_fx( L_shl( Energy, sub( exp, 15 ) ) ); /*Q0 */ + } + + test(); +#ifdef BASOP_NOGLOB + IF( LT_32( SWB_tenv[i], 65536 ) && LT_32( Energy, L_shl_sat( SWB_tenv[i], sub( 16, exp ) ) ) ) #else - *pit = round_fx(L_shl(L_mult(tmp, *pit), sub(exp,1))); /*Q(13-exp+1)->Q(14-exp)->Qsyn-3 */ + IF( LT_32( SWB_tenv[i], 65536 ) && LT_32( Energy, L_shl( SWB_tenv[i], sub( 16, exp ) ) ) ) #endif - pit++; - } - } - } + { + *Q_synth = add( *Q_synth, 3 ); + move16(); + } + ELSE + { + pit -= L / 4; + move16(); + tmp_ener = 0; + move16(); + exp = 0; + move16(); + + IF( Energy_16 != 0 ) + { + exp = norm_s( Energy_16 ); + tmp_ener = div_s( shl( 1, sub( 14, exp ) ), Energy_16 ); /*Q(29-exp) */ + } + + L_tmp = Mult_32_16( SWB_tenv[i], tmp_ener ); /*Q(29-exp) */ + tmp = round_fx( L_tmp ); /*Q(13-exp) */ + + FOR( j = 0; j < L / 4; j++ ) + { +#ifdef BASOP_NOGLOB + *pit = round_fx_sat( L_shl_sat( L_mult( tmp, *pit ), sub( exp, 1 ) ) ); /*Q(13-exp+1)->Q(14-exp)->Qsyn-3 */ +#else + *pit = round_fx( L_shl( L_mult( tmp, *pit ), sub( exp, 1 ) ) ); /*Q(13-exp+1)->Q(14-exp)->Qsyn-3 */ +#endif + pit++; + } + } + } - return; + return; } /*==========================================================================*/ @@ -2215,187 +2218,186 @@ void time_envelop_shaping_fx( /* _ None */ /*--------------------------------------------------------------------------*/ void time_reduce_pre_echo_fx( - const Word16 *synth, /* i : ACELP core synthesis Q_syn*/ - Word16 *error, /* i/o: SHB BWE synthesis Q0*/ - Word16 prev_td_energy, /* o : last td energy Q0*/ - const Word16 L, /* i : subframe length */ - Word16 Q_syn, - Word16 Q_synth -) + const Word16 *synth, /* i : ACELP core synthesis Q_syn*/ + Word16 *error, /* i/o: SHB BWE synthesis Q0*/ + Word16 prev_td_energy, /* o : last td energy Q0*/ + const Word16 L, /* i : subframe length */ + Word16 Q_syn, + Word16 Q_synth ) { - Word16 i, j, pos = 0, Len; - Word32 energy; - Word16 energy_16; - Word32 energyL[4]; - Word16 tmp_ener; - Word16 *pit; - Word16 tmpi, tmp_exp; - Word16 exp_L, exp, frac, inv_L, exp_j, tmp; - Word32 L_tmp, L_tmp1, Ltmp_ener; - - exp_L = norm_s(L); - inv_L = div_s(shl(1, sub(14, exp_L)), L); /*Q(29-exp_L) */ - FOR(i = 0; i < 4; i++) - { - Len = i_mult(L, i); - - L_tmp = L_deposit_l(0); - FOR(j = 0; j < L; j++) - { + Word16 i, j, pos = 0, Len; + Word32 energy; + Word16 energy_16; + Word32 energyL[4]; + Word16 tmp_ener; + Word16 *pit; + Word16 tmpi, tmp_exp; + Word16 exp_L, exp, frac, inv_L, exp_j, tmp; + Word32 L_tmp, L_tmp1, Ltmp_ener; + + exp_L = norm_s( L ); + inv_L = div_s( shl( 1, sub( 14, exp_L ) ), L ); /*Q(29-exp_L) */ + FOR( i = 0; i < 4; i++ ) + { + Len = i_mult( L, i ); + + L_tmp = L_deposit_l( 0 ); + FOR( j = 0; j < L; j++ ) + { #ifdef BASOP_NOGLOB - L_tmp = L_mac0_sat( L_tmp, synth[Len + j], synth[Len + j] ); /*2*Q_syn */ + L_tmp = L_mac0_sat( L_tmp, synth[Len + j], synth[Len + j] ); /*2*Q_syn */ #else - L_tmp = L_mac0(L_tmp, synth[Len + j], synth[Len + j]); /*2*Q_syn */ + L_tmp = L_mac0( L_tmp, synth[Len + j], synth[Len + j] ); /*2*Q_syn */ #endif - } - energyL[i] = Mult_32_16(L_shr(L_tmp, sub(14, exp_L)), inv_L); - move32(); /*Q(2*Q_syn +29-exp_L-15 - (14-exp_L) ) -> Q(2*Q_syn) */ - - IF(energyL[i] != 0) - { - exp = norm_l(energyL[i]); - frac = extract_h(L_shl(energyL[i], exp)); - exp = sub(exp, sub(30, shl(Q_syn, 1))); - - tmp = div_s(16384, frac); - L_tmp = L_deposit_h(tmp); - L_tmp = Isqrt_lc(L_tmp, &exp); - energyL[i] = L_shl(L_tmp, sub(exp, 16)); - move32();/* Q15 */ - } - } - - FOR(i = 0; i < 3; i++) - { - L_tmp = Mult_32_16(energyL[i], 29491); /*Q14 */ - test(); - IF(GT_32(L_shr(energyL[i + 1], 1), L_tmp) && GT_32(energyL[i + 1], 1638400)) - { - pos = add(i, 1); - move16(); - BREAK; - } - } - - IF(pos > 0) - { - if (LT_16(pos, 3)) - { - pos = add(pos, 1); - } - energy = L_deposit_l(0); - j = i_mult(L, pos); - move16(); - FOR(i = 0; i < j; i++) - { + } + energyL[i] = Mult_32_16( L_shr( L_tmp, sub( 14, exp_L ) ), inv_L ); + move32(); /*Q(2*Q_syn +29-exp_L-15 - (14-exp_L) ) -> Q(2*Q_syn) */ + + IF( energyL[i] != 0 ) + { + exp = norm_l( energyL[i] ); + frac = extract_h( L_shl( energyL[i], exp ) ); + exp = sub( exp, sub( 30, shl( Q_syn, 1 ) ) ); + + tmp = div_s( 16384, frac ); + L_tmp = L_deposit_h( tmp ); + L_tmp = Isqrt_lc( L_tmp, &exp ); + energyL[i] = L_shl( L_tmp, sub( exp, 16 ) ); + move32(); /* Q15 */ + } + } + + FOR( i = 0; i < 3; i++ ) + { + L_tmp = Mult_32_16( energyL[i], 29491 ); /*Q14 */ + test(); + IF( GT_32( L_shr( energyL[i + 1], 1 ), L_tmp ) && GT_32( energyL[i + 1], 1638400 ) ) + { + pos = add( i, 1 ); + move16(); + BREAK; + } + } + + IF( pos > 0 ) + { + if ( LT_16( pos, 3 ) ) + { + pos = add( pos, 1 ); + } + energy = L_deposit_l( 0 ); + j = i_mult( L, pos ); + move16(); + FOR( i = 0; i < j; i++ ) + { #ifdef BASOP_NOGLOB - energy = L_mac0_sat(energy, error[i], error[i]); /*Q(2*Q_synth) */ + energy = L_mac0_sat( energy, error[i], error[i] ); /*Q(2*Q_synth) */ #else - energy = L_mac0(energy, error[i], error[i]); /*Q(2*Q_synth) */ + energy = L_mac0( energy, error[i], error[i] ); /*Q(2*Q_synth) */ #endif - } - - exp_j = norm_s(j); - tmp = div_s(shl(1, sub(14, exp_j)), j); /*Q(29-exp_j) */ - energy = Mult_32_16(energy, tmp); /*Q(29-exp_j+1-16) -> Q(-exp_j+14 +2*Q_synth) */ - energy_16 = 0; - move16(); - - IF(energy != 0) - { - exp = norm_l(energy); - frac = extract_h(L_shl(energy, exp)); - /*exp = sub(exp, 30-(-exp_j+14 +2*Q_synth)); */ - exp = sub(exp, sub(14, sub(shl(Q_synth, 1), exp_j))); - tmp = div_s(16384, frac); - L_tmp = L_deposit_h(tmp); - energy = Isqrt_lc(L_tmp, &exp); /*Q(31-exp) */ - energy_16 = round_fx(L_shl(energy, sub(exp, 15))); /*Q0 */ - } - - tmp = mult_r(energy_16, 6554); /*Q0 */ - if (LT_16(prev_td_energy, tmp)) - { - prev_td_energy = tmp; - move16(); - } - - tmp_ener = 0; - move16(); - exp = 0; - move16(); - IF(energy_16 != 0) - { - exp = norm_s(energy_16); - tmp_ener = div_s(shl(1, sub(14, exp)), energy_16); /*Q(29-exp) */ - } - L_tmp = L_mult(prev_td_energy, tmp_ener); /*Q(30-exp) */ - tmp_exp = add(1, exp); - FOR(i = 0; i < j; i++) - { + } + + exp_j = norm_s( j ); + tmp = div_s( shl( 1, sub( 14, exp_j ) ), j ); /*Q(29-exp_j) */ + energy = Mult_32_16( energy, tmp ); /*Q(29-exp_j+1-16) -> Q(-exp_j+14 +2*Q_synth) */ + energy_16 = 0; + move16(); + + IF( energy != 0 ) + { + exp = norm_l( energy ); + frac = extract_h( L_shl( energy, exp ) ); + /*exp = sub(exp, 30-(-exp_j+14 +2*Q_synth)); */ + exp = sub( exp, sub( 14, sub( shl( Q_synth, 1 ), exp_j ) ) ); + tmp = div_s( 16384, frac ); + L_tmp = L_deposit_h( tmp ); + energy = Isqrt_lc( L_tmp, &exp ); /*Q(31-exp) */ + energy_16 = round_fx( L_shl( energy, sub( exp, 15 ) ) ); /*Q0 */ + } + + tmp = mult_r( energy_16, 6554 ); /*Q0 */ + if ( LT_16( prev_td_energy, tmp ) ) + { + prev_td_energy = tmp; + move16(); + } + + tmp_ener = 0; + move16(); + exp = 0; + move16(); + IF( energy_16 != 0 ) + { + exp = norm_s( energy_16 ); + tmp_ener = div_s( shl( 1, sub( 14, exp ) ), energy_16 ); /*Q(29-exp) */ + } + L_tmp = L_mult( prev_td_energy, tmp_ener ); /*Q(30-exp) */ + tmp_exp = add( 1, exp ); + FOR( i = 0; i < j; i++ ) + { #ifdef BASOP_NOGLOB - error[i] = round_fx_sat(L_shl_sat(Mult_32_16(L_tmp, error[i]), tmp_exp)); /*Q(30-exp+1-16)->Q(15-exp)->Q_synth */ + error[i] = round_fx_sat( L_shl_sat( Mult_32_16( L_tmp, error[i] ), tmp_exp ) ); /*Q(30-exp+1-16)->Q(15-exp)->Q_synth */ #else - error[i] = round_fx(L_shl(Mult_32_16(L_tmp, error[i]), tmp_exp)); /*Q(30-exp+1-16)->Q(15-exp)->Q_synth */ + error[i] = round_fx( L_shl( Mult_32_16( L_tmp, error[i] ), tmp_exp ) ); /*Q(30-exp+1-16)->Q(15-exp)->Q_synth */ #endif - } + } - energy = L_deposit_l(0); - FOR(i = j; i < (j + L); i++) - { + energy = L_deposit_l( 0 ); + FOR( i = j; i < ( j + L ); i++ ) + { #ifdef BASOP_NOGLOB - energy = L_mac0_sat(energy, error[i], error[i]); /*(2*Q_synth) */ + energy = L_mac0_sat( energy, error[i], error[i] ); /*(2*Q_synth) */ #else - energy = L_mac0(energy, error[i], error[i]); /*(2*Q_synth) */ + energy = L_mac0( energy, error[i], error[i] ); /*(2*Q_synth) */ #endif - } - - energy = Mult_32_16(energy, inv_L); /*Q(29-exp_L+1-16) -> Q(-exp_L+14) */ - energy_16 = 0; - move16(); - IF(energy != 0) - { - exp = norm_l(energy); - frac = extract_h(L_shl(energy, exp)); - /*exp = sub(exp, 30-(-exp_L+14+2*Q_synth)); */ - exp = sub(exp, sub(14, sub(shl(Q_synth, 1), exp_L))); - - tmp = div_s(16384, frac); - L_tmp = L_deposit_h(tmp); - energy = Isqrt_lc(L_tmp, &exp); /*Q(31-exp) */ - energy_16 = round_fx(L_shl(energy, sub(exp, 15))); /*Q0 */ - } - - tmp_ener = 0; - move16(); - exp = 0; - move16(); - IF(energy_16 != 0) - { - exp = norm_s(energy_16); - tmp_ener = div_s(shl(1, sub(14, exp)), energy_16); /*Q(29-exp) */ - } - Ltmp_ener = L_mult(prev_td_energy, tmp_ener); /*Q(30-exp) */ - L_tmp1 = L_shl(1, sub(30, exp)); - - pit = &error[j]; - move16(); - FOR(i = 0; i < L; i++) - { - tmpi = round_fx(L_shl(L_mult(i, inv_L), add(1, exp_L))); /*Q15 */ - L_tmp = L_sub(L_tmp1, Ltmp_ener); /*Q(30-exp) */ - L_tmp = Mult_32_16(L_tmp, tmpi); /*Q(30-exp) */ - L_tmp = L_add(Ltmp_ener, L_tmp); /*Q(30-exp) */ + } + + energy = Mult_32_16( energy, inv_L ); /*Q(29-exp_L+1-16) -> Q(-exp_L+14) */ + energy_16 = 0; + move16(); + IF( energy != 0 ) + { + exp = norm_l( energy ); + frac = extract_h( L_shl( energy, exp ) ); + /*exp = sub(exp, 30-(-exp_L+14+2*Q_synth)); */ + exp = sub( exp, sub( 14, sub( shl( Q_synth, 1 ), exp_L ) ) ); + + tmp = div_s( 16384, frac ); + L_tmp = L_deposit_h( tmp ); + energy = Isqrt_lc( L_tmp, &exp ); /*Q(31-exp) */ + energy_16 = round_fx( L_shl( energy, sub( exp, 15 ) ) ); /*Q0 */ + } + + tmp_ener = 0; + move16(); + exp = 0; + move16(); + IF( energy_16 != 0 ) + { + exp = norm_s( energy_16 ); + tmp_ener = div_s( shl( 1, sub( 14, exp ) ), energy_16 ); /*Q(29-exp) */ + } + Ltmp_ener = L_mult( prev_td_energy, tmp_ener ); /*Q(30-exp) */ + L_tmp1 = L_shl( 1, sub( 30, exp ) ); + + pit = &error[j]; + move16(); + FOR( i = 0; i < L; i++ ) + { + tmpi = round_fx( L_shl( L_mult( i, inv_L ), add( 1, exp_L ) ) ); /*Q15 */ + L_tmp = L_sub( L_tmp1, Ltmp_ener ); /*Q(30-exp) */ + L_tmp = Mult_32_16( L_tmp, tmpi ); /*Q(30-exp) */ + L_tmp = L_add( Ltmp_ener, L_tmp ); /*Q(30-exp) */ #ifdef BASOP_NOGLOB tmp = round_fx_sat( L_shl_sat( Mult_32_16( L_tmp, *pit ), add( 1, exp ) ) ); /*Q0 */ #else - tmp = round_fx(L_shl(Mult_32_16(L_tmp, *pit), add(1, exp))); /*Q0 */ + tmp = round_fx( L_shl( Mult_32_16( L_tmp, *pit ), add( 1, exp ) ) ); /*Q0 */ #endif - *pit++ = tmp; - } - } + *pit++ = tmp; + } + } - return; + return; } /*-------------------------------------------------------------------* @@ -2403,123 +2405,123 @@ void time_reduce_pre_echo_fx( * *-------------------------------------------------------------------*/ void calc_normal_length_fx_32( - const Word16 core, /* i : core : Q0 */ - const Word32 *sp, /* i : input signal : Q12 */ - const Word16 mode, /* i : input mode : Q0 */ - const Word16 extl, /* i : extension layer : Q0 */ - Word16 *L_swb_norm, /* o : normalize length : Q0 */ - Word16 *prev_L_swb_norm /*i/o : last normalize length : Q0 */ + const Word16 core, /* i : core : Q0 */ + const Word32 *sp, /* i : input signal : Q12 */ + const Word16 mode, /* i : input mode : Q0 */ + const Word16 extl, /* i : extension layer : Q0 */ + Word16 *L_swb_norm, /* o : normalize length : Q0 */ + Word16 *prev_L_swb_norm /*i/o : last normalize length : Q0 */ ) { - Word16 i, n_freq, n_band, THRES; - Word16 L_swb_norm_trans, L_swb_norm_norm, L_swb_norm_harm, L_swb_norm_cur; - Word16 N; - - const Word32 *pit; - Word32 peak, mean, mag; - Word32 L_tmp1, L_tmp2; - - THRES = 4; - move16(); - test(); - test(); - if (EQ_16(core, HQ_CORE) || EQ_16(extl, SWB_BWE) || EQ_16(extl, FB_BWE)) - { - THRES = 8; - move16(); - } - - N = 16; - move16(); - test(); - test(); - if (EQ_16(core, HQ_CORE) && (EQ_16(mode, HQ_HARMONIC) || EQ_16(mode, HQ_HVQ))) - { - N = 13; - move16(); - } - - n_band = 0; - move16(); - pit = sp; - move16(); - FOR(i = 0; i < N; i++) - { - peak = 0; - move16(); - mean = 0; - move16(); - - FOR(n_freq = 0; n_freq < 16; n_freq++) - { - mag = L_abs(*pit); - if (GT_32(mag, peak)) - { - peak = mag; - move16(); - } + Word16 i, n_freq, n_band, THRES; + Word16 L_swb_norm_trans, L_swb_norm_norm, L_swb_norm_harm, L_swb_norm_cur; + Word16 N; + + const Word32 *pit; + Word32 peak, mean, mag; + Word32 L_tmp1, L_tmp2; + + THRES = 4; + move16(); + test(); + test(); + if ( EQ_16( core, HQ_CORE ) || EQ_16( extl, SWB_BWE ) || EQ_16( extl, FB_BWE ) ) + { + THRES = 8; + move16(); + } + + N = 16; + move16(); + test(); + test(); + if ( EQ_16( core, HQ_CORE ) && ( EQ_16( mode, HQ_HARMONIC ) || EQ_16( mode, HQ_HVQ ) ) ) + { + N = 13; + move16(); + } + + n_band = 0; + move16(); + pit = sp; + move16(); + FOR( i = 0; i < N; i++ ) + { + peak = 0; + move16(); + mean = 0; + move16(); + + FOR( n_freq = 0; n_freq < 16; n_freq++ ) + { + mag = L_abs( *pit ); + if ( GT_32( mag, peak ) ) + { + peak = mag; + move16(); + } #ifdef BASOP_NOGLOB mean = L_add_sat( mean, mag ); #else - mean = L_add(mean, mag); + mean = L_add( mean, mag ); #endif - pit++; - } - - L_tmp1 = Mult_32_16(peak, shl(15 + THRES, 10)); - L_tmp2 = Mult_32_16(mean, shl(THRES, 10)); - test(); - if (GT_32(L_tmp1, L_tmp2) && GT_32(peak, 40960)) - { - n_band = add(n_band, 1); - } - } - - IF(EQ_16(core, ACELP_CORE)) - { - L_swb_norm_trans = add(4, shr(n_band, 2)); - L_swb_norm_norm = add(8, shr(n_band, 1)); - L_swb_norm_harm = s_max(add(32, shl(n_band, 1)), 24); - - IF(mode == HARMONIC) - { - L_swb_norm_cur = L_swb_norm_harm; - move16(); - } - ELSE IF(mode == NORMAL) - { - L_swb_norm_cur = L_swb_norm_norm; - move16(); - } - ELSE - { - L_swb_norm_cur = L_swb_norm_trans; - move16(); - } - - *L_swb_norm = shr(add(L_swb_norm_cur, *prev_L_swb_norm), 1); - move16(); - *prev_L_swb_norm = L_swb_norm_cur; - move16(); - } - ELSE - { - test(); - IF(mode == HQ_HARMONIC || mode == HQ_HVQ) - { - L_swb_norm_cur = add(32, add(shl(n_band, 1), shr(n_band, 1))); - } - ELSE - { - L_swb_norm_cur = add(8, shr(n_band, 1)); - } - - *L_swb_norm = extract_h(L_add(L_mac(L_mult(L_swb_norm_cur, 3276), *prev_L_swb_norm, 29491),32768)); - *prev_L_swb_norm = L_swb_norm_cur; - move16(); - } - - return; + pit++; + } + + L_tmp1 = Mult_32_16( peak, shl( 15 + THRES, 10 ) ); + L_tmp2 = Mult_32_16( mean, shl( THRES, 10 ) ); + test(); + if ( GT_32( L_tmp1, L_tmp2 ) && GT_32( peak, 40960 ) ) + { + n_band = add( n_band, 1 ); + } + } + + IF( EQ_16( core, ACELP_CORE ) ) + { + L_swb_norm_trans = add( 4, shr( n_band, 2 ) ); + L_swb_norm_norm = add( 8, shr( n_band, 1 ) ); + L_swb_norm_harm = s_max( add( 32, shl( n_band, 1 ) ), 24 ); + + IF( mode == HARMONIC ) + { + L_swb_norm_cur = L_swb_norm_harm; + move16(); + } + ELSE IF( mode == NORMAL ) + { + L_swb_norm_cur = L_swb_norm_norm; + move16(); + } + ELSE + { + L_swb_norm_cur = L_swb_norm_trans; + move16(); + } + + *L_swb_norm = shr( add( L_swb_norm_cur, *prev_L_swb_norm ), 1 ); + move16(); + *prev_L_swb_norm = L_swb_norm_cur; + move16(); + } + ELSE + { + test(); + IF( mode == HQ_HARMONIC || mode == HQ_HVQ ) + { + L_swb_norm_cur = add( 32, add( shl( n_band, 1 ), shr( n_band, 1 ) ) ); + } + ELSE + { + L_swb_norm_cur = add( 8, shr( n_band, 1 ) ); + } + + *L_swb_norm = extract_h( L_add( L_mac( L_mult( L_swb_norm_cur, 3276 ), *prev_L_swb_norm, 29491 ), 32768 ) ); + *prev_L_swb_norm = L_swb_norm_cur; + move16(); + } + + return; } @@ -2528,60 +2530,60 @@ void calc_normal_length_fx_32( * *-------------------------------------------------------------------*/ void calc_norm_envelop_fx_32( - const Word32 SWB_signal_fx[], /* i : SWB spectrum : Q12 */ - Word32 *envelope_fx, /* o : normalized envelope : Q16 */ - const Word16 L_swb_norm, /* i : length of envelope : Q0 */ - const Word16 SWB_flength, /* i : Length of input/output : Q0 */ - const Word16 st_offset /* i : offset : Q0 */ + const Word32 SWB_signal_fx[], /* i : SWB spectrum : Q12 */ + Word32 *envelope_fx, /* o : normalized envelope : Q16 */ + const Word16 L_swb_norm, /* i : length of envelope : Q0 */ + const Word16 SWB_flength, /* i : Length of input/output : Q0 */ + const Word16 st_offset /* i : offset : Q0 */ ) { - Word16 i, lookback, env_index, n_freq, n_lag_now, n_lag, tmp; - - lookback = L_swb_norm / 2; - move16(); - env_index = swb_bwe_subband[0] + st_offset; - move16(); - n_lag_now = L_swb_norm; - move16(); - tmp = sub(add(SWB_flength, st_offset), L_swb_norm); - FOR(n_freq = sub(add(swb_bwe_trans_subband[0], st_offset), lookback); n_freq < tmp; n_freq++) - { - /* Apply MA filter */ - envelope_fx[env_index] = 0; - move16(); - FOR(n_lag = 0; n_lag < n_lag_now; n_lag++) - { + Word16 i, lookback, env_index, n_freq, n_lag_now, n_lag, tmp; + + lookback = L_swb_norm / 2; + move16(); + env_index = swb_bwe_subband[0] + st_offset; + move16(); + n_lag_now = L_swb_norm; + move16(); + tmp = sub( add( SWB_flength, st_offset ), L_swb_norm ); + FOR( n_freq = sub( add( swb_bwe_trans_subband[0], st_offset ), lookback ); n_freq < tmp; n_freq++ ) + { + /* Apply MA filter */ + envelope_fx[env_index] = 0; + move16(); + FOR( n_lag = 0; n_lag < n_lag_now; n_lag++ ) + { #ifdef BASOP_NOGLOB - envelope_fx[env_index] = L_add_sat( envelope_fx[env_index], L_abs( SWB_signal_fx[add( n_freq, n_lag )] ) ); + envelope_fx[env_index] = L_add_sat( envelope_fx[env_index], L_abs( SWB_signal_fx[add( n_freq, n_lag )] ) ); #else - envelope_fx[env_index] = L_add(envelope_fx[env_index], L_abs(SWB_signal_fx[add(n_freq, n_lag)])); + envelope_fx[env_index] = L_add( envelope_fx[env_index], L_abs( SWB_signal_fx[add( n_freq, n_lag )] ) ); #endif - move32(); - } - env_index++; - } - i = 0; - move16(); - tmp = sub(add(SWB_flength, st_offset), lookback); - FOR(n_freq = sub(add(SWB_flength, st_offset), L_swb_norm); n_freq < tmp; n_freq++) - { - Word32 L_tmp; - - n_lag_now = L_swb_norm - i; - move16(); - /* Apply MA filter */ - L_tmp = L_deposit_l(0); - FOR(n_lag = 0; n_lag < n_lag_now; n_lag++) - { - L_tmp = L_add(L_tmp, L_abs(SWB_signal_fx[n_freq + n_lag])); - } - envelope_fx[env_index] = L_tmp; - move32(); - env_index = add(env_index, 1); - i++; - } - - return; + move32(); + } + env_index++; + } + i = 0; + move16(); + tmp = sub( add( SWB_flength, st_offset ), lookback ); + FOR( n_freq = sub( add( SWB_flength, st_offset ), L_swb_norm ); n_freq < tmp; n_freq++ ) + { + Word32 L_tmp; + + n_lag_now = L_swb_norm - i; + move16(); + /* Apply MA filter */ + L_tmp = L_deposit_l( 0 ); + FOR( n_lag = 0; n_lag < n_lag_now; n_lag++ ) + { + L_tmp = L_add( L_tmp, L_abs( SWB_signal_fx[n_freq + n_lag] ) ); + } + envelope_fx[env_index] = L_tmp; + move32(); + env_index = add( env_index, 1 ); + i++; + } + + return; } /*-------------------------------------------------------------------* @@ -2589,569 +2591,567 @@ void calc_norm_envelop_fx_32( * *-------------------------------------------------------------------*/ void hq_generic_decoding_fx( - const Word16 HQ_mode, /* i : HQ mode : Q0 */ - Word32 *coeff_out1_fx, /* i/o: BWE input & temporary buffer : Q12 */ - const Word16 *hq_generic_fenv_fx, /* i : SWB frequency envelopes : Q1 */ - Word32 *coeff_out_fx, /* o : SWB signal in MDCT domain : Q12 */ - const Word16 hq_generic_offset, /* i : frequency offset for representing hq generci : Q0 */ - Word16 *prev_L_swb_norm, /* i/o: last normalize length : Q0 */ - const Word16 hq_generic_exc_clas, /* i : bwe excitation class " Q0 */ - const Word16 *R -) + const Word16 HQ_mode, /* i : HQ mode : Q0 */ + Word32 *coeff_out1_fx, /* i/o: BWE input & temporary buffer : Q12 */ + const Word16 *hq_generic_fenv_fx, /* i : SWB frequency envelopes : Q1 */ + Word32 *coeff_out_fx, /* o : SWB signal in MDCT domain : Q12 */ + const Word16 hq_generic_offset, /* i : frequency offset for representing hq generci : Q0 */ + Word16 *prev_L_swb_norm, /* i/o: last normalize length : Q0 */ + const Word16 hq_generic_exc_clas, /* i : bwe excitation class " Q0 */ + const Word16 *R ) { - Word16 i, n_freq, n_band, L_swb_norm; - Word16 k; - Word16 nenv; - Word16 tenv; - - Word16 exp, exp1, exp2, frac, tmp, tmp2, cs; - Word32 L_tmp, L_tmp1, L_tmp2, max_coeff_fx; - Word16 fenvL_fx, wfenv_fx, factor_fx; - Word32* pit1_fx; - Word16 tmp1_fx, tmp2_fx, tmp3_fx, tmp4_fx; - Word32 energy_fx; - - Word32 envelope_fx[L_FRAME16k]; - Word32 mean_vector_fx[20]; - Word16 rn_weight0_fx; - Word16 s; - Word16 blen, nband_lf, sfidx, efidx; - Word16 bwe_seed; - Word16 signum[L_FRAME16k]; - - nenv = sub(SWB_FENV, 2); - if (LE_16(hq_generic_offset, HQ_GENERIC_FOFFSET_24K4)) - { - nenv = SWB_FENV; - move16(); - } - - tenv = nenv; - move16(); - if (EQ_16(HQ_mode, HQ_GEN_FB)) - { - tenv = add(nenv, DIM_FB); - } - - max_coeff_fx = 0; - move16(); - tmp = add(swb_bwe_subband[0], hq_generic_offset); - FOR(n_freq = add(HQ_GENERIC_ST_FREQ, hq_generic_offset); n_freq < tmp; n_freq++) - { - max_coeff_fx = L_max(max_coeff_fx, L_abs(coeff_out1_fx[n_freq])); - } - cs = norm_l(max_coeff_fx); - - L_tmp = 0; - move16(); - tmp2 = add(swb_bwe_subband[0], hq_generic_offset); - FOR(n_freq = add(HQ_GENERIC_ST_FREQ, hq_generic_offset); n_freq < tmp2; n_freq++) - { - tmp = extract_h(L_shl(coeff_out1_fx[n_freq], cs));/*12 + cs - 16 */ - L_tmp1 = L_mult0(tmp, tmp);/*2*(cs-2) */ - L_tmp = L_add(L_tmp, L_shr(L_tmp1, 5));/*2*(cs-2) - 5 */ - } - cs = sub(shl(cs, 1), 9); - fenvL_fx = 0; - move16(); - IF(L_tmp != 0) - { - exp = norm_l(L_tmp); + Word16 i, n_freq, n_band, L_swb_norm; + Word16 k; + Word16 nenv; + Word16 tenv; + + Word16 exp, exp1, exp2, frac, tmp, tmp2, cs; + Word32 L_tmp, L_tmp1, L_tmp2, max_coeff_fx; + Word16 fenvL_fx, wfenv_fx, factor_fx; + Word32 *pit1_fx; + Word16 tmp1_fx, tmp2_fx, tmp3_fx, tmp4_fx; + Word32 energy_fx; + + Word32 envelope_fx[L_FRAME16k]; + Word32 mean_vector_fx[20]; + Word16 rn_weight0_fx; + Word16 s; + Word16 blen, nband_lf, sfidx, efidx; + Word16 bwe_seed; + Word16 signum[L_FRAME16k]; + + nenv = sub( SWB_FENV, 2 ); + if ( LE_16( hq_generic_offset, HQ_GENERIC_FOFFSET_24K4 ) ) + { + nenv = SWB_FENV; + move16(); + } + + tenv = nenv; + move16(); + if ( EQ_16( HQ_mode, HQ_GEN_FB ) ) + { + tenv = add( nenv, DIM_FB ); + } + + max_coeff_fx = 0; + move16(); + tmp = add( swb_bwe_subband[0], hq_generic_offset ); + FOR( n_freq = add( HQ_GENERIC_ST_FREQ, hq_generic_offset ); n_freq < tmp; n_freq++ ) + { + max_coeff_fx = L_max( max_coeff_fx, L_abs( coeff_out1_fx[n_freq] ) ); + } + cs = norm_l( max_coeff_fx ); + + L_tmp = 0; + move16(); + tmp2 = add( swb_bwe_subband[0], hq_generic_offset ); + FOR( n_freq = add( HQ_GENERIC_ST_FREQ, hq_generic_offset ); n_freq < tmp2; n_freq++ ) + { + tmp = extract_h( L_shl( coeff_out1_fx[n_freq], cs ) ); /*12 + cs - 16 */ + L_tmp1 = L_mult0( tmp, tmp ); /*2*(cs-2) */ + L_tmp = L_add( L_tmp, L_shr( L_tmp1, 5 ) ); /*2*(cs-2) - 5 */ + } + cs = sub( shl( cs, 1 ), 9 ); + fenvL_fx = 0; + move16(); + IF( L_tmp != 0 ) + { + exp = norm_l( L_tmp ); #ifdef EVS_FUNC_MODIFIED - frac = round_fx_sat(L_shl(L_tmp, exp));/*cs+exp-16 */ + frac = round_fx_sat( L_shl( L_tmp, exp ) ); /*cs+exp-16 */ #else - frac = round_fx(L_shl(L_tmp, exp));/*cs+exp-16 */ + frac = round_fx( L_shl( L_tmp, exp ) ); /*cs+exp-16 */ #endif - tmp = div_s(16384, frac);/*15 + 14 - (cs+exp-16) */ - exp = sub(add(cs, exp), 30); - L_tmp = Isqrt_lc(L_deposit_h(tmp), &exp);/*Q31 - exp */ + tmp = div_s( 16384, frac ); /*15 + 14 - (cs+exp-16) */ + exp = sub( add( cs, exp ), 30 ); + L_tmp = Isqrt_lc( L_deposit_h( tmp ), &exp ); /*Q31 - exp */ #ifdef BASOP_NOGLOB fenvL_fx = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 14 ) ) ); /*Q1 */ #else - fenvL_fx = round_fx(L_shl(L_tmp, sub(exp, 14)));/*Q1 */ + fenvL_fx = round_fx( L_shl( L_tmp, sub( exp, 14 ) ) ); /*Q1 */ #endif - } - - calc_normal_length_fx_32(HQ_CORE, coeff_out1_fx, HQ_GEN_SWB, -1, &L_swb_norm, prev_L_swb_norm); - - calc_norm_envelop_lf_fx(coeff_out1_fx, envelope_fx, &L_swb_norm, HQ_mode, hq_generic_offset, &sfidx, &efidx); - - blen = 16; - move16(); - - IF(EQ_16(hq_generic_exc_clas, HQ_GENERIC_EXC0)) - { - rn_weight0_fx = 819; - move16();/* 0.8 Q10 */ - } - ELSE IF(EQ_16(hq_generic_exc_clas, HQ_GENERIC_EXC1)) - { - rn_weight0_fx = 51; - move16();/* 0.05 Q10*/ - } - ELSE - { - rn_weight0_fx = 205; - move16();/* 0.02 Q10 */ - } - - tmp = sub(efidx, sfidx); - IF(EQ_16(tmp, 0)) - { - nband_lf = 0; - } - ELSE - { - exp = norm_s(tmp); - nband_lf = shl(tmp,sub(exp,1)); - exp1 = norm_s(blen); - tmp = shl(blen,exp1); - nband_lf = shr(div_s(nband_lf,tmp), add(sub(14,exp1),exp));/* 15 + exp-1 - exp1, Q0*/ - } - - FOR(n_freq = sfidx; n_freq < efidx; n_freq++) - { - IF(coeff_out1_fx[n_freq] < 0) - { - signum[n_freq] = -1; - move16(); - coeff_out1_fx[n_freq] = L_negate(coeff_out1_fx[n_freq]); - move32(); - } - ELSE - { - signum[n_freq] = 1; - move16(); - } - } - - /* applying whitening */ - FOR(n_freq = sfidx; n_freq < efidx; n_freq++) - { - exp = norm_l(coeff_out1_fx[n_freq]) - 1; - exp1 = norm_l(envelope_fx[n_freq]); - - L_tmp = L_shl(coeff_out1_fx[n_freq], exp); - L_tmp1 = L_shl(envelope_fx[n_freq], exp1); - - logic16(); - coeff_out1_fx[n_freq] = Div_32(L_tmp, extract_h(L_tmp1), extract_l(L_shr(L_tmp1, 1)) & 0x00007fff); - move32();/*31 + exp1 - exp2*/ - - exp = add(31, sub(exp, exp1)); - coeff_out1_fx[n_freq] = L_shl(coeff_out1_fx[n_freq], sub(20, exp)); - move32();/*Q12->Q20*/ - } - - /* mean vector generation for controlling dynamic range */ - FOR(k = 0; k < nband_lf; ++k) - { - energy_fx = 1; - move16(); - - tmp = add(i_mult2(add(k, 1), blen), sfidx); - FOR(i = add(i_mult2(k, blen), sfidx); i < tmp; ++i) - { - energy_fx = L_add(energy_fx, coeff_out1_fx[i]); - } - exp = sub(norm_l(energy_fx), 1); - L_tmp = L_shl(energy_fx, exp); - exp1 = norm_l(L_and(blen, 0x00007fff)); - L_tmp1 = L_shl(blen, exp1); - logic16(); - mean_vector_fx[k] = Div_32(L_tmp, extract_h(L_tmp1), extract_l(L_shr(L_tmp1, 1)) & 0x00007fff); - move32();/*31 + 20 + exp1 - exp2*/ - exp = add(51, sub(exp, exp1)); - mean_vector_fx[k] = L_shl(mean_vector_fx[k], sub(20, exp)); - move32();/*Q12->Q20*/ - } - - /* dynamics control */ - FOR(k = 0; k < nband_lf; ++k) - { - tmp = add(i_mult2(add(k, 1), blen), sfidx); - FOR(i = add(i_mult2(k, blen), sfidx); i < tmp; ++i) - { - L_tmp = L_sub(coeff_out1_fx[i], mean_vector_fx[k]); - exp = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, exp); /* exp+12*/ - exp1 = norm_l(rn_weight0_fx); - L_tmp1 = L_shl(rn_weight0_fx, exp1); /* exp1+10*/ - L_tmp = L_mult(extract_h(L_tmp), extract_h(L_tmp1)); - L_tmp = L_shr(L_tmp, add(exp, sub(exp1, 21))); /* Q20*/ - coeff_out1_fx[i] = L_sub(coeff_out1_fx[i], L_tmp); - move32(); - } - } - - IF(EQ_16(hq_generic_exc_clas, HQ_GENERIC_EXC0)) - { - bwe_seed = add(add(shl(R[0], 3), shl(R[1], 2)), add(shl(R[2], 1), R[3])); - - FOR(n_freq = sfidx; n_freq < efidx; n_freq++) - { - IF(signum[n_freq] < 0) - { - coeff_out1_fx[n_freq] = L_negate(coeff_out1_fx[n_freq]); - move32(); - } - - IF(Random(&bwe_seed) < 0) - { - coeff_out1_fx[n_freq] = L_negate(coeff_out1_fx[n_freq]); - move32(); - } - } - } - ELSE - { - FOR(n_freq = sfidx; n_freq < efidx; n_freq++) - { - IF(signum[n_freq] < 0) - { - coeff_out1_fx[n_freq] = L_negate(coeff_out1_fx[n_freq]); - move32(); - } - } - } - - /* normalizing modified low frequency spectrum */ - FOR(k = 0; k < nband_lf; ++k) - { - energy_fx = 1; - move16(); - tmp = add(i_mult2(add(k, 1), blen), sfidx); - FOR(i = add((i_mult2(k, blen)), sfidx); i < tmp; ++i) - { - exp = norm_l(coeff_out1_fx[i]); - L_tmp1 = L_shl(coeff_out1_fx[i], exp);/* exp + 12*/ - - L_tmp = Mult_32_32(L_tmp1, L_tmp1); - L_tmp = L_shr(L_tmp, sub(i_mult2(2, exp), 11));/*Q20 */ - energy_fx = L_add(energy_fx, L_tmp); - } - - exp = norm_l(energy_fx); - L_tmp = L_shl(energy_fx, sub(exp, 1)); - exp1 = norm_s(blen); - L_tmp1 = L_shl((Word32)blen, add(exp1, 16)); - - L_tmp = Div_32(L_tmp, extract_h(L_tmp1), extract_l(L_shr(L_tmp1, 1)) & 0x00007fff); - exp = sub(add(34, exp), exp1); - L_tmp = L_shr(L_tmp, sub(exp, 31)); - exp = 31; - move16(); - - exp = sub(31, exp); - IF(exp & 0x1) - { - L_tmp = L_shr(L_tmp, 1); - exp = add(exp, 1); - } - L_tmp = Sqrt_l(L_tmp, &exp1); - exp = add(31, sub(shr(exp1, 1), shr(exp, 1))); - energy_fx = L_shl(L_tmp, sub(31, exp)); /*Q31*/ - - tmp = add(i_mult2(add(k, 1), blen), sfidx); - FOR(i = add((i_mult2(k, blen)), sfidx); i < tmp; ++i) - { - IF(NE_32(L_abs(coeff_out1_fx[i]), coeff_out1_fx[i])) - { - s = -1; - move16(); - coeff_out1_fx[i] = L_abs(coeff_out1_fx[i]); - move32(); - } - ELSE - { - s = 0; - move16(); - } - exp = norm_l(coeff_out1_fx[i]); - L_tmp = L_shl(coeff_out1_fx[i], sub(exp, 1)); - exp1 = norm_l(energy_fx); - L_tmp1 = L_shl((Word32)energy_fx, exp1); - logic16(); - L_tmp = Div_32(L_tmp, extract_h(L_tmp1), extract_l(L_shr(L_tmp1, 1)) & 0x00007fff); - exp = add(sub(19, exp1), exp); - coeff_out1_fx[i] = L_shl(L_tmp, add(sub(12, exp), 15)); - move32(); /* Q12 -> Q27 */ - IF(s) - { - coeff_out1_fx[i] = L_negate(coeff_out1_fx[i]); - move32(); - } - } - } - - Copy32(&coeff_out1_fx[HQ_GENERIC_OFFSET], &coeff_out_fx[add(HQ_GENERIC_HIGH0, hq_generic_offset)], HQ_GENERIC_LEN0); - Copy32(&coeff_out1_fx[HQ_GENERIC_OFFSET], &coeff_out_fx[add(HQ_GENERIC_HIGH1, hq_generic_offset)], HQ_GENERIC_LEN0); - - IF(LE_16(hq_generic_offset, HQ_GENERIC_FOFFSET_24K4)) - { - Copy32(&coeff_out1_fx[HQ_GENERIC_LOW0], &coeff_out_fx[add(HQ_GENERIC_HIGH2, hq_generic_offset)], sub(HQ_GENERIC_END_FREQ, HQ_GENERIC_HIGH2)); - } - - IF(EQ_16(HQ_mode, HQ_GEN_FB)) - { - IF(LE_16(hq_generic_offset, HQ_GENERIC_FOFFSET_24K4)) - { - Copy32(&coeff_out1_fx[sub(add(HQ_GENERIC_LOW0, HQ_GENERIC_END_FREQ), HQ_GENERIC_HIGH2)], &coeff_out_fx[fb_bwe_subband[0]], 160); - } - ELSE - { - Copy32(&coeff_out1_fx[add(HQ_GENERIC_OFFSET , HQ_GENERIC_LEN0)], &coeff_out_fx[fb_bwe_subband[0]], 160); - } - } - - - L_tmp1 = L_deposit_l(0); - L_tmp2 = L_deposit_l(0); - FOR(i = 0; i < 5; ++i) - { - L_tmp1 = L_add(L_tmp1, L_abs(coeff_out_fx[add(add(HQ_GENERIC_HIGH1, hq_generic_offset), i)])); - L_tmp2 = L_add(L_tmp2, L_abs(coeff_out_fx[sub(add(sub(HQ_GENERIC_HIGH1, 2), hq_generic_offset), i)])); - } - - pit1_fx = &coeff_out_fx[add(HQ_GENERIC_HIGH1, hq_generic_offset)]; - L_tmp1 = L_max(L_tmp1, 1); - L_tmp2 = L_max(L_tmp2, 1); - exp1 = norm_l(L_tmp1); - exp2 = sub(norm_l(L_tmp2), 1); - tmp1_fx = extract_h(L_shl(L_tmp1, exp1)); - tmp2_fx = extract_h(L_shl(L_tmp2, exp2)); - tmp3_fx = div_s(tmp2_fx, tmp1_fx);/*15 + exp2 + 15 - (exp1 + 15) */ - tmp3_fx = shr(tmp3_fx, add(5, sub(exp2, exp1)));/*10 */ - - if (LT_16(tmp3_fx, 307)) - { - tmp3_fx = 307; - move16(); - } - FOR(; tmp3_fx < 1024; tmp3_fx += 102) - { - *pit1_fx = Mult_32_16(*pit1_fx, shl(tmp3_fx, 5)); - move32();/*15 + 5 + 10 -15 */ - pit1_fx++; - } - - pit1_fx = &coeff_out_fx[add(sub(HQ_GENERIC_HIGH1, 1), hq_generic_offset)]; - - exp1 = sub(norm_l(L_tmp1), 1); - exp2 = norm_l(L_tmp2); - tmp1_fx = extract_h(L_shl(L_tmp1, exp1)); - tmp2_fx = extract_h(L_shl(L_tmp2, exp2)); - tmp3_fx = div_s(tmp1_fx, tmp2_fx);/*15 + exp2 + 15 - (exp1 + 15) */ - tmp3_fx = shr(tmp3_fx, add(5, sub(exp1, exp2)));/*10 */ - - IF(GT_16(tmp3_fx, 5120)) - { - FOR(tmp3_fx = 5120; tmp3_fx > 1024; tmp3_fx -= 512) - { - L_tmp1 = L_shl(Mult_32_16(*pit1_fx, tmp3_fx), 5); /*15 + 5 + 10 -15 */ - *pit1_fx-- = L_tmp1; - move32(); - } - } - - IF(LE_16(hq_generic_offset, HQ_GENERIC_FOFFSET_24K4)) - { - L_tmp1 = L_add(L_abs(coeff_out_fx[add(HQ_GENERIC_HIGH2, hq_generic_offset)]), L_abs(coeff_out_fx[add(add(HQ_GENERIC_HIGH2, 1), hq_generic_offset)])); - L_tmp2 = L_add(L_abs(coeff_out_fx[add(sub(HQ_GENERIC_HIGH2, 4), hq_generic_offset)]), L_add(L_abs(coeff_out_fx[add(sub(HQ_GENERIC_HIGH2, 3), hq_generic_offset)]), - L_add(L_abs(coeff_out_fx[add(sub(HQ_GENERIC_HIGH2, 2), hq_generic_offset)]), L_abs(coeff_out_fx[add(sub(HQ_GENERIC_HIGH2, 1), hq_generic_offset)])))); - - pit1_fx = &coeff_out_fx[add(HQ_GENERIC_HIGH2, hq_generic_offset)]; - - L_tmp1 = L_max(L_tmp1, 1); - L_tmp2 = L_max(L_tmp2, 1); - exp1 = norm_l(L_tmp1); - exp2 = sub(norm_l(L_tmp2), 1); - tmp1_fx = extract_h(L_shl(L_tmp1, exp1)); - tmp2_fx = extract_h(L_shl(L_tmp2, exp2)); - tmp3_fx = div_s(tmp2_fx, tmp1_fx);/*15 + exp2 + 15 - (exp1 + 15) */ + } + + calc_normal_length_fx_32( HQ_CORE, coeff_out1_fx, HQ_GEN_SWB, -1, &L_swb_norm, prev_L_swb_norm ); + + calc_norm_envelop_lf_fx( coeff_out1_fx, envelope_fx, &L_swb_norm, HQ_mode, hq_generic_offset, &sfidx, &efidx ); + + blen = 16; + move16(); + + IF( EQ_16( hq_generic_exc_clas, HQ_GENERIC_EXC0 ) ) + { + rn_weight0_fx = 819; + move16(); /* 0.8 Q10 */ + } + ELSE IF( EQ_16( hq_generic_exc_clas, HQ_GENERIC_EXC1 ) ) + { + rn_weight0_fx = 51; + move16(); /* 0.05 Q10*/ + } + ELSE + { + rn_weight0_fx = 205; + move16(); /* 0.02 Q10 */ + } + + tmp = sub( efidx, sfidx ); + IF( EQ_16( tmp, 0 ) ) + { + nband_lf = 0; + } + ELSE + { + exp = norm_s( tmp ); + nband_lf = shl( tmp, sub( exp, 1 ) ); + exp1 = norm_s( blen ); + tmp = shl( blen, exp1 ); + nband_lf = shr( div_s( nband_lf, tmp ), add( sub( 14, exp1 ), exp ) ); /* 15 + exp-1 - exp1, Q0*/ + } + + FOR( n_freq = sfidx; n_freq < efidx; n_freq++ ) + { + IF( coeff_out1_fx[n_freq] < 0 ) + { + signum[n_freq] = -1; + move16(); + coeff_out1_fx[n_freq] = L_negate( coeff_out1_fx[n_freq] ); + move32(); + } + ELSE + { + signum[n_freq] = 1; + move16(); + } + } + + /* applying whitening */ + FOR( n_freq = sfidx; n_freq < efidx; n_freq++ ) + { + exp = norm_l( coeff_out1_fx[n_freq] ) - 1; + exp1 = norm_l( envelope_fx[n_freq] ); + + L_tmp = L_shl( coeff_out1_fx[n_freq], exp ); + L_tmp1 = L_shl( envelope_fx[n_freq], exp1 ); + + logic16(); + coeff_out1_fx[n_freq] = Div_32( L_tmp, extract_h( L_tmp1 ), extract_l( L_shr( L_tmp1, 1 ) ) & 0x00007fff ); + move32(); /*31 + exp1 - exp2*/ + + exp = add( 31, sub( exp, exp1 ) ); + coeff_out1_fx[n_freq] = L_shl( coeff_out1_fx[n_freq], sub( 20, exp ) ); + move32(); /*Q12->Q20*/ + } + + /* mean vector generation for controlling dynamic range */ + FOR( k = 0; k < nband_lf; ++k ) + { + energy_fx = 1; + move16(); + + tmp = add( i_mult2( add( k, 1 ), blen ), sfidx ); + FOR( i = add( i_mult2( k, blen ), sfidx ); i < tmp; ++i ) + { + energy_fx = L_add( energy_fx, coeff_out1_fx[i] ); + } + exp = sub( norm_l( energy_fx ), 1 ); + L_tmp = L_shl( energy_fx, exp ); + exp1 = norm_l( L_and( blen, 0x00007fff ) ); + L_tmp1 = L_shl( blen, exp1 ); + logic16(); + mean_vector_fx[k] = Div_32( L_tmp, extract_h( L_tmp1 ), extract_l( L_shr( L_tmp1, 1 ) ) & 0x00007fff ); + move32(); /*31 + 20 + exp1 - exp2*/ + exp = add( 51, sub( exp, exp1 ) ); + mean_vector_fx[k] = L_shl( mean_vector_fx[k], sub( 20, exp ) ); + move32(); /*Q12->Q20*/ + } + + /* dynamics control */ + FOR( k = 0; k < nband_lf; ++k ) + { + tmp = add( i_mult2( add( k, 1 ), blen ), sfidx ); + FOR( i = add( i_mult2( k, blen ), sfidx ); i < tmp; ++i ) + { + L_tmp = L_sub( coeff_out1_fx[i], mean_vector_fx[k] ); + exp = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, exp ); /* exp+12*/ + exp1 = norm_l( rn_weight0_fx ); + L_tmp1 = L_shl( rn_weight0_fx, exp1 ); /* exp1+10*/ + L_tmp = L_mult( extract_h( L_tmp ), extract_h( L_tmp1 ) ); + L_tmp = L_shr( L_tmp, add( exp, sub( exp1, 21 ) ) ); /* Q20*/ + coeff_out1_fx[i] = L_sub( coeff_out1_fx[i], L_tmp ); + move32(); + } + } + + IF( EQ_16( hq_generic_exc_clas, HQ_GENERIC_EXC0 ) ) + { + bwe_seed = add( add( shl( R[0], 3 ), shl( R[1], 2 ) ), add( shl( R[2], 1 ), R[3] ) ); + + FOR( n_freq = sfidx; n_freq < efidx; n_freq++ ) + { + IF( signum[n_freq] < 0 ) + { + coeff_out1_fx[n_freq] = L_negate( coeff_out1_fx[n_freq] ); + move32(); + } + + IF( Random( &bwe_seed ) < 0 ) + { + coeff_out1_fx[n_freq] = L_negate( coeff_out1_fx[n_freq] ); + move32(); + } + } + } + ELSE + { + FOR( n_freq = sfidx; n_freq < efidx; n_freq++ ) + { + IF( signum[n_freq] < 0 ) + { + coeff_out1_fx[n_freq] = L_negate( coeff_out1_fx[n_freq] ); + move32(); + } + } + } + + /* normalizing modified low frequency spectrum */ + FOR( k = 0; k < nband_lf; ++k ) + { + energy_fx = 1; + move16(); + tmp = add( i_mult2( add( k, 1 ), blen ), sfidx ); + FOR( i = add( ( i_mult2( k, blen ) ), sfidx ); i < tmp; ++i ) + { + exp = norm_l( coeff_out1_fx[i] ); + L_tmp1 = L_shl( coeff_out1_fx[i], exp ); /* exp + 12*/ + + L_tmp = Mult_32_32( L_tmp1, L_tmp1 ); + L_tmp = L_shr( L_tmp, sub( i_mult2( 2, exp ), 11 ) ); /*Q20 */ + energy_fx = L_add( energy_fx, L_tmp ); + } + + exp = norm_l( energy_fx ); + L_tmp = L_shl( energy_fx, sub( exp, 1 ) ); + exp1 = norm_s( blen ); + L_tmp1 = L_shl( (Word32) blen, add( exp1, 16 ) ); + + L_tmp = Div_32( L_tmp, extract_h( L_tmp1 ), extract_l( L_shr( L_tmp1, 1 ) ) & 0x00007fff ); + exp = sub( add( 34, exp ), exp1 ); + L_tmp = L_shr( L_tmp, sub( exp, 31 ) ); + exp = 31; + move16(); + + exp = sub( 31, exp ); + IF( exp & 0x1 ) + { + L_tmp = L_shr( L_tmp, 1 ); + exp = add( exp, 1 ); + } + L_tmp = Sqrt_l( L_tmp, &exp1 ); + exp = add( 31, sub( shr( exp1, 1 ), shr( exp, 1 ) ) ); + energy_fx = L_shl( L_tmp, sub( 31, exp ) ); /*Q31*/ + + tmp = add( i_mult2( add( k, 1 ), blen ), sfidx ); + FOR( i = add( ( i_mult2( k, blen ) ), sfidx ); i < tmp; ++i ) + { + IF( NE_32( L_abs( coeff_out1_fx[i] ), coeff_out1_fx[i] ) ) + { + s = -1; + move16(); + coeff_out1_fx[i] = L_abs( coeff_out1_fx[i] ); + move32(); + } + ELSE + { + s = 0; + move16(); + } + exp = norm_l( coeff_out1_fx[i] ); + L_tmp = L_shl( coeff_out1_fx[i], sub( exp, 1 ) ); + exp1 = norm_l( energy_fx ); + L_tmp1 = L_shl( (Word32) energy_fx, exp1 ); + logic16(); + L_tmp = Div_32( L_tmp, extract_h( L_tmp1 ), extract_l( L_shr( L_tmp1, 1 ) ) & 0x00007fff ); + exp = add( sub( 19, exp1 ), exp ); + coeff_out1_fx[i] = L_shl( L_tmp, add( sub( 12, exp ), 15 ) ); + move32(); /* Q12 -> Q27 */ + IF( s ) + { + coeff_out1_fx[i] = L_negate( coeff_out1_fx[i] ); + move32(); + } + } + } + + Copy32( &coeff_out1_fx[HQ_GENERIC_OFFSET], &coeff_out_fx[add( HQ_GENERIC_HIGH0, hq_generic_offset )], HQ_GENERIC_LEN0 ); + Copy32( &coeff_out1_fx[HQ_GENERIC_OFFSET], &coeff_out_fx[add( HQ_GENERIC_HIGH1, hq_generic_offset )], HQ_GENERIC_LEN0 ); + + IF( LE_16( hq_generic_offset, HQ_GENERIC_FOFFSET_24K4 ) ) + { + Copy32( &coeff_out1_fx[HQ_GENERIC_LOW0], &coeff_out_fx[add( HQ_GENERIC_HIGH2, hq_generic_offset )], sub( HQ_GENERIC_END_FREQ, HQ_GENERIC_HIGH2 ) ); + } + + IF( EQ_16( HQ_mode, HQ_GEN_FB ) ) + { + IF( LE_16( hq_generic_offset, HQ_GENERIC_FOFFSET_24K4 ) ) + { + Copy32( &coeff_out1_fx[sub( add( HQ_GENERIC_LOW0, HQ_GENERIC_END_FREQ ), HQ_GENERIC_HIGH2 )], &coeff_out_fx[fb_bwe_subband[0]], 160 ); + } + ELSE + { + Copy32( &coeff_out1_fx[add( HQ_GENERIC_OFFSET, HQ_GENERIC_LEN0 )], &coeff_out_fx[fb_bwe_subband[0]], 160 ); + } + } + + + L_tmp1 = L_deposit_l( 0 ); + L_tmp2 = L_deposit_l( 0 ); + FOR( i = 0; i < 5; ++i ) + { + L_tmp1 = L_add( L_tmp1, L_abs( coeff_out_fx[add( add( HQ_GENERIC_HIGH1, hq_generic_offset ), i )] ) ); + L_tmp2 = L_add( L_tmp2, L_abs( coeff_out_fx[sub( add( sub( HQ_GENERIC_HIGH1, 2 ), hq_generic_offset ), i )] ) ); + } + + pit1_fx = &coeff_out_fx[add( HQ_GENERIC_HIGH1, hq_generic_offset )]; + L_tmp1 = L_max( L_tmp1, 1 ); + L_tmp2 = L_max( L_tmp2, 1 ); + exp1 = norm_l( L_tmp1 ); + exp2 = sub( norm_l( L_tmp2 ), 1 ); + tmp1_fx = extract_h( L_shl( L_tmp1, exp1 ) ); + tmp2_fx = extract_h( L_shl( L_tmp2, exp2 ) ); + tmp3_fx = div_s( tmp2_fx, tmp1_fx ); /*15 + exp2 + 15 - (exp1 + 15) */ + tmp3_fx = shr( tmp3_fx, add( 5, sub( exp2, exp1 ) ) ); /*10 */ + + if ( LT_16( tmp3_fx, 307 ) ) + { + tmp3_fx = 307; + move16(); + } + FOR( ; tmp3_fx < 1024; tmp3_fx += 102 ) + { + *pit1_fx = Mult_32_16( *pit1_fx, shl( tmp3_fx, 5 ) ); + move32(); /*15 + 5 + 10 -15 */ + pit1_fx++; + } + + pit1_fx = &coeff_out_fx[add( sub( HQ_GENERIC_HIGH1, 1 ), hq_generic_offset )]; + + exp1 = sub( norm_l( L_tmp1 ), 1 ); + exp2 = norm_l( L_tmp2 ); + tmp1_fx = extract_h( L_shl( L_tmp1, exp1 ) ); + tmp2_fx = extract_h( L_shl( L_tmp2, exp2 ) ); + tmp3_fx = div_s( tmp1_fx, tmp2_fx ); /*15 + exp2 + 15 - (exp1 + 15) */ + tmp3_fx = shr( tmp3_fx, add( 5, sub( exp1, exp2 ) ) ); /*10 */ + + IF( GT_16( tmp3_fx, 5120 ) ) + { + FOR( tmp3_fx = 5120; tmp3_fx > 1024; tmp3_fx -= 512 ) + { + L_tmp1 = L_shl( Mult_32_16( *pit1_fx, tmp3_fx ), 5 ); /*15 + 5 + 10 -15 */ + *pit1_fx-- = L_tmp1; + move32(); + } + } + + IF( LE_16( hq_generic_offset, HQ_GENERIC_FOFFSET_24K4 ) ) + { + L_tmp1 = L_add( L_abs( coeff_out_fx[add( HQ_GENERIC_HIGH2, hq_generic_offset )] ), L_abs( coeff_out_fx[add( add( HQ_GENERIC_HIGH2, 1 ), hq_generic_offset )] ) ); + L_tmp2 = L_add( L_abs( coeff_out_fx[add( sub( HQ_GENERIC_HIGH2, 4 ), hq_generic_offset )] ), L_add( L_abs( coeff_out_fx[add( sub( HQ_GENERIC_HIGH2, 3 ), hq_generic_offset )] ), + L_add( L_abs( coeff_out_fx[add( sub( HQ_GENERIC_HIGH2, 2 ), hq_generic_offset )] ), L_abs( coeff_out_fx[add( sub( HQ_GENERIC_HIGH2, 1 ), hq_generic_offset )] ) ) ) ); + + pit1_fx = &coeff_out_fx[add( HQ_GENERIC_HIGH2, hq_generic_offset )]; + + L_tmp1 = L_max( L_tmp1, 1 ); + L_tmp2 = L_max( L_tmp2, 1 ); + exp1 = norm_l( L_tmp1 ); + exp2 = sub( norm_l( L_tmp2 ), 1 ); + tmp1_fx = extract_h( L_shl( L_tmp1, exp1 ) ); + tmp2_fx = extract_h( L_shl( L_tmp2, exp2 ) ); + tmp3_fx = div_s( tmp2_fx, tmp1_fx ); /*15 + exp2 + 15 - (exp1 + 15) */ #ifdef BASOP_NOGLOB tmp3_fx = shr_sat( tmp3_fx, add( 5, sub( exp2, exp1 ) ) ); /*10 */ #else - tmp3_fx = shr(tmp3_fx, add(5, sub(exp2, exp1)));/*10 */ + tmp3_fx = shr( tmp3_fx, add( 5, sub( exp2, exp1 ) ) ); /*10 */ #endif - if (LT_16(tmp3_fx, 307)) - { - tmp3_fx = 307; - move16(); - } - FOR(; tmp3_fx < 1024; tmp3_fx += 102) - { - L_tmp = L_shl(Mult_32_16(*pit1_fx, tmp3_fx), 5); /*15 + 5 + 10 -15 */ - *pit1_fx++ = L_tmp; - move32(); - } - - pit1_fx = &coeff_out_fx[add(sub(HQ_GENERIC_HIGH2, 1), hq_generic_offset)]; - - exp1 = sub(norm_l(L_tmp1), 1); - exp2 = norm_l(L_tmp2); - tmp1_fx = extract_h(L_shl(L_tmp1, exp1)); - tmp2_fx = extract_h(L_shl(L_tmp2, exp2)); - tmp3_fx = div_s(tmp1_fx, tmp2_fx);/*15 + exp2 + 15 - (exp1 + 15) */ - tmp3_fx = shr(tmp3_fx, add(5, sub(exp1, exp2)));/*10 */ - tmp3_fx = shr(tmp3_fx, 1); - tmp4_fx = mult_r(tmp3_fx, 1638); - WHILE(tmp3_fx > 1024) - { + if ( LT_16( tmp3_fx, 307 ) ) + { + tmp3_fx = 307; + move16(); + } + FOR( ; tmp3_fx < 1024; tmp3_fx += 102 ) + { + L_tmp = L_shl( Mult_32_16( *pit1_fx, tmp3_fx ), 5 ); /*15 + 5 + 10 -15 */ + *pit1_fx++ = L_tmp; + move32(); + } + + pit1_fx = &coeff_out_fx[add( sub( HQ_GENERIC_HIGH2, 1 ), hq_generic_offset )]; + + exp1 = sub( norm_l( L_tmp1 ), 1 ); + exp2 = norm_l( L_tmp2 ); + tmp1_fx = extract_h( L_shl( L_tmp1, exp1 ) ); + tmp2_fx = extract_h( L_shl( L_tmp2, exp2 ) ); + tmp3_fx = div_s( tmp1_fx, tmp2_fx ); /*15 + exp2 + 15 - (exp1 + 15) */ + tmp3_fx = shr( tmp3_fx, add( 5, sub( exp1, exp2 ) ) ); /*10 */ + tmp3_fx = shr( tmp3_fx, 1 ); + tmp4_fx = mult_r( tmp3_fx, 1638 ); + WHILE( tmp3_fx > 1024 ) + { #ifdef EVS_FUNC_MODIFIED - L_tmp1 = L_shl(Mult_32_16(*pit1_fx , tmp3_fx), 5); /*15 + 5 + 10 -15 */ + L_tmp1 = L_shl( Mult_32_16( *pit1_fx, tmp3_fx ), 5 ); /*15 + 5 + 10 -15 */ #else - L_tmp1 = Mult_32_16(L_shl(*pit1_fx, 5), tmp3_fx); /*15 + 5 + 10 -15 */ + L_tmp1 = Mult_32_16( L_shl( *pit1_fx, 5 ), tmp3_fx ); /*15 + 5 + 10 -15 */ #endif - *pit1_fx-- = L_tmp1; - move32(); - tmp3_fx = sub(tmp3_fx, tmp4_fx); - } - } - - - wfenv_fx = hq_generic_fenv_fx[0]; - move16();/*1 */ - i = 0; - move16(); - tmp2 = add(add(swb_bwe_subband[0], hq_generic_offset), 8); - FOR(n_freq = add(swb_bwe_subband[0], hq_generic_offset); n_freq < tmp2; n_freq++) - { - factor_fx = shl(i, 12);/*15 */ - L_tmp1 = L_mult(sub(32767, factor_fx), fenvL_fx);/*17 */ - L_tmp2 = L_mult(factor_fx, wfenv_fx);/*17 */ - L_tmp1 = L_add(L_tmp1, L_tmp2);/*17 */ - - cs = norm_l(L_tmp1); - tmp = extract_h(L_shl(L_tmp1, cs));/*17 + cs - 16 */ - L_tmp = Mult_32_16(coeff_out_fx[n_freq], tmp);/*12 + 15 + 17 + cs - 16 - 15 */ - coeff_out_fx[n_freq] = L_shr(L_tmp, add(1, cs)); - move32();/*12 */ - i++; - move16(); - } - - k = sub(nenv, 2); - FOR(n_band = 0; n_band < k; n_band++) - { - wfenv_fx = hq_generic_fenv_fx[add(n_band, 1)]; - move16();/*1 */ - - tmp2 = swb_bwe_sm_subband[add(n_band, 1)] + hq_generic_offset; - FOR(i = 0; n_freq < tmp2; i++) - { - L_tmp1 = L_mult(sub(wfenv_fx, hq_generic_fenv_fx[n_band]), smooth_factor_fx[n_band]);/*17 */ - L_tmp1 = Mult_32_16(L_tmp1, shl(i, 10));/*17 + 10 - 15 */ - L_tmp1 = L_add(L_tmp1, L_shl(hq_generic_fenv_fx[n_band], 11));/*12 */ - - cs = norm_l(L_tmp1); - tmp = extract_h(L_shl(L_tmp1, cs));/*12 + cs - 16 */ - L_tmp = Mult_32_16(coeff_out_fx[n_freq], tmp);/*12 + 15 + 12 + cs - 16 - 15 */ - coeff_out_fx[n_freq] = L_shl(L_tmp, sub(4, cs)); - move32();/*12 */ - n_freq++; - } - } - - wfenv_fx = hq_generic_fenv_fx[sub(nenv, 1)]; - move16();/*1 */ - tmp2 = add(swb_bwe_sm_subband[sub(nenv, 1)], hq_generic_offset); - FOR(i = 0; n_freq < tmp2; i++) - { - L_tmp1 = L_mult(sub(wfenv_fx, hq_generic_fenv_fx[sub(nenv, 2)]), smooth_factor_fx[sub(nenv, 2)]);/*17 */ - L_tmp1 = Mult_32_16(L_tmp1, shl(i, 10));/*17 + 10 - 15 */ - L_tmp1 = L_add(L_tmp1, L_shl(hq_generic_fenv_fx[sub(nenv, 2)], 11));/*12 */ - - cs = norm_l(L_tmp1); - tmp = extract_h(L_shl(L_tmp1, cs));/*12 + cs - 16 */ - L_tmp = Mult_32_16(coeff_out_fx[n_freq], tmp);/*12 + 15 + 12 + cs - 16 - 15 */ - coeff_out_fx[n_freq] = L_shl(L_tmp, sub(4, cs)); - move32();/*12 */ - n_freq++; - } - - IF(EQ_16(HQ_mode, HQ_GEN_SWB)) - { - FOR(n_band = sub(nenv, 1); n_band < nenv; ++n_band) - { - wfenv_fx = hq_generic_fenv_fx[n_band]; - move16();/*1 */ - tmp2 = add(swb_bwe_subband[add(n_band, 1)], hq_generic_offset); - FOR(; n_freq < tmp2; n_freq++) - { - L_tmp = Mult_32_16(coeff_out_fx[n_freq], wfenv_fx);/*15 + 12 + 1 - 15 */ - coeff_out_fx[n_freq] = L_shr(L_tmp, 1); - move32();/*12 */ - } - } - } - ELSE - { - test(); - IF(hq_generic_fenv_fx[sub(nenv,1)] - hq_generic_fenv_fx[nenv] > 30 || hq_generic_fenv_fx[nenv] < 10) - { - wfenv_fx = hq_generic_fenv_fx[sub(nenv,1)]; - move16();/*1 */ - FOR(i = 0; n_freq < fb_bwe_subband[0]; i++) - { - L_tmp = Mult_32_16(coeff_out_fx[n_freq], wfenv_fx);/*15 + 12 + 1 - 15 */ - coeff_out_fx[n_freq] = L_shr(L_tmp, 1); - move32();/*12 */ - n_freq++; - } - - FOR(n_band = 0; n_band < DIM_FB; n_band++) - { - wfenv_fx = hq_generic_fenv_fx[add(n_band , nenv)]; - move16();/*1 */ - tmp2 = fb_bwe_subband[add(n_band,1)]; - FOR(i = 0; n_freq < tmp2; i++) - { - L_tmp = Mult_32_16(coeff_out_fx[n_freq], wfenv_fx);/*15 + 12 + 1 - 15 */ - coeff_out_fx[n_freq] = L_shr(L_tmp, 1); - move32();/*12 */ - n_freq++; - } - } - } - ELSE - { - FOR(n_band = 0; n_band < DIM_FB; n_band++) - { - wfenv_fx = hq_generic_fenv_fx[sub(add(n_band,nenv),1)]; - move16();/*1 */ - - FOR(i = 0; n_freq < fb_bwe_sm_subband[n_band]; i++) - { - L_tmp1 = L_mult(sub(wfenv_fx, hq_generic_fenv_fx[add(n_band,nenv)]), fb_smooth_factor_fx[n_band]);/*17 */ - L_tmp1 = Mult_32_16(L_tmp1, shl(i, 9));/*17 + 9 - 15 */ - L_tmp1 = L_add(L_tmp1, L_shl(hq_generic_fenv_fx[add(n_band,nenv)], 10));/*11 */ - - cs = norm_l(L_tmp1); - tmp = extract_h(L_shl(L_tmp1, cs));/*11 + cs - 16 */ - L_tmp = Mult_32_16(coeff_out_fx[n_freq] , tmp);/*12 + 15 + 11 + cs - 16 - 15 */ - coeff_out_fx[n_freq] = L_shl(L_tmp, sub(5, cs)); - move32();/*12 */ - n_freq++; - } - } - - wfenv_fx = hq_generic_fenv_fx[sub(tenv,1)]; - move16();/*1 */ - - FOR(; n_freq < fb_bwe_subband[DIM_FB]; n_freq++) - { - L_tmp = Mult_32_16(coeff_out_fx[n_freq], wfenv_fx);/*15 + 12 + 1 - 15 */ - coeff_out_fx[n_freq] = L_shr(L_tmp, 1); - move32();/*12 */ - } - } - } - - return; -} + *pit1_fx-- = L_tmp1; + move32(); + tmp3_fx = sub( tmp3_fx, tmp4_fx ); + } + } + wfenv_fx = hq_generic_fenv_fx[0]; + move16(); /*1 */ + i = 0; + move16(); + tmp2 = add( add( swb_bwe_subband[0], hq_generic_offset ), 8 ); + FOR( n_freq = add( swb_bwe_subband[0], hq_generic_offset ); n_freq < tmp2; n_freq++ ) + { + factor_fx = shl( i, 12 ); /*15 */ + L_tmp1 = L_mult( sub( 32767, factor_fx ), fenvL_fx ); /*17 */ + L_tmp2 = L_mult( factor_fx, wfenv_fx ); /*17 */ + L_tmp1 = L_add( L_tmp1, L_tmp2 ); /*17 */ + + cs = norm_l( L_tmp1 ); + tmp = extract_h( L_shl( L_tmp1, cs ) ); /*17 + cs - 16 */ + L_tmp = Mult_32_16( coeff_out_fx[n_freq], tmp ); /*12 + 15 + 17 + cs - 16 - 15 */ + coeff_out_fx[n_freq] = L_shr( L_tmp, add( 1, cs ) ); + move32(); /*12 */ + i++; + move16(); + } + + k = sub( nenv, 2 ); + FOR( n_band = 0; n_band < k; n_band++ ) + { + wfenv_fx = hq_generic_fenv_fx[add( n_band, 1 )]; + move16(); /*1 */ + + tmp2 = swb_bwe_sm_subband[add( n_band, 1 )] + hq_generic_offset; + FOR( i = 0; n_freq < tmp2; i++ ) + { + L_tmp1 = L_mult( sub( wfenv_fx, hq_generic_fenv_fx[n_band] ), smooth_factor_fx[n_band] ); /*17 */ + L_tmp1 = Mult_32_16( L_tmp1, shl( i, 10 ) ); /*17 + 10 - 15 */ + L_tmp1 = L_add( L_tmp1, L_shl( hq_generic_fenv_fx[n_band], 11 ) ); /*12 */ + + cs = norm_l( L_tmp1 ); + tmp = extract_h( L_shl( L_tmp1, cs ) ); /*12 + cs - 16 */ + L_tmp = Mult_32_16( coeff_out_fx[n_freq], tmp ); /*12 + 15 + 12 + cs - 16 - 15 */ + coeff_out_fx[n_freq] = L_shl( L_tmp, sub( 4, cs ) ); + move32(); /*12 */ + n_freq++; + } + } + + wfenv_fx = hq_generic_fenv_fx[sub( nenv, 1 )]; + move16(); /*1 */ + tmp2 = add( swb_bwe_sm_subband[sub( nenv, 1 )], hq_generic_offset ); + FOR( i = 0; n_freq < tmp2; i++ ) + { + L_tmp1 = L_mult( sub( wfenv_fx, hq_generic_fenv_fx[sub( nenv, 2 )] ), smooth_factor_fx[sub( nenv, 2 )] ); /*17 */ + L_tmp1 = Mult_32_16( L_tmp1, shl( i, 10 ) ); /*17 + 10 - 15 */ + L_tmp1 = L_add( L_tmp1, L_shl( hq_generic_fenv_fx[sub( nenv, 2 )], 11 ) ); /*12 */ + + cs = norm_l( L_tmp1 ); + tmp = extract_h( L_shl( L_tmp1, cs ) ); /*12 + cs - 16 */ + L_tmp = Mult_32_16( coeff_out_fx[n_freq], tmp ); /*12 + 15 + 12 + cs - 16 - 15 */ + coeff_out_fx[n_freq] = L_shl( L_tmp, sub( 4, cs ) ); + move32(); /*12 */ + n_freq++; + } + + IF( EQ_16( HQ_mode, HQ_GEN_SWB ) ) + { + FOR( n_band = sub( nenv, 1 ); n_band < nenv; ++n_band ) + { + wfenv_fx = hq_generic_fenv_fx[n_band]; + move16(); /*1 */ + tmp2 = add( swb_bwe_subband[add( n_band, 1 )], hq_generic_offset ); + FOR( ; n_freq < tmp2; n_freq++ ) + { + L_tmp = Mult_32_16( coeff_out_fx[n_freq], wfenv_fx ); /*15 + 12 + 1 - 15 */ + coeff_out_fx[n_freq] = L_shr( L_tmp, 1 ); + move32(); /*12 */ + } + } + } + ELSE + { + test(); + IF( hq_generic_fenv_fx[sub( nenv, 1 )] - hq_generic_fenv_fx[nenv] > 30 || hq_generic_fenv_fx[nenv] < 10 ) + { + wfenv_fx = hq_generic_fenv_fx[sub( nenv, 1 )]; + move16(); /*1 */ + FOR( i = 0; n_freq < fb_bwe_subband[0]; i++ ) + { + L_tmp = Mult_32_16( coeff_out_fx[n_freq], wfenv_fx ); /*15 + 12 + 1 - 15 */ + coeff_out_fx[n_freq] = L_shr( L_tmp, 1 ); + move32(); /*12 */ + n_freq++; + } + + FOR( n_band = 0; n_band < DIM_FB; n_band++ ) + { + wfenv_fx = hq_generic_fenv_fx[add( n_band, nenv )]; + move16(); /*1 */ + tmp2 = fb_bwe_subband[add( n_band, 1 )]; + FOR( i = 0; n_freq < tmp2; i++ ) + { + L_tmp = Mult_32_16( coeff_out_fx[n_freq], wfenv_fx ); /*15 + 12 + 1 - 15 */ + coeff_out_fx[n_freq] = L_shr( L_tmp, 1 ); + move32(); /*12 */ + n_freq++; + } + } + } + ELSE + { + FOR( n_band = 0; n_band < DIM_FB; n_band++ ) + { + wfenv_fx = hq_generic_fenv_fx[sub( add( n_band, nenv ), 1 )]; + move16(); /*1 */ + + FOR( i = 0; n_freq < fb_bwe_sm_subband[n_band]; i++ ) + { + L_tmp1 = L_mult( sub( wfenv_fx, hq_generic_fenv_fx[add( n_band, nenv )] ), fb_smooth_factor_fx[n_band] ); /*17 */ + L_tmp1 = Mult_32_16( L_tmp1, shl( i, 9 ) ); /*17 + 9 - 15 */ + L_tmp1 = L_add( L_tmp1, L_shl( hq_generic_fenv_fx[add( n_band, nenv )], 10 ) ); /*11 */ + + cs = norm_l( L_tmp1 ); + tmp = extract_h( L_shl( L_tmp1, cs ) ); /*11 + cs - 16 */ + L_tmp = Mult_32_16( coeff_out_fx[n_freq], tmp ); /*12 + 15 + 11 + cs - 16 - 15 */ + coeff_out_fx[n_freq] = L_shl( L_tmp, sub( 5, cs ) ); + move32(); /*12 */ + n_freq++; + } + } + + wfenv_fx = hq_generic_fenv_fx[sub( tenv, 1 )]; + move16(); /*1 */ + + FOR( ; n_freq < fb_bwe_subband[DIM_FB]; n_freq++ ) + { + L_tmp = Mult_32_16( coeff_out_fx[n_freq], wfenv_fx ); /*15 + 12 + 1 - 15 */ + coeff_out_fx[n_freq] = L_shr( L_tmp, 1 ); + move32(); /*12 */ + } + } + } + + return; +} + /*-------------------------------------------------------------------* * save_old_syn() @@ -3161,28 +3161,28 @@ void hq_generic_decoding_fx( *-------------------------------------------------------------------*/ void save_old_syn_fx( - const Word16 L_frame, /* i : frame length */ - const Word16 syn[], /* i : ACELP synthesis */ - Word16 old_syn[], /* o : old synthesis buffer */ - Word16 old_syn_mem[], /* i/o: old synthesis buffer memory */ - const Word16 preemph_fac, /* i : preemphasis factor */ - Word16 *mem_deemph /* i/o: deemphasis filter memory */ + const Word16 L_frame, /* i : frame length */ + const Word16 syn[], /* i : ACELP synthesis */ + Word16 old_syn[], /* o : old synthesis buffer */ + Word16 old_syn_mem[], /* i/o: old synthesis buffer memory */ + const Word16 preemph_fac, /* i : preemphasis factor */ + Word16 *mem_deemph /* i/o: deemphasis filter memory */ ) { - Word16 tmps; - - tmps = NS2SA(16000, DELAY_FD_BWE_ENC_16k_NS); - move16(); - if (EQ_16(L_frame, L_FRAME)) - { - tmps = NS2SA(12800, DELAY_FD_BWE_ENC_12k8_NS); - move16(); - } - Copy(old_syn_mem, old_syn, tmps); - Copy(syn, old_syn + tmps, L_frame - tmps); - Copy(syn + L_frame - tmps, old_syn_mem, tmps); - - deemph_fx(old_syn, preemph_fac, L_frame, mem_deemph); - - return; + Word16 tmps; + + tmps = NS2SA( 16000, DELAY_FD_BWE_ENC_16k_NS ); + move16(); + if ( EQ_16( L_frame, L_FRAME ) ) + { + tmps = NS2SA( 12800, DELAY_FD_BWE_ENC_12k8_NS ); + move16(); + } + Copy( old_syn_mem, old_syn, tmps ); + Copy( syn, old_syn + tmps, L_frame - tmps ); + Copy( syn + L_frame - tmps, old_syn_mem, tmps ); + + deemph_fx( old_syn, preemph_fac, L_frame, mem_deemph ); + + return; } diff --git a/lib_com/swb_bwe_com_hr_fx.c b/lib_com/swb_bwe_com_hr_fx.c index c7714b099..da8997a26 100644 --- a/lib_com/swb_bwe_com_hr_fx.c +++ b/lib_com/swb_bwe_com_hr_fx.c @@ -13,54 +13,53 @@ * SWB BWE HR noise filling of zero subbands *-------------------------------------------------------------------*/ static void swb_hr_nonzero_subband_noise_fill_fx( - const Word16 tilt_wb_fx, /* i : tilt of wideband signal */ - Word16 *t_audio_fx, /* i/o: mdct spectrum */ - Word16 *bwe_highrate_seed, /* i/o: seed of random noise */ - const Word16 N, /* i : length of subband */ - const Word16 Nsv, /* i : number of subband */ - Word16 Q_audio -) + const Word16 tilt_wb_fx, /* i : tilt of wideband signal */ + Word16 *t_audio_fx, /* i/o: mdct spectrum */ + Word16 *bwe_highrate_seed, /* i/o: seed of random noise */ + const Word16 N, /* i : length of subband */ + const Word16 Nsv, /* i : number of subband */ + Word16 Q_audio ) { Word16 i, j; Word16 *ptr_fx; Word16 min_bwe_fx, max_bwe_fx, tmpF_fx; Word16 tmp; - IF( GT_16(tilt_wb_fx, 10240)) + IF( GT_16( tilt_wb_fx, 10240 ) ) { - FOR( i=0; i 0 ) + max_bwe_fx = s_max( tmpF_fx, max_bwe_fx ); + if ( tmpF_fx > 0 ) { - min_bwe_fx = s_min(tmpF_fx, min_bwe_fx); + min_bwe_fx = s_min( tmpF_fx, min_bwe_fx ); } } test(); - if( EQ_16(max_bwe_fx, min_bwe_fx)&>_16(min_bwe_fx,shl(1,Q_audio))) + if ( EQ_16( max_bwe_fx, min_bwe_fx ) && GT_16( min_bwe_fx, shl( 1, Q_audio ) ) ) { - min_bwe_fx = mult_r(min_bwe_fx, 16384); + min_bwe_fx = mult_r( min_bwe_fx, 16384 ); } ptr_fx = &t_audio_fx[tmp]; - FOR( j=0; jQ15 */ + beta_fx = div_s( 1600, pitch_fx ); /*Q15+4-4 ->Q15 */ } } @@ -144,7 +142,7 @@ void swb_hr_noise_fill_fx( i = 1; move16(); test(); - WHILE( LT_16(i, Nsv)&&nq[i]==0) + WHILE( LT_16( i, Nsv ) && nq[i] == 0 ) { i++; move16(); @@ -154,51 +152,51 @@ void swb_hr_noise_fill_fx( pos_start = i; move16(); test(); - WHILE( LT_16(i, Nsv)&&nq[i]!=0) + WHILE( LT_16( i, Nsv ) && nq[i] != 0 ) { i++; move16(); test(); } - pos_end = sub(i, 1); + pos_end = sub( i, 1 ); move16(); - IF( GT_16(pos_end, shl(pos_start, 1))) + IF( GT_16( pos_end, shl( pos_start, 1 ) ) ) { - pos_end = sub(shl(pos_start, 1), 1); + pos_end = sub( shl( pos_start, 1 ), 1 ); move16(); } incr = pos_end; move16(); - FOR( j = sub(pos_start, 1); j >= 0; j-- ) + FOR( j = sub( pos_start, 1 ); j >= 0; j-- ) { - tmp = shl(j, 3); - tmp1 = shl(incr, 3); - FOR( k=0; k= pos_start; j-- ) + FOR( j = sub( pos_end, 1 ); j >= pos_start; j-- ) { - tmp = shl(j, 3); - tmp1 = shl(incr, 3); - FOR( k=0; k - /*-------------------------------------------------------------------* - * GetPredictedSignal() - * - * Routine for calculating the predicted signal - *-------------------------------------------------------------------*/ +/*-------------------------------------------------------------------* + * GetPredictedSignal() + * + * Routine for calculating the predicted signal + *-------------------------------------------------------------------*/ void GetPredictedSignal_fx( - const Word16 *predBuf_fx, /* i: Q8 */ - Word32 *L_outBuf, /* o: Q9 */ - const Word16 lag_fx, /* i: Q0 */ - const Word16 fLen_fx, /* i: Q0 */ - const Word16 lagGains_fx, /* i: Qgain */ - const Word16 Qgain /* i: Q0 */ + const Word16 *predBuf_fx, /* i: Q8 */ + Word32 *L_outBuf, /* o: Q9 */ + const Word16 lag_fx, /* i: Q0 */ + const Word16 fLen_fx, /* i: Q0 */ + const Word16 lagGains_fx, /* i: Qgain */ + const Word16 Qgain /* i: Q0 */ ) { - Word16 i; - const Word16 *p_predBuf; - Word32 *p_L_outBuf; - - p_predBuf = predBuf_fx + lag_fx; - p_L_outBuf = L_outBuf; - - FOR(i = 0; i < fLen_fx; i++) - { - /* Q8 x Q0 --> Q9, 9+7-16=Q0 */ - *p_L_outBuf++ = L_shr(L_mult(*p_predBuf++, lagGains_fx), Qgain); - move32(); - } + Word16 i; + const Word16 *p_predBuf; + Word32 *p_L_outBuf; + + p_predBuf = predBuf_fx + lag_fx; + p_L_outBuf = L_outBuf; + + FOR( i = 0; i < fLen_fx; i++ ) + { + /* Q8 x Q0 --> Q9, 9+7-16=Q0 */ + *p_L_outBuf++ = L_shr( L_mult( *p_predBuf++, lagGains_fx ), Qgain ); + move32(); + } } /*-------------------------------------------------------------------* @@ -73,96 +73,95 @@ void GetPredictedSignal_fx( * * Harmonic frequency decision matrix *-------------------------------------------------------------------*/ -static -void est_freq_har_decis_fx( - Word16 *har_freq_est1, /* o: harmonic analysis 1 */ - Word16 *har_freq_est2, /* o: harmonic analysis 2 */ - Word16 sharp, /* i: pka-avg for group 1 */ - Word16 sharp1, /* i: pka-avg for group 2 */ - Word16 hfe_est_countk1, /* i: group pks count 1 */ - Word16 hfe_est_countk2, /* i: group pks count 2 */ - Word16 k, /* i: group count */ - Word16 k1, /* i: */ - Word16 k2, /* i: */ - Word16 *prev_frm_hfe2 /* i: harmonic estimation */ +static void est_freq_har_decis_fx( + Word16 *har_freq_est1, /* o: harmonic analysis 1 */ + Word16 *har_freq_est2, /* o: harmonic analysis 2 */ + Word16 sharp, /* i: pka-avg for group 1 */ + Word16 sharp1, /* i: pka-avg for group 2 */ + Word16 hfe_est_countk1, /* i: group pks count 1 */ + Word16 hfe_est_countk2, /* i: group pks count 2 */ + Word16 k, /* i: group count */ + Word16 k1, /* i: */ + Word16 k2, /* i: */ + Word16 *prev_frm_hfe2 /* i: harmonic estimation */ ) { - Word16 temp_hfe2 = 0; - Word16 har_freq_est2_2; - Word16 prev_frm_hfe2_2; - - IF(k != 0) - { - *har_freq_est1 = div_s_ss(sharp, k); - } - - test(); - test(); - IF(GT_16(k1, 1)) - { - *har_freq_est2 = div_s_ss(sharp1, k1); - } - ELSE IF(LT_16(k1, 2) && (k2 != 0 || GT_16(k, 1))) - { - *har_freq_est2 = *har_freq_est1; - move16(); - } - ELSE - { - test(); - test(); - test(); - IF((hfe_est_countk1 != 0 || hfe_est_countk2 != 0) && (k1 == 0 && k2 == 0)) - { - *har_freq_est2 = (*har_freq_est1); - move16(); - } - ELSE - { - *har_freq_est2 = shl(*har_freq_est1, 1); - move16(); - } - } - - /* Consider Estimation Error upto 200Hz */ - test(); - test(); - test(); - har_freq_est2_2 = shl(*har_freq_est2, 1); - prev_frm_hfe2_2 = shl(*prev_frm_hfe2, 1); - IF(*prev_frm_hfe2 != 0 && (LT_16(abs_s(sub(*prev_frm_hfe2, *har_freq_est2)), 10) || LT_16(abs_s(sub(*prev_frm_hfe2, har_freq_est2_2)), 10))) - { - *har_freq_est2 = *prev_frm_hfe2; - move16(); - } - ELSE IF(*prev_frm_hfe2 != 0 && LT_16(abs_s(sub(*har_freq_est2, prev_frm_hfe2_2)), 10)) - { - *har_freq_est2 = prev_frm_hfe2_2; - move16(); - } - ELSE - { - temp_hfe2 = shr(add(*prev_frm_hfe2, *har_freq_est2), 1); - move16(); - - IF(LT_16(abs_s(sub(temp_hfe2, *prev_frm_hfe2)), 2)) - { - temp_hfe2 = *prev_frm_hfe2; - move16(); - *har_freq_est2 = temp_hfe2; - move16(); - } - } - - test(); - test(); - if (LT_16(*har_freq_est2, *har_freq_est1) && (GT_16(k, 1) && LT_16(k1, 2))) - { - *har_freq_est2 = *har_freq_est1; - move16(); - } - - return; + Word16 temp_hfe2 = 0; + Word16 har_freq_est2_2; + Word16 prev_frm_hfe2_2; + + IF( k != 0 ) + { + *har_freq_est1 = div_s_ss( sharp, k ); + } + + test(); + test(); + IF( GT_16( k1, 1 ) ) + { + *har_freq_est2 = div_s_ss( sharp1, k1 ); + } + ELSE IF( LT_16( k1, 2 ) && ( k2 != 0 || GT_16( k, 1 ) ) ) + { + *har_freq_est2 = *har_freq_est1; + move16(); + } + ELSE + { + test(); + test(); + test(); + IF( ( hfe_est_countk1 != 0 || hfe_est_countk2 != 0 ) && ( k1 == 0 && k2 == 0 ) ) + { + *har_freq_est2 = ( *har_freq_est1 ); + move16(); + } + ELSE + { + *har_freq_est2 = shl( *har_freq_est1, 1 ); + move16(); + } + } + + /* Consider Estimation Error upto 200Hz */ + test(); + test(); + test(); + har_freq_est2_2 = shl( *har_freq_est2, 1 ); + prev_frm_hfe2_2 = shl( *prev_frm_hfe2, 1 ); + IF( *prev_frm_hfe2 != 0 && ( LT_16( abs_s( sub( *prev_frm_hfe2, *har_freq_est2 ) ), 10 ) || LT_16( abs_s( sub( *prev_frm_hfe2, har_freq_est2_2 ) ), 10 ) ) ) + { + *har_freq_est2 = *prev_frm_hfe2; + move16(); + } + ELSE IF( *prev_frm_hfe2 != 0 && LT_16( abs_s( sub( *har_freq_est2, prev_frm_hfe2_2 ) ), 10 ) ) + { + *har_freq_est2 = prev_frm_hfe2_2; + move16(); + } + ELSE + { + temp_hfe2 = shr( add( *prev_frm_hfe2, *har_freq_est2 ), 1 ); + move16(); + + IF( LT_16( abs_s( sub( temp_hfe2, *prev_frm_hfe2 ) ), 2 ) ) + { + temp_hfe2 = *prev_frm_hfe2; + move16(); + *har_freq_est2 = temp_hfe2; + move16(); + } + } + + test(); + test(); + if ( LT_16( *har_freq_est2, *har_freq_est1 ) && ( GT_16( k, 1 ) && LT_16( k1, 2 ) ) ) + { + *har_freq_est2 = *har_freq_est1; + move16(); + } + + return; } /*--------------------------------------------------------------------------* @@ -172,600 +171,602 @@ void est_freq_har_decis_fx( *--------------------------------------------------------------------------*/ Word16 har_est_fx( - Word32 L_spectra[], /* i : coded spectrum */ - Word16 N, /* i : length of the desired spectrum */ - Word16 *har_freq_est1, /* i/o: Estimation harmonics 1 */ - Word16 *har_freq_est2, /* o : Estimation harmonics 2 */ - Word16 *flag_dis, /* i/o: flag for BWE reconstruction */ - Word16 *prev_frm_hfe2, /* i/o: Estimated harmonic update */ - const Word16 subband_search_offset[], /* i : Subband Search range */ - const Word16 sbWidth[], /* i : Subband Search range */ - Word16 *prev_stab_hfe2 /* i/o: Estimated harmonic position */ + Word32 L_spectra[], /* i : coded spectrum */ + Word16 N, /* i : length of the desired spectrum */ + Word16 *har_freq_est1, /* i/o: Estimation harmonics 1 */ + Word16 *har_freq_est2, /* o : Estimation harmonics 2 */ + Word16 *flag_dis, /* i/o: flag for BWE reconstruction */ + Word16 *prev_frm_hfe2, /* i/o: Estimated harmonic update */ + const Word16 subband_search_offset[], /* i : Subband Search range */ + const Word16 sbWidth[], /* i : Subband Search range */ + Word16 *prev_stab_hfe2 /* i/o: Estimated harmonic position */ ) { - Word32 L_peak; - Word32 L_input_abs[L_FRAME32k], L_blk_peak[30]; - Word32 L_blk_peak_te[30]; - Word32 L_blk_peak_max; - Word32 *p_L_blk_peak, *pm1_L_blk_peak; - - Word16 i, j, q, k, k1, k2; - Word16 blk_end, blk_st; - Word16 peak_pos, blk_peak_pos[30], diff_peak_pos[30], sharp, sharp1; - Word16 min_har_pos; - Word16 blk_peak_pos_te[30]; - Word16 temp; - Word16 hfe_est_countk, hfe_est_countk1, hfe_est_countk2; - Word16 r1, r2, r3; - Word16 start_pos; - Word16 blk_peak_pos_max; - - Word16 nlags, nlags_half, ct_hfsb2, sum_diff; - Word16 blk_peak_pos_hfsb2[30], diff_peak_pos_hfsb2[30]; - Word16 rem_hfe2, q_diffpos_hfe2, diff_posmax_hfe2, q_diffpos_prevhfe2; - - Word16 blk_end_LEN; - - Word16 *p_blk_peak_pos, *pm1_blk_peak_pos; - Word16 *p_diff_peak_pos, *pm1_diff_peak_pos; - Word16 blk_peak_max_idx, blk_peak_pos_max_diff, diff_peak_pos_te[30]; - Word16 thr1, thr2; - - set32_fx(L_input_abs, 0x0L, L_FRAME32k); - set32_fx(L_blk_peak, 0x0L, 30); - set16_fx(blk_peak_pos, 0, 30); - set16_fx(blk_peak_pos_te, 0, 30); - - rem_hfe2 = 0; - move16(); - q_diffpos_hfe2 = 0; - move16(); - diff_posmax_hfe2 = 0; - move16(); - q_diffpos_prevhfe2 = 0; - move16(); - - set16_fx(diff_peak_pos, 0, 30); - - r1 = SWB_HAR_RAN1; - move16(); - r2 = SWB_HAR_RAN2; - move16(); - r3 = SWB_HAR_RAN3; - move16(); - start_pos = r1; - move16(); - - /* Copy the abs values of LF spectrum*/ - FOR(i = start_pos; i < N; i++) - { - L_input_abs[i] = L_abs(L_spectra[i]); - move32(); - } - - blk_end = div_s_ss(N, LR_BLK_LEN); - blk_st = div_s_ss(start_pos, LR_BLK_LEN); - - /*if( N/(LR_BLK_LEN) - blk_end > 0.0f) */ - blk_end_LEN = i_mult(blk_end, LR_BLK_LEN); - if (GT_16(N, blk_end_LEN)) - { - blk_end = add(blk_end, 1); - } - - /* initialization of over buffer for fractional point */ - temp = i_mult(blk_end, LR_BLK_LEN); - FOR(i = N; i < temp; i++) - { - L_input_abs[i] = L_deposit_l(0); - } - - q = start_pos; - move16(); - - /* Block Processing, to detect the spectral peaks*/ - FOR(i = blk_st; i < blk_end; i++) - { - L_peak = L_deposit_l(0); - peak_pos = 0; - move16(); - - FOR(j = 0; j < LR_BLK_LEN; j++) - { - IF(GT_32(L_input_abs[q], L_peak)) - { - L_peak = L_input_abs[q]; - move32(); - peak_pos = q; - move16(); - } - - test(); - test(); - test(); - IF(GT_16(i, blk_st) && L_input_abs[q] != 0x0L && EQ_32(L_input_abs[q], L_peak) && LT_16(sub(peak_pos, blk_peak_pos[i - 1]), LR_HLF_PK_BLK_LEN)) - { - L_peak = L_input_abs[q]; - move32(); - peak_pos = q; - move16(); - } - q = add(q, 1); - } - - L_blk_peak[i] = L_peak; - move32(); - blk_peak_pos[i] = peak_pos; - move16(); - } - - p_L_blk_peak = &L_blk_peak[blk_st]; - pm1_L_blk_peak = &L_blk_peak[sub(blk_st, 1)]; - p_blk_peak_pos = &blk_peak_pos[blk_st]; - pm1_blk_peak_pos = &blk_peak_pos[sub(blk_st, 1)]; - FOR(i = blk_st; i < blk_end; i++) - { - IF(GT_16(i, blk_st)) - { - - test(); - IF(*p_blk_peak_pos != 0 && *pm1_blk_peak_pos != 0) - { - IF(LT_16(sub(*p_blk_peak_pos, *pm1_blk_peak_pos), LR_LOWBAND_DIF_PK_LEN)) - { - IF(GT_32(*p_L_blk_peak, *pm1_L_blk_peak)) - { - *pm1_L_blk_peak = L_deposit_l(0); - *pm1_blk_peak_pos = 0; - move16(); - } - ELSE - { - *p_L_blk_peak = *pm1_L_blk_peak; - move32(); - *p_blk_peak_pos = *pm1_blk_peak_pos; - move16(); - *pm1_L_blk_peak = L_deposit_l(0); - *pm1_blk_peak_pos = 0; - move16(); - } - } - } - } - p_L_blk_peak++; - pm1_L_blk_peak++; - - p_blk_peak_pos++; - pm1_blk_peak_pos++; - } - - /* peak counts in each group */ - j = 0; - move16(); - hfe_est_countk = 0; - move16(); - hfe_est_countk1 = 0; - move16(); - hfe_est_countk2 = 0; - move16(); - FOR(i = blk_st; i < blk_end; i++) - { - IF(blk_peak_pos[i] != 0) - { - blk_peak_pos_te[j] = blk_peak_pos[i]; - move16(); - IF(LT_16(blk_peak_pos[i], r2)) - { - hfe_est_countk = add(hfe_est_countk, 1); - } - ELSE IF(LT_16(blk_peak_pos[i], r3)) - { - hfe_est_countk1 = add(hfe_est_countk1, 1); - } - ELSE - { - hfe_est_countk2 = add(hfe_est_countk2, 1); - } - L_blk_peak_te[j] = L_blk_peak[i]; - move32(); - j = add(j, 1); - } - } - - min_har_pos = SWB_HAR_RAN1; - move16(); - temp = 0; - move16(); - L_blk_peak_max = L_blk_peak_te[0]; - move32(); - blk_peak_pos_max = blk_peak_pos_te[0]; - move16(); - blk_peak_max_idx = 0; - move16(); - - - p_diff_peak_pos = &diff_peak_pos[1]; - pm1_diff_peak_pos = &diff_peak_pos[1 - 1]; - FOR(i = 1; i < j; i++) - { - *pm1_diff_peak_pos = sub(blk_peak_pos_te[i], blk_peak_pos_te[sub(i, 1)]); - if (LE_16(*pm1_diff_peak_pos, min_har_pos)) - { - min_har_pos = *pm1_diff_peak_pos; - move16(); - } - - IF(GT_32(L_blk_peak_te[sub(i, 1)], L_blk_peak_max)) - { - L_blk_peak_max = L_blk_peak_te[sub(i, 1)]; - move32(); - blk_peak_pos_max = blk_peak_pos_te[sub(i, 1)]; - move16(); - blk_peak_max_idx = sub(i, 1); - } - - temp = add(temp, 1); - - p_diff_peak_pos++; - pm1_diff_peak_pos++; - } - blk_peak_pos_max_diff = diff_peak_pos[blk_peak_max_idx]; - move16(); - - /* Decision for BWE reconstruction */ - test(); - test(); - test(); - IF((LT_16(hfe_est_countk, 2) && LT_16(hfe_est_countk1, 2) && LT_16(hfe_est_countk2, 2)) || GE_16(min_har_pos, SWB_HAR_RAN1)) - { - *flag_dis = 0; - move16(); - test(); - test(); - test(); - if ((EQ_16(hfe_est_countk, 1) && EQ_16(hfe_est_countk1, 1)) && (EQ_16(hfe_est_countk2, 1) || hfe_est_countk2 == 0)) - { - *flag_dis = 1; - move16(); - } - } - thr1 = add(blk_peak_pos_max_diff, LR_LOWBAND_DIF_PK_LEN); - FOR(i = 0; i < temp; i++) - { - if (LT_16(thr1, diff_peak_pos[i])) - { - diff_peak_pos[i] = 0; - move16(); - } - } - Copy(diff_peak_pos, diff_peak_pos_te, temp); - set16_fx(diff_peak_pos, -1, temp); - j = 0; - FOR(i = 0; i < temp; i++) - { - IF(diff_peak_pos_te[i] != 0) - { - diff_peak_pos[j] = diff_peak_pos_te[i]; - move16(); - j = add(j, 1); - } - } - temp = j; - move16(); - - /* harmonic estimation analysis to perform BWE Reconstruction */ - IF(*flag_dis) - { - sharp = 0; - move16(); - k = 0; - move16(); - k1 = 0; - move16(); - sharp1 = 0; - move16(); - k2 = 0; - move16(); - - q = 1; - move16(); - thr1 = add(min_har_pos, LR_LOWBAND_DIF_PK_LEN); - thr2 = add(min_har_pos, shl(LR_LOWBAND_DIF_PK_LEN, 1)); - FOR(i = 0; i < temp; i++) - { - test(); - test(); - IF(LE_16(diff_peak_pos[i], thr1) && diff_peak_pos[i] > 0) - { - sharp = add(sharp, diff_peak_pos[i]); - k = add(k, 1); - } - ELSE IF(LE_16(diff_peak_pos[i], thr2) && diff_peak_pos[i] > 0) - { - sharp1 = add(sharp1, diff_peak_pos[i]); - k1 = add(k1, 1); - } - ELSE IF(diff_peak_pos[i] > 0) - { - k2 = add(k2, 1); - } - q = add(q, 1); - } - - est_freq_har_decis_fx(har_freq_est1, har_freq_est2, sharp, sharp1, hfe_est_countk1, hfe_est_countk2, k, k1, k2, prev_frm_hfe2); - - blk_peak_pos_max = blk_peak_pos_te[sub(temp, 1)]; - move16(); - - test(); - test(); - IF((*prev_stab_hfe2) > 0 && (*prev_frm_hfe2) > 0 && *prev_stab_hfe2 < N) - { - rem_hfe2 = sub(*har_freq_est2, extract_h(L_shl(L_mult(div_s_ss(*har_freq_est2, *prev_frm_hfe2), *prev_frm_hfe2), 15))); - diff_posmax_hfe2 = abs_s(sub(blk_peak_pos_max, *prev_stab_hfe2)); - IF(rem_hfe2 == 0) - { - test(); - IF(LT_16(diff_posmax_hfe2, 9) || *har_freq_est2 == 0) - { - blk_peak_pos_max = *prev_stab_hfe2; - move16(); - } - ELSE - { - q_diffpos_hfe2 = div_s_ss(diff_posmax_hfe2, *har_freq_est2); - q_diffpos_prevhfe2 = div_s_ss(diff_posmax_hfe2, *prev_frm_hfe2); - test(); - IF(LT_16(q_diffpos_hfe2, 10) || LT_16(q_diffpos_prevhfe2,10)) - { - blk_peak_pos_max = *prev_stab_hfe2; - move16(); - } - ELSE - { - *prev_stab_hfe2 = blk_peak_pos_max; - move16(); - } - } - } - ELSE - { - *prev_stab_hfe2 = blk_peak_pos_max; - move16(); - } - } - ELSE - { - *prev_stab_hfe2 = blk_peak_pos_max; - move16(); - } - - test(); - if (*har_freq_est1 == 0 || *har_freq_est2 == 0) - { - *flag_dis = 0; - move16(); - } - } - - IF(*flag_dis == 0) - { - IF(*prev_frm_hfe2 != 0) - { - *har_freq_est2 = *prev_frm_hfe2; - move16(); - } - ELSE - { - nlags = shl(1, bits_lagIndices_mode0_Har[0]); - nlags_half = shr(nlags, 1); - ct_hfsb2 = 0; - move16(); - FOR(i = 0; i < j; i++) - { - test(); - IF(GE_16(blk_peak_pos_te[i], sub(subband_search_offset[0], nlags_half)) - && - LT_16(blk_peak_pos_te[i], add(add(subband_search_offset[0], sbWidth[0]), nlags_half))) - { - blk_peak_pos_hfsb2[ct_hfsb2] = blk_peak_pos_te[i]; - move16(); - ct_hfsb2 = add(ct_hfsb2, 1); - move16(); - } - } - - IF(GT_16(ct_hfsb2, 1)) - { - sum_diff = 0; - move16(); - FOR(i = 1; i < ct_hfsb2; i++) - { - diff_peak_pos_hfsb2[i - 1] = sub(blk_peak_pos_hfsb2[i], blk_peak_pos_hfsb2[i - 1]); - sum_diff = add(sum_diff, diff_peak_pos_hfsb2[i - 1]); - } - *har_freq_est2 = div_s_ss(sum_diff, ct_hfsb2); - } - ELSE - { - *har_freq_est2 = min_har_pos; - move16(); - } - } - } - return blk_peak_pos_max; + Word32 L_peak; + Word32 L_input_abs[L_FRAME32k], L_blk_peak[30]; + Word32 L_blk_peak_te[30]; + Word32 L_blk_peak_max; + Word32 *p_L_blk_peak, *pm1_L_blk_peak; + + Word16 i, j, q, k, k1, k2; + Word16 blk_end, blk_st; + Word16 peak_pos, blk_peak_pos[30], diff_peak_pos[30], sharp, sharp1; + Word16 min_har_pos; + Word16 blk_peak_pos_te[30]; + Word16 temp; + Word16 hfe_est_countk, hfe_est_countk1, hfe_est_countk2; + Word16 r1, r2, r3; + Word16 start_pos; + Word16 blk_peak_pos_max; + + Word16 nlags, nlags_half, ct_hfsb2, sum_diff; + Word16 blk_peak_pos_hfsb2[30], diff_peak_pos_hfsb2[30]; + Word16 rem_hfe2, q_diffpos_hfe2, diff_posmax_hfe2, q_diffpos_prevhfe2; + + Word16 blk_end_LEN; + + Word16 *p_blk_peak_pos, *pm1_blk_peak_pos; + Word16 *p_diff_peak_pos, *pm1_diff_peak_pos; + Word16 blk_peak_max_idx, blk_peak_pos_max_diff, diff_peak_pos_te[30]; + Word16 thr1, thr2; + + set32_fx( L_input_abs, 0x0L, L_FRAME32k ); + set32_fx( L_blk_peak, 0x0L, 30 ); + set16_fx( blk_peak_pos, 0, 30 ); + set16_fx( blk_peak_pos_te, 0, 30 ); + + rem_hfe2 = 0; + move16(); + q_diffpos_hfe2 = 0; + move16(); + diff_posmax_hfe2 = 0; + move16(); + q_diffpos_prevhfe2 = 0; + move16(); + + set16_fx( diff_peak_pos, 0, 30 ); + + r1 = SWB_HAR_RAN1; + move16(); + r2 = SWB_HAR_RAN2; + move16(); + r3 = SWB_HAR_RAN3; + move16(); + start_pos = r1; + move16(); + + /* Copy the abs values of LF spectrum*/ + FOR( i = start_pos; i < N; i++ ) + { + L_input_abs[i] = L_abs( L_spectra[i] ); + move32(); + } + + blk_end = div_s_ss( N, LR_BLK_LEN ); + blk_st = div_s_ss( start_pos, LR_BLK_LEN ); + + /*if( N/(LR_BLK_LEN) - blk_end > 0.0f) */ + blk_end_LEN = i_mult( blk_end, LR_BLK_LEN ); + if ( GT_16( N, blk_end_LEN ) ) + { + blk_end = add( blk_end, 1 ); + } + + /* initialization of over buffer for fractional point */ + temp = i_mult( blk_end, LR_BLK_LEN ); + FOR( i = N; i < temp; i++ ) + { + L_input_abs[i] = L_deposit_l( 0 ); + } + + q = start_pos; + move16(); + + /* Block Processing, to detect the spectral peaks*/ + FOR( i = blk_st; i < blk_end; i++ ) + { + L_peak = L_deposit_l( 0 ); + peak_pos = 0; + move16(); + + FOR( j = 0; j < LR_BLK_LEN; j++ ) + { + IF( GT_32( L_input_abs[q], L_peak ) ) + { + L_peak = L_input_abs[q]; + move32(); + peak_pos = q; + move16(); + } + + test(); + test(); + test(); + IF( GT_16( i, blk_st ) && L_input_abs[q] != 0x0L && EQ_32( L_input_abs[q], L_peak ) && LT_16( sub( peak_pos, blk_peak_pos[i - 1] ), LR_HLF_PK_BLK_LEN ) ) + { + L_peak = L_input_abs[q]; + move32(); + peak_pos = q; + move16(); + } + q = add( q, 1 ); + } + + L_blk_peak[i] = L_peak; + move32(); + blk_peak_pos[i] = peak_pos; + move16(); + } + + p_L_blk_peak = &L_blk_peak[blk_st]; + pm1_L_blk_peak = &L_blk_peak[sub( blk_st, 1 )]; + p_blk_peak_pos = &blk_peak_pos[blk_st]; + pm1_blk_peak_pos = &blk_peak_pos[sub( blk_st, 1 )]; + FOR( i = blk_st; i < blk_end; i++ ) + { + IF( GT_16( i, blk_st ) ) + { + + test(); + IF( *p_blk_peak_pos != 0 && *pm1_blk_peak_pos != 0 ) + { + IF( LT_16( sub( *p_blk_peak_pos, *pm1_blk_peak_pos ), LR_LOWBAND_DIF_PK_LEN ) ) + { + IF( GT_32( *p_L_blk_peak, *pm1_L_blk_peak ) ) + { + *pm1_L_blk_peak = L_deposit_l( 0 ); + *pm1_blk_peak_pos = 0; + move16(); + } + ELSE + { + *p_L_blk_peak = *pm1_L_blk_peak; + move32(); + *p_blk_peak_pos = *pm1_blk_peak_pos; + move16(); + *pm1_L_blk_peak = L_deposit_l( 0 ); + *pm1_blk_peak_pos = 0; + move16(); + } + } + } + } + p_L_blk_peak++; + pm1_L_blk_peak++; + + p_blk_peak_pos++; + pm1_blk_peak_pos++; + } + + /* peak counts in each group */ + j = 0; + move16(); + hfe_est_countk = 0; + move16(); + hfe_est_countk1 = 0; + move16(); + hfe_est_countk2 = 0; + move16(); + FOR( i = blk_st; i < blk_end; i++ ) + { + IF( blk_peak_pos[i] != 0 ) + { + blk_peak_pos_te[j] = blk_peak_pos[i]; + move16(); + IF( LT_16( blk_peak_pos[i], r2 ) ) + { + hfe_est_countk = add( hfe_est_countk, 1 ); + } + ELSE IF( LT_16( blk_peak_pos[i], r3 ) ) + { + hfe_est_countk1 = add( hfe_est_countk1, 1 ); + } + ELSE + { + hfe_est_countk2 = add( hfe_est_countk2, 1 ); + } + L_blk_peak_te[j] = L_blk_peak[i]; + move32(); + j = add( j, 1 ); + } + } + + min_har_pos = SWB_HAR_RAN1; + move16(); + temp = 0; + move16(); + L_blk_peak_max = L_blk_peak_te[0]; + move32(); + blk_peak_pos_max = blk_peak_pos_te[0]; + move16(); + blk_peak_max_idx = 0; + move16(); + + + p_diff_peak_pos = &diff_peak_pos[1]; + pm1_diff_peak_pos = &diff_peak_pos[1 - 1]; + FOR( i = 1; i < j; i++ ) + { + *pm1_diff_peak_pos = sub( blk_peak_pos_te[i], blk_peak_pos_te[sub( i, 1 )] ); + if ( LE_16( *pm1_diff_peak_pos, min_har_pos ) ) + { + min_har_pos = *pm1_diff_peak_pos; + move16(); + } + + IF( GT_32( L_blk_peak_te[sub( i, 1 )], L_blk_peak_max ) ) + { + L_blk_peak_max = L_blk_peak_te[sub( i, 1 )]; + move32(); + blk_peak_pos_max = blk_peak_pos_te[sub( i, 1 )]; + move16(); + blk_peak_max_idx = sub( i, 1 ); + } + + temp = add( temp, 1 ); + + p_diff_peak_pos++; + pm1_diff_peak_pos++; + } + blk_peak_pos_max_diff = diff_peak_pos[blk_peak_max_idx]; + move16(); + + /* Decision for BWE reconstruction */ + test(); + test(); + test(); + IF( ( LT_16( hfe_est_countk, 2 ) && LT_16( hfe_est_countk1, 2 ) && LT_16( hfe_est_countk2, 2 ) ) || GE_16( min_har_pos, SWB_HAR_RAN1 ) ) + { + *flag_dis = 0; + move16(); + test(); + test(); + test(); + if ( ( EQ_16( hfe_est_countk, 1 ) && EQ_16( hfe_est_countk1, 1 ) ) && ( EQ_16( hfe_est_countk2, 1 ) || hfe_est_countk2 == 0 ) ) + { + *flag_dis = 1; + move16(); + } + } + thr1 = add( blk_peak_pos_max_diff, LR_LOWBAND_DIF_PK_LEN ); + FOR( i = 0; i < temp; i++ ) + { + if ( LT_16( thr1, diff_peak_pos[i] ) ) + { + diff_peak_pos[i] = 0; + move16(); + } + } + Copy( diff_peak_pos, diff_peak_pos_te, temp ); + set16_fx( diff_peak_pos, -1, temp ); + j = 0; + FOR( i = 0; i < temp; i++ ) + { + IF( diff_peak_pos_te[i] != 0 ) + { + diff_peak_pos[j] = diff_peak_pos_te[i]; + move16(); + j = add( j, 1 ); + } + } + temp = j; + move16(); + + /* harmonic estimation analysis to perform BWE Reconstruction */ + IF( *flag_dis ) + { + sharp = 0; + move16(); + k = 0; + move16(); + k1 = 0; + move16(); + sharp1 = 0; + move16(); + k2 = 0; + move16(); + + q = 1; + move16(); + thr1 = add( min_har_pos, LR_LOWBAND_DIF_PK_LEN ); + thr2 = add( min_har_pos, shl( LR_LOWBAND_DIF_PK_LEN, 1 ) ); + FOR( i = 0; i < temp; i++ ) + { + test(); + test(); + IF( LE_16( diff_peak_pos[i], thr1 ) && diff_peak_pos[i] > 0 ) + { + sharp = add( sharp, diff_peak_pos[i] ); + k = add( k, 1 ); + } + ELSE IF( LE_16( diff_peak_pos[i], thr2 ) && diff_peak_pos[i] > 0 ) + { + sharp1 = add( sharp1, diff_peak_pos[i] ); + k1 = add( k1, 1 ); + } + ELSE IF( diff_peak_pos[i] > 0 ) + { + k2 = add( k2, 1 ); + } + q = add( q, 1 ); + } + + est_freq_har_decis_fx( har_freq_est1, har_freq_est2, sharp, sharp1, hfe_est_countk1, hfe_est_countk2, k, k1, k2, prev_frm_hfe2 ); + + blk_peak_pos_max = blk_peak_pos_te[sub( temp, 1 )]; + move16(); + + test(); + test(); + IF( ( *prev_stab_hfe2 ) > 0 && ( *prev_frm_hfe2 ) > 0 && *prev_stab_hfe2 < N ) + { + rem_hfe2 = sub( *har_freq_est2, extract_h( L_shl( L_mult( div_s_ss( *har_freq_est2, *prev_frm_hfe2 ), *prev_frm_hfe2 ), 15 ) ) ); + diff_posmax_hfe2 = abs_s( sub( blk_peak_pos_max, *prev_stab_hfe2 ) ); + IF( rem_hfe2 == 0 ) + { + test(); + IF( LT_16( diff_posmax_hfe2, 9 ) || *har_freq_est2 == 0 ) + { + blk_peak_pos_max = *prev_stab_hfe2; + move16(); + } + ELSE + { + q_diffpos_hfe2 = div_s_ss( diff_posmax_hfe2, *har_freq_est2 ); + q_diffpos_prevhfe2 = div_s_ss( diff_posmax_hfe2, *prev_frm_hfe2 ); + test(); + IF( LT_16( q_diffpos_hfe2, 10 ) || LT_16( q_diffpos_prevhfe2, 10 ) ) + { + blk_peak_pos_max = *prev_stab_hfe2; + move16(); + } + ELSE + { + *prev_stab_hfe2 = blk_peak_pos_max; + move16(); + } + } + } + ELSE + { + *prev_stab_hfe2 = blk_peak_pos_max; + move16(); + } + } + ELSE + { + *prev_stab_hfe2 = blk_peak_pos_max; + move16(); + } + + test(); + if ( *har_freq_est1 == 0 || *har_freq_est2 == 0 ) + { + *flag_dis = 0; + move16(); + } + } + + IF( *flag_dis == 0 ) + { + IF( *prev_frm_hfe2 != 0 ) + { + *har_freq_est2 = *prev_frm_hfe2; + move16(); + } + ELSE + { + nlags = shl( 1, bits_lagIndices_mode0_Har[0] ); + nlags_half = shr( nlags, 1 ); + ct_hfsb2 = 0; + move16(); + FOR( i = 0; i < j; i++ ) + { + test(); + IF( GE_16( blk_peak_pos_te[i], sub( subband_search_offset[0], nlags_half ) ) && + LT_16( blk_peak_pos_te[i], add( add( subband_search_offset[0], sbWidth[0] ), nlags_half ) ) ) + { + blk_peak_pos_hfsb2[ct_hfsb2] = blk_peak_pos_te[i]; + move16(); + ct_hfsb2 = add( ct_hfsb2, 1 ); + move16(); + } + } + + IF( GT_16( ct_hfsb2, 1 ) ) + { + sum_diff = 0; + move16(); + FOR( i = 1; i < ct_hfsb2; i++ ) + { + diff_peak_pos_hfsb2[i - 1] = sub( blk_peak_pos_hfsb2[i], blk_peak_pos_hfsb2[i - 1] ); + sum_diff = add( sum_diff, diff_peak_pos_hfsb2[i - 1] ); + } + *har_freq_est2 = div_s_ss( sum_diff, ct_hfsb2 ); + } + ELSE + { + *har_freq_est2 = min_har_pos; + move16(); + } + } + } + return blk_peak_pos_max; } void genhf_noise_fx( - const Word16 noise_flr_fx[], /* i : Qss smoothed non tonal */ /* sspectra_diff_fx:Qss */ - const Word16 Qss, /* i : Q0 Q value */ - Word32 L_xSynth_har[], /* o : QsL hf non tonal components */ /* xSynth_har:QsL */ - const Word16 QsL, /* i : Q0 Q value */ - const Word16 *predBuf_fx, /* i : Qss smoothed tonal compone */ /* sspectra:Qss */ - const Word16 bands, /* i : Q0 total number of subbands in a frame */ - const Word16 harmonic_band, /* i : Q0 Number of LF harmonic frames */ - const Word16 har_freq_est2, /* i : Q0 harmonic signal parameter */ - const Word16 pos_max_hfe2, /* i : Q0 last pulse in core coder */ - Word16 *pul_res, /* o : Q0 pulse resolution */ - GainItem_fx pk_sf_fx[], /* o : representative region */ - const Word16 fLenLow, /* i : Q0 low frequency length */ - const Word16 fLenHigh, /* i : Q0 high frequency length */ - const Word16 sbWidth[], /* i : Q0 bandwidth for high bands */ - const Word16 lagIndices[], /* i : Q0 correlation indices for most representative */ - const Word16 subband_offsets[], /* i : Q0 band offsets for HF reconstruction */ - const Word16 subband_search_offset[]/* i : Q0 most representative regions offsets in LF */ + const Word16 noise_flr_fx[], + /* i : Qss smoothed non tonal */ /* sspectra_diff_fx:Qss */ + const Word16 Qss, /* i : Q0 Q value */ + Word32 L_xSynth_har[], + /* o : QsL hf non tonal components */ /* xSynth_har:QsL */ + const Word16 QsL, /* i : Q0 Q value */ + const Word16 *predBuf_fx, + /* i : Qss smoothed tonal compone */ /* sspectra:Qss */ + const Word16 bands, /* i : Q0 total number of subbands in a frame */ + const Word16 harmonic_band, /* i : Q0 Number of LF harmonic frames */ + const Word16 har_freq_est2, /* i : Q0 harmonic signal parameter */ + const Word16 pos_max_hfe2, /* i : Q0 last pulse in core coder */ + Word16 *pul_res, /* o : Q0 pulse resolution */ + GainItem_fx pk_sf_fx[], /* o : representative region */ + const Word16 fLenLow, /* i : Q0 low frequency length */ + const Word16 fLenHigh, /* i : Q0 high frequency length */ + const Word16 sbWidth[], /* i : Q0 bandwidth for high bands */ + const Word16 lagIndices[], /* i : Q0 correlation indices for most representative */ + const Word16 subband_offsets[], /* i : Q0 band offsets for HF reconstruction */ + const Word16 subband_search_offset[] /* i : Q0 most representative regions offsets in LF */ ) { - Word16 k, j, ii, st_pos, dst_pos; - Word16 nlags[NB_SWB_SUBBANDS_HAR_SEARCH_SB]; - Word32 L_tmpbuf[L_FRAME32k]; - Word16 hfband_end[NB_SWB_SUBBANDS]; - Word16 rem_hfe,/*last_peakpos,*/ temp_last_peakpos, i, l, pos, res; - Word16 hf_pulse_peaks_fx[160], pulse_peak_sb_fx[320]; /* Qss */ - Word16 st_last_peakpos; - Word16 tmp_fx; - - set32_fx(L_tmpbuf, 0x0L, L_FRAME32k); - FOR(k = 0; k < 3; k++) - { - hfband_end[k] = add(fLenLow, subband_offsets[k + 1]); - move16(); - } - hfband_end[3] = add(fLenLow, fLenHigh); - move16(); - - tmp_fx = sub(sub(fLenLow, pos_max_hfe2), 1); - rem_hfe = div_s_ss(tmp_fx, har_freq_est2); - - st_last_peakpos = add(pos_max_hfe2, i_mult(rem_hfe, har_freq_est2)); - - temp_last_peakpos = st_last_peakpos; - move16(); - i = 0; - move16(); - - FOR(k = 0; k < 2; k++) - { - nlags[k] = shl(1, bits_lagIndices_mode0_Har[k]); - - l = 0; - move16(); - WHILE(LT_16(st_last_peakpos, add(fLenLow, subband_offsets[k]))) - { - st_last_peakpos = add(st_last_peakpos, har_freq_est2); - } - st_last_peakpos = sub(st_last_peakpos, har_freq_est2); - - IF(k == 0) - { - st_pos = add(sub(subband_search_offset[k], shr(nlags[k], 1)), lagIndices[k]); - - /*Copy the LF Smoothed Noise to the HF*/ - FOR(j = 0; j < sbWidth[k]; j++) - { - L_xSynth_har[j] = L_shl(L_deposit_l(noise_flr_fx[st_pos + j]), sub(QsL, Qss)); - - L_tmpbuf[j] = L_xSynth_har[j]; - move32(); - IF(predBuf_fx[st_pos + j] != 0x0) - { - hf_pulse_peaks_fx[l] = predBuf_fx[st_pos + j]; - move16(); /* Qss */ - l = add(l, 1); - } - } - } - ELSE - { - st_pos = sub(add(subband_search_offset[k], shr(nlags[k], 1)), lagIndices[k]); - dst_pos = sub(st_pos, sbWidth[k]); - ii = sbWidth[k - 1]; - move16(); - /*Copy the LF Smoothed Noise floor to the HF*/ - FOR(j = st_pos; j > (dst_pos); j--) - { - IF(GE_16(ii, add(sbWidth[k],sbWidth[k - 1]))) - { - BREAK; - } - - /*xSynth_har[ii] = noise_flr[j];*/ - L_xSynth_har[ii] = L_shl(L_deposit_l(noise_flr_fx[j]), sub(QsL, Qss)); - L_tmpbuf[ii] = L_xSynth_har[ii]; - move32(); - IF(predBuf_fx[j] != 0x0) - { - hf_pulse_peaks_fx[l] = predBuf_fx[j]; - move16(); - l = add(l, 1); - } - ii = add(ii, 1); - } - } - pos = 0; - move16(); - FOR(j = 0; j < l; j++) - { - st_last_peakpos = add(st_last_peakpos, har_freq_est2); - IF(LT_16(st_last_peakpos, hfband_end[k])) - { - pk_sf_fx[k * 8 + pos].nmrValue_fx = hf_pulse_peaks_fx[j]; - move16(); /* Qss */ - pk_sf_fx[k * 8 + pos].gainIndex_fx = sub(st_last_peakpos, fLenLow); - move16(); - pul_res[k] = add(pul_res[k], 1); - move16(); - pulse_peak_sb_fx[i] = hf_pulse_peaks_fx[j]; - move16(); /* Qss */ - i = add(i, 1); - pos = add(pos, 1); - } - } - st_last_peakpos = temp_last_peakpos; - move16(); - } - res = sub(i, 1); - l = 1; - move16(); - ii = sub(sub(hfband_end[k - 1], fLenLow), 1); - tmp_fx = sub(bands, harmonic_band); - FOR(; k < tmp_fx; k++) - { - Word16 tmp2; - - tmp2 = (sub(hfband_end[k], fLenLow)); - FOR(j = sub(hfband_end[k - 1], fLenLow); j < tmp2; j++) - { - L_xSynth_har[j] = L_tmpbuf[ii]; - move32(); - L_tmpbuf[j] = L_xSynth_har[j]; - move32(); - ii = sub(ii, 1); - } - pos = 0; - move16(); - WHILE(LT_16(st_last_peakpos, hfband_end[k - 1])) - { - st_last_peakpos = add(st_last_peakpos, har_freq_est2); - } - WHILE(LT_16(st_last_peakpos, hfband_end[k]) && LT_16(pul_res[k], pul_res[2 - l]) && LE_16(l, 2)) - { - test(); - test(); - pk_sf_fx[k * 8 + pos].nmrValue_fx = pulse_peak_sb_fx[res]; - move16(); /* Qss */ - pk_sf_fx[k * 8 + pos].gainIndex_fx = sub(st_last_peakpos, fLenLow); - move16(); - pul_res[k] = add(pul_res[k], 1); - move16(); - res = sub(res, 1); - pos = add(pos, 1); - st_last_peakpos = add(st_last_peakpos, har_freq_est2); - } - l = add(l, 1); - } - - return; + Word16 k, j, ii, st_pos, dst_pos; + Word16 nlags[NB_SWB_SUBBANDS_HAR_SEARCH_SB]; + Word32 L_tmpbuf[L_FRAME32k]; + Word16 hfband_end[NB_SWB_SUBBANDS]; + Word16 rem_hfe, /*last_peakpos,*/ temp_last_peakpos, i, l, pos, res; + Word16 hf_pulse_peaks_fx[160], pulse_peak_sb_fx[320]; /* Qss */ + Word16 st_last_peakpos; + Word16 tmp_fx; + + set32_fx( L_tmpbuf, 0x0L, L_FRAME32k ); + FOR( k = 0; k < 3; k++ ) + { + hfband_end[k] = add( fLenLow, subband_offsets[k + 1] ); + move16(); + } + hfband_end[3] = add( fLenLow, fLenHigh ); + move16(); + + tmp_fx = sub( sub( fLenLow, pos_max_hfe2 ), 1 ); + rem_hfe = div_s_ss( tmp_fx, har_freq_est2 ); + + st_last_peakpos = add( pos_max_hfe2, i_mult( rem_hfe, har_freq_est2 ) ); + + temp_last_peakpos = st_last_peakpos; + move16(); + i = 0; + move16(); + + FOR( k = 0; k < 2; k++ ) + { + nlags[k] = shl( 1, bits_lagIndices_mode0_Har[k] ); + + l = 0; + move16(); + WHILE( LT_16( st_last_peakpos, add( fLenLow, subband_offsets[k] ) ) ) + { + st_last_peakpos = add( st_last_peakpos, har_freq_est2 ); + } + st_last_peakpos = sub( st_last_peakpos, har_freq_est2 ); + + IF( k == 0 ) + { + st_pos = add( sub( subband_search_offset[k], shr( nlags[k], 1 ) ), lagIndices[k] ); + + /*Copy the LF Smoothed Noise to the HF*/ + FOR( j = 0; j < sbWidth[k]; j++ ) + { + L_xSynth_har[j] = L_shl( L_deposit_l( noise_flr_fx[st_pos + j] ), sub( QsL, Qss ) ); + + L_tmpbuf[j] = L_xSynth_har[j]; + move32(); + IF( predBuf_fx[st_pos + j] != 0x0 ) + { + hf_pulse_peaks_fx[l] = predBuf_fx[st_pos + j]; + move16(); /* Qss */ + l = add( l, 1 ); + } + } + } + ELSE + { + st_pos = sub( add( subband_search_offset[k], shr( nlags[k], 1 ) ), lagIndices[k] ); + dst_pos = sub( st_pos, sbWidth[k] ); + ii = sbWidth[k - 1]; + move16(); + /*Copy the LF Smoothed Noise floor to the HF*/ + FOR( j = st_pos; j > ( dst_pos ); j-- ) + { + IF( GE_16( ii, add( sbWidth[k], sbWidth[k - 1] ) ) ) + { + BREAK; + } + + /*xSynth_har[ii] = noise_flr[j];*/ + L_xSynth_har[ii] = L_shl( L_deposit_l( noise_flr_fx[j] ), sub( QsL, Qss ) ); + L_tmpbuf[ii] = L_xSynth_har[ii]; + move32(); + IF( predBuf_fx[j] != 0x0 ) + { + hf_pulse_peaks_fx[l] = predBuf_fx[j]; + move16(); + l = add( l, 1 ); + } + ii = add( ii, 1 ); + } + } + pos = 0; + move16(); + FOR( j = 0; j < l; j++ ) + { + st_last_peakpos = add( st_last_peakpos, har_freq_est2 ); + IF( LT_16( st_last_peakpos, hfband_end[k] ) ) + { + pk_sf_fx[k * 8 + pos].nmrValue_fx = hf_pulse_peaks_fx[j]; + move16(); /* Qss */ + pk_sf_fx[k * 8 + pos].gainIndex_fx = sub( st_last_peakpos, fLenLow ); + move16(); + pul_res[k] = add( pul_res[k], 1 ); + move16(); + pulse_peak_sb_fx[i] = hf_pulse_peaks_fx[j]; + move16(); /* Qss */ + i = add( i, 1 ); + pos = add( pos, 1 ); + } + } + st_last_peakpos = temp_last_peakpos; + move16(); + } + res = sub( i, 1 ); + l = 1; + move16(); + ii = sub( sub( hfband_end[k - 1], fLenLow ), 1 ); + tmp_fx = sub( bands, harmonic_band ); + FOR( ; k < tmp_fx; k++ ) + { + Word16 tmp2; + + tmp2 = ( sub( hfband_end[k], fLenLow ) ); + FOR( j = sub( hfband_end[k - 1], fLenLow ); j < tmp2; j++ ) + { + L_xSynth_har[j] = L_tmpbuf[ii]; + move32(); + L_tmpbuf[j] = L_xSynth_har[j]; + move32(); + ii = sub( ii, 1 ); + } + pos = 0; + move16(); + WHILE( LT_16( st_last_peakpos, hfband_end[k - 1] ) ) + { + st_last_peakpos = add( st_last_peakpos, har_freq_est2 ); + } + WHILE( LT_16( st_last_peakpos, hfband_end[k] ) && LT_16( pul_res[k], pul_res[2 - l] ) && LE_16( l, 2 ) ) + { + test(); + test(); + pk_sf_fx[k * 8 + pos].nmrValue_fx = pulse_peak_sb_fx[res]; + move16(); /* Qss */ + pk_sf_fx[k * 8 + pos].gainIndex_fx = sub( st_last_peakpos, fLenLow ); + move16(); + pul_res[k] = add( pul_res[k], 1 ); + move16(); + res = sub( res, 1 ); + pos = add( pos, 1 ); + st_last_peakpos = add( st_last_peakpos, har_freq_est2 ); + } + l = add( l, 1 ); + } + + return; } /*-------------------------------------------------------------------* @@ -775,110 +776,109 @@ void genhf_noise_fx( * of points in the average is given by 'span'. Note that current * implementation does not accept 'span' to be smaller than 'fLen'. *-------------------------------------------------------------------*/ -static -void SmoothSpec_fx( - Word16 *inBuf, /* i : Input spectrum Q8 */ - Word16 *outBuf, /* o : Smoothed spectrum Q8 */ - Word16 num_subband /* i : subband number */ +static void SmoothSpec_fx( + Word16 *inBuf, /* i : Input spectrum Q8 */ + Word16 *outBuf, /* o : Smoothed spectrum Q8 */ + Word16 num_subband /* i : subband number */ ) { - Word16 i, tmp; - Word16 span1; /* */ - Word16 nItems, inItems; /* inverse */ - Word32 L_sum; /* */ - Word16 *oldPtr, *newPtr;/* */ - Word16 hi, lo; - /* ======== Q8 ======== */ - span1 = shr(MA_LEN, 1); - - /*-- First sample. --*/ - L_sum = L_deposit_l(*inBuf); - *outBuf++ = *inBuf; - move16(); - - oldPtr = inBuf; - newPtr = inBuf + 2; - - /*-- Handle start. --*/ - inBuf++; - L_sum = L_mac0(L_sum, 0x0001, *inBuf); - - /* nItems = 3 --> inItems = 1/3 = 0.33f, 85(Q8) */ - /* 1/3 = 0.3333f -> 0x2AAA Q15 */ - inItems = 0x2AAA; - move16(); - FOR(i = 1; i < span1; i++) - { - L_sum = L_mac0(L_sum, 0x0001, *newPtr++); - - lo = L_Extract_lc(L_sum, &hi); - *outBuf++ = round_fx(L_shl(Mpy_32_16(hi, lo, inItems), 16)); /* Q(8+15+1-16)=Q8 -> Q(8+16-16)=Q8 */ - - L_sum = L_mac0(L_sum, 0x0001, *newPtr++); - /* nItems += 2, - * only used value is 5 --> - * inItems = 1/5 = 0.2f, 51(Q8) - */ - /* 1/5 = 0.2f -> 0x1999 Q15 */ - inItems = 0x1999; - move16(); - inBuf++; - } - - inBuf++; - L_sum = L_mac0(L_sum, 0x0001, *newPtr++); - - lo = L_Extract_lc(L_sum, &hi); - /* 4681 (in Q15) = 0.1428 = 1/7 */ - *outBuf++ = round_fx(L_shl(Mpy_32_16(hi, lo, 4681), 16)); /* Q(8+15+1-16)=Q8 -> Q(8+16-16)=Q8 */ - i = add(i, 1); - - /*-- Moving average. --*/ - tmp = sub(num_subband, span1); - FOR(; i < tmp; i++) - { - L_sum = L_mac0(L_sum, 0x0001, *newPtr++); - L_sum = L_msu0(L_sum, 0x0001, *oldPtr++); - - lo = L_Extract_lc(L_sum, &hi); - /* 4681 (in Q15) = 0.1428 = 1/7 */ - *outBuf++ = round_fx(L_shl(Mpy_32_16(hi, lo, 4681), 16)); /* Q(8+15+1-16)=Q8 -> Q(8+16-16)=Q8 */ - inBuf++; - } - - /*-- Handle end. --*/ - /* nItems = span - 2; (nItems = 5, so we can maintain inItems = 1/5 = 0.2f from above) */ - nItems = sub(MA_LEN, 2); - L_sum = L_msu0(L_sum, 0x0001, *oldPtr++); - - tmp = sub(num_subband, 1); - FOR(; i < tmp; i++) - { - L_sum = L_msu0(L_sum, 0x0001, *oldPtr++); - - lo = L_Extract_lc(L_sum, &hi); - *outBuf++ = round_fx(L_shl(Mpy_32_16(hi, lo, inItems), 16)); /* Q(8+15+1-16)=Q8 -> Q(8+16-16)=Q8 */ - - /* nItems -= 2; */ - nItems = sub(nItems, 2); - - /* 1.0f -> 0x7fff Q15 */ - inItems = 0x7fff; - move16(); - if (EQ_16(nItems, 3)) - { - /* 1/3 = 0.333f -> 0x2AAA Q15 */ - inItems = 0x2AAA; - move16(); - } - L_sum = L_msu0(L_sum, 0x0001, *oldPtr++); - - inBuf++; - } - - /*-- Last sample. --*/ - *outBuf = *inBuf; - move16(); + Word16 i, tmp; + Word16 span1; /* */ + Word16 nItems, inItems; /* inverse */ + Word32 L_sum; /* */ + Word16 *oldPtr, *newPtr; /* */ + Word16 hi, lo; + /* ======== Q8 ======== */ + span1 = shr( MA_LEN, 1 ); + + /*-- First sample. --*/ + L_sum = L_deposit_l( *inBuf ); + *outBuf++ = *inBuf; + move16(); + + oldPtr = inBuf; + newPtr = inBuf + 2; + + /*-- Handle start. --*/ + inBuf++; + L_sum = L_mac0( L_sum, 0x0001, *inBuf ); + + /* nItems = 3 --> inItems = 1/3 = 0.33f, 85(Q8) */ + /* 1/3 = 0.3333f -> 0x2AAA Q15 */ + inItems = 0x2AAA; + move16(); + FOR( i = 1; i < span1; i++ ) + { + L_sum = L_mac0( L_sum, 0x0001, *newPtr++ ); + + lo = L_Extract_lc( L_sum, &hi ); + *outBuf++ = round_fx( L_shl( Mpy_32_16( hi, lo, inItems ), 16 ) ); /* Q(8+15+1-16)=Q8 -> Q(8+16-16)=Q8 */ + + L_sum = L_mac0( L_sum, 0x0001, *newPtr++ ); + /* nItems += 2, + * only used value is 5 --> + * inItems = 1/5 = 0.2f, 51(Q8) + */ + /* 1/5 = 0.2f -> 0x1999 Q15 */ + inItems = 0x1999; + move16(); + inBuf++; + } + + inBuf++; + L_sum = L_mac0( L_sum, 0x0001, *newPtr++ ); + + lo = L_Extract_lc( L_sum, &hi ); + /* 4681 (in Q15) = 0.1428 = 1/7 */ + *outBuf++ = round_fx( L_shl( Mpy_32_16( hi, lo, 4681 ), 16 ) ); /* Q(8+15+1-16)=Q8 -> Q(8+16-16)=Q8 */ + i = add( i, 1 ); + + /*-- Moving average. --*/ + tmp = sub( num_subband, span1 ); + FOR( ; i < tmp; i++ ) + { + L_sum = L_mac0( L_sum, 0x0001, *newPtr++ ); + L_sum = L_msu0( L_sum, 0x0001, *oldPtr++ ); + + lo = L_Extract_lc( L_sum, &hi ); + /* 4681 (in Q15) = 0.1428 = 1/7 */ + *outBuf++ = round_fx( L_shl( Mpy_32_16( hi, lo, 4681 ), 16 ) ); /* Q(8+15+1-16)=Q8 -> Q(8+16-16)=Q8 */ + inBuf++; + } + + /*-- Handle end. --*/ + /* nItems = span - 2; (nItems = 5, so we can maintain inItems = 1/5 = 0.2f from above) */ + nItems = sub( MA_LEN, 2 ); + L_sum = L_msu0( L_sum, 0x0001, *oldPtr++ ); + + tmp = sub( num_subband, 1 ); + FOR( ; i < tmp; i++ ) + { + L_sum = L_msu0( L_sum, 0x0001, *oldPtr++ ); + + lo = L_Extract_lc( L_sum, &hi ); + *outBuf++ = round_fx( L_shl( Mpy_32_16( hi, lo, inItems ), 16 ) ); /* Q(8+15+1-16)=Q8 -> Q(8+16-16)=Q8 */ + + /* nItems -= 2; */ + nItems = sub( nItems, 2 ); + + /* 1.0f -> 0x7fff Q15 */ + inItems = 0x7fff; + move16(); + if ( EQ_16( nItems, 3 ) ) + { + /* 1/3 = 0.333f -> 0x2AAA Q15 */ + inItems = 0x2AAA; + move16(); + } + L_sum = L_msu0( L_sum, 0x0001, *oldPtr++ ); + + inBuf++; + } + + /*-- Last sample. --*/ + *outBuf = *inBuf; + move16(); } /*-------------------------------------------------------------------* @@ -888,226 +888,227 @@ void SmoothSpec_fx( *-------------------------------------------------------------------*/ void SpectrumSmoothing_fx( - const Word32 *L_inBuf, /* i : Qs Low band MDCT */ - Word16 *outBuf_fx, /* o : Qss output */ - Word16 *Qss, /* o : Q0 Q value of output vector */ - const Word16 fLen, /* i : Q0 length */ - const Word16 th_cut_fx /* i : Qss threshold of cut */ + const Word32 *L_inBuf, /* i : Qs Low band MDCT */ + Word16 *outBuf_fx, /* o : Qss output */ + Word16 *Qss, /* o : Q0 Q value of output vector */ + const Word16 fLen, /* i : Q0 length */ + const Word16 th_cut_fx /* i : Qss threshold of cut */ ) { - /* internal variable */ - Word16 i, j, k; + /* internal variable */ + Word16 i, j, k; - Word16 num_subband_smooth_fx; - Word16 num_subband_smooth_pre_fx; + Word16 num_subband_smooth_fx; + Word16 num_subband_smooth_pre_fx; - Word16 exp_normd; - Word16 exp_shift; + Word16 exp_normd; + Word16 exp_shift; - Word16 max_val_norm_fx; + Word16 max_val_norm_fx; - Word16 Qmax_val_norm[L_FRAME32k / L_SB]; + Word16 Qmax_val_norm[L_FRAME32k / L_SB]; - Word32 L_inBuf_abs; - Word32 L_inBuf_pss[L_FRAME32k]; - Word32 L_max_val[L_FRAME32k / L_SB]; - Word16 outBuf_pss_fx[L_FRAME32k]; + Word32 L_inBuf_abs; + Word32 L_inBuf_pss[L_FRAME32k]; + Word32 L_max_val[L_FRAME32k / L_SB]; + Word16 outBuf_pss_fx[L_FRAME32k]; - Word16 m, n; - Word16 cnt_zero_cont; - Word16 n_list[BANDS_MAX]; - Word16 reset_flag; - Word16 pp, pk; - Word16 exp_norm; + Word16 m, n; + Word16 cnt_zero_cont; + Word16 n_list[BANDS_MAX]; + Word16 reset_flag; + Word16 pp, pk; + Word16 exp_norm; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; + Flag Overflow = 0; #endif - *Qss = 10; - - num_subband_smooth_pre_fx = mult(fLen, 21845); /* 1/L_SB = 1/12 = 21845(Q18) Q = exp_normn-18 */ - num_subband_smooth_fx = shr(num_subband_smooth_pre_fx, 18 - 15); - IF(NE_16(num_subband_smooth_pre_fx, shl(num_subband_smooth_fx, 18 - 15))) - { - num_subband_smooth_fx++; - } - - FOR(i = 0; i < fLen; i++) - { - L_inBuf_pss[i] = L_inBuf[i]; - move32(); - outBuf_pss_fx[i] = 0; - move16(); - } - - FOR(i = fLen; i < fLen + (num_subband_smooth_fx * L_SB - fLen); i++) - { - L_inBuf_pss[i] = L_deposit_l(0); - outBuf_pss_fx[i] = 0; - move16(); - } - - j = 0; - FOR(i = 0; i < num_subband_smooth_fx; i++) - { - L_max_val[i] = L_deposit_l(0); - FOR(k = 0; k < L_SB; k++) - { - L_inBuf_abs = L_abs(L_inBuf_pss[j]); - if (LT_32(L_max_val[i], L_inBuf_abs)) - { - L_max_val[i] = L_inBuf_abs; - move32(); - } - - j++; - } - } - - /* convert to maximum amplitude frequency log scale envelope */ - j = 0; - FOR(i = 0; i < num_subband_smooth_fx; i++) - { - /* max_val_norm = 10.0f / (max_val[i] + 0.001f); */ - /* 10.0f : 0x2800, Q10 */ - IF(GT_32(L_max_val[i], 0x1L)) - { - exp_normd = norm_l(L_max_val[i]); + *Qss = 10; + + num_subband_smooth_pre_fx = mult( fLen, 21845 ); /* 1/L_SB = 1/12 = 21845(Q18) Q = exp_normn-18 */ + num_subband_smooth_fx = shr( num_subband_smooth_pre_fx, 18 - 15 ); + IF( NE_16( num_subband_smooth_pre_fx, shl( num_subband_smooth_fx, 18 - 15 ) ) ) + { + num_subband_smooth_fx++; + } + + FOR( i = 0; i < fLen; i++ ) + { + L_inBuf_pss[i] = L_inBuf[i]; + move32(); + outBuf_pss_fx[i] = 0; + move16(); + } + + FOR( i = fLen; i < fLen + ( num_subband_smooth_fx * L_SB - fLen ); i++ ) + { + L_inBuf_pss[i] = L_deposit_l( 0 ); + outBuf_pss_fx[i] = 0; + move16(); + } + + j = 0; + FOR( i = 0; i < num_subband_smooth_fx; i++ ) + { + L_max_val[i] = L_deposit_l( 0 ); + FOR( k = 0; k < L_SB; k++ ) + { + L_inBuf_abs = L_abs( L_inBuf_pss[j] ); + if ( LT_32( L_max_val[i], L_inBuf_abs ) ) + { + L_max_val[i] = L_inBuf_abs; + move32(); + } + + j++; + } + } + + /* convert to maximum amplitude frequency log scale envelope */ + j = 0; + FOR( i = 0; i < num_subband_smooth_fx; i++ ) + { + /* max_val_norm = 10.0f / (max_val[i] + 0.001f); */ + /* 10.0f : 0x2800, Q10 */ + IF( GT_32( L_max_val[i], 0x1L ) ) + { + exp_normd = norm_l( L_max_val[i] ); #ifdef BASOP_NOGLOB - max_val_norm_fx = div_s(0x2800, round_fx_o(L_shl_o(L_max_val[i], exp_normd, &Overflow), &Overflow)); /* Q10-(Qs+exp_normd-16) */ + max_val_norm_fx = div_s( 0x2800, round_fx_o( L_shl_o( L_max_val[i], exp_normd, &Overflow ), &Overflow ) ); /* Q10-(Qs+exp_normd-16) */ #else - max_val_norm_fx = div_s(0x2800, round_fx(L_shl(L_max_val[i], exp_normd))); /* Q10-(Qs+exp_normd-16) */ + max_val_norm_fx = div_s( 0x2800, round_fx( L_shl( L_max_val[i], exp_normd ) ) ); /* Q10-(Qs+exp_normd-16) */ #endif - Qmax_val_norm[i] = sub(10 - 12 + 16 + 15, exp_normd); - move16(); /* 10 - (12+exp_normd-16) +15 */; - } - ELSE - { - max_val_norm_fx = 0; - move16(); - Qmax_val_norm[i] = 0; - move16(); - } - - exp_shift = sub(*Qss, add(Qmax_val_norm[i], -19)); - FOR(k = 0; k < L_SB; k++) - { - exp_norm = norm_l(L_inBuf_pss[j]); - IF(L_inBuf_pss[j] == 0x0L) - { - outBuf_pss_fx[j] = 0; - move16(); - } - ELSE IF(LT_32(L_abs(L_inBuf_pss[j]), L_max_val[i])) - { - IF(L_inBuf_pss[j] >= 0) - { + Qmax_val_norm[i] = sub( 10 - 12 + 16 + 15, exp_normd ); + move16(); /* 10 - (12+exp_normd-16) +15 */ + ; + } + ELSE + { + max_val_norm_fx = 0; + move16(); + Qmax_val_norm[i] = 0; + move16(); + } + + exp_shift = sub( *Qss, add( Qmax_val_norm[i], -19 ) ); + FOR( k = 0; k < L_SB; k++ ) + { + exp_norm = norm_l( L_inBuf_pss[j] ); + IF( L_inBuf_pss[j] == 0x0L ) + { + outBuf_pss_fx[j] = 0; + move16(); + } + ELSE IF( LT_32( L_abs( L_inBuf_pss[j] ), L_max_val[i] ) ) + { + IF( L_inBuf_pss[j] >= 0 ) + { #ifdef BASOP_NOGLOB - outBuf_pss_fx[j] = round_fx_o(L_shl_o(Mpy_32_16_r(L_shl_o(L_inBuf_pss[j], exp_norm, &Overflow), max_val_norm_fx), sub(exp_shift, exp_norm), &Overflow), &Overflow); + outBuf_pss_fx[j] = round_fx_o( L_shl_o( Mpy_32_16_r( L_shl_o( L_inBuf_pss[j], exp_norm, &Overflow ), max_val_norm_fx ), sub( exp_shift, exp_norm ), &Overflow ), &Overflow ); #else - outBuf_pss_fx[j] = round_fx(L_shl(Mpy_32_16_r(L_shl(L_inBuf_pss[j], exp_norm), max_val_norm_fx), sub(exp_shift, exp_norm))); + outBuf_pss_fx[j] = round_fx( L_shl( Mpy_32_16_r( L_shl( L_inBuf_pss[j], exp_norm ), max_val_norm_fx ), sub( exp_shift, exp_norm ) ) ); #endif - move32(); - } - ELSE - { + move32(); + } + ELSE + { #ifdef BASOP_NOGLOB - outBuf_pss_fx[j] = negate(round_fx_o(L_shl_o(Mpy_32_16_r(L_shl_o(L_abs(L_inBuf_pss[j]), exp_norm, &Overflow), max_val_norm_fx), sub(exp_shift, exp_norm), &Overflow), &Overflow)); + outBuf_pss_fx[j] = negate( round_fx_o( L_shl_o( Mpy_32_16_r( L_shl_o( L_abs( L_inBuf_pss[j] ), exp_norm, &Overflow ), max_val_norm_fx ), sub( exp_shift, exp_norm ), &Overflow ), &Overflow ) ); #else - outBuf_pss_fx[j] = negate(round_fx(L_shl(Mpy_32_16_r(L_shl(L_abs(L_inBuf_pss[j]), exp_norm), max_val_norm_fx), sub(exp_shift, exp_norm)))); + outBuf_pss_fx[j] = negate( round_fx( L_shl( Mpy_32_16_r( L_shl( L_abs( L_inBuf_pss[j] ), exp_norm ), max_val_norm_fx ), sub( exp_shift, exp_norm ) ) ) ); #endif - } - } - ELSE - { - /* CLIP, for avoiding computational difference */ - outBuf_pss_fx[j] = 0x2800; - move16(); - if (L_inBuf_pss[j] < 0x0L) - { - outBuf_pss_fx[j] = -0x2800; - move16(); - } - } - j++; - } - } - - k = 0; - move16(); - m = 0; - move16(); - n = 0; - move16(); - reset_flag = 0; - move16(); - n_list[0] = 0; - move16(); - FOR(j = 0; j < num_subband_smooth_fx; j++) - { - cnt_zero_cont = 0; - move16(); - FOR(i = 0; i < L_SB; i++) - { - cnt_zero_cont = add(cnt_zero_cont, 1); - if (outBuf_pss_fx[k] != 0) - { - cnt_zero_cont = 0; - move16(); - } - k = add(k, 1); - } - - IF(cnt_zero_cont != 0) - { - test(); - IF(GT_16(j, div_s_ss(subband_search_offsets[0], L_SB)) && reset_flag == 0) - { - n = 0; - move16(); - reset_flag = 1; - move16(); - } - n_list[n] = j; - move16(); - n = add(n, 1); - } - - test(); - if (EQ_16(reset_flag, 1) && EQ_16(n, 1)) - { - m = 0; - move16(); - } - - pk = sub(k, L_SB); - IF(GT_16(cnt_zero_cont, mult_r(L_SB, 24576))) /* cnt_zero_cont > 3*L_SB/4 */ - { - pp = round_fx(L_shl(L_mult(n_list[m], L_SB), 15)); - FOR(i = 0; i < L_SB; i++) - { - if (outBuf_pss_fx[pk + i] == 0) - { - outBuf_pss_fx[pk + i] = shr(outBuf_pss_fx[pp + i], 1); - move16(); - } - } - m = add(m, 1); - } - } - - FOR(i = 0; i < fLen; i++) - { - outBuf_fx[i] = 0x0; - move16(); - if (GT_16(abs_s(outBuf_pss_fx[i]), th_cut_fx)) - { - outBuf_fx[i] = outBuf_pss_fx[i]; - move16(); - } - } - - return; + } + } + ELSE + { + /* CLIP, for avoiding computational difference */ + outBuf_pss_fx[j] = 0x2800; + move16(); + if ( L_inBuf_pss[j] < 0x0L ) + { + outBuf_pss_fx[j] = -0x2800; + move16(); + } + } + j++; + } + } + + k = 0; + move16(); + m = 0; + move16(); + n = 0; + move16(); + reset_flag = 0; + move16(); + n_list[0] = 0; + move16(); + FOR( j = 0; j < num_subband_smooth_fx; j++ ) + { + cnt_zero_cont = 0; + move16(); + FOR( i = 0; i < L_SB; i++ ) + { + cnt_zero_cont = add( cnt_zero_cont, 1 ); + if ( outBuf_pss_fx[k] != 0 ) + { + cnt_zero_cont = 0; + move16(); + } + k = add( k, 1 ); + } + + IF( cnt_zero_cont != 0 ) + { + test(); + IF( GT_16( j, div_s_ss( subband_search_offsets[0], L_SB ) ) && reset_flag == 0 ) + { + n = 0; + move16(); + reset_flag = 1; + move16(); + } + n_list[n] = j; + move16(); + n = add( n, 1 ); + } + + test(); + if ( EQ_16( reset_flag, 1 ) && EQ_16( n, 1 ) ) + { + m = 0; + move16(); + } + + pk = sub( k, L_SB ); + IF( GT_16( cnt_zero_cont, mult_r( L_SB, 24576 ) ) ) /* cnt_zero_cont > 3*L_SB/4 */ + { + pp = round_fx( L_shl( L_mult( n_list[m], L_SB ), 15 ) ); + FOR( i = 0; i < L_SB; i++ ) + { + if ( outBuf_pss_fx[pk + i] == 0 ) + { + outBuf_pss_fx[pk + i] = shr( outBuf_pss_fx[pp + i], 1 ); + move16(); + } + } + m = add( m, 1 ); + } + } + + FOR( i = 0; i < fLen; i++ ) + { + outBuf_fx[i] = 0x0; + move16(); + if ( GT_16( abs_s( outBuf_pss_fx[i] ), th_cut_fx ) ) + { + outBuf_fx[i] = outBuf_pss_fx[i]; + move16(); + } + } + + return; } /*-------------------------------------------------------------------* @@ -1117,44 +1118,45 @@ void SpectrumSmoothing_fx( *-------------------------------------------------------------------*/ void Get20Log10Spec_fx( - const Word32 *L_inBuf, /* i : input Q_inBuf */ /* L_inBuf >=0, so L_abs is omitted. */ - Word16 *outBuf_fx, /* o : output Q7 */ - const Word16 fLen, /* i : loop length */ - const Word16 Q_inBuf /* i : Qvalue of L_inBuf */ + const Word32 *L_inBuf, + /* i : input Q_inBuf */ /* L_inBuf >=0, so L_abs is omitted. */ + Word16 *outBuf_fx, /* o : output Q7 */ + const Word16 fLen, /* i : loop length */ + const Word16 Q_inBuf /* i : Qvalue of L_inBuf */ ) { - Word16 i; - Word16 exp, frac; - - Word32 L_tmp; - - Word32 L_lamda; - Word16 Q_inBuf_1; - - Q_inBuf_1 = sub(Q_inBuf, 1); - L_lamda = L_shl(1L, Q_inBuf_1); /* +1 : Q_inBuf -> Q_inBuf-1 for overflow problem */ - - FOR(i = 0; i < fLen; i++) - { - /*outBuf++ = (float) (20.0f * log10(fabs(*inBuf + 1.0))); */ - L_tmp = L_add(L_shr(*L_inBuf++, 1), L_lamda); - exp = 31; - move16(); - if (L_tmp != 0x0L) - { - exp = norm_l(L_tmp); - } - frac = Log2_norm_lc(L_shl(L_tmp, exp)); - exp = sub(30, exp); - exp = sub(exp, Q_inBuf_1); - L_tmp = L_Comp(exp, frac); - - L_tmp = Mpy_32_16_1(L_tmp, 24660); /* 6.0206 in Q12 */ - L_tmp = L_shl(L_tmp, 2 + 8); /* Q7 */ - *outBuf_fx++ = round_fx(L_tmp); - } - - return; + Word16 i; + Word16 exp, frac; + + Word32 L_tmp; + + Word32 L_lamda; + Word16 Q_inBuf_1; + + Q_inBuf_1 = sub( Q_inBuf, 1 ); + L_lamda = L_shl( 1L, Q_inBuf_1 ); /* +1 : Q_inBuf -> Q_inBuf-1 for overflow problem */ + + FOR( i = 0; i < fLen; i++ ) + { + /*outBuf++ = (float) (20.0f * log10(fabs(*inBuf + 1.0))); */ + L_tmp = L_add( L_shr( *L_inBuf++, 1 ), L_lamda ); + exp = 31; + move16(); + if ( L_tmp != 0x0L ) + { + exp = norm_l( L_tmp ); + } + frac = Log2_norm_lc( L_shl( L_tmp, exp ) ); + exp = sub( 30, exp ); + exp = sub( exp, Q_inBuf_1 ); + L_tmp = L_Comp( exp, frac ); + + L_tmp = Mpy_32_16_1( L_tmp, 24660 ); /* 6.0206 in Q12 */ + L_tmp = L_shl( L_tmp, 2 + 8 ); /* Q7 */ + *outBuf_fx++ = round_fx( L_tmp ); + } + + return; } /*-------------------------------------------------------------------* * convert_lagIndices_pls2smp() @@ -1162,44 +1164,43 @@ void Get20Log10Spec_fx( * *-------------------------------------------------------------------*/ void convert_lagIndices_pls2smp_fx( - Word16 lagIndices_in_fx[], - Word16 nBands_search_fx, - Word16 lagIndices_out_fx[], - const Word16 sspectra_fx[], - const Word16 sbWidth_fx[], - const Word16 fLenLow_fx -) + Word16 lagIndices_in_fx[], + Word16 nBands_search_fx, + Word16 lagIndices_out_fx[], + const Word16 sspectra_fx[], + const Word16 sbWidth_fx[], + const Word16 fLenLow_fx ) { - Word16 sb; - Word16 i, cnt; - - FOR(sb = 0; sb < nBands_search_fx; sb++) - { - cnt = 0; - move16(); - i = 0; - move16(); - - WHILE(LE_16(cnt, lagIndices_in_fx[sb])) - { - if (sspectra_fx[subband_search_offsets[sb] + i] != 0) - { - cnt = add(cnt, 1); - } - - i = add(i, 1); - - IF(GE_16(add(subband_search_offsets[sb], add(i, sbWidth_fx[sb])), fLenLow_fx)) - { - BREAK; - } - } - - lagIndices_out_fx[sb] = add(sub(i, 1), subband_search_offsets[sb]); - move16(); - } - - return; + Word16 sb; + Word16 i, cnt; + + FOR( sb = 0; sb < nBands_search_fx; sb++ ) + { + cnt = 0; + move16(); + i = 0; + move16(); + + WHILE( LE_16( cnt, lagIndices_in_fx[sb] ) ) + { + if ( sspectra_fx[subband_search_offsets[sb] + i] != 0 ) + { + cnt = add( cnt, 1 ); + } + + i = add( i, 1 ); + + IF( GE_16( add( subband_search_offsets[sb], add( i, sbWidth_fx[sb] ) ), fLenLow_fx ) ) + { + BREAK; + } + } + + lagIndices_out_fx[sb] = add( sub( i, 1 ), subband_search_offsets[sb] ); + move16(); + } + + return; } /*-------------------------------------------------------------------* @@ -1208,45 +1209,44 @@ void convert_lagIndices_pls2smp_fx( * *-------------------------------------------------------------------*/ Word16 get_usebit_npswb_fx( - Word16 hqswb_clas_fx -) + Word16 hqswb_clas_fx ) { - Word16 i; - Word16 bits; - Word16 up_lmt; - const Word16 *bits_req; - - up_lmt = 0; - move16(); - bits_req = bits_lagIndices_modeNormal; - move16(); - bits = 0; - move16(); - - IF(EQ_16(hqswb_clas_fx, HQ_NORMAL)) - { - up_lmt = NB_SWB_SUBBANDS; - move16(); - bits_req = bits_lagIndices_modeNormal; - move16(); - } - ELSE IF(EQ_16(hqswb_clas_fx, HQ_HARMONIC)) - { - up_lmt = NB_SWB_SUBBANDS_HAR_SEARCH_SB; - move16(); - bits_req = bits_lagIndices_mode0_Har; - move16(); - bits = 2; - move16(); /*noise gain*/ - } - - FOR(i = 0; i < up_lmt; i++) - { - bits = add(bits, bits_req[i]); - move16(); - } - - return bits; + Word16 i; + Word16 bits; + Word16 up_lmt; + const Word16 *bits_req; + + up_lmt = 0; + move16(); + bits_req = bits_lagIndices_modeNormal; + move16(); + bits = 0; + move16(); + + IF( EQ_16( hqswb_clas_fx, HQ_NORMAL ) ) + { + up_lmt = NB_SWB_SUBBANDS; + move16(); + bits_req = bits_lagIndices_modeNormal; + move16(); + } + ELSE IF( EQ_16( hqswb_clas_fx, HQ_HARMONIC ) ) + { + up_lmt = NB_SWB_SUBBANDS_HAR_SEARCH_SB; + move16(); + bits_req = bits_lagIndices_mode0_Har; + move16(); + bits = 2; + move16(); /*noise gain*/ + } + + FOR( i = 0; i < up_lmt; i++ ) + { + bits = add( bits, bits_req[i] ); + move16(); + } + + return bits; } /*-------------------------------------------------------------------* * SpectrumSmoothing_nss() @@ -1254,294 +1254,301 @@ Word16 get_usebit_npswb_fx( * *-------------------------------------------------------------------*/ void SpectrumSmoothing_nss_fx( - const Word32 *L_inBuf, /* i : lowband MDCT */ - Word16 *outBuf_fx, /* o : output */ - Word16 *Qss, /* o : Q value of output vector */ - const Word16 fLen /* i : length */ + const Word32 *L_inBuf, /* i : lowband MDCT */ + Word16 *outBuf_fx, /* o : output */ + Word16 *Qss, /* o : Q value of output vector */ + const Word16 fLen /* i : length */ ) { - /* internal variable */ - Word16 i, k; - - Word16 inBuf_fx[L_FRAME32k]; - Word16 Qm; - Word32 L_tmp[L_FRAME32k]; - - Word16 num_subband_smooth_fx; - Word16 exp_tmp; - - Word16 inBufw_fx[L_FRAME32k + L_SB_NSS]; - Word16 outBufw_fx[L_FRAME32k + L_SB_NSS]; - Word32 L_outBufw[L_FRAME32k + L_SB_NSS]; - Word16 Qo[NUM_SUBBAND_SMOOTH_MAX]; - - Word16 avg_val_fx; - Word32 L_avg_val; - Word16 r0_fx; - Word32 L_r0; - Word32 L_temp; - Word16 temp_fx; - - Word16 max_peak_fx; - - Word16 smr_fx; - Word32 L_smr; - - Word32 L_temp_sum_1[NUM_SUBBAND_SMOOTH_MAX]; - Word32 L_temp_sum_2[NUM_SUBBAND_SMOOTH_MAX]; - Word32 L_temp_sum_3[NUM_SUBBAND_SMOOTH_MAX]; - - - Word16 temp_sum_smooth_fx[NUM_SUBBAND_SMOOTH_MAX]; - Word16 temp_sum_div_fx[NUM_SUBBAND_SMOOTH_MAX]; - Word16 Qsumdiv[NUM_SUBBAND_SMOOTH_MAX]; - Word32 L_temp1; - Word16 temp_hi; - Word16 temp_lo; - - - Word16 avg_val2_fx; - Word32 L_avg_val2; - Word16 Qavg_val; - Word16 Qsmr; - Word16 exp, frac; - - Word16 clip_cof_fx; - - Word16 thre_fx, thre_fx_neg; - Word16 thre_min_fx; - - Word16 temp_sum_log_fx[NUM_SUBBAND_SMOOTH_MAX]; - Word16 exp_norm; - Word16 exp_normn; - Word16 exp_normd; - Word16 exp_shift; - - L_tmp[0] = L_deposit_l(0); - FOR(i = 0; i < fLen; i++) - { - L_tmp[0] = L_or(L_tmp[0], L_abs(L_inBuf[i])); - } - exp_norm = norm_l(L_tmp[0]); - Qm = sub(exp_norm, 4); /* Qm = sub(add(12, exp_norm), 16); */ - - FOR(i = 0; i < fLen; i++) - { - L_tmp[i] = L_shl(L_inBuf[i], exp_norm); /* Q(12+exp_norm) */ move32(); - inBuf_fx[i] = round_fx(L_tmp[i]); /* Qm */ - } - - num_subband_smooth_fx = shr(fLen, 3); /* L_SB_NSS=8 shr(target, 3); */ - - /* buffer copy for fractional point */ - FOR(i = 0; i < fLen; i++) - { - inBufw_fx[i] = inBuf_fx[i]; - move16(); - outBufw_fx[i] = 0; - move16(); - } - - /* initialization of over buffer for fractional point */ - k = add(fLen, L_SB_NSS); - FOR(i = fLen; i < k; i++) - { - inBufw_fx[i] = 0; - move16(); - outBufw_fx[i] = 0; - move16(); - } - - L_avg_val = L_deposit_l(0); - FOR(i = 0; i < fLen; i++) - { - L_r0 = L_abs(L_deposit_l(inBufw_fx[i])); - L_avg_val = L_add(L_avg_val, L_r0); - } - exp_normn = norm_l(L_avg_val); - exp_normn = sub(exp_normn, 1); - exp_normd = norm_s(fLen); - avg_val_fx = div_l(L_shl(L_avg_val, exp_normn), shl(fLen, exp_normd)); /* (Qs+exp_norm+exp_normn) - (exp_normd) - 15 */ - Qavg_val = sub(add(Qm, sub(exp_normn, exp_normd)), 1); - - max_peak_fx = 0; - move16(); - FOR(i = 0; i < fLen; i++) - { - r0_fx = abs_s(inBufw_fx[i]); - if (LT_16(max_peak_fx, r0_fx)) - { - max_peak_fx = r0_fx; - move16(); /* Qm */ - } - } - - /*smr = 10.0f * (float)log10( max_peak/(avg_val + 1.0e-20) + 1.0e-20 ); */ - exp_normn = norm_s(max_peak_fx); - exp_normn = sub(exp_normn, 1); - - avg_val_fx = s_max(avg_val_fx, 0x1); - exp_normd = norm_s(avg_val_fx); - - smr_fx = div_s(shl(max_peak_fx, exp_normn), shl(avg_val_fx, exp_normd)); /* Q(exp_normn-exp_normd+15) */ - exp_tmp = sub(exp_normn, exp_normd); - L_smr = L_deposit_h(smr_fx); /* Q+16 -> Q(exp_normn-exp_normd+15+16) */ - Qsmr = add(sub(add(Qm, exp_tmp), Qavg_val), 31); - - L_temp = L_add(L_shr(L_smr, 1), 0x1L); /* add minimum value */ - exp = norm_l(L_temp); - frac = Log2_norm_lc(L_shl(L_temp, exp)); - exp = sub(30, exp); - exp = sub(exp, sub(Qsmr, 1)); - L_temp = L_Comp(exp, frac); - - L_temp = Mpy_32_16_1(L_temp, 12330); /* 3.0103 in Q12 */ - L_temp = L_shl(L_temp, 2 + 8); /* Q7 */ - smr_fx = round_fx(L_temp); - - FOR(i = 0; i < num_subband_smooth_fx; i++) - { - L_temp_sum_1[i] = L_deposit_l(0); - L_temp_sum_2[i] = L_deposit_l(0); - - FOR(k = 0; k < L_SB_NSS_HALF; k++) - { - L_temp_sum_1[i] = L_add(L_temp_sum_1[i], extract_l(abs_s(inBufw_fx[k + L_SB_NSS * i]))); /* Qm */ move32(); - } - - FOR(k = L_SB_NSS_HALF; k < L_SB_NSS; k++) - { - L_temp_sum_2[i] = L_add(L_temp_sum_2[i], extract_l(abs_s(inBufw_fx[k + L_SB_NSS * i]))); /* Qm */ move32(); - } - - L_temp_sum_1[i] = L_shr(L_temp_sum_1[i], 2); /* *0.25 guarantee low-side 16bit for L_temp_sum_* */ move32(); - L_temp_sum_2[i] = L_shr(L_temp_sum_2[i], 2); /* *0.25 */ move32(); - L_temp_sum_3[i] = L_mult(extract_l(L_temp_sum_1[i]), extract_l(L_temp_sum_2[i])); /* Qm*2+1 */ move32(); - - IF(L_temp_sum_3[i] == 0) - { - L_temp_sum_3[i] = L_shl(L_add(L_temp_sum_1[i], L_temp_sum_2[i]), add(Qm, 1)); /*Q(Qm+Qm+1) */ move32(); - } - } - - exp_norm = add(shl(Qm, 1), 1); - Get20Log10Spec_fx(L_temp_sum_3, temp_sum_log_fx, num_subband_smooth_fx, exp_norm); - - /* temp_sum_log_fx // *0.5 Q7 -> Q8 (not change) */ - SmoothSpec_fx(temp_sum_log_fx, temp_sum_smooth_fx, num_subband_smooth_fx); - - FOR(i = 0; i < num_subband_smooth_fx; i++) - { - L_temp1 = L_mult(temp_sum_smooth_fx[i], 1360); /* Q8+Q13+1=Q22, 1360(Q13) = 0.1660 = 3.321928(log2^10) * 0.05 */ - L_temp1 = L_shr(L_temp1, 6); /* Q22 -> Q16 */ - L_temp1 = L_negate(L_temp1); - temp_lo = L_Extract_lc(L_temp1, &temp_hi); - Qsumdiv[i] = sub(14, temp_hi); - temp_sum_div_fx[i] = extract_l(Pow2(14, temp_lo)); /* Qsumdiv[i] */ - exp_norm = norm_s(temp_sum_div_fx[i]); - temp_sum_div_fx[i] = shl(temp_sum_div_fx[i], exp_norm); - move16(); - Qsumdiv[i] = add(Qsumdiv[i], exp_norm); - move16(); - } - - *Qss = 31; - move16(); - FOR(i = 0; i < num_subband_smooth_fx; i++) - { - Qo[i] = add(add(Qm, Qsumdiv[i]), 1); - L_temp1 = 0x0L; - FOR(k = 0; k < L_SB_NSS; k++) - { - L_outBufw[k + L_SB_NSS * i] = L_mult(inBufw_fx[k + L_SB_NSS * i], temp_sum_div_fx[i]); - move32(); - L_temp1 = L_or(L_temp1, L_abs(L_outBufw[k + L_SB_NSS * i])); - } - exp_norm = 31; - if (L_temp1 != 0x0L) - { - exp_norm = norm_l(L_temp1); - } - FOR(k = 0; k < L_SB_NSS; k++) - { - L_outBufw[k + L_SB_NSS * i] = L_shl(L_outBufw[k + L_SB_NSS * i], exp_norm); - move32(); - } - Qo[i] = add(Qo[i], exp_norm); - move16(); - *Qss = s_min(*Qss, Qo[i]); - move16(); - } - - FOR(i = 0; i < num_subband_smooth_fx; i++) - { - exp_shift = sub(*Qss, Qo[i]); - exp_shift = s_max(-31, exp_shift); - FOR(k = 0; k < L_SB_NSS; k++) - { - L_outBufw[k + L_SB_NSS * i] = L_shl(L_outBufw[k + L_SB_NSS * i], exp_shift); - move16(); - outBufw_fx[k + L_SB_NSS * i] = round_fx(L_outBufw[k + L_SB_NSS * i]); - } - } - *Qss = sub(*Qss, 16); - - L_avg_val2 = L_deposit_l(0); - FOR(i = 0; i < fLen; i++) - { - L_r0 = L_abs(L_deposit_l(outBufw_fx[i])); - L_avg_val2 = L_add(L_avg_val2, L_r0); /* Qss */ - } - - exp_normn = norm_l(L_avg_val2); - exp_normn = sub(exp_normn, 1); - exp_normd = norm_s(fLen); - temp_fx = div_l(L_shl(L_avg_val2, exp_normn), shl(fLen, exp_normd)); /* Q(obw+exp_normn - exp_normd) - 1 */ - avg_val2_fx = shr(temp_fx, sub(sub(exp_normn, exp_normd), 1)); /* Qss */ - - /*clip_cof = smr - 16.0f; */ - clip_cof_fx = sub(smr_fx, 2048); /* 2048: 16.0f (Q7) */ - if (clip_cof_fx < 0) - { - clip_cof_fx = 0; - move16(); - } - /*clip_cof += 2.5f; */ - clip_cof_fx = add(clip_cof_fx, 320); /* 320: 2.5f (Q7) */ - - thre_fx = round_fx(L_shl(L_mult(avg_val2_fx, clip_cof_fx), 8)); /* Q(Qss+7+1) -> Qss */ - thre_fx_neg = negate(thre_fx); - thre_min_fx = shr(avg_val2_fx, 2); /* *0.25f // Qss */ - - FOR(i = 0; i < fLen; i++) - { - IF(GT_16(abs_s(outBufw_fx[i]), thre_fx)) - { - temp_fx = thre_fx; - move16(); - if (outBufw_fx[i] < 0) - { - temp_fx = thre_fx_neg; - move16(); - } - outBufw_fx[i] = temp_fx; - move16(); - } - - if (LT_16(abs_s(outBufw_fx[i]), thre_min_fx)) - { - outBufw_fx[i] = 0; - move16(); - } - } - - FOR(i = 0; i < fLen; i++) - { - outBuf_fx[i] = outBufw_fx[i]; - move16(); /* Qss */ - } - - return; + /* internal variable */ + Word16 i, k; + + Word16 inBuf_fx[L_FRAME32k]; + Word16 Qm; + Word32 L_tmp[L_FRAME32k]; + + Word16 num_subband_smooth_fx; + Word16 exp_tmp; + + Word16 inBufw_fx[L_FRAME32k + L_SB_NSS]; + Word16 outBufw_fx[L_FRAME32k + L_SB_NSS]; + Word32 L_outBufw[L_FRAME32k + L_SB_NSS]; + Word16 Qo[NUM_SUBBAND_SMOOTH_MAX]; + + Word16 avg_val_fx; + Word32 L_avg_val; + Word16 r0_fx; + Word32 L_r0; + Word32 L_temp; + Word16 temp_fx; + + Word16 max_peak_fx; + + Word16 smr_fx; + Word32 L_smr; + + Word32 L_temp_sum_1[NUM_SUBBAND_SMOOTH_MAX]; + Word32 L_temp_sum_2[NUM_SUBBAND_SMOOTH_MAX]; + Word32 L_temp_sum_3[NUM_SUBBAND_SMOOTH_MAX]; + + + Word16 temp_sum_smooth_fx[NUM_SUBBAND_SMOOTH_MAX]; + Word16 temp_sum_div_fx[NUM_SUBBAND_SMOOTH_MAX]; + Word16 Qsumdiv[NUM_SUBBAND_SMOOTH_MAX]; + Word32 L_temp1; + Word16 temp_hi; + Word16 temp_lo; + + + Word16 avg_val2_fx; + Word32 L_avg_val2; + Word16 Qavg_val; + Word16 Qsmr; + Word16 exp, frac; + + Word16 clip_cof_fx; + + Word16 thre_fx, thre_fx_neg; + Word16 thre_min_fx; + + Word16 temp_sum_log_fx[NUM_SUBBAND_SMOOTH_MAX]; + Word16 exp_norm; + Word16 exp_normn; + Word16 exp_normd; + Word16 exp_shift; + + L_tmp[0] = L_deposit_l( 0 ); + FOR( i = 0; i < fLen; i++ ) + { + L_tmp[0] = L_or( L_tmp[0], L_abs( L_inBuf[i] ) ); + } + exp_norm = norm_l( L_tmp[0] ); + Qm = sub( exp_norm, 4 ); /* Qm = sub(add(12, exp_norm), 16); */ + + FOR( i = 0; i < fLen; i++ ) + { + L_tmp[i] = L_shl( L_inBuf[i], exp_norm ); /* Q(12+exp_norm) */ + move32(); + inBuf_fx[i] = round_fx( L_tmp[i] ); /* Qm */ + } + + num_subband_smooth_fx = shr( fLen, 3 ); /* L_SB_NSS=8 shr(target, 3); */ + + /* buffer copy for fractional point */ + FOR( i = 0; i < fLen; i++ ) + { + inBufw_fx[i] = inBuf_fx[i]; + move16(); + outBufw_fx[i] = 0; + move16(); + } + + /* initialization of over buffer for fractional point */ + k = add( fLen, L_SB_NSS ); + FOR( i = fLen; i < k; i++ ) + { + inBufw_fx[i] = 0; + move16(); + outBufw_fx[i] = 0; + move16(); + } + + L_avg_val = L_deposit_l( 0 ); + FOR( i = 0; i < fLen; i++ ) + { + L_r0 = L_abs( L_deposit_l( inBufw_fx[i] ) ); + L_avg_val = L_add( L_avg_val, L_r0 ); + } + exp_normn = norm_l( L_avg_val ); + exp_normn = sub( exp_normn, 1 ); + exp_normd = norm_s( fLen ); + avg_val_fx = div_l( L_shl( L_avg_val, exp_normn ), shl( fLen, exp_normd ) ); /* (Qs+exp_norm+exp_normn) - (exp_normd) - 15 */ + Qavg_val = sub( add( Qm, sub( exp_normn, exp_normd ) ), 1 ); + + max_peak_fx = 0; + move16(); + FOR( i = 0; i < fLen; i++ ) + { + r0_fx = abs_s( inBufw_fx[i] ); + if ( LT_16( max_peak_fx, r0_fx ) ) + { + max_peak_fx = r0_fx; + move16(); /* Qm */ + } + } + + /*smr = 10.0f * (float)log10( max_peak/(avg_val + 1.0e-20) + 1.0e-20 ); */ + exp_normn = norm_s( max_peak_fx ); + exp_normn = sub( exp_normn, 1 ); + + avg_val_fx = s_max( avg_val_fx, 0x1 ); + exp_normd = norm_s( avg_val_fx ); + + smr_fx = div_s( shl( max_peak_fx, exp_normn ), shl( avg_val_fx, exp_normd ) ); /* Q(exp_normn-exp_normd+15) */ + exp_tmp = sub( exp_normn, exp_normd ); + L_smr = L_deposit_h( smr_fx ); /* Q+16 -> Q(exp_normn-exp_normd+15+16) */ + Qsmr = add( sub( add( Qm, exp_tmp ), Qavg_val ), 31 ); + + L_temp = L_add( L_shr( L_smr, 1 ), 0x1L ); /* add minimum value */ + exp = norm_l( L_temp ); + frac = Log2_norm_lc( L_shl( L_temp, exp ) ); + exp = sub( 30, exp ); + exp = sub( exp, sub( Qsmr, 1 ) ); + L_temp = L_Comp( exp, frac ); + + L_temp = Mpy_32_16_1( L_temp, 12330 ); /* 3.0103 in Q12 */ + L_temp = L_shl( L_temp, 2 + 8 ); /* Q7 */ + smr_fx = round_fx( L_temp ); + + FOR( i = 0; i < num_subband_smooth_fx; i++ ) + { + L_temp_sum_1[i] = L_deposit_l( 0 ); + L_temp_sum_2[i] = L_deposit_l( 0 ); + + FOR( k = 0; k < L_SB_NSS_HALF; k++ ) + { + L_temp_sum_1[i] = L_add( L_temp_sum_1[i], extract_l( abs_s( inBufw_fx[k + L_SB_NSS * i] ) ) ); /* Qm */ + move32(); + } + + FOR( k = L_SB_NSS_HALF; k < L_SB_NSS; k++ ) + { + L_temp_sum_2[i] = L_add( L_temp_sum_2[i], extract_l( abs_s( inBufw_fx[k + L_SB_NSS * i] ) ) ); /* Qm */ + move32(); + } + + L_temp_sum_1[i] = L_shr( L_temp_sum_1[i], 2 ); /* *0.25 guarantee low-side 16bit for L_temp_sum_* */ + move32(); + L_temp_sum_2[i] = L_shr( L_temp_sum_2[i], 2 ); /* *0.25 */ + move32(); + L_temp_sum_3[i] = L_mult( extract_l( L_temp_sum_1[i] ), extract_l( L_temp_sum_2[i] ) ); /* Qm*2+1 */ + move32(); + + IF( L_temp_sum_3[i] == 0 ) + { + L_temp_sum_3[i] = L_shl( L_add( L_temp_sum_1[i], L_temp_sum_2[i] ), add( Qm, 1 ) ); /*Q(Qm+Qm+1) */ + move32(); + } + } + + exp_norm = add( shl( Qm, 1 ), 1 ); + Get20Log10Spec_fx( L_temp_sum_3, temp_sum_log_fx, num_subband_smooth_fx, exp_norm ); + + /* temp_sum_log_fx // *0.5 Q7 -> Q8 (not change) */ + SmoothSpec_fx( temp_sum_log_fx, temp_sum_smooth_fx, num_subband_smooth_fx ); + + FOR( i = 0; i < num_subband_smooth_fx; i++ ) + { + L_temp1 = L_mult( temp_sum_smooth_fx[i], 1360 ); /* Q8+Q13+1=Q22, 1360(Q13) = 0.1660 = 3.321928(log2^10) * 0.05 */ + L_temp1 = L_shr( L_temp1, 6 ); /* Q22 -> Q16 */ + L_temp1 = L_negate( L_temp1 ); + temp_lo = L_Extract_lc( L_temp1, &temp_hi ); + Qsumdiv[i] = sub( 14, temp_hi ); + temp_sum_div_fx[i] = extract_l( Pow2( 14, temp_lo ) ); /* Qsumdiv[i] */ + exp_norm = norm_s( temp_sum_div_fx[i] ); + temp_sum_div_fx[i] = shl( temp_sum_div_fx[i], exp_norm ); + move16(); + Qsumdiv[i] = add( Qsumdiv[i], exp_norm ); + move16(); + } + + *Qss = 31; + move16(); + FOR( i = 0; i < num_subband_smooth_fx; i++ ) + { + Qo[i] = add( add( Qm, Qsumdiv[i] ), 1 ); + L_temp1 = 0x0L; + FOR( k = 0; k < L_SB_NSS; k++ ) + { + L_outBufw[k + L_SB_NSS * i] = L_mult( inBufw_fx[k + L_SB_NSS * i], temp_sum_div_fx[i] ); + move32(); + L_temp1 = L_or( L_temp1, L_abs( L_outBufw[k + L_SB_NSS * i] ) ); + } + exp_norm = 31; + if ( L_temp1 != 0x0L ) + { + exp_norm = norm_l( L_temp1 ); + } + FOR( k = 0; k < L_SB_NSS; k++ ) + { + L_outBufw[k + L_SB_NSS * i] = L_shl( L_outBufw[k + L_SB_NSS * i], exp_norm ); + move32(); + } + Qo[i] = add( Qo[i], exp_norm ); + move16(); + *Qss = s_min( *Qss, Qo[i] ); + move16(); + } + + FOR( i = 0; i < num_subband_smooth_fx; i++ ) + { + exp_shift = sub( *Qss, Qo[i] ); + exp_shift = s_max( -31, exp_shift ); + FOR( k = 0; k < L_SB_NSS; k++ ) + { + L_outBufw[k + L_SB_NSS * i] = L_shl( L_outBufw[k + L_SB_NSS * i], exp_shift ); + move16(); + outBufw_fx[k + L_SB_NSS * i] = round_fx( L_outBufw[k + L_SB_NSS * i] ); + } + } + *Qss = sub( *Qss, 16 ); + + L_avg_val2 = L_deposit_l( 0 ); + FOR( i = 0; i < fLen; i++ ) + { + L_r0 = L_abs( L_deposit_l( outBufw_fx[i] ) ); + L_avg_val2 = L_add( L_avg_val2, L_r0 ); /* Qss */ + } + + exp_normn = norm_l( L_avg_val2 ); + exp_normn = sub( exp_normn, 1 ); + exp_normd = norm_s( fLen ); + temp_fx = div_l( L_shl( L_avg_val2, exp_normn ), shl( fLen, exp_normd ) ); /* Q(obw+exp_normn - exp_normd) - 1 */ + avg_val2_fx = shr( temp_fx, sub( sub( exp_normn, exp_normd ), 1 ) ); /* Qss */ + + /*clip_cof = smr - 16.0f; */ + clip_cof_fx = sub( smr_fx, 2048 ); /* 2048: 16.0f (Q7) */ + if ( clip_cof_fx < 0 ) + { + clip_cof_fx = 0; + move16(); + } + /*clip_cof += 2.5f; */ + clip_cof_fx = add( clip_cof_fx, 320 ); /* 320: 2.5f (Q7) */ + + thre_fx = round_fx( L_shl( L_mult( avg_val2_fx, clip_cof_fx ), 8 ) ); /* Q(Qss+7+1) -> Qss */ + thre_fx_neg = negate( thre_fx ); + thre_min_fx = shr( avg_val2_fx, 2 ); /* *0.25f // Qss */ + + FOR( i = 0; i < fLen; i++ ) + { + IF( GT_16( abs_s( outBufw_fx[i] ), thre_fx ) ) + { + temp_fx = thre_fx; + move16(); + if ( outBufw_fx[i] < 0 ) + { + temp_fx = thre_fx_neg; + move16(); + } + outBufw_fx[i] = temp_fx; + move16(); + } + + if ( LT_16( abs_s( outBufw_fx[i] ), thre_min_fx ) ) + { + outBufw_fx[i] = 0; + move16(); + } + } + + FOR( i = 0; i < fLen; i++ ) + { + outBuf_fx[i] = outBufw_fx[i]; + move16(); /* Qss */ + } + + return; } /*-------------------------------------------------------------------* @@ -1551,26 +1558,26 @@ void SpectrumSmoothing_nss_fx( *-------------------------------------------------------------------*/ void return_bits_normal2_fx( - Word16 *bit_budget_fx, /* i/o : bit budget */ - const Word16 p2a_flags_fx[], /* i : HF tonal indicator */ - const Word16 bands_fx, /* i : Total number of Subbands in a frame */ - const Word16 bits_lagIndices_fx[] /* i : bits for lagIndices */ + Word16 *bit_budget_fx, /* i/o : bit budget */ + const Word16 p2a_flags_fx[], /* i : HF tonal indicator */ + const Word16 bands_fx, /* i : Total number of Subbands in a frame */ + const Word16 bits_lagIndices_fx[] /* i : bits for lagIndices */ ) { - Word16 i; - const Word16 *p_p2a_flags_fx; - - p_p2a_flags_fx = &p2a_flags_fx[sub(bands_fx, NB_SWB_SUBBANDS)]; - FOR(i = 0; i < NB_SWB_SUBBANDS; i++) - { - if (EQ_16(*p_p2a_flags_fx++, 1)) - { - *bit_budget_fx = add(*bit_budget_fx, bits_lagIndices_fx[i]); - move16(); - } - } - - return; + Word16 i; + const Word16 *p_p2a_flags_fx; + + p_p2a_flags_fx = &p2a_flags_fx[sub( bands_fx, NB_SWB_SUBBANDS )]; + FOR( i = 0; i < NB_SWB_SUBBANDS; i++ ) + { + if ( EQ_16( *p_p2a_flags_fx++, 1 ) ) + { + *bit_budget_fx = add( *bit_budget_fx, bits_lagIndices_fx[i] ); + move16(); + } + } + + return; } /*-------------------------------------------------------------------* @@ -1579,38 +1586,37 @@ void return_bits_normal2_fx( * preset before swb_bwe_{enc,dec}_lr *-------------------------------------------------------------------*/ -void preset_hq2_swb_fx -( - const Word16 hqswb_clas_fx, /* i : HQ2 class information */ - const Word16 band_end_fx[], /* i : band end of each SB */ - Word16 *har_bands_fx, /* i/o : Number of LF harmonic bands */ - Word16 p2a_bands_fx, /* i : flag for peakness */ - const Word16 length_fx, /* i : processed band length */ - const Word16 bands_fx, /* i : Total number of Subbands in a frame */ - Word16 *lowlength_fx, /* o : lowband length */ - Word16 *highlength_fx, /* o : highband length */ - Word32 L_m[] /* o : MDCT */ +void preset_hq2_swb_fx( + const Word16 hqswb_clas_fx, /* i : HQ2 class information */ + const Word16 band_end_fx[], /* i : band end of each SB */ + Word16 *har_bands_fx, /* i/o : Number of LF harmonic bands */ + Word16 p2a_bands_fx, /* i : flag for peakness */ + const Word16 length_fx, /* i : processed band length */ + const Word16 bands_fx, /* i : Total number of Subbands in a frame */ + Word16 *lowlength_fx, /* o : lowband length */ + Word16 *highlength_fx, /* o : highband length */ + Word32 L_m[] /* o : MDCT */ ) { - IF(EQ_16(hqswb_clas_fx, HQ_HARMONIC)) - { - *har_bands_fx = add(sub(bands_fx, p2a_bands_fx), 1); - move16(); - *lowlength_fx = add(band_end_fx[*har_bands_fx - 1], 1); - move16(); - } - ELSE - { - *lowlength_fx = add(band_end_fx[bands_fx - NB_SWB_SUBBANDS - 1], 1); - move16(); - } - - *highlength_fx = sub(length_fx, *lowlength_fx); - move16(); - - set32_fx(L_m, 0, length_fx); - - return; + IF( EQ_16( hqswb_clas_fx, HQ_HARMONIC ) ) + { + *har_bands_fx = add( sub( bands_fx, p2a_bands_fx ), 1 ); + move16(); + *lowlength_fx = add( band_end_fx[*har_bands_fx - 1], 1 ); + move16(); + } + ELSE + { + *lowlength_fx = add( band_end_fx[bands_fx - NB_SWB_SUBBANDS - 1], 1 ); + move16(); + } + + *highlength_fx = sub( length_fx, *lowlength_fx ); + move16(); + + set32_fx( L_m, 0, length_fx ); + + return; } /*-------------------------------------------------------------------* @@ -1619,54 +1625,53 @@ void preset_hq2_swb_fx * post process after swb_bwe_{enc,dec}_lr *-------------------------------------------------------------------*/ -void post_hq2_swb_fx -( - const Word32 L_m[], /* i : input_signal */ - const Word16 lowlength_fx, /* i : lowband length */ - const Word16 highlength_fx, /* i : highband length */ - const Word16 hqswb_clas_fx, /* i : HQ2 class information */ - const Word16 har_bands_fx, /* i : Number of LF harmonic bands */ - const Word16 bands_fx, /* i : Total number of Subbands in a frame */ - const Word16 p2a_flags_fx[], /* i : HF tonal indicator */ - const Word16 band_start_fx[], /* i : band start of each SB */ - const Word16 band_end_fx[], /* i : band end of each SB */ - Word32 L_y2[], /* o : output signal */ - Word16 npulses_fx[] /* i/o : Number of coded spectrum */ +void post_hq2_swb_fx( + const Word32 L_m[], /* i : input_signal */ + const Word16 lowlength_fx, /* i : lowband length */ + const Word16 highlength_fx, /* i : highband length */ + const Word16 hqswb_clas_fx, /* i : HQ2 class information */ + const Word16 har_bands_fx, /* i : Number of LF harmonic bands */ + const Word16 bands_fx, /* i : Total number of Subbands in a frame */ + const Word16 p2a_flags_fx[], /* i : HF tonal indicator */ + const Word16 band_start_fx[], /* i : band start of each SB */ + const Word16 band_end_fx[], /* i : band end of each SB */ + Word32 L_y2[], /* o : output signal */ + Word16 npulses_fx[] /* i/o : Number of coded spectrum */ ) { - Word16 i, k; - - /* copy the scratch buffer to the output */ - Copy32(&L_m[lowlength_fx], &L_y2[lowlength_fx], highlength_fx); - - IF(EQ_16(hqswb_clas_fx, HQ_HARMONIC)) - { - k = har_bands_fx; - move16(); - } - ELSE - { - k = sub(bands_fx, NB_SWB_SUBBANDS); - move16(); - } - - FOR(; k < bands_fx; k++) - { - test(); - IF(p2a_flags_fx[k] == 0 && npulses_fx[k] == 0) - { - FOR(i = band_start_fx[k]; i <= band_end_fx[k]; i++) - { - if (L_y2[i] != 0) - { - npulses_fx[k] = add(npulses_fx[k], 1); - move16(); - } - } - } - } - - return; + Word16 i, k; + + /* copy the scratch buffer to the output */ + Copy32( &L_m[lowlength_fx], &L_y2[lowlength_fx], highlength_fx ); + + IF( EQ_16( hqswb_clas_fx, HQ_HARMONIC ) ) + { + k = har_bands_fx; + move16(); + } + ELSE + { + k = sub( bands_fx, NB_SWB_SUBBANDS ); + move16(); + } + + FOR( ; k < bands_fx; k++ ) + { + test(); + IF( p2a_flags_fx[k] == 0 && npulses_fx[k] == 0 ) + { + FOR( i = band_start_fx[k]; i <= band_end_fx[k]; i++ ) + { + if ( L_y2[i] != 0 ) + { + npulses_fx[k] = add( npulses_fx[k], 1 ); + move16(); + } + } + } + } + + return; } /*--------------------------------------------------------------------------* @@ -1676,63 +1681,63 @@ void post_hq2_swb_fx *--------------------------------------------------------------------------*/ void GetSynthesizedSpecThinOut_fx( - const Word16 *predBuf_fx, /* i : Qss: prediction buffer (i.e., lowband) */ - const Word16 Qss, /* i : Q value of input vector */ - Word32 *L_outBuf, /* o : QsL: synthesized spectrum */ - Word16 QsL, /* o : Q value of synthesized spectrum */ - const Word16 nBands_fx, /* i : Q0: number of subbands calculated */ - const Word16 *sbWidth_fx, /* i : Q0: subband lengths */ - const Word16 *lagIndices_fx, /* i : Q0: lowband index for each subband */ - const Word16 *lagGains_fx, /* i : Qgain: lagGain for each subband */ - const Word16 *QlagGains_fx, /* i : Q0: Q value of lagGains_fx */ - const Word16 predBufLen_fx /* i : Q0: lowband length */ + const Word16 *predBuf_fx, /* i : Qss: prediction buffer (i.e., lowband) */ + const Word16 Qss, /* i : Q value of input vector */ + Word32 *L_outBuf, /* o : QsL: synthesized spectrum */ + Word16 QsL, /* o : Q value of synthesized spectrum */ + const Word16 nBands_fx, /* i : Q0: number of subbands calculated */ + const Word16 *sbWidth_fx, /* i : Q0: subband lengths */ + const Word16 *lagIndices_fx, /* i : Q0: lowband index for each subband */ + const Word16 *lagGains_fx, /* i : Qgain: lagGain for each subband */ + const Word16 *QlagGains_fx, /* i : Q0: Q value of lagGains_fx */ + const Word16 predBufLen_fx /* i : Q0: lowband length */ ) { - Word16 i, sb; - Word16 fLen_fx, lag_fx; - - const Word16 *ptr_predBuf_fx; - Word32 *ptr_L_outBuf; - Word32 *ptr_L_in_outBuf; - - Word16 exp_shift; - - ptr_L_in_outBuf = L_outBuf; - ptr_L_outBuf = L_outBuf; - - FOR(sb = 0; sb < nBands_fx; sb++) - { - fLen_fx = sbWidth_fx[sb]; - lag_fx = lagIndices_fx[sb]; - - if (GT_16(add(lag_fx, fLen_fx), predBufLen_fx)) - { - /* should never happen */ - lag_fx = sub(predBufLen_fx, fLen_fx); - } - ptr_predBuf_fx = predBuf_fx + lag_fx; - - - exp_shift = sub(add(add(Qss, QlagGains_fx[sb]), 1), QsL); - - FOR(i = 0; i < fLen_fx; i++) - { - IF(*ptr_predBuf_fx >= 0x0L) - { - *ptr_L_outBuf++ = L_shr(L_mult(*ptr_predBuf_fx++, lagGains_fx[sb]), exp_shift); - move32(); /* Qss+QlagGains+1 -> QsL */ - } - ELSE - { - *ptr_L_outBuf++ = L_negate(L_shr(L_mult(abs_s(*ptr_predBuf_fx++), lagGains_fx[sb]), exp_shift)); - move32(); /* Qss+QlagGains+1 -> QsL */ - } - } - } - - ptr_L_outBuf = ptr_L_in_outBuf; - - return; + Word16 i, sb; + Word16 fLen_fx, lag_fx; + + const Word16 *ptr_predBuf_fx; + Word32 *ptr_L_outBuf; + Word32 *ptr_L_in_outBuf; + + Word16 exp_shift; + + ptr_L_in_outBuf = L_outBuf; + ptr_L_outBuf = L_outBuf; + + FOR( sb = 0; sb < nBands_fx; sb++ ) + { + fLen_fx = sbWidth_fx[sb]; + lag_fx = lagIndices_fx[sb]; + + if ( GT_16( add( lag_fx, fLen_fx ), predBufLen_fx ) ) + { + /* should never happen */ + lag_fx = sub( predBufLen_fx, fLen_fx ); + } + ptr_predBuf_fx = predBuf_fx + lag_fx; + + + exp_shift = sub( add( add( Qss, QlagGains_fx[sb] ), 1 ), QsL ); + + FOR( i = 0; i < fLen_fx; i++ ) + { + IF( *ptr_predBuf_fx >= 0x0L ) + { + *ptr_L_outBuf++ = L_shr( L_mult( *ptr_predBuf_fx++, lagGains_fx[sb] ), exp_shift ); + move32(); /* Qss+QlagGains+1 -> QsL */ + } + ELSE + { + *ptr_L_outBuf++ = L_negate( L_shr( L_mult( abs_s( *ptr_predBuf_fx++ ), lagGains_fx[sb] ), exp_shift ) ); + move32(); /* Qss+QlagGains+1 -> QsL */ + } + } + } + + ptr_L_outBuf = ptr_L_in_outBuf; + + return; } /*--------------------------------------------------------------------------* @@ -1741,31 +1746,31 @@ void GetSynthesizedSpecThinOut_fx( * compute division with Word16 Q0. ex. 10/2 -> 5 *--------------------------------------------------------------------------*/ -Word16 div_s_ss( /* o: result of division (Word16 Q0) */ - const Word16 n, /* i: numerator (Word16 Q0 */ - const Word16 d /* i: denominator (Word16 Q0) */ +Word16 div_s_ss( /* o: result of division (Word16 Q0) */ + const Word16 n, /* i: numerator (Word16 Q0 */ + const Word16 d /* i: denominator (Word16 Q0) */ ) { - Word16 norm_n, norm_d; - Word16 ns, ds; - Word16 res; + Word16 norm_n, norm_d; + Word16 ns, ds; + Word16 res; - test(); - IF(n == 0 || d == 0) - { - return 0; - } + test(); + IF( n == 0 || d == 0 ) + { + return 0; + } - norm_n = norm_s(n); - norm_n = sub(norm_n, 1); - ns = shl(n, norm_n); + norm_n = norm_s( n ); + norm_n = sub( norm_n, 1 ); + ns = shl( n, norm_n ); - norm_d = norm_s(d); - ds = shl(d, norm_d); + norm_d = norm_s( d ); + ds = shl( d, norm_d ); - res = shr(div_s(ns, ds), add(sub(norm_n, norm_d), 15)); + res = shr( div_s( ns, ds ), add( sub( norm_n, norm_d ), 15 ) ); - return res; + return res; } /*-------------------------------------------------------------------* * hf_parinitiz() @@ -1773,220 +1778,219 @@ Word16 div_s_ss( /* o: result of division (Word16 Q0) */ * *-------------------------------------------------------------------*/ void hf_parinitiz_fx( - const Word32 L_total_brate, - const Word16 hqswb_clas_fx, - Word16 lowlength_fx, - Word16 highlength_fx, - Word16 wBands_fx[], - const Word16 **subband_search_offset_fx, - const Word16 **subband_offsets_fx, - Word16 *nBands_fx, - Word16 *nBands_search_fx, - Word16 *swb_lowband_fx, - Word16 *swb_highband_fx -) + const Word32 L_total_brate, + const Word16 hqswb_clas_fx, + Word16 lowlength_fx, + Word16 highlength_fx, + Word16 wBands_fx[], + const Word16 **subband_search_offset_fx, + const Word16 **subband_offsets_fx, + Word16 *nBands_fx, + Word16 *nBands_search_fx, + Word16 *swb_lowband_fx, + Word16 *swb_highband_fx ) { - *swb_lowband_fx = lowlength_fx; - move16(); - *swb_highband_fx = highlength_fx; - move16(); - - IF(EQ_16(hqswb_clas_fx, HQ_HARMONIC)) - { - /* Mode dependent initializations (performed every frame in case mode-switching implemented) */ - *nBands_fx = NB_SWB_SUBBANDS_HAR; - move16(); - *nBands_search_fx = NB_SWB_SUBBANDS_HAR_SEARCH_SB; - move16(); - - IF(EQ_32(L_total_brate, HQ_13k20)) - { - wBands_fx[0] = SWB_SB_BW_LEN0_12KBPS_HAR; - move16(); - wBands_fx[1] = SWB_SB_BW_LEN1_12KBPS_HAR; - move16(); - wBands_fx[2] = SWB_SB_BW_LEN2_12KBPS_HAR; - move16(); - wBands_fx[3] = SWB_SB_BW_LEN3_12KBPS_HAR; - move16(); - *subband_offsets_fx = subband_offsets_sub5_13p2kbps_Har; - move16(); - *subband_search_offset_fx = subband_search_offsets_13p2kbps_Har; - move16(); - } - ELSE - { - wBands_fx[0] = SWB_SB_BW_LEN0_16KBPS_HAR; - move16(); - wBands_fx[1] = SWB_SB_BW_LEN1_16KBPS_HAR; - move16(); - wBands_fx[2] = SWB_SB_BW_LEN2_16KBPS_HAR; - move16(); - wBands_fx[3] = SWB_SB_BW_LEN3_16KBPS_HAR; - move16(); - *subband_offsets_fx = subband_offsets_sub5_16p4kbps_Har; - move16(); - *subband_search_offset_fx = subband_search_offsets_16p4kbps_Har; - move16(); - } - } - ELSE - { - /* Mode-dependent initializations (performed every frame in case mode-switching implemented) */ - *nBands_fx = NB_SWB_SUBBANDS; - move16(); - *nBands_search_fx = NB_SWB_SUBBANDS; - move16(); - - IF(EQ_32(L_total_brate, HQ_13k20)) - { - wBands_fx[0] = SWB_SB_LEN0_12KBPS; - move16(); - wBands_fx[1] = SWB_SB_LEN1_12KBPS; - move16(); - wBands_fx[2] = SWB_SB_LEN2_12KBPS; - move16(); - wBands_fx[3] = SWB_SB_LEN3_12KBPS; - move16(); - *subband_offsets_fx = subband_offsets_12KBPS; - move16(); - } - ELSE - { - wBands_fx[0] = SWB_SB_LEN0_16KBPS; - move16(); - wBands_fx[1] = SWB_SB_LEN1_16KBPS; - move16(); - wBands_fx[2] = SWB_SB_LEN2_16KBPS; - move16(); - wBands_fx[3] = SWB_SB_LEN3_16KBPS; - move16(); - *subband_offsets_fx = subband_offsets_16KBPS; - move16(); - } - } - - return; + *swb_lowband_fx = lowlength_fx; + move16(); + *swb_highband_fx = highlength_fx; + move16(); + + IF( EQ_16( hqswb_clas_fx, HQ_HARMONIC ) ) + { + /* Mode dependent initializations (performed every frame in case mode-switching implemented) */ + *nBands_fx = NB_SWB_SUBBANDS_HAR; + move16(); + *nBands_search_fx = NB_SWB_SUBBANDS_HAR_SEARCH_SB; + move16(); + + IF( EQ_32( L_total_brate, HQ_13k20 ) ) + { + wBands_fx[0] = SWB_SB_BW_LEN0_12KBPS_HAR; + move16(); + wBands_fx[1] = SWB_SB_BW_LEN1_12KBPS_HAR; + move16(); + wBands_fx[2] = SWB_SB_BW_LEN2_12KBPS_HAR; + move16(); + wBands_fx[3] = SWB_SB_BW_LEN3_12KBPS_HAR; + move16(); + *subband_offsets_fx = subband_offsets_sub5_13p2kbps_Har; + move16(); + *subband_search_offset_fx = subband_search_offsets_13p2kbps_Har; + move16(); + } + ELSE + { + wBands_fx[0] = SWB_SB_BW_LEN0_16KBPS_HAR; + move16(); + wBands_fx[1] = SWB_SB_BW_LEN1_16KBPS_HAR; + move16(); + wBands_fx[2] = SWB_SB_BW_LEN2_16KBPS_HAR; + move16(); + wBands_fx[3] = SWB_SB_BW_LEN3_16KBPS_HAR; + move16(); + *subband_offsets_fx = subband_offsets_sub5_16p4kbps_Har; + move16(); + *subband_search_offset_fx = subband_search_offsets_16p4kbps_Har; + move16(); + } + } + ELSE + { + /* Mode-dependent initializations (performed every frame in case mode-switching implemented) */ + *nBands_fx = NB_SWB_SUBBANDS; + move16(); + *nBands_search_fx = NB_SWB_SUBBANDS; + move16(); + + IF( EQ_32( L_total_brate, HQ_13k20 ) ) + { + wBands_fx[0] = SWB_SB_LEN0_12KBPS; + move16(); + wBands_fx[1] = SWB_SB_LEN1_12KBPS; + move16(); + wBands_fx[2] = SWB_SB_LEN2_12KBPS; + move16(); + wBands_fx[3] = SWB_SB_LEN3_12KBPS; + move16(); + *subband_offsets_fx = subband_offsets_12KBPS; + move16(); + } + ELSE + { + wBands_fx[0] = SWB_SB_LEN0_16KBPS; + move16(); + wBands_fx[1] = SWB_SB_LEN1_16KBPS; + move16(); + wBands_fx[2] = SWB_SB_LEN2_16KBPS; + move16(); + wBands_fx[3] = SWB_SB_LEN3_16KBPS; + move16(); + *subband_offsets_fx = subband_offsets_16KBPS; + move16(); + } + } + + return; } void GetlagGains_fx( - const Word16 *predBuf_fx, /* i: Qss Low freq. Smoothed Spectrum */ - const Word16 Qss, /* i: Q0 Q value of predBuf */ - const Word32 *L_band_energy, /* i: Qbe Band Energy */ - const Word16 Qbe, /* i: Q0 Q value of band energy */ - const Word16 nBands, /* i: Q0 number of SWB subbands */ - const Word16 *sbWidth, /* i: Q0 width of SWB subbands */ - const Word16 *lagIndices, /* i: Q0 lagIndices */ - const Word16 predBufLen, /* i: Q0 length of predBuf */ - Word16 *lagGains_fx, /* o: QlagGains lagGains */ - Word16 *QlagGains /* o: Q0 Q value of lagGains */ + const Word16 *predBuf_fx, /* i: Qss Low freq. Smoothed Spectrum */ + const Word16 Qss, /* i: Q0 Q value of predBuf */ + const Word32 *L_band_energy, /* i: Qbe Band Energy */ + const Word16 Qbe, /* i: Q0 Q value of band energy */ + const Word16 nBands, /* i: Q0 number of SWB subbands */ + const Word16 *sbWidth, /* i: Q0 width of SWB subbands */ + const Word16 *lagIndices, /* i: Q0 lagIndices */ + const Word16 predBufLen, /* i: Q0 length of predBuf */ + Word16 *lagGains_fx, /* o: QlagGains lagGains */ + Word16 *QlagGains /* o: Q0 Q value of lagGains */ ) { - Word16 i; - Word16 sb, fLen, lag; - - Word32 L_outBuf[L_FRAME32k]; - - Word16 *ptr_ssBuf_fx; - Word32 L_lagEnergy; - Word16 Qene; - - Word16 temp_lo_fx, temp_hi_fx; - Word16 pow_fx; - Word16 Qpow; - Word16 exp_normd, exp_normn; - Word16 Qdiv; - Word16 exp_norm; - - Word16 temp_fx; - Word32 L_temp; - - Word16 ssBuf_fx[L_FRAME32k]; - Word16 exp_norm_ss; - - exp_norm_ss = 2; - move16(); - FOR(i = 0; i < predBufLen; i++) - { - ssBuf_fx[i] = shr(predBuf_fx[i], exp_norm_ss); - move16(); /* Qss+exp_norm_ss */ - } - - FOR(sb = 0; sb < nBands; sb++) - { - fLen = sbWidth[sb]; - move16(); - lag = lagIndices[sb]; - move16(); - - IF(GT_16(add(lag, fLen), predBufLen)) - { - /* should never happen */ - lag = sub(predBufLen, fLen); - move16(); - } - - GetPredictedSignal_fx(predBuf_fx, L_outBuf, lag, fLen, 0x7fff, 15); - - ptr_ssBuf_fx = ssBuf_fx + lag; - L_lagEnergy = L_deposit_l(0); - FOR(i = 0; i < fLen; i++) - { - L_lagEnergy = L_mac(L_lagEnergy, *ptr_ssBuf_fx, *ptr_ssBuf_fx); /* (Qss-exp_norm_ss)*2+1 */ - ptr_ssBuf_fx++; - } - Qene = add(shl(sub(Qss, exp_norm_ss), 1), 1); - - IF(L_lagEnergy != 0x0L) - { - /* lagGains[sb] = (float)sqrt( pow(2.0f, band_energy[sb]) / lagEnergy ); */ - /* Pow part (pow(2.0f, band_energy) ) */ - L_temp = L_shr(L_band_energy[sb], sub(Qbe, 16)); /* Qbe -> Q16 */ - temp_lo_fx = L_Extract_lc(L_temp, &temp_hi_fx); - Qpow = sub(14, temp_hi_fx); - pow_fx = extract_l(Pow2(14, temp_lo_fx)); /* Qpow */ - - /* Div part ( pow (2.0f, band_energy[i])/lagEenegy ) */ - exp_normn = norm_s(pow_fx); - exp_normn = sub(exp_normn, 1); - exp_normd = norm_l(L_lagEnergy); - temp_fx = div_s(shl(pow_fx, exp_normn), extract_h(L_shl(L_lagEnergy, exp_normd))); - Qdiv = add(sub(add(Qpow, exp_normn), add(Qene, exp_normd)), 31); - - exp_norm = norm_s(temp_fx); - temp_fx = shl(temp_fx, exp_norm); - Qdiv = add(Qdiv, exp_norm); - - /* Sqrt part sqrt(pow (2.0f, band_energy[i])/lagEnergy) */ - QlagGains[sb] = add(Qdiv, 16); - IF(s_and(Qdiv, 1) == 0) /* Qdiv % 2 == 0 */ - { - L_temp = Sqrt_l(L_shr(L_deposit_h(temp_fx), 1), &exp_norm); - L_temp = L_shr(L_temp, exp_norm); - QlagGains[sb] = sub(shr(QlagGains[sb], 1), 1); - move16(); - lagGains_fx[sb] = round_fx(L_temp); - } - ELSE - { - L_temp = Sqrt_l(L_deposit_h(temp_fx), &exp_norm); - L_temp = L_shr(L_temp, exp_norm); - QlagGains[sb] = shr(QlagGains[sb], 1); - move16(); - lagGains_fx[sb] = round_fx(L_temp); - } - } - ELSE - { - /* lagGains[sb] = 0.0f; */ - lagGains_fx[sb] = 0; - move16(); - QlagGains[sb] = 15; - move16(); - } - } - - return; + Word16 i; + Word16 sb, fLen, lag; + + Word32 L_outBuf[L_FRAME32k]; + + Word16 *ptr_ssBuf_fx; + Word32 L_lagEnergy; + Word16 Qene; + + Word16 temp_lo_fx, temp_hi_fx; + Word16 pow_fx; + Word16 Qpow; + Word16 exp_normd, exp_normn; + Word16 Qdiv; + Word16 exp_norm; + + Word16 temp_fx; + Word32 L_temp; + + Word16 ssBuf_fx[L_FRAME32k]; + Word16 exp_norm_ss; + + exp_norm_ss = 2; + move16(); + FOR( i = 0; i < predBufLen; i++ ) + { + ssBuf_fx[i] = shr( predBuf_fx[i], exp_norm_ss ); + move16(); /* Qss+exp_norm_ss */ + } + + FOR( sb = 0; sb < nBands; sb++ ) + { + fLen = sbWidth[sb]; + move16(); + lag = lagIndices[sb]; + move16(); + + IF( GT_16( add( lag, fLen ), predBufLen ) ) + { + /* should never happen */ + lag = sub( predBufLen, fLen ); + move16(); + } + + GetPredictedSignal_fx( predBuf_fx, L_outBuf, lag, fLen, 0x7fff, 15 ); + + ptr_ssBuf_fx = ssBuf_fx + lag; + L_lagEnergy = L_deposit_l( 0 ); + FOR( i = 0; i < fLen; i++ ) + { + L_lagEnergy = L_mac( L_lagEnergy, *ptr_ssBuf_fx, *ptr_ssBuf_fx ); /* (Qss-exp_norm_ss)*2+1 */ + ptr_ssBuf_fx++; + } + Qene = add( shl( sub( Qss, exp_norm_ss ), 1 ), 1 ); + + IF( L_lagEnergy != 0x0L ) + { + /* lagGains[sb] = (float)sqrt( pow(2.0f, band_energy[sb]) / lagEnergy ); */ + /* Pow part (pow(2.0f, band_energy) ) */ + L_temp = L_shr( L_band_energy[sb], sub( Qbe, 16 ) ); /* Qbe -> Q16 */ + temp_lo_fx = L_Extract_lc( L_temp, &temp_hi_fx ); + Qpow = sub( 14, temp_hi_fx ); + pow_fx = extract_l( Pow2( 14, temp_lo_fx ) ); /* Qpow */ + + /* Div part ( pow (2.0f, band_energy[i])/lagEenegy ) */ + exp_normn = norm_s( pow_fx ); + exp_normn = sub( exp_normn, 1 ); + exp_normd = norm_l( L_lagEnergy ); + temp_fx = div_s( shl( pow_fx, exp_normn ), extract_h( L_shl( L_lagEnergy, exp_normd ) ) ); + Qdiv = add( sub( add( Qpow, exp_normn ), add( Qene, exp_normd ) ), 31 ); + + exp_norm = norm_s( temp_fx ); + temp_fx = shl( temp_fx, exp_norm ); + Qdiv = add( Qdiv, exp_norm ); + + /* Sqrt part sqrt(pow (2.0f, band_energy[i])/lagEnergy) */ + QlagGains[sb] = add( Qdiv, 16 ); + IF( s_and( Qdiv, 1 ) == 0 ) /* Qdiv % 2 == 0 */ + { + L_temp = Sqrt_l( L_shr( L_deposit_h( temp_fx ), 1 ), &exp_norm ); + L_temp = L_shr( L_temp, exp_norm ); + QlagGains[sb] = sub( shr( QlagGains[sb], 1 ), 1 ); + move16(); + lagGains_fx[sb] = round_fx( L_temp ); + } + ELSE + { + L_temp = Sqrt_l( L_deposit_h( temp_fx ), &exp_norm ); + L_temp = L_shr( L_temp, exp_norm ); + QlagGains[sb] = shr( QlagGains[sb], 1 ); + move16(); + lagGains_fx[sb] = round_fx( L_temp ); + } + } + ELSE + { + /* lagGains[sb] = 0.0f; */ + lagGains_fx[sb] = 0; + move16(); + QlagGains[sb] = 15; + move16(); + } + } + + return; } /*--------------------------------------------------------------------------* @@ -1995,147 +1999,147 @@ void GetlagGains_fx( *--------------------------------------------------------------------------*/ void noise_extr_corcod_fx( - Word32 L_spectra[], /* i : QsL core coder */ - const Word32 L_spectra_ni[], /* i : QsL core coder with sparse filling */ - Word16 sspectra_fx[], /* o : Qss Smoothed tonal information from core coder */ - Word16 sspectra_diff_fx[], /* o : Qss non tonal infomration for gap filling */ - Word16 sspectra_ni_fx[], /* o : Qss smoothed core coder */ - const Word16 fLenLow_fx, /* i : Q0 low frequency bands width */ - Word16 prev_hqswb_clas, /* i : Q0 classification information */ - Word16 *prev_ni_ratio_fx, /* i : Q15 noise parameter */ - Word16 *Qss /* o : Q0 Q value for sspectra_*_fx */ + Word32 L_spectra[], /* i : QsL core coder */ + const Word32 L_spectra_ni[], /* i : QsL core coder with sparse filling */ + Word16 sspectra_fx[], /* o : Qss Smoothed tonal information from core coder */ + Word16 sspectra_diff_fx[], /* o : Qss non tonal infomration for gap filling */ + Word16 sspectra_ni_fx[], /* o : Qss smoothed core coder */ + const Word16 fLenLow_fx, /* i : Q0 low frequency bands width */ + Word16 prev_hqswb_clas, /* i : Q0 classification information */ + Word16 *prev_ni_ratio_fx, /* i : Q15 noise parameter */ + Word16 *Qss /* o : Q0 Q value for sspectra_*_fx */ ) { - Word16 i, pulse_num_fx; - Word32 L_spectra_diff[L_FRAME32k]; /* QsL */ - Word16 Qss_s, Qss_d; - Word16 ni_ratio_fx, ni_ratio_cur_fx, br_adj_fx; /* Q15 */ - Word16 tmp_fx; - Word16 exp_normn, exp_normd, exp_shift; - Word16 exp_norm; - - /*Spectrum Smoothing for tonal signals*/ - SpectrumSmoothing_nss_fx(L_spectra, sspectra_fx, &Qss_s, fLenLow_fx); - Copy(sspectra_fx, sspectra_ni_fx, fLenLow_fx); - tmp_fx = 0; - FOR(i = 0; i < fLenLow_fx; i++) - { - tmp_fx |= abs_s(sspectra_fx[i]); - logic16(); - } - exp_norm = norm_s(tmp_fx); - FOR(i = 0; i < fLenLow_fx; i++) - { - sspectra_fx[i] = shl(sspectra_fx[i], exp_norm); - move16(); - } - Qss_s = add(Qss_s, exp_norm); - - /*noise extraction*/ - FOR(i = 0; i < fLenLow_fx; i++) - { - L_spectra_diff[i] = L_sub(L_spectra_ni[i], L_spectra[i]); - move32(); - } - SpectrumSmoothing_nss_fx(L_spectra_diff, sspectra_diff_fx, &Qss_d, fLenLow_fx); - tmp_fx = 0; - FOR(i = 0; i < fLenLow_fx; i++) - { - tmp_fx |= abs_s(sspectra_diff_fx[i]); - logic16(); - } - exp_norm = norm_s(tmp_fx); - FOR(i = 0; i < fLenLow_fx; i++) - { - sspectra_diff_fx[i] = shl(sspectra_diff_fx[i], exp_norm); - move16(); - } - Qss_d = add(Qss_d, exp_norm); - - IF(LT_16(Qss_s, Qss_d)) - { - *Qss = Qss_s; - move16(); - exp_shift = sub(Qss_d, *Qss); - FOR(i = 0; i < fLenLow_fx; i++) - { - sspectra_diff_fx[i] = shr(sspectra_diff_fx[i], exp_shift); - move16(); - } - } - ELSE - { - *Qss = Qss_d; - move16(); - exp_shift = sub(Qss_s, *Qss); - FOR(i = 0; i < fLenLow_fx; i++) - { - sspectra_fx[i] = shr(sspectra_fx[i], exp_shift); - move16(); - sspectra_ni_fx[i] = shr(sspectra_ni_fx[i], exp_shift); - move16(); - } - } - - /*Smoothing the noise components*/ - br_adj_fx = 29491; /* br_adj = 0.9f; Q15 */ - - pulse_num_fx = 0; - move16(); - FOR(i = 0; i < fLenLow_fx; i++) - { - if (L_spectra[i] != 0x0L) - { - pulse_num_fx = add(pulse_num_fx, 1); - } - } - - ni_ratio_cur_fx = 0x0; - move16(); - IF(pulse_num_fx != 0) - { - /*ni_ratio_cur = (fLenLow-pulse_num)/(fLenLow+0.0f);*/ - tmp_fx = sub(fLenLow_fx, pulse_num_fx); - exp_normn = norm_s(tmp_fx); - exp_normn = sub(exp_normn, 1); - exp_normd = norm_s(fLenLow_fx); - ni_ratio_cur_fx = div_s(shl(tmp_fx, exp_normn), shl(fLenLow_fx, exp_normd)); /* exp_normn - exp_normd + 15 */ - ni_ratio_cur_fx = shl(ni_ratio_cur_fx, sub(exp_normn, exp_normd)); /* 15 - (exp_normn - exp-normd + 15) */ - - /*ni_ratio_cur *= br_adj;*/ - ni_ratio_cur_fx = mult_r(ni_ratio_cur_fx, br_adj_fx); - } - - IF(EQ_16(prev_hqswb_clas, HQ_HARMONIC)) - { - IF(GT_16(ni_ratio_cur_fx, *prev_ni_ratio_fx)) - { - /* 0.8: 26214(Q15) 0.2: 6554(Q15) */ - ni_ratio_fx = mac_r(L_mult(ni_ratio_cur_fx, 26214), *prev_ni_ratio_fx, 6554); - } - ELSE - { - /* 0.6: 19661(Q15) 0.4: 13107(Q15) */ - ni_ratio_fx = mac_r(L_mult(ni_ratio_cur_fx, 19661), *prev_ni_ratio_fx, 13107); - } - } - ELSE - { - /* 0.7: 22938(Q15) */ - ni_ratio_fx = mult_r(ni_ratio_cur_fx, 22938); - } - *prev_ni_ratio_fx = ni_ratio_fx; - move16(); - - FOR(i = 0; i < fLenLow_fx; i++) - { - sspectra_diff_fx[i] = mult_r(sspectra_diff_fx[i], ni_ratio_fx); - move16(); - sspectra_ni_fx[i] = add(sspectra_fx[i], sspectra_diff_fx[i]); - move16(); - } - - return; + Word16 i, pulse_num_fx; + Word32 L_spectra_diff[L_FRAME32k]; /* QsL */ + Word16 Qss_s, Qss_d; + Word16 ni_ratio_fx, ni_ratio_cur_fx, br_adj_fx; /* Q15 */ + Word16 tmp_fx; + Word16 exp_normn, exp_normd, exp_shift; + Word16 exp_norm; + + /*Spectrum Smoothing for tonal signals*/ + SpectrumSmoothing_nss_fx( L_spectra, sspectra_fx, &Qss_s, fLenLow_fx ); + Copy( sspectra_fx, sspectra_ni_fx, fLenLow_fx ); + tmp_fx = 0; + FOR( i = 0; i < fLenLow_fx; i++ ) + { + tmp_fx |= abs_s( sspectra_fx[i] ); + logic16(); + } + exp_norm = norm_s( tmp_fx ); + FOR( i = 0; i < fLenLow_fx; i++ ) + { + sspectra_fx[i] = shl( sspectra_fx[i], exp_norm ); + move16(); + } + Qss_s = add( Qss_s, exp_norm ); + + /*noise extraction*/ + FOR( i = 0; i < fLenLow_fx; i++ ) + { + L_spectra_diff[i] = L_sub( L_spectra_ni[i], L_spectra[i] ); + move32(); + } + SpectrumSmoothing_nss_fx( L_spectra_diff, sspectra_diff_fx, &Qss_d, fLenLow_fx ); + tmp_fx = 0; + FOR( i = 0; i < fLenLow_fx; i++ ) + { + tmp_fx |= abs_s( sspectra_diff_fx[i] ); + logic16(); + } + exp_norm = norm_s( tmp_fx ); + FOR( i = 0; i < fLenLow_fx; i++ ) + { + sspectra_diff_fx[i] = shl( sspectra_diff_fx[i], exp_norm ); + move16(); + } + Qss_d = add( Qss_d, exp_norm ); + + IF( LT_16( Qss_s, Qss_d ) ) + { + *Qss = Qss_s; + move16(); + exp_shift = sub( Qss_d, *Qss ); + FOR( i = 0; i < fLenLow_fx; i++ ) + { + sspectra_diff_fx[i] = shr( sspectra_diff_fx[i], exp_shift ); + move16(); + } + } + ELSE + { + *Qss = Qss_d; + move16(); + exp_shift = sub( Qss_s, *Qss ); + FOR( i = 0; i < fLenLow_fx; i++ ) + { + sspectra_fx[i] = shr( sspectra_fx[i], exp_shift ); + move16(); + sspectra_ni_fx[i] = shr( sspectra_ni_fx[i], exp_shift ); + move16(); + } + } + + /*Smoothing the noise components*/ + br_adj_fx = 29491; /* br_adj = 0.9f; Q15 */ + + pulse_num_fx = 0; + move16(); + FOR( i = 0; i < fLenLow_fx; i++ ) + { + if ( L_spectra[i] != 0x0L ) + { + pulse_num_fx = add( pulse_num_fx, 1 ); + } + } + + ni_ratio_cur_fx = 0x0; + move16(); + IF( pulse_num_fx != 0 ) + { + /*ni_ratio_cur = (fLenLow-pulse_num)/(fLenLow+0.0f);*/ + tmp_fx = sub( fLenLow_fx, pulse_num_fx ); + exp_normn = norm_s( tmp_fx ); + exp_normn = sub( exp_normn, 1 ); + exp_normd = norm_s( fLenLow_fx ); + ni_ratio_cur_fx = div_s( shl( tmp_fx, exp_normn ), shl( fLenLow_fx, exp_normd ) ); /* exp_normn - exp_normd + 15 */ + ni_ratio_cur_fx = shl( ni_ratio_cur_fx, sub( exp_normn, exp_normd ) ); /* 15 - (exp_normn - exp-normd + 15) */ + + /*ni_ratio_cur *= br_adj;*/ + ni_ratio_cur_fx = mult_r( ni_ratio_cur_fx, br_adj_fx ); + } + + IF( EQ_16( prev_hqswb_clas, HQ_HARMONIC ) ) + { + IF( GT_16( ni_ratio_cur_fx, *prev_ni_ratio_fx ) ) + { + /* 0.8: 26214(Q15) 0.2: 6554(Q15) */ + ni_ratio_fx = mac_r( L_mult( ni_ratio_cur_fx, 26214 ), *prev_ni_ratio_fx, 6554 ); + } + ELSE + { + /* 0.6: 19661(Q15) 0.4: 13107(Q15) */ + ni_ratio_fx = mac_r( L_mult( ni_ratio_cur_fx, 19661 ), *prev_ni_ratio_fx, 13107 ); + } + } + ELSE + { + /* 0.7: 22938(Q15) */ + ni_ratio_fx = mult_r( ni_ratio_cur_fx, 22938 ); + } + *prev_ni_ratio_fx = ni_ratio_fx; + move16(); + + FOR( i = 0; i < fLenLow_fx; i++ ) + { + sspectra_diff_fx[i] = mult_r( sspectra_diff_fx[i], ni_ratio_fx ); + move16(); + sspectra_ni_fx[i] = add( sspectra_fx[i], sspectra_diff_fx[i] ); + move16(); + } + + return; } /*--------------------------------------------------------------------------* @@ -2144,282 +2148,289 @@ void noise_extr_corcod_fx( *--------------------------------------------------------------------------*/ void ton_ene_est_fx( - Word32 L_xSynth_har[], /* i/o: QsL buffer with non tonal compoents */ - const Word16 QsL, /* i : Q0 Q value for xSynth_har */ - Word32 L_be_tonal[], /* o : QbeL tonal energy of the missing bands */ - Word16 *QbeL, /* o : Q0 Q value for be_tonal */ - const Word32 L_band_energy[], /* i : Qbe subband energies */ - const Word16 Qbe, /* i : Q0 Q value for band_energy */ - const Word16 band_start[], /* i : Q0 subband start indices */ - const Word16 band_end[], /* i : Q0 subband end indices */ - const Word16 band_width[], /* i : Q0 subband widths */ - const Word16 fLenLow, /* i : Q0 low frequency width */ - const Word16 fLenHigh, /* i : Q0 High frequency width */ - const Word16 bands, /* i : Q0 total subbands */ - const Word16 har_bands, /* i : Q0 total number of harmonics bands */ - const Word16 ni_lvl_fx, /* i : Q11 noise enve for the hf bands */ - GainItem_fx pk_sf_fx[], /* i : */ - const Word16 Qss, /* i : Q0 Q value for GainItem_fx->nmrValue */ - const Word16 *pul_res /* i : Q0 tonal resolution */ + Word32 L_xSynth_har[], /* i/o: QsL buffer with non tonal compoents */ + const Word16 QsL, /* i : Q0 Q value for xSynth_har */ + Word32 L_be_tonal[], /* o : QbeL tonal energy of the missing bands */ + Word16 *QbeL, /* o : Q0 Q value for be_tonal */ + const Word32 L_band_energy[], /* i : Qbe subband energies */ + const Word16 Qbe, /* i : Q0 Q value for band_energy */ + const Word16 band_start[], /* i : Q0 subband start indices */ + const Word16 band_end[], /* i : Q0 subband end indices */ + const Word16 band_width[], /* i : Q0 subband widths */ + const Word16 fLenLow, /* i : Q0 low frequency width */ + const Word16 fLenHigh, /* i : Q0 High frequency width */ + const Word16 bands, /* i : Q0 total subbands */ + const Word16 har_bands, /* i : Q0 total number of harmonics bands */ + const Word16 ni_lvl_fx, /* i : Q11 noise enve for the hf bands */ + GainItem_fx pk_sf_fx[], /* i : */ + const Word16 Qss, /* i : Q0 Q value for GainItem_fx->nmrValue */ + const Word16 *pul_res /* i : Q0 tonal resolution */ ) { - Word16 i, j, k; - Word16 exp_norm; - Word16 Inv_band_width_fx[BANDS_MAX]; - Word16 QInvBW[BANDS_MAX]; - - Word16 xSynth_har_fx[L_FRAME32k]; - Word16 QxSynth; /* Q value for xSynth_har_fx */ - Word16 QxSynth_sft; /* Q value for xSynth_har_fx */ - - Word16 sb_ton_loc_fx[SWB_HAR_RAN1]; /* Q0 */ - Word16 sb_ton_fx[SWB_HAR_RAN1]; /* Qss */ - Word16 ni_gain_fx[NB_SWB_SUBBANDS]; - Word16 Qni_gain; - Word16 avg_pe_fx[NB_SWB_SUBBANDS]; - Word16 Qavg_pe[NB_SWB_SUBBANDS]; - Word16 QsN; /* Q value for xSynth_har after multipy ni_lvl */ - Word16 exp_safe; /* overflow prevent shift */ - - Word16 pos, count_pos_st, count_pos_end; - Word16 pul_res_bnd[NB_SWB_SUBBANDS]; - Word16 peak_fx[NB_SWB_SUBBANDS]; /* Qss */ - - Word32 L_E; - Word16 QE; - Word16 temp_lo_fx, temp_hi_fx; - Word32 L_temp; - Word16 exp_pow; - Word32 L_band_energy_Linear[BANDS_MAX]; - - Word16 exp_normd, exp_normn; - - Word16 E_r_fx; - Word16 QE_r; /* Q value for E_r_fx */ - - Word16 exp_shift; - - Word16 E_r_shift_fx; - Word16 fac_fx; - Word16 Qtemp; - Word16 temp2_fx, Qtemp2; - Word16 temp_fx; + Word16 i, j, k; + Word16 exp_norm; + Word16 Inv_band_width_fx[BANDS_MAX]; + Word16 QInvBW[BANDS_MAX]; + + Word16 xSynth_har_fx[L_FRAME32k]; + Word16 QxSynth; /* Q value for xSynth_har_fx */ + Word16 QxSynth_sft; /* Q value for xSynth_har_fx */ + + Word16 sb_ton_loc_fx[SWB_HAR_RAN1]; /* Q0 */ + Word16 sb_ton_fx[SWB_HAR_RAN1]; /* Qss */ + Word16 ni_gain_fx[NB_SWB_SUBBANDS]; + Word16 Qni_gain; + Word16 avg_pe_fx[NB_SWB_SUBBANDS]; + Word16 Qavg_pe[NB_SWB_SUBBANDS]; + Word16 QsN; /* Q value for xSynth_har after multipy ni_lvl */ + Word16 exp_safe; /* overflow prevent shift */ + + Word16 pos, count_pos_st, count_pos_end; + Word16 pul_res_bnd[NB_SWB_SUBBANDS]; + Word16 peak_fx[NB_SWB_SUBBANDS]; /* Qss */ + + Word32 L_E; + Word16 QE; + Word16 temp_lo_fx, temp_hi_fx; + Word32 L_temp; + Word16 exp_pow; + Word32 L_band_energy_Linear[BANDS_MAX]; + + Word16 exp_normd, exp_normn; + + Word16 E_r_fx; + Word16 QE_r; /* Q value for E_r_fx */ + + Word16 exp_shift; + + Word16 E_r_shift_fx; + Word16 fac_fx; + Word16 Qtemp; + Word16 temp2_fx, Qtemp2; + Word16 temp_fx; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; + Flag Overflow = 0; #endif - *QbeL = 3; - move16(); - Qni_gain = 8; - move16(); - - FOR(k = 0; k < bands; k++) - { - exp_norm = norm_s(band_width[k]); - exp_norm = sub(exp_norm, 1); - Inv_band_width_fx[k] = div_s(0x1fff, shl(band_width[k], exp_norm)); /* */ - QInvBW[k] = sub(28, exp_norm); /* 13-exp_norm+15 */ move16(); - } - - set16_fx(sb_ton_loc_fx, -1, SWB_HAR_RAN1); - set16_fx(ni_gain_fx, 0, NB_SWB_SUBBANDS); - set16_fx(avg_pe_fx, 0, NB_SWB_SUBBANDS); - set16_fx(Qavg_pe, 0, NB_SWB_SUBBANDS); - set16_fx(sb_ton_fx, 0, NB_SWB_SUBBANDS); - set16_fx(peak_fx, 0, NB_SWB_SUBBANDS); - FOR(i = 0; i < fLenHigh; i++) - { - L_xSynth_har[i] = Mult_32_16(L_xSynth_har[i], ni_lvl_fx); /* QsL(=12)+11-15=8 */ move32(); - } - QsN = sub(add(QsL, 11), 15); - - exp_safe = 4; /*move16();*/ - norm_vec_32_16_scale_fx(L_xSynth_har, QsN, fLenHigh, xSynth_har_fx, &QxSynth, exp_safe); - - pos = 0; - move16(); - i = sub(bands, har_bands); - FOR(k = 0; k < i; k++) - { - FOR(j = 0; j < pul_res[k]; j++) - { - sb_ton_loc_fx[pos] = pk_sf_fx[k * 8 + j].gainIndex_fx; - move16(); - sb_ton_fx[pos] = pk_sf_fx[k * 8 + j].nmrValue_fx; - move16(); - pos = add(pos, 1); - } - } - k = 0; - move16(); - pos = 0; - move16(); - DO - { - count_pos_st = pos; - WHILE(sb_ton_loc_fx[pos] <= (band_end[k + har_bands] - fLenLow) && sb_ton_loc_fx[pos] >= 0) - { - pos = add(pos, 1); - } - count_pos_end = pos; - move16(); - pul_res_bnd[k] = sub(count_pos_end, count_pos_st); - move16(); - if (pul_res_bnd[k] > 0) - { - peak_fx[k] = abs_s(sb_ton_fx[count_pos_st]); - move16(); - } - k = add(k, 1); - } WHILE(LT_16(k, NB_SWB_SUBBANDS)); - - k = 0; - move16(); - /*energy calculation for tonal components*/ - FOR(i = har_bands; i < bands; i++) - { - L_E = sum2_fx(&xSynth_har_fx[sub(band_start[i], fLenLow)], band_width[i]); - QE = add(shl(QxSynth, 1), 1); /* QxSynth*2+1 */ - - /* E_r = (float) E/(float)pow(2.0f,band_energy[i]); -> E * pow(2.0f, -band_energy) */ - /* Pow Part */ - L_temp = L_shr(L_band_energy[i], sub(Qbe, 16)); - temp_lo_fx = L_Extract_lc(L_temp, &temp_hi_fx); - - exp_pow = sub(14, temp_hi_fx); - L_band_energy_Linear[i] = Pow2(14, temp_lo_fx); - move32(); /* Qexp_pow */ + *QbeL = 3; + move16(); + Qni_gain = 8; + move16(); + + FOR( k = 0; k < bands; k++ ) + { + exp_norm = norm_s( band_width[k] ); + exp_norm = sub( exp_norm, 1 ); + Inv_band_width_fx[k] = div_s( 0x1fff, shl( band_width[k], exp_norm ) ); /* */ + QInvBW[k] = sub( 28, exp_norm ); /* 13-exp_norm+15 */ + move16(); + } + + set16_fx( sb_ton_loc_fx, -1, SWB_HAR_RAN1 ); + set16_fx( ni_gain_fx, 0, NB_SWB_SUBBANDS ); + set16_fx( avg_pe_fx, 0, NB_SWB_SUBBANDS ); + set16_fx( Qavg_pe, 0, NB_SWB_SUBBANDS ); + set16_fx( sb_ton_fx, 0, NB_SWB_SUBBANDS ); + set16_fx( peak_fx, 0, NB_SWB_SUBBANDS ); + FOR( i = 0; i < fLenHigh; i++ ) + { + L_xSynth_har[i] = Mult_32_16( L_xSynth_har[i], ni_lvl_fx ); /* QsL(=12)+11-15=8 */ + move32(); + } + QsN = sub( add( QsL, 11 ), 15 ); + + exp_safe = 4; /*move16();*/ + norm_vec_32_16_scale_fx( L_xSynth_har, QsN, fLenHigh, xSynth_har_fx, &QxSynth, exp_safe ); + + pos = 0; + move16(); + i = sub( bands, har_bands ); + FOR( k = 0; k < i; k++ ) + { + FOR( j = 0; j < pul_res[k]; j++ ) + { + sb_ton_loc_fx[pos] = pk_sf_fx[k * 8 + j].gainIndex_fx; + move16(); + sb_ton_fx[pos] = pk_sf_fx[k * 8 + j].nmrValue_fx; + move16(); + pos = add( pos, 1 ); + } + } + k = 0; + move16(); + pos = 0; + move16(); + DO + { + count_pos_st = pos; + WHILE( sb_ton_loc_fx[pos] <= ( band_end[k + har_bands] - fLenLow ) && sb_ton_loc_fx[pos] >= 0 ) + { + pos = add( pos, 1 ); + } + count_pos_end = pos; + move16(); + pul_res_bnd[k] = sub( count_pos_end, count_pos_st ); + move16(); + if ( pul_res_bnd[k] > 0 ) + { + peak_fx[k] = abs_s( sb_ton_fx[count_pos_st] ); + move16(); + } + k = add( k, 1 ); + } + WHILE( LT_16( k, NB_SWB_SUBBANDS ) ); + + k = 0; + move16(); + /*energy calculation for tonal components*/ + FOR( i = har_bands; i < bands; i++ ) + { + L_E = sum2_fx( &xSynth_har_fx[sub( band_start[i], fLenLow )], band_width[i] ); + QE = add( shl( QxSynth, 1 ), 1 ); /* QxSynth*2+1 */ + + /* E_r = (float) E/(float)pow(2.0f,band_energy[i]); -> E * pow(2.0f, -band_energy) */ + /* Pow Part */ + L_temp = L_shr( L_band_energy[i], sub( Qbe, 16 ) ); + temp_lo_fx = L_Extract_lc( L_temp, &temp_hi_fx ); + + exp_pow = sub( 14, temp_hi_fx ); + L_band_energy_Linear[i] = Pow2( 14, temp_lo_fx ); + move32(); /* Qexp_pow */ #ifdef BASOP_NOGLOB L_band_energy_Linear[i] = L_shl_sat( L_band_energy_Linear[i], sub( *QbeL, exp_pow ) ); #else - L_band_energy_Linear[i] = L_shl(L_band_energy_Linear[i], sub(*QbeL, exp_pow)); + L_band_energy_Linear[i] = L_shl( L_band_energy_Linear[i], sub( *QbeL, exp_pow ) ); #endif - /* Div Part */ - E_r_fx = 0x7fff; - move16(); - QE_r = 0; - move16(); - IF(L_band_energy_Linear[i] != 0x0L) - { - exp_normd = norm_l(L_E); - exp_normd = sub(exp_normd, 1); - exp_normn = norm_l(L_band_energy_Linear[i]); - - E_r_fx = div_s(extract_h(L_shl(L_E, exp_normd)), extract_h(L_shl(L_band_energy_Linear[i], exp_normn))); - /* QE_r = (QE-16) - (QbeL+exp_normn-16) + 15; */ - QE_r = add(sub(add(QE, exp_normd), add(*QbeL, exp_normn)), 15); - } - - L_E = L_shl(L_E, sub(*QbeL, QE)); - QE = *QbeL; - - /* 0.06=15729(Q18) */ - exp_shift = sub(18, QE_r); + /* Div Part */ + E_r_fx = 0x7fff; + move16(); + QE_r = 0; + move16(); + IF( L_band_energy_Linear[i] != 0x0L ) + { + exp_normd = norm_l( L_E ); + exp_normd = sub( exp_normd, 1 ); + exp_normn = norm_l( L_band_energy_Linear[i] ); + + E_r_fx = div_s( extract_h( L_shl( L_E, exp_normd ) ), extract_h( L_shl( L_band_energy_Linear[i], exp_normn ) ) ); + /* QE_r = (QE-16) - (QbeL+exp_normn-16) + 15; */ + QE_r = add( sub( add( QE, exp_normd ), add( *QbeL, exp_normn ) ), 15 ); + } + + L_E = L_shl( L_E, sub( *QbeL, QE ) ); + QE = *QbeL; + + /* 0.06=15729(Q18) */ + exp_shift = sub( 18, QE_r ); #ifdef BASOP_NOGLOB - E_r_shift_fx = shl_o(E_r_fx, exp_shift, &Overflow); + E_r_shift_fx = shl_o( E_r_fx, exp_shift, &Overflow ); #else - E_r_shift_fx = shl(E_r_fx, exp_shift); + E_r_shift_fx = shl( E_r_fx, exp_shift ); #endif - IF(LT_16(E_r_shift_fx, 15729)) /* E_r < 0.06 */ - { - /* avg_pe[k] = (float) sqrt(pow(2.0f,band_energy[i])/band_width[i]); */ - /* Pre SQRT part */ - /*L_temp = Mpy_32_16_1(L_band_energy_Linear[i], Inv_band_width_fx[i]);*/ /* QbeL + QInvBW -15 */ - L_temp = Mult_32_16(L_band_energy_Linear[i], Inv_band_width_fx[i]); /* QbeL + QInvBW -15 */ - Qtemp = sub(add(*QbeL, QInvBW[i]), 15); - - sqrt_32n_16_fx(L_temp, Qtemp, &avg_pe_fx[k], &Qavg_pe[k]); - - fac_fx = 19661; /* 0.6(Q15) */ - IF(pul_res_bnd[k] != 0) - { - /* Div Part */ - L_temp = Mult_32_16(L_E, Inv_band_width_fx[i]); /* QE+exp_norm+QInvBW[i]+1 */ - Qtemp = sub(add(QE, QInvBW[i]), 15); - - /* SQRT Part */ - sqrt_32n_16_fx(L_temp, Qtemp, &temp2_fx, &Qtemp2); - - /* Div Part */ - exp_normd = norm_s(temp2_fx); - exp_normd = sub(exp_normd, 1); - exp_normn = norm_s(peak_fx[k]); - - fac_fx = div_s(shl(temp2_fx, exp_normd), shl(peak_fx[k], exp_normn)); - fac_fx = shl(fac_fx, sub(add(Qss, exp_normn), add(Qtemp2, exp_normd))); /* Qtemp2+exp_normd-(Qss+exp_normn)+15 -> 15*/ - - } - - ni_gain_fx[k] = mult_r(avg_pe_fx[k], fac_fx); /* Qavg_pe[k] */ move16(); - - L_temp = L_mult(ni_gain_fx[k], ni_gain_fx[k]); - L_temp = Mult_32_16(L_temp, E_r_fx); - - /* 0.12f: 257698038 (Q31) */ + IF( LT_16( E_r_shift_fx, 15729 ) ) /* E_r < 0.06 */ + { + /* avg_pe[k] = (float) sqrt(pow(2.0f,band_energy[i])/band_width[i]); */ + /* Pre SQRT part */ + /*L_temp = Mpy_32_16_1(L_band_energy_Linear[i], Inv_band_width_fx[i]);*/ /* QbeL + QInvBW -15 */ + L_temp = Mult_32_16( L_band_energy_Linear[i], Inv_band_width_fx[i] ); /* QbeL + QInvBW -15 */ + Qtemp = sub( add( *QbeL, QInvBW[i] ), 15 ); + + sqrt_32n_16_fx( L_temp, Qtemp, &avg_pe_fx[k], &Qavg_pe[k] ); + + fac_fx = 19661; /* 0.6(Q15) */ + IF( pul_res_bnd[k] != 0 ) + { + /* Div Part */ + L_temp = Mult_32_16( L_E, Inv_band_width_fx[i] ); /* QE+exp_norm+QInvBW[i]+1 */ + Qtemp = sub( add( QE, QInvBW[i] ), 15 ); + + /* SQRT Part */ + sqrt_32n_16_fx( L_temp, Qtemp, &temp2_fx, &Qtemp2 ); + + /* Div Part */ + exp_normd = norm_s( temp2_fx ); + exp_normd = sub( exp_normd, 1 ); + exp_normn = norm_s( peak_fx[k] ); + + fac_fx = div_s( shl( temp2_fx, exp_normd ), shl( peak_fx[k], exp_normn ) ); + fac_fx = shl( fac_fx, sub( add( Qss, exp_normn ), add( Qtemp2, exp_normd ) ) ); /* Qtemp2+exp_normd-(Qss+exp_normn)+15 -> 15*/ + } + + ni_gain_fx[k] = mult_r( avg_pe_fx[k], fac_fx ); /* Qavg_pe[k] */ + move16(); + + L_temp = L_mult( ni_gain_fx[k], ni_gain_fx[k] ); + L_temp = Mult_32_16( L_temp, E_r_fx ); + + /* 0.12f: 257698038 (Q31) */ #ifdef BASOP_NOGLOB - if (GE_32(L_shl_o(L_temp, sub(31, add(add(shl(Qavg_pe[k], 1), QE_r), 1 - 15)), &Overflow), 257698038)) + if ( GE_32( L_shl_o( L_temp, sub( 31, add( add( shl( Qavg_pe[k], 1 ), QE_r ), 1 - 15 ) ), &Overflow ), 257698038 ) ) #else - if (GE_32(L_shl(L_temp, sub(31, add(add(shl(Qavg_pe[k], 1), QE_r), 1 - 15))), 257698038)) + if ( GE_32( L_shl( L_temp, sub( 31, add( add( shl( Qavg_pe[k], 1 ), QE_r ), 1 - 15 ) ) ), 257698038 ) ) #endif - { - ni_gain_fx[k] = mult_r(1638, ni_gain_fx[k]); /* 0.05 : 1638(Q15) */ move16(); - } - Overflow = 0; - move16(); - ni_gain_fx[k] = shl(ni_gain_fx[k], sub(Qni_gain, Qavg_pe[k])); - assert(Qni_gain == 8); /* 358 is '(short)(1.4*pow(2,Qni_gain))' */ - ni_gain_fx[k] = s_max(ni_gain_fx[k], 358); /* 1.4 -> 22938(Q14) */ - - exp_shift = QsL - (QxSynth + Qni_gain + 1); /* QsL - (QxSynth+Qni_gain+1) */ - FOR(j = band_start[i]; j <= band_end[i]; j++) - { - L_xSynth_har[j - fLenLow] = L_shl(L_mult(xSynth_har_fx[j - fLenLow], ni_gain_fx[k]), exp_shift); /* QsL - (QxSynth+Qni_gain+1) */ move32(); - } - - exp_safe = 4; /* move16(); */ - norm_vec_32_16_scale_fx(&L_xSynth_har[band_start[i] - fLenLow], QsL, band_width[i], &xSynth_har_fx[band_start[i] - fLenLow], &QxSynth_sft, exp_safe); - - L_E = sum2_fx(&xSynth_har_fx[sub(band_start[i], fLenLow)], band_width[i]); - QE = add(shl(QxSynth_sft, 1), 1); + { + ni_gain_fx[k] = mult_r( 1638, ni_gain_fx[k] ); /* 0.05 : 1638(Q15) */ + move16(); + } + Overflow = 0; + move16(); + ni_gain_fx[k] = shl( ni_gain_fx[k], sub( Qni_gain, Qavg_pe[k] ) ); + assert( Qni_gain == 8 ); /* 358 is '(short)(1.4*pow(2,Qni_gain))' */ + ni_gain_fx[k] = s_max( ni_gain_fx[k], 358 ); /* 1.4 -> 22938(Q14) */ + + exp_shift = QsL - ( QxSynth + Qni_gain + 1 ); /* QsL - (QxSynth+Qni_gain+1) */ + FOR( j = band_start[i]; j <= band_end[i]; j++ ) + { + L_xSynth_har[j - fLenLow] = L_shl( L_mult( xSynth_har_fx[j - fLenLow], ni_gain_fx[k] ), exp_shift ); /* QsL - (QxSynth+Qni_gain+1) */ + move32(); + } + + exp_safe = 4; /* move16(); */ + norm_vec_32_16_scale_fx( &L_xSynth_har[band_start[i] - fLenLow], QsL, band_width[i], &xSynth_har_fx[band_start[i] - fLenLow], &QxSynth_sft, exp_safe ); + + L_E = sum2_fx( &xSynth_har_fx[sub( band_start[i], fLenLow )], band_width[i] ); + QE = add( shl( QxSynth_sft, 1 ), 1 ); #ifdef BASOP_NOGLOB L_E = L_shl_sat( L_E, sub( *QbeL, QE ) ); #else - L_E = L_shl(L_E, sub(*QbeL, QE)); -#endif - QE = *QbeL; - } - ELSE - { - /* Q8 -> Q12 */ - FOR(j = band_start[i]; j <= band_end[i]; j++) - { - L_xSynth_har[j - fLenLow] = L_shl(L_xSynth_har[j - fLenLow], 4); /* Q8(12+11-15) -> Q12 */ move32(); - } - } - - k = add(k, 1); - - L_be_tonal[i] = L_sub(L_band_energy_Linear[i], L_E); - - IF(L_be_tonal[i] < 0x0L) - { - L_E = L_deposit_l(0); - FOR(j = (band_start[i] - fLenLow); j <= (band_end[i] - fLenLow); j++) - { - temp_fx = round_fx(L_shl(L_xSynth_har[j], (*QbeL + 7) / 2)); /* (12+x-16)*2+1 => QbeL */ - L_xSynth_har[j] = L_shr(L_xSynth_har[j], 2); /* 1/4 */ move32(); - L_E = L_mac(L_E, temp_fx, temp_fx); - } - - L_E = L_shr(L_E, 4); /* 1/4 */ - L_be_tonal[i] = L_sub(L_band_energy_Linear[i], L_E); - move32(); - } - } - - return; + L_E = L_shl( L_E, sub( *QbeL, QE ) ); +#endif + QE = *QbeL; + } + ELSE + { + /* Q8 -> Q12 */ + FOR( j = band_start[i]; j <= band_end[i]; j++ ) + { + L_xSynth_har[j - fLenLow] = L_shl( L_xSynth_har[j - fLenLow], 4 ); /* Q8(12+11-15) -> Q12 */ + move32(); + } + } + + k = add( k, 1 ); + + L_be_tonal[i] = L_sub( L_band_energy_Linear[i], L_E ); + + IF( L_be_tonal[i] < 0x0L ) + { + L_E = L_deposit_l( 0 ); + FOR( j = ( band_start[i] - fLenLow ); j <= ( band_end[i] - fLenLow ); j++ ) + { + temp_fx = round_fx( L_shl( L_xSynth_har[j], ( *QbeL + 7 ) / 2 ) ); /* (12+x-16)*2+1 => QbeL */ + L_xSynth_har[j] = L_shr( L_xSynth_har[j], 2 ); /* 1/4 */ + move32(); + L_E = L_mac( L_E, temp_fx, temp_fx ); + } + + L_E = L_shr( L_E, 4 ); /* 1/4 */ + L_be_tonal[i] = L_sub( L_band_energy_Linear[i], L_E ); + move32(); + } + } + + return; } @@ -2427,262 +2438,260 @@ void ton_ene_est_fx( * Gettonl_scalfact() * Gap filling for the core coder *--------------------------------------------------------------------------*/ -void Gettonl_scalfact_fx -( - Word32 *L_outBuf, /* i/o: QsL synthesized spectrum */ - Word16 QsL, /* i : Q0 Q value for outBuf */ - const Word32 *L_codbuf, /* i : QsL core coder */ - const Word16 fLenLow, /* i : Q0 lowband length */ - const Word16 fLenHigh, /* i : Q0 highband length */ - const Word16 harmonic_band, /* i : Q0 total number of Low frequency bands */ - const Word16 bands, /* i : Q0 total number of subbands in a frame */ - Word32 *L_band_energy, /* i : Qbe band energy of each subband */ - Word16 Qbe, /* i : Q0 Q value for band_energy */ - const Word16 *band_start, /* i : Q0 subband start indices */ - const Word16 *band_end, /* i : Q0 subband end indices */ - const Word16 p2aflags[], /* i : Q0 missing bands in the core coder */ - Word32 L_be_tonal[], /* i : QbeL tonal energy */ - Word16 QbeL, /* i : Q0 Q value for be_tonal */ - GainItem_fx *pk_sf_fx, /* i : toanl information for Sparse filling */ - Word16 Qss, /* i : Q0 Q value for pk_sf.nmrValue */ - Word16 *pul_res_pk /* i : Q0 pulse resolution information */ +void Gettonl_scalfact_fx( + Word32 *L_outBuf, /* i/o: QsL synthesized spectrum */ + Word16 QsL, /* i : Q0 Q value for outBuf */ + const Word32 *L_codbuf, /* i : QsL core coder */ + const Word16 fLenLow, /* i : Q0 lowband length */ + const Word16 fLenHigh, /* i : Q0 highband length */ + const Word16 harmonic_band, /* i : Q0 total number of Low frequency bands */ + const Word16 bands, /* i : Q0 total number of subbands in a frame */ + Word32 *L_band_energy, /* i : Qbe band energy of each subband */ + Word16 Qbe, /* i : Q0 Q value for band_energy */ + const Word16 *band_start, /* i : Q0 subband start indices */ + const Word16 *band_end, /* i : Q0 subband end indices */ + const Word16 p2aflags[], /* i : Q0 missing bands in the core coder */ + Word32 L_be_tonal[], /* i : QbeL tonal energy */ + Word16 QbeL, /* i : Q0 Q value for be_tonal */ + GainItem_fx *pk_sf_fx, /* i : toanl information for Sparse filling */ + Word16 Qss, /* i : Q0 Q value for pk_sf.nmrValue */ + Word16 *pul_res_pk /* i : Q0 pulse resolution information */ ) { - Word16 i, j, tmp; - Word16 sb_ton_fx[SWB_HAR_RAN1]; /* Qss */ - Word16 sb_ton_loc_fx[SWB_HAR_RAN1]; /* Q0 */ - Word32 L_est_ton_ene[NB_SWB_SUBBANDS]; /* QetEne */ - Word16 QetEne; - Word16 band_sf_fx[SWB_HAR_RAN1]; /* Qton_sf */ - Word16 pos_fx, k_fx, pos_tmp_fx; /* Q0 */ - Word16 exp_safe; - Word16 temp_fx; - Word16 Qtemp; - - Word16 band_pos_fx; - Word16 count_pos_st_fx, count_pos_end_fx; - - Word16 exp_normd, exp_normn; - - Word16 ton_sf_fx; /* Qton_sf */ - Word16 Qton_sf; - - Word16 step_fx; /* Q15 */ - Word32 L_temp; - - Word16 enrd_r_fx; /* Q15 */ - - Word32 L_band_energy_Linear[BANDS_MAX]; /* QbeL */ - Word16 temp_hi_fx, temp_lo_fx; - Word16 exp_pow; - Word16 exp_shift; - - Word16 Qbsf2[SWB_HAR_RAN1]; - - Qton_sf = sub(sub(QsL, Qss), 1); - - enrd_r_fx = 29491; - move16(); /* 0.9: 29491.2(Q15) */ - - set32_fx(L_est_ton_ene, 0x0L, NB_SWB_SUBBANDS); - set16_fx(sb_ton_loc_fx, -1, SWB_HAR_RAN1); - - /* Get the tonal information for sparse filling */ - pos_fx = 0; - move16(); - FOR(k_fx = 0; k_fx < sub(bands, harmonic_band); k_fx++) - { - FOR(j = 0; j < pul_res_pk[k_fx]; j++) - { - sb_ton_loc_fx[pos_fx] = pk_sf_fx[k_fx * 8 + j].gainIndex_fx; - move16(); - sb_ton_fx[pos_fx] = pk_sf_fx[k_fx * 8 + j].nmrValue_fx; - move16(); - pos_fx = add(pos_fx, 1); - } - } - k_fx = 0; - move16(); - pos_fx = 0; - move16(); - pos_tmp_fx = 0; - move16(); - - DO - { - band_pos_fx = add(k_fx, harmonic_band); - count_pos_st_fx = pos_fx; - move16(); - WHILE(LE_16(sb_ton_loc_fx[pos_fx], sub(band_end[band_pos_fx], fLenLow)) && sb_ton_loc_fx[pos_fx] >= 0) - { - test(); - pos_fx = add(pos_fx, 1); - } - count_pos_end_fx = pos_fx; - move16(); - - exp_safe = 2; /* move16(); */ - QetEne = add(shl(sub(Qss, exp_safe), 1), 1); - L_temp = L_add(L_est_ton_ene[k_fx], 0); - FOR(i = count_pos_st_fx; i < count_pos_end_fx; i++) - { - temp_fx = shr(sb_ton_fx[i], exp_safe); - L_temp = L_mac(L_temp, temp_fx, temp_fx); - } - L_est_ton_ene[k_fx] = L_temp; - move32(); - - IF(L_est_ton_ene[k_fx] <= 0x0L) - { - /* 1.0 */ - L_est_ton_ene[k_fx] = L_deposit_l(32767); - QetEne = 15; - } - - /*ton_sf= (float) sqrt(be_tonal[band_pos]/est_ton_ene[k]);*/ /* be_tonal: QbeL, est_ton_ene: (Qss-exp_safe)*2+1 */ - /* Div Part */ - exp_normd = norm_l(L_be_tonal[band_pos_fx]); - exp_normd = sub(exp_normd, 1); - exp_normn = norm_l(L_est_ton_ene[k_fx]); - - ton_sf_fx = 0x0; - move16(); - IF(L_be_tonal[band_pos_fx] > 0x0L) - { - ton_sf_fx = div_l(L_shl(L_be_tonal[band_pos_fx], exp_normd), extract_h(L_shl(L_est_ton_ene[k_fx], exp_normn))); /* QbeL+exp_normd - (QetEne+exp_normn-16) - 1 */ - } - - /* Sqrt Part */ - /*sqrt_32n_16_fx(L_deposit_h(ton_sf_fx), (QbeL+exp_normd)-(QetEne+exp_normn-16)-1+16, &ton_sf_fx, &Qton_sf);*/ - sqrt_32n_16_fx(L_deposit_h(ton_sf_fx), add(sub(add(QbeL, exp_normd), add(QetEne, exp_normn)), 31), &ton_sf_fx, &Qton_sf); - - FOR(i = count_pos_st_fx; i < count_pos_end_fx; i++) - { - band_sf_fx[pos_tmp_fx] = ton_sf_fx; - move16(); - Qbsf2[pos_tmp_fx] = Qton_sf; - move16(); - pos_tmp_fx = add(pos_tmp_fx, 1); - } - k_fx = add(k_fx, 1); - } WHILE(LT_16(k_fx, NB_SWB_SUBBANDS)); - - /* Gap filling for the core coder */ - /* 0.077=20185(Q18) */ - L_temp = L_mult(20185, fLenHigh); /* 18+0+1= 19 */ - exp_normn = norm_l(L_temp); - - step_fx = div_s(0x3fff, extract_h(L_shl(L_temp, exp_normn))); - step_fx = shl(step_fx, sub(exp_normn, 11)); /* 15 - (14-(19+exp_normn-16)+15) */ /* Q15 */ - - pos_tmp_fx = 0; - move16(); - tmp = sub(bands, harmonic_band); - FOR(k_fx = 0; k_fx < tmp; k_fx++) - { - band_pos_fx = add(k_fx, harmonic_band); - - IF(L_be_tonal[band_pos_fx] > 0x0L) - { - /* enrd_r *=(float)sqrt(be_tonal[band_pos]/pow(2.0f,band_energy[band_pos])); */ - /* Pow Part */ - L_temp = L_shr(L_band_energy[band_pos_fx], sub(Qbe, 16)); - temp_lo_fx = L_Extract_lc(L_temp, &temp_hi_fx); - exp_pow = sub(14, temp_hi_fx); - L_band_energy_Linear[band_pos_fx] = Pow2(14, temp_lo_fx); - move32(); /* Qexp_pow */ + Word16 i, j, tmp; + Word16 sb_ton_fx[SWB_HAR_RAN1]; /* Qss */ + Word16 sb_ton_loc_fx[SWB_HAR_RAN1]; /* Q0 */ + Word32 L_est_ton_ene[NB_SWB_SUBBANDS]; /* QetEne */ + Word16 QetEne; + Word16 band_sf_fx[SWB_HAR_RAN1]; /* Qton_sf */ + Word16 pos_fx, k_fx, pos_tmp_fx; /* Q0 */ + Word16 exp_safe; + Word16 temp_fx; + Word16 Qtemp; + + Word16 band_pos_fx; + Word16 count_pos_st_fx, count_pos_end_fx; + + Word16 exp_normd, exp_normn; + + Word16 ton_sf_fx; /* Qton_sf */ + Word16 Qton_sf; + + Word16 step_fx; /* Q15 */ + Word32 L_temp; + + Word16 enrd_r_fx; /* Q15 */ + + Word32 L_band_energy_Linear[BANDS_MAX]; /* QbeL */ + Word16 temp_hi_fx, temp_lo_fx; + Word16 exp_pow; + Word16 exp_shift; + + Word16 Qbsf2[SWB_HAR_RAN1]; + + Qton_sf = sub( sub( QsL, Qss ), 1 ); + + enrd_r_fx = 29491; + move16(); /* 0.9: 29491.2(Q15) */ + + set32_fx( L_est_ton_ene, 0x0L, NB_SWB_SUBBANDS ); + set16_fx( sb_ton_loc_fx, -1, SWB_HAR_RAN1 ); + + /* Get the tonal information for sparse filling */ + pos_fx = 0; + move16(); + FOR( k_fx = 0; k_fx < sub( bands, harmonic_band ); k_fx++ ) + { + FOR( j = 0; j < pul_res_pk[k_fx]; j++ ) + { + sb_ton_loc_fx[pos_fx] = pk_sf_fx[k_fx * 8 + j].gainIndex_fx; + move16(); + sb_ton_fx[pos_fx] = pk_sf_fx[k_fx * 8 + j].nmrValue_fx; + move16(); + pos_fx = add( pos_fx, 1 ); + } + } + k_fx = 0; + move16(); + pos_fx = 0; + move16(); + pos_tmp_fx = 0; + move16(); + + DO + { + band_pos_fx = add( k_fx, harmonic_band ); + count_pos_st_fx = pos_fx; + move16(); + WHILE( LE_16( sb_ton_loc_fx[pos_fx], sub( band_end[band_pos_fx], fLenLow ) ) && sb_ton_loc_fx[pos_fx] >= 0 ) + { + test(); + pos_fx = add( pos_fx, 1 ); + } + count_pos_end_fx = pos_fx; + move16(); + + exp_safe = 2; /* move16(); */ + QetEne = add( shl( sub( Qss, exp_safe ), 1 ), 1 ); + L_temp = L_add( L_est_ton_ene[k_fx], 0 ); + FOR( i = count_pos_st_fx; i < count_pos_end_fx; i++ ) + { + temp_fx = shr( sb_ton_fx[i], exp_safe ); + L_temp = L_mac( L_temp, temp_fx, temp_fx ); + } + L_est_ton_ene[k_fx] = L_temp; + move32(); + + IF( L_est_ton_ene[k_fx] <= 0x0L ) + { + /* 1.0 */ + L_est_ton_ene[k_fx] = L_deposit_l( 32767 ); + QetEne = 15; + } + + /*ton_sf= (float) sqrt(be_tonal[band_pos]/est_ton_ene[k]);*/ /* be_tonal: QbeL, est_ton_ene: (Qss-exp_safe)*2+1 */ + /* Div Part */ + exp_normd = norm_l( L_be_tonal[band_pos_fx] ); + exp_normd = sub( exp_normd, 1 ); + exp_normn = norm_l( L_est_ton_ene[k_fx] ); + + ton_sf_fx = 0x0; + move16(); + IF( L_be_tonal[band_pos_fx] > 0x0L ) + { + ton_sf_fx = div_l( L_shl( L_be_tonal[band_pos_fx], exp_normd ), extract_h( L_shl( L_est_ton_ene[k_fx], exp_normn ) ) ); /* QbeL+exp_normd - (QetEne+exp_normn-16) - 1 */ + } + + /* Sqrt Part */ + /*sqrt_32n_16_fx(L_deposit_h(ton_sf_fx), (QbeL+exp_normd)-(QetEne+exp_normn-16)-1+16, &ton_sf_fx, &Qton_sf);*/ + sqrt_32n_16_fx( L_deposit_h( ton_sf_fx ), add( sub( add( QbeL, exp_normd ), add( QetEne, exp_normn ) ), 31 ), &ton_sf_fx, &Qton_sf ); + + FOR( i = count_pos_st_fx; i < count_pos_end_fx; i++ ) + { + band_sf_fx[pos_tmp_fx] = ton_sf_fx; + move16(); + Qbsf2[pos_tmp_fx] = Qton_sf; + move16(); + pos_tmp_fx = add( pos_tmp_fx, 1 ); + } + k_fx = add( k_fx, 1 ); + } + WHILE( LT_16( k_fx, NB_SWB_SUBBANDS ) ); + + /* Gap filling for the core coder */ + /* 0.077=20185(Q18) */ + L_temp = L_mult( 20185, fLenHigh ); /* 18+0+1= 19 */ + exp_normn = norm_l( L_temp ); + + step_fx = div_s( 0x3fff, extract_h( L_shl( L_temp, exp_normn ) ) ); + step_fx = shl( step_fx, sub( exp_normn, 11 ) ); /* 15 - (14-(19+exp_normn-16)+15) */ /* Q15 */ + + pos_tmp_fx = 0; + move16(); + tmp = sub( bands, harmonic_band ); + FOR( k_fx = 0; k_fx < tmp; k_fx++ ) + { + band_pos_fx = add( k_fx, harmonic_band ); + + IF( L_be_tonal[band_pos_fx] > 0x0L ) + { + /* enrd_r *=(float)sqrt(be_tonal[band_pos]/pow(2.0f,band_energy[band_pos])); */ + /* Pow Part */ + L_temp = L_shr( L_band_energy[band_pos_fx], sub( Qbe, 16 ) ); + temp_lo_fx = L_Extract_lc( L_temp, &temp_hi_fx ); + exp_pow = sub( 14, temp_hi_fx ); + L_band_energy_Linear[band_pos_fx] = Pow2( 14, temp_lo_fx ); + move32(); /* Qexp_pow */ #ifdef BASOP_NOGLOB L_band_energy_Linear[band_pos_fx] = L_shl_sat( L_band_energy_Linear[band_pos_fx], sub( QbeL, exp_pow ) ); #else - L_band_energy_Linear[band_pos_fx] = L_shl(L_band_energy_Linear[band_pos_fx], sub(QbeL, exp_pow)); + L_band_energy_Linear[band_pos_fx] = L_shl( L_band_energy_Linear[band_pos_fx], sub( QbeL, exp_pow ) ); #endif - /* Div Part */ - exp_normd = norm_l(L_be_tonal[band_pos_fx]); - exp_normd = sub(exp_normd, 1); - exp_normn = norm_l(L_band_energy_Linear[band_pos_fx]); - temp_fx = div_l(L_shl(L_be_tonal[band_pos_fx], exp_normd), extract_h(L_shl(L_band_energy_Linear[band_pos_fx], exp_normn))); /* QbeL+exp_normd-(QbeL+exp_normn-16)-1 */ - sqrt_32n_16_fx(L_deposit_h(temp_fx), add(sub(exp_normd, exp_normn), 31), &temp_fx, &Qtemp); + /* Div Part */ + exp_normd = norm_l( L_be_tonal[band_pos_fx] ); + exp_normd = sub( exp_normd, 1 ); + exp_normn = norm_l( L_band_energy_Linear[band_pos_fx] ); + temp_fx = div_l( L_shl( L_be_tonal[band_pos_fx], exp_normd ), extract_h( L_shl( L_band_energy_Linear[band_pos_fx], exp_normn ) ) ); /* QbeL+exp_normd-(QbeL+exp_normn-16)-1 */ + sqrt_32n_16_fx( L_deposit_h( temp_fx ), add( sub( exp_normd, exp_normn ), 31 ), &temp_fx, &Qtemp ); #ifdef BASOP_NOGLOB enrd_r_fx = extract_h( L_shl_sat( L_mult( enrd_r_fx, temp_fx ), sub( 15, Qtemp ) ) ); #else - enrd_r_fx = extract_h(L_shl(L_mult(enrd_r_fx, temp_fx), sub(15, Qtemp))); + enrd_r_fx = extract_h( L_shl( L_mult( enrd_r_fx, temp_fx ), sub( 15, Qtemp ) ) ); #endif - enrd_r_fx = sub(enrd_r_fx, step_fx); - } - ELSE - { - enrd_r_fx = 0x0; - move16(); - } - - IF(EQ_16(p2aflags[band_pos_fx], 1)) - { - FOR(i = band_start[band_pos_fx]; i <= band_end[band_pos_fx]; i++) - { - L_outBuf[i - fLenLow] = L_codbuf[i]; - move32(); - } - } - ELSE - { - pos_fx = 0; - move16(); - pos_fx = add(pos_fx, pos_tmp_fx); - exp_shift = sub(sub(QsL, Qss), 1); - FOR(j = 0; j < pul_res_pk[k_fx]; j++) - { - /*outBuf[pk_sf[k*8+j].gainIndex] = pk_sf[k*8+j].nmrValue*band_sf[pos]*enrd_r;*/ - /* outBuf:QsL , pk_sf.nmrValue:Qss, band_sf:Qbsf2(Qton_sf), enrd_r:Q15 */ - L_outBuf[pk_sf_fx[k_fx * 8 + j].gainIndex_fx] = L_shl(Mult_32_16(L_mult(band_sf_fx[pos_fx], enrd_r_fx), pk_sf_fx[k_fx * 8 + j].nmrValue_fx), sub(exp_shift ,Qbsf2[pos_fx])); - move32(); /* QsL - (Qbsf2[pos_fx]+Qss+16-15) */ - - pos_fx = add(pos_fx, 1); - } - } - pos_tmp_fx = add(pos_tmp_fx, pul_res_pk[k_fx]); - - } - - return; + enrd_r_fx = sub( enrd_r_fx, step_fx ); + } + ELSE + { + enrd_r_fx = 0x0; + move16(); + } + + IF( EQ_16( p2aflags[band_pos_fx], 1 ) ) + { + FOR( i = band_start[band_pos_fx]; i <= band_end[band_pos_fx]; i++ ) + { + L_outBuf[i - fLenLow] = L_codbuf[i]; + move32(); + } + } + ELSE + { + pos_fx = 0; + move16(); + pos_fx = add( pos_fx, pos_tmp_fx ); + exp_shift = sub( sub( QsL, Qss ), 1 ); + FOR( j = 0; j < pul_res_pk[k_fx]; j++ ) + { + /*outBuf[pk_sf[k*8+j].gainIndex] = pk_sf[k*8+j].nmrValue*band_sf[pos]*enrd_r;*/ + /* outBuf:QsL , pk_sf.nmrValue:Qss, band_sf:Qbsf2(Qton_sf), enrd_r:Q15 */ + L_outBuf[pk_sf_fx[k_fx * 8 + j].gainIndex_fx] = L_shl( Mult_32_16( L_mult( band_sf_fx[pos_fx], enrd_r_fx ), pk_sf_fx[k_fx * 8 + j].nmrValue_fx ), sub( exp_shift, Qbsf2[pos_fx] ) ); + move32(); /* QsL - (Qbsf2[pos_fx]+Qss+16-15) */ + + pos_fx = add( pos_fx, 1 ); + } + } + pos_tmp_fx = add( pos_tmp_fx, pul_res_pk[k_fx] ); + } + + return; } - /*-------------------------------------------------------------------* * sqrt_32n_16_fx() * * Routine for Sqrt *-------------------------------------------------------------------*/ void sqrt_32n_16_fx( - Word32 L_in, /* i : input vector (Word32) */ - Word16 Qin, /* i : Q value for L_in */ - Word16 *out_fx, /* o : sqrt input vector (Word16) */ - Word16 *Qout /* o : Q value for out_fx */ + Word32 L_in, /* i : input vector (Word32) */ + Word16 Qin, /* i : Q value for L_in */ + Word16 *out_fx, /* o : sqrt input vector (Word16) */ + Word16 *Qout /* o : Q value for out_fx */ ) { - Word16 exp_norm; - Word32 L_in_t; - Word16 Qin_t; - - /* Input Normalization */ - exp_norm = norm_l(L_in); - L_in_t = L_shl(L_in, exp_norm); - Qin_t = add(Qin, exp_norm); - - /* SQRT part */ - IF(s_and(Qin_t, 1) == 0) - { - L_in_t = Sqrt_l(L_shr(L_in_t, 1), &exp_norm); - L_in_t = L_shr(L_in_t, exp_norm); - *Qout = sub(shr(Qin_t, 1), 1); - } - ELSE - { - L_in_t = Sqrt_l(L_in_t, &exp_norm); - L_in_t = L_shr(L_in_t, exp_norm); - *Qout = shr(Qin_t, 1); - } - *out_fx = round_fx(L_in_t); + Word16 exp_norm; + Word32 L_in_t; + Word16 Qin_t; + + /* Input Normalization */ + exp_norm = norm_l( L_in ); + L_in_t = L_shl( L_in, exp_norm ); + Qin_t = add( Qin, exp_norm ); + + /* SQRT part */ + IF( s_and( Qin_t, 1 ) == 0 ) + { + L_in_t = Sqrt_l( L_shr( L_in_t, 1 ), &exp_norm ); + L_in_t = L_shr( L_in_t, exp_norm ); + *Qout = sub( shr( Qin_t, 1 ), 1 ); + } + ELSE + { + L_in_t = Sqrt_l( L_in_t, &exp_norm ); + L_in_t = L_shr( L_in_t, exp_norm ); + *Qout = shr( Qin_t, 1 ); + } + *out_fx = round_fx( L_in_t ); } /*-------------------------------------------------------------------* @@ -2691,447 +2700,447 @@ void sqrt_32n_16_fx( * Routine for normilization and convert Word32 to Word16 *-------------------------------------------------------------------*/ void norm_vec_32_16_scale_fx( - Word32 *L_vec_in, /* i : input vector */ - Word16 Qin, /* i : Q value for input vector */ - Word16 length_fx, /* i :vector size */ - Word16 *vec_out_fx, /* o : output vectror */ - Word16 *Qout, /* o : Q value for output vectro */ - Word16 exp_safe /* i : suppress left shift: for prevend overflow on sum */ + Word32 *L_vec_in, /* i : input vector */ + Word16 Qin, /* i : Q value for input vector */ + Word16 length_fx, /* i :vector size */ + Word16 *vec_out_fx, /* o : output vectror */ + Word16 *Qout, /* o : Q value for output vectro */ + Word16 exp_safe /* i : suppress left shift: for prevend overflow on sum */ ) { - Word16 i; - Word32 L_temp; - Word16 exp_norm, exp_shift; - - L_temp = L_deposit_l(0); - FOR(i = 0; i < length_fx; i++) - { - L_temp = L_or(L_temp, L_abs(L_vec_in[i])); - } - exp_norm = norm_l(L_temp); - - exp_shift = sub(exp_norm, exp_safe); - *Qout = sub(add(Qin, exp_shift), 16); - FOR(i = 0; i < length_fx; i++) - { - vec_out_fx[i] = round_fx(L_shl(L_vec_in[i], exp_shift)); - } + Word16 i; + Word32 L_temp; + Word16 exp_norm, exp_shift; + + L_temp = L_deposit_l( 0 ); + FOR( i = 0; i < length_fx; i++ ) + { + L_temp = L_or( L_temp, L_abs( L_vec_in[i] ) ); + } + exp_norm = norm_l( L_temp ); + + exp_shift = sub( exp_norm, exp_safe ); + *Qout = sub( add( Qin, exp_shift ), 16 ); + FOR( i = 0; i < length_fx; i++ ) + { + vec_out_fx[i] = round_fx( L_shl( L_vec_in[i], exp_shift ) ); + } } void get_sigma_fx_har( - const Word32 L_x_abs[], /* i: Qi absolute input */ - const Word16 Qi, /* i: Q0 Q value of x_abs */ - const Word16 avg_fx, /* i: Qavg average of x_abs */ - const Word16 Qavg, /* i: Q0 Q value of avg */ - const Word16 length_fx, /* i: Q0 length */ - Word16 *sigma_fx, /* o: Qsigma sigma */ - Word16 *Qsigma /* o: Q0 Q value of sigma */ + const Word32 L_x_abs[], /* i: Qi absolute input */ + const Word16 Qi, /* i: Q0 Q value of x_abs */ + const Word16 avg_fx, /* i: Qavg average of x_abs */ + const Word16 Qavg, /* i: Q0 Q value of avg */ + const Word16 length_fx, /* i: Q0 length */ + Word16 *sigma_fx, /* o: Qsigma sigma */ + Word16 *Qsigma /* o: Q0 Q value of sigma */ ) { - Word16 i; - Word32 L_d; - Word16 d_fx; - - Word16 length1_fx; - Word16 exp_normd; - Word16 exp_normn; - Word16 exp_shift; - - Word16 exp_norm; - - Word32 L_temp; - - Word16 temp_fx; - - Word32 L_tmp; - Word32 L_x_abs_sh[L_FRAME32k]; - Word16 Qd; - - Word16 exp_safe; - - exp_safe = 4; - move16(); /* max 103 < 2^7 -> 4+4=8 */ - - L_tmp = L_deposit_l(0); - FOR(i = 0; i < length_fx; i++) - { - L_tmp = L_or(L_tmp, L_x_abs[i]); - } - exp_norm = norm_l(L_tmp); - exp_norm = sub(exp_norm, exp_safe); - FOR(i = 0; i < length_fx; i++) - { - L_x_abs_sh[i] = L_shl(L_x_abs[i], exp_norm); - } - - L_d = L_deposit_l(0); - FOR(i = 0; i < length_fx; i++) - { - temp_fx = extract_h(L_x_abs_sh[i]); - L_d = L_mac(L_d, temp_fx, temp_fx); /* (Qi+exp_norm-16)*2+1 */ - } - Qd = add(shl(sub(add(Qi, exp_norm), 16), 1), 1); - IF(L_d == 0x0L) - { - *sigma_fx = 0; - move16(); - *Qsigma = 15; - move16(); - return; - } - - /* d /= (length-1); */ - length1_fx = sub(length_fx, 1); - - /* d /= (length-1); */ - exp_normn = norm_l(L_d); - exp_normn = sub(exp_normn, 1); - exp_normd = norm_s(length1_fx); - - exp_shift = sub(sub(exp_normn, exp_normd), 1); - d_fx = div_l(L_shl(L_d, exp_normn), shl(length1_fx, exp_normd)); /* Qabs*2+1+exp_normn - exp_normd - 1 */ - L_d = L_shr(L_deposit_l(d_fx), exp_shift); /* Qabs*2+1 + 16 */ - /* Qd = ((Qd+exp_normn) - exp_normd-exp_shift -1); */ - Qd = sub(sub(add(Qd, exp_normn), add(exp_normd, exp_shift)), 1); - - /* d -= avg*avg; */ - IF(avg_fx != 0x0) - { - L_tmp = L_mult(avg_fx, avg_fx); /* Qavg*2+1 */ - L_tmp = L_shr(L_tmp, sub(add(shl(Qavg, 1), 1), Qd)); - L_d = L_sub(L_d, L_tmp); - } - - exp_norm = norm_l(L_d); - L_d = L_shl(L_d, exp_norm); - Qd = add(Qd, exp_norm); - - /* sigma = (float)sqrt(d); */ - IF(s_and(Qd, 1) == 0)/* Qd % 2 == 0 */ - { - L_temp = Sqrt_l(L_shr(L_d, 1), &exp_norm); - L_temp = L_shr(L_temp, exp_norm); - *Qsigma = sub(shr(Qd, 1), 1); - *sigma_fx = round_fx(L_temp); - } - ELSE - { - L_temp = Sqrt_l(L_d, &exp_norm); - L_temp = L_shr(L_temp, exp_norm); - *Qsigma = shr(Qd, 1); - *sigma_fx = round_fx(L_temp); - } - - return; + Word16 i; + Word32 L_d; + Word16 d_fx; + + Word16 length1_fx; + Word16 exp_normd; + Word16 exp_normn; + Word16 exp_shift; + + Word16 exp_norm; + + Word32 L_temp; + + Word16 temp_fx; + + Word32 L_tmp; + Word32 L_x_abs_sh[L_FRAME32k]; + Word16 Qd; + + Word16 exp_safe; + + exp_safe = 4; + move16(); /* max 103 < 2^7 -> 4+4=8 */ + + L_tmp = L_deposit_l( 0 ); + FOR( i = 0; i < length_fx; i++ ) + { + L_tmp = L_or( L_tmp, L_x_abs[i] ); + } + exp_norm = norm_l( L_tmp ); + exp_norm = sub( exp_norm, exp_safe ); + FOR( i = 0; i < length_fx; i++ ) + { + L_x_abs_sh[i] = L_shl( L_x_abs[i], exp_norm ); + } + + L_d = L_deposit_l( 0 ); + FOR( i = 0; i < length_fx; i++ ) + { + temp_fx = extract_h( L_x_abs_sh[i] ); + L_d = L_mac( L_d, temp_fx, temp_fx ); /* (Qi+exp_norm-16)*2+1 */ + } + Qd = add( shl( sub( add( Qi, exp_norm ), 16 ), 1 ), 1 ); + IF( L_d == 0x0L ) + { + *sigma_fx = 0; + move16(); + *Qsigma = 15; + move16(); + return; + } + + /* d /= (length-1); */ + length1_fx = sub( length_fx, 1 ); + + /* d /= (length-1); */ + exp_normn = norm_l( L_d ); + exp_normn = sub( exp_normn, 1 ); + exp_normd = norm_s( length1_fx ); + + exp_shift = sub( sub( exp_normn, exp_normd ), 1 ); + d_fx = div_l( L_shl( L_d, exp_normn ), shl( length1_fx, exp_normd ) ); /* Qabs*2+1+exp_normn - exp_normd - 1 */ + L_d = L_shr( L_deposit_l( d_fx ), exp_shift ); /* Qabs*2+1 + 16 */ + /* Qd = ((Qd+exp_normn) - exp_normd-exp_shift -1); */ + Qd = sub( sub( add( Qd, exp_normn ), add( exp_normd, exp_shift ) ), 1 ); + + /* d -= avg*avg; */ + IF( avg_fx != 0x0 ) + { + L_tmp = L_mult( avg_fx, avg_fx ); /* Qavg*2+1 */ + L_tmp = L_shr( L_tmp, sub( add( shl( Qavg, 1 ), 1 ), Qd ) ); + L_d = L_sub( L_d, L_tmp ); + } + + exp_norm = norm_l( L_d ); + L_d = L_shl( L_d, exp_norm ); + Qd = add( Qd, exp_norm ); + + /* sigma = (float)sqrt(d); */ + IF( s_and( Qd, 1 ) == 0 ) /* Qd % 2 == 0 */ + { + L_temp = Sqrt_l( L_shr( L_d, 1 ), &exp_norm ); + L_temp = L_shr( L_temp, exp_norm ); + *Qsigma = sub( shr( Qd, 1 ), 1 ); + *sigma_fx = round_fx( L_temp ); + } + ELSE + { + L_temp = Sqrt_l( L_d, &exp_norm ); + L_temp = L_shr( L_temp, exp_norm ); + *Qsigma = shr( Qd, 1 ); + *sigma_fx = round_fx( L_temp ); + } + + return; } void FindNBiggest2_simple_fx_har( - const Word32 *L_inBuf, /* i : input buffer (searched) */ - const Word16 Qabs_in, /* i : Q value of input buffer */ - GainItem_fx *pk_sf_fx, /* o : N biggest components found */ - const Word16 nIdx_fx, /* i : search length */ - Word16 *n_fx, /* i : number of components searched (N biggest) */ - Word16 n_nbiggestsearch /* i : */ + const Word32 *L_inBuf, /* i : input buffer (searched) */ + const Word16 Qabs_in, /* i : Q value of input buffer */ + GainItem_fx *pk_sf_fx, /* o : N biggest components found */ + const Word16 nIdx_fx, /* i : search length */ + Word16 *n_fx, /* i : number of components searched (N biggest) */ + Word16 n_nbiggestsearch /* i : */ ) { - Word16 j; - Word32 L_avg_in; - Word32 L_abs_in[400]; - Word32 L_abs_in_sft[400]; - Word16 avg_in_fx; - Word32 L_max_in; - Word16 Qavg_in; - - Word16 exp_normd; - Word16 exp_normn; - - Word16 temp_fx; - - Word16 sigma_fx; - Word16 Qsigma; - - Word16 peak_cnt_fx; - Word32 L_thr; - Word32 L_temp; - - L_max_in = L_deposit_l(0); - L_avg_in = L_deposit_l(0); - - FOR(j = 0; j < nIdx_fx; j++) - { - L_abs_in[j] = L_abs(L_inBuf[j]); /* Qabs_in */ - L_abs_in_sft[j] = L_shr(L_abs_in[j], 8); /* 8 is safe shift */ - - if (LT_32(L_max_in, L_abs_in_sft[j])) - { - L_max_in = L_abs_in_sft[j]; - move32(); - } - - L_avg_in = L_add(L_avg_in, L_abs_in_sft[j]); - } - - /*avg_in /= (float)nIdx;*/ - avg_in_fx = 0; - move16(); - Qavg_in = 15; - move16(); - IF(L_avg_in != 0) - { - exp_normn = norm_l(L_avg_in); - exp_normn = sub(exp_normn, 1); - L_avg_in = L_shl(L_avg_in, exp_normn); - exp_normd = norm_s(nIdx_fx); - temp_fx = shl(nIdx_fx, exp_normd); - avg_in_fx = div_l(L_avg_in, temp_fx); - Qavg_in = sub(add(sub(Qabs_in, 8), exp_normn), add(exp_normd, 1)); - } - - peak_cnt_fx = 0; - move16(); - IF(LE_32(L_max_in, 0x1)) - { - FOR(j = 0; j < n_nbiggestsearch; j++) - { - pk_sf_fx[peak_cnt_fx].nmrValue_fx = 0x0; - move16(); - pk_sf_fx[peak_cnt_fx].gainIndex_fx = j; - move16(); - peak_cnt_fx = add(peak_cnt_fx, 1); - } - } - - get_sigma_fx_har(L_abs_in, Qabs_in, avg_in_fx, Qavg_in, nIdx_fx, &sigma_fx, &Qsigma); - - temp_fx = mult_r(sigma_fx, 18841); /* 18841 = 1.15(Q14) Qsigma + Q14 + 1 */ - L_thr = L_add(extract_l(avg_in_fx), L_shr(extract_l(temp_fx), sub(sub(Qsigma, 1), Qavg_in))); - L_thr = L_shr(L_thr, sub(Qavg_in, Qabs_in)); - - IF(LT_16(peak_cnt_fx, n_nbiggestsearch)) - { - FOR(j = 0; j < nIdx_fx; j++) - { - IF(GT_32(L_abs_in[j], L_thr)) - { - pk_sf_fx[peak_cnt_fx].nmrValue_fx = round_fx(L_abs_in[j]); /* Qabs_in-16 */ - pk_sf_fx[peak_cnt_fx].gainIndex_fx = j; - move16(); - L_abs_in[j] = L_deposit_l(0); - peak_cnt_fx = add(peak_cnt_fx, 1); - move16(); - } - - IF(EQ_16(peak_cnt_fx, n_nbiggestsearch)) - { - BREAK; - } - } - } - - /* thr *= (0.3f / n_nbiggestsearch) * peak_cnt + 0.7f; */ - /* 0.3=19661(Q16) */ - temp_fx = div_s_ss(19661, n_nbiggestsearch); - L_temp = L_mult(temp_fx, peak_cnt_fx); /* 16+0+1 */ - temp_fx = add(round_fx(L_shl(L_temp, 14)), 22938); /* shift: 17+14-16 -> 15 */ /* 0.7(22937.6:Q15)*/ - L_thr = Mult_32_16(L_thr, temp_fx); - - IF(LT_16(peak_cnt_fx, n_nbiggestsearch)) - { - FOR(j = 0; j < nIdx_fx; j++) - { - IF(GT_32(L_abs_in[j], L_thr)) - { - pk_sf_fx[peak_cnt_fx].nmrValue_fx = round_fx(L_abs_in[j]); /* Qabs_in-16 */ - pk_sf_fx[peak_cnt_fx].gainIndex_fx = j; - move16(); - L_abs_in[j] = L_deposit_l(0); - peak_cnt_fx = add(peak_cnt_fx, 1); - move16(); - } - - IF(EQ_16(peak_cnt_fx, n_nbiggestsearch)) - { - BREAK; - } - } - } - - /* thr *= (0.6f / n_nbiggestsearch) * peak_cnt + 0.3f; */ - /* 0.6=19661(Q15) */ - temp_fx = div_s_ss(19661, n_nbiggestsearch); - L_temp = L_mult(temp_fx, peak_cnt_fx); /* 15+0+1 */ - temp_fx = add(round_fx(L_shl(L_temp, 15)), 9830); /* shift: 16+15-16 -> 15 */ /* 0.3(9830.4:Q15)*/ - - L_thr = Mult_32_16(L_thr, temp_fx); - IF(LT_16(peak_cnt_fx, n_nbiggestsearch)) - { - FOR(j = 0; j < nIdx_fx; j++) - { - IF(GT_32(L_abs_in[j], L_thr)) - { - pk_sf_fx[peak_cnt_fx].nmrValue_fx = round_fx(L_abs_in[j]); /* Qabs_in-16 */ - pk_sf_fx[peak_cnt_fx].gainIndex_fx = j; - move16(); - L_abs_in[j] = L_deposit_l(0); - peak_cnt_fx = add(peak_cnt_fx, 1); - move16(); - } - - IF(EQ_16(peak_cnt_fx, n_nbiggestsearch)) - { - BREAK; - } - } - } - - *n_fx = peak_cnt_fx; - move16(); + Word16 j; + Word32 L_avg_in; + Word32 L_abs_in[400]; + Word32 L_abs_in_sft[400]; + Word16 avg_in_fx; + Word32 L_max_in; + Word16 Qavg_in; + + Word16 exp_normd; + Word16 exp_normn; + + Word16 temp_fx; + + Word16 sigma_fx; + Word16 Qsigma; + + Word16 peak_cnt_fx; + Word32 L_thr; + Word32 L_temp; + + L_max_in = L_deposit_l( 0 ); + L_avg_in = L_deposit_l( 0 ); + + FOR( j = 0; j < nIdx_fx; j++ ) + { + L_abs_in[j] = L_abs( L_inBuf[j] ); /* Qabs_in */ + L_abs_in_sft[j] = L_shr( L_abs_in[j], 8 ); /* 8 is safe shift */ + + if ( LT_32( L_max_in, L_abs_in_sft[j] ) ) + { + L_max_in = L_abs_in_sft[j]; + move32(); + } + + L_avg_in = L_add( L_avg_in, L_abs_in_sft[j] ); + } + + /*avg_in /= (float)nIdx;*/ + avg_in_fx = 0; + move16(); + Qavg_in = 15; + move16(); + IF( L_avg_in != 0 ) + { + exp_normn = norm_l( L_avg_in ); + exp_normn = sub( exp_normn, 1 ); + L_avg_in = L_shl( L_avg_in, exp_normn ); + exp_normd = norm_s( nIdx_fx ); + temp_fx = shl( nIdx_fx, exp_normd ); + avg_in_fx = div_l( L_avg_in, temp_fx ); + Qavg_in = sub( add( sub( Qabs_in, 8 ), exp_normn ), add( exp_normd, 1 ) ); + } + + peak_cnt_fx = 0; + move16(); + IF( LE_32( L_max_in, 0x1 ) ) + { + FOR( j = 0; j < n_nbiggestsearch; j++ ) + { + pk_sf_fx[peak_cnt_fx].nmrValue_fx = 0x0; + move16(); + pk_sf_fx[peak_cnt_fx].gainIndex_fx = j; + move16(); + peak_cnt_fx = add( peak_cnt_fx, 1 ); + } + } + + get_sigma_fx_har( L_abs_in, Qabs_in, avg_in_fx, Qavg_in, nIdx_fx, &sigma_fx, &Qsigma ); + + temp_fx = mult_r( sigma_fx, 18841 ); /* 18841 = 1.15(Q14) Qsigma + Q14 + 1 */ + L_thr = L_add( extract_l( avg_in_fx ), L_shr( extract_l( temp_fx ), sub( sub( Qsigma, 1 ), Qavg_in ) ) ); + L_thr = L_shr( L_thr, sub( Qavg_in, Qabs_in ) ); + + IF( LT_16( peak_cnt_fx, n_nbiggestsearch ) ) + { + FOR( j = 0; j < nIdx_fx; j++ ) + { + IF( GT_32( L_abs_in[j], L_thr ) ) + { + pk_sf_fx[peak_cnt_fx].nmrValue_fx = round_fx( L_abs_in[j] ); /* Qabs_in-16 */ + pk_sf_fx[peak_cnt_fx].gainIndex_fx = j; + move16(); + L_abs_in[j] = L_deposit_l( 0 ); + peak_cnt_fx = add( peak_cnt_fx, 1 ); + move16(); + } + + IF( EQ_16( peak_cnt_fx, n_nbiggestsearch ) ) + { + BREAK; + } + } + } + + /* thr *= (0.3f / n_nbiggestsearch) * peak_cnt + 0.7f; */ + /* 0.3=19661(Q16) */ + temp_fx = div_s_ss( 19661, n_nbiggestsearch ); + L_temp = L_mult( temp_fx, peak_cnt_fx ); /* 16+0+1 */ + temp_fx = add( round_fx( L_shl( L_temp, 14 ) ), 22938 ); /* shift: 17+14-16 -> 15 */ /* 0.7(22937.6:Q15)*/ + L_thr = Mult_32_16( L_thr, temp_fx ); + + IF( LT_16( peak_cnt_fx, n_nbiggestsearch ) ) + { + FOR( j = 0; j < nIdx_fx; j++ ) + { + IF( GT_32( L_abs_in[j], L_thr ) ) + { + pk_sf_fx[peak_cnt_fx].nmrValue_fx = round_fx( L_abs_in[j] ); /* Qabs_in-16 */ + pk_sf_fx[peak_cnt_fx].gainIndex_fx = j; + move16(); + L_abs_in[j] = L_deposit_l( 0 ); + peak_cnt_fx = add( peak_cnt_fx, 1 ); + move16(); + } + + IF( EQ_16( peak_cnt_fx, n_nbiggestsearch ) ) + { + BREAK; + } + } + } + + /* thr *= (0.6f / n_nbiggestsearch) * peak_cnt + 0.3f; */ + /* 0.6=19661(Q15) */ + temp_fx = div_s_ss( 19661, n_nbiggestsearch ); + L_temp = L_mult( temp_fx, peak_cnt_fx ); /* 15+0+1 */ + temp_fx = add( round_fx( L_shl( L_temp, 15 ) ), 9830 ); /* shift: 16+15-16 -> 15 */ /* 0.3(9830.4:Q15)*/ + + L_thr = Mult_32_16( L_thr, temp_fx ); + IF( LT_16( peak_cnt_fx, n_nbiggestsearch ) ) + { + FOR( j = 0; j < nIdx_fx; j++ ) + { + IF( GT_32( L_abs_in[j], L_thr ) ) + { + pk_sf_fx[peak_cnt_fx].nmrValue_fx = round_fx( L_abs_in[j] ); /* Qabs_in-16 */ + pk_sf_fx[peak_cnt_fx].gainIndex_fx = j; + move16(); + L_abs_in[j] = L_deposit_l( 0 ); + peak_cnt_fx = add( peak_cnt_fx, 1 ); + move16(); + } + + IF( EQ_16( peak_cnt_fx, n_nbiggestsearch ) ) + { + BREAK; + } + } + } + + *n_fx = peak_cnt_fx; + move16(); } /*--------------------------------------------------------------------------* * spectrumsmooth_noiseton() * Spectrum normalization for the the core coder *--------------------------------------------------------------------------*/ -Word16 spectrumsmooth_noiseton_fx( /* o : Qss ss_min */ - Word32 L_spectra[], /* i : Qs core coder */ - /*Word16 Qs,*/ /* i : Q0 Q value for spectra, spectra_ni */ - const Word32 L_spectra_ni[], /* i : Qs core coder with sparse filling */ - Word16 sspectra_fx[], /* o : Qss Smoothed tonal information from core coder */ - Word16 sspectra_diff_fx[], /* o : Qss non tonal infomration for gap filling */ - Word16 sspectra_ni_fx[], /* o : Qss smoothed core coder */ - Word16 *Qss, /* o : Q0 Q value for sspectra* */ - const Word16 fLenLow_fx, /* i : Q0 low frequency boundaries */ - Word16 *ni_seed_fx /* io : Q0 random seed */ +Word16 spectrumsmooth_noiseton_fx( /* o : Qss ss_min */ + Word32 L_spectra[], /* i : Qs core coder */ + /*Word16 Qs,*/ /* i : Q0 Q value for spectra, spectra_ni */ + const Word32 L_spectra_ni[], /* i : Qs core coder with sparse filling */ + Word16 sspectra_fx[], /* o : Qss Smoothed tonal information from core coder */ + Word16 sspectra_diff_fx[], /* o : Qss non tonal infomration for gap filling */ + Word16 sspectra_ni_fx[], /* o : Qss smoothed core coder */ + Word16 *Qss, /* o : Q0 Q value for sspectra* */ + const Word16 fLenLow_fx, /* i : Q0 low frequency boundaries */ + Word16 *ni_seed_fx /* io : Q0 random seed */ ) { - Word16 i; - Word32 L_spectra_diff[L_FRAME32k]; - Word16 ni_ratio_fx; /* Q15 */ - Word16 ss_min_fx; /* Q10 */ - Word16 cut_sig_th_fx; /* Q10 */ - Word16 cut_ni_th_fx; /* Q10 */ - Word16 pcnt_fx, sign_fx; - Word16 exp_normn, exp_normd; - - Word16 ratio_fx; - Word32 L_temp; - Word32 L_spectra_rm[L_FRAME32k]; - Word32 L_cut_input = 410; - Word16 rand_a_fx[L_FRAME32k]; - - - /* pre-prepare random array for float-fix interoperability */ - FOR(i = 0; i < fLenLow_fx; i++) - { - rand_a_fx[i] = Random(ni_seed_fx); - } - - - /*Get the pulse resolution for the core coder*/ - pcnt_fx = 0; - move16(); - FOR(i = 0; i < fLenLow_fx; i++) - { - if (L_spectra[i] != 0x0L) - { - pcnt_fx = add(pcnt_fx, 1); - } - } - - /*ni_ratio = 4.0f*(pcnt)/(fLenLow+0.0f);*/ - exp_normn = norm_s(pcnt_fx); - exp_normn = sub(exp_normn, 1); - exp_normd = norm_s(fLenLow_fx); - - ni_ratio_fx = div_s(shl(pcnt_fx, exp_normn), shl(fLenLow_fx, exp_normd)); /* exp_normn - exp_normd + 15 - 2 */ - - ni_ratio_fx = shl(ni_ratio_fx, add(sub(exp_normd, exp_normn), 2)); /* 15 - (exp_normn-exp_normd+15-2) */ - - /*ni_ratio = min(0.9f, ni_ratio);*/ - ni_ratio_fx = s_min(29491, ni_ratio_fx); /* 0.9: 29491(Q15) */ - - move16(); - - ss_min_fx = mult_r(ni_ratio_fx, 10240); /* Q15+Q10-15 = Q10 */ /* 10.0: 10240(Q10) */ - cut_sig_th_fx = shr(ss_min_fx, 2); /* 1/4 */ - cut_sig_th_fx = s_max(973, cut_sig_th_fx); /* 0.95: 972.8(Q10) */ - - /*core coder normalization for gap filling*/ - FOR(i = 0; i < fLenLow_fx; i++) - { - L_spectra_rm[i] = L_deposit_l(0); - if (GE_32(L_abs(L_spectra[i]), L_cut_input)) - { - L_spectra_rm[i] = L_spectra[i]; - move32(); - } - } - SpectrumSmoothing_fx(L_spectra_rm, sspectra_fx, Qss, fLenLow_fx, cut_sig_th_fx); - - /*Extract noise informaton from the core coder*/ - Copy(sspectra_fx, sspectra_ni_fx, fLenLow_fx); - FOR(i = 0; i < fLenLow_fx; i++) - { - L_spectra_diff[i] = L_sub(L_spectra_ni[i], L_spectra[i]); - move32(); - } - cut_ni_th_fx = 0x0; - move16(); - /*normalize sparse filled components*/ - FOR(i = 0; i < fLenLow_fx; i++) - { - L_spectra_rm[i] = L_deposit_l(0); - if (GE_32(L_abs(L_spectra_diff[i]), L_cut_input)) - { - L_spectra_rm[i] = L_spectra_diff[i]; - move32(); - } - } - SpectrumSmoothing_fx(L_spectra_rm, sspectra_diff_fx, Qss, fLenLow_fx, cut_ni_th_fx); - - /*Normalized corecoder for Gap filling */ - /* ratio = 1 - ss_min/10.0 */ - ratio_fx = sub(0x7fff, shl(mult_r(ss_min_fx, 3277), 15 - 10)); /* Q15 */ - FOR(i = 0; i < fLenLow_fx; i++) - { - sign_fx = 0; - move16(); - if (sspectra_fx[i] < 0) - { - sign_fx = 1; - move16(); - } - IF(GT_16(abs_s(sspectra_fx[i]), ss_min_fx)) - { - /*sspectra[i] = sign*((10-ss_min)/10.0f*(float)fabs(sspectra[i])+ss_min);*/ - sspectra_fx[i] = add(mult_r(ratio_fx, abs_s(sspectra_fx[i])), ss_min_fx); - IF(sign_fx != 0) - { - sspectra_fx[i] = negate(sspectra_fx[i]); - move16(); - } - } - IF(sspectra_fx[i] != 0x0) - { - sspectra_ni_fx[i] = sspectra_fx[i]; - move16(); - } - ELSE - { - sspectra_ni_fx[i] = mult_r(sspectra_diff_fx[i], ni_ratio_fx); - move16(); - } - - IF(sspectra_ni_fx[i] == 0x0) - { - /*sspectra_ni[i] = 0.5f*10.0f*ni_ratio* own_random(ni_seed)/32768.0f;*/ - L_temp = L_mult(ni_ratio_fx, 20480); /* ni_ratio*5 */ - L_temp = Mult_32_16(L_temp, rand_a_fx[i]); /* Q28 */ - sspectra_ni_fx[i] = round_fx(L_shr(L_temp, 2)); /* Qss */ - } - } - - return(ss_min_fx); + Word16 i; + Word32 L_spectra_diff[L_FRAME32k]; + Word16 ni_ratio_fx; /* Q15 */ + Word16 ss_min_fx; /* Q10 */ + Word16 cut_sig_th_fx; /* Q10 */ + Word16 cut_ni_th_fx; /* Q10 */ + Word16 pcnt_fx, sign_fx; + Word16 exp_normn, exp_normd; + + Word16 ratio_fx; + Word32 L_temp; + Word32 L_spectra_rm[L_FRAME32k]; + Word32 L_cut_input = 410; + Word16 rand_a_fx[L_FRAME32k]; + + + /* pre-prepare random array for float-fix interoperability */ + FOR( i = 0; i < fLenLow_fx; i++ ) + { + rand_a_fx[i] = Random( ni_seed_fx ); + } + + + /*Get the pulse resolution for the core coder*/ + pcnt_fx = 0; + move16(); + FOR( i = 0; i < fLenLow_fx; i++ ) + { + if ( L_spectra[i] != 0x0L ) + { + pcnt_fx = add( pcnt_fx, 1 ); + } + } + + /*ni_ratio = 4.0f*(pcnt)/(fLenLow+0.0f);*/ + exp_normn = norm_s( pcnt_fx ); + exp_normn = sub( exp_normn, 1 ); + exp_normd = norm_s( fLenLow_fx ); + + ni_ratio_fx = div_s( shl( pcnt_fx, exp_normn ), shl( fLenLow_fx, exp_normd ) ); /* exp_normn - exp_normd + 15 - 2 */ + + ni_ratio_fx = shl( ni_ratio_fx, add( sub( exp_normd, exp_normn ), 2 ) ); /* 15 - (exp_normn-exp_normd+15-2) */ + + /*ni_ratio = min(0.9f, ni_ratio);*/ + ni_ratio_fx = s_min( 29491, ni_ratio_fx ); /* 0.9: 29491(Q15) */ + + move16(); + + ss_min_fx = mult_r( ni_ratio_fx, 10240 ); /* Q15+Q10-15 = Q10 */ /* 10.0: 10240(Q10) */ + cut_sig_th_fx = shr( ss_min_fx, 2 ); /* 1/4 */ + cut_sig_th_fx = s_max( 973, cut_sig_th_fx ); /* 0.95: 972.8(Q10) */ + + /*core coder normalization for gap filling*/ + FOR( i = 0; i < fLenLow_fx; i++ ) + { + L_spectra_rm[i] = L_deposit_l( 0 ); + if ( GE_32( L_abs( L_spectra[i] ), L_cut_input ) ) + { + L_spectra_rm[i] = L_spectra[i]; + move32(); + } + } + SpectrumSmoothing_fx( L_spectra_rm, sspectra_fx, Qss, fLenLow_fx, cut_sig_th_fx ); + + /*Extract noise informaton from the core coder*/ + Copy( sspectra_fx, sspectra_ni_fx, fLenLow_fx ); + FOR( i = 0; i < fLenLow_fx; i++ ) + { + L_spectra_diff[i] = L_sub( L_spectra_ni[i], L_spectra[i] ); + move32(); + } + cut_ni_th_fx = 0x0; + move16(); + /*normalize sparse filled components*/ + FOR( i = 0; i < fLenLow_fx; i++ ) + { + L_spectra_rm[i] = L_deposit_l( 0 ); + if ( GE_32( L_abs( L_spectra_diff[i] ), L_cut_input ) ) + { + L_spectra_rm[i] = L_spectra_diff[i]; + move32(); + } + } + SpectrumSmoothing_fx( L_spectra_rm, sspectra_diff_fx, Qss, fLenLow_fx, cut_ni_th_fx ); + + /*Normalized corecoder for Gap filling */ + /* ratio = 1 - ss_min/10.0 */ + ratio_fx = sub( 0x7fff, shl( mult_r( ss_min_fx, 3277 ), 15 - 10 ) ); /* Q15 */ + FOR( i = 0; i < fLenLow_fx; i++ ) + { + sign_fx = 0; + move16(); + if ( sspectra_fx[i] < 0 ) + { + sign_fx = 1; + move16(); + } + IF( GT_16( abs_s( sspectra_fx[i] ), ss_min_fx ) ) + { + /*sspectra[i] = sign*((10-ss_min)/10.0f*(float)fabs(sspectra[i])+ss_min);*/ + sspectra_fx[i] = add( mult_r( ratio_fx, abs_s( sspectra_fx[i] ) ), ss_min_fx ); + IF( sign_fx != 0 ) + { + sspectra_fx[i] = negate( sspectra_fx[i] ); + move16(); + } + } + IF( sspectra_fx[i] != 0x0 ) + { + sspectra_ni_fx[i] = sspectra_fx[i]; + move16(); + } + ELSE + { + sspectra_ni_fx[i] = mult_r( sspectra_diff_fx[i], ni_ratio_fx ); + move16(); + } + + IF( sspectra_ni_fx[i] == 0x0 ) + { + /*sspectra_ni[i] = 0.5f*10.0f*ni_ratio* own_random(ni_seed)/32768.0f;*/ + L_temp = L_mult( ni_ratio_fx, 20480 ); /* ni_ratio*5 */ + L_temp = Mult_32_16( L_temp, rand_a_fx[i] ); /* Q28 */ + sspectra_ni_fx[i] = round_fx( L_shr( L_temp, 2 ) ); /* Qss */ + } + } + + return ( ss_min_fx ); } /*--------------------------------------------------------------------------* @@ -3139,191 +3148,191 @@ Word16 spectrumsmooth_noiseton_fx( /* o : Qss ss_min * level adjustments for the missing bands in the core coder *--------------------------------------------------------------------------*/ void noiseinj_hf_fx( - Word32 L_xSynth_har[], /* i/o : Qs gap filled information */ - Word16 Qs, /* i : Q0 Q value for xSynth_har */ - Word32 L_th_g[], /* i : Qs level adjustment information */ - Word32 L_band_energy[], /* i : Qbe subband energies */ - Word16 Qbe, /* i : Q0 Q value for band_energy */ - Word16 *prev_En_sb_fx, /* i/o : QsEn smoothed sqrt band Energies */ - const Word16 p2a_flags_fx[], /* i : Q0 Missing bands in the core coder */ - const Word16 BANDS_fx, /* i : Q0 total bands */ - const Word16 band_start_fx[], /* i : Q0 band start indices */ - const Word16 band_end_fx[], /* i : Q0 band end indices */ - const Word16 fLenLow_fx, /* i : Q0 low frequency bandwidth */ - const Word16 fLenHigh_fx /* i : Q0 SWB frequency bandwidth */ + Word32 L_xSynth_har[], /* i/o : Qs gap filled information */ + Word16 Qs, /* i : Q0 Q value for xSynth_har */ + Word32 L_th_g[], /* i : Qs level adjustment information */ + Word32 L_band_energy[], /* i : Qbe subband energies */ + Word16 Qbe, /* i : Q0 Q value for band_energy */ + Word16 *prev_En_sb_fx, /* i/o : QsEn smoothed sqrt band Energies */ + const Word16 p2a_flags_fx[], /* i : Q0 Missing bands in the core coder */ + const Word16 BANDS_fx, /* i : Q0 total bands */ + const Word16 band_start_fx[], /* i : Q0 band start indices */ + const Word16 band_end_fx[], /* i : Q0 band end indices */ + const Word16 fLenLow_fx, /* i : Q0 low frequency bandwidth */ + const Word16 fLenHigh_fx /* i : Q0 SWB frequency bandwidth */ ) { - Word16 k, i; + Word16 k, i; - Word16 *p_prev_En_sb_fx; - Word16 QbeL = 7; /* Don't need 3, because this E only use under th samples */ /* QsEn=3 */ + Word16 *p_prev_En_sb_fx; + Word16 QbeL = 7; /* Don't need 3, because this E only use under th samples */ /* QsEn=3 */ - Word16 map_pulse_t_fx[L_FRAME32k]; - Word16 map_pulse_fx[L_FRAME32k]; + Word16 map_pulse_t_fx[L_FRAME32k]; + Word16 map_pulse_fx[L_FRAME32k]; - Word16 QsEn = 4; /* kiken */ - Word32 L_En[NB_SWB_SUBBANDS]; - Word32 *p_L_En; - Word16 QE; - Word16 sqrt_En_fx[NB_SWB_SUBBANDS]; /* QsEn */ - Word16 *p_sqrt_En_fx; /* QsEn */ + Word16 QsEn = 4; /* kiken */ + Word32 L_En[NB_SWB_SUBBANDS]; + Word32 *p_L_En; + Word16 QE; + Word16 sqrt_En_fx[NB_SWB_SUBBANDS]; /* QsEn */ + Word16 *p_sqrt_En_fx; /* QsEn */ - Word16 Enn_sm_sb_fx[NB_SWB_SUBBANDS]; - Word16 *p_Enn_sm_sb_fx; + Word16 Enn_sm_sb_fx[NB_SWB_SUBBANDS]; + Word16 *p_Enn_sm_sb_fx; - Word16 exp_safe; - Word16 xSynth_har_fx[L_FRAME32k]; - Word16 QxSynth; + Word16 exp_safe; + Word16 xSynth_har_fx[L_FRAME32k]; + Word16 QxSynth; - Word16 Qtemp; + Word16 Qtemp; - Word16 ni_scale_fx; /* Q14 */ + Word16 ni_scale_fx; /* Q14 */ - Word16 temp_fx; - Word32 L_temp; + Word16 temp_fx; + Word32 L_temp; - Word16 exp_normn, exp_normd; - Word16 div_fx; - Word16 Qdiv; + Word16 exp_normn, exp_normd; + Word16 div_fx; + Word16 Qdiv; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; + Flag Overflow = 0; #endif - set16_fx(map_pulse_t_fx, 0, band_end_fx[BANDS_fx - 1] + 1); - set16_fx(map_pulse_fx, 0, band_end_fx[BANDS_fx - 1] + 1); - - /*level adjust the missing bands in the core coder */ - exp_safe = 4; /*move16();*/ - norm_vec_32_16_scale_fx(L_xSynth_har, Qs, fLenHigh_fx, xSynth_har_fx, &QxSynth, exp_safe); - QE = add(shl(QxSynth, 1), 1); - - p_L_En = L_En; - p_sqrt_En_fx = sqrt_En_fx; - FOR(k = sub(BANDS_fx, NB_SWB_SUBBANDS); k < BANDS_fx; k++) - { - *p_L_En = L_deposit_l(0); - IF(p2a_flags_fx[k] == 0) - { - FOR(i = band_start_fx[k]; i <= band_end_fx[k]; i++) - { - IF(LE_32(L_abs(L_xSynth_har[i - fLenLow_fx]), L_th_g[k - (BANDS_fx - NB_SWB_SUBBANDS)])) - { - *p_L_En = L_mac(*p_L_En, xSynth_har_fx[i - fLenLow_fx], xSynth_har_fx[i - fLenLow_fx]); - } - ELSE - { - map_pulse_t_fx[i] = 1; - move16(); - } - } + set16_fx( map_pulse_t_fx, 0, band_end_fx[BANDS_fx - 1] + 1 ); + set16_fx( map_pulse_fx, 0, band_end_fx[BANDS_fx - 1] + 1 ); + + /*level adjust the missing bands in the core coder */ + exp_safe = 4; /*move16();*/ + norm_vec_32_16_scale_fx( L_xSynth_har, Qs, fLenHigh_fx, xSynth_har_fx, &QxSynth, exp_safe ); + QE = add( shl( QxSynth, 1 ), 1 ); + + p_L_En = L_En; + p_sqrt_En_fx = sqrt_En_fx; + FOR( k = sub( BANDS_fx, NB_SWB_SUBBANDS ); k < BANDS_fx; k++ ) + { + *p_L_En = L_deposit_l( 0 ); + IF( p2a_flags_fx[k] == 0 ) + { + FOR( i = band_start_fx[k]; i <= band_end_fx[k]; i++ ) + { + IF( LE_32( L_abs( L_xSynth_har[i - fLenLow_fx] ), L_th_g[k - ( BANDS_fx - NB_SWB_SUBBANDS )] ) ) + { + *p_L_En = L_mac( *p_L_En, xSynth_har_fx[i - fLenLow_fx], xSynth_har_fx[i - fLenLow_fx] ); + } + ELSE + { + map_pulse_t_fx[i] = 1; + move16(); + } + } #ifdef BASOP_NOGLOB *p_L_En = L_shl_sat( *p_L_En, sub( QbeL, QE ) ); #else - *p_L_En = L_shl( *p_L_En, sub( QbeL, QE ) ); + *p_L_En = L_shl( *p_L_En, sub( QbeL, QE ) ); #endif - move32(); - /**p_L_En = (float)sqrt(*p_En);*/ - sqrt_32n_16_fx(*p_L_En, QbeL, p_sqrt_En_fx, &Qtemp); + move32(); + /**p_L_En = (float)sqrt(*p_En);*/ + sqrt_32n_16_fx( *p_L_En, QbeL, p_sqrt_En_fx, &Qtemp ); #ifdef BASOP_NOGLOB - *p_sqrt_En_fx = shl_o(*p_sqrt_En_fx, sub(QsEn, Qtemp), &Overflow); /* -> Q2 */ move16(); + *p_sqrt_En_fx = shl_o( *p_sqrt_En_fx, sub( QsEn, Qtemp ), &Overflow ); /* -> Q2 */ + move16(); #else - *p_sqrt_En_fx = shl(*p_sqrt_En_fx, sub(QsEn, Qtemp)); /* -> Q2 */ move16(); + *p_sqrt_En_fx = shl( *p_sqrt_En_fx, sub( QsEn, Qtemp ) ); /* -> Q2 */ + move16(); #endif - } - p_L_En++; - p_sqrt_En_fx++; - } - - p_sqrt_En_fx = sqrt_En_fx; - p_Enn_sm_sb_fx = Enn_sm_sb_fx; - p_prev_En_sb_fx = prev_En_sb_fx; - FOR(k = BANDS_fx - NB_SWB_SUBBANDS; k < BANDS_fx; k++) - { - *p_Enn_sm_sb_fx = prev_En_sb_fx[k - (BANDS_fx - NB_SWB_SUBBANDS)]; - move16(); /* QsEn */ - IF(p2a_flags_fx[k] == 0) - { - L_temp = Mult_32_16(L_band_energy[k], 26214); /* 0.8: 26214(Q15) */ - temp_fx = round_fx(L_shl(L_temp, sub(QsEn, sub(Qbe, 16)))); - IF(LT_16(*p_prev_En_sb_fx, temp_fx)) - { - /**p_Enn_sm_sb = (0.15f*(*p_En)) + (0.85f*prev_En_sb[k-(BANDS-NB_SWB_SUBBANDS)]);*/ - /* 0.15: 4915.2(Q15) 0.85: 27852.80(Q15) */ - *p_Enn_sm_sb_fx = round_fx(L_mac(L_mult(*p_sqrt_En_fx, 4915), *p_prev_En_sb_fx, 27853)); - } - ELSE - { - /**p_Enn_sm_sb = (0.8f*(*p_En)) + (0.2f*prev_En_sb[k-(BANDS-NB_SWB_SUBBANDS)]);*/ - /* 0.8: 26214.4(Q15) 0.2:6553.6(Q15) */ - *p_Enn_sm_sb_fx = round_fx(L_mac(L_mult(*p_sqrt_En_fx, 26214), *p_prev_En_sb_fx, 6554)); - } - } - - p_Enn_sm_sb_fx++; - p_sqrt_En_fx++; - p_prev_En_sb_fx++; - } - - p_sqrt_En_fx = sqrt_En_fx; - p_Enn_sm_sb_fx = Enn_sm_sb_fx; - p_prev_En_sb_fx = prev_En_sb_fx; - map_pulse_fx[fLenLow_fx] = (map_pulse_t_fx[fLenLow_fx] | map_pulse_t_fx[fLenLow_fx + 1]); - logic16(); - move16(); - FOR(i = fLenLow_fx + 1; i < band_end_fx[BANDS_fx - 1]; i++) - { - map_pulse_fx[i] = (map_pulse_t_fx[i - 1] | map_pulse_t_fx[i] | map_pulse_t_fx[i + 1]); - logic16(); - logic16(); - move16(); - } - map_pulse_fx[i] = (map_pulse_t_fx[i - 1] | map_pulse_t_fx[i]); - logic16(); - move16(); - - FOR(k = BANDS_fx - NB_SWB_SUBBANDS; k < BANDS_fx; k++) - { - test(); - IF(p2a_flags_fx[k] == 0 && *p_sqrt_En_fx != 0x0) - { - /*ni_scale = sqrt((*p_Enn_sm_sb)/(*p_En));*/ - /* Div Part */ - exp_normn = norm_s(*p_Enn_sm_sb_fx); - exp_normn = sub(exp_normn, 1); - exp_normd = norm_s(*p_sqrt_En_fx); - div_fx = div_s(shl(*p_Enn_sm_sb_fx, exp_normn), shl(*p_sqrt_En_fx, exp_normd)); - Qdiv = add(sub(exp_normn, exp_normd), 15); - - /* SQRT Part */ - sqrt_32n_16_fx(L_deposit_h(div_fx), add(Qdiv, 16), &ni_scale_fx, &Qtemp); + } + p_L_En++; + p_sqrt_En_fx++; + } + + p_sqrt_En_fx = sqrt_En_fx; + p_Enn_sm_sb_fx = Enn_sm_sb_fx; + p_prev_En_sb_fx = prev_En_sb_fx; + FOR( k = BANDS_fx - NB_SWB_SUBBANDS; k < BANDS_fx; k++ ) + { + *p_Enn_sm_sb_fx = prev_En_sb_fx[k - ( BANDS_fx - NB_SWB_SUBBANDS )]; + move16(); /* QsEn */ + IF( p2a_flags_fx[k] == 0 ) + { + L_temp = Mult_32_16( L_band_energy[k], 26214 ); /* 0.8: 26214(Q15) */ + temp_fx = round_fx( L_shl( L_temp, sub( QsEn, sub( Qbe, 16 ) ) ) ); + IF( LT_16( *p_prev_En_sb_fx, temp_fx ) ) + { + /**p_Enn_sm_sb = (0.15f*(*p_En)) + (0.85f*prev_En_sb[k-(BANDS-NB_SWB_SUBBANDS)]);*/ + /* 0.15: 4915.2(Q15) 0.85: 27852.80(Q15) */ + *p_Enn_sm_sb_fx = round_fx( L_mac( L_mult( *p_sqrt_En_fx, 4915 ), *p_prev_En_sb_fx, 27853 ) ); + } + ELSE + { + /**p_Enn_sm_sb = (0.8f*(*p_En)) + (0.2f*prev_En_sb[k-(BANDS-NB_SWB_SUBBANDS)]);*/ + /* 0.8: 26214.4(Q15) 0.2:6553.6(Q15) */ + *p_Enn_sm_sb_fx = round_fx( L_mac( L_mult( *p_sqrt_En_fx, 26214 ), *p_prev_En_sb_fx, 6554 ) ); + } + } + + p_Enn_sm_sb_fx++; + p_sqrt_En_fx++; + p_prev_En_sb_fx++; + } + + p_sqrt_En_fx = sqrt_En_fx; + p_Enn_sm_sb_fx = Enn_sm_sb_fx; + p_prev_En_sb_fx = prev_En_sb_fx; + map_pulse_fx[fLenLow_fx] = ( map_pulse_t_fx[fLenLow_fx] | map_pulse_t_fx[fLenLow_fx + 1] ); + logic16(); + move16(); + FOR( i = fLenLow_fx + 1; i < band_end_fx[BANDS_fx - 1]; i++ ) + { + map_pulse_fx[i] = ( map_pulse_t_fx[i - 1] | map_pulse_t_fx[i] | map_pulse_t_fx[i + 1] ); + logic16(); + logic16(); + move16(); + } + map_pulse_fx[i] = ( map_pulse_t_fx[i - 1] | map_pulse_t_fx[i] ); + logic16(); + move16(); + + FOR( k = BANDS_fx - NB_SWB_SUBBANDS; k < BANDS_fx; k++ ) + { + test(); + IF( p2a_flags_fx[k] == 0 && *p_sqrt_En_fx != 0x0 ) + { + /*ni_scale = sqrt((*p_Enn_sm_sb)/(*p_En));*/ + /* Div Part */ + exp_normn = norm_s( *p_Enn_sm_sb_fx ); + exp_normn = sub( exp_normn, 1 ); + exp_normd = norm_s( *p_sqrt_En_fx ); + div_fx = div_s( shl( *p_Enn_sm_sb_fx, exp_normn ), shl( *p_sqrt_En_fx, exp_normd ) ); + Qdiv = add( sub( exp_normn, exp_normd ), 15 ); + + /* SQRT Part */ + sqrt_32n_16_fx( L_deposit_h( div_fx ), add( Qdiv, 16 ), &ni_scale_fx, &Qtemp ); #ifdef BASOP_NOGLOB - ni_scale_fx = shl_o(ni_scale_fx, sub(14, Qtemp), &Overflow); + ni_scale_fx = shl_o( ni_scale_fx, sub( 14, Qtemp ), &Overflow ); #else - ni_scale_fx = shl(ni_scale_fx, sub(14, Qtemp)); + ni_scale_fx = shl( ni_scale_fx, sub( 14, Qtemp ) ); #endif - ni_scale_fx = s_min(20408, ni_scale_fx); /* 1.25=20408.0(Q14) */ - - ni_scale_fx = s_max(12288, ni_scale_fx); /* 0.75=12288.0(Q14) */ - - ni_scale_fx = mult_r(ni_scale_fx, 26214); /* 0.8=26214.4(Q15) -> Q14 */ - FOR(i = band_start_fx[k]; i <= band_end_fx[k]; i++) - { - IF(LE_32(L_abs(L_xSynth_har[i - fLenLow_fx]), L_th_g[k - (BANDS_fx - NB_SWB_SUBBANDS)])) - { - IF(map_pulse_fx[i] == 0) - { - L_xSynth_har[i - fLenLow_fx] = L_shl(Mult_32_16(L_xSynth_har[i - fLenLow_fx], ni_scale_fx), 1); /* Q12+Q14-15-1 = Q12 */ move32(); - } - } - } - *p_prev_En_sb_fx = *p_Enn_sm_sb_fx; - move16(); - } - p_Enn_sm_sb_fx++; - p_sqrt_En_fx++; - p_prev_En_sb_fx++; - } - - return; + ni_scale_fx = s_min( 20408, ni_scale_fx ); /* 1.25=20408.0(Q14) */ + + ni_scale_fx = s_max( 12288, ni_scale_fx ); /* 0.75=12288.0(Q14) */ + + ni_scale_fx = mult_r( ni_scale_fx, 26214 ); /* 0.8=26214.4(Q15) -> Q14 */ + FOR( i = band_start_fx[k]; i <= band_end_fx[k]; i++ ){ + IF( LE_32( L_abs( L_xSynth_har[i - fLenLow_fx] ), L_th_g[k - ( BANDS_fx - NB_SWB_SUBBANDS )] ) ){ + IF( map_pulse_fx[i] == 0 ){ + L_xSynth_har[i - fLenLow_fx] = L_shl( Mult_32_16( L_xSynth_har[i - fLenLow_fx], ni_scale_fx ), 1 ); /* Q12+Q14-15-1 = Q12 */ + move32(); + } + } +} +*p_prev_En_sb_fx = *p_Enn_sm_sb_fx; +move16(); +} +p_Enn_sm_sb_fx++; +p_sqrt_En_fx++; +p_prev_En_sb_fx++; +} + +return; } /*--------------------------------------------------------------------------* @@ -3332,112 +3341,111 @@ void noiseinj_hf_fx( * *--------------------------------------------------------------------------*/ void updat_prev_frm_fx( - Word32 L_y2[], /* i/o: core coder buffer */ - Word32 L_t_audio[], /* o: core coder buffer */ - Word32 L_bwe_br, /* i: core bitrate */ - Word16 length_fx, /* i: frame length coded bw */ - const Word16 inner_frame_fx, /* i: input frame length */ - Word16 bands_fx, /* i: sub band resolution */ - Word16 bwidth_fx, /* i: NB/WB/SWB indicator */ - const Word16 is_transient_fx, /* i: signal class information */ - Word16 hqswb_clas_fx, /* i: signal class information */ - Word16 *prev_hqswb_clas, /* o: update signal class information */ - Word16 prev_SWB_peak_pos_fx[], /* o: update core coder last coded peaks*/ - Word16 prev_SWB_peak_pos_tmp_fx[], /* o: update core coder last coded peaks*/ - Word16 *prev_frm_hfe2, /* o: update harmonics */ - Word16 *prev_stab_hfe2, /* o: update harmonics */ - Word16 bws_cnt_fx /* i: band width detector */ + Word32 L_y2[], /* i/o: core coder buffer */ + Word32 L_t_audio[], /* o: core coder buffer */ + Word32 L_bwe_br, /* i: core bitrate */ + Word16 length_fx, /* i: frame length coded bw */ + const Word16 inner_frame_fx, /* i: input frame length */ + Word16 bands_fx, /* i: sub band resolution */ + Word16 bwidth_fx, /* i: NB/WB/SWB indicator */ + const Word16 is_transient_fx, /* i: signal class information */ + Word16 hqswb_clas_fx, /* i: signal class information */ + Word16 *prev_hqswb_clas, /* o: update signal class information */ + Word16 prev_SWB_peak_pos_fx[], /* o: update core coder last coded peaks*/ + Word16 prev_SWB_peak_pos_tmp_fx[], /* o: update core coder last coded peaks*/ + Word16 *prev_frm_hfe2, /* o: update harmonics */ + Word16 *prev_stab_hfe2, /* o: update harmonics */ + Word16 bws_cnt_fx /* i: band width detector */ ) { - Word16 i, j, k; - Word16 k1_fx, k2_fx; - Word16 length1_fx, length2_fx, length3_fx; - - /* Copy the coded MDCT coefficient to the output buffer */ - IF(!is_transient_fx) - { - /* Copy the scratch buffer to the output */ - Copy32(L_y2, L_t_audio, length_fx); - - /* If the input frame is larger than coded bandwidth, zero out uncoded MDCT coefficients */ - IF(GT_16(inner_frame_fx, length_fx)) - { - set32_fx(L_t_audio + length_fx, 0x0L, sub(inner_frame_fx, length_fx)); - } - } - ELSE /* transient frame */ - { - test(); - IF(EQ_16(inner_frame_fx, length_fx) || bws_cnt_fx > 0) - { - /* Copy the scratch buffer to the output */ - Copy32(L_y2, L_t_audio, length_fx); - } - ELSE - { - /* length/NUM_TIME_SWITCHING_BLOCKS */ - /*length1_fx = div_s_ss(length_fx, NUM_TIME_SWITCHING_BLOCKS); */ - length1_fx = shr(length_fx, 2); /* length1 = length/NUM_TIME_SWITCHING_BLOCKS */ - /* inner_frame/NUM_TIME_SWITCHING_BLOCKS */ - /*length2_fx = div_s_ss(inner_frame_fx, NUM_TIME_SWITCHING_BLOCKS); */ - length2_fx = shr(inner_frame_fx, 2); /* length2 = inner_frame/NUM_TIME_SWITCHING_BLOCKS */ - /* (inner_frame-length)/NUM_TIME_SWITCHING_BLOCKS */ - /*length3_fx = div_s_ss(sub(inner_frame_fx, length_fx), NUM_TIME_SWITCHING_BLOCKS); */ - length3_fx = shr(sub(inner_frame_fx, length_fx) ,2); /* (inner_frame-length)/NUM_TIME_SWITCHING_BLOCKS */ - - k1_fx = 0; - move16(); - k2_fx = 0; - move16(); - - /* un-collapse transient frame and interleave zeros */ - FOR(i = 0; i < NUM_TIME_SWITCHING_BLOCKS; i++) - { - /*k1 = i*length/NUM_TIME_SWITCHING_BLOCKS; */ - /*k2 = i*inner_frame/NUM_TIME_SWITCHING_BLOCKS; */ - - Copy32(L_y2 + k1_fx, L_t_audio + k2_fx, length1_fx); - set32_fx(L_t_audio + k2_fx + length1_fx, 0x0L, length3_fx); - - k1_fx = add(k1_fx, length1_fx); - k2_fx = add(k2_fx, length2_fx); - - } - } - } - - IF((EQ_32(L_bwe_br, HQ_16k40) || EQ_32(L_bwe_br, HQ_13k20)) && EQ_16(bwidth_fx, SWB)) - { - *prev_hqswb_clas = hqswb_clas_fx; - move16(); - IF(NE_16(hqswb_clas_fx, HQ_HARMONIC)) - { - *prev_frm_hfe2 = 0; - move16(); - *prev_stab_hfe2 = 0; - move16(); - } - } - ELSE - { - *prev_hqswb_clas = is_transient_fx; - move16(); - } - - test(); - test(); - test(); - IF((EQ_32(L_bwe_br, HQ_16k40) || EQ_32(L_bwe_br, HQ_13k20)) && EQ_16(bwidth_fx, SWB) && EQ_16(hqswb_clas_fx, HQ_NORMAL)) - { - j = 0; - move16(); - FOR(k = sub(bands_fx, SPT_SHORTEN_SBNUM); k < bands_fx; k++) - { - prev_SWB_peak_pos_fx[j] = prev_SWB_peak_pos_tmp_fx[j]; - move16(); - j = add(j, 1); - } - } - - return; + Word16 i, j, k; + Word16 k1_fx, k2_fx; + Word16 length1_fx, length2_fx, length3_fx; + + /* Copy the coded MDCT coefficient to the output buffer */ + IF( !is_transient_fx ) + { + /* Copy the scratch buffer to the output */ + Copy32( L_y2, L_t_audio, length_fx ); + + /* If the input frame is larger than coded bandwidth, zero out uncoded MDCT coefficients */ + IF( GT_16( inner_frame_fx, length_fx ) ) + { + set32_fx( L_t_audio + length_fx, 0x0L, sub( inner_frame_fx, length_fx ) ); + } + } + ELSE /* transient frame */ + { + test(); + IF( EQ_16( inner_frame_fx, length_fx ) || bws_cnt_fx > 0 ) + { + /* Copy the scratch buffer to the output */ + Copy32( L_y2, L_t_audio, length_fx ); + } + ELSE + { + /* length/NUM_TIME_SWITCHING_BLOCKS */ + /*length1_fx = div_s_ss(length_fx, NUM_TIME_SWITCHING_BLOCKS); */ + length1_fx = shr( length_fx, 2 ); /* length1 = length/NUM_TIME_SWITCHING_BLOCKS */ + /* inner_frame/NUM_TIME_SWITCHING_BLOCKS */ + /*length2_fx = div_s_ss(inner_frame_fx, NUM_TIME_SWITCHING_BLOCKS); */ + length2_fx = shr( inner_frame_fx, 2 ); /* length2 = inner_frame/NUM_TIME_SWITCHING_BLOCKS */ + /* (inner_frame-length)/NUM_TIME_SWITCHING_BLOCKS */ + /*length3_fx = div_s_ss(sub(inner_frame_fx, length_fx), NUM_TIME_SWITCHING_BLOCKS); */ + length3_fx = shr( sub( inner_frame_fx, length_fx ), 2 ); /* (inner_frame-length)/NUM_TIME_SWITCHING_BLOCKS */ + + k1_fx = 0; + move16(); + k2_fx = 0; + move16(); + + /* un-collapse transient frame and interleave zeros */ + FOR( i = 0; i < NUM_TIME_SWITCHING_BLOCKS; i++ ) + { + /*k1 = i*length/NUM_TIME_SWITCHING_BLOCKS; */ + /*k2 = i*inner_frame/NUM_TIME_SWITCHING_BLOCKS; */ + + Copy32( L_y2 + k1_fx, L_t_audio + k2_fx, length1_fx ); + set32_fx( L_t_audio + k2_fx + length1_fx, 0x0L, length3_fx ); + + k1_fx = add( k1_fx, length1_fx ); + k2_fx = add( k2_fx, length2_fx ); + } + } + } + + IF( ( EQ_32( L_bwe_br, HQ_16k40 ) || EQ_32( L_bwe_br, HQ_13k20 ) ) && EQ_16( bwidth_fx, SWB ) ) + { + *prev_hqswb_clas = hqswb_clas_fx; + move16(); + IF( NE_16( hqswb_clas_fx, HQ_HARMONIC ) ) + { + *prev_frm_hfe2 = 0; + move16(); + *prev_stab_hfe2 = 0; + move16(); + } + } + ELSE + { + *prev_hqswb_clas = is_transient_fx; + move16(); + } + + test(); + test(); + test(); + IF( ( EQ_32( L_bwe_br, HQ_16k40 ) || EQ_32( L_bwe_br, HQ_13k20 ) ) && EQ_16( bwidth_fx, SWB ) && EQ_16( hqswb_clas_fx, HQ_NORMAL ) ) + { + j = 0; + move16(); + FOR( k = sub( bands_fx, SPT_SHORTEN_SBNUM ); k < bands_fx; k++ ) + { + prev_SWB_peak_pos_fx[j] = prev_SWB_peak_pos_tmp_fx[j]; + move16(); + j = add( j, 1 ); + } + } + + return; } diff --git a/lib_com/swb_tbe_com.c b/lib_com/swb_tbe_com.c index 1755a8f82..582dc217b 100644 --- a/lib_com/swb_tbe_com.c +++ b/lib_com/swb_tbe_com.c @@ -57,7 +57,7 @@ static void create_random_vector( float output[], const int16_t length, int16_t static void flip_spectrum( const float input[], float output[], const int16_t length ); static void Hilbert_transform( float tmp_R[], float tmp_I[], float *tmpi_R, float *tmpi_I, const int16_t length, const int16_t HB_stage_id ); #ifdef IVAS_FLOAT_FIXED -static void Hilbert_transform_fx_32(Word32 tmp_R[], Word32 tmp_I[], Word32 *tmpi_R, Word32 *tmpi_I, const Word16 length, const Word16 HB_stage_id); +static void Hilbert_transform_fx_32( Word32 tmp_R[], Word32 tmp_I[], Word32 *tmpi_R, Word32 *tmpi_I, const Word16 length, const Word16 HB_stage_id ); #endif static void Estimate_mix_factors( const float *shb_res, const float *exc16kWhtnd, const float *White_exc16k, const float pow1, const float pow22, float *vf_modified, int16_t *vf_ind ); @@ -243,13 +243,13 @@ void flip_and_downmix_generic( } #ifdef IVAS_FLOAT_FIXED void flip_and_downmix_generic_fx_32( - Word32 input[], /* i : input spectrum Qx*/ - Word32 output[], /* o : output spectrum Qx*/ - const Word16 length, /* i : length of spectra */ - Word32 mem1_ext[HILBERT_ORDER1], /* i/o: memory Qx*/ - Word32 mem2_ext[2*HILBERT_ORDER2], /* i/o: memory Qx*/ - Word32 mem3_ext[2*HILBERT_ORDER2], /* i/o: memory Qx*/ - Word16* phase_state /* i/o: Phase state in case frequency isn't multiple of 50 Hz */ + Word32 input[], /* i : input spectrum Qx*/ + Word32 output[], /* o : output spectrum Qx*/ + const Word16 length, /* i : length of spectra */ + Word32 mem1_ext[HILBERT_ORDER1], /* i/o: memory Qx*/ + Word32 mem2_ext[2 * HILBERT_ORDER2], /* i/o: memory Qx*/ + Word32 mem3_ext[2 * HILBERT_ORDER2], /* i/o: memory Qx*/ + Word16 *phase_state /* i/o: Phase state in case frequency isn't multiple of 50 Hz */ ) { Word16 i, j; @@ -264,14 +264,12 @@ void flip_and_downmix_generic_fx_32( /*Word16 s_tmp[L_FRAME32k];*/ /*Word16 factor;*/ Word16 period; - Word16 local_negsin_table17[17] = { 0, -11793, -22005, -29268, -32609, -31580, - -26319, -17530, -6393, 6393, 17530, 26319, - 31580, 32609, 29268, 22005, 11793 - }; /* Q15 */ - Word16 local_cos_table17[17] = {32767, 30571, 24279, 14732, 3212, -8739, - -19519, -27683, -32137, -32137, -27683, - -19519, -8739, 3212, 14732, 24279, 30571 - }; /* Q15 */ + Word16 local_negsin_table17[17] = { 0, -11793, -22005, -29268, -32609, -31580, + -26319, -17530, -6393, 6393, 17530, 26319, + 31580, 32609, 29268, 22005, 11793 }; /* Q15 */ + Word16 local_cos_table17[17] = { 32767, 30571, 24279, 14732, 3212, -8739, + -19519, -27683, -32137, -32137, -27683, + -19519, -8739, 3212, 14732, 24279, 30571 }; /* Q15 */ Word16 *local_negsin_table, *local_cos_table; Word32 L_tmp; @@ -282,59 +280,59 @@ void flip_and_downmix_generic_fx_32( local_cos_table = local_cos_table17; - FOR (i = 0; i < length; i = i + 2 ) + FOR( i = 0; i < length; i = i + 2 ) { input[i] = L_negate( input[i] ); move16(); } - Copy32(input, tmp + HILBERT_ORDER1, length ); - Copy32( mem1_ext, tmp, HILBERT_ORDER1); + Copy32( input, tmp + HILBERT_ORDER1, length ); + Copy32( mem1_ext, tmp, HILBERT_ORDER1 ); /* Hilber transform stage - 0 - single precision */ - Hilbert_transform_fx_32( tmp, /* i: Real component of HB */ - tmp, /* i: Imag component of HB */ - tmpi_R, /* o: Real component of HB */ - tmpi_I, /* o: Imag. component of HB */ - length, /* i: length of the spectra */ - 0); /* i: HB transform stage */ + Hilbert_transform_fx_32( tmp, /* i: Real component of HB */ + tmp, /* i: Imag component of HB */ + tmpi_R, /* o: Real component of HB */ + tmpi_I, /* o: Imag. component of HB */ + length, /* i: length of the spectra */ + 0 ); /* i: HB transform stage */ Copy32( mem2_ext, tmpi2_R, HILBERT_ORDER2 ); Copy32( mem3_ext, tmpi2_I, HILBERT_ORDER2 ); /* Hilber transform stage - 1 */ - Hilbert_transform_fx_32( tmpi_R, /* i: Real component of HB */ - tmpi_I, /* i: Imag component of HB */ - tmpi2_R, /* o: Real component of HB */ - tmpi2_I, /* o: Imag. component of HB */ - length, /* i: length of the spectra */ - 1); /* i: HB transform stage */ - Copy32(tmp + length, mem1_ext, HILBERT_ORDER1); - Copy32( mem2_ext+HILBERT_ORDER2, tmp_R, HILBERT_ORDER2 ); - Copy32( mem3_ext+HILBERT_ORDER2, tmp_I, HILBERT_ORDER2 ); + Hilbert_transform_fx_32( tmpi_R, /* i: Real component of HB */ + tmpi_I, /* i: Imag component of HB */ + tmpi2_R, /* o: Real component of HB */ + tmpi2_I, /* o: Imag. component of HB */ + length, /* i: length of the spectra */ + 1 ); /* i: HB transform stage */ + Copy32( tmp + length, mem1_ext, HILBERT_ORDER1 ); + Copy32( mem2_ext + HILBERT_ORDER2, tmp_R, HILBERT_ORDER2 ); + Copy32( mem3_ext + HILBERT_ORDER2, tmp_I, HILBERT_ORDER2 ); /* Hilber transform stage - 2 */ - Hilbert_transform_fx_32( tmpi2_R, /* i: Real component of HB */ - tmpi2_I, /* i: Imag component of HB */ - tmpi_R, /* o: Real component of HB */ - tmpi_I, /* o: Imag. component of HB */ - length, /* i: length of the spectra */ - 2); /* i: HB transform stage */ + Hilbert_transform_fx_32( tmpi2_R, /* i: Real component of HB */ + tmpi2_I, /* i: Imag component of HB */ + tmpi_R, /* o: Real component of HB */ + tmpi_I, /* o: Imag. component of HB */ + length, /* i: length of the spectra */ + 2 ); /* i: HB transform stage */ Copy32( tmpi2_R + length, mem2_ext, HILBERT_ORDER2 ); Copy32( tmpi2_I + length, mem3_ext, HILBERT_ORDER2 ); /* Hilber transform stage - 3 */ - Hilbert_transform_fx_32( tmpi_R, /* i: Real component of HB */ - tmpi_I, /* i: Imag component of HB */ - tmp_R, /* o: Real component of HB */ - tmp_I, /* o: Imag. component of HB */ - length, /* i: length of the spectra */ - 3); /* i: HB transform stage */ + Hilbert_transform_fx_32( tmpi_R, /* i: Real component of HB */ + tmpi_I, /* i: Imag component of HB */ + tmp_R, /* o: Real component of HB */ + tmp_I, /* o: Imag. component of HB */ + length, /* i: length of the spectra */ + 3 ); /* i: HB transform stage */ - Copy32( tmp_R + length, mem2_ext+HILBERT_ORDER2, HILBERT_ORDER2 ); - Copy32( tmp_I + length, mem3_ext+HILBERT_ORDER2, HILBERT_ORDER2 ); + Copy32( tmp_R + length, mem2_ext + HILBERT_ORDER2, HILBERT_ORDER2 ); + Copy32( tmp_I + length, mem3_ext + HILBERT_ORDER2, HILBERT_ORDER2 ); if ( *phase_state >= period ) { @@ -347,15 +345,15 @@ void flip_and_downmix_generic_fx_32( j = *phase_state; move16(); - WHILE ( i < length ) + WHILE( i < length ) { - WHILE ( ( j < period ) && ( i < length ) ) + WHILE( ( j < period ) && ( i < length ) ) { - L_tmp = Mult_32_16( tmp_R[i + 4], local_cos_table[j] ); /*//Qx+16 */ + L_tmp = Mult_32_16( tmp_R[i + 4], local_cos_table[j] ); /*//Qx+16 */ L_tmp = Madd_32_16( L_tmp, tmp_I[i + 4], local_negsin_table[j] ); /*Qx+16 */ - output[i] = L_tmp ; /*Qx */ - i++ ; - j++ ; + output[i] = L_tmp; /*Qx */ + i++; + j++; } if ( j >= period ) @@ -414,22 +412,22 @@ static void Hilbert_transform( } #ifdef IVAS_FLOAT_FIXED -static void Hilbert_transform_fx_32( - Word32 tmp_R[], /* i: Real component of HB */ - Word32 tmp_I[], /* i: Real component of HB */ - Word32 tmpi_R[], /* o: Real component of HB */ - Word32 tmpi_I[], /* o: Imag. component of HB */ - const Word16 length, /* i: input length */ - const Word16 HB_stage_id /* i: HB transform stage */ +static void Hilbert_transform_fx_32( + Word32 tmp_R[], /* i: Real component of HB */ + Word32 tmp_I[], /* i: Real component of HB */ + Word32 tmpi_R[], /* o: Real component of HB */ + Word32 tmpi_I[], /* o: Imag. component of HB */ + const Word16 length, /* i: input length */ + const Word16 HB_stage_id /* i: HB transform stage */ ) { Word16 i, hb_filter_stage, offset; Word32 L_tmp; - hb_filter_stage = 2*HB_stage_id; + hb_filter_stage = 2 * HB_stage_id; offset = 0; move16(); - if( HB_stage_id == 0 ) + if ( HB_stage_id == 0 ) { offset = 1; move16(); @@ -437,36 +435,36 @@ static void Hilbert_transform_fx_32( test(); test(); - IF (HB_stage_id == 0 || HB_stage_id == 2) + IF( HB_stage_id == 0 || HB_stage_id == 2 ) { - FOR ( i = 0; i < length; i++ ) + FOR( i = 0; i < length; i++ ) { - L_tmp = Mult_32_16( tmp_R[i + 4], Hilbert_coeffs_fx[hb_filter_stage][0 + offset] ); /*Qx+15 */ - L_tmp = Madd_32_16( L_tmp, tmp_R[i + 2], Hilbert_coeffs_fx[hb_filter_stage][2 + offset] ); /*Qx+15 */ - L_tmp = Madd_32_16( L_tmp, tmp_R[i] , Hilbert_coeffs_fx[hb_filter_stage][4 + offset] );/*Qx+15 */ + L_tmp = Mult_32_16( tmp_R[i + 4], Hilbert_coeffs_fx[hb_filter_stage][0 + offset] ); /*Qx+15 */ + L_tmp = Madd_32_16( L_tmp, tmp_R[i + 2], Hilbert_coeffs_fx[hb_filter_stage][2 + offset] ); /*Qx+15 */ + L_tmp = Madd_32_16( L_tmp, tmp_R[i], Hilbert_coeffs_fx[hb_filter_stage][4 + offset] ); /*Qx+15 */ tmpi_R[i] = L_shl( L_tmp, 1 ); move32(); /*Qx+16 */ - L_tmp = Mult_32_16( tmp_I[i + 4 + offset], Hilbert_coeffs_fx[hb_filter_stage+1][0] ); /*Qx+15 */ - L_tmp = Madd_32_16( L_tmp, tmp_I[i + 2 + offset], Hilbert_coeffs_fx[hb_filter_stage+1][2] ); /*Qx+15 */ - L_tmp = Madd_32_16( L_tmp, tmp_I[i + offset] , Hilbert_coeffs_fx[hb_filter_stage+1][4] ); /*Qx+15 */ + L_tmp = Mult_32_16( tmp_I[i + 4 + offset], Hilbert_coeffs_fx[hb_filter_stage + 1][0] ); /*Qx+15 */ + L_tmp = Madd_32_16( L_tmp, tmp_I[i + 2 + offset], Hilbert_coeffs_fx[hb_filter_stage + 1][2] ); /*Qx+15 */ + L_tmp = Madd_32_16( L_tmp, tmp_I[i + offset], Hilbert_coeffs_fx[hb_filter_stage + 1][4] ); /*Qx+15 */ tmpi_I[i] = L_shl( L_tmp, 1 ); move32(); /*Qx+16 */ } } - ELSE IF (HB_stage_id == 1 || HB_stage_id == 3) + ELSE IF( HB_stage_id == 1 || HB_stage_id == 3 ) { - FOR ( i = 0; i < length; i++ ) + FOR( i = 0; i < length; i++ ) { - L_tmp = Mult_32_16( tmpi_R[i + 2], Hilbert_coeffs_fx[hb_filter_stage][2] ); /*Qx+15 */ - L_tmp = Madd_32_16( L_tmp, tmpi_R[i] , Hilbert_coeffs_fx[hb_filter_stage][4] ); /*Qx+15 */ - tmpi_R[i + 4] = L_sub( tmp_R[i], L_shl( L_tmp, 1 ) ); - move32();/*Qx+16 */ + L_tmp = Mult_32_16( tmpi_R[i + 2], Hilbert_coeffs_fx[hb_filter_stage][2] ); /*Qx+15 */ + L_tmp = Madd_32_16( L_tmp, tmpi_R[i], Hilbert_coeffs_fx[hb_filter_stage][4] ); /*Qx+15 */ + tmpi_R[i + 4] = L_sub( tmp_R[i], L_shl( L_tmp, 1 ) ); + move32(); /*Qx+16 */ - L_tmp = Mult_32_16( tmpi_I[i + 2], Hilbert_coeffs_fx[hb_filter_stage+1][2] ); /*Qx+15 */ - L_tmp = Madd_32_16( L_tmp, tmpi_I[i] , Hilbert_coeffs_fx[hb_filter_stage+1][4] ); /*Qx+15 */ - tmpi_I[i + 4] = L_sub( tmp_I[i], L_shl( L_tmp, 1 ) ); + L_tmp = Mult_32_16( tmpi_I[i + 2], Hilbert_coeffs_fx[hb_filter_stage + 1][2] ); /*Qx+15 */ + L_tmp = Madd_32_16( L_tmp, tmpi_I[i], Hilbert_coeffs_fx[hb_filter_stage + 1][4] ); /*Qx+15 */ + tmpi_I[i + 4] = L_sub( tmp_I[i], L_shl( L_tmp, 1 ) ); move32(); /*Qx+16 */ } } @@ -2127,7 +2125,7 @@ void synthesise_fb_high_band( const float excitation_in[], /* i : full band excitation */ float output[], /* o : high band speech - 14.0 to 20 kHz */ const float fb_exc_energy, /* i : full band excitation energy */ - const float ratio_float, /* i : energy ratio */ + const float ratio_float, /* i : energy ratio */ const int16_t L_frame, /* i : ACELP frame length */ const int16_t bfi, /* i : BFI flag */ float *prev_fbbwe_ratio, /* o : previous frame energy for FEC */ diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index dea9b6a63..e93fdc57c 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -5,8 +5,8 @@ #include #include "options.h" -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ #include "prot.h" #include "prot_fx1.h" #include "prot_fx2.h" @@ -15,27 +15,26 @@ #include "ivas_prot_fx.h" #endif -#define POW_EXC16k_WHTND 1.14e11f /* power of random excitation, length 320 samples, uniform distribution */ -#define POW_EXC16k_WHTND_FX_INV_SQRT 6360 //Q31 -#define POW_EXC16k_WHTND_FX 178125000 //Q-6 +#define POW_EXC16k_WHTND 1.14e11f /* power of random excitation, length 320 samples, uniform distribution */ +#define POW_EXC16k_WHTND_FX_INV_SQRT 6360 // Q31 +#define POW_EXC16k_WHTND_FX 178125000 // Q-6 /*-----------------------------------------------------------------* -* Local function prototypes -*-----------------------------------------------------------------*/ + * Local function prototypes + *-----------------------------------------------------------------*/ static void create_random_vector_fx( Word16 output[], const Word16 length, Word16 seed[] ); static void flip_spectrum_fx( const Word16 input[], Word16 output[], const Word16 length ); -static void Calc_st_filt_tbe(Word16 * apond2,Word16 * apond1,Word16 * parcor0,Word16 * sig_ltp_ptr,Word16 * mem_zero ); +static void Calc_st_filt_tbe( Word16 *apond2, Word16 *apond1, Word16 *parcor0, Word16 *sig_ltp_ptr, Word16 *mem_zero ); static void Hilbert_transform_fx( Word32 tmp_R[], Word32 tmp_I[], Word32 *tmpi_R, Word32 *tmpi_I, const Word16 length, const Word16 HB_stage_id ); -static void Hilbert_transform_sp_fx( Word16 tmp_R[], Word16 tmp_I[], Word32 *tmpi_R, Word32 *tmpi_I, const Word16 length, const Word16 HB_stage_id ); -void Estimate_mix_factors_fx( const Word16 *shb_res, const Word16 Q_shb, const Word16 *exc16kWhtnd, const Word16 Q_bwe_exc, const Word16 *White_exc16k_frac, - const Word16 Q_frac, const Word32 pow1, const Word16 Q_pow1, const Word32 pow22, const Word16 Q_pow22, Word16 *vf_modified, Word16 *vf_ind ); +static void Hilbert_transform_sp_fx( Word16 tmp_R[], Word16 tmp_I[], Word32 *tmpi_R, Word32 *tmpi_I, const Word16 length, const Word16 HB_stage_id ); +void Estimate_mix_factors_fx( const Word16 *shb_res, const Word16 Q_shb, const Word16 *exc16kWhtnd, const Word16 Q_bwe_exc, const Word16 *White_exc16k_frac, const Word16 Q_frac, const Word32 pow1, const Word16 Q_pow1, const Word32 pow22, const Word16 Q_pow22, Word16 *vf_modified, Word16 *vf_ind ); /*-------------------------------------------------------------------* -* swb_tbe_reset() -* -* Reset the SWB TBE encoder -*-------------------------------------------------------------------*/ + * swb_tbe_reset() + * + * Reset the SWB TBE encoder + *-------------------------------------------------------------------*/ void swb_tbe_reset_fx( Word32 mem_csfilt[], @@ -43,14 +42,13 @@ void swb_tbe_reset_fx( Word16 state_lpc_syn[], Word16 syn_overlap[], Word16 state_syn_shbexc[], - Word16* tbe_demph, - Word16* tbe_premph, - Word16 mem_stp_swb[], - Word16* gain_prec_swb -) + Word16 *tbe_demph, + Word16 *tbe_premph, + Word16 mem_stp_swb[], + Word16 *gain_prec_swb ) { set32_fx( mem_csfilt, 0, 2 ); - set16_fx( mem_genSHBexc_filt_down_shb, 0, (2*ALLPASSSECTIONS_STEEP+1)); + set16_fx( mem_genSHBexc_filt_down_shb, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); set16_fx( state_lpc_syn, 0, LPC_SHB_ORDER ); set16_fx( syn_overlap, 0, L_SHB_LAHEAD ); @@ -61,19 +59,19 @@ void swb_tbe_reset_fx( *tbe_premph = 0; move16(); - set16_fx(mem_stp_swb, 0, LPC_SHB_ORDER); + set16_fx( mem_stp_swb, 0, LPC_SHB_ORDER ); *gain_prec_swb = 16384; - move16();/*Q14 = 1 */ + move16(); /*Q14 = 1 */ return; } /*-------------------------------------------------------------------* -* swb_tbe_reset_synth() -* -* Reset the extra parameters needed for synthesis of the SWB TBE output -*-------------------------------------------------------------------*/ + * swb_tbe_reset_synth() + * + * Reset the extra parameters needed for synthesis of the SWB TBE output + *-------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED void swb_tbe_reset_synth_ivas_fx( @@ -83,8 +81,8 @@ void swb_tbe_reset_synth_ivas_fx( { set32_fx( genSHBsynth_Hilbert_Mem, 0, HILBERT_MEM_SIZE ); - set16_fx( genSHBsynth_state_lsyn_filt_shb_local_fx, 0, 2*ALLPASSSECTIONS_STEEP ); - set32_fx( genSHBsynth_state_lsyn_filt_shb_local_fx_32, 0, 2*ALLPASSSECTIONS_STEEP ); + set16_fx( genSHBsynth_state_lsyn_filt_shb_local_fx, 0, 2 * ALLPASSSECTIONS_STEEP ); + set32_fx( genSHBsynth_state_lsyn_filt_shb_local_fx_32, 0, 2 * ALLPASSSECTIONS_STEEP ); return; } @@ -95,7 +93,7 @@ void swb_tbe_reset_synth_fx( { set32_fx( genSHBsynth_Hilbert_Mem, 0, HILBERT_MEM_SIZE ); - set16_fx( genSHBsynth_state_lsyn_filt_shb_local_fx, 0, 2*ALLPASSSECTIONS_STEEP ); + set16_fx( genSHBsynth_state_lsyn_filt_shb_local_fx, 0, 2 * ALLPASSSECTIONS_STEEP ); return; } @@ -110,8 +108,7 @@ void swb_tbe_reset_synth_fx( void fb_tbe_reset_synth_fx( Word32 fbbwe_hpf_mem_fx[][4], Word16 fbbwe_hpf_mem_fx_Q[], - Word16 *prev_fbbwe_ratio_fx -) + Word16 *prev_fbbwe_ratio_fx ) { set32_fx( fbbwe_hpf_mem_fx[0], 0, 4 ); set32_fx( fbbwe_hpf_mem_fx[1], 0, 4 ); @@ -132,53 +129,53 @@ void fb_tbe_reset_synth_fx( *-------------------------------------------------------------------*/ Word16 tbe_celp_exc_offset( - const Word16 T0_fx, /* i : Integer pitch */ - const Word16 T0_frac_fx, /* i : Fractional part of the pitch */ - const Word16 L_frame /* i : frame lenght */ + const Word16 T0_fx, /* i : Integer pitch */ + const Word16 T0_frac_fx, /* i : Fractional part of the pitch */ + const Word16 L_frame /* i : frame lenght */ ) { Word16 offset_fx, tmp_fx, tmp1_fx, tmp2_fx, tmp_fac; tmp_fac = 320; - move16(); /*2.5 in Q7*/ - if(EQ_16(L_frame, L_FRAME16k)) + move16(); /*2.5 in Q7*/ + if ( EQ_16( L_frame, L_FRAME16k ) ) { tmp_fac = 256; move16(); /*2.0 in Q7*/ } - tmp_fx = extract_l(L_mult(T0_frac_fx,32));/*Q8, 0.25 in Q7*/ - tmp_fx = add(512,tmp_fx);/*Q8; 2 in Q8*/ - tmp_fx = mult_r(tmp_fx,tmp_fac);/*Q16->Q0; 2.5 in Q7 or 2.0 in Q7 */ + tmp_fx = extract_l( L_mult( T0_frac_fx, 32 ) ); /*Q8, 0.25 in Q7*/ + tmp_fx = add( 512, tmp_fx ); /*Q8; 2 in Q8*/ + tmp_fx = mult_r( tmp_fx, tmp_fac ); /*Q16->Q0; 2.5 in Q7 or 2.0 in Q7 */ - tmp1_fx = sub(T0_fx,2);/*Q0*/ + tmp1_fx = sub( T0_fx, 2 ); /*Q0*/ - tmp2_fx = shl(tmp1_fx,1);/*Q0 */ + tmp2_fx = shl( tmp1_fx, 1 ); /*Q0 */ - IF(EQ_16(L_frame, L_FRAME)) + IF( EQ_16( L_frame, L_FRAME ) ) { - tmp2_fx = add(shl(tmp1_fx,1),shr(tmp1_fx,1));/*Q0; (5/2 = 2 + 1/2)*/ + tmp2_fx = add( shl( tmp1_fx, 1 ), shr( tmp1_fx, 1 ) ); /*Q0; (5/2 = 2 + 1/2)*/ } - offset_fx = add(tmp_fx,tmp2_fx);/*Q0*/ + offset_fx = add( tmp_fx, tmp2_fx ); /*Q0*/ return offset_fx; } /*-------------------------------------------------------------------* -* swb_tbe_celp_exc() -* -* Compute tbe bwe celp excitation -*-------------------------------------------------------------------*/ + * swb_tbe_celp_exc() + * + * Compute tbe bwe celp excitation + *-------------------------------------------------------------------*/ void tbe_celp_exc( - const Word16 L_frame_fx, /* i : Frame lenght */ - const Word16 i_subfr_fx, /* i : sub frame */ - const Word16 T0_fx, /* i : Integer pitch */ - const Word16 T0_frac_fx, /* i : Fractional part of the pitch */ - Word16 *error_fx, /* i/o: Error */ - Word16 *bwe_exc_fx /* i/o: bandwitdh extension signal */ + const Word16 L_frame_fx, /* i : Frame lenght */ + const Word16 i_subfr_fx, /* i : sub frame */ + const Word16 T0_fx, /* i : Integer pitch */ + const Word16 T0_frac_fx, /* i : Fractional part of the pitch */ + Word16 *error_fx, /* i/o: Error */ + Word16 *bwe_exc_fx /* i/o: bandwitdh extension signal */ ) { Word16 offset_fx, tmp_fx, i; - IF( EQ_16(L_frame_fx,L_FRAME)) + IF( EQ_16( L_frame_fx, L_FRAME ) ) { /*offset = T0 * HIBND_ACB_L_FAC + (int) ((float) T0_frac * 0.25f * HIBND_ACB_L_FAC + 2 * HIBND_ACB_L_FAC + 0.5f) - 2 * HIBND_ACB_L_FAC; for (i=0; i0) + offset_fx = tbe_celp_exc_offset( T0_fx, T0_frac_fx, L_frame_fx ); + IF( *error_fx > 0 ) { - tmp_fx = shr(*error_fx,5);/*Q0*/ + tmp_fx = shr( *error_fx, 5 ); /*Q0*/ } ELSE { - tmp_fx = negate(shr(abs_s(*error_fx),5));/*Q0*/ + tmp_fx = negate( shr( abs_s( *error_fx ), 5 ) ); /*Q0*/ } - FOR (i=0; i0) + offset_fx = tbe_celp_exc_offset( T0_fx, T0_frac_fx, L_frame_fx ); + IF( *error_fx > 0 ) { - tmp_fx = shr(*error_fx,5);/*Q0*/ + tmp_fx = shr( *error_fx, 5 ); /*Q0*/ } ELSE { - tmp_fx = negate(shr(abs_s(*error_fx),5));/*Q0*/ + tmp_fx = negate( shr( abs_s( *error_fx ), 5 ) ); /*Q0*/ } - FOR (i=0; i 0) + offset_fx = tbe_celp_exc_offset( T0_fx, T0_frac_fx, L_frame_fx ); + IF( *error_fx > 0 ) { - tmp_fx = shr(*error_fx, 5);/*Q0*/ + tmp_fx = shr( *error_fx, 5 ); /*Q0*/ } ELSE { - tmp_fx = negate(shr(abs_s(*error_fx),5));/*Q0*/ + tmp_fx = negate( shr( abs_s( *error_fx ), 5 ) ); /*Q0*/ } - FOR(i = 0; i < L_subfr * HIBND_ACB_L_FAC; i++) + FOR( i = 0; i < L_subfr * HIBND_ACB_L_FAC; i++ ) { bwe_exc_fx[i + i_subfr_fx * HIBND_ACB_L_FAC] = bwe_exc_fx[i + i_subfr_fx * HIBND_ACB_L_FAC - offset_fx + tmp_fx]; move16(); } - tmp_fx = extract_l(L_mult(T0_frac_fx, 1));/*Q3; 0.25 in Q2*/ - tmp_fx = add(shl(T0_fx, 3), tmp_fx);/*Q3*/ - tmp_fx = extract_l(L_mult(tmp_fx, 5));/*Q5, 2.5 in Q1*/ - tmp_fx = sub(shl(offset_fx, 5), tmp_fx);/*Q5*/ - *error_fx = add(*error_fx, tmp_fx);/*Q5*/ + tmp_fx = extract_l( L_mult( T0_frac_fx, 1 ) ); /*Q3; 0.25 in Q2*/ + tmp_fx = add( shl( T0_fx, 3 ), tmp_fx ); /*Q3*/ + tmp_fx = extract_l( L_mult( tmp_fx, 5 ) ); /*Q5, 2.5 in Q1*/ + tmp_fx = sub( shl( offset_fx, 5 ), tmp_fx ); /*Q5*/ + *error_fx = add( *error_fx, tmp_fx ); /*Q5*/ } ELSE { @@ -300,28 +297,28 @@ void tbe_celp_exc_ivas( /* offset = T0*2 + (int) ((float) T0_frac * 0.25f*2 + 2*2 + 0.5f) - 2*2; - case here*/ /*(int) ((float) T0_frac * 0.25f*2 + 2*2 + 0.5f)*/ - offset_fx = tbe_celp_exc_offset(T0_fx, T0_frac_fx, L_frame_fx); - IF(*error_fx > 0) + offset_fx = tbe_celp_exc_offset( T0_fx, T0_frac_fx, L_frame_fx ); + IF( *error_fx > 0 ) { - tmp_fx = shr(*error_fx,5);/*Q0*/ + tmp_fx = shr( *error_fx, 5 ); /*Q0*/ } ELSE { - tmp_fx = negate(shr(abs_s(*error_fx),5));/*Q0*/ + tmp_fx = negate( shr( abs_s( *error_fx ), 5 ) ); /*Q0*/ } - FOR(i = 0; i < L_subfr * 2; i++) + FOR( i = 0; i < L_subfr * 2; i++ ) { bwe_exc_fx[i + i_subfr_fx * 2] = bwe_exc_fx[i + i_subfr_fx * 2 - offset_fx + tmp_fx]; move16(); } /* error += (float) offset - (float) T0 * 2 - 0.5f * (float) T0_frac;*/ - tmp_fx = extract_l(L_mult(T0_frac_fx,2));/*Q3; 0.5 in Q2*/ - tmp_fx = add(shl(T0_fx,4),tmp_fx);/* now tmp_fx = "T0_fx*2+ 0.5f*T0_frac_fx" in Q3*/ - tmp_fx = shl(tmp_fx,2);/*now above tmp_fx in Q5*/ - tmp_fx = sub(shl(offset_fx,5),tmp_fx);/*move offset_fx to Q5, tmp_fx in Q5, ans tmp_fx in Q5*/ - *error_fx = add(*error_fx,tmp_fx);/*error_fx in Q5*/ + tmp_fx = extract_l( L_mult( T0_frac_fx, 2 ) ); /*Q3; 0.5 in Q2*/ + tmp_fx = add( shl( T0_fx, 4 ), tmp_fx ); /* now tmp_fx = "T0_fx*2+ 0.5f*T0_frac_fx" in Q3*/ + tmp_fx = shl( tmp_fx, 2 ); /*now above tmp_fx in Q5*/ + tmp_fx = sub( shl( offset_fx, 5 ), tmp_fx ); /*move offset_fx to Q5, tmp_fx in Q5, ans tmp_fx in Q5*/ + *error_fx = add( *error_fx, tmp_fx ); /*error_fx in Q5*/ } } @@ -352,13 +349,13 @@ void tbe_celp_exc_ivas( /* _ None */ /*---------------------------------------------------------------------------*/ void flip_and_downmix_generic_fx( - Word16 input[], /* i : input spectrum Qx*/ - Word16 output[], /* o : output spectrum Qx*/ - const Word16 length, /* i : length of spectra */ - Word32 mem1_ext[HILBERT_ORDER1], /* i/o: memory Qx+16*/ - Word32 mem2_ext[2*HILBERT_ORDER2], /* i/o: memory Qx+16*/ - Word32 mem3_ext[2*HILBERT_ORDER2], /* i/o: memory Qx+16*/ - Word16* phase_state /* i/o: Phase state in case frequency isn't multiple of 50 Hz */ + Word16 input[], /* i : input spectrum Qx*/ + Word16 output[], /* o : output spectrum Qx*/ + const Word16 length, /* i : length of spectra */ + Word32 mem1_ext[HILBERT_ORDER1], /* i/o: memory Qx+16*/ + Word32 mem2_ext[2 * HILBERT_ORDER2], /* i/o: memory Qx+16*/ + Word32 mem3_ext[2 * HILBERT_ORDER2], /* i/o: memory Qx+16*/ + Word16 *phase_state /* i/o: Phase state in case frequency isn't multiple of 50 Hz */ ) { Word16 i, j; @@ -373,14 +370,12 @@ void flip_and_downmix_generic_fx( /*Word16 s_tmp[L_FRAME32k];*/ /*Word16 factor;*/ Word16 period; - Word16 local_negsin_table17[17] = { 0, -11793, -22005, -29268, -32609, -31580, - -26319, -17530, -6393, 6393, 17530, 26319, - 31580, 32609, 29268, 22005, 11793 - }; /* Q15 */ - Word16 local_cos_table17[17] = {32767, 30571, 24279, 14732, 3212, -8739, - -19519, -27683, -32137, -32137, -27683, - -19519, -8739, 3212, 14732, 24279, 30571 - }; /* Q15 */ + Word16 local_negsin_table17[17] = { 0, -11793, -22005, -29268, -32609, -31580, + -26319, -17530, -6393, 6393, 17530, 26319, + 31580, 32609, 29268, 22005, 11793 }; /* Q15 */ + Word16 local_cos_table17[17] = { 32767, 30571, 24279, 14732, 3212, -8739, + -19519, -27683, -32137, -32137, -27683, + -19519, -8739, 3212, 14732, 24279, 30571 }; /* Q15 */ Word16 *local_negsin_table, *local_cos_table; Word32 L_tmp; @@ -391,68 +386,68 @@ void flip_and_downmix_generic_fx( local_cos_table = local_cos_table17; - FOR (i = 0; i < length; i = i + 2 ) + FOR( i = 0; i < length; i = i + 2 ) { input[i] = negate( input[i] ); move16(); } - Copy(input, tmp_16 + HILBERT_ORDER1, length ); + Copy( input, tmp_16 + HILBERT_ORDER1, length ); /*Copy32( mem1_ext, tmp_16, 5 ); */ - FOR (i=0; i= period ) { @@ -465,15 +460,15 @@ void flip_and_downmix_generic_fx( j = *phase_state; move16(); - WHILE ( i < length ) + WHILE( i < length ) { - WHILE ( ( j < period ) && ( i < length ) ) + WHILE( ( j < period ) && ( i < length ) ) { - L_tmp = Mult_32_16( tmp_R[i + 4], local_cos_table[j] ); /*//Qx+16 */ + L_tmp = Mult_32_16( tmp_R[i + 4], local_cos_table[j] ); /*//Qx+16 */ L_tmp = Madd_32_16( L_tmp, tmp_I[i + 4], local_negsin_table[j] ); /*Qx+16 */ - output[i] = round_fx( L_tmp ); /*Qx */ - i++ ; - j++ ; + output[i] = round_fx( L_tmp ); /*Qx */ + i++; + j++; } if ( j >= period ) @@ -492,22 +487,22 @@ void flip_and_downmix_generic_fx( /*---------------------------------------------- * Hilbert transform - Double precision *------------------------------------------------*/ -static void Hilbert_transform_fx( - Word32 tmp_R[], /* i: Real component of HB */ - Word32 tmp_I[], /* i: Real component of HB */ - Word32 tmpi_R[], /* o: Real component of HB */ - Word32 tmpi_I[], /* o: Imag. component of HB */ - const Word16 length, /* i: input length */ - const Word16 HB_stage_id /* i: HB transform stage */ +static void Hilbert_transform_fx( + Word32 tmp_R[], /* i: Real component of HB */ + Word32 tmp_I[], /* i: Real component of HB */ + Word32 tmpi_R[], /* o: Real component of HB */ + Word32 tmpi_I[], /* o: Imag. component of HB */ + const Word16 length, /* i: input length */ + const Word16 HB_stage_id /* i: HB transform stage */ ) { Word16 i, hb_filter_stage, offset; Word32 L_tmp; - hb_filter_stage = 2*HB_stage_id; + hb_filter_stage = 2 * HB_stage_id; offset = 0; move16(); - if( HB_stage_id == 0 ) + if ( HB_stage_id == 0 ) { offset = 1; move16(); @@ -515,36 +510,36 @@ static void Hilbert_transform_fx( test(); test(); - IF (HB_stage_id == 0 || HB_stage_id == 2) + IF( HB_stage_id == 0 || HB_stage_id == 2 ) { - FOR ( i = 0; i < length; i++ ) + FOR( i = 0; i < length; i++ ) { - L_tmp = Mult_32_16( tmp_R[i + 4], Hilbert_coeffs_fx[hb_filter_stage][0 + offset] ); /*Qx+15 */ - L_tmp = Madd_32_16( L_tmp, tmp_R[i + 2], Hilbert_coeffs_fx[hb_filter_stage][2 + offset] ); /*Qx+15 */ - L_tmp = Madd_32_16( L_tmp, tmp_R[i] , Hilbert_coeffs_fx[hb_filter_stage][4 + offset] );/*Qx+15 */ + L_tmp = Mult_32_16( tmp_R[i + 4], Hilbert_coeffs_fx[hb_filter_stage][0 + offset] ); /*Qx+15 */ + L_tmp = Madd_32_16( L_tmp, tmp_R[i + 2], Hilbert_coeffs_fx[hb_filter_stage][2 + offset] ); /*Qx+15 */ + L_tmp = Madd_32_16( L_tmp, tmp_R[i], Hilbert_coeffs_fx[hb_filter_stage][4 + offset] ); /*Qx+15 */ tmpi_R[i] = L_shl( L_tmp, 1 ); move32(); /*Qx+16 */ - L_tmp = Mult_32_16( tmp_I[i + 4 + offset], Hilbert_coeffs_fx[hb_filter_stage+1][0] ); /*Qx+15 */ - L_tmp = Madd_32_16( L_tmp, tmp_I[i + 2 + offset], Hilbert_coeffs_fx[hb_filter_stage+1][2] ); /*Qx+15 */ - L_tmp = Madd_32_16( L_tmp, tmp_I[i + offset] , Hilbert_coeffs_fx[hb_filter_stage+1][4] ); /*Qx+15 */ + L_tmp = Mult_32_16( tmp_I[i + 4 + offset], Hilbert_coeffs_fx[hb_filter_stage + 1][0] ); /*Qx+15 */ + L_tmp = Madd_32_16( L_tmp, tmp_I[i + 2 + offset], Hilbert_coeffs_fx[hb_filter_stage + 1][2] ); /*Qx+15 */ + L_tmp = Madd_32_16( L_tmp, tmp_I[i + offset], Hilbert_coeffs_fx[hb_filter_stage + 1][4] ); /*Qx+15 */ tmpi_I[i] = L_shl( L_tmp, 1 ); move32(); /*Qx+16 */ } } - ELSE IF (HB_stage_id == 1 || HB_stage_id == 3) + ELSE IF( HB_stage_id == 1 || HB_stage_id == 3 ) { - FOR ( i = 0; i < length; i++ ) + FOR( i = 0; i < length; i++ ) { - L_tmp = Mult_32_16( tmpi_R[i + 2], Hilbert_coeffs_fx[hb_filter_stage][2] ); /*Qx+15 */ - L_tmp = Madd_32_16( L_tmp, tmpi_R[i] , Hilbert_coeffs_fx[hb_filter_stage][4] ); /*Qx+15 */ - tmpi_R[i + 4] = L_sub( tmp_R[i], L_shl( L_tmp, 1 ) ); - move32();/*Qx+16 */ + L_tmp = Mult_32_16( tmpi_R[i + 2], Hilbert_coeffs_fx[hb_filter_stage][2] ); /*Qx+15 */ + L_tmp = Madd_32_16( L_tmp, tmpi_R[i], Hilbert_coeffs_fx[hb_filter_stage][4] ); /*Qx+15 */ + tmpi_R[i + 4] = L_sub( tmp_R[i], L_shl( L_tmp, 1 ) ); + move32(); /*Qx+16 */ - L_tmp = Mult_32_16( tmpi_I[i + 2], Hilbert_coeffs_fx[hb_filter_stage+1][2] ); /*Qx+15 */ - L_tmp = Madd_32_16( L_tmp, tmpi_I[i] , Hilbert_coeffs_fx[hb_filter_stage+1][4] ); /*Qx+15 */ - tmpi_I[i + 4] = L_sub( tmp_I[i], L_shl( L_tmp, 1 ) ); + L_tmp = Mult_32_16( tmpi_I[i + 2], Hilbert_coeffs_fx[hb_filter_stage + 1][2] ); /*Qx+15 */ + L_tmp = Madd_32_16( L_tmp, tmpi_I[i], Hilbert_coeffs_fx[hb_filter_stage + 1][4] ); /*Qx+15 */ + tmpi_I[i + 4] = L_sub( tmp_I[i], L_shl( L_tmp, 1 ) ); move32(); /*Qx+16 */ } } @@ -552,42 +547,42 @@ static void Hilbert_transform_fx( /*---------------------------------------------- -* Hilbert transform - Single precision Stage 0 -*------------------------------------------------*/ -static void Hilbert_transform_sp_fx( - Word16 tmp_R[], /* i: Real component of HB */ - Word16 tmp_I[], /* i: Real component of HB */ - Word32 tmpi_R[], /* o: Real component of HB */ - Word32 tmpi_I[], /* o: Imag. component of HB */ - const Word16 length, /* i: input length */ - const Word16 HB_stage_id /* i: HB transform stage */ + * Hilbert transform - Single precision Stage 0 + *------------------------------------------------*/ +static void Hilbert_transform_sp_fx( + Word16 tmp_R[], /* i: Real component of HB */ + Word16 tmp_I[], /* i: Real component of HB */ + Word32 tmpi_R[], /* o: Real component of HB */ + Word32 tmpi_I[], /* o: Imag. component of HB */ + const Word16 length, /* i: input length */ + const Word16 HB_stage_id /* i: HB transform stage */ ) { Word16 i, hb_filter_stage, offset; Word32 L_tmp; - hb_filter_stage = shl(HB_stage_id,1); + hb_filter_stage = shl( HB_stage_id, 1 ); offset = 0; move16(); - if( HB_stage_id == 0 ) + if ( HB_stage_id == 0 ) { offset = 1; move16(); } /* Hilbert single precision stage 0 */ - FOR ( i = 0; i < length; i++ ) + FOR( i = 0; i < length; i++ ) { - L_tmp = L_mult( tmp_R[i + 4], Hilbert_coeffs_fx[hb_filter_stage][0 + offset] ); /*Qx */ - L_tmp = L_mac ( L_tmp, tmp_R[i + 2], Hilbert_coeffs_fx[hb_filter_stage][2 + offset] ); /*Qx */ - L_tmp = L_mac ( L_tmp, tmp_R[i] , Hilbert_coeffs_fx[hb_filter_stage][4 + offset] ); /*Qx */ - tmpi_R[i] = L_shl ( L_tmp, 1 ); + L_tmp = L_mult( tmp_R[i + 4], Hilbert_coeffs_fx[hb_filter_stage][0 + offset] ); /*Qx */ + L_tmp = L_mac( L_tmp, tmp_R[i + 2], Hilbert_coeffs_fx[hb_filter_stage][2 + offset] ); /*Qx */ + L_tmp = L_mac( L_tmp, tmp_R[i], Hilbert_coeffs_fx[hb_filter_stage][4 + offset] ); /*Qx */ + tmpi_R[i] = L_shl( L_tmp, 1 ); move32(); /*Qx+16 */ - L_tmp = L_mult( tmp_I[i + 4 + offset], Hilbert_coeffs_fx[hb_filter_stage+1][0] ); /*Qx */ - L_tmp = L_mac ( L_tmp, tmp_I[i + 2 + offset], Hilbert_coeffs_fx[hb_filter_stage+1][2] ); /*Qx */ - L_tmp = L_mac ( L_tmp, tmp_I[i + offset] , Hilbert_coeffs_fx[hb_filter_stage+1][4] ); /*Qx */ - tmpi_I[i] = L_shl ( L_tmp, 1 ); + L_tmp = L_mult( tmp_I[i + 4 + offset], Hilbert_coeffs_fx[hb_filter_stage + 1][0] ); /*Qx */ + L_tmp = L_mac( L_tmp, tmp_I[i + 2 + offset], Hilbert_coeffs_fx[hb_filter_stage + 1][2] ); /*Qx */ + L_tmp = L_mac( L_tmp, tmp_I[i + offset], Hilbert_coeffs_fx[hb_filter_stage + 1][4] ); /*Qx */ + tmpi_I[i] = L_shl( L_tmp, 1 ); move32(); /*Qx+16 */ } @@ -599,14 +594,14 @@ static void Hilbert_transform_sp_fx( * flip_spectrum_fx *----------------------------------------------*/ void flip_spectrum_fx( - const Word16 input[], /* i : input spectrum */ - Word16 output[], /* o : output spectrum */ - const Word16 length /* i : vector length */ + const Word16 input[], /* i : input spectrum */ + Word16 output[], /* o : output spectrum */ + const Word16 length /* i : vector length */ ) { Word16 i; - FOR ( i = 0; i < length; i = i + 2 ) + FOR( i = 0; i < length; i = i + 2 ) { output[i] = negate( input[i] ); move16(); @@ -624,8 +619,8 @@ void flip_spectrum_fx( * computes 1st parcor from composed filter impulse response *---------------------------------------------------------------------------*/ void Calc_rc0_h( - Word16 * h, /* i : impulse response of composed filter */ - Word16 * rc0 /* o : 1st parcor */ + Word16 *h, /* i : impulse response of composed filter */ + Word16 *rc0 /* o : 1st parcor */ ) { Word32 L_acc; @@ -635,58 +630,58 @@ void Calc_rc0_h( Word16 i; /* computation of the autocorrelation function acf */ - L_acc = L_mult(h[0], h[0]); - FOR(i = 1; i < LONG_H_ST; i++) + L_acc = L_mult( h[0], h[0] ); + FOR( i = 1; i < LONG_H_ST; i++ ) { - L_acc = L_mac(L_acc, h[i], h[i]); + L_acc = L_mac( L_acc, h[i], h[i] ); } - sh_acf = norm_l(L_acc); - L_acc = L_shl(L_acc, sh_acf); - acf0 = extract_h(L_acc); + sh_acf = norm_l( L_acc ); + L_acc = L_shl( L_acc, sh_acf ); + acf0 = extract_h( L_acc ); ptrs = h; temp = *ptrs++; move16(); - L_acc = L_mult(temp, *ptrs); - FOR(i = 1; i < LONG_H_ST - 1; i++) + L_acc = L_mult( temp, *ptrs ); + FOR( i = 1; i < LONG_H_ST - 1; i++ ) { temp = *ptrs++; move16(); - L_acc = L_mac(L_acc, temp, *ptrs); + L_acc = L_mac( L_acc, temp, *ptrs ); } - L_acc = L_shl(L_acc, sh_acf); - acf1 = extract_h(L_acc); + L_acc = L_shl( L_acc, sh_acf ); + acf1 = extract_h( L_acc ); /* Compute 1st parcor */ - if (acf0 == 0) + if ( acf0 == 0 ) { *rc0 = 0; move16(); return; } - IF (LT_16(acf0, abs_s(acf1))) + IF( LT_16( acf0, abs_s( acf1 ) ) ) { *rc0 = 0; move16(); return; } - *rc0 = div_s(abs_s(acf1), acf0); + *rc0 = div_s( abs_s( acf1 ), acf0 ); move16(); - if (acf1 > 0) + if ( acf1 > 0 ) { - *rc0 = negate(*rc0); + *rc0 = negate( *rc0 ); move16(); } } static void Calc_st_filt_tbe( - Word16 * apond2, /* i : coefficients of numerator */ - Word16 * apond1, /* i : coefficients of denominator */ - Word16 * parcor0, /* o : 1st parcor calcul. on composed filter */ - Word16 * sig_ltp_ptr, /* i/o: i of 1/A(gamma1) : scaled by 1/g0 */ - Word16 * mem_zero /* i : All zero memory */ + Word16 *apond2, /* i : coefficients of numerator */ + Word16 *apond1, /* i : coefficients of denominator */ + Word16 *parcor0, /* o : 1st parcor calcul. on composed filter */ + Word16 *sig_ltp_ptr, /* i/o: i of 1/A(gamma1) : scaled by 1/g0 */ + Word16 *mem_zero /* i : All zero memory */ ) { Word32 L_g0; @@ -697,141 +692,140 @@ static void Calc_st_filt_tbe( Word16 i; temp = sub( 2, norm_s( apond2[0] ) ); /* compute i.r. of composed filter apond2 / apond1 */ - Syn_filt_s(temp, apond1, LPC_SHB_ORDER, apond2, h, LONG_H_ST, mem_zero, 0); + Syn_filt_s( temp, apond1, LPC_SHB_ORDER, apond2, h, LONG_H_ST, mem_zero, 0 ); /* compute 1st parcor */ - Calc_rc0_h(h, parcor0); + Calc_rc0_h( h, parcor0 ); /* compute g0 */ - L_g0 = L_mult0(1, abs_s(h[0])); - FOR (i = 1; i < LONG_H_ST; i++) + L_g0 = L_mult0( 1, abs_s( h[0] ) ); + FOR( i = 1; i < LONG_H_ST; i++ ) { - L_g0 = L_mac0(L_g0, 1, abs_s(h[i])); + L_g0 = L_mac0( L_g0, 1, abs_s( h[i] ) ); } - g0 = extract_h(L_shl(L_g0, 14)); + g0 = extract_h( L_shl( L_g0, 14 ) ); /* Scale signal i of 1/A(gamma1) */ - IF (GT_16(g0, 1024)) + IF( GT_16( g0, 1024 ) ) { - temp = div_s(1024, g0); /* temp = 2**15 / gain0 */ - FOR (i = 0; i < L_SUBFR16k; i++) + temp = div_s( 1024, g0 ); /* temp = 2**15 / gain0 */ + FOR( i = 0; i < L_SUBFR16k; i++ ) { - sig_ltp_ptr[i] = mult_r(sig_ltp_ptr[i], temp); + sig_ltp_ptr[i] = mult_r( sig_ltp_ptr[i], temp ); move16(); } } } static void filt_mu_fx( - const Word16 *sig_in, /* i : signal (beginning at sample -1) */ + const Word16 *sig_in, /* i : signal (beginning at sample -1) */ Word16 *sig_out, /* o : output signal */ - const Word16 parcor0, /* i : parcor0 (mu = parcor0 * gamma3) */ + const Word16 parcor0, /* i : parcor0 (mu = parcor0 * gamma3) */ Word16 SubFrameLength /* i : the length of subframe */ ) { Word16 n; Word16 mu, ga, temp; const Word16 *ptrs; - Word16 tmp,exp; + Word16 tmp, exp; - IF ( EQ_16(SubFrameLength ,L_SUBFR )) + IF( EQ_16( SubFrameLength, L_SUBFR ) ) { - IF (parcor0 > 0) + IF( parcor0 > 0 ) { - mu = mult_r(parcor0 , GAMMA3_PLUS_FX); + mu = mult_r( parcor0, GAMMA3_PLUS_FX ); } ELSE { - mu = mult_r(parcor0 , GAMMA3_MINUS_FX); + mu = mult_r( parcor0, GAMMA3_MINUS_FX ); } } ELSE { - IF(parcor0 > 0) + IF( parcor0 > 0 ) { - mu = mult_r( parcor0 , GAMMA3_PLUS_WB_FX); + mu = mult_r( parcor0, GAMMA3_PLUS_WB_FX ); } ELSE { - mu = mult_r( parcor0 , GAMMA3_MINUS_WB_FX); + mu = mult_r( parcor0, GAMMA3_MINUS_WB_FX ); } } - tmp = abs_s(mu); - tmp = sub(32767 , tmp); - exp = norm_s(tmp); - tmp = div_s(shl(1,sub(14,exp)),tmp);/*(14 - exp) */ - ga = shl_sat(tmp ,exp);/*Q14 */ + tmp = abs_s( mu ); + tmp = sub( 32767, tmp ); + exp = norm_s( tmp ); + tmp = div_s( shl( 1, sub( 14, exp ) ), tmp ); /*(14 - exp) */ + ga = shl_sat( tmp, exp ); /*Q14 */ /* ga = (float) 1. / ((float) 1. - (float) fabs (mu)); */ - ptrs = sig_in; /* points on sig_in(-1) */ + ptrs = sig_in; /* points on sig_in(-1) */ - FOR (n = 0; n < SubFrameLength; n++) + FOR( n = 0; n < SubFrameLength; n++ ) { - temp = mult_r(mu , (*ptrs++)); - temp = add (temp ,*ptrs );/*Q12 */ - sig_out[n] = shl(mult_r( ga , temp),1); - move16();/*Q12 */ + temp = mult_r( mu, ( *ptrs++ ) ); + temp = add( temp, *ptrs ); /*Q12 */ + sig_out[n] = shl( mult_r( ga, temp ), 1 ); + move16(); /*Q12 */ } return; } static void scale_st_swb( - const Word16 * sig_in_fx, /* i : postfilter i signal */ - Word16 * sig_out_fx, /* i/o: postfilter o signal */ - Word16 * gain_prec_fx, /* i/o: last value of gain for subframe */ - Word16 SubFrameLength -) + const Word16 *sig_in_fx, /* i : postfilter i signal */ + Word16 *sig_out_fx, /* i/o: postfilter o signal */ + Word16 *gain_prec_fx, /* i/o: last value of gain for subframe */ + Word16 SubFrameLength ) { Word16 i; Word16 agc_fac1_para_fx; Word16 agc_fac_para_fx; - Word32 L_acc,L_temp; + Word32 L_acc, L_temp; Word16 g0_fx, gain_fx; Word16 scal_in, scal_out; - Word16 s_g_in, s_g_out,sh_g0,temp; + Word16 s_g_in, s_g_out, sh_g0, temp; - IF ( EQ_16(SubFrameLength ,L_SUBFR )) + IF( EQ_16( SubFrameLength, L_SUBFR ) ) { agc_fac1_para_fx = AGC_FAC1_FX; move16(); - agc_fac_para_fx = AGC_FAC_FX; + agc_fac_para_fx = AGC_FAC_FX; move16(); } ELSE /*IF( SubFrameLength == L_SUBFR16k ) */ { - agc_fac1_para_fx = AGC_FAC1_WB_FX; + agc_fac1_para_fx = AGC_FAC1_WB_FX; move16(); - agc_fac_para_fx = AGC_FAC_WB_FX; + agc_fac_para_fx = AGC_FAC_WB_FX; move16(); } /* compute input gain */ - L_acc = L_mult0(1, abs_s(sig_in_fx[0]));/*0 +Q_bwe_exc-1 */ - FOR (i = 1; i < SubFrameLength; i++) + L_acc = L_mult0( 1, abs_s( sig_in_fx[0] ) ); /*0 +Q_bwe_exc-1 */ + FOR( i = 1; i < SubFrameLength; i++ ) { - L_acc = L_mac0(L_acc, 1, abs_s(sig_in_fx[i])); /*Q_bwe_exc-1 */ + L_acc = L_mac0( L_acc, 1, abs_s( sig_in_fx[i] ) ); /*Q_bwe_exc-1 */ } g0_fx = 0; move16(); - IF (L_acc != 0L) + IF( L_acc != 0L ) { - scal_in = norm_l(L_acc); - L_acc = L_shl(L_acc, scal_in); - s_g_in = extract_h(L_acc); /* normalized */ + scal_in = norm_l( L_acc ); + L_acc = L_shl( L_acc, scal_in ); + s_g_in = extract_h( L_acc ); /* normalized */ /* Compute o gain */ - L_acc = L_mult0(1, abs_s(sig_out_fx[0])); - FOR (i = 1; i < SubFrameLength; i++) + L_acc = L_mult0( 1, abs_s( sig_out_fx[0] ) ); + FOR( i = 1; i < SubFrameLength; i++ ) { - L_acc = L_mac0(L_acc, 1, abs_s(sig_out_fx[i])); + L_acc = L_mac0( L_acc, 1, abs_s( sig_out_fx[i] ) ); } - IF (L_acc == 0L) + IF( L_acc == 0L ) { *gain_prec_fx = 0; move16(); @@ -839,48 +833,48 @@ static void scale_st_swb( return; } - scal_out = norm_l(L_acc); - L_acc = L_shl(L_acc, scal_out); - s_g_out = extract_h(L_acc); /* normalized */ + scal_out = norm_l( L_acc ); + L_acc = L_shl( L_acc, scal_out ); + s_g_out = extract_h( L_acc ); /* normalized */ - sh_g0 = add(scal_in, 1); - sh_g0 = sub(sh_g0, scal_out); /* scal_in - scal_out + 1 */ - IF (LT_16(s_g_in, s_g_out)) + sh_g0 = add( scal_in, 1 ); + sh_g0 = sub( sh_g0, scal_out ); /* scal_in - scal_out + 1 */ + IF( LT_16( s_g_in, s_g_out ) ) { - g0_fx = div_s(s_g_in, s_g_out); /* s_g_in/s_g_out in Q15 */ + g0_fx = div_s( s_g_in, s_g_out ); /* s_g_in/s_g_out in Q15 */ } ELSE { - temp = sub(s_g_in, s_g_out); /* sufficient since normalized */ - g0_fx = shr(div_s(temp, s_g_out), 1); - g0_fx = add(g0_fx, (Word16) 0x4000); /* s_g_in/s_g_out in Q14 */ - sh_g0 = sub(sh_g0, 1); + temp = sub( s_g_in, s_g_out ); /* sufficient since normalized */ + g0_fx = shr( div_s( temp, s_g_out ), 1 ); + g0_fx = add( g0_fx, (Word16) 0x4000 ); /* s_g_in/s_g_out in Q14 */ + sh_g0 = sub( sh_g0, 1 ); } /* L_gain_in/L_gain_out in Q14 */ /* overflows if L_gain_in > 2 * L_gain_out */ - g0_fx = shr_sat(g0_fx, sh_g0); /* sh_g0 may be >0, <0, or =0 */ //Need to verify? + g0_fx = shr_sat( g0_fx, sh_g0 ); /* sh_g0 may be >0, <0, or =0 */ // Need to verify? - g0_fx = mult_r(g0_fx, agc_fac1_para_fx); /* L_gain_in/L_gain_out * AGC_FAC1_FX */ + g0_fx = mult_r( g0_fx, agc_fac1_para_fx ); /* L_gain_in/L_gain_out * AGC_FAC1_FX */ } /* compute gain(n) = AGC_FAC gain(n-1) + (1-AGC_FAC)gain_in/gain_out */ /* sig_out(n) = gain(n) sig_out(n) */ gain_fx = *gain_prec_fx; move16(); /*14 */ - FOR (i = 0; i < SubFrameLength; i++) + FOR( i = 0; i < SubFrameLength; i++ ) { - temp = mult_r(agc_fac_para_fx, gain_fx);/*15 +14 -15 =14 */ - gain_fx = add(temp, g0_fx); /* in Q14 */ - L_temp = L_mult(gain_fx, sig_out_fx[i]);/*14 + Q_bwe_exc-1 +1 = 14 + Q_bwe_exc */ + temp = mult_r( agc_fac_para_fx, gain_fx ); /*15 +14 -15 =14 */ + gain_fx = add( temp, g0_fx ); /* in Q14 */ + L_temp = L_mult( gain_fx, sig_out_fx[i] ); /*14 + Q_bwe_exc-1 +1 = 14 + Q_bwe_exc */ #ifdef BASOP_NOGLOB - L_temp = L_shl_sat(L_temp, 1); /*14 + Q_bwe_exc +1 */ - sig_out_fx[i] = round_fx_sat(L_temp); /*Q_bwe_exc +15 -16 = Q_bwe_exc-1 */ + L_temp = L_shl_sat( L_temp, 1 ); /*14 + Q_bwe_exc +1 */ + sig_out_fx[i] = round_fx_sat( L_temp ); /*Q_bwe_exc +15 -16 = Q_bwe_exc-1 */ #else - L_temp = L_shl(L_temp, 1); /*14 + Q_bwe_exc +1 */ - sig_out_fx[i] = round_fx(L_temp); /*Q_bwe_exc +15 -16 = Q_bwe_exc-1 */ + L_temp = L_shl( L_temp, 1 ); /*14 + Q_bwe_exc +1 */ + sig_out_fx[i] = round_fx( L_temp ); /*Q_bwe_exc +15 -16 = Q_bwe_exc-1 */ #endif } - *gain_prec_fx =gain_fx; + *gain_prec_fx = gain_fx; move16(); return; @@ -897,31 +891,31 @@ void PostShortTerm_fx( const Word16 formant_fac_fx /* i : Strength of post-filter*/ ) { - Word16 apond1_fx[LPC_SHB_ORDER+1]; /* denominator coeff.*/ - Word16 apond2_fx[LONG_H_ST]; /* numerator coeff. */ - Word16 sig_ltp_fx[L_SUBFR16k +1]; /* residual signal */ + Word16 apond1_fx[LPC_SHB_ORDER + 1]; /* denominator coeff.*/ + Word16 apond2_fx[LONG_H_ST]; /* numerator coeff. */ + Word16 sig_ltp_fx[L_SUBFR16k + 1]; /* residual signal */ /*Word16 lpccoeff_fx[LPC_SHB_ORDER+1];//Q12 */ - Word16 g1_fx,g2_fx,parcor0_fx; /*Q15 */ + Word16 g1_fx, g2_fx, parcor0_fx; /*Q15 */ Word16 tmp; parcor0_fx = 0; move16(); - set16_fx( apond1_fx, 0, LPC_SHB_ORDER+1 ); + set16_fx( apond1_fx, 0, LPC_SHB_ORDER + 1 ); set16_fx( apond2_fx, 0, LONG_H_ST ); - set16_fx( sig_ltp_fx, 0, L_SUBFR16k+1 ); + set16_fx( sig_ltp_fx, 0, L_SUBFR16k + 1 ); /* Obtain post-filter weights */ - tmp = extract_h(L_mult(GAMMA_SHARP_FX,formant_fac_fx));/*Q15 */ - g1_fx = add(GAMMA0_FX,tmp);/*Q15 */ - g2_fx = sub(GAMMA0_FX,tmp);/*Q15 */ + tmp = extract_h( L_mult( GAMMA_SHARP_FX, formant_fac_fx ) ); /*Q15 */ + g1_fx = add( GAMMA0_FX, tmp ); /*Q15 */ + g2_fx = sub( GAMMA0_FX, tmp ); /*Q15 */ /* Compute weighted LPC coefficients */ - weight_a_fx(lpccoeff, apond1_fx, g1_fx, LPC_SHB_ORDER); - weight_a_fx(lpccoeff, apond2_fx, g2_fx, LPC_SHB_ORDER); + weight_a_fx( lpccoeff, apond1_fx, g1_fx, LPC_SHB_ORDER ); + weight_a_fx( lpccoeff, apond2_fx, g2_fx, LPC_SHB_ORDER ); /* o: apond1_fx, apond2_fx in Q12 */ /* Compute A(gamma2) residual */ - Residu3_10_fx( apond2_fx, sig_in, sig_ltp_fx+1, L_SUBFR16k, 0 ); + Residu3_10_fx( apond2_fx, sig_in, sig_ltp_fx + 1, L_SUBFR16k, 0 ); /* o: sig_ltp_fx in Q_bwe_exc */ /* Save last output of 1/A(gamma1) */ @@ -929,43 +923,43 @@ void PostShortTerm_fx( move16(); /* Control short term pst filter gain and compute parcor0 */ - Calc_st_filt_tbe(apond2_fx, apond1_fx, &parcor0_fx, sig_ltp_fx+1, mem_zero); + Calc_st_filt_tbe( apond2_fx, apond1_fx, &parcor0_fx, sig_ltp_fx + 1, mem_zero ); /* o: parcor0 in Q15 */ /* i/o: sig_ltp_fx in Q_bwe_exc */ /* 1/A(gamma1) filtering, mem_stp is updated */ - Syn_filt_s(0,apond1_fx,LPC_SHB_ORDER,sig_ltp_fx+1,sig_ltp_fx+1,L_SUBFR16k,mem_stp,1); + Syn_filt_s( 0, apond1_fx, LPC_SHB_ORDER, sig_ltp_fx + 1, sig_ltp_fx + 1, L_SUBFR16k, mem_stp, 1 ); /* (1 + mu z-1) tilt filtering */ - filt_mu_fx(sig_ltp_fx, sig_out, parcor0_fx, L_SUBFR16k); + filt_mu_fx( sig_ltp_fx, sig_out, parcor0_fx, L_SUBFR16k ); /* o: sig_out in Q_bwe_exc */ /* gain control */ - scale_st_swb(sig_in, sig_out, ptr_gain_prec, L_SUBFR16k ); + scale_st_swb( sig_in, sig_out, ptr_gain_prec, L_SUBFR16k ); return; } void flip_spectrum_and_decimby4_fx( - const Word16 input[], /* i : input spectrum Q_inp */ - Word16 output[], /* o : output spectrum Q_inp */ - const Word16 length, /* i : vector length */ - Word16 mem1[], /* i/o : memory Q_inp */ - Word16 mem2[], /* i/o : memory Q_inp */ - const Word16 ramp_flag /*i: flag to trigger slow ramp-up of output following change of core (HQ to ACELP or 12k8 to 16k ACELP) */ + const Word16 input[], /* i : input spectrum Q_inp */ + Word16 output[], /* o : output spectrum Q_inp */ + const Word16 length, /* i : vector length */ + Word16 mem1[], /* i/o : memory Q_inp */ + Word16 mem2[], /* i/o : memory Q_inp */ + const Word16 ramp_flag /*i: flag to trigger slow ramp-up of output following change of core (HQ to ACELP or 12k8 to 16k ACELP) */ ) { Word16 i; - Word16 factor, tmp[L_FRAME16k/2]; + Word16 factor, tmp[L_FRAME16k / 2]; Word16 tmp1, tmp2; Word16 input_change[L_FRAME16k]; - IF ( ramp_flag ) + IF( ramp_flag ) { factor = div_s( 4, length ); /* Q15 */ - FOR ( i = 0; i < length / 4; i += 2) + FOR( i = 0; i < length / 4; i += 2 ) { - tmp1 = extract_l( L_mult0( i, factor ) ); /* Q15 */ + tmp1 = extract_l( L_mult0( i, factor ) ); /* Q15 */ tmp2 = extract_l( L_mult0( add( i, 1 ), factor ) ); /*Q15 */ input_change[i] = negate( mult_r( input[i], tmp1 ) ); move16(); @@ -979,7 +973,7 @@ void flip_spectrum_and_decimby4_fx( move16(); } - FOR (; i < length; i = i + 2 ) + FOR( ; i < length; i = i + 2 ) { input_change[i] = negate( input[i] ); move16(); @@ -1166,7 +1160,7 @@ void ivas_GenShapedWBExcitation_fx( { #ifdef BASOP_NOGLOB L_tmp = L_mult_o( excTmp2_frac[i], excTmp2_frac[i], &Overflow ); /* Q29 */ - pow1 = L_add_o( pow1, L_shr( L_tmp, 10 ), &Overflow ); /* Q22 */ + pow1 = L_add_o( pow1, L_shr( L_tmp, 10 ), &Overflow ); /* Q22 */ #else L_tmp = L_mult( excTmp2_frac[i], excTmp2_frac[i] ); /* Q29 */ pow1 = L_add( pow1, L_shr( L_tmp, 7 ) ); /* Q22 */ @@ -1312,44 +1306,44 @@ void ivas_GenShapedWBExcitation_fx( } #endif -void GenShapedWBExcitation_fx( - Word16* excSHB, /* o : synthesized shaped shb exctiation Q_bwe_exc*/ - const Word16* lpc_shb, /* i : lpc coefficients Q12*/ - Word16* exc4kWhtnd, /* o : whitened synthesized shb excitation Q_bwe_exc*/ - Word32* mem_csfilt, /* i/o : memory Q_bwe_exc+16*/ - Word16* mem_genSHBexc_filt_down1, /* i/o : memory Q_bwe_exc*/ - Word16* mem_genSHBexc_filt_down2, /* i/o : memory Q_bwe_exc*/ - Word16* mem_genSHBexc_filt_down3, /* i/o : memory Q_bwe_exc*/ - Word16* state_lpc_syn, /* i/o : memory Q_bwe_exc*/ - const Word16 coder_type, /* i : coding type */ - const Word16* bwe_exc_extended, /* i : bwidth extended exciatation Q_bwe_exc*/ - const Word16 Q_bwe_exc, Word16 bwe_seed[], /* i/o : random number generator seed */ - const Word16 voice_factors[], /* i : voicing factor Q15*/ - const Word16 uv_flag, /* i : unvoiced flag */ - const Word16 igf_flag -) +void GenShapedWBExcitation_fx( + Word16 *excSHB, /* o : synthesized shaped shb exctiation Q_bwe_exc*/ + const Word16 *lpc_shb, /* i : lpc coefficients Q12*/ + Word16 *exc4kWhtnd, /* o : whitened synthesized shb excitation Q_bwe_exc*/ + Word32 *mem_csfilt, /* i/o : memory Q_bwe_exc+16*/ + Word16 *mem_genSHBexc_filt_down1, /* i/o : memory Q_bwe_exc*/ + Word16 *mem_genSHBexc_filt_down2, /* i/o : memory Q_bwe_exc*/ + Word16 *mem_genSHBexc_filt_down3, /* i/o : memory Q_bwe_exc*/ + Word16 *state_lpc_syn, /* i/o : memory Q_bwe_exc*/ + const Word16 coder_type, /* i : coding type */ + const Word16 *bwe_exc_extended, /* i : bwidth extended exciatation Q_bwe_exc*/ + const Word16 Q_bwe_exc, + Word16 bwe_seed[], /* i/o : random number generator seed */ + const Word16 voice_factors[], /* i : voicing factor Q15*/ + const Word16 uv_flag, /* i : unvoiced flag */ + const Word16 igf_flag ) { Word16 i, j, k; - Word16 wht_fil_mem [ LPC_WHTN_ORDER_WB ]; - Word16 lpc_whtn[ LPC_WHTN_ORDER_WB + 1]; + Word16 wht_fil_mem[LPC_WHTN_ORDER_WB]; + Word16 lpc_whtn[LPC_WHTN_ORDER_WB + 1]; Word16 R_h[LPC_WHTN_ORDER_WB + 2], R_l[LPC_WHTN_ORDER_WB + 2]; Word16 Q_R; - Word16 excTmp[ L_FRAME16k]; - Word16 excTmp2[ L_FRAME16k / 4]; - Word16 excTmp2_frac[ L_FRAME16k / 4]; - Word16 exc4k[ L_FRAME16k / 4]; - Word16 exc4k_frac[ L_FRAME16k / 4]; - Word32 exc4k_32[ L_FRAME16k / 4]; + Word16 excTmp[L_FRAME16k]; + Word16 excTmp2[L_FRAME16k / 4]; + Word16 excTmp2_frac[L_FRAME16k / 4]; + Word16 exc4k[L_FRAME16k / 4]; + Word16 exc4k_frac[L_FRAME16k / 4]; + Word32 exc4k_32[L_FRAME16k / 4]; Word32 pow1, pow22; Word16 scale; - Word32 excNoisyEnv[ L_FRAME16k / 4]; - Word16 csfilt_num2[1] = {1638}; /* Q15*/ - Word16 neg_csfilt_den2[2] = {-32768, 31457}; /* Q15 */ + Word32 excNoisyEnv[L_FRAME16k / 4]; + Word16 csfilt_num2[1] = { 1638 }; /* Q15*/ + Word16 neg_csfilt_den2[2] = { -32768, 31457 }; /* Q15 */ Word32 L_tmp, Ltemp1, Ltemp2; Word16 temp1, temp2, exp; Word32 Lmax; Word16 max_val, n1, n2, sc; - Word32 LepsP[LPC_WHTN_ORDER_WB+1]; + Word32 LepsP[LPC_WHTN_ORDER_WB + 1]; Word16 tmp_vfac; Word16 avg_voice_fac; #ifdef BASOP_NOGLOB_DECLARE_LOCAL @@ -1357,71 +1351,71 @@ void GenShapedWBExcitation_fx( #endif /*0.25f*sum_f(voice_factors, NB_SUBFR)*/ - L_tmp = L_mult(voice_factors[0], 8192); - FOR (i=1; i 0.35f*/ + IF( igf_flag != 0 && ( EQ_16( coder_type, VOICED ) || GT_16( avg_voice_fac, 11469 ) ) ) /*Q15 -> 0.35f*/ { csfilt_num2[0] = 6554; - move16(); /*Q15 -> 0.2f*/ + move16(); /*Q15 -> 0.2f*/ neg_csfilt_den2[1] = 26214; - move16(); /*Q15 -> 0.8f*/ + move16(); /*Q15 -> 0.8f*/ } - ELSE IF( igf_flag != 0 && ( EQ_16(coder_type, UNVOICED)||LT_16(avg_voice_fac,6654))) /*Q15 -> 0.2f*/ + ELSE IF( igf_flag != 0 && ( EQ_16( coder_type, UNVOICED ) || LT_16( avg_voice_fac, 6654 ) ) ) /*Q15 -> 0.2f*/ { csfilt_num2[0] = 328; - move16(); /*Q15 -> 0.01f*/ + move16(); /*Q15 -> 0.01f*/ neg_csfilt_den2[1] = 32440; - move16(); /*Q15 -> 0.99f*/ + move16(); /*Q15 -> 0.99f*/ } set16_fx( wht_fil_mem, 0, LPC_WHTN_ORDER_WB ); - Decimate_allpass_steep_fx( bwe_exc_extended, mem_genSHBexc_filt_down1, L_FRAME32k, excTmp ); + Decimate_allpass_steep_fx( bwe_exc_extended, mem_genSHBexc_filt_down1, L_FRAME32k, excTmp ); flip_spectrum_and_decimby4_fx( excTmp, exc4k, L_FRAME16k, mem_genSHBexc_filt_down2, mem_genSHBexc_filt_down3, 0 ); - IF ( uv_flag ) + IF( uv_flag ) { create_random_vector_fx( exc4kWhtnd, L_FRAME16k / 4, bwe_seed ); - IF ( LT_16( Q_bwe_exc, 5 )) + IF( LT_16( Q_bwe_exc, 5 ) ) { - FOR ( i = 0; i < L_FRAME16k / 4; i++ ) + FOR( i = 0; i < L_FRAME16k / 4; i++ ) { - exc4kWhtnd[i] = shl_r( exc4kWhtnd[i], sub( Q_bwe_exc, 5 ) );/*Q(Q_bwe_exc)/Q5(if Q_bwe_exc > 5) */ + exc4kWhtnd[i] = shl_r( exc4kWhtnd[i], sub( Q_bwe_exc, 5 ) ); /*Q(Q_bwe_exc)/Q5(if Q_bwe_exc > 5) */ } } } ELSE { autocorr_fx( exc4k, LPC_WHTN_ORDER_WB + 1, R_h, R_l, &Q_R, - L_FRAME16k / 4, win_flatten_4k_fx, 0, 1 ); + L_FRAME16k / 4, win_flatten_4k_fx, 0, 1 ); /* Ensure R[0] isn't zero when entering Levinson Durbin */ R_l[0] = s_max( R_l[0], 1 ); move16(); - FOR ( i = 1; i <= LPC_WHTN_ORDER_WB; i++ ) + FOR( i = 1; i <= LPC_WHTN_ORDER_WB; i++ ) { L_tmp = Mpy_32( R_h[i], R_l[i], wac_h[i - 1], wac_l[i - 1] ); L_Extract( L_tmp, &R_h[i], &R_l[i] ); } - E_LPC_lev_dur(R_h, R_l, lpc_whtn, LepsP, LPC_WHTN_ORDER_WB, NULL); + E_LPC_lev_dur( R_h, R_l, lpc_whtn, LepsP, LPC_WHTN_ORDER_WB, NULL ); - Copy_Scale_sig( lpc_whtn, lpc_whtn, LPC_WHTN_ORDER_WB+1, sub(norm_s(lpc_whtn[0]),2) ); + Copy_Scale_sig( lpc_whtn, lpc_whtn, LPC_WHTN_ORDER_WB + 1, sub( norm_s( lpc_whtn[0] ), 2 ) ); fir_fx( exc4k, lpc_whtn, exc4kWhtnd, wht_fil_mem, L_FRAME16k / 4, - LPC_WHTN_ORDER_WB, 0, 3 ); + LPC_WHTN_ORDER_WB, 0, 3 ); /* Ensure pow1 is greater than zero when computing normalization */ max_val = 0; - FOR ( i = 0; i < L_FRAME16k / 4; i++ ) + FOR( i = 0; i < L_FRAME16k / 4; i++ ) { excTmp2[i] = abs_s( exc4kWhtnd[i] ); move16(); /* Q_bwe_exc */ @@ -1429,7 +1423,7 @@ void GenShapedWBExcitation_fx( move16(); } - IF ( max_val == 0 ) + IF( max_val == 0 ) { pow1 = 1; move16(); @@ -1439,7 +1433,7 @@ void GenShapedWBExcitation_fx( ELSE { n1 = norm_s( max_val ); - FOR ( i = 0; i < L_FRAME16k / 4; i++ ) + FOR( i = 0; i < L_FRAME16k / 4; i++ ) { #ifdef BASOP_NOGLOB excTmp2_frac[i] = shl_o( excTmp2[i], n1, &Overflow ); @@ -1450,42 +1444,42 @@ void GenShapedWBExcitation_fx( } n1 = sub( sub( 14, n1 ), Q_bwe_exc ); pow1 = 1; - FOR ( i = 0; i < L_FRAME16k / 4; i++ ) + FOR( i = 0; i < L_FRAME16k / 4; i++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_mult_o( excTmp2_frac[i], excTmp2_frac[i], &Overflow); /* Q29 */ - pow1 = L_add_o( pow1, L_shr( L_tmp, 7 ), &Overflow); /* Q22 */ + L_tmp = L_mult_o( excTmp2_frac[i], excTmp2_frac[i], &Overflow ); /* Q29 */ + pow1 = L_add_o( pow1, L_shr( L_tmp, 7 ), &Overflow ); /* Q22 */ #else L_tmp = L_mult( excTmp2_frac[i], excTmp2_frac[i] ); /* Q29 */ - pow1 = L_add( pow1, L_shr( L_tmp, 7 ) ); /* Q22 */ + pow1 = L_add( pow1, L_shr( L_tmp, 7 ) ); /* Q22 */ #endif } } - FOR ( i = 0; i < L_FRAME16k / 4; i++ ) + FOR( i = 0; i < L_FRAME16k / 4; i++ ) { #ifdef BASOP_NOGLOB - excNoisyEnv[i] = L_add_o( *mem_csfilt, L_mult_o( csfilt_num2[0], excTmp2[i], &Overflow ), &Overflow); + excNoisyEnv[i] = L_add_o( *mem_csfilt, L_mult_o( csfilt_num2[0], excTmp2[i], &Overflow ), &Overflow ); #else excNoisyEnv[i] = L_add( *mem_csfilt, L_mult( csfilt_num2[0], excTmp2[i] ) ); #endif - move32(); /* Q_bwe_exc+16 */ + move32(); /* Q_bwe_exc+16 */ *mem_csfilt = Mult_32_16( excNoisyEnv[i], neg_csfilt_den2[1] ); - move32(); /* Q_bwe_exc+16 */ + move32(); /* Q_bwe_exc+16 */ } create_random_vector_fx( exc4k, L_FRAME16k / 4, bwe_seed ); /* Ensure pow22 is greater than zero when computing normalization */ Lmax = 0; - FOR ( i = 0; i < L_FRAME16k / 4; i++ ) + FOR( i = 0; i < L_FRAME16k / 4; i++ ) { exc4k_32[i] = Mult_32_16( excNoisyEnv[i], exc4k[i] ); - move32();/* Q_bwe_exc+6 */ + move32(); /* Q_bwe_exc+6 */ Lmax = L_max( Lmax, L_abs( exc4k_32[i] ) ); } - IF ( Lmax == 0 ) + IF( Lmax == 0 ) { pow22 = 1; move16(); @@ -1496,43 +1490,43 @@ void GenShapedWBExcitation_fx( ELSE { n2 = norm_l( Lmax ); - FOR ( i = 0; i < L_FRAME16k / 4; i++ ) + FOR( i = 0; i < L_FRAME16k / 4; i++ ) { #ifdef BASOP_NOGLOB exc4k_frac[i] = extract_h( L_shl_o( exc4k_32[i], n2, &Overflow ) ); /* Q(14-n2) */ #else - exc4k_frac[i] = extract_h( L_shl( exc4k_32[i], n2 ) ); /* Q(14-n2) */ + exc4k_frac[i] = extract_h( L_shl( exc4k_32[i], n2 ) ); /* Q(14-n2) */ #endif } n2 = 30 - n2 - ( Q_bwe_exc + 6 ); pow22 = 1; - FOR ( i = 0; i < L_FRAME16k / 4; i++ ) + FOR( i = 0; i < L_FRAME16k / 4; i++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_mult_o( exc4k_frac[i], exc4k_frac[i], &Overflow); /* Q29 */ - pow22 = L_add_o( pow22, L_shr( L_tmp, 7 ), &Overflow); /* Q22 */ + L_tmp = L_mult_o( exc4k_frac[i], exc4k_frac[i], &Overflow ); /* Q29 */ + pow22 = L_add_o( pow22, L_shr( L_tmp, 7 ), &Overflow ); /* Q22 */ #else - L_tmp = L_mult( exc4k_frac[i], exc4k_frac[i] ); /* Q29 */ - pow22 = L_add( pow22, L_shr( L_tmp, 7 ) ); /* Q22 */ + L_tmp = L_mult( exc4k_frac[i], exc4k_frac[i] ); /* Q29 */ + pow22 = L_add( pow22, L_shr( L_tmp, 7 ) ); /* Q22 */ #endif } } test(); test(); - IF( EQ_16(coder_type, UNVOICED)||(igf_flag!=0&<_16(avg_voice_fac,6654))) + IF( EQ_16( coder_type, UNVOICED ) || ( igf_flag != 0 && LT_16( avg_voice_fac, 6654 ) ) ) { L_tmp = root_a_over_b_fx( pow1, sub( 22, shl( n1, 1 ) ), pow22, sub( 22, shl( n2, 1 ) ), &exp ); #ifdef BASOP_NOGLOB - scale = round_fx_o( L_shl_o( L_tmp, exp, &Overflow ), &Overflow); /*Q15 */ + scale = round_fx_o( L_shl_o( L_tmp, exp, &Overflow ), &Overflow ); /*Q15 */ #else - scale = round_fx( L_shl( L_tmp, exp ) ); /*Q15 */ + scale = round_fx( L_shl( L_tmp, exp ) ); /*Q15 */ #endif sc = sub( add( n2, Q_bwe_exc ), 14 ); - FOR ( i = 0; i < L_FRAME16k / 4; i++ ) + FOR( i = 0; i < L_FRAME16k / 4; i++ ) { #ifdef BASOP_NOGLOB - exc4kWhtnd[i] = round_fx_o( L_shl_o( L_mult_o( exc4k_frac[i], scale, &Overflow), sc, &Overflow), &Overflow); /* Q_bwe_exc+n2-10+16+ Q_bwe_exc + n2 -14 -16 = //Q_bwe_exc */ + exc4kWhtnd[i] = round_fx_o( L_shl_o( L_mult_o( exc4k_frac[i], scale, &Overflow ), sc, &Overflow ), &Overflow ); /* Q_bwe_exc+n2-10+16+ Q_bwe_exc + n2 -14 -16 = //Q_bwe_exc */ #else exc4kWhtnd[i] = round_fx( L_shl( L_mult( exc4k_frac[i], scale ), sc ) ); /* Q_bwe_exc+n2-10+16+ Q_bwe_exc + n2 -14 -16 = //Q_bwe_exc */ #endif @@ -1543,18 +1537,18 @@ void GenShapedWBExcitation_fx( sc = sub( add( n2, Q_bwe_exc ), 14 ); /* Q_bwe_exc+n2-14*/ k = 0; - FOR ( i = 0; i < 4; i++ ) + FOR( i = 0; i < 4; i++ ) { test(); - IF( igf_flag != 0 && EQ_16(coder_type, VOICED)) + IF( igf_flag != 0 && EQ_16( coder_type, VOICED ) ) { /*tmp_vfac = 2*voice_factors[i]; tmp_vfac = min(1, tmp_vfac);*/ #ifdef BASOP_NOGLOB - tmp_vfac = shl_o(voice_factors[i], 1, &Overflow); + tmp_vfac = shl_o( voice_factors[i], 1, &Overflow ); #else BASOP_SATURATE_WARNING_OFF_EVS - tmp_vfac = shl(voice_factors[i], 1); + tmp_vfac = shl( voice_factors[i], 1 ); BASOP_SATURATE_WARNING_ON_EVS #endif } @@ -1568,25 +1562,25 @@ void GenShapedWBExcitation_fx( #ifdef BASOP_NOGLOB temp1 = round_fx_o( L_shl_o( Ltemp1, exp, &Overflow ), &Overflow ); /* Q15 */ #else - temp1 = round_fx( L_shl( Ltemp1, exp ) ); /* Q15 */ + temp1 = round_fx( L_shl( Ltemp1, exp ) ); /* Q15 */ #endif L_tmp = Mult_32_16( pow1, sub( 32767, tmp_vfac ) ); /* Q22*/ Ltemp2 = root_a_over_b_fx( L_tmp, sub( 22, shl( n1, 1 ) ), pow22, sub( 22, shl( n2, 1 ) ), &exp ); #ifdef BASOP_NOGLOB temp2 = round_fx_o( L_shl_o( Ltemp2, exp, &Overflow ), &Overflow ); /* Q15 */ #else - temp2 = round_fx( L_shl( Ltemp2, exp ) ); /* Q15 */ + temp2 = round_fx( L_shl( Ltemp2, exp ) ); /* Q15 */ #endif - FOR ( j = 0; j < L_FRAME16k / 16; j++ ) + FOR( j = 0; j < L_FRAME16k / 16; j++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_mult_o( temp1, exc4kWhtnd[k], &Overflow );/* Q(16+Q_bwe_exc) */ - L_tmp = L_add_o( L_tmp, L_shl_o( L_mult_o( temp2, exc4k_frac[k], &Overflow), sc, &Overflow), &Overflow); /* Q(16+Q_bwe_exc) */ - exc4kWhtnd[k] = round_fx_o( L_tmp, &Overflow); /* Q_bwe_exc */ + L_tmp = L_mult_o( temp1, exc4kWhtnd[k], &Overflow ); /* Q(16+Q_bwe_exc) */ + L_tmp = L_add_o( L_tmp, L_shl_o( L_mult_o( temp2, exc4k_frac[k], &Overflow ), sc, &Overflow ), &Overflow ); /* Q(16+Q_bwe_exc) */ + exc4kWhtnd[k] = round_fx_o( L_tmp, &Overflow ); /* Q_bwe_exc */ #else - L_tmp = L_mult( temp1, exc4kWhtnd[k] );/* Q(16+Q_bwe_exc) */ + L_tmp = L_mult( temp1, exc4kWhtnd[k] ); /* Q(16+Q_bwe_exc) */ L_tmp = L_add( L_tmp, L_shl( L_mult( temp2, exc4k_frac[k] ), sc ) ); /* Q(16+Q_bwe_exc) */ - exc4kWhtnd[k] = round_fx( L_tmp ); /* Q_bwe_exc */ + exc4kWhtnd[k] = round_fx( L_tmp ); /* Q_bwe_exc */ #endif k++; } @@ -1597,22 +1591,21 @@ void GenShapedWBExcitation_fx( Syn_filt_s( 0, lpc_shb, LPC_SHB_ORDER_WB, exc4kWhtnd, excSHB, L_FRAME16k / 4, state_lpc_syn, 1 ); - return; } /*-------------------------------------------------------------------* -* GenWBSynth() -* -* Generate 16 KHz sampled highband component from synthesized highband -*-------------------------------------------------------------------*/ + * GenWBSynth() + * + * Generate 16 KHz sampled highband component from synthesized highband + *-------------------------------------------------------------------*/ void GenWBSynth_fx( - const Word16* input_synspeech, /* i : input synthesized speech Qx*/ - Word16* shb_syn_speech_16k, /* o : output highband compnent Qx*/ - Word16* state_lsyn_filt_shb1, /* i/o: memory Qx*/ - Word16* state_lsyn_filt_shb2 /* i/o: memory Qx*/ + const Word16 *input_synspeech, /* i : input synthesized speech Qx*/ + Word16 *shb_syn_speech_16k, /* o : output highband compnent Qx*/ + Word16 *state_lsyn_filt_shb1, /* i/o: memory Qx*/ + Word16 *state_lsyn_filt_shb2 /* i/o: memory Qx*/ ) { Word16 speech_buf_16k1[L_FRAME16k], speech_buf_16k2[L_FRAME16k]; @@ -1621,33 +1614,34 @@ void GenWBSynth_fx( maxm = 0; move16(); - FOR(i = 0; i 0 && len <= L_FRAME16k); + assert( len > 0 && len <= L_FRAME16k ); - K = (int16_t)(len_h / 2); /* length of FIR filter memory = half of the total filter length */ + K = (int16_t) ( len_h / 2 ); /* length of FIR filter memory = half of the total filter length */ w = 1.0f / len_h; /* MA filtering coefficient */ /* copy filter memory to the input buffer */ - if (mem_h != NULL) + if ( mem_h != NULL ) { - mvr2r(mem_h, buf_in, K); + mvr2r( mem_h, buf_in, K ); } else { /* no memory available, use the first len_h/2 samples as memory */ p_in = buf_in; - for (k = 0; k < K; k++) + for ( k = 0; k < K; k++ ) { - *p_in++ = (float)fabs(inp[k]) * w; + *p_in++ = (float) fabs( inp[k] ) * w; } } /* take the absolute value of the input signal and copy it to the input buffer */ /* multiply each value by 1 / filter length */ p_in = &buf_in[K]; - for (k = 0; k < len; k++) + for ( k = 0; k < len; k++ ) { - *p_in++ = (float)fabs(inp[k]) * w; + *p_in++ = (float) fabs( inp[k] ) * w; } /* update filter memory from the end of the input buffer */ - if (mem_h != NULL) + if ( mem_h != NULL ) { - mvr2r(&buf_in[len], mem_h, K); + mvr2r( &buf_in[len], mem_h, K ); } /* do MA filtering */ - out[0] = sum_f(buf_in, len_h); + out[0] = sum_f( buf_in, len_h ); p_out = &buf_in[0]; /* pointer to leaving sample */ p_in = &buf_in[len_h]; /* pointer to entering sample*/ - for (k = 1; k < len - K; k++) + for ( k = 1; k < len - K; k++ ) { out[k] = out[k - 1] - *p_out++ + *p_in++; } @@ -1710,9 +1704,9 @@ void find_td_envelope( p_in = &buf_in[len - K]; p_out = &out[len - K]; p_prev = p_out - 1; - for (k = 0; k < K; k++) + for ( k = 0; k < K; k++ ) { - *p_out++ = 0.05f * (*p_in++) + 0.95f * (*p_prev++); + *p_out++ = 0.05f * ( *p_in++ ) + 0.95f * ( *p_prev++ ); } return; @@ -1752,57 +1746,57 @@ void find_td_envelope( /* CALLED FROM : RX */ /*======================================================================================*/ void GenShapedSHBExcitation_fx( - Word16 *excSHB, /* o : synthesized shaped shb excitation Q_bwe_exc*/ - const Word16 *lpc_shb, /* i : lpc coefficients Q12*/ - Word16 *White_exc16k_FB, /* o : white excitation for the Fullband extension Q_bwe_exc */ - Word32 *mem_csfilt, /* i/o: memory */ - Word16 *mem_genSHBexc_filt_down_shb, /* i/o: memory */ - Word16 *state_lpc_syn, /* i/o: memory */ - const Word16 coder_type, /* i : coding type */ - const Word16 *bwe_exc_extended, /* i : bwidth extended excitation */ - Word16 bwe_seed[], /* i/o: random number generator seed */ - Word16 voice_factors[], /* i : voicing factor*/ - const Word16 extl, /* i : extension layer */ - Word16 *tbe_demph, /* i/o: de-emphasis memory */ - Word16 *tbe_premph, /* i/o: pre-emphasis memory */ - Word16 *lpc_shb_sf, /* i: LP coefficients */ - const Word32 shb_ener_sf_32, /* i: input shb ener, Q31 */ - Word16 *shb_res_gshape, /* i: input res gain shape, Q14 */ + Word16 *excSHB, /* o : synthesized shaped shb excitation Q_bwe_exc*/ + const Word16 *lpc_shb, /* i : lpc coefficients Q12*/ + Word16 *White_exc16k_FB, /* o : white excitation for the Fullband extension Q_bwe_exc */ + Word32 *mem_csfilt, /* i/o: memory */ + Word16 *mem_genSHBexc_filt_down_shb, /* i/o: memory */ + Word16 *state_lpc_syn, /* i/o: memory */ + const Word16 coder_type, /* i : coding type */ + const Word16 *bwe_exc_extended, /* i : bwidth extended excitation */ + Word16 bwe_seed[], /* i/o: random number generator seed */ + Word16 voice_factors[], /* i : voicing factor*/ + const Word16 extl, /* i : extension layer */ + Word16 *tbe_demph, /* i/o: de-emphasis memory */ + Word16 *tbe_premph, /* i/o: pre-emphasis memory */ + Word16 *lpc_shb_sf, /* i: LP coefficients */ + const Word32 shb_ener_sf_32, /* i: input shb ener, Q31 */ + Word16 *shb_res_gshape, /* i: input res gain shape, Q14 */ Word16 *shb_res, Word16 *vf_ind, - const Word16 formant_fac, /* i : Formant sharpening factor [0..1] */ - Word16 fb_state_lpc_syn[], /* i/o: memory */ - Word16 *fb_tbe_demph, /* i/o: fb de-emphasis memory */ + const Word16 formant_fac, /* i : Formant sharpening factor [0..1] */ + Word16 fb_state_lpc_syn[], /* i/o: memory */ + Word16 *fb_tbe_demph, /* i/o: fb de-emphasis memory */ Word16 *Q_bwe_exc, Word16 *Q_bwe_exc_fb, const Word16 Q_shb, - Word16 n_mem2, /* i : n_mem2 scale factor to adjust 24.4/32kbps memories */ - Word16 prev_Q_bwe_syn, /* i : st_fx->prev_Q_bwe_syn */ + Word16 n_mem2, /* i : n_mem2 scale factor to adjust 24.4/32kbps memories */ + Word16 prev_Q_bwe_syn, /* i : st_fx->prev_Q_bwe_syn */ const Word32 bitrate, const Word16 prev_bfi #ifdef ADD_IVAS_TBE_CODE - , /* i : previous frame was concealed */ - const Word16 element_mode, /* i : element mode */ - const Word16 flag_ACELP16k, /* i : ACELP@16kHz flag */ - Word16* nlExc16k, /* i/o: NL exc for IC-BWE */ - Word16* mixExc16k, /* i/o: exc spreading for IC-BWE */ - const Word32 extl_brate, /* i : extension layer bitarte */ - const Word16 MSFlag, /* i : Multi Source flag */ - Word16 EnvSHBres_4k[], /* i/o: TD envelope of the SHB residual signal */ - Word16* prev_pow_exc16kWhtnd, /* i/o: power of the LB excitation signal in the previous frame */ - Word16* prev_mix_factor, /* i/o: mixing factor in the previous frame */ - Word16* Env_error, /* o : error in SHB residual envelope modelling*/ - Word16 Env_error_part[] /* o : per-segment error in SHB residual envelope modelling */ + , /* i : previous frame was concealed */ + const Word16 element_mode, /* i : element mode */ + const Word16 flag_ACELP16k, /* i : ACELP@16kHz flag */ + Word16 *nlExc16k, /* i/o: NL exc for IC-BWE */ + Word16 *mixExc16k, /* i/o: exc spreading for IC-BWE */ + const Word32 extl_brate, /* i : extension layer bitarte */ + const Word16 MSFlag, /* i : Multi Source flag */ + Word16 EnvSHBres_4k[], /* i/o: TD envelope of the SHB residual signal */ + Word16 *prev_pow_exc16kWhtnd, /* i/o: power of the LB excitation signal in the previous frame */ + Word16 *prev_mix_factor, /* i/o: mixing factor in the previous frame */ + Word16 *Env_error, /* o : error in SHB residual envelope modelling*/ + Word16 Env_error_part[] /* o : per-segment error in SHB residual envelope modelling */ #endif ) { Word16 i, j, k; Word16 wht_fil_mem[LPC_WHTN_ORDER]; Word16 lpc_whtn[LPC_WHTN_ORDER + 1]; - Word16 R_h[LPC_WHTN_ORDER+ 2]; /* Autocorrelations of windowed speech MSB */ - Word16 R_l[LPC_WHTN_ORDER+ 2]; /* Autocorrelations of windowed speech LSB */ + Word16 R_h[LPC_WHTN_ORDER + 2]; /* Autocorrelations of windowed speech MSB */ + Word16 R_l[LPC_WHTN_ORDER + 2]; /* Autocorrelations of windowed speech LSB */ Word16 Q_R; - Word32 LepsP[LPC_WHTN_ORDER+1]; + Word32 LepsP[LPC_WHTN_ORDER + 1]; Word16 exc32k[L_FRAME32k], exc16k[L_FRAME16k]; Word32 pow1, pow22; Word16 scale, temp1, temp2; @@ -1810,8 +1804,8 @@ void GenShapedSHBExcitation_fx( Word16 excTmp2[L_FRAME16k]; Word16 *White_exc16k; Word16 excNoisyEnv[L_FRAME16k]; - Word16 csfilt_num2[1] = {6554}; /*0.2 in Q15 */ - Word16 neg_csfilt_den2[2] = {-32767, 26214}; /* {1.0f, -0.8f} */ + Word16 csfilt_num2[1] = { 6554 }; /*0.2 in Q15 */ + Word16 neg_csfilt_den2[2] = { -32767, 26214 }; /* {1.0f, -0.8f} */ Word16 varEnvShape; Word16 fb_deemph_fac = 15729; /*0.48f in Q15 */ Word16 exc16kWhtnd[L_FRAME16k]; @@ -1832,7 +1826,7 @@ void GenShapedSHBExcitation_fx( Word32 White_exc16k_32[L_FRAME16k]; Word16 Q_temp; Word16 prev_Q_bwe_exc_fb; - + #ifdef ADD_IVAS_TBE_CODE Word32 tempD; Word16 alpha, step, mem_csfilt_left, mem_csfilt_right, excNoisyEnvLeft[L_FRAME16k], excNoisyEnvRight[L_FRAME16k]; @@ -1850,16 +1844,16 @@ void GenShapedSHBExcitation_fx( set16_fx( zero_mem, 0, LPC_SHB_ORDER ); set16_fx( wht_fil_mem, 0, LPC_WHTN_ORDER ); - FOR(i = 0; i < L_FRAME32k; i=i+2) + FOR( i = 0; i < L_FRAME32k; i = i + 2 ) { - exc32k[i] = negate(bwe_exc_extended[i]); + exc32k[i] = negate( bwe_exc_extended[i] ); move16(); - exc32k[i+1] = bwe_exc_extended[i+1]; + exc32k[i + 1] = bwe_exc_extended[i + 1]; move16(); } /* Decimate by 2 */ - Decimate_allpass_steep_fx( exc32k, mem_genSHBexc_filt_down_shb, 2*L_FRAME16k, exc16k ); + Decimate_allpass_steep_fx( exc32k, mem_genSHBexc_filt_down_shb, 2 * L_FRAME16k, exc16k ); /* i: exc32k in Q_bwe_exc */ /* o: exc16k in Q_bwe_exc */ @@ -1867,48 +1861,48 @@ void GenShapedSHBExcitation_fx( /* Ensure R[0] isn't zero when entering Levinson Durbin */ R_l[0] = s_max( R_l[0], 1 ); move16(); - FOR ( i = 1; i <= LPC_WHTN_ORDER; i++ ) + FOR( i = 1; i <= LPC_WHTN_ORDER; i++ ) { L_tmp = Mpy_32( R_h[i], R_l[i], wac_h[i - 1], wac_l[i - 1] ); L_Extract( L_tmp, &R_h[i], &R_l[i] ); } - E_LPC_lev_dur(R_h, R_l, lpc_whtn, LepsP, LPC_WHTN_ORDER, NULL); - Copy_Scale_sig( lpc_whtn, lpc_whtn, LPC_WHTN_ORDER+1, sub(norm_s(lpc_whtn[0]),2) ); - fir_fx( exc16k, lpc_whtn, exc16kWhtnd, wht_fil_mem, L_FRAME16k, LPC_WHTN_ORDER, 0, 3 ); + E_LPC_lev_dur( R_h, R_l, lpc_whtn, LepsP, LPC_WHTN_ORDER, NULL ); + Copy_Scale_sig( lpc_whtn, lpc_whtn, LPC_WHTN_ORDER + 1, sub( norm_s( lpc_whtn[0] ), 2 ) ); + fir_fx( exc16k, lpc_whtn, exc16kWhtnd, wht_fil_mem, L_FRAME16k, LPC_WHTN_ORDER, 0, 3 ); /* i: exc16k in Q_bwe_exc */ /* o: exc16kWhtnd in Q_bwe_exc */ #ifdef ADD_IVAS_TBE_CODE - IF(GE_32(extl_brate, SWB_TBE_2k8)) + IF( GE_32( extl_brate, SWB_TBE_2k8 ) ) #else - IF(GE_32(bitrate, ACELP_24k40)) + IF( GE_32( bitrate, ACELP_24k40 ) ) #endif { temp2 = 0; move16(); - FOR(j = 0; j < 4; j++) + FOR( j = 0; j < 4; j++ ) { temp1 = shb_res_gshape[j]; move16(); - FOR(i = 0; i < 80; i++) + FOR( i = 0; i < 80; i++ ) { - exc16kWhtnd[temp2 + i] = round_fx(L_shl(L_mult( exc16kWhtnd[temp2 + i], temp1 ), 1)); + exc16kWhtnd[temp2 + i] = round_fx( L_shl( L_mult( exc16kWhtnd[temp2 + i], temp1 ), 1 ) ); /* exc16kWhtnd in Q_bwe_exc, shb_res_gshape in Q14 */ } - temp2 = add(temp2, 80); + temp2 = add( temp2, 80 ); } } /* Estimate pow1 associated with Low band nonlinear extended excitation */ /* pow1=0.00001f */ - tmp = sub(shl(*Q_bwe_exc, 1), 31); + tmp = sub( shl( *Q_bwe_exc, 1 ), 31 ); #ifdef BASOP_NOGLOB - pow1 = L_shl_sat(21475l/*0.00001f Q31*/, tmp); /* 0.00001f in 2*(Q_bwe_exc) */ + pow1 = L_shl_sat( 21475l /*0.00001f Q31*/, tmp ); /* 0.00001f in 2*(Q_bwe_exc) */ #else - pow1 = L_shl(21475l/*0.00001f Q31*/, tmp); /* 0.00001f in 2*(Q_bwe_exc) */ + pow1 = L_shl( 21475l /*0.00001f Q31*/, tmp ); /* 0.00001f in 2*(Q_bwe_exc) */ #endif - FOR( k = 0; k < L_FRAME16k; k++) + FOR( k = 0; k < L_FRAME16k; k++ ) { /*excTmp2[k ] = (float)(fabs(exc16kWhtnd[k]));*/ excTmp2[k] = abs_s( exc16kWhtnd[k] ); @@ -1916,57 +1910,57 @@ void GenShapedSHBExcitation_fx( /* pow1 += exc16kWhtnd[k] * exc16kWhtnd[k]; */ #ifdef BASOP_NOGLOB - pow1 = L_mac0_sat( pow1, exc16kWhtnd[k], exc16kWhtnd[k] ); /* 2*Q_bwe_exc */ + pow1 = L_mac0_sat( pow1, exc16kWhtnd[k], exc16kWhtnd[k] ); /* 2*Q_bwe_exc */ #else - pow1 = L_mac0( pow1, exc16kWhtnd[k], exc16kWhtnd[k] ); /* 2*Q_bwe_exc */ + pow1 = L_mac0( pow1, exc16kWhtnd[k], exc16kWhtnd[k] ); /* 2*Q_bwe_exc */ #endif } - Q_pow1 = shl(*Q_bwe_exc,1); + Q_pow1 = shl( *Q_bwe_exc, 1 ); test(); #ifdef ADD_IVAS_TBE_CODE - IF(EQ_16(flag_ACELP16k,0)) + IF( EQ_16( flag_ACELP16k, 0 ) ) #else - IF( (LE_32( bitrate, ACELP_13k20 ))&&(GE_32(bitrate,ACELP_7k20))) + IF( ( LE_32( bitrate, ACELP_13k20 ) ) && ( GE_32( bitrate, ACELP_7k20 ) ) ) #endif { /* varEnvShape = mean_fx(voice_factors, 4); */ /* unroll the loop */ - L_tmp = L_mult(voice_factors[0], 8192); - L_tmp = L_mac(L_tmp, voice_factors[1], 8192 ); - L_tmp = L_mac(L_tmp, voice_factors[2], 8192 ); - varEnvShape = mac_r(L_tmp, voice_factors[3], 8192 ); /* varEnvShape in Q15 */ + L_tmp = L_mult( voice_factors[0], 8192 ); + L_tmp = L_mac( L_tmp, voice_factors[1], 8192 ); + L_tmp = L_mac( L_tmp, voice_factors[2], 8192 ); + varEnvShape = mac_r( L_tmp, voice_factors[3], 8192 ); /* varEnvShape in Q15 */ } ELSE /* 16k core */ { /* varEnvShape = mean_fx(voice_factors, 5); */ /* unroll the loop */ - L_tmp = L_mult(voice_factors[0], 6554); - L_tmp = L_mac(L_tmp, voice_factors[1], 6554 ); - L_tmp = L_mac(L_tmp, voice_factors[2], 6554 ); - L_tmp = L_mac(L_tmp, voice_factors[3], 6554 ); - varEnvShape = mac_r(L_tmp, voice_factors[4], 6554 ); /* varEnvShape in Q15 */ + L_tmp = L_mult( voice_factors[0], 6554 ); + L_tmp = L_mac( L_tmp, voice_factors[1], 6554 ); + L_tmp = L_mac( L_tmp, voice_factors[2], 6554 ); + L_tmp = L_mac( L_tmp, voice_factors[3], 6554 ); + varEnvShape = mac_r( L_tmp, voice_factors[4], 6554 ); /* varEnvShape in Q15 */ } - IF ( EQ_16(extl, FB_TBE)) + IF( EQ_16( extl, FB_TBE ) ) { /*pow(varEnvShape,3) */ - tmp = mult_r(varEnvShape, varEnvShape); - tmp = mult_r(tmp, varEnvShape); + tmp = mult_r( varEnvShape, varEnvShape ); + tmp = mult_r( tmp, varEnvShape ); /* max_val((0.68f - (float)pow(varEnvShape, 3)), 0.48f); */ - fb_deemph_fac = sub(22282/*0.68f Q15*/, tmp); - fb_deemph_fac = s_max(fb_deemph_fac, 15729/*0.48f Q15*/); + fb_deemph_fac = sub( 22282 /*0.68f Q15*/, tmp ); + fb_deemph_fac = s_max( fb_deemph_fac, 15729 /*0.48f Q15*/ ); } /*varEnvShape = 1.09875f - 0.49875f * varEnvShape; */ - varEnvShape = msu_r(1179773824l/*0.549375f Q31*/, 8172/*0.249375f Q15*/, varEnvShape); + varEnvShape = msu_r( 1179773824l /*0.549375f Q31*/, 8172 /*0.249375f Q15*/, varEnvShape ); /*varEnvShape = min( max_val(varEnvShape, 0.6f), 0.999f); */ - varEnvShape = s_max(varEnvShape, 9830/*0.3f Q15*/); - varEnvShape = s_min(varEnvShape, 16368/*0.4995f Q15*/); - varEnvShape = shl(varEnvShape, 1); - csfilt_num2[0] = sub(MAX_16, varEnvShape); + varEnvShape = s_max( varEnvShape, 9830 /*0.3f Q15*/ ); + varEnvShape = s_min( varEnvShape, 16368 /*0.4995f Q15*/ ); + varEnvShape = shl( varEnvShape, 1 ); + csfilt_num2[0] = sub( MAX_16, varEnvShape ); move16(); neg_csfilt_den2[1] = varEnvShape; move16(); @@ -1975,28 +1969,28 @@ void GenShapedSHBExcitation_fx( test(); test(); #ifdef ADD_IVAS_TBE_CODE - IF (EQ_16(element_mode, EVS_MONO) && *mem_csfilt == 0 && ( (EQ_32( bitrate, ACELP_9k60 ))||(EQ_32(bitrate,ACELP_16k40))||(EQ_32(bitrate,ACELP_24k40)))) + IF( EQ_16( element_mode, EVS_MONO ) && *mem_csfilt == 0 && ( ( EQ_32( bitrate, ACELP_9k60 ) ) || ( EQ_32( bitrate, ACELP_16k40 ) ) || ( EQ_32( bitrate, ACELP_24k40 ) ) ) ) #else - IF ( *mem_csfilt == 0 && ( (EQ_32( bitrate, ACELP_9k60 ))||(EQ_32(bitrate,ACELP_16k40))||(EQ_32(bitrate,ACELP_24k40)))) + IF( *mem_csfilt == 0 && ( ( EQ_32( bitrate, ACELP_9k60 ) ) || ( EQ_32( bitrate, ACELP_16k40 ) ) || ( EQ_32( bitrate, ACELP_24k40 ) ) ) ) #endif { /* pre-init smoothing filter to avoid energy drop outs */ - L_tmp = L_mult(excTmp2[0], 1638); - FOR (i = 1; i < L_SUBFR16k/4; i++) + L_tmp = L_mult( excTmp2[0], 1638 ); + FOR( i = 1; i < L_SUBFR16k / 4; i++ ) { - L_tmp = L_mac(L_tmp, excTmp2[i], 1638); /*1638 = 1/20 in Q15*/ + L_tmp = L_mac( L_tmp, excTmp2[i], 1638 ); /*1638 = 1/20 in Q15*/ } /*L_tmp = sum(excTmp2, L_SUBFR16k/4)*(1/20) where L_SUBFR16k/4 =20 */ /* don't apply for FB in case the FB start-frame was potentially lost - White_exc16k is very sensitive to enery mismatch between enc - dec */ /* rather stick to the more conservative approach, to avoid potential clippings */ test(); - IF( !(prev_bfi && EQ_16(extl, FB_TBE))) + IF( !( prev_bfi && EQ_16( extl, FB_TBE ) ) ) { /* use weak smoothing for 1st frame after switching to make filter recover more quickly */ - varEnvShape = 26214/*0.8f Q15*/; + varEnvShape = 26214 /*0.8f Q15*/; move16(); - csfilt_num2[0] = sub(MAX_16, varEnvShape); + csfilt_num2[0] = sub( MAX_16, varEnvShape ); move16(); neg_csfilt_den2[1] = varEnvShape; move16(); @@ -2006,7 +2000,7 @@ void GenShapedSHBExcitation_fx( move32(); } #ifdef ADD_IVAS_TBE_CODE - if (MSFlag > 0) + if ( MSFlag > 0 ) { varEnvShape = 0.995f; csfilt_num2[0] = 1.0f - varEnvShape; @@ -2016,13 +2010,13 @@ void GenShapedSHBExcitation_fx( White_exc16k = exc16k; /* Track the low band envelope */ - if (element_mode == IVAS_CPE_TD || element_mode == IVAS_CPE_DFT) + if ( element_mode == IVAS_CPE_TD || element_mode == IVAS_CPE_DFT ) { - if (extl_brate != SWB_TBE_1k10 && extl_brate != SWB_TBE_1k75) + if ( extl_brate != SWB_TBE_1k10 && extl_brate != SWB_TBE_1k75 ) { mem_csfilt_left = 0.0f; mem_csfilt_right = 0.0f; - for (k = 0; k < L_FRAME16k; k++) + for ( k = 0; k < L_FRAME16k; k++ ) { excNoisyEnvLeft[k] = mem_csfilt_left + csfilt_num2[0] * excTmp2[k]; mem_csfilt_left = -csfilt_den2[1] * excNoisyEnvLeft[k]; @@ -2032,9 +2026,9 @@ void GenShapedSHBExcitation_fx( alpha = 0.0f; step = 1.0f / L_FRAME16k; - for (k = 0; k < L_FRAME16k; k++) + for ( k = 0; k < L_FRAME16k; k++ ) { - excNoisyEnv[k] = alpha * excNoisyEnvLeft[k] + (1 - alpha) * excNoisyEnvRight[k]; + excNoisyEnv[k] = alpha * excNoisyEnvLeft[k] + ( 1 - alpha ) * excNoisyEnvRight[k]; alpha += step; } } @@ -2045,57 +2039,57 @@ void GenShapedSHBExcitation_fx( /* Track the low band envelope */ L_tmp = *mem_csfilt; move32(); - FOR(i = 0; i < L_FRAME16k; i++) + FOR( i = 0; i < L_FRAME16k; i++ ) { - excNoisyEnv[i] = mac_r(L_tmp, csfilt_num2[0], excTmp2[i]); + excNoisyEnv[i] = mac_r( L_tmp, csfilt_num2[0], excTmp2[i] ); move16(); /* excNoisyEnv : Q_bwe_exc, *mem_csfilt: Q_bwe_exc+16, excTmp2: Q_bwe_exc, csfilt_num2[0] Q15 */ - L_tmp = L_mult(excNoisyEnv[i], neg_csfilt_den2[1]); /* Q_bwe_exc+16 */ + L_tmp = L_mult( excNoisyEnv[i], neg_csfilt_den2[1] ); /* Q_bwe_exc+16 */ } *mem_csfilt = L_tmp; move32(); } #ifdef ADD_IVAS_TBE_CODE - if (extl_brate == SWB_TBE_1k10 || extl_brate == SWB_TBE_1k75) + if ( extl_brate == SWB_TBE_1k10 || extl_brate == SWB_TBE_1k75 ) { /* generate gaussian (white) excitation */ - for (k = 0; k < L_FRAME16k; k++) + for ( k = 0; k < L_FRAME16k; k++ ) { - White_exc16k[k] = (float)own_random(&bwe_seed[0]); + White_exc16k[k] = (float) own_random( &bwe_seed[0] ); } /* normalize the amplitude of the gaussian excitation to that of the LB exc. */ pow22 = POW_EXC16k_WHTND; - v_multc(White_exc16k, (float)sqrt(pow1 / pow22), White_exc16k, L_FRAME16k); + v_multc( White_exc16k, (float) sqrt( pow1 / pow22 ), White_exc16k, L_FRAME16k ); } else #endif { /* create a random excitation - Reuse exc16k memory */ White_exc16k = exc16k; - create_random_vector_fx(White_exc16k, L_FRAME, bwe_seed); - create_random_vector_fx(White_exc16k + L_FRAME, L_FRAME16k - L_FRAME, bwe_seed); + create_random_vector_fx( White_exc16k, L_FRAME, bwe_seed ); + create_random_vector_fx( White_exc16k + L_FRAME, L_FRAME16k - L_FRAME, bwe_seed ); - L_tmp = L_deposit_l(0); - tmp = add(*Q_bwe_exc, 1); - FOR(k = 0; k < L_FRAME16k; k++) + L_tmp = L_deposit_l( 0 ); + tmp = add( *Q_bwe_exc, 1 ); + FOR( k = 0; k < L_FRAME16k; k++ ) { #ifdef BASOP_NOGLOB - L_tmp4 = L_shl_sat(L_deposit_l(White_exc16k[k]), tmp); + L_tmp4 = L_shl_sat( L_deposit_l( White_exc16k[k] ), tmp ); #else - L_tmp4 = L_shl(L_deposit_l(White_exc16k[k]), tmp); + L_tmp4 = L_shl( L_deposit_l( White_exc16k[k] ), tmp ); #endif - if (excNoisyEnv[k] != 0) + if ( excNoisyEnv[k] != 0 ) { - L_tmp4 = L_mult(excNoisyEnv[k], White_exc16k[k]);/* (Q_bwe_exc) +5 +1*/ + L_tmp4 = L_mult( excNoisyEnv[k], White_exc16k[k] ); /* (Q_bwe_exc) +5 +1*/ } White_exc16k_32[k] = L_tmp4; move32(); - L_tmp = L_max(L_tmp, L_abs(White_exc16k_32[k])); + L_tmp = L_max( L_tmp, L_abs( White_exc16k_32[k] ) ); } - Q_temp = norm_l(L_tmp); - if (L_tmp == 0) + Q_temp = norm_l( L_tmp ); + if ( L_tmp == 0 ) { Q_temp = 31; } @@ -2104,47 +2098,49 @@ void GenShapedSHBExcitation_fx( /* calculate pow22 */ /* pow22=0.00001f */ - tmp = sub(shl(sub(*Q_bwe_exc, NOISE_QADJ), 1), 31); - pow22 = L_shl(21475l/*0.00001f Q31*/, tmp); /* 0.00001f in 2*(Q_bwe_exc-NOISE_QADJ) */ - tmp = sub(NOISE_QFAC, 5); - FOR(k = 0; k < L_FRAME16k; k++) + tmp = sub( shl( sub( *Q_bwe_exc, NOISE_QADJ ), 1 ), 31 ); + pow22 = L_shl( 21475l /*0.00001f Q31*/, tmp ); /* 0.00001f in 2*(Q_bwe_exc-NOISE_QADJ) */ + tmp = sub( NOISE_QFAC, 5 ); + FOR( k = 0; k < L_FRAME16k; k++ ) { /* White_exc16k[k] *= excNoisyEnv[k]; */ - White_exc16k[k] = mult_r(excNoisyEnv[k], shl(White_exc16k[k], tmp)); + White_exc16k[k] = mult_r( excNoisyEnv[k], shl( White_exc16k[k], tmp ) ); move16(); /* i: excNoisyEnv in (Q_bwe_exc) */ /* i: White_exc16k in Q6 */ /* o: White_exc16k in (Q_bwe_exc-NOISE_QADJ) */ /* pow22 += White_exc16k[k] * White_exc16k[k]; */ #ifdef BASOP_NOGLOB - pow22 = L_mac0_sat(pow22, White_exc16k[k], White_exc16k[k]); /* 2*(Q_bwe_exc-NOISE_QADJ)*/ + pow22 = L_mac0_sat( pow22, White_exc16k[k], White_exc16k[k] ); /* 2*(Q_bwe_exc-NOISE_QADJ)*/ #else - pow22 = L_mac0(pow22, White_exc16k[k], White_exc16k[k]); /* 2*(Q_bwe_exc-NOISE_QADJ)*/ + pow22 = L_mac0( pow22, White_exc16k[k], White_exc16k[k] ); /* 2*(Q_bwe_exc-NOISE_QADJ)*/ #endif } /*Q_pow22 = sub( shl(*Q_bwe_exc,1), 18 );*/ - Q_pow22 = shl(sub(*Q_bwe_exc, NOISE_QADJ), 1); + Q_pow22 = shl( sub( *Q_bwe_exc, NOISE_QADJ ), 1 ); } #ifdef ADD_IVAS_TBE_CODE flag_plosive = 0; move16(); - test(); test(); test(); + test(); + test(); + test(); IF(GE_32(extl_brate, SWB_TBE_2k8) || EQ_32(extl_brate, SWB_TBE_1k10) || EQ_32(extl_brate, SWB_TBE_1k75))) #else - IF( GE_32(bitrate, ACELP_24k40)) + IF( GE_32( bitrate, ACELP_24k40 ) ) #endif { - IF( EQ_16(*vf_ind,20)) /* encoder side */ + IF( EQ_16( *vf_ind, 20 ) ) /* encoder side */ { #ifdef ADD_IVAS_TBE_CODE - if (extl_brate == SWB_TBE_1k10 || extl_brate == SWB_TBE_1k75) + if ( extl_brate == SWB_TBE_1k10 || extl_brate == SWB_TBE_1k75 ) { /* calculate TD envelopes of exc16kWhtnd and White_exc16k */ - find_td_envelope(White_exc16k, L_FRAME16k, 20, NULL, EnvWhiteExc16k); - find_td_envelope(exc16kWhtnd, L_FRAME16k, 20, NULL, EnvExc16kWhtnd); + find_td_envelope( White_exc16k, L_FRAME16k, 20, NULL, EnvWhiteExc16k ); + find_td_envelope( exc16kWhtnd, L_FRAME16k, 20, NULL, EnvExc16kWhtnd ); - for (k = 0; k < L_FRAME4k; k++) + for ( k = 0; k < L_FRAME4k; k++ ) { EnvWhiteExc16k_4k[k] = EnvWhiteExc16k[4 * k]; EnvExc16kWhtnd_4k[k] = EnvExc16kWhtnd[4 * k]; @@ -2152,14 +2148,14 @@ void GenShapedSHBExcitation_fx( /* calculate the optimal mix factor */ c0 = c1 = c2 = c3 = c4 = c5 = 0.0f; - for (i = 0; i < NUM_SHB_SUBGAINS; i++) + for ( i = 0; i < NUM_SHB_SUBGAINS; i++ ) { - c0_part[i] = sum2_f(&EnvExc16kWhtnd_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], L_FRAME4k / NUM_SHB_SUBGAINS); - c1_part[i] = -2.0f * dotp(&EnvSHBres_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], &EnvExc16kWhtnd_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], L_FRAME4k / NUM_SHB_SUBGAINS); - c2_part[i] = sum2_f(&EnvWhiteExc16k_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], L_FRAME4k / NUM_SHB_SUBGAINS); - c3_part[i] = -2.0f * dotp(&EnvSHBres_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], &EnvWhiteExc16k_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], L_FRAME4k / NUM_SHB_SUBGAINS); - c4_part[i] = 2.0f * dotp(&EnvExc16kWhtnd_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], &EnvWhiteExc16k_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], L_FRAME4k / NUM_SHB_SUBGAINS); - c5_part[i] = sum2_f(&EnvSHBres_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], L_FRAME4k / NUM_SHB_SUBGAINS); + c0_part[i] = sum2_f( &EnvExc16kWhtnd_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], L_FRAME4k / NUM_SHB_SUBGAINS ); + c1_part[i] = -2.0f * dotp( &EnvSHBres_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], &EnvExc16kWhtnd_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], L_FRAME4k / NUM_SHB_SUBGAINS ); + c2_part[i] = sum2_f( &EnvWhiteExc16k_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], L_FRAME4k / NUM_SHB_SUBGAINS ); + c3_part[i] = -2.0f * dotp( &EnvSHBres_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], &EnvWhiteExc16k_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], L_FRAME4k / NUM_SHB_SUBGAINS ); + c4_part[i] = 2.0f * dotp( &EnvExc16kWhtnd_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], &EnvWhiteExc16k_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], L_FRAME4k / NUM_SHB_SUBGAINS ); + c5_part[i] = sum2_f( &EnvSHBres_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], L_FRAME4k / NUM_SHB_SUBGAINS ); c0 += c0_part[i]; c1 += c1_part[i]; @@ -2170,24 +2166,24 @@ void GenShapedSHBExcitation_fx( } den = 4.0f * c0 * c2 - c4 * c4; - g1 = (c3 * c4 - 2 * c1 * c2) / den; - g2 = (c1 * c4 - 2 * c0 * c3) / den; + g1 = ( c3 * c4 - 2 * c1 * c2 ) / den; + g2 = ( c1 * c4 - 2 * c0 * c3 ) / den; *Env_error = 0.0f; flag_plosive = 0; - for (i = 0; i < NUM_SHB_SUBGAINS; i++) + for ( i = 0; i < NUM_SHB_SUBGAINS; i++ ) { Env_error_part[i] = c5_part[i] + g1 * g1 * c0_part[i] + g1 * c1_part[i] + g2 * g2 * c2_part[i] + g2 * c3_part[i] + g1 * g2 * c4_part[i]; *Env_error += Env_error_part[i]; - if (Env_error_part[i] > THR_ENV_ERROR_PLOSIVE) + if ( Env_error_part[i] > THR_ENV_ERROR_PLOSIVE ) { /* envelope error is too high -> likely a plosive */ flag_plosive = 1; } } - if (flag_plosive) + if ( flag_plosive ) { /* plosive detected -> set the mixing factor to 0 */ *vf_ind = 0; @@ -2196,157 +2192,157 @@ void GenShapedSHBExcitation_fx( else { /* normalize gain */ - g = g2 / (g1 + g2); + g = g2 / ( g1 + g2 ); /* quantization of the mixing factor */ cbsize = 1 << NUM_BITS_SHB_VF; - delta = 1.0f / (cbsize - 1); - if (g > 1.0f) + delta = 1.0f / ( cbsize - 1 ); + if ( g > 1.0f ) { g = 1.0f; } - else if (g < delta) + else if ( g < delta ) { /* prevent low gains to be quantized to 0 as this is reserved for plosives */ g = delta; } - *vf_ind = usquant(g, &mix_factor, 0.0f, 1.0f / (cbsize - 1), cbsize); + *vf_ind = usquant( g, &mix_factor, 0.0f, 1.0f / ( cbsize - 1 ), cbsize ); } } else #endif { - Estimate_mix_factors_fx(shb_res, Q_shb, exc16kWhtnd, *Q_bwe_exc, White_exc16k, - (*Q_bwe_exc - NOISE_QADJ), pow1, Q_pow1, pow22, Q_pow22, voiceFacEst, vf_ind); + Estimate_mix_factors_fx( shb_res, Q_shb, exc16kWhtnd, *Q_bwe_exc, White_exc16k, + ( *Q_bwe_exc - NOISE_QADJ ), pow1, Q_pow1, pow22, Q_pow22, voiceFacEst, vf_ind ); tmp = voiceFacEst[0]; tmp2 = MAX_16; - if (LE_16(tmp, 22938/*0.7f Q15*/)) + if ( LE_16( tmp, 22938 /*0.7f Q15*/ ) ) { - tmp2 = 26214/*0.8f Q15*/; + tmp2 = 26214 /*0.8f Q15*/; } } } ELSE /* decoder side */ { #ifdef ADD_IVAS_TBE_CODE - if (extl_brate == SWB_TBE_1k10 || extl_brate == SWB_TBE_1k75) + if ( extl_brate == SWB_TBE_1k10 || extl_brate == SWB_TBE_1k75 ) { - if (*vf_ind == 0) + if ( *vf_ind == 0 ) { mix_factor = 0.0f; flag_plosive = 1; } else { - mix_factor = usdequant(*vf_ind, 0.0f, 1.0f / ((1 << NUM_BITS_SHB_VF) - 1)); + mix_factor = usdequant( *vf_ind, 0.0f, 1.0f / ( ( 1 << NUM_BITS_SHB_VF ) - 1 ) ); } } else #endif { /* *vf_ind is an integer scale by 0.125f*/ - tmp = shl(*vf_ind, (15 - 3)); + tmp = shl( *vf_ind, ( 15 - 3 ) ); tmp2 = MAX_16; - if( LE_16(tmp, 22938/*0.7f Q15*/)) + if ( LE_16( tmp, 22938 /*0.7f Q15*/ ) ) { - tmp2 = 26214/*0.8f Q15*/; + tmp2 = 26214 /*0.8f Q15*/; } } } #ifdef ADD_IVAS_TBE_CODE - IF (NE_32(extl_brate, SWB_TBE_1k10) && NE_32(extl_brate, SWB_TBE_1k75) ) + IF( NE_32( extl_brate, SWB_TBE_1k10 ) && NE_32( extl_brate, SWB_TBE_1k75 ) ) #endif { - voice_factors[0] = mult_r(voice_factors[0], tmp2); + voice_factors[0] = mult_r( voice_factors[0], tmp2 ); move16(); - voice_factors[1] = mult_r(voice_factors[1], tmp2); + voice_factors[1] = mult_r( voice_factors[1], tmp2 ); move16(); - voice_factors[2] = mult_r(voice_factors[2], tmp2); + voice_factors[2] = mult_r( voice_factors[2], tmp2 ); move16(); - voice_factors[3] = mult_r(voice_factors[3], tmp2); + voice_factors[3] = mult_r( voice_factors[3], tmp2 ); move16(); - voice_factors[4] = mult_r(voice_factors[4], tmp2); + voice_factors[4] = mult_r( voice_factors[4], tmp2 ); move16(); } } #ifdef ADD_IVAS_TBE_CODE - if (element_mode >= IVAS_CPE_DFT && nlExc16k != NULL) + if ( element_mode >= IVAS_CPE_DFT && nlExc16k != NULL ) { /* save buffers for IC-BWE */ - mvr2r(exc16kWhtnd, nlExc16k, L_FRAME16k); - v_multc(White_exc16k, (float)sqrt(pow1 / pow22), mixExc16k, L_FRAME16k); + mvr2r( exc16kWhtnd, nlExc16k, L_FRAME16k ); + v_multc( White_exc16k, (float) sqrt( pow1 / pow22 ), mixExc16k, L_FRAME16k ); } #endif - tmp = sub(Q_temp, 3); - FOR ( k = 0; k < L_FRAME16k; k++ ) + tmp = sub( Q_temp, 3 ); + FOR( k = 0; k < L_FRAME16k; k++ ) { - White_exc16k_FB[k] = round_fx(L_shl(White_exc16k_32[k], tmp)); /* Q_bwe_exc +5 +1 +Q_temp -16 -3 */ + White_exc16k_FB[k] = round_fx( L_shl( White_exc16k_32[k], tmp ) ); /* Q_bwe_exc +5 +1 +Q_temp -16 -3 */ } prev_Q_bwe_exc_fb = *Q_bwe_exc_fb; - *Q_bwe_exc_fb = sub(add(*Q_bwe_exc, Q_temp), 13); + *Q_bwe_exc_fb = sub( add( *Q_bwe_exc, Q_temp ), 13 ); deemph_fx( White_exc16k, PREEMPH_FAC, L_FRAME16k, tbe_demph ); /* i/o: White_exc16k (Q_bwe_exc-NOISE_QADJ) */ /* i: tbe_demph (Q_bwe_exc-NOISE_QADJ) */ #ifdef ADD_IVAS_TBE_CODE - if (extl_brate == SWB_TBE_1k10 || extl_brate == SWB_TBE_1k75) + if ( extl_brate == SWB_TBE_1k10 || extl_brate == SWB_TBE_1k75 ) { - if (!flag_plosive) /* use only LB excitation in case of plosives */ + if ( !flag_plosive ) /* use only LB excitation in case of plosives */ { /* re-scale gaussian excitation at the beginning to gradually move from old energy to new energy */ - old_scale = (float)sqrt(*prev_pow_exc16kWhtnd / pow1); + old_scale = (float) sqrt( *prev_pow_exc16kWhtnd / pow1 ); new_scale = 1.0f; - step_scale = (new_scale - old_scale) / (L_FRAME16k / 2); + step_scale = ( new_scale - old_scale ) / ( L_FRAME16k / 2 ); scale = old_scale; /* interpolate between the old and the new value of the mixing factor */ old_fact = *prev_mix_factor; new_fact = mix_factor; - step = (new_fact - old_fact) / (L_FRAME16k / 2); + step = ( new_fact - old_fact ) / ( L_FRAME16k / 2 ); fact = old_fact; /* mixing of LB and gaussian excitation in the first half of the frame */ - for (k = 0; k < L_FRAME16k / 2; k++) + for ( k = 0; k < L_FRAME16k / 2; k++ ) { - exc16kWhtnd[k] = (float)fact * (White_exc16k[k] * scale) + (float)(1 - fact) * exc16kWhtnd[k]; + exc16kWhtnd[k] = (float) fact * ( White_exc16k[k] * scale ) + (float) ( 1 - fact ) * exc16kWhtnd[k]; fact += step; scale += step_scale; } /* mixing of LB and gaussian excitation in the second half of the frame */ - for (; k < L_FRAME16k; k++) + for ( ; k < L_FRAME16k; k++ ) { - exc16kWhtnd[k] = (float)new_fact * White_exc16k[k] + (float)(1 - new_fact) * exc16kWhtnd[k]; + exc16kWhtnd[k] = (float) new_fact * White_exc16k[k] + (float) ( 1 - new_fact ) * exc16kWhtnd[k]; } } - preemph(exc16kWhtnd, PREEMPH_FAC, L_FRAME16k, tbe_premph); + preemph( exc16kWhtnd, PREEMPH_FAC, L_FRAME16k, tbe_premph ); } else #endif { #ifdef ADD_IVAS_TBE_CODE - if (coder_type == UNVOICED || MSFlag == 1) + if ( coder_type == UNVOICED || MSFlag == 1 ) #else - IF(EQ_16(coder_type, UNVOICED)) + IF( EQ_16( coder_type, UNVOICED ) ) #endif { - L_tmp = root_a_over_b_fx(pow1, Q_pow1, pow22, Q_pow22, &exp); + L_tmp = root_a_over_b_fx( pow1, Q_pow1, pow22, Q_pow22, &exp ); #ifdef BASOP_NOGLOB scale = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /*Q15 */ #else - scale = round_fx( L_shl( L_tmp, exp ) ); /*Q15 */ + scale = round_fx( L_shl( L_tmp, exp ) ); /*Q15 */ #endif - FOR(k = 0; k < L_FRAME16k; k++) + FOR( k = 0; k < L_FRAME16k; k++ ) { /* White_exc16k: (Q_bwe_exc-NOISE_QADJ), scale: Q15 */ - L_tmp = L_mult(White_exc16k[k], scale); + L_tmp = L_mult( White_exc16k[k], scale ); /* L_tmp: (Q_bwe_exc-NOISE_QADJ) + 15 + 1 */ - exc16kWhtnd[k] = round_fx(L_shl(L_tmp, NOISE_QADJ)); + exc16kWhtnd[k] = round_fx( L_shl( L_tmp, NOISE_QADJ ) ); /* exc16kWhtnd: Q_bwe_exc */ } - preemph_fx(exc16kWhtnd, PREEMPH_FAC, L_FRAME16k, tbe_premph); + preemph_fx( exc16kWhtnd, PREEMPH_FAC, L_FRAME16k, tbe_premph ); /* i/o: exc16kWhtnd (Q_bwe_exc) */ /* i/o: tbe_premph (Q_bwe_exc) */ } @@ -2357,87 +2353,87 @@ void GenShapedSHBExcitation_fx( Word32 tempQ31; /*nbSubFr = ( bitrate < ACELP_24k40 )? NB_SUBFR : NB_SUBFR16k;*/ nbSubFr = NB_SUBFR16k; - lSubFr = (L_FRAME16k / NB_SUBFR16k); - IF(LT_32(bitrate, ACELP_24k40)) + lSubFr = ( L_FRAME16k / NB_SUBFR16k ); + IF( LT_32( bitrate, ACELP_24k40 ) ) { nbSubFr = NB_SUBFR; move16(); - lSubFr = (L_FRAME16k / NB_SUBFR); + lSubFr = ( L_FRAME16k / NB_SUBFR ); move16(); } k = 0; - FOR(i = 0; i < nbSubFr; i++) + FOR( i = 0; i < nbSubFr; i++ ) { test(); - IF(EQ_16(coder_type, VOICED) && (LT_32(bitrate,ACELP_24k40))) + IF( EQ_16( coder_type, VOICED ) && ( LT_32( bitrate, ACELP_24k40 ) ) ) { exp = 0; - tempQ15 = Sqrt16(voice_factors[i], &exp); /* Q15 */ - temp = shl(tempQ15, exp); /* Q15 exc16kWhtnd scale factor */ + tempQ15 = Sqrt16( voice_factors[i], &exp ); /* Q15 */ + temp = shl( tempQ15, exp ); /* Q15 exc16kWhtnd scale factor */ exp = 0; - tempQ15 = Sqrt16(temp, &exp); /* Q15 */ - temp1 = shl(tempQ15, exp); /* Q15 exc16kWhtnd scale factor */ + tempQ15 = Sqrt16( temp, &exp ); /* Q15 */ + temp1 = shl( tempQ15, exp ); /* Q15 exc16kWhtnd scale factor */ /*temp2 = root_a_over_b_fx( pow1 * (1.0f - temp), pow22 ); */ - temp = sub(MAX_16, temp); - tempQ31 = Mult_32_16(pow1, temp); - L_tmp = root_a_over_b_fx(tempQ31, Q_pow1, pow22, Q_pow22, &exp); + temp = sub( MAX_16, temp ); + tempQ31 = Mult_32_16( pow1, temp ); + L_tmp = root_a_over_b_fx( tempQ31, Q_pow1, pow22, Q_pow22, &exp ); #ifdef BASOP_NOGLOB - temp2 = round_fx_sat(L_shl_sat(L_tmp, exp)); /* Q15 whiteEnvShapedExc scale factor */ + temp2 = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q15 whiteEnvShapedExc scale factor */ #else - temp2 = round_fx(L_shl(L_tmp, exp)); /* Q15 whiteEnvShapedExc scale factor */ + temp2 = round_fx( L_shl( L_tmp, exp ) ); /* Q15 whiteEnvShapedExc scale factor */ #endif } ELSE { /* Adjust noise mixing for formant sharpening filter */ - tempQ15 = mult_r(SWB_NOISE_MIX_FAC_FX, formant_fac); + tempQ15 = mult_r( SWB_NOISE_MIX_FAC_FX, formant_fac ); /* vf_tmp = voice_factors[i] * (1.0f - vf_tmp); */ - vf_tmp = sub(MAX_16, tempQ15); - vf_tmp = mult_r(voice_factors[i], vf_tmp); + vf_tmp = sub( MAX_16, tempQ15 ); + vf_tmp = mult_r( voice_factors[i], vf_tmp ); exp = 0; - tempQ15 = Sqrt16(vf_tmp, &exp); /* Q15 */ - temp1 = shl(tempQ15, exp); /* Q15 exc16kWhtnd scale factor */ + tempQ15 = Sqrt16( vf_tmp, &exp ); /* Q15 */ + temp1 = shl( tempQ15, exp ); /* Q15 exc16kWhtnd scale factor */ /*temp2 = root_a_over_b(pow1 * (1.0f - vf_tmp), pow22); */ - temp = sub(MAX_16, vf_tmp); - tempQ31 = Mult_32_16(pow1, temp); - L_tmp = root_a_over_b_fx(tempQ31, Q_pow1, pow22, Q_pow22, &exp); + temp = sub( MAX_16, vf_tmp ); + tempQ31 = Mult_32_16( pow1, temp ); + L_tmp = root_a_over_b_fx( tempQ31, Q_pow1, pow22, Q_pow22, &exp ); #ifdef BASOP_NOGLOB - temp2 = round_fx_sat(L_shl_sat(L_tmp, exp)); /* Q15 whiteEnvShapedExc scale factor */ + temp2 = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q15 whiteEnvShapedExc scale factor */ #else - temp2 = round_fx(L_shl(L_tmp, exp)); /* Q15 whiteEnvShapedExc scale factor */ + temp2 = round_fx( L_shl( L_tmp, exp ) ); /* Q15 whiteEnvShapedExc scale factor */ #endif } - FOR(j = 0; j < lSubFr; j++) + FOR( j = 0; j < lSubFr; j++ ) { /*exc16kWhtnd[k+j] = temp1 * exc16kWhtnd[k+j] + temp2 * White_exc16k[k+j]; */ - L_tmp = L_mult(temp2, White_exc16k[k + j]); /* 16+(Q_bwe_exc-NOISE_QADJ)*/ + L_tmp = L_mult( temp2, White_exc16k[k + j] ); /* 16+(Q_bwe_exc-NOISE_QADJ)*/ #ifdef BASOP_NOGLOB - L_tmp = L_shl_sat(L_tmp, NOISE_QADJ); /* 16+(Q_bwe_exc) */ - exc16kWhtnd[k + j] = mac_r_sat(L_tmp, temp1, exc16kWhtnd[k + j]); + L_tmp = L_shl_sat( L_tmp, NOISE_QADJ ); /* 16+(Q_bwe_exc) */ + exc16kWhtnd[k + j] = mac_r_sat( L_tmp, temp1, exc16kWhtnd[k + j] ); #else - L_tmp = L_shl(L_tmp, NOISE_QADJ); /* 16+(Q_bwe_exc) */ - exc16kWhtnd[k + j] = mac_r(L_tmp, temp1, exc16kWhtnd[k + j]); + L_tmp = L_shl( L_tmp, NOISE_QADJ ); /* 16+(Q_bwe_exc) */ + exc16kWhtnd[k + j] = mac_r( L_tmp, temp1, exc16kWhtnd[k + j] ); #endif move16(); /* Q_bwe_exc */ } - k = add(k, lSubFr); + k = add( k, lSubFr ); /* estimate the pre-emph factor */ - tempQ15 = sub(MAX_16, voice_factors[i]); + tempQ15 = sub( MAX_16, voice_factors[i] ); exp = 0; - temp = Sqrt16(tempQ15, &exp); - temp = shl(temp, exp - 1); + temp = Sqrt16( tempQ15, &exp ); + temp = shl( temp, exp - 1 ); - temp2 = add(temp, shl(temp1, -1)); /* shift right by 1 to avoid overflow */ - temp = div_s(temp, temp2); /* Q15 */ - temp = mult_r(PREEMPH_FAC, temp); + temp2 = add( temp, shl( temp1, -1 ) ); /* shift right by 1 to avoid overflow */ + temp = div_s( temp, temp2 ); /* Q15 */ + temp = mult_r( PREEMPH_FAC, temp ); - preemph_fx(&exc16kWhtnd[i * lSubFr], temp, lSubFr, tbe_premph); + preemph_fx( &exc16kWhtnd[i * lSubFr], temp, lSubFr, tbe_premph ); /* exc16kWhtnd: Q_bwe_exc; tbe_premph: Q_bwe_exc*/ } @@ -2445,60 +2441,60 @@ void GenShapedSHBExcitation_fx( } #ifdef ADD_IVAS_TBE_CODE - IF ( LT_32(extl_brate, SWB_TBE_2k8)) + IF( LT_32( extl_brate, SWB_TBE_2k8 ) ) #else - IF ( LT_32(bitrate, ACELP_24k40)) + IF( LT_32( bitrate, ACELP_24k40 ) ) #endif { - Syn_filt_s(0, lpc_shb, LPC_SHB_ORDER, exc16kWhtnd, excSHB, L_FRAME16k, state_lpc_syn, 1 ); + Syn_filt_s( 0, lpc_shb, LPC_SHB_ORDER, exc16kWhtnd, excSHB, L_FRAME16k, state_lpc_syn, 1 ); /* i: exc16kWhtnd in Q_bwe_exc */ /* o: excSHB in Q_bwe_exc */ } ELSE { - set16_fx( zero_mem, 0, LPC_SHB_ORDER); + set16_fx( zero_mem, 0, LPC_SHB_ORDER ); - Syn_filt_s(0, lpc_shb_sf, LPC_SHB_ORDER, exc16kWhtnd, tempSHB, 80, zero_mem, 1); - syn_shb_ener_sf[0] = L_shr(sum2_fx(tempSHB, 80),3); + Syn_filt_s( 0, lpc_shb_sf, LPC_SHB_ORDER, exc16kWhtnd, tempSHB, 80, zero_mem, 1 ); + syn_shb_ener_sf[0] = L_shr( sum2_fx( tempSHB, 80 ), 3 ); move32(); - Syn_filt_s(0, lpc_shb_sf+(LPC_SHB_ORDER+1), LPC_SHB_ORDER, exc16kWhtnd+ 80, tempSHB, 80, zero_mem, 1 ); - syn_shb_ener_sf[1] = L_shr(sum2_fx(tempSHB, 80),3); + Syn_filt_s( 0, lpc_shb_sf + ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 80, tempSHB, 80, zero_mem, 1 ); + syn_shb_ener_sf[1] = L_shr( sum2_fx( tempSHB, 80 ), 3 ); move32(); - Syn_filt_s(0, lpc_shb_sf+2*(LPC_SHB_ORDER+1), LPC_SHB_ORDER, exc16kWhtnd+160, tempSHB, 80, zero_mem, 1 ); - syn_shb_ener_sf[2] = L_shr(sum2_fx(tempSHB, 80),3); + Syn_filt_s( 0, lpc_shb_sf + 2 * ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 160, tempSHB, 80, zero_mem, 1 ); + syn_shb_ener_sf[2] = L_shr( sum2_fx( tempSHB, 80 ), 3 ); move32(); - Syn_filt_s(0, lpc_shb_sf+3*(LPC_SHB_ORDER+1), LPC_SHB_ORDER, exc16kWhtnd+240, tempSHB, 80, zero_mem, 1 ); - syn_shb_ener_sf[3] = L_shr(sum2_fx(tempSHB, 80),3); + Syn_filt_s( 0, lpc_shb_sf + 3 * ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 240, tempSHB, 80, zero_mem, 1 ); + syn_shb_ener_sf[3] = L_shr( sum2_fx( tempSHB, 80 ), 3 ); move32(); /* i: exc16kWhtnd in Q_bwe_exc */ /* o: tempSHB in Q_bwe_exc */ /* o: syn_shb_ener_sf in (2*Q_bwe_exc+1) */ - IF(LE_32(bitrate,ACELP_32k)) + IF( LE_32( bitrate, ACELP_32k ) ) { - L_tmp = sum32_fx(syn_shb_ener_sf, 4); + L_tmp = sum32_fx( syn_shb_ener_sf, 4 ); /* find root_a(tempSHB[0]) = root_a_over_b(shb_ener_sf[0]), L_tmp) */ - tmp = shl(Q_shb, 1); - tmp2 = add(shl(*Q_bwe_exc, 1), 1); - L_tmp2 = root_a_over_b_fx(shb_ener_sf_32, tmp, L_tmp, tmp2, &exp); /* L_tmp2 in (Q31-exp) */ + tmp = shl( Q_shb, 1 ); + tmp2 = add( shl( *Q_bwe_exc, 1 ), 1 ); + L_tmp2 = root_a_over_b_fx( shb_ener_sf_32, tmp, L_tmp, tmp2, &exp ); /* L_tmp2 in (Q31-exp) */ - *Q_bwe_exc = sub(*Q_bwe_exc, exp); + *Q_bwe_exc = sub( *Q_bwe_exc, exp ); move16(); /* compensate for the exp shift */ tmp2 = add( prev_Q_bwe_syn, n_mem2 ); - IF( GT_16( *Q_bwe_exc, tmp2)) + IF( GT_16( *Q_bwe_exc, tmp2 ) ) { - L_tmp2 = L_shl(L_tmp2, sub(tmp2, *Q_bwe_exc)); + L_tmp2 = L_shl( L_tmp2, sub( tmp2, *Q_bwe_exc ) ); *Q_bwe_exc = tmp2; move16(); } - FOR(i = 0; i < L_FRAME16k; i++) + FOR( i = 0; i < L_FRAME16k; i++ ) { - L_tmp3 = Mult_32_16(L_tmp2, exc16kWhtnd[i]); /* *Q_bwe_exc + (31-exp) - 15 */ - exc16kWhtnd[i] = round_fx(L_tmp3); /* *Q_bwe_exc - exp */ + L_tmp3 = Mult_32_16( L_tmp2, exc16kWhtnd[i] ); /* *Q_bwe_exc + (31-exp) - 15 */ + exc16kWhtnd[i] = round_fx( L_tmp3 ); /* *Q_bwe_exc - exp */ } } /* i: L_tmp2 in (Q31-exp) */ @@ -2506,55 +2502,54 @@ void GenShapedSHBExcitation_fx( /* o: exc16kWhtnd in Q_bwe_exc: (Q_bwe_exc-exp) */ /* Rescale the past memories: LP synth and SHB look ahead buffers */ - tmp = sub(*Q_bwe_exc, prev_Q_bwe_syn); + tmp = sub( *Q_bwe_exc, prev_Q_bwe_syn ); FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { state_lpc_syn[i] = shl( state_lpc_syn[i], tmp ); move16(); } - FOR( i = -L_SHB_LAHEAD; i < 0; i++ ) + FOR( i = -L_SHB_LAHEAD; i < 0; i++ ) { - excSHB[i] = shl(excSHB[i], tmp); + excSHB[i] = shl( excSHB[i], tmp ); move16(); } /* Do mem_stp_swb_fx scaling before PostShortTerm_fx */ - Syn_filt_s(0, lpc_shb_sf, LPC_SHB_ORDER, exc16kWhtnd, excSHB, 80, state_lpc_syn, 1 ); - Syn_filt_s(0, lpc_shb_sf+(LPC_SHB_ORDER+1), LPC_SHB_ORDER, exc16kWhtnd+ 80, excSHB+ 80, 80, state_lpc_syn, 1 ); - Syn_filt_s(0, lpc_shb_sf+2*(LPC_SHB_ORDER+1), LPC_SHB_ORDER, exc16kWhtnd+160, excSHB+160, 80, state_lpc_syn, 1 ); - Syn_filt_s(0, lpc_shb_sf+3*(LPC_SHB_ORDER+1), LPC_SHB_ORDER, exc16kWhtnd+240, excSHB+240, 80, state_lpc_syn, 1 ); + Syn_filt_s( 0, lpc_shb_sf, LPC_SHB_ORDER, exc16kWhtnd, excSHB, 80, state_lpc_syn, 1 ); + Syn_filt_s( 0, lpc_shb_sf + ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 80, excSHB + 80, 80, state_lpc_syn, 1 ); + Syn_filt_s( 0, lpc_shb_sf + 2 * ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 160, excSHB + 160, 80, state_lpc_syn, 1 ); + Syn_filt_s( 0, lpc_shb_sf + 3 * ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 240, excSHB + 240, 80, state_lpc_syn, 1 ); /* i: exc16kWhtnd in (Q_bwe_exc) */ /* o: excSHB in (Q_bwe_exc) */ } - IF ( EQ_16(extl, FB_TBE)) + IF( EQ_16( extl, FB_TBE ) ) { - tmp = sub( add(*Q_bwe_exc_fb, 20), prev_Q_bwe_exc_fb ); + tmp = sub( add( *Q_bwe_exc_fb, 20 ), prev_Q_bwe_exc_fb ); Scale_sig( fb_state_lpc_syn, LPC_SHB_ORDER, tmp ); Scale_sig( fb_tbe_demph, 1, tmp ); - Syn_filt_s(0, lpc_shb, LPC_SHB_ORDER, White_exc16k_FB, White_exc16k_FB_temp, L_FRAME16k, fb_state_lpc_syn, 1 ); + Syn_filt_s( 0, lpc_shb, LPC_SHB_ORDER, White_exc16k_FB, White_exc16k_FB_temp, L_FRAME16k, fb_state_lpc_syn, 1 ); /* i: White_exc16k_FB in (14-n2) */ /* o: White_exc16k_FB_temp in (14-n2) */ - FOR( i=0; i<10; i++ ) + FOR( i = 0; i < 10; i++ ) { - FOR( j=0; j<32; ++j ) + FOR( j = 0; j < 32; ++j ) { - White_exc16k_FB_temp[i*32+j] = mult_r(White_exc16k_FB_temp[i*32+j], cos_fb_exc_fx[j]); + White_exc16k_FB_temp[i * 32 + j] = mult_r( White_exc16k_FB_temp[i * 32 + j], cos_fb_exc_fx[j] ); move16(); } } - *Q_bwe_exc_fb = add(*Q_bwe_exc_fb, 20); + *Q_bwe_exc_fb = add( *Q_bwe_exc_fb, 20 ); move16(); /**Q_bwe_exc_fb +35 +1 -16*/ flip_spectrum_fx( White_exc16k_FB_temp, White_exc16k_FB, L_FRAME16k ); deemph_fx( White_exc16k_FB, fb_deemph_fac, L_FRAME16k, fb_tbe_demph ); - } ELSE { - set16_fx( White_exc16k_FB, 0, L_FRAME16k); + set16_fx( White_exc16k_FB, 0, L_FRAME16k ); } #ifdef ADD_IVAS_TBE_CODE @@ -2565,47 +2560,47 @@ void GenShapedSHBExcitation_fx( } void GenShapedSHBExcitation_ivas_fx( - Word16 *excSHB, /* o : synthesized shaped shb excitation Q_bwe_exc*/ - const Word16 *lpc_shb, /* i : lpc coefficients Q12*/ - Word16 *White_exc16k_FB, /* o : white excitation for the Fullband extension Q_bwe_exc */ - Word32 *mem_csfilt, /* i/o: memory */ - Word16 *mem_genSHBexc_filt_down_shb, /* i/o: memory */ - Word16 *state_lpc_syn, /* i/o: memory */ - const Word16 coder_type, /* i : coding type */ - const Word16 *bwe_exc_extended, /* i : bwidth extended excitation */ - Word16 bwe_seed[], /* i/o: random number generator seed */ - Word16 voice_factors[], /* i : voicing factor*/ - const Word16 extl, /* i : extension layer */ - Word16 *tbe_demph, /* i/o: de-emphasis memory */ - Word16 *tbe_premph, /* i/o: pre-emphasis memory */ - Word16 *lpc_shb_sf, /* i: LP coefficients */ - const Word32 shb_ener_sf_32, /* i: input shb ener, Q31 */ - Word16 *shb_res_gshape, /* i: input res gain shape, Q14 */ + Word16 *excSHB, /* o : synthesized shaped shb excitation Q_bwe_exc*/ + const Word16 *lpc_shb, /* i : lpc coefficients Q12*/ + Word16 *White_exc16k_FB, /* o : white excitation for the Fullband extension Q_bwe_exc */ + Word32 *mem_csfilt, /* i/o: memory */ + Word16 *mem_genSHBexc_filt_down_shb, /* i/o: memory */ + Word16 *state_lpc_syn, /* i/o: memory */ + const Word16 coder_type, /* i : coding type */ + const Word16 *bwe_exc_extended, /* i : bwidth extended excitation */ + Word16 bwe_seed[], /* i/o: random number generator seed */ + Word16 voice_factors[], /* i : voicing factor*/ + const Word16 extl, /* i : extension layer */ + Word16 *tbe_demph, /* i/o: de-emphasis memory */ + Word16 *tbe_premph, /* i/o: pre-emphasis memory */ + Word16 *lpc_shb_sf, /* i: LP coefficients */ + const Word32 shb_ener_sf_32, /* i: input shb ener, Q31 */ + Word16 *shb_res_gshape, /* i: input res gain shape, Q14 */ Word16 *shb_res, Word16 *vf_ind, - const Word16 formant_fac, /* i : Formant sharpening factor [0..1] */ - Word16 fb_state_lpc_syn[], /* i/o: memory */ - Word16 *fb_tbe_demph, /* i/o: fb de-emphasis memory */ + const Word16 formant_fac, /* i : Formant sharpening factor [0..1] */ + Word16 fb_state_lpc_syn[], /* i/o: memory */ + Word16 *fb_tbe_demph, /* i/o: fb de-emphasis memory */ Word16 *Q_bwe_exc, Word16 *Q_bwe_exc_fb, const Word16 Q_shb, - Word16 n_mem2, /* i : n_mem2 scale factor to adjust 24.4/32kbps memories */ - Word16 prev_Q_bwe_syn, /* i : st_fx->prev_Q_bwe_syn */ + Word16 n_mem2, /* i : n_mem2 scale factor to adjust 24.4/32kbps memories */ + Word16 prev_Q_bwe_syn, /* i : st_fx->prev_Q_bwe_syn */ const Word32 bitrate, const Word16 prev_bfi -#if 1//def ADD_IVAS_TBE_CODE - , /* i : previous frame was concealed */ - const Word16 element_mode, /* i : element mode */ - const Word16 flag_ACELP16k, /* i : ACELP@16kHz flag */ - Word16* nlExc16k, /* i/o: NL exc for IC-BWE */ - Word16* mixExc16k, /* i/o: exc spreading for IC-BWE */ - const Word32 extl_brate, /* i : extension layer bitarte */ - const Word16 MSFlag, /* i : Multi Source flag */ - Word16 EnvSHBres_4k[], /* i/o: TD envelope of the SHB residual signal */ - Word32* prev_pow_exc16kWhtnd, /* i/o: power of the LB excitation signal in the previous frame */ - Word16* prev_mix_factor, /* i/o: mixing factor in the previous frame */ - Word16* Env_error, /* o : error in SHB residual envelope modelling*/ - Word16 Env_error_part[] /* o : per-segment error in SHB residual envelope modelling */ +#if 1 // def ADD_IVAS_TBE_CODE + , /* i : previous frame was concealed */ + const Word16 element_mode, /* i : element mode */ + const Word16 flag_ACELP16k, /* i : ACELP@16kHz flag */ + Word16 *nlExc16k, /* i/o: NL exc for IC-BWE */ + Word16 *mixExc16k, /* i/o: exc spreading for IC-BWE */ + const Word32 extl_brate, /* i : extension layer bitarte */ + const Word16 MSFlag, /* i : Multi Source flag */ + Word16 EnvSHBres_4k[], /* i/o: TD envelope of the SHB residual signal */ + Word32 *prev_pow_exc16kWhtnd, /* i/o: power of the LB excitation signal in the previous frame */ + Word16 *prev_mix_factor, /* i/o: mixing factor in the previous frame */ + Word16 *Env_error, /* o : error in SHB residual envelope modelling*/ + Word16 Env_error_part[] /* o : per-segment error in SHB residual envelope modelling */ #endif ) { @@ -2623,15 +2618,15 @@ void GenShapedSHBExcitation_ivas_fx( Word16 excTmp2[L_FRAME16k]; Word16 *White_exc16k; Word16 excNoisyEnv[L_FRAME16k]; - Word16 csfilt_num2[1] = { 6554 }; /*0.2 in Q15 */ - Word16 neg_csfilt_den2[2] = { -32767, 26214 }; /* {1.0f, -0.8f} */ + Word16 csfilt_num2[1] = { 6554 }; /*0.2 in Q15 */ + Word16 neg_csfilt_den2[2] = { -32767, 26214 }; /* {1.0f, -0.8f} */ Word16 varEnvShape; Word16 fb_deemph_fac = 15729; /*0.48f in Q15 */ Word16 exc16kWhtnd[L_FRAME16k]; Word32 L_tmp; Word16 vf_tmp; - Word16 tmp, exp, tmp2=0; + Word16 tmp, exp, tmp2 = 0; Word16 voiceFacEst[NB_SUBFR16k]; Word16 zero_mem[LPC_SHB_ORDER]; Word32 syn_shb_ener_sf[4]; @@ -2646,7 +2641,7 @@ void GenShapedSHBExcitation_ivas_fx( Word16 Q_temp; Word16 prev_Q_bwe_exc_fb; -#if 1//def ADD_IVAS_TBE_CODE +#if 1 // def ADD_IVAS_TBE_CODE Word16 alpha, step, mem_csfilt_left, mem_csfilt_right, excNoisyEnvLeft[L_FRAME16k], excNoisyEnvRight[L_FRAME16k]; Word16 cbsize; Word16 mix_factor, old_fact, new_fact, fact, old_scale, new_scale, step_scale; @@ -2659,126 +2654,126 @@ void GenShapedSHBExcitation_ivas_fx( mix_factor = 0; #endif - set16_fx(zero_mem, 0, LPC_SHB_ORDER); - set16_fx(wht_fil_mem, 0, LPC_WHTN_ORDER); + set16_fx( zero_mem, 0, LPC_SHB_ORDER ); + set16_fx( wht_fil_mem, 0, LPC_WHTN_ORDER ); - FOR(i = 0; i < L_FRAME32k; i = i + 2) + FOR( i = 0; i < L_FRAME32k; i = i + 2 ) { - exc32k[i] = negate(bwe_exc_extended[i]); + exc32k[i] = negate( bwe_exc_extended[i] ); move16(); exc32k[i + 1] = bwe_exc_extended[i + 1]; move16(); } /* Decimate by 2 */ - Decimate_allpass_steep_fx(exc32k, mem_genSHBexc_filt_down_shb, 2 * L_FRAME16k, exc16k); + Decimate_allpass_steep_fx( exc32k, mem_genSHBexc_filt_down_shb, 2 * L_FRAME16k, exc16k ); /* i: exc32k in Q_bwe_exc */ /* o: exc16k in Q_bwe_exc */ - autocorr_fx(exc16k, LPC_WHTN_ORDER + 1, R_h, R_l, &Q_R, L_FRAME16k, win_flatten_fx, 0, 1); + autocorr_fx( exc16k, LPC_WHTN_ORDER + 1, R_h, R_l, &Q_R, L_FRAME16k, win_flatten_fx, 0, 1 ); /* Ensure R[0] isn't zero when entering Levinson Durbin */ - R_l[0] = s_max(R_l[0], 1); + R_l[0] = s_max( R_l[0], 1 ); move16(); - FOR(i = 1; i <= LPC_WHTN_ORDER; i++) + FOR( i = 1; i <= LPC_WHTN_ORDER; i++ ) { - L_tmp = Mpy_32(R_h[i], R_l[i], wac_h[i - 1], wac_l[i - 1]); - L_Extract(L_tmp, &R_h[i], &R_l[i]); + L_tmp = Mpy_32( R_h[i], R_l[i], wac_h[i - 1], wac_l[i - 1] ); + L_Extract( L_tmp, &R_h[i], &R_l[i] ); } - E_LPC_lev_dur(R_h, R_l, lpc_whtn, LepsP, LPC_WHTN_ORDER, NULL); - Copy_Scale_sig(lpc_whtn, lpc_whtn, LPC_WHTN_ORDER + 1, sub(norm_s(lpc_whtn[0]), 2)); - fir_fx(exc16k, lpc_whtn, exc16kWhtnd, wht_fil_mem, L_FRAME16k, LPC_WHTN_ORDER, 0, 3); + E_LPC_lev_dur( R_h, R_l, lpc_whtn, LepsP, LPC_WHTN_ORDER, NULL ); + Copy_Scale_sig( lpc_whtn, lpc_whtn, LPC_WHTN_ORDER + 1, sub( norm_s( lpc_whtn[0] ), 2 ) ); + fir_fx( exc16k, lpc_whtn, exc16kWhtnd, wht_fil_mem, L_FRAME16k, LPC_WHTN_ORDER, 0, 3 ); /* i: exc16k in Q_bwe_exc */ /* o: exc16kWhtnd in Q_bwe_exc */ -#if 1//def ADD_IVAS_TBE_CODE - IF(GE_32(extl_brate, SWB_TBE_2k8)) +#if 1 // def ADD_IVAS_TBE_CODE + IF( GE_32( extl_brate, SWB_TBE_2k8 ) ) #else - IF(GE_32(bitrate, ACELP_24k40)) + IF( GE_32( bitrate, ACELP_24k40 ) ) #endif { temp2 = 0; move16(); - FOR(j = 0; j < 4; j++) + FOR( j = 0; j < 4; j++ ) { temp1 = shb_res_gshape[j]; move16(); - FOR(i = 0; i < 80; i++) + FOR( i = 0; i < 80; i++ ) { - exc16kWhtnd[temp2 + i] = round_fx(L_shl(L_mult(exc16kWhtnd[temp2 + i], temp1), 1)); + exc16kWhtnd[temp2 + i] = round_fx( L_shl( L_mult( exc16kWhtnd[temp2 + i], temp1 ), 1 ) ); /* exc16kWhtnd in Q_bwe_exc, shb_res_gshape in Q14 */ } - temp2 = add(temp2, 80); + temp2 = add( temp2, 80 ); } } /* Estimate pow1 associated with Low band nonlinear extended excitation */ /* pow1=0.00001f */ - tmp = sub(shl(*Q_bwe_exc, 1), 31); + tmp = sub( shl( *Q_bwe_exc, 1 ), 31 ); #ifdef BASOP_NOGLOB - pow1 = L_shl_sat(21475l/*0.00001f Q31*/, tmp); /* 0.00001f in 2*(Q_bwe_exc) */ + pow1 = L_shl_sat( 21475l /*0.00001f Q31*/, tmp ); /* 0.00001f in 2*(Q_bwe_exc) */ #else - pow1 = L_shl(21475l/*0.00001f Q31*/, tmp); /* 0.00001f in 2*(Q_bwe_exc) */ + pow1 = L_shl( 21475l /*0.00001f Q31*/, tmp ); /* 0.00001f in 2*(Q_bwe_exc) */ #endif - FOR(k = 0; k < L_FRAME16k; k++) + FOR( k = 0; k < L_FRAME16k; k++ ) { /*excTmp2[k ] = (float)(fabs(exc16kWhtnd[k]));*/ - excTmp2[k] = abs_s(exc16kWhtnd[k]); + excTmp2[k] = abs_s( exc16kWhtnd[k] ); move16(); /* pow1 += exc16kWhtnd[k] * exc16kWhtnd[k]; */ #ifdef BASOP_NOGLOB - pow1 = L_mac0_sat(pow1, exc16kWhtnd[k], exc16kWhtnd[k]); /* 2*Q_bwe_exc */ + pow1 = L_mac0_sat( pow1, exc16kWhtnd[k], exc16kWhtnd[k] ); /* 2*Q_bwe_exc */ #else - pow1 = L_mac0(pow1, exc16kWhtnd[k], exc16kWhtnd[k]); /* 2*Q_bwe_exc */ + pow1 = L_mac0( pow1, exc16kWhtnd[k], exc16kWhtnd[k] ); /* 2*Q_bwe_exc */ #endif } - Q_pow1 = shl(*Q_bwe_exc, 1); + Q_pow1 = shl( *Q_bwe_exc, 1 ); test(); -#if 1//ADD_IVAS_TBE_CODE - IF(EQ_16(flag_ACELP16k, 0)) +#if 1 // ADD_IVAS_TBE_CODE + IF( EQ_16( flag_ACELP16k, 0 ) ) #else - IF((LE_32(bitrate, ACELP_13k20)) && (GE_32(bitrate, ACELP_7k20))) + IF( ( LE_32( bitrate, ACELP_13k20 ) ) && ( GE_32( bitrate, ACELP_7k20 ) ) ) #endif { /* varEnvShape = mean_fx(voice_factors, 4); */ /* unroll the loop */ - L_tmp = L_mult(voice_factors[0], 8192); - L_tmp = L_mac(L_tmp, voice_factors[1], 8192); - L_tmp = L_mac(L_tmp, voice_factors[2], 8192); - varEnvShape = mac_r(L_tmp, voice_factors[3], 8192); /* varEnvShape in Q15 */ + L_tmp = L_mult( voice_factors[0], 8192 ); + L_tmp = L_mac( L_tmp, voice_factors[1], 8192 ); + L_tmp = L_mac( L_tmp, voice_factors[2], 8192 ); + varEnvShape = mac_r( L_tmp, voice_factors[3], 8192 ); /* varEnvShape in Q15 */ } ELSE /* 16k core */ { /* varEnvShape = mean_fx(voice_factors, 5); */ /* unroll the loop */ - L_tmp = L_mult(voice_factors[0], 6554); - L_tmp = L_mac(L_tmp, voice_factors[1], 6554); - L_tmp = L_mac(L_tmp, voice_factors[2], 6554); - L_tmp = L_mac(L_tmp, voice_factors[3], 6554); - varEnvShape = mac_r(L_tmp, voice_factors[4], 6554); /* varEnvShape in Q15 */ + L_tmp = L_mult( voice_factors[0], 6554 ); + L_tmp = L_mac( L_tmp, voice_factors[1], 6554 ); + L_tmp = L_mac( L_tmp, voice_factors[2], 6554 ); + L_tmp = L_mac( L_tmp, voice_factors[3], 6554 ); + varEnvShape = mac_r( L_tmp, voice_factors[4], 6554 ); /* varEnvShape in Q15 */ } - IF(EQ_16(extl, FB_TBE)) + IF( EQ_16( extl, FB_TBE ) ) { /*pow(varEnvShape,3) */ - tmp = mult_r(varEnvShape, varEnvShape); - tmp = mult_r(tmp, varEnvShape); + tmp = mult_r( varEnvShape, varEnvShape ); + tmp = mult_r( tmp, varEnvShape ); /* max_val((0.68f - (float)pow(varEnvShape, 3)), 0.48f); */ - fb_deemph_fac = sub(22282/*0.68f Q15*/, tmp); - fb_deemph_fac = s_max(fb_deemph_fac, 15729/*0.48f Q15*/); + fb_deemph_fac = sub( 22282 /*0.68f Q15*/, tmp ); + fb_deemph_fac = s_max( fb_deemph_fac, 15729 /*0.48f Q15*/ ); } /*varEnvShape = 1.09875f - 0.49875f * varEnvShape; */ - varEnvShape = msu_r(1179773824l/*0.549375f Q31*/, 8172/*0.249375f Q15*/, varEnvShape); + varEnvShape = msu_r( 1179773824l /*0.549375f Q31*/, 8172 /*0.249375f Q15*/, varEnvShape ); /*varEnvShape = min( max_val(varEnvShape, 0.6f), 0.999f); */ - varEnvShape = s_max(varEnvShape, 9830/*0.3f Q15*/); - varEnvShape = s_min(varEnvShape, 16368/*0.4995f Q15*/); - varEnvShape = shl(varEnvShape, 1); - csfilt_num2[0] = sub(MAX_16, varEnvShape); + varEnvShape = s_max( varEnvShape, 9830 /*0.3f Q15*/ ); + varEnvShape = s_min( varEnvShape, 16368 /*0.4995f Q15*/ ); + varEnvShape = shl( varEnvShape, 1 ); + csfilt_num2[0] = sub( MAX_16, varEnvShape ); move16(); neg_csfilt_den2[1] = varEnvShape; move16(); @@ -2786,76 +2781,76 @@ void GenShapedSHBExcitation_ivas_fx( test(); test(); test(); -#if 1//def ADD_IVAS_TBE_CODE - IF(EQ_16(element_mode, EVS_MONO) && *mem_csfilt == 0 && ((EQ_32(bitrate, ACELP_9k60)) || (EQ_32(bitrate, ACELP_16k40)) || (EQ_32(bitrate, ACELP_24k40)))) +#if 1 // def ADD_IVAS_TBE_CODE + IF( EQ_16( element_mode, EVS_MONO ) && *mem_csfilt == 0 && ( ( EQ_32( bitrate, ACELP_9k60 ) ) || ( EQ_32( bitrate, ACELP_16k40 ) ) || ( EQ_32( bitrate, ACELP_24k40 ) ) ) ) #else - IF(*mem_csfilt == 0 && ((EQ_32(bitrate, ACELP_9k60)) || (EQ_32(bitrate, ACELP_16k40)) || (EQ_32(bitrate, ACELP_24k40)))) + IF( *mem_csfilt == 0 && ( ( EQ_32( bitrate, ACELP_9k60 ) ) || ( EQ_32( bitrate, ACELP_16k40 ) ) || ( EQ_32( bitrate, ACELP_24k40 ) ) ) ) #endif { /* pre-init smoothing filter to avoid energy drop outs */ - L_tmp = L_mult(excTmp2[0], 1638); - FOR(i = 1; i < L_SUBFR16k / 4; i++) + L_tmp = L_mult( excTmp2[0], 1638 ); + FOR( i = 1; i < L_SUBFR16k / 4; i++ ) { - L_tmp = L_mac(L_tmp, excTmp2[i], 1638); /*1638 = 1/20 in Q15*/ + L_tmp = L_mac( L_tmp, excTmp2[i], 1638 ); /*1638 = 1/20 in Q15*/ } /*L_tmp = sum(excTmp2, L_SUBFR16k/4)*(1/20) where L_SUBFR16k/4 =20 */ /* don't apply for FB in case the FB start-frame was potentially lost - White_exc16k is very sensitive to enery mismatch between enc - dec */ /* rather stick to the more conservative approach, to avoid potential clippings */ test(); - IF(!(prev_bfi && EQ_16(extl, FB_TBE))) + IF( !( prev_bfi && EQ_16( extl, FB_TBE ) ) ) { /* use weak smoothing for 1st frame after switching to make filter recover more quickly */ - varEnvShape = 26214/*0.8f Q15*/; + varEnvShape = 26214 /*0.8f Q15*/; move16(); - csfilt_num2[0] = sub(MAX_16, varEnvShape); + csfilt_num2[0] = sub( MAX_16, varEnvShape ); move16(); neg_csfilt_den2[1] = varEnvShape; move16(); } - *mem_csfilt = Mult_32_16(L_tmp, varEnvShape); + *mem_csfilt = Mult_32_16( L_tmp, varEnvShape ); move32(); } -#if 1//def ADD_IVAS_TBE_CODE - IF (MSFlag > 0) +#if 1 // def ADD_IVAS_TBE_CODE + IF( MSFlag > 0 ) { - //varEnvShape = 0.995f; + // varEnvShape = 0.995f; varEnvShape = 32604; - //csfilt_num2[0] = 1.0f - varEnvShape; + // csfilt_num2[0] = 1.0f - varEnvShape; csfilt_num2[0] = 32768 - varEnvShape; neg_csfilt_den2[1] = varEnvShape; } White_exc16k = exc16k; - Word16 Q_excTmp2 = getScaleFactor16(excTmp2, L_FRAME16k) + *Q_bwe_exc; + Word16 Q_excTmp2 = getScaleFactor16( excTmp2, L_FRAME16k ) + *Q_bwe_exc; /* Track the low band envelope */ - IF(element_mode == IVAS_CPE_TD || element_mode == IVAS_CPE_DFT) + IF( element_mode == IVAS_CPE_TD || element_mode == IVAS_CPE_DFT ) { - IF(extl_brate != SWB_TBE_1k10 && extl_brate != SWB_TBE_1k75) + IF( extl_brate != SWB_TBE_1k10 && extl_brate != SWB_TBE_1k75 ) { mem_csfilt_left = 0; mem_csfilt_right = 0; - FOR (k = 0; k < L_FRAME16k; k++) + FOR( k = 0; k < L_FRAME16k; k++ ) { - //excNoisyEnvLeft[k] = mem_csfilt_left + csfilt_num2[0] * excTmp2[k]; - excNoisyEnvLeft[k] = add(mem_csfilt_left, mult_r(csfilt_num2[0], shl(excTmp2[k], sub(Q_excTmp2, *Q_bwe_exc)))); //Q_excTmp2 - //mem_csfilt_left = -csfilt_den2[1] * excNoisyEnvLeft[k]; - mem_csfilt_left = mult_r(neg_csfilt_den2[1], excNoisyEnvLeft[k]); //Q_excTmp2 - //excNoisyEnvRight[L_FRAME16k - k - 1] = mem_csfilt_right + csfilt_num2[0] * excTmp2[L_FRAME16k - k - 1]; - excNoisyEnvRight[L_FRAME16k - k - 1] = add(mem_csfilt_right, mult_r(csfilt_num2[0], shl(excTmp2[L_FRAME16k - k - 1], sub(Q_excTmp2, *Q_bwe_exc)))); //Q_excTmp2 - //mem_csfilt_right = -csfilt_den2[1] * excNoisyEnvRight[L_FRAME16k - k - 1]; - mem_csfilt_right = mult_r(neg_csfilt_den2[1], excNoisyEnvRight[L_FRAME16k - k - 1]); //Q_excTmp2 + // excNoisyEnvLeft[k] = mem_csfilt_left + csfilt_num2[0] * excTmp2[k]; + excNoisyEnvLeft[k] = add( mem_csfilt_left, mult_r( csfilt_num2[0], shl( excTmp2[k], sub( Q_excTmp2, *Q_bwe_exc ) ) ) ); // Q_excTmp2 + // mem_csfilt_left = -csfilt_den2[1] * excNoisyEnvLeft[k]; + mem_csfilt_left = mult_r( neg_csfilt_den2[1], excNoisyEnvLeft[k] ); // Q_excTmp2 + // excNoisyEnvRight[L_FRAME16k - k - 1] = mem_csfilt_right + csfilt_num2[0] * excTmp2[L_FRAME16k - k - 1]; + excNoisyEnvRight[L_FRAME16k - k - 1] = add( mem_csfilt_right, mult_r( csfilt_num2[0], shl( excTmp2[L_FRAME16k - k - 1], sub( Q_excTmp2, *Q_bwe_exc ) ) ) ); // Q_excTmp2 + // mem_csfilt_right = -csfilt_den2[1] * excNoisyEnvRight[L_FRAME16k - k - 1]; + mem_csfilt_right = mult_r( neg_csfilt_den2[1], excNoisyEnvRight[L_FRAME16k - k - 1] ); // Q_excTmp2 } alpha = 0; - //step = 1.0f / L_FRAME16k; - step = 102; //Q15 - FOR (k = 0; k < L_FRAME16k; k++) + // step = 1.0f / L_FRAME16k; + step = 102; // Q15 + FOR( k = 0; k < L_FRAME16k; k++ ) { - //excNoisyEnv[k] = alpha * excNoisyEnvLeft[k] + (1 - alpha) * excNoisyEnvRight[k]; - excNoisyEnv[k] = add(mult_r(alpha, excNoisyEnvLeft[k]), mult_r((32767 - alpha), excNoisyEnvRight[k])); //Q_excTmp2 - alpha = add(alpha, step); + // excNoisyEnv[k] = alpha * excNoisyEnvLeft[k] + (1 - alpha) * excNoisyEnvRight[k]; + excNoisyEnv[k] = add( mult_r( alpha, excNoisyEnvLeft[k] ), mult_r( ( 32767 - alpha ), excNoisyEnvRight[k] ) ); // Q_excTmp2 + alpha = add( alpha, step ); } } } @@ -2865,46 +2860,47 @@ void GenShapedSHBExcitation_ivas_fx( /* Track the low band envelope */ L_tmp = *mem_csfilt; move32(); - FOR(i = 0; i < L_FRAME16k; i++) + FOR( i = 0; i < L_FRAME16k; i++ ) { - excNoisyEnv[i] = mac_r(L_tmp, csfilt_num2[0], shl(excTmp2[i], sub(Q_excTmp2, *Q_bwe_exc))); + excNoisyEnv[i] = mac_r( L_tmp, csfilt_num2[0], shl( excTmp2[i], sub( Q_excTmp2, *Q_bwe_exc ) ) ); move16(); /* excNoisyEnv : Q_excTmp2, *mem_csfilt: Q_excTmp2+16, excTmp2: Q_excTmp2, csfilt_num2[0] Q_excTmp2 */ - L_tmp = L_mult(excNoisyEnv[i], neg_csfilt_den2[1]); /* Q_excTmp2 + 16 */ + L_tmp = L_mult( excNoisyEnv[i], neg_csfilt_den2[1] ); /* Q_excTmp2 + 16 */ } *mem_csfilt = L_tmp; move32(); } -#if 1//def ADD_IVAS_TBE_CODE - IF (extl_brate == SWB_TBE_1k10 || extl_brate == SWB_TBE_1k75) +#if 1 // def ADD_IVAS_TBE_CODE + IF( extl_brate == SWB_TBE_1k10 || extl_brate == SWB_TBE_1k75 ) { /* generate gaussian (white) excitation */ - FOR (k = 0; k < L_FRAME16k; k++) + FOR( k = 0; k < L_FRAME16k; k++ ) { - White_exc16k[k] = own_random(&bwe_seed[0]); + White_exc16k[k] = own_random( &bwe_seed[0] ); } /* normalize the amplitude of the gaussian excitation to that of the LB exc. */ Word32 pow22_inv = POW_EXC16k_WHTND_FX_INV_SQRT; pow22 = POW_EXC16k_WHTND_FX; Q_pow22 = -6; - //v_multc(White_exc16k, (float)sqrt(pow1 / pow22), White_exc16k, L_FRAME16k); + // v_multc(White_exc16k, (float)sqrt(pow1 / pow22), White_exc16k, L_FRAME16k); Word16 pow1_exp = Q31 - Q_pow1; - Word32 temp_pow = Sqrt32(pow1, &pow1_exp); - temp_pow = L_shl(Mpy_32_32(temp_pow, pow22_inv), pow1_exp); + Word32 temp_pow = Sqrt32( pow1, &pow1_exp ); + temp_pow = L_shl( Mpy_32_32( temp_pow, pow22_inv ), pow1_exp ); /*Word16 out_exp; Word32 temp_pow1 = root_a_over_b_fx(pow1, Q_pow1, pow22, Q_pow22, &out_exp); temp_pow1 = L_shl(temp_pow1, out_exp);*/ - //v_multc_fixed_16_16(White_exc16k, round_fx(temp_pow), White_exc16k, L_FRAME16k); + // v_multc_fixed_16_16(White_exc16k, round_fx(temp_pow), White_exc16k, L_FRAME16k); L_tmp = 0; - FOR (k = 0; k < L_FRAME16k; k++) { - White_exc16k_32[k] = L_mult(White_exc16k[k], round_fx(temp_pow)); - White_exc16k[k] = round_fx(L_shl(White_exc16k_32[k], *Q_bwe_exc - NOISE_QADJ)); // Q_bwe_exc - NOISE_QADJ - L_tmp = max(L_tmp, L_abs(White_exc16k_32[k])); + FOR( k = 0; k < L_FRAME16k; k++ ) + { + White_exc16k_32[k] = L_mult( White_exc16k[k], round_fx( temp_pow ) ); + White_exc16k[k] = round_fx( L_shl( White_exc16k_32[k], *Q_bwe_exc - NOISE_QADJ ) ); // Q_bwe_exc - NOISE_QADJ + L_tmp = max( L_tmp, L_abs( White_exc16k_32[k] ) ); } - Q_temp = norm_l(L_tmp); - IF (L_tmp == 0) + Q_temp = norm_l( L_tmp ); + IF( L_tmp == 0 ) { Q_temp = 31; } @@ -2914,28 +2910,28 @@ void GenShapedSHBExcitation_ivas_fx( { /* create a random excitation - Reuse exc16k memory */ White_exc16k = exc16k; - create_random_vector_fx(White_exc16k, L_FRAME, bwe_seed); - create_random_vector_fx(White_exc16k + L_FRAME, L_FRAME16k - L_FRAME, bwe_seed); + create_random_vector_fx( White_exc16k, L_FRAME, bwe_seed ); + create_random_vector_fx( White_exc16k + L_FRAME, L_FRAME16k - L_FRAME, bwe_seed ); - L_tmp = L_deposit_l(0); - tmp = add(*Q_bwe_exc, 1); - FOR(k = 0; k < L_FRAME16k; k++) + L_tmp = L_deposit_l( 0 ); + tmp = add( *Q_bwe_exc, 1 ); + FOR( k = 0; k < L_FRAME16k; k++ ) { #ifdef BASOP_NOGLOB - L_tmp4 = L_shl_sat(L_deposit_l(White_exc16k[k]), tmp); + L_tmp4 = L_shl_sat( L_deposit_l( White_exc16k[k] ), tmp ); #else - L_tmp4 = L_shl(L_deposit_l(White_exc16k[k]), tmp); + L_tmp4 = L_shl( L_deposit_l( White_exc16k[k] ), tmp ); #endif - IF (excNoisyEnv[k] != 0) + IF( excNoisyEnv[k] != 0 ) { - L_tmp4 = L_mult(shr(excNoisyEnv[k], sub(Q_excTmp2, *Q_bwe_exc)), White_exc16k[k]);/* (Q_bwe_exc) +5 +1*/ + L_tmp4 = L_mult( shr( excNoisyEnv[k], sub( Q_excTmp2, *Q_bwe_exc ) ), White_exc16k[k] ); /* (Q_bwe_exc) +5 +1*/ } White_exc16k_32[k] = L_tmp4; move32(); - L_tmp = L_max(L_tmp, L_abs(White_exc16k_32[k])); + L_tmp = L_max( L_tmp, L_abs( White_exc16k_32[k] ) ); } - Q_temp = norm_l(L_tmp); - IF (L_tmp == 0) + Q_temp = norm_l( L_tmp ); + IF( L_tmp == 0 ) { Q_temp = 31; } @@ -2944,48 +2940,50 @@ void GenShapedSHBExcitation_ivas_fx( /* calculate pow22 */ /* pow22=0.00001f */ - tmp = sub(shl(sub(Q_excTmp2, NOISE_QADJ), 1), 31); - pow22 = L_shl(21475l/*0.00001f Q31*/, tmp); /* 0.00001f in 2*(Q_excTmp2-NOISE_QADJ) */ - tmp = sub(NOISE_QFAC, 5); - FOR(k = 0; k < L_FRAME16k; k++) + tmp = sub( shl( sub( Q_excTmp2, NOISE_QADJ ), 1 ), 31 ); + pow22 = L_shl( 21475l /*0.00001f Q31*/, tmp ); /* 0.00001f in 2*(Q_excTmp2-NOISE_QADJ) */ + tmp = sub( NOISE_QFAC, 5 ); + FOR( k = 0; k < L_FRAME16k; k++ ) { /* White_exc16k[k] *= excNoisyEnv[k]; */ - White_exc16k[k] = mult_r(excNoisyEnv[k], shl(White_exc16k[k], tmp)); + White_exc16k[k] = mult_r( excNoisyEnv[k], shl( White_exc16k[k], tmp ) ); move16(); /* i: excNoisyEnv in (Q_bwe_exc) */ /* i: White_exc16k in Q6 */ /* o: White_exc16k in (Q_bwe_exc-NOISE_QADJ) */ /* pow22 += White_exc16k[k] * White_exc16k[k]; */ #ifdef BASOP_NOGLOB - pow22 = L_mac0_sat(pow22, White_exc16k[k], White_exc16k[k]); /* 2*(Q_bwe_exc-NOISE_QADJ)*/ + pow22 = L_mac0_sat( pow22, White_exc16k[k], White_exc16k[k] ); /* 2*(Q_bwe_exc-NOISE_QADJ)*/ #else - pow22 = L_mac0(pow22, White_exc16k[k], White_exc16k[k]); /* 2*(Q_bwe_exc-NOISE_QADJ)*/ + pow22 = L_mac0( pow22, White_exc16k[k], White_exc16k[k] ); /* 2*(Q_bwe_exc-NOISE_QADJ)*/ #endif } /*Q_pow22 = sub( shl(*Q_bwe_exc,1), 18 );*/ - Q_pow22 = shl(sub(Q_excTmp2, NOISE_QADJ), 1); - Scale_sig(White_exc16k, L_FRAME16k, sub(*Q_bwe_exc, Q_excTmp2)); + Q_pow22 = shl( sub( Q_excTmp2, NOISE_QADJ ), 1 ); + Scale_sig( White_exc16k, L_FRAME16k, sub( *Q_bwe_exc, Q_excTmp2 ) ); } -#if 1//def ADD_IVAS_TBE_CODE +#if 1 // def ADD_IVAS_TBE_CODE flag_plosive = 0; move16(); - test(); test(); test(); - IF(GE_32(extl_brate, SWB_TBE_2k8) || EQ_32(extl_brate, SWB_TBE_1k10) || EQ_32(extl_brate, SWB_TBE_1k75)) + test(); + test(); + test(); + IF( GE_32( extl_brate, SWB_TBE_2k8 ) || EQ_32( extl_brate, SWB_TBE_1k10 ) || EQ_32( extl_brate, SWB_TBE_1k75 ) ) #else - IF(GE_32(bitrate, ACELP_24k40)) + IF( GE_32( bitrate, ACELP_24k40 ) ) #endif { - IF(EQ_16(*vf_ind, 20)) /* encoder side */ + IF( EQ_16( *vf_ind, 20 ) ) /* encoder side */ { -#ifdef ADD_IVAS_TBE_CODE //BELOW PART WILL NEED TO BE CONVERTED FOR ENCODER!! - if (extl_brate == SWB_TBE_1k10 || extl_brate == SWB_TBE_1k75) +#ifdef ADD_IVAS_TBE_CODE // BELOW PART WILL NEED TO BE CONVERTED FOR ENCODER!! + if ( extl_brate == SWB_TBE_1k10 || extl_brate == SWB_TBE_1k75 ) { /* calculate TD envelopes of exc16kWhtnd and White_exc16k */ - find_td_envelope(White_exc16k, L_FRAME16k, 20, NULL, EnvWhiteExc16k); - find_td_envelope(exc16kWhtnd, L_FRAME16k, 20, NULL, EnvExc16kWhtnd); + find_td_envelope( White_exc16k, L_FRAME16k, 20, NULL, EnvWhiteExc16k ); + find_td_envelope( exc16kWhtnd, L_FRAME16k, 20, NULL, EnvExc16kWhtnd ); - for (k = 0; k < L_FRAME4k; k++) + for ( k = 0; k < L_FRAME4k; k++ ) { EnvWhiteExc16k_4k[k] = EnvWhiteExc16k[4 * k]; EnvExc16kWhtnd_4k[k] = EnvExc16kWhtnd[4 * k]; @@ -2993,14 +2991,14 @@ void GenShapedSHBExcitation_ivas_fx( /* calculate the optimal mix factor */ c0 = c1 = c2 = c3 = c4 = c5 = 0.0f; - for (i = 0; i < NUM_SHB_SUBGAINS; i++) + for ( i = 0; i < NUM_SHB_SUBGAINS; i++ ) { - c0_part[i] = sum2_f(&EnvExc16kWhtnd_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], L_FRAME4k / NUM_SHB_SUBGAINS); - c1_part[i] = -2.0f * dotp(&EnvSHBres_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], &EnvExc16kWhtnd_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], L_FRAME4k / NUM_SHB_SUBGAINS); - c2_part[i] = sum2_f(&EnvWhiteExc16k_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], L_FRAME4k / NUM_SHB_SUBGAINS); - c3_part[i] = -2.0f * dotp(&EnvSHBres_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], &EnvWhiteExc16k_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], L_FRAME4k / NUM_SHB_SUBGAINS); - c4_part[i] = 2.0f * dotp(&EnvExc16kWhtnd_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], &EnvWhiteExc16k_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], L_FRAME4k / NUM_SHB_SUBGAINS); - c5_part[i] = sum2_f(&EnvSHBres_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], L_FRAME4k / NUM_SHB_SUBGAINS); + c0_part[i] = sum2_f( &EnvExc16kWhtnd_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], L_FRAME4k / NUM_SHB_SUBGAINS ); + c1_part[i] = -2.0f * dotp( &EnvSHBres_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], &EnvExc16kWhtnd_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], L_FRAME4k / NUM_SHB_SUBGAINS ); + c2_part[i] = sum2_f( &EnvWhiteExc16k_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], L_FRAME4k / NUM_SHB_SUBGAINS ); + c3_part[i] = -2.0f * dotp( &EnvSHBres_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], &EnvWhiteExc16k_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], L_FRAME4k / NUM_SHB_SUBGAINS ); + c4_part[i] = 2.0f * dotp( &EnvExc16kWhtnd_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], &EnvWhiteExc16k_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], L_FRAME4k / NUM_SHB_SUBGAINS ); + c5_part[i] = sum2_f( &EnvSHBres_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], L_FRAME4k / NUM_SHB_SUBGAINS ); c0 += c0_part[i]; c1 += c1_part[i]; @@ -3011,24 +3009,24 @@ void GenShapedSHBExcitation_ivas_fx( } den = 4.0f * c0 * c2 - c4 * c4; - g1 = (c3 * c4 - 2 * c1 * c2) / den; - g2 = (c1 * c4 - 2 * c0 * c3) / den; + g1 = ( c3 * c4 - 2 * c1 * c2 ) / den; + g2 = ( c1 * c4 - 2 * c0 * c3 ) / den; *Env_error = 0.0f; flag_plosive = 0; - for (i = 0; i < NUM_SHB_SUBGAINS; i++) + for ( i = 0; i < NUM_SHB_SUBGAINS; i++ ) { Env_error_part[i] = c5_part[i] + g1 * g1 * c0_part[i] + g1 * c1_part[i] + g2 * g2 * c2_part[i] + g2 * c3_part[i] + g1 * g2 * c4_part[i]; *Env_error += Env_error_part[i]; - if (Env_error_part[i] > THR_ENV_ERROR_PLOSIVE) + if ( Env_error_part[i] > THR_ENV_ERROR_PLOSIVE ) { /* envelope error is too high -> likely a plosive */ flag_plosive = 1; } } - if (flag_plosive) + if ( flag_plosive ) { /* plosive detected -> set the mixing factor to 0 */ *vf_ind = 0; @@ -3037,213 +3035,214 @@ void GenShapedSHBExcitation_ivas_fx( else { /* normalize gain */ - g = g2 / (g1 + g2); + g = g2 / ( g1 + g2 ); /* quantization of the mixing factor */ cbsize = 1 << NUM_BITS_SHB_VF; - delta = 1.0f / (cbsize - 1); - if (g > 1.0f) + delta = 1.0f / ( cbsize - 1 ); + if ( g > 1.0f ) { g = 1.0f; } - else if (g < delta) + else if ( g < delta ) { /* prevent low gains to be quantized to 0 as this is reserved for plosives */ g = delta; } - *vf_ind = usquant(g, &mix_factor, 0.0f, 1.0f / (cbsize - 1), cbsize); + *vf_ind = usquant( g, &mix_factor, 0.0f, 1.0f / ( cbsize - 1 ), cbsize ); } } else #else - UNUSED_PARAM(Env_error_part); - UNUSED_PARAM(Env_error); - UNUSED_PARAM(EnvSHBres_4k); - UNUSED_PARAM(c5_part); - UNUSED_PARAM(c1); - UNUSED_PARAM(den); - UNUSED_PARAM(c3_part); - UNUSED_PARAM(c0); - UNUSED_PARAM(delta); - UNUSED_PARAM(c3); - UNUSED_PARAM(c2_part); - UNUSED_PARAM(c1_part); - UNUSED_PARAM(EnvWhiteExc16k); - UNUSED_PARAM(g2); - UNUSED_PARAM(c5); - UNUSED_PARAM(c4_part); - UNUSED_PARAM(EnvWhiteExc16k_4k); - UNUSED_PARAM(c2); - UNUSED_PARAM(g); - UNUSED_PARAM(cbsize); - UNUSED_PARAM(g1); - UNUSED_PARAM(EnvExc16kWhtnd); - UNUSED_PARAM(c0_part); - UNUSED_PARAM(EnvExc16kWhtnd_4k); - UNUSED_PARAM(c4); + UNUSED_PARAM( Env_error_part ); + UNUSED_PARAM( Env_error ); + UNUSED_PARAM( EnvSHBres_4k ); + UNUSED_PARAM( c5_part ); + UNUSED_PARAM( c1 ); + UNUSED_PARAM( den ); + UNUSED_PARAM( c3_part ); + UNUSED_PARAM( c0 ); + UNUSED_PARAM( delta ); + UNUSED_PARAM( c3 ); + UNUSED_PARAM( c2_part ); + UNUSED_PARAM( c1_part ); + UNUSED_PARAM( EnvWhiteExc16k ); + UNUSED_PARAM( g2 ); + UNUSED_PARAM( c5 ); + UNUSED_PARAM( c4_part ); + UNUSED_PARAM( EnvWhiteExc16k_4k ); + UNUSED_PARAM( c2 ); + UNUSED_PARAM( g ); + UNUSED_PARAM( cbsize ); + UNUSED_PARAM( g1 ); + UNUSED_PARAM( EnvExc16kWhtnd ); + UNUSED_PARAM( c0_part ); + UNUSED_PARAM( EnvExc16kWhtnd_4k ); + UNUSED_PARAM( c4 ); #endif { - Estimate_mix_factors_fx(shb_res, Q_shb, exc16kWhtnd, *Q_bwe_exc, White_exc16k, - (*Q_bwe_exc - NOISE_QADJ), pow1, Q_pow1, pow22, Q_pow22, voiceFacEst, vf_ind); + Estimate_mix_factors_fx( shb_res, Q_shb, exc16kWhtnd, *Q_bwe_exc, White_exc16k, + ( *Q_bwe_exc - NOISE_QADJ ), pow1, Q_pow1, pow22, Q_pow22, voiceFacEst, vf_ind ); tmp = voiceFacEst[0]; tmp2 = MAX_16; - if (LE_16(tmp, 22938/*0.7f Q15*/)) + if ( LE_16( tmp, 22938 /*0.7f Q15*/ ) ) { - tmp2 = 26214/*0.8f Q15*/; + tmp2 = 26214 /*0.8f Q15*/; } } } ELSE /* decoder side */ { -#if 1//def ADD_IVAS_TBE_CODE - IF (extl_brate == SWB_TBE_1k10 || extl_brate == SWB_TBE_1k75) +#if 1 // def ADD_IVAS_TBE_CODE + IF( extl_brate == SWB_TBE_1k10 || extl_brate == SWB_TBE_1k75 ) { - IF (*vf_ind == 0) + IF( *vf_ind == 0 ) { - //mix_factor = 0.0f; + // mix_factor = 0.0f; mix_factor = 0; flag_plosive = 1; } ELSE { - //mix_factor = usdequant(*vf_ind, 0.0f, 1.0f / ((1 << NUM_BITS_SHB_VF) - 1)); - mix_factor = usdequant_fx(*vf_ind, 0, 2341); + // mix_factor = usdequant(*vf_ind, 0.0f, 1.0f / ((1 << NUM_BITS_SHB_VF) - 1)); + mix_factor = usdequant_fx( *vf_ind, 0, 2341 ); } } ELSE #endif { /* *vf_ind is an integer scale by 0.125f*/ - tmp = shl(*vf_ind, (15 - 3)); + tmp = shl( *vf_ind, ( 15 - 3 ) ); tmp2 = MAX_16; - IF (LE_16(tmp, 22938/*0.7f Q15*/)) + IF( LE_16( tmp, 22938 /*0.7f Q15*/ ) ) { - tmp2 = 26214/*0.8f Q15*/; + tmp2 = 26214 /*0.8f Q15*/; } } } -#if 1//def ADD_IVAS_TBE_CODE - IF(NE_32(extl_brate, SWB_TBE_1k10) && NE_32(extl_brate, SWB_TBE_1k75)) +#if 1 // def ADD_IVAS_TBE_CODE + IF( NE_32( extl_brate, SWB_TBE_1k10 ) && NE_32( extl_brate, SWB_TBE_1k75 ) ) #endif { - voice_factors[0] = mult_r(voice_factors[0], tmp2); + voice_factors[0] = mult_r( voice_factors[0], tmp2 ); move16(); - voice_factors[1] = mult_r(voice_factors[1], tmp2); + voice_factors[1] = mult_r( voice_factors[1], tmp2 ); move16(); - voice_factors[2] = mult_r(voice_factors[2], tmp2); + voice_factors[2] = mult_r( voice_factors[2], tmp2 ); move16(); - voice_factors[3] = mult_r(voice_factors[3], tmp2); + voice_factors[3] = mult_r( voice_factors[3], tmp2 ); move16(); - voice_factors[4] = mult_r(voice_factors[4], tmp2); + voice_factors[4] = mult_r( voice_factors[4], tmp2 ); move16(); } } -#if 1//def ADD_IVAS_TBE_CODE - IF (element_mode >= IVAS_CPE_DFT && nlExc16k != NULL) +#if 1 // def ADD_IVAS_TBE_CODE + IF( element_mode >= IVAS_CPE_DFT && nlExc16k != NULL ) { /* save buffers for IC-BWE */ - //mvr2r(exc16kWhtnd, nlExc16k, L_FRAME16k); - Copy(exc16kWhtnd, nlExc16k, L_FRAME16k); - //v_multc(White_exc16k, (float)sqrt(pow1 / pow22), mixExc16k, L_FRAME16k); + // mvr2r(exc16kWhtnd, nlExc16k, L_FRAME16k); + Copy( exc16kWhtnd, nlExc16k, L_FRAME16k ); + // v_multc(White_exc16k, (float)sqrt(pow1 / pow22), mixExc16k, L_FRAME16k); /*Word16 temp_fac = divide3232(L_shr(pow1, Q_pow1), pow22); Word16 temp_fac_exp = 0; temp_fac = Sqrt16(temp_fac, &temp_fac_exp);*/ - L_tmp = root_a_over_b_fx(pow1, Q_pow1, pow22, Q_pow22, &exp); - Word16 temp_fac = round_fx_sat(L_shl_sat(L_tmp, exp)); //Q15 - //v_multc_fixed_16_16(White_exc16k,shr(temp_fac, temp_fac_exp) , mixExc16k, L_FRAME16k); - FOR (k = 0; k < L_FRAME16k; k++) { - mixExc16k[k] = mult_r(White_exc16k[k], temp_fac); + L_tmp = root_a_over_b_fx( pow1, Q_pow1, pow22, Q_pow22, &exp ); + Word16 temp_fac = round_fx_sat( L_shl_sat( L_tmp, exp ) ); // Q15 + // v_multc_fixed_16_16(White_exc16k,shr(temp_fac, temp_fac_exp) , mixExc16k, L_FRAME16k); + FOR( k = 0; k < L_FRAME16k; k++ ) + { + mixExc16k[k] = mult_r( White_exc16k[k], temp_fac ); } } #endif - tmp = sub(Q_temp, 3); - FOR(k = 0; k < L_FRAME16k; k++) + tmp = sub( Q_temp, 3 ); + FOR( k = 0; k < L_FRAME16k; k++ ) { - White_exc16k_FB[k] = round_fx(L_shl(White_exc16k_32[k], tmp)); /* Q_bwe_exc +5 +1 +Q_temp -16 -3 */ + White_exc16k_FB[k] = round_fx( L_shl( White_exc16k_32[k], tmp ) ); /* Q_bwe_exc +5 +1 +Q_temp -16 -3 */ } prev_Q_bwe_exc_fb = *Q_bwe_exc_fb; - *Q_bwe_exc_fb = sub(add(*Q_bwe_exc, Q_temp), 13); + *Q_bwe_exc_fb = sub( add( *Q_bwe_exc, Q_temp ), 13 ); - deemph_fx(White_exc16k, PREEMPH_FAC, L_FRAME16k, tbe_demph); + deemph_fx( White_exc16k, PREEMPH_FAC, L_FRAME16k, tbe_demph ); /* i/o: White_exc16k (Q_bwe_exc-NOISE_QADJ) */ /* i: tbe_demph (Q_bwe_exc-NOISE_QADJ) */ -#if 1//def ADD_IVAS_TBE_CODE - IF (extl_brate == SWB_TBE_1k10 || extl_brate == SWB_TBE_1k75) +#if 1 // def ADD_IVAS_TBE_CODE + IF( extl_brate == SWB_TBE_1k10 || extl_brate == SWB_TBE_1k75 ) { - IF (!flag_plosive) /* use only LB excitation in case of plosives */ + IF( !flag_plosive ) /* use only LB excitation in case of plosives */ { /* re-scale gaussian excitation at the beginning to gradually move from old energy to new energy */ - //old_scale = (float)sqrt(*prev_pow_exc16kWhtnd / pow1); - //old_scale = divide3232(*prev_pow_exc16kWhtnd, pow1); // exp = Q15 - (Q_pow1) - //Word16 old_scale_exp = Q15 - (Q_pow1); - //old_scale = Sqrt16(old_scale, &old_scale_exp); - //old_scale = shl(old_scale, old_scale_exp); //Q15 - L_tmp = root_a_over_b_fx(*prev_pow_exc16kWhtnd, 0, pow1, Q_pow1, &exp); - old_scale = round_fx_sat(L_shl_sat(L_tmp, exp)); //Q15 - //new_scale = 1.0f; + // old_scale = (float)sqrt(*prev_pow_exc16kWhtnd / pow1); + // old_scale = divide3232(*prev_pow_exc16kWhtnd, pow1); // exp = Q15 - (Q_pow1) + // Word16 old_scale_exp = Q15 - (Q_pow1); + // old_scale = Sqrt16(old_scale, &old_scale_exp); + // old_scale = shl(old_scale, old_scale_exp); //Q15 + L_tmp = root_a_over_b_fx( *prev_pow_exc16kWhtnd, 0, pow1, Q_pow1, &exp ); + old_scale = round_fx_sat( L_shl_sat( L_tmp, exp ) ); // Q15 + // new_scale = 1.0f; new_scale = 32767; - //step_scale = (new_scale - old_scale) / (L_FRAME16k / 2); - step_scale = mult_r(sub(new_scale, old_scale), 205); + // step_scale = (new_scale - old_scale) / (L_FRAME16k / 2); + step_scale = mult_r( sub( new_scale, old_scale ), 205 ); scale = old_scale; /* interpolate between the old and the new value of the mixing factor */ old_fact = *prev_mix_factor; new_fact = mix_factor; - //step = (new_fact - old_fact) / (L_FRAME16k / 2); - step = mult_r(sub(new_fact, old_fact), 205); + // step = (new_fact - old_fact) / (L_FRAME16k / 2); + step = mult_r( sub( new_fact, old_fact ), 205 ); fact = old_fact; /* mixing of LB and gaussian excitation in the first half of the frame */ - FOR (k = 0; k < L_FRAME16k / 2; k++) + FOR( k = 0; k < L_FRAME16k / 2; k++ ) { - //exc16kWhtnd[k] = (float)fact * (White_exc16k[k] * scale) + (float)(1 - fact) * exc16kWhtnd[k]; - //exc16kWhtnd[k] = add(mult_r(fact, mult(shl(White_exc16k[k], *Q_bwe_exc), scale)), mult_r(sub(32767, fact), exc16kWhtnd[k])); + // exc16kWhtnd[k] = (float)fact * (White_exc16k[k] * scale) + (float)(1 - fact) * exc16kWhtnd[k]; + // exc16kWhtnd[k] = add(mult_r(fact, mult(shl(White_exc16k[k], *Q_bwe_exc), scale)), mult_r(sub(32767, fact), exc16kWhtnd[k])); L_tmp = L_add( L_shl( L_mult( fact, mult_r( White_exc16k[k], scale ) ), NOISE_QADJ ), L_mult( sub( 32767, fact ), exc16kWhtnd[k] ) ); // Q_bwe_exc exc16kWhtnd[k] = round_fx( L_tmp ); - fact = add_sat(fact, step); - scale = add_sat(scale, step_scale); + fact = add_sat( fact, step ); + scale = add_sat( scale, step_scale ); } /* mixing of LB and gaussian excitation in the second half of the frame */ - FOR (; k < L_FRAME16k; k++) + FOR( ; k < L_FRAME16k; k++ ) { - //exc16kWhtnd[k] = (float)new_fact * White_exc16k[k] + (float)(1 - new_fact) * exc16kWhtnd[k]; - //exc16kWhtnd[k] = add(mult_r(new_fact, shl(White_exc16k[k], *Q_bwe_exc)), mult_r(sub(32767, new_fact), exc16kWhtnd[k])); + // exc16kWhtnd[k] = (float)new_fact * White_exc16k[k] + (float)(1 - new_fact) * exc16kWhtnd[k]; + // exc16kWhtnd[k] = add(mult_r(new_fact, shl(White_exc16k[k], *Q_bwe_exc)), mult_r(sub(32767, new_fact), exc16kWhtnd[k])); L_tmp = L_add( L_shl( L_mult( new_fact, White_exc16k[k] ), NOISE_QADJ ), mult_r( sub( 32767, new_fact ), exc16kWhtnd[k] ) ); // Q_bwe_exc exc16kWhtnd[k] = round_fx( L_tmp ); } } - //preemph(exc16kWhtnd, PREEMPH_FAC, L_FRAME16k, tbe_premph); - preemph_fx(exc16kWhtnd, PREEMPH_FAC, L_FRAME16k, tbe_premph); + // preemph(exc16kWhtnd, PREEMPH_FAC, L_FRAME16k, tbe_premph); + preemph_fx( exc16kWhtnd, PREEMPH_FAC, L_FRAME16k, tbe_premph ); } ELSE #endif { -#if 1//def ADD_IVAS_TBE_CODE - IF (coder_type == UNVOICED || MSFlag == 1) +#if 1 // def ADD_IVAS_TBE_CODE + IF( coder_type == UNVOICED || MSFlag == 1 ) #else - IF(EQ_16(coder_type, UNVOICED)) + IF( EQ_16( coder_type, UNVOICED ) ) #endif { - L_tmp = root_a_over_b_fx(pow1, Q_pow1, pow22, Q_pow22, &exp); + L_tmp = root_a_over_b_fx( pow1, Q_pow1, pow22, Q_pow22, &exp ); #ifdef BASOP_NOGLOB - scale = round_fx_sat(L_shl_sat(L_tmp, exp)); /*Q15 */ + scale = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /*Q15 */ #else - scale = round_fx(L_shl(L_tmp, exp)); /*Q15 */ + scale = round_fx( L_shl( L_tmp, exp ) ); /*Q15 */ #endif - FOR(k = 0; k < L_FRAME16k; k++) + FOR( k = 0; k < L_FRAME16k; k++ ) { /* White_exc16k: (Q_bwe_exc-NOISE_QADJ), scale: Q15 */ - L_tmp = L_mult(White_exc16k[k], scale); + L_tmp = L_mult( White_exc16k[k], scale ); /* L_tmp: (Q_bwe_exc-NOISE_QADJ) + 15 + 1 */ - exc16kWhtnd[k] = round_fx(L_shl(L_tmp, NOISE_QADJ)); + exc16kWhtnd[k] = round_fx( L_shl( L_tmp, NOISE_QADJ ) ); /* exc16kWhtnd: Q_bwe_exc */ } - preemph_fx(exc16kWhtnd, PREEMPH_FAC, L_FRAME16k, tbe_premph); + preemph_fx( exc16kWhtnd, PREEMPH_FAC, L_FRAME16k, tbe_premph ); /* i/o: exc16kWhtnd (Q_bwe_exc) */ /* i/o: tbe_premph (Q_bwe_exc) */ } @@ -3254,148 +3253,148 @@ void GenShapedSHBExcitation_ivas_fx( Word32 tempQ31; /*nbSubFr = ( bitrate < ACELP_24k40 )? NB_SUBFR : NB_SUBFR16k;*/ nbSubFr = NB_SUBFR16k; - lSubFr = (L_FRAME16k / NB_SUBFR16k); - IF(LT_32(bitrate, ACELP_24k40)) + lSubFr = ( L_FRAME16k / NB_SUBFR16k ); + IF( LT_32( bitrate, ACELP_24k40 ) ) { nbSubFr = NB_SUBFR; move16(); - lSubFr = (L_FRAME16k / NB_SUBFR); + lSubFr = ( L_FRAME16k / NB_SUBFR ); move16(); } k = 0; - FOR(i = 0; i < nbSubFr; i++) + FOR( i = 0; i < nbSubFr; i++ ) { test(); - IF(EQ_16(coder_type, VOICED) && (LT_32(bitrate,ACELP_24k40))) + IF( EQ_16( coder_type, VOICED ) && ( LT_32( bitrate, ACELP_24k40 ) ) ) { exp = 0; - tempQ15 = Sqrt16(voice_factors[i], &exp); /* Q15 */ - temp = shl(tempQ15, exp); /* Q15 exc16kWhtnd scale factor */ + tempQ15 = Sqrt16( voice_factors[i], &exp ); /* Q15 */ + temp = shl( tempQ15, exp ); /* Q15 exc16kWhtnd scale factor */ exp = 0; - tempQ15 = Sqrt16(temp, &exp); /* Q15 */ - temp1 = shl(tempQ15, exp); /* Q15 exc16kWhtnd scale factor */ + tempQ15 = Sqrt16( temp, &exp ); /* Q15 */ + temp1 = shl( tempQ15, exp ); /* Q15 exc16kWhtnd scale factor */ /*temp2 = root_a_over_b_fx( pow1 * (1.0f - temp), pow22 ); */ - temp = sub(MAX_16, temp); - tempQ31 = Mult_32_16(pow1, temp); - L_tmp = root_a_over_b_fx(tempQ31, Q_pow1, pow22, Q_pow22, &exp); + temp = sub( MAX_16, temp ); + tempQ31 = Mult_32_16( pow1, temp ); + L_tmp = root_a_over_b_fx( tempQ31, Q_pow1, pow22, Q_pow22, &exp ); #ifdef BASOP_NOGLOB - temp2 = round_fx_sat(L_shl_sat(L_tmp, exp)); /* Q15 whiteEnvShapedExc scale factor */ + temp2 = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q15 whiteEnvShapedExc scale factor */ #else - temp2 = round_fx(L_shl(L_tmp, exp)); /* Q15 whiteEnvShapedExc scale factor */ + temp2 = round_fx( L_shl( L_tmp, exp ) ); /* Q15 whiteEnvShapedExc scale factor */ #endif } ELSE { /* Adjust noise mixing for formant sharpening filter */ - tempQ15 = mult_r(SWB_NOISE_MIX_FAC_FX, formant_fac); - /* vf_tmp = voice_factors[i] * (1.0f - vf_tmp); */ - vf_tmp = sub(MAX_16, tempQ15); - vf_tmp = mult_r(voice_factors[i], vf_tmp); + tempQ15 = mult_r( SWB_NOISE_MIX_FAC_FX, formant_fac ); + /* vf_tmp = voice_factors[i] * (1.0f - vf_tmp); */ + vf_tmp = sub( MAX_16, tempQ15 ); + vf_tmp = mult_r( voice_factors[i], vf_tmp ); - exp = 0; - tempQ15 = Sqrt16(vf_tmp, &exp); /* Q15 */ - temp1 = shl(tempQ15, exp); /* Q15 exc16kWhtnd scale factor */ + exp = 0; + tempQ15 = Sqrt16( vf_tmp, &exp ); /* Q15 */ + temp1 = shl( tempQ15, exp ); /* Q15 exc16kWhtnd scale factor */ - /*temp2 = root_a_over_b(pow1 * (1.0f - vf_tmp), pow22); */ - temp = sub(MAX_16, vf_tmp); - tempQ31 = Mult_32_16(pow1, temp); - L_tmp = root_a_over_b_fx(tempQ31, Q_pow1, pow22, Q_pow22, &exp); + /*temp2 = root_a_over_b(pow1 * (1.0f - vf_tmp), pow22); */ + temp = sub( MAX_16, vf_tmp ); + tempQ31 = Mult_32_16( pow1, temp ); + L_tmp = root_a_over_b_fx( tempQ31, Q_pow1, pow22, Q_pow22, &exp ); #ifdef BASOP_NOGLOB - temp2 = round_fx_sat(L_shl_sat(L_tmp, exp)); /* Q15 whiteEnvShapedExc scale factor */ + temp2 = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q15 whiteEnvShapedExc scale factor */ #else - temp2 = round_fx(L_shl(L_tmp, exp)); /* Q15 whiteEnvShapedExc scale factor */ + temp2 = round_fx( L_shl( L_tmp, exp ) ); /* Q15 whiteEnvShapedExc scale factor */ #endif } - FOR(j = 0; j < lSubFr; j++) + FOR( j = 0; j < lSubFr; j++ ) { /*exc16kWhtnd[k+j] = temp1 * exc16kWhtnd[k+j] + temp2 * White_exc16k[k+j]; */ - L_tmp = L_mult(temp2, White_exc16k[k + j]); /* 16+(Q_bwe_exc-NOISE_QADJ)*/ + L_tmp = L_mult( temp2, White_exc16k[k + j] ); /* 16+(Q_bwe_exc-NOISE_QADJ)*/ #ifdef BASOP_NOGLOB - L_tmp = L_shl_sat(L_tmp, NOISE_QADJ); /* 16+(Q_bwe_exc) */ - exc16kWhtnd[k + j] = mac_r_sat(L_tmp, temp1, exc16kWhtnd[k + j]); + L_tmp = L_shl_sat( L_tmp, NOISE_QADJ ); /* 16+(Q_bwe_exc) */ + exc16kWhtnd[k + j] = mac_r_sat( L_tmp, temp1, exc16kWhtnd[k + j] ); #else - L_tmp = L_shl(L_tmp, NOISE_QADJ); /* 16+(Q_bwe_exc) */ - exc16kWhtnd[k + j] = mac_r(L_tmp, temp1, exc16kWhtnd[k + j]); + L_tmp = L_shl( L_tmp, NOISE_QADJ ); /* 16+(Q_bwe_exc) */ + exc16kWhtnd[k + j] = mac_r( L_tmp, temp1, exc16kWhtnd[k + j] ); #endif move16(); /* Q_bwe_exc */ } - k = add(k, lSubFr); + k = add( k, lSubFr ); /* estimate the pre-emph factor */ - tempQ15 = sub(MAX_16, voice_factors[i]); + tempQ15 = sub( MAX_16, voice_factors[i] ); exp = 0; - temp = Sqrt16(tempQ15, &exp); - temp = shl(temp, exp - 1); + temp = Sqrt16( tempQ15, &exp ); + temp = shl( temp, exp - 1 ); - temp2 = add(temp, shl(temp1, -1)); /* shift right by 1 to avoid overflow */ - temp = div_s(temp, temp2); /* Q15 */ - temp = mult_r(PREEMPH_FAC, temp); + temp2 = add( temp, shl( temp1, -1 ) ); /* shift right by 1 to avoid overflow */ + temp = div_s( temp, temp2 ); /* Q15 */ + temp = mult_r( PREEMPH_FAC, temp ); - preemph_fx(&exc16kWhtnd[i * lSubFr], temp, lSubFr, tbe_premph); + preemph_fx( &exc16kWhtnd[i * lSubFr], temp, lSubFr, tbe_premph ); /* exc16kWhtnd: Q_bwe_exc; tbe_premph: Q_bwe_exc*/ } } } -#if 1//def ADD_IVAS_TBE_CODE - IF(LT_32(extl_brate, SWB_TBE_2k8)) +#if 1 // def ADD_IVAS_TBE_CODE + IF( LT_32( extl_brate, SWB_TBE_2k8 ) ) #else - IF(LT_32(bitrate, ACELP_24k40)) + IF( LT_32( bitrate, ACELP_24k40 ) ) #endif { - Syn_filt_s(0, lpc_shb, LPC_SHB_ORDER, exc16kWhtnd, excSHB, L_FRAME16k, state_lpc_syn, 1); + Syn_filt_s( 0, lpc_shb, LPC_SHB_ORDER, exc16kWhtnd, excSHB, L_FRAME16k, state_lpc_syn, 1 ); /* i: exc16kWhtnd in Q_bwe_exc */ /* o: excSHB in Q_bwe_exc */ } ELSE { - set16_fx(zero_mem, 0, LPC_SHB_ORDER); + set16_fx( zero_mem, 0, LPC_SHB_ORDER ); - Syn_filt_s(0, lpc_shb_sf, LPC_SHB_ORDER, exc16kWhtnd, tempSHB, 80, zero_mem, 1); - syn_shb_ener_sf[0] = L_shr(sum2_fx(tempSHB, 80),3); + Syn_filt_s( 0, lpc_shb_sf, LPC_SHB_ORDER, exc16kWhtnd, tempSHB, 80, zero_mem, 1 ); + syn_shb_ener_sf[0] = L_shr( sum2_fx( tempSHB, 80 ), 3 ); move32(); - Syn_filt_s(0, lpc_shb_sf + (LPC_SHB_ORDER + 1), LPC_SHB_ORDER, exc16kWhtnd + 80, tempSHB, 80, zero_mem, 1); - syn_shb_ener_sf[1] = L_shr(sum2_fx(tempSHB, 80),3); + Syn_filt_s( 0, lpc_shb_sf + ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 80, tempSHB, 80, zero_mem, 1 ); + syn_shb_ener_sf[1] = L_shr( sum2_fx( tempSHB, 80 ), 3 ); move32(); - Syn_filt_s(0, lpc_shb_sf + 2 * (LPC_SHB_ORDER + 1), LPC_SHB_ORDER, exc16kWhtnd + 160, tempSHB, 80, zero_mem, 1); - syn_shb_ener_sf[2] = L_shr(sum2_fx(tempSHB, 80),3); + Syn_filt_s( 0, lpc_shb_sf + 2 * ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 160, tempSHB, 80, zero_mem, 1 ); + syn_shb_ener_sf[2] = L_shr( sum2_fx( tempSHB, 80 ), 3 ); move32(); - Syn_filt_s(0, lpc_shb_sf + 3 * (LPC_SHB_ORDER + 1), LPC_SHB_ORDER, exc16kWhtnd + 240, tempSHB, 80, zero_mem, 1); - syn_shb_ener_sf[3] = L_shr(sum2_fx(tempSHB, 80),3); + Syn_filt_s( 0, lpc_shb_sf + 3 * ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 240, tempSHB, 80, zero_mem, 1 ); + syn_shb_ener_sf[3] = L_shr( sum2_fx( tempSHB, 80 ), 3 ); move32(); /* i: exc16kWhtnd in Q_bwe_exc */ /* o: tempSHB in Q_bwe_exc */ /* o: syn_shb_ener_sf in (2*Q_bwe_exc+1) */ - IF(LE_32(bitrate, MAX_ACELP_BRATE)) + IF( LE_32( bitrate, MAX_ACELP_BRATE ) ) { - L_tmp = sum32_fx(syn_shb_ener_sf, 4); + L_tmp = sum32_fx( syn_shb_ener_sf, 4 ); /* find root_a(tempSHB[0]) = root_a_over_b(shb_ener_sf[0]), L_tmp) */ - tmp = shl(Q_shb, 1); - tmp2 = add(shl(*Q_bwe_exc, 1), 1); - L_tmp2 = root_a_over_b_fx(shb_ener_sf_32, tmp, L_tmp, tmp2, &exp); /* L_tmp2 in (Q31-exp) */ + tmp = shl( Q_shb, 1 ); + tmp2 = add( shl( *Q_bwe_exc, 1 ), 1 ); + L_tmp2 = root_a_over_b_fx( shb_ener_sf_32, tmp, L_tmp, tmp2, &exp ); /* L_tmp2 in (Q31-exp) */ - *Q_bwe_exc = sub(*Q_bwe_exc, exp); + *Q_bwe_exc = sub( *Q_bwe_exc, exp ); move16(); /* compensate for the exp shift */ - tmp2 = add(prev_Q_bwe_syn, n_mem2); - IF(GT_16(*Q_bwe_exc, tmp2)) + tmp2 = add( prev_Q_bwe_syn, n_mem2 ); + IF( GT_16( *Q_bwe_exc, tmp2 ) ) { - L_tmp2 = L_shl(L_tmp2, sub(tmp2, *Q_bwe_exc)); + L_tmp2 = L_shl( L_tmp2, sub( tmp2, *Q_bwe_exc ) ); *Q_bwe_exc = tmp2; move16(); } - FOR(i = 0; i < L_FRAME16k; i++) + FOR( i = 0; i < L_FRAME16k; i++ ) { - L_tmp3 = Mult_32_16(L_tmp2, exc16kWhtnd[i]); /* *Q_bwe_exc + (31-exp) - 15 */ - exc16kWhtnd[i] = round_fx(L_tmp3); /* *Q_bwe_exc - exp */ + L_tmp3 = Mult_32_16( L_tmp2, exc16kWhtnd[i] ); /* *Q_bwe_exc + (31-exp) - 15 */ + exc16kWhtnd[i] = round_fx( L_tmp3 ); /* *Q_bwe_exc - exp */ } } /* i: L_tmp2 in (Q31-exp) */ @@ -3403,59 +3402,58 @@ void GenShapedSHBExcitation_ivas_fx( /* o: exc16kWhtnd in Q_bwe_exc: (Q_bwe_exc-exp) */ /* Rescale the past memories: LP synth and SHB look ahead buffers */ - tmp = sub(*Q_bwe_exc, prev_Q_bwe_syn); - FOR(i = 0; i < LPC_SHB_ORDER; i++) + tmp = sub( *Q_bwe_exc, prev_Q_bwe_syn ); + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - state_lpc_syn[i] = shl_sat(state_lpc_syn[i], tmp); + state_lpc_syn[i] = shl_sat( state_lpc_syn[i], tmp ); move16(); } - FOR(i = -L_SHB_LAHEAD; i < 0; i++) + FOR( i = -L_SHB_LAHEAD; i < 0; i++ ) { - excSHB[i] = shl_sat(excSHB[i], tmp); + excSHB[i] = shl_sat( excSHB[i], tmp ); move16(); } /* Do mem_stp_swb_fx scaling before PostShortTerm_fx */ - Syn_filt_s(0, lpc_shb_sf, LPC_SHB_ORDER, exc16kWhtnd, excSHB, 80, state_lpc_syn, 1); - Syn_filt_s(0, lpc_shb_sf + (LPC_SHB_ORDER + 1), LPC_SHB_ORDER, exc16kWhtnd + 80, excSHB + 80, 80, state_lpc_syn, 1); - Syn_filt_s(0, lpc_shb_sf + 2 * (LPC_SHB_ORDER + 1), LPC_SHB_ORDER, exc16kWhtnd + 160, excSHB + 160, 80, state_lpc_syn, 1); - Syn_filt_s(0, lpc_shb_sf + 3 * (LPC_SHB_ORDER + 1), LPC_SHB_ORDER, exc16kWhtnd + 240, excSHB + 240, 80, state_lpc_syn, 1); + Syn_filt_s( 0, lpc_shb_sf, LPC_SHB_ORDER, exc16kWhtnd, excSHB, 80, state_lpc_syn, 1 ); + Syn_filt_s( 0, lpc_shb_sf + ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 80, excSHB + 80, 80, state_lpc_syn, 1 ); + Syn_filt_s( 0, lpc_shb_sf + 2 * ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 160, excSHB + 160, 80, state_lpc_syn, 1 ); + Syn_filt_s( 0, lpc_shb_sf + 3 * ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 240, excSHB + 240, 80, state_lpc_syn, 1 ); /* i: exc16kWhtnd in (Q_bwe_exc) */ /* o: excSHB in (Q_bwe_exc) */ } - IF(EQ_16(extl, FB_TBE)) + IF( EQ_16( extl, FB_TBE ) ) { - tmp = sub(add(*Q_bwe_exc_fb, 20), prev_Q_bwe_exc_fb); - Scale_sig(fb_state_lpc_syn, LPC_SHB_ORDER, tmp); - Scale_sig(fb_tbe_demph, 1, tmp); - Syn_filt_s(0, lpc_shb, LPC_SHB_ORDER, White_exc16k_FB, White_exc16k_FB_temp, L_FRAME16k, fb_state_lpc_syn, 1); + tmp = sub( add( *Q_bwe_exc_fb, 20 ), prev_Q_bwe_exc_fb ); + Scale_sig( fb_state_lpc_syn, LPC_SHB_ORDER, tmp ); + Scale_sig( fb_tbe_demph, 1, tmp ); + Syn_filt_s( 0, lpc_shb, LPC_SHB_ORDER, White_exc16k_FB, White_exc16k_FB_temp, L_FRAME16k, fb_state_lpc_syn, 1 ); /* i: White_exc16k_FB in (14-n2) */ /* o: White_exc16k_FB_temp in (14-n2) */ - FOR(i = 0; i < 10; i++) + FOR( i = 0; i < 10; i++ ) { - FOR(j = 0; j < 32; ++j) + FOR( j = 0; j < 32; ++j ) { - White_exc16k_FB_temp[i * 32 + j] = mult_r(White_exc16k_FB_temp[i * 32 + j], cos_fb_exc_fx[j]); + White_exc16k_FB_temp[i * 32 + j] = mult_r( White_exc16k_FB_temp[i * 32 + j], cos_fb_exc_fx[j] ); move16(); } } - *Q_bwe_exc_fb = add(*Q_bwe_exc_fb, 20); + *Q_bwe_exc_fb = add( *Q_bwe_exc_fb, 20 ); move16(); /**Q_bwe_exc_fb +35 +1 -16*/ - flip_spectrum_fx(White_exc16k_FB_temp, White_exc16k_FB, L_FRAME16k); - - deemph_fx(White_exc16k_FB, fb_deemph_fac, L_FRAME16k, fb_tbe_demph); + flip_spectrum_fx( White_exc16k_FB_temp, White_exc16k_FB, L_FRAME16k ); + deemph_fx( White_exc16k_FB, fb_deemph_fac, L_FRAME16k, fb_tbe_demph ); } ELSE { - set16_fx(White_exc16k_FB, 0, L_FRAME16k); + set16_fx( White_exc16k_FB, 0, L_FRAME16k ); } -#if 1//def ADD_IVAS_TBE_CODE - *prev_pow_exc16kWhtnd = L_shr_sat(pow1, Q_pow1); // power goes above MAX_32 +#if 1 // def ADD_IVAS_TBE_CODE + *prev_pow_exc16kWhtnd = L_shr_sat( pow1, Q_pow1 ); // power goes above MAX_32 *prev_mix_factor = mix_factor; #endif return; @@ -3482,13 +3480,12 @@ void GenShapedSHBExcitation_ivas_fx( /*------------------------------------------------------------------------------------*/ void GenSHBSynth_fx( - const Word16* input_synspeech, /* i : input synthesized speech */ - Word16* shb_syn_speech_32k, /* o : output highband component */ - Word32 Hilbert_Mem[], /* i/o: memory */ - Word16 allpass_mem[], /* i/o: memory */ - const Word16 L_frame, /* i : ACELP frame length */ - Word16* syn_dm_phase -) + const Word16 *input_synspeech, /* i : input synthesized speech */ + Word16 *shb_syn_speech_32k, /* o : output highband component */ + Word32 Hilbert_Mem[], /* i/o: memory */ + Word16 allpass_mem[], /* i/o: memory */ + const Word16 L_frame, /* i : ACELP frame length */ + Word16 *syn_dm_phase ) { Word16 i, speech_buf_32k[L_FRAME32k]; Word16 maxm, nor, nor32, shift; @@ -3498,64 +3495,61 @@ void GenSHBSynth_fx( maxm = 0; move16(); - maxm32 = L_deposit_l(0); - FOR(i = 0; i (Q_bwe_exc + Q_gFr_norm - 13) */ + *Q_bwe_exc = add( *Q_bwe_exc, Q_gFr_norm ); /* compensate for the exp shift */ + *Q_bwe_exc = sub( *Q_bwe_exc, 13 ); /* Keep Q-fac at => (Q_bwe_exc + Q_gFr_norm - 13) */ /* check for headroom of previous buff memories: overlap, Hilbert, and interp all-pass mem */ tmpQ15 = add( prev_Q_bwe_syn2, n_mem3 ); - if( GT_16( *Q_bwe_exc, tmpQ15)) + if ( GT_16( *Q_bwe_exc, tmpQ15 ) ) { *Q_bwe_exc = tmpQ15; move16(); @@ -3728,37 +3727,37 @@ void ScaleShapedSHB_fx( FOR( i = 0; i < L_SHB_LAHEAD; i++ ) { temp2 = 1; - if( overlap[i] < 0 ) + if ( overlap[i] < 0 ) { temp2 = -1; } - temp1 = abs_s(overlap[i]); - temp1 = shl( temp1, (*Q_bwe_exc - prev_Q_bwe_syn2) ); - move16(); /* Q_bwe_exc + Q_gFr_norm - 13 */ - overlap[i] = i_mult(temp1, temp2); + temp1 = abs_s( overlap[i] ); + temp1 = shl( temp1, ( *Q_bwe_exc - prev_Q_bwe_syn2 ) ); + move16(); /* Q_bwe_exc + Q_gFr_norm - 13 */ + overlap[i] = i_mult( temp1, temp2 ); } - FOR ( i = 0; i < l_shb_lahead; i++ ) + FOR( i = 0; i < l_shb_lahead; i++ ) { - L_tmp = Mult_32_16(mod_syn[i], gain_frame_Q16); /* Q_bwe_exc + 16 + Q_gFr_norm + 2 - 15 */ - L_tmp2 = Mult_32_16(L_tmp, win[i]); /* (Q_bwe_exc + 16 + Q_gFr_norm + 2 - 15) + 15 + (1-16) */ - synSHB[i] = mac_r(L_tmp2, overlap[i], MAX_16); - move16(); /* Q_bwe_exc + Q_gFr_norm - 13 */ - synSHB[i+l_shb_lahead] = round_fx(L_tmp); /* Q_bwe_exc + Q_gFr_norm - 13 */ + L_tmp = Mult_32_16( mod_syn[i], gain_frame_Q16 ); /* Q_bwe_exc + 16 + Q_gFr_norm + 2 - 15 */ + L_tmp2 = Mult_32_16( L_tmp, win[i] ); /* (Q_bwe_exc + 16 + Q_gFr_norm + 2 - 15) + 15 + (1-16) */ + synSHB[i] = mac_r( L_tmp2, overlap[i], MAX_16 ); + move16(); /* Q_bwe_exc + Q_gFr_norm - 13 */ + synSHB[i + l_shb_lahead] = round_fx( L_tmp ); /* Q_bwe_exc + Q_gFr_norm - 13 */ } - FOR ( ; i < l_frame; i++ ) + FOR( ; i < l_frame; i++ ) { - L_tmp = Mult_32_16( mod_syn[i], gain_frame_Q16); /* Q_bwe_exc + 16 + Q_gFr_norm + 2 - 15 */ - synSHB[i] = round_fx( L_tmp ); /* Q_bwe_exc + Q_gFr_norm - 13 */ + L_tmp = Mult_32_16( mod_syn[i], gain_frame_Q16 ); /* Q_bwe_exc + 16 + Q_gFr_norm + 2 - 15 */ + synSHB[i] = round_fx( L_tmp ); /* Q_bwe_exc + Q_gFr_norm - 13 */ } - l_frame_tmp = add(l_frame, l_shb_lahead); - FOR ( ; i < l_frame_tmp; i++ ) + l_frame_tmp = add( l_frame, l_shb_lahead ); + FOR( ; i < l_frame_tmp; i++ ) { - L_tmp = Mult_32_16( mod_syn[i], gain_frame_Q16); /* Q_bwe_exc + 16 + Q_gFr_norm + 2 - 15 */ - L_tmp = Mult_32_16(L_tmp, win[l_frame + l_shb_lahead - 1 - i]); /* (Q_bwe_exc + 16 + Q_gFr_norm + 2 - 15) + 15 + (1-16) */ - overlap[i - l_frame] = round_fx( L_tmp ); /* Q_bwe_exc + Q_gFr_norm - 13 */ + L_tmp = Mult_32_16( mod_syn[i], gain_frame_Q16 ); /* Q_bwe_exc + 16 + Q_gFr_norm + 2 - 15 */ + L_tmp = Mult_32_16( L_tmp, win[l_frame + l_shb_lahead - 1 - i] ); /* (Q_bwe_exc + 16 + Q_gFr_norm + 2 - 15) + 15 + (1-16) */ + overlap[i - l_frame] = round_fx( L_tmp ); /* Q_bwe_exc + Q_gFr_norm - 13 */ } return; @@ -3770,33 +3769,37 @@ void ScaleShapedSHB_fx( *-------------------------------------------------------------------*/ void ScaleShapedWB_fx( - const Word16 length, /* i : SHB overlap length */ - Word16* synSHB, /* i/o : synthesized shb signal Q_bwe_exc/Qx */ - Word16* overlap, /* i/o : buffer for overlap-add Q_bwe_exc/Qx */ - const Word16* subgain, /* i : subframe gain Q15*/ - const Word32 frame_gain, /* i : frame gain Q18 */ - const Word16* win, /* i : window Q15*/ - const Word16* subwin, /* i : subframes window Q15*/ - const Word16 Q_bwe_exc - ,Word16 L_frame /* i : Frame length - determines whether 12.8 or 16kHz core in-use */ - ,Word16 dynQ /* i : indicate whether output is dynamic Q, or Q0 */ - ,Word16* Qx /* o : newly computed Q factor for synSHB */ - ,Word16 prev_Qx /* i : prev_Qx for memory scaling */ - ,Word32* Hilbert_Mem /* i : Hilbert memory used for computing Qx */ + const Word16 length, /* i : SHB overlap length */ + Word16 *synSHB, /* i/o : synthesized shb signal Q_bwe_exc/Qx */ + Word16 *overlap, /* i/o : buffer for overlap-add Q_bwe_exc/Qx */ + const Word16 *subgain, /* i : subframe gain Q15*/ + const Word32 frame_gain, /* i : frame gain Q18 */ + const Word16 *win, /* i : window Q15*/ + const Word16 *subwin, /* i : subframes window Q15*/ + const Word16 Q_bwe_exc, + Word16 L_frame /* i : Frame length - determines whether 12.8 or 16kHz core in-use */ + , + Word16 dynQ /* i : indicate whether output is dynamic Q, or Q0 */ + , + Word16 *Qx /* o : newly computed Q factor for synSHB */ + , + Word16 prev_Qx /* i : prev_Qx for memory scaling */ + , + Word32 *Hilbert_Mem /* i : Hilbert memory used for computing Qx */ ) { - const Word16* skip; + const Word16 *skip; Word16 i, j, k, l_shb_lahead, l_frame, l_frame_tmp; Word16 join_length, num_join; - Word32 mod_syn[L_FRAME16k+L_SHB_LAHEAD]; + Word32 mod_syn[L_FRAME16k + L_SHB_LAHEAD]; Word16 sum_gain; Word32 L_tmp; Word16 max_val, abs_sig, sc1, sc2, shift, max_headroom, min_shift, max_shift, max_shift2; /* Init */ - set32_fx( mod_syn, 0, L_FRAME16k+L_SHB_LAHEAD ); + set32_fx( mod_syn, 0, L_FRAME16k + L_SHB_LAHEAD ); /* apply gain for each subframe, and store noise output signal using overlap-add */ - IF ( EQ_16(length,SHB_OVERLAP_LEN / 2 )) + IF( EQ_16( length, SHB_OVERLAP_LEN / 2 ) ) { /* WB Gain shape and gain frame application with overlap */ skip = skip_bands_WB_TBE; @@ -3808,29 +3811,29 @@ void ScaleShapedWB_fx( sum_gain = 0; move16(); - FOR ( k = 0; k < length / 2; k++ ) + FOR( k = 0; k < length / 2; k++ ) { sum_gain = mult_r( subwin[2 * k + 2], subgain[0] ); /* Q15 */ mod_syn[skip[0] + k] = L_mult( sum_gain, synSHB[skip[0] + k] ); - move32();/* Q_bwe_exc + 16 */ + move32(); /* Q_bwe_exc + 16 */ mod_syn[skip[0] + k + length / 2] = L_mult( subgain[0], synSHB[skip[0] + k + length / 2] ); - move32();/* Q_bwe_exc + 16 */ + move32(); /* Q_bwe_exc + 16 */ } - FOR ( i = 1; i < NUM_SHB_SUBFR / 2; i++ ) + FOR( i = 1; i < NUM_SHB_SUBFR / 2; i++ ) { - FOR ( k = 0; k < length; k++ ) + FOR( k = 0; k < length; k++ ) { - L_tmp = L_mult0( subwin[k + 1], subgain[i] ); /* Q30 */ + L_tmp = L_mult0( subwin[k + 1], subgain[i] ); /* Q30 */ sum_gain = round_fx( L_mac0( L_tmp, subwin[length - k - 1], subgain[i - 1] ) ); /* Q14 */ mod_syn[skip[i] + k] = L_shl( L_mult( sum_gain, synSHB[skip[i] + k] ), 1 ); - move32(); /* Q_bwe_exc + 16 */ + move32(); /* Q_bwe_exc + 16 */ } } - FOR ( k = 0; k < length / 2; k++ ) + FOR( k = 0; k < length / 2; k++ ) { sum_gain = mult_r( subwin[length - 2 * k - 2], subgain[i - 1] ); /* Q15 */ mod_syn[skip[i] + k] = L_mult( sum_gain, synSHB[skip[i] + k] ); - move32();/* Q_bwe_exc + 16 */ + move32(); /* Q_bwe_exc + 16 */ } } ELSE @@ -3847,41 +3850,41 @@ void ScaleShapedWB_fx( move16(); join_length = i_mult2( num_join, length ); j = 0; /* ptr*/ - FOR ( k = 0; k < length; k++ ) + FOR( k = 0; k < length; k++ ) { - sum_gain = mult_r( subwin[k + 1], subgain[0] ); /* Q15 */ + sum_gain = mult_r( subwin[k + 1], subgain[0] ); /* Q15 */ mod_syn[j] = L_mult( synSHB[j], sum_gain ); - move32(); /* Q_bwe_exc + 16 */ + move32(); /* Q_bwe_exc + 16 */ j++; } - FOR ( i = 0; i < NUM_SHB_SUBGAINS - 1; i++ ) + FOR( i = 0; i < NUM_SHB_SUBGAINS - 1; i++ ) { - FOR ( k = 0; k < join_length - length; k++ ) + FOR( k = 0; k < join_length - length; k++ ) { mod_syn[j] = L_mult( synSHB[j], subgain[i * num_join] ); move32(); /* Q_bwe_exc + 16 */ j++; } - FOR ( k = 0; k < length; k++ ) + FOR( k = 0; k < length; k++ ) { - L_tmp = L_mult0( subwin[k + 1], subgain[i_mult2(( i + 1 ), num_join)] ); /* Q30 */ - sum_gain = round_fx( L_mac0( L_tmp, subwin[length - k - 1], subgain[i_mult2(i, num_join)] ) );/*Q14 */ + L_tmp = L_mult0( subwin[k + 1], subgain[i_mult2( ( i + 1 ), num_join )] ); /* Q30 */ + sum_gain = round_fx( L_mac0( L_tmp, subwin[length - k - 1], subgain[i_mult2( i, num_join )] ) ); /*Q14 */ mod_syn[j] = L_shl( L_mult( sum_gain, synSHB[j] ), 1 ); move32(); /* Q_bwe_exc + 16 */ j++; } } - FOR ( k = 0; k < join_length - length; k++ ) + FOR( k = 0; k < join_length - length; k++ ) { mod_syn[j] = L_mult( synSHB[j], subgain[( NUM_SHB_SUBGAINS - 1 ) * num_join] ); move32(); /* Q_bwe_exc + 16 */ j++; } - FOR ( k = 0; k < length; k++ ) + FOR( k = 0; k < length; k++ ) { - sum_gain = mult_r( subwin[length - k - 1], subgain[( NUM_SHB_SUBGAINS - 1 ) *num_join] ); /* Q15 */ + sum_gain = mult_r( subwin[length - k - 1], subgain[( NUM_SHB_SUBGAINS - 1 ) * num_join] ); /* Q15 */ mod_syn[j] = L_mult( synSHB[j], sum_gain ); move32(); /* Q_bwe_exc + 16 */ j++; @@ -3889,13 +3892,12 @@ void ScaleShapedWB_fx( } - max_val = 0; move16(); FOR( i = 0; i < l_frame + l_shb_lahead; i++ ) { - abs_sig = abs_s( round_fx(mod_syn[i]) ); - if(GT_16(abs_sig,max_val)) + abs_sig = abs_s( round_fx( mod_syn[i] ) ); + if ( GT_16( abs_sig, max_val ) ) { max_val = abs_sig; move16(); @@ -3904,8 +3906,8 @@ void ScaleShapedWB_fx( FOR( i = 0; i < HILBERT_MEM_SIZE; i++ ) { - abs_sig = abs_s( round_fx(Hilbert_Mem[i]) ); - if(GT_16(abs_sig,max_val)) + abs_sig = abs_s( round_fx( Hilbert_Mem[i] ) ); + if ( GT_16( abs_sig, max_val ) ) { max_val = abs_sig; move16(); @@ -3913,49 +3915,49 @@ void ScaleShapedWB_fx( } sc1 = norm_s( max_val ); /* max_val headroom in mod_syn[] */ - sc2 = norm_s( round_fx(frame_gain));/* headroom in GainFrame */ + sc2 = norm_s( round_fx( frame_gain ) ); /* headroom in GainFrame */ - IF(dynQ == 0 ) + IF( dynQ == 0 ) { - shift = sub(13, Q_bwe_exc); /* earlier = (10 - Q_bwe_exc) but we changed GainFrame Q21 to Q18 */ + shift = sub( 13, Q_bwe_exc ); /* earlier = (10 - Q_bwe_exc) but we changed GainFrame Q21 to Q18 */ *Qx = 0; } - ELSE IF (EQ_16(L_frame,L_FRAME)) /* 12.8k core */ + ELSE IF( EQ_16( L_frame, L_FRAME ) ) /* 12.8k core */ { - max_headroom = sub(add(sc1,sc2),4); /* Max headroom after multiplying = sc1 + sc2 -3 (keep 3 bit extra headroom) */ + max_headroom = sub( add( sc1, sc2 ), 4 ); /* Max headroom after multiplying = sc1 + sc2 -3 (keep 3 bit extra headroom) */ /* 12.8k core needs extra headroom than 16k core */ /* otherwise Hilbert transform inside flip_and_downmix have saturation, causes ringing in output */ /* Qx = (Q_bwe_exc+3) + shift - 16 */ /* make sure 14 > Qx > 2 */ - min_shift = 2-(Q_bwe_exc+3-16); - max_shift = 13-(Q_bwe_exc+3-16); - max_shift2 = s_min(max_shift,max_headroom); /* avoid shifting more than the available max_val headroom to avoid overflow */ + min_shift = 2 - ( Q_bwe_exc + 3 - 16 ); + max_shift = 13 - ( Q_bwe_exc + 3 - 16 ); + max_shift2 = s_min( max_shift, max_headroom ); /* avoid shifting more than the available max_val headroom to avoid overflow */ - shift = s_min(min_shift,max_shift2); - *Qx = (Q_bwe_exc+3) + shift - 16; + shift = s_min( min_shift, max_shift2 ); + *Qx = ( Q_bwe_exc + 3 ) + shift - 16; } ELSE /* 16k core */ { - max_headroom = sub(add(sc1,sc2),1); /* Max headroom after multiplying = sc1 + sc2 -1 (keep 1 bit extra headroom) */ + max_headroom = sub( add( sc1, sc2 ), 1 ); /* Max headroom after multiplying = sc1 + sc2 -1 (keep 1 bit extra headroom) */ /* Qx = (Q_bwe_exc+3) + shift - 16 */ /* make sure 14 > Qx > 3 */ - min_shift = 3-(Q_bwe_exc+3-16); - max_shift = 13-(Q_bwe_exc+3-16); - max_shift2 = s_min(max_shift,max_headroom); /* avoid shifting more than the available max_val headroom to avoid overflow */ + min_shift = 3 - ( Q_bwe_exc + 3 - 16 ); + max_shift = 13 - ( Q_bwe_exc + 3 - 16 ); + max_shift2 = s_min( max_shift, max_headroom ); /* avoid shifting more than the available max_val headroom to avoid overflow */ - shift = s_min(min_shift,max_shift2); - *Qx = (Q_bwe_exc+3) + shift - 16; + shift = s_min( min_shift, max_shift2 ); + *Qx = ( Q_bwe_exc + 3 ) + shift - 16; } /* bring memory st_fx->syn_overlap_fx[] = overlap[i] to new Q = Qx to prepare for addition */ - FOR ( i = 0; i < l_shb_lahead; i++ ) + FOR( i = 0; i < l_shb_lahead; i++ ) { - overlap[i] = shl(overlap[i], (*Qx - prev_Qx)); + overlap[i] = shl( overlap[i], ( *Qx - prev_Qx ) ); } - FOR ( i = 0; i < l_shb_lahead; i++ ) + FOR( i = 0; i < l_shb_lahead; i++ ) { /* mod_syn in (16+Q_bwe_exc), frame_gain in Q18 */ L_tmp = Mult_32_32( mod_syn[i], frame_gain ); /* L_tmp in (Q_bwe_exc+3) */ @@ -3965,31 +3967,31 @@ void ScaleShapedWB_fx( move16(); /* Qx */ synSHB[i + l_shb_lahead] = round_fx_sat( L_shl_sat( L_tmp, shift ) ); /* Qx */ #else - synSHB[i] = round_fx( L_shl( Mult_32_16( L_tmp, win[i] ), shift) ); /* Qx */ + synSHB[i] = round_fx( L_shl( Mult_32_16( L_tmp, win[i] ), shift ) ); /* Qx */ synSHB[i] = add( synSHB[i], overlap[i] ); - move16(); /* Qx */ - synSHB[i + l_shb_lahead] = round_fx( L_shl( L_tmp, shift) ); /* Qx */ + move16(); /* Qx */ + synSHB[i + l_shb_lahead] = round_fx( L_shl( L_tmp, shift ) ); /* Qx */ #endif } - FOR ( ; i < l_frame; i++ ) + FOR( ; i < l_frame; i++ ) { - L_tmp = Mult_32_32( mod_syn[i], frame_gain); /* L_tmp in (Q_bwe_exc+3) */ + L_tmp = Mult_32_32( mod_syn[i], frame_gain ); /* L_tmp in (Q_bwe_exc+3) */ #ifdef BASOP_NOGLOB synSHB[i] = round_fx_sat( L_shl_sat( L_tmp, shift ) ); /* Qx; */ #else - synSHB[i] = round_fx( L_shl(L_tmp, shift) ); /* Qx; */ + synSHB[i] = round_fx( L_shl( L_tmp, shift ) ); /* Qx; */ #endif } - l_frame_tmp = add(l_frame, l_shb_lahead); - FOR ( ; i < l_frame_tmp; i++ ) + l_frame_tmp = add( l_frame, l_shb_lahead ); + FOR( ; i < l_frame_tmp; i++ ) { L_tmp = Mult_32_32( mod_syn[i], frame_gain ); /* (Q_bwe_exc+3) */ #ifdef BASOP_NOGLOB overlap[i - l_frame] = round_fx_sat( L_shl_sat( Mult_32_16( L_tmp, win[l_frame + l_shb_lahead - 1 - i] ), shift ) ); /* Qx */ #else - overlap[i - l_frame] = round_fx( L_shl( Mult_32_16( L_tmp, win[l_frame + l_shb_lahead - 1 - i] ), shift ) ); /* Qx */ + overlap[i - l_frame] = round_fx( L_shl( Mult_32_16( L_tmp, win[l_frame + l_shb_lahead - 1 - i] ), shift ) ); /* Qx */ #endif } @@ -4009,35 +4011,34 @@ static Word32 non_linearity_scaled_copy( Word32 output[], Word32 prev_scale, const Word16 scale_step, - const Word16 en_abs -) + const Word16 en_abs ) { Word16 i; Word32 L_tmp; - IF (en_abs) + IF( en_abs ) { - FOR ( i = 0; i < j; i++ ) + FOR( i = 0; i < j; i++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_mult_sat( input[i], input[i] ); /* 2*Q_inp+1 */ + L_tmp = L_mult_sat( input[i], input[i] ); /* 2*Q_inp+1 */ #else - L_tmp = L_mult( input[i], input[i] ); /* 2*Q_inp+1 */ + L_tmp = L_mult( input[i], input[i] ); /* 2*Q_inp+1 */ #endif L_tmp = Mult_32_32( L_tmp, prev_scale ); /* 2*Q_inp */ output[i] = L_tmp; move32(); - L_tmp = Mult_32_16( prev_scale, scale_step ); /* Q29 */ - prev_scale = L_shl( L_tmp, 1 ); /* Q30 */ + L_tmp = Mult_32_16( prev_scale, scale_step ); /* Q29 */ + prev_scale = L_shl( L_tmp, 1 ); /* Q30 */ } - FOR ( ; i < length; i++ ) + FOR( ; i < length; i++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_mult_sat( input[i], input[i] ); /* 2*Q_inp+1 */ + L_tmp = L_mult_sat( input[i], input[i] ); /* 2*Q_inp+1 */ #else - L_tmp = L_mult( input[i], input[i] ); /* 2*Q_inp+1 */ + L_tmp = L_mult( input[i], input[i] ); /* 2*Q_inp+1 */ #endif L_tmp = Mult_32_32( L_tmp, prev_scale ); /* 2*Q_inp */ output[i] = L_tmp; @@ -4046,38 +4047,38 @@ static Word32 non_linearity_scaled_copy( } ELSE { - FOR ( i = 0; i < j; i++ ) + FOR( i = 0; i < j; i++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_mult_sat( input[i], input[i] ); /* 2*Q_inp+1 */ + L_tmp = L_mult_sat( input[i], input[i] ); /* 2*Q_inp+1 */ #else - L_tmp = L_mult( input[i], input[i] ); /* 2*Q_inp+1 */ + L_tmp = L_mult( input[i], input[i] ); /* 2*Q_inp+1 */ #endif L_tmp = Mult_32_32( L_tmp, prev_scale ); /* 2*Q_inp */ if ( input[i] < 0 ) { - L_tmp = L_negate(L_tmp); + L_tmp = L_negate( L_tmp ); } output[i] = L_tmp; move32(); - L_tmp = Mult_32_16( prev_scale, scale_step ); /* Q29 */ - prev_scale = L_shl( L_tmp, 1 ); /* Q30 */ + L_tmp = Mult_32_16( prev_scale, scale_step ); /* Q29 */ + prev_scale = L_shl( L_tmp, 1 ); /* Q30 */ } - FOR ( ; i < length; i++ ) + FOR( ; i < length; i++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_mult_sat( input[i], input[i]); /* 2*Q_inp+1 */ -#else /* BASOP_NOGLOB */ - L_tmp = L_mult( input[i], input[i] ); /* 2*Q_inp+1 */ -#endif /* BASOP_NOGLOB */ - L_tmp = Mult_32_32( L_tmp, prev_scale ); /* 2*Q_inp */ + L_tmp = L_mult_sat( input[i], input[i] ); /* 2*Q_inp+1 */ +#else /* BASOP_NOGLOB */ + L_tmp = L_mult( input[i], input[i] ); /* 2*Q_inp+1 */ +#endif /* BASOP_NOGLOB */ + L_tmp = Mult_32_32( L_tmp, prev_scale ); /* 2*Q_inp */ if ( input[i] < 0 ) { - L_tmp = L_negate(L_tmp); + L_tmp = L_negate( L_tmp ); } output[i] = L_tmp; move32(); @@ -4100,22 +4101,22 @@ static Word32 non_linearity_scaled_copy_ivas( Word32 output[], Word32 prev_scale, const Word16 scale_step, - const Word16 en_abs -) + const Word16 en_abs ) { Word16 i; Word32 L_tmp; - IF (en_abs) + IF( en_abs ) { - FOR ( i = 0; i < j; i++ ) + FOR( i = 0; i < j; i++ ) { - L_tmp = L_mult( input[i], input[i] ); /* 2*Q_inp+1 */ + L_tmp = L_mult( input[i], input[i] ); /* 2*Q_inp+1 */ L_tmp = Mult_32_32( L_tmp, prev_scale ); /* 2*Q_inp */ - test(); test(); - IF(input[i] != 0 && prev_scale != 0 && L_tmp == 0) + test(); + test(); + IF( input[i] != 0 && prev_scale != 0 && L_tmp == 0 ) { /* NOTE: this is done to avoid the product to become zero for small non-zero input */ L_tmp = 1; @@ -4125,16 +4126,17 @@ static Word32 non_linearity_scaled_copy_ivas( output[i] = L_tmp; move32(); - L_tmp = Mult_32_16( prev_scale, scale_step ); /* Q29 */ - prev_scale = L_shl( L_tmp, 1 ); /* Q30 */ + L_tmp = Mult_32_16( prev_scale, scale_step ); /* Q29 */ + prev_scale = L_shl( L_tmp, 1 ); /* Q30 */ } - FOR ( ; i < length; i++ ) + FOR( ; i < length; i++ ) { - L_tmp = L_mult( input[i], input[i] ); /* 2*Q_inp+1 */ + L_tmp = L_mult( input[i], input[i] ); /* 2*Q_inp+1 */ L_tmp = Mult_32_32( L_tmp, prev_scale ); /* 2*Q_inp */ - test(); test(); - IF(input[i] != 0 && prev_scale != 0 && L_tmp == 0) + test(); + test(); + IF( input[i] != 0 && prev_scale != 0 && L_tmp == 0 ) { /* NOTE: this is done to avoid the product to become zero for small non-zero input */ L_tmp = 1; @@ -4146,13 +4148,14 @@ static Word32 non_linearity_scaled_copy_ivas( } ELSE { - FOR ( i = 0; i < j; i++ ) + FOR( i = 0; i < j; i++ ) { - L_tmp = L_mult( input[i], input[i] ); /* 2*Q_inp+1 */ + L_tmp = L_mult( input[i], input[i] ); /* 2*Q_inp+1 */ L_tmp = Mult_32_32( L_tmp, prev_scale ); /* 2*Q_inp */ - test(); test(); - IF(input[i] != 0 && prev_scale != 0 && L_tmp == 0) + test(); + test(); + IF( input[i] != 0 && prev_scale != 0 && L_tmp == 0 ) { /* NOTE: this is done to avoid the product to become zero for small non-zero input */ L_tmp = 1; @@ -4161,25 +4164,26 @@ static Word32 non_linearity_scaled_copy_ivas( if ( input[i] < 0 ) { - L_tmp = L_negate(L_tmp); + L_tmp = L_negate( L_tmp ); } output[i] = L_tmp; move32(); - L_tmp = Mult_32_16( prev_scale, scale_step ); /* Q29 */ - prev_scale = L_shl( L_tmp, 1 ); /* Q30 */ + L_tmp = Mult_32_16( prev_scale, scale_step ); /* Q29 */ + prev_scale = L_shl( L_tmp, 1 ); /* Q30 */ } - FOR ( ; i < length; i++ ) + FOR( ; i < length; i++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_mult_sat( input[i], input[i]); /* 2*Q_inp+1 */ -#else /* BASOP_NOGLOB */ - L_tmp = L_mult( input[i], input[i] ); /* 2*Q_inp+1 */ -#endif /* BASOP_NOGLOB */ - L_tmp = Mult_32_32( L_tmp, prev_scale ); /* 2*Q_inp */ - test(); test(); - IF(input[i] != 0 && prev_scale != 0 && L_tmp == 0) + L_tmp = L_mult_sat( input[i], input[i] ); /* 2*Q_inp+1 */ +#else /* BASOP_NOGLOB */ + L_tmp = L_mult( input[i], input[i] ); /* 2*Q_inp+1 */ +#endif /* BASOP_NOGLOB */ + L_tmp = Mult_32_32( L_tmp, prev_scale ); /* 2*Q_inp */ + test(); + test(); + IF( input[i] != 0 && prev_scale != 0 && L_tmp == 0 ) { /* NOTE: this is done to avoid the product to become zero for small non-zero input */ L_tmp = 1; @@ -4188,7 +4192,7 @@ static Word32 non_linearity_scaled_copy_ivas( if ( input[i] < 0 ) { - L_tmp = L_negate(L_tmp); + L_tmp = L_negate( L_tmp ); } output[i] = L_tmp; move32(); @@ -4220,19 +4224,19 @@ static Word32 non_linearity_scaled_copy_ivas( /*==========================================================================*/ void non_linearity_fx( - const Word16 input[], /* i : input signal Q_inp */ - Word32 output[], /* o : output signal 2*Q_inp */ - const Word16 length, /* i : input length */ - Word32* pPrevScale, /* i/o: memory Q30 */ + const Word16 input[], /* i : input signal Q_inp */ + Word32 output[], /* o : output signal 2*Q_inp */ + const Word16 length, /* i : input length */ + Word32 *pPrevScale, /* i/o: memory Q30 */ Word16 Q_inp, - Word16 coder_type, /* i : Coder Type */ - Word16 *voice_factors, /* i : Voice Factors */ - const Word16 L_frame /* i : ACELP frame length */ + Word16 coder_type, /* i : Coder Type */ + Word16 *voice_factors, /* i : Voice Factors */ + const Word16 L_frame /* i : ACELP frame length */ ) { Word16 i, j; - Word16 max_val=0; + Word16 max_val = 0; Word32 scale; Word16 scale_step; Word16 exp, tmp; @@ -4252,7 +4256,7 @@ void non_linearity_fx( #endif - IF ( EQ_16(L_frame, L_FRAME16k )) + IF( EQ_16( L_frame, L_FRAME16k ) ) { nframes = 5; move16(); @@ -4268,44 +4272,42 @@ void non_linearity_fx( } - FOR ( i = 0; i < nframes; i++ ) + FOR( i = 0; i < nframes; i++ ) { v_fac = add( v_fac, shr( voice_factors[i], 3 ) ); /* Q12 */ } test(); - if ( EQ_16( coder_type, VOICED )&>_16(v_fac,ths)) + if ( EQ_16( coder_type, VOICED ) && GT_16( v_fac, ths ) ) { en_abs = 1; move16(); } - length_half = shr(length, 1); + length_half = shr( length, 1 ); prev_scale = *pPrevScale; move32(); - /* Delay Alignment in FX is done inside swb_tbe_enc_fx() */ - FOR ( i = j = 0; i < length_half; i++ ) + FOR( i = j = 0; i < length_half; i++ ) { - tmp = abs_s(input[i]); - if(GT_16(tmp,max_val)) + tmp = abs_s( input[i] ); + if ( GT_16( tmp, max_val ) ) { j = i; move16(); } - max_val = s_max(max_val, tmp); - + max_val = s_max( max_val, tmp ); } - IF ( GT_16(max_val, shl(1,Q_inp))) + IF( GT_16( max_val, shl( 1, Q_inp ) ) ) { exp = norm_s( max_val ); - tmp = div_s( shl(1, sub( 14, exp)), max_val ); /* Q(29-exp-Q_inp) */ - scale = L_shl( L_mult( 21955, tmp ), add(exp, sub(Q_inp,14)) ); /* Q31 */ + tmp = div_s( shl( 1, sub( 14, exp ) ), max_val ); /* Q(29-exp-Q_inp) */ + scale = L_shl( L_mult( 21955, tmp ), add( exp, sub( Q_inp, 14 ) ) ); /* Q31 */ } ELSE { @@ -4314,17 +4316,17 @@ void non_linearity_fx( } test(); - IF ( prev_scale <= 0 || GT_32( Mult_32_16( prev_scale, 32 ), scale )) + IF( prev_scale <= 0 || GT_32( Mult_32_16( prev_scale, 32 ), scale ) ) { scale_step = 16384; - move16(); /* Q14 */ - prev_scale = L_shr( scale, 1 ); /* Q30 */ + move16(); /* Q14 */ + prev_scale = L_shr( scale, 1 ); /* Q30 */ } ELSE { /* Computing log2(scale) */ - IF ( j == 0 ) + IF( j == 0 ) { scale_step = 32767; move16(); @@ -4333,13 +4335,13 @@ void non_linearity_fx( { e_tmp = norm_l( scale ); f_tmp = Log2_norm_lc( L_shl( scale, e_tmp ) ); - e_tmp = sub(-1, e_tmp); + e_tmp = sub( -1, e_tmp ); L_tmp = Mpy_32_16( e_tmp, f_tmp, 32767 ); /* Q16 */ /* Computing log2(prev_scale) */ e_tmp = norm_l( prev_scale ); f_tmp = Log2_norm_lc( L_shl( prev_scale, e_tmp ) ); - e_tmp = negate(e_tmp); + e_tmp = negate( e_tmp ); L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 32767 ); /* Q16 */ /* log2(scale / prev_scale) = log2(scale) - log2(prev_scale) */ @@ -4347,13 +4349,13 @@ void non_linearity_fx( /* Computing 1/j */ exp = norm_s( j ); - tmp = div_s( shl(1, sub( 14, exp)), j ); /* Q(29-exp) */ + tmp = div_s( shl( 1, sub( 14, exp ) ), j ); /* Q(29-exp) */ /* (log2(scale / prev_scale))/length */ #ifdef BASOP_NOGLOB - L_tmp = L_shl_o( Mult_32_16( L_tmp, tmp ), sub(exp, 14), &Overflow ); /* Q(16+29-exp+1-16+exp-14)->Q16 */ + L_tmp = L_shl_o( Mult_32_16( L_tmp, tmp ), sub( exp, 14 ), &Overflow ); /* Q(16+29-exp+1-16+exp-14)->Q16 */ #else - L_tmp = L_shl( Mult_32_16( L_tmp, tmp ), sub(exp, 14) ); /* Q(16+29-exp+1-16+exp-14)->Q16 */ + L_tmp = L_shl( Mult_32_16( L_tmp, tmp ), sub( exp, 14 ) ); /* Q(16+29-exp+1-16+exp-14)->Q16 */ #endif frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent of L_tmp */ @@ -4362,7 +4364,7 @@ void non_linearity_fx( #ifdef BASOP_NOGLOB scale_step = shl_o( tmp, exp, &Overflow ); /* Q14 */ #else - scale_step = shl( tmp, exp ); /* Q14 */ + scale_step = shl( tmp, exp ); /* Q14 */ #endif } } @@ -4371,61 +4373,61 @@ void non_linearity_fx( max_val = 0; move16(); - j = shr(length, 1); - FOR ( i = length_half; i < length; i++ ) + j = shr( length, 1 ); + FOR( i = length_half; i < length; i++ ) { - tmp = abs_s(input[i]); - if(GT_16(tmp,max_val)) + tmp = abs_s( input[i] ); + if ( GT_16( tmp, max_val ) ) { j = i; move16(); } - max_val = s_max(max_val, tmp); + max_val = s_max( max_val, tmp ); } - IF ( GT_16( max_val, shl( 1, Q_inp ) )) + IF( GT_16( max_val, shl( 1, Q_inp ) ) ) { exp = norm_s( max_val ); - tmp = div_s( shl(1, sub( 14, exp)), max_val ); /* Q(29-exp-Q_inp) */ + tmp = div_s( shl( 1, sub( 14, exp ) ), max_val ); /* Q(29-exp-Q_inp) */ #ifdef BASOP_NOGLOB - scale = L_shl_o( L_mult( 21955, tmp ), add(exp, sub(Q_inp, 14)), &Overflow ); /* Q31 */ + scale = L_shl_o( L_mult( 21955, tmp ), add( exp, sub( Q_inp, 14 ) ), &Overflow ); /* Q31 */ #else - scale = L_shl( L_mult( 21955, tmp ), add(exp, sub(Q_inp, 14)) ); /* Q31 */ + scale = L_shl( L_mult( 21955, tmp ), add( exp, sub( Q_inp, 14 ) ) ); /* Q31 */ #endif } ELSE { scale = 1438814044; - move32(); /* Q31; 0.67 in Q31 */ + move32(); /* Q31; 0.67 in Q31 */ } test(); - IF ( prev_scale <= 0 || GT_32( Mult_32_16( prev_scale, 32 ), scale )) + IF( prev_scale <= 0 || GT_32( Mult_32_16( prev_scale, 32 ), scale ) ) { scale_step = 16384; - move16(); /*Q14 */ + move16(); /*Q14 */ prev_scale = L_shr( scale, 1 ); /*Q30 */ } ELSE { /*scale_step = (float) exp(1.0f / (float) (j - length/2) * (float) log(scale / prev_scale)); */ /* Computing log2(scale) */ - IF ( EQ_16(j,length_half)) + IF( EQ_16( j, length_half ) ) { scale_step = 32767; - move16();/*Q14 */ + move16(); /*Q14 */ } ELSE { e_tmp = norm_l( scale ); f_tmp = Log2_norm_lc( L_shl( scale, e_tmp ) ); - e_tmp = sub(-e_tmp, 1); + e_tmp = sub( -e_tmp, 1 ); L_tmp = Mpy_32_16( e_tmp, f_tmp, 32767 ); /* Q16 */ /* Computing log2(prev_scale) */ e_tmp = norm_l( prev_scale ); f_tmp = Log2_norm_lc( L_shl( prev_scale, e_tmp ) ); - e_tmp = negate(e_tmp); + e_tmp = negate( e_tmp ); L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 32767 ); /* Q16 */ /* log2(scale / prev_scale) = log2(scale) - log2(prev_scale) */ @@ -4437,13 +4439,13 @@ void non_linearity_fx( exp = norm_s( tmp ); - tmp = div_s( shl(1, sub( 14, exp)), tmp ); /* Q(29-exp) */ + tmp = div_s( shl( 1, sub( 14, exp ) ), tmp ); /* Q(29-exp) */ /* (log2(scale / prev_scale))/length */ #ifdef BASOP_NOGLOB - L_tmp = L_shl_o( Mult_32_16( L_tmp, tmp ), sub(exp,14), &Overflow); /*Q(16+29-exp+1-16+exp-14)->Q16 */ + L_tmp = L_shl_o( Mult_32_16( L_tmp, tmp ), sub( exp, 14 ), &Overflow ); /*Q(16+29-exp+1-16+exp-14)->Q16 */ #else - L_tmp = L_shl( Mult_32_16( L_tmp, tmp ), sub(exp,14) ); /*Q(16+29-exp+1-16+exp-14)->Q16 */ + L_tmp = L_shl( Mult_32_16( L_tmp, tmp ), sub( exp, 14 ) ); /*Q(16+29-exp+1-16+exp-14)->Q16 */ #endif frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent of L_tmp */ @@ -4452,12 +4454,12 @@ void non_linearity_fx( #ifdef BASOP_NOGLOB scale_step = shl_o( tmp, exp, &Overflow ); /*Q14 */ #else - scale_step = shl( tmp, exp ); /*Q14 */ + scale_step = shl( tmp, exp ); /*Q14 */ #endif } } - prev_scale = non_linearity_scaled_copy( input+length_half, sub(j, length_half), sub(length, length_half), output+length_half, prev_scale, scale_step, en_abs ); + prev_scale = non_linearity_scaled_copy( input + length_half, sub( j, length_half ), sub( length, length_half ), output + length_half, prev_scale, scale_step, en_abs ); *pPrevScale = prev_scale; move32(); @@ -4490,19 +4492,19 @@ void non_linearity_fx( /*==========================================================================*/ void non_linearity_ivas_fx( - const Word16 input[], /* i : input signal Q_inp */ - Word32 output[], /* o : output signal 2*Q_inp */ - const Word16 length, /* i : input length */ - Word32* pPrevScale, /* i/o: memory Q30 */ + const Word16 input[], /* i : input signal Q_inp */ + Word32 output[], /* o : output signal 2*Q_inp */ + const Word16 length, /* i : input length */ + Word32 *pPrevScale, /* i/o: memory Q30 */ Word16 Q_inp, - Word16 coder_type, /* i : Coder Type */ - Word16 *voice_factors, /* i : Voice Factors */ - const Word16 L_frame /* i : ACELP frame length */ + Word16 coder_type, /* i : Coder Type */ + Word16 *voice_factors, /* i : Voice Factors */ + const Word16 L_frame /* i : ACELP frame length */ ) { Word16 i, j; - Word16 max_val=0; + Word16 max_val = 0; Word32 scale; Word16 scale_step; Word16 exp, tmp; @@ -4522,7 +4524,7 @@ void non_linearity_ivas_fx( #endif - IF ( EQ_16(L_frame, L_FRAME16k )) + IF( EQ_16( L_frame, L_FRAME16k ) ) { nframes = 5; move16(); @@ -4538,44 +4540,42 @@ void non_linearity_ivas_fx( } - FOR ( i = 0; i < nframes; i++ ) + FOR( i = 0; i < nframes; i++ ) { v_fac = add( v_fac, shr( voice_factors[i], 3 ) ); /* Q12 */ } test(); - if ( EQ_16( coder_type, VOICED )&>_16(v_fac,ths)) + if ( EQ_16( coder_type, VOICED ) && GT_16( v_fac, ths ) ) { en_abs = 1; move16(); } - length_half = shr(length, 1); + length_half = shr( length, 1 ); prev_scale = *pPrevScale; move32(); - /* Delay Alignment in FX is done inside swb_tbe_enc_fx() */ - FOR ( i = j = 0; i < length_half; i++ ) + FOR( i = j = 0; i < length_half; i++ ) { - tmp = abs_s(input[i]); - if(GT_16(tmp,max_val)) + tmp = abs_s( input[i] ); + if ( GT_16( tmp, max_val ) ) { j = i; move16(); } - max_val = s_max(max_val, tmp); - + max_val = s_max( max_val, tmp ); } - IF ( GT_16(max_val, shl(1,Q_inp))) + IF( GT_16( max_val, shl( 1, Q_inp ) ) ) { exp = norm_s( max_val ); - tmp = div_s( shl(1, sub( 14, exp)), max_val ); /* Q(29-exp-Q_inp) */ - scale = L_shl( L_mult( 21955, tmp ), add(exp, sub(Q_inp,14)) ); /* Q31 */ + tmp = div_s( shl( 1, sub( 14, exp ) ), max_val ); /* Q(29-exp-Q_inp) */ + scale = L_shl( L_mult( 21955, tmp ), add( exp, sub( Q_inp, 14 ) ) ); /* Q31 */ } ELSE { @@ -4584,17 +4584,17 @@ void non_linearity_ivas_fx( } test(); - IF ( prev_scale <= 0 || GT_32( Mult_32_16( prev_scale, 64 ) /*Q30 -> Q31*/, scale/*Q31*/ )) + IF( prev_scale <= 0 || GT_32( Mult_32_16( prev_scale, 64 ) /*Q30 -> Q31*/, scale /*Q31*/ ) ) { scale_step = 16384; - move16(); /* Q14 */ - prev_scale = L_shr( scale, 1 ); /* Q30 */ + move16(); /* Q14 */ + prev_scale = L_shr( scale, 1 ); /* Q30 */ } ELSE { /* Computing log2(scale) */ - IF ( j == 0 ) + IF( j == 0 ) { scale_step = 32767; move16(); @@ -4603,13 +4603,13 @@ void non_linearity_ivas_fx( { e_tmp = norm_l( scale ); f_tmp = Log2_norm_lc( L_shl( scale, e_tmp ) ); - e_tmp = sub(-1, e_tmp); + e_tmp = sub( -1, e_tmp ); L_tmp = Mpy_32_16( e_tmp, f_tmp, 32767 ); /* Q16 */ /* Computing log2(prev_scale) */ e_tmp = norm_l( prev_scale ); f_tmp = Log2_norm_lc( L_shl( prev_scale, e_tmp ) ); - e_tmp = negate(e_tmp); + e_tmp = negate( e_tmp ); L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 32767 ); /* Q16 */ /* log2(scale / prev_scale) = log2(scale) - log2(prev_scale) */ @@ -4617,13 +4617,13 @@ void non_linearity_ivas_fx( /* Computing 1/j */ exp = norm_s( j ); - tmp = div_s( shl(1, sub( 14, exp)), j ); /* Q(29-exp) */ + tmp = div_s( shl( 1, sub( 14, exp ) ), j ); /* Q(29-exp) */ /* (log2(scale / prev_scale))/length */ #ifdef BASOP_NOGLOB - L_tmp = L_shl_o( Mult_32_16( L_tmp, tmp ), sub(exp, 14), &Overflow ); /* Q(16+29-exp+1-16+exp-14)->Q16 */ + L_tmp = L_shl_o( Mult_32_16( L_tmp, tmp ), sub( exp, 14 ), &Overflow ); /* Q(16+29-exp+1-16+exp-14)->Q16 */ #else - L_tmp = L_shl( Mult_32_16( L_tmp, tmp ), sub(exp, 14) ); /* Q(16+29-exp+1-16+exp-14)->Q16 */ + L_tmp = L_shl( Mult_32_16( L_tmp, tmp ), sub( exp, 14 ) ); /* Q(16+29-exp+1-16+exp-14)->Q16 */ #endif frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent of L_tmp */ @@ -4632,7 +4632,7 @@ void non_linearity_ivas_fx( #ifdef BASOP_NOGLOB scale_step = shl_o( tmp, exp, &Overflow ); /* Q14 */ #else - scale_step = shl( tmp, exp ); /* Q14 */ + scale_step = shl( tmp, exp ); /* Q14 */ #endif } } @@ -4641,61 +4641,61 @@ void non_linearity_ivas_fx( max_val = 0; move16(); - j = shr(length, 1); - FOR ( i = length_half; i < length; i++ ) + j = shr( length, 1 ); + FOR( i = length_half; i < length; i++ ) { - tmp = abs_s(input[i]); - if(GT_16(tmp,max_val)) + tmp = abs_s( input[i] ); + if ( GT_16( tmp, max_val ) ) { j = i; move16(); } - max_val = s_max(max_val, tmp); + max_val = s_max( max_val, tmp ); } - IF ( GT_16( max_val, shl( 1, Q_inp ) )) + IF( GT_16( max_val, shl( 1, Q_inp ) ) ) { exp = norm_s( max_val ); - tmp = div_s( shl(1, sub( 14, exp)), max_val ); /* Q(29-exp-Q_inp) */ + tmp = div_s( shl( 1, sub( 14, exp ) ), max_val ); /* Q(29-exp-Q_inp) */ #ifdef BASOP_NOGLOB - scale = L_shl_o( L_mult( 21955, tmp ), add(exp, sub(Q_inp, 14)), &Overflow ); /* Q31 */ + scale = L_shl_o( L_mult( 21955, tmp ), add( exp, sub( Q_inp, 14 ) ), &Overflow ); /* Q31 */ #else - scale = L_shl( L_mult( 21955, tmp ), add(exp, sub(Q_inp, 14)) ); /* Q31 */ + scale = L_shl( L_mult( 21955, tmp ), add( exp, sub( Q_inp, 14 ) ) ); /* Q31 */ #endif } ELSE { scale = 1438814044; - move32(); /* Q31; 0.67 in Q31 */ + move32(); /* Q31; 0.67 in Q31 */ } test(); - IF ( prev_scale <= 0 || GT_32( Mult_32_16( prev_scale, 64 ), scale )) + IF( prev_scale <= 0 || GT_32( Mult_32_16( prev_scale, 64 ), scale ) ) { scale_step = 16384; - move16(); /*Q14 */ + move16(); /*Q14 */ prev_scale = L_shr( scale, 1 ); /*Q30 */ } ELSE { /*scale_step = (float) exp(1.0f / (float) (j - length/2) * (float) log(scale / prev_scale)); */ /* Computing log2(scale) */ - IF ( EQ_16(j,length_half)) + IF( EQ_16( j, length_half ) ) { scale_step = 32767; - move16();/*Q14 */ + move16(); /*Q14 */ } ELSE { e_tmp = norm_l( scale ); f_tmp = Log2_norm_lc( L_shl( scale, e_tmp ) ); - e_tmp = sub(-e_tmp, 1); + e_tmp = sub( -e_tmp, 1 ); L_tmp = Mpy_32_16( e_tmp, f_tmp, 32767 ); /* Q16 */ /* Computing log2(prev_scale) */ e_tmp = norm_l( prev_scale ); f_tmp = Log2_norm_lc( L_shl( prev_scale, e_tmp ) ); - e_tmp = negate(e_tmp); + e_tmp = negate( e_tmp ); L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 32767 ); /* Q16 */ /* log2(scale / prev_scale) = log2(scale) - log2(prev_scale) */ @@ -4707,13 +4707,13 @@ void non_linearity_ivas_fx( exp = norm_s( tmp ); - tmp = div_s( shl(1, sub( 14, exp)), tmp ); /* Q(29-exp) */ + tmp = div_s( shl( 1, sub( 14, exp ) ), tmp ); /* Q(29-exp) */ /* (log2(scale / prev_scale))/length */ #ifdef BASOP_NOGLOB - L_tmp = L_shl_o( Mult_32_16( L_tmp, tmp ), sub(exp,14), &Overflow); /*Q(16+29-exp+1-16+exp-14)->Q16 */ + L_tmp = L_shl_o( Mult_32_16( L_tmp, tmp ), sub( exp, 14 ), &Overflow ); /*Q(16+29-exp+1-16+exp-14)->Q16 */ #else - L_tmp = L_shl( Mult_32_16( L_tmp, tmp ), sub(exp,14) ); /*Q(16+29-exp+1-16+exp-14)->Q16 */ + L_tmp = L_shl( Mult_32_16( L_tmp, tmp ), sub( exp, 14 ) ); /*Q(16+29-exp+1-16+exp-14)->Q16 */ #endif frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent of L_tmp */ @@ -4722,12 +4722,12 @@ void non_linearity_ivas_fx( #ifdef BASOP_NOGLOB scale_step = shl_o( tmp, exp, &Overflow ); /*Q14 */ #else - scale_step = shl( tmp, exp ); /*Q14 */ + scale_step = shl( tmp, exp ); /*Q14 */ #endif } } - prev_scale = non_linearity_scaled_copy_ivas( input+length_half, sub(j, length_half), sub(length, length_half), output+length_half, prev_scale, scale_step, en_abs ); + prev_scale = non_linearity_scaled_copy_ivas( input + length_half, sub( j, length_half ), sub( length, length_half ), output + length_half, prev_scale, scale_step, en_abs ); *pPrevScale = prev_scale; move32(); @@ -4738,36 +4738,35 @@ void non_linearity_ivas_fx( } - /*-------------------------------------------------------------------* -* create_random_vector() -* -* creates random number vector -* Note: the abs(max_val) value coming out of create_random_vector should -* fit into the precision of Q6. -* -------------------------------------------------------------------*/ + * create_random_vector() + * + * creates random number vector + * Note: the abs(max_val) value coming out of create_random_vector should + * fit into the precision of Q6. + * -------------------------------------------------------------------*/ void create_random_vector_fx( - Word16 output[], /* o : output random vector Q5*/ + Word16 output[], /* o : output random vector Q5*/ const Word16 length, /* i : length of random vector */ - Word16 seed[] /* i/o: start seed */ + Word16 seed[] /* i/o: start seed */ ) { Word16 i, j, k; Word16 scale1, scale2; Word32 L_tmp; - L_tmp = L_abs( Mult_32_16( 2144047674, Random( &seed[0] ) ) );/*Q23 */ + L_tmp = L_abs( Mult_32_16( 2144047674, Random( &seed[0] ) ) ); /*Q23 */ j = extract_l( L_shr( L_tmp, 23 ) ); j = s_and( j, 0xff ); - L_tmp = L_abs( Mult_32_16( 2144047674, Random( &seed[1] ) ) );/*Q23 */ + L_tmp = L_abs( Mult_32_16( 2144047674, Random( &seed[1] ) ) ); /*Q23 */ k = extract_l( L_shr( L_tmp, 23 ) ); k = s_and( k, 0xff ); - WHILE ( EQ_16(k,j)) + WHILE( EQ_16( k, j ) ) { - L_tmp = L_abs( Mult_32_16( 2144047674, Random( &seed[1] ) ) );/*Q23 */ + L_tmp = L_abs( Mult_32_16( 2144047674, Random( &seed[1] ) ) ); /*Q23 */ k = extract_l( L_shr( L_tmp, 23 ) ); k = s_and( k, 0xff ); } @@ -4788,11 +4787,11 @@ void create_random_vector_fx( move16(); /*Q5 */ /* -80.00f * 0.35f/0.1243f; */ } - FOR ( i = 0; i < length; i++ ) + FOR( i = 0; i < length; i++ ) { j = s_and( j, 0xff ); k = s_and( k, 0xff ); - output[i] = round_fx( L_add( L_mult( scale1, gaus_dico_swb_fx[j] ), L_mult( scale2, gaus_dico_swb_fx[k] ) ) ); /*Q5 */ + output[i] = round_fx( L_add( L_mult( scale1, gaus_dico_swb_fx[j] ), L_mult( scale2, gaus_dico_swb_fx[k] ) ) ); /*Q5 */ j++; k++; } @@ -4826,26 +4825,26 @@ void create_random_vector_fx( /*======================================================================================*/ void interp_code_5over2_fx( - const Word16 inp_code_fx[], /* i : input vector Qx*/ - Word16 interp_code_fx[], /* o : output vector Qx*/ - const Word16 inp_length /* i : length of input vector */ + const Word16 inp_code_fx[], /* i : input vector Qx*/ + Word16 interp_code_fx[], /* o : output vector Qx*/ + const Word16 inp_length /* i : length of input vector */ ) { Word16 i, kk, kkp1, i_len2; Word32 Ltemp; - Word16 factor_i_fx[5] = {6554, 19661, 32767, 19661, 6554}; - Word16 factor_j_fx[5] = {26214, 13107, 0, 13107, 26214}; + Word16 factor_i_fx[5] = { 6554, 19661, 32767, 19661, 6554 }; + Word16 factor_j_fx[5] = { 26214, 13107, 0, 13107, 26214 }; interp_code_fx[0] = inp_code_fx[0]; - move16();/* Qx */ + move16(); /* Qx */ - Ltemp = L_mult( inp_code_fx[0], factor_i_fx[3] );/* Q(16+x) */ - Ltemp = L_mac( Ltemp, inp_code_fx[1], factor_j_fx[3] );/* Q(16+x) */ - interp_code_fx[1] = round_fx( Ltemp );/*Qx */ + Ltemp = L_mult( inp_code_fx[0], factor_i_fx[3] ); /* Q(16+x) */ + Ltemp = L_mac( Ltemp, inp_code_fx[1], factor_j_fx[3] ); /* Q(16+x) */ + interp_code_fx[1] = round_fx( Ltemp ); /*Qx */ - Ltemp = L_mult( inp_code_fx[0], factor_i_fx[4] );/*Q(16+x) */ - Ltemp = L_mac( Ltemp, inp_code_fx[1], factor_j_fx[4] );/*Q(16+x) */ - interp_code_fx[2] = round_fx( Ltemp ); /* Qx */ + Ltemp = L_mult( inp_code_fx[0], factor_i_fx[4] ); /*Q(16+x) */ + Ltemp = L_mac( Ltemp, inp_code_fx[1], factor_j_fx[4] ); /*Q(16+x) */ + interp_code_fx[2] = round_fx( Ltemp ); /* Qx */ kk = 1; move16(); @@ -4854,48 +4853,47 @@ void interp_code_5over2_fx( i = 3; move16(); /*i_len2 = ( inp_length - 2 ) * HIBND_ACB_L_FAC; */ /*HIBND_ACB_L_FAC == 5/2 */ - i_len2 = sub(inp_length, 2); - i_len2 = shr(add(shl(i_len2, 2),i_len2),1); /* rounding below during shr makes it non BE*/ + i_len2 = sub( inp_length, 2 ); + i_len2 = shr( add( shl( i_len2, 2 ), i_len2 ), 1 ); /* rounding below during shr makes it non BE*/ - FOR ( ; i < i_len2; i += 5 ) + FOR( ; i < i_len2; i += 5 ) { - Ltemp = L_mult( inp_code_fx[kk], factor_j_fx[0] );/*Q(16+x) */ - Ltemp = L_mac( Ltemp, inp_code_fx[kkp1], factor_i_fx[0] );/*Q(16+x) */ - interp_code_fx[i] = round_fx( Ltemp );/*Qx */ + Ltemp = L_mult( inp_code_fx[kk], factor_j_fx[0] ); /*Q(16+x) */ + Ltemp = L_mac( Ltemp, inp_code_fx[kkp1], factor_i_fx[0] ); /*Q(16+x) */ + interp_code_fx[i] = round_fx( Ltemp ); /*Qx */ - Ltemp = L_mult( inp_code_fx[kk], factor_j_fx[1] );/*Q(16+x) */ - Ltemp = L_mac( Ltemp, inp_code_fx[kkp1], factor_i_fx[1] );/*Q(16+x) */ - interp_code_fx[i + 1] = round_fx( Ltemp );/*Qx */ + Ltemp = L_mult( inp_code_fx[kk], factor_j_fx[1] ); /*Q(16+x) */ + Ltemp = L_mac( Ltemp, inp_code_fx[kkp1], factor_i_fx[1] ); /*Q(16+x) */ + interp_code_fx[i + 1] = round_fx( Ltemp ); /*Qx */ - Ltemp = L_mult( inp_code_fx[kkp1], factor_i_fx[2] );/*Q(16+x) */ - interp_code_fx[i + 2] = round_fx( Ltemp );/*Qx */ + Ltemp = L_mult( inp_code_fx[kkp1], factor_i_fx[2] ); /*Q(16+x) */ + interp_code_fx[i + 2] = round_fx( Ltemp ); /*Qx */ kk++; kkp1++; - Ltemp = L_mult( inp_code_fx[kk], factor_i_fx[3] );/*Q(16+x) */ - Ltemp = L_mac( Ltemp, inp_code_fx[kkp1], factor_j_fx[3] );/*Q(16+x) */ - interp_code_fx[i + 3] = round_fx( Ltemp ); /*Qx */ + Ltemp = L_mult( inp_code_fx[kk], factor_i_fx[3] ); /*Q(16+x) */ + Ltemp = L_mac( Ltemp, inp_code_fx[kkp1], factor_j_fx[3] ); /*Q(16+x) */ + interp_code_fx[i + 3] = round_fx( Ltemp ); /*Qx */ - Ltemp = L_mult( inp_code_fx[kk], factor_i_fx[4] );/*Q(16+x) */ - Ltemp = L_mac( Ltemp, inp_code_fx[kkp1], factor_j_fx[4] );/*Q(16+x) */ - interp_code_fx[i + 4] = round_fx( Ltemp ); /*Qx */ + Ltemp = L_mult( inp_code_fx[kk], factor_i_fx[4] ); /*Q(16+x) */ + Ltemp = L_mac( Ltemp, inp_code_fx[kkp1], factor_j_fx[4] ); /*Q(16+x) */ + interp_code_fx[i + 4] = round_fx( Ltemp ); /*Qx */ kk++; kkp1++; } - Ltemp = L_mult( inp_code_fx[kk], factor_j_fx[0] );/*Q(16+x) */ - interp_code_fx[i] = round_fx( Ltemp ); /*Qx */ + Ltemp = L_mult( inp_code_fx[kk], factor_j_fx[0] ); /*Q(16+x) */ + interp_code_fx[i] = round_fx( Ltemp ); /*Qx */ - Ltemp = L_mult( inp_code_fx[kk], factor_j_fx[1] );/*Q(16+x) */ - interp_code_fx[i + 1] = round_fx( Ltemp ); /*Qx */ + Ltemp = L_mult( inp_code_fx[kk], factor_j_fx[1] ); /*Q(16+x) */ + interp_code_fx[i + 1] = round_fx( Ltemp ); /*Qx */ return; } - /*======================================================================================*/ /* FUNCTION : interp_code_4over2_fx() */ /*--------------------------------------------------------------------------------------*/ @@ -4921,45 +4919,44 @@ void interp_code_5over2_fx( /*======================================================================================*/ void interp_code_4over2_fx( - const Word16 inp_code_fx[], /* i : input vector Qx*/ - Word16 interp_code_fx[], /* o : output vector Qx*/ - const Word16 inp_length /* i : length of input vector */ + const Word16 inp_code_fx[], /* i : input vector Qx*/ + Word16 interp_code_fx[], /* o : output vector Qx*/ + const Word16 inp_length /* i : length of input vector */ ) { Word16 i, j; j = 0; move16(); - FOR ( i = 0; i < inp_length - 1; i++ ) + FOR( i = 0; i < inp_length - 1; i++ ) { interp_code_fx[j] = inp_code_fx[i]; - move16();/*Qx */ + move16(); /*Qx */ interp_code_fx[j + 1] = add( shr( inp_code_fx[i], 1 ), shr( inp_code_fx[i + 1], 1 ) ); move16(); - move16();/*Qx */ + move16(); /*Qx */ j = add( j, 2 ); } interp_code_fx[j] = inp_code_fx[i]; move16(); interp_code_fx[j + 1] = shr( inp_code_fx[i], 1 ); - move16();/*Qx */ + move16(); /*Qx */ return; } /*-------------------------------------------------------------------* -* wb_tbe_extras_reset_synth() -* -* Reset the extra parameters only required for WB TBE synthesis -*-------------------------------------------------------------------*/ + * wb_tbe_extras_reset_synth() + * + * Reset the extra parameters only required for WB TBE synthesis + *-------------------------------------------------------------------*/ -void wb_tbe_extras_reset_synth_fx( - Word16 state_lsyn_filt_shb[], +void wb_tbe_extras_reset_synth_fx( + Word16 state_lsyn_filt_shb[], Word16 state_lsyn_filt_dwn_shb[], Word16 state_32and48k_WB_upsample[], - Word16 state_resamp_HB[] -) + Word16 state_resamp_HB[] ) { set16_fx( state_lsyn_filt_shb, 0, 2 * ALLPASSSECTIONS_STEEP ); set16_fx( state_lsyn_filt_dwn_shb, 0, 2 * ALLPASSSECTIONS_STEEP ); @@ -4977,400 +4974,424 @@ void wb_tbe_extras_reset_synth_fx( *-------------------------------------------------------------------*/ void elliptic_bpf_48k_generic_fx( - const Word16 input_fx[], /* i : input signal */ + const Word16 input_fx[], /* i : input signal */ Word16 *Q_input_fx, - Word16 output_fx[], /* o : output signal */ - Word32 memory_fx2[][4], /* i/o: 4 arrays of 4 for memory */ + Word16 output_fx[], /* o : output signal */ + Word32 memory_fx2[][4], /* i/o: 4 arrays of 4 for memory */ Word16 memory_fx_Q[], - const Word16 full_band_bpf_fx[][5] /* i : filter coefficients b0,b1,b2,a0,a1,a2 Q13 */ + const Word16 full_band_bpf_fx[][5] /* i : filter coefficients b0,b1,b2,a0,a1,a2 Q13 */ ) { - Word16 i,j; + Word16 i, j; Word16 memory_fx0[4][4], memory_fx[4][4], Q_temp, Q_temp2; Word32 L_tmp[L_FRAME48k], L_tmp2[L_FRAME48k], L_output[L_FRAME48k], L_tmpX, memory2_fx[4][4], L_tmpMax; Word32 memory2_fx_2[4], memory2_fx_3[4]; - FOR( i=0; i<4; i++ ) + FOR( i = 0; i < 4; i++ ) { - memory_fx0[0][i] = extract_l(memory_fx2[0][i]); + memory_fx0[0][i] = extract_l( memory_fx2[0][i] ); #ifdef BASOP_NOGLOB - memory_fx[0][i] =shl_sat(memory_fx0[0][i],sub(*Q_input_fx,memory_fx_Q[0])); - memory2_fx[1][i] = L_shl_sat(memory_fx2[1][i], sub(add(*Q_input_fx, 11), memory_fx_Q[1])); - memory2_fx[2][i] = L_shl_sat(memory_fx2[2][i], sub(add(*Q_input_fx, 6), memory_fx_Q[2])); - memory2_fx[3][i] = L_shl_sat(memory_fx2[3][i], sub(add(*Q_input_fx, 1), memory_fx_Q[3])); + memory_fx[0][i] = shl_sat( memory_fx0[0][i], sub( *Q_input_fx, memory_fx_Q[0] ) ); + memory2_fx[1][i] = L_shl_sat( memory_fx2[1][i], sub( add( *Q_input_fx, 11 ), memory_fx_Q[1] ) ); + memory2_fx[2][i] = L_shl_sat( memory_fx2[2][i], sub( add( *Q_input_fx, 6 ), memory_fx_Q[2] ) ); + memory2_fx[3][i] = L_shl_sat( memory_fx2[3][i], sub( add( *Q_input_fx, 1 ), memory_fx_Q[3] ) ); #else - memory_fx[0][i] =shl(memory_fx0[0][i],sub(*Q_input_fx,memory_fx_Q[0])); - memory2_fx[1][i] = L_shl(memory_fx2[1][i], sub(add(*Q_input_fx, 11), memory_fx_Q[1])); - memory2_fx[2][i] = L_shl(memory_fx2[2][i], sub(add(*Q_input_fx, 6), memory_fx_Q[2])); - memory2_fx[3][i] = L_shl(memory_fx2[3][i], sub(add(*Q_input_fx, 1), memory_fx_Q[3])); + memory_fx[0][i] = shl( memory_fx0[0][i], sub( *Q_input_fx, memory_fx_Q[0] ) ); + memory2_fx[1][i] = L_shl( memory_fx2[1][i], sub( add( *Q_input_fx, 11 ), memory_fx_Q[1] ) ); + memory2_fx[2][i] = L_shl( memory_fx2[2][i], sub( add( *Q_input_fx, 6 ), memory_fx_Q[2] ) ); + memory2_fx[3][i] = L_shl( memory_fx2[3][i], sub( add( *Q_input_fx, 1 ), memory_fx_Q[3] ) ); #endif } - L_tmpX = L_shr(L_mult(memory_fx[0][0],full_band_bpf_fx[0][4]),3);/*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_add(L_shr(L_mult(memory_fx[0][1],full_band_bpf_fx[0][3]),3),L_tmpX);/*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_add(L_shr(L_mult(memory_fx[0][2],full_band_bpf_fx[0][2]),3),L_tmpX);/*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_add(L_shr(L_mult(memory_fx[0][3],full_band_bpf_fx[0][1]),3),L_tmpX);/*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_add(L_shr(L_mult(input_fx[0],full_band_bpf_fx[0][0]),3),L_tmpX);/*Q_input_fx + 13 + 1 - 3*/ + L_tmpX = L_shr( L_mult( memory_fx[0][0], full_band_bpf_fx[0][4] ), 3 ); /*Q_input_fx + 13 + 1 - 3*/ + L_tmpX = L_add( L_shr( L_mult( memory_fx[0][1], full_band_bpf_fx[0][3] ), 3 ), L_tmpX ); /*Q_input_fx + 13 + 1 - 3*/ + L_tmpX = L_add( L_shr( L_mult( memory_fx[0][2], full_band_bpf_fx[0][2] ), 3 ), L_tmpX ); /*Q_input_fx + 13 + 1 - 3*/ + L_tmpX = L_add( L_shr( L_mult( memory_fx[0][3], full_band_bpf_fx[0][1] ), 3 ), L_tmpX ); /*Q_input_fx + 13 + 1 - 3*/ + L_tmpX = L_add( L_shr( L_mult( input_fx[0], full_band_bpf_fx[0][0] ), 3 ), L_tmpX ); /*Q_input_fx + 13 + 1 - 3*/ #ifdef BASOP_NOGLOB - L_tmpX = L_sub_sat(L_tmpX,L_shl_sat(Mult_32_16(memory2_fx[1][3],full_band_bpf_fx[3][1]),2));/*Q_input_fx + 11 + 13 -15 +2*/ - L_tmpX = L_sub_sat(L_tmpX,L_shl_sat(Mult_32_16(memory2_fx[1][2],full_band_bpf_fx[3][2]),2));/*Q_input_fx + 11 + 13 -15 +2*/ - L_tmpX = L_sub_sat(L_tmpX,L_shl_sat(Mult_32_16(memory2_fx[1][1],full_band_bpf_fx[3][3]),2));/*Q_input_fx + 11 + 13 -15 +2*/ - L_tmp[0] = L_sub_sat(L_tmpX,L_shl_sat(Mult_32_16(memory2_fx[1][0],full_band_bpf_fx[3][4]),2));/*Q_input_fx + 11 + 13 -15 +2*/ move32(); + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( memory2_fx[1][3], full_band_bpf_fx[3][1] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( memory2_fx[1][2], full_band_bpf_fx[3][2] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( memory2_fx[1][1], full_band_bpf_fx[3][3] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ + L_tmp[0] = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( memory2_fx[1][0], full_band_bpf_fx[3][4] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ + move32(); #else - L_tmpX = L_sub(L_tmpX,L_shl(Mult_32_16(memory2_fx[1][3],full_band_bpf_fx[3][1]),2));/*Q_input_fx + 11 + 13 -15 +2*/ - L_tmpX = L_sub(L_tmpX,L_shl(Mult_32_16(memory2_fx[1][2],full_band_bpf_fx[3][2]),2));/*Q_input_fx + 11 + 13 -15 +2*/ - L_tmpX = L_sub(L_tmpX,L_shl(Mult_32_16(memory2_fx[1][1],full_band_bpf_fx[3][3]),2));/*Q_input_fx + 11 + 13 -15 +2*/ - L_tmp[0] = L_sub(L_tmpX,L_shl(Mult_32_16(memory2_fx[1][0],full_band_bpf_fx[3][4]),2));/*Q_input_fx + 11 + 13 -15 +2*/ move32(); + L_tmpX = L_sub( L_tmpX, L_shl( Mult_32_16( memory2_fx[1][3], full_band_bpf_fx[3][1] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ + L_tmpX = L_sub( L_tmpX, L_shl( Mult_32_16( memory2_fx[1][2], full_band_bpf_fx[3][2] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ + L_tmpX = L_sub( L_tmpX, L_shl( Mult_32_16( memory2_fx[1][1], full_band_bpf_fx[3][3] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ + L_tmp[0] = L_sub( L_tmpX, L_shl( Mult_32_16( memory2_fx[1][0], full_band_bpf_fx[3][4] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ + move32(); #endif - L_tmpX = L_shr(L_mult(memory_fx[0][1],full_band_bpf_fx[0][4]),3);/*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_add(L_shr(L_mult(memory_fx[0][2],full_band_bpf_fx[0][3]),3),L_tmpX);/*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_add(L_shr(L_mult(memory_fx[0][3],full_band_bpf_fx[0][2]),3),L_tmpX);/*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_add(L_shr(L_mult(input_fx[0],full_band_bpf_fx[0][1]),3),L_tmpX);/*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_add(L_shr(L_mult(input_fx[1],full_band_bpf_fx[0][0]),3),L_tmpX);/*Q_input_fx + 13 + 1 - 3*/ + L_tmpX = L_shr( L_mult( memory_fx[0][1], full_band_bpf_fx[0][4] ), 3 ); /*Q_input_fx + 13 + 1 - 3*/ + L_tmpX = L_add( L_shr( L_mult( memory_fx[0][2], full_band_bpf_fx[0][3] ), 3 ), L_tmpX ); /*Q_input_fx + 13 + 1 - 3*/ + L_tmpX = L_add( L_shr( L_mult( memory_fx[0][3], full_band_bpf_fx[0][2] ), 3 ), L_tmpX ); /*Q_input_fx + 13 + 1 - 3*/ + L_tmpX = L_add( L_shr( L_mult( input_fx[0], full_band_bpf_fx[0][1] ), 3 ), L_tmpX ); /*Q_input_fx + 13 + 1 - 3*/ + L_tmpX = L_add( L_shr( L_mult( input_fx[1], full_band_bpf_fx[0][0] ), 3 ), L_tmpX ); /*Q_input_fx + 13 + 1 - 3*/ #ifdef BASOP_NOGLOB - L_tmpX = L_sub_sat(L_tmpX,L_shl_sat(Mult_32_16(L_tmp[0],full_band_bpf_fx[3][1]),2));/*Q_input_fx + 11 + 13 -15 +2*/ - L_tmpX = L_sub_sat(L_tmpX,L_shl_sat(Mult_32_16(memory2_fx[1][3],full_band_bpf_fx[3][2]),2));/*Q_input_fx + 11 + 13 -15 +2*/ - L_tmpX = L_sub_sat(L_tmpX,L_shl_sat(Mult_32_16(memory2_fx[1][2],full_band_bpf_fx[3][3]),2));/*Q_input_fx + 11 + 13 -15 +2*/ - L_tmp[1] = L_sub_sat(L_tmpX,L_shl_sat(Mult_32_16(memory2_fx[1][1],full_band_bpf_fx[3][4]),2));/*Q_input_fx + 11 + 13 -15 +2*/ move32(); + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_tmp[0], full_band_bpf_fx[3][1] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( memory2_fx[1][3], full_band_bpf_fx[3][2] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( memory2_fx[1][2], full_band_bpf_fx[3][3] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ + L_tmp[1] = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( memory2_fx[1][1], full_band_bpf_fx[3][4] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ + move32(); #else - L_tmpX = L_sub(L_tmpX,L_shl(Mult_32_16(L_tmp[0],full_band_bpf_fx[3][1]),2));/*Q_input_fx + 11 + 13 -15 +2*/ - L_tmpX = L_sub(L_tmpX,L_shl(Mult_32_16(memory2_fx[1][3],full_band_bpf_fx[3][2]),2));/*Q_input_fx + 11 + 13 -15 +2*/ - L_tmpX = L_sub(L_tmpX,L_shl(Mult_32_16(memory2_fx[1][2],full_band_bpf_fx[3][3]),2));/*Q_input_fx + 11 + 13 -15 +2*/ - L_tmp[1] = L_sub(L_tmpX,L_shl(Mult_32_16(memory2_fx[1][1],full_band_bpf_fx[3][4]),2));/*Q_input_fx + 11 + 13 -15 +2*/ move32(); + L_tmpX = L_sub( L_tmpX, L_shl( Mult_32_16( L_tmp[0], full_band_bpf_fx[3][1] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ + L_tmpX = L_sub( L_tmpX, L_shl( Mult_32_16( memory2_fx[1][3], full_band_bpf_fx[3][2] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ + L_tmpX = L_sub( L_tmpX, L_shl( Mult_32_16( memory2_fx[1][2], full_band_bpf_fx[3][3] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ + L_tmp[1] = L_sub( L_tmpX, L_shl( Mult_32_16( memory2_fx[1][1], full_band_bpf_fx[3][4] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ + move32(); #endif - L_tmpX = L_shr(L_mult(memory_fx[0][2],full_band_bpf_fx[0][4]),3);/*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_add(L_shr(L_mult(memory_fx[0][3],full_band_bpf_fx[0][3]),3),L_tmpX);/*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_add(L_shr(L_mult(input_fx[0],full_band_bpf_fx[0][2]),3),L_tmpX);/*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_add(L_shr(L_mult(input_fx[1],full_band_bpf_fx[0][1]),3),L_tmpX);/*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_add(L_shr(L_mult(input_fx[2],full_band_bpf_fx[0][0]),3),L_tmpX);/*Q_input_fx + 13 + 1 - 3*/ + L_tmpX = L_shr( L_mult( memory_fx[0][2], full_band_bpf_fx[0][4] ), 3 ); /*Q_input_fx + 13 + 1 - 3*/ + L_tmpX = L_add( L_shr( L_mult( memory_fx[0][3], full_band_bpf_fx[0][3] ), 3 ), L_tmpX ); /*Q_input_fx + 13 + 1 - 3*/ + L_tmpX = L_add( L_shr( L_mult( input_fx[0], full_band_bpf_fx[0][2] ), 3 ), L_tmpX ); /*Q_input_fx + 13 + 1 - 3*/ + L_tmpX = L_add( L_shr( L_mult( input_fx[1], full_band_bpf_fx[0][1] ), 3 ), L_tmpX ); /*Q_input_fx + 13 + 1 - 3*/ + L_tmpX = L_add( L_shr( L_mult( input_fx[2], full_band_bpf_fx[0][0] ), 3 ), L_tmpX ); /*Q_input_fx + 13 + 1 - 3*/ #ifdef BASOP_NOGLOB - L_tmpX = L_sub_sat(L_tmpX,L_shl_sat(Mult_32_16(L_tmp[1],full_band_bpf_fx[3][1]),2));/*Q_input_fx + 11 + 13 -15 +2*/ - L_tmpX = L_sub_sat(L_tmpX,L_shl_sat(Mult_32_16(L_tmp[0],full_band_bpf_fx[3][2]),2));/*Q_input_fx + 11 + 13 -15 +2*/ - L_tmpX = L_sub_sat(L_tmpX,L_shl_sat(Mult_32_16(memory2_fx[1][3],full_band_bpf_fx[3][3]),2));/*Q_input_fx + 11 + 13 -15 +2*/ - L_tmp[2] = L_sub_sat(L_tmpX,L_shl_sat(Mult_32_16(memory2_fx[1][2],full_band_bpf_fx[3][4]),2));/*Q_input_fx + 11 + 13 -15 +2*/ move32(); + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_tmp[1], full_band_bpf_fx[3][1] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_tmp[0], full_band_bpf_fx[3][2] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( memory2_fx[1][3], full_band_bpf_fx[3][3] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ + L_tmp[2] = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( memory2_fx[1][2], full_band_bpf_fx[3][4] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ + move32(); #else - L_tmpX = L_sub(L_tmpX,L_shl(Mult_32_16(L_tmp[1],full_band_bpf_fx[3][1]),2));/*Q_input_fx + 11 + 13 -15 +2*/ - L_tmpX = L_sub(L_tmpX,L_shl(Mult_32_16(L_tmp[0],full_band_bpf_fx[3][2]),2));/*Q_input_fx + 11 + 13 -15 +2*/ - L_tmpX = L_sub(L_tmpX,L_shl(Mult_32_16(memory2_fx[1][3],full_band_bpf_fx[3][3]),2));/*Q_input_fx + 11 + 13 -15 +2*/ - L_tmp[2] = L_sub(L_tmpX,L_shl(Mult_32_16(memory2_fx[1][2],full_band_bpf_fx[3][4]),2));/*Q_input_fx + 11 + 13 -15 +2*/ move32(); -#endif - L_tmpX = L_shr(L_mult(memory_fx[0][3],full_band_bpf_fx[0][4]),3);/*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_add(L_shr(L_mult(input_fx[0],full_band_bpf_fx[0][3]),3),L_tmpX);/*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_add(L_shr(L_mult(input_fx[1],full_band_bpf_fx[0][2]),3),L_tmpX);/*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_add(L_shr(L_mult(input_fx[2],full_band_bpf_fx[0][1]),3),L_tmpX);/*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_add(L_shr(L_mult(input_fx[3],full_band_bpf_fx[0][0]),3),L_tmpX);/*Q_input_fx + 13 + 1 - 3*/ + L_tmpX = L_sub( L_tmpX, L_shl( Mult_32_16( L_tmp[1], full_band_bpf_fx[3][1] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ + L_tmpX = L_sub( L_tmpX, L_shl( Mult_32_16( L_tmp[0], full_band_bpf_fx[3][2] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ + L_tmpX = L_sub( L_tmpX, L_shl( Mult_32_16( memory2_fx[1][3], full_band_bpf_fx[3][3] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ + L_tmp[2] = L_sub( L_tmpX, L_shl( Mult_32_16( memory2_fx[1][2], full_band_bpf_fx[3][4] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ + move32(); +#endif + L_tmpX = L_shr( L_mult( memory_fx[0][3], full_band_bpf_fx[0][4] ), 3 ); /*Q_input_fx + 13 + 1 - 3*/ + L_tmpX = L_add( L_shr( L_mult( input_fx[0], full_band_bpf_fx[0][3] ), 3 ), L_tmpX ); /*Q_input_fx + 13 + 1 - 3*/ + L_tmpX = L_add( L_shr( L_mult( input_fx[1], full_band_bpf_fx[0][2] ), 3 ), L_tmpX ); /*Q_input_fx + 13 + 1 - 3*/ + L_tmpX = L_add( L_shr( L_mult( input_fx[2], full_band_bpf_fx[0][1] ), 3 ), L_tmpX ); /*Q_input_fx + 13 + 1 - 3*/ + L_tmpX = L_add( L_shr( L_mult( input_fx[3], full_band_bpf_fx[0][0] ), 3 ), L_tmpX ); /*Q_input_fx + 13 + 1 - 3*/ #ifdef BASOP_NOGLOB - L_tmpX = L_sub_sat(L_tmpX,L_shl_sat(Mult_32_16(L_tmp[2],full_band_bpf_fx[3][1]),2));/*Q_input_fx + 11 + 13 -15 +2*/ - L_tmpX = L_sub_sat(L_tmpX,L_shl_sat(Mult_32_16(L_tmp[1],full_band_bpf_fx[3][2]),2));/*Q_input_fx + 11 + 13 -15 +2*/ - L_tmpX = L_sub_sat(L_tmpX,L_shl_sat(Mult_32_16(L_tmp[0],full_band_bpf_fx[3][3]),2));/*Q_input_fx + 11 + 13 -15 +2*/ - L_tmp[3] = L_sub_sat(L_tmpX,L_shl_sat(Mult_32_16(memory2_fx[1][3],full_band_bpf_fx[3][4]),2));/*Q_input_fx + 11 + 13 -15 +2*/ move32(); + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_tmp[2], full_band_bpf_fx[3][1] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_tmp[1], full_band_bpf_fx[3][2] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_tmp[0], full_band_bpf_fx[3][3] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ + L_tmp[3] = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( memory2_fx[1][3], full_band_bpf_fx[3][4] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ + move32(); #else - L_tmpX = L_sub(L_tmpX,L_shl(Mult_32_16(L_tmp[2],full_band_bpf_fx[3][1]),2));/*Q_input_fx + 11 + 13 -15 +2*/ - L_tmpX = L_sub(L_tmpX,L_shl(Mult_32_16(L_tmp[1],full_band_bpf_fx[3][2]),2));/*Q_input_fx + 11 + 13 -15 +2*/ - L_tmpX = L_sub(L_tmpX,L_shl(Mult_32_16(L_tmp[0],full_band_bpf_fx[3][3]),2));/*Q_input_fx + 11 + 13 -15 +2*/ - L_tmp[3] = L_sub(L_tmpX,L_shl(Mult_32_16(memory2_fx[1][3],full_band_bpf_fx[3][4]),2));/*Q_input_fx + 11 + 13 -15 +2*/ move32(); + L_tmpX = L_sub( L_tmpX, L_shl( Mult_32_16( L_tmp[2], full_band_bpf_fx[3][1] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ + L_tmpX = L_sub( L_tmpX, L_shl( Mult_32_16( L_tmp[1], full_band_bpf_fx[3][2] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ + L_tmpX = L_sub( L_tmpX, L_shl( Mult_32_16( L_tmp[0], full_band_bpf_fx[3][3] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ + L_tmp[3] = L_sub( L_tmpX, L_shl( Mult_32_16( memory2_fx[1][3], full_band_bpf_fx[3][4] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ + move32(); #endif - FOR( i=4; i0) + IF( temp_p1_p3 > 0 ) { - expa = norm_l(temp_p1_p3); - fraca = extract_h(L_shl(temp_p1_p3,expa)); - expa = sub(30,expa); + expa = norm_l( temp_p1_p3 ); + fraca = extract_h( L_shl( temp_p1_p3, expa ) ); + expa = sub( 30, expa ); - expb = norm_l(temp_p1_p2); + expb = norm_l( temp_p1_p2 ); #ifdef BASOP_NOGLOB - fracb = round_fx_o(L_shl_o(temp_p1_p2,expb, &Overflow), &Overflow); + fracb = round_fx_o( L_shl_o( temp_p1_p2, expb, &Overflow ), &Overflow ); #else - fracb = round_fx(L_shl(temp_p1_p2,expb)); + fracb = round_fx( L_shl( temp_p1_p2, expb ) ); #endif - expb = sub(30,expb); + expb = sub( 30, expb ); num_flag = 0; move16(); - IF(fraca<0) + IF( fraca < 0 ) { num_flag = 1; move16(); - fraca = negate(fraca); + fraca = negate( fraca ); } den_flag = 0; move16(); - IF(fracb<0) + IF( fracb < 0 ) { den_flag = 1; move16(); - fracb = negate(fracb); + fracb = negate( fracb ); } - scale = shr(sub(fraca,fracb),15); - fracb = shl(fracb,scale); - expb = sub(expb,scale); + scale = shr( sub( fraca, fracb ), 15 ); + fracb = shl( fracb, scale ); + expb = sub( expb, scale ); - tmp = div_s(fracb,fraca); - exp1 = sub(expb,expa); + tmp = div_s( fracb, fraca ); + exp1 = sub( expb, expa ); #ifdef BASOP_NOGLOB tmp = shl_sat( tmp, exp1 ); #else - tmp = shl(tmp,exp1); + tmp = shl( tmp, exp1 ); #endif - if(NE_16(num_flag,den_flag)) + if ( NE_16( num_flag, den_flag ) ) { - tmp = negate(tmp); + tmp = negate( tmp ); } } ELSE @@ -5638,10 +5659,10 @@ void Estimate_mix_factors_fx( tmp = 0; } - vf_modified[0] = s_min(s_max(tmp, 3277 /* 0.1f in Q15*/), 32440 /* 0.99f in Q15 */); + vf_modified[0] = s_min( s_max( tmp, 3277 /* 0.1f in Q15*/ ), 32440 /* 0.99f in Q15 */ ); move16(); - *vf_ind = usquant_fx(vf_modified[0], &tmp1, 4096 /* 0.125 in Q15 */, 2048 /* 0.125 in Q14 */, shl(1,NUM_BITS_SHB_VF)); + *vf_ind = usquant_fx( vf_modified[0], &tmp1, 4096 /* 0.125 in Q15 */, 2048 /* 0.125 in Q14 */, shl( 1, NUM_BITS_SHB_VF ) ); move16(); vf_modified[0] = tmp1; @@ -5669,41 +5690,41 @@ void Estimate_mix_factors_fx( void tbe_celp_exc( const int16_t element_mode, /* i : element mode */ const int16_t idchan, /* i : channel ID */ - float* bwe_exc, /* i/o: BWE excitation */ + float *bwe_exc, /* i/o: BWE excitation */ const int16_t L_frame, /* i : frame length */ const int16_t L_subfr, /* i : subframe length */ const int16_t i_subfr, /* i : subframe index */ const int16_t T0, /* i : integer pitch lag */ const int16_t T0_frac, /* i : fraction of lag */ - float* error, /* i/o: error */ + float *error, /* i/o: error */ const int16_t tdm_LRTD_flag /* i : LRTD stereo mode flag */ ) { int16_t i, offset; - if (element_mode == IVAS_CPE_TD && idchan == 1 && !tdm_LRTD_flag) + if ( element_mode == IVAS_CPE_TD && idchan == 1 && !tdm_LRTD_flag ) { return; } - if (L_frame == L_FRAME) + if ( L_frame == L_FRAME ) { - offset = tbe_celp_exc_offset(T0, T0_frac); + offset = tbe_celp_exc_offset( T0, T0_frac ); - for (i = 0; i < L_subfr * HIBND_ACB_L_FAC; i++) + for ( i = 0; i < L_subfr * HIBND_ACB_L_FAC; i++ ) { - bwe_exc[i + i_subfr * HIBND_ACB_L_FAC] = bwe_exc[i + i_subfr * HIBND_ACB_L_FAC - offset + (int16_t)*error]; + bwe_exc[i + i_subfr * HIBND_ACB_L_FAC] = bwe_exc[i + i_subfr * HIBND_ACB_L_FAC - offset + (int16_t) *error]; } - *error += (float)offset - (float)T0 * HIBND_ACB_L_FAC - 0.25f * HIBND_ACB_L_FAC * (float)T0_frac; + *error += (float) offset - (float) T0 * HIBND_ACB_L_FAC - 0.25f * HIBND_ACB_L_FAC * (float) T0_frac; } else { - offset = T0 * 2 + (int16_t)((float)T0_frac * 0.5f + 4 + 0.5f) - 4; - for (i = 0; i < L_subfr * 2; i++) + offset = T0 * 2 + (int16_t) ( (float) T0_frac * 0.5f + 4 + 0.5f ) - 4; + for ( i = 0; i < L_subfr * 2; i++ ) { - bwe_exc[i + i_subfr * 2] = bwe_exc[i + i_subfr * 2 - offset + (int16_t)*error]; + bwe_exc[i + i_subfr * 2] = bwe_exc[i + i_subfr * 2 - offset + (int16_t) *error]; } - *error += (float)offset - (float)T0 * 2 - 0.5f * (float)T0_frac; + *error += (float) offset - (float) T0 * 2 - 0.5f * (float) T0_frac; } return; @@ -5738,35 +5759,35 @@ void tbe_celp_exc( /*======================================================================================*/ void prep_tbe_exc_fx( - const Word16 L_frame_fx, /* i : length of the frame */ + const Word16 L_frame_fx, /* i : length of the frame */ #ifdef ADD_IVAS_TBE_CODE const Word16 L_subfr, #endif - const Word16 i_subfr_fx, /* i : subframe index */ - const Word16 gain_pit_fx, /* i : Pitch gain Q14*/ - const Word32 gain_code_fx, /* i : algebraic codebook gain 16+Q_exc*/ - const Word16 code_fx[], /* i : algebraic excitation Q9*/ - const Word16 voice_fac_fx, /* i : voicing factor Q15*/ - Word16 *voice_factors_fx, /* o : TBE voicing factor Q15*/ - Word16 bwe_exc_fx[], /* i/o: excitation for TBE Q_exc*/ - const Word16 gain_preQ_fx, /* i : prequantizer excitation gain */ - const Word16 code_preQ_fx[], /* i : prequantizer excitation */ - const Word16 Q_exc, /* i : Excitation, bwe_exc Q-factor */ - Word16 T0, /* i : integer pitch variables Q0 */ - Word16 T0_frac, /* i : Fractional pitch variables Q0*/ - const Word16 coder_type, /* i : coding type */ + const Word16 i_subfr_fx, /* i : subframe index */ + const Word16 gain_pit_fx, /* i : Pitch gain Q14*/ + const Word32 gain_code_fx, /* i : algebraic codebook gain 16+Q_exc*/ + const Word16 code_fx[], /* i : algebraic excitation Q9*/ + const Word16 voice_fac_fx, /* i : voicing factor Q15*/ + Word16 *voice_factors_fx, /* o : TBE voicing factor Q15*/ + Word16 bwe_exc_fx[], /* i/o: excitation for TBE Q_exc*/ + const Word16 gain_preQ_fx, /* i : prequantizer excitation gain */ + const Word16 code_preQ_fx[], /* i : prequantizer excitation */ + const Word16 Q_exc, /* i : Excitation, bwe_exc Q-factor */ + Word16 T0, /* i : integer pitch variables Q0 */ + Word16 T0_frac, /* i : Fractional pitch variables Q0*/ + const Word16 coder_type, /* i : coding type */ Word32 core_brate #ifdef ADD_IVAS_TBE_CODE - , /* i : core bitrate */ - const int16_t element_mode, /* i : element mode */ - const int16_t idchan, /* i : channel ID */ - const int16_t flag_TD_BWE, /* i : flag indicating whether hTD_BWE exists */ - const int16_t tdm_LRTD_flag /* i : LRTD stereo mode flag */ + , /* i : core bitrate */ + const int16_t element_mode, /* i : element mode */ + const int16_t idchan, /* i : channel ID */ + const int16_t flag_TD_BWE, /* i : flag indicating whether hTD_BWE exists */ + const int16_t tdm_LRTD_flag /* i : LRTD stereo mode flag */ #endif ) { Word16 i; - Word16 tmp_code_fx[2*L_SUBFR * HIBND_ACB_L_FAC]; + Word16 tmp_code_fx[2 * L_SUBFR * HIBND_ACB_L_FAC]; Word16 tmp_code_preInt_fx[L_SUBFR]; Word16 gain_code16 = 0; Word16 tmp /*, tmp1, tmp2*/; @@ -5787,66 +5808,66 @@ void prep_tbe_exc_fx( = VF_0th_PARAM + voice_fac * (VF_1st_PARAM + VF_2nd_PARAM * voice_fac ) *voice_factors = min( max_val(0.0f, *voice_factors), 1.0f); */ tempQ31 = L_deposit_h( VF_1st_PARAM_FX ); - tempQ15 = mac_r(tempQ31, VF_2nd_PARAM_FX, voice_fac_fx); + tempQ15 = mac_r( tempQ31, VF_2nd_PARAM_FX, voice_fac_fx ); tempQ31 = L_deposit_h( VF_0th_PARAM_FX ); - *voice_factors_fx = mac_r(tempQ31, voice_fac_fx, tempQ15); + *voice_factors_fx = mac_r( tempQ31, voice_fac_fx, tempQ15 ); tmp = 32767; move16(); #ifdef BASOP_NOGLOB pitch = shl_o( add( shl_o( T0, 2, &Overflow ), T0_frac ), 5, &Overflow ); /* Q7 */ -#else /* BASOP_NOGLOB */ - pitch = shl( add( shl( T0, 2 ), T0_frac ), 5 ); /* Q7 */ -#endif /* BASOP_NOGLOB */ +#else /* BASOP_NOGLOB */ + pitch = shl( add( shl( T0, 2 ), T0_frac ), 5 ); /* Q7 */ +#endif /* BASOP_NOGLOB */ test(); test(); - IF ( ( ( EQ_16(coder_type,VOICED))||(GT_16(pitch,14784)))&&(GT_32(core_brate,ACELP_8k00))) + IF( ( ( EQ_16( coder_type, VOICED ) ) || ( GT_16( pitch, 14784 ) ) ) && ( GT_32( core_brate, ACELP_8k00 ) ) ) { tmp = MAX_16; move16(); *voice_factors_fx = mult_r( *voice_factors_fx, tmp ); } - *voice_factors_fx = s_min(s_max(*voice_factors_fx, 0), MAX_16); + *voice_factors_fx = s_min( s_max( *voice_factors_fx, 0 ), MAX_16 ); move16(); #ifdef ADD_IVAS_TBE_CODE - IF (EQ_16(element_mode, IVAS_CPE_TD) && EQ_16(idchan, 1) && !tdm_LRTD_flag) + IF( EQ_16( element_mode, IVAS_CPE_TD ) && EQ_16( idchan, 1 ) && !tdm_LRTD_flag ) { - IF (flag_TD_BWE && i_subfr == 0) + IF( flag_TD_BWE && i_subfr == 0 ) { - set16_fx(bwe_exc, 0, L_FRAME32k); + set16_fx( bwe_exc, 0, L_FRAME32k ); } return; } - + #endif - IF ( EQ_16(L_frame_fx,L_FRAME)) + IF( EQ_16( L_frame_fx, L_FRAME ) ) { - interp_code_5over2_fx( code_fx, tmp_code_fx, L_subfr); /* code: Q9, tmp_code: Q9 */ + interp_code_5over2_fx( code_fx, tmp_code_fx, L_subfr ); /* code: Q9, tmp_code: Q9 */ #ifdef BASOP_NOGLOB - gain_code16 = round_fx_o( L_shl_o( gain_code_fx, Q_exc, &Overflow ), &Overflow); /*Q_exc */ + gain_code16 = round_fx_o( L_shl_o( gain_code_fx, Q_exc, &Overflow ), &Overflow ); /*Q_exc */ #else - gain_code16 = round_fx( L_shl( gain_code_fx, Q_exc ) ); /*Q_exc */ + gain_code16 = round_fx( L_shl( gain_code_fx, Q_exc ) ); /*Q_exc */ #endif - FOR ( i = 0; i < L_subfr* HIBND_ACB_L_FAC; i++ ) + FOR( i = 0; i < L_subfr * HIBND_ACB_L_FAC; i++ ) { - L_tmp = L_mult( gain_code16, tmp_code_fx[i] ); /* Q9 + Q_exc + 1*/ + L_tmp = L_mult( gain_code16, tmp_code_fx[i] ); /* Q9 + Q_exc + 1*/ #ifdef BASOP_NOGLOB L_tmp = L_shl_sat( L_tmp, 5 ); /* Q9 + Q_exc + Q6*/ L_tmp = L_mac_sat( L_tmp, gain_pit_fx, bwe_exc_fx[i + i_subfr_fx * HIBND_ACB_L_FAC] ); /*Q15+Q_exc */ #else - L_tmp = L_shl( L_tmp, 5 ); /* Q9 + Q_exc + Q6*/ + L_tmp = L_shl( L_tmp, 5 ); /* Q9 + Q_exc + Q6*/ L_tmp = L_mac( L_tmp, gain_pit_fx, bwe_exc_fx[i + i_subfr_fx * HIBND_ACB_L_FAC] ); /*Q15+Q_exc */ #endif #ifdef BASOP_NOGLOB - L_tmp = L_shl_o( L_tmp, 1 , &Overflow); /*16+Q_exc */ /* saturation can occur here */ - bwe_exc_fx[i + i_subfr_fx * HIBND_ACB_L_FAC] = round_fx_o(L_tmp, &Overflow); /*Q_exc */ -#else /* BASOP_NOGLOB */ - L_tmp = L_shl( L_tmp, 1 ); /*16+Q_exc */ /* saturation can occur here */ - bwe_exc_fx[i + i_subfr_fx * HIBND_ACB_L_FAC] = round_fx( L_tmp ); /*Q_exc */ -#endif /* BASOP_NOGLOB */ + L_tmp = L_shl_o( L_tmp, 1, &Overflow ); /*16+Q_exc */ /* saturation can occur here */ + bwe_exc_fx[i + i_subfr_fx * HIBND_ACB_L_FAC] = round_fx_o( L_tmp, &Overflow ); /*Q_exc */ +#else /* BASOP_NOGLOB */ + L_tmp = L_shl( L_tmp, 1 ); /*16+Q_exc */ /* saturation can occur here */ + bwe_exc_fx[i + i_subfr_fx * HIBND_ACB_L_FAC] = round_fx( L_tmp ); /*Q_exc */ +#endif /* BASOP_NOGLOB */ } } ELSE @@ -5856,20 +5877,20 @@ void prep_tbe_exc_fx( FOR( i = 0; i < L_subfr; i++ ) { /*code in the encoder is Q9 and there is no <<1 with Mult_32_16 Q16 * Q9 -> Q9 */ - Ltemp1 = Mult_32_16(gain_code_fx, code_fx[i]); /* Q16 + Q9 + 1 - 16 = Q10 */ - Ltemp2 = L_mult(gain_preQ_fx, code_preQ_fx[i]); /*Q2 * Q10 -> Q12 */ + Ltemp1 = Mult_32_16( gain_code_fx, code_fx[i] ); /* Q16 + Q9 + 1 - 16 = Q10 */ + Ltemp2 = L_mult( gain_preQ_fx, code_preQ_fx[i] ); /*Q2 * Q10 -> Q12 */ #ifdef BASOP_NOGLOB - Ltemp1 = L_shl_o(Ltemp1, Q_exc + 6 /*Q_exc+16-19*/, &Overflow); /*Q_exc+16 */ - Ltemp2 = L_shl_o( Ltemp2, Q_exc+4 /*Q_exc+16-13*/, &Overflow) ; /*Q_exc+16 */ + Ltemp1 = L_shl_o( Ltemp1, Q_exc + 6 /*Q_exc+16-19*/, &Overflow ); /*Q_exc+16 */ + Ltemp2 = L_shl_o( Ltemp2, Q_exc + 4 /*Q_exc+16-13*/, &Overflow ); /*Q_exc+16 */ - tmp_code_preInt_fx[i] = round_fx_o(L_add_o(Ltemp1, Ltemp2, &Overflow), &Overflow); /* Q_exc */ -#else /* BASOP_NOGLOB */ - Ltemp1 = L_shl( Ltemp1, Q_exc+6 /*Q_exc+16-19*/) ; /*Q_exc+16 */ - Ltemp2 = L_shl( Ltemp2, Q_exc+4 /*Q_exc+16-13*/ ) ; /*Q_exc+16 */ + tmp_code_preInt_fx[i] = round_fx_o( L_add_o( Ltemp1, Ltemp2, &Overflow ), &Overflow ); /* Q_exc */ +#else /* BASOP_NOGLOB */ + Ltemp1 = L_shl( Ltemp1, Q_exc + 6 /*Q_exc+16-19*/ ); /*Q_exc+16 */ + Ltemp2 = L_shl( Ltemp2, Q_exc + 4 /*Q_exc+16-13*/ ); /*Q_exc+16 */ - tmp_code_preInt_fx[i] = round_fx(L_add(Ltemp1, Ltemp2)); /* Q_exc */ -#endif /* BASOP_NOGLOB */ + tmp_code_preInt_fx[i] = round_fx( L_add( Ltemp1, Ltemp2 ) ); /* Q_exc */ +#endif /* BASOP_NOGLOB */ } } ELSE @@ -5877,27 +5898,29 @@ void prep_tbe_exc_fx( FOR( i = 0; i < L_subfr; i++ ) { /*code in the encoder is Q9 and there is no <<1 with Mult_32_16 Q16 * Q9 -> Q9 */ - Ltemp1 = Mult_32_16(gain_code_fx, code_fx[i]); /* Q16 + Q9 + 1 - 16 = Q10 */ + Ltemp1 = Mult_32_16( gain_code_fx, code_fx[i] ); /* Q16 + Q9 + 1 - 16 = Q10 */ #ifdef BASOP_NOGLOB - Ltemp1 = L_shl_o( Ltemp1, Q_exc+6 /*Q_exc+16-19*/, &Overflow) ; /*Q_exc+16 */ - tmp_code_preInt_fx[i] = round_fx_o(Ltemp1, &Overflow); /* Q_exc */ + Ltemp1 = L_shl_o( Ltemp1, Q_exc + 6 /*Q_exc+16-19*/, &Overflow ); /*Q_exc+16 */ + tmp_code_preInt_fx[i] = round_fx_o( Ltemp1, &Overflow ); /* Q_exc */ #else - Ltemp1 = L_shl( Ltemp1, Q_exc+6 /*Q_exc+16-19*/) ; /*Q_exc+16 */ - tmp_code_preInt_fx[i] = round_fx(Ltemp1); /* Q_exc */ + Ltemp1 = L_shl( Ltemp1, Q_exc + 6 /*Q_exc+16-19*/ ); /*Q_exc+16 */ + tmp_code_preInt_fx[i] = round_fx( Ltemp1 ); /* Q_exc */ #endif } } - interp_code_4over2_fx( tmp_code_preInt_fx, tmp_code_fx, L_subfr); /* o: tmp_code in Q_exc */ - FOR ( i = 0; i < L_subfr * 2; i++ ) + interp_code_4over2_fx( tmp_code_preInt_fx, tmp_code_fx, L_subfr ); /* o: tmp_code in Q_exc */ + FOR( i = 0; i < L_subfr * 2; i++ ) { - L_tmp = L_mult(gain_pit_fx, bwe_exc_fx[i + i_subfr_fx*2]); /*Q14+Q_exc+1 */ + L_tmp = L_mult( gain_pit_fx, bwe_exc_fx[i + i_subfr_fx * 2] ); /*Q14+Q_exc+1 */ #ifdef BASOP_NOGLOB - tmp = round_fx_o(L_shl_o(L_tmp, 1 /* (Q_exc+16)-(14+Q_exc+1)*/, &Overflow), &Overflow); /* tmp in Q_exc */ - bwe_exc_fx[i + i_subfr_fx * 2] = add_o(tmp, tmp_code_fx[i], &Overflow); /*Q_exc */ move16(); + tmp = round_fx_o( L_shl_o( L_tmp, 1 /* (Q_exc+16)-(14+Q_exc+1)*/, &Overflow ), &Overflow ); /* tmp in Q_exc */ + bwe_exc_fx[i + i_subfr_fx * 2] = add_o( tmp, tmp_code_fx[i], &Overflow ); /*Q_exc */ + move16(); #else /* BASOP_NOGLOB */ - tmp = round_fx(L_shl(L_tmp, 1 /* (Q_exc+16)-(14+Q_exc+1)*/ )); /* tmp in Q_exc */ - bwe_exc_fx[i + i_subfr_fx * 2] = add(tmp, tmp_code_fx[i]); /*Q_exc */ move16(); + tmp = round_fx( L_shl( L_tmp, 1 /* (Q_exc+16)-(14+Q_exc+1)*/ ) ); /* tmp in Q_exc */ + bwe_exc_fx[i + i_subfr_fx * 2] = add( tmp, tmp_code_fx[i] ); /*Q_exc */ + move16(); #endif } } @@ -5934,30 +5957,30 @@ void prep_tbe_exc_fx( /*======================================================================================*/ void prep_tbe_exc_ivas_fx( - const Word16 L_frame_fx, /* i : length of the frame */ -#if 1//def ADD_IVAS_TBE_CODE + const Word16 L_frame_fx, /* i : length of the frame */ +#if 1 // def ADD_IVAS_TBE_CODE const Word16 L_subfr, #endif - const Word16 i_subfr_fx, /* i : subframe index */ - const Word16 gain_pit_fx, /* i : Pitch gain Q14*/ - const Word32 gain_code_fx, /* i : algebraic codebook gain 16+Q_exc*/ - const Word16 code_fx[], /* i : algebraic excitation Q9*/ - const Word16 voice_fac_fx, /* i : voicing factor Q15*/ - Word16 *voice_factors_fx, /* o : TBE voicing factor Q15*/ - Word16 bwe_exc_fx[], /* i/o: excitation for TBE Q_exc*/ - const Word16 gain_preQ_fx, /* i : prequantizer excitation gain */ - const Word16 code_preQ_fx[], /* i : prequantizer excitation */ - const Word16 Q_exc, /* i : Excitation, bwe_exc Q-factor */ - Word16 T0, /* i : integer pitch variables Q0 */ - Word16 T0_frac, /* i : Fractional pitch variables Q0*/ - const Word16 coder_type, /* i : coding type */ + const Word16 i_subfr_fx, /* i : subframe index */ + const Word16 gain_pit_fx, /* i : Pitch gain Q14*/ + const Word32 gain_code_fx, /* i : algebraic codebook gain 16+Q_exc*/ + const Word16 code_fx[], /* i : algebraic excitation Q9*/ + const Word16 voice_fac_fx, /* i : voicing factor Q15*/ + Word16 *voice_factors_fx, /* o : TBE voicing factor Q15*/ + Word16 bwe_exc_fx[], /* i/o: excitation for TBE Q_exc*/ + const Word16 gain_preQ_fx, /* i : prequantizer excitation gain */ + const Word16 code_preQ_fx[], /* i : prequantizer excitation */ + const Word16 Q_exc, /* i : Excitation, bwe_exc Q-factor */ + Word16 T0, /* i : integer pitch variables Q0 */ + Word16 T0_frac, /* i : Fractional pitch variables Q0*/ + const Word16 coder_type, /* i : coding type */ Word32 core_brate -#if 1//def ADD_IVAS_TBE_CODE - , /* i : core bitrate */ - const Word16 element_mode, /* i : element mode */ - const Word16 idchan, /* i : channel ID */ - const Word16 flag_TD_BWE, /* i : flag indicating whether hTD_BWE exists */ - const Word16 tdm_LRTD_flag /* i : LRTD stereo mode flag */ +#if 1 // def ADD_IVAS_TBE_CODE + , /* i : core bitrate */ + const Word16 element_mode, /* i : element mode */ + const Word16 idchan, /* i : channel ID */ + const Word16 flag_TD_BWE, /* i : flag indicating whether hTD_BWE exists */ + const Word16 tdm_LRTD_flag /* i : LRTD stereo mode flag */ #endif ) { @@ -5972,7 +5995,7 @@ void prep_tbe_exc_ivas_fx( Word32 L_tmp, Ltemp1, Ltemp2; Word32 tempQ31; Word16 tempQ15; -#if 0//ndef ADD_IVAS_TBE_CODE +#if 0 // ndef ADD_IVAS_TBE_CODE Word16 L_subfr = L_SUBFR; #endif #ifdef BASOP_NOGLOB_DECLARE_LOCAL @@ -5982,113 +6005,115 @@ void prep_tbe_exc_ivas_fx( /**voice_factors = VF_0th_PARAM + VF_1st_PARAM * voice_fac + VF_2nd_PARAM * voice_fac * voice_fac; = VF_0th_PARAM + voice_fac * (VF_1st_PARAM + VF_2nd_PARAM * voice_fac ) *voice_factors = min( max_val(0.0f, *voice_factors), 1.0f); */ - tempQ31 = L_deposit_h(VF_1st_PARAM_FX); - tempQ15 = mac_r(tempQ31, VF_2nd_PARAM_FX, voice_fac_fx); - tempQ31 = L_deposit_h(VF_0th_PARAM_FX); - *voice_factors_fx = mac_r(tempQ31, voice_fac_fx, tempQ15); + tempQ31 = L_deposit_h( VF_1st_PARAM_FX ); + tempQ15 = mac_r( tempQ31, VF_2nd_PARAM_FX, voice_fac_fx ); + tempQ31 = L_deposit_h( VF_0th_PARAM_FX ); + *voice_factors_fx = mac_r( tempQ31, voice_fac_fx, tempQ15 ); tmp = 32767; move16(); #ifdef BASOP_NOGLOB - pitch = shl_o(add(shl_o(T0, 2, &Overflow), T0_frac), 5, &Overflow); /* Q7 */ -#else /* BASOP_NOGLOB */ - pitch = shl(add(shl(T0, 2), T0_frac), 5); /* Q7 */ -#endif /* BASOP_NOGLOB */ + pitch = shl_o( add( shl_o( T0, 2, &Overflow ), T0_frac ), 5, &Overflow ); /* Q7 */ +#else /* BASOP_NOGLOB */ + pitch = shl( add( shl( T0, 2 ), T0_frac ), 5 ); /* Q7 */ +#endif /* BASOP_NOGLOB */ test(); test(); - IF(((EQ_16(coder_type, VOICED)) || (GT_16(pitch, 14784))) && (GT_32(core_brate, ACELP_8k00))) + IF( ( ( EQ_16( coder_type, VOICED ) ) || ( GT_16( pitch, 14784 ) ) ) && ( GT_32( core_brate, ACELP_8k00 ) ) ) { tmp = MAX_16; move16(); - *voice_factors_fx = mult_r(*voice_factors_fx, tmp); + *voice_factors_fx = mult_r( *voice_factors_fx, tmp ); } - *voice_factors_fx = s_min(s_max(*voice_factors_fx, 0), MAX_16); + *voice_factors_fx = s_min( s_max( *voice_factors_fx, 0 ), MAX_16 ); move16(); -#if 1 //def ADD_IVAS_TBE_CODE - IF(EQ_16(element_mode, IVAS_CPE_TD) && EQ_16(idchan, 1) && !tdm_LRTD_flag) +#if 1 // def ADD_IVAS_TBE_CODE + IF( EQ_16( element_mode, IVAS_CPE_TD ) && EQ_16( idchan, 1 ) && !tdm_LRTD_flag ) { - IF(flag_TD_BWE && i_subfr_fx == 0) + IF( flag_TD_BWE && i_subfr_fx == 0 ) { - set16_fx(bwe_exc_fx, 0, L_FRAME32k); + set16_fx( bwe_exc_fx, 0, L_FRAME32k ); } return; } #endif - IF(EQ_16(L_frame_fx, L_FRAME)) + IF( EQ_16( L_frame_fx, L_FRAME ) ) { - interp_code_5over2_fx(code_fx, tmp_code_fx, L_subfr); /* code: Q9, tmp_code: Q9 */ + interp_code_5over2_fx( code_fx, tmp_code_fx, L_subfr ); /* code: Q9, tmp_code: Q9 */ #ifdef BASOP_NOGLOB - gain_code16 = round_fx_o(L_shl_o(gain_code_fx, Q_exc, &Overflow), &Overflow); /*Q_exc */ + gain_code16 = round_fx_o( L_shl_o( gain_code_fx, Q_exc, &Overflow ), &Overflow ); /*Q_exc */ #else - gain_code16 = round_fx(L_shl(gain_code_fx, Q_exc)); /*Q_exc */ + gain_code16 = round_fx( L_shl( gain_code_fx, Q_exc ) ); /*Q_exc */ #endif - FOR(i = 0; i < L_subfr* HIBND_ACB_L_FAC; i++) + FOR( i = 0; i < L_subfr * HIBND_ACB_L_FAC; i++ ) { - L_tmp = L_mult(gain_code16, tmp_code_fx[i]); /* Q9 + Q_exc + 1*/ - L_tmp = L_shl(L_tmp, 5); /* Q9 + Q_exc + Q6*/ - L_tmp = L_mac(L_tmp, gain_pit_fx, bwe_exc_fx[i + i_subfr_fx * HIBND_ACB_L_FAC]); /*Q15+Q_exc */ + L_tmp = L_mult( gain_code16, tmp_code_fx[i] ); /* Q9 + Q_exc + 1*/ + L_tmp = L_shl( L_tmp, 5 ); /* Q9 + Q_exc + Q6*/ + L_tmp = L_mac( L_tmp, gain_pit_fx, bwe_exc_fx[i + i_subfr_fx * HIBND_ACB_L_FAC] ); /*Q15+Q_exc */ #ifdef BASOP_NOGLOB - L_tmp = L_shl_o(L_tmp, 1, &Overflow); /*16+Q_exc */ /* saturation can occur here */ - bwe_exc_fx[i + i_subfr_fx * HIBND_ACB_L_FAC] = round_fx_o(L_tmp, &Overflow); /*Q_exc */ -#else /* BASOP_NOGLOB */ - L_tmp = L_shl(L_tmp, 1); /*16+Q_exc */ /* saturation can occur here */ - bwe_exc_fx[i + i_subfr_fx * HIBND_ACB_L_FAC] = round_fx(L_tmp); /*Q_exc */ -#endif /* BASOP_NOGLOB */ + L_tmp = L_shl_o( L_tmp, 1, &Overflow ); /*16+Q_exc */ /* saturation can occur here */ + bwe_exc_fx[i + i_subfr_fx * HIBND_ACB_L_FAC] = round_fx_o( L_tmp, &Overflow ); /*Q_exc */ +#else /* BASOP_NOGLOB */ + L_tmp = L_shl( L_tmp, 1 ); /*16+Q_exc */ /* saturation can occur here */ + bwe_exc_fx[i + i_subfr_fx * HIBND_ACB_L_FAC] = round_fx( L_tmp ); /*Q_exc */ +#endif /* BASOP_NOGLOB */ } } ELSE { - IF(gain_preQ_fx != 0) + IF( gain_preQ_fx != 0 ) { - FOR(i = 0; i < L_subfr; i++) + FOR( i = 0; i < L_subfr; i++ ) { /*code in the encoder is Q9 and there is no <<1 with Mult_32_16 Q16 * Q9 -> Q9 */ - Ltemp1 = Mult_32_16(gain_code_fx, code_fx[i]); /* Q16 + Q9 + 1 - 16 = Q10 */ - Ltemp2 = L_mult(gain_preQ_fx, code_preQ_fx[i]); /*Q2 * Q10 -> Q12 */ + Ltemp1 = Mult_32_16( gain_code_fx, code_fx[i] ); /* Q16 + Q9 + 1 - 16 = Q10 */ + Ltemp2 = L_mult( gain_preQ_fx, code_preQ_fx[i] ); /*Q2 * Q10 -> Q12 */ #ifdef BASOP_NOGLOB - Ltemp1 = L_shl_o(Ltemp1, Q_exc + 6 /*Q_exc+16-19*/, &Overflow); /*Q_exc+16 */ - Ltemp2 = L_shl_o(Ltemp2, Q_exc + 4 /*Q_exc+16-13*/, &Overflow); /*Q_exc+16 */ + Ltemp1 = L_shl_o( Ltemp1, Q_exc + 6 /*Q_exc+16-19*/, &Overflow ); /*Q_exc+16 */ + Ltemp2 = L_shl_o( Ltemp2, Q_exc + 4 /*Q_exc+16-13*/, &Overflow ); /*Q_exc+16 */ - tmp_code_preInt_fx[i] = round_fx_o(L_add_o(Ltemp1, Ltemp2, &Overflow), &Overflow); /* Q_exc */ -#else /* BASOP_NOGLOB */ - Ltemp1 = L_shl(Ltemp1, Q_exc + 6 /*Q_exc+16-19*/); /*Q_exc+16 */ - Ltemp2 = L_shl(Ltemp2, Q_exc + 4 /*Q_exc+16-13*/); /*Q_exc+16 */ + tmp_code_preInt_fx[i] = round_fx_o( L_add_o( Ltemp1, Ltemp2, &Overflow ), &Overflow ); /* Q_exc */ +#else /* BASOP_NOGLOB */ + Ltemp1 = L_shl( Ltemp1, Q_exc + 6 /*Q_exc+16-19*/ ); /*Q_exc+16 */ + Ltemp2 = L_shl( Ltemp2, Q_exc + 4 /*Q_exc+16-13*/ ); /*Q_exc+16 */ - tmp_code_preInt_fx[i] = round_fx(L_add(Ltemp1, Ltemp2)); /* Q_exc */ -#endif /* BASOP_NOGLOB */ + tmp_code_preInt_fx[i] = round_fx( L_add( Ltemp1, Ltemp2 ) ); /* Q_exc */ +#endif /* BASOP_NOGLOB */ } } ELSE { - FOR(i = 0; i < L_subfr; i++) + FOR( i = 0; i < L_subfr; i++ ) { - /*code in the encoder is Q9 and there is no <<1 with Mult_32_16 Q16 * Q9 -> Q9 */ - Ltemp1 = Mult_32_16(gain_code_fx, code_fx[i]); /* Q16 + Q9 + 1 - 16 = Q10 */ + /*code in the encoder is Q9 and there is no <<1 with Mult_32_16 Q16 * Q9 -> Q9 */ + Ltemp1 = Mult_32_16( gain_code_fx, code_fx[i] ); /* Q16 + Q9 + 1 - 16 = Q10 */ #ifdef BASOP_NOGLOB - Ltemp1 = L_shl_o(Ltemp1, Q_exc + 6 /*Q_exc+16-19*/, &Overflow); /*Q_exc+16 */ - tmp_code_preInt_fx[i] = round_fx_o(Ltemp1, &Overflow); /* Q_exc */ + Ltemp1 = L_shl_o( Ltemp1, Q_exc + 6 /*Q_exc+16-19*/, &Overflow ); /*Q_exc+16 */ + tmp_code_preInt_fx[i] = round_fx_o( Ltemp1, &Overflow ); /* Q_exc */ #else - Ltemp1 = L_shl(Ltemp1, Q_exc + 6 /*Q_exc+16-19*/); /*Q_exc+16 */ - tmp_code_preInt_fx[i] = round_fx(Ltemp1); /* Q_exc */ + Ltemp1 = L_shl( Ltemp1, Q_exc + 6 /*Q_exc+16-19*/ ); /*Q_exc+16 */ + tmp_code_preInt_fx[i] = round_fx( Ltemp1 ); /* Q_exc */ #endif } } - interp_code_4over2_fx(tmp_code_preInt_fx, tmp_code_fx, L_subfr); /* o: tmp_code in Q_exc */ - FOR(i = 0; i < L_subfr * 2; i++) + interp_code_4over2_fx( tmp_code_preInt_fx, tmp_code_fx, L_subfr ); /* o: tmp_code in Q_exc */ + FOR( i = 0; i < L_subfr * 2; i++ ) { - L_tmp = L_mult(gain_pit_fx, bwe_exc_fx[i + i_subfr_fx * 2]); /*Q14+Q_exc+1 */ + L_tmp = L_mult( gain_pit_fx, bwe_exc_fx[i + i_subfr_fx * 2] ); /*Q14+Q_exc+1 */ #ifdef BASOP_NOGLOB - tmp = round_fx_o(L_shl_o(L_tmp, 1 /* (Q_exc+16)-(14+Q_exc+1)*/, &Overflow), &Overflow); /* tmp in Q_exc */ - bwe_exc_fx[i + i_subfr_fx * 2] = add_o(tmp, tmp_code_fx[i], &Overflow); /*Q_exc */ move16(); + tmp = round_fx_o( L_shl_o( L_tmp, 1 /* (Q_exc+16)-(14+Q_exc+1)*/, &Overflow ), &Overflow ); /* tmp in Q_exc */ + bwe_exc_fx[i + i_subfr_fx * 2] = add_o( tmp, tmp_code_fx[i], &Overflow ); /*Q_exc */ + move16(); #else /* BASOP_NOGLOB */ - tmp = round_fx(L_shl(L_tmp, 1 /* (Q_exc+16)-(14+Q_exc+1)*/)); /* tmp in Q_exc */ - bwe_exc_fx[i + i_subfr_fx * 2] = add(tmp, tmp_code_fx[i]); /*Q_exc */ move16(); + tmp = round_fx( L_shl( L_tmp, 1 /* (Q_exc+16)-(14+Q_exc+1)*/ ) ); /* tmp in Q_exc */ + bwe_exc_fx[i + i_subfr_fx * 2] = add( tmp, tmp_code_fx[i] ); /*Q_exc */ + move16(); #endif } } @@ -6115,9 +6140,9 @@ void prep_tbe_exc_ivas_fx( /* CALLED FROM : */ /*==============================================================================*/ -Word16 swb_formant_fac_fx( /* o : Formant filter strength [0,1] */ - const Word16 lpc_shb2, /* Q12 i : 2nd HB LPC coefficient */ - Word16* tilt_mem /* i/o: Tilt smoothing memory (Q12) */ +Word16 swb_formant_fac_fx( /* o : Formant filter strength [0,1] */ + const Word16 lpc_shb2, /* Q12 i : 2nd HB LPC coefficient */ + Word16 *tilt_mem /* i/o: Tilt smoothing memory (Q12) */ ) { Word16 formant_fac; @@ -6131,14 +6156,14 @@ Word16 swb_formant_fac_fx( /* o : Formant filter strength [0,1] */ tmp = mult_r( 16384, abs_s( lpc_shb2 ) ); tmp = add( tmp, mult_r( 16384, *tilt_mem ) ); /* Q12 */ *tilt_mem = tmp; - move16();/*Q12 */ + move16(); /*Q12 */ /* Map to PF strength */ /* formant_fac = (tmp - SWB_TILT_LOW)*SWB_TILT_DELTA; */ - tmp = sub( tmp, SWB_TILT_LOW_FX ); /* Q12 */ + tmp = sub( tmp, SWB_TILT_LOW_FX ); /* Q12 */ formant_fac = mult_r( tmp, SWB_TILT_DELTA_FX ); /* Q12 */ - IF ( GT_16( formant_fac, 4096 )) + IF( GT_16( formant_fac, 4096 ) ) { formant_fac = 4096; move16(); @@ -6151,11 +6176,11 @@ Word16 swb_formant_fac_fx( /* o : Formant filter strength [0,1] */ /* now formant_fac in Q12 */ /* formant_fac = 1.0f - 0.5f*formant_fac */ - tmp = mult_r(16384, formant_fac); /* 0.5 in Q12 */ + tmp = mult_r( 16384, formant_fac ); /* 0.5 in Q12 */ #ifdef BASOP_NOGLOB - formant_fac = shl_o(sub(4096,tmp),3, &Overflow); + formant_fac = shl_o( sub( 4096, tmp ), 3, &Overflow ); #else - formant_fac = shl(sub(4096,tmp),3); + formant_fac = shl( sub( 4096, tmp ), 3 ); #endif return formant_fac; /*Q15 */ } @@ -6165,39 +6190,39 @@ void wb_tbe_extras_reset_fx( Word16 mem_genSHBexc_filt_down_wb2[], Word16 mem_genSHBexc_filt_down_wb3[] ) { - set16_fx( mem_genSHBexc_filt_down_wb2, 0, 2*ALLPASSSECTIONS_STEEP+1 ); - set16_fx( mem_genSHBexc_filt_down_wb3, 0, 2*ALLPASSSECTIONS_STEEP+1 ); + set16_fx( mem_genSHBexc_filt_down_wb2, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); + set16_fx( mem_genSHBexc_filt_down_wb3, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); return; } /*-------------------------------------------------------------------* -* get_tbe_bits() * -* * -* Determine TBE bit consumption per frame from bitrate * -*-------------------------------------------------------------------*/ + * get_tbe_bits() * + * * + * Determine TBE bit consumption per frame from bitrate * + *-------------------------------------------------------------------*/ Word16 get_tbe_bits_fx( - const Word32 total_brate, /* o : TBE bit consumption per frame */ - const Word16 bwidth, /* i : overall bitrate */ - const Word16 rf_mode /* i : bandwidht mode */ + const Word32 total_brate, /* o : TBE bit consumption per frame */ + const Word16 bwidth, /* i : overall bitrate */ + const Word16 rf_mode /* i : bandwidht mode */ ) { Word16 i, bits = 0; - IF( EQ_16(rf_mode,1)) + IF( EQ_16( rf_mode, 1 ) ) { /* TBE bits for core, primary frame */ test(); test(); - IF( (EQ_16(bwidth, WB ))&&(EQ_32(total_brate,ACELP_13k20))) + IF( ( EQ_16( bwidth, WB ) ) && ( EQ_32( total_brate, ACELP_13k20 ) ) ) { /* Gain frame: 4, Gain shapes: 0, and LSFs: 2 */ bits = NUM_BITS_SHB_FrameGain_LBR_WB + NUM_BITS_LBR_WB_LSF; move16(); } - ELSE IF( (EQ_16(bwidth, SWB ))&&(EQ_32(total_brate,ACELP_13k20))) + ELSE IF( ( EQ_16( bwidth, SWB ) ) && ( EQ_32( total_brate, ACELP_13k20 ) ) ) { /* Gain frame: 5, Gain shapes: 5, and lowrate LSFs: 8 */ bits = NUM_BITS_SHB_FRAMEGAIN + NUM_BITS_SHB_SUBGAINS + 8; @@ -6208,43 +6233,43 @@ Word16 get_tbe_bits_fx( { test(); test(); - IF( (EQ_16(bwidth, WB ))&&(EQ_32(total_brate,ACELP_9k60))) + IF( ( EQ_16( bwidth, WB ) ) && ( EQ_32( total_brate, ACELP_9k60 ) ) ) { bits = NUM_BITS_LBR_WB_LSF + NUM_BITS_SHB_FrameGain_LBR_WB; move16(); } - ELSE IF( (EQ_16( bwidth, SWB ))||(EQ_16(bwidth,FB))) + ELSE IF( ( EQ_16( bwidth, SWB ) ) || ( EQ_16( bwidth, FB ) ) ) { test(); - IF( EQ_32(total_brate, ACELP_9k60)) + IF( EQ_32( total_brate, ACELP_9k60 ) ) { bits = NUM_BITS_SHB_FRAMEGAIN + NUM_BITS_SHB_SUBGAINS + 8; move16(); } - ELSE IF( (GE_32( total_brate, ACELP_13k20 ))&&(LE_32(total_brate,ACELP_32k))) + ELSE IF( ( GE_32( total_brate, ACELP_13k20 ) ) && ( LE_32( total_brate, ACELP_32k ) ) ) { - bits = NUM_BITS_SHB_SUBGAINS + NUM_BITS_SHB_FRAMEGAIN + NUM_LSF_GRID_BITS + MIRROR_POINT_BITS; + bits = NUM_BITS_SHB_SUBGAINS + NUM_BITS_SHB_FRAMEGAIN + NUM_LSF_GRID_BITS + MIRROR_POINT_BITS; move16(); - FOR ( i=0; i -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ /*===========================================================================*/ @@ -35,28 +35,28 @@ /*===========================================================================*/ void syn_12k8_fx( Word16 L_frame, - const Word16 *Aq, /* i : LP filter coefficients Q12 */ - const Word16 *exc, /* i : input signal Q_exc */ - Word16 *synth, /* o : output signal Q_syn */ - Word16 *mem, /* i/o: initial filter states Q_syn */ - const Word16 update_m, /* i : update memory flag: 0 --> no memory update Q0 */ + const Word16 *Aq, /* i : LP filter coefficients Q12 */ + const Word16 *exc, /* i : input signal Q_exc */ + Word16 *synth, /* o : output signal Q_syn */ + Word16 *mem, /* i/o: initial filter states Q_syn */ + const Word16 update_m, /* i : update memory flag: 0 --> no memory update Q0 */ /* 1 --> update of memory */ - const Word16 Q_exc, /* i : Excitation scaling Q0 */ - const Word16 Q_syn /* i : Synthesis scaling Q0 */ + const Word16 Q_exc, /* i : Excitation scaling Q0 */ + const Word16 Q_syn /* i : Synthesis scaling Q0 */ ) { const Word16 *p_Aq; Word16 i_subfr; Word16 shift; - shift = sub(Q_exc, Q_syn); + shift = sub( Q_exc, Q_syn ); p_Aq = Aq; move16(); - FOR (i_subfr = 0; i_subfr < L_frame; i_subfr += L_SUBFR) + FOR( i_subfr = 0; i_subfr < L_frame; i_subfr += L_SUBFR ) { - Syn_filt_s(shift, p_Aq, M, &exc[i_subfr], &synth[i_subfr], L_SUBFR, mem, update_m); - p_Aq += (M+1); - move16(); /* interpolated LPC parameters for next subframe */ + Syn_filt_s( shift, p_Aq, M, &exc[i_subfr], &synth[i_subfr], L_SUBFR, mem, update_m ); + p_Aq += ( M + 1 ); + move16(); /* interpolated LPC parameters for next subframe */ } return; } diff --git a/lib_com/syn_filt_fx.c b/lib_com/syn_filt_fx.c index a3bc741bd..5b7fcc4c3 100644 --- a/lib_com/syn_filt_fx.c +++ b/lib_com/syn_filt_fx.c @@ -3,104 +3,104 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ #include "prot_fx1.h" #include "prot_fx2.h" #include "stl.h" -static Word32 syn_kern_2(Word32 L_tmp, const Word16 a[], const Word16 y[]) +static Word32 syn_kern_2( Word32 L_tmp, const Word16 a[], const Word16 y[] ) { #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif #ifdef BASOP_NOGLOB - L_tmp = L_msu_o(L_tmp, y[-1], a[1], &Overflow); - return L_msu_o(L_tmp, y[-2], a[2], &Overflow); + L_tmp = L_msu_o( L_tmp, y[-1], a[1], &Overflow ); + return L_msu_o( L_tmp, y[-2], a[2], &Overflow ); #else - L_tmp = L_msu(L_tmp, y[-1], a[1]); - return L_msu(L_tmp, y[-2], a[2]); + L_tmp = L_msu( L_tmp, y[-1], a[1] ); + return L_msu( L_tmp, y[-2], a[2] ); #endif } -static Word32 syn_kern_4(Word32 L_tmp, const Word16 a[], const Word16 y[]) +static Word32 syn_kern_4( Word32 L_tmp, const Word16 a[], const Word16 y[] ) { - L_tmp = syn_kern_2(L_tmp, a, y); - return syn_kern_2(L_tmp, a+2, y-2); + L_tmp = syn_kern_2( L_tmp, a, y ); + return syn_kern_2( L_tmp, a + 2, y - 2 ); } -static Word32 syn_kern_6(Word32 L_tmp, const Word16 a[], const Word16 y[]) +static Word32 syn_kern_6( Word32 L_tmp, const Word16 a[], const Word16 y[] ) { - L_tmp = syn_kern_4(L_tmp, a, y); - return syn_kern_2(L_tmp, a+4, y-4); + L_tmp = syn_kern_4( L_tmp, a, y ); + return syn_kern_2( L_tmp, a + 4, y - 4 ); } -static Word32 syn_kern_8(Word32 L_tmp, const Word16 a[], const Word16 y[]) +static Word32 syn_kern_8( Word32 L_tmp, const Word16 a[], const Word16 y[] ) { - L_tmp = syn_kern_4(L_tmp, a, y); - return syn_kern_4(L_tmp, a+4, y-4); + L_tmp = syn_kern_4( L_tmp, a, y ); + return syn_kern_4( L_tmp, a + 4, y - 4 ); } -static Word32 syn_kern_10(Word32 L_tmp, const Word16 a[], const Word16 y[]) +static Word32 syn_kern_10( Word32 L_tmp, const Word16 a[], const Word16 y[] ) { - L_tmp = syn_kern_8(L_tmp, a, y); - return syn_kern_2(L_tmp, a+8, y-8); + L_tmp = syn_kern_8( L_tmp, a, y ); + return syn_kern_2( L_tmp, a + 8, y - 8 ); } -Word32 syn_kern_16(Word32 L_tmp, const Word16 a[], const Word16 y[]) +Word32 syn_kern_16( Word32 L_tmp, const Word16 a[], const Word16 y[] ) { - L_tmp = syn_kern_8(L_tmp, a, y); - return syn_kern_8(L_tmp, a+8, y-8); + L_tmp = syn_kern_8( L_tmp, a, y ); + return syn_kern_8( L_tmp, a + 8, y - 8 ); } -static Word32 syn_kern_24(Word32 L_tmp, const Word16 a[], const Word16 y[]) +static Word32 syn_kern_24( Word32 L_tmp, const Word16 a[], const Word16 y[] ) { - L_tmp = syn_kern_16(L_tmp, a, y); - return syn_kern_8(L_tmp, a+16, y-16); + L_tmp = syn_kern_16( L_tmp, a, y ); + return syn_kern_8( L_tmp, a + 16, y - 16 ); } -static Word32 syn_kern_2_fx(Word32 L_tmp, const Word32 a[], const Word32 y[]) +static Word32 syn_kern_2_fx( Word32 L_tmp, const Word32 a[], const Word32 y[] ) { - L_tmp = Msub_32_32_r(L_tmp, y[-1], a[1]); - return Msub_32_32_r(L_tmp, y[-2], a[2]); + L_tmp = Msub_32_32_r( L_tmp, y[-1], a[1] ); + return Msub_32_32_r( L_tmp, y[-2], a[2] ); } -static Word32 syn_kern_4_fx(Word32 L_tmp, const Word32 a[], const Word32 y[]) +static Word32 syn_kern_4_fx( Word32 L_tmp, const Word32 a[], const Word32 y[] ) { - L_tmp = syn_kern_2_fx(L_tmp, a, y); - return syn_kern_2_fx(L_tmp, a + 2, y - 2); + L_tmp = syn_kern_2_fx( L_tmp, a, y ); + return syn_kern_2_fx( L_tmp, a + 2, y - 2 ); } -static Word32 syn_kern_6_fx(Word32 L_tmp, const Word32 a[], const Word32 y[]) +static Word32 syn_kern_6_fx( Word32 L_tmp, const Word32 a[], const Word32 y[] ) { - L_tmp = syn_kern_4_fx(L_tmp, a, y); - return syn_kern_2_fx(L_tmp, a + 4, y - 4); + L_tmp = syn_kern_4_fx( L_tmp, a, y ); + return syn_kern_2_fx( L_tmp, a + 4, y - 4 ); } -static Word32 syn_kern_8_fx(Word32 L_tmp, const Word32 a[], const Word32 y[]) +static Word32 syn_kern_8_fx( Word32 L_tmp, const Word32 a[], const Word32 y[] ) { - L_tmp = syn_kern_4_fx(L_tmp, a, y); - return syn_kern_4_fx(L_tmp, a + 4, y - 4); + L_tmp = syn_kern_4_fx( L_tmp, a, y ); + return syn_kern_4_fx( L_tmp, a + 4, y - 4 ); } -static Word32 syn_kern_10_fx(Word32 L_tmp, const Word32 a[], const Word32 y[]) +static Word32 syn_kern_10_fx( Word32 L_tmp, const Word32 a[], const Word32 y[] ) { - L_tmp = syn_kern_8_fx(L_tmp, a, y); - return syn_kern_2_fx(L_tmp, a + 8, y - 8); + L_tmp = syn_kern_8_fx( L_tmp, a, y ); + return syn_kern_2_fx( L_tmp, a + 8, y - 8 ); } -static Word32 syn_kern_16_fx(Word32 L_tmp, const Word32 a[], const Word32 y[]) +static Word32 syn_kern_16_fx( Word32 L_tmp, const Word32 a[], const Word32 y[] ) { - L_tmp = syn_kern_8_fx(L_tmp, a, y); - return syn_kern_8_fx(L_tmp, a + 8, y - 8); + L_tmp = syn_kern_8_fx( L_tmp, a, y ); + return syn_kern_8_fx( L_tmp, a + 8, y - 8 ); } -static Word32 syn_kern_24_fx(Word32 L_tmp, const Word32 a[], const Word32 y[]) +static Word32 syn_kern_24_fx( Word32 L_tmp, const Word32 a[], const Word32 y[] ) { - L_tmp = syn_kern_16_fx(L_tmp, a, y); - return syn_kern_8_fx(L_tmp, a + 16, y - 16); + L_tmp = syn_kern_16_fx( L_tmp, a, y ); + return syn_kern_8_fx( L_tmp, a + 16, y - 16 ); } @@ -111,11 +111,11 @@ static Word32 syn_kern_24_fx(Word32 L_tmp, const Word32 a[], const Word32 y[]) * Optimized Version when No Memory, Past is Set to 0 *------------------------------------------------------------------*/ void syn_filt_s_lc_fx( - const Word16 shift, /* i : scaling to apply Q0 */ - const Word16 a[], /* i : LP filter coefficients Q12 */ - const Word16 x[], /* i : input signal Qx */ - Word16 y[], /* o : output signal Qx-s */ - const Word16 lg /* i : size of filtering Q0 */ + const Word16 shift, /* i : scaling to apply Q0 */ + const Word16 a[], /* i : LP filter coefficients Q12 */ + const Word16 x[], /* i : input signal Qx */ + Word16 y[], /* o : output signal Qx-s */ + const Word16 lg /* i : size of filtering Q0 */ ) { Word16 i, j; @@ -124,22 +124,22 @@ void syn_filt_s_lc_fx( Word16 q; - q = add( norm_s(a[0]), 1 ); - a0 = shr(a[0], shift); /* input / 2^shift */ + q = add( norm_s( a[0] ), 1 ); + a0 = shr( a[0], shift ); /* input / 2^shift */ /*-----------------------------------------------------------------------* * Do the filtering *-----------------------------------------------------------------------*/ - FOR (i = 0; i < M; i++) + FOR( i = 0; i < M; i++ ) { - L_tmp = L_mult(*x++, a0); + L_tmp = L_mult( *x++, a0 ); /* Stop at i to Avoid Mults with Zeros */ - FOR (j = 1; j <= i; j++) + FOR( j = 1; j <= i; j++ ) { #ifdef BASOP_NOGLOB L_tmp = L_msu_sat( L_tmp, y[-j], a[j] ); #else - L_tmp = L_msu(L_tmp, y[-j], a[j]); + L_tmp = L_msu( L_tmp, y[-j], a[j] ); #endif } @@ -152,15 +152,15 @@ void syn_filt_s_lc_fx( #endif } - FOR (; i < lg; i++) + FOR( ; i < lg; i++ ) { - L_tmp = syn_kern_16(L_mult(*x++, a0), a, y); + L_tmp = syn_kern_16( L_mult( *x++, a0 ), a, y ); #ifdef BASOP_NOGLOB L_tmp = L_shl_sat( L_tmp, q ); - *y++ = round_fx_sat(L_tmp); + *y++ = round_fx_sat( L_tmp ); #else L_tmp = L_shl( L_tmp, q ); - *y++ = round_fx(L_tmp); + *y++ = round_fx( L_tmp ); #endif } } @@ -171,17 +171,17 @@ void syn_filt_s_lc_fx( * perform the synthesis filtering 1/A(z). *------------------------------------------------------------------*/ void Syn_filt_s( - const Word16 shift, /* i : scaling to apply Q0 */ - const Word16 a[], /* i : LP filter coefficients Q12 */ - const Word16 m, /* i : order of LP filter Q0 */ - const Word16 x[], /* i : input signal Qx */ - Word16 y[], /* o : output signal Qx-s */ - const Word16 lg, /* i : size of filtering Q0 */ - Word16 mem[], /* i/o: memory associated with this filtering. Qx-s */ - const Word16 update /* i : 0=no update, 1=update of memory. Q0 */ + const Word16 shift, /* i : scaling to apply Q0 */ + const Word16 a[], /* i : LP filter coefficients Q12 */ + const Word16 m, /* i : order of LP filter Q0 */ + const Word16 x[], /* i : input signal Qx */ + Word16 y[], /* o : output signal Qx-s */ + const Word16 lg, /* i : size of filtering Q0 */ + Word16 mem[], /* i/o: memory associated with this filtering. Qx-s */ + const Word16 update /* i : 0=no update, 1=update of memory. Q0 */ ) { - E_UTIL_synthesis(shift, a, x, y, lg, mem, update, m); + E_UTIL_synthesis( shift, a, x, y, lg, mem, update, m ); } @@ -205,77 +205,74 @@ void Syn_filt_s( * Returns: * void */ -void E_UTIL_synthesis(const Word16 shift, const Word16 a[], const Word16 x[], Word16 y[], - const Word16 lg, Word16 mem[], const Word16 update, const Word16 m - ) +void E_UTIL_synthesis( const Word16 shift, const Word16 a[], const Word16 x[], Word16 y[], const Word16 lg, Word16 mem[], const Word16 update, const Word16 m ) { Word16 i, j, a0; Word32 L_tmp; Word16 q; - Word32 (*syn_kern)(Word32 L_tmp, const Word16 a[], const Word16 y[]) = NULL; + Word32 ( *syn_kern )( Word32 L_tmp, const Word16 a[], const Word16 y[] ) = NULL; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - if (EQ_16(m, 6)) + if ( EQ_16( m, 6 ) ) { syn_kern = syn_kern_6; } - if (EQ_16(m, 10)) + if ( EQ_16( m, 10 ) ) { syn_kern = syn_kern_10; } - if (EQ_16(m, 16)) + if ( EQ_16( m, 16 ) ) { syn_kern = syn_kern_16; } - if (EQ_16(m, 24)) + if ( EQ_16( m, 24 ) ) { syn_kern = syn_kern_24; } - assert(syn_kern != NULL); - q = add( norm_s(a[0]), 1 ); - + assert( syn_kern != NULL ); + q = add( norm_s( a[0] ), 1 ); /*-----------------------------------------------------------------------* * Set Memory Pointer at End for Backward Access *-----------------------------------------------------------------------*/ - mem += m; /*move16();*/ + mem += m; /*move16();*/ #ifdef BASOP_NOGLOB - a0 = shr_o(a[0], shift, &Overflow); /* input / 2^shift */ + a0 = shr_o( a[0], shift, &Overflow ); /* input / 2^shift */ #else - a0 = shr(a[0], shift); /* input / 2^shift */ + a0 = shr( a[0], shift ); /* input / 2^shift */ #endif /*-----------------------------------------------------------------------* * Do the filtering *-----------------------------------------------------------------------*/ /* Filtering Only from Input + Memory */ - L_tmp = syn_kern(L_mult(a0, *x++), a, mem); + L_tmp = syn_kern( L_mult( a0, *x++ ), a, mem ); #ifdef BASOP_NOGLOB - L_tmp = L_shl_o(L_tmp, q, &Overflow); - *y++ = round_fx_o(L_tmp, &Overflow); + L_tmp = L_shl_o( L_tmp, q, &Overflow ); + *y++ = round_fx_o( L_tmp, &Overflow ); #else - L_tmp = L_shl(L_tmp, q); - *y++ = round_fx(L_tmp); + L_tmp = L_shl( L_tmp, q ); + *y++ = round_fx( L_tmp ); #endif /* Filtering from Input + Mix of Memory & Output Signal Past */ - FOR (i = 1; i < m; i++) + FOR( i = 1; i < m; i++ ) { - L_tmp = L_mult(a0, *x++); + L_tmp = L_mult( a0, *x++ ); /* Process Output Signal Past */ - FOR (j = 1; j <= i; j++) + FOR( j = 1; j <= i; j++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_msu_o(L_tmp, a[j], y[-j], &Overflow); + L_tmp = L_msu_o( L_tmp, a[j], y[-j], &Overflow ); #else - L_tmp = L_msu(L_tmp, a[j], y[-j]); + L_tmp = L_msu( L_tmp, a[j], y[-j] ); #endif } /* Process Memory */ - FOR (; j <= m; j++) + FOR( ; j <= m; j++ ) { #ifdef BASOP_NOGLOB L_tmp = L_msu_sat( L_tmp, a[j], mem[i - j] ); @@ -284,33 +281,33 @@ void E_UTIL_synthesis(const Word16 shift, const Word16 a[], const Word16 x[], Wo #endif } #ifdef BASOP_NOGLOB - L_tmp = L_shl_o(L_tmp, q, &Overflow); - *y++ = round_fx_o(L_tmp, &Overflow); + L_tmp = L_shl_o( L_tmp, q, &Overflow ); + *y++ = round_fx_o( L_tmp, &Overflow ); #else - L_tmp = L_shl(L_tmp, q); - *y++ = round_fx(L_tmp); + L_tmp = L_shl( L_tmp, q ); + *y++ = round_fx( L_tmp ); #endif } /* Filtering from Input + Output Signal Past */ - FOR (; i < lg; i++) + FOR( ; i < lg; i++ ) { - L_tmp = syn_kern(L_mult(a0, *x++), a, y); + L_tmp = syn_kern( L_mult( a0, *x++ ), a, y ); #ifdef BASOP_NOGLOB - L_tmp = L_shl_o(L_tmp, q, &Overflow); - *y++ = round_fx_o(L_tmp, &Overflow); + L_tmp = L_shl_o( L_tmp, q, &Overflow ); + *y++ = round_fx_o( L_tmp, &Overflow ); #else /* BASOP_NOGLOB */ - L_tmp = L_shl(L_tmp, q); - *y++ = round_fx(L_tmp); + L_tmp = L_shl( L_tmp, q ); + *y++ = round_fx( L_tmp ); #endif } /*-----------------------------------------------------------------------* * Update memory if required *-----------------------------------------------------------------------*/ - IF (update != 0) + IF( update != 0 ) { - FOR (i = 0; i < m; i++) + FOR( i = 0; i < m; i++ ) { *--mem = *--y; move16(); @@ -321,92 +318,89 @@ void E_UTIL_synthesis(const Word16 shift, const Word16 a[], const Word16 x[], Wo } -void E_UTIL_synthesis_fx(const Word16 shift, const Word32 a[], const Word32 x[], Word32 y[], - const Word16 lg, Word32 mem[], const Word16 update, const Word16 m -) +void E_UTIL_synthesis_fx( const Word16 shift, const Word32 a[], const Word32 x[], Word32 y[], const Word16 lg, Word32 mem[], const Word16 update, const Word16 m ) { - Word16 i, j; - Word32 a0; - Word32 L_tmp; - Word16 q; - Word32(*syn_kern)(Word32 L_tmp, const Word32 a[], const Word32 y[]) = NULL; - Flag Overflow = 0; - - if (EQ_16(m, 6)) - { - syn_kern = syn_kern_6_fx; - } - if (EQ_16(m, 10)) - { - syn_kern = syn_kern_10_fx; - } - if (EQ_16(m, 16)) - { - syn_kern = syn_kern_16_fx; - } - if (EQ_16(m, 24)) - { - syn_kern = syn_kern_24_fx; - } - assert(syn_kern != NULL); - q = add(norm_l(a[0]), 1); - - - - /*-----------------------------------------------------------------------* - * Set Memory Pointer at End for Backward Access - *-----------------------------------------------------------------------*/ - mem += m; /*move32();*/ - - a0 = L_shr_o(a[0], shift, &Overflow); /* input / 2^shift */ + Word16 i, j; + Word32 a0; + Word32 L_tmp; + Word16 q; + Word32 ( *syn_kern )( Word32 L_tmp, const Word32 a[], const Word32 y[] ) = NULL; + Flag Overflow = 0; + + if ( EQ_16( m, 6 ) ) + { + syn_kern = syn_kern_6_fx; + } + if ( EQ_16( m, 10 ) ) + { + syn_kern = syn_kern_10_fx; + } + if ( EQ_16( m, 16 ) ) + { + syn_kern = syn_kern_16_fx; + } + if ( EQ_16( m, 24 ) ) + { + syn_kern = syn_kern_24_fx; + } + assert( syn_kern != NULL ); + q = add( norm_l( a[0] ), 1 ); + + + /*-----------------------------------------------------------------------* + * Set Memory Pointer at End for Backward Access + *-----------------------------------------------------------------------*/ + mem += m; /*move32();*/ + + a0 = L_shr_o( a[0], shift, &Overflow ); /* input / 2^shift */ /*-----------------------------------------------------------------------* * Do the filtering *-----------------------------------------------------------------------*/ - /* Filtering Only from Input + Memory */ - L_tmp = syn_kern(Mpy_32_32(a0, *x++), a, mem); - L_tmp = L_shl_o(L_tmp, q, &Overflow); - *y++ = L_tmp; - - /* Filtering from Input + Mix of Memory & Output Signal Past */ - FOR(i = 1; i < m; i++) - { - L_tmp = Mpy_32_32(a0, *x++); - /* Process Output Signal Past */ - FOR(j = 1; j <= i; j++) + /* Filtering Only from Input + Memory */ + L_tmp = syn_kern( Mpy_32_32( a0, *x++ ), a, mem ); + L_tmp = L_shl_o( L_tmp, q, &Overflow ); + *y++ = L_tmp; + + /* Filtering from Input + Mix of Memory & Output Signal Past */ + FOR( i = 1; i < m; i++ ) { - L_tmp = Msub_32_32_r(L_tmp, a[j], y[-j]); + L_tmp = Mpy_32_32( a0, *x++ ); + /* Process Output Signal Past */ + FOR( j = 1; j <= i; j++ ) + { + L_tmp = Msub_32_32_r( L_tmp, a[j], y[-j] ); + } + /* Process Memory */ + FOR( ; j <= m; j++ ) + { + L_tmp = Msub_32_32_r( L_tmp, a[j], mem[i - j] ); + } + L_tmp = L_shl_o( L_tmp, q, &Overflow ); + *y++ = L_tmp; } - /* Process Memory */ - FOR(; j <= m; j++) + + /* Filtering from Input + Output Signal Past */ + FOR( ; i < lg; i++ ) { - L_tmp = Msub_32_32_r(L_tmp, a[j], mem[i - j]); + L_tmp = syn_kern( Mpy_32_32( a0, *x++ ), a, y ); + L_tmp = L_shl_o( L_tmp, q, &Overflow ); + *y++ = L_tmp; } - L_tmp = L_shl_o(L_tmp, q, &Overflow); - *y++ = L_tmp; - } - /* Filtering from Input + Output Signal Past */ - FOR(; i < lg; i++) - { - L_tmp = syn_kern(Mpy_32_32(a0, *x++), a, y); - L_tmp = L_shl_o(L_tmp, q, &Overflow); - *y++ = L_tmp; - } - - /*-----------------------------------------------------------------------* - * Update memory if required - *-----------------------------------------------------------------------*/ - IF(update != 0) - { - FOR(i = 0; i < m; i++) + /*-----------------------------------------------------------------------* + * Update memory if required + *-----------------------------------------------------------------------*/ + IF( update != 0 ) { - *--mem = *--y; - move32(); + FOR( i = 0; i < m; i++ ) + { + *--mem = *--y; + move32(); + } } - } - return; + return; } @@ -451,7 +445,7 @@ void ivas_synth_mem_updt2_fx( en2 = L_shr( sum2_f_16_fx( mem_syn_r + L_SYN_MEM - M, M ), 1 ); /* 2 * Q - 1 */ // loc_rat = sqrtf( en2 ) / ( sqrtf( en1 ) + 0.01f ); - IF( EQ_32(en1, 0 )) + IF( EQ_32( en1, 0 ) ) { loc_rat = 0; move16(); @@ -464,7 +458,7 @@ void ivas_synth_mem_updt2_fx( tmp2 = Sqrt32( en2, &en2_e ); tmp = BASOP_Util_Divide3232_Scale( tmp1, tmp2, &tmp_e ); loc_rat_e = en1_e - en2_e + tmp_e; - loc_rat = shl_sat( tmp, loc_rat_e); // Q15 + loc_rat = shl_sat( tmp, loc_rat_e ); // Q15 } /* scale synthesis filter memory */ @@ -492,39 +486,39 @@ void ivas_synth_mem_updt2_fx( } #endif void synth_mem_updt2( - const Word16 L_frame, /* i : frame length */ - const Word16 last_L_frame, /* i : frame length */ - Word16 old_exc[], /* i/o: excitation buffer */ - Word16 mem_syn_r[], /* i/o: synthesis filter memory */ - Word16 mem_syn2[], /* o : synthesis filter memory for find_target */ - Word16 mem_syn[], /* o : synthesis filter memory for find_target */ - const Word16 dec /* i : flag for decoder indication */ + const Word16 L_frame, /* i : frame length */ + const Word16 last_L_frame, /* i : frame length */ + Word16 old_exc[], /* i/o: excitation buffer */ + Word16 mem_syn_r[], /* i/o: synthesis filter memory */ + Word16 mem_syn2[], /* o : synthesis filter memory for find_target */ + Word16 mem_syn[], /* o : synthesis filter memory for find_target */ + const Word16 dec /* i : flag for decoder indication */ ) { Word16 mem_syn_r_size_old, mem_syn_r_size_new; /* Residual and update old_exc */ - IF( GE_16(dec, DEC)) + IF( GE_16( dec, DEC ) ) { - lerp( old_exc+L_EXC_MEM_DEC-(last_L_frame+last_L_frame/2), old_exc+L_EXC_MEM_DEC-(L_frame+L_frame/2), L_frame+L_frame/2, last_L_frame+last_L_frame/2 ); + lerp( old_exc + L_EXC_MEM_DEC - ( last_L_frame + last_L_frame / 2 ), old_exc + L_EXC_MEM_DEC - ( L_frame + L_frame / 2 ), L_frame + L_frame / 2, last_L_frame + last_L_frame / 2 ); } ELSE { - lerp( old_exc+L_EXC_MEM-last_L_frame, old_exc+L_EXC_MEM-L_frame, L_frame, last_L_frame ); + lerp( old_exc + L_EXC_MEM - last_L_frame, old_exc + L_EXC_MEM - L_frame, L_frame, last_L_frame ); } #ifdef ADD_LRTD - IF (EQ_16(dec, DEC_IVAS) ) + IF( EQ_16( dec, DEC_IVAS ) ) { - IF (EQ_16(L_frame, L_FRAME16k)) + IF( EQ_16( L_frame, L_FRAME16k ) ) { /* find scaling factor */ PME() - en1 = 1.25f * sum2_f(mem_syn2, M); - en2 = sum2_f(mem_syn_r + L_SYN_MEM - M, M); + en1 = 1.25f * sum2_f( mem_syn2, M ); + en2 = sum2_f( mem_syn_r + L_SYN_MEM - M, M ); - loc_rat = sqrtf(en2) / (sqrtf(en1) + 0.01f); + loc_rat = sqrtf( en2 ) / ( sqrtf( en1 ) + 0.01f ); /* scale synthesis filter memory */ - FOR (i = 0; i < M; i++) + FOR( i = 0; i < M; i++ ) { mem_syn_r[L_SYN_MEM - M + i] *= loc_rat; } @@ -534,18 +528,15 @@ void synth_mem_updt2( /*Resamp memory*/ /*Size of LPC syn memory*/ /* 1.25/20.0 = 1.0/16.0 -> shift 4 to the right. */ - mem_syn_r_size_old = shr(last_L_frame, 4); - mem_syn_r_size_new = shr(L_frame, 4); + mem_syn_r_size_old = shr( last_L_frame, 4 ); + mem_syn_r_size_new = shr( L_frame, 4 ); lerp( mem_syn_r + L_SYN_MEM - mem_syn_r_size_old, mem_syn_r + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); - Copy( mem_syn_r+L_SYN_MEM-M, mem_syn2, M ); + Copy( mem_syn_r + L_SYN_MEM - M, mem_syn2, M ); IF( mem_syn != NULL ) { Copy( mem_syn2, mem_syn, M ); } - } - - diff --git a/lib_com/tcq_position_arith.c b/lib_com/tcq_position_arith.c index 82c7785cc..4c9764fac 100644 --- a/lib_com/tcq_position_arith.c +++ b/lib_com/tcq_position_arith.c @@ -246,7 +246,7 @@ static Word32 GetBitsFromPulses_fx( temp32 = L_shl( L_sub( mantissa_fx, L_deposit_h( temp_fx1 ) ), 15 ); /*31 */ exp1 = sub( norm_l( temp32 ), 1 ); temp32 = ar_div_ivas( L_shl( temp32, exp1 ), temp_fx1 ); /*31 + exp1 */ - temp32 = L_shr( temp32, exp1 + 1 ); /*30 */ + temp32 = L_shr( temp32, exp1 + 1 ); /*30 */ frac_fx32 = L_sub( 0x40000000, L_shr( temp32, 1 ) ); /*30 */ frac_fx32 = Mult_32_32( frac_fx32, temp32 ); /*29 */ diff --git a/lib_com/tcq_position_arith_fx.c b/lib_com/tcq_position_arith_fx.c index 49decdd6d..12ed38196 100644 --- a/lib_com/tcq_position_arith_fx.c +++ b/lib_com/tcq_position_arith_fx.c @@ -3,73 +3,71 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ +#include "options.h" /* Compilation switches */ #include "stl.h" #include "rom_com.h" #include "prot_fx1.h" #include "prot_fx2.h" -Word32 ar_div( - Word32 num, - Word32 denum -) +Word32 ar_div( + Word32 num, + Word32 denum ) { Word16 exp1, exp2, exp, i; Word32 varout; Word32 sign; - sign = L_and(L_xor(num, denum), 0x80000000); + sign = L_and( L_xor( num, denum ), 0x80000000 ); - num = L_abs(num); - denum = L_abs(denum); + num = L_abs( num ); + denum = L_abs( denum ); test(); - IF (LT_32(num, denum)||denum==0) + IF( LT_32( num, denum ) || denum == 0 ) { return 0; } - ELSE IF (EQ_32(num, denum)) + ELSE IF( EQ_32( num, denum ) ) { return 1; } ELSE { - exp1 = norm_l(num); - exp2 = norm_l(denum); - exp = sub(exp2, exp1); - denum = L_shl(denum, exp); - exp = add(exp, 1); - varout = L_deposit_l(0); - FOR (i = 0; i < exp; i++) + exp1 = norm_l( num ); + exp2 = norm_l( denum ); + exp = sub( exp2, exp1 ); + denum = L_shl( denum, exp ); + exp = add( exp, 1 ); + varout = L_deposit_l( 0 ); + FOR( i = 0; i < exp; i++ ) { - num = L_sub(num, denum); - varout = L_shl(varout, 1); - IF (num >= 0) + num = L_sub( num, denum ); + varout = L_shl( varout, 1 ); + IF( num >= 0 ) { - num = L_shl(num, 1); - varout = L_add(varout, 1); + num = L_shl( num, 1 ); + varout = L_add( varout, 1 ); } ELSE { - num = L_add(num, denum); - num = L_shl(num, 1); + num = L_add( num, denum ); + num = L_shl( num, 1 ); } } } - if(sign != 0) + if ( sign != 0 ) { - varout = L_negate(varout); + varout = L_negate( varout ); } return varout; } static void bitstream_save_bit( - TCQ_PBITSTREAM pBS, - Word32 bit -) + TCQ_PBITSTREAM pBS, + Word32 bit ) { UWord8 cur; @@ -77,46 +75,45 @@ static void bitstream_save_bit( move16(); - cur = (UWord8)(cur | L_shl(bit,pBS->curPos)); + cur = (UWord8) ( cur | L_shl( bit, pBS->curPos ) ); move16(); - pBS->curPos = sub(pBS->curPos,1); + pBS->curPos = sub( pBS->curPos, 1 ); pBS->buf[pBS->numByte] = cur; move16(); - pBS->numbits = L_add(pBS->numbits, 1); + pBS->numbits = L_add( pBS->numbits, 1 ); - IF (pBS->curPos < 0) + IF( pBS->curPos < 0 ) { pBS->curPos = 7; move16(); - pBS->numByte = L_add(pBS->numByte, 1); + pBS->numByte = L_add( pBS->numByte, 1 ); } return; } static UWord32 bitstream_load_bit( - TCQ_PBITSTREAM pBS -) + TCQ_PBITSTREAM pBS ) { UWord32 bit; Word16 *curPos; /* safety check in case of bit errors */ - IF( GE_32(pBS->numByte, pBS->maxBytes)) + IF( GE_32( pBS->numByte, pBS->maxBytes ) ) { return 0; } curPos = &pBS->curPos; move16(); - bit = (( pBS->buf[pBS->numByte] >> (*curPos)--) & 0x00000001); + bit = ( ( pBS->buf[pBS->numByte] >> ( *curPos )-- ) & 0x00000001 ); move16(); move16(); move16(); - IF (*curPos < 0) + IF( *curPos < 0 ) { - pBS->numByte = L_add(pBS->numByte, 1); + pBS->numByte = L_add( pBS->numByte, 1 ); *curPos = 7; move16(); } @@ -125,48 +122,46 @@ static UWord32 bitstream_load_bit( } static void bitstream_rollback( - TCQ_PBITSTREAM pBS, - Word32 numBits -) + TCQ_PBITSTREAM pBS, + Word32 numBits ) { - FOR ( ; numBits > 0; numBits--) + FOR( ; numBits > 0; numBits-- ) { pBS->curPos++; move16(); - pBS->numbits = L_sub(pBS->numbits, 1); - IF (EQ_16(pBS->curPos, 8)) + pBS->numbits = L_sub( pBS->numbits, 1 ); + IF( EQ_16( pBS->curPos, 8 ) ) { pBS->curPos = 0; move16(); - pBS->numByte = L_sub(pBS->numByte, 1); + pBS->numByte = L_sub( pBS->numByte, 1 ); } } return; } -static void transmission_bits( - PARCODEC arInst, - Word32 bit -) +static void transmission_bits( + PARCODEC arInst, + Word32 bit ) { bitstream_save_bit( arInst->bsInst, bit ); - arInst->num_bits = L_add(arInst->num_bits, 1); + arInst->num_bits = L_add( arInst->num_bits, 1 ); bit = !bit; move32(); - FOR ( ; arInst->bits_to_follow > 0 && arInst->num_bits < arInst->max_bits; arInst->bits_to_follow --) + FOR( ; arInst->bits_to_follow > 0 && arInst->num_bits < arInst->max_bits; arInst->bits_to_follow-- ) { bitstream_save_bit( arInst->bsInst, bit ); - arInst->num_bits = L_add(arInst->num_bits, 1); + arInst->num_bits = L_add( arInst->num_bits, 1 ); } return; } -static Word32 ar_make_model_fx( - const Word16 *freq, - Word16 *model, +static Word32 ar_make_model_fx( + const Word16 *freq, + Word16 *model, const Word16 len ) { Word16 dist; @@ -174,112 +169,111 @@ static Word32 ar_make_model_fx( Word32 cum = 0; Word16 i, tmp; - FOR ( i = 0 ; i < len ; i ++ ) + FOR( i = 0; i < len; i++ ) { - sum = L_add(sum, freq[i]); + sum = L_add( sum, freq[i] ); } - IF ( sum == 0 ) + IF( sum == 0 ) { return 0; } - FOR ( i = len ; i >= 0; i -- ) + FOR( i = len; i >= 0; i-- ) { /*model[i] = (short)( ( cum * MAX_AR_FREQ ) / sum ); */ - model[i] = extract_l(ar_div(cum * MAX_AR_FREQ, sum)); + model[i] = extract_l( ar_div( cum * MAX_AR_FREQ, sum ) ); - if (i) cum = L_add(cum, freq[i - 1]); + if ( i ) + cum = L_add( cum, freq[i - 1] ); } - tmp = sub(len, 1); - FOR ( i = 0 ; i < tmp ; i ++ ) + tmp = sub( len, 1 ); + FOR( i = 0; i < tmp; i++ ) { - dist = sub(model[i], model[i + 1]); + dist = sub( model[i], model[i + 1] ); - IF ( dist <= 0 ) + IF( dist <= 0 ) { - model[i + 1] = add(model[i + 1], sub(dist, 1)); + model[i + 1] = add( model[i + 1], sub( dist, 1 ) ); move16(); } } - FOR ( i = len ; i > 0 ; i -- ) + FOR( i = len; i > 0; i-- ) { - dist = sub(model[i - 1], model[i]); + dist = sub( model[i - 1], model[i] ); - IF ( dist <= 0 ) + IF( dist <= 0 ) { - model[i - 1] = sub(model[i - 1], sub(dist, 1)); + model[i - 1] = sub( model[i - 1], sub( dist, 1 ) ); move16(); } } - return (model[0] > model[1]); + return ( model[0] > model[1] ); } -void ar_encoder_start_fx( - PARCODEC arInst, - TCQ_PBITSTREAM bsInst, - const Word32 max_bits -) +void ar_encoder_start_fx( + PARCODEC arInst, + TCQ_PBITSTREAM bsInst, + const Word32 max_bits ) { arInst->bsInst = bsInst; move32(); - arInst->low = L_deposit_l(0); + arInst->low = L_deposit_l( 0 ); arInst->high = AR_TOP; move32(); - arInst->bits_to_follow = 0; + arInst->bits_to_follow = 0; move16(); - arInst->num_bits = L_deposit_l(0); + arInst->num_bits = L_deposit_l( 0 ); arInst->max_bits = max_bits; move32(); } -static void ar_encode_fx( - PARCODEC arInst, +static void ar_encode_fx( + PARCODEC arInst, const Word16 *model, - Word32 symbol -) + Word32 symbol ) { Word32 range, high, low; - high = L_add(arInst->high, 0); - low = L_add(arInst->low, 0); + high = L_add( arInst->high, 0 ); + low = L_add( arInst->low, 0 ); - symbol = L_add(symbol, 1); - range = L_add(L_sub(high, low), 1); + symbol = L_add( symbol, 1 ); + range = L_add( L_sub( high, low ), 1 ); - high = L_sub(L_add(low, ar_div(range * model[symbol - 1], model[0])), 1); - low = L_add(low, ar_div(range * model[symbol], model[0])); + high = L_sub( L_add( low, ar_div( range * model[symbol - 1], model[0] ) ), 1 ); + low = L_add( low, ar_div( range * model[symbol], model[0] ) ); - FOR( ; ; ) + FOR( ;; ) { - IF ( LT_32(high, AR_HALF)) + IF( LT_32( high, AR_HALF ) ) { transmission_bits( arInst, 0 ); } ELSE { - IF (GE_32(low, AR_HALF)) + IF( GE_32( low, AR_HALF ) ) { transmission_bits( arInst, 1 ); - low = L_sub(low, AR_HALF); - high = L_sub(high, AR_HALF); + low = L_sub( low, AR_HALF ); + high = L_sub( high, AR_HALF ); } ELSE { test(); - IF (GE_32(low, AR_FIRST)&<_32(high,AR_THIRD)) + IF( GE_32( low, AR_FIRST ) && LT_32( high, AR_THIRD ) ) { - arInst->bits_to_follow ++; + arInst->bits_to_follow++; move16(); - low = L_sub(low, AR_FIRST); - high = L_sub(high, AR_FIRST); + low = L_sub( low, AR_FIRST ); + high = L_sub( high, AR_FIRST ); } ELSE { @@ -288,8 +282,8 @@ static void ar_encode_fx( } } - low = L_shl(low, 1); - high = L_add(L_shl(high, 1 ), 1); + low = L_shl( low, 1 ); + high = L_add( L_shl( high, 1 ), 1 ); } arInst->high = high; @@ -300,103 +294,99 @@ static void ar_encode_fx( return; } -static void ar_encode_uniform_fx( - PARCODEC arInst, - UWord32 data, - const Word32 bits -) +static void ar_encode_uniform_fx( + PARCODEC arInst, + UWord32 data, + const Word32 bits ) { Word32 i; - FOR ( i = 0 ; i < bits ; i ++ ) + FOR( i = 0; i < bits; i++ ) { ar_encode_fx( arInst, uniform_model, data & 0x1 ); - data = L_lshr(data, 1); + data = L_lshr( data, 1 ); } return; } -void ar_encoder_done_fx( - PARCODEC arInst -) +void ar_encoder_done_fx( + PARCODEC arInst ) { - arInst->bits_to_follow ++; + arInst->bits_to_follow++; move16(); transmission_bits( arInst, arInst->low >= AR_FIRST ); return; } -void ar_decoder_start_fx( - PARCODEC arInst, - TCQ_PBITSTREAM bsInst -) +void ar_decoder_start_fx( + PARCODEC arInst, + TCQ_PBITSTREAM bsInst ) { Word16 i; - arInst->bsInst = bsInst; + arInst->bsInst = bsInst; move32(); - arInst->low = L_deposit_l(0); - arInst->high = AR_TOP; + arInst->low = L_deposit_l( 0 ); + arInst->high = AR_TOP; move32(); - arInst->value = L_deposit_l(0); + arInst->value = L_deposit_l( 0 ); - FOR ( i = 0; i < AR_BITS ; i ++ ) + FOR( i = 0; i < AR_BITS; i++ ) { - arInst->value = L_add(L_shl( arInst->value, 1), bitstream_load_bit( arInst->bsInst )); + arInst->value = L_add( L_shl( arInst->value, 1 ), bitstream_load_bit( arInst->bsInst ) ); } return; } -static Word16 ar_decode_fx( - PARCODEC arInst, - const Word16 *model -) +static Word16 ar_decode_fx( + PARCODEC arInst, + const Word16 *model ) { Word32 range, high, low, value, i; Word16 cum; Word16 symbol; - high = L_add(arInst->high, 0); - low = L_add(arInst->low, 0); - value = L_add(arInst->value, 0); + high = L_add( arInst->high, 0 ); + low = L_add( arInst->low, 0 ); + value = L_add( arInst->value, 0 ); - range = L_add(L_sub( high, low ), 1); + range = L_add( L_sub( high, low ), 1 ); /*cum = (short)( ( ( (unsigned int)( arInst->value - arInst->low ) + 1 ) * model[0] - 1 ) / range ); */ - cum = extract_l(ar_div(L_sub(L_add(L_sub( value, low ), 1 ) * model[0], 1), range)); + cum = extract_l( ar_div( L_sub( L_add( L_sub( value, low ), 1 ) * model[0], 1 ), range ) ); symbol = 1; move16(); - WHILE ( GT_16(model[symbol], cum)) + WHILE( GT_16( model[symbol], cum ) ) { - symbol = add(symbol, 1); + symbol = add( symbol, 1 ); } - high = L_sub(L_add(low, ar_div(range * model[symbol - 1], model[0])), 1); - low = L_add(low, ar_div(range * model[symbol], model[0])); + high = L_sub( L_add( low, ar_div( range * model[symbol - 1], model[0] ) ), 1 ); + low = L_add( low, ar_div( range * model[symbol], model[0] ) ); - FOR (i = 0; i < 0x7FFF; i++) + FOR( i = 0; i < 0x7FFF; i++ ) { Word32 L_msb_diff, L_msb_low, L_msb_high; - L_msb_high = L_shr(high,14); - L_msb_low = L_shr(low,14); - L_msb_diff = L_sub(L_msb_high, L_msb_low); - IF (GE_32(L_msb_diff,2)) + L_msb_high = L_shr( high, 14 ); + L_msb_low = L_shr( low, 14 ); + L_msb_diff = L_sub( L_msb_high, L_msb_low ); + IF( GE_32( L_msb_diff, 2 ) ) { BREAK; } - assert (tab_ari_qnew[L_msb_high][L_msb_low] != 0x0CCC); - assert (tab_ari_qnew[L_msb_high][L_msb_low] != 0x0BBB); - low = L_msu(low,1,tab_ari_qnew[L_msb_high][L_msb_low]); - low = L_shl(low,1); - high = L_msu(high,1,tab_ari_qnew[L_msb_high][L_msb_low]); - high = L_add(L_shl(high, 1), 1); - value = L_msu(value,1,tab_ari_qnew[L_msb_high][L_msb_low]); - value = L_add(L_shl(value, 1), bitstream_load_bit( arInst->bsInst )); + assert( tab_ari_qnew[L_msb_high][L_msb_low] != 0x0CCC ); + assert( tab_ari_qnew[L_msb_high][L_msb_low] != 0x0BBB ); + low = L_msu( low, 1, tab_ari_qnew[L_msb_high][L_msb_low] ); + low = L_shl( low, 1 ); + high = L_msu( high, 1, tab_ari_qnew[L_msb_high][L_msb_low] ); + high = L_add( L_shl( high, 1 ), 1 ); + value = L_msu( value, 1, tab_ari_qnew[L_msb_high][L_msb_low] ); + value = L_add( L_shl( value, 1 ), bitstream_load_bit( arInst->bsInst ) ); } arInst->low = low; @@ -406,33 +396,31 @@ static Word16 ar_decode_fx( arInst->value = value; move32(); - return (symbol - 1); + return ( symbol - 1 ); } -void ar_decoder_done_fx( - PARCODEC arInst -) +void ar_decoder_done_fx( + PARCODEC arInst ) { bitstream_rollback( arInst->bsInst, AR_BITS - 2 ); return; } -static Word16 quantize_fx( - Word16 val, - const Word16 D -) +static Word16 quantize_fx( + Word16 val, + const Word16 D ) { Word16 qval4_fx; Word16 retval_fx; - val = s_min(val, 32255); /* limit input by (2^15 - 1)-2^9 */ - qval4_fx = shr(abs_s(add(val, 512)), 12); - retval_fx = add(shl(qval4_fx, 2), DDP_fx[D]); + val = s_min( val, 32255 ); /* limit input by (2^15 - 1)-2^9 */ + qval4_fx = shr( abs_s( add( val, 512 ) ), 12 ); + retval_fx = add( shl( qval4_fx, 2 ), DDP_fx[D] ); /* 2nd zero check */ - IF (D == 0) + IF( D == 0 ) { - if (GT_16(abs_s(sub(shl(abs_s(retval_fx), 10), abs_s(val))), abs_s(val))) + if ( GT_16( abs_s( sub( shl( abs_s( retval_fx ), 10 ), abs_s( val ) ) ), abs_s( val ) ) ) { retval_fx = 0; move16(); @@ -443,9 +431,8 @@ static Word16 quantize_fx( } static Word32 GetBitsFromPulses_fx( - Word16 m, - Word16 n -) + Word16 m, + Word16 n ) { Word16 i, tmp, integer_fx, temp_fx1, temp_fx2, exp1, exp2; Word32 temp32; @@ -456,18 +443,18 @@ static Word32 GetBitsFromPulses_fx( move16(); move32(); - IF (m == 0) + IF( m == 0 ) { return 0; } - tmp = s_min(m, n); - FOR (i = 0; i < tmp; i++) + tmp = s_min( m, n ); + FOR( i = 0; i < tmp; i++ ) { - logCoeff_fx = L_add(L_shl(i + 1, 16), L_sub(table_logcum_fx[n+1], L_add(table_logcum_fx[i + 2], table_logcum_fx[n - i]))); - logCoeff_fx = L_add(logCoeff_fx, L_sub(table_logcum_fx[m], L_add(table_logcum_fx[i + 1], table_logcum_fx[m - i])));/*Q16 */ - integer_fx = extract_h(logCoeff_fx);/*Q0 */ - frac_fx32 = L_sub(logCoeff_fx, L_shl(integer_fx, 16));/*Q16 */ + logCoeff_fx = L_add( L_shl( i + 1, 16 ), L_sub( table_logcum_fx[n + 1], L_add( table_logcum_fx[i + 2], table_logcum_fx[n - i] ) ) ); + logCoeff_fx = L_add( logCoeff_fx, L_sub( table_logcum_fx[m], L_add( table_logcum_fx[i + 1], table_logcum_fx[m - i] ) ) ); /*Q16 */ + integer_fx = extract_h( logCoeff_fx ); /*Q0 */ + frac_fx32 = L_sub( logCoeff_fx, L_shl( integer_fx, 16 ) ); /*Q16 */ /*ln2, 0.987, ln2 * ln2, 0.977 */ /*temp1 = (int) (frac / 0.0625); */ @@ -476,70 +463,68 @@ static Word32 GetBitsFromPulses_fx( /* frac = pow(2.0, temp1 * 0.0625) * (1 + 0.693 * temp2 + 0.480 * temp2 * temp2 * 0.5);*/ /*frac = pow_getbitsfrompulses[temp1] * (1 + 0.693f * temp2 + 0.480f * temp2 * temp2 * 0.5f); */ - temp_fx1 = extract_h(L_shl(frac_fx32, 4)); - temp_fx2 = extract_l(L_and(frac_fx32, 0xfff));/*Q16 */ + temp_fx1 = extract_h( L_shl( frac_fx32, 4 ) ); + temp_fx2 = extract_l( L_and( frac_fx32, 0xfff ) ); /*Q16 */ - frac_fx32 =L_mac(Mult_32_16(L_mult0(temp_fx2, temp_fx2), 7864), temp_fx2, 22708);/*Q32 */ - frac_fx32 = L_add(0x40000000, L_shr(frac_fx32, 2));/*30 */ + frac_fx32 = L_mac( Mult_32_16( L_mult0( temp_fx2, temp_fx2 ), 7864 ), temp_fx2, 22708 ); /*Q32 */ + frac_fx32 = L_add( 0x40000000, L_shr( frac_fx32, 2 ) ); /*30 */ - exp1 = norm_l(pow_getbitsfrompulses_fx[temp_fx1]); - exp2 = norm_l(frac_fx32); - frac_fx32 = Mult_32_32(L_shl(pow_getbitsfrompulses_fx[temp_fx1], exp1), L_shl(frac_fx32, exp2));/*21 + exp1 + 30 + exp2 - 31 */ - frac_fx32 = L_shr(frac_fx32, exp1 + exp2) + 1;/*20 */ + exp1 = norm_l( pow_getbitsfrompulses_fx[temp_fx1] ); + exp2 = norm_l( frac_fx32 ); + frac_fx32 = Mult_32_32( L_shl( pow_getbitsfrompulses_fx[temp_fx1], exp1 ), L_shl( frac_fx32, exp2 ) ); /*21 + exp1 + 30 + exp2 - 31 */ + frac_fx32 = L_shr( frac_fx32, exp1 + exp2 ) + 1; /*20 */ - IF (LT_16(exp, integer_fx)) + IF( LT_16( exp, integer_fx ) ) { - mantissa_fx = L_shr(mantissa_fx, sub(integer_fx, exp)); - mantissa_fx = L_add(mantissa_fx, frac_fx32); + mantissa_fx = L_shr( mantissa_fx, sub( integer_fx, exp ) ); + mantissa_fx = L_add( mantissa_fx, frac_fx32 ); exp = integer_fx; move16(); } ELSE { - mantissa_fx = L_add(mantissa_fx, L_shr(frac_fx32, sub(exp, integer_fx))); + mantissa_fx = L_add( mantissa_fx, L_shr( frac_fx32, sub( exp, integer_fx ) ) ); } - IF (GE_32(mantissa_fx, 0x200000)) + IF( GE_32( mantissa_fx, 0x200000 ) ) { exp++; move16(); - mantissa_fx = L_shr(mantissa_fx, 1); + mantissa_fx = L_shr( mantissa_fx, 1 ); } } - mantissa_fx = L_shl(mantissa_fx, 2);/*22 */ - temp_fx1 = extract_h(mantissa_fx); + mantissa_fx = L_shl( mantissa_fx, 2 ); /*22 */ + temp_fx1 = extract_h( mantissa_fx ); /*temp_fx2 = extract_h(L_shl(L_sub(mantissa_fx, L_deposit_h(temp_fx1)), 15)); // 15 */ - temp32 = L_shl(L_sub(mantissa_fx, L_deposit_h(temp_fx1)), 15);/*31 */ - exp1 = sub(norm_l(temp32), 1); - temp32 = ar_div(L_shl(temp32, exp1), temp_fx1); /*31 + exp1 */ - temp32 = L_shr(temp32, exp1 + 1);/*30 */ - - frac_fx32 = L_sub(0x40000000, L_shr(temp32, 1));/*30 */ - frac_fx32 = Mult_32_32(frac_fx32, temp32);/*29 */ - frac_fx32 = L_shr(frac_fx32, 13);/*16 */ - exp1 = norm_l(temp_fx1); - temp_fx1 = Log2_norm_lc(L_shl(temp_fx1, exp1));/*15 */ - frac_fx32 = frac_fx32 + Mult_32_32(frac_fx32, 950680361); /* frac_fx32 *= 1/ln(2) */ - return L_add(L_deposit_h(exp), L_add(L_shl(temp_fx1, 1), frac_fx32)); + temp32 = L_shl( L_sub( mantissa_fx, L_deposit_h( temp_fx1 ) ), 15 ); /*31 */ + exp1 = sub( norm_l( temp32 ), 1 ); + temp32 = ar_div( L_shl( temp32, exp1 ), temp_fx1 ); /*31 + exp1 */ + temp32 = L_shr( temp32, exp1 + 1 ); /*30 */ + + frac_fx32 = L_sub( 0x40000000, L_shr( temp32, 1 ) ); /*30 */ + frac_fx32 = Mult_32_32( frac_fx32, temp32 ); /*29 */ + frac_fx32 = L_shr( frac_fx32, 13 ); /*16 */ + exp1 = norm_l( temp_fx1 ); + temp_fx1 = Log2_norm_lc( L_shl( temp_fx1, exp1 ) ); /*15 */ + frac_fx32 = frac_fx32 + Mult_32_32( frac_fx32, 950680361 ); /* frac_fx32 *= 1/ln(2) */ + return L_add( L_deposit_h( exp ), L_add( L_shl( temp_fx1, 1 ), frac_fx32 ) ); /*return exp + (float)temp_fx1 / pow(2.0, 15) + (float)frac_fx32 / pow(2.0, 16); */ } -static -void TCQnew_fx( - Word32 *v_fx, - Word32 scale_fx, +static void TCQnew_fx( + Word32 *v_fx, + Word32 scale_fx, Word16 Qscale, - Word16 length, - Word16 *vout_fx, - Word16 pulses, - Word16 *pulsesout, - Word16* nzposout, - Word32 *savedstates, - Word32 * lasttrellislevel, - Word32 terminate -) + Word16 length, + Word16 *vout_fx, + Word16 pulses, + Word16 *pulsesout, + Word16 *nzposout, + Word32 *savedstates, + Word32 *lasttrellislevel, + Word32 terminate ) { Word16 i, st, dminpos, position; Word16 pulsesnum, nzpos = 0; @@ -548,97 +533,97 @@ void TCQnew_fx( Word16 path_fx[STATES][TCQ_MAX_BAND_SIZE]; Word16 quant_fx[STATES][TCQ_MAX_BAND_SIZE]; Word16 pused_fx[STATES][TCQ_MAX_BAND_SIZE]; - Word16 quantum1_fx, quantum2_fx, newdist1_fx, newdist2_fx/*, signq_fx*/; - Word32 /*scale_fx, */tmp32, dmin_fx, curdist1_fx, curdist2_fx; + Word16 quantum1_fx, quantum2_fx, newdist1_fx, newdist2_fx /*, signq_fx*/; + Word32 /*scale_fx, */ tmp32, dmin_fx, curdist1_fx, curdist2_fx; Word16 value_fx, exp; Word16 exp1, exp2; - set32_fx(*metric_fx, 0, STATES * TCQ_MAX_BAND_SIZE); - set16_fx( *path_fx, 0, STATES*TCQ_MAX_BAND_SIZE ); - set16_fx( *quant_fx, 0, STATES*TCQ_MAX_BAND_SIZE ); - set16_fx( *pused_fx, 0, STATES*TCQ_MAX_BAND_SIZE ); + set32_fx( *metric_fx, 0, STATES * TCQ_MAX_BAND_SIZE ); + set16_fx( *path_fx, 0, STATES * TCQ_MAX_BAND_SIZE ); + set16_fx( *quant_fx, 0, STATES * TCQ_MAX_BAND_SIZE ); + set16_fx( *pused_fx, 0, STATES * TCQ_MAX_BAND_SIZE ); /* Initialize metric */ - FOR ( st = 1; st < STATES; st++) + FOR( st = 1; st < STATES; st++ ) { - metric_fx[st][0] = MAX_32>>1; + metric_fx[st][0] = MAX_32 >> 1; move32(); } - FOR ( st = 2; st < STATES; st++) + FOR( st = 2; st < STATES; st++ ) { - metric_fx[st][1] = MAX_32>>1; + metric_fx[st][1] = MAX_32 >> 1; move32(); } - FOR ( st = 4; st < STATES; st++) + FOR( st = 4; st < STATES; st++ ) { - metric_fx[st][2] = MAX_32>>1; + metric_fx[st][2] = MAX_32 >> 1; move32(); } /* Viterbi for input sequence */ - FOR ( i = 0; i < length; i++) /* cycle over symbols */ + FOR( i = 0; i < length; i++ ) /* cycle over symbols */ { - FOR ( st = 0; st < STATES; st++) /* cycle over conditions */ + FOR( st = 0; st < STATES; st++ ) /* cycle over conditions */ { - curdist1_fx = L_add(metric_fx[ step_tcq[st][0]][i], 0); - curdist2_fx = L_add(metric_fx[ step_tcq[st][1]][i], 0); + curdist1_fx = L_add( metric_fx[step_tcq[st][0]][i], 0 ); + curdist2_fx = L_add( metric_fx[step_tcq[st][1]][i], 0 ); - exp = norm_l(scale_fx); - tmp32 = L_shl(scale_fx, exp); - tmp32 = Mult_32_16(v_fx[i], extract_h(tmp32));/*12 + 20 + exp - 16 - 15 + Qscale */ - exp1 = 26-(exp-19+Qscale); - exp2 = norm_l(tmp32); - IF( GE_16(exp2, exp1)) + exp = norm_l( scale_fx ); + tmp32 = L_shl( scale_fx, exp ); + tmp32 = Mult_32_16( v_fx[i], extract_h( tmp32 ) ); /*12 + 20 + exp - 16 - 15 + Qscale */ + exp1 = 26 - ( exp - 19 + Qscale ); + exp2 = norm_l( tmp32 ); + IF( GE_16( exp2, exp1 ) ) { - value_fx = extract_h(L_shl(tmp32, sub(26, add(sub(exp, 19), Qscale))));/*exp -19 + Qscale*/ /*10*/ + value_fx = extract_h( L_shl( tmp32, sub( 26, add( sub( exp, 19 ), Qscale ) ) ) ); /*exp -19 + Qscale*/ /*10*/ } ELSE { - value_fx = extract_h(L_shl(tmp32, exp2));/*exp -19 + Qscale*/ /*10*/ + value_fx = extract_h( L_shl( tmp32, exp2 ) ); /*exp -19 + Qscale*/ /*10*/ } /* step 1 */ - quantum1_fx = quantize_fx(value_fx, denc[st][0]); - newdist1_fx = sub(shl(quantum1_fx, 10), abs_s(value_fx));/*10*/ - newdist1_fx = mult(newdist1_fx, newdist1_fx); /* 5 */ + quantum1_fx = quantize_fx( value_fx, denc[st][0] ); + newdist1_fx = sub( shl( quantum1_fx, 10 ), abs_s( value_fx ) ); /*10*/ + newdist1_fx = mult( newdist1_fx, newdist1_fx ); /* 5 */ test(); - if (GT_16(add(quantum1_fx , pused_fx[step_tcq[st][0]][i]), pulses)&&terminate) + if ( GT_16( add( quantum1_fx, pused_fx[step_tcq[st][0]][i] ), pulses ) && terminate ) { newdist1_fx = MAX_16; move16(); } /* step 2 */ - quantum2_fx = quantize_fx(value_fx, denc[st][1]); - newdist2_fx = sub(shl(quantum2_fx, 10), abs_s(value_fx));/*10*/ - newdist2_fx = mult(newdist2_fx, newdist2_fx);/*5*/ + quantum2_fx = quantize_fx( value_fx, denc[st][1] ); + newdist2_fx = sub( shl( quantum2_fx, 10 ), abs_s( value_fx ) ); /*10*/ + newdist2_fx = mult( newdist2_fx, newdist2_fx ); /*5*/ test(); - if (GT_16(add(quantum2_fx , pused_fx[step_tcq[st][1]][i]), pulses)&&terminate) + if ( GT_16( add( quantum2_fx, pused_fx[step_tcq[st][1]][i] ), pulses ) && terminate ) { newdist2_fx = MAX_16; move16(); } /* decision */ - IF (LT_32(L_add(curdist1_fx, newdist1_fx), L_add(curdist2_fx, newdist2_fx))) + IF( LT_32( L_add( curdist1_fx, newdist1_fx ), L_add( curdist2_fx, newdist2_fx ) ) ) { - path_fx[st][i+1] = step_tcq[st][0]; + path_fx[st][i + 1] = step_tcq[st][0]; move16(); - metric_fx[st][i+1] = L_add(curdist1_fx, newdist1_fx); + metric_fx[st][i + 1] = L_add( curdist1_fx, newdist1_fx ); move32(); - quant_fx[st][i+1] = quantize_fx(value_fx, denc[st][0]); + quant_fx[st][i + 1] = quantize_fx( value_fx, denc[st][0] ); move16(); - pused_fx[st][i+1] = add(pused_fx[ step_tcq[st][0]][i], abs_s( quant_fx[st][i+1] )); + pused_fx[st][i + 1] = add( pused_fx[step_tcq[st][0]][i], abs_s( quant_fx[st][i + 1] ) ); move16(); } ELSE { - path_fx[st][i+1] = step_tcq[st][1]; + path_fx[st][i + 1] = step_tcq[st][1]; move16(); - metric_fx[st][i+1] = L_add(curdist2_fx, newdist2_fx); + metric_fx[st][i + 1] = L_add( curdist2_fx, newdist2_fx ); move32(); - quant_fx[st][i+1] = quantize_fx(value_fx, denc[st][1]); + quant_fx[st][i + 1] = quantize_fx( value_fx, denc[st][1] ); move16(); - pused_fx[st][i+1] = add(pused_fx[ step_tcq[st][1]][i], abs_s( quant_fx[st][i+1] )); + pused_fx[st][i + 1] = add( pused_fx[step_tcq[st][1]][i], abs_s( quant_fx[st][i + 1] ) ); move16(); } } @@ -647,16 +632,16 @@ void TCQnew_fx( /* Find path with minimal metric */ dminpos = 0; move16(); - dmin_fx = L_add(metric_fx[dminpos][ length], 0); - FOR ( i = 1; i < STATES; i++) + dmin_fx = L_add( metric_fx[dminpos][length], 0 ); + FOR( i = 1; i < STATES; i++ ) { test(); test(); test(); - IF ( (GT_32(dmin_fx, metric_fx[ i][ length])&&EQ_16(pused_fx[i][length],pulses))|| - (NE_16(pused_fx[dminpos][ length], pulses) && EQ_16(pused_fx[i][ length], pulses)) ) + IF( ( GT_32( dmin_fx, metric_fx[i][length] ) && EQ_16( pused_fx[i][length], pulses ) ) || + ( NE_16( pused_fx[dminpos][length], pulses ) && EQ_16( pused_fx[i][length], pulses ) ) ) { - dmin_fx = L_add(metric_fx[ i][ length], 0); + dmin_fx = L_add( metric_fx[i][length], 0 ); dminpos = i; move16(); } @@ -668,23 +653,23 @@ void TCQnew_fx( move16(); position = dminpos; move16(); - FOR ( i = length; i > 0; i--) + FOR( i = length; i > 0; i-- ) { - vout_fx[i-1] = quant_fx[position][i]; + vout_fx[i - 1] = quant_fx[position][i]; move16(); - if (v_fx[i-1] <= 0) + if ( v_fx[i - 1] <= 0 ) { - vout_fx[i-1] = - quant_fx[position][i]; + vout_fx[i - 1] = -quant_fx[position][i]; move16(); } - position = path_fx[position][i]; + position = path_fx[position][i]; move16(); - savedstates[i-1] = position; + savedstates[i - 1] = position; move32(); /* calculate output pulses number & nz */ - pulsesnum = add(pulsesnum, abs_s(vout_fx[i-1]));/*quant[position][i]; */ - IF ( abs_s(vout_fx[i-1]) > 0 ) + pulsesnum = add( pulsesnum, abs_s( vout_fx[i - 1] ) ); /*quant[position][i]; */ + IF( abs_s( vout_fx[i - 1] ) > 0 ) { if ( nzpos == 0 ) { @@ -692,7 +677,7 @@ void TCQnew_fx( move32(); } - nzpos = add(nzpos, 1); + nzpos = add( nzpos, 1 ); } } @@ -703,29 +688,28 @@ void TCQnew_fx( } if ( nzposout != 0 ) { - *nzposout = nzpos; + *nzposout = nzpos; move16(); } return; } -Word32 GetISCScale_fx( - Word32 *quants_fx, - Word16 size, - Word32 bits_fx, - Word16 *magn_fx, - Word32 *qscale_fx, - Word32 *surplus_fx, - Word16 *pulses, - Word32* savedstates, +Word32 GetISCScale_fx( + Word32 *quants_fx, + Word16 size, + Word32 bits_fx, + Word16 *magn_fx, + Word32 *qscale_fx, + Word32 *surplus_fx, + Word16 *pulses, + Word32 *savedstates, Word32 noTCQ, - Word16 *nzpout, - Word16 *bcount, - Word32 *abuffer, - Word16 *mbuffer, - Word32 *sbuffer -) + Word16 *nzpout, + Word16 *bcount, + Word32 *abuffer, + Word16 *mbuffer, + Word32 *sbuffer ) { Word32 pos, terminate, trellislevel, st; Word32 lasttrellislevel; @@ -735,7 +719,7 @@ Word32 GetISCScale_fx( Word32 t32; Word16 SafeExp; - Word32 magnbits_fx = 0, tcqmagnbits_fx/*, surplus_fx, bits_fx*/; + Word32 magnbits_fx = 0, tcqmagnbits_fx /*, surplus_fx, bits_fx*/; Word16 prob0_fx, prob1_fx, num, denum, quantum1_fx, quantum2_fx; Word32 dmin_fx, scale_fx32; Word32 actualt_fx; @@ -743,59 +727,60 @@ Word32 GetISCScale_fx( Word16 pn_fx, g_fx, scale_fx; Word16 tmp16, exp, exp1, exp2, Q_temp, hi, lo; Word32 m_fx, tmp32; - Word32 /*quants_fx[TCQ_MAX_BAND_SIZE], */aquants_fx[TCQ_MAX_BAND_SIZE], dist_fx[TCQ_MAX_BAND_SIZE]; + Word32 /*quants_fx[TCQ_MAX_BAND_SIZE], */ aquants_fx[TCQ_MAX_BAND_SIZE], dist_fx[TCQ_MAX_BAND_SIZE]; Word16 exp_dist[TCQ_MAX_BAND_SIZE]; - Word16 /*magn_fx[TCQ_MAX_BAND_SIZE], */t_fx; + Word16 /*magn_fx[TCQ_MAX_BAND_SIZE], */ t_fx; Word16 Qscale; - Word16 Qsxy=4; + Word16 Qsxy = 4; - exp = 0; /* to avoid compilation warnings */ - Qscale = 0; /* to avoid compilation warnings */ + exp = 0; /* to avoid compilation warnings */ + Qscale = 0; /* to avoid compilation warnings */ set32_fx( dist_fx, 0, size ); - set16_fx(exp_dist, 31, size ); + set16_fx( exp_dist, 31, size ); set32_fx( aquants_fx, 0, size ); IF( bits_fx < 0 ) { - pulsesnum = 0; + pulsesnum = 0; move16(); IF( surplus_fx != NULL ) { /* *surplus_fx += bits_fx; */ - *surplus_fx = L_add(*surplus_fx, bits_fx); + *surplus_fx = L_add( *surplus_fx, bits_fx ); move32(); } } ELSE { - pulsesnum = GetScale_fx(size, bits_fx, surplus_fx); + pulsesnum = GetScale_fx( size, bits_fx, surplus_fx ); } *nzpout = 0; move16(); - if ( pulses != NULL) + if ( pulses != NULL ) { *pulses = pulsesnum; move16(); } - IF ( pulsesnum > 0 ) + IF( pulsesnum > 0 ) { /* Initial quantization */ - m_fx = L_deposit_l(0); - FOR (i = 0; i < size; i++) + m_fx = L_deposit_l( 0 ); + FOR( i = 0; i < size; i++ ) { - aquants_fx[i] = L_abs(quants_fx[i]);/*Q12 */ move32(); - m_fx = L_add(m_fx, L_shr( aquants_fx[i], 2) );/*Q12 - 2*/ + aquants_fx[i] = L_abs( quants_fx[i] ); /*Q12 */ + move32(); + m_fx = L_add( m_fx, L_shr( aquants_fx[i], 2 ) ); /*Q12 - 2*/ } - IF (m_fx == 0) + IF( m_fx == 0 ) { scale_fx = 0; move16(); - FOR (i = 0; i < size; i++) + FOR( i = 0; i < size; i++ ) { magn_fx[i] = 0; move16(); @@ -805,44 +790,44 @@ Word32 GetISCScale_fx( } ELSE { - exp1 = sub(norm_s(pulsesnum), 1); - exp2 = norm_l(m_fx); - scale_fx = div_s(shl(pulsesnum, exp1), extract_h(L_shl(m_fx, exp2)));/*15 + exp1 - (exp2 + 12 - 16) */ + exp1 = sub( norm_s( pulsesnum ), 1 ); + exp2 = norm_l( m_fx ); + scale_fx = div_s( shl( pulsesnum, exp1 ), extract_h( L_shl( m_fx, exp2 ) ) ); /*15 + exp1 - (exp2 + 12 - 16) */ - exp = 15 + exp1 - (exp2 + 12 - 16) + 2; + exp = 15 + exp1 - ( exp2 + 12 - 16 ) + 2; move16(); t_fx = 0; move16(); - FOR (i = 0; i < size; i++) + FOR( i = 0; i < size; i++ ) { - tmp32 = Mult_32_16(aquants_fx[i], scale_fx);/*12 + exp - 15 */ - tmp32 = L_shl(tmp32, sub(16, 12 + exp - 15));/*16 */ - magn_fx[i] = extract_h(L_add(32768, tmp32)); - t_fx = add(t_fx, magn_fx[i]); + tmp32 = Mult_32_16( aquants_fx[i], scale_fx ); /*12 + exp - 15 */ + tmp32 = L_shl( tmp32, sub( 16, 12 + exp - 15 ) ); /*16 */ + magn_fx[i] = extract_h( L_add( 32768, tmp32 ) ); + t_fx = add( t_fx, magn_fx[i] ); } } /* Pulses redistribution */ - WHILE (NE_16(t_fx, pulsesnum)) + WHILE( NE_16( t_fx, pulsesnum ) ) { pn_fx = 0; move16(); - pt_fx = L_deposit_l(0); + pt_fx = L_deposit_l( 0 ); nzpos = 0; move16(); - FOR (i = 0; i < size; i++) + FOR( i = 0; i < size; i++ ) { - IF (magn_fx[i] > 0) + IF( magn_fx[i] > 0 ) { - pn_fx = add(pn_fx, magn_fx[i]);/*0 */ - pt_fx = L_add(pt_fx, L_shr( aquants_fx[i], 2) );/*12 */ + pn_fx = add( pn_fx, magn_fx[i] ); /*0 */ + pt_fx = L_add( pt_fx, L_shr( aquants_fx[i], 2 ) ); /*12 */ } } direction = -1; move16(); - if ( GT_16(pulsesnum, t_fx)) + if ( GT_16( pulsesnum, t_fx ) ) { direction = 1; move16(); @@ -850,37 +835,37 @@ Word32 GetISCScale_fx( /* new alg */ { - FOR ( i = 0; i < size; i++) + FOR( i = 0; i < size; i++ ) { - sxy_fx = L_add(sxy_fx, L_shl(Mult_32_16(aquants_fx[i], magn_fx[i]), Qsxy+3)); /* 12+0-15 +9 -> 6 */ - sy2_fx = L_add(sy2_fx, L_mult0(magn_fx[i], magn_fx[i]));/*0 */ + sxy_fx = L_add( sxy_fx, L_shl( Mult_32_16( aquants_fx[i], magn_fx[i] ), Qsxy + 3 ) ); /* 12+0-15 +9 -> 6 */ + sy2_fx = L_add( sy2_fx, L_mult0( magn_fx[i], magn_fx[i] ) ); /*0 */ } Q_temp = 32; move16(); - FOR ( i = 0; i < size; i++) + FOR( i = 0; i < size; i++ ) { - IF (magn_fx[i] > 0) + IF( magn_fx[i] > 0 ) { - tmp16 = add(pn_fx, direction); - tmp32 = L_add(pt_fx, 0); + tmp16 = add( pn_fx, direction ); + tmp32 = L_add( pt_fx, 0 ); } ELSE { - tmp16 = add(pn_fx, direction); - tmp32 = L_add(pt_fx, L_shr( aquants_fx[i], 2) ); + tmp16 = add( pn_fx, direction ); + tmp32 = L_add( pt_fx, L_shr( aquants_fx[i], 2 ) ); } - IF (tmp32 == 0) + IF( tmp32 == 0 ) { g_fx = 0; move16(); } ELSE { - exp1 = sub(norm_l(tmp32), 1); - exp2 = norm_s(tmp16); - tmp32 = L_shl(tmp32, exp1); - IF (tmp16 == 0) + exp1 = sub( norm_l( tmp32 ), 1 ); + exp2 = norm_s( tmp16 ); + tmp32 = L_shl( tmp32, exp1 ); + IF( tmp16 == 0 ) { tmp16 = 1; move16(); @@ -889,28 +874,28 @@ Word32 GetISCScale_fx( } ELSE { - tmp16 = shl(tmp16, exp2); + tmp16 = shl( tmp16, exp2 ); } - g_fx = div_s(extract_h(tmp32), tmp16);/*15 + 12 + exp1 - 16 - exp2; */ + g_fx = div_s( extract_h( tmp32 ), tmp16 ); /*15 + 12 + exp1 - 16 - exp2; */ exp = 15 + 12 + exp1 - 16 - exp2 - 2; move16(); } - IF (g_fx == 0) + IF( g_fx == 0 ) { - dist_fx[i] = L_deposit_l(0); + dist_fx[i] = L_deposit_l( 0 ); } ELSE { - IF (direction > 0) + IF( direction > 0 ) { - tmp32 = L_add(sxy_fx, L_shr(aquants_fx[i], 12-Qsxy));/*Qsxy */ - t32 = L_add( sy2_fx, L_add( 1, L_deposit_l( shl(magn_fx[i], 1) ) ) ); + tmp32 = L_add( sxy_fx, L_shr( aquants_fx[i], 12 - Qsxy ) ); /*Qsxy */ + t32 = L_add( sy2_fx, L_add( 1, L_deposit_l( shl( magn_fx[i], 1 ) ) ) ); - IF( LT_16(norm_l(t32), 15)) + IF( LT_16( norm_l( t32 ), 15 ) ) { - SafeExp = sub(16, norm_l(t32)); - tmp16 = extract_l( L_shr( t32, SafeExp) ); + SafeExp = sub( 16, norm_l( t32 ) ); + tmp16 = extract_l( L_shr( t32, SafeExp ) ); } ELSE { @@ -921,14 +906,14 @@ Word32 GetISCScale_fx( } ELSE { - tmp32 = L_sub(sxy_fx, L_shr(aquants_fx[i], 12-Qsxy));/*Qsxy */ - t32 = L_add( sy2_fx, L_sub( 1, L_deposit_l( shl(magn_fx[i], 1) ) ) ); - SafeExp = norm_l(t32); + tmp32 = L_sub( sxy_fx, L_shr( aquants_fx[i], 12 - Qsxy ) ); /*Qsxy */ + t32 = L_add( sy2_fx, L_sub( 1, L_deposit_l( shl( magn_fx[i], 1 ) ) ) ); + SafeExp = norm_l( t32 ); - IF( LE_16(norm_l(t32), 15)) + IF( LE_16( norm_l( t32 ), 15 ) ) { - SafeExp = sub(16, norm_l(t32)); - tmp16 = extract_l( L_shr( t32, SafeExp) ); + SafeExp = sub( 16, norm_l( t32 ) ); + tmp16 = extract_l( L_shr( t32, SafeExp ) ); } ELSE { @@ -938,103 +923,103 @@ Word32 GetISCScale_fx( } } #ifdef BASOP_NOGLOB - tmp32 = L_shl_sat( tmp32, 1 - SafeExp ); /* *2 */ + tmp32 = L_shl_sat( tmp32, 1 - SafeExp ); /* *2 */ tmp32 = L_sub_sat( L_shl_sat( L_mult0( g_fx, tmp16 ), sub( Qsxy, exp ) ), tmp32 ); /*Qsxy */ #else tmp32 = L_shl( tmp32, 1 - SafeExp ); /* *2 */ tmp32 = L_sub( L_shl( L_mult0( g_fx, tmp16 ), sub( Qsxy, exp ) ), tmp32 ); /*Qsxy */ #endif - dist_fx[i] = Mult_32_16(tmp32, g_fx);/*Qsxy + exp - 15 */ move32(); - exp_dist[i] = add(Qsxy-15, exp); + dist_fx[i] = Mult_32_16( tmp32, g_fx ); /*Qsxy + exp - 15 */ + move32(); + exp_dist[i] = add( Qsxy - 15, exp ); move16(); - if (LT_16(exp_dist[i], Q_temp)) + if ( LT_16( exp_dist[i], Q_temp ) ) { Q_temp = exp_dist[i]; move16(); } } - } - FOR (i = 0; i < size; i++) + FOR( i = 0; i < size; i++ ) { - dist_fx[i] = L_shr(dist_fx[i], s_min(sub(exp_dist[i], Q_temp), 31)); + dist_fx[i] = L_shr( dist_fx[i], s_min( sub( exp_dist[i], Q_temp ), 31 ) ); move32(); } } { /* find min */ - pos = L_deposit_l(0); - dmin_fx = L_add(dist_fx[0], 0); - FOR (i = 1; i < size; i++) + pos = L_deposit_l( 0 ); + dmin_fx = L_add( dist_fx[0], 0 ); + FOR( i = 1; i < size; i++ ) { - IF (GT_32(dmin_fx, dist_fx[i])) + IF( GT_32( dmin_fx, dist_fx[i] ) ) { - pos = L_deposit_l(i); - dmin_fx = L_add(dist_fx[i], 0); + pos = L_deposit_l( i ); + dmin_fx = L_add( dist_fx[i], 0 ); } } /*IF (magn_fx[i] == 0 && direction < 0) */ test(); - IF (magn_fx[pos] == 0 && direction < 0) + IF( magn_fx[pos] == 0 && direction < 0 ) { - pos = L_deposit_l(0); - FOR (i = 0; i < size; i++) + pos = L_deposit_l( 0 ); + FOR( i = 0; i < size; i++ ) { - IF (magn_fx[i] != 0) + IF( magn_fx[i] != 0 ) { - pos = L_deposit_l(i); + pos = L_deposit_l( i ); BREAK; } } - dmin_fx = L_add(dist_fx[i], 0); - FOR (; i < size; i++) + dmin_fx = L_add( dist_fx[i], 0 ); + FOR( ; i < size; i++ ) { test(); - IF (magn_fx[i] != 0 && LT_32(dmin_fx, dist_fx[i])) + IF( magn_fx[i] != 0 && LT_32( dmin_fx, dist_fx[i] ) ) { - pos = L_deposit_l(i); - dmin_fx = L_add(dist_fx[i], 0); + pos = L_deposit_l( i ); + dmin_fx = L_add( dist_fx[i], 0 ); } } } - magn_fx[pos] = add(magn_fx[pos], direction); + magn_fx[pos] = add( magn_fx[pos], direction ); move16(); - t_fx = add(t_fx, direction); + t_fx = add( t_fx, direction ); } } /* calculate actual nz positions */ - actualt_fx = L_deposit_l(0); + actualt_fx = L_deposit_l( 0 ); nzpos = 0; move16(); - FOR (i = 0; i < size; i++) + FOR( i = 0; i < size; i++ ) { - IF (magn_fx[i] > 0) + IF( magn_fx[i] > 0 ) { - if (quants_fx[i] < 0) + if ( quants_fx[i] < 0 ) { - magn_fx[i] = negate(magn_fx[i]); + magn_fx[i] = negate( magn_fx[i] ); move16(); } - actualt_fx = L_add(actualt_fx, L_shr( aquants_fx[i], 2) );/*12 */ + actualt_fx = L_add( actualt_fx, L_shr( aquants_fx[i], 2 ) ); /*12 */ nzpos++; } /*magn[i] = (float)magn_fx[i]; */ } /* calculate scale */ - IF (actualt_fx == 0) + IF( actualt_fx == 0 ) { - scale_fx32 = L_add(MAX_32, 0); + scale_fx32 = L_add( MAX_32, 0 ); } ELSE { - exp1 = norm_l(actualt_fx); - exp2 = sub(norm_l(pulsesnum), 1); - lo = L_Extract_lc(L_shl(actualt_fx, exp1), &hi); - scale_fx32 = Div_32(L_shl(pulsesnum, exp2), hi, lo);/*31 + exp2 - exp1 - 12 */ + exp1 = norm_l( actualt_fx ); + exp2 = sub( norm_l( pulsesnum ), 1 ); + lo = L_Extract_lc( L_shl( actualt_fx, exp1 ), &hi ); + scale_fx32 = Div_32( L_shl( pulsesnum, exp2 ), hi, lo ); /*31 + exp2 - exp1 - 12 */ Qscale = 31 + exp2 - exp1 - 12 + 2; move16(); } @@ -1047,55 +1032,55 @@ Word32 GetISCScale_fx( test(); test(); - IF ( (NE_16(nzpos, pulsesnum)&>_16(nzpos,1))&&noTCQ==0) + IF( ( NE_16( nzpos, pulsesnum ) && GT_16( nzpos, 1 ) ) && noTCQ == 0 ) { - terminate = L_deposit_l(1); + terminate = L_deposit_l( 1 ); /*TCQnew( quants, scale, size, magn, pulsesnum, &pulsescurr, &nzposcurr, savedstates, &lasttrellislevel, terminate); */ - TCQnew_fx(quants_fx, scale_fx32, Qscale, - size, magn_fx, pulsesnum, &pulsescurr, &nzposcurr, savedstates, &lasttrellislevel, terminate); - IF (GT_16(pulsesnum, pulsescurr)) + TCQnew_fx( quants_fx, scale_fx32, Qscale, + size, magn_fx, pulsesnum, &pulsescurr, &nzposcurr, savedstates, &lasttrellislevel, terminate ); + IF( GT_16( pulsesnum, pulsescurr ) ) { Word32 L_tmp; - IF( GT_32( 1952247030, scale_fx32)) + IF( GT_32( 1952247030, scale_fx32 ) ) { - scale_fx32 = L_add(scale_fx32, Mult_32_16(scale_fx32, 3277)); + scale_fx32 = L_add( scale_fx32, Mult_32_16( scale_fx32, 3277 ) ); } ELSE { - L_tmp = L_shr(scale_fx32, 1); - scale_fx32 = L_add(L_tmp, Mult_32_16(L_tmp, 3277)); - Qscale = sub(Qscale, 1); + L_tmp = L_shr( scale_fx32, 1 ); + scale_fx32 = L_add( L_tmp, Mult_32_16( L_tmp, 3277 ) ); + Qscale = sub( Qscale, 1 ); } } - if(LT_16(pulsesnum, pulsescurr)) + if ( LT_16( pulsesnum, pulsescurr ) ) { - scale_fx32 = Mult_32_16(scale_fx32, 29491); + scale_fx32 = Mult_32_16( scale_fx32, 29491 ); } - IF (GT_16(pulsesnum, pulsescurr)) + IF( GT_16( pulsesnum, pulsescurr ) ) { - diff = sub(pulsesnum, pulsescurr); + diff = sub( pulsesnum, pulsescurr ); - FOR ( i = size-1; i >=0; i--) + FOR( i = size - 1; i >= 0; i-- ) { - IF ( abs_s(magn_fx[i]) > 0 ) + IF( abs_s( magn_fx[i] ) > 0 ) { sign = -1; move16(); - if( magn_fx[i] > 0 ) + if ( magn_fx[i] > 0 ) { sign = 1; move16(); } /*magn_fx[i] = sign * abs_s(add(magn_fx[i], diff)); move32(); */ - IF (sign > 0) + IF( sign > 0 ) { - magn_fx[i] = abs_s(add(magn_fx[i], diff)); + magn_fx[i] = abs_s( add( magn_fx[i], diff ) ); move16(); } ELSE { - magn_fx[i] = -abs_s(add(magn_fx[i], diff)); + magn_fx[i] = -abs_s( add( magn_fx[i], diff ) ); move16(); } @@ -1103,49 +1088,49 @@ Word32 GetISCScale_fx( } } } - ELSE IF(LT_16(pulsesnum, pulsescurr)) + ELSE IF( LT_16( pulsesnum, pulsescurr ) ) { - diff = sub(pulsescurr, pulsesnum); + diff = sub( pulsescurr, pulsesnum ); - FOR ( i = size-1; i >=0; i--) + FOR( i = size - 1; i >= 0; i-- ) { - IF (diff <= 0) + IF( diff <= 0 ) { BREAK; } - IF ( abs_s(magn_fx[i]) > 0 ) + IF( abs_s( magn_fx[i] ) > 0 ) { sign = -1; move16(); - if( magn_fx[i] > 0 ) + if ( magn_fx[i] > 0 ) { sign = 1; move16(); } - m_int = abs_s(magn_fx[i]); + m_int = abs_s( magn_fx[i] ); - IF (LT_16(diff, m_int)) + IF( LT_16( diff, m_int ) ) { /*magn_fx[i] = sign * sub(abs_s(magn_fx[i]), diff); move16(); */ - IF (sign > 0) + IF( sign > 0 ) { - magn_fx[i] = sub(abs_s(magn_fx[i]), diff); + magn_fx[i] = sub( abs_s( magn_fx[i] ), diff ); move16(); } ELSE { - magn_fx[i] = - sub(abs_s(magn_fx[i]), diff); + magn_fx[i] = -sub( abs_s( magn_fx[i] ), diff ); move16(); } BREAK; } ELSE { - diff = sub(diff, m_int); + diff = sub( diff, m_int ); magn_fx[i] = 0; move16(); - nzposcurr = sub(nzposcurr, 1); + nzposcurr = sub( nzposcurr, 1 ); } } } @@ -1156,26 +1141,26 @@ Word32 GetISCScale_fx( /* Magnitudes coding */ { - leftp = pulsescurr; - move16();/*pulsesnum; */ + leftp = pulsescurr; + move16(); /*pulsesnum; */ leftnz = nzposcurr; move16(); /*nzpos; */ - trellislevel = L_deposit_l(0); + trellislevel = L_deposit_l( 0 ); - FOR ( i = 0; i < size; i++) + FOR( i = 0; i < size; i++ ) { - IF (LE_16(leftnz, 1)) + IF( LE_16( leftnz, 1 ) ) { BREAK; } - IF ( magn_fx[i] != 0 ) + IF( magn_fx[i] != 0 ) { - FOR ( j = 0; j < leftp; j++) + FOR( j = 0; j < leftp; j++ ) { - num = sub(leftnz, 1); - denum = sub(leftp, add(j, 1)); - IF (GE_16(num, denum)) + num = sub( leftnz, 1 ); + denum = sub( leftp, add( j, 1 ) ); + IF( GE_16( num, denum ) ) { prob1_fx = MAX_16; move16(); @@ -1184,21 +1169,21 @@ Word32 GetISCScale_fx( } ELSE { - exp1 = sub(norm_s(num), 1); - exp2 = norm_s(denum); - prob1_fx = div_s(shl(num, exp1), shl(denum, exp2));/*15 + exp1 - exp2 */ + exp1 = sub( norm_s( num ), 1 ); + exp2 = norm_s( denum ); + prob1_fx = div_s( shl( num, exp1 ), shl( denum, exp2 ) ); /*15 + exp1 - exp2 */ exp = 15 + exp1 - exp2; move16(); - prob1_fx = shl(prob1_fx, sub(15, exp)); - prob0_fx = sub(MAX_16, prob1_fx); + prob1_fx = shl( prob1_fx, sub( 15, exp ) ); + prob0_fx = sub( MAX_16, prob1_fx ); } - st = L_add(savedstates[ trellislevel ], 0); - quantum1_fx = quantize_fx(shl(add(j, 1), 10), ddec[st][0]); - quantum2_fx = quantize_fx(shl(add(j, 1), 10), ddec[st][1]); + st = L_add( savedstates[trellislevel], 0 ); + quantum1_fx = quantize_fx( shl( add( j, 1 ), 10 ), ddec[st][0] ); + quantum2_fx = quantize_fx( shl( add( j, 1 ), 10 ), ddec[st][1] ); test(); - IF(NE_16(quantum1_fx, add(j, 1))&&NE_16(quantum2_fx,add(j,1))) + IF( NE_16( quantum1_fx, add( j, 1 ) ) && NE_16( quantum2_fx, add( j, 1 ) ) ) { /* this magnitude is not possible so set probabilities */ prob0_fx = MAX_16; @@ -1207,92 +1192,92 @@ Word32 GetISCScale_fx( move16(); } - IF (LT_16(j, sub(abs_s(magn_fx[i]), 1))) + IF( LT_16( j, sub( abs_s( magn_fx[i] ), 1 ) ) ) { - exp1 = norm_s(prob0_fx); - tmp32 = L_deposit_h(shl(prob0_fx, exp1));/*exp1 + 15 + 16 */ - tmp16 = Log2_norm_lc(tmp32);/*15 */ - magnbits_fx = L_sub(magnbits_fx, L_sub(tmp16, L_shl(add(exp1, 1), 15)));/*15 */ + exp1 = norm_s( prob0_fx ); + tmp32 = L_deposit_h( shl( prob0_fx, exp1 ) ); /*exp1 + 15 + 16 */ + tmp16 = Log2_norm_lc( tmp32 ); /*15 */ + magnbits_fx = L_sub( magnbits_fx, L_sub( tmp16, L_shl( add( exp1, 1 ), 15 ) ) ); /*15 */ } ELSE { - exp1 = norm_s(prob1_fx); - tmp32 = L_deposit_h(shl(prob1_fx, exp1));/*exp1 + 15 + 16 */ - tmp16 = Log2_norm_lc(tmp32);/*15 */ - magnbits_fx = L_sub(magnbits_fx, L_sub(tmp16, L_shl(add(exp1, 1), 15)));/*15 */ + exp1 = norm_s( prob1_fx ); + tmp32 = L_deposit_h( shl( prob1_fx, exp1 ) ); /*exp1 + 15 + 16 */ + tmp16 = Log2_norm_lc( tmp32 ); /*15 */ + magnbits_fx = L_sub( magnbits_fx, L_sub( tmp16, L_shl( add( exp1, 1 ), 15 ) ) ); /*15 */ BREAK; } } leftnz--; move16(); - leftp = sub(leftp, abs_s(magn_fx[i])); + leftp = sub( leftp, abs_s( magn_fx[i] ) ); } - trellislevel = L_add(trellislevel, 1); + trellislevel = L_add( trellislevel, 1 ); } /* Update actual occurred surplus */ - tcqmagnbits_fx = L_sub(L_sub(table_logcum_fx[pulsescurr], table_logcum_fx[nzposcurr]), table_logcum_fx[pulsescurr - (nzposcurr - 1)]); - *surplus_fx = L_add(*surplus_fx, L_sub(tcqmagnbits_fx, L_shl(magnbits_fx, 1))); + tcqmagnbits_fx = L_sub( L_sub( table_logcum_fx[pulsescurr], table_logcum_fx[nzposcurr] ), table_logcum_fx[pulsescurr - ( nzposcurr - 1 )] ); + *surplus_fx = L_add( *surplus_fx, L_sub( tcqmagnbits_fx, L_shl( magnbits_fx, 1 ) ) ); *nzpout = nzposcurr; move16(); - }/*magnitude coding */ - }/*TCQ */ + } /*magnitude coding */ + } /*TCQ */ - IF (actualt_fx == 0) + IF( actualt_fx == 0 ) { - scale_fx32 = L_add(MAX_32, 0); + scale_fx32 = L_add( MAX_32, 0 ); } ELSE { - exp1 = norm_l(actualt_fx); - exp2 = sub(norm_l(pulsesnum), 1); - lo = L_Extract_lc(L_shl(actualt_fx, exp1), &hi); - scale_fx32 = Div_32(L_shl(pulsesnum, exp2), hi, lo);/*31 + exp2 - exp1 - 12 */ + exp1 = norm_l( actualt_fx ); + exp2 = sub( norm_l( pulsesnum ), 1 ); + lo = L_Extract_lc( L_shl( actualt_fx, exp1 ), &hi ); + scale_fx32 = Div_32( L_shl( pulsesnum, exp2 ), hi, lo ); /*31 + exp2 - exp1 - 12 */ Qscale = 31 + exp2 - exp1 - 12; move16(); } test(); - IF ( GT_16(*nzpout, 1) && bcount != NULL) + IF( GT_16( *nzpout, 1 ) && bcount != NULL ) { flag_g1 = 0; move16(); - FOR ( i = 0; i < size; i++) + FOR( i = 0; i < size; i++ ) { - if( abs_s(magn_fx[i]) > 1 ) + if ( abs_s( magn_fx[i] ) > 1 ) { flag_g1 = 1; move16(); } } /* prepare vector for TCQ */ - FOR ( i = 0; i < size; i++) + FOR( i = 0; i < size; i++ ) { test(); - IF (flag_g1 == 0 || GE_16(*bcount, 2*TCQ_AMP)) + IF( flag_g1 == 0 || GE_16( *bcount, 2 * TCQ_AMP ) ) { BREAK; } - IF ( abs_s(magn_fx[i]) > 0 ) + IF( abs_s( magn_fx[i] ) > 0 ) { abuffer[*bcount] = quants_fx[i]; move32(); mbuffer[*bcount] = magn_fx[i]; move16(); /*sbuffer[*bcount] = scale_fx32;*/ - exp = norm_s(pulsesnum); - tmp16 = div_l( actualt_fx, shl( pulsesnum, exp-1) ); - tmp32 = L_shl( L_deposit_l(tmp16), exp); + exp = norm_s( pulsesnum ); + tmp16 = div_l( actualt_fx, shl( pulsesnum, exp - 1 ) ); + tmp32 = L_shl( L_deposit_l( tmp16 ), exp ); /*sbuffer[*bcount] = 1/((float)tmp32/pow(2.0, 12));*/ - sbuffer[*bcount] = tmp32;/*Q12*/ move32(); + sbuffer[*bcount] = tmp32; /*Q12*/ + move32(); /*sbuffer[*bcount] = (float)scale_fx32 / pow(2.0, Qscale);*/ - (*bcount)++; - + ( *bcount )++; } } } @@ -1300,19 +1285,18 @@ Word32 GetISCScale_fx( move32(); } - return L_shl(magnbits_fx, 1); + return L_shl( magnbits_fx, 1 ); } void TCQLSB_fx( - Word16 bcount, - Word32 *abuffer_fx, - Word16 *mbuffer_fx, - Word32 *sbuffer_fx, - Word16 *dpath -) + Word16 bcount, + Word32 *abuffer_fx, + Word16 *mbuffer_fx, + Word32 *sbuffer_fx, + Word16 *dpath ) { Word16 i, st, dminpos, position; - Word16 q_fx = 6554;/*Q15*/ + Word16 q_fx = 6554; /*Q15*/ Word32 dmin_fx, curdist1_fx, curdist2_fx, newdist1_fx, newdist2_fx; Word16 path[STATES_LSB][TCQ_LSB_SIZE]; Word16 quant[STATES_LSB][TCQ_LSB_SIZE]; @@ -1328,131 +1312,131 @@ void TCQLSB_fx( Word32 metric_fx[STATES_LSB][TCQ_LSB_SIZE]; Word32 MaxPath; - set32_fx(*metric_fx, 0, STATES_LSB*TCQ_LSB_SIZE); - set16_fx( *path, 0, STATES_LSB*TCQ_LSB_SIZE ); - set16_fx( *quant, 0, STATES_LSB*TCQ_LSB_SIZE ); - set16_fx( *dquant, 0, STATES_LSB*TCQ_LSB_SIZE ); + set32_fx( *metric_fx, 0, STATES_LSB * TCQ_LSB_SIZE ); + set16_fx( *path, 0, STATES_LSB * TCQ_LSB_SIZE ); + set16_fx( *quant, 0, STATES_LSB * TCQ_LSB_SIZE ); + set16_fx( *dquant, 0, STATES_LSB * TCQ_LSB_SIZE ); set16_fx( qout, 0, TCQ_LSB_SIZE ); - metric_fx[1][0] = MAX_32>>8; + metric_fx[1][0] = MAX_32 >> 8; move32(); - metric_fx[2][0] = MAX_32>>8; + metric_fx[2][0] = MAX_32 >> 8; move32(); - metric_fx[3][0] = MAX_32>>8; + metric_fx[3][0] = MAX_32 >> 8; move32(); - FOR( i = 0; i < 2*TCQ_AMP; i+=2 ) + FOR( i = 0; i < 2 * TCQ_AMP; i += 2 ) { q1_fx = mbuffer_fx[i]; move16(); q2_fx = mbuffer_fx[i + 1]; move16(); - s1_fx= L_add(sbuffer_fx[i], 0); /*12*/ - s2_fx = L_add(sbuffer_fx[i + 1], 0); /*12*/ - exp1 = norm_l(s1_fx); - exp2 = norm_l(s2_fx); - s1_fx16 = extract_h(L_shl(s1_fx, exp1));/*12 + exp1 - 16*/ - s2_fx16 = extract_h(L_shl(s2_fx, exp2));/*12 + exp2 - 16*/ + s1_fx = L_add( sbuffer_fx[i], 0 ); /*12*/ + s2_fx = L_add( sbuffer_fx[i + 1], 0 ); /*12*/ + exp1 = norm_l( s1_fx ); + exp2 = norm_l( s2_fx ); + s1_fx16 = extract_h( L_shl( s1_fx, exp1 ) ); /*12 + exp1 - 16*/ + s2_fx16 = extract_h( L_shl( s2_fx, exp2 ) ); /*12 + exp2 - 16*/ exp1 = 12 + exp1 - 16; move16(); exp2 = 12 + exp2 - 16; move16(); - a1_fx = L_add(abuffer_fx[i], 0); - a2_fx = L_add(abuffer_fx[i + 1], 0); + a1_fx = L_add( abuffer_fx[i], 0 ); + a2_fx = L_add( abuffer_fx[i + 1], 0 ); - MaxPath = L_add(MAX_32, 0); + MaxPath = L_add( MAX_32, 0 ); /* cycle over conditions */ - FOR ( st = 0; st < 4; st++) + FOR( st = 0; st < 4; st++ ) { - curdist1_fx = L_add(metric_fx[ step_LSB[st][0] ][i/2], 0); - curdist2_fx = L_add(metric_fx[ step_LSB[st][1] ][i/2], 0); + curdist1_fx = L_add( metric_fx[step_LSB[st][0]][i / 2], 0 ); + curdist2_fx = L_add( metric_fx[step_LSB[st][1]][i / 2], 0 ); /* step 1 */ /*sign1_fx = (denc_LSB[st][0] & 0x1)?(q_fx):(-q_fx);*/ - IF (s_and(denc_LSB[st][0], 0x1)) + IF( s_and( denc_LSB[st][0], 0x1 ) ) { sign1_fx = q_fx; move16(); } ELSE { - sign1_fx = negate(q_fx); + sign1_fx = negate( q_fx ); } /*sign2_fx = (denc_LSB[st][0] & 0x2)?(q_fx):(-q_fx);*/ - IF (s_and(denc_LSB[st][0], 0x2)) + IF( s_and( denc_LSB[st][0], 0x2 ) ) { sign2_fx = q_fx; move16(); } ELSE { - sign2_fx = negate(q_fx); + sign2_fx = negate( q_fx ); } - tmp1 = L_sub(a1_fx, L_shl(Mult_32_16(L_add(L_shl(q1_fx, 15), sign1_fx), s1_fx16), sub(12+2, exp1)));/*12*/ - tmp2 = L_sub(a2_fx, L_shl(Mult_32_16(L_add(L_shl(q2_fx, 15), sign2_fx), s2_fx16), sub(12+2, exp2)));/*12*/ - newdist1_fx = L_add(Mult_32_32(tmp1, tmp1), Mult_32_32(tmp2, tmp2)); /* -7 */ + tmp1 = L_sub( a1_fx, L_shl( Mult_32_16( L_add( L_shl( q1_fx, 15 ), sign1_fx ), s1_fx16 ), sub( 12 + 2, exp1 ) ) ); /*12*/ + tmp2 = L_sub( a2_fx, L_shl( Mult_32_16( L_add( L_shl( q2_fx, 15 ), sign2_fx ), s2_fx16 ), sub( 12 + 2, exp2 ) ) ); /*12*/ + newdist1_fx = L_add( Mult_32_32( tmp1, tmp1 ), Mult_32_32( tmp2, tmp2 ) ); /* -7 */ /* step 2 */ /*sign1_fx = (denc_LSB[st][1] & 0x1)?(q_fx):(-q_fx);*/ - IF (s_and(denc_LSB[st][1], 0x1)) + IF( s_and( denc_LSB[st][1], 0x1 ) ) { sign1_fx = q_fx; move16(); } ELSE { - sign1_fx = negate(q_fx); + sign1_fx = negate( q_fx ); } /*sign2_fx = (denc_LSB[st][1] & 0x2)?(q_fx):(-q_fx);*/ - IF (s_and(denc_LSB[st][1], 0x2)) + IF( s_and( denc_LSB[st][1], 0x2 ) ) { sign2_fx = q_fx; move16(); } ELSE { - sign2_fx = negate(q_fx); + sign2_fx = negate( q_fx ); } - tmp1 = L_sub(a1_fx, L_shl(Mult_32_16(L_add(L_shl(q1_fx, 15), sign1_fx), s1_fx16), sub(12+2, exp1)));/*12*/ - tmp2 = L_sub(a2_fx, L_shl(Mult_32_16(L_add(L_shl(q2_fx, 15), sign2_fx), s2_fx16), sub(12+2, exp2)));/*12*/ - newdist2_fx = L_add(Mult_32_32(tmp1, tmp1), Mult_32_32(tmp2, tmp2));/*-7*/ + tmp1 = L_sub( a1_fx, L_shl( Mult_32_16( L_add( L_shl( q1_fx, 15 ), sign1_fx ), s1_fx16 ), sub( 12 + 2, exp1 ) ) ); /*12*/ + tmp2 = L_sub( a2_fx, L_shl( Mult_32_16( L_add( L_shl( q2_fx, 15 ), sign2_fx ), s2_fx16 ), sub( 12 + 2, exp2 ) ) ); /*12*/ + newdist2_fx = L_add( Mult_32_32( tmp1, tmp1 ), Mult_32_32( tmp2, tmp2 ) ); /*-7*/ /* decision */ - IF ( LT_32(L_add(curdist1_fx, newdist1_fx), L_add(curdist2_fx, newdist2_fx))) + IF( LT_32( L_add( curdist1_fx, newdist1_fx ), L_add( curdist2_fx, newdist2_fx ) ) ) { - path[st][i/2+1] = step_LSB[st][0]; + path[st][i / 2 + 1] = step_LSB[st][0]; move16(); - metric_fx[st][i/2+1] = L_add(curdist1_fx, newdist1_fx); + metric_fx[st][i / 2 + 1] = L_add( curdist1_fx, newdist1_fx ); move32(); - quant[st][i/2+1] = 0; + quant[st][i / 2 + 1] = 0; move16(); - dquant[st][i/2+1] = dqnt_LSB[ step_LSB[st][0] ][st]; + dquant[st][i / 2 + 1] = dqnt_LSB[step_LSB[st][0]][st]; move16(); } ELSE { - path[st][i/2+1] = step_LSB[st][1]; + path[st][i / 2 + 1] = step_LSB[st][1]; move16(); - metric_fx[st][i/2+1] = L_add(curdist2_fx, newdist2_fx); + metric_fx[st][i / 2 + 1] = L_add( curdist2_fx, newdist2_fx ); move32(); - quant[st][i/2+1] = 1; + quant[st][i / 2 + 1] = 1; move16(); - dquant[st][i/2+1] = dqnt_LSB[ step_LSB[st][0] ][st]; + dquant[st][i / 2 + 1] = dqnt_LSB[step_LSB[st][0]][st]; move16(); } - if( GT_32( MaxPath, metric_fx[st][i/2+1])) + if ( GT_32( MaxPath, metric_fx[st][i / 2 + 1] ) ) { - MaxPath = L_add(metric_fx[st][i/2+1], 0); + MaxPath = L_add( metric_fx[st][i / 2 + 1], 0 ); } } /* Metric renormalization to prevent overflow */ - FOR ( st = 0; st < 4; st++) + FOR( st = 0; st < 4; st++ ) { - metric_fx[st][i/2+1] = L_sub( metric_fx[st][i/2+1], MaxPath ); + metric_fx[st][i / 2 + 1] = L_sub( metric_fx[st][i / 2 + 1], MaxPath ); move32(); } } @@ -1460,12 +1444,12 @@ void TCQLSB_fx( /* Find path with minimal metric */ dminpos = 0; move16(); - dmin_fx = L_add(metric_fx[ dminpos][ i/2], 0); - FOR ( st = 1; st < 4; st++) + dmin_fx = L_add( metric_fx[dminpos][i / 2], 0 ); + FOR( st = 1; st < 4; st++ ) { - IF ( GT_32(dmin_fx, metric_fx[ st][ i/2])) + IF( GT_32( dmin_fx, metric_fx[st][i / 2] ) ) { - dmin_fx = L_add(metric_fx[ st][ i/2], 0); + dmin_fx = L_add( metric_fx[st][i / 2], 0 ); dminpos = st; move16(); } @@ -1475,14 +1459,14 @@ void TCQLSB_fx( position = dminpos; move16(); - FOR ( ; i >= 0; i-=2) + FOR( ; i >= 0; i -= 2 ) { - qout[i/2] = quant[position][ i/2+1 ]; + qout[i / 2] = quant[position][i / 2 + 1]; move16(); - dpath[i/2] = dquant[position][ i/2+1 ]; + dpath[i / 2] = dquant[position][i / 2 + 1]; move16(); - IF (s_and(denc_LSB[position][qout[i/2]], 0x1)) + IF( s_and( denc_LSB[position][qout[i / 2]], 0x1 ) ) { dbuffer_fx[i] = 1; move16(); @@ -1492,7 +1476,7 @@ void TCQLSB_fx( dbuffer_fx[i] = -1; move16(); } - IF (s_and(denc_LSB[position][qout[i/2]], 0x2)) + IF( s_and( denc_LSB[position][qout[i / 2]], 0x2 ) ) { dbuffer_fx[i + 1] = 1; move16(); @@ -1503,75 +1487,73 @@ void TCQLSB_fx( move16(); } - position = path[position][i/2+1]; + position = path[position][i / 2 + 1]; move16(); } /* add decoded sequence to quanta */ - FOR ( i = 0; i < bcount; i++ ) + FOR( i = 0; i < bcount; i++ ) { - mbuffer_fx[i] = add(add(mbuffer_fx[i], shl(mbuffer_fx[i], 2)), dbuffer_fx[i]); + mbuffer_fx[i] = add( add( mbuffer_fx[i], shl( mbuffer_fx[i], 2 ) ), dbuffer_fx[i] ); } return; } -void TCQLSBdec_fx( - Word16 *dpath, - Word16 *mbuffer, - Word16 bcount -) +void TCQLSBdec_fx( + Word16 *dpath, + Word16 *mbuffer, + Word16 bcount ) { /*float q = QTCQ;*/ - Word16 q = 1;/*x5*/ + Word16 q = 1; /*x5*/ Word16 i, tmp, state = 0; - tmp = shr(bcount, 1); - FOR ( i = 0; i < tmp; i++) + tmp = shr( bcount, 1 ); + FOR( i = 0; i < tmp; i++ ) { - IF (s_and(ddec_LSB[state][dpath[i]], 0x1)) + IF( s_and( ddec_LSB[state][dpath[i]], 0x1 ) ) { - mbuffer[2*i] = q; + mbuffer[2 * i] = q; move16(); } ELSE { - mbuffer[2*i] = negate(q); + mbuffer[2 * i] = negate( q ); } - IF (s_and(ddec_LSB[state][dpath[i]], 0x2)) + IF( s_and( ddec_LSB[state][dpath[i]], 0x2 ) ) { - mbuffer[2*i + 1] = q; + mbuffer[2 * i + 1] = q; move16(); } ELSE { - mbuffer[2*i + 1] = negate(q); + mbuffer[2 * i + 1] = negate( q ); } - state = dstep_LSB[state][dpath[i]]; + state = dstep_LSB[state][dpath[i]]; move16(); } return; } void RestoreTCQ_fx( - Word16 * magn, - Word16 size, - Word16 *bcount, - Word16 *mbuffer -) + Word16 *magn, + Word16 size, + Word16 *bcount, + Word16 *mbuffer ) { Word16 i, nzpos = 0, flag_g1 = 0; /* calculate actual nz positions */ nzpos = 0; move16(); - FOR ( i = 0; i < size; i++) + FOR( i = 0; i < size; i++ ) { - IF ( magn[i] != 0 ) + IF( magn[i] != 0 ) { - nzpos = add(nzpos, 1); - if ( GT_16(abs_s(magn[i]), 5)) + nzpos = add( nzpos, 1 ); + if ( GT_16( abs_s( magn[i] ), 5 ) ) { flag_g1 = 1; move16(); @@ -1579,21 +1561,21 @@ void RestoreTCQ_fx( } } - IF ( GT_16(nzpos, 1)) + IF( GT_16( nzpos, 1 ) ) { - FOR( i = 0; i < size; i++) + FOR( i = 0; i < size; i++ ) { test(); - IF (flag_g1 == 0 || GE_16(*bcount, 2*TCQ_AMP)) + IF( flag_g1 == 0 || GE_16( *bcount, 2 * TCQ_AMP ) ) { BREAK; } - IF( abs_s(magn[i]) > 0 ) + IF( abs_s( magn[i] ) > 0 ) { magn[i] = mbuffer[*bcount]; move16(); - *bcount = add(*bcount, 1); + *bcount = add( *bcount, 1 ); } } } @@ -1601,48 +1583,47 @@ void RestoreTCQ_fx( return; } void RestoreTCQdec_fx( - Word16 * magn, - Word16 size, - Word16 *bcount, - Word16 *mbuffer -) + Word16 *magn, + Word16 size, + Word16 *bcount, + Word16 *mbuffer ) { Word16 i, nzpos = 0, flag_g1 = 0; /* calculate actual nz positions */ nzpos = 0; move16(); - FOR ( i = 0; i < size; i++) + FOR( i = 0; i < size; i++ ) { IF( magn[i] != 0 ) { - nzpos = add(nzpos, 1); - if ( GT_16(abs_s(magn[i]), 1)) + nzpos = add( nzpos, 1 ); + if ( GT_16( abs_s( magn[i] ), 1 ) ) { flag_g1 = 1; move16(); } - magn[i] = extract_l(L_mult0(magn[i], 5)); + magn[i] = extract_l( L_mult0( magn[i], 5 ) ); } } - IF( GT_16(nzpos, 1)) + IF( GT_16( nzpos, 1 ) ) { - FOR ( i = 0; i < size; i++) + FOR( i = 0; i < size; i++ ) { test(); - IF (!(flag_g1 && LT_16(*bcount, 2*TCQ_AMP))) + IF( !( flag_g1 && LT_16( *bcount, 2 * TCQ_AMP ) ) ) { BREAK; } - IF ( magn[i] != 0 ) + IF( magn[i] != 0 ) { - mbuffer[*bcount] = add(magn[i], mbuffer[*bcount]); + mbuffer[*bcount] = add( magn[i], mbuffer[*bcount] ); move16(); magn[i] = mbuffer[*bcount]; move16(); - *bcount = add(*bcount, 1); + *bcount = add( *bcount, 1 ); } } } @@ -1651,36 +1632,33 @@ void RestoreTCQdec_fx( } void InitLSBTCQ_fx( - Word16 *bcount -) + Word16 *bcount ) { *bcount = 0; move16(); return; } -void SaveTCQdata_fx( - PARCODEC arInst, - Word16 *dpath, - Word16 bcount -) +void SaveTCQdata_fx( + PARCODEC arInst, + Word16 *dpath, + Word16 bcount ) { Word16 i; - FOR ( i = 0; i < bcount; i++) + FOR( i = 0; i < bcount; i++ ) { - ar_encode_uniform_fx( arInst, dpath[i], 1); + ar_encode_uniform_fx( arInst, dpath[i], 1 ); } return; } -void LoadTCQdata_fx( - PARCODEC arInst, - Word16 *dpath, - Word16 bcount -) +void LoadTCQdata_fx( + PARCODEC arInst, + Word16 *dpath, + Word16 bcount ) { Word32 i; - FOR ( i = 0; i < bcount; i++) + FOR( i = 0; i < bcount; i++ ) { dpath[i] = ar_decode_fx( arInst, uniform_model ); } @@ -1690,11 +1668,10 @@ void LoadTCQdata_fx( Word32 encode_position_ari_fx( - PARCODEC parenc, - Word16* quants, - Word16 size, - Word32* est_bits_frame_fx -) + PARCODEC parenc, + Word16 *quants, + Word16 size, + Word32 *est_bits_frame_fx ) { Word16 i, tmp; Word16 nz = 0, pulses = 0; @@ -1702,54 +1679,53 @@ Word32 encode_position_ari_fx( Word16 model_num_nz[TCQ_MAX_BAND_SIZE]; Word16 *cur_quants = quants; Word16 integer, frac; - Word32 /*est_bits_frame_fx, */btcq_fx = 0, bits_fx = 0, pnzp_fx; + Word32 /*est_bits_frame_fx, */ btcq_fx = 0, bits_fx = 0, pnzp_fx; Word32 cp, scp, fxone, fxp1; Word16 pos; fxone = 32768; move32(); - fxp1 = 512*32768; + fxp1 = 512 * 32768; move32(); - set16_fx( prob, 0, TCQ_MAX_BAND_SIZE ); set16_fx( model_num_nz, 0, TCQ_MAX_BAND_SIZE ); - FOR (i = 0; i < size; i ++) + FOR( i = 0; i < size; i++ ) { - pulses = add(pulses, abs_s(cur_quants[i])); - if (cur_quants[i] != 0) + pulses = add( pulses, abs_s( cur_quants[i] ) ); + if ( cur_quants[i] != 0 ) { - nz = add(nz, 1); + nz = add( nz, 1 ); } } - btcq_fx = GetBitsFromPulses_fx(pulses, size); + btcq_fx = GetBitsFromPulses_fx( pulses, size ); /* Estimate TCQ bits */ - bits_fx = L_sub(table_logcum_fx[size + 1], L_add(table_logcum_fx[nz + 1], table_logcum_fx[size - nz + 1])); - bits_fx = L_add(bits_fx, L_sub(btcq_fx, L_sub(table_logcum_fx[size + 1], L_add(table_logcum_fx[nz + 1], table_logcum_fx[size - nz + 1])))); - bits_fx = L_sub(bits_fx, L_sub(table_logcum_fx[pulses], L_add(table_logcum_fx[nz], table_logcum_fx[pulses - (nz - 1)]))); - bits_fx = L_sub(bits_fx, nz); - *est_bits_frame_fx = L_add(*est_bits_frame_fx, bits_fx); + bits_fx = L_sub( table_logcum_fx[size + 1], L_add( table_logcum_fx[nz + 1], table_logcum_fx[size - nz + 1] ) ); + bits_fx = L_add( bits_fx, L_sub( btcq_fx, L_sub( table_logcum_fx[size + 1], L_add( table_logcum_fx[nz + 1], table_logcum_fx[size - nz + 1] ) ) ) ); + bits_fx = L_sub( bits_fx, L_sub( table_logcum_fx[pulses], L_add( table_logcum_fx[nz], table_logcum_fx[pulses - ( nz - 1 )] ) ) ); + bits_fx = L_sub( bits_fx, nz ); + *est_bits_frame_fx = L_add( *est_bits_frame_fx, bits_fx ); /*caculate the #nz probability */ - tmp = s_min(pulses, size); - FOR (i = 0; i < tmp; i++) + tmp = s_min( pulses, size ); + FOR( i = 0; i < tmp; i++ ) { - pnzp_fx = L_sub(L_deposit_h(add(i, 1)), btcq_fx); - pnzp_fx = L_add(pnzp_fx, L_add(L_sub(table_logcum_fx[size + 1], L_add(table_logcum_fx[i + 2], table_logcum_fx[size - i])), - L_sub(table_logcum_fx[pulses], L_add(table_logcum_fx[i + 1], table_logcum_fx[pulses - i])))); - pnzp_fx = L_add(pnzp_fx, 917498);/*16 */ - IF( GT_32( pnzp_fx, 0)) + pnzp_fx = L_sub( L_deposit_h( add( i, 1 ) ), btcq_fx ); + pnzp_fx = L_add( pnzp_fx, L_add( L_sub( table_logcum_fx[size + 1], L_add( table_logcum_fx[i + 2], table_logcum_fx[size - i] ) ), + L_sub( table_logcum_fx[pulses], L_add( table_logcum_fx[i + 1], table_logcum_fx[pulses - i] ) ) ) ); + pnzp_fx = L_add( pnzp_fx, 917498 ); /*16 */ + IF( GT_32( pnzp_fx, 0 ) ) { - integer = extract_h(pnzp_fx); - frac = extract_l(L_shr(L_sub(pnzp_fx, L_deposit_h(integer)), 1));/*15 */ - prob[i] = extract_h(L_shl(Pow2(integer, frac), 16));/*0 */ + integer = extract_h( pnzp_fx ); + frac = extract_l( L_shr( L_sub( pnzp_fx, L_deposit_h( integer ) ), 1 ) ); /*15 */ + prob[i] = extract_h( L_shl( Pow2( integer, frac ), 16 ) ); /*0 */ /*zero probability will incur problems in ar_make_model() */ - if (prob[i] == 0) + if ( prob[i] == 0 ) { prob[i] = 1; move16(); @@ -1762,42 +1738,42 @@ Word32 encode_position_ari_fx( } } - ar_make_model_fx(prob, model_num_nz, s_min(pulses, size)); + ar_make_model_fx( prob, model_num_nz, s_min( pulses, size ) ); - IF (GT_16(nz, 1)) + IF( GT_16( nz, 1 ) ) { - ar_encode_fx(parenc, model_num_nz, nz - 1);/*encode #nz */ - scp = L_add(fxp1, 0); + ar_encode_fx( parenc, model_num_nz, nz - 1 ); /*encode #nz */ + scp = L_add( fxp1, 0 ); pos = 0; move16(); - FOR( i = 0; i < size; i++) + FOR( i = 0; i < size; i++ ) { - IF (nz <= 0) + IF( nz <= 0 ) { BREAK; } - IF( nz == (size - i) ) + IF( nz == ( size - i ) ) { - cp = L_deposit_l(0); + cp = L_deposit_l( 0 ); } ELSE { - cp = L_sub( fxone, div_l( L_deposit_h(nz), (size - i)) ); + cp = L_sub( fxone, div_l( L_deposit_h( nz ), ( size - i ) ) ); } - scp = Mult_32_16( scp, extract_l(cp) ); - model_num_nz[pos+1] = round_fx( L_shl( scp, 6) ); + scp = Mult_32_16( scp, extract_l( cp ) ); + model_num_nz[pos + 1] = round_fx( L_shl( scp, 6 ) ); test(); test(); - IF( (model_num_nz[pos+1] == 0 && scp > 0) || model_num_nz[pos] == model_num_nz[pos+1] ) + IF( ( model_num_nz[pos + 1] == 0 && scp > 0 ) || model_num_nz[pos] == model_num_nz[pos + 1] ) { - model_num_nz[pos+1] = 0; + model_num_nz[pos + 1] = 0; move16(); ar_encode_fx( parenc, model_num_nz, pos ); i--; move16(); - scp = L_add(fxp1, 0); + scp = L_add( fxp1, 0 ); pos = 0; move16(); CONTINUE; @@ -1808,7 +1784,7 @@ Word32 encode_position_ari_fx( ar_encode_fx( parenc, model_num_nz, pos ); pos = 0; move16(); - scp = L_add(fxp1, 0); + scp = L_add( fxp1, 0 ); nz--; move16(); } @@ -1819,20 +1795,20 @@ Word32 encode_position_ari_fx( } } } - ELSE IF (EQ_16(nz, 1)) + ELSE IF( EQ_16( nz, 1 ) ) { - IF (GT_16(pulses, 1)) + IF( GT_16( pulses, 1 ) ) { /*temp -= log2_f((float)(model_num_nz[nz-1] - model_num_nz[nz]) / MAX_AR_FREQ); */ - ar_encode_fx(parenc, model_num_nz, 0);/*encode #nz */ + ar_encode_fx( parenc, model_num_nz, 0 ); /*encode #nz */ } pos = 0; move16(); - FOR( i = 0; i < size; i++) + FOR( i = 0; i < size; i++ ) { - model_num_nz[i+1] = round_fx( L_shr( L_deposit_h( div_l( L_deposit_h(size - i - 1), size)), 1) ); + model_num_nz[i + 1] = round_fx( L_shr( L_deposit_h( div_l( L_deposit_h( size - i - 1 ), size ) ), 1 ) ); - if( cur_quants[i] != 0 ) + if ( cur_quants[i] != 0 ) { pos = i; move16(); @@ -1843,47 +1819,46 @@ Word32 encode_position_ari_fx( return bits_fx; } Word32 encode_magnitude_usq_fx( - ARCODEC* parenc, - Word16* magn_fx, - Word16 size, - Word16 npulses, - Word16 nzpos, - Word32* est_frame_bits_fx -) + ARCODEC *parenc, + Word16 *magn_fx, + Word16 size, + Word16 npulses, + Word16 nzpos, + Word32 *est_frame_bits_fx ) { Word16 i, j, k, tmp, magnp, magnzp; Word16 magn_position[MAX_PULSES]; - Word32 /*est_frame_bits_fx, */bits_fx; + Word32 /*est_frame_bits_fx, */ bits_fx; Word16 pos, model_m[MAX_PULSES + 2]; Word32 fxone, fxp1, cp, scp; fxone = 32768; move32(); - fxp1 = 512*32768; + fxp1 = 512 * 32768; move32(); /*estimate fac bits */ - bits_fx = L_sub(table_logcum_fx[npulses], L_add(table_logcum_fx[nzpos], table_logcum_fx[npulses - nzpos + 1])); - *est_frame_bits_fx = L_add(*est_frame_bits_fx, bits_fx); + bits_fx = L_sub( table_logcum_fx[npulses], L_add( table_logcum_fx[nzpos], table_logcum_fx[npulses - nzpos + 1] ) ); + *est_frame_bits_fx = L_add( *est_frame_bits_fx, bits_fx ); test(); - IF (EQ_16(npulses, nzpos)||EQ_16(nzpos,1)) + IF( EQ_16( npulses, nzpos ) || EQ_16( nzpos, 1 ) ) { return bits_fx; } - magnp = sub(npulses, 1); - magnzp = sub(nzpos, 1); + magnp = sub( npulses, 1 ); + magnzp = sub( nzpos, 1 ); /*generate the binary sequences of magnitudes */ k = 0; move16(); - FOR (i = 0; i < size; i++) + FOR( i = 0; i < size; i++ ) { - IF (magn_fx[i] != 0) + IF( magn_fx[i] != 0 ) { - tmp = sub(abs_s(magn_fx[i]), 1); - FOR (j = 0; j < tmp; j++) + tmp = sub( abs_s( magn_fx[i] ), 1 ); + FOR( j = 0; j < tmp; j++ ) { magn_position[k++] = 0; move16(); @@ -1893,36 +1868,36 @@ Word32 encode_magnitude_usq_fx( } } - set16_fx( model_m, 0, MAX_PULSES + 2); - scp = L_add(fxp1, 0); + set16_fx( model_m, 0, MAX_PULSES + 2 ); + scp = L_add( fxp1, 0 ); model_m[0] = MAX_AR_FREQ; move16(); pos = 0; move16(); - tmp = sub(npulses, 1); + tmp = sub( npulses, 1 ); FOR( i = 0; i < tmp; i++ ) { - IF (magnzp <= 0) + IF( magnzp <= 0 ) { BREAK; } IF( magnzp == magnp ) { - cp = L_deposit_l(0); + cp = L_deposit_l( 0 ); } ELSE { - cp = L_sub( fxone, div_l( L_deposit_h(magnzp), magnp) ); + cp = L_sub( fxone, div_l( L_deposit_h( magnzp ), magnp ) ); } - scp = Mult_32_16( scp, extract_l(cp) ); - model_m[pos+1] = round_fx( L_shl( scp, 6) ); + scp = Mult_32_16( scp, extract_l( cp ) ); + model_m[pos + 1] = round_fx( L_shl( scp, 6 ) ); test(); test(); - IF( (model_m[pos+1] == 0 && scp > 0) || model_m[pos] == model_m[pos+1] ) + IF( ( model_m[pos + 1] == 0 && scp > 0 ) || model_m[pos] == model_m[pos + 1] ) { - model_m[pos+1] = 0; + model_m[pos + 1] = 0; move16(); ar_encode_fx( parenc, model_m, pos ); @@ -1930,7 +1905,7 @@ Word32 encode_magnitude_usq_fx( move16(); i--; move16(); - scp = L_add(fxp1, 0); + scp = L_add( fxp1, 0 ); CONTINUE; } @@ -1941,7 +1916,7 @@ Word32 encode_magnitude_usq_fx( move16(); magnzp--; move16(); - scp = L_add(fxp1, 0); + scp = L_add( fxp1, 0 ); } ELSE { @@ -1955,55 +1930,54 @@ Word32 encode_magnitude_usq_fx( return bits_fx; } Word32 encode_magnitude_tcq_fx( - ARCODEC* parenc, - Word16* magn_fx, - Word16 size, - Word16 npulses, - Word16 nzpos, - Word32* savedstates, - Word32* est_frame_bits_fx -) + ARCODEC *parenc, + Word16 *magn_fx, + Word16 size, + Word16 npulses, + Word16 nzpos, + Word32 *savedstates, + Word32 *est_frame_bits_fx ) { - Word32 tcq_bits_fx, bits_fx/*, est_frame_bits_fx*/; + Word32 tcq_bits_fx, bits_fx /*, est_frame_bits_fx*/; Word16 prob0_fx, prob1_fx, num, denum, quantum1_fx, quantum2_fx; Word16 exp, exp1, exp2; Word16 i, j; Word32 st; - Word16 magn_mode[3] = {MAX_AR_FREQ, 0, 0}; + Word16 magn_mode[3] = { MAX_AR_FREQ, 0, 0 }; - Word16 leftp = npulses;/*pulsesnum; */ - Word16 leftnz = nzpos;/*nzpos; */ + Word16 leftp = npulses; /*pulsesnum; */ + Word16 leftnz = nzpos; /*nzpos; */ move16(); move16(); - bits_fx = L_deposit_l(0); - tcq_bits_fx = L_sub(table_logcum_fx[npulses], L_add(table_logcum_fx[nzpos], table_logcum_fx[npulses - (nzpos - 1)])); - *est_frame_bits_fx = L_add(*est_frame_bits_fx, tcq_bits_fx); + bits_fx = L_deposit_l( 0 ); + tcq_bits_fx = L_sub( table_logcum_fx[npulses], L_add( table_logcum_fx[nzpos], table_logcum_fx[npulses - ( nzpos - 1 )] ) ); + *est_frame_bits_fx = L_add( *est_frame_bits_fx, tcq_bits_fx ); test(); - IF (EQ_16(nzpos, npulses)||EQ_16(nzpos,1)) + IF( EQ_16( nzpos, npulses ) || EQ_16( nzpos, 1 ) ) { return bits_fx; } - st = L_deposit_l(0); - FOR ( i = 0; i < size; i++) + st = L_deposit_l( 0 ); + FOR( i = 0; i < size; i++ ) { - IF (LE_16(leftnz, 1)) + IF( LE_16( leftnz, 1 ) ) { BREAK; } - st = L_add(savedstates[i], 0); - IF (magn_fx[i] != 0) + st = L_add( savedstates[i], 0 ); + IF( magn_fx[i] != 0 ) { - FOR ( j = 0; j < leftp; j++) + FOR( j = 0; j < leftp; j++ ) { /*calculate the two path probs point to next two states */ - num = sub(leftnz, 1); - denum = sub(leftp, add(j, 0x1)); - IF (GE_16(num, denum)) + num = sub( leftnz, 1 ); + denum = sub( leftp, add( j, 0x1 ) ); + IF( GE_16( num, denum ) ) { prob1_fx = MAX_16; move16(); @@ -2012,20 +1986,20 @@ Word32 encode_magnitude_tcq_fx( } ELSE { - exp1 = sub(norm_s(num), 1); - exp2 = norm_s(denum); - prob1_fx = div_s(shl(num, exp1), shl(denum, exp2));/*15 + exp1 - exp2 */ + exp1 = sub( norm_s( num ), 1 ); + exp2 = norm_s( denum ); + prob1_fx = div_s( shl( num, exp1 ), shl( denum, exp2 ) ); /*15 + exp1 - exp2 */ exp = 15 + exp1 - exp2; move16(); - prob1_fx = shl(prob1_fx, sub(15, exp)); - prob0_fx = sub(MAX_16, prob1_fx); + prob1_fx = shl( prob1_fx, sub( 15, exp ) ); + prob0_fx = sub( MAX_16, prob1_fx ); } - quantum1_fx = quantize_fx(shl(add(j, 1), 10), ddec[st][0]); - quantum2_fx = quantize_fx(shl(add(j, 1), 10), ddec[st][1]); + quantum1_fx = quantize_fx( shl( add( j, 1 ), 10 ), ddec[st][0] ); + quantum2_fx = quantize_fx( shl( add( j, 1 ), 10 ), ddec[st][1] ); test(); - IF (NE_16(quantum1_fx, add(j, 1))&&NE_16(quantum2_fx,add(j,1))) + IF( NE_16( quantum1_fx, add( j, 1 ) ) && NE_16( quantum2_fx, add( j, 1 ) ) ) { prob0_fx = MAX_16; move16(); @@ -2034,21 +2008,21 @@ Word32 encode_magnitude_tcq_fx( } test(); - IF (EQ_16(prob0_fx, MAX_16)||EQ_16(prob1_fx,MAX_16)) + IF( EQ_16( prob0_fx, MAX_16 ) || EQ_16( prob1_fx, MAX_16 ) ) { CONTINUE; } - magn_mode[1] = mult(prob1_fx, MAX_AR_FREQ); - IF (LT_16(j, sub(abs_s(magn_fx[i]), 1))) + magn_mode[1] = mult( prob1_fx, MAX_AR_FREQ ); + IF( LT_16( j, sub( abs_s( magn_fx[i] ), 1 ) ) ) { - ar_encode_fx(parenc, magn_mode, 0); + ar_encode_fx( parenc, magn_mode, 0 ); } ELSE { - IF (sub(leftp, j) > leftnz) + IF( sub( leftp, j ) > leftnz ) { - ar_encode_fx(parenc, magn_mode, 1); + ar_encode_fx( parenc, magn_mode, 1 ); } BREAK; } @@ -2056,45 +2030,43 @@ Word32 encode_magnitude_tcq_fx( leftnz--; move16(); - leftp = sub(leftp, abs_s( magn_fx[i] )); + leftp = sub( leftp, abs_s( magn_fx[i] ) ); } } return bits_fx; } Word32 encode_signs_fx( - ARCODEC* parenc, - Word16* magn, - Word16 size, - Word16 npos, - Word32* est_frame_bits_fx -) + ARCODEC *parenc, + Word16 *magn, + Word16 size, + Word16 npos, + Word32 *est_frame_bits_fx ) { Word32 i, sign; - *est_frame_bits_fx = L_add(*est_frame_bits_fx, L_deposit_h(npos)); - FOR (i = 0; i < size; i++) + *est_frame_bits_fx = L_add( *est_frame_bits_fx, L_deposit_h( npos ) ); + FOR( i = 0; i < size; i++ ) { - IF (magn[i] != 0) + IF( magn[i] != 0 ) { - sign = L_deposit_l(0); - if (magn[i] > 0) + sign = L_deposit_l( 0 ); + if ( magn[i] > 0 ) { - sign = L_deposit_l(1); + sign = L_deposit_l( 1 ); } - ar_encode_uniform_fx(parenc, sign, 1); + ar_encode_uniform_fx( parenc, sign, 1 ); } } - return L_deposit_h(npos); + return L_deposit_h( npos ); } void decode_position_ari_fx( - PARCODEC pardec, - Word16 size, - Word16 npulses, - Word16* nz, - Word16* position -) + PARCODEC pardec, + Word16 size, + Word16 npulses, + Word16 *nz, + Word16 *position ) { Word16 i, tmp, nzp; Word16 mode_num_nz[TCQ_MAX_BAND_SIZE]; @@ -2107,7 +2079,7 @@ void decode_position_ari_fx( fxone = 32768; move32(); - fxp1 = 512*32768; + fxp1 = 512 * 32768; move32(); temppos = 0; move16(); @@ -2117,30 +2089,30 @@ void decode_position_ari_fx( set16_fx( mode_num_nz, 0, TCQ_MAX_BAND_SIZE ); set16_fx( prob, 0, TCQ_MAX_BAND_SIZE ); - FOR (i = 0; i < size; i++) + FOR( i = 0; i < size; i++ ) { position[i] = 0; move16(); } - IF (GT_32(npulses, 1)) + IF( GT_32( npulses, 1 ) ) { - btcq_fx = GetBitsFromPulses_fx(npulses, size); - tmp = s_min(npulses, size); - FOR (i = 0; i < tmp; i++) + btcq_fx = GetBitsFromPulses_fx( npulses, size ); + tmp = s_min( npulses, size ); + FOR( i = 0; i < tmp; i++ ) { /*calculate the probability of #nz */ - pnzp_fx = L_sub(L_deposit_h(add(i, 1)), btcq_fx); - pnzp_fx = L_add(pnzp_fx, L_add(L_sub(table_logcum_fx[size + 1], L_add(table_logcum_fx[i + 2], table_logcum_fx[size - i])), - L_sub(table_logcum_fx[npulses], L_add(table_logcum_fx[i + 1], table_logcum_fx[npulses - i])))); - pnzp_fx = L_add(pnzp_fx, 917498);/*16 */ - IF( GT_32( pnzp_fx, 0)) + pnzp_fx = L_sub( L_deposit_h( add( i, 1 ) ), btcq_fx ); + pnzp_fx = L_add( pnzp_fx, L_add( L_sub( table_logcum_fx[size + 1], L_add( table_logcum_fx[i + 2], table_logcum_fx[size - i] ) ), + L_sub( table_logcum_fx[npulses], L_add( table_logcum_fx[i + 1], table_logcum_fx[npulses - i] ) ) ) ); + pnzp_fx = L_add( pnzp_fx, 917498 ); /*16 */ + IF( GT_32( pnzp_fx, 0 ) ) { - integer = extract_h(pnzp_fx); - frac = extract_l(L_shr(L_sub(pnzp_fx, L_deposit_h(integer)), 1));/*15 */ - prob[i] = extract_h(L_shl(Pow2(integer, frac), 16));/*0 */ - if (prob[i] == 0) + integer = extract_h( pnzp_fx ); + frac = extract_l( L_shr( L_sub( pnzp_fx, L_deposit_h( integer ) ), 1 ) ); /*15 */ + prob[i] = extract_h( L_shl( Pow2( integer, frac ), 16 ) ); /*0 */ + if ( prob[i] == 0 ) { prob[i] = 1; move16(); @@ -2153,20 +2125,20 @@ void decode_position_ari_fx( } } - ar_make_model_fx(prob, mode_num_nz, s_min(npulses, size)); - *nz = add(1, ar_decode_fx(pardec, mode_num_nz));/*get #nz */ + ar_make_model_fx( prob, mode_num_nz, s_min( npulses, size ) ); + *nz = add( 1, ar_decode_fx( pardec, mode_num_nz ) ); /*get #nz */ nzp = *nz; move16(); IF( nzp == 1 ) { mode_num_nz[0] = MAX_AR_FREQ; move16(); - FOR (i = 0; i < size; i ++) + FOR( i = 0; i < size; i++ ) { - mode_num_nz[i+1] = round_fx( L_shr( L_deposit_h( div_l( L_deposit_h(size - i - 1), size)), 1) ); + mode_num_nz[i + 1] = round_fx( L_shr( L_deposit_h( div_l( L_deposit_h( size - i - 1 ), size ) ), 1 ) ); } - position[ ar_decode_fx(pardec, mode_num_nz) ] = 1; + position[ar_decode_fx( pardec, mode_num_nz )] = 1; move16(); } ELSE @@ -2176,43 +2148,43 @@ void decode_position_ari_fx( FOR( ; nzp > 0; nzp-- ) { - scp = L_add(fxp1, 0); - temppos = 0; + scp = L_add( fxp1, 0 ); + temppos = 0; move16(); storepos = 0; move16(); - FOR( i = stpos; i < size; i++) + FOR( i = stpos; i < size; i++ ) { ovrflag = 0; move16(); - IF( nzp == (size - i) ) + IF( nzp == ( size - i ) ) { - cp = L_deposit_l(0); + cp = L_deposit_l( 0 ); } ELSE { - cp = L_sub( fxone, div_l( L_deposit_h(nzp), (size - i)) ); + cp = L_sub( fxone, div_l( L_deposit_h( nzp ), ( size - i ) ) ); } - scp = Mult_32_16( scp, extract_l(cp) ); - mode_num_nz[i+1-storepos-stpos] = round_fx( L_shl( scp, 6) ); + scp = Mult_32_16( scp, extract_l( cp ) ); + mode_num_nz[i + 1 - storepos - stpos] = round_fx( L_shl( scp, 6 ) ); test(); test(); - IF( (mode_num_nz[i+1-storepos-stpos] == 0 && scp > 0) || mode_num_nz[i-storepos-stpos] == mode_num_nz[i+1-storepos-stpos] ) + IF( ( mode_num_nz[i + 1 - storepos - stpos] == 0 && scp > 0 ) || mode_num_nz[i - storepos - stpos] == mode_num_nz[i + 1 - storepos - stpos] ) { - mode_num_nz[i+1-storepos-stpos] = 0; + mode_num_nz[i + 1 - storepos - stpos] = 0; move16(); ovrflag = 1; move16(); - temppos = ar_decode_fx(pardec, mode_num_nz); + temppos = ar_decode_fx( pardec, mode_num_nz ); move16(); storepos += temppos; move16(); - scp = L_add(fxp1, 0); + scp = L_add( fxp1, 0 ); - IF( temppos == i-stpos) /* esc transmitted */ + IF( temppos == i - stpos ) /* esc transmitted */ { i--; move16(); @@ -2225,7 +2197,7 @@ void decode_position_ari_fx( } IF( !ovrflag ) { - pos = ar_decode_fx(pardec, mode_num_nz) + storepos; + pos = ar_decode_fx( pardec, mode_num_nz ) + storepos; move16(); } ELSE @@ -2234,14 +2206,14 @@ void decode_position_ari_fx( move16(); } - position[ stpos + pos] = 1; + position[stpos + pos] = 1; move16(); stpos += pos + 1; move16(); } } } - ELSE IF (EQ_32(npulses, 1)) + ELSE IF( EQ_32( npulses, 1 ) ) { *nz = npulses; move16(); @@ -2249,12 +2221,12 @@ void decode_position_ari_fx( move16(); mode_num_nz[0] = MAX_AR_FREQ; move16(); - FOR (i = 0; i < size; i ++) + FOR( i = 0; i < size; i++ ) { - mode_num_nz[i+1] = round_fx( L_shr( L_deposit_h( div_l( L_deposit_h(size - i - 1), size)), 1) ); + mode_num_nz[i + 1] = round_fx( L_shr( L_deposit_h( div_l( L_deposit_h( size - i - 1 ), size ) ), 1 ) ); } - position[ ar_decode_fx(pardec, mode_num_nz) ] = 1; + position[ar_decode_fx( pardec, mode_num_nz )] = 1; move16(); } ELSE @@ -2266,39 +2238,38 @@ void decode_position_ari_fx( return; } void decode_magnitude_usq_fx( - ARCODEC* pardec, - Word16 size, - Word16 npulses, - Word16 nzpos, - Word16* positions, - Word16* out -) + ARCODEC *pardec, + Word16 size, + Word16 npulses, + Word16 nzpos, + Word16 *positions, + Word16 *out ) { Word16 i, magnp, magnzp; Word16 magns[TCQ_MAX_BAND_SIZE], magncout = 0; - Word16 storemagn, ovrflag = 0, pos, tempmagn = 0, mmodel[MAX_PULSES+2]; + Word16 storemagn, ovrflag = 0, pos, tempmagn = 0, mmodel[MAX_PULSES + 2]; Word32 cp, scp, fxone, fxp1; fxone = 32768; move32(); - fxp1 = 512*32768; + fxp1 = 512 * 32768; move32(); set16_fx( magns, 1, TCQ_MAX_BAND_SIZE ); - IF (EQ_16(nzpos, npulses)) + IF( EQ_16( nzpos, npulses ) ) { - FOR (i = 0; i < size; i++) + FOR( i = 0; i < size; i++ ) { out[i] = positions[i]; move16(); } return; } - ELSE IF (EQ_16(nzpos, 1)) + ELSE IF( EQ_16( nzpos, 1 ) ) { - FOR (i = 0; i < size; i++) + FOR( i = 0; i < size; i++ ) { - IF ( positions[i] != 0 ) + IF( positions[i] != 0 ) { out[i] = npulses; move16(); @@ -2307,39 +2278,39 @@ void decode_magnitude_usq_fx( } } - magnzp = sub(nzpos, 1); - magnp = sub(npulses, 1); + magnzp = sub( nzpos, 1 ); + magnp = sub( npulses, 1 ); magncout = 0; move16(); set16_fx( out, 0, size ); - set16_fx( mmodel, 0, MAX_PULSES+2 ); + set16_fx( mmodel, 0, MAX_PULSES + 2 ); mmodel[0] = MAX_AR_FREQ; move16(); magncout = 0; move16(); - FOR( pos = 0; pos < size; pos++) + FOR( pos = 0; pos < size; pos++ ) { - scp = L_add(fxp1, 0); - IF( positions[pos] != 0) + scp = L_add( fxp1, 0 ); + IF( positions[pos] != 0 ) { storemagn = 0; move16(); - FOR( i = 0; i < magnp; i++) + FOR( i = 0; i < magnp; i++ ) { ovrflag = 0; move16(); - IF( magnzp == (magnp-i) ) + IF( magnzp == ( magnp - i ) ) { - cp = L_deposit_l(0); + cp = L_deposit_l( 0 ); } ELSE { - cp = L_sub( fxone, div_l( L_deposit_h(magnzp), magnp-i) ); + cp = L_sub( fxone, div_l( L_deposit_h( magnzp ), magnp - i ) ); } IF( cp == fxone ) @@ -2347,14 +2318,14 @@ void decode_magnitude_usq_fx( BREAK; } - scp = Mult_32_16( scp, extract_l(cp) ); - mmodel[i+1-storemagn] = round_fx( L_shl( scp, 6) ); + scp = Mult_32_16( scp, extract_l( cp ) ); + mmodel[i + 1 - storemagn] = round_fx( L_shl( scp, 6 ) ); test(); test(); - IF( (mmodel[i+1- storemagn] == 0 && scp > 0) || mmodel[i- storemagn] == mmodel[i+1- storemagn] ) + IF( ( mmodel[i + 1 - storemagn] == 0 && scp > 0 ) || mmodel[i - storemagn] == mmodel[i + 1 - storemagn] ) { - mmodel[i+1-storemagn] = 0; + mmodel[i + 1 - storemagn] = 0; move16(); /* read data */ tempmagn = ar_decode_fx( pardec, mmodel ); @@ -2371,7 +2342,7 @@ void decode_magnitude_usq_fx( ELSE { /* esc code */ - scp = L_add(fxp1, 0); + scp = L_add( fxp1, 0 ); i--; move16(); } @@ -2395,11 +2366,11 @@ void decode_magnitude_usq_fx( magncout++; move16(); - IF (magnzp == 0) /* last magnitude generation */ + IF( magnzp == 0 ) /* last magnitude generation */ { - FOR( pos = add(pos,1); pos < size; pos++) + FOR( pos = add( pos, 1 ); pos < size; pos++ ) { - IF( positions[pos] != 0) + IF( positions[pos] != 0 ) { out[magncout] = magnp + 1; move16(); @@ -2414,9 +2385,9 @@ void decode_magnitude_usq_fx( } } } - ELSE IF(magnzp == magnp) /* rest magnitudes generation */ + ELSE IF( magnzp == magnp ) /* rest magnitudes generation */ { - FOR( pos = add(pos,1); pos < size; pos++) + FOR( pos = add( pos, 1 ); pos < size; pos++ ) { out[magncout] = positions[pos]; move16(); @@ -2438,31 +2409,30 @@ void decode_magnitude_usq_fx( return; } void decode_mangitude_tcq_fx( - ARCODEC* pardec, - Word16 size, - Word16 npulses, - Word16 nzpos, - Word16* positions, - Word16* out, - Word32* surplus_fx -) + ARCODEC *pardec, + Word16 size, + Word16 npulses, + Word16 nzpos, + Word16 *positions, + Word16 *out, + Word32 *surplus_fx ) { - Word32 tcq_bits_fx, bits_fx/*, surplus_fx*/; + Word32 tcq_bits_fx, bits_fx /*, surplus_fx*/; Word16 prob0_fx, prob1_fx, num, denum, quantum1_fx, quantum2_fx; Word16 exp, exp1, exp2, tmp16; Word32 tmp32; Word16 i, j, symbol, st; - Word16 leftp = npulses;/*pulsesnum; */ - Word16 leftnz = nzpos; /*nzpos; */ - Word16 magn_mode[3] = {MAX_AR_FREQ, 0, 0}; + Word16 leftp = npulses; /*pulsesnum; */ + Word16 leftnz = nzpos; /*nzpos; */ + Word16 magn_mode[3] = { MAX_AR_FREQ, 0, 0 }; - bits_fx = L_deposit_l(0); - tcq_bits_fx = L_sub(table_logcum_fx[npulses], L_add(table_logcum_fx[nzpos], table_logcum_fx[npulses - (nzpos - 1)])); + bits_fx = L_deposit_l( 0 ); + tcq_bits_fx = L_sub( table_logcum_fx[npulses], L_add( table_logcum_fx[nzpos], table_logcum_fx[npulses - ( nzpos - 1 )] ) ); - IF (EQ_16(nzpos, npulses)) + IF( EQ_16( nzpos, npulses ) ) { - FOR (i = 0; i < size; i++) + FOR( i = 0; i < size; i++ ) { out[i] = positions[i]; move16(); @@ -2470,11 +2440,11 @@ void decode_mangitude_tcq_fx( return; } - ELSE IF (EQ_16(nzpos, 1)) + ELSE IF( EQ_16( nzpos, 1 ) ) { - FOR (i = 0; i < size; i++) + FOR( i = 0; i < size; i++ ) { - IF ( positions[i] != 0 ) + IF( positions[i] != 0 ) { out[i] = npulses; move16(); @@ -2484,24 +2454,24 @@ void decode_mangitude_tcq_fx( } st = 0; move16(); - FOR (i = 0; i < size; i++) + FOR( i = 0; i < size; i++ ) { - IF (LE_16(leftnz, 1)) + IF( LE_16( leftnz, 1 ) ) { BREAK; } out[i] = positions[i]; - IF (positions[i] != 0) + IF( positions[i] != 0 ) { /*generate the trellis path */ symbol = 0; move16(); - FOR (j = 0; j < leftp; j++) + FOR( j = 0; j < leftp; j++ ) { - num = sub(leftnz, 1); - denum = sub(leftp, add(j, 1)); - IF (GE_16(num, denum)) + num = sub( leftnz, 1 ); + denum = sub( leftp, add( j, 1 ) ); + IF( GE_16( num, denum ) ) { prob1_fx = MAX_16; move16(); @@ -2510,24 +2480,24 @@ void decode_mangitude_tcq_fx( } ELSE { - exp1 = sub(norm_s(num), 1); - exp2 = norm_s(denum); - prob1_fx = div_s(shl(num, exp1), shl(denum, exp2));/*15 + exp1 - exp2 */ + exp1 = sub( norm_s( num ), 1 ); + exp2 = norm_s( denum ); + prob1_fx = div_s( shl( num, exp1 ), shl( denum, exp2 ) ); /*15 + exp1 - exp2 */ exp = 15 + exp1 - exp2; - prob1_fx = shl(prob1_fx, sub(15, exp)); - prob0_fx = sub(MAX_16, prob1_fx); + prob1_fx = shl( prob1_fx, sub( 15, exp ) ); + prob0_fx = sub( MAX_16, prob1_fx ); } - IF (EQ_32(sub(leftp, j), leftnz)) + IF( EQ_32( sub( leftp, j ), leftnz ) ) { - symbol = add(j, 1); + symbol = add( j, 1 ); BREAK; } - quantum1_fx = quantize_fx(shl(add(j, 1), 10), ddec[st][0]); - quantum2_fx = quantize_fx(shl(add(j, 1), 10), ddec[st][1]); + quantum1_fx = quantize_fx( shl( add( j, 1 ), 10 ), ddec[st][0] ); + quantum2_fx = quantize_fx( shl( add( j, 1 ), 10 ), ddec[st][1] ); test(); - IF (NE_16(quantum1_fx, add(j, 1))&&NE_16(quantum2_fx,add(j,1))) + IF( NE_16( quantum1_fx, add( j, 1 ) ) && NE_16( quantum2_fx, add( j, 1 ) ) ) { prob0_fx = MAX_16; move16(); @@ -2536,45 +2506,45 @@ void decode_mangitude_tcq_fx( } test(); - IF (EQ_16(prob0_fx, MAX_16)||EQ_16(prob1_fx,MAX_16)) + IF( EQ_16( prob0_fx, MAX_16 ) || EQ_16( prob1_fx, MAX_16 ) ) { - symbol = add(j, 1); + symbol = add( j, 1 ); CONTINUE; } /*magn_mode[1] = (short)(prob1 * MAX_AR_FREQ); */ - magn_mode[1] = mult(prob1_fx, MAX_AR_FREQ); + magn_mode[1] = mult( prob1_fx, MAX_AR_FREQ ); - IF (ar_decode_fx(pardec, magn_mode)) + IF( ar_decode_fx( pardec, magn_mode ) ) { - exp1 = norm_s(prob1_fx); - tmp32 = L_deposit_h(shl(prob1_fx, exp1));/*exp1 + 15 + 16 */ - tmp16 = Log2_norm_lc(tmp32);/*15 */ - bits_fx = L_sub(bits_fx, L_sub(tmp16, L_shl(add(exp1, 1), 15)));/*15 */ + exp1 = norm_s( prob1_fx ); + tmp32 = L_deposit_h( shl( prob1_fx, exp1 ) ); /*exp1 + 15 + 16 */ + tmp16 = Log2_norm_lc( tmp32 ); /*15 */ + bits_fx = L_sub( bits_fx, L_sub( tmp16, L_shl( add( exp1, 1 ), 15 ) ) ); /*15 */ - symbol = add(j, 1); + symbol = add( j, 1 ); BREAK; } ELSE { - exp1 = norm_s(prob0_fx); - tmp32 = L_deposit_h(shl(prob0_fx, exp1));/*exp1 + 15 + 16 */ - tmp16 = Log2_norm_lc(tmp32);/*15 */ - bits_fx = L_sub(bits_fx, L_sub(tmp16, L_shl(add(exp1, 1), 15)));/*15 */ + exp1 = norm_s( prob0_fx ); + tmp32 = L_deposit_h( shl( prob0_fx, exp1 ) ); /*exp1 + 15 + 16 */ + tmp16 = Log2_norm_lc( tmp32 ); /*15 */ + bits_fx = L_sub( bits_fx, L_sub( tmp16, L_shl( add( exp1, 1 ), 15 ) ) ); /*15 */ } } out[i] = symbol; move16(); /*leftp -= symbol; */ - leftp = sub(leftp, symbol); - leftnz = sub(leftnz, 1); + leftp = sub( leftp, symbol ); + leftnz = sub( leftnz, 1 ); } - quantum1_fx = quantize_fx(out[i], ddec[st][0]); - quantum2_fx = quantize_fx(out[i], ddec[st][1]); + quantum1_fx = quantize_fx( out[i], ddec[st][0] ); + quantum2_fx = quantize_fx( out[i], ddec[st][1] ); /*generate the next state */ - IF (EQ_16(quantum1_fx, out[i])) + IF( EQ_16( quantum1_fx, out[i] ) ) { st = nextstate[st][0]; move16(); @@ -2587,45 +2557,43 @@ void decode_mangitude_tcq_fx( } /*generate the magnitudes */ - FOR (; i < size; i++) + FOR( ; i < size; i++ ) { out[i] = 0; move16(); - IF (positions[i] != 0) + IF( positions[i] != 0 ) { - out[i] = add(sub(leftp, leftnz), 1); + out[i] = add( sub( leftp, leftnz ), 1 ); } - } test(); - IF (NE_16(nzpos, npulses)&>_16(nzpos,1)) + IF( NE_16( nzpos, npulses ) && GT_16( nzpos, 1 ) ) { /*update the surplus */ - *surplus_fx = L_add(*surplus_fx, L_sub(tcq_bits_fx, L_shl(bits_fx, 1))); + *surplus_fx = L_add( *surplus_fx, L_sub( tcq_bits_fx, L_shl( bits_fx, 1 ) ) ); } return; } void decode_signs_fx( - ARCODEC* pardec, - Word16 size, - Word16* out -) + ARCODEC *pardec, + Word16 size, + Word16 *out ) { Word16 i; - FOR ( i = 0; i < size; i++) + FOR( i = 0; i < size; i++ ) { - IF ( out[i] != 0 ) + IF( out[i] != 0 ) { Word16 tmp; tmp = ar_decode_fx( pardec, uniform_model ); - if( tmp <= 0 ) + if ( tmp <= 0 ) { - out[i] = negate(out[i]); + out[i] = negate( out[i] ); } } } @@ -2633,10 +2601,10 @@ void decode_signs_fx( return; } -Word16 GetScale_fx( - Word16 blen, - Word32 bits_fx/*Q16*/, - Word32 *surplus_fx/*Q16*/ +Word16 GetScale_fx( + Word16 blen, + Word32 bits_fx /*Q16*/, + Word32 *surplus_fx /*Q16*/ ) { Word16 pulses = MAX_PULSES, p_est, exp, exp1, exp2, magicnum; @@ -2645,74 +2613,73 @@ Word16 GetScale_fx( magicnum = 24773; move16(); /*Q17: 0.188992013101951f; */ - t = L_shr( L_mult( magicnum, blen), 2); - exp = norm_l(t); - a = L_shl( 14 - exp, 15) + Log2_norm_lc( L_shl( t, exp ) ); + t = L_shr( L_mult( magicnum, blen ), 2 ); + exp = norm_l( t ); + a = L_shl( 14 - exp, 15 ) + Log2_norm_lc( L_shl( t, exp ) ); - exp1 = sub( norm_l(bits_fx), 1); + exp1 = sub( norm_l( bits_fx ), 1 ); exp2 = norm_s( blen - 1 ); - b = L_shr( L_deposit_l( div_l( L_shl( bits_fx, exp1), shl( blen - 1, exp2) ) ), exp1-exp2 ); + b = L_shr( L_deposit_l( div_l( L_shl( bits_fx, exp1 ), shl( blen - 1, exp2 ) ) ), exp1 - exp2 ); - ab = L_add( a, b); + ab = L_add( a, b ); - p_est = extract_h(L_shl(Pow2( extract_l( L_shr(ab,15) ), ab&0x7FFF ),16)); /* enable saturationof pow2 result */ + p_est = extract_h( L_shl( Pow2( extract_l( L_shr( ab, 15 ) ), ab & 0x7FFF ), 16 ) ); /* enable saturationof pow2 result */ pulses = s_min( p_est, MAX_PULSES ); - FOR( ; pulses >= 0; pulses--) + FOR( ; pulses >= 0; pulses-- ) { - estbits_fx = GetBitsFromPulses_fx( pulses, blen); - IF( GE_32( bits_fx, estbits_fx)) + estbits_fx = GetBitsFromPulses_fx( pulses, blen ); + IF( GE_32( bits_fx, estbits_fx ) ) { BREAK; } } - IF ( surplus_fx != 0 ) + IF( surplus_fx != 0 ) { - *surplus_fx = L_add(*surplus_fx, L_sub(bits_fx, estbits_fx)); + *surplus_fx = L_add( *surplus_fx, L_sub( bits_fx, estbits_fx ) ); } return pulses; } -void srt_vec_ind_fx ( - const Word32 *linear, /* linear input */ - Word32 *srt, /* sorted output*/ - Word16 *I, /* index for sorted output */ - Word16 length -) +void srt_vec_ind_fx( + const Word32 *linear, /* linear input */ + Word32 *srt, /* sorted output*/ + Word16 *I, /* index for sorted output */ + Word16 length ) { - Word16 pos,npos,tmp; + Word16 pos, npos, tmp; Word16 idxMem; - Word32 valMem; + Word32 valMem; /*initilize */ - FOR (pos = 0; pos < length; pos++) + FOR( pos = 0; pos < length; pos++ ) { I[pos] = pos; move16(); } - Copy32(linear, srt, length); + Copy32( linear, srt, length ); /* now iterate */ - tmp = sub(length, 1); - FOR (pos = 0; pos < tmp; pos++) + tmp = sub( length, 1 ); + FOR( pos = 0; pos < tmp; pos++ ) { - FOR (npos = add(pos, 1); npos < length; npos++) + FOR( npos = add( pos, 1 ); npos < length; npos++ ) { - IF (LT_32(srt[npos], srt[pos])) + IF( LT_32( srt[npos], srt[pos] ) ) { - idxMem = I[pos]; + idxMem = I[pos]; move16(); - I[pos] = I[npos]; + I[pos] = I[npos]; move16(); - I[npos] = idxMem; + I[npos] = idxMem; move16(); - valMem = L_add(srt[pos], 0); - srt[pos] = srt[npos]; + valMem = L_add( srt[pos], 0 ); + srt[pos] = srt[npos]; move32(); srt[npos] = valMem; move32(); diff --git a/lib_com/tcx_ltp.c b/lib_com/tcx_ltp.c index 78558964f..8bf28ca9d 100644 --- a/lib_com/tcx_ltp.c +++ b/lib_com/tcx_ltp.c @@ -1060,7 +1060,7 @@ void tcx_ltp_post_flt( { /* Filtering with the first filter unit, followed by the filtering with the second filter unit */ tcx_ltp_synth_filter_11_unequal_pitch_flt( sig_out + delay, sig_in + delay, L_transition, pitch_int, pitch_fr, gain, st->pit_res_max, filtIdx, - hTcxLtpDec->tcxltp_pitch_int_post_prev, hTcxLtpDec->tcxltp_pitch_fr_post_prev, hTcxLtpDec->tcxltp_gain_post_prev_float, st->pit_res_max_past, hTcxLtpDec->tcxltp_filt_idx_prev ); + hTcxLtpDec->tcxltp_pitch_int_post_prev, hTcxLtpDec->tcxltp_pitch_fr_post_prev, hTcxLtpDec->tcxltp_gain_post_prev_float, st->pit_res_max_past, hTcxLtpDec->tcxltp_filt_idx_prev ); } } else @@ -1109,4 +1109,4 @@ void tcx_ltp_post_flt( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_com/tcx_ltp_fx.c b/lib_com/tcx_ltp_fx.c index a7097ac96..0c3190705 100644 --- a/lib_com/tcx_ltp_fx.c +++ b/lib_com/tcx_ltp_fx.c @@ -13,75 +13,76 @@ * Local constants *-------------------------------------------------------------------*/ -#define ALPHA 27853/*0.85f Q15*/ +#define ALPHA 27853 /*0.85f Q15*/ #define MAX_TCX_LTP_FILTER_LEN 8 #define MAX_TRANSITION_LEN 240 /* L_FRAME_48K / 4 */ void tcx_ltp_get_lpc( - Word16 *x, - const Word16 L, - Word16 *A, - const Word16 order -) + Word16 *x, + const Word16 L, + Word16 *A, + const Word16 order ) { Word16 i, j, s, s2, tmp; Word32 r, L_tmp; Word16 tmpbuf[L_FRAME_MAX], *p = x; - Word16 r_l[TCXLTP_LTP_ORDER+1], r_h[TCXLTP_LTP_ORDER+1]; + Word16 r_l[TCXLTP_LTP_ORDER + 1], r_h[TCXLTP_LTP_ORDER + 1]; - assert(L <= L_FRAME_MAX); + assert( L <= L_FRAME_MAX ); /* calc r[0], determine shift */ s = 0; move16(); - r = L_deposit_l(0); - FOR (j = 0; j < L; j++) + r = L_deposit_l( 0 ); + FOR( j = 0; j < L; j++ ) { - L_tmp = L_sub(r, 0x40000000); - if (L_tmp > 0) s = sub(s, 1); - if (L_tmp > 0) r = L_shr(r, 2); + L_tmp = L_sub( r, 0x40000000 ); + if ( L_tmp > 0 ) + s = sub( s, 1 ); + if ( L_tmp > 0 ) + r = L_shr( r, 2 ); - tmp = shl(x[j], s); + tmp = shl( x[j], s ); #ifdef BASOP_NOGLOB r = L_mac0_sat( r, tmp, tmp ); #else - r = L_mac0(r, tmp, tmp); + r = L_mac0( r, tmp, tmp ); #endif } - r = L_max(r, L_shl(100, shl(s, 1))); - r = Mpy_32_16_1(r, 16386/*1.0001f Q14*/); - s2 = norm_l(r); - r = L_shl(r, s2); - s2 = sub(s2, 1); - r_l[0] = L_Extract_lc(r, &r_h[0]); + r = L_max( r, L_shl( 100, shl( s, 1 ) ) ); + r = Mpy_32_16_1( r, 16386 /*1.0001f Q14*/ ); + s2 = norm_l( r ); + r = L_shl( r, s2 ); + s2 = sub( s2, 1 ); + r_l[0] = L_Extract_lc( r, &r_h[0] ); move16(); move16(); - IF (s < 0) + IF( s < 0 ) { /* shift buffer by s, recompute r[0] to reduce risk of instable LPC */ - r = L_deposit_l(0); - tmp = lshl((Word16)0x8000, s); /* factor corresponding to right shift by -s */ + r = L_deposit_l( 0 ); + tmp = lshl( (Word16) 0x8000, s ); /* factor corresponding to right shift by -s */ { Word64 r64 = 0; move64(); - FOR (j = 0; j < L; j++) + FOR( j = 0; j < L; j++ ) { - tmpbuf[j] = mult_r(x[j], tmp); + tmpbuf[j] = mult_r( x[j], tmp ); move16(); - r64 = W_mac0_16_16(r64, tmpbuf[j], tmpbuf[j]); + r64 = W_mac0_16_16( r64, tmpbuf[j], tmpbuf[j] ); } - r = W_sat_l(r64); + r = W_sat_l( r64 ); } - r = L_max(r, L_shl(100, shl(s, 1))); - r = Mpy_32_16_1(r, 16386/*1.0001f Q14*/); - s2 = norm_l(r); - r = L_shl(r, s2); - s2 = sub(s2, 1); - r_l[0] = L_Extract_lc(r, &r_h[0]); + r = L_max( r, L_shl( 100, shl( s, 1 ) ) ); + r = Mpy_32_16_1( r, 16386 /*1.0001f Q14*/ ); + s2 = norm_l( r ); + r = L_shl( r, s2 ); + s2 = sub( s2, 1 ); + r_l[0] = L_Extract_lc( r, &r_h[0] ); move16(); move16(); @@ -89,28 +90,27 @@ void tcx_ltp_get_lpc( } /* calc r[1...] */ - FOR (i = 1; i <= order; i++) + FOR( i = 1; i <= order; i++ ) { - r = L_deposit_l(0); + r = L_deposit_l( 0 ); - tmp = sub(L, i); + tmp = sub( L, i ); { Word64 r64 = 0; move64(); - FOR (j = 0; j < tmp; j++) + FOR( j = 0; j < tmp; j++ ) { - r64 = W_mac0_16_16(r64, p[j], p[j+i]); + r64 = W_mac0_16_16( r64, p[j], p[j + i] ); } - r = W_sat_l(r64); + r = W_sat_l( r64 ); } - r = L_shl(r, s2); - r_l[i] = L_Extract_lc(r, &r_h[i]); + r = L_shl( r, s2 ); + r_l[i] = L_Extract_lc( r, &r_h[i] ); move16(); move16(); } - E_LPC_lev_dur(r_h, r_l, A, NULL, order, NULL); - + E_LPC_lev_dur( r_h, r_l, A, NULL, order, NULL ); } void tcx_ltp_get_lpc_fx( @@ -165,7 +165,7 @@ void tcx_ltp_get_lpc_fx( { tmpbuf[j] = Mpy_32_32( x[j], tmp ); move32(); - r64 = W_add( r64, W_mult0_32_32(tmpbuf[j], tmpbuf[j] )); + r64 = W_add( r64, W_mult0_32_32( tmpbuf[j], tmpbuf[j] ) ); } r = W_sat_l( r64 ); } @@ -206,18 +206,17 @@ void tcx_ltp_get_lpc_fx( } static void tcx_ltp_get_zir( - Word16 *zir, - const Word16 length, - Word16 *synth_ltp, - Word16 *synth, - Word16 *A, - const Word16 lpcorder, - const Word16 gain, - const Word16 pitch_int, - const Word16 pitch_fr, - const Word16 pitres, - const Word16 filtIdx -) + Word16 *zir, + const Word16 length, + Word16 *synth_ltp, + Word16 *synth, + Word16 *A, + const Word16 lpcorder, + const Word16 gain, + const Word16 pitch_int, + const Word16 pitch_fr, + const Word16 pitres, + const Word16 filtIdx ) { Word16 buf[TCXLTP_LTP_ORDER], alpha, step; Word16 *x0, *x1; @@ -231,41 +230,41 @@ static void tcx_ltp_get_zir( y0 = synth; y1 = y0 - 1; - assert(filtIdx >= 0); + assert( filtIdx >= 0 ); w0 = &tcxLtpFilters[filtIdx].filt[pitch_fr]; - w1 = &tcxLtpFilters[filtIdx].filt[sub(pitres, pitch_fr)]; + w1 = &tcxLtpFilters[filtIdx].filt[sub( pitres, pitch_fr )]; v0 = &tcxLtpFilters[filtIdx].filt[0]; v1 = &tcxLtpFilters[filtIdx].filt[pitres]; L = tcxLtpFilters[filtIdx].length; move16(); - FOR (j = 0; j < lpcorder; j++) + FOR( j = 0; j < lpcorder; j++ ) { - s = L_deposit_l(0); - s2 = L_deposit_l(0); + s = L_deposit_l( 0 ); + s2 = L_deposit_l( 0 ); k = 0; move16(); - FOR (i = 0; i < L; i++) + FOR( i = 0; i < L; i++ ) { #ifdef BASOP_NOGLOB - s = L_mac_sat(L_mac_sat(s, w0[k], x0[i]), w1[k], x1[-i]); - s2 = L_mac_sat(L_mac_sat(s2, v0[k], y0[i]), v1[k], y1[-i]); + s = L_mac_sat( L_mac_sat( s, w0[k], x0[i] ), w1[k], x1[-i] ); + s2 = L_mac_sat( L_mac_sat( s2, v0[k], y0[i] ), v1[k], y1[-i] ); #else - s = L_mac(L_mac(s, w0[k], x0[i]), w1[k], x1[-i]); - s2 = L_mac(L_mac(s2, v0[k], y0[i]), v1[k], y1[-i]); + s = L_mac( L_mac( s, w0[k], x0[i] ), w1[k], x1[-i] ); + s2 = L_mac( L_mac( s2, v0[k], y0[i] ), v1[k], y1[-i] ); #endif - k = add(k, pitres); + k = add( k, pitres ); } /* s2 *= ALPHA; buf[j] = ( synth[j] - gain * s2 ) - ( synth_ltp[j] - gain * s ); */ #ifdef BASOP_NOGLOB - i = sub_sat(round_fx_sat(s), mult_r_sat(round_fx_sat(s2), ALPHA)); - buf[j] = add_sat(sub_sat(synth[j], synth_ltp[j]), mult_r_sat(gain, i)); + i = sub_sat( round_fx_sat( s ), mult_r_sat( round_fx_sat( s2 ), ALPHA ) ); + buf[j] = add_sat( sub_sat( synth[j], synth_ltp[j] ), mult_r_sat( gain, i ) ); #else - i = sub(round_fx(s), mult_r(round_fx(s2), ALPHA)); - buf[j] = add(sub(synth[j], synth_ltp[j]), mult_r(gain, i)); + i = sub( round_fx( s ), mult_r( round_fx( s2 ), ALPHA ) ); + buf[j] = add( sub( synth[j], synth_ltp[j] ), mult_r( gain, i ) ); #endif move16(); @@ -275,29 +274,29 @@ static void tcx_ltp_get_zir( y1++; } - set16_fx(zir, 0, length); + set16_fx( zir, 0, length ); - E_UTIL_synthesis(0, A, zir, zir, length, buf, 0, lpcorder); + E_UTIL_synthesis( 0, A, zir, zir, length, buf, 0, lpcorder ); alpha = 0x7FFF; move16(); /* step = 1.f/(float)(length/2); */ - step = shl(4, norm_s(length)); - if (s_and(length, sub(length, 1)) != 0) + step = shl( 4, norm_s( length ) ); + if ( s_and( length, sub( length, 1 ) ) != 0 ) { - step = mult_r(step, 26214/*64.f/80.f Q15*/); + step = mult_r( step, 26214 /*64.f/80.f Q15*/ ); } - if (EQ_16(length, 240)) + if ( EQ_16( length, 240 ) ) { - step = 273/*1.f/120.f Q15*/; + step = 273 /*1.f/120.f Q15*/; move16(); } - FOR (j = shr(length, 1); j < length; j++) + FOR( j = shr( length, 1 ); j < length; j++ ) { - zir[j] = mult_r(zir[j], alpha); + zir[j] = mult_r( zir[j], alpha ); move16(); - alpha = sub(alpha, step); + alpha = sub( alpha, step ); } } @@ -390,12 +389,12 @@ static void tcx_ltp_get_zir_fx( } void predict_signal( - const Word16 excI[], /* i : input excitation buffer */ - Word16 excO[], /* o : output excitation buffer */ - const Word16 T0, /* i : integer pitch lag */ - Word16 frac, /* i : fraction of lag */ - const Word16 frac_max, /* i : max fraction */ - const Word16 L_subfr /* i : subframe size */ + const Word16 excI[], /* i : input excitation buffer */ + Word16 excO[], /* o : output excitation buffer */ + const Word16 T0, /* i : integer pitch lag */ + Word16 frac, /* i : fraction of lag */ + const Word16 frac_max, /* i : max fraction */ + const Word16 L_subfr /* i : subframe size */ ) { Word16 j; @@ -404,39 +403,39 @@ void predict_signal( #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - x0 = &excI[-T0-1]; - frac = negate(frac); + x0 = &excI[-T0 - 1]; + frac = negate( frac ); - IF (frac < 0) + IF( frac < 0 ) { - frac = add(frac, frac_max); + frac = add( frac, frac_max ); x0--; } win = &inter4_2tcx2[frac][0]; - if (EQ_16(frac_max, 6))win=&inter6_2tcx2[frac][0]; + if ( EQ_16( frac_max, 6 ) ) + win = &inter6_2tcx2[frac][0]; - FOR (j = 0; j < L_subfr; j++) + FOR( j = 0; j < L_subfr; j++ ) { #ifdef BASOP_NOGLOB - s = L_mult_o(win[0], x0[0], &Overflow); - s = L_mac_o(s, win[1], x0[1], &Overflow); - s = L_mac_o(s, win[2], x0[2], &Overflow); - excO[j] = mac_ro(s, win[3], x0[3], &Overflow); + s = L_mult_o( win[0], x0[0], &Overflow ); + s = L_mac_o( s, win[1], x0[1], &Overflow ); + s = L_mac_o( s, win[2], x0[2], &Overflow ); + excO[j] = mac_ro( s, win[3], x0[3], &Overflow ); #else - s = L_mult(win[0], x0[0]); - s = L_mac(s, win[1], x0[1]); - s = L_mac(s, win[2], x0[2]); - excO[j] = mac_r(s, win[3], x0[3]); + s = L_mult( win[0], x0[0] ); + s = L_mac( s, win[1], x0[1] ); + s = L_mac( s, win[2], x0[2] ); + excO[j] = mac_r( s, win[3], x0[3] ); #endif move16(); x0++; } - } -static void tcx_ltp_synth_filter( +static void tcx_ltp_synth_filter( Word16 *synth_ltp, Word16 *synth, Word16 length, @@ -444,10 +443,9 @@ static void tcx_ltp_synth_filter( Word16 pitch_fr, Word16 gain, Word16 pitch_res, - Word16 *zir, /* can be NULL */ - Word16 fade, /* 0=normal, +1=fade-in, -1=fade-out */ - Word16 filtIdx - ) + Word16 *zir, /* can be NULL */ + Word16 fade, /* 0=normal, +1=fade-in, -1=fade-out */ + Word16 filtIdx ) { Word16 *x0, *x1; Word16 *y0, *y1; @@ -457,17 +455,17 @@ static void tcx_ltp_synth_filter( Word16 alpha, step = 0; /* initialize just to avoid compiler warning */ Word16 i, j, k, L; - IF (gain > 0) + IF( gain > 0 ) { x0 = &synth_ltp[-pitch_int]; x1 = x0 - 1; y0 = synth; y1 = y0 - 1; - assert(filtIdx >= 0); + assert( filtIdx >= 0 ); w0 = &tcxLtpFilters[filtIdx].filt[pitch_fr]; - w1 = &tcxLtpFilters[filtIdx].filt[sub(pitch_res, pitch_fr)]; + w1 = &tcxLtpFilters[filtIdx].filt[sub( pitch_res, pitch_fr )]; v0 = &tcxLtpFilters[filtIdx].filt[0]; v1 = &tcxLtpFilters[filtIdx].filt[pitch_res]; @@ -476,45 +474,46 @@ static void tcx_ltp_synth_filter( alpha = 0; move16(); - IF (fade != 0) + IF( fade != 0 ) { - if (fade < 0) + if ( fade < 0 ) { alpha = 0x7FFF; move16(); } /* step = 1.f/(float)(length); */ - step = shl(2, norm_s(length)); - if (s_and(length, sub(length, 1)) != 0) + step = shl( 2, norm_s( length ) ); + if ( s_and( length, sub( length, 1 ) ) != 0 ) { - step = mult_r(step, 26214/*64.f/80.f Q15*/); + step = mult_r( step, 26214 /*64.f/80.f Q15*/ ); } - if (EQ_16(length, 240)) + if ( EQ_16( length, 240 ) ) { - step = 137/*1.f/240.f Q15*/; + step = 137 /*1.f/240.f Q15*/; move16(); } - if (fade < 0) step = negate(step); + if ( fade < 0 ) + step = negate( step ); } - FOR(j = 0; j < length; j++) + FOR( j = 0; j < length; j++ ) { - s = L_deposit_l(0); - s2 = L_deposit_l(0); + s = L_deposit_l( 0 ); + s2 = L_deposit_l( 0 ); k = 0; move16(); - FOR(i = 0; i < L; i++) + FOR( i = 0; i < L; i++ ) { #ifdef BASOP_NOGLOB - s = L_mac_sat(L_mac_sat(s, w0[k], x0[i]), w1[k], x1[-i]); - s2 = L_mac_sat(L_mac_sat(s2, v0[k], y0[i]), v1[k], y1[-i]); + s = L_mac_sat( L_mac_sat( s, w0[k], x0[i] ), w1[k], x1[-i] ); + s2 = L_mac_sat( L_mac_sat( s2, v0[k], y0[i] ), v1[k], y1[-i] ); #else - s = L_mac(L_mac(s, w0[k], x0[i]), w1[k], x1[-i]); - s2 = L_mac(L_mac(s2, v0[k], y0[i]), v1[k], y1[-i]); + s = L_mac( L_mac( s, w0[k], x0[i] ), w1[k], x1[-i] ); + s2 = L_mac( L_mac( s2, v0[k], y0[i] ), v1[k], y1[-i] ); #endif - k = add(k, pitch_res); + k = add( k, pitch_res ); } /* s2 *= ALPHA; @@ -522,21 +521,23 @@ static void tcx_ltp_synth_filter( zir: synth_ltp[j] = synth[j] - gain * s2 + gain * s - zir[j]; fade-in/out: synth_ltp[j] = synth[j] - alpha * gain * s2 + alpha * gain * s; */ #ifdef BASOP_NOGLOB - i = sub_sat(round_fx_sat(s), mult_r_sat(round_fx_sat(s2), ALPHA)); + i = sub_sat( round_fx_sat( s ), mult_r_sat( round_fx_sat( s2 ), ALPHA ) ); #else - i = sub(round_fx(s), mult_r(round_fx(s2), ALPHA)); + i = sub( round_fx( s ), mult_r( round_fx( s2 ), ALPHA ) ); #endif - k = mult_r(gain, i); - if (fade != 0) k = mult_r(k, alpha); + k = mult_r( gain, i ); + if ( fade != 0 ) + k = mult_r( k, alpha ); #ifdef BASOP_NOGLOB - k = add_sat(synth[j], k); - if (zir != NULL) + k = add_sat( synth[j], k ); + if ( zir != NULL ) { - k = sub_sat(k, zir[j]); + k = sub_sat( k, zir[j] ); } #else - k = add(synth[j], k); - if (zir != NULL) k = sub(k, zir[j]); + k = add( synth[j], k ); + if ( zir != NULL ) + k = sub( k, zir[j] ); #endif synth_ltp[j] = k; @@ -544,12 +545,13 @@ static void tcx_ltp_synth_filter( BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB - if (fade != 0) + if ( fade != 0 ) { - alpha = add_sat(alpha, step); - } + alpha = add_sat( alpha, step ); + } #else - if (fade != 0) alpha = add(alpha, step); + if ( fade != 0 ) + alpha = add( alpha, step ); #endif BASOP_SATURATE_WARNING_ON_EVS; @@ -760,64 +762,64 @@ static void tcx_ltp_synth_filter_10( } static void tcx_ltp_synth_filter_10_fx( - Word32 *out, - Word32 *in, - const Word16 length, - const Word16 pitch_int, - const Word16 pitch_fr, - const Word16 gain, - const Word16 pitch_res, - const Word16 filtIdx) + Word32 *out, + Word32 *in, + const Word16 length, + const Word16 pitch_int, + const Word16 pitch_fr, + const Word16 gain, + const Word16 pitch_res, + const Word16 filtIdx ) { - Word32 *x0, *x1; - Word32 *y0, *y1; - Word32 s, s2; - const Word16 *v0, *v1; - const Word16 *w0, *w1; - Word16 i, j, k, L; - Word16 curr_gain, gain_step; - - x0 = &out[-pitch_int]; - x1 = x0 - 1; - y0 = in; - y1 = y0 - 1; - - assert(GE_16(filtIdx, 0)); - - w0 = &tcxLtpFilters[filtIdx].filt[pitch_fr]; - w1 = &tcxLtpFilters[filtIdx].filt[pitch_res - pitch_fr]; - v0 = &tcxLtpFilters[filtIdx].filt[0]; - v1 = &tcxLtpFilters[filtIdx].filt[pitch_res]; - L = tcxLtpFilters[filtIdx].length; - - curr_gain = gain; - gain_step = negate(gain) / length; - - for (j = 0; j < length; j++) - { - s = 0; - s2 = 0; + Word32 *x0, *x1; + Word32 *y0, *y1; + Word32 s, s2; + const Word16 *v0, *v1; + const Word16 *w0, *w1; + Word16 i, j, k, L; + Word16 curr_gain, gain_step; + + x0 = &out[-pitch_int]; + x1 = x0 - 1; + y0 = in; + y1 = y0 - 1; + + assert( GE_16( filtIdx, 0 ) ); - for (i = 0, k = 0; i < L; i++, k += pitch_res) + w0 = &tcxLtpFilters[filtIdx].filt[pitch_fr]; + w1 = &tcxLtpFilters[filtIdx].filt[pitch_res - pitch_fr]; + v0 = &tcxLtpFilters[filtIdx].filt[0]; + v1 = &tcxLtpFilters[filtIdx].filt[pitch_res]; + L = tcxLtpFilters[filtIdx].length; + + curr_gain = gain; + gain_step = negate( gain ) / length; + + for ( j = 0; j < length; j++ ) { - // s += w0[k] * x0[i] + w1[k] * x1[-i]; - // s2 += v0[k] * y0[i] + v1[k] * y1[-i]; - s = Madd_32_16_r(Madd_32_16_r(s, x0[i], w0[k]), x1[-i], w1[k]); - s2 = Madd_32_16_r(Madd_32_16_r(s2, y0[i], v0[k]), y1[-i], v1[k]); - } + s = 0; + s2 = 0; - // out[j] = in[j] - curr_gain * s2 * ALPHA + curr_gain * s; - out[j] = L_add_sat(in[j], Mpy_32_16_1(L_sub_sat(s, Mpy_32_16_1(s2, ALPHA)), curr_gain)); + for ( i = 0, k = 0; i < L; i++, k += pitch_res ) + { + // s += w0[k] * x0[i] + w1[k] * x1[-i]; + // s2 += v0[k] * y0[i] + v1[k] * y1[-i]; + s = Madd_32_16_r( Madd_32_16_r( s, x0[i], w0[k] ), x1[-i], w1[k] ); + s2 = Madd_32_16_r( Madd_32_16_r( s2, y0[i], v0[k] ), y1[-i], v1[k] ); + } - x0++; - x1++; - y0++; - y1++; + // out[j] = in[j] - curr_gain * s2 * ALPHA + curr_gain * s; + out[j] = L_add_sat( in[j], Mpy_32_16_1( L_sub_sat( s, Mpy_32_16_1( s2, ALPHA ) ), curr_gain ) ); - curr_gain = add(curr_gain, gain_step); - } + x0++; + x1++; + y0++; + y1++; + + curr_gain = add( curr_gain, gain_step ); + } - return; + return; } static void tcx_ltp_synth_filter_01( @@ -883,65 +885,65 @@ static void tcx_ltp_synth_filter_01( } static void tcx_ltp_synth_filter_01_fx( - Word32 *out, - Word32 *in, - const Word16 length, - const Word16 pitch_int, - const Word16 pitch_fr, - const Word16 gain, - const Word16 pitch_res, - const Word16 filtIdx) + Word32 *out, + Word32 *in, + const Word16 length, + const Word16 pitch_int, + const Word16 pitch_fr, + const Word16 gain, + const Word16 pitch_res, + const Word16 filtIdx ) { - Word32 *x0, *x1; - Word32 *y0, *y1; - Word32 s, s2; - const Word16 *v0, *v1; - const Word16 *w0, *w1; - Word16 i, j, k, L; - Word16 curr_gain, gain_step; - - x0 = &out[negate(pitch_int)]; - x1 = x0 - 1; - y0 = in; - y1 = y0 - 1; - - assert(GE_16(filtIdx, 0)); - - w0 = &tcxLtpFilters[filtIdx].filt[pitch_fr]; - w1 = &tcxLtpFilters[filtIdx].filt[pitch_res - pitch_fr]; - v0 = &tcxLtpFilters[filtIdx].filt[0]; - v1 = &tcxLtpFilters[filtIdx].filt[pitch_res]; - L = tcxLtpFilters[filtIdx].length; - - curr_gain = 0; - gain_step = gain / length; - - for (j = 0; j < length; j++) - { - s = 0; - s2 = 0; + Word32 *x0, *x1; + Word32 *y0, *y1; + Word32 s, s2; + const Word16 *v0, *v1; + const Word16 *w0, *w1; + Word16 i, j, k, L; + Word16 curr_gain, gain_step; + + x0 = &out[negate( pitch_int )]; + x1 = x0 - 1; + y0 = in; + y1 = y0 - 1; + + assert( GE_16( filtIdx, 0 ) ); - for (i = 0, k = 0; i < L; i++, k = add(k, pitch_res)) + w0 = &tcxLtpFilters[filtIdx].filt[pitch_fr]; + w1 = &tcxLtpFilters[filtIdx].filt[pitch_res - pitch_fr]; + v0 = &tcxLtpFilters[filtIdx].filt[0]; + v1 = &tcxLtpFilters[filtIdx].filt[pitch_res]; + L = tcxLtpFilters[filtIdx].length; + + curr_gain = 0; + gain_step = gain / length; + + for ( j = 0; j < length; j++ ) { - // s += w0[k] * x0[i] + w1[k] * x1[-i]; - // s2 += v0[k] * y0[i] + v1[k] * y1[-i]; - s = Madd_32_16_r(Madd_32_16_r(s, x0[i], w0[k]), x1[-i], w1[k]); - s2 = Madd_32_16_r(Madd_32_16_r(s2, y0[i], v0[k]), y1[-i], v1[k]); - } + s = 0; + s2 = 0; + + for ( i = 0, k = 0; i < L; i++, k = add( k, pitch_res ) ) + { + // s += w0[k] * x0[i] + w1[k] * x1[-i]; + // s2 += v0[k] * y0[i] + v1[k] * y1[-i]; + s = Madd_32_16_r( Madd_32_16_r( s, x0[i], w0[k] ), x1[-i], w1[k] ); + s2 = Madd_32_16_r( Madd_32_16_r( s2, y0[i], v0[k] ), y1[-i], v1[k] ); + } - // out[j] = in[j] - curr_gain * s2 * ALPHA + curr_gain * s; - out[j] = L_add_sat(in[j], Mpy_32_16_r(L_sub_sat(s, Mpy_32_16_1(s2, ALPHA)), curr_gain)); + // out[j] = in[j] - curr_gain * s2 * ALPHA + curr_gain * s; + out[j] = L_add_sat( in[j], Mpy_32_16_r( L_sub_sat( s, Mpy_32_16_1( s2, ALPHA ) ), curr_gain ) ); - x0++; - x1++; - y0++; - y1++; + x0++; + x1++; + y0++; + y1++; - curr_gain = add(curr_gain, gain_step); - } + curr_gain = add( curr_gain, gain_step ); + } - return; + return; } /*------------------------------------------------------------------- @@ -1204,55 +1206,53 @@ Word16 tcx_ltp_decode_params( const Word16 pitfr1, const Word16 pitfr2, const Word16 pitmax, - const Word16 pitres -) + const Word16 pitres ) { Word16 tmp, tmp2; - /* Decode Pitch and Gain */ test(); - IF (ltp_param != 0 && ltp_param[0] != 0) + IF( ltp_param != 0 && ltp_param[0] != 0 ) { - tmp = imult1616(sub(pitfr2, pitmin), pitres); + tmp = imult1616( sub( pitfr2, pitmin ), pitres ); - IF ( LT_16(ltp_param[1], tmp)) + IF( LT_16( ltp_param[1], tmp ) ) { - tmp2 = idiv1616U(ltp_param[1], pitres); + tmp2 = idiv1616U( ltp_param[1], pitres ); - *pitch_int = add(pitmin, tmp2); + *pitch_int = add( pitmin, tmp2 ); move16(); tmp2 = sub( *pitch_int, pitmin ); - *pitch_fr = sub(ltp_param[1], imult1616(tmp2, pitres)); + *pitch_fr = sub( ltp_param[1], imult1616( tmp2, pitres ) ); move16(); } ELSE { - tmp2 = imult1616(sub(pitfr1, pitfr2),shr( pitres, 1 )); + tmp2 = imult1616( sub( pitfr1, pitfr2 ), shr( pitres, 1 ) ); - IF ( LT_16(ltp_param[1], add(tmp, tmp2))) + IF( LT_16( ltp_param[1], add( tmp, tmp2 ) ) ) { - tmp2 = idiv1616U(sub(ltp_param[1], tmp),shr( pitres,1)); + tmp2 = idiv1616U( sub( ltp_param[1], tmp ), shr( pitres, 1 ) ); - *pitch_int = add(pitfr2, tmp2); + *pitch_int = add( pitfr2, tmp2 ); move16(); - *pitch_fr = shl( sub(sub(ltp_param[1], tmp), imult1616(tmp2,shr( pitres,1 ))), 1 ); + *pitch_fr = shl( sub( sub( ltp_param[1], tmp ), imult1616( tmp2, shr( pitres, 1 ) ) ), 1 ); move16(); } ELSE { - *pitch_int = sub(add(ltp_param[1], pitfr1), add(tmp, tmp2)); + *pitch_int = sub( add( ltp_param[1], pitfr1 ), add( tmp, tmp2 ) ); move16(); *pitch_fr = 0; move16(); } } - *gain = imult1616(add(ltp_param[2], 1), 0x1400); + *gain = imult1616( add( ltp_param[2], 1 ), 0x1400 ); move16(); - IF( LT_16(*pitch_int,PIT_MIN_SHORTER)) + IF( LT_16( *pitch_int, PIT_MIN_SHORTER ) ) { /*pitch out of range due to bit error */ *pitch_int = PIT_MIN_SHORTER; @@ -1260,7 +1260,7 @@ Word16 tcx_ltp_decode_params( return 1; } - IF( GT_16(*pitch_int,PIT_MAX_MAX)) + IF( GT_16( *pitch_int, PIT_MAX_MAX ) ) { /*pitch out of range due to bit error */ *pitch_int = PIT_MAX_MAX; @@ -1281,39 +1281,38 @@ Word16 tcx_ltp_decode_params( return 0; } -void tcx_ltp_post( - Decoder_State* st, +void tcx_ltp_post( + Decoder_State *st, TCX_LTP_DEC_HANDLE hTcxLtpDec, Word16 core, Word16 output_frame, Word16 delay, Word16 *sig, - Word16 *tcx_buf -) + Word16 *tcx_buf ) { Word16 tmp, L_transition, lpcorder, filtIdx; Word16 gain, gain2; Word32 tmp32; - Word16 zir[L_FRAME_PLUS/4], A[TCXLTP_LTP_ORDER+1]; - Word16 buf_in[TCXLTP_MAX_DELAY+L_FRAME48k+TCXLTP_MAX_DELAY], buf_out[2*L_FRAME48k]; + Word16 zir[L_FRAME_PLUS / 4], A[TCXLTP_LTP_ORDER + 1]; + Word16 buf_in[TCXLTP_MAX_DELAY + L_FRAME48k + TCXLTP_MAX_DELAY], buf_out[2 * L_FRAME48k]; Word16 *sig_in, *sig_out; Word16 pitch_int, pitch_fr; Word16 tcx_buf_len, bfi, L_frame_core, SideInfoOnly; Word32 total_brate; - + total_brate = st->total_brate; move32(); - IF (EQ_16(st->element_mode, IVAS_CPE_MDCT)) + IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) { - total_brate = st->bits_frame_nominal* FRAMES_PER_SEC; + total_brate = st->bits_frame_nominal * FRAMES_PER_SEC; move32(); - } + } - filtIdx = 0; /* just to avoid comilation warnings */ - tcx_buf_len = NS2SA(st->output_Fs, TCXLTP_DELAY_NS); + filtIdx = 0; /* just to avoid comilation warnings */ + tcx_buf_len = NS2SA( st->output_Fs, TCXLTP_DELAY_NS ); SideInfoOnly = 0; - if (GE_32(total_brate, HQ_96k)) + if ( GE_32( total_brate, HQ_96k ) ) { SideInfoOnly = 1; move16(); @@ -1322,20 +1321,23 @@ void tcx_ltp_post( L_frame_core = st->L_frame; move16(); - if (EQ_16(st->element_mode, IVAS_CPE_MDCT)) + if ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) { L_frame_core = L_FRAME; move16(); } - IF (EQ_16(core, ACELP_CORE)) + IF( EQ_16( core, ACELP_CORE ) ) { bfi = 0; pitch_int = 0; pitch_fr = 0; gain = 0; L_frame_core = st->L_frame_past; - move16(); move16(); move16(); move16(); + move16(); + move16(); + move16(); + move16(); } ELSE { @@ -1343,34 +1345,37 @@ void tcx_ltp_post( pitch_int = hTcxLtpDec->tcxltp_pitch_int; pitch_fr = hTcxLtpDec->tcxltp_pitch_fr; gain = hTcxLtpDec->tcxltp_gain; - move16(); move16(); move16(); move16(); + move16(); + move16(); + move16(); + move16(); } /******** Init ********/ /* Parameters */ - L_transition = shr(output_frame, 2); + L_transition = shr( output_frame, 2 ); lpcorder = TCXLTP_LTP_ORDER; move16(); /* Input buffer */ sig_in = buf_in + tcx_buf_len; - Copy(hTcxLtpDec->tcxltp_mem_in, buf_in, tcx_buf_len ); - Copy( sig, buf_in+tcx_buf_len, output_frame ); - IF ( core > ACELP_CORE ) + Copy( hTcxLtpDec->tcxltp_mem_in, buf_in, tcx_buf_len ); + Copy( sig, buf_in + tcx_buf_len, output_frame ); + IF( core > ACELP_CORE ) { - Copy( tcx_buf, sig_in+output_frame, tcx_buf_len ); + Copy( tcx_buf, sig_in + output_frame, tcx_buf_len ); } - Copy( sig+output_frame-tcx_buf_len, hTcxLtpDec->tcxltp_mem_in, tcx_buf_len ); + Copy( sig + output_frame - tcx_buf_len, hTcxLtpDec->tcxltp_mem_in, tcx_buf_len ); /* Output buffer */ sig_out = buf_out + output_frame; - Copy(hTcxLtpDec->tcxltp_mem_out, buf_out, output_frame ); + Copy( hTcxLtpDec->tcxltp_mem_out, buf_out, output_frame ); /* TCX-LTP parameters: integer pitch, fractional pitch, gain */ test(); test(); - IF ( !(SideInfoOnly != 0 || hTcxLtpDec->tcxltp != 0) || EQ_16(core, ACELP_CORE)) + IF( !( SideInfoOnly != 0 || hTcxLtpDec->tcxltp != 0 ) || EQ_16( core, ACELP_CORE ) ) { /* No LTP */ pitch_int = 0; @@ -1380,55 +1385,55 @@ void tcx_ltp_post( gain = 0; move16(); } - ELSE IF (bfi == 0) + ELSE IF( bfi == 0 ) { /* LTP and good frame */ - IF(EQ_16(st->element_mode, EVS_MONO)) /* hard tunings for EVS_MONO, HQ_48k is TCX only */ + IF( EQ_16( st->element_mode, EVS_MONO ) ) /* hard tunings for EVS_MONO, HQ_48k is TCX only */ { - IF(NE_16(output_frame, L_frame_core)) + IF( NE_16( output_frame, L_frame_core ) ) { - tmp = div_s(output_frame, shl(L_frame_core, 2)); /* Q13 */ - tmp32 = L_mult0(add(imult1616(pitch_int, st->pit_res_max), pitch_fr), tmp); /* Q13 */ - tmp = round_fx(L_shl(tmp32, 3)); /* Q0 */ - pitch_int = idiv1616U(tmp, st->pit_res_max); - pitch_fr = sub(tmp, imult1616(pitch_int, st->pit_res_max)); + tmp = div_s( output_frame, shl( L_frame_core, 2 ) ); /* Q13 */ + tmp32 = L_mult0( add( imult1616( pitch_int, st->pit_res_max ), pitch_fr ), tmp ); /* Q13 */ + tmp = round_fx( L_shl( tmp32, 3 ) ); /* Q0 */ + pitch_int = idiv1616U( tmp, st->pit_res_max ); + pitch_fr = sub( tmp, imult1616( pitch_int, st->pit_res_max ) ); } test(); test(); - IF(EQ_32(total_brate, 48000) && EQ_16(L_frame_core, L_FRAME16k)) + IF( EQ_32( total_brate, 48000 ) && EQ_16( L_frame_core, L_FRAME16k ) ) { - gain = mult_r(gain, 10486/*0.32f Q15*/); + gain = mult_r( gain, 10486 /*0.32f Q15*/ ); } - ELSE IF(EQ_32(total_brate, 48000) && EQ_16(L_frame_core, 512)) + ELSE IF( EQ_32( total_brate, 48000 ) && EQ_16( L_frame_core, 512 ) ) { - gain = mult_r(gain, 13107/*0.40f Q15*/); + gain = mult_r( gain, 13107 /*0.40f Q15*/ ); } ELSE { - gain = mult_r(gain, 20972/*0.64f Q15*/); + gain = mult_r( gain, 20972 /*0.64f Q15*/ ); } } - ELSE IF (GT_16(st->element_mode, IVAS_SCE) && GE_32(total_brate, IVAS_96k)) + ELSE IF( GT_16( st->element_mode, IVAS_SCE ) && GE_32( total_brate, IVAS_96k ) ) { - gain = mult_r(gain, 13107/*0.40f Q15*/); + gain = mult_r( gain, 13107 /*0.40f Q15*/ ); } ELSE { - gain = mult_r(gain, 20972/*0.64f Q15*/); + gain = mult_r( gain, 20972 /*0.64f Q15*/ ); } } ELSE { /* PLC: [TCX: Fade-out] * PLC: LTP and bad frame (concealment) */ - IF (st->pit_res_max == st->pit_res_max_past) /* ensure consistent core SR to previous frame; otherwise, set gain to 0 */ + IF( st->pit_res_max == st->pit_res_max_past ) /* ensure consistent core SR to previous frame; otherwise, set gain to 0 */ { pitch_int = hTcxLtpDec->tcxltp_pitch_int_post_prev; move16(); - pitch_fr = hTcxLtpDec->tcxltp_pitch_fr_post_prev; + pitch_fr = hTcxLtpDec->tcxltp_pitch_fr_post_prev; move16(); - gain = shl(mult_r(hTcxLtpDec->tcxltp_gain_post_prev, st->hTcxDec->damping), 1); - } + gain = shl( mult_r( hTcxLtpDec->tcxltp_gain_post_prev, st->hTcxDec->damping ), 1 ); + } ELSE { gain = 0; @@ -1437,7 +1442,7 @@ void tcx_ltp_post( } - IF ( SideInfoOnly != 0 ) + IF( SideInfoOnly != 0 ) { gain = 0; move16(); @@ -1450,76 +1455,76 @@ void tcx_ltp_post( gain2 = gain; move16(); - IF (EQ_16(L_frame_core, L_FRAME)) + IF( EQ_16( L_frame_core, L_FRAME ) ) { - SWITCH ( output_frame ) + SWITCH( output_frame ) { - case L_FRAME8k: - filtIdx = 0; - move16(); - BREAK; - case L_FRAME16k: - filtIdx = 1; - move16(); - BREAK; - case L_FRAME32k: - filtIdx = 2; - move16(); - BREAK; - case L_FRAME48k: - filtIdx = 3; - move16(); - BREAK; - default: - assert(0); + case L_FRAME8k: + filtIdx = 0; + move16(); + BREAK; + case L_FRAME16k: + filtIdx = 1; + move16(); + BREAK; + case L_FRAME32k: + filtIdx = 2; + move16(); + BREAK; + case L_FRAME48k: + filtIdx = 3; + move16(); + BREAK; + default: + assert( 0 ); } } - ELSE IF (EQ_16(L_frame_core, L_FRAME16k)) + ELSE IF( EQ_16( L_frame_core, L_FRAME16k ) ) { - SWITCH ( output_frame ) + SWITCH( output_frame ) { - case L_FRAME8k: - filtIdx = 4; - move16(); - BREAK; - case L_FRAME16k: - filtIdx = 5; - move16(); - BREAK; - case L_FRAME32k: - filtIdx = 6; - move16(); - BREAK; - case L_FRAME48k: - filtIdx = 7; - move16(); - BREAK; - default: - assert(0); + case L_FRAME8k: + filtIdx = 4; + move16(); + BREAK; + case L_FRAME16k: + filtIdx = 5; + move16(); + BREAK; + case L_FRAME32k: + filtIdx = 6; + move16(); + BREAK; + case L_FRAME48k: + filtIdx = 7; + move16(); + BREAK; + default: + assert( 0 ); } } - ELSE IF (EQ_16(L_frame_core, 512)) + ELSE IF( EQ_16( L_frame_core, 512 ) ) { - SWITCH ( output_frame ) + SWITCH( output_frame ) { - case L_FRAME8k: - filtIdx = 8; - move16(); - BREAK; - case L_FRAME16k: - filtIdx = 9; - move16(); - BREAK; - case L_FRAME32k: - filtIdx = 10; - move16(); - BREAK; - case L_FRAME48k: - filtIdx = 11; - move16(); - BREAK; - default: - assert(0); + case L_FRAME8k: + filtIdx = 8; + move16(); + BREAK; + case L_FRAME16k: + filtIdx = 9; + move16(); + BREAK; + case L_FRAME32k: + filtIdx = 10; + move16(); + BREAK; + case L_FRAME48k: + filtIdx = 11; + move16(); + BREAK; + default: + assert( 0 ); } } ELSE @@ -1532,76 +1537,76 @@ void tcx_ltp_post( /******** Previous-frame part ********/ tcx_ltp_synth_filter( sig_out, sig_in, delay, hTcxLtpDec->tcxltp_pitch_int_post_prev, hTcxLtpDec->tcxltp_pitch_fr_post_prev, hTcxLtpDec->tcxltp_gain_post_prev, - st->pit_res_max_past, NULL, 0, hTcxLtpDec->tcxltp_filt_idx_prev); + st->pit_res_max_past, NULL, 0, hTcxLtpDec->tcxltp_filt_idx_prev ); /******** Transition part ********/ test(); test(); test(); -//#ifdef IVAS_CODE_TCX_LTP - if (st->element_mode != EVS_MONO) + //#ifdef IVAS_CODE_TCX_LTP + if ( st->element_mode != EVS_MONO ) { - if (gain == 0 && hTcxLtpDec->tcxltp_gain_post_prev == 0) + if ( gain == 0 && hTcxLtpDec->tcxltp_gain_post_prev == 0 ) { /* The filtering is deactivated, just copy input to the output */ - Copy(sig_in + delay, sig_out + delay, L_transition); + Copy( sig_in + delay, sig_out + delay, L_transition ); } - else if (gain == 0 && hTcxLtpDec->tcxltp_gain_post_prev != 0) + else if ( gain == 0 && hTcxLtpDec->tcxltp_gain_post_prev != 0 ) { /* Filtering with the first filter unit */ - tcx_ltp_synth_filter_10(sig_out + delay, sig_in + delay, L_transition, hTcxLtpDec->tcxltp_pitch_int_post_prev, hTcxLtpDec->tcxltp_pitch_fr_post_prev, hTcxLtpDec->tcxltp_gain_post_prev, st->pit_res_max_past, hTcxLtpDec->tcxltp_filt_idx_prev); + tcx_ltp_synth_filter_10( sig_out + delay, sig_in + delay, L_transition, hTcxLtpDec->tcxltp_pitch_int_post_prev, hTcxLtpDec->tcxltp_pitch_fr_post_prev, hTcxLtpDec->tcxltp_gain_post_prev, st->pit_res_max_past, hTcxLtpDec->tcxltp_filt_idx_prev ); } - else if (gain != 0 && hTcxLtpDec->tcxltp_gain_post_prev == 0) + else if ( gain != 0 && hTcxLtpDec->tcxltp_gain_post_prev == 0 ) { /* Filtering with the second filter unit */ - tcx_ltp_synth_filter_01(sig_out + delay, sig_in + delay, L_transition, pitch_int, pitch_fr, gain, st->pit_res_max, filtIdx); + tcx_ltp_synth_filter_01( sig_out + delay, sig_in + delay, L_transition, pitch_int, pitch_fr, gain, st->pit_res_max, filtIdx ); } - else if (gain == hTcxLtpDec->tcxltp_gain_post_prev && pitch_int == hTcxLtpDec->tcxltp_pitch_int_post_prev && pitch_fr == hTcxLtpDec->tcxltp_pitch_fr_post_prev && st->pit_res_max == st->pit_res_max_past && filtIdx == hTcxLtpDec->tcxltp_filt_idx_prev) + else if ( gain == hTcxLtpDec->tcxltp_gain_post_prev && pitch_int == hTcxLtpDec->tcxltp_pitch_int_post_prev && pitch_fr == hTcxLtpDec->tcxltp_pitch_fr_post_prev && st->pit_res_max == st->pit_res_max_past && filtIdx == hTcxLtpDec->tcxltp_filt_idx_prev ) { tcx_ltp_synth_filter( sig_out + delay, sig_in + delay, L_transition, pitch_int, pitch_fr, gain, st->pit_res_max, NULL, 0, filtIdx ); } else { /* Filtering with the first filter unit, followed by the filtering with the second filter unit */ - tcx_ltp_synth_filter_11_unequal_pitch(sig_out + delay, sig_in + delay, L_transition, pitch_int, pitch_fr, gain, st->pit_res_max, filtIdx, - hTcxLtpDec->tcxltp_pitch_int_post_prev, hTcxLtpDec->tcxltp_pitch_fr_post_prev, hTcxLtpDec->tcxltp_gain_post_prev, st->pit_res_max_past, hTcxLtpDec->tcxltp_filt_idx_prev); + tcx_ltp_synth_filter_11_unequal_pitch( sig_out + delay, sig_in + delay, L_transition, pitch_int, pitch_fr, gain, st->pit_res_max, filtIdx, + hTcxLtpDec->tcxltp_pitch_int_post_prev, hTcxLtpDec->tcxltp_pitch_fr_post_prev, hTcxLtpDec->tcxltp_gain_post_prev, st->pit_res_max_past, hTcxLtpDec->tcxltp_filt_idx_prev ); } } ELSE -//#endif + //#endif { - IF(gain == 0 && hTcxLtpDec->tcxltp_gain_post_prev == 0) + IF( gain == 0 && hTcxLtpDec->tcxltp_gain_post_prev == 0 ) { - Copy(sig_in + delay, sig_out + delay, L_transition); + Copy( sig_in + delay, sig_out + delay, L_transition ); } - ELSE IF(hTcxLtpDec->tcxltp_gain_post_prev == 0) + ELSE IF( hTcxLtpDec->tcxltp_gain_post_prev == 0 ) { - tcx_ltp_synth_filter(sig_out + delay, sig_in + delay, L_transition, pitch_int, + tcx_ltp_synth_filter( sig_out + delay, sig_in + delay, L_transition, pitch_int, pitch_fr, gain, st->pit_res_max, NULL, 1, filtIdx ); } - ELSE IF(gain == 0) + ELSE IF( gain == 0 ) { - tcx_ltp_synth_filter(sig_out + delay,sig_in + delay,L_transition, hTcxLtpDec->tcxltp_pitch_int_post_prev, hTcxLtpDec->tcxltp_pitch_fr_post_prev, - hTcxLtpDec->tcxltp_gain_post_prev, st->pit_res_max_past, NULL, -1, hTcxLtpDec->tcxltp_filt_idx_prev); + tcx_ltp_synth_filter( sig_out + delay, sig_in + delay, L_transition, hTcxLtpDec->tcxltp_pitch_int_post_prev, hTcxLtpDec->tcxltp_pitch_fr_post_prev, + hTcxLtpDec->tcxltp_gain_post_prev, st->pit_res_max_past, NULL, -1, hTcxLtpDec->tcxltp_filt_idx_prev ); } - ELSE IF(EQ_16(gain, hTcxLtpDec->tcxltp_gain_post_prev) && EQ_16(pitch_int,hTcxLtpDec->tcxltp_pitch_int_post_prev) && EQ_16(pitch_fr,hTcxLtpDec->tcxltp_pitch_fr_post_prev)) + ELSE IF( EQ_16( gain, hTcxLtpDec->tcxltp_gain_post_prev ) && EQ_16( pitch_int, hTcxLtpDec->tcxltp_pitch_int_post_prev ) && EQ_16( pitch_fr, hTcxLtpDec->tcxltp_pitch_fr_post_prev ) ) { - tcx_ltp_synth_filter(sig_out + delay, sig_in + delay, L_transition, pitch_int, pitch_fr, gain, st->pit_res_max, NULL, 0, filtIdx ); + tcx_ltp_synth_filter( sig_out + delay, sig_in + delay, L_transition, pitch_int, pitch_fr, gain, st->pit_res_max, NULL, 0, filtIdx ); } ELSE { - tcx_ltp_get_lpc(sig_out + delay - output_frame, output_frame, A, lpcorder); + tcx_ltp_get_lpc( sig_out + delay - output_frame, output_frame, A, lpcorder ); - tcx_ltp_get_zir(zir, L_transition, sig_out + delay - lpcorder, sig_in + delay - lpcorder, A, lpcorder, gain, pitch_int, pitch_fr, st->pit_res_max, filtIdx); + tcx_ltp_get_zir( zir, L_transition, sig_out + delay - lpcorder, sig_in + delay - lpcorder, A, lpcorder, gain, pitch_int, pitch_fr, st->pit_res_max, filtIdx ); - tcx_ltp_synth_filter(sig_out + delay, sig_in + delay, L_transition, pitch_int, pitch_fr, gain, st->pit_res_max, zir, 0, filtIdx); + tcx_ltp_synth_filter( sig_out + delay, sig_in + delay, L_transition, pitch_int, pitch_fr, gain, st->pit_res_max, zir, 0, filtIdx ); } } /******** Current-frame part - subsequent subinterval, filtered with the third filter unit ********/ - tcx_ltp_synth_filter( sig_out+(delay+L_transition),sig_in+(delay+L_transition), output_frame-(delay+L_transition), pitch_int, pitch_fr, gain, st->pit_res_max, NULL, 0, filtIdx); + tcx_ltp_synth_filter( sig_out + ( delay + L_transition ), sig_in + ( delay + L_transition ), output_frame - ( delay + L_transition ), pitch_int, pitch_fr, gain, st->pit_res_max, NULL, 0, filtIdx ); /******** Output ********/ @@ -1622,7 +1627,6 @@ void tcx_ltp_post( move16(); st->pit_res_max_past = st->pit_res_max; Copy( sig_out, hTcxLtpDec->tcxltp_mem_out, output_frame ); - } @@ -1733,14 +1737,14 @@ void tcx_ltp_post32( ELSE IF( bfi == 0 ) { /* LTP and good frame */ - IF( NE_16( output_frame, L_frame_core ) ) - { - tmp = div_s( output_frame, shl( L_frame_core, 2 ) ); /* Q13 */ - tmp32 = L_mult0( add( imult1616( pitch_int, st->pit_res_max ), pitch_fr ), tmp ); /* Q13 */ - tmp = round_fx( L_shl( tmp32, 3 ) ); /* Q0 */ - pitch_int = idiv1616U( tmp, st->pit_res_max ); - pitch_fr = sub( tmp, imult1616( pitch_int, st->pit_res_max ) ); - } + IF( NE_16( output_frame, L_frame_core ) ) + { + tmp = div_s( output_frame, shl( L_frame_core, 2 ) ); /* Q13 */ + tmp32 = L_mult0( add( imult1616( pitch_int, st->pit_res_max ), pitch_fr ), tmp ); /* Q13 */ + tmp = round_fx( L_shl( tmp32, 3 ) ); /* Q0 */ + pitch_int = idiv1616U( tmp, st->pit_res_max ); + pitch_fr = sub( tmp, imult1616( pitch_int, st->pit_res_max ) ); + } IF( EQ_16( st->element_mode, EVS_MONO ) ) /* hard tunings for EVS_MONO, HQ_48k is TCX only */ { test(); diff --git a/lib_com/tcx_mdct_fx.c b/lib_com/tcx_mdct_fx.c index dad45f8a8..76f8e414a 100644 --- a/lib_com/tcx_mdct_fx.c +++ b/lib_com/tcx_mdct_fx.c @@ -10,28 +10,27 @@ #include "basop_util.h" static Word16 TCX_MDCT_GetScaleFactor( - const Word16 L, - Word16 *factor_e -) + const Word16 L, + Word16 *factor_e ) { Word16 factor; - IF(EQ_16(L, NORM_MDCT_FACTOR)) + IF( EQ_16( L, NORM_MDCT_FACTOR ) ) { factor = 32767; move16(); *factor_e = 0; move16(); } - ELSE IF(EQ_16(L, 2*NORM_MDCT_FACTOR)) + ELSE IF( EQ_16( L, 2 * NORM_MDCT_FACTOR ) ) { factor = 23170; move16(); *factor_e = 0; move16(); } - ELSE IF(EQ_16(L, 4*NORM_MDCT_FACTOR)) + ELSE IF( EQ_16( L, 4 * NORM_MDCT_FACTOR ) ) { factor = 16384; move16(); @@ -41,39 +40,38 @@ static Word16 TCX_MDCT_GetScaleFactor( ELSE { - factor = mult_r(shl(L, 4), 26214 /*128.f / NORM_MDCT_FACTOR*/); /* 4Q11 */ + factor = mult_r( shl( L, 4 ), 26214 /*128.f / NORM_MDCT_FACTOR*/ ); /* 4Q11 */ *factor_e = 4; move16(); - factor = ISqrt16(factor, factor_e); + factor = ISqrt16( factor, factor_e ); } return factor; } static Word16 TCX_MDCT_Inverse_GetScaleFactor( - const Word16 L, - Word16 *factor_e -) + const Word16 L, + Word16 *factor_e ) { Word16 factor; - IF(EQ_16(L, NORM_MDCT_FACTOR)) + IF( EQ_16( L, NORM_MDCT_FACTOR ) ) { factor = 32767; move16(); *factor_e = 0; move16(); } - ELSE IF(EQ_16(L, 2*NORM_MDCT_FACTOR)) + ELSE IF( EQ_16( L, 2 * NORM_MDCT_FACTOR ) ) { factor = 23170; move16(); *factor_e = 1; move16(); } - ELSE IF(EQ_16(L, 4*NORM_MDCT_FACTOR)) + ELSE IF( EQ_16( L, 4 * NORM_MDCT_FACTOR ) ) { factor = 32767; move16(); @@ -82,11 +80,11 @@ static Word16 TCX_MDCT_Inverse_GetScaleFactor( } ELSE { - factor = mult_r(shl(L, 4), 26214 /*128.f / NORM_MDCT_FACTOR*/); /* 4Q11 */ + factor = mult_r( shl( L, 4 ), 26214 /*128.f / NORM_MDCT_FACTOR*/ ); /* 4Q11 */ *factor_e = 4; move16(); - factor = Sqrt16(factor, factor_e); + factor = Sqrt16( factor, factor_e ); } return factor; @@ -94,115 +92,111 @@ static Word16 TCX_MDCT_Inverse_GetScaleFactor( void TCX_MDCT( - const Word16 *x, - Word32 *y, - Word16* y_e, - const Word16 l, - const Word16 m, - const Word16 r, - const Word16 element_mode -) + const Word16 *x, + Word32 *y, + Word16 *y_e, + const Word16 l, + const Word16 m, + const Word16 r, + const Word16 element_mode ) { Word16 i; Word16 factor, neg_factor; Word16 factor_e; #ifdef REMOVE_IVAS_UNUSED_PARAMETERS_WARNING - (void)element_mode; + (void) element_mode; #endif #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - factor = TCX_MDCT_GetScaleFactor(add(add(shr(l, 1), m), shr(r, 1)), &factor_e); - *y_e = add(*y_e, factor_e); + factor = TCX_MDCT_GetScaleFactor( add( add( shr( l, 1 ), m ), shr( r, 1 ) ), &factor_e ); + *y_e = add( *y_e, factor_e ); - neg_factor = negate(factor); + neg_factor = negate( factor ); /* Init */ - FOR(i=0; iv.im = *p1; - move16(); - window1_trunc++; - p1 += d; - } + FOR( i = 0; i < n0; i++ ) + { + *window1 = *p1; + move16(); + window1++; + p1 += d; + } + + tmp = shr( n, 1 ); + FOR( ; i < tmp; i++ ) + { + window1_trunc->v.im = *p1; + move16(); + window1_trunc++; + p1 += d; + } - test(); - if (EQ_16(n, 512 / 2) || EQ_16(n, 320 / 2))p1++; + test(); + if ( EQ_16( n, 512 / 2 ) || EQ_16( n, 320 / 2 ) ) + p1++; - FOR(; i < n1; i++) + FOR( ; i < n1; i++ ) + { + window1_trunc--; + window1_trunc->v.re = *p1; + move16(); + p1 += d; + } + } + ELSE { - window1_trunc--; - window1_trunc->v.re = *p1; - move16(); - p1 += d; + const Word16 *pi = window_8_16_32kHz_fx; + + FOR( i = 0; i < n0; i += 2 ) + { + *window1 = *p1; + move16(); + window1++; + p1 += d; + + *window1 = *pi; + move16(); + window1++; + pi++; + } + + tmp = shr( n, 1 ); + FOR( ; i < tmp; i += 2 ) + { + window1_trunc->v.im = *p1; + move16(); + window1_trunc++; + p1 += d; + + window1_trunc->v.im = *pi; + move16(); + window1_trunc++; + pi++; + } + + FOR( ; i < n1; i += 2 ) + { + window1_trunc--; + window1_trunc->v.re = *pi; + move16(); + pi++; + + window1_trunc--; + window1_trunc->v.re = *p1; + move16(); + p1 += d; + } } - } - ELSE - { - const Word16 *pi = window_8_16_32kHz_fx; - - FOR(i = 0; i < n0; i += 2) - { - *window1 = *p1; - move16(); - window1++; - p1 += d; - - *window1 = *pi; - move16(); - window1++; - pi++; - } - - tmp = shr(n, 1); - FOR(; i < tmp; i += 2) - { - window1_trunc->v.im = *p1; - move16(); - window1_trunc++; - p1 += d; - - window1_trunc->v.im = *pi; - move16(); - window1_trunc++; - pi++; - } - - FOR(; i < n1; i += 2) - { - window1_trunc--; - window1_trunc->v.re = *pi; - move16(); - pi++; - - window1_trunc--; - window1_trunc->v.re = *p1; - move16(); - p1 += d; - } - } /* second part (short slope) */ - IF(NE_16(n, 1280 / 2)) - { - tmp = shr(n2, 1); - FOR(i = 0; i < tmp; i++) + IF( NE_16( n, 1280 / 2 ) ) { - window2->v.im = *p2; - move16(); - window2++; - p2 -= d; - } + tmp = shr( n2, 1 ); + FOR( i = 0; i < tmp; i++ ) + { + window2->v.im = *p2; + move16(); + window2++; + p2 -= d; + } - test(); - if (EQ_16(n, 512 / 2) || EQ_16(n, 320 / 2))p2--; + test(); + if ( EQ_16( n, 512 / 2 ) || EQ_16( n, 320 / 2 ) ) + p2--; - FOR(; i < n2; i++) + FOR( ; i < n2; i++ ) + { + window2--; + window2->v.re = *p2; + move16(); + p2 -= d; + } + } + ELSE { - window2--; - window2->v.re = *p2; - move16(); - p2 -= d; + const Word16 *pi = window_8_16_32kHz_fx + 370 - 1; + + tmp = shr( n2, 1 ); + FOR( i = 0; i < tmp; i += 2 ) + { + window2->v.im = *p2; + move16(); + window2++; + p2 -= d; + + window2->v.im = *pi; + move16(); + window2++; + pi--; + } + + FOR( ; i < n2; i += 2 ) + { + window2--; + window2->v.re = *pi; + move16(); + pi--; + + window2--; + window2->v.re = *p2; + move16(); + p2 -= d; + } } - } - ELSE - { - const Word16 *pi = window_8_16_32kHz_fx + 370 - 1; - - tmp = shr(n2, 1); - FOR(i = 0; i < tmp; i += 2) - { - window2->v.im = *p2; - move16(); - window2++; - p2 -= d; - - window2->v.im = *pi; - move16(); - window2++; - pi--; - } - - FOR(; i < n2; i += 2) - { - window2--; - window2->v.re = *pi; - move16(); - pi--; - - window2--; - window2->v.re = *p2; - move16(); - p2 -= d; - } - } -} \ No newline at end of file +} diff --git a/lib_com/tcx_utils_fx.c b/lib_com/tcx_utils_fx.c index 3107ee760..1932730ac 100644 --- a/lib_com/tcx_utils_fx.c +++ b/lib_com/tcx_utils_fx.c @@ -14,27 +14,26 @@ #define inv_int InvIntTable - /*-------------------------------------------------------------------* - * getInvFrameLen() - * - * - *-------------------------------------------------------------------*/ -Word16 getInvFrameLen( /* returns 1/L_frame in Q21 format */ - const Word16 L_frame -) +/*-------------------------------------------------------------------* + * getInvFrameLen() + * + * + *-------------------------------------------------------------------*/ +Word16 getInvFrameLen( /* returns 1/L_frame in Q21 format */ + const Word16 L_frame ) { Word16 idx, s; - s = norm_s(L_frame); - idx = shl(L_frame, s); + s = norm_s( L_frame ); + idx = shl( L_frame, s ); - assert((idx == 0x4000) || (idx == 0x4B00) || (idx == 0x5000) || (idx == 0x5A00) || (idx == 0x6000) || (idx == 0x6400) || (idx == 0x7800)); + assert( ( idx == 0x4000 ) || ( idx == 0x4B00 ) || ( idx == 0x5000 ) || ( idx == 0x5A00 ) || ( idx == 0x6000 ) || ( idx == 0x6400 ) || ( idx == 0x7800 ) ); - idx = mult_r(idx, 0x10); /* idx = shr(add(idx, 0x0400), 11); */ - idx = s_and(idx, 7); + idx = mult_r( idx, 0x10 ); /* idx = shr(add(idx, 0x0400), 11); */ + idx = s_and( idx, 7 ); - return shl(L_frame_inv[idx], sub(s, 7)); + return shl( L_frame_inv[idx], sub( s, 7 ) ); } /*-------------------------------------------------------------------* *tcx_get_windows() @@ -43,175 +42,177 @@ Word16 getInvFrameLen( /* returns 1/L_frame in Q21 format */ * ------------------------------------------------------------------ - */ static void tcx_get_windows( TCX_CONFIG_HANDLE hTcxCfg, /* i : TCX configuration */ - const Word16 left_mode, /* i: overlap mode of left window half */ - const Word16 right_mode, /* i: overlap mode of right window half */ - Word16 *left_overlap, /* o: left overlap length */ - const PWord16 **left_win, /* o: left overlap window */ - Word16 *right_overlap, /* o: right overlap length */ - const PWord16 **right_win, /* o: right overlap window */ - const Word8 fullband /* i: fullband flag */ + const Word16 left_mode, /* i: overlap mode of left window half */ + const Word16 right_mode, /* i: overlap mode of right window half */ + Word16 *left_overlap, /* o: left overlap length */ + const PWord16 **left_win, /* o: left overlap window */ + Word16 *right_overlap, /* o: right overlap length */ + const PWord16 **right_win, /* o: right overlap window */ + const Word8 fullband /* i: fullband flag */ ) -{ /* LFE is only FULL_OVERLAP*/ - IF (fullband == 0) +{ /* LFE is only FULL_OVERLAP*/ + IF( fullband == 0 ) { /* Left part */ - SWITCH (left_mode) + SWITCH( left_mode ) { - case TRANSITION_OVERLAP: /* ACELP->TCX transition */ - *left_overlap = hTcxCfg->tcx_mdct_window_trans_length; - move16(); - *left_win = hTcxCfg->tcx_mdct_window_trans; - BREAK; - case MIN_OVERLAP: - *left_overlap = hTcxCfg->tcx_mdct_window_min_length; - move16(); - *left_win = hTcxCfg->tcx_mdct_window_minimum; - BREAK; - case HALF_OVERLAP: - *left_overlap = hTcxCfg->tcx_mdct_window_half_length; - move16(); - *left_win = hTcxCfg->tcx_mdct_window_half; - BREAK; - case FULL_OVERLAP: - *left_overlap = hTcxCfg->tcx_mdct_window_length; - move16(); - *left_win = hTcxCfg->tcx_aldo_window_1_trunc; - move16(); - BREAK; - default: - assert(!"Not supported overlap"); + case TRANSITION_OVERLAP: /* ACELP->TCX transition */ + *left_overlap = hTcxCfg->tcx_mdct_window_trans_length; + move16(); + *left_win = hTcxCfg->tcx_mdct_window_trans; + BREAK; + case MIN_OVERLAP: + *left_overlap = hTcxCfg->tcx_mdct_window_min_length; + move16(); + *left_win = hTcxCfg->tcx_mdct_window_minimum; + BREAK; + case HALF_OVERLAP: + *left_overlap = hTcxCfg->tcx_mdct_window_half_length; + move16(); + *left_win = hTcxCfg->tcx_mdct_window_half; + BREAK; + case FULL_OVERLAP: + *left_overlap = hTcxCfg->tcx_mdct_window_length; + move16(); + *left_win = hTcxCfg->tcx_aldo_window_1_trunc; + move16(); + BREAK; + default: + assert( !"Not supported overlap" ); } /* Right part */ - SWITCH(right_mode) + SWITCH( right_mode ) { - case MIN_OVERLAP: - *right_overlap = hTcxCfg->tcx_mdct_window_min_length; - move16(); - *right_win = hTcxCfg->tcx_mdct_window_minimum; - BREAK; - case HALF_OVERLAP: - *right_overlap = hTcxCfg->tcx_mdct_window_half_length; - move16(); - *right_win = hTcxCfg->tcx_mdct_window_half; - BREAK; - case FULL_OVERLAP: - *right_overlap = hTcxCfg->tcx_mdct_window_delay; - move16(); - *right_win = hTcxCfg->tcx_aldo_window_2; - move16(); - BREAK; - default: - assert(!"Not supported overlap"); + case MIN_OVERLAP: + *right_overlap = hTcxCfg->tcx_mdct_window_min_length; + move16(); + *right_win = hTcxCfg->tcx_mdct_window_minimum; + BREAK; + case HALF_OVERLAP: + *right_overlap = hTcxCfg->tcx_mdct_window_half_length; + move16(); + *right_win = hTcxCfg->tcx_mdct_window_half; + BREAK; + case FULL_OVERLAP: + *right_overlap = hTcxCfg->tcx_mdct_window_delay; + move16(); + *right_win = hTcxCfg->tcx_aldo_window_2; + move16(); + BREAK; + default: + assert( !"Not supported overlap" ); } } ELSE { /* Left part */ - SWITCH (left_mode) + SWITCH( left_mode ) { - case TRANSITION_OVERLAP: /* ACELP->TCX transition */ - *left_overlap = hTcxCfg->tcx_mdct_window_trans_lengthFB; - move16(); - *left_win = hTcxCfg->tcx_mdct_window_transFB; - BREAK; - case MIN_OVERLAP: - *left_overlap = hTcxCfg->tcx_mdct_window_min_lengthFB; - move16(); - *left_win = hTcxCfg->tcx_mdct_window_minimumFB; - BREAK; - case HALF_OVERLAP: - *left_overlap = hTcxCfg->tcx_mdct_window_half_lengthFB; - move16(); - *left_win = hTcxCfg->tcx_mdct_window_halfFB; - BREAK; - case RECTANGULAR_OVERLAP: - *left_overlap = 0; - move16(); - *left_win = NULL; - BREAK; - case FULL_OVERLAP: - *left_overlap = hTcxCfg->tcx_mdct_window_lengthFB; - *left_win = hTcxCfg->tcx_aldo_window_1_FB_trunc; - move16();move16(); + case TRANSITION_OVERLAP: /* ACELP->TCX transition */ + *left_overlap = hTcxCfg->tcx_mdct_window_trans_lengthFB; + move16(); + *left_win = hTcxCfg->tcx_mdct_window_transFB; + BREAK; + case MIN_OVERLAP: + *left_overlap = hTcxCfg->tcx_mdct_window_min_lengthFB; + move16(); + *left_win = hTcxCfg->tcx_mdct_window_minimumFB; + BREAK; + case HALF_OVERLAP: + *left_overlap = hTcxCfg->tcx_mdct_window_half_lengthFB; + move16(); + *left_win = hTcxCfg->tcx_mdct_window_halfFB; + BREAK; + case RECTANGULAR_OVERLAP: + *left_overlap = 0; + move16(); + *left_win = NULL; + BREAK; + case FULL_OVERLAP: + *left_overlap = hTcxCfg->tcx_mdct_window_lengthFB; + *left_win = hTcxCfg->tcx_aldo_window_1_FB_trunc; + move16(); + move16(); - BREAK; - default: - assert(!"Not supported overlap"); + BREAK; + default: + assert( !"Not supported overlap" ); } /* Right part */ - SWITCH (right_mode) + SWITCH( right_mode ) { - case MIN_OVERLAP: - *right_overlap = hTcxCfg->tcx_mdct_window_min_lengthFB; - move16(); - *right_win = hTcxCfg->tcx_mdct_window_minimumFB; - BREAK; - case HALF_OVERLAP: - *right_overlap = hTcxCfg->tcx_mdct_window_half_lengthFB; - move16(); - *right_win = hTcxCfg->tcx_mdct_window_halfFB; - BREAK; - case RECTANGULAR_OVERLAP: - *right_overlap = 0; - move16(); - *right_win = NULL; - BREAK; - case FULL_OVERLAP: - *right_overlap = hTcxCfg->tcx_mdct_window_delayFB; - move16();move16(); - *right_win = hTcxCfg->tcx_aldo_window_2_FB; - BREAK; - default: - assert(!"Not supported overlap"); + case MIN_OVERLAP: + *right_overlap = hTcxCfg->tcx_mdct_window_min_lengthFB; + move16(); + *right_win = hTcxCfg->tcx_mdct_window_minimumFB; + BREAK; + case HALF_OVERLAP: + *right_overlap = hTcxCfg->tcx_mdct_window_half_lengthFB; + move16(); + *right_win = hTcxCfg->tcx_mdct_window_halfFB; + BREAK; + case RECTANGULAR_OVERLAP: + *right_overlap = 0; + move16(); + *right_win = NULL; + BREAK; + case FULL_OVERLAP: + *right_overlap = hTcxCfg->tcx_mdct_window_delayFB; + move16(); + move16(); + *right_win = hTcxCfg->tcx_aldo_window_2_FB; + BREAK; + default: + assert( !"Not supported overlap" ); } } } static void tcx_windowing_analysis( - Word16 const *signal, /* i: signal vector */ - Word16 L_frame, /* i: frame length */ - Word16 left_overlap, /* i: left overlap length */ - PWord16 const *left_win, /* i: left overlap window */ - Word16 right_overlap, /* i: right overlap length */ - PWord16 const *right_win, /* i: right overlap window */ - Word16 *output /* o: windowed signal vector */ + Word16 const *signal, /* i: signal vector */ + Word16 L_frame, /* i: frame length */ + Word16 left_overlap, /* i: left overlap length */ + PWord16 const *left_win, /* i: left overlap window */ + Word16 right_overlap, /* i: right overlap length */ + PWord16 const *right_win, /* i: right overlap window */ + Word16 *output /* o: windowed signal vector */ ) { Word16 w, n; /* Left overlap */ - n = shr(left_overlap, 1); - FOR (w = 0; w < n; w++) + n = shr( left_overlap, 1 ); + FOR( w = 0; w < n; w++ ) { - *output++ = mult_r(*signal++, left_win[w].v.im); + *output++ = mult_r( *signal++, left_win[w].v.im ); move16(); } - FOR (w = 0; w < n; w++) + FOR( w = 0; w < n; w++ ) { - *output++ = mult_r(*signal++, left_win[n-1-w].v.re); + *output++ = mult_r( *signal++, left_win[n - 1 - w].v.re ); move16(); } /* Non overlapping region */ - n = sub(L_frame, shr(add(left_overlap, right_overlap), 1)); - FOR (w = 0; w < n; w++) + n = sub( L_frame, shr( add( left_overlap, right_overlap ), 1 ) ); + FOR( w = 0; w < n; w++ ) { *output++ = *signal++; move16(); } /* Right overlap */ - n = shr(right_overlap, 1); - FOR (w = 0; w < n; w++) + n = shr( right_overlap, 1 ); + FOR( w = 0; w < n; w++ ) { - *output++ = mult_r(*signal++, right_win[w].v.re); + *output++ = mult_r( *signal++, right_win[w].v.re ); move16(); } - FOR (w = 0; w < n; w++) + FOR( w = 0; w < n; w++ ) { - *output++ = mult_r(*signal++, right_win[n-1-w].v.im); + *output++ = mult_r( *signal++, right_win[n - 1 - w].v.im ); move16(); } } @@ -221,47 +222,47 @@ static void tcx_windowing_analysis( * *-------------------------------------------------------------------*/ void WindowSignal( - TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */ - Word16 offset, /* i : left folding point offset relative to the input signal pointer */ - const Word16 left_overlap_mode, /* i : overlap mode of left window half */ - Word16 right_overlap_mode, /* i : overlap mode of right window half */ - Word16 * left_overlap_length, /* o : TCX window left overlap length */ - Word16 * right_overlap_length, /* o : TCX window right overlap length */ - const Word16 in[], /* i : input signal */ - Word16 * L_frame, /* i/o: frame length */ - Word16 out[], /* o : output windowed signal */ - const Word16 truncate_aldo, /* i : nonzero to truncate long ALDO slope */ - const Word8 fullband /* i : fullband flag */ + TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */ + Word16 offset, /* i : left folding point offset relative to the input signal pointer */ + const Word16 left_overlap_mode, /* i : overlap mode of left window half */ + Word16 right_overlap_mode, /* i : overlap mode of right window half */ + Word16 *left_overlap_length, /* o : TCX window left overlap length */ + Word16 *right_overlap_length, /* o : TCX window right overlap length */ + const Word16 in[], /* i : input signal */ + Word16 *L_frame, /* i/o: frame length */ + Word16 out[], /* o : output windowed signal */ + const Word16 truncate_aldo, /* i : nonzero to truncate long ALDO slope */ + const Word8 fullband /* i : fullband flag */ ) { Word16 l, r; - PWord16 const * left_win; - PWord16 const * right_win; + PWord16 const *left_win; + PWord16 const *right_win; /*-----------------------------------------------------------* * Init * *-----------------------------------------------------------*/ - tcx_get_windows(hTcxCfg, left_overlap_mode, right_overlap_mode, &l, &left_win, &r, &right_win, fullband); + tcx_get_windows( hTcxCfg, left_overlap_mode, right_overlap_mode, &l, &left_win, &r, &right_win, fullband ); /* Init lengths */ /* if past frame is ACELP */ - IF (EQ_16(left_overlap_mode, TRANSITION_OVERLAP)) + IF( EQ_16( left_overlap_mode, TRANSITION_OVERLAP ) ) { /* Increase frame size for 5ms */ - IF (fullband == 0) + IF( fullband == 0 ) { - *L_frame = add(*L_frame, hTcxCfg->tcx5Size); + *L_frame = add( *L_frame, hTcxCfg->tcx5Size ); move16(); - offset = negate(shr(hTcxCfg->tcx_mdct_window_trans_length, 1)); + offset = negate( shr( hTcxCfg->tcx_mdct_window_trans_length, 1 ) ); } ELSE { - *L_frame = add(*L_frame, hTcxCfg->tcx5SizeFB); + *L_frame = add( *L_frame, hTcxCfg->tcx5SizeFB ); move16(); - offset = negate(shr(hTcxCfg->tcx_mdct_window_trans_lengthFB, 1)); + offset = negate( shr( hTcxCfg->tcx_mdct_window_trans_lengthFB, 1 ) ); } } @@ -269,30 +270,31 @@ void WindowSignal( * Windowing * *-----------------------------------------------------------*/ - tcx_windowing_analysis(in-shr(l,1)+offset, *L_frame, l, left_win, r, right_win, out); - test(); test(); - IF (EQ_16(left_overlap_mode, FULL_OVERLAP) && truncate_aldo ) + tcx_windowing_analysis( in - shr( l, 1 ) + offset, *L_frame, l, left_win, r, right_win, out ); + test(); + test(); + IF( EQ_16( left_overlap_mode, FULL_OVERLAP ) && truncate_aldo ) { /* fade truncated ALDO window to avoid discontinuities */ Word16 i, tmp; const PWord16 *p; p = hTcxCfg->tcx_mdct_window_minimum; - tmp = shr(hTcxCfg->tcx_mdct_window_min_length, 1); - IF (fullband != 0) + tmp = shr( hTcxCfg->tcx_mdct_window_min_length, 1 ); + IF( fullband != 0 ) { p = hTcxCfg->tcx_mdct_window_minimumFB; - tmp = shr(hTcxCfg->tcx_mdct_window_min_lengthFB, 1); + tmp = shr( hTcxCfg->tcx_mdct_window_min_lengthFB, 1 ); } - FOR (i = 0; i < tmp; i++) + FOR( i = 0; i < tmp; i++ ) { - out[i] = mult_r(out[i], p[i].v.im); + out[i] = mult_r( out[i], p[i].v.im ); move16(); } - FOR (i = 0; i < tmp; i++) + FOR( i = 0; i < tmp; i++ ) { - out[i+tmp] = mult_r(out[i+tmp], p[tmp-1-i].v.re); + out[i + tmp] = mult_r( out[i + tmp], p[tmp - 1 - i].v.re ); move16(); } } @@ -301,7 +303,6 @@ void WindowSignal( move16(); *right_overlap_length = r; move16(); - } /*-------------------------------------------------------------------* * tcx_windowing_synthesis_current_frame() @@ -310,307 +311,304 @@ void WindowSignal( *-------------------------------------------------------------------*/ void tcx_windowing_synthesis_current_frame( - Word16 *signal, /* i/o: signal vector */ - const PWord16 *window, /* i: TCX window vector */ - const PWord16 *window_half, /* i: TCX window vector for half-overlap window */ - const PWord16 *window_min, /* i: TCX minimum overlap window */ - const Word16 window_length, /* i: TCX window length */ - const Word16 window_half_length, /* i: TCX half window length */ - const Word16 window_min_length, /* i: TCX minimum overlap length */ - const Word16 left_rect, /* i: left part is rectangular */ - const Word16 left_mode, /* i: overlap mode of left window half */ - Word16 *acelp_zir, /* i: acelp ZIR */ - const Word16* old_syn, - const Word16* syn_overl, - const Word16* A_zir, - const PWord16 *window_trans, + Word16 *signal, /* i/o: signal vector */ + const PWord16 *window, /* i: TCX window vector */ + const PWord16 *window_half, /* i: TCX window vector for half-overlap window */ + const PWord16 *window_min, /* i: TCX minimum overlap window */ + const Word16 window_length, /* i: TCX window length */ + const Word16 window_half_length, /* i: TCX half window length */ + const Word16 window_min_length, /* i: TCX minimum overlap length */ + const Word16 left_rect, /* i: left part is rectangular */ + const Word16 left_mode, /* i: overlap mode of left window half */ + Word16 *acelp_zir, /* i: acelp ZIR */ + const Word16 *old_syn, + const Word16 *syn_overl, + const Word16 *A_zir, + const PWord16 *window_trans, Word16 acelp_zir_len, const Word16 acelp_mem_len, - const Word16 last_core_bfi, /* i : last core */ + const Word16 last_core_bfi, /* i : last core */ const Word8 last_is_cng, - const Word16 fullbandScale -) + const Word16 fullbandScale ) { Word16 i, overlap, n, tmp, tmp2; - Word16 tmp_buf[L_FRAME_MAX/2]; + Word16 tmp_buf[L_FRAME_MAX / 2]; Word32 L_tmp; /* Init */ - overlap = shr(window_length, 1); + overlap = shr( window_length, 1 ); /* Past-frame is TCX concealed as CNG and current-frame is TCX */ test(); test(); test(); test(); - IF ( EQ_16(last_is_cng, 1)&&left_rect==0) + IF( EQ_16( last_is_cng, 1 ) && left_rect == 0 ) { - IF (!fullbandScale) + IF( !fullbandScale ) { - set16_fx(acelp_zir, 0, acelp_zir_len); - E_UTIL_synthesis(0, A_zir, acelp_zir, acelp_zir, acelp_zir_len, signal+overlap+acelp_mem_len-M, 0, M); + set16_fx( acelp_zir, 0, acelp_zir_len ); + E_UTIL_synthesis( 0, A_zir, acelp_zir, acelp_zir, acelp_zir_len, signal + overlap + acelp_mem_len - M, 0, M ); } ELSE { #ifdef BASOP_NOGLOB - lerp(acelp_zir, tmp_buf, acelp_zir_len, idiv1616U(shl_sat(acelp_zir_len, LD_FSCALE_DENOM), fullbandScale)); + lerp( acelp_zir, tmp_buf, acelp_zir_len, idiv1616U( shl_sat( acelp_zir_len, LD_FSCALE_DENOM ), fullbandScale ) ); #else - lerp(acelp_zir, tmp_buf, acelp_zir_len, idiv1616U(shl(acelp_zir_len, LD_FSCALE_DENOM), fullbandScale)); + lerp( acelp_zir, tmp_buf, acelp_zir_len, idiv1616U( shl( acelp_zir_len, LD_FSCALE_DENOM ), fullbandScale ) ); #endif acelp_zir = tmp_buf; } - FOR (i = 0; i < acelp_zir_len; i++) + FOR( i = 0; i < acelp_zir_len; i++ ) { /*signal[i] *= (float)(i)/(float)(acelp_zir_len); signal[i] += acelp_zir[i]*(float)(acelp_zir_len-i)/(float)(acelp_zir_len);*/ move16(); - signal[i] = add(mult_r(signal[i], div_s(i, acelp_zir_len)), mult_r(acelp_zir[i], div_s(sub(acelp_zir_len, i), acelp_zir_len))); + signal[i] = add( mult_r( signal[i], div_s( i, acelp_zir_len ) ), mult_r( acelp_zir[i], div_s( sub( acelp_zir_len, i ), acelp_zir_len ) ) ); } } /* Rectangular window (past-frame is ACELP) */ - ELSE IF ( EQ_16(left_rect, 1)&&last_core_bfi==ACELP_CORE) + ELSE IF( EQ_16( left_rect, 1 ) && last_core_bfi == ACELP_CORE ) { - tmp = sub(overlap,acelp_mem_len); - FOR (i=0; i< tmp ; i++) + tmp = sub( overlap, acelp_mem_len ); + FOR( i = 0; i < tmp; i++ ) { move16(); signal[i] = 0; } - IF (fullbandScale == 0) + IF( fullbandScale == 0 ) { - tmp = shl(acelp_mem_len, 1); + tmp = shl( acelp_mem_len, 1 ); /*OLA with ACELP*/ - FOR (i = 0; i < acelp_mem_len; i++) + FOR( i = 0; i < acelp_mem_len; i++ ) { /*window decoded TCX with aliasing*/ - tmp2 = mult_r(signal[i+overlap-acelp_mem_len], window_trans[i].v.im); + tmp2 = mult_r( signal[i + overlap - acelp_mem_len], window_trans[i].v.im ); /*Time TDAC: 1)forward part of ACELP*/ #ifdef BASOP_NOGLOB tmp2 = add_sat( tmp2, mult_r( old_syn[acelp_zir_len - tmp + i], mult_r( window_trans[i].v.re, window_trans[i].v.re ) ) ); /*Time TDAC: 1)reward part of ACELP*/ - tmp2 = add_sat(tmp2, mult_r(old_syn[acelp_zir_len-i-1], mult_r(window_trans[i].v.im, window_trans[i].v.re))); + tmp2 = add_sat( tmp2, mult_r( old_syn[acelp_zir_len - i - 1], mult_r( window_trans[i].v.im, window_trans[i].v.re ) ) ); #else - tmp2 = add(tmp2, mult_r(old_syn[acelp_zir_len-tmp+i], mult_r(window_trans[i].v.re, window_trans[i].v.re))); + tmp2 = add( tmp2, mult_r( old_syn[acelp_zir_len - tmp + i], mult_r( window_trans[i].v.re, window_trans[i].v.re ) ) ); /*Time TDAC: 1)reward part of ACELP*/ - tmp2 = add(tmp2, mult_r(old_syn[acelp_zir_len-i-1], mult_r(window_trans[i].v.im, window_trans[i].v.re))); + tmp2 = add( tmp2, mult_r( old_syn[acelp_zir_len - i - 1], mult_r( window_trans[i].v.im, window_trans[i].v.re ) ) ); #endif move16(); - signal[i+overlap-acelp_mem_len] = tmp2; + signal[i + overlap - acelp_mem_len] = tmp2; } - FOR ( ; i < tmp; i++) + FOR( ; i < tmp; i++ ) { /*window decoded TCX with aliasing*/ - tmp2 = mult_r(signal[i+overlap-acelp_mem_len], window_trans[tmp-1-i].v.re); + tmp2 = mult_r( signal[i + overlap - acelp_mem_len], window_trans[tmp - 1 - i].v.re ); /*Time TDAC: 1)forward part of ACELP*/ #ifdef BASOP_NOGLOB tmp2 = add_sat( tmp2, mult_r( old_syn[acelp_zir_len - tmp + i], mult_r( window_trans[tmp - 1 - i].v.im, window_trans[tmp - 1 - i].v.im ) ) ); #else - tmp2 = add(tmp2, mult_r(old_syn[acelp_zir_len-tmp+i], mult_r(window_trans[tmp-1-i].v.im, window_trans[tmp-1-i].v.im))); + tmp2 = add( tmp2, mult_r( old_syn[acelp_zir_len - tmp + i], mult_r( window_trans[tmp - 1 - i].v.im, window_trans[tmp - 1 - i].v.im ) ) ); #endif /*Time TDAC: 1)reward part of ACELP*/ #ifdef BASOP_NOGLOB tmp2 = add_sat( tmp2, mult_r( old_syn[acelp_zir_len - i - 1], mult_r( window_trans[tmp - 1 - i].v.re, window_trans[tmp - 1 - i].v.im ) ) ); #else - tmp2 = add(tmp2, mult_r(old_syn[acelp_zir_len-i-1], mult_r(window_trans[tmp-1-i].v.re, window_trans[tmp-1-i].v.im))); + tmp2 = add( tmp2, mult_r( old_syn[acelp_zir_len - i - 1], mult_r( window_trans[tmp - 1 - i].v.re, window_trans[tmp - 1 - i].v.im ) ) ); #endif move16(); - signal[i+overlap-acelp_mem_len] = tmp2; + signal[i + overlap - acelp_mem_len] = tmp2; } - FOR (i=0; i=0; i--) + FOR( i = acelp_zir_len - 3; i >= 0; i-- ) { - L_tmp = L_mult(acelp_zir[i], 13107); - L_tmp = L_mac(L_tmp, acelp_zir[i+1], 11469); - acelp_zir[i] = mac_r(L_tmp, acelp_zir[i+2], 8192); + L_tmp = L_mult( acelp_zir[i], 13107 ); + L_tmp = L_mac( L_tmp, acelp_zir[i + 1], 11469 ); + acelp_zir[i] = mac_r( L_tmp, acelp_zir[i + 2], 8192 ); move16(); } } } - FOR (i = 0; i < acelp_zir_len; i++) + FOR( i = 0; i < acelp_zir_len; i++ ) { /*remove reconstructed ZIR and add ACELP ZIR*/ move16(); #ifdef BASOP_NOGLOB signal[i + overlap + acelp_mem_len] = sub_sat( signal[i + overlap + acelp_mem_len], mult_r_sat( acelp_zir[i], div_s( sub_sat( acelp_zir_len, i ), acelp_zir_len ) ) ); #else - signal[i+overlap+acelp_mem_len] = sub(signal[i+overlap+acelp_mem_len], mult_r(acelp_zir[i], div_s(sub(acelp_zir_len, i), acelp_zir_len))); + signal[i + overlap + acelp_mem_len] = sub( signal[i + overlap + acelp_mem_len], mult_r( acelp_zir[i], div_s( sub( acelp_zir_len, i ), acelp_zir_len ) ) ); #endif } } /* Rectangular window (past-frame is TCX) */ - ELSE IF ( left_rect==1 && last_core_bfi!=ACELP_CORE ) + ELSE IF( left_rect == 1 && last_core_bfi != ACELP_CORE ) { - n = add(overlap, acelp_mem_len); - FOR (i=0; ican be skipped*/ - } /*-------------------------------------------------------------------* * tcx_windowing_synthesis_past_frame() @@ -618,83 +616,82 @@ void tcx_windowing_synthesis_current_frame( * *-------------------------------------------------------------------*/ void tcx_windowing_synthesis_past_frame( - Word16 *signal, /* i/o: signal vector */ - const PWord16 *window, /* i: TCX window vector */ - const PWord16 *window_half, /* i: TCX window vector for half-overlap window */ - const PWord16 *window_min, /* i: TCX minimum overlap window */ - const Word16 window_length, /* i: TCX window length */ - const Word16 window_half_length, /* i: TCX half window length */ - const Word16 window_min_length, /* i: TCX minimum overlap length */ - const Word16 right_mode /* i: overlap mode (left_mode of current frame) */ + Word16 *signal, /* i/o: signal vector */ + const PWord16 *window, /* i: TCX window vector */ + const PWord16 *window_half, /* i: TCX window vector for half-overlap window */ + const PWord16 *window_min, /* i: TCX minimum overlap window */ + const Word16 window_length, /* i: TCX window length */ + const Word16 window_half_length, /* i: TCX half window length */ + const Word16 window_min_length, /* i: TCX minimum overlap length */ + const Word16 right_mode /* i: overlap mode (left_mode of current frame) */ ) { Word16 i, n; - IF ( EQ_16(right_mode, 2)) /* min. overlap */ + IF( EQ_16( right_mode, 2 ) ) /* min. overlap */ { - signal += shr(sub(window_length, window_min_length), 1); + signal += shr( sub( window_length, window_min_length ), 1 ); - n = shr(window_min_length, 1); - FOR (i = 0; i < n; i++) + n = shr( window_min_length, 1 ); + FOR( i = 0; i < n; i++ ) { - *signal = mult_r(*signal, window_min[i].v.re); + *signal = mult_r( *signal, window_min[i].v.re ); move16(); signal++; } - FOR (i = 0; i < n; i++) + FOR( i = 0; i < n; i++ ) { - *signal = mult_r(*signal, window_min[n-1-i].v.im); + *signal = mult_r( *signal, window_min[n - 1 - i].v.im ); move16(); signal++; } - n = shr(sub(window_length, window_min_length), 1); - FOR (i = 0; i < n; i++) + n = shr( sub( window_length, window_min_length ), 1 ); + FOR( i = 0; i < n; i++ ) { *signal = 0; move16(); signal++; } } - ELSE IF ( EQ_16(right_mode,3)) /* half OL */ + ELSE IF( EQ_16( right_mode, 3 ) ) /* half OL */ { Word16 w; - i = shr(sub(window_length, window_half_length),1); - n = shr(window_half_length,1); - FOR (w=0 ; w < n; w++) + i = shr( sub( window_length, window_half_length ), 1 ); + n = shr( window_half_length, 1 ); + FOR( w = 0; w < n; w++ ) { - signal[i] = mult_r(signal[i], window_half[w].v.re); + signal[i] = mult_r( signal[i], window_half[w].v.re ); move16(); - i = add(i,1); + i = add( i, 1 ); } - FOR (w=0 ; w < n; w++) + FOR( w = 0; w < n; w++ ) { - signal[i] = mult_r(signal[i], window_half[window_half_length/2-1-w].v.im); + signal[i] = mult_r( signal[i], window_half[window_half_length / 2 - 1 - w].v.im ); move16(); - i = add(i,1); + i = add( i, 1 ); } - FOR (; i < window_length; i++) + FOR( ; i < window_length; i++ ) { move16(); signal[i] = 0; } } - ELSE /* normal full/maximum overlap */ + ELSE /* normal full/maximum overlap */ { - n = shr(window_length,1); - FOR (i = 0; i < n; i++) + n = shr( window_length, 1 ); + FOR( i = 0; i < n; i++ ) { move16(); - signal[i] = mult_r(signal[i], window[i].v.re); + signal[i] = mult_r( signal[i], window[i].v.re ); move16(); - signal[window_length-1-i] = mult_r(signal[window_length-1-i], window[i].v.im); + signal[window_length - 1 - i] = mult_r( signal[window_length - 1 - i], window[i].v.im ); } } - } /*-------------------------------------------------------------------* * lpc2mdct() @@ -703,152 +700,151 @@ void tcx_windowing_synthesis_past_frame( *-------------------------------------------------------------------*/ void lpc2mdct( - Word16 *lpcCoeffs, + Word16 *lpcCoeffs, const Word16 lpcOrder, - Word16 *mdct_gains, + Word16 *mdct_gains, Word16 *mdct_gains_exp, - Word16 *mdct_inv_gains, + Word16 *mdct_inv_gains, Word16 *mdct_inv_gains_exp, const int16_t length, - const int16_t noInverse -) + const int16_t noInverse ) { - Word32 ComplexData[2*FDNS_NPTS]; + Word32 ComplexData[2 * FDNS_NPTS]; Word16 i, j, k, sizeN, step, scale, s, tmp16; Word16 g, g_e, ig, ig_e; Word32 tmp32; const PWord16 *ptwiddle; - Word32 workBuffer[2*BASOP_CFFT_MAX_LENGTH]; + Word32 workBuffer[2 * BASOP_CFFT_MAX_LENGTH]; #ifndef IVAS_CODE_TCX_UTIL (void) noInverse; #endif - assert(length <= FDNS_NPTS); - sizeN = shl(length, 1); + assert( length <= FDNS_NPTS ); + sizeN = shl( length, 1 ); - BASOP_getTables(NULL, &ptwiddle, &step, sizeN); + BASOP_getTables( NULL, &ptwiddle, &step, sizeN ); /*ODFT*/ - assert(lpcOrder < FDNS_NPTS); + assert( lpcOrder < FDNS_NPTS ); /* pre-twiddle */ - FOR (i=0; i<=lpcOrder; i++) + FOR( i = 0; i <= lpcOrder; i++ ) { - ComplexData[2*i] = L_mult(lpcCoeffs[i], ptwiddle->v.re); + ComplexData[2 * i] = L_mult( lpcCoeffs[i], ptwiddle->v.re ); move32(); - ComplexData[2*i+1] = L_negate(L_mult(lpcCoeffs[i], ptwiddle->v.im)); + ComplexData[2 * i + 1] = L_negate( L_mult( lpcCoeffs[i], ptwiddle->v.im ) ); move32(); ptwiddle += step; } /* zero padding */ - FOR ( ; i In float the fft type changes as well + scale = add( norm_s( lpcCoeffs[0] ), 1 ); + BASOP_cfft( (cmplx *) ComplexData, FDNS_NPTS, &scale, workBuffer ); // tbv -> In float the fft type changes as well /*Get amplitude*/ - j = sub(length, 1); + j = sub( length, 1 ); k = 0; - for (i = 0; i < length; i++) + for ( i = 0; i < length; i++ ) { - mdct_gains[i] = (float)(sqrt(RealData[i] * RealData[i] + ImagData[i] * ImagData[i])); + mdct_gains[i] = (float) ( sqrt( RealData[i] * RealData[i] + ImagData[i] * ImagData[i] ) ); } } else #endif { /* half length FFT */ - scale = add(norm_s(lpcCoeffs[0]), 1); - BASOP_cfft((cmplx*)ComplexData, FDNS_NPTS, &scale, workBuffer); + scale = add( norm_s( lpcCoeffs[0] ), 1 ); + BASOP_cfft( (cmplx *) ComplexData, FDNS_NPTS, &scale, workBuffer ); /*Get amplitude*/ - j = sub(length, 1); + j = sub( length, 1 ); k = 0; - FOR(i = 0; i < length / 2; i++) - { - s = sub(norm_l(L_max(L_abs(ComplexData[2 * i]), L_abs(ComplexData[2 * i + 1]))), 1); - tmp16 = extract_h(L_shl(ComplexData[2 * i], s)); - tmp32 = L_mult(tmp16, tmp16); - tmp16 = extract_h(L_shl(ComplexData[2 * i + 1], s)); - tmp16 = mac_r(tmp32, tmp16, tmp16); - s = shl(sub(scale, s), 1); - if (tmp16 == 0) + FOR( i = 0; i < length / 2; i++ ) + { + s = sub( norm_l( L_max( L_abs( ComplexData[2 * i] ), L_abs( ComplexData[2 * i + 1] ) ) ), 1 ); + tmp16 = extract_h( L_shl( ComplexData[2 * i], s ) ); + tmp32 = L_mult( tmp16, tmp16 ); + tmp16 = extract_h( L_shl( ComplexData[2 * i + 1], s ) ); + tmp16 = mac_r( tmp32, tmp16, tmp16 ); + s = shl( sub( scale, s ), 1 ); + if ( tmp16 == 0 ) { s = -16; move16(); } - if (tmp16 == 0) + if ( tmp16 == 0 ) { tmp16 = 1; move16(); } - BASOP_Util_Sqrt_InvSqrt_MantExp(tmp16, s, &g, &g_e, &ig, &ig_e); - if (mdct_gains != 0) + BASOP_Util_Sqrt_InvSqrt_MantExp( tmp16, s, &g, &g_e, &ig, &ig_e ); + if ( mdct_gains != 0 ) { mdct_gains[k] = g; move16(); } - if (mdct_gains_exp != 0) + if ( mdct_gains_exp != 0 ) { mdct_gains_exp[k] = g_e; move16(); } - if (mdct_inv_gains != 0) + if ( mdct_inv_gains != 0 ) { mdct_inv_gains[k] = ig; move16(); } - if (mdct_inv_gains_exp != 0) + if ( mdct_inv_gains_exp != 0 ) { mdct_inv_gains_exp[k] = ig_e; move16(); } - k = add(k, 1); - s = sub(norm_l(L_max(L_abs(ComplexData[2 * j]), L_abs(ComplexData[2 * j + 1]))), 1); - tmp16 = extract_h(L_shl(ComplexData[2 * j], s)); - tmp32 = L_mult(tmp16, tmp16); - tmp16 = extract_h(L_shl(ComplexData[2 * j + 1], s)); - tmp16 = mac_r(tmp32, tmp16, tmp16); - s = shl(sub(scale, s), 1); - if (tmp16 == 0) + k = add( k, 1 ); + s = sub( norm_l( L_max( L_abs( ComplexData[2 * j] ), L_abs( ComplexData[2 * j + 1] ) ) ), 1 ); + tmp16 = extract_h( L_shl( ComplexData[2 * j], s ) ); + tmp32 = L_mult( tmp16, tmp16 ); + tmp16 = extract_h( L_shl( ComplexData[2 * j + 1], s ) ); + tmp16 = mac_r( tmp32, tmp16, tmp16 ); + s = shl( sub( scale, s ), 1 ); + if ( tmp16 == 0 ) { s = -16; move16(); } - if (tmp16 == 0) + if ( tmp16 == 0 ) { tmp16 = 1; move16(); } - BASOP_Util_Sqrt_InvSqrt_MantExp(tmp16, s, &g, &g_e, &ig, &ig_e); - if (mdct_gains != 0) + BASOP_Util_Sqrt_InvSqrt_MantExp( tmp16, s, &g, &g_e, &ig, &ig_e ); + if ( mdct_gains != 0 ) { mdct_gains[k] = g; move16(); } - if (mdct_gains_exp != 0) + if ( mdct_gains_exp != 0 ) { mdct_gains_exp[k] = g_e; move16(); } - if (mdct_inv_gains != 0) + if ( mdct_inv_gains != 0 ) { mdct_inv_gains[k] = ig; move16(); } - if (mdct_inv_gains_exp != 0) + if ( mdct_inv_gains_exp != 0 ) { mdct_inv_gains_exp[k] = ig_e; move16(); } - j = sub(j, 1); - k = add(k, 1); + j = sub( j, 1 ); + k = add( k, 1 ); } } } @@ -874,14 +870,14 @@ void lpc2mdct_2( BASOP_getTables( NULL, &ptwiddle, &step, sizeN ); /* ODFT */ - FOR ( i = 0; i < lpcOrder + 1; i++ ) + FOR( i = 0; i < lpcOrder + 1; i++ ) { RealData_fx[i] = L_mult( lpcCoeffs[i], ptwiddle->v.re ); ImagData_fx[i] = L_negate( L_mult( lpcCoeffs[i], ptwiddle->v.im ) ); ptwiddle += step; } - FOR ( ; i < sizeN; i++ ) + FOR( ; i < sizeN; i++ ) { RealData_fx[i] = L_deposit_l( 0 ); ImagData_fx[i] = L_deposit_l( 0 ); @@ -1010,40 +1006,40 @@ void lpc2mdct_2( * \param gains_exp shaping gains exponents */ void mdct_shaping( - Word32 x[], - const Word16 lg, - const Word16 gains[], + Word32 x[], + const Word16 lg, + const Word16 gains[], const Word16 gains_exp[] - /*const Word16 nBands*/ /*Parameter added in IVAS, but always equal to FDNS_NPTS */ + /*const Word16 nBands*/ /*Parameter added in IVAS, but always equal to FDNS_NPTS */ ) { Word16 i, k, l; Word16 m, n, k1, k2, j; - Word32 * px = x; - Word16 const * pgains = gains; - Word16 const * pgainsexp = gains_exp; + Word32 *px = x; + Word16 const *pgains = gains; + Word16 const *pgainsexp = gains_exp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif /* FDNS_NPTS = 64 */ - k = shr(lg, 6); - m = s_and(lg, 0x3F); + k = shr( lg, 6 ); + m = s_and( lg, 0x3F ); - IF (m != 0) + IF( m != 0 ) { - IF ( LE_16( m, FDNS_NPTS/2 )) + IF( LE_16( m, FDNS_NPTS / 2 ) ) { - n = idiv1616U(FDNS_NPTS,m); + n = idiv1616U( FDNS_NPTS, m ); k1 = k; move16(); - k2 = add(k,1); + k2 = add( k, 1 ); } ELSE { - n = idiv1616U(FDNS_NPTS,sub(FDNS_NPTS,m)); - k1 = add(k,1); + n = idiv1616U( FDNS_NPTS, sub( FDNS_NPTS, m ) ); + k1 = add( k, 1 ); k2 = k; move16(); } @@ -1053,34 +1049,34 @@ void mdct_shaping( j = 0; move16(); - WHILE (LT_16(i, lg)) + WHILE( LT_16( i, lg ) ) { k = k2; move16(); - if (j != 0) + if ( j != 0 ) { k = k1; move16(); } - j = add(j, 1); - if ( EQ_16(j, n)) + j = add( j, 1 ); + if ( EQ_16( j, n ) ) { j = 0; move16(); } /* Limit number of loops, if end is reached */ - k = s_min(k, sub(lg, i)); + k = s_min( k, sub( lg, i ) ); - FOR (l=0; l < k; l++) + FOR( l = 0; l < k; l++ ) { - *x = L_shl(Mpy_32_16_r(*x, *gains), *gains_exp); + *x = L_shl( Mpy_32_16_r( *x, *gains ), *gains_exp ); move32(); x++; } - i = add(i, k); + i = add( i, k ); gains++; gains_exp++; @@ -1088,17 +1084,17 @@ void mdct_shaping( } ELSE { - FOR (l=0; l < k; l++) + FOR( l = 0; l < k; l++ ) { x = &px[l]; gains = pgains; gains_exp = pgainsexp; - FOR (i=0; i 0) pg = shr(pg, tmp); - if (tmp < 0) g = shl(g, tmp); - e = s_max(gains_exp[j], gains_exp[jp]); - - tmp = mac_r(L_mult(pg, 12288/*0.375f Q15*/), g, 20480/*0.625f Q15*/); - x[i] = L_shl(Mpy_32_16_1(x[i], tmp), e); + tmp = sub( gains_exp[j], gains_exp[jp] ); + if ( tmp > 0 ) + pg = shr( pg, tmp ); + if ( tmp < 0 ) + g = shl( g, tmp ); + e = s_max( gains_exp[j], gains_exp[jp] ); + + tmp = mac_r( L_mult( pg, 12288 /*0.375f Q15*/ ), g, 20480 /*0.625f Q15*/ ); + x[i] = L_shl( Mpy_32_16_1( x[i], tmp ), e ); move32(); - tmp = mac_r(L_mult(pg, 4096/*0.125f Q15*/), g, 28672/*0.875f Q15*/); - x[i+1] = L_shl(Mpy_32_16_1(x[i+1], tmp), e); + tmp = mac_r( L_mult( pg, 4096 /*0.125f Q15*/ ), g, 28672 /*0.875f Q15*/ ); + x[i + 1] = L_shl( Mpy_32_16_1( x[i + 1], tmp ), e ); move32(); /* common exponent for g and ng */ g = gains[j]; move16(); - tmp = sub(gains_exp[j], gains_exp[jn]); - if (tmp > 0) ng = shr(ng, tmp); - if (tmp < 0) g = shl(g, tmp); - e = s_max(gains_exp[j], gains_exp[jn]); - - tmp = mac_r(L_mult(g, 28672/*0.875f Q15*/), ng, 4096/*0.125f Q15*/); - x[i+2] = L_shl(Mpy_32_16_1(x[i+2], tmp), e); + tmp = sub( gains_exp[j], gains_exp[jn] ); + if ( tmp > 0 ) + ng = shr( ng, tmp ); + if ( tmp < 0 ) + g = shl( g, tmp ); + e = s_max( gains_exp[j], gains_exp[jn] ); + + tmp = mac_r( L_mult( g, 28672 /*0.875f Q15*/ ), ng, 4096 /*0.125f Q15*/ ); + x[i + 2] = L_shl( Mpy_32_16_1( x[i + 2], tmp ), e ); move32(); - tmp = mac_r(L_mult(g, 20480/*0.625f Q15*/), ng, 12288/*0.375f Q15*/); - x[i+3] = L_shl(Mpy_32_16_1(x[i+3], tmp), e); + tmp = mac_r( L_mult( g, 20480 /*0.625f Q15*/ ), ng, 12288 /*0.375f Q15*/ ); + x[i + 3] = L_shl( Mpy_32_16_1( x[i + 3], tmp ), e ); move32(); jp = j; move16(); j = jn; move16(); - jn = s_min(add(jn, 1), FDNS_NPTS-1); + jn = s_min( add( jn, 1 ), FDNS_NPTS - 1 ); } } - ELSE IF (EQ_16(k, 5)) + ELSE IF( EQ_16( k, 5 ) ) { jp = 0; move16(); @@ -1336,63 +1334,67 @@ void mdct_noiseShaping_interp( jn = 1; move16(); - FOR (i = 0; i < lg; i += 5) + FOR( i = 0; i < lg; i += 5 ) { pg = gains[jp]; move16(); - g = gains[j]; + g = gains[j]; move16(); ng = gains[jn]; move16(); /* common exponent for pg and g */ - tmp = sub(gains_exp[j], gains_exp[jp]); - if (tmp > 0) pg = shr(pg, tmp); - if (tmp < 0) g = shl(g, tmp); - e = s_max(gains_exp[j], gains_exp[jp]); - - tmp = mac_r(L_mult(pg, 13107/*0.40f Q15*/), g, 19661/*0.60f Q15*/); - x[i] = L_shl(Mpy_32_16_1(x[i], tmp), e); + tmp = sub( gains_exp[j], gains_exp[jp] ); + if ( tmp > 0 ) + pg = shr( pg, tmp ); + if ( tmp < 0 ) + g = shl( g, tmp ); + e = s_max( gains_exp[j], gains_exp[jp] ); + + tmp = mac_r( L_mult( pg, 13107 /*0.40f Q15*/ ), g, 19661 /*0.60f Q15*/ ); + x[i] = L_shl( Mpy_32_16_1( x[i], tmp ), e ); move32(); - tmp = mac_r(L_mult(pg, 6554/*0.20f Q15*/), g, 26214/*0.80f Q15*/); - x[i+1] = L_shl(Mpy_32_16_1(x[i+1], tmp), e); + tmp = mac_r( L_mult( pg, 6554 /*0.20f Q15*/ ), g, 26214 /*0.80f Q15*/ ); + x[i + 1] = L_shl( Mpy_32_16_1( x[i + 1], tmp ), e ); move32(); - x[i+2] = L_shl(Mpy_32_16_1(x[i+2], gains[j]), gains_exp[j]); + x[i + 2] = L_shl( Mpy_32_16_1( x[i + 2], gains[j] ), gains_exp[j] ); move32(); /* common exponent for g and ng */ g = gains[j]; move16(); - tmp = sub(gains_exp[j], gains_exp[jn]); - if (tmp > 0) ng = shr(ng, tmp); - if (tmp < 0) g = shl(g, tmp); - e = s_max(gains_exp[j], gains_exp[jn]); - - tmp = mac_r(L_mult(g, 26214/*0.80f Q15*/), ng, 6554/*0.20f Q15*/); - x[i+3] = L_shl(Mpy_32_16_1(x[i+3], tmp), e); + tmp = sub( gains_exp[j], gains_exp[jn] ); + if ( tmp > 0 ) + ng = shr( ng, tmp ); + if ( tmp < 0 ) + g = shl( g, tmp ); + e = s_max( gains_exp[j], gains_exp[jn] ); + + tmp = mac_r( L_mult( g, 26214 /*0.80f Q15*/ ), ng, 6554 /*0.20f Q15*/ ); + x[i + 3] = L_shl( Mpy_32_16_1( x[i + 3], tmp ), e ); move32(); - tmp = mac_r(L_mult(g, 19661/*0.60f Q15*/), ng, 13107/*0.40f Q15*/); - x[i+4] = L_shl(Mpy_32_16_1(x[i+4], tmp), e); + tmp = mac_r( L_mult( g, 19661 /*0.60f Q15*/ ), ng, 13107 /*0.40f Q15*/ ); + x[i + 4] = L_shl( Mpy_32_16_1( x[i + 4], tmp ), e ); move32(); jp = j; move16(); j = jn; move16(); - jn = s_min(add(jn, 1), FDNS_NPTS-1); + jn = s_min( add( jn, 1 ), FDNS_NPTS - 1 ); } } - ELSE /* no interpolation */ + ELSE /* no interpolation */ { - FOR (i = 0; i < FDNS_NPTS; i++) + FOR( i = 0; i < FDNS_NPTS; i++ ) { - FOR (l = 0; l < k; l++) + FOR( l = 0; l < k; l++ ) { - *x = L_shl(Mpy_32_16_1(*x, *gains), *gains_exp); + *x = L_shl( Mpy_32_16_1( *x, *gains ), *gains_exp ); move32(); x++; } @@ -1402,15 +1404,13 @@ void mdct_noiseShaping_interp( } } } - } void PsychAdaptLowFreqDeemph( Word32 x[], - const Word16 lpcGains[], + const Word16 lpcGains[], const Word16 lpcGains_e[], - Word16 lf_deemph_factors[] -) + Word16 lf_deemph_factors[] ) { Word16 i; Word16 max_val, max_e, fac, min, min_e, tmp, tmp_e; @@ -1420,8 +1420,7 @@ void PsychAdaptLowFreqDeemph( #endif - - assert(lpcGains[0] >= 0x4000); + assert( lpcGains[0] >= 0x4000 ); max_val = lpcGains[0]; move16(); @@ -1433,9 +1432,9 @@ void PsychAdaptLowFreqDeemph( move16(); /* find minimum (min) and maximum (max_val) of LPC gains in low frequencies */ - FOR (i = 1; i < 9; i++) + FOR( i = 1; i < 9; i++ ) { - IF (compMantExp16Unorm(lpcGains[i], lpcGains_e[i], min, min_e) < 0) + IF( compMantExp16Unorm( lpcGains[i], lpcGains_e[i], min, min_e ) < 0 ) { min = lpcGains[i]; move16(); @@ -1443,7 +1442,7 @@ void PsychAdaptLowFreqDeemph( move16(); } - IF (compMantExp16Unorm(lpcGains[i], lpcGains_e[i], max_val, max_e) > 0) + IF( compMantExp16Unorm( lpcGains[i], lpcGains_e[i], max_val, max_e ) > 0 ) { max_val = lpcGains[i]; move16(); @@ -1452,81 +1451,82 @@ void PsychAdaptLowFreqDeemph( } } - min_e = add(min_e, 5); /* min *= 32.0f; */ + min_e = add( min_e, 5 ); /* min *= 32.0f; */ test(); - IF ((compMantExp16Unorm(max_val, max_e, min, min_e) < 0) && (min > 0)) + IF( ( compMantExp16Unorm( max_val, max_e, min, min_e ) < 0 ) && ( min > 0 ) ) { /* fac = tmp = (float)pow(max_val / min, 0.0078125f); */ tmp_e = min_e; move16(); - tmp = Inv16(min, &tmp_e); - L_tmp = L_shl(L_mult(tmp, max_val), add(tmp_e, max_e)); /* Q31 */ - L_tmp = BASOP_Util_Log2(L_tmp); /* Q25 */ - L_tmp = L_shr(L_tmp, 7); /* 0.0078125f = 1.f/(1<<7) */ - L_tmp = BASOP_Util_InvLog2(L_tmp); /* Q31 */ + tmp = Inv16( min, &tmp_e ); + L_tmp = L_shl( L_mult( tmp, max_val ), add( tmp_e, max_e ) ); /* Q31 */ + L_tmp = BASOP_Util_Log2( L_tmp ); /* Q25 */ + L_tmp = L_shr( L_tmp, 7 ); /* 0.0078125f = 1.f/(1<<7) */ + L_tmp = BASOP_Util_InvLog2( L_tmp ); /* Q31 */ #ifdef BASOP_NOGLOB - tmp = round_fx_o(L_tmp, &Overflow); /* Q15 */ -#else /* BASOP_NOGLOB */ - tmp = round_fx(L_tmp); /* Q15 */ + tmp = round_fx_o( L_tmp, &Overflow ); /* Q15 */ +#else /* BASOP_NOGLOB */ + tmp = round_fx( L_tmp ); /* Q15 */ #endif - fac = tmp; /* Q15 */ move16(); + fac = tmp; /* Q15 */ + move16(); /* gradual lowering of lowest 32 bins; DC is lowered by (max_val/tmp)^1/4 */ - FOR (i = 31; i >= 0; i--) + FOR( i = 31; i >= 0; i-- ) { - x[i] = Mpy_32_16_1(x[i], fac); + x[i] = Mpy_32_16_1( x[i], fac ); move32(); - if (lf_deemph_factors != NULL) + if ( lf_deemph_factors != NULL ) { - lf_deemph_factors[i] = mult_r(lf_deemph_factors[i], fac); + lf_deemph_factors[i] = mult_r( lf_deemph_factors[i], fac ); move16(); } - fac = mult_r(fac, tmp); + fac = mult_r( fac, tmp ); } } - } void AdaptLowFreqDeemph( - Word32 x[], + Word32 x[], Word16 x_e, Word16 tcx_lpc_shaped_ari, - Word16 lpcGains[], + Word16 lpcGains[], Word16 lpcGains_e[], const Word16 lg, - Word16 lf_deemph_factors[] -) + Word16 lf_deemph_factors[] ) { Word16 i, i_max, i_max_old, lg_4; Word32 v2, v4, tmp32; - tmp32 = 0; /* to avoid compilation warnings */ + tmp32 = 0; /* to avoid compilation warnings */ - IF (tcx_lpc_shaped_ari == 0) + IF( tcx_lpc_shaped_ari == 0 ) { - v2 = L_shl(2, sub(31, x_e)); /* 2.0 */ - v4 = L_shl(v2, 1); /* 4.0 */ - lg_4 = shr(lg, 2); /* lg/4 */ + v2 = L_shl( 2, sub( 31, x_e ) ); /* 2.0 */ + v4 = L_shl( v2, 1 ); /* 4.0 */ + lg_4 = shr( lg, 2 ); /* lg/4 */ /* 1. find first magnitude maximum in lower quarter of spectrum */ i_max = -1; move16(); - FOR (i = 0; i < lg_4; i++) + FOR( i = 0; i < lg_4; i++ ) { - IF (GE_32(L_abs(x[i]), v4)) + IF( GE_32( L_abs( x[i] ), v4 ) ) { /* Debug initialization to catch illegal x[i] values. */ tmp32 = 0; - if (x[i] < 0) tmp32 = L_add(x[i], v2); - if (x[i] > 0) tmp32 = L_sub(x[i], v2); + if ( x[i] < 0 ) + tmp32 = L_add( x[i], v2 ); + if ( x[i] > 0 ) + tmp32 = L_sub( x[i], v2 ); - assert(tmp32 != 0); + assert( tmp32 != 0 ); x[i] = tmp32; move32(); @@ -1537,11 +1537,11 @@ void AdaptLowFreqDeemph( } /* 2. expand value range of all xi up to i_max: two extra steps */ - FOR (i = 0; i < i_max; i++) + FOR( i = 0; i < i_max; i++ ) { - x[i] = L_shr(x[i], 1); + x[i] = L_shr( x[i], 1 ); move32(); - lf_deemph_factors[i] = shr(lf_deemph_factors[i], 1); + lf_deemph_factors[i] = shr( lf_deemph_factors[i], 1 ); move16(); } @@ -1549,18 +1549,20 @@ void AdaptLowFreqDeemph( i_max_old = i_max; move16(); - IF (i_max_old >= 0) + IF( i_max_old >= 0 ) { i_max = -1; move16(); - FOR (i = 0; i < lg_4; i++) + FOR( i = 0; i < lg_4; i++ ) { - IF (GE_32(L_abs(x[i]), v4)) + IF( GE_32( L_abs( x[i] ), v4 ) ) { - assert(x[i] != 0); - if (x[i] < 0) tmp32 = L_add(x[i], v2); - if (x[i] >= 0) tmp32 = L_sub(x[i], v2); + assert( x[i] != 0 ); + if ( x[i] < 0 ) + tmp32 = L_add( x[i], v2 ); + if ( x[i] >= 0 ) + tmp32 = L_sub( x[i], v2 ); x[i] = tmp32; move32(); i_max = i; @@ -1571,110 +1573,109 @@ void AdaptLowFreqDeemph( } /* 4. expand value range of all xi up to i_max: two extra steps */ - FOR (i = 0; i < i_max; i++) + FOR( i = 0; i < i_max; i++ ) { - x[i] = L_shr(x[i], 1); + x[i] = L_shr( x[i], 1 ); move32(); - lf_deemph_factors[i] = shr(lf_deemph_factors[i], 1); + lf_deemph_factors[i] = shr( lf_deemph_factors[i], 1 ); move16(); } /* 5. always expand two lines; lines could be at index 0 and 1! */ - i_max = s_max(i_max, i_max_old); - i = add(i_max, 1); + i_max = s_max( i_max, i_max_old ); + i = add( i_max, 1 ); - IF (x[i] < 0) + IF( x[i] < 0 ) { - tmp32 = L_sub(x[i], L_negate(v4)); + tmp32 = L_sub( x[i], L_negate( v4 ) ); - if (tmp32 > 0) + if ( tmp32 > 0 ) { - lf_deemph_factors[i] = shr(lf_deemph_factors[i], 1); + lf_deemph_factors[i] = shr( lf_deemph_factors[i], 1 ); move16(); } - if (tmp32 <= 0) + if ( tmp32 <= 0 ) { - x[i] = L_add(x[i], v2); + x[i] = L_add( x[i], v2 ); move32(); } - if (tmp32 > 0) + if ( tmp32 > 0 ) { - x[i] = L_shr(x[i], 1); + x[i] = L_shr( x[i], 1 ); move32(); } } ELSE { - tmp32 = L_sub(x[i], v4); + tmp32 = L_sub( x[i], v4 ); - if (tmp32 < 0) + if ( tmp32 < 0 ) { - lf_deemph_factors[i] = shr(lf_deemph_factors[i], 1); + lf_deemph_factors[i] = shr( lf_deemph_factors[i], 1 ); move16(); } - if (tmp32 >= 0) + if ( tmp32 >= 0 ) { - x[i] = L_sub(x[i], v2); + x[i] = L_sub( x[i], v2 ); move32(); } - if (tmp32 < 0) + if ( tmp32 < 0 ) { - x[i] = L_shr(x[i], 1); + x[i] = L_shr( x[i], 1 ); move32(); } } - i = add(i, 1); + i = add( i, 1 ); - IF (x[i] < 0) + IF( x[i] < 0 ) { - tmp32 = L_sub(x[i], L_negate(v4)); + tmp32 = L_sub( x[i], L_negate( v4 ) ); - if (tmp32 > 0) + if ( tmp32 > 0 ) { - lf_deemph_factors[i] = shr(lf_deemph_factors[i], 1); + lf_deemph_factors[i] = shr( lf_deemph_factors[i], 1 ); move16(); } - if (tmp32 <= 0) + if ( tmp32 <= 0 ) { - x[i] = L_add(x[i], v2); + x[i] = L_add( x[i], v2 ); move32(); } - if (tmp32 > 0) + if ( tmp32 > 0 ) { - x[i] = L_shr(x[i], 1); + x[i] = L_shr( x[i], 1 ); move32(); } } ELSE { - tmp32 = L_sub(x[i], v4); + tmp32 = L_sub( x[i], v4 ); - if (tmp32 < 0) + if ( tmp32 < 0 ) { - lf_deemph_factors[i] = shr(lf_deemph_factors[i], 1); + lf_deemph_factors[i] = shr( lf_deemph_factors[i], 1 ); move16(); } - if (tmp32 >= 0) + if ( tmp32 >= 0 ) { - x[i] = L_sub(x[i], v2); + x[i] = L_sub( x[i], v2 ); move32(); } - if (tmp32 < 0) + if ( tmp32 < 0 ) { - x[i] = L_shr(x[i], 1); + x[i] = L_shr( x[i], 1 ); move32(); } } } - ELSE /*if(!tcx_lpc_shaped_ari)*/ + ELSE /*if(!tcx_lpc_shaped_ari)*/ { - PsychAdaptLowFreqDeemph(x, lpcGains, lpcGains_e, lf_deemph_factors); - }/*if(!tcx_lpc_shaped_ari)*/ - + PsychAdaptLowFreqDeemph( x, lpcGains, lpcGains_e, lf_deemph_factors ); + } /*if(!tcx_lpc_shaped_ari)*/ } void tcx_noise_filling( - Word32* Q, + Word32 *Q, Word16 Q_e, Word16 seed, const Word16 iFirstLine, @@ -1683,7 +1684,7 @@ void tcx_noise_filling( const Word16 L_frame, const Word16 tiltCompFactor, Word16 fac_ns, - Word16* infoTCXNoise, + Word16 *infoTCXNoise, const Word16 element_mode /* i : IVAS element mode */ ) { @@ -1696,104 +1697,104 @@ void tcx_noise_filling( /* get inverse frame length */ - tmp1 = getInvFrameLen(L_frame); + tmp1 = getInvFrameLen( L_frame ); /* tilt_factor = (float)pow(max_val(0.375f, tiltCompFactor), 1.0f/(float)L_frame); */ - tmp32 = BASOP_Util_Log2(L_deposit_h(s_max(0x3000, tiltCompFactor))); /* 6Q25 */ - tmp32 = L_shr(Mpy_32_16_1(tmp32, tmp1), 6); + tmp32 = BASOP_Util_Log2( L_deposit_h( s_max( 0x3000, tiltCompFactor ) ) ); /* 6Q25 */ + tmp32 = L_shr( Mpy_32_16_1( tmp32, tmp1 ), 6 ); BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB tilt_factor = round_fx_sat( BASOP_Util_InvLog2( tmp32 ) ); #else - tilt_factor = round_fx(BASOP_Util_InvLog2(tmp32)); + tilt_factor = round_fx( BASOP_Util_InvLog2( tmp32 ) ); #endif BASOP_SATURATE_WARNING_ON_EVS; /* find last nonzero line below iFirstLine, use it as start offset */ i = iFirstLine; move16(); - tmp1 = shr(iFirstLine, 1); - IF (EQ_16(element_mode, IVAS_CPE_MDCT)) /* ... but only in mono or parametric stereo since it may cause binaural unmasking in discrete stereo */ + tmp1 = shr( iFirstLine, 1 ); + IF( EQ_16( element_mode, IVAS_CPE_MDCT ) ) /* ... but only in mono or parametric stereo since it may cause binaural unmasking in discrete stereo */ { segmentOffset = i; move16(); } ELSE { - FOR(; i > tmp1; i--) + FOR( ; i > tmp1; i-- ) { - IF(Q[i] != 0) + IF( Q[i] != 0 ) { BREAK; } } /* fac_ns *= (float)pow(tilt_factor, (float)i); */ - FOR(m = 0; m < i; m++) + FOR( m = 0; m < i; m++ ) { - fac_ns = mult_r(fac_ns, tilt_factor); + fac_ns = mult_r( fac_ns, tilt_factor ); } - i = add(i, 1); + i = add( i, 1 ); segmentOffset = i; } - nrg = L_deposit_l(1); + nrg = L_deposit_l( 1 ); win = 0; move16(); move16(); - FOR (; i < lowpassLine; i++) + FOR( ; i < lowpassLine; i++ ) { - fac_ns = mult_r(fac_ns, tilt_factor); + fac_ns = mult_r( fac_ns, tilt_factor ); - IF (Q[i] != 0) + IF( Q[i] != 0 ) { - IF (win > 0) + IF( win > 0 ) { /* RMS-normalize current noise-filled segment */ - tmp1 = BASOP_Util_Divide3216_Scale(nrg, sub(i, segmentOffset), &s); /* mean */ - s = add(s, 9-15); /* scaling */ - tmp1 = ISqrt16(tmp1, &s); /* 1/RMS */ - tmp1 = mult_r(tmp1, inv_int[nTransWidth]); /* compensate win */ - s = add(s, sub(16, Q_e)); /* scaling */ - - tmp2 = sub(i, win); - IF (LT_16(segmentOffset, tmp2)) + tmp1 = BASOP_Util_Divide3216_Scale( nrg, sub( i, segmentOffset ), &s ); /* mean */ + s = add( s, 9 - 15 ); /* scaling */ + tmp1 = ISqrt16( tmp1, &s ); /* 1/RMS */ + tmp1 = mult_r( tmp1, inv_int[nTransWidth] ); /* compensate win */ + s = add( s, sub( 16, Q_e ) ); /* scaling */ + + tmp2 = sub( i, win ); + IF( LT_16( segmentOffset, tmp2 ) ) { - FOR (m = segmentOffset; m < tmp2; m++) + FOR( m = segmentOffset; m < tmp2; m++ ) { - Q[m] = L_shl(Mpy_32_16_1(Q[m], tmp1), s); + Q[m] = L_shl( Mpy_32_16_1( Q[m], tmp1 ), s ); move32(); } } - tmp2 = mult(tmp1, inv_int[nTransWidth]); - tmp1 = extract_l(L_mult0(tmp2, win)); - FOR (m = sub(i, win); m < i; m++) + tmp2 = mult( tmp1, inv_int[nTransWidth] ); + tmp1 = extract_l( L_mult0( tmp2, win ) ); + FOR( m = sub( i, win ); m < i; m++ ) { - Q[m] = L_shl(Mpy_32_16_1(Q[m], tmp1), s); + Q[m] = L_shl( Mpy_32_16_1( Q[m], tmp1 ), s ); move32(); - win = sub(win, 1); - tmp1 = sub(tmp1, tmp2); + win = sub( win, 1 ); + tmp1 = sub( tmp1, tmp2 ); } - nrg = L_deposit_l(1); /* start new segment: reset noise segment energy */ + nrg = L_deposit_l( 1 ); /* start new segment: reset noise segment energy */ } - segmentOffset = add(i, 1); + segmentOffset = add( i, 1 ); } - ELSE /* line is zero, so fill line and update window and energy */ + ELSE /* line is zero, so fill line and update window and energy */ { - if (LT_16(win, nTransWidth)) + if ( LT_16( win, nTransWidth ) ) { - win = add(win, 1); + win = add( win, 1 ); } - seed = own_random2_fx(seed); - Q[i] = L_mult0(mult(seed, fac_ns), win); + seed = own_random2_fx( seed ); + Q[i] = L_mult0( mult( seed, fac_ns ), win ); move32(); - tmp1 = shr(seed, 4); - nrg = L_mac0(nrg, tmp1, tmp1); /* sum up energy of current noise segment */ + tmp1 = shr( seed, 4 ); + nrg = L_mac0( nrg, tmp1, tmp1 ); /* sum up energy of current noise segment */ - if(infoTCXNoise) /* set noiseflags for IGF */ + if ( infoTCXNoise ) /* set noiseflags for IGF */ { infoTCXNoise[i] = 1; move16(); @@ -1801,22 +1802,21 @@ void tcx_noise_filling( } } - IF (win > 0) + IF( win > 0 ) { /* RMS-normalize uppermost noise-filled segment */ - tmp1 = BASOP_Util_Divide3216_Scale(nrg, sub(lowpassLine, segmentOffset), &s); /* mean */ - s = add(s, 9-15); /* compensate energy scaling */ - tmp1 = ISqrt16(tmp1, &s); /* 1/RMS */ - tmp1 = mult_r(tmp1, inv_int[nTransWidth]); /* compensate win */ - s = add(s, sub(16, Q_e)); /* compensate noise scaling */ + tmp1 = BASOP_Util_Divide3216_Scale( nrg, sub( lowpassLine, segmentOffset ), &s ); /* mean */ + s = add( s, 9 - 15 ); /* compensate energy scaling */ + tmp1 = ISqrt16( tmp1, &s ); /* 1/RMS */ + tmp1 = mult_r( tmp1, inv_int[nTransWidth] ); /* compensate win */ + s = add( s, sub( 16, Q_e ) ); /* compensate noise scaling */ - FOR (m = segmentOffset; m < lowpassLine; m++) + FOR( m = segmentOffset; m < lowpassLine; m++ ) { - Q[m] = L_shl(Mpy_32_16_1(Q[m], tmp1), s); + Q[m] = L_shl( Mpy_32_16_1( Q[m], tmp1 ), s ); move32(); } } - } void tcx_noise_filling_with_shift( @@ -2029,27 +2029,25 @@ void InitTnsConfigs( const Word16 igfStopFreq, const Word32 total_brate, const int16_t element_mode, - const int16_t MCT_flag -) + const int16_t MCT_flag ) { - IF (GT_32(total_brate,ACELP_32k)) + IF( GT_32( total_brate, ACELP_32k ) ) { - InitTnsConfiguration(bwidth, shr(L_frame,1), &tnsConfig[0][0], igfStopFreq, total_brate, element_mode, MCT_flag); + InitTnsConfiguration( bwidth, shr( L_frame, 1 ), &tnsConfig[0][0], igfStopFreq, total_brate, element_mode, MCT_flag ); } - InitTnsConfiguration(bwidth, L_frame, &tnsConfig[1][0], igfStopFreq, total_brate, element_mode, MCT_flag); - InitTnsConfiguration(bwidth, add(L_frame, shr(L_frame,2)), &tnsConfig[1][1], igfStopFreq, total_brate, element_mode, MCT_flag); + InitTnsConfiguration( bwidth, L_frame, &tnsConfig[1][0], igfStopFreq, total_brate, element_mode, MCT_flag ); + InitTnsConfiguration( bwidth, add( L_frame, shr( L_frame, 2 ) ), &tnsConfig[1][1], igfStopFreq, total_brate, element_mode, MCT_flag ); } void SetTnsConfig( TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */ const Word16 isTCX20, - const Word16 isAfterACELP -) + const Word16 isAfterACELP ) { move16(); hTcxCfg->pCurrentTnsConfig = &hTcxCfg->tnsConfig[isTCX20][isAfterACELP]; - assert(hTcxCfg->pCurrentTnsConfig != NULL); + assert( hTcxCfg->pCurrentTnsConfig != NULL ); } #define IVAS_CODE_TCX_UTIL #ifdef IVAS_CODE_TCX_UTIL @@ -2060,7 +2058,7 @@ void SetTnsConfig( *-------------------------------------------------------------------*/ void SetAllowTnsOnWhite( - STnsConfig tnsConfig[2][2], /* o : updated TNS configurations */ + STnsConfig tnsConfig[2][2], /* o : updated TNS configurations */ const Word8 allowTnsOnWhite /* i : flag for TNS in whiteded domain mode */ ) { @@ -2075,15 +2073,15 @@ void SetAllowTnsOnWhite( #undef IVAS_CODE_TCX_UTIL void tcx_get_gain( - Word32 *x, /* i: spectrum 1 */ - Word16 x_e, /* i: spectrum 1 exponent */ - Word32 *y, /* i: spectrum 2 */ - Word16 y_e, /* i: spectrum 2 exponent */ - Word16 n, /* i: length */ - Word16 *gain, /* o: gain */ - Word16 *gain_e, /* o: gain exponent */ - Word32 *en_y, /* o: energy of y (optional) */ - Word16 *en_y_e /* o: energy of y exponent (optional) */ + Word32 *x, /* i: spectrum 1 */ + Word16 x_e, /* i: spectrum 1 exponent */ + Word32 *y, /* i: spectrum 2 */ + Word16 y_e, /* i: spectrum 2 exponent */ + Word16 n, /* i: length */ + Word16 *gain, /* o: gain */ + Word16 *gain_e, /* o: gain exponent */ + Word32 *en_y, /* o: energy of y (optional) */ + Word16 *en_y_e /* o: energy of y exponent (optional) */ ) { Word32 maxX, minX, maxY, minY; @@ -2094,68 +2092,73 @@ void tcx_get_gain( Flag Overflow = 0; #endif - maxX = L_deposit_l(1); - maxY = L_deposit_l(1); - minX = L_deposit_l(-1); - minY = L_deposit_l(-1); - FOR (i = 0; i < n; i++) + maxX = L_deposit_l( 1 ); + maxY = L_deposit_l( 1 ); + minX = L_deposit_l( -1 ); + minY = L_deposit_l( -1 ); + FOR( i = 0; i < n; i++ ) { - if (x[i] > 0) maxX = L_max(maxX, x[i]); - if (x[i] < 0) minX = L_min(minX, x[i]); - - if (y[i] > 0) maxY = L_max(maxY, y[i]); - if (y[i] < 0) minY = L_min(minY, y[i]); + if ( x[i] > 0 ) + maxX = L_max( maxX, x[i] ); + if ( x[i] < 0 ) + minX = L_min( minX, x[i] ); + + if ( y[i] > 0 ) + maxY = L_max( maxY, y[i] ); + if ( y[i] < 0 ) + minY = L_min( minY, y[i] ); } - sx = s_min(norm_l(maxX), norm_l(minX)); - sy = s_min(norm_l(maxY), norm_l(minY)); - sx = sub(sx, 4); - sy = sub(sy, 4); - - ener = L_deposit_l(0); - corr = L_deposit_l(0); - FOR (i = 0; i < n; i++) + sx = s_min( norm_l( maxX ), norm_l( minX ) ); + sy = s_min( norm_l( maxY ), norm_l( minY ) ); + sx = sub( sx, 4 ); + sy = sub( sy, 4 ); + + ener = L_deposit_l( 0 ); + corr = L_deposit_l( 0 ); + FOR( i = 0; i < n; i++ ) { - tmp = round_fx(L_shl(y[i], sy)); - ener = L_mac0(ener, tmp, tmp); - corr = L_mac0(corr, tmp, round_fx(L_shl(x[i], sx))); + tmp = round_fx( L_shl( y[i], sy ) ); + ener = L_mac0( ener, tmp, tmp ); + corr = L_mac0( corr, tmp, round_fx( L_shl( x[i], sx ) ) ); } - if (ener == 0) ener = L_deposit_l(1); + if ( ener == 0 ) + ener = L_deposit_l( 1 ); - ener_e = add(shl(sub(y_e, sy), 1), 1); - corr_e = add(sub(add(x_e, y_e), add(sx, sy)), 1); + ener_e = add( shl( sub( y_e, sy ), 1 ), 1 ); + corr_e = add( sub( add( x_e, y_e ), add( sx, sy ) ), 1 ); - tmp = sub(norm_l(corr), 1); - corr = L_shl(corr, tmp); - corr_e = sub(corr_e, tmp); + tmp = sub( norm_l( corr ), 1 ); + corr = L_shl( corr, tmp ); + corr_e = sub( corr_e, tmp ); - tmp = norm_l(ener); - ener = L_shl(ener, tmp); - ener_e = sub(ener_e, tmp); + tmp = norm_l( ener ); + ener = L_shl( ener, tmp ); + ener_e = sub( ener_e, tmp ); #ifdef BASOP_NOGLOB - tmp = div_s(abs_s(round_fx_o(corr, &Overflow)), round_fx_o(ener, &Overflow)); + tmp = div_s( abs_s( round_fx_o( corr, &Overflow ) ), round_fx_o( ener, &Overflow ) ); #else - tmp = div_s(abs_s(round_fx(corr)), round_fx(ener)); + tmp = div_s( abs_s( round_fx( corr ) ), round_fx( ener ) ); #endif - if (corr < 0) tmp = negate(tmp); + if ( corr < 0 ) + tmp = negate( tmp ); *gain = tmp; move16(); - *gain_e = sub(corr_e, ener_e); + *gain_e = sub( corr_e, ener_e ); move16(); - if (en_y != NULL) + if ( en_y != NULL ) { *en_y = ener; move32(); } - if (en_y_e != NULL) + if ( en_y_e != NULL ) { *en_y_e = ener_e; move16(); } - } #if 0 void init_TCX_config_dec( /* TEMPORARY */ @@ -2205,35 +2208,34 @@ void init_TCX_config_dec( /* TEMPORARY */ } #endif void init_TCX_config( - TCX_CONFIG_HANDLE hTcxCfg, + TCX_CONFIG_HANDLE hTcxCfg, Word16 L_frame, - Word16 fscale - ,Word16 L_frameTCX - ,Word16 fscaleFB -) + Word16 fscale, + Word16 L_frameTCX, + Word16 fscaleFB ) { /* Initialize the TCX MDCT windows */ - hTcxCfg->tcx_mdct_window_length = extract_l(L_shr(L_mult0(L_LOOK_12k8, fscale), LD_FSCALE_DENOM)); + hTcxCfg->tcx_mdct_window_length = extract_l( L_shr( L_mult0( L_LOOK_12k8, fscale ), LD_FSCALE_DENOM ) ); hTcxCfg->tcx_mdct_window_delay = hTcxCfg->tcx_mdct_window_length; move16(); - hTcxCfg->tcx_mdct_window_half_length = extract_l(L_shr(L_mult0(L_LOOK_12k8 - NS2SA(12800, 5000000L), fscale), LD_FSCALE_DENOM)); + hTcxCfg->tcx_mdct_window_half_length = extract_l( L_shr( L_mult0( L_LOOK_12k8 - NS2SA( 12800, 5000000L ), fscale ), LD_FSCALE_DENOM ) ); - hTcxCfg->tcx_mdct_window_min_length = shr(L_frame, 4); /* 1.25ms */ - hTcxCfg->tcx_mdct_window_trans_length = shr(L_frame, 4); /* 1.25ms */ + hTcxCfg->tcx_mdct_window_min_length = shr( L_frame, 4 ); /* 1.25ms */ + hTcxCfg->tcx_mdct_window_trans_length = shr( L_frame, 4 ); /* 1.25ms */ - hTcxCfg->tcx5Size = shr(L_frame, 2); /* 5ms */ + hTcxCfg->tcx5Size = shr( L_frame, 2 ); /* 5ms */ - hTcxCfg->tcx_mdct_window_lengthFB = extract_l(L_shr(L_mult0(L_LOOK_12k8, fscaleFB), LD_FSCALE_DENOM)); + hTcxCfg->tcx_mdct_window_lengthFB = extract_l( L_shr( L_mult0( L_LOOK_12k8, fscaleFB ), LD_FSCALE_DENOM ) ); hTcxCfg->tcx_mdct_window_delayFB = hTcxCfg->tcx_mdct_window_lengthFB; move16(); - hTcxCfg->tcx_mdct_window_half_lengthFB = extract_l(L_shr(L_mult0(L_LOOK_12k8 - NS2SA(12800, 5000000L), fscaleFB), LD_FSCALE_DENOM)); + hTcxCfg->tcx_mdct_window_half_lengthFB = extract_l( L_shr( L_mult0( L_LOOK_12k8 - NS2SA( 12800, 5000000L ), fscaleFB ), LD_FSCALE_DENOM ) ); - hTcxCfg->tcx_mdct_window_min_lengthFB = shr(L_frameTCX, 4); /* 1.25ms */ - hTcxCfg->tcx_mdct_window_trans_lengthFB = shr(L_frameTCX, 4); /* 1.25ms */ + hTcxCfg->tcx_mdct_window_min_lengthFB = shr( L_frameTCX, 4 ); /* 1.25ms */ + hTcxCfg->tcx_mdct_window_trans_lengthFB = shr( L_frameTCX, 4 ); /* 1.25ms */ - hTcxCfg->tcx5SizeFB = shr(L_frameTCX, 2); /* 5ms */ + hTcxCfg->tcx5SizeFB = shr( L_frameTCX, 2 ); /* 5ms */ mdct_window_sine( hTcxCfg->tcx_mdct_window, hTcxCfg->tcx_mdct_window_length ); mdct_window_sine( hTcxCfg->tcx_mdct_window_half, hTcxCfg->tcx_mdct_window_half_length ); @@ -2246,7 +2248,6 @@ void init_TCX_config( mdct_window_sine( hTcxCfg->tcx_mdct_window_transFB, hTcxCfg->tcx_mdct_window_trans_lengthFB ); /*ALDO windows for MODE2*/ - mdct_window_aldo(hTcxCfg->tcx_aldo_window_1, hTcxCfg->tcx_aldo_window_1_trunc, hTcxCfg->tcx_aldo_window_2, L_frame); - mdct_window_aldo(hTcxCfg->tcx_aldo_window_1_FB, hTcxCfg->tcx_aldo_window_1_FB_trunc, hTcxCfg->tcx_aldo_window_2_FB, L_frameTCX); + mdct_window_aldo( hTcxCfg->tcx_aldo_window_1, hTcxCfg->tcx_aldo_window_1_trunc, hTcxCfg->tcx_aldo_window_2, L_frame ); + mdct_window_aldo( hTcxCfg->tcx_aldo_window_1_FB, hTcxCfg->tcx_aldo_window_1_FB_trunc, hTcxCfg->tcx_aldo_window_2_FB, L_frameTCX ); } - diff --git a/lib_com/tec_com.c b/lib_com/tec_com.c index a2ef5c6b0..5e32b842b 100644 --- a/lib_com/tec_com.c +++ b/lib_com/tec_com.c @@ -15,9 +15,9 @@ *-------------------------------------------------------------------*/ /*#define EPS ( 1e-12f)*/ -#define ENV_SCALE_OFFSET_1_FX 1515133568l/*90.309f/128.0 Q31*/ /* 10*log10(2^30) */ /* scaled by 1/128.0 */ -#define MAX_TEC_BW_LO (12) -#define MAX_NB_TEC_LOW_BAND ( 3) +#define ENV_SCALE_OFFSET_1_FX 1515133568l /*90.309f/128.0 Q31*/ /* 10*log10(2^30) */ /* scaled by 1/128.0 */ +#define MAX_TEC_BW_LO ( 12 ) +#define MAX_NB_TEC_LOW_BAND ( 3 ) #define NBTECLOWBAND 3 #define TECSMOOTHINGDEG 5 #define LOBUF_NO_SMOOTHING_MODE 1 @@ -28,14 +28,13 @@ * *-------------------------------------------------------------------*/ void resetTecDec_Fx( - TEC_DEC_HANDLE hTecDec -) + TEC_DEC_HANDLE hTecDec ) { - set16_fx(hTecDec->pGainTemp_m, 0, CLDFB_NO_COL_MAX); - set16_fx(hTecDec->pGainTemp_e, 0, CLDFB_NO_COL_MAX); + set16_fx( hTecDec->pGainTemp_m, 0, CLDFB_NO_COL_MAX ); + set16_fx( hTecDec->pGainTemp_e, 0, CLDFB_NO_COL_MAX ); - set16_fx(hTecDec->loBuffer, 0, CLDFB_NO_COL_MAX + MAX_TEC_SMOOTHING_DEG); + set16_fx( hTecDec->loBuffer, 0, CLDFB_NO_COL_MAX + MAX_TEC_SMOOTHING_DEG ); return; } @@ -45,18 +44,18 @@ void resetTecDec_Fx( * * *-------------------------------------------------------------------*/ -void resetTecEnc_Fx(TEC_ENC_HANDLE hTecEnc, Word16 flag) +void resetTecEnc_Fx( TEC_ENC_HANDLE hTecEnc, Word16 flag ) { - IF (flag == 0) + IF( flag == 0 ) { - set16_fx(hTecEnc->loBuffer, 0, CLDFB_NO_COL_MAX + MAX_TEC_SMOOTHING_DEG + DELAY_TEMP_ENV_BUFF_TEC); - set16_fx(hTecEnc->loTempEnv, 0, CLDFB_NO_COL_MAX); - set16_fx(hTecEnc->loTempEnv_ns, 0, CLDFB_NO_COL_MAX); - set16_fx(hTecEnc->hiTempEnv, 0, CLDFB_NO_COL_MAX + DELAY_TEMP_ENV_BUFF_TEC + EXT_DELAY_HI_TEMP_ENV); + set16_fx( hTecEnc->loBuffer, 0, CLDFB_NO_COL_MAX + MAX_TEC_SMOOTHING_DEG + DELAY_TEMP_ENV_BUFF_TEC ); + set16_fx( hTecEnc->loTempEnv, 0, CLDFB_NO_COL_MAX ); + set16_fx( hTecEnc->loTempEnv_ns, 0, CLDFB_NO_COL_MAX ); + set16_fx( hTecEnc->hiTempEnv, 0, CLDFB_NO_COL_MAX + DELAY_TEMP_ENV_BUFF_TEC + EXT_DELAY_HI_TEMP_ENV ); } ELSE { - set16_fx(hTecEnc->loBuffer, 0, MAX_TEC_SMOOTHING_DEG); + set16_fx( hTecEnc->loBuffer, 0, MAX_TEC_SMOOTHING_DEG ); } return; } @@ -68,10 +67,9 @@ void resetTecEnc_Fx(TEC_ENC_HANDLE hTecEnc, Word16 flag) *-------------------------------------------------------------------*/ static Word32 calcVar_Fix( - const Word32 in[], - const Word32 len, - Word32* x -) + const Word32 in[], + const Word32 len, + Word32 *x ) { Word32 xx; Word32 i; @@ -80,38 +78,35 @@ static Word32 calcVar_Fix( Word16 r_sft; Word32 tmpX; - xx = L_deposit_l(0); - *x = L_deposit_l(0); - FOR(i=0; i 0 ) + IF( tmp32 > 0 ) { - IF ( GE_32(tmp32,1006632960l/*0.46875 Q31*/)) + IF( GE_32( tmp32, 1006632960l /*0.46875 Q31*/ ) ) { - s = add(s,sub(WORD32_BITS,norm_l(BASOP_Util_InvLog2(L_sub(tmp32,1006632960l/*0.46875 Q31*/))))); - s = add(s,30); + s = add( s, sub( WORD32_BITS, norm_l( BASOP_Util_InvLog2( L_sub( tmp32, 1006632960l /*0.46875 Q31*/ ) ) ) ) ); + s = add( s, 30 ); } ELSE { - s = add(s,sub(WORD32_BITS,norm_l(BASOP_Util_InvLog2(tmp32)))); + s = add( s, sub( WORD32_BITS, norm_l( BASOP_Util_InvLog2( tmp32 ) ) ) ); } /* scalefactor for logarithmic domain */ - logScaleFactor = L_shl(L_mult0(512/*1.0/(1<= BW_LO); + assert( lowSubband >= BW_LO ); calcLoBufferDec_Fx( pCldfbRealSrc_Fx, pCldfbImagSrc_Fx, - loBuffer_Fx+MAX_TEC_SMOOTHING_DEG, + loBuffer_Fx + MAX_TEC_SMOOTHING_DEG, startPos, stopPos, bandOffset, - 15 - cldfb_exp - ); + 15 - cldfb_exp ); - IF (code > 0) + IF( code > 0 ) { - IF (NE_16(code, 2)) + IF( NE_16( code, 2 ) ) { - calcLoTempEnv_TBE_Fx(loBuffer_Fx + MAX_TEC_SMOOTHING_DEG, noCols, - loTempEnv_Fx, 19531/*0.5f * ratioHiLoFacDec Q15*/); + calcLoTempEnv_TBE_Fx( loBuffer_Fx + MAX_TEC_SMOOTHING_DEG, noCols, + loTempEnv_Fx, 19531 /*0.5f * ratioHiLoFacDec Q15*/ ); } ELSE { - calcLoTempEnv_ns_TBE_Fx(loBuffer_Fx + MAX_TEC_SMOOTHING_DEG, noCols, loTempEnv_Fx); + calcLoTempEnv_ns_TBE_Fx( loBuffer_Fx + MAX_TEC_SMOOTHING_DEG, noCols, loTempEnv_Fx ); } - calcGainLinear_TBE_Fx(loTempEnv_Fx, startPos, stopPos, - pGainTemp_m, pGainTemp_e); + calcGainLinear_TBE_Fx( loTempEnv_Fx, startPos, stopPos, + pGainTemp_m, pGainTemp_e ); } - FOR (slot = 0; slot < MAX_TEC_SMOOTHING_DEG; slot++) + FOR( slot = 0; slot < MAX_TEC_SMOOTHING_DEG; slot++ ) { loBuffer_Fx[slot] = loBuffer_Fx[slot + stopPos]; move16(); @@ -689,14 +674,13 @@ void calcGainTemp_TBE_Fx( *-------------------------------------------------------------------*/ static void setSubfrConfig_Fix( - const Word16 i_offset, - Word16* k_offset, - Word16* n_subfr, - const Word16 l_subfr -) + const Word16 i_offset, + Word16 *k_offset, + Word16 *n_subfr, + const Word16 l_subfr ) { - *n_subfr = sub((Word16)N_TEC_TFA_SUBFR,i_offset); - *k_offset = i_mult(i_offset,l_subfr); + *n_subfr = sub( (Word16) N_TEC_TFA_SUBFR, i_offset ); + *k_offset = i_mult( i_offset, l_subfr ); } /*------------------------------------------------------------------- * calcSum_Fx() @@ -705,10 +689,10 @@ static void setSubfrConfig_Fix( *-------------------------------------------------------------------*/ static Word16 calcSum_Fx( - Word16* vec_m, /*Q0*/ - Word16* vec_e, /*Q0*/ + Word16 *vec_m, /*Q0*/ + Word16 *vec_e, /*Q0*/ const Word16 len, - Word16* sum16_m /*Q0*/ + Word16 *sum16_m /*Q0*/ ) { Word16 slot; @@ -716,15 +700,14 @@ static Word16 calcSum_Fx( *sum16_m = 0; sum16_e = 0; - FOR (slot=0; slot 0) + IF( nrg32 > 0 ) { Word16 tmp; - s = norm_l(nrg32); - tmp = extract_h(L_shl(nrg32, s)); + s = norm_l( nrg32 ); + tmp = extract_h( L_shl( nrg32, s ) ); enr_m[i] = tmp; move16(); - enr_e[i] = - s; + enr_e[i] = -s; move16(); } ELSE { enr_m[i] = 0; move16(); - enr_e[i] = - 15; + enr_e[i] = -15; move16(); } } sum16_e = enr_e[i_offset]; *sum16_m = enr_m[i_offset]; - FOR (i=i_offset+1; i 0) + IF( enr_m[i] > 0 ) { - BASOP_Util_Divide_MantExp(enr_ave_m, enr_ave_e, - enr_m[i], enr_e[i], - &inv_curr_enr_m[i], &inv_curr_enr_e[i]); + BASOP_Util_Divide_MantExp( enr_ave_m, enr_ave_e, + enr_m[i], enr_e[i], + &inv_curr_enr_m[i], &inv_curr_enr_e[i] ); } ELSE { /* 1.0e+12 */ - inv_curr_enr_m[i] = 28282/*0.8631 Q15*/; + inv_curr_enr_m[i] = 28282 /*0.8631 Q15*/; move16(); inv_curr_enr_e[i] = 39; move16(); } - s = norm_s(inv_curr_enr_m[i]); - inv_curr_enr_m[i] = shl(inv_curr_enr_m[i], s); + s = norm_s( inv_curr_enr_m[i] ); + inv_curr_enr_m[i] = shl( inv_curr_enr_m[i], s ); move16(); - inv_curr_enr_e[i] = sub(inv_curr_enr_e[i], s); + inv_curr_enr_e[i] = sub( inv_curr_enr_e[i], s ); move16(); - IF (gain_m[i] > 0) + IF( gain_m[i] > 0 ) { - BASOP_Util_Divide_MantExp(gain_m[i], gain_e[i], - gain_ave_m, gain_ave_e, - &gain_m[i], &gain_e[i]); + BASOP_Util_Divide_MantExp( gain_m[i], gain_e[i], + gain_ave_m, gain_ave_e, + &gain_m[i], &gain_e[i] ); } ELSE { @@ -931,11 +909,11 @@ static Word16 procTec_Fx( max_inv_curr_enr_m = inv_curr_enr_m[i_offset]; move16(); - FOR (i=i_offset+1; i 15) + exp_syn = sub( s, min_shift ); + if ( exp_syn > 15 ) { exp_syn = 15; move16(); } - if (exp_syn < 0) + if ( exp_syn < 0 ) { exp_syn = 0; move16(); } - min_shift = sub(s, exp_syn); /* exp_syn(old) - exp_syn(new) */ + min_shift = sub( s, exp_syn ); /* exp_syn(old) - exp_syn(new) */ k = k_offset; - FOR (i=i_offset; i 0) + if ( s > 0 ) { - hb_synth_Fx[k] = shr(hb_synth_Fx[k], s); + hb_synth_Fx[k] = shr( hb_synth_Fx[k], s ); move16(); } - k = add(k, 1); + k = add( k, 1 ); } } @@ -1081,13 +1063,12 @@ static Word16 procTec_Fx( * *-------------------------------------------------------------------*/ static Word16 procTfa_Fx( - Word16* hb_synth_Fx, + Word16 *hb_synth_Fx, Word16 exp_syn, const Word16 i_offset, - const Word16 l_subfr -) + const Word16 l_subfr ) { - Word16 i,j,k; + Word16 i, j, k; Word16 k_offset, n_subfr; Word16 enr_m[N_TEC_TFA_SUBFR]; @@ -1105,35 +1086,34 @@ static Word16 procTfa_Fx( Word16 gain_m[N_TEC_TFA_SUBFR]; Word16 gain_e[N_TEC_TFA_SUBFR]; - setSubfrConfig_Fix(i_offset, &k_offset, &n_subfr, l_subfr); + setSubfrConfig_Fix( i_offset, &k_offset, &n_subfr, l_subfr ); - assert(8 /* = 2^3 */ < n_subfr); - inv_n_subfr = getNormReciprocalWord16Scale(n_subfr, 3); + assert( 8 /* = 2^3 */ < n_subfr ); + inv_n_subfr = getNormReciprocalWord16Scale( n_subfr, 3 ); - enr_ave_e = calcSubfrNrg_Fx(hb_synth_Fx, - exp_syn, - i_offset, - enr_m, - enr_e, - k_offset, - &enr_ave_m - ,l_subfr - ); + enr_ave_e = calcSubfrNrg_Fx( hb_synth_Fx, + exp_syn, + i_offset, + enr_m, + enr_e, + k_offset, + &enr_ave_m, l_subfr ); - enr_ave_m = mult_r(enr_ave_m, inv_n_subfr); - enr_ave_e = sub(enr_ave_e, 3); + enr_ave_m = mult_r( enr_ave_m, inv_n_subfr ); + enr_ave_e = sub( enr_ave_e, 3 ); - min_shift = 15; /* min_shift <= 15 */ move16(); + min_shift = 15; /* min_shift <= 15 */ + move16(); k = k_offset; move16(); - FOR (i=i_offset; i 0) + IF( enr_m[i] > 0 ) { - BASOP_Util_Divide_MantExp(enr_ave_m, enr_ave_e, - enr_m[i], enr_e[i], - &gain_m[i], &gain_e[i]); + BASOP_Util_Divide_MantExp( enr_ave_m, enr_ave_e, + enr_m[i], enr_e[i], + &gain_m[i], &gain_e[i] ); } ELSE { @@ -1144,64 +1124,64 @@ static Word16 procTfa_Fx( move16(); } - gain_m[i] = Sqrt16(gain_m[i], &gain_e[i]); + gain_m[i] = Sqrt16( gain_m[i], &gain_e[i] ); move16(); - s = norm_s(gain_m[i]); - gain_m[i] = shl(gain_m[i], s); + s = norm_s( gain_m[i] ); + gain_m[i] = shl( gain_m[i], s ); move16(); - gain_e[i] = sub(gain_e[i], s); + gain_e[i] = sub( gain_e[i], s ); move16(); - FOR (j=0; j 15) + exp_syn = sub( s, min_shift ); + if ( exp_syn > 15 ) { exp_syn = 15; move16(); } - if (exp_syn < 0) + if ( exp_syn < 0 ) { exp_syn = 0; move16(); } - min_shift = sub(s, exp_syn); /* exp_syn(old) - exp_syn(new) */ + min_shift = sub( s, exp_syn ); /* exp_syn(old) - exp_syn(new) */ k = k_offset; move16(); - FOR (i=i_offset; i 0) + if ( s > 0 ) { - hb_synth_Fx[k] = shr(hb_synth_Fx[k], s); + hb_synth_Fx[k] = shr( hb_synth_Fx[k], s ); move16(); } - k = add(k, 1); + k = add( k, 1 ); } } @@ -1220,42 +1200,37 @@ Word16 procTecTfa_TBE_Fx( Word16 flat_flag, Word16 last_core, Word16 l_subfr, - Word16 code -) + Word16 code ) { Word16 i_offset = 0; - Word16 exp_syn_frame = sub(15, hb_synth_fx_exp); + Word16 exp_syn_frame = sub( 15, hb_synth_fx_exp ); - IF (flat_flag) + IF( flat_flag ) { - exp_syn_frame = procTfa_Fx(hb_synth_Fx, - exp_syn_frame, - i_offset, - l_subfr - ); + exp_syn_frame = procTfa_Fx( hb_synth_Fx, + exp_syn_frame, + i_offset, + l_subfr ); } ELSE { - if (NE_16(last_core, ACELP_CORE)) + if ( NE_16( last_core, ACELP_CORE ) ) { i_offset = 1; move16(); } - exp_syn_frame = procTec_Fx(hb_synth_Fx, - exp_syn_frame, - gain_m, - gain_e, - i_offset, - l_subfr - , code - ); - + exp_syn_frame = procTec_Fx( hb_synth_Fx, + exp_syn_frame, + gain_m, + gain_e, + i_offset, + l_subfr, code ); } - hb_synth_fx_exp = sub(15, exp_syn_frame); + hb_synth_fx_exp = sub( 15, exp_syn_frame ); return hb_synth_fx_exp; } @@ -1269,13 +1244,12 @@ Word16 procTecTfa_TBE_Fx( void calcHiEnvLoBuff_Fix( const Word16 noCols, - const Word16* pFreqBandTable, /*!< freqbandTable. */ - const Word16 nSfb, /*!< Number of scalefactors. */ - Word32** pCldfbPow_Fix /*float** pCldfbPow*/, - Word16* loBuffer_Fix /*float* loBuffer Q8*/, - Word16* hiTempEnvOrig_Fix /*float* hiTempEnvOrig*/, - Word16 pCldfbPow_FixScale -) + const Word16 *pFreqBandTable, /*!< freqbandTable. */ + const Word16 nSfb, /*!< Number of scalefactors. */ + Word32 **pCldfbPow_Fix /*float** pCldfbPow*/, + Word16 *loBuffer_Fix /*float* loBuffer Q8*/, + Word16 *hiTempEnvOrig_Fix /*float* hiTempEnvOrig*/, + Word16 pCldfbPow_FixScale ) { const Word16 BW_LO = TecLowBandTable[NBTECLOWBAND]; const Word16 lowSubband = pFreqBandTable[0]; @@ -1283,20 +1257,20 @@ void calcHiEnvLoBuff_Fix( Word16 bandOffsetBottom; - Word16* hiTempEnv = hiTempEnvOrig_Fix + EXT_DELAY_HI_TEMP_ENV; + Word16 *hiTempEnv = hiTempEnvOrig_Fix + EXT_DELAY_HI_TEMP_ENV; move16(); move16(); move16(); - bandOffsetBottom = sub(lowSubband, BW_LO); + bandOffsetBottom = sub( lowSubband, BW_LO ); - assert(bandOffsetBottom > 0); - assert(noCols <= CLDFB_NO_COL_MAX); + assert( bandOffsetBottom > 0 ); + assert( noCols <= CLDFB_NO_COL_MAX ); /* ============================================================ */ /* = calc hiTempEnv = */ - calcHiTempEnv_Fx(pCldfbPow_Fix,sub(pCldfbPow_FixScale,30),0,noCols,lowSubband,highSubband,hiTempEnv + DELAY_TEMP_ENV_BUFF_TEC); + calcHiTempEnv_Fx( pCldfbPow_Fix, sub( pCldfbPow_FixScale, 30 ), 0, noCols, lowSubband, highSubband, hiTempEnv + DELAY_TEMP_ENV_BUFF_TEC ); /* = = */ /* ============================================================ */ @@ -1304,7 +1278,7 @@ void calcHiEnvLoBuff_Fix( /* ============================================================ */ /* = calc loBuffer = */ - calcLoBufferEnc_Fx(pCldfbPow_Fix,sub(pCldfbPow_FixScale,30),0, noCols,bandOffsetBottom,loBuffer_Fix + MAX_TEC_SMOOTHING_DEG + DELAY_TEMP_ENV_BUFF_TEC); + calcLoBufferEnc_Fx( pCldfbPow_Fix, sub( pCldfbPow_FixScale, 30 ), 0, noCols, bandOffsetBottom, loBuffer_Fix + MAX_TEC_SMOOTHING_DEG + DELAY_TEMP_ENV_BUFF_TEC ); /* = = */ /* ============================================================ */ @@ -1317,12 +1291,12 @@ void calcHiEnvLoBuff_Fix( *-------------------------------------------------------------------*/ void calcLoEnvCheckCorrHiLo_Fix( const Word16 noCols, - const Word16* pFreqBandTable, /*!< freqbandTable. */ - Word16* loBuffer_Fix /*float* loBuffer Q8*/, - Word16* loTempEnv_Fix /*float* loTempEnv Q7*/, - Word16* loTempEnv_ns_Fix /* float* loTempEnv_ns*/, - Word16* hiTempEnvOrig_Fix /*float* hiTempEnvOrig*/, - Word16* corrFlag /*int* corrFlag*/ + const Word16 *pFreqBandTable, /*!< freqbandTable. */ + Word16 *loBuffer_Fix /*float* loBuffer Q8*/, + Word16 *loTempEnv_Fix /*float* loTempEnv Q7*/, + Word16 *loTempEnv_ns_Fix /* float* loTempEnv_ns*/, + Word16 *hiTempEnvOrig_Fix /*float* hiTempEnvOrig*/, + Word16 *corrFlag /*int* corrFlag*/ ) { const Word16 BW_LO = TecLowBandTable[NBTECLOWBAND]; @@ -1340,72 +1314,72 @@ void calcLoEnvCheckCorrHiLo_Fix( Word32 corrCoef_Fix; Word32 EQ1, EQ2, EQ3; - Word32 EQ4,EQ5,EQ6; + Word32 EQ4, EQ5, EQ6; Word16 code = 0; /* SET TENTATIVELY */ Word32 loVar_ns_Fix; Word32 diff_hi_lo_sum_Fix; Word32 loSum_ns_Fix; - Word16* hiTempEnv = hiTempEnvOrig_Fix + EXT_DELAY_HI_TEMP_ENV; + Word16 *hiTempEnv = hiTempEnvOrig_Fix + EXT_DELAY_HI_TEMP_ENV; move16(); move16(); move16(); - bandOffsetBottom = sub(lowSubband, BW_LO); + bandOffsetBottom = sub( lowSubband, BW_LO ); - assert(bandOffsetBottom > 0); - assert(noCols <= CLDFB_NO_COL_MAX); + assert( bandOffsetBottom > 0 ); + assert( noCols <= CLDFB_NO_COL_MAX ); - FOR( i = 0; i < noCols+ DELAY_TEMP_ENV_BUFF_TEC; i++) + FOR( i = 0; i < noCols + DELAY_TEMP_ENV_BUFF_TEC; i++ ) { - hiTempEnv32_Fix[i] = L_deposit_l(hiTempEnv[i]); + hiTempEnv32_Fix[i] = L_deposit_l( hiTempEnv[i] ); } - hiVar_Fix = calcVar_Fix(hiTempEnv32_Fix, (Word32)noCols, &hiSum_Fix); + hiVar_Fix = calcVar_Fix( hiTempEnv32_Fix, (Word32) noCols, &hiSum_Fix ); /* ============================================================ */ /* = calc loTempEnv = */ - - calcLoTempEnv_Fx(loBuffer_Fix+MAX_TEC_SMOOTHING_DEG,noCols,loTempEnv_Fix,26041/*0.5 * ratioHiLoFac Q15*/); + calcLoTempEnv_Fx( loBuffer_Fix + MAX_TEC_SMOOTHING_DEG, noCols, loTempEnv_Fix, 26041 /*0.5 * ratioHiLoFac Q15*/ ); - calcLoTempEnv_ns_Fx(loBuffer_Fix+MAX_TEC_SMOOTHING_DEG,noCols,loTempEnv_ns_Fix); + calcLoTempEnv_ns_Fx( loBuffer_Fix + MAX_TEC_SMOOTHING_DEG, noCols, loTempEnv_ns_Fix ); /* = = */ /* ============================================================ */ - FOR( i = 0; i < noCols; i++) + FOR( i = 0; i < noCols; i++ ) { - loTempEnv32_ns_Fix[i] = L_deposit_l(loTempEnv_ns_Fix[i]); + loTempEnv32_ns_Fix[i] = L_deposit_l( loTempEnv_ns_Fix[i] ); } - loVar_ns_Fix = calcVar_Fix(loTempEnv32_ns_Fix, noCols, &loSum_ns_Fix); + loVar_ns_Fix = calcVar_Fix( loTempEnv32_ns_Fix, noCols, &loSum_ns_Fix ); - diff_hi_lo_sum_Fix = L_sub(loSum_ns_Fix,hiSum_Fix); + diff_hi_lo_sum_Fix = L_sub( loSum_ns_Fix, hiSum_Fix ); - EQ4 = L_sub(L_shr(hiVar_Fix,7),800); - EQ5 = L_sub(L_shr(loVar_ns_Fix,7),720);; - EQ6 = L_sub(L_shr(diff_hi_lo_sum_Fix,7),100); ; + EQ4 = L_sub( L_shr( hiVar_Fix, 7 ), 800 ); + EQ5 = L_sub( L_shr( loVar_ns_Fix, 7 ), 720 ); + ; + EQ6 = L_sub( L_shr( diff_hi_lo_sum_Fix, 7 ), 100 ); + ; test(); test(); - if (EQ4 > 0 && EQ5 > 0 && EQ6 < 0) + if ( EQ4 > 0 && EQ5 > 0 && EQ6 < 0 ) { code = 1; move16(); } - *corrFlag = 0; move16(); - assert(code == 0 || code == 1); + assert( code == 0 || code == 1 ); - IF (code) + IF( code ) { /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ /* ++++ code == 1 +++++*/ @@ -1419,24 +1393,24 @@ void calcLoEnvCheckCorrHiLo_Fix( move16(); maxPosHi = maxPosLo = 0; move16(); - FOR (i = 1; i < noCols; i++) + FOR( i = 1; i < noCols; i++ ) { - if ( LT_16(maxHiFix , hiTempEnv[i])) + if ( LT_16( maxHiFix, hiTempEnv[i] ) ) { maxPosHi = i; move16(); } - maxHiFix = s_max(maxHiFix, hiTempEnv[i]); + maxHiFix = s_max( maxHiFix, hiTempEnv[i] ); - if ( LT_16(maxLoFix , loTempEnv_ns_Fix[i])) + if ( LT_16( maxLoFix, loTempEnv_ns_Fix[i] ) ) { maxPosLo = i; move16(); } - maxLoFix = s_max(maxLoFix, loTempEnv_ns_Fix[i]); + maxLoFix = s_max( maxLoFix, loTempEnv_ns_Fix[i] ); } - if (LT_16(abs_s( sub(maxPosHi , maxPosLo)), 2)) + if ( LT_16( abs_s( sub( maxPosHi, maxPosLo ) ), 2 ) ) { *corrFlag = 2; move16(); @@ -1451,7 +1425,7 @@ void calcLoEnvCheckCorrHiLo_Fix( Word16 j; Word16 len_window = EXT_DELAY_HI_TEMP_ENV + 1; - Word16* curr_pos_Fix = hiTempEnv; + Word16 *curr_pos_Fix = hiTempEnv; move16(); move16(); @@ -1463,48 +1437,47 @@ void calcLoEnvCheckCorrHiLo_Fix( pos_feature_max = 0; move16(); - FOR (i = 0; i < 16; i++) + FOR( i = 0; i < 16; i++ ) { max_local_Fix = min_local_Fix = curr_pos_Fix[0]; move16(); move16(); - FOR (j = 1; j < len_window; j++) + FOR( j = 1; j < len_window; j++ ) { - if ( LT_16( max_local_Fix , curr_pos_Fix[-j])) + if ( LT_16( max_local_Fix, curr_pos_Fix[-j] ) ) { max_local_Fix = curr_pos_Fix[-j]; move16(); } - if ( GT_16(min_local_Fix, curr_pos_Fix[-j] )) + if ( GT_16( min_local_Fix, curr_pos_Fix[-j] ) ) { min_local_Fix = curr_pos_Fix[-j]; move16(); } } - feature_Fix[i] = sub(max_local_Fix , min_local_Fix); + feature_Fix[i] = sub( max_local_Fix, min_local_Fix ); - if ( LT_16(feature_max_Fix , feature_Fix[i])) + if ( LT_16( feature_max_Fix, feature_Fix[i] ) ) { pos_feature_max = i; move16(); } - feature_max_Fix = s_max(feature_max_Fix, feature_Fix[i]); + feature_max_Fix = s_max( feature_max_Fix, feature_Fix[i] ); curr_pos_Fix += 1; } - IF (*corrFlag > 0) + IF( *corrFlag > 0 ) { test(); - if ((LE_16(feature_max_Fix, shl(20, 7))||GE_16(abs_s(sub(pos_feature_max,maxPosHi)),3))) + if ( ( LE_16( feature_max_Fix, shl( 20, 7 ) ) || GE_16( abs_s( sub( pos_feature_max, maxPosHi ) ), 3 ) ) ) { *corrFlag = 0; move16(); } } } - } ELSE { @@ -1516,11 +1489,11 @@ void calcLoEnvCheckCorrHiLo_Fix( /* ============================================================ */ /* = calc the variance of loTempEnv = */ - FOR( i = 0; i < noCols; i++) + FOR( i = 0; i < noCols; i++ ) { - loTempEnv32_Fix[i] = L_deposit_l(loTempEnv_Fix[i]); + loTempEnv32_Fix[i] = L_deposit_l( loTempEnv_Fix[i] ); } - loVar_Fix = calcVar_Fix(loTempEnv32_Fix, noCols, &loSum_Fix); + loVar_Fix = calcVar_Fix( loTempEnv32_Fix, noCols, &loSum_Fix ); /* = = */ /* ============================================================ */ @@ -1529,39 +1502,35 @@ void calcLoEnvCheckCorrHiLo_Fix( /* = loTempEnv and hiTempEnv = */ corrCoef_Fix = calcCorrelationCoefficient2_Fix( hiTempEnv32_Fix, loTempEnv32_Fix, - noCols, hiVar_Fix, loVar_Fix, hiSum_Fix, loSum_Fix); + noCols, hiVar_Fix, loVar_Fix, hiSum_Fix, loSum_Fix ); /* = = */ /* ============================================================ */ - - - EQ1 = L_sub(L_shl(corrCoef_Fix, 8),28819/*thCorrCoef Q15*/); - EQ2 = L_sub(L_shl(hiVar_Fix,0),Mpy_32_16_1(loVar_Fix,11957/*thRatio Q15*/)); - EQ3 = L_sub(L_shr(hiVar_Fix,2),Mpy_32_16_1(loVar_Fix,16620/*thRatio2 Q13*/)); + EQ1 = L_sub( L_shl( corrCoef_Fix, 8 ), 28819 /*thCorrCoef Q15*/ ); + EQ2 = L_sub( L_shl( hiVar_Fix, 0 ), Mpy_32_16_1( loVar_Fix, 11957 /*thRatio Q15*/ ) ); + EQ3 = L_sub( L_shr( hiVar_Fix, 2 ), Mpy_32_16_1( loVar_Fix, 16620 /*thRatio2 Q13*/ ) ); test(); test(); - if (EQ1 >= 0 && EQ2 > 0 /*ratio > thRatio*/ && EQ3 < 0) + if ( EQ1 >= 0 && EQ2 > 0 /*ratio > thRatio*/ && EQ3 < 0 ) { *corrFlag = 1; move16(); } - } - FOR (i = 0; i < MAX_TEC_SMOOTHING_DEG + DELAY_TEMP_ENV_BUFF_TEC; i++) + FOR( i = 0; i < MAX_TEC_SMOOTHING_DEG + DELAY_TEMP_ENV_BUFF_TEC; i++ ) { loBuffer_Fix[i] = loBuffer_Fix[noCols + i]; move16(); } - FOR (i = 0; i < DELAY_TEMP_ENV_BUFF_TEC + EXT_DELAY_HI_TEMP_ENV; i++) + FOR( i = 0; i < DELAY_TEMP_ENV_BUFF_TEC + EXT_DELAY_HI_TEMP_ENV; i++ ) { hiTempEnvOrig_Fix[i] = hiTempEnvOrig_Fix[noCols + i]; move16(); } - } /*------------------------------------------------------------------- @@ -1571,10 +1540,9 @@ void calcLoEnvCheckCorrHiLo_Fix( *-------------------------------------------------------------------*/ void tecEnc_TBE_fx( - Word16* corrFlag, - const Word16* voicing, - const Word16 coder_type -) + Word16 *corrFlag, + const Word16 *voicing, + const Word16 coder_type ) { Word16 voice_sum; Word16 voice_diff; @@ -1583,27 +1551,27 @@ void tecEnc_TBE_fx( * TEC updates *-----------------------------------------------------------------*/ - voice_sum = add(shr(voicing[0], 1), shr(voicing[1], 1)); /*voice_sum = voicing[0] + voicing[1];*/ - voice_diff = sub(voicing[0], voicing[1]); /*voice_diff = voicing[0] - voicing[1];*/ + voice_sum = add( shr( voicing[0], 1 ), shr( voicing[1], 1 ) ); /*voice_sum = voicing[0] + voicing[1];*/ + voice_diff = sub( voicing[0], voicing[1] ); /*voice_diff = voicing[0] - voicing[1];*/ - if( voice_diff < 0 ) + if ( voice_diff < 0 ) { - voice_diff = negate(voice_diff);/*voice_diff *= -1.0f;*/ + voice_diff = negate( voice_diff ); /*voice_diff *= -1.0f;*/ } - IF( EQ_16(*corrFlag, 1)) + IF( EQ_16( *corrFlag, 1 ) ) { test(); test(); test(); /*if( ((voice_sum > 0.35 * 2 && voice_sum < 0.55 * 2) && (voice_diff < 0.2)) )*/ - if( EQ_16(coder_type,INACTIVE) || (GT_16(voice_sum,11469/*0.35 Q15*/) && LT_16(voice_sum,18022/*0.55 Q15*/) && (sub(voice_diff,6554/*0.2 Q15*/)<0))) + if ( EQ_16( coder_type, INACTIVE ) || ( GT_16( voice_sum, 11469 /*0.35 Q15*/ ) && LT_16( voice_sum, 18022 /*0.55 Q15*/ ) && ( sub( voice_diff, 6554 /*0.2 Q15*/ ) < 0 ) ) ) { *corrFlag = 0; move16(); } } - if( GT_16(voice_sum, 19661/*0.6 Q15*/)) /*if( voice_sum > 0.6 * 2 )*/ + if ( GT_16( voice_sum, 19661 /*0.6 Q15*/ ) ) /*if( voice_sum > 0.6 * 2 )*/ { *corrFlag = 0; move16(); @@ -1615,27 +1583,25 @@ void tecEnc_TBE_fx( * *-------------------------------------------------------------------*/ void set_TEC_TFA_code_fx( - const Word16 corrFlag, - Word16* tec_flag, - Word16* tfa_flag -) + const Word16 corrFlag, + Word16 *tec_flag, + Word16 *tfa_flag ) { *tec_flag = 0; move16(); - IF (*tfa_flag == 0) + IF( *tfa_flag == 0 ) { test(); - if (EQ_16(corrFlag, 1)||EQ_16(corrFlag,2)) + if ( EQ_16( corrFlag, 1 ) || EQ_16( corrFlag, 2 ) ) { *tec_flag = 1; move16(); } - if (EQ_16(corrFlag, 2)) + if ( EQ_16( corrFlag, 2 ) ) { *tfa_flag = 1; move16(); } } } - diff --git a/lib_com/tns_base.c b/lib_com/tns_base.c index fcc442f8c..f89bf8e07 100644 --- a/lib_com/tns_base.c +++ b/lib_com/tns_base.c @@ -18,7 +18,7 @@ * Local constants *---------------------------------------------------------------------------*/ -#define HLM_MIN_NRG 32768.0f +#define HLM_MIN_NRG 32768.0f #define MAX_SUBDIVISIONS 3 @@ -27,31 +27,31 @@ *---------------------------------------------------------------------------*/ /** Linear prediction analysis/synthesis filter definition. - * @param order filter order. - * @param parCoeff filter (PARCOR) coefficients. - * @param state state of the filter. Must be at least of 'order' size. - * @param x the current input value. - * @return the output of the filter. - */ -typedef Word32 (* TLinearPredictionFilter)(Word16 order, Word16 const parCoeff[], Word32 * state, Word32 x); + * @param order filter order. + * @param parCoeff filter (PARCOR) coefficients. + * @param state state of the filter. Must be at least of 'order' size. + * @param x the current input value. + * @return the output of the filter. + */ +typedef Word32 ( *TLinearPredictionFilter )( Word16 order, Word16 const parCoeff[], Word32 *state, Word32 x ); /** Inverse quantization for reflection coefficients. - * - * @param index input quantized values. - * @param parCoeff output reflection coefficients. - * @param order number of coefficients/values. - */ -static void Index2Parcor(Word16 const index[], Word16 parCoeff[], Word16 order); + * + * @param index input quantized values. + * @param parCoeff output reflection coefficients. + * @param order number of coefficients/values. + */ +static void Index2Parcor( Word16 const index[], Word16 parCoeff[], Word16 order ); /** Linear prediction analysis filter. - * See TLinearPredictionFilter for details. - */ -static Word32 FIRLattice(const Word16 order, const Word16 *parCoeff, Word32 *state, Word32 x); + * See TLinearPredictionFilter for details. + */ +static Word32 FIRLattice( const Word16 order, const Word16 *parCoeff, Word32 *state, Word32 x ); /** Linear prediction synthesis filter. - * See TLinearPredictionFilter for details. - */ -static Word32 IIRLattice(Word16 order, const Word16 *parCoeff, Word32 *state, Word32 x); + * See TLinearPredictionFilter for details. + */ +static Word32 IIRLattice( Word16 order, const Word16 *parCoeff, Word32 *state, Word32 x ); /** TNS analysis/synthesis filter. * @param spectrum input spectrum values. @@ -63,11 +63,11 @@ static Word32 IIRLattice(Word16 order, const Word16 *parCoeff, Word32 *state, Wo * @param output filtered output spectrum values. Inplace operation is supported, so it can be equal to spectrum. */ -static void TnsFilter(const Word32 spectrum[], const Word16 numOfLines, const Word16 parCoeff[], const Word16 order, TLinearPredictionFilter filter, Word32 * state, Word32 output[]); +static void TnsFilter( const Word32 spectrum[], const Word16 numOfLines, const Word16 parCoeff[], const Word16 order, TLinearPredictionFilter filter, Word32 *state, Word32 output[] ); -static void ITF_TnsFilter_fx( const Word32 spectrum[], const Word16 numOfLines, const Word16 A[], /* Q14 */ const Word16 Q_A, const Word16 order, Word32 output[]); +static void ITF_TnsFilter_fx( const Word32 spectrum[], const Word16 numOfLines, const Word16 A[], /* Q14 */ const Word16 Q_A, const Word16 order, Word32 output[] ); -static void ITF_GetFilterParameters_fx(Word32 rxx[], const Word16 maxOrder, Word16* A, /* Q14 */Word16* Q_A, Word16* predictionGain); +static void ITF_GetFilterParameters_fx( Word32 rxx[], const Word16 maxOrder, Word16 *A, /* Q14 */ Word16 *Q_A, Word16 *predictionGain ); /********************************/ /* Interface functions */ @@ -83,30 +83,29 @@ static void ITF_GetFilterParameters_fx(Word32 rxx[], const Word16 maxOrder, Wor void InitTnsConfiguration( const Word16 bwidth, const Word16 frameLength, - STnsConfig * pTnsConfig, + STnsConfig *pTnsConfig, const Word16 igfStopFreq, const Word32 total_brate, const int16_t element_mode, - const int16_t is_mct -) + const int16_t is_mct ) { Word16 iFilter = 0; - Word16 * startLineFilter; + Word16 *startLineFilter; Word32 L_tmp; Word32 nSampleRate; Word16 s1; Word16 s2; #ifndef ADD_IVAS_TNS - (void)(element_mode); - (void)(is_mct); + (void) ( element_mode ); + (void) ( is_mct ); #endif nSampleRate = bwMode2fs[bwidth]; move32(); startLineFilter = &pTnsConfig->iFilterBorders[1]; /* Sanity checks */ - assert((nSampleRate > 0) && (frameLength > 0) && (pTnsConfig != NULL)); - if ((nSampleRate <= 0) || (frameLength <= 0) || (pTnsConfig == NULL)) + assert( ( nSampleRate > 0 ) && ( frameLength > 0 ) && ( pTnsConfig != NULL ) ); + if ( ( nSampleRate <= 0 ) || ( frameLength <= 0 ) || ( pTnsConfig == NULL ) ) { return /*TNS_FATAL_ERROR*/; } @@ -114,33 +113,33 @@ void InitTnsConfiguration( /* Initialize TNS filter flag and maximum order */ move16(); - pTnsConfig->maxOrder = TNS_MAX_FILTER_ORDER; + pTnsConfig->maxOrder = TNS_MAX_FILTER_ORDER; - IF (LE_32(total_brate, ACELP_32k)) + IF( LE_32( total_brate, ACELP_32k ) ) { move16(); move16(); - pTnsConfig->nMaxFilters = sizeof(tnsParametersIGF32kHz_LowBR)/sizeof(tnsParametersIGF32kHz_LowBR[0]); + pTnsConfig->nMaxFilters = sizeof( tnsParametersIGF32kHz_LowBR ) / sizeof( tnsParametersIGF32kHz_LowBR[0] ); pTnsConfig->pTnsParameters = tnsParametersIGF32kHz_LowBR; } ELSE { test(); - IF (GT_32(nSampleRate,32000)&&EQ_32(nSampleRate,L_mult0(100,frameLength))) + IF( GT_32( nSampleRate, 32000 ) && EQ_32( nSampleRate, L_mult0( 100, frameLength ) ) ) { move16(); - pTnsConfig->nMaxFilters = sizeof(tnsParameters48kHz_grouped)/sizeof(tnsParameters48kHz_grouped[0]); + pTnsConfig->nMaxFilters = sizeof( tnsParameters48kHz_grouped ) / sizeof( tnsParameters48kHz_grouped[0] ); move16(); pTnsConfig->pTnsParameters = tnsParameters48kHz_grouped; } ELSE - IF ( GT_32(nSampleRate,INT_FS_16k)) + IF( GT_32( nSampleRate, INT_FS_16k ) ) { #ifdef ADD_IVAS_TNS - if ((element_mode > IVAS_SCE) && (total_brate >= (is_mct ? IVAS_32k : IVAS_48k))) + if ( ( element_mode > IVAS_SCE ) && ( total_brate >= ( is_mct ? IVAS_32k : IVAS_48k ) ) ) { - pTnsConfig->nMaxFilters = sizeof(tnsParameters32kHz_Stereo) / sizeof(tnsParameters32kHz_Stereo[0]); - if (nSampleRate == 100 * frameLength) /* sub-frame length is <= 10 ms */ + pTnsConfig->nMaxFilters = sizeof( tnsParameters32kHz_Stereo ) / sizeof( tnsParameters32kHz_Stereo[0] ); + if ( nSampleRate == 100 * frameLength ) /* sub-frame length is <= 10 ms */ { pTnsConfig->pTnsParameters = tnsParameters32kHz_grouped; } @@ -154,12 +153,12 @@ void InitTnsConfiguration( { move16(); - pTnsConfig->nMaxFilters = sizeof(tnsParameters32kHz) / sizeof(tnsParameters32kHz[0]); + pTnsConfig->nMaxFilters = sizeof( tnsParameters32kHz ) / sizeof( tnsParameters32kHz[0] ); move16(); pTnsConfig->pTnsParameters = tnsParameters32kHz; - if (EQ_32(nSampleRate, L_mult0(100, frameLength))) /* sub-frame length is <= 10 ms */ + if ( EQ_32( nSampleRate, L_mult0( 100, frameLength ) ) ) /* sub-frame length is <= 10 ms */ { move16(); pTnsConfig->pTnsParameters = tnsParameters32kHz_grouped; @@ -168,51 +167,50 @@ void InitTnsConfiguration( } ELSE { - IF ( EQ_32(nSampleRate, L_mult0(100, frameLength))) /* sub-frame length is <= 10 ms */ + IF( EQ_32( nSampleRate, L_mult0( 100, frameLength ) ) ) /* sub-frame length is <= 10 ms */ { move16(); move16(); - pTnsConfig->nMaxFilters = sizeof(tnsParameters16kHz_grouped)/sizeof(tnsParameters16kHz_grouped[0]); + pTnsConfig->nMaxFilters = sizeof( tnsParameters16kHz_grouped ) / sizeof( tnsParameters16kHz_grouped[0] ); pTnsConfig->pTnsParameters = tnsParameters16kHz_grouped; } ELSE { move16(); move16(); - pTnsConfig->nMaxFilters = sizeof(tnsParameters16kHz)/sizeof(tnsParameters16kHz[0]); + pTnsConfig->nMaxFilters = sizeof( tnsParameters16kHz ) / sizeof( tnsParameters16kHz[0] ); pTnsConfig->pTnsParameters = tnsParameters16kHz; } } } - assert(pTnsConfig->nMaxFilters <= TNS_MAX_NUM_OF_FILTERS); + assert( pTnsConfig->nMaxFilters <= TNS_MAX_NUM_OF_FILTERS ); /* Set starting MDCT line for each filter based on the starting frequencies from the TNS table */ - FOR (iFilter = 0; iFilter < pTnsConfig->nMaxFilters; iFilter++) + FOR( iFilter = 0; iFilter < pTnsConfig->nMaxFilters; iFilter++ ) { - assert(pTnsConfig->pTnsParameters[iFilter].startLineFrequency < 0.5f*nSampleRate); - assert(nSampleRate <= 96000); + assert( pTnsConfig->pTnsParameters[iFilter].startLineFrequency < 0.5f * nSampleRate ); + assert( nSampleRate <= 96000 ); move16(); - startLineFilter[iFilter] = divide3232(L_mult0(frameLength, pTnsConfig->pTnsParameters[iFilter].startLineFrequency), L_shl(nSampleRate,14)); + startLineFilter[iFilter] = divide3232( L_mult0( frameLength, pTnsConfig->pTnsParameters[iFilter].startLineFrequency ), L_shl( nSampleRate, 14 ) ); } - IF (igfStopFreq > 0) + IF( igfStopFreq > 0 ) { - L_tmp = L_mult(frameLength, igfStopFreq); - s1 = sub(norm_l(L_tmp), 1); - s2 = norm_l(nSampleRate); + L_tmp = L_mult( frameLength, igfStopFreq ); + s1 = sub( norm_l( L_tmp ), 1 ); + s2 = norm_l( nSampleRate ); move16(); - pTnsConfig->iFilterBorders[0] = shr( div_l( L_shl(L_tmp, s1), extract_h(L_shl(nSampleRate, s2)) ) , sub(WORD16_BITS-1, sub(s2, s1))); - + pTnsConfig->iFilterBorders[0] = shr( div_l( L_shl( L_tmp, s1 ), extract_h( L_shl( nSampleRate, s2 ) ) ), sub( WORD16_BITS - 1, sub( s2, s1 ) ) ); } ELSE { move16(); pTnsConfig->iFilterBorders[0] = frameLength; } -#ifdef ADD_IVAS_TNS +#ifdef ADD_IVAS_TNS pTnsConfig->allowTnsOnWhite = 0; #endif return; /*TNS_NO_ERROR;*/ @@ -224,34 +222,33 @@ void InitTnsConfiguration( *-------------------------------------------------------------------*/ void ApplyTnsFilter( - STnsConfig const * pTnsConfig, - STnsData const * pTnsData, + STnsConfig const *pTnsConfig, + STnsData const *pTnsData, Word32 spectrum[], - const Word8 fIsAnalysis -) + const Word8 fIsAnalysis ) { TLinearPredictionFilter filter; Word32 state[TNS_MAX_FILTER_ORDER]; Word16 iFilter; Word16 stopLine, startLine; - Word16 const * pBorders; + Word16 const *pBorders; move16(); filter = IIRLattice; - if (fIsAnalysis) + if ( fIsAnalysis ) { move16(); filter = FIRLattice; } - set32_fx(state, 0, TNS_MAX_FILTER_ORDER); + set32_fx( state, 0, TNS_MAX_FILTER_ORDER ); move16(); pBorders = pTnsConfig->iFilterBorders; - FOR (iFilter = pTnsConfig->nMaxFilters-1; iFilter >= 0; iFilter--) + FOR( iFilter = pTnsConfig->nMaxFilters - 1; iFilter >= 0; iFilter-- ) { Word16 parCoeff[TNS_MAX_FILTER_ORDER]; - const STnsFilter * pFilter; + const STnsFilter *pFilter; move16(); @@ -259,15 +256,14 @@ void ApplyTnsFilter( move16(); pFilter = &pTnsData->filter[iFilter]; stopLine = pBorders[iFilter]; - startLine = pBorders[iFilter+1]; - - Index2Parcor(pFilter->coefIndex, parCoeff, pFilter->order); + startLine = pBorders[iFilter + 1]; - TnsFilter(&spectrum[startLine], stopLine-startLine, - parCoeff, pFilter->order, - filter, state, - &spectrum[startLine]); + Index2Parcor( pFilter->coefIndex, parCoeff, pFilter->order ); + TnsFilter( &spectrum[startLine], stopLine - startLine, + parCoeff, pFilter->order, + filter, state, + &spectrum[startLine] ); } move16(); @@ -280,37 +276,35 @@ void ApplyTnsFilter( * *-------------------------------------------------------------------*/ -void ITF_Apply_fx( +void ITF_Apply_fx( Word32 spectrum[], Word16 startLine, Word16 stopLine, - const Word16* A, + const Word16 *A, Word16 Q_A, - Word16 order -) + Word16 order ) { - ITF_TnsFilter_fx(&spectrum[startLine],(Word16)(stopLine-startLine), A, Q_A, (Word16)order, &spectrum[startLine]); + ITF_TnsFilter_fx( &spectrum[startLine], (Word16) ( stopLine - startLine ), A, Q_A, (Word16) order, &spectrum[startLine] ); return /*TNS_NO_ERROR*/; } /*-------------------------------------------------------------------* -* ITF_Detect() -* -* -*-------------------------------------------------------------------*/ + * ITF_Detect() + * + * + *-------------------------------------------------------------------*/ Word16 ITF_Detect_fx( const Word32 pSpectrum[], const Word16 startLine, const Word16 stopLine, const Word16 maxOrder, - Word16* A, - Word16* Q_A, - Word16* predictionGain, - Word16* curr_order, - Word16 Q -) + Word16 *A, + Word16 *Q_A, + Word16 *predictionGain, + Word16 *curr_order, + Word16 Q ) { Word16 spectrumLength; @@ -322,7 +316,7 @@ Word16 ITF_Detect_fx( Word16 facs_e[MAX_SUBDIVISIONS]; /* exponents of facs[][] */ Word16 shifts[MAX_SUBDIVISIONS]; Word16 tmp, headroom, shift; - Word32 rxx[ITF_MAX_FILTER_ORDER+1]; + Word32 rxx[ITF_MAX_FILTER_ORDER + 1]; Word16 lag; Word32 L_tmp, tmp32; Word16 tmpbuf[325]; @@ -335,42 +329,44 @@ Word16 ITF_Detect_fx( move16(); move16(); - if (maxOrder <= 0) + if ( maxOrder <= 0 ) { return 0; } /* Calculate norms for each spectrum part */ - FOR (iSubdivisions = 0; iSubdivisions < nSubdivisions; iSubdivisions++) + FOR( iSubdivisions = 0; iSubdivisions < nSubdivisions; iSubdivisions++ ) { - assert((nSubdivisions == 1) || (nSubdivisions == 3)); + assert( ( nSubdivisions == 1 ) || ( nSubdivisions == 3 ) ); - tmp = sub(stopLine, startLine); - iStartLine = imult1616(tmp, iSubdivisions); - iEndLine = add(iStartLine, tmp); + tmp = sub( stopLine, startLine ); + iStartLine = imult1616( tmp, iSubdivisions ); + iEndLine = add( iStartLine, tmp ); - if (EQ_16(nSubdivisions, 3))iStartLine=mult(iStartLine,0x2AAB); - iStartLine = add(iStartLine, startLine); + if ( EQ_16( nSubdivisions, 3 ) ) + iStartLine = mult( iStartLine, 0x2AAB ); + iStartLine = add( iStartLine, startLine ); - if (EQ_16(nSubdivisions, 3))iEndLine=mult(iEndLine,0x2AAB); - iEndLine = add(iEndLine, startLine); - headroom = getScaleFactor32(pSpectrum+iStartLine-IGF_START_MN, sub(iEndLine, iStartLine)); + if ( EQ_16( nSubdivisions, 3 ) ) + iEndLine = mult( iEndLine, 0x2AAB ); + iEndLine = add( iEndLine, startLine ); + headroom = getScaleFactor32( pSpectrum + iStartLine - IGF_START_MN, sub( iEndLine, iStartLine ) ); /* Calculate norm of spectrum band */ - L_tmp = Norm32Norm(pSpectrum+iStartLine-IGF_START_MN, headroom, sub(iEndLine, iStartLine), &shift); + L_tmp = Norm32Norm( pSpectrum + iStartLine - IGF_START_MN, headroom, sub( iEndLine, iStartLine ), &shift ); /* Check threshold HLM_MIN_NRG */ BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB - tmp32 = L_sub(L_shl_o(L_tmp, sub(shift, 24-Q), &Overflow), 4194304l/*HLM_MIN_NRG Q7*/); + tmp32 = L_sub( L_shl_o( L_tmp, sub( shift, 24 - Q ), &Overflow ), 4194304l /*HLM_MIN_NRG Q7*/ ); #else /* BASOP_NOGLOB */ - tmp32 = L_sub(L_shl(L_tmp, sub(shift, 24-Q)), 4194304l/*HLM_MIN_NRG Q7*/); + tmp32 = L_sub( L_shl( L_tmp, sub( shift, 24 - Q ) ), 4194304l /*HLM_MIN_NRG Q7*/ ); #endif BASOP_SATURATE_WARNING_ON_EVS; /* get pre-shift for autocorrelation */ - tmp = sub(shift, norm_l(L_tmp)); /* exponent for normalized L_tmp */ - tmp = shr(sub(1, tmp), 1); /* pre-shift to apply before autocorrelation */ - shifts[iSubdivisions] = s_min(tmp, headroom); + tmp = sub( shift, norm_l( L_tmp ) ); /* exponent for normalized L_tmp */ + tmp = shr( sub( 1, tmp ), 1 ); /* pre-shift to apply before autocorrelation */ + shifts[iSubdivisions] = s_min( tmp, headroom ); move16(); /* calc normalization factor */ @@ -379,20 +375,20 @@ Word16 ITF_Detect_fx( facs_e[iSubdivisions] = 0; move16(); - if (tmp32 > 0) + if ( tmp32 > 0 ) { facs[iSubdivisions] = 0x7FFF; move16(); /* normalization not needed for one subdivision */ } test(); - IF ((tmp32 > 0) && (GT_16(nSubdivisions, 1))) + IF( ( tmp32 > 0 ) && ( GT_16( nSubdivisions, 1 ) ) ) { move16(); - facs_e[iSubdivisions] = shl(sub(tmp, shifts[iSubdivisions]), 1); + facs_e[iSubdivisions] = shl( sub( tmp, shifts[iSubdivisions] ), 1 ); - tmp = sub(1, shl(tmp, 1)); /* exponent of autocorrelation */ - L_tmp = L_shl(L_tmp, sub(shift, tmp)); /* shift L_tmp to that exponent */ + tmp = sub( 1, shl( tmp, 1 ) ); /* exponent of autocorrelation */ + L_tmp = L_shl( L_tmp, sub( shift, tmp ) ); /* shift L_tmp to that exponent */ /* calc factor (with 2 bits headroom for sum of 3 subdivisions) */ #ifdef BASOP_NOGLOB @@ -402,70 +398,70 @@ Word16 ITF_Detect_fx( #endif move16(); } - } /* Calculate normalized autocorrelation for spectrum subdivision and get filter parameters based on it */ - set32_fx(rxx, 0, ITF_MAX_FILTER_ORDER+1); + set32_fx( rxx, 0, ITF_MAX_FILTER_ORDER + 1 ); - spectrumLength = sub(stopLine, startLine); + spectrumLength = sub( stopLine, startLine ); - FOR (iSubdivisions = 0; iSubdivisions < nSubdivisions; iSubdivisions++) + FOR( iSubdivisions = 0; iSubdivisions < nSubdivisions; iSubdivisions++ ) { - IF ( facs[iSubdivisions] == 0 ) + IF( facs[iSubdivisions] == 0 ) { BREAK; } - assert((nSubdivisions == 1) || (nSubdivisions == 3)); + assert( ( nSubdivisions == 1 ) || ( nSubdivisions == 3 ) ); - iStartLine = imult1616(spectrumLength, iSubdivisions); - iEndLine = add(iStartLine, spectrumLength); + iStartLine = imult1616( spectrumLength, iSubdivisions ); + iEndLine = add( iStartLine, spectrumLength ); - if (EQ_16(nSubdivisions, 3))iStartLine=mult(iStartLine,0x2AAB); - iStartLine = add(iStartLine, startLine); + if ( EQ_16( nSubdivisions, 3 ) ) + iStartLine = mult( iStartLine, 0x2AAB ); + iStartLine = add( iStartLine, startLine ); - if (EQ_16(nSubdivisions, 3))iEndLine=mult(iEndLine,0x2AAB); - iEndLine = add(iEndLine, startLine); + if ( EQ_16( nSubdivisions, 3 ) ) + iEndLine = mult( iEndLine, 0x2AAB ); + iEndLine = add( iEndLine, startLine ); move16(); shift = shifts[iSubdivisions]; - n = sub(iEndLine, iStartLine); - assert(n < (Word16)(sizeof(tmpbuf)/sizeof(Word16))); - FOR (i = 0; i < n; i++) + n = sub( iEndLine, iStartLine ); + assert( n < (Word16) ( sizeof( tmpbuf ) / sizeof( Word16 ) ) ); + FOR( i = 0; i < n; i++ ) { - tmpbuf[i] = round_fx(L_shl(pSpectrum[iStartLine+i-IGF_START_MN], shift)); + tmpbuf[i] = round_fx( L_shl( pSpectrum[iStartLine + i - IGF_START_MN], shift ) ); } - FOR (lag = 0; lag <= maxOrder; lag++) + FOR( lag = 0; lag <= maxOrder; lag++ ) { - n = sub(sub(iEndLine,lag), iStartLine); + n = sub( sub( iEndLine, lag ), iStartLine ); { Word64 tmp64 = 0; - FOR (i = 0; i < n; i++) + FOR( i = 0; i < n; i++ ) { - tmp64 = W_mac0_16_16(tmp64, tmpbuf[i], tmpbuf[i+lag]); + tmp64 = W_mac0_16_16( tmp64, tmpbuf[i], tmpbuf[i + lag] ); } - L_tmp = W_sat_l(tmp64); + L_tmp = W_sat_l( tmp64 ); } - L_tmp = Mpy_32_16_1(L_tmp, facs[iSubdivisions]); - L_tmp = L_shl(L_tmp, facs_e[iSubdivisions]); + L_tmp = Mpy_32_16_1( L_tmp, facs[iSubdivisions] ); + L_tmp = L_shl( L_tmp, facs_e[iSubdivisions] ); - rxx[lag] = L_add(rxx[lag], L_tmp); + rxx[lag] = L_add( rxx[lag], L_tmp ); move32(); } - } - IF ( EQ_16(iSubdivisions,nSubdivisions)) /* meaning there is no subdivision with low energy */ + IF( EQ_16( iSubdivisions, nSubdivisions ) ) /* meaning there is no subdivision with low energy */ { /* Limit the maximum order to spectrum length/4 */ - ITF_GetFilterParameters_fx(rxx, s_min (maxOrder, shr(spectrumLength,2)), A, Q_A, predictionGain); + ITF_GetFilterParameters_fx( rxx, s_min( maxOrder, shr( spectrumLength, 2 ) ), A, Q_A, predictionGain ); *curr_order = maxOrder; } @@ -478,12 +474,11 @@ Word16 ITF_Detect_ivas_fx( const Word16 startLine, const Word16 stopLine, const Word16 maxOrder, - Word16* A, - Word16* Q_A, - Word16* predictionGain, - Word16* curr_order, - Word16 Q -) + Word16 *A, + Word16 *Q_A, + Word16 *predictionGain, + Word16 *curr_order, + Word16 Q ) { Word16 spectrumLength; @@ -495,7 +490,7 @@ Word16 ITF_Detect_ivas_fx( Word16 facs_e[MAX_SUBDIVISIONS]; /* exponents of facs[][] */ Word16 shifts[MAX_SUBDIVISIONS]; Word16 tmp, headroom, shift; - Word32 rxx[ITF_MAX_FILTER_ORDER+1]; + Word32 rxx[ITF_MAX_FILTER_ORDER + 1]; Word16 lag; Word32 L_tmp, tmp32; Word16 tmpbuf[325]; @@ -508,42 +503,44 @@ Word16 ITF_Detect_ivas_fx( move16(); move16(); - if (maxOrder <= 0) + if ( maxOrder <= 0 ) { return 0; } /* Calculate norms for each spectrum part */ - FOR (iSubdivisions = 0; iSubdivisions < nSubdivisions; iSubdivisions++) + FOR( iSubdivisions = 0; iSubdivisions < nSubdivisions; iSubdivisions++ ) { - assert((nSubdivisions == 1) || (nSubdivisions == 3)); + assert( ( nSubdivisions == 1 ) || ( nSubdivisions == 3 ) ); - tmp = sub(stopLine, startLine); - iStartLine = imult1616(tmp, iSubdivisions); - iEndLine = add(iStartLine, tmp); + tmp = sub( stopLine, startLine ); + iStartLine = imult1616( tmp, iSubdivisions ); + iEndLine = add( iStartLine, tmp ); - if (EQ_16(nSubdivisions, 3))iStartLine=mult(iStartLine,0x2AAB); - iStartLine = add(iStartLine, startLine); + if ( EQ_16( nSubdivisions, 3 ) ) + iStartLine = mult( iStartLine, 0x2AAB ); + iStartLine = add( iStartLine, startLine ); - if (EQ_16(nSubdivisions, 3))iEndLine=mult(iEndLine,0x2AAB); - iEndLine = add(iEndLine, startLine); - headroom = getScaleFactor32(pSpectrum+iStartLine-IGF_START_MN, sub(iEndLine, iStartLine)); + if ( EQ_16( nSubdivisions, 3 ) ) + iEndLine = mult( iEndLine, 0x2AAB ); + iEndLine = add( iEndLine, startLine ); + headroom = getScaleFactor32( pSpectrum + iStartLine - IGF_START_MN, sub( iEndLine, iStartLine ) ); /* Calculate norm of spectrum band */ - L_tmp = Norm32Norm(pSpectrum+iStartLine-IGF_START_MN, headroom, sub(iEndLine, iStartLine), &shift); + L_tmp = Norm32Norm( pSpectrum + iStartLine - IGF_START_MN, headroom, sub( iEndLine, iStartLine ), &shift ); /* Check threshold HLM_MIN_NRG */ BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB - tmp32 = L_sub(L_shl_o(L_tmp, sub(shift, 24-Q), &Overflow), 4194304l/*HLM_MIN_NRG Q7*/); + tmp32 = L_sub( L_shl_o( L_tmp, sub( shift, 24 - Q ), &Overflow ), 4194304l /*HLM_MIN_NRG Q7*/ ); #else /* BASOP_NOGLOB */ - tmp32 = L_sub(L_shl(L_tmp, sub(shift, 24-Q)), 4194304l/*HLM_MIN_NRG Q7*/); + tmp32 = L_sub( L_shl( L_tmp, sub( shift, 24 - Q ) ), 4194304l /*HLM_MIN_NRG Q7*/ ); #endif BASOP_SATURATE_WARNING_ON_EVS; /* get pre-shift for autocorrelation */ - tmp = sub(shift, norm_l(L_tmp)); /* exponent for normalized L_tmp */ - tmp = shr(sub(1, tmp), 1); /* pre-shift to apply before autocorrelation */ - shifts[iSubdivisions] = s_min(tmp, headroom); + tmp = sub( shift, norm_l( L_tmp ) ); /* exponent for normalized L_tmp */ + tmp = shr( sub( 1, tmp ), 1 ); /* pre-shift to apply before autocorrelation */ + shifts[iSubdivisions] = s_min( tmp, headroom ); move16(); /* calc normalization factor */ @@ -552,88 +549,89 @@ Word16 ITF_Detect_ivas_fx( facs_e[iSubdivisions] = 0; move16(); - if (tmp32 > 0) + if ( tmp32 > 0 ) { facs[iSubdivisions] = 0x7FFF; move16(); /* normalization not needed for one subdivision */ } test(); - IF ((tmp32 > 0) && (GT_16(nSubdivisions, 1))) + IF( ( tmp32 > 0 ) && ( GT_16( nSubdivisions, 1 ) ) ) { move16(); - facs_e[iSubdivisions] = shl(sub(tmp, shifts[iSubdivisions]), 1); + facs_e[iSubdivisions] = shl( sub( tmp, shifts[iSubdivisions] ), 1 ); - tmp = sub(1, shl(tmp, 1)); /* exponent of autocorrelation */ - L_tmp = L_shl(L_tmp, sub(shift, tmp)); /* shift L_tmp to that exponent */ + tmp = sub( 1, shl( tmp, 1 ) ); /* exponent of autocorrelation */ + L_tmp = L_shl( L_tmp, sub( shift, tmp ) ); /* shift L_tmp to that exponent */ /* calc factor (with 2 bits headroom for sum of 3 subdivisions) */ - facs[iSubdivisions] = div_s(0x2000, round_fx_o(L_tmp, &Overflow)); /* L_tmp is >= 0x2000000 */ move16(); + facs[iSubdivisions] = div_s( 0x2000, round_fx_o( L_tmp, &Overflow ) ); /* L_tmp is >= 0x2000000 */ + move16(); } - } /* Calculate normalized autocorrelation for spectrum subdivision and get filter parameters based on it */ - set32_fx(rxx, 0, ITF_MAX_FILTER_ORDER+1); + set32_fx( rxx, 0, ITF_MAX_FILTER_ORDER + 1 ); - spectrumLength = sub(stopLine, startLine); + spectrumLength = sub( stopLine, startLine ); - FOR (iSubdivisions = 0; iSubdivisions < nSubdivisions; iSubdivisions++) + FOR( iSubdivisions = 0; iSubdivisions < nSubdivisions; iSubdivisions++ ) { - IF ( facs[iSubdivisions] == 0 ) + IF( facs[iSubdivisions] == 0 ) { BREAK; } - assert((nSubdivisions == 1) || (nSubdivisions == 3)); + assert( ( nSubdivisions == 1 ) || ( nSubdivisions == 3 ) ); - iStartLine = imult1616(spectrumLength, iSubdivisions); - iEndLine = add(iStartLine, spectrumLength); + iStartLine = imult1616( spectrumLength, iSubdivisions ); + iEndLine = add( iStartLine, spectrumLength ); - if (EQ_16(nSubdivisions, 3))iStartLine=mult(iStartLine,0x2AAB); - iStartLine = add(iStartLine, startLine); + if ( EQ_16( nSubdivisions, 3 ) ) + iStartLine = mult( iStartLine, 0x2AAB ); + iStartLine = add( iStartLine, startLine ); - if (EQ_16(nSubdivisions, 3))iEndLine=mult(iEndLine,0x2AAB); - iEndLine = add(iEndLine, startLine); + if ( EQ_16( nSubdivisions, 3 ) ) + iEndLine = mult( iEndLine, 0x2AAB ); + iEndLine = add( iEndLine, startLine ); move16(); shift = shifts[iSubdivisions]; - n = sub(iEndLine, iStartLine); - assert(n < (Word16)(sizeof(tmpbuf)/sizeof(Word16))); - FOR (i = 0; i < n; i++) + n = sub( iEndLine, iStartLine ); + assert( n < (Word16) ( sizeof( tmpbuf ) / sizeof( Word16 ) ) ); + FOR( i = 0; i < n; i++ ) { - tmpbuf[i] = round_fx_o(L_shl(pSpectrum[iStartLine+i-IGF_START_MN], shift), &Overflow); + tmpbuf[i] = round_fx_o( L_shl( pSpectrum[iStartLine + i - IGF_START_MN], shift ), &Overflow ); } - FOR (lag = 0; lag <= maxOrder; lag++) + FOR( lag = 0; lag <= maxOrder; lag++ ) { - n = sub(sub(iEndLine,lag), iStartLine); + n = sub( sub( iEndLine, lag ), iStartLine ); { Word64 tmp64 = 0; - FOR (i = 0; i < n; i++) + FOR( i = 0; i < n; i++ ) { - tmp64 = W_mac0_16_16(tmp64, tmpbuf[i], tmpbuf[i+lag]); + tmp64 = W_mac0_16_16( tmp64, tmpbuf[i], tmpbuf[i + lag] ); } - L_tmp = W_sat_l(tmp64); + L_tmp = W_sat_l( tmp64 ); } - L_tmp = Mpy_32_16_1(L_tmp, facs[iSubdivisions]); - L_tmp = L_shl(L_tmp, facs_e[iSubdivisions]); + L_tmp = Mpy_32_16_1( L_tmp, facs[iSubdivisions] ); + L_tmp = L_shl( L_tmp, facs_e[iSubdivisions] ); - rxx[lag] = L_add(rxx[lag], L_tmp); + rxx[lag] = L_add( rxx[lag], L_tmp ); move32(); } - } - IF ( EQ_16(iSubdivisions,nSubdivisions)) /* meaning there is no subdivision with low energy */ + IF( EQ_16( iSubdivisions, nSubdivisions ) ) /* meaning there is no subdivision with low energy */ { /* Limit the maximum order to spectrum length/4 */ - ITF_GetFilterParameters_fx(rxx, s_min (maxOrder, shr(spectrumLength,2)), A, Q_A, predictionGain); + ITF_GetFilterParameters_fx( rxx, s_min( maxOrder, shr( spectrumLength, 2 ) ), A, Q_A, predictionGain ); *curr_order = maxOrder; } @@ -644,25 +642,25 @@ Word16 ITF_Detect_ivas_fx( /** Get number of bits from a Huffman table. - * The table must be sorted by values. - */ -static Word16 GetBitsFromTable(const Word16 value, const Coding codes[], const Word16 nSize) + * The table must be sorted by values. + */ +static Word16 GetBitsFromTable( const Word16 value, const Coding codes[], const Word16 nSize ) { - (void)nSize; - assert((value >= 0) && (value < nSize) && (nSize >= 0) && (nSize <= 256)); + (void) nSize; + assert( ( value >= 0 ) && ( value < nSize ) && ( nSize >= 0 ) && ( nSize <= 256 ) ); move16(); cast16(); - return (Word16)codes[value].nBits; + return (Word16) codes[value].nBits; } /** Get the code for a value from a Huffman table. - * The table must be sorted by values. - */ -static Word16 EncodeUsingTable(const Word16 value, const Coding codes[], const Word16 nSize) + * The table must be sorted by values. + */ +static Word16 EncodeUsingTable( const Word16 value, const Coding codes[], const Word16 nSize ) { - (void)nSize; - assert((value >= 0) && (value < nSize) && (nSize >= 0) && (nSize <= 256)); + (void) nSize; + assert( ( value >= 0 ) && ( value < nSize ) && ( nSize >= 0 ) && ( nSize <= 256 ) ); move16(); return codes[value].code; @@ -670,24 +668,24 @@ static Word16 EncodeUsingTable(const Word16 value, const Coding codes[], const W /** Decode a value from a bitstream using a Huffman table. */ -static Word16 DecodeUsingTable(Decoder_State *st, Word16 * pValue, const Coding codes[], const Word16 nSize) +static Word16 DecodeUsingTable( Decoder_State *st, Word16 *pValue, const Coding codes[], const Word16 nSize ) { Word16 code = 0; Word16 nBits = 0; Word16 valueIndex; - assert((nSize >= 0) && (nSize <= 256)); + assert( ( nSize >= 0 ) && ( nSize <= 256 ) ); move16(); valueIndex = nSize; - WHILE (valueIndex == nSize) + WHILE( valueIndex == nSize ) { - code = add(shl(code,1), get_next_indice(st, 1)); - nBits = add(nBits,1); - if (nBits > nSize || nBits > 16) + code = add( shl( code, 1 ), get_next_indice( st, 1 ) ); + nBits = add( nBits, 1 ); + if ( nBits > nSize || nBits > 16 ) { st->BER_detect = 1; *pValue = 0; @@ -695,19 +693,18 @@ static Word16 DecodeUsingTable(Decoder_State *st, Word16 * pValue, const Coding return -1; } - FOR (valueIndex = 0; valueIndex < nSize; valueIndex++) + FOR( valueIndex = 0; valueIndex < nSize; valueIndex++ ) { - IF ( s_and((Word16)EQ_16(codes[valueIndex].nBits,nBits),(Word16)EQ_16(codes[valueIndex].code,code))) + IF( s_and( (Word16) EQ_16( codes[valueIndex].nBits, nBits ), (Word16) EQ_16( codes[valueIndex].code, code ) ) ) { BREAK; } } - } - if (valueIndex < nSize) + if ( valueIndex < nSize ) { - *pValue = (Word16)codes[valueIndex].value; + *pValue = (Word16) codes[valueIndex].value; } else { @@ -723,190 +720,189 @@ static Word16 DecodeUsingTable(Decoder_State *st, Word16 * pValue, const Coding /* TNS filter coefficients */ -void const * GetTnsFilterCoeff(void const * p, const Word16 index, Word16 * pValue) +void const *GetTnsFilterCoeff( void const *p, const Word16 index, Word16 *pValue ) { - *pValue = ((Word16 const *)p)[index] + INDEX_SHIFT; + *pValue = ( (Word16 const *) p )[index] + INDEX_SHIFT; return NULL; } -void * SetTnsFilterCoeff(void * p, const Word16 index, const Word16 value) +void *SetTnsFilterCoeff( void *p, const Word16 index, const Word16 value ) { - ((Word16 *)p)[index] = sub(value, INDEX_SHIFT); + ( (Word16 *) p )[index] = sub( value, INDEX_SHIFT ); return NULL; } -Word16 GetSWBTCX20TnsFilterCoeffBits(const Word16 value, const Word16 index) +Word16 GetSWBTCX20TnsFilterCoeffBits( const Word16 value, const Word16 index ) { - assert((index >= 0) && (index < nTnsCoeffTables)); + assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); - return GetBitsFromTable(value, codesTnsCoeffSWBTCX20[index], nTnsCoeffCodes); + return GetBitsFromTable( value, codesTnsCoeffSWBTCX20[index], nTnsCoeffCodes ); } -Word16 EncodeSWBTCX20TnsFilterCoeff(const Word16 value, const Word16 index) +Word16 EncodeSWBTCX20TnsFilterCoeff( const Word16 value, const Word16 index ) { - assert((index >= 0) && (index < nTnsCoeffTables)); + assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); - return EncodeUsingTable(value, codesTnsCoeffSWBTCX20[index], nTnsCoeffCodes); + return EncodeUsingTable( value, codesTnsCoeffSWBTCX20[index], nTnsCoeffCodes ); } -Word16 DecodeSWBTCX20TnsFilterCoeff(Decoder_State *st, const Word16 index, Word16 * pValue) +Word16 DecodeSWBTCX20TnsFilterCoeff( Decoder_State *st, const Word16 index, Word16 *pValue ) { - assert((index >= 0) && (index < nTnsCoeffTables)); + assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); - return DecodeUsingTable(st, pValue, codesTnsCoeffSWBTCX20[index], nTnsCoeffCodes); + return DecodeUsingTable( st, pValue, codesTnsCoeffSWBTCX20[index], nTnsCoeffCodes ); } -Word16 GetSWBTCX10TnsFilterCoeffBits(const Word16 value, const Word16 index) +Word16 GetSWBTCX10TnsFilterCoeffBits( const Word16 value, const Word16 index ) { - assert((index >= 0) && (index < nTnsCoeffTables)); + assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); - return GetBitsFromTable(value, codesTnsCoeffSWBTCX10[index], nTnsCoeffCodes); + return GetBitsFromTable( value, codesTnsCoeffSWBTCX10[index], nTnsCoeffCodes ); } -Word16 EncodeSWBTCX10TnsFilterCoeff(const Word16 value, const Word16 index) +Word16 EncodeSWBTCX10TnsFilterCoeff( const Word16 value, const Word16 index ) { - assert((index >= 0) && (index < nTnsCoeffTables)); + assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); - return EncodeUsingTable(value, codesTnsCoeffSWBTCX10[index], nTnsCoeffCodes); + return EncodeUsingTable( value, codesTnsCoeffSWBTCX10[index], nTnsCoeffCodes ); } -Word16 DecodeSWBTCX10TnsFilterCoeff(Decoder_State *st, const Word16 index, Word16 * pValue) +Word16 DecodeSWBTCX10TnsFilterCoeff( Decoder_State *st, const Word16 index, Word16 *pValue ) { - assert((index >= 0) && (index < nTnsCoeffTables)); + assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); - return DecodeUsingTable(st, pValue, codesTnsCoeffSWBTCX10[index], nTnsCoeffCodes); + return DecodeUsingTable( st, pValue, codesTnsCoeffSWBTCX10[index], nTnsCoeffCodes ); } -Word16 GetWBTCX20TnsFilterCoeffBits(const Word16 value, const Word16 index) +Word16 GetWBTCX20TnsFilterCoeffBits( const Word16 value, const Word16 index ) { - assert((index >= 0) && (index < nTnsCoeffTables)); + assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); - return GetBitsFromTable(value, codesTnsCoeffWBTCX20[index], nTnsCoeffCodes); + return GetBitsFromTable( value, codesTnsCoeffWBTCX20[index], nTnsCoeffCodes ); } -Word16 EncodeWBTCX20TnsFilterCoeff(const Word16 value, const Word16 index) +Word16 EncodeWBTCX20TnsFilterCoeff( const Word16 value, const Word16 index ) { - assert((index >= 0) && (index < nTnsCoeffTables)); + assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); - return EncodeUsingTable(value, codesTnsCoeffWBTCX20[index], nTnsCoeffCodes); + return EncodeUsingTable( value, codesTnsCoeffWBTCX20[index], nTnsCoeffCodes ); } -Word16 DecodeWBTCX20TnsFilterCoeff(Decoder_State *st, const Word16 index, Word16 * pValue) +Word16 DecodeWBTCX20TnsFilterCoeff( Decoder_State *st, const Word16 index, Word16 *pValue ) { - assert((index >= 0) && (index < nTnsCoeffTables)); + assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); - return DecodeUsingTable(st, pValue, codesTnsCoeffWBTCX20[index], nTnsCoeffCodes); + return DecodeUsingTable( st, pValue, codesTnsCoeffWBTCX20[index], nTnsCoeffCodes ); } - /* TNS filter order */ -void const * GetTnsFilterOrder(void const * p, const Word16 index, Word16 * pValue) +void const *GetTnsFilterOrder( void const *p, const Word16 index, Word16 *pValue ) { move16(); - *pValue = ((STnsFilter const *)p)[index].order; + *pValue = ( (STnsFilter const *) p )[index].order; move16(); - return ((STnsFilter const *)p)[index].coefIndex; + return ( (STnsFilter const *) p )[index].coefIndex; } -void * SetTnsFilterOrder(void * p, const Word16 index, const Word16 value) +void *SetTnsFilterOrder( void *p, const Word16 index, const Word16 value ) { move16(); - ((STnsFilter *)p)[index].order = value; + ( (STnsFilter *) p )[index].order = value; move16(); - return ((STnsFilter *)p)[index].coefIndex; + return ( (STnsFilter *) p )[index].coefIndex; } -Word16 GetTnsFilterOrderBitsSWBTCX20(const Word16 value, const Word16 index) +Word16 GetTnsFilterOrderBitsSWBTCX20( const Word16 value, const Word16 index ) { - (void)index; + (void) index; - return GetBitsFromTable(value-1, codesTnsOrderTCX20, nTnsOrderCodes); + return GetBitsFromTable( value - 1, codesTnsOrderTCX20, nTnsOrderCodes ); } -Word16 EncodeTnsFilterOrderSWBTCX20(const Word16 value, const Word16 index) +Word16 EncodeTnsFilterOrderSWBTCX20( const Word16 value, const Word16 index ) { - (void)index; + (void) index; - return EncodeUsingTable(value-1, codesTnsOrderTCX20, nTnsOrderCodes); + return EncodeUsingTable( value - 1, codesTnsOrderTCX20, nTnsOrderCodes ); } -Word16 DecodeTnsFilterOrderSWBTCX20(Decoder_State *st, const Word16 index, Word16 * pValue) +Word16 DecodeTnsFilterOrderSWBTCX20( Decoder_State *st, const Word16 index, Word16 *pValue ) { - (void)index; + (void) index; - return DecodeUsingTable(st, pValue, codesTnsOrderTCX20, nTnsOrderCodes); + return DecodeUsingTable( st, pValue, codesTnsOrderTCX20, nTnsOrderCodes ); } -Word16 GetTnsFilterOrderBitsSWBTCX10(const Word16 value, const Word16 index) +Word16 GetTnsFilterOrderBitsSWBTCX10( const Word16 value, const Word16 index ) { - (void)index; + (void) index; - return GetBitsFromTable(value-1, codesTnsOrderTCX10, nTnsOrderCodes); + return GetBitsFromTable( value - 1, codesTnsOrderTCX10, nTnsOrderCodes ); } -Word16 EncodeTnsFilterOrderSWBTCX10(const Word16 value, const Word16 index) +Word16 EncodeTnsFilterOrderSWBTCX10( const Word16 value, const Word16 index ) { - (void)index; + (void) index; - return EncodeUsingTable(value-1, codesTnsOrderTCX10, nTnsOrderCodes); + return EncodeUsingTable( value - 1, codesTnsOrderTCX10, nTnsOrderCodes ); } -Word16 DecodeTnsFilterOrderSWBTCX10(Decoder_State *st, const Word16 index, Word16 * pValue) +Word16 DecodeTnsFilterOrderSWBTCX10( Decoder_State *st, const Word16 index, Word16 *pValue ) { - (void)index; + (void) index; - return DecodeUsingTable(st, pValue, codesTnsOrderTCX10, nTnsOrderCodes); + return DecodeUsingTable( st, pValue, codesTnsOrderTCX10, nTnsOrderCodes ); } -Word16 GetTnsFilterOrderBits(const Word16 value, const Word16 index) +Word16 GetTnsFilterOrderBits( const Word16 value, const Word16 index ) { - (void)index; + (void) index; - return GetBitsFromTable(value-1, codesTnsOrder, nTnsOrderCodes); + return GetBitsFromTable( value - 1, codesTnsOrder, nTnsOrderCodes ); } -Word16 EncodeTnsFilterOrder(const Word16 value, const Word16 index) +Word16 EncodeTnsFilterOrder( const Word16 value, const Word16 index ) { - (void)index; + (void) index; - return EncodeUsingTable(value-1, codesTnsOrder, nTnsOrderCodes); + return EncodeUsingTable( value - 1, codesTnsOrder, nTnsOrderCodes ); } -Word16 DecodeTnsFilterOrder(Decoder_State *st, const Word16 index, Word16 * pValue) +Word16 DecodeTnsFilterOrder( Decoder_State *st, const Word16 index, Word16 *pValue ) { - (void)index; + (void) index; - return DecodeUsingTable(st, pValue, codesTnsOrder, nTnsOrderCodes); + return DecodeUsingTable( st, pValue, codesTnsOrder, nTnsOrderCodes ); } /* Number of TNS filters */ -void const * GetNumOfTnsFilters(void const * p, const Word16 index, Word16 * pValue) +void const *GetNumOfTnsFilters( void const *p, const Word16 index, Word16 *pValue ) { - *pValue = ((STnsData const *)p)[index].nFilters; + *pValue = ( (STnsData const *) p )[index].nFilters; - return ((STnsData const *)p)[index].filter; + return ( (STnsData const *) p )[index].filter; } -void * SetNumOfTnsFilters(void * p, const Word16 index, Word16 value) +void *SetNumOfTnsFilters( void *p, const Word16 index, Word16 value ) { - ((STnsData *)p)[index].nFilters = value; + ( (STnsData *) p )[index].nFilters = value; - return ((STnsData *)p)[index].filter; + return ( (STnsData *) p )[index].filter; } /* TNS enabled/disabled flag */ -void const * GetTnsEnabled(void const * p, const Word16 index, Word16 * pValue) +void const *GetTnsEnabled( void const *p, const Word16 index, Word16 *pValue ) { move16(); *pValue = 0; - if (((STnsData const *)p)[index].nFilters != 0) + if ( ( (STnsData const *) p )[index].nFilters != 0 ) { move16(); *pValue = 1; @@ -914,49 +910,49 @@ void const * GetTnsEnabled(void const * p, const Word16 index, Word16 * pValue) return NULL; } -void * SetTnsEnabled(void * p, const Word16 index, const Word16 value) +void *SetTnsEnabled( void *p, const Word16 index, const Word16 value ) { - (void)p,(void)index,(void)value; + (void) p, (void) index, (void) value; return NULL; } #ifdef ADD_IVAS_TNS /* TNS on whitened spectra flag */ -void const* GetTnsOnWhite(void const* p, const int16_t index, int16_t* pValue) +void const *GetTnsOnWhite( void const *p, const int16_t index, int16_t *pValue ) { - *pValue = ((STnsData const*)p)[index].tnsOnWhitenedSpectra > 0 ? 1 : 0; + *pValue = ( (STnsData const *) p )[index].tnsOnWhitenedSpectra > 0 ? 1 : 0; return NULL; } -void* SetTnsOnWhite(void* p, const int16_t index, const int16_t value) +void *SetTnsOnWhite( void *p, const int16_t index, const int16_t value ) { - ((STnsData*)p)[index].tnsOnWhitenedSpectra = value; + ( (STnsData *) p )[index].tnsOnWhitenedSpectra = value; return NULL; } -void const* GetTnsEnabledSingleFilter(void const* p, const int16_t index, int16_t* pValue) +void const *GetTnsEnabledSingleFilter( void const *p, const int16_t index, int16_t *pValue ) { - *pValue = ((STnsData const*)p)[index].nFilters != 0 ? 1 : 0; - return ((STnsData const*)p)[index].filter; + *pValue = ( (STnsData const *) p )[index].nFilters != 0 ? 1 : 0; + return ( (STnsData const *) p )[index].filter; } #endif -void const * GetTnsEnabledSingleFilter(void const * p, const Word16 index, Word16 * pValue) +void const *GetTnsEnabledSingleFilter( void const *p, const Word16 index, Word16 *pValue ) { move16(); *pValue = 0; - if (((STnsData const *)p)[index].nFilters > 0) + if ( ( (STnsData const *) p )[index].nFilters > 0 ) { move16(); *pValue = 1; } - return ((STnsData const *)p)[index].filter; + return ( (STnsData const *) p )[index].filter; } -void * SetTnsEnabledSingleFilter(void * p, const Word16 index, const Word16 value) +void *SetTnsEnabledSingleFilter( void *p, const Word16 index, const Word16 value ) { - ((STnsData *)p)[index].nFilters = value; - return ((STnsData *)p)[index].filter; + ( (STnsData *) p )[index].nFilters = value; + return ( (STnsData *) p )[index].filter; } /*-------------------------------------------------------------------* @@ -964,16 +960,16 @@ void * SetTnsEnabledSingleFilter(void * p, const Word16 index, const Word16 valu * *-------------------------------------------------------------------*/ -void ResetTnsData(STnsData * pTnsData) +void ResetTnsData( STnsData *pTnsData ) { Word16 iFilter; pTnsData->nFilters = 0; pTnsData->tnsOnWhitenedSpectra = 0; - FOR (iFilter = 0; iFilter < (Word16) (sizeof(pTnsData->filter)/sizeof(pTnsData->filter[0])); iFilter++) + FOR( iFilter = 0; iFilter < (Word16) ( sizeof( pTnsData->filter ) / sizeof( pTnsData->filter[0] ) ); iFilter++ ) { - STnsFilter * const pTnsFilter = &pTnsData->filter[iFilter]; + STnsFilter *const pTnsFilter = &pTnsData->filter[iFilter]; pTnsFilter->spectrumLength = 0; pTnsFilter->predictionGain = ONE_IN_Q7; pTnsFilter->avgSqrCoef = 0; @@ -981,9 +977,8 @@ void ResetTnsData(STnsData * pTnsData) pTnsFilter->predictionGain_flt = 1.0f; pTnsFilter->avgSqrCoef_flt = 0; pTnsFilter->filterType = TNS_FILTER_OFF; - ClearTnsFilterCoefficients(pTnsFilter); + ClearTnsFilterCoefficients( pTnsFilter ); } - } /*-------------------------------------------------------------------* * ClearTnsFilterCoefficients() @@ -991,14 +986,19 @@ void ResetTnsData(STnsData * pTnsData) *-------------------------------------------------------------------*/ void ClearTnsFilterCoefficients( - STnsFilter * pTnsFilter -) + STnsFilter *pTnsFilter ) { move16(); pTnsFilter->order = 0; - assert(TNS_MAX_FILTER_ORDER == 8); - move16();move16();move16();move16(); - move16();move16();move16();move16(); + assert( TNS_MAX_FILTER_ORDER == 8 ); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); pTnsFilter->coefIndex[0] = 0; pTnsFilter->coefIndex[1] = 0; pTnsFilter->coefIndex[2] = 0; @@ -1015,18 +1015,18 @@ void ClearTnsFilterCoefficients( * @param parCoeff output reflection coefficients. * @param order number of coefficients/values. */ -static void Index2Parcor(const Word16 index[], Word16 parCoeff[], Word16 order) +static void Index2Parcor( const Word16 index[], Word16 parCoeff[], Word16 order ) { - const Word16 * values; + const Word16 *values; Word16 i; move16(); values = tnsCoeff4; - FOR (i = 0; i < order; i++) + FOR( i = 0; i < order; i++ ) { move16(); - parCoeff[i] = values[add(index[i], INDEX_SHIFT)]; + parCoeff[i] = values[add( index[i], INDEX_SHIFT )]; } return; } @@ -1034,9 +1034,9 @@ static void Index2Parcor(const Word16 index[], Word16 parCoeff[], Word16 order) /* Linear prediction analysis filter. */ static Word32 FIRLattice( - const Word16 order, - const Word16 *parCoeff /*Q15*/, - Word32 *state, + const Word16 order, + const Word16 *parCoeff /*Q15*/, + Word32 *state, Word32 x /* Q0 */ ) { @@ -1046,10 +1046,10 @@ static Word32 FIRLattice( tmpSave = x; move32(); - FOR (i = 0; i < order-1; i++) + FOR( i = 0; i < order - 1; i++ ) { - tmp = L_add(state[i], Mpy_32_16_1(x, parCoeff[i])); - x = L_add(x, Mpy_32_16_1(state[i], parCoeff[i])); /* exponent: 31+0 */ + tmp = L_add( state[i], Mpy_32_16_1( x, parCoeff[i] ) ); + x = L_add( x, Mpy_32_16_1( state[i], parCoeff[i] ) ); /* exponent: 31+0 */ state[i] = tmpSave; move32(); tmpSave = tmp; @@ -1057,25 +1057,25 @@ static Word32 FIRLattice( } /* last stage: only need half operations */ - x = L_add(x, Mpy_32_16_1(state[order-1], parCoeff[order-1])); - state[order-1] = tmpSave; + x = L_add( x, Mpy_32_16_1( state[order - 1], parCoeff[order - 1] ) ); + state[order - 1] = tmpSave; move32(); return x; } -static Word32 IIRLattice(Word16 order, const Word16 *parCoeff, Word32 *state, Word32 x) +static Word32 IIRLattice( Word16 order, const Word16 *parCoeff, Word32 *state, Word32 x ) { Word16 i; /* first stage: no need to calculate state[order-1] */ - x = L_sub(x, Mpy_32_16_1(state[order-1], parCoeff[order-1])); + x = L_sub( x, Mpy_32_16_1( state[order - 1], parCoeff[order - 1] ) ); - FOR (i = order-2; i >= 0; i--) + FOR( i = order - 2; i >= 0; i-- ) { - x = L_sub(x, Mpy_32_16_1(state[i], parCoeff[i])); - state[i+1] = L_add(state[i], Mpy_32_16_1(x, parCoeff[i])); + x = L_sub( x, Mpy_32_16_1( state[i], parCoeff[i] ) ); + state[i + 1] = L_add( state[i], Mpy_32_16_1( x, parCoeff[i] ) ); move32(); } @@ -1094,38 +1094,37 @@ static Word32 IIRLattice(Word16 order, const Word16 *parCoeff, Word32 *state, Wo Inplace operation is supported, so it can be equal to spectrum. */ static void TnsFilter( - const Word32 spectrum[], - const Word16 numOfLines, - const Word16 parCoeff[], - const Word16 order, - TLinearPredictionFilter filter, - Word32 * state, - Word32 output[] -) + const Word32 spectrum[], + const Word16 numOfLines, + const Word16 parCoeff[], + const Word16 order, + TLinearPredictionFilter filter, + Word32 *state, + Word32 output[] ) { Word16 j; - assert((order >= 0) && (order <= TNS_MAX_FILTER_ORDER)); - assert((numOfLines > 0) || ((numOfLines == 0) && (order == 0))); + assert( ( order >= 0 ) && ( order <= TNS_MAX_FILTER_ORDER ) ); + assert( ( numOfLines > 0 ) || ( ( numOfLines == 0 ) && ( order == 0 ) ) ); - IF (order == 0) + IF( order == 0 ) { test(); - IF ( s_and((spectrum != output), numOfLines > 0) ) + IF( s_and( ( spectrum != output ), numOfLines > 0 ) ) { - Copy32(spectrum, output, numOfLines); + Copy32( spectrum, output, numOfLines ); } } ELSE { { - FOR (j = 0; j < numOfLines; j++) + FOR( j = 0; j < numOfLines; j++ ) { move32(); - output[j] = filter(order, parCoeff, state, spectrum[j]); + output[j] = filter( order, parCoeff, state, spectrum[j] ); } } } @@ -1138,40 +1137,39 @@ static void ITF_TnsFilter_fx( const Word16 A[], /* ifdef FIX_ITF_OVERFLOW Q_A else Q14 */ const Word16 Q_A, const Word16 order, - Word32 output[] -) + Word32 output[] ) { Word16 i, j; Word32 buf[ITF_MAX_FILTER_ORDER + N_MAX]; - Word32* p; + Word32 *p; Word16 shift; - assert((order >= 0) && (order <= ITF_MAX_FILTER_ORDER)); - assert((numOfLines > 0) || ((numOfLines == 0) && (order == 0))); + assert( ( order >= 0 ) && ( order <= ITF_MAX_FILTER_ORDER ) ); + assert( ( numOfLines > 0 ) || ( ( numOfLines == 0 ) && ( order == 0 ) ) ); - IF (order == 0) + IF( order == 0 ) { test(); - IF ( s_and((spectrum != output), numOfLines > 0) ) + IF( s_and( ( spectrum != output ), numOfLines > 0 ) ) { - Copy32(spectrum, output, numOfLines); + Copy32( spectrum, output, numOfLines ); } } ELSE { - shift = sub(15, Q_A); + shift = sub( 15, Q_A ); p = buf + ITF_MAX_FILTER_ORDER; - set32_fx(buf, 0, ITF_MAX_FILTER_ORDER); - Copy32(spectrum, p, numOfLines); - FOR (j = 0; j < numOfLines; j++) + set32_fx( buf, 0, ITF_MAX_FILTER_ORDER ); + Copy32( spectrum, p, numOfLines ); + FOR( j = 0; j < numOfLines; j++ ) { Word32 L_tmp; - L_tmp = L_add(p[0], 0); - FOR (i = 1; i < order; i++) + L_tmp = L_add( p[0], 0 ); + FOR( i = 1; i < order; i++ ) { - L_tmp = L_add_sat(L_tmp, L_shl(Mpy_32_16_1(p[-i], A[i]), shift)); + L_tmp = L_add_sat( L_tmp, L_shl( Mpy_32_16_1( p[-i], A[i] ), shift ) ); } output[j] = L_tmp; move32(); @@ -1184,19 +1182,18 @@ static void ITF_TnsFilter_fx( static void ITF_GetFilterParameters_fx( Word32 rxx[], const Word16 maxOrder, - Word16* A, /* ifdef FIX_ITF_OVERFLOW Q_A else Q14 */ - Word16* Q_A, - Word16* predictionGain -) + Word16 *A, /* ifdef FIX_ITF_OVERFLOW Q_A else Q14 */ + Word16 *Q_A, + Word16 *predictionGain ) { Word16 i, j, i_2, tmp; Word16 parCoeff[ITF_MAX_FILTER_ORDER]; - Word32 epsP[ITF_MAX_FILTER_ORDER+1], L_tmp; + Word32 epsP[ITF_MAX_FILTER_ORDER + 1], L_tmp; /* compute filter in ParCor form with LeRoux-Gueguen algorithm */ - L_tmp = E_LPC_schur(rxx, parCoeff, epsP, maxOrder); + L_tmp = E_LPC_schur( rxx, parCoeff, epsP, maxOrder ); BASOP_SATURATE_WARNING_OFF_EVS /* Allow saturation, this value is compared against a threshold. */ - *predictionGain = divide3232(L_shr(epsP[0], PRED_GAIN_E), L_tmp); + *predictionGain = divide3232( L_shr( epsP[0], PRED_GAIN_E ), L_tmp ); BASOP_SATURATE_WARNING_ON_EVS { @@ -1204,44 +1201,46 @@ static void ITF_GetFilterParameters_fx( Word16 tmp1_l, tmp1_h, tmp2_l, tmp2_h; /* Convert ParCor / reflection coefficients to LPC */ - A32[0] = 134217728l/*1.0 Q27*/; - move16(); /* Q11+16 */ - A32[1] = L_shr(L_deposit_h(parCoeff[0]), 4); /* Q11+16 */ + A32[0] = 134217728l /*1.0 Q27*/; + move16(); /* Q11+16 */ + A32[1] = L_shr( L_deposit_h( parCoeff[0] ), 4 ); /* Q11+16 */ - FOR (i=1; i Q14 */ - FOR (i=0; i Q14 */ + FOR( i = 0; i < maxOrder; i++ ) { - tmp = s_min(tmp, norm_l(A32[i])); + tmp = s_min( tmp, norm_l( A32[i] ) ); } - FOR (i=0; i= 0 ) && ( index < nTnsCoeffTables ) ); -// return GetBitsFromTable( value, codesTnsCoeffSWBTCX20[index], nTnsCoeffCodes ); -//} +// assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); +// return GetBitsFromTable( value, codesTnsCoeffSWBTCX20[index], nTnsCoeffCodes ); +// } -//int16_t EncodeSWBTCX20TnsFilterCoeff_flt( const int16_t value, const int16_t index ) +// int16_t EncodeSWBTCX20TnsFilterCoeff_flt( const int16_t value, const int16_t index ) //{ -// assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); -// return EncodeUsingTable( value, codesTnsCoeffSWBTCX20[index], nTnsCoeffCodes ); -//} +// assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); +// return EncodeUsingTable( value, codesTnsCoeffSWBTCX20[index], nTnsCoeffCodes ); +// } int16_t DecodeSWBTCX20TnsFilterCoeff_flt( Decoder_State *st, const int16_t index, int16_t *pValue ) { @@ -317,17 +317,17 @@ int16_t DecodeSWBTCX20TnsFilterCoeff_flt( Decoder_State *st, const int16_t index return DecodeUsingTable( st, pValue, codesTnsCoeffSWBTCX20[index], nTnsCoeffCodes ); } -//int16_t GetSWBTCX10TnsFilterCoeffBits_flt( const int16_t value, const int16_t index ) +// int16_t GetSWBTCX10TnsFilterCoeffBits_flt( const int16_t value, const int16_t index ) //{ -// assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); -// return GetBitsFromTable( value, codesTnsCoeffSWBTCX10[index], nTnsCoeffCodes ); -//} +// assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); +// return GetBitsFromTable( value, codesTnsCoeffSWBTCX10[index], nTnsCoeffCodes ); +// } -//int16_t EncodeSWBTCX10TnsFilterCoeff_flt( const int16_t value, const int16_t index ) +// int16_t EncodeSWBTCX10TnsFilterCoeff_flt( const int16_t value, const int16_t index ) //{ -// assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); -// return EncodeUsingTable( value, codesTnsCoeffSWBTCX10[index], nTnsCoeffCodes ); -//} +// assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); +// return EncodeUsingTable( value, codesTnsCoeffSWBTCX10[index], nTnsCoeffCodes ); +// } int16_t DecodeSWBTCX10TnsFilterCoeff_flt( Decoder_State *st, const int16_t index, int16_t *pValue ) { @@ -335,17 +335,17 @@ int16_t DecodeSWBTCX10TnsFilterCoeff_flt( Decoder_State *st, const int16_t index return DecodeUsingTable( st, pValue, codesTnsCoeffSWBTCX10[index], nTnsCoeffCodes ); } -//int16_t GetWBTCX20TnsFilterCoeffBits_flt( const int16_t value, const int16_t index ) +// int16_t GetWBTCX20TnsFilterCoeffBits_flt( const int16_t value, const int16_t index ) //{ -// assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); -// return GetBitsFromTable( value, codesTnsCoeffWBTCX20[index], nTnsCoeffCodes ); -//} +// assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); +// return GetBitsFromTable( value, codesTnsCoeffWBTCX20[index], nTnsCoeffCodes ); +// } -//int16_t EncodeWBTCX20TnsFilterCoeff_flt( const int16_t value, const int16_t index ) +// int16_t EncodeWBTCX20TnsFilterCoeff_flt( const int16_t value, const int16_t index ) //{ -// assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); -// return EncodeUsingTable( value, codesTnsCoeffWBTCX20[index], nTnsCoeffCodes ); -//} +// assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); +// return EncodeUsingTable( value, codesTnsCoeffWBTCX20[index], nTnsCoeffCodes ); +// } int16_t DecodeWBTCX20TnsFilterCoeff_flt( Decoder_State *st, const int16_t index, int16_t *pValue ) { @@ -356,29 +356,29 @@ int16_t DecodeWBTCX20TnsFilterCoeff_flt( Decoder_State *st, const int16_t index, /* TNS filter order */ -//void const *GetTnsFilterOrder_flt( void const *p, const int16_t index, int16_t *pValue ) +// void const *GetTnsFilterOrder_flt( void const *p, const int16_t index, int16_t *pValue ) //{ -// *pValue = ( (STnsFilter const *) p )[index].order; -// return ( (STnsFilter const *) p )[index].coefIndex; -//} +// *pValue = ( (STnsFilter const *) p )[index].order; +// return ( (STnsFilter const *) p )[index].coefIndex; +// } -//void *SetTnsFilterOrder_flt( void *p, const int16_t index, const int16_t value ) +// void *SetTnsFilterOrder_flt( void *p, const int16_t index, const int16_t value ) //{ -// ( (STnsFilter *) p )[index].order = value; -// return ( (STnsFilter *) p )[index].coefIndex; -//} +// ( (STnsFilter *) p )[index].order = value; +// return ( (STnsFilter *) p )[index].coefIndex; +// } -//int16_t GetTnsFilterOrderBitsSWBTCX20_flt( const int16_t value, const int16_t index ) +// int16_t GetTnsFilterOrderBitsSWBTCX20_flt( const int16_t value, const int16_t index ) //{ -// (void) index; -// return GetBitsFromTable( value - 1, codesTnsOrderTCX20, nTnsOrderCodes ); -//} +// (void) index; +// return GetBitsFromTable( value - 1, codesTnsOrderTCX20, nTnsOrderCodes ); +// } -//int16_t EncodeTnsFilterOrderSWBTCX20_flt( const int16_t value, const int16_t index ) +// int16_t EncodeTnsFilterOrderSWBTCX20_flt( const int16_t value, const int16_t index ) //{ -// (void) index; -// return EncodeUsingTable( value - 1, codesTnsOrderTCX20, nTnsOrderCodes ); -//} +// (void) index; +// return EncodeUsingTable( value - 1, codesTnsOrderTCX20, nTnsOrderCodes ); +// } int16_t DecodeTnsFilterOrderSWBTCX20_flt( Decoder_State *st, const int16_t index, int16_t *pValue ) { @@ -404,17 +404,17 @@ int16_t DecodeTnsFilterOrderSWBTCX10_flt( Decoder_State *st, const int16_t index return DecodeUsingTable( st, pValue, codesTnsOrderTCX10, nTnsOrderCodes ); } -//int16_t GetTnsFilterOrderBits_flt( const int16_t value, const int16_t index ) +// int16_t GetTnsFilterOrderBits_flt( const int16_t value, const int16_t index ) //{ -// (void) index; -// return GetBitsFromTable( value - 1, codesTnsOrder, nTnsOrderCodes ); -//} +// (void) index; +// return GetBitsFromTable( value - 1, codesTnsOrder, nTnsOrderCodes ); +// } -//int16_t EncodeTnsFilterOrder_flt( const int16_t value, const int16_t index ) +// int16_t EncodeTnsFilterOrder_flt( const int16_t value, const int16_t index ) //{ -// (void) index; -// return EncodeUsingTable( value - 1, codesTnsOrder, nTnsOrderCodes ); -//} +// (void) index; +// return EncodeUsingTable( value - 1, codesTnsOrder, nTnsOrderCodes ); +// } int16_t DecodeTnsFilterOrder_flt( Decoder_State *st, const int16_t index, int16_t *pValue ) { @@ -438,17 +438,17 @@ void *SetNumOfTnsFilters_flt( void *p, const int16_t index, const int16_t value /* TNS enabled/disabled flag */ -//void const *GetTnsEnabled_flt( void const *p, const int16_t index, int16_t *pValue ) +// void const *GetTnsEnabled_flt( void const *p, const int16_t index, int16_t *pValue ) //{ -// *pValue = ( (STnsData const *) p )[index].nFilters != 0 ? 1 : 0; -// return NULL; -//} +// *pValue = ( (STnsData const *) p )[index].nFilters != 0 ? 1 : 0; +// return NULL; +// } -//void *SetTnsEnabled_flt( void *p, const int16_t index, const int16_t value ) +// void *SetTnsEnabled_flt( void *p, const int16_t index, const int16_t value ) //{ -// (void) p, (void) index, (void) value; -// return NULL; -//} +// (void) p, (void) index, (void) value; +// return NULL; +// } /* TNS on whitened spectra flag */ @@ -464,17 +464,17 @@ void *SetTnsOnWhite( void *p, const int16_t index, const int16_t value ) return NULL; } -//void const *GetTnsEnabledSingleFilter_flt( void const *p, const int16_t index, int16_t *pValue ) +// void const *GetTnsEnabledSingleFilter_flt( void const *p, const int16_t index, int16_t *pValue ) //{ -// *pValue = ( (STnsData const *) p )[index].nFilters != 0 ? 1 : 0; -// return ( (STnsData const *) p )[index].filter; -//} +// *pValue = ( (STnsData const *) p )[index].nFilters != 0 ? 1 : 0; +// return ( (STnsData const *) p )[index].filter; +// } -//void *SetTnsEnabledSingleFilter_flt( void *p, const int16_t index, const int16_t value ) +// void *SetTnsEnabledSingleFilter_flt( void *p, const int16_t index, const int16_t value ) //{ -// ( (STnsData *) p )[index].nFilters = value; -// return ( (STnsData *) p )[index].filter; -//} +// ( (STnsData *) p )[index].nFilters = value; +// return ( (STnsData *) p )[index].filter; +// } /*-------------------------------------------------------------------* @@ -604,7 +604,7 @@ static void TnsFilter( const int16_t numOfLines, const float parCoeff[], const int16_t order, - TLinearPredictionFilter_flt filter, + TLinearPredictionFilter_flt filter, float *state, float output[] ) { diff --git a/lib_com/tools.c b/lib_com/tools.c index f91a2081a..4bb03acc0 100644 --- a/lib_com/tools.c +++ b/lib_com/tools.c @@ -182,7 +182,7 @@ float sum_f( #ifdef IVAS_FLOAT_FIXED Word32 sum2_f_16_fx( const Word16 *vec, /* i : input vector */ - const Word16 lvec /* i : length of input vector */ + const Word16 lvec /* i : length of input vector */ ) { int16_t i; @@ -218,18 +218,17 @@ float sum2_f( Word32 sum2_f_32_fx( const Word32 *vec, /* i : input vector */ const int16_t lvec, /* i : length of input vector */ - Word16 gb -) + Word16 gb ) { int16_t i; Word32 tmp; tmp = 0; Word32 var_a = 0; - for (i = 0; i < lvec; i++) + for ( i = 0; i < lvec; i++ ) { - var_a = Mpy_32_32(vec[i], vec[i]);//2x-31 - tmp = L_add(tmp, L_shr(var_a, gb));//2x-31-gb + var_a = Mpy_32_32( vec[i], vec[i] ); // 2x-31 + tmp = L_add( tmp, L_shr( var_a, gb ) ); // 2x-31-gb } return tmp; @@ -325,7 +324,7 @@ void set_zero_fx( { Word16 i; - FOR ( i = 0; i < lvec; i++ ) + FOR( i = 0; i < lvec; i++ ) { *vec++ = 0; } @@ -496,33 +495,33 @@ uint32_t mvr2s( uint32_t mvl2s_r( const Word32 x[], /* i : input vector */ const Word16 q_x, - Word16 y[], /* o : output vector */ - const Word16 n /* i : vector size */ + Word16 y[], /* o : output vector */ + const Word16 n /* i : vector size */ ) { Word16 i; Word32 temp; uint32_t noClipping = 0; - IF ( n <= 0 ) + IF( n <= 0 ) { /* cannot transfer vectors with size 0 */ return 0; } - IF ( (void *) y <= (const void *) x ) + IF( (void *) y <= (const void *) x ) { - FOR ( i = 0; i < n; i++ ) + FOR( i = 0; i < n; i++ ) { - temp = L_shr(x[i], q_x-1); - temp = L_shr(L_add(temp, 1), 1); + temp = L_shr( x[i], q_x - 1 ); + temp = L_shr( L_add( temp, 1 ), 1 ); - IF ( temp > MAX16B ) + IF( temp > MAX16B ) { temp = MAX16B; noClipping++; } - ELSE IF ( temp < MIN16B ) + ELSE IF( temp < MIN16B ) { temp = MIN16B; noClipping++; @@ -533,17 +532,17 @@ uint32_t mvl2s_r( } ELSE { - FOR ( i = n - 1; i >= 0; i-- ) + FOR( i = n - 1; i >= 0; i-- ) { - temp = L_shr(x[i], q_x-1); - temp = L_shr(L_add(temp, 1), 1); + temp = L_shr( x[i], q_x - 1 ); + temp = L_shr( L_add( temp, 1 ), 1 ); - IF ( temp > MAX16B ) + IF( temp > MAX16B ) { temp = MAX16B; noClipping++; } - ELSE IF ( temp < MIN16B ) + ELSE IF( temp < MIN16B ) { temp = MIN16B; noClipping++; @@ -739,7 +738,7 @@ Word16 maximum_l( ind = 0; tmp = vec[0]; - FOR ( i = 1; i < lvec; i++ ) + FOR( i = 1; i < lvec; i++ ) { IF( GT_32( vec[i], tmp ) ) { @@ -775,16 +774,16 @@ int16_t maximumAbs( ind = 0; tmp = (float) fabs( vec[0] ); - FOR ( j = 1; j < lvec; j++ ) + FOR( j = 1; j < lvec; j++ ) { - IF ( (float) fabs( vec[j] ) > tmp ) + IF( (float) fabs( vec[j] ) > tmp ) { ind = j; tmp = (float) fabs( vec[j] ); } } - IF ( max_val != NULL ) + IF( max_val != NULL ) { *max_val = tmp; } @@ -1029,11 +1028,11 @@ Word32 dotp_fixed( Word16 i; Word32 suma; - suma = Mpy_32_32(x[0], y[0]); + suma = Mpy_32_32( x[0], y[0] ); - FOR(i = 1; i < n; i++) + FOR( i = 1; i < n; i++ ) { - suma = L_add(suma, Mpy_32_32(x[i], y[i])); + suma = L_add( suma, Mpy_32_32( x[i], y[i] ) ); } return suma; @@ -1048,12 +1047,12 @@ Word32 dotp_fixed_guarded( { Word16 i; Word32 suma; - Word16 guarded_bits = find_guarded_bits_fx(n); - suma = L_shr(Mpy_32_32( x[0], y[0] ), guarded_bits); + Word16 guarded_bits = find_guarded_bits_fx( n ); + suma = L_shr( Mpy_32_32( x[0], y[0] ), guarded_bits ); - FOR ( i = 1; i < n; i++ ) + FOR( i = 1; i < n; i++ ) { - suma = L_add( suma, L_shr(Mpy_32_32( x[i], y[i] ), guarded_bits)); + suma = L_add( suma, L_shr( Mpy_32_32( x[i], y[i] ), guarded_bits ) ); } return suma; @@ -1072,17 +1071,17 @@ Word32 dotp_fixed_o( Word16 i; Word64 suma; /*resultant q= q(x)+q(y)-9-x such that q<=31*/ - suma = W_shr( W_mult_32_32( x[0], y[0] ), log_len); + suma = W_shr( W_mult_32_32( x[0], y[0] ), log_len ); FOR( i = 1; i < n; i++ ) { - suma = W_add( suma, W_shr( W_mult_32_32( x[i], y[i] ), log_len) ); + suma = W_add( suma, W_shr( W_mult_32_32( x[i], y[i] ), log_len ) ); } - *res_q = add(sub(*res_q , log_len) , 1); - WHILE( GT_64(suma , MAX_32) || GT_16(*res_q,31)) + *res_q = add( sub( *res_q, log_len ), 1 ); + WHILE( GT_64( suma, MAX_32 ) || GT_16( *res_q, 31 ) ) { suma = W_shr( suma, 1 ); - *res_q= sub(*res_q,1); + *res_q = sub( *res_q, 1 ); } return (Word32) suma; } @@ -1243,15 +1242,15 @@ void v_add_fixed_me( ) { Word16 i; - Word16 x1_shift = s_max(x1_e, x2_e) - x1_e; - Word16 x2_shift = s_max(x1_e, x2_e) - x2_e; + Word16 x1_shift = s_max( x1_e, x2_e ) - x1_e; + Word16 x2_shift = s_max( x1_e, x2_e ) - x2_e; FOR( i = 0; i < N; i++ ) { y[i] = L_add( L_shr( x1[i], hdrm + x1_shift ), L_shr( x2[i], hdrm + x2_shift ) ); } - *y_e = s_max(x1_e, x2_e) + hdrm; + *y_e = s_max( x1_e, x2_e ) + hdrm; return; } @@ -1321,7 +1320,7 @@ void v_sub_fixed( { Word16 i; - FOR ( i = 0; i < N; i++ ) + FOR( i = 0; i < N; i++ ) { y[i] = L_sub( L_shr( x1[i], hdrm ), L_shr( x2[i], hdrm ) ); } @@ -1339,14 +1338,14 @@ void v_mult_fixed( const Word32 x1[], /* i : Input vector 1 */ const Word32 x2[], /* i : Input vector 2 */ Word32 y[], /* o : Output vector that contains vector 1 .* vector 2 */ - const Word16 N /* i : Vector length */ + const Word16 N /* i : Vector length */ ) { Word16 i; - FOR(i = 0; i < N; i++) + FOR( i = 0; i < N; i++ ) { - y[i] = Mpy_32_32(x1[i], x2[i]); + y[i] = Mpy_32_32( x1[i], x2[i] ); } return; @@ -1408,7 +1407,7 @@ void v_multc_fixed( { Word16 i; - FOR ( i = 0; i < N; i++ ) + FOR( i = 0; i < N; i++ ) { y[i] = Mpy_32_32( c, x[i] ); } @@ -1425,7 +1424,7 @@ void v_multc_fixed_16( { Word16 i; - FOR ( i = 0; i < N; i++ ) + FOR( i = 0; i < N; i++ ) { y[i] = Mpy_32_16_1( x[i], c ); } @@ -1442,7 +1441,7 @@ void v_multc_fixed_16_16( { Word16 i; - FOR ( i = 0; i < N; i++ ) + FOR( i = 0; i < N; i++ ) { y[i] = mult_r( x[i], c ); } @@ -1809,10 +1808,10 @@ void sort_l( Word16 i, j; Word32 tempr; - FOR ( i = len - 2; i >= 0; i-- ) + FOR( i = len - 2; i >= 0; i-- ) { tempr = x[i]; - FOR ( j = i + 1; ( j < len ) && ( tempr > x[j] ); j++ ) + FOR( j = i + 1; ( j < len ) && ( tempr > x[j] ); j++ ) { x[j - 1] = x[j]; } @@ -2220,7 +2219,8 @@ Word32 anint_fixed( Word32 x, Word16 exp ) * * Ceil to the next multiple of (1 << exp). *-------------------------------------------------------------------*/ -Word32 ceil_fixed(Word32 x, Word16 exp) { +Word32 ceil_fixed( Word32 x, Word16 exp ) +{ Word32 step; step = x / L_shl( 1, exp ); IF( GT_32( x % L_shl( 1, exp ), 0 ) ) diff --git a/lib_com/tools_fx.c b/lib_com/tools_fx.c index 0f0065a3d..bba84cdb9 100644 --- a/lib_com/tools_fx.c +++ b/lib_com/tools_fx.c @@ -54,22 +54,22 @@ #include "prot.h" #include "ivas_prot_fx.h" -#define INV_BANDS10 3277 /* 1/10 in Q15 */ -#define INV_BANDS9 3641 /* 1/9 in Q15 */ -#define INV_BANDS3 10923 /* 1/9 in Q15 */ -const Word16 b_hp400_fx[3] = { 3660, -7320, 3660 }; /* Q12 (/4) */ +#define INV_BANDS10 3277 /* 1/10 in Q15 */ +#define INV_BANDS9 3641 /* 1/9 in Q15 */ +#define INV_BANDS3 10923 /* 1/9 in Q15 */ +const Word16 b_hp400_fx[3] = { 3660, -7320, 3660 }; /* Q12 (/4) */ const Word16 a_hp400_fx[3] = { 16384, 29280, -14160 }; -const Word16 a_hp400_ivas_fx[3] = { 4096, 7320, -3540 };/*Q12*/ +const Word16 a_hp400_ivas_fx[3] = { 4096, 7320, -3540 }; /*Q12*/ // conversion functions: Word32 float_to_fix( float number, Word32 Q ) { assert( Q >= 0 ); - if (number == 1.0f && Q == Q31) + if ( number == 1.0f && Q == Q31 ) { return ONE_IN_Q31; } - if (isnan(number)) + if ( isnan( number ) ) { number = 0; } @@ -88,7 +88,8 @@ float fix_to_float( Word32 number, Word32 Q ) Word16 float_to_fix16( float number, Word16 Q ) { assert( Q >= 0 ); - IF(isnan(number)) return 0; + IF( isnan( number ) ) + return 0; if ( number == 1.0f && Q == Q15 ) return MAX16B; assert( fabs( number ) < pow( 2, 15 - Q ) ); @@ -97,21 +98,23 @@ Word16 float_to_fix16( float number, Word16 Q ) } #ifdef IVAS_FLOAT_FIXED -Word16 float_to_fix16_thrld(float number, Word16 Q) +Word16 float_to_fix16_thrld( float number, Word16 Q ) { - assert(Q >= 0); - if (number == 1.0f && Q == Q15) + assert( Q >= 0 ); + if ( number == 1.0f && Q == Q15 ) return MAX16B; - float limit = (float)pow(2, 15 - Q); + float limit = (float) pow( 2, 15 - Q ); /*Add threshold*/ - if (number > MAX16B_FLT) { + if ( number > MAX16B_FLT ) + { number = MAX16B_FLT; } - else if (number < MIN16B_FLT) { + else if ( number < MIN16B_FLT ) + { number = MIN16B_FLT; } - assert(number <= limit && number >= -limit); - Word16 ret = (Word16)(number * ((UWord16)1 << Q)); + assert( number <= limit && number >= -limit ); + Word16 ret = (Word16) ( number * ( (UWord16) 1 << Q ) ); return ret; } #endif @@ -225,62 +228,62 @@ void fix2f( Word32 *var_fix, float *var_flt, Word32 expo ) *var_flt = (float) ldexp( mf, expo ); } -void f2fix_16(float *var_flt, Word16 *var_fix, Word32 expo) +void f2fix_16( float *var_flt, Word16 *var_fix, Word32 expo ) { - *var_fix = (Word16)(*var_flt * pow(2, 15 - expo)); + *var_fix = (Word16) ( *var_flt * pow( 2, 15 - expo ) ); } -void fix2f_16(Word16 *var_fix, float *var_flt, Word32 expo) +void fix2f_16( Word16 *var_fix, float *var_flt, Word32 expo ) { - float mf = fix16_to_float(*var_fix, 15); - *var_flt = (float)ldexp(mf, expo); + float mf = fix16_to_float( *var_fix, 15 ); + *var_flt = (float) ldexp( mf, expo ); } -int16_t norm_ul(uint32_t UL_var1) +int16_t norm_ul( uint32_t UL_var1 ) { - int16_t var_out; + int16_t var_out; - if (UL_var1 == 0) - { - var_out = 0; - } - else - { - for (var_out = 0; UL_var1 < (uint32_t)0x80000000U; var_out++) + if ( UL_var1 == 0 ) { - UL_var1 <<= 1; + var_out = 0; } - } - BASOP_CHECK(); + else + { + for ( var_out = 0; UL_var1 < (uint32_t) 0x80000000U; var_out++ ) + { + UL_var1 <<= 1; + } + } + BASOP_CHECK(); - return (var_out); + return ( var_out ); } /*-------------------------------------------------------------------* - * usdequant_fx() - * - * Uniform scalar de-quantizer routine - * - * Applies de-quantization based on scale and round operations. - *-------------------------------------------------------------------*/ -Word16 usdequant_fx( /* Qx*/ - const Word16 idx, /* i: quantizer index Q0*/ - const Word16 qlow, /* i: lowest codebook entry (index 0) Qx*/ - const Word16 delta /* i: quantization step Qx-1*/ + * usdequant_fx() + * + * Uniform scalar de-quantizer routine + * + * Applies de-quantization based on scale and round operations. + *-------------------------------------------------------------------*/ +Word16 usdequant_fx( /* Qx*/ + const Word16 idx, /* i: quantizer index Q0*/ + const Word16 qlow, /* i: lowest codebook entry (index 0) Qx*/ + const Word16 delta /* i: quantization step Qx-1*/ ) { Word16 g; Word32 L_tmp; /*g = idx * delta + qlow;*/ - L_tmp = L_deposit_l(qlow);/*Qx */ - L_tmp = L_mac(L_tmp,idx,delta);/*Qx */ + L_tmp = L_deposit_l( qlow ); /*Qx */ + L_tmp = L_mac( L_tmp, idx, delta ); /*Qx */ #ifdef BASOP_NOGLOB - g = round_fx_sat(L_shl_sat(L_tmp,16)); /*Qx */ + g = round_fx_sat( L_shl_sat( L_tmp, 16 ) ); /*Qx */ #else - g = round_fx(L_shl(L_tmp,16)); /*Qx */ + g = round_fx( L_shl( L_tmp, 16 ) ); /*Qx */ #endif - return( g ); + return ( g ); } /*-------------------------------------------------------------------* @@ -292,12 +295,12 @@ Word16 usdequant_fx( /* Qx*/ * Applies quantization based on scale and round operations. * Index of the winning codeword and the winning codeword itself are returned. *-------------------------------------------------------------------*/ -Word16 usquant_fx( /* o: index of the winning codeword */ - const Word16 x, /* i: scalar value to quantize Qx*/ - Word16 *xq, /* o: quantized value Qx*/ - const Word16 qlow, /* i: lowest codebook entry (index 0) Qx*/ - const Word16 delta, /* i: quantization step Qx-1*/ - const Word16 cbsize /* i: codebook size */ +Word16 usquant_fx( /* o: index of the winning codeword */ + const Word16 x, /* i: scalar value to quantize Qx*/ + Word16 *xq, /* o: quantized value Qx*/ + const Word16 qlow, /* i: lowest codebook entry (index 0) Qx*/ + const Word16 delta, /* i: quantization step Qx-1*/ + const Word16 cbsize /* i: codebook size */ ) { Word16 idx; @@ -308,51 +311,51 @@ Word16 usquant_fx( /* o: index of the winning codeword */ #endif /* idx = (short)( (x - qlow)/delta + 0.5f); */ - exp = norm_s(delta); - tmp = div_s(shl(1,sub(14,exp)),delta); /*Q(29-exp-(Qx-1))->Q(30-exp-Qx) */ + exp = norm_s( delta ); + tmp = div_s( shl( 1, sub( 14, exp ) ), delta ); /*Q(29-exp-(Qx-1))->Q(30-exp-Qx) */ #ifdef BASOP_NOGLOB - L_tmp = L_mult(sub_o(x, qlow, &Overflow), tmp); /*Q(31-exp) */ - idx = extract_l(L_shr_r(L_add(L_tmp,shl_o(1,sub(30,exp), &Overflow)),sub(31,exp))); /*Q0 */ -#else /* BASOP_NOGLOB */ - L_tmp = L_mult(sub(x, qlow), tmp); /*Q(31-exp) */ - idx = extract_l(L_shr_r(L_add(L_tmp,shl(1,sub(30,exp))),sub(31,exp))); /*Q0 */ -#endif /* BASOP_NOGLOB */ + L_tmp = L_mult( sub_o( x, qlow, &Overflow ), tmp ); /*Q(31-exp) */ + idx = extract_l( L_shr_r( L_add( L_tmp, shl_o( 1, sub( 30, exp ), &Overflow ) ), sub( 31, exp ) ) ); /*Q0 */ +#else /* BASOP_NOGLOB */ + L_tmp = L_mult( sub( x, qlow ), tmp ); /*Q(31-exp) */ + idx = extract_l( L_shr_r( L_add( L_tmp, shl( 1, sub( 30, exp ) ) ), sub( 31, exp ) ) ); /*Q0 */ +#endif /* BASOP_NOGLOB */ - idx = s_min(idx,sub(cbsize,1)); - idx = s_max( idx, 0); + idx = s_min( idx, sub( cbsize, 1 ) ); + idx = s_max( idx, 0 ); /* *xq = idx*delta + qlow; */ - L_tmp = L_deposit_l(qlow);/*Qx */ - L_tmp = L_mac(L_tmp,idx,delta);/*Qx */ + L_tmp = L_deposit_l( qlow ); /*Qx */ + L_tmp = L_mac( L_tmp, idx, delta ); /*Qx */ #ifdef BASOP_NOGLOB - *xq = round_fx_o(L_shl_o(L_tmp,16, &Overflow), &Overflow);/*Qx */ + *xq = round_fx_o( L_shl_o( L_tmp, 16, &Overflow ), &Overflow ); /*Qx */ #else - *xq = round_fx(L_shl(L_tmp,16));/*Qx */ + *xq = round_fx( L_shl( L_tmp, 16 ) ); /*Qx */ #endif return idx; } /*-------------------------------------------------------------------* -* Dot_product: -* -* Compute scalar product of using accumulator. -* Performs no normalization, as opposed to Dot_product12() -*-------------------------------------------------------------------*/ -Word32 Dot_product( /* o : Sum */ - const Word16 x[], /* i : 12bits: x vector */ - const Word16 y[], /* i : 12bits: y vector */ - const Word16 lg /* i : vector length */ + * Dot_product: + * + * Compute scalar product of using accumulator. + * Performs no normalization, as opposed to Dot_product12() + *-------------------------------------------------------------------*/ +Word32 Dot_product( /* o : Sum */ + const Word16 x[], /* i : 12bits: x vector */ + const Word16 y[], /* i : 12bits: y vector */ + const Word16 lg /* i : vector length */ ) { Word16 i; Word32 L_sum; - Word64 L64_sum; + Word64 L64_sum; L64_sum = 1; - FOR (i = 0; i < lg; i++) + FOR( i = 0; i < lg; i++ ) { - L64_sum = W_mac_16_16(L64_sum, x[i], y[i]); + L64_sum = W_mac_16_16( L64_sum, x[i], y[i] ); } - L_sum = W_sat_l(L64_sum); + L_sum = W_sat_l( L64_sum ); return L_sum; } /*---------------------------------------------------------------------* @@ -361,34 +364,34 @@ Word32 Dot_product( /* o : Sum */ * Dot product of vector x[] and vector y[] *---------------------------------------------------------------------*/ -Word32 dotp_fx( /* o : dot product of x[] and y[] */ - const Word16 x[], /* i : vector x[] */ - const Word16 y[], /* i : vector y[] */ - const Word16 n, /* i : vector length */ - Word16 *exp /* (o) : exponent of result (0..+30) */ +Word32 dotp_fx( /* o : dot product of x[] and y[] */ + const Word16 x[], /* i : vector x[] */ + const Word16 y[], /* i : vector y[] */ + const Word16 n, /* i : vector length */ + Word16 *exp /* (o) : exponent of result (0..+30) */ ) { Word16 sft; Word32 L_sum; - assert(*exp == 0); + assert( *exp == 0 ); - L_sum = L_add(L_shr(Dot_product(x, y, n), 1), 1); + L_sum = L_add( L_shr( Dot_product( x, y, n ), 1 ), 1 ); /* Normalize acc in Q31 */ - sft = norm_l(L_sum); - L_sum = L_shl(L_sum, sft); + sft = norm_l( L_sum ); + L_sum = L_shl( L_sum, sft ); - *exp = sub(30, sft); - move16(); /* exponent = 0..30 */ + *exp = sub( 30, sft ); + move16(); /* exponent = 0..30 */ return L_sum; } -Word32 sum2_fx( /* o : sum of all squared vector elements Q(2x+1)*/ - const Word16 *vec, /* i : input vector Qx*/ - const Word16 lvec /* i : length of input vector */ +Word32 sum2_fx( /* o : sum of all squared vector elements Q(2x+1)*/ + const Word16 *vec, /* i : input vector Qx*/ + const Word16 lvec /* i : length of input vector */ ) { Word16 i; @@ -396,22 +399,22 @@ Word32 sum2_fx( /* o : sum of all squared vector elements Q(2x+1)*/ #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - L_tmp = L_deposit_l(0); - FOR( i=0; i= 0; i--) + FOR( i = L - 1; i >= 0; i-- ) { y[i] = x[i]; move16(); @@ -499,11 +502,11 @@ void set64_fx( ) { Word16 i; - FOR( i = 0; i < N; i++ ) - { - y[i] = a; - move64(); - } + FOR( i = 0; i < N; i++ ) + { + y[i] = a; + move64(); + } return; } @@ -541,15 +544,15 @@ void Copy_pword( * Copy vector x[] to y[] (32 bits) *-------------------------------------------------------------------*/ void Copy32( - const Word32 x[], /* i : input vector */ - Word32 y[], /* o : output vector */ - const Word16 L /* i : vector length */ + const Word32 x[], /* i : input vector */ + Word32 y[], /* o : output vector */ + const Word16 L /* i : vector length */ ) { Word16 i; - IF(y < x) + IF( y < x ) { - FOR (i = 0; i < L; i++) + FOR( i = 0; i < L; i++ ) { y[i] = x[i]; move32(); @@ -557,7 +560,7 @@ void Copy32( } ELSE { - FOR (i = L-1; i >= 0; i--) + FOR( i = L - 1; i >= 0; i-- ) { y[i] = x[i]; move32(); @@ -565,20 +568,20 @@ void Copy32( } } /*-------------------------------------------------------------------* - * set16_fx() - * set32_fx() - * - * Set the vector elements to a value - *-------------------------------------------------------------------*/ + * set16_fx() + * set32_fx() + * + * Set the vector elements to a value + *-------------------------------------------------------------------*/ void set16_fx( - Word16 y[], /* i/o: Vector to set */ - const Word16 a, /* i : Value to set the vector to */ - const Word16 N /* i : Lenght of the vector */ + Word16 y[], /* i/o: Vector to set */ + const Word16 a, /* i : Value to set the vector to */ + const Word16 N /* i : Lenght of the vector */ ) { Word16 i; - FOR (i=0 ; i 0) + IF( exp0 > 0 ) { - FOR (i = 0; i < lg; i++) + FOR( i = 0; i < lg; i++ ) { #ifdef BASOP_NOGLOB - x[i] = shl_sat(x[i], exp0); -#else /* BASOP_NOGLOB */ - x[i] = shl(x[i], exp0); -#endif /* BASOP_NOGLOB */ + x[i] = shl_sat( x[i], exp0 ); +#else /* BASOP_NOGLOB */ + x[i] = shl( x[i], exp0 ); +#endif /* BASOP_NOGLOB */ move16(); /* saturation can occur here */ } return; } - IF (exp0 < 0) + IF( exp0 < 0 ) { #ifdef BASOP_NOGLOB - tmp = shl_sat(-32768, exp0); /* we use negative to correctly represent 1.0 */ + tmp = shl_sat( -32768, exp0 ); /* we use negative to correctly represent 1.0 */ #else BASOP_SATURATE_WARNING_OFF_EVS - tmp = shl(-32768, exp0); /* we use negative to correctly represent 1.0 */ + tmp = shl( -32768, exp0 ); /* we use negative to correctly represent 1.0 */ BASOP_SATURATE_WARNING_ON_EVS #endif - FOR (i = 0; i < lg; i++) + FOR( i = 0; i < lg; i++ ) { #ifdef BASOP_NOGLOB - x[i] = msu_r_sat(0, x[i], tmp); + x[i] = msu_r_sat( 0, x[i], tmp ); #else - x[i] = msu_r(0, x[i], tmp); + x[i] = msu_r( 0, x[i], tmp ); #endif move16(); /* msu instead of mac because factor is negative */ } @@ -901,18 +904,18 @@ void Scale_sig( } /*---------------------------------------------------------------------* - * mean() - * - *---------------------------------------------------------------------*/ -Word16 mean_fx( /* o : mean of vector */ - const Word16 *vec_fx, /* i : input vector */ - const Word16 lvec_fx /* i : length of input vector */ + * mean() + * + *---------------------------------------------------------------------*/ +Word16 mean_fx( /* o : mean of vector */ + const Word16 *vec_fx, /* i : input vector */ + const Word16 lvec_fx /* i : length of input vector */ ) { Word16 tmp; - //PMT("TBV : this function could be written differently to minimize the risk of saturation"); - tmp = sum16_fx(vec_fx,lvec_fx); - tmp = mult_r(tmp,div_s(1,lvec_fx)); + // PMT("TBV : this function could be written differently to minimize the risk of saturation"); + tmp = sum16_fx( vec_fx, lvec_fx ); + tmp = mult_r( tmp, div_s( 1, lvec_fx ) ); return tmp; } @@ -924,86 +927,86 @@ Word16 mean_fx( /* o : mean of vector */ void Vr_add( const Word16 *in1, /* i : Input vector 1 */ const Word16 *in2, /* i : Input vector 2 */ - Word16 *out, /* o : Output vector that contains vector 1 + vector 2 */ - Word16 Len /* i : Vector lenght */ + Word16 *out, /* o : Output vector that contains vector 1 + vector 2 */ + Word16 Len /* i : Vector lenght */ ) { Word16 i; - FOR (i=0; i=lo; i--) + FOR( i = sub( up, 1 ); i >= lo; i-- ) { - i1 = add(i, 1); + i1 = add( i, 1 ); tempr = r[i]; move16(); move16(); /*supplementary move for the j-1 PTR initialization*/ - FOR (j=i1; j<=up; j++) + FOR( j = i1; j <= up; j++ ) { - IF (LE_16(tempr, r[j])) + IF( LE_16( tempr, r[j] ) ) { BREAK; } - r[j-1] = r[j]; + r[j - 1] = r[j]; move16(); } - r[j-1] = tempr; + r[j - 1] = tempr; move16(); } } void sort_32_fx( - Word32 *r, /* i/o: Vector to be sorted in place */ - const Word16 lo, /* i : Low limit of sorting range */ - const Word16 up /* I : High limit of sorting range */ + Word32 *r, /* i/o: Vector to be sorted in place */ + const Word16 lo, /* i : Low limit of sorting range */ + const Word16 up /* I : High limit of sorting range */ ) { Word16 i, j; Word32 tempr; - FOR ( i=sub(up, 1); i>=lo; i-- ) + FOR( i = sub( up, 1 ); i >= lo; i-- ) { tempr = r[i]; move32(); - FOR ( j=add(i, 1); j<=up; j++ ) + FOR( j = add( i, 1 ); j <= up; j++ ) { - IF (LE_32(tempr,r[j])) + IF( LE_32( tempr, r[j] ) ) { BREAK; } - r[j-1] = r[j]; + r[j - 1] = r[j]; move32(); } - r[j-1] = tempr; + r[j - 1] = tempr; move32(); } return; } -Word16 minimum_fx( /* o : index of the minimum value in the input vector */ - const Word16 *vec_fx, /* i : input vector */ - const Word16 lvec_fx, /* i : length of input vector */ - Word16 *min_fx /* o : minimum value in the input vector */ +Word16 minimum_fx( /* o : index of the minimum value in the input vector */ + const Word16 *vec_fx, /* i : input vector */ + const Word16 lvec_fx, /* i : length of input vector */ + Word16 *min_fx /* o : minimum value in the input vector */ ) { Word16 j, ind; @@ -1013,15 +1016,15 @@ Word16 minimum_fx( /* o : index of the minimum value in the input vec tmp = vec_fx[0]; move16(); - FOR ( j=1 ; j 0) + L_tmp = L_mult0( vec[j], vec[j] ); + L_tmp1 = L_sub( L_tmp, emax ); + if ( L_tmp1 > 0 ) { ind = j; move16(); } - emax = L_max(emax, L_tmp); + emax = L_max( emax, L_tmp ); } #ifdef BASOP_NOGLOB - *ener_max = L_shr_sat(emax, add(Qvec, Qvec)); -#else /* BASOP_NOGLOB */ - *ener_max = L_shr(emax, add(Qvec, Qvec)); + *ener_max = L_shr_sat( emax, add( Qvec, Qvec ) ); +#else /* BASOP_NOGLOB */ + *ener_max = L_shr( emax, add( Qvec, Qvec ) ); #endif /* BASOP_NOGLOB */ move32(); @@ -1896,9 +1897,9 @@ Word16 emaximum_32fx( /* o : return index with max energy va * * Find the mean of a 32 bits vector *-------------------------------------------------------------------*/ -Word32 Mean32( /* o : mean of the elements of the vector */ - const Word32 in[], /* i : input vector */ - const Word16 L /* i : length of input vector */ +Word32 Mean32( /* o : mean of the elements of the vector */ + const Word32 in[], /* i : input vector */ + const Word16 L /* i : length of input vector */ ) { Word32 Ltmp; @@ -1906,53 +1907,53 @@ Word32 Mean32( /* o : mean of the elements of the vector */ inv_L = INV_BANDS9; move16(); - if (EQ_16(L, 10)) + if ( EQ_16( L, 10 ) ) { inv_L = INV_BANDS10; move16(); } - Ltmp = sum32_fx(in, L); + Ltmp = sum32_fx( in, L ); - Ltmp = Mult_32_16(Ltmp, inv_L); + Ltmp = Mult_32_16( Ltmp, inv_L ); return Ltmp; } -Word32 sum32_fx( /* o : sum of all vector elements Qx*/ - const Word32 *vec, /* i : input vector Qx*/ - const Word16 lvec /* i : length of input vector */ +Word32 sum32_fx( /* o : sum of all vector elements Qx*/ + const Word32 *vec, /* i : input vector Qx*/ + const Word16 lvec /* i : length of input vector */ ) { Word16 i; Word32 tmp; - tmp = L_deposit_l(0); - FOR( i=0; i= 0) + if ( L_mac( N, D, -32768L ) >= 0 ) { - expA = sub(expA, 1); + expA = sub( expA, 1 ); } - N = L_shl(Numer, expA); + N = L_shl( Numer, expA ); /* Perform Approximation of the Division * Since 'lo' part is '0' AND 'denom' is supposed to be constant in the targeted usage * one could import the Div32 code and pre-calc the div_s and eliminate all calcs * with 'lo' to save some complexity */ - Quotient = Div_32_optmz(N, D); /* takes 36 clocks */ + Quotient = Div_32_optmz( N, D ); /* takes 36 clocks */ /* Bring Back to Q0 (minus 2 because we removed the left shift by 2 in the Div32_optmz) */ - IF(rshift) + IF( rshift ) { - Quotient = L_shr(Quotient, add(15-2, sub(expA, sub(expB,1)))); + Quotient = L_shr( Quotient, add( 15 - 2, sub( expA, sub( expB, 1 ) ) ) ); } ELSE { - Quotient = L_shr(Quotient, add(15-2, sub(expA, expB))); + Quotient = L_shr( Quotient, add( 15 - 2, sub( expA, expB ) ) ); } /* Cross Check (do Quotient x Divisor) @@ -2069,9 +2069,8 @@ void iDiv_and_mod_32( * It is assumed that all are positive values. If not, one could * check the sign of the numer and denom, turn them into abs values * and restore the sign after*/ - TEMP = L_shl(L_mult0(extract_h(L_shl(Quotient, 1)), Denom), 16-1); - TEMP = L_mac0(TEMP, extract_l(L_and(0x7FFF, Quotient)), Denom); - + TEMP = L_shl( L_mult0( extract_h( L_shl( Quotient, 1 ) ), Denom ), 16 - 1 ); + TEMP = L_mac0( TEMP, extract_l( L_and( 0x7FFF, Quotient ) ), Denom ); /* Here we test to see if the previous "Quotient x Divisor" (or TEMP) is too small @@ -2082,40 +2081,36 @@ void iDiv_and_mod_32( * In some cases, when the divisor is very small (like 10 or something) * the quotient could be off by more than 1 and we would need a loop * to check again. That is not the case here with the current divisor */ - IF(rshift) + IF( rshift ) { - TEMP = L_shl(TEMP, 1); - WHILE (L_msu0(L_sub(Numer, TEMP), 2, Denom) >= 0) + TEMP = L_shl( TEMP, 1 ); + WHILE( L_msu0( L_sub( Numer, TEMP ), 2, Denom ) >= 0 ) { - Quotient = L_add(Quotient, 1); - TEMP = L_shl(L_mult0(extract_h(L_shl(Quotient, 1)), Denom), 16-1); - TEMP = L_mac0(TEMP, extract_l(L_and(0x7FFF, Quotient)), Denom); - TEMP = L_shl(TEMP, 1); + Quotient = L_add( Quotient, 1 ); + TEMP = L_shl( L_mult0( extract_h( L_shl( Quotient, 1 ) ), Denom ), 16 - 1 ); + TEMP = L_mac0( TEMP, extract_l( L_and( 0x7FFF, Quotient ) ), Denom ); + TEMP = L_shl( TEMP, 1 ); } } - ELSE - { - WHILE (L_msu0(L_sub(Numer, TEMP), 1, Denom) >= 0) - { - Quotient = L_add(Quotient, 1); - TEMP = L_shl(L_mult0(extract_h(L_shl(Quotient, 1)), Denom), 16-1); - TEMP = L_mac0(TEMP, extract_l(L_and(0x7FFF, Quotient)), Denom); - } - } - *Int_quotient = Quotient; + ELSE{ + WHILE( L_msu0( L_sub( Numer, TEMP ), 1, Denom ) >= 0 ){ + Quotient = L_add( Quotient, 1 ); + TEMP = L_shl( L_mult0( extract_h( L_shl( Quotient, 1 ) ), Denom ), 16 - 1 ); + TEMP = L_mac0( TEMP, extract_l( L_and( 0x7FFF, Quotient ) ), Denom ); +} +} +*Int_quotient = Quotient; +move32(); +IF( L_msu0( L_sub( Numer, TEMP ), 1, Denom ) == 0 ) +{ + *Int_mod = 0L; move32(); - IF(L_msu0(L_sub(Numer, TEMP), 1, Denom) == 0) - { - *Int_mod = 0L; - move32(); - } - ELSE - { - *Int_mod = L_sub(Numer, TEMP); - move32(); - } - - +} +ELSE +{ + *Int_mod = L_sub( Numer, TEMP ); + move32(); +} } /*===================================================================*/ @@ -2145,17 +2140,16 @@ void iDiv_and_mod_32( /* RETURN ARGUMENTS : _ None. */ /*===================================================================*/ -void pz_filter_sp_fx ( - const Word16 b [], - const Word16 a [], - Word16 x [], - Word16 y [], - Word16 buf [], +void pz_filter_sp_fx( + const Word16 b[], + const Word16 a[], + Word16 x[], + Word16 y[], + Word16 buf[], Word16 PNR, Word16 PDR, Word16 N, - Word16 Qa -) + Word16 Qa ) { Word16 i, j; Word16 s; @@ -2163,13 +2157,13 @@ void pz_filter_sp_fx ( Word32 Ltemp1; Word32 Lacc; s = negate( Qa ); - s = add( s, s ); /* s=-2Qa*/ + s = add( s, s ); /* s=-2Qa*/ s = add( s, 1 ); - FOR ( i = 0; i < N; i++ ) + FOR( i = 0; i < N; i++ ) { Lacc = L_deposit_h( x[i] ); /* Lacc in Q(16+Qn)*/ - Lacc = L_shl( Lacc, s ); /* Lacc=x[i] in Q(16+Qn-2Qa+1)*/ - FOR ( j = PDR - 1; j >= 0; j-- ) + Lacc = L_shl( Lacc, s ); /* Lacc=x[i] in Q(16+Qn-2Qa+1)*/ + FOR( j = PDR - 1; j >= 0; j-- ) #ifdef BASOP_NOGLOB Lacc = L_msu_sat( Lacc, buf[j], a[j + 1] ); /*Q(16+Qn-2Qa+1)*/ #else @@ -2179,14 +2173,14 @@ void pz_filter_sp_fx ( Lacc = L_shr( Lacc, 1 ); #ifdef BASOP_NOGLOB - Ltemp1 = L_add_sat( L_shl_sat( Lacc, Qa), 0x08000); + Ltemp1 = L_add_sat( L_shl_sat( Lacc, Qa ), 0x08000 ); #else Ltemp1 = L_add( L_shl( Lacc, Qa ), 0x08000 ); #endif s_mem = extract_h( Ltemp1 ); - Lacc = L_deposit_l(0); - FOR ( j = PNR - 1; j >= 0; j-- ) + Lacc = L_deposit_l( 0 ); + FOR( j = PNR - 1; j >= 0; j-- ) #ifdef BASOP_NOGLOB Lacc = L_mac_sat( Lacc, buf[j], b[j + 1] ); Lacc = L_mac_sat( Lacc, s_mem, b[0] ); @@ -2196,7 +2190,7 @@ void pz_filter_sp_fx ( #endif /* Lacc in Q(1+Qc+Qn-Qa)*/ - FOR ( j = s_max(PDR, PNR ) - 1; j > 0; j-- ) + FOR( j = s_max( PDR, PNR ) - 1; j > 0; j-- ) { /* Update filter memory */ buf[j] = buf[j - 1]; @@ -2210,17 +2204,15 @@ void pz_filter_sp_fx ( #else Ltemp1 = L_add( L_shr( Lacc, s ), 0x08000 ); /* Ltemp1 in Qc+Qa+Qn=Q(Qn) */ #endif - y[i] = extract_h( Ltemp1 ); /* y[i] in Qn */ + y[i] = extract_h( Ltemp1 ); /* y[i] in Qn */ } } - Word32 root_a_fx( Word32 a, Word16 Q_a, - Word16* exp_out -) + Word16 *exp_out ) { Word16 exp, tmp; Word32 L_tmp; @@ -2233,7 +2225,7 @@ Word32 root_a_fx( exp = norm_l( a ); tmp = extract_h( L_shl( a, exp ) ); - exp = sub( exp, sub(30, Q_a) ); + exp = sub( exp, sub( 30, Q_a ) ); tmp = div_s( 16384, tmp ); L_tmp = L_deposit_h( tmp ); L_tmp = Isqrt_lc( L_tmp, &exp ); @@ -2250,8 +2242,7 @@ Word32 root_a_over_b_fx( Word16 Q_a, Word32 b, Word16 Q_b, - Word16* exp_out -) + Word16 *exp_out ) { Word16 tmp, num, den, scale; Word16 exp, exp_num, exp_den; @@ -2269,7 +2260,7 @@ Word32 root_a_over_b_fx( exp_num = norm_l( b ); #ifdef BASOP_NOGLOB - num = round_fx_o( L_shl_o( b, exp_num, &Overflow ), &Overflow); + num = round_fx_o( L_shl_o( b, exp_num, &Overflow ), &Overflow ); #else num = round_fx( L_shl( b, exp_num ) ); #endif @@ -2277,8 +2268,8 @@ Word32 root_a_over_b_fx( exp_den = norm_l( a ); #ifdef BASOP_NOGLOB - den = round_fx_o( L_shl_o( a, exp_den , &Overflow) , &Overflow); -#else /* BASOP_NOGLOB */ + den = round_fx_o( L_shl_o( a, exp_den, &Overflow ), &Overflow ); +#else /* BASOP_NOGLOB */ den = round_fx( L_shl( a, exp_den ) ); #endif /* BASOP_NOGLOB */ exp_den = sub( sub( 30, exp_den ), Q_a ); @@ -2326,18 +2317,19 @@ Word32 root_a_over_b_fx( /*-------------------------------------------------------------------*/ /* RETURN ARGUMENTS : _ None. */ /*===================================================================*/ -void fir_fx( const Word16 x[], /* i : input vector Qx*/ - const Word16 h[], /* i : impulse response of the FIR filter Q12*/ - Word16 y[], /* o : output vector (result of filtering) Qx*/ - Word16 mem[], /* i/o: memory of the input signal (L samples) Qx*/ - const Word16 L, /* i : input vector size */ - const Word16 K, /* i : order of the FIR filter (K+1 coefs.) */ - const Word16 upd /* i : 1 = update the memory, 0 = not */ - , Word16 shift /* i : difference between Q15 and scaling of h[] */ - ) -{ - - Word16 buf_in[L_FRAME32k+L_FILT_MAX]; +void fir_fx( const Word16 x[], /* i : input vector Qx*/ + const Word16 h[], /* i : impulse response of the FIR filter Q12*/ + Word16 y[], /* o : output vector (result of filtering) Qx*/ + Word16 mem[], /* i/o: memory of the input signal (L samples) Qx*/ + const Word16 L, /* i : input vector size */ + const Word16 K, /* i : order of the FIR filter (K+1 coefs.) */ + const Word16 upd /* i : 1 = update the memory, 0 = not */ + , + Word16 shift /* i : difference between Q15 and scaling of h[] */ +) +{ + + Word16 buf_in[L_FRAME32k + L_FILT_MAX]; Word16 i, j; Word32 s; #ifdef BASOP_NOGLOB_DECLARE_LOCAL @@ -2346,27 +2338,27 @@ void fir_fx( const Word16 x[], /* i : input vector /* prepare the input buffer (copy and update memory) */ Copy( mem, buf_in, K ); Copy( x, buf_in + K, L ); - IF ( upd ) + IF( upd ) { Copy( buf_in + L, mem, K ); } /* do the filtering */ - FOR ( i = 0; i < L; i++ ) + FOR( i = 0; i < L; i++ ) { #ifdef BASOP_NOGLOB s = L_mult_o( buf_in[K + i], h[0], &Overflow ); - FOR ( j = 1; j <= K; j++ ) + FOR( j = 1; j <= K; j++ ) { - s = L_mac_o( s, h[j], buf_in[K + i - j], &Overflow); + s = L_mac_o( s, h[j], buf_in[K + i - j], &Overflow ); } - s = L_shl_o( s, shift, &Overflow); - y[i] = round_fx_o( s, &Overflow); /*Qx */ + s = L_shl_o( s, shift, &Overflow ); + y[i] = round_fx_o( s, &Overflow ); /*Qx */ #else s = L_mult( buf_in[K + i], h[0] ); - FOR ( j = 1; j <= K; j++ ) + FOR( j = 1; j <= K; j++ ) { s = L_mac( s, h[j], buf_in[K + i - j] ); } @@ -2393,7 +2385,7 @@ void v_add_32( for ( i = 0; i < N; i++ ) { - y[i] = L_add(x1[i] , x2[i]); + y[i] = L_add( x1[i], x2[i] ); } return; @@ -2492,11 +2484,11 @@ void v_sub_16( /*--------------------------------------------------------------------------------*/ /* squant_fx() */ /*--------------------------------------------------------------------------------*/ -Word16 squant_fx( /* o: index of the winning codeword */ - const Word16 x, /* i: scalar value to quantize */ - Word16* xq, /* o: quantized value */ - const Word16 cb[], /* i: codebook */ - const Word16 cbsize /* i: codebook size */ +Word16 squant_fx( /* o: index of the winning codeword */ + const Word16 x, /* i: scalar value to quantize */ + Word16 *xq, /* o: quantized value */ + const Word16 cb[], /* i: codebook */ + const Word16 cbsize /* i: codebook size */ ) { Word16 tmp; @@ -2511,28 +2503,28 @@ Word16 squant_fx( /* o: index of the winning codeword */ L_mindist = MAX_32; move32(); - FOR ( c = 0; c < cbsize; c++ ) + FOR( c = 0; c < cbsize; c++ ) { - L_dist = L_deposit_l(0); + L_dist = L_deposit_l( 0 ); #ifdef BASOP_NOGLOB - tmp = sub_o( x, cb[c] , &Overflow); -#else /* BASOP_NOGLOB */ + tmp = sub_o( x, cb[c], &Overflow ); +#else /* BASOP_NOGLOB */ tmp = sub( x, cb[c] ); #endif /* BASOP_NOGLOB */ /*dist += tmp*tmp; */ #ifdef BASOP_NOGLOB - L_dist = L_mac_o( L_dist, tmp, tmp , &Overflow); -#else /* BASOP_NOGLOB */ + L_dist = L_mac_o( L_dist, tmp, tmp, &Overflow ); +#else /* BASOP_NOGLOB */ L_dist = L_mac( L_dist, tmp, tmp ); #endif /* BASOP_NOGLOB */ - if ( LT_32( L_dist, L_mindist )) + if ( LT_32( L_dist, L_mindist ) ) { idx = c; move16(); } - L_mindist = L_min(L_mindist, L_dist); + L_mindist = L_min( L_mindist, L_dist ); } *xq = cb[idx]; @@ -2568,17 +2560,16 @@ Word16 squant_fx( /* o: index of the winning codeword */ /* RETURN ARGUMENTS : _ None. */ /*===================================================================*/ -void pz_filter_dp_fx ( - const Word16 b [], - const Word16 a [], - Word16 x [], - Word16 y [], - Word32 buf [], +void pz_filter_dp_fx( + const Word16 b[], + const Word16 a[], + Word16 x[], + Word16 y[], + Word32 buf[], Word16 PNR, Word16 PDR, Word16 N, - Word16 Qa -) + Word16 Qa ) { Word16 i, j; Word16 s; @@ -2587,27 +2578,27 @@ void pz_filter_dp_fx ( Word32 Lacc; s = negate( Qa ); - s = add( s, s ); /* s=-2Qa */ + s = add( s, s ); /* s=-2Qa */ s = add( s, 1 ); - FOR ( i = 0; i < N; i++ ) + FOR( i = 0; i < N; i++ ) { - Lacc = L_deposit_h( x[i] ); /* Lacc in Q(16+Qn)*/ - Lacc = L_shl( Lacc, s ); /* Lacc=x[i] in Q(16+Qn-2Qa+1)*/ - FOR ( j = PDR - 1; j >= 0; j-- ) - Lacc = Msub_32_16( Lacc, buf[j], a[j + 1] ); /*Q(16+Qn-2Qa+1)*/ + Lacc = L_deposit_h( x[i] ); /* Lacc in Q(16+Qn)*/ + Lacc = L_shl( Lacc, s ); /* Lacc=x[i] in Q(16+Qn-2Qa+1)*/ + FOR( j = PDR - 1; j >= 0; j-- ) + Lacc = Msub_32_16( Lacc, buf[j], a[j + 1] ); /*Q(16+Qn-2Qa+1)*/ #ifdef BASOP_NOGLOB s_mem = L_shl_sat( Lacc, sub( Qa, 1 ) ); /*Qn-Qa+16=Qn+Qc*/ #else - s_mem = L_shl( Lacc, sub( Qa, 1 ) ); /*Qn-Qa+16=Qn+Qc*/ + s_mem = L_shl( Lacc, sub( Qa, 1 ) ); /*Qn-Qa+16=Qn+Qc*/ #endif - Lacc = L_deposit_l(0); - FOR ( j = PNR - 1; j >= 0; j-- ) + Lacc = L_deposit_l( 0 ); + FOR( j = PNR - 1; j >= 0; j-- ) Lacc = Madd_32_16( Lacc, buf[j], b[j + 1] ); Lacc = Madd_32_16( Lacc, s_mem, b[0] ); /* Lacc in Q(1+Qc+Qn-Qa) */ - FOR ( j = s_max( PDR, PNR ) - 1; j > 0; j-- ) + FOR( j = s_max( PDR, PNR ) - 1; j > 0; j-- ) { /* Update filter memory */ buf[j] = buf[j - 1]; @@ -2617,11 +2608,11 @@ void pz_filter_dp_fx ( move16(); #ifdef BASOP_NOGLOB - Ltemp1 = L_shr_sat( Lacc, s ); /* Ltemp1 in Qc+Qa+Qn=Q(16+Qn) */ + Ltemp1 = L_shr_sat( Lacc, s ); /* Ltemp1 in Qc+Qa+Qn=Q(16+Qn) */ #else - Ltemp1 = L_shr( Lacc, s ); /* Ltemp1 in Qc+Qa+Qn=Q(16+Qn) */ + Ltemp1 = L_shr( Lacc, s ); /* Ltemp1 in Qc+Qa+Qn=Q(16+Qn) */ #endif - y[i] = extract_h( Ltemp1 ); /* y[i] in Qn */ + y[i] = extract_h( Ltemp1 ); /* y[i] in Qn */ } } @@ -2632,36 +2623,36 @@ void pz_filter_dp_fx ( *-------------------------------------------------------------------*/ void Copy_Scale_sig32_16( const Word32 *src, /* i : signal to scale Qx */ - Word16 *dst, /* o : scaled signal Qx */ - Word16 len, /* i : size of x[] Q0 */ - Word16 exp0) /* i : exponent: x = round(x << exp) Qx ?exp */ + Word16 *dst, /* o : scaled signal Qx */ + Word16 len, /* i : size of x[] Q0 */ + Word16 exp0 ) /* i : exponent: x = round(x << exp) Qx ?exp */ { Word16 i; Word32 L_temp; - IF (exp0 == 0) + IF( exp0 == 0 ) { - FOR (i = 0; i < len; i++ ) + FOR( i = 0; i < len; i++ ) { #ifdef BASOP_NOGLOB *dst++ = round_fx_sat( *src++ ); #else - *dst++ = round_fx(*src++); + *dst++ = round_fx( *src++ ); #endif } return; } - FOR (i = 0; i < len; i++ ) + FOR( i = 0; i < len; i++ ) { #ifdef BASOP_NOGLOB L_temp = L_shl_sat( *src++, exp0 ); - *dst++ = round_fx_sat(L_temp); + *dst++ = round_fx_sat( L_temp ); #else - L_temp = L_shl(*src++, exp0); + L_temp = L_shl( *src++, exp0 ); - *dst++ = round_fx(L_temp); + *dst++ = round_fx( L_temp ); #endif } } @@ -2669,44 +2660,44 @@ void Copy_Scale_sig32_16( /*-------------------------------------------------------------------* * v_multc_att() * - * Attenuation of a vector,, attenuation factor in Q15 + * Attenuation of a vector,, attenuation factor in Q15 *-------------------------------------------------------------------*/ void v_multc_att( - const Word16 x[], /* i : Input vector Qx */ - const Word16 att, /* i : Constant Q15, <= MAX_16 */ - Word16 y[], /* o : Output vector that contains att*x */ - const Word16 N /* i : Vector length */ + const Word16 x[], /* i : Input vector Qx */ + const Word16 att, /* i : Constant Q15, <= MAX_16 */ + Word16 y[], /* o : Output vector that contains att*x */ + const Word16 N /* i : Vector length */ ) { Word16 i; - IF(LT_16(att, 32767)) + IF( LT_16( att, 32767 ) ) { - FOR(i = 0; i < N; i++) + FOR( i = 0; i < N; i++ ) { - y[i] = mult_r(x[i], att); + y[i] = mult_r( x[i], att ); move16(); } } -}/*-------------------------------------------------------------------* - * v_multc_att32() - * - * Attenuation of a vector,, attenuation factor in Q15 - *-------------------------------------------------------------------*/ +} /*-------------------------------------------------------------------* + * v_multc_att32() + * + * Attenuation of a vector,, attenuation factor in Q15 + *-------------------------------------------------------------------*/ void v_multc_att32( - const Word32 x[], /* i : Input vector Qx */ - const Word16 att, /* i : Constant Q15, <= MAX_16 */ - Word32 y[], /* o : Output vector that contains att*x */ - const Word16 N /* i : Vector length */ + const Word32 x[], /* i : Input vector Qx */ + const Word16 att, /* i : Constant Q15, <= MAX_16 */ + Word32 y[], /* o : Output vector that contains att*x */ + const Word16 N /* i : Vector length */ ) { Word16 i; - IF(LT_16(att, 32767)) + IF( LT_16( att, 32767 ) ) { - FOR(i = 0; i < N; i++) + FOR( i = 0; i < N; i++ ) { - y[i] = Mpy_32_16_r(x[i], att); + y[i] = Mpy_32_16_r( x[i], att ); move32(); } } @@ -2789,41 +2780,41 @@ void v_L_mult_3216( *-------------------------------------------------------------------*/ void add_vec_fx( - const Word16 x1[], /* i : Input vector 1 */ - const Word16 Qx1, /* i : SCaling of input 1 */ - const Word16 x2[], /* i : Input vector 2 */ - const Word16 Qx2, /* i : SCaling of input 1 */ - Word16 y[], /* o : Output vector that contains vector 1 + vector 2 */ - const Word16 Qy, /* i : SCaling of output 1 */ - const Word16 N /* i : Vector lenght */ + const Word16 x1[], /* i : Input vector 1 */ + const Word16 Qx1, /* i : SCaling of input 1 */ + const Word16 x2[], /* i : Input vector 2 */ + const Word16 Qx2, /* i : SCaling of input 1 */ + Word16 y[], /* o : Output vector that contains vector 1 + vector 2 */ + const Word16 Qy, /* i : SCaling of output 1 */ + const Word16 N /* i : Vector lenght */ ) { Word16 i, Qyx1, Qyx2; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - Qyx1 = sub(Qx1,Qy); - Qyx2 = sub(Qx2,Qy); - IF (Qyx1 == 0) + Qyx1 = sub( Qx1, Qy ); + Qyx2 = sub( Qx2, Qy ); + IF( Qyx1 == 0 ) { - FOR (i=0 ; i0: Val was Left Shifted, <0:Right Shifted) */ - Word32 L_val2, /* i: Mantisa of Val2 */ - Word16 exp2, /* i: Exp of Val2 (same as exp1) */ - Word16 *exp /* o: Exp of Result (# of 'L_shl' Req to get to Final Value) */ +Word32 Sqrt_Ratio32( /* o: Result in Q31 */ + Word32 L_val1, /* i: Mantisa of Val1 */ + Word16 exp1, /* i: Exp of Val1 (>0: Val was Left Shifted, <0:Right Shifted) */ + Word32 L_val2, /* i: Mantisa of Val2 */ + Word16 exp2, /* i: Exp of Val2 (same as exp1) */ + Word16 *exp /* o: Exp of Result (# of 'L_shl' Req to get to Final Value) */ ) { Word16 temp; /* Normalize Energy #1 */ - temp = norm_l(L_val1); - L_val1 = L_shl(L_val1, temp); + temp = norm_l( L_val1 ); + L_val1 = L_shl( L_val1, temp ); /* Adjust Exponent of Energy #1 */ - exp1 = add(exp1, temp); + exp1 = add( exp1, temp ); /* Normalize Energy #2 */ - temp = norm_l(L_val2); - L_val2 = L_shl(L_val2, temp); + temp = norm_l( L_val2 ); + L_val2 = L_shl( L_val2, temp ); /* Adjust Exponent of Energy #1 */ - exp2 = add(exp2, temp); + exp2 = add( exp2, temp ); /* Prepare for Inverse */ #ifdef BASOP_NOGLOB - temp = round_fx_sat(L_val1); + temp = round_fx_sat( L_val1 ); #else - temp = round_fx(L_val1); + temp = round_fx( L_val1 ); #endif - temp = div_s(16384, temp); + temp = div_s( 16384, temp ); /* Mult Now */ - L_val2 = Mult_32_16(L_val2, temp); - exp1 = add(sub(exp2, exp1), 15*2); + L_val2 = Mult_32_16( L_val2, temp ); + exp1 = add( sub( exp2, exp1 ), 15 * 2 ); /* Here Result of ('L_val2' / 2^'exp2') / ('L_val1' / 2^'exp1') is */ /* 'L_val2' / 2^'exp1' */ /* Which is val2/val1 instead of val1/val2 because we will use Inverted Square Root */ /* Normalize before Square Root */ - temp = norm_l(L_val2); - L_val2 = L_shl(L_val2, temp); - exp1 = add(temp, exp1); + temp = norm_l( L_val2 ); + L_val2 = L_shl( L_val2, temp ); + exp1 = add( temp, exp1 ); /* Do Sqrt */ - temp = sub(31, exp1); - L_val1 = Isqrt_lc(L_val2, &temp); + temp = sub( 31, exp1 ); + L_val1 = Isqrt_lc( L_val2, &temp ); *exp = temp; move16(); @@ -3107,26 +3098,26 @@ Word32 Sqrt_Ratio32(/* o: Result in Q31 } Word16 Invert16( /* result in Q'15 + 'exp' */ - Word16 val, - Word16 *exp) + Word16 val, + Word16 *exp ) { Word16 temp; /* prevent 0 input */ - val = s_max(val,1); + val = s_max( val, 1 ); /* Normalize Value */ - temp = norm_s(val); - val = shl(val, temp); + temp = norm_s( val ); + val = shl( val, temp ); - *exp = sub(sub(15-1, *exp), temp); - move16();/* -1 because of 0x4000 is 1.0 in Q14 (and not Q15) */ + *exp = sub( sub( 15 - 1, *exp ), temp ); + move16(); /* -1 because of 0x4000 is 1.0 in Q14 (and not Q15) */ - temp = div_s(0x4000, val); + temp = div_s( 0x4000, val ); return temp; } -Word16 find_rem(Word16 n, Word16 m, Word16 *r) +Word16 find_rem( Word16 n, Word16 m, Word16 *r ) { Word16 i, q1, q2, qd; Word32 Ltemp2; @@ -3134,44 +3125,44 @@ Word16 find_rem(Word16 n, Word16 m, Word16 *r) test(); test(); - IF (n<=0 || m<=0 || n=0) + Lacc = L_sub( Lacc, Ltemp2 ); + IF( Lacc >= 0 ) { - Lacc=L_add(L_shl(Lacc,1),1); + Lacc = L_add( L_shl( Lacc, 1 ), 1 ); } ELSE { - Lacc=L_add(Lacc,Ltemp2); - Lacc=L_shl(Lacc,1); + Lacc = L_add( Lacc, Ltemp2 ); + Lacc = L_shl( Lacc, 1 ); } } - q1=extract_l(Lacc); - Ltemp2=L_shr(Lacc,q2); - *r=extract_h(Ltemp2); - return(q1); + q1 = extract_l( Lacc ); + Ltemp2 = L_shr( Lacc, q2 ); + *r = extract_h( Ltemp2 ); + return ( q1 ); } -Word32 find_remd(Word32 n, Word32 m, Word32 *r) +Word32 find_remd( Word32 n, Word32 m, Word32 *r ) { Word16 i, q1, q2, qd; Word32 Ltemp2, qo; @@ -3179,46 +3170,46 @@ Word32 find_remd(Word32 n, Word32 m, Word32 *r) test(); test(); - IF (n<=0 || m<=0 || n=0) + Lacc = L_sub( Lacc, Ltemp2 ); + qo = L_shl( qo, 1 ); + IF( Lacc >= 0 ) { - Lacc=L_shl(Lacc,1); - qo=L_add(qo,1); + Lacc = L_shl( Lacc, 1 ); + qo = L_add( qo, 1 ); } ELSE { - Lacc=L_add(Lacc,Ltemp2); - Lacc=L_shl(Lacc,1); + Lacc = L_add( Lacc, Ltemp2 ); + Lacc = L_shl( Lacc, 1 ); } } - *r=L_shr(Lacc,q2); - return(qo); + *r = L_shr( Lacc, q2 ); + return ( qo ); } -Word16 rint_new_fx ( - Word32 x /*Q16 */ +Word16 rint_new_fx( + Word32 x /*Q16 */ ) { Word16 a; @@ -3226,27 +3217,27 @@ Word16 rint_new_fx ( Word16 frac, tmp; /* middle value point test */ - frac = lshr(extract_l(x),1); /*Q15 */ - tmp = sub(frac,0x4000); + frac = lshr( extract_l( x ), 1 ); /*Q15 */ + tmp = sub( frac, 0x4000 ); - IF (!tmp) + IF( !tmp ) { - a = add(extract_h(x),1); + a = add( extract_h( x ), 1 ); - if (s_and(a,1) == 0) + if ( s_and( a, 1 ) == 0 ) { return a; } - if (s_and(a,1) != 0) + if ( s_and( a, 1 ) != 0 ) { - return extract_h(x); + return extract_h( x ); } - return extract_h(x); + return extract_h( x ); } ELSE { - L_tmp = L_add(x,32768); /*Q16 */ - return extract_h(L_tmp); + L_tmp = L_add( x, 32768 ); /*Q16 */ + return extract_h( L_tmp ); } } @@ -3279,11 +3270,9 @@ Word16 rint_new_fx ( /* CALLED FROM : TX */ /*===================================================================*/ -Word16 erb_diff_search_fx(Word16 *prev_erb, const Word16 *curr_erb, Word16 *dif_erb, - Word16 *pow_spec, const Word16 *cb_fx, - Word16 cb_size, Word16 cb_dim, Word16 offset) +Word16 erb_diff_search_fx( Word16 *prev_erb, const Word16 *curr_erb, Word16 *dif_erb, Word16 *pow_spec, const Word16 *cb_fx, Word16 cb_size, Word16 cb_dim, Word16 offset ) { - Word16 i, j, mmseindex ; + Word16 i, j, mmseindex; Word16 dh, dl; Word32 mmse; Word32 Ltemp1; @@ -3293,98 +3282,97 @@ Word16 erb_diff_search_fx(Word16 *prev_erb, const Word16 *curr_erb, Word16 *dif_ move32(); mmseindex = -1; move16(); - FOR (j=0; j Q13 */ + L_tmp = L_shl( L_tmp, 1 ); /* coeff Q12 --> Q13 */ - L_tmp2 = L_mac(L_tmp3, y1_hi, a_hp400_fx[2]); - L_tmp2 = L_mac(L_tmp2, *signal, b_hp400_fx[1]); - L_tmp3 = L_mac(16384L, y1_lo, a_hp400_fx[2]); /* rounding to maximize precision */ + L_tmp2 = L_mac( L_tmp3, y1_hi, a_hp400_fx[2] ); + L_tmp2 = L_mac( L_tmp2, *signal, b_hp400_fx[1] ); + L_tmp3 = L_mac( 16384L, y1_lo, a_hp400_fx[2] ); /* rounding to maximize precision */ - y1_lo = L_Extract_lc(L_tmp, &y1_hi); + y1_lo = L_Extract_lc( L_tmp, &y1_hi ); - L_tmp3 = L_mac(L_tmp3, y1_lo, a_hp400_fx[1]); - L_tmp3 = L_shr(L_tmp3, 15); + L_tmp3 = L_mac( L_tmp3, y1_lo, a_hp400_fx[1] ); + L_tmp3 = L_shr( L_tmp3, 15 ); - L_tmp2 = L_add(L_tmp3, L_tmp2); + L_tmp2 = L_add( L_tmp3, L_tmp2 ); - L_tmp3 = L_mult(*signal, b_hp400_fx[2]); + L_tmp3 = L_mult( *signal, b_hp400_fx[2] ); /* signal is divided by 16 to avoid overflow in energy computation */ - *signal++ = round_fx(L_tmp); + *signal++ = round_fx( L_tmp ); } /* y[i] = b[0]*x[i] + b[1]*x[i-1] + b[2]*x[i-2] */ /* + a[1]*y[i-1] + a[2] * y[i-2] */ - L_tmp = L_mac(L_tmp2, y1_hi, a_hp400_fx[1]); + L_tmp = L_mac( L_tmp2, y1_hi, a_hp400_fx[1] ); mem[4] = *signal; move16(); - L_tmp = L_mac(L_tmp, mem[4], b_hp400_fx[0]); + L_tmp = L_mac( L_tmp, mem[4], b_hp400_fx[0] ); - L_tmp = L_shl(L_tmp, 1); /* coeff Q12 --> Q13 */ + L_tmp = L_shl( L_tmp, 1 ); /* coeff Q12 --> Q13 */ mem[0] = y1_hi; move16(); mem[1] = y1_lo; move16(); - L_Extract(L_tmp, &mem[2], &mem[3]); + L_Extract( L_tmp, &mem[2], &mem[3] ); /* signal is divided by 16 to avoid overflow in energy computation */ - *signal++ = round_fx(L_tmp); + *signal++ = round_fx( L_tmp ); return; } @@ -3634,7 +3622,7 @@ void hp400_12k8_ivas_fx( } #endif -Word16 dot_prod_satcontr(const Word16 *x, const Word16 *y, Word16 qx, Word16 qy, Word16 *qo, Word16 len) +Word16 dot_prod_satcontr( const Word16 *x, const Word16 *y, Word16 qx, Word16 qy, Word16 *qo, Word16 len ) { Word16 tmp_tab_x[L_FRAME16k]; Word16 tmp_tab_y[L_FRAME16k]; @@ -3656,37 +3644,37 @@ Word16 dot_prod_satcontr(const Word16 *x, const Word16 *y, Word16 qx, Word16 qy, { Overflow = 0; move16(); -#ifdef BASOP_NOGLOB /* Critical Overflow and all those below*/ - L_tmp = L_shl_o(1, s_max(sub(add(add(qx, qy), 7), shift), 0), &Overflow); -#else /* BASOP_NOGLOB */ - L_tmp = L_shl(1, s_max(sub(add(add(qx, qy), 7), shift), 0)); +#ifdef BASOP_NOGLOB /* Critical Overflow and all those below*/ + L_tmp = L_shl_o( 1, s_max( sub( add( add( qx, qy ), 7 ), shift ), 0 ), &Overflow ); +#else /* BASOP_NOGLOB */ + L_tmp = L_shl( 1, s_max( sub( add( add( qx, qy ), 7 ), shift ), 0 ) ); #endif /* BASOP_NOGLOB */ pt1 = tmp_tab_x; pt2 = tmp_tab_y; - FOR ( i = 0; i < len; i++ ) + FOR( i = 0; i < len; i++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_mac0_o(L_tmp, *pt1++, *pt2++, &Overflow); /*Q(qx+qy-shift) */ -#else /* BASOP_NOGLOB */ - L_tmp = L_mac0(L_tmp, *pt1++, *pt2++); /*Q(qx+qy-shift) */ + L_tmp = L_mac0_o( L_tmp, *pt1++, *pt2++, &Overflow ); /*Q(qx+qy-shift) */ +#else /* BASOP_NOGLOB */ + L_tmp = L_mac0( L_tmp, *pt1++, *pt2++ ); /*Q(qx+qy-shift) */ #endif } - IF(Overflow != 0) + IF( Overflow != 0 ) { - Scale_sig(tmp_tab_x, len, -2); - Scale_sig(tmp_tab_y, len, -2); - shift = add(shift, 4); + Scale_sig( tmp_tab_x, len, -2 ); + Scale_sig( tmp_tab_y, len, -2 ); + shift = add( shift, 4 ); } } - WHILE(Overflow != 0); + WHILE( Overflow != 0 ); BASOP_SATURATE_WARNING_ON_EVS - q = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, q); /*Q(qx+qy-shift+q) */ - ener = extract_h(L_tmp); /*Q(qx+qy-shift+q-16) */ - q = add(q, add(qx, qy)); - *qo = sub(q, add(shift, 16)); + q = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, q ); /*Q(qx+qy-shift+q) */ + ener = extract_h( L_tmp ); /*Q(qx+qy-shift+q-16) */ + q = add( q, add( qx, qy ) ); + *qo = sub( q, add( shift, 16 ) ); return ener; } @@ -3709,21 +3697,21 @@ Word16 dot_prod_satcontr(const Word16 *x, const Word16 *y, Word16 qx, Word16 qy, * Returns: * void */ -void E_UTIL_f_convolve(const Word16 x[], const Word16 h[], Word16 y[], const Word16 size) +void E_UTIL_f_convolve( const Word16 x[], const Word16 h[], Word16 y[], const Word16 size ) { Word16 i, n; Word32 L_sum; Word64 L64_sum; - FOR (n = 0; n < size; n++) + FOR( n = 0; n < size; n++ ) { L64_sum = 0; - FOR (i = 0; i < n; i++) + FOR( i = 0; i < n; i++ ) { - L64_sum = W_mac_16_16(L64_sum, x[i], h[n - i]); + L64_sum = W_mac_16_16( L64_sum, x[i], h[n - i] ); } - L_sum = W_sat_l(L64_sum); - y[n] = mac_r(L_sum, x[i], h[0]); + L_sum = W_sat_l( L64_sum ); + y[n] = mac_r( L_sum, x[i], h[0] ); } return; } @@ -3734,10 +3722,10 @@ void E_UTIL_f_convolve(const Word16 x[], const Word16 h[], Word16 y[], const Wor * Add two floating point numbers: x <- x + y. *----------------------------------------------------------------------------*/ void floating_point_add( - Word32 *mx, /* io: mantissa of the addend Q31 */ - Word16 *ex, /* io: exponent of the addend Q0 */ - const Word32 my, /* i: mantissa of the adder Q31 */ - const Word16 ey /* i: exponent of the adder Q0 */ + Word32 *mx, /* io: mantissa of the addend Q31 */ + Word16 *ex, /* io: exponent of the addend Q0 */ + const Word32 my, /* i: mantissa of the adder Q31 */ + const Word16 ey /* i: exponent of the adder Q0 */ ) { Word32 accX, accY; @@ -3745,25 +3733,25 @@ void floating_point_add( /* NB: This function will not work properly if the mantissa is zero and the exponent is not 32. It is up to the caller function to avoid this condition. */ /* Ensure 1 bit headroom before addition. */ - accX = L_shr(*mx, 1); - accY = L_shr(my, 1); + accX = L_shr( *mx, 1 ); + accY = L_shr( my, 1 ); /* First, align the Q-points of the two operands. Then, add. */ - align = sub(*ex, ey); + align = sub( *ex, ey ); test(); - IF (align < 0) + IF( align < 0 ) { - accX = L_add(accX, L_shl(accY, align)); + accX = L_add( accX, L_shl( accY, align ) ); } ELSE { - accX = L_add(accY, L_shr(accX, align)); + accX = L_add( accY, L_shr( accX, align ) ); *ex = ey; move16(); } /* Normalize the result and update the mantissa and exponent. */ - expo = norm_l(accX); - *mx = L_shl(accX, expo); - *ex = sub(add(*ex, expo), 1); /* Subtract 1 due to 1-bit down-shift above ensuring 1 bit headroom before addition. */ + expo = norm_l( accX ); + *mx = L_shl( accX, expo ); + *ex = sub( add( *ex, expo ), 1 ); /* Subtract 1 due to 1-bit down-shift above ensuring 1 bit headroom before addition. */ return; } /*-------------------------------------------------------------------* @@ -3773,18 +3761,18 @@ void floating_point_add( *-------------------------------------------------------------------*/ void delay_signal( - Word16 x[], /* i/o: signal to be delayed */ - const Word16 len, /* i : length of the input signal */ - Word16 mem[], /* i/o: synchronization memory */ - const Word16 delay /* i : delay in samples */ + Word16 x[], /* i/o: signal to be delayed */ + const Word16 len, /* i : length of the input signal */ + Word16 mem[], /* i/o: synchronization memory */ + const Word16 delay /* i : delay in samples */ ) { Word16 tmp_buffer[L_FRAME48k]; - Copy(mem, tmp_buffer, delay); - Copy(x + len - delay, mem, delay); - Copy(x, x + delay, len - delay); - Copy(tmp_buffer, x, delay); + Copy( mem, tmp_buffer, delay ); + Copy( x + len - delay, mem, delay ); + Copy( x, x + delay, len - delay ); + Copy( tmp_buffer, x, delay ); return; } @@ -3809,12 +3797,11 @@ void delay_signal_fx( #ifdef IVAS_FLOAT_FIXED void delay_signal_q_adj_fx( Word32 x[], /* i/o: signal to be delayed */ - const int16_t len, /* i : length of the input signal */ + const int16_t len, /* i : length of the input signal */ Word32 mem[], /* i/o: synchronization memory */ const int16_t delay, /* i : delay in samples */ const Word16 q_x, - const Word16 q_mem -) + const Word16 q_mem ) { Word32 tmp_buffer[L_FRAME48k]; @@ -3824,13 +3811,13 @@ void delay_signal_q_adj_fx( Copy32( x, x + delay, len - delay ); - IF (EQ_16(q_x, q_mem)) + IF( EQ_16( q_x, q_mem ) ) { Copy32( tmp_buffer, x, delay ); } ELSE { - v_shr( tmp_buffer, sub(q_mem, q_x), x, delay ); + v_shr( tmp_buffer, sub( q_mem, q_x ), x, delay ); } return; @@ -3841,14 +3828,14 @@ void v_add_fx( const Word32 x1[], /* i : Input vector 1 */ const Word32 x2[], /* i : Input vector 2 */ Word32 y[], /* o : Output vector that contains vector 1 + vector 2 */ - const int16_t N /* i : Vector length */ + const int16_t N /* i : Vector length */ ) { int16_t i; for ( i = 0; i < N; i++ ) { - y[i] = L_add_sat(x1[i], x2[i]); + y[i] = L_add_sat( x1[i], x2[i] ); } return; @@ -3879,34 +3866,34 @@ Word16 floor_log_2( Word32 num ) } void v_shr( - const Word32 x[], /* i : Input vector */ - const Word16 shift, /* i : Constant */ - Word32 y[], /* o : Output vector that contains x >> shift */ - const Word16 N /* i : Vector length */ + const Word32 x[], /* i : Input vector */ + const Word16 shift, /* i : Constant */ + Word32 y[], /* o : Output vector that contains x >> shift */ + const Word16 N /* i : Vector length */ ) { Word16 i; for ( i = 0; i < N; i++ ) { - y[i] = L_shr(x[i], shift); + y[i] = L_shr( x[i], shift ); } return; } void v_shr_16( - const Word16 x[], /* i : Input vector */ - const Word16 shift, /* i : Constant */ - Word16 y[], /* o : Output vector that contains x >> shift */ - const Word16 N /* i : Vector length */ + const Word16 x[], /* i : Input vector */ + const Word16 shift, /* i : Constant */ + Word16 y[], /* o : Output vector that contains x >> shift */ + const Word16 N /* i : Vector length */ ) { Word16 i; for ( i = 0; i < N; i++ ) { - y[i] = shr(x[i], shift); + y[i] = shr( x[i], shift ); } return; @@ -3919,20 +3906,20 @@ void v_shr_16( *-------------------------------------------------------------------*/ void delay_signal32( - Word32 x[], /* i/o: signal to be delayed */ - const Word16 len, /* i : length of the input signal */ - Word32 mem[], /* i/o: synchronization memory */ - const Word16 delay /* i : delay in samples */ + Word32 x[], /* i/o: signal to be delayed */ + const Word16 len, /* i : length of the input signal */ + Word32 mem[], /* i/o: synchronization memory */ + const Word16 delay /* i : delay in samples */ ) { - Word32 tmp_buffer[L_FRAME48k]; + Word32 tmp_buffer[L_FRAME48k]; - Copy32(mem, tmp_buffer, delay); - Copy32(x + len - delay, mem, delay); - Copy32(x, x + delay, len - delay); - Copy32(tmp_buffer, x, delay); + Copy32( mem, tmp_buffer, delay ); + Copy32( x + len - delay, mem, delay ); + Copy32( x, x + delay, len - delay ); + Copy32( tmp_buffer, x, delay ); - return; + return; } @@ -3982,7 +3969,7 @@ Word32 sign_l( const Word32 x /* i : input value of x */ ) { - IF ( LT_32(x , 0) ) + IF( LT_32( x, 0 ) ) { return MIN_32; } diff --git a/lib_com/trans_direct_fx.c b/lib_com/trans_direct_fx.c index c4962a813..b088be832 100644 --- a/lib_com/trans_direct_fx.c +++ b/lib_com/trans_direct_fx.c @@ -2,24 +2,24 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common FX constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "rom_com.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common FX constants */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "rom_com.h" /* Function prototypes */ /*------------------------------------------------------------------- * direct_transform() * * Transformation of the signal to DCT domain *-------------------------------------------------------------------*/ - void direct_transform_fx( - const Word32 in32_fx[], /* i : input signal */ - Word32 out32_fx[], /* o : transformation */ - const Word16 is_transient, /* i : is transient */ - const Word16 L, /* i : length */ +void direct_transform_fx( + const Word32 in32_fx[], /* i : input signal */ + Word32 out32_fx[], /* o : transformation */ + const Word16 is_transient, /* i : is transient */ + const Word16 L, /* i : length */ Word16 *Q, - const Word16 element_mode /* i : IVAS element mode */ + const Word16 element_mode /* i : IVAS element mode */ ) { @@ -42,24 +42,24 @@ Word32 L_tmp; Word16 Qs[NUM_TIME_SWITCHING_BLOCKS]; #ifdef REMOVE_IVAS_UNUSED_PARAMETERS_WARNING - (void)(element_mode); + (void) ( element_mode ); #endif - segment_length = shr(L, 1); - segment_length2 = shr(segment_length, 1); - segment_length4 = shr(segment_length2, 1); + segment_length = shr( L, 1 ); + segment_length2 = shr( segment_length, 1 ); + segment_length4 = shr( segment_length2, 1 ); - IF (is_transient) + IF( is_transient ) { - IF (EQ_16(L, L_FRAME48k)) + IF( EQ_16( L, L_FRAME48k ) ) { win_fx = wscw16q15_fx; } - ELSE IF (EQ_16(L, L_FRAME32k)) + ELSE IF( EQ_16( L, L_FRAME32k ) ) { win_fx = wscw16q15_32_fx; } - ELSE IF (EQ_16(L, L_FRAME8k)) + ELSE IF( EQ_16( L, L_FRAME8k ) ) { win_fx = wscw16q15_8_fx; } @@ -68,134 +68,134 @@ win_fx = wscw16q15_16_fx; } - sh_fx = &in32_fx[L-1]; - add(0,0); - sl_fx = &in32_r16_fx[L-1]; - add(0,0); - FOR (i = 0; i < segment_length; i++) + sh_fx = &in32_fx[L - 1]; + add( 0, 0 ); + sl_fx = &in32_r16_fx[L - 1]; + add( 0, 0 ); + FOR( i = 0; i < segment_length; i++ ) { - in32_r16_fx[i] = (*sh_fx--); + in32_r16_fx[i] = ( *sh_fx-- ); move32(); - (*sl_fx--) = in32_fx[i]; + ( *sl_fx-- ) = in32_fx[i]; move32(); } iseg_fx = &in32_r16_fx[-segment_length4]; - add(0,0); + add( 0, 0 ); oseg_fx = out32_fx; wh_fx = &win_fx[segment_length4]; - add(0,0); + add( 0, 0 ); wl_fx = wh_fx - 1; - shift = extract_l(L_mult0(3, segment_length4)); + shift = extract_l( L_mult0( 3, segment_length4 ) ); sh_fx = &iseg_fx[shift]; - add(0,0); + add( 0, 0 ); sl_fx2 = sh_fx - 1; - FOR (i = 0; i < segment_length4; i++) + FOR( i = 0; i < segment_length4; i++ ) { - L_tmp = L_negate(Mult_32_16( (*sh_fx++), (*wh_fx++) )); /*Q+15-15=Q */ - dctin32_fx[i] = Madd_32_16(L_tmp, *sl_fx2--, *wl_fx-- ); - move32();/*Q */ + L_tmp = L_negate( Mult_32_16( ( *sh_fx++ ), ( *wh_fx++ ) ) ); /*Q+15-15=Q */ + dctin32_fx[i] = Madd_32_16( L_tmp, *sl_fx2--, *wl_fx-- ); + move32(); /*Q */ } sl_fx2 = &iseg_fx[segment_length2 - 1]; - add(0,0); + add( 0, 0 ); - FOR (i = segment_length4; i < segment_length2; i++) + FOR( i = segment_length4; i < segment_length2; i++ ) { - dctin32_fx[i] = L_negate(*sl_fx2--); + dctin32_fx[i] = L_negate( *sl_fx2-- ); move32(); } Qs[0] = *Q; move16(); - edct_fx(dctin32_fx, oseg_fx, segment_length2, &Qs[0]); - Qmin = s_min(Qs[0], Qmin); + edct_fx( dctin32_fx, oseg_fx, segment_length2, &Qs[0] ); + Qmin = s_min( Qs[0], Qmin ); iseg_fx += segment_length2; - add(0,0); + add( 0, 0 ); oseg_fx += segment_length2; - add(0,0); + add( 0, 0 ); - FOR (seg = 1 ; seg < NUM_TIME_SWITCHING_BLOCKS-1; seg++) + FOR( seg = 1; seg < NUM_TIME_SWITCHING_BLOCKS - 1; seg++ ) { wh_fx = &win_fx[segment_length4]; - add(0,0); + add( 0, 0 ); wl_fx = wh_fx - 1; sh_fx = &iseg_fx[shift]; - add(0,0); + add( 0, 0 ); sl_fx2 = sh_fx - 1; - FOR (i = 0; i < segment_length4; i++) + FOR( i = 0; i < segment_length4; i++ ) { - L_tmp = L_negate(Mult_32_16( (*sh_fx++), (*wh_fx++) )); /*Q+15-15=Q */ - dctin32_fx[i] = Madd_32_16(L_tmp, *sl_fx2--, *wl_fx-- ); + L_tmp = L_negate( Mult_32_16( ( *sh_fx++ ), ( *wh_fx++ ) ) ); /*Q+15-15=Q */ + dctin32_fx[i] = Madd_32_16( L_tmp, *sl_fx2--, *wl_fx-- ); move32(); /*Q */ } sh_fx = iseg_fx; sl_fx2 = &iseg_fx[segment_length2 - 1]; - add(0,0); + add( 0, 0 ); wh_fx = &win_fx[segment_length2 - 1]; - add(0,0); - wl_fx = win_fx ; + add( 0, 0 ); + wl_fx = win_fx; - FOR (i = segment_length4; i < segment_length2; i++) + FOR( i = segment_length4; i < segment_length2; i++ ) { - L_tmp = Mult_32_16( (*sh_fx++), (*wh_fx--) ); /*Q+15-15=Q */ - dctin32_fx[i] = Madd_32_16(L_tmp, *sl_fx2--, *wl_fx++ ); + L_tmp = Mult_32_16( ( *sh_fx++ ), ( *wh_fx-- ) ); /*Q+15-15=Q */ + dctin32_fx[i] = Madd_32_16( L_tmp, *sl_fx2--, *wl_fx++ ); move32(); /*Q */ } Qs[seg] = *Q; move16(); - edct_fx(dctin32_fx, oseg_fx, segment_length2, &Qs[seg]); - Qmin = s_min(Qs[seg], Qmin); + edct_fx( dctin32_fx, oseg_fx, segment_length2, &Qs[seg] ); + Qmin = s_min( Qs[seg], Qmin ); iseg_fx += segment_length2; - add(0,0); + add( 0, 0 ); oseg_fx += segment_length2; - add(0,0); + add( 0, 0 ); } sh_fx = &iseg_fx[shift - 1]; - add(0,0); - FOR (i = 0; i < segment_length4; i++) + add( 0, 0 ); + FOR( i = 0; i < segment_length4; i++ ) { - dctin32_fx[i] = L_negate(*sh_fx--); + dctin32_fx[i] = L_negate( *sh_fx-- ); move32(); } sh_fx = iseg_fx; sl_fx2 = &iseg_fx[segment_length2 - 1]; - add(0,0); + add( 0, 0 ); wh_fx = &win_fx[segment_length2 - 1]; - add(0,0); + add( 0, 0 ); wl_fx = win_fx; - FOR (i = segment_length4; i < segment_length2; i++) + FOR( i = segment_length4; i < segment_length2; i++ ) { - L_tmp = Mult_32_16( (*sl_fx2--), (*wl_fx++) ); /*Q+15-15=Q */ - dctin32_fx[i] = Madd_32_16(L_tmp, *sh_fx++, *wh_fx-- ); + L_tmp = Mult_32_16( ( *sl_fx2-- ), ( *wl_fx++ ) ); /*Q+15-15=Q */ + dctin32_fx[i] = Madd_32_16( L_tmp, *sh_fx++, *wh_fx-- ); move32(); /*Q */ } - Qs[NUM_TIME_SWITCHING_BLOCKS-1] = *Q; + Qs[NUM_TIME_SWITCHING_BLOCKS - 1] = *Q; move16(); - edct_fx(dctin32_fx, oseg_fx, segment_length2, &Qs[NUM_TIME_SWITCHING_BLOCKS-1]); - Qmin = s_min(Qs[NUM_TIME_SWITCHING_BLOCKS-1], Qmin); + edct_fx( dctin32_fx, oseg_fx, segment_length2, &Qs[NUM_TIME_SWITCHING_BLOCKS - 1] ); + Qmin = s_min( Qs[NUM_TIME_SWITCHING_BLOCKS - 1], Qmin ); *Q = Qmin; move16(); oseg_fx = out32_fx; - FOR ( k=0; k -#include "options.h" /* Compilation switches */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "rom_com.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "rom_com.h" /* Function prototypes */ #include "rom_dec.h" - /*--------------------------------------------------------------------------* * Local constants *--------------------------------------------------------------------------*/ -#define NUMSF 8 -#define NUMSF_M1 (NUMSF-1) -#define NUMSF_M2 (NUMSF-2) -#define NUMSF_S2 (NUMSF/2) -#define LOG2_NUMSF 3 -#define INV_NUMSF (float)0.125 +#define NUMSF 8 +#define NUMSF_M1 ( NUMSF - 1 ) +#define NUMSF_M2 ( NUMSF - 2 ) +#define NUMSF_S2 ( NUMSF / 2 ) +#define LOG2_NUMSF 3 +#define INV_NUMSF (float) 0.125 /*--------------------------------------------------------------------------* * preecho_sb() @@ -28,31 +27,31 @@ *--------------------------------------------------------------------------*/ void preecho_sb_fx( - const Word32 core_brate, /* i Q0 : core bit-rate */ - Word32 *wtda_audio_fx, /* i q_sig32 : imdct signal, used to compute imdct_mem_fx when not 24400 bps */ - Word16 q_sig32, /* i Q value for wtda_audio_fx */ - Word16 *rec_sig_fx, /* i q_sig16 : reconstructed signal, output of the imdct transform */ - Word16 q_sig16, /* i Q value for rec_sig_fx and imdct_mem_fx */ - const Word16 framelength, /* i Q0 : frame length */ - Word16 *memfilt_lb_fx, /* i/o Q0 : memory */ - Word32 *mean_prev_hb_fx, /* i/o Q0 : memory */ - Word16 *smoothmem_fx, /* i/o Q15 : memory */ - Word32 *mean_prev_fx, /* i/o Q0 : memory */ - Word32 *mean_prev_nc_fx, /* i/o Q0 : memory */ - Word16 *wmold_hb_fx, /* i/o Q15 : memory */ - Word16 *prevflag, /* i/o Q0 : flag */ - Word16 *pastpre, /* i/o Q0 : flag */ - const Word16 bwidth /* i Q0 : bandwidth */ + const Word32 core_brate, /* i Q0 : core bit-rate */ + Word32 *wtda_audio_fx, /* i q_sig32 : imdct signal, used to compute imdct_mem_fx when not 24400 bps */ + Word16 q_sig32, /* i Q value for wtda_audio_fx */ + Word16 *rec_sig_fx, /* i q_sig16 : reconstructed signal, output of the imdct transform */ + Word16 q_sig16, /* i Q value for rec_sig_fx and imdct_mem_fx */ + const Word16 framelength, /* i Q0 : frame length */ + Word16 *memfilt_lb_fx, /* i/o Q0 : memory */ + Word32 *mean_prev_hb_fx, /* i/o Q0 : memory */ + Word16 *smoothmem_fx, /* i/o Q15 : memory */ + Word32 *mean_prev_fx, /* i/o Q0 : memory */ + Word32 *mean_prev_nc_fx, /* i/o Q0 : memory */ + Word16 *wmold_hb_fx, /* i/o Q15 : memory */ + Word16 *prevflag, /* i/o Q0 : flag */ + Word16 *pastpre, /* i/o Q0 : flag */ + const Word16 bwidth /* i Q0 : bandwidth */ ) { Word16 i, j, len3xLp20; - Word16 zcr[9]; /* 0..3 (0..7): zero crossing of the 4 (8) subframes, 4..5: (8..10) zero crossing of the future subframes */ - Word16 maxnzcr[8], cntnzcr; /* max number of samples without zero crossing */ + Word16 zcr[9]; /* 0..3 (0..7): zero crossing of the 4 (8) subframes, 4..5: (8..10) zero crossing of the future subframes */ + Word16 maxnzcr[8], cntnzcr; /* max number of samples without zero crossing */ Word16 maxind, stind, stind_hb, cnt2, cnt5, adv, advmem; Word16 ind2, ind3, ind4, ind5, ind6, pluslim, ind2_m1, ind2_sfl, numsf_ind2; Word16 subframelength, subsubframelength; - Word16 *ptr_fx, *fxptr1, *fxptr2, *fxptr3, *fxptr4, *fxptr5, *fxptr6/*, *fxptr7, *fxptr8*/; + Word16 *ptr_fx, *fxptr1, *fxptr2, *fxptr3, *fxptr4, *fxptr5, *fxptr6 /*, *fxptr7, *fxptr8*/; Word32 *fx32ptr1, *fx32ptr4, *fx32ptr5, *fx32ptr6; Word16 *sptr1, *sptr2, sptr1_loc, sptr2_loc; Word16 framelength_m1; @@ -64,19 +63,19 @@ void preecho_sb_fx( Word16 subframelength_s2, subframelength_s34; Word16 tmp_fx1, tmp_fx2, tmp_fx3; Word32 tmp_fxL1, tmp_fxL2, tmp_fxL3; - Word32 es_mdct_fx[9]; /* 0..3 (0..7): energy of the 4 (8) subframes, 4..5: (8..10) energy of the future subframes */ - Word32 es_mdct_hb_fx[9]; /* 0..3 (0..7): energy of the 4 (8) subframes, 4..5: (8..10) energy of the future subframes */ + Word32 es_mdct_fx[9]; /* 0..3 (0..7): energy of the 4 (8) subframes, 4..5: (8..10) energy of the future subframes */ + Word32 es_mdct_hb_fx[9]; /* 0..3 (0..7): energy of the 4 (8) subframes, 4..5: (8..10) energy of the future subframes */ Word32 es_mdct_half_fx[9]; Word32 es_mdct_quart_fx[9]; Word32 savehalfe_fx, last2_fx, maxcrit_fx, sum_plus_es_fx, mean_plus_es_fx[65]; Word32 savehalfe_hb_fx, last2_hb_fx; Word32 plus_es_mdct_fx[64], max_es_fx, max_es_hb_fx, max_plus_es_mdct_fx; - Word16 imdct_mem_fx[L_FRAME48k]; /* memory of the imdct transform, used in the next frame */ + Word16 imdct_mem_fx[L_FRAME48k]; /* memory of the imdct transform, used in the next frame */ Word16 rec_sig_lb_fx[L_FRAME48k], rec_sig_hb_fx[L_FRAME48k]; /* 960 max frame length at 48 kHz */ Word16 min_g_fx[13], g_fx, gt_fx[13]; Word16 min_g_hb_fx[13], gt_hb_fx[13]; - Word16 preechogain_fx[L_FRAME48k +PREECHO_SMOOTH_LEN]; + Word16 preechogain_fx[L_FRAME48k + PREECHO_SMOOTH_LEN]; Word16 preechogain_hb_fx[L_FRAME48k]; Word16 pre_g_ch_tab[9]; Word32 eshbmean2_fx, eshbmean3_fx, sxyhb2_fx, sxylb3_fx; @@ -85,27 +84,27 @@ void preecho_sb_fx( Word16 fattnext_fx; Word16 oldgain_fx, oldgain_hb_fx; UWord16 tmp_u16; - Word32 mean_prev_hb_fx_loc, mean_prev_nc_fx_loc, mean_prev_fx_loc; /* */ + Word32 mean_prev_hb_fx_loc, mean_prev_nc_fx_loc, mean_prev_fx_loc; /* */ Word16 q16p1, qmemp1, qtmp; - q16p1 = add(q_sig16, 1); + q16p1 = add( q_sig16, 1 ); qmemp1 = q16p1; - IF(LE_32(core_brate, HQ_32k)) + IF( LE_32( core_brate, HQ_32k ) ) { - mean_prev_fx_loc = L_add(*mean_prev_fx, 0); + mean_prev_fx_loc = L_add( *mean_prev_fx, 0 ); #ifdef BASOP_NOGLOB - mean_prev_hb_fx_loc = L_shl_sat(*mean_prev_hb_fx, shl(q_sig16, 1)); /*Q0 to q_sig16*/ + mean_prev_hb_fx_loc = L_shl_sat( *mean_prev_hb_fx, shl( q_sig16, 1 ) ); /*Q0 to q_sig16*/ #else - mean_prev_hb_fx_loc = L_shl(*mean_prev_hb_fx, shl(q_sig16,1)); /*Q0 to q_sig16*/ + mean_prev_hb_fx_loc = L_shl( *mean_prev_hb_fx, shl( q_sig16, 1 ) ); /*Q0 to q_sig16*/ #endif - mean_prev_nc_fx_loc = L_add(*mean_prev_nc_fx, 0); - framelength_m1 = sub(framelength, 1); + mean_prev_nc_fx_loc = L_add( *mean_prev_nc_fx, 0 ); + framelength_m1 = sub( framelength, 1 ); nb_flag = 0; move16(); - if( EQ_16(bwidth, NB)) + if ( EQ_16( bwidth, NB ) ) { nb_flag = 1; move16(); @@ -116,7 +115,7 @@ void preecho_sb_fx( move16(); invsmoothlenp1_fx = 6554; move16(); - IF( EQ_16(nb_flag, 1)) + IF( EQ_16( nb_flag, 1 ) ) { limzcr = 10; move16(); @@ -126,13 +125,13 @@ void preecho_sb_fx( move16(); } - limmaxnzcr = mult(framelength, 1365); /*1/24*/ + limmaxnzcr = mult( framelength, 1365 ); /*1/24*/ num_subsubframes = 8; move16(); log2_num_subsubframes = 3; move16(); - IF( EQ_16(framelength, L_FRAME8k)) + IF( EQ_16( framelength, L_FRAME8k ) ) { num_subsubframes = 4; move16(); @@ -140,7 +139,7 @@ void preecho_sb_fx( move16(); } - len3xLp20 = mult_r(framelength, 7168); /*7*framelength/32;*/ + len3xLp20 = mult_r( framelength, 7168 ); /*7*framelength/32;*/ /* len3xLp20 = framelength/2-(short)((float)framelength*N_ZERO_MDCT/FRAME_SIZE_MS); in float*/ fxptr1 = imdct_mem_fx; @@ -150,27 +149,27 @@ void preecho_sb_fx( #ifdef BASOP_NOGLOB *fxptr1++ = negate( extract_h( L_shl_sat( *fx32ptr1--, 15 - q_sig32 ) ) ); #else - *fxptr1++ = negate(extract_h(L_shl(*fx32ptr1--,15-q_sig32))); + *fxptr1++ = negate( extract_h( L_shl( *fx32ptr1--, 15 - q_sig32 ) ) ); #endif move16(); /*convert to Word16 Q-1 with saturation (saturation not a problem here) */ } - FOR( i = 0; i < L_shr(framelength, 1); i++ ) + FOR( i = 0; i < L_shr( framelength, 1 ); i++ ) { #ifdef BASOP_NOGLOB *fxptr1++ = negate( extract_h( L_shl_sat( wtda_audio_fx[i], 15 - q_sig32 ) ) ); #else - *fxptr1++ = negate(extract_h(L_shl(wtda_audio_fx[i], 15-q_sig32))); + *fxptr1++ = negate( extract_h( L_shl( wtda_audio_fx[i], 15 - q_sig32 ) ) ); #endif move16(); /*convert to Word16 Q-1 with saturation (saturation not a problem here) */ } qmemp1 = 0; /*already in q-1*/ - subframelength = shr(framelength, LOG2_NUMSF); - subsubframelength = shr(subframelength, log2_num_subsubframes); + subframelength = shr( framelength, LOG2_NUMSF ); + subsubframelength = shr( subframelength, log2_num_subsubframes ); wmold_fx = *smoothmem_fx; move16(); - subframelength_s2 = shr(subframelength, 1); - subframelength_s34 = mult(subframelength, 24576); + subframelength_s2 = shr( subframelength, 1 ); + subframelength_s34 = mult( subframelength, 24576 ); cntnzcr = -1; move16(); @@ -179,8 +178,8 @@ void preecho_sb_fx( move16(); lim32_fx = 328; move16(); - savehalfe_fx = L_deposit_l(0); - savehalfe_hb_fx = L_deposit_l(0); + savehalfe_fx = L_deposit_l( 0 ); + savehalfe_hb_fx = L_deposit_l( 0 ); IF( *pastpre == 0 ) { @@ -199,20 +198,20 @@ void preecho_sb_fx( fxptr4 = rec_sig_fx + 2; #ifdef BASOP_NOGLOB - tmp_fxL1 = L_mult(shl_sat(*memfilt_lb_fx, q_sig16), 8192); /* *memfilt_lb_fx in q0 */ + tmp_fxL1 = L_mult( shl_sat( *memfilt_lb_fx, q_sig16 ), 8192 ); /* *memfilt_lb_fx in q0 */ #else - tmp_fxL1 = L_mult(shl(*memfilt_lb_fx, q_sig16), 8192); /* *memfilt_lb_fx in q0 */ + tmp_fxL1 = L_mult( shl( *memfilt_lb_fx, q_sig16 ), 8192 ); /* *memfilt_lb_fx in q0 */ #endif - tmp_fxL1 = L_mac(tmp_fxL1, *fxptr3, 8192); - *fxptr1 = mac_r(tmp_fxL1, *fxptr2, 16384); + tmp_fxL1 = L_mac( tmp_fxL1, *fxptr3, 8192 ); + *fxptr1 = mac_r( tmp_fxL1, *fxptr2, 16384 ); move16(); fxptr1++; - FOR(j = 2; j < framelength; j++) + FOR( j = 2; j < framelength; j++ ) { - tmp_fxL1 = L_mult(*fxptr2, 8192); - tmp_fxL1 = L_mac(tmp_fxL1, *fxptr4, 8192); - *fxptr1 = mac_r(tmp_fxL1, *fxptr3, 16384); + tmp_fxL1 = L_mult( *fxptr2, 8192 ); + tmp_fxL1 = L_mac( tmp_fxL1, *fxptr4, 8192 ); + *fxptr1 = mac_r( tmp_fxL1, *fxptr3, 16384 ); move16(); fxptr1++; fxptr2++; @@ -220,16 +219,16 @@ void preecho_sb_fx( fxptr4++; } - tmp_fxL1 = L_mult(*fxptr2, 8192); - *fxptr1 = mac_r(tmp_fxL1, *fxptr3, 16384); + tmp_fxL1 = L_mult( *fxptr2, 8192 ); + *fxptr1 = mac_r( tmp_fxL1, *fxptr3, 16384 ); move16(); fxptr1 = rec_sig_lb_fx; /*q_sig16*/ - fxptr2 = rec_sig_fx; /*q_sig16*/ + fxptr2 = rec_sig_fx; /*q_sig16*/ fxptr3 = rec_sig_hb_fx; /*q_sig16*/ - FOR(j = 0; j < framelength; j++) + FOR( j = 0; j < framelength; j++ ) { - *fxptr3 = sub(*fxptr2, *fxptr1); + *fxptr3 = sub( *fxptr2, *fxptr1 ); move16(); fxptr1++; fxptr2++; @@ -238,9 +237,9 @@ void preecho_sb_fx( fxptr2--; #ifdef BASOP_NOGLOB - *memfilt_lb_fx = shr_sat(*fxptr2, q_sig16); + *memfilt_lb_fx = shr_sat( *fxptr2, q_sig16 ); #else - *memfilt_lb_fx = shr(*fxptr2, q_sig16); + *memfilt_lb_fx = shr( *fxptr2, q_sig16 ); #endif move16(); /* *memfilt_lb_fx in q0 */ @@ -258,18 +257,18 @@ void preecho_sb_fx( fx32ptr4 = es_mdct_hb_fx; firstnzcr = 0; move16(); - FOR (j = 0; j < NUMSF; j++) /* 8 present subframes */ + FOR( j = 0; j < NUMSF; j++ ) /* 8 present subframes */ { - tmp_fx2 = sub(j, 1); + tmp_fx2 = sub( j, 1 ); #ifdef BASOP_NOGLOB tmp_fx1 = shr_sat( *fxptr2, q16p1 ); /*q-1 to avoisd saturation in energy*/ - tmp_fxL1 = L_mac0_sat(25, tmp_fx1, tmp_fx1); - tmp_fxL2 = L_mac0_sat(100, *fxptr3, *fxptr3); + tmp_fxL1 = L_mac0_sat( 25, tmp_fx1, tmp_fx1 ); + tmp_fxL2 = L_mac0_sat( 100, *fxptr3, *fxptr3 ); #else - tmp_fx1 = shr(*fxptr2, q16p1); /*q-1 to avoisd saturation in energy*/ - tmp_fxL1 = L_mac0(25, tmp_fx1, tmp_fx1); + tmp_fx1 = shr( *fxptr2, q16p1 ); /*q-1 to avoisd saturation in energy*/ + tmp_fxL1 = L_mac0( 25, tmp_fx1, tmp_fx1 ); - tmp_fxL2 = L_mac0(100, *fxptr3, *fxptr3); + tmp_fxL2 = L_mac0( 100, *fxptr3, *fxptr3 ); #endif sptr2_loc = 0; move16(); @@ -277,36 +276,36 @@ void preecho_sb_fx( fxptr2++; fxptr3++; - FOR (i = 1; i < subframelength; i++) + FOR( i = 1; i < subframelength; i++ ) { - if( EQ_16(i, subframelength_s2)) + if ( EQ_16( i, subframelength_s2 ) ) { *fx32ptr5 = tmp_fxL1; move32(); } - if( EQ_16(i, subframelength_s34)) + if ( EQ_16( i, subframelength_s34 ) ) { *fx32ptr6 = tmp_fxL1; move32(); } #ifdef BASOP_NOGLOB tmp_fx1 = shr_sat( *fxptr2, q16p1 ); /*q-1 to avoisd saturation in energy*/ - tmp_fxL1 = L_mac0_sat(tmp_fxL1, tmp_fx1, tmp_fx1); - tmp_fxL2 = L_mac0_sat(tmp_fxL2, *fxptr3, *fxptr3); + tmp_fxL1 = L_mac0_sat( tmp_fxL1, tmp_fx1, tmp_fx1 ); + tmp_fxL2 = L_mac0_sat( tmp_fxL2, *fxptr3, *fxptr3 ); #else tmp_fx1 = shr( *fxptr2, q16p1 ); /*q-1 to avoisd saturation in energy*/ - tmp_fxL1 = L_mac0(tmp_fxL1, tmp_fx1, tmp_fx1); - tmp_fxL2 = L_mac0(tmp_fxL2, *fxptr3, *fxptr3); + tmp_fxL1 = L_mac0( tmp_fxL1, tmp_fx1, tmp_fx1 ); + tmp_fxL2 = L_mac0( tmp_fxL2, *fxptr3, *fxptr3 ); #endif - cntnzcr = add(cntnzcr, 1); - IF( L_mult0(*fxptr2, *(fxptr2-1)) <= 0 ) + cntnzcr = add( cntnzcr, 1 ); + IF( L_mult0( *fxptr2, *( fxptr2 - 1 ) ) <= 0 ) { - sptr1_loc = add(sptr1_loc, 1); - sptr2_loc = s_max(sptr2_loc, cntnzcr); + sptr1_loc = add( sptr1_loc, 1 ); + sptr2_loc = s_max( sptr2_loc, cntnzcr ); test(); - if( (firstnzcr > 0) && (GT_16(cntnzcr, maxnzcr[tmp_fx2]))) + if ( ( firstnzcr > 0 ) && ( GT_16( cntnzcr, maxnzcr[tmp_fx2] ) ) ) { maxnzcr[tmp_fx2] = cntnzcr; move16(); @@ -320,11 +319,11 @@ void preecho_sb_fx( fxptr2++; fxptr3++; } - if(LT_16(j, NUMSF_M1)) + if ( LT_16( j, NUMSF_M1 ) ) { - cntnzcr = add(cntnzcr, 1); + cntnzcr = add( cntnzcr, 1 ); } - sptr2_loc = s_max(sptr2_loc, cntnzcr); + sptr2_loc = s_max( sptr2_loc, cntnzcr ); *fx32ptr4 = tmp_fxL2; move32(); fx32ptr4++; @@ -336,7 +335,7 @@ void preecho_sb_fx( sptr2++; test(); - if( (firstnzcr > 0) && (GT_16(cntnzcr, maxnzcr[tmp_fx2]))) + if ( ( firstnzcr > 0 ) && ( GT_16( cntnzcr, maxnzcr[tmp_fx2] ) ) ) { maxnzcr[tmp_fx2] = cntnzcr; move16(); @@ -347,9 +346,9 @@ void preecho_sb_fx( test(); firstnzcr = 1; move16(); - IF((LT_16(j, NUMSF_M1))&&(L_mult0(*fxptr2,*(fxptr2-1))<=0)) /* zcr between 2 subframes */ + IF( ( LT_16( j, NUMSF_M1 ) ) && ( L_mult0( *fxptr2, *( fxptr2 - 1 ) ) <= 0 ) ) /* zcr between 2 subframes */ { - sptr1_loc = add(sptr1_loc, 1); /* counts for the nexte subframe */ + sptr1_loc = add( sptr1_loc, 1 ); /* counts for the nexte subframe */ cntnzcr = -1; move16(); firstnzcr = 0; @@ -358,12 +357,12 @@ void preecho_sb_fx( *fx32ptr1 = tmp_fxL1; move32(); - if( LT_32(*fx32ptr5, L_shr(*fx32ptr1, 1))) + if ( LT_32( *fx32ptr5, L_shr( *fx32ptr1, 1 ) ) ) { #ifdef BASOP_NOGLOB - tmp_fxL1 = L_shl_sat(L_sub_sat(*fx32ptr1, *fx32ptr5),1); + tmp_fxL1 = L_shl_sat( L_sub_sat( *fx32ptr1, *fx32ptr5 ), 1 ); #else - tmp_fxL1 = L_shl(L_sub(*fx32ptr1, *fx32ptr5),1); + tmp_fxL1 = L_shl( L_sub( *fx32ptr1, *fx32ptr5 ), 1 ); #endif } *fx32ptr5 = tmp_fxL1; @@ -376,25 +375,25 @@ void preecho_sb_fx( fxptr2 = imdct_mem_fx; /* q_sig16 or q-1*/ j = NUMSF; - move16(); /* one future subframe but 96 samples (not 80) (enough with ALDO window) */ - tmp_fx1 = shr(*fxptr2, qmemp1); /* q-1 shr to avoid overflow in es_mdct_fx*/ - tmp_fxL1 = L_mac0(25, tmp_fx1, tmp_fx1); + move16(); /* one future subframe but 96 samples (not 80) (enough with ALDO window) */ + tmp_fx1 = shr( *fxptr2, qmemp1 ); /* q-1 shr to avoid overflow in es_mdct_fx*/ + tmp_fxL1 = L_mac0( 25, tmp_fx1, tmp_fx1 ); sptr1_loc = 0; move16(); fxptr2++; - tmp_fx3 = sub(len3xLp20,1); - FOR (i = 1; i < len3xLp20; i++) + tmp_fx3 = sub( len3xLp20, 1 ); + FOR( i = 1; i < len3xLp20; i++ ) { - tmp_fx1 = shr(*fxptr2, qmemp1); /*q-1 to avoisd saturation in energy*/ + tmp_fx1 = shr( *fxptr2, qmemp1 ); /*q-1 to avoisd saturation in energy*/ #ifdef BASOP_NOGLOB - tmp_fxL1 = L_mac0_sat(tmp_fxL1, tmp_fx1, tmp_fx1); + tmp_fxL1 = L_mac0_sat( tmp_fxL1, tmp_fx1, tmp_fx1 ); #else - tmp_fxL1 = L_mac0(tmp_fxL1, tmp_fx1, tmp_fx1); + tmp_fxL1 = L_mac0( tmp_fxL1, tmp_fx1, tmp_fx1 ); #endif - if(*fxptr2 **(fxptr2-1) <= 0) + if ( *fxptr2 * *( fxptr2 - 1 ) <= 0 ) { - sptr1_loc = add(sptr1_loc,1); + sptr1_loc = add( sptr1_loc, 1 ); } fxptr2++; @@ -405,56 +404,56 @@ void preecho_sb_fx( fxptr2 = imdct_mem_fx; fxptr3 = imdct_mem_fx + 1; fxptr4 = imdct_mem_fx + 2; - tmp_fxL1 = L_mult(rec_sig_fx[framelength_m1], -8192); - tmp_fxL1 = L_mac(tmp_fxL1, *fxptr3, -8192); - tmp_fx1 = mac_r(tmp_fxL1, *fxptr2, 16384); + tmp_fxL1 = L_mult( rec_sig_fx[framelength_m1], -8192 ); + tmp_fxL1 = L_mac( tmp_fxL1, *fxptr3, -8192 ); + tmp_fx1 = mac_r( tmp_fxL1, *fxptr2, 16384 ); - tmp_fxL2 = L_deposit_l(100); - tmp_fxL2 = L_mac0(tmp_fxL2, tmp_fx1, tmp_fx1); + tmp_fxL2 = L_deposit_l( 100 ); + tmp_fxL2 = L_mac0( tmp_fxL2, tmp_fx1, tmp_fx1 ); - FOR(j = 1; j < tmp_fx3; j++) /* tmp_fx3 still contains subframelength*1.2-1 */ + FOR( j = 1; j < tmp_fx3; j++ ) /* tmp_fx3 still contains subframelength*1.2-1 */ { - tmp_fxL1 = L_mult(*fxptr2, -8192); + tmp_fxL1 = L_mult( *fxptr2, -8192 ); #ifdef BASOP_NOGLOB - tmp_fxL1 = L_mac_sat(tmp_fxL1, *fxptr4, -8192); - tmp_fx1 = mac_r_sat(tmp_fxL1, *fxptr3, 16384); + tmp_fxL1 = L_mac_sat( tmp_fxL1, *fxptr4, -8192 ); + tmp_fx1 = mac_r_sat( tmp_fxL1, *fxptr3, 16384 ); - tmp_fxL2 = L_mac0_sat(tmp_fxL2, tmp_fx1, tmp_fx1); + tmp_fxL2 = L_mac0_sat( tmp_fxL2, tmp_fx1, tmp_fx1 ); #else - tmp_fxL1 = L_mac(tmp_fxL1, *fxptr4, -8192); - tmp_fx1 = mac_r(tmp_fxL1, *fxptr3, 16384); + tmp_fxL1 = L_mac( tmp_fxL1, *fxptr4, -8192 ); + tmp_fx1 = mac_r( tmp_fxL1, *fxptr3, 16384 ); - tmp_fxL2 = L_mac0(tmp_fxL2, tmp_fx1, tmp_fx1); + tmp_fxL2 = L_mac0( tmp_fxL2, tmp_fx1, tmp_fx1 ); #endif fxptr2++; fxptr3++; fxptr4++; } - tmp_fxL1 = L_mult(*fxptr2, -8192); + tmp_fxL1 = L_mult( *fxptr2, -8192 ); #ifdef BASOP_NOGLOB - tmp_fx1 = mac_r_sat(tmp_fxL1, *fxptr3, 16384); - es_mdct_hb_fx[NUMSF] = L_mac0_sat(tmp_fxL2, tmp_fx1, tmp_fx1); + tmp_fx1 = mac_r_sat( tmp_fxL1, *fxptr3, 16384 ); + es_mdct_hb_fx[NUMSF] = L_mac0_sat( tmp_fxL2, tmp_fx1, tmp_fx1 ); #else - tmp_fx1 = mac_r(tmp_fxL1, *fxptr3, 16384); - es_mdct_hb_fx[NUMSF] = L_mac0(tmp_fxL2, tmp_fx1, tmp_fx1); + tmp_fx1 = mac_r( tmp_fxL1, *fxptr3, 16384 ); + es_mdct_hb_fx[NUMSF] = L_mac0( tmp_fxL2, tmp_fx1, tmp_fx1 ); #endif move32(); - max_es_hb_fx = L_add(es_mdct_hb_fx[0], 0); /* for memorising the max energy */ - max_es_fx = L_add(es_mdct_fx[0], 0); /* for memorising the max energy */ + max_es_hb_fx = L_add( es_mdct_hb_fx[0], 0 ); /* for memorising the max energy */ + max_es_fx = L_add( es_mdct_fx[0], 0 ); /* for memorising the max energy */ maxind = 0; move16(); - FOR (i = 1; i <= NUMSF; i++) + FOR( i = 1; i <= NUMSF; i++ ) { - IF (GE_32(es_mdct_hb_fx[i], max_es_hb_fx)) /* '=' to handle the first window*/ + IF( GE_32( es_mdct_hb_fx[i], max_es_hb_fx ) ) /* '=' to handle the first window*/ { - max_es_hb_fx = L_add(es_mdct_hb_fx[i], 0); /* max energy low band, 8 present and 1 future subframes */ + max_es_hb_fx = L_add( es_mdct_hb_fx[i], 0 ); /* max energy low band, 8 present and 1 future subframes */ } - IF (GE_32(es_mdct_fx[i], max_es_fx)) /* '=' to handle the first window*/ + IF( GE_32( es_mdct_fx[i], max_es_fx ) ) /* '=' to handle the first window*/ { - max_es_fx = L_add(es_mdct_fx[i], 0); /* max energy low band, 8 present and 1 future subframes */ + max_es_fx = L_add( es_mdct_fx[i], 0 ); /* max energy low band, 8 present and 1 future subframes */ maxind = i; move16(); } @@ -464,16 +463,16 @@ void preecho_sb_fx( move16(); move16(); test(); - if( *prevflag != 0 || LT_32(max_es_fx, L_mult0(subframelength, 2500))) + if ( *prevflag != 0 || LT_32( max_es_fx, L_mult0( subframelength, 2500 ) ) ) { maxind = 0; move16(); } #ifdef BASOP_NOGLOB - if( LT_32(max_es_fx, L_shl_sat(mean_prev_fx_loc, 2)))/*OK if saturated*/ + if ( LT_32( max_es_fx, L_shl_sat( mean_prev_fx_loc, 2 ) ) ) /*OK if saturated*/ #else - if( LT_32(max_es_fx, L_shl(mean_prev_fx_loc, 2)))/*OK if saturated*/ + if ( LT_32( max_es_fx, L_shl( mean_prev_fx_loc, 2 ) ) ) /*OK if saturated*/ #endif { maxind = 0; @@ -482,32 +481,32 @@ void preecho_sb_fx( *prevflag = 0; move16(); - FOR (i = 0; i < maxind; i++) /* only subbands before max energy subband are handled */ + FOR( i = 0; i < maxind; i++ ) /* only subbands before max energy subband are handled */ { g_fx = 32767; - move16(); /* default gain */ + move16(); /* default gain */ min_g_fx[i] = 32767; move16(); min_g_hb_fx[i] = 32767; move16(); - Mpy_32_16_ss(es_mdct_half_fx[i], 328, &tmp_fxL1, &tmp_u16); /* 328 for 1/100*/ - Mpy_32_16_ss(es_mdct_half_fx[i], 3277, &tmp_fxL2, &tmp_u16); /* 3277 for 1/10*/ - Mpy_32_16_ss(es_mdct_fx[i], 5461, &tmp_fxL3, &tmp_u16); /* 5461 for 1/6*/ + Mpy_32_16_ss( es_mdct_half_fx[i], 328, &tmp_fxL1, &tmp_u16 ); /* 328 for 1/100*/ + Mpy_32_16_ss( es_mdct_half_fx[i], 3277, &tmp_fxL2, &tmp_u16 ); /* 3277 for 1/10*/ + Mpy_32_16_ss( es_mdct_fx[i], 5461, &tmp_fxL3, &tmp_u16 ); /* 5461 for 1/6*/ test(); test(); test(); - IF( ( GT_32(tmp_fxL1, L_add(mean_prev_nc_fx_loc,125000)))||/* less then 20% energy in 3/4 of the subframe -> starting onset in the last quarter */ - (( GT_32(tmp_fxL2, L_add(mean_prev_nc_fx_loc,125000))) && - ((LT_16(zcr[i], limzcr))||(LT_32(es_mdct_quart_fx[i],tmp_fxL3))))) /* already an offset, plosif, do not touch */ + IF( ( GT_32( tmp_fxL1, L_add( mean_prev_nc_fx_loc, 125000 ) ) ) || /* less then 20% energy in 3/4 of the subframe -> starting onset in the last quarter */ + ( ( GT_32( tmp_fxL2, L_add( mean_prev_nc_fx_loc, 125000 ) ) ) && + ( ( LT_16( zcr[i], limzcr ) ) || ( LT_32( es_mdct_quart_fx[i], tmp_fxL3 ) ) ) ) ) /* already an offset, plosif, do not touch */ { maxind = i; - move16(); /* no preecho reduction after the first subframe with gain 1 */ + move16(); /* no preecho reduction after the first subframe with gain 1 */ *prevflag = 1; move16(); - FOR(j = sub(i,1); j >= 0; j--) + FOR( j = sub( i, 1 ); j >= 0; j-- ) { - if (GT_32(es_mdct_fx[j], L_shr(es_mdct_fx[i],1))) + if ( GT_32( es_mdct_fx[j], L_shr( es_mdct_fx[i], 1 ) ) ) { maxind = j; move16(); @@ -516,63 +515,63 @@ void preecho_sb_fx( } ELSE { - IF (LT_32(es_mdct_fx[i], L_shr(max_es_fx, 4))) + IF( LT_32( es_mdct_fx[i], L_shr( max_es_fx, 4 ) ) ) { g_fx = lim16_fx; move16(); - cnt5 = add(cnt5,1); + cnt5 = add( cnt5, 1 ); - IF (LT_32(es_mdct_fx[i], L_shr(max_es_fx, 5))) + IF( LT_32( es_mdct_fx[i], L_shr( max_es_fx, 5 ) ) ) { g_fx = lim32_fx; move16(); - cnt2 = add(cnt2, 1); + cnt2 = add( cnt2, 1 ); } - IF(LT_32(mean_prev_fx_loc, es_mdct_fx[i])) + IF( LT_32( mean_prev_fx_loc, es_mdct_fx[i] ) ) { - tmp_fx1 = norm_l(es_mdct_fx[i]); - tmp_fxL1 = L_shl(es_mdct_fx[i], tmp_fx1); - tmp_fxL2 = L_shl(mean_prev_fx_loc, tmp_fx1); - tmp_fx1 = round_fx(tmp_fxL1); - tmp_fx2 = round_fx(tmp_fxL2); - tmp_fx3 = div_s(tmp_fx2, tmp_fx1); - min_g_fx[i] = Frac_sqrt(tmp_fx3); + tmp_fx1 = norm_l( es_mdct_fx[i] ); + tmp_fxL1 = L_shl( es_mdct_fx[i], tmp_fx1 ); + tmp_fxL2 = L_shl( mean_prev_fx_loc, tmp_fx1 ); + tmp_fx1 = round_fx( tmp_fxL1 ); + tmp_fx2 = round_fx( tmp_fxL2 ); + tmp_fx3 = div_s( tmp_fx2, tmp_fx1 ); + min_g_fx[i] = Frac_sqrt( tmp_fx3 ); move16(); } - IF(LT_32(mean_prev_hb_fx_loc, es_mdct_hb_fx[i])) + IF( LT_32( mean_prev_hb_fx_loc, es_mdct_hb_fx[i] ) ) { - tmp_fx1 = norm_l(es_mdct_hb_fx[i]); - tmp_fxL1 = L_shl(es_mdct_hb_fx[i], tmp_fx1); - tmp_fxL2 = L_shl(mean_prev_hb_fx_loc, tmp_fx1); - tmp_fx1 = round_fx(tmp_fxL1); - tmp_fx2 = round_fx(tmp_fxL2); - tmp_fx3 = div_s(tmp_fx2, tmp_fx1); - min_g_hb_fx[i] = Frac_sqrt(tmp_fx3); + tmp_fx1 = norm_l( es_mdct_hb_fx[i] ); + tmp_fxL1 = L_shl( es_mdct_hb_fx[i], tmp_fx1 ); + tmp_fxL2 = L_shl( mean_prev_hb_fx_loc, tmp_fx1 ); + tmp_fx1 = round_fx( tmp_fxL1 ); + tmp_fx2 = round_fx( tmp_fxL2 ); + tmp_fx3 = div_s( tmp_fx2, tmp_fx1 ); + min_g_hb_fx[i] = Frac_sqrt( tmp_fx3 ); move16(); } test(); - IF( (LT_16(zcr[i], limzcr/2))||(GT_16(maxnzcr[i],limmaxnzcr))) + IF( ( LT_16( zcr[i], limzcr / 2 ) ) || ( GT_16( maxnzcr[i], limmaxnzcr ) ) ) { - if(LT_16(min_g_fx[i], 32767)) /* *mean_prev < es_mdct[i]) */ + if ( LT_16( min_g_fx[i], 32767 ) ) /* *mean_prev < es_mdct[i]) */ { - mean_prev_fx_loc = L_add(es_mdct_fx[i], 0); + mean_prev_fx_loc = L_add( es_mdct_fx[i], 0 ); } min_g_fx[i] = 32767; - move16(); /* not noise-like, do not touch the amplitude, but may do in HB*/ + move16(); /* not noise-like, do not touch the amplitude, but may do in HB*/ } } ELSE { test(); - if( i > 0 && LT_16(maxind, NUMSF)) + if ( i > 0 && LT_16( maxind, NUMSF ) ) { *prevflag = 1; move16(); } maxind = i; - move16(); /* no preecho reduction after the first subframe with gain 1*/ + move16(); /* no preecho reduction after the first subframe with gain 1*/ } } gt_fx[i] = g_fx; @@ -581,7 +580,7 @@ void preecho_sb_fx( move16(); } - FOR ( i = maxind; i <= NUMSF; i++ ) /* also for the first memory subframe */ + FOR( i = maxind; i <= NUMSF; i++ ) /* also for the first memory subframe */ { gt_fx[i] = 32767; move16(); @@ -591,29 +590,28 @@ void preecho_sb_fx( move16(); min_g_hb_fx[i] = 32767; move16(); - } ind2 = 0; move16(); FOR( i = 0; i < NUMSF; i++ ) { - if( LT_16(gt_fx[i], 32767)) /*gt not yet limited by min_g*/ + if ( LT_16( gt_fx[i], 32767 ) ) /*gt not yet limited by min_g*/ { - ind2 = add(i, 1); /* first subframe with gain = 1 after last gain < 1 --> frame with the attack*/ + ind2 = add( i, 1 ); /* first subframe with gain = 1 after last gain < 1 --> frame with the attack*/ } } test(); - if( (GT_16(wmold_fx, 16384))&&(LT_16(add(cnt2,cnt5),2))) /* mini either 1 cnt2 (and so also cnt5) or 2 cnt5 */ + if ( ( GT_16( wmold_fx, 16384 ) ) && ( LT_16( add( cnt2, cnt5 ), 2 ) ) ) /* mini either 1 cnt2 (and so also cnt5) or 2 cnt5 */ { /* maxind = 0; false alarm, no echo reduction */ ind2 = 0; move16(); } - ind2_m1 = sub(ind2, 1); - ind2_sfl = i_mult(subframelength,ind2); - numsf_ind2 = sub(NUMSF, ind2); + ind2_m1 = sub( ind2, 1 ); + ind2_sfl = i_mult( subframelength, ind2 ); + numsf_ind2 = sub( NUMSF, ind2 ); fxptr3 = gt_fx; fxptr4 = gt_hb_fx; fxptr5 = min_g_fx; @@ -623,15 +621,15 @@ void preecho_sb_fx( pre_g_ch_tab[0] = smooth_len; move16(); /*1st after smoothmem*/ fxptr2 = preechogain_hb_fx; - FOR (i = 0; i < ind2; i++) /* only subbands before max energy subband are handled*/ + FOR( i = 0; i < ind2; i++ ) /* only subbands before max energy subband are handled*/ { - *fxptr3 = s_max(*fxptr3, *fxptr5); + *fxptr3 = s_max( *fxptr3, *fxptr5 ); move16(); - *fxptr4 = s_max(*fxptr4, *fxptr6); + *fxptr4 = s_max( *fxptr4, *fxptr6 ); move16(); - FOR(j = 0; j < subframelength; j++) + FOR( j = 0; j < subframelength; j++ ) { *fxptr1 = *fxptr3; move16(); @@ -640,22 +638,22 @@ void preecho_sb_fx( fxptr1++; fxptr2++; } - pre_g_ch_tab[add(i, 1)] = add(pre_g_ch_tab[i], subframelength); + pre_g_ch_tab[add( i, 1 )] = add( pre_g_ch_tab[i], subframelength ); fxptr3++; fxptr4++; fxptr5++; fxptr6++; } - max_plus_es_mdct_fx = L_deposit_l(0); + max_plus_es_mdct_fx = L_deposit_l( 0 ); adv = smooth_len; - move16(); /* samples needed to have near 1 gain after smoothing at the beggining of the attack subframe*/ + move16(); /* samples needed to have near 1 gain after smoothing at the beggining of the attack subframe*/ advmem = adv; move16(); test(); test(); - IF( ind2 > 0 || LT_16(wmold_fx, 32767)||LT_16(*wmold_hb_fx,32767)) + IF( ind2 > 0 || LT_16( wmold_fx, 32767 ) || LT_16( *wmold_hb_fx, 32767 ) ) { ptr_fx = imdct_mem_fx; qtmp = qmemp1; @@ -663,15 +661,15 @@ void preecho_sb_fx( move16(); /* if ind2 == NUMSF */ IF( numsf_ind2 > 0 ) { - ptr_fx = rec_sig_fx + ind2_sfl; + ptr_fx = rec_sig_fx + ind2_sfl; qtmp = q16p1; - pluslim = i_mult(numsf_ind2, num_subsubframes); + pluslim = i_mult( numsf_ind2, num_subsubframes ); } - maxcrit_fx = L_add(mean_prev_nc_fx_loc, 0); + maxcrit_fx = L_add( mean_prev_nc_fx_loc, 0 ); IF( ind2 == 0 ) { - sum_plus_es_fx = L_add(mean_prev_nc_fx_loc, 0); /* 8 times mean sususb enenrgy (=maxcrit)*/ + sum_plus_es_fx = L_add( mean_prev_nc_fx_loc, 0 ); /* 8 times mean sususb enenrgy (=maxcrit)*/ pluslim = num_subsubframes; move16(); oldgain_fx = wmold_fx; @@ -688,26 +686,26 @@ void preecho_sb_fx( oldgain_hb_fx = gt_hb_fx[ind2_m1]; move16(); - tmp_fx1 = mult_r(gt_fx[ind2_m1], gt_fx[ind2_m1]); - Mpy_32_16_ss(es_mdct_fx[ind2_m1], tmp_fx1, &maxcrit_fx, &tmp_u16); - Mpy_32_16_ss(max_es_fx, 410, &tmp_fxL1, &tmp_u16); /* 410 for 1/80*/ + tmp_fx1 = mult_r( gt_fx[ind2_m1], gt_fx[ind2_m1] ); + Mpy_32_16_ss( es_mdct_fx[ind2_m1], tmp_fx1, &maxcrit_fx, &tmp_u16 ); + Mpy_32_16_ss( max_es_fx, 410, &tmp_fxL1, &tmp_u16 ); /* 410 for 1/80*/ test(); - if( (GT_32(tmp_fxL1, maxcrit_fx))&&(GT_16(zcr[ind2],limzcr))) + if ( ( GT_32( tmp_fxL1, maxcrit_fx ) ) && ( GT_16( zcr[ind2], limzcr ) ) ) { - maxcrit_fx = L_add(tmp_fxL1, 0); /* still 10 times smaller then mean max_es*/ + maxcrit_fx = L_add( tmp_fxL1, 0 ); /* still 10 times smaller then mean max_es*/ } } fx32ptr1 = plus_es_mdct_fx; fx32ptr4 = mean_plus_es_fx + 1; - FOR (j = 0; j < pluslim; j++) /* 8 sub-subframes */ + FOR( j = 0; j < pluslim; j++ ) /* 8 sub-subframes */ { tmp_fxL1 = 100; move16(); - FOR (i = 0; i < subsubframelength; i++) + FOR( i = 0; i < subsubframelength; i++ ) { - tmp_fx1 = shr(*ptr_fx, qtmp); /* q-1, to have same shift as es_mdct_.. */ + tmp_fx1 = shr( *ptr_fx, qtmp ); /* q-1, to have same shift as es_mdct_.. */ #ifdef BASOP_NOGLOB tmp_fxL1 = L_mac0_sat( tmp_fxL1, tmp_fx1, tmp_fx1 ); #else @@ -715,20 +713,20 @@ void preecho_sb_fx( #endif ptr_fx++; } - if( GT_32(tmp_fxL1, max_plus_es_mdct_fx)) + if ( GT_32( tmp_fxL1, max_plus_es_mdct_fx ) ) { - max_plus_es_mdct_fx = L_add(tmp_fxL1, 0); + max_plus_es_mdct_fx = L_add( tmp_fxL1, 0 ); } #ifdef BASOP_NOGLOB - sum_plus_es_fx = L_add_sat(sum_plus_es_fx, L_shl_sat(tmp_fxL1, 2)); + sum_plus_es_fx = L_add_sat( sum_plus_es_fx, L_shl_sat( tmp_fxL1, 2 ) ); #else - sum_plus_es_fx = L_add(sum_plus_es_fx, L_shl(tmp_fxL1, 2)); + sum_plus_es_fx = L_add( sum_plus_es_fx, L_shl( tmp_fxL1, 2 ) ); #endif *fx32ptr1 = tmp_fxL1; fx32ptr1++; - Mpy_32_16_ss(sum_plus_es_fx, inv_jp2[j], fx32ptr4, &tmp_u16); /* 410 for 1/80*/ - if( LT_32(*fx32ptr4, maxcrit_fx)) + Mpy_32_16_ss( sum_plus_es_fx, inv_jp2[j], fx32ptr4, &tmp_u16 ); /* 410 for 1/80*/ + if ( LT_32( *fx32ptr4, maxcrit_fx ) ) { *fx32ptr4 = maxcrit_fx; move32(); @@ -739,7 +737,7 @@ void preecho_sb_fx( move32(); /*mean_plus_es_fx[pluslim] = -1; */ *mean_plus_es_fx = *plus_es_mdct_fx; move32(); /* index [0] */ - if( LT_32(*mean_plus_es_fx, maxcrit_fx)) + if ( LT_32( *mean_plus_es_fx, maxcrit_fx ) ) { *mean_plus_es_fx = maxcrit_fx; move32(); @@ -747,52 +745,52 @@ void preecho_sb_fx( j = 0; move16(); - WHILE((LT_32(plus_es_mdct_fx[j], mean_plus_es_fx[j]))&&(LT_32(plus_es_mdct_fx[j],max_plus_es_mdct_fx/8))) + WHILE( ( LT_32( plus_es_mdct_fx[j], mean_plus_es_fx[j] ) ) && ( LT_32( plus_es_mdct_fx[j], max_plus_es_mdct_fx / 8 ) ) ) { test(); - j = add(j,1); + j = add( j, 1 ); } - tmp_fx3 = i_mult(j,subsubframelength); - adv = sub(adv, tmp_fx3); - IF( numsf_ind2 > 0 ) /* onset not in future frame */ + tmp_fx3 = i_mult( j, subsubframelength ); + adv = sub( adv, tmp_fx3 ); + IF( numsf_ind2 > 0 ) /* onset not in future frame */ { - fxptr1 = preechogain_fx + ind2_sfl+smooth_len; + fxptr1 = preechogain_fx + ind2_sfl + smooth_len; fxptr2 = preechogain_hb_fx + ind2_sfl; - FOR (i = 0; i < tmp_fx3; i++) + FOR( i = 0; i < tmp_fx3; i++ ) { *fxptr1 = oldgain_fx; - move16(); /*keep the gain of the previous subframe*/ + move16(); /*keep the gain of the previous subframe*/ *fxptr2 = oldgain_hb_fx; - move16(); /*keep the gain of the previous subframe*/ + move16(); /*keep the gain of the previous subframe*/ fxptr1++; fxptr2++; } } } - IF(ind2>0) + IF( ind2 > 0 ) { /* check increasing energy of preecho by regression last 3 subframes (if possible) */ - ind3 = add(ind2, shr(j, log2_num_subsubframes)); /* return (with rounding) to subframe basis */ - ind4 = sub(ind3, 1); - ind5 = sub(ind3, 2); - ind6 = sub(ind3, 3); + ind3 = add( ind2, shr( j, log2_num_subsubframes ) ); /* return (with rounding) to subframe basis */ + ind4 = sub( ind3, 1 ); + ind5 = sub( ind3, 2 ); + ind6 = sub( ind3, 3 ); IF( ind4 > 0 ) { /* case of 3 points is simply */ - eshbmean2_fx = L_add(es_mdct_hb_fx[ind4], es_mdct_hb_fx[ind5]); + eshbmean2_fx = L_add( es_mdct_hb_fx[ind4], es_mdct_hb_fx[ind5] ); - sxyhb2_fx = L_sub(es_mdct_hb_fx[ind4], es_mdct_hb_fx[ind5]); /* / eshbmean2 * 2; 04042013: division not needed, only sign of sxyhb2 is used*/ + sxyhb2_fx = L_sub( es_mdct_hb_fx[ind4], es_mdct_hb_fx[ind5] ); /* / eshbmean2 * 2; 04042013: division not needed, only sign of sxyhb2 is used*/ - IF( GT_16(ind3, 2)) + IF( GT_16( ind3, 2 ) ) { - tmp_fxL1 = L_add(eshbmean2_fx, es_mdct_hb_fx[ind6]); - Mpy_32_16_ss(tmp_fxL1, 4369, &eshbmean3_fx, &tmp_u16); /*10922 : 1/3*/ - sxylb3_fx = L_sub(es_mdct_fx[ind4], es_mdct_fx[ind6]); /* /eslbmean3 / 2; /2 for 3 points regression calc; 04042013: division not needed, only sign of sxylb3 is used*/ - tmp_fxL1 = L_sub(es_mdct_hb_fx[ind4], es_mdct_hb_fx[ind6]); + tmp_fxL1 = L_add( eshbmean2_fx, es_mdct_hb_fx[ind6] ); + Mpy_32_16_ss( tmp_fxL1, 4369, &eshbmean3_fx, &tmp_u16 ); /*10922 : 1/3*/ + sxylb3_fx = L_sub( es_mdct_fx[ind4], es_mdct_fx[ind6] ); /* /eslbmean3 / 2; /2 for 3 points regression calc; 04042013: division not needed, only sign of sxylb3 is used*/ + tmp_fxL1 = L_sub( es_mdct_hb_fx[ind4], es_mdct_hb_fx[ind6] ); test(); - IF ((LT_32(tmp_fxL1, eshbmean3_fx))||(sxylb3_fx<0)) + IF( ( LT_32( tmp_fxL1, eshbmean3_fx ) ) || ( sxylb3_fx < 0 ) ) { ind2 = 0; move16(); @@ -804,22 +802,22 @@ void preecho_sb_fx( } ELSE { - IF (sxyhb2_fx < 0) + IF( sxyhb2_fx < 0 ) { ind2 = 0; move16(); ind2_sfl = 0; move16(); adv = advmem; - move16();/* 04042013: small bug corection*/ + move16(); /* 04042013: small bug corection*/ } } - tmp_fxL1 = L_add(eshbmean2_fx, es_mdct_hb_fx[ind3]); - Mpy_32_16_ss(tmp_fxL1, 4369, &eshbmean3_fx, &tmp_u16); /*10922 : 1/3*/ + tmp_fxL1 = L_add( eshbmean2_fx, es_mdct_hb_fx[ind3] ); + Mpy_32_16_ss( tmp_fxL1, 4369, &eshbmean3_fx, &tmp_u16 ); /*10922 : 1/3*/ - tmp_fxL1 = L_sub(es_mdct_hb_fx[ind3], es_mdct_hb_fx[ind5]); - IF (LT_32(tmp_fxL1, eshbmean3_fx)) + tmp_fxL1 = L_sub( es_mdct_hb_fx[ind3], es_mdct_hb_fx[ind5] ); + IF( LT_32( tmp_fxL1, eshbmean3_fx ) ) { ind2 = 0; move16(); @@ -831,80 +829,80 @@ void preecho_sb_fx( } } - ind2_m1 = sub(ind2, 1);/*ind2_m1 needs to be recomputed as ind2 could have changed since*/ + ind2_m1 = sub( ind2, 1 ); /*ind2_m1 needs to be recomputed as ind2 could have changed since*/ - stind = sub(ind2_sfl, adv); - stind_hb = add(stind, advmem); - if( stind < 0 ) + stind = sub( ind2_sfl, adv ); + stind_hb = add( stind, advmem ); + if ( stind < 0 ) { stind = 0; move16(); } - if( stind_hb < 0 ) + if ( stind_hb < 0 ) { stind_hb = 0; move16(); } - tmp_fx1 = add(stind, smooth_len); + tmp_fx1 = add( stind, smooth_len ); fxptr1 = preechogain_fx + tmp_fx1; fxptr2 = preechogain_hb_fx + stind_hb; - FOR (i = tmp_fx1; i < framelength; i++) /* rest of the gains, without 4 (PREECHO_SMOOTH_LEN) 1 for fadeout */ + FOR( i = tmp_fx1; i < framelength; i++ ) /* rest of the gains, without 4 (PREECHO_SMOOTH_LEN) 1 for fadeout */ { - *(fxptr1++) = 32767; + *( fxptr1++ ) = 32767; move16(); } - pre_g_ch_tab[ind2] = s_min(tmp_fx1, framelength); + pre_g_ch_tab[ind2] = s_min( tmp_fx1, framelength ); move16(); - FOR (i = stind_hb; i < framelength; i++) /* rest of the gains*/ + FOR( i = stind_hb; i < framelength; i++ ) /* rest of the gains*/ { - *(fxptr2++) = 32767; + *( fxptr2++ ) = 32767; move16(); } fxptr1 = preechogain_fx; - FOR (i = 0; i < smooth_len; i++) + FOR( i = 0; i < smooth_len; i++ ) { - *(fxptr1++) = *smoothmem_fx; + *( fxptr1++ ) = *smoothmem_fx; move16(); } fattnext_fx = 32767; move16(); - if( GT_16(stind, framelength)) + if ( GT_16( stind, framelength ) ) { fattnext_fx = gt_fx[ind2_m1]; move16(); } fxptr1 = preechogain_fx + framelength; - FOR (i = 0; i < smooth_len; i++) + FOR( i = 0; i < smooth_len; i++ ) { - *(fxptr1++) = fattnext_fx; + *( fxptr1++ ) = fattnext_fx; move16(); } - FOR (i = 0; i <= ind2; i++) + FOR( i = 0; i <= ind2; i++ ) { tmp_fx1 = pre_g_ch_tab[i]; move16(); - tmp_fx2 = sub(tmp_fx1, smooth_len); /* any index in the previous subframe*/ - tmp_fx3 = mult_r(sub(preechogain_fx[tmp_fx1], preechogain_fx[tmp_fx2]), invsmoothlenp1_fx);/*step*/ + tmp_fx2 = sub( tmp_fx1, smooth_len ); /* any index in the previous subframe*/ + tmp_fx3 = mult_r( sub( preechogain_fx[tmp_fx1], preechogain_fx[tmp_fx2] ), invsmoothlenp1_fx ); /*step*/ tmp_fx1 = tmp_fx3; move16(); /*cumulated step*/ fxptr1 = preechogain_fx + tmp_fx2; - FOR(j = 0; j < smooth_len; j++) + FOR( j = 0; j < smooth_len; j++ ) { #ifdef BASOP_NOGLOB - *fxptr1 = add_sat(*fxptr1, tmp_fx1); + *fxptr1 = add_sat( *fxptr1, tmp_fx1 ); #else - *fxptr1 = add(*fxptr1, tmp_fx1); + *fxptr1 = add( *fxptr1, tmp_fx1 ); #endif move16(); - tmp_fx1 = add(tmp_fx1, tmp_fx3); + tmp_fx1 = add( tmp_fx1, tmp_fx3 ); fxptr1++; } } @@ -920,10 +918,10 @@ void preecho_sb_fx( fxptr3 = rec_sig_fx; fxptr4 = rec_sig_lb_fx; fxptr5 = rec_sig_hb_fx; - FOR (i = 0; i < framelength; i++) + FOR( i = 0; i < framelength; i++ ) { - tmp_fxL1 = L_mult(*fxptr4, *fxptr1); - *fxptr3 = mac_r(tmp_fxL1, *fxptr5, *fxptr2); + tmp_fxL1 = L_mult( *fxptr4, *fxptr1 ); + *fxptr3 = mac_r( tmp_fxL1, *fxptr5, *fxptr2 ); move16(); fxptr1++; fxptr2++; @@ -932,90 +930,89 @@ void preecho_sb_fx( fxptr5++; } - mean_prev_nc_fx_loc = L_add(es_mdct_fx[0], 0); /* compute mean not corrected by the actual gains*/ + mean_prev_nc_fx_loc = L_add( es_mdct_fx[0], 0 ); /* compute mean not corrected by the actual gains*/ - FOR (i = 1; i < NUMSF; i++) /* all present subbands */ + FOR( i = 1; i < NUMSF; i++ ) /* all present subbands */ { - if( EQ_16(i, NUMSF_S2)) + if ( EQ_16( i, NUMSF_S2 ) ) { - savehalfe_fx = L_add(mean_prev_nc_fx_loc, 0); + savehalfe_fx = L_add( mean_prev_nc_fx_loc, 0 ); } #ifdef BASOP_NOGLOB - mean_prev_nc_fx_loc = L_add_sat(mean_prev_nc_fx_loc, es_mdct_fx[i]); + mean_prev_nc_fx_loc = L_add_sat( mean_prev_nc_fx_loc, es_mdct_fx[i] ); #else - mean_prev_nc_fx_loc = L_add(mean_prev_nc_fx_loc, es_mdct_fx[i]); + mean_prev_nc_fx_loc = L_add( mean_prev_nc_fx_loc, es_mdct_fx[i] ); #endif } - if( LT_32(savehalfe_fx, L_shr(mean_prev_nc_fx_loc,1) )) + if ( LT_32( savehalfe_fx, L_shr( mean_prev_nc_fx_loc, 1 ) ) ) { #ifdef BASOP_NOGLOB - mean_prev_nc_fx_loc = L_shl_sat(L_sub_sat(mean_prev_nc_fx_loc, savehalfe_fx), 1); + mean_prev_nc_fx_loc = L_shl_sat( L_sub_sat( mean_prev_nc_fx_loc, savehalfe_fx ), 1 ); #else - mean_prev_nc_fx_loc = L_shl(L_sub(mean_prev_nc_fx_loc, savehalfe_fx), 1); + mean_prev_nc_fx_loc = L_shl( L_sub( mean_prev_nc_fx_loc, savehalfe_fx ), 1 ); #endif } - mean_prev_nc_fx_loc = L_shr(mean_prev_nc_fx_loc, 3); /* >> LOG2_NUMSF in fixpoint */ + mean_prev_nc_fx_loc = L_shr( mean_prev_nc_fx_loc, 3 ); /* >> LOG2_NUMSF in fixpoint */ - FOR( i = 0; i < ind2; i++ ) /* only subbands before max energy subband are handled*/ + FOR( i = 0; i < ind2; i++ ) /* only subbands before max energy subband are handled*/ { - tmp_fx1 = mult_r(gt_fx[i], gt_fx[i]); - Mpy_32_16_ss(es_mdct_fx[i], tmp_fx1, &es_mdct_fx[i], &tmp_u16); - - tmp_fx1 = mult_r(gt_hb_fx[i], gt_hb_fx[i]); - Mpy_32_16_ss(es_mdct_hb_fx[i], tmp_fx1, &es_mdct_hb_fx[i], &tmp_u16); + tmp_fx1 = mult_r( gt_fx[i], gt_fx[i] ); + Mpy_32_16_ss( es_mdct_fx[i], tmp_fx1, &es_mdct_fx[i], &tmp_u16 ); + tmp_fx1 = mult_r( gt_hb_fx[i], gt_hb_fx[i] ); + Mpy_32_16_ss( es_mdct_hb_fx[i], tmp_fx1, &es_mdct_hb_fx[i], &tmp_u16 ); } - mean_prev_fx_loc = L_shr(es_mdct_fx[0],3); /* compute mean used in next frame to limit gain*/ - mean_prev_hb_fx_loc = L_shr(es_mdct_hb_fx[0],3); /* compute mean used in next frame to limit gain*/ + mean_prev_fx_loc = L_shr( es_mdct_fx[0], 3 ); /* compute mean used in next frame to limit gain*/ + mean_prev_hb_fx_loc = L_shr( es_mdct_hb_fx[0], 3 ); /* compute mean used in next frame to limit gain*/ - FOR (i = 1; i < NUMSF; i++) /* all present subbands */ + FOR( i = 1; i < NUMSF; i++ ) /* all present subbands */ { - IF(EQ_16(i, NUMSF_S2)) + IF( EQ_16( i, NUMSF_S2 ) ) { - savehalfe_fx = L_add(mean_prev_fx_loc, 0); - savehalfe_hb_fx = L_add(mean_prev_hb_fx_loc, 0); + savehalfe_fx = L_add( mean_prev_fx_loc, 0 ); + savehalfe_hb_fx = L_add( mean_prev_hb_fx_loc, 0 ); } - mean_prev_fx_loc = L_add(mean_prev_fx_loc, L_shr(es_mdct_fx[i], 3)); - mean_prev_hb_fx_loc = L_add(mean_prev_hb_fx_loc, L_shr(es_mdct_hb_fx[i], 3)); + mean_prev_fx_loc = L_add( mean_prev_fx_loc, L_shr( es_mdct_fx[i], 3 ) ); + mean_prev_hb_fx_loc = L_add( mean_prev_hb_fx_loc, L_shr( es_mdct_hb_fx[i], 3 ) ); } - tmp_fxL1 = L_sub(mean_prev_fx_loc, savehalfe_fx); - if( LT_32(savehalfe_fx, L_shr(mean_prev_fx_loc, 1) )) + tmp_fxL1 = L_sub( mean_prev_fx_loc, savehalfe_fx ); + if ( LT_32( savehalfe_fx, L_shr( mean_prev_fx_loc, 1 ) ) ) { - mean_prev_fx_loc = L_shl(tmp_fxL1, 1); + mean_prev_fx_loc = L_shl( tmp_fxL1, 1 ); } - tmp_fxL1 = L_sub(mean_prev_hb_fx_loc, savehalfe_hb_fx); - if( LT_32(savehalfe_hb_fx, L_shr(mean_prev_hb_fx_loc, 1) )) + tmp_fxL1 = L_sub( mean_prev_hb_fx_loc, savehalfe_hb_fx ); + if ( LT_32( savehalfe_hb_fx, L_shr( mean_prev_hb_fx_loc, 1 ) ) ) { - mean_prev_hb_fx_loc = L_shl(tmp_fxL1, 1); + mean_prev_hb_fx_loc = L_shl( tmp_fxL1, 1 ); } #ifdef BASOP_NOGLOB - last2_fx = L_shr(L_add_sat(es_mdct_fx[NUMSF_M1], es_mdct_fx[NUMSF_M2]), 1); - last2_hb_fx = L_shr(L_add_sat(es_mdct_hb_fx[NUMSF_M1], es_mdct_hb_fx[NUMSF_M2]), 1); + last2_fx = L_shr( L_add_sat( es_mdct_fx[NUMSF_M1], es_mdct_fx[NUMSF_M2] ), 1 ); + last2_hb_fx = L_shr( L_add_sat( es_mdct_hb_fx[NUMSF_M1], es_mdct_hb_fx[NUMSF_M2] ), 1 ); #else - last2_fx = L_shr(L_add(es_mdct_fx[NUMSF_M1], es_mdct_fx[NUMSF_M2]), 1); - last2_hb_fx = L_shr(L_add(es_mdct_hb_fx[NUMSF_M1], es_mdct_hb_fx[NUMSF_M2]), 1); + last2_fx = L_shr( L_add( es_mdct_fx[NUMSF_M1], es_mdct_fx[NUMSF_M2] ), 1 ); + last2_hb_fx = L_shr( L_add( es_mdct_hb_fx[NUMSF_M1], es_mdct_hb_fx[NUMSF_M2] ), 1 ); #endif - if( GT_32(last2_fx, mean_prev_fx_loc)) + if ( GT_32( last2_fx, mean_prev_fx_loc ) ) { - mean_prev_fx_loc = L_add(last2_fx, 0); + mean_prev_fx_loc = L_add( last2_fx, 0 ); } - if( GT_32(last2_hb_fx, mean_prev_hb_fx_loc)) + if ( GT_32( last2_hb_fx, mean_prev_hb_fx_loc ) ) { - mean_prev_hb_fx_loc = L_add(last2_hb_fx, 0); + mean_prev_hb_fx_loc = L_add( last2_hb_fx, 0 ); } *mean_prev_fx = mean_prev_fx_loc; move32(); #ifdef BASOP_NOGLOB - *mean_prev_hb_fx = L_shr_sat(mean_prev_hb_fx_loc, shl_sat(q_sig16,1)); + *mean_prev_hb_fx = L_shr_sat( mean_prev_hb_fx_loc, shl_sat( q_sig16, 1 ) ); #else - *mean_prev_hb_fx = L_shr(mean_prev_hb_fx_loc, shl(q_sig16,1)); + *mean_prev_hb_fx = L_shr( mean_prev_hb_fx_loc, shl( q_sig16, 1 ) ); #endif move32(); /*save in Q0*/ *mean_prev_nc_fx = mean_prev_nc_fx_loc; @@ -1032,13 +1029,13 @@ void preecho_sb_fx( *--------------------------------------------------------------------------*/ void Inverse_Transform( - const Word32 *in_mdct, /* i : input MDCT vector */ - Word16 *Q, /* i/o: Q value of input */ - Word32 *out, /* o : output vector */ - const Word16 is_transient, /* i : transient flag */ - const Word16 L, /* i : output frame length */ - const Word16 L_inner, /* i : length of the transform */ - const Word16 element_mode /* i : IVAS element mode */ + const Word32 *in_mdct, /* i : input MDCT vector */ + Word16 *Q, /* i/o: Q value of input */ + Word32 *out, /* o : output vector */ + const Word16 is_transient, /* i : transient flag */ + const Word16 L, /* i : output frame length */ + const Word16 L_inner, /* i : length of the transform */ + const Word16 element_mode /* i : IVAS element mode */ ) { Word16 ta, seg, tmp16; @@ -1054,45 +1051,45 @@ void Inverse_Transform( Word16 tmp, q_out; Word32 L_temp; #ifdef REMOVE_IVAS_UNUSED_PARAMETERS_WARNING - (void)(element_mode); + (void) ( element_mode ); #endif /* This value is used to right shift all vectors returned by 'iedct_short_fx()' */ /* to bring them to a scaling that is equal to the 1st 'Q' returned by the 1st */ /* call to 'iedct_short_fx()' minus these guard bits. */ -#define N_GUARD_BITS (9+1) /* 9 is enough but we put one extra bit */ +#define N_GUARD_BITS ( 9 + 1 ) /* 9 is enough but we put one extra bit */ - IF (is_transient) + IF( is_transient ) { - segment_length = shr(L, 1); - segment_length_div2 = shr(L, 2); - segment_length_div4 = shr(L, 3); + segment_length = shr( L, 1 ); + segment_length_div2 = shr( L, 2 ); + segment_length_div4 = shr( L, 3 ); - IF (EQ_16(L, L_FRAME48k)) + IF( EQ_16( L, L_FRAME48k ) ) { win = short_window_48kHz_fx; } - ELSE IF (EQ_16(L, L_FRAME32k)) + ELSE IF( EQ_16( L, L_FRAME32k ) ) { win = short_window_32kHz_fx; } - ELSE IF( EQ_16(L, L_FRAME16k)) + ELSE IF( EQ_16( L, L_FRAME16k ) ) { win = short_window_16kHz_fx; } - ELSE /* L == L_FRAME8k */ + ELSE /* L == L_FRAME8k */ { win = short_window_8kHz_fx; } - set32_fx(out_alias, 0, L); + set32_fx( out_alias, 0, L ); in_segment = in_mdct; in_segment_modif = in_mdct_modif; - tmp16 = sub(L, L_inner); + tmp16 = sub( L, L_inner ); IF( tmp16 == 0 ) { - Copy32(in_mdct, in_mdct_modif, L); + Copy32( in_mdct, in_mdct_modif, L ); } ELSE IF( tmp16 > 0 ) { @@ -1120,21 +1117,21 @@ void Inverse_Transform( *in_segment_modif++ = *in_segment++; move32(); } - in_segment += shr(sub(L_inner, L), 2); + in_segment += shr( sub( L_inner, L ), 2 ); move32(); } } out_segment = out_alias - segment_length_div4; - in_segment = in_mdct_modif; + in_segment = in_mdct_modif; tmp = *Q; /* output of 'iedct_short_fx' has up to 'output frame length'/2 # of Elements */ iedct_short_fx( in_segment, &tmp, alias, segment_length ); - IF (GT_16(tmp, N_GUARD_BITS)) + IF( GT_16( tmp, N_GUARD_BITS ) ) { - q_out = sub(tmp, N_GUARD_BITS); - tmp = sub(tmp, q_out); + q_out = sub( tmp, N_GUARD_BITS ); + tmp = sub( tmp, q_out ); } ELSE { @@ -1144,7 +1141,7 @@ void Inverse_Transform( FOR( ta = segment_length_div4; ta < segment_length_div2; ta++ ) { - out_segment[ta] = L_shr(alias[ta], tmp); + out_segment[ta] = L_shr( alias[ta], tmp ); move32(); } /* This previous loop fills the output buffer from [0..seg_len_div4-1] */ @@ -1152,61 +1149,61 @@ void Inverse_Transform( win2 = &win[segment_length_div2]; FOR( ta = segment_length_div2; ta < segment_length; ta++ ) { - out_segment[ta] = L_shr(Mult_32_16(alias[ta], *--win2), tmp); + out_segment[ta] = L_shr( Mult_32_16( alias[ta], *--win2 ), tmp ); move32(); } /* This previous loop fills the output buffer from [seg_len_div4..seg_len-seg_len_div4-1] */ out_segment += segment_length_div2; - in_segment += segment_length_div2; + in_segment += segment_length_div2; - FOR( seg = 1; seg < NUM_TIME_SWITCHING_BLOCKS-1; seg++ ) + FOR( seg = 1; seg < NUM_TIME_SWITCHING_BLOCKS - 1; seg++ ) { tmp = *Q; move16(); /* output of 'iedct_short_fx' has up to 'output frame length'/2 # of Elements */ iedct_short_fx( in_segment, &tmp, alias, segment_length ); - tmp = sub(tmp, q_out); + tmp = sub( tmp, q_out ); FOR( ta = 0; ta < segment_length_div2; ta++ ) { - out_segment[ta] = L_add(out_segment[ta], L_shr(Mult_32_16(alias[ta], *win2++), tmp)); + out_segment[ta] = L_add( out_segment[ta], L_shr( Mult_32_16( alias[ta], *win2++ ), tmp ) ); move32(); } FOR( ; ta < segment_length; ta++ ) { - out_segment[ta] = L_add(out_segment[ta], L_shr(Mult_32_16(alias[ta], *--win2), tmp)); + out_segment[ta] = L_add( out_segment[ta], L_shr( Mult_32_16( alias[ta], *--win2 ), tmp ) ); move32(); } - in_segment += segment_length_div2; + in_segment += segment_length_div2; out_segment += segment_length_div2; } tmp = *Q; move16(); iedct_short_fx( in_segment, &tmp, alias, segment_length ); - tmp = sub(tmp, q_out); + tmp = sub( tmp, q_out ); - FOR (ta = 0; ta < segment_length_div2; ta++) + FOR( ta = 0; ta < segment_length_div2; ta++ ) { - out_segment[ta] = L_add(out_segment[ta], L_shr(Mult_32_16(alias[ta], *win2++), tmp)); + out_segment[ta] = L_add( out_segment[ta], L_shr( Mult_32_16( alias[ta], *win2++ ), tmp ) ); move32(); } - seg = add(segment_length_div2, shr(segment_length_div2, 1)); /* seg = 3*segment_length/4 */ - FOR (ta = segment_length_div2; ta < seg; ta++) + seg = add( segment_length_div2, shr( segment_length_div2, 1 ) ); /* seg = 3*segment_length/4 */ + FOR( ta = segment_length_div2; ta < seg; ta++ ) { - out_segment[ta] = L_shr(alias[ta], tmp); + out_segment[ta] = L_shr( alias[ta], tmp ); move32(); } - FOR (ta = 0; ta < segment_length; ta++) + FOR( ta = 0; ta < segment_length; ta++ ) { - L_temp = L_add(out_alias[ta], 0); - out[ta] = out_alias[L-1-ta]; + L_temp = L_add( out_alias[ta], 0 ); + out[ta] = out_alias[L - 1 - ta]; move32(); - out[L-1-ta] = L_temp; + out[L - 1 - ta] = L_temp; move32(); } @@ -1215,6 +1212,6 @@ void Inverse_Transform( } ELSE { - edct_fx(in_mdct, out, L, Q); + edct_fx( in_mdct, out, L, Q ); } } diff --git a/lib_com/typedef.h b/lib_com/typedef.h index ccaf01e0d..3d86229dd 100644 --- a/lib_com/typedef.h +++ b/lib_com/typedef.h @@ -123,16 +123,16 @@ typedef int Flag; #ifdef ENH_64_BIT_OPERATOR #define Word64 long long int #endif /* #ifdef ENH_64_BIT_OPERATOR */ -#define minWord32 INT_MIN -#define maxWord32 INT_MAX -#define minUWord32 0 -#define maxUWord32 UINT_MAX +#define minWord32 INT_MIN +#define maxWord32 INT_MAX +#define minUWord32 0 +#define maxUWord32 UINT_MAX /* Definition of Word40 was missing 10/06/2013 */ -#define Word40 long long +#define Word40 long long typedef float Float32; -typedef unsigned short int UNS_Word16; /* 16 bit "register" (sw*) */ +typedef unsigned short int UNS_Word16; /* 16 bit "register" (sw*) */ #ifndef TYPEDEF_INITIALIZED #error types in typedef.h not initialized diff --git a/lib_com/typedefs.h b/lib_com/typedefs.h index c0e7645a7..ed3860391 100644 --- a/lib_com/typedefs.h +++ b/lib_com/typedefs.h @@ -9,7 +9,7 @@ History: 03 Nov 04 v2.0 Incorporation of new 32-bit / 40-bit / control - operators for the ITU-T Standard Tool Library as + operators for the ITU-T Standard Tool Library as described in Geneva, 20-30 January 2004 WP 3/16 Q10/16 TD 11 document and subsequent discussions on the wp3audio@yahoogroups.com email reflector. @@ -55,7 +55,7 @@ * OSF only defined if the current platform is an Alpha * PC only defined if the current platform is a PC * SUN only defined if the current platform is a Sun - * + * * LSBFIRST is defined if the byte order on this platform is * "least significant byte first" -> defined on DEC Alpha * and PC, undefined on Sun @@ -75,16 +75,16 @@ #define ENH_64_BIT_OPERATOR /***************************************************************************** - * DEFINITION OF CONSTANTS + * DEFINITION OF CONSTANTS *****************************************************************************/ /* ********* define char type */ typedef char Char; -typedef unsigned short int UNS_Word16; /* 16 bit "register" (sw*) */ +typedef unsigned short int UNS_Word16; /* 16 bit "register" (sw*) */ #ifdef UNS_Word16 -#pragma message ("UNS_Word16 is defined but not officially part of STL2009@") +#pragma message( "UNS_Word16 is defined but not officially part of STL2009@" ) #endif /* @@ -92,8 +92,8 @@ typedef unsigned short int UNS_Word16; /* 16 bit "register" (sw*) */ */ #if SCHAR_MAX == 127 typedef signed char Word8; -#define minWord8 SCHAR_MIN -#define maxWord8 SCHAR_MAX +#define minWord8 SCHAR_MIN +#define maxWord8 SCHAR_MAX typedef unsigned char UWord8; #define minUWord8 0 @@ -108,18 +108,18 @@ typedef unsigned char UWord8; */ #if INT_MAX == 32767 typedef int Word16; -#define minWord16 INT_MIN -#define maxWord16 INT_MAX +#define minWord16 INT_MIN +#define maxWord16 INT_MAX typedef unsigned int UWord16; -#define minUWord16 0 -#define maxUWord16 UINT_MAX +#define minUWord16 0 +#define maxUWord16 UINT_MAX #elif SHRT_MAX == 32767 typedef short Word16; -#define minWord16 SHRT_MIN -#define maxWord16 SHRT_MAX +#define minWord16 SHRT_MIN +#define maxWord16 SHRT_MAX typedef unsigned short UWord16; -#define minUWord16 0 -#define maxUWord16 USHRT_MAX +#define minUWord16 0 +#define maxUWord16 USHRT_MAX #else #error cannot find 16-bit type #endif @@ -130,25 +130,25 @@ typedef unsigned short UWord16; #endif /* #ifdef ENH_64_BIT_OPERATOR */ /* Definition of Word40 was missing 10/06/2013 */ -#define Word40 long long +#define Word40 long long /* ********* define 32 bit signed/unsigned types & constants */ #if INT_MAX == 2147483647 typedef int Word32; -#define minWord32 INT_MIN -#define maxWord32 INT_MAX +#define minWord32 INT_MIN +#define maxWord32 INT_MAX typedef unsigned int UWord32; -#define minUWord32 0 -#define maxUWord32 UINT_MAX +#define minUWord32 0 +#define maxUWord32 UINT_MAX #elif LONG_MAX == 2147483647 typedef long Word32; -#define minWord32 LONG_MIN -#define maxWord32 LONG_MAX +#define minWord32 LONG_MIN +#define maxWord32 LONG_MAX typedef unsigned long UWord32; -#define minUWord32 0 -#define maxUWord32 ULONG_MAX +#define minUWord32 0 +#define maxUWord32 ULONG_MAX #else #error cannot find 32-bit type #endif @@ -161,20 +161,21 @@ typedef unsigned long UWord32; */ #if 0 typedef float Float; -#define maxFloat FLT_MAX -#define minFloat FLT_MIN +#define maxFloat FLT_MAX +#define minFloat FLT_MIN #else typedef double Float; -#define maxFloat DBL_MAX -#define minFloat DBL_MIN +#define maxFloat DBL_MAX +#define minFloat DBL_MIN #endif /* ********* define complex type */ -typedef struct { - Float r; /* real part */ - Float i; /* imaginary part */ +typedef struct +{ + Float r; /* real part */ + Float i; /* imaginary part */ } CPX; /* @@ -187,19 +188,19 @@ typedef int Bool; /* ********* Check current platform */ -#if defined (__MSDOS__) +#if defined( __MSDOS__ ) #define PC #define PLATFORM "PC" #define LSBFIRST -#elif defined (__osf__) +#elif defined( __osf__ ) #define OSF #define PLATFORM "OSF" #define LSBFIRST -#elif defined (__sun__) || defined (__sun) +#elif defined( __sun__ ) || defined( __sun ) #define SUN #define PLATFORM "SUN" #undef LSBFIRST -#elif defined (linux) && defined (i386) +#elif defined( linux ) && defined( i386 ) #define PC #define PLATFORM "PC" #define LSBFIRST diff --git a/lib_com/vlpc_2st_com_fx.c b/lib_com/vlpc_2st_com_fx.c index 81082087c..f25e8bbf0 100644 --- a/lib_com/vlpc_2st_com_fx.c +++ b/lib_com/vlpc_2st_com_fx.c @@ -12,46 +12,46 @@ void lsf_weight_2st( - const Word16 *lsfq, /* input: quantized lsf coefficients (14Q1*1.28) */ + const Word16 *lsfq, /* input: quantized lsf coefficients (14Q1*1.28) */ Word16 *w, /* output: weighting function (0Q15*1.28) */ const Word16 mode /* input: operational mode */ ) { Word16 i; - Word16 d[M+1], weight; + Word16 d[M + 1], weight; /* compute lsf distance */ d[0] = lsfq[0]; - move16(); /*14Q1*1.28*/ - FOR (i=1; i0); */ /*w[i] = (weight * sqrt(d[i]*d[i+1])));*/ - w[i] = mult_r(weight,getSqrtWord32(L_shl(L_mult0(d[i],d[i+1]),6))); + w[i] = mult_r( weight, getSqrtWord32( L_shl( L_mult0( d[i], d[i + 1] ), 6 ) ) ); move16(); } diff --git a/lib_com/weight_a_fx.c b/lib_com/weight_a_fx.c index 73a735455..3177fea34 100644 --- a/lib_com/weight_a_fx.c +++ b/lib_com/weight_a_fx.c @@ -2,8 +2,8 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "rom_com.h" /* Static table prototypes */ +#include "options.h" /* Compilation switches */ +#include "rom_com.h" /* Static table prototypes */ #include "prot_fx1.h" #include "prot_fx2.h" #include @@ -16,20 +16,20 @@ *------------------------------------------------------------------*/ void weight_a_subfr_fx( - const Word16 nb_subfr, /* i : number of subframes */ - const Word16 *A, /* i : LP filter coefficients Q12 */ - Word16 *Aw, /* o : weighted LP filter coefficients Q12 */ - const Word16 gamma, /* i : weighting factor */ - const Word16 order /* i : order of LP filter */ + const Word16 nb_subfr, /* i : number of subframes */ + const Word16 *A, /* i : LP filter coefficients Q12 */ + Word16 *Aw, /* o : weighted LP filter coefficients Q12 */ + const Word16 gamma, /* i : weighting factor */ + const Word16 order /* i : order of LP filter */ ) { Word16 k, orderp1; /* Smoothing aka spreading aka masking envelope generation */ - orderp1 = add(order,1); - FOR (k=0; k -#include "options.h" /* Compilation switches */ +#include "options.h" /* Compilation switches */ #include "cnst.h" /* Common constants */ #include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ /*--------------------------------------------------------------------------* * sfm2mqb_fx() @@ -16,94 +16,94 @@ *--------------------------------------------------------------------------*/ static void sfm2mqb_fx( - Word16 spe[], /* i : sub-vectors */ - Word16 spe2q[], /* o : pbands */ - const Word16 nb_sfm /* i : number of norms */ + Word16 spe[], /* i : sub-vectors */ + Word16 spe2q[], /* o : pbands */ + const Word16 nb_sfm /* i : number of norms */ ) { Word16 tmp, i; /* short groups */ - spe2q[0] = add(spe[0], 3); + spe2q[0] = add( spe[0], 3 ); move16(); - spe2q[1] = add(spe[1], 3); + spe2q[1] = add( spe[1], 3 ); move16(); - spe2q[2] = add(spe[2], 3); + spe2q[2] = add( spe[2], 3 ); move16(); - spe2q[3] = add(spe[3], 3); + spe2q[3] = add( spe[3], 3 ); move16(); - spe2q[4] = add(spe[4], 3); + spe2q[4] = add( spe[4], 3 ); move16(); - spe2q[5] = add(spe[5], 3); + spe2q[5] = add( spe[5], 3 ); move16(); - spe2q[6] = add(spe[6], 3); + spe2q[6] = add( spe[6], 3 ); move16(); - spe2q[7] = add(spe[7], 3); + spe2q[7] = add( spe[7], 3 ); move16(); - spe2q[8] = add(spe[8], 3); + spe2q[8] = add( spe[8], 3 ); move16(); - spe2q[9] = add(spe[9], 3); + spe2q[9] = add( spe[9], 3 ); move16(); - spe2q[10] = add(shr(add(spe[10], spe[11]),1),4); + spe2q[10] = add( shr( add( spe[10], spe[11] ), 1 ), 4 ); move16(); - spe2q[11] = add(shr(add(spe[12], spe[13]),1),4); + spe2q[11] = add( shr( add( spe[12], spe[13] ), 1 ), 4 ); move16(); - spe2q[12] = add(shr(add(spe[14], spe[15]),1),4); + spe2q[12] = add( shr( add( spe[14], spe[15] ), 1 ), 4 ); move16(); - spe2q[13] = add(shr(add(spe[16], spe[17]),1),5); + spe2q[13] = add( shr( add( spe[16], spe[17] ), 1 ), 5 ); move16(); - spe2q[14] = add(shr(add(spe[18], spe[19]),1),5); + spe2q[14] = add( shr( add( spe[18], spe[19] ), 1 ), 5 ); move16(); tmp = 0; move16(); - FOR (i=20; i < 24; i++) + FOR( i = 20; i < 24; i++ ) { - tmp = add(tmp,spe[i]); + tmp = add( tmp, spe[i] ); } - spe2q[15] = add(mult(tmp,8192),6); + spe2q[15] = add( mult( tmp, 8192 ), 6 ); move16(); tmp = 0; move16(); - FOR (i=24; i < 27; i++) + FOR( i = 24; i < 27; i++ ) { - tmp = add(tmp,spe[i]); + tmp = add( tmp, spe[i] ); } - spe2q[16] = add(mult(tmp,10923),6); + spe2q[16] = add( mult( tmp, 10923 ), 6 ); move16(); - IF (GT_16(nb_sfm, SFM_N_STA_8k)) + IF( GT_16( nb_sfm, SFM_N_STA_8k ) ) { tmp = 0; move16(); - FOR (i=27; i < 30; i++) + FOR( i = 27; i < 30; i++ ) { - tmp = add(tmp,spe[i]); + tmp = add( tmp, spe[i] ); } - spe2q[17] = add(mult(tmp,10923),6); + spe2q[17] = add( mult( tmp, 10923 ), 6 ); move16(); - IF (GT_16(nb_sfm, SFM_N_STA_10k)) + IF( GT_16( nb_sfm, SFM_N_STA_10k ) ) { tmp = 0; move16(); - FOR (i=30; i < 35; i++) + FOR( i = 30; i < 35; i++ ) { - tmp = add(tmp,spe[i]); + tmp = add( tmp, spe[i] ); } - spe2q[18] = add(mult(tmp,6553),7); + spe2q[18] = add( mult( tmp, 6553 ), 7 ); move16(); tmp = 0; move16(); - FOR (i=35; i < 44; i++) + FOR( i = 35; i < 44; i++ ) { - tmp = add(tmp,spe[i]); + tmp = add( tmp, spe[i] ); } - spe2q[19] = add(mult(tmp,3641),8); + spe2q[19] = add( mult( tmp, 3641 ), 8 ); move16(); } } @@ -118,32 +118,32 @@ static void sfm2mqb_fx( *--------------------------------------------------------------------------*/ static void mqb2sfm_fx( - Word16 spe2q[], /* i : pbands */ - Word16 spe[], /* o : sub-vectors */ - const Word16 lnb_sfm /* i : number of norms */ + Word16 spe2q[], /* i : pbands */ + Word16 spe[], /* o : sub-vectors */ + const Word16 lnb_sfm /* i : number of norms */ ) { Word16 i; - spe[0] = spe2q[0]; + spe[0] = spe2q[0]; move16(); - spe[1] = spe2q[1]; + spe[1] = spe2q[1]; move16(); - spe[2] = spe2q[2]; + spe[2] = spe2q[2]; move16(); - spe[3] = spe2q[3]; + spe[3] = spe2q[3]; move16(); - spe[4] = spe2q[4]; + spe[4] = spe2q[4]; move16(); - spe[5] = spe2q[5]; + spe[5] = spe2q[5]; move16(); - spe[6] = spe2q[6]; + spe[6] = spe2q[6]; move16(); - spe[7] = spe2q[7]; + spe[7] = spe2q[7]; move16(); - spe[8] = spe2q[8]; + spe[8] = spe2q[8]; move16(); - spe[9] = spe2q[9]; + spe[9] = spe2q[9]; move16(); spe[10] = spe2q[10]; @@ -171,35 +171,35 @@ static void mqb2sfm_fx( spe[19] = spe2q[14]; move16(); - FOR (i=20; i < 24; i++) + FOR( i = 20; i < 24; i++ ) { spe[i] = spe2q[15]; move16(); } - FOR (i=24; i < 27; i++) + FOR( i = 24; i < 27; i++ ) { spe[i] = spe2q[16]; move16(); } - IF (GT_16(lnb_sfm, SFM_N_STA_8k)) + IF( GT_16( lnb_sfm, SFM_N_STA_8k ) ) { - FOR (i=27; i < 30; i++) + FOR( i = 27; i < 30; i++ ) { spe[i] = spe2q[17]; move16(); } - IF (GT_16(lnb_sfm, SFM_N_STA_10k)) + IF( GT_16( lnb_sfm, SFM_N_STA_10k ) ) { - FOR (i=30; i < 35; i++) + FOR( i = 30; i < 35; i++ ) { spe[i] = spe2q[18]; move16(); } - FOR (i=35; i < 44; i++) + FOR( i = 35; i < 44; i++ ) { spe[i] = spe2q[19]; move16(); @@ -217,9 +217,9 @@ static void mqb2sfm_fx( *--------------------------------------------------------------------------*/ void map_quant_weight_fx( - const Word16 normqlg2[], /* i : quantized norms */ - Word16 wnorm[], /* o : weighted norm */ - const Word16 is_transient /* i : transient flag */ + const Word16 normqlg2[], /* i : quantized norms */ + Word16 wnorm[], /* o : weighted norm */ + const Word16 is_transient /* i : transient flag */ ) { Word16 sfm; @@ -233,67 +233,67 @@ void map_quant_weight_fx( Word16 shift; Word16 sum; Word16 k; - Word16 lnb_sfm,num_map_bands; + Word16 lnb_sfm, num_map_bands; lnb_sfm = NB_SFM; move16(); num_map_bands = NUM_MAP_BANDS; move16(); - IF (is_transient != 0) + IF( is_transient != 0 ) { - FOR (sfm = 0; sfm < lnb_sfm; sfm+=4) + FOR( sfm = 0; sfm < lnb_sfm; sfm += 4 ) { sum = 0; move16(); - FOR (k=0; k < 4; k++) + FOR( k = 0; k < 4; k++ ) { - sum = add(sum,normqlg2[sfm+k]); + sum = add( sum, normqlg2[sfm + k] ); } - sum = shr(sum,2); + sum = shr( sum, 2 ); - FOR (k=0; k < 4; k++) + FOR( k = 0; k < 4; k++ ) { - spe[sfm +k] = sum; + spe[sfm + k] = sum; move16(); } } } ELSE { - FOR (sfm = 0; sfm < lnb_sfm; sfm++) + FOR( sfm = 0; sfm < lnb_sfm; sfm++ ) { spe[sfm] = normqlg2[sfm]; move16(); } } - sfm2mqb_fx(spe, spe2q, lnb_sfm); + sfm2mqb_fx( spe, spe2q, lnb_sfm ); - FOR (sfm = 0; sfm < num_map_bands; sfm++) + FOR( sfm = 0; sfm < num_map_bands; sfm++ ) { - spe2q[sfm] = sub(spe2q[sfm],10); + spe2q[sfm] = sub( spe2q[sfm], 10 ); move16(); } /* spectral smoothing */ - FOR (sfm = 1; sfm < num_map_bands; sfm++) + FOR( sfm = 1; sfm < num_map_bands; sfm++ ) { - tmp16 = sub(spe2q[sfm-1],4); - spe2q[sfm] = s_max(spe2q[sfm], tmp16); + tmp16 = sub( spe2q[sfm - 1], 4 ); + spe2q[sfm] = s_max( spe2q[sfm], tmp16 ); move16(); } - FOR (sfm = num_map_bands-2 ; sfm >= 0 ; sfm--) + FOR( sfm = num_map_bands - 2; sfm >= 0; sfm-- ) { - tmp16 = sub(spe2q[sfm+1],8); - spe2q[sfm] = s_max(spe2q[sfm], tmp16); + tmp16 = sub( spe2q[sfm + 1], 8 ); + spe2q[sfm] = s_max( spe2q[sfm], tmp16 ); move16(); } - FOR (sfm = 0; sfm < num_map_bands ; sfm++) + FOR( sfm = 0; sfm < num_map_bands; sfm++ ) { - spe2q[sfm] = s_max(spe2q[sfm], a_map[sfm]); + spe2q[sfm] = s_max( spe2q[sfm], a_map[sfm] ); move16(); } @@ -303,61 +303,59 @@ void map_quant_weight_fx( spe2q_min = MAX_16; move16(); - FOR (sfm = 0; sfm < num_map_bands ; sfm++) + FOR( sfm = 0; sfm < num_map_bands; sfm++ ) { - spe2q[sfm] = sub(sfm_width[sfm], spe2q[sfm]); + spe2q[sfm] = sub( sfm_width[sfm], spe2q[sfm] ); move16(); - spe2q_max = s_max(spe2q[sfm], spe2q_max); - spe2q_min = s_min(spe2q[sfm], spe2q_min); + spe2q_max = s_max( spe2q[sfm], spe2q_max ); + spe2q_min = s_min( spe2q[sfm], spe2q_min ); } - FOR (sfm = 0; sfm < num_map_bands ; sfm++) + FOR( sfm = 0; sfm < num_map_bands; sfm++ ) { - spe2q[sfm] = sub(spe2q[sfm], spe2q_min); + spe2q[sfm] = sub( spe2q[sfm], spe2q_min ); move16(); } - spe2q_max = sub(spe2q_max, spe2q_min); + spe2q_max = sub( spe2q_max, spe2q_min ); - norm_max = norm_s(spe2q_max); + norm_max = norm_s( spe2q_max ); - shift = sub(norm_max,13); + shift = sub( norm_max, 13 ); - FOR (sfm = 0; sfm < num_map_bands ; sfm++) + FOR( sfm = 0; sfm < num_map_bands; sfm++ ) { - spe2q[sfm] = shl(spe2q[sfm],shift); + spe2q[sfm] = shl( spe2q[sfm], shift ); move16(); } - mqb2sfm_fx(spe2q,spe,lnb_sfm); + mqb2sfm_fx( spe2q, spe, lnb_sfm ); - IF (is_transient != 0) + IF( is_transient != 0 ) { - FOR (sfm = 0; sfm < lnb_sfm; sfm+=4) + FOR( sfm = 0; sfm < lnb_sfm; sfm += 4 ) { sum = 0; move16(); - FOR (k=0; k < 4; k++) + FOR( k = 0; k < 4; k++ ) { - sum = add(sum , spe[sfm+k]); + sum = add( sum, spe[sfm + k] ); } - sum = shr(sum,2); - FOR (k=0; k < 4; k++) + sum = shr( sum, 2 ); + FOR( k = 0; k < 4; k++ ) { - spe[sfm +k] = sum; + spe[sfm + k] = sum; move16(); } } } /* modify the norms for bit-allocation */ - FOR (sfm = 0; sfm < lnb_sfm ; sfm++) + FOR( sfm = 0; sfm < lnb_sfm; sfm++ ) { - wnorm[sfm] = add(spe[sfm], normqlg2[sfm]); + wnorm[sfm] = add( spe[sfm], normqlg2[sfm] ); move16(); } return; } - - diff --git a/lib_com/wi_fx.c b/lib_com/wi_fx.c index 3ffc76834..602487f71 100644 --- a/lib_com/wi_fx.c +++ b/lib_com/wi_fx.c @@ -12,16 +12,16 @@ /*-------------------------------------------------------------------* * Local constants *-------------------------------------------------------------------*/ -#define WARP_OS_RATE 8 -#define LL 256 -#define LL_OS (WARP_OS_RATE*LL) -#define OSLENGTH 12 -#define CUTFREE_ABS_RANGE 6 -#define CUTFREE_REL_RANGE 0.25 +#define WARP_OS_RATE 8 +#define LL 256 +#define LL_OS ( WARP_OS_RATE * LL ) +#define OSLENGTH 12 +#define CUTFREE_ABS_RANGE 6 +#define CUTFREE_REL_RANGE 0.25 #define CUTFREE_ABS_RANGE_Q3 48 #define CUTFREE_REL_RANGE_Q2 1 -#define WI_THRESHLD 0.8 -#define WI_SAMPLE_THLD 20 +#define WI_THRESHLD 0.8 +#define WI_SAMPLE_THLD 20 /*#define _POLY1(x, c) ((c)[0] * (x) + (c)[1]) */ /*#define _POLY2(x, c) (_POLY1((x), (c)) * (x) + (c)[2]) */ @@ -31,42 +31,41 @@ * Local functions *--------------------------------------------------------------------*/ -static Word32 DTFS_setEngy_fx(DTFS_STRUCTURE* X_DTFS_FX, Word32 en2_fx); +static Word32 DTFS_setEngy_fx( DTFS_STRUCTURE *X_DTFS_FX, Word32 en2_fx ); /*-------------------------------------------------------------------* -* DTFS_new_fx() -* -* DTFS structure initialization. -*-------------------------------------------------------------------*/ + * DTFS_new_fx() + * + * DTFS structure initialization. + *-------------------------------------------------------------------*/ ivas_error DTFS_new_fx( - DTFS_STRUCTURE** dtfs_out -) + DTFS_STRUCTURE **dtfs_out ) { - Word16 i ; + Word16 i; - DTFS_STRUCTURE* dtfs_fx = NULL; - dtfs_fx = (DTFS_STRUCTURE *) calloc(1,sizeof(DTFS_STRUCTURE)); - //PMT("verif mem alloc") - IF (dtfs_fx == NULL) + DTFS_STRUCTURE *dtfs_fx = NULL; + dtfs_fx = (DTFS_STRUCTURE *) calloc( 1, sizeof( DTFS_STRUCTURE ) ); + // PMT("verif mem alloc") + IF( dtfs_fx == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTFS (SC-VBR) structure\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTFS (SC-VBR) structure\n" ) ); } - dtfs_fx->lag_fx = 0 ; + dtfs_fx->lag_fx = 0; move16(); - dtfs_fx->nH_fx=0; + dtfs_fx->nH_fx = 0; move16(); - dtfs_fx->nH_4kHz_fx=0; + dtfs_fx->nH_4kHz_fx = 0; move16(); - dtfs_fx->upper_cut_off_freq_of_interest_fx=3300; + dtfs_fx->upper_cut_off_freq_of_interest_fx = 3300; move16(); - dtfs_fx->upper_cut_off_freq_fx=4000; + dtfs_fx->upper_cut_off_freq_fx = 4000; move16(); dtfs_fx->Q = 0; move16(); - FOR(i=0; ia_fx[i] = 0; move16(); @@ -77,71 +76,70 @@ ivas_error DTFS_new_fx( return IVAS_ERR_OK; } /*-------------------------------------------------------------------* -* DTFS_copy_fx() -* -* Copy from one DTFS STRUCTURE to another. -*-------------------------------------------------------------------*/ + * DTFS_copy_fx() + * + * Copy from one DTFS STRUCTURE to another. + *-------------------------------------------------------------------*/ void DTFS_copy_fx( - DTFS_STRUCTURE *Xout_fx, /* o: DTFS structure */ - DTFS_STRUCTURE Xinp_fx /* i: DTFS structure */ + DTFS_STRUCTURE *Xout_fx, /* o: DTFS structure */ + DTFS_STRUCTURE Xinp_fx /* i: DTFS structure */ ) { Word16 k; - FOR(k=0; ka_fx[k]=Xinp_fx.a_fx[k]; + Xout_fx->a_fx[k] = Xinp_fx.a_fx[k]; move16(); } - FOR(k=0; kb_fx[k]=Xinp_fx.b_fx[k]; + Xout_fx->b_fx[k] = Xinp_fx.b_fx[k]; move16(); } - Xout_fx->lag_fx=Xinp_fx.lag_fx; + Xout_fx->lag_fx = Xinp_fx.lag_fx; move16(); - Xout_fx->nH_fx=Xinp_fx.nH_fx; + Xout_fx->nH_fx = Xinp_fx.nH_fx; move16(); - Xout_fx->nH_4kHz_fx=Xinp_fx.nH_4kHz_fx; + Xout_fx->nH_4kHz_fx = Xinp_fx.nH_4kHz_fx; move16(); - Xout_fx->upper_cut_off_freq_of_interest_fx=Xinp_fx.upper_cut_off_freq_of_interest_fx; + Xout_fx->upper_cut_off_freq_of_interest_fx = Xinp_fx.upper_cut_off_freq_of_interest_fx; move16(); - Xout_fx->upper_cut_off_freq_fx=Xinp_fx.upper_cut_off_freq_fx; + Xout_fx->upper_cut_off_freq_fx = Xinp_fx.upper_cut_off_freq_fx; move16(); Xout_fx->Q = Xinp_fx.Q; move16(); return; - } /*-------------------------------------------------------------------* -* DTFS_sub_fx() -* -* Subtract one DTFS STRUCTURE from another. -*-------------------------------------------------------------------*/ + * DTFS_sub_fx() + * + * Subtract one DTFS STRUCTURE from another. + *-------------------------------------------------------------------*/ void DTFS_sub_fx( - DTFS_STRUCTURE *tmp,/* o: X1 - X2 */ - DTFS_STRUCTURE X1, /* i: DTFS input 1 */ - DTFS_STRUCTURE X2 /* i: DTFS input 2 */ + DTFS_STRUCTURE *tmp, /* o: X1 - X2 */ + DTFS_STRUCTURE X1, /* i: DTFS input 1 */ + DTFS_STRUCTURE X2 /* i: DTFS input 2 */ ) { - Word16 i ,sft, tmp_loop; - sft = sub(X1.Q,X2.Q); + Word16 i, sft, tmp_loop; + sft = sub( X1.Q, X2.Q ); - IF(sft>0) + IF( sft > 0 ) { - tmp_loop = shr(X1.lag_fx,1); - FOR(i=0; i<=tmp_loop; i++) + tmp_loop = shr( X1.lag_fx, 1 ); + FOR( i = 0; i <= tmp_loop; i++ ) { - tmp->a_fx[i] = sub(shr(X1.a_fx[i],sft),X2.a_fx[i]); + tmp->a_fx[i] = sub( shr( X1.a_fx[i], sft ), X2.a_fx[i] ); move16(); - tmp->b_fx[i] = sub(shr(X1.b_fx[i],sft),X2.b_fx[i]); + tmp->b_fx[i] = sub( shr( X1.b_fx[i], sft ), X2.b_fx[i] ); move16(); } tmp->Q = X2.Q; @@ -149,26 +147,26 @@ void DTFS_sub_fx( } ELSE { - tmp_loop = shr(X1.lag_fx,1); - FOR(i=0; i<=tmp_loop; i++) + tmp_loop = shr( X1.lag_fx, 1 ); + FOR( i = 0; i <= tmp_loop; i++ ) { - tmp->a_fx[i] = sub(X1.a_fx[i],shl(X2.a_fx[i],sft)); + tmp->a_fx[i] = sub( X1.a_fx[i], shl( X2.a_fx[i], sft ) ); move16(); - tmp->b_fx[i] = sub(X1.b_fx[i],shl(X2.b_fx[i],sft)); + tmp->b_fx[i] = sub( X1.b_fx[i], shl( X2.b_fx[i], sft ) ); move16(); } tmp->Q = X1.Q; move16(); } - tmp->lag_fx = s_max(X1.lag_fx, X2.lag_fx) ; - tmp->nH_fx=s_max(X1.nH_fx,X2.nH_fx); - tmp->nH_4kHz_fx=s_max(X1.nH_4kHz_fx,X2.nH_4kHz_fx); - tmp->upper_cut_off_freq_of_interest_fx=X1.upper_cut_off_freq_of_interest_fx; + tmp->lag_fx = s_max( X1.lag_fx, X2.lag_fx ); + tmp->nH_fx = s_max( X1.nH_fx, X2.nH_fx ); + tmp->nH_4kHz_fx = s_max( X1.nH_4kHz_fx, X2.nH_4kHz_fx ); + tmp->upper_cut_off_freq_of_interest_fx = X1.upper_cut_off_freq_of_interest_fx; move16(); - tmp->upper_cut_off_freq_fx=X1.upper_cut_off_freq_fx; + tmp->upper_cut_off_freq_fx = X1.upper_cut_off_freq_fx; move16(); - return ; + return; } /*-------------------------------------------------------------------* * DTFS_fast_fs_inv() @@ -176,43 +174,44 @@ void DTFS_sub_fx( * DTFS inverse. *-------------------------------------------------------------------*/ -static void DTFS_fast_fs_inv_fx( DTFS_STRUCTURE *X_fx,Word16 *out_fx, Word16 N_fx, Word16 LOG2N) +static void DTFS_fast_fs_inv_fx( DTFS_STRUCTURE *X_fx, Word16 *out_fx, Word16 N_fx, Word16 LOG2N ) { Word16 i, M_2, N_2, s; - Word16 dbuf_fx[256+1]; + Word16 dbuf_fx[256 + 1]; - M_2=s_min(shr(X_fx->lag_fx,1),X_fx->nH_fx); + M_2 = s_min( shr( X_fx->lag_fx, 1 ), X_fx->nH_fx ); move16(); - N_2=shr(N_fx,1); - s=negate(X_fx->Q); + N_2 = shr( N_fx, 1 ); + s = negate( X_fx->Q ); - dbuf_fx[0]=X_fx->a_fx[0]; + dbuf_fx[0] = X_fx->a_fx[0]; move16(); - dbuf_fx[1]=0; + dbuf_fx[1] = 0; move16(); - FOR (i=1; i<=M_2; i++) + FOR( i = 1; i <= M_2; i++ ) { - dbuf_fx[2*i]=shl_r(X_fx->a_fx[i],s); + dbuf_fx[2 * i] = shl_r( X_fx->a_fx[i], s ); move16(); - dbuf_fx[2*i+1]=shl_r(X_fx->b_fx[i],s); + dbuf_fx[2 * i + 1] = shl_r( X_fx->b_fx[i], s ); move16(); } - FOR ( ; i 0 ) { - fshift_fx = n_fx ; + fshift_fx = n_fx; move16(); - maxcorr_fx = L_add(wcorr_fx, 0); + maxcorr_fx = L_add( wcorr_fx, 0 ); Qmaxcorr = Qcorr; move16(); } } - return fshift_fx ; + return fshift_fx; } @@ -422,16 +420,15 @@ static Word16 DTFS_alignment_weight_fx( /* CALLED FROM : TX */ /*===========================================================================*/ -Word16 DTFS_alignment_full_fx( - DTFS_STRUCTURE X1_DTFS_fx, - DTFS_STRUCTURE X2_DTFS_fx, +Word16 DTFS_alignment_full_fx( + DTFS_STRUCTURE X1_DTFS_fx, + DTFS_STRUCTURE X2_DTFS_fx, Word16 ph_offset_fx, - Word16 *S_fx, + Word16 *S_fx, Word16 *C_fx, - Word16 FR_flag -) + Word16 FR_flag ) { - Word16 temp, temp1, k, start, end, HalfLag, ab1[MAXLAG_WI], ab2[MAXLAG_WI] ; + Word16 temp, temp1, k, start, end, HalfLag, ab1[MAXLAG_WI], ab2[MAXLAG_WI]; Word16 n, fshift_fx; Word32 corr_fx, maxcorr_fx; Word16 Eshift, Adiff_fx; @@ -440,56 +437,56 @@ Word16 DTFS_alignment_full_fx( #endif /* Calculating the expected alignment shift */ - Eshift = mult_r(ph_offset_fx, shl(X2_DTFS_fx.lag_fx, 7)); /* confirmed I<2 by smv12.org, Q7 */ - find_rem((Word16)L_FRAME, shr(add(X2_DTFS_fx.lag_fx, X1_DTFS_fx.lag_fx), 1), &temp); + Eshift = mult_r( ph_offset_fx, shl( X2_DTFS_fx.lag_fx, 7 ) ); /* confirmed I<2 by smv12.org, Q7 */ + find_rem( (Word16) L_FRAME, shr( add( X2_DTFS_fx.lag_fx, X1_DTFS_fx.lag_fx ), 1 ), &temp ); #ifdef BASOP_NOGLOB temp = add_sat( shl( temp, 7 ), Eshift ); /* Q7 */ #else - temp = add(shl(temp, 7), Eshift); /* Q7 */ + temp = add( shl( temp, 7 ), Eshift ); /* Q7 */ #endif - IF (temp<0) + IF( temp < 0 ) { #ifdef BASOP_NOGLOB temp = add_sat( temp, shl_sat( X1_DTFS_fx.lag_fx, 7 ) ); /* Q7 */ #else - temp = add(temp, shl(X1_DTFS_fx.lag_fx, 7)); /* Q7 */ + temp = add( temp, shl( X1_DTFS_fx.lag_fx, 7 ) ); /* Q7 */ #endif } - find_rem(temp, shl(X1_DTFS_fx.lag_fx, 7), &Eshift); /* Q7 */ - Eshift=shl(shr(Eshift,7),1); /* Q1 but integer */ + find_rem( temp, shl( X1_DTFS_fx.lag_fx, 7 ), &Eshift ); /* Q7 */ + Eshift = shl( shr( Eshift, 7 ), 1 ); /* Q1 but integer */ - IF (GT_16(X2_DTFS_fx.lag_fx,60)) + IF( GT_16( X2_DTFS_fx.lag_fx, 60 ) ) { - Adiff_fx = shl(X2_DTFS_fx.lag_fx,1-3); /* lag_fx/8 in Q1 */ + Adiff_fx = shl( X2_DTFS_fx.lag_fx, 1 - 3 ); /* lag_fx/8 in Q1 */ } ELSE { - Adiff_fx = shl(X2_DTFS_fx.lag_fx,1-2); /* lag_fx/4 in Q1 */ + Adiff_fx = shl( X2_DTFS_fx.lag_fx, 1 - 2 ); /* lag_fx/4 in Q1 */ } - IF (X1_DTFS_fx.lag_fx < X2_DTFS_fx.lag_fx) + IF( X1_DTFS_fx.lag_fx < X2_DTFS_fx.lag_fx ) { - DTFS_zeroPadd_fx(X2_DTFS_fx.lag_fx,&X1_DTFS_fx) ; + DTFS_zeroPadd_fx( X2_DTFS_fx.lag_fx, &X1_DTFS_fx ); } - maxcorr_fx = L_add(MIN_32, 0); - HalfLag = s_min(shr(X2_DTFS_fx.lag_fx, 1),X2_DTFS_fx.nH_4kHz_fx); + maxcorr_fx = L_add( MIN_32, 0 ); + HalfLag = s_min( shr( X2_DTFS_fx.lag_fx, 1 ), X2_DTFS_fx.nH_4kHz_fx ); - FOR (k=0; k<=HalfLag; k++) + FOR( k = 0; k <= HalfLag; k++ ) { #ifdef BASOP_NOGLOB - ab1[k] = round_fx_o(L_mac_o(L_mult_o(X1_DTFS_fx.a_fx[k], X2_DTFS_fx.a_fx[k], &Overflow), X1_DTFS_fx.b_fx[k], X2_DTFS_fx.b_fx[k], &Overflow), &Overflow); /* Q(-15); */ - ab2[k] = round_fx_o(L_msu_o(L_mult_o(X1_DTFS_fx.b_fx[k], X2_DTFS_fx.a_fx[k], &Overflow), X1_DTFS_fx.a_fx[k], X2_DTFS_fx.b_fx[k], &Overflow), &Overflow); /* Q(-15); */ + ab1[k] = round_fx_o( L_mac_o( L_mult_o( X1_DTFS_fx.a_fx[k], X2_DTFS_fx.a_fx[k], &Overflow ), X1_DTFS_fx.b_fx[k], X2_DTFS_fx.b_fx[k], &Overflow ), &Overflow ); /* Q(-15); */ + ab2[k] = round_fx_o( L_msu_o( L_mult_o( X1_DTFS_fx.b_fx[k], X2_DTFS_fx.a_fx[k], &Overflow ), X1_DTFS_fx.a_fx[k], X2_DTFS_fx.b_fx[k], &Overflow ), &Overflow ); /* Q(-15); */ #else - ab1[k] = round_fx(L_mac(L_mult(X1_DTFS_fx.a_fx[k], X2_DTFS_fx.a_fx[k]), X1_DTFS_fx.b_fx[k], X2_DTFS_fx.b_fx[k])); /* Q(-15); */ - ab2[k] = round_fx(L_msu(L_mult(X1_DTFS_fx.b_fx[k], X2_DTFS_fx.a_fx[k]), X1_DTFS_fx.a_fx[k], X2_DTFS_fx.b_fx[k])); /* Q(-15); */ + ab1[k] = round_fx( L_mac( L_mult( X1_DTFS_fx.a_fx[k], X2_DTFS_fx.a_fx[k] ), X1_DTFS_fx.b_fx[k], X2_DTFS_fx.b_fx[k] ) ); /* Q(-15); */ + ab2[k] = round_fx( L_msu( L_mult( X1_DTFS_fx.b_fx[k], X2_DTFS_fx.a_fx[k] ), X1_DTFS_fx.a_fx[k], X2_DTFS_fx.b_fx[k] ) ); /* Q(-15); */ #endif } - IF (FR_flag == 0) + IF( FR_flag == 0 ) { - start=sub(Eshift, Adiff_fx); /*Q1*/ - end=add(Eshift, Adiff_fx); /*Q1*/ + start = sub( Eshift, Adiff_fx ); /*Q1*/ + end = add( Eshift, Adiff_fx ); /*Q1*/ } ELSE { @@ -498,41 +495,42 @@ Word16 DTFS_alignment_full_fx( so we set ph_offset_fx = 0, as a result we cannot accurately estimate the expected alignment shift Eshift to limit the search, so we search the full range [0 to X2_DTFS_fx.lag_fx] similar to FL */ - start=0; /*Q1*/ - end=shl(X2_DTFS_fx.lag_fx,1); /*Q1*/ + start = 0; /*Q1*/ + end = shl( X2_DTFS_fx.lag_fx, 1 ); /*Q1*/ } - fshift_fx=start; - move16(); /*Q1*/ + fshift_fx = start; + move16(); /*Q1*/ - FOR (n=start; n<=end; n++) /*n in Q1*/ + FOR( n = start; n <= end; n++ ) /*n in Q1*/ { /* Q1 */ - corr_fx = L_deposit_l(0); + corr_fx = L_deposit_l( 0 ); temp = 0; move16(); - temp1 = add(n,shl(X2_DTFS_fx.lag_fx,1)); /* add lag_fx in Q1to make positive */ - FOR (k=0; k<=HalfLag; k++) + temp1 = add( n, shl( X2_DTFS_fx.lag_fx, 1 ) ); /* add lag_fx in Q1to make positive */ + FOR( k = 0; k <= HalfLag; k++ ) { #ifdef BASOP_NOGLOB - corr_fx = L_mac_o(corr_fx, ab1[k], C_fx[(2*temp)%(4*X2_DTFS_fx.lag_fx)], &Overflow); - corr_fx = L_mac_o(corr_fx, ab2[k], S_fx[(2*temp)%(4*X2_DTFS_fx.lag_fx)], &Overflow); - temp = add_o(temp, temp1, &Overflow); + corr_fx = L_mac_o( corr_fx, ab1[k], C_fx[( 2 * temp ) % ( 4 * X2_DTFS_fx.lag_fx )], &Overflow ); + corr_fx = L_mac_o( corr_fx, ab2[k], S_fx[( 2 * temp ) % ( 4 * X2_DTFS_fx.lag_fx )], &Overflow ); + temp = add_o( temp, temp1, &Overflow ); #else - corr_fx = L_mac(corr_fx, ab1[k], C_fx[(2*temp)%(4*X2_DTFS_fx.lag_fx)]); - corr_fx = L_mac(corr_fx, ab2[k], S_fx[(2*temp)%(4*X2_DTFS_fx.lag_fx)]); - temp = add(temp, temp1); + corr_fx = L_mac( corr_fx, ab1[k], C_fx[( 2 * temp ) % ( 4 * X2_DTFS_fx.lag_fx )] ); + corr_fx = L_mac( corr_fx, ab2[k], S_fx[( 2 * temp ) % ( 4 * X2_DTFS_fx.lag_fx )] ); + temp = add( temp, temp1 ); #endif } - if (GT_32(corr_fx, maxcorr_fx)) + if ( GT_32( corr_fx, maxcorr_fx ) ) { - fshift_fx = n ; /* Q1 */ move16(); - maxcorr_fx = L_add(corr_fx, 0); + fshift_fx = n; /* Q1 */ + move16(); + maxcorr_fx = L_add( corr_fx, 0 ); } } - return fshift_fx ; /*Q1*/ + return fshift_fx; /*Q1*/ } /*===================================================================*/ /* FUNCTION : DTFS_phaseShift_fx () */ @@ -556,36 +554,36 @@ Word16 DTFS_alignment_full_fx( /* CALLED FROM : TX/RX */ /*===================================================================*/ -void DTFS_phaseShift_fx( DTFS_STRUCTURE *X_fx,Word16 ph, Word16 Lag, Word16 *S_fx, Word16 *C_fx) +void DTFS_phaseShift_fx( DTFS_STRUCTURE *X_fx, Word16 ph, Word16 Lag, Word16 *S_fx, Word16 *C_fx ) { - Word16 k ; + Word16 k; Word16 temp, HalfLag; Word32 L_temp, L_temp2; - L_temp2 = L_deposit_l(0); - HalfLag = s_min(shr(X_fx->lag_fx, 1),X_fx->nH_fx); + L_temp2 = L_deposit_l( 0 ); + HalfLag = s_min( shr( X_fx->lag_fx, 1 ), X_fx->nH_fx ); - IF (ph>0) + IF( ph > 0 ) { - FOR (k=0; k<=HalfLag; k++) + FOR( k = 0; k <= HalfLag; k++ ) { temp = X_fx->a_fx[k]; - L_temp = L_shr(L_temp2, 5); /* Q2 */ - X_fx->a_fx[k] = round_fx(L_msu(L_mult(temp, C_fx[L_temp%(4*Lag)]), X_fx->b_fx[k], S_fx[L_temp%(4*Lag)])) ; /* X.Q */ - X_fx->b_fx[k] = round_fx(L_mac(L_mult(X_fx->b_fx[k], C_fx[L_temp%(4*Lag)]), temp, S_fx[L_temp%(4*Lag)])) ; - L_temp2 = L_add(L_temp2, ph); + L_temp = L_shr( L_temp2, 5 ); /* Q2 */ + X_fx->a_fx[k] = round_fx( L_msu( L_mult( temp, C_fx[L_temp % ( 4 * Lag )] ), X_fx->b_fx[k], S_fx[L_temp % ( 4 * Lag )] ) ); /* X.Q */ + X_fx->b_fx[k] = round_fx( L_mac( L_mult( X_fx->b_fx[k], C_fx[L_temp % ( 4 * Lag )] ), temp, S_fx[L_temp % ( 4 * Lag )] ) ); + L_temp2 = L_add( L_temp2, ph ); } } - IF (ph<0) + IF( ph < 0 ) { - FOR (k=0; k<=HalfLag; k++) + FOR( k = 0; k <= HalfLag; k++ ) { temp = X_fx->a_fx[k]; - L_temp = L_shr(L_negate(L_temp2), 5); /* Q2 */ - X_fx->a_fx[k] = round_fx(L_mac(L_mult(temp, C_fx[L_temp%(4*Lag)]), X_fx->b_fx[k], S_fx[L_temp%(4*Lag)])) ; /* X.Q */ - X_fx->b_fx[k] = round_fx(L_msu(L_mult(X_fx->b_fx[k], C_fx[L_temp%(4*Lag)]), temp, S_fx[L_temp%(4*Lag)])) ; - L_temp2 = L_add(L_temp2, ph); + L_temp = L_shr( L_negate( L_temp2 ), 5 ); /* Q2 */ + X_fx->a_fx[k] = round_fx( L_mac( L_mult( temp, C_fx[L_temp % ( 4 * Lag )] ), X_fx->b_fx[k], S_fx[L_temp % ( 4 * Lag )] ) ); /* X.Q */ + X_fx->b_fx[k] = round_fx( L_msu( L_mult( X_fx->b_fx[k], C_fx[L_temp % ( 4 * Lag )] ), temp, S_fx[L_temp % ( 4 * Lag )] ) ); + L_temp2 = L_add( L_temp2, ph ); } } return; @@ -613,57 +611,55 @@ void DTFS_phaseShift_fx( DTFS_STRUCTURE *X_fx,Word16 ph, Word16 Lag, Word16 *S_f /* CALLED FROM : TX/RX */ /*===================================================================*/ -void Q2phaseShift_fx( +void Q2phaseShift_fx( DTFS_STRUCTURE *X_fx, - Word16 ph, - Word16 Lag, - Word16 *S_fx, - Word16 *C_fx -) + Word16 ph, + Word16 Lag, + Word16 *S_fx, + Word16 *C_fx ) { - Word16 k ; - Word16 temp, HalfLag; + Word16 k; + Word16 temp, HalfLag; Word32 temp2; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - temp2 = L_deposit_l(0); + temp2 = L_deposit_l( 0 ); - HalfLag = s_min(shr(X_fx->lag_fx, 1),X_fx->nH_fx); + HalfLag = s_min( shr( X_fx->lag_fx, 1 ), X_fx->nH_fx ); - IF (ph>0) + IF( ph > 0 ) { - FOR (k=0; k<=HalfLag; k++) + FOR( k = 0; k <= HalfLag; k++ ) { temp = X_fx->a_fx[k]; #ifdef BASOP_NOGLOB - X_fx->a_fx[k] = round_fx_o(L_msu_o(L_mult_o(temp, C_fx[temp2%(4*Lag)], &Overflow), X_fx->b_fx[k], S_fx[temp2%(4*Lag)], &Overflow), &Overflow) ; /* X.Q */ - X_fx->b_fx[k] = round_fx_o(L_mac_o(L_mult_o(X_fx->b_fx[k], C_fx[temp2%(4*Lag)], &Overflow), temp, S_fx[temp2%(4*Lag)], &Overflow), &Overflow) ; - temp2 = L_add_o(temp2, (Word32)ph, &Overflow); + X_fx->a_fx[k] = round_fx_o( L_msu_o( L_mult_o( temp, C_fx[temp2 % ( 4 * Lag )], &Overflow ), X_fx->b_fx[k], S_fx[temp2 % ( 4 * Lag )], &Overflow ), &Overflow ); /* X.Q */ + X_fx->b_fx[k] = round_fx_o( L_mac_o( L_mult_o( X_fx->b_fx[k], C_fx[temp2 % ( 4 * Lag )], &Overflow ), temp, S_fx[temp2 % ( 4 * Lag )], &Overflow ), &Overflow ); + temp2 = L_add_o( temp2, (Word32) ph, &Overflow ); #else - X_fx->a_fx[k] = round_fx(L_msu(L_mult(temp, C_fx[temp2 % (4 * Lag)]), X_fx->b_fx[k], S_fx[temp2 % (4 * Lag)])); /* X.Q */ - X_fx->b_fx[k] = round_fx(L_mac(L_mult(X_fx->b_fx[k], C_fx[temp2 % (4 * Lag)]), temp, S_fx[temp2 % (4 * Lag)])); - temp2 = L_add(temp2, (Word32)ph); + X_fx->a_fx[k] = round_fx( L_msu( L_mult( temp, C_fx[temp2 % ( 4 * Lag )] ), X_fx->b_fx[k], S_fx[temp2 % ( 4 * Lag )] ) ); /* X.Q */ + X_fx->b_fx[k] = round_fx( L_mac( L_mult( X_fx->b_fx[k], C_fx[temp2 % ( 4 * Lag )] ), temp, S_fx[temp2 % ( 4 * Lag )] ) ); + temp2 = L_add( temp2, (Word32) ph ); #endif } } - - IF (ph<0) + IF( ph < 0 ) { - FOR (k=0; k<=HalfLag; k++) + FOR( k = 0; k <= HalfLag; k++ ) { temp = X_fx->a_fx[k]; #ifdef BASOP_NOGLOB - X_fx->a_fx[k] = round_fx_o(L_mac_o(L_mult_o(temp, C_fx[temp2%(4*Lag)], &Overflow), X_fx->b_fx[k], S_fx[temp2%(4*Lag)], &Overflow), &Overflow) ; /* X.Q */ - X_fx->b_fx[k] = round_fx_o(L_msu_o(L_mult_o(X_fx->b_fx[k], C_fx[temp2%(4*Lag)], &Overflow), temp, S_fx[temp2%(4*Lag)], &Overflow), &Overflow) ; - temp2 = add_o((Word16)temp2, negate(ph), &Overflow); + X_fx->a_fx[k] = round_fx_o( L_mac_o( L_mult_o( temp, C_fx[temp2 % ( 4 * Lag )], &Overflow ), X_fx->b_fx[k], S_fx[temp2 % ( 4 * Lag )], &Overflow ), &Overflow ); /* X.Q */ + X_fx->b_fx[k] = round_fx_o( L_msu_o( L_mult_o( X_fx->b_fx[k], C_fx[temp2 % ( 4 * Lag )], &Overflow ), temp, S_fx[temp2 % ( 4 * Lag )], &Overflow ), &Overflow ); + temp2 = add_o( (Word16) temp2, negate( ph ), &Overflow ); #else - X_fx->a_fx[k] = round_fx(L_mac(L_mult(temp, C_fx[temp2%(4*Lag)]), X_fx->b_fx[k], S_fx[temp2%(4*Lag)])) ; /* X.Q */ - X_fx->b_fx[k] = round_fx(L_msu(L_mult(X_fx->b_fx[k], C_fx[temp2%(4*Lag)]), temp, S_fx[temp2%(4*Lag)])) ; - temp2 = add((Word16)temp2, negate(ph)); + X_fx->a_fx[k] = round_fx( L_mac( L_mult( temp, C_fx[temp2 % ( 4 * Lag )] ), X_fx->b_fx[k], S_fx[temp2 % ( 4 * Lag )] ) ); /* X.Q */ + X_fx->b_fx[k] = round_fx( L_msu( L_mult( X_fx->b_fx[k], C_fx[temp2 % ( 4 * Lag )] ), temp, S_fx[temp2 % ( 4 * Lag )] ) ); + temp2 = add( (Word16) temp2, negate( ph ) ); #endif } } @@ -690,37 +686,36 @@ void Q2phaseShift_fx( void DTFS_zeroPadd_fx( Word16 N_fx, - DTFS_STRUCTURE *X_fx -) + DTFS_STRUCTURE *X_fx ) { - Word16 i, start, end ,diff_fx,rem_fx; + Word16 i, start, end, diff_fx, rem_fx; - if (EQ_16(N_fx,X_fx->lag_fx)) + if ( EQ_16( N_fx, X_fx->lag_fx ) ) { - return ; + return; } - start = add(shr(X_fx->lag_fx,1), 1); - end = shr(N_fx, 1); + start = add( shr( X_fx->lag_fx, 1 ), 1 ); + end = shr( N_fx, 1 ); move16(); - FOR (i=start; i<=end; i++) + FOR( i = start; i <= end; i++ ) { - X_fx->a_fx[i]=0; + X_fx->a_fx[i] = 0; move16(); - X_fx->b_fx[i]=0; + X_fx->b_fx[i] = 0; move16(); } - X_fx->lag_fx = N_fx ; + X_fx->lag_fx = N_fx; move16(); /* recompute nH for new lag */ - diff_fx = find_rem(12800,X_fx->lag_fx,&rem_fx); - X_fx->nH_fx = find_rem(X_fx->upper_cut_off_freq_fx,diff_fx,&rem_fx); + diff_fx = find_rem( 12800, X_fx->lag_fx, &rem_fx ); + X_fx->nH_fx = find_rem( X_fx->upper_cut_off_freq_fx, diff_fx, &rem_fx ); - if(GE_16(sub(X_fx->upper_cut_off_freq_fx,shr((Word16)L_mult(diff_fx,X_fx->nH_fx),1)),diff_fx)) + if ( GE_16( sub( X_fx->upper_cut_off_freq_fx, shr( (Word16) L_mult( diff_fx, X_fx->nH_fx ), 1 ) ), diff_fx ) ) { - X_fx->nH_fx = add(X_fx->nH_fx,1); + X_fx->nH_fx = add( X_fx->nH_fx, 1 ); } } /*===================================================================*/ @@ -749,145 +744,144 @@ void DTFS_zeroPadd_fx( /* CALLED FROM : TX/RX */ /*===================================================================*/ void DTFS_to_fs_fx( - const Word16 *x, /* i : time domain signal */ - Word16 N, /* i : Length of input vector */ - DTFS_STRUCTURE *X_fx, /* o : DTFS structure with a, b, lag */ - const Word16 Fs, /* i : sampling rate */ - const Word16 FR_flag, /* i : FR flag */ + const Word16 *x, /* i : time domain signal */ + Word16 N, /* i : Length of input vector */ + DTFS_STRUCTURE *X_fx, /* o : DTFS structure with a, b, lag */ + const Word16 Fs, /* i : sampling rate */ + const Word16 FR_flag, /* i : FR flag */ Word16 *S_fx, - Word16 *C_fx -) + Word16 *C_fx ) { - Word16 n,temp,temp_neg,inv_lag,sum,diff_fx; + Word16 n, temp, temp_neg, inv_lag, sum, diff_fx; Word16 nH, k, nH_band, nH_4kHz; Word32 L_temp, Lx0; - Word32 L_a, L_b,L_tmp; + Word32 L_a, L_b, L_tmp; Word32 La[MAXLAG_WI], Lb[MAXLAG_WI], Labmax; - Word16 exp,tmp; + Word16 exp, tmp; Word32 L_tmp1; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - IF (!FR_flag) + IF( !FR_flag ) { - IF (EQ_16(Fs,16000)) + IF( EQ_16( Fs, 16000 ) ) { - X_fx->upper_cut_off_freq_of_interest_fx=4000; + X_fx->upper_cut_off_freq_of_interest_fx = 4000; move16(); - X_fx->upper_cut_off_freq_fx=6400; + X_fx->upper_cut_off_freq_fx = 6400; move16(); - X_fx->Fs_fx=INT_FS_FX; + X_fx->Fs_fx = INT_FS_FX; move16(); } - ELSE IF (EQ_16(Fs,8000)) + ELSE IF( EQ_16( Fs, 8000 ) ) { - X_fx->upper_cut_off_freq_of_interest_fx=3300; + X_fx->upper_cut_off_freq_of_interest_fx = 3300; move16(); - X_fx->upper_cut_off_freq_fx=4000; + X_fx->upper_cut_off_freq_fx = 4000; move16(); - X_fx->Fs_fx=INT_FS_FX; + X_fx->Fs_fx = INT_FS_FX; move16(); } } ELSE { - X_fx->upper_cut_off_freq_of_interest_fx=8000; + X_fx->upper_cut_off_freq_of_interest_fx = 8000; move16(); - X_fx->upper_cut_off_freq_fx=8000; + X_fx->upper_cut_off_freq_fx = 8000; move16(); - X_fx->Fs_fx=16000; + X_fx->Fs_fx = 16000; move16(); } - X_fx->lag_fx = N ; + X_fx->lag_fx = N; move16(); - exp = norm_s(X_fx->lag_fx); - tmp = div_s(shl(1,sub(14,exp)),X_fx->lag_fx); /* Q29-exp */ + exp = norm_s( X_fx->lag_fx ); + tmp = div_s( shl( 1, sub( 14, exp ) ), X_fx->lag_fx ); /* Q29-exp */ #ifdef BASOP_NOGLOB - L_tmp1 = L_mult_o(12800,tmp, &Overflow); /* Q(30-exp) */ - diff_fx = extract_h(L_shl_o(L_tmp1,sub(exp,14), &Overflow)); /* Q0 */ + L_tmp1 = L_mult_o( 12800, tmp, &Overflow ); /* Q(30-exp) */ + diff_fx = extract_h( L_shl_o( L_tmp1, sub( exp, 14 ), &Overflow ) ); /* Q0 */ #else - L_tmp1 = L_mult(12800,tmp); /* Q(30-exp) */ - diff_fx = extract_h(L_shl(L_tmp1,sub(exp,14))); /* Q0 */ + L_tmp1 = L_mult( 12800, tmp ); /* Q(30-exp) */ + diff_fx = extract_h( L_shl( L_tmp1, sub( exp, 14 ) ) ); /* Q0 */ #endif - exp = norm_s(diff_fx); - tmp = div_s(shl(1,sub(14,exp)),diff_fx); /* Q29-exp */ + exp = norm_s( diff_fx ); + tmp = div_s( shl( 1, sub( 14, exp ) ), diff_fx ); /* Q29-exp */ #ifdef BASOP_NOGLOB - L_tmp1 = L_mult_o(X_fx->upper_cut_off_freq_fx,tmp, &Overflow); /* Q(30-exp) */ - nH_band = extract_h(L_shl_o(L_tmp1,sub(exp,14), &Overflow)); /* Q0 */ + L_tmp1 = L_mult_o( X_fx->upper_cut_off_freq_fx, tmp, &Overflow ); /* Q(30-exp) */ + nH_band = extract_h( L_shl_o( L_tmp1, sub( exp, 14 ), &Overflow ) ); /* Q0 */ #else - L_tmp1 = L_mult(X_fx->upper_cut_off_freq_fx,tmp); /* Q(30-exp) */ - nH_band = extract_h(L_shl(L_tmp1,sub(exp,14))); /* Q0 */ + L_tmp1 = L_mult( X_fx->upper_cut_off_freq_fx, tmp ); /* Q(30-exp) */ + nH_band = extract_h( L_shl( L_tmp1, sub( exp, 14 ) ) ); /* Q0 */ #endif - nH_4kHz = mult(10240,(X_fx->lag_fx)); /* 4000/12800 in Q15 */ + nH_4kHz = mult( 10240, ( X_fx->lag_fx ) ); /* 4000/12800 in Q15 */ - if(GE_16(sub(X_fx->upper_cut_off_freq_fx,shr((Word16)L_mult(diff_fx,nH_band),1)),diff_fx)) + if ( GE_16( sub( X_fx->upper_cut_off_freq_fx, shr( (Word16) L_mult( diff_fx, nH_band ), 1 ) ), diff_fx ) ) { - nH_band = add(nH_band,1); + nH_band = add( nH_band, 1 ); } - if(GE_16(sub(4000,shr((Word16)L_mult(diff_fx,nH_4kHz),1)),diff_fx)) + if ( GE_16( sub( 4000, shr( (Word16) L_mult( diff_fx, nH_4kHz ), 1 ) ), diff_fx ) ) { - nH_4kHz = add(nH_4kHz,1); + nH_4kHz = add( nH_4kHz, 1 ); } /* Number of harmonics excluding the ones at 0 and at pi */ - nH = shr(sub(N,1),1); + nH = shr( sub( N, 1 ), 1 ); /* The DC component */ - X_fx->a_fx[0] = 0 ; + X_fx->a_fx[0] = 0; move16(); - X_fx->b_fx[0] = 0 ; + X_fx->b_fx[0] = 0; move16(); - exp = norm_s(N); - tmp = div_s(shl(1,(sub(14,exp))),N); + exp = norm_s( N ); + tmp = div_s( shl( 1, ( sub( 14, exp ) ) ), N ); #ifdef BASOP_NOGLOB - L_tmp = L_shl_o(tmp,add(exp,6), &Overflow); - inv_lag = round_fx_o(L_tmp, &Overflow); + L_tmp = L_shl_o( tmp, add( exp, 6 ), &Overflow ); + inv_lag = round_fx_o( L_tmp, &Overflow ); #else - L_tmp = L_shl(tmp,add(exp,6)); - inv_lag = round_fx(L_tmp); + L_tmp = L_shl( tmp, add( exp, 6 ) ); + inv_lag = round_fx( L_tmp ); #endif - Lx0 = L_deposit_h(x[0]); - Labmax = L_deposit_l(0); - FOR ( k=1; k<=nH; k++ ) + Lx0 = L_deposit_h( x[0] ); + Labmax = L_deposit_l( 0 ); + FOR( k = 1; k <= nH; k++ ) { - L_a = L_shr(Lx0,1) ; /* Q16 */ + L_a = L_shr( Lx0, 1 ); /* Q16 */ - L_b = L_deposit_l(0); + L_b = L_deposit_l( 0 ); sum = k; move16(); temp = k; move16(); - FOR ( n=1; nb_fx[k] = 0 ; + X_fx->b_fx[k] = 0; move16(); } - temp = norm_l(Labmax); - if (Labmax==0) + temp = norm_l( Labmax ); + if ( Labmax == 0 ) { temp = 31; move16(); } - FOR ( k=1; k<=nH; k++ ) + FOR( k = 1; k <= nH; k++ ) { #ifdef BASOP_NOGLOB - X_fx->a_fx[k]=round_fx_o(L_shl_o(La[k], temp, &Overflow), &Overflow); /* Q(8+temp-16)=Q(temp-8) */ - X_fx->a_fx[k]=mult_ro(X_fx->a_fx[k], inv_lag, &Overflow); - move16(); /* Q(temp-8+19+1-16)=Q(temp-4) of a[k]*2.0/N */ - X_fx->b_fx[k]=round_fx_o(L_shl_o(Lb[k], temp, &Overflow), &Overflow); /* Q(8+temp-16)=Q(temp-8) */ - X_fx->b_fx[k]=mult_ro(X_fx->b_fx[k], inv_lag, &Overflow); - move16(); /* Q(temp-8+19+1-16)=Q(temp-4) of b[k]*2.0/N */ + X_fx->a_fx[k] = round_fx_o( L_shl_o( La[k], temp, &Overflow ), &Overflow ); /* Q(8+temp-16)=Q(temp-8) */ + X_fx->a_fx[k] = mult_ro( X_fx->a_fx[k], inv_lag, &Overflow ); + move16(); /* Q(temp-8+19+1-16)=Q(temp-4) of a[k]*2.0/N */ + X_fx->b_fx[k] = round_fx_o( L_shl_o( Lb[k], temp, &Overflow ), &Overflow ); /* Q(8+temp-16)=Q(temp-8) */ + X_fx->b_fx[k] = mult_ro( X_fx->b_fx[k], inv_lag, &Overflow ); + move16(); /* Q(temp-8+19+1-16)=Q(temp-4) of b[k]*2.0/N */ #else - X_fx->a_fx[k]=round_fx(L_shl(La[k], temp)); /* Q(8+temp-16)=Q(temp-8) */ - X_fx->a_fx[k]=mult_r(X_fx->a_fx[k], inv_lag); - move16(); /* Q(temp-8+19+1-16)=Q(temp-4) of a[k]*2.0/N */ - X_fx->b_fx[k]=round_fx(L_shl(Lb[k], temp)); /* Q(8+temp-16)=Q(temp-8) */ - X_fx->b_fx[k]=mult_r(X_fx->b_fx[k], inv_lag); - move16(); /* Q(temp-8+19+1-16)=Q(temp-4) of b[k]*2.0/N */ + X_fx->a_fx[k] = round_fx( L_shl( La[k], temp ) ); /* Q(8+temp-16)=Q(temp-8) */ + X_fx->a_fx[k] = mult_r( X_fx->a_fx[k], inv_lag ); + move16(); /* Q(temp-8+19+1-16)=Q(temp-4) of a[k]*2.0/N */ + X_fx->b_fx[k] = round_fx( L_shl( Lb[k], temp ) ); /* Q(8+temp-16)=Q(temp-8) */ + X_fx->b_fx[k] = mult_r( X_fx->b_fx[k], inv_lag ); + move16(); /* Q(temp-8+19+1-16)=Q(temp-4) of b[k]*2.0/N */ #endif } /* IF ( N%2 == 0 ) */ - IF ( s_and(N,1) == 0 ) + IF( s_and( N, 1 ) == 0 ) { #ifdef BASOP_NOGLOB - X_fx->a_fx[k]=round_fx_o(L_shl_o(La[k], temp, &Overflow), &Overflow); /* Q(8+temp-16)=Q(temp-8) */ - X_fx->a_fx[k]=mult_ro(X_fx->a_fx[k], inv_lag, &Overflow); + X_fx->a_fx[k] = round_fx_o( L_shl_o( La[k], temp, &Overflow ), &Overflow ); /* Q(8+temp-16)=Q(temp-8) */ + X_fx->a_fx[k] = mult_ro( X_fx->a_fx[k], inv_lag, &Overflow ); #else - X_fx->a_fx[k]=round_fx(L_shl(La[k], temp)); /* Q(8+temp-16)=Q(temp-8) */ - X_fx->a_fx[k]=mult_r(X_fx->a_fx[k], inv_lag); + X_fx->a_fx[k] = round_fx( L_shl( La[k], temp ) ); /* Q(8+temp-16)=Q(temp-8) */ + X_fx->a_fx[k] = mult_r( X_fx->a_fx[k], inv_lag ); #endif - move16(); /* Q(temp-8+19+1-16)=Q(temp-4) of a[k]*1.0/N */ - X_fx->b_fx[k]=0; + move16(); /* Q(temp-8+19+1-16)=Q(temp-4) of a[k]*1.0/N */ + X_fx->b_fx[k] = 0; move16(); } - X_fx->Q=sub(temp, 4); + X_fx->Q = sub( temp, 4 ); - tmp = s_min(shr(X_fx->lag_fx,1),sub(MAXLAG_WI,1)); - FOR(k=add(nH_band,1); k<=tmp; k++) + tmp = s_min( shr( X_fx->lag_fx, 1 ), sub( MAXLAG_WI, 1 ) ); + FOR( k = add( nH_band, 1 ); k <= tmp; k++ ) { - X_fx->a_fx[k]=0; + X_fx->a_fx[k] = 0; move16(); - X_fx->b_fx[k]=0; + X_fx->b_fx[k] = 0; move16(); } - X_fx->nH_fx=nH_band; + X_fx->nH_fx = nH_band; move16(); - X_fx->nH_4kHz_fx=nH_4kHz; + X_fx->nH_4kHz_fx = nH_4kHz; move16(); return; } @@ -1019,20 +1012,20 @@ void DTFS_to_fs_fx( /* CALLED FROM : TX/RX */ /*===================================================================*/ static void DTFS_transform_fx( - DTFS_STRUCTURE X_fx, /* i : Starting DTFS to use in WI */ - DTFS_STRUCTURE X2_fx, /* i : Ending DTFS to use in WI */ - const Word32 *phase_fx, /* i : Phase contour */ - Word16 *out_fx, /* o : Output time domain waveform */ - Word16 N, /* i : Number of samples to generate */ - const Word16 FR_flag /* i : Flag to indicate called in FR context */ + DTFS_STRUCTURE X_fx, /* i : Starting DTFS to use in WI */ + DTFS_STRUCTURE X2_fx, /* i : Ending DTFS to use in WI */ + const Word32 *phase_fx, /* i : Phase contour */ + Word16 *out_fx, /* o : Output time domain waveform */ + Word16 N, /* i : Number of samples to generate */ + const Word16 FR_flag /* i : Flag to indicate called in FR context */ ) { - Word16 i, j ; + Word16 i, j; Word32 L_temp_fx; Word16 w_fx; Word16 inv1_fx, inv2_fx, inv_fx, q1, q2; - Word32 Lw_fx,temp32_fx; + Word32 Lw_fx, temp32_fx; Word16 x2_256_fx[256], x1_256_fx[256]; Word16 k, m, l1; Word32 x_r_fx[256] = { 0 }; @@ -1046,69 +1039,67 @@ static void DTFS_transform_fx( ivas_error error; - DTFS_STRUCTURE* tmp1_dtfs_fx; - DTFS_STRUCTURE* tmp2_dtfs_fx; - DTFS_STRUCTURE* tmp3_dtfs_fx; + DTFS_STRUCTURE *tmp1_dtfs_fx; + DTFS_STRUCTURE *tmp2_dtfs_fx; + DTFS_STRUCTURE *tmp3_dtfs_fx; error = IVAS_ERR_OK; - IF ((error = DTFS_new_fx(&tmp1_dtfs_fx)) != IVAS_ERR_OK) + IF( ( error = DTFS_new_fx( &tmp1_dtfs_fx ) ) != IVAS_ERR_OK ) { - IVAS_ERROR(error, "Error creating DTFS structure 1"); + IVAS_ERROR( error, "Error creating DTFS structure 1" ); } - IF ((error = DTFS_new_fx(&tmp2_dtfs_fx)) != IVAS_ERR_OK) + IF( ( error = DTFS_new_fx( &tmp2_dtfs_fx ) ) != IVAS_ERR_OK ) { - IVAS_ERROR(error, "Error creating DTFS structure 2"); + IVAS_ERROR( error, "Error creating DTFS structure 2" ); } - IF ((error = DTFS_new_fx(&tmp3_dtfs_fx)) != IVAS_ERR_OK) + IF( ( error = DTFS_new_fx( &tmp3_dtfs_fx ) ) != IVAS_ERR_OK ) { - IVAS_ERROR(error, "Error creating DTFS structure 3"); + IVAS_ERROR( error, "Error creating DTFS structure 3" ); } - DTFS_copy_fx(tmp1_dtfs_fx,X_fx); - DTFS_copy_fx(tmp2_dtfs_fx,X2_fx); - - tmp2 = 0; /* to avoid compilation warnings */ + DTFS_copy_fx( tmp1_dtfs_fx, X_fx ); + DTFS_copy_fx( tmp2_dtfs_fx, X2_fx ); + tmp2 = 0; /* to avoid compilation warnings */ - DTFS_fast_fs_inv_fx(tmp1_dtfs_fx,x1_256_fx,256,8); - DTFS_fast_fs_inv_fx(tmp2_dtfs_fx,x2_256_fx,256,8); + DTFS_fast_fs_inv_fx( tmp1_dtfs_fx, x1_256_fx, 256, 8 ); + DTFS_fast_fs_inv_fx( tmp2_dtfs_fx, x2_256_fx, 256, 8 ); /* L_temp_fx=invert_dp((Word40)N,4,&n,1); = 1/M, Q(61-n) */ /* inv1_fx=round_fx(L_temp_fx); = 1/M in Q(45-n) */ /* q1=sub(n,15); */ - exp1 = norm_s(N); - inv1_fx = div_s(shl(1,sub(14,exp1)),N); /* 29-exp1 */ - q1=add(exp1,1); + exp1 = norm_s( N ); + inv1_fx = div_s( shl( 1, sub( 14, exp1 ) ), N ); /* 29-exp1 */ + q1 = add( exp1, 1 ); - tmp1 = sub(X_fx.lag_fx,N); - exp2 = norm_s(tmp1); + tmp1 = sub( X_fx.lag_fx, N ); + exp2 = norm_s( tmp1 ); - if(tmp1<0) + if ( tmp1 < 0 ) { - tmp2 = negate(tmp1); + tmp2 = negate( tmp1 ); } - tmp = div_s(shl(1,(14- exp2)),tmp2); /* 29-exp2 */ - L_tmp = L_shl(tmp,16); + tmp = div_s( shl( 1, ( 14 - exp2 ) ), tmp2 ); /* 29-exp2 */ + L_tmp = L_shl( tmp, 16 ); - if(tmp1<0) + if ( tmp1 < 0 ) { - L_tmp = L_negate(L_tmp); + L_tmp = L_negate( L_tmp ); } - q2=sub(exp2,3); - + q2 = sub( exp2, 3 ); /*L_temp_fx=(Word32) Mpy_32_16(extract_h(L_tmp),extract_l(L_tmp),22904); move32(); */ /* L_temp=log(0.2)*log10(e)/(lag-M), Q(61-n) */ - L_temp_fx= Mult_32_16(L_tmp,22904); /* L_temp=log(0.2)*log10(e)/(lag-M), Q(61-n) */ - inv2_fx=round_fx(L_temp_fx); /* log(0.2)*log10(e)/(lag-M), Q(45-n) */ - /* q2=sub(n,19); */ /* adjust Q factor to Q26 */ + L_temp_fx = Mult_32_16( L_tmp, 22904 ); /* L_temp=log(0.2)*log10(e)/(lag-M), Q(61-n) */ + inv2_fx = round_fx( L_temp_fx ); /* log(0.2)*log10(e)/(lag-M), Q(45-n) */ + /* q2=sub(n,19); */ /* adjust Q factor to Q26 */ - IF (GT_16(sub(N, WI_SAMPLE_THLD), X_fx.lag_fx)) + IF( GT_16( sub( N, WI_SAMPLE_THLD ), X_fx.lag_fx ) ) { inv_fx = inv2_fx; move16(); @@ -1121,73 +1112,71 @@ static void DTFS_transform_fx( move16(); } - Lw_fx = L_deposit_l(inv_fx); + Lw_fx = L_deposit_l( inv_fx ); - FOR (i=0; i 16+13+1 */ /*27-exp2 */ - L_tmp = L_shl(L_tmp, sub(exp2,add(q2,11))); - frac = L_Extract_lc(L_tmp, &exp1); /* Extract exponent */ - L_temp_fx =Pow2(14, frac); - exp1 = sub(exp1,14); - L_temp_fx = L_shl(L_temp_fx,add(exp1,15)); /* Q15 */ + L_tmp = L_shl( Lw_fx, q2 ); /* Q29-exp2+q2 */ + L_tmp = Mult_32_16( L_tmp, 27213 ); /* 3.321928 in Q13 -> 16+13+1 */ /*27-exp2 */ + L_tmp = L_shl( L_tmp, sub( exp2, add( q2, 11 ) ) ); + frac = L_Extract_lc( L_tmp, &exp1 ); /* Extract exponent */ + L_temp_fx = Pow2( 14, frac ); + exp1 = sub( exp1, 14 ); + L_temp_fx = L_shl( L_temp_fx, add( exp1, 15 ) ); /* Q15 */ - w_fx=sub(16384,extract_h(L_shl(L_temp_fx,15))); /* w_fx in Q14 1- exp(- (i+1) * log(.2)/(lag-M)) */ + w_fx = sub( 16384, extract_h( L_shl( L_temp_fx, 15 ) ) ); /* w_fx in Q14 1- exp(- (i+1) * log(.2)/(lag-M)) */ } ELSE { - w_fx=round_fx(L_shl(Lw_fx,q1)); /* Q14 */ + w_fx = round_fx( L_shl( Lw_fx, q1 ) ); /* Q14 */ } } ELSE { - IF (nrg_flag) + IF( nrg_flag ) { - w_fx=round_fx(L_shl(Lw_fx,q1)); /* Q14 */ + w_fx = round_fx( L_shl( Lw_fx, q1 ) ); /* Q14 */ } ELSE { - N1 = sub(N , tmp2_dtfs_fx->lag_fx); + N1 = sub( N, tmp2_dtfs_fx->lag_fx ); - IF (LT_16(i,N1)) + IF( LT_16( i, N1 ) ) /* w = (i+1)/N1; */ { /* w = (i+1)/N1; */ - IF(N1) + IF( N1 ) { - expa = norm_s(N1); - fraca = shl(N1,expa); - expa = sub(14,expa); - - tmp = add(i,1); - expb = norm_s(tmp); - fracb = shl(tmp,expb); - expb = sub(14,expb); - - scale = shr(sub(fraca,fracb),15); - fracb = shl(fracb,scale); - expb = sub(expb,scale); - - w_fx = div_s(fracb,fraca); - exp1 = sub(expb,expa); - w_fx = shl(w_fx,exp1-1); /*Q14*/ + expa = norm_s( N1 ); + fraca = shl( N1, expa ); + expa = sub( 14, expa ); + + tmp = add( i, 1 ); + expb = norm_s( tmp ); + fracb = shl( tmp, expb ); + expb = sub( 14, expb ); + + scale = shr( sub( fraca, fracb ), 15 ); + fracb = shl( fracb, scale ); + expb = sub( expb, scale ); + + w_fx = div_s( fracb, fraca ); + exp1 = sub( expb, expa ); + w_fx = shl( w_fx, exp1 - 1 ); /*Q14*/ } ELSE { w_fx = 0; } - Lw_fx=L_deposit_h(w_fx); - - + Lw_fx = L_deposit_h( w_fx ); } ELSE { @@ -1197,44 +1186,43 @@ static void DTFS_transform_fx( } } - Lw_fx=L_add(Lw_fx,inv_fx); /* (i+1)*inv */ + Lw_fx = L_add( Lw_fx, inv_fx ); /* (i+1)*inv */ /* mapping phase to 8x256 length signal */ - temp32_fx = phase_fx[i]; /* Q(27-11)=Q16 due to multiplication by pow(2.0,11) */ - j = rint_new_fx(temp32_fx); - j = s_and(j,0x07ff); + temp32_fx = phase_fx[i]; /* Q(27-11)=Q16 due to multiplication by pow(2.0,11) */ + j = rint_new_fx( temp32_fx ); + j = s_and( j, 0x07ff ); /* k=j%8; */ - k=s_and(j,7); - l1=shr(j,3); /* reminder and quotient */ + k = s_and( j, 7 ); + l1 = shr( j, 3 ); /* reminder and quotient */ temp_w = sub( 16384, w_fx ); - tmptmp3_40_fx = L_deposit_l(0); + tmptmp3_40_fx = L_deposit_l( 0 ); - FOR (j=0; j<12; j++) + FOR( j = 0; j < 12; j++ ) { - m=(1000*LL+l1-OSLENGTH/2+j)%LL; /* use circular addressing */ - x_r_fx[m] = L_mac( L_mult( x1_256_fx[m], temp_w), x2_256_fx[m], w_fx); + m = ( 1000 * LL + l1 - OSLENGTH / 2 + j ) % LL; /* use circular addressing */ + x_r_fx[m] = L_mac( L_mult( x1_256_fx[m], temp_w ), x2_256_fx[m], w_fx ); } - tmptmp3_40_fx = L_deposit_l(0); + tmptmp3_40_fx = L_deposit_l( 0 ); - FOR (j=0; j<12; j++) + FOR( j = 0; j < 12; j++ ) { - m=(1000*LL+l1-OSLENGTH/2+j)%LL; /* use circular addressing */ - tmptmp3_40_fx=L_add(tmptmp3_40_fx, Mult_32_16(x_r_fx[m],sinc_fx[k][j])); - + m = ( 1000 * LL + l1 - OSLENGTH / 2 + j ) % LL; /* use circular addressing */ + tmptmp3_40_fx = L_add( tmptmp3_40_fx, Mult_32_16( x_r_fx[m], sinc_fx[k][j] ) ); } #ifdef BASOP_NOGLOB out_fx[i] = round_fx_sat( L_shl_sat( tmptmp3_40_fx, 2 ) ); #else - out_fx[i] = round_fx(L_shl(tmptmp3_40_fx,2)); + out_fx[i] = round_fx( L_shl( tmptmp3_40_fx, 2 ) ); #endif } - count_free(tmp1_dtfs_fx); - count_free(tmp2_dtfs_fx); - count_free(tmp3_dtfs_fx); + count_free( tmp1_dtfs_fx ); + count_free( tmp2_dtfs_fx ); + count_free( tmp3_dtfs_fx ); return; } /*===================================================================*/ @@ -1262,16 +1250,15 @@ static void DTFS_transform_fx( /* CALLED FROM : TX/RX */ /*===================================================================*/ -void DTFS_zeroFilter_fx( +void DTFS_zeroFilter_fx( DTFS_STRUCTURE *X_fx, - Word16 *LPC, - Word16 N, - Word16 *S_fx, - Word16 *C_fx -) + Word16 *LPC, + Word16 N, + Word16 *S_fx, + Word16 *C_fx ) { - Word32 sum1_fx, sum2_fx ; - Word16 k, n, HalfLag ; + Word32 sum1_fx, sum2_fx; + Word16 k, n, HalfLag; Word16 temp, temp1, temp2; Word32 L_temp1, L_temp2; Word16 Qmin, Qab[MAXLAG_WI], na, nb; @@ -1280,8 +1267,8 @@ void DTFS_zeroFilter_fx( #endif Qmin = 32767; move16(); - HalfLag = s_min(shr(X_fx->lag_fx, 1),X_fx->nH_fx); - FOR ( k=0 ; k<=HalfLag ; k++ ) + HalfLag = s_min( shr( X_fx->lag_fx, 1 ), X_fx->nH_fx ); + FOR( k = 0; k <= HalfLag; k++ ) { temp = k; move16(); @@ -1289,92 +1276,92 @@ void DTFS_zeroFilter_fx( move16(); /* Calculate sum1 and sum2 */ - sum1_fx = L_deposit_h(4096); /* 1: Q(12+15+1) */ - sum2_fx = L_deposit_l(0); + sum1_fx = L_deposit_h( 4096 ); /* 1: Q(12+15+1) */ + sum2_fx = L_deposit_l( 0 ); - FOR ( n=0 ; nlag_fx)], &Overflow) ; /* Q(12+15+1) */ - sum2_fx = L_mac_o(sum2_fx, LPC[n], S_fx[(4*temp2)%(4*X_fx->lag_fx)], &Overflow) ; + sum1_fx = L_mac_o( sum1_fx, LPC[n], C_fx[( 4 * temp2 ) % ( 4 * X_fx->lag_fx )], &Overflow ); /* Q(12+15+1) */ + sum2_fx = L_mac_o( sum2_fx, LPC[n], S_fx[( 4 * temp2 ) % ( 4 * X_fx->lag_fx )], &Overflow ); #else - sum1_fx = L_mac(sum1_fx, LPC[n], C_fx[(4*temp2)%(4*X_fx->lag_fx)]) ; /* Q(12+15+1) */ - sum2_fx = L_mac(sum2_fx, LPC[n], S_fx[(4*temp2)%(4*X_fx->lag_fx)]) ; + sum1_fx = L_mac( sum1_fx, LPC[n], C_fx[( 4 * temp2 ) % ( 4 * X_fx->lag_fx )] ); /* Q(12+15+1) */ + sum2_fx = L_mac( sum2_fx, LPC[n], S_fx[( 4 * temp2 ) % ( 4 * X_fx->lag_fx )] ); #endif - temp2 = add(temp2, temp); + temp2 = add( temp2, temp ); } #ifdef BASOP_NOGLOB - temp1 = round_fx_o(sum1_fx, &Overflow); /* Q(12+15+1-16)=Q(12) */ - temp2 = round_fx_o(sum2_fx, &Overflow); /* Q(12) */ + temp1 = round_fx_o( sum1_fx, &Overflow ); /* Q(12+15+1-16)=Q(12) */ + temp2 = round_fx_o( sum2_fx, &Overflow ); /* Q(12) */ /* Calculate the circular convolution */ - L_temp1 = L_mult_o(temp1, X_fx->a_fx[k], &Overflow); - L_temp1 = L_msu_o(L_temp1, temp2, X_fx->b_fx[k], &Overflow); /* Q(12+Q+1) */ - L_temp2 = L_mult_o(temp1, X_fx->b_fx[k], &Overflow); - L_temp2 = L_mac_o(L_temp2, temp2, X_fx->a_fx[k], &Overflow); /* Q(12+Q+1) */ + L_temp1 = L_mult_o( temp1, X_fx->a_fx[k], &Overflow ); + L_temp1 = L_msu_o( L_temp1, temp2, X_fx->b_fx[k], &Overflow ); /* Q(12+Q+1) */ + L_temp2 = L_mult_o( temp1, X_fx->b_fx[k], &Overflow ); + L_temp2 = L_mac_o( L_temp2, temp2, X_fx->a_fx[k], &Overflow ); /* Q(12+Q+1) */ #else - temp1 = round_fx(sum1_fx); /* Q(12+15+1-16)=Q(12) */ - temp2 = round_fx(sum2_fx); /* Q(12) */ + temp1 = round_fx( sum1_fx ); /* Q(12+15+1-16)=Q(12) */ + temp2 = round_fx( sum2_fx ); /* Q(12) */ /* Calculate the circular convolution */ - L_temp1 = L_mult(temp1, X_fx->a_fx[k]); - L_temp1 = L_msu(L_temp1, temp2, X_fx->b_fx[k]); /* Q(12+Q+1) */ - L_temp2 = L_mult(temp1, X_fx->b_fx[k]); - L_temp2 = L_mac(L_temp2, temp2, X_fx->a_fx[k]); /* Q(12+Q+1) */ + L_temp1 = L_mult( temp1, X_fx->a_fx[k] ); + L_temp1 = L_msu( L_temp1, temp2, X_fx->b_fx[k] ); /* Q(12+Q+1) */ + L_temp2 = L_mult( temp1, X_fx->b_fx[k] ); + L_temp2 = L_mac( L_temp2, temp2, X_fx->a_fx[k] ); /* Q(12+Q+1) */ #endif /* normalization */ - na = norm_l(L_temp1); - if (L_temp1==0) + na = norm_l( L_temp1 ); + if ( L_temp1 == 0 ) { - na=31; + na = 31; move16(); } - nb = norm_l(L_temp2); - if (L_temp2==0) + nb = norm_l( L_temp2 ); + if ( L_temp2 == 0 ) { - nb=31; + nb = 31; move16(); } - if (LT_16(na, nb)) + if ( LT_16( na, nb ) ) { - nb=na; + nb = na; move16(); } #ifdef BASOP_NOGLOB - X_fx->a_fx[k] = round_fx_o((Word32)L_shl_o(L_temp1, nb, &Overflow), &Overflow); /* Q(13+Q+nb-16)=Q(Q+nb-3) */ - X_fx->b_fx[k] = round_fx_o((Word32)L_shl_o(L_temp2, nb, &Overflow), &Overflow); /* Q(Q+nb-3) */ + X_fx->a_fx[k] = round_fx_o( (Word32) L_shl_o( L_temp1, nb, &Overflow ), &Overflow ); /* Q(13+Q+nb-16)=Q(Q+nb-3) */ + X_fx->b_fx[k] = round_fx_o( (Word32) L_shl_o( L_temp2, nb, &Overflow ), &Overflow ); /* Q(Q+nb-3) */ #else - X_fx->a_fx[k] = round_fx((Word32)L_shl(L_temp1, nb)); /* Q(13+Q+nb-16)=Q(Q+nb-3) */ - X_fx->b_fx[k] = round_fx((Word32)L_shl(L_temp2, nb)); /* Q(Q+nb-3) */ + X_fx->a_fx[k] = round_fx( (Word32) L_shl( L_temp1, nb ) ); /* Q(13+Q+nb-16)=Q(Q+nb-3) */ + X_fx->b_fx[k] = round_fx( (Word32) L_shl( L_temp2, nb ) ); /* Q(Q+nb-3) */ #endif - Qab[k] = sub(nb, 3); + Qab[k] = sub( nb, 3 ); - if (LT_16(Qab[k], Qmin)) + if ( LT_16( Qab[k], Qmin ) ) { Qmin = Qab[k]; move16(); } } /* bring to the same Q */ - FOR ( k=0 ; k<=HalfLag ; k++ ) + FOR( k = 0; k <= HalfLag; k++ ) { #ifdef BASOP_NOGLOB - X_fx->a_fx[k] = shl_o(X_fx->a_fx[k], sub(Qmin, Qab[k]), &Overflow); + X_fx->a_fx[k] = shl_o( X_fx->a_fx[k], sub( Qmin, Qab[k] ), &Overflow ); move16(); /* Q(Q+Qab[k]+Qmin-Qab[k]=Q(Q+Qmin) */ - X_fx->b_fx[k] = shl_o(X_fx->b_fx[k], sub(Qmin, Qab[k]), &Overflow); + X_fx->b_fx[k] = shl_o( X_fx->b_fx[k], sub( Qmin, Qab[k] ), &Overflow ); move16(); /* Q(Q+Qmin) */ #else - X_fx->a_fx[k] = shl(X_fx->a_fx[k], sub(Qmin, Qab[k])); + X_fx->a_fx[k] = shl( X_fx->a_fx[k], sub( Qmin, Qab[k] ) ); move16(); /* Q(Q+Qab[k]+Qmin-Qab[k]=Q(Q+Qmin) */ - X_fx->b_fx[k] = shl(X_fx->b_fx[k], sub(Qmin, Qab[k])); + X_fx->b_fx[k] = shl( X_fx->b_fx[k], sub( Qmin, Qab[k] ) ); move16(); /* Q(Q+Qmin) */ #endif } - X_fx->Q = add(X_fx->Q, Qmin); + X_fx->Q = add( X_fx->Q, Qmin ); move16(); return; } @@ -1406,24 +1393,23 @@ void DTFS_zeroFilter_fx( /* PORTING: Handling the functions with variable no. of arguments */ -void DTFS_poleFilter_fx_9( - DTFS_STRUCTURE *X_fx, - Word16 *pf_temp1, - Word16 *pf_temp2, - Word16 *pf_temp, - Word16 *pf_n2_temp1 -) +void DTFS_poleFilter_fx_9( + DTFS_STRUCTURE *X_fx, + Word16 *pf_temp1, + Word16 *pf_temp2, + Word16 *pf_temp, + Word16 *pf_n2_temp1 ) { - Word16 temp, temp1, temp2, HalfLag ; + Word16 temp, temp1, temp2, HalfLag; Word32 sum1_fx, sum2_fx; Word32 L_temp1, L_temp2; - Word16 k,n2_temp1, na, nb; + Word16 k, n2_temp1, na, nb; Word16 Qmin, Qab[MAXLAG_WI]; Qmin = 32767; move16(); - HalfLag = s_min(shr(X_fx->lag_fx, 1),X_fx->nH_fx); - FOR ( k=0; k<=HalfLag; k++ ) + HalfLag = s_min( shr( X_fx->lag_fx, 1 ), X_fx->nH_fx ); + FOR( k = 0; k <= HalfLag; k++ ) { temp = temp2 = k; move16(); @@ -1434,46 +1420,46 @@ void DTFS_poleFilter_fx_9( move16(); temp1 = pf_temp1[k]; - move16();/* Q(12+15+1+n2-16)=Q(12+n2) */ + move16(); /* Q(12+15+1+n2-16)=Q(12+n2) */ temp2 = pf_temp2[k]; - move16();/* Q(12+n2) */ + move16(); /* Q(12+n2) */ /* Calculate the circular convolution */ - L_temp1 = L_mac(L_mult(temp1, X_fx->a_fx[k]), temp2, X_fx->b_fx[k]); /* Q(12+n2+Q+1)=Q(13+n2+Q) */ - L_temp2 = L_msu(L_mult(temp1, X_fx->b_fx[k]), temp2, X_fx->a_fx[k]); /* Q(12+n2+Q+1)=Q(13+n2+Q) */ + L_temp1 = L_mac( L_mult( temp1, X_fx->a_fx[k] ), temp2, X_fx->b_fx[k] ); /* Q(12+n2+Q+1)=Q(13+n2+Q) */ + L_temp2 = L_msu( L_mult( temp1, X_fx->b_fx[k] ), temp2, X_fx->a_fx[k] ); /* Q(12+n2+Q+1)=Q(13+n2+Q) */ temp = pf_temp[k]; - move16(); /* Q(61-25-2*n2-temp1-16)=Q(20-2*n2-temp1) */ + move16(); /* Q(61-25-2*n2-temp1-16)=Q(20-2*n2-temp1) */ - sum1_fx = Mult_32_16(L_temp1, temp); /* Q(13+n2+Q+15+exp-15) = Q(13+n2+Q+exp) */ - sum2_fx = Mult_32_16(L_temp2, temp); + sum1_fx = Mult_32_16( L_temp1, temp ); /* Q(13+n2+Q+15+exp-15) = Q(13+n2+Q+exp) */ + sum2_fx = Mult_32_16( L_temp2, temp ); /* normalization */ - na = norm_l(sum1_fx); - if(sum1_fx==0) + na = norm_l( sum1_fx ); + if ( sum1_fx == 0 ) { na = 31; move16(); } - nb = norm_l(sum2_fx); - if(sum2_fx==0) + nb = norm_l( sum2_fx ); + if ( sum2_fx == 0 ) { nb = 31; move16(); } - if (LT_16(na, nb)) + if ( LT_16( na, nb ) ) { - nb=na; + nb = na; move16(); } - nb=sub(nb,1); /* leave one more sign bit */ - X_fx->a_fx[k] = round_fx((Word32)L_shl(sum1_fx, nb)); /* Q(-3+n2+Q+exp+nb ) */ - X_fx->b_fx[k] = round_fx((Word32)L_shl(sum2_fx, nb)); + nb = sub( nb, 1 ); /* leave one more sign bit */ + X_fx->a_fx[k] = round_fx( (Word32) L_shl( sum1_fx, nb ) ); /* Q(-3+n2+Q+exp+nb ) */ + X_fx->b_fx[k] = round_fx( (Word32) L_shl( sum2_fx, nb ) ); - Qab[k] = add(sub(nb, 3), n2_temp1); + Qab[k] = add( sub( nb, 3 ), n2_temp1 ); - if (LT_16(Qab[k], Qmin)) + if ( LT_16( Qab[k], Qmin ) ) { Qmin = Qab[k]; move16(); @@ -1481,15 +1467,15 @@ void DTFS_poleFilter_fx_9( } /* bring to the same Q */ move16(); - FOR ( k=0; k<=HalfLag; k++ ) + FOR( k = 0; k <= HalfLag; k++ ) { - X_fx->a_fx[k] = shl(X_fx->a_fx[k], sub(Qmin, Qab[k])); - move16(); /* Q(Q+Qab[k]+Qmin-Qab[k])=Q(Q+Qmin) */ - X_fx->b_fx[k] = shl(X_fx->b_fx[k], sub(Qmin, Qab[k])); - move16(); /* Q(Q+Qab[k]+Qmin-Qab[k])=Q(Q+Qmin) */ + X_fx->a_fx[k] = shl( X_fx->a_fx[k], sub( Qmin, Qab[k] ) ); + move16(); /* Q(Q+Qab[k]+Qmin-Qab[k])=Q(Q+Qmin) */ + X_fx->b_fx[k] = shl( X_fx->b_fx[k], sub( Qmin, Qab[k] ) ); + move16(); /* Q(Q+Qab[k]+Qmin-Qab[k])=Q(Q+Qmin) */ } - X_fx->Q = add(X_fx->Q, Qmin); + X_fx->Q = add( X_fx->Q, Qmin ); return; } /*===================================================================*/ @@ -1512,74 +1498,74 @@ void DTFS_poleFilter_fx_9( /*===================================================================*/ void DTFS_adjustLag_fx( - DTFS_STRUCTURE *X_DTFS_FX, /* i/o : DTFS to adjust lag for */ - Word16 N_fx /* i : Target lag */ + DTFS_STRUCTURE *X_DTFS_FX, /* i/o : DTFS to adjust lag for */ + Word16 N_fx /* i : Target lag */ ) { Word32 en_fx; - Word32 temp32_fx,tempnH_fx,mul1_fx,mul2_fx; - Word16 k,diff_fx; - Word16 exp,tmp; + Word32 temp32_fx, tempnH_fx, mul1_fx, mul2_fx; + Word16 k, diff_fx; + Word16 exp, tmp; Word32 L_tmp; - if (EQ_16(N_fx,X_DTFS_FX->lag_fx)) + if ( EQ_16( N_fx, X_DTFS_FX->lag_fx ) ) { - return ; + return; } - IF(GT_16(N_fx,X_DTFS_FX->lag_fx)) + IF( GT_16( N_fx, X_DTFS_FX->lag_fx ) ) { - DTFS_zeroPadd_fx(N_fx,X_DTFS_FX); + DTFS_zeroPadd_fx( N_fx, X_DTFS_FX ); } ELSE { - en_fx = DTFS_getEngy_fx(X_DTFS_FX); /* Q = 2*(X_DTFS_FX->Q) */ + en_fx = DTFS_getEngy_fx( X_DTFS_FX ); /* Q = 2*(X_DTFS_FX->Q) */ - tmp = s_min(shr(X_DTFS_FX->lag_fx,1),X_DTFS_FX->nH_fx); - FOR( k = add(shr(N_fx,1),1) ; k<= tmp ; k++) + tmp = s_min( shr( X_DTFS_FX->lag_fx, 1 ), X_DTFS_FX->nH_fx ); + FOR( k = add( shr( N_fx, 1 ), 1 ); k <= tmp; k++ ) { X_DTFS_FX->a_fx[k] = 0; move16(); X_DTFS_FX->b_fx[k] = 0; move16(); } - DTFS_setEngy_fx(X_DTFS_FX,en_fx); - X_DTFS_FX->lag_fx = N_fx ; + DTFS_setEngy_fx( X_DTFS_FX, en_fx ); + X_DTFS_FX->lag_fx = N_fx; move16(); /* recompute nH for new lag */ - exp = norm_s(X_DTFS_FX->lag_fx); - tmp = div_s(shl(1,sub(14,exp)),X_DTFS_FX->lag_fx);/* 29 - exp */ - L_tmp = L_mult0(12800,tmp); - temp32_fx = L_shl(L_tmp,sub(exp,23)); - diff_fx = (Word16) L_shl(L_tmp,sub(exp,29)); + exp = norm_s( X_DTFS_FX->lag_fx ); + tmp = div_s( shl( 1, sub( 14, exp ) ), X_DTFS_FX->lag_fx ); /* 29 - exp */ + L_tmp = L_mult0( 12800, tmp ); + temp32_fx = L_shl( L_tmp, sub( exp, 23 ) ); + diff_fx = (Word16) L_shl( L_tmp, sub( exp, 29 ) ); - exp = norm_s(diff_fx); - tmp = div_s(shl(1,sub(14,exp)),diff_fx);/* 29 - exp */ - L_tmp = L_mult0(X_DTFS_FX->upper_cut_off_freq_fx,tmp); - X_DTFS_FX->nH_fx = (Word16) L_shl(L_tmp,sub(exp,29)); + exp = norm_s( diff_fx ); + tmp = div_s( shl( 1, sub( 14, exp ) ), diff_fx ); /* 29 - exp */ + L_tmp = L_mult0( X_DTFS_FX->upper_cut_off_freq_fx, tmp ); + X_DTFS_FX->nH_fx = (Word16) L_shl( L_tmp, sub( exp, 29 ) ); - L_tmp = L_mult0(4000,tmp); - tempnH_fx = L_shl(L_tmp,sub(exp,23)); - X_DTFS_FX->nH_4kHz_fx = extract_l(L_shl(L_tmp, sub(exp,29))); + L_tmp = L_mult0( 4000, tmp ); + tempnH_fx = L_shl( L_tmp, sub( exp, 23 ) ); + X_DTFS_FX->nH_4kHz_fx = extract_l( L_shl( L_tmp, sub( exp, 29 ) ) ); - if(GE_16(sub(X_DTFS_FX->upper_cut_off_freq_fx, shr((Word16)L_mult(diff_fx,X_DTFS_FX->nH_fx),1)), diff_fx)) + if ( GE_16( sub( X_DTFS_FX->upper_cut_off_freq_fx, shr( (Word16) L_mult( diff_fx, X_DTFS_FX->nH_fx ), 1 ) ), diff_fx ) ) { - X_DTFS_FX->nH_fx = add(X_DTFS_FX->nH_fx,1); + X_DTFS_FX->nH_fx = add( X_DTFS_FX->nH_fx, 1 ); move16(); } - mul1_fx = L_shl(temp32_fx,13);/* Q19 */ - mul2_fx = L_shl((Word32)X_DTFS_FX->nH_4kHz_fx,18);/* Q18 */ - tempnH_fx = Mult_32_32(mul1_fx,mul2_fx);/* Q6 */ - tempnH_fx = L_sub((Word32)256000,tempnH_fx);/* Q6 */ + mul1_fx = L_shl( temp32_fx, 13 ); /* Q19 */ + mul2_fx = L_shl( (Word32) X_DTFS_FX->nH_4kHz_fx, 18 ); /* Q18 */ + tempnH_fx = Mult_32_32( mul1_fx, mul2_fx ); /* Q6 */ + tempnH_fx = L_sub( (Word32) 256000, tempnH_fx ); /* Q6 */ - if(GE_32(tempnH_fx,temp32_fx)) + if ( GE_32( tempnH_fx, temp32_fx ) ) { - X_DTFS_FX->nH_4kHz_fx = add(X_DTFS_FX->nH_4kHz_fx,1); + X_DTFS_FX->nH_4kHz_fx = add( X_DTFS_FX->nH_4kHz_fx, 1 ); move16(); } } @@ -1604,19 +1590,18 @@ void DTFS_adjustLag_fx( /*===================================================================*/ -Word32 DTFS_getEngy_fx( - DTFS_STRUCTURE *X_fx -) +Word32 DTFS_getEngy_fx( + DTFS_STRUCTURE *X_fx ) { Word16 k, HalfLag_fx; - Word32 en_fx=0; - Word16 temp_a_fx,temp_b_fx; + Word32 en_fx = 0; + Word16 temp_a_fx, temp_b_fx; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - HalfLag_fx = shr(sub(X_fx->lag_fx, 1), 1); - HalfLag_fx = s_min(HalfLag_fx,X_fx->nH_fx); - FOR (k=1; k<=HalfLag_fx; k++) + HalfLag_fx = shr( sub( X_fx->lag_fx, 1 ), 1 ); + HalfLag_fx = s_min( HalfLag_fx, X_fx->nH_fx ); + FOR( k = 1; k <= HalfLag_fx; k++ ) { temp_a_fx = X_fx->a_fx[k]; move16(); @@ -1624,23 +1609,23 @@ Word32 DTFS_getEngy_fx( move16(); #ifdef BASOP_NOGLOB - en_fx = L_mac0_o(en_fx, temp_a_fx, temp_a_fx, &Overflow); - en_fx = L_mac0_o(en_fx, temp_b_fx, temp_b_fx, &Overflow); + en_fx = L_mac0_o( en_fx, temp_a_fx, temp_a_fx, &Overflow ); + en_fx = L_mac0_o( en_fx, temp_b_fx, temp_b_fx, &Overflow ); #else - en_fx = L_mac0(en_fx, temp_a_fx, temp_a_fx); - en_fx = L_mac0(en_fx, temp_b_fx, temp_b_fx); + en_fx = L_mac0( en_fx, temp_a_fx, temp_a_fx ); + en_fx = L_mac0( en_fx, temp_b_fx, temp_b_fx ); #endif } - en_fx = L_shr(en_fx, 1); + en_fx = L_shr( en_fx, 1 ); temp_a_fx = X_fx->a_fx[0]; #ifdef BASOP_NOGLOB - en_fx = L_mac0_o(en_fx,temp_a_fx, temp_a_fx, &Overflow); + en_fx = L_mac0_o( en_fx, temp_a_fx, temp_a_fx, &Overflow ); #else - en_fx = L_mac0(en_fx,temp_a_fx, temp_a_fx); + en_fx = L_mac0( en_fx, temp_a_fx, temp_a_fx ); #endif /* IF (X_fx->lag_fx%2 == 0) */ - IF (s_and(X_fx->lag_fx,1) == 0) + IF( s_and( X_fx->lag_fx, 1 ) == 0 ) { temp_a_fx = X_fx->a_fx[k]; move16(); @@ -1648,19 +1633,18 @@ Word32 DTFS_getEngy_fx( move16(); #ifdef BASOP_NOGLOB - en_fx = L_mac0_o(en_fx, temp_a_fx, temp_a_fx, &Overflow); - en_fx = L_mac0_o(en_fx, temp_b_fx, temp_b_fx, &Overflow); + en_fx = L_mac0_o( en_fx, temp_a_fx, temp_a_fx, &Overflow ); + en_fx = L_mac0_o( en_fx, temp_b_fx, temp_b_fx, &Overflow ); #else - en_fx = L_mac0(en_fx, temp_a_fx, temp_a_fx); - en_fx = L_mac0(en_fx, temp_b_fx, temp_b_fx); + en_fx = L_mac0( en_fx, temp_a_fx, temp_a_fx ); + en_fx = L_mac0( en_fx, temp_b_fx, temp_b_fx ); #endif } - return en_fx ; /* 2*X1.Q+1=Q13 */ + return en_fx; /* 2*X1.Q+1=Q13 */ } - /*===================================================================*/ /* FUNCTION : DTFS_getEngy_P2A_fx () */ /*-------------------------------------------------------------------*/ @@ -1679,50 +1663,48 @@ Word32 DTFS_getEngy_fx( /* CALLED FROM : TX/RX */ /*===================================================================*/ -Word32 DTFS_getEngy_P2A_fx( - DTFS_STRUCTURE *X_fx -) +Word32 DTFS_getEngy_P2A_fx( + DTFS_STRUCTURE *X_fx ) { Word16 k, HalfLag_fx; - Word32 en_fx=0; + Word32 en_fx = 0; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - HalfLag_fx = shr(sub(X_fx->lag_fx, 1), 1); - HalfLag_fx = s_min(HalfLag_fx,X_fx->nH_fx); - FOR (k=1; k<=HalfLag_fx; k++) + HalfLag_fx = shr( sub( X_fx->lag_fx, 1 ), 1 ); + HalfLag_fx = s_min( HalfLag_fx, X_fx->nH_fx ); + FOR( k = 1; k <= HalfLag_fx; k++ ) { #ifdef BASOP_NOGLOB - en_fx = L_mac0_o(en_fx, X_fx->a_fx[k], X_fx->a_fx[k], &Overflow); - en_fx = L_mac0_o(en_fx, X_fx->b_fx[k], X_fx->b_fx[k], &Overflow); + en_fx = L_mac0_o( en_fx, X_fx->a_fx[k], X_fx->a_fx[k], &Overflow ); + en_fx = L_mac0_o( en_fx, X_fx->b_fx[k], X_fx->b_fx[k], &Overflow ); #else - en_fx = L_mac0(en_fx, X_fx->a_fx[k], X_fx->a_fx[k]); - en_fx = L_mac0(en_fx, X_fx->b_fx[k], X_fx->b_fx[k]); + en_fx = L_mac0( en_fx, X_fx->a_fx[k], X_fx->a_fx[k] ); + en_fx = L_mac0( en_fx, X_fx->b_fx[k], X_fx->b_fx[k] ); #endif } - en_fx = L_shr(en_fx, 1); + en_fx = L_shr( en_fx, 1 ); #ifdef BASOP_NOGLOB - en_fx = L_mac0_o(en_fx,X_fx->a_fx[0], X_fx->a_fx[0], &Overflow); + en_fx = L_mac0_o( en_fx, X_fx->a_fx[0], X_fx->a_fx[0], &Overflow ); #else - en_fx = L_mac0(en_fx,X_fx->a_fx[0], X_fx->a_fx[0]); + en_fx = L_mac0( en_fx, X_fx->a_fx[0], X_fx->a_fx[0] ); #endif /* IF (X_fx->lag_fx%2 == 0) */ - IF (s_and(X_fx->lag_fx,1) == 0) + IF( s_and( X_fx->lag_fx, 1 ) == 0 ) { #ifdef BASOP_NOGLOB - en_fx = L_mac0_o(en_fx, X_fx->a_fx[k], X_fx->a_fx[k], &Overflow); - en_fx = L_mac0_o(en_fx, X_fx->b_fx[k], X_fx->b_fx[k], &Overflow); + en_fx = L_mac0_o( en_fx, X_fx->a_fx[k], X_fx->a_fx[k], &Overflow ); + en_fx = L_mac0_o( en_fx, X_fx->b_fx[k], X_fx->b_fx[k], &Overflow ); #else - en_fx = L_mac0(en_fx, X_fx->a_fx[k], X_fx->a_fx[k]); - en_fx = L_mac0(en_fx, X_fx->b_fx[k], X_fx->b_fx[k]); + en_fx = L_mac0( en_fx, X_fx->a_fx[k], X_fx->a_fx[k] ); + en_fx = L_mac0( en_fx, X_fx->b_fx[k], X_fx->b_fx[k] ); #endif } - return en_fx ; /* 2*X1.Q */ + return en_fx; /* 2*X1.Q */ } - /*===================================================================*/ /* FUNCTION : DTFS_setEngy_fx ( ) */ /*-------------------------------------------------------------------*/ @@ -1743,71 +1725,68 @@ Word32 DTFS_getEngy_P2A_fx( /* CALLED FROM : TX/RX */ /*===================================================================*/ -static Word32 DTFS_setEngy_fx( +static Word32 DTFS_setEngy_fx( DTFS_STRUCTURE *X_DTFS_FX, - Word32 en2_fx -) + Word32 en2_fx ) { - Word16 k, HalfLag_fx ; + Word16 k, HalfLag_fx; Word32 en1_fx; Word32 L_temp_fx; - Word16 expa,expb,fraca,fracb,scale,tmp,exp; - Word32 L_tmp,factor_fx; + Word16 expa, expb, fraca, fracb, scale, tmp, exp; + Word32 L_tmp, factor_fx; - HalfLag_fx = s_min(shr(X_DTFS_FX->lag_fx, 1),X_DTFS_FX->nH_fx); + HalfLag_fx = s_min( shr( X_DTFS_FX->lag_fx, 1 ), X_DTFS_FX->nH_fx ); move16(); - en1_fx = DTFS_getEngy_fx(X_DTFS_FX); + en1_fx = DTFS_getEngy_fx( X_DTFS_FX ); move16(); - if (en1_fx == 0) + if ( en1_fx == 0 ) { return 0; } - IF (en2_fx==0) + IF( en2_fx == 0 ) { - factor_fx=0; + factor_fx = 0; } ELSE { - expa = norm_l(en2_fx); - fraca = extract_h(L_shl(en2_fx,expa)); - expa = sub(30, add(expa,shl(X_DTFS_FX->Q, 1))); + expa = norm_l( en2_fx ); + fraca = extract_h( L_shl( en2_fx, expa ) ); + expa = sub( 30, add( expa, shl( X_DTFS_FX->Q, 1 ) ) ); - expb = norm_l(en1_fx); + expb = norm_l( en1_fx ); #ifdef BASOP_NOGLOB fracb = round_fx_sat( L_shl_sat( en1_fx, expb ) ); #else - fracb = round_fx(L_shl(en1_fx,expb)); + fracb = round_fx( L_shl( en1_fx, expb ) ); #endif - expb = sub(30, add(expb, shl(X_DTFS_FX->Q, 1))); + expb = sub( 30, add( expb, shl( X_DTFS_FX->Q, 1 ) ) ); - scale = shr(sub(fraca,fracb),15); - fracb = shl(fracb,scale); - expb = sub(expb,scale); + scale = shr( sub( fraca, fracb ), 15 ); + fracb = shl( fracb, scale ); + expb = sub( expb, scale ); - tmp = div_s(fracb,fraca); - exp = sub(expb,expa); - - L_tmp = Isqrt_lc(L_deposit_h(tmp),&exp); /* Q(31-exp) */ - factor_fx = L_shr(L_tmp,1); + tmp = div_s( fracb, fraca ); + exp = sub( expb, expa ); + L_tmp = Isqrt_lc( L_deposit_h( tmp ), &exp ); /* Q(31-exp) */ + factor_fx = L_shr( L_tmp, 1 ); } - FOR (k=0; k<=HalfLag_fx; k++) + FOR( k = 0; k <= HalfLag_fx; k++ ) { - L_temp_fx = Mult_32_16(factor_fx, X_DTFS_FX->a_fx[k]); /* Q(temp+X1.Q-15) */ - X_DTFS_FX->a_fx[k] = round_fx(L_temp_fx); /* Q(temp+X1.Q-15-16)=Q(temp+X1.Q-31); */ - - L_temp_fx =Mult_32_16(factor_fx, X_DTFS_FX->b_fx[k]); /* Q(temp+X1.Q-15) */ - X_DTFS_FX->b_fx[k] = round_fx(L_temp_fx); /* Q(temp+X1.Q-15-16)=Q(temp+X1.Q-31); */ + L_temp_fx = Mult_32_16( factor_fx, X_DTFS_FX->a_fx[k] ); /* Q(temp+X1.Q-15) */ + X_DTFS_FX->a_fx[k] = round_fx( L_temp_fx ); /* Q(temp+X1.Q-15-16)=Q(temp+X1.Q-31); */ + L_temp_fx = Mult_32_16( factor_fx, X_DTFS_FX->b_fx[k] ); /* Q(temp+X1.Q-15) */ + X_DTFS_FX->b_fx[k] = round_fx( L_temp_fx ); /* Q(temp+X1.Q-15-16)=Q(temp+X1.Q-31); */ } - return en1_fx ;/* 2*X1.Q+1 = Q13 */ + return en1_fx; /* 2*X1.Q+1 = Q13 */ } /*===================================================================*/ @@ -1841,39 +1820,39 @@ static Word32 DTFS_setEngy_fx( /* Cartesian representation to avoid computing phases by arctan*/ /*===================================================================*/ void DTFS_car2pol_fx( - DTFS_STRUCTURE *X_fx /* i/o : DTFS structure a, b, lag */ + DTFS_STRUCTURE *X_fx /* i/o : DTFS structure a, b, lag */ ) { - Word16 k, HalfLag_fx ; + Word16 k, HalfLag_fx; Word32 Ltemp_fx; Word32 Lacc_fx; - Word16 exp,tmp,frac; + Word16 exp, tmp, frac; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - HalfLag_fx = s_min(shr(sub(X_fx->lag_fx,1),1),X_fx->nH_fx); - FOR ( k=1 ; k<=HalfLag_fx; k++ ) + HalfLag_fx = s_min( shr( sub( X_fx->lag_fx, 1 ), 1 ), X_fx->nH_fx ); + FOR( k = 1; k <= HalfLag_fx; k++ ) { - Lacc_fx=L_mult(X_fx->a_fx[k],X_fx->a_fx[k]); /* a[k]^2, 2Q+1 */ + Lacc_fx = L_mult( X_fx->a_fx[k], X_fx->a_fx[k] ); /* a[k]^2, 2Q+1 */ #ifdef BASOP_NOGLOB - Lacc_fx=L_mac_o(Lacc_fx,X_fx->b_fx[k],X_fx->b_fx[k], &Overflow); /* a[k]^2+b[k]^2, 2Q+1 */ + Lacc_fx = L_mac_o( Lacc_fx, X_fx->b_fx[k], X_fx->b_fx[k], &Overflow ); /* a[k]^2+b[k]^2, 2Q+1 */ #else - Lacc_fx=L_mac(Lacc_fx,X_fx->b_fx[k],X_fx->b_fx[k]); /* a[k]^2+b[k]^2, 2Q+1 */ + Lacc_fx = L_mac( Lacc_fx, X_fx->b_fx[k], X_fx->b_fx[k] ); /* a[k]^2+b[k]^2, 2Q+1 */ #endif - Lacc_fx=L_shr(Lacc_fx,3); /* Lacc=(a[k]^2+b[k]^2)/4, 2Q */ + Lacc_fx = L_shr( Lacc_fx, 3 ); /* Lacc=(a[k]^2+b[k]^2)/4, 2Q */ - IF(Lacc_fx) + IF( Lacc_fx ) { - exp = norm_l(Lacc_fx); - frac = extract_h(L_shl(Lacc_fx,exp)); /* Q14 */ - exp = sub(exp, sub(30,(2*X_fx->Q))); + exp = norm_l( Lacc_fx ); + frac = extract_h( L_shl( Lacc_fx, exp ) ); /* Q14 */ + exp = sub( exp, sub( 30, ( 2 * X_fx->Q ) ) ); - tmp = div_s(16384,frac); /* Q15 */ - Ltemp_fx = Isqrt_lc(L_deposit_h(tmp),&exp); /* Q(31-exp) */ + tmp = div_s( 16384, frac ); /* Q15 */ + Ltemp_fx = Isqrt_lc( L_deposit_h( tmp ), &exp ); /* Q(31-exp) */ - X_fx->a_fx[k]=extract_h(L_shl(Ltemp_fx, sub(add(X_fx->Q, exp), 15))); /* Q */ + X_fx->a_fx[k] = extract_h( L_shl( Ltemp_fx, sub( add( X_fx->Q, exp ), 15 ) ) ); /* Q */ } ELSE { @@ -1881,26 +1860,26 @@ void DTFS_car2pol_fx( move16(); } - X_fx->b_fx[k]= 0; + X_fx->b_fx[k] = 0; move16(); /* clear b[k] */ } - IF (s_and(X_fx->lag_fx,1) == 0) + IF( s_and( X_fx->lag_fx, 1 ) == 0 ) { - IF(X_fx->a_fx[k]) + IF( X_fx->a_fx[k] ) { - Lacc_fx=L_mult0(X_fx->a_fx[k],X_fx->a_fx[k]); /* a[k]^2, 2Q+1 */ - Lacc_fx=L_mac0(Lacc_fx,X_fx->b_fx[k],X_fx->b_fx[k]); /* a[k]^2+b[k]^2, 2Q+1 */ + Lacc_fx = L_mult0( X_fx->a_fx[k], X_fx->a_fx[k] ); /* a[k]^2, 2Q+1 */ + Lacc_fx = L_mac0( Lacc_fx, X_fx->b_fx[k], X_fx->b_fx[k] ); /* a[k]^2+b[k]^2, 2Q+1 */ - exp = norm_l(Lacc_fx); - frac = extract_h(L_shl(Lacc_fx,exp)); /* Q14 */ - exp = sub(exp,sub(30,shl(X_fx->Q,1))); + exp = norm_l( Lacc_fx ); + frac = extract_h( L_shl( Lacc_fx, exp ) ); /* Q14 */ + exp = sub( exp, sub( 30, shl( X_fx->Q, 1 ) ) ); - tmp = div_s(16384,frac); /* Q15 */ - Ltemp_fx = Isqrt_lc(L_deposit_h(tmp),&exp); /* Q(31-exp) */ + tmp = div_s( 16384, frac ); /* Q15 */ + Ltemp_fx = Isqrt_lc( L_deposit_h( tmp ), &exp ); /* Q(31-exp) */ - X_fx->a_fx[k]=extract_h(L_shl(Ltemp_fx, sub(add(X_fx->Q, exp), 15))); /* Q */ + X_fx->a_fx[k] = extract_h( L_shl( Ltemp_fx, sub( add( X_fx->Q, exp ), 15 ) ) ); /* Q */ } ELSE { @@ -1908,7 +1887,7 @@ void DTFS_car2pol_fx( move16(); } - X_fx->b_fx[k]= 0; + X_fx->b_fx[k] = 0; move16(); /* clear b[k]; */ } return; @@ -1945,156 +1924,152 @@ void DTFS_car2pol_fx( /* of harmonics, instead of the whole DTFS */ /*============================================================================== */ Word32 DTFS_setEngyHarm_fx( - Word16 f1_fx, /* i : lower band freq of input to control energy */ - Word16 f2_fx, /* i : upper band freq of input to control energy */ - Word16 g1_fx, /* i : lower band freq of output to control energy */ - Word16 g2_fx, /* i : upper band freq of output to control energy */ - Word32 en2_fx, /* i : Target Energy to set the DTFS to */ - Word16 Qen2_fx, /* i : Input Q format for en2 */ - Word16 *Qa_fx, /* i : Output Q format for x->a */ - DTFS_STRUCTURE *X_fx /* i/o: DTFS to adjust the energy of */ + Word16 f1_fx, /* i : lower band freq of input to control energy */ + Word16 f2_fx, /* i : upper band freq of input to control energy */ + Word16 g1_fx, /* i : lower band freq of output to control energy */ + Word16 g2_fx, /* i : upper band freq of output to control energy */ + Word32 en2_fx, /* i : Target Energy to set the DTFS to */ + Word16 Qen2_fx, /* i : Input Q format for en2 */ + Word16 *Qa_fx, /* i : Output Q format for x->a */ + DTFS_STRUCTURE *X_fx /* i/o: DTFS to adjust the energy of */ ) { - Word16 k, count=0, HalfLag_fx; + Word16 k, count = 0, HalfLag_fx; Word16 f_low_fx, f_high_fx, g_low_fx, g_high_fx; Word32 L_temp_fx, factor_fx; Word32 en1_fx; Word32 Lacc; - Word16 exp,tmp,expa,expb,fraca,fracb,scale; + Word16 exp, tmp, expa, expb, fraca, fracb, scale; Word32 L_tmp; Word32 Lacc_max = 0; - Word16 expp=0; + Word16 expp = 0; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - f_low_fx=mult(f1_fx,X_fx->lag_fx); /* Q0 */ - f_high_fx=mult(f2_fx,X_fx->lag_fx); /* Q0 */ - g_low_fx=mult(g1_fx,X_fx->lag_fx); /* Q0 */ - g_high_fx=mult(g2_fx,X_fx->lag_fx); /* Q0 */ - HalfLag_fx = s_min(f_high_fx,shl(X_fx->nH_fx,1)); + f_low_fx = mult( f1_fx, X_fx->lag_fx ); /* Q0 */ + f_high_fx = mult( f2_fx, X_fx->lag_fx ); /* Q0 */ + g_low_fx = mult( g1_fx, X_fx->lag_fx ); /* Q0 */ + g_high_fx = mult( g2_fx, X_fx->lag_fx ); /* Q0 */ + HalfLag_fx = s_min( f_high_fx, shl( X_fx->nH_fx, 1 ) ); - Lacc = L_deposit_l(0); - FOR (k=f_low_fx+1 ; k<=HalfLag_fx; k++) + Lacc = L_deposit_l( 0 ); + FOR( k = f_low_fx + 1; k <= HalfLag_fx; k++ ) { #ifdef BASOP_NOGLOB - Lacc = L_mac0_o(Lacc, X_fx->a_fx[k], X_fx->a_fx[k], &Overflow); /* 2*X1.Q */ + Lacc = L_mac0_o( Lacc, X_fx->a_fx[k], X_fx->a_fx[k], &Overflow ); /* 2*X1.Q */ #else - Lacc = L_mac0(Lacc, X_fx->a_fx[k], X_fx->a_fx[k]); /* 2*X1.Q */ + Lacc = L_mac0( Lacc, X_fx->a_fx[k], X_fx->a_fx[k] ); /* 2*X1.Q */ #endif - Lacc_max = L_max( Lacc_max, Lacc); + Lacc_max = L_max( Lacc_max, Lacc ); - count=add(count,1); + count = add( count, 1 ); } - IF( GE_32( Lacc_max, 2147483647 )) + IF( GE_32( Lacc_max, 2147483647 ) ) { - tmp = sub(HalfLag_fx, f_low_fx); - exp = norm_s(tmp); - expp = sub(15,exp); + tmp = sub( HalfLag_fx, f_low_fx ); + exp = norm_s( tmp ); + expp = sub( 15, exp ); - Lacc = L_deposit_l(0); - FOR( k=f_low_fx+1; k<=HalfLag_fx; k++ ) + Lacc = L_deposit_l( 0 ); + FOR( k = f_low_fx + 1; k <= HalfLag_fx; k++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_mult_o( X_fx->a_fx[k], X_fx->a_fx[k], &Overflow); - Lacc = L_add_o(Lacc, L_shr(L_tmp,expp), &Overflow); /* 2*X1.Q-expp */ + L_tmp = L_mult_o( X_fx->a_fx[k], X_fx->a_fx[k], &Overflow ); + Lacc = L_add_o( Lacc, L_shr( L_tmp, expp ), &Overflow ); /* 2*X1.Q-expp */ #else L_tmp = L_mult( X_fx->a_fx[k], X_fx->a_fx[k] ); - Lacc = L_add(Lacc, L_shr(L_tmp,expp)); /* 2*X1.Q-expp */ + Lacc = L_add( Lacc, L_shr( L_tmp, expp ) ); /* 2*X1.Q-expp */ #endif - count=add(count,1); + count = add( count, 1 ); } } - if (count <= 0) + if ( count <= 0 ) { count = 1; move16(); } - exp = norm_s(count); - tmp = div_s(shl(1,sub(14,exp)),count);/* 29 - exp */ + exp = norm_s( count ); + tmp = div_s( shl( 1, sub( 14, exp ) ), count ); /* 29 - exp */ #ifdef BASOP_NOGLOB - en1_fx = L_shl_o( Mult_32_16(Lacc , tmp), sub(exp,14), &Overflow); + en1_fx = L_shl_o( Mult_32_16( Lacc, tmp ), sub( exp, 14 ), &Overflow ); #else - en1_fx = L_shl( Mult_32_16(Lacc , tmp), sub(exp,14)); + en1_fx = L_shl( Mult_32_16( Lacc, tmp ), sub( exp, 14 ) ); #endif test(); - IF (en1_fx>0 && en2_fx > 0) + IF( en1_fx > 0 && en2_fx > 0 ) { /* factor_fx = sqrt_divide_dp((Word40)en2_fx, en1_fx, sub(Qen2_fx, shl(X_fx->Q, 1)), &temp_fx,1); : Q(temp) */ - expa = norm_l(en2_fx); - fraca = extract_h(L_shl(en2_fx,expa)); - expa = sub(30,add(expa,Qen2_fx)); + expa = norm_l( en2_fx ); + fraca = extract_h( L_shl( en2_fx, expa ) ); + expa = sub( 30, add( expa, Qen2_fx ) ); - expb = norm_l(en1_fx); + expb = norm_l( en1_fx ); #ifdef BASOP_NOGLOB - fracb = round_fx_o(L_shl_o(en1_fx,expb, &Overflow), &Overflow); + fracb = round_fx_o( L_shl_o( en1_fx, expb, &Overflow ), &Overflow ); #else - fracb = round_fx(L_shl(en1_fx,expb)); + fracb = round_fx( L_shl( en1_fx, expb ) ); #endif - IF( GE_32( Lacc_max, 2147483647 )) + IF( GE_32( Lacc_max, 2147483647 ) ) { - expb = sub( 30, add( expb, sub(shl(X_fx->Q, 1),expp) ) ); + expb = sub( 30, add( expb, sub( shl( X_fx->Q, 1 ), expp ) ) ); } ELSE { - expb = sub(30, add(expb, shl(X_fx->Q, 1))); + expb = sub( 30, add( expb, shl( X_fx->Q, 1 ) ) ); } - scale = shr(sub(fraca,fracb),15); - fracb = shl(fracb,scale); - expb = sub(expb,scale); + scale = shr( sub( fraca, fracb ), 15 ); + fracb = shl( fracb, scale ); + expb = sub( expb, scale ); - tmp = div_s(fracb,fraca); - exp = sub(expb,expa); + tmp = div_s( fracb, fraca ); + exp = sub( expb, expa ); - L_tmp = Isqrt_lc(L_deposit_h(tmp),&exp); /* Q(31-exp) */ + L_tmp = Isqrt_lc( L_deposit_h( tmp ), &exp ); /* Q(31-exp) */ - IF( GE_32( Lacc_max, 2147483647 )) + IF( GE_32( Lacc_max, 2147483647 ) ) { - factor_fx = L_shr(L_tmp,add(1,s_min(2,expp))); + factor_fx = L_shr( L_tmp, add( 1, s_min( 2, expp ) ) ); } ELSE { - factor_fx = L_shr(L_tmp,1); + factor_fx = L_shr( L_tmp, 1 ); } - - } ELSE { - factor_fx = L_deposit_l(0); + factor_fx = L_deposit_l( 0 ); } - HalfLag_fx = s_min(g_high_fx,shl(X_fx->nH_fx,1)); - FOR (k=g_low_fx+1; k<=HalfLag_fx; k++) + HalfLag_fx = s_min( g_high_fx, shl( X_fx->nH_fx, 1 ) ); + FOR( k = g_low_fx + 1; k <= HalfLag_fx; k++ ) { /*L_temp_fx =(Word32)Mpy_32_16(extract_h(factor_fx),extract_l(factor_fx), X_fx->a_fx[k]); move32(); */ /* Q(temp+X1.Q-15) */ - L_temp_fx = Mult_32_16(factor_fx, X_fx->a_fx[k]); /* Q(temp+X1.Q-15) */ + L_temp_fx = Mult_32_16( factor_fx, X_fx->a_fx[k] ); /* Q(temp+X1.Q-15) */ #ifdef BASOP_NOGLOB - X_fx->a_fx[k] = round_fx_o(L_temp_fx, &Overflow); /* Q(temp+X1.Q-15-16)=Q(temp+X1.Q-31); */ + X_fx->a_fx[k] = round_fx_o( L_temp_fx, &Overflow ); /* Q(temp+X1.Q-15-16)=Q(temp+X1.Q-31); */ #else - X_fx->a_fx[k] = round_fx(L_temp_fx); /* Q(temp+X1.Q-15-16)=Q(temp+X1.Q-31); */ + X_fx->a_fx[k] = round_fx( L_temp_fx ); /* Q(temp+X1.Q-15-16)=Q(temp+X1.Q-31); */ #endif } - if ( GE_32( Lacc_max, 2147483647 )) + if ( GE_32( Lacc_max, 2147483647 ) ) { - *Qa_fx = sub( sub(X_fx->Q,add(1,s_min(2,expp))) , exp); + *Qa_fx = sub( sub( X_fx->Q, add( 1, s_min( 2, expp ) ) ), exp ); } else { - *Qa_fx = sub( sub(X_fx->Q,1) , exp); + *Qa_fx = sub( sub( X_fx->Q, 1 ), exp ); } - return en1_fx; /* Q(2*X1.Q) */ - - + return en1_fx; /* Q(2*X1.Q) */ } /*===================================================================*/ /* FUNCTION : cubicPhase_fx () */ @@ -2121,26 +2096,26 @@ Word32 DTFS_setEngyHarm_fx( /* NOTE: This function outputs phase in (-1,1) */ /*===================================================================*/ static void cubicPhase_fx( - Word16 ph1_fx, /* i : phase offset */ - Word16 ph2_fx, /* i : phase 2 */ - const Word16 L1, /* i : previous lag */ - const Word16 L2, /* i : current lag */ - Word16 N, /* i : input length */ - Word32* phOut_fx /* o : cubic phase output */ + Word16 ph1_fx, /* i : phase offset */ + Word16 ph2_fx, /* i : phase 2 */ + const Word16 L1, /* i : previous lag */ + const Word16 L2, /* i : current lag */ + Word16 N, /* i : input length */ + Word32 *phOut_fx /* o : cubic phase output */ ) { Word16 n; Word16 n2; - Word16 f1, f2; /* invert of L1, L2, Q19 */ + Word16 f1, f2; /* invert of L1, L2, Q19 */ Word16 factor, temp; Word16 c0, c1, c2, c3; /* cubic polynomial coefficients */ /* Q33, Q27, Q19, Q15 respectively */ - Word32 Ltemp1, Ltemp2, Ltemp3,Ltemp4,Ltemp; - Word16 tmp,exp; + Word32 Ltemp1, Ltemp2, Ltemp3, Ltemp4, Ltemp; + Word16 tmp, exp; Word32 Lacc; - Word16 expa,expb,fraca,fracb,scale; - Word32 L_tmp,L_tmp1; - Word16 num_flag,den_flag; + Word16 expa, expb, fraca, fracb, scale; + Word32 L_tmp, L_tmp1; + Word16 num_flag, den_flag; Word32 N2; Word16 dbgshft; #ifdef BASOP_NOGLOB_DECLARE_LOCAL @@ -2149,233 +2124,233 @@ static void cubicPhase_fx( num_flag = 0; den_flag = 0; - N=sub(N,L2); + N = sub( N, L2 ); - exp = norm_s(L1); - tmp = div_s(shl(1,sub(14,exp)),L1); - L_tmp = L_shl(tmp,exp+6); - f1 = round_fx(L_tmp); + exp = norm_s( L1 ); + tmp = div_s( shl( 1, sub( 14, exp ) ), L1 ); + L_tmp = L_shl( tmp, exp + 6 ); + f1 = round_fx( L_tmp ); - exp = norm_s(L2); - tmp = div_s(shl(1,sub(14,exp)),L2); - L_tmp = L_shl(tmp,exp+6); + exp = norm_s( L2 ); + tmp = div_s( shl( 1, sub( 14, exp ) ), L2 ); + L_tmp = L_shl( tmp, exp + 6 ); Ltemp4 = inverse_table[L2]; - f2 = round_fx(L_tmp); + f2 = round_fx( L_tmp ); c3 = ph1_fx; move16(); /* c3 in Q15 */ c2 = f1; - move16();/* c2 in Q19 */ + move16(); /* c2 in Q19 */ - Ltemp1 = L_sub(ph1_fx,ph2_fx); /* Ltemp1=ph1_fx-ph2_fx, Q15 */ - Ltemp2 = L_add(f1,f2); /* Ltemp2=0.5*(f1+f2), Q20 */ - temp = extract_l(Ltemp2);/* Q20 */ + Ltemp1 = L_sub( ph1_fx, ph2_fx ); /* Ltemp1=ph1_fx-ph2_fx, Q15 */ + Ltemp2 = L_add( f1, f2 ); /* Ltemp2=0.5*(f1+f2), Q20 */ + temp = extract_l( Ltemp2 ); /* Q20 */ - IF(temp<0) + IF( temp < 0 ) { - L_tmp1 = L_shl(L_add(65536,temp),14); /* Q30 */ - L_tmp = Mult_32_16(L_tmp1,N); /* 30-15=15 */ - Ltemp2 = L_shl(L_tmp,1); + L_tmp1 = L_shl( L_add( 65536, temp ), 14 ); /* Q30 */ + L_tmp = Mult_32_16( L_tmp1, N ); /* 30-15=15 */ + Ltemp2 = L_shl( L_tmp, 1 ); } ELSE { - Ltemp2 = (Word32)L_mult0(N,temp); /* Ltemp2=0.5*N*(f1+f2), Q20 */ + Ltemp2 = (Word32) L_mult0( N, temp ); /* Ltemp2=0.5*N*(f1+f2), Q20 */ } - Ltemp1 = L_add(L_shl(Ltemp1,5),Ltemp2); /* Ltemp1=ph1_fx - ph2_fx + 0.5*N*(f2+f1), Q16, Q20 */ + Ltemp1 = L_add( L_shl( Ltemp1, 5 ), Ltemp2 ); /* Ltemp1=ph1_fx - ph2_fx + 0.5*N*(f2+f1), Q16, Q20 */ - factor = round_fx(L_shr(Ltemp1,4)); /* factor in Q0 */ + factor = round_fx( L_shr( Ltemp1, 4 ) ); /* factor in Q0 */ - c1 = sub(f2,f1); /* c1=f2-f1, Q19 */ - Ltemp1 = L_sub(ph2_fx,ph1_fx); /* Q15 */ - Ltemp2 = L_mult(N,f1); /* Ltemp2=N*f1, Q20 */ - Ltemp2 = L_sub(L_shl(L_deposit_h(factor),4),Ltemp2); /* Ltemp2=factor-N*f1, Q20 */ - Ltemp1 = L_add(Ltemp2,L_shl(Ltemp1,5)); /* Ltemp1 in Q20 */ + c1 = sub( f2, f1 ); /* c1=f2-f1, Q19 */ + Ltemp1 = L_sub( ph2_fx, ph1_fx ); /* Q15 */ + Ltemp2 = L_mult( N, f1 ); /* Ltemp2=N*f1, Q20 */ + Ltemp2 = L_sub( L_shl( L_deposit_h( factor ), 4 ), Ltemp2 ); /* Ltemp2=factor-N*f1, Q20 */ + Ltemp1 = L_add( Ltemp2, L_shl( Ltemp1, 5 ) ); /* Ltemp1 in Q20 */ - IF(GT_16(N,180)) + IF( GT_16( N, 180 ) ) { - Ltemp2 = L_shl(L_mult0(N,N),14); - Ltemp2 = L_shl(Mult_32_16(Ltemp2,N),1); + Ltemp2 = L_shl( L_mult0( N, N ), 14 ); + Ltemp2 = L_shl( Mult_32_16( Ltemp2, N ), 1 ); /* IF(N%2) */ - if(s_and(N,1) == 1) + if ( s_and( N, 1 ) == 1 ) { - Ltemp2 = L_add(Ltemp2,1); + Ltemp2 = L_add( Ltemp2, 1 ); } } ELSE { - Ltemp2=L_shr(L_mult(N,N),1); - Ltemp2 = L_mult0(N,extract_l(Ltemp2)); /* Ltemp2=N^3 */ + Ltemp2 = L_shr( L_mult( N, N ), 1 ); + Ltemp2 = L_mult0( N, extract_l( Ltemp2 ) ); /* Ltemp2=N^3 */ } - Ltemp3 = L_mult(N,c1); /* Q20 */ - Ltemp3 = L_sub(Ltemp3,L_shl(Ltemp1,1)); /* Ltemp3=N*c1-2*Ltemp1, Q20 */ + Ltemp3 = L_mult( N, c1 ); /* Q20 */ + Ltemp3 = L_sub( Ltemp3, L_shl( Ltemp1, 1 ) ); /* Ltemp3=N*c1-2*Ltemp1, Q20 */ #ifdef BASOP_NOGLOB - IF (GE_32(L_abs(Ltemp3),L_shl_o(Ltemp2,8, &Overflow))) + IF( GE_32( L_abs( Ltemp3 ), L_shl_o( Ltemp2, 8, &Overflow ) ) ) #else - IF (GE_32(L_abs(Ltemp3),L_shl(Ltemp2,8))) + IF( GE_32( L_abs( Ltemp3 ), L_shl( Ltemp2, 8 ) ) ) #endif { - Lacc = L_add(MIN_32, 0); - if (Ltemp3 > 0) + Lacc = L_add( MIN_32, 0 ); + if ( Ltemp3 > 0 ) { - Lacc = L_add(MAX_32, 0); + Lacc = L_add( MAX_32, 0 ); } - c0 = extract_h(Lacc); /* c0 in Q33 */ + c0 = extract_h( Lacc ); /* c0 in Q33 */ } ELSE { - expa = norm_l(Ltemp3); + expa = norm_l( Ltemp3 ); #ifdef BASOP_NOGLOB - fraca = extract_h(L_shl_o(Ltemp3,expa, &Overflow)); + fraca = extract_h( L_shl_o( Ltemp3, expa, &Overflow ) ); #else - fraca = extract_h(L_shl(Ltemp3,expa)); + fraca = extract_h( L_shl( Ltemp3, expa ) ); #endif - expa = sub(30,add(expa, 20)); - if(fraca<0) + expa = sub( 30, add( expa, 20 ) ); + if ( fraca < 0 ) { num_flag = 1; move16(); } - expb = norm_l(Ltemp2); + expb = norm_l( Ltemp2 ); #ifdef BASOP_NOGLOB - fracb = extract_h(L_shl_o(Ltemp2,expb, &Overflow)); + fracb = extract_h( L_shl_o( Ltemp2, expb, &Overflow ) ); #else - fracb = extract_h(L_shl(Ltemp2,expb)); + fracb = extract_h( L_shl( Ltemp2, expb ) ); #endif - expb = sub(30,expb); - if(fracb<0) + expb = sub( 30, expb ); + if ( fracb < 0 ) { den_flag = 1; move16(); } - if(num_flag) + if ( num_flag ) { - fraca = negate(fraca); + fraca = negate( fraca ); } - if(den_flag) + if ( den_flag ) { - fracb = negate(fracb); + fracb = negate( fracb ); } - scale = shr(sub(fracb,fraca),15); + scale = shr( sub( fracb, fraca ), 15 ); #ifdef BASOP_NOGLOB - fraca = shl_o(fraca,scale, &Overflow); + fraca = shl_o( fraca, scale, &Overflow ); #else - fraca = shl(fraca,scale); + fraca = shl( fraca, scale ); #endif - expa = sub(expa,scale); + expa = sub( expa, scale ); - tmp = div_s(fraca,fracb); /* 15-exp */ - exp = sub(expa,expb); + tmp = div_s( fraca, fracb ); /* 15-exp */ + exp = sub( expa, expb ); test(); - if(num_flag && !den_flag) + if ( num_flag && !den_flag ) { - tmp = negate(tmp); + tmp = negate( tmp ); } test(); - if(den_flag && !num_flag) + if ( den_flag && !num_flag ) { - tmp = negate(tmp); + tmp = negate( tmp ); } #ifdef BASOP_NOGLOB - Lacc = L_shl_o(tmp,add(exp,34), &Overflow); - Lacc = L_add_o(Lacc,0x08000, &Overflow); + Lacc = L_shl_o( tmp, add( exp, 34 ), &Overflow ); + Lacc = L_add_o( Lacc, 0x08000, &Overflow ); #else - Lacc = L_shl(tmp,add(exp,34)); - Lacc = L_add(Lacc,0x08000); + Lacc = L_shl( tmp, add( exp, 34 ) ); + Lacc = L_add( Lacc, 0x08000 ); #endif - c0 = extract_h(Lacc); /* c0 in Q33 */ + c0 = extract_h( Lacc ); /* c0 in Q33 */ } - Ltemp1 = L_mult(N,N); /* Ltemp1=2*N*N */ - Ltemp1 = L_add(Ltemp1,L_shr(Ltemp1,1)); /* Ltemp1=3*N*N, max is 3*140*140 */ + Ltemp1 = L_mult( N, N ); /* Ltemp1=2*N*N */ + Ltemp1 = L_add( Ltemp1, L_shr( Ltemp1, 1 ) ); /* Ltemp1=3*N*N, max is 3*140*140 */ /* patch added for time warping support, where N can be more than 140 */ - dbgshft= norm_l(Ltemp1); - Ltemp1= L_shl(Ltemp1,dbgshft); - temp = extract_h(Ltemp1); - Ltemp1 = (Word32)L_shl((Word32)L_mult0(c0,temp), sub(16,dbgshft)); /* Ltemp1=3*N*N*c0, Q33 */ + dbgshft = norm_l( Ltemp1 ); + Ltemp1 = L_shl( Ltemp1, dbgshft ); + temp = extract_h( Ltemp1 ); + Ltemp1 = (Word32) L_shl( (Word32) L_mult0( c0, temp ), sub( 16, dbgshft ) ); /* Ltemp1=3*N*N*c0, Q33 */ /* Patch end */ num_flag = den_flag = 0; move16(); move16(); - Ltemp1 = L_sub(L_shr(L_deposit_h(c1),2),Ltemp1); /* Ltemp1=c1-3*N*N*c0, Q33 */ + Ltemp1 = L_sub( L_shr( L_deposit_h( c1 ), 2 ), Ltemp1 ); /* Ltemp1=c1-3*N*N*c0, Q33 */ - expa = norm_l(Ltemp1); - fraca = extract_h(L_shl(Ltemp1,expa)); - expa = sub(30,add(expa, 33)); - if(fraca<0) + expa = norm_l( Ltemp1 ); + fraca = extract_h( L_shl( Ltemp1, expa ) ); + expa = sub( 30, add( expa, 33 ) ); + if ( fraca < 0 ) { num_flag = 1; move16(); } - expb = norm_l(N); - fracb = extract_h(L_shl(N,expb)); - expb = sub(30,expb); - if(fracb<0) + expb = norm_l( N ); + fracb = extract_h( L_shl( N, expb ) ); + expb = sub( 30, expb ); + if ( fracb < 0 ) { den_flag = 1; move16(); } - if(num_flag) + if ( num_flag ) { - fraca = negate(fraca); + fraca = negate( fraca ); } - if(den_flag) + if ( den_flag ) { - fracb = negate(fracb); + fracb = negate( fracb ); } - scale = shr(sub(fracb,fraca),15); - fraca = shl(fraca,scale); - expa = sub(expa,scale); + scale = shr( sub( fracb, fraca ), 15 ); + fraca = shl( fraca, scale ); + expa = sub( expa, scale ); - tmp = div_s(fraca,fracb); /* 15-exp */ - exp = sub(expa,expb); + tmp = div_s( fraca, fracb ); /* 15-exp */ + exp = sub( expa, expb ); test(); - if(num_flag && !den_flag) + if ( num_flag && !den_flag ) { - tmp = negate(tmp); + tmp = negate( tmp ); } test(); - if(den_flag && !num_flag) + if ( den_flag && !num_flag ) { - tmp = negate(tmp); + tmp = negate( tmp ); } - Lacc = L_shl(tmp,exp+27); - Lacc = L_add(Lacc,0x08000); - c1 = extract_h(Lacc); /* c1 in Q27 */ + Lacc = L_shl( tmp, exp + 27 ); + Lacc = L_add( Lacc, 0x08000 ); + c1 = extract_h( Lacc ); /* c1 in Q27 */ /* Computation of the phase value at each sample point */ /* ph[n]= c0*n^3+c1*n^2+c2*n+c3, Q15 */ - phOut_fx[0] = L_shl(ph1_fx,11);/* Q27 */ + phOut_fx[0] = L_shl( ph1_fx, 11 ); /* Q27 */ - IF(LT_16(N,181)) + IF( LT_16( N, 181 ) ) { - FOR (n=1; n=diff_fx)/* Q0 compare */ + if ( L_sub( upper_cut_off_freq_fx, L_tmp ) >= diff_fx ) /* Q0 compare */ { - nH_band_fx = add(nH_band_fx,1);/* Q0 */ + nH_band_fx = add( nH_band_fx, 1 ); /* Q0 */ } - n=s_min(shr(lag_fx,1),nH_band_fx); - exp = norm_s(lag_fx); - tmp = div_s(shl(1,sub(14,exp)),lag_fx); /* Q29-exp */ - L_tmp = L_shl(tmp, add(exp,6)); - diff_fx =round_fx(L_tmp); + n = s_min( shr( lag_fx, 1 ), nH_band_fx ); + exp = norm_s( lag_fx ); + tmp = div_s( shl( 1, sub( 14, exp ) ), lag_fx ); /* Q29-exp */ + L_tmp = L_shl( tmp, add( exp, 6 ) ); + diff_fx = round_fx( L_tmp ); - j=0; + j = 0; move16(); - FOR (i=0; i<=n; i++) + FOR( i = 0; i <= n; i++ ) { - Ltemp_fx=L_mult(diff_fx,i); /* Ltemp=i*diff, Q20 */ + Ltemp_fx = L_mult( diff_fx, i ); /* Ltemp=i*diff, Q20 */ /* freq=round32_16(L_shl(Ltemp,11)); : freq=i*diff, Q15 */ - IF (EQ_16(num_erb_fx,NUM_ERB_NB)) + IF( EQ_16( num_erb_fx, NUM_ERB_NB ) ) { - Ltemp_fx=L_min(Ltemp_fx,0x050000); /* 0x50000=0.3125 in Q20 (4000Hz) */ + Ltemp_fx = L_min( Ltemp_fx, 0x050000 ); /* 0x50000=0.3125 in Q20 (4000Hz) */ } - ELSE IF (EQ_16(num_erb_fx,NUM_ERB_WB)) + ELSE IF( EQ_16( num_erb_fx, NUM_ERB_WB ) ) { - Ltemp_fx=L_min(Ltemp_fx,0x080000); /* 0x80000=0.5 in Q20 (6400Hz) */ + Ltemp_fx = L_min( Ltemp_fx, 0x080000 ); /* 0x80000=0.5 in Q20 (6400Hz) */ } - FOR ( ; jlag_fx); - tmp = div_s(shl(1,sub(14,exp)),X_fx->lag_fx);/* 29-exp */ - diff_fx= shl(tmp,exp-10); /* Q19 */ + exp = norm_s( X_fx->lag_fx ); + tmp = div_s( shl( 1, sub( 14, exp ) ), X_fx->lag_fx ); /* 29-exp */ + diff_fx = shl( tmp, exp - 10 ); /* Q19 */ min_q = EVS_SW_MAX; move16(); - X_fx->a_fx[0]=0; + X_fx->a_fx[0] = 0; move16(); - HalfLag_fx=s_min(shr(X_fx->lag_fx,1),X_fx->nH_fx); + HalfLag_fx = s_min( shr( X_fx->lag_fx, 1 ), X_fx->nH_fx ); - j=1; + j = 1; move16(); - FOR (i=1 ; i<=HalfLag_fx; i++) + FOR( i = 1; i <= HalfLag_fx; i++ ) { - Ltemp_fx=L_mult(diff_fx,i); /* Ltemp=i*diff, Q20 */ - freq_fx=round_fx(L_shl(Ltemp_fx,11)); /* Q15 */ + Ltemp_fx = L_mult( diff_fx, i ); /* Ltemp=i*diff, Q20 */ + freq_fx = round_fx( L_shl( Ltemp_fx, 11 ) ); /* Q15 */ - freq_fx=s_min(freq_fx,upper_cut_off_freq_fx); /* 0x4000 is 0.5 in Q15 */ + freq_fx = s_min( freq_fx, upper_cut_off_freq_fx ); /* 0x4000 is 0.5 in Q15 */ - FOR ( ; j=0) + IF( d1 >= 0 ) { - d2=sub(freq_fx,f_fx[j-1]); - Ltemp_fx=L_mac(L_mult(amp_fx[j],d2),amp_fx[j-1],d1); /* Q29 */ - d2=sub(f_fx[j],f_fx[j-1]); /* Q15 */ + d2 = sub( freq_fx, f_fx[j - 1] ); + Ltemp_fx = L_mac( L_mult( amp_fx[j], d2 ), amp_fx[j - 1], d1 ); /* Q29 */ + d2 = sub( f_fx[j], f_fx[j - 1] ); /* Q15 */ /* Ltemp2_fx=invert_dp((Word40)d2, 4, &n,1); : Ltemp2=1/d2, Q(61-15-n) */ - exp = norm_s(d2); - tmp = div_s(shl(1,sub(14,exp)),d2);/* 29-exp */ + exp = norm_s( d2 ); + tmp = div_s( shl( 1, sub( 14, exp ) ), d2 ); /* 29-exp */ /* L_tmp = L_shr(tmp,8); */ - Ltemp2_fx = L_shl(tmp,16); - n = add(exp,16); - - d1h=extract_h(Ltemp_fx); - d1l=extract_l(Ltemp_fx); - d2h=extract_h(Ltemp2_fx); - d2l=extract_l(Ltemp2_fx); - Ltemp_fx=(Word32)L_mult0(d1h,d2l); - Lacc_fx=L_mac0((Word32)Ltemp_fx,d2h,d1l); - Ltemp_fx=L_add((Word32)L_shr(Lacc_fx,15),L_mult(d1h,d2h)); /* 46-n+29-31 */ - d2h=norm_l(Ltemp_fx); /* d2h is 0 IF Ltemp=0 */ - if( Ltemp_fx == 0 ) + Ltemp2_fx = L_shl( tmp, 16 ); + n = add( exp, 16 ); + + d1h = extract_h( Ltemp_fx ); + d1l = extract_l( Ltemp_fx ); + d2h = extract_h( Ltemp2_fx ); + d2l = extract_l( Ltemp2_fx ); + Ltemp_fx = (Word32) L_mult0( d1h, d2l ); + Lacc_fx = L_mac0( (Word32) Ltemp_fx, d2h, d1l ); + Ltemp_fx = L_add( (Word32) L_shr( Lacc_fx, 15 ), L_mult( d1h, d2h ) ); /* 46-n+29-31 */ + d2h = norm_l( Ltemp_fx ); /* d2h is 0 IF Ltemp=0 */ + if ( Ltemp_fx == 0 ) { d2h = 31; move16(); } #ifdef BASOP_NOGLOB - X_fx->a_fx[i]=round_fx_o(L_shl_o(Ltemp_fx,d2h, &Overflow), &Overflow); /* Q(28-n+d2h) */ + X_fx->a_fx[i] = round_fx_o( L_shl_o( Ltemp_fx, d2h, &Overflow ), &Overflow ); /* Q(28-n+d2h) */ #else - X_fx->a_fx[i]=round_fx(L_shl(Ltemp_fx,d2h)); /* Q(28-n+d2h) */ + X_fx->a_fx[i] = round_fx( L_shl( Ltemp_fx, d2h ) ); /* Q(28-n+d2h) */ #endif - q[i]=add(sub(28,n),d2h); - min_q=s_min(min_q,q[i]); + q[i] = add( sub( 28, n ), d2h ); + min_q = s_min( min_q, q[i] ); - BREAK ; + BREAK; } } } /* block normalize a[i] */ - FOR (i=1; i<=HalfLag_fx; i++) + FOR( i = 1; i <= HalfLag_fx; i++ ) { - X_fx->a_fx[i]=shl(X_fx->a_fx[i],sub(min_q,q[i])); + X_fx->a_fx[i] = shl( X_fx->a_fx[i], sub( min_q, q[i] ) ); move16(); } - X_fx->Q=min_q; + X_fx->Q = min_q; return; } @@ -2931,48 +2903,48 @@ void DTFS_erb_inv_fx( /*===================================================================*/ void erb_add_fx( - Word16 *curr_erb_fx, /* i/o: current ERB */ - Word16 l_fx, /* i : current lag */ - const Word16 *prev_erb_fx, /* i : previous ERB */ - Word16 pl_fx, /* i : previous lag */ - const Word16 *index_fx, /* i : ERB index */ - Word16 num_erb_fx /* i : number of ERBs */ + Word16 *curr_erb_fx, /* i/o: current ERB */ + Word16 l_fx, /* i : current lag */ + const Word16 *prev_erb_fx, /* i : previous ERB */ + Word16 pl_fx, /* i : previous lag */ + const Word16 *index_fx, /* i : ERB index */ + Word16 num_erb_fx /* i : number of ERBs */ ) { - Word16 i ; - Word16 pslot_fx[NUM_ERB_WB],cslot_fx[NUM_ERB_WB],t_prev_erb_fx[NUM_ERB_WB]; - Word16 tmp_fx,tmp2_fx,tmp_loop; + Word16 i; + Word16 pslot_fx[NUM_ERB_WB], cslot_fx[NUM_ERB_WB], t_prev_erb_fx[NUM_ERB_WB]; + Word16 tmp_fx, tmp2_fx, tmp_loop; const Word16 *AmpCB1_fx = NULL; /*move16(); */ - IF (EQ_16(num_erb_fx,NUM_ERB_NB)) + IF( EQ_16( num_erb_fx, NUM_ERB_NB ) ) { - AmpCB1_fx=AmpCB1_NB_fx; + AmpCB1_fx = AmpCB1_NB_fx; move16(); } - ELSE IF (EQ_16(num_erb_fx,NUM_ERB_WB)) + ELSE IF( EQ_16( num_erb_fx, NUM_ERB_WB ) ) { - AmpCB1_fx=AmpCB1_WB_fx; + AmpCB1_fx = AmpCB1_WB_fx; move16(); } - erb_slot_fx(l_fx,cslot_fx,t_prev_erb_fx,num_erb_fx); - erb_slot_fx(pl_fx,pslot_fx,t_prev_erb_fx,num_erb_fx); + erb_slot_fx( l_fx, cslot_fx, t_prev_erb_fx, num_erb_fx ); + erb_slot_fx( pl_fx, pslot_fx, t_prev_erb_fx, num_erb_fx ); - FOR (i=0; i=0; i--) + tmp_fx = t_prev_erb_fx[sub( num_erb_fx, 1 )]; /* Q13 */ + FOR( i = sub( num_erb_fx, 1 ); i >= 0; i-- ) { - IF (pslot_fx[i] != 0) + IF( pslot_fx[i] != 0 ) { tmp_fx = t_prev_erb_fx[i]; move16(); /* Q13 */ @@ -3003,45 +2975,45 @@ void erb_add_fx( } } - tmp_fx = add(shl(index_fx[0],3),shl(index_fx[0],1)); /* tmp_fx=10*index_fx[0] */ - FOR (i=1; i<11; i++) + tmp_fx = add( shl( index_fx[0], 3 ), shl( index_fx[0], 1 ) ); /* tmp_fx=10*index_fx[0] */ + FOR( i = 1; i < 11; i++ ) { - IF (cslot_fx[i]!=0) + IF( cslot_fx[i] != 0 ) { - curr_erb_fx[i] = add(AmpCB1_fx[sub(add(tmp_fx,i),1)],t_prev_erb_fx[i]); - move16();/* Q13+Q13=Q13 */ - curr_erb_fx[i] = s_max(0, curr_erb_fx[i]); + curr_erb_fx[i] = add( AmpCB1_fx[sub( add( tmp_fx, i ), 1 )], t_prev_erb_fx[i] ); + move16(); /* Q13+Q13=Q13 */ + curr_erb_fx[i] = s_max( 0, curr_erb_fx[i] ); move16(); } ELSE - curr_erb_fx[i] = 0; + curr_erb_fx[i] = 0; move16(); } - tmp_fx = add(shl(index_fx[1],3),index_fx[1]); /* tmp=9*index[1] */ - tmp2_fx = mult(shl(index_fx[1],6),5632);/* temp=11*index_fx[1] */ - tmp_loop = sub(num_erb_fx,2); - FOR (i=11; iQ,1),13); /* tmp=2Q-13, Q factor of getSpEngy... output */ - Ltemp3=L_shl(L_mult(tmp,24660),9); /* Ltemp3=(2Q-13)*10log10(2), Q23, 24660=10log10(2) in Q13 */ + tmp = sub( shl( X_fx->Q, 1 ), 13 ); /* tmp=2Q-13, Q factor of getSpEngy... output */ + Ltemp3 = L_shl( L_mult( tmp, 24660 ), 9 ); /* Ltemp3=(2Q-13)*10log10(2), Q23, 24660=10log10(2) in Q13 */ - Ltemp1 = getSpEngyFromResAmp_fx(X_fx,0, 2828,curr_lpc, sin_tab, cos_tab); - Ltemp1=log10_fx(Ltemp1); + Ltemp1 = getSpEngyFromResAmp_fx( X_fx, 0, 2828, curr_lpc, sin_tab, cos_tab ); + Ltemp1 = log10_fx( Ltemp1 ); /* subtract 10log10(2)*(2Q-13), Q23 */ - Ltemp1=L_sub(Ltemp1,Ltemp3); - Ltemp1=L_max(0,Ltemp1); - Ltemp2 = getSpEngyFromResAmp_fx(X_fx,2828,X_fx->upper_cut_off_freq_fx,curr_lpc, sin_tab, cos_tab); - Ltemp2=log10_fx(Ltemp2 ); /* Ltemp1=10log10(eng_hb), Q23, need to adjust for Q factor of energy (2Q-13) */ - Ltemp2=L_sub(Ltemp2,Ltemp3); /* Ltemp2 in Q23 */ + Ltemp1 = L_sub( Ltemp1, Ltemp3 ); + Ltemp1 = L_max( 0, Ltemp1 ); + Ltemp2 = getSpEngyFromResAmp_fx( X_fx, 2828, X_fx->upper_cut_off_freq_fx, curr_lpc, sin_tab, cos_tab ); + Ltemp2 = log10_fx( Ltemp2 ); /* Ltemp1=10log10(eng_hb), Q23, need to adjust for Q factor of energy (2Q-13) */ + Ltemp2 = L_sub( Ltemp2, Ltemp3 ); /* Ltemp2 in Q23 */ - Ltemp2=L_max(0,Ltemp2); + Ltemp2 = L_max( 0, Ltemp2 ); /* Getting the Speech Domain Energy LOG Ratio */ - Lacc = L_add(Ltemp1,Ltemp2); - exp = norm_l(Lacc); - tmp = round_fx(L_shl(Lacc,exp)); - exp = sub(sub(30,exp),23); - IF(tmp) - tmp = div_s(16384,tmp); /* 15+exp1 */ + Lacc = L_add( Ltemp1, Ltemp2 ); + exp = norm_l( Lacc ); + tmp = round_fx( L_shl( Lacc, exp ) ); + exp = sub( sub( 30, exp ), 23 ); + IF( tmp ) + tmp = div_s( 16384, tmp ); /* 15+exp1 */ ELSE - tmp = 0; - Ltemp = L_deposit_h(tmp); - - tmp=round_fx(Ltemp); /* tmp in Q(22-n) */ - Ltemp1= Mult_32_16(Ltemp1,tmp); /* Q(30-n) */ - n=sub(8,exp); - w[0]=round_fx(L_shl(Ltemp1,n)); /* w[0] in Q15 */ - Ltemp2= Mult_32_16(Ltemp2,tmp); - w[1]=round_fx(L_shl(Ltemp2,n)); /* w[1] in Q15 */ - - logLag=log10_fx(X_fx->lag_fx); /* logLag=10*log10(lag), Q23 */ - Ltemp3=L_shl(L_mult(shl(X_fx->Q,1),24660),9); /* Ltemp3=2Q*10log10(2), Q23 */ + tmp = 0; + Ltemp = L_deposit_h( tmp ); + + tmp = round_fx( Ltemp ); /* tmp in Q(22-n) */ + Ltemp1 = Mult_32_16( Ltemp1, tmp ); /* Q(30-n) */ + n = sub( 8, exp ); + w[0] = round_fx( L_shl( Ltemp1, n ) ); /* w[0] in Q15 */ + Ltemp2 = Mult_32_16( Ltemp2, tmp ); + w[1] = round_fx( L_shl( Ltemp2, n ) ); /* w[1] in Q15 */ + + logLag = log10_fx( X_fx->lag_fx ); /* logLag=10*log10(lag), Q23 */ + Ltemp3 = L_shl( L_mult( shl( X_fx->Q, 1 ), 24660 ), 9 ); /* Ltemp3=2Q*10log10(2), Q23 */ /* Process low band */ - Ltemp=DTFS_setEngyHarm_fx(236, 2828, 0, 2828, 1, 0, &Ql,X_fx); /* Ql is norm factor of low band a[], Ltemp is energy in 2Q */ + Ltemp = DTFS_setEngyHarm_fx( 236, 2828, 0, 2828, 1, 0, &Ql, X_fx ); /* Ql is norm factor of low band a[], Ltemp is energy in 2Q */ /* Compensate for Q factor of energy to get log10(lag*eng) */ - Ltemp=log10_fx(Ltemp); /* Ltemp=10log10(eng), Q23 */ - Ltemp=L_add(L_sub(Ltemp,Ltemp3),logLag); /* Ltemp=10*log10(lag*eng), Q23 */ + Ltemp = log10_fx( Ltemp ); /* Ltemp=10log10(eng), Q23 */ + Ltemp = L_add( L_sub( Ltemp, Ltemp3 ), logLag ); /* Ltemp=10*log10(lag*eng), Q23 */ - target[0]=round_fx(L_shl(Mult_32_16(Ltemp,0x6666),1)); /* Q11 */ + target[0] = round_fx( L_shl( Mult_32_16( Ltemp, 0x6666 ), 1 ) ); /* Q11 */ /* Process high band */ - Ltemp=DTFS_setEngyHarm_fx(2828, X_fx->upper_cut_off_freq_of_interest_fx, 2828, X_fx->upper_cut_off_freq_fx, 1, 0, &Qh,X_fx); - Ltemp=log10_fx(Ltemp); - Ltemp=L_add(L_sub(Ltemp,Ltemp3),logLag); /* Ltemp=10*log10(lag*eng), Q23 */ - target[1]=round_fx(L_shl(Mult_32_16(Ltemp,0x6666),1)); /* Q11 */ + Ltemp = DTFS_setEngyHarm_fx( 2828, X_fx->upper_cut_off_freq_of_interest_fx, 2828, X_fx->upper_cut_off_freq_fx, 1, 0, &Qh, X_fx ); + Ltemp = log10_fx( Ltemp ); + Ltemp = L_add( L_sub( Ltemp, Ltemp3 ), logLag ); /* Ltemp=10*log10(lag*eng), Q23 */ + target[1] = round_fx( L_shl( Mult_32_16( Ltemp, 0x6666 ), 1 ) ); /* Q11 */ /* Need to unify the Q factors of both bands */ - X_fx->Q=s_min(Ql,Qh); /* set Q factor to be the smaller one */ - n=sub(Ql,Qh); /* compare band Q factors */ + X_fx->Q = s_min( Ql, Qh ); /* set Q factor to be the smaller one */ + n = sub( Ql, Qh ); /* compare band Q factors */ - IF (n<0) rshiftHarmBand_fx(X_fx,2828, X_fx->upper_cut_off_freq_fx,n); - ELSE IF (n>0) rshiftHarmBand_fx(X_fx,0, 2828, sub(Qh,Ql)); + IF( n < 0 ) + rshiftHarmBand_fx( X_fx, 2828, X_fx->upper_cut_off_freq_fx, n ); + ELSE IF( n > 0 ) rshiftHarmBand_fx( X_fx, 0, 2828, sub( Qh, Ql ) ); } /*==========================================================================*/ @@ -3164,51 +3136,50 @@ void quant_target_fx( DTFS_STRUCTURE *X_fx,const Word16 *curr_lpc, Word16 *w, Wo /* RETURN ARGUMENTS : _ None. */ /*==========================================================================*/ ivas_error WIsyn_fx( - DTFS_STRUCTURE PREVCW_FX, /* i : Prev frame DTFS */ - DTFS_STRUCTURE* CURRCW_DTFS_out, /* i/o: Curr frame DTFS */ - const Word16* curr_lpc_fx, /* i : LPC */ - Word16* ph_offset_fx, /* i/o: Phase offset to line up at end of frame */ - Word16* out_fx, /* o : Waveform Interpolated time domain signal */ - const Word16 N, /* i : Number of output samples to generate */ - const Word16 FR_flag, /* i : called for post-smoothing in FR */ - Word16 * S_fx, - Word16* C_fx, + DTFS_STRUCTURE PREVCW_FX, /* i : Prev frame DTFS */ + DTFS_STRUCTURE *CURRCW_DTFS_out, /* i/o: Curr frame DTFS */ + const Word16 *curr_lpc_fx, /* i : LPC */ + Word16 *ph_offset_fx, /* i/o: Phase offset to line up at end of frame */ + Word16 *out_fx, /* o : Waveform Interpolated time domain signal */ + const Word16 N, /* i : Number of output samples to generate */ + const Word16 FR_flag, /* i : called for post-smoothing in FR */ + Word16 *S_fx, + Word16 *C_fx, Word16 *pf_temp1, Word16 *pf_temp2, Word16 *pf_temp, - Word16 *pf_n2 -) + Word16 *pf_n2 ) { Word16 i; - UWord16 I=1, flag=0; + UWord16 I = 1, flag = 0; /* Word16 *phase_fx = (Word16*)malloc(sizeof(Word16) * (2*N)); new operator used size 2*N */ Word32 phase_fx[WI_FX_phase_fx]; Word16 alignment_fx; Word16 tmp_fx, temp; Word32 L_temp; - Word16 exp,tmp; + Word16 exp, tmp; Word32 L_tmp; /* prev_lsp_fx; */ - DTFS_STRUCTURE *CURRCW_DTFS_FX; + DTFS_STRUCTURE *CURRCW_DTFS_FX; ivas_error error; error = IVAS_ERR_OK; - IF ((error = DTFS_new_fx(&CURRCW_DTFS_FX)) != IVAS_ERR_OK) + IF( ( error = DTFS_new_fx( &CURRCW_DTFS_FX ) ) != IVAS_ERR_OK ) { - return IVAS_ERROR(error, "Error creating new DTFS structure\n"); + return IVAS_ERROR( error, "Error creating new DTFS structure\n" ); } - IF(LT_16(PREVCW_FX.Q, CURRCW_DTFS_out->Q)) + IF( LT_16( PREVCW_FX.Q, CURRCW_DTFS_out->Q ) ) { - temp = sub(CURRCW_DTFS_out->Q, PREVCW_FX.Q); - tmp = s_min(shr(CURRCW_DTFS_out->lag_fx, 1), CURRCW_DTFS_out->nH_fx); - FOR(i = 0; i <= tmp; i++) + temp = sub( CURRCW_DTFS_out->Q, PREVCW_FX.Q ); + tmp = s_min( shr( CURRCW_DTFS_out->lag_fx, 1 ), CURRCW_DTFS_out->nH_fx ); + FOR( i = 0; i <= tmp; i++ ) { - CURRCW_DTFS_out->a_fx[i] = shr(CURRCW_DTFS_out->a_fx[i], temp); + CURRCW_DTFS_out->a_fx[i] = shr( CURRCW_DTFS_out->a_fx[i], temp ); move16(); - CURRCW_DTFS_out->b_fx[i] = shr(CURRCW_DTFS_out->b_fx[i], temp); + CURRCW_DTFS_out->b_fx[i] = shr( CURRCW_DTFS_out->b_fx[i], temp ); move16(); } CURRCW_DTFS_out->Q = PREVCW_FX.Q; @@ -3216,133 +3187,130 @@ ivas_error WIsyn_fx( } - IF(LT_16(CURRCW_DTFS_out->Q, PREVCW_FX.Q)) + IF( LT_16( CURRCW_DTFS_out->Q, PREVCW_FX.Q ) ) { - temp = sub(PREVCW_FX.Q, CURRCW_DTFS_out->Q); - tmp = s_min(shr(PREVCW_FX.lag_fx, 1), PREVCW_FX.nH_fx); - FOR(i = 0; i <= tmp; i++) + temp = sub( PREVCW_FX.Q, CURRCW_DTFS_out->Q ); + tmp = s_min( shr( PREVCW_FX.lag_fx, 1 ), PREVCW_FX.nH_fx ); + FOR( i = 0; i <= tmp; i++ ) { - PREVCW_FX.a_fx[i] = shr(PREVCW_FX.a_fx[i], temp); + PREVCW_FX.a_fx[i] = shr( PREVCW_FX.a_fx[i], temp ); move16(); - PREVCW_FX.b_fx[i] = shr(PREVCW_FX.b_fx[i], temp); + PREVCW_FX.b_fx[i] = shr( PREVCW_FX.b_fx[i], temp ); move16(); } PREVCW_FX.Q = CURRCW_DTFS_out->Q; move16(); } - DTFS_copy_fx(CURRCW_DTFS_FX, *CURRCW_DTFS_out); + DTFS_copy_fx( CURRCW_DTFS_FX, *CURRCW_DTFS_out ); /* Calculating the expected alignment shift */ - alignment_fx = mult_r(*ph_offset_fx, shl(PREVCW_FX.lag_fx, 7)); /* confirmed I<2 by smv12.org, Q7 */ + alignment_fx = mult_r( *ph_offset_fx, shl( PREVCW_FX.lag_fx, 7 ) ); /* confirmed I<2 by smv12.org, Q7 */ - IF (EQ_16(flag,1)) - alignment_fx = extract_l(L_shr(L_mult(alignment_fx, I), 1)) ; /* Q7 */ + IF( EQ_16( flag, 1 ) ) + alignment_fx = extract_l( L_shr( L_mult( alignment_fx, I ), 1 ) ); /* Q7 */ /* Calculating the expected alignment shift */ - find_rem((Word16)N, shr(add(PREVCW_FX.lag_fx, CURRCW_DTFS_FX->lag_fx), 1), &temp); - temp = add(shl(temp, 7), alignment_fx); /* Q7 */ + find_rem( (Word16) N, shr( add( PREVCW_FX.lag_fx, CURRCW_DTFS_FX->lag_fx ), 1 ), &temp ); + temp = add( shl( temp, 7 ), alignment_fx ); /* Q7 */ - IF (temp<0) - temp = add(temp,shl(CURRCW_DTFS_FX->lag_fx,7)); /* Q7 */ + IF( temp < 0 ) + temp = add( temp, shl( CURRCW_DTFS_FX->lag_fx, 7 ) ); /* Q7 */ - find_rem(temp,shl(CURRCW_DTFS_FX->lag_fx, 7),&tmp_fx); /* Q7 */ - IF (FR_flag==0) + find_rem( temp, shl( CURRCW_DTFS_FX->lag_fx, 7 ), &tmp_fx ); /* Q7 */ + IF( FR_flag == 0 ) { - alignment_fx = DTFS_alignment_weight_fx(&PREVCW_FX, *CURRCW_DTFS_FX,tmp_fx, curr_lpc_fx, curr_lpc_fx, S_fx, - C_fx, pf_temp1, pf_temp2, pf_temp, pf_n2); - move16();/* Q7 */ + alignment_fx = DTFS_alignment_weight_fx( &PREVCW_FX, *CURRCW_DTFS_FX, tmp_fx, curr_lpc_fx, curr_lpc_fx, S_fx, + C_fx, pf_temp1, pf_temp2, pf_temp, pf_n2 ); + move16(); /* Q7 */ } ELSE { - alignment_fx = DTFS_alignment_full_fx(PREVCW_FX, *CURRCW_DTFS_FX, *ph_offset_fx, S_fx, C_fx - ,FR_flag - ); + alignment_fx = DTFS_alignment_full_fx( PREVCW_FX, *CURRCW_DTFS_FX, *ph_offset_fx, S_fx, C_fx, FR_flag ); /*alignment_fx is in Q1, we make it Q7*/ - alignment_fx = shl(alignment_fx,6); + alignment_fx = shl( alignment_fx, 6 ); } - IF (GE_16(alignment_fx,shl(CURRCW_DTFS_FX->lag_fx, 7))) + IF( GE_16( alignment_fx, shl( CURRCW_DTFS_FX->lag_fx, 7 ) ) ) { - temp=sub(alignment_fx, shl(CURRCW_DTFS_FX->lag_fx, 7)); - tmp = shl(CURRCW_DTFS_FX->lag_fx, 7); - exp = norm_s(tmp); - tmp = div_s(shl(1,sub(14,exp)),tmp);/* 22-exp */ - L_tmp =L_shl(L_mult(temp,tmp),exp+1); - tmp_fx = round_fx(L_tmp); + temp = sub( alignment_fx, shl( CURRCW_DTFS_FX->lag_fx, 7 ) ); + tmp = shl( CURRCW_DTFS_FX->lag_fx, 7 ); + exp = norm_s( tmp ); + tmp = div_s( shl( 1, sub( 14, exp ) ), tmp ); /* 22-exp */ + L_tmp = L_shl( L_mult( temp, tmp ), exp + 1 ); + tmp_fx = round_fx( L_tmp ); } - ELSE IF (alignment_fx<0) + ELSE IF( alignment_fx < 0 ) { - temp=negate(alignment_fx); - tmp = shl(CURRCW_DTFS_FX->lag_fx, 7); - exp = norm_s(tmp); - tmp = div_s(shl(1,sub(14,exp)),tmp);/* 22-exp */ - L_tmp =L_shl(L_mult(temp,tmp),exp+1); - tmp_fx = negate( round_fx(L_tmp)); + temp = negate( alignment_fx ); + tmp = shl( CURRCW_DTFS_FX->lag_fx, 7 ); + exp = norm_s( tmp ); + tmp = div_s( shl( 1, sub( 14, exp ) ), tmp ); /* 22-exp */ + L_tmp = L_shl( L_mult( temp, tmp ), exp + 1 ); + tmp_fx = negate( round_fx( L_tmp ) ); } ELSE { - temp=alignment_fx; + temp = alignment_fx; move16(); - tmp = shl(CURRCW_DTFS_FX->lag_fx, 7); - exp = norm_s(tmp); - tmp = div_s(shl(1,sub(14,exp)),tmp);/* 22-exp */ - L_tmp =L_shl(L_mult(temp,tmp),exp+1); - tmp_fx = round_fx(L_tmp); + tmp = shl( CURRCW_DTFS_FX->lag_fx, 7 ); + exp = norm_s( tmp ); + tmp = div_s( shl( 1, sub( 14, exp ) ), tmp ); /* 22-exp */ + L_tmp = L_shl( L_mult( temp, tmp ), exp + 1 ); + tmp_fx = round_fx( L_tmp ); } - DTFS_phaseShift_fx(CURRCW_DTFS_FX, alignment_fx, CURRCW_DTFS_FX->lag_fx, S_fx, C_fx) ; /* Qmin */ - DTFS_phaseShift_fx(CURRCW_DTFS_out, alignment_fx, CURRCW_DTFS_out->lag_fx, S_fx, C_fx);/* Qmin */ + DTFS_phaseShift_fx( CURRCW_DTFS_FX, alignment_fx, CURRCW_DTFS_FX->lag_fx, S_fx, C_fx ); /* Qmin */ + DTFS_phaseShift_fx( CURRCW_DTFS_out, alignment_fx, CURRCW_DTFS_out->lag_fx, S_fx, C_fx ); /* Qmin */ /* Compute the cubic phase track and transform to 1-D signal */ - cubicPhase_fx(*ph_offset_fx, tmp_fx, PREVCW_FX.lag_fx , CURRCW_DTFS_FX->lag_fx, N, phase_fx) ; + cubicPhase_fx( *ph_offset_fx, tmp_fx, PREVCW_FX.lag_fx, CURRCW_DTFS_FX->lag_fx, N, phase_fx ); - temp = shr(add(PREVCW_FX.lag_fx,CURRCW_DTFS_FX->lag_fx),1); /* Q0 */ + temp = shr( add( PREVCW_FX.lag_fx, CURRCW_DTFS_FX->lag_fx ), 1 ); /* Q0 */ - IF (FR_flag==0) + IF( FR_flag == 0 ) { - DTFS_transform_fx(PREVCW_FX,*CURRCW_DTFS_FX, phase_fx, out_fx, N, 0) ; + DTFS_transform_fx( PREVCW_FX, *CURRCW_DTFS_FX, phase_fx, out_fx, N, 0 ); } ELSE { - DTFS_transform_fx (PREVCW_FX, *CURRCW_DTFS_FX, phase_fx, out_fx, N, 1) ; + DTFS_transform_fx( PREVCW_FX, *CURRCW_DTFS_FX, phase_fx, out_fx, N, 1 ); } /* Adjust the phase offset and wrap it between 0 and 2pi */ -//PMT("NEED a complete verification of mem flow and assignment") + // PMT("NEED a complete verification of mem flow and assignment") - IF (EQ_16(flag,2)) + IF( EQ_16( flag, 2 ) ) { - L_temp = L_shr(L_mult(tmp_fx, I), 1); /* Q15 */ + L_temp = L_shr( L_mult( tmp_fx, I ), 1 ); /* Q15 */ } ELSE { - L_temp = L_deposit_l(tmp_fx); /* Q15 */ + L_temp = L_deposit_l( tmp_fx ); /* Q15 */ } - FOR ( ; L_temp < 0; L_temp += 0x8000L) + FOR( ; L_temp < 0; L_temp += 0x8000L ) { /* empty loop */ } - L_temp = L_temp&0x7fff; - move16(); /* fraction part */ - *ph_offset_fx = extract_l(L_temp); + L_temp = L_temp & 0x7fff; + move16(); /* fraction part */ + *ph_offset_fx = extract_l( L_temp ); /* free(phase_fx) ; */ - free(CURRCW_DTFS_FX); + free( CURRCW_DTFS_FX ); return error; } - /*===================================================================*/ /* FUNCTION : ppp_extract_pitch_period_fx () */ /*-------------------------------------------------------------------*/ @@ -3364,212 +3332,212 @@ ivas_error WIsyn_fx( /* _ (Word16) spike_near_edge : Q0 */ /*===================================================================*/ Word16 ppp_extract_pitch_period_fx( - const Word16 *in, /* i : input residual */ - Word16 *out, /* o : output residual */ - Word16 l, /* i : lag */ - Word16 *out_of_bound, /* o : out of bound flag */ + const Word16 *in, /* i : input residual */ + Word16 *out, /* o : output residual */ + Word16 l, /* i : lag */ + Word16 *out_of_bound, /* o : out of bound flag */ Word16 Qres ) { - Word16 i,j,k; - Word16 spike=0,range; - Word16 max=0; - const Word16 *ptr=in+L_FRAME-l; - Word32 en1 = 0,Lacc,L_tmp; - Word16 spike_near_edge=0,scale; - Word16 pos_max,neg_max; - Word16 spike_pos=0,spike_neg=0; - Word16 x,tmp,expa,fraca,expb,fracb,scale1,exp; + Word16 i, j, k; + Word16 spike = 0, range; + Word16 max = 0; + const Word16 *ptr = in + L_FRAME - l; + Word32 en1 = 0, Lacc, L_tmp; + Word16 spike_near_edge = 0, scale; + Word16 pos_max, neg_max; + Word16 spike_pos = 0, spike_neg = 0; + Word16 x, tmp, expa, fraca, expb, fracb, scale1, exp; pos_max = -0x8000L; move16(); neg_max = 0; move16(); - *out_of_bound=0; + *out_of_bound = 0; move16(); - en1 = L_deposit_l(0); - FOR (i=0 ; i0) + IF( ptr[spike] > 0 ) { - spike_pos=spike; + spike_pos = spike; move16(); /* search for neg spike around the pos spike */ - FOR(j=spike-10; j0) - tmp = add(tmp,4);/* Q3 */ + IF( tmp > 0 ) + tmp = add( tmp, 4 ); /* Q3 */ ELSE - tmp = sub(tmp,4);/* Q3 */ - range = shr(tmp,3);/* Q0 */ + tmp = sub( tmp, 4 ); /* Q3 */ + range = shr( tmp, 3 ); /* Q0 */ test(); - IF((LT_16(spike,range))||(GE_16(add(spike,range),l))) + IF( ( LT_16( spike, range ) ) || ( GE_16( add( spike, range ), l ) ) ) { /* need to grab from one lag before ensure that there is no array bound read */ - IF(LT_16(sub(L_FRAME,l),l)) + IF( LT_16( sub( L_FRAME, l ), l ) ) { - *out_of_bound=1; + *out_of_bound = 1; move16(); return spike_near_edge; } - spike_near_edge=1; + spike_near_edge = 1; move16(); } - IF(LT_16(spike,range)) + IF( LT_16( spike, range ) ) { - tmp = add(l,sub(spike,range)); - FOR(i=0; i=in) + IF( ptr - l + i >= in ) { - FOR(ptr-=l; i= 0) + IF( time_fx[i] >= 0 ) { - if (GT_32(L_temp,maxPosEn_fx)) + if ( GT_32( L_temp, maxPosEn_fx ) ) { - maxPosEn_fx = L_temp ; /* Q(1) */ + maxPosEn_fx = L_temp; /* Q(1) */ } } ELSE { - if (GT_32(L_temp,maxNegEn_fx)) + if ( GT_32( L_temp, maxNegEn_fx ) ) { - maxNegEn_fx = L_temp ; /* Q(1) */ + maxNegEn_fx = L_temp; /* Q(1) */ } } } - IF (L_sum==0) + IF( L_sum == 0 ) { - *pos_fx=*neg_fx=0; + *pos_fx = *neg_fx = 0; move16(); move16(); } ELSE { - IF (maxPosEn_fx==0) + IF( maxPosEn_fx == 0 ) { - *pos_fx=0; - *Qpos=31; + *pos_fx = 0; + *Qpos = 31; } ELSE { - expa = norm_l(maxPosEn_fx); + expa = norm_l( maxPosEn_fx ); #ifdef BASOP_NOGLOB - fraca = extract_h(L_shl_o(maxPosEn_fx,expa, &Overflow)); + fraca = extract_h( L_shl_o( maxPosEn_fx, expa, &Overflow ) ); #else - fraca = extract_h(L_shl(maxPosEn_fx,expa)); + fraca = extract_h( L_shl( maxPosEn_fx, expa ) ); #endif - expa = sub(30,add(expa,1)); + expa = sub( 30, add( expa, 1 ) ); - expb = norm_l(L_sum); + expb = norm_l( L_sum ); #ifdef BASOP_NOGLOB - fracb = round_fx_o(L_shl_o(L_sum,expb, &Overflow), &Overflow); + fracb = round_fx_o( L_shl_o( L_sum, expb, &Overflow ), &Overflow ); #else - fracb = round_fx(L_shl(L_sum,expb)); + fracb = round_fx( L_shl( L_sum, expb ) ); #endif - expb = sub(30,add(expb,shl(X_fx.Q,1))); + expb = sub( 30, add( expb, shl( X_fx.Q, 1 ) ) ); - scale = shr(sub(fraca,fracb),15); + scale = shr( sub( fraca, fracb ), 15 ); #ifdef BASOP_NOGLOB - fracb = shl_o(fracb,scale, &Overflow); + fracb = shl_o( fracb, scale, &Overflow ); #else - fracb = shl(fracb,scale); + fracb = shl( fracb, scale ); #endif - expb = sub(expb,scale); + expb = sub( expb, scale ); - tmp = div_s(fracb,fraca); - exp = sub(expb,expa); + tmp = div_s( fracb, fraca ); + exp = sub( expb, expa ); - L_tmp = Isqrt_lc(L_deposit_h(tmp),&exp); /* Q(31-exp) */ + L_tmp = Isqrt_lc( L_deposit_h( tmp ), &exp ); /* Q(31-exp) */ *pos_fx = L_tmp; - *Qpos = sub(31, exp); - + *Qpos = sub( 31, exp ); } - IF (maxNegEn_fx==0) + IF( maxNegEn_fx == 0 ) { - *neg_fx=0; - *Qneg=31; + *neg_fx = 0; + *Qneg = 31; } ELSE { - expa = norm_l(maxNegEn_fx); + expa = norm_l( maxNegEn_fx ); #ifdef BASOP_NOGLOB - fraca = extract_h(L_shl_o(maxNegEn_fx,expa, &Overflow)); + fraca = extract_h( L_shl_o( maxNegEn_fx, expa, &Overflow ) ); #else - fraca = extract_h(L_shl(maxNegEn_fx,expa)); + fraca = extract_h( L_shl( maxNegEn_fx, expa ) ); #endif - expa = 30-expa- 1; + expa = 30 - expa - 1; - expb = norm_l(L_sum); + expb = norm_l( L_sum ); #ifdef BASOP_NOGLOB - fracb = round_fx_o(L_shl_o(L_sum,expb, &Overflow), &Overflow); + fracb = round_fx_o( L_shl_o( L_sum, expb, &Overflow ), &Overflow ); #else - fracb = round_fx(L_shl(L_sum,expb)); + fracb = round_fx( L_shl( L_sum, expb ) ); #endif - expb = 30-expb - (2*X_fx.Q); + expb = 30 - expb - ( 2 * X_fx.Q ); - scale = shr(sub(fraca,fracb),15); + scale = shr( sub( fraca, fracb ), 15 ); #ifdef BASOP_NOGLOB - fracb = shl_o(fracb,scale, &Overflow); + fracb = shl_o( fracb, scale, &Overflow ); #else - fracb = shl(fracb,scale); + fracb = shl( fracb, scale ); #endif - expb = sub(expb,scale); + expb = sub( expb, scale ); - tmp = div_s(fracb,fraca); - exp = sub(expb,expa); + tmp = div_s( fracb, fraca ); + exp = sub( expb, expa ); - L_tmp = Isqrt_lc(L_deposit_h(tmp),&exp); /* Q(31-exp) */ + L_tmp = Isqrt_lc( L_deposit_h( tmp ), &exp ); /* Q(31-exp) */ *neg_fx = L_tmp; *Qneg = 31 - exp; - } - } } @@ -3755,18 +3720,18 @@ void DTFS_peaktoaverage_fx( DTFS_STRUCTURE X_fx,Word32 *pos_fx, Word16 *Qpos, Wo /* to setEngyHarm_fx, because the norm factor outputs from */ /* the two previous calls might be different */ /*===================================================================*/ -void rshiftHarmBand_fx( DTFS_STRUCTURE *X_fx,Word16 lband_fx, Word16 hband_fx, Word16 shift_fx) +void rshiftHarmBand_fx( DTFS_STRUCTURE *X_fx, Word16 lband_fx, Word16 hband_fx, Word16 shift_fx ) { Word16 k_fx, HalfLag_fx; Word16 low_fx, high_fx; - low_fx=mult(lband_fx,X_fx->lag_fx); /* low=lband*lag, Q0 */ - high_fx=mult(hband_fx,X_fx->lag_fx); /* high=hband*lag, Q0 */ - HalfLag_fx = s_min(high_fx,shl(X_fx->nH_fx,1)); + low_fx = mult( lband_fx, X_fx->lag_fx ); /* low=lband*lag, Q0 */ + high_fx = mult( hband_fx, X_fx->lag_fx ); /* high=hband*lag, Q0 */ + HalfLag_fx = s_min( high_fx, shl( X_fx->nH_fx, 1 ) ); - FOR (k_fx=low_fx+1; k_fx<=HalfLag_fx; k_fx++) + FOR( k_fx = low_fx + 1; k_fx <= HalfLag_fx; k_fx++ ) { - X_fx->a_fx[k_fx]=shl_r(X_fx->a_fx[k_fx],shift_fx); + X_fx->a_fx[k_fx] = shl_r( X_fx->a_fx[k_fx], shift_fx ); move16(); /* right shift and round */ } } @@ -3794,7 +3759,7 @@ void rshiftHarmBand_fx( DTFS_STRUCTURE *X_fx,Word16 lband_fx, Word16 hband_fx, W /*===================================================================*/ /* NOTE: This function interpolates cos_table for better accuracy */ /*===================================================================*/ -void GetSinCosTab_fx(Word16 L, Word16 *sinTab, Word16 *cosTab) +void GetSinCosTab_fx( Word16 L, Word16 *sinTab, Word16 *cosTab ) { Word16 i, L4; Word16 dl, t1, w, dt; @@ -3803,81 +3768,79 @@ void GetSinCosTab_fx(Word16 L, Word16 *sinTab, Word16 *cosTab) Word32 Ltemp, Lw; Word32 L_tmp; - invL = L_shr(inverse_table[L],4); + invL = L_shr( inverse_table[L], 4 ); - L4=shl(L,2); - Lw = L_deposit_l(0); - FOR (i=0 ; i 0; k -= size) + FOR( k = 256; k > 0; k -= size ) { - K=add(K,1); /* K=512/size */ + K = add( K, 1 ); /* K=512/size */ } - n_2=shr(size,1); - FOR (i=1; i<=stage; i++) ii_table[i-1]=shr(size,i); + n_2 = shr( size, 1 ); + FOR( i = 1; i <= stage; i++ ) + ii_table[i - 1] = shr( size, i ); /* Rearrange the input array in bit reversed order */ j = 0; move16(); - FOR (i = 0 ; i < size - 2; i = i + 2) + FOR( i = 0; i < size - 2; i = i + 2 ) { move16(); move16(); @@ -3906,23 +3870,23 @@ static void c_fft_wi_fx(Word16 * farray_ptr_fx, Word16 size, Word16 stage, Word1 move16(); move16(); - IF (GT_16(j,i)) + IF( GT_16( j, i ) ) { - ftmp_fx = *(farray_ptr_fx + i); - *(farray_ptr_fx + i) = *(farray_ptr_fx + j); - *(farray_ptr_fx + j) = (Word16) ftmp_fx; + ftmp_fx = *( farray_ptr_fx + i ); + *( farray_ptr_fx + i ) = *( farray_ptr_fx + j ); + *( farray_ptr_fx + j ) = (Word16) ftmp_fx; - ftmp_fx = *(farray_ptr_fx + i + 1); - *(farray_ptr_fx + i + 1) = *(farray_ptr_fx + j + 1); - *(farray_ptr_fx + j + 1) = (Word16)ftmp_fx; + ftmp_fx = *( farray_ptr_fx + i + 1 ); + *( farray_ptr_fx + i + 1 ) = *( farray_ptr_fx + j + 1 ); + *( farray_ptr_fx + j + 1 ) = (Word16) ftmp_fx; } k = n_2; move16(); - WHILE (j >= k) + WHILE( j >= k ) { - j = sub(j, k); - k = shr(k, 1); + j = sub( j, k ); + k = shr( k, 1 ); } j += k; } @@ -3930,54 +3894,53 @@ static void c_fft_wi_fx(Word16 * farray_ptr_fx, Word16 size, Word16 stage, Word1 /* The FFT part */ - - IF (isign == 1) + IF( isign == 1 ) { - FOR (i = 0; i < stage; i++) /* i is stage counter */ + FOR( i = 0; i < stage; i++ ) /* i is stage counter */ { - jj = shl(2, i); /* FFT size */ - kk = shl(jj, 1); /* 2 * FFT size */ + jj = shl( 2, i ); /* FFT size */ + kk = shl( jj, 1 ); /* 2 * FFT size */ move16(); - ii = ii_table[i]; /* 2 * number of FFT's */ + ii = ii_table[i]; /* 2 * number of FFT's */ - FOR (j = 0; j < jj; j = j + 2) /* j is sample counter */ + FOR( j = 0; j < jj; j = j + 2 ) /* j is sample counter */ { - ji = j * ii; /* ji is phase table index */ + ji = j * ii; /* ji is phase table index */ - FOR (k = j; k < size; k = k + kk) /* k is butterfly top */ + FOR( k = j; k < size; k = k + kk ) /* k is butterfly top */ { - kj = add(k, jj); /* kj is butterfly bottom */ - temp_sand = s_and((ji*K+384),511); + kj = add( k, jj ); /* kj is butterfly bottom */ + temp_sand = s_and( ( ji * K + 384 ), 511 ); /* Butterfly computations */ /* ftmp_real_fx = L_sub(L_mult(*(farray_ptr_fx + kj), cos_table[ji*K]), */ /* L_mult(*(farray_ptr_fx + kj + 1), cos_table[(ji*K+384)%512])); */ - ftmp_real_fx = L_msu(L_mult(*(farray_ptr_fx + kj), cos_table[ji*K]), - *(farray_ptr_fx + kj + 1), cos_table[temp_sand]); + ftmp_real_fx = L_msu( L_mult( *( farray_ptr_fx + kj ), cos_table[ji * K] ), + *( farray_ptr_fx + kj + 1 ), cos_table[temp_sand] ); /* ftmp_imag_fx = L_add(L_mult(*(farray_ptr_fx + kj + 1), cos_table[ji*K]), */ /* L_mult(*(farray_ptr_fx + kj), cos_table[(ji*K+384)%512])); */ - ftmp_imag_fx = L_mac(L_mult(*(farray_ptr_fx + kj + 1), cos_table[ji*K]), - *(farray_ptr_fx + kj), cos_table[temp_sand]); + ftmp_imag_fx = L_mac( L_mult( *( farray_ptr_fx + kj + 1 ), cos_table[ji * K] ), + *( farray_ptr_fx + kj ), cos_table[temp_sand] ); - tmp1 = round_fx(ftmp_real_fx); - tmp2 = round_fx(ftmp_imag_fx); + tmp1 = round_fx( ftmp_real_fx ); + tmp2 = round_fx( ftmp_imag_fx ); - tmp = sub(*(farray_ptr_fx + k), tmp1); - *(farray_ptr_fx + kj) = shr(tmp, 1); + tmp = sub( *( farray_ptr_fx + k ), tmp1 ); + *( farray_ptr_fx + kj ) = shr( tmp, 1 ); move16(); - tmp = sub(*(farray_ptr_fx + k + 1), tmp2); - *(farray_ptr_fx + kj + 1) = shr(tmp, 1); + tmp = sub( *( farray_ptr_fx + k + 1 ), tmp2 ); + *( farray_ptr_fx + kj + 1 ) = shr( tmp, 1 ); move16(); - tmp = add(*(farray_ptr_fx + k), tmp1); - *(farray_ptr_fx + k) = shr(tmp, 1); + tmp = add( *( farray_ptr_fx + k ), tmp1 ); + *( farray_ptr_fx + k ) = shr( tmp, 1 ); move16(); - tmp = add(*(farray_ptr_fx + k + 1), tmp2); - *(farray_ptr_fx + k + 1) = shr(tmp, 1); + tmp = add( *( farray_ptr_fx + k + 1 ), tmp2 ); + *( farray_ptr_fx + k + 1 ) = shr( tmp, 1 ); move16(); } } @@ -3987,51 +3950,51 @@ static void c_fft_wi_fx(Word16 * farray_ptr_fx, Word16 size, Word16 stage, Word1 } ELSE { - FOR (i = 0; i < stage; i++) /* i is stage counter */ + FOR( i = 0; i < stage; i++ ) /* i is stage counter */ { - jj = shl(2, i); /* FFT size */ - kk = shl(jj, 1); /* 2 * FFT size */ - ii = ii_table[i]; /* 2 * number of FFT's */ + jj = shl( 2, i ); /* FFT size */ + kk = shl( jj, 1 ); /* 2 * FFT size */ + ii = ii_table[i]; /* 2 * number of FFT's */ - FOR (j = 0; j < jj; j = j + 2) /* j is sample counter */ + FOR( j = 0; j < jj; j = j + 2 ) /* j is sample counter */ { - ji = j * ii; /* ji is phase table index */ + ji = j * ii; /* ji is phase table index */ - FOR (k = j; k < size; k = k + kk) /* k is butterfly top */ + FOR( k = j; k < size; k = k + kk ) /* k is butterfly top */ { - kj = add(k, jj); /* kj is butterfly bottom */ - temp_sand = s_and((ji*K+384),511); + kj = add( k, jj ); /* kj is butterfly bottom */ + temp_sand = s_and( ( ji * K + 384 ), 511 ); /* Butterfly computations */ /* ftmp_real_fx = L_add(L_mult(*(farray_ptr_fx + kj), cos_table[ji*K]), */ /* L_mult(*(farray_ptr_fx + kj + 1), cos_table[(ji*K+384)%512])); */ - ftmp_real_fx = L_mac(L_mult(*(farray_ptr_fx + kj), cos_table[ji*K]), - *(farray_ptr_fx + kj + 1), cos_table[temp_sand]); + ftmp_real_fx = L_mac( L_mult( *( farray_ptr_fx + kj ), cos_table[ji * K] ), + *( farray_ptr_fx + kj + 1 ), cos_table[temp_sand] ); /* ftmp_imag_fx = L_sub(L_mult(*(farray_ptr_fx + kj + 1), cos_table[ji*K]), */ /* L_mult(*(farray_ptr_fx + kj), cos_table[(ji*K+384)%512])); */ - ftmp_imag_fx = L_msu(L_mult(*(farray_ptr_fx + kj + 1), cos_table[ji*K]), - *(farray_ptr_fx + kj), cos_table[temp_sand]); + ftmp_imag_fx = L_msu( L_mult( *( farray_ptr_fx + kj + 1 ), cos_table[ji * K] ), + *( farray_ptr_fx + kj ), cos_table[temp_sand] ); - tmp1 = round_fx(ftmp_real_fx); - tmp2 = round_fx(ftmp_imag_fx); + tmp1 = round_fx( ftmp_real_fx ); + tmp2 = round_fx( ftmp_imag_fx ); #ifdef BASOP_NOGLOB *( farray_ptr_fx + kj ) = sub_sat( *( farray_ptr_fx + k ), tmp1 ); move16(); - *(farray_ptr_fx + kj + 1) = sub_sat(*(farray_ptr_fx + k + 1), tmp2); + *( farray_ptr_fx + kj + 1 ) = sub_sat( *( farray_ptr_fx + k + 1 ), tmp2 ); move16(); - *(farray_ptr_fx + k) = add_sat(*(farray_ptr_fx + k), tmp1); + *( farray_ptr_fx + k ) = add_sat( *( farray_ptr_fx + k ), tmp1 ); move16(); - *(farray_ptr_fx + k + 1) = add_sat(*(farray_ptr_fx + k + 1), tmp2); + *( farray_ptr_fx + k + 1 ) = add_sat( *( farray_ptr_fx + k + 1 ), tmp2 ); move16(); #else - *(farray_ptr_fx + kj) = sub(*(farray_ptr_fx + k), tmp1); + *( farray_ptr_fx + kj ) = sub( *( farray_ptr_fx + k ), tmp1 ); move16(); - *(farray_ptr_fx + kj + 1) = sub(*(farray_ptr_fx + k + 1), tmp2); + *( farray_ptr_fx + kj + 1 ) = sub( *( farray_ptr_fx + k + 1 ), tmp2 ); move16(); - *(farray_ptr_fx + k) = add(*(farray_ptr_fx + k), tmp1); + *( farray_ptr_fx + k ) = add( *( farray_ptr_fx + k ), tmp1 ); move16(); - *(farray_ptr_fx + k + 1) = add(*(farray_ptr_fx + k + 1), tmp2); + *( farray_ptr_fx + k + 1 ) = add( *( farray_ptr_fx + k + 1 ), tmp2 ); move16(); #endif } @@ -4039,70 +4002,69 @@ static void c_fft_wi_fx(Word16 * farray_ptr_fx, Word16 size, Word16 stage, Word1 } } -} /* end of c_fft () */ +} /* end of c_fft () */ -void r_fft_4_fx(Word16 * farray_ptr_fx, Word16 size, Word16 stage, Word16 isign) +void r_fft_4_fx( Word16 *farray_ptr_fx, Word16 size, Word16 stage, Word16 isign ) { Word16 ftmp1_real_fx, ftmp1_imag_fx, ftmp2_real_fx, ftmp2_imag_fx; Word32 Lftmp1_real_fx, Lftmp1_imag_fx; - Word16 i, j,temp_sand; + Word16 i, j, temp_sand; Word32 Ltmp1_fx, Ltmp2_fx; Word16 n_2, k, K; - n_2 = shr(size,1); - K=0; + n_2 = shr( size, 1 ); + K = 0; move16(); - FOR (k = 256; k > 0; k -= size) + FOR( k = 256; k > 0; k -= size ) { - K = add(K,1); /* K=512/size */ + K = add( K, 1 ); /* K=512/size */ } /* The FFT part */ - IF (isign == 1) + IF( isign == 1 ) { /* Perform the complex FFT */ - c_fft_wi_fx(farray_ptr_fx, size, stage, isign); + c_fft_wi_fx( farray_ptr_fx, size, stage, isign ); /* First, handle the DC and foldover frequencies */ ftmp1_real_fx = *farray_ptr_fx; - ftmp2_real_fx = *(farray_ptr_fx + 1); - *farray_ptr_fx = add(ftmp1_real_fx, ftmp2_real_fx); - *(farray_ptr_fx + 1) = sub(ftmp1_real_fx, ftmp2_real_fx); + ftmp2_real_fx = *( farray_ptr_fx + 1 ); + *farray_ptr_fx = add( ftmp1_real_fx, ftmp2_real_fx ); + *( farray_ptr_fx + 1 ) = sub( ftmp1_real_fx, ftmp2_real_fx ); /* Now, handle the remaining positive frequencies */ j = size - 2; - FOR (i = 2; i <= n_2; i = i + 2 ) + FOR( i = 2; i <= n_2; i = i + 2 ) { - ftmp1_real_fx = add(*(farray_ptr_fx + i), *(farray_ptr_fx + j)); - ftmp1_imag_fx = sub(*(farray_ptr_fx + i + 1), *(farray_ptr_fx + j + 1)); - ftmp2_real_fx = add(*(farray_ptr_fx + i + 1), *(farray_ptr_fx + j + 1)); - ftmp2_imag_fx = sub(*(farray_ptr_fx + j), *(farray_ptr_fx + i)); - - Lftmp1_real_fx = L_deposit_h(ftmp1_real_fx); - Lftmp1_imag_fx = L_deposit_h(ftmp1_imag_fx); - temp_sand = s_and((i*K+384),511); + ftmp1_real_fx = add( *( farray_ptr_fx + i ), *( farray_ptr_fx + j ) ); + ftmp1_imag_fx = sub( *( farray_ptr_fx + i + 1 ), *( farray_ptr_fx + j + 1 ) ); + ftmp2_real_fx = add( *( farray_ptr_fx + i + 1 ), *( farray_ptr_fx + j + 1 ) ); + ftmp2_imag_fx = sub( *( farray_ptr_fx + j ), *( farray_ptr_fx + i ) ); + + Lftmp1_real_fx = L_deposit_h( ftmp1_real_fx ); + Lftmp1_imag_fx = L_deposit_h( ftmp1_imag_fx ); + temp_sand = s_and( ( i * K + 384 ), 511 ); /* Ltmp1_fx = L_sub(L_mult(ftmp2_real_fx, cos_table[i*K]), L_mult(ftmp2_imag_fx, cos_table[(i*K+384)%512])); */ - Ltmp1_fx = L_msu(L_mult(ftmp2_real_fx, cos_table[i*K]), ftmp2_imag_fx, cos_table[temp_sand]); - *(farray_ptr_fx + i) = round_fx(L_shr(L_add(Lftmp1_real_fx, Ltmp1_fx), 1)); + Ltmp1_fx = L_msu( L_mult( ftmp2_real_fx, cos_table[i * K] ), ftmp2_imag_fx, cos_table[temp_sand] ); + *( farray_ptr_fx + i ) = round_fx( L_shr( L_add( Lftmp1_real_fx, Ltmp1_fx ), 1 ) ); /* Ltmp1_fx = L_add(L_mult(ftmp2_imag_fx, cos_table[i*K]), L_mult(ftmp2_real_fx, cos_table[(i*K+384)%512])); */ - Ltmp1_fx = L_mac(L_mult(ftmp2_imag_fx, cos_table[i*K]), ftmp2_real_fx, cos_table[temp_sand]); - *(farray_ptr_fx + i + 1) = round_fx(L_shr(L_add(Lftmp1_imag_fx, Ltmp1_fx), 1)); + Ltmp1_fx = L_mac( L_mult( ftmp2_imag_fx, cos_table[i * K] ), ftmp2_real_fx, cos_table[temp_sand] ); + *( farray_ptr_fx + i + 1 ) = round_fx( L_shr( L_add( Lftmp1_imag_fx, Ltmp1_fx ), 1 ) ); /* Ltmp1_fx = L_add(L_mult(ftmp2_real_fx, cos_table[j*K]), L_mult(ftmp2_imag_fx, cos_table[(j*K+384)%512])); */ - Ltmp1_fx = L_mac(L_mult(ftmp2_real_fx, cos_table[j*K]), ftmp2_imag_fx, cos_table[temp_sand]); - *(farray_ptr_fx + j) = round_fx(L_shr(L_add(Lftmp1_real_fx, Ltmp1_fx), 1)); + Ltmp1_fx = L_mac( L_mult( ftmp2_real_fx, cos_table[j * K] ), ftmp2_imag_fx, cos_table[temp_sand] ); + *( farray_ptr_fx + j ) = round_fx( L_shr( L_add( Lftmp1_real_fx, Ltmp1_fx ), 1 ) ); /* Ltmp1_fx = L_add(L_negate(L_mult(ftmp2_imag_fx, cos_table[j*K])), L_mult(ftmp2_real_fx, cos_table[(j*K+384)%512])); */ - Ltmp1_fx = L_msu(L_mult(ftmp2_real_fx, cos_table[temp_sand]), ftmp2_imag_fx, cos_table[j*K]); - Ltmp2_fx = L_sub(Ltmp1_fx, Lftmp1_imag_fx); - *(farray_ptr_fx + j + 1) = round_fx(L_shr(Ltmp2_fx, 1)); + Ltmp1_fx = L_msu( L_mult( ftmp2_real_fx, cos_table[temp_sand] ), ftmp2_imag_fx, cos_table[j * K] ); + Ltmp2_fx = L_sub( Ltmp1_fx, Lftmp1_imag_fx ); + *( farray_ptr_fx + j + 1 ) = round_fx( L_shr( Ltmp2_fx, 1 ) ); j = size - i; } - } ELSE { @@ -4113,48 +4075,46 @@ void r_fft_4_fx(Word16 * farray_ptr_fx, Word16 size, Word16 stage, Word16 isign) move16(); ftmp1_real_fx = *farray_ptr_fx; - ftmp2_real_fx = *(farray_ptr_fx + 1); - *farray_ptr_fx = shr(add(ftmp1_real_fx, ftmp2_real_fx), 1); + ftmp2_real_fx = *( farray_ptr_fx + 1 ); + *farray_ptr_fx = shr( add( ftmp1_real_fx, ftmp2_real_fx ), 1 ); move16(); - *(farray_ptr_fx + 1) = shr(sub(ftmp1_real_fx, ftmp2_real_fx), 1); + *( farray_ptr_fx + 1 ) = shr( sub( ftmp1_real_fx, ftmp2_real_fx ), 1 ); move16(); /* Now, handle the remaining positive frequencies */ - FOR (i = 2; i <= n_2; i += 2) + FOR( i = 2; i <= n_2; i += 2 ) { - j = sub(size, i); + j = sub( size, i ); - ftmp1_real_fx = add(*(farray_ptr_fx + i), *(farray_ptr_fx + j)); - ftmp1_imag_fx = sub(*(farray_ptr_fx + i + 1), *(farray_ptr_fx + j + 1)); - ftmp2_real_fx = negate(add(*(farray_ptr_fx + j + 1), *(farray_ptr_fx + i + 1))); - ftmp2_imag_fx = negate(sub(*(farray_ptr_fx + j), *(farray_ptr_fx + i))); + ftmp1_real_fx = add( *( farray_ptr_fx + i ), *( farray_ptr_fx + j ) ); + ftmp1_imag_fx = sub( *( farray_ptr_fx + i + 1 ), *( farray_ptr_fx + j + 1 ) ); + ftmp2_real_fx = negate( add( *( farray_ptr_fx + j + 1 ), *( farray_ptr_fx + i + 1 ) ) ); + ftmp2_imag_fx = negate( sub( *( farray_ptr_fx + j ), *( farray_ptr_fx + i ) ) ); - Lftmp1_real_fx = L_deposit_h(ftmp1_real_fx); - Lftmp1_imag_fx = L_deposit_h(ftmp1_imag_fx); - temp_sand = s_and((i*K+384),511); + Lftmp1_real_fx = L_deposit_h( ftmp1_real_fx ); + Lftmp1_imag_fx = L_deposit_h( ftmp1_imag_fx ); + temp_sand = s_and( ( i * K + 384 ), 511 ); /* Ltmp1_fx = L_add(L_mult(ftmp2_real_fx, cos_table[i*K]), L_mult(ftmp2_imag_fx, cos_table[(i*K+384)%512])); */ - Ltmp1_fx = L_mac(L_mult(ftmp2_real_fx, cos_table[i*K]), ftmp2_imag_fx, cos_table[ temp_sand]); - *(farray_ptr_fx + i) = round_fx(L_shr(L_add(Lftmp1_real_fx, Ltmp1_fx), 1)); + Ltmp1_fx = L_mac( L_mult( ftmp2_real_fx, cos_table[i * K] ), ftmp2_imag_fx, cos_table[temp_sand] ); + *( farray_ptr_fx + i ) = round_fx( L_shr( L_add( Lftmp1_real_fx, Ltmp1_fx ), 1 ) ); /* Ltmp1_fx = L_sub(L_mult(ftmp2_imag_fx, cos_table[i*K]), L_mult(ftmp2_real_fx, cos_table[(i*K+384)%512])); */ - Ltmp1_fx = L_msu(L_mult(ftmp2_imag_fx, cos_table[i*K]), ftmp2_real_fx, cos_table[ temp_sand]); - *(farray_ptr_fx + i + 1) = round_fx(L_shr(L_add(Lftmp1_imag_fx, Ltmp1_fx), 1)); + Ltmp1_fx = L_msu( L_mult( ftmp2_imag_fx, cos_table[i * K] ), ftmp2_real_fx, cos_table[temp_sand] ); + *( farray_ptr_fx + i + 1 ) = round_fx( L_shr( L_add( Lftmp1_imag_fx, Ltmp1_fx ), 1 ) ); /* Ltmp1_fx = L_sub(L_mult(ftmp2_real_fx, cos_table[j*K]), L_mult(ftmp2_imag_fx, cos_table[(j*K+384)%512])); */ - Ltmp1_fx = L_msu(L_mult(ftmp2_real_fx, cos_table[j*K]), ftmp2_imag_fx, cos_table[temp_sand]); - *(farray_ptr_fx + j) = round_fx(L_shr(L_add(Lftmp1_real_fx, Ltmp1_fx), 1)); + Ltmp1_fx = L_msu( L_mult( ftmp2_real_fx, cos_table[j * K] ), ftmp2_imag_fx, cos_table[temp_sand] ); + *( farray_ptr_fx + j ) = round_fx( L_shr( L_add( Lftmp1_real_fx, Ltmp1_fx ), 1 ) ); /* Ltmp1_fx = L_negate(L_add(L_mult(ftmp2_imag_fx, cos_table[j*K]), L_mult(ftmp2_real_fx, cos_table[(j*K+384)%512]))); */ - Ltmp1_fx = L_negate(L_mac(L_mult(ftmp2_imag_fx, cos_table[j*K]), ftmp2_real_fx, cos_table[temp_sand])); - Ltmp2_fx = L_sub(Ltmp1_fx, Lftmp1_imag_fx); - *(farray_ptr_fx + j + 1) = round_fx(L_shr(Ltmp2_fx, 1)); + Ltmp1_fx = L_negate( L_mac( L_mult( ftmp2_imag_fx, cos_table[j * K] ), ftmp2_real_fx, cos_table[temp_sand] ) ); + Ltmp2_fx = L_sub( Ltmp1_fx, Lftmp1_imag_fx ); + *( farray_ptr_fx + j + 1 ) = round_fx( L_shr( Ltmp2_fx, 1 ) ); } /* Perform the complex IFFT */ - c_fft_wi_fx(farray_ptr_fx, size, stage, isign); - + c_fft_wi_fx( farray_ptr_fx, size, stage, isign ); } - } @@ -4192,98 +4152,97 @@ void r_fft_4_fx(Word16 * farray_ptr_fx, Word16 size, Word16 stage, Word16 isign) /* X.a[k]=2*X2.a[k]/sqrt(X1.a[k]^2+X1.b[k]^2)*X1.a[k] */ /* X.b[k]=2*X2.a[k]/sqrt(X1.a[k]^2+X1.b[k]^2)*X1.b[k] */ /*===================================================================*/ -void copy_phase_fx( DTFS_STRUCTURE *X1_fx, DTFS_STRUCTURE X2_fx, DTFS_STRUCTURE *retX_fx) +void copy_phase_fx( DTFS_STRUCTURE *X1_fx, DTFS_STRUCTURE X2_fx, DTFS_STRUCTURE *retX_fx ) { /* DTFS_fx X; */ Word16 k, q, sn, cn, HalfLag; Word16 d1h, d1l; - Word32 Ltemp_fx,L_tmp; + Word32 Ltemp_fx, L_tmp; Word32 Lacc_fx; - Word16 exp,tmp,exp1; + Word16 exp, tmp, exp1; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif move16(); - retX_fx->lag_fx=X1_fx->lag_fx; - retX_fx->Q = sub(X2_fx.Q,1); /* equivalent to 2x MIN_FX(shr(sub(X_fx->lag_fx,1),1),X_fx->nH_fx) */ - HalfLag = s_min(shr(X1_fx->lag_fx,1),X1_fx->nH_fx); + retX_fx->lag_fx = X1_fx->lag_fx; + retX_fx->Q = sub( X2_fx.Q, 1 ); /* equivalent to 2x MIN_FX(shr(sub(X_fx->lag_fx,1),1),X_fx->nH_fx) */ + HalfLag = s_min( shr( X1_fx->lag_fx, 1 ), X1_fx->nH_fx ); move16(); - FOR ( k=1; k<=HalfLag; k++ ) + FOR( k = 1; k <= HalfLag; k++ ) { #ifdef BASOP_NOGLOB - Lacc_fx=L_mult_o(X1_fx->a_fx[k],X1_fx->a_fx[k], &Overflow); - Lacc_fx = L_mac_o(Lacc_fx,X1_fx->b_fx[k],X1_fx->b_fx[k], &Overflow); /* 2*Q+1 */ + Lacc_fx = L_mult_o( X1_fx->a_fx[k], X1_fx->a_fx[k], &Overflow ); + Lacc_fx = L_mac_o( Lacc_fx, X1_fx->b_fx[k], X1_fx->b_fx[k], &Overflow ); /* 2*Q+1 */ #else - Lacc_fx=L_mult(X1_fx->a_fx[k],X1_fx->a_fx[k]); - Lacc_fx = L_mac(Lacc_fx,X1_fx->b_fx[k],X1_fx->b_fx[k]); /* 2*Q+1 */ + Lacc_fx = L_mult( X1_fx->a_fx[k], X1_fx->a_fx[k] ); + Lacc_fx = L_mac( Lacc_fx, X1_fx->b_fx[k], X1_fx->b_fx[k] ); /* 2*Q+1 */ #endif - exp = norm_l(Lacc_fx); - tmp = extract_h(L_shl(Lacc_fx,exp)); - exp1 = sub(sub(30,exp),2*X1_fx->Q+1); + exp = norm_l( Lacc_fx ); + tmp = extract_h( L_shl( Lacc_fx, exp ) ); + exp1 = sub( sub( 30, exp ), 2 * X1_fx->Q + 1 ); - IF(tmp) - tmp = div_s(16384,tmp); /* 15+exp1 */ + IF( tmp ) + tmp = div_s( 16384, tmp ); /* 15+exp1 */ ELSE - tmp = 0; - tmp = shr(tmp,1); - q = 15+exp1+16-1; + tmp = 0; + tmp = shr( tmp, 1 ); + q = 15 + exp1 + 16 - 1; - IF(tmp) + IF( tmp ) { - exp = norm_s(tmp); - tmp = shl(tmp, exp); - tmp = div_s(16384, tmp); - L_tmp = L_deposit_h(tmp); - Ltemp_fx = Isqrt_lc(L_tmp,&exp); /* Q(31-exp) */ + exp = norm_s( tmp ); + tmp = shl( tmp, exp ); + tmp = div_s( 16384, tmp ); + L_tmp = L_deposit_h( tmp ); + Ltemp_fx = Isqrt_lc( L_tmp, &exp ); /* Q(31-exp) */ } ELSE - Ltemp_fx = 0; + Ltemp_fx = 0; - if (s_and(q, 1)) - Ltemp_fx = Mult_32_16(Ltemp_fx, 23170); /* 23170 is 1/sqrt(2) in Q15 */ + if ( s_and( q, 1 ) ) + Ltemp_fx = Mult_32_16( Ltemp_fx, 23170 ); /* 23170 is 1/sqrt(2) in Q15 */ - q = shr(q,1); /* Ltemp_fx in Q(q+16) */ + q = shr( q, 1 ); /* Ltemp_fx in Q(q+16) */ - d1h=extract_h(Ltemp_fx); - d1l=extract_l(Ltemp_fx); + d1h = extract_h( Ltemp_fx ); + d1l = extract_l( Ltemp_fx ); #ifdef BASOP_NOGLOB - Ltemp_fx = L_mult0(X1_fx->b_fx[k],d1l); - Ltemp_fx = L_add_o(L_shr(Ltemp_fx,15),L_mult_o(X1_fx->b_fx[k],d1h, &Overflow), &Overflow); /* sin(w) in Q(q+16+Q-15) */ - sn = round_fx_o(L_shl_o(Ltemp_fx,sub(30,add(q,X1_fx->Q)), &Overflow), &Overflow); /* Q15 */ - retX_fx->b_fx[k] = mult_ro(X2_fx.a_fx[k],sn, &Overflow); /* X2_fx.Q */ - - Ltemp_fx = L_mult0(X1_fx->a_fx[k],d1l); - Ltemp_fx = L_add_o(L_shr(Ltemp_fx,15),L_mult_o(X1_fx->a_fx[k],d1h, &Overflow), &Overflow); /* cos(w) in Q(q+Q+1) */ - cn = round_fx_o(L_shl_o(Ltemp_fx,sub(30,add(q,X1_fx->Q)), &Overflow), &Overflow); /* Q15 */ - retX_fx->a_fx[k] = mult_ro(X2_fx.a_fx[k],cn, &Overflow); /* X2_fx.Q */ + Ltemp_fx = L_mult0( X1_fx->b_fx[k], d1l ); + Ltemp_fx = L_add_o( L_shr( Ltemp_fx, 15 ), L_mult_o( X1_fx->b_fx[k], d1h, &Overflow ), &Overflow ); /* sin(w) in Q(q+16+Q-15) */ + sn = round_fx_o( L_shl_o( Ltemp_fx, sub( 30, add( q, X1_fx->Q ) ), &Overflow ), &Overflow ); /* Q15 */ + retX_fx->b_fx[k] = mult_ro( X2_fx.a_fx[k], sn, &Overflow ); /* X2_fx.Q */ + + Ltemp_fx = L_mult0( X1_fx->a_fx[k], d1l ); + Ltemp_fx = L_add_o( L_shr( Ltemp_fx, 15 ), L_mult_o( X1_fx->a_fx[k], d1h, &Overflow ), &Overflow ); /* cos(w) in Q(q+Q+1) */ + cn = round_fx_o( L_shl_o( Ltemp_fx, sub( 30, add( q, X1_fx->Q ) ), &Overflow ), &Overflow ); /* Q15 */ + retX_fx->a_fx[k] = mult_ro( X2_fx.a_fx[k], cn, &Overflow ); /* X2_fx.Q */ #else - Ltemp_fx = L_mult0(X1_fx->b_fx[k], d1l); - Ltemp_fx = L_add(L_shr(Ltemp_fx, 15), L_mult(X1_fx->b_fx[k], d1h)); /* sin(w) in Q(q+16+Q-15) */ - sn = round_fx(L_shl(Ltemp_fx, sub(30, add(q, X1_fx->Q)))); /* Q15 */ - retX_fx->b_fx[k] = mult_r(X2_fx.a_fx[k], sn); /* X2_fx.Q */ - - Ltemp_fx = L_mult0(X1_fx->a_fx[k], d1l); - Ltemp_fx = L_add(L_shr(Ltemp_fx, 15), L_mult(X1_fx->a_fx[k], d1h)); /* cos(w) in Q(q+Q+1) */ - cn = round_fx(L_shl(Ltemp_fx, sub(30, add(q, X1_fx->Q)))); /* Q15 */ - retX_fx->a_fx[k] = mult_r(X2_fx.a_fx[k], cn); /* X2_fx.Q */ + Ltemp_fx = L_mult0( X1_fx->b_fx[k], d1l ); + Ltemp_fx = L_add( L_shr( Ltemp_fx, 15 ), L_mult( X1_fx->b_fx[k], d1h ) ); /* sin(w) in Q(q+16+Q-15) */ + sn = round_fx( L_shl( Ltemp_fx, sub( 30, add( q, X1_fx->Q ) ) ) ); /* Q15 */ + retX_fx->b_fx[k] = mult_r( X2_fx.a_fx[k], sn ); /* X2_fx.Q */ + + Ltemp_fx = L_mult0( X1_fx->a_fx[k], d1l ); + Ltemp_fx = L_add( L_shr( Ltemp_fx, 15 ), L_mult( X1_fx->a_fx[k], d1h ) ); /* cos(w) in Q(q+Q+1) */ + cn = round_fx( L_shl( Ltemp_fx, sub( 30, add( q, X1_fx->Q ) ) ) ); /* Q15 */ + retX_fx->a_fx[k] = mult_r( X2_fx.a_fx[k], cn ); /* X2_fx.Q */ #endif } - k=sub(k,1); + k = sub( k, 1 ); - IF (s_and(X1_fx->lag_fx,1)==0) + IF( s_and( X1_fx->lag_fx, 1 ) == 0 ) { - retX_fx->a_fx[k] = shr(retX_fx->a_fx[k],1); + retX_fx->a_fx[k] = shr( retX_fx->a_fx[k], 1 ); move16(); - retX_fx->b_fx[k] = shr(retX_fx->b_fx[k],1); + retX_fx->b_fx[k] = shr( retX_fx->b_fx[k], 1 ); move16(); } } - /*===================================================================*/ /* FUNCTION : getSpEngyFromResAmp_fx () */ /*-------------------------------------------------------------------*/ @@ -4312,130 +4271,127 @@ void copy_phase_fx( DTFS_STRUCTURE *X1_fx, DTFS_STRUCTURE X2_fx, DTFS_STRUCTURE /*-------------------------------------------------------------------*/ /* CALLED FROM : TX */ /*===================================================================*/ -Word32 getSpEngyFromResAmp_fx( DTFS_STRUCTURE *X_fx,Word16 lband, Word16 hband, - const Word16 *curr_lpc, Word16 *sin_tab, - Word16 *cos_tab) +Word32 getSpEngyFromResAmp_fx( DTFS_STRUCTURE *X_fx, Word16 lband, Word16 hband, const Word16 *curr_lpc, Word16 *sin_tab, Word16 *cos_tab ) { Word16 i, k, k4, n, M_fx, HalfLag; Word16 fdiff, freq; Word32 Ltemp; Word32 Lacc; - Word32 Re, Im; /* Q27 */ + Word32 Re, Im; /* Q27 */ Word32 en; - Word16 exp,tmp,expa,fraca,expb,fracb,scale; + Word16 exp, tmp, expa, fraca, expb, fracb, scale; Word32 L_tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - en = L_deposit_l(0); + en = L_deposit_l( 0 ); - if (EQ_16(hband,X_fx->upper_cut_off_freq_fx)) + if ( EQ_16( hband, X_fx->upper_cut_off_freq_fx ) ) { hband = 0x2803; move16(); /* 4001.0/12800 in Q15 */ } - M_fx=shl(X_fx->lag_fx,2); /* M_fx=4*lag */ + M_fx = shl( X_fx->lag_fx, 2 ); /* M_fx=4*lag */ /* Ltemp=invert_dp(X_fx->lag_fx, 4, &n,1); : Ltemp=1/lag, Q(61-n) */ /* fdiff=round_fx(L_shl(Ltemp,sub(n,26))); : fdiff=1/lag, Q19 */ - exp = norm_s(X_fx->lag_fx); - tmp = div_s(shl(1,sub(14,exp)),X_fx->lag_fx); - L_tmp = L_shl(tmp ,add(exp,6)); - fdiff = round_fx(L_tmp); + exp = norm_s( X_fx->lag_fx ); + tmp = div_s( shl( 1, sub( 14, exp ) ), X_fx->lag_fx ); + L_tmp = L_shl( tmp, add( exp, 6 ) ); + fdiff = round_fx( L_tmp ); - HalfLag = s_min(shr(X_fx->lag_fx,1),X_fx->nH_4kHz_fx); - FOR (k=0; k<=HalfLag; k++) + HalfLag = s_min( shr( X_fx->lag_fx, 1 ), X_fx->nH_4kHz_fx ); + FOR( k = 0; k <= HalfLag; k++ ) { - Ltemp=L_mult(fdiff,k); /* Ltemp=k*fdiff, Q20 */ - freq=extract_h(L_shl(Ltemp,11)); /* k*fdiff in Q15 */ + Ltemp = L_mult( fdiff, k ); /* Ltemp=k*fdiff, Q20 */ + freq = extract_h( L_shl( Ltemp, 11 ) ); /* k*fdiff in Q15 */ test(); - IF (LT_16(freq,hband)&&GE_16(freq,lband)) + IF( LT_16( freq, hband ) && GE_16( freq, lband ) ) { - Lacc = L_add(0x10000000, 0); /* Re=1.0, Q28 */ - k4=shl(k,2); /* k4=4*k */ + Lacc = L_add( 0x10000000, 0 ); /* Re=1.0, Q28 */ + k4 = shl( k, 2 ); /* k4=4*k */ - n=k4; + n = k4; move16(); - FOR (i=0; ia_fx[k],X_fx->a_fx[k]); /* 2*a[k]^2 in 2Q */ + Ltemp = L_mult0( X_fx->a_fx[k], X_fx->a_fx[k] ); /* 2*a[k]^2 in 2Q */ /* Ltemp=(Word32)L_sat32_40(divide_dp(Ltemp,Lacc,-19,1)); : Ltemp in Q(2Q-13) */ - if(Lacc<0) + if ( Lacc < 0 ) { - Lacc = L_negate(Lacc); + Lacc = L_negate( Lacc ); } - IF(Lacc) + IF( Lacc ) { - expa = norm_l(Lacc); - fraca = extract_h(L_shl(Lacc,expa)); - expa = sub(30,add(expa,23)); + expa = norm_l( Lacc ); + fraca = extract_h( L_shl( Lacc, expa ) ); + expa = sub( 30, add( expa, 23 ) ); - expb = norm_l(Ltemp); - fracb = round_fx(L_shl(Ltemp,expb)); - expb = sub(30,add(expb, shl(X_fx->Q,1))); + expb = norm_l( Ltemp ); + fracb = round_fx( L_shl( Ltemp, expb ) ); + expb = sub( 30, add( expb, shl( X_fx->Q, 1 ) ) ); - scale = shr(sub(fraca,fracb),15); - fracb = shl(fracb,scale); - expb = sub(expb,scale); + scale = shr( sub( fraca, fracb ), 15 ); + fracb = shl( fracb, scale ); + expb = sub( expb, scale ); - tmp = div_s(fracb,fraca); /* 15-exp */ - exp = sub(expb,expa); + tmp = div_s( fracb, fraca ); /* 15-exp */ + exp = sub( expb, expa ); #ifdef BASOP_NOGLOB - Ltemp = L_shl_o(tmp, sub(add(shl(X_fx->Q,1),exp), 27), &Overflow) ; + Ltemp = L_shl_o( tmp, sub( add( shl( X_fx->Q, 1 ), exp ), 27 ), &Overflow ); #else - Ltemp = L_shl(tmp, sub(add(shl(X_fx->Q,1),exp), 27)) ; + Ltemp = L_shl( tmp, sub( add( shl( X_fx->Q, 1 ), exp ), 27 ) ); #endif } ELSE { - Ltemp = L_deposit_l(0); + Ltemp = L_deposit_l( 0 ); } test(); - IF (X_fx->lag_fx%2==0 && EQ_16(k,shr(X_fx->lag_fx,1))) - en=L_add(en,L_shr(Ltemp,1)); + IF( X_fx->lag_fx % 2 == 0 && EQ_16( k, shr( X_fx->lag_fx, 1 ) ) ) + en = L_add( en, L_shr( Ltemp, 1 ) ); ELSE - en=L_add(en,Ltemp); /* en in 2Q-13 */ + en = L_add( en, Ltemp ); /* en in 2Q-13 */ } - } - return(en); /* en in 2Q-13 */ + return ( en ); /* en in 2Q-13 */ } /*===================================================================*/ /* FUNCTION : DTFS_poleFilter_fx() */ @@ -4462,126 +4418,125 @@ Word32 getSpEngyFromResAmp_fx( DTFS_STRUCTURE *X_fx,Word16 lband, Word16 hband, /* CALLED FROM : TX/RX */ /*===================================================================*/ -void DTFS_poleFilter_fx( DTFS_STRUCTURE *X_fx,Word16 *LPC, Word16 N, Word16 *S_fx, Word16 *C_fx) +void DTFS_poleFilter_fx( DTFS_STRUCTURE *X_fx, Word16 *LPC, Word16 N, Word16 *S_fx, Word16 *C_fx ) { - Word16 temp, temp1, temp2, HalfLag ; + Word16 temp, temp1, temp2, HalfLag; Word32 sum1_fx, sum2_fx; Word32 sum, L_temp1, L_temp2; Word16 k, n, na, nb; Word16 Qmin, Qab[MAXLAG_WI]; - Word16 exp,tmp; + Word16 exp, tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif Qmin = 32767; move16(); - HalfLag = s_min(shr(X_fx->lag_fx, 1),X_fx->nH_fx); - FOR ( k=0; k<=HalfLag; k++ ) + HalfLag = s_min( shr( X_fx->lag_fx, 1 ), X_fx->nH_fx ); + FOR( k = 0; k <= HalfLag; k++ ) { temp2 = k; move16(); /* Calculate sum1 and sum2 */ - sum1_fx = L_deposit_h(4096); /* 1: Q(12+15+1) */ + sum1_fx = L_deposit_h( 4096 ); /* 1: Q(12+15+1) */ - sum2_fx = L_deposit_l(0); - FOR ( n=0 ; nlag_fx)], &Overflow) ; /* Q(12+15+1) */ - sum2_fx = L_mac_o(sum2_fx, LPC[n], S_fx[(4*temp2)%(4*X_fx->lag_fx)], &Overflow) ; /* Q(12+15+1) */ + sum1_fx = L_mac_o( sum1_fx, LPC[n], C_fx[( 4 * temp2 ) % ( 4 * X_fx->lag_fx )], &Overflow ); /* Q(12+15+1) */ + sum2_fx = L_mac_o( sum2_fx, LPC[n], S_fx[( 4 * temp2 ) % ( 4 * X_fx->lag_fx )], &Overflow ); /* Q(12+15+1) */ #else - sum1_fx = L_mac(sum1_fx, LPC[n], C_fx[(4*temp2)%(4*X_fx->lag_fx)]) ; /* Q(12+15+1) */ - sum2_fx = L_mac(sum2_fx, LPC[n], S_fx[(4*temp2)%(4*X_fx->lag_fx)]) ; /* Q(12+15+1) */ + sum1_fx = L_mac( sum1_fx, LPC[n], C_fx[( 4 * temp2 ) % ( 4 * X_fx->lag_fx )] ); /* Q(12+15+1) */ + sum2_fx = L_mac( sum2_fx, LPC[n], S_fx[( 4 * temp2 ) % ( 4 * X_fx->lag_fx )] ); /* Q(12+15+1) */ #endif - temp2 = add(temp2, k); + temp2 = add( temp2, k ); } #ifdef BASOP_NOGLOB - temp1 = round_fx_o(sum1_fx, &Overflow); /* Q(12+15+1-16)=Q(12) */ - temp2 = round_fx_o(sum2_fx, &Overflow); /* Q(12) */ + temp1 = round_fx_o( sum1_fx, &Overflow ); /* Q(12+15+1-16)=Q(12) */ + temp2 = round_fx_o( sum2_fx, &Overflow ); /* Q(12) */ /* Calculate the circular convolution */ - sum = L_mac_o(L_mult_o(temp1, temp1, &Overflow), temp2, temp2, &Overflow); /* Q(12+12+1)=Q(25) */ + sum = L_mac_o( L_mult_o( temp1, temp1, &Overflow ), temp2, temp2, &Overflow ); /* Q(12+12+1)=Q(25) */ #else - temp1 = round_fx(sum1_fx); /* Q(12+15+1-16)=Q(12) */ - temp2 = round_fx(sum2_fx); /* Q(12) */ + temp1 = round_fx( sum1_fx ); /* Q(12+15+1-16)=Q(12) */ + temp2 = round_fx( sum2_fx ); /* Q(12) */ /* Calculate the circular convolution */ - sum = L_mac(L_mult(temp1, temp1), temp2, temp2); /* Q(12+12+1)=Q(25) */ + sum = L_mac( L_mult( temp1, temp1 ), temp2, temp2 ); /* Q(12+12+1)=Q(25) */ #endif - L_temp1 = L_mult(temp1, X_fx->a_fx[k]); + L_temp1 = L_mult( temp1, X_fx->a_fx[k] ); #ifdef BASOP_NOGLOB - L_temp1 = L_mac_o(L_temp1, temp2, X_fx->b_fx[k], &Overflow); /* Q(12+Q+1)=Q(13+Q) */ + L_temp1 = L_mac_o( L_temp1, temp2, X_fx->b_fx[k], &Overflow ); /* Q(12+Q+1)=Q(13+Q) */ #else - L_temp1 = L_mac(L_temp1, temp2, X_fx->b_fx[k]); /* Q(12+Q+1)=Q(13+Q) */ + L_temp1 = L_mac( L_temp1, temp2, X_fx->b_fx[k] ); /* Q(12+Q+1)=Q(13+Q) */ #endif - L_temp2 = L_mult(temp1, X_fx->b_fx[k]); + L_temp2 = L_mult( temp1, X_fx->b_fx[k] ); #ifdef BASOP_NOGLOB - L_temp2 = L_msu_o(L_temp2, temp2, X_fx->a_fx[k], &Overflow); /* Q(12+Q+1)=Q(13+Q) */ + L_temp2 = L_msu_o( L_temp2, temp2, X_fx->a_fx[k], &Overflow ); /* Q(12+Q+1)=Q(13+Q) */ #else - L_temp2 = L_msu(L_temp2, temp2, X_fx->a_fx[k]); /* Q(12+Q+1)=Q(13+Q) */ + L_temp2 = L_msu( L_temp2, temp2, X_fx->a_fx[k] ); /* Q(12+Q+1)=Q(13+Q) */ #endif - IF(sum) + IF( sum ) { - exp = norm_l(sum); + exp = norm_l( sum ); temp1 = exp; - tmp = extract_h(L_shl(sum,exp)); - exp = sub(sub(30,exp),25); - tmp = div_s(16384,tmp); /* Q(15+exp) */ - sum = L_shl(tmp ,16 ); - temp = round_fx(sum); + tmp = extract_h( L_shl( sum, exp ) ); + exp = sub( sub( 30, exp ), 25 ); + tmp = div_s( 16384, tmp ); /* Q(15+exp) */ + sum = L_shl( tmp, 16 ); + temp = round_fx( sum ); } ELSE { - sum =0; + sum = 0; move16(); - temp =0; + temp = 0; move16(); - temp1 =0; + temp1 = 0; move16(); - } - sum1_fx = Mult_32_16(L_temp1, temp); /* Q(13+Q+20-temp1-15)=Q(Q-temp1+18) */ - sum2_fx = Mult_32_16(L_temp2, temp); /* Q(Q-temp1+18) */ + sum1_fx = Mult_32_16( L_temp1, temp ); /* Q(13+Q+20-temp1-15)=Q(Q-temp1+18) */ + sum2_fx = Mult_32_16( L_temp2, temp ); /* Q(Q-temp1+18) */ /* normalization */ - na = norm_l(sum1_fx); - if (sum1_fx==0) + na = norm_l( sum1_fx ); + if ( sum1_fx == 0 ) { na = 31; move16(); } - nb = norm_l(sum2_fx); - if (sum2_fx==0) + nb = norm_l( sum2_fx ); + if ( sum2_fx == 0 ) { nb = 31; move16(); } - if (LT_16(na, nb)) + if ( LT_16( na, nb ) ) { - nb=na; + nb = na; move16(); } - nb=sub(nb,1); /* leave one more sign bit */ - X_fx->a_fx[k] = round_fx(L_shl(sum1_fx, nb)); /* Q(Q-temp1+22+nb-16)=Q(Q-temp1+nb+2) */ - X_fx->b_fx[k] = round_fx(L_shl(sum2_fx, nb)); /* Q(Q-temp1+nb+2) */ + nb = sub( nb, 1 ); /* leave one more sign bit */ + X_fx->a_fx[k] = round_fx( L_shl( sum1_fx, nb ) ); /* Q(Q-temp1+22+nb-16)=Q(Q-temp1+nb+2) */ + X_fx->b_fx[k] = round_fx( L_shl( sum2_fx, nb ) ); /* Q(Q-temp1+nb+2) */ - Qab[k] = add(sub(add(nb, 2), temp1),X_fx->Q); + Qab[k] = add( sub( add( nb, 2 ), temp1 ), X_fx->Q ); - if (LT_16(Qab[k], Qmin)) + if ( LT_16( Qab[k], Qmin ) ) { Qmin = Qab[k]; move16(); } } /* bring to the same Q */ - FOR ( k=0; k<=HalfLag; k++ ) + FOR( k = 0; k <= HalfLag; k++ ) { - X_fx->a_fx[k] = shl(X_fx->a_fx[k], sub(Qmin, Qab[k])); - move16(); /* Q(Q+Qab[k]+Qmin-Qab[k])=Q(Q+Qmin) */ - X_fx->b_fx[k] = shl(X_fx->b_fx[k], sub(Qmin, Qab[k])); - move16(); /* Q(Q+Qab[k]+Qmin-Qab[k])=Q(Q+Qmin) */ + X_fx->a_fx[k] = shl( X_fx->a_fx[k], sub( Qmin, Qab[k] ) ); + move16(); /* Q(Q+Qab[k]+Qmin-Qab[k])=Q(Q+Qmin) */ + X_fx->b_fx[k] = shl( X_fx->b_fx[k], sub( Qmin, Qab[k] ) ); + move16(); /* Q(Q+Qab[k]+Qmin-Qab[k])=Q(Q+Qmin) */ } X_fx->Q = Qmin; @@ -4610,80 +4565,78 @@ void DTFS_poleFilter_fx( DTFS_STRUCTURE *X_fx,Word16 *LPC, Word16 N, Word16 *S_f /* CALLED FROM : TX/RX */ /*===================================================================*/ -void poleFilter_setup_fx(const Word16 *LPC, Word16 N, DTFS_STRUCTURE X_fx, Word16 *S_fx, Word16 *C_fx, Word16 *pf_temp1, Word16 *pf_temp2, Word16 *pf_temp, Word16 *pf_n2_temp1) +void poleFilter_setup_fx( const Word16 *LPC, Word16 N, DTFS_STRUCTURE X_fx, Word16 *S_fx, Word16 *C_fx, Word16 *pf_temp1, Word16 *pf_temp2, Word16 *pf_temp, Word16 *pf_n2_temp1 ) { - Word16 temp1, temp2, HalfLag ; + Word16 temp1, temp2, HalfLag; Word32 sum1_fx, sum2_fx; Word32 sum; Word16 k, n, n1, n2; - Word16 exp,tmp; + Word16 exp, tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - HalfLag = s_min(shr(X_fx.lag_fx, 1),X_fx.nH_fx); + HalfLag = s_min( shr( X_fx.lag_fx, 1 ), X_fx.nH_fx ); - FOR ( k=0; k<=HalfLag; k++ ) + FOR( k = 0; k <= HalfLag; k++ ) { temp2 = k; move16(); /* Calculate sum1 and sum2 */ - sum1_fx = L_deposit_h(4096); /* 1: Q(12+15+1) */ + sum1_fx = L_deposit_h( 4096 ); /* 1: Q(12+15+1) */ - sum2_fx = L_deposit_l(0); - FOR ( n=0 ; n=102 ); /* if n1 is too low -> overflow in div_l */ + assert( n1 >= 102 ); /* if n1 is too low -> overflow in div_l */ /* cte = PI2/(Float32)(2*n1 - 1); */ BASOP_SATURATE_WARNING_OFF_EVS move16(); - cte = L_deposit_l(div_l(PI2_10Q21,sub(shl(n1,1),1))); /*0Q15*/ + cte = L_deposit_l( div_l( PI2_10Q21, sub( shl( n1, 1 ), 1 ) ) ); /*0Q15*/ BASOP_SATURATE_WARNING_ON_EVS cc = 0; - FOR (i = 0; i < n1; i++) + FOR( i = 0; i < n1; i++ ) { /* fh_f[i] = 0.54f - 0.46f * (Float32)cos(cc); */ BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB - fh[i] = sub_o(P54_0Q15, mult_r(getCosWord16(round_fx_o(L_shl_o(cc,9, &Overflow), &Overflow)),P92_0Q15), &Overflow); /*0Q15*/ move16(); + fh[i] = sub_o( P54_0Q15, mult_r( getCosWord16( round_fx_o( L_shl_o( cc, 9, &Overflow ), &Overflow ) ), P92_0Q15 ), &Overflow ); /*0Q15*/ + move16(); #else - fh[i] = sub(P54_0Q15, mult_r(getCosWord16(round_fx(L_shl(cc,9))),P92_0Q15)); /*0Q15*/ move16(); + fh[i] = sub( P54_0Q15, mult_r( getCosWord16( round_fx( L_shl( cc, 9 ) ) ), P92_0Q15 ) ); /*0Q15*/ + move16(); #endif BASOP_SATURATE_WARNING_ON_EVS - cc = L_add(cc, cte); /*0Q15*/ + cc = L_add( cc, cte ); /*0Q15*/ } - assert( n2>=26 ); /* if n2 is too low -> overflow in div_l */ + assert( n2 >= 26 ); /* if n2 is too low -> overflow in div_l */ /* cte = PI2/(Float32)(4*n2 - 1); */ - cte = L_deposit_l(div_l(PI2_11Q20,sub(shl(n2,2),1))); /*0Q15*/ + cte = L_deposit_l( div_l( PI2_11Q20, sub( shl( n2, 2 ), 1 ) ) ); /*0Q15*/ cc = 0; move16(); - add(n1,n2); + add( n1, n2 ); BASOP_SATURATE_WARNING_OFF_EVS - FOR (i = n1; i < n1+n2; i++) + FOR( i = n1; i < n1 + n2; i++ ) { /* fh_f[i] = (Float32)cos(cc); */ #ifdef BASOP_NOGLOB - fh[i] = shl_o(getCosWord16(round_fx(L_shl(cc, 10))), 1, &Overflow); /*0Q15*/ move16(); + fh[i] = shl_o( getCosWord16( round_fx( L_shl( cc, 10 ) ) ), 1, &Overflow ); /*0Q15*/ + move16(); #else - fh[i] = shl(getCosWord16(round_fx(L_shl(cc,10))),1); /*0Q15*/ move16(); + fh[i] = shl( getCosWord16( round_fx( L_shl( cc, 10 ) ) ), 1 ); /*0Q15*/ + move16(); #endif - cc = L_add(cc, cte); + cc = L_add( cc, cte ); } BASOP_SATURATE_WARNING_ON_EVS @@ -81,32 +84,33 @@ void ham_cos_window( } void ham_cos_window_ivas( - Word16 *fh, /* o: 0Q15 */ - const Word16 n1, /* i: */ - const Word16 n2 /* i: */ + Word16 *fh, /* o: 0Q15 */ + const Word16 n1, /* i: */ + const Word16 n2 /* i: */ ) { Word16 cc_fx; Word16 i; // cte = PI2 / (float) ( 2 * n1 - 1 ); - //cte_fx = div_s(1, sub(shl(n1, 1), 1)); + // cte_fx = div_s(1, sub(shl(n1, 1), 1)); cc_fx = 0; move16(); for ( i = 0; i < n1; i++ ) { - *fh++ = sub(17694, mult(getCosWord16R2( cc_fx ), 15073)); - cc_fx = div_s(add(i, 1), sub(shl(n1, 1), 1));//add(cc_fx, cte_fx); + *fh++ = sub( 17694, mult( getCosWord16R2( cc_fx ), 15073 ) ); + cc_fx = div_s( add( i, 1 ), sub( shl( n1, 1 ), 1 ) ); // add(cc_fx, cte_fx); } // cte = PI2 / (float) ( 4 * n2 - 1 ); - //cte_fx = div_s(1, sub(shl(n2, 2), 1)); + // cte_fx = div_s(1, sub(shl(n2, 2), 1)); cc_fx = 0; move16(); for ( i = 0; i < n2; i++ ) { *fh++ = getCosWord16R2( cc_fx ); - cc_fx = div_s(add(i, 1), sub(shl(n1, 2), 1));; + cc_fx = div_s( add( i, 1 ), sub( shl( n1, 2 ), 1 ) ); + ; } return; diff --git a/lib_com/window_ola_fx.c b/lib_com/window_ola_fx.c index 26066ca46..32ae48d50 100644 --- a/lib_com/window_ola_fx.c +++ b/lib_com/window_ola_fx.c @@ -2,78 +2,77 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include "options.h" /* Compilation switches */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "rom_com.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "rom_com.h" /* Function prototypes */ #include "stl.h" void sinq_fx( - const Word16 tmp, /* i : sinus factor cos(tmp*i+phi) Q15*/ - const Word16 phi, /* i : sinus phase cos(tmp*i+phi) Q15*/ - const Word16 N, /* i : size of output */ - Word16 x[] /* o : output vector Q15*/ + const Word16 tmp, /* i : sinus factor cos(tmp*i+phi) Q15*/ + const Word16 phi, /* i : sinus phase cos(tmp*i+phi) Q15*/ + const Word16 N, /* i : size of output */ + Word16 x[] /* o : output vector Q15*/ ) { Word16 i; Word16 tmp1, tmp2; - Word32 L_tmp, A32,tmp_old,tmp_old_old; + Word32 L_tmp, A32, tmp_old, tmp_old_old; - x[0]= phi; - move16(); /*sin(x) approximated by x; Q15 */ - tmp1 = add(tmp, phi); /*Q15 */ - L_tmp = L_mult(tmp1, tmp1); /*Q31 */ - L_tmp = Mult_32_16(L_tmp, tmp1); /*Q31 */ - L_tmp = Mult_32_16(L_tmp, 5461); /*Q31; division by 6 */ - tmp2 = round_fx(L_tmp); /*Q15 */ - x[1] = sub(tmp1, tmp2); + x[0] = phi; + move16(); /*sin(x) approximated by x; Q15 */ + tmp1 = add( tmp, phi ); /*Q15 */ + L_tmp = L_mult( tmp1, tmp1 ); /*Q31 */ + L_tmp = Mult_32_16( L_tmp, tmp1 ); /*Q31 */ + L_tmp = Mult_32_16( L_tmp, 5461 ); /*Q31; division by 6 */ + tmp2 = round_fx( L_tmp ); /*Q15 */ + x[1] = sub( tmp1, tmp2 ); move16(); /* sin(x) approximated by (x-x^3/3!); Q15 */ #ifdef BASOP_NOGLOB tmp1 = add_sat( shl_sat( tmp, 1 ), phi ); /*Q15 */ #else - tmp1 = add(shl(tmp,1), phi); /*Q15 */ + tmp1 = add( shl( tmp, 1 ), phi ); /*Q15 */ #endif - L_tmp = L_mult(tmp1, tmp1); /*Q31 */ - L_tmp = Mult_32_16(L_tmp, tmp1); /*Q31 */ - L_tmp = Mult_32_16(L_tmp, 5461); /*Q31; division by 6 */ - tmp2 = round_fx(L_tmp); /*Q15 */ - x[2] = sub(tmp1, tmp2); + L_tmp = L_mult( tmp1, tmp1 ); /*Q31 */ + L_tmp = Mult_32_16( L_tmp, tmp1 ); /*Q31 */ + L_tmp = Mult_32_16( L_tmp, 5461 ); /*Q31; division by 6 */ + tmp2 = round_fx( L_tmp ); /*Q15 */ + x[2] = sub( tmp1, tmp2 ); move16(); /* sin(x) approximated by (x-x^3/3!); Q15 */ - IF ( GT_16(abs_s(tmp),3)) + IF( GT_16( abs_s( tmp ), 3 ) ) { /*A=(x[2]+x[0])/x[1]=2*cos(tmp); here approximated by 2*(1-tmp^2/2!) */ - A32 = L_mult0(tmp,tmp); /*Q30 */ - A32 = L_add(L_sub(1073741824, A32), 1073741824); /*Q30 */ + A32 = L_mult0( tmp, tmp ); /*Q30 */ + A32 = L_add( L_sub( 1073741824, A32 ), 1073741824 ); /*Q30 */ } ELSE { - A32 = L_deposit_l(0); + A32 = L_deposit_l( 0 ); } - tmp_old=L_deposit_h(x[2]); /*Q31 */ - tmp_old_old=L_deposit_h(x[1]); /*Q31 */ + tmp_old = L_deposit_h( x[2] ); /*Q31 */ + tmp_old_old = L_deposit_h( x[1] ); /*Q31 */ - FOR ( i=3; i Q15 */ *pt2 = shl_sat( mult_r_sat( *pt2, *pt4 ), 1 ); #else - *pt= shl( mult_r(*pt,*pt5),1); - move16();/* // Q14* Q15 + shl ==> Q15 */ - *pt2 = shl( mult_r(*pt2,*pt4),1); + *pt = shl( mult_r( *pt, *pt5 ), 1 ); + move16(); /* // Q14* Q15 + shl ==> Q15 */ + *pt2 = shl( mult_r( *pt2, *pt4 ), 1 ); #endif - move16();/*/= win[(3*L_FRAME16k/2-1-i/2)*decimate+decay-L_FRAME48k*14/20]; */ - pt+=2; - pt2+=2; - pt5-=3; + move16(); /*/= win[(3*L_FRAME16k/2-1-i/2)*decimate+decay-L_FRAME48k*14/20]; */ + pt += 2; + pt2 += 2; + pt5 -= 3; pt4--; - } } ELSE { - pt=synth+tmp; - pt5=on_win+210-1; - temp_len = i_mult2(shr(R2_16,2),delta); - FOR( i=0 ; i< temp_len; i++ ) + pt = synth + tmp; + pt5 = on_win + 210 - 1; + temp_len = i_mult2( shr( R2_16, 2 ), delta ); + FOR( i = 0; i < temp_len; i++ ) { #ifdef BASOP_NOGLOB - *pt=shl_sat( mult_r_sat(*pt,*pt5),1); + *pt = shl_sat( mult_r_sat( *pt, *pt5 ), 1 ); #else - *pt=shl( mult_r(*pt,*pt5),1); + *pt = shl( mult_r( *pt, *pt5 ), 1 ); #endif - move16();/* /= win[(3*output_frame/2-1-i)*decimate+decay-L_FRAME48k*14/20]; */ + move16(); /* /= win[(3*output_frame/2-1-i)*decimate+decay-L_FRAME48k*14/20]; */ pt++; - pt5-=decimate; + pt5 -= decimate; move16(); } } - pt=synth+tmp; - move16();/*Q15 */ - pt2=synth_subfr_bwe+tmp-NS2SA(output_Fs, DELAY_CLDFB_NS); + pt = synth + tmp; + move16(); /*Q15 */ + pt2 = synth_subfr_bwe + tmp - NS2SA( output_Fs, DELAY_CLDFB_NS ); move16(); /*Q15 */ - pt3=tmp_buf_switch+tmp; + pt3 = tmp_buf_switch + tmp; move16(); /*Q15 */ - FOR( i=0; i -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* required by wmc_tool */ -#include "prot_fx2.h" /* required by wmc_tool */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx1.h" /* required by wmc_tool */ +#include "prot_fx2.h" /* required by wmc_tool */ #include "stat_com.h" - /*--------------------------------------------------------------------------* - * mvr2r_inv() - * - * - *--------------------------------------------------------------------------*/ +/*--------------------------------------------------------------------------* + * mvr2r_inv() + * + * + *--------------------------------------------------------------------------*/ static void mvs2s_inv( - const Word16 *in, /* i : input vector */ - Word16* out, /* o : output vector */ - const Word16 L, /* i : length */ - const Word16 decimate /* i : decimation flag [-1,1] */ + const Word16 *in, /* i : input vector */ + Word16 *out, /* o : output vector */ + const Word16 L, /* i : length */ + const Word16 decimate /* i : decimation flag [-1,1] */ ) { Word16 i; - in= in+ shr(sub(decimate,1),1); - out=out+sub(L,1); - FOR (i=0; i= 2 ? -1.f : 1.f); - const float sign_right = (kernel_type & 1 ? 1.f : -1.f); + const float sign_left = ( kernel_type >= 2 ? -1.f : 1.f ); + const float sign_right = ( kernel_type & 1 ? 1.f : -1.f ); int16_t i, decimate, decay; int16_t n, windecay48, windecay16; - const float* allsig_l, * allsig_r; + const float *allsig_l, *allsig_r; float win_right[R2_48]; float win_int_left[R1_16]; float win_left[R1_48]; float win_int_right[R2_16]; - tcx_get_windows_mode1(left_mode, right_mode, win_left, win_right, win_int_left, win_int_right, L); + tcx_get_windows_mode1( left_mode, right_mode, win_left, win_right, win_int_left, win_int_right, L ); decimate = 1; /* L_FRAME 48k */ decay = 0; - windecay48 = (int16_t)(2 * ((float)L_FRAME48k * N_ZERO_MDCT_NS / FRAME_SIZE_NS)) + R1_48; + windecay48 = (int16_t) ( 2 * ( (float) L_FRAME48k * N_ZERO_MDCT_NS / FRAME_SIZE_NS ) ) + R1_48; - if (L == L_FRAME32k || L == L_FRAME16k) + if ( L == L_FRAME32k || L == L_FRAME16k ) { decimate = 3; decay = 1; } - else if (L == L_FRAME8k) + else if ( L == L_FRAME8k ) { decimate = 6; decay = 2; } - n = (int16_t)((float)L * N_ZERO_MDCT_NS / FRAME_SIZE_NS); + n = (int16_t) ( (float) L * N_ZERO_MDCT_NS / FRAME_SIZE_NS ); - windecay16 = (int16_t)(2 * ((float)L_FRAME16k * N_ZERO_MDCT_NS / FRAME_SIZE_NS)) + R1_16; + windecay16 = (int16_t) ( 2 * ( (float) L_FRAME16k * N_ZERO_MDCT_NS / FRAME_SIZE_NS ) ) + R1_16; allsig_r = new_audio + n; allsig_l = new_audio + n - L; - if (L == L_FRAME32k) + if ( L == L_FRAME32k ) { - for (i = 0; i < L / 2 - n; i += 2) + for ( i = 0; i < L / 2 - n; i += 2 ) { wtda_audio[i] = -allsig_r[L / 2 - i - 1] * win_int_right[3 * L_FRAME16k / 2 - i / 2 - 1 - windecay16] + sign_right * allsig_r[L / 2 + i] * win_int_right[3 * L_FRAME16k / 2 + i / 2 - windecay16]; - wtda_audio[i + 1] = -allsig_r[L / 2 - (i + 1) - 1] * win_right[(3 * L_FRAME16k / 2 - i / 2 - 1) * decimate + decay - windecay48] + sign_right * allsig_r[L / 2 + i + 1] * win_right[(3 * L_FRAME16k / 2 + 1 + i / 2) * decimate - decay - 1 - windecay48]; + wtda_audio[i + 1] = -allsig_r[L / 2 - ( i + 1 ) - 1] * win_right[( 3 * L_FRAME16k / 2 - i / 2 - 1 ) * decimate + decay - windecay48] + sign_right * allsig_r[L / 2 + i + 1] * win_right[( 3 * L_FRAME16k / 2 + 1 + i / 2 ) * decimate - decay - 1 - windecay48]; } - for (i = L / 2 - n; i < L / 2; i += 2) + for ( i = L / 2 - n; i < L / 2; i += 2 ) { wtda_audio[i] = -allsig_r[L / 2 - i - 1]; - wtda_audio[i + 1] = -allsig_r[L / 2 - (i + 1) - 1]; + wtda_audio[i + 1] = -allsig_r[L / 2 - ( i + 1 ) - 1]; } - for (i = 0; i < n; i += 2) + for ( i = 0; i < n; i += 2 ) { - wtda_audio[i + L / 2] = sign_left * allsig_l[i] * win_left[(i / 2) * decimate + decay] - new_audio[n - i - 1]; - wtda_audio[i + L / 2 + 1] = sign_left * allsig_l[i + 1] * win_int_left[i / 2] - new_audio[n - (i + 1) - 1]; + wtda_audio[i + L / 2] = sign_left * allsig_l[i] * win_left[( i / 2 ) * decimate + decay] - new_audio[n - i - 1]; + wtda_audio[i + L / 2 + 1] = sign_left * allsig_l[i + 1] * win_int_left[i / 2] - new_audio[n - ( i + 1 ) - 1]; } - for (i = n; i < L / 2; i += 2) + for ( i = n; i < L / 2; i += 2 ) { - wtda_audio[i + L / 2] = sign_left * allsig_l[i] * win_left[(i / 2) * decimate + decay] - allsig_l[L - i - 1] * win_left[(L / 2 - i / 2) * decimate - 1 - decay]; - wtda_audio[i + L / 2 + 1] = sign_left * allsig_l[i + 1] * win_int_left[i / 2] - allsig_l[L - (i + 1) - 1] * win_int_left[L / 2 - i / 2 - 1]; + wtda_audio[i + L / 2] = sign_left * allsig_l[i] * win_left[( i / 2 ) * decimate + decay] - allsig_l[L - i - 1] * win_left[( L / 2 - i / 2 ) * decimate - 1 - decay]; + wtda_audio[i + L / 2 + 1] = sign_left * allsig_l[i + 1] * win_int_left[i / 2] - allsig_l[L - ( i + 1 ) - 1] * win_int_left[L / 2 - i / 2 - 1]; } } else { - for (i = 0; i < L / 2 - n; i++) + for ( i = 0; i < L / 2 - n; i++ ) { - wtda_audio[i] = -allsig_r[L / 2 - i - 1] * win_right[3 * L / 2 * decimate - (i + 1) * decimate + decay - windecay48] + sign_right * allsig_r[L / 2 + i] * win_right[3 * L / 2 * decimate - 1 + (i + 1) * decimate - decay - windecay48]; + wtda_audio[i] = -allsig_r[L / 2 - i - 1] * win_right[3 * L / 2 * decimate - ( i + 1 ) * decimate + decay - windecay48] + sign_right * allsig_r[L / 2 + i] * win_right[3 * L / 2 * decimate - 1 + ( i + 1 ) * decimate - decay - windecay48]; } - for (i = L / 2 - n; i < L / 2; i++) + for ( i = L / 2 - n; i < L / 2; i++ ) { wtda_audio[i] = -allsig_r[L / 2 - i - 1]; } - for (i = 0; i < n; i++) + for ( i = 0; i < n; i++ ) { wtda_audio[i + L / 2] = sign_left * allsig_l[i] * win_left[i * decimate + decay] - new_audio[n - i - 1]; } - for (i = n; i < L / 2; i++) + for ( i = n; i < L / 2; i++ ) { wtda_audio[i + L / 2] = sign_left * allsig_l[i] * win_left[i * decimate + decay] - allsig_l[L - i - 1] * win_left[L * decimate - i * decimate - 1 - decay]; } @@ -520,4 +508,3 @@ void wtda_ext( } #endif - diff --git a/lib_dec/ACcontextMapping_dec.c b/lib_dec/ACcontextMapping_dec.c index cb3863a5e..952303ce8 100644 --- a/lib_dec/ACcontextMapping_dec.c +++ b/lib_dec/ACcontextMapping_dec.c @@ -672,4 +672,4 @@ int16_t RCcontextMapping_decode2_no_mem_s17_LCS( return resQBits; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/ACcontextMapping_dec_fx.c b/lib_dec/ACcontextMapping_dec_fx.c index cdb1d1a17..f2ec7d573 100644 --- a/lib_dec/ACcontextMapping_dec_fx.c +++ b/lib_dec/ACcontextMapping_dec_fx.c @@ -22,11 +22,11 @@ #ifdef IVAS_FLOAT_FIXED Word16 ACcontextMapping_decode2_no_mem_s17_LC( - Decoder_State *st,/* i/o: decoder state */ - Word16 *x, /* o: decoded spectrum */ - Word16 nt, /* i: size of spectrum */ - Word16 nbbits, /* i: bit budget */ - Word16 resQMaxBits, /* i: residual coding maximum bits*/ + Decoder_State *st, /* i/o: decoder state */ + Word16 *x, /* o: decoded spectrum */ + Word16 nt, /* i: size of spectrum */ + Word16 nbbits, /* i: bit budget */ + Word16 resQMaxBits, /* i: residual coding maximum bits*/ CONTEXT_HM_CONFIG *hm_cfg /* i: context-based harmonic model configuration */ ) { @@ -40,7 +40,7 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC( UWord16 r; Word16 resQBits; Word16 rest_bits, rest_bits_overflow; - Word16 tmp=0; /* initialize just to avoid compiler warning */ + Word16 tmp = 0; /* initialize just to avoid compiler warning */ Word16 nt_half; Word16 c[2], *ctx; Word16 p1, p2; @@ -50,15 +50,17 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC( Word16 nbbits_m2; Word32 La, Lb; - r = 0; /* to avoid compilation warnings */ move16(); - esc_nb = 0; /* to avoid compilation warnings */ move16(); + r = 0; /* to avoid compilation warnings */ + move16(); + esc_nb = 0; /* to avoid compilation warnings */ + move16(); - set16_fx(x, 0, nt); + set16_fx( x, 0, nt ); /* Rate flag */ rateFlag = 0; move16(); - IF (GT_16(nbbits, 400)) + IF( GT_16( nbbits, 400 ) ) { rateFlag = 2 << NBITS_CONTEXT; move16(); @@ -67,16 +69,16 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC( /*Decode number of ntuples*/ start_bit_pos = st->next_bit_pos; move16(); - lsbs_bit_pos = add(start_bit_pos, sub(nbbits, 1)); + lsbs_bit_pos = add( start_bit_pos, sub( nbbits, 1 ) ); n = 0; move16(); - L = sub(14, norm_s(negate(nt))); - n = add(get_next_indice_fx(st, L), 1); + L = sub( 14, norm_s( negate( nt ) ) ); + n = add( get_next_indice_fx( st, L ), 1 ); /* Init */ - nt_half = shr(nt, 1); + nt_half = shr( nt, 1 ); c[0] = c[1] = 0; move16(); move16(); @@ -84,27 +86,27 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC( t = 0; move16(); - lastnz = shl(n, 1); + lastnz = shl( n, 1 ); - IF (GT_16(lastnz, nt) || st->BER_detect) + IF( GT_16( lastnz, nt ) || st->BER_detect ) { st->BER_detect = 1; move16(); return 0; } - IF (hm_cfg) /* mapped domain */ + IF( hm_cfg ) /* mapped domain */ { numPeakIndicesOrig = hm_cfg->numPeakIndices; move16(); - hm_cfg->numPeakIndices = s_min(hm_cfg->numPeakIndices, lastnz); + hm_cfg->numPeakIndices = s_min( hm_cfg->numPeakIndices, lastnz ); move16(); - numHoleIndices = sub(lastnz, hm_cfg->numPeakIndices); + numHoleIndices = sub( lastnz, hm_cfg->numPeakIndices ); /* Mark hole indices beyond lastnz as pruned */ - FOR (k=numHoleIndices; knumHoleIndices; ++k) + FOR( k = numHoleIndices; k < hm_cfg->numHoleIndices; ++k ) { - hm_cfg->holeIndices[k] = add(hm_cfg->holeIndices[k], nt); + hm_cfg->holeIndices[k] = add( hm_cfg->holeIndices[k], nt ); move16(); } @@ -117,7 +119,7 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC( get_next_coeff = get_next_coeff_mapped; move16(); } - ELSE /* unmapped domain */ + ELSE /* unmapped domain */ { ii[0] = 0; move16(); @@ -131,71 +133,71 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC( } /* Start Decoding */ - ari_start_decoding_14bits_fx(st, &as); + ari_start_decoding_14bits_fx( st, &as ); overflow_bit_pos = st->next_bit_pos; move16(); - nbbits_m2 = add(nbbits, cbitsnew - 2); - rest_bits_overflow = rest_bits = negate(nbbits_m2); + nbbits_m2 = add( nbbits, cbitsnew - 2 ); + rest_bits_overflow = rest_bits = negate( nbbits_m2 ); move16(); /*Main Loop through the 2-tuples*/ - FOR (k = 0; k < lastnz; k += 2) + FOR( k = 0; k < lastnz; k += 2 ) { /* First coefficient */ - a1_i = get_next_coeff(ii, &p1, &idx1, hm_cfg); + a1_i = get_next_coeff( ii, &p1, &idx1, hm_cfg ); /* Second coefficient */ - b1_i = get_next_coeff(ii, &p2, &idx2, hm_cfg); + b1_i = get_next_coeff( ii, &p2, &idx2, hm_cfg ); - idx = s_min(idx1, idx2); + idx = s_min( idx1, idx2 ); /* Get context */ - ctx = &c[s_or(p1, p2)]; + ctx = &c[s_or( p1, p2 )]; move16(); - t = add(*ctx, rateFlag); - IF (GT_16(idx, nt_half)) + t = add( *ctx, rateFlag ); + IF( GT_16( idx, nt_half ) ) { - t = add(t, 1 << NBITS_CONTEXT); + t = add( t, 1 << NBITS_CONTEXT ); } test(); /* BER detection: Check max value of context t leading to out-of-bound access to ari_lookup_s17_LC[]*/ - IF( GE_16(t , ( 1 << ( NBITS_CONTEXT + NBITS_RATEQ ) ) ) || LE_16( lsbs_bit_pos, 0 ) ) + IF( GE_16( t, ( 1 << ( NBITS_CONTEXT + NBITS_RATEQ ) ) ) || LE_16( lsbs_bit_pos, 0 ) ) { st->BER_detect = 1; move16(); return 0; } - La = L_deposit_l(0); - Lb = L_deposit_l(0); + La = L_deposit_l( 0 ); + Lb = L_deposit_l( 0 ); /* MSBs decoding */ test(); - FOR (lev = 0; lev < 15 && lsbs_bit_pos > 0; lev++) + FOR( lev = 0; lev < 15 && lsbs_bit_pos > 0; lev++ ) { test(); - esc_nb = s_min(lev, 3); - tmp = add(t, Tab_esc_nb[esc_nb]); - assert(tmp >= 0 && tmp < 4096); + esc_nb = s_min( lev, 3 ); + tmp = add( t, Tab_esc_nb[esc_nb] ); + assert( tmp >= 0 && tmp < 4096 ); pki = ari_lookup_s17_LC[tmp]; move16(); - r = ari_decode_14bits_s17_ext_fx(st, &as, ari_pk_s17_LC_ext[pki]); + r = ari_decode_14bits_s17_ext_fx( st, &as, ari_pk_s17_LC_ext[pki] ); - IF (LT_16(r, VAL_ESC)) + IF( LT_16( r, VAL_ESC ) ) { BREAK; } /*LSBs decoding*/ - La = L_mac0(La, pow2tab[lev], get_indice_1_fx(st, lsbs_bit_pos--)); - Lb = L_mac0(Lb, pow2tab[lev], get_indice_1_fx(st, lsbs_bit_pos--)); + La = L_mac0( La, pow2tab[lev], get_indice_1_fx( st, lsbs_bit_pos-- ) ); + Lb = L_mac0( Lb, pow2tab[lev], get_indice_1_fx( st, lsbs_bit_pos-- ) ); } test(); test(); - IF ( ((LT_16(lsbs_bit_pos, -1)&&GE_16(r,VAL_ESC)))||(GT_16(lev,14))) + IF( ( ( LT_16( lsbs_bit_pos, -1 ) && GE_16( r, VAL_ESC ) ) ) || ( GT_16( lev, 14 ) ) ) { x[a1_i] = 0; move16(); @@ -207,28 +209,28 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC( } /*MSBs contributions*/ - b1 = shr(r, 2); - a1 = s_and(r, 0x3); - a = extract_l(L_mac0(La, pow2tab[lev], a1)); - b = extract_l(L_mac0(Lb, pow2tab[lev], b1)); + b1 = shr( r, 2 ); + a1 = s_and( r, 0x3 ); + a = extract_l( L_mac0( La, pow2tab[lev], a1 ) ); + b = extract_l( L_mac0( Lb, pow2tab[lev], b1 ) ); /*lsbs bits sign bits*/ - rest_bits = add(rest_bits, shl(lev, 1)); + rest_bits = add( rest_bits, shl( lev, 1 ) ); - IF (a > 0) + IF( a > 0 ) { - rest_bits = add(rest_bits, 1); + rest_bits = add( rest_bits, 1 ); } - IF (b > 0) + IF( b > 0 ) { - rest_bits = add(rest_bits, 1); + rest_bits = add( rest_bits, 1 ); } /*Dectect overflow*/ - IF (add(sub(st->next_bit_pos, start_bit_pos), rest_bits) > 0) + IF( add( sub( st->next_bit_pos, start_bit_pos ), rest_bits ) > 0 ) { /* Roll back bitstream position to overflow_bit_pos */ - get_next_indice_tmp_fx(st, sub(overflow_bit_pos, st->next_bit_pos)); + get_next_indice_tmp_fx( st, sub( overflow_bit_pos, st->next_bit_pos ) ); rest_bits = rest_bits_overflow; move16(); x[a1_i] = 0; @@ -250,76 +252,79 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC( move16(); /* Update context for next 2-tuple */ - IF (EQ_32(p1, p2)) /* peak-peak or hole-hole context */ + IF( EQ_32( p1, p2 ) ) /* peak-peak or hole-hole context */ { - lev = sub(esc_nb, 1); - IF (lev > 0) t = add(12, lev); - IF (lev <= 0) t = add(a1, b1); - IF (lev == 0) t = add(t, t); - - *ctx = add(shl(s_and(*ctx, 0xf), 4), add(t, 1)); + lev = sub( esc_nb, 1 ); + IF( lev > 0 ) + t = add( 12, lev ); + IF( lev <= 0 ) + t = add( a1, b1 ); + IF( lev == 0 ) + t = add( t, t ); + + *ctx = add( shl( s_and( *ctx, 0xf ), 4 ), add( t, 1 ) ); move16(); } - ELSE /* mixed context */ + ELSE /* mixed context */ { - IF (s_and(idx1, 1)) /* update first context */ + IF( s_and( idx1, 1 ) ) /* update first context */ { - c[p1] = update_mixed_context(c[p1], a); + c[p1] = update_mixed_context( c[p1], a ); move16(); } - IF (s_and(idx2, 1)) /* update second context */ + IF( s_and( idx2, 1 ) ) /* update second context */ { - c[p2] = update_mixed_context(c[p2], b); + c[p2] = update_mixed_context( c[p2], b ); move16(); } } } /* Total number of decoded AC bits */ - get_next_indice_tmp_fx(st, -(cbitsnew - 2)); + get_next_indice_tmp_fx( st, -( cbitsnew - 2 ) ); /*detect overflow*/ - IF (NE_16(k, lastnz)) + IF( NE_16( k, lastnz ) ) { - rest_bits = add(rest_bits, nbbits_m2); + rest_bits = add( rest_bits, nbbits_m2 ); /* Set bitstream position to (start_bit_pos+nbbits-rest_bits) */ - get_next_indice_tmp_fx(st, sub((sub(add(start_bit_pos, nbbits), rest_bits)), st->next_bit_pos)); + get_next_indice_tmp_fx( st, sub( ( sub( add( start_bit_pos, nbbits ), rest_bits ) ), st->next_bit_pos ) ); } /*Decode signs*/ - IF (hm_cfg) + IF( hm_cfg ) { tmp = nt; move16(); } - IF (!hm_cfg) + IF( !hm_cfg ) { tmp = lastnz; move16(); } - FOR (k = 0; k < tmp; k++) + FOR( k = 0; k < tmp; k++ ) { - IF (x[k] > 0) + IF( x[k] > 0 ) { - IF (get_next_indice_1_fx(st) != 0) + IF( get_next_indice_1_fx( st ) != 0 ) { - x[k] = negate(x[k]); + x[k] = negate( x[k] ); move16(); } } } /*Decode Residual Q*/ - resQBits = s_min(resQMaxBits, sub(add(lsbs_bit_pos,1), st->next_bit_pos)); - FOR (k=0; knext_bit_pos ) ); + FOR( k = 0; k < resQBits; ++k ) { - x[nt+k] = get_indice_1_fx(st, sub(lsbs_bit_pos, k)); + x[nt + k] = get_indice_1_fx( st, sub( lsbs_bit_pos, k ) ); move16(); } /* Set bitstream pointer to end of buffer */ - get_next_indice_tmp_fx(st, sub(add(start_bit_pos, nbbits), st->next_bit_pos)); + get_next_indice_tmp_fx( st, sub( add( start_bit_pos, nbbits ), st->next_bit_pos ) ); return resQBits; @@ -336,14 +341,14 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC( * Range decoder *-------------------------------------------------------------------*/ - /*! r: resQBits */ +/*! r: resQBits */ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx( - Decoder_State* st, /* i/o: decoder state */ - Word16* x, /* o : decoded spectrum */ + Decoder_State *st, /* i/o: decoder state */ + Word16 *x, /* o : decoded spectrum */ const Word16 nt, /* i : size of spectrum */ const Word16 nbbits, /* i : bit budget */ const Word16 resQMaxBits, /* i : residual coding maximum bits */ - CONTEXT_HM_CONFIG* hm_cfg /* i : context-based harmonic model configuration*/ + CONTEXT_HM_CONFIG *hm_cfg /* i : context-based harmonic model configuration*/ ) { RangeUniDecState rc_st_dec; /* State of the range decoder */ @@ -360,7 +365,7 @@ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx( Word16 nbbits_m2; Word16 bits_tups; /* No. of bits for coding the no. of tuples */ - set16_fx(x, 0, nt); + set16_fx( x, 0, nt ); /*Decode number of ntuples*/ start_bit_pos = st->next_bit_pos; @@ -392,7 +397,7 @@ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx( IF( hm_cfg ) { Word16 a1_i, b1_i; - Word16 c[2], * ctx; + Word16 c[2], *ctx; Word16 p1, p2; Word16 ii[2]; Word16 idx1, idx2, idx; @@ -413,13 +418,13 @@ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx( /* mapped domain */ numPeakIndicesOrig = hm_cfg->numPeakIndices; - hm_cfg->numPeakIndices = s_min(hm_cfg->numPeakIndices, lastnz); - numHoleIndices = sub( lastnz, hm_cfg->numPeakIndices); + hm_cfg->numPeakIndices = s_min( hm_cfg->numPeakIndices, lastnz ); + numHoleIndices = sub( lastnz, hm_cfg->numPeakIndices ); /* Mark hole indices beyond lastnz as pruned */ - FOR(k = numHoleIndices; k < hm_cfg->numHoleIndices; ++k) + FOR( k = numHoleIndices; k < hm_cfg->numHoleIndices; ++k ) { - hm_cfg->holeIndices[k] = add( hm_cfg->holeIndices[k], nt); + hm_cfg->holeIndices[k] = add( hm_cfg->holeIndices[k], nt ); } ii[0] = numPeakIndicesOrig; @@ -429,32 +434,32 @@ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx( /* Start Decoding */ /* Initialize range decoder */ - rc_uni_dec_init_fx(&rc_st_dec, &st->bit_stream[st->next_bit_pos], nbbits); /* (nbbits + 30) entries are read by the decoder */ + rc_uni_dec_init_fx( &rc_st_dec, &st->bit_stream[st->next_bit_pos], nbbits ); /* (nbbits + 30) entries are read by the decoder */ nbbits_m2 = nbbits; - rest_bits = negate(nbbits_m2); + rest_bits = negate( nbbits_m2 ); /* Main Loop through the 2-tuples */ - FOR(k = 0; k < lastnz; k += 2) + FOR( k = 0; k < lastnz; k += 2 ) { - a1_i = get_next_coeff_mapped(ii, &p1, &idx1, hm_cfg); - b1_i = get_next_coeff_mapped(ii, &p2, &idx2, hm_cfg); - idx = s_min(idx1, idx2); + a1_i = get_next_coeff_mapped( ii, &p1, &idx1, hm_cfg ); + b1_i = get_next_coeff_mapped( ii, &p2, &idx2, hm_cfg ); + idx = s_min( idx1, idx2 ); /* Get context */ - ctx = &c[s_or(p1, p2)]; + ctx = &c[s_or( p1, p2 )]; - t = add(*ctx, rateFlag); - IF(LT_16( nt_half, idx)) + t = add( *ctx, rateFlag ); + IF( LT_16( nt_half, idx ) ) { - t = add(t, 1 << NBITS_CONTEXT); + t = add( t, 1 << NBITS_CONTEXT ); } esc_nb = 0; r = 0; /* BER detection: Check max value of context t leading to out-of-bound access to ari_lookup_s17_LC[]*/ - IF((GE_16(t , (1 << (NBITS_CONTEXT + NBITS_RATEQ)))) || lsbs_bit_pos <= 0) + IF( ( GE_16( t, ( 1 << ( NBITS_CONTEXT + NBITS_RATEQ ) ) ) ) || lsbs_bit_pos <= 0 ) { st->BER_detect = 1; return 0; @@ -463,24 +468,24 @@ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx( a = b = 0; /* MSBs decoding */ - FOR(lev = 0; lev < 15 && lsbs_bit_pos > 0; ++lev) + FOR( lev = 0; lev < 15 && lsbs_bit_pos > 0; ++lev ) { - esc_nb = s_min(lev, 3); - pki = ari_lookup_s17_LC[add(t, Tab_esc_nb[esc_nb])]; - r = rc_uni_dec_read_symbol_fastS_fx(&rc_st_dec, cum_freq_ari_pk_s17_LC_ext[pki], sym_freq_ari_pk_s17_LC_ext[pki], 17, 14); /*Alphabet size = 17 (2^4 = 16 MSB symbols + 1 ESC symbol) */ + esc_nb = s_min( lev, 3 ); + pki = ari_lookup_s17_LC[add( t, Tab_esc_nb[esc_nb] )]; + r = rc_uni_dec_read_symbol_fastS_fx( &rc_st_dec, cum_freq_ari_pk_s17_LC_ext[pki], sym_freq_ari_pk_s17_LC_ext[pki], 17, 14 ); /*Alphabet size = 17 (2^4 = 16 MSB symbols + 1 ESC symbol) */ /* r is the symbol read, the possible values are {0,1,....alphabet_size - 1} */ - IF (LT_16(r, VAL_ESC)) /* If symbol read corresponds to MSB */ + IF( LT_16( r, VAL_ESC ) ) /* If symbol read corresponds to MSB */ { BREAK; } /* LSBs decoding */ - a = add( a, shl( get_indice_1_fx(st, lsbs_bit_pos--) , lev)); - b = add( b, shl( get_indice_1_fx(st, lsbs_bit_pos--) , lev)); + a = add( a, shl( get_indice_1_fx( st, lsbs_bit_pos-- ), lev ) ); + b = add( b, shl( get_indice_1_fx( st, lsbs_bit_pos-- ), lev ) ); } - IF ((LT_16(lsbs_bit_pos , -1 ) && GE_16( r , VAL_ESC)) || GT_16(lev, 14)) + IF( ( LT_16( lsbs_bit_pos, -1 ) && GE_16( r, VAL_ESC ) ) || GT_16( lev, 14 ) ) { x[a1_i] = 0; x[b1_i] = 0; @@ -491,8 +496,8 @@ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx( /* MSBs contributions */ b1 = shr( r, 2 ); a1 = s_and( r, 0x3 ); - a = add( a, shl( a1, lev)); - b = add( b, shl( b1, lev)); + a = add( a, shl( a1, lev ) ); + b = add( b, shl( b1, lev ) ); /* Add 2 LSB bits per bit-plane */ rest_bits = add( rest_bits, shl( lev, 1 ) ); @@ -505,7 +510,7 @@ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx( /* Confirm that there is no overflow */ #ifdef DEBUGGING - assert(st->next_bit_pos - start_bit_pos + rest_bits <= 0); + assert( st->next_bit_pos - start_bit_pos + rest_bits <= 0 ); #endif /* Store decoded data */ @@ -536,13 +541,13 @@ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx( IF( s_and( idx1, 1 ) ) { /* update first context */ - c[p1] = update_mixed_context(c[p1], a); + c[p1] = update_mixed_context( c[p1], a ); } IF( idx2 & 1 ) { /* update second context */ - c[p2] = update_mixed_context(c[p2], b); + c[p2] = update_mixed_context( c[p2], b ); } } } @@ -551,11 +556,11 @@ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx( /*st->next_bit_pos = rc_uni_dec_finish(&rc_st_dec);*/ /* Check for bitstream errors */ - assert(rc_st_dec.bit_error_detected == 0); + assert( rc_st_dec.bit_error_detected == 0 ); /* Cross-check: No overflow */ #ifdef DEBUGGING - assert(k == lastnz); + assert( k == lastnz ); #endif /* Decode signs */ @@ -589,7 +594,7 @@ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx( /* Main Loop through the 2-tuples */ FOR( k = 0; k < lastnz; k += 2 ) { - rateQ = add( rateFlag, (Word16)GT_16( k, ( nt_half ) ) ); + rateQ = add( rateFlag, (Word16) GT_16( k, ( nt_half ) ) ); /* BER detection: Check max value of context t leading to out-of-bound access to ari_lookup_s17_LC[]*/ IF( ( GE_16( t, ( 1 << ( NBITS_CONTEXT ) ) ) ) || lsbs_bit_pos <= 0 ) @@ -645,7 +650,7 @@ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx( /* Confirm that there is no overflow */ #ifdef DEBUGGING - assert(st->next_bit_pos - start_bit_pos + rest_bits <= 0); + assert( st->next_bit_pos - start_bit_pos + rest_bits <= 0 ); #endif /* Store decoded data */ @@ -662,9 +667,9 @@ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx( c = add( 12, esc_nb ); } - s = (UWord16)L_shl( s, 4 ); /*Shift old 4 bits*/ - s = (UWord16)L_add( s, c ); /*replace last 4 bits*/ - t = (UWord16)L_and( s, 0xFF ); + s = (UWord16) L_shl( s, 4 ); /*Shift old 4 bits*/ + s = (UWord16) L_add( s, c ); /*replace last 4 bits*/ + t = (UWord16) L_and( s, 0xFF ); } /* Decode signs */ @@ -695,4 +700,4 @@ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx( #endif #undef IVAS_CONTEXT_MAPPING -#endif \ No newline at end of file +#endif diff --git a/lib_dec/FEC_HQ_core.c b/lib_dec/FEC_HQ_core.c index 4a336eccf..23b587ac1 100644 --- a/lib_dec/FEC_HQ_core.c +++ b/lib_dec/FEC_HQ_core.c @@ -1332,7 +1332,7 @@ static void Smoothing_vector_scaledown_NB( return; } -#ifndef IVAS_FLOAT_FIXED +#ifndef IVAS_FLOAT_FIXED /*--------------------------------------------------------------------------* * time_domain_FEC_HQ() * @@ -1540,7 +1540,7 @@ void save_synthesis_hq_fec( #ifdef IVAS_FLOAT_FIXED void save_synthesis_hq_fec_fx( Decoder_State *st, /* i/o: decoder state structure */ - const Word32 output_fx[], /* i : decoded synthesis */ + const Word32 output_fx[], /* i : decoded synthesis */ const Word16 output_frame, /* i : decoded synthesis */ CPE_DEC_HANDLE hCPE /* i : CPE decoder structure */ ) @@ -1573,8 +1573,9 @@ void save_synthesis_hq_fec_fx( IF( ( EQ_16( st->codec_mode, MODE1 ) && st->hTcxDec != NULL ) && ( ( EQ_16( st->core, ACELP_CORE ) && !( EQ_16( st->bfi, 1 ) && EQ_16( st->con_tcx, 1 ) ) ) || EQ_16( st->core, HQ_CORE ) ) ) { Copy( st->hTcxDec->synth_history_fx + output_frame, st->hTcxDec->synth_history_fx, output_frame - post_hq_delay + NS2SA( st->output_Fs, PH_ECU_MEM_NS ) ); - FOR (int i = 0; i < output_frame; i++) { - st->hTcxDec->old_synthFB_fx[i + output_frame - post_hq_delay] = extract_h(output_fx[i]); + FOR( int i = 0; i < output_frame; i++ ) + { + st->hTcxDec->old_synthFB_fx[i + output_frame - post_hq_delay] = extract_h( output_fx[i] ); } IF( EQ_16( st->element_mode, EVS_MONO ) ) @@ -1617,4 +1618,4 @@ void save_synthesis_hq_fec_fx( } return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/FEC_HQ_core_fx.c b/lib_dec/FEC_HQ_core_fx.c index 63caeaaf9..6d709b728 100644 --- a/lib_dec/FEC_HQ_core_fx.c +++ b/lib_dec/FEC_HQ_core_fx.c @@ -2,10 +2,10 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ #include "rom_com.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" @@ -16,18 +16,18 @@ * Local function prototypes *---------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -static Word16 FEC_phase_matching_fx(HQ_NBFEC_HANDLE st_fx, Word32* ImdctOut_fx, Word16* auOut_fx, Word16* OldauOut_fx, Word16 OldauOut_pha_fx[2][N_LEAD_NB]); -static void FEC_phase_matching_nextgood_fx(const Word32* ImdctOut_fx, Word16* auOut_fx, Word16* OldauOut_fx, Word16 OldauOut_pha_fx[2][N_LEAD_NB],Word16 mean_en_high_fx); -static void FEC_phase_matching_burst_fx(const Word32* ImdctOut_fx, Word16* auOut_fx, Word16* OldauOut_fx, Word16 OldauOut_pha_fx[2][N_LEAD_NB], Word16* prev_oldauOut_fx ); -static void Repetition_smoothing_nextgood_fx(const Word32* ImdctOut_fx, Word16* auOut_fx, Word32* OldImdctOut_fx, Word16* OldauOut_fx, Word16 cur_data_use_flag, Word16 overlap_time); -static Word16 Repetition_smoothing_fx(const Word32* ImdctOut_fx, Word16* auOut_fx, Word32* OldImdctOut_fx, Word16* OldauOut_fx, const Word16 L, Word16* prev_oldauOut_fx, Word16 overlap_time ); -static void Smoothing_vector_scaledown_NB_fx(const Word16 OldauOutnoWin_fx[], const Word16 ImdctOutWin_fx[], const Word16 SmoothingWin_fx[], Word16 auOut_fx[], const Word16 ol_size); -static void Smoothing_vector_NB_fx(const Word16 OldauOutnoWin_fx[], const Word16 ImdctOutWin_fx[], const Word16 SmoothingWin_fx[], Word16 auOut_fx[], const Word16 ol_size); -static void Windowing_1st_NB_fx(Word16* ImdctOutWin_fx, const Word32* ImdctOut_fx, const Word16* win_fx, const Word16* smoothingWin_fx, Word16 smoothing_flag ); -static void Windowing_2nd_NB_fx(Word16* ImdctOutWin_fx, const Word32* ImdctOut_fx, const Word16* win_fx ); -static void Scaledown_fx(Word16 x[], Word16 y[], Word16 scale_v,const Word16 N ); -static void Next_good_after_burst_erasures_fx(const Word32* ImdctOut_fx, Word16* auOut_fx,Word16* OldauOut_fx, const Word16 ol_size); -static void common_overlapping_fx(Word16* auOut_fx, Word16* ImdctOutWin_fx, Word16* OldauOut_fx, Word16 end1, Word16 offset1, Word16 start2, Word16 end2, Word16 offset_i2, Word16 offset2); +static Word16 FEC_phase_matching_fx( HQ_NBFEC_HANDLE st_fx, Word32 *ImdctOut_fx, Word16 *auOut_fx, Word16 *OldauOut_fx, Word16 OldauOut_pha_fx[2][N_LEAD_NB] ); +static void FEC_phase_matching_nextgood_fx( const Word32 *ImdctOut_fx, Word16 *auOut_fx, Word16 *OldauOut_fx, Word16 OldauOut_pha_fx[2][N_LEAD_NB], Word16 mean_en_high_fx ); +static void FEC_phase_matching_burst_fx( const Word32 *ImdctOut_fx, Word16 *auOut_fx, Word16 *OldauOut_fx, Word16 OldauOut_pha_fx[2][N_LEAD_NB], Word16 *prev_oldauOut_fx ); +static void Repetition_smoothing_nextgood_fx( const Word32 *ImdctOut_fx, Word16 *auOut_fx, Word32 *OldImdctOut_fx, Word16 *OldauOut_fx, Word16 cur_data_use_flag, Word16 overlap_time ); +static Word16 Repetition_smoothing_fx( const Word32 *ImdctOut_fx, Word16 *auOut_fx, Word32 *OldImdctOut_fx, Word16 *OldauOut_fx, const Word16 L, Word16 *prev_oldauOut_fx, Word16 overlap_time ); +static void Smoothing_vector_scaledown_NB_fx( const Word16 OldauOutnoWin_fx[], const Word16 ImdctOutWin_fx[], const Word16 SmoothingWin_fx[], Word16 auOut_fx[], const Word16 ol_size ); +static void Smoothing_vector_NB_fx( const Word16 OldauOutnoWin_fx[], const Word16 ImdctOutWin_fx[], const Word16 SmoothingWin_fx[], Word16 auOut_fx[], const Word16 ol_size ); +static void Windowing_1st_NB_fx( Word16 *ImdctOutWin_fx, const Word32 *ImdctOut_fx, const Word16 *win_fx, const Word16 *smoothingWin_fx, Word16 smoothing_flag ); +static void Windowing_2nd_NB_fx( Word16 *ImdctOutWin_fx, const Word32 *ImdctOut_fx, const Word16 *win_fx ); +static void Scaledown_fx( Word16 x[], Word16 y[], Word16 scale_v, const Word16 N ); +static void Next_good_after_burst_erasures_fx( const Word32 *ImdctOut_fx, Word16 *auOut_fx, Word16 *OldauOut_fx, const Word16 ol_size ); +static void common_overlapping_fx( Word16 *auOut_fx, Word16 *ImdctOutWin_fx, Word16 *OldauOut_fx, Word16 end1, Word16 offset1, Word16 start2, Word16 end2, Word16 offset_i2, Word16 offset2 ); #endif /*--------------------------------------------------------------------------* @@ -37,22 +37,22 @@ static void common_overlapping_fx(Word16* auOut_fx, Word16* ImdctOutWin_fx, Word *--------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED static void Regression_Anal_fx( - const Word32 *values_fx, /* i : Previous values */ - Word32 *r_p_fx, /* o : Output r[a b] array : y=ax+b */ - const Word16 num_pgf /* i : Number of previous good frame */ + const Word32 *values_fx, /* i : Previous values */ + Word32 *r_p_fx, /* o : Output r[a b] array : y=ax+b */ + const Word16 num_pgf /* i : Number of previous good frame */ ) { Word16 i; Word16 tmp; Word32 L_tmp1, L_tmp2; - Word16 aindex_fx[MAX_PGF+1]; - Word32 b_p_fx[MAX_PGF+1]; + Word16 aindex_fx[MAX_PGF + 1]; + Word32 b_p_fx[MAX_PGF + 1]; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif /* Initialize */ - FOR (i=0; ienergy_MA_Curr_fx[1], hHQ_nbfec->energy_MA_Curr_fx[0])); - exp1 = sub(norm_s(tmp_fx), 1); - hHQ_nbfec->energy_MA_Curr_fx[0] = s_max(hHQ_nbfec->energy_MA_Curr_fx[0],1); + tmp_fx = abs_s( sub( hHQ_nbfec->energy_MA_Curr_fx[1], hHQ_nbfec->energy_MA_Curr_fx[0] ) ); + exp1 = sub( norm_s( tmp_fx ), 1 ); + hHQ_nbfec->energy_MA_Curr_fx[0] = s_max( hHQ_nbfec->energy_MA_Curr_fx[0], 1 ); move16(); - exp2 = norm_s(hHQ_nbfec->energy_MA_Curr_fx[0]); - tmp_fx = div_s(shl(tmp_fx, exp1), shl(hHQ_nbfec->energy_MA_Curr_fx[0], exp2));/*15 + exp1 - exp2*/ - energy_diff_fx = shl(tmp_fx, sub(sub(exp2, exp1), 5));/*10*/ + exp2 = norm_s( hHQ_nbfec->energy_MA_Curr_fx[0] ); + tmp_fx = div_s( shl( tmp_fx, exp1 ), shl( hHQ_nbfec->energy_MA_Curr_fx[0], exp2 ) ); /*15 + exp1 - exp2*/ + energy_diff_fx = shl( tmp_fx, sub( sub( exp2, exp1 ), 5 ) ); /*10*/ test(); - IF ((LT_16(energy_diff_fx, 1024))&&(is_transient==0)) /* First erasure frame */ + IF( ( LT_16( energy_diff_fx, 1024 ) ) && ( is_transient == 0 ) ) /* First erasure frame */ { mute_start = 5; move16(); @@ -187,19 +186,19 @@ void HQ_FEC_processing_fx( } test(); test(); - if( EQ_16(st_fx->prev_old_bfi, 1)&&EQ_16(st_fx->nbLostCmpt,1)&&EQ_16(output_frame,L_FRAME8k)) + if ( EQ_16( st_fx->prev_old_bfi, 1 ) && EQ_16( st_fx->nbLostCmpt, 1 ) && EQ_16( output_frame, L_FRAME8k ) ) { - st_fx->nbLostCmpt = add(st_fx->nbLostCmpt, 1); + st_fx->nbLostCmpt = add( st_fx->nbLostCmpt, 1 ); } /* Frequency-domain FEC */ - IF ( EQ_16(st_fx->nbLostCmpt, 1)) /* First erasure frame */ + IF( EQ_16( st_fx->nbLostCmpt, 1 ) ) /* First erasure frame */ { - IF ( is_transient == 0 ) + IF( is_transient == 0 ) { - IF (LT_16(energy_diff_fx, 1024)) + IF( LT_16( energy_diff_fx, 1024 ) ) { - FOR (i=0; i < output_frame; i++) + FOR( i = 0; i < output_frame; i++ ) { t_audio_q_fx[i] = hHQ_nbfec->old_coeffs_fx[i]; move32(); @@ -207,26 +206,26 @@ void HQ_FEC_processing_fx( } ELSE { - FOR (i=0; i < output_frame; i++) + FOR( i = 0; i < output_frame; i++ ) { - hHQ_nbfec->old_coeffs_fx[i] = Mult_32_16(hHQ_nbfec->old_coeffs_fx[i], 23170);/*23170, 3dB, Q15*/ + hHQ_nbfec->old_coeffs_fx[i] = Mult_32_16( hHQ_nbfec->old_coeffs_fx[i], 23170 ); /*23170, 3dB, Q15*/ t_audio_q_fx[i] = hHQ_nbfec->old_coeffs_fx[i]; move32(); } } /* Sign prediction in 4-dim bands up to 1.6 kHz*/ - IF (hHQ_core->old_is_transient[1] == 0) + IF( hHQ_core->old_is_transient[1] == 0 ) { - IF (hHQ_core->old_is_transient[2] == 0) + IF( hHQ_core->old_is_transient[2] == 0 ) { - FOR (sfm = 0; sfm < HQ_FEC_SIGN_SFM; sfm++) + FOR( sfm = 0; sfm < HQ_FEC_SIGN_SFM; sfm++ ) { - IF (GE_16(hHQ_nbfec->prev_sign_switch[sfm], HQ_FEC_SIGN_THRES)) + IF( GE_16( hHQ_nbfec->prev_sign_switch[sfm], HQ_FEC_SIGN_THRES ) ) { - FOR (i = 0; i < HQ_FEC_BAND_SIZE; i++) + FOR( i = 0; i < HQ_FEC_BAND_SIZE; i++ ) { - t_audio_q_fx[i+sfm*HQ_FEC_BAND_SIZE] = L_negate(t_audio_q_fx[i+sfm*HQ_FEC_BAND_SIZE]); + t_audio_q_fx[i + sfm * HQ_FEC_BAND_SIZE] = L_negate( t_audio_q_fx[i + sfm * HQ_FEC_BAND_SIZE] ); move32(); } } @@ -234,13 +233,13 @@ void HQ_FEC_processing_fx( } ELSE { - FOR (sfm = 0; sfm < HQ_FEC_SIGN_SFM; sfm++) + FOR( sfm = 0; sfm < HQ_FEC_SIGN_SFM; sfm++ ) { - IF (GE_16(hHQ_nbfec->prev_sign_switch[sfm], HQ_FEC_SIGN_THRES_TRANS)) + IF( GE_16( hHQ_nbfec->prev_sign_switch[sfm], HQ_FEC_SIGN_THRES_TRANS ) ) { - FOR (i = 0; i < HQ_FEC_BAND_SIZE; i++) + FOR( i = 0; i < HQ_FEC_BAND_SIZE; i++ ) { - t_audio_q_fx[i+sfm*HQ_FEC_BAND_SIZE] = L_negate(t_audio_q_fx[i+sfm*HQ_FEC_BAND_SIZE]); + t_audio_q_fx[i + sfm * HQ_FEC_BAND_SIZE] = L_negate( t_audio_q_fx[i + sfm * HQ_FEC_BAND_SIZE] ); move32(); } } @@ -249,11 +248,11 @@ void HQ_FEC_processing_fx( } ELSE { - FOR (i = RANDOM_START*8; i < output_frame; i++) + FOR( i = RANDOM_START * 8; i < output_frame; i++ ) { - IF(Random(&hHQ_nbfec->HQ_FEC_seed) < 0) + IF( Random( &hHQ_nbfec->HQ_FEC_seed ) < 0 ) { - t_audio_q_fx[i] = L_negate(t_audio_q_fx[i]); + t_audio_q_fx[i] = L_negate( t_audio_q_fx[i] ); move32(); } } @@ -261,30 +260,30 @@ void HQ_FEC_processing_fx( } ELSE { - IF(hHQ_core->old_is_transient[1] ) /* hangover */ + IF( hHQ_core->old_is_transient[1] ) /* hangover */ { - FOR (i=0; i < output_frame; i++) + FOR( i = 0; i < output_frame; i++ ) { - hHQ_nbfec->old_coeffs_fx[i] = Mult_32_16(hHQ_nbfec->old_coeffs_fx[i], 23170); + hHQ_nbfec->old_coeffs_fx[i] = Mult_32_16( hHQ_nbfec->old_coeffs_fx[i], 23170 ); t_audio_q_fx[i] = hHQ_nbfec->old_coeffs_fx[i]; move32(); } } ELSE { - FOR (i = 0; i < RANDOM_START*8; i++) + FOR( i = 0; i < RANDOM_START * 8; i++ ) { - hHQ_nbfec->old_coeffs_fx[i] = Mult_32_16(hHQ_nbfec->old_coeffs_fx[i], 23170); + hHQ_nbfec->old_coeffs_fx[i] = Mult_32_16( hHQ_nbfec->old_coeffs_fx[i], 23170 ); t_audio_q_fx[i] = hHQ_nbfec->old_coeffs_fx[i]; move32(); } - FOR (i = RANDOM_START*8; i < output_frame; i++) + FOR( i = RANDOM_START * 8; i < output_frame; i++ ) { - hHQ_nbfec->old_coeffs_fx[i] = Mult_32_16(hHQ_nbfec->old_coeffs_fx[i], 23170); - IF (Random(&hHQ_nbfec->HQ_FEC_seed) < 0) + hHQ_nbfec->old_coeffs_fx[i] = Mult_32_16( hHQ_nbfec->old_coeffs_fx[i], 23170 ); + IF( Random( &hHQ_nbfec->HQ_FEC_seed ) < 0 ) { - t_audio_q_fx[i] = L_negate(hHQ_nbfec->old_coeffs_fx[i]); + t_audio_q_fx[i] = L_negate( hHQ_nbfec->old_coeffs_fx[i] ); move32(); } ELSE @@ -299,7 +298,7 @@ void HQ_FEC_processing_fx( ELSE /* st_fx->nbLostCmpt > 1 */ { test(); - IF( LT_16(energy_diff_fx, 1024)&&is_transient==0) + IF( LT_16( energy_diff_fx, 1024 ) && is_transient == 0 ) { num_pgf = 4; move16(); @@ -312,71 +311,72 @@ void HQ_FEC_processing_fx( Num_sb_bwe = num_Sb; move16(); - IF ( EQ_16(st_fx->nbLostCmpt, 2)) + IF( EQ_16( st_fx->nbLostCmpt, 2 ) ) { - FOR ( i=0; inbLostCmpt, mute_start)) + IF( GE_16( st_fx->nbLostCmpt, mute_start ) ) { /* Scaling */ - FOR ( i=0; i < output_frame; i++ ) + FOR( i = 0; i < output_frame; i++ ) { - hHQ_nbfec->old_coeffs_fx[i] = Mult_32_16(hHQ_nbfec->old_coeffs_fx[i], 23170); + hHQ_nbfec->old_coeffs_fx[i] = Mult_32_16( hHQ_nbfec->old_coeffs_fx[i], 23170 ); move32(); } } k = 0; move16(); - FOR ( i=0; i 0 ) + IF( r_p_fx[1] > 0 ) { - r_p_fx[1] = L_deposit_l(0); - norm_p_fx[i] = L_shr(norm_values_fx[0], 7);/*5*/ move32(); + r_p_fx[1] = L_deposit_l( 0 ); + norm_p_fx[i] = L_shr( norm_values_fx[0], 7 ); /*5*/ + move32(); } ELSE { - norm_p_fx[i] = L_add(r_p_fx[0], L_mult0(extract_l(r_p_fx[1]), sub(add(st_fx->nbLostCmpt, num_pgf), 1))); + norm_p_fx[i] = L_add( r_p_fx[0], L_mult0( extract_l( r_p_fx[1] ), sub( add( st_fx->nbLostCmpt, num_pgf ), 1 ) ) ); } test(); - IF ( norm_values_fx[0] != 0 && norm_p_fx[i] > 0 ) /* Avoid negative value of the predicted energy */ + IF( norm_values_fx[0] != 0 && norm_p_fx[i] > 0 ) /* Avoid negative value of the predicted energy */ { - exp1 = sub(norm_l(norm_p_fx[i]), 1); - exp2 = norm_l(norm_values_fx[0]); - tmp_fx = div_s(extract_h(L_shl(norm_p_fx[i], exp1)), - extract_h(L_shl(norm_values_fx[0], exp2)));/*15 + (5 + exp1 - 16) - (12 + exp2 - 16)*/ + exp1 = sub( norm_l( norm_p_fx[i] ), 1 ); + exp2 = norm_l( norm_values_fx[0] ); + tmp_fx = div_s( extract_h( L_shl( norm_p_fx[i], exp1 ) ), + extract_h( L_shl( norm_values_fx[0], exp2 ) ) ); /*15 + (5 + exp1 - 16) - (12 + exp2 - 16)*/ #ifdef BASOP_NOGLOB tmp_fx = shl_sat( tmp_fx, add( 6, sub( exp2, exp1 ) ) ); /*14*/ #else - tmp_fx = shl(tmp_fx, add(6, sub(exp2, exp1)));/*14*/ + tmp_fx = shl( tmp_fx, add( 6, sub( exp2, exp1 ) ) ); /*14*/ #endif - if (GT_16(tmp_fx, 16384)) + if ( GT_16( tmp_fx, 16384 ) ) { tmp_fx = 16384; move16(); } - FOR ( j=0; jNorm_gain_fx[k++] = shl_o(tmp_fx, 1, &Overflow); + hHQ_nbfec->Norm_gain_fx[k++] = shl_o( tmp_fx, 1, &Overflow ); #else - hHQ_nbfec->Norm_gain_fx[k++] = shl(tmp_fx, 1); + hHQ_nbfec->Norm_gain_fx[k++] = shl( tmp_fx, 1 ); #endif move16(); } @@ -384,9 +384,9 @@ void HQ_FEC_processing_fx( ELSE { /* Scale down the last gain with the fixed gain(-3dB) */ - FOR (j=0; jNorm_gain_fx[k] = mult_r(hHQ_nbfec->Norm_gain_fx[k], 23170); + hHQ_nbfec->Norm_gain_fx[k] = mult_r( hHQ_nbfec->Norm_gain_fx[k], 23170 ); move16(); k++; } @@ -394,8 +394,7 @@ void HQ_FEC_processing_fx( } /* Scaling for core band */ - FEC_scaling_fx(hHQ_nbfec->old_coeffs_fx, t_audio_q_fx, hHQ_nbfec->Norm_gain_fx, &hHQ_nbfec->HQ_FEC_seed, nb_sfm, sfm_start, sfm_end ); - + FEC_scaling_fx( hHQ_nbfec->old_coeffs_fx, t_audio_q_fx, hHQ_nbfec->Norm_gain_fx, &hHQ_nbfec->HQ_FEC_seed, nb_sfm, sfm_start, sfm_end ); } @@ -692,9 +691,9 @@ void ivas_HQ_FEC_Mem_update_fx( #ifdef IVAS_FLOAT_FIXED void HQ_FEC_Mem_update_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word32 *t_audio_q_fx, /*Q12*/ - Word32 *normq_fx, /*Q14*/ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word32 *t_audio_q_fx, /*Q12*/ + Word32 *normq_fx, /*Q14*/ Word16 *ynrm, Word16 *Num_bands_p, Word16 is_transient, @@ -702,10 +701,9 @@ void HQ_FEC_Mem_update_fx( Word16 c_switching_flag, Word16 nb_sfm, Word16 num_Sb, - Word16 *mean_en_high_fx, /*Q5*/ - Word16 hq_core_type, /* i : normal or low-rate MDCT(HQ) core */ - Word16 output_frame -) + Word16 *mean_en_high_fx, /*Q5*/ + Word16 hq_core_type, /* i : normal or low-rate MDCT(HQ) core */ + Word16 output_frame ) { Word16 Min_ind; Word32 Min_value; @@ -715,7 +713,7 @@ void HQ_FEC_Mem_update_fx( Word16 i, j, k; Word16 offset; Word16 exp, exp1, exp2, tmp_fx; - Word32* norm_values_fx; + Word32 *norm_values_fx; Word32 L_tmp, tmp_energy_fx = 0, Max_coeff_fx; Word32 en_high_fx[MAX_SB_NB]; HQ_NBFEC_HANDLE hHQ_nbfec; @@ -726,1335 +724,1328 @@ void HQ_FEC_Mem_update_fx( Flag Overflow = 0; #endif #ifdef ADD_IVAS_HQ_CODE_FEC - IF(EQ_16(output_frame, L_FRAME8k)) + IF( EQ_16( output_frame, L_FRAME8k ) ) { #endif - IF (is_transient) + IF( is_transient ) { - set16_fx(hHQ_nbfec->prev_sign_switch_2, 0, HQ_FEC_SIGN_SFM); - set16_fx(hHQ_nbfec->prev_sign_switch, 0, HQ_FEC_SIGN_SFM); + set16_fx( hHQ_nbfec->prev_sign_switch_2, 0, HQ_FEC_SIGN_SFM ); + set16_fx( hHQ_nbfec->prev_sign_switch, 0, HQ_FEC_SIGN_SFM ); } ELSE { - FOR (j = 0; j < HQ_FEC_SIGN_SFM; j++) + FOR( j = 0; j < HQ_FEC_SIGN_SFM; j++ ) { hHQ_nbfec->prev_sign_switch[j] = hHQ_nbfec->prev_sign_switch_2[j]; move16(); hHQ_nbfec->prev_sign_switch_2[j] = 0; move16(); - FOR (i = 0; i < HQ_FEC_BAND_SIZE; i++) + FOR( i = 0; i < HQ_FEC_BAND_SIZE; i++ ) { test(); test(); test(); - IF ((hHQ_nbfec->old_coeffs_fx[i+j*HQ_FEC_BAND_SIZE]>0 && t_audio_q_fx[i+j*HQ_FEC_BAND_SIZE]<0) - || (hHQ_nbfec->old_coeffs_fx[i+j*HQ_FEC_BAND_SIZE]<0 && t_audio_q_fx[i+j*HQ_FEC_BAND_SIZE]>0)) + IF( ( hHQ_nbfec->old_coeffs_fx[i + j * HQ_FEC_BAND_SIZE] > 0 && t_audio_q_fx[i + j * HQ_FEC_BAND_SIZE] < 0 ) || ( hHQ_nbfec->old_coeffs_fx[i + j * HQ_FEC_BAND_SIZE] < 0 && t_audio_q_fx[i + j * HQ_FEC_BAND_SIZE] > 0 ) ) { - hHQ_nbfec->prev_sign_switch[j] = add(hHQ_nbfec->prev_sign_switch[j], 1); + hHQ_nbfec->prev_sign_switch[j] = add( hHQ_nbfec->prev_sign_switch[j], 1 ); move16(); - hHQ_nbfec->prev_sign_switch_2[j] = add(hHQ_nbfec->prev_sign_switch_2[j], 1); + hHQ_nbfec->prev_sign_switch_2[j] = add( hHQ_nbfec->prev_sign_switch_2[j], 1 ); move16(); } } } } #ifndef ADD_IVAS_HQ_CODE_FEC - IF(EQ_16(output_frame, L_FRAME8k)) - { -#endif - /* if LR MDCT core is used, recalculate norms from decoded MDCT spectrum (using code from hq_hr_enc_fx()) */ - test(); - IF ( ( EQ_16(hqswb_clas, HQ_HVQ))||(EQ_16(hq_core_type,LOW_RATE_HQ_CORE))) + IF( EQ_16( output_frame, L_FRAME8k ) ) { - /* First group */ - logqnorm_fx(t_audio_q_fx, 12, ynrm, 32, WID_G1, (hqswb_clas == HQ_HVQ)); - j = ynrm[0]; - move16(); - offset = WID_G1; - move16(); - - FOR ( i=1; iynrm_values_fx[i][0]; - Copy32(norm_values_fx, &norm_values_fx[1], MAX_PGF-1); + FOR( i = 1; i < SFM_G1; i++ ) + { + logqnorm_fx( &t_audio_q_fx[offset], 12, &ynrm[i], 40, WID_G1, ( hqswb_clas == HQ_HVQ ) ); + offset += WID_G1; + move16(); + } + + /* Second group */ + FOR( i = SFM_G1; i < SFM_G1 + 2; i++ ) + { + logqnorm_fx( &t_audio_q_fx[offset], 12, &ynrm[i], 40, WID_G2, ( hqswb_clas == HQ_HVQ ) ); + offset += WID_G2; + move16(); + } + } - L_tmp = L_deposit_l(0); - FOR (j=0; jynrm_values_fx[i][0]; + Copy32( norm_values_fx, &norm_values_fx[1], MAX_PGF - 1 ); + + L_tmp = L_deposit_l( 0 ); + FOR( j = 0; j < Num_bands_p[i]; j++ ) + { + L_tmp = L_add( L_tmp, L_shr( normq_fx[k++], 3 ) ); /*11*/ + } #ifdef BASOP_NOGLOB - tmp_fx = shl_o(inv_tbl_fx[Num_bands_p[i]], 1, &Overflow);/*16*/ + tmp_fx = shl_o( inv_tbl_fx[Num_bands_p[i]], 1, &Overflow ); /*16*/ #else - tmp_fx = shl(inv_tbl_fx[Num_bands_p[i]], 1);/*16*/ + tmp_fx = shl( inv_tbl_fx[Num_bands_p[i]], 1 ); /*16*/ #endif - norm_values_fx[0] = Mult_32_16(L_tmp, tmp_fx);/*11 + 16 - 15*/ move32(); - tmp_energy_fx = L_add(tmp_energy_fx, L_shr(L_tmp, 3));/*8*/ - } - test(); - test(); - IF((c_switching_flag)||((EQ_16(st_fx->last_core, ACELP_CORE))&&(EQ_16(st_fx->core,HQ_CORE)))) - { - FOR (i=0; ilast_core, ACELP_CORE ) ) && ( EQ_16( st_fx->core, HQ_CORE ) ) ) ) { - FOR (j=1; jynrm_values_fx[i][j]= hHQ_nbfec->ynrm_values_fx[i][0]; - move32(); + FOR( j = 1; j < MAX_PGF; j++ ) + { + hHQ_nbfec->ynrm_values_fx[i][j] = hHQ_nbfec->ynrm_values_fx[i][0]; + move32(); + } } } - } - set16_fx(hHQ_nbfec->Norm_gain_fx, 32767, SFM_N_NB);/*15*/ - /* st->energy_MA_Curr[1]=Energy of the current frame */ - tmp_fx = inv_tbl_fx[nb_sfm]; - move16();/*15*/ - L_tmp = Mult_32_16(tmp_energy_fx, tmp_fx);/*8 + 15 - 15*/ + set16_fx( hHQ_nbfec->Norm_gain_fx, 32767, SFM_N_NB ); /*15*/ + /* st->energy_MA_Curr[1]=Energy of the current frame */ + tmp_fx = inv_tbl_fx[nb_sfm]; + move16(); /*15*/ + L_tmp = Mult_32_16( tmp_energy_fx, tmp_fx ); /*8 + 15 - 15*/ #ifdef BASOP_NOGLOB - hHQ_nbfec->energy_MA_Curr_fx[1] = extract_h( L_shl_sat( L_tmp, 16 - 8 ) ); + hHQ_nbfec->energy_MA_Curr_fx[1] = extract_h( L_shl_sat( L_tmp, 16 - 8 ) ); #else - hHQ_nbfec->energy_MA_Curr_fx[1] = extract_h(L_shl(L_tmp, 16-8)); + hHQ_nbfec->energy_MA_Curr_fx[1] = extract_h( L_shl( L_tmp, 16 - 8 ) ); #endif - /* Moving Average */ - hHQ_nbfec->energy_MA_Curr_fx[0] = s_max(1,add(mult_r(26214, hHQ_nbfec->energy_MA_Curr_fx[0]), mult_r(6554, hHQ_nbfec->energy_MA_Curr_fx[1]))); + /* Moving Average */ + hHQ_nbfec->energy_MA_Curr_fx[0] = s_max( 1, add( mult_r( 26214, hHQ_nbfec->energy_MA_Curr_fx[0] ), mult_r( 6554, hHQ_nbfec->energy_MA_Curr_fx[1] ) ) ); + + /*st->diff_energy = (float)fabs((st->energy_MA_Curr[1] - st->energy_MA_Curr[0])/st->energy_MA_Curr[0]); */ + hHQ_nbfec->diff_energy_fx = abs_s( sub( hHQ_nbfec->energy_MA_Curr_fx[1], hHQ_nbfec->energy_MA_Curr_fx[0] ) ); + exp1 = sub( norm_l( hHQ_nbfec->diff_energy_fx ), 1 ); + exp2 = norm_l( hHQ_nbfec->energy_MA_Curr_fx[0] ); + hHQ_nbfec->diff_energy_fx = div_s( extract_h( L_shl( hHQ_nbfec->diff_energy_fx, exp1 ) ), extract_h( L_shl( hHQ_nbfec->energy_MA_Curr_fx[0], exp2 ) ) ); + exp = add( 15, sub( exp1, exp2 ) ); + hHQ_nbfec->diff_energy_fx = shl( hHQ_nbfec->diff_energy_fx, sub( 11, exp ) ); /*11*/ - /*st->diff_energy = (float)fabs((st->energy_MA_Curr[1] - st->energy_MA_Curr[0])/st->energy_MA_Curr[0]); */ - hHQ_nbfec->diff_energy_fx = abs_s(sub(hHQ_nbfec->energy_MA_Curr_fx[1], hHQ_nbfec->energy_MA_Curr_fx[0])); - exp1 = sub(norm_l(hHQ_nbfec->diff_energy_fx), 1); - exp2 = norm_l(hHQ_nbfec->energy_MA_Curr_fx[0]); - hHQ_nbfec->diff_energy_fx = div_s(extract_h(L_shl(hHQ_nbfec->diff_energy_fx, exp1)), extract_h(L_shl(hHQ_nbfec->energy_MA_Curr_fx[0], exp2))); - exp = add(15, sub(exp1, exp2)); - hHQ_nbfec->diff_energy_fx = shl(hHQ_nbfec->diff_energy_fx, sub(11, exp));/*11*/ + /* Classify the stationary mode : 12% */ + IF( LT_16( hHQ_nbfec->diff_energy_fx, ED_THRES_12P_fx ) ) + { + stat_mode_curr = 1; + move16(); + } + ELSE + { + stat_mode_curr = 0; + move16(); + } - /* Classify the stationary mode : 12% */ - IF (LT_16(hHQ_nbfec->diff_energy_fx, ED_THRES_12P_fx)) - { - stat_mode_curr = 1; - move16(); - } - ELSE - { - stat_mode_curr = 0; - move16(); - } + /* Apply Hysteresis to prevent frequent mode changing */ + IF( EQ_16( hHQ_nbfec->stat_mode_old, stat_mode_curr ) ) + { + hHQ_nbfec->stat_mode_out = stat_mode_curr; + move16(); + } - /* Apply Hysteresis to prevent frequent mode changing */ - IF(EQ_16(hHQ_nbfec->stat_mode_old, stat_mode_curr)) - { - hHQ_nbfec->stat_mode_out = stat_mode_curr; + hHQ_nbfec->stat_mode_old = stat_mode_curr; move16(); - } - - hHQ_nbfec->stat_mode_old = stat_mode_curr; - move16(); - /* Find max. band index (Minimum value means maximum energy) */ - Min_ind=0; - move16(); - Min_value = L_deposit_l(100); - FOR (i=0; iynrm_values[i][j+1];*/ - en_high_fx[i] = L_add(en_high_fx[i], L_shr(hHQ_nbfec->ynrm_values_fx[i][j+1], 1));/*Q12*/ move32(); + en_high_fx[i] = L_deposit_l( 0 ); + FOR( j = 0; j < 2; j++ ) + { + /*en_high[i] += 0.5f*st->ynrm_values[i][j+1];*/ + en_high_fx[i] = L_add( en_high_fx[i], L_shr( hHQ_nbfec->ynrm_values_fx[i][j + 1], 1 ) ); /*Q12*/ + move32(); + } } - } - *mean_en_high_fx = 0; - move16(); - FOR (i=k; iynrm_values[i][0]);*/ - exp1 = sub(norm_l(en_high_fx[i]), 1); - exp2 = norm_l(hHQ_nbfec->ynrm_values_fx[i][0]); - tmp_fx = div_s(extract_h(L_shl(en_high_fx[i], exp1)), extract_h(L_shl(hHQ_nbfec->ynrm_values_fx[i][0], exp2))); - exp = add(15, sub(exp1, exp2)); + *mean_en_high_fx = 0; + move16(); + FOR( i = k; i < num_Sb; i++ ) + { + /* *mean_en_high += (float)(en_high[i]/st->ynrm_values[i][0]);*/ + exp1 = sub( norm_l( en_high_fx[i] ), 1 ); + exp2 = norm_l( hHQ_nbfec->ynrm_values_fx[i][0] ); + tmp_fx = div_s( extract_h( L_shl( en_high_fx[i], exp1 ) ), extract_h( L_shl( hHQ_nbfec->ynrm_values_fx[i][0], exp2 ) ) ); + exp = add( 15, sub( exp1, exp2 ) ); #ifdef BASOP_NOGLOB - *mean_en_high_fx = add_o(*mean_en_high_fx, shr_o(tmp_fx, sub(exp, 5), &Overflow), &Overflow); + *mean_en_high_fx = add_o( *mean_en_high_fx, shr_o( tmp_fx, sub( exp, 5 ), &Overflow ), &Overflow ); #else - *mean_en_high_fx = add(*mean_en_high_fx, shr(tmp_fx, sub(exp, 5))); + *mean_en_high_fx = add( *mean_en_high_fx, shr( tmp_fx, sub( exp, 5 ) ) ); #endif - } - *mean_en_high_fx = mult(*mean_en_high_fx, inv_tbl_fx[num_Sb-k]); + } + *mean_en_high_fx = mult( *mean_en_high_fx, inv_tbl_fx[num_Sb - k] ); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF ((LT_16(Min_ind, 5))&&(LT_16(abs_s(sub(Min_ind, hHQ_nbfec->old_Min_ind)),2))&&(LT_16(hHQ_nbfec->diff_energy_fx,ED_THRES_90P_fx))&&(!st_fx->bfi)&&(!st_fx->prev_bfi)&&(!st_fx->prev_old_bfi) - &&(!is_transient)&&(!hHQ_core->old_is_transient[1]) && (hHQ_nbfec->prev_last_core==HQ_CORE) && (st_fx->last_core==HQ_CORE)) - { - hHQ_nbfec->phase_mat_flag = 1; - move16(); test(); - if ((Min_ind == 0)&&(LT_16(Max_ind, 3))) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( LT_16( Min_ind, 5 ) ) && ( LT_16( abs_s( sub( Min_ind, hHQ_nbfec->old_Min_ind ) ), 2 ) ) && ( LT_16( hHQ_nbfec->diff_energy_fx, ED_THRES_90P_fx ) ) && ( !st_fx->bfi ) && ( !st_fx->prev_bfi ) && ( !st_fx->prev_old_bfi ) && ( !is_transient ) && ( !hHQ_core->old_is_transient[1] ) && ( hHQ_nbfec->prev_last_core == HQ_CORE ) && ( st_fx->last_core == HQ_CORE ) ) + { + hHQ_nbfec->phase_mat_flag = 1; + move16(); + test(); + if ( ( Min_ind == 0 ) && ( LT_16( Max_ind, 3 ) ) ) + { + hHQ_nbfec->phase_mat_flag = 0; + move16(); + } + } + ELSE { hHQ_nbfec->phase_mat_flag = 0; move16(); } + + hHQ_nbfec->old_Min_ind = Min_ind; + move16(); } - ELSE + + FOR( i = 0; i < L_FRAME8k; i++ ) { - hHQ_nbfec->phase_mat_flag = 0; - move16(); + hHQ_nbfec->old_coeffs_fx[i] = t_audio_q_fx[i]; + move32(); } - hHQ_nbfec->old_Min_ind = Min_ind; + hHQ_core->old_is_transient[2] = hHQ_core->old_is_transient[1]; + move16(); + hHQ_core->old_is_transient[1] = hHQ_core->old_is_transient[0]; + move16(); + hHQ_core->old_is_transient[0] = is_transient; move16(); - } - FOR (i=0; i < L_FRAME8k; i++) - { - hHQ_nbfec->old_coeffs_fx[i] = t_audio_q_fx[i]; - move32(); + return; } - - hHQ_core->old_is_transient[2] = hHQ_core->old_is_transient[1]; - move16(); - hHQ_core->old_is_transient[1] = hHQ_core->old_is_transient[0]; - move16(); - hHQ_core->old_is_transient[0] = is_transient; - move16(); - - return; -} #endif #ifdef IVAS_FLOAT_FIXED -static Word16 find_best_delay_fx( - Word16 *mu_o_fx, - Word16 *in_fx, - Word16 mind1, - Word16 maxd1, - Word16 lin, - Word16 delta, - Word16 *false_flag -) -{ - Word16 i, d1, k; - Word16 d1m = 0; - - Word16 tmp, exp1, exp2; - Word32 L_tmp1, L_tmp2; - - Word32 min_sq_cross_fx, min_corr_fx; - Word32 accA_fx, accB_fx; - Word32 Rxy_fx[MAXDELAY_FEC], Ryy_fx[MAXDELAY_FEC]; + static Word16 find_best_delay_fx( + Word16 * mu_o_fx, + Word16 * in_fx, + Word16 mind1, + Word16 maxd1, + Word16 lin, + Word16 delta, + Word16 * false_flag ) + { + Word16 i, d1, k; + Word16 d1m = 0; + + Word16 tmp, exp1, exp2; + Word32 L_tmp1, L_tmp2; + + Word32 min_sq_cross_fx, min_corr_fx; + Word32 accA_fx, accB_fx; + Word32 Rxy_fx[MAXDELAY_FEC], Ryy_fx[MAXDELAY_FEC]; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; + Flag Overflow = 0; #endif - d1 = mind1; - move16(); - FOR ( k = 0; k < (maxd1-mind1)/delta; k++ ) - { - accA_fx = L_deposit_l(0); - accB_fx = L_deposit_l(0); - FOR ( i = 0; i < lin; i += delta ) + d1 = mind1; + move16(); + FOR( k = 0; k < ( maxd1 - mind1 ) / delta; k++ ) { + accA_fx = L_deposit_l( 0 ); + accB_fx = L_deposit_l( 0 ); + FOR( i = 0; i < lin; i += delta ) + { #ifdef BASOP_NOGLOB - accA_fx = L_add_sat( accA_fx, L_shr( L_mult_sat( mu_o_fx[d1 + i], mu_o_fx[d1 + i] ), 2 ) ); - accB_fx = L_add_sat(accB_fx, L_shr(L_mult_sat(mu_o_fx[d1+i], in_fx[i]),2)); + accA_fx = L_add_sat( accA_fx, L_shr( L_mult_sat( mu_o_fx[d1 + i], mu_o_fx[d1 + i] ), 2 ) ); + accB_fx = L_add_sat( accB_fx, L_shr( L_mult_sat( mu_o_fx[d1 + i], in_fx[i] ), 2 ) ); #else accA_fx = L_add( accA_fx, L_shr( L_mult( mu_o_fx[d1 + i], mu_o_fx[d1 + i] ), 2 ) ); - accB_fx = L_add(accB_fx, L_shr(L_mult(mu_o_fx[d1+i], in_fx[i]),2)); + accB_fx = L_add( accB_fx, L_shr( L_mult( mu_o_fx[d1 + i], in_fx[i] ), 2 ) ); #endif + } + + Rxy_fx[k] = accB_fx; + move32(); + Ryy_fx[k] = accA_fx; + move32(); + + d1 = add( d1, delta ); } - Rxy_fx[k] = accB_fx; - move32(); - Ryy_fx[k] = accA_fx; + /* Obtain the best delay values */ + min_sq_cross_fx = 0x80000000; move32(); + min_corr_fx = L_deposit_l( 0 ); + exp2 = 0; + move16(); + FOR( d1 = 0; d1 < ( maxd1 - mind1 ) / delta; d1++ ) + { + IF( L_abs( Rxy_fx[d1] ) > L_abs( Ryy_fx[d1] ) ) + exp1 = norm_l( Rxy_fx[d1] ); + ELSE + exp1 = norm_l( Ryy_fx[d1] ); - d1 = add(d1, delta); - } + L_tmp1 = Mult_32_32( L_shl( Rxy_fx[d1], exp1 ), L_shl( min_corr_fx, exp2 ) ); + L_tmp2 = Mult_32_32( L_shl( Ryy_fx[d1], exp1 ), L_shl( min_sq_cross_fx, exp2 ) ); + IF( GE_32( L_tmp1, L_tmp2 ) ) + { + d1m = d1; + move16(); + min_corr_fx = L_add( Ryy_fx[d1], 0 ); /*12 + 12 - 31 */ + min_sq_cross_fx = L_add( Rxy_fx[d1], 0 ); /*12 + 12 - 31 */ + exp2 = exp1; + move16(); + } + } - /* Obtain the best delay values */ - min_sq_cross_fx = 0x80000000; - move32(); - min_corr_fx = L_deposit_l(0); - exp2 = 0; - move16(); - FOR ( d1 = 0; d1 < (maxd1-mind1)/delta; d1++ ) - { - IF (L_abs(Rxy_fx[d1]) > L_abs(Ryy_fx[d1])) - exp1 = norm_l(Rxy_fx[d1]); + test(); + IF( ( min_sq_cross_fx <= 0 ) || ( min_corr_fx <= 0 ) ) + { + tmp = 0; + move16(); /* If cross correlation is negative, the division per the energy will always be negative --> tmp will be < 8192, no need to do the division per say */ + } ELSE - exp1 = norm_l(Ryy_fx[d1]); + { + /*d1m *= delta; */ + d1m = extract_l( L_mult0( d1m, delta ) ); + + exp1 = sub( norm_l( min_sq_cross_fx ), 1 ); + exp2 = norm_l( min_corr_fx ); + L_tmp1 = L_shl( min_sq_cross_fx, exp1 ); + L_tmp2 = L_shl( min_corr_fx, exp2 ); + tmp = div_s( extract_h( L_tmp1 ), extract_h( L_tmp2 ) ); /*15 + exp1 - exp2 */ +#ifdef BASOP_NOGLOB + tmp = shl_o( tmp, sub( exp2, add( exp1, 1 ) ), &Overflow ); /*14 */ +#else + tmp = shl( tmp, sub( exp2, add( exp1, 1 ) ) ); /*14 */ +#endif + } - L_tmp1 = Mult_32_32(L_shl(Rxy_fx[d1], exp1), L_shl(min_corr_fx, exp2)); - L_tmp2 = Mult_32_32(L_shl(Ryy_fx[d1], exp1), L_shl(min_sq_cross_fx, exp2)); - IF ( GE_32(L_tmp1, L_tmp2)) + *false_flag = 0; + move16(); + test(); + if ( LT_16( tmp, 8192 ) || GT_16( tmp, 24576 ) ) { - d1m = d1; - move16(); - min_corr_fx = L_add(Ryy_fx[d1], 0); /*12 + 12 - 31 */ - min_sq_cross_fx = L_add(Rxy_fx[d1], 0); /*12 + 12 - 31 */ - exp2 = exp1; + *false_flag = 1; move16(); } - } - test(); - IF((min_sq_cross_fx<=0) || (min_corr_fx<=0)) - { - tmp = 0; - move16(); /* If cross correlation is negative, the division per the energy will always be negative --> tmp will be < 8192, no need to do the division per say */ - } - ELSE - { - /*d1m *= delta; */ - d1m = extract_l(L_mult0(d1m, delta)); - - exp1 = sub(norm_l(min_sq_cross_fx), 1); - exp2 = norm_l(min_corr_fx); - L_tmp1 = L_shl(min_sq_cross_fx, exp1); - L_tmp2 = L_shl(min_corr_fx, exp2); - tmp = div_s(extract_h(L_tmp1), extract_h(L_tmp2));/*15 + exp1 - exp2 */ -#ifdef BASOP_NOGLOB - tmp = shl_o(tmp, sub(exp2, add(exp1, 1)), &Overflow);/*14 */ -#else - tmp = shl(tmp, sub(exp2, add(exp1, 1)));/*14 */ -#endif + return d1m; } - *false_flag = 0; - move16(); - test(); - if (LT_16(tmp, 8192)||GT_16(tmp,24576)) + static Word16 Search_Max_Corr_fx( + Word16 * mu_o_fx, /* i : *old_auOut_2fr, */ + Word16 old_Min_ind, /* i : *old_auOut_2fr, */ + const Word16 L /* i : L/2 */ + ) { - *false_flag = 1; - move16(); - } + Word16 pos; + Word16 pos2, delta2; + Word16 lin, delta; + Word16 mind1, maxd1; + Word16 false_flag; + Word16 min_d1, max_d1; + Word16 tmp1, tmp2; + Word16 *in_fx; - return d1m; + IF( old_Min_ind == 0 ) + { + /*lin = 8*L/20; */ /* Basic size of the block for phase matching */ + lin = mult_r( L, 13107 ); /* Basic size of the block for phase matching */ + /*min_dist = -1e35f; */ + mind1 = 0; + move16(); /* min value of delay d1 to search for */ + /*maxd1 = 12*L/20; */ /* max value of delay d1 to search for */ + maxd1 = mult_r( L, 19661 ); /* max value of delay d1 to search for */ + + /*in = mu_o + 2*L -lin; */ + in_fx = mu_o_fx + 2 * L - lin; + move16(); -} + /* generate correlation */ + delta = 2; + move16(); + delta2 = 1; + move16(); -static Word16 Search_Max_Corr_fx( - Word16 *mu_o_fx, /* i : *old_auOut_2fr, */ - Word16 old_Min_ind, /* i : *old_auOut_2fr, */ - const Word16 L /* i : L/2 */ -) -{ - Word16 pos; - Word16 pos2,delta2; - Word16 lin, delta; - Word16 mind1,maxd1; - Word16 false_flag; - Word16 min_d1, max_d1; - Word16 tmp1, tmp2; - Word16 *in_fx; - - IF (old_Min_ind == 0) - { - /*lin = 8*L/20; */ /* Basic size of the block for phase matching */ - lin = mult_r(L, 13107); /* Basic size of the block for phase matching */ - /*min_dist = -1e35f; */ - mind1 = 0; - move16(); /* min value of delay d1 to search for */ - /*maxd1 = 12*L/20; */ /* max value of delay d1 to search for */ - maxd1 = mult_r(L, 19661); /* max value of delay d1 to search for */ - - /*in = mu_o + 2*L -lin; */ - in_fx = mu_o_fx + 2*L - lin; - move16(); - - /* generate correlation */ - delta = 2; - move16(); - delta2 = 1; - move16(); + pos = find_best_delay_fx( mu_o_fx, in_fx, mind1, maxd1, lin, delta, &false_flag ); - pos = find_best_delay_fx(mu_o_fx, in_fx, mind1, maxd1, lin, delta, &false_flag); + IF( false_flag ) + { + return 0; + } - IF (false_flag) - { - return 0; - } + tmp1 = add( mind1, sub( add( pos, 1 ), delta ) ); + tmp2 = add( mind1, add( pos, delta ) ); + min_d1 = s_max( mind1, tmp1 ); + max_d1 = s_min( maxd1, tmp2 ); + pos2 = find_best_delay_fx( mu_o_fx, in_fx, min_d1, max_d1, lin, delta2, &false_flag ); + IF( GT_16( mind1, tmp1 ) ) + { + pos = pos2; + move16(); + } + ELSE + { + pos = add( pos, add( sub( pos2, delta ), 1 ) ); + } - tmp1 = add(mind1, sub(add(pos, 1), delta)); - tmp2 = add(mind1, add(pos, delta)); - min_d1 = s_max(mind1, tmp1); - max_d1 = s_min(maxd1, tmp2); - pos2 = find_best_delay_fx(mu_o_fx, in_fx, min_d1, max_d1, lin, delta2, &false_flag); - IF (GT_16(mind1, tmp1)) - { - pos = pos2; - move16(); + pos = add( pos, add( lin, mind1 ) ); } ELSE { - pos = add(pos, add(sub(pos2, delta), 1)); - } + lin = mult_r( L, 9830 ); + mind1 = mult_r( L, 14746 ); /* min value of delay d1 to search for */ + maxd1 = mult_r( L, 22938 ); /* max value of delay d1 to search for */ + in_fx = mu_o_fx + 2 * L - lin; + move16(); - pos = add(pos, add(lin, mind1)); - } - ELSE - { - lin = mult_r(L, 9830); - mind1 = mult_r(L, 14746); /* min value of delay d1 to search for */ - maxd1 = mult_r(L, 22938); /* max value of delay d1 to search for */ - in_fx = mu_o_fx + 2*L - lin; - move16(); + /* generate correlation */ + delta = 2; + move16(); + delta2 = 1; + move16(); - /* generate correlation */ - delta = 2; - move16(); - delta2 = 1; - move16(); + pos = find_best_delay_fx( mu_o_fx, in_fx, mind1, maxd1, lin, delta, &false_flag ); - pos = find_best_delay_fx(mu_o_fx, in_fx, mind1, maxd1, lin, delta, &false_flag); + IF( false_flag ) + { + return 0; + } - IF (false_flag) - { - return 0; + tmp1 = add( mind1, add( sub( pos, delta ), 1 ) ); + tmp2 = add( mind1, add( pos, delta ) ); + min_d1 = s_max( mind1, tmp1 ); + max_d1 = s_min( maxd1, tmp2 ); + pos2 = find_best_delay_fx( mu_o_fx, in_fx, min_d1, max_d1, lin, delta2, &false_flag ); + + IF( GT_16( mind1, tmp1 ) ) + { + pos = pos2; + move16(); + } + ELSE + { + pos = add( pos, add( sub( pos2, delta ), 1 ) ); + } + pos = add( pos, add( lin, mind1 ) ); } - tmp1 = add(mind1, add(sub(pos, delta), 1)); - tmp2 = add(mind1, add(pos, delta)); - min_d1 = s_max(mind1, tmp1); - max_d1 = s_min(maxd1, tmp2); - pos2 = find_best_delay_fx(mu_o_fx, in_fx, min_d1, max_d1, lin, delta2, &false_flag); + return pos; + } + + static Word16 FEC_phase_matching_fx( + HQ_NBFEC_HANDLE st_fx, /* i : Decoder State */ + Word32 * ImdctOut_fx, /* i : input */ + Word16 * auOut_fx, /* o : output audio */ + Word16 * OldauOut_fx, + Word16 OldauOut_pha_fx[2][N_LEAD_NB] ) + { + Word16 i; + Word16 pos, remain; + Word16 ol_size; + Word16 L_overlap, L; + Word16 ImdctOutWin_fx[2 * L_FRAME8k]; + Word16 OldauOutnoWin_fx[L_FRAME8k]; + Word16 OldauOut2_fx[L_FRAME8k]; + Word16 win_NB_fx[L_FRAME8k + 25]; + Word16 exp1, exp2, tmp; + Word32 pow1_fx, pow22_fx; + Word16 SmoothingWin_NB3_fx[24]; + + L = L_FRAME8k; + move16(); + ol_size = 2 * L / 20; + move16(); + L_overlap = 3 * L / 20; + move16(); - IF (GT_16(mind1, tmp1)) + FOR( i = 0; i < L_overlap; i++ ) { - pos = pos2; + SmoothingWin_NB3_fx[i] = SmoothingWin_NB875_fx[i * 3]; move16(); } - ELSE + + FOR( i = 0; i < L + 25; i++ ) { - pos = add(pos, add(sub(pos2, delta), 1)); + win_NB_fx[i] = window_48kHz_fx[i * 6 + 3]; + move16(); } - pos = add(pos, add(lin, mind1)); - } + set16_fx( ImdctOutWin_fx, 0, 2 * L ); - return pos; -} + pos = Search_Max_Corr_fx( st_fx->old_auOut_2fr_fx, st_fx->old_Min_ind, L ); -static Word16 FEC_phase_matching_fx( - HQ_NBFEC_HANDLE st_fx, /* i : Decoder State */ - Word32 *ImdctOut_fx, /* i : input */ - Word16 *auOut_fx, /* o : output audio */ - Word16 *OldauOut_fx, - Word16 OldauOut_pha_fx[2][N_LEAD_NB] -) -{ - Word16 i; - Word16 pos, remain; - Word16 ol_size; - Word16 L_overlap, L; - Word16 ImdctOutWin_fx[2*L_FRAME8k]; - Word16 OldauOutnoWin_fx[L_FRAME8k]; - Word16 OldauOut2_fx[L_FRAME8k]; - Word16 win_NB_fx[L_FRAME8k + 25]; - Word16 exp1, exp2, tmp; - Word32 pow1_fx, pow22_fx; - Word16 SmoothingWin_NB3_fx[24]; - - L = L_FRAME8k; - move16(); - ol_size = 2*L/20; - move16(); - L_overlap = 3*L/20; - move16(); - - FOR (i=0; iold_auOut_2fr_fx, st_fx->old_Min_ind, L); - - IF (pos == 0) - { - return 1; - } - - /* Repetition */ - remain = L+N_Z_L_NB - ((2*L)-pos); - move16(); - Copy(&st_fx->old_auOut_2fr_fx[pos], &ImdctOutWin_fx[N_ZERO_NB], (2*L)-pos); + Copy( &st_fx->old_auOut_2fr_fx[pos], &ImdctOutWin_fx[N_ZERO_NB], ( 2 * L ) - pos ); - /* OldauOut without windowing */ - FOR (i = N_ZERO_NB; i < L/2; i++) - { - OldauOutnoWin_fx[i-N_ZERO_NB] = extract_l( L_shr( L_negate(st_fx->oldIMDCTout_fx[L/2 - 1 - i]), 6 ) ); - } - FOR(i = 0; i < L/2; i++) - { - OldauOutnoWin_fx[i+N_ZERO_O_NB] = extract_l( L_shr( L_negate(st_fx->oldIMDCTout_fx[i]), 6 ) ); - } + /* OldauOut without windowing */ + FOR( i = N_ZERO_NB; i < L / 2; i++ ) + { + OldauOutnoWin_fx[i - N_ZERO_NB] = extract_l( L_shr( L_negate( st_fx->oldIMDCTout_fx[L / 2 - 1 - i] ), 6 ) ); + } + FOR( i = 0; i < L / 2; i++ ) + { + OldauOutnoWin_fx[i + N_ZERO_O_NB] = extract_l( L_shr( L_negate( st_fx->oldIMDCTout_fx[i] ), 6 ) ); + } - Copy(OldauOutnoWin_fx, &ImdctOutWin_fx[N_ZERO_NB+(2*L)-pos], remain); + Copy( OldauOutnoWin_fx, &ImdctOutWin_fx[N_ZERO_NB + ( 2 * L ) - pos], remain ); - pow1_fx = L_deposit_l(0); - pow22_fx = L_deposit_l(0); - FOR (i = 0; i < L; i++) - { - pow1_fx = L_add(pow1_fx, shr(abs_s(st_fx->old_auOut_2fr_fx[L+i]), 1)); - pow22_fx = L_add(pow22_fx, shr(abs_s(ImdctOutWin_fx[N_ZERO_NB+i]), 1)); - } - IF(pow22_fx != 0) - { - exp1 = sub(norm_l(pow1_fx), 1); - exp2 = norm_l(pow22_fx); - tmp = div_s(extract_h(L_shl(pow1_fx, exp1)), extract_h(L_shl(pow22_fx, exp2)));/*15 + exp1 - exp2*/ - tmp = shl(tmp, sub(sub(exp2, exp1), 1));/*14*/ - FOR (i = N_ZERO_NB; i < 2*L; i++) + pow1_fx = L_deposit_l( 0 ); + pow22_fx = L_deposit_l( 0 ); + FOR( i = 0; i < L; i++ ) + { + pow1_fx = L_add( pow1_fx, shr( abs_s( st_fx->old_auOut_2fr_fx[L + i] ), 1 ) ); + pow22_fx = L_add( pow22_fx, shr( abs_s( ImdctOutWin_fx[N_ZERO_NB + i] ), 1 ) ); + } + IF( pow22_fx != 0 ) { + exp1 = sub( norm_l( pow1_fx ), 1 ); + exp2 = norm_l( pow22_fx ); + tmp = div_s( extract_h( L_shl( pow1_fx, exp1 ) ), extract_h( L_shl( pow22_fx, exp2 ) ) ); /*15 + exp1 - exp2*/ + tmp = shl( tmp, sub( sub( exp2, exp1 ), 1 ) ); /*14*/ + FOR( i = N_ZERO_NB; i < 2 * L; i++ ) + { #ifdef BASOP_NOGLOB - ImdctOutWin_fx[i] = shl_sat( mult( ImdctOutWin_fx[i], tmp ), 1 ); + ImdctOutWin_fx[i] = shl_sat( mult( ImdctOutWin_fx[i], tmp ), 1 ); #else ImdctOutWin_fx[i] = shl( mult( ImdctOutWin_fx[i], tmp ), 1 ); #endif + } } - } - Smoothing_vector_NB_fx(OldauOutnoWin_fx, &ImdctOutWin_fx[N_ZERO_NB], SmoothingWin_NB2_fx, auOut_fx, ol_size); - - FOR (i = 0; i < L/2; i++) - { - /*ImdctOutWin[3*L/2 + i] *= win_NB[L/2-i-1];*/ - ImdctOutWin_fx[3*L/2 + i] = mult(ImdctOutWin_fx[3*L/2 + i], win_NB_fx[L/2-i-1]); - move16(); - } - - FOR (i = N_ZERO_NB; i < L/2; i++) - { - /*ImdctOutWin_fx[L + i] *= win_NB_fx[(L-1-i)];*/ - ImdctOutWin_fx[L + i] = mult(ImdctOutWin_fx[L + i], win_NB_fx[(L-1-i)]); - move16(); - } + Smoothing_vector_NB_fx( OldauOutnoWin_fx, &ImdctOutWin_fx[N_ZERO_NB], SmoothingWin_NB2_fx, auOut_fx, ol_size ); - Copy(&ImdctOutWin_fx[N_Z_L_O_NB], &OldauOut_pha_fx[0][0], N_LEAD_NB); - Copy(&ImdctOutWin_fx[ol_size+N_ZERO_NB], &auOut_fx[ol_size], N_Z_L_NB-ol_size); - Copy(&ImdctOutWin_fx[L], &auOut_fx[N_Z_L_NB], N_ZERO_NB); - Copy(&ImdctOutWin_fx[L], OldauOut_fx, L); + FOR( i = 0; i < L / 2; i++ ) + { + /*ImdctOutWin[3*L/2 + i] *= win_NB[L/2-i-1];*/ + ImdctOutWin_fx[3 * L / 2 + i] = mult( ImdctOutWin_fx[3 * L / 2 + i], win_NB_fx[L / 2 - i - 1] ); + move16(); + } - FOR (i = 0; i < L/2; i++) - { - OldauOut2_fx[i] = extract_l( L_shr( L_negate(ImdctOut_fx[L/2 - 1 - i]), 6 ) ); - OldauOut2_fx[L/2+i] = extract_l( L_shr( L_negate(ImdctOut_fx[i]), 6 ) ); - } + FOR( i = N_ZERO_NB; i < L / 2; i++ ) + { + /*ImdctOutWin_fx[L + i] *= win_NB_fx[(L-1-i)];*/ + ImdctOutWin_fx[L + i] = mult( ImdctOutWin_fx[L + i], win_NB_fx[( L - 1 - i )] ); + move16(); + } - Smoothing_vector_NB_fx(&ImdctOutWin_fx[N_Z_L_O_NB], &OldauOut2_fx[N_ZERO_NB], SmoothingWin_NB3_fx, &OldauOut_pha_fx[1][0], L_overlap); + Copy( &ImdctOutWin_fx[N_Z_L_O_NB], &OldauOut_pha_fx[0][0], N_LEAD_NB ); + Copy( &ImdctOutWin_fx[ol_size + N_ZERO_NB], &auOut_fx[ol_size], N_Z_L_NB - ol_size ); + Copy( &ImdctOutWin_fx[L], &auOut_fx[N_Z_L_NB], N_ZERO_NB ); + Copy( &ImdctOutWin_fx[L], OldauOut_fx, L ); - FOR (i=L_overlap; i Q0 */ - } - FOR (i = 0; i < L/2; i++) + static void Repetition_smoothing_nextgood_fx( + const Word32 *ImdctOut_fx, /* i : input */ + Word16 *auOut_fx, /* o : output audio */ + Word32 *OldImdctOut_fx, /* i : input */ + Word16 *OldauOut_fx, /* i/o: audio from previous frame */ + Word16 cur_data_use_flag, /* i : current imdct data use flag */ + Word16 overlap_time ) { - /*OldauOut[i+N_ZERO_O_NB] = -OldImdctOut[i];*/ - OldauOut_fx[i+N_ZERO_O_NB] = extract_l( L_shr( L_negate(OldImdctOut_fx[i]), 6 )); /* Q6 -> Q0 */ - } + Word16 i; + Word16 L_overlap; + Word16 ol_size; + Word16 L; + Word16 ImdctOutWin_fx[2 * L_FRAME8k]; + Word16 win_NB_fx[L_FRAME8k + 25]; - /* Overlapping with next good frame : Overlapping to remove the discontinuity */ - IF (cur_data_use_flag) - { - ol_size = N_LEAD_NB; + L = L_FRAME8k; move16(); - FOR (i = N_ZERO_NB; i < L/2; i++) + FOR( i = 0; i < L_FRAME8k + 25; i++ ) + { + /*win_NB[i] = window_48kHz[i*6+3];*/ + win_NB_fx[i] = window_48kHz_fx[i * 6 + 3]; + move16(); + } + + FOR( i = N_ZERO_NB; i < L / 2; i++ ) { - /* ImdctOutWin[i+L] = -ImdctOut[L/2 - 1 - i]; */ - ImdctOutWin_fx[i+L] = extract_l( L_shr( L_negate(ImdctOut_fx[L/2 - 1 - i]), 6 ) ); + /*OldauOut[i-N_ZERO_NB] = -OldImdctOut[L/2 - 1 - i];*/ + OldauOut_fx[i - N_ZERO_NB] = extract_l( L_shr( L_negate( OldImdctOut_fx[L / 2 - 1 - i] ), 6 ) ); /* Q6 -> Q0 */ } - FOR (i = 0; i < L/2; i++) + FOR( i = 0; i < L / 2; i++ ) { - ImdctOutWin_fx[i+3*L/2] = extract_l( L_shr( L_negate(ImdctOut_fx[i]), 6 ) ); + /*OldauOut[i+N_ZERO_O_NB] = -OldImdctOut[i];*/ + OldauOut_fx[i + N_ZERO_O_NB] = extract_l( L_shr( L_negate( OldImdctOut_fx[i] ), 6 ) ); /* Q6 -> Q0 */ } - /*a = (float)(1./(float)(ol_size)); y = ax */ - Smoothing_vector_scaledown_NB_fx(OldauOut_fx, &ImdctOutWin_fx[N_Z_L_O_NB], SmoothingWin_NB875_fx, OldauOut_fx, ol_size); + /* Overlapping with next good frame : Overlapping to remove the discontinuity */ + IF( cur_data_use_flag ) + { + ol_size = N_LEAD_NB; + move16(); - /* Scale down the overlapped signal */ - Scaledown_fx(&ImdctOutWin_fx[ol_size+N_Z_L_O_NB], &OldauOut_fx[ol_size], 23170, N_Z_L_NB-ol_size); - } + FOR( i = N_ZERO_NB; i < L / 2; i++ ) + { + /* ImdctOutWin[i+L] = -ImdctOut[L/2 - 1 - i]; */ + ImdctOutWin_fx[i + L] = extract_l( L_shr( L_negate( ImdctOut_fx[L / 2 - 1 - i] ), 6 ) ); + } + FOR( i = 0; i < L / 2; i++ ) + { + ImdctOutWin_fx[i + 3 * L / 2] = extract_l( L_shr( L_negate( ImdctOut_fx[i] ), 6 ) ); + } - L_overlap = overlap_time; - move16(); - FOR (i = 0; i < L_overlap; i++) - { - /*OldauOut[i] *= SmoothingWin_NB875[L_overlap-i-1];*/ - OldauOut_fx[i] = mult(OldauOut_fx[i], SmoothingWin_NB875_fx[L_overlap-i-1]); - move16(); - } - FOR (i=L_overlap; i < L; i++) - { - OldauOut_fx[i] = 0; - move16(); - } + /*a = (float)(1./(float)(ol_size)); y = ax */ + Smoothing_vector_scaledown_NB_fx( OldauOut_fx, &ImdctOutWin_fx[N_Z_L_O_NB], SmoothingWin_NB875_fx, OldauOut_fx, ol_size ); - /* Windowing */ - /*Windowing_1st_NB(ImdctOutWin, ImdctOut, win_NB, SmoothingWin_NB875, 1);*/ - /*Windowing_2nd_NB(ImdctOutWin, ImdctOut, win_NB);*/ - Windowing_1st_NB_fx(ImdctOutWin_fx, ImdctOut_fx, win_NB_fx, SmoothingWin_NB875_fx, 1); - Windowing_2nd_NB_fx(ImdctOutWin_fx, ImdctOut_fx, win_NB_fx); + /* Scale down the overlapped signal */ + Scaledown_fx( &ImdctOutWin_fx[ol_size + N_Z_L_O_NB], &OldauOut_fx[ol_size], 23170, N_Z_L_NB - ol_size ); + } - /*v_add(&ImdctOutWin[N_ZERO_NB], OldauOut, auOut, L);*/ - /*mvr2r(&ImdctOutWin[L], OldauOut, L);*/ - FOR (i = 0; i < L; i++) - { + L_overlap = overlap_time; + move16(); + FOR( i = 0; i < L_overlap; i++ ) + { + /*OldauOut[i] *= SmoothingWin_NB875[L_overlap-i-1];*/ + OldauOut_fx[i] = mult( OldauOut_fx[i], SmoothingWin_NB875_fx[L_overlap - i - 1] ); + move16(); + } + FOR( i = L_overlap; i < L; i++ ) + { + OldauOut_fx[i] = 0; + move16(); + } + + /* Windowing */ + /*Windowing_1st_NB(ImdctOutWin, ImdctOut, win_NB, SmoothingWin_NB875, 1);*/ + /*Windowing_2nd_NB(ImdctOutWin, ImdctOut, win_NB);*/ + Windowing_1st_NB_fx( ImdctOutWin_fx, ImdctOut_fx, win_NB_fx, SmoothingWin_NB875_fx, 1 ); + Windowing_2nd_NB_fx( ImdctOutWin_fx, ImdctOut_fx, win_NB_fx ); + + /*v_add(&ImdctOutWin[N_ZERO_NB], OldauOut, auOut, L);*/ + /*mvr2r(&ImdctOutWin[L], OldauOut, L);*/ + FOR( i = 0; i < L; i++ ) + { #ifdef BASOP_NOGLOB - auOut_fx[i] = add_sat( ImdctOutWin_fx[N_ZERO_NB + i], OldauOut_fx[i] ); + auOut_fx[i] = add_sat( ImdctOutWin_fx[N_ZERO_NB + i], OldauOut_fx[i] ); #else - auOut_fx[i] = add(ImdctOutWin_fx[N_ZERO_NB + i], OldauOut_fx[i]); + auOut_fx[i] = add( ImdctOutWin_fx[N_ZERO_NB + i], OldauOut_fx[i] ); #endif - move16(); - } - Copy(&ImdctOutWin_fx[L], OldauOut_fx, L); - - return; -} + move16(); + } + Copy( &ImdctOutWin_fx[L], OldauOut_fx, L ); -static Word16 Repetition_smoothing_fx( - const Word32 *ImdctOut_fx, /* i : input */ - Word16 *auOut_fx, /* o : output audio */ - Word32 *OldImdctOut_fx, /* i : input */ - Word16 *OldauOut_fx, /* i/o: audio from previous frame */ - const Word16 L, /* i : length */ - Word16 *prev_oldauOut_fx, /* i : OldauOut from previous frame */ - Word16 overlap_time /* i : overlap time */ -) -{ - Word16 i; - Word32 pow1_fx; - Word32 pow22_fx; - Word16 ImdctOutWin_fx[2*L_FRAME8k]; - Word16 OldauOutnoWin_fx[L_FRAME8k]; - Word16 win_NB_fx[L_FRAME8k + 25]; + return; + } - FOR (i=0; i L_add(pow1_fx, L_shl(pow1_fx, 1))) - { - return 1; - } - /* Update the OldauOut array for next overlapping */ - Copy(&ImdctOutWin_fx[L], OldauOut_fx, L); - Scaledown_fx(prev_oldauOut_fx, prev_oldauOut_fx, 23170, L); + IF( pow22_fx > L_add( pow1_fx, L_shl( pow1_fx, 1 ) ) ) + { + return 1; + } - return 0; -} + /* Update the OldauOut array for next overlapping */ + Copy( &ImdctOutWin_fx[L], OldauOut_fx, L ); + Scaledown_fx( prev_oldauOut_fx, prev_oldauOut_fx, 23170, L ); -static void common_overlapping_fx( - Word16 *auOut_fx, /* i : Input */ - Word16 *ImdctOutWin_fx, /* o : Output */ - Word16 *OldauOut_fx, /* i : Window */ - Word16 end1, /* i : Decay */ - Word16 offset1, - Word16 start2, - Word16 end2, - Word16 offset_i2, - Word16 offset2 -) -{ - Word16 i; + return 0; + } - /* Common Overlapping */ - FOR (i=0 ; i < end1; i++) + static void common_overlapping_fx( + Word16 * auOut_fx, /* i : Input */ + Word16 * ImdctOutWin_fx, /* o : Output */ + Word16 * OldauOut_fx, /* i : Window */ + Word16 end1, /* i : Decay */ + Word16 offset1, + Word16 start2, + Word16 end2, + Word16 offset_i2, + Word16 offset2 ) { - /*auOut_fx[i] = L_add(ImdctOutWin_fx[i+7*L/20], OldauOut_fx[i+offset1]);*/ + Word16 i; + + /* Common Overlapping */ + FOR( i = 0; i < end1; i++ ) + { + /*auOut_fx[i] = L_add(ImdctOutWin_fx[i+7*L/20], OldauOut_fx[i+offset1]);*/ #ifdef BASOP_NOGLOB - auOut_fx[i] = add_sat( ImdctOutWin_fx[i + N_ZERO_NB], OldauOut_fx[i + offset1] ); + auOut_fx[i] = add_sat( ImdctOutWin_fx[i + N_ZERO_NB], OldauOut_fx[i + offset1] ); #else - auOut_fx[i] = add(ImdctOutWin_fx[i+N_ZERO_NB], OldauOut_fx[i+offset1]); + auOut_fx[i] = add( ImdctOutWin_fx[i + N_ZERO_NB], OldauOut_fx[i + offset1] ); #endif - move16(); - } - FOR (i=start2 ; i < end2; i++) - { - /*auOut_fx[i+offset2] = ImdctOutWin_fx[i+offset_i2]; move32();*/ - auOut_fx[i+offset2] = ImdctOutWin_fx[i+offset_i2]; - move16(); - } - - return; -} + move16(); + } + FOR( i = start2; i < end2; i++ ) + { + /*auOut_fx[i+offset2] = ImdctOutWin_fx[i+offset_i2]; move32();*/ + auOut_fx[i + offset2] = ImdctOutWin_fx[i + offset_i2]; + move16(); + } + return; + } -static void Smoothing_vector_NB_fx( - const Word16 OldauOutnoWin_fx[], /* i : Input vector 1 */ - const Word16 ImdctOutWin_fx[], /* i : Input vector 2 */ - const Word16 SmoothingWin_fx[], /* i : Smoothing window */ - Word16 auOut_fx[], /* o : Output vector that contains vector 1 .* vector 2 */ - const Word16 ol_size /* i : Overlap size */ -) -{ - Word16 i; - Word16 weight_fx; - FOR (i=0 ; i < ol_size; i++) + static void Smoothing_vector_NB_fx( + const Word16 OldauOutnoWin_fx[], /* i : Input vector 1 */ + const Word16 ImdctOutWin_fx[], /* i : Input vector 2 */ + const Word16 SmoothingWin_fx[], /* i : Smoothing window */ + Word16 auOut_fx[], /* o : Output vector that contains vector 1 .* vector 2 */ + const Word16 ol_size /* i : Overlap size */ + ) { - weight_fx = SmoothingWin_fx[i]; - move16(); - auOut_fx[i] = add(mult(OldauOutnoWin_fx[i], sub(32767, weight_fx)), mult(ImdctOutWin_fx[i], weight_fx)); - move16(); - } + Word16 i; + Word16 weight_fx; - return; -} + FOR( i = 0; i < ol_size; i++ ) + { + weight_fx = SmoothingWin_fx[i]; + move16(); + auOut_fx[i] = add( mult( OldauOutnoWin_fx[i], sub( 32767, weight_fx ) ), mult( ImdctOutWin_fx[i], weight_fx ) ); + move16(); + } + return; + } -static void Windowing_1st_NB_fx( - Word16 *ImdctOutWin_fx, /* o : Output */ - const Word32 *ImdctOut_fx, /* i : Input */ - const Word16 *win_fx, /* i : Window */ - const Word16 *smoothingWin_fx, /* i : Smoothing Window */ - Word16 smoothing_flag /* i : 1=Smoothing window, 0=Original window */ -) -{ - Word16 i; - Word16 L; - L = L_FRAME8k; - move16(); - IF ( smoothing_flag == 0 ) + static void Windowing_1st_NB_fx( + Word16 * ImdctOutWin_fx, /* o : Output */ + const Word32 *ImdctOut_fx, /* i : Input */ + const Word16 *win_fx, /* i : Window */ + const Word16 *smoothingWin_fx, /* i : Smoothing Window */ + Word16 smoothing_flag /* i : 1=Smoothing window, 0=Original window */ + ) { - FOR (i = N_ZERO_NB; i < L/2; i++) + Word16 i; + Word16 L; + + L = L_FRAME8k; + move16(); + IF( smoothing_flag == 0 ) { - /*ImdctOutWin[i] = ImdctOut[L/2 + i] * win[(2*L-1-i)-N_LEAD_O_NB];*/ - ImdctOutWin_fx[i] = extract_l( L_shr( Mult_32_16(ImdctOut_fx[L/2 + i], win_fx[(2*L-1-i)-N_LEAD_O_NB]), 6 )); - } + FOR( i = N_ZERO_NB; i < L / 2; i++ ) + { + /*ImdctOutWin[i] = ImdctOut[L/2 + i] * win[(2*L-1-i)-N_LEAD_O_NB];*/ + ImdctOutWin_fx[i] = extract_l( L_shr( Mult_32_16( ImdctOut_fx[L / 2 + i], win_fx[( 2 * L - 1 - i ) - N_LEAD_O_NB] ), 6 ) ); + } - FOR (i = 0; i < N_ZERO_O_NB; i++) + FOR( i = 0; i < N_ZERO_O_NB; i++ ) + { + /*ImdctOutWin[L/2 + i] = -ImdctOut[L - 1 - i] * win[(3*L/2-1-i)-N_LEAD_O_NB];*/ + /*ImdctOutWin[3*L/2 + i] = -ImdctOut[i] * win[(L/2-i-1)];*/ + ImdctOutWin_fx[L / 2 + i] = extract_l( L_shr( Mult_32_16( L_negate( ImdctOut_fx[L - 1 - i] ), win_fx[( 3 * L / 2 - 1 - i ) - N_LEAD_O_NB] ), 6 ) ); + ImdctOutWin_fx[3 * L / 2 + i] = extract_l( L_shr( Mult_32_16( L_negate( ImdctOut_fx[i] ), win_fx[( L / 2 - i - 1 )] ), 6 ) ); + } + } + ELSE { - /*ImdctOutWin[L/2 + i] = -ImdctOut[L - 1 - i] * win[(3*L/2-1-i)-N_LEAD_O_NB];*/ - /*ImdctOutWin[3*L/2 + i] = -ImdctOut[i] * win[(L/2-i-1)];*/ - ImdctOutWin_fx[L/2 + i] = extract_l( L_shr( Mult_32_16(L_negate(ImdctOut_fx[L - 1 - i]), win_fx[(3*L/2-1-i)-N_LEAD_O_NB]), 6 )); - ImdctOutWin_fx[3*L/2 + i] = extract_l( L_shr( Mult_32_16(L_negate(ImdctOut_fx[i]), win_fx[(L/2-i-1)]), 6 )); + FOR( i = N_ZERO_NB; i < L / 2; i++ ) + { + /*ImdctOutWin[i] = ImdctOut[L/2 + i] * smoothingWin[(i-N_ZERO_NB)];*/ /*win[(2*L-i)*decimate-1-decay-14*L_FRAME48k/20];*/ + ImdctOutWin_fx[i] = extract_l( L_shr( Mult_32_16( ImdctOut_fx[L / 2 + i], smoothingWin_fx[( i - N_ZERO_NB )] ), 6 ) ); /*win[(2*L-i)*decimate-1-decay-14*L_FRAME48k/20];*/ + } + + FOR( i = 0; i < N_ZERO_O_NB; i++ ) + { + /*ImdctOutWin[L/2 + i] = -ImdctOut[L - 1 - i] * smoothingWin[(i+N_ZERO_O_NB)];*/ /*win[(3*L/2-1-i)*decimate+decay-L_FRAME48k*14/20];*/ + /*ImdctOutWin[3*L/2 + i] = -ImdctOut[i] * win[(L/2-i-1)];*/ + ImdctOutWin_fx[L / 2 + i] = extract_l( L_shr( Mult_32_16( L_negate( ImdctOut_fx[L - 1 - i] ), smoothingWin_fx[( i + N_ZERO_O_NB )] ), 6 ) ); /*win[(3*L/2-1-i)*decimate+decay-L_FRAME48k*14/20];*/ + ImdctOutWin_fx[3 * L / 2 + i] = extract_l( L_shr( Mult_32_16( L_negate( ImdctOut_fx[i] ), win_fx[( L / 2 - i - 1 )] ), 6 ) ); + } } + + return; } - ELSE + static void Windowing_2nd_NB_fx( + Word16 * ImdctOutWin_fx, /* o : Output */ + const Word32 *ImdctOut_fx, /* i : Input */ + const Word16 *win_fx /* i : Window */ + ) { - FOR (i = N_ZERO_NB; i < L/2; i++) + Word16 i; + Word16 L; + + L = L_FRAME8k; + move16(); + FOR( i = N_ZERO_O_NB; i < L / 2; i++ ) { - /*ImdctOutWin[i] = ImdctOut[L/2 + i] * smoothingWin[(i-N_ZERO_NB)];*/ /*win[(2*L-i)*decimate-1-decay-14*L_FRAME48k/20];*/ - ImdctOutWin_fx[i] = extract_l( L_shr( Mult_32_16(ImdctOut_fx[L/2 + i], smoothingWin_fx[(i-N_ZERO_NB)]), 6 )); /*win[(2*L-i)*decimate-1-decay-14*L_FRAME48k/20];*/ + /*ImdctOutWin[L/2 + i] = -ImdctOut[L - 1 - i];*/ + /*ImdctOutWin[3*L/2 + i] = -ImdctOut[i] * win[L/2-i-1];*/ + ImdctOutWin_fx[L / 2 + i] = extract_l( L_shr( L_negate( ImdctOut_fx[L - 1 - i] ), 6 ) ); + ImdctOutWin_fx[3 * L / 2 + i] = extract_l( L_shr( Mult_32_16( L_negate( ImdctOut_fx[i] ), win_fx[L / 2 - i - 1] ), 6 ) ); } - FOR (i = 0; i < N_ZERO_O_NB; i++) + FOR( i = 0; i < N_ZERO_NB; i++ ) { - /*ImdctOutWin[L/2 + i] = -ImdctOut[L - 1 - i] * smoothingWin[(i+N_ZERO_O_NB)];*/ /*win[(3*L/2-1-i)*decimate+decay-L_FRAME48k*14/20];*/ - /*ImdctOutWin[3*L/2 + i] = -ImdctOut[i] * win[(L/2-i-1)];*/ - ImdctOutWin_fx[L/2 + i] = extract_l( L_shr( Mult_32_16(L_negate(ImdctOut_fx[L - 1 - i]), smoothingWin_fx[(i+N_ZERO_O_NB)]), 6 )); /*win[(3*L/2-1-i)*decimate+decay-L_FRAME48k*14/20];*/ - ImdctOutWin_fx[3*L/2 + i] = extract_l( L_shr( Mult_32_16(L_negate(ImdctOut_fx[i]), win_fx[(L/2-i-1)]), 6 )); + /*ImdctOutWin[L + i] = -ImdctOut[L/2 - 1 - i];*/ + ImdctOutWin_fx[L + i] = extract_l( L_shr( L_negate( ImdctOut_fx[L / 2 - 1 - i] ), 6 ) ); } - } - return; -} -static void Windowing_2nd_NB_fx( - Word16 *ImdctOutWin_fx, /* o : Output */ - const Word32 *ImdctOut_fx, /* i : Input */ - const Word16 *win_fx /* i : Window */ -) -{ - Word16 i; - Word16 L; + FOR( i = N_ZERO_NB; i < L / 2; i++ ) + { + /*ImdctOutWin[L + i] = -ImdctOut[L/2 - 1 - i] * win[L - 1 - i];*/ + ImdctOutWin_fx[L + i] = extract_l( L_shr( Mult_32_16( L_negate( ImdctOut_fx[L / 2 - 1 - i] ), win_fx[L - 1 - i] ), 6 ) ); + } - L = L_FRAME8k; - move16(); - FOR (i = N_ZERO_O_NB; i < L/2; i++) - { - /*ImdctOutWin[L/2 + i] = -ImdctOut[L - 1 - i];*/ - /*ImdctOutWin[3*L/2 + i] = -ImdctOut[i] * win[L/2-i-1];*/ - ImdctOutWin_fx[L/2 + i] = extract_l( L_shr( L_negate(ImdctOut_fx[L - 1 - i]), 6 )); - ImdctOutWin_fx[3*L/2 + i] = extract_l( L_shr( Mult_32_16(L_negate(ImdctOut_fx[i]), win_fx[L/2-i-1]), 6 )); + return; } - FOR (i = 0; i < N_ZERO_NB; i++) - { - /*ImdctOutWin[L + i] = -ImdctOut[L/2 - 1 - i];*/ - ImdctOutWin_fx[L + i] = extract_l( L_shr( L_negate(ImdctOut_fx[L/2 - 1 - i]), 6 )); - } + static void Smoothing_vector_scaledown_NB_fx( + const Word16 OldauOutnoWin_fx[], /* i : Input vector 1 */ + const Word16 ImdctOutWin_fx[], /* i : Input vector 2 */ + const Word16 SmoothingWin_fx[], /* i : Smoothing window */ + Word16 auOut_fx[], /* o : Output vector that contains vector 1 .* vector 2 */ + const Word16 ol_size /* i : Overlap size */ - FOR (i = N_ZERO_NB; i < L/2; i++) + ) { - /*ImdctOutWin[L + i] = -ImdctOut[L/2 - 1 - i] * win[L - 1 - i];*/ - ImdctOutWin_fx[L + i] = extract_l( L_shr( Mult_32_16(L_negate(ImdctOut_fx[L/2 - 1 - i]), win_fx[L - 1 - i]), 6 )); - } - - return; -} + Word16 i; + Word16 weight_fx; -static void Smoothing_vector_scaledown_NB_fx( - const Word16 OldauOutnoWin_fx[], /* i : Input vector 1 */ - const Word16 ImdctOutWin_fx[], /* i : Input vector 2 */ - const Word16 SmoothingWin_fx[], /* i : Smoothing window */ - Word16 auOut_fx[], /* o : Output vector that contains vector 1 .* vector 2 */ - const Word16 ol_size /* i : Overlap size */ - -) -{ - Word16 i; - Word16 weight_fx; + FOR( i = 0; i < ol_size; i++ ) + { + weight_fx = SmoothingWin_fx[i]; + move16(); + auOut_fx[i] = add( mult( OldauOutnoWin_fx[i], sub( 32767, weight_fx ) ), + mult( ImdctOutWin_fx[i], mult_r( 23170, weight_fx ) ) ); + move16(); + } - FOR (i=0 ; i < ol_size; i++) - { - weight_fx = SmoothingWin_fx[i]; - move16(); - auOut_fx[i] = add(mult(OldauOutnoWin_fx[i], sub(32767, weight_fx)), - mult(ImdctOutWin_fx[i], mult_r(23170, weight_fx))); - move16(); + return; } - return; -} - - -static void Scaledown_fx( - Word16 x[], /* i : Input vector */ - Word16 y[], /* o : Output vector that contains vector 1 .* vector 2 */ - Word16 scale_v, /*Q15 */ - const Word16 N /* i : Overlap size */ -) -{ - Word16 i; - FOR (i=0; ihHQ_nbfec; - hHQ_core = st_fx->hHQ_core; + FOR( i = 0; i < N; i++ ) + { + y[i] = mult( x[i], scale_v ); + move16(); + } - IF(hHQ_core->Q_old_wtda != 0) - { - Scale_sig(hHQ_core->old_out_fx, output_frame, negate(hHQ_core->Q_old_wtda)); - hHQ_core->Q_old_wtda = 0; - move16(); + return; } - test(); - test(); - test(); - test(); - test(); - test(); - IF( (EQ_16(st_fx->nbLostCmpt, 1))&&(EQ_16(hHQ_nbfec->phase_mat_flag,1))&&(EQ_16(hHQ_nbfec->phase_mat_next,0))) + void time_domain_FEC_HQ_fx( + Decoder_State * st_fx, /* i : Decoder State */ + Word32 * wtda_audio_fx, /* i : input */ + Word16 * out_fx, /* o : output audio */ + Word16 mean_en_high_fx, /* i : transient flag */ + const Word16 output_frame, + Word16 *Q_synth ) { - IF (FEC_phase_matching_fx(hHQ_nbfec, wtda_audio_fx, out_fx, hHQ_core->old_out_fx, hHQ_nbfec->old_out_pha_fx) ) - { - /* window_ola( wtda_audio, out, st->old_out, output_frame, 0, 0, 0 ); */ - window_ola_fx(wtda_audio_fx, out_fx, Q_synth, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, output_frame, ALDO_WINDOW, ALDO_WINDOW, 0, 0, 0 ); - hHQ_nbfec->phase_mat_next = 0; - move16(); - } - ELSE + HQ_NBFEC_HANDLE hHQ_nbfec; + HQ_DEC_HANDLE hHQ_core; + hHQ_nbfec = st_fx->hHQ_nbfec; + hHQ_core = st_fx->hHQ_core; + + IF( hHQ_core->Q_old_wtda != 0 ) { - hHQ_nbfec->phase_mat_next = 1; - move16(); - *Q_synth = 0; + Scale_sig( hHQ_core->old_out_fx, output_frame, negate( hHQ_core->Q_old_wtda ) ); + hHQ_core->Q_old_wtda = 0; move16(); } - } - ELSE IF((EQ_16(st_fx->prev_bfi, 1))&&(st_fx->bfi==0)&&(EQ_16(hHQ_nbfec->phase_mat_next,1))) - { - FEC_phase_matching_nextgood_fx( wtda_audio_fx, out_fx, hHQ_core->old_out_fx, hHQ_nbfec->old_out_pha_fx, mean_en_high_fx); - hHQ_nbfec->phase_mat_next = 0; - move16(); - *Q_synth = 0; - move16(); - } - ELSE IF((EQ_16(st_fx->prev_bfi, 1))&&(EQ_16(st_fx->bfi,1))&&(EQ_16(hHQ_nbfec->phase_mat_next,1))) - { - FEC_phase_matching_burst_fx( wtda_audio_fx, out_fx, hHQ_core->old_out_fx, hHQ_nbfec->old_out_pha_fx, hHQ_nbfec->prev_oldauOut_fx); - hHQ_nbfec->phase_mat_next = 1; - move16(); - *Q_synth = 0; - move16(); - } - ELSE - { - /*n4 = (short)(N_LEAD_MDCT*(float)(output_frame/20));*/ test(); - IF (st_fx->bfi == 0 && EQ_16(st_fx->prev_bfi, 1)) + test(); + test(); + test(); + test(); + test(); + IF( ( EQ_16( st_fx->nbLostCmpt, 1 ) ) && ( EQ_16( hHQ_nbfec->phase_mat_flag, 1 ) ) && ( EQ_16( hHQ_nbfec->phase_mat_next, 0 ) ) ) { - test(); - IF((EQ_16(hHQ_nbfec->stat_mode_out, 1))||(LT_16(hHQ_nbfec->diff_energy_fx,ED_THRES_50P_fx)))/* Q11 */ + IF( FEC_phase_matching_fx( hHQ_nbfec, wtda_audio_fx, out_fx, hHQ_core->old_out_fx, hHQ_nbfec->old_out_pha_fx ) ) { - Word16 tmp; - - tmp = 0; - if( GT_16(st_fx->old_bfi_cnt,1)) - { - tmp = 1; - } - Repetition_smoothing_nextgood_fx( wtda_audio_fx, out_fx, hHQ_nbfec->oldIMDCTout_fx, hHQ_core->old_out_fx, tmp, N_LEAD_NB); - *Q_synth = 0; + /* window_ola( wtda_audio, out, st->old_out, output_frame, 0, 0, 0 ); */ + window_ola_fx( wtda_audio_fx, out_fx, Q_synth, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, output_frame, ALDO_WINDOW, ALDO_WINDOW, 0, 0, 0 ); + hHQ_nbfec->phase_mat_next = 0; move16(); } - ELSE IF(GT_16(st_fx->old_bfi_cnt, 1)) + ELSE { - Next_good_after_burst_erasures_fx( wtda_audio_fx, out_fx, hHQ_core->old_out_fx, N_LEAD_NB ); + hHQ_nbfec->phase_mat_next = 1; + move16(); *Q_synth = 0; move16(); } - ELSE - { - /*window_ola( wtda_audio, out, st->old_out, output_frame, 0, 0, 0); */ - window_ola_fx( wtda_audio_fx, out_fx, Q_synth, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, output_frame, - st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, st_fx->prev_bfi, hHQ_core->oldHqVoicing , hHQ_core->oldgapsynth_fx ); - } } - ELSE /* if(st->bfi == 1) */ + ELSE IF( ( EQ_16( st_fx->prev_bfi, 1 ) ) && ( st_fx->bfi == 0 ) && ( EQ_16( hHQ_nbfec->phase_mat_next, 1 ) ) ) { + FEC_phase_matching_nextgood_fx( wtda_audio_fx, out_fx, hHQ_core->old_out_fx, hHQ_nbfec->old_out_pha_fx, mean_en_high_fx ); + + hHQ_nbfec->phase_mat_next = 0; + move16(); + *Q_synth = 0; + move16(); + } + ELSE IF( ( EQ_16( st_fx->prev_bfi, 1 ) ) && ( EQ_16( st_fx->bfi, 1 ) ) && ( EQ_16( hHQ_nbfec->phase_mat_next, 1 ) ) ) + { + FEC_phase_matching_burst_fx( wtda_audio_fx, out_fx, hHQ_core->old_out_fx, hHQ_nbfec->old_out_pha_fx, hHQ_nbfec->prev_oldauOut_fx ); + hHQ_nbfec->phase_mat_next = 1; + move16(); + *Q_synth = 0; + move16(); + } + ELSE + { + /*n4 = (short)(N_LEAD_MDCT*(float)(output_frame/20));*/ test(); - IF( (EQ_16(hHQ_nbfec->stat_mode_out, 1))||(LT_16(hHQ_nbfec->diff_energy_fx,ED_THRES_50P_fx))) + IF( st_fx->bfi == 0 && EQ_16( st_fx->prev_bfi, 1 ) ) { - /* if( window_ola_bfi( wtda_audio, out, st->oldIMDCTout, st->old_out, output_frame, st->prev_oldauOut, N_LEAD_NB) ) */ - IF( Repetition_smoothing_fx( wtda_audio_fx, out_fx, hHQ_nbfec->oldIMDCTout_fx, hHQ_core->old_out_fx, output_frame, hHQ_nbfec->prev_oldauOut_fx, N_LEAD_NB) ) + test(); + IF( ( EQ_16( hHQ_nbfec->stat_mode_out, 1 ) ) || ( LT_16( hHQ_nbfec->diff_energy_fx, ED_THRES_50P_fx ) ) ) /* Q11 */ { - /*window_ola( wtda_audio, out, st->old_out, output_frame, 0, 0, 0);*/ - window_ola_fx( wtda_audio_fx, out_fx, Q_synth, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, output_frame, - st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, st_fx->prev_bfi, hHQ_core->oldHqVoicing , hHQ_core->oldgapsynth_fx ); + Word16 tmp; + + tmp = 0; + if ( GT_16( st_fx->old_bfi_cnt, 1 ) ) + { + tmp = 1; + } + Repetition_smoothing_nextgood_fx( wtda_audio_fx, out_fx, hHQ_nbfec->oldIMDCTout_fx, hHQ_core->old_out_fx, tmp, N_LEAD_NB ); + *Q_synth = 0; + move16(); } - ELSE + ELSE IF( GT_16( st_fx->old_bfi_cnt, 1 ) ) { + Next_good_after_burst_erasures_fx( wtda_audio_fx, out_fx, hHQ_core->old_out_fx, N_LEAD_NB ); *Q_synth = 0; move16(); } + ELSE + { + /*window_ola( wtda_audio, out, st->old_out, output_frame, 0, 0, 0); */ + window_ola_fx( wtda_audio_fx, out_fx, Q_synth, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, output_frame, + st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, st_fx->prev_bfi, hHQ_core->oldHqVoicing, hHQ_core->oldgapsynth_fx ); + } } - ELSE + ELSE /* if(st->bfi == 1) */ { - /*window_ola( wtda_audio, out, st->old_out, output_frame, 0, 0, 0 );*/ - window_ola_fx( wtda_audio_fx, out_fx, Q_synth, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, output_frame, - st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, st_fx->prev_bfi, hHQ_core->oldHqVoicing , hHQ_core->oldgapsynth_fx ); + test(); + IF( ( EQ_16( hHQ_nbfec->stat_mode_out, 1 ) ) || ( LT_16( hHQ_nbfec->diff_energy_fx, ED_THRES_50P_fx ) ) ) + { + /* if( window_ola_bfi( wtda_audio, out, st->oldIMDCTout, st->old_out, output_frame, st->prev_oldauOut, N_LEAD_NB) ) */ + IF( Repetition_smoothing_fx( wtda_audio_fx, out_fx, hHQ_nbfec->oldIMDCTout_fx, hHQ_core->old_out_fx, output_frame, hHQ_nbfec->prev_oldauOut_fx, N_LEAD_NB ) ) + { + /*window_ola( wtda_audio, out, st->old_out, output_frame, 0, 0, 0);*/ + window_ola_fx( wtda_audio_fx, out_fx, Q_synth, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, output_frame, + st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, st_fx->prev_bfi, hHQ_core->oldHqVoicing, hHQ_core->oldgapsynth_fx ); + } + ELSE + { + *Q_synth = 0; + move16(); + } + } + ELSE + { + /*window_ola( wtda_audio, out, st->old_out, output_frame, 0, 0, 0 );*/ + window_ola_fx( wtda_audio_fx, out_fx, Q_synth, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, output_frame, + st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, st_fx->prev_bfi, hHQ_core->oldHqVoicing, hHQ_core->oldgapsynth_fx ); + } } + hHQ_nbfec->phase_mat_next = 0; + move16(); } - hHQ_nbfec->phase_mat_next = 0; - move16(); - } - return; -} - -static void Next_good_after_burst_erasures_fx( - const Word32 *ImdctOut_fx, - Word16 *auOut_fx, - Word16 *OldauOut_fx, - const Word16 ol_size -) -{ - Word16 i, L; - Word16 ImdctOutWin_fx[2*L_FRAME48k]; - Word16 win_NB_fx[L_FRAME8k + 25]; + return; + } - L = L_FRAME8k; - move16(); - FOR (i=0; ielement_mode) - { - case EVS_MONO: - post_hq_delay = NS2SA(st->output_Fs, POST_HQ_DELAY_NS); - break; - case IVAS_SCE: - post_hq_delay = NS2SA(st->output_Fs, DELAY_CLDFB_NS); - break; - case IVAS_CPE_DFT: - if (hCPE->nchan_out == 1 && hCPE->hStereoDft->hConfig->res_cod_mode == STEREO_DFT_RES_COD_OFF) - { - post_hq_delay = NS2SA(st->output_Fs, DELAY_CLDFB_NS); - } - else + /*-------------------------------------------------------------------------- + * save_synthesis_hq_fec() + * + * Save synthesis for HQ FEC + *-------------------------------------------------------------------------*/ + + void save_synthesis_hq_fec( + Decoder_State * st, /* i/o: decoder state structure */ + const float *output, /* i : decoded synthesis */ + const int16_t output_frame, /* i : decoded synthesis */ + CPE_DEC_HANDLE hCPE /* i : CPE decoder structure */ + ) + { + int16_t post_hq_delay; + + switch ( st->element_mode ) { - post_hq_delay = 0; + case EVS_MONO: + post_hq_delay = NS2SA( st->output_Fs, POST_HQ_DELAY_NS ); + break; + case IVAS_SCE: + post_hq_delay = NS2SA( st->output_Fs, DELAY_CLDFB_NS ); + break; + case IVAS_CPE_DFT: + if ( hCPE->nchan_out == 1 && hCPE->hStereoDft->hConfig->res_cod_mode == STEREO_DFT_RES_COD_OFF ) + { + post_hq_delay = NS2SA( st->output_Fs, DELAY_CLDFB_NS ); + } + else + { + post_hq_delay = 0; + } + break; + default: + post_hq_delay = 0; + break; } - break; - default: - post_hq_delay = 0; - break; - } - - if ((st->codec_mode == MODE1 && st->hTcxDec != NULL) && ((st->core == ACELP_CORE && !(st->bfi == 1 && st->con_tcx == 1)) || st->core == HQ_CORE)) - { - mvr2r(st->hTcxDec->synth_history + output_frame, st->hTcxDec->synth_history, output_frame - post_hq_delay + NS2SA(st->output_Fs, PH_ECU_MEM_NS)); - mvr2r(output, st->hTcxDec->old_synthFB + output_frame - post_hq_delay, output_frame); - if (st->element_mode == EVS_MONO) + if ( ( st->codec_mode == MODE1 && st->hTcxDec != NULL ) && ( ( st->core == ACELP_CORE && !( st->bfi == 1 && st->con_tcx == 1 ) ) || st->core == HQ_CORE ) ) { - /* reset the remaining buffer, which is read in TCX concealment the necessary samples to fill - this buffer are not available for all cases, the impact on the output is limited */ - set_f(st->hTcxDec->old_synthFB + 2 * output_frame - post_hq_delay, 0.f, post_hq_delay); - if (output_frame >= L_FRAME16k) - { - mvr2r(st->prev_synth_buffer, st->hTcxDec->old_synthFB + 2 * output_frame - NS2SA(st->output_Fs, DELAY_BWE_TOTAL_NS), NS2SA(st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS)); - } - else - { - mvr2r(st->hHQ_core->old_out + NS2SA(st->output_Fs, N_ZERO_MDCT_NS), st->hTcxDec->old_synthFB + 2 * output_frame, NS2SA(st->output_Fs, PH_ECU_LOOKAHEAD_NS)); - } + mvr2r( st->hTcxDec->synth_history + output_frame, st->hTcxDec->synth_history, output_frame - post_hq_delay + NS2SA( st->output_Fs, PH_ECU_MEM_NS ) ); + mvr2r( output, st->hTcxDec->old_synthFB + output_frame - post_hq_delay, output_frame ); - if (st->core != ACELP_CORE) + if ( st->element_mode == EVS_MONO ) { - if (output_frame >= L_FRAME16k) + /* reset the remaining buffer, which is read in TCX concealment the necessary samples to fill + this buffer are not available for all cases, the impact on the output is limited */ + set_f( st->hTcxDec->old_synthFB + 2 * output_frame - post_hq_delay, 0.f, post_hq_delay ); + if ( output_frame >= L_FRAME16k ) { - mvr2r(st->delay_buf_out, st->hTcxDec->old_synthFB + 2 * output_frame - NS2SA(st->output_Fs, DELAY_CLDFB_NS), NS2SA(st->output_Fs, DELAY_CLDFB_NS)); - mvr2r(st->hHQ_core->old_out + NS2SA(st->output_Fs, N_ZERO_MDCT_NS), st->hTcxDec->old_synthFB + 2 * output_frame, NS2SA(st->output_Fs, PH_ECU_LOOKAHEAD_NS)); + mvr2r( st->prev_synth_buffer, st->hTcxDec->old_synthFB + 2 * output_frame - NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS ), NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) ); } else { - mvr2r(st->delay_buf_out, st->hTcxDec->old_synthFB + 2 * output_frame - NS2SA(st->output_Fs, DELAY_BWE_TOTAL_NS), NS2SA(st->output_Fs, DELAY_CLDFB_NS)); - mvr2r(st->hHQ_core->old_out + NS2SA(st->output_Fs, N_ZERO_MDCT_NS), st->hTcxDec->old_synthFB + 2 * output_frame - NS2SA(st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS), NS2SA(st->output_Fs, PH_ECU_LOOKAHEAD_NS)); + mvr2r( st->hHQ_core->old_out + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), st->hTcxDec->old_synthFB + 2 * output_frame, NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ); + } + + if ( st->core != ACELP_CORE ) + { + if ( output_frame >= L_FRAME16k ) + { + mvr2r( st->delay_buf_out, st->hTcxDec->old_synthFB + 2 * output_frame - NS2SA( st->output_Fs, DELAY_CLDFB_NS ), NS2SA( st->output_Fs, DELAY_CLDFB_NS ) ); + mvr2r( st->hHQ_core->old_out + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), st->hTcxDec->old_synthFB + 2 * output_frame, NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ); + } + else + { + mvr2r( st->delay_buf_out, st->hTcxDec->old_synthFB + 2 * output_frame - NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS ), NS2SA( st->output_Fs, DELAY_CLDFB_NS ) ); + mvr2r( st->hHQ_core->old_out + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), st->hTcxDec->old_synthFB + 2 * output_frame - NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ); + } } } - } - else - { - if (st->core != ACELP_CORE) + else { - mvr2r(st->delay_buf_out, st->hTcxDec->old_synthFB + 2 * output_frame - post_hq_delay, post_hq_delay); - mvr2r(st->hHQ_core->old_out + NS2SA(st->output_Fs, N_ZERO_MDCT_NS), st->hTcxDec->old_synthFB + 2 * output_frame, NS2SA(st->output_Fs, PH_ECU_LOOKAHEAD_NS)); + if ( st->core != ACELP_CORE ) + { + mvr2r( st->delay_buf_out, st->hTcxDec->old_synthFB + 2 * output_frame - post_hq_delay, post_hq_delay ); + mvr2r( st->hHQ_core->old_out + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), st->hTcxDec->old_synthFB + 2 * output_frame, NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ); + } } } - } - return; -} -#endif \ No newline at end of file + return; + } +#endif diff --git a/lib_dec/FEC_HQ_phase_ecu.c b/lib_dec/FEC_HQ_phase_ecu.c index 5c8e917b6..7d0a5f11c 100644 --- a/lib_dec/FEC_HQ_phase_ecu.c +++ b/lib_dec/FEC_HQ_phase_ecu.c @@ -2167,7 +2167,7 @@ static void hq_phase_ecu( } #endif -#ifndef IVAS_FLOAT_FIXED +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------------- * hq_ecu() * diff --git a/lib_dec/FEC_HQ_phase_ecu_fx.c b/lib_dec/FEC_HQ_phase_ecu_fx.c index 71f7860d8..bd6d018a6 100644 --- a/lib_dec/FEC_HQ_phase_ecu_fx.c +++ b/lib_dec/FEC_HQ_phase_ecu_fx.c @@ -3,7 +3,7 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ +#include "options.h" /* Compilation switches */ #include "rom_dec.h" /* Static table prototypes */ #include "rom_com.h" /* Static table prototypes */ #include "prot_fx1.h" @@ -17,36 +17,36 @@ * Local constants *---------------------------------------------------------------------*/ -#define FEC_MAX 512 -#define FEC_NB_PULSE_MAX 20 -#define FEC_FFT_MAX_SIZE 512 +#define FEC_MAX 512 +#define FEC_NB_PULSE_MAX 20 +#define FEC_FFT_MAX_SIZE 512 #define FEC_DCIM_FILT_SIZE_MAX 60 -#define ENV_STAB_DEC_THR 16384 /* Q15 st->env_stab based threshold for hq-ecu technology decision */ +#define ENV_STAB_DEC_THR 16384 /* Q15 st->env_stab based threshold for hq-ecu technology decision */ -#define PHASE_DITH_fx 25736 /* 2*pi in Q12 */ -#define DELTA_CORR 6 /* Tuning parameter - defining range for phase correction around peak */ -#define THRESH_TR_DB_FX 10 -#define THRESH_TR_LIN_BY2_FX (10/2) /* 10.0^(THRESH_TR_DB_FX/10.0)/2. Divided by 2 to facilitate fixed-point implementation. */ -#define MAX_INCREASE_GRPPOW_FX 0 /* max. amplification in case of transients (in dB scale) */ -#define MAX_INCREASE_GRPPOW_LIN_FX 32767 /* in Q15-- 10.0^(MAX_INCREASE_GRPPOW_FX/10.0) (in linear scale) */ +#define PHASE_DITH_fx 25736 /* 2*pi in Q12 */ +#define DELTA_CORR 6 /* Tuning parameter - defining range for phase correction around peak */ +#define THRESH_TR_DB_FX 10 +#define THRESH_TR_LIN_BY2_FX ( 10 / 2 ) /* 10.0^(THRESH_TR_DB_FX/10.0)/2. Divided by 2 to facilitate fixed-point implementation. */ +#define MAX_INCREASE_GRPPOW_FX 0 /* max. amplification in case of transients (in dB scale) */ +#define MAX_INCREASE_GRPPOW_LIN_FX 32767 /* in Q15-- 10.0^(MAX_INCREASE_GRPPOW_FX/10.0) (in linear scale) */ -#define PHASE_DITH_SCALE_SHIFT 16 /* The number of bit shift equivalent to multiply by PHASE_DITH_SCALE */ +#define PHASE_DITH_SCALE_SHIFT 16 /* The number of bit shift equivalent to multiply by PHASE_DITH_SCALE */ -#define BURST_PHDITH_THRESH (4-1) /* speech start phase dither with losses in a row */ -#define BURST_PHDITH_RAMPUP_LEN 2 /* speech ramp up degree of phase dither over a length of frames */ -#define BURST_ATT_THRESH (3-1) /* speech start attenuate with losses in a row */ -#define ATT_PER_FRAME 4 /* speech attenuation in dB */ -#define BETA_MUTE_THR 10 /* time threshold to start beta-noise attenuation */ +#define BURST_PHDITH_THRESH ( 4 - 1 ) /* speech start phase dither with losses in a row */ +#define BURST_PHDITH_RAMPUP_LEN 2 /* speech ramp up degree of phase dither over a length of frames */ +#define BURST_ATT_THRESH ( 3 - 1 ) /* speech start attenuate with losses in a row */ +#define ATT_PER_FRAME 4 /* speech attenuation in dB */ +#define BETA_MUTE_THR 10 /* time threshold to start beta-noise attenuation */ -#define LGW32K 7 -#define LGW16K 6 -#define LGW48K LGW32K+1 /* Use the same frequency groups as for SWB + 1 */ +#define LGW32K 7 +#define LGW16K 6 +#define LGW48K LGW32K + 1 /* Use the same frequency groups as for SWB + 1 */ -#define LTRANALOG32K 8 -#define LTRANALOG16K 7 -#define PFIND_SENS_FX 31785 /* 0.97 in Q15 */ -#define CMPLMNT_PFIND_SENS_FX 983 /* (1.0 - pfind_sen) in Q15 */ +#define LTRANALOG32K 8 +#define LTRANALOG16K 7 +#define PFIND_SENS_FX 31785 /* 0.97 in Q15 */ +#define CMPLMNT_PFIND_SENS_FX 983 /* (1.0 - pfind_sen) in Q15 */ #ifdef IVAS_FLOAT_FIXED #define DELTA_CORR_F0_INT 2 /* Constant controls the bin range where Jacobsen is used */ @@ -66,38 +66,41 @@ #endif #endif -#define FEC_HQ_ECU_POINT5 (0x4000) /* 0.5 in Q15. Prefix with FEC_HQ namespace to avoid naming conflict. */ -#define FEC_HQ_ECU_ROOT2 (0x5a83) /* sqrt(2) in Q14 */ -#define FEC_HQ_HAMM_A0 17695 /* 0.54 in Q15 */ -#define FEC_HQ_HAMM_A1 15073 /* 0.46 in Q15 */ -#define FEC_HQ_WIN_A0 FEC_HQ_HAMM_A0 -#define FEC_HQ_WIN_A1 FEC_HQ_HAMM_A1 +#define FEC_HQ_ECU_POINT5 ( 0x4000 ) /* 0.5 in Q15. Prefix with FEC_HQ namespace to avoid naming conflict. */ +#define FEC_HQ_ECU_ROOT2 ( 0x5a83 ) /* sqrt(2) in Q14 */ +#define FEC_HQ_HAMM_A0 17695 /* 0.54 in Q15 */ +#define FEC_HQ_HAMM_A1 15073 /* 0.46 in Q15 */ +#define FEC_HQ_WIN_A0 FEC_HQ_HAMM_A0 +#define FEC_HQ_WIN_A1 FEC_HQ_HAMM_A1 #ifdef IVAS_FLOAT_FIXED -static Word16 sqrt2ndOrder(const Word16); +static Word16 sqrt2ndOrder( const Word16 ); -static void windowing(const Word16*, Word16*, const Word16*, const Word16, const Word16); -static void windowing_ROM_optimized(const Word16*, Word16*, const Word16, const Word16, const Word16); -static void fft_spec2_fx(const Word16 [], Word32 [], const Word16); -static void trans_ana_fx(const Word16*, Word16*, Word16*, Word16*, const Word16, const Word16, const Word16,const Word16,Word16*, Word16*, Word16*, Word16*); -static void peakfinder_fx(const Word16*, const Word16, Word16*, Word16*, const Word16 +static void windowing( const Word16 *, Word16 *, const Word16 *, const Word16, const Word16 ); +static void windowing_ROM_optimized( const Word16 *, Word16 *, const Word16, const Word16, const Word16 ); +static void fft_spec2_fx( const Word16[], Word32[], const Word16 ); +static void trans_ana_fx( const Word16 *, Word16 *, Word16 *, Word16 *, const Word16, const Word16, const Word16, const Word16, Word16 *, Word16 *, Word16 *, Word16 * ); +static void peakfinder_fx( const Word16 *, const Word16, Word16 *, Word16 *, const Word16 #ifdef IVAS_FEC_ECU_TO_COMPLETE - , const Word16 endpoints /* i : Flag to include endpoints in peak search */ + , + const Word16 endpoints /* i : Flag to include endpoints in peak search */ #endif - ); -static Word16 imax_fx( const Word16 *, const Word16); -static void spec_ana_fx(const Word16* prevsynth, Word16* plocs, Word32* plocsi, Word16* num_plocs, Word16* X_sav, const Word16 output_frame, const Word16 bwidth_fx, Word16* Q +); +static Word16 imax_fx( const Word16 *, const Word16 ); +static void spec_ana_fx( const Word16 *prevsynth, Word16 *plocs, Word32 *plocsi, Word16 *num_plocs, Word16 *X_sav, const Word16 output_frame, const Word16 bwidth_fx, Word16 *Q #ifdef IVAS_FEC_ECU_TO_COMPLETE - , const Word16 element_mode, Word16* noise_fac, const Word16 pcorr + , + const Word16 element_mode, + Word16 *noise_fac, + const Word16 pcorr #endif - ); -static void subst_spec_fx(const Word16*, const Word32*, Word16*, const Word16, Word16*, const Word16*, const Word16, const Word16*, const Word16, Word16* - ,const Word16*, const Word16*, Word16, const Word16*); +); +static void subst_spec_fx( const Word16 *, const Word32 *, Word16 *, const Word16, Word16 *, const Word16 *, const Word16, const Word16 *, const Word16, Word16 *, const Word16 *, const Word16 *, Word16, const Word16 * ); #ifdef IVAS_FLOAT_FIXED -static Word16 rand_phase_fx(const Word16 seed, Word16 *sin_F, Word16 *cos_F); +static Word16 rand_phase_fx( const Word16 seed, Word16 *sin_F, Word16 *cos_F ); #endif #ifdef IVAS_FEC_ECU_TO_COMPLETE -static float imax2_jacobsen_mag(const float* y_re, const float* y_im); +static float imax2_jacobsen_mag( const float *y_re, const float *y_im ); #endif /*------------------------------------------------------------------* @@ -106,25 +109,25 @@ static float imax2_jacobsen_mag(const float* y_re, const float* y_im); * randomized phase in form of sin and cos components *------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -static Word16 rand_phase_fx(const Word16 seed, Word16 *sin_F, Word16 *cos_F) +static Word16 rand_phase_fx( const Word16 seed, Word16 *sin_F, Word16 *cos_F ) { const Word16 *sincos = sincos_t_ext_fx + 128; - Word16 seed2 = own_random2_fx(seed); - Word16 seed2_shift = shr(seed2, 8); + Word16 seed2 = own_random2_fx( seed ); + Word16 seed2_shift = shr( seed2, 8 ); - *sin_F = negate(*(sincos + seed2_shift)); + *sin_F = negate( *( sincos + seed2_shift ) ); move16(); - if (s_and(seed2, 0x40) != 0) + if ( s_and( seed2, 0x40 ) != 0 ) { - *sin_F = *(sincos + seed2_shift); + *sin_F = *( sincos + seed2_shift ); move16(); } - *cos_F = negate(*(sincos - seed2_shift)); + *cos_F = negate( *( sincos - seed2_shift ) ); move16(); - if (s_and(seed2, 0x80) != 0) + if ( s_and( seed2, 0x80 ) != 0 ) { - *cos_F = *(sincos - seed2_shift); + *cos_F = *( sincos - seed2_shift ); move16(); } @@ -133,7 +136,7 @@ static Word16 rand_phase_fx(const Word16 seed, Word16 *sin_F, Word16 *cos_F) #endif #ifdef IVAS_FLOAT_FIXED - /*! r: The location, relative to the middle of the 3 given data point, of the maximum. (Q15)*/ +/*! r: The location, relative to the middle of the 3 given data point, of the maximum. (Q15)*/ static Word16 ivas_imax2_jacobsen_mag_fx( const Word16 *y_re, /* i : The 3 given data points. real part order -1 0 1 */ const Word16 *y_im /* i : The 3 given data points. imag part order 1 0 -1 (from FFT) */ @@ -193,7 +196,7 @@ static Word16 ivas_imax2_jacobsen_mag_fx( IF( NE_32( numer, 0 ) && NE_32( denom, 0 ) ) { tmp = BASOP_Util_Divide3232_Scale( numer, denom, &tmp_e ); - tmp = shl_sat( tmp, tmp_e ); // Q15 + tmp = shl_sat( tmp, tmp_e ); // Q15 posi = shl_sat( mult_r( tmp, C_JACOB_FX ), Q1 ); // Q15 } ELSE @@ -211,14 +214,14 @@ static Word16 ivas_imax2_jacobsen_mag_fx( * refine peak interpolation using jacobsen and periodic speca ana windows *----------------------------------------------------------------------------*/ - /*! r: The location, relative to the middle of the 3 given data point, of the maximum. (Q15)*/ +/*! r: The location, relative to the middle of the 3 given data point, of the maximum. (Q15)*/ static float imax2_jacobsen_mag( - const float* y_re, /* i : The 3 given data points. real part order -1 0 1 */ - const float* y_im /* i : The 3 given data points. imag part order 1 0 -1 (from FFT) */ + const float *y_re, /* i : The 3 given data points. real part order -1 0 1 */ + const float *y_im /* i : The 3 given data points. imag part order 1 0 -1 (from FFT) */ ) { float posi; - const float* pY; + const float *pY; float y_m1_re, y_0_re, y_p1_re; float y_m1_im, y_0_im, y_p1_im; float N_re, N_im; @@ -234,7 +237,7 @@ static float imax2_jacobsen_mag( */ #define C_JACOB 1.1453f /* % assume 0.1875 hammrect window 'symmetric' */ - /* Get the bin parameters into variables */ + /* Get the bin parameters into variables */ pY = y_re; y_m1_re = *pY++; y_0_re = *pY++; @@ -260,7 +263,7 @@ static float imax2_jacobsen_mag( denom = D_re * D_re + D_im * D_im; test(); - if (numer != 0 && denom != 0) + if ( numer != 0 && denom != 0 ) { posi = numer / denom * C_JACOB; } @@ -280,9 +283,9 @@ static float imax2_jacobsen_mag( * Square magnitude of fft spectrum *----------------------------------------------------------------------------*/ static void fft_spec2_fx( - const Word16 x[], /* i : Input vector: complex spectrum */ - Word32 xMagSq[], /* o : Magnitude square spectrum */ - const Word16 N /* i : Input vector length */ + const Word16 x[], /* i : Input vector: complex spectrum */ + Word32 xMagSq[], /* o : Magnitude square spectrum */ + const Word16 N /* i : Input vector length */ ) { Word16 i, l; @@ -292,24 +295,24 @@ static void fft_spec2_fx( /* Magnitude at 0. */ pMagSq = &xMagSq[0]; pRe = &x[0]; - *pMagSq++ = L_mult0(*pRe, *pRe); + *pMagSq++ = L_mult0( *pRe, *pRe ); pRe++; /* Non-fractional multiply gives subsequent group power accumulation a bit headroom. */ /* From 1 to (N/2 - 1). */ - l = sub(shr(N, 1), 1); /* N/2 - 1. */ + l = sub( shr( N, 1 ), 1 ); /* N/2 - 1. */ pIm = &x[N]; pIm--; - FOR (i = 0; i < l; i++) + FOR( i = 0; i < l; i++ ) { - acc = L_mult0(*pRe, *pRe); - pRe++; /* Non-fractional mode multiply. */ - *pMagSq++ = L_mac0(acc, *pIm, *pIm); + acc = L_mult0( *pRe, *pRe ); + pRe++; /* Non-fractional mode multiply. */ + *pMagSq++ = L_mac0( acc, *pIm, *pIm ); pIm--; move32(); } /* The magnitude square at N/2 */ - *pMagSq = L_mult0(*pRe, *pRe); + *pMagSq = L_mult0( *pRe, *pRe ); move32(); return; } @@ -320,33 +323,33 @@ static void fft_spec2_fx( * Transient analysis *----------------------------------------------------------------------------*/ static void trans_ana_fx( - const Word16 *xfp, /* i : Input signal Q0 */ - Word16 *mag_chg, /* o : Magnitude modification Q15 */ - Word16 *ph_dith, /* o : Phase dither, 2*PI is not included (Q15, i.e., between 0.0 and 1.0) */ - Word16 *mag_chg_1st, /* i/o: per band magnitude modifier for transients Q15 */ - const Word16 output_frame, /* i : Frame length */ - const Word16 time_offs, /* i : Time offset (integral multiple of output_frame) */ - const Word16 est_mus_content, /* i : 0.0=speech_like ... 1.0=Music (==st->env_stab ) */ - const Word16 last_fec, /* i : signal that previous frame was concealed with fec_alg */ - Word16 *alpha, /* o : Magnitude modification factors for fade to average */ - Word16 *beta, /* o : Magnitude modification factors for fade to average */ - Word16 *beta_mute, /* o : Factor for long-term mute */ - Word16 *Xavg /* o : Frequency group average gain to fade to */ + const Word16 *xfp, /* i : Input signal Q0 */ + Word16 *mag_chg, /* o : Magnitude modification Q15 */ + Word16 *ph_dith, /* o : Phase dither, 2*PI is not included (Q15, i.e., between 0.0 and 1.0) */ + Word16 *mag_chg_1st, /* i/o: per band magnitude modifier for transients Q15 */ + const Word16 output_frame, /* i : Frame length */ + const Word16 time_offs, /* i : Time offset (integral multiple of output_frame) */ + const Word16 est_mus_content, /* i : 0.0=speech_like ... 1.0=Music (==st->env_stab ) */ + const Word16 last_fec, /* i : signal that previous frame was concealed with fec_alg */ + Word16 *alpha, /* o : Magnitude modification factors for fade to average */ + Word16 *beta, /* o : Magnitude modification factors for fade to average */ + Word16 *beta_mute, /* o : Factor for long-term mute */ + Word16 *Xavg /* o : Frequency group average gain to fade to */ ) { const Word16 *w_hamm, *pFftTbl; Word16 att_val, attDegreeFrames; Word16 xfp_left[L_TRANA48k], xfp_right[L_TRANA48k]; - Word32 magSqLeft[L_TRANA48k/2+1], magSqRight[L_TRANA48k/2+1]; + Word32 magSqLeft[L_TRANA48k / 2 + 1], magSqRight[L_TRANA48k / 2 + 1]; Word32 *pLeft, *pRight, *pGrPowLeft, *pGrPowRight; Word32 gr_pow_left[LGW_MAX], gr_pow_right[LGW_MAX]; const Word16 *pXfp, *pGw; Word16 Ltrana, Ltrana_2, Lprot, three4thLength, LtranaLogMinus1, Lgw, i, k, l, burst_len; Word16 man, expo; - Word16 att_always = 0; /* fixed attenuation per frequency group if set to 1 */ + Word16 att_always = 0; /* fixed attenuation per frequency group if set to 1 */ Word16 oneOverFrame, roundEstMusContent, tmp16, headroom, lowerEdge; - Word16 burst_phdith_thresh = BURST_PHDITH_THRESH; /*speech settings */ - Word16 burst_att_thresh = BURST_ATT_THRESH ; + Word16 burst_phdith_thresh = BURST_PHDITH_THRESH; /*speech settings */ + Word16 burst_att_thresh = BURST_ATT_THRESH; Word16 att_per_frame = ATT_PER_FRAME; Word16 burst_phdith_rampup_len = BURST_PHDITH_RAMPUP_LEN; Word16 tr_dec[LGW_MAX]; @@ -358,93 +361,102 @@ static void trans_ana_fx( pFftTbl = NULL; /* Initialisation to prevent warnings */ - oneOverFrame = 102; /* 1/320 in Q15 */ move16(); + oneOverFrame = 102; /* 1/320 in Q15 */ + move16(); w_hamm = w_hamm16k_2_fx; move16(); Lprot = 512; move16(); /* check burst error */ - IF (EQ_16(output_frame, L_FRAME48k)) /* output_frame = (sampling frequency)/50 */ + IF( EQ_16( output_frame, L_FRAME48k ) ) /* output_frame = (sampling frequency)/50 */ { - oneOverFrame = 34; /* 1/960 in Q15 */ move16(); + oneOverFrame = 34; /* 1/960 in Q15 */ + move16(); w_hamm = w_hamm48k_2_fx; move16(); Lgw = LGW48K; move16(); - Lprot = 1536; /* (2*output_frame)*1024/1280; */ move16(); + Lprot = 1536; /* (2*output_frame)*1024/1280; */ + move16(); } - ELSE IF (EQ_16(output_frame, L_FRAME32k)) + ELSE IF( EQ_16( output_frame, L_FRAME32k ) ) { - oneOverFrame = 51; /* 1/640 in Q15 */ move16(); + oneOverFrame = 51; /* 1/640 in Q15 */ + move16(); w_hamm = w_hamm32k_2_fx; move16(); Lgw = LGW32K; move16(); Lprot = 1024; move16(); - pFftTbl = FFT_W128; /* Table for 256 real input radix-2 FFT */ move16(); + pFftTbl = FFT_W128; /* Table for 256 real input radix-2 FFT */ + move16(); LtranaLogMinus1 = LTRANALOG32K - 1; move16(); } ELSE { - oneOverFrame = 102; /* 1/320 in Q15 */ move16(); + oneOverFrame = 102; /* 1/320 in Q15 */ + move16(); w_hamm = w_hamm16k_2_fx; move16(); Lgw = LGW16K; move16(); Lprot = 512; move16(); - pFftTbl = FFT_W64; /* Table for 128 real input radix-2 FFT */ move16(); + pFftTbl = FFT_W64; /* Table for 128 real input radix-2 FFT */ + move16(); LtranaLogMinus1 = LTRANALOG16K - 1; move16(); } - burst_len = add(mult_r(time_offs, oneOverFrame), 1); + burst_len = add( mult_r( time_offs, oneOverFrame ), 1 ); *ph_dith = 0; move16(); /* typical pattern is 2*pi*[0 0 .25 .50 .75 1.0 1.0 1.0 ..] */ - IF (GE_16(output_frame, L_FRAME32k)) /*currently est_mus_content only calculated for SWB and FB */ + IF( GE_16( output_frame, L_FRAME32k ) ) /*currently est_mus_content only calculated for SWB and FB */ { roundEstMusContent = 0; move16(); - if (GE_16(est_mus_content, FEC_HQ_ECU_POINT5)) /* est_mus_content is in [0.0, 1.0]. */ + if ( GE_16( est_mus_content, FEC_HQ_ECU_POINT5 ) ) /* est_mus_content is in [0.0, 1.0]. */ { roundEstMusContent = 1; move16(); } /* softly shift attenuation just a bit later for estimated "stable" music_content */ - burst_phdith_thresh = add(BURST_PHDITH_THRESH, roundEstMusContent); - burst_att_thresh = add(BURST_ATT_THRESH, roundEstMusContent); - att_per_frame = sub(ATT_PER_FRAME, roundEstMusContent); /* only slighty less att for music */ + burst_phdith_thresh = add( BURST_PHDITH_THRESH, roundEstMusContent ); + burst_att_thresh = add( BURST_ATT_THRESH, roundEstMusContent ); + att_per_frame = sub( ATT_PER_FRAME, roundEstMusContent ); /* only slighty less att for music */ } ELSE { /* lock to music-like stable envelope setting for now */ - burst_phdith_thresh = add(BURST_PHDITH_THRESH, 1); /* in Q0 */ - burst_att_thresh = add(BURST_ATT_THRESH, 1); /* in Q0 */ - att_per_frame = sub(ATT_PER_FRAME, 1); /* in Q0 */ + burst_phdith_thresh = add( BURST_PHDITH_THRESH, 1 ); /* in Q0 */ + burst_att_thresh = add( BURST_ATT_THRESH, 1 ); /* in Q0 */ + att_per_frame = sub( ATT_PER_FRAME, 1 ); /* in Q0 */ } - IF (GT_16(burst_len, burst_phdith_thresh)) + IF( GT_16( burst_len, burst_phdith_thresh ) ) { /* increase degree of dither */ #if BURST_PHDITH_RAMPUP_LEN != 2 #error The implementation of phase_dith=min(1.0, (burst_len - burst_phdith_thresh)/burst_phdith_rampup_len)) is incorrect #endif - *ph_dith = 32767; /* 1.0 in Q15. N.B. 2*PI is not included. */ move16(); - tmp16 = sub(burst_len, burst_phdith_thresh); - if (LT_16(tmp16, burst_phdith_rampup_len)) + *ph_dith = 32767; /* 1.0 in Q15. N.B. 2*PI is not included. */ + move16(); + tmp16 = sub( burst_len, burst_phdith_thresh ); + if ( LT_16( tmp16, burst_phdith_rampup_len ) ) { - *ph_dith = 16384; /* 0.5 in Q15. N.B. 2*PI is not included. */ move16(); + *ph_dith = 16384; /* 0.5 in Q15. N.B. 2*PI is not included. */ + move16(); } } attDegreeFrames = 0; move16(); - IF (GT_16(burst_len, burst_att_thresh)) + IF( GT_16( burst_len, burst_att_thresh ) ) { att_always = 1; move16(); @@ -453,130 +465,132 @@ static void trans_ana_fx( /* N.B. To facilitate the subsequent 10^(-att_degree/20) implementation * so as to use direct table-lookup, * (burstLen - burst_att_thresh) is NOT multiplied by "att_per_frame". */ - attDegreeFrames = sub(burst_len, burst_att_thresh); /* Not multiplied by att_per_frqme! */ + attDegreeFrames = sub( burst_len, burst_att_thresh ); /* Not multiplied by att_per_frqme! */ /* Furthermore, in order to minimize the size of the lookup-table required to * implement 10^(-att_degree/10), hard limit attDegreeFrames to (30% of 50)=15. * If attDegreeFrames is greater than 15, it means there are more than 15 successive * bad frames. In this case, no matter what to do, the sound quality will be bad. */ - if (GT_16(attDegreeFrames, OFF_FRAMES_LIMIT)) + if ( GT_16( attDegreeFrames, OFF_FRAMES_LIMIT ) ) { - attDegreeFrames = OFF_FRAMES_LIMIT; /* Hard limit the no. of frames */ move16(); + attDegreeFrames = OFF_FRAMES_LIMIT; /* Hard limit the no. of frames */ + move16(); } } - Ltrana = shr(Lprot, 2); - Ltrana_2 = shr(Ltrana, 1); + Ltrana = shr( Lprot, 2 ); + Ltrana_2 = shr( Ltrana, 1 ); test(); test(); - IF (LE_16(burst_len, 1)||(EQ_16(burst_len,2)&&last_fec!=0)) + IF( LE_16( burst_len, 1 ) || ( EQ_16( burst_len, 2 ) && last_fec != 0 ) ) { - set16_fx(alpha, 32767, LGW_MAX); - set16_fx(beta, 0, LGW_MAX); + set16_fx( alpha, 32767, LGW_MAX ); + set16_fx( beta, 0, LGW_MAX ); *beta_mute = BETA_MUTE_FAC_INI; move16(); /* Apply Hamming window */ - windowing(xfp, xfp_left, w_hamm, 0, Ltrana_2); /* 1st quarter */ - three4thLength = sub(Lprot, Ltrana); + windowing( xfp, xfp_left, w_hamm, 0, Ltrana_2 ); /* 1st quarter */ + three4thLength = sub( Lprot, Ltrana ); pXfp = xfp + three4thLength; - windowing(pXfp, xfp_right, w_hamm, 0, Ltrana_2); /* 4th quarter */ + windowing( pXfp, xfp_right, w_hamm, 0, Ltrana_2 ); /* 4th quarter */ /* spectrum */ - IF (EQ_16(output_frame, L_FRAME48k)) + IF( EQ_16( output_frame, L_FRAME48k ) ) { - fft3_fx(xfp_left, xfp_left, Ltrana); - fft3_fx(xfp_right, xfp_right, Ltrana); + fft3_fx( xfp_left, xfp_left, Ltrana ); + fft3_fx( xfp_right, xfp_right, Ltrana ); } ELSE { - r_fft_fx_lc(pFftTbl, Ltrana, Ltrana_2, LtranaLogMinus1, xfp_left, xfp_left, 1); - r_fft_fx_lc(pFftTbl, Ltrana, Ltrana_2, LtranaLogMinus1, xfp_right, xfp_right, 1); + r_fft_fx_lc( pFftTbl, Ltrana, Ltrana_2, LtranaLogMinus1, xfp_left, xfp_left, 1 ); + r_fft_fx_lc( pFftTbl, Ltrana, Ltrana_2, LtranaLogMinus1, xfp_right, xfp_right, 1 ); } /* square representation */ - fft_spec2_fx(xfp_left, magSqLeft, Ltrana); - fft_spec2_fx(xfp_right, magSqRight, Ltrana); + fft_spec2_fx( xfp_left, magSqLeft, Ltrana ); + fft_spec2_fx( xfp_right, magSqRight, Ltrana ); /* band powers in frequency groups * exclude bin at PI from calculation */ - magSqLeft[Ltrana_2] = L_deposit_l(0); - magSqRight[Ltrana_2] = L_deposit_l(0); + magSqLeft[Ltrana_2] = L_deposit_l( 0 ); + magSqRight[Ltrana_2] = L_deposit_l( 0 ); } - pGrPowLeft = &gr_pow_left[0]; + pGrPowLeft = &gr_pow_left[0]; pGrPowRight = &gr_pow_right[0]; pGw = gw; - FOR ( k = 0; k < Lgw; k++ ) + FOR( k = 0; k < Lgw; k++ ) { test(); test(); - IF (LE_16(burst_len, 1)||(EQ_16(burst_len,2)&&last_fec!=0)) + IF( LE_16( burst_len, 1 ) || ( EQ_16( burst_len, 2 ) && last_fec != 0 ) ) { lowerEdge = *pGw++; move16(); - l = sub(*pGw, lowerEdge); - headroom = GR_POW_HEADROOM[k]; /* Number of bits to scale down preventing from saturation in accumulation.*/ move16(); - pLeft = magSqLeft + lowerEdge; + l = sub( *pGw, lowerEdge ); + headroom = GR_POW_HEADROOM[k]; /* Number of bits to scale down preventing from saturation in accumulation.*/ + move16(); + pLeft = magSqLeft + lowerEdge; pRight = magSqRight + lowerEdge; - *pGrPowLeft = L_deposit_l(0); - *pGrPowRight = L_deposit_l(0); - FOR (i = 0; i < l; i++) + *pGrPowLeft = L_deposit_l( 0 ); + *pGrPowRight = L_deposit_l( 0 ); + FOR( i = 0; i < l; i++ ) { - acc = L_shr(*pLeft++, headroom); /* Scale down to prevent from saturation. */ - *pGrPowLeft = L_add(*pGrPowLeft, acc); + acc = L_shr( *pLeft++, headroom ); /* Scale down to prevent from saturation. */ + *pGrPowLeft = L_add( *pGrPowLeft, acc ); move32(); - acc = L_shr(*pRight++, headroom); - *pGrPowRight = L_add(*pGrPowRight, acc); + acc = L_shr( *pRight++, headroom ); + *pGrPowRight = L_add( *pGrPowRight, acc ); move32(); } /*Xavg[k] = sqrt(0.5f*(gr_pow_left[k]+gr_pow_right[k])/(float)(gw[k+1]-gw[k]));*/ - acc = L_shr(L_add(*pGrPowLeft, *pGrPowRight), 1); - acc = Mult_32_16(acc, gw_len_inv_fx[k]); /* -headroom */ + acc = L_shr( L_add( *pGrPowLeft, *pGrPowRight ), 1 ); + acc = Mult_32_16( acc, gw_len_inv_fx[k] ); /* -headroom */ - acc = Sqrt_l(acc, &expo); /* -headroom+31+expo */ + acc = Sqrt_l( acc, &expo ); /* -headroom+31+expo */ - expo = sub(add(expo, 31), headroom); - if ( EQ_16(s_and(expo, 1), 1)) + expo = sub( add( expo, 31 ), headroom ); + if ( EQ_16( s_and( expo, 1 ), 1 ) ) { - acc = Mult_32_16(acc, 23170); /* 1/sqrt(2) in Q15 */ + acc = Mult_32_16( acc, 23170 ); /* 1/sqrt(2) in Q15 */ } - expo = shr(expo, 1); - Xavg[k] = round_fx(L_shl(acc, sub(sub(16, expo), 2))); /* Q0, additional right shift by 2 to account for that Xavg is - calculated using lenght N/4 fft but is applied on a fft of length N */ + expo = shr( expo, 1 ); + Xavg[k] = round_fx( L_shl( acc, sub( sub( 16, expo ), 2 ) ) ); /* Q0, additional right shift by 2 to account for that Xavg is + calculated using lenght N/4 fft but is applied on a fft of length N */ /*dither phase in case of transient */ /* separate transition detection and application of forced burst dithering */ tr_dec[k] = 0; move16(); - Mpy_32_16_ss(*pGrPowLeft, THRESH_TR_LIN_BY2_FX, &acc, &lsb); /* To facilitate fixed-point implementation, divide threshold by 2. */ + Mpy_32_16_ss( *pGrPowLeft, THRESH_TR_LIN_BY2_FX, &acc, &lsb ); /* To facilitate fixed-point implementation, divide threshold by 2. */ #ifdef BASOP_NOGLOB acc = L_or( L_shl_sat( acc, 16 ), L_and( 0xffffL, lsb ) ); /* Equivalent to concatenate acc and lsb, and then down shift by 16 bits. */ #else - acc = L_or(L_shl(acc,16), L_and(0xffffL,lsb)); /* Equivalent to concatenate acc and lsb, and then down shift by 16 bits. */ + acc = L_or( L_shl( acc, 16 ), L_and( 0xffffL, lsb ) ); /* Equivalent to concatenate acc and lsb, and then down shift by 16 bits. */ #endif - if (GT_32(*pGrPowRight, acc)) /* gr_pow_right > thres_tr_lin*gr_pow_left */ + if ( GT_32( *pGrPowRight, acc ) ) /* gr_pow_right > thres_tr_lin*gr_pow_left */ { tr_dec[k] = 1; move16(); } - Mpy_32_16_ss(*pGrPowRight, THRESH_TR_LIN_BY2_FX, &acc, &lsb); + Mpy_32_16_ss( *pGrPowRight, THRESH_TR_LIN_BY2_FX, &acc, &lsb ); #ifdef BASOP_NOGLOB acc = L_or( L_shl_sat( acc, 16 ), L_and( 0xffffL, lsb ) ); /* Equivalent to concatenate acc and lsb, and then down shift by 16 bits. */ #else - acc = L_or(L_shl(acc,16), L_and(0xffffL,lsb)); /* Equivalent to concatenate acc and lsb, and then down shift by 16 bits. */ + acc = L_or( L_shl( acc, 16 ), L_and( 0xffffL, lsb ) ); /* Equivalent to concatenate acc and lsb, and then down shift by 16 bits. */ #endif - if (GT_32(*pGrPowLeft, acc)) /* gr_pow_left > thres_tr_lin*gr_pow_right */ + if ( GT_32( *pGrPowLeft, acc ) ) /* gr_pow_left > thres_tr_lin*gr_pow_right */ { tr_dec[k] = 1; move16(); } /* magnitude modification */ - IF ( add(tr_dec[k], att_always) != 0) + IF( add( tr_dec[k], att_always ) != 0 ) { #if MAX_INCREASE_GRPPOW_FX != 0 @@ -584,23 +598,23 @@ static void trans_ana_fx( #endif att_val = 32767; move16(); - IF (GT_32(*pGrPowRight, 0)) + IF( GT_32( *pGrPowRight, 0 ) ) { - IF (LT_32(*pGrPowRight, *pGrPowLeft)) /* i.e., (gr_pow_right/gr_pow_left) < 1.0 */ + IF( LT_32( *pGrPowRight, *pGrPowLeft ) ) /* i.e., (gr_pow_right/gr_pow_left) < 1.0 */ { /* Compute sqrt(grp_pow_chg), where grp_pow_chg = gr_pow_right/gr_pow_left. */ - tmp16 = ratio(*pGrPowRight, *pGrPowLeft, &expo); /* tmp16 in Q14 */ - expo = sub(expo, (15-14)); /* Now, tmp16 is considered in Q15 */ - i = norm_s(tmp16); - man = shl(tmp16, i); /* Mandatory normalization before sqrtNthOrder(). */ - expo = add(expo, i); - man = sqrt2ndOrder(man); - if (s_and(expo,1) != 0) /* Check even or odd. */ + tmp16 = ratio( *pGrPowRight, *pGrPowLeft, &expo ); /* tmp16 in Q14 */ + expo = sub( expo, ( 15 - 14 ) ); /* Now, tmp16 is considered in Q15 */ + i = norm_s( tmp16 ); + man = shl( tmp16, i ); /* Mandatory normalization before sqrtNthOrder(). */ + expo = add( expo, i ); + man = sqrt2ndOrder( man ); + if ( s_and( expo, 1 ) != 0 ) /* Check even or odd. */ { - man = mult_r(man,FEC_HQ_ECU_ROOT2); + man = mult_r( man, FEC_HQ_ECU_ROOT2 ); } - expo = shr(expo, 1); /* Divided by 2-- square root operation. */ - att_val = shr(man, expo); /* Denormalize the mantissa back to Q15. */ + expo = shr( expo, 1 ); /* Divided by 2-- square root operation. */ + att_val = shr( man, expo ); /* Denormalize the mantissa back to Q15. */ } /* ELSE do nothing because (gr_pow_right/gr_pow_left) >= 1.0 (i.e., * max_increase_grppow_lin) */ @@ -616,7 +630,7 @@ static void trans_ana_fx( mag_chg_1st[k] = 32767; move16(); mag_chg[k] = 32767; - move16(); /* Set to 1.0 in Q15 */ + move16(); /* Set to 1.0 in Q15 */ } } ELSE @@ -627,41 +641,43 @@ static void trans_ana_fx( * either ATT_PER_FRAME-1 or ATT_PER_FRAME and nothing else. This * means only 2 tables of size=(OFF_FRAMES_LIMIT+1) each are required. * To take square root into account, it is divided by 20 instead of 10. */ - IF (EQ_16(att_per_frame, ATT_PER_FRAME)) /* Select the corresponding lookup-table. */ + IF( EQ_16( att_per_frame, ATT_PER_FRAME ) ) /* Select the corresponding lookup-table. */ { - att_val = POW_ATT_TABLE0[attDegreeFrames]; /* 10^(-attDegreeFrames*(ATT_PER_FRAME)/20) */ move16(); + att_val = POW_ATT_TABLE0[attDegreeFrames]; /* 10^(-attDegreeFrames*(ATT_PER_FRAME)/20) */ + move16(); } ELSE { - att_val = POW_ATT_TABLE1[attDegreeFrames]; /* 10^(-attDegreeFrames*(ATT_PER_FRAME - 1)/20) */ move16(); + att_val = POW_ATT_TABLE1[attDegreeFrames]; /* 10^(-attDegreeFrames*(ATT_PER_FRAME - 1)/20) */ + move16(); } - mag_chg[k] = mult_r(mag_chg_1st[k], att_val); /* Q15 */ + mag_chg[k] = mult_r( mag_chg_1st[k], att_val ); /* Q15 */ - if (GT_16(burst_len, BETA_MUTE_THR)) + if ( GT_16( burst_len, BETA_MUTE_THR ) ) { - *beta_mute = shr(*beta_mute, 1); + *beta_mute = shr( *beta_mute, 1 ); } alpha[k] = mag_chg[k]; move16(); /*beta[k] = sqrt(1.0f - SQR(alpha[k])) * *beta_mute;*/ - acc = L_sub(1073741824, L_mult0(alpha[k], alpha[k])); - acc = Sqrt_l(acc, &expo); - expo = add(30, add(31, expo)); - if (EQ_16(s_and(expo, 1), 1)) + acc = L_sub( 1073741824, L_mult0( alpha[k], alpha[k] ) ); + acc = Sqrt_l( acc, &expo ); + expo = add( 30, add( 31, expo ) ); + if ( EQ_16( s_and( expo, 1 ), 1 ) ) { - acc = Mult_32_16(acc, 23170); /* 1/sqrt(2) in Q15 */ + acc = Mult_32_16( acc, 23170 ); /* 1/sqrt(2) in Q15 */ } - expo = shr(expo, 1); - beta[k] = mult_r(*beta_mute, round_fx(L_shl(acc, sub(31, expo)))); + expo = shr( expo, 1 ); + beta[k] = mult_r( *beta_mute, round_fx( L_shl( acc, sub( 31, expo ) ) ) ); move16(); - IF (GE_16(k, LGW32K-1)) + IF( GE_16( k, LGW32K - 1 ) ) { - beta[k] = mult_r(beta[k], 3277); /* 0.1 in Q15 */ + beta[k] = mult_r( beta[k], 3277 ); /* 0.1 in Q15 */ } - ELSE IF (GE_16(k, LGW16K-1)) + ELSE IF( GE_16( k, LGW16K - 1 ) ) { - beta[k] = mult_r(beta[k], 16384); /* 0.5 in Q15 */ + beta[k] = mult_r( beta[k], 16384 ); /* 0.5 in Q15 */ } } pGrPowLeft++; @@ -967,35 +983,36 @@ static void ivas_peakfinder_fx( #endif static void peakfinder_fx( - const Word16 *x0, /* i : vector from which the maxima will be found */ - const Word16 len0, /* i : length of input vector */ - Word16 *plocs, /* o : the indices of the identified peaks in x0 Q0 */ - Word16 *cInd, /* o : number of identified peaks Q0 */ - const Word16 sel /* i : The amount above surrounding data for a peak to be identified */ + const Word16 *x0, /* i : vector from which the maxima will be found */ + const Word16 len0, /* i : length of input vector */ + Word16 *plocs, /* o : the indices of the identified peaks in x0 Q0 */ + Word16 *cInd, /* o : number of identified peaks Q0 */ + const Word16 sel /* i : The amount above surrounding data for a peak to be identified */ #ifdef IVAS_FEC_ECU_TO_COMPLETE - ,const Word16 endpoints /* i : Flag to include endpoints in peak search */ + , + const Word16 endpoints /* i : Flag to include endpoints in peak search */ #endif ) { const Word16 *pX0; Word16 minMag, tempMag, leftMin; - Word16 dx0[L_PROT48k_2], x[L_PROT48k_2+1], peakMag[MAX_PLOCS]; + Word16 dx0[L_PROT48k_2], x[L_PROT48k_2 + 1], peakMag[MAX_PLOCS]; Word16 *pDx0, *pDx01, *pX; Word16 i, len, tempLoc, foundPeak, ii, xInd, tmp16, threshold, xAt0, xAt1, xAt2; Word16 len0Minus1, len0Minus2, lenMinus1; - Word16 indarr[L_PROT48k_2+1], peakLoc[MAX_PLOCS]; + Word16 indarr[L_PROT48k_2 + 1], peakLoc[MAX_PLOCS]; Word16 *pInd; tempLoc = 0; /* Find derivative */ - len0Minus1 = sub(len0, 1); + len0Minus1 = sub( len0, 1 ); pX0 = x0 + 1; - Vr_subt(pX0, x0, dx0, len0Minus1); + Vr_subt( pX0, x0, dx0, len0Minus1 ); - FOR (i=0; i 0))) -#else - IF (GT_16(len, 2)) + test(); + test(); + IF( GT_16( len, 2 ) || ( !endpoints && ( len > 0 ) ) ) +#else + IF( GT_16( len, 2 ) ) #endif { /* Set initial parameters for loop */ @@ -1065,58 +1083,64 @@ static void peakfinder_fx( move16(); leftMin = minMag; move16(); - threshold = add(leftMin, sel); + threshold = add( leftMin, sel ); #ifdef IVAS_FEC_ECU_TO_COMPLETE - IF(len > 0) + IF( len > 0 ) #endif { /* Deal with first point a little differently since tacked it on Calculate the sign of the derivative since we took the first point on it does not necessarily alternate like the rest. */ - /* The first point is larger or equal to the second */ + /* The first point is larger or equal to the second */ pX = x; xAt0 = *pX++; move16(); xAt1 = *pX++; move16(); - xAt2 = *pX--; /* After decrement, pX points to x[1]. */ move16(); - IF(GE_16(xAt0, xAt1)) + xAt2 = *pX--; /* After decrement, pX points to x[1]. */ + move16(); + IF( GE_16( xAt0, xAt1 ) ) { ii = -1; move16(); - IF(GE_16(xAt1, xAt2)) /* x[1] is not extremum -> overwrite with x[0] */ + IF( GE_16( xAt1, xAt2 ) ) /* x[1] is not extremum -> overwrite with x[0] */ { - *pX = xAt0; /* x[1] = x[0] */ move16(); + *pX = xAt0; /* x[1] = x[0] */ + move16(); tmp16 = *pInd++; move16(); - *pInd++ = tmp16; /* ind[1] = ind[0] */ move16(); - len = sub(len, 1); + *pInd++ = tmp16; /* ind[1] = ind[0] */ + move16(); + len = sub( len, 1 ); } pX--; /* After decrement, pX points to x[0]. */ } ELSE /* First point is smaller than the second */ { ii = 0; - IF(LT_16(xAt1, xAt2)) /* x[1] is not extremum -> overwrite with x[0] */ + IF( LT_16( xAt1, xAt2 ) ) /* x[1] is not extremum -> overwrite with x[0] */ { - *pX = xAt0; /* x[1] = x[0] */ move16(); + *pX = xAt0; /* x[1] = x[0] */ + move16(); tmp16 = *pInd++; move16(); - *pInd++ = tmp16; /* ind[1] = ind[0] */ move16(); - len = sub(len, 1); + *pInd++ = tmp16; /* ind[1] = ind[0] */ + move16(); + len = sub( len, 1 ); } } pX--; /* After decrement, pX points to either x[-1] or x[0]. */ } #ifdef IVAS_FEC_ECU_TO_COMPLETE ELSE - { PMTE () + { + PMTE() ii = -1; /* First point is a peak */ - if (len >= 2) + if ( len >= 2 ) { - if (x[1] >= x[0]) + if ( x[1] >= x[0] ) { ii = 0; /* First point is a valley, skip it */ } @@ -1126,20 +1150,20 @@ static void peakfinder_fx( *cInd = 0; move16(); /*Loop through extrema which should be peaks and then valleys*/ - lenMinus1 = sub(len, 1); - FOR (;;) + lenMinus1 = sub( len, 1 ); + FOR( ;; ) { - ii = add(ii, 1); /* This is a peak */ + ii = add( ii, 1 ); /* This is a peak */ /* Make sure we don't iterate past the length of our vector */ - IF (GE_16(ii, lenMinus1)) + IF( GE_16( ii, lenMinus1 ) ) { BREAK; } /*Reset peak finding if we had a peak and the next peak is bigger than the last or the left min was small enough to reset.*/ - IF (GT_16(foundPeak,0)) + IF( GT_16( foundPeak, 0 ) ) { tempMag = minMag; move16(); @@ -1149,9 +1173,9 @@ static void peakfinder_fx( /* Found new peak that was larger than temp mag and selectivity larger than the minimum to its left. */ - IF (GT_16(*(++pX), tempMag)) + IF( GT_16( *( ++pX ), tempMag ) ) { - IF ( GT_16(*pX, threshold)) /* threshold = leftMin + sel */ + IF( GT_16( *pX, threshold ) ) /* threshold = leftMin + sel */ { tempLoc = ii; move16(); @@ -1160,65 +1184,67 @@ static void peakfinder_fx( } } - ii = add(ii, 1); /* Move onto the valley */ + ii = add( ii, 1 ); /* Move onto the valley */ pX++; /* Come down at least sel from peak */ - IF (foundPeak == 0) + IF( foundPeak == 0 ) { - IF (GT_16(tempMag, add(sel, *pX))) + IF( GT_16( tempMag, add( sel, *pX ) ) ) { - foundPeak = 1; /* We have found a peak */ move16(); + foundPeak = 1; /* We have found a peak */ + move16(); leftMin = *pX; move16(); - threshold = add(leftMin, sel); - peakLoc[*cInd] = tempLoc; /* Add peak to index */ move16(); + threshold = add( leftMin, sel ); + peakLoc[*cInd] = tempLoc; /* Add peak to index */ + move16(); peakMag[*cInd] = tempMag; move16(); - *cInd = add(*cInd, 1); + *cInd = add( *cInd, 1 ); } } - IF (foundPeak == 0) /* The above IF-block has not found the peak yet. */ + IF( foundPeak == 0 ) /* The above IF-block has not found the peak yet. */ { - IF (LT_16(*pX, leftMin))/* New left minimum */ + IF( LT_16( *pX, leftMin ) ) /* New left minimum */ { leftMin = *pX; move16(); - threshold = add(leftMin, sel); + threshold = add( leftMin, sel ); } } } /* Check end point */ - IF (GT_16(x[lenMinus1], tempMag)) + IF( GT_16( x[lenMinus1], tempMag ) ) { - IF (GT_16(x[lenMinus1], threshold)) /* threshold = leftMin + sel */ + IF( GT_16( x[lenMinus1], threshold ) ) /* threshold = leftMin + sel */ { peakLoc[*cInd] = lenMinus1; move16(); peakMag[*cInd] = x[lenMinus1]; move16(); - *cInd = add(*cInd, 1); + *cInd = add( *cInd, 1 ); foundPeak = 1; move16(); } } - IF (foundPeak == 0) /* Check if we still need to add the last point */ + IF( foundPeak == 0 ) /* Check if we still need to add the last point */ { - IF (GT_16(tempMag, minMag)) + IF( GT_16( tempMag, minMag ) ) { peakLoc[*cInd] = tempLoc; move16(); peakMag[*cInd] = tempMag; move16(); - *cInd = add(*cInd, 1); + *cInd = add( *cInd, 1 ); } } /* Create output */ - FOR (i = 0; i < *cInd; i++) + FOR( i = 0; i < *cInd; i++ ) { - plocs[i] = *(indarr + peakLoc[i]); + plocs[i] = *( indarr + peakLoc[i] ); move16(); move16(); } @@ -1226,12 +1252,12 @@ static void peakfinder_fx( ELSE /* This is a monotone function where an endpoint is the only peak */ { #ifdef IVAS_FEC_ECU_TO_COMPLETE - IF(endpoints) + IF( endpoints ) #endif { xInd = 1; move16(); - if (GT_16(x[0], x[1])) + if ( GT_16( x[0], x[1] ) ) { xInd = 0; move16(); @@ -1239,9 +1265,9 @@ static void peakfinder_fx( peakMag[0] = x[xInd]; move16(); - IF(GT_16(peakMag[0], add(minMag, sel))) + IF( GT_16( peakMag[0], add( minMag, sel ) ) ) { - plocs[0] = *(indarr + xInd); + plocs[0] = *( indarr + xInd ); move16(); *cInd = 1; move16(); @@ -1254,7 +1280,7 @@ static void peakfinder_fx( } #ifdef IVAS_FEC_ECU_TO_COMPLETE ELSE - {/* Input constant or all zeros -- no peaks found */ + { /* Input constant or all zeros -- no peaks found */ *cInd = 0; move16(); } @@ -1263,13 +1289,13 @@ static void peakfinder_fx( } /*----------------------------------------------------------------------------- -* imax_fx() -* -* Get interpolated maximum position -*-----------------------------------------------------------------------------*/ -static Word16 imax_fx( /* o: The location, relative to the middle of the 3 given data point, of the maximum. (Q15) */ - const Word16 *y, /* i: The 3 given data points. */ - const Word16 special /* i: -1 = left edge special case, 0 = normal, +1 = right edge special case */ + * imax_fx() + * + * Get interpolated maximum position + *-----------------------------------------------------------------------------*/ +static Word16 imax_fx( /* o: The location, relative to the middle of the 3 given data point, of the maximum. (Q15) */ + const Word16 *y, /* i: The 3 given data points. */ + const Word16 special /* i: -1 = left edge special case, 0 = normal, +1 = right edge special case */ ) { Word16 posi; @@ -1294,42 +1320,44 @@ static Word16 imax_fx( /* o: The location, relative to the middle of the 3 given */ /* Compute the extremum location: posi = (y3 - y1)/(4*y2 - 2*y1 - 2*y3). */ - y3_y1 = L_sub(y3, y1); - acc = L_shl(y2,1); /* N.B. y2 is multiplied by 2 not 4. */ - acc = L_sub(acc, y1); /* N.B. Y1 is not multiplied by 2. */ - denom = L_sub(acc, y3); /* N.B. Y3 is not multiplied by 2. */ - sign = L_xor(y3_y1, denom); /* Preserve the sign since div_s() only takes positive arguments. */ - numer = L_abs(y3_y1); - denom = L_abs(denom); - IF (numer == 0) + y3_y1 = L_sub( y3, y1 ); + acc = L_shl( y2, 1 ); /* N.B. y2 is multiplied by 2 not 4. */ + acc = L_sub( acc, y1 ); /* N.B. Y1 is not multiplied by 2. */ + denom = L_sub( acc, y3 ); /* N.B. Y3 is not multiplied by 2. */ + sign = L_xor( y3_y1, denom ); /* Preserve the sign since div_s() only takes positive arguments. */ + numer = L_abs( y3_y1 ); + denom = L_abs( denom ); + IF( numer == 0 ) { return 0; } - IF (denom == 0) + IF( denom == 0 ) { return 0; } /* Although the output of ratio() is in Q14, adding the missing factor of 2 (See above) * in the denominator, the output is now considered to be in Q15. */ - man = ratio(numer, denom, &expo); /* The mantissa is considered in Q15 */ + man = ratio( numer, denom, &expo ); /* The mantissa is considered in Q15 */ #ifdef BASOP_NOGLOB - posi = shr_o(man, expo, &Overflow); /* in Q15 (Due to saturation, it is automatically bound inside [-1.0,1.0].) */ + posi = shr_o( man, expo, &Overflow ); /* in Q15 (Due to saturation, it is automatically bound inside [-1.0,1.0].) */ #else - posi = shr(man, expo); /* in Q15 (Due to saturation, it is automatically bound inside [-1.0,1.0].) */ + posi = shr( man, expo ); /* in Q15 (Due to saturation, it is automatically bound inside [-1.0,1.0].) */ #endif - if (sign < 0) /* Restore the sign. */ + if ( sign < 0 ) /* Restore the sign. */ { - posi = negate(posi); + posi = negate( posi ); } /* For both edges (left and right), the extremum found above may be minimum. * It needs to reject the minimum. */ - IF (NE_16(special,0)) /* Either edge specical case. */ + IF( NE_16( special, 0 ) ) /* Either edge specical case. */ { - edge = 0x7fff; /* 1 in Q15 for the right edge special case */ move16(); - if (LT_16(special,0)) + edge = 0x7fff; /* 1 in Q15 for the right edge special case */ + move16(); + if ( LT_16( special, 0 ) ) { - edge = 0; /* Left edge special case */ move16(); + edge = 0; /* Left edge special case */ + move16(); } /* The derivative (slope) of the interpolating parabola = 2*A*y + B, @@ -1338,26 +1366,28 @@ static Word16 imax_fx( /* o: The location, relative to the middle of the 3 given * Therefore, the slope at y=0 is simply B. Use this slope to determine * if the parabola is concave upward or downward. */ - IF (GT_16(posi,0)) /* The extremum is in between the middle and the right given data points. */ + IF( GT_16( posi, 0 ) ) /* The extremum is in between the middle and the right given data points. */ { - IF (LE_16(y3, y1)) /* Check the slope at y=0, i.e., at the middle given data point. */ + IF( LE_16( y3, y1 ) ) /* Check the slope at y=0, i.e., at the middle given data point. */ { - posi = edge; /* minimum case */ move16(); + posi = edge; /* minimum case */ + move16(); } ELSE { - posi = sub(0x7fff, posi); /* maximum case */ + posi = sub( 0x7fff, posi ); /* maximum case */ } } ELSE /* The extremum is in between the left and the middle given data points. */ { - IF (GE_16(y3, y1)) + IF( GE_16( y3, y1 ) ) { - posi = edge; /* minimum case */ move16(); + posi = edge; /* minimum case */ + move16(); } ELSE { - posi = add(0x7fff, posi); /* maximum case */ + posi = add( 0x7fff, posi ); /* maximum case */ } } } @@ -1365,10 +1395,10 @@ static Word16 imax_fx( /* o: The location, relative to the middle of the 3 given } /*----------------------------------------------------------------------------- -* spec_ana_fx() -* -* Spectral analysis -*-----------------------------------------------------------------------------*/ + * spec_ana_fx() + * + * Spectral analysis + *-----------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED static void ivas_spec_ana_fx( @@ -1624,7 +1654,7 @@ static void ivas_spec_ana_fx( /* Special case-- The very 1st peak if it is at 0 index position (DC) */ /* With DELTA_CORR_F0_INT == 2 one needs to handle both *pPlocs==0 and *pPlocs==1 */ - //IF( n > 0 && *pPlocs == 0 ) /* Very 1st peak position possible to have a peak at 0/DC index position. */ + // IF( n > 0 && *pPlocs == 0 ) /* Very 1st peak position possible to have a peak at 0/DC index position. */ test(); IF( GT_16( n, 0 ) && EQ_16( *pPlocs, 0 ) ) /* Very 1st peak position possible to have a peak at 0/DC index position. */ { @@ -1691,7 +1721,7 @@ static void ivas_spec_ana_fx( move32(); currPlocs = *pPlocs++; move16(); - n = sub(n, 1); + n = sub( n, 1 ); } /* Here the only remaining point would be a fs/2 plocs */ @@ -1740,50 +1770,57 @@ static void ivas_spec_ana_fx( #endif static void spec_ana_fx( - const Word16* prevsynth, /* i : Input signal */ - Word16* plocs, /* o : The indicies of the identified peaks Q0 */ - Word32* plocsi, /* o : Interpolated positions of the identified peaks Q16 */ - Word16* num_plocs, /* o : Number of identified peaks Q0 */ - Word16* X_sav, /* o : Stored fft spectrum */ - const Word16 output_frame, /* i : Frame length Q0 */ - const Word16 bwidth_fx, /* i : Encoded bandwidth index Q0 */ - Word16* Q /* o : Q value of the fft spectrum */ + const Word16 *prevsynth, /* i : Input signal */ + Word16 *plocs, /* o : The indicies of the identified peaks Q0 */ + Word32 *plocsi, /* o : Interpolated positions of the identified peaks Q16 */ + Word16 *num_plocs, /* o : Number of identified peaks Q0 */ + Word16 *X_sav, /* o : Stored fft spectrum */ + const Word16 output_frame, /* i : Frame length Q0 */ + const Word16 bwidth_fx, /* i : Encoded bandwidth index Q0 */ + Word16 *Q /* o : Q value of the fft spectrum */ #ifdef IVAS_FEC_ECU_TO_COMPLETE - , const Word16 element_mode, /* i : IVAS element mode */ - Word16* noise_fac, /* o : for few peaks zeroing valleys decision making */ + , + const Word16 element_mode, /* i : IVAS element mode */ + Word16 *noise_fac, /* o : for few peaks zeroing valleys decision making */ const Word16 pcorr #endif ) { Word16 Lprot, LprotLog2Minus1 = 0, hamm_len2 = 0, Lprot2, Lprot2_1, m, n; - const Word16* pFftTbl = NULL; + const Word16 *pFftTbl = NULL; Word16 xfp[L_PROT48k]; - Word32 magSq[L_PROT48k / 2 + 1], * pMagSq; - Word16* pXfp, * pXfp1, * pXsav, * pPlocs; + Word32 magSq[L_PROT48k / 2 + 1], *pMagSq; + Word16 *pXfp, *pXfp1, *pXsav, *pPlocs; Word16 Xmax, Xmin, sel, man, expo, expoBy2; Word16 sinTblOffset, rectLength, fraction, special; - Word32* pPlocsi; + Word32 *pPlocsi; Word32 acc; Word16 stop_band_start; Word16 stop_band_length; - Lprot = 512; /* 1536=(2*output_frame)*1024/1280; */ move16(); + Lprot = 512; /* 1536=(2*output_frame)*1024/1280; */ + move16(); sinTblOffset = 0; - IF(EQ_16(output_frame, L_FRAME48k)) + IF( EQ_16( output_frame, L_FRAME48k ) ) { - Lprot = L_PROT48k; /* 1536=(2*output_frame)*1024/1280; */ move16(); - hamm_len2 = L_PROT_HAMM_LEN2_48k; /* half Hamming window = 288 */ move16(); + Lprot = L_PROT48k; /* 1536=(2*output_frame)*1024/1280; */ + move16(); + hamm_len2 = L_PROT_HAMM_LEN2_48k; /* half Hamming window = 288 */ + move16(); } - ELSE IF(EQ_16(output_frame, L_FRAME32k)) + ELSE IF( EQ_16( output_frame, L_FRAME32k ) ) { - Lprot = L_PROT32k; /* 1024 */ move16(); + Lprot = L_PROT32k; /* 1024 */ + move16(); sinTblOffset = 4; move16(); - hamm_len2 = L_PROT_HAMM_LEN2_32k; /* half Hamming window = 192 */ move16(); + hamm_len2 = L_PROT_HAMM_LEN2_32k; /* half Hamming window = 192 */ + move16(); pFftTbl = FFT_W512; /* Table for 1024-point real input FFT */ - LprotLog2Minus1 = 9; /* FFT stages for complex input FFT */ move16(); + LprotLog2Minus1 = 9; /* FFT stages for complex input FFT */ + move16(); } ELSE { @@ -1791,195 +1828,199 @@ static void spec_ana_fx( move16(); sinTblOffset = 8; move16(); - hamm_len2 = L_PROT_HAMM_LEN2_16k; /* half Hamming window = 96 */ move16(); + hamm_len2 = L_PROT_HAMM_LEN2_16k; /* half Hamming window = 96 */ + move16(); pFftTbl = FFT_W256; /* Table for 512-point real input FFT */ - LprotLog2Minus1 = 8; /* FFT stages for complex input FFT */ move16(); + LprotLog2Minus1 = 8; /* FFT stages for complex input FFT */ + move16(); } - Lprot2 = shr(Lprot, 1); - Lprot2_1 = add(Lprot2, 1); - rectLength = sub(Lprot, shl(hamm_len2, 1)); /* The length of the rectangular portion of the Hamming-Rectangular window. */ + Lprot2 = shr( Lprot, 1 ); + Lprot2_1 = add( Lprot2, 1 ); + rectLength = sub( Lprot, shl( hamm_len2, 1 ) ); /* The length of the rectangular portion of the Hamming-Rectangular window. */ - *Q = s_max(0, sub(Exp16Array(Lprot, prevsynth), 1)); + *Q = s_max( 0, sub( Exp16Array( Lprot, prevsynth ), 1 ) ); move16(); - Copy_Scale_sig(prevsynth, xfp, Lprot, *Q); + Copy_Scale_sig( prevsynth, xfp, Lprot, *Q ); - IF(EQ_16(output_frame, L_FRAME48k)) + IF( EQ_16( output_frame, L_FRAME48k ) ) { /* Apply hamming-rect window */ #ifdef IVAS_FEC_ECU_TO_COMPLETE - IF(EQ_16(element_mode, EVS_MONO)) + IF( EQ_16( element_mode, EVS_MONO ) ) #endif { - windowing(xfp, xfp, w_hamm_sana48k_2_fx, rectLength, hamm_len2); + windowing( xfp, xfp, w_hamm_sana48k_2_fx, rectLength, hamm_len2 ); } #ifdef IVAS_FEC_ECU_TO_COMPLETE ELSE { PMTE() - //window_corr = w_hamm[0]; - //window_corr_step = w_hamm[0] / hamm_len2; - //for (i = 0; i < hamm_len2; i++) + // window_corr = w_hamm[0]; + // window_corr_step = w_hamm[0] / hamm_len2; + // for (i = 0; i < hamm_len2; i++) //{ - // xfp[i] = prevsynth[i] * (w_hamm[i] - window_corr); - // xfp[Lprot - i - 1] = prevsynth[Lprot - i - 1] * (w_hamm[i] - window_corr); - // window_corr -= window_corr_step; - //} + // xfp[i] = prevsynth[i] * (w_hamm[i] - window_corr); + // xfp[Lprot - i - 1] = prevsynth[Lprot - i - 1] * (w_hamm[i] - window_corr); + // window_corr -= window_corr_step; + // } } #endif - /* Spectrum */ - fft3_fx(xfp, xfp, Lprot); + /* Spectrum */ + fft3_fx( xfp, xfp, Lprot ); } ELSE { #ifdef IVAS_FEC_ECU_TO_COMPLETE - IF(EQ_16(element_mode, EVS_MONO)) + IF( EQ_16( element_mode, EVS_MONO ) ) #endif { - /* Apply hamming-rect window */ - windowing_ROM_optimized(xfp, xfp, sinTblOffset, rectLength, hamm_len2); - } + /* Apply hamming-rect window */ + windowing_ROM_optimized( xfp, xfp, sinTblOffset, rectLength, hamm_len2 ); + } #ifdef IVAS_FEC_ECU_TO_COMPLETE ELSE { PMTE() - //window_corr = w_hamm[0]; - //window_corr_step = w_hamm[0] / hamm_len2; - //for (i = 0; i < hamm_len2; i++) + // window_corr = w_hamm[0]; + // window_corr_step = w_hamm[0] / hamm_len2; + // for (i = 0; i < hamm_len2; i++) //{ - // xfp[i] = prevsynth[i] * (w_hamm[i] - window_corr); - // xfp[Lprot - i - 1] = prevsynth[Lprot - i - 1] * (w_hamm[i] - window_corr); - // window_corr -= window_corr_step; - //} - } + // xfp[i] = prevsynth[i] * (w_hamm[i] - window_corr); + // xfp[Lprot - i - 1] = prevsynth[Lprot - i - 1] * (w_hamm[i] - window_corr); + // window_corr -= window_corr_step; + // } + } #endif - /* Spectrum */ - r_fft_fx_lc(pFftTbl, Lprot, Lprot2, LprotLog2Minus1, xfp, xfp, 1); + /* Spectrum */ + r_fft_fx_lc( pFftTbl, Lprot, Lprot2, LprotLog2Minus1, xfp, xfp, 1 ); } - /* Apply zeroing of non-coded FFT spectrum */ - IF(GT_16(output_frame, inner_frame_tbl[bwidth_fx])) + /* Apply zeroing of non-coded FFT spectrum */ + IF( GT_16( output_frame, inner_frame_tbl[bwidth_fx] ) ) { - stop_band_start = shl(128, bwidth_fx); - stop_band_length = sub(Lprot, shl(stop_band_start, 1)); - stop_band_start = add(stop_band_start, 1); - set16_fx(xfp + stop_band_start, 0, stop_band_length); + stop_band_start = shl( 128, bwidth_fx ); + stop_band_length = sub( Lprot, shl( stop_band_start, 1 ) ); + stop_band_start = add( stop_band_start, 1 ); + set16_fx( xfp + stop_band_start, 0, stop_band_length ); } pXfp = xfp; pXsav = X_sav; - FOR(m = 0; m < Lprot; m++) + FOR( m = 0; m < Lprot; m++ ) { *pXsav++ = *pXfp++; move16(); } /* Magnitude representation */ - fft_spec2_fx(xfp, magSq, Lprot); + fft_spec2_fx( xfp, magSq, Lprot ); /* Compute xfp[m] = sqrt(magSq[m]) */ pXfp = xfp; pMagSq = magSq; - FOR(m = 0; m < Lprot2_1; m++) + FOR( m = 0; m < Lprot2_1; m++ ) { - IF(*pMagSq == 0) + IF( *pMagSq == 0 ) { - *pXfp++ = extract_l(*pMagSq++); /* magSq[] is zero */ + *pXfp++ = extract_l( *pMagSq++ ); /* magSq[] is zero */ } ELSE { - expo = norm_l(*pMagSq); /* exponent */ - man = extract_h(L_shl(*pMagSq++, expo)); /* mantissa */ - man = sqrt2ndOrder(man); - expoBy2 = shr(expo, 1); /* Divided by 2-- square root operation. */ - IF(s_and(expo,1) == 0) /* Check even or odd. */ + expo = norm_l( *pMagSq ); /* exponent */ + man = extract_h( L_shl( *pMagSq++, expo ) ); /* mantissa */ + man = sqrt2ndOrder( man ); + expoBy2 = shr( expo, 1 ); /* Divided by 2-- square root operation. */ + IF( s_and( expo, 1 ) == 0 ) /* Check even or odd. */ { - man = mult_r(man,FEC_HQ_ECU_ROOT2); /* FEC_HQ_ECU_ROOT2 is sqrt(2) in Q14 */ - expoBy2 = sub(expoBy2, 1); + man = mult_r( man, FEC_HQ_ECU_ROOT2 ); /* FEC_HQ_ECU_ROOT2 is sqrt(2) in Q14 */ + expoBy2 = sub( expoBy2, 1 ); } #ifdef BASOP_NOGLOB *pXfp++ = shr_sat( man, expoBy2 ); #else - *pXfp++ = shr(man, expoBy2); + *pXfp++ = shr( man, expoBy2 ); #endif - move16();/* Denormalize the mantissa back to Q0. */ + move16(); /* Denormalize the mantissa back to Q0. */ } } /* Find maximum and minimum. */ - maximum_fx(xfp, Lprot2_1, &Xmax); - minimum_fx(xfp, Lprot2_1, &Xmin); + maximum_fx( xfp, Lprot2_1, &Xmax ); + minimum_fx( xfp, Lprot2_1, &Xmin ); #ifdef IVAS_FEC_ECU_TO_COMPLETE - IF(EQ_16(element_mode, EVS_MONO)) + IF( EQ_16( element_mode, EVS_MONO ) ) #endif { - sel = mult_r(sub(Xmax, Xmin), CMPLMNT_PFIND_SENS_FX); + sel = mult_r( sub( Xmax, Xmin ), CMPLMNT_PFIND_SENS_FX ); } #ifdef IVAS_FEC_ECU_TO_COMPLETE ELSE { - sel = (Xmax - Xmin) * (1.0f - ST_PFIND_SENS); + sel = ( Xmax - Xmin ) * ( 1.0f - ST_PFIND_SENS ); } #endif - peakfinder_fx(xfp, Lprot2_1, plocs, num_plocs, sel + peakfinder_fx( xfp, Lprot2_1, plocs, num_plocs, sel #ifdef IVAS_FEC_ECU_TO_COMPLETE - , endpoints + , + endpoints #endif - ); + ); #ifdef IVAS_FEC_ECU_TO_COMPLETE /* Currently not the pitch correlation but some LF correlation */ - if (element_mode != EVS_MONO && *num_plocs > 50 && pcorr < 0.6f) + if ( element_mode != EVS_MONO && *num_plocs > 50 && pcorr < 0.6f ) { *num_plocs = 0; } - IF(EQ_16(element_mode, EVS_MONO)) + IF( EQ_16( element_mode, EVS_MONO ) ) #endif { /* Refine peaks */ pPlocsi = plocsi; pPlocs = plocs; - n = sub(*num_plocs, 1); /* -1 so as to exclude the very last peak. */ + n = sub( *num_plocs, 1 ); /* -1 so as to exclude the very last peak. */ /* Special case-- The very 1st peak if it is at 0 index position */ - IF(EQ_16(*pPlocs, 0)) /* Only the very 1st peak is possible the peak at 0 index position. */ + IF( EQ_16( *pPlocs, 0 ) ) /* Only the very 1st peak is possible the peak at 0 index position. */ { - fraction = imax_fx(xfp, -1); /* -1 signifies special left edge case. */ - acc = L_deposit_h(*pPlocs++); /* N.B., (*pPlocs) must be zero here. */ - *pPlocsi++ = L_mac(acc, fraction, 1); - move32();/* in Q16 */ - n = sub(n, 1); /* This special case is taken care of-- one less to go */ + fraction = imax_fx( xfp, -1 ); /* -1 signifies special left edge case. */ + acc = L_deposit_h( *pPlocs++ ); /* N.B., (*pPlocs) must be zero here. */ + *pPlocsi++ = L_mac( acc, fraction, 1 ); + move32(); /* in Q16 */ + n = sub( n, 1 ); /* This special case is taken care of-- one less to go */ } /* All peaks except the very last peak but including the very 1st one if it has not been taken care of. */ pXfp1 = xfp - 1; - FOR(m = 0; m < n; m++) /* Loop through up to the last but one peak. (The last one is excluded.) */ + FOR( m = 0; m < n; m++ ) /* Loop through up to the last but one peak. (The last one is excluded.) */ { pXfp = pXfp1 + *pPlocs; - fraction = imax_fx(pXfp, 0); /* in Q15 */ - acc = L_deposit_h(*pPlocs++); - *pPlocsi++ = L_mac(acc, fraction, 1); - move32();/* in Q16. Append the fractional part to the integral part. */ + fraction = imax_fx( pXfp, 0 ); /* in Q15 */ + acc = L_deposit_h( *pPlocs++ ); + *pPlocsi++ = L_mac( acc, fraction, 1 ); + move32(); /* in Q16. Append the fractional part to the integral part. */ } - IF(n >= 0) + IF( n >= 0 ) { /* Special case-- The very last peak */ pXfp = pXfp1 + *pPlocs; - IF(EQ_16(*pPlocs, Lprot2)) /* Only the very last peak is possible the peak at Lprot2 index position. */ + IF( EQ_16( *pPlocs, Lprot2 ) ) /* Only the very last peak is possible the peak at Lprot2 index position. */ { - pXfp--; /* Special case needs extra decrement */ - special = 1; /* Signify special right edge case. */ move16(); + pXfp--; /* Special case needs extra decrement */ + special = 1; /* Signify special right edge case. */ + move16(); } ELSE { special = 0; move16(); } - fraction = imax_fx(pXfp, special); /* in Q15 */ - acc = L_deposit_h(*pPlocs); - *pPlocsi = L_mac(acc, fraction, 1); - move32();/* in Q16. Append the fractional part to the integral part. */ + fraction = imax_fx( pXfp, special ); /* in Q15 */ + acc = L_deposit_h( *pPlocs ); + *pPlocsi = L_mac( acc, fraction, 1 ); + move32(); /* in Q16. Append the fractional part to the integral part. */ } } #ifdef IVAS_FEC_ECU_TO_COMPLETE @@ -1994,16 +2035,16 @@ static void spec_ana_fx( /* Special case-- The very 1st peak if it is at 0 index position (DC) */ /* With DELTA_CORR_F0_INT == 2 one needs to handle both *pPlocs==0 and *pPlocs==1 */ - if (n > 0 && *pPlocs == 0) /* Very 1st peak position possible to have a peak at 0/DC index position. */ + if ( n > 0 && *pPlocs == 0 ) /* Very 1st peak position possible to have a peak at 0/DC index position. */ { - *pPlocsi++ = *pPlocs + imax_pos(&xfp[*pPlocs]); + *pPlocsi++ = *pPlocs + imax_pos( &xfp[*pPlocs] ); pPlocs++; n = n - 1; } - if (n > 0 && *pPlocs == 1) /* Also 2nd peak position uses DC which makes jacobsen unsuitable. */ + if ( n > 0 && *pPlocs == 1 ) /* Also 2nd peak position uses DC which makes jacobsen unsuitable. */ { - *pPlocsi++ = *pPlocs - 1 + imax_pos(&xfp[*pPlocs - 1]); + *pPlocsi++ = *pPlocs - 1 + imax_pos( &xfp[*pPlocs - 1] ); currPlocs = *pPlocs++; n = n - 1; } @@ -2013,17 +2054,17 @@ static void spec_ana_fx( endPlocs = Lprot2p1 - DELTA_CORR_F0_INT; /* last *pPlocs position for Jacobsen */ /* precompute number of turns based on endpoint integer location and make into a proper for loop */ - if (n > 0) + if ( n > 0 ) { nJacob = n; - if (sub(endPlocs, plocs[sub(*num_plocs, 1)]) <= 0) + if ( sub( endPlocs, plocs[sub( *num_plocs, 1 )] ) <= 0 ) { - nJacob = sub(nJacob, 1); + nJacob = sub( nJacob, 1 ); } - for (k = 0; k < nJacob; k++) + for ( k = 0; k < nJacob; k++ ) { - *pPlocsi++ = currPlocs + imax2_jacobsen_mag(&(X_sav[currPlocs - 1]), &(X_sav[Lprot - 1 - currPlocs])); + *pPlocsi++ = currPlocs + imax2_jacobsen_mag( &( X_sav[currPlocs - 1] ), &( X_sav[Lprot - 1 - currPlocs] ) ); currPlocs = *pPlocs++; } n = n - nJacob; @@ -2031,15 +2072,15 @@ static void spec_ana_fx( /* At this point there should at most two plocs left to process */ /* the position before fs/2 and fs/2 both use the same magnitude points */ - if (n > 0) + if ( n > 0 ) { /* [ . . . . . . . ] Lprot/2+1 positions */ /* | | | */ /* 0 (Lprot/2-2) (Lprot/2) */ - if (currPlocs == (Lprot2p1 - DELTA_CORR_F0_INT)) /* Also 2nd last peak position uses fs/2 which makes jacobsen less suitable. */ + if ( currPlocs == ( Lprot2p1 - DELTA_CORR_F0_INT ) ) /* Also 2nd last peak position uses fs/2 which makes jacobsen less suitable. */ { - *pPlocsi++ = currPlocs - 1 + imax_pos(&xfp[currPlocs - 1]); + *pPlocsi++ = currPlocs - 1 + imax_pos( &xfp[currPlocs - 1] ); currPlocs = *pPlocs++; n = n - 1; } @@ -2047,30 +2088,30 @@ static void spec_ana_fx( /* Here the only remaining point would be a fs/2 plocs */ /* pXfp = xfp + sub(Lprot2,1); already set just a reminder where it * whould point */ - if (n > 0) /* fs/2 which makes special case . */ + if ( n > 0 ) /* fs/2 which makes special case . */ { - *pPlocsi++ = currPlocs - 2 + imax_pos(&xfp[currPlocs - 2]); + *pPlocsi++ = currPlocs - 2 + imax_pos( &xfp[currPlocs - 2] ); currPlocs = *pPlocs++; n = n - 1; } } /* For few peaks decide noise floor attenuation */ - if (*num_plocs < 3 && *num_plocs > 0) + if ( *num_plocs < 3 && *num_plocs > 0 ) { - sig = sum_f(xfp, Lprot2_1) + EPSILON; + sig = sum_f( xfp, Lprot2_1 ) + EPSILON; /*excluding peaks and neighboring bins*/ - for (i = 0; i < *num_plocs; i++) + for ( i = 0; i < *num_plocs; i++ ) { - st_point = max(0, plocs[i] - DELTA_CORR); - end_point = min(Lprot2_1 - 1, plocs[i] + DELTA_CORR); - set_f(&xfp[st_point], 0.0f, end_point - st_point + 1); + st_point = max( 0, plocs[i] - DELTA_CORR ); + end_point = min( Lprot2_1 - 1, plocs[i] + DELTA_CORR ); + set_f( &xfp[st_point], 0.0f, end_point - st_point + 1 ); } - noise = sum_f(xfp, Lprot2_1) + EPSILON; + noise = sum_f( xfp, Lprot2_1 ) + EPSILON; nsr = noise / sig; - if (nsr < 0.03f) + if ( nsr < 0.03f ) { *noise_fac = 0.5f; } @@ -2084,10 +2125,10 @@ static void spec_ana_fx( } /*-------------------------------------------------------------------* -* subst_spec_fx() -* -* Substitution spectrum calculation -*-------------------------------------------------------------------*/ + * subst_spec_fx() + * + * Substitution spectrum calculation + *-------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED static void ivas_subst_spec_fx( @@ -2180,7 +2221,7 @@ static void ivas_subst_spec_fx( FOR( m = 0; m < *num_plocs; m++ ) { Mpy_32_16_ss( *pPlocsi++, tmp, &acc, &lsb ); /* plocsi[] in Q16, tmp in Q10 and tmp does not include 2*PI. */ - acc = L_add( L_shl( acc, 5 ), lshr( (Word16)lsb, 11 ) ); + acc = L_add( L_shl( acc, 5 ), lshr( (Word16) lsb, 11 ) ); *pCorrPhase++ = acc; /* in Q16. 2*PI is not included. */ move32(); } @@ -2484,24 +2525,25 @@ static void ivas_subst_spec_fx( #endif static void subst_spec_fx( - const Word16 *plocs, /* i : The indices of the identified peaks Q0 */ - const Word32 *plocsi, /* i : Interpolated positions of the identified peaks Q16 */ - Word16 *num_plocs, /* i/o : Number of identified peaks Q0 */ - const Word16 time_offs, /* i : Time offset Q0 */ - Word16 *X, /* i/o : FFT spectrum */ - const Word16 *mag_chg, /* i : Magnitude modification Q15 */ - const Word16 ph_dith, /* i : Phase dither, 2*PI is not included. (Q15, i.e., between 0.0 and 1.0) */ - const Word16 *is_trans, /* i : Transient flags (either 0 or 1) */ - const Word16 output_frame, /* i : Frame length Q0 */ - Word16 *seed, /* i/o : Random seed */ - const Word16 *alpha, /* i : Magnitude modification factors for fade to average Q15 */ - const Word16 *beta, /* i : Magnitude modification factors for fade to average Q15 */ - Word16 beta_mute, /* i : Factor for long-term mute Q15 */ - const Word16 *Xavg /* i : Frequency group averages to fade to Q0 */ + const Word16 *plocs, /* i : The indices of the identified peaks Q0 */ + const Word32 *plocsi, /* i : Interpolated positions of the identified peaks Q16 */ + Word16 *num_plocs, /* i/o : Number of identified peaks Q0 */ + const Word16 time_offs, /* i : Time offset Q0 */ + Word16 *X, /* i/o : FFT spectrum */ + const Word16 *mag_chg, /* i : Magnitude modification Q15 */ + const Word16 ph_dith, /* i : Phase dither, 2*PI is not included. (Q15, i.e., between 0.0 and 1.0) */ + const Word16 *is_trans, /* i : Transient flags (either 0 or 1) */ + const Word16 output_frame, /* i : Frame length Q0 */ + Word16 *seed, /* i/o : Random seed */ + const Word16 *alpha, /* i : Magnitude modification factors for fade to average Q15 */ + const Word16 *beta, /* i : Magnitude modification factors for fade to average Q15 */ + Word16 beta_mute, /* i : Factor for long-term mute Q15 */ + const Word16 *Xavg /* i : Frequency group averages to fade to Q0 */ #ifdef IVAS_FEC_ECU_TO_COMPLETE - ,const Word16 element_mode, /* i : IVAS element mode */ + , + const Word16 element_mode, /* i : IVAS element mode */ const Word16 ph_ecu_lookahead, /* i : Phase ECU lookahead */ - const Word16 noise_fac /* i : noise factor */ + const Word16 noise_fac /* i : noise factor */ #endif ) { @@ -2528,108 +2570,118 @@ static void subst_spec_fx( Word16 alpha_local; Word16 beta_local; #endif - Word16 mag_chg_local; /*for peak attenuation in burst */ + Word16 mag_chg_local; /*for peak attenuation in burst */ Lprot = 512; move16(); Lprot_inv = 8192; move16(); - Lecu = shl(output_frame, 1); + Lecu = shl( output_frame, 1 ); - IF (EQ_16(output_frame, L_FRAME48k)) + IF( EQ_16( output_frame, L_FRAME48k ) ) { - Lprot = L_PROT48k; /* 1536=(2*output_frame)*1024/1280; */ move16(); - Lprot_inv = 2731; /* Q22 */ move16(); + Lprot = L_PROT48k; /* 1536=(2*output_frame)*1024/1280; */ + move16(); + Lprot_inv = 2731; /* Q22 */ + move16(); } - ELSE IF (EQ_16(output_frame, L_FRAME32k)) + ELSE IF( EQ_16( output_frame, L_FRAME32k ) ) { - Lprot = L_PROT32k; /* 1024 */ move16(); - Lprot_inv = 4096; /* Q22 */ move16(); + Lprot = L_PROT32k; /* 1024 */ + move16(); + Lprot_inv = 4096; /* Q22 */ + move16(); } ELSE { Lprot = 512; move16(); - Lprot_inv = 8192; /* Q22 */ move16(); + Lprot_inv = 8192; /* Q22 */ + move16(); } /* Correction phase of the identified peaks */ - IF (s_or(is_trans[0], is_trans[1]) != 0) + IF( s_or( is_trans[0], is_trans[1] ) != 0 ) { *num_plocs = 0; move16(); } ELSE { - tmp = NS2SA(output_frame*50,PH_ECU_ALDO_OLP2_NS-PH_ECU_LOOKAHEAD_NS); - tmp = add(tmp, sub(Lecu, shr(sub(Lecu, Lprot), 1))); - tmp = sub(tmp, shr(output_frame, 1)); - tmp = add(tmp, time_offs); - tmp = round_fx(L_shl(L_mult0(tmp, Lprot_inv), 4)); /* 0+22+4-16=10 */ + tmp = NS2SA( output_frame * 50, PH_ECU_ALDO_OLP2_NS - PH_ECU_LOOKAHEAD_NS ); + tmp = add( tmp, sub( Lecu, shr( sub( Lecu, Lprot ), 1 ) ) ); + tmp = sub( tmp, shr( output_frame, 1 ) ); + tmp = add( tmp, time_offs ); + tmp = round_fx( L_shl( L_mult0( tmp, Lprot_inv ), 4 ) ); /* 0+22+4-16=10 */ pPlocsi = plocsi; pCorrPhase = corr_phase; - FOR (m = 0; m < *num_plocs; m++) + FOR( m = 0; m < *num_plocs; m++ ) { - Mpy_32_16_ss(*pPlocsi++, tmp, &acc, &lsb); /* plocsi[] in Q16, tmp in Q10 and tmp does not include 2*PI. */ - acc = L_add(L_shl(acc, 5), lshr(lsb, 11)); - *pCorrPhase++ = acc; /* in Q16. 2*PI is not included. */ move32(); + Mpy_32_16_ss( *pPlocsi++, tmp, &acc, &lsb ); /* plocsi[] in Q16, tmp in Q10 and tmp does not include 2*PI. */ + acc = L_add( L_shl( acc, 5 ), lshr( lsb, 11 ) ); + *pCorrPhase++ = acc; /* in Q16. 2*PI is not included. */ + move32(); } } #ifdef IVAS_FEC_ECU_TO_COMPLETE one_peak_flag_mask = 1; /* all ones mask -> keep */ - IF(NE_16(element_mode, EVS_MONO)) + IF( NE_16( element_mode, EVS_MONO ) ) { - if ((*num_plocs > 0) && sub(*num_plocs, 3) < 0) + if ( ( *num_plocs > 0 ) && sub( *num_plocs, 3 ) < 0 ) { one_peak_flag_mask = noise_fac; /* all zeroes mask -> zero */ } - if (*num_plocs == 0) + if ( *num_plocs == 0 ) { X[0] = 0; /* reset DC if there are no peaks */ - X[shr(Lprot, 1)] = 0; /* also reset fs/2 if there are no peaks */ + X[shr( Lprot, 1 )] = 0; /* also reset fs/2 if there are no peaks */ } } #endif - lprotBy2Minus1 = sub(shr(Lprot, 1), 1); + lprotBy2Minus1 = sub( shr( Lprot, 1 ), 1 ); i = 1; move16(); k = 0; move16(); - im_ind = sub(Lprot, 1); + im_ind = sub( Lprot, 1 ); + move16(); + pReX = X + i; + pImX = X + im_ind; + pPlocs = plocs; + pCorrPhase = corr_phase; + pkLocation = *pPlocs; /* N.B. No post-increment */ move16(); - pReX = X + i; - pImX = X + im_ind; - pPlocs = plocs; - pCorrPhase = corr_phase; - pkLocation = *pPlocs; /* N.B. No post-increment */ move16(); pkLocation1 = *pPlocs++; move16(); - lastPeak = sub(*num_plocs, 1); - FOR (m = 0; m < *num_plocs; m++) + lastPeak = sub( *num_plocs, 1 ); + FOR( m = 0; m < *num_plocs; m++ ) { delta_corr_dn = DELTA_CORR; move16(); delta_corr_up = DELTA_CORR; move16(); - pkLocation_1 = pkLocation; /* plocs[m - 1] */ move16(); - pkLocation = pkLocation1; /* plocs[m] */ move16(); - pkLocation1 = *pPlocs++; /* plocs[m + 1] */ move16(); - IF (m > 0) + pkLocation_1 = pkLocation; /* plocs[m - 1] */ + move16(); + pkLocation = pkLocation1; /* plocs[m] */ + move16(); + pkLocation1 = *pPlocs++; /* plocs[m + 1] */ + move16(); + IF( m > 0 ) { - delta_tmp = shr(sub(sub(pkLocation, pkLocation_1), 1), 1); - if (LT_16(delta_tmp, DELTA_CORR)) + delta_tmp = shr( sub( sub( pkLocation, pkLocation_1 ), 1 ), 1 ); + if ( LT_16( delta_tmp, DELTA_CORR ) ) { delta_corr_dn = delta_tmp; move16(); } } - IF (LT_16(m, lastPeak)) + IF( LT_16( m, lastPeak ) ) { - delta_tmp = shr(sub(sub(pkLocation1, pkLocation), 1), 1); - if (LT_16(delta_tmp, DELTA_CORR )) + delta_tmp = shr( sub( sub( pkLocation1, pkLocation ), 1 ), 1 ); + if ( LT_16( delta_tmp, DELTA_CORR ) ) { delta_corr_up = delta_tmp; move16(); @@ -2637,73 +2689,73 @@ static void subst_spec_fx( } /* Input Xph */ - segmentLen = sub(sub(pkLocation, delta_corr_dn), i); + segmentLen = sub( sub( pkLocation, delta_corr_dn ), i ); /* i = add(i, segmentLen); */ - FOR (j = 0; j < segmentLen; j++) + FOR( j = 0; j < segmentLen; j++ ) { - *seed = rand_phase_fx(*seed, &sin_F, &cos_F); + *seed = rand_phase_fx( *seed, &sin_F, &cos_F ); re = *pReX; move16(); im = *pImX; move16(); #ifdef IVAS_FEC_ECU_TO_COMPLETE - IF(EQ_16(element_mode, EVS_MONO)) + IF( EQ_16( element_mode, EVS_MONO ) ) #endif { - tmp = sub(mult_r(re, cos_F), mult_r(im, sin_F)); - im = add(mult_r(re, sin_F), mult_r(im, cos_F)); + tmp = sub( mult_r( re, cos_F ), mult_r( im, sin_F ) ); + im = add( mult_r( re, sin_F ), mult_r( im, cos_F ) ); } #ifdef IVAS_FEC_ECU_TO_COMPLETE ELSE { PMTE() - //tmp = one_peak_flag_mask * (X[i] * cos_F - X[im_ind] * sin_F); - //X[im_ind] = one_peak_flag_mask * (X[i] * sin_F + X[im_ind] * cos_F); + // tmp = one_peak_flag_mask * (X[i] * cos_F - X[im_ind] * sin_F); + // X[im_ind] = one_peak_flag_mask * (X[i] * sin_F + X[im_ind] * cos_F); } #endif - IF (LT_16(alpha[k], 32766)) + IF( LT_16( alpha[k], 32766 ) ) { - *seed = rand_phase_fx(*seed, &sin_F, &cos_F); - tmp2 = mult_r(beta[k], Xavg[k]); - *pReX++ = add( mult_r(alpha[k], tmp), mult_r(tmp2, cos_F) ); + *seed = rand_phase_fx( *seed, &sin_F, &cos_F ); + tmp2 = mult_r( beta[k], Xavg[k] ); + *pReX++ = add( mult_r( alpha[k], tmp ), mult_r( tmp2, cos_F ) ); move16(); - *pImX-- = add( mult_r(alpha[k], im), mult_r(tmp2, sin_F) ); + *pImX-- = add( mult_r( alpha[k], im ), mult_r( tmp2, sin_F ) ); move16(); } ELSE { - *pReX++ = mult_r(mag_chg[k], tmp); + *pReX++ = mult_r( mag_chg[k], tmp ); move16(); - *pImX-- = mult_r(mag_chg[k], im); + *pImX-- = mult_r( mag_chg[k], im ); move16(); } - i = add(i, 1); - if (GE_16(i, ivas_gwlpr[k+1])) + i = add( i, 1 ); + if ( GE_16( i, ivas_gwlpr[k + 1] ) ) { - k = add(k, 1); + k = add( k, 1 ); } } - e = add(pkLocation, delta_corr_up); - if (GT_16(e, lprotBy2Minus1)) + e = add( pkLocation, delta_corr_up ); + if ( GT_16( e, lprotBy2Minus1 ) ) { e = lprotBy2Minus1; move16(); } Xph = *pCorrPhase; - Xph_short = s_and(extract_l(L_shr(Xph, 16 - 10)), 0x3ff); /* 10 bits precision after radix point */ - IF (GE_16(Xph_short, 512)) + Xph_short = s_and( extract_l( L_shr( Xph, 16 - 10 ) ), 0x3ff ); /* 10 bits precision after radix point */ + IF( GE_16( Xph_short, 512 ) ) { - sin_F = negate(sincos_t_ext_fx[Xph_short - 512]); - IF (LT_16(Xph_short, 768)) + sin_F = negate( sincos_t_ext_fx[Xph_short - 512] ); + IF( LT_16( Xph_short, 768 ) ) { - cos_F = negate(sincos_t_ext_fx[Xph_short - (512 - 256)]); + cos_F = negate( sincos_t_ext_fx[Xph_short - ( 512 - 256 )] ); } ELSE { - cos_F = sincos_t_ext_fx[-Xph_short + (1024 + 256)]; + cos_F = sincos_t_ext_fx[-Xph_short + ( 1024 + 256 )]; move16(); } } @@ -2711,47 +2763,47 @@ static void subst_spec_fx( { sin_F = sincos_t_ext_fx[Xph_short]; move16(); - IF (LT_16(Xph_short, 256)) + IF( LT_16( Xph_short, 256 ) ) { cos_F = sincos_t_ext_fx[Xph_short + 256]; move16(); } ELSE { - cos_F = negate(sincos_t_ext_fx[-Xph_short + (256 + 512)]); + cos_F = negate( sincos_t_ext_fx[-Xph_short + ( 256 + 512 )] ); } } - segmentLen = add(sub(e, i), 1); + segmentLen = add( sub( e, i ), 1 ); /* i = add(i, segmentLen); */ - FOR (j = 0; j < segmentLen; j++ ) + FOR( j = 0; j < segmentLen; j++ ) { mag_chg_local = mag_chg[k]; move16(); - IF (ph_dith != 0 ) + IF( ph_dith != 0 ) { - Xph = *pCorrPhase; /* in Q16. 2*PI is not included. */ - *seed = own_random2_fx(*seed); /* in Q0 */ - acc = L_mult(*seed, ph_dith); /* N.B. ph_dith[i] is in Q15, i.e., in between 0 and 1.0 (2*PI not included) */ - acc = L_shr(acc, PHASE_DITH_SCALE_SHIFT); - Xph = L_add(Xph, acc); /* in Q16. */ + Xph = *pCorrPhase; /* in Q16. 2*PI is not included. */ + *seed = own_random2_fx( *seed ); /* in Q0 */ + acc = L_mult( *seed, ph_dith ); /* N.B. ph_dith[i] is in Q15, i.e., in between 0 and 1.0 (2*PI not included) */ + acc = L_shr( acc, PHASE_DITH_SCALE_SHIFT ); + Xph = L_add( Xph, acc ); /* in Q16. */ - IF (ph_dith > 0 ) /* up to 6 dB additional att of peaks in non_transient longer bursts, (when peak phase is randomized ) */ + IF( ph_dith > 0 ) /* up to 6 dB additional att of peaks in non_transient longer bursts, (when peak phase is randomized ) */ { /* mag_chg_local *= 0.5 + (1.0 - ph_dith[i])/2 where 0.5~= sqrt((float)pow(10.0,-6/10.0)) and ph_dith=0..1.0--> scale=1.0 ...5 */ - mag_chg_local = mult_r(mag_chg_local, sub(32767, shr(ph_dith, 1))); + mag_chg_local = mult_r( mag_chg_local, sub( 32767, shr( ph_dith, 1 ) ) ); } - Xph_short = s_and(extract_l(L_shr(Xph, 16 - 10)), 0x3ff); - IF (GE_16(Xph_short, 512)) + Xph_short = s_and( extract_l( L_shr( Xph, 16 - 10 ) ), 0x3ff ); + IF( GE_16( Xph_short, 512 ) ) { - sin_F = negate(sincos_t_ext_fx[Xph_short - 512]); - IF (LT_16(Xph_short, 768)) + sin_F = negate( sincos_t_ext_fx[Xph_short - 512] ); + IF( LT_16( Xph_short, 768 ) ) { - cos_F = negate(sincos_t_ext_fx[Xph_short - (512 - 256)]); + cos_F = negate( sincos_t_ext_fx[Xph_short - ( 512 - 256 )] ); } ELSE { - cos_F = sincos_t_ext_fx[-Xph_short + (1024 + 256)]; + cos_F = sincos_t_ext_fx[-Xph_short + ( 1024 + 256 )]; move16(); } } @@ -2759,14 +2811,14 @@ static void subst_spec_fx( { sin_F = sincos_t_ext_fx[Xph_short]; move16(); - IF (LT_16(Xph_short, 256)) + IF( LT_16( Xph_short, 256 ) ) { cos_F = sincos_t_ext_fx[Xph_short + 256]; move16(); } ELSE { - cos_F = negate(sincos_t_ext_fx[-Xph_short + (256 + 512)]); + cos_F = negate( sincos_t_ext_fx[-Xph_short + ( 256 + 512 )] ); } } } @@ -2776,105 +2828,105 @@ static void subst_spec_fx( im = *pImX; move16(); #ifdef IVAS_FEC_ECU_TO_COMPLETE - IF(EQ_16(element_mode, EVS_MONO)) + IF( EQ_16( element_mode, EVS_MONO ) ) #endif { #ifdef BASOP_NOGLOB tmp = sub_sat( mult_r( re, cos_F ), mult_r( im, sin_F ) ); - im = add_sat(mult_r(re, sin_F), mult_r(im, cos_F)); + im = add_sat( mult_r( re, sin_F ), mult_r( im, cos_F ) ); #else - tmp = sub(mult_r(re, cos_F), mult_r(im, sin_F)); - im = add(mult_r(re, sin_F), mult_r(im, cos_F)); + tmp = sub( mult_r( re, cos_F ), mult_r( im, sin_F ) ); + im = add( mult_r( re, sin_F ), mult_r( im, cos_F ) ); #endif } #ifdef IVAS_FEC_ECU_TO_COMPLETE ELSE { PMTE() - //tmp = one_peak_flag_mask * (X[i] * cos_F - X[im_ind] * sin_F); - //X[im_ind] = one_peak_flag_mask * (X[i] * sin_F + X[im_ind] * cos_F); + // tmp = one_peak_flag_mask * (X[i] * cos_F - X[im_ind] * sin_F); + // X[im_ind] = one_peak_flag_mask * (X[i] * sin_F + X[im_ind] * cos_F); } #endif - IF (LT_16(alpha[k], 32766)) + IF( LT_16( alpha[k], 32766 ) ) { alpha_local = mag_chg_local; move16(); - acc = L_sub(1073741824L, L_mult0(alpha_local, alpha_local)); - acc = Sqrt_l(acc, &expo); - expo = add(30, add(31, expo)); - if (EQ_16(s_and(expo, 1), 1)) + acc = L_sub( 1073741824L, L_mult0( alpha_local, alpha_local ) ); + acc = Sqrt_l( acc, &expo ); + expo = add( 30, add( 31, expo ) ); + if ( EQ_16( s_and( expo, 1 ), 1 ) ) { - acc = Mult_32_16(acc, 23170); /* 1/sqrt(2) in Q15 */ + acc = Mult_32_16( acc, 23170 ); /* 1/sqrt(2) in Q15 */ } - expo = shr(expo, 1); - beta_local = mult_r(beta_mute, round_fx(L_shl(acc, sub(31, expo)))); + expo = shr( expo, 1 ); + beta_local = mult_r( beta_mute, round_fx( L_shl( acc, sub( 31, expo ) ) ) ); - IF (GE_16(k, LGW32K-1)) + IF( GE_16( k, LGW32K - 1 ) ) { - beta_local = mult_r(beta_local, 3277); /* 0.1 in Q15 */ + beta_local = mult_r( beta_local, 3277 ); /* 0.1 in Q15 */ } - ELSE if (GE_16(k, LGW16K-1)) + ELSE if ( GE_16( k, LGW16K - 1 ) ) { - beta_local = mult_r(beta_local, 16384); /* 0.5 in Q15 */ + beta_local = mult_r( beta_local, 16384 ); /* 0.5 in Q15 */ } - *seed = rand_phase_fx(*seed, &sin_F, &cos_F); - tmp2 = mult_r(beta_local, Xavg[k]); - *pReX++ = add( mult_r(alpha_local, tmp), mult_r(tmp2, cos_F) ); + *seed = rand_phase_fx( *seed, &sin_F, &cos_F ); + tmp2 = mult_r( beta_local, Xavg[k] ); + *pReX++ = add( mult_r( alpha_local, tmp ), mult_r( tmp2, cos_F ) ); move16(); - *pImX-- = add( mult_r(alpha_local, im), mult_r(tmp2, sin_F) ); + *pImX-- = add( mult_r( alpha_local, im ), mult_r( tmp2, sin_F ) ); move16(); } ELSE { - *pReX++ = mult_r(mag_chg_local, tmp); + *pReX++ = mult_r( mag_chg_local, tmp ); move16(); - *pImX-- = mult_r(mag_chg_local, im); + *pImX-- = mult_r( mag_chg_local, im ); move16(); } - i = add(i, 1); - if (GE_16(i, ivas_gwlpr[k+1])) + i = add( i, 1 ); + if ( GE_16( i, ivas_gwlpr[k + 1] ) ) { - k = add(k, 1); + k = add( k, 1 ); } } pCorrPhase++; } - segmentLen = sub(shr(Lprot,1), i); - FOR (j = 0; j < segmentLen; j++) + segmentLen = sub( shr( Lprot, 1 ), i ); + FOR( j = 0; j < segmentLen; j++ ) { - *seed = rand_phase_fx(*seed, &sin_F, &cos_F); + *seed = rand_phase_fx( *seed, &sin_F, &cos_F ); re = *pReX; move16(); im = *pImX; move16(); - tmp = sub(mult_r(re, cos_F), mult_r(im, sin_F)); - im = add(mult_r(re, sin_F), mult_r(im, cos_F)); - IF (LT_16(alpha[k], 32766)) + tmp = sub( mult_r( re, cos_F ), mult_r( im, sin_F ) ); + im = add( mult_r( re, sin_F ), mult_r( im, cos_F ) ); + IF( LT_16( alpha[k], 32766 ) ) { - *seed = rand_phase_fx(*seed, &sin_F, &cos_F); - tmp2 = mult_r(beta[k], Xavg[k]); - *pReX++ = add( mult_r(alpha[k], tmp), mult_r(tmp2, cos_F) ); + *seed = rand_phase_fx( *seed, &sin_F, &cos_F ); + tmp2 = mult_r( beta[k], Xavg[k] ); + *pReX++ = add( mult_r( alpha[k], tmp ), mult_r( tmp2, cos_F ) ); move16(); - *pImX-- = add( mult_r(alpha[k], im), mult_r(tmp2, sin_F) ); + *pImX-- = add( mult_r( alpha[k], im ), mult_r( tmp2, sin_F ) ); move16(); } ELSE { - *pReX++ = mult_r(mag_chg[k], tmp); + *pReX++ = mult_r( mag_chg[k], tmp ); move16(); - *pImX-- = mult_r(mag_chg[k], im); + *pImX-- = mult_r( mag_chg[k], im ); move16(); } - i = add(i, 1); - if (GE_16(i, ivas_gwlpr[k+1])) + i = add( i, 1 ); + if ( GE_16( i, ivas_gwlpr[k + 1] ) ) { - k = add(k, 1); + k = add( k, 1 ); } } } @@ -3022,16 +3074,15 @@ static void ivas_rec_wtda_fx( #endif static void rec_wtda_fx( - Word16 *X, /* i : FFT spectrum */ - Word32 *ecu_rec, /* o : Reconstructed frame in tda domain */ - const Word16 output_frame, /* i : Frame length */ - const Word16 Lprot, /* i : Prototype frame length */ - const Word32 fs -) + Word16 *X, /* i : FFT spectrum */ + Word32 *ecu_rec, /* o : Reconstructed frame in tda domain */ + const Word16 output_frame, /* i : Frame length */ + const Word16 Lprot, /* i : Prototype frame length */ + const Word32 fs ) { Word16 l, Lprot2, timesh; - Word16 rec_buf[3*L_FRAME48k]; - Word16 *xsubst_,*out_ptr; + Word16 rec_buf[3 * L_FRAME48k]; + Word16 *xsubst_, *out_ptr; Word16 Qin; Word16 xf_len; Word16 i, idx; @@ -3040,26 +3091,26 @@ static void rec_wtda_fx( Word16 tbl_delta; #ifdef IVAS_FEC_ECU_TO_COMPLETE float xsubst_[2 * L_FRAME48k]; - const float* w_hamm; - float* pX_start, * pX_end; + const float *w_hamm; + float *pX_start, *pX_end; float tmp; int16_t hamm_len2; - float* pNew; - const float* pOldW, * pNewW; - float xfwin[NS2SA(L_FRAME48k * FRAMES_PER_SEC, N_ZERO_MDCT_NS - (2 * FRAME_SIZE_NS - L_PROT_NS) / 2)]; - const float* pOld; + float *pNew; + const float *pOldW, *pNewW; + float xfwin[NS2SA( L_FRAME48k * FRAMES_PER_SEC, N_ZERO_MDCT_NS - ( 2 * FRAME_SIZE_NS - L_PROT_NS ) / 2 )]; + const float *pOld; int16_t copy_len; int16_t ola_len; - copy_len = NS2SA(output_frame * FRAMES_PER_SEC, (2 * FRAME_SIZE_NS - L_PROT_NS) / 2); /* prototype fill on each side of xsubst to fill MDCT Frame */ - ola_len = NS2SA(output_frame * FRAMES_PER_SEC, N_ZERO_MDCT_NS - (2 * FRAME_SIZE_NS - L_PROT_NS) / 2); /* remaining lengt of LA_ZEROS to overlap add decoded with xsubst */ + copy_len = NS2SA( output_frame * FRAMES_PER_SEC, ( 2 * FRAME_SIZE_NS - L_PROT_NS ) / 2 ); /* prototype fill on each side of xsubst to fill MDCT Frame */ + ola_len = NS2SA( output_frame * FRAMES_PER_SEC, N_ZERO_MDCT_NS - ( 2 * FRAME_SIZE_NS - L_PROT_NS ) / 2 ); /* remaining lengt of LA_ZEROS to overlap add decoded with xsubst */ - if (output_frame == L_FRAME48k) + if ( output_frame == L_FRAME48k ) { w_hamm = w_hamm_sana48k_2; hamm_len2 = L_PROT_HAMM_LEN2_48k; } - else if (output_frame == L_FRAME32k) + else if ( output_frame == L_FRAME32k ) { w_hamm = w_hamm_sana32k_2; hamm_len2 = L_PROT_HAMM_LEN2_32k; @@ -3070,12 +3121,12 @@ static void rec_wtda_fx( hamm_len2 = L_PROT_HAMM_LEN2_16k; } - if (element_mode != EVS_MONO && *num_p > 0 && plocs[0] > 3) + if ( element_mode != EVS_MONO && *num_p > 0 && plocs[0] > 3 ) { /* Perform inverse windowing of hammrect */ pX_start = X; pX_end = X + Lprot - 1; - for (i = 0; i < hamm_len2; i++) + for ( i = 0; i < hamm_len2; i++ ) { tmp = 1.0f / *w_hamm; *pX_start *= tmp; @@ -3087,22 +3138,22 @@ static void rec_wtda_fx( } /* extract reconstructed frame with aldo window */ - timesh = NS2SA(output_frame * FRAMES_PER_SEC, N_ZERO_MDCT_NS) - (2 * output_frame - Lprot) / 2; + timesh = NS2SA( output_frame * FRAMES_PER_SEC, N_ZERO_MDCT_NS ) - ( 2 * output_frame - Lprot ) / 2; - set_f(xsubst_, 0.0f, 2 * output_frame - Lprot + timesh); - mvr2r(X, xsubst_ + 2 * output_frame - Lprot + timesh, Lprot - timesh); + set_f( xsubst_, 0.0f, 2 * output_frame - Lprot + timesh ); + mvr2r( X, xsubst_ + 2 * output_frame - Lprot + timesh, Lprot - timesh ); /* Copy and OLA look ahead zero part of MDCT window from decoded signal */ - if (element_mode != EVS_MONO) + if ( element_mode != EVS_MONO ) { - mvr2r(old_dec, xsubst_ + NS2SA(output_frame * FRAMES_PER_SEC, N_ZERO_MDCT_NS), copy_len); /* also need to scale to Q0 ?? */ + mvr2r( old_dec, xsubst_ + NS2SA( output_frame * FRAMES_PER_SEC, N_ZERO_MDCT_NS ), copy_len ); /* also need to scale to Q0 ?? */ pOld = old_dec + copy_len; - pNew = xsubst_ + copy_len + NS2SA(output_frame * FRAMES_PER_SEC, N_ZERO_MDCT_NS); - sinq(EVS_PI / (ola_len * 2), 0.0f, ola_len, xfwin); - v_mult(xfwin, xfwin, xfwin, ola_len); /* xfwin = sin^2 of 0..pi/4 */ + pNew = xsubst_ + copy_len + NS2SA( output_frame * FRAMES_PER_SEC, N_ZERO_MDCT_NS ); + sinq( EVS_PI / ( ola_len * 2 ), 0.0f, ola_len, xfwin ); + v_mult( xfwin, xfwin, xfwin, ola_len ); /* xfwin = sin^2 of 0..pi/4 */ pOldW = xfwin + ola_len - 1; pNewW = xfwin; - for (i = 0; i < ola_len; i++) + for ( i = 0; i < ola_len; i++ ) { *pNew = *pOld * *pOldW + *pNew * *pNewW; pOld += 1; @@ -3114,67 +3165,70 @@ static void rec_wtda_fx( else { /* Smoothen onset of ECU frame */ - xf_len = (int16_t)((float)output_frame * N_ZERO_MDCT_NS / FRAME_SIZE_NS) - (output_frame - Lprot / 2); + xf_len = (int16_t) ( (float) output_frame * N_ZERO_MDCT_NS / FRAME_SIZE_NS ) - ( output_frame - Lprot / 2 ); p_ecu = xsubst_ + 2 * output_frame - Lprot + timesh; tbl_delta = 64.f / xf_len; /* 64 samples = 1/4 cycle in sincos_t */ - for (i = 0; i < xf_len; i++, p_ecu++) + for ( i = 0; i < xf_len; i++, p_ecu++ ) { - g = sincos_t[((int16_t)(i * tbl_delta))]; + g = sincos_t[( (int16_t) ( i * tbl_delta ) )]; g *= g; - *p_ecu = g * (*p_ecu); + *p_ecu = g * ( *p_ecu ); } } /* Apply TDA and windowing to ECU frame */ - wtda(xsubst_ + output_frame, ecu_rec, NULL, ALDO_WINDOW, ALDO_WINDOW, output_frame); + wtda( xsubst_ + output_frame, ecu_rec, NULL, ALDO_WINDOW, ALDO_WINDOW, output_frame ); #else - //PMTE() + // PMTE() xsubst_ = rec_buf + output_frame; - Lprot2 = shr(Lprot, 1); + Lprot2 = shr( Lprot, 1 ); /* Initialize to WB constants */ xf_len = 26; move16(); - tbl_delta = 10082; /* Q12 */ move16(); - IF (EQ_16(output_frame, L_FRAME48k)) + tbl_delta = 10082; /* Q12 */ + move16(); + IF( EQ_16( output_frame, L_FRAME48k ) ) { xf_len = 78; move16(); - tbl_delta = 3361; /* Q12 */ move16(); + tbl_delta = 3361; /* Q12 */ + move16(); } - ELSE IF (EQ_16(output_frame, L_FRAME32k)) + ELSE IF( EQ_16( output_frame, L_FRAME32k ) ) { xf_len = 52; move16(); - tbl_delta = 5041; /* Q12 */ move16(); + tbl_delta = 5041; /* Q12 */ + move16(); } /* extract reconstructed frame with aldo window */ - l = sub(output_frame, Lprot2); - set16_fx(xsubst_,0 , l); - Copy(X, xsubst_ + l, Lprot); - set16_fx(xsubst_ + add(output_frame, Lprot2), 0, l); + l = sub( output_frame, Lprot2 ); + set16_fx( xsubst_, 0, l ); + Copy( X, xsubst_ + l, Lprot ); + set16_fx( xsubst_ + add( output_frame, Lprot2 ), 0, l ); /* Smoothen onset of ECU frame */ - p_ecu = xsubst_ + (output_frame - Lprot2); - FOR ( i = 0; i < xf_len; i++) + p_ecu = xsubst_ + ( output_frame - Lprot2 ); + FOR( i = 0; i < xf_len; i++ ) { - idx = extract_l(L_shr(L_mult0(i, tbl_delta), 12)); + idx = extract_l( L_shr( L_mult0( i, tbl_delta ), 12 ) ); g = sincos_t_fx[idx]; - g = mult(g, g); - *p_ecu = mult(g, (*p_ecu)); + g = mult( g, g ); + *p_ecu = mult( g, ( *p_ecu ) ); move16(); p_ecu++; } - timesh = NS2SA_fx2(fs, 10000000L - PH_ECU_ALDO_OLP2_NS); + timesh = NS2SA_fx2( fs, 10000000L - PH_ECU_ALDO_OLP2_NS ); - set16_fx(rec_buf, 0, output_frame); + set16_fx( rec_buf, 0, output_frame ); Qin = 0; - out_ptr = rec_buf + sub(shl(output_frame,1), timesh); - wtda_fx(out_ptr, &Qin, ecu_rec, NULL, 0, ALDO_WINDOW, ALDO_WINDOW, /* window overlap of current frame (0: full, 2: none, or 3: half) */ - output_frame); + out_ptr = rec_buf + sub( shl( output_frame, 1 ), timesh ); + wtda_fx( out_ptr, &Qin, ecu_rec, NULL, 0, ALDO_WINDOW, ALDO_WINDOW, /* window overlap of current frame (0: full, 2: none, or 3: half) */ + output_frame ); #endif return; } @@ -3238,15 +3292,16 @@ static void ivas_rec_frame_fx( #endif static void rec_frame_fx( - Word16 *X, /* i : FFT spectrum */ - Word32 *ecu_rec, /* o : Reconstructed frame in tda domain */ - const Word16 output_frame, /* i : Frame length */ + Word16 *X, /* i : FFT spectrum */ + Word32 *ecu_rec, /* o : Reconstructed frame in tda domain */ + const Word16 output_frame, /* i : Frame length */ const Word16 Q #ifdef IVAS_FEC_ECU_TO_COMPLETE - ,const float* old_dec, /* i : end of last decoded for OLA before tda and itda */ + , + const float *old_dec, /* i : end of last decoded for OLA before tda and itda */ const int16_t element_mode, /* i : IVAS element mode */ - const int16_t* num_p, /* i : Number of peaks */ - const int16_t* plocs /* i : Peak locations */ + const int16_t *num_p, /* i : Number of peaks */ + const int16_t *plocs /* i : Peak locations */ #endif ) { @@ -3254,71 +3309,71 @@ static void rec_frame_fx( Word16 Lprot, lprotLog2Minus1; Word32 fs; - fs = L_mult0(output_frame, 50); + fs = L_mult0( output_frame, 50 ); /* Initialize to WB constants */ Lprot = 512; move16(); lprotLog2Minus1 = 9 - 1; move16(); - pFftTbl = FFT_W256; /* Table for 512-point real input FFT */ - IF (EQ_16(output_frame, L_FRAME48k)) + pFftTbl = FFT_W256; /* Table for 512-point real input FFT */ + IF( EQ_16( output_frame, L_FRAME48k ) ) { - Lprot = L_PROT48k; /* 1536 = (2*output_frame)*1024/1280 */ move16(); + Lprot = L_PROT48k; /* 1536 = (2*output_frame)*1024/1280 */ + move16(); } - ELSE IF (EQ_16(output_frame, L_FRAME32k)) + ELSE IF( EQ_16( output_frame, L_FRAME32k ) ) { - Lprot = L_PROT32k; /* 1024 */ move16(); + Lprot = L_PROT32k; /* 1024 */ + move16(); lprotLog2Minus1 = 10 - 1; move16(); - pFftTbl = FFT_W512; /* Table for 1024-point real input FFT */ + pFftTbl = FFT_W512; /* Table for 1024-point real input FFT */ } /* extend spectrum and IDFT */ - IF (EQ_16(output_frame, L_FRAME48k)) + IF( EQ_16( output_frame, L_FRAME48k ) ) { - ifft3_fx(X, X, Lprot); + ifft3_fx( X, X, Lprot ); } ELSE { - r_fft_fx_lc(pFftTbl, Lprot, shr(Lprot, 1), lprotLog2Minus1, X, X, 0); /* Inverse FFT */ + r_fft_fx_lc( pFftTbl, Lprot, shr( Lprot, 1 ), lprotLog2Minus1, X, X, 0 ); /* Inverse FFT */ } - Scale_sig(X, Lprot, -Q); + Scale_sig( X, Lprot, -Q ); - rec_wtda_fx(X, ecu_rec, output_frame, Lprot, fs); + rec_wtda_fx( X, ecu_rec, output_frame, Lprot, fs ); return; } -static -Word32 mult_32_32_q(const Word32 a, const Word32 b, const Word16 q) +static Word32 mult_32_32_q( const Word32 a, const Word32 b, const Word16 q ) { Word32 hi; UWord32 lo; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - Mpy_32_32_ss(a, b, &hi, &lo); + Mpy_32_32_ss( a, b, &hi, &lo ); #ifdef BASOP_NOGLOB - return L_or(L_shl_o(hi, 32 - q - 1, &Overflow), L_lshr(lo, q + 1)); + return L_or( L_shl_o( hi, 32 - q - 1, &Overflow ), L_lshr( lo, q + 1 ) ); #else - return L_or(L_shl(hi, 32 - q - 1), L_lshr(lo, q + 1)); + return L_or( L_shl( hi, 32 - q - 1 ), L_lshr( lo, q + 1 ) ); #endif } -static -void fir_dwn_fx( - const Word16 x[], /* i : input vector Q(x_Q) */ - const Word16 h[], /* i : impulse response of the FIR filter Q(h_Q) */ - const Word16 h_Q, /* H's Q */ - Word16 y[], /* o : output vector (result of filtering) Q~ */ - const Word16 L, /* i : input vector size */ - const Word16 K, /* i : order of the FIR filter (K+1 coefs.) */ - const Word16 decimation /* i : decimation */ +static void fir_dwn_fx( + const Word16 x[], /* i : input vector Q(x_Q) */ + const Word16 h[], /* i : impulse response of the FIR filter Q(h_Q) */ + const Word16 h_Q, /* H's Q */ + Word16 y[], /* o : output vector (result of filtering) Q~ */ + const Word16 L, /* i : input vector size */ + const Word16 K, /* i : order of the FIR filter (K+1 coefs.) */ + const Word16 decimation /* i : decimation */ ) { - Word32 s; + Word32 s; Word16 i, j; const Word16 *ptr_h, *ptr_x; Word16 *ptr_y; @@ -3326,19 +3381,19 @@ void fir_dwn_fx( Word16 centering; Word16 tmp; - centering = sub(16, h_Q); - Kdiv2 = shr(K,1); + centering = sub( 16, h_Q ); + Kdiv2 = shr( K, 1 ); ptr_y = y; /* do the filtering */ - FOR (i = Kdiv2; i < K; i+=decimation) + FOR( i = Kdiv2; i < K; i += decimation ) { - s = L_deposit_l(0); + s = L_deposit_l( 0 ); ptr_h = h + 1; ptr_x = x + i - 1; move16(); - FOR (j = 1; j <= i; j++) + FOR( j = 1; j <= i; j++ ) { #ifdef BASOP_NOGLOB s = L_mac0_sat( s, *ptr_h++, *ptr_x-- ); @@ -3348,55 +3403,55 @@ void fir_dwn_fx( } #ifdef BASOP_NOGLOB - *ptr_y++ = extract_h(L_shl_sat(s, centering)); + *ptr_y++ = extract_h( L_shl_sat( s, centering ) ); #else - *ptr_y++ = extract_h(L_shl(s, centering)); + *ptr_y++ = extract_h( L_shl( s, centering ) ); #endif } - FOR (i = K; i < L; i+=decimation) + FOR( i = K; i < L; i += decimation ) { - s = L_deposit_l(0); + s = L_deposit_l( 0 ); ptr_h = h + 1; ptr_x = x + i - 1; move16(); - FOR (j = 1; j <= K; j++) + FOR( j = 1; j <= K; j++ ) { #ifdef BASOP_NOGLOB - s = L_mac0_sat(s, *ptr_h++, *ptr_x--); + s = L_mac0_sat( s, *ptr_h++, *ptr_x-- ); #else - s = L_mac0(s, *ptr_h++, *ptr_x--); + s = L_mac0( s, *ptr_h++, *ptr_x-- ); #endif } #ifdef BASOP_NOGLOB - *ptr_y++ = extract_h(L_shl_sat(s, centering)); + *ptr_y++ = extract_h( L_shl_sat( s, centering ) ); #else - *ptr_y++ = extract_h(L_shl(s, centering)); + *ptr_y++ = extract_h( L_shl( s, centering ) ); #endif } - tmp = add(L,Kdiv2); - FOR (i = i; i < tmp; i+=decimation) + tmp = add( L, Kdiv2 ); + FOR( i = i; i < tmp; i += decimation ) { - s = L_deposit_l(0); + s = L_deposit_l( 0 ); ptr_h = h + i - L + 1; move16(); ptr_x = x + L - 1; move16(); - FOR (j = add(sub(i,L),1); j <= K; j++) + FOR( j = add( sub( i, L ), 1 ); j <= K; j++ ) { #ifdef BASOP_NOGLOB - s = L_mac0_sat(s, *ptr_h++, *ptr_x--); + s = L_mac0_sat( s, *ptr_h++, *ptr_x-- ); #else - s = L_mac0(s, *ptr_h++, *ptr_x--); + s = L_mac0( s, *ptr_h++, *ptr_x-- ); #endif } #ifdef BASOP_NOGLOB - *ptr_y++ = extract_h(L_shl_sat(s, centering)); + *ptr_y++ = extract_h( L_shl_sat( s, centering ) ); #else - *ptr_y++ = extract_h(L_shl(s, centering)); + *ptr_y++ = extract_h( L_shl( s, centering ) ); #endif } @@ -3409,224 +3464,214 @@ void fir_dwn_fx( * Pitch/correlation analysis and adaptive analysis frame length calculation *--------------------------------------------------------------------------*/ -static -void fec_ecu_pitch_fx( +static void fec_ecu_pitch_fx( const Word16 *prevsynth_fx, /*Q15 16 */ - Word16 *prevsynth_LP_fx, /* Q15 16 */ + Word16 *prevsynth_LP_fx, /* Q15 16 */ const Word16 L, Word16 *N, - Word16 *min_corr_fx, /* Q15 16 */ + Word16 *min_corr_fx, /* Q15 16 */ Word16 *decimatefator, - const Word16 HqVoicing -) + const Word16 HqVoicing ) { - Word16 i,filt_size; - Word16 QAsr,Ryy,cb_start, tmpQLP; + Word16 i, filt_size; + Word16 QAsr, Ryy, cb_start, tmpQLP; Word32 Ryytmp; - Word32 accA,accB, accBisqrt,accC, accCisqrt; - Word16 delay_ind,k; + Word32 accA, accB, accBisqrt, accC, accCisqrt; + Word16 delay_ind, k; const Word16 *Asr_LP_fx; Word16 *ptr_LP, *ptr_LP2, *ptr_LP3, *ptr_LP4; Word16 cb_end; Word16 Lmul2, Lon20mul6, Lon20mul28, Lon20mul33, Lon20mul34; - SWITCH(L) + SWITCH( L ) { - case L_FRAME48k: - *decimatefator=6; - move16(); - filt_size=60; - move16(); - Asr_LP_fx = Asr_LP48_fx; - QAsr = 17; - move16(); - Lon20mul6 = 48; - move16(); - Lon20mul28 = 224; - move16(); - Lon20mul33 = 264; - move16(); - Lon20mul34 = 272; - move16(); - Lmul2 = 1920; - move16(); - BREAK; + case L_FRAME48k: + *decimatefator = 6; + move16(); + filt_size = 60; + move16(); + Asr_LP_fx = Asr_LP48_fx; + QAsr = 17; + move16(); + Lon20mul6 = 48; + move16(); + Lon20mul28 = 224; + move16(); + Lon20mul33 = 264; + move16(); + Lon20mul34 = 272; + move16(); + Lmul2 = 1920; + move16(); + BREAK; - case L_FRAME32k: - *decimatefator=4; - move16(); - filt_size=40; - move16(); - Asr_LP_fx = Asr_LP32_fx; - QAsr = 15; - move16(); - Lon20mul6 = 48; - move16(); - Lon20mul28 = 224; - move16(); - Lon20mul33 = 264; - move16(); - Lon20mul34 = 272; - move16(); - Lmul2 = 1280; - move16(); - BREAK; + case L_FRAME32k: + *decimatefator = 4; + move16(); + filt_size = 40; + move16(); + Asr_LP_fx = Asr_LP32_fx; + QAsr = 15; + move16(); + Lon20mul6 = 48; + move16(); + Lon20mul28 = 224; + move16(); + Lon20mul33 = 264; + move16(); + Lon20mul34 = 272; + move16(); + Lmul2 = 1280; + move16(); + BREAK; - case L_FRAME16k: - *decimatefator=2; - move16(); - filt_size=20; - move16(); - Asr_LP_fx = Asr_LP16_fx; - QAsr = 15; - move16(); - Lon20mul6 = 48; - move16(); - Lon20mul28 = 224; - move16(); - Lon20mul33 = 264; - move16(); - Lon20mul34 = 272; - move16(); - Lmul2 = 640; - move16(); - BREAK; + case L_FRAME16k: + *decimatefator = 2; + move16(); + filt_size = 20; + move16(); + Asr_LP_fx = Asr_LP16_fx; + QAsr = 15; + move16(); + Lon20mul6 = 48; + move16(); + Lon20mul28 = 224; + move16(); + Lon20mul33 = 264; + move16(); + Lon20mul34 = 272; + move16(); + Lmul2 = 640; + move16(); + BREAK; - default: - *decimatefator=2; - move16(); - filt_size=40; - move16(); - Asr_LP_fx = Asr_LP16_fx; - QAsr = 15; - move16(); - Lon20mul6 = 48; - move16(); - Lon20mul28 = 224; - move16(); - Lon20mul33 = 264; - move16(); - Lon20mul34 = 272; - move16(); - Lmul2 = 320; - move16(); - BREAK; + default: + *decimatefator = 2; + move16(); + filt_size = 40; + move16(); + Asr_LP_fx = Asr_LP16_fx; + QAsr = 15; + move16(); + Lon20mul6 = 48; + move16(); + Lon20mul28 = 224; + move16(); + Lon20mul33 = 264; + move16(); + Lon20mul34 = 272; + move16(); + Lmul2 = 320; + move16(); + BREAK; } /* Resampling to work at 8Khz */ - fir_dwn_fx(prevsynth_fx, Asr_LP_fx, QAsr, prevsynth_LP_fx, Lmul2, filt_size, *decimatefator); /* resampling without delay */ + fir_dwn_fx( prevsynth_fx, Asr_LP_fx, QAsr, prevsynth_LP_fx, Lmul2, filt_size, *decimatefator ); /* resampling without delay */ - tmpQLP = Find_Max_Norm16(prevsynth_LP_fx,320); - Scale_sig(prevsynth_LP_fx,320,sub(tmpQLP,3)); /* to avoid over scaling */ - + tmpQLP = Find_Max_Norm16( prevsynth_LP_fx, 320 ); + Scale_sig( prevsynth_LP_fx, 320, sub( tmpQLP, 3 ) ); /* to avoid over scaling */ /* Correlation analysis */ *min_corr_fx = 0; move16(); - accC = L_deposit_l(0); + accC = L_deposit_l( 0 ); ptr_LP = prevsynth_LP_fx + Lon20mul34; - FOR (k = 0; k < Lon20mul6; k++) + FOR( k = 0; k < Lon20mul6; k++ ) { - accC = L_mac0 (accC, *ptr_LP, *ptr_LP); + accC = L_mac0( accC, *ptr_LP, *ptr_LP ); ptr_LP++; - } - - IF (HqVoicing==1) + IF( HqVoicing == 1 ) { - cb_start=0; - cb_end=Lon20mul33; + cb_start = 0; + cb_end = Lon20mul33; } ELSE { - cb_start=0; - cb_end=Lon20mul28; + cb_start = 0; + cb_end = Lon20mul28; } - accB=0; - delay_ind=cb_start; + accB = 0; + delay_ind = cb_start; - FOR (i=cb_start; i *min_corr_fx ) + IF( Ryy > *min_corr_fx ) { *min_corr_fx = Ryy; delay_ind = i; } test(); - IF ( HqVoicing == 0 && *min_corr_fx > 31130) + IF( HqVoicing == 0 && *min_corr_fx > 31130 ) { BREAK; } } - *N= sub(Lon20mul34, delay_ind); + *N = sub( Lon20mul34, delay_ind ); - Scale_sig(prevsynth_LP_fx,320,negate(sub(tmpQLP,3))); + Scale_sig( prevsynth_LP_fx, 320, negate( sub( tmpQLP, 3 ) ) ); return; } -static -void sin_cos_est_fx(Word32 phi, Word16 *cosfreq, Word16 *sinfreq) +static void sin_cos_est_fx( Word32 phi, Word16 *cosfreq, Word16 *sinfreq ) { @@ -3639,65 +3684,63 @@ void sin_cos_est_fx(Word32 phi, Word16 *cosfreq, Word16 *sinfreq) Word16 sinb, cosb; Word32 sinv, cosv, tmp; - i=0; + i = 0; move16(); - FOR (imin=0; imin0 || HqVoicing */ } - - pt4 = pulses; - nb_pulses=0; + nb_pulses = 0; move16(); - PL=0; + PL = 0; move16(); - cpt=0; + cpt = 0; move16(); - old=0; + old = 0; move16(); - glued=1; + glued = 1; move16(); - new_s=Tf_abs[1]; + new_s = Tf_abs[1]; move16(); - if (flag ) + if ( flag ) { - PL=1; + PL = 1; move16(); } - tmp=sub(shr(N,1),3); - WHILE(LE_16(cpt,tmp)) + tmp = sub( shr( N, 1 ), 3 ); + WHILE( LE_16( cpt, tmp ) ) { test(); - IF(GT_16(Tf_abs[cpt],old)&>_16(Tf_abs[cpt],new_s)) + IF( GT_16( Tf_abs[cpt], old ) && GT_16( Tf_abs[cpt], new_s ) ) { Word16 tmp2; - glued=cpt; + glued = cpt; move16(); - tmp2 = add(add(cpt,PL),1); - FOR (i=glued; i scaling of a_re is Qin+sN */ @@ -4220,10 +4254,11 @@ void sinusoidal_synthesis_fx( Tf_abs[indmax] = -1; move16(); - maxi=sub(maxi,1); - } WHILE( maxi>0 && LT_32(cumsum, L_tmp)); + maxi = sub( maxi, 1 ); + } + WHILE( maxi > 0 && LT_32( cumsum, L_tmp ) ); - nb_pulses_final = sub(nb_pulses_final,maxi); + nb_pulses_final = sub( nb_pulses_final, maxi ); move16(); } @@ -4231,39 +4266,38 @@ void sinusoidal_synthesis_fx( /* sinusoidal synthesis */ - set32_fx(synthesis_fx,0,Len); + set32_fx( synthesis_fx, 0, Len ); - exp = add(exp,sN); + exp = add( exp, sN ); pt1 = a_re; pt2 = a_im; pt3 = freqi; - q = shr_r(N,2); - if (GT_16(N,shl(q,2))) + q = shr_r( N, 2 ); + if ( GT_16( N, shl( q, 2 ) ) ) { - q = add(q,1); + q = add( q, 1 ); } - inv_den = i_mult2(N,decimate_factor); /*Q0 */ + inv_den = i_mult2( N, decimate_factor ); /*Q0 */ /*tmp = div_s(12868,inv_den);*/ /*Q15 */ - FOR ( i=0; i 0 ) + WHILE( flag > 0 ) { - tmp_fx = Random(ni_seed_forfec); + tmp_fx = Random( ni_seed_forfec ); - L_tmp = L_mac(1503264768, tmp_fx ,9830); + L_tmp = L_mac( 1503264768, tmp_fx, 9830 ); if ( kk == 0 ) { - L_tmp = L_mac(1073741824, tmp_fx ,6554); + L_tmp = L_mac( 1073741824, tmp_fx, 6554 ); } - kk = sub(1,kk) ; - tmp_fx = round_fx(L_tmp); - Rnd_N_noise = extract_h(L_mult(N_noise, tmp_fx)); /*Q0 */ + kk = sub( 1, kk ); + tmp_fx = round_fx( L_tmp ); + Rnd_N_noise = extract_h( L_mult( N_noise, tmp_fx ) ); /*Q0 */ - tmp_fx = div_s(1, Rnd_N_noise); /*Q15 */ + tmp_fx = div_s( 1, Rnd_N_noise ); /*Q15 */ #ifdef BASOP_NOGLOB tmp_fx = round_fx_sat( L_shl_sat( L_mult( tmp_fx, 25736 ), 2 ) ); /*Q15 */ #else - tmp_fx = round_fx(L_shl(L_mult(tmp_fx, 25736),2)); /*Q15 */ + tmp_fx = round_fx( L_shl( L_mult( tmp_fx, 25736 ), 2 ) ); /*Q15 */ #endif #ifdef IVAS_FEC_ECU_TO_COMPLETE - if (element_mode == EVS_MONO) + if ( element_mode == EVS_MONO ) { kk = 7 * L / 20; p_mdct_ola = prevsynth + 37 * L / 20; } else { - kk = NS2SA(L * FRAMES_PER_SEC, N_ZERO_MDCT_NS); + kk = NS2SA( L * FRAMES_PER_SEC, N_ZERO_MDCT_NS ); p_mdct_ola = old_out + kk; } #endif - sinq_fx( shr(tmp_fx,1), shr(tmp_fx,2), Rnd_N_noise, SS_fx); + sinq_fx( shr( tmp_fx, 1 ), shr( tmp_fx, 2 ), Rnd_N_noise, SS_fx ); pt2 = &noisevect_fx[N_noise]; pt1 = pt2 - Rnd_N_noise; pt3 = SS_fx; - pt4 = pt3 + sub(Rnd_N_noise,1); - tmp_fx = s_min(Rnd_N_noise, flag); - FOR ( i=0 ; i 0) + if ( *num_p > 0 ) { - seed = add(seed, plocs[*num_p-1]); + seed = add( seed, plocs[*num_p - 1] ); } - subst_spec_fx(plocs, plocsi, num_p, *time_offs, X, mag_chg, ph_dith, old_is_transient, output_frame, &seed, - alpha, beta, *beta_mute, Xavg + subst_spec_fx( plocs, plocsi, num_p, *time_offs, X, mag_chg, ph_dith, old_is_transient, output_frame, &seed, + alpha, beta, *beta_mute, Xavg #ifdef IVAS_FEC_ECU_TO_COMPLETE - , element_mode, ph_ecu_lookahead, noise_fac + , + element_mode, ph_ecu_lookahead, noise_fac #endif ); /* reconstructed frame in tda domain */ #ifdef IVAS_FEC_ECU_TO_COMPLETE - old_dec = prevsynth + 2 * output_frame - NS2SA(output_frame * FRAMES_PER_SEC, N_ZERO_MDCT_NS); + old_dec = prevsynth + 2 * output_frame - NS2SA( output_frame * FRAMES_PER_SEC, N_ZERO_MDCT_NS ); #endif - rec_frame_fx(X, ecu_rec, output_frame, *Q_spec + rec_frame_fx( X, ecu_rec, output_frame, *Q_spec #ifdef IVAS_FEC_ECU_TO_COMPLETE - , old_dec, element_mode, num_p, plocs + , + old_dec, element_mode, num_p, plocs #endif ); @@ -5125,103 +5166,116 @@ void ivas_hq_ecu_fx( #endif void hq_ecu_fx( - const Word16 *prevsynth, /* i : buffer of previously synthesized signal */ - Word32 *ecu_rec, /* o : reconstructed frame in tda domain */ - Word16 *time_offs, /* i/o: Sample offset for consecutive frame losses */ - Word16 *X_sav, /* i/o: Stored spectrum of prototype frame */ - Word16 *Q_spec, /* i/o: Q value of stored spectrum */ - Word16 *num_p, /* i/o: Number of identified peaks */ - Word16 *plocs, /* i/o: Peak locations */ - Word32 *plocsi, /* i/o: Interpolated peak locations Q16 */ - const Word16 env_stab, /* i : Envelope stability parameter */ - Word16 *last_fec, /* i/o: Flag for usage of pitch dependent ECU */ - const Word16 ph_ecu_HqVoicing, /* i : HQ Voicing flag */ - Word16 *ph_ecu_active, /* i : Phase ECU active flag */ - Word16 *gapsynth, /* o : Gap synthesis */ - const Word16 prev_bfi, /* i : indicating burst frame error */ - const Word16 old_is_transient[2], /* i : flags indicating previous transient frames */ - Word16 *mag_chg_1st, /* i/o: per band magnitude modifier for transients */ - Word16 *Xavg, /* i/o: Frequency group average gain to fade to */ - Word16 *beta_mute, /* o : Factor for long-term mute */ - const Word16 output_frame, /* i : frame length */ - Decoder_State *st_fx /* i/o: decoder state structure */ + const Word16 *prevsynth, /* i : buffer of previously synthesized signal */ + Word32 *ecu_rec, /* o : reconstructed frame in tda domain */ + Word16 *time_offs, /* i/o: Sample offset for consecutive frame losses */ + Word16 *X_sav, /* i/o: Stored spectrum of prototype frame */ + Word16 *Q_spec, /* i/o: Q value of stored spectrum */ + Word16 *num_p, /* i/o: Number of identified peaks */ + Word16 *plocs, /* i/o: Peak locations */ + Word32 *plocsi, /* i/o: Interpolated peak locations Q16 */ + const Word16 env_stab, /* i : Envelope stability parameter */ + Word16 *last_fec, /* i/o: Flag for usage of pitch dependent ECU */ + const Word16 ph_ecu_HqVoicing, /* i : HQ Voicing flag */ + Word16 *ph_ecu_active, /* i : Phase ECU active flag */ + Word16 *gapsynth, /* o : Gap synthesis */ + const Word16 prev_bfi, /* i : indicating burst frame error */ + const Word16 old_is_transient[2], /* i : flags indicating previous transient frames */ + Word16 *mag_chg_1st, /* i/o: per band magnitude modifier for transients */ + Word16 *Xavg, /* i/o: Frequency group average gain to fade to */ + Word16 *beta_mute, /* o : Factor for long-term mute */ + const Word16 output_frame, /* i : frame length */ + Decoder_State *st_fx /* i/o: decoder state structure */ ) { Word16 N; Word16 decimatefactor; Word16 corr; /*Q15 */ - Word16 prevsynth_LP[2*L_FRAME8k]; + Word16 prevsynth_LP[2 * L_FRAME8k]; #ifdef IVAS_FEC_ECU_TO_COMPLETE HQ_DEC_HANDLE hHQ_core; - const float* fec_alg_input; + const float *fec_alg_input; int16_t evs_mode_selection; int16_t ivas_mode_selection; hHQ_core = st->hHQ_core; - if (st->element_mode == EVS_MONO) + if ( st->element_mode == EVS_MONO ) { - fec_alg_input = prevsynth + NS2SA(output_frame * FRAMES_PER_SEC, ACELP_LOOK_NS / 2 - PH_ECU_LOOKAHEAD_NS); + fec_alg_input = prevsynth + NS2SA( output_frame * FRAMES_PER_SEC, ACELP_LOOK_NS / 2 - PH_ECU_LOOKAHEAD_NS ); } else { - fec_alg_input = prevsynth - NS2SA(output_frame * FRAMES_PER_SEC, PH_ECU_LOOKAHEAD_NS); + fec_alg_input = prevsynth - NS2SA( output_frame * FRAMES_PER_SEC, PH_ECU_LOOKAHEAD_NS ); } #endif /* init (values ar changed after) */ - decimatefactor=4; - N=shr(output_frame,2); + decimatefactor = 4; + N = shr( output_frame, 2 ); /* find pitch and R value */ - IF (!(LT_16(output_frame,L_FRAME16k))) + IF( !( LT_16( output_frame, L_FRAME16k ) ) ) { #ifdef IVAS_FEC_ECU_TO_COMPLETE - fec_ecu_pitch_fx(fec_alg_input, prevsynth_LP, output_frame, &N, &corr, &decimatefactor, ph_ecu_HqVoicing); + fec_ecu_pitch_fx( fec_alg_input, prevsynth_LP, output_frame, &N, &corr, &decimatefactor, ph_ecu_HqVoicing ); #else - fec_ecu_pitch_fx( prevsynth+NS2SA(output_frame*50,ACELP_LOOK_NS/2-PH_ECU_LOOKAHEAD_NS), prevsynth_LP, output_frame, &N, &corr, &decimatefactor, ph_ecu_HqVoicing); + fec_ecu_pitch_fx( prevsynth + NS2SA( output_frame * 50, ACELP_LOOK_NS / 2 - PH_ECU_LOOKAHEAD_NS ), prevsynth_LP, output_frame, &N, &corr, &decimatefactor, ph_ecu_HqVoicing ); #endif } ELSE { corr = 0; - move16(); /* just to avoid using uninitialized value in if statement below */ + move16(); /* just to avoid using uninitialized value in if statement below */ } - test();test();test();test();test();test(); - test();test();test();test();test();test(); - test();test();test(); -#if defined IVAS_FEC_ECU_TO_COMPLETE - evs_mode_selection = (st->total_brate >= 48000 && (output_frame >= L_FRAME16k && !prev_bfi && (!old_is_transient[0] || old_is_transient[1]) && - (ph_ecu_HqVoicing || (((hHQ_core->env_stab_plc > 0.5) && (corr < 0.6)) || (hHQ_core->env_stab_plc < 0.5 && (corr > 0.85)))))) || - (st->total_brate < 48000 && ((ph_ecu_HqVoicing || corr > 0.85) && !prev_bfi && (!old_is_transient[0] || old_is_transient[1]))); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); +#if defined IVAS_FEC_ECU_TO_COMPLETE + evs_mode_selection = ( st->total_brate >= 48000 && ( output_frame >= L_FRAME16k && !prev_bfi && ( !old_is_transient[0] || old_is_transient[1] ) && + ( ph_ecu_HqVoicing || ( ( ( hHQ_core->env_stab_plc > 0.5 ) && ( corr < 0.6 ) ) || ( hHQ_core->env_stab_plc < 0.5 && ( corr > 0.85 ) ) ) ) ) ) || + ( st->total_brate < 48000 && ( ( ph_ecu_HqVoicing || corr > 0.85 ) && !prev_bfi && ( !old_is_transient[0] || old_is_transient[1] ) ) ); - ivas_mode_selection = (N < PH_ECU_N_LIMIT) || (corr < PH_ECU_CORR_LIMIT); - if (((st->element_mode == EVS_MONO) && evs_mode_selection) || - ((st->element_mode != EVS_MONO) && evs_mode_selection && ivas_mode_selection)) + ivas_mode_selection = ( N < PH_ECU_N_LIMIT ) || ( corr < PH_ECU_CORR_LIMIT ); + if ( ( ( st->element_mode == EVS_MONO ) && evs_mode_selection ) || + ( ( st->element_mode != EVS_MONO ) && evs_mode_selection && ivas_mode_selection ) ) { - fec_alg_fx(fec_alg_input, prevsynth_LP, ecu_rec, output_frame, N, decimatefactor, ph_ecu_HqVoicing, gapsynth, &hHQ_core->ni_seed_forfec, st->element_mode, st->hHQ_core->old_out); + fec_alg_fx( fec_alg_input, prevsynth_LP, ecu_rec, output_frame, N, decimatefactor, ph_ecu_HqVoicing, gapsynth, &hHQ_core->ni_seed_forfec, st->element_mode, st->hHQ_core->old_out ); *last_fec = 1; *ph_ecu_active = 0; move16(); *time_offs = output_frame; - move16();; + move16(); + ; } else { - hq_phase_ecu(prevsynth - NS2SA(output_frame * FRAMES_PER_SEC, PH_ECU_LOOKAHEAD_NS), ecu_rec, time_offs, X_sav, num_p, plocs, plocsi, env_stab, last_fec, prev_bfi, old_is_transient, mag_chg_1st, Xavg, beta_mute, st->bwidth, output_frame, corr, st->element_mode); + hq_phase_ecu( prevsynth - NS2SA( output_frame * FRAMES_PER_SEC, PH_ECU_LOOKAHEAD_NS ), ecu_rec, time_offs, X_sav, num_p, plocs, plocsi, env_stab, last_fec, prev_bfi, old_is_transient, mag_chg_1st, Xavg, beta_mute, st->bwidth, output_frame, corr, st->element_mode ); *last_fec = 0; *ph_ecu_active = 1; } #else - IF ( (GE_32(st_fx->total_brate,48000)&& - ( GE_16(output_frame, L_FRAME16k) && !prev_bfi && (!old_is_transient[0] || old_is_transient[1] ) && (NE_16(ph_ecu_HqVoicing,0) || ( ((NE_16(st_fx->hHQ_core->env_stab_plc_fx ,0)) && (LT_16(corr,19661))) || (!(NE_16(st_fx->hHQ_core->env_stab_plc_fx ,0)) && (GT_16(corr, 27853)) ))))) || - (LT_32(st_fx->total_brate,48000) && ( ( ph_ecu_HqVoicing || GT_16(corr, 27853)) && !prev_bfi && (!old_is_transient[0] || old_is_transient[1]) )) ) + IF( ( GE_32( st_fx->total_brate, 48000 ) && + ( GE_16( output_frame, L_FRAME16k ) && !prev_bfi && ( !old_is_transient[0] || old_is_transient[1] ) && ( NE_16( ph_ecu_HqVoicing, 0 ) || ( ( ( NE_16( st_fx->hHQ_core->env_stab_plc_fx, 0 ) ) && ( LT_16( corr, 19661 ) ) ) || ( !( NE_16( st_fx->hHQ_core->env_stab_plc_fx, 0 ) ) && ( GT_16( corr, 27853 ) ) ) ) ) ) ) || + ( LT_32( st_fx->total_brate, 48000 ) && ( ( ph_ecu_HqVoicing || GT_16( corr, 27853 ) ) && !prev_bfi && ( !old_is_transient[0] || old_is_transient[1] ) ) ) ) { - fec_alg_fx( prevsynth+NS2SA(output_frame*50,ACELP_LOOK_NS/2-PH_ECU_LOOKAHEAD_NS), prevsynth_LP, &st_fx->hHQ_core->ni_seed_forfec, ecu_rec, output_frame, N, decimatefactor, ph_ecu_HqVoicing, gapsynth); + fec_alg_fx( prevsynth + NS2SA( output_frame * 50, ACELP_LOOK_NS / 2 - PH_ECU_LOOKAHEAD_NS ), prevsynth_LP, &st_fx->hHQ_core->ni_seed_forfec, ecu_rec, output_frame, N, decimatefactor, ph_ecu_HqVoicing, gapsynth ); *last_fec = 1; *ph_ecu_active = 0; move16(); @@ -5231,8 +5285,8 @@ void hq_ecu_fx( ELSE { hq_phase_ecu_fx( prevsynth, ecu_rec, time_offs, X_sav, Q_spec, num_p, plocs, plocsi, - env_stab, last_fec, ph_ecu_active, prev_bfi, old_is_transient, - mag_chg_1st, Xavg, beta_mute, st_fx->bwidth, output_frame ); + env_stab, last_fec, ph_ecu_active, prev_bfi, old_is_transient, + mag_chg_1st, Xavg, beta_mute, st_fx->bwidth, output_frame ); } #endif return; @@ -5257,17 +5311,19 @@ void hq_ecu_fx( * plot(err); ******************************************************************************/ -static Word16 sqrt2ndOrder( /* o: in Q15 (2nd order least square approx.) */ - const Word16 x /* i: x must be in between 0.5 and 1.0 (Q15). */ +static Word16 sqrt2ndOrder( /* o: in Q15 (2nd order least square approx.) */ + const Word16 x /* i: x must be in between 0.5 and 1.0 (Q15). */ ) { Word32 acc; Word16 z; - acc = 1890205600L; /* 0.880195572812922 in Q31 */ move32(); - z = mac_r(acc, x, -6506); /* -0.198537395405340 in Q15 */ - acc = 682030261L; /* 0.317595089462249 in Q31 */ move32(); - z = mac_r(acc, z, x); /* in Q15 */ + acc = 1890205600L; /* 0.880195572812922 in Q31 */ + move32(); + z = mac_r( acc, x, -6506 ); /* -0.198537395405340 in Q15 */ + acc = 682030261L; /* 0.317595089462249 in Q31 */ + move32(); + z = mac_r( acc, z, x ); /* in Q15 */ return z; } @@ -5293,19 +5349,19 @@ static void windowing( pX = x; pW = win; pY = y; - FOR (i = 0; i < halfLength; i++) /* 1st symmetric half of the Hamming window */ + FOR( i = 0; i < halfLength; i++ ) /* 1st symmetric half of the Hamming window */ { - *pY++ = mult_r(*pX++, *pW++); + *pY++ = mult_r( *pX++, *pW++ ); move16(); } - FOR (i = 0; i < rectLength; i++) /* If rectLength is zero, it's a pure Hamming window; otherwise Hamming-Rectangular. */ + FOR( i = 0; i < rectLength; i++ ) /* If rectLength is zero, it's a pure Hamming window; otherwise Hamming-Rectangular. */ { *pY++ = *pX++; move16(); } - FOR (i = 0; i < halfLength; i++) /* 2nd symmetric half of the Hamming window. */ + FOR( i = 0; i < halfLength; i++ ) /* 2nd symmetric half of the Hamming window. */ { - *pY++ = mult_r(*pX++, *(--pW)); + *pY++ = mult_r( *pX++, *( --pW ) ); move16(); } } @@ -5323,11 +5379,11 @@ static void windowing( * 5. 2nd half of the right half of the Hamming window *----------------------------------------------------------------------------*/ static void windowing_ROM_optimized( - const Word16 *x, /* i: Input signal */ - Word16 *y, /* o: Windowed output */ - const Word16 downSamples,/* i: Offset in accessing the sine table. */ - const Word16 rectLength, /* i: Length of the rectangular portion (excluding the Hamming window part) */ - const Word16 halfLength /* i: Half of the total length of the Hamming (excluding rectangular part) window */ + const Word16 *x, /* i: Input signal */ + Word16 *y, /* o: Windowed output */ + const Word16 downSamples, /* i: Offset in accessing the sine table. */ + const Word16 rectLength, /* i: Length of the rectangular portion (excluding the Hamming window part) */ + const Word16 halfLength /* i: Half of the total length of the Hamming (excluding rectangular part) window */ ) { Word16 i, hamm, quarterLen, initOffset; @@ -5335,65 +5391,65 @@ static void windowing_ROM_optimized( const Word16 *pX, *pSine; Word32 acc; - quarterLen = shr(halfLength, 1); /* 1/4 length of the entire Hamming (excluding the rectangular part) window. */ - initOffset = add(T_SIN_PI_2, shr(downSamples,1)); + quarterLen = shr( halfLength, 1 ); /* 1/4 length of the entire Hamming (excluding the rectangular part) window. */ + initOffset = add( T_SIN_PI_2, shr( downSamples, 1 ) ); pSine = sincos_t_rad3_fx + initOffset; pX = x; pY = y; /* 1st half of the left half of the Hamming window. */ - FOR (i = 0; i < quarterLen; i++) + FOR( i = 0; i < quarterLen; i++ ) { - pSine -= downSamples; /* Decrement address counter */ - acc = L_deposit_h(FEC_HQ_WIN_A0); /* Derive the Hamming window coefficient from the sine table. */ - hamm = msu_r(acc, *pSine, FEC_HQ_WIN_A1); - *pY++ = mult_r(hamm, *pX++); + pSine -= downSamples; /* Decrement address counter */ + acc = L_deposit_h( FEC_HQ_WIN_A0 ); /* Derive the Hamming window coefficient from the sine table. */ + hamm = msu_r( acc, *pSine, FEC_HQ_WIN_A1 ); + *pY++ = mult_r( hamm, *pX++ ); move16(); } /* 2nd half of the left half of the Hamming window. */ - FOR (i = 0; i < quarterLen; i++) + FOR( i = 0; i < quarterLen; i++ ) { - acc = L_deposit_h(FEC_HQ_WIN_A0); + acc = L_deposit_h( FEC_HQ_WIN_A0 ); #ifdef BASOP_NOGLOB - hamm = mac_r_sat(acc, *pSine, FEC_HQ_WIN_A1); + hamm = mac_r_sat( acc, *pSine, FEC_HQ_WIN_A1 ); #else - hamm = mac_r(acc, *pSine, FEC_HQ_WIN_A1); + hamm = mac_r( acc, *pSine, FEC_HQ_WIN_A1 ); #endif - *pY++ = mult_r(hamm, *pX++); + *pY++ = mult_r( hamm, *pX++ ); move16(); - pSine += downSamples; /* Increment address counter */ + pSine += downSamples; /* Increment address counter */ } /* The rectangular flat region */ - FOR (i = 0; i < rectLength; i++) + FOR( i = 0; i < rectLength; i++ ) { *pY++ = *pX++; move16(); } /* 1st half of the right half of the Hamming window. */ - FOR (i = 0; i < quarterLen; i++) + FOR( i = 0; i < quarterLen; i++ ) { - pSine -= downSamples; /* Decrement address counter */ - acc = L_deposit_h(FEC_HQ_WIN_A0); + pSine -= downSamples; /* Decrement address counter */ + acc = L_deposit_h( FEC_HQ_WIN_A0 ); #ifdef BASOP_NOGLOB - hamm = mac_r_sat(acc, *pSine, FEC_HQ_WIN_A1); + hamm = mac_r_sat( acc, *pSine, FEC_HQ_WIN_A1 ); #else - hamm = mac_r(acc, *pSine, FEC_HQ_WIN_A1); + hamm = mac_r( acc, *pSine, FEC_HQ_WIN_A1 ); #endif - *pY++ = mult_r(hamm, *pX++); + *pY++ = mult_r( hamm, *pX++ ); move16(); } /* 2nd half of the right half of the Hamming window. */ - FOR (i = 0; i < quarterLen; i++) + FOR( i = 0; i < quarterLen; i++ ) { - acc = L_deposit_h(FEC_HQ_WIN_A0); - hamm = msu_r(acc, *pSine, FEC_HQ_WIN_A1); - *pY++ = mult_r(hamm, *pX++); + acc = L_deposit_h( FEC_HQ_WIN_A0 ); + hamm = msu_r( acc, *pSine, FEC_HQ_WIN_A1 ); + *pY++ = mult_r( hamm, *pX++ ); move16(); - pSine += downSamples; /* Increment address counter */ + pSine += downSamples; /* Increment address counter */ } } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/FEC_adapt_codebook.c b/lib_dec/FEC_adapt_codebook.c index bb638b3a4..e6a07ddba 100644 --- a/lib_dec/FEC_adapt_codebook.c +++ b/lib_dec/FEC_adapt_codebook.c @@ -492,4 +492,4 @@ int16_t FEC_enhACB( return do_WI; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/FEC_adapt_codebook_fx.c b/lib_dec/FEC_adapt_codebook_fx.c index fab0dfe43..6a8a23518 100644 --- a/lib_dec/FEC_adapt_codebook_fx.c +++ b/lib_dec/FEC_adapt_codebook_fx.c @@ -3,11 +3,11 @@ ====================================================================================*/ #include #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_dec.h" /* Decoder static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_dec.h" /* Decoder static table prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ /*---------------------------------------------------------------------* @@ -16,18 +16,18 @@ * Create an artificial onset when it is lost *---------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -Word16 FEC_SinOnset_fx ( - Word16 *exc, /* i/o : exc vector to modify */ - Word16 puls_pos, /* i : last pulse position desired */ - const Word16 T0, /* i : Pitch information of the 1 subfr */ - Word32 enr_q, /* i : energy provide by the encoder */ - Word16 *Aq, /* i : A(z) filter Q12 */ - const Word16 L_frame /* i : frame length */ - ,const Word16 Qold -) +Word16 FEC_SinOnset_fx( + Word16 *exc, /* i/o : exc vector to modify */ + Word16 puls_pos, /* i : last pulse position desired */ + const Word16 T0, /* i : Pitch information of the 1 subfr */ + Word32 enr_q, /* i : energy provide by the encoder */ + Word16 *Aq, /* i : A(z) filter Q12 */ + const Word16 L_frame /* i : frame length */ + , + const Word16 Qold ) { Word16 P0, onset_len, sign, i, len, L_subfr, L_subfr2; - Word16 h1[L_SUBFR16k], mem[M], exc_tmp[L_FRAME16k+ MODE1_L_FIR_FER]; + Word16 h1[L_SUBFR16k], mem[M], exc_tmp[L_FRAME16k + MODE1_L_FIR_FER]; Word16 *pt_end, *pt_exc, enr_LP, gain, H_low_s[5], exp_gain, exp2, tmp; Word32 L_tmp; Word16 Q_exc; @@ -38,102 +38,102 @@ Word16 FEC_SinOnset_fx ( move16(); L_subfr = L_SUBFR; move16(); - if( EQ_16(L_frame,L_FRAME16k)) + if ( EQ_16( L_frame, L_FRAME16k ) ) { L_subfr = L_SUBFR16k; move16(); } - L_subfr2 = shl(L_subfr,1); - onset_len = s_max(T0, L_subfr2); + L_subfr2 = shl( L_subfr, 1 ); + onset_len = s_max( T0, L_subfr2 ); P0 = puls_pos; move16(); - IF (P0 < 0) + IF( P0 < 0 ) { sign = 1; move16(); - P0 = negate(P0); + P0 = negate( P0 ); } test(); test(); - IF ( GT_16(P0,PIT_MAX)&&EQ_16(L_frame,L_FRAME)) + IF( GT_16( P0, PIT_MAX ) && EQ_16( L_frame, L_FRAME ) ) { P0 = PIT_MAX; - move16();/* Should never be the case, however... */ + move16(); /* Should never be the case, however... */ } - ELSE if ( GT_16(P0,PIT16k_MAX)&&EQ_16(L_frame,L_FRAME16k)) + ELSE if ( GT_16( P0, PIT16k_MAX ) && EQ_16( L_frame, L_FRAME16k ) ) { P0 = PIT16k_MAX; move16(); /* Should never be the case, however... */ } - set16_fx( exc_tmp, 0, add(L_frame, MODE1_L_FIR_FER)); /* Reset excitation vector */ + set16_fx( exc_tmp, 0, add( L_frame, MODE1_L_FIR_FER ) ); /* Reset excitation vector */ /*-------------------------------------------------------------------------------* * Find LP filter impulse response energy and Generate the scaled pulse prototype *-------------------------------------------------------------------------------*/ - set16_fx(h1, 0, L_subfr); /* Find the impulse response */ - set16_fx(mem, 0, M); + set16_fx( h1, 0, L_subfr ); /* Find the impulse response */ + set16_fx( mem, 0, M ); h1[0] = 1024; move16(); - Syn_filt_s(1, Aq, M, h1, h1, L_subfr, mem, 0); + Syn_filt_s( 1, Aq, M, h1, h1, L_subfr, mem, 0 ); - enr_LP = extract_h(Dot_product12(h1, h1, L_subfr, &exp_gain)); - exp_gain = sub(exp_gain, 10 + 10); /* h1 in Q10 */ + enr_LP = extract_h( Dot_product12( h1, h1, L_subfr, &exp_gain ) ); + exp_gain = sub( exp_gain, 10 + 10 ); /* h1 in Q10 */ /* divide by LP filter E, scaled by transmitted E */ /* gain = (float)sqrt( enr_q / enr_LP ); */ - enr_q = L_max(enr_q,1); + enr_q = L_max( enr_q, 1 ); - exp2 = norm_l(enr_q); - tmp = extract_h(L_shl(enr_q, exp2)); - tmp = mult(tmp, 24576); /* multpiply by 1.5 */ + exp2 = norm_l( enr_q ); + tmp = extract_h( L_shl( enr_q, exp2 ) ); + tmp = mult( tmp, 24576 ); /* multpiply by 1.5 */ - IF(LT_16(tmp, 16384)) + IF( LT_16( tmp, 16384 ) ) { - exp2 = add(exp2, 1); - tmp = shl(tmp, 1); + exp2 = add( exp2, 1 ); + tmp = shl( tmp, 1 ); } - exp2 = sub(30, exp2); /* in Q15 */ + exp2 = sub( 30, exp2 ); /* in Q15 */ - IF(GT_16(enr_LP, tmp)) + IF( GT_16( enr_LP, tmp ) ) { - enr_LP = shr(enr_LP, 1); - exp_gain = add(exp_gain, 1); + enr_LP = shr( enr_LP, 1 ); + exp_gain = add( exp_gain, 1 ); } - tmp = div_s(enr_LP, tmp); - exp2 = sub(exp_gain, exp2); + tmp = div_s( enr_LP, tmp ); + exp2 = sub( exp_gain, exp2 ); - L_tmp = L_deposit_h(tmp); - L_tmp = Isqrt_lc(L_tmp, &exp2); - gain = round_fx(L_tmp); + L_tmp = L_deposit_h( tmp ); + L_tmp = Isqrt_lc( L_tmp, &exp2 ); + gain = round_fx( L_tmp ); - gain = mult_r(gain, 31457); /* multiply by .96 like floating point */ - exp2 = add(sub(exp2, 15), Q_exc); /* from Q15 to Q_exc */ + gain = mult_r( gain, 31457 ); /* multiply by .96 like floating point */ + exp2 = add( sub( exp2, 15 ), Q_exc ); /* from Q15 to Q_exc */ /* Find if rescaling needed */ - tmp = extract_h(L_mult(H_low[2], gain)); - exp_gain = norm_s(tmp); - tmp = sub(exp_gain, exp2); /* difference */ + tmp = extract_h( L_mult( H_low[2], gain ) ); + exp_gain = norm_s( tmp ); + tmp = sub( exp_gain, exp2 ); /* difference */ - IF(tmp < 0)/* Need to correct scaling */ + IF( tmp < 0 ) /* Need to correct scaling */ { - Q_exc = add(Q_exc, tmp); - exp2 = add(exp2, tmp); + Q_exc = add( Q_exc, tmp ); + exp2 = add( exp2, tmp ); } /* Scale pulse "prototype" energy */ /* Generate the scaled pulse */ - FOR(i = 0; i < MODE1_L_FIR_FER; i++) + FOR( i = 0; i < MODE1_L_FIR_FER; i++ ) { - L_tmp = L_mult(gain, H_low[i]); /* Q_exc*Q15 -> Q_exc */ - H_low_s[i] = round_fx(L_shl(L_tmp, exp2)); + L_tmp = L_mult( gain, H_low[i] ); /* Q_exc*Q15 -> Q_exc */ + H_low_s[i] = round_fx( L_shl( L_tmp, exp2 ) ); } /*------------------------------------------------------------------------------------------* * Construct the harmonic part as a train of low-pass filtered pulses @@ -141,41 +141,41 @@ Word16 FEC_SinOnset_fx ( move16(); move16(); move16(); - pt_exc = exc_tmp + sub(L_frame, add(add(1, MODE1_L_FIR_FER/2), P0)); /* beginning of the 1st pulse */ + pt_exc = exc_tmp + sub( L_frame, add( add( 1, MODE1_L_FIR_FER / 2 ), P0 ) ); /* beginning of the 1st pulse */ pt_end = exc_tmp + onset_len; - len = (Word16) (pt_exc - pt_end); + len = (Word16) ( pt_exc - pt_end ); - len = s_min(len, MODE1_L_FIR_FER); - IF(!sign) + len = s_min( len, MODE1_L_FIR_FER ); + IF( !sign ) { - FOR(i = 0; i < len; i++) + FOR( i = 0; i < len; i++ ) { /* The filter response would have E=1 in full band. */ - pt_exc[i] = add(pt_exc[i], H_low_s[i]); + pt_exc[i] = add( pt_exc[i], H_low_s[i] ); move16(); } } ELSE { - FOR(i = 0; i < len; i++) + FOR( i = 0; i < len; i++ ) { /* The filter response would have E=1 in full band. */ - pt_exc[i] = sub(pt_exc[i], H_low_s[i]); + pt_exc[i] = sub( pt_exc[i], H_low_s[i] ); move16(); } } - Copy(&exc_tmp[L_frame - L_EXC_MEM], exc, L_EXC_MEM); + Copy( &exc_tmp[L_frame - L_EXC_MEM], exc, L_EXC_MEM ); return Q_exc; } Word16 FEC_enhACB_fx( - const Word16 L_frame, /* i : frame length */ - const Word16 last_L_frame, /* i : frame length of previous frame */ - Word16 *exc_io, /* i/o : adaptive codebook memory */ - const Word16 new_pit, /* i : decoded first frame pitch */ - const Word16 puls_pos, /* i : decoder position of the last glottal pulses decoded in the previous frame */ - const Word16 bfi_pitch /* i : Q6 pitch used for concealment */ + const Word16 L_frame, /* i : frame length */ + const Word16 last_L_frame, /* i : frame length of previous frame */ + Word16 *exc_io, /* i/o : adaptive codebook memory */ + const Word16 new_pit, /* i : decoded first frame pitch */ + const Word16 puls_pos, /* i : decoder position of the last glottal pulses decoded in the previous frame */ + const Word16 bfi_pitch /* i : Q6 pitch used for concealment */ ) { Word16 Tc, P0, sign, pit_search; @@ -186,12 +186,12 @@ Word16 FEC_enhACB_fx( move16(); - set16_fx(exc, 0, L_FRAME16k - L_EXC_MEM); - set16_fx(exc+L_FRAME16k, 0, L_SUBFR); - Copy(exc_io, exc + L_FRAME16k - L_EXC_MEM, L_EXC_MEM); + set16_fx( exc, 0, L_FRAME16k - L_EXC_MEM ); + set16_fx( exc + L_FRAME16k, 0, L_SUBFR ); + Copy( exc_io, exc + L_FRAME16k - L_EXC_MEM, L_EXC_MEM ); - Tc = shr(bfi_pitch,6); - Copy(exc + L_FRAME16k - Tc, exc + L_FRAME16k, L_SUBFR); + Tc = shr( bfi_pitch, 6 ); + Copy( exc + L_FRAME16k - Tc, exc + L_FRAME16k, L_SUBFR ); /*------------------------------------------------------------ * Decode phase information transmitted in the bitstream @@ -203,20 +203,20 @@ Word16 FEC_enhACB_fx( move16(); sign = 0; move16(); - IF (P0 < 0) + IF( P0 < 0 ) { sign = 1; move16(); - P0 = negate(P0); + P0 = negate( P0 ); } - IF( EQ_16(L_frame,L_FRAME)) + IF( EQ_16( L_frame, L_FRAME ) ) { - P0 = s_min(PIT_MAX, P0); + P0 = s_min( PIT_MAX, P0 ); } - ELSE /* L_frame == L_FRAME16k */ + ELSE /* L_frame == L_FRAME16k */ { - P0 = s_min(PIT16k_MAX, P0); + P0 = s_min( PIT16k_MAX, P0 ); } /*---------------------------------------------------------------------------------- @@ -228,36 +228,36 @@ Word16 FEC_enhACB_fx( pit_search = Tc; move16(); - Tlist[0] = findpulse_fx( L_frame, exc+sub(L_frame,pit_search) , pit_search,DEC, &sign); + Tlist[0] = findpulse_fx( L_frame, exc + sub( L_frame, pit_search ), pit_search, DEC, &sign ); /*Terr = (short) abs(pit_search-Tlist[0]-P0);*/ - Terr = abs_s(sub(pit_search,add(Tlist[0],P0))); + Terr = abs_s( sub( pit_search, add( Tlist[0], P0 ) ) ); - dist_Plast = sub(Tc,Tlist[0]); + dist_Plast = sub( Tc, Tlist[0] ); - Tlist[1] = findpulse_fx( L_frame, exc+sub(L_frame,pit_search) , add(pit_search,L_SUBFR),DEC, &sign); + Tlist[1] = findpulse_fx( L_frame, exc + sub( L_frame, pit_search ), add( pit_search, L_SUBFR ), DEC, &sign ); /*if(Terr > abs(Tlist[1]-Tc + P0))*/ - IF(GT_16(Terr,abs_s(add(sub(Tlist[1],Tc), P0)))) + IF( GT_16( Terr, abs_s( add( sub( Tlist[1], Tc ), P0 ) ) ) ) { - dist_Plast = sub(Tc,Tlist[1]); - Terr = abs_s(add(sub(Tlist[1],Tc), P0)); + dist_Plast = sub( Tc, Tlist[1] ); + Terr = abs_s( add( sub( Tlist[1], Tc ), P0 ) ); } - diff_pit = abs_s(sub(new_pit, Tc)); + diff_pit = abs_s( sub( new_pit, Tc ) ); /*ftmp = (float) (int)((float)L_frame/(float)Tc+0.5);*/ - tmp2 = mult_r(div_s(16, Tc), shr(L_frame,4)); + tmp2 = mult_r( div_s( 16, Tc ), shr( L_frame, 4 ) ); test(); test(); - IF (LE_16(Terr, i_mult(tmp2, diff_pit))&& - Terr != 0 && /* If Terr = 0, no resynchronization required */ - sub(Terr, L_SUBFR) < 0 )/* prevent catastrophy search */ + IF( LE_16( Terr, i_mult( tmp2, diff_pit ) ) && + Terr != 0 && /* If Terr = 0, no resynchronization required */ + sub( Terr, L_SUBFR ) < 0 ) /* prevent catastrophy search */ { /* performe excitation resynchronization here */ Do_WI = FEC_synchro_exc_fx( L_frame, exc, P0, dist_Plast, Tc ); move16(); - Copy(exc + L_FRAME16k - L_EXC_MEM, exc_io, L_EXC_MEM); + Copy( exc + L_FRAME16k - L_EXC_MEM, exc_io, L_EXC_MEM ); } ELSE { @@ -265,7 +265,7 @@ Word16 FEC_enhACB_fx( move16(); } - if( NE_16(last_L_frame, L_FRAME16k)) + if ( NE_16( last_L_frame, L_FRAME16k ) ) { Do_WI = 0; move16(); @@ -274,20 +274,20 @@ Word16 FEC_enhACB_fx( return Do_WI; } -Word16 FEC_synchro_exc_fx( /* o : do_WI flag */ - const Word16 L_frame, /* i : length of the frame */ - Word16 *exc, /* i/o: exc vector to modify */ - const Word16 desire_puls_pos, /* i : Pulse position send by the encoder */ - const Word16 true_puls_pos, /* i : Present pulse location */ - const Word16 Old_pitch /* i : Pitch use to create temporary adaptive codebook */ +Word16 FEC_synchro_exc_fx( /* o : do_WI flag */ + const Word16 L_frame, /* i : length of the frame */ + Word16 *exc, /* i/o: exc vector to modify */ + const Word16 desire_puls_pos, /* i : Pulse position send by the encoder */ + const Word16 true_puls_pos, /* i : Present pulse location */ + const Word16 Old_pitch /* i : Pitch use to create temporary adaptive codebook */ ) { - Word16 exc_tmp[L_FRAME16k+L_SUBFR]; + Word16 exc_tmp[L_FRAME16k + L_SUBFR]; Word16 fact; Word32 L_min_energy, L_tmp; Word16 *pt_exc, *pt_exc1; Word16 i, j, point_to_remove, point_to_add, nb_min; - Word16 min_pos[L_FRAME16k/PIT_MIN_DOUBLEEXTEND], points_by_pos[L_FRAME16k/PIT_MIN_DOUBLEEXTEND]; + Word16 min_pos[L_FRAME16k / PIT_MIN_DOUBLEEXTEND], points_by_pos[L_FRAME16k / PIT_MIN_DOUBLEEXTEND]; Word16 total_point, tmp_len; Word16 *pt_pos, pos, start_search, tmp16; Word16 remaining_len; @@ -296,7 +296,7 @@ Word16 FEC_synchro_exc_fx( /* o : do_WI flag move16(); /* Init */ - FOR (i = 0; i < L_FRAME16k/PIT_MIN_DOUBLEEXTEND; i++) + FOR( i = 0; i < L_FRAME16k / PIT_MIN_DOUBLEEXTEND; i++ ) { min_pos[i] = 10000; move16(); @@ -305,37 +305,37 @@ Word16 FEC_synchro_exc_fx( /* o : do_WI flag } /* Find number of point to remove and number of minimum */ - point_to_remove = sub(true_puls_pos, desire_puls_pos); /* if it is negative it means remove point else it means add point */ + point_to_remove = sub( true_puls_pos, desire_puls_pos ); /* if it is negative it means remove point else it means add point */ - pos = sub(L_frame, true_puls_pos); + pos = sub( L_frame, true_puls_pos ); /* Find number of minimum energy region */ /* nb_min = (L_FRAME - true_puls_pos)/Old_pitch */ - tmp16 = shl(Old_pitch, 5); - tmp16 = div_s(pos, tmp16); - nb_min = shr(tmp16, 10); + tmp16 = shl( Old_pitch, 5 ); + tmp16 = div_s( pos, tmp16 ); + nb_min = shr( tmp16, 10 ); /* if Old pitch < 128, must have at least 2 min */ - if (LE_16(Old_pitch, 128)) + if ( LE_16( Old_pitch, 128 ) ) { - nb_min = s_max(nb_min, 2); + nb_min = s_max( nb_min, 2 ); } /* Must have at least 1 min */ - nb_min = s_max(nb_min, 1); + nb_min = s_max( nb_min, 1 ); pt_exc = exc + pos; move16(); /* Find starting point for minimum energy search */ - start_search = mult_r(Old_pitch, -24576); - if(EQ_16(s_and(Old_pitch,3),1)) + start_search = mult_r( Old_pitch, -24576 ); + if ( EQ_16( s_and( Old_pitch, 3 ), 1 ) ) { /* Only be align with integer operation -3*Old_pitch/4 */ - start_search = add(start_search,1); + start_search = add( start_search, 1 ); } - IF (add(start_search, pos) < 0) + IF( add( start_search, pos ) < 0 ) { - start_search = negate(pos); - IF (LT_16(abs_s(start_search), shr(Old_pitch, 3))) + start_search = negate( pos ); + IF( LT_16( abs_s( start_search ), shr( Old_pitch, 3 ) ) ) { /* it's not safe to remove/add point inside 1/8 of the pulse position */ return 0; @@ -348,51 +348,51 @@ Word16 FEC_synchro_exc_fx( /* o : do_WI flag * using a sliding 5-sample window. The minimum energy position is set * at the middle of the window at which the energy is at minimum * --------------------------------------------------------------------*/ - L_min_energy = L_add(MAX_32, 0); - L_tmp = L_mult(pt_exc[start_search], pt_exc[start_search]); - L_tmp = L_mac(L_tmp, pt_exc[start_search + 1], pt_exc[start_search + 1]); - L_tmp = L_mac(L_tmp, pt_exc[start_search + 2], pt_exc[start_search + 2]); - L_tmp = L_mac(L_tmp, pt_exc[start_search + 3], pt_exc[start_search + 3]); - L_tmp = L_mac(L_tmp, pt_exc[start_search + 4], pt_exc[start_search + 4]); - - IF (LT_32(L_tmp, L_min_energy)) + L_min_energy = L_add( MAX_32, 0 ); + L_tmp = L_mult( pt_exc[start_search], pt_exc[start_search] ); + L_tmp = L_mac( L_tmp, pt_exc[start_search + 1], pt_exc[start_search + 1] ); + L_tmp = L_mac( L_tmp, pt_exc[start_search + 2], pt_exc[start_search + 2] ); + L_tmp = L_mac( L_tmp, pt_exc[start_search + 3], pt_exc[start_search + 3] ); + L_tmp = L_mac( L_tmp, pt_exc[start_search + 4], pt_exc[start_search + 4] ); + + IF( LT_32( L_tmp, L_min_energy ) ) { - L_min_energy = L_add(L_tmp, 0); - min_pos[0] = add(add(pos, start_search), 2); + L_min_energy = L_add( L_tmp, 0 ); + min_pos[0] = add( add( pos, start_search ), 2 ); } - FOR (i = start_search; i < -5; i++) + FOR( i = start_search; i < -5; i++ ) { - L_tmp = L_msu(L_tmp, pt_exc[i], pt_exc[i]); - L_tmp = L_mac(L_tmp, pt_exc[i + 5], pt_exc[i + 5]); + L_tmp = L_msu( L_tmp, pt_exc[i], pt_exc[i] ); + L_tmp = L_mac( L_tmp, pt_exc[i + 5], pt_exc[i + 5] ); - IF (LT_32(L_tmp, L_min_energy)) + IF( LT_32( L_tmp, L_min_energy ) ) { L_min_energy = L_tmp; /* sets to 'L_tmp' in 1 clock */ - move32(); - min_pos[0] = add(add(pos, i), 2); + move32(); + min_pos[0] = add( add( pos, i ), 2 ); } } - FOR (j = 1; j < nb_min; j++) + FOR( j = 1; j < nb_min; j++ ) { - min_pos[j] = sub(min_pos[j-1], Old_pitch); + min_pos[j] = sub( min_pos[j - 1], Old_pitch ); /* If the first minimum is in the past, forget this minimum */ - IF (min_pos[j] < 0) + IF( min_pos[j] < 0 ) { min_pos[j] = -10000; move16(); - nb_min = sub(nb_min, 1); + nb_min = sub( nb_min, 1 ); } } /* safety-measure against not properly initialized min_pos[] */ - IF( GE_32(L_min_energy, MAX_32)) + IF( GE_32( L_min_energy, MAX_32 ) ) { return 0; } - IF(GT_16(nb_min,16)) /* inv_sqi & sqi are built for a maximum of nb_min-2 = 14 values*/ + IF( GT_16( nb_min, 16 ) ) /* inv_sqi & sqi are built for a maximum of nb_min-2 = 14 values*/ { return 0; } @@ -402,35 +402,35 @@ Word16 FEC_synchro_exc_fx( /* o : do_WI flag * more towards the end of the frame * --------------------------------------------------------------------*/ test(); - IF (EQ_16(nb_min, 1)||EQ_16(abs_s(point_to_remove),1)) + IF( EQ_16( nb_min, 1 ) || EQ_16( abs_s( point_to_remove ), 1 ) ) { nb_min = 1; move16(); - points_by_pos[0] = abs_s(point_to_remove); + points_by_pos[0] = abs_s( point_to_remove ); } ELSE { /* First position */ /* fact = (float)fabs(point_to_remove) / sqi[nb_min-2]; (nb_min*nb_min) */ - fact = mult_r(shl(abs_s(point_to_remove), 7), inv_sqi[nb_min - 2]); /*Q7 */ - points_by_pos[0] = mult_r(fact, 256); /*Q7 */ + fact = mult_r( shl( abs_s( point_to_remove ), 7 ), inv_sqi[nb_min - 2] ); /*Q7 */ + points_by_pos[0] = mult_r( fact, 256 ); /*Q7 */ total_point = points_by_pos[0]; move16(); - FOR (i = 2; i <= nb_min; i++) + FOR( i = 2; i <= nb_min; i++ ) { /* points_by_pos[i-1] = (Word16)(fact*(sqi[i-2]) - total_point+0.5) */ - points_by_pos[i - 1] = sub(shr(extract_l(L_mac0(64L, fact, sqi[i - 2])), 7), total_point); - total_point = add(total_point, points_by_pos[i-1]); + points_by_pos[i - 1] = sub( shr( extract_l( L_mac0( 64L, fact, sqi[i - 2] ) ), 7 ), total_point ); + total_point = add( total_point, points_by_pos[i - 1] ); /* ensure a constant increase */ - IF (LT_16(points_by_pos[i-1], points_by_pos[i-2])) + IF( LT_16( points_by_pos[i - 1], points_by_pos[i - 2] ) ) { - tmp16 = points_by_pos[i-2]; + tmp16 = points_by_pos[i - 2]; move16(); - points_by_pos[i-2] = points_by_pos[i-1]; + points_by_pos[i - 2] = points_by_pos[i - 1]; move16(); - points_by_pos[i-1] = tmp16; + points_by_pos[i - 1] = tmp16; move16(); } } @@ -441,7 +441,7 @@ Word16 FEC_synchro_exc_fx( /* o : do_WI flag * excitation is forced to align to the actual maximum pulse position * at the end of the frame which is transmitted in the future frame. * --------------------------------------------------------------------*/ - if (point_to_remove > 0) + if ( point_to_remove > 0 ) { point_to_add = point_to_remove; move16(); @@ -454,85 +454,84 @@ Word16 FEC_synchro_exc_fx( /* o : do_WI flag i = 0; move16(); - pt_pos = min_pos + sub(nb_min, 1); + pt_pos = min_pos + sub( nb_min, 1 ); - IF (point_to_add > 0)/* Samples insertion */ + IF( point_to_add > 0 ) /* Samples insertion */ { remaining_len = L_frame; move16(); - FOR (i = 0; i < nb_min; i++) + FOR( i = 0; i < nb_min; i++ ) { /* Copy section */ /* Compute len to copy */ tmp_len = *pt_pos; move16(); - IF (i != 0) + IF( i != 0 ) { /* Compute len to copy */ - tmp_len = sub(sub(*pt_pos, *(pt_pos+1)), points_by_pos[i-1]); + tmp_len = sub( sub( *pt_pos, *( pt_pos + 1 ) ), points_by_pos[i - 1] ); } /*Copy section */ - Copy(pt_exc1, pt_exc, tmp_len); - remaining_len = sub(remaining_len, tmp_len); + Copy( pt_exc1, pt_exc, tmp_len ); + remaining_len = sub( remaining_len, tmp_len ); pt_exc1 += tmp_len; move16(); pt_exc += tmp_len; move16(); /* Find point to add and Add points */ - tmp16 = mult_r(*pt_exc1, -1638); - FOR (j = 0; j < points_by_pos[i]; j++) + tmp16 = mult_r( *pt_exc1, -1638 ); + FOR( j = 0; j < points_by_pos[i]; j++ ) { *pt_exc++ = tmp16; - move16();/* repeat last point */ - tmp16 = negate(tmp16); + move16(); /* repeat last point */ + tmp16 = negate( tmp16 ); } - remaining_len = sub(remaining_len, points_by_pos[i]); + remaining_len = sub( remaining_len, points_by_pos[i] ); pt_pos--; } /* Copy remaining data */ - remaining_len = s_max(0, remaining_len); - Copy(pt_exc1, pt_exc, remaining_len); + remaining_len = s_max( 0, remaining_len ); + Copy( pt_exc1, pt_exc, remaining_len ); /* Update true excitation vector */ - Copy(exc_tmp, exc, L_frame); + Copy( exc_tmp, exc, L_frame ); } ELSE /* Samples deletion */ { remaining_len = L_frame; move16(); - FOR (i = 0; i < nb_min; i++) + FOR( i = 0; i < nb_min; i++ ) { /* Compute len to copy */ tmp_len = *pt_pos; move16(); - IF (i != 0) + IF( i != 0 ) { /* Compute len to copy */ - tmp_len = sub(sub(*pt_pos, *(pt_pos+1)), points_by_pos[i-1]); + tmp_len = sub( sub( *pt_pos, *( pt_pos + 1 ) ), points_by_pos[i - 1] ); } - Copy(pt_exc1, pt_exc, tmp_len); - remaining_len = sub(remaining_len, tmp_len); + Copy( pt_exc1, pt_exc, tmp_len ); + remaining_len = sub( remaining_len, tmp_len ); pt_exc1 += tmp_len; move16(); pt_exc += tmp_len; move16(); /* Remove points */ - FOR (j = 0; j < points_by_pos[i]; j++) + FOR( j = 0; j < points_by_pos[i]; j++ ) { pt_exc1++; } pt_pos--; } /* Copy remaining data */ - remaining_len = s_max(0, remaining_len); - Copy(pt_exc1, pt_exc, remaining_len); + remaining_len = s_max( 0, remaining_len ); + Copy( pt_exc1, pt_exc, remaining_len ); /* Update true excitation vector */ - Copy(exc_tmp, exc, L_frame); + Copy( exc_tmp, exc, L_frame ); } return 1; - } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/FEC_clas_estim.c b/lib_dec/FEC_clas_estim.c index 1fb0e735b..b293bdf9a 100644 --- a/lib_dec/FEC_clas_estim.c +++ b/lib_dec/FEC_clas_estim.c @@ -799,4 +799,4 @@ int16_t FEC_pos_dec( return T0; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/FEC_clas_estim_fx.c b/lib_dec/FEC_clas_estim_fx.c index abeaf4ca9..aef047af1 100644 --- a/lib_dec/FEC_clas_estim_fx.c +++ b/lib_dec/FEC_clas_estim_fx.c @@ -3,42 +3,41 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ #include "basop_util.h" /*-------------------------------------------------------------------* * Local function prototypes *-------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -static Word16 FEC_dec_class_fx( Decoder_State *st_fx, Word32 *enr_q); -static void Corre(const Word16 *x,const Word16 *y,const Word16 l,Word16 *gain); +static Word16 FEC_dec_class_fx( Decoder_State *st_fx, Word32 *enr_q ); +static void Corre( const Word16 *x, const Word16 *y, const Word16 l, Word16 *gain ); #endif /*---------------------------------------------------------------------* * Local Constants *---------------------------------------------------------------------*/ -#define UNS6 10923/2 -#define UNS5 13107/2 +#define UNS6 10923 / 2 +#define UNS5 13107 / 2 -#define K_COR_FX 14004 /* Q14 0.8547f <-0.29, 0.88> */ -#define C_COR_FX 266180599 /* Q14+16 0.2479f */ +#define K_COR_FX 14004 /* Q14 0.8547f <-0.29, 0.88> */ +#define C_COR_FX 266180599 /* Q14+16 0.2479f */ -#define K_TILT_FX 13653 /*Q14 0.8333f <-0.35, 0.85> */ -#define C_TILT_FX 313210491 /*Q14+16 0.2917f */ +#define K_TILT_FX 13653 /*Q14 0.8333f <-0.35, 0.85> */ +#define C_TILT_FX 313210491 /*Q14+16 0.2917f */ -#define K_ZC_FX -1310 /*Q15 -0.04f <63, 38> */ -#define C_ZC_FX 2642416 /*11Q20 2.52 */ +#define K_ZC_FX -1310 /*Q15 -0.04f <63, 38> */ +#define C_ZC_FX 2642416 /*11Q20 2.52 */ -#define K_ENR_FX 1311 /*Q15 0.04 <-14, 11> */ -#define C_ENR_FX 9395241 /*Q8+16 0.56f */ - -#define K_PC_FX -1169 /*Q15 -0.0357f <45, 17> */ -#define C_PC_FX 105323 /*Q0+16 1.6071f */ +#define K_ENR_FX 1311 /*Q15 0.04 <-14, 11> */ +#define C_ENR_FX 9395241 /*Q8+16 0.56f */ +#define K_PC_FX -1169 /*Q15 -0.0357f <45, 17> */ +#define C_PC_FX 105323 /*Q0+16 1.6071f */ /*======================================================================*/ @@ -51,161 +50,185 @@ static void Corre(const Word16 *x,const Word16 *y,const Word16 l,Word16 *gain); #ifdef IVAS_FLOAT_FIXED void FEC_clas_estim_fx( - Decoder_State *st_fx , /* i/o: decoder state handle */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ /*A*/ - const Word16 L_frame, /* i : length of the frame */ - Word16 *clas, /* i/o: frame classification */ - const Word16 coder_type, /* i : coder type */ - const Word16 *pitch, /* i : pitch values for each subframe (Q6)*/ - Word16 *syn, /* i : synthesis buffer */ - Word16 *lp_speech, /* i/o: long term active speech energy average Q8 */ - Word16 *decision_hyst, /* i/o: hysteresis of the music/speech decision */ /*A*/ - Word16 *UV_cnt, /* i/o: number of consecutives frames classified as UV */ /*A*/ - Word16 *LT_UV_cnt, /* i/o: long term consecutives frames classified as UV */ /*A*/ - Word16 *Last_ener, /* i/o: last_energy frame */ /*A*/ - Word16 *locattack, /* i/o: detection of attack (mainly to localized speech burst) */ /*A*/ - Word16 *lt_diff_etot, /* i/o: long-term total energy variation */ /*A*/ - Word16 *amr_io_class, /* i/o: classification for AMR-WB IO mode */ /*A*/ - const Word32 bitrate, /* i : Decoded bitrate */ /*A*/ - Word16 Q_syn, /* i : Synthesis scaling */ - Word16 *class_para, /* o : classification para. fmerit1 */ /*A*/ - Word16 *mem_syn_clas_estim, /* i/o: memory of the synthesis signal for frame class estimation */ - Word16 *Q_mem_syn, /* i/o: exponent for memory of synthesis signal for frame class estimation */ /*B*/ - Word16 LTP_Gain, /* i : LTP gain is 0..0.6 or -1 Q15 *//*B*/ - Word16 mode, /* i : signal classifier mode *//*B*/ - Word16 bfi, /* i : bad frame indicator *//*B*/ - Word32 last_core_brate, /* i : bitrate of previous frame */ - const int16_t FEC_mode /* i : ACELP FEC mode */ + Decoder_State *st_fx, /* i/o: decoder state handle */ + const Word16 Opt_AMR_WB, + /* i : flag indicating AMR-WB IO mode */ /*A*/ + const Word16 L_frame, /* i : length of the frame */ + Word16 *clas, /* i/o: frame classification */ + const Word16 coder_type, /* i : coder type */ + const Word16 *pitch, /* i : pitch values for each subframe (Q6)*/ + Word16 *syn, /* i : synthesis buffer */ + Word16 *lp_speech, /* i/o: long term active speech energy average Q8 */ + Word16 *decision_hyst, + /* i/o: hysteresis of the music/speech decision */ /*A*/ + Word16 *UV_cnt, + /* i/o: number of consecutives frames classified as UV */ /*A*/ + Word16 *LT_UV_cnt, + /* i/o: long term consecutives frames classified as UV */ /*A*/ + Word16 *Last_ener, + /* i/o: last_energy frame */ /*A*/ + Word16 *locattack, + /* i/o: detection of attack (mainly to localized speech burst) */ /*A*/ + Word16 *lt_diff_etot, + /* i/o: long-term total energy variation */ /*A*/ + Word16 *amr_io_class, + /* i/o: classification for AMR-WB IO mode */ /*A*/ + const Word32 bitrate, + /* i : Decoded bitrate */ /*A*/ + Word16 Q_syn, /* i : Synthesis scaling */ + Word16 *class_para, + /* o : classification para. fmerit1 */ /*A*/ + Word16 *mem_syn_clas_estim, /* i/o: memory of the synthesis signal for frame class estimation */ + Word16 *Q_mem_syn, + /* i/o: exponent for memory of synthesis signal for frame class estimation */ /*B*/ + Word16 LTP_Gain, + /* i : LTP gain is 0..0.6 or -1 Q15 */ /*B*/ + Word16 mode, + /* i : signal classifier mode */ /*B*/ + Word16 bfi, + /* i : bad frame indicator */ /*B*/ + Word32 last_core_brate, /* i : bitrate of previous frame */ + const int16_t FEC_mode /* i : ACELP FEC mode */ ) { Word16 i, j, pos; - Word16 *pt1, *pt2, zc_frame, frame_ener =1 ,tmp_scale=0, tmp_scale_syn, tmp_scale_mem; - Word16 tiltn, corn, zcn, pcn, fmerit1, enern, ener = 0/*not necessary, just to quiet a warning so not cmplxty counted*/, tilt, diff_ener; + Word16 *pt1, *pt2, zc_frame, frame_ener = 1, tmp_scale = 0, tmp_scale_syn, tmp_scale_mem; + Word16 tiltn, corn, zcn, pcn, fmerit1, enern, ener = 0 /*not necessary, just to quiet a warning so not cmplxty counted*/, tilt, diff_ener; Word16 voicing, cor_max[4], *synth, tmp16, exp1, exp2; Word32 Ltmp, Ltmp1; Word16 tmpS, T0, pc, /*max,*/ tmp_x, tmp_y; Word16 old_synth[L_SYN_MEM_CLAS_ESTIM + L_FRAME16k]; Word16 nb_subfr; Word16 pos_limit; - Word16 codec_mode, narrowBand, tcxonly,preemph_fac; + Word16 codec_mode, narrowBand, tcxonly, preemph_fac; Word16 memmax; - nb_subfr = shr(L_frame,6); + nb_subfr = shr( L_frame, 6 ); memmax = 0; move16(); tmp_scale_syn = 0; move16(); - codec_mode = st_fx->codec_mode; - tcxonly = st_fx->tcxonly; /* i : tcxonly flag *//*B*/ - narrowBand = st_fx->narrowBand; /* i : narrowband flag *//*B*/ - preemph_fac = st_fx->preemph_fac; /* i : preemphasis factor *//*B*/ + codec_mode = st_fx->codec_mode; + tcxonly = st_fx->tcxonly; /* i : tcxonly flag */ /*B*/ + narrowBand = st_fx->narrowBand; /* i : narrowband flag */ /*B*/ + preemph_fac = st_fx->preemph_fac; /* i : preemphasis factor */ /*B*/ /*------------------------------------------------------------------------* * Copy synthesized into local buffer *------------------------------------------------------------------------*/ /* After Rate Switching st->last_core is reset to 0. Check for last_core_brate is needed */ - test();test();test();test();test();test();test();test();test();test();test(); - IF((EQ_32(last_core_brate, SID_1k75)||EQ_32(last_core_brate,ACELP_6k60)||EQ_32(last_core_brate,ACELP_8k85) - || EQ_32(last_core_brate, ACELP_12k65) || EQ_32(last_core_brate, ACELP_14k25) || EQ_32(last_core_brate, ACELP_15k85) - || EQ_32(last_core_brate, ACELP_18k25) || EQ_32(last_core_brate, ACELP_19k85) || EQ_32(last_core_brate, ACELP_23k05) - || EQ_32(last_core_brate, ACELP_23k85)) && !Opt_AMR_WB && EQ_16(codec_mode, MODE2) - && GT_16(L_frame,L_FRAME) ) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( EQ_32( last_core_brate, SID_1k75 ) || EQ_32( last_core_brate, ACELP_6k60 ) || EQ_32( last_core_brate, ACELP_8k85 ) || EQ_32( last_core_brate, ACELP_12k65 ) || EQ_32( last_core_brate, ACELP_14k25 ) || EQ_32( last_core_brate, ACELP_15k85 ) || EQ_32( last_core_brate, ACELP_18k25 ) || EQ_32( last_core_brate, ACELP_19k85 ) || EQ_32( last_core_brate, ACELP_23k05 ) || EQ_32( last_core_brate, ACELP_23k85 ) ) && !Opt_AMR_WB && EQ_16( codec_mode, MODE2 ) && GT_16( L_frame, L_FRAME ) ) { Word16 oldLenClasBuff, newLenClasBuff; - oldLenClasBuff = extract_l(L_shr(Mpy_32_16_1(L_mult0(st_fx->last_L_frame,getInvFrameLen(st_fx->L_frame)/*Q21*/)/*Q21*/,L_SYN_MEM_CLAS_ESTIM/*Q0*/)/*Q6*/,6)/*Q0*/); + oldLenClasBuff = extract_l( L_shr( Mpy_32_16_1( L_mult0( st_fx->last_L_frame, getInvFrameLen( st_fx->L_frame ) /*Q21*/ ) /*Q21*/, L_SYN_MEM_CLAS_ESTIM /*Q0*/ ) /*Q6*/, 6 ) /*Q0*/ ); newLenClasBuff = L_SYN_MEM_CLAS_ESTIM; move16(); - lerp( &mem_syn_clas_estim[L_SYN_MEM_CLAS_ESTIM-oldLenClasBuff], &mem_syn_clas_estim[L_SYN_MEM_CLAS_ESTIM-newLenClasBuff], newLenClasBuff, oldLenClasBuff ); + lerp( &mem_syn_clas_estim[L_SYN_MEM_CLAS_ESTIM - oldLenClasBuff], &mem_syn_clas_estim[L_SYN_MEM_CLAS_ESTIM - newLenClasBuff], newLenClasBuff, oldLenClasBuff ); } - synth = old_synth + L_SYN_MEM_CLAS_ESTIM; + synth = old_synth + L_SYN_MEM_CLAS_ESTIM; /*Rescale synthesis mem buffer or synthesis buffer, if necessary - allign them to the same scaling in case of switching MODE2->MODE1*/ - IF(EQ_16(codec_mode, MODE2)) + IF( EQ_16( codec_mode, MODE2 ) ) { - memmax=1; + memmax = 1; move16(); /*find maximum of mem syn*/ - FOR(i=0; i0) /*mem syn is bigger, scale it down*/ + tmp_scale = sub( *Q_mem_syn, Q_syn ); + IF( tmp_scale > 0 ) /*mem syn is bigger, scale it down*/ { - tmp_scale_mem = negate(tmp_scale); - Scale_sig(mem_syn_clas_estim, L_SYN_MEM_CLAS_ESTIM, tmp_scale_mem); + tmp_scale_mem = negate( tmp_scale ); + Scale_sig( mem_syn_clas_estim, L_SYN_MEM_CLAS_ESTIM, tmp_scale_mem ); } ELSE /*synthesis is bigger, scale it down*/ { /*check for upscaling mem syn, first*/ - tmp_scale_mem = norm_s(sub(memmax,1)); - if (EQ_16(memmax,1)) + tmp_scale_mem = norm_s( sub( memmax, 1 ) ); + if ( EQ_16( memmax, 1 ) ) { tmp_scale_mem = 14; move16(); } - tmp_scale_syn = sub(add(*Q_mem_syn, tmp_scale_mem), Q_syn); /*if this is negative, syn can be scaled down*/ + tmp_scale_syn = sub( add( *Q_mem_syn, tmp_scale_mem ), Q_syn ); /*if this is negative, syn can be scaled down*/ test(); - IF(tmp_scale_syn > 0 || EQ_16(mode , 1/*CLASSIFIER_TCX*/)) /*dont scale up syn, but scale mem_syn, adequately*/ + IF( tmp_scale_syn > 0 || EQ_16( mode, 1 /*CLASSIFIER_TCX*/ ) ) /*dont scale up syn, but scale mem_syn, adequately*/ { - tmp_scale_mem = sub(tmp_scale_mem,tmp_scale_syn); + tmp_scale_mem = sub( tmp_scale_mem, tmp_scale_syn ); tmp_scale_syn = 0; move16(); } Scale_sig( mem_syn_clas_estim, L_SYN_MEM_CLAS_ESTIM, tmp_scale_mem ); - *Q_mem_syn = add(*Q_mem_syn, tmp_scale_mem); + *Q_mem_syn = add( *Q_mem_syn, tmp_scale_mem ); } - } tmp_scale = -1; move16(); Copy_Scale_sig( mem_syn_clas_estim, old_synth, L_SYN_MEM_CLAS_ESTIM, tmp_scale ); - Copy_Scale_sig( syn, synth, L_frame, add(tmp_scale_syn, tmp_scale) ); + Copy_Scale_sig( syn, synth, L_frame, add( tmp_scale_syn, tmp_scale ) ); /*Tell MODE2 decoder the scaling of the buffer*/ - *Q_mem_syn = add(add(Q_syn, tmp_scale_syn), tmp_scale); + *Q_mem_syn = add( add( Q_syn, tmp_scale_syn ), tmp_scale ); /**Q_mem_syn = *Q_syn; move16();*/ test(); - IF(EQ_16(codec_mode,MODE2)&&EQ_16(mode,1/*CLASSIFIER_TCX*/)) + IF( EQ_16( codec_mode, MODE2 ) && EQ_16( mode, 1 /*CLASSIFIER_TCX*/ ) ) { /* TCX outputs non-pe-speech */ move16(); - tmp16 = shl(syn[-1],tmp_scale); /*dont forget to scale the mem*/ - preemph_copy_fx(synth, synth, preemph_fac, L_frame, &tmp16); + tmp16 = shl( syn[-1], tmp_scale ); /*dont forget to scale the mem*/ + preemph_copy_fx( synth, synth, preemph_fac, L_frame, &tmp16 ); } /*------------------------------------------------------------------------* - * GC, TC and AC frames - *------------------------------------------------------------------------*/ + * GC, TC and AC frames + *------------------------------------------------------------------------*/ /* Do the classification only - MODE1: when the class is not transmitted in the bitstream - MODE2: on good frames (classifier is also called for bfi=1) */ - test();test();test();test();test();test(); - IF (( EQ_16(codec_mode , MODE1) && (FEC_mode == 0 || LE_16(coder_type , UNVOICED) || Opt_AMR_WB)) || (EQ_16(codec_mode , MODE2) && NE_16(bfi,1) && !tcxonly )) + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( EQ_16( codec_mode, MODE1 ) && ( FEC_mode == 0 || LE_16( coder_type, UNVOICED ) || Opt_AMR_WB ) ) || ( EQ_16( codec_mode, MODE2 ) && NE_16( bfi, 1 ) && !tcxonly ) ) { /*------------------------------------------------------------------------* - * Overwrite classification decision using coder_type information - *------------------------------------------------------------------------*/ + * Overwrite classification decision using coder_type information + *------------------------------------------------------------------------*/ test(); - IF( EQ_16(coder_type,VOICED)) + IF( EQ_16( coder_type, VOICED ) ) { *clas = VOICED_CLAS; move16(); } - ELSE IF( EQ_16(coder_type,UNVOICED)) + ELSE IF( EQ_16( coder_type, UNVOICED ) ) { *clas = UNVOICED_CLAS; move16(); } - ELSE IF( EQ_16(coder_type,INACTIVE)&&!Opt_AMR_WB) + ELSE IF( EQ_16( coder_type, INACTIVE ) && !Opt_AMR_WB ) { *clas = INACTIVE_CLAS; move16(); @@ -213,226 +236,226 @@ void FEC_clas_estim_fx( ELSE { /*------------------------------------------------------------------------* - * Compute the zero crossing rate for all subframes - *------------------------------------------------------------------------*/ + * Compute the zero crossing rate for all subframes + *------------------------------------------------------------------------*/ - pt1 = (Word16 *)synth - 1; + pt1 = (Word16 *) synth - 1; move16(); - tmpS = shr(*pt1, 15); /* sets 'tmpS to -1 if *pt1 < 0 */ - Ltmp = L_deposit_l(0); - FOR (j = 0; j < L_SUBFR*nb_subfr; j++) + tmpS = shr( *pt1, 15 ); /* sets 'tmpS to -1 if *pt1 < 0 */ + Ltmp = L_deposit_l( 0 ); + FOR( j = 0; j < L_SUBFR * nb_subfr; j++ ) { - tmp16 = add(1, tmpS); + tmp16 = add( 1, tmpS ); pt1++; - if(*pt1 != 0) /* Do only count zero crossing, no zero touchings */ + if ( *pt1 != 0 ) /* Do only count zero crossing, no zero touchings */ { - tmpS = shr(*pt1, 15); /* 1Clk: >=0 ---> 0 OTHERWISE -1 */ + tmpS = shr( *pt1, 15 ); /* 1Clk: >=0 ---> 0 OTHERWISE -1 */ } - Ltmp = L_msu0(Ltmp, tmpS, tmp16); + Ltmp = L_msu0( Ltmp, tmpS, tmp16 ); } - zc_frame = shl(extract_l(Ltmp),4); /* Q4 */ + zc_frame = shl( extract_l( Ltmp ), 4 ); /* Q4 */ - if( EQ_16(L_frame,L_FRAME16k)) + if ( EQ_16( L_frame, L_FRAME16k ) ) { - /*zc_frame *= 0.8f;*/ /* Renormalization for 12.8kHz core*/ - zc_frame = mult_r(zc_frame, 26214); + /*zc_frame *= 0.8f;*/ /* Renormalization for 12.8kHz core*/ + zc_frame = mult_r( zc_frame, 26214 ); } /*------------------------------------------------------------------------* * Compute the normalized correlation pitch-synch. at the end of the frame *------------------------------------------------------------------------*/ - T0 = shr(pitch[3], 6); - Ltmp1 = L_mult(pitch[3], 256); + T0 = shr( pitch[3], 6 ); + Ltmp1 = L_mult( pitch[3], 256 ); - if (GT_16(T0, L_SUBFR*3/2)) + if ( GT_16( T0, L_SUBFR * 3 / 2 ) ) { - T0 = mac_r(Ltmp1, pitch[2], 256); + T0 = mac_r( Ltmp1, pitch[2], 256 ); } pt1 = synth; move16(); - pos = sub(L_frame, T0); /* T0 [34 231] */ + pos = sub( L_frame, T0 ); /* T0 [34 231] */ - Corre(&pt1[pos], &pt1[pos-T0], T0, &cor_max[0]); + Corre( &pt1[pos], &pt1[pos - T0], T0, &cor_max[0] ); #ifdef BASOP_NOGLOB - T0 = mult_r_sat(add_sat(pitch[2], pitch[3]), 256); + T0 = mult_r_sat( add_sat( pitch[2], pitch[3] ), 256 ); #else - T0 = mult_r(add(pitch[2], pitch[3]), 256); + T0 = mult_r( add( pitch[2], pitch[3] ), 256 ); #endif - pos_limit = sub(L_frame, L_SUBFR); - j = s_min(1, s_max(0, sub(pos, pos_limit))); - Ltmp = L_deposit_l(cor_max[0]); - IF (j > 0) + pos_limit = sub( L_frame, L_SUBFR ); + j = s_min( 1, s_max( 0, sub( pos, pos_limit ) ) ); + Ltmp = L_deposit_l( cor_max[0] ); + IF( j > 0 ) { j = 16384; move16(); - pos = sub(pos, T0); /* T0 [34 231] */ - Corre(&pt1[pos], &pt1[pos-T0], T0, &cor_max[1]); - Ltmp = L_add(Ltmp, cor_max[1]); - IF (GT_16(pos, pos_limit)) + pos = sub( pos, T0 ); /* T0 [34 231] */ + Corre( &pt1[pos], &pt1[pos - T0], T0, &cor_max[1] ); + Ltmp = L_add( Ltmp, cor_max[1] ); + IF( GT_16( pos, pos_limit ) ) { j = 10923; move16(); - pos = sub(pos, T0); /* T0 [34 231] */ - Corre(&pt1[pos], &pt1[pos-T0], T0, &cor_max[2]); - Ltmp = L_add(Ltmp, cor_max[2]); + pos = sub( pos, T0 ); /* T0 [34 231] */ + Corre( &pt1[pos], &pt1[pos - T0], T0, &cor_max[2] ); + Ltmp = L_add( Ltmp, cor_max[2] ); } - IF (GT_16(pos, pos_limit)) + IF( GT_16( pos, pos_limit ) ) { j = 8192; move16(); - pos = sub(pos, T0); /* T0 [34 231] */ - Corre(&pt1[pos], &pt1[pos-T0], T0, &cor_max[3]); - Ltmp = L_add(Ltmp, cor_max[3]); + pos = sub( pos, T0 ); /* T0 [34 231] */ + Corre( &pt1[pos], &pt1[pos - T0], T0, &cor_max[3] ); + Ltmp = L_add( Ltmp, cor_max[3] ); } } voicing = cor_max[0]; move16(); - IF(j > 0) + IF( j > 0 ) { - voicing = extract_l(Mult_32_16(Ltmp, j)); + voicing = extract_l( Mult_32_16( Ltmp, j ) ); } /*------------------------------------------------------------------------* - * Compute pitch coherence - *------------------------------------------------------------------------*/ + * Compute pitch coherence + *------------------------------------------------------------------------*/ pc = 0; move16(); test(); test(); - IF (EQ_16(codec_mode , MODE1)||!(NE_16(LTP_Gain,-32768/*-1.f Q15*/)&&EQ_16(mode,CLASSIFIER_TCX))) + IF( EQ_16( codec_mode, MODE1 ) || !( NE_16( LTP_Gain, -32768 /*-1.f Q15*/ ) && EQ_16( mode, CLASSIFIER_TCX ) ) ) { #ifdef BASOP_NOGLOB - pc = shr(abs_s(sub(add_sat(pitch[3], sub(pitch[2], pitch[1])), pitch[0])), 6); + pc = shr( abs_s( sub( add_sat( pitch[3], sub( pitch[2], pitch[1] ) ), pitch[0] ) ), 6 ); #else - pc = shr(abs_s(sub(add(pitch[3], sub(pitch[2], pitch[1])), pitch[0])), 6); + pc = shr( abs_s( sub( add( pitch[3], sub( pitch[2], pitch[1] ) ), pitch[0] ) ), 6 ); #endif - if(EQ_16(L_frame,L_FRAME16k)) + if ( EQ_16( L_frame, L_FRAME16k ) ) { - pc = mult_r(pc, 26214); /* Renormalization for 12.8kHz core*/ + pc = mult_r( pc, 26214 ); /* Renormalization for 12.8kHz core*/ } } /*------------------------------------------------------------------------* * Compute spectral tilt *------------------------------------------------------------------------*/ - pt1 = (Word16 *)synth + L_SUBFR; + pt1 = (Word16 *) synth + L_SUBFR; move16(); - pt2 = (Word16 *)synth + L_SUBFR - 1; + pt2 = (Word16 *) synth + L_SUBFR - 1; move16(); - Ltmp = L_mult0(*pt1, *pt1); - Ltmp1 = L_mult0(*pt1, *pt2); - FOR(j = 1; j < L_SUBFR*(nb_subfr-1); j++) + Ltmp = L_mult0( *pt1, *pt1 ); + Ltmp1 = L_mult0( *pt1, *pt2 ); + FOR( j = 1; j < L_SUBFR * ( nb_subfr - 1 ); j++ ) { pt1++; pt2++; #ifdef BASOP_NOGLOB - Ltmp = L_mac0_sat(Ltmp, *pt1, *pt1); - Ltmp1 = L_mac0_sat(Ltmp1, *pt1, *pt2); + Ltmp = L_mac0_sat( Ltmp, *pt1, *pt1 ); + Ltmp1 = L_mac0_sat( Ltmp1, *pt1, *pt2 ); #else - Ltmp = L_mac0(Ltmp, *pt1, *pt1); - Ltmp1 = L_mac0(Ltmp1, *pt1, *pt2); + Ltmp = L_mac0( Ltmp, *pt1, *pt1 ); + Ltmp1 = L_mac0( Ltmp1, *pt1, *pt2 ); #endif } tilt = 0; move16(); - IF (Ltmp != 0) + IF( Ltmp != 0 ) { BASOP_SATURATE_WARNING_OFF_EVS - tmp16 = extract_l(L_or(L_shr(Ltmp1, 32), 1)); /* sets a flag -1 or 1 for sign of Ltmp1 */ + tmp16 = extract_l( L_or( L_shr( Ltmp1, 32 ), 1 ) ); /* sets a flag -1 or 1 for sign of Ltmp1 */ BASOP_SATURATE_WARNING_ON_EVS - Ltmp1 = L_abs(Ltmp1); - exp1 = norm_l(Ltmp1); - tmp_y = extract_h(L_shl(Ltmp1, exp1)); - exp1 = sub(31-1+3, exp1); - exp2 = norm_l(Ltmp); - tmp_x = extract_h(L_shl(Ltmp, exp2)); - exp2 = sub(31-1+3, exp2); + Ltmp1 = L_abs( Ltmp1 ); + exp1 = norm_l( Ltmp1 ); + tmp_y = extract_h( L_shl( Ltmp1, exp1 ) ); + exp1 = sub( 31 - 1 + 3, exp1 ); + exp2 = norm_l( Ltmp ); + tmp_x = extract_h( L_shl( Ltmp, exp2 ) ); + exp2 = sub( 31 - 1 + 3, exp2 ); BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB tmpS = shr( sub_sat( tmp_x, tmp_y ), 16 ); /* if tmp_x >= tmp_y tmpS = 0, -1 otherwise */ #else - tmpS = shr(sub(tmp_x, tmp_y), 16); /* if tmp_x >= tmp_y tmpS = 0, -1 otherwise */ + tmpS = shr( sub( tmp_x, tmp_y ), 16 ); /* if tmp_x >= tmp_y tmpS = 0, -1 otherwise */ #endif BASOP_SATURATE_WARNING_ON_EVS - tmp_y = shl(tmp_y, tmpS); - exp1 = sub(exp1, tmpS); + tmp_y = shl( tmp_y, tmpS ); + exp1 = sub( exp1, tmpS ); - tilt = div_s(tmp_y, tmp_x); + tilt = div_s( tmp_y, tmp_x ); #ifdef BASOP_NOGLOB - tilt = shl_sat(tilt, sub(exp1, exp2)); /* saturate to 1.0 */ + tilt = shl_sat( tilt, sub( exp1, exp2 ) ); /* saturate to 1.0 */ #else - tilt = shl(tilt, sub(exp1, exp2)); /* saturate to 1.0 */ + tilt = shl( tilt, sub( exp1, exp2 ) ); /* saturate to 1.0 */ #endif - tilt = i_mult2(tilt, tmp16); + tilt = i_mult2( tilt, tmp16 ); } /*------------------------------------------------------------------------* * Compute pitch-synchronous energy at the frame end *------------------------------------------------------------------------*/ - ener = frame_energy_fx(L_frame, pitch, synth, *lp_speech, &frame_ener, *Q_mem_syn); + ener = frame_energy_fx( L_frame, pitch, synth, *lp_speech, &frame_ener, *Q_mem_syn ); /*------------------------------------------------------------------------* * transform parameters between 0 & 1 * find unique merit function *------------------------------------------------------------------------*/ - enern = mac_r(C_ENR_FX, K_ENR_FX, ener); /*Q8*/ + enern = mac_r( C_ENR_FX, K_ENR_FX, ener ); /*Q8*/ - tiltn = extract_h(L_shr(L_mac(C_TILT_FX, K_TILT_FX, tilt), 6)); /*Q14 -> Q8*/ + tiltn = extract_h( L_shr( L_mac( C_TILT_FX, K_TILT_FX, tilt ), 6 ) ); /*Q14 -> Q8*/ - corn = extract_h(L_shr(L_mac(C_COR_FX, K_COR_FX, voicing), 6)); /*Q14 -> Q8*/ + corn = extract_h( L_shr( L_mac( C_COR_FX, K_COR_FX, voicing ), 6 ) ); /*Q14 -> Q8*/ - zcn = extract_h(L_shl(L_mac(C_ZC_FX, K_ZC_FX, zc_frame), 4)); /* Q4 -> Q8*/ + zcn = extract_h( L_shl( L_mac( C_ZC_FX, K_ZC_FX, zc_frame ), 4 ) ); /* Q4 -> Q8*/ BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB - tmp16 = sub_sat(LTP_Gain, -32768/*-1.f Q15*/); + tmp16 = sub_sat( LTP_Gain, -32768 /*-1.f Q15*/ ); #else - tmp16 = sub(LTP_Gain , -32768/*-1.f Q15*/); + tmp16 = sub( LTP_Gain, -32768 /*-1.f Q15*/ ); #endif BASOP_SATURATE_WARNING_ON_EVS test(); test(); - IF ( EQ_16(codec_mode , MODE2)&&tmp16!=0&&EQ_16(mode,CLASSIFIER_TCX)) + IF( EQ_16( codec_mode, MODE2 ) && tmp16 != 0 && EQ_16( mode, CLASSIFIER_TCX ) ) { - pcn = round_fx(L_shl(Mpy_32_16_1(C_PC_FX/*Q16*/, LTP_Gain/*Q15*/),8)); /*Q16*/ + pcn = round_fx( L_shl( Mpy_32_16_1( C_PC_FX /*Q16*/, LTP_Gain /*Q15*/ ), 8 ) ); /*Q16*/ } ELSE { - pcn = extract_h(L_shl(L_mac(C_PC_FX, K_PC_FX, pc),8)); /* Q0 -> Q8*/ + pcn = extract_h( L_shl( L_mac( C_PC_FX, K_PC_FX, pc ), 8 ) ); /* Q0 -> Q8*/ } - pcn = s_min(256, pcn); - pcn = s_max( 0, pcn); + pcn = s_min( 256, pcn ); + pcn = s_max( 0, pcn ); /* fmerit1 = (1.0f/6.0f) * (tiltn + 2.0f*corn + zcn + pcn + enern) */ - Ltmp = L_mult(tiltn, UNS6); - Ltmp = L_mac(Ltmp, corn, 2*UNS6); - Ltmp = L_mac(Ltmp, zcn, UNS6); - Ltmp = L_mac(Ltmp, pcn, UNS6); - Ltmp = L_mac(Ltmp, enern, UNS6); + Ltmp = L_mult( tiltn, UNS6 ); + Ltmp = L_mac( Ltmp, corn, 2 * UNS6 ); + Ltmp = L_mac( Ltmp, zcn, UNS6 ); + Ltmp = L_mac( Ltmp, pcn, UNS6 ); + Ltmp = L_mac( Ltmp, enern, UNS6 ); BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB - fmerit1 = round_fx_sat(L_shl_sat(Ltmp, 15 - 8)); /*Q15 can saturate to 1.0 */ + fmerit1 = round_fx_sat( L_shl_sat( Ltmp, 15 - 8 ) ); /*Q15 can saturate to 1.0 */ #else - fmerit1 = round_fx(L_shl(Ltmp, 15-8)); /*Q15 can saturate to 1.0 */ + fmerit1 = round_fx( L_shl( Ltmp, 15 - 8 ) ); /*Q15 can saturate to 1.0 */ #endif BASOP_SATURATE_WARNING_ON_EVS test(); - if ( EQ_16(codec_mode,MODE2)&&narrowBand!=0) + if ( EQ_16( codec_mode, MODE2 ) && narrowBand != 0 ) { - fmerit1 = mult_r(fmerit1, 29491/*0.9f Q15*/); /* 0.90 */ + fmerit1 = mult_r( fmerit1, 29491 /*0.9f Q15*/ ); /* 0.90 */ } - IF(EQ_16(codec_mode, MODE1)) + IF( EQ_16( codec_mode, MODE1 ) ) { - *class_para = round_fx(L_shl(Ltmp, 14-8)); /*Q14 - cannot be saturated, degrades HF synthesis */ + *class_para = round_fx( L_shl( Ltmp, 14 - 8 ) ); /*Q14 - cannot be saturated, degrades HF synthesis */ } /*------------------------------------------------------------------------* @@ -440,55 +463,53 @@ void FEC_clas_estim_fx( *------------------------------------------------------------------------*/ test(); test(); - if ( (NE_16(coder_type,VOICED)&<_32(bitrate,ACELP_11k60))||Opt_AMR_WB) + if ( ( NE_16( coder_type, VOICED ) && LT_32( bitrate, ACELP_11k60 ) ) || Opt_AMR_WB ) { - Word16 result = UNVOICED_CLAS; + Word16 result = UNVOICED_CLAS; move16(); SWITCH( *clas ) { - case VOICED_CLAS: - case ONSET: - case SIN_ONSET: - case VOICED_TRANSITION: - IF(LT_16(fmerit1, 12780/*0.39f Q15*/)) - { - result = UNVOICED_CLAS; - move16(); - } - ELSE IF(LT_16(fmerit1, 20644/*0.63f Q15*/) - && (LT_16(ener,-3840) || EQ_16(codec_mode,MODE2))) - { - result = VOICED_TRANSITION; - move16(); - } - ELSE - { - result = VOICED_CLAS; - move16(); - } - - BREAK; - - case UNVOICED_CLAS: - case UNVOICED_TRANSITION: - case INACTIVE_CLAS: - IF( GT_16(fmerit1, 18350/*0.56f Q15*/)) - { - result = ONSET; - move16(); - } - ELSE IF( GT_16(fmerit1, 14746/*0.45f Q15*/)) - { - result = UNVOICED_TRANSITION; - move16(); - } - ELSE - { - result = UNVOICED_CLAS; - move16(); - } - BREAK; - + case VOICED_CLAS: + case ONSET: + case SIN_ONSET: + case VOICED_TRANSITION: + IF( LT_16( fmerit1, 12780 /*0.39f Q15*/ ) ) + { + result = UNVOICED_CLAS; + move16(); + } + ELSE IF( LT_16( fmerit1, 20644 /*0.63f Q15*/ ) && ( LT_16( ener, -3840 ) || EQ_16( codec_mode, MODE2 ) ) ) + { + result = VOICED_TRANSITION; + move16(); + } + ELSE + { + result = VOICED_CLAS; + move16(); + } + + BREAK; + + case UNVOICED_CLAS: + case UNVOICED_TRANSITION: + case INACTIVE_CLAS: + IF( GT_16( fmerit1, 18350 /*0.56f Q15*/ ) ) + { + result = ONSET; + move16(); + } + ELSE IF( GT_16( fmerit1, 14746 /*0.45f Q15*/ ) ) + { + result = UNVOICED_TRANSITION; + move16(); + } + ELSE + { + result = UNVOICED_CLAS; + move16(); + } + BREAK; } *clas = result; move16(); @@ -496,34 +517,33 @@ void FEC_clas_estim_fx( } - - IF(EQ_16(codec_mode,MODE1)) + IF( EQ_16( codec_mode, MODE1 ) ) { /*------------------------------------------------------------------------* * Overwrite classification decision in case of music *------------------------------------------------------------------------*/ - IF( EQ_16(coder_type,AUDIO)) + IF( EQ_16( coder_type, AUDIO ) ) { - (*decision_hyst) = add(*decision_hyst,4); + ( *decision_hyst ) = add( *decision_hyst, 4 ); move16(); } ELSE { - (*decision_hyst) = sub(*decision_hyst,1); + ( *decision_hyst ) = sub( *decision_hyst, 1 ); move16(); } - if( EQ_16(coder_type,INACTIVE)) + if ( EQ_16( coder_type, INACTIVE ) ) { - *decision_hyst = sub(*decision_hyst,10); + *decision_hyst = sub( *decision_hyst, 10 ); move16(); } - IF( GT_16(*decision_hyst,200)) + IF( GT_16( *decision_hyst, 200 ) ) { *decision_hyst = 200; move16(); } - ELSE if( *decision_hyst < 0 ) + ELSE if ( *decision_hyst < 0 ) { *decision_hyst = 0; move16(); @@ -531,7 +551,7 @@ void FEC_clas_estim_fx( test(); test(); - if( GT_16(*decision_hyst,16)&<_16(*clas,VOICED_CLAS)&&EQ_16(coder_type,AUDIO)) + if ( GT_16( *decision_hyst, 16 ) && LT_16( *clas, VOICED_CLAS ) && EQ_16( coder_type, AUDIO ) ) { *clas = VOICED_CLAS; move16(); @@ -541,34 +561,32 @@ void FEC_clas_estim_fx( /*---------------------------------------------------------------------------------* * Measure energy on active voice frames (to improve FEC performance) *---------------------------------------------------------------------------------*/ - IF( EQ_16(*clas,VOICED_CLAS)) + IF( EQ_16( *clas, VOICED_CLAS ) ) { test(); test(); test(); test(); test(); - IF( (EQ_16(codec_mode,MODE2)&&EQ_16(coder_type,VOICED)) - || (EQ_16(codec_mode,MODE1) && (Opt_AMR_WB || (NE_16(coder_type,GENERIC) && NE_16(coder_type,TRANSITION) ) ) ) - ) + IF( ( EQ_16( codec_mode, MODE2 ) && EQ_16( coder_type, VOICED ) ) || ( EQ_16( codec_mode, MODE1 ) && ( Opt_AMR_WB || ( NE_16( coder_type, GENERIC ) && NE_16( coder_type, TRANSITION ) ) ) ) ) { /* pitch-synchronous energy at the frame end */ - enern = frame_energy_fx(L_frame,pitch, synth, *lp_speech, &frame_ener, *Q_mem_syn); + enern = frame_energy_fx( L_frame, pitch, synth, *lp_speech, &frame_ener, *Q_mem_syn ); } /* update of long-term active speech energy */ - Ltmp = L_mult0(655, frame_ener); /* 0.01 */ - *lp_speech = mac_r(Ltmp, 32440, *lp_speech); + Ltmp = L_mult0( 655, frame_ener ); /* 0.01 */ + *lp_speech = mac_r( Ltmp, 32440, *lp_speech ); move16(); /* lp_speech update */ } - IF(EQ_16(codec_mode, MODE1)) + IF( EQ_16( codec_mode, MODE1 ) ) { /*---------------------------------------------------------------------------------* * Overwrite classification decision to UNVOICED_CLAS in case of INACTIVE frame *---------------------------------------------------------------------------------*/ test(); - if( EQ_16(coder_type, INACTIVE)&&NE_16(*clas,INACTIVE_CLAS)) + if ( EQ_16( coder_type, INACTIVE ) && NE_16( *clas, INACTIVE_CLAS ) ) { *clas = UNVOICED_CLAS; move16(); @@ -587,9 +605,9 @@ void FEC_clas_estim_fx( *-----------------------------------------------------------------------------*/ test(); - IF( EQ_16(*clas, UNVOICED_CLAS)&&NE_16(coder_type,INACTIVE)) + IF( EQ_16( *clas, UNVOICED_CLAS ) && NE_16( coder_type, INACTIVE ) ) { - IF ( LE_16(*lp_speech, 40*256/*Q8*/)) + IF( LE_16( *lp_speech, 40 * 256 /*Q8*/ ) ) { *UV_cnt = 16; move16(); @@ -597,7 +615,7 @@ void FEC_clas_estim_fx( ELSE { move16(); - *UV_cnt = sub(*UV_cnt, 8); + *UV_cnt = sub( *UV_cnt, 8 ); } } @@ -606,18 +624,18 @@ void FEC_clas_estim_fx( * Number of frames between UV is increased *-----------------------------------------------------------------------------*/ - ELSE IF ( NE_16(coder_type, INACTIVE)) + ELSE IF( NE_16( coder_type, INACTIVE ) ) { move16(); - *UV_cnt = add(*UV_cnt, 1); + *UV_cnt = add( *UV_cnt, 1 ); } /*-----------------------------------------------------------------------------* * Maximum/minimum number of frames between UV reached *-----------------------------------------------------------------------------*/ - /* Range 0..300 */ move16(); - *UV_cnt = s_max(s_min(300, *UV_cnt), 0); + /* Range 0..300 */ move16(); + *UV_cnt = s_max( s_min( 300, *UV_cnt ), 0 ); /*-----------------------------------------------------------------------------* * IF VAD = 0 (no voice activity) @@ -627,24 +645,24 @@ void FEC_clas_estim_fx( * update long-term average *-----------------------------------------------------------------------------*/ - IF ( EQ_16(coder_type, INACTIVE)) + IF( EQ_16( coder_type, INACTIVE ) ) { move16(); - *LT_UV_cnt = mult_r(31130/*0.95f*/, *LT_UV_cnt); /* tend to speech if no activity */ - *UV_cnt = s_min(125, *UV_cnt); + *LT_UV_cnt = mult_r( 31130 /*0.95f*/, *LT_UV_cnt ); /* tend to speech if no activity */ + *UV_cnt = s_min( 125, *UV_cnt ); move16(); } ELSE { /* *LT_UV_cnt = 0.9f * *LT_UV_cnt + 0.1f * *UV_cnt */ - Ltmp = L_mult(3277/*0.1f*/, *UV_cnt); + Ltmp = L_mult( 3277 /*0.1f*/, *UV_cnt ); /* Bring to Q22 */ - Ltmp = L_shl(Ltmp, 6); + Ltmp = L_shl( Ltmp, 6 ); /* Add to 0.9 x *LT_UV_cnt (Already in Q6) */ - Ltmp = L_mac(Ltmp, 29491/*0.9f*/, *LT_UV_cnt); /* Q22*/ + Ltmp = L_mac( Ltmp, 29491 /*0.9f*/, *LT_UV_cnt ); /* Q22*/ /* Store */ - *LT_UV_cnt = round_fx(Ltmp); + *LT_UV_cnt = round_fx( Ltmp ); } /*-----------------------------------------------------------------------------* @@ -655,20 +673,20 @@ void FEC_clas_estim_fx( * consider an attack *-----------------------------------------------------------------------------*/ - diff_ener = sub(ener, *Last_ener); + diff_ener = sub( ener, *Last_ener ); *Last_ener = ener; move16(); *amr_io_class = *clas; move16(); test(); - if ( GT_16(*LT_UV_cnt, LT_UV_THR_FX)&<_16(diff_ener,12*256/*Q8*/)) + if ( GT_16( *LT_UV_cnt, LT_UV_THR_FX ) && LT_16( diff_ener, 12 * 256 /*Q8*/ ) ) { move16(); *amr_io_class = AUDIO_CLAS; } test(); test(); - if ( (GT_16(diff_ener, 6*256/*Q8*/)&&EQ_16(*clas,AUDIO_CLAS))||GT_16(diff_ener,9*256/*Q8*/)) + if ( ( GT_16( diff_ener, 6 * 256 /*Q8*/ ) && EQ_16( *clas, AUDIO_CLAS ) ) || GT_16( diff_ener, 9 * 256 /*Q8*/ ) ) { *locattack = 1; move16(); @@ -678,16 +696,16 @@ void FEC_clas_estim_fx( * Find mean of the past 40 frames energy variation *------------------------------------------------------------------------*/ - IF( NE_16(coder_type, INACTIVE)) + IF( NE_16( coder_type, INACTIVE ) ) { - Ltmp = L_deposit_l(0); - FOR (i = 1; icoder_type,VOICED)) + IF( NE_16( st_fx->coder_type, VOICED ) ) { /* decode the class */ - tmpS = (Word16)get_next_indice( st_fx, FEC_BITS_CLS ); + tmpS = (Word16) get_next_indice( st_fx, FEC_BITS_CLS ); IF( tmpS == 0 ) { clas = UNVOICED_CLAS; move16(); } - ELSE IF( EQ_16(tmpS,1)) + ELSE IF( EQ_16( tmpS, 1 ) ) { - IF( GE_16(st_fx->last_good,VOICED_TRANSITION)) + IF( GE_16( st_fx->last_good, VOICED_TRANSITION ) ) { clas = VOICED_TRANSITION; move16(); @@ -786,7 +803,7 @@ static Word16 FEC_dec_class_fx( move16(); } } - ELSE IF( EQ_16(tmpS,2)) + ELSE IF( EQ_16( tmpS, 2 ) ) { clas = VOICED_CLAS; move16(); @@ -801,15 +818,15 @@ static Word16 FEC_dec_class_fx( /* decode the energy */ test(); test(); - IF(GT_16(st_fx->acelp_cfg.FEC_mode , 1) ) + IF( GT_16( st_fx->acelp_cfg.FEC_mode, 1 ) ) { - tmpS = (Word16)get_next_indice( st_fx, FEC_BITS_ENR ); + tmpS = (Word16) get_next_indice( st_fx, FEC_BITS_ENR ); /* convert from logarithmic to linear domain (the range is 0 : 3.0 : 96 dB) */ - tmpS = mult_r(shl(tmpS,10), 24576); /* Q10*Q13->Q8 */ - L_tmp = L_mult(tmpS, 10885); /* 0.332192 in Q15 */ - L_tmp = L_shr(L_tmp, 8); /* From Q24 to Q16 */ - sfrac = L_Extract_lc(L_tmp, &tmpS); - *enr_q = Pow2(tmpS, sfrac); + tmpS = mult_r( shl( tmpS, 10 ), 24576 ); /* Q10*Q13->Q8 */ + L_tmp = L_mult( tmpS, 10885 ); /* 0.332192 in Q15 */ + L_tmp = L_shr( L_tmp, 8 ); /* From Q24 to Q16 */ + sfrac = L_Extract_lc( L_tmp, &tmpS ); + *enr_q = Pow2( tmpS, sfrac ); move32(); } @@ -817,10 +834,10 @@ static Word16 FEC_dec_class_fx( } Word16 FEC_pos_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *last_pulse_pos, /* o : last glotal pulse position in the lost ACB */ - Word32 *enr_q, /* o : decoded energy in Q0 */ - const Word16 nBits_es_Pred /* i : number of bits for Es_pred Q */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *last_pulse_pos, /* o : last glotal pulse position in the lost ACB */ + Word32 *enr_q, /* o : decoded energy in Q0 */ + const Word16 nBits_es_Pred /* i : number of bits for Es_pred Q */ ) { Word16 pitch_index, T0, T0_frac, T0_min, T0_max; @@ -828,18 +845,18 @@ Word16 FEC_pos_dec_fx( T0 = 0; move16(); - IF( GT_16(st_fx->coder_type,UNVOICED)) + IF( GT_16( st_fx->coder_type, UNVOICED ) ) { /* decode the clas and energy information */ - IF( LT_16(st_fx->coder_type,AUDIO)) + IF( LT_16( st_fx->coder_type, AUDIO ) ) { - st_fx->clas_dec = FEC_dec_class_fx( st_fx, enr_q); + st_fx->clas_dec = FEC_dec_class_fx( st_fx, enr_q ); move16(); test(); test(); test(); - IF( EQ_16(st_fx->coder_type,GENERIC) && EQ_16(st_fx->clas_dec,VOICED_CLAS) && (LE_16(st_fx->last_good,UNVOICED_CLAS) || EQ_16(st_fx->last_good,INACTIVE_CLAS))) + IF( EQ_16( st_fx->coder_type, GENERIC ) && EQ_16( st_fx->clas_dec, VOICED_CLAS ) && ( LE_16( st_fx->last_good, UNVOICED_CLAS ) || EQ_16( st_fx->last_good, INACTIVE_CLAS ) ) ) { st_fx->clas_dec = SIN_ONSET; move16(); @@ -847,17 +864,17 @@ Word16 FEC_pos_dec_fx( } test(); - IF( EQ_16(st_fx->coder_type,GENERIC) && GT_16(st_fx->acelp_cfg.FEC_mode,2) ) + IF( EQ_16( st_fx->coder_type, GENERIC ) && GT_16( st_fx->acelp_cfg.FEC_mode, 2 ) ) { - nBits = st_fx->acelp_cfg.pitch_bits[0]; /* The first pitch index is located right after the actual position + the last pulse position index + predicted innovation energy index */ + nBits = st_fx->acelp_cfg.pitch_bits[0]; /* The first pitch index is located right after the actual position + the last pulse position index + predicted innovation energy index */ bit_pos_pitch_index = st_fx->next_bit_pos + FEC_BITS_POS + nBits_es_Pred; - IF (GE_32(st_fx->core_brate, MIN_BRATE_AVQ_EXC) && LE_32(st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD) && EQ_16(st_fx->coder_type, GENERIC)) + IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && LE_32( st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD ) && EQ_16( st_fx->coder_type, GENERIC ) ) { /* Harmonic flag is present */ - bit_pos_pitch_index = add(bit_pos_pitch_index, 1); + bit_pos_pitch_index = add( bit_pos_pitch_index, 1 ); } /* retrieve the pitch index */ - pitch_index = (Word16)get_indice( st_fx, bit_pos_pitch_index, nBits ); + pitch_index = (Word16) get_indice( st_fx, bit_pos_pitch_index, nBits ); /* decode pitch period */ T0_min = PIT_MIN; @@ -867,21 +884,21 @@ Word16 FEC_pos_dec_fx( pit16k_Q_dec_fx( pitch_index, 10, 1, &T0, &T0_frac, &T0_min, &T0_max, &st_fx->BER_detect ); /* decode last pulse position */ - *last_pulse_pos = (Word16)get_next_indice( st_fx, FEC_BITS_POS ); + *last_pulse_pos = (Word16) get_next_indice( st_fx, FEC_BITS_POS ); /* respect the sign */ - IF (GE_16(*last_pulse_pos,128)) + IF( GE_16( *last_pulse_pos, 128 ) ) { - *last_pulse_pos = negate(s_and(*last_pulse_pos , 0x7F)); + *last_pulse_pos = negate( s_and( *last_pulse_pos, 0x7F ) ); move16(); } - if ( GE_16(T0,128)) + if ( GE_16( T0, 128 ) ) { - *last_pulse_pos = add(*last_pulse_pos,*last_pulse_pos); + *last_pulse_pos = add( *last_pulse_pos, *last_pulse_pos ); move16(); } - if( st_fx->BER_detect ) + if ( st_fx->BER_detect ) { *last_pulse_pos = 0; move16(); @@ -898,10 +915,10 @@ Word16 FEC_pos_dec_fx( * Information about the similarity between vectors is returned in *gain *----------------------------------------------------------------------*/ static void Corre( - const Word16 *x, /* i : vector 1 Q12 */ - const Word16 *y, /* i : vector 2 Q12 */ - const Word16 l, /* i : length of vectors */ - Word16 *gain /* o : normalized correlation gain Q15 */ + const Word16 *x, /* i : vector 1 Q12 */ + const Word16 *y, /* i : vector 2 Q12 */ + const Word16 l, /* i : length of vectors */ + Word16 *gain /* o : normalized correlation gain Q15 */ ) { Word16 cor, cor_exp; @@ -911,26 +928,26 @@ static void Corre( Word16 tmp_exp; /* keep Q15 normalized result */ - cor = extract_h(Dot_product12(x, y, l, &cor_exp)); + cor = extract_h( Dot_product12( x, y, l, &cor_exp ) ); #ifdef BASOP_NOGLOB - den = add_sat(extract_h(Dot_product12(y, y, l, &den_exp)), 1); + den = add_sat( extract_h( Dot_product12( y, y, l, &den_exp ) ), 1 ); #else - den = add(extract_h(Dot_product12(y, y, l, &den_exp)), 1); + den = add( extract_h( Dot_product12( y, y, l, &den_exp ) ), 1 ); #endif - den2 = extract_h(Dot_product12(x, x, l, &den2_exp)); + den2 = extract_h( Dot_product12( x, x, l, &den2_exp ) ); /* keep Q31 normalized result */ - tmp = L_mult(den, den2); - tmp_exp = norm_l(tmp); - tmp = L_shl(tmp, tmp_exp); - tmp_exp = sub(add(den_exp, den2_exp), tmp_exp); + tmp = L_mult( den, den2 ); + tmp_exp = norm_l( tmp ); + tmp = L_shl( tmp, tmp_exp ); + tmp_exp = sub( add( den_exp, den2_exp ), tmp_exp ); - tmp = Isqrt_lc(tmp, &tmp_exp); + tmp = Isqrt_lc( tmp, &tmp_exp ); /* keep Q15 result */ #ifdef BASOP_NOGLOB - gain[0] = shl_sat(mult_r(cor, extract_h(tmp)), add(cor_exp, tmp_exp)); + gain[0] = shl_sat( mult_r( cor, extract_h( tmp ) ), add( cor_exp, tmp_exp ) ); #else - gain[0] = shl(mult_r(cor, extract_h(tmp)), add(cor_exp, tmp_exp)); + gain[0] = shl( mult_r( cor, extract_h( tmp ) ), add( cor_exp, tmp_exp ) ); #endif move16(); } diff --git a/lib_dec/FEC_fx.c b/lib_dec/FEC_fx.c index 2dc26d6a3..225e2c638 100644 --- a/lib_dec/FEC_fx.c +++ b/lib_dec/FEC_fx.c @@ -3,19 +3,19 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Common static table prototypes */ -#include "rom_dec.h" /* Decoder static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Common static table prototypes */ +#include "rom_dec.h" /* Decoder static table prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ #include "basop_util.h" #ifdef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * Local function prototypes *-------------------------------------------------------------------*/ -static void pulseRes_preCalc(Word16* cond1, Word16* cond2, Word32* cond3 ,Word16 new_pit, Word16 Tc, Word16 L_frame); -void gain_dec_bfi_fx(Word16 *past_qua_en); +static void pulseRes_preCalc( Word16 *cond1, Word16 *cond2, Word32 *cond3, Word16 new_pit, Word16 Tc, Word16 L_frame ); +void gain_dec_bfi_fx( Word16 *past_qua_en ); /*======================================================================*/ /* FUNCTION : FEC_exc_estim_fx() */ /*----------------------------------------------------------------------*/ @@ -61,36 +61,36 @@ void gain_dec_bfi_fx(Word16 *past_qua_en); void FEC_exc_estim_fx( - Decoder_State *st_fx, /* i/o: Decoder static memory */ - const Word16 L_frame, /* i : length of the frame */ - Word16 *exc, /* o : pointer to excitation buffer (with past) */ - Word16 *exc2, /* o : total excitation (for synthesis) */ - Word16 exc_dct_in[], /* o : GSC excitation in DCT domain */ - Word16 *pitch_buf, /* o : Floating pitch for each subframe */ - Word16 *voice_factors, /* o : voicing factors */ - Word16 *tmp_tc, /* o : FEC pitch Q6 */ - Word16 *bwe_exc, /* o : excitation for SWB TBE */ - Word16 *lsf_new, /* i : ISFs at the end of the frame */ + Decoder_State *st_fx, /* i/o: Decoder static memory */ + const Word16 L_frame, /* i : length of the frame */ + Word16 *exc, /* o : pointer to excitation buffer (with past) */ + Word16 *exc2, /* o : total excitation (for synthesis) */ + Word16 exc_dct_in[], /* o : GSC excitation in DCT domain */ + Word16 *pitch_buf, /* o : Floating pitch for each subframe */ + Word16 *voice_factors, /* o : voicing factors */ + Word16 *tmp_tc, /* o : FEC pitch Q6 */ + Word16 *bwe_exc, /* o : excitation for SWB TBE */ + Word16 *lsf_new, /* i : ISFs at the end of the frame */ Word16 *Q_exc, - Word16 *tmp_noise /* o : long-term noise energy Q0 */ + Word16 *tmp_noise /* o : long-term noise energy Q0 */ ) { - Word16 exc2_buf[L_FRAME16k + MODE1_L_FIR_FER-1]; - Word16 gainCNG,new_pit /*Q0*/; /* Q3*/ + Word16 exc2_buf[L_FRAME16k + MODE1_L_FIR_FER - 1]; + Word16 gainCNG, new_pit /*Q0*/; /* Q3*/ Word16 exp; - Word32 L_tmp,L_tmp2; - Word16 tmp,tmp1,tmp16; + Word32 L_tmp, L_tmp2; + Word16 tmp, tmp1, tmp16; Word16 delta; - Word16 i,j; + Word16 i, j; Word16 alpha; - Word16 gain,gain_inov; + Word16 gain, gain_inov; Word16 Tc; - Word16 *pt_exc,*pt1_exc; + Word16 *pt_exc, *pt1_exc; Word16 step; Word32 L_step; Word16 hp_filt[5]; - Word16 Diff_len,max_len,Len; + Word16 Diff_len, max_len, Len; Word16 last_bin_fx, nb_subfr; Word16 extrapolationFailed; Word16 cond1, cond2; @@ -104,9 +104,9 @@ void FEC_exc_estim_fx( AMRWB_IO_DEC_HANDLE hAmrwb_IO; hAmrwb_IO = st_fx->hAmrwb_IO; - /* nb_subfr = L_frame/L_SUBFR */ - nb_subfr = shr(L_frame, 6); - Diff_len = 0; /* to avoid compilation flags */ + /* nb_subfr = L_frame/L_SUBFR */ + nb_subfr = shr( L_frame, 6 ); + Diff_len = 0; /* to avoid compilation flags */ set16_fx( exc_dct_in, 0, L_FRAME16k ); extrapolationFailed = 1; @@ -114,25 +114,24 @@ void FEC_exc_estim_fx( gainCNG = 0; move16(); - IF(st_fx->lp_ener_fx != 0) + IF( st_fx->lp_ener_fx != 0 ) { - exp = norm_l(st_fx->lp_ener_fx); /*lp_ener in Q6*/ - tmp = extract_h(L_shl(st_fx->lp_ener_fx,exp)); - exp = sub(exp, 30-6); + exp = norm_l( st_fx->lp_ener_fx ); /*lp_ener in Q6*/ + tmp = extract_h( L_shl( st_fx->lp_ener_fx, exp ) ); + exp = sub( exp, 30 - 6 ); - tmp = div_s(16384, tmp); - L_tmp = L_deposit_h(tmp); - L_tmp = Isqrt_lc(L_tmp, &exp); - - gainCNG = round_fx(L_shl(L_tmp, sub(exp, 12))); /* In Q3 */ + tmp = div_s( 16384, tmp ); + L_tmp = L_deposit_h( tmp ); + L_tmp = Isqrt_lc( L_tmp, &exp ); + gainCNG = round_fx( L_shl( L_tmp, sub( exp, 12 ) ) ); /* In Q3 */ } #ifdef BASOP_NOGLOB - tmp1 = shl_o(st_fx->lp_gainc_fx, 1, &Overflow); + tmp1 = shl_o( st_fx->lp_gainc_fx, 1, &Overflow ); #else - tmp1 = shl(st_fx->lp_gainc_fx,1); + tmp1 = shl( st_fx->lp_gainc_fx, 1 ); #endif - gainCNG = s_min(gainCNG , tmp1); + gainCNG = s_min( gainCNG, tmp1 ); set16_fx( exc_dct_in, 0, L_FRAME16k ); /*-----------------------------------------------------------------* @@ -147,12 +146,12 @@ void FEC_exc_estim_fx( /*tmp_pitmin = L_frame == L_FRAME?PIT_MIN_DOUBLEEXTEND:PIT16k_MIN_EXTEND;*/ /*tmp_pitmax = L_frame == L_FRAME?PIT_MAX:PIT16k_MAX;*/ - tmp_old_pitch = &st_fx->old_pitch_buf_fx[2*NB_SUBFR16k-1]; + tmp_old_pitch = &st_fx->old_pitch_buf_fx[2 * NB_SUBFR16k - 1]; tmp_pitmin = PIT16k_MIN_EXTEND; tmp_pitmax = PIT16k_MAX; - IF(EQ_16(L_frame, L_FRAME)) + IF( EQ_16( L_frame, L_FRAME ) ) { - tmp_old_pitch = &st_fx->old_pitch_buf_fx[2*NB_SUBFR-1]; + tmp_old_pitch = &st_fx->old_pitch_buf_fx[2 * NB_SUBFR - 1]; tmp_pitmin = PIT_MIN_DOUBLEEXTEND; move16(); tmp_pitmax = PIT_MAX; @@ -172,13 +171,12 @@ void FEC_exc_estim_fx( 0, 0, &extrapolationFailed, - nb_subfr); + nb_subfr ); - new_pit/*Q0 int*/ = shl(round_fx(predPitchLag),0); + new_pit /*Q0 int*/ = shl( round_fx( predPitchLag ), 0 ); } - /*-----------------------------------------------------------------* * estimate subframe pitch values for the FEC frame *-----------------------------------------------------------------*/ @@ -186,83 +184,80 @@ void FEC_exc_estim_fx( /* initialize pitch to the long-term pitch */ *tmp_tc = st_fx->bfi_pitch_fx; - move16(); /*Q6*/ - IF( EQ_16(L_frame,L_FRAME)) + move16(); /*Q6*/ + IF( EQ_16( L_frame, L_FRAME ) ) { test(); test(); #ifdef BASOP_NOGLOB - IF ( (LT_16(round_fx(L_shl(st_fx->old_pitch_buf_fx[2*NB_SUBFR-1], 6)), shl_o(mult(29491, st_fx->bfi_pitch_fx), 1, &Overflow))&& - GT_16(round_fx(L_shl(st_fx->old_pitch_buf_fx[2*NB_SUBFR-1], 6)), mult(19661, st_fx->bfi_pitch_fx)) ) || /* last pitch coherent with the past */ - GE_16(st_fx->upd_cnt, MAX_UPD_CNT) ) /* or last update too far in the past */ + IF( ( LT_16( round_fx( L_shl( st_fx->old_pitch_buf_fx[2 * NB_SUBFR - 1], 6 ) ), shl_o( mult( 29491, st_fx->bfi_pitch_fx ), 1, &Overflow ) ) && + GT_16( round_fx( L_shl( st_fx->old_pitch_buf_fx[2 * NB_SUBFR - 1], 6 ) ), mult( 19661, st_fx->bfi_pitch_fx ) ) ) || /* last pitch coherent with the past */ + GE_16( st_fx->upd_cnt, MAX_UPD_CNT ) ) /* or last update too far in the past */ #else - IF((LT_16(round_fx(L_shl(st_fx->old_pitch_buf_fx[2 * NB_SUBFR - 1], 6)), shl(mult(29491, st_fx->bfi_pitch_fx), 1)) && - GT_16(round_fx(L_shl(st_fx->old_pitch_buf_fx[2 * NB_SUBFR - 1], 6)), mult(19661, st_fx->bfi_pitch_fx)) ) || /* last pitch coherent with the past */ - GE_16(st_fx->upd_cnt, MAX_UPD_CNT) ) /* or last update too far in the past */ + IF( ( LT_16( round_fx( L_shl( st_fx->old_pitch_buf_fx[2 * NB_SUBFR - 1], 6 ) ), shl( mult( 29491, st_fx->bfi_pitch_fx ), 1 ) ) && + GT_16( round_fx( L_shl( st_fx->old_pitch_buf_fx[2 * NB_SUBFR - 1], 6 ) ), mult( 19661, st_fx->bfi_pitch_fx ) ) ) || /* last pitch coherent with the past */ + GE_16( st_fx->upd_cnt, MAX_UPD_CNT ) ) /* or last update too far in the past */ #endif { /* take the pitch value of last subframe of the previous frame */ - *tmp_tc = round_fx(L_shl(st_fx->old_pitch_buf_fx[2*NB_SUBFR-1], 6)); + *tmp_tc = round_fx( L_shl( st_fx->old_pitch_buf_fx[2 * NB_SUBFR - 1], 6 ) ); } } - ELSE /* L_frame == L_FRAME16k */ + ELSE /* L_frame == L_FRAME16k */ { test(); test(); #ifdef BASOP_NOGLOB - IF ( (LT_16(round_fx(L_shl(st_fx->old_pitch_buf_fx[2*NB_SUBFR16k-1], 6)), shl_o(mult(29491, st_fx->bfi_pitch_fx), 1, &Overflow))&& - GT_16(round_fx(L_shl(st_fx->old_pitch_buf_fx[2*NB_SUBFR16k-1], 6)), mult(19661, st_fx->bfi_pitch_fx))) || /* last pitch coherent with the past */ - GE_16(st_fx->upd_cnt, MAX_UPD_CNT)) /* or last update too far in the past */ + IF( ( LT_16( round_fx( L_shl( st_fx->old_pitch_buf_fx[2 * NB_SUBFR16k - 1], 6 ) ), shl_o( mult( 29491, st_fx->bfi_pitch_fx ), 1, &Overflow ) ) && + GT_16( round_fx( L_shl( st_fx->old_pitch_buf_fx[2 * NB_SUBFR16k - 1], 6 ) ), mult( 19661, st_fx->bfi_pitch_fx ) ) ) || /* last pitch coherent with the past */ + GE_16( st_fx->upd_cnt, MAX_UPD_CNT ) ) /* or last update too far in the past */ #else - IF ( (LT_16(round_fx(L_shl(st_fx->old_pitch_buf_fx[2*NB_SUBFR16k-1], 6)), shl(mult(29491, st_fx->bfi_pitch_fx), 1))&& - GT_16(round_fx(L_shl(st_fx->old_pitch_buf_fx[2*NB_SUBFR16k-1], 6)), mult(19661, st_fx->bfi_pitch_fx))) || /* last pitch coherent with the past */ - GE_16(st_fx->upd_cnt, MAX_UPD_CNT)) /* or last update too far in the past */ + IF( ( LT_16( round_fx( L_shl( st_fx->old_pitch_buf_fx[2 * NB_SUBFR16k - 1], 6 ) ), shl( mult( 29491, st_fx->bfi_pitch_fx ), 1 ) ) && + GT_16( round_fx( L_shl( st_fx->old_pitch_buf_fx[2 * NB_SUBFR16k - 1], 6 ) ), mult( 19661, st_fx->bfi_pitch_fx ) ) ) || /* last pitch coherent with the past */ + GE_16( st_fx->upd_cnt, MAX_UPD_CNT ) ) /* or last update too far in the past */ #endif { /* take the pitch value of last subframe of the previous frame */ - *tmp_tc = round_fx(L_shl(st_fx->old_pitch_buf_fx[2*NB_SUBFR16k-1], 6)); + *tmp_tc = round_fx( L_shl( st_fx->old_pitch_buf_fx[2 * NB_SUBFR16k - 1], 6 ) ); } } /* convert pitch period */ /* Tc = (short)(tmp_tc + 0.5f) */ - Tc = shr_r(*tmp_tc,6); + Tc = shr_r( *tmp_tc, 6 ); /* estimate pitch values for all subframes */ /*calculate conditions for Pulse resynchronization to take place*/ - pulseRes_preCalc( &cond1, &cond2, &cond3 , new_pit, Tc, L_frame); + pulseRes_preCalc( &cond1, &cond2, &cond3, new_pit, Tc, L_frame ); test(); test(); test(); test(); - IF ((cond1 < 0 ) - && (new_pit > 0) && (cond2 != 0) - && (cond3 > 0) - && extrapolationFailed == 0 - ) + IF( ( cond1 < 0 ) && ( new_pit > 0 ) && ( cond2 != 0 ) && ( cond3 > 0 ) && extrapolationFailed == 0 ) { - tmp16 = *tmp_tc; /*Q6*/ move16(); - IF(EQ_16(nb_subfr,4)) + tmp16 = *tmp_tc; /*Q6*/ + move16(); + IF( EQ_16( nb_subfr, 4 ) ) { - delta = shr(sub(shl(new_pit,6), *tmp_tc),2 ); /* 4 sub-frames */ + delta = shr( sub( shl( new_pit, 6 ), *tmp_tc ), 2 ); /* 4 sub-frames */ } ELSE { - delta = mult_r(sub(shl(new_pit,6), *tmp_tc),6554); /* 5 sub-frames */ + delta = mult_r( sub( shl( new_pit, 6 ), *tmp_tc ), 6554 ); /* 5 sub-frames */ } - FOR (i = 0; i < nb_subfr; i++) /* subframe pitch values */ + FOR( i = 0; i < nb_subfr; i++ ) /* subframe pitch values */ { /* fT0 += delta */ - tmp16 = add(tmp16, delta); + tmp16 = add( tmp16, delta ); /* ptch_buf[i] = (short)(fT0 + 0.5) */ - pitch_buf[i] = shl(mult_r(tmp16, 512), 6); + pitch_buf[i] = shl( mult_r( tmp16, 512 ), 6 ); move16(); } } ELSE { - FOR (i = 0; i < nb_subfr; i++) /* subframe pitch values for bass postfilter */ + FOR( i = 0; i < nb_subfr; i++ ) /* subframe pitch values for bass postfilter */ { pitch_buf[i] = *tmp_tc; move16(); @@ -283,21 +278,21 @@ void FEC_exc_estim_fx( test(); test(); test(); - IF( st_fx->last_coder_type == UNVOICED && LE_16(st_fx->nbLostCmpt, 3)) + IF( st_fx->last_coder_type == UNVOICED && LE_16( st_fx->nbLostCmpt, 3 ) ) { /* last good frame was clearly unvoiced */ alpha = _ALPHA_UU_FX; move16(); } - ELSE IF( EQ_16(st_fx->last_coder_type,AUDIO)||EQ_16(st_fx->last_good,INACTIVE_CLAS)) + ELSE IF( EQ_16( st_fx->last_coder_type, AUDIO ) || EQ_16( st_fx->last_good, INACTIVE_CLAS ) ) { test(); - IF( hGSCDec->Last_GSC_pit_band_idx > 0 && GT_16(st_fx->nbLostCmpt,1)) + IF( hGSCDec->Last_GSC_pit_band_idx > 0 && GT_16( st_fx->nbLostCmpt, 1 ) ) { alpha = 26214; move16(); } - ELSE IF( LE_16(st_fx->nbLostCmpt,5)) + ELSE IF( LE_16( st_fx->nbLostCmpt, 5 ) ) { alpha = 32604; move16(); @@ -308,21 +303,21 @@ void FEC_exc_estim_fx( move16(); } } - ELSE IF( EQ_16(st_fx->last_good,UNVOICED_CLAS)) + ELSE IF( EQ_16( st_fx->last_good, UNVOICED_CLAS ) ) { - IF( LE_16(st_fx->nbLostCmpt,1)) + IF( LE_16( st_fx->nbLostCmpt, 1 ) ) { /* if stable, do not decrease the energy, pitch_gain = 0 */ #ifdef BASOP_NOGLOB - alpha = mac_ro((1L << 16) * 2 * _ALPHA_U_FX, st_fx->stab_fac_fx, 32768 - 2 * _ALPHA_U_FX, &Overflow); /*st_fx->stab_fac_fx in Q15*/ + alpha = mac_ro( ( 1L << 16 ) * 2 * _ALPHA_U_FX, st_fx->stab_fac_fx, 32768 - 2 * _ALPHA_U_FX, &Overflow ); /*st_fx->stab_fac_fx in Q15*/ #else - alpha = mac_r((1L<<16)*2*_ALPHA_U_FX, st_fx->stab_fac_fx, 32768-2*_ALPHA_U_FX); /*st_fx->stab_fac_fx in Q15*/ + alpha = mac_r( ( 1L << 16 ) * 2 * _ALPHA_U_FX, st_fx->stab_fac_fx, 32768 - 2 * _ALPHA_U_FX ); /*st_fx->stab_fac_fx in Q15*/ #endif } - ELSE IF ( EQ_16(st_fx->nbLostCmpt,2)) + ELSE IF( EQ_16( st_fx->nbLostCmpt, 2 ) ) { - alpha =_ALPHA_S_FX; - move16(); /* ALPHA_U*1.5f = 0.6 */ + alpha = _ALPHA_S_FX; + move16(); /* ALPHA_U*1.5f = 0.6 */ } ELSE { @@ -330,51 +325,51 @@ void FEC_exc_estim_fx( move16(); /* 0.4 go rapidly to CNG gain, pitch gain = 0 */ } } - ELSE IF( EQ_16(st_fx->last_good,UNVOICED_TRANSITION)) + ELSE IF( EQ_16( st_fx->last_good, UNVOICED_TRANSITION ) ) { alpha = _ALPHA_UT_FX; move16(); } - ELSE IF( EQ_16(st_fx->last_good,ONSET)&&LE_16(st_fx->nbLostCmpt,3)&&(EQ_16(st_fx->last_coder_type,GENERIC)||EQ_16(st_fx->last_coder_type,TRANSITION))) + ELSE IF( EQ_16( st_fx->last_good, ONSET ) && LE_16( st_fx->nbLostCmpt, 3 ) && ( EQ_16( st_fx->last_coder_type, GENERIC ) || EQ_16( st_fx->last_coder_type, TRANSITION ) ) ) { alpha = 26214; - move16(); /* mild convergence to 0 for the first 3 erased frames 0.8 in Q15 */ + move16(); /* mild convergence to 0 for the first 3 erased frames 0.8 in Q15 */ } - ELSE IF( ( EQ_16(st_fx->last_good,VOICED_CLAS)||EQ_16(st_fx->last_good,ONSET))&&LE_16(st_fx->nbLostCmpt,3)) + ELSE IF( ( EQ_16( st_fx->last_good, VOICED_CLAS ) || EQ_16( st_fx->last_good, ONSET ) ) && LE_16( st_fx->nbLostCmpt, 3 ) ) { alpha = _ALPHA_V_FX; - move16(); /* constant for the first 3 erased frames */ + move16(); /* constant for the first 3 erased frames */ } - ELSE IF( EQ_16(st_fx->last_good,SIN_ONSET)) + ELSE IF( EQ_16( st_fx->last_good, SIN_ONSET ) ) { alpha = _ALPHA_S_FX; move16(); } test(); test(); - IF( GE_16(st_fx->last_good,VOICED_CLAS)&<_16(st_fx->last_good,INACTIVE_CLAS)&&NE_16(st_fx->last_coder_type,AUDIO)) + IF( GE_16( st_fx->last_good, VOICED_CLAS ) && LT_16( st_fx->last_good, INACTIVE_CLAS ) && NE_16( st_fx->last_coder_type, AUDIO ) ) { - IF( EQ_16(st_fx->nbLostCmpt,1)) /* if first erased frame in a block, reset harmonic gain */ + IF( EQ_16( st_fx->nbLostCmpt, 1 ) ) /* if first erased frame in a block, reset harmonic gain */ { /* move pitch gain towards 1 for voiced to remove energy fluctuations */ /*gain = (float)sqrt( st_fx->lp_gainp );*/ - st_fx->lp_gainp_fx = s_max(st_fx->lp_gainp_fx, 1); - exp = norm_s(st_fx->lp_gainp_fx); - tmp = shl(st_fx->lp_gainp_fx, exp); - tmp = div_s(16384, tmp); - L_tmp = L_deposit_h(tmp); - L_tmp = Isqrt_lc(L_tmp, &exp); + st_fx->lp_gainp_fx = s_max( st_fx->lp_gainp_fx, 1 ); + exp = norm_s( st_fx->lp_gainp_fx ); + tmp = shl( st_fx->lp_gainp_fx, exp ); + tmp = div_s( 16384, tmp ); + L_tmp = L_deposit_h( tmp ); + L_tmp = Isqrt_lc( L_tmp, &exp ); #ifdef BASOP_NOGLOB - gain = extract_h(L_shl_o(L_tmp, exp, &Overflow)); + gain = extract_h( L_shl_o( L_tmp, exp, &Overflow ) ); #else - gain = extract_h(L_shl(L_tmp, exp)); + gain = extract_h( L_shl( L_tmp, exp ) ); #endif - gain = s_min(gain, 32113); /*0.98 */ - gain = s_max(gain, 27853); /*0.85 */ + gain = s_min( gain, 32113 ); /*0.98 */ + gain = s_max( gain, 27853 ); /*0.85 */ - alpha = mult_r(alpha, gain); + alpha = mult_r( alpha, gain ); } ELSE { @@ -391,8 +386,8 @@ void FEC_exc_estim_fx( test(); test(); test(); - IF( (GE_16(st_fx->last_good,UNVOICED_TRANSITION)&<_16(st_fx->last_good,INACTIVE_CLAS))|| - ( (EQ_16(st_fx->last_coder_type,AUDIO) || EQ_16(st_fx->last_good,INACTIVE_CLAS) ) && hGSCDec->Last_GSC_pit_band_idx > 0) ) + IF( ( GE_16( st_fx->last_good, UNVOICED_TRANSITION ) && LT_16( st_fx->last_good, INACTIVE_CLAS ) ) || + ( ( EQ_16( st_fx->last_coder_type, AUDIO ) || EQ_16( st_fx->last_good, INACTIVE_CLAS ) ) && hGSCDec->Last_GSC_pit_band_idx > 0 ) ) { pt_exc = exc; @@ -400,16 +395,16 @@ void FEC_exc_estim_fx( pt1_exc = pt_exc - Tc; move16(); - IF (EQ_16(st_fx->nbLostCmpt,1)) + IF( EQ_16( st_fx->nbLostCmpt, 1 ) ) { /* first pitch cycle is low-pass filtered */ - FOR (i = 0; i < Tc; i++) /* pitch cycle is first low-pass filtered */ + FOR( i = 0; i < Tc; i++ ) /* pitch cycle is first low-pass filtered */ { /* *pt_exc++ = (0.18f * pt1_exc[-1] + 0.64f * pt1_exc[0] + 0.18f * pt1_exc[1]) */ - L_tmp = L_mult(5898, pt1_exc[-1]); - L_tmp = L_mac(L_tmp, 20972, pt1_exc[0]); - *pt_exc++ = mac_r(L_tmp, 5898, pt1_exc[1]); + L_tmp = L_mult( 5898, pt1_exc[-1] ); + L_tmp = L_mac( L_tmp, 20972, pt1_exc[0] ); + *pt_exc++ = mac_r( L_tmp, 5898, pt1_exc[1] ); move16(); pt1_exc++; } @@ -417,35 +412,31 @@ void FEC_exc_estim_fx( /* last pitch cycle of the previous frame is repeatedly copied up to an extra subframe */ - tmp = (Word16)((exc + L_frame + L_SUBFR) - pt_exc); - FOR (i = 0; i < tmp; i++) + tmp = (Word16) ( ( exc + L_frame + L_SUBFR ) - pt_exc ); + FOR( i = 0; i < tmp; i++ ) { *pt_exc++ = *pt1_exc++; move16(); } - IF (new_pit > 0 ) + IF( new_pit > 0 ) { /*calculate conditions for Pulse resynchronization to take place*/ - pulseRes_preCalc( &cond1, &cond2, &cond3 , new_pit, Tc, L_frame); + pulseRes_preCalc( &cond1, &cond2, &cond3, new_pit, Tc, L_frame ); test(); test(); test(); test(); - IF ((cond1 < 0 ) - && (new_pit > 0) && (cond2 != 0) - && (cond3 > 0) - && extrapolationFailed == 0 - ) + IF( ( cond1 < 0 ) && ( new_pit > 0 ) && ( cond2 != 0 ) && ( cond3 > 0 ) && extrapolationFailed == 0 ) { - Copy(exc,exc-L_frame-L_SUBFR,L_frame+L_SUBFR); - PulseResynchronization_fx(exc-L_frame-L_SUBFR, exc, L_frame, nb_subfr, L_deposit_h(Tc/*Q0*/)/*15Q16*/, L_deposit_h(new_pit/*Q0*/)/*15Q16*/); + Copy( exc, exc - L_frame - L_SUBFR, L_frame + L_SUBFR ); + PulseResynchronization_fx( exc - L_frame - L_SUBFR, exc, L_frame, nb_subfr, L_deposit_h( Tc /*Q0*/ ) /*15Q16*/, L_deposit_h( new_pit /*Q0*/ ) /*15Q16*/ ); } } test(); test(); - IF( EQ_16(st_fx->last_good,UNVOICED_TRANSITION)&&(EQ_16(st_fx->last_coder_type,GENERIC)||EQ_16(st_fx->last_coder_type,TRANSITION))) + IF( EQ_16( st_fx->last_good, UNVOICED_TRANSITION ) && ( EQ_16( st_fx->last_coder_type, GENERIC ) || EQ_16( st_fx->last_coder_type, TRANSITION ) ) ) { /* start of the frame gain */ gain = 0; @@ -467,85 +458,87 @@ void FEC_exc_estim_fx( /* end of the frame gain */ test(); - IF(!(GE_16(st_fx->last_good,VOICED_CLAS)&<_16(st_fx->last_good,INACTIVE_CLAS)&&NE_16(st_fx->last_coder_type,AUDIO)&>_16(st_fx->nbLostCmpt,1))) + IF( !( GE_16( st_fx->last_good, VOICED_CLAS ) && LT_16( st_fx->last_good, INACTIVE_CLAS ) && NE_16( st_fx->last_coder_type, AUDIO ) && GT_16( st_fx->nbLostCmpt, 1 ) ) ) { - st_fx->lp_gainp_fx = shr(alpha,1); /* alpha in Q15 */ + st_fx->lp_gainp_fx = shr( alpha, 1 ); /* alpha in Q15 */ } ELSE { st_fx->lp_gainp_fx = alpha; - move16(); /* alpha in Q14 */ + move16(); /* alpha in Q14 */ } - IF(EQ_16(L_frame, L_FRAME)) + IF( EQ_16( L_frame, L_FRAME ) ) { - step = shr(sub(gain,st_fx->lp_gainp_fx),8); + step = shr( sub( gain, st_fx->lp_gainp_fx ), 8 ); } ELSE /*L_frame == L_FRAME16k*/ { /*step = (1.0f/L_frame) * (gain - st_fx->lp_gainp);*/ - step = shr(mult_r(26214,sub(gain,st_fx->lp_gainp_fx)),8); /*Q14*/ + step = shr( mult_r( 26214, sub( gain, st_fx->lp_gainp_fx ) ), 8 ); /*Q14*/ } } - FOR( i=0 ; i< L_frame; i++ ) + FOR( i = 0; i < L_frame; i++ ) { /* exc[i] *= gain */ - exc[i] = round_fx(L_shl(L_mult(exc[i], gain), 1)); /* in Q_exc */ + exc[i] = round_fx( L_shl( L_mult( exc[i], gain ), 1 ) ); /* in Q_exc */ /* gain -= step */ - gain = sub(gain, step); + gain = sub( gain, step ); } test(); test(); - IF( (EQ_16(st_fx->last_coder_type,AUDIO)||EQ_16(st_fx->last_good,INACTIVE_CLAS))&& hGSCDec->Last_GSC_pit_band_idx>0) + IF( ( EQ_16( st_fx->last_coder_type, AUDIO ) || EQ_16( st_fx->last_good, INACTIVE_CLAS ) ) && hGSCDec->Last_GSC_pit_band_idx > 0 ) { Diff_len = mfreq_loc_div_25[hGSCDec->Last_GSC_pit_band_idx]; move16(); /* Transform to frequency domain */ - edct_16fx( exc, exc_dct_in, st_fx->L_frame, 5, st_fx->element_mode); + edct_16fx( exc, exc_dct_in, st_fx->L_frame, 5, st_fx->element_mode ); /* Reset unvaluable part of the adaptive (pitch) excitation contribution */ - max_len = sub(st_fx->L_frame,Diff_len); + max_len = sub( st_fx->L_frame, Diff_len ); Len = s_min( max_len, 80 ); - move16(); /*ptr init*/ - FOR( i=0; ilast_good >= VOICED_TRANSITION" */ + } /* end of "if st_fx->last_good >= VOICED_TRANSITION" */ /*-----------------------------------------------------------------* - * Replicate the last spectrum in case the last good frame was coded by GSC - *-----------------------------------------------------------------*/ + * Replicate the last spectrum in case the last good frame was coded by GSC + *-----------------------------------------------------------------*/ test(); test(); test(); - IF( EQ_16(st_fx->last_coder_type,AUDIO)||(EQ_16(st_fx->last_good,INACTIVE_CLAS)&&LE_32(st_fx->total_brate, MAX_GSC_INACTIVE_BRATE)&&!st_fx->Opt_AMR_WB)) + IF( EQ_16( st_fx->last_coder_type, AUDIO ) || ( EQ_16( st_fx->last_good, INACTIVE_CLAS ) && LE_32( st_fx->total_brate, MAX_GSC_INACTIVE_BRATE ) && !st_fx->Opt_AMR_WB ) ) { st_fx->GSC_noisy_speech = st_fx->Last_GSC_noisy_speech_flag; move16(); /* Replication of the last spectrum, with a slight downscaling of its dynamic */ - if (st_fx->element_mode == EVS_MONO) { - gsc_dec_fx(st_fx, exc_dct_in, hGSCDec->Last_GSC_pit_band_idx, Diff_len, 0, st_fx->L_frame / L_SUBFR, st_fx->last_coder_type, &last_bin_fx, lsf_new, NULL, st_fx->Q_exc); + if ( st_fx->element_mode == EVS_MONO ) + { + gsc_dec_fx( st_fx, exc_dct_in, hGSCDec->Last_GSC_pit_band_idx, Diff_len, 0, st_fx->L_frame / L_SUBFR, st_fx->last_coder_type, &last_bin_fx, lsf_new, NULL, st_fx->Q_exc ); } - else { - gsc_dec_ivas_fx(st_fx, exc_dct_in, hGSCDec->Last_GSC_pit_band_idx, Diff_len, 0, st_fx->L_frame / L_SUBFR, st_fx->last_coder_type, &last_bin_fx, lsf_new, NULL, st_fx->Q_exc); + else + { + gsc_dec_ivas_fx( st_fx, exc_dct_in, hGSCDec->Last_GSC_pit_band_idx, Diff_len, 0, st_fx->L_frame / L_SUBFR, st_fx->last_coder_type, &last_bin_fx, lsf_new, NULL, st_fx->Q_exc ); } - *tmp_noise = shr_r(st_fx->lp_gainc_fx,3); /*Q0*/ + *tmp_noise = shr_r( st_fx->lp_gainc_fx, 3 ); /*Q0*/ /* Transform back to time domain */ - edct_16fx( exc_dct_in, exc, st_fx->L_frame, 5, st_fx->element_mode); + edct_16fx( exc_dct_in, exc, st_fx->L_frame, 5, st_fx->element_mode ); } ELSE { @@ -554,10 +547,10 @@ void FEC_exc_estim_fx( *-----------------------------------------------------------------*/ /* generate the random part of the excitation */ - FOR (i=0; iseed ),3); + exc2_buf[i] = shr( Random( &st_fx->seed ), 3 ); move16(); } @@ -568,26 +561,26 @@ void FEC_exc_estim_fx( test(); test(); test(); - IF(!(GE_16(st_fx->last_good,VOICED_CLAS)&<_16(st_fx->last_good,INACTIVE_CLAS)&&NE_16(st_fx->last_coder_type,AUDIO)&>_16(st_fx->nbLostCmpt,1))) + IF( !( GE_16( st_fx->last_good, VOICED_CLAS ) && LT_16( st_fx->last_good, INACTIVE_CLAS ) && NE_16( st_fx->last_coder_type, AUDIO ) && GT_16( st_fx->nbLostCmpt, 1 ) ) ) { /* Here alpha is in Q15 and lp_gainc_fx in Q3 */ /* st_fx->lp_gainc = alpha * st_fx->lp_gainc + (1.0f - alpha) * gainCNG; */ - L_tmp = L_mult(alpha, st_fx->lp_gainc_fx); + L_tmp = L_mult( alpha, st_fx->lp_gainc_fx ); - st_fx->lp_gainc_fx = msu_r(L_tmp, add(alpha, -32768), gainCNG); + st_fx->lp_gainc_fx = msu_r( L_tmp, add( alpha, -32768 ), gainCNG ); } ELSE - { /* Here alpha is in Q14, but lp_gainc still in Q3 */ + { /* Here alpha is in Q14, but lp_gainc still in Q3 */ /* st_fx->lp_gainc = alpha * st_fx->lp_gainc + (1.0f - alpha) * gainCNG; */ - L_tmp = L_mult(alpha, st_fx->lp_gainc_fx); /* Q14*Q3->Q18 */ + L_tmp = L_mult( alpha, st_fx->lp_gainc_fx ); /* Q14*Q3->Q18 */ - st_fx->lp_gainc_fx = round_fx(L_shl(L_msu(L_tmp, add(alpha, -16384), gainCNG),1));/* (Q14*Q3<<1)>>16 ->Q3 */ + st_fx->lp_gainc_fx = round_fx( L_shl( L_msu( L_tmp, add( alpha, -16384 ), gainCNG ), 1 ) ); /* (Q14*Q3<<1)>>16 ->Q3 */ } test(); test(); test(); - if( EQ_16(st_fx->last_good,UNVOICED_TRANSITION)&&(EQ_16(st_fx->last_coder_type,GENERIC)||EQ_16(st_fx->last_coder_type,TRANSITION))&&gainCNG>0) + if ( EQ_16( st_fx->last_good, UNVOICED_TRANSITION ) && ( EQ_16( st_fx->last_coder_type, GENERIC ) || EQ_16( st_fx->last_coder_type, TRANSITION ) ) && gainCNG > 0 ) { st_fx->lp_gainc_fx = gainCNG; move16(); @@ -595,97 +588,96 @@ void FEC_exc_estim_fx( /* linearly attenuate the gain throughout the frame */ /* step = (1.0f/L_FRAME) * (gain - *lp_gainc); */ - step = sub(gain,st_fx->lp_gainc_fx); /* divide by L_FRAME done later */ + step = sub( gain, st_fx->lp_gainc_fx ); /* divide by L_FRAME done later */ test(); - if(EQ_16(L_frame,L_FRAME16k)) + if ( EQ_16( L_frame, L_FRAME16k ) ) { - step = mult_r(step,26214); /* L_frame16k-> L_frame and division by L_frame done later*/ + step = mult_r( step, 26214 ); /* L_frame16k-> L_frame and division by L_frame done later*/ } /* calculate gain to normalize energy */ - pt_exc = exc2_buf + MODE1_L_FIR_FER/2; + pt_exc = exc2_buf + MODE1_L_FIR_FER / 2; move16(); /* To avoid saturation split the L_frame dot product into (L_frame/L_SUBFR) dot products and scale down before adding */ /* gain_inov = 1.0f / (float)sqrt( dotp( pt_exc, pt_exc, L_frame ) / L_frame + 0.01f ); */ - L_tmp = L_deposit_l(0); - FOR (i = 0; i < 2; i++) + L_tmp = L_deposit_l( 0 ); + FOR( i = 0; i < 2; i++ ) { - L_tmp2 = L_mult0(*pt_exc, *pt_exc); + L_tmp2 = L_mult0( *pt_exc, *pt_exc ); pt_exc++; - FOR (j = 1; j < shr(L_frame,1); j++) + FOR( j = 1; j < shr( L_frame, 1 ); j++ ) { - L_tmp2 = L_mac0(L_tmp2, *pt_exc, *pt_exc); /* Q-5 */ + L_tmp2 = L_mac0( L_tmp2, *pt_exc, *pt_exc ); /* Q-5 */ pt_exc++; } - L_tmp = L_add(L_tmp, L_shr(L_tmp2, 1)); /* Q-7 */ + L_tmp = L_add( L_tmp, L_shr( L_tmp2, 1 ) ); /* Q-7 */ } test(); - if(EQ_16(L_frame,L_FRAME16k)) + if ( EQ_16( L_frame, L_FRAME16k ) ) { - L_tmp = Mult_32_16(L_tmp, 26214); /* x0.8 to normalize to 256 samples */ + L_tmp = Mult_32_16( L_tmp, 26214 ); /* x0.8 to normalize to 256 samples */ } - exp = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, exp); /* Normalize */ - exp = add(exp, 8-7); /* Q0, 8 ->divide by 256 */ - exp = sub(31, exp); /* For Denormalization in Q31 */ - L_tmp = Isqrt_lc(L_tmp, &exp);/* in Q(31-exp) */ - gain_inov = round_fx(L_tmp); + exp = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, exp ); /* Normalize */ + exp = add( exp, 8 - 7 ); /* Q0, 8 ->divide by 256 */ + exp = sub( 31, exp ); /* For Denormalization in Q31 */ + L_tmp = Isqrt_lc( L_tmp, &exp ); /* in Q(31-exp) */ + gain_inov = round_fx( L_tmp ); /* attenuate somewhat on unstable unvoiced */ test(); test(); - if( (EQ_16(st_fx->last_good,UNVOICED_CLAS)||EQ_16(st_fx->last_good,INACTIVE_CLAS))&&NE_16(st_fx->last_coder_type,UNVOICED)) + if ( ( EQ_16( st_fx->last_good, UNVOICED_CLAS ) || EQ_16( st_fx->last_good, INACTIVE_CLAS ) ) && NE_16( st_fx->last_coder_type, UNVOICED ) ) { - gain_inov = mult_r(gain_inov, 26214); + gain_inov = mult_r( gain_inov, 26214 ); } /* scaling of the random part of excitation */ pt_exc = exc2_buf; move16(); - L_step = L_shr(L_mult(gain_inov, step), 8); /* here is the divide by L_FRAME */ - L_tmp2 = L_mult(gain_inov, gain); /* Q15 * Q3 -> Q3 */ - tmp = round_fx(L_tmp2); - exp = add(add(exp, *Q_exc), 15); /* 3+Q_exc+15 -> Q_exc+18 */ + L_step = L_shr( L_mult( gain_inov, step ), 8 ); /* here is the divide by L_FRAME */ + L_tmp2 = L_mult( gain_inov, gain ); /* Q15 * Q3 -> Q3 */ + tmp = round_fx( L_tmp2 ); + exp = add( add( exp, *Q_exc ), 15 ); /* 3+Q_exc+15 -> Q_exc+18 */ - FOR( i=0; i< MODE1_L_FIR_FER/2; i++ ) + FOR( i = 0; i < MODE1_L_FIR_FER / 2; i++ ) { /* non-causal ringing of the FIR filter */ /**pt_exc++ *= (gain_inov * gain);*/ - L_tmp = L_mult(tmp, *pt_exc); /* Q_exc+18 * Q-3 -> Q_exc+16 */ + L_tmp = L_mult( tmp, *pt_exc ); /* Q_exc+18 * Q-3 -> Q_exc+16 */ #ifdef BASOP_NOGLOB *pt_exc++ = round_fx_sat( L_shl_sat( L_tmp, exp ) ); #else - *pt_exc++ = round_fx(L_shl(L_tmp, exp)); + *pt_exc++ = round_fx( L_shl( L_tmp, exp ) ); #endif } - FOR( i=0; i< L_frame; i++ ) + FOR( i = 0; i < L_frame; i++ ) { /* the inner part of the FIR filter */ /* *pt_exc++ *= (gain_inov * gain); */ - L_tmp = L_mult(tmp, *pt_exc); + L_tmp = L_mult( tmp, *pt_exc ); #ifdef BASOP_NOGLOB *pt_exc++ = round_fx_sat( L_shl_sat( L_tmp, exp ) ); #else - *pt_exc++ = round_fx(L_shl(L_tmp, exp)); + *pt_exc++ = round_fx( L_shl( L_tmp, exp ) ); #endif /* gain -= step; */ - L_tmp2 = L_sub(L_tmp2, L_step); - tmp = round_fx(L_tmp2); - + L_tmp2 = L_sub( L_tmp2, L_step ); + tmp = round_fx( L_tmp2 ); } - FOR (i = 0 ; i < MODE1_L_FIR_FER/2; i++) /* causal ringing of the FIR filter */ + FOR( i = 0; i < MODE1_L_FIR_FER / 2; i++ ) /* causal ringing of the FIR filter */ { /* *pt_exc++ *= (gain_inov * gain) */ - L_tmp = L_mult(tmp, *pt_exc); + L_tmp = L_mult( tmp, *pt_exc ); #ifdef BASOP_NOGLOB *pt_exc++ = round_fx_sat( L_shl_sat( L_tmp, exp ) ); #else - *pt_exc++ = round_fx(L_shl(L_tmp, exp)); + *pt_exc++ = round_fx( L_shl( L_tmp, exp ) ); #endif } } @@ -697,42 +689,42 @@ void FEC_exc_estim_fx( test(); test(); test(); - IF( (EQ_16(st_fx->last_coder_type,AUDIO)||EQ_16(st_fx->last_good,INACTIVE_CLAS))&&LE_32(st_fx->total_brate, MAX_GSC_INACTIVE_BRATE)&&!st_fx->Opt_AMR_WB) + IF( ( EQ_16( st_fx->last_coder_type, AUDIO ) || EQ_16( st_fx->last_good, INACTIVE_CLAS ) ) && LE_32( st_fx->total_brate, MAX_GSC_INACTIVE_BRATE ) && !st_fx->Opt_AMR_WB ) { /* For GSC - the excitation is already computed */ Copy( exc, exc2, st_fx->L_frame ); } - ELSE IF( GE_16(st_fx->last_good,UNVOICED_TRANSITION)&<_16(st_fx->last_good,INACTIVE_CLAS)) + ELSE IF( GE_16( st_fx->last_good, UNVOICED_TRANSITION ) && LT_16( st_fx->last_good, INACTIVE_CLAS ) ) { /* For voiced and generic signals - prepare a HP filter for the random part of excitation */ /* tmp = -(1-tilt_code) to correctly represent 1.0000 */ - tmp = add(st_fx->tilt_code_fx, -32768); + tmp = add( st_fx->tilt_code_fx, -32768 ); move16(); - FOR (i = 0; i < MODE1_L_FIR_FER; i++) + FOR( i = 0; i < MODE1_L_FIR_FER; i++ ) { - hp_filt[i] = msu_r(0, tmp, h_high_fx[i]); + hp_filt[i] = msu_r( 0, tmp, h_high_fx[i] ); move16(); } /* HP filter the random part of the excitation and add the adaptive part */ pt_exc = exc2_buf; move16(); - FOR( i=0; i< L_frame; i++ ) + FOR( i = 0; i < L_frame; i++ ) { /* exc2[i] = exc[i] + dotp( &exc2_buf[i], hp_filt, MODE1_L_FIR_FER );*/ - L_tmp = L_mult(hp_filt[0], pt_exc[0]); - FOR (j = 1; j < MODE1_L_FIR_FER; j++) + L_tmp = L_mult( hp_filt[0], pt_exc[0] ); + FOR( j = 1; j < MODE1_L_FIR_FER; j++ ) { #ifdef BASOP_NOGLOB L_tmp = L_mac_sat( L_tmp, hp_filt[j], pt_exc[j] ); #else - L_tmp = L_mac(L_tmp, hp_filt[j], pt_exc[j]); + L_tmp = L_mac( L_tmp, hp_filt[j], pt_exc[j] ); #endif } #ifdef BASOP_NOGLOB exc2[i] = msu_r_sat( L_tmp, -32768, exc[i] ); #else - exc2[i] = msu_r(L_tmp, -32768, exc[i]); + exc2[i] = msu_r( L_tmp, -32768, exc[i] ); #endif move16(); pt_exc++; @@ -741,25 +733,25 @@ void FEC_exc_estim_fx( ELSE { /* For purely unvoiced signals - just copy the unfiltered random part of the excitation */ - Copy( exc2_buf + MODE1_L_FIR_FER/2, exc, L_frame ); - Copy( exc2_buf + MODE1_L_FIR_FER/2, exc2, L_frame ); + Copy( exc2_buf + MODE1_L_FIR_FER / 2, exc, L_frame ); + Copy( exc2_buf + MODE1_L_FIR_FER / 2, exc2, L_frame ); } - IF(st_fx->hBWE_TD != NULL) + IF( st_fx->hBWE_TD != NULL ) { - IF(EQ_16(L_frame, L_FRAME)) + IF( EQ_16( L_frame, L_FRAME ) ) { - interp_code_5over2_fx(exc, bwe_exc, L_frame); + interp_code_5over2_fx( exc, bwe_exc, L_frame ); } ELSE { - interp_code_4over2_fx(exc, bwe_exc, L_frame); + interp_code_4over2_fx( exc, bwe_exc, L_frame ); } } test(); - IF( EQ_16(st_fx->last_coder_type,AUDIO)||EQ_16(st_fx->last_good,INACTIVE_CLAS)) + IF( EQ_16( st_fx->last_coder_type, AUDIO ) || EQ_16( st_fx->last_good, INACTIVE_CLAS ) ) { - IF( EQ_16(st_fx->L_frame,L_FRAME)) + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { set16_fx( voice_factors, 32767, NB_SUBFR ); } @@ -770,20 +762,20 @@ void FEC_exc_estim_fx( } ELSE { - IF( EQ_16(st_fx->L_frame,L_FRAME)) + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { - set16_fx( voice_factors, st_fx->last_voice_factor_fx, NB_SUBFR); /* The factor of the last subframe is propagated forward */ + set16_fx( voice_factors, st_fx->last_voice_factor_fx, NB_SUBFR ); /* The factor of the last subframe is propagated forward */ } ELSE { - set16_fx( voice_factors, st_fx->last_voice_factor_fx, NB_SUBFR16k ); /* The factor of the last subframe is propagated forward */ + set16_fx( voice_factors, st_fx->last_voice_factor_fx, NB_SUBFR16k ); /* The factor of the last subframe is propagated forward */ } } IF( st_fx->Opt_AMR_WB ) { - gain_dec_bfi_fx(hAmrwb_IO->past_qua_en_fx); + gain_dec_bfi_fx( hAmrwb_IO->past_qua_en_fx ); } - st_fx->bfi_pitch_fx = pitch_buf[(L_frame/L_SUBFR)-1]; + st_fx->bfi_pitch_fx = pitch_buf[( L_frame / L_SUBFR ) - 1]; move16(); st_fx->bfi_pitch_frame = st_fx->L_frame; move16(); @@ -792,7 +784,7 @@ void FEC_exc_estim_fx( /*calculates some conditions for Pulse resynchronization to take place*/ -static void pulseRes_preCalc(Word16* cond1, Word16* cond2, Word32* cond3 ,Word16 new_pit, Word16 Tc, Word16 L_frame) +static void pulseRes_preCalc( Word16 *cond1, Word16 *cond2, Word32 *cond3, Word16 new_pit, Word16 Tc, Word16 L_frame ) { Word16 tmp_pit, tmp_pit_e, tmp_frame, tmp_frame_e; Word32 tmp_pit2; @@ -800,35 +792,35 @@ static void pulseRes_preCalc(Word16* cond1, Word16* cond2, Word32* cond3 ,Word16 Flag Overflow = 0; #endif - tmp_pit = BASOP_Util_Divide1616_Scale(new_pit/*Q0*/,Tc/*Q0*/,&tmp_pit_e)/*Q15*/; - tmp_frame = add( extract_l(L_mult0(L_frame , 64/*1.f/L_SUBFR Q12*/)/*Q12*/) , 4096/*1.f Q12*/ );/*Q12*/ - tmp_frame = BASOP_Util_Divide1616_Scale(4096/*1.f Q12*/,tmp_frame, &tmp_frame_e);/*Q15*/ - tmp_frame = shl(tmp_frame,add(tmp_frame_e,1)); - tmp_frame = sub(32767/*1.f Q15*/, tmp_frame);/*Q15*/ + tmp_pit = BASOP_Util_Divide1616_Scale( new_pit /*Q0*/, Tc /*Q0*/, &tmp_pit_e ) /*Q15*/; + tmp_frame = add( extract_l( L_mult0( L_frame, 64 /*1.f/L_SUBFR Q12*/ ) /*Q12*/ ), 4096 /*1.f Q12*/ ); /*Q12*/ + tmp_frame = BASOP_Util_Divide1616_Scale( 4096 /*1.f Q12*/, tmp_frame, &tmp_frame_e ); /*Q15*/ + tmp_frame = shl( tmp_frame, add( tmp_frame_e, 1 ) ); + tmp_frame = sub( 32767 /*1.f Q15*/, tmp_frame ); /*Q15*/ BASOP_SATURATE_WARNING_OFF_EVS /*To calc Q15 threshold, overflow may happen - do negation and compare with negated value to check also highest possible value*/ #ifdef BASOP_NOGLOB - tmp_pit = shl_o(negate(tmp_pit), tmp_pit_e, &Overflow); + tmp_pit = shl_o( negate( tmp_pit ), tmp_pit_e, &Overflow ); #else - tmp_pit = shl(negate(tmp_pit),tmp_pit_e); + tmp_pit = shl( negate( tmp_pit ), tmp_pit_e ); #endif BASOP_SATURATE_WARNING_ON_EVS - *cond1 = sub(tmp_pit, negate(tmp_frame)); + *cond1 = sub( tmp_pit, negate( tmp_frame ) ); - *cond2 = sub(Tc, new_pit); + *cond2 = sub( Tc, new_pit ); - tmp_pit_e = BASOP_Util_Add_MantExp(new_pit,15-0,negate(Tc),15-0,&tmp_pit);/*Q15*/ - tmp_pit = abs_s(tmp_pit); - tmp_pit2 = L_mult(Tc,4915/*0.15f Q15*/);/*Q16*/ + tmp_pit_e = BASOP_Util_Add_MantExp( new_pit, 15 - 0, negate( Tc ), 15 - 0, &tmp_pit ); /*Q15*/ + tmp_pit = abs_s( tmp_pit ); + tmp_pit2 = L_mult( Tc, 4915 /*0.15f Q15*/ ); /*Q16*/ BASOP_SATURATE_WARNING_OFF_EVS /*To calc Q15 threshold, overflow may happen - do negation and compare with negated value to check also highest possible value*/ #ifdef BASOP_NOGLOB tmp_pit2 = L_shl_sat( L_negate( tmp_pit2 ), sub( 15 - 16, tmp_pit_e ) ); #else - tmp_pit2 = L_shl(L_negate(tmp_pit2),sub(15-16,tmp_pit_e)); + tmp_pit2 = L_shl( L_negate( tmp_pit2 ), sub( 15 - 16, tmp_pit_e ) ); #endif BASOP_SATURATE_WARNING_ON_EVS - *cond3 = L_sub(L_mult0(-1, tmp_pit),tmp_pit2); + *cond3 = L_sub( L_mult0( -1, tmp_pit ), tmp_pit2 ); } /*-------------------------------------------------------------------* @@ -839,29 +831,29 @@ static void pulseRes_preCalc(Word16* cond1, Word16* cond2, Word32* cond3 ,Word16 *-------------------------------------------------------------------*/ void gain_dec_bfi_fx( - Word16 *past_qua_en /* i/o: gain quantization memory (4 words) */ + Word16 *past_qua_en /* i/o: gain quantization memory (4 words) */ ) { - Word16 i; + Word16 i; Word16 av_pred_en; Word32 Lav_pred_en; - Lav_pred_en = L_mult(past_qua_en[0], 8192); - FOR (i = 1; i < GAIN_PRED_ORDER; i++) + Lav_pred_en = L_mult( past_qua_en[0], 8192 ); + FOR( i = 1; i < GAIN_PRED_ORDER; i++ ) { - Lav_pred_en = L_mac(Lav_pred_en, past_qua_en[i], 8192); + Lav_pred_en = L_mac( Lav_pred_en, past_qua_en[i], 8192 ); } /*av_pred_en = (float)(av_pred_en*(1.0f/(float)GAIN_PRED_ORDER)-3.0f);*/ - av_pred_en = sub(round_fx(Lav_pred_en),3<<10); + av_pred_en = sub( round_fx( Lav_pred_en ), 3 << 10 ); /*if (av_pred_en < -14.0f)av_pred_en = -14.0f;*/ - av_pred_en = s_max(av_pred_en, -14 * (1 << 10)); + av_pred_en = s_max( av_pred_en, -14 * ( 1 << 10 ) ); - FOR (i=GAIN_PRED_ORDER-1; i>0; i--) + FOR( i = GAIN_PRED_ORDER - 1; i > 0; i-- ) { - past_qua_en[i] = past_qua_en[i-1]; + past_qua_en[i] = past_qua_en[i - 1]; move16(); } diff --git a/lib_dec/FEC_lsf_estim_fx.c b/lib_dec/FEC_lsf_estim_fx.c index bdfbb2023..21efc90e7 100644 --- a/lib_dec/FEC_lsf_estim_fx.c +++ b/lib_dec/FEC_lsf_estim_fx.c @@ -3,11 +3,11 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ /*-------------------------------------------------------------------* @@ -18,28 +18,28 @@ *-------------------------------------------------------------------*/ void FEC_lsf2lsp_interp( - Decoder_State *st, /* i/o: Decoder static memory */ - const Word16 L_frame, /* i : length of the frame */ - Word16 *Aq, /* o : calculated A(z) for 4 subframes */ - Word16 *lsf, /* o : estimated LSF vector */ - Word16 *lsp /* o : estimated LSP vector */ + Decoder_State *st, /* i/o: Decoder static memory */ + const Word16 L_frame, /* i : length of the frame */ + Word16 *Aq, /* o : calculated A(z) for 4 subframes */ + Word16 *lsf, /* o : estimated LSF vector */ + Word16 *lsp /* o : estimated LSP vector */ ) { /* convert LSFs to LSPs */ - IF ( st->Opt_AMR_WB ) + IF( st->Opt_AMR_WB ) { - E_LPC_isf_isp_conversion( lsf, lsp, M); + E_LPC_isf_isp_conversion( lsf, lsp, M ); } ELSE { - IF( EQ_16(L_frame,L_FRAME)) + IF( EQ_16( L_frame, L_FRAME ) ) { lsf2lsp_fx( lsf, lsp, M, INT_FS_FX ); } ELSE /* L_frame == L_FRAME16k */ { - lsf2lsp_fx( lsf, lsp, M, INT_FS_16k_FX); + lsf2lsp_fx( lsf, lsp, M, INT_FS_16k_FX ); } } @@ -47,7 +47,7 @@ void FEC_lsf2lsp_interp( * Interpolate LSP vector and find A(z) *----------------------------------------------------------------------*/ - IF ( st->Opt_AMR_WB ) + IF( st->Opt_AMR_WB ) { int_lsp_fx( L_frame, st->lsp_old_fx, lsp, Aq, M, interpol_isp_amr_wb_fx, 1 ); } diff --git a/lib_dec/FEC_pitch_estim_fx.c b/lib_dec/FEC_pitch_estim_fx.c index 713e4c579..4fa36e5b8 100644 --- a/lib_dec/FEC_pitch_estim_fx.c +++ b/lib_dec/FEC_pitch_estim_fx.c @@ -2,10 +2,10 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ #include "stl.h" @@ -37,39 +37,41 @@ /*========================================================================*/ #ifdef IVAS_FLOAT_FIXED void FEC_pitch_estim_fx( - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 last_core, /* i : last core */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 clas, /* i : current frame classification */ - const Word16 last_good, /* i : last good clas information */ - const Word16 pitch_buf[], /* i : Floating pitch for each subframe */ - const Word32 old_pitch_buf[], /* i : buffer of old subframe pitch values 15Q16 */ - Word16 *bfi_pitch, /* i/o: update of the estimated pitch for FEC */ - Word16 *bfi_pitch_frame, /* o : frame length when pitch was updated */ - Word16 *upd_cnt /* i/o: update counter */ - ,const Word16 coder_type, /* i : coder_type */ - Word16 element_mode /* i : element mode */ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const Word16 last_core, /* i : last core */ + const Word16 L_frame, /* i : length of the frame */ + const Word16 clas, /* i : current frame classification */ + const Word16 last_good, /* i : last good clas information */ + const Word16 pitch_buf[], /* i : Floating pitch for each subframe */ + const Word32 old_pitch_buf[], /* i : buffer of old subframe pitch values 15Q16 */ + Word16 *bfi_pitch, /* i/o: update of the estimated pitch for FEC */ + Word16 *bfi_pitch_frame, /* o : frame length when pitch was updated */ + Word16 *upd_cnt /* i/o: update counter */ + , + const Word16 coder_type, /* i : coder_type */ + Word16 element_mode /* i : element mode */ ) { - Word16 tmp,tmp1,tmp2,tmp3; - Word16 tmp16k1,tmp16k2; + Word16 tmp, tmp1, tmp2, tmp3; + Word16 tmp16k1, tmp16k2; - tmp = mult_r(pitch_buf[1],22938); /*Q6( 0.7f * pitch_buf[1] 0.7 in Q15)*/ - tmp1 = shl(tmp,1); /*Q6 (1.4f * pitch_buf[1])*/ - tmp2 = round_fx(L_shl(Mpy_32_16_1(old_pitch_buf[2*NB_SUBFR-1],22938), 6)); /*Q6 (0.7f * old_pitch_buf[2*NB_SUBFR-1])*/ - tmp3 = shl(tmp2,1); /*Q6 (1.4f * old_pitch_buf[2*NB_SUBFR-1])*/ + tmp = mult_r( pitch_buf[1], 22938 ); /*Q6( 0.7f * pitch_buf[1] 0.7 in Q15)*/ + tmp1 = shl( tmp, 1 ); /*Q6 (1.4f * pitch_buf[1])*/ + tmp2 = round_fx( L_shl( Mpy_32_16_1( old_pitch_buf[2 * NB_SUBFR - 1], 22938 ), 6 ) ); /*Q6 (0.7f * old_pitch_buf[2*NB_SUBFR-1])*/ + tmp3 = shl( tmp2, 1 ); /*Q6 (1.4f * old_pitch_buf[2*NB_SUBFR-1])*/ - tmp16k1 = round_fx(L_shl(Mpy_32_16_1(old_pitch_buf[2*NB_SUBFR16k-1],22938), 6)); /*Q6 0.7f * old_pitch_buf[2*NB_SUBFR16k-1]*/ + tmp16k1 = round_fx( L_shl( Mpy_32_16_1( old_pitch_buf[2 * NB_SUBFR16k - 1], 22938 ), 6 ) ); /*Q6 0.7f * old_pitch_buf[2*NB_SUBFR16k-1]*/ #ifdef BASOP_NOGLOB - tmp16k2 = shl_sat(tmp16k1,1); /*Q6 1.4f * old_pitch_buf[2*NB_SUBFR16k-1]*/ + tmp16k2 = shl_sat( tmp16k1, 1 ); /*Q6 1.4f * old_pitch_buf[2*NB_SUBFR16k-1]*/ #else - tmp16k2 = shl(tmp16k1,1); /*Q6 1.4f * old_pitch_buf[2*NB_SUBFR16k-1]*/ + tmp16k2 = shl( tmp16k1, 1 ); /*Q6 1.4f * old_pitch_buf[2*NB_SUBFR16k-1]*/ #endif - test(); test(); - IF ((EQ_16(element_mode, EVS_MONO) && EQ_16(last_core, HQ_CORE)) || (NE_16(element_mode, EVS_MONO) && (EQ_16(last_core, HQ_CORE) || EQ_16(last_core, TCX_20_CORE) || EQ_16(last_core, TCX_10_CORE)))) + test(); + test(); + IF( ( EQ_16( element_mode, EVS_MONO ) && EQ_16( last_core, HQ_CORE ) ) || ( NE_16( element_mode, EVS_MONO ) && ( EQ_16( last_core, HQ_CORE ) || EQ_16( last_core, TCX_20_CORE ) || EQ_16( last_core, TCX_10_CORE ) ) ) ) { - *bfi_pitch = pitch_buf[shr(L_frame,6)-1]; + *bfi_pitch = pitch_buf[shr( L_frame, 6 ) - 1]; move16(); *bfi_pitch_frame = L_frame; move16(); @@ -80,7 +82,7 @@ void FEC_pitch_estim_fx( test(); test(); test(); - IF( (EQ_16(clas,VOICED_CLAS)&&GE_16(last_good,VOICED_TRANSITION))||(Opt_AMR_WB&&EQ_16(clas,VOICED_CLAS))) + IF( ( EQ_16( clas, VOICED_CLAS ) && GE_16( last_good, VOICED_TRANSITION ) ) || ( Opt_AMR_WB && EQ_16( clas, VOICED_CLAS ) ) ) { test(); test(); @@ -92,15 +94,15 @@ void FEC_pitch_estim_fx( test(); test(); test(); - IF( ( (LT_16(pitch_buf[3],tmp1))&&(GT_16(pitch_buf[3],tmp))&& - (LT_16(pitch_buf[1],tmp3) ) && (GT_16(pitch_buf[1],tmp2) ) && - (EQ_16(L_frame,L_FRAME) ) ) || - ( (LT_16(pitch_buf[3],tmp1) ) && (GT_16(pitch_buf[3],tmp) ) && - (LT_16(pitch_buf[1],tmp16k2) ) && (GT_16(pitch_buf[1],tmp16k1) ) && - (EQ_16(L_frame,L_FRAME16k) ) ) - || (EQ_16(coder_type, TRANSITION) ) ) + IF( ( ( LT_16( pitch_buf[3], tmp1 ) ) && ( GT_16( pitch_buf[3], tmp ) ) && + ( LT_16( pitch_buf[1], tmp3 ) ) && ( GT_16( pitch_buf[1], tmp2 ) ) && + ( EQ_16( L_frame, L_FRAME ) ) ) || + ( ( LT_16( pitch_buf[3], tmp1 ) ) && ( GT_16( pitch_buf[3], tmp ) ) && + ( LT_16( pitch_buf[1], tmp16k2 ) ) && ( GT_16( pitch_buf[1], tmp16k1 ) ) && + ( EQ_16( L_frame, L_FRAME16k ) ) ) || + ( EQ_16( coder_type, TRANSITION ) ) ) { - *bfi_pitch = pitch_buf[shr(L_frame,6)-1]; + *bfi_pitch = pitch_buf[shr( L_frame, 6 ) - 1]; move16(); *bfi_pitch_frame = L_frame; move16(); diff --git a/lib_dec/FEC_scale_syn.c b/lib_dec/FEC_scale_syn.c index cd6feb24d..58d0dbc96 100644 --- a/lib_dec/FEC_scale_syn.c +++ b/lib_dec/FEC_scale_syn.c @@ -440,4 +440,4 @@ void FEC_scale_syn( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/FEC_scale_syn_fx.c b/lib_dec/FEC_scale_syn_fx.c index 120855b12..24fca62db 100644 --- a/lib_dec/FEC_scale_syn_fx.c +++ b/lib_dec/FEC_scale_syn_fx.c @@ -2,16 +2,16 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ /*-------------------------------------------------------------------* * Local constants *-------------------------------------------------------------------*/ -#define AGC_FX 32113 /* 0.98f */ -#define SCLSYN_LAMBDA (9830/*0.3f Q15*/) +#define AGC_FX 32113 /* 0.98f */ +#define SCLSYN_LAMBDA ( 9830 /*0.3f Q15*/ ) /*========================================================================*/ /* FUNCTION : FEC_scale_syn_fx() */ @@ -53,33 +53,33 @@ #ifdef IVAS_FLOAT_FIXED void FEC_scale_syn_fx( - const Word16 L_frame, /* i : length of the frame */ - Word16 *update_flg, /* o: flag indicating re-synthesis after scaling*/ - Word16 clas, /* i/o: frame classification */ - const Word16 last_good, /* i: last good frame classification */ - Word16 *synth, /* i/o: synthesized speech at Fs = 12k8 Hz */ - const Word16 *pitch, /* i: pitch values for each subframe */ - Word32 L_enr_old, /* i: energy at the end of previous frame */ - Word32 L_enr_q, /* i: transmitted energy for current frame */ - const Word16 coder_type, /* i: coder type */ - const Word16 LSF_Q_prediction, /* i : LSF prediction mode */ - Word16 *scaling_flag, /* i/o: flag to indicate energy control of syn */ - Word32 *lp_ener_FEC_av, /* i/o: averaged voiced signal energy */ - Word32 *lp_ener_FEC_max, /* i/o: averaged voiced signal energy */ - const Word16 bfi, /* i: current frame BFI */ - const Word32 total_brate, /* i: total bitrate */ - const Word16 prev_bfi, /* i: previous frame BFI */ - const Word32 last_core_brate, /* i: previous frame core bitrate */ - Word16 *exc, /* i/o: excitation signal without enhancement */ - Word16 *exc2, /* i/o: excitation signal with enhancement */ - Word16 Aq[], /* i/o: LP filter coefs (can be modified if BR) */ - Word16 *old_enr_LP, /* i/o: LP filter E of last good voiced frame */ - const Word16 *mem_tmp, /* i: temp. initial synthesis filter states */ - Word16 *mem_syn, /* o: initial synthesis filter states */ + const Word16 L_frame, /* i : length of the frame */ + Word16 *update_flg, /* o: flag indicating re-synthesis after scaling*/ + Word16 clas, /* i/o: frame classification */ + const Word16 last_good, /* i: last good frame classification */ + Word16 *synth, /* i/o: synthesized speech at Fs = 12k8 Hz */ + const Word16 *pitch, /* i: pitch values for each subframe */ + Word32 L_enr_old, /* i: energy at the end of previous frame */ + Word32 L_enr_q, /* i: transmitted energy for current frame */ + const Word16 coder_type, /* i: coder type */ + const Word16 LSF_Q_prediction, /* i : LSF prediction mode */ + Word16 *scaling_flag, /* i/o: flag to indicate energy control of syn */ + Word32 *lp_ener_FEC_av, /* i/o: averaged voiced signal energy */ + Word32 *lp_ener_FEC_max, /* i/o: averaged voiced signal energy */ + const Word16 bfi, /* i: current frame BFI */ + const Word32 total_brate, /* i: total bitrate */ + const Word16 prev_bfi, /* i: previous frame BFI */ + const Word32 last_core_brate, /* i: previous frame core bitrate */ + Word16 *exc, /* i/o: excitation signal without enhancement */ + Word16 *exc2, /* i/o: excitation signal with enhancement */ + Word16 Aq[], /* i/o: LP filter coefs (can be modified if BR) */ + Word16 *old_enr_LP, /* i/o: LP filter E of last good voiced frame */ + const Word16 *mem_tmp, /* i: temp. initial synthesis filter states */ + Word16 *mem_syn, /* o: initial synthesis filter states */ Word16 Q_exc, Word16 Q_syn, - const Word16 avoid_lpc_burst_on_recovery, /* i : if true the excitation energy is limited if LP has big gain */ - const Word16 force_scaling /* i: force scaling */ + const Word16 avoid_lpc_burst_on_recovery, /* i : if true the excitation energy is limited if LP has big gain */ + const Word16 force_scaling /* i: force scaling */ ) { Word16 i; @@ -90,7 +90,7 @@ void FEC_scale_syn_fx( Word32 L_tmp; Word16 scaling; Word32 ener_max, L_enr2_av, L_ener2_max; - Word16 h1[L_FRAME/2], tilt, pitch_dist, mean_pitch; + Word16 h1[L_FRAME / 2], tilt, pitch_dist, mean_pitch; Word16 k; Word32 L_mean_pitch; @@ -102,148 +102,150 @@ void FEC_scale_syn_fx( move16(); *update_flg = 0; move16(); - L_enr_old = L_max(1, L_enr_old); /* to avoid division by zero (*L_enr_old is always >= 0) */ + L_enr_old = L_max( 1, L_enr_old ); /* to avoid division by zero (*L_enr_old is always >= 0) */ scaling = 16384; - move16(); /* Q14*/ + move16(); /* Q14*/ /*-----------------------------------------------------------------* * Find the synthesis filter impulse response on voiced *-----------------------------------------------------------------*/ test(); - IF( GE_16(clas,VOICED_TRANSITION)&<_16(clas,INACTIVE_CLAS)) + IF( GE_16( clas, VOICED_TRANSITION ) && LT_16( clas, INACTIVE_CLAS ) ) { - IF( EQ_16(L_frame,L_FRAME)) + IF( EQ_16( L_frame, L_FRAME ) ) { - enr_LP = Enr_1_Az_fx(Aq+(NB_SUBFR-1)*(M+1), L_SUBFR ); + enr_LP = Enr_1_Az_fx( Aq + ( NB_SUBFR - 1 ) * ( M + 1 ), L_SUBFR ); } - ELSE /* L_frame == L_FRAME16k */ + ELSE /* L_frame == L_FRAME16k */ { - enr_LP = Enr_1_Az_fx( Aq+(NB_SUBFR16k-1)*(M+1), L_SUBFR ); /*Q3*/ + enr_LP = Enr_1_Az_fx( Aq + ( NB_SUBFR16k - 1 ) * ( M + 1 ), L_SUBFR ); /*Q3*/ } } /*-----------------------------------------------------------------* - * Define when to scale the synthesis - *-----------------------------------------------------------------*/ + * Define when to scale the synthesis + *-----------------------------------------------------------------*/ IF( bfi ) { *scaling_flag = 1; - move16(); /* Always check synthesis on bad frames */ + move16(); /* Always check synthesis on bad frames */ } ELSE IF( prev_bfi ) { test(); - IF( ( EQ_16(LSF_Q_prediction,AUTO_REGRESSIVE))||(EQ_16(LSF_Q_prediction,MOVING_AVERAGE))) + IF( ( EQ_16( LSF_Q_prediction, AUTO_REGRESSIVE ) ) || ( EQ_16( LSF_Q_prediction, MOVING_AVERAGE ) ) ) { *scaling_flag = 2; - move16(); /* Decoded LSFs affected */ + move16(); /* Decoded LSFs affected */ } - ELSE IF( NE_16(coder_type,TRANSITION)) + ELSE IF( NE_16( coder_type, TRANSITION ) ) { *scaling_flag = 1; - move16(); /* SN, but not TC mode - LSF still affected by the interpolation */ + move16(); /* SN, but not TC mode - LSF still affected by the interpolation */ } ELSE { *scaling_flag = 0; - move16(); /* LSF still possibly affected due to interpolation */ + move16(); /* LSF still possibly affected due to interpolation */ } - scaling = 24576; /*1.5 Q14*/ move16(); + scaling = 24576; /*1.5 Q14*/ + move16(); } ELSE { test(); - IF( (EQ_16(LSF_Q_prediction,AUTO_REGRESSIVE))&&(EQ_16(*scaling_flag,2))) + IF( ( EQ_16( LSF_Q_prediction, AUTO_REGRESSIVE ) ) && ( EQ_16( *scaling_flag, 2 ) ) ) { *scaling_flag = 2; - move16(); /* Continue with energy control till the end of AR prediction */ + move16(); /* Continue with energy control till the end of AR prediction */ } ELSE IF( *scaling_flag > 0 ) { - (*scaling_flag) = sub(*scaling_flag,1); /* If scaling flag was equal to 2, add one control frame to account for the LSF interpolation */ + ( *scaling_flag ) = sub( *scaling_flag, 1 ); /* If scaling flag was equal to 2, add one control frame to account for the LSF interpolation */ } - scaling = 32767; /*2.0 Q14*/ move16(); + scaling = 32767; /*2.0 Q14*/ + move16(); } /*-----------------------------------------------------------------* - * Find the energy/gain at the end of the frame - *-----------------------------------------------------------------*/ + * Find the energy/gain at the end of the frame + *-----------------------------------------------------------------*/ /*fer_energy( L_frame, clas, synth, pitch[(L_frame>>6)-1], &enr2, L_frame );*/ - frame_ener_fx(L_frame,clas, synth, pitch[sub(shr(L_frame,6),1)], &L_enr2/*Q0*/, 1, Q_syn, 3, 0); + frame_ener_fx( L_frame, clas, synth, pitch[sub( shr( L_frame, 6 ), 1 )], &L_enr2 /*Q0*/, 1, Q_syn, 3, 0 ); - if( bfi || (EQ_32(total_brate,ACELP_7k20))||(EQ_32(total_brate,ACELP_8k00))) + if ( bfi || ( EQ_32( total_brate, ACELP_7k20 ) ) || ( EQ_32( total_brate, ACELP_8k00 ) ) ) { /* previous frame erased and no TC frame */ IF( *scaling_flag > 0 ) { /*enr2 += 0.01f;*/ - L_enr2 = L_max(L_enr2, 1); /* L_enr2 is in Q0 */ + L_enr2 = L_max( L_enr2, 1 ); /* L_enr2 is in Q0 */ - IF( bfi ) /* In all bad frames, limit the gain to 1 */ + IF( bfi ) /* In all bad frames, limit the gain to 1 */ { /* gain2 = (float)sqrt( enr_old / enr2 );*/ - L_tmp = Sqrt_Ratio32(L_enr_old, 0, L_enr2, 0, &exp2); + L_tmp = Sqrt_Ratio32( L_enr_old, 0, L_enr2, 0, &exp2 ); #ifdef BASOP_NOGLOB - gain2 = round_fx_sat(L_shl_sat(L_tmp, sub(exp2, 1))); /* in Q14 */ + gain2 = round_fx_sat( L_shl_sat( L_tmp, sub( exp2, 1 ) ) ); /* in Q14 */ #else - gain2 = round_fx(L_shl(L_tmp, sub(exp2, 1))); /* in Q14 */ + gain2 = round_fx( L_shl( L_tmp, sub( exp2, 1 ) ) ); /* in Q14 */ #endif /*if( gain2 > 1.0f )gain2 = 1.0f;*/ - gain2 = s_min(gain2, 16384); + gain2 = s_min( gain2, 16384 ); /* find the energy/gain at the beginning of the frame */ - frame_ener_fx(L_frame,clas, synth, pitch[0], &L_enr1/*Q0*/, 1, Q_syn, 3, 0); + frame_ener_fx( L_frame, clas, synth, pitch[0], &L_enr1 /*Q0*/, 1, Q_syn, 3, 0 ); /*enr1 += 0.1f;*/ - L_enr1 = L_max(L_enr1, 1); /* L_enr2 is in Q0 */ + L_enr1 = L_max( L_enr1, 1 ); /* L_enr2 is in Q0 */ /*gain1 = (float)sqrt( enr_old / enr1 );*/ - L_tmp = Sqrt_Ratio32(L_enr_old, 0, L_enr1, 0, &exp2); + L_tmp = Sqrt_Ratio32( L_enr_old, 0, L_enr1, 0, &exp2 ); #ifdef BASOP_NOGLOB - gain1 = round_fx_sat(L_shl_sat(L_tmp, sub(exp2, 1))); /* in Q14 */ + gain1 = round_fx_sat( L_shl_sat( L_tmp, sub( exp2, 1 ) ) ); /* in Q14 */ #else - gain1 = round_fx(L_shl(L_tmp, sub(exp2, 1))); /* in Q14 */ + gain1 = round_fx( L_shl( L_tmp, sub( exp2, 1 ) ) ); /* in Q14 */ #endif /*if( gain1 > 1.0f )gain1 = 1.0f;*/ - gain1 = s_min(gain1, 16384); + gain1 = s_min( gain1, 16384 ); } - ELSE /* good frame */ + ELSE /* good frame */ { - IF( L_enr_q == 0 ) /* If E info (FEC protection bits) is not available in the bitstream */ + IF( L_enr_q == 0 ) /* If E info (FEC protection bits) is not available in the bitstream */ { L_enr_q = L_enr2; - set16_fx( h1, 0, L_FRAME/2 ); + set16_fx( h1, 0, L_FRAME / 2 ); h1[0] = 1024; move16(); /*syn_filt( Aq+(3*(M+1)), M, h1, h1, L_FRAME/2, h1+(M+1), 0 );*/ - E_UTIL_synthesis(1, Aq+(3*(M+1)), h1, h1, L_FRAME/2, h1+(M+1), 0, M); + E_UTIL_synthesis( 1, Aq + ( 3 * ( M + 1 ) ), h1, h1, L_FRAME / 2, h1 + ( M + 1 ), 0, M ); /*Compute tilt */ /*rr0 = dotp( h1, h1, L_FRAME/2-1 ) + 0.1f;*/ /*rr1 = dotp( h1, h1+1, L_FRAME/2-1 );*/ /*tilt = rr1 / rr0;*/ #ifdef BASOP_NOGLOB - tilt = extract_h(L_shl_sat(get_gain(h1+1, h1, L_FRAME/2-1),15)); + tilt = extract_h( L_shl_sat( get_gain( h1 + 1, h1, L_FRAME / 2 - 1 ), 15 ) ); #else - tilt = extract_h(L_shl(get_gain(h1+1, h1, L_FRAME/2-1),15)); + tilt = extract_h( L_shl( get_gain( h1 + 1, h1, L_FRAME / 2 - 1 ), 15 ) ); #endif pitch_dist = 0; move16(); - L_mean_pitch = L_mult(pitch[0], 8192); + L_mean_pitch = L_mult( pitch[0], 8192 ); move32(); - FOR( k=0; k<(NB_SUBFR - 1); k++ ) + FOR( k = 0; k < ( NB_SUBFR - 1 ); k++ ) { - pitch_dist = add(pitch_dist, abs_s(sub(pitch[k+1],pitch[k]))); - L_mean_pitch = L_mac(L_mean_pitch, pitch[k+1], 8192); + pitch_dist = add( pitch_dist, abs_s( sub( pitch[k + 1], pitch[k] ) ) ); + L_mean_pitch = L_mac( L_mean_pitch, pitch[k + 1], 8192 ); } /*pitch_dist /= (float)(NB_SUBFR-1); */ - pitch_dist = mult_r(shl(pitch_dist,4),10923); + pitch_dist = mult_r( shl( pitch_dist, 4 ), 10923 ); /*mean_pitch /= (float)(NB_SUBFR);*/ - mean_pitch = extract_h(L_shl(L_mean_pitch,4)); + mean_pitch = extract_h( L_shl( L_mean_pitch, 4 ) ); test(); @@ -252,15 +254,15 @@ void FEC_scale_syn_fx( test(); test(); test(); - IF( ( GT_16(tilt,22938))&& /* HF resonnant filter */ - ( (GT_16(pitch_dist, 8<<4) ) || (LT_16(mean_pitch,PIT_MIN<<4) ) ) && /* pitch unstable or very short */ - ( (prev_bfi) || ( (EQ_16(coder_type,GENERIC) ) && (EQ_16(LSF_Q_prediction,AUTO_REGRESSIVE) ) ) ) ) + IF( ( GT_16( tilt, 22938 ) ) && /* HF resonnant filter */ + ( ( GT_16( pitch_dist, 8 << 4 ) ) || ( LT_16( mean_pitch, PIT_MIN << 4 ) ) ) && /* pitch unstable or very short */ + ( ( prev_bfi ) || ( ( EQ_16( coder_type, GENERIC ) ) && ( EQ_16( LSF_Q_prediction, AUTO_REGRESSIVE ) ) ) ) ) { /*if( enr_q > scaling * enr_old ){enr_q = scaling * enr_old;}*/ #ifdef BASOP_NOGLOB L_enr_q = L_min( L_enr_q, L_shl_sat( Mult_32_16( L_enr_old, scaling ), 1 ) ); /* scaling in Q14*/ #else - L_enr_q = L_min(L_enr_q, L_shl(Mult_32_16(L_enr_old, scaling),1)); /* scaling in Q14*/ + L_enr_q = L_min( L_enr_q, L_shl( Mult_32_16( L_enr_old, scaling ), 1 ) ); /* scaling in Q14*/ #endif } ELSE @@ -268,30 +270,30 @@ void FEC_scale_syn_fx( ener_max = *lp_ener_FEC_max; move32(); test(); - if( EQ_16(clas,VOICED_TRANSITION)||(GE_16(clas,INACTIVE_CLAS))) + if ( EQ_16( clas, VOICED_TRANSITION ) || ( GE_16( clas, INACTIVE_CLAS ) ) ) { ener_max = *lp_ener_FEC_av; move32(); } /*if( enr_old > ener_max )ener_max = enr_old;*/ - ener_max = L_max(ener_max, L_enr_old); + ener_max = L_max( ener_max, L_enr_old ); /*if( enr_q > scaling * ener_max ){enr_q = scaling * ener_max;}*/ #ifdef BASOP_NOGLOB - L_enr_q = L_min(L_enr_q, L_shl_sat(Mult_32_16(ener_max, scaling),1)); /* scaling in Q14*/ + L_enr_q = L_min( L_enr_q, L_shl_sat( Mult_32_16( ener_max, scaling ), 1 ) ); /* scaling in Q14*/ #else - L_enr_q = L_min(L_enr_q, L_shl(Mult_32_16(ener_max, scaling),1)); /* scaling in Q14*/ + L_enr_q = L_min( L_enr_q, L_shl( Mult_32_16( ener_max, scaling ), 1 ) ); /* scaling in Q14*/ #endif } } /*gain2 = (float)sqrt( enr_q / enr2 );*/ - L_enr_q = L_max(L_enr_q, 1); /* L_enr2 is in Q0 */ - L_tmp = Sqrt_Ratio32(L_enr_q, 0, L_enr2, 0, &exp2); - gain2 = round_fx(L_shl(L_tmp, sub(exp2, 1))); /* in Q14 */ + L_enr_q = L_max( L_enr_q, 1 ); /* L_enr2 is in Q0 */ + L_tmp = Sqrt_Ratio32( L_enr_q, 0, L_enr2, 0, &exp2 ); + gain2 = round_fx( L_shl( L_tmp, sub( exp2, 1 ) ) ); /* in Q14 */ /*-----------------------------------------------------------------* - * Find the energy/gain at the beginning of the frame to ensure smooth transition after erasure(s) - *-----------------------------------------------------------------*/ + * Find the energy/gain at the beginning of the frame to ensure smooth transition after erasure(s) + *-----------------------------------------------------------------*/ test(); test(); @@ -299,8 +301,9 @@ void FEC_scale_syn_fx( test(); test(); test(); - IF( ( (GE_16(last_good,VOICED_TRANSITION)&<_16(last_good,INACTIVE_CLAS)&&(EQ_16(clas,UNVOICED_CLAS)||EQ_16(clas,INACTIVE_CLAS)))|| - EQ_32(last_core_brate,SID_1k75) || EQ_32(last_core_brate,SID_2k40) || EQ_32(last_core_brate,FRAME_NO_DATA) ) && prev_bfi ) + IF( ( ( GE_16( last_good, VOICED_TRANSITION ) && LT_16( last_good, INACTIVE_CLAS ) && ( EQ_16( clas, UNVOICED_CLAS ) || EQ_16( clas, INACTIVE_CLAS ) ) ) || + EQ_32( last_core_brate, SID_1k75 ) || EQ_32( last_core_brate, SID_2k40 ) || EQ_32( last_core_brate, FRAME_NO_DATA ) ) && + prev_bfi ) { /* voiced -> unvoiced signal transition */ /* CNG -> active signal transition */ @@ -310,27 +313,27 @@ void FEC_scale_syn_fx( ELSE { /* find the energy at the beginning of the frame */ - frame_ener_fx(L_frame,clas, synth, pitch[0], &L_enr1/*Q0*/, 1, Q_syn, 3, 0); + frame_ener_fx( L_frame, clas, synth, pitch[0], &L_enr1 /*Q0*/, 1, Q_syn, 3, 0 ); /*enr1 += 0.1f;*/ - L_enr1 = L_max(L_enr1, 1); /* L_enr1 is in Q0 */ + L_enr1 = L_max( L_enr1, 1 ); /* L_enr1 is in Q0 */ /*gain1 = (float)sqrt( enr_old / enr1 );*/ - L_tmp = Sqrt_Ratio32(L_enr_old, 0, L_enr1, 0, &exp2); + L_tmp = Sqrt_Ratio32( L_enr_old, 0, L_enr1, 0, &exp2 ); #ifdef BASOP_NOGLOB - gain1 = round_fx_sat(L_shl_sat(L_tmp, sub(exp2, 1))); /* in Q14 */ + gain1 = round_fx_sat( L_shl_sat( L_tmp, sub( exp2, 1 ) ) ); /* in Q14 */ #else - gain1 = round_fx(L_shl(L_tmp, sub(exp2, 1))); /* in Q14 */ + gain1 = round_fx( L_shl( L_tmp, sub( exp2, 1 ) ) ); /* in Q14 */ #endif /*if( gain1 > 1.2f )gain1 = 1.2f;*/ /* prevent clipping */ - gain1 = s_min(gain1, 19661); + gain1 = s_min( gain1, 19661 ); /* prevent amplifying the unvoiced or inactive part of the frame in case an offset is followed by an onset */ test(); test(); - if( EQ_16(clas,ONSET)&>_16(gain1,gain2)&&prev_bfi) + if ( EQ_16( clas, ONSET ) && GT_16( gain1, gain2 ) && prev_bfi ) { gain1 = gain2; move16(); @@ -338,33 +341,33 @@ void FEC_scale_syn_fx( } L_enr2 = L_enr_q; - move32(); /* Set the end frame energy to the scaled energy, to be used in the lp_ener_FEC */ + move32(); /* Set the end frame energy to the scaled energy, to be used in the lp_ener_FEC */ } /*------------------------------------------------------------------------------* - * Smooth the energy evolution by exponentially evolving from gain1 to gain2 - *------------------------------------------------------------------------------*/ + * Smooth the energy evolution by exponentially evolving from gain1 to gain2 + *------------------------------------------------------------------------------*/ /*gain2 *= ( 1.0f - AGC );*/ - L_tmp = L_mult(gain2, (Word16)(32768 - AGC_FX)); - FOR( i=0; i scaling * enr_old )enr_q = scaling * enr_old;*/ #ifdef BASOP_NOGLOB L_enr_q = L_min( L_enr_q, L_shl_sat( Mult_32_16( L_enr_old, scaling ), 1 ) ); /* scaling in Q14*/ #else - L_enr_q = L_min(L_enr_q, L_shl(Mult_32_16(L_enr_old, scaling),1)); /* scaling in Q14*/ + L_enr_q = L_min( L_enr_q, L_shl( Mult_32_16( L_enr_old, scaling ), 1 ) ); /* scaling in Q14*/ #endif } - ELSE IF( GE_16(last_good,VOICED_TRANSITION)&<_16(last_good,INACTIVE_CLAS)&&GE_16(clas,VOICED_TRANSITION)&<_16(clas,INACTIVE_CLAS)) + ELSE IF( GE_16( last_good, VOICED_TRANSITION ) && LT_16( last_good, INACTIVE_CLAS ) && GE_16( clas, VOICED_TRANSITION ) && LT_16( clas, INACTIVE_CLAS ) ) { /* Voiced-voiced recovery */ test(); #ifdef BASOP_NOGLOB - IF( *old_enr_LP != 0 && GT_16(enr_LP, shl_sat(*old_enr_LP, 1))) + IF( *old_enr_LP != 0 && GT_16( enr_LP, shl_sat( *old_enr_LP, 1 ) ) ) #else - IF( *old_enr_LP != 0 && GT_16(enr_LP, shl(*old_enr_LP, 1))) + IF( *old_enr_LP != 0 && GT_16( enr_LP, shl( *old_enr_LP, 1 ) ) ) #endif { /* enr_q /= enr_LP */ - exp = norm_l(L_enr_q); - tmp = extract_h(L_shl(L_enr_q, exp)); + exp = norm_l( L_enr_q ); + tmp = extract_h( L_shl( L_enr_q, exp ) ); - exp2 = norm_s(enr_LP); - tmp2 = shl(enr_LP, exp2); + exp2 = norm_s( enr_LP ); + tmp2 = shl( enr_LP, exp2 ); - exp = sub(exp2, exp); + exp = sub( exp2, exp ); - tmp3 = sub(tmp, tmp2); - IF (tmp3 > 0) + tmp3 = sub( tmp, tmp2 ); + IF( tmp3 > 0 ) { - tmp = shr(tmp, 1); - exp = add(exp, 1); + tmp = shr( tmp, 1 ); + exp = add( exp, 1 ); } - tmp = div_s(tmp, tmp2); + tmp = div_s( tmp, tmp2 ); /* L_enr_q *= 2 * *old_enr_LP */ - L_enr_q = L_shl(L_mult(tmp, shl(*old_enr_LP, 1)), exp); + L_enr_q = L_shl( L_mult( tmp, shl( *old_enr_LP, 1 ) ), exp ); } ELSE { test(); - IF( avoid_lpc_burst_on_recovery && GT_16(enr_LP, 160)) + IF( avoid_lpc_burst_on_recovery && GT_16( enr_LP, 160 ) ) { - exp = norm_s(enr_LP); - tmp = shl(enr_LP, exp); + exp = norm_s( enr_LP ); + tmp = shl( enr_LP, exp ); exp2 = 7; move16(); tmp2 = 160 << 7; /* 160 = 20.0f in Q3 */ - exp = sub(exp2, exp); + exp = sub( exp2, exp ); - IF (GT_16(tmp, tmp2)) + IF( GT_16( tmp, tmp2 ) ) { - tmp = shr(tmp, 1); - exp = add(exp, 1); + tmp = shr( tmp, 1 ); + exp = add( exp, 1 ); } - tmp = div_s(tmp, tmp2); /* tmp*2^exp = enr_LP/20.0 */ - L_tmp = Isqrt_lc(L_deposit_h(tmp), &exp); /* L_tmp*2^exp = sqrt(20.0/enr_LP) */ - L_enr_q = L_shl(Mpy_32_32(L_enr_q, L_tmp), exp); + tmp = div_s( tmp, tmp2 ); /* tmp*2^exp = enr_LP/20.0 */ + L_tmp = Isqrt_lc( L_deposit_h( tmp ), &exp ); /* L_tmp*2^exp = sqrt(20.0/enr_LP) */ + L_enr_q = L_shl( Mpy_32_32( L_enr_q, L_tmp ), exp ); } } - } test(); test(); test(); - IF( (GE_16(last_good,VOICED_TRANSITION)&<_16(last_good,INACTIVE_CLAS)&&GE_16(clas,VOICED_TRANSITION)&<_16(clas,INACTIVE_CLAS)) - || force_scaling ) + IF( ( GE_16( last_good, VOICED_TRANSITION ) && LT_16( last_good, INACTIVE_CLAS ) && GE_16( clas, VOICED_TRANSITION ) && LT_16( clas, INACTIVE_CLAS ) ) || force_scaling ) { - IF( GT_32(L_enr_q, L_enr_old)) /* Prevent energy to increase on voiced */ + IF( GT_32( L_enr_q, L_enr_old ) ) /* Prevent energy to increase on voiced */ { - L_enr_q = L_add(Mpy_32_16_1(L_enr_old, 32767 - SCLSYN_LAMBDA), Mpy_32_16_1(L_enr_q, SCLSYN_LAMBDA)); + L_enr_q = L_add( Mpy_32_16_1( L_enr_old, 32767 - SCLSYN_LAMBDA ), Mpy_32_16_1( L_enr_q, SCLSYN_LAMBDA ) ); } } } - L_enr_q = L_max(1, L_enr_q); + L_enr_q = L_max( 1, L_enr_q ); /* gain2 = (float)sqrt( enr_q / enr2 );*/ - exp = norm_l(L_enr_q); - tmp = extract_h(L_shl(L_enr_q, exp)); + exp = norm_l( L_enr_q ); + tmp = extract_h( L_shl( L_enr_q, exp ) ); - exp2 = norm_l(L_enr2); - tmp2 = extract_h(L_shl(L_enr2, exp2)); + exp2 = norm_l( L_enr2 ); + tmp2 = extract_h( L_shl( L_enr2, exp2 ) ); - exp2 = sub(exp, exp2); /* Denormalize and substract */ + exp2 = sub( exp, exp2 ); /* Denormalize and substract */ - tmp3 = sub(tmp2, tmp); - IF (tmp3 > 0) + tmp3 = sub( tmp2, tmp ); + IF( tmp3 > 0 ) { - tmp2 = shr(tmp2, 1); - exp2 = add(exp2, 1); + tmp2 = shr( tmp2, 1 ); + exp2 = add( exp2, 1 ); } - tmp = div_s(tmp2, tmp); + tmp = div_s( tmp2, tmp ); - L_tmp = L_deposit_h(tmp); - L_tmp = Isqrt_lc(L_tmp, &exp2); + L_tmp = L_deposit_h( tmp ); + L_tmp = Isqrt_lc( L_tmp, &exp2 ); #ifdef BASOP_NOGLOB - gain2 = round_fx_sat(L_shl_sat(L_tmp, sub(exp2, 1))); /* in Q14 */ + gain2 = round_fx_sat( L_shl_sat( L_tmp, sub( exp2, 1 ) ) ); /* in Q14 */ #else - gain2 = round_fx(L_shl(L_tmp, sub(exp2, 1))); /* in Q14 */ + gain2 = round_fx( L_shl( L_tmp, sub( exp2, 1 ) ) ); /* in Q14 */ #endif /*-----------------------------------------------------------------* - * Clipping of the smoothing gain at the frame end - *-----------------------------------------------------------------*/ + * Clipping of the smoothing gain at the frame end + *-----------------------------------------------------------------*/ - gain2 = s_min(gain2, 19661); /* Gain modification clipping */ - if (LT_32(L_enr_q, 2)) + gain2 = s_min( gain2, 19661 ); /* Gain modification clipping */ + if ( LT_32( L_enr_q, 2 ) ) { - gain2 = s_min(gain2, 16384); /* Gain modification clipping */ + gain2 = s_min( gain2, 16384 ); /* Gain modification clipping */ } /*-----------------------------------------------------------------* - * Find the energy/gain at the beginning of the frame to ensure smooth transition after erasure(s) - *-----------------------------------------------------------------*/ + * Find the energy/gain at the beginning of the frame to ensure smooth transition after erasure(s) + *-----------------------------------------------------------------*/ test(); test(); @@ -530,15 +531,15 @@ void FEC_scale_syn_fx( test(); test(); test(); - IF( EQ_16(clas,SIN_ONSET)) /* slow increase */ + IF( EQ_16( clas, SIN_ONSET ) ) /* slow increase */ { - gain1 = shr(gain2, 1); + gain1 = shr( gain2, 1 ); } /*------------------------------------------------------------* - * voiced->unvoiced transition recovery - *------------------------------------------------------------*/ - ELSE IF( (GE_16(last_good,VOICED_TRANSITION)&<_16(last_good,INACTIVE_CLAS)&&(EQ_16(clas,UNVOICED_CLAS)||EQ_16(clas,INACTIVE_CLAS)))|| /* voiced->unvoiced transition recovery */ - EQ_32(last_core_brate,SID_1k75) || EQ_32(last_core_brate,SID_2k40) || EQ_32(last_core_brate,FRAME_NO_DATA)) /* CNG -> active signal transition */ + * voiced->unvoiced transition recovery + *------------------------------------------------------------*/ + ELSE IF( ( GE_16( last_good, VOICED_TRANSITION ) && LT_16( last_good, INACTIVE_CLAS ) && ( EQ_16( clas, UNVOICED_CLAS ) || EQ_16( clas, INACTIVE_CLAS ) ) ) || /* voiced->unvoiced transition recovery */ + EQ_32( last_core_brate, SID_1k75 ) || EQ_32( last_core_brate, SID_2k40 ) || EQ_32( last_core_brate, FRAME_NO_DATA ) ) /* CNG -> active signal transition */ { gain1 = gain2; move16(); @@ -546,124 +547,123 @@ void FEC_scale_syn_fx( ELSE { /*--------------------------------------------------------* - * Find the energy at the beginning of the frame - *--------------------------------------------------------*/ - tmp = frame_ener_fx(L_frame,clas, synth, pitch[0], &L_enr1, 0, Q_syn, 3, 0); + * Find the energy at the beginning of the frame + *--------------------------------------------------------*/ + tmp = frame_ener_fx( L_frame, clas, synth, pitch[0], &L_enr1, 0, Q_syn, 3, 0 ); /*gain1 = (float)sqrt( enr_old / enr1 );*/ - exp = norm_l(L_enr_old); - tmp = extract_h(L_shl(L_enr_old, exp)); - exp2 = norm_l(L_enr1); - tmp2 = extract_h(L_shl(L_enr1, exp2)); + exp = norm_l( L_enr_old ); + tmp = extract_h( L_shl( L_enr_old, exp ) ); + exp2 = norm_l( L_enr1 ); + tmp2 = extract_h( L_shl( L_enr1, exp2 ) ); - exp2 = sub(exp, exp2); /* Denormalize and substract */ + exp2 = sub( exp, exp2 ); /* Denormalize and substract */ - tmp3 = sub(tmp2, tmp); + tmp3 = sub( tmp2, tmp ); - IF (tmp3 > 0) + IF( tmp3 > 0 ) { - tmp2 = shr(tmp2, 1); - exp2 = add(exp2, 1); + tmp2 = shr( tmp2, 1 ); + exp2 = add( exp2, 1 ); } - tmp = div_s(tmp2, tmp); + tmp = div_s( tmp2, tmp ); - L_tmp = L_deposit_h(tmp); - L_tmp = Isqrt_lc(L_tmp, &exp2); + L_tmp = L_deposit_h( tmp ); + L_tmp = Isqrt_lc( L_tmp, &exp2 ); #ifdef BASOP_NOGLOB - gain1 = round_fx_sat(L_shl_sat(L_tmp, sub(exp2, 1))); /* in Q14 */ + gain1 = round_fx_sat( L_shl_sat( L_tmp, sub( exp2, 1 ) ) ); /* in Q14 */ #else - gain1 = round_fx(L_shl(L_tmp, sub(exp2, 1))); /* in Q14 */ + gain1 = round_fx( L_shl( L_tmp, sub( exp2, 1 ) ) ); /* in Q14 */ #endif /* exp2 is always <= 1 */ - gain1 = s_min(gain1, 19661); + gain1 = s_min( gain1, 19661 ); test(); test(); - if( avoid_lpc_burst_on_recovery && (GT_16(enr_LP, 160))&&(LE_16(enr_LP,shl_sat(*old_enr_LP,1)))) + if ( avoid_lpc_burst_on_recovery && ( GT_16( enr_LP, 160 ) ) && ( LE_16( enr_LP, shl_sat( *old_enr_LP, 1 ) ) ) ) { - gain1 = s_min(gain1, 16384); + gain1 = s_min( gain1, 16384 ); } /*--------------------------------------------------------* - * Prevent a catastrophy in case of offset followed by onset - *--------------------------------------------------------*/ + * Prevent a catastrophy in case of offset followed by onset + *--------------------------------------------------------*/ test(); - if( ( EQ_16(clas,ONSET))&&(GT_16(gain1,gain2))) + if ( ( EQ_16( clas, ONSET ) ) && ( GT_16( gain1, gain2 ) ) ) { gain1 = gain2; move16(); } } /*-----------------------------------------------------------------* - * Smooth the energy evolution by exponentially evolving from - * gain1 to gain2 - *-----------------------------------------------------------------*/ + * Smooth the energy evolution by exponentially evolving from + * gain1 to gain2 + *-----------------------------------------------------------------*/ - L_tmp = L_mult(gain2, (Word16)(32768 - AGC_FX)); + L_tmp = L_mult( gain2, (Word16) ( 32768 - AGC_FX ) ); - FOR( i=0; iLDm_enh_min_ns_gain = (float) pow( 10.0f, -12 / 20.0f ); #endif #ifdef IVAS_FLOAT_FIXED - hMusicPF->LDm_enh_min_ns_gain_fx = (Word16)(0x2027); + hMusicPF->LDm_enh_min_ns_gain_fx = (Word16) ( 0x2027 ); #endif hMusicPF->LDm_last_music_flag = 0; #ifndef IVAS_FLOAT_FIXED @@ -802,7 +802,7 @@ void music_postfilt_init_flt( #endif } - //set_f( hMusicPF->filt_lfE, 1.0f, DCT_L_POST ); + // set_f( hMusicPF->filt_lfE, 1.0f, DCT_L_POST ); hMusicPF->last_nonfull_music = 0; #ifdef IVAS_FLOAT_FIXED hMusicPF->Old_ener_Q = 0; @@ -810,39 +810,39 @@ void music_postfilt_init_flt( return; } #else - void music_postfilt_init_flt( - MUSIC_POSTFILT_HANDLE hMusicPF /* i/o: LD music postfilter handle */ - ) +void music_postfilt_init_flt( + MUSIC_POSTFILT_HANDLE hMusicPF /* i/o: LD music postfilter handle */ +) +{ + int16_t i; + + set_f( hMusicPF->dct_post_old_exc, 0, DCT_L_POST - OFFSET2 ); + + hMusicPF->LDm_enh_min_ns_gain = (float) pow( 10.0f, -12 / 20.0f ); + hMusicPF->LDm_last_music_flag = 0; + set_f( hMusicPF->LDm_lt_diff_etot, 0, MAX_LT ); + hMusicPF->LDm_thres[0] = TH_0_MIN; + hMusicPF->LDm_thres[1] = TH_1_MIN; + hMusicPF->LDm_thres[2] = TH_2_MIN; + hMusicPF->LDm_thres[3] = TH_3_MIN; + hMusicPF->LDm_nb_thr_1 = 0; + hMusicPF->LDm_nb_thr_3 = 0; + hMusicPF->LDm_mem_etot = 0.0f; + + for ( i = 0; i < VOIC_BINS_HR; i++ ) { - int16_t i; - - set_f(hMusicPF->dct_post_old_exc, 0, DCT_L_POST - OFFSET2); - - hMusicPF->LDm_enh_min_ns_gain = (float)pow(10.0f, -12 / 20.0f); - hMusicPF->LDm_last_music_flag = 0; - set_f(hMusicPF->LDm_lt_diff_etot, 0, MAX_LT); - hMusicPF->LDm_thres[0] = TH_0_MIN; - hMusicPF->LDm_thres[1] = TH_1_MIN; - hMusicPF->LDm_thres[2] = TH_2_MIN; - hMusicPF->LDm_thres[3] = TH_3_MIN; - hMusicPF->LDm_nb_thr_1 = 0; - hMusicPF->LDm_nb_thr_3 = 0; - hMusicPF->LDm_mem_etot = 0.0f; - - for (i = 0; i < VOIC_BINS_HR; i++) - { hMusicPF->LDm_enh_lp_gbin[i] = 1.0f; hMusicPF->LDm_enh_lf_EO[i] = 0.01f; - } + } - for (i = 0; i < MBANDS_GN_LD; i++) - { + for ( i = 0; i < MBANDS_GN_LD; i++ ) + { hMusicPF->LDm_bckr_noise[i] = E_MIN; - } + } - set_f(hMusicPF->filt_lfE, 1.0f, DCT_L_POST); - hMusicPF->last_nonfull_music = 0; + set_f( hMusicPF->filt_lfE, 1.0f, DCT_L_POST ); + hMusicPF->last_nonfull_music = 0; - return; - } -#endif \ No newline at end of file + return; +} +#endif diff --git a/lib_dec/LD_music_post_filter_fx.c b/lib_dec/LD_music_post_filter_fx.c index b723289bd..261b9b4d7 100644 --- a/lib_dec/LD_music_post_filter_fx.c +++ b/lib_dec/LD_music_post_filter_fx.c @@ -3,63 +3,59 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ /*-------------------------------------------------------------------* * Local constants *-------------------------------------------------------------------*/ -#define INV_MAX_SNR_FX 745 /* Q15 {1/(45-1)} Max. SNR considered for noise subtraction in voiced segments */ -#define MAX_SNR_SNR1_FX 16756 /* Q14 45* (1/(max_snr1-1)) */ +#define INV_MAX_SNR_FX 745 /* Q15 {1/(45-1)} Max. SNR considered for noise subtraction in voiced segments */ +#define MAX_SNR_SNR1_FX 16756 /* Q14 45* (1/(max_snr1-1)) */ -#define BIN_1KHZ (Word16)(1000/BIN_16kdct_fx) -#define BIN_2KHZ (Word16)(2000/BIN_16kdct_fx) -#define BIN_4KHZ (Word16)(4000/BIN_16kdct_fx) +#define BIN_1KHZ ( Word16 )( 1000 / BIN_16kdct_fx ) +#define BIN_2KHZ ( Word16 )( 2000 / BIN_16kdct_fx ) +#define BIN_4KHZ ( Word16 )( 4000 / BIN_16kdct_fx ) -#define MAX_GN_R_Q14_FX 3277 -#define ALPH_Q15_FX 32767 -#define BET_Q15_FX 30310 -#define MAXX_Q12_FX (20480) +#define MAX_GN_R_Q14_FX 3277 +#define ALPH_Q15_FX 32767 +#define BET_Q15_FX 30310 +#define MAXX_Q12_FX ( 20480 ) -#define MAXX_FX 5 +#define MAXX_FX 5 /*-------------------------------------------------------------------* * Local function prototypes *-------------------------------------------------------------------*/ -static void analy_sp_dct_fx(const Word16 *dct_buf, Word32 *fr_bands, Word32 *lf_E, Word16 *etot, const Word16 Qdct); -static void find_enr_dct_fx(const Word16 data[], Word32 band[], Word32 *ptE, Word32 *Etot, const Word16 min_band, - const Word16 max_band, const Word16 Q_dct, const Word16 bin_freq ); -static Word16 norm_lfe(const Word32 Lfe,const Word16 m_max,const Word16 e_max); -static void spectrum_mod_dct_fx(const Word16 Qdct,Word16 data[], const Word32 lf_E[], Word32 lf_EO[], - const Word32 noiseE[], const Word16 minGain, - Word16 lp_gbin[], const Word16 music_flag, Word16 min_band, const Word16 MAX_GN, const Word16 MAX_band ); +static void analy_sp_dct_fx( const Word16 *dct_buf, Word32 *fr_bands, Word32 *lf_E, Word16 *etot, const Word16 Qdct ); +static void find_enr_dct_fx( const Word16 data[], Word32 band[], Word32 *ptE, Word32 *Etot, const Word16 min_band, const Word16 max_band, const Word16 Q_dct, const Word16 bin_freq ); +static Word16 norm_lfe( const Word32 Lfe, const Word16 m_max, const Word16 e_max ); +static void spectrum_mod_dct_fx( const Word16 Qdct, Word16 data[], const Word32 lf_E[], Word32 lf_EO[], const Word32 noiseE[], const Word16 minGain, Word16 lp_gbin[], const Word16 music_flag, Word16 min_band, const Word16 MAX_GN, const Word16 MAX_band ); /*------------------------------------------------------------------------* * LD_music_post_filter() * * Music post-filter *------------------------------------------------------------------------*/ -void LD_music_post_filter_fx -( +void LD_music_post_filter_fx( MUSIC_POSTFILT_HANDLE hMusicPF, /* i/o: LD music postfilter handle */ - const Word16 dtc_in[], /* i : input synthesis Qdct */ - Word16 dtc_out[], /* o : output synthesis Qdct */ - const Word32 core_brate, /* i : core bitrate Q0 */ - Word16 *Old_ener_Q, /* i/o : Old energy scaling factor */ - const Word16 coder_type, /* i : Coder type : -1 in case of IO Q0 */ - const Word16 Last_coder_type, /* i : input scaling Q0 */ - const Word16 Qdct /* i : input scaling Q0 */ + const Word16 dtc_in[], /* i : input synthesis Qdct */ + Word16 dtc_out[], /* o : output synthesis Qdct */ + const Word32 core_brate, /* i : core bitrate Q0 */ + Word16 *Old_ener_Q, /* i/o : Old energy scaling factor */ + const Word16 coder_type, /* i : Coder type : -1 in case of IO Q0 */ + const Word16 Last_coder_type, /* i : input scaling Q0 */ + const Word16 Qdct /* i : input scaling Q0 */ ) { Word32 fr_bands[MBANDS_GN_LD]; Word32 lf_E[VOIC_BINS_HR]; Word32 Ltmp, Ltmp_max; - Word16 LG_etot; /*Q8*/ + Word16 LG_etot; /*Q8*/ Word16 i, j, k; Word16 min_band = 0; Word16 local_min_gain; @@ -68,7 +64,7 @@ void LD_music_post_filter_fx Word16 max_ovf_2k, max_ovf_4k, max_ovf_6k; Word16 min_g_2k, min_g_4k, min_g_6k; Word32 m_ave; - Word16 tmp_lfE[DCT_L_POST]; /*Q12*/ + Word16 tmp_lfE[DCT_L_POST]; /*Q12*/ Word16 MAX_GN = MAX_GN_R_Q14_FX; Word16 MAX_band = MBANDS_GN_LD; Word16 mant, exp1, s_ave, tmp16, old_tmp16; @@ -79,86 +75,89 @@ void LD_music_post_filter_fx #endif - local_min_gain = hMusicPF->LDm_enh_min_ns_gain_fx; /*------------------------------------------------------------------------* * Frequency analysis *------------------------------------------------------------------------*/ - analy_sp_dct_fx( dtc_in, fr_bands, lf_E, &LG_etot, Qdct); - diff_sc = shl(sub(Qdct, *Old_ener_Q),1); + analy_sp_dct_fx( dtc_in, fr_bands, lf_E, &LG_etot, Qdct ); + diff_sc = shl( sub( Qdct, *Old_ener_Q ), 1 ); *Old_ener_Q = Qdct; move16(); - Scale_sig32(hMusicPF->LDm_enh_lf_EO_fx, VOIC_BINS_HR, diff_sc); + Scale_sig32( hMusicPF->LDm_enh_lf_EO_fx, VOIC_BINS_HR, diff_sc ); /*------------------------------------------------------------------------* * Find signal classification *------------------------------------------------------------------------*/ - music_flag2 = stab_est_fx( LG_etot, hMusicPF->LDm_lt_diff_etot_fx, &hMusicPF->LDm_mem_etot_fx - , &hMusicPF->LDm_nb_thr_3, &hMusicPF->LDm_nb_thr_1, hMusicPF->LDm_thres_fx, &hMusicPF->LDm_last_music_flag, 1 ); + music_flag2 = stab_est_fx( LG_etot, hMusicPF->LDm_lt_diff_etot_fx, &hMusicPF->LDm_mem_etot_fx, &hMusicPF->LDm_nb_thr_3, &hMusicPF->LDm_nb_thr_1, hMusicPF->LDm_thres_fx, &hMusicPF->LDm_last_music_flag, 1 ); test(); - if ( LT_32(core_brate,ACELP_6k60)||NE_16(Last_coder_type,AUDIO)) + if ( LT_32( core_brate, ACELP_6k60 ) || NE_16( Last_coder_type, AUDIO ) ) { /* do not perform music improvement on SID frames */ music_flag2 = 0; move16(); } - hMusicPF->last_nonfull_music = add(hMusicPF->last_nonfull_music,1); + hMusicPF->last_nonfull_music = add( hMusicPF->last_nonfull_music, 1 ); move16(); - if( LT_16(music_flag2,4)) + if ( LT_16( music_flag2, 4 ) ) { hMusicPF->last_nonfull_music = 0; move16(); } - hMusicPF->last_nonfull_music = s_min( 51, hMusicPF->last_nonfull_music); + hMusicPF->last_nonfull_music = s_min( 51, hMusicPF->last_nonfull_music ); /*------------------------------------------------------------------------* * Remapping of bands * Section to "remap" the minimal band and the minimum gain for our needs *------------------------------------------------------------------------*/ - IF( GT_16(music_flag2,3)) + IF( GT_16( music_flag2, 3 ) ) { min_band = 2; move16(); - local_min_gain = 8231; /*Q15->0.25119f;*/ move16(); + local_min_gain = 8231; /*Q15->0.25119f;*/ + move16(); } - ELSE IF( EQ_16(music_flag2,3)) + ELSE IF( EQ_16( music_flag2, 3 ) ) { min_band = 3; move16(); - local_min_gain = 8231; /*Q15->0.25119f; */ move16(); + local_min_gain = 8231; /*Q15->0.25119f; */ + move16(); } - ELSE IF( EQ_16(music_flag2,2)) + ELSE IF( EQ_16( music_flag2, 2 ) ) { min_band = 4; move16(); - local_min_gain = 11626; /*Q15->0.35481f; */ move16(); + local_min_gain = 11626; /*Q15->0.35481f; */ + move16(); } - ELSE IF( EQ_16(music_flag2,1)) + ELSE IF( EQ_16( music_flag2, 1 ) ) { min_band = 4; move16(); - local_min_gain = 16423; /*Q15->0.50119f;*/ move16(); + local_min_gain = 16423; /*Q15->0.50119f;*/ + move16(); } - min_band = add(min_band, 4); + min_band = add( min_band, 4 ); - MAX_GN = 1638; /*Q14*/ move16(); - if( GT_32(core_brate,ACELP_9k60)) + MAX_GN = 1638; /*Q14*/ + move16(); + if ( GT_32( core_brate, ACELP_9k60 ) ) { /* overshoot not allowed, since GSC already matches the energy */ MAX_GN = 0; move16(); } - if( EQ_16(coder_type,AUDIO)) + if ( EQ_16( coder_type, AUDIO ) ) { /* with GSC we know for sure that we are in music */ min_band = s_min( min_band, 3 ); @@ -172,33 +171,33 @@ void LD_music_post_filter_fx j = 0; move16(); - Ltmp_max = L_deposit_l(0); - FOR (i = 0; i < MBANDS_GN_LD; i++) + Ltmp_max = L_deposit_l( 0 ); + FOR( i = 0; i < MBANDS_GN_LD; i++ ) { - Ltmp = L_deposit_l(0); - max_val = L_deposit_l(0); + Ltmp = L_deposit_l( 0 ); + max_val = L_deposit_l( 0 ); - FOR( k=j; k < mfreq_bindiv_LD[i]+j; k++ ) + FOR( k = j; k < mfreq_bindiv_LD[i] + j; k++ ) { /*m_ave += lf_E[k];*/ #ifdef BASOP_NOGLOB - Ltmp = L_add_o(lf_E[k], Ltmp, &Overflow); + Ltmp = L_add_o( lf_E[k], Ltmp, &Overflow ); #else - Ltmp = L_add(lf_E[k], Ltmp); + Ltmp = L_add( lf_E[k], Ltmp ); #endif - max_val = L_max(max_val, lf_E[k]); + max_val = L_max( max_val, lf_E[k] ); } - Ltmp_max = L_max(Ltmp_max, max_val); + Ltmp_max = L_max( Ltmp_max, max_val ); /*m_ave -= max_val;*/ - Ltmp = L_sub(Ltmp, max_val); + Ltmp = L_sub( Ltmp, max_val ); /*m_ave /=(mfreq_bindiv_LD[i]-1);*/ - m_ave = Mult_32_16(Ltmp,inv_mfreq_bindiv_LD_M1_fx[i]); + m_ave = Mult_32_16( Ltmp, inv_mfreq_bindiv_LD_M1_fx[i] ); /*bckr[i] = m_ave*sc_qnoise[i];*/ - hMusicPF->LDm_bckr_noise_fx[i] = Mult_32_16(m_ave,sc_qnoise_fx[i]); + hMusicPF->LDm_bckr_noise_fx[i] = Mult_32_16( m_ave, sc_qnoise_fx[i] ); move32(); - j+=mfreq_bindiv_LD[i]; + j += mfreq_bindiv_LD[i]; } /* This is computed inside the loop i = maximum(lf_E, DCT_L_POST, &m_ave);*/ @@ -208,51 +207,51 @@ void LD_music_post_filter_fx * - LT averaging with the past and in function of the stability factor *------------------------------------------------------------------------*/ /*m_ave = ALPH/lf_E[i];*/ - exp1 = norm_l(Ltmp_max); - mant = extract_h(L_shl(Ltmp_max, exp1)); + exp1 = norm_l( Ltmp_max ); + mant = extract_h( L_shl( Ltmp_max, exp1 ) ); /*exp1 = sub(16,exp1);*/ - s_ave = div_s(16384, mant); - exp1 = sub(14/*+15*/+16, exp1); /*s_ave in Q15 + exp1*/ - old_tmp16 = norm_lfe(lf_E[0], s_ave, exp1); - old_tmp16 = s_min(old_tmp16, MAXX_Q12_FX); - tmp16 = norm_lfe(lf_E[1], s_ave, exp1); - tmp16 = s_min(tmp16, MAXX_Q12_FX); + s_ave = div_s( 16384, mant ); + exp1 = sub( 14 /*+15*/ + 16, exp1 ); /*s_ave in Q15 + exp1*/ + old_tmp16 = norm_lfe( lf_E[0], s_ave, exp1 ); + old_tmp16 = s_min( old_tmp16, MAXX_Q12_FX ); + tmp16 = norm_lfe( lf_E[1], s_ave, exp1 ); + tmp16 = s_min( tmp16, MAXX_Q12_FX ); old_tmp16_1 = tmp16; move16(); - tmp_lfE[0] = round_fx(L_mac(L_mult(16384, old_tmp16), 16384, tmp16)); + tmp_lfE[0] = round_fx( L_mac( L_mult( 16384, old_tmp16 ), 16384, tmp16 ) ); - FOR(i = 1; i < DCT_L_POST-1; i++) + FOR( i = 1; i < DCT_L_POST - 1; i++ ) { /*tmp_lfE[i] = 0.333f*old_ftmp + 0.333f*ftmp; */ - Ltmp = L_mac(L_mult(10813, old_tmp16), 10813, old_tmp16_1); + Ltmp = L_mac( L_mult( 10813, old_tmp16 ), 10813, old_tmp16_1 ); old_tmp16 = old_tmp16_1; move16(); - tmp16 = norm_lfe(lf_E[i+1], s_ave, exp1); + tmp16 = norm_lfe( lf_E[i + 1], s_ave, exp1 ); /*ftmp = min(ftmp, MAXX); tmp_lfE[i] += 0.333f*ftmp; */ - old_tmp16_1 = s_min(tmp16, MAXX_Q12_FX); - Ltmp = L_mac(Ltmp, 10813, old_tmp16_1); - tmp_lfE[i] = round_fx(Ltmp); + old_tmp16_1 = s_min( tmp16, MAXX_Q12_FX ); + Ltmp = L_mac( Ltmp, 10813, old_tmp16_1 ); + tmp_lfE[i] = round_fx( Ltmp ); } - tmp16 = norm_lfe(lf_E[i], s_ave, exp1); + tmp16 = norm_lfe( lf_E[i], s_ave, exp1 ); /*ftmp = min(ftmp, MAXX); tmp_lfE[i] = 0.5f*old_ftmp + 0.5f*ftmp;*/ - tmp16 = s_min(tmp16, MAXX_Q12_FX); - tmp_lfE[i] = round_fx(L_mac(L_mult(16384, old_tmp16), 16384, tmp16)); + tmp16 = s_min( tmp16, MAXX_Q12_FX ); + tmp_lfE[i] = round_fx( L_mac( L_mult( 16384, old_tmp16 ), 16384, tmp16 ) ); - FOR(i = 0; i < BIN_4KHZ; i++) + FOR( i = 0; i < BIN_4KHZ; i++ ) { /*filt_lfE[i] = tmp_lfE[i]*.05f + .95f*filt_lfE[i] ;*/ - hMusicPF->filt_lfE_fx[i] = round_fx(L_mac(L_mult(tmp_lfE[i],1638), 31130, hMusicPF->filt_lfE_fx[i])) ; + hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( L_mult( tmp_lfE[i], 1638 ), 31130, hMusicPF->filt_lfE_fx[i] ) ); } - FOR(; i < DCT_L_POST; i++) + FOR( ; i < DCT_L_POST; i++ ) { /*filt_lfE[i] = tmp_lfE[i]*(.15f) + .85f*filt_lfE[i] ;*/ - hMusicPF->filt_lfE_fx[i] = round_fx(L_mac(L_mult(tmp_lfE[i],4915), 27853, hMusicPF->filt_lfE_fx[i])) ; + hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( L_mult( tmp_lfE[i], 4915 ), 27853, hMusicPF->filt_lfE_fx[i] ) ); } /*------------------------------------------------------------------------* * - Reduce inter-harmonic noise with SNR based method @@ -260,32 +259,35 @@ void LD_music_post_filter_fx * on the pow(x,4) energy spectrum *------------------------------------------------------------------------*/ - if( EQ_16(coder_type,AUDIO)) + if ( EQ_16( coder_type, AUDIO ) ) { MAX_band = 16; move16(); } - Copy(dtc_in, dtc_out, DCT_L_POST); + Copy( dtc_in, dtc_out, DCT_L_POST ); spectrum_mod_dct_fx( Qdct, dtc_out, lf_E, hMusicPF->LDm_enh_lf_EO_fx, hMusicPF->LDm_bckr_noise_fx, local_min_gain, hMusicPF->LDm_enh_lp_gbin_fx, music_flag2, min_band, MAX_GN, MAX_band ); i = 0; move16(); - IF( GE_16(music_flag2,1)) + IF( GE_16( music_flag2, 1 ) ) { - FOR(i = 0; i < BIN_1KHZ; i++) + FOR( i = 0; i < BIN_1KHZ; i++ ) { - tmp16 = s_min(4096, hMusicPF->filt_lfE_fx[i]); - dtc_out[i] = round_fx(L_shl(L_mult(dtc_out[i], tmp16),3)); + tmp16 = s_min( 4096, hMusicPF->filt_lfE_fx[i] ); + dtc_out[i] = round_fx( L_shl( L_mult( dtc_out[i], tmp16 ), 3 ) ); } } { - IF( GT_16(hMusicPF->last_nonfull_music,40)) + IF( GT_16( hMusicPF->last_nonfull_music, 40 ) ) { - max_ovf_2k = 5120; /*1.25 Q12*/ move16(); - max_ovf_4k = 6144; /*1.5 Q12*/ move16(); - max_ovf_6k = 6144; /*1.5 Q12*/ move16(); + max_ovf_2k = 5120; /*1.25 Q12*/ + move16(); + max_ovf_4k = 6144; /*1.5 Q12*/ + move16(); + max_ovf_6k = 6144; /*1.5 Q12*/ + move16(); min_g_2k = 0; move16(); @@ -294,94 +296,112 @@ void LD_music_post_filter_fx min_g_6k = 0; move16(); - IF( EQ_16(coder_type,AUDIO )) + IF( EQ_16( coder_type, AUDIO ) ) { - max_ovf_2k = 4096; /*1.0 Q12*/ move16(); - max_ovf_4k = 4506; /*1.1 Q12*/ move16(); - max_ovf_6k = 5120; /*1.25 Q12*/ move16(); + max_ovf_2k = 4096; /*1.0 Q12*/ + move16(); + max_ovf_4k = 4506; /*1.1 Q12*/ + move16(); + max_ovf_6k = 5120; /*1.25 Q12*/ + move16(); - min_g_2k = 3072; /*0.75 Q12*/ move16(); - min_g_4k = 2048; /*0.5 Q12*/ move16(); - min_g_6k = 2048; /*0.5 Q12*/ move16(); + min_g_2k = 3072; /*0.75 Q12*/ + move16(); + min_g_4k = 2048; /*0.5 Q12*/ + move16(); + min_g_6k = 2048; /*0.5 Q12*/ + move16(); - IF( GT_32(core_brate,ACELP_9k60)) + IF( GT_32( core_brate, ACELP_9k60 ) ) { - max_ovf_4k = 4096; /*1.0 Q12*/ move16(); - max_ovf_6k = 4710; /*1.15 Q12*/ move16(); - - min_g_2k = 3789; /*0.925 Q12*/ move16(); - min_g_4k = 3379; /*0.825 Q12*/ move16(); - min_g_6k = 3072; /*0.75 Q12*/ move16(); + max_ovf_4k = 4096; /*1.0 Q12*/ + move16(); + max_ovf_6k = 4710; /*1.15 Q12*/ + move16(); + + min_g_2k = 3789; /*0.925 Q12*/ + move16(); + min_g_4k = 3379; /*0.825 Q12*/ + move16(); + min_g_6k = 3072; /*0.75 Q12*/ + move16(); } } - ELSE IF( GE_32(core_brate,ACELP_12k65)) + ELSE IF( GE_32( core_brate, ACELP_12k65 ) ) { - max_ovf_2k = 4096; /*1.0 Q12*/ move16(); - max_ovf_4k = 5120; /*1.25 Q12*/ move16(); + max_ovf_2k = 4096; /*1.0 Q12*/ + move16(); + max_ovf_4k = 5120; /*1.25 Q12*/ + move16(); - IF( GT_32(core_brate,ACELP_15k85)) + IF( GT_32( core_brate, ACELP_15k85 ) ) { - max_ovf_4k = 4096; /*1.0 Q12*/ move16(); - max_ovf_6k = 5120; /*1.25 Q12*/ move16(); - - min_g_2k = 3072; /*0.75 Q12*/ move16(); - min_g_4k = 2048; /*0.5 Q12*/ move16(); - min_g_6k = 2048; /*0.5 Q12*/ move16(); + max_ovf_4k = 4096; /*1.0 Q12*/ + move16(); + max_ovf_6k = 5120; /*1.25 Q12*/ + move16(); + + min_g_2k = 3072; /*0.75 Q12*/ + move16(); + min_g_4k = 2048; /*0.5 Q12*/ + move16(); + min_g_6k = 2048; /*0.5 Q12*/ + move16(); } } - FOR(; i < BIN_2KHZ; i++) + FOR( ; i < BIN_2KHZ; i++ ) { - tmp16 = s_min(max_ovf_2k, hMusicPF->filt_lfE_fx[i]); - tmp16 = s_max(min_g_2k, tmp16); + tmp16 = s_min( max_ovf_2k, hMusicPF->filt_lfE_fx[i] ); + tmp16 = s_max( min_g_2k, tmp16 ); /*DCT_buf[i] *= ftmp;*/ #ifdef BASOP_NOGLOB dtc_out[i] = round_fx_sat( L_shl_sat( L_mult( dtc_out[i], tmp16 ), 3 ) ); #else - dtc_out[i] = round_fx(L_shl(L_mult(dtc_out[i], tmp16),3)); + dtc_out[i] = round_fx( L_shl( L_mult( dtc_out[i], tmp16 ), 3 ) ); #endif } - FOR(; i < BIN_4KHZ; i++) + FOR( ; i < BIN_4KHZ; i++ ) { - tmp16 = s_min(max_ovf_4k, hMusicPF->filt_lfE_fx[i]); - tmp16 = s_max(min_g_4k, tmp16); + tmp16 = s_min( max_ovf_4k, hMusicPF->filt_lfE_fx[i] ); + tmp16 = s_max( min_g_4k, tmp16 ); /*DCT_buf[i] *= ftmp;*/ #ifdef BASOP_NOGLOB dtc_out[i] = round_fx_sat( L_shl_sat( L_mult_sat( dtc_out[i], tmp16 ), 3 ) ); #else - dtc_out[i] = round_fx(L_shl(L_mult(dtc_out[i], tmp16),3)); + dtc_out[i] = round_fx( L_shl( L_mult( dtc_out[i], tmp16 ), 3 ) ); #endif } test(); - IF( NE_16(coder_type,AUDIO)||GT_32(core_brate,ACELP_8k85)) + IF( NE_16( coder_type, AUDIO ) || GT_32( core_brate, ACELP_8k85 ) ) { /* Do not modify HF when coded with GSC at LR, because the spectrum is just noise */ - FOR(; i < DCT_L_POST; i++) + FOR( ; i < DCT_L_POST; i++ ) { - tmp16 = s_min(max_ovf_6k, hMusicPF->filt_lfE_fx[i]); - tmp16 = s_max(min_g_6k, tmp16); + tmp16 = s_min( max_ovf_6k, hMusicPF->filt_lfE_fx[i] ); + tmp16 = s_max( min_g_6k, tmp16 ); /*DCT_buf[i] *= ftmp;*/ #ifdef BASOP_NOGLOB dtc_out[i] = round_fx_sat( L_shl_sat( L_mult_sat( dtc_out[i], tmp16 ), 3 ) ); #else - dtc_out[i] = round_fx(L_shl(L_mult(dtc_out[i], tmp16),3)); + dtc_out[i] = round_fx( L_shl( L_mult( dtc_out[i], tmp16 ), 3 ) ); #endif } } } - ELSE IF( GT_16(hMusicPF->last_nonfull_music,25)) + ELSE IF( GT_16( hMusicPF->last_nonfull_music, 25 ) ) { /* When unsure on content type only slight clean-up allowed, no overshoot allowed */ - FOR(; i < DCT_L_POST; i++) + FOR( ; i < DCT_L_POST; i++ ) { - tmp16 = s_min(4096, hMusicPF->filt_lfE_fx[i]); + tmp16 = s_min( 4096, hMusicPF->filt_lfE_fx[i] ); /*DCT_buf[i] *= ftmp;*/ #ifdef BASOP_NOGLOB dtc_out[i] = round_fx_sat( L_shl_sat( L_mult_sat( dtc_out[i], tmp16 ), 3 ) ); #else - dtc_out[i] = round_fx(L_shl(L_mult(dtc_out[i], tmp16),3)); + dtc_out[i] = round_fx( L_shl( L_mult( dtc_out[i], tmp16 ), 3 ) ); #endif } } @@ -395,23 +415,23 @@ void LD_music_post_filter_fx *---------------------------------------------------------------------------*/ static void spectrum_mod_dct_fx( - const Word16 Qdct, /* i : scaling factor Q0 */ - Word16 data[], /* i/o: dct spectrum */ - const Word32 lf_E[], /* i: per bin E for first 46 bins (without DC) 2*Qdct+10 */ - Word32 lf_EO[], /* i/o: old per bin E for previous half frame 2*Qdct+10 */ - const Word32 noiseE[], /* i: per band background noise energy estimate 2*Qdct+10 */ - const Word16 minGain, /* i: minimum suppression gain Q15 */ - Word16 lp_gbin[], /* i/o: Smoothed suppression gain, per FFT bin Q14*/ - const Word16 music_flag, /* i: music ? 1:0 */ - Word16 min_band, /* i : minimum band */ - const Word16 MAX_GN, /* i : Maximum gain overshoot */ - const Word16 MAX_band /* i : minimum band */ + const Word16 Qdct, /* i : scaling factor Q0 */ + Word16 data[], /* i/o: dct spectrum */ + const Word32 lf_E[], /* i: per bin E for first 46 bins (without DC) 2*Qdct+10 */ + Word32 lf_EO[], /* i/o: old per bin E for previous half frame 2*Qdct+10 */ + const Word32 noiseE[], /* i: per band background noise energy estimate 2*Qdct+10 */ + const Word16 minGain, /* i: minimum suppression gain Q15 */ + Word16 lp_gbin[], /* i/o: Smoothed suppression gain, per FFT bin Q14*/ + const Word16 music_flag, /* i: music ? 1:0 */ + Word16 min_band, /* i : minimum band */ + const Word16 MAX_GN, /* i : Maximum gain overshoot */ + const Word16 MAX_band /* i : minimum band */ ) { Word32 maxNoise; Word32 binE[VOIC_BINS_HR], Lgain; Word16 gain = 0, minE; - Word16 freq, slope, m_invno[MBANDS_GN_LD],e_invno[MBANDS_GN_LD]; + Word16 freq, slope, m_invno[MBANDS_GN_LD], e_invno[MBANDS_GN_LD]; Word16 *pt_gbin, alpha, tmpN; Word16 i; Word32 Ltmp; @@ -438,36 +458,36 @@ static void spectrum_mod_dct_fx( * Compute the inverse of noise *-----------------------------------------------------------------*/ - scaling = add(shl(Qdct,1),10); - IF(LE_16(scaling, 31)) + scaling = add( shl( Qdct, 1 ), 10 ); + IF( LE_16( scaling, 31 ) ) { - /* Calculate .5 in Qscaling only if scaling <= 31 */ - dot5_scaled = L_shl(1, sub(scaling,1)); + /* Calculate .5 in Qscaling only if scaling <= 31 */ + dot5_scaled = L_shl( 1, sub( scaling, 1 ) ); } ELSE { - /* This is only for avaoiding build warning */ - dot5_scaled = MAX_32; - move32(); + /* This is only for avaoiding build warning */ + dot5_scaled = MAX_32; + move32(); } - FOR ( i=0; i<=MBANDS_GN_LD-1; i++) + FOR( i = 0; i <= MBANDS_GN_LD - 1; i++ ) { /*inv_noise[i] = 1.0f / noiseE[i];*/ - IF (noiseE[i] != 0) + IF( noiseE[i] != 0 ) { - e_invno[i] = norm_l(noiseE[i]); + e_invno[i] = norm_l( noiseE[i] ); move16(); - m_invno[i] = extract_h(L_shl(noiseE[i],e_invno[i])); - e_invno[i] = sub(14, e_invno[i]); + m_invno[i] = extract_h( L_shl( noiseE[i], e_invno[i] ) ); + e_invno[i] = sub( 14, e_invno[i] ); move16(); - m_invno[i] = div_s(16384, m_invno[i]); + m_invno[i] = div_s( 16384, m_invno[i] ); move16(); } ELSE { /* noiseE[i] == 0 only if Q_new <0*/ - e_invno[i] = add(-16,Qdct); + e_invno[i] = add( -16, Qdct ); move16(); m_invno[i] = MAX_16; move16(); @@ -476,11 +496,11 @@ static void spectrum_mod_dct_fx( /*----------------------------------------------------------------------* * Perform noise reduction for 1 frames *----------------------------------------------------------------------*/ - FOR (i=0 ; i < VOIC_BINS_HR ; i++) + FOR( i = 0; i < VOIC_BINS_HR; i++ ) { /*binE[i] = (float)(0.3 * lf_EO[i] + 0.7 * lf_E[i]);*/ - Ltmp = Mult_32_16(lf_EO[i], 9830); - binE[i] = Madd_32_16(Ltmp, lf_E[i], 22938); + Ltmp = Mult_32_16( lf_EO[i], 9830 ); + binE[i] = Madd_32_16( Ltmp, lf_E[i], 22938 ); move32(); } Copy32( lf_E, lf_EO, VOIC_BINS_HR ); /* update */ @@ -488,10 +508,10 @@ static void spectrum_mod_dct_fx( * Find the maximum noise in a critical band *----------------------------------------------------------------------*/ - maxNoise = L_max(noiseE[0], noiseE[1]); - FOR (i=2; i<=MBANDS_GN_LD-1; i++) + maxNoise = L_max( noiseE[0], noiseE[1] ); + FOR( i = 2; i <= MBANDS_GN_LD - 1; i++ ) { - maxNoise = L_max(maxNoise, noiseE[i]); + maxNoise = L_max( maxNoise, noiseE[i] ); } /* pointer initialization */ @@ -502,19 +522,20 @@ static void spectrum_mod_dct_fx( * (exclude Clean speech) *-----------------------------------------------------------------*/ - IF ( music_flag != 0 ) /* prevent subtraction on clean speech */ + IF( music_flag != 0 ) /* prevent subtraction on clean speech */ { #ifdef BASOP_NOGLOB - IF(LE_32(maxNoise, L_shl_o(10, scaling, &Overflow))) + IF( LE_32( maxNoise, L_shl_o( 10, scaling, &Overflow ) ) ) #else - IF( LE_32(maxNoise, L_shl(10, scaling))) + IF( LE_32( maxNoise, L_shl( 10, scaling ) ) ) #endif { - minE = 18432/2; /*Q14*/ move16(); + minE = 18432 / 2; /*Q14*/ + move16(); } ELSE { - minE = shr(mult_r(minGain, minGain),1); /*Q14*/ + minE = shr( mult_r( minGain, minGain ), 1 ); /*Q14*/ } Lpt2 = binE; @@ -522,10 +543,10 @@ static void spectrum_mod_dct_fx( move16(); pt_gbin = lp_gbin; - FOR (i=0; i < min_band; i++) + FOR( i = 0; i < min_band; i++ ) { - FOR (; freq <= mfreq_loc_LD_fx[i]; freq += BIN_16kdct_fx) + FOR( ; freq <= mfreq_loc_LD_fx[i]; freq += BIN_16kdct_fx ) { Lpt2++; /* Lgain is already saturate if it's > 1*/ @@ -542,7 +563,7 @@ static void spectrum_mod_dct_fx( * first 17 critical bands) *-----------------------------------------------------------------*/ - FOR (; i < MAX_band; i++) + FOR( ; i < MAX_band; i++ ) { /*tmp = INV_MAX_SNR_tab[i]; @@ -553,78 +574,77 @@ static void spectrum_mod_dct_fx( tmp_snr = INV_MAX_SNR_tab_FX[i]; move16(); /*slope = -tmp * minE + tmp;*/ - Ltmp = L_mult(tmp_snr, 16384); - slope = msu_r(Ltmp,tmp_snr, minE); /*Q14*/ + Ltmp = L_mult( tmp_snr, 16384 ); + slope = msu_r( Ltmp, tmp_snr, minE ); /*Q14*/ /*shift = MAX_SNR1 * tmp * minE - tmp;*/ - Ltmp = L_mult(MAX_SNR_SNR1_tab_FX[i], minE); /*Q14*Q14*/ - Lshift = L_msu(Ltmp, tmp_snr,8192); /*Q15*Q13+Q29*/ - Lshift = L_shl(Lshift,1); /*Q29 -> Q30*/ + Ltmp = L_mult( MAX_SNR_SNR1_tab_FX[i], minE ); /*Q14*Q14*/ + Lshift = L_msu( Ltmp, tmp_snr, 8192 ); /*Q15*Q13+Q29*/ + Lshift = L_shl( Lshift, 1 ); /*Q29 -> Q30*/ /*tmpN = slope * inv_noise[i];*/ - tmpN = mult(slope, m_invno[i]); + tmpN = mult( slope, m_invno[i] ); e_tmp = e_invno[i]; move16(); /*while (freq <= mfreq_loc_LD[i])*/ - FOR (; freq <= mfreq_loc_LD_fx[i]; freq += BIN_16kdct_fx) + FOR( ; freq <= mfreq_loc_LD_fx[i]; freq += BIN_16kdct_fx ) { /*gain = 1.0f;*/ - Lgain = L_deposit_h(16384); + Lgain = L_deposit_h( 16384 ); /*if (noiseE[i] >= 0.5f)*/ test(); - IF (LT_16(scaling, 32) && GT_32(noiseE[i], dot5_scaled))/* Do not alter if noise E very low */ + IF( LT_16( scaling, 32 ) && GT_32( noiseE[i], dot5_scaled ) ) /* Do not alter if noise E very low */ { /*gain = tmpN * *pt2 + shift;*/ /* limits: [x,y] = {[1, minE], [MAX_SNR1, 1]}, */ - e_binE = norm_l(*Lpt2); - m_binE = extract_h(L_shl(*Lpt2, e_binE)); + e_binE = norm_l( *Lpt2 ); + m_binE = extract_h( L_shl( *Lpt2, e_binE ) ); - e_binE = sub(e_binE,0); /* lf_e divided by 4 in anal_sp*/ + e_binE = sub( e_binE, 0 ); /* lf_e divided by 4 in anal_sp*/ - Ltmp = L_mult(tmpN, m_binE); - e_binE = sub(add(e_tmp, e_binE),15); + Ltmp = L_mult( tmpN, m_binE ); + e_binE = sub( add( e_tmp, e_binE ), 15 ); #ifdef BASOP_NOGLOB - Ltmp = L_shr_o(Ltmp, e_binE, &Overflow); - Lgain = L_add_o(Ltmp, Lshift, &Overflow); /*Saturation can occure here result in Q30*/ + Ltmp = L_shr_o( Ltmp, e_binE, &Overflow ); + Lgain = L_add_o( Ltmp, Lshift, &Overflow ); /*Saturation can occure here result in Q30*/ #else - Ltmp = L_shr(Ltmp, e_binE); - Lgain = L_add(Ltmp, Lshift); /*Saturation can occure here result in Q30*/ + Ltmp = L_shr( Ltmp, e_binE ); + Lgain = L_add( Ltmp, Lshift ); /*Saturation can occure here result in Q30*/ #endif - } Lpt2++; #ifdef BASOP_NOGLOB - gain = round_fx_o(Lgain, &Overflow); /*gain in Q30-16 = Q14*/ + gain = round_fx_o( Lgain, &Overflow ); /*gain in Q30-16 = Q14*/ #else - gain = round_fx(Lgain); /*gain in Q30-16 = Q14*/ + gain = round_fx( Lgain ); /*gain in Q30-16 = Q14*/ #endif /*if (gain < minE)gain = minE;*/ - gain = s_max(gain,minE); + gain = s_max( gain, minE ); /*if (gain > 1.0f+MAX_GN)gain = 1.0f+MAX_GN;*/ - gain = s_min(gain,add(16384, MAX_GN)); + gain = s_min( gain, add( 16384, MAX_GN ) ); /* prepare gain to find sqrt */ - e_gain = norm_s(gain); - Ltmp = L_shl(gain, add(16,e_gain)); - e_gain = negate(sub(e_gain,1)); + e_gain = norm_s( gain ); + Ltmp = L_shl( gain, add( 16, e_gain ) ); + e_gain = negate( sub( e_gain, 1 ) ); - Ltmp = Isqrt_lc(Ltmp, &e_gain); - wtmp = extract_h(Ltmp); - sqrt_gain = div_s(16384,wtmp); + Ltmp = Isqrt_lc( Ltmp, &e_gain ); + wtmp = extract_h( Ltmp ); + sqrt_gain = div_s( 16384, wtmp ); /* the gain smoothing control: stronger lp filtering for lower gains */ /*alpha = 1.0f - (float)sqrt(gain);*/ /* keep gain in Q14*/ - sqrt_gain = shr(sqrt_gain, e_gain); + sqrt_gain = shr( sqrt_gain, e_gain ); /*alpha = 1.0f - gain;*/ /* the gain smoothing control: stronger LP filtering for lower gains */ - alpha = shl(sub(16384, sqrt_gain),1); + alpha = shl( sub( 16384, sqrt_gain ), 1 ); /**pt_gbin = gain + alpha * *pt_gbin;*/ - Ltmp = L_mult(gain, 32767); - *pt_gbin = round_fx(L_mac(Ltmp, alpha, *pt_gbin)); /*Q14*/ - /**pt++ *= *pt_gbin;*/ + Ltmp = L_mult( gain, 32767 ); + *pt_gbin = round_fx( L_mac( Ltmp, alpha, *pt_gbin ) ); /*Q14*/ + /**pt++ *= *pt_gbin;*/ #ifdef BASOP_NOGLOB *pt = round_fx_sat( L_shl_sat( L_mult( *pt, *pt_gbin ), 1 ) ); #else @@ -641,19 +661,18 @@ static void spectrum_mod_dct_fx( move16(); pt_gbin = lp_gbin; move16(); - FOR (i=0; i < MBANDS_GN_LD; i++) + FOR( i = 0; i < MBANDS_GN_LD; i++ ) { - FOR (; freq <= mfreq_loc_LD[i]; freq += BIN_16kdct_fx) + FOR( ; freq <= mfreq_loc_LD[i]; freq += BIN_16kdct_fx ) { /**pt_gbin = 0.9f* *pt_gbin + 0.1f;*/ - *pt_gbin = round_fx(L_mac(L_mult(29491, *pt_gbin), 32767, 1638)); + *pt_gbin = round_fx( L_mac( L_mult( 29491, *pt_gbin ), 32767, 1638 ) ); pt_gbin++; } } } return; - } @@ -665,30 +684,30 @@ static void spectrum_mod_dct_fx( static void analy_sp_dct_fx( const Word16 *dct_buf, /* i input dct spectrum */ - Word32 *fr_bands, /* o: energy in critical frequency bands 2*Qdct+10 */ - Word32 *lf_E, /* o: per bin E for first... 2*Qdct+10 */ - Word16 *etot, /* o: total input energy Q8 */ - const Word16 Qdct /* i: Scaling of dct */ + Word32 *fr_bands, /* o: energy in critical frequency bands 2*Qdct+10 */ + Word32 *lf_E, /* o: per bin E for first... 2*Qdct+10 */ + Word16 *etot, /* o: total input energy Q8 */ + const Word16 Qdct /* i: Scaling of dct */ ) { Word32 Letot = 0; Word16 exp_etot, frac_etot; - Letot = L_deposit_l(0); + Letot = L_deposit_l( 0 ); /*-----------------------------------------------------------------* * find energy per critical frequency band and total energy in dB *-----------------------------------------------------------------*/ - find_enr_dct_fx(dct_buf, fr_bands, lf_E, &Letot, 0, MBANDS_GN_LD, Qdct, BIN_16kdct_fx ); + find_enr_dct_fx( dct_buf, fr_bands, lf_E, &Letot, 0, MBANDS_GN_LD, Qdct, BIN_16kdct_fx ); /* find average log total energy over both half-frames */ /**etot = 10.0f * (float)log10(*etot) - 3.0103f;*/ - exp_etot = norm_l(Letot); - frac_etot = Log2_norm_lc(L_shl(Letot, exp_etot)); - exp_etot = sub(30, exp_etot); - exp_etot = sub(exp_etot, add(shl(Qdct,1),10+1)); /* +(1) */ - Letot = Mpy_32_16(exp_etot, frac_etot, LG10); + exp_etot = norm_l( Letot ); + frac_etot = Log2_norm_lc( L_shl( Letot, exp_etot ) ); + exp_etot = sub( 30, exp_etot ); + exp_etot = sub( exp_etot, add( shl( Qdct, 1 ), 10 + 1 ) ); /* +(1) */ + Letot = Mpy_32_16( exp_etot, frac_etot, LG10 ); /* Q8 Averaged the total energy over both half-frames in log10 */ - *etot = extract_l(L_shr(Letot, 14-8)); + *etot = extract_l( L_shr( Letot, 14 - 8 ) ); return; } @@ -701,14 +720,14 @@ static void analy_sp_dct_fx( *------------------------------------------------------------------------*/ static void find_enr_dct_fx( - const Word16 data[], /* i : dct result, for the format Qdct*/ - Word32 band[], /* o : per band energy 2*Qdct+10*/ - Word32 *ptE, /* o : per bin energy for low frequencies 2*Qdct+10*/ - Word32 *Etot, /* o : total energy 2*Qdct+10*/ - const Word16 min_band, /* i : minimum critical band Q0 */ - const Word16 max_band, /* i : maximum critical band Q0 */ - const Word16 Q_dct, /* i : scaling factor Q0 */ - const Word16 bin_freq /* i : Number of frequency bins Q0 */ + const Word16 data[], /* i : dct result, for the format Qdct*/ + Word32 band[], /* o : per band energy 2*Qdct+10*/ + Word32 *ptE, /* o : per bin energy for low frequencies 2*Qdct+10*/ + Word32 *Etot, /* o : total energy 2*Qdct+10*/ + const Word16 min_band, /* i : minimum critical band Q0 */ + const Word16 max_band, /* i : maximum critical band Q0 */ + const Word16 Q_dct, /* i : scaling factor Q0 */ + const Word16 bin_freq /* i : Number of frequency bins Q0 */ ) { Word16 i; @@ -717,37 +736,37 @@ static void find_enr_dct_fx( Word32 LE_min, Ltmp, Ltmp1; - LE_min = L_max(L_shl(E_MIN_Q15, sub(shl(Q_dct,1)+10,22)),1); + LE_min = L_max( L_shl( E_MIN_Q15, sub( shl( Q_dct, 1 ) + 10, 22 ) ), 1 ); - ptR = &data[0]; /* pointer to first real coefficient */ + ptR = &data[0]; /* pointer to first real coefficient */ freq = 0; move16(); - FOR( i=0; i < max_band; i++ ) + FOR( i = 0; i < max_band; i++ ) { band[i] = 0; move16(); - Ltmp1 = L_deposit_l(0); - FOR(; freq <= mfreq_loc_LD_fx[i]; freq += bin_freq) + Ltmp1 = L_deposit_l( 0 ); + FOR( ; freq <= mfreq_loc_LD_fx[i]; freq += bin_freq ) { /* energy */ /**ptE = *ptR * *ptR; */ #ifdef BASOP_NOGLOB - Ltmp = L_mult_sat(*ptR, *ptR); + Ltmp = L_mult_sat( *ptR, *ptR ); #else - Ltmp = L_mult(*ptR, *ptR); + Ltmp = L_mult( *ptR, *ptR ); #endif /* normalization */ /**ptE *= 1.0f / (DCT_L_POST);*/ - Ltmp = Mult_32_16(Ltmp, 26214); /*26214 = 1.0/640 ->Q15+9 --> 2*Q_dct + 9*/ - Ltmp = L_max(Ltmp, LE_min); + Ltmp = Mult_32_16( Ltmp, 26214 ); /*26214 = 1.0/640 ->Q15+9 --> 2*Q_dct + 9*/ + Ltmp = L_max( Ltmp, LE_min ); *ptE = Ltmp; move32(); /*band[i] += *ptE++;*/ #ifdef BASOP_NOGLOB - Ltmp1 = L_add_sat(Ltmp, Ltmp1); + Ltmp1 = L_add_sat( Ltmp, Ltmp1 ); #else - Ltmp1 = L_add(Ltmp, Ltmp1); + Ltmp1 = L_add( Ltmp, Ltmp1 ); #endif ptE++; @@ -756,14 +775,13 @@ static void find_enr_dct_fx( /* normalization per frequency bin */ /*band[i] /= cnt;*/ - band[i] = L_max(Mult_32_16(Ltmp1, inv_mfreq_bindiv_LD_fx[i]), LE_min); - move32(); /* 2*Q_dct + 9*/ - + band[i] = L_max( Mult_32_16( Ltmp1, inv_mfreq_bindiv_LD_fx[i] ), LE_min ); + move32(); /* 2*Q_dct + 9*/ } /*-----------------------------------------------------------------* - * Find the total energy over the input bandwidth - *-----------------------------------------------------------------*/ + * Find the total energy over the input bandwidth + *-----------------------------------------------------------------*/ Ltmp = 0; move16(); @@ -773,7 +791,7 @@ static void find_enr_dct_fx( #ifdef BASOP_NOGLOB Ltmp = L_add_sat( band[i], Ltmp ); #else - Ltmp = L_add(band[i],Ltmp); + Ltmp = L_add( band[i], Ltmp ); #endif } @@ -790,18 +808,18 @@ static void find_enr_dct_fx( *------------------------------------------------------------------------*/ void Prep_music_postP_fx( - Word16 exc_buffer_in[], /* i/o: excitation buffer Q_exc*/ - Word16 dct_buffer_out[], /* o : DCT output buffer (qdct)*/ - Word16 filt_lfE[], /* i/o: long term spectrum energy Q15?*/ - const Word16 last_core, /* i : last core */ - const Word16 element_mode, /* i : element mode */ - const Word16 *pitch_buf, /* i : current frame pitch information Q6*/ - Word16 *LDm_enh_lp_gbin, /* o : smoothed suppression gain, per dct bin Q14*/ - const Word16 Q_exc, /* i : excitation scaling */ - Word16 *qdct /* o : Scaling factor of dct coefficient */ + Word16 exc_buffer_in[], /* i/o: excitation buffer Q_exc*/ + Word16 dct_buffer_out[], /* o : DCT output buffer (qdct)*/ + Word16 filt_lfE[], /* i/o: long term spectrum energy Q15?*/ + const Word16 last_core, /* i : last core */ + const Word16 element_mode, /* i : element mode */ + const Word16 *pitch_buf, /* i : current frame pitch information Q6*/ + Word16 *LDm_enh_lp_gbin, /* o : smoothed suppression gain, per dct bin Q14*/ + const Word16 Q_exc, /* i : excitation scaling */ + Word16 *qdct /* o : Scaling factor of dct coefficient */ ) { - Word16 i; + Word16 i; Word16 *pt1; const Word16 *pt2; Word16 s_pit, fr_pit; @@ -809,18 +827,18 @@ void Prep_music_postP_fx( Word16 exc16[DCT_L_POST]; Word16 *pt1_out; - s_pit = shr(pitch_buf[3],6); - fr_pit = shr(sub(pitch_buf[3], shl(s_pit,6)),4); /* Find fractional part */ + s_pit = shr( pitch_buf[3], 6 ); + fr_pit = shr( sub( pitch_buf[3], shl( s_pit, 6 ) ), 4 ); /* Find fractional part */ /*------------------------------------------------------------* * Resetting some memories in case of switching *------------------------------------------------------------*/ - IF( ( EQ_16( element_mode, EVS_MONO ) && EQ_16(last_core,HQ_CORE) ) || ( NE_16( element_mode, EVS_MONO ) && ( EQ_16(last_core,HQ_CORE) || EQ_16(last_core, TCX_20_CORE) || EQ_16(last_core, TCX_10_CORE) ) ) ) + IF( ( EQ_16( element_mode, EVS_MONO ) && EQ_16( last_core, HQ_CORE ) ) || ( NE_16( element_mode, EVS_MONO ) && ( EQ_16( last_core, HQ_CORE ) || EQ_16( last_core, TCX_20_CORE ) || EQ_16( last_core, TCX_10_CORE ) ) ) ) { set16_fx( filt_lfE, 4096, DCT_L_POST ); set16_fx( LDm_enh_lp_gbin, 16384, VOIC_BINS_HR ); pt1 = exc_buffer_in + OFFSET2 - 1; - pt2 = pt1 + shr_r(pitch_buf[0],6); + pt2 = pt1 + shr_r( pitch_buf[0], 6 ); FOR( i = 0; i < OFFSET2; i++ ) { *pt1 = *pt2; @@ -834,7 +852,7 @@ void Prep_music_postP_fx( * Extrapolation of the last future part and windowing *------------------------------------------------------------*/ pt1 = exc_buffer_in + DCT_L_POST - OFFSET2; - pred_lt4(pt1, pt1, s_pit, fr_pit, OFFSET2, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP); + pred_lt4( pt1, pt1, s_pit, fr_pit, OFFSET2, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); /*------------------------------------------------------------* * windowing right side *------------------------------------------------------------*/ @@ -842,7 +860,7 @@ void Prep_music_postP_fx( pt1_out = exc16 + DCT_L_POST - OFFSET2; FOR( i = 0; i < OFFSET2; i++ ) { - *pt1_out = mult_r(*pt1,*pt2); + *pt1_out = mult_r( *pt1, *pt2 ); move16(); pt1++; pt2++; @@ -856,7 +874,7 @@ void Prep_music_postP_fx( pt2--; FOR( i = 0; i < OFFSET2; i++ ) { - *pt1_out = mult_r(*pt1,*pt2); + *pt1_out = mult_r( *pt1, *pt2 ); move16(); pt1++; pt1_out++; @@ -866,7 +884,7 @@ void Prep_music_postP_fx( * Copy remaining data (Flat part) *------------------------------------------------------------*/ - FOR(; i < L_FRAME+OFFSET2; i++ ) + FOR( ; i < L_FRAME + OFFSET2; i++ ) { *pt1_out = *pt1; move16(); @@ -877,7 +895,7 @@ void Prep_music_postP_fx( * EDCT and back to 16 bits *------------------------------------------------------------*/ - edct_16fx(exc16, dct_buffer_out, DCT_L_POST, 6, EVS_MONO); + edct_16fx( exc16, dct_buffer_out, DCT_L_POST, 6, EVS_MONO ); *qdct = Q_exc; move16(); @@ -895,32 +913,32 @@ static Word16 norm_lfe( ) { Word32 Ltmp; - Word16 exp2, tmp16, exp3 ; + Word16 exp2, tmp16, exp3; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - Ltmp = Mult_32_16(Lfe, m_norm); - Ltmp = L_add(Ltmp, L_shl(BET_Q15_FX, sub(e_norm,15))); /* Ltmp -> e_norm*/ - exp2 = norm_l(Ltmp); - tmp16 = extract_h(L_shl(Ltmp,exp2)); /* exp2 -= 16 */ - exp2 = add(e_norm,exp2); + Ltmp = Mult_32_16( Lfe, m_norm ); + Ltmp = L_add( Ltmp, L_shl( BET_Q15_FX, sub( e_norm, 15 ) ) ); /* Ltmp -> e_norm*/ + exp2 = norm_l( Ltmp ); + tmp16 = extract_h( L_shl( Ltmp, exp2 ) ); /* exp2 -= 16 */ + exp2 = add( e_norm, exp2 ); - tmp16 = mult_r(tmp16,tmp16); /* tmp16 in Q exp2 */ - tmp16 = mult_r(tmp16,tmp16); - tmp16 = mult_r(tmp16,tmp16); + tmp16 = mult_r( tmp16, tmp16 ); /* tmp16 in Q exp2 */ + tmp16 = mult_r( tmp16, tmp16 ); + tmp16 = mult_r( tmp16, tmp16 ); - exp3 = sub(12+16, exp2); /* tmp16 in Q exp2 */ - if(NE_16(exp2,31)) + exp3 = sub( 12 + 16, exp2 ); /* tmp16 in Q exp2 */ + if ( NE_16( exp2, 31 ) ) { - exp3 = sub(exp2, 12+16-3); /* if exp2 < 31, means that tmp >= 1.0 */ + exp3 = sub( exp2, 12 + 16 - 3 ); /* if exp2 < 31, means that tmp >= 1.0 */ /* Need to shl by 3 to take into account the 3 multiplications */ } #ifdef BASOP_NOGLOB - tmp16 = shl_o(tmp16, exp3, &Overflow); /* Result in Q12 */ + tmp16 = shl_o( tmp16, exp3, &Overflow ); /* Result in Q12 */ #else - tmp16 = shl(tmp16, exp3); /* Result in Q12 */ + tmp16 = shl( tmp16, exp3 ); /* Result in Q12 */ #endif return tmp16; @@ -934,24 +952,25 @@ static Word16 norm_lfe( *------------------------------------------------------------------------*/ void Post_music_postP_fx( - Word16 dct_buffer_in[], /* i/o: excitation buffer */ - Word16 *exc2, /* i/o: Current excitation to be overwriten */ - const Word16 *mem_tmp, /* i : previous frame synthesis memory */ - Word16 *st_mem_syn2, /* i/o: current frame synthesis memory */ - const Word16 *Aq, /* i : LPC filter coefficients */ - Word16 *syn, /* i/o: 12k8 synthesis */ - Word16 *Q_exc, /* i : excitation scaling */ - Word16 *prev_Q_syn, /* i : previsous frame synthesis scaling */ - Word16 *Q_syn, /* i : Current frame synthesis scaling */ - Word16 *mem_syn_clas_estim_fx, /* i : old 12k8 synthesis used for frame classification*/ - const Word16 IsIO, /* i: Flag to indicate IO mode */ - Word16 *mem_deemph, /* i/o: speech deemph filter memory */ - Word16 *st_pst_old_syn_fx, /* i/o: psfiler */ - Word16 *st_pst_mem_deemp_err_fx, /* i/o: psfiler */ + Word16 dct_buffer_in[], /* i/o: excitation buffer */ + Word16 *exc2, /* i/o: Current excitation to be overwriten */ + const Word16 *mem_tmp, /* i : previous frame synthesis memory */ + Word16 *st_mem_syn2, /* i/o: current frame synthesis memory */ + const Word16 *Aq, /* i : LPC filter coefficients */ + Word16 *syn, /* i/o: 12k8 synthesis */ + Word16 *Q_exc, /* i : excitation scaling */ + Word16 *prev_Q_syn, /* i : previsous frame synthesis scaling */ + Word16 *Q_syn, /* i : Current frame synthesis scaling */ + Word16 *mem_syn_clas_estim_fx, /* i : old 12k8 synthesis used for frame classification*/ + const Word16 IsIO, /* i: Flag to indicate IO mode */ + Word16 *mem_deemph, /* i/o: speech deemph filter memory */ + Word16 *st_pst_old_syn_fx, /* i/o: psfiler */ + Word16 *st_pst_mem_deemp_err_fx, /* i/o: psfiler */ Word16 *mem_agc, PFSTAT *pf_stat, /* i/o: All memories related to NB post filter */ - const Word16 *tmp_buffer /* tmp_buffer in Q-1 */ - ,Word16 *mem_tmp2 /* Temporary memory used with scale_syn */ + const Word16 *tmp_buffer /* tmp_buffer in Q-1 */ + , + Word16 *mem_tmp2 /* Temporary memory used with scale_syn */ ) { Word16 exc16[DCT_L_POST]; @@ -960,24 +979,24 @@ void Post_music_postP_fx( * Go back to time domain *------------------------------------------------------------------------*/ - edct_16fx( dct_buffer_in, exc16, DCT_L_POST, 6, EVS_MONO); + edct_16fx( dct_buffer_in, exc16, DCT_L_POST, 6, EVS_MONO ); - Copy( exc16 + OFFSET2, exc2, L_FRAME); + Copy( exc16 + OFFSET2, exc2, L_FRAME ); Copy( mem_tmp, st_mem_syn2, M ); /*------------------------------------------------------------------------* * Perform the synthesis filtering using the enhanced excitation *------------------------------------------------------------------------*/ - IF(IsIO == 0) /* Rescaling already done in IO mode */ + IF( IsIO == 0 ) /* Rescaling already done in IO mode */ { - Rescale_mem(*Q_exc, prev_Q_syn, Q_syn, st_mem_syn2,mem_syn_clas_estim_fx, 4, - mem_deemph, st_pst_old_syn_fx, st_pst_mem_deemp_err_fx, mem_agc, - pf_stat, 1, 0, tmp_buffer); + Rescale_mem( *Q_exc, prev_Q_syn, Q_syn, st_mem_syn2, mem_syn_clas_estim_fx, 4, + mem_deemph, st_pst_old_syn_fx, st_pst_mem_deemp_err_fx, mem_agc, + pf_stat, 1, 0, tmp_buffer ); Copy( st_mem_syn2, mem_tmp2, M ); } - syn_12k8_fx( L_FRAME, Aq, exc2, syn, st_mem_syn2, 1 , *Q_exc, *Q_syn); + syn_12k8_fx( L_FRAME, Aq, exc2, syn, st_mem_syn2, 1, *Q_exc, *Q_syn ); return; } @@ -995,19 +1014,19 @@ void music_postfilt_init( Word16 i, e_db, f_db; Word32 L_tmp; - set16_fx(hMusicPF->dct_post_old_exc_fx, 0, DCT_L_POST - OFFSET2); + set16_fx( hMusicPF->dct_post_old_exc_fx, 0, DCT_L_POST - OFFSET2 ); /*st->LDm_enh_min_ns_gain = (float)pow(10.0f, -12/20.0f);*/ - L_tmp = L_mult(((-12 * 256)), 5443); /* *0.166096 in Q15 -> Q24 */ - L_tmp = L_shr(L_tmp, 8); /* From Q24 to Q16 */ - f_db = L_Extract_lc(L_tmp, &e_db); /* Extract exponent */ - f_db = extract_l(Pow2(14, f_db)); /* Put 14 as exponent so that */ - e_db = add(e_db, 15 - 14); - f_db = add(f_db, shr(1, add(e_db, 1))); - hMusicPF->LDm_enh_min_ns_gain_fx = shl(f_db, e_db); + L_tmp = L_mult( ( ( -12 * 256 ) ), 5443 ); /* *0.166096 in Q15 -> Q24 */ + L_tmp = L_shr( L_tmp, 8 ); /* From Q24 to Q16 */ + f_db = L_Extract_lc( L_tmp, &e_db ); /* Extract exponent */ + f_db = extract_l( Pow2( 14, f_db ) ); /* Put 14 as exponent so that */ + e_db = add( e_db, 15 - 14 ); + f_db = add( f_db, shr( 1, add( e_db, 1 ) ) ); + hMusicPF->LDm_enh_min_ns_gain_fx = shl( f_db, e_db ); hMusicPF->LDm_last_music_flag = 0; move16(); - set16_fx(hMusicPF->LDm_lt_diff_etot_fx, 0, MAX_LT); + set16_fx( hMusicPF->LDm_lt_diff_etot_fx, 0, MAX_LT ); hMusicPF->LDm_thres_fx[0] = TH_0_MIN_FX; move16(); @@ -1025,7 +1044,7 @@ void music_postfilt_init( hMusicPF->LDm_mem_etot_fx = 0; move16(); - FOR(i = 0; i < VOIC_BINS_HR; i++) + FOR( i = 0; i < VOIC_BINS_HR; i++ ) { hMusicPF->LDm_enh_lp_gbin_fx[i] = 16384; move16(); @@ -1033,12 +1052,12 @@ void music_postfilt_init( move16(); } - FOR(i = 0; i < MBANDS_GN_LD; i++) + FOR( i = 0; i < MBANDS_GN_LD; i++ ) { hMusicPF->LDm_bckr_noise_fx[i] = E_MIN_Q15; move16(); } - set16_fx(hMusicPF->filt_lfE_fx, 4096, DCT_L_POST); + set16_fx( hMusicPF->filt_lfE_fx, 4096, DCT_L_POST ); move16(); hMusicPF->last_nonfull_music = 0; move16(); diff --git a/lib_dec/TonalComponentDetection.c b/lib_dec/TonalComponentDetection.c index b849df6fc..76ee5e179 100644 --- a/lib_dec/TonalComponentDetection.c +++ b/lib_dec/TonalComponentDetection.c @@ -116,23 +116,23 @@ void DetectTonalComponents_flt( q_scaleFactors_fx -= 1; FOR( Word16 c = 0; c < nSamplesCore; c++ ) { - pScaledMdctSpectrum_fx[c] = (Word32) ( pScaledMdctSpectrum[c] * ( 1<< q_pScaledMdctSpectrum_fx ) ); + pScaledMdctSpectrum_fx[c] = (Word32) ( pScaledMdctSpectrum[c] * ( 1 << q_pScaledMdctSpectrum_fx ) ); } FOR( Word16 c = 0; c < FDNS_NPTS; c++ ) { - scaleFactors_fx[c] = (Word32) ( scaleFactors[c] * ( 1<< q_scaleFactors_fx ) ); + scaleFactors_fx[c] = (Word32) ( scaleFactors[c] * ( 1 << q_scaleFactors_fx ) ); } sns_shape_spectrum_fx( pScaledMdctSpectrum_fx, &q_pScaledMdctSpectrum_fx, psychParamsCurrent, scaleFactors_fx, q_scaleFactors_fx, nSamplesCore ); - IF ( q_pScaledMdctSpectrum_fx + 1 < 31 ) + IF( q_pScaledMdctSpectrum_fx + 1 < 31 ) { FOR( Word16 c = 0; c < nSamplesCore; c++ ) { pScaledMdctSpectrum[c] = ( (float) pScaledMdctSpectrum_fx[c] / ( 1 << ( q_pScaledMdctSpectrum_fx + 1 ) ) ); } } - ELSE IF ( q_pScaledMdctSpectrum_fx + 1 == 31 ) + ELSE IF( q_pScaledMdctSpectrum_fx + 1 == 31 ) { FOR( Word16 c = 0; c < nSamplesCore; c++ ) { @@ -196,7 +196,7 @@ void RefineTonalComponents_flt( float *pOldPhase, *pNewPhase; DetectTonalComponents_flt( newIndexOfTonalPeak, newLowerIndex, newUpperIndex, &newNumIndexes, lastPitchLag, currentPitchLag, lastMDCTSpectrum, scaleFactors, secondLastPowerSpectrum, - nSamples, nSamplesCore, floorPowerSpectrum, psychParamsCurrent ); + nSamples, nSamplesCore, floorPowerSpectrum, psychParamsCurrent ); nPreservedPeaks = 0; iNew = 0; diff --git a/lib_dec/TonalComponentDetection_fx.c b/lib_dec/TonalComponentDetection_fx.c index 9c7f57f24..55a262318 100644 --- a/lib_dec/TonalComponentDetection_fx.c +++ b/lib_dec/TonalComponentDetection_fx.c @@ -22,16 +22,16 @@ /*---------------------------------------------------------------------* * Local function prototypes *---------------------------------------------------------------------*/ -static void calcPseudoSpec(const Word32 * mdctSpec, const Word16 mdctSpec_exp, const Word16 nSamples, Word16 floorPowerSpectrum, Word32 * powerSpec, Word16 * powerSpec_exp); -static void getEnvelope(const Word16 nSamples, const Word32 * powerSpec, Word16 F0, Word32 * envelope, Word32 * smoothedSpectrum); -static void GetF0(Word16 const nSamples,Word16 const nSamplesCore,Word32 const * const powerSpectrum, Word32 const pitchLag, Word16 * const pOrigF0, Word16 * const pF0); -static void findStrongestHarmonics(const Word16 nSamples, const Word32 * powerSpectrum, const Word16 F0, const Word16 nTotalHarmonics, Word16 * pHarmonicIndexes, Word16 * pnHarmonics); -static void CorrectF0(const Word16 * pHarmonicIndexes, const Word16 nHarmonics, Word16 * pF0); -static void findCandidates(const Word16 nSamples, const Word32 * MDCTSpectrum, const Word16 MDCTSpectrum_exp, Word16 * thresholdModificationNew, Word16 floorPowerSpectrum ); -static void modifyThreshold(Word16 i, Word16 F0, Word16 threshold, Word16 * thresholdModification); -static void modifyThresholds(Word16 F0, Word16 origF0, Word16 * thresholdModification); -static void RefineThresholdsUsingPitch(const Word16 nSamples, const Word16 nSamplesCore, const Word32 powerSpectrum[], const Word32 lastPitchLag, const Word32 currentPitchLag, Word16 * pF0, Word16 * thresholdModification); -static void findTonalComponents(Word16 * indexOfTonalPeak, Word16 * lowerIndex, Word16 * upperIndex, Word16 *numIndexes, Word16 nSamples, const Word32 * powerSpectrum, Word16 F0, Word16 * thresholdModification, Word16 element_mode); +static void calcPseudoSpec( const Word32 *mdctSpec, const Word16 mdctSpec_exp, const Word16 nSamples, Word16 floorPowerSpectrum, Word32 *powerSpec, Word16 *powerSpec_exp ); +static void getEnvelope( const Word16 nSamples, const Word32 *powerSpec, Word16 F0, Word32 *envelope, Word32 *smoothedSpectrum ); +static void GetF0( Word16 const nSamples, Word16 const nSamplesCore, Word32 const *const powerSpectrum, Word32 const pitchLag, Word16 *const pOrigF0, Word16 *const pF0 ); +static void findStrongestHarmonics( const Word16 nSamples, const Word32 *powerSpectrum, const Word16 F0, const Word16 nTotalHarmonics, Word16 *pHarmonicIndexes, Word16 *pnHarmonics ); +static void CorrectF0( const Word16 *pHarmonicIndexes, const Word16 nHarmonics, Word16 *pF0 ); +static void findCandidates( const Word16 nSamples, const Word32 *MDCTSpectrum, const Word16 MDCTSpectrum_exp, Word16 *thresholdModificationNew, Word16 floorPowerSpectrum ); +static void modifyThreshold( Word16 i, Word16 F0, Word16 threshold, Word16 *thresholdModification ); +static void modifyThresholds( Word16 F0, Word16 origF0, Word16 *thresholdModification ); +static void RefineThresholdsUsingPitch( const Word16 nSamples, const Word16 nSamplesCore, const Word32 powerSpectrum[], const Word32 lastPitchLag, const Word32 currentPitchLag, Word16 *pF0, Word16 *thresholdModification ); +static void findTonalComponents( Word16 *indexOfTonalPeak, Word16 *lowerIndex, Word16 *upperIndex, Word16 *numIndexes, Word16 nSamples, const Word32 *powerSpectrum, Word16 F0, Word16 *thresholdModification, Word16 element_mode ); /*-------------------------------------------------------------------* * DetectTonalComponents() @@ -39,15 +39,15 @@ static void findTonalComponents(Word16 * indexOfTonalPeak, Word16 * lowerIndex, * Detect tonal components in the lastMDCTSpectrum, use * secondLastPowerSpectrum for the precise location of the peaks and * store them in indexOfTonalPeak. Updates lowerIndex, upperIndex, - * pNumIndexes accordingly. + * pNumIndexes accordingly. *-------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED void ivas_DetectTonalComponents_fx( Word16 indexOfTonalPeak[], Word16 lowerIndex[], Word16 upperIndex[], - Word16* pNumIndexes, - const Word32 lastPitchLag, + Word16 *pNumIndexes, + const Word32 lastPitchLag, const Word32 currentPitchLag, const Word16 lastMDCTSpectrum[], const Word16 lastMDCTSpectrum_exp, @@ -57,9 +57,9 @@ void ivas_DetectTonalComponents_fx( const Word32 secondLastPowerSpectrum[], const Word16 nSamples, const Word16 nSamplesCore, - Word16 floorPowerSpectrum, /* i: lower limit for power spectrum bins */ - const PsychoacousticParameters* psychParamsCurrent, - Word16 element_mode /* i: element mode */ + Word16 floorPowerSpectrum, /* i: lower limit for power spectrum bins */ + const PsychoacousticParameters *psychParamsCurrent, + Word16 element_mode /* i: element mode */ ) { Word16 F0; @@ -69,64 +69,65 @@ void ivas_DetectTonalComponents_fx( Word32 sns_int_scf_fx[FDNS_NPTS]; Word16 q_pScaledMdctSpectrum; - FOR(Word16 i = 0; i < nSamples; i++) + FOR( Word16 i = 0; i < nSamples; i++ ) { - pScaledMdctSpectrum[i] = L_shl(lastMDCTSpectrum[i], 16); // Q31 - lastMDCTSpectrum_exp + pScaledMdctSpectrum[i] = L_shl( lastMDCTSpectrum[i], 16 ); // Q31 - lastMDCTSpectrum_exp } #ifdef MSAN_FIX - FOR(Word16 i = 0; i < FDNS_NPTS; i++) + FOR( Word16 i = 0; i < FDNS_NPTS; i++ ) { - sns_int_scf_fx[i] = L_shl_sat(scaleFactors[i], 1 + scaleFactors_exp[i]); // Q16 + sns_int_scf_fx[i] = L_shl_sat( scaleFactors[i], 1 + scaleFactors_exp[i] ); // Q16 } #endif - IF (psychParamsCurrent == NULL) + IF( psychParamsCurrent == NULL ) { nBands = FDNS_NPTS; - //PMT("add nBands argument to mdct_shaping_16") + // PMT("add nBands argument to mdct_shaping_16") - mdct_shaping_16(lastMDCTSpectrum, nSamplesCore, nSamples, scaleFactors, scaleFactors_exp, scaleFactors_max_e, pScaledMdctSpectrum); - lastMDCTSpect_exp = add(lastMDCTSpectrum_exp, scaleFactors_max_e); + mdct_shaping_16( lastMDCTSpectrum, nSamplesCore, nSamples, scaleFactors, scaleFactors_exp, scaleFactors_max_e, pScaledMdctSpectrum ); + lastMDCTSpect_exp = add( lastMDCTSpectrum_exp, scaleFactors_max_e ); } ELSE { #ifndef MSAN_FIX - FOR(Word16 i = 0; i < FDNS_NPTS; i++) + FOR( Word16 i = 0; i < FDNS_NPTS; i++ ) { - sns_int_scf_fx[i] = L_shl(scaleFactors[i], 1 + scaleFactors_exp[i]); // Q16 + sns_int_scf_fx[i] = L_shl( scaleFactors[i], 1 + scaleFactors_exp[i] ); // Q16 } #endif q_pScaledMdctSpectrum = 31 - lastMDCTSpectrum_exp; - sns_shape_spectrum_fx(pScaledMdctSpectrum, &q_pScaledMdctSpectrum, psychParamsCurrent, sns_int_scf_fx,16, nSamplesCore); + sns_shape_spectrum_fx( pScaledMdctSpectrum, &q_pScaledMdctSpectrum, psychParamsCurrent, sns_int_scf_fx, 16, nSamplesCore ); q_pScaledMdctSpectrum = q_pScaledMdctSpectrum + 1; Word16 tmp_e = 31 - q_pScaledMdctSpectrum; nBands = psychParamsCurrent->nBands; // till nSamplesCore different Q and nSamples - nSamplesCore in different Q - Scale_sig32(pScaledMdctSpectrum + nSamplesCore, nSamples - nSamplesCore, lastMDCTSpectrum_exp - tmp_e); + Scale_sig32( pScaledMdctSpectrum + nSamplesCore, nSamples - nSamplesCore, lastMDCTSpectrum_exp - tmp_e ); lastMDCTSpect_exp = 31 - q_pScaledMdctSpectrum; } - for (int i = nSamplesCore; i < nSamples; ++i) { - Word64 tmp = W_mult_32_32(pScaledMdctSpectrum[i], sns_int_scf_fx[nBands - 1]); // q_pScaledMdctSpectrum + 16 + 1 - pScaledMdctSpectrum[i] = W_extract_h(W_shl(tmp, Q15)); // q_pScaledMdctSpectrum + for ( int i = nSamplesCore; i < nSamples; ++i ) + { + Word64 tmp = W_mult_32_32( pScaledMdctSpectrum[i], sns_int_scf_fx[nBands - 1] ); // q_pScaledMdctSpectrum + 16 + 1 + pScaledMdctSpectrum[i] = W_extract_h( W_shl( tmp, Q15 ) ); // q_pScaledMdctSpectrum } /* Find peak candidates in the last frame. */ - findCandidates(nSamples, pScaledMdctSpectrum, lastMDCTSpect_exp, thresholdModification, floorPowerSpectrum); + findCandidates( nSamples, pScaledMdctSpectrum, lastMDCTSpect_exp, thresholdModification, floorPowerSpectrum ); /* Refine peak candidates using the pitch information */ - RefineThresholdsUsingPitch(nSamples, nSamplesCore, secondLastPowerSpectrum, lastPitchLag, currentPitchLag, &F0, thresholdModification); + RefineThresholdsUsingPitch( nSamples, nSamplesCore, secondLastPowerSpectrum, lastPitchLag, currentPitchLag, &F0, thresholdModification ); /* Find peaks in the second last frame */ - findTonalComponents(indexOfTonalPeak, lowerIndex, upperIndex, pNumIndexes, nSamples, secondLastPowerSpectrum, F0, thresholdModification, element_mode); + findTonalComponents( indexOfTonalPeak, lowerIndex, upperIndex, pNumIndexes, nSamples, secondLastPowerSpectrum, F0, thresholdModification, element_mode ); } #endif -void DetectTonalComponents( +void DetectTonalComponents( Word16 indexOfTonalPeak[], Word16 lowerIndex[], Word16 upperIndex[], - Word16* pNumIndexes, - const Word32 lastPitchLag, + Word16 *pNumIndexes, + const Word32 lastPitchLag, const Word32 currentPitchLag, const Word16 lastMDCTSpectrum[], const Word16 lastMDCTSpectrum_exp, @@ -136,10 +137,11 @@ void DetectTonalComponents( const Word32 secondLastPowerSpectrum[], const Word16 nSamples, const Word16 nSamplesCore, - Word16 floorPowerSpectrum, /* i: lower limit for power spectrum bins */ + Word16 floorPowerSpectrum, /* i: lower limit for power spectrum bins */ Word16 element_mode #ifdef IVAS_CODE_MDCT_GSHAPE - , const PsychoacousticParameters* psychParamsCurrent + , + const PsychoacousticParameters *psychParamsCurrent #endif ) { @@ -148,32 +150,32 @@ void DetectTonalComponents( Word32 pScaledMdctSpectrum[L_FRAME_MAX]; #ifdef IVAS_CODE_MDCT_GSHAPE Word16 nBands; - IF (psychParamsCurrent == NULL) + IF( psychParamsCurrent == NULL ) { nBands = FDNS_NPTS; - PMT("add nBands argument to mdct_shaping_16") + PMT( "add nBands argument to mdct_shaping_16" ) #endif - mdct_shaping_16(lastMDCTSpectrum, nSamplesCore, nSamples, scaleFactors, scaleFactors_exp, scaleFactors_max_e, pScaledMdctSpectrum); + mdct_shaping_16( lastMDCTSpectrum, nSamplesCore, nSamples, scaleFactors, scaleFactors_exp, scaleFactors_max_e, pScaledMdctSpectrum ); #ifdef IVAS_CODE_MDCT_GSHAPE } ELSE { - sns_shape_spectrum(pScaledMdctSpectrum, psychParamsCurrent, scaleFactors, nSamplesCore); + sns_shape_spectrum( pScaledMdctSpectrum, psychParamsCurrent, scaleFactors, nSamplesCore ); nBands = psychParamsCurrent->nBands; } #endif - lastMDCTSpect_exp = add(lastMDCTSpectrum_exp, scaleFactors_max_e); + lastMDCTSpect_exp = add( lastMDCTSpectrum_exp, scaleFactors_max_e ); /* Find peak candidates in the last frame. */ - findCandidates(nSamples, pScaledMdctSpectrum, lastMDCTSpect_exp, thresholdModification, floorPowerSpectrum); + findCandidates( nSamples, pScaledMdctSpectrum, lastMDCTSpect_exp, thresholdModification, floorPowerSpectrum ); /* Refine peak candidates using the pitch information */ - RefineThresholdsUsingPitch(nSamples, nSamplesCore, secondLastPowerSpectrum, lastPitchLag, currentPitchLag, &F0, thresholdModification); + RefineThresholdsUsingPitch( nSamples, nSamplesCore, secondLastPowerSpectrum, lastPitchLag, currentPitchLag, &F0, thresholdModification ); /* Find peaks in the second last frame */ - findTonalComponents(indexOfTonalPeak, lowerIndex, upperIndex, pNumIndexes, nSamples, secondLastPowerSpectrum, F0, thresholdModification, element_mode); + findTonalComponents( indexOfTonalPeak, lowerIndex, upperIndex, pNumIndexes, nSamples, secondLastPowerSpectrum, F0, thresholdModification, element_mode ); } /*-------------------------------------------------------------------* @@ -191,8 +193,8 @@ void RefineTonalComponents( Word16 lowerIndex[], Word16 upperIndex[], Word16 phaseDiff[], - Word16 phases[], - Word16 * pNumIndexes, + Word16 phases[], + Word16 *pNumIndexes, const Word32 lastPitchLag, const Word32 currentPitchLag, const Word16 lastMDCTSpectrum[], @@ -203,10 +205,11 @@ void RefineTonalComponents( const Word32 secondLastPowerSpectrum[], const Word16 nSamples, const Word16 nSamplesCore, - const Word16 floorPowerSpectrum, /* i: lower limit for power spectrum bins */ + const Word16 floorPowerSpectrum, /* i: lower limit for power spectrum bins */ Word16 element_mode #ifdef IVAS_CODE_MDCT_GSHAPE - ,const PsychoacousticParameters* psychParamsCurrent + , + const PsychoacousticParameters *psychParamsCurrent #endif ) { @@ -215,13 +218,14 @@ void RefineTonalComponents( Word16 newUpperIndex[MAX_NUMBER_OF_IDX]; Word16 newNumIndexes, nPreservedPeaks; Word16 iNew, iOld, j; - Word16 * pOldPhase, * pNewPhase; + Word16 *pOldPhase, *pNewPhase; - DetectTonalComponents(newIndexOfTonalPeak, newLowerIndex, newUpperIndex, &newNumIndexes, lastPitchLag, currentPitchLag, lastMDCTSpectrum, - lastMDCTSpectrum_exp, scaleFactors, scaleFactors_exp, scaleFactors_max_e, secondLastPowerSpectrum, nSamples, nSamplesCore, floorPowerSpectrum, element_mode + DetectTonalComponents( newIndexOfTonalPeak, newLowerIndex, newUpperIndex, &newNumIndexes, lastPitchLag, currentPitchLag, lastMDCTSpectrum, + lastMDCTSpectrum_exp, scaleFactors, scaleFactors_exp, scaleFactors_max_e, secondLastPowerSpectrum, nSamples, nSamplesCore, floorPowerSpectrum, element_mode #ifdef IVAS_CODE_MDCT_GSHAPE - , psychParamsCurrent + , + psychParamsCurrent #endif ); @@ -232,17 +236,17 @@ void RefineTonalComponents( pOldPhase = phases; pNewPhase = phases; - FOR (iOld = 0; iOld < *pNumIndexes; iOld++) + FOR( iOld = 0; iOld < *pNumIndexes; iOld++ ) { /* We don't want that the old peak index is at the border of the new peak region, that is why >= newUpperIndex and > newLowerIndex */ test(); - WHILE (LT_16(iNew,newNumIndexes)&&GE_16(indexOfTonalPeak[iOld],newUpperIndex[iNew])) + WHILE( LT_16( iNew, newNumIndexes ) && GE_16( indexOfTonalPeak[iOld], newUpperIndex[iNew] ) ) { - iNew = add(iNew,1); + iNew = add( iNew, 1 ); } test(); - IF (LT_16(iNew,newNumIndexes)&>_16(indexOfTonalPeak[iOld],newLowerIndex[iNew])) + IF( LT_16( iNew, newNumIndexes ) && GT_16( indexOfTonalPeak[iOld], newLowerIndex[iNew] ) ) { newIndexOfTonalPeak[nPreservedPeaks] = indexOfTonalPeak[iOld]; move16(); @@ -253,20 +257,20 @@ void RefineTonalComponents( phaseDiff[nPreservedPeaks] = phaseDiff[iOld]; move16(); - FOR (j = lowerIndex[iOld]; j <= upperIndex[iOld]; j++) + FOR( j = lowerIndex[iOld]; j <= upperIndex[iOld]; j++ ) { *pNewPhase++ = *pOldPhase++; move16(); } - nPreservedPeaks = add(nPreservedPeaks,1); + nPreservedPeaks = add( nPreservedPeaks, 1 ); } ELSE { - pOldPhase += sub(upperIndex[iOld],add(lowerIndex[iOld],1)); + pOldPhase += sub( upperIndex[iOld], add( lowerIndex[iOld], 1 ) ); } } - FOR (iNew = 0; iNew < nPreservedPeaks; iNew++) + FOR( iNew = 0; iNew < nPreservedPeaks; iNew++ ) { indexOfTonalPeak[iNew] = newIndexOfTonalPeak[iNew]; move16(); @@ -284,12 +288,12 @@ void RefineTonalComponents( * Local functions *-------------------------------------------------------------------*/ static void calcPseudoSpec( - const Word32 * mdctSpec, /* i: MDCT spectrum */ - const Word16 mdctSpec_exp, /* i: exponent of MDCT spectrum */ - const Word16 nSamples, /* i: frame size */ - Word16 floorPowerSpectrum, /* i: lower limit for power spectrum bins */ - Word32 * powerSpec, /* o: estimated power spectrum */ - Word16 * powerSpec_exp /* o: exponent of estimated power spectrum */ + const Word32 *mdctSpec, /* i: MDCT spectrum */ + const Word16 mdctSpec_exp, /* i: exponent of MDCT spectrum */ + const Word16 nSamples, /* i: frame size */ + Word16 floorPowerSpectrum, /* i: lower limit for power spectrum bins */ + Word32 *powerSpec, /* o: estimated power spectrum */ + Word16 *powerSpec_exp /* o: exponent of estimated power spectrum */ ) { Word16 k; @@ -297,53 +301,51 @@ static void calcPseudoSpec( Word16 tmp_loop; - - *powerSpec_exp = add(add(mdctSpec_exp, mdctSpec_exp), 5); + *powerSpec_exp = add( add( mdctSpec_exp, mdctSpec_exp ), 5 ); move16(); - k = sub(31, *powerSpec_exp); + k = sub( 31, *powerSpec_exp ); /* If the signal is bellow floor, special care is needed for *powerSpec_exp */ - IF (LT_16(add(16-3, norm_s(floorPowerSpectrum)), k)) /*extra 3 bits of headroom for MA filter in getEnvelope*/ + IF( LT_16( add( 16 - 3, norm_s( floorPowerSpectrum ) ), k ) ) /*extra 3 bits of headroom for MA filter in getEnvelope*/ { - k = add(16-3, norm_s(floorPowerSpectrum)); /*extra 3 bits of headroom for MA filter in getEnvelope*/ - L_tmp_floor = L_shl(L_deposit_l(floorPowerSpectrum), k); - set32_fx(powerSpec, L_tmp_floor, nSamples); - *powerSpec_exp = sub(31, k); + k = add( 16 - 3, norm_s( floorPowerSpectrum ) ); /*extra 3 bits of headroom for MA filter in getEnvelope*/ + L_tmp_floor = L_shl( L_deposit_l( floorPowerSpectrum ), k ); + set32_fx( powerSpec, L_tmp_floor, nSamples ); + *powerSpec_exp = sub( 31, k ); } ELSE { - L_tmp_floor = L_shl(L_deposit_l(floorPowerSpectrum), k); + L_tmp_floor = L_shl( L_deposit_l( floorPowerSpectrum ), k ); - tmp_loop = sub(nSamples, 2); - FOR (k = 1; k <= tmp_loop; k++) + tmp_loop = sub( nSamples, 2 ); + FOR( k = 1; k <= tmp_loop; k++ ) { - x = L_sub(L_shr(mdctSpec[k+1], 1),L_shr(mdctSpec[k-1], 1)); /* An MDST estimate */ + x = L_sub( L_shr( mdctSpec[k + 1], 1 ), L_shr( mdctSpec[k - 1], 1 ) ); /* An MDST estimate */ - x = L_shr(Mpy_32_32(x, x), 3); + x = L_shr( Mpy_32_32( x, x ), 3 ); - L_tmp = Mpy_32_32(mdctSpec[k], mdctSpec[k]); - L_tmp = L_shr(L_tmp, 5); + L_tmp = Mpy_32_32( mdctSpec[k], mdctSpec[k] ); + L_tmp = L_shr( L_tmp, 5 ); - powerSpec[k] = L_max(L_tmp_floor, L_add(L_tmp, x)); + powerSpec[k] = L_max( L_tmp_floor, L_add( L_tmp, x ) ); move32(); } } - powerSpec[0] = L_shr(powerSpec[1], 1); + powerSpec[0] = L_shr( powerSpec[1], 1 ); move32(); - powerSpec[nSamples-1] = L_shr(powerSpec[nSamples-2], 1); + powerSpec[nSamples - 1] = L_shr( powerSpec[nSamples - 2], 1 ); move32(); return; - } -#define LEVEL_EXP 3/*+4*/ +#define LEVEL_EXP 3 /*+4*/ static void getEnvelope( - const Word16 nSamples, /*i: Q0 */ - const Word32* powerSpec, /*i: powerSpec_exp */ - Word16 F0, /*i: 5Q10*/ - Word32 * envelope, /*o: powerSpec_exp + LEVEL_EXP*/ - Word32 * smoothedSpectrum /*o: powerSpec_exp + LEVEL_EXP*/ + const Word16 nSamples, /*i: Q0 */ + const Word32 *powerSpec, /*i: powerSpec_exp */ + Word16 F0, /*i: 5Q10*/ + Word32 *envelope, /*o: powerSpec_exp + LEVEL_EXP*/ + Word32 *smoothedSpectrum /*o: powerSpec_exp + LEVEL_EXP*/ ) { Word16 nFilterLength, nHalfFilterLength, nSecondHalfFilterLength, n1, n2; @@ -351,17 +353,17 @@ static void getEnvelope( Word16 i; Word32 sum, tmp; - IF (F0 == 0) + IF( F0 == 0 ) { nFilterLength = 15; move16(); } - ELSE IF (F0 <= 10240/*10.0f Q10*/) + ELSE IF( F0 <= 10240 /*10.0f Q10*/ ) { nFilterLength = 11; move16(); } - ELSE IF (F0 >= 22528/*22.0f Q10*/) + ELSE IF( F0 >= 22528 /*22.0f Q10*/ ) { /* For F0 >= 22 peak is isolated well enough with the filter length of 23. This case is however not triggered due to the limit of pit_min, @@ -371,80 +373,81 @@ static void getEnvelope( } ELSE { - nFilterLength = s_or(1, shr(F0,10)); /*1+2*(int)(F0/2); F0->Q10*/ move16(); + nFilterLength = s_or( 1, shr( F0, 10 ) ); /*1+2*(int)(F0/2); F0->Q10*/ + move16(); } - nHalfFilterLength = shr(nFilterLength,1); + nHalfFilterLength = shr( nFilterLength, 1 ); - n1 = add(nHalfFilterLength,1); + n1 = add( nHalfFilterLength, 1 ); - nSecondHalfFilterLength = sub(nFilterLength,nHalfFilterLength); + nSecondHalfFilterLength = sub( nFilterLength, nHalfFilterLength ); - n2 = sub(nSecondHalfFilterLength,1); + n2 = sub( nSecondHalfFilterLength, 1 ); - assert((nFilterLength >= 7) && (nFilterLength <= 23) && (nFilterLength %2 == 1)); + assert( ( nFilterLength >= 7 ) && ( nFilterLength <= 23 ) && ( nFilterLength % 2 == 1 ) ); - sum = L_deposit_l(0); - level = 31089/*LEVEL_ABOVE_ENVELOPE Q12*/; /*Q12*/ + sum = L_deposit_l( 0 ); + level = 31089 /*LEVEL_ABOVE_ENVELOPE Q12*/; /*Q12*/ - FOR (i = 0; i < n2; i++) + FOR( i = 0; i < n2; i++ ) { - sum = L_add(sum, powerSpec[i]); + sum = L_add( sum, powerSpec[i] ); } /* No need for PTR_INIT for powerSpec[i+n2] as we continue from the previous loop */ - FOR (i = 0; i < n1; i++) + FOR( i = 0; i < n1; i++ ) { #ifdef BASOP_NOGLOB - sum = L_add_sat(sum, powerSpec[i+n2]); + sum = L_add_sat( sum, powerSpec[i + n2] ); #else - sum = L_add(sum, powerSpec[i+n2]); + sum = L_add( sum, powerSpec[i + n2] ); #endif - tmp = Mpy_32_16_1(sum/*Q31,powerSpec_exp*/,level/*Q12*/); /*Q28,powerSpec_exp*/ - envelope[i]/*Q28,powerSpec_exp*/ = Mpy_32_16_1(tmp/*Q28,powerSpec_exp*/, InvIntTable[i+nSecondHalfFilterLength]/*Q15*/); + tmp = Mpy_32_16_1( sum /*Q31,powerSpec_exp*/, level /*Q12*/ ); /*Q28,powerSpec_exp*/ + envelope[i] /*Q28,powerSpec_exp*/ = Mpy_32_16_1( tmp /*Q28,powerSpec_exp*/, InvIntTable[i + nSecondHalfFilterLength] /*Q15*/ ); move32(); } - inv_len = mult_r(level, InvIntTable[nFilterLength]); - FOR (i = n1; i < nSamples-n2; i++) + inv_len = mult_r( level, InvIntTable[nFilterLength] ); + FOR( i = n1; i < nSamples - n2; i++ ) { #ifdef BASOP_NOGLOB - sum = L_add_sat(sum, L_sub(powerSpec[i+n2],powerSpec[i-n1])); + sum = L_add_sat( sum, L_sub( powerSpec[i + n2], powerSpec[i - n1] ) ); #else - sum = L_add(sum, L_sub(powerSpec[i+n2],powerSpec[i-n1])); + sum = L_add( sum, L_sub( powerSpec[i + n2], powerSpec[i - n1] ) ); #endif - envelope[i] = Mpy_32_16_1(sum, inv_len); + envelope[i] = Mpy_32_16_1( sum, inv_len ); move32(); } - FOR (i = nSamples-n2; i < nSamples; i++) + FOR( i = nSamples - n2; i < nSamples; i++ ) { - sum = L_sub(sum, powerSpec[i-n1]); - tmp = Mpy_32_16_1(sum,level); - envelope[i] = Mpy_32_16_1(tmp, InvIntTable[nSamples-(i-nHalfFilterLength)]); + sum = L_sub( sum, powerSpec[i - n1] ); + tmp = Mpy_32_16_1( sum, level ); + envelope[i] = Mpy_32_16_1( tmp, InvIntTable[nSamples - ( i - nHalfFilterLength )] ); move32(); } - FOR (i = 1; i < nSamples-1; i++) + FOR( i = 1; i < nSamples - 1; i++ ) { - smoothedSpectrum[i] = L_add(L_add(Mpy_32_16_1(powerSpec[i-1],3072/*0.75f Q12*/),L_shr(powerSpec[i],LEVEL_EXP)), Mpy_32_16_1(powerSpec[i+1],3072/*0.75f Q12*/)); + smoothedSpectrum[i] = L_add( L_add( Mpy_32_16_1( powerSpec[i - 1], 3072 /*0.75f Q12*/ ), L_shr( powerSpec[i], LEVEL_EXP ) ), Mpy_32_16_1( powerSpec[i + 1], 3072 /*0.75f Q12*/ ) ); } move32(); move32(); - smoothedSpectrum[0] = L_add(Mpy_32_16_1(powerSpec[1],3072/*0.75f Q12*/),L_shr(powerSpec[0],LEVEL_EXP)); - smoothedSpectrum[nSamples-1] = L_add(Mpy_32_16_1(powerSpec[nSamples-2],3072/*0.75f Q12*/),L_shr(powerSpec[nSamples-1],LEVEL_EXP)); + smoothedSpectrum[0] = L_add( Mpy_32_16_1( powerSpec[1], 3072 /*0.75f Q12*/ ), L_shr( powerSpec[0], LEVEL_EXP ) ); + smoothedSpectrum[nSamples - 1] = L_add( Mpy_32_16_1( powerSpec[nSamples - 2], 3072 /*0.75f Q12*/ ), L_shr( powerSpec[nSamples - 1], LEVEL_EXP ) ); return; - } static void GetF0( - Word16 /*int*/ const nSamples, /*i - Q0 */ - Word16 /*int*/ const nSamplesCore, /*i - Q0 */ - Word32 /*float*/ const * const powerSpectrum, /*i - Qx */ /*is justed handed over and given back*/ - Word32 /*float*/ const pitchLag, /*i - Q16*/ - Word16 /*float*/ * const pOrigF0, /*o - Q10*/ - Word16 /*float*/ * const pF0) /*o - Q10*/ + Word16 /*int*/ const nSamples, /*i - Q0 */ + Word16 /*int*/ const nSamplesCore, /*i - Q0 */ + Word32 /*float*/ const *const powerSpectrum, + /*i - Qx */ /*is justed handed over and given back*/ + Word32 /*float*/ const pitchLag, /*i - Q16*/ + Word16 /*float*/ *const pOrigF0, /*o - Q10*/ + Word16 /*float*/ *const pF0 ) /*o - Q10*/ { Word16 /*float*/ tmpPitchLag; Word16 /*int*/ rgiStrongHarmonics[MAX_PEAKS_FROM_PITCH]; @@ -452,39 +455,39 @@ static void GetF0( Word16 tmp; - assert(LAST_HARMONIC_POS_TO_CHECK <= nSamplesCore); + assert( LAST_HARMONIC_POS_TO_CHECK <= nSamplesCore ); /* Use only F0 >= 100 Hz */ test(); - IF ((pitchLag > 0) && (LE_16(round_fx(pitchLag) , shr(nSamplesCore,1)))) + IF( ( pitchLag > 0 ) && ( LE_16( round_fx( pitchLag ), shr( nSamplesCore, 1 ) ) ) ) { - tmpPitchLag /*"halfPitchLag" in FLC - read as Q5 for comparison to halfpitchlag */ - = round_fx(L_shl(pitchLag,4)); /*no division by 2, will be done in following division - - furthermore, do a leftshift before rounding, to preserve more accuracy - - will be accommodated also in following division*/ + tmpPitchLag /*"halfPitchLag" in FLC - read as Q5 for comparison to halfpitchlag */ + = round_fx( L_shl( pitchLag, 4 ) ); /*no division by 2, will be done in following division - + furthermore, do a leftshift before rounding, to preserve more accuracy - + will be accommodated also in following division*/ /**pF0 = nSamplesCore/tmpPitchLag;*/ - BASOP_Util_Divide_MantExp(nSamplesCore,0,tmpPitchLag,-(1/*division by 2*/+4/*accommodate accuracy-prevention-leftshift*/),pF0,&tmp); /*pF0 is Q15*/ + BASOP_Util_Divide_MantExp( nSamplesCore, 0, tmpPitchLag, -( 1 /*division by 2*/ + 4 /*accommodate accuracy-prevention-leftshift*/ ), pF0, &tmp ); /*pF0 is Q15*/ move16(); - *pF0 = shr(*pF0,sub(5,tmp)); /*Q10 without scalingfactor*/ + *pF0 = shr( *pF0, sub( 5, tmp ) ); /*Q10 without scalingfactor*/ move16(); *pOrigF0 = *pF0; /*Q10*/ move16(); - tmp = 2*LAST_HARMONIC_POS_TO_CHECK; - if (LT_16(nSamples , 2*LAST_HARMONIC_POS_TO_CHECK)) + tmp = 2 * LAST_HARMONIC_POS_TO_CHECK; + if ( LT_16( nSamples, 2 * LAST_HARMONIC_POS_TO_CHECK ) ) { move16(); tmp = nSamples; } - BASOP_Util_Divide_MantExp(tmp,15,*pF0,5,&nTotalHarmonics,&tmp); - nTotalHarmonics =shl(nTotalHarmonics,sub(tmp,15)); + BASOP_Util_Divide_MantExp( tmp, 15, *pF0, 5, &nTotalHarmonics, &tmp ); + nTotalHarmonics = shl( nTotalHarmonics, sub( tmp, 15 ) ); /* Get in rgiStrongHarmonics all i for which i*F0 are the strongest harmonics */ - findStrongestHarmonics(nSamples, powerSpectrum, *pF0, nTotalHarmonics, rgiStrongHarmonics, &nStrongHarmonics); + findStrongestHarmonics( nSamples, powerSpectrum, *pF0, nTotalHarmonics, rgiStrongHarmonics, &nStrongHarmonics ); - CorrectF0(rgiStrongHarmonics, nStrongHarmonics, pF0); + CorrectF0( rgiStrongHarmonics, nStrongHarmonics, pF0 ); } ELSE { @@ -499,17 +502,16 @@ static void GetF0( static void findStrongestHarmonics( const Word16 nSamples, - const Word32 * powerSpectrum, - const Word16 F0/*5Q10*/, + const Word32 *powerSpectrum, + const Word16 F0 /*5Q10*/, const Word16 nTotalHarmonics, - Word16 * pHarmonicIndexes, - Word16 * pnHarmonics -) + Word16 *pHarmonicIndexes, + Word16 *pnHarmonics ) { Word32 peaks[MAX_PEAKS_FROM_PITCH], smallestPeak; Word16 nPeaksToCheck, nPeaks, iSmallestPeak; Word16 i, l, k; - (void)nSamples; + (void) nSamples; nPeaks = 0; @@ -520,62 +522,62 @@ static void findStrongestHarmonics( smallestPeak = 0x7fffffff; move32(); - nPeaksToCheck = s_min(nTotalHarmonics, MAX_PEAKS_FROM_PITCH+1); + nPeaksToCheck = s_min( nTotalHarmonics, MAX_PEAKS_FROM_PITCH + 1 ); - FOR (i = 1; i < nPeaksToCheck; i++) + FOR( i = 1; i < nPeaksToCheck; i++ ) { Word32 newPeak; - k = extract_h(L_shl(L_mult(i,F0),5)); /*k = (int)(i*F0);*/ - assert(k > 0 && k < 2*LAST_HARMONIC_POS_TO_CHECK && k < nSamples); + k = extract_h( L_shl( L_mult( i, F0 ), 5 ) ); /*k = (int)(i*F0);*/ + assert( k > 0 && k < 2 * LAST_HARMONIC_POS_TO_CHECK && k < nSamples ); - newPeak = L_add(powerSpectrum[k], 0); + newPeak = L_add( powerSpectrum[k], 0 ); peaks[nPeaks] = newPeak; move32(); pHarmonicIndexes[nPeaks] = i; move16(); - IF (LE_32(newPeak,smallestPeak)) + IF( LE_32( newPeak, smallestPeak ) ) { iSmallestPeak = nPeaks; move16(); - smallestPeak = L_add(newPeak, 0); + smallestPeak = L_add( newPeak, 0 ); } - nPeaks = add(nPeaks,1); + nPeaks = add( nPeaks, 1 ); } - FOR (; i < nTotalHarmonics; i++) + FOR( ; i < nTotalHarmonics; i++ ) { Word32 newPeak; - k = extract_h(L_shl(L_mult(i,F0),5)); - assert(k > 0 && k < 2*LAST_HARMONIC_POS_TO_CHECK && k < nSamples); + k = extract_h( L_shl( L_mult( i, F0 ), 5 ) ); + assert( k > 0 && k < 2 * LAST_HARMONIC_POS_TO_CHECK && k < nSamples ); - newPeak = L_add(powerSpectrum[k], 0); + newPeak = L_add( powerSpectrum[k], 0 ); - IF (GT_32(newPeak,smallestPeak)) + IF( GT_32( newPeak, smallestPeak ) ) { peaks[iSmallestPeak] = newPeak; move32(); pHarmonicIndexes[iSmallestPeak] = i; move16(); - smallestPeak = L_add(newPeak, 0); + smallestPeak = L_add( newPeak, 0 ); - FOR (l = 0; l < MAX_PEAKS_FROM_PITCH; l++) + FOR( l = 0; l < MAX_PEAKS_FROM_PITCH; l++ ) { - IF (peaks[l] <= smallestPeak) + IF( peaks[l] <= smallestPeak ) { iSmallestPeak = l; move16(); - smallestPeak = L_add(peaks[l], 0); + smallestPeak = L_add( peaks[l], 0 ); } } } } - sort_fx(pHarmonicIndexes, 0, sub(nPeaks,1)); + sort_fx( pHarmonicIndexes, 0, sub( nPeaks, 1 ) ); *pnHarmonics = nPeaks; move16(); @@ -584,19 +586,19 @@ static void findStrongestHarmonics( /* Use new F0, for which harmonics are most common in pHarmonicIndexes */ static void CorrectF0( - const Word16 /*int*/ * pHarmonicIndexes, /*I - Q0 */ - const Word16 /*int*/ nHarmonics, /*I - Q0 */ - Word16 /*float*/ * pF0) /*I/O - Q10 range: {0}, [4..18) */ + const Word16 /*int*/ *pHarmonicIndexes, /*I - Q0 */ + const Word16 /*int*/ nHarmonics, /*I - Q0 */ + Word16 /*float*/ *pF0 ) /*I/O - Q10 range: {0}, [4..18) */ { - Word16 /*int*/ i; + Word16 /*int*/ i; Word16 /*float*/ F0; - Word16 /*int*/ diff[MAX_PEAKS_FROM_PITCH-1], sortedDiff[MAX_PEAKS_FROM_PITCH-1]; - Word16 /*int*/ iMostCommonDiff, nMostCommonDiff, nSameDiff, iMult; + Word16 /*int*/ diff[MAX_PEAKS_FROM_PITCH - 1], sortedDiff[MAX_PEAKS_FROM_PITCH - 1]; + Word16 /*int*/ iMostCommonDiff, nMostCommonDiff, nSameDiff, iMult; Word16 tmp; #ifdef IVAS_CODE - FOR (i = 0; i < MAX_PEAKS_FROM_PITCH - 1; i++) + FOR( i = 0; i < MAX_PEAKS_FROM_PITCH - 1; i++ ) { diff[i] = 0; sortedDiff[i] = 0; @@ -607,31 +609,31 @@ static void CorrectF0( F0 = *pF0; test(); - IF (F0 > 0 && nHarmonics != 0) + IF( F0 > 0 && nHarmonics != 0 ) { - tmp = sub(nHarmonics, 1); - FOR (i = 0; i < tmp; i++) + tmp = sub( nHarmonics, 1 ); + FOR( i = 0; i < tmp; i++ ) { - diff[i] = sub(pHarmonicIndexes[i+1], pHarmonicIndexes[i]); + diff[i] = sub( pHarmonicIndexes[i + 1], pHarmonicIndexes[i] ); move16(); sortedDiff[i] = diff[i]; move16(); } - sort_fx(sortedDiff, 0,sub(nHarmonics, 1+1)); + sort_fx( sortedDiff, 0, sub( nHarmonics, 1 + 1 ) ); iMostCommonDiff = sortedDiff[0]; move16(); nSameDiff = 1; move16(); i = 1; move16(); - IF (EQ_16(imult1616(sortedDiff[0],pHarmonicIndexes[0]),1)) + IF( EQ_16( imult1616( sortedDiff[0], pHarmonicIndexes[0] ), 1 ) ) { /* Find how many distances between peaks have length 1 */ - FOR (; i < tmp; i++) + FOR( ; i < tmp; i++ ) { - if (EQ_16(sortedDiff[i],1)) + if ( EQ_16( sortedDiff[i], 1 ) ) { - nSameDiff=add(nSameDiff,1); + nSameDiff = add( nSameDiff, 1 ); } } } @@ -640,31 +642,32 @@ static void CorrectF0( /* If there are at least 3 distances between peaks with length 1 and if the 1st harmonic is in pHarmonicIndexes then keep the original F0 */ /* Otherwise find the most common distance between peaks */ - IF (LT_16(nSameDiff,3)) + IF( LT_16( nSameDiff, 3 ) ) { /* Find the most common difference */ - FOR (i = nSameDiff; i < tmp; i++) + FOR( i = nSameDiff; i < tmp; i++ ) { - IF (EQ_16(sortedDiff[i], sortedDiff[i-1])) + IF( EQ_16( sortedDiff[i], sortedDiff[i - 1] ) ) { - nSameDiff=add(nSameDiff,1); + nSameDiff = add( nSameDiff, 1 ); } ELSE { - IF (GT_16(nSameDiff, nMostCommonDiff)) + IF( GT_16( nSameDiff, nMostCommonDiff ) ) { nMostCommonDiff = nSameDiff; move16(); - iMostCommonDiff = sortedDiff[i-1]; + iMostCommonDiff = sortedDiff[i - 1]; move16(); } - ELSE { + ELSE + { test(); - IF (EQ_16(nSameDiff, nMostCommonDiff)&&(abs_s(sub(iMostCommonDiff,pHarmonicIndexes[0]))>abs_s(sub(sortedDiff[i-1],pHarmonicIndexes[0])))) + IF( EQ_16( nSameDiff, nMostCommonDiff ) && ( abs_s( sub( iMostCommonDiff, pHarmonicIndexes[0] ) ) > abs_s( sub( sortedDiff[i - 1], pHarmonicIndexes[0] ) ) ) ) { nMostCommonDiff = nSameDiff; move16(); - iMostCommonDiff = sortedDiff[i-1]; + iMostCommonDiff = sortedDiff[i - 1]; move16(); } } @@ -672,23 +675,23 @@ static void CorrectF0( move16(); } } - IF (GT_16(nSameDiff,nMostCommonDiff)) + IF( GT_16( nSameDiff, nMostCommonDiff ) ) { nMostCommonDiff = nSameDiff; move16(); - iMostCommonDiff = sortedDiff[nHarmonics-2]; + iMostCommonDiff = sortedDiff[nHarmonics - 2]; move16(); } } /* If there are enough peaks at the same distance */ - IF (GE_16(nMostCommonDiff, MAX_PEAKS_FROM_PITCH/2)) + IF( GE_16( nMostCommonDiff, MAX_PEAKS_FROM_PITCH / 2 ) ) { iMult = 1; move16(); - FOR (i = 0; i < tmp; i++) + FOR( i = 0; i < tmp; i++ ) { - IF (EQ_16(diff[i], iMostCommonDiff)) + IF( EQ_16( diff[i], iMostCommonDiff ) ) { iMult = pHarmonicIndexes[i]; move16(); @@ -697,7 +700,7 @@ static void CorrectF0( /* for rare cases of octave mismatch or missing harmonics */ test(); test(); - IF (GT_16(sub(nHarmonics,2),i)&&(EQ_16(diff[i],diff[i+1]))&&(EQ_16(add(diff[i],diff[i+1]),iMostCommonDiff))) + IF( GT_16( sub( nHarmonics, 2 ), i ) && ( EQ_16( diff[i], diff[i + 1] ) ) && ( EQ_16( add( diff[i], diff[i + 1] ), iMostCommonDiff ) ) ) { iMult = pHarmonicIndexes[i]; move16(); @@ -707,10 +710,10 @@ static void CorrectF0( /* If the real F0 is much higher than the original F0 from the pitch */ - IF (LE_16(iMult, 3)) + IF( LE_16( iMult, 3 ) ) { /* Use iMostCommonDiff, because the lowest pHarmonicIndexes[i] (which is equal to iMult) may not correspond to the new F0, but to it's multiple */ - F0 = round_fx(L_shl(L_mult(iMostCommonDiff /*Q0*/,F0 /*Q10*/),15)); + F0 = round_fx( L_shl( L_mult( iMostCommonDiff /*Q0*/, F0 /*Q10*/ ), 15 ) ); } ELSE { @@ -722,7 +725,7 @@ static void CorrectF0( ELSE { test(); - if ((GT_16(iMostCommonDiff,1))||(LT_16(nMostCommonDiff,3))) + if ( ( GT_16( iMostCommonDiff, 1 ) ) || ( LT_16( nMostCommonDiff, 3 ) ) ) { /* Not enough peaks at the same distance => don't use the pitch. */ F0 = 0; @@ -736,10 +739,10 @@ static void CorrectF0( } static void modifyThreshold( - Word16 /*int*/ i, /*I - Q0 */ - Word16 /*float*/ F0, /*I - Q10*/ - Word16 /*float*/ threshold, /*I - Q10*/ - Word16* /*float*/ thresholdModification) /*I/O - Q10*/ + Word16 /*int*/ i, /*I - Q0 */ + Word16 /*float*/ F0, /*I - Q10*/ + Word16 /*float*/ threshold, /*I - Q10*/ + Word16 * /*float*/ thresholdModification ) /*I/O - Q10*/ { Word32 harmonic; Word16 fractional /*Q15*/; @@ -747,56 +750,55 @@ static void modifyThreshold( Word16 twoTimesFract /*Q10*/; - - harmonic = L_mult(shl(i,5),F0); /*Q0 * Q10 = 15Q16*/ - k = extract_h(harmonic); /*Q0*/ - fractional = lshr(extract_l(harmonic),1); /* Fractional part of the i*F0 */ /*Q15*/ - twoTimesFract = mult(2048/*2 in Q10*/,fractional/*Q15*/); /*Q10*/ /* threshold if the center of the peek is between k-1 and k, threshold+2 if the center of the peek is between k and k+1 */ + harmonic = L_mult( shl( i, 5 ), F0 ); /*Q0 * Q10 = 15Q16*/ + k = extract_h( harmonic ); /*Q0*/ + fractional = lshr( extract_l( harmonic ), 1 ); /* Fractional part of the i*F0 */ /*Q15*/ + twoTimesFract = mult( 2048 /*2 in Q10*/, fractional /*Q15*/ ); /*Q10*/ /* threshold if the center of the peek is between k-1 and k, threshold+2 if the center of the peek is between k and k+1 */ move16(); thresholdModification[k] = threshold; move16(); - thresholdModification[k-1] = add(threshold/*Q10*/, twoTimesFract/*Q10*/); /*Q10*/ + thresholdModification[k - 1] = add( threshold /*Q10*/, twoTimesFract /*Q10*/ ); /*Q10*/ move16(); - thresholdModification[k+1] = add(threshold/*Q10*/, sub(2048/*2 in Q10*/, twoTimesFract/*Q10*/)/*Q10*/); /*Q10*/ + thresholdModification[k + 1] = add( threshold /*Q10*/, sub( 2048 /*2 in Q10*/, twoTimesFract /*Q10*/ ) /*Q10*/ ); /*Q10*/ return; } static void modifyThresholds( - Word16 /*float*/ F0, /*I - Q10*/ - Word16 /*float*/ origF0, /*I - Q10*/ - Word16* /*float*/ thresholdModification) /*I/O - Q10*/ + Word16 /*float*/ F0, /*I - Q10*/ + Word16 /*float*/ origF0, /*I - Q10*/ + Word16 * /*float*/ thresholdModification ) /*I/O - Q10*/ { Word16 /*int*/ i, /*int*/ nHarmonics; Word16 tmp, tmpM, tmpE; - IF (origF0 > 0) + IF( origF0 > 0 ) { - IF (F0 == 0) + IF( F0 == 0 ) { - nHarmonics /*Q0*/ = s_min(MAX_PEAKS_FROM_PITCH /*Q0*/, shl((div_s(LAST_HARMONIC_POS_TO_CHECK /*Q0*/, origF0/*Q10*/) /*Q15*2^10*/),-5 /*Q0*2^-5*/) /*Q0*/); + nHarmonics /*Q0*/ = s_min( MAX_PEAKS_FROM_PITCH /*Q0*/, shl( ( div_s( LAST_HARMONIC_POS_TO_CHECK /*Q0*/, origF0 /*Q10*/ ) /*Q15*2^10*/ ), -5 /*Q0*2^-5*/ ) /*Q0*/ ); - FOR (i = 1; i <= nHarmonics; i++) + FOR( i = 1; i <= nHarmonics; i++ ) { - modifyThreshold(i, origF0, 717/*0.7f Q10*/ /*0.7f in Q10*/, thresholdModification); + modifyThreshold( i, origF0, 717 /*0.7f Q10*/ /*0.7f in Q10*/, thresholdModification ); } } - IF (F0 > 0) + IF( F0 > 0 ) { - nHarmonics /*Q0*/ = s_min(MAX_PEAKS_FROM_PITCH /*Q0*/, shl((div_s(LAST_HARMONIC_POS_TO_CHECK /*Q0*/, F0/*Q10*/) /*Q15*2^10*/),-5 /*Q0*2^-5*/) /*Q0*/); + nHarmonics /*Q0*/ = s_min( MAX_PEAKS_FROM_PITCH /*Q0*/, shl( ( div_s( LAST_HARMONIC_POS_TO_CHECK /*Q0*/, F0 /*Q10*/ ) /*Q15*2^10*/ ), -5 /*Q0*2^-5*/ ) /*Q0*/ ); /*(int)(F0/origF0+0.5f)*/ - BASOP_Util_Divide_MantExp(F0,0,origF0,0,&tmpM,&tmpE); - tmp=round_fx(L_shl(L_deposit_l(tmpM),add(tmpE,1))); + BASOP_Util_Divide_MantExp( F0, 0, origF0, 0, &tmpM, &tmpE ); + tmp = round_fx( L_shl( L_deposit_l( tmpM ), add( tmpE, 1 ) ) ); - FOR (i = tmp; i > 0; i--) + FOR( i = tmp; i > 0; i-- ) { - modifyThreshold(i, origF0, 358/*0.35f Q10*/, thresholdModification); + modifyThreshold( i, origF0, 358 /*0.35f Q10*/, thresholdModification ); } - FOR (i = 1; i <= nHarmonics; i++) + FOR( i = 1; i <= nHarmonics; i++ ) { - modifyThreshold(i, F0, 358/*0.35f Q10*/, thresholdModification); + modifyThreshold( i, F0, 358 /*0.35f Q10*/, thresholdModification ); } } } @@ -804,11 +806,11 @@ static void modifyThresholds( } static void findCandidates( - const Word16 nSamples, /* i: frame size */ - const Word32 * MDCTSpectrum, /* i: MDCT spectrum */ - const Word16 MDCTSpectrum_exp, /* i: exponent of MDCT spectrum */ - Word16 * thresholdModificationNew, /* o: threshold modification Q10 */ - Word16 floorPowerSpectrum /* i: lower limit for power spectrum bins */ + const Word16 nSamples, /* i: frame size */ + const Word32 *MDCTSpectrum, /* i: MDCT spectrum */ + const Word16 MDCTSpectrum_exp, /* i: exponent of MDCT spectrum */ + Word16 *thresholdModificationNew, /* o: threshold modification Q10 */ + Word16 floorPowerSpectrum /* i: lower limit for power spectrum bins */ ) { Word32 powerSpectrum[L_FRAME_MAX]; @@ -821,93 +823,92 @@ static void findCandidates( Word16 tmp_loop1, tmp_loop2, tmp_loop3; + calcPseudoSpec( MDCTSpectrum, MDCTSpectrum_exp, nSamples, floorPowerSpectrum, powerSpectrum, &powerSpectrum_exp ); - calcPseudoSpec(MDCTSpectrum, MDCTSpectrum_exp, nSamples, floorPowerSpectrum, powerSpectrum, &powerSpectrum_exp); + getEnvelope( nSamples, powerSpectrum, 0, envelope, smoothedSpectrum ); - getEnvelope(nSamples, powerSpectrum, 0, envelope, smoothedSpectrum); + set16_fx( thresholdModificationNew, UNREACHABLE_THRESHOLD, nSamples ); - set16_fx(thresholdModificationNew, UNREACHABLE_THRESHOLD, nSamples); - - k = GROUP_LENGTH/2; + k = GROUP_LENGTH / 2; move16(); - tmp_loop1 = sub(nSamples, (GROUP_LENGTH-GROUP_LENGTH/2)); - tmp_loop2 = sub(nSamples,1); - WHILE ( LE_16(k, tmp_loop1)) + tmp_loop1 = sub( nSamples, ( GROUP_LENGTH - GROUP_LENGTH / 2 ) ); + tmp_loop2 = sub( nSamples, 1 ); + WHILE( LE_16( k, tmp_loop1 ) ) { - IF (GT_32(smoothedSpectrum[k],envelope[k])) + IF( GT_32( smoothedSpectrum[k], envelope[k] ) ) { /* The check that bin at k is bigger than bins at k-1 and k+1 is needed to avoid deadlocks when the thresholds are low. */ /* It removes some true peaks, especially if non weighted sum is used for the smoothed spectrum. */ - biggerNeighbor = L_max(powerSpectrum[k-1], powerSpectrum[k+1]); + biggerNeighbor = L_max( powerSpectrum[k - 1], powerSpectrum[k + 1] ); - IF (GE_32(powerSpectrum[k], biggerNeighbor)) + IF( GE_32( powerSpectrum[k], biggerNeighbor ) ) { /* Find the right foot */ - upperIdx = add(k, 1); - WHILE ( LT_16(upperIdx,tmp_loop2)) + upperIdx = add( k, 1 ); + WHILE( LT_16( upperIdx, tmp_loop2 ) ) { - IF (LT_32(powerSpectrum[upperIdx],powerSpectrum[upperIdx+1])) + IF( LT_32( powerSpectrum[upperIdx], powerSpectrum[upperIdx + 1] ) ) { /* Side lobes may increase for certain amount */ - IF (LT_32( L_shl(Mpy_32_16_1(powerSpectrum[upperIdx], ALLOWED_SIDE_LOBE_FLUCTUATION), ALLOWED_SIDE_LOBE_FLUCTUATION_EXP), powerSpectrum[upperIdx+1] )) + IF( LT_32( L_shl( Mpy_32_16_1( powerSpectrum[upperIdx], ALLOWED_SIDE_LOBE_FLUCTUATION ), ALLOWED_SIDE_LOBE_FLUCTUATION_EXP ), powerSpectrum[upperIdx + 1] ) ) { BREAK; } /* Check for further decrease after a side lobe increase */ - FOR (j = add(upperIdx,1); j < tmp_loop2; j++) + FOR( j = add( upperIdx, 1 ); j < tmp_loop2; j++ ) { - IF (LT_32( powerSpectrum[j], L_shl(Mpy_32_16_1(powerSpectrum[j+1], ALLOWED_SIDE_LOBE_FLUCTUATION), ALLOWED_SIDE_LOBE_FLUCTUATION_EXP) )) + IF( LT_32( powerSpectrum[j], L_shl( Mpy_32_16_1( powerSpectrum[j + 1], ALLOWED_SIDE_LOBE_FLUCTUATION ), ALLOWED_SIDE_LOBE_FLUCTUATION_EXP ) ) ) { BREAK; } } /* Side lobe increase must be 2 times smaller than the decrease to the foot */ /* Eq. to 2.0f*powerSpectrum[lowerIdx-1]/powerSpectrum[lowerIdx] > powerSpectrum[lowerIdx]/powerSpectrum[j] */ - IF ( GT_32( Mpy_32_32(L_shl(powerSpectrum[upperIdx+1],1),powerSpectrum[j]), Mpy_32_32(powerSpectrum[upperIdx], powerSpectrum[upperIdx]) )) + IF( GT_32( Mpy_32_32( L_shl( powerSpectrum[upperIdx + 1], 1 ), powerSpectrum[j] ), Mpy_32_32( powerSpectrum[upperIdx], powerSpectrum[upperIdx] ) ) ) { BREAK; } - upperIdx = sub(j,1); + upperIdx = sub( j, 1 ); } - upperIdx = add(upperIdx, 1); + upperIdx = add( upperIdx, 1 ); } /* left foot */ - lowerIdx = sub(k,1); - WHILE ( lowerIdx > 0 ) + lowerIdx = sub( k, 1 ); + WHILE( lowerIdx > 0 ) { - IF (LT_32(powerSpectrum[lowerIdx], powerSpectrum[lowerIdx-1])) + IF( LT_32( powerSpectrum[lowerIdx], powerSpectrum[lowerIdx - 1] ) ) { /* Side lobes may increase for certain amount */ - IF (LT_32( L_shl(Mpy_32_16_1(powerSpectrum[lowerIdx], ALLOWED_SIDE_LOBE_FLUCTUATION), ALLOWED_SIDE_LOBE_FLUCTUATION_EXP), powerSpectrum[lowerIdx-1])) + IF( LT_32( L_shl( Mpy_32_16_1( powerSpectrum[lowerIdx], ALLOWED_SIDE_LOBE_FLUCTUATION ), ALLOWED_SIDE_LOBE_FLUCTUATION_EXP ), powerSpectrum[lowerIdx - 1] ) ) { BREAK; } /* Check for further decrease after a side lobe increase */ - FOR (j = sub(lowerIdx,1); j > 0; j--) + FOR( j = sub( lowerIdx, 1 ); j > 0; j-- ) { - IF (LT_32(powerSpectrum[j], L_shl(Mpy_32_16_1(powerSpectrum[j-1], ALLOWED_SIDE_LOBE_FLUCTUATION), ALLOWED_SIDE_LOBE_FLUCTUATION_EXP) ) ) + IF( LT_32( powerSpectrum[j], L_shl( Mpy_32_16_1( powerSpectrum[j - 1], ALLOWED_SIDE_LOBE_FLUCTUATION ), ALLOWED_SIDE_LOBE_FLUCTUATION_EXP ) ) ) { BREAK; } } /* Side lobe increase must be 2 times smaller than the decrease to the foot */ /* Eq. to 2.0f*powerSpectrum[lowerIdx-1]/powerSpectrum[lowerIdx] > powerSpectrum[lowerIdx]/powerSpectrum[j] */ - IF (GT_32 ( Mpy_32_32(L_shl(powerSpectrum[lowerIdx-1],1), powerSpectrum[j]), Mpy_32_32(powerSpectrum[lowerIdx], powerSpectrum[lowerIdx])) ) + IF( GT_32( Mpy_32_32( L_shl( powerSpectrum[lowerIdx - 1], 1 ), powerSpectrum[j] ), Mpy_32_32( powerSpectrum[lowerIdx], powerSpectrum[lowerIdx] ) ) ) { BREAK; } - lowerIdx = add(j,1); + lowerIdx = add( j, 1 ); } - lowerIdx = sub(lowerIdx, 1); + lowerIdx = sub( lowerIdx, 1 ); } /* Check if there is a bigger peak up to the next peak foot */ - tmp_loop3 = s_min(upperIdx, tmp_loop1); - FOR (j = s_max(GROUP_LENGTH/2, lowerIdx); j <= tmp_loop3; j++) + tmp_loop3 = s_min( upperIdx, tmp_loop1 ); + FOR( j = s_max( GROUP_LENGTH / 2, lowerIdx ); j <= tmp_loop3; j++ ) { - if (GT_32(powerSpectrum[j], powerSpectrum[k])) + if ( GT_32( powerSpectrum[j], powerSpectrum[k] ) ) { k = j; move16(); @@ -915,25 +916,24 @@ static void findCandidates( } /* Modify thresholds for the following frame */ - tmp_loop3 = add(k,2); - FOR (j = sub(k,1); j < tmp_loop3; j++) + tmp_loop3 = add( k, 2 ); + FOR( j = sub( k, 1 ); j < tmp_loop3; j++ ) { thresholdModificationNew[j] = BIG_THRESHOLD; move16(); - if (GT_32(smoothedSpectrum[j], envelope[j])) + if ( GT_32( smoothedSpectrum[j], envelope[j] ) ) { thresholdModificationNew[j] = SMALL_THRESHOLD; move16(); } - } /* Jump to the next foot of the peak. */ k = upperIdx; move16(); } } - k = add(k, 1); + k = add( k, 1 ); } return; } @@ -944,8 +944,8 @@ static void RefineThresholdsUsingPitch( const Word32 powerSpectrum[], const Word32 lastPitchLag, const Word32 currentPitchLag, - Word16 * pF0, - Word16 * thresholdModification) + Word16 *pF0, + Word16 *thresholdModification ) { Word16 pitchIsStable; Word16 origF0; @@ -954,20 +954,20 @@ static void RefineThresholdsUsingPitch( /*pitchIsStable = (fabs(lastPitchLag-currentPitchLag) < 0.25f);*/ pitchIsStable = 0; move16(); - L_tmp = L_abs(L_sub(lastPitchLag, currentPitchLag)); - if (LT_32(L_tmp, 16384l/*0.25f Q16*/)) + L_tmp = L_abs( L_sub( lastPitchLag, currentPitchLag ) ); + if ( LT_32( L_tmp, 16384l /*0.25f Q16*/ ) ) { pitchIsStable = 1; move16(); } - IF (pitchIsStable) + IF( pitchIsStable ) { - GetF0(nSamples, - nSamplesCore, - powerSpectrum, lastPitchLag, &origF0, pF0); + GetF0( nSamples, + nSamplesCore, + powerSpectrum, lastPitchLag, &origF0, pF0 ); - modifyThresholds(*pF0, origF0, thresholdModification); + modifyThresholds( *pF0, origF0, thresholdModification ); } ELSE { @@ -978,15 +978,15 @@ static void RefineThresholdsUsingPitch( } static void findTonalComponents( - Word16 * indexOfTonalPeak, /* OUT */ - Word16 * lowerIndex, /* OUT */ - Word16 * upperIndex, /* OUT */ - Word16 *numIndexes, /* OUT */ - Word16 nSamples, /* IN */ - const Word32 * powerSpectrum, /* IN */ - Word16 F0, /* IN */ - Word16 * thresholdModification, /* IN */ - Word16 element_mode) /* IN */ + Word16 *indexOfTonalPeak, /* OUT */ + Word16 *lowerIndex, /* OUT */ + Word16 *upperIndex, /* OUT */ + Word16 *numIndexes, /* OUT */ + Word16 nSamples, /* IN */ + const Word32 *powerSpectrum, /* IN */ + Word16 F0, /* IN */ + Word16 *thresholdModification, /* IN */ + Word16 element_mode ) /* IN */ { Word32 envelope[L_FRAME_MAX]; Word32 smoothedSpectrum[L_FRAME_MAX]; @@ -996,7 +996,7 @@ static void findTonalComponents( Word32 biggerNeighbor; Word16 tmp_loop1, tmp_loop2, tmp_loop3; - getEnvelope(nSamples, powerSpectrum, F0, envelope, smoothedSpectrum); + getEnvelope( nSamples, powerSpectrum, F0, envelope, smoothedSpectrum ); nrOfFIS = 0; @@ -1004,89 +1004,89 @@ static void findTonalComponents( lowerBound = 0; move16(); - k = GROUP_LENGTH/2; + k = GROUP_LENGTH / 2; move16(); - tmp_loop1 = sub(nSamples, (GROUP_LENGTH-GROUP_LENGTH/2)); - tmp_loop2 = sub(nSamples,1); - WHILE ( LE_16(k, tmp_loop1)) + tmp_loop1 = sub( nSamples, ( GROUP_LENGTH - GROUP_LENGTH / 2 ) ); + tmp_loop2 = sub( nSamples, 1 ); + WHILE( LE_16( k, tmp_loop1 ) ) { /* There is 3 bits headroom in envelope and max of thresholdModification is 16384, so shifting left for 4 would produce overflow only when the result is anyhow close to 1 */ - IF (GT_32(L_shr(smoothedSpectrum[k], 1), L_shl(Mpy_32_16_1(envelope[k]/*Q28,powerSpec_exp*/, thresholdModification[k]/*Q10*/), 4))) + IF( GT_32( L_shr( smoothedSpectrum[k], 1 ), L_shl( Mpy_32_16_1( envelope[k] /*Q28,powerSpec_exp*/, thresholdModification[k] /*Q10*/ ), 4 ) ) ) { /* The check that bin at k is bigger than bins at k-1 and k+1 is needed to avoid deadlocks when the thresholds are low. */ /* It removes some true peaks, especially if non weighted sum is used for the smoothed spectrum. */ - biggerNeighbor = L_max(powerSpectrum[k-1], powerSpectrum[k+1]); + biggerNeighbor = L_max( powerSpectrum[k - 1], powerSpectrum[k + 1] ); - IF (GE_32(powerSpectrum[k], biggerNeighbor)) + IF( GE_32( powerSpectrum[k], biggerNeighbor ) ) { /* Find the right foot */ - upperIdx = add(k, 1); - WHILE (LT_16(upperIdx, tmp_loop2)) + upperIdx = add( k, 1 ); + WHILE( LT_16( upperIdx, tmp_loop2 ) ) { - IF (LT_32(powerSpectrum[upperIdx], powerSpectrum[upperIdx+1])) + IF( LT_32( powerSpectrum[upperIdx], powerSpectrum[upperIdx + 1] ) ) { /* Side lobes may increase for certain amount */ - IF (LT_32( L_shl(Mpy_32_16_1(powerSpectrum[upperIdx], ALLOWED_SIDE_LOBE_FLUCTUATION), ALLOWED_SIDE_LOBE_FLUCTUATION_EXP), powerSpectrum[upperIdx+1])) + IF( LT_32( L_shl( Mpy_32_16_1( powerSpectrum[upperIdx], ALLOWED_SIDE_LOBE_FLUCTUATION ), ALLOWED_SIDE_LOBE_FLUCTUATION_EXP ), powerSpectrum[upperIdx + 1] ) ) { BREAK; } /* Check for further decrease after a side lobe increase */ - FOR (j = add(upperIdx, 1); j < tmp_loop2; j++) + FOR( j = add( upperIdx, 1 ); j < tmp_loop2; j++ ) { - IF (LT_32( powerSpectrum[j], L_shl(Mpy_32_16_1(powerSpectrum[j+1], ALLOWED_SIDE_LOBE_FLUCTUATION), ALLOWED_SIDE_LOBE_FLUCTUATION_EXP))) + IF( LT_32( powerSpectrum[j], L_shl( Mpy_32_16_1( powerSpectrum[j + 1], ALLOWED_SIDE_LOBE_FLUCTUATION ), ALLOWED_SIDE_LOBE_FLUCTUATION_EXP ) ) ) { BREAK; } } /* Side lobe increase must be 2 times smaller than the decrease to the foot */ /* Eq. to 2.0f*powerSpectrum[lowerIdx-1]/powerSpectrum[lowerIdx] > powerSpectrum[lowerIdx]/powerSpectrum[j] */ - IF( (EQ_16(element_mode, EVS_MONO) && GT_32( Mpy_32_32( L_shl( powerSpectrum[upperIdx + 1], 1 ), powerSpectrum[j] ), Mpy_32_32( powerSpectrum[upperIdx], powerSpectrum[upperIdx] ) ) ) || - (NE_16(element_mode, EVS_MONO) && ( GT_64( W_mult_32_32( L_shl( powerSpectrum[upperIdx + 1], 1 ), powerSpectrum[j] ), W_mult_32_32( powerSpectrum[upperIdx], powerSpectrum[upperIdx] ) ) ) ) ) + IF( ( EQ_16( element_mode, EVS_MONO ) && GT_32( Mpy_32_32( L_shl( powerSpectrum[upperIdx + 1], 1 ), powerSpectrum[j] ), Mpy_32_32( powerSpectrum[upperIdx], powerSpectrum[upperIdx] ) ) ) || + ( NE_16( element_mode, EVS_MONO ) && ( GT_64( W_mult_32_32( L_shl( powerSpectrum[upperIdx + 1], 1 ), powerSpectrum[j] ), W_mult_32_32( powerSpectrum[upperIdx], powerSpectrum[upperIdx] ) ) ) ) ) { BREAK; } - upperIdx = sub(j, 1); + upperIdx = sub( j, 1 ); } - upperIdx = add(upperIdx, 1); + upperIdx = add( upperIdx, 1 ); } /* left foot */ - lowerIdx = sub(k, 1); - WHILE (GT_16(lowerIdx, lowerBound)) + lowerIdx = sub( k, 1 ); + WHILE( GT_16( lowerIdx, lowerBound ) ) { - IF (LT_32(powerSpectrum[lowerIdx], powerSpectrum[lowerIdx-1])) + IF( LT_32( powerSpectrum[lowerIdx], powerSpectrum[lowerIdx - 1] ) ) { /* Side lobes may increase for certain amount */ - IF ( LT_32(L_shl(Mpy_32_16_1(powerSpectrum[lowerIdx], ALLOWED_SIDE_LOBE_FLUCTUATION), ALLOWED_SIDE_LOBE_FLUCTUATION_EXP), powerSpectrum[lowerIdx-1])) + IF( LT_32( L_shl( Mpy_32_16_1( powerSpectrum[lowerIdx], ALLOWED_SIDE_LOBE_FLUCTUATION ), ALLOWED_SIDE_LOBE_FLUCTUATION_EXP ), powerSpectrum[lowerIdx - 1] ) ) { BREAK; } /* Check for further decrease after a side lobe increase */ - FOR (j = sub(lowerIdx, 1); j > 0; j--) + FOR( j = sub( lowerIdx, 1 ); j > 0; j-- ) { - IF (LT_32(powerSpectrum[j], L_shl(Mpy_32_16_1(powerSpectrum[j-1], ALLOWED_SIDE_LOBE_FLUCTUATION), ALLOWED_SIDE_LOBE_FLUCTUATION_EXP))) + IF( LT_32( powerSpectrum[j], L_shl( Mpy_32_16_1( powerSpectrum[j - 1], ALLOWED_SIDE_LOBE_FLUCTUATION ), ALLOWED_SIDE_LOBE_FLUCTUATION_EXP ) ) ) { BREAK; } } /* Side lobe increase must be 2 times smaller than the decrease to the foot */ /* Eq. to 2.0f*powerSpectrum[lowerIdx-1]/powerSpectrum[lowerIdx] > powerSpectrum[lowerIdx]/powerSpectrum[j] */ - IF ( GT_32( Mpy_32_32(L_shl(powerSpectrum[lowerIdx-1], 1), powerSpectrum[j]), Mpy_32_32(powerSpectrum[lowerIdx], powerSpectrum[lowerIdx]))) + IF( GT_32( Mpy_32_32( L_shl( powerSpectrum[lowerIdx - 1], 1 ), powerSpectrum[j] ), Mpy_32_32( powerSpectrum[lowerIdx], powerSpectrum[lowerIdx] ) ) ) { BREAK; } - lowerIdx = add(j, 1); + lowerIdx = add( j, 1 ); } - lowerIdx = sub(lowerIdx, 1); + lowerIdx = sub( lowerIdx, 1 ); } lowerBound = upperIdx; move16(); /* Check if there is a bigger peak up to the next peak foot */ - tmp_loop3 = s_min(upperIdx, tmp_loop1); - FOR (j = s_max(GROUP_LENGTH/2, lowerIdx); j <= tmp_loop3; j++) + tmp_loop3 = s_min( upperIdx, tmp_loop1 ); + FOR( j = s_max( GROUP_LENGTH / 2, lowerIdx ); j <= tmp_loop3; j++ ) { - if (GT_32(powerSpectrum[j],powerSpectrum[k])) + if ( GT_32( powerSpectrum[j], powerSpectrum[k] ) ) { k = j; @@ -1094,28 +1094,28 @@ static void findTonalComponents( } } - assert((nrOfFIS == 0) || (indexOfTonalPeak[nrOfFIS-1] < k)); + assert( ( nrOfFIS == 0 ) || ( indexOfTonalPeak[nrOfFIS - 1] < k ) ); - lowerIndex[nrOfFIS] = sub(k, GROUP_LENGTH/2); + lowerIndex[nrOfFIS] = sub( k, GROUP_LENGTH / 2 ); move16(); - upperIndex[nrOfFIS] = add(k,(GROUP_LENGTH-GROUP_LENGTH/2-1)); + upperIndex[nrOfFIS] = add( k, ( GROUP_LENGTH - GROUP_LENGTH / 2 - 1 ) ); move16(); test(); - IF ((nrOfFIS > 0) && (LE_16(lowerIndex[nrOfFIS], upperIndex[nrOfFIS-1]))) + IF( ( nrOfFIS > 0 ) && ( LE_16( lowerIndex[nrOfFIS], upperIndex[nrOfFIS - 1] ) ) ) { - m = shr(add(k, indexOfTonalPeak[nrOfFIS-1]), 1); - upperIndex[nrOfFIS-1] = m; + m = shr( add( k, indexOfTonalPeak[nrOfFIS - 1] ), 1 ); + upperIndex[nrOfFIS - 1] = m; move16(); - lowerIndex[nrOfFIS] = add(m, 1); + lowerIndex[nrOfFIS] = add( m, 1 ); move16(); } indexOfTonalPeak[nrOfFIS++] = k; move16(); - IF (EQ_16(nrOfFIS, MAX_NUMBER_OF_IDX)) + IF( EQ_16( nrOfFIS, MAX_NUMBER_OF_IDX ) ) { BREAK; } @@ -1124,11 +1124,10 @@ static void findTonalComponents( move16(); } } - k = add(k, 1); + k = add( k, 1 ); } *numIndexes = nrOfFIS; move16(); return; } - diff --git a/lib_dec/acelp_core_dec.c b/lib_dec/acelp_core_dec.c index 325bfc5b5..c0267b47f 100644 --- a/lib_dec/acelp_core_dec.c +++ b/lib_dec/acelp_core_dec.c @@ -81,7 +81,7 @@ ivas_error acelp_core_dec( ) { float old_exc[L_EXC_DEC], *exc; /* excitation signal buffer */ - float syn_tmp[L_FRAME16k + L_SUBFR] = { 0 }, *syn; /* synthesis signal buffer */ + float syn_tmp[L_FRAME16k + L_SUBFR] = { 0 }, *syn; /* synthesis signal buffer */ int16_t output_frame; /* frame length at output sampling freq. */ float lsf_new[M]; /* LSFs at the end of the frame */ float lsp_new[M]; /* LSPs at the end of the frame */ @@ -1440,4 +1440,4 @@ ivas_error acelp_core_dec( pop_wmops(); return error; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/acelp_core_dec_fx.c b/lib_dec/acelp_core_dec_fx.c index 360f9bd7e..bb2dfffff 100644 --- a/lib_dec/acelp_core_dec_fx.c +++ b/lib_dec/acelp_core_dec_fx.c @@ -4,13 +4,13 @@ #include #include -#include "options.h" /* Compilation switches */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ #include "ivas_prot_fx.h" -#include "ivas_cnst.h" /* Common constants */ -#include "cnst.h" /* Common constants */ +#include "ivas_cnst.h" /* Common constants */ +#include "cnst.h" /* Common constants */ #ifdef IVAS_FLOAT_FIXED /*==========================================================================*/ /* FUNCTION : void acelp_core_dec_fx () */ @@ -38,50 +38,50 @@ /*==========================================================================*/ ivas_error acelp_core_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 output[], /* o : synthesis @internal Fs */ - Word16 synth_out[], /* o : synthesis */ - Word16 save_hb_synth[], /* o : HB synthesis */ - Word32 bwe_exc_extended[], /* i/o: bandwidth extended excitation */ - Word16 *voice_factors, /* o : voicing factors */ - Word16 old_syn_12k8_16k[], /* o : intermediate ACELP synthesis for SWB BWE */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 output[], /* o : synthesis @internal Fs */ + Word16 synth_out[], /* o : synthesis */ + Word16 save_hb_synth[], /* o : HB synthesis */ + Word32 bwe_exc_extended[], /* i/o: bandwidth extended excitation */ + Word16 *voice_factors, /* o : voicing factors */ + Word16 old_syn_12k8_16k[], /* o : intermediate ACELP synthesis for SWB BWE */ Word16 sharpFlag, - Word16 pitch_buf_fx[NB_SUBFR16k], /* o : floating pitch for each subframe */ - Word16 *unbits, /* o : number of unused bits */ - Word16 *sid_bw, /* o : 0-NB/WB, 1-SWB SID */ - STEREO_TD_DEC_DATA_HANDLE hStereoTD,/* i/o: TD stereo decoder handle */ - const Word16 tdm_lspQ_PCh[M], /* i : Q LSPs for primary channel */ - const Word16 tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */ - const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ - const Word16 last_element_mode, /* i : last element mode */ - const Word32 last_element_brate, /* i : last element bitrate */ - const Word16 flag_sec_CNA, /* i : CNA flag for secondary channel */ - const Word16 nchan_out, /* i : number of output channels */ - STEREO_CNG_DEC_HANDLE hStereoCng, /* i : stereo CNG handle */ - const Word16 read_sid_info /* i : read SID info flag */ + Word16 pitch_buf_fx[NB_SUBFR16k], /* o : floating pitch for each subframe */ + Word16 *unbits, /* o : number of unused bits */ + Word16 *sid_bw, /* o : 0-NB/WB, 1-SWB SID */ + STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle */ + const Word16 tdm_lspQ_PCh[M], /* i : Q LSPs for primary channel */ + const Word16 tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */ + const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ + const Word16 last_element_mode, /* i : last element mode */ + const Word32 last_element_brate, /* i : last element bitrate */ + const Word16 flag_sec_CNA, /* i : CNA flag for secondary channel */ + const Word16 nchan_out, /* i : number of output channels */ + STEREO_CNG_DEC_HANDLE hStereoCng, /* i : stereo CNG handle */ + const Word16 read_sid_info /* i : read SID info flag */ ) { - Word16 old_exc_fx[L_EXC_DEC] = {0}, *exc_fx; /* excitation signal buffer (Q0) */ - Word16 syn_fx_tmp[L_FRAME_16k+L_SUBFR], *syn_fx; /* synthesis signal buffer */ + Word16 old_exc_fx[L_EXC_DEC] = { 0 }, *exc_fx; /* excitation signal buffer (Q0) */ + Word16 syn_fx_tmp[L_FRAME_16k + L_SUBFR], *syn_fx; /* synthesis signal buffer */ Word16 temp_buf[L_FRAME16k + L_SYN_MEM]; - Word16 output_frame; /* frame length at output sampling freq. */ - Word16 mem_tmp_fx[M]; /* temporary synthesis filter memory */ - Word32 enr_q_fx; /* E information for FER protection */ - Word16 tmp_noise_fx; /* Long term temporary noise energy */ + Word16 output_frame; /* frame length at output sampling freq. */ + Word16 mem_tmp_fx[M]; /* temporary synthesis filter memory */ + Word32 enr_q_fx; /* E information for FER protection */ + Word16 tmp_noise_fx; /* Long term temporary noise energy */ Word16 i, int_fs; Word16 tc_subfr_fx; Word16 allow_cn_step_fx; Word16 temp_buf_fx[L_FRAME16k + L_SYN_MEM]; - Word16 Aq_fx[NB_SUBFR16k*(M+1)]= {0}; /*Q12*/ - Word16 Es_pred_fx; /*Q8*/ - Word16 old_bwe_exc_fx[((PIT16k_MAX + (L_FRAME16k+1) + L_SUBFR16k) * 2)] = {0}; /* excitation buffer */ - Word16 old_exc2_fx[L_FRAME16k + L_EXC_MEM], *exc2_fx; /* total excitation buffer */ + Word16 Aq_fx[NB_SUBFR16k * ( M + 1 )] = { 0 }; /*Q12*/ + Word16 Es_pred_fx; /*Q8*/ + Word16 old_bwe_exc_fx[( ( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2 )] = { 0 }; /* excitation buffer */ + Word16 old_exc2_fx[L_FRAME16k + L_EXC_MEM], *exc2_fx; /* total excitation buffer */ Word16 *bwe_exc_fx; - Word16 lsf_new_fx[M]; /* LSFs at the end of the frame */ - Word16 lsp_new_fx[M]; /* LSPs at the end of the frame */ - Word16 lsp_mid_fx[M]; /* LSPs in the middle of the frame */ - Word16 FEC_pitch_fx; /*Q6*/ + Word16 lsf_new_fx[M]; /* LSFs at the end of the frame */ + Word16 lsp_new_fx[M]; /* LSPs at the end of the frame */ + Word16 lsp_mid_fx[M]; /* LSPs in the middle of the frame */ + Word16 FEC_pitch_fx; /*Q6*/ Word16 last_pulse_pos; Word16 T0_tmp; Word16 do_WI_fx; @@ -89,13 +89,13 @@ ivas_error acelp_core_dec_fx( Word16 exc_buffer_fx[DCT_L_POST]; Word16 dct_exc_tmp[L_FRAME16k]; Word16 qdct; - Word16 delta_mem_scale; + Word16 delta_mem_scale; Word16 bpf_error_signal[L_FRAME16k]; CLDFB_SCALE_FACTOR scaleFactor; - Word32 workBuffer[128*3]; + Word32 workBuffer[128 * 3]; Word32 q_env[20]; Word16 exc3_fx[L_FRAME16k]; - Word16 syn1_fx_tmp[L_FRAME16k+2], *syn1_fx; + Word16 syn1_fx_tmp[L_FRAME16k + 2], *syn1_fx; Word32 *realBuffer[CLDFB_NO_COL_MAX], *imagBuffer[CLDFB_NO_COL_MAX]; Word16 gain_buf[NB_SUBFR16k]; /*Q14*/ Word16 syn_fx_tmp2[L_FRAME_16k]; @@ -104,13 +104,13 @@ ivas_error acelp_core_dec_fx( Word16 update_flg; Word32 realBufferTmp[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; Word32 imagBufferTmp[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - Word16 LSF_Q_prediction; /* o : LSF prediction mode */ + Word16 LSF_Q_prediction; /* o : LSF prediction mode */ Word16 avoid_lpc_burst_on_recovery; Word16 uc_two_stage_flag, dec; Word16 nb_bits, indice; - Word16 tdm_lp_reuse_flag, tdm_low_rate_mode, tdm_Pitch_reuse_flag; + Word16 tdm_lp_reuse_flag, tdm_low_rate_mode, tdm_Pitch_reuse_flag; #ifdef ADD_LRTD - Word16 * p_tdm_Pri_pitch_buf; + Word16 *p_tdm_Pri_pitch_buf; #endif MUSIC_POSTFILT_HANDLE hMusicPF; BPF_DEC_HANDLE hBPF; @@ -119,17 +119,17 @@ ivas_error acelp_core_dec_fx( TCX_DEC_HANDLE hTcxDec; ivas_error error; #ifdef REMOVE_IVAS_UNUSED_PARAMETERS_WARNING - (void)(tdm_lspQ_PCh); - (void)(tdm_lsfQ_PCh); - (void)(use_cldfb_for_dft); - (void)(last_element_mode); - (void)(last_element_brate); - (void)(flag_sec_CNA); - (void)(nchan_out); - (void)(save_hb_synth); - (void)(output); - (void)(read_sid_info); - (void)hStereoCng; + (void) ( tdm_lspQ_PCh ); + (void) ( tdm_lsfQ_PCh ); + (void) ( use_cldfb_for_dft ); + (void) ( last_element_mode ); + (void) ( last_element_brate ); + (void) ( flag_sec_CNA ); + (void) ( nchan_out ); + (void) ( save_hb_synth ); + (void) ( output ); + (void) ( read_sid_info ); + (void) hStereoCng; #endif hMusicPF = st_fx->hMusicPF; hBPF = st_fx->hBPF; @@ -138,8 +138,8 @@ ivas_error acelp_core_dec_fx( hTcxDec = st_fx->hTcxDec; error = IVAS_ERR_OK; - //IF ( EQ_16(st_fx->element_mode, IVAS_CPE_MDCT) && EQ_16(nchan_out, 1) && EQ_16(st_fx->idchan, 1) && LE_32(last_element_brate, IVAS_SID_4k4) ) - IF ( EQ_16(st_fx->element_mode, IVAS_CPE_MDCT) && EQ_16(nchan_out, 1) && EQ_16(st_fx->idchan, 1) && LE_32(last_element_brate, IVAS_SID_5k2) ) + // IF ( EQ_16(st_fx->element_mode, IVAS_CPE_MDCT) && EQ_16(nchan_out, 1) && EQ_16(st_fx->idchan, 1) && LE_32(last_element_brate, IVAS_SID_4k4) ) + IF( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) && EQ_16( nchan_out, 1 ) && EQ_16( st_fx->idchan, 1 ) && LE_32( last_element_brate, IVAS_SID_5k2 ) ) { /* In MDCT-Stereo DTX with mono output, we can skip CNG for the second channel, except for the first inactive frame following an active period */ return error; @@ -147,54 +147,54 @@ ivas_error acelp_core_dec_fx( #ifdef IVAS_CODE - output_frame = (int16_t)(st->output_Fs / FRAMES_PER_SEC); + output_frame = (int16_t) ( st->output_Fs / FRAMES_PER_SEC ); /*----------------------------------------------------------------* * stereo SID and CNG frames processing *----------------------------------------------------------------*/ - if (st->core_brate <= SID_2k40 && st->element_mode == IVAS_CPE_DFT && nchan_out == 2) + if ( st->core_brate <= SID_2k40 && st->element_mode == IVAS_CPE_DFT && nchan_out == 2 ) { - if (st->cng_type == FD_CNG) + if ( st->cng_type == FD_CNG ) { - configureFdCngDec_fx(st->hFdCngDec, st->bwidth, ACELP_14k25, st->L_frame, st->last_L_frame, st->element_mode); + configureFdCngDec_fx( st->hFdCngDec, st->bwidth, ACELP_14k25, st->L_frame, st->last_L_frame, st->element_mode ); /* Only run parameter decoding in SID frames */ - if (st->core_brate == SID_2k40) + if ( st->core_brate == SID_2k40 ) { - FdCng_decodeSID_fx(st); + FdCng_decodeSID_fx( st ); } - for (i = 0; i < NPART; i++) + for ( i = 0; i < NPART; i++ ) { - st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] = STEREO_DFT_FD_FILT * st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] + (1 - STEREO_DFT_FD_FILT) * st->hFdCngDec->hFdCngCom->sidNoiseEst[i]; + st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] = STEREO_DFT_FD_FILT * st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] + ( 1 - STEREO_DFT_FD_FILT ) * st->hFdCngDec->hFdCngCom->sidNoiseEst[i]; } #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - ApplyFdCng_fx(NULL, NULL, NULL, NULL, st, 0, 0); + ApplyFdCng_fx( NULL, NULL, NULL, NULL, st, 0, 0 ); #else - ApplyFdCng_fx(NULL, NULL, NULL, NULL, st, 0, 0); + ApplyFdCng_fx( NULL, NULL, NULL, NULL, st, 0, 0 ); #endif } else { - configureFdCngDec_fx(st->hFdCngDec, st->bwidth, ACELP_14k25, st->L_frame, st->last_L_frame, st->element_mode); + configureFdCngDec_fx( st->hFdCngDec, st->bwidth, ACELP_14k25, st->L_frame, st->last_L_frame, st->element_mode ); /* decode CNG parameters */ - CNG_dec(st, last_element_mode, Aq, lsp_new, lsf_new, &allow_cn_step, sid_bw, q_env); + CNG_dec( st, last_element_mode, Aq, lsp_new, lsf_new, &allow_cn_step, sid_bw, q_env ); /* comfort noise generation */ - CNG_exc(st->core_brate, st->L_frame, &st->hTdCngDec->Enew, &st->hTdCngDec->cng_seed, NULL, NULL, &st->lp_ener, st->last_core_brate, &st->first_CNG, &(st->hTdCngDec->cng_ener_seed), NULL, allow_cn_step, &st->hTdCngDec->last_allow_cn_step, st->hTdCngDec->num_ho, q_env, st->hTdCngDec->lp_env, st->hTdCngDec->old_env, st->hTdCngDec->exc_mem, st->hTdCngDec->exc_mem1, sid_bw, &st->hTdCngDec->cng_ener_seed1, NULL, st->Opt_AMR_WB, st->element_mode); + CNG_exc( st->core_brate, st->L_frame, &st->hTdCngDec->Enew, &st->hTdCngDec->cng_seed, NULL, NULL, &st->lp_ener, st->last_core_brate, &st->first_CNG, &( st->hTdCngDec->cng_ener_seed ), NULL, allow_cn_step, &st->hTdCngDec->last_allow_cn_step, st->hTdCngDec->num_ho, q_env, st->hTdCngDec->lp_env, st->hTdCngDec->old_env, st->hTdCngDec->exc_mem, st->hTdCngDec->exc_mem1, sid_bw, &st->hTdCngDec->cng_ener_seed1, NULL, st->Opt_AMR_WB, st->element_mode ); - mvr2r(Aq, st->Aq_cng, M + 1); + mvr2r( Aq, st->Aq_cng, M + 1 ); /* update old LSP and LSF vector */ - mvr2r(lsf_new, st->lsf_old, M); - mvr2r(lsp_new, st->lsp_old, M); + mvr2r( lsf_new, st->lsf_old, M ); + mvr2r( lsp_new, st->lsp_old, M ); } - set_f(output, 0, output_frame); /* output and synth are not used in DFT domain CNG generation and the decoder output is unaffected if they are left uninitalized */ - set_f(synth, 0, output_frame); /* They are however read in a few places which causes errors in the valgrind tests. Simplest solution from a code perspective was to set them to zero. */ + set_f( output, 0, output_frame ); /* output and synth are not used in DFT domain CNG generation and the decoder output is unaffected if they are left uninitalized */ + set_f( synth, 0, output_frame ); /* They are however read in a few places which causes errors in the valgrind tests. Simplest solution from a code perspective was to set them to zero. */ /* CN generation done in DFT domain */ wmops_sub_end(); @@ -205,10 +205,10 @@ ivas_error acelp_core_dec_fx( * Active frames processing *----------------------------------------------------------------*/ #endif - FOR( i=0; ioutput_Fs_fx / 50); move16();*/ output_frame = st_fx->output_frame_fx; move16(); st_fx->bpf_off = 0; move16(); - test(); test(); test(); test(); - IF ( EQ_16(st_fx->last_core, HQ_CORE) || EQ_16(st_fx->last_core, TCX_20_CORE) || EQ_16(st_fx->last_core, TCX_10_CORE) || (EQ_16(st_fx->element_mode, IVAS_CPE_DFT) && LE_32(st_fx->last_core_brate, SID_2k40)) || (EQ_16(st_fx->element_mode, IVAS_CPE_MDCT) && LE_32(st_fx->last_core_brate, SID_2k40) )) + test(); + test(); + test(); + test(); + IF( EQ_16( st_fx->last_core, HQ_CORE ) || EQ_16( st_fx->last_core, TCX_20_CORE ) || EQ_16( st_fx->last_core, TCX_10_CORE ) || ( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) && LE_32( st_fx->last_core_brate, SID_2k40 ) ) || ( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) && LE_32( st_fx->last_core_brate, SID_2k40 ) ) ) { /* in case of HQ->ACELP switching, do not apply BPF */ st_fx->bpf_off = 1; move16(); /* in case of core switching, reset post-filter memories */ - IF (st_fx->hPFstat != NULL) + IF( st_fx->hPFstat != NULL ) { st_fx->hPFstat->on = 0; } move16(); /* reset the GSC pre echo energy threshold in case of switching */ - IF (st_fx->hGSCDec != NULL) + IF( st_fx->hGSCDec != NULL ) { st_fx->hGSCDec->Last_frame_ener_fx = MAX_32; } move32(); } - if(st_fx->prev_bfi > 0) + if ( st_fx->prev_bfi > 0 ) { /* reset the GSC pre echo energy threshold in case of FEC */ - IF(st_fx->hGSCDec != NULL) + IF( st_fx->hGSCDec != NULL ) { st_fx->hGSCDec->Last_frame_ener_fx = MAX_32; } move32(); } #ifdef IVAS_CODE - if ((st->element_mode == IVAS_CPE_DFT || st->element_mode == IVAS_CPE_TD) && (st->last_core_brate == SID_2k40 || st->last_core_brate == FRAME_NO_DATA)) + if ( ( st->element_mode == IVAS_CPE_DFT || st->element_mode == IVAS_CPE_TD ) && ( st->last_core_brate == SID_2k40 || st->last_core_brate == FRAME_NO_DATA ) ) { - set_zero(st->hFdCngDec->hFdCngCom->olapBufferSynth2, FFTLEN); - set_zero(hStereoCng->olapBufferSynth22, FFTLEN); + set_zero( st->hFdCngDec->hFdCngCom->olapBufferSynth2, FFTLEN ); + set_zero( hStereoCng->olapBufferSynth22, FFTLEN ); } #endif st_fx->clas_dec = st_fx->last_good; @@ -279,18 +282,18 @@ ivas_error acelp_core_dec_fx( Copy( st_fx->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); exc_fx = old_exc_fx + L_EXC_MEM_DEC; move16(); - IF (st_fx->hWIDec != NULL) + IF( st_fx->hWIDec != NULL ) { - Copy(st_fx->hWIDec->old_exc2_fx, old_exc2_fx, L_EXC_MEM); + Copy( st_fx->hWIDec->old_exc2_fx, old_exc2_fx, L_EXC_MEM ); } - ELSE + ELSE { - set16_fx(old_exc2_fx, 0, L_EXC_MEM); + set16_fx( old_exc2_fx, 0, L_EXC_MEM ); } exc2_fx = old_exc2_fx + L_EXC_MEM; - IF (st_fx->hBWE_TD != NULL) + IF( st_fx->hBWE_TD != NULL ) { - Copy(hBWE_TD->old_bwe_exc_fx, old_bwe_exc_fx, PIT16k_MAX * 2); + Copy( hBWE_TD->old_bwe_exc_fx, old_bwe_exc_fx, PIT16k_MAX * 2 ); bwe_exc_fx = old_bwe_exc_fx + PIT16k_MAX * 2; } ELSE @@ -309,7 +312,7 @@ ivas_error acelp_core_dec_fx( move16(); set16_fx( gain_buf, 0, NB_SUBFR16k ); - IF( EQ_16(st_fx->L_frame,L_FRAME)) + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { st_fx->gamma = GAMMA1; move16(); @@ -329,9 +332,9 @@ ivas_error acelp_core_dec_fx( } /* reset post-filter in case post-filtering was off in previous frame */ - IF(st_fx->hPFstat != NULL) + IF( st_fx->hPFstat != NULL ) { - if (st_fx->hPFstat->on == 0) + if ( st_fx->hPFstat->on == 0 ) { st_fx->hPFstat->reset = 1; move16(); @@ -341,14 +344,14 @@ ivas_error acelp_core_dec_fx( move16(); test(); test(); - if( st_fx->last_con_tcx && NE_16(st_fx->L_frameTCX_past, st_fx->L_frame)&&st_fx->last_core!=0) + if ( st_fx->last_con_tcx && NE_16( st_fx->L_frameTCX_past, st_fx->L_frame ) && st_fx->last_core != 0 ) { avoid_lpc_burst_on_recovery = 1; move16(); } /* TD stereo parameters */ test(); - IF (EQ_16(st_fx->element_mode, IVAS_CPE_TD) && st_fx->idchan == 1) + IF( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && st_fx->idchan == 1 ) { tdm_lp_reuse_flag = hStereoTD->tdm_lp_reuse_flag; tdm_low_rate_mode = hStereoTD->tdm_low_rate_mode; @@ -356,15 +359,19 @@ ivas_error acelp_core_dec_fx( #ifdef ADD_LRTD p_tdm_Pri_pitch_buf = hStereoTD->tdm_Pri_pitch_buf; #endif - move16(); move16(); move16(); move16(); + move16(); + move16(); + move16(); + move16(); } else { tdm_lp_reuse_flag = 0; tdm_low_rate_mode = 0; - move16(); move16(); + move16(); + move16(); test(); - IF (EQ_16(st_fx->element_mode, IVAS_SCE) && st_fx->low_rate_mode) + IF( EQ_16( st_fx->element_mode, IVAS_SCE ) && st_fx->low_rate_mode ) { tdm_low_rate_mode = 1; move16(); @@ -373,26 +380,27 @@ ivas_error acelp_core_dec_fx( #ifdef ADD_LRTD p_tdm_Pri_pitch_buf = NULL; #endif - move16(); move16(); + move16(); + move16(); } /*----------------------------------------------------------------* * Updates in case of internal sampling rate switching *----------------------------------------------------------------*/ test(); test(); - IF (NE_16(st_fx->last_L_frame, st_fx->L_frame) && (EQ_16(st_fx->last_core, ACELP_CORE) || EQ_16(st_fx->last_core, AMR_WB_CORE))) + IF( NE_16( st_fx->last_L_frame, st_fx->L_frame ) && ( EQ_16( st_fx->last_core, ACELP_CORE ) || EQ_16( st_fx->last_core, AMR_WB_CORE ) ) ) { - if( st_fx->hPFstat->on != 0 ) + if ( st_fx->hPFstat->on != 0 ) { Word16 mem_syn_r_size_old, mem_syn_r_size_new; - mem_syn_r_size_old = shr(st_fx->last_L_frame, 4); - mem_syn_r_size_new = shr(st_fx->L_frame, 4); - lerp( st_fx->hPFstat->mem_stp+L_SYN_MEM-mem_syn_r_size_old, st_fx->hPFstat->mem_stp+L_SYN_MEM-mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); - lerp( st_fx->hPFstat->mem_pf_in+L_SYN_MEM-mem_syn_r_size_old, st_fx->hPFstat->mem_pf_in+L_SYN_MEM-mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); + mem_syn_r_size_old = shr( st_fx->last_L_frame, 4 ); + mem_syn_r_size_new = shr( st_fx->L_frame, 4 ); + lerp( st_fx->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_old, st_fx->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); + lerp( st_fx->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_old, st_fx->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); } /* convert quantized LSP vector */ - st_fx->rate_switching_reset=lsp_convert_poly_fx( st_fx->lsp_old_fx, st_fx->L_frame, 0); + st_fx->rate_switching_reset = lsp_convert_poly_fx( st_fx->lsp_old_fx, st_fx->L_frame, 0 ); /* convert old quantized LSF vector */ lsp2lsf_fx( st_fx->lsp_old_fx, st_fx->lsf_old_fx, M, int_fs ); @@ -402,7 +410,7 @@ ivas_error acelp_core_dec_fx( Copy( st_fx->lsf_old_fx, st_fx->lsf_adaptive_mean_fx, M ); /* Reset LPC mem */ - IF( EQ_32(st_fx->sr_core, INT_FS_16k)) + IF( EQ_32( st_fx->sr_core, INT_FS_16k ) ) { Copy( GEWB2_Ave_fx, st_fx->mem_AR_fx, M ); } @@ -410,11 +418,11 @@ ivas_error acelp_core_dec_fx( { Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M ); } - set16_fx( st_fx->mem_MA_fx,0, M ); -#if 1//def IVAS_CODE + set16_fx( st_fx->mem_MA_fx, 0, M ); +#if 1 // def IVAS_CODE dec = DEC; move16(); - IF (NE_16(st_fx->element_mode, EVS_MONO)) + IF( NE_16( st_fx->element_mode, EVS_MONO ) ) { dec = DEC_IVAS; move16(); @@ -426,24 +434,23 @@ ivas_error acelp_core_dec_fx( synth_mem_updt2( st_fx->L_frame, st_fx->last_L_frame, st_fx->old_exc_fx, st_fx->mem_syn_r, st_fx->mem_syn2_fx, NULL, DEC ); #endif Copy( st_fx->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); - Copy_Scale_sig(st_fx->mem_syn2_fx, st_fx->mem_syn1_fx, M, sub(-1,st_fx->Q_syn)); /*Q-1*/ + Copy_Scale_sig( st_fx->mem_syn2_fx, st_fx->mem_syn1_fx, M, sub( -1, st_fx->Q_syn ) ); /*Q-1*/ Copy( st_fx->mem_syn2_fx, st_fx->mem_syn3_fx, M ); - } - IF( NE_16(st_fx->last_L_frame,st_fx->L_frame)) + IF( NE_16( st_fx->last_L_frame, st_fx->L_frame ) ) { /* update buffer of old subframe pitch values */ - IF( EQ_16(st_fx->L_frame,L_FRAME)) + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { move16(); - IF( EQ_16(st_fx->last_L_frame,L_FRAME32k)) + IF( EQ_16( st_fx->last_L_frame, L_FRAME32k ) ) { /* (float)12800/(float)32000; */ k = 13107; } - ELSE IF( EQ_16(st_fx->last_L_frame,512)) + ELSE IF( EQ_16( st_fx->last_L_frame, 512 ) ) { /* (float)12800/(float)25600; */ k = 16384; @@ -454,27 +461,27 @@ ivas_error acelp_core_dec_fx( k = 26214; } - FOR( i=NB_SUBFR16k-NB_SUBFR; iold_pitch_buf_fx[i-1] = Mpy_32_16_1(st_fx->old_pitch_buf_fx[i], k); + st_fx->old_pitch_buf_fx[i - 1] = Mpy_32_16_1( st_fx->old_pitch_buf_fx[i], k ); move32(); } - FOR( i=2*NB_SUBFR16k-NB_SUBFR; i<2*NB_SUBFR16k; i++ ) + FOR( i = 2 * NB_SUBFR16k - NB_SUBFR; i < 2 * NB_SUBFR16k; i++ ) { - st_fx->old_pitch_buf_fx[i-2] = Mpy_32_16_1(st_fx->old_pitch_buf_fx[i], k); + st_fx->old_pitch_buf_fx[i - 2] = Mpy_32_16_1( st_fx->old_pitch_buf_fx[i], k ); move32(); } } ELSE { move16(); - IF( EQ_16(st_fx->last_L_frame,L_FRAME32k)) + IF( EQ_16( st_fx->last_L_frame, L_FRAME32k ) ) { /* (float)16000/(float)32000; */ k = -16384; } - ELSE IF( EQ_16(st_fx->last_L_frame,512)) + ELSE IF( EQ_16( st_fx->last_L_frame, 512 ) ) { /* tmpF = (float)16000/(float)25600; */ k = -12288; @@ -485,17 +492,17 @@ ivas_error acelp_core_dec_fx( k = 8192; } - FOR( i=2*NB_SUBFR-1; i>=NB_SUBFR; i-- ) + FOR( i = 2 * NB_SUBFR - 1; i >= NB_SUBFR; i-- ) { - st_fx->old_pitch_buf_fx[i+2] = L_add(st_fx->old_pitch_buf_fx[i], Mpy_32_16_1(st_fx->old_pitch_buf_fx[i], k)); + st_fx->old_pitch_buf_fx[i + 2] = L_add( st_fx->old_pitch_buf_fx[i], Mpy_32_16_1( st_fx->old_pitch_buf_fx[i], k ) ); move32(); } - st_fx->old_pitch_buf_fx[NB_SUBFR+1] = st_fx->old_pitch_buf_fx[NB_SUBFR+2]; + st_fx->old_pitch_buf_fx[NB_SUBFR + 1] = st_fx->old_pitch_buf_fx[NB_SUBFR + 2]; move32(); - FOR( i=NB_SUBFR-1; i>=0; i-- ) + FOR( i = NB_SUBFR - 1; i >= 0; i-- ) { - st_fx->old_pitch_buf_fx[i+1] = L_add(st_fx->old_pitch_buf_fx[i], Mpy_32_16_1(st_fx->old_pitch_buf_fx[i], k)); + st_fx->old_pitch_buf_fx[i + 1] = L_add( st_fx->old_pitch_buf_fx[i], Mpy_32_16_1( st_fx->old_pitch_buf_fx[i], k ) ); move32(); } st_fx->old_pitch_buf_fx[0] = st_fx->old_pitch_buf_fx[1]; @@ -503,17 +510,17 @@ ivas_error acelp_core_dec_fx( } } - IF( NE_16(st_fx->bfi_pitch_frame, st_fx->L_frame)) + IF( NE_16( st_fx->bfi_pitch_frame, st_fx->L_frame ) ) { - IF( EQ_16(st_fx->L_frame,L_FRAME)) + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { move16(); - IF( EQ_16(st_fx->bfi_pitch_frame,L_FRAME32k)) + IF( EQ_16( st_fx->bfi_pitch_frame, L_FRAME32k ) ) { /* (float)12800/(float)32000; */ k = 13107; } - ELSE IF( EQ_16(st_fx->bfi_pitch_frame,512)) + ELSE IF( EQ_16( st_fx->bfi_pitch_frame, 512 ) ) { /* (float)12800/(float)25600; */ k = 16384; @@ -523,19 +530,19 @@ ivas_error acelp_core_dec_fx( /* (float)12800/(float)16000; */ k = 26214; } - st_fx->bfi_pitch_fx = mult_r(k, st_fx->bfi_pitch_fx); + st_fx->bfi_pitch_fx = mult_r( k, st_fx->bfi_pitch_fx ); st_fx->bfi_pitch_frame = L_FRAME; move16(); } ELSE { move16(); - IF( EQ_16(st_fx->bfi_pitch_frame,L_FRAME32k)) + IF( EQ_16( st_fx->bfi_pitch_frame, L_FRAME32k ) ) { /* (float)16000/(float)32000; */ k = -16384; } - ELSE IF( EQ_16(st_fx->bfi_pitch_frame,512)) + ELSE IF( EQ_16( st_fx->bfi_pitch_frame, 512 ) ) { /* tmpF = (float)16000/(float)25600; */ k = -12288; @@ -545,7 +552,7 @@ ivas_error acelp_core_dec_fx( /* tmpF = (float)16000/(float)12800; */ k = 8192; } - st_fx->bfi_pitch_fx = add(st_fx->bfi_pitch_fx, mult_r(st_fx->bfi_pitch_fx,k)); + st_fx->bfi_pitch_fx = add( st_fx->bfi_pitch_fx, mult_r( st_fx->bfi_pitch_fx, k ) ); st_fx->bfi_pitch_frame = L_FRAME16k; move16(); } @@ -553,9 +560,9 @@ ivas_error acelp_core_dec_fx( test(); test(); - if( EQ_16(st_fx->last_bwidth,NB)&&NE_16(st_fx->bwidth,NB)&&st_fx->ini_frame!=0) + if ( EQ_16( st_fx->last_bwidth, NB ) && NE_16( st_fx->bwidth, NB ) && st_fx->ini_frame != 0 ) { - st_fx->rate_switching_reset=1; + st_fx->rate_switching_reset = 1; move16(); } @@ -572,21 +579,21 @@ ivas_error acelp_core_dec_fx( tc_subfr_fx = -1; move16(); - if( EQ_16(st_fx->coder_type,TRANSITION)) + if ( EQ_16( st_fx->coder_type, TRANSITION ) ) { tc_subfr_fx = tc_classif_fx( st_fx, st_fx->L_frame ); move16(); } -#if 1//def IVAS_CODE +#if 1 // def IVAS_CODE /*----------------------------------------------------------------* * Decoding of GSC IVAS mode *----------------------------------------------------------------*/ st_fx->GSC_IVAS_mode = 0; - IF (GT_16(st_fx->element_mode, EVS_MONO) && st_fx->idchan == 0 && !(EQ_32(st_fx->core_brate, FRAME_NO_DATA) || EQ_32(st_fx->core_brate, SID_2k40)) && !tdm_low_rate_mode) + IF( GT_16( st_fx->element_mode, EVS_MONO ) && st_fx->idchan == 0 && !( EQ_32( st_fx->core_brate, FRAME_NO_DATA ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) && !tdm_low_rate_mode ) { - IF (EQ_16(st_fx->coder_type, AUDIO) || (EQ_16(st_fx->coder_type, INACTIVE) && LE_32(st_fx->total_brate, MAX_GSC_INACTIVE_BRATE))) + IF( EQ_16( st_fx->coder_type, AUDIO ) || ( EQ_16( st_fx->coder_type, INACTIVE ) && LE_32( st_fx->total_brate, MAX_GSC_INACTIVE_BRATE ) ) ) { - st_fx->GSC_IVAS_mode = get_next_indice(st_fx, 2); + st_fx->GSC_IVAS_mode = get_next_indice( st_fx, 2 ); } } #endif @@ -594,17 +601,17 @@ ivas_error acelp_core_dec_fx( * Decoding of inactive CNG frames *----------------------------------------------------------------*/ test(); - IF ( st_fx->core_brate == FRAME_NO_DATA || EQ_32(st_fx->core_brate,SID_2k40)) + IF( st_fx->core_brate == FRAME_NO_DATA || EQ_32( st_fx->core_brate, SID_2k40 ) ) { /* decode CNG parameters */ - IF ( EQ_16(st_fx->cng_type,LP_CNG)) + IF( EQ_16( st_fx->cng_type, LP_CNG ) ) { CNG_dec_fx( st_fx, st_fx->last_element_mode, Aq_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step_fx, sid_bw, q_env ); #ifdef IVAS_CODE local_element_mode = st_fx->element_mode; move16(); - IF ((EQ_16(nchan_out, 1) && EQ_16(st_fx->element_mode, IVAS_CPE_DFT)) || EQ_16(st_fx->masa_sid_format,1)) + IF( ( EQ_16( nchan_out, 1 ) && EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) ) || EQ_16( st_fx->masa_sid_format, 1 ) ) { local_element_mode = IVAS_SCE; /* For DFT Stereo mono decoding, run CNG_exc as in SCE */ move16(); @@ -612,50 +619,49 @@ ivas_error acelp_core_dec_fx( #endif /* comfort noise generation */ CNG_exc_fx( st_fx->core_brate, st_fx->L_frame, &st_fx->hTdCngDec->Enew_fx, &st_fx->hTdCngDec->cng_seed, exc_fx, exc2_fx, &st_fx->lp_ener_fx, st_fx->last_core_brate, - &st_fx->first_CNG, &(st_fx->hTdCngDec->cng_ener_seed), bwe_exc_fx, allow_cn_step_fx, &st_fx->hTdCngDec->last_allow_cn_step, st_fx->prev_Q_exc, st_fx->Q_exc, st_fx->hTdCngDec->num_ho, - q_env, st_fx->hTdCngDec->lp_env_fx, st_fx->hTdCngDec->old_env_fx, st_fx->hTdCngDec->exc_mem_fx, st_fx->hTdCngDec->exc_mem1_fx, sid_bw, &st_fx->hTdCngDec->cng_ener_seed1, exc3_fx ,st_fx->Opt_AMR_WB, st_fx->element_mode ); -#if 1//def IVAS_CODE - Copy(Aq_fx, st_fx->Aq_cng, M + 1); + &st_fx->first_CNG, &( st_fx->hTdCngDec->cng_ener_seed ), bwe_exc_fx, allow_cn_step_fx, &st_fx->hTdCngDec->last_allow_cn_step, st_fx->prev_Q_exc, st_fx->Q_exc, st_fx->hTdCngDec->num_ho, + q_env, st_fx->hTdCngDec->lp_env_fx, st_fx->hTdCngDec->old_env_fx, st_fx->hTdCngDec->exc_mem_fx, st_fx->hTdCngDec->exc_mem1_fx, sid_bw, &st_fx->hTdCngDec->cng_ener_seed1, exc3_fx, st_fx->Opt_AMR_WB, st_fx->element_mode ); +#if 1 // def IVAS_CODE + Copy( Aq_fx, st_fx->Aq_cng, M + 1 ); #endif - } ELSE { - IF( EQ_32(st_fx->core_brate,SID_2k40) && NE_16(st_fx->element_mode, IVAS_CPE_MDCT) ) + IF( EQ_32( st_fx->core_brate, SID_2k40 ) && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) { - FdCng_decodeSID_fx(st_fx->hFdCngDec->hFdCngCom, st_fx); - *sid_bw=0; + FdCng_decodeSID_fx( st_fx->hFdCngDec->hFdCngCom, st_fx ); + *sid_bw = 0; move16(); - } + } #ifdef IVAS_CODE - if (st->element_mode == IVAS_CPE_DFT) + if ( st->element_mode == IVAS_CPE_DFT ) { - assert(nchan_out == 1); + assert( nchan_out == 1 ); - for (i = 0; i < NPART; i++) + for ( i = 0; i < NPART; i++ ) { - st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] = STEREO_DFT_FD_FILT * st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] + (1 - STEREO_DFT_FD_FILT) * st->hFdCngDec->hFdCngCom->sidNoiseEst[i]; + st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] = STEREO_DFT_FD_FILT * st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] + ( 1 - STEREO_DFT_FD_FILT ) * st->hFdCngDec->hFdCngCom->sidNoiseEst[i]; } #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - ApplyFdCng_fx(syn, 0, NULL, realBuffer, imagBuffer, NULL, st, 0, (st->coder_type == AUDIO && !st->GSC_noisy_speech)); + ApplyFdCng_fx( syn, 0, NULL, realBuffer, imagBuffer, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); #else - ApplyFdCng_fx(syn, realBuffer, imagBuffer, st, 0, (st->coder_type == AUDIO && !st->GSC_noisy_speech)); + ApplyFdCng_fx( syn, realBuffer, imagBuffer, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); #endif } - if (!read_sid_info) + if ( !read_sid_info ) { float noise_lvl_highest; noise_lvl_highest = st->hFdCngDec->hFdCngCom->cngNoiseLevel[st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand - 1]; - for (int16_t b = st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand; b < st->hFdCngDec->hFdCngCom->stopBand; b++) + for ( int16_t b = st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand; b < st->hFdCngDec->hFdCngCom->stopBand; b++ ) { st->hFdCngDec->hFdCngCom->cngNoiseLevel[b] = noise_lvl_highest; } } #endif - generate_comfort_noise_dec_fx( NULL, NULL, NULL, st_fx, &(st_fx->Q_exc), 2, -1 ); + generate_comfort_noise_dec_fx( NULL, NULL, NULL, st_fx, &( st_fx->Q_exc ), 2, -1 ); - FdCng_exc(st_fx->hFdCngDec->hFdCngCom, &st_fx->CNG_mode, st_fx->L_frame, st_fx->lsp_old_fx, st_fx->first_CNG, st_fx->lspCNG_fx, Aq_fx, lsp_new_fx, lsf_new_fx, exc_fx, exc2_fx, bwe_exc_fx); + FdCng_exc( st_fx->hFdCngDec->hFdCngCom, &st_fx->CNG_mode, st_fx->L_frame, st_fx->lsp_old_fx, st_fx->first_CNG, st_fx->lspCNG_fx, Aq_fx, lsp_new_fx, lsf_new_fx, exc_fx, exc2_fx, bwe_exc_fx ); Copy( exc2_fx, exc3_fx, st_fx->L_frame ); } @@ -663,29 +669,29 @@ ivas_error acelp_core_dec_fx( delta_mem_scale = 3; move16(); test(); - if( LT_32(st_fx->lp_ener_fx,40)&&EQ_16(st_fx->cng_type,LP_CNG)) /* very low energy frames, less than 0.3125 */ + if ( LT_32( st_fx->lp_ener_fx, 40 ) && EQ_16( st_fx->cng_type, LP_CNG ) ) /* very low energy frames, less than 0.3125 */ { delta_mem_scale = 0; move16(); } i = st_fx->Q_exc; - Rescale_exc(hMusicPF->dct_post_old_exc_fx, exc_fx, bwe_exc_fx, st_fx->hGSCDec->last_exc_dct_in_fx, st_fx->L_frame, - st_fx->L_frame* HIBND_ACB_L_FAC, 0, &(st_fx->Q_exc), st_fx->Q_subfr, NULL, 0, INACTIVE); + Rescale_exc( hMusicPF->dct_post_old_exc_fx, exc_fx, bwe_exc_fx, st_fx->hGSCDec->last_exc_dct_in_fx, st_fx->L_frame, + st_fx->L_frame * HIBND_ACB_L_FAC, 0, &( st_fx->Q_exc ), st_fx->Q_subfr, NULL, 0, INACTIVE ); Rescale_mem( st_fx->Q_exc, &st_fx->prev_Q_syn, &st_fx->Q_syn, st_fx->mem_syn2_fx, st_fx->mem_syn_clas_estim_fx, delta_mem_scale, - &st_fx->mem_deemph_fx, hBPF->pst_old_syn_fx,&hBPF->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], st_fx->hPFstat, 0, 0, NULL ); - Copy_Scale_sig(exc2_fx, exc2_fx, st_fx->L_frame, sub(st_fx->Q_exc, i)); + &st_fx->mem_deemph_fx, hBPF->pst_old_syn_fx, &hBPF->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], st_fx->hPFstat, 0, 0, NULL ); + Copy_Scale_sig( exc2_fx, exc2_fx, st_fx->L_frame, sub( st_fx->Q_exc, i ) ); /* update past excitation signals for LD music post-filter */ - IF(hMusicPF != NULL) + IF( hMusicPF != NULL ) { - Copy(hMusicPF->dct_post_old_exc_fx + L_FRAME, hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2); - Copy(exc2_fx, hMusicPF->dct_post_old_exc_fx + (DCT_L_POST - L_FRAME - OFFSET2), L_FRAME); + Copy( hMusicPF->dct_post_old_exc_fx + L_FRAME, hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2 ); + Copy( exc2_fx, hMusicPF->dct_post_old_exc_fx + ( DCT_L_POST - L_FRAME - OFFSET2 ), L_FRAME ); /* Update music post processing values */ /* Filter energies update */ - FOR(i = 0; i < DCT_L_POST; i++) + FOR( i = 0; i < DCT_L_POST; i++ ) { /*st_fx->filt_lfE_fx[i] = 0.3f + 0.7f * st_fx->filt_lfE_fx[i];*/ - hMusicPF->filt_lfE_fx[i] = round_fx(L_mac((1228 << (16)), 22938, hMusicPF->filt_lfE_fx[i])); + hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( ( 1228 << ( 16 ) ), 22938, hMusicPF->filt_lfE_fx[i] ) ); } } /* synthesis at 12.8kHz sampling rate */ @@ -703,10 +709,10 @@ ivas_error acelp_core_dec_fx( /* save and delay synthesis to be used by SWB BWE */ - Copy_Scale_sig( syn1_fx, temp_buf_fx, st_fx->L_frame, sub(-1,st_fx->Q_syn)); - IF (hBWE_FD != NULL) + Copy_Scale_sig( syn1_fx, temp_buf_fx, st_fx->L_frame, sub( -1, st_fx->Q_syn ) ); + IF( hBWE_FD != NULL ) { - save_old_syn_fx(st_fx->L_frame, temp_buf_fx, old_syn_12k8_16k, hBWE_FD->old_syn_12k8_16k_fx, st_fx->preemph_fac, &hBWE_FD->mem_deemph_old_syn_fx); + save_old_syn_fx( st_fx->L_frame, temp_buf_fx, old_syn_12k8_16k, hBWE_FD->old_syn_12k8_16k_fx, st_fx->preemph_fac, &hBWE_FD->mem_deemph_old_syn_fx ); } } @@ -722,32 +728,36 @@ ivas_error acelp_core_dec_fx( nb_bits = 0; st_fx->acelp_cfg.FEC_mode = 0; uc_two_stage_flag = 0; - move16(); move16(); move16(); + move16(); + move16(); + move16(); test(); - IF (!st_fx->nelp_mode_dec && !st_fx->ppp_mode_dec) + IF( !st_fx->nelp_mode_dec && !st_fx->ppp_mode_dec ) { Word16 tc_subfr_tmp; tc_subfr_tmp = tc_subfr_fx; move16(); - IF (LT_16(tc_subfr_tmp, L_SUBFR)) + IF( LT_16( tc_subfr_tmp, L_SUBFR ) ) { tc_subfr_tmp = 0; move16(); } - IF (EQ_16(tc_subfr_fx, TC_0_192)) + IF( EQ_16( tc_subfr_fx, TC_0_192 ) ) { nb_bits = -1; move16(); } - config_acelp1(DEC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl_orig, st_fx->extl_brate_orig, st_fx->L_frame, st_fx->GSC_noisy_speech, &(st_fx->acelp_cfg), st_fx->next_bit_pos, st_fx->coder_type, tc_subfr_tmp, 1, &nb_bits, unbits, st_fx->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st_fx->idchan, st_fx->active_cnt, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode); + config_acelp1( DEC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl_orig, st_fx->extl_brate_orig, st_fx->L_frame, st_fx->GSC_noisy_speech, &( st_fx->acelp_cfg ), st_fx->next_bit_pos, st_fx->coder_type, tc_subfr_tmp, 1, &nb_bits, unbits, st_fx->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st_fx->idchan, st_fx->active_cnt, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode ); - test(); test(); test(); - IF (EQ_16(st_fx->coder_type, TRANSITION) && LT_16(tc_subfr_fx, L_SUBFR) && EQ_16(st_fx->L_frame, L_FRAME)) + test(); + test(); + test(); + IF( EQ_16( st_fx->coder_type, TRANSITION ) && LT_16( tc_subfr_fx, L_SUBFR ) && EQ_16( st_fx->L_frame, L_FRAME ) ) { - config_acelp1(DEC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl_orig, st_fx->extl_brate_orig, st_fx->L_frame, -1, &(st_fx->acelp_cfg), st_fx->next_bit_pos, st_fx->coder_type, tc_subfr_fx, 2, &nb_bits, unbits, st_fx->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st_fx->idchan, st_fx->active_cnt, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode); + config_acelp1( DEC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl_orig, st_fx->extl_brate_orig, st_fx->L_frame, -1, &( st_fx->acelp_cfg ), st_fx->next_bit_pos, st_fx->coder_type, tc_subfr_fx, 2, &nb_bits, unbits, st_fx->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st_fx->idchan, st_fx->active_cnt, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode ); } } @@ -755,8 +765,9 @@ ivas_error acelp_core_dec_fx( * After CNG period, use the most up-to-date LSPs *-----------------------------------------------------------------*/ - test(); test(); - IF (st_fx->hTdCngDec != NULL && (st_fx->last_core_brate == FRAME_NO_DATA || EQ_32(st_fx->last_core_brate,SID_2k40))) + test(); + test(); + IF( st_fx->hTdCngDec != NULL && ( st_fx->last_core_brate == FRAME_NO_DATA || EQ_32( st_fx->last_core_brate, SID_2k40 ) ) ) { Copy( st_fx->lspCNG_fx, st_fx->lsp_old_fx, M ); @@ -786,85 +797,86 @@ ivas_error acelp_core_dec_fx( * LSF de-quantization and interpolation *-----------------------------------------------------------------*/ #ifdef ADD_LRTD - if (!tdm_lp_reuse_flag) + if ( !tdm_lp_reuse_flag ) #endif { - lsf_dec_fx( st_fx, tc_subfr_fx, Aq_fx,&LSF_Q_prediction, lsf_new_fx, lsp_new_fx, lsp_mid_fx, tdm_low_rate_mode + lsf_dec_fx( st_fx, tc_subfr_fx, Aq_fx, &LSF_Q_prediction, lsf_new_fx, lsp_new_fx, lsp_mid_fx, tdm_low_rate_mode #ifdef LSF_RE_USE_SECONDARY_CHANNEL - ,tdm_lsfQ_PCh + , + tdm_lsfQ_PCh #endif - ); + ); } #ifdef ADD_LRTD else { - const float* pt_interp_2; + const float *pt_interp_2; #ifdef LSF_RE_USE_SECONDARY_CHANNEL - if (st->active_cnt != 1) + if ( st->active_cnt != 1 ) { int16_t beta_index; - beta_index = get_next_indice(st, TDM_IC_LSF_PRED_BITS); - tdm_SCh_lsf_reuse(DEC, st->element_brate, lsf_new, lsp_new, tdm_lsfQ_PCh, NULL, &beta_index); + beta_index = get_next_indice( st, TDM_IC_LSF_PRED_BITS ); + tdm_SCh_lsf_reuse( DEC, st->element_brate, lsf_new, lsp_new, tdm_lsfQ_PCh, NULL, &beta_index ); } else { - mvr2r(tdm_lspQ_PCh, lsp_new, M); - mvr2r(tdm_lsfQ_PCh, lsf_new, M); + mvr2r( tdm_lspQ_PCh, lsp_new, M ); + mvr2r( tdm_lsfQ_PCh, lsf_new, M ); } #else - mvr2r(tdm_lspQ_PCh, lsp_new, M); - mvr2r(tdm_lsfQ_PCh, lsf_new, M); + mvr2r( tdm_lspQ_PCh, lsp_new, M ); + mvr2r( tdm_lsfQ_PCh, lsf_new, M ); #endif - if (st->rate_switching_reset) + if ( st->rate_switching_reset ) { /* extrapolation in case of unstable LSF convert */ - mvr2r(lsp_new, st->lsp_old, M); - mvr2r(lsf_new, st->lsf_old, M); + mvr2r( lsp_new, st->lsp_old, M ); + mvr2r( lsf_new, st->lsf_old, M ); } pt_interp_2 = interpol_frac_12k8; - if (tdm_low_rate_mode == 1 && st->coder_type > UNVOICED) + if ( tdm_low_rate_mode == 1 && st->coder_type > UNVOICED ) { pt_interp_2 = interpol_frac2; } - if (st->active_cnt == 1) + if ( st->active_cnt == 1 ) { - mvr2r(lsp_new, st->lsp_old, M); - lsp2lsf(lsp_new, st->lsf_old, M, st->sr_core); + mvr2r( lsp_new, st->lsp_old, M ); + lsp2lsf( lsp_new, st->lsf_old, M, st->sr_core ); } /* LSP interpolation and conversion of LSPs to A(z) */ - int_lsp(st->L_frame, st->lsp_old, lsp_new, Aq, M, pt_interp_2, 0); + int_lsp( st->L_frame, st->lsp_old, lsp_new, Aq, M, pt_interp_2, 0 ); /* Check LSF stability (distance between old LSFs and current LSFs) */ - st->stab_fac = lsf_stab(lsf_new, st->lsf_old, 0, st->L_frame); + st->stab_fac = lsf_stab( lsf_new, st->lsf_old, 0, st->L_frame ); } - if (st->last_core == HQ_CORE && st->element_mode > EVS_MONO) + if ( st->last_core == HQ_CORE && st->element_mode > EVS_MONO ) { /* Prepare ACB memory from last HQ frame */ old_exc_s = st->old_exc + L_EXC_MEM_DEC - st->L_frame; tmpF = *old_exc_s; st->mem_deemph = old_exc_s[st->L_frame - 1]; - preemph(old_exc_s, st->preemph_fac, L_FRAME16k, &tmpF); - mvr2r(old_exc_s + st->L_frame - M, st->mem_syn2, M); - residu(Aq, M, old_exc_s, old_exc + L_EXC_MEM_DEC - st->L_frame, st->L_frame); + preemph( old_exc_s, st->preemph_fac, L_FRAME16k, &tmpF ); + mvr2r( old_exc_s + st->L_frame - M, st->mem_syn2, M ); + residu( Aq, M, old_exc_s, old_exc + L_EXC_MEM_DEC - st->L_frame, st->L_frame ); } - if (st->last_core != ACELP_CORE && st->element_mode > EVS_MONO) + if ( st->last_core != ACELP_CORE && st->element_mode > EVS_MONO ) { /* Prepare ACB memory of old_bwe_exc */ #ifdef CR_FIX_639_HQ_ACELP_TRANSITION - if (st->L_frame == L_FRAME) + if ( st->L_frame == L_FRAME ) { - lerp(old_exc, old_bwe_exc, L_EXC_MEM_DEC * HIBND_ACB_L_FAC, L_EXC_MEM_DEC); + lerp( old_exc, old_bwe_exc, L_EXC_MEM_DEC * HIBND_ACB_L_FAC, L_EXC_MEM_DEC ); } else { - lerp(old_exc, old_bwe_exc, L_EXC_MEM_DEC * 2, L_EXC_MEM_DEC); + lerp( old_exc, old_bwe_exc, L_EXC_MEM_DEC * 2, L_EXC_MEM_DEC ); } #else - lerp(old_exc, old_bwe_exc, L_EXC_MEM_DEC * HIBND_ACB_L_FAC, L_EXC_MEM_DEC); + lerp( old_exc, old_bwe_exc, L_EXC_MEM_DEC * HIBND_ACB_L_FAC, L_EXC_MEM_DEC ); #endif } #endif @@ -872,18 +884,18 @@ ivas_error acelp_core_dec_fx( * FEC - first good frame after lost frame(s) (possibility to correct the ACB) *-----------------------------------------------------------------*/ - IF( st_fx->acelp_cfg.FEC_mode > 0) + IF( st_fx->acelp_cfg.FEC_mode > 0 ) { last_pulse_pos = 0; move16(); /* decode the last glottal pulse position */ - T0_tmp = FEC_pos_dec_fx( st_fx, &last_pulse_pos, &enr_q_fx, nb_bits); + T0_tmp = FEC_pos_dec_fx( st_fx, &last_pulse_pos, &enr_q_fx, nb_bits ); move16(); test(); test(); - IF( NE_16(st_fx->last_core,HQ_CORE)||(EQ_16(st_fx->last_core,HQ_CORE)&&st_fx->last_con_tcx)) + IF( NE_16( st_fx->last_core, HQ_CORE ) || ( EQ_16( st_fx->last_core, HQ_CORE ) && st_fx->last_con_tcx ) ) { test(); test(); @@ -891,14 +903,14 @@ ivas_error acelp_core_dec_fx( test(); test(); test(); - IF( EQ_16(st_fx->clas_dec,SIN_ONSET)&&last_pulse_pos!=0&&EQ_16(st_fx->prev_bfi,1)) + IF( EQ_16( st_fx->clas_dec, SIN_ONSET ) && last_pulse_pos != 0 && EQ_16( st_fx->prev_bfi, 1 ) ) { st_fx->Q_exc = - FEC_SinOnset_fx( old_exc_fx+L_EXC_MEM_DEC-L_EXC_MEM, last_pulse_pos, T0_tmp, enr_q_fx, Aq_fx, st_fx->L_frame, st_fx->Q_exc ); + FEC_SinOnset_fx( old_exc_fx + L_EXC_MEM_DEC - L_EXC_MEM, last_pulse_pos, T0_tmp, enr_q_fx, Aq_fx, st_fx->L_frame, st_fx->Q_exc ); } - ELSE IF( (EQ_16(st_fx->coder_type,GENERIC) || EQ_16(st_fx->coder_type,VOICED)) && last_pulse_pos!=0 && EQ_16(st_fx->old_bfi_cnt,1) && EQ_16(output_frame,L_FRAME16k) && st_fx->hWIDec != NULL) + ELSE IF( ( EQ_16( st_fx->coder_type, GENERIC ) || EQ_16( st_fx->coder_type, VOICED ) ) && last_pulse_pos != 0 && EQ_16( st_fx->old_bfi_cnt, 1 ) && EQ_16( output_frame, L_FRAME16k ) && st_fx->hWIDec != NULL ) { - do_WI_fx = FEC_enhACB_fx( st_fx->L_frame, st_fx->last_L_frame, old_exc_fx+L_EXC_MEM_DEC-L_EXC_MEM , T0_tmp, last_pulse_pos, st_fx->bfi_pitch_fx ); + do_WI_fx = FEC_enhACB_fx( st_fx->L_frame, st_fx->last_L_frame, old_exc_fx + L_EXC_MEM_DEC - L_EXC_MEM, T0_tmp, last_pulse_pos, st_fx->bfi_pitch_fx ); } } } @@ -911,38 +923,40 @@ ivas_error acelp_core_dec_fx( test(); test(); test(); - IF( st_fx->stab_fac_fx == 0 && st_fx->old_bfi_cnt > 0 && NE_16(st_fx->clas_dec,VOICED_CLAS) && NE_16(st_fx->clas_dec,ONSET) && - st_fx->relax_prev_lsf_interp==0 && !(EQ_16(st_fx->element_mode, IVAS_CPE_TD) && EQ_16(st_fx->idchan, 1))) + IF( st_fx->stab_fac_fx == 0 && st_fx->old_bfi_cnt > 0 && NE_16( st_fx->clas_dec, VOICED_CLAS ) && NE_16( st_fx->clas_dec, ONSET ) && + st_fx->relax_prev_lsf_interp == 0 && !( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && EQ_16( st_fx->idchan, 1 ) ) ) { - int_lsp4_fx(st_fx->L_frame, st_fx->lsp_old_fx, lsp_mid_fx, lsp_new_fx, Aq_fx, M, 2 ); + int_lsp4_fx( st_fx->L_frame, st_fx->lsp_old_fx, lsp_mid_fx, lsp_new_fx, Aq_fx, M, 2 ); } /*---------------------------------------------------------------* * Decoding of the scaled predicted innovation energy *---------------------------------------------------------------*/ - IF (nb_bits > 0) + IF( nb_bits > 0 ) { - indice = get_next_indice(st_fx, nb_bits); - Es_pred_dec_fx( &Es_pred_fx, indice, nb_bits, uc_two_stage_flag); + indice = get_next_indice( st_fx, nb_bits ); + Es_pred_dec_fx( &Es_pred_fx, indice, nb_bits, uc_two_stage_flag ); } /*------------------------------------------------------------* - * Decode excitation according to coding type - *------------------------------------------------------------*/ - test(); test(); test(); + * Decode excitation according to coding type + *------------------------------------------------------------*/ + test(); + test(); + test(); #ifdef ADD_LRTD - IF (tdm_low_rate_mode) /* tdm stereo low rate mode */ + IF( tdm_low_rate_mode ) /* tdm stereo low rate mode */ { - IF (LE_16(st_fx->coder_type, UNVOICED)) + IF( LE_16( st_fx->coder_type, UNVOICED ) ) { - tdm_low_rate_dec(st_fx, dct_exc_tmp, &tmp_noise, pitch_buf, voice_factors, exc, exc2, bwe_exc, lsf_new); + tdm_low_rate_dec( st_fx, dct_exc_tmp, &tmp_noise, pitch_buf, voice_factors, exc, exc2, bwe_exc, lsf_new ); } ELSE /* GENERIC */ { - decod_gen_2sbfr(st_fx, sharpFlag, Aq, pitch_buf, voice_factors, exc, exc2, bwe_exc, gain_buf, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf); + decod_gen_2sbfr( st_fx, sharpFlag, Aq, pitch_buf, voice_factors, exc, exc2, bwe_exc, gain_buf, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf ); - IF (EQ_16(st_fx->element_mode, IVAS_CPE_TD)) + IF( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) { tmp_noise = st_fx->lp_gainc_fx; move16(); @@ -951,65 +965,66 @@ ivas_error acelp_core_dec_fx( } else #endif - IF( EQ_16(st_fx->nelp_mode_dec,1)) + IF( EQ_16( st_fx->nelp_mode_dec, 1 ) ) { /* SC-VBR - NELP frames */ - Scale_sig(exc_fx-L_EXC_MEM, L_EXC_MEM, -st_fx->Q_exc); + Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, -st_fx->Q_exc ); st_fx->Q_exc = 0; move16(); - decod_nelp_fx( st_fx, &tmp_noise_fx, pitch_buf_fx, exc_fx, exc2_fx,voice_factors, bwe_exc_fx, &st_fx->Q_exc, st_fx->bfi, gain_buf ); - Rescale_exc(hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st_fx->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32)0, &(st_fx->Q_exc), st_fx->Q_subfr, exc2_fx, L_FRAME, st_fx->coder_type); + decod_nelp_fx( st_fx, &tmp_noise_fx, pitch_buf_fx, exc_fx, exc2_fx, voice_factors, bwe_exc_fx, &st_fx->Q_exc, st_fx->bfi, gain_buf ); + Rescale_exc( hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st_fx->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32) 0, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, L_FRAME, st_fx->coder_type ); } - ELSE IF( EQ_16(st_fx->coder_type,UNVOICED)) + ELSE IF( EQ_16( st_fx->coder_type, UNVOICED ) ) { /* UNVOICED frames */ decod_unvoiced_fx( st_fx, Aq_fx, st_fx->coder_type, &tmp_noise_fx, pitch_buf_fx, voice_factors, exc_fx, exc2_fx, bwe_exc_fx, gain_buf ); } - ELSE IF ( EQ_16(st_fx->ppp_mode_dec,1)) + ELSE IF( EQ_16( st_fx->ppp_mode_dec, 1 ) ) { - Scale_sig(exc_fx-L_EXC_MEM, L_EXC_MEM, -st_fx->Q_exc); + Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, -st_fx->Q_exc ); st_fx->Q_exc = 0; /* SC-VBR - PPP frames */ - IF ((error = decod_ppp_fx( st_fx, Aq_fx, pitch_buf_fx, exc_fx, exc2_fx, st_fx->bfi, gain_buf, voice_factors, bwe_exc_fx )) != IVAS_ERR_OK) + IF( ( error = decod_ppp_fx( st_fx, Aq_fx, pitch_buf_fx, exc_fx, exc2_fx, st_fx->bfi, gain_buf, voice_factors, bwe_exc_fx ) ) != IVAS_ERR_OK ) { return error; } - Rescale_exc(hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st_fx->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32)0, &(st_fx->Q_exc), st_fx->Q_subfr, exc2_fx, L_FRAME, st_fx->coder_type ); + Rescale_exc( hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st_fx->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32) 0, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, L_FRAME, st_fx->coder_type ); } - ELSE IF( EQ_16(st_fx->coder_type,TRANSITION )) + ELSE IF( EQ_16( st_fx->coder_type, TRANSITION ) ) { decod_tran_fx( st_fx, st_fx->L_frame, tc_subfr_fx, Aq_fx, Es_pred_fx, pitch_buf_fx, voice_factors, exc_fx, exc2_fx, bwe_exc_fx, unbits, sharpFlag, gain_buf ); } - ELSE IF( EQ_16(st_fx->coder_type,AUDIO) || (EQ_16(st_fx->coder_type,INACTIVE) && LE_32(st_fx->core_brate, MAX_GSC_INACTIVE_BRATE))) + ELSE IF( EQ_16( st_fx->coder_type, AUDIO ) || ( EQ_16( st_fx->coder_type, INACTIVE ) && LE_32( st_fx->core_brate, MAX_GSC_INACTIVE_BRATE ) ) ) { - decod_audio_fx( st_fx, dct_exc_tmp, Aq_fx, pitch_buf_fx, voice_factors, exc_fx, exc2_fx, bwe_exc_fx, lsf_new_fx, gain_buf + decod_audio_fx( st_fx, dct_exc_tmp, Aq_fx, pitch_buf_fx, voice_factors, exc_fx, exc2_fx, bwe_exc_fx, lsf_new_fx, gain_buf #ifdef ADD_LRTD - , tdm_lp_reuse_flag, tdm_low_rate_mode, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf + , + tdm_lp_reuse_flag, tdm_low_rate_mode, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf #endif ); - tmp_noise_fx = shr_r(st_fx->lp_gainc_fx,3); /*Q0*/ + tmp_noise_fx = shr_r( st_fx->lp_gainc_fx, 3 ); /*Q0*/ } ELSE { - IF ((error = decod_gen_voic_fx(st_fx, st_fx->L_frame, sharpFlag, Aq_fx, Es_pred_fx, do_WI_fx, pitch_buf_fx, voice_factors, exc_fx, exc2_fx, bwe_exc_fx, unbits, gain_buf/*, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf*/)) != IVAS_ERR_OK) + IF( ( error = decod_gen_voic_fx( st_fx, st_fx->L_frame, sharpFlag, Aq_fx, Es_pred_fx, do_WI_fx, pitch_buf_fx, voice_factors, exc_fx, exc2_fx, bwe_exc_fx, unbits, gain_buf /*, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf*/ ) ) != IVAS_ERR_OK ) { return error; } - IF (EQ_16(st_fx->element_mode, IVAS_CPE_TD)) + IF( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) { - tmp_noise_fx = shr_r(st_fx->lp_gainc_fx, 3); /*Q0*/ + tmp_noise_fx = shr_r( st_fx->lp_gainc_fx, 3 ); /*Q0*/ } } /* synthesis for ACELP core switching and SWB BWE */ syn_12k8_fx( st_fx->L_frame, Aq_fx, exc_fx, temp_buf_fx, st_fx->mem_syn1_fx, 1, st_fx->Q_exc, -1 ); /* save and delay synthesis to be used by SWB BWE */ - IF (hBWE_FD != NULL) + IF( hBWE_FD != NULL ) { - save_old_syn_fx(st_fx->L_frame, temp_buf_fx, old_syn_12k8_16k, hBWE_FD->old_syn_12k8_16k_fx, st_fx->preemph_fac, &hBWE_FD->mem_deemph_old_syn_fx); + save_old_syn_fx( st_fx->L_frame, temp_buf_fx, old_syn_12k8_16k, hBWE_FD->old_syn_12k8_16k_fx, st_fx->preemph_fac, &hBWE_FD->mem_deemph_old_syn_fx ); } /*-----------------------------------------------------------------* @@ -1020,10 +1035,12 @@ ivas_error acelp_core_dec_fx( /*------------------------------------------------------------* * Decode information and modify the excitation signal of stationary unvoiced frames *------------------------------------------------------------*/ - test(); test(); test(); - IF (!(EQ_16(st_fx->idchan, 1) && EQ_16(st_fx->element_mode, IVAS_CPE_TD)) && NE_16(st_fx->nelp_mode_dec, 1) && !(EQ_16(st_fx->element_mode, IVAS_SCE) && tdm_low_rate_mode)) + test(); + test(); + test(); + IF( !( EQ_16( st_fx->idchan, 1 ) && EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) && NE_16( st_fx->nelp_mode_dec, 1 ) && !( EQ_16( st_fx->element_mode, IVAS_SCE ) && tdm_low_rate_mode ) ) { - stat_noise_uv_dec_fx( st_fx, lsp_new_fx, lsp_mid_fx, Aq_fx, exc2_fx, uc_two_stage_flag); + stat_noise_uv_dec_fx( st_fx, lsp_new_fx, lsp_mid_fx, Aq_fx, exc2_fx, uc_two_stage_flag ); } /*------------------------------------------------------------* @@ -1032,46 +1049,46 @@ ivas_error acelp_core_dec_fx( *------------------------------------------------------------*/ /* update past excitation signals for LD music post-filter */ - IF(hMusicPF != NULL) + IF( hMusicPF != NULL ) { - Copy(hMusicPF->dct_post_old_exc_fx + L_FRAME, hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2); - Copy(exc2_fx, hMusicPF->dct_post_old_exc_fx + (DCT_L_POST - L_FRAME - OFFSET2), L_FRAME); - Copy(hMusicPF->dct_post_old_exc_fx, exc_buffer_fx, DCT_L_POST - OFFSET2); + Copy( hMusicPF->dct_post_old_exc_fx + L_FRAME, hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2 ); + Copy( exc2_fx, hMusicPF->dct_post_old_exc_fx + ( DCT_L_POST - L_FRAME - OFFSET2 ), L_FRAME ); + Copy( hMusicPF->dct_post_old_exc_fx, exc_buffer_fx, DCT_L_POST - OFFSET2 ); } test(); - IF(hMusicPF != NULL && ((EQ_16(st_fx->coder_type, AUDIO) && EQ_16(st_fx->GSC_noisy_speech, 0)) || (GE_16(st_fx->GSC_IVAS_mode, 1) && EQ_16(st_fx->L_frame, L_FRAME)))) + IF( hMusicPF != NULL && ( ( EQ_16( st_fx->coder_type, AUDIO ) && EQ_16( st_fx->GSC_noisy_speech, 0 ) ) || ( GE_16( st_fx->GSC_IVAS_mode, 1 ) && EQ_16( st_fx->L_frame, L_FRAME ) ) ) ) { Word16 last_coder_type = st_fx->last_coder_type; - if ( (EQ_16(st_fx->idchan, 1) && EQ_16(st_fx->element_mode, IVAS_CPE_TD)) || (GE_16(st_fx->GSC_IVAS_mode, 1) && st_fx->GSC_noisy_speech == 0)) + if ( ( EQ_16( st_fx->idchan, 1 ) && EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) || ( GE_16( st_fx->GSC_IVAS_mode, 1 ) && st_fx->GSC_noisy_speech == 0 ) ) { last_coder_type = AUDIO; } /* Extrapolation of the last future part, windowing and high resolution DCT transform */ qdct = 0; -#ifdef _DIFF_FLOAT_FIX_ /* FLoat point using last_core which fits with the inner part of the function */ - Prep_music_postP_fx(exc_buffer_fx, dct_buffer_fx, hMusicPF->filt_lfE_fx, st_fx->last_core, st_fx->element_mode, pitch_buf_fx, - hMusicPF->LDm_enh_lp_gbin_fx, st_fx->Q_exc, &qdct); +#ifdef _DIFF_FLOAT_FIX_ /* FLoat point using last_core which fits with the inner part of the function */ + Prep_music_postP_fx( exc_buffer_fx, dct_buffer_fx, hMusicPF->filt_lfE_fx, st_fx->last_core, st_fx->element_mode, pitch_buf_fx, + hMusicPF->LDm_enh_lp_gbin_fx, st_fx->Q_exc, &qdct ); #else - Prep_music_postP_fx( exc_buffer_fx, dct_buffer_fx, hMusicPF->filt_lfE_fx, st_fx->last_coder_type, st_fx->element_mode, pitch_buf_fx, - hMusicPF->LDm_enh_lp_gbin_fx, st_fx->Q_exc, &qdct ); + Prep_music_postP_fx( exc_buffer_fx, dct_buffer_fx, hMusicPF->filt_lfE_fx, st_fx->last_coder_type, st_fx->element_mode, pitch_buf_fx, + hMusicPF->LDm_enh_lp_gbin_fx, st_fx->Q_exc, &qdct ); #endif /* LD music post-filter */ - LD_music_post_filter_fx( hMusicPF, dct_buffer_fx, dct_buffer_fx, st_fx->core_brate, - &hMusicPF->Old_ener_Q, AUDIO, last_coder_type, qdct ); + LD_music_post_filter_fx( hMusicPF, dct_buffer_fx, dct_buffer_fx, st_fx->core_brate, + &hMusicPF->Old_ener_Q, AUDIO, last_coder_type, qdct ); /* Inverse DCT transform, retrieval of the aligned excitation, re-synthesis */ Post_music_postP_fx( dct_buffer_fx, exc2_fx, st_fx->mem_syn2_fx, st_fx->mem_syn2_fx, Aq_fx, syn_fx, &st_fx->Q_exc, &st_fx->prev_Q_syn, - &st_fx->Q_syn, st_fx->mem_syn_clas_estim_fx,0, &st_fx->mem_deemph_fx, hBPF->pst_old_syn_fx, - &hBPF->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], st_fx->hPFstat, temp_buf_fx, mem_tmp_fx ); + &st_fx->Q_syn, st_fx->mem_syn_clas_estim_fx, 0, &st_fx->mem_deemph_fx, hBPF->pst_old_syn_fx, + &hBPF->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], st_fx->hPFstat, temp_buf_fx, mem_tmp_fx ); } ELSE { /* Core synthesis at 12.8kHz or 16kHz */ i = 1; move16(); - if( EQ_16(st_fx->coder_type,INACTIVE)) + if ( EQ_16( st_fx->coder_type, INACTIVE ) ) { i = 0; move16(); @@ -1081,23 +1098,23 @@ ivas_error acelp_core_dec_fx( move16(); test(); test(); - if( EQ_16(st_fx->coder_type, INACTIVE)&&st_fx->flag_cna&&GE_16(round_fx(L_shl(st_fx->lp_noise,1)),15<<7)) + if ( EQ_16( st_fx->coder_type, INACTIVE ) && st_fx->flag_cna && GE_16( round_fx( L_shl( st_fx->lp_noise, 1 ) ), 15 << 7 ) ) { k = 1; move16(); } Rescale_mem( st_fx->Q_exc, &st_fx->prev_Q_syn, &st_fx->Q_syn, st_fx->mem_syn2_fx, st_fx->mem_syn_clas_estim_fx, 4, &st_fx->mem_deemph_fx, - hBPF->pst_old_syn_fx, &hBPF->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], st_fx->hPFstat, i, k, temp_buf_fx ); + hBPF->pst_old_syn_fx, &hBPF->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], st_fx->hPFstat, i, k, temp_buf_fx ); Copy( st_fx->mem_syn2_fx, mem_tmp_fx, M ); - syn_12k8_fx( st_fx->L_frame, Aq_fx, exc2_fx, syn_fx, st_fx->mem_syn2_fx, 1 , st_fx->Q_exc, st_fx->Q_syn); - IF(hMusicPF != NULL) + syn_12k8_fx( st_fx->L_frame, Aq_fx, exc2_fx, syn_fx, st_fx->mem_syn2_fx, 1, st_fx->Q_exc, st_fx->Q_syn ); + IF( hMusicPF != NULL ) { - FOR(i = 0; i < DCT_L_POST; i++) + FOR( i = 0; i < DCT_L_POST; i++ ) { /*st_fx->filt_lfE_fx[i] = 0.3f + 0.7f * st_fx->filt_lfE_fx[i];*/ - hMusicPF->filt_lfE_fx[i] = round_fx(L_mac((1228 << (16)), 22938, hMusicPF->filt_lfE_fx[i])); + hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( ( 1228 << ( 16 ) ), 22938, hMusicPF->filt_lfE_fx[i] ) ); } } } @@ -1107,17 +1124,17 @@ ivas_error acelp_core_dec_fx( *------------------------------------------------------------*/ FEC_clas_estim_fx( st_fx, st_fx->Opt_AMR_WB, st_fx->L_frame, &st_fx->clas_dec, st_fx->coder_type, pitch_buf_fx, - syn_fx, &st_fx->lp_ener_FER_fx, &st_fx->decision_hyst, - NULL, NULL, NULL, NULL, 0, NULL, st_fx->core_brate, st_fx->Q_syn, temp_buf_fx, - st_fx->mem_syn_clas_estim_fx, &st_fx->classifier_Q_mem_syn, - 0, 0, 0, st_fx->last_core_brate, st_fx->acelp_cfg.FEC_mode); + syn_fx, &st_fx->lp_ener_FER_fx, &st_fx->decision_hyst, + NULL, NULL, NULL, NULL, 0, NULL, st_fx->core_brate, st_fx->Q_syn, temp_buf_fx, + st_fx->mem_syn_clas_estim_fx, &st_fx->classifier_Q_mem_syn, + 0, 0, 0, st_fx->last_core_brate, st_fx->acelp_cfg.FEC_mode ); /*------------------------------------------------------------* * FEC - Estimate pitch *------------------------------------------------------------*/ FEC_pitch_estim_fx( st_fx->Opt_AMR_WB, st_fx->last_core, st_fx->L_frame, st_fx->clas_dec, st_fx->last_good, pitch_buf_fx, st_fx->old_pitch_buf_fx, - &st_fx->bfi_pitch_fx, &st_fx->bfi_pitch_frame, &st_fx->upd_cnt, st_fx->coder_type, st_fx->element_mode ); + &st_fx->bfi_pitch_fx, &st_fx->bfi_pitch_frame, &st_fx->upd_cnt, st_fx->coder_type, st_fx->element_mode ); /*------------------------------------------------------------* * FEC - Smooth the speech energy evolution when recovering after a BAD frame @@ -1126,21 +1143,21 @@ ivas_error acelp_core_dec_fx( k = 0; move16(); - FOR (i = 0; i < st_fx->L_frame; i += L_SUBFR) + FOR( i = 0; i < st_fx->L_frame; i += L_SUBFR ) { - pitch_buf_tmp[k] = mult_r(pitch_buf_fx[k], 512); + pitch_buf_tmp[k] = mult_r( pitch_buf_fx[k], 512 ); move16(); k++; } FEC_scale_syn_fx( st_fx->L_frame, &update_flg, st_fx->clas_dec, st_fx->last_good, syn_fx, pitch_buf_tmp, st_fx->enr_old_fx, enr_q_fx, st_fx->coder_type, LSF_Q_prediction, - &st_fx->scaling_flag, &st_fx->lp_ener_FEC_av, &st_fx->lp_ener_FEC_max, st_fx->bfi, st_fx->total_brate, st_fx->prev_bfi, st_fx->last_core_brate, - exc_fx, exc2_fx, Aq_fx, &st_fx->old_enr_LP, mem_tmp_fx, st_fx->mem_syn2_fx, st_fx->Q_exc, st_fx->Q_syn , avoid_lpc_burst_on_recovery, 0 ); + &st_fx->scaling_flag, &st_fx->lp_ener_FEC_av, &st_fx->lp_ener_FEC_max, st_fx->bfi, st_fx->total_brate, st_fx->prev_bfi, st_fx->last_core_brate, + exc_fx, exc2_fx, Aq_fx, &st_fx->old_enr_LP, mem_tmp_fx, st_fx->mem_syn2_fx, st_fx->Q_exc, st_fx->Q_syn, avoid_lpc_burst_on_recovery, 0 ); test(); - IF((EQ_16(st_fx->idchan, 1) && EQ_16(st_fx->element_mode, IVAS_CPE_TD) && LE_32(st_fx->total_brate, ACELP_7k20) ) || (EQ_32(st_fx->total_brate,ACELP_7k20))||(EQ_32(st_fx->total_brate,ACELP_8k00))) + IF( ( EQ_16( st_fx->idchan, 1 ) && EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && LE_32( st_fx->total_brate, ACELP_7k20 ) ) || ( EQ_32( st_fx->total_brate, ACELP_7k20 ) ) || ( EQ_32( st_fx->total_brate, ACELP_8k00 ) ) ) { - frame_ener_fx( st_fx->L_frame, st_fx->clas_dec, syn_fx, pitch_buf_tmp[sub(shr(st_fx->L_frame,6),1)], &st_fx->enr_old_fx, st_fx->L_frame, st_fx->Q_syn, 3, 0 ); + frame_ener_fx( st_fx->L_frame, st_fx->clas_dec, syn_fx, pitch_buf_tmp[sub( shr( st_fx->L_frame, 6 ), 1 )], &st_fx->enr_old_fx, st_fx->L_frame, st_fx->Q_syn, 3, 0 ); } } @@ -1152,7 +1169,7 @@ ivas_error acelp_core_dec_fx( ELSE { /* SC-VBR */ - if ( EQ_16(st_fx->last_nelp_mode_dec,1)) + if ( EQ_16( st_fx->last_nelp_mode_dec, 1 ) ) { st_fx->nelp_mode_dec = 1; move16(); @@ -1161,7 +1178,7 @@ ivas_error acelp_core_dec_fx( /* long burst frame erasures */ test(); test(); - if( GT_16(st_fx->nbLostCmpt,5)&&GE_16(st_fx->clas_dec,VOICED_CLAS)&<_16(st_fx->clas_dec,INACTIVE_CLAS)) + if ( GT_16( st_fx->nbLostCmpt, 5 ) && GE_16( st_fx->clas_dec, VOICED_CLAS ) && LT_16( st_fx->clas_dec, INACTIVE_CLAS ) ) { st_fx->last_good = VOICED_TRANSITION; move16(); @@ -1169,15 +1186,15 @@ ivas_error acelp_core_dec_fx( /* LSF estimation and A(z) calculation */ lsf_dec_bfi( MODE1, lsf_new_fx, st_fx->lsf_old_fx, st_fx->lsf_adaptive_mean_fx, NULL, st_fx->mem_MA_fx, st_fx->mem_AR_fx, - st_fx->stab_fac_fx, st_fx->last_coder_type, st_fx->L_frame, st_fx->last_good, - st_fx->nbLostCmpt, 0, NULL, NULL, NULL, st_fx->hGSCDec->Last_GSC_pit_band_idx, st_fx->Opt_AMR_WB, 0, st_fx->bwidth); + st_fx->stab_fac_fx, st_fx->last_coder_type, st_fx->L_frame, st_fx->last_good, + st_fx->nbLostCmpt, 0, NULL, NULL, NULL, st_fx->hGSCDec->Last_GSC_pit_band_idx, st_fx->Opt_AMR_WB, 0, st_fx->bwidth ); FEC_lsf2lsp_interp( st_fx, st_fx->L_frame, Aq_fx, lsf_new_fx, lsp_new_fx ); - IF ( st_fx->nelp_mode_dec == 1 ) + IF( st_fx->nelp_mode_dec == 1 ) { /* SC-VBR */ - Scale_sig(exc_fx-L_EXC_MEM, L_EXC_MEM, -st_fx->Q_exc); + Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, -st_fx->Q_exc ); st_fx->Q_exc = 0; move16(); @@ -1185,7 +1202,7 @@ ivas_error acelp_core_dec_fx( FEC_pitch_fx = pitch_buf_fx[3]; move16(); - Rescale_exc(hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st_fx->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32)0, &(st_fx->Q_exc), st_fx->Q_subfr, exc2_fx, L_FRAME, st_fx->coder_type ); + Rescale_exc( hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st_fx->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32) 0, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, L_FRAME, st_fx->coder_type ); } ELSE { @@ -1193,10 +1210,10 @@ ivas_error acelp_core_dec_fx( FEC_exc_estim_fx( st_fx, st_fx->L_frame, exc_fx, exc2_fx, dct_exc_tmp, pitch_buf_fx, voice_factors, &FEC_pitch_fx, bwe_exc_fx, lsf_new_fx, &st_fx->Q_exc, &tmp_noise_fx ); - Rescale_exc( NULL, exc_fx, bwe_exc_fx, st_fx->hGSCDec->last_exc_dct_in_fx, st_fx->L_frame, L_FRAME32k, (Word32)0, - &(st_fx->Q_exc), st_fx->Q_subfr, exc2_fx, st_fx->L_frame, st_fx->last_coder_type ); + Rescale_exc( NULL, exc_fx, bwe_exc_fx, st_fx->hGSCDec->last_exc_dct_in_fx, st_fx->L_frame, L_FRAME32k, (Word32) 0, + &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, st_fx->L_frame, st_fx->last_coder_type ); - tmp_noise_fx = shr_r(st_fx->lp_gainc_fx,3); /*Q0*/ + tmp_noise_fx = shr_r( st_fx->lp_gainc_fx, 3 ); /*Q0*/ /* SC-VBR */ st_fx->prev_gain_pit_dec_fx = st_fx->lp_gainp_fx; @@ -1204,10 +1221,10 @@ ivas_error acelp_core_dec_fx( } /* synthesis for ACELP core switching and SWB BWE */ - syn_12k8_fx( st_fx->L_frame, Aq_fx, exc_fx, temp_buf_fx, st_fx->mem_syn1_fx, 1, st_fx->Q_exc, -1 ); /*old_syn_12k8_16k directly in q-1*/ + syn_12k8_fx( st_fx->L_frame, Aq_fx, exc_fx, temp_buf_fx, st_fx->mem_syn1_fx, 1, st_fx->Q_exc, -1 ); /*old_syn_12k8_16k directly in q-1*/ /* save and delay synthesis to be used by SWB BWE */ - IF (hBWE_FD != NULL) + IF( hBWE_FD != NULL ) { save_old_syn_fx( st_fx->L_frame, temp_buf_fx, old_syn_12k8_16k, hBWE_FD->old_syn_12k8_16k_fx, st_fx->preemph_fac, &hBWE_FD->mem_deemph_old_syn_fx ); } @@ -1215,19 +1232,19 @@ ivas_error acelp_core_dec_fx( Inac_swtch_ematch_fx( exc2_fx, dct_exc_tmp, st_fx->hGSCDec->lt_ener_per_band_fx, st_fx->coder_type, st_fx->L_frame, st_fx->core_brate, st_fx->Q_exc, st_fx->bfi, st_fx->last_core, st_fx->last_codec_mode ); /* udate past excitation signals for LD music post-filter */ - IF (hMusicPF != NULL) + IF( hMusicPF != NULL ) { - Copy(hMusicPF->dct_post_old_exc_fx + L_FRAME, hMusicPF->dct_post_old_exc_fx, DCT_L_POST-L_FRAME-OFFSET2 ); - Copy( exc2_fx, hMusicPF->dct_post_old_exc_fx + (DCT_L_POST-L_FRAME-OFFSET2), L_FRAME ); + Copy( hMusicPF->dct_post_old_exc_fx + L_FRAME, hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2 ); + Copy( exc2_fx, hMusicPF->dct_post_old_exc_fx + ( DCT_L_POST - L_FRAME - OFFSET2 ), L_FRAME ); /* Update music post processing values */ /* Filter energies update */ - FOR(i = 0; i < DCT_L_POST; i++) + FOR( i = 0; i < DCT_L_POST; i++ ) { /*st_fx->filt_lfE_fx[i] = 0.3f + 0.7f * st_fx->filt_lfE_fx[i];*/ - hMusicPF->filt_lfE_fx[i] = round_fx(L_mac((1228 << (16)), 22938, hMusicPF->filt_lfE_fx[i])); + hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( ( 1228 << ( 16 ) ), 22938, hMusicPF->filt_lfE_fx[i] ) ); } /* Update circular buffer, keep last energy difference unchanged */ - FOR(i = 1; i < MAX_LT; i++) + FOR( i = 1; i < MAX_LT; i++ ) { hMusicPF->LDm_lt_diff_etot_fx[i - 1] = hMusicPF->LDm_lt_diff_etot_fx[i]; move16(); @@ -1239,26 +1256,26 @@ ivas_error acelp_core_dec_fx( move16(); test(); test(); - if( EQ_16(st_fx->coder_type, INACTIVE)&&st_fx->flag_cna&&GE_16(round_fx(L_shl(st_fx->lp_noise,1)),15<<7)) + if ( EQ_16( st_fx->coder_type, INACTIVE ) && st_fx->flag_cna && GE_16( round_fx( L_shl( st_fx->lp_noise, 1 ) ), 15 << 7 ) ) { k = 1; move16(); } Rescale_mem( st_fx->Q_exc, &st_fx->prev_Q_syn, &st_fx->Q_syn, st_fx->mem_syn2_fx, st_fx->mem_syn_clas_estim_fx, 4, &st_fx->mem_deemph_fx, - hBPF->pst_old_syn_fx, &hBPF->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], st_fx->hPFstat, 1, k, temp_buf_fx ); + hBPF->pst_old_syn_fx, &hBPF->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], st_fx->hPFstat, 1, k, temp_buf_fx ); - if( (EQ_32(st_fx->total_brate,ACELP_7k20))||(EQ_32(st_fx->total_brate,ACELP_8k00))) + if ( ( EQ_32( st_fx->total_brate, ACELP_7k20 ) ) || ( EQ_32( st_fx->total_brate, ACELP_8k00 ) ) ) { Copy( st_fx->mem_syn2_fx, mem_tmp_fx, M ); } - syn_12k8_fx( st_fx->L_frame, Aq_fx, exc2_fx, syn_fx, st_fx->mem_syn2_fx, 1, st_fx->Q_exc, st_fx->Q_syn); + syn_12k8_fx( st_fx->L_frame, Aq_fx, exc2_fx, syn_fx, st_fx->mem_syn2_fx, 1, st_fx->Q_exc, st_fx->Q_syn ); /* update buffer for classifier */ - IF (st_fx->hWIDec != NULL) + IF( st_fx->hWIDec != NULL ) { - Copy(exc2_fx + st_fx->L_frame - L_EXC_MEM, st_fx->hWIDec->old_exc2_fx, L_EXC_MEM); - Copy(syn_fx + st_fx->L_frame - L_EXC_MEM, st_fx->hWIDec->old_syn2_fx, L_EXC_MEM); + Copy( exc2_fx + st_fx->L_frame - L_EXC_MEM, st_fx->hWIDec->old_exc2_fx, L_EXC_MEM ); + Copy( syn_fx + st_fx->L_frame - L_EXC_MEM, st_fx->hWIDec->old_syn2_fx, L_EXC_MEM ); } st_fx->prev_Q_exc_fr = st_fx->Q_exc; st_fx->prev_Q_syn_fr = st_fx->Q_syn; @@ -1266,22 +1283,21 @@ ivas_error acelp_core_dec_fx( Copy( syn_fx + st_fx->L_frame - L_SYN_MEM_CLAS_ESTIM, st_fx->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM ); - - if( (EQ_32(st_fx->total_brate,ACELP_7k20))||(EQ_32(st_fx->total_brate,ACELP_8k00))) + if ( ( EQ_32( st_fx->total_brate, ACELP_7k20 ) ) || ( EQ_32( st_fx->total_brate, ACELP_8k00 ) ) ) { k = 0; move16(); - FOR (i = 0; i < st_fx->L_frame; i += L_SUBFR) + FOR( i = 0; i < st_fx->L_frame; i += L_SUBFR ) { - pitch_buf_tmp[k] = mult_r(pitch_buf_fx[k], 512); + pitch_buf_tmp[k] = mult_r( pitch_buf_fx[k], 512 ); move16(); k++; } /*------------------------------------------------------------* - * FEC - Smooth the speech energy evolution when recovering after a BAD frame - * (smoothing is performed in the excitation domain and signal is resynthesized after) - *------------------------------------------------------------*/ + * FEC - Smooth the speech energy evolution when recovering after a BAD frame + * (smoothing is performed in the excitation domain and signal is resynthesized after) + *------------------------------------------------------------*/ FEC_scale_syn_fx( st_fx->L_frame, &update_flg, st_fx->clas_dec, st_fx->last_good, syn_fx, pitch_buf_tmp, st_fx->enr_old_fx, enr_q_fx, st_fx->coder_type, LSF_Q_prediction, &st_fx->scaling_flag, &st_fx->lp_ener_FEC_av, &st_fx->lp_ener_FEC_max, st_fx->bfi, st_fx->total_brate, st_fx->prev_bfi, st_fx->last_core_brate, @@ -1290,46 +1306,46 @@ ivas_error acelp_core_dec_fx( /* estimate the pitch-synchronous speech energy per sample to be used when normal operation recovers */ /* fer_energy( st_fx->L_frame, st_fx->last_good, syn_fx, FEC_pitch_fx, &st_fx->enr_old_fx, st_fx->L_frame ); */ - frame_ener_fx( st_fx->L_frame, st_fx->last_good, syn_fx, shr(add(FEC_pitch_fx,32),6), &st_fx->enr_old_fx, st_fx->L_frame, st_fx->Q_syn, 3, 0 ); + frame_ener_fx( st_fx->L_frame, st_fx->last_good, syn_fx, shr( add( FEC_pitch_fx, 32 ), 6 ), &st_fx->enr_old_fx, st_fx->L_frame, st_fx->Q_syn, 3, 0 ); - IF ( st_fx->nelp_mode_dec !=1 ) + IF( st_fx->nelp_mode_dec != 1 ) { /* modify the excitation signal of stationary unvoiced frames */ stat_noise_uv_mod_fx( st_fx->coder_type, 0, st_fx->lsp_old_fx, lsp_new_fx, lsp_new_fx, Aq_fx, exc2_fx, st_fx->Q_exc, 1, &st_fx->ge_sm_fx, &st_fx->uv_count, &st_fx->act_count, st_fx->lspold_s_fx, &st_fx->noimix_seed, &st_fx->min_alpha_fx, - &st_fx->exc_pe_fx, st_fx->core_brate,st_fx->bwidth, &st_fx->Q_stat_noise, &st_fx->Q_stat_noise_ge ); + &st_fx->exc_pe_fx, st_fx->core_brate, st_fx->bwidth, &st_fx->Q_stat_noise, &st_fx->Q_stat_noise_ge ); } /* SC-VBR */ - st_fx->hSC_VBR->FadeScale_fx = mult(st_fx->hSC_VBR->FadeScale_fx,24576); /*24576 in Q15*/ + st_fx->hSC_VBR->FadeScale_fx = mult( st_fx->hSC_VBR->FadeScale_fx, 24576 ); /*24576 in Q15*/ } - IF(hBWE_TD != NULL) + IF( hBWE_TD != NULL ) { - IF (EQ_16(st_fx->L_frame,L_FRAME)) - { - Copy( Aq_fx+2*(M+1), hBWE_TD->cur_sub_Aq_fx, (M+1) ); - } - ELSE - { - Copy( Aq_fx+3*(M+1), hBWE_TD->cur_sub_Aq_fx, (M+1) ); - } + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) + { + Copy( Aq_fx + 2 * ( M + 1 ), hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) ); + } + ELSE + { + Copy( Aq_fx + 3 * ( M + 1 ), hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) ); + } } /*--------------------------------------------------------* * Apply NB postfilter in case of 8kHz output *--------------------------------------------------------*/ test(); - IF( EQ_16(st_fx->last_bwidth,NB) && st_fx->hPFstat != NULL) + IF( EQ_16( st_fx->last_bwidth, NB ) && st_fx->hPFstat != NULL ) { k = 0; move16(); - FOR (i = 0; i < st_fx->L_frame; i += L_SUBFR) + FOR( i = 0; i < st_fx->L_frame; i += L_SUBFR ) { - pitch_buf_tmp[k] = mult_r(pitch_buf_fx[k], 512); + pitch_buf_tmp[k] = mult_r( pitch_buf_fx[k], 512 ); move16(); k++; } - IF(EQ_16(st_fx->bwidth,NB)) + IF( EQ_16( st_fx->bwidth, NB ) ) { st_fx->hPFstat->on = 1; move16(); @@ -1344,7 +1360,7 @@ ivas_error acelp_core_dec_fx( } ELSE { - st_fx->psf_lp_noise_fx = round_fx(L_shl(st_fx->lp_noise,1)); + st_fx->psf_lp_noise_fx = round_fx( L_shl( st_fx->lp_noise, 1 ) ); } /*------------------------------------------------------------------* @@ -1353,46 +1369,48 @@ ivas_error acelp_core_dec_fx( /* Update old synthesis buffer - needed for ACELP internal sampling rate switching */ Copy( syn_fx + st_fx->L_frame - L_SYN_MEM, st_fx->mem_syn_r, L_SYN_MEM ); - deemph_fx( syn_fx, st_fx->preemph_fac, st_fx->L_frame, &(st_fx->mem_deemph_fx) ); + deemph_fx( syn_fx, st_fx->preemph_fac, st_fx->L_frame, &( st_fx->mem_deemph_fx ) ); unscale_AGC( syn_fx, st_fx->Q_syn, syn_fx_tmp2, st_fx->agc_mem_fx, st_fx->L_frame ); - Copy(syn_fx_tmp2, syn_fx, st_fx->L_frame); + Copy( syn_fx_tmp2, syn_fx, st_fx->L_frame ); /* Update MODE2 memories*/ - IF(hTcxDec != NULL) + IF( hTcxDec != NULL ) { - Copy_Scale_sig( syn_fx + st_fx->L_frame/2, hTcxDec->old_syn_Overl, st_fx->L_frame/2, sub(-1,st_fx->Q_syn)); /*Q-1*/ + Copy_Scale_sig( syn_fx + st_fx->L_frame / 2, hTcxDec->old_syn_Overl, st_fx->L_frame / 2, sub( -1, st_fx->Q_syn ) ); /*Q-1*/ } - Copy_Scale_sig( syn_fx + st_fx->L_frame-M-1, st_fx->syn, M+1, sub(0,st_fx->Q_syn)); /*Q0*/ + Copy_Scale_sig( syn_fx + st_fx->L_frame - M - 1, st_fx->syn, M + 1, sub( 0, st_fx->Q_syn ) ); /*Q0*/ /*------------------------------------------------------------------* * Formant post-filter *-----------------------------------------------------------------*/ - IF(st_fx->hPFstat != NULL) - { - test(); test(); test(); - IF(GE_16(st_fx->last_bwidth, WB) && (GT_32(st_fx->core_brate, ACELP_24k40) || GT_16(st_fx->element_mode, EVS_MONO)) && LE_32(st_fx->core_brate, ACELP_32k)) + IF( st_fx->hPFstat != NULL ) { - Copy( syn_fx, temp_buf + L_SYN_MEM, L_FRAME16k ); - st_fx->hPFstat->on = 1; - move16(); - formant_post_filt_fx( st_fx->hPFstat, temp_buf + L_SYN_MEM, Aq_fx, syn_fx, L_FRAME16k, st_fx->lp_noise, st_fx->total_brate, 0); - } - ELSE IF( GE_16(st_fx->last_bwidth,WB)) - { - if( st_fx->hPFstat->on ) + test(); + test(); + test(); + IF( GE_16( st_fx->last_bwidth, WB ) && ( GT_32( st_fx->core_brate, ACELP_24k40 ) || GT_16( st_fx->element_mode, EVS_MONO ) ) && LE_32( st_fx->core_brate, ACELP_32k ) ) { - Copy( st_fx->hPFstat->mem_pf_in+L_SYN_MEM-M, temp_buf, M ); - Copy( syn_fx, temp_buf + M, L_SUBFR ); - Residu3_fx ( Aq_fx, temp_buf + M, temp_buf+M+L_SUBFR, L_SUBFR, 1 ); - E_UTIL_synthesis ( 1, Aq_fx, temp_buf+M+L_SUBFR, temp_buf, L_SUBFR, st_fx->hPFstat->mem_stp+L_SYN_MEM-M, 0, M ); - scale_st_fx ( syn_fx, temp_buf, &st_fx->hPFstat->gain_prec, L_SUBFR ); - Copy( temp_buf, syn_fx, L_SUBFR/2 ); - blend_subfr2_fx( temp_buf + L_SUBFR/2, syn_fx + L_SUBFR/2, syn_fx + L_SUBFR/2 ); + Copy( syn_fx, temp_buf + L_SYN_MEM, L_FRAME16k ); + st_fx->hPFstat->on = 1; + move16(); + formant_post_filt_fx( st_fx->hPFstat, temp_buf + L_SYN_MEM, Aq_fx, syn_fx, L_FRAME16k, st_fx->lp_noise, st_fx->total_brate, 0 ); + } + ELSE IF( GE_16( st_fx->last_bwidth, WB ) ) + { + if ( st_fx->hPFstat->on ) + { + Copy( st_fx->hPFstat->mem_pf_in + L_SYN_MEM - M, temp_buf, M ); + Copy( syn_fx, temp_buf + M, L_SUBFR ); + Residu3_fx( Aq_fx, temp_buf + M, temp_buf + M + L_SUBFR, L_SUBFR, 1 ); + E_UTIL_synthesis( 1, Aq_fx, temp_buf + M + L_SUBFR, temp_buf, L_SUBFR, st_fx->hPFstat->mem_stp + L_SYN_MEM - M, 0, M ); + scale_st_fx( syn_fx, temp_buf, &st_fx->hPFstat->gain_prec, L_SUBFR ); + Copy( temp_buf, syn_fx, L_SUBFR / 2 ); + blend_subfr2_fx( temp_buf + L_SUBFR / 2, syn_fx + L_SUBFR / 2, syn_fx + L_SUBFR / 2 ); + } + st_fx->hPFstat->on = 0; + move16(); } - st_fx->hPFstat->on = 0; - move16(); - } } /*----------------------------------------------------------------* * Comfort noise addition @@ -1402,28 +1420,28 @@ ivas_error acelp_core_dec_fx( test(); test(); test(); - IF((st_fx->hFdCngDec != NULL || EQ_16(st_fx->idchan, 1)) && NE_16(st_fx->element_mode, IVAS_CPE_MDCT)) + IF( ( st_fx->hFdCngDec != NULL || EQ_16( st_fx->idchan, 1 ) ) && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) { - IF(EQ_16(st_fx->element_mode, IVAS_CPE_TD) || st_fx->flag_cna || (EQ_16(st_fx->cng_type, FD_CNG) && LE_32(st_fx->total_brate, ACELP_32k)) || (EQ_16(st_fx->cng_type, LP_CNG) && LE_32(st_fx->total_brate, SID_2k40))) + IF( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) || st_fx->flag_cna || ( EQ_16( st_fx->cng_type, FD_CNG ) && LE_32( st_fx->total_brate, ACELP_32k ) ) || ( EQ_16( st_fx->cng_type, LP_CNG ) && LE_32( st_fx->total_brate, SID_2k40 ) ) ) { /*VAD only for non inactive frame*/ test(); - st_fx->VAD = st_fx->VAD && (st_fx->coder_type != INACTIVE); + st_fx->VAD = st_fx->VAD && ( st_fx->coder_type != INACTIVE ); - IF(st_fx->idchan == 0 && (st_fx->flag_cna || (EQ_16(st_fx->cng_type, FD_CNG) && LE_32(st_fx->total_brate, ACELP_32k)) || - (EQ_16(st_fx->cng_type, LP_CNG) && LE_32(st_fx->total_brate, SID_2k40)))) + IF( st_fx->idchan == 0 && ( st_fx->flag_cna || ( EQ_16( st_fx->cng_type, FD_CNG ) && LE_32( st_fx->total_brate, ACELP_32k ) ) || + ( EQ_16( st_fx->cng_type, LP_CNG ) && LE_32( st_fx->total_brate, SID_2k40 ) ) ) ) { /*Noisy speech detector*/ - noisy_speech_detection_fx(st_fx->hFdCngDec, st_fx->VAD, syn_fx, st_fx->Q_syn); + noisy_speech_detection_fx( st_fx->hFdCngDec, st_fx->VAD, syn_fx, st_fx->Q_syn ); - st_fx->hFdCngDec->hFdCngCom->likelihood_noisy_speech = mult_r(st_fx->hFdCngDec->hFdCngCom->likelihood_noisy_speech, 32440/*0.99 Q15*/); - IF(st_fx->hFdCngDec->hFdCngCom->flag_noisy_speech != 0) + st_fx->hFdCngDec->hFdCngCom->likelihood_noisy_speech = mult_r( st_fx->hFdCngDec->hFdCngCom->likelihood_noisy_speech, 32440 /*0.99 Q15*/ ); + IF( st_fx->hFdCngDec->hFdCngCom->flag_noisy_speech != 0 ) { - st_fx->hFdCngDec->hFdCngCom->likelihood_noisy_speech = add(st_fx->hFdCngDec->hFdCngCom->likelihood_noisy_speech, 328/*0.01 Q15*/); + st_fx->hFdCngDec->hFdCngCom->likelihood_noisy_speech = add( st_fx->hFdCngDec->hFdCngCom->likelihood_noisy_speech, 328 /*0.01 Q15*/ ); move16(); } } - IF(st_fx->idchan == 0) + IF( st_fx->idchan == 0 ) { st_fx->lp_noise = st_fx->hFdCngDec->lp_noise; move32(); @@ -1431,13 +1449,13 @@ ivas_error acelp_core_dec_fx( /*Noise estimate*/ test(); test(); - IF(NE_16(st_fx->element_mode, IVAS_CPE_TD)/* && !st->cng_ism_flag IVAS_CODE */ ) + IF( NE_16( st_fx->element_mode, IVAS_CPE_TD ) /* && !st->cng_ism_flag IVAS_CODE */ ) { #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - PMT("Code for IVAS_CODE_CNG_FIX185_PLC_FADEOUT not done") - ApplyFdCng_fx(syn, st_fx->Q_syn, NULL, realBuffer, imagBuffer, st, 0, (st->coder_type == AUDIO && !st->GSC_noisy_speech)); + PMT( "Code for IVAS_CODE_CNG_FIX185_PLC_FADEOUT not done" ) + ApplyFdCng_fx( syn, st_fx->Q_syn, NULL, realBuffer, imagBuffer, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); #else - ApplyFdCng_fx(syn_fx, st_fx->Q_syn, realBuffer, imagBuffer, NULL, st_fx, 0, (EQ_16(st_fx->coder_type, AUDIO) && st_fx->GSC_noisy_speech == 0)); + ApplyFdCng_fx( syn_fx, st_fx->Q_syn, realBuffer, imagBuffer, NULL, st_fx, 0, ( EQ_16( st_fx->coder_type, AUDIO ) && st_fx->GSC_noisy_speech == 0 ) ); #endif } /* CNA: Generate additional comfort noise to mask potential coding artefacts */ @@ -1446,188 +1464,188 @@ ivas_error acelp_core_dec_fx( test(); test(); #ifdef IVAS_CODE - if (!st->cna_dirac_flag) + if ( !st->cna_dirac_flag ) { /* CNA: Generate additional comfort noise to mask potential coding artefacts */ - if (st->flag_cna && !(st->coder_type == AUDIO && !(st->element_mode > EVS_MONO && st->GSC_noisy_speech))) + if ( st->flag_cna && !( st->coder_type == AUDIO && !( st->element_mode > EVS_MONO && st->GSC_noisy_speech ) ) ) { - if (st->element_mode == IVAS_CPE_TD && nchan_out == 2) + if ( st->element_mode == IVAS_CPE_TD && nchan_out == 2 ) { - if (hStereoCng->flag_cna_fade) + if ( hStereoCng->flag_cna_fade ) { - generate_stereo_masking_noise(syn, st, hStereoTD, flag_sec_CNA, 1, hStereoCng, nchan_out); + generate_stereo_masking_noise( syn, st, hStereoTD, flag_sec_CNA, 1, hStereoCng, nchan_out ); hStereoCng->flag_cna_fade = 0; } else { - if (st->element_mode != last_element_mode && st->idchan == 0) + if ( st->element_mode != last_element_mode && st->idchan == 0 ) { /* Clear memory for secondary channel CNA */ - set_f(hStereoCng->olapBufferSynth22, 0.0f, st->hFdCngDec->hFdCngCom->frameSize / 2); + set_f( hStereoCng->olapBufferSynth22, 0.0f, st->hFdCngDec->hFdCngCom->frameSize / 2 ); } - generate_stereo_masking_noise(syn, st, hStereoTD, flag_sec_CNA, 0, hStereoCng, nchan_out); + generate_stereo_masking_noise( syn, st, hStereoTD, flag_sec_CNA, 0, hStereoCng, nchan_out ); } } - else if (st->element_mode != IVAS_CPE_DFT) + else if ( st->element_mode != IVAS_CPE_DFT ) { - if (st->idchan == 0) + if ( st->idchan == 0 ) { - if (st->element_mode != last_element_mode) + if ( st->element_mode != last_element_mode ) { - set_f(st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0.0f, st->hFdCngDec->hFdCngCom->fftlen); + set_f( st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0.0f, st->hFdCngDec->hFdCngCom->fftlen ); } - generate_masking_noise_fx(syn, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0, 0, 0, st->element_mode, hStereoCng, nchan_out); + generate_masking_noise_fx( syn, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0, 0, 0, st->element_mode, hStereoCng, nchan_out ); } } } - else if (st->flag_cna && st->coder_type == AUDIO && ((st->last_core == ACELP_CORE && !(st->last_coder_type == AUDIO && !(st->element_mode > EVS_MONO && st->Last_GSC_noisy_speech_flag))) || st->last_core == TCX_20_CORE)) + else if ( st->flag_cna && st->coder_type == AUDIO && ( ( st->last_core == ACELP_CORE && !( st->last_coder_type == AUDIO && !( st->element_mode > EVS_MONO && st->Last_GSC_noisy_speech_flag ) ) ) || st->last_core == TCX_20_CORE ) ) { - if (st->element_mode == IVAS_CPE_TD && nchan_out == 2) + if ( st->element_mode == IVAS_CPE_TD && nchan_out == 2 ) { - generate_stereo_masking_noise(syn, st, hStereoTD, flag_sec_CNA, 1, hStereoCng, nchan_out); + generate_stereo_masking_noise( syn, st, hStereoTD, flag_sec_CNA, 1, hStereoCng, nchan_out ); hStereoCng->flag_cna_fade = 1; } else { - v_multc(st->hFdCngDec->hFdCngCom->olapBufferSynth2 + 5 * st->hFdCngDec->hFdCngCom->frameSize / 4, (float)(st->hFdCngDec->hFdCngCom->fftlen / 2), temp_buf, st->hFdCngDec->hFdCngCom->frameSize / 2); - v_add(temp_buf, syn, syn, st->hFdCngDec->hFdCngCom->frameSize / 2); + v_multc( st->hFdCngDec->hFdCngCom->olapBufferSynth2 + 5 * st->hFdCngDec->hFdCngCom->frameSize / 4, (float) ( st->hFdCngDec->hFdCngCom->fftlen / 2 ), temp_buf, st->hFdCngDec->hFdCngCom->frameSize / 2 ); + v_add( temp_buf, syn, syn, st->hFdCngDec->hFdCngCom->frameSize / 2 ); } } else { - if (hStereoCng != NULL) + if ( hStereoCng != NULL ) { hStereoCng->flag_cna_fade = 1; hStereoCng->enableSecCNA = 0; } } - if (st->element_mode == IVAS_CPE_TD) + if ( st->element_mode == IVAS_CPE_TD ) { /*Noise estimate*/ - if (st->idchan == 0 && (nchan_out == 2 || (st->core_brate != FRAME_NO_DATA && st->core_brate != SID_2k40))) + if ( st->idchan == 0 && ( nchan_out == 2 || ( st->core_brate != FRAME_NO_DATA && st->core_brate != SID_2k40 ) ) ) { #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - ApplyFdCng_fx(syn, st_fx->Q_syn, realBuffer, imagBuffer, NULL, st, 0, (st->coder_type == AUDIO && !st->GSC_noisy_speech)); + ApplyFdCng_fx( syn, st_fx->Q_syn, realBuffer, imagBuffer, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); #else - ApplyFdCng_fx(syn, st_fx->Q_syn, realBuffer, imagBuffer, NULL, st, 0, (st->coder_type == AUDIO && !st->GSC_noisy_speech)); + ApplyFdCng_fx( syn, st_fx->Q_syn, realBuffer, imagBuffer, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); #endif } } } } - if (!st->cna_dirac_flag) + if ( !st->cna_dirac_flag ) { - if (st->flag_cna == 0 && st->L_frame == L_FRAME16k && st->last_flag_cna == 1 && ((st->last_core == ACELP_CORE && !(st->last_coder_type == AUDIO && !(st->element_mode > EVS_MONO && st->Last_GSC_noisy_speech_flag))) || st->last_core == AMR_WB_CORE)) + if ( st->flag_cna == 0 && st->L_frame == L_FRAME16k && st->last_flag_cna == 1 && ( ( st->last_core == ACELP_CORE && !( st->last_coder_type == AUDIO && !( st->element_mode > EVS_MONO && st->Last_GSC_noisy_speech_flag ) ) ) || st->last_core == AMR_WB_CORE ) ) { - v_multc(st->hFdCngDec->hFdCngCom->olapBufferSynth2 + 5 * st->L_frame / 4, 256.f, temp_buf, st->L_frame / 2); - v_add(temp_buf, syn, syn, st->L_frame / 2); + v_multc( st->hFdCngDec->hFdCngCom->olapBufferSynth2 + 5 * st->L_frame / 4, 256.f, temp_buf, st->L_frame / 2 ); + v_add( temp_buf, syn, syn, st->L_frame / 2 ); } - if (st->flag_cna == 0 || (st->coder_type == AUDIO && !(st->element_mode > EVS_MONO && st->GSC_noisy_speech))) + if ( st->flag_cna == 0 || ( st->coder_type == AUDIO && !( st->element_mode > EVS_MONO && st->GSC_noisy_speech ) ) ) { - if (st->idchan == 0) + if ( st->idchan == 0 ) { - set_f(st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0.f, st->hFdCngDec->hFdCngCom->fftlen); + set_f( st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0.f, st->hFdCngDec->hFdCngCom->fftlen ); } - if (hStereoCng != NULL && st->idchan == 0) + if ( hStereoCng != NULL && st->idchan == 0 ) { - set_f(hStereoCng->olapBufferSynth22, 0.f, st->hFdCngDec->hFdCngCom->fftlen); + set_f( hStereoCng->olapBufferSynth22, 0.f, st->hFdCngDec->hFdCngCom->fftlen ); } } } #else - IF(st_fx->flag_cna && NE_16(st_fx->coder_type, AUDIO)) + IF( st_fx->flag_cna && NE_16( st_fx->coder_type, AUDIO ) ) { - generate_masking_noise_fx(syn_fx, st_fx->Q_syn, st_fx->hFdCngDec->hFdCngCom, st_fx->hFdCngDec->hFdCngCom->frameSize, 0); + generate_masking_noise_fx( syn_fx, st_fx->Q_syn, st_fx->hFdCngDec->hFdCngCom, st_fx->hFdCngDec->hFdCngCom->frameSize, 0 ); } - ELSE IF(st_fx->flag_cna && st_fx->coder_type == AUDIO && st_fx->last_core == ACELP_CORE && st_fx->last_coder_type != AUDIO) + ELSE IF( st_fx->flag_cna && st_fx->coder_type == AUDIO && st_fx->last_core == ACELP_CORE && st_fx->last_coder_type != AUDIO ) { - FOR(i = 0; i < st_fx->hFdCngDec->hFdCngCom->frameSize / 2; i++) + FOR( i = 0; i < st_fx->hFdCngDec->hFdCngCom->frameSize / 2; i++ ) { - syn_fx[i] = add(syn_fx[i], shr_r(mult_r(st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * st_fx->hFdCngDec->hFdCngCom->frameSize / 4], st_fx->hFdCngDec->hFdCngCom->fftlenFac), -st_fx->Q_syn)); + syn_fx[i] = add( syn_fx[i], shr_r( mult_r( st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * st_fx->hFdCngDec->hFdCngCom->frameSize / 4], st_fx->hFdCngDec->hFdCngCom->fftlenFac ), -st_fx->Q_syn ) ); move16(); } } } - IF(st_fx->flag_cna == 0 && EQ_16(st_fx->L_frame, L_FRAME16k) && st_fx->last_flag_cna == 1 && ((st_fx->last_core == ACELP_CORE && st_fx->last_coder_type != AUDIO) || st_fx->last_core == AMR_WB_CORE)) + IF( st_fx->flag_cna == 0 && EQ_16( st_fx->L_frame, L_FRAME16k ) && st_fx->last_flag_cna == 1 && ( ( st_fx->last_core == ACELP_CORE && st_fx->last_coder_type != AUDIO ) || st_fx->last_core == AMR_WB_CORE ) ) { - FOR(i = 0; i < st_fx->L_frame / 2; i++) + FOR( i = 0; i < st_fx->L_frame / 2; i++ ) { - syn_fx[i] = add(syn_fx[i], shr_r(st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * st_fx->L_frame / 4], -st_fx->Q_syn)); + syn_fx[i] = add( syn_fx[i], shr_r( st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * st_fx->L_frame / 4], -st_fx->Q_syn ) ); move16(); } } test(); - IF(st_fx->flag_cna == 0 || EQ_16(st_fx->coder_type, AUDIO)) + IF( st_fx->flag_cna == 0 || EQ_16( st_fx->coder_type, AUDIO ) ) { - set16_fx(st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, st_fx->hFdCngDec->hFdCngCom->fftlen); + set16_fx( st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, st_fx->hFdCngDec->hFdCngCom->fftlen ); } #endif } /*----------------------------------------------------------------* - * Resample to the output sampling rate (8/16/32/48 kHz) - * Bass post-filter - *----------------------------------------------------------------*/ + * Resample to the output sampling rate (8/16/32/48 kHz) + * Bass post-filter + *----------------------------------------------------------------*/ /* check if the CLDFB works on the right sample rate */ - IF( (st_fx->cldfbAna->usb * st_fx->cldfbAna->no_col) != st_fx->L_frame ) + IF( ( st_fx->cldfbAna->usb * st_fx->cldfbAna->no_col ) != st_fx->L_frame ) { /* resample to ACELP internal sampling rate */ - Word16 newCldfbBands = CLDFB_getNumChannels(L_mult0(st_fx->L_frame, FRAMES_PER_SEC)); + Word16 newCldfbBands = CLDFB_getNumChannels( L_mult0( st_fx->L_frame, FRAMES_PER_SEC ) ); resampleCldfb( st_fx->cldfbAna, newCldfbBands, st_fx->L_frame, 0 ); resampleCldfb( st_fx->cldfbBPF, newCldfbBands, st_fx->L_frame, 0 ); - if( st_fx->ini_frame > 0 ) + if ( st_fx->ini_frame > 0 ) { - st_fx->cldfbSyn->bandsToZero = sub(st_fx->cldfbSyn->no_channels,st_fx->cldfbAna->no_channels); + st_fx->cldfbSyn->bandsToZero = sub( st_fx->cldfbSyn->no_channels, st_fx->cldfbAna->no_channels ); } } -#ifdef ADD_LRTD +#ifdef ADD_LRTD /* analyze pitch coherence for bass post-filter */ - bpf_pitch_coherence(st, pitch_buf); + bpf_pitch_coherence( st, pitch_buf ); #endif - IF(!(EQ_16(st_fx->element_mode, IVAS_CPE_MDCT) && st_fx->bpf_off)) + IF( !( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) && st_fx->bpf_off ) ) { test(); - IF( NE_16(st_fx->L_frame,st_fx->last_L_frame)&&NE_16(st_fx->last_codec_mode,MODE2)) + IF( NE_16( st_fx->L_frame, st_fx->last_L_frame ) && NE_16( st_fx->last_codec_mode, MODE2 ) ) { - IF( EQ_16(st_fx->L_frame,L_FRAME)) + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { - retro_interp5_4_fx(hBPF->pst_old_syn_fx ); + retro_interp5_4_fx( hBPF->pst_old_syn_fx ); } - ELSE IF( EQ_16(st_fx->L_frame,L_FRAME16k)) + ELSE IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { retro_interp4_5_fx( syn_fx, hBPF->pst_old_syn_fx ); } } - bass_psfilter_fx(st_fx->hBPF, st_fx->Opt_AMR_WB, syn_fx, st_fx->L_frame, pitch_buf_fx, st_fx->bpf_off, - st_fx->stab_fac_fx, &st_fx->stab_fac_smooth_fx, st_fx->coder_type, st_fx->Q_syn, bpf_error_signal ); + bass_psfilter_fx( st_fx->hBPF, st_fx->Opt_AMR_WB, syn_fx, st_fx->L_frame, pitch_buf_fx, st_fx->bpf_off, + st_fx->stab_fac_fx, &st_fx->stab_fac_smooth_fx, st_fx->coder_type, st_fx->Q_syn, bpf_error_signal ); } test(); - IF (NE_16(st_fx->element_mode, IVAS_CPE_DFT) || use_cldfb_for_dft) + IF( NE_16( st_fx->element_mode, IVAS_CPE_DFT ) || use_cldfb_for_dft ) { #ifdef IVAS_CODE float realBufferSave[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; float imagBufferSave[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - float* pRealSave[CLDFB_NO_COL_MAX], * pImagSave[CLDFB_NO_COL_MAX]; - for (i = 0; i < CLDFB_NO_COL_MAX; i++) + float *pRealSave[CLDFB_NO_COL_MAX], *pImagSave[CLDFB_NO_COL_MAX]; + for ( i = 0; i < CLDFB_NO_COL_MAX; i++ ) { pRealSave[i] = realBufferSave[i]; pImagSave[i] = imagBufferSave[i]; } - if (st->p_bpf_noise_buf) + if ( st->p_bpf_noise_buf ) { - mvr2r(bpf_error_signal, st->p_bpf_noise_buf, st->L_frame); + mvr2r( bpf_error_signal, st->p_bpf_noise_buf, st->L_frame ); } #endif /* analysis of the synthesis at internal sampling rate */ - cldfbAnalysisFiltering( st_fx->cldfbAna, realBuffer, imagBuffer, &scaleFactor, syn_fx, negate(st_fx->Q_syn), CLDFB_NO_COL_MAX, workBuffer); + cldfbAnalysisFiltering( st_fx->cldfbAna, realBuffer, imagBuffer, &scaleFactor, syn_fx, negate( st_fx->Q_syn ), CLDFB_NO_COL_MAX, workBuffer ); scaleFactor.hb_scale = scaleFactor.lb_scale; move16(); @@ -1635,24 +1653,24 @@ ivas_error acelp_core_dec_fx( /* analysis and add the BPF error signal */ i = 0; move16(); - if( st_fx->bpf_off == 0 ) + if ( st_fx->bpf_off == 0 ) { i = CLDFB_NO_COL_MAX; move16(); } - addBassPostFilter_fx( bpf_error_signal, realBuffer, imagBuffer, st_fx->cldfbBPF, workBuffer, negate(st_fx->Q_syn), - i, st_fx->cldfbAna->no_col, st_fx->cldfbAna->no_channels, &scaleFactor ); + addBassPostFilter_fx( bpf_error_signal, realBuffer, imagBuffer, st_fx->cldfbBPF, workBuffer, negate( st_fx->Q_syn ), + i, st_fx->cldfbAna->no_col, st_fx->cldfbAna->no_channels, &scaleFactor ); /* set output mask for upsampling */ - IF( EQ_16(st_fx->bwidth,NB)) + IF( EQ_16( st_fx->bwidth, NB ) ) { /* set NB mask for upsampling */ - st_fx->cldfbSyn->bandsToZero = sub(st_fx->cldfbSyn->no_channels,10); + st_fx->cldfbSyn->bandsToZero = sub( st_fx->cldfbSyn->no_channels, 10 ); } - ELSE if( NE_16(st_fx->cldfbSyn->bandsToZero,sub(st_fx->cldfbSyn->no_channels,st_fx->cldfbAna->no_channels))) + ELSE if ( NE_16( st_fx->cldfbSyn->bandsToZero, sub( st_fx->cldfbSyn->no_channels, st_fx->cldfbAna->no_channels ) ) ) { /* in case of BW switching, re-init to default */ - st_fx->cldfbSyn->bandsToZero = sub(st_fx->cldfbSyn->no_channels, st_fx->cldfbAna->no_channels); + st_fx->cldfbSyn->bandsToZero = sub( st_fx->cldfbSyn->no_channels, st_fx->cldfbAna->no_channels ); } /*WB/SWB-FD_CNG*/ @@ -1662,17 +1680,17 @@ ivas_error acelp_core_dec_fx( test(); test(); test(); - IF(!st_fx->cng_sba_flag || EQ_16(st_fx->element_mode, IVAS_CPE_MDCT)) + IF( !st_fx->cng_sba_flag || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) { - IF((EQ_32(st_fx->core_brate, FRAME_NO_DATA) || EQ_32(st_fx->core_brate, SID_2k40)) && (EQ_16(st_fx->cng_type, FD_CNG)) && (LT_16(st_fx->hFdCngDec->hFdCngCom->numCoreBands, st_fx->cldfbSyn->no_channels))) + IF( ( EQ_32( st_fx->core_brate, FRAME_NO_DATA ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) && ( EQ_16( st_fx->cng_type, FD_CNG ) ) && ( LT_16( st_fx->hFdCngDec->hFdCngCom->numCoreBands, st_fx->cldfbSyn->no_channels ) ) ) { - generate_comfort_noise_dec_hf_fx(realBuffer, imagBuffer, &scaleFactor.hb_scale, st_fx); + generate_comfort_noise_dec_hf_fx( realBuffer, imagBuffer, &scaleFactor.hb_scale, st_fx ); st_fx->cldfbSyn->bandsToZero = 0; move16(); - if (LT_16(st_fx->hFdCngDec->hFdCngCom->regularStopBand, st_fx->cldfbSyn->no_channels)) + if ( LT_16( st_fx->hFdCngDec->hFdCngCom->regularStopBand, st_fx->cldfbSyn->no_channels ) ) { - st_fx->cldfbSyn->bandsToZero = sub(st_fx->cldfbSyn->no_channels, st_fx->hFdCngDec->hFdCngCom->regularStopBand); + st_fx->cldfbSyn->bandsToZero = sub( st_fx->cldfbSyn->no_channels, st_fx->hFdCngDec->hFdCngCom->regularStopBand ); } st_fx->cldfbSyn->lsb = st_fx->cldfbAna->no_channels; move16(); @@ -1682,16 +1700,16 @@ ivas_error acelp_core_dec_fx( st_fx->Q_syn2 = st_fx->Q_syn; move16(); #ifdef IVAS_CODE - if (save_hb_synth != NULL) + if ( save_hb_synth != NULL ) { /* save and then zero-out lowband */ - for (int16_t j = 0; j < CLDFB_NO_CHANNELS_MAX; j++) + for ( int16_t j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) { - for (i = 0; i < CLDFB_NO_COL_MAX; i++) + for ( i = 0; i < CLDFB_NO_COL_MAX; i++ ) { realBufferSave[i][j] = realBuffer[i][j]; imagBufferSave[i][j] = imagBuffer[i][j]; - if (j < st->hFdCngDec->hFdCngCom->numCoreBands && i < st->hFdCngDec->hFdCngCom->numSlots) + if ( j < st->hFdCngDec->hFdCngCom->numCoreBands && i < st->hFdCngDec->hFdCngCom->numSlots ) { realBuffer[i][j] = 0.0f; imagBuffer[i][j] = 0.0f; @@ -1699,29 +1717,29 @@ ivas_error acelp_core_dec_fx( } } - cldfbSynthesis(realBuffer, imagBuffer, save_hb_synth, -1, st->cldfbSynHB); + cldfbSynthesis( realBuffer, imagBuffer, save_hb_synth, -1, st->cldfbSynHB ); /* restore lowband */ - for (int16_t j = 0; j < CLDFB_NO_CHANNELS_MAX; j++) + for ( int16_t j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) { - for (i = 0; i < CLDFB_NO_COL_MAX; i++) + for ( i = 0; i < CLDFB_NO_COL_MAX; i++ ) { realBuffer[i][j] = realBufferSave[i][j]; imagBuffer[i][j] = imagBufferSave[i][j]; } } - cldfbSynthesis(pRealSave, pImagSave, synth, -1, st->cldfbSyn); + cldfbSynthesis( pRealSave, pImagSave, synth, -1, st->cldfbSyn ); } else #endif { - cldfbSynthesisFiltering(st_fx->cldfbSyn, realBuffer, imagBuffer, &scaleFactor, synth_out, negate(st_fx->Q_syn2), CLDFB_NO_COL_MAX, workBuffer); + cldfbSynthesisFiltering( st_fx->cldfbSyn, realBuffer, imagBuffer, &scaleFactor, synth_out, negate( st_fx->Q_syn2 ), CLDFB_NO_COL_MAX, workBuffer ); } /* Bring CLDFB output to Q0 */ - Scale_sig(synth_out, output_frame, negate(st_fx->Q_syn2)); + Scale_sig( synth_out, output_frame, negate( st_fx->Q_syn2 ) ); st_fx->Q_syn2 = 0; - move16(); + move16(); /* save synthesis - needed in case of core switching */ Copy( synth_out, st_fx->previoussynth_fx, output_frame ); @@ -1729,46 +1747,52 @@ ivas_error acelp_core_dec_fx( #ifdef IVAS_CODE ELSE { - int16_t nSamples = NS2SA(st->L_frame * FRAMES_PER_SEC, FRAME_SIZE_NS /*DELAY_CLDFB_NS*/); /* IVAS-64: optimization is likely possible here (don't resample the whole frame) */ + int16_t nSamples = NS2SA( st->L_frame * FRAMES_PER_SEC, FRAME_SIZE_NS /*DELAY_CLDFB_NS*/ ); /* IVAS-64: optimization is likely possible here (don't resample the whole frame) */ /* analysis of the synthesis at internal sampling rate - needed for DFT stereo -> TD stereo switching */ - cldfbAnalysis(syn + st->L_frame - nSamples, realBuffer, imagBuffer, nSamples, st->cldfbAna); + cldfbAnalysis( syn + st->L_frame - nSamples, realBuffer, imagBuffer, nSamples, st->cldfbAna ); /* analysis and add the BPF error signal - needed for DFT stereo -> TD stereo switching */ - addBassPostFilter(bpf_error_signal + st->L_frame - nSamples, st->bpf_off ? 0 : nSamples, realBuffer, imagBuffer, st->cldfbBPF); + addBassPostFilter( bpf_error_signal + st->L_frame - nSamples, st->bpf_off ? 0 : nSamples, realBuffer, imagBuffer, st->cldfbBPF ); /* synthesis of the combined signal - needed for DFT stereo -> TD stereo switching */ - cldfbSynthesis(realBuffer, imagBuffer, synth /*dummy*/, NS2SA(st->output_Fs, FRAME_SIZE_NS /*DELAY_CLDFB_NS*/), st->cldfbSyn); + cldfbSynthesis( realBuffer, imagBuffer, synth /*dummy*/, NS2SA( st->output_Fs, FRAME_SIZE_NS /*DELAY_CLDFB_NS*/ ), st->cldfbSyn ); - if (st->p_bpf_noise_buf) + if ( st->p_bpf_noise_buf ) { - mvr2r(bpf_error_signal, st->p_bpf_noise_buf, st->L_frame); + mvr2r( bpf_error_signal, st->p_bpf_noise_buf, st->L_frame ); } - set_f(synth, 0.0f, output_frame); + set_f( synth, 0.0f, output_frame ); } /* Copy output signal */ - if (st->element_mode > EVS_MONO) + if ( st->element_mode > EVS_MONO ) { - mvr2r(syn, output, st->L_frame); + mvr2r( syn, output, st->L_frame ); } #endif /*-----------------------------------------------------------------* - * Bandwidth extension 6kHz-7kHz + * Bandwidth extension 6kHz-7kHz *-----------------------------------------------------------------*/ - IF(st_fx->hBWE_zero != NULL) + IF( st_fx->hBWE_zero != NULL ) { - test(); test(); test(); test(); test(); test(); test(); - IF( (EQ_16(st_fx->L_frame,L_FRAME)&&NE_16(st_fx->bwidth,NB)&&GE_16(output_frame,L_FRAME16k)&& - ( EQ_16(st_fx->extl,-1) || EQ_16(st_fx->extl,SWB_CNG) || (EQ_16(st_fx->extl,WB_BWE) && st_fx->extl_brate == 0 && NE_16(st_fx->coder_type,AUDIO) )) ) ) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( EQ_16( st_fx->L_frame, L_FRAME ) && NE_16( st_fx->bwidth, NB ) && GE_16( output_frame, L_FRAME16k ) && + ( EQ_16( st_fx->extl, -1 ) || EQ_16( st_fx->extl, SWB_CNG ) || ( EQ_16( st_fx->extl, WB_BWE ) && st_fx->extl_brate == 0 && NE_16( st_fx->coder_type, AUDIO ) ) ) ) ) { hf_synth_fx( st_fx->hBWE_zero, st_fx->core_brate, output_frame, Aq_fx, exc2_fx, syn_fx, synth_out, st_fx->Q_exc, - st_fx->Q_syn2, st_fx->hBWE_zero->delay_syn_hf_fx, &hBWE_FD->memExp1, st_fx->hBWE_zero->mem_hp_interp_fx, st_fx->extl, st_fx->CNG_mode ); + st_fx->Q_syn2, st_fx->hBWE_zero->delay_syn_hf_fx, &hBWE_FD->memExp1, st_fx->hBWE_zero->mem_hp_interp_fx, st_fx->extl, st_fx->CNG_mode ); } ELSE { - hf_synth_reset_fx( st_fx->hBWE_zero ); + hf_synth_reset_fx( st_fx->hBWE_zero ); } } @@ -1777,28 +1801,35 @@ ivas_error acelp_core_dec_fx( *-----------------------------------------------------------------*/ /* Apply a non linearity to the SHB excitation */ - IF(hBWE_TD != NULL) + IF( hBWE_TD != NULL ) { - test(); test(); test(); test(); test(); test(); test(); test(); test(); test(); - IF((!st_fx->bfi && (st_fx->prev_bfi)) || ((EQ_16(st_fx->last_vbr_hw_BWE_disable_dec, 1)) && (st_fx->vbr_hw_BWE_disable_dec == 0)) || ((EQ_16(st_fx->extl, SWB_TBE) || EQ_16(st_fx->extl, WB_TBE) || EQ_16(st_fx->extl, FB_TBE)) - && NE_16(st_fx->last_extl, SWB_TBE) && NE_16(st_fx->last_extl, WB_TBE) && NE_16(st_fx->last_extl, FB_TBE)) - || (EQ_16(st_fx->idchan, 1) && EQ_16(st_fx->element_mode, IVAS_CPE_TD) && !st_fx->tdm_LRTD_flag)) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( !st_fx->bfi && ( st_fx->prev_bfi ) ) || ( ( EQ_16( st_fx->last_vbr_hw_BWE_disable_dec, 1 ) ) && ( st_fx->vbr_hw_BWE_disable_dec == 0 ) ) || ( ( EQ_16( st_fx->extl, SWB_TBE ) || EQ_16( st_fx->extl, WB_TBE ) || EQ_16( st_fx->extl, FB_TBE ) ) && NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, WB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) ) || ( EQ_16( st_fx->idchan, 1 ) && EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && !st_fx->tdm_LRTD_flag ) ) { - hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l(0); - set16_fx(hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); + hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 ); + set16_fx( hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); } - IF(!st_fx->ppp_mode_dec && (st_fx->idchan == 0 || NE_16(st_fx->element_mode, IVAS_CPE_TD) || (EQ_16(st_fx->idchan, 1) && EQ_16(st_fx->element_mode, IVAS_CPE_TD) && st_fx->tdm_LRTD_flag))) + IF( !st_fx->ppp_mode_dec && ( st_fx->idchan == 0 || NE_16( st_fx->element_mode, IVAS_CPE_TD ) || ( EQ_16( st_fx->idchan, 1 ) && EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && st_fx->tdm_LRTD_flag ) ) ) { - non_linearity_fx(bwe_exc_fx, bwe_exc_extended, L_FRAME32k, &hBWE_TD->bwe_non_lin_prev_scale_fx, st_fx->Q_exc, - st_fx->coder_type, voice_factors, st_fx->L_frame); + non_linearity_fx( bwe_exc_fx, bwe_exc_extended, L_FRAME32k, &hBWE_TD->bwe_non_lin_prev_scale_fx, st_fx->Q_exc, + st_fx->coder_type, voice_factors, st_fx->L_frame ); } test(); - IF( EQ_32(st_fx->core_brate,FRAME_NO_DATA)||EQ_32(st_fx->core_brate,SID_2k40)) + IF( EQ_32( st_fx->core_brate, FRAME_NO_DATA ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) { - hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l(0); + hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 ); } } /*----------------------------------------------------------------------* @@ -1807,7 +1838,7 @@ ivas_error acelp_core_dec_fx( updt_dec_fx( st_fx, old_exc_fx, pitch_buf_fx, Es_pred_fx, Aq_fx, lsf_new_fx, lsp_new_fx, voice_factors, old_bwe_exc_fx, gain_buf ); - IF( GT_32(st_fx->core_brate,SID_2k40) && st_fx->hTdCngDec != NULL && st_fx->hFdCngDec != NULL) + IF( GT_32( st_fx->core_brate, SID_2k40 ) && st_fx->hTdCngDec != NULL && st_fx->hFdCngDec != NULL ) { /* update CNG parameters in active frames */ cng_params_upd_fx( lsp_new_fx, exc_fx, st_fx->L_frame, &st_fx->hTdCngDec->ho_circ_ptr, st_fx->hTdCngDec->ho_ener_circ_fx, &st_fx->hTdCngDec->ho_circ_size, st_fx->hTdCngDec->ho_lsp_circ_fx, @@ -1815,7 +1846,7 @@ ivas_error acelp_core_dec_fx( /* Set 16k LSP flag for CNG buffer */ st_fx->hTdCngDec->ho_16k_lsp[st_fx->hTdCngDec->ho_circ_ptr] = 0; move16(); - if (NE_16(st_fx->L_frame, L_FRAME)) + if ( NE_16( st_fx->L_frame, L_FRAME ) ) { st_fx->hTdCngDec->ho_16k_lsp[st_fx->hTdCngDec->ho_circ_ptr] = 1; move16(); @@ -1823,6 +1854,5 @@ ivas_error acelp_core_dec_fx( } return IVAS_ERR_OK; - } #endif diff --git a/lib_dec/acelp_core_dec_ivas_fx.c b/lib_dec/acelp_core_dec_ivas_fx.c index 211a696d1..c59436411 100644 --- a/lib_dec/acelp_core_dec_ivas_fx.c +++ b/lib_dec/acelp_core_dec_ivas_fx.c @@ -53,22 +53,22 @@ * * ACELP core decoder *-------------------------------------------------------------------*/ -static void rescale_fdCngDec(HANDLE_FD_CNG_DEC hFdCngDec, Word16 old_NoiseExp); +static void rescale_fdCngDec( HANDLE_FD_CNG_DEC hFdCngDec, Word16 old_NoiseExp ); ivas_error acelp_core_dec_ivas_fx( Decoder_State *st, /* i/o: decoder state structure */ - Word16 output_fx[], /* o : synthesis @internal Fs */ - Word16 synth_fx16[], /* o : synthesis */ - Word16 save_hb_synth_fx16[], /* o : HB synthesis */ - Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation */ - Word16 *voice_factors_fx, /* o : voicing factors */ - Word16 old_syn_12k8_16k_fx[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE */ + Word16 output_fx[], /* o : synthesis @internal Fs */ + Word16 synth_fx16[], /* o : synthesis */ + Word16 save_hb_synth_fx16[], /* o : HB synthesis */ + Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation */ + Word16 *voice_factors_fx, /* o : voicing factors */ + Word16 old_syn_12k8_16k_fx[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE */ const int16_t sharpFlag, /* i : formant sharpening flag */ - Word16 pitch_buf_fx[NB_SUBFR16k], /* o : floating pitch for each subframe */ + Word16 pitch_buf_fx[NB_SUBFR16k], /* o : floating pitch for each subframe */ int16_t *unbits, /* o : number of unused bits */ int16_t *sid_bw, /* o : 0-NB/WB, 1-SWB SID */ STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle */ - const Word16 tdm_lspQ_PCh_fx[M], /* i : Q LSPs for primary channel */ - const Word16 tdm_lsfQ_PCh_fx[M], /* i : Q LSFs for primary channel */ + const Word16 tdm_lspQ_PCh_fx[M], /* i : Q LSPs for primary channel */ + const Word16 tdm_lsfQ_PCh_fx[M], /* i : Q LSFs for primary channel */ const int16_t use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ const int16_t last_element_mode, /* i : last element mode */ const int32_t last_element_brate, /* i : last element bitrate */ @@ -78,31 +78,31 @@ ivas_error acelp_core_dec_ivas_fx( const int16_t read_sid_info /* i : read SID info flag */ ) { - Word32 synth_fx[960], save_hb_synth_fx[960]/*, bwe_exc_extended_fx[L_FRAME32k + NL_BUFF_OFFSET]*/; - - Word16 old_exc_fx[L_EXC_DEC], *exc_fx; /* excitation signal buffer */ - Word16 syn_tmp_fx[L_FRAME16k + L_SUBFR], *psyn_fx; /* synthesis signal buffer */ - int16_t output_frame; /* frame length at output sampling freq. */ - Word16 lsf_new_fx[M]; /* LSFs at the end of the frame Qlog2(2.56) */ - Word16 lsp_new_fx[M]; /* LSPs at the end of the frame Q15 */ - Word16 lsp_mid_fx[M]; /* LSPs in the middle of the frame */ + Word32 synth_fx[960], save_hb_synth_fx[960] /*, bwe_exc_extended_fx[L_FRAME32k + NL_BUFF_OFFSET]*/; + + Word16 old_exc_fx[L_EXC_DEC], *exc_fx; /* excitation signal buffer */ + Word16 syn_tmp_fx[L_FRAME16k + L_SUBFR], *psyn_fx; /* synthesis signal buffer */ + int16_t output_frame; /* frame length at output sampling freq. */ + Word16 lsf_new_fx[M]; /* LSFs at the end of the frame Qlog2(2.56) */ + Word16 lsp_new_fx[M]; /* LSPs at the end of the frame Q15 */ + Word16 lsp_mid_fx[M]; /* LSPs in the middle of the frame */ #ifdef MSAN_FIX - Word16 Aq_fx[NB_SUBFR16k * ( M + 1 )] = { 0 }; /* A(q) quantized for the 4 subframes */ + Word16 Aq_fx[NB_SUBFR16k * ( M + 1 )] = { 0 }; /* A(q) quantized for the 4 subframes */ #else Word16 Aq_fx[NB_SUBFR16k * ( M + 1 )]; /* A(q) quantized for the 4 subframes */ #endif - Word16 old_exc2_fx[L_FRAME16k + L_EXC_MEM], *exc2_fx; /* total excitation buffer */ - Word16 mem_tmp_fx[M]; /* temporary synthesis filter memory */ - Word32 enr_q_fx; /* E information for FER protection */ - Word16 tmp_noise_fx; /* Long term temporary noise energy */ - Word16 Es_pred_fx; /* predicted scaled innov. energy Q8 */ - Word16 FEC_pitch_fx; /* FEC pitch */ + Word16 old_exc2_fx[L_FRAME16k + L_EXC_MEM], *exc2_fx; /* total excitation buffer */ + Word16 mem_tmp_fx[M]; /* temporary synthesis filter memory */ + Word32 enr_q_fx; /* E information for FER protection */ + Word16 tmp_noise_fx; /* Long term temporary noise energy */ + Word16 Es_pred_fx; /* predicted scaled innov. energy Q8 */ + Word16 FEC_pitch_fx; /* FEC pitch */ #ifdef MSAN_FIX Word16 old_bwe_exc_fx[( ( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2 )] = { 0 }; /* excitation buffer */ #else Word16 old_bwe_exc_fx[( ( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2 )]; /* excitation buffer */ #endif - Word16 *bwe_exc_fx; /* Excitation for SWB TBE */ + Word16 *bwe_exc_fx; /* Excitation for SWB TBE */ int16_t i, j, int_fs; int16_t tc_subfr; int16_t allow_cn_step; @@ -137,11 +137,11 @@ ivas_error acelp_core_dec_ivas_fx( Word32 bpf_error_signal_fx[L_FRAME16k]; #ifdef MSAN_FIX - set32_fx(bpf_error_signal_fx, 0, L_FRAME16k); + set32_fx( bpf_error_signal_fx, 0, L_FRAME16k ); #endif Word16 bpf_error_signal_16fx[L_FRAME16k]; #ifdef MSAN_FIX - set_s(bpf_error_signal_16fx, 0, L_FRAME16k); + set_s( bpf_error_signal_16fx, 0, L_FRAME16k ); #endif Word16 tmp; @@ -169,7 +169,7 @@ ivas_error acelp_core_dec_ivas_fx( if ( st->core_brate == SID_2k40 ) { FdCng_decodeSID_ivas_fx( st ); - rescale_fdCngDec(st->hFdCngDec, old_NoiseEstExp - st->hFdCngDec->hFdCngCom->sidNoiseEstExp); + rescale_fdCngDec( st->hFdCngDec, old_NoiseEstExp - st->hFdCngDec->hFdCngCom->sidNoiseEstExp ); } for ( i = 0; i < NPART; i++ ) { @@ -179,8 +179,9 @@ ivas_error acelp_core_dec_ivas_fx( ApplyFdCng_ivas_fx( NULL, 0, NULL, 0, NULL, NULL, NULL, st, 0, 0 ); - if (st->hFdCngDec->hFdCngCom->cngNoiseLevelExp < 0) { - Scale_sig32(st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp); + if ( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp < 0 ) + { + Scale_sig32( st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ); st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 0; } } @@ -189,21 +190,20 @@ ivas_error acelp_core_dec_ivas_fx( configureFdCngDec_fx( st->hFdCngDec, st->bwidth, ACELP_14k25, st->L_frame, st->last_L_frame, st->element_mode ); /* decode CNG parameters */ - CNG_dec_fx( st, last_element_mode, Aq_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step, sid_bw, q_env_fx); - + CNG_dec_fx( st, last_element_mode, Aq_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step, sid_bw, q_env_fx ); + /* comfort noise generation */ CNG_exc_fx( st->core_brate, st->L_frame, &st->hTdCngDec->Enew_fx, &st->hTdCngDec->cng_seed, NULL, NULL, &st->lp_ener_fx, st->last_core_brate, &st->first_CNG, &( st->hTdCngDec->cng_ener_seed ), NULL, allow_cn_step, &st->hTdCngDec->last_allow_cn_step, st->prev_Q_exc, st->Q_exc, st->hTdCngDec->num_ho, q_env_fx, st->hTdCngDec->lp_env_fx, st->hTdCngDec->old_env_fx, st->hTdCngDec->exc_mem_fx, st->hTdCngDec->exc_mem1_fx, sid_bw, &st->hTdCngDec->cng_ener_seed1, NULL, st->Opt_AMR_WB, st->element_mode ); - + Copy( Aq_fx, st->Aq_cng, M + 1 ); /* update old LSP and LSF vector */ Copy( lsf_new_fx, st->lsf_old_fx, M ); Copy( lsp_new_fx, st->lsp_old_fx, M ); - } - set_s( output_fx, 0, output_frame ); /* output and synth are not used in DFT domain CNG generation and the decoder output is unaffected if they are left uninitalized */ - set_s( synth_fx16, 0, output_frame ); /* They are however read in a few places which causes errors in the valgrind tests. Simplest solution from a code perspective was to set them to zero. */ + set_s( output_fx, 0, output_frame ); /* output and synth are not used in DFT domain CNG generation and the decoder output is unaffected if they are left uninitalized */ + set_s( synth_fx16, 0, output_frame ); /* They are however read in a few places which causes errors in the valgrind tests. Simplest solution from a code perspective was to set them to zero. */ /* CN generation done in DFT domain */ pop_wmops(); @@ -229,7 +229,7 @@ ivas_error acelp_core_dec_ivas_fx( LSF_Q_prediction = -1; - set_s(syn_tmp_fx, 0, L_SUBFR); + set_s( syn_tmp_fx, 0, L_SUBFR ); psyn_fx = syn_tmp_fx + L_SUBFR; syn1_tmp_fx[0] = 0; syn1_tmp_fx[1] = 0; @@ -324,7 +324,7 @@ ivas_error acelp_core_dec_ivas_fx( } avoid_lpc_burst_on_recovery = 0; - if (st->last_con_tcx && NE_16(st->L_frameTCX_past, st->L_frame) && st->last_core != 0) + if ( st->last_con_tcx && NE_16( st->L_frameTCX_past, st->L_frame ) && st->last_core != 0 ) { avoid_lpc_burst_on_recovery = 1; } @@ -396,20 +396,20 @@ ivas_error acelp_core_dec_ivas_fx( } synth_mem_updt2( st->L_frame, st->last_L_frame, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, dec ); Copy( st->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); - Copy_Scale_sig(st->mem_syn2_fx, st->mem_syn1_fx, M, sub(-1, st->Q_syn)); /*Q-1*/ + Copy_Scale_sig( st->mem_syn2_fx, st->mem_syn1_fx, M, sub( -1, st->Q_syn ) ); /*Q-1*/ Copy( st->mem_syn2_fx, st->mem_syn3_fx, M ); } /* update buffer of old subframe pitch values */ - IF(NE_16(st->last_L_frame, st->L_frame)) + IF( NE_16( st->last_L_frame, st->L_frame ) ) { - IF(EQ_16(st->L_frame, L_FRAME)) + IF( EQ_16( st->L_frame, L_FRAME ) ) { - IF(EQ_16(st->last_L_frame, L_FRAME32k)) + IF( EQ_16( st->last_L_frame, L_FRAME32k ) ) { tmpF_fx = 13107; } - ELSE IF(EQ_16(st->last_L_frame, 512)) + ELSE IF( EQ_16( st->last_L_frame, 512 ) ) { tmpF_fx = 16384; } @@ -418,15 +418,15 @@ ivas_error acelp_core_dec_ivas_fx( tmpF_fx = 26214; } - FOR(i = NB_SUBFR16k - NB_SUBFR; i < NB_SUBFR16k; i++) + FOR( i = NB_SUBFR16k - NB_SUBFR; i < NB_SUBFR16k; i++ ) { - st->old_pitch_buf_fx[i - 1] = Mpy_32_16_1(st->old_pitch_buf_fx[i], tmpF_fx); + st->old_pitch_buf_fx[i - 1] = Mpy_32_16_1( st->old_pitch_buf_fx[i], tmpF_fx ); move32(); } - FOR(i = 2 * NB_SUBFR16k - NB_SUBFR; i < 2 * NB_SUBFR16k; i++) + FOR( i = 2 * NB_SUBFR16k - NB_SUBFR; i < 2 * NB_SUBFR16k; i++ ) { - st->old_pitch_buf_fx[i - 2] = Mpy_32_16_1(st->old_pitch_buf_fx[i], tmpF_fx); + st->old_pitch_buf_fx[i - 2] = Mpy_32_16_1( st->old_pitch_buf_fx[i], tmpF_fx ); move32(); } } @@ -434,21 +434,21 @@ ivas_error acelp_core_dec_ivas_fx( { move16(); Word16 exp = 0; - IF(EQ_16(st->last_L_frame,L_FRAME32k)) + IF( EQ_16( st->last_L_frame, L_FRAME32k ) ) { tmpF_fx = 16384; } - ELSE IF(EQ_16(st->last_L_frame,512)) + ELSE IF( EQ_16( st->last_L_frame, 512 ) ) { tmpF_fx = 20480; } ELSE /* st->last_L_frame == L_FRAME12k8 */ { - tmpF_fx = 20480; //Q14 + tmpF_fx = 20480; // Q14 exp = 1; } - FOR(i = 2 * NB_SUBFR - 1; i >= NB_SUBFR; i--) + FOR( i = 2 * NB_SUBFR - 1; i >= NB_SUBFR; i-- ) { st->old_pitch_buf_fx[i + 2] = Mpy_32_16_1( L_shl( st->old_pitch_buf_fx[i], exp ), tmpF_fx ); move32(); @@ -456,7 +456,7 @@ ivas_error acelp_core_dec_ivas_fx( st->old_pitch_buf_fx[NB_SUBFR + 1] = st->old_pitch_buf_fx[NB_SUBFR + 2]; move32(); - FOR(i = NB_SUBFR - 1; i >= 0; i--) + FOR( i = NB_SUBFR - 1; i >= 0; i-- ) { st->old_pitch_buf_fx[i + 1] = Mpy_32_16_1( L_shl( st->old_pitch_buf_fx[i], exp ), tmpF_fx ); move32(); @@ -466,16 +466,16 @@ ivas_error acelp_core_dec_ivas_fx( } } - IF(NE_16(st->bfi_pitch_frame, st->L_frame)) + IF( NE_16( st->bfi_pitch_frame, st->L_frame ) ) { - IF(EQ_16(st->L_frame, L_FRAME)) + IF( EQ_16( st->L_frame, L_FRAME ) ) { move16(); - IF(EQ_16(st->bfi_pitch_frame, L_FRAME32k)) + IF( EQ_16( st->bfi_pitch_frame, L_FRAME32k ) ) { tmpF_fx = 13107; } - ELSE IF(EQ_16(st->bfi_pitch_frame, 512)) + ELSE IF( EQ_16( st->bfi_pitch_frame, 512 ) ) { tmpF_fx = 16384; } @@ -483,7 +483,7 @@ ivas_error acelp_core_dec_ivas_fx( { tmpF_fx = 26214; } - st->bfi_pitch_fx = mult_r(st->bfi_pitch_fx, tmpF_fx); + st->bfi_pitch_fx = mult_r( st->bfi_pitch_fx, tmpF_fx ); st->bfi_pitch_frame = L_FRAME; move16(); } @@ -491,17 +491,17 @@ ivas_error acelp_core_dec_ivas_fx( { move16(); Word16 exp = 0; - IF(EQ_16(st->bfi_pitch_frame,L_FRAME32k)) + IF( EQ_16( st->bfi_pitch_frame, L_FRAME32k ) ) { tmpF_fx = 16384; } - ELSE IF(EQ_16(st->bfi_pitch_frame,512)) + ELSE IF( EQ_16( st->bfi_pitch_frame, 512 ) ) { tmpF_fx = 20480; } ELSE /* st->bfi_pitch_frame == L_FRAME12k8 */ { - tmpF_fx = 20480; //Q14 + tmpF_fx = 20480; // Q14 exp = 1; } st->bfi_pitch_fx = mult_r( shl_sat( st->bfi_pitch_fx, exp ), tmpF_fx ); @@ -554,9 +554,10 @@ ivas_error acelp_core_dec_ivas_fx( if ( st->cng_type == LP_CNG ) { CNG_dec_fx( st, last_element_mode, Aq_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step, sid_bw, q_env_fx ); - for (int nsf = 0; nsf < NB_SUBFR16k; nsf++) { - Scale_sig(Aq_fx + (nsf * (M + 1)), M + 1, norm_s(Aq_fx[nsf * (M + 1)]) - Q2); - Aq_fx[nsf * (M + 1)] = ONE_IN_Q12; + for ( int nsf = 0; nsf < NB_SUBFR16k; nsf++ ) + { + Scale_sig( Aq_fx + ( nsf * ( M + 1 ) ), M + 1, norm_s( Aq_fx[nsf * ( M + 1 )] ) - Q2 ); + Aq_fx[nsf * ( M + 1 )] = ONE_IN_Q12; } Copy( Aq_fx, st->Aq_cng, M + 1 ); @@ -567,7 +568,6 @@ ivas_error acelp_core_dec_ivas_fx( local_element_mode = IVAS_SCE; /* For DFT Stereo mono decoding, run CNG_exc as in SCE */ } CNG_exc_fx( st->core_brate, st->L_frame, &st->hTdCngDec->Enew_fx, &st->hTdCngDec->cng_seed, exc_fx, exc2_fx, &st->lp_ener_fx, st->last_core_brate, &st->first_CNG, &( st->hTdCngDec->cng_ener_seed ), bwe_exc_fx, allow_cn_step, &st->hTdCngDec->last_allow_cn_step, st->prev_Q_exc, st->Q_exc, st->hTdCngDec->num_ho, q_env_fx, st->hTdCngDec->lp_env_fx, st->hTdCngDec->old_env_fx, st->hTdCngDec->exc_mem_fx, st->hTdCngDec->exc_mem1_fx, sid_bw, &st->hTdCngDec->cng_ener_seed1, exc3_fx, st->Opt_AMR_WB, local_element_mode ); - } else { @@ -576,8 +576,8 @@ ivas_error acelp_core_dec_ivas_fx( { Word16 old_NoiseEstExp = st->hFdCngDec->hFdCngCom->sidNoiseEstExp; FdCng_decodeSID_ivas_fx( st ); - rescale_fdCngDec(st->hFdCngDec, old_NoiseEstExp - st->hFdCngDec->hFdCngCom->sidNoiseEstExp); - Scale_sig(st->hFdCngDec->hFdCngCom->A_cng, M + 1, norm_s(st->hFdCngDec->hFdCngCom->A_cng[0]) - Q2); + rescale_fdCngDec( st->hFdCngDec, old_NoiseEstExp - st->hFdCngDec->hFdCngCom->sidNoiseEstExp ); + Scale_sig( st->hFdCngDec->hFdCngCom->A_cng, M + 1, norm_s( st->hFdCngDec->hFdCngCom->A_cng[0] ) - Q2 ); *sid_bw = 0; } @@ -590,18 +590,19 @@ ivas_error acelp_core_dec_ivas_fx( st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] = L_add( Mpy_32_32( STEREO_DFT_FD_FILT_Q31, st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] ), Mpy_32_32( STEREO_DFT_FD_FILT_COMP_Q31, st->hFdCngDec->hFdCngCom->sidNoiseEst[i] ) ); } - Word16 new_sidNoiseEstExp = 31 - Q4; - Scale_sig32(st->hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART, st->hFdCngDec->hFdCngCom->sidNoiseEstExp - new_sidNoiseEstExp); - Scale_sig32(st->hFdCngDec->hFdCngCom->sidNoiseEst, NPART, st->hFdCngDec->hFdCngCom->sidNoiseEstExp - new_sidNoiseEstExp); + Word16 new_sidNoiseEstExp = 31 - Q4; + Scale_sig32( st->hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART, st->hFdCngDec->hFdCngCom->sidNoiseEstExp - new_sidNoiseEstExp ); + Scale_sig32( st->hFdCngDec->hFdCngCom->sidNoiseEst, NPART, st->hFdCngDec->hFdCngCom->sidNoiseEstExp - new_sidNoiseEstExp ); st->hFdCngDec->hFdCngCom->sidNoiseEstExp = new_sidNoiseEstExp; Word16 new_cngNoiseLevelExp = 31 - Q4; - Scale_sig32(st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp - new_cngNoiseLevelExp); + Scale_sig32( st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp - new_cngNoiseLevelExp ); st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = new_cngNoiseLevelExp; - ApplyFdCng_ivas_fx(psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); + ApplyFdCng_ivas_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); - if (st->hFdCngDec->hFdCngCom->cngNoiseLevelExp < 0) { - Scale_sig32(st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp); + if ( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp < 0 ) + { + Scale_sig32( st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ); st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 0; } } @@ -617,9 +618,9 @@ ivas_error acelp_core_dec_ivas_fx( } } - generate_comfort_noise_dec_fx(NULL, NULL, NULL, st, &(st->Q_exc), 1, nchan_out); + generate_comfort_noise_dec_fx( NULL, NULL, NULL, st, &( st->Q_exc ), 1, nchan_out ); - FdCng_exc(st->hFdCngDec->hFdCngCom, &st->CNG_mode, st->L_frame, st->lsp_old_fx, st->first_CNG, st->lspCNG_fx, Aq_fx, lsp_new_fx, lsf_new_fx, exc_fx, exc2_fx, bwe_exc_fx); + FdCng_exc( st->hFdCngDec->hFdCngCom, &st->CNG_mode, st->L_frame, st->lsp_old_fx, st->first_CNG, st->lspCNG_fx, Aq_fx, lsp_new_fx, lsf_new_fx, exc_fx, exc2_fx, bwe_exc_fx ); Copy( exc2_fx, exc3_fx, st->L_frame ); } @@ -627,28 +628,29 @@ ivas_error acelp_core_dec_ivas_fx( Word16 delta_mem_scale = 3; move16(); test(); - if (LT_32(st->lp_ener_fx, 40) && EQ_16(st->cng_type, LP_CNG)) /* very low energy frames, less than 0.3125 */ + if ( LT_32( st->lp_ener_fx, 40 ) && EQ_16( st->cng_type, LP_CNG ) ) /* very low energy frames, less than 0.3125 */ { delta_mem_scale = 0; move16(); } i = st->Q_exc; - IF (st->hMusicPF && st->hGSCDec) { - Rescale_exc(st->hMusicPF->dct_post_old_exc_fx, exc_fx, bwe_exc_fx, st->hGSCDec->last_exc_dct_in_fx, st->L_frame, - st->L_frame* HIBND_ACB_L_FAC, 0, &(st->Q_exc), st->Q_subfr, NULL, 0, INACTIVE); - } - IF(st->hPFstat != NULL) - { - Rescale_mem(st->Q_exc, &st->prev_Q_syn, &st->Q_syn, st->mem_syn2_fx, st->mem_syn_clas_estim_fx, delta_mem_scale, - &st->mem_deemph_fx, st->hBPF->pst_old_syn_fx, &st->hBPF->pst_mem_deemp_err_fx, &st->agc_mem_fx[1], st->hPFstat, 0, 0, NULL); - } - ELSE - { - Rescale_mem(st->Q_exc, &st->prev_Q_syn, &st->Q_syn, st->mem_syn2_fx, st->mem_syn_clas_estim_fx, delta_mem_scale, - &st->mem_deemph_fx, NULL, NULL, &st->agc_mem_fx[1], NULL, 0, 0, NULL); - } - Copy_Scale_sig(exc2_fx, exc2_fx, st->L_frame, sub(st->Q_exc, i)); - + IF( st->hMusicPF && st->hGSCDec ) + { + Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, exc_fx, bwe_exc_fx, st->hGSCDec->last_exc_dct_in_fx, st->L_frame, + st->L_frame * HIBND_ACB_L_FAC, 0, &( st->Q_exc ), st->Q_subfr, NULL, 0, INACTIVE ); + } + IF( st->hPFstat != NULL ) + { + Rescale_mem( st->Q_exc, &st->prev_Q_syn, &st->Q_syn, st->mem_syn2_fx, st->mem_syn_clas_estim_fx, delta_mem_scale, + &st->mem_deemph_fx, st->hBPF->pst_old_syn_fx, &st->hBPF->pst_mem_deemp_err_fx, &st->agc_mem_fx[1], st->hPFstat, 0, 0, NULL ); + } + ELSE + { + Rescale_mem( st->Q_exc, &st->prev_Q_syn, &st->Q_syn, st->mem_syn2_fx, st->mem_syn_clas_estim_fx, delta_mem_scale, + &st->mem_deemph_fx, NULL, NULL, &st->agc_mem_fx[1], NULL, 0, 0, NULL ); + } + Copy_Scale_sig( exc2_fx, exc2_fx, st->L_frame, sub( st->Q_exc, i ) ); + /* update past excitation signals for LD music post-filter */ if ( st->hMusicPF != NULL ) { @@ -674,18 +676,17 @@ ivas_error acelp_core_dec_ivas_fx( CNG_reset_dec_fx( st, pitch_buf_fx, voice_factors_fx ); /* update st->mem_syn1 for ACELP core switching */ - Copy_Scale_sig( st->mem_syn3_fx, st->mem_syn1_fx, M, sub(-1, st->Q_syn)); + Copy_Scale_sig( st->mem_syn3_fx, st->mem_syn1_fx, M, sub( -1, st->Q_syn ) ); /* update old synthesis for classification */ Copy( syn1_fx + st->L_frame - L_SYN_MEM_CLAS_ESTIM, st->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM ); /* save and delay synthesis to be used by SWB BWE */ - Copy_Scale_sig(syn1_fx, temp_buf_fx, st->L_frame, sub(-1, st->Q_syn)); + Copy_Scale_sig( syn1_fx, temp_buf_fx, st->L_frame, sub( -1, st->Q_syn ) ); if ( st->hBWE_FD != NULL ) { - save_old_syn_fx(st->L_frame, syn1_fx, old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx); + save_old_syn_fx( st->L_frame, syn1_fx, old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx ); } - } /*----------------------------------------------------------------* @@ -722,7 +723,7 @@ ivas_error acelp_core_dec_ivas_fx( if ( st->coder_type == TRANSITION && tc_subfr < L_SUBFR && st->L_frame == L_FRAME ) { - config_acelp1_IVAS( DEC, st->total_brate, st->core_brate, st->core, st->extl_orig, st->extl_brate_orig, st->L_frame, -1, &( st->acelp_cfg ), st->next_bit_pos, st->coder_type, tc_subfr, 2, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); + config_acelp1_IVAS( DEC, st->total_brate, st->core_brate, st->core, st->extl_orig, st->extl_brate_orig, st->L_frame, -1, &( st->acelp_cfg ), st->next_bit_pos, st->coder_type, tc_subfr, 2, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); } } @@ -754,7 +755,7 @@ ivas_error acelp_core_dec_ivas_fx( if ( !tdm_lp_reuse_flag ) { - lsf_dec_fx( st, tc_subfr, Aq_fx, &LSF_Q_prediction, lsf_new_fx, lsp_new_fx, lsp_mid_fx, tdm_low_rate_mode/*, tdm_lsfQ_PCh*/ ); + lsf_dec_fx( st, tc_subfr, Aq_fx, &LSF_Q_prediction, lsf_new_fx, lsp_new_fx, lsp_mid_fx, tdm_low_rate_mode /*, tdm_lsfQ_PCh*/ ); } else { @@ -765,7 +766,7 @@ ivas_error acelp_core_dec_ivas_fx( int16_t beta_index; beta_index = get_next_indice( st, TDM_IC_LSF_PRED_BITS ); - tdm_SCh_lsf_reuse_fx(DEC, st->element_brate, lsf_new_fx, lsp_new_fx, tdm_lsfQ_PCh_fx, NULL, &beta_index); + tdm_SCh_lsf_reuse_fx( DEC, st->element_brate, lsf_new_fx, lsp_new_fx, tdm_lsfQ_PCh_fx, NULL, &beta_index ); } else { @@ -798,165 +799,357 @@ ivas_error acelp_core_dec_ivas_fx( st->stab_fac_fx = lsf_stab_ivas_fx( lsf_new_fx, st->lsf_old_fx, 0, st->L_frame ); } #ifndef MSAN_FIX - for (int nsf = 0; nsf < NB_SUBFR16k; nsf++) { + for ( int nsf = 0; nsf < NB_SUBFR16k; nsf++ ) + { #else FOR( int nsf = 0; nsf < st->nb_subfr; nsf++ ) #endif - { - Scale_sig(Aq_fx + (nsf * (M + 1)), M + 1, norm_s(Aq_fx[nsf * (M + 1)]) - Q2); - Aq_fx[nsf * (M + 1)] = ONE_IN_Q12; - } - if ( st->last_core == HQ_CORE && st->element_mode > EVS_MONO ) - { - /* Prepare ACB memory from last HQ frame */ - old_exc_s_fx = st->old_exc_fx + L_EXC_MEM_DEC - st->L_frame; - tmpF_fx = *old_exc_s_fx; - st->mem_deemph_fx = old_exc_s_fx[st->L_frame - 1]; - preemph_fx( old_exc_s_fx, st->preemph_fac, L_FRAME16k, &tmpF_fx ); - Copy(old_exc_s_fx + st->L_frame - M, st->mem_syn2_fx, M ); - Residu3_fx( Aq_fx, old_exc_s_fx, old_exc_fx + L_EXC_MEM_DEC - st->L_frame, st->L_frame, 0 ); + { + Scale_sig( Aq_fx + ( nsf * ( M + 1 ) ), M + 1, norm_s( Aq_fx[nsf * ( M + 1 )] ) - Q2 ); + Aq_fx[nsf * ( M + 1 )] = ONE_IN_Q12; + } + if ( st->last_core == HQ_CORE && st->element_mode > EVS_MONO ) + { + /* Prepare ACB memory from last HQ frame */ + old_exc_s_fx = st->old_exc_fx + L_EXC_MEM_DEC - st->L_frame; + tmpF_fx = *old_exc_s_fx; + st->mem_deemph_fx = old_exc_s_fx[st->L_frame - 1]; + preemph_fx( old_exc_s_fx, st->preemph_fac, L_FRAME16k, &tmpF_fx ); + Copy( old_exc_s_fx + st->L_frame - M, st->mem_syn2_fx, M ); + Residu3_fx( Aq_fx, old_exc_s_fx, old_exc_fx + L_EXC_MEM_DEC - st->L_frame, st->L_frame, 0 ); #ifdef FIX_737_HQ_ACELP_SWITCH_SCALING_ERROR - Scale_sig( old_exc_fx + L_EXC_MEM_DEC - st->L_frame, st->L_frame, st->Q_exc ); + Scale_sig( old_exc_fx + L_EXC_MEM_DEC - st->L_frame, st->L_frame, st->Q_exc ); #endif - } + } - if ( st->last_core != ACELP_CORE && st->element_mode > EVS_MONO ) - { - /* Prepare ACB memory of old_bwe_exc */ - if ( st->L_frame == L_FRAME ) + if ( st->last_core != ACELP_CORE && st->element_mode > EVS_MONO ) { - lerp( old_exc_fx, old_bwe_exc_fx, L_EXC_MEM_DEC * HIBND_ACB_L_FAC, L_EXC_MEM_DEC ); + /* Prepare ACB memory of old_bwe_exc */ + if ( st->L_frame == L_FRAME ) + { + lerp( old_exc_fx, old_bwe_exc_fx, L_EXC_MEM_DEC * HIBND_ACB_L_FAC, L_EXC_MEM_DEC ); + } + else + { + lerp( old_exc_fx, old_bwe_exc_fx, L_EXC_MEM_DEC * 2, L_EXC_MEM_DEC ); + } } - else + + /*-----------------------------------------------------------------* + * FEC - first good frame after lost frame(s) (possibility to correct the ACB) + *-----------------------------------------------------------------*/ + + if ( st->acelp_cfg.FEC_mode > 0 ) { - lerp( old_exc_fx, old_bwe_exc_fx, L_EXC_MEM_DEC * 2, L_EXC_MEM_DEC ); + last_pulse_pos = 0; + + /* decode the last glottal pulse position */ + T0_tmp = FEC_pos_dec_fx( st, &last_pulse_pos, &enr_q_fx, nb_bits ); + + if ( st->last_core != HQ_CORE || ( st->last_core == HQ_CORE && st->last_con_tcx ) ) + { + if ( st->clas_dec == SIN_ONSET && last_pulse_pos != 0 && st->prev_bfi == 1 ) + { + FEC_SinOnset_fx( old_exc_fx + L_EXC_MEM_DEC - L_EXC_MEM, last_pulse_pos, T0_tmp, enr_q_fx, Aq_fx, st->L_frame, st->Q_exc ); + } + else if ( ( st->coder_type == GENERIC || st->coder_type == VOICED ) && last_pulse_pos != 0 && st->old_bfi_cnt == 1 && st->hWIDec != NULL ) + { + do_WI = FEC_enhACB_fx( st->L_frame, st->last_L_frame, old_exc_fx + L_EXC_MEM_DEC - L_EXC_MEM, T0_tmp, last_pulse_pos, st->bfi_pitch_fx ); + } + } } - } - /*-----------------------------------------------------------------* - * FEC - first good frame after lost frame(s) (possibility to correct the ACB) - *-----------------------------------------------------------------*/ + /*------------------------------------------------------------* + * In case of first frame after an erasure and transition from voiced to unvoiced or inactive + * redo the LPC interpolation + *------------------------------------------------------------*/ - if ( st->acelp_cfg.FEC_mode > 0 ) - { - last_pulse_pos = 0; + if ( st->stab_fac_fx == 0 && st->old_bfi_cnt > 0 && st->clas_dec != VOICED_CLAS && st->clas_dec != ONSET && st->relax_prev_lsf_interp == 0 && !( st->element_mode == IVAS_CPE_TD && st->idchan == 1 ) ) + { + int_lsp4_fx( st->L_frame, st->lsp_old_fx, lsp_mid_fx, lsp_new_fx, Aq_fx, M, 2 ); + } + + /*---------------------------------------------------------------* + * Decoding of the scaled predicted innovation energy + *---------------------------------------------------------------*/ - /* decode the last glottal pulse position */ - T0_tmp = FEC_pos_dec_fx( st, &last_pulse_pos, &enr_q_fx, nb_bits ); + if ( nb_bits > 0 ) + { + indice = get_next_indice( st, nb_bits ); + Es_pred_dec_fx( &Es_pred_fx, indice, nb_bits, uc_two_stage_flag ); + } - if ( st->last_core != HQ_CORE || ( st->last_core == HQ_CORE && st->last_con_tcx ) ) + /*------------------------------------------------------------* + * Decode excitation according to coding type + *------------------------------------------------------------*/ + + if ( tdm_low_rate_mode ) /* tdm stereo low rate mode */ { - if ( st->clas_dec == SIN_ONSET && last_pulse_pos != 0 && st->prev_bfi == 1 ) + if ( st->coder_type <= UNVOICED ) { - FEC_SinOnset_fx( old_exc_fx + L_EXC_MEM_DEC - L_EXC_MEM, last_pulse_pos, T0_tmp, enr_q_fx, Aq_fx, st->L_frame, st->Q_exc ); + tdm_low_rate_dec_fx( st, dct_exc_tmp_fx /*, &tmp_noise*/, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, lsf_new_fx ); + tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/ } - else if ( ( st->coder_type == GENERIC || st->coder_type == VOICED ) && last_pulse_pos != 0 && st->old_bfi_cnt == 1 && st->hWIDec != NULL ) + else /* GENERIC */ { - do_WI = FEC_enhACB_fx( st->L_frame, st->last_L_frame, old_exc_fx + L_EXC_MEM_DEC - L_EXC_MEM, T0_tmp, last_pulse_pos, st->bfi_pitch_fx ); + decod_gen_2sbfr_ivas_fx( st, sharpFlag, Aq_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, gain_buf_fx, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx ); + + if ( st->element_mode == IVAS_CPE_TD ) + { + tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/ + } } } - } + else if ( st->nelp_mode_dec ) + { + /* SC-VBR - NELP frames */ + Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, -st->Q_exc ); + st->Q_exc = 0; + move16(); + /* SC-VBR - NELP frames */ + decod_nelp_fx( st, &tmp_noise_fx, pitch_buf_fx, exc_fx, exc2_fx, voice_factors_fx, bwe_exc_fx, &st->Q_exc, st->bfi, gain_buf_fx ); + Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32) 0, &( st->Q_exc ), st->Q_subfr, exc2_fx, L_FRAME, st->coder_type ); + } + else if ( st->coder_type == UNVOICED ) + { + /* UNVOICED frames */ + decod_unvoiced_ivas_fx( st, Aq_fx, Es_pred_fx, uc_two_stage_flag, st->coder_type, &tmp_noise_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, gain_buf_fx ); + tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/ + } + else if ( st->ppp_mode_dec ) + { + Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, -st->Q_exc ); + st->Q_exc = 0; + /* SC-VBR - PPP frames */ + if ( ( error = decod_ppp_fx( st, Aq_fx, pitch_buf_fx, exc_fx, exc2_fx, st->bfi, gain_buf_fx, voice_factors_fx, bwe_exc_fx ) ) != IVAS_ERR_OK ) + { + return error; + } - /*------------------------------------------------------------* - * In case of first frame after an erasure and transition from voiced to unvoiced or inactive - * redo the LPC interpolation - *------------------------------------------------------------*/ + Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32) 0, &( st->Q_exc ), st->Q_subfr, exc2_fx, L_FRAME, st->coder_type ); + } + else if ( st->coder_type == TRANSITION ) + { + decod_tran_fx( st, st->L_frame, tc_subfr, Aq_fx, Es_pred_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, unbits, sharpFlag, gain_buf_fx ); + } + else if ( st->coder_type == AUDIO || ( st->coder_type == INACTIVE && st->inactive_coder_type_flag ) ) + { + /* AUDIO and INACTIVE frames (coded by GSC technology) */ + decod_audio_ivas_fx( st, dct_exc_tmp_fx, Aq_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, lsf_new_fx, gain_buf_fx +#if 1 // def ADD_LRTD + , + tdm_lp_reuse_flag, tdm_low_rate_mode, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx +#endif + ); + tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/ + } + else + { + /* GENERIC, VOICED and INACTIVE frames (coded by AVQ technology) */ + if ( ( error = decod_gen_voic_ivas_fx( st, st->L_frame, sharpFlag, Aq_fx, Es_pred_fx, do_WI, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, unbits, gain_buf_fx, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx ) ) != IVAS_ERR_OK ) + { + return error; + } - if ( st->stab_fac_fx == 0 && st->old_bfi_cnt > 0 && st->clas_dec != VOICED_CLAS && st->clas_dec != ONSET && st->relax_prev_lsf_interp == 0 && !( st->element_mode == IVAS_CPE_TD && st->idchan == 1 ) ) - { - int_lsp4_fx( st->L_frame, st->lsp_old_fx, lsp_mid_fx, lsp_new_fx, Aq_fx, M, 2 ); - } + if ( st->element_mode == IVAS_CPE_TD ) + { + tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/ + } + } - /*---------------------------------------------------------------* - * Decoding of the scaled predicted innovation energy - *---------------------------------------------------------------*/ + /* synthesis for ACELP core switching and SWB BWE */ + syn_12k8_fx( st->L_frame, Aq_fx, exc_fx, temp_buf_fx, st->mem_syn1_fx, 1, st->Q_exc, -1 ); - if ( nb_bits > 0 ) - { - indice = get_next_indice( st, nb_bits ); - Es_pred_dec_fx( &Es_pred_fx, indice, nb_bits, uc_two_stage_flag ); - } + /* save and delay synthesis to be used by SWB BWE */ + if ( st->hBWE_FD != NULL ) + { + save_old_syn_fx( st->L_frame, temp_buf_fx, old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx ); + } - /*------------------------------------------------------------* - * Decode excitation according to coding type - *------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * Apply energy matching when switching to inactive frames + *-----------------------------------------------------------------*/ - if ( tdm_low_rate_mode ) /* tdm stereo low rate mode */ - { - if ( st->coder_type <= UNVOICED ) + Inac_switch_ematch_ivas_fx( exc2_fx, dct_exc_tmp_fx, st->hGSCDec->lt_ener_per_band_fx, st->coder_type, st->L_frame, st->total_brate, st->Q_exc, st->bfi, st->last_core, st->last_codec_mode, tdm_low_rate_mode, st->element_mode ); + + /*------------------------------------------------------------* + * Decode information and modify the excitation signal of stationary unvoiced frames + *------------------------------------------------------------*/ + + if ( !( st->idchan == 1 && st->element_mode == IVAS_CPE_TD ) && st->nelp_mode_dec != 1 && !( st->element_mode == IVAS_SCE && tdm_low_rate_mode ) ) { - tdm_low_rate_dec_fx( st, dct_exc_tmp_fx/*, &tmp_noise*/, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, lsf_new_fx ); - tmp_noise_fx = shr_r(st->lp_gainc_fx, 3); /*Q0*/ + stat_noise_uv_dec_fx( st, lsp_new_fx, lsp_mid_fx, Aq_fx, exc2_fx, uc_two_stage_flag ); } - else /* GENERIC */ + + /*------------------------------------------------------------* + * Save filter memory in case the synthesis is redone after scaling + * Synthesis at 12k8 Hz sampling rate + *------------------------------------------------------------*/ + + /* update past excitation signals for LD music post-filter */ + if ( st->hMusicPF != NULL ) { - decod_gen_2sbfr_ivas_fx( st, sharpFlag, Aq_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, gain_buf_fx, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx ); + Copy( st->hMusicPF->dct_post_old_exc_fx + L_FRAME, st->hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2 ); + Copy( exc2_fx, st->hMusicPF->dct_post_old_exc_fx + ( DCT_L_POST - L_FRAME - OFFSET2 ), L_FRAME ); + Copy( st->hMusicPF->dct_post_old_exc_fx, exc_buffer_fx, DCT_L_POST - OFFSET2 ); + } - if ( st->element_mode == IVAS_CPE_TD ) + if ( ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) || ( st->GSC_IVAS_mode >= 1 && st->L_frame == L_FRAME ) ) + { + int16_t last_coder_type = st->last_coder_type; + + if ( ( st->idchan == 1 && st->element_mode == IVAS_CPE_TD ) || ( st->GSC_IVAS_mode >= 1 && st->GSC_noisy_speech == 0 ) ) + { + last_coder_type = AUDIO; + } + + Word16 qdct = 0; + /* Extrapolation of the last future part, windowing and high resolution DCT transform */ + Prep_music_postP_fx( exc_buffer_fx, dct_buffer_fx, st->hMusicPF->filt_lfE_fx, st->last_core, st->element_mode, pitch_buf_fx, st->hMusicPF->LDm_enh_lp_gbin_fx, st->Q_exc, &qdct ); + + /* LD music post-filter */ + LD_music_post_filter_fx( st->hMusicPF, dct_buffer_fx, dct_buffer_fx, st->core_brate, &st->hMusicPF->Old_ener_Q, AUDIO, last_coder_type, qdct ); + + /* Inverse DCT transform, retrieval of the aligned excitation, re-synthesis */ + Copy( st->mem_syn2_fx, mem_tmp_fx, M ); + Post_music_postP_fx( dct_buffer_fx, exc2_fx, st->mem_syn2_fx, st->mem_syn2_fx, Aq_fx, psyn_fx, &st->Q_exc, &st->prev_Q_syn, + &st->Q_syn, st->mem_syn_clas_estim_fx, 0, &st->mem_deemph_fx, st->hBPF->pst_old_syn_fx, + &st->hBPF->pst_mem_deemp_err_fx, &st->agc_mem_fx[1], st->hPFstat, temp_buf_fx, mem_tmp_fx ); + } + else + { + /* Core synthesis at 12.8kHz or 16kHz */ + i = 1; + move16(); + if ( EQ_16( st->coder_type, INACTIVE ) ) + { + i = 0; + move16(); + } + /* add extra headroom in case a CNA addition is likely (i.e. st_fx->psf_lp_noise_fx is close to the threshold) */ + Word16 k = 0; + move16(); + test(); + test(); + if ( EQ_16( st->coder_type, INACTIVE ) && st->flag_cna && GE_16( round_fx( L_shl( st->lp_noise, 1 ) ), 15 << 7 ) ) + { + k = 1; + move16(); + } + + Rescale_mem( st->Q_exc, &st->prev_Q_syn, &st->Q_syn, st->mem_syn2_fx, st->mem_syn_clas_estim_fx, 4, &st->mem_deemph_fx, + st->hBPF->pst_old_syn_fx, &st->hBPF->pst_mem_deemp_err_fx, &st->agc_mem_fx[1], st->hPFstat, i, k, temp_buf_fx ); + + Copy( st->mem_syn2_fx, mem_tmp_fx, M ); + syn_12k8_fx( st->L_frame, Aq_fx, exc2_fx, psyn_fx, st->mem_syn2_fx, 1, st->Q_exc, st->Q_syn ); + + if ( st->hMusicPF != NULL ) { - tmp_noise_fx = shr_r(st->lp_gainc_fx, 3); /*Q0*/ + for ( i = 0; i < DCT_L_POST; i++ ) + { + st->hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( ( 1228 << ( 16 ) ), 22938, st->hMusicPF->filt_lfE_fx[i] ) ); + } } } + + /*------------------------------------------------------------* + * FEC - Estimate the classification information + *------------------------------------------------------------*/ + + FEC_clas_estim_fx( st, st->Opt_AMR_WB, st->L_frame, &st->clas_dec, st->coder_type, pitch_buf_fx, + psyn_fx, &st->lp_ener_FER_fx, &st->decision_hyst, + NULL, NULL, NULL, NULL, 0, NULL, st->core_brate, st->Q_syn, temp_buf_fx, + st->mem_syn_clas_estim_fx, &st->classifier_Q_mem_syn, + 0, 0, 0, st->last_core_brate, st->acelp_cfg.FEC_mode ); + /*------------------------------------------------------------* + * FEC - Estimate pitch + *------------------------------------------------------------*/ + + FEC_pitch_estim_fx( st->Opt_AMR_WB, st->last_core, st->L_frame, st->clas_dec, st->last_good, pitch_buf_fx, st->old_pitch_buf_fx, + &st->bfi_pitch_fx, &st->bfi_pitch_frame, &st->upd_cnt, st->coder_type, st->element_mode ); + + /*------------------------------------------------------------* + * FEC - Smooth the speech energy evolution when recovering after a BAD frame + * (smoothing is performed in the excitation domain and signal is resynthesized after) + *------------------------------------------------------------*/ + + move16(); + Copy_Scale_sig( pitch_buf_fx, pitch_buf_tmp, NB_SUBFR16k, -Q6 ); + FEC_scale_syn_fx( st->L_frame, &update_flg, st->clas_dec, st->last_good, psyn_fx, pitch_buf_tmp, st->enr_old_fx, enr_q_fx, st->coder_type, LSF_Q_prediction, + &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate, + exc_fx, exc2_fx, Aq_fx, &st->old_enr_LP, mem_tmp_fx, st->mem_syn2_fx, st->Q_exc, st->Q_syn, avoid_lpc_burst_on_recovery, 0 ); + + /* estimate the pitch-synchronous speech energy per sample to be used when normal operation recovers */ + if ( ( st->idchan == 1 && st->element_mode == IVAS_CPE_TD && st->total_brate <= ACELP_7k20 ) || ( st->total_brate == ACELP_7k20 ) || ( st->total_brate == ACELP_8k00 ) ) + { + frame_ener_fx( st->L_frame, st->clas_dec, psyn_fx, pitch_buf_tmp[sub( shr( st->L_frame, 6 ), 1 )], &st->enr_old_fx, st->L_frame, st->Q_syn, 3, 0 ); + } } - else if ( st->nelp_mode_dec ) + + } /* End of GOOD FRAME */ + + /*----------------------------------------------------------------* + * BAD frame + *----------------------------------------------------------------*/ + + else + { + /* SC-VBR */ + IF( EQ_16( st->last_nelp_mode_dec, 1 ) ) { - /* SC-VBR - NELP frames */ - Scale_sig(exc_fx - L_EXC_MEM, L_EXC_MEM, -st->Q_exc); - st->Q_exc = 0; + st->nelp_mode_dec = 1; move16(); - /* SC-VBR - NELP frames */ - decod_nelp_fx( st, &tmp_noise_fx, pitch_buf_fx, exc_fx, exc2_fx, voice_factors_fx, bwe_exc_fx, &st->Q_exc, st->bfi, gain_buf_fx); - Rescale_exc(st->hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32)0, &(st->Q_exc), st->Q_subfr, exc2_fx, L_FRAME, st->coder_type); } - else if ( st->coder_type == UNVOICED ) + + /* long burst frame erasures */ + IF( GT_16( st->nbLostCmpt, 5 ) && GE_16( st->clas_dec, VOICED_CLAS ) && LT_16( st->clas_dec, INACTIVE_CLAS ) ) { - /* UNVOICED frames */ - decod_unvoiced_ivas_fx( st, Aq_fx, Es_pred_fx, uc_two_stage_flag, st->coder_type, &tmp_noise_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, gain_buf_fx); - tmp_noise_fx = shr_r(st->lp_gainc_fx, 3); /*Q0*/ + st->last_good = VOICED_TRANSITION; + move16(); } - else if ( st->ppp_mode_dec) - { - Scale_sig(exc_fx - L_EXC_MEM, L_EXC_MEM, -st->Q_exc); - st->Q_exc = 0; - /* SC-VBR - PPP frames */ - if ( ( error = decod_ppp_fx( st, Aq_fx, pitch_buf_fx, exc_fx, exc2_fx, st->bfi, gain_buf_fx, voice_factors_fx, bwe_exc_fx ) ) != IVAS_ERR_OK ) - { - return error; - } - Rescale_exc(st->hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32)0, &(st->Q_exc), st->Q_subfr, exc2_fx, L_FRAME, st->coder_type); + /* LSF estimation and A(z) calculation */ + lsf_dec_bfi( MODE1, lsf_new_fx, st->lsf_old_fx, st->lsf_adaptive_mean_fx, NULL, st->mem_MA_fx, st->mem_AR_fx, st->stab_fac_fx, st->last_coder_type, st->L_frame, st->last_good, st->nbLostCmpt, 0, NULL, NULL, NULL, st->hGSCDec->Last_GSC_pit_band_idx, st->Opt_AMR_WB, 0, st->bwidth ); - } - else if ( st->coder_type == TRANSITION ) + FEC_lsf2lsp_interp( st, st->L_frame, Aq_fx, lsf_new_fx, lsp_new_fx ); +#ifndef MSAN_FIX + for ( int nsf = 0; nsf < NB_SUBFR16k; nsf++ ) { - decod_tran_fx( st, st->L_frame, tc_subfr, Aq_fx, Es_pred_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, unbits, sharpFlag, gain_buf_fx); +#else + FOR( int nsf = 0; nsf < st->nb_subfr; nsf++ ) + { +#endif + Scale_sig( Aq_fx + ( nsf * ( M + 1 ) ), M + 1, norm_s( Aq_fx[nsf * ( M + 1 )] ) - Q2 ); + Aq_fx[nsf * ( M + 1 )] = ONE_IN_Q12; } - else if ( st->coder_type == AUDIO || ( st->coder_type == INACTIVE && st->inactive_coder_type_flag ) ) + if ( st->nelp_mode_dec == 1 ) { - /* AUDIO and INACTIVE frames (coded by GSC technology) */ - decod_audio_ivas_fx( st, dct_exc_tmp_fx, Aq_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, lsf_new_fx, gain_buf_fx -#if 1//def ADD_LRTD - , tdm_lp_reuse_flag, tdm_low_rate_mode, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx -#endif - ); - tmp_noise_fx = shr_r(st->lp_gainc_fx, 3); /*Q0*/ + /* SC-VBR */ + Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, -st->Q_exc ); + st->Q_exc = 0; + move16(); + + decod_nelp_fx( st, &tmp_noise_fx, pitch_buf_fx, exc_fx, exc2_fx, voice_factors_fx, bwe_exc_fx, &st->Q_exc, st->bfi, gain_buf_fx ); + FEC_pitch_fx = pitch_buf_fx[3]; + + Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32) 0, &( st->Q_exc ), st->Q_subfr, exc2_fx, L_FRAME, st->coder_type ); } else { - /* GENERIC, VOICED and INACTIVE frames (coded by AVQ technology) */ - if ( ( error = decod_gen_voic_ivas_fx( st, st->L_frame, sharpFlag, Aq_fx, Es_pred_fx, do_WI, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, unbits, gain_buf_fx, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx) ) != IVAS_ERR_OK ) - { - return error; - } + /* calculation of excitation signal */ + FEC_exc_estim_fx( st, st->L_frame, exc_fx, exc2_fx, dct_exc_tmp_fx, pitch_buf_fx, voice_factors_fx, &FEC_pitch_fx, bwe_exc_fx, lsf_new_fx, &st->Q_exc, &tmp_noise_fx ); - if ( st->element_mode == IVAS_CPE_TD ) - { - tmp_noise_fx = shr_r(st->lp_gainc_fx, 3); /*Q0*/ - } + Rescale_exc( NULL, exc_fx, bwe_exc_fx, st->hGSCDec->last_exc_dct_in_fx, st->L_frame, L_FRAME32k, (Word32) 0, + &( st->Q_exc ), st->Q_subfr, exc2_fx, st->L_frame, st->last_coder_type ); + + tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/ + + /* SC-VBR */ + st->prev_gain_pit_dec_fx = st->lp_gainp_fx; } /* synthesis for ACELP core switching and SWB BWE */ - syn_12k8_fx( st->L_frame, Aq_fx, exc_fx, temp_buf_fx, st->mem_syn1_fx, 1, st->Q_exc, -1); + syn_12k8_fx( st->L_frame, Aq_fx, exc_fx, temp_buf_fx, st->mem_syn1_fx, 1, st->Q_exc, -1 ); /* save and delay synthesis to be used by SWB BWE */ if ( st->hBWE_FD != NULL ) @@ -964,1025 +1157,837 @@ ivas_error acelp_core_dec_ivas_fx( save_old_syn_fx( st->L_frame, temp_buf_fx, old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx ); } - /*-----------------------------------------------------------------* - * Apply energy matching when switching to inactive frames - *-----------------------------------------------------------------*/ - + /* Apply energy matching when switching to inactive frames */ Inac_switch_ematch_ivas_fx( exc2_fx, dct_exc_tmp_fx, st->hGSCDec->lt_ener_per_band_fx, st->coder_type, st->L_frame, st->total_brate, st->Q_exc, st->bfi, st->last_core, st->last_codec_mode, tdm_low_rate_mode, st->element_mode ); - /*------------------------------------------------------------* - * Decode information and modify the excitation signal of stationary unvoiced frames - *------------------------------------------------------------*/ - - if ( !( st->idchan == 1 && st->element_mode == IVAS_CPE_TD ) && st->nelp_mode_dec != 1 && !( st->element_mode == IVAS_SCE && tdm_low_rate_mode ) ) - { - stat_noise_uv_dec_fx(st, lsp_new_fx, lsp_mid_fx, Aq_fx, exc2_fx, uc_two_stage_flag); - } - - /*------------------------------------------------------------* - * Save filter memory in case the synthesis is redone after scaling - * Synthesis at 12k8 Hz sampling rate - *------------------------------------------------------------*/ - /* update past excitation signals for LD music post-filter */ if ( st->hMusicPF != NULL ) { Copy( st->hMusicPF->dct_post_old_exc_fx + L_FRAME, st->hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2 ); Copy( exc2_fx, st->hMusicPF->dct_post_old_exc_fx + ( DCT_L_POST - L_FRAME - OFFSET2 ), L_FRAME ); - Copy( st->hMusicPF->dct_post_old_exc_fx, exc_buffer_fx, DCT_L_POST - OFFSET2 ); - } - - if ( ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) || ( st->GSC_IVAS_mode >= 1 && st->L_frame == L_FRAME ) ) - { - int16_t last_coder_type = st->last_coder_type; - if ( ( st->idchan == 1 && st->element_mode == IVAS_CPE_TD ) || ( st->GSC_IVAS_mode >= 1 && st->GSC_noisy_speech == 0 ) ) + /* Update music post processing values */ + /* Filter energies update */ + for ( i = 0; i < DCT_L_POST; i++ ) { - last_coder_type = AUDIO; + st->hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( ( 1228 << ( 16 ) ), 22938, st->hMusicPF->filt_lfE_fx[i] ) ); } - - Word16 qdct = 0; - /* Extrapolation of the last future part, windowing and high resolution DCT transform */ - Prep_music_postP_fx( exc_buffer_fx, dct_buffer_fx, st->hMusicPF->filt_lfE_fx, st->last_core, st->element_mode, pitch_buf_fx, st->hMusicPF->LDm_enh_lp_gbin_fx, st->Q_exc, &qdct); - - /* LD music post-filter */ - LD_music_post_filter_fx( st->hMusicPF, dct_buffer_fx, dct_buffer_fx, st->core_brate, &st->hMusicPF->Old_ener_Q, AUDIO, last_coder_type, qdct ); - - /* Inverse DCT transform, retrieval of the aligned excitation, re-synthesis */ - Copy( st->mem_syn2_fx, mem_tmp_fx, M ); - Post_music_postP_fx(dct_buffer_fx, exc2_fx, st->mem_syn2_fx, st->mem_syn2_fx, Aq_fx, psyn_fx, &st->Q_exc, &st->prev_Q_syn, - &st->Q_syn, st->mem_syn_clas_estim_fx, 0, &st->mem_deemph_fx, st->hBPF->pst_old_syn_fx, - &st->hBPF->pst_mem_deemp_err_fx, &st->agc_mem_fx[1], st->hPFstat, temp_buf_fx, mem_tmp_fx); - } - else - { - /* Core synthesis at 12.8kHz or 16kHz */ - i = 1; - move16(); - if (EQ_16(st->coder_type, INACTIVE)) + /* Update circular buffer, keep last energy difference unchanged */ + for ( i = 1; i < MAX_LT; i++ ) { - i = 0; - move16(); + st->hMusicPF->LDm_lt_diff_etot_fx[i - 1] = st->hMusicPF->LDm_lt_diff_etot_fx[i]; } - /* add extra headroom in case a CNA addition is likely (i.e. st_fx->psf_lp_noise_fx is close to the threshold) */ - Word16 k = 0; + } + + /* synthesis at 12k8 Hz sampling rate */ + /* add extra headroom in case a CNA addition is likely (i.e. st_fx->psf_lp_noise_fx is close to the threshold) */ + Word16 k = 0; + move16(); + test(); + test(); + if ( EQ_16( st->coder_type, INACTIVE ) && st->flag_cna && GE_16( round_fx( L_shl( st->lp_noise, 1 ) ), 15 << 7 ) ) + { + k = 1; move16(); - test(); - test(); - if (EQ_16(st->coder_type, INACTIVE) && st->flag_cna&&GE_16(round_fx(L_shl(st->lp_noise, 1)), 15 << 7)) - { - k = 1; - move16(); - } + } - Rescale_mem(st->Q_exc, &st->prev_Q_syn, &st->Q_syn, st->mem_syn2_fx, st->mem_syn_clas_estim_fx, 4, &st->mem_deemph_fx, - st->hBPF->pst_old_syn_fx, &st->hBPF->pst_mem_deemp_err_fx, &st->agc_mem_fx[1], st->hPFstat, i, k, temp_buf_fx); + Rescale_mem( st->Q_exc, &st->prev_Q_syn, &st->Q_syn, st->mem_syn2_fx, st->mem_syn_clas_estim_fx, 4, &st->mem_deemph_fx, + st->hBPF->pst_old_syn_fx, &st->hBPF->pst_mem_deemp_err_fx, &st->agc_mem_fx[1], st->hPFstat, 1, k, temp_buf_fx ); + if ( ( st->total_brate == ACELP_7k20 ) || ( st->total_brate == ACELP_8k00 ) ) + { Copy( st->mem_syn2_fx, mem_tmp_fx, M ); - syn_12k8_fx( st->L_frame, Aq_fx, exc2_fx, psyn_fx, st->mem_syn2_fx, 1, st->Q_exc, st->Q_syn); - - if ( st->hMusicPF != NULL ) - { - for ( i = 0; i < DCT_L_POST; i++ ) - { - st->hMusicPF->filt_lfE_fx[i] = round_fx(L_mac((1228 << (16)), 22938, st->hMusicPF->filt_lfE_fx[i])); - } - } } + syn_12k8_fx( st->L_frame, Aq_fx, exc2_fx, psyn_fx, st->mem_syn2_fx, 1, st->Q_exc, st->Q_syn ); - /*------------------------------------------------------------* - * FEC - Estimate the classification information - *------------------------------------------------------------*/ - - FEC_clas_estim_fx(st, st->Opt_AMR_WB, st->L_frame, &st->clas_dec, st->coder_type, pitch_buf_fx, - psyn_fx, &st->lp_ener_FER_fx, &st->decision_hyst, - NULL, NULL, NULL, NULL, 0, NULL, st->core_brate, st->Q_syn, temp_buf_fx, - st->mem_syn_clas_estim_fx, &st->classifier_Q_mem_syn, - 0, 0, 0, st->last_core_brate, st->acelp_cfg.FEC_mode); - /*------------------------------------------------------------* - * FEC - Estimate pitch - *------------------------------------------------------------*/ + /* update buffer for classifier */ + if ( st->hWIDec != NULL ) + { + Copy( exc2_fx + st->L_frame - L_EXC_MEM, st->hWIDec->old_exc2_fx, L_EXC_MEM ); + Copy( psyn_fx + st->L_frame - L_EXC_MEM, st->hWIDec->old_syn2_fx, L_EXC_MEM ); + } + st->prev_Q_exc_fr = st->Q_exc; + st->prev_Q_syn_fr = st->Q_syn; - FEC_pitch_estim_fx(st->Opt_AMR_WB, st->last_core, st->L_frame, st->clas_dec, st->last_good, pitch_buf_fx, st->old_pitch_buf_fx, - &st->bfi_pitch_fx, &st->bfi_pitch_frame, &st->upd_cnt, st->coder_type, st->element_mode); + Copy( psyn_fx + st->L_frame - L_SYN_MEM_CLAS_ESTIM, st->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM ); /*------------------------------------------------------------* * FEC - Smooth the speech energy evolution when recovering after a BAD frame * (smoothing is performed in the excitation domain and signal is resynthesized after) *------------------------------------------------------------*/ - move16(); - Copy_Scale_sig(pitch_buf_fx, pitch_buf_tmp, NB_SUBFR16k, -Q6); - FEC_scale_syn_fx(st->L_frame, &update_flg, st->clas_dec, st->last_good, psyn_fx, pitch_buf_tmp, st->enr_old_fx, enr_q_fx, st->coder_type, LSF_Q_prediction, - &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate, - exc_fx, exc2_fx, Aq_fx, &st->old_enr_LP, mem_tmp_fx, st->mem_syn2_fx, st->Q_exc, st->Q_syn, avoid_lpc_burst_on_recovery, 0); + if ( ( st->total_brate == ACELP_7k20 ) || ( st->total_brate == ACELP_8k00 ) ) + { + Copy_Scale_sig( pitch_buf_fx, pitch_buf_tmp, NB_SUBFR16k, -Q6 ); + + FEC_scale_syn_fx( st->L_frame, &update_flg, st->clas_dec, st->last_good, psyn_fx, pitch_buf_tmp, st->enr_old_fx, enr_q_fx, st->coder_type, LSF_Q_prediction, + &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate, + exc_fx, exc2_fx, Aq_fx, &st->old_enr_LP, mem_tmp_fx, st->mem_syn2_fx, st->Q_exc, st->Q_syn, avoid_lpc_burst_on_recovery, 0 ); + } /* estimate the pitch-synchronous speech energy per sample to be used when normal operation recovers */ - if ( ( st->idchan == 1 && st->element_mode == IVAS_CPE_TD && st->total_brate <= ACELP_7k20 ) || ( st->total_brate == ACELP_7k20 ) || ( st->total_brate == ACELP_8k00 ) ) + frame_ener_fx( st->L_frame, st->last_good, psyn_fx, shr( add( FEC_pitch_fx, 32 ), 6 ), &st->enr_old_fx, st->L_frame, st->Q_syn, 3, 0 ); + + if ( st->nelp_mode_dec != 1 ) { - frame_ener_fx(st->L_frame, st->clas_dec, psyn_fx, pitch_buf_tmp[sub(shr(st->L_frame, 6), 1)], &st->enr_old_fx, st->L_frame, st->Q_syn, 3, 0); + /* modify the excitation signal of stationary unvoiced frames */ + stat_noise_uv_mod_fx( st->coder_type, 0, st->lsp_old_fx, lsp_new_fx, lsp_new_fx, Aq_fx, exc2_fx, st->Q_exc, 1, &st->ge_sm_fx, + &st->uv_count, &st->act_count, st->lspold_s_fx, &st->noimix_seed, &st->min_alpha_fx, + &st->exc_pe_fx, st->core_brate, st->bwidth, &st->Q_stat_noise, &st->Q_stat_noise_ge ); } } - } /* End of GOOD FRAME */ - - /*----------------------------------------------------------------* - * BAD frame - *----------------------------------------------------------------*/ - - else - { - /* SC-VBR */ - IF(EQ_16(st->last_nelp_mode_dec, 1)) + IF( st->hBWE_TD != NULL ) { - st->nelp_mode_dec = 1; - move16(); + IF( EQ_16( st->L_frame, L_FRAME ) ) + { + Copy( Aq_fx + 2 * ( M + 1 ), st->hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) ); + } + ELSE + { + Copy( Aq_fx + 3 * ( M + 1 ), st->hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) ); + } } - /* long burst frame erasures */ - IF(GT_16(st->nbLostCmpt, 5) && GE_16(st->clas_dec, VOICED_CLAS) && LT_16(st->clas_dec, INACTIVE_CLAS)) + /*--------------------------------------------------------* + * Apply NB postfilter in case of 8kHz output + *--------------------------------------------------------*/ + test(); + IF( EQ_16( st->last_bwidth, NB ) && st->hPFstat != NULL ) { - st->last_good = VOICED_TRANSITION; - move16(); + Copy( pitch_buf_fx, pitch_buf_tmp, NB_SUBFR16k ); + IF( EQ_16( st->bwidth, NB ) ) + { + st->hPFstat->on = 1; + move16(); + nb_post_filt_fx( st->L_frame, st->hPFstat, &st->psf_lp_noise_fx, tmp_noise_fx, psyn_fx, Aq_fx, pitch_buf_tmp, st->coder_type, st->BER_detect, 0 ); + } + ELSE + { + st->hPFstat->on = 0; + nb_post_filt_fx( st->L_frame, st->hPFstat, &st->psf_lp_noise_fx, tmp_noise_fx, psyn_fx, Aq_fx, pitch_buf_tmp, AUDIO, st->BER_detect, 0 ); + } + } + else + { + st->psf_lp_noise_fx = round_fx( L_shl( st->lp_noise, 1 ) ); } - /* LSF estimation and A(z) calculation */ - lsf_dec_bfi(MODE1, lsf_new_fx, st->lsf_old_fx, st->lsf_adaptive_mean_fx, NULL, st->mem_MA_fx, st->mem_AR_fx, st->stab_fac_fx, st->last_coder_type, st->L_frame, st->last_good, st->nbLostCmpt, 0, NULL, NULL, NULL, st->hGSCDec->Last_GSC_pit_band_idx, st->Opt_AMR_WB, 0, st->bwidth); + /*------------------------------------------------------------------* + * Perform fixed deemphasis through 1/(1 - g*z^-1) + *-----------------------------------------------------------------*/ - FEC_lsf2lsp_interp(st, st->L_frame, Aq_fx, lsf_new_fx, lsp_new_fx); -#ifndef MSAN_FIX - for (int nsf = 0; nsf < NB_SUBFR16k; nsf++) { -#else - FOR(int nsf = 0; nsf < st->nb_subfr; nsf++) { -#endif - Scale_sig(Aq_fx + (nsf * (M + 1)), M + 1, norm_s(Aq_fx[nsf * (M + 1)]) - Q2); - Aq_fx[nsf * (M + 1)] = ONE_IN_Q12; + /* update old synthesis buffer - needed for ACELP internal sampling rate switching */ + Copy( psyn_fx + st->L_frame - L_SYN_MEM, st->mem_syn_r, L_SYN_MEM ); + deemph_fx( psyn_fx, st->preemph_fac, st->L_frame, &( st->mem_deemph_fx ) ); + unscale_AGC( psyn_fx, st->Q_syn, syn_fx_tmp2, st->agc_mem_fx, st->L_frame ); + Copy( syn_fx_tmp2, psyn_fx, st->L_frame ); + IF( st->hTcxDec != NULL ) + { + Copy_Scale_sig( psyn_fx + st->L_frame / 2, st->hTcxDec->old_syn_Overl, st->L_frame / 2, sub( -1, st->Q_syn ) ); /*Q-1*/ } - if ( st->nelp_mode_dec == 1 ) + Copy_Scale_sig( psyn_fx + st->L_frame - M - 1, st->syn, M + 1, sub( 0, st->Q_syn ) ); /*Q0*/ + + /*------------------------------------------------------------------* + * Formant post-filter + *-----------------------------------------------------------------*/ + + test(); + test(); + test(); + + IF( st->hPFstat != NULL && GE_16( st->last_bwidth, WB ) && ( GT_32( st->core_brate, ACELP_24k40 ) || GT_16( st->element_mode, EVS_MONO ) ) && LE_32( st->core_brate, ACELP_32k ) ) { - /* SC-VBR */ - Scale_sig(exc_fx - L_EXC_MEM, L_EXC_MEM, -st->Q_exc); - st->Q_exc = 0; - move16(); + st->hPFstat->on = 1; + /*----ftf conversions---*/ + Copy( psyn_fx, temp_buf_fx + L_SYN_MEM, L_FRAME16k ); - decod_nelp_fx(st, &tmp_noise_fx, pitch_buf_fx, exc_fx, exc2_fx, voice_factors_fx, bwe_exc_fx, &st->Q_exc, st->bfi, gain_buf_fx); - FEC_pitch_fx = pitch_buf_fx[3]; + set16_fx( st->hPFstat->mem_zero, 0, M ); - Rescale_exc(st->hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32)0, &(st->Q_exc), st->Q_subfr, exc2_fx, L_FRAME, st->coder_type); + formant_post_filt_ivas_fx( st->hPFstat, temp_buf_fx + L_SYN_MEM, Aq_fx, psyn_fx, st->L_frame, st->lp_noise, st->total_brate, 0 ); } - else + ELSE IF( st->hPFstat != NULL && GE_16( st->last_bwidth, WB ) ) { - /* calculation of excitation signal */ - FEC_exc_estim_fx(st, st->L_frame, exc_fx, exc2_fx, dct_exc_tmp_fx, pitch_buf_fx, voice_factors_fx, &FEC_pitch_fx, bwe_exc_fx, lsf_new_fx, &st->Q_exc, &tmp_noise_fx); - - Rescale_exc(NULL, exc_fx, bwe_exc_fx, st->hGSCDec->last_exc_dct_in_fx, st->L_frame, L_FRAME32k, (Word32)0, - &(st->Q_exc), st->Q_subfr, exc2_fx, st->L_frame, st->last_coder_type); + IF( st->hPFstat->on ) + { - tmp_noise_fx = shr_r(st->lp_gainc_fx, 3); /*Q0*/ + Copy( st->hPFstat->mem_pf_in + L_SYN_MEM - M, temp_buf_fx, M ); + Copy( psyn_fx, temp_buf_fx + M, L_SUBFR ); - /* SC-VBR */ - st->prev_gain_pit_dec_fx = st->lp_gainp_fx; + Residu3_fx( Aq_fx, temp_buf_fx + M, temp_buf_fx + M + L_SUBFR, L_SUBFR, 1 ); + E_UTIL_synthesis( 1, Aq_fx, temp_buf_fx + M + L_SUBFR, temp_buf_fx, L_SUBFR, st->hPFstat->mem_stp + L_SYN_MEM - M, 0, M ); + scale_st_fx( psyn_fx, temp_buf_fx, &st->hPFstat->gain_prec, L_SUBFR ); + Copy( temp_buf_fx, psyn_fx, L_SUBFR / 2 ); + blend_subfr2_fx( temp_buf_fx + L_SUBFR / 2, psyn_fx + L_SUBFR / 2, psyn_fx + L_SUBFR / 2 ); + } + st->hPFstat->on = 0; } - /* synthesis for ACELP core switching and SWB BWE */ - syn_12k8_fx(st->L_frame, Aq_fx, exc_fx, temp_buf_fx, st->mem_syn1_fx, 1, st->Q_exc, -1); - - /* save and delay synthesis to be used by SWB BWE */ - if ( st->hBWE_FD != NULL ) - { - save_old_syn_fx(st->L_frame, temp_buf_fx, old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx); - } - - /* Apply energy matching when switching to inactive frames */ - Inac_switch_ematch_ivas_fx(exc2_fx, dct_exc_tmp_fx, st->hGSCDec->lt_ener_per_band_fx, st->coder_type, st->L_frame, st->total_brate, st->Q_exc, st->bfi, st->last_core, st->last_codec_mode, tdm_low_rate_mode, st->element_mode); + /*----------------------------------------------------------------* + * Comfort noise addition + *----------------------------------------------------------------*/ - /* update past excitation signals for LD music post-filter */ - if ( st->hMusicPF != NULL ) + if ( ( st->hFdCngDec != NULL || st->idchan == 1 ) && st->element_mode != IVAS_CPE_MDCT ) { - Copy(st->hMusicPF->dct_post_old_exc_fx + L_FRAME, st->hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2); - Copy(exc2_fx, st->hMusicPF->dct_post_old_exc_fx + (DCT_L_POST - L_FRAME - OFFSET2), L_FRAME); - - /* Update music post processing values */ - /* Filter energies update */ - for ( i = 0; i < DCT_L_POST; i++ ) - { - st->hMusicPF->filt_lfE_fx[i] = round_fx(L_mac((1228 << (16)), 22938, st->hMusicPF->filt_lfE_fx[i])); - } - /* Update circular buffer, keep last energy difference unchanged */ - for ( i = 1; i < MAX_LT; i++ ) + if ( st->element_mode == IVAS_CPE_TD || st->flag_cna || ( st->cng_type == FD_CNG && st->total_brate <= ACELP_32k ) || ( st->cng_type == LP_CNG && st->core_brate <= SID_2k40 ) ) { - st->hMusicPF->LDm_lt_diff_etot_fx[i - 1] = st->hMusicPF->LDm_lt_diff_etot_fx[i]; - } - } - - /* synthesis at 12k8 Hz sampling rate */ - /* add extra headroom in case a CNA addition is likely (i.e. st_fx->psf_lp_noise_fx is close to the threshold) */ - Word16 k = 0; - move16(); - test(); - test(); - if (EQ_16(st->coder_type, INACTIVE) && st->flag_cna&&GE_16(round_fx(L_shl(st->lp_noise, 1)), 15 << 7)) - { - k = 1; - move16(); - } - - Rescale_mem(st->Q_exc, &st->prev_Q_syn, &st->Q_syn, st->mem_syn2_fx, st->mem_syn_clas_estim_fx, 4, &st->mem_deemph_fx, - st->hBPF->pst_old_syn_fx, &st->hBPF->pst_mem_deemp_err_fx, &st->agc_mem_fx[1], st->hPFstat, 1, k, temp_buf_fx); - - if ( ( st->total_brate == ACELP_7k20 ) || ( st->total_brate == ACELP_8k00 ) ) - { - Copy(st->mem_syn2_fx, mem_tmp_fx, M); - } - syn_12k8_fx(st->L_frame, Aq_fx, exc2_fx, psyn_fx, st->mem_syn2_fx, 1, st->Q_exc, st->Q_syn); - - /* update buffer for classifier */ - if ( st->hWIDec != NULL ) - { - Copy(exc2_fx + st->L_frame - L_EXC_MEM, st->hWIDec->old_exc2_fx, L_EXC_MEM); - Copy(psyn_fx + st->L_frame - L_EXC_MEM, st->hWIDec->old_syn2_fx, L_EXC_MEM); - } - st->prev_Q_exc_fr = st->Q_exc; - st->prev_Q_syn_fr = st->Q_syn; - - Copy(psyn_fx + st->L_frame - L_SYN_MEM_CLAS_ESTIM, st->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM); - - /*------------------------------------------------------------* - * FEC - Smooth the speech energy evolution when recovering after a BAD frame - * (smoothing is performed in the excitation domain and signal is resynthesized after) - *------------------------------------------------------------*/ - - if ( ( st->total_brate == ACELP_7k20 ) || ( st->total_brate == ACELP_8k00 ) ) - { - Copy_Scale_sig(pitch_buf_fx, pitch_buf_tmp, NB_SUBFR16k, -Q6); - - FEC_scale_syn_fx(st->L_frame, &update_flg, st->clas_dec, st->last_good, psyn_fx, pitch_buf_tmp, st->enr_old_fx, enr_q_fx, st->coder_type, LSF_Q_prediction, - &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate, - exc_fx, exc2_fx, Aq_fx, &st->old_enr_LP, mem_tmp_fx, st->mem_syn2_fx, st->Q_exc, st->Q_syn, avoid_lpc_burst_on_recovery, 0); - } - - /* estimate the pitch-synchronous speech energy per sample to be used when normal operation recovers */ - frame_ener_fx(st->L_frame, st->last_good, psyn_fx, shr(add(FEC_pitch_fx, 32), 6), &st->enr_old_fx, st->L_frame, st->Q_syn, 3, 0); - - if ( st->nelp_mode_dec != 1 ) - { - /* modify the excitation signal of stationary unvoiced frames */ - stat_noise_uv_mod_fx(st->coder_type, 0, st->lsp_old_fx, lsp_new_fx, lsp_new_fx, Aq_fx, exc2_fx, st->Q_exc, 1, &st->ge_sm_fx, - &st->uv_count, &st->act_count, st->lspold_s_fx, &st->noimix_seed, &st->min_alpha_fx, - &st->exc_pe_fx, st->core_brate, st->bwidth, &st->Q_stat_noise, &st->Q_stat_noise_ge); - } - } - - IF(st->hBWE_TD != NULL) - { - IF(EQ_16(st->L_frame, L_FRAME)) - { - Copy( Aq_fx + 2 * ( M + 1 ), st->hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) ); - } - ELSE - { - Copy( Aq_fx + 3 * ( M + 1 ), st->hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) ); - } - } - - /*--------------------------------------------------------* - * Apply NB postfilter in case of 8kHz output - *--------------------------------------------------------*/ - test(); - IF(EQ_16(st->last_bwidth, NB) && st->hPFstat != NULL) - { - Copy(pitch_buf_fx, pitch_buf_tmp, NB_SUBFR16k); - IF(EQ_16(st->bwidth, NB)) - { - st->hPFstat->on = 1; - move16(); - nb_post_filt_fx(st->L_frame, st->hPFstat, &st->psf_lp_noise_fx, tmp_noise_fx, psyn_fx, Aq_fx, pitch_buf_tmp, st->coder_type, st->BER_detect, 0); - } - ELSE - { - st->hPFstat->on = 0; - nb_post_filt_fx(st->L_frame, st->hPFstat, &st->psf_lp_noise_fx, tmp_noise_fx, psyn_fx, Aq_fx, pitch_buf_tmp, AUDIO, st->BER_detect, 0); - } - } - else - { - st->psf_lp_noise_fx = round_fx(L_shl(st->lp_noise, 1)); - } - - /*------------------------------------------------------------------* - * Perform fixed deemphasis through 1/(1 - g*z^-1) - *-----------------------------------------------------------------*/ - - /* update old synthesis buffer - needed for ACELP internal sampling rate switching */ - Copy(psyn_fx + st->L_frame - L_SYN_MEM, st->mem_syn_r, L_SYN_MEM); - deemph_fx(psyn_fx, st->preemph_fac, st->L_frame, &(st->mem_deemph_fx)); - unscale_AGC(psyn_fx, st->Q_syn, syn_fx_tmp2, st->agc_mem_fx, st->L_frame); - Copy(syn_fx_tmp2, psyn_fx, st->L_frame); - IF(st->hTcxDec != NULL) - { - Copy_Scale_sig(psyn_fx + st->L_frame / 2, st->hTcxDec->old_syn_Overl, st->L_frame / 2, sub(-1, st->Q_syn)); /*Q-1*/ - } - Copy_Scale_sig(psyn_fx + st->L_frame - M - 1, st->syn, M + 1, sub(0, st->Q_syn)); /*Q0*/ - - /*------------------------------------------------------------------* - * Formant post-filter - *-----------------------------------------------------------------*/ - - test(); - test(); - test(); - - IF(st->hPFstat != NULL && GE_16(st->last_bwidth, WB) && (GT_32(st->core_brate, ACELP_24k40) || GT_16(st->element_mode, EVS_MONO)) && LE_32(st->core_brate, ACELP_32k)) - { - st->hPFstat->on = 1; - /*----ftf conversions---*/ - Copy(psyn_fx, temp_buf_fx + L_SYN_MEM, L_FRAME16k); - - set16_fx(st->hPFstat->mem_zero, 0, M); - - formant_post_filt_ivas_fx(st->hPFstat, temp_buf_fx + L_SYN_MEM, Aq_fx, psyn_fx, st->L_frame, st->lp_noise, st->total_brate, 0); - - } - ELSE IF(st->hPFstat != NULL && GE_16(st->last_bwidth, WB)) - { - IF(st->hPFstat->on) - { - - Copy(st->hPFstat->mem_pf_in + L_SYN_MEM - M, temp_buf_fx, M); - Copy(psyn_fx, temp_buf_fx + M, L_SUBFR); - - Residu3_fx(Aq_fx, temp_buf_fx + M, temp_buf_fx + M + L_SUBFR, L_SUBFR, 1); - E_UTIL_synthesis(1, Aq_fx, temp_buf_fx + M + L_SUBFR, temp_buf_fx, L_SUBFR, st->hPFstat->mem_stp + L_SYN_MEM - M, 0, M); - scale_st_fx(psyn_fx, temp_buf_fx, &st->hPFstat->gain_prec, L_SUBFR); - Copy(temp_buf_fx, psyn_fx, L_SUBFR / 2); - blend_subfr2_fx(temp_buf_fx + L_SUBFR / 2, psyn_fx + L_SUBFR / 2, psyn_fx + L_SUBFR / 2); - } - st->hPFstat->on = 0; - } + /*VAD only for non inactive frame*/ + st->VAD = st->VAD && ( st->coder_type != INACTIVE ); - /*----------------------------------------------------------------* - * Comfort noise addition - *----------------------------------------------------------------*/ - - if ((st->hFdCngDec != NULL || st->idchan == 1) && st->element_mode != IVAS_CPE_MDCT) - { - if (st->element_mode == IVAS_CPE_TD || st->flag_cna || (st->cng_type == FD_CNG && st->total_brate <= ACELP_32k) || (st->cng_type == LP_CNG && st->core_brate <= SID_2k40)) - { - /*VAD only for non inactive frame*/ - st->VAD = st->VAD && (st->coder_type != INACTIVE); + if ( st->idchan == 0 && ( st->flag_cna || ( st->cng_type == FD_CNG && st->total_brate <= ACELP_32k ) || ( st->cng_type == LP_CNG && st->core_brate <= SID_2k40 ) ) ) + { + /*Noisy speech detector*/ + noisy_speech_detection_fx( st->hFdCngDec, st->VAD, psyn_fx, st->Q_syn ); - if (st->idchan == 0 && (st->flag_cna || (st->cng_type == FD_CNG && st->total_brate <= ACELP_32k) || (st->cng_type == LP_CNG && st->core_brate <= SID_2k40))) - { - /*Noisy speech detector*/ - noisy_speech_detection_fx(st->hFdCngDec, st->VAD, psyn_fx, st->Q_syn); + st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = mult_r( st->hFdCngDec->hFdCngCom->likelihood_noisy_speech, 32440 /*0.99 Q15*/ ); + IF( st->hFdCngDec->hFdCngCom->flag_noisy_speech != 0 ) + { + st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = add( st->hFdCngDec->hFdCngCom->likelihood_noisy_speech, 328 /*0.01 Q15*/ ); + move16(); + } + st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx = L_deposit_h( st->hFdCngDec->hFdCngCom->likelihood_noisy_speech ); + } - st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = mult_r(st->hFdCngDec->hFdCngCom->likelihood_noisy_speech, 32440/*0.99 Q15*/); - IF(st->hFdCngDec->hFdCngCom->flag_noisy_speech != 0) + if ( st->idchan == 0 ) { - st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = add(st->hFdCngDec->hFdCngCom->likelihood_noisy_speech, 328/*0.01 Q15*/); - move16(); + st->lp_noise = st->hFdCngDec->lp_noise; + move32(); } - st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx = L_deposit_h(st->hFdCngDec->hFdCngCom->likelihood_noisy_speech); - } - if (st->idchan == 0) - { - st->lp_noise = st->hFdCngDec->lp_noise; - move32(); - } - - if (st->element_mode != IVAS_CPE_TD && !st->cng_ism_flag) - { - /*Noise estimate*/ + if ( st->element_mode != IVAS_CPE_TD && !st->cng_ism_flag ) + { + /*Noise estimate*/ - Scale_sig32(st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp - Q27); - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 31 - Q4; // Q4 + Scale_sig32( st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp - Q27 ); + st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 31 - Q4; // Q4 - Scale_sig32(st->hFdCngDec->hFdCngCom->sidNoiseEst, NPART, st->hFdCngDec->hFdCngCom->sidNoiseEstExp - Q27); - Scale_sig32(st->hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART, st->hFdCngDec->hFdCngCom->sidNoiseEstExp - Q27); - st->hFdCngDec->hFdCngCom->sidNoiseEstExp = 31 - Q4; // Q4 - /*==========================================================*/ - ApplyFdCng_ivas_fx(psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, (st->coder_type == AUDIO && !st->GSC_noisy_speech)); - /*==========================================================*/ - if (st->hFdCngDec->partNoiseShape_exp < 0) { - Scale_sig32(st->hFdCngDec->partNoiseShape, NPART, st->hFdCngDec->partNoiseShape_exp); - st->hFdCngDec->partNoiseShape_exp = 0; - } - if (st->hFdCngDec->hFdCngCom->cngNoiseLevelExp < 0) { - Scale_sig32(st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp); - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 0; + Scale_sig32( st->hFdCngDec->hFdCngCom->sidNoiseEst, NPART, st->hFdCngDec->hFdCngCom->sidNoiseEstExp - Q27 ); + Scale_sig32( st->hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART, st->hFdCngDec->hFdCngCom->sidNoiseEstExp - Q27 ); + st->hFdCngDec->hFdCngCom->sidNoiseEstExp = 31 - Q4; // Q4 + /*==========================================================*/ + ApplyFdCng_ivas_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); + /*==========================================================*/ + if ( st->hFdCngDec->partNoiseShape_exp < 0 ) + { + Scale_sig32( st->hFdCngDec->partNoiseShape, NPART, st->hFdCngDec->partNoiseShape_exp ); + st->hFdCngDec->partNoiseShape_exp = 0; + } + if ( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp < 0 ) + { + Scale_sig32( st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ); + st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 0; + } } - } - - if (!st->cna_dirac_flag) - { - /* CNA: Generate additional comfort noise to mask potential coding artefacts */ - if (st->flag_cna && !(st->coder_type == AUDIO && !(st->element_mode > EVS_MONO && st->GSC_noisy_speech))) + if ( !st->cna_dirac_flag ) { - if (st->element_mode == IVAS_CPE_TD && nchan_out == 2) + /* CNA: Generate additional comfort noise to mask potential coding artefacts */ + if ( st->flag_cna && !( st->coder_type == AUDIO && !( st->element_mode > EVS_MONO && st->GSC_noisy_speech ) ) ) { - if (hStereoCng->flag_cna_fade) + if ( st->element_mode == IVAS_CPE_TD && nchan_out == 2 ) { - generate_stereo_masking_noise_fx(psyn_fx, st->Q_syn, st, hStereoTD, flag_sec_CNA, 1, hStereoCng, nchan_out); - hStereoCng->flag_cna_fade = 0; + if ( hStereoCng->flag_cna_fade ) + { + generate_stereo_masking_noise_fx( psyn_fx, st->Q_syn, st, hStereoTD, flag_sec_CNA, 1, hStereoCng, nchan_out ); + hStereoCng->flag_cna_fade = 0; + } + else + { + if ( st->element_mode != last_element_mode && st->idchan == 0 ) + { + /* Clear memory for secondary channel CNA */ + set_s( hStereoCng->olapBufferSynth22_fx, 0, st->hFdCngDec->hFdCngCom->frameSize / 2 ); + } + + generate_stereo_masking_noise_fx( psyn_fx, st->Q_syn, st, hStereoTD, flag_sec_CNA, 0, hStereoCng, nchan_out ); + } } - else + else if ( st->element_mode != IVAS_CPE_DFT ) { - if (st->element_mode != last_element_mode && st->idchan == 0) + if ( st->idchan == 0 ) { - /* Clear memory for secondary channel CNA */ - set_s(hStereoCng->olapBufferSynth22_fx, 0, st->hFdCngDec->hFdCngCom->frameSize / 2); + if ( st->element_mode != last_element_mode ) + { + set_s( st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, st->hFdCngDec->hFdCngCom->fftlen ); + } + generate_masking_noise_fx( psyn_fx, st->Q_syn, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0 /*, 0, 0, st->element_mode, hStereoCng, nchan_out*/ ); } - - generate_stereo_masking_noise_fx(psyn_fx, st->Q_syn, st, hStereoTD, flag_sec_CNA, 0, hStereoCng, nchan_out); } } - else if (st->element_mode != IVAS_CPE_DFT) + else if ( st->flag_cna && st->coder_type == AUDIO && ( ( st->last_core == ACELP_CORE && !( st->last_coder_type == AUDIO && !( st->element_mode > EVS_MONO && st->Last_GSC_noisy_speech_flag ) ) ) || st->last_core == TCX_20_CORE ) ) { - if (st->idchan == 0) + if ( st->element_mode == IVAS_CPE_TD && nchan_out == 2 ) { - if (st->element_mode != last_element_mode) + generate_stereo_masking_noise_fx( psyn_fx, st->Q_syn, st, hStereoTD, flag_sec_CNA, 1, hStereoCng, nchan_out ); + hStereoCng->flag_cna_fade = 1; + } + else + { + FOR( i = 0; i < st->hFdCngDec->hFdCngCom->frameSize / 2; i++ ) { - set_s(st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, st->hFdCngDec->hFdCngCom->fftlen); + psyn_fx[i] = add( psyn_fx[i], shr_r( mult_r( st->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * st->hFdCngDec->hFdCngCom->frameSize / 4], st->hFdCngDec->hFdCngCom->fftlenFac ), -st->Q_syn ) ); + move16(); } - generate_masking_noise_fx(psyn_fx, st->Q_syn, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0/*, 0, 0, st->element_mode, hStereoCng, nchan_out*/); } } - } - else if (st->flag_cna && st->coder_type == AUDIO && ((st->last_core == ACELP_CORE && !(st->last_coder_type == AUDIO && !(st->element_mode > EVS_MONO && st->Last_GSC_noisy_speech_flag))) || st->last_core == TCX_20_CORE)) - { - if (st->element_mode == IVAS_CPE_TD && nchan_out == 2) + else { - generate_stereo_masking_noise_fx(psyn_fx, st->Q_syn, st, hStereoTD, flag_sec_CNA, 1, hStereoCng, nchan_out); - hStereoCng->flag_cna_fade = 1; + if ( hStereoCng != NULL ) + { + hStereoCng->flag_cna_fade = 1; + hStereoCng->enableSecCNA = 0; + } } - else + + if ( st->element_mode == IVAS_CPE_TD ) { - FOR(i = 0; i < st->hFdCngDec->hFdCngCom->frameSize / 2; i++) + /*Noise estimate*/ + if ( st->idchan == 0 && ( nchan_out == 2 || ( st->core_brate != FRAME_NO_DATA && st->core_brate != SID_2k40 ) ) ) { - psyn_fx[i] = add(psyn_fx[i], shr_r(mult_r(st->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * st->hFdCngDec->hFdCngCom->frameSize / 4], st->hFdCngDec->hFdCngCom->fftlenFac), -st->Q_syn)); - move16(); + ApplyFdCng_ivas_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); + if ( st->hFdCngDec->partNoiseShape_exp < 0 ) + { + Scale_sig32( st->hFdCngDec->partNoiseShape, NPART, -st->hFdCngDec->partNoiseShape_exp ); + st->hFdCngDec->partNoiseShape_exp = 0; + } + if ( st->hFdCngDec->partNoiseShape_exp < 0 ) + { + Scale_sig32( st->hFdCngDec->partNoiseShape, NPART, st->hFdCngDec->partNoiseShape_exp ); + st->hFdCngDec->partNoiseShape_exp = 0; + } + if ( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp < 0 ) + { + Scale_sig32( st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ); + st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 0; + } } } } - else + } + + if ( !st->cna_dirac_flag ) + { + if ( st->flag_cna == 0 && st->L_frame == L_FRAME16k && st->last_flag_cna == 1 && ( ( st->last_core == ACELP_CORE && !( st->last_coder_type == AUDIO && !( st->element_mode > EVS_MONO && st->Last_GSC_noisy_speech_flag ) ) ) || st->last_core == AMR_WB_CORE ) ) { - if (hStereoCng != NULL) + FOR( i = 0; i < st->hFdCngDec->hFdCngCom->frameSize / 2; i++ ) { - hStereoCng->flag_cna_fade = 1; - hStereoCng->enableSecCNA = 0; + psyn_fx[i] = add( psyn_fx[i], shr_r( mult_r( st->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * st->hFdCngDec->hFdCngCom->frameSize / 4], st->hFdCngDec->hFdCngCom->fftlenFac ), -st->Q_syn ) ); + move16(); } } - if (st->element_mode == IVAS_CPE_TD) + if ( st->flag_cna == 0 || ( st->coder_type == AUDIO && !( st->element_mode > EVS_MONO && st->GSC_noisy_speech ) ) ) { - /*Noise estimate*/ - if (st->idchan == 0 && (nchan_out == 2 || (st->core_brate != FRAME_NO_DATA && st->core_brate != SID_2k40))) + if ( st->idchan == 0 ) { - ApplyFdCng_ivas_fx(psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, (st->coder_type == AUDIO && !st->GSC_noisy_speech)); - if (st->hFdCngDec->partNoiseShape_exp < 0) { - Scale_sig32(st->hFdCngDec->partNoiseShape, NPART, -st->hFdCngDec->partNoiseShape_exp); - st->hFdCngDec->partNoiseShape_exp = 0; - } - if (st->hFdCngDec->partNoiseShape_exp < 0) { - Scale_sig32(st->hFdCngDec->partNoiseShape, NPART, st->hFdCngDec->partNoiseShape_exp); - st->hFdCngDec->partNoiseShape_exp = 0; - } - if (st->hFdCngDec->hFdCngCom->cngNoiseLevelExp < 0) { - Scale_sig32(st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp); - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 0; - } + set_s( st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, st->hFdCngDec->hFdCngCom->fftlen ); + } + if ( hStereoCng != NULL && st->idchan == 0 ) + { + set_s( hStereoCng->olapBufferSynth22_fx, 0, st->hFdCngDec->hFdCngCom->fftlen ); } } } } - if (!st->cna_dirac_flag) + /*----------------------------------------------------------------* + * Resample to the output sampling rate (8/16/32/48 kHz) + * Bass post-filter + *----------------------------------------------------------------*/ + + /* check if the CLDFB works on the right sample rate */ + if ( ( st->cldfbAna->no_channels * st->cldfbAna->no_col ) != st->L_frame ) { - if (st->flag_cna == 0 && st->L_frame == L_FRAME16k && st->last_flag_cna == 1 && ((st->last_core == ACELP_CORE && !(st->last_coder_type == AUDIO && !(st->element_mode > EVS_MONO && st->Last_GSC_noisy_speech_flag))) || st->last_core == AMR_WB_CORE)) - { - FOR(i = 0; i < st->hFdCngDec->hFdCngCom->frameSize / 2; i++) - { - psyn_fx[i] = add(psyn_fx[i], shr_r(mult_r(st->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * st->hFdCngDec->hFdCngCom->frameSize / 4], st->hFdCngDec->hFdCngCom->fftlenFac), -st->Q_syn)); - move16(); - } - } + resampleCldfb_ivas_fx( st->cldfbAna, st->L_frame * FRAMES_PER_SEC ); + resampleCldfb_ivas_fx( st->cldfbBPF, st->L_frame * FRAMES_PER_SEC ); - if (st->flag_cna == 0 || (st->coder_type == AUDIO && !(st->element_mode > EVS_MONO && st->GSC_noisy_speech))) + if ( st->ini_frame > 0 ) { - if (st->idchan == 0) - { - set_s(st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, st->hFdCngDec->hFdCngCom->fftlen); - } - if (hStereoCng != NULL && st->idchan == 0) - { - set_s(hStereoCng->olapBufferSynth22_fx, 0, st->hFdCngDec->hFdCngCom->fftlen); - } + st->cldfbSyn->bandsToZero = st->cldfbSyn->no_channels - st->cldfbAna->no_channels; } } - } - /*----------------------------------------------------------------* - * Resample to the output sampling rate (8/16/32/48 kHz) - * Bass post-filter - *----------------------------------------------------------------*/ + /* analyze pitch coherence for bass post-filter */ - /* check if the CLDFB works on the right sample rate */ - if ((st->cldfbAna->no_channels * st->cldfbAna->no_col) != st->L_frame) - { - resampleCldfb_ivas_fx(st->cldfbAna, st->L_frame * FRAMES_PER_SEC); - resampleCldfb_ivas_fx(st->cldfbBPF, st->L_frame * FRAMES_PER_SEC); + Word32 pitch_buf_fx_q20[12]; - if (st->ini_frame > 0) + Scale_sig32( st->old_pitch_buf_fx, 2 * NB_SUBFR16k + 2, Q4 ); + Word16 lim = st->L_frame / 64; + for ( Word16 lp = 0; lp < lim; lp++ ) { - st->cldfbSyn->bandsToZero = st->cldfbSyn->no_channels - st->cldfbAna->no_channels; + pitch_buf_fx_q20[lp] = L_shl( pitch_buf_fx[lp], Q14 ); } - } + bpf_pitch_coherence_ivas_fx( st, pitch_buf_fx_q20 ); + Scale_sig32( st->old_pitch_buf_fx, 2 * NB_SUBFR16k + 2, -Q4 ); - /* analyze pitch coherence for bass post-filter */ - - Word32 pitch_buf_fx_q20[12]; - - Scale_sig32(st->old_pitch_buf_fx, 2 * NB_SUBFR16k + 2, Q4); - Word16 lim = st->L_frame / 64; - for (Word16 lp = 0; lp < lim; lp++) - { - pitch_buf_fx_q20[lp] = L_shl(pitch_buf_fx[lp], Q14); - } - bpf_pitch_coherence_ivas_fx(st, pitch_buf_fx_q20); - Scale_sig32(st->old_pitch_buf_fx, 2 * NB_SUBFR16k + 2, -Q4); - - - IF( !( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && st->bpf_off ) ) - { - test(); - IF( NE_16( st->L_frame, st->last_L_frame ) && NE_16( st->last_codec_mode, MODE2 ) ) + IF( !( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && st->bpf_off ) ) { - IF( EQ_16( st->L_frame, L_FRAME ) ) - { - retro_interp5_4_fx( st->hBPF->pst_old_syn_fx ); - } - ELSE IF( EQ_16( st->L_frame, L_FRAME16k ) ) + test(); + IF( NE_16( st->L_frame, st->last_L_frame ) && NE_16( st->last_codec_mode, MODE2 ) ) { - retro_interp4_5_fx( psyn_fx, st->hBPF->pst_old_syn_fx ); + IF( EQ_16( st->L_frame, L_FRAME ) ) + { + retro_interp5_4_fx( st->hBPF->pst_old_syn_fx ); + } + ELSE IF( EQ_16( st->L_frame, L_FRAME16k ) ) + { + retro_interp4_5_fx( psyn_fx, st->hBPF->pst_old_syn_fx ); + } } - } - bass_psfilter_fx( st->hBPF, st->Opt_AMR_WB, psyn_fx, st->L_frame, pitch_buf_fx, st->bpf_off, - st->stab_fac_fx, &st->stab_fac_smooth_fx, st->coder_type, st->Q_syn, bpf_error_signal_16fx); - } + bass_psfilter_fx( st->hBPF, st->Opt_AMR_WB, psyn_fx, st->L_frame, pitch_buf_fx, st->bpf_off, + st->stab_fac_fx, &st->stab_fac_smooth_fx, st->coder_type, st->Q_syn, bpf_error_signal_16fx ); + } - Word32 syn_tmp_32_fx[L_FRAME16k + L_SUBFR], *syn_32_fx; - set32_fx(syn_tmp_32_fx, 0, L_FRAME16k + L_SUBFR); - syn_32_fx = syn_tmp_32_fx + L_SUBFR; + Word32 syn_tmp_32_fx[L_FRAME16k + L_SUBFR], *syn_32_fx; + set32_fx( syn_tmp_32_fx, 0, L_FRAME16k + L_SUBFR ); + syn_32_fx = syn_tmp_32_fx + L_SUBFR; - if (st->element_mode != IVAS_CPE_DFT || use_cldfb_for_dft) - { - /* analysis of the synthesis at internal sampling rate */ - Word32 realBufferSave_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - Word32 imagBufferSave_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - Word32 *pRealSave_fx[CLDFB_NO_COL_MAX], *pImagSave_fx[CLDFB_NO_COL_MAX]; - FOR(i = 0; i < CLDFB_NO_COL_MAX; i++) + if ( st->element_mode != IVAS_CPE_DFT || use_cldfb_for_dft ) { - pRealSave_fx[i] = realBufferSave_fx[i]; - pImagSave_fx[i] = imagBufferSave_fx[i]; - } + /* analysis of the synthesis at internal sampling rate */ + Word32 realBufferSave_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; + Word32 imagBufferSave_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; + Word32 *pRealSave_fx[CLDFB_NO_COL_MAX], *pImagSave_fx[CLDFB_NO_COL_MAX]; + FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + pRealSave_fx[i] = realBufferSave_fx[i]; + pImagSave_fx[i] = imagBufferSave_fx[i]; + } #ifndef MSAN_FIX - Copy_Scale_sig_16_32(bpf_error_signal_16fx, bpf_error_signal_fx, st->L_frame, -1); //Q_syn-1 + Copy_Scale_sig_16_32( bpf_error_signal_16fx, bpf_error_signal_fx, st->L_frame, -1 ); // Q_syn-1 #endif - IF(st->p_bpf_noise_buf_32) - { + IF( st->p_bpf_noise_buf_32 ) + { #ifdef MSAN_FIX - Copy_Scale_sig_16_32( bpf_error_signal_16fx, bpf_error_signal_fx, st->L_frame, -1 ); // Q_syn-1 + Copy_Scale_sig_16_32( bpf_error_signal_16fx, bpf_error_signal_fx, st->L_frame, -1 ); // Q_syn-1 #endif - Copy32(bpf_error_signal_fx, st->p_bpf_noise_buf_32, st->L_frame); - Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( Q11, sub( st->Q_syn, 1 ) ) ); - } + Copy32( bpf_error_signal_fx, st->p_bpf_noise_buf_32, st->L_frame ); + Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( Q11, sub( st->Q_syn, 1 ) ) ); + } #ifdef MSAN_FIX - FOR( i = 0; i < st->L_frame; i++ ) + FOR( i = 0; i < st->L_frame; i++ ) #else - for (i = 0; i < L_FRAME16k; i++) + for ( i = 0; i < L_FRAME16k; i++ ) #endif - { - syn_32_fx[i] = L_shr(L_deposit_h(psyn_fx[i]), 4 + st->Q_syn); //Q12 - } + { + syn_32_fx[i] = L_shr( L_deposit_h( psyn_fx[i] ), 4 + st->Q_syn ); // Q12 + } - Word16 offset = sub(st->cldfbAna->p_filter_length, st->cldfbAna->no_channels); - Scale_sig32(st->cldfbAna->cldfb_state_fx, offset, 1); //Q12 - st->cldfbAna->Q_cldfb_state = Q12; + Word16 offset = sub( st->cldfbAna->p_filter_length, st->cldfbAna->no_channels ); + Scale_sig32( st->cldfbAna->cldfb_state_fx, offset, 1 ); // Q12 + st->cldfbAna->Q_cldfb_state = Q12; - cldfbAnalysis_ivas_fx(syn_32_fx, realBuffer_fx, imagBuffer_fx, -1, st->cldfbAna); - Scale_sig32(st->cldfbAna->cldfb_state_fx, offset, -1); //Q11 - st->cldfbAna->Q_cldfb_state = Q11; + cldfbAnalysis_ivas_fx( syn_32_fx, realBuffer_fx, imagBuffer_fx, -1, st->cldfbAna ); + Scale_sig32( st->cldfbAna->cldfb_state_fx, offset, -1 ); // Q11 + st->cldfbAna->Q_cldfb_state = Q11; - /* analysis and add the BPF error signal */ - Word32 tmp_bpf_error_signal_fx[L_FRAME16k]; - Word16 q_bpf_error_signal; - Word16 cldfb_state_offset = sub(st->cldfbBPF->p_filter_length, st->cldfbBPF->no_channels); + /* analysis and add the BPF error signal */ + Word32 tmp_bpf_error_signal_fx[L_FRAME16k]; + Word16 q_bpf_error_signal; + Word16 cldfb_state_offset = sub( st->cldfbBPF->p_filter_length, st->cldfbBPF->no_channels ); - q_bpf_error_signal = Q6; + q_bpf_error_signal = Q6; #ifdef MSAN_FIX - Copy_Scale_sig_16_32(bpf_error_signal_16fx, tmp_bpf_error_signal_fx, st->L_frame, q_bpf_error_signal - st->Q_syn); // Q6 + Copy_Scale_sig_16_32( bpf_error_signal_16fx, tmp_bpf_error_signal_fx, st->L_frame, q_bpf_error_signal - st->Q_syn ); // Q6 #else - Copy_Scale_sig_16_32(bpf_error_signal_16fx, tmp_bpf_error_signal_fx, L_FRAME16k, q_bpf_error_signal - st->Q_syn); // Q6 + Copy_Scale_sig_16_32( bpf_error_signal_16fx, tmp_bpf_error_signal_fx, L_FRAME16k, q_bpf_error_signal - st->Q_syn ); // Q6 #endif - for (i = 0; i < CLDFB_NO_COL_MAX; i++) - { - Scale_sig32(realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, -Q7); //Q0 - Scale_sig32(imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, -Q7); //Q0 - } - Scale_sig32(st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, q_bpf_error_signal - Q10); //q_bpf_error_signal (Q6) - st->cldfbBPF->Q_cldfb_state = q_bpf_error_signal; + for ( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + Scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, -Q7 ); // Q0 + Scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, -Q7 ); // Q0 + } + Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, q_bpf_error_signal - Q10 ); // q_bpf_error_signal (Q6) + st->cldfbBPF->Q_cldfb_state = q_bpf_error_signal; - tmp = -1; - move16(); - IF(st->bpf_off) - { - tmp = 0; + tmp = -1; move16(); - } - - addBassPostFilter_ivas_fx(tmp_bpf_error_signal_fx, tmp, realBuffer_fx, imagBuffer_fx, st->cldfbBPF); - Scale_sig32(st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, -(q_bpf_error_signal - Q10)); //Q10 - st->cldfbBPF->Q_cldfb_state = Q10; + IF( st->bpf_off ) + { + tmp = 0; + move16(); + } - /* set output mask for upsampling */ - IF(EQ_16(st->bwidth, NB)) - { - /* set NB mask for upsampling */ - st->cldfbSyn->bandsToZero = sub(st->cldfbSyn->no_channels, 10); - } - ELSE IF(NE_16(st->cldfbSyn->bandsToZero, sub(st->cldfbSyn->no_channels, st->cldfbAna->no_channels))) - { - /* in case of BW switching, re-init to default */ - st->cldfbSyn->bandsToZero = sub(st->cldfbSyn->no_channels, st->cldfbAna->no_channels); - } + addBassPostFilter_ivas_fx( tmp_bpf_error_signal_fx, tmp, realBuffer_fx, imagBuffer_fx, st->cldfbBPF ); + Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, -( q_bpf_error_signal - Q10 ) ); // Q10 + st->cldfbBPF->Q_cldfb_state = Q10; - IF(!st->cng_sba_flag || EQ_16(st->element_mode, IVAS_CPE_MDCT)) - { - /*WB/SWB-FD_CNG*/ - IF((EQ_32(st->core_brate, FRAME_NO_DATA) || EQ_32(st->core_brate, SID_2k40)) && (EQ_16(st->cng_type, FD_CNG)) && (LE_16(st->hFdCngDec->hFdCngCom->numCoreBands, st->cldfbSyn->no_channels))) + /* set output mask for upsampling */ + IF( EQ_16( st->bwidth, NB ) ) { - Word16 tmpBufferScale = 0; - generate_comfort_noise_dec_hf_ivas_fx(realBuffer_fx, imagBuffer_fx, /*realBuffer, imagBuffer,*/ &tmpBufferScale, st->hFdCngDec->hFdCngCom, st->cng_ism_flag); + /* set NB mask for upsampling */ + st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, 10 ); + } + ELSE IF( NE_16( st->cldfbSyn->bandsToZero, sub( st->cldfbSyn->no_channels, st->cldfbAna->no_channels ) ) ) + { + /* in case of BW switching, re-init to default */ + st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, st->cldfbAna->no_channels ); + } - /* Fixed to float */ - FOR(i = 0; i < st->hFdCngDec->hFdCngCom->numSlots; i++) + IF( !st->cng_sba_flag || EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) + { + /*WB/SWB-FD_CNG*/ + IF( ( EQ_32( st->core_brate, FRAME_NO_DATA ) || EQ_32( st->core_brate, SID_2k40 ) ) && ( EQ_16( st->cng_type, FD_CNG ) ) && ( LE_16( st->hFdCngDec->hFdCngCom->numCoreBands, st->cldfbSyn->no_channels ) ) ) { - Scale_sig32(realBuffer_fx[i] + st->hFdCngDec->hFdCngCom->numCoreBands, st->hFdCngDec->hFdCngCom->regularStopBand - st->hFdCngDec->hFdCngCom->numCoreBands, (tmpBufferScale + 15) - Q31); //Q0 - Scale_sig32(imagBuffer_fx[i] + st->hFdCngDec->hFdCngCom->numCoreBands, st->hFdCngDec->hFdCngCom->regularStopBand - st->hFdCngDec->hFdCngCom->numCoreBands, (tmpBufferScale + 15) - Q31); //Q0 - } + Word16 tmpBufferScale = 0; + generate_comfort_noise_dec_hf_ivas_fx( realBuffer_fx, imagBuffer_fx, /*realBuffer, imagBuffer,*/ &tmpBufferScale, st->hFdCngDec->hFdCngCom, st->cng_ism_flag ); - IF(st->hFdCngDec->hFdCngCom->regularStopBand < st->cldfbSyn->no_channels) - { - st->cldfbSyn->bandsToZero = sub(st->cldfbSyn->no_channels, st->hFdCngDec->hFdCngCom->regularStopBand); - } - ELSE - { - st->cldfbSyn->bandsToZero = 0; + /* Fixed to float */ + FOR( i = 0; i < st->hFdCngDec->hFdCngCom->numSlots; i++ ) + { + Scale_sig32( realBuffer_fx[i] + st->hFdCngDec->hFdCngCom->numCoreBands, st->hFdCngDec->hFdCngCom->regularStopBand - st->hFdCngDec->hFdCngCom->numCoreBands, ( tmpBufferScale + 15 ) - Q31 ); // Q0 + Scale_sig32( imagBuffer_fx[i] + st->hFdCngDec->hFdCngCom->numCoreBands, st->hFdCngDec->hFdCngCom->regularStopBand - st->hFdCngDec->hFdCngCom->numCoreBands, ( tmpBufferScale + 15 ) - Q31 ); // Q0 + } + + IF( st->hFdCngDec->hFdCngCom->regularStopBand < st->cldfbSyn->no_channels ) + { + st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, st->hFdCngDec->hFdCngCom->regularStopBand ); + } + ELSE + { + st->cldfbSyn->bandsToZero = 0; + } } } - } - if (save_hb_synth_fx16 != NULL) - { - /* save and then zero-out lowband */ - Word16 Q_real = 0, Q_imag = 0; - Word32 max_real = 0, max_imag = 0; - for (i = 0; i < CLDFB_NO_COL_MAX; i++) + if ( save_hb_synth_fx16 != NULL ) { - for ( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) + /* save and then zero-out lowband */ + Word16 Q_real = 0, Q_imag = 0; + Word32 max_real = 0, max_imag = 0; + for ( i = 0; i < CLDFB_NO_COL_MAX; i++ ) { - max_real = max(max_real, L_abs(realBuffer_fx[i][j])); - max_imag = max(max_imag, L_abs(imagBuffer_fx[i][j])); + for ( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) + { + max_real = max( max_real, L_abs( realBuffer_fx[i][j] ) ); + max_imag = max( max_imag, L_abs( imagBuffer_fx[i][j] ) ); + } } - } - Word32 max_val = max(max_real, max_imag); - Q_imag = norm_l(max_val) - 3/* Guard bits */; - Q_real = Q_imag; + Word32 max_val = max( max_real, max_imag ); + Q_imag = norm_l( max_val ) - 3 /* Guard bits */; + Q_real = Q_imag; - for (i = 0; i < CLDFB_NO_COL_MAX; i++) - { - scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real); - scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_imag); - } - scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->p_filter_length, ( Q_real - 1 ) - Q10 ); // (Q_real-1) - st->cldfbSynHB->Q_cldfb_state = sub(Q_real, 1); - Scale_sig32(save_hb_synth_fx, L_FRAME48k, Q_real - 1); + for ( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); + scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_imag ); + } + scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->p_filter_length, ( Q_real - 1 ) - Q10 ); // (Q_real-1) + st->cldfbSynHB->Q_cldfb_state = sub( Q_real, 1 ); + Scale_sig32( save_hb_synth_fx, L_FRAME48k, Q_real - 1 ); - FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) - { - FOR(i = 0; i < CLDFB_NO_COL_MAX; i++) + FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) { - realBufferSave_fx[i][j] = realBuffer_fx[i][j]; - imagBufferSave_fx[i][j] = imagBuffer_fx[i][j]; - IF(j < st->hFdCngDec->hFdCngCom->numCoreBands && i < st->hFdCngDec->hFdCngCom->numSlots) + FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) { - realBuffer_fx[i][j] = 0; - imagBuffer_fx[i][j] = 0; + realBufferSave_fx[i][j] = realBuffer_fx[i][j]; + imagBufferSave_fx[i][j] = imagBuffer_fx[i][j]; + IF( j < st->hFdCngDec->hFdCngCom->numCoreBands && i < st->hFdCngDec->hFdCngCom->numSlots ) + { + realBuffer_fx[i][j] = 0; + imagBuffer_fx[i][j] = 0; + } } } - } - cldfbSynthesis_ivas_fx(realBuffer_fx, imagBuffer_fx, save_hb_synth_fx, -1, st->cldfbSynHB); + cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, save_hb_synth_fx, -1, st->cldfbSynHB ); - Scale_sig32(save_hb_synth_fx, L_FRAME48k, -(Q_real - 1)); //Q0 - Scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->p_filter_length, Q10 - ( Q_real - 1 ) ); // Q10 - st->cldfbSynHB->Q_cldfb_state = Q10; + Scale_sig32( save_hb_synth_fx, L_FRAME48k, -( Q_real - 1 ) ); // Q0 + Scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->p_filter_length, Q10 - ( Q_real - 1 ) ); // Q10 + st->cldfbSynHB->Q_cldfb_state = Q10; - /* restore lowband */ - FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) - { - FOR(i = 0; i < CLDFB_NO_COL_MAX; i++) + /* restore lowband */ + FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) { - realBuffer_fx[i][j] = realBufferSave_fx[i][j]; - imagBuffer_fx[i][j] = imagBufferSave_fx[i][j]; + FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + realBuffer_fx[i][j] = realBufferSave_fx[i][j]; + imagBuffer_fx[i][j] = imagBufferSave_fx[i][j]; + } } + Scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, ( Q_real - 1 ) - Q10 ); // Q_real-1 + st->cldfbSynHB->Q_cldfb_state = sub( Q_real, 1 ); + cldfbSynthesis_ivas_fx( pRealSave_fx, pImagSave_fx, synth_fx, -1, st->cldfbSyn ); + Scale_sig32( synth_fx, L_FRAME48k, -( Q_real - 1 ) ); + Scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, Q10 - ( Q_real - 1 ) ); // Q10 + st->cldfbSynHB->Q_cldfb_state = Q10; } - Scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, (Q_real - 1) - Q10); //Q_real-1 - st->cldfbSynHB->Q_cldfb_state = sub(Q_real, 1); - cldfbSynthesis_ivas_fx(pRealSave_fx, pImagSave_fx, synth_fx, -1, st->cldfbSyn); - Scale_sig32(synth_fx, L_FRAME48k, -(Q_real - 1)); - Scale_sig32(st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, Q10 - (Q_real - 1)); //Q10 - st->cldfbSynHB->Q_cldfb_state = Q10; - } - else - { - /* synthesis of the combined signal */ - Word16 Q_real = 0, Q_imag = 0; - Word32 max_real = 0, max_imag = 0; - for (i = 0; i < CLDFB_NO_COL_MAX; i++) + else { - for (j = 0; j < CLDFB_NO_CHANNELS_MAX; j++) + /* synthesis of the combined signal */ + Word16 Q_real = 0, Q_imag = 0; + Word32 max_real = 0, max_imag = 0; + for ( i = 0; i < CLDFB_NO_COL_MAX; i++ ) { - max_real = max(max_real, L_abs(realBuffer_fx[i][j])); - max_imag = max(max_imag, L_abs(imagBuffer_fx[i][j])); + for ( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) + { + max_real = max( max_real, L_abs( realBuffer_fx[i][j] ) ); + max_imag = max( max_imag, L_abs( imagBuffer_fx[i][j] ) ); + } } - } - Word32 max_val = max(max_real, max_imag); - Q_imag = norm_l(max_val) - 3/* Guard bits */; - Q_real = Q_imag; + Word32 max_val = max( max_real, max_imag ); + Q_imag = norm_l( max_val ) - 3 /* Guard bits */; + Q_real = Q_imag; - for (i = 0; i < CLDFB_NO_COL_MAX; i++) - { - scale_sig32(realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real); - scale_sig32(imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real); - } - scale_sig32(st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, (Q_real - 1) - Q10); //(Q_real - 1) - st->cldfbSyn->Q_cldfb_state = Q_real - 1; + for ( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); + scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); + } + scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, ( Q_real - 1 ) - Q10 ); //(Q_real - 1) + st->cldfbSyn->Q_cldfb_state = Q_real - 1; #ifndef MSAN_FIX - Scale_sig32( synth_fx, L_FRAME48k, Q_real - 1); + Scale_sig32( synth_fx, L_FRAME48k, Q_real - 1 ); #endif - cldfbSynthesis_ivas_fx(realBuffer_fx, imagBuffer_fx, synth_fx, -1, st->cldfbSyn); + cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, synth_fx, -1, st->cldfbSyn ); #ifdef MSAN_FIX - scale_sig32(synth_fx, output_frame, -(Q_real - 1)); + scale_sig32( synth_fx, output_frame, -( Q_real - 1 ) ); #else - Scale_sig32(synth_fx, L_FRAME48k, -(Q_real - 1)); + Scale_sig32( synth_fx, L_FRAME48k, -( Q_real - 1 ) ); #endif - scale_sig32(st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, Q10 - (Q_real - 1)); //Q10 - st->cldfbSyn->Q_cldfb_state = Q10; - } - - /* save synthesis - needed in case of core switching */ - Copy32(synth_fx, st->previoussynth_fx_32, output_frame); //Q0 + scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, Q10 - ( Q_real - 1 ) ); // Q10 + st->cldfbSyn->Q_cldfb_state = Q10; + } - } - else - { - int16_t nSamples = NS2SA(st->L_frame * FRAMES_PER_SEC, FRAME_SIZE_NS /*DELAY_CLDFB_NS*/); /* IVAS-64: optimization is likely possible here (don't resample the whole frame) */ + /* save synthesis - needed in case of core switching */ + Copy32( synth_fx, st->previoussynth_fx_32, output_frame ); // Q0 + } + else + { + int16_t nSamples = NS2SA( st->L_frame * FRAMES_PER_SEC, FRAME_SIZE_NS /*DELAY_CLDFB_NS*/ ); /* IVAS-64: optimization is likely possible here (don't resample the whole frame) */ - /* analysis of the synthesis at internal sampling rate - needed for DFT stereo -> TD stereo switching */ + /* analysis of the synthesis at internal sampling rate - needed for DFT stereo -> TD stereo switching */ #ifndef MSAN_FIX - for (i = 0; i < L_FRAME16k; i++) + for ( i = 0; i < L_FRAME16k; i++ ) #else FOR( i = 0; i < st->L_frame; i++ ) #endif - { - syn_32_fx[i] = L_shr(L_deposit_h(psyn_fx[i]), 4 + st->Q_syn); - } + { + syn_32_fx[i] = L_shr( L_deposit_h( psyn_fx[i] ), 4 + st->Q_syn ); + } - Word16 offset = sub(st->cldfbAna->p_filter_length, st->cldfbAna->no_channels); - Scale_sig32(st->cldfbAna->cldfb_state_fx, offset, 1); //Q12 - st->cldfbAna->Q_cldfb_state = Q12; - cldfbAnalysis_ivas_fx(syn_32_fx + st->L_frame - nSamples, realBuffer_fx, imagBuffer_fx, nSamples, st->cldfbAna); + Word16 offset = sub( st->cldfbAna->p_filter_length, st->cldfbAna->no_channels ); + Scale_sig32( st->cldfbAna->cldfb_state_fx, offset, 1 ); // Q12 + st->cldfbAna->Q_cldfb_state = Q12; + cldfbAnalysis_ivas_fx( syn_32_fx + st->L_frame - nSamples, realBuffer_fx, imagBuffer_fx, nSamples, st->cldfbAna ); - Scale_sig32(st->cldfbAna->cldfb_state_fx, offset, -1); //Q11 - st->cldfbAna->Q_cldfb_state = Q11; + Scale_sig32( st->cldfbAna->cldfb_state_fx, offset, -1 ); // Q11 + st->cldfbAna->Q_cldfb_state = Q11; - /* analysis and add the BPF error signal - needed for DFT stereo -> TD stereo switching */ - Word32 tmp_bpf_error_signal_fx[L_FRAME16k]; - Word16 q_bpf_error_signal; - Word16 cldfb_state_offset = sub(st->cldfbBPF->p_filter_length, st->cldfbBPF->no_channels); + /* analysis and add the BPF error signal - needed for DFT stereo -> TD stereo switching */ + Word32 tmp_bpf_error_signal_fx[L_FRAME16k]; + Word16 q_bpf_error_signal; + Word16 cldfb_state_offset = sub( st->cldfbBPF->p_filter_length, st->cldfbBPF->no_channels ); - // Get Q-factor - q_bpf_error_signal = Q6; + // Get Q-factor + q_bpf_error_signal = Q6; - Copy_Scale_sig_16_32(bpf_error_signal_16fx, tmp_bpf_error_signal_fx, L_FRAME16k, q_bpf_error_signal - st->Q_syn); // Q6 - for (i = 0; i < CLDFB_NO_COL_MAX; i++) - { - Scale_sig32(realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, -Q7); //Q0 - Scale_sig32(imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, -Q7); //Q0 - } - Scale_sig32(st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, q_bpf_error_signal - Q10); //q_bpf_error_signal (Q6) - st->cldfbBPF->Q_cldfb_state = q_bpf_error_signal; + Copy_Scale_sig_16_32( bpf_error_signal_16fx, tmp_bpf_error_signal_fx, L_FRAME16k, q_bpf_error_signal - st->Q_syn ); // Q6 + for ( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + Scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, -Q7 ); // Q0 + Scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, -Q7 ); // Q0 + } + Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, q_bpf_error_signal - Q10 ); // q_bpf_error_signal (Q6) + st->cldfbBPF->Q_cldfb_state = q_bpf_error_signal; - tmp = 0; - move16(); - IF(!st->bpf_off) - { - tmp = nSamples; + tmp = 0; move16(); - } - addBassPostFilter_ivas_fx(tmp_bpf_error_signal_fx + st->L_frame - nSamples, tmp, realBuffer_fx, imagBuffer_fx, st->cldfbBPF); + IF( !st->bpf_off ) + { + tmp = nSamples; + move16(); + } + addBassPostFilter_ivas_fx( tmp_bpf_error_signal_fx + st->L_frame - nSamples, tmp, realBuffer_fx, imagBuffer_fx, st->cldfbBPF ); - Scale_sig32(st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, -(q_bpf_error_signal - Q10)); //Q10 - st->cldfbBPF->Q_cldfb_state = Q10; - /* synthesis of the combined signal - needed for DFT stereo -> TD stereo switching */ - Word16 Q_real = 0, Q_imag = 0; - Word32 max_real = 0, max_imag = 0; - for (i = 0; i < CLDFB_NO_COL_MAX; i++) - { - for (j = 0; j < CLDFB_NO_CHANNELS_MAX; j++) + Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, -( q_bpf_error_signal - Q10 ) ); // Q10 + st->cldfbBPF->Q_cldfb_state = Q10; + /* synthesis of the combined signal - needed for DFT stereo -> TD stereo switching */ + Word16 Q_real = 0, Q_imag = 0; + Word32 max_real = 0, max_imag = 0; + for ( i = 0; i < CLDFB_NO_COL_MAX; i++ ) { - max_real = max(max_real, L_abs(realBuffer_fx[i][j])); - max_imag = max(max_imag, L_abs(imagBuffer_fx[i][j])); + for ( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) + { + max_real = max( max_real, L_abs( realBuffer_fx[i][j] ) ); + max_imag = max( max_imag, L_abs( imagBuffer_fx[i][j] ) ); + } } - } - Word32 max_val = max(max_real, max_imag); - Q_imag = norm_l(max_val) - 3/* Guard bits */; - Q_real = Q_imag; + Word32 max_val = max( max_real, max_imag ); + Q_imag = norm_l( max_val ) - 3 /* Guard bits */; + Q_real = Q_imag; - for (i = 0; i < CLDFB_NO_COL_MAX; i++) - { - scale_sig32(realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real); - scale_sig32(imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real); - } - scale_sig32(st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, (Q_real - 1) - Q10); //(Q_real - 1) + for ( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); + scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); + } + scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, ( Q_real - 1 ) - Q10 ); //(Q_real - 1) #ifndef MSAN_FIX - Scale_sig32( synth_fx, L_FRAME48k, Q_real - 1); + Scale_sig32( synth_fx, L_FRAME48k, Q_real - 1 ); #endif - cldfbSynthesis_ivas_fx(realBuffer_fx, imagBuffer_fx, synth_fx /*dummy*/, NS2SA(st->output_Fs, FRAME_SIZE_NS /*DELAY_CLDFB_NS*/), st->cldfbSyn); + cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, synth_fx /*dummy*/, NS2SA( st->output_Fs, FRAME_SIZE_NS /*DELAY_CLDFB_NS*/ ), st->cldfbSyn ); #ifdef MSAN_FIX - Scale_sig32(synth_fx, output_frame, -(Q_real - 1)); + Scale_sig32( synth_fx, output_frame, -( Q_real - 1 ) ); #else - Scale_sig32(synth_fx, L_FRAME48k, -(Q_real - 1)); + Scale_sig32( synth_fx, L_FRAME48k, -( Q_real - 1 ) ); #endif - Scale_sig32(st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, Q10 - (Q_real - 1)); - st->cldfbSyn->Q_cldfb_state = Q10; - - if (st->p_bpf_noise_buf_32) - { - Copy_Scale_sig_16_32(bpf_error_signal_16fx, bpf_error_signal_fx, st->L_frame, -1); //Q_syn-1 - Copy32(bpf_error_signal_fx, st->p_bpf_noise_buf_32, st->L_frame); + Scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, Q10 - ( Q_real - 1 ) ); + st->cldfbSyn->Q_cldfb_state = Q10; - Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( Q11, sub( st->Q_syn, 1 ) ) ); - } + if ( st->p_bpf_noise_buf_32 ) + { + Copy_Scale_sig_16_32( bpf_error_signal_16fx, bpf_error_signal_fx, st->L_frame, -1 ); // Q_syn-1 + Copy32( bpf_error_signal_fx, st->p_bpf_noise_buf_32, st->L_frame ); - set_l(synth_fx, 0, output_frame); + Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( Q11, sub( st->Q_syn, 1 ) ) ); + } - } + set_l( synth_fx, 0, output_frame ); + } - /* Copy output signal */ + /* Copy output signal */ #ifndef MSAN_FIX - Scale_sig(syn_tmp_fx, L_FRAME16k + L_SUBFR, -st->Q_syn); + Scale_sig( syn_tmp_fx, L_FRAME16k + L_SUBFR, -st->Q_syn ); #else - Scale_sig(syn_tmp_fx, st->L_frame + L_SUBFR, -st->Q_syn); + Scale_sig( syn_tmp_fx, st->L_frame + L_SUBFR, -st->Q_syn ); #endif - if (st->element_mode > EVS_MONO) - { - Copy(psyn_fx, output_fx, st->L_frame); - } - - st->Q_syn2 = 0; + if ( st->element_mode > EVS_MONO ) + { + Copy( psyn_fx, output_fx, st->L_frame ); + } - /*-----------------------------------------------------------------* - * Bandwidth extension 6kHz-7kHz - *-----------------------------------------------------------------*/ - IF( st->hBWE_zero != NULL ) - { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( EQ_16( st->L_frame, L_FRAME ) && NE_16( st->bwidth, NB ) && GE_16( output_frame, L_FRAME16k ) && - ( EQ_16( st->extl, -1 ) || EQ_16( st->extl, SWB_CNG ) || ( EQ_16( st->extl, WB_BWE ) && st->extl_brate == 0 && NE_16( st->coder_type, AUDIO ) ) ) ) ) + st->Q_syn2 = 0; + + /*-----------------------------------------------------------------* + * Bandwidth extension 6kHz-7kHz + *-----------------------------------------------------------------*/ + IF( st->hBWE_zero != NULL ) { - Word16 tmp_exp = 0; + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( EQ_16( st->L_frame, L_FRAME ) && NE_16( st->bwidth, NB ) && GE_16( output_frame, L_FRAME16k ) && + ( EQ_16( st->extl, -1 ) || EQ_16( st->extl, SWB_CNG ) || ( EQ_16( st->extl, WB_BWE ) && st->extl_brate == 0 && NE_16( st->coder_type, AUDIO ) ) ) ) ) + { + Word16 tmp_exp = 0; #ifdef MSAN_FIX - Copy_Scale_sig_32_16(synth_fx, synth_fx16, output_frame, 0); + Copy_Scale_sig_32_16( synth_fx, synth_fx16, output_frame, 0 ); #else - Copy_Scale_sig_32_16(synth_fx, synth_fx16, L_FRAME48k, 0); + Copy_Scale_sig_32_16( synth_fx, synth_fx16, L_FRAME48k, 0 ); #endif - hf_synth_ivas_fx( st->hBWE_zero, st->core_brate, output_frame, Aq_fx, exc_fx, - psyn_fx, synth_fx16, st->Q_exc, st->Q_syn2, st->hBWE_zero->delay_syn_hf_fx, &tmp_exp, - st->hBWE_zero->mem_hp_interp_fx, st->extl, st->CNG_mode, st->element_mode ); + hf_synth_ivas_fx( st->hBWE_zero, st->core_brate, output_frame, Aq_fx, exc_fx, + psyn_fx, synth_fx16, st->Q_exc, st->Q_syn2, st->hBWE_zero->delay_syn_hf_fx, &tmp_exp, + st->hBWE_zero->mem_hp_interp_fx, st->extl, st->CNG_mode, st->element_mode ); #ifdef MSAN_FIX - Copy_Scale_sig_16_32(synth_fx16, synth_fx, output_frame, 0); + Copy_Scale_sig_16_32( synth_fx16, synth_fx, output_frame, 0 ); #else - Copy_Scale_sig_16_32(synth_fx16, synth_fx, L_FRAME48k, 0); + Copy_Scale_sig_16_32( synth_fx16, synth_fx, L_FRAME48k, 0 ); #endif - IF( st->hBWE_FD != NULL ) - { - st->hBWE_FD->memExp1 = tmp_exp; + IF( st->hBWE_FD != NULL ) + { + st->hBWE_FD->memExp1 = tmp_exp; + } + ELSE + { + Scale_sig( st->hBWE_zero->mem_hf_fx, L_FIR - 1, -tmp_exp ); + } } ELSE { - Scale_sig( st->hBWE_zero->mem_hf_fx, L_FIR - 1, -tmp_exp ); - } - } - ELSE - { - hf_synth_reset_fx( st->hBWE_zero ); + hf_synth_reset_fx( st->hBWE_zero ); #ifdef MSAN_FIX - set16_fx( st->hBWE_zero->mem_hp400_fx, 0, 6 ); + set16_fx( st->hBWE_zero->mem_hp400_fx, 0, 6 ); #endif + } } - } - /*-----------------------------------------------------------------* - * Populate parameters for SWB TBE - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * Populate parameters for SWB TBE + *-----------------------------------------------------------------*/ - if (st->hBWE_TD != NULL) - { - if ((!st->bfi && st->prev_bfi) || (st->last_vbr_hw_BWE_disable_dec == 1 && st->vbr_hw_BWE_disable_dec == 0) || ((st->extl == SWB_TBE || st->extl == WB_TBE || st->extl == FB_TBE) && st->last_extl != SWB_TBE && st->last_extl != WB_TBE && st->last_extl != FB_TBE) || (st->idchan == 1 && st->element_mode == IVAS_CPE_TD && !st->tdm_LRTD_flag)) + if ( st->hBWE_TD != NULL ) { - st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; - set_s(st->hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET); - } + if ( ( !st->bfi && st->prev_bfi ) || ( st->last_vbr_hw_BWE_disable_dec == 1 && st->vbr_hw_BWE_disable_dec == 0 ) || ( ( st->extl == SWB_TBE || st->extl == WB_TBE || st->extl == FB_TBE ) && st->last_extl != SWB_TBE && st->last_extl != WB_TBE && st->last_extl != FB_TBE ) || ( st->idchan == 1 && st->element_mode == IVAS_CPE_TD && !st->tdm_LRTD_flag ) ) + { + st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; + set_s( st->hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); + } - if (!st->ppp_mode_dec && (st->idchan == 0 || st->element_mode != IVAS_CPE_TD || (st->idchan == 1 && st->element_mode == IVAS_CPE_TD && st->tdm_LRTD_flag))) - { - Copy_Scale_sig_16_32( st->hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_fx, NL_BUFF_OFFSET, ( 2 * st->Q_exc - ( st->prev_Q_bwe_exc - 16 ) ) ); - non_linearity_ivas_fx( bwe_exc_fx, bwe_exc_extended_fx + NL_BUFF_OFFSET, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale_fx, st->Q_exc, st->coder_type, voice_factors_fx, st->L_frame ); - Copy_Scale_sig_32_16( bwe_exc_extended_fx + L_FRAME32k, st->hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET, -( 2 * st->Q_exc - ( st->prev_Q_bwe_exc - 16 ) ) ); - } + if ( !st->ppp_mode_dec && ( st->idchan == 0 || st->element_mode != IVAS_CPE_TD || ( st->idchan == 1 && st->element_mode == IVAS_CPE_TD && st->tdm_LRTD_flag ) ) ) + { + Copy_Scale_sig_16_32( st->hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_fx, NL_BUFF_OFFSET, ( 2 * st->Q_exc - ( st->prev_Q_bwe_exc - 16 ) ) ); + non_linearity_ivas_fx( bwe_exc_fx, bwe_exc_extended_fx + NL_BUFF_OFFSET, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale_fx, st->Q_exc, st->coder_type, voice_factors_fx, st->L_frame ); + Copy_Scale_sig_32_16( bwe_exc_extended_fx + L_FRAME32k, st->hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET, -( 2 * st->Q_exc - ( st->prev_Q_bwe_exc - 16 ) ) ); + } - if ( st->core_brate == FRAME_NO_DATA || st->core_brate == SID_2k40 ) - { - st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; + if ( st->core_brate == FRAME_NO_DATA || st->core_brate == SID_2k40 ) + { + st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; + } } - } - /*----------------------------------------------------------------------* - * Updates - *----------------------------------------------------------------------*/ + /*----------------------------------------------------------------------* + * Updates + *----------------------------------------------------------------------*/ - updt_dec_fx( st, old_exc_fx, pitch_buf_fx, Es_pred_fx, Aq_fx, lsf_new_fx, lsp_new_fx, voice_factors_fx, old_bwe_exc_fx, gain_buf_fx ); + updt_dec_fx( st, old_exc_fx, pitch_buf_fx, Es_pred_fx, Aq_fx, lsf_new_fx, lsp_new_fx, voice_factors_fx, old_bwe_exc_fx, gain_buf_fx ); - IF( GT_32( st->core_brate, SID_2k40 ) && st->hTdCngDec != NULL && st->hFdCngDec != NULL ) - { - /* update CNG parameters in active frames */ - cng_params_upd_ivas_fx( lsp_new_fx, exc_fx, st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ_fx, &st->hTdCngDec->ho_circ_size, - st->hTdCngDec->ho_lsp_circ_fx, st->Q_exc, DEC, st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate, st->element_mode, - st->hFdCngDec->hFdCngCom->CngBandwidth ); + IF( GT_32( st->core_brate, SID_2k40 ) && st->hTdCngDec != NULL && st->hFdCngDec != NULL ) + { + /* update CNG parameters in active frames */ + cng_params_upd_ivas_fx( lsp_new_fx, exc_fx, st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ_fx, &st->hTdCngDec->ho_circ_size, + st->hTdCngDec->ho_lsp_circ_fx, st->Q_exc, DEC, st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate, st->element_mode, + st->hFdCngDec->hFdCngCom->CngBandwidth ); - /* Set 16k LSP flag for CNG buffer */ - st->hTdCngDec->ho_16k_lsp[st->hTdCngDec->ho_circ_ptr] = 0; - move16(); - IF( NE_16( st->L_frame, L_FRAME ) ) - { - st->hTdCngDec->ho_16k_lsp[st->hTdCngDec->ho_circ_ptr] = 1; + /* Set 16k LSP flag for CNG buffer */ + st->hTdCngDec->ho_16k_lsp[st->hTdCngDec->ho_circ_ptr] = 0; move16(); + IF( NE_16( st->L_frame, L_FRAME ) ) + { + st->hTdCngDec->ho_16k_lsp[st->hTdCngDec->ho_circ_ptr] = 1; + move16(); + } } - } - { - if (save_hb_synth_fx16) { - Copy_Scale_sig_32_16(save_hb_synth_fx, save_hb_synth_fx16, L_FRAME48k, 0); - } + { + if ( save_hb_synth_fx16 ) + { + Copy_Scale_sig_32_16( save_hb_synth_fx, save_hb_synth_fx16, L_FRAME48k, 0 ); + } #ifdef MSAN_FIX - Copy_Scale_sig_32_16(synth_fx, synth_fx16, output_frame, 0); + Copy_Scale_sig_32_16( synth_fx, synth_fx16, output_frame, 0 ); #else - Copy_Scale_sig_32_16(synth_fx, synth_fx16, L_FRAME48k, 0); + Copy_Scale_sig_32_16( synth_fx, synth_fx16, L_FRAME48k, 0 ); #endif - if (st->hFdCngDec) - { - st->hFdCngDec->hFdCngCom->A_cng[0] = ONE_IN_Q12; + if ( st->hFdCngDec ) + { + st->hFdCngDec->hFdCngCom->A_cng[0] = ONE_IN_Q12; + } } + pop_wmops(); + return error; } - pop_wmops(); - return error; -} - -static void rescale_fdCngDec(HANDLE_FD_CNG_DEC hFdCngDec, Word16 Exp_diff) { - Scale_sig32(hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART, Exp_diff); -} + static void rescale_fdCngDec( HANDLE_FD_CNG_DEC hFdCngDec, Word16 Exp_diff ) + { + Scale_sig32( hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART, Exp_diff ); + } #endif diff --git a/lib_dec/acelp_core_switch_dec.c b/lib_dec/acelp_core_switch_dec.c index e0391ac47..a982d8bb4 100644 --- a/lib_dec/acelp_core_switch_dec.c +++ b/lib_dec/acelp_core_switch_dec.c @@ -206,7 +206,7 @@ ivas_error acelp_core_switch_dec( if ( st->flag_cna ) { - generate_masking_noise( synth_intFreq, st->hFdCngDec->hFdCngCom, 2 * L_SUBFR, 0, 0, 0, st->element_mode, NULL, nchan_out ); + generate_masking_noise( synth_intFreq, st->hFdCngDec->hFdCngCom, 2 * L_SUBFR, 0, 0, 0, st->element_mode, NULL, nchan_out ); } /*----------------------------------------------------------------* diff --git a/lib_dec/acelp_core_switch_dec_fx.c b/lib_dec/acelp_core_switch_dec_fx.c index 0e993139e..b86c8ae81 100644 --- a/lib_dec/acelp_core_switch_dec_fx.c +++ b/lib_dec/acelp_core_switch_dec_fx.c @@ -3,48 +3,46 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot.h" /* Function prototypes */ #ifdef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* * Local function prototypes *---------------------------------------------------------------------*/ -static void decod_gen_voic_core_switch_fx( Decoder_State *st_fx, const Word16 L_frame, const Word16 sharpFlag, const Word16 *Aq, - Word16 *exc, const Word32 core_brate, Word16 *Q_exc ); +static void decod_gen_voic_core_switch_fx( Decoder_State *st_fx, const Word16 L_frame, const Word16 sharpFlag, const Word16 *Aq, Word16 *exc, const Word32 core_brate, Word16 *Q_exc ); /*-------------------------------------------------------------------* -* acelp_core_switch_dec() -* -* ACELP core decoder in the first ACELP->HQ switching frame -*-------------------------------------------------------------------*/ + * acelp_core_switch_dec() + * + * ACELP core decoder in the first ACELP->HQ switching frame + *-------------------------------------------------------------------*/ ivas_error acelp_core_switch_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *synth_subfr_out, /* o : synthesized ACELP subframe Q_syn*/ - Word16 *tmp_synth_bwe, /* o : synthesized ACELP subframe BWE Q_syn*/ - const Word16 output_frame, /* i : input frame length */ - const Word16 core_switching_flag, /* i : core switching flag */ - Word16 *mem_synth, /* o : synthesis to overlap */ - Word16 *Q_syn -) + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *synth_subfr_out, /* o : synthesized ACELP subframe Q_syn*/ + Word16 *tmp_synth_bwe, /* o : synthesized ACELP subframe BWE Q_syn*/ + const Word16 output_frame, /* i : input frame length */ + const Word16 core_switching_flag, /* i : core switching flag */ + Word16 *mem_synth, /* o : synthesis to overlap */ + Word16 *Q_syn ) { - Word16 i, delta, L_frame_for_cs, decode_bwe, tmp; + Word16 i, delta, L_frame_for_cs, decode_bwe, tmp; Word16 d1m, ind1, fdelay, gapsize; Word32 cbrate; - Word16 synth_intFreq[2*L_SUBFR]; + Word16 synth_intFreq[2 * L_SUBFR]; CLDFB_SCALE_FACTOR scaleFactor; - Word32 workBuffer[128*3]; + Word32 workBuffer[128 * 3]; Word16 old_exc[L_EXC_DEC], *exc; - Word16 tmp_mem2[2*L_FILT48k], gain; - Word16 hb_synth_tmp[NS2SA(48000,10000000)]; + Word16 tmp_mem2[2 * L_FILT48k], gain; + Word16 hb_synth_tmp[NS2SA( 48000, 10000000 )]; const Word16 *hp_filter; - Word16 Aq[2*(M+1)]; - Word16 bpf_error_signal[2*L_SUBFR]; + Word16 Aq[2 * ( M + 1 )]; + Word16 bpf_error_signal[2 * L_SUBFR]; Word16 *pt1, *pt2; Word16 syn_fx_tmp[L_FRAME_16k]; Word32 *realBuffer[CLDFB_NO_COL_MAX_SWITCH], *imagBuffer[CLDFB_NO_COL_MAX_SWITCH]; @@ -55,10 +53,10 @@ ivas_error acelp_core_switch_dec_fx( ivas_error error; error = IVAS_ERR_OK; - FOR( i=0; iold_Aq_12_8_fx, Aq, M+1 ); - Copy( st_fx->old_Aq_12_8_fx, Aq + (M+1), M+1 ); + Copy( st_fx->old_Aq_12_8_fx, Aq, M + 1 ); + Copy( st_fx->old_Aq_12_8_fx, Aq + ( M + 1 ), M + 1 ); - set16_fx( mem_synth, 0, NS2SA(16000, DELAY_CLDFB_NS)+2 ); + set16_fx( mem_synth, 0, NS2SA( 16000, DELAY_CLDFB_NS ) + 2 ); set16_fx( synth_subfr_out, 0, SWITCH_MAX_GAP ); /* avoid valgrind complaining about uninitialized memory in core_switching_OLA_fx() */ /* set multiplication factor according to the sampling rate */ delta = 1; - if( GT_16(output_frame, L_FRAME16k)) + if ( GT_16( output_frame, L_FRAME16k ) ) { - delta = shr(output_frame,8); + delta = shr( output_frame, 8 ); } /*----------------------------------------------------------------* - * set switching frame bitrate - *----------------------------------------------------------------*/ + * set switching frame bitrate + *----------------------------------------------------------------*/ test(); test(); test(); - IF( core_switching_flag && EQ_16(st_fx->last_L_frame, st_fx->last_L_frame_ori)&&((EQ_16(st_fx->last_core,ACELP_CORE))||(EQ_16(st_fx->last_core,AMR_WB_CORE)))) + IF( core_switching_flag && EQ_16( st_fx->last_L_frame, st_fx->last_L_frame_ori ) && ( ( EQ_16( st_fx->last_core, ACELP_CORE ) ) || ( EQ_16( st_fx->last_core, AMR_WB_CORE ) ) ) ) { exc = old_exc + L_EXC_MEM_DEC; Copy( st_fx->old_exc_fx, old_exc, L_EXC_MEM_DEC ); /*scaling of exc from previous frame*/ - IF( EQ_16(st_fx->last_L_frame, L_FRAME)) + IF( EQ_16( st_fx->last_L_frame, L_FRAME ) ) { - cbrate = L_add(st_fx->core_brate, 0); - if( GT_32(cbrate, ACELP_24k40)) + cbrate = L_add( st_fx->core_brate, 0 ); + if ( GT_32( cbrate, ACELP_24k40 ) ) { - cbrate = L_add(ACELP_24k40, 0); + cbrate = L_add( ACELP_24k40, 0 ); } L_frame_for_cs = L_FRAME; @@ -109,17 +107,17 @@ ivas_error acelp_core_switch_dec_fx( } ELSE { - IF( LE_32(st_fx->core_brate, ACELP_8k00)) + IF( LE_32( st_fx->core_brate, ACELP_8k00 ) ) { - cbrate = L_add(ACELP_8k00, 0); + cbrate = L_add( ACELP_8k00, 0 ); } - ELSE IF( LE_32(st_fx->core_brate, ACELP_14k80)) + ELSE IF( LE_32( st_fx->core_brate, ACELP_14k80 ) ) { - cbrate = L_add(ACELP_14k80, 0); + cbrate = L_add( ACELP_14k80, 0 ); } ELSE { - cbrate = L_min(st_fx->core_brate, ACELP_22k60 ); + cbrate = L_min( st_fx->core_brate, ACELP_22k60 ); } L_frame_for_cs = L_FRAME16k; @@ -127,63 +125,63 @@ ivas_error acelp_core_switch_dec_fx( } /*----------------------------------------------------------------* - * Excitation decoding - *----------------------------------------------------------------*/ - config_acelp1(DEC, st_fx->total_brate, cbrate, st_fx->core, -1, -1, st_fx->last_L_frame, -1, &(st_fx->acelp_cfg), st_fx->next_bit_pos, GENERIC, -1, -1, &decode_bwe /* dummy */, &i, st_fx->element_mode, &i /*dummy*/, 0, 0, st_fx->idchan, st_fx->active_cnt, 0, 0, 0 ); + * Excitation decoding + *----------------------------------------------------------------*/ + config_acelp1( DEC, st_fx->total_brate, cbrate, st_fx->core, -1, -1, st_fx->last_L_frame, -1, &( st_fx->acelp_cfg ), st_fx->next_bit_pos, GENERIC, -1, -1, &decode_bwe /* dummy */, &i, st_fx->element_mode, &i /*dummy*/, 0, 0, st_fx->idchan, st_fx->active_cnt, 0, 0, 0 ); decod_gen_voic_core_switch_fx( st_fx, L_frame_for_cs, 0, Aq, exc, cbrate, &st_fx->Q_exc ); /*----------------------------------------------------------------* - * synthesis, deemphasis, postprocessing and resampling - *----------------------------------------------------------------*/ + * synthesis, deemphasis, postprocessing and resampling + *----------------------------------------------------------------*/ /* Core synthesis at 12.8kHz or 16kHz */ Rescale_mem( st_fx->Q_exc, &st_fx->prev_Q_syn, &st_fx->Q_syn, st_fx->mem_syn2_fx, st_fx->mem_syn_clas_estim_fx, - 4, &st_fx->mem_deemph_fx, hBPF->pst_old_syn_fx, &hBPF->pst_mem_deemp_err_fx,&st_fx->agc_mem_fx[1], st_fx->hPFstat , 1, 0, NULL ); + 4, &st_fx->mem_deemph_fx, hBPF->pst_old_syn_fx, &hBPF->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], st_fx->hPFstat, 1, 0, NULL ); - syn_12k8_fx( 2*L_SUBFR, Aq, exc, synth_intFreq, st_fx->mem_syn2_fx, 1, st_fx->Q_exc, st_fx->Q_syn ); + syn_12k8_fx( 2 * L_SUBFR, Aq, exc, synth_intFreq, st_fx->mem_syn2_fx, 1, st_fx->Q_exc, st_fx->Q_syn ); - IF(st_fx->hPFstat->on && (EQ_16(st_fx->last_bwidth,NB))) + IF( st_fx->hPFstat->on && ( EQ_16( st_fx->last_bwidth, NB ) ) ) { Word16 tmp_noise, pitch_buf_tmp[2]; tmp_noise = 0; - FOR( i=0; i<2; i++ ) + FOR( i = 0; i < 2; i++ ) { pitch_buf_tmp[i] = L_SUBFR; move16(); } - nb_post_filt_fx( 2*L_SUBFR, st_fx->hPFstat, &tmp_noise, 0, synth_intFreq, Aq, pitch_buf_tmp, AUDIO, st_fx->BER_detect, 0 ); + nb_post_filt_fx( 2 * L_SUBFR, st_fx->hPFstat, &tmp_noise, 0, synth_intFreq, Aq, pitch_buf_tmp, AUDIO, st_fx->BER_detect, 0 ); } - IF( EQ_16(L_frame_for_cs,L_FRAME)) + IF( EQ_16( L_frame_for_cs, L_FRAME ) ) { - deemph_fx( synth_intFreq, PREEMPH_FAC, 2*L_SUBFR, &(st_fx->mem_deemph_fx) ); + deemph_fx( synth_intFreq, PREEMPH_FAC, 2 * L_SUBFR, &( st_fx->mem_deemph_fx ) ); } ELSE { - deemph_fx( synth_intFreq, PREEMPH_FAC_16k, 2*L_SUBFR, &(st_fx->mem_deemph_fx) ); + deemph_fx( synth_intFreq, PREEMPH_FAC_16k, 2 * L_SUBFR, &( st_fx->mem_deemph_fx ) ); } - unscale_AGC( synth_intFreq, st_fx->Q_syn, syn_fx_tmp+M, st_fx->agc_mem_fx, 2*L_SUBFR ); - Copy( syn_fx_tmp+M, synth_intFreq, 2*L_SUBFR ); + unscale_AGC( synth_intFreq, st_fx->Q_syn, syn_fx_tmp + M, st_fx->agc_mem_fx, 2 * L_SUBFR ); + Copy( syn_fx_tmp + M, synth_intFreq, 2 * L_SUBFR ); test(); - IF( st_fx->hPFstat->on && (NE_16(st_fx->last_bwidth,NB))) + IF( st_fx->hPFstat->on && ( NE_16( st_fx->last_bwidth, NB ) ) ) { - Copy( st_fx->hPFstat->mem_pf_in+L_SYN_MEM-M, bpf_error_signal, M ); + Copy( st_fx->hPFstat->mem_pf_in + L_SYN_MEM - M, bpf_error_signal, M ); Copy( synth_intFreq, bpf_error_signal + M, L_SUBFR ); - Residu3_fx ( Aq, bpf_error_signal + M, exc, L_SUBFR, 1 ); - E_UTIL_synthesis ( 1, Aq, exc, bpf_error_signal, L_SUBFR, st_fx->hPFstat->mem_stp+L_SYN_MEM-M, 0, M ); - scale_st_fx ( synth_intFreq, bpf_error_signal, &st_fx->hPFstat->gain_prec, L_SUBFR ); - Copy( bpf_error_signal, synth_intFreq, L_SUBFR/2 ); - blend_subfr2_fx( bpf_error_signal + L_SUBFR/2, synth_intFreq + L_SUBFR/2, synth_intFreq + L_SUBFR/2 ); + Residu3_fx( Aq, bpf_error_signal + M, exc, L_SUBFR, 1 ); + E_UTIL_synthesis( 1, Aq, exc, bpf_error_signal, L_SUBFR, st_fx->hPFstat->mem_stp + L_SYN_MEM - M, 0, M ); + scale_st_fx( synth_intFreq, bpf_error_signal, &st_fx->hPFstat->gain_prec, L_SUBFR ); + Copy( bpf_error_signal, synth_intFreq, L_SUBFR / 2 ); + blend_subfr2_fx( bpf_error_signal + L_SUBFR / 2, synth_intFreq + L_SUBFR / 2, synth_intFreq + L_SUBFR / 2 ); } st_fx->hPFstat->on = 0; move16(); - IF ( st_fx->flag_cna != 0 ) + IF( st_fx->flag_cna != 0 ) { - generate_masking_noise_fx( synth_intFreq, st_fx->Q_syn, st_fx->hFdCngDec->hFdCngCom, 2*L_SUBFR, 0); + generate_masking_noise_fx( synth_intFreq, st_fx->Q_syn, st_fx->hFdCngDec->hFdCngCom, 2 * L_SUBFR, 0 ); } /*----------------------------------------------------------------* @@ -191,66 +189,66 @@ ivas_error acelp_core_switch_dec_fx( * Bass post-filter *----------------------------------------------------------------*/ - bass_psfilter_fx(st_fx->hBPF, st_fx->Opt_AMR_WB, synth_intFreq, 2*L_SUBFR, NULL, + bass_psfilter_fx( st_fx->hBPF, st_fx->Opt_AMR_WB, synth_intFreq, 2 * L_SUBFR, NULL, st_fx->bpf_off, st_fx->stab_fac_fx, &st_fx->stab_fac_smooth_fx, GENERIC, st_fx->Q_syn, bpf_error_signal ); - if ((error = cldfb_save_memory( st_fx->cldfbAna)) != IVAS_ERR_OK) + if ( ( error = cldfb_save_memory( st_fx->cldfbAna ) ) != IVAS_ERR_OK ) { return error; } cldfbAnalysisFiltering( st_fx->cldfbAna, realBuffer, imagBuffer, &scaleFactor, synth_intFreq, - negate(st_fx->Q_syn), CLDFB_NO_COL_MAX_SWITCH, workBuffer); - cldfb_restore_memory( st_fx->cldfbAna); + negate( st_fx->Q_syn ), CLDFB_NO_COL_MAX_SWITCH, workBuffer ); + cldfb_restore_memory( st_fx->cldfbAna ); /* CLDFB synthesis of the combined signal */ scaleFactor.hb_scale = scaleFactor.lb_scale; move16(); /* CLDFB analysis and add the BPF error signal */ - if ((error = cldfb_save_memory( st_fx->cldfbBPF )) != IVAS_ERR_OK) + if ( ( error = cldfb_save_memory( st_fx->cldfbBPF ) ) != IVAS_ERR_OK ) { return error; } i = 0; move16(); - if( st_fx->bpf_off == 0 ) + if ( st_fx->bpf_off == 0 ) { i = CLDFB_NO_COL_MAX_SWITCH; move16(); } - addBassPostFilter_fx( bpf_error_signal, realBuffer, imagBuffer, st_fx->cldfbBPF, workBuffer, negate(st_fx->Q_syn), - i, CLDFB_NO_COL_MAX_SWITCH, st_fx->cldfbAna->no_channels, &scaleFactor ); + addBassPostFilter_fx( bpf_error_signal, realBuffer, imagBuffer, st_fx->cldfbBPF, workBuffer, negate( st_fx->Q_syn ), + i, CLDFB_NO_COL_MAX_SWITCH, st_fx->cldfbAna->no_channels, &scaleFactor ); cldfb_restore_memory( st_fx->cldfbBPF ); /* CLDFB synthesis of the combined signal */ scaleFactor.hb_scale = scaleFactor.lb_scale; - if ((error = cldfb_save_memory( st_fx->cldfbSyn )) != IVAS_ERR_OK) + if ( ( error = cldfb_save_memory( st_fx->cldfbSyn ) ) != IVAS_ERR_OK ) { return error; } - cldfbSynthesisFiltering(st_fx->cldfbSyn, realBuffer, imagBuffer, &scaleFactor, synth_subfr_out, 0, CLDFB_NO_COL_MAX_SWITCH, workBuffer); + cldfbSynthesisFiltering( st_fx->cldfbSyn, realBuffer, imagBuffer, &scaleFactor, synth_subfr_out, 0, CLDFB_NO_COL_MAX_SWITCH, workBuffer ); cldfb_restore_memory( st_fx->cldfbSyn ); *Q_syn = 0; move16(); - Copy_Scale_sig( synth_intFreq+ NS2SA(L_frame_for_cs * 50, SWITCH_GAP_LENGTH_NS-DELAY_CLDFB_NS)-2, mem_synth, NS2SA(L_frame_for_cs * 50, DELAY_CLDFB_NS)+2, negate(st_fx->Q_syn) ); /* Copy mem with Q0 */ + Copy_Scale_sig( synth_intFreq + NS2SA( L_frame_for_cs * 50, SWITCH_GAP_LENGTH_NS - DELAY_CLDFB_NS ) - 2, mem_synth, NS2SA( L_frame_for_cs * 50, DELAY_CLDFB_NS ) + 2, negate( st_fx->Q_syn ) ); /* Copy mem with Q0 */ /*----------------------------------------------------------------* - * BWE decoding - *----------------------------------------------------------------*/ + * BWE decoding + *----------------------------------------------------------------*/ decode_bwe = 0; move16(); test(); test(); - IF( !(( EQ_16(inner_frame_tbl[st_fx->bwidth], L_FRAME16k)&&EQ_16(st_fx->last_L_frame,L_FRAME16k))||EQ_16(inner_frame_tbl[st_fx->bwidth],L_FRAME8k))) + IF( !( ( EQ_16( inner_frame_tbl[st_fx->bwidth], L_FRAME16k ) && EQ_16( st_fx->last_L_frame, L_FRAME16k ) ) || EQ_16( inner_frame_tbl[st_fx->bwidth], L_FRAME8k ) ) ) { /* Decoding of BWE */ - d1m = (Word16)get_next_indice(st_fx, AUDIODELAYBITS); - ind1 = (Word16)get_next_indice(st_fx, NOOFGAINBITS1); - gain = usdequant_fx( ind1, MINVALUEOFFIRSTGAIN_FX, shr(DELTAOFFIRSTGAIN_FX,3) ); /*Q13*/ + d1m = (Word16) get_next_indice( st_fx, AUDIODELAYBITS ); + ind1 = (Word16) get_next_indice( st_fx, NOOFGAINBITS1 ); + gain = usdequant_fx( ind1, MINVALUEOFFIRSTGAIN_FX, shr( DELTAOFFIRSTGAIN_FX, 3 ) ); /*Q13*/ decode_bwe = 1; move16(); } @@ -258,25 +256,25 @@ ivas_error acelp_core_switch_dec_fx( test(); test(); test(); - IF( decode_bwe && !(( EQ_16(output_frame, L_FRAME16k)&&EQ_16(st_fx->last_L_frame,L_FRAME16k))||EQ_16(output_frame,L_FRAME8k))) + IF( decode_bwe && !( ( EQ_16( output_frame, L_FRAME16k ) && EQ_16( st_fx->last_L_frame, L_FRAME16k ) ) || EQ_16( output_frame, L_FRAME8k ) ) ) { - set16_fx( tmp_mem2, 0, 2*L_FILT48k ); + set16_fx( tmp_mem2, 0, 2 * L_FILT48k ); hp_filter = hp16000_48000_fx; fdelay = 48; move16(); - IF ( EQ_32(st_fx->output_Fs, 16000)) + IF( EQ_32( st_fx->output_Fs, 16000 ) ) { - IF( EQ_16(st_fx->last_L_frame, L_FRAME)) + IF( EQ_16( st_fx->last_L_frame, L_FRAME ) ) { hp_filter = hp12800_16000_fx; fdelay = 20; move16(); } } - ELSE IF( EQ_32(st_fx->output_Fs, 32000)) + ELSE IF( EQ_32( st_fx->output_Fs, 32000 ) ) { - IF( EQ_16(st_fx->last_L_frame, L_FRAME)) + IF( EQ_16( st_fx->last_L_frame, L_FRAME ) ) { hp_filter = hp12800_32000_fx; fdelay = 40; @@ -289,7 +287,7 @@ ivas_error acelp_core_switch_dec_fx( move16(); } } - ELSE IF( EQ_16(st_fx->last_L_frame, L_FRAME)) + ELSE IF( EQ_16( st_fx->last_L_frame, L_FRAME ) ) { hp_filter = hp12800_48000_fx; fdelay = 60; @@ -299,39 +297,40 @@ ivas_error acelp_core_switch_dec_fx( /* safety check in case of bit errors */ i = MAX_D1M_16k; move16(); - if( EQ_16(st_fx->last_L_frame,L_FRAME)) + if ( EQ_16( st_fx->last_L_frame, L_FRAME ) ) { i = MAX_D1M_12k8; move16(); } - IF( GE_16(d1m,i)) + IF( GE_16( d1m, i ) ) { - d1m = sub(i,1); - gain = 0; /* force muting */ move16(); + d1m = sub( i, 1 ); + gain = 0; /* force muting */ + move16(); st_fx->BER_detect = 1; move16(); } - i = NS2SA_fx2(st_fx->output_Fs, FRAME_SIZE_NS-ACELP_LOOK_NS-DELAY_BWE_TOTAL_NS); + i = NS2SA_fx2( st_fx->output_Fs, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS ); move16(); Copy( st_fx->old_synth_sw_fx, hb_synth_tmp, i ); - set16_fx( hb_synth_tmp + i, 0, NS2SA_fx2(st_fx->output_Fs, 10000000L) - i ); - fir_fx( hb_synth_tmp, hp_filter, hb_synth_tmp, tmp_mem2, shr(output_frame,1), fdelay, 1, 0 ); + set16_fx( hb_synth_tmp + i, 0, NS2SA_fx2( st_fx->output_Fs, 10000000L ) - i ); + fir_fx( hb_synth_tmp, hp_filter, hb_synth_tmp, tmp_mem2, shr( output_frame, 1 ), fdelay, 1, 0 ); set16_fx( tmp_synth_bwe, 0, SWITCH_MAX_GAP ); - gapsize = i_mult2(delta, (NS2SA(16000,SWITCH_GAP_LENGTH_NS))); + gapsize = i_mult2( delta, ( NS2SA( 16000, SWITCH_GAP_LENGTH_NS ) ) ); pt1 = tmp_synth_bwe; - tmp = add(i_mult(d1m,delta),fdelay); + tmp = add( i_mult( d1m, delta ), fdelay ); pt2 = &hb_synth_tmp[tmp]; - FOR( i=0; iHQ switching frame in case of BAD frame -*-------------------------------------------------------------------*/ + * acelp_core_switch_dec_bfi() + * + * ACELP core decoder in the first ACELP->HQ switching frame in case of BAD frame + *-------------------------------------------------------------------*/ ivas_error acelp_core_switch_dec_bfi_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 synth_out[], /* o : synthesis Q_syn */ - const Word16 coder_type /* i : coder type */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 synth_out[], /* o : synthesis Q_syn */ + const Word16 coder_type /* i : coder type */ ) { - Word16 old_exc[L_EXC_DEC], *exc; /* excitation signal buffer */ - Word16 syn[L_FRAME16k]; /* synthesis signal buffer */ - Word16 lsf_new[M]; /* LSFs at the end of the frame */ - Word16 lsp_new[M]; /* LSPs at the end of the frame */ - Word16 Aq[NB_SUBFR16k*(M+1)]; /* A(q) quantized for the 4 subframes */ - Word16 old_exc2[L_FRAME16k + L_EXC_MEM], *exc2; /* total excitation buffer */ - Word16 tmp_noise; /* Long term temporary noise energy */ - Word16 FEC_pitch; /* FEC pitch */ - Word16 old_bwe_exc[((PIT16k_MAX + (L_FRAME16k+1) + L_SUBFR16k) * 2)]; /* excitation buffer */ - Word16 *bwe_exc; /* Excitation for SWB TBE */ + Word16 old_exc[L_EXC_DEC], *exc; /* excitation signal buffer */ + Word16 syn[L_FRAME16k]; /* synthesis signal buffer */ + Word16 lsf_new[M]; /* LSFs at the end of the frame */ + Word16 lsp_new[M]; /* LSPs at the end of the frame */ + Word16 Aq[NB_SUBFR16k * ( M + 1 )]; /* A(q) quantized for the 4 subframes */ + Word16 old_exc2[L_FRAME16k + L_EXC_MEM], *exc2; /* total excitation buffer */ + Word16 tmp_noise; /* Long term temporary noise energy */ + Word16 FEC_pitch; /* FEC pitch */ + Word16 old_bwe_exc[( ( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2 )]; /* excitation buffer */ + Word16 *bwe_exc; /* Excitation for SWB TBE */ Word16 tmp_float[NBPSF_PIT_MAX]; Word16 tmp_float2[M]; Word16 tmp_float3; @@ -382,26 +381,26 @@ ivas_error acelp_core_switch_dec_bfi_fx( Word32 realBufferTmp[CLDFB_NO_COL_MAX_SWITCH_BFI][CLDFB_NO_CHANNELS_MAX], imagBufferTmp[CLDFB_NO_COL_MAX_SWITCH_BFI][CLDFB_NO_CHANNELS_MAX]; Word16 i; CLDFB_SCALE_FACTOR scaleFactor; - Word32 workBuffer[128*3]; + Word32 workBuffer[128 * 3]; MUSIC_POSTFILT_HANDLE hMusicPF; BPF_DEC_HANDLE hBPF; ivas_error error; - + hMusicPF = st_fx->hMusicPF; hBPF = st_fx->hBPF; error = IVAS_ERR_OK; - FOR( i=0; iQ_exc; move16(); st_fx->bpf_off = 1; @@ -413,18 +412,18 @@ ivas_error acelp_core_switch_dec_bfi_fx( Copy( st_fx->old_exc_fx, old_exc, L_EXC_MEM_DEC ); exc = old_exc + L_EXC_MEM_DEC; - IF(st_fx->hWIDec != NULL) + IF( st_fx->hWIDec != NULL ) { - Copy(st_fx->hWIDec->old_exc2_fx, old_exc2, L_EXC_MEM); + Copy( st_fx->hWIDec->old_exc2_fx, old_exc2, L_EXC_MEM ); } ELSE { - set16_fx(old_exc2, 0, L_EXC_MEM); + set16_fx( old_exc2, 0, L_EXC_MEM ); } exc2 = old_exc2 + L_EXC_MEM; - if (st_fx->hBWE_TD != NULL) + if ( st_fx->hBWE_TD != NULL ) { - Copy(st_fx->hBWE_TD->old_bwe_exc_fx, old_bwe_exc, PIT16k_MAX * 2); + Copy( st_fx->hBWE_TD->old_bwe_exc_fx, old_bwe_exc, PIT16k_MAX * 2 ); bwe_exc = old_bwe_exc + PIT16k_MAX * 2; } else @@ -438,39 +437,39 @@ ivas_error acelp_core_switch_dec_bfi_fx( move16(); /* SC-VBR */ - if( EQ_16(st_fx->last_nelp_mode_dec, 1)) + if ( EQ_16( st_fx->last_nelp_mode_dec, 1 ) ) { st_fx->nelp_mode_dec = 1; move16(); } - Copy(st_fx->mem_AR_fx,tmp_float,M); - Copy(st_fx->mem_MA_fx,tmp_float2,M); + Copy( st_fx->mem_AR_fx, tmp_float, M ); + Copy( st_fx->mem_MA_fx, tmp_float2, M ); /* LSF estimation and A(z) calculation */ - lsf_dec_bfi(MODE1, lsf_new, st_fx->lsf_old_fx, st_fx->lsf_adaptive_mean_fx, NULL, st_fx->mem_MA_fx, st_fx->mem_AR_fx, - st_fx->stab_fac_fx, st_fx->last_coder_type, st_fx->L_frame, st_fx->last_good, - st_fx->nbLostCmpt, 0, NULL, NULL, NULL, st_fx->hGSCDec->Last_GSC_pit_band_idx, st_fx->Opt_AMR_WB, 0, st_fx->bwidth); + lsf_dec_bfi( MODE1, lsf_new, st_fx->lsf_old_fx, st_fx->lsf_adaptive_mean_fx, NULL, st_fx->mem_MA_fx, st_fx->mem_AR_fx, + st_fx->stab_fac_fx, st_fx->last_coder_type, st_fx->L_frame, st_fx->last_good, + st_fx->nbLostCmpt, 0, NULL, NULL, NULL, st_fx->hGSCDec->Last_GSC_pit_band_idx, st_fx->Opt_AMR_WB, 0, st_fx->bwidth ); - FEC_lsf2lsp_interp( st_fx, st_fx->L_frame, Aq, lsf_new, lsp_new); + FEC_lsf2lsp_interp( st_fx, st_fx->L_frame, Aq, lsf_new, lsp_new ); Copy( tmp_float, st_fx->mem_AR_fx, M ); Copy( tmp_float2, st_fx->mem_MA_fx, M ); /*----------------------------------------------------------------* - * Excitation decoding - *----------------------------------------------------------------*/ + * Excitation decoding + *----------------------------------------------------------------*/ - IF( EQ_16(st_fx->nelp_mode_dec, 1)) + IF( EQ_16( st_fx->nelp_mode_dec, 1 ) ) { Word16 gain_buf[NB_SUBFR16k]; - Scale_sig(exc-L_EXC_MEM, L_EXC_MEM, -st_fx->Q_exc); + Scale_sig( exc - L_EXC_MEM, L_EXC_MEM, -st_fx->Q_exc ); st_fx->Q_exc = 0; /* SC-VBR */ decod_nelp_fx( st_fx, &tmp_noise, pitch_buf, exc, exc2, voice_factors, bwe_exc, &Q_exc, st_fx->bfi, gain_buf ); FEC_pitch = pitch_buf[3]; move16(); - Rescale_exc(hMusicPF->dct_post_old_exc_fx, exc, NULL, st_fx->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32)0, &Q_exc, st_fx->Q_subfr, exc2, L_FRAME, coder_type); + Rescale_exc( hMusicPF->dct_post_old_exc_fx, exc, NULL, st_fx->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32) 0, &Q_exc, st_fx->Q_subfr, exc2, L_FRAME, coder_type ); st_fx->Q_exc = Q_exc; } ELSE @@ -490,8 +489,8 @@ ivas_error acelp_core_switch_dec_bfi_fx( /* calculation of excitation signal */ FEC_exc_estim_fx( st_fx, st_fx->L_frame, exc, exc2, syn /* dummy buffer */, pitch_buf, voice_factors, &FEC_pitch, bwe_exc, lsf_new, &Q_exc, &tmp_noise ); - Rescale_exc( NULL, exc, bwe_exc, st_fx->hGSCDec->last_exc_dct_in_fx, st_fx->L_frame, L_FRAME32k, (Word32)0, - &Q_exc, st_fx->Q_subfr, exc2, st_fx->L_frame, st_fx->last_coder_type); + Rescale_exc( NULL, exc, bwe_exc, st_fx->hGSCDec->last_exc_dct_in_fx, st_fx->L_frame, L_FRAME32k, (Word32) 0, + &Q_exc, st_fx->Q_subfr, exc2, st_fx->L_frame, st_fx->last_coder_type ); st_fx->seed = tmp_float[5]; move16(); @@ -508,25 +507,25 @@ ivas_error acelp_core_switch_dec_bfi_fx( } /*------------------------------------------------------------------* - * Synthesis - *-----------------------------------------------------------------*/ + * Synthesis + *-----------------------------------------------------------------*/ Rescale_mem( Q_exc, &st_fx->prev_Q_syn, &st_fx->Q_syn, st_fx->mem_syn2_fx, st_fx->mem_syn_clas_estim_fx, 4, &st_fx->mem_deemph_fx, hBPF->pst_old_syn_fx, &hBPF->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], st_fx->hPFstat, 1, 0, NULL ); - Copy( st_fx->mem_syn2_fx,tmp_float,M); + Copy( st_fx->mem_syn2_fx, tmp_float, M ); syn_12k8_fx( st_fx->L_frame, Aq, exc2, syn, tmp_float, 1, Q_exc, st_fx->Q_syn ); tmp_float32 = st_fx->enr_old_fx; - frame_ener_fx( st_fx->L_frame, st_fx->last_good, syn, shr(add(FEC_pitch,32),6), &tmp_float32, st_fx->L_frame, st_fx->Q_syn, 3, 0 ); + frame_ener_fx( st_fx->L_frame, st_fx->last_good, syn, shr( add( FEC_pitch, 32 ), 6 ), &tmp_float32, st_fx->L_frame, st_fx->Q_syn, 3, 0 ); /*------------------------------------------------------------------* - * Perform fixed deemphasis through 1/(1 - g*z^-1) - *-----------------------------------------------------------------*/ + * Perform fixed deemphasis through 1/(1 - g*z^-1) + *-----------------------------------------------------------------*/ tmp_float[0] = st_fx->mem_deemph_fx; move16(); /*if in acelp_core_dec_fx deemph_fx is used*/ /*tmp_float = shr(st_fx->mem_deemph_fx, sub(st_fx->Q_syn,1)); if in acelp_core_dec_fx Deemph2 is used*/ - IF(EQ_16(st_fx->L_frame,L_FRAME )) + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { deemph_fx( syn, PREEMPH_FAC, L_FRAME, &tmp_float[0] ); /*Q0*/ } @@ -536,53 +535,53 @@ ivas_error acelp_core_switch_dec_bfi_fx( } /*----------------------------------------------------------------* - * Bass post-filter - *----------------------------------------------------------------*/ + * Bass post-filter + *----------------------------------------------------------------*/ - st_fx->bpf_off=1; + st_fx->bpf_off = 1; move16(); - Copy(hBPF->pst_old_syn_fx,tmp_float,NBPSF_PIT_MAX); + Copy( hBPF->pst_old_syn_fx, tmp_float, NBPSF_PIT_MAX ); tmp_float3 = st_fx->stab_fac_smooth_fx; move16(); - Copy(hBPF->mem_mean_pit_fx,tmp_float4, L_TRACK_HIST); - Copy(hBPF->Track_on_hist,tmp_float5, L_TRACK_HIST); - Copy(hBPF->vibrato_hist,tmp_float6, L_TRACK_HIST); + Copy( hBPF->mem_mean_pit_fx, tmp_float4, L_TRACK_HIST ); + Copy( hBPF->Track_on_hist, tmp_float5, L_TRACK_HIST ); + Copy( hBPF->vibrato_hist, tmp_float6, L_TRACK_HIST ); tmp_float7 = hBPF->psf_att_fx; move16(); - bass_psfilter_fx(st_fx->hBPF, st_fx->Opt_AMR_WB, syn, st_fx->L_frame, pitch_buf, - st_fx->bpf_off, st_fx->stab_fac_fx, &tmp_float3, coder_type, st_fx->Q_syn, old_exc /* tmp buffer*/); + bass_psfilter_fx( st_fx->hBPF, st_fx->Opt_AMR_WB, syn, st_fx->L_frame, pitch_buf, + st_fx->bpf_off, st_fx->stab_fac_fx, &tmp_float3, coder_type, st_fx->Q_syn, old_exc /* tmp buffer*/ ); - Copy(tmp_float, hBPF->pst_old_syn_fx, NBPSF_PIT_MAX); - Copy(tmp_float4, hBPF->mem_mean_pit_fx, L_TRACK_HIST); - Copy(tmp_float5, hBPF->Track_on_hist, L_TRACK_HIST); - Copy(tmp_float6, hBPF->vibrato_hist, L_TRACK_HIST); - hBPF->psf_att_fx = tmp_float7 ; + Copy( tmp_float, hBPF->pst_old_syn_fx, NBPSF_PIT_MAX ); + Copy( tmp_float4, hBPF->mem_mean_pit_fx, L_TRACK_HIST ); + Copy( tmp_float5, hBPF->Track_on_hist, L_TRACK_HIST ); + Copy( tmp_float6, hBPF->vibrato_hist, L_TRACK_HIST ); + hBPF->psf_att_fx = tmp_float7; /*----------------------------------------------------------------* - * Resamping to the output sampling frequency - *----------------------------------------------------------------*/ + * Resamping to the output sampling frequency + *----------------------------------------------------------------*/ /* CLDFB analysis of the synthesis at internal sampling rate */ - if ((error = cldfb_save_memory( st_fx->cldfbAna)) != IVAS_ERR_OK) + if ( ( error = cldfb_save_memory( st_fx->cldfbAna ) ) != IVAS_ERR_OK ) { return error; } cldfbAnalysisFiltering( st_fx->cldfbAna, realBuffer, imagBuffer, &scaleFactor, syn, - negate(st_fx->Q_syn), CLDFB_NO_COL_MAX_SWITCH_BFI, workBuffer); - cldfb_restore_memory( st_fx->cldfbAna); + negate( st_fx->Q_syn ), CLDFB_NO_COL_MAX_SWITCH_BFI, workBuffer ); + cldfb_restore_memory( st_fx->cldfbAna ); scaleFactor.hb_scale = scaleFactor.lb_scale; /* CLDFB synthesis of the combined signal */ - if ((error = cldfb_save_memory( st_fx->cldfbSyn )) != IVAS_ERR_OK) + if ( ( error = cldfb_save_memory( st_fx->cldfbSyn ) ) != IVAS_ERR_OK ) { return error; } cldfbSynthesisFiltering( st_fx->cldfbSyn, realBuffer, imagBuffer, &scaleFactor, synth_out, - negate(st_fx->Q_syn), CLDFB_NO_COL_MAX_SWITCH_BFI, workBuffer ); + negate( st_fx->Q_syn ), CLDFB_NO_COL_MAX_SWITCH_BFI, workBuffer ); /* output to Q0 */ - Scale_sig(synth_out,L_FRAME48k, negate(st_fx->Q_syn)); + Scale_sig( synth_out, L_FRAME48k, negate( st_fx->Q_syn ) ); cldfb_restore_memory( st_fx->cldfbSyn ); @@ -591,22 +590,22 @@ ivas_error acelp_core_switch_dec_bfi_fx( #ifdef IVAS_FLOAT_FIXED ivas_error acelp_core_switch_dec_bfi_ivas_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 synth_out[], /* o : synthesis Q_syn */ - const Word16 coder_type /* i : coder type */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 synth_out[], /* o : synthesis Q_syn */ + const Word16 coder_type /* i : coder type */ ) { - Word16 old_exc[L_EXC_DEC], *exc; /* excitation signal buffer */ - Word16 syn[L_FRAME16k]; /* synthesis signal buffer */ - Word32 syn32[L_FRAME16k]; /* synthesis signal buffer */ - Word16 lsf_new[M]; /* LSFs at the end of the frame */ - Word16 lsp_new[M]; /* LSPs at the end of the frame */ - Word16 Aq[NB_SUBFR16k*(M+1)]; /* A(q) quantized for the 4 subframes */ - Word16 old_exc2[L_FRAME16k + L_EXC_MEM], *exc2; /* total excitation buffer */ - Word16 tmp_noise; /* Long term temporary noise energy */ - Word16 FEC_pitch; /* FEC pitch */ - Word16 old_bwe_exc[((PIT16k_MAX + (L_FRAME16k+1) + L_SUBFR16k) * 2)]; /* excitation buffer */ - Word16 *bwe_exc; /* Excitation for SWB TBE */ + Word16 old_exc[L_EXC_DEC], *exc; /* excitation signal buffer */ + Word16 syn[L_FRAME16k]; /* synthesis signal buffer */ + Word32 syn32[L_FRAME16k]; /* synthesis signal buffer */ + Word16 lsf_new[M]; /* LSFs at the end of the frame */ + Word16 lsp_new[M]; /* LSPs at the end of the frame */ + Word16 Aq[NB_SUBFR16k * ( M + 1 )]; /* A(q) quantized for the 4 subframes */ + Word16 old_exc2[L_FRAME16k + L_EXC_MEM], *exc2; /* total excitation buffer */ + Word16 tmp_noise; /* Long term temporary noise energy */ + Word16 FEC_pitch; /* FEC pitch */ + Word16 old_bwe_exc[( ( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2 )]; /* excitation buffer */ + Word16 *bwe_exc; /* Excitation for SWB TBE */ Word16 tmp_float[NBPSF_PIT_MAX]; Word16 tmp_float2[M]; Word16 tmp_float3; @@ -617,32 +616,32 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( Word32 tmp_float32; Word16 voice_factors[NB_SUBFR16k]; Word16 pitch_buf[NB_SUBFR16k]; - Word16 Q_exc,Qtmp; + Word16 Q_exc, Qtmp; Word32 *realBuffer[CLDFB_NO_COL_MAX_SWITCH_BFI], *imagBuffer[CLDFB_NO_COL_MAX_SWITCH_BFI]; Word32 realBufferTmp[CLDFB_NO_COL_MAX_SWITCH_BFI][CLDFB_NO_CHANNELS_MAX], imagBufferTmp[CLDFB_NO_COL_MAX_SWITCH_BFI][CLDFB_NO_CHANNELS_MAX]; Word16 i; - //CLDFB_SCALE_FACTOR scaleFactor; - //Word32 workBuffer[128*3]; + // CLDFB_SCALE_FACTOR scaleFactor; + // Word32 workBuffer[128*3]; Word32 synth32[L_FRAME48k]; MUSIC_POSTFILT_HANDLE hMusicPF; BPF_DEC_HANDLE hBPF; ivas_error error; - + hMusicPF = st_fx->hMusicPF; hBPF = st_fx->hBPF; error = IVAS_ERR_OK; - FOR( i=0; iQ_exc; move16(); st_fx->bpf_off = 1; @@ -654,18 +653,18 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( Copy( st_fx->old_exc_fx, old_exc, L_EXC_MEM_DEC ); exc = old_exc + L_EXC_MEM_DEC; - IF(st_fx->hWIDec != NULL) + IF( st_fx->hWIDec != NULL ) { - Copy(st_fx->hWIDec->old_exc2_fx, old_exc2, L_EXC_MEM); + Copy( st_fx->hWIDec->old_exc2_fx, old_exc2, L_EXC_MEM ); } ELSE { - set16_fx(old_exc2, 0, L_EXC_MEM); + set16_fx( old_exc2, 0, L_EXC_MEM ); } exc2 = old_exc2 + L_EXC_MEM; - if (st_fx->hBWE_TD != NULL) + if ( st_fx->hBWE_TD != NULL ) { - Copy(st_fx->hBWE_TD->old_bwe_exc_fx, old_bwe_exc, PIT16k_MAX * 2); + Copy( st_fx->hBWE_TD->old_bwe_exc_fx, old_bwe_exc, PIT16k_MAX * 2 ); bwe_exc = old_bwe_exc + PIT16k_MAX * 2; } else @@ -679,39 +678,39 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( move16(); /* SC-VBR */ - if( EQ_16(st_fx->last_nelp_mode_dec, 1)) + if ( EQ_16( st_fx->last_nelp_mode_dec, 1 ) ) { st_fx->nelp_mode_dec = 1; move16(); } - Copy(st_fx->mem_AR_fx,tmp_float,M); - Copy(st_fx->mem_MA_fx,tmp_float2,M); + Copy( st_fx->mem_AR_fx, tmp_float, M ); + Copy( st_fx->mem_MA_fx, tmp_float2, M ); /* LSF estimation and A(z) calculation */ - lsf_dec_bfi(MODE1, lsf_new, st_fx->lsf_old_fx, st_fx->lsf_adaptive_mean_fx, NULL, st_fx->mem_MA_fx, st_fx->mem_AR_fx, - st_fx->stab_fac_fx, st_fx->last_coder_type, st_fx->L_frame, st_fx->last_good, - st_fx->nbLostCmpt, 0, NULL, NULL, NULL, st_fx->hGSCDec->Last_GSC_pit_band_idx, st_fx->Opt_AMR_WB, 0, st_fx->bwidth); + lsf_dec_bfi( MODE1, lsf_new, st_fx->lsf_old_fx, st_fx->lsf_adaptive_mean_fx, NULL, st_fx->mem_MA_fx, st_fx->mem_AR_fx, + st_fx->stab_fac_fx, st_fx->last_coder_type, st_fx->L_frame, st_fx->last_good, + st_fx->nbLostCmpt, 0, NULL, NULL, NULL, st_fx->hGSCDec->Last_GSC_pit_band_idx, st_fx->Opt_AMR_WB, 0, st_fx->bwidth ); - FEC_lsf2lsp_interp( st_fx, st_fx->L_frame, Aq, lsf_new, lsp_new); + FEC_lsf2lsp_interp( st_fx, st_fx->L_frame, Aq, lsf_new, lsp_new ); Copy( tmp_float, st_fx->mem_AR_fx, M ); Copy( tmp_float2, st_fx->mem_MA_fx, M ); /*----------------------------------------------------------------* - * Excitation decoding - *----------------------------------------------------------------*/ + * Excitation decoding + *----------------------------------------------------------------*/ - IF( EQ_16(st_fx->nelp_mode_dec, 1)) + IF( EQ_16( st_fx->nelp_mode_dec, 1 ) ) { Word16 gain_buf[NB_SUBFR16k]; - Scale_sig(exc-L_EXC_MEM, L_EXC_MEM, -st_fx->Q_exc); + Scale_sig( exc - L_EXC_MEM, L_EXC_MEM, -st_fx->Q_exc ); st_fx->Q_exc = 0; /* SC-VBR */ decod_nelp_fx( st_fx, &tmp_noise, pitch_buf, exc, exc2, voice_factors, bwe_exc, &Q_exc, st_fx->bfi, gain_buf ); FEC_pitch = pitch_buf[3]; move16(); - Rescale_exc(hMusicPF->dct_post_old_exc_fx, exc, NULL, st_fx->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32)0, &Q_exc, st_fx->Q_subfr, exc2, L_FRAME, coder_type); + Rescale_exc( hMusicPF->dct_post_old_exc_fx, exc, NULL, st_fx->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32) 0, &Q_exc, st_fx->Q_subfr, exc2, L_FRAME, coder_type ); st_fx->Q_exc = Q_exc; } ELSE @@ -731,8 +730,8 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( /* calculation of excitation signal */ FEC_exc_estim_fx( st_fx, st_fx->L_frame, exc, exc2, syn /* dummy buffer */, pitch_buf, voice_factors, &FEC_pitch, bwe_exc, lsf_new, &Q_exc, &tmp_noise ); - Rescale_exc( NULL, exc, bwe_exc, st_fx->hGSCDec->last_exc_dct_in_fx, st_fx->L_frame, L_FRAME32k, (Word32)0, - &Q_exc, st_fx->Q_subfr, exc2, st_fx->L_frame, st_fx->last_coder_type); + Rescale_exc( NULL, exc, bwe_exc, st_fx->hGSCDec->last_exc_dct_in_fx, st_fx->L_frame, L_FRAME32k, (Word32) 0, + &Q_exc, st_fx->Q_subfr, exc2, st_fx->L_frame, st_fx->last_coder_type ); st_fx->seed = tmp_float[5]; move16(); @@ -749,25 +748,25 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( } /*------------------------------------------------------------------* - * Synthesis - *-----------------------------------------------------------------*/ + * Synthesis + *-----------------------------------------------------------------*/ Rescale_mem( Q_exc, &st_fx->prev_Q_syn, &st_fx->Q_syn, st_fx->mem_syn2_fx, st_fx->mem_syn_clas_estim_fx, 4, &st_fx->mem_deemph_fx, hBPF->pst_old_syn_fx, &hBPF->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], st_fx->hPFstat, 1, 0, NULL ); - Copy( st_fx->mem_syn2_fx,tmp_float,M); + Copy( st_fx->mem_syn2_fx, tmp_float, M ); syn_12k8_fx( st_fx->L_frame, Aq, exc2, syn, tmp_float, 1, Q_exc, st_fx->Q_syn ); tmp_float32 = st_fx->enr_old_fx; - frame_ener_fx( st_fx->L_frame, st_fx->last_good, syn, shr(add(FEC_pitch,32),6), &tmp_float32, st_fx->L_frame, st_fx->Q_syn, 3, 0 ); + frame_ener_fx( st_fx->L_frame, st_fx->last_good, syn, shr( add( FEC_pitch, 32 ), 6 ), &tmp_float32, st_fx->L_frame, st_fx->Q_syn, 3, 0 ); /*------------------------------------------------------------------* - * Perform fixed deemphasis through 1/(1 - g*z^-1) - *-----------------------------------------------------------------*/ + * Perform fixed deemphasis through 1/(1 - g*z^-1) + *-----------------------------------------------------------------*/ tmp_float[0] = st_fx->mem_deemph_fx; move16(); /*if in acelp_core_dec_fx deemph_fx is used*/ /*tmp_float = shr(st_fx->mem_deemph_fx, sub(st_fx->Q_syn,1)); if in acelp_core_dec_fx Deemph2 is used*/ - IF(EQ_16(st_fx->L_frame,L_FRAME )) + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { deemph_fx( syn, PREEMPH_FAC, L_FRAME, &tmp_float[0] ); /*Q0*/ } @@ -777,66 +776,66 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( } /*----------------------------------------------------------------* - * Bass post-filter - *----------------------------------------------------------------*/ + * Bass post-filter + *----------------------------------------------------------------*/ - st_fx->bpf_off=1; + st_fx->bpf_off = 1; move16(); - Copy(hBPF->pst_old_syn_fx,tmp_float,NBPSF_PIT_MAX); + Copy( hBPF->pst_old_syn_fx, tmp_float, NBPSF_PIT_MAX ); tmp_float3 = st_fx->stab_fac_smooth_fx; move16(); - Copy(hBPF->mem_mean_pit_fx,tmp_float4, L_TRACK_HIST); - Copy(hBPF->Track_on_hist,tmp_float5, L_TRACK_HIST); - Copy(hBPF->vibrato_hist,tmp_float6, L_TRACK_HIST); + Copy( hBPF->mem_mean_pit_fx, tmp_float4, L_TRACK_HIST ); + Copy( hBPF->Track_on_hist, tmp_float5, L_TRACK_HIST ); + Copy( hBPF->vibrato_hist, tmp_float6, L_TRACK_HIST ); tmp_float7 = hBPF->psf_att_fx; move16(); - bass_psfilter_fx(st_fx->hBPF, st_fx->Opt_AMR_WB, syn, st_fx->L_frame, pitch_buf, - st_fx->bpf_off, st_fx->stab_fac_fx, &tmp_float3, coder_type, st_fx->Q_syn, old_exc /* tmp buffer*/); + bass_psfilter_fx( st_fx->hBPF, st_fx->Opt_AMR_WB, syn, st_fx->L_frame, pitch_buf, + st_fx->bpf_off, st_fx->stab_fac_fx, &tmp_float3, coder_type, st_fx->Q_syn, old_exc /* tmp buffer*/ ); - Copy(tmp_float, hBPF->pst_old_syn_fx, NBPSF_PIT_MAX); - Copy(tmp_float4, hBPF->mem_mean_pit_fx, L_TRACK_HIST); - Copy(tmp_float5, hBPF->Track_on_hist, L_TRACK_HIST); - Copy(tmp_float6, hBPF->vibrato_hist, L_TRACK_HIST); - hBPF->psf_att_fx = tmp_float7 ; + Copy( tmp_float, hBPF->pst_old_syn_fx, NBPSF_PIT_MAX ); + Copy( tmp_float4, hBPF->mem_mean_pit_fx, L_TRACK_HIST ); + Copy( tmp_float5, hBPF->Track_on_hist, L_TRACK_HIST ); + Copy( tmp_float6, hBPF->vibrato_hist, L_TRACK_HIST ); + hBPF->psf_att_fx = tmp_float7; /*----------------------------------------------------------------* - * Resamping to the output sampling frequency - *----------------------------------------------------------------*/ + * Resamping to the output sampling frequency + *----------------------------------------------------------------*/ /* CLDFB analysis of the synthesis at internal sampling rate */ - Qtmp = 11 - st_fx->Q_syn; - Copy_Scale_sig_16_32(syn, syn32,L_FRAME16k,Qtmp); - if ((error = cldfb_save_memory_ivas_fx( st_fx->cldfbAna )) != IVAS_ERR_OK) + Qtmp = 11 - st_fx->Q_syn; + Copy_Scale_sig_16_32( syn, syn32, L_FRAME16k, Qtmp ); + if ( ( error = cldfb_save_memory_ivas_fx( st_fx->cldfbAna ) ) != IVAS_ERR_OK ) { return error; } /*cldfbAnalysisFiltering( st_fx->cldfbAna, realBuffer, imagBuffer, &scaleFactor, syn, negate(st_fx->Q_syn), CLDFB_NO_COL_MAX_SWITCH_BFI, workBuffer);*/ - cldfbAnalysis_ivas_fx(syn32, realBuffer, imagBuffer, st_fx->L_frame / 2, st_fx->cldfbAna); + cldfbAnalysis_ivas_fx( syn32, realBuffer, imagBuffer, st_fx->L_frame / 2, st_fx->cldfbAna ); cldfb_restore_memory_ivas_fx( st_fx->cldfbAna ); - //scaleFactor.hb_scale = scaleFactor.lb_scale; + // scaleFactor.hb_scale = scaleFactor.lb_scale; /* CLDFB synthesis of the combined signal */ - if ((error = cldfb_save_memory_ivas_fx( st_fx->cldfbSyn )) != IVAS_ERR_OK) + if ( ( error = cldfb_save_memory_ivas_fx( st_fx->cldfbSyn ) ) != IVAS_ERR_OK ) { return error; } /*cldfbSynthesisFiltering( st_fx->cldfbSyn, realBuffer, imagBuffer, &scaleFactor, synth_out, negate(st_fx->Q_syn), CLDFB_NO_COL_MAX_SWITCH_BFI, workBuffer );*/ - Scale_sig32(st_fx->cldfbSyn->cldfb_state_fx,st_fx->cldfbSyn->cldfb_state_length,1); - st_fx->cldfbSyn->Q_cldfb_state = add(st_fx->cldfbSyn->Q_cldfb_state, 1); - Copy_Scale_sig_16_32(synth_out, synth32, L_FRAME48k, 11 - 5 - 1); + Scale_sig32( st_fx->cldfbSyn->cldfb_state_fx, st_fx->cldfbSyn->cldfb_state_length, 1 ); + st_fx->cldfbSyn->Q_cldfb_state = add( st_fx->cldfbSyn->Q_cldfb_state, 1 ); + Copy_Scale_sig_16_32( synth_out, synth32, L_FRAME48k, 11 - 5 - 1 ); - //cldfbSynthesis_ivas_fx(realBuffer, imagBuffer, synth_out, (int16_t)(st_fx->output_Fs * 0.01f), st_fx->cldfbSyn); - cldfbSynthesis_ivas_fx( realBuffer, imagBuffer, synth32, extract_l( Mpy_32_16_1( st_fx->output_Fs, 328 ) ), st_fx->cldfbSyn ); - Scale_sig32(st_fx->cldfbSyn->cldfb_state_fx, st_fx->cldfbSyn->cldfb_state_length, -1); - st_fx->cldfbSyn->Q_cldfb_state = sub(st_fx->cldfbSyn->Q_cldfb_state, 1); - Copy_Scale_sig_32_16(synth32, synth_out, L_FRAME48k, -5); + // cldfbSynthesis_ivas_fx(realBuffer, imagBuffer, synth_out, (int16_t)(st_fx->output_Fs * 0.01f), st_fx->cldfbSyn); + cldfbSynthesis_ivas_fx( realBuffer, imagBuffer, synth32, extract_l( Mpy_32_16_1( st_fx->output_Fs, 328 ) ), st_fx->cldfbSyn ); + Scale_sig32( st_fx->cldfbSyn->cldfb_state_fx, st_fx->cldfbSyn->cldfb_state_length, -1 ); + st_fx->cldfbSyn->Q_cldfb_state = sub( st_fx->cldfbSyn->Q_cldfb_state, 1 ); + Copy_Scale_sig_32_16( synth32, synth_out, L_FRAME48k, -5 ); /* output to Q0 */ - Copy_Scale_sig32_16(syn32, synth_out, L_FRAME16k, -5); - //Scale_sig(synth_out,L_FRAME48k, negate(st_fx->Q_syn)); + Copy_Scale_sig32_16( syn32, synth_out, L_FRAME16k, -5 ); + // Scale_sig(synth_out,L_FRAME48k, negate(st_fx->Q_syn)); cldfb_restore_memory_ivas_fx( st_fx->cldfbSyn ); @@ -845,30 +844,29 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( #endif /*-------------------------------------------------------------------* -* decod_gen_voic_core_switch() -* -* Decode excitation signal in the first ACELP->HQ switching frame -*-------------------------------------------------------------------*/ + * decod_gen_voic_core_switch() + * + * Decode excitation signal in the first ACELP->HQ switching frame + *-------------------------------------------------------------------*/ static void decod_gen_voic_core_switch_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 sharpFlag, /* i : flag for formant sharpening */ - const Word16 *Aq, /* i : LP filter coefficient */ + Decoder_State *st_fx, /* i/o: decoder static memory */ + const Word16 L_frame, /* i : length of the frame */ + const Word16 sharpFlag, /* i : flag for formant sharpening */ + const Word16 *Aq, /* i : LP filter coefficient */ Word16 *exc, /* i/o: adapt. excitation exc */ - const Word32 core_brate, /* i : switching frame bit-rate */ - Word16 *Q_exc -) + const Word32 core_brate, /* i : switching frame bit-rate */ + Word16 *Q_exc ) { - Word16 T0, T0_frac, T0_min, T0_max;/* integer pitch variables */ - Word16 gain_pit,gain_code16; /* pitch gain */ - Word32 gain_code,L_tmp; /* gain/normalized gain of the algebraic excitation */ - Word32 norm_gain_code; /* normalized gain of the algebraic excitation */ - Word16 gain_inov; /* Innovation gain */ - Word16 voice_fac; /* voicing factor */ - Word16 code[L_SUBFR]; /* algebraic codevector */ - Word16 pitch; /* pointer to floating pitch */ - Word16 i; /* tmp variables */ + Word16 T0, T0_frac, T0_min, T0_max; /* integer pitch variables */ + Word16 gain_pit, gain_code16; /* pitch gain */ + Word32 gain_code, L_tmp; /* gain/normalized gain of the algebraic excitation */ + Word32 norm_gain_code; /* normalized gain of the algebraic excitation */ + Word16 gain_inov; /* Innovation gain */ + Word16 voice_fac; /* voicing factor */ + Word16 code[L_SUBFR]; /* algebraic codevector */ + Word16 pitch; /* pointer to floating pitch */ + Word16 i; /* tmp variables */ Word16 pitch_limit_flag; Word16 *pt1; GSC_DEC_HANDLE hGSCDec; @@ -878,12 +876,11 @@ static void decod_gen_voic_core_switch_fx( #endif - /*----------------------------------------------------------------------* - * initializations - *----------------------------------------------------------------------*/ + * initializations + *----------------------------------------------------------------------*/ - IF( EQ_16(L_frame, L_FRAME)) + IF( EQ_16( L_frame, L_FRAME ) ) { T0_max = PIT_MAX; move16(); @@ -899,35 +896,35 @@ static void decod_gen_voic_core_switch_fx( } /*----------------------------------------------------------------------* - * Decode pitch lag - *----------------------------------------------------------------------*/ + * Decode pitch lag + *----------------------------------------------------------------------*/ pitch = pit_decode_fx( st_fx, core_brate, 0, L_frame, 0, GENERIC, &pitch_limit_flag, &T0, &T0_frac, &T0_min, &T0_max, L_SUBFR ); /*Q6*/ /*--------------------------------------------------------------* - * Find the adaptive codebook vector. - *--------------------------------------------------------------*/ + * Find the adaptive codebook vector. + *--------------------------------------------------------------*/ - pred_lt4( &exc[0], &exc[0], T0, T0_frac, L_SUBFR+1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + pred_lt4( &exc[0], &exc[0], T0, T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); /*--------------------------------------------------------------* - * LP filtering of the adaptive excitation - *--------------------------------------------------------------*/ + * LP filtering of the adaptive excitation + *--------------------------------------------------------------*/ - lp_filt_exc_dec_fx(st_fx, MODE1, 0, L_SUBFR, L_frame, st_fx->acelp_cfg.ltf_mode, exc); /*Scaling of exc doesn't change*/ + lp_filt_exc_dec_fx( st_fx, MODE1, 0, L_SUBFR, L_frame, st_fx->acelp_cfg.ltf_mode, exc ); /*Scaling of exc doesn't change*/ - /*--------------------------------------------------------------* - * Innovation decoding - *--------------------------------------------------------------*/ + /*--------------------------------------------------------------* + * Innovation decoding + *--------------------------------------------------------------*/ - inov_decode_fx( st_fx, core_brate, 0, L_frame, sharpFlag, 0, Aq, st_fx->tilt_code_fx, pitch, code, L_SUBFR); /*code in Q9*/ + inov_decode_fx( st_fx, core_brate, 0, L_frame, sharpFlag, 0, Aq, st_fx->tilt_code_fx, pitch, code, L_SUBFR ); /*code in Q9*/ /*--------------------------------------------------------------* - * Gain decoding - * Estimate spectrum tilt and voicing - *--------------------------------------------------------------*/ + * Gain decoding + * Estimate spectrum tilt and voicing + *--------------------------------------------------------------*/ - IF( EQ_16(L_frame, L_FRAME)) + IF( EQ_16( L_frame, L_FRAME ) ) { gain_dec_mless_fx( st_fx, L_frame, TRANSITION, 0, -1, code, st_fx->old_Es_pred_fx, &gain_pit, &gain_code, &gain_inov, &norm_gain_code ); } @@ -943,49 +940,49 @@ static void decod_gen_voic_core_switch_fx( st_fx->tilt_code_fx = est_tilt_fx( exc, gain_pit, code, gain_code, &voice_fac, *Q_exc ); /*Q15*/ /*----------------------------------------------------------------------* - * Find the total excitation - *----------------------------------------------------------------------*/ + * Find the total excitation + *----------------------------------------------------------------------*/ /* Rescaling for 12.8k core */ - IF ( EQ_16(L_frame,L_FRAME)) + IF( EQ_16( L_frame, L_FRAME ) ) { - Rescale_exc( NULL, &exc[0], NULL, hGSCDec->last_exc_dct_in_fx, L_SUBFR, L_SUBFR * HIBND_ACB_L_FAC, gain_code, &(st_fx->Q_exc), st_fx->Q_subfr, NULL, 0, GENERIC ); + Rescale_exc( NULL, &exc[0], NULL, hGSCDec->last_exc_dct_in_fx, L_SUBFR, L_SUBFR * HIBND_ACB_L_FAC, gain_code, &( st_fx->Q_exc ), st_fx->Q_subfr, NULL, 0, GENERIC ); } /* Rescaling for 16k core */ ELSE { - Rescale_exc(NULL, &exc[0], NULL, hGSCDec->last_exc_dct_in_fx, L_SUBFR, L_SUBFR * 2, gain_code, &(st_fx->Q_exc), st_fx->Q_subfr, NULL, 0, GENERIC); + Rescale_exc( NULL, &exc[0], NULL, hGSCDec->last_exc_dct_in_fx, L_SUBFR, L_SUBFR * 2, gain_code, &( st_fx->Q_exc ), st_fx->Q_subfr, NULL, 0, GENERIC ); } - gain_code16 = round_fx(L_shl(gain_code,st_fx->Q_exc)); /*Q_exc*/ + gain_code16 = round_fx( L_shl( gain_code, st_fx->Q_exc ) ); /*Q_exc*/ IF( st_fx->prev_bfi ) { /*gain_code = min(gain_code, 0.5f*gain_code+0.5f*st->lp_gainc);*/ #ifdef BASOP_NOGLOB - gain_code16 = s_min(gain_code16, mac_r(L_mult(16384, gain_code16), shl_o(16384 >> 3, st_fx->Q_exc, &Overflow), st_fx->lp_gainc_fx)); /* st_fx->lp_gainc_fx in Q3 >>3 to bring it to Q0 as gain_code16 */ + gain_code16 = s_min( gain_code16, mac_r( L_mult( 16384, gain_code16 ), shl_o( 16384 >> 3, st_fx->Q_exc, &Overflow ), st_fx->lp_gainc_fx ) ); /* st_fx->lp_gainc_fx in Q3 >>3 to bring it to Q0 as gain_code16 */ #else - gain_code16 = s_min(gain_code16, mac_r(L_mult(16384,gain_code16),shl(16384>>3, st_fx->Q_exc), st_fx->lp_gainc_fx)); /* st_fx->lp_gainc_fx in Q3 >>3 to bring it to Q0 as gain_code16 */ + gain_code16 = s_min( gain_code16, mac_r( L_mult( 16384, gain_code16 ), shl( 16384 >> 3, st_fx->Q_exc ), st_fx->lp_gainc_fx ) ); /* st_fx->lp_gainc_fx in Q3 >>3 to bring it to Q0 as gain_code16 */ #endif } - FOR (i = 0; i < L_SUBFR; i++) + FOR( i = 0; i < L_SUBFR; i++ ) { - L_tmp = L_shl(L_mult(gain_pit, exc[i]), 1); /*Q16+Q_exc*/ - /*exc2_fx[i+i_subfr] = round_fx(L_tmp);*/ /*Q_exc*/ - L_tmp = L_add(L_tmp, L_shl(L_mult(gain_code16, code[i]), 6)); /*Q16+Q_exc*/ - exc[i] = round_fx(L_tmp); /*Q_exc*/ + L_tmp = L_shl( L_mult( gain_pit, exc[i] ), 1 ); /*Q16+Q_exc*/ + /*exc2_fx[i+i_subfr] = round_fx(L_tmp);*/ /*Q_exc*/ + L_tmp = L_add( L_tmp, L_shl( L_mult( gain_code16, code[i] ), 6 ) ); /*Q16+Q_exc*/ + exc[i] = round_fx( L_tmp ); /*Q_exc*/ } /*-----------------------------------------------------------------* - * long term prediction on the 2nd sub frame - *-----------------------------------------------------------------*/ + * long term prediction on the 2nd sub frame + *-----------------------------------------------------------------*/ - pred_lt4(&exc[L_SUBFR], &exc[L_SUBFR], T0, T0_frac, L_SUBFR+1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP); - pt1 = exc+L_SUBFR; + pred_lt4( &exc[L_SUBFR], &exc[L_SUBFR], T0, T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + pt1 = exc + L_SUBFR; - FOR( i = 0; i < L_SUBFR; i++ ) + FOR( i = 0; i < L_SUBFR; i++ ) { - (*pt1) = round_fx(L_shl(L_mult(*pt1, gain_pit),1)); /*Q_exc + Q14 +1 +1 -16*/ + ( *pt1 ) = round_fx( L_shl( L_mult( *pt1, gain_pit ), 1 ) ); /*Q_exc + Q14 +1 +1 -16*/ pt1++; } diff --git a/lib_dec/amr_wb_dec.c b/lib_dec/amr_wb_dec.c index 81ec8ebed..895af0860 100644 --- a/lib_dec/amr_wb_dec.c +++ b/lib_dec/amr_wb_dec.c @@ -846,4 +846,4 @@ void amr_wb_dec_init( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/amr_wb_dec_fx.c b/lib_dec/amr_wb_dec_fx.c index 30159c660..ef751675e 100644 --- a/lib_dec/amr_wb_dec_fx.c +++ b/lib_dec/amr_wb_dec_fx.c @@ -8,7 +8,7 @@ #include "rom_com.h" #include "prot_fx1.h" #include "prot_fx2.h" -#include "basop_util.h" /* Function prototypes */ +#include "basop_util.h" /* Function prototypes */ #ifdef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * amr_wb_dec_fx() @@ -17,13 +17,13 @@ *-------------------------------------------------------------------*/ ivas_error amr_wb_dec_fx( - Word16 output_sp[], /* o : synthesis output */ - Decoder_State *st_fx /* o : Decoder static variables structure */ + Word16 output_sp[], /* o : synthesis output */ + Decoder_State *st_fx /* o : Decoder static variables structure */ ) { Word16 i; Word16 vad_flag; - Word16 output_frame; /* frame length at output sampling freq. */ + Word16 output_frame; /* frame length at output sampling freq. */ Word16 allow_cn_step; Word16 locattack, amr_io_class; Word16 tmps; @@ -36,20 +36,20 @@ ivas_error amr_wb_dec_fx( Word16 dct_buffer_fx[DCT_L_POST]; Word16 frame_e_fx; Word16 exc_buffer_fx[DCT_L_POST]; - Word16 lsp_new_fx[M]; /* LSPs at the end of the frame */ - Word16 lsf_new_fx[M]; /* LSFs at the end of the frame */ + Word16 lsp_new_fx[M]; /* LSPs at the end of the frame */ + Word16 lsf_new_fx[M]; /* LSFs at the end of the frame */ Word16 xsp_tmp[M]; - Word16 Aq_fx[NB_SUBFR*(M+1)]; /* A(q) quantized for the 4 subframes */ - Word16 exc2_fx[L_FRAME]; /* total excitation buffer */ - Word16 mem_tmp_fx[M]; /* temporary synthesis filter memory */ - Word32 L_enr_q_fx; /* E information for FER protection */ - Word16 tmp_noise_fx; /* Long term temporary noise energy */ - Word16 FEC_pitch_fx; /* FEC pitch */ - Word16 dummy_buf_fx[L_FRAME32k]; /* dummy buffer - no usage */ - Word16 old_exc_fx[L_EXC_DEC], *exc_fx; /* excitation signal buffer */ - Word16 syn_tmp_fx[L_FRAME+2], *syn_fx; /* synthesis signal buffer */ + Word16 Aq_fx[NB_SUBFR * ( M + 1 )]; /* A(q) quantized for the 4 subframes */ + Word16 exc2_fx[L_FRAME]; /* total excitation buffer */ + Word16 mem_tmp_fx[M]; /* temporary synthesis filter memory */ + Word32 L_enr_q_fx; /* E information for FER protection */ + Word16 tmp_noise_fx; /* Long term temporary noise energy */ + Word16 FEC_pitch_fx; /* FEC pitch */ + Word16 dummy_buf_fx[L_FRAME32k]; /* dummy buffer - no usage */ + Word16 old_exc_fx[L_EXC_DEC], *exc_fx; /* excitation signal buffer */ + Word16 syn_tmp_fx[L_FRAME + 2], *syn_fx; /* synthesis signal buffer */ Word32 L_tmp, L_tmp1; - Word16 pitch_buf_fx[NB_SUBFR], Qdct, tmp_coder_type; /* floating pitch for each subframe (Q6) */ + Word16 pitch_buf_fx[NB_SUBFR], Qdct, tmp_coder_type; /* floating pitch for each subframe (Q6) */ Word16 tmp16; Word16 sid_bw = 0; Word32 L_Ng_ener; @@ -57,7 +57,7 @@ ivas_error amr_wb_dec_fx( Word16 bpf_error_signal[L_FRAME]; CLDFB_SCALE_FACTOR scaleFactor; - Word32 workBuffer[128*3]; + Word32 workBuffer[128 * 3]; Word32 q_env[20]; Word16 exc3[L_FRAME]; Word16 gain_buf[NB_SUBFR16k]; @@ -99,12 +99,12 @@ ivas_error amr_wb_dec_fx( move16(); syn_tmp_fx[1] = 0; move16(); - syn_fx = syn_tmp_fx+2; + syn_fx = syn_tmp_fx + 2; - FOR( i=0; icoder_type = GENERIC; move16(); output_frame = st_fx->output_frame_fx; - move16(); /* frame length of the input signal */ + move16(); /* frame length of the input signal */ st_fx->bpf_off = 0; move16(); - if( EQ_16(st_fx->last_core,HQ_CORE)) + if ( EQ_16( st_fx->last_core, HQ_CORE ) ) { st_fx->bpf_off = 1; move16(); @@ -148,9 +148,9 @@ ivas_error amr_wb_dec_fx( st_fx->igf = 0; move16(); - st_fx->sr_core = i_mult(st_fx->L_frame,50); - st_fx->fscale_old = st_fx->fscale; - st_fx->fscale = sr2fscale_fx(st_fx->sr_core); + st_fx->sr_core = i_mult( st_fx->L_frame, 50 ); + st_fx->fscale_old = st_fx->fscale; + st_fx->fscale = sr2fscale_fx( st_fx->sr_core ); /* Initialization in case that the first frame is the good received AMR-WB (IO) frame */ IF( st_fx->ini_frame == 0 ) @@ -162,38 +162,38 @@ ivas_error amr_wb_dec_fx( } /* Updates in case of EVS primary mode -> AMR-WB IO mode switching */ - IF( NE_16(st_fx->last_core,AMR_WB_CORE)) + IF( NE_16( st_fx->last_core, AMR_WB_CORE ) ) { updt_IO_switch_dec_fx( output_frame, st_fx ); } /* Updates in case of EVS -> AMR-WB IO switching */ - if ((error = core_switching_pre_dec_fx( st_fx, output_frame )) != IVAS_ERR_OK) + if ( ( error = core_switching_pre_dec_fx( st_fx, output_frame ) ) != IVAS_ERR_OK ) { return error; } last_core_ori = st_fx->last_core; move16(); - set16_fx( hf_gain_fx, 0, NB_SUBFR); + set16_fx( hf_gain_fx, 0, NB_SUBFR ); amr_io_class = UNVOICED_CLAS; move16(); - L_enr_q_fx = L_deposit_l(0); + L_enr_q_fx = L_deposit_l( 0 ); tmp_noise_fx = 0; move16(); Copy( st_fx->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); exc_fx = old_exc_fx + L_EXC_MEM_DEC; /* reset post-filter in case of switching */ - if( st_fx->hPFstat->on == 0 ) + if ( st_fx->hPFstat->on == 0 ) { st_fx->hPFstat->reset = 1; move16(); } IF( st_fx->bfi > 0 ) { - st_fx->nbLostCmpt = add(st_fx->nbLostCmpt,1); + st_fx->nbLostCmpt = add( st_fx->nbLostCmpt, 1 ); } ELSE { @@ -202,18 +202,18 @@ ivas_error amr_wb_dec_fx( } /* PLC: [TCX: Fade-out-recovery] - * PLC: overlapping part needs to be attenuated for first good frame */ test(); + * PLC: overlapping part needs to be attenuated for first good frame */ test(); test(); test(); - IF (!st_fx->bfi && st_fx->prev_bfi && (EQ_16(st_fx->last_codec_mode, MODE2) ) - && (EQ_16(st_fx->last_core_bfi, TCX_20_CORE) || EQ_16(st_fx->last_core_bfi, TCX_10_CORE) )) + test(); + IF( !st_fx->bfi && st_fx->prev_bfi && ( EQ_16( st_fx->last_codec_mode, MODE2 ) ) && ( EQ_16( st_fx->last_core_bfi, TCX_20_CORE ) || EQ_16( st_fx->last_core_bfi, TCX_10_CORE ) ) ) { /* v_multc(st_fx->old_out_fx, st_fx->plcInfo.recovery_gain, */ /* st_fx->old_out_fx, st_fx->L_frameTCX); */ FOR( i = 0; i < hTcxDec->L_frameTCX; i++ ) { - hHQ_core->old_out_fx[i] = shl(mult_r(hHQ_core->old_out_fx[i], st_fx->plcInfo.recovery_gain), 1); + hHQ_core->old_out_fx[i] = shl( mult_r( hHQ_core->old_out_fx[i], st_fx->plcInfo.recovery_gain ), 1 ); } } @@ -221,7 +221,7 @@ ivas_error amr_wb_dec_fx( move16(); test(); test(); - if (st_fx->last_con_tcx && (NE_16(st_fx->L_frameTCX_past, st_fx->L_frame))&&(st_fx->last_core!=0)) + if ( st_fx->last_con_tcx && ( NE_16( st_fx->L_frameTCX_past, st_fx->L_frame ) ) && ( st_fx->last_core != 0 ) ) { avoid_lpc_burst_on_recovery = 1; move16(); @@ -230,26 +230,26 @@ ivas_error amr_wb_dec_fx( /*-----------------------------------------------------------------* * switching from ACELP@16k core to AMR-WB IO mode *-----------------------------------------------------------------*/ - st_fx->rate_switching_reset=0; + st_fx->rate_switching_reset = 0; move16(); test(); test(); - IF( NE_16(st_fx->last_core,AMR_WB_CORE)&&EQ_16(st_fx->last_L_frame,L_FRAME16k)&&NE_16(st_fx->last_core,HQ_CORE)) + IF( NE_16( st_fx->last_core, AMR_WB_CORE ) && EQ_16( st_fx->last_L_frame, L_FRAME16k ) && NE_16( st_fx->last_core, HQ_CORE ) ) { /* in case of switching, do not apply BPF */ st_fx->bpf_off = 1; move16(); - if(st_fx->hPFstat->on!=0) + if ( st_fx->hPFstat->on != 0 ) { Word16 mem_syn_r_size_old, mem_syn_r_size_new; - mem_syn_r_size_old = shr(st_fx->last_L_frame, 4); - mem_syn_r_size_new = shr(st_fx->L_frame, 4); - lerp( st_fx->hPFstat->mem_stp+L_SYN_MEM-mem_syn_r_size_old, st_fx->hPFstat->mem_stp+L_SYN_MEM-mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); - lerp( st_fx->hPFstat->mem_pf_in+L_SYN_MEM-mem_syn_r_size_old, st_fx->hPFstat->mem_pf_in+L_SYN_MEM-mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); + mem_syn_r_size_old = shr( st_fx->last_L_frame, 4 ); + mem_syn_r_size_new = shr( st_fx->L_frame, 4 ); + lerp( st_fx->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_old, st_fx->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); + lerp( st_fx->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_old, st_fx->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); } - st_fx->rate_switching_reset=lsp_convert_poly_fx( st_fx->lsp_old_fx, L_FRAME, 1 ); + st_fx->rate_switching_reset = lsp_convert_poly_fx( st_fx->lsp_old_fx, L_FRAME, 1 ); /* convert old quantized LSF vector */ lsp2lsf_fx( st_fx->lsp_old_fx, st_fx->lsf_old_fx, M, INT_FS_FX ); @@ -260,30 +260,29 @@ ivas_error amr_wb_dec_fx( /* Reset LPC mem */ Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M ); - set16_fx( st_fx->mem_MA_fx,0, M ); + set16_fx( st_fx->mem_MA_fx, 0, M ); /* update synthesis filter memories */ synth_mem_updt2( L_FRAME, st_fx->last_L_frame, st_fx->old_exc_fx, st_fx->mem_syn_r, st_fx->mem_syn2_fx, NULL, DEC ); Copy( st_fx->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); - Copy_Scale_sig(st_fx->mem_syn2_fx, st_fx->mem_syn1_fx, M, sub(-1,st_fx->Q_syn)); /*Q-1*/ + Copy_Scale_sig( st_fx->mem_syn2_fx, st_fx->mem_syn1_fx, M, sub( -1, st_fx->Q_syn ) ); /*Q-1*/ Copy( st_fx->mem_syn2_fx, st_fx->mem_syn3_fx, M ); /* LSP -> ISP */ Copy( stable_ISP_fx, xsp_tmp, M ); lsp2isp_fx( st_fx->lsp_old_fx, st_fx->lsp_old_fx, xsp_tmp, M ); - } /* update buffer of old subframe pitch values */ - IF( NE_16(st_fx->last_L_frame,L_FRAME)) + IF( NE_16( st_fx->last_L_frame, L_FRAME ) ) { move16(); - IF( EQ_16(st_fx->last_L_frame,L_FRAME32k)) + IF( EQ_16( st_fx->last_L_frame, L_FRAME32k ) ) { /* (float)12800/(float)32000; */ tmp16 = 13107; } - ELSE IF( EQ_16(st_fx->last_L_frame,512)) + ELSE IF( EQ_16( st_fx->last_L_frame, 512 ) ) { /* (float)12800/(float)25600; */ tmp16 = 16384; @@ -294,28 +293,28 @@ ivas_error amr_wb_dec_fx( tmp16 = 26214; } - FOR( i=NB_SUBFR16k-NB_SUBFR; iold_pitch_buf_fx[i-1] = Mpy_32_16_1(st_fx->old_pitch_buf_fx[i], tmp16); + st_fx->old_pitch_buf_fx[i - 1] = Mpy_32_16_1( st_fx->old_pitch_buf_fx[i], tmp16 ); move32(); } - FOR( i=2*NB_SUBFR16k-NB_SUBFR; i<2*NB_SUBFR16k; i++ ) + FOR( i = 2 * NB_SUBFR16k - NB_SUBFR; i < 2 * NB_SUBFR16k; i++ ) { - st_fx->old_pitch_buf_fx[i-2] = Mpy_32_16_1(st_fx->old_pitch_buf_fx[i], tmp16); + st_fx->old_pitch_buf_fx[i - 2] = Mpy_32_16_1( st_fx->old_pitch_buf_fx[i], tmp16 ); move32(); } } - IF( NE_16(st_fx->bfi_pitch_frame, L_FRAME)) + IF( NE_16( st_fx->bfi_pitch_frame, L_FRAME ) ) { move16(); - IF( EQ_16(st_fx->bfi_pitch_frame,L_FRAME32k)) + IF( EQ_16( st_fx->bfi_pitch_frame, L_FRAME32k ) ) { /* (float)12800/(float)32000; */ tmp16 = 13107; } - ELSE IF( EQ_16(st_fx->bfi_pitch_frame,512)) + ELSE IF( EQ_16( st_fx->bfi_pitch_frame, 512 ) ) { /* (float)12800/(float)25600; */ tmp16 = 16384; @@ -325,26 +324,26 @@ ivas_error amr_wb_dec_fx( /* (float)12800/(float)16000; */ tmp16 = 26214; } - st_fx->bfi_pitch_fx = mult_r(tmp16, st_fx->bfi_pitch_fx); + st_fx->bfi_pitch_fx = mult_r( tmp16, st_fx->bfi_pitch_fx ); st_fx->bfi_pitch_frame = L_FRAME; move16(); } #ifdef _DIFF_FLOAT_FIX_ - PMT("the code below has been removed in IVAS float (or moved somewhere else), is it ok?") + PMT( "the code below has been removed in IVAS float (or moved somewhere else), is it ok?" ) #endif - IF( NE_16(st_fx->last_core,AMR_WB_CORE)) + IF( NE_16( st_fx->last_core, AMR_WB_CORE ) ) { /* reset the unvoiced/audio signal improvement memories */ E_LPC_f_isp_a_conversion( st_fx->lsp_old_fx, st_fx->hAmrwb_IO->old_Aq_fx, M ); - Copy( st_fx->hAmrwb_IO->old_Aq_fx, st_fx->hAmrwb_IO->old_Aq_fx + (M+1), M+1 ); - Copy( st_fx->hAmrwb_IO->old_Aq_fx, st_fx->hAmrwb_IO->old_Aq_fx + 2*(M+1), M+1 ); - Copy( st_fx->hAmrwb_IO->old_Aq_fx, st_fx->hAmrwb_IO->old_Aq_fx + 3*(M+1), M+1 ); + Copy( st_fx->hAmrwb_IO->old_Aq_fx, st_fx->hAmrwb_IO->old_Aq_fx + ( M + 1 ), M + 1 ); + Copy( st_fx->hAmrwb_IO->old_Aq_fx, st_fx->hAmrwb_IO->old_Aq_fx + 2 * ( M + 1 ), M + 1 ); + Copy( st_fx->hAmrwb_IO->old_Aq_fx, st_fx->hAmrwb_IO->old_Aq_fx + 3 * ( M + 1 ), M + 1 ); } - /*End of _DIFF_FLOAT_FIX_*/ + /*End of _DIFF_FLOAT_FIX_*/ test(); - if( EQ_16(st_fx->last_bwidth,NB)&&st_fx->ini_frame!=0) + if ( EQ_16( st_fx->last_bwidth, NB ) && st_fx->ini_frame != 0 ) { - st_fx->rate_switching_reset=1; + st_fx->rate_switching_reset = 1; move16(); } @@ -360,66 +359,66 @@ ivas_error amr_wb_dec_fx( *----------------------------------------------------------------*/ test(); - IF ( EQ_32(st_fx->core_brate,FRAME_NO_DATA)||EQ_32(st_fx->core_brate,SID_1k75)) + IF( EQ_32( st_fx->core_brate, FRAME_NO_DATA ) || EQ_32( st_fx->core_brate, SID_1k75 ) ) { /* decode CNG parameters */ CNG_dec_fx( st_fx, EVS_MONO, Aq_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step, &sid_bw, q_env ); /* comfort noise generation */ CNG_exc_fx( st_fx->core_brate, L_FRAME, &st_fx->hTdCngDec->Enew_fx, &st_fx->hTdCngDec->cng_seed, exc_fx, exc2_fx, &st_fx->lp_ener_fx, st_fx->last_core_brate, - &st_fx->first_CNG, &st_fx->hTdCngDec->cng_ener_seed, dummy_buf_fx, allow_cn_step, &st_fx->hTdCngDec->last_allow_cn_step, st_fx->prev_Q_exc, st_fx->Q_exc , st_fx->hTdCngDec->num_ho, - q_env, st_fx->hTdCngDec->lp_env_fx, st_fx->hTdCngDec->old_env_fx, st_fx->hTdCngDec->exc_mem_fx, st_fx->hTdCngDec->exc_mem1_fx, &sid_bw, &st_fx->hTdCngDec->cng_ener_seed1, exc3, st_fx->Opt_AMR_WB, st_fx->element_mode); + &st_fx->first_CNG, &st_fx->hTdCngDec->cng_ener_seed, dummy_buf_fx, allow_cn_step, &st_fx->hTdCngDec->last_allow_cn_step, st_fx->prev_Q_exc, st_fx->Q_exc, st_fx->hTdCngDec->num_ho, + q_env, st_fx->hTdCngDec->lp_env_fx, st_fx->hTdCngDec->old_env_fx, st_fx->hTdCngDec->exc_mem_fx, st_fx->hTdCngDec->exc_mem1_fx, &sid_bw, &st_fx->hTdCngDec->cng_ener_seed1, exc3, st_fx->Opt_AMR_WB, st_fx->element_mode ); set16_fx( voice_factors_fx, 32767, NB_SUBFR ); class_para_fx = 0; move16(); // has been moved to updt_dec_common_fx() - //if( st_fx->first_CNG == 0 ) + // if( st_fx->first_CNG == 0 ) //{ // st_fx->first_CNG = 1; // move16(); //} - + delta_mem_scale = 3; move16(); test(); - if( LT_32(st_fx->lp_ener_fx,40)) /* very low energy frames, less than 0.3125 */ + if ( LT_32( st_fx->lp_ener_fx, 40 ) ) /* very low energy frames, less than 0.3125 */ { delta_mem_scale = 0; move16(); } i = st_fx->Q_exc; - Rescale_exc(hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st_fx->hGSCDec->last_exc_dct_in_fx, st_fx->L_frame, - st_fx->L_frame* HIBND_ACB_L_FAC, 0, &(st_fx->Q_exc), st_fx->Q_subfr, NULL, 0, INACTIVE); + Rescale_exc( hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st_fx->hGSCDec->last_exc_dct_in_fx, st_fx->L_frame, + st_fx->L_frame * HIBND_ACB_L_FAC, 0, &( st_fx->Q_exc ), st_fx->Q_subfr, NULL, 0, INACTIVE ); Rescale_mem( st_fx->Q_exc, &st_fx->prev_Q_syn, &st_fx->Q_syn, st_fx->mem_syn2_fx, st_fx->mem_syn_clas_estim_fx, delta_mem_scale, - &st_fx->mem_deemph_fx, hBPF->pst_old_syn_fx,&hBPF->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], st_fx->hPFstat, 0, 0, NULL ); - Copy_Scale_sig(exc2_fx, exc2_fx, st_fx->L_frame, sub(st_fx->Q_exc, i)); + &st_fx->mem_deemph_fx, hBPF->pst_old_syn_fx, &hBPF->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], st_fx->hPFstat, 0, 0, NULL ); + Copy_Scale_sig( exc2_fx, exc2_fx, st_fx->L_frame, sub( st_fx->Q_exc, i ) ); /* update past excitation signals for LD music post-filter */ - Copy(hMusicPF->dct_post_old_exc_fx + L_FRAME, hMusicPF->dct_post_old_exc_fx, DCT_L_POST-L_FRAME-OFFSET2 ); - Copy( exc2_fx, hMusicPF->dct_post_old_exc_fx + (DCT_L_POST-L_FRAME-OFFSET2), L_FRAME ); + Copy( hMusicPF->dct_post_old_exc_fx + L_FRAME, hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2 ); + Copy( exc2_fx, hMusicPF->dct_post_old_exc_fx + ( DCT_L_POST - L_FRAME - OFFSET2 ), L_FRAME ); /* synthesis at 12k8 Hz sampling rate */ syn_12k8_fx( L_FRAME, Aq_fx, exc2_fx, syn_fx, st_fx->mem_syn2_fx, 1, st_fx->Q_exc, st_fx->Q_syn ); syn_12k8_fx( L_FRAME, Aq_fx, exc2_fx, dummy_buf_fx, st_fx->mem_syn3_fx, 1, st_fx->Q_exc, st_fx->Q_syn ); /* reset the decoder */ - CNG_reset_dec_fx( st_fx, pitch_buf_fx, dummy_buf_fx+L_FRAME ); + CNG_reset_dec_fx( st_fx, pitch_buf_fx, dummy_buf_fx + L_FRAME ); /* update st_fx->mem_syn1 for ACELP core switching */ - Copy_Scale_sig( st_fx->mem_syn3_fx, st_fx->mem_syn1_fx, M, sub(-1,st_fx->Q_syn) ); /*Q-1*/ - IF( NE_16(output_frame,L_FRAME8k)) + Copy_Scale_sig( st_fx->mem_syn3_fx, st_fx->mem_syn1_fx, M, sub( -1, st_fx->Q_syn ) ); /*Q-1*/ + IF( NE_16( output_frame, L_FRAME8k ) ) { Word16 pitch_temp[4]; - pitch_temp[2] = shl(L_FRAME, 6); + pitch_temp[2] = shl( L_FRAME, 6 ); move16(); - pitch_temp[3] = shl(L_FRAME, 6); + pitch_temp[3] = shl( L_FRAME, 6 ); move16(); frame_energy_fx( L_FRAME, pitch_temp, syn_fx, 0, &frame_e_fx, st_fx->Q_syn ); /*st->psf_lp_noise = 0.99f * st->psf_lp_noise + 0.01f * frame_e; */ - st_fx->psf_lp_noise_fx = round_fx(L_mac(L_mult(32440, st_fx->psf_lp_noise_fx), 328, frame_e_fx)); /*Q8*/ + st_fx->psf_lp_noise_fx = round_fx( L_mac( L_mult( 32440, st_fx->psf_lp_noise_fx ), 328, frame_e_fx ) ); /*Q8*/ } /* update old synthesis for classification */ Copy( syn_fx + L_FRAME - L_SYN_MEM_CLAS_ESTIM, st_fx->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM ); @@ -429,7 +428,7 @@ ivas_error amr_wb_dec_fx( FOR( i = 0; i < DCT_L_POST; i++ ) { /*st->filt_lfE[i] = 0.3f + 0.7f * st->filt_lfE[i];*/ - hMusicPF->filt_lfE_fx[i] = round_fx(L_mac(L_deposit_h(1229), 22938, hMusicPF->filt_lfE_fx[i])); + hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( L_deposit_h( 1229 ), 22938, hMusicPF->filt_lfE_fx[i] ) ); } vad_flag = 0; @@ -447,7 +446,7 @@ ivas_error amr_wb_dec_fx( *-----------------------------------------------------------------*/ test(); - IF ( EQ_32(st_fx->last_core_brate,FRAME_NO_DATA)||EQ_32(st_fx->last_core_brate,SID_1k75)) + IF( EQ_32( st_fx->last_core_brate, FRAME_NO_DATA ) || EQ_32( st_fx->last_core_brate, SID_1k75 ) ) { Copy( st_fx->lspCNG_fx, st_fx->lsp_old_fx, M ); E_LPC_isp_isf_conversion( st_fx->lspCNG_fx, st_fx->lsf_old_fx, M ); @@ -458,7 +457,7 @@ ivas_error amr_wb_dec_fx( * Extracts VAD information from the bitstream in AMR-WB IO mode *------------------------------------------------------------*/ - vad_flag = (Word16)get_next_indice( st_fx, 1 ); + vad_flag = (Word16) get_next_indice( st_fx, 1 ); st_fx->coder_type = GENERIC; move16(); @@ -488,24 +487,24 @@ ivas_error amr_wb_dec_fx( * Update ISP vector for CNG *------------------------------------------------------------*/ - IF( EQ_16(st_fx->coder_type,INACTIVE)) + IF( EQ_16( st_fx->coder_type, INACTIVE ) ) { - IF( GT_16(st_fx->unv_cnt,20)) + IF( GT_16( st_fx->unv_cnt, 20 ) ) { /*ftmp = st->lp_gainc * st->lp_gainc;*/ - L_tmp1 = L_mult0(st_fx->lp_gainc_fx, st_fx->lp_gainc_fx); /* Q3*Q3 -> Q6*/ + L_tmp1 = L_mult0( st_fx->lp_gainc_fx, st_fx->lp_gainc_fx ); /* Q3*Q3 -> Q6*/ /*st->lp_ener = 0.7f * st->lp_ener + 0.3f * ftmp;*/ - L_tmp = Mult_32_16(st_fx->lp_ener_fx, 22938); - st_fx->lp_ener_fx = L_add(L_tmp, Mult_32_16(L_tmp1, 9830)); /*Q6 + Q6*/ - FOR( i=0; ilp_ener_fx, 22938 ); + st_fx->lp_ener_fx = L_add( L_tmp, Mult_32_16( L_tmp1, 9830 ) ); /*Q6 + Q6*/ + FOR( i = 0; i < M; i++ ) { - L_tmp = L_mult(3277, lsp_new_fx[i]); - st_fx->lspCNG_fx[i] = round_fx(L_mac(L_tmp, 29491, st_fx->lspCNG_fx[i])); + L_tmp = L_mult( 3277, lsp_new_fx[i] ); + st_fx->lspCNG_fx[i] = round_fx( L_mac( L_tmp, 29491, st_fx->lspCNG_fx[i] ) ); } } ELSE { - st_fx->unv_cnt = add(st_fx->unv_cnt,1); + st_fx->unv_cnt = add( st_fx->unv_cnt, 1 ); } } ELSE @@ -524,13 +523,13 @@ ivas_error amr_wb_dec_fx( move16(); test(); test(); - if(EQ_16(st_fx->coder_type,INACTIVE)&&st_fx->flag_cna&&GE_16(st_fx->psf_lp_noise_fx,15<<7)) + if ( EQ_16( st_fx->coder_type, INACTIVE ) && st_fx->flag_cna && GE_16( st_fx->psf_lp_noise_fx, 15 << 7 ) ) { tmp16 = 1; move16(); } Rescale_mem( st_fx->Q_exc, &st_fx->prev_Q_syn, &st_fx->Q_syn, st_fx->mem_syn2_fx, st_fx->mem_syn_clas_estim_fx, 5, &st_fx->mem_deemph_fx, - hBPF->pst_old_syn_fx, &hBPF->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], st_fx->hPFstat, vad_flag, tmp16, tmp_buffer_fx ); + hBPF->pst_old_syn_fx, &hBPF->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], st_fx->hPFstat, vad_flag, tmp16, tmp_buffer_fx ); Copy( st_fx->mem_syn2_fx, mem_tmp_fx, M ); syn_12k8_fx( L_FRAME, Aq_fx, exc2_fx, syn_fx, st_fx->mem_syn2_fx, 1, st_fx->Q_exc, st_fx->Q_syn ); @@ -539,34 +538,34 @@ ivas_error amr_wb_dec_fx( *------------------------------------------------------------*/ FEC_clas_estim_fx( st_fx, 1, L_FRAME, &st_fx->clas_dec, st_fx->coder_type, pitch_buf_fx, - syn_fx, &st_fx->lp_ener_FER_fx, - &st_fx->decision_hyst, &st_fx->hAmrwb_IO->UV_cnt_fx, &st_fx->hAmrwb_IO->LT_UV_cnt_fx, &st_fx->hAmrwb_IO->Last_ener_fx, &locattack, st_fx->hAmrwb_IO->lt_diff_etot_fx, - &amr_io_class, st_fx->core_brate, st_fx->Q_syn, &class_para_fx, st_fx->mem_syn_clas_estim_fx, &st_fx->classifier_Q_mem_syn, - 0, 0, 0, st_fx->last_core_brate, -1); + syn_fx, &st_fx->lp_ener_FER_fx, + &st_fx->decision_hyst, &st_fx->hAmrwb_IO->UV_cnt_fx, &st_fx->hAmrwb_IO->LT_UV_cnt_fx, &st_fx->hAmrwb_IO->Last_ener_fx, &locattack, st_fx->hAmrwb_IO->lt_diff_etot_fx, + &amr_io_class, st_fx->core_brate, st_fx->Q_syn, &class_para_fx, st_fx->mem_syn_clas_estim_fx, &st_fx->classifier_Q_mem_syn, + 0, 0, 0, st_fx->last_core_brate, -1 ); /* update past excitation signals for LD music post-filter */ - Copy(hMusicPF->dct_post_old_exc_fx + L_FRAME, hMusicPF->dct_post_old_exc_fx, DCT_L_POST-L_FRAME-OFFSET2 ); - Copy( exc2_fx, hMusicPF->dct_post_old_exc_fx + (DCT_L_POST-L_FRAME-OFFSET2), L_FRAME ); - Copy(hMusicPF->dct_post_old_exc_fx, exc_buffer_fx, DCT_L_POST-OFFSET2 ); + Copy( hMusicPF->dct_post_old_exc_fx + L_FRAME, hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2 ); + Copy( exc2_fx, hMusicPF->dct_post_old_exc_fx + ( DCT_L_POST - L_FRAME - OFFSET2 ), L_FRAME ); + Copy( hMusicPF->dct_post_old_exc_fx, exc_buffer_fx, DCT_L_POST - OFFSET2 ); - IF( NE_16(output_frame,L_FRAME8k)) + IF( NE_16( output_frame, L_FRAME8k ) ) { - IF ( EQ_16(st_fx->coder_type,INACTIVE)) + IF( EQ_16( st_fx->coder_type, INACTIVE ) ) { frame_energy_fx( L_FRAME, pitch_buf_fx, syn_fx, 0, &frame_e_fx, st_fx->Q_syn ); /*st->psf_lp_noise = 0.99f * st->psf_lp_noise + 0.01f * frame_e; */ - st_fx->psf_lp_noise_fx = round_fx(L_mac(L_mult(32440, st_fx->psf_lp_noise_fx), 328, frame_e_fx)); /*Q8*/ + st_fx->psf_lp_noise_fx = round_fx( L_mac( L_mult( 32440, st_fx->psf_lp_noise_fx ), 328, frame_e_fx ) ); /*Q8*/ } } test(); test(); - IF( NE_16(amr_io_class,UNVOICED_CLAS)&&NE_16(st_fx->coder_type,INACTIVE)&<_16(st_fx->psf_lp_noise_fx,15<<8)) + IF( NE_16( amr_io_class, UNVOICED_CLAS ) && NE_16( st_fx->coder_type, INACTIVE ) && LT_16( st_fx->psf_lp_noise_fx, 15 << 8 ) ) { tmp_coder_type = AUDIO; move16(); test(); - if (EQ_16(st_fx->last_coder_type,INACTIVE)||EQ_16(st_fx->last_coder_type,UNVOICED)) + if ( EQ_16( st_fx->last_coder_type, INACTIVE ) || EQ_16( st_fx->last_coder_type, UNVOICED ) ) { tmp_coder_type = INACTIVE; move16(); @@ -575,12 +574,12 @@ ivas_error amr_wb_dec_fx( Prep_music_postP_fx( exc_buffer_fx, dct_buffer_fx, hMusicPF->filt_lfE_fx, st_fx->last_core, st_fx->element_mode, pitch_buf_fx, hMusicPF->LDm_enh_lp_gbin_fx, st_fx->Q_exc, &Qdct ); /* LD music post-filter */ - LD_music_post_filter_fx( hMusicPF, dct_buffer_fx, dct_buffer_fx, st_fx->core_brate,&hMusicPF->Old_ener_Q, -1, tmp_coder_type, Qdct ); + LD_music_post_filter_fx( hMusicPF, dct_buffer_fx, dct_buffer_fx, st_fx->core_brate, &hMusicPF->Old_ener_Q, -1, tmp_coder_type, Qdct ); /* Inverse DCT transform, retrieval of the aligned excitation, re-synthesis */ Post_music_postP_fx( dct_buffer_fx, exc2_fx, mem_tmp_fx, st_fx->mem_syn2_fx, Aq_fx, syn_fx, &st_fx->Q_exc, &st_fx->prev_Q_syn, &st_fx->Q_syn, st_fx->mem_syn_clas_estim_fx, 1, &st_fx->mem_deemph_fx, hBPF->pst_old_syn_fx, - &hBPF->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], st_fx->hPFstat, NULL, NULL ); + &hBPF->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], st_fx->hPFstat, NULL, NULL ); } ELSE { @@ -588,13 +587,13 @@ ivas_error amr_wb_dec_fx( * Improvement for unvoiced and audio signals *------------------------------------------------------------*/ - improv_amr_wb_gs_fx(amr_io_class, st_fx->coder_type, st_fx->core_brate, &st_fx->hGSCDec->seed_tcx, st_fx->hAmrwb_IO->old_Aq_fx, st_fx->mem_syn2_fx, st_fx->hAmrwb_IO->lt_voice_fac_fx, - locattack, Aq_fx, exc2_fx, st_fx->Q_exc, mem_tmp_fx, syn_fx, st_fx->Q_syn, pitch_buf_fx, st_fx->hAmrwb_IO->Last_ener_fx, st_fx->rate_switching_reset, st_fx->last_coder_type); + improv_amr_wb_gs_fx( amr_io_class, st_fx->coder_type, st_fx->core_brate, &st_fx->hGSCDec->seed_tcx, st_fx->hAmrwb_IO->old_Aq_fx, st_fx->mem_syn2_fx, st_fx->hAmrwb_IO->lt_voice_fac_fx, + locattack, Aq_fx, exc2_fx, st_fx->Q_exc, mem_tmp_fx, syn_fx, st_fx->Q_syn, pitch_buf_fx, st_fx->hAmrwb_IO->Last_ener_fx, st_fx->rate_switching_reset, st_fx->last_coder_type ); FOR( i = 0; i < DCT_L_POST; i++ ) { /*st->filt_lfE[i] = 0.3f + 0.7f * st->filt_lfE[i] ;*/ - hMusicPF->filt_lfE_fx[i] = round_fx(L_mac(L_deposit_h(1229), 22938, hMusicPF->filt_lfE_fx[i])); + hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( L_deposit_h( 1229 ), 22938, hMusicPF->filt_lfE_fx[i] ) ); } } @@ -603,22 +602,22 @@ ivas_error amr_wb_dec_fx( *------------------------------------------------------------*/ FEC_pitch_estim_fx( 1, st_fx->last_core, L_FRAME, st_fx->clas_dec, st_fx->last_good, pitch_buf_fx, st_fx->old_pitch_buf_fx, &st_fx->bfi_pitch_fx, - &st_fx->bfi_pitch_frame, &st_fx->upd_cnt, GENERIC, st_fx->element_mode ); + &st_fx->bfi_pitch_frame, &st_fx->upd_cnt, GENERIC, st_fx->element_mode ); /*------------------------------------------------------------* * FEC - Smooth the speech energy evolution when recovering after a BAD frame * (smoothing is performed in the excitation domain and signal is resynthesized after) *------------------------------------------------------------*/ - FOR( i=0; iclas_dec, st_fx->last_good, syn_fx, pitch_buf_tmp, st_fx->enr_old_fx, L_enr_q_fx, -1, MOVING_AVERAGE, - &st_fx->scaling_flag, &st_fx->lp_ener_FEC_av, &st_fx->lp_ener_FEC_max, st_fx->bfi, st_fx->total_brate, st_fx->prev_bfi, st_fx->last_core_brate, - exc_fx, exc2_fx, Aq_fx, &st_fx->old_enr_LP, mem_tmp_fx, st_fx->mem_syn2_fx, st_fx->Q_exc, st_fx->Q_syn, avoid_lpc_burst_on_recovery, 0 ); + &st_fx->scaling_flag, &st_fx->lp_ener_FEC_av, &st_fx->lp_ener_FEC_max, st_fx->bfi, st_fx->total_brate, st_fx->prev_bfi, st_fx->last_core_brate, + exc_fx, exc2_fx, Aq_fx, &st_fx->old_enr_LP, mem_tmp_fx, st_fx->mem_syn2_fx, st_fx->Q_exc, st_fx->Q_syn, avoid_lpc_burst_on_recovery, 0 ); frame_ener_fx( L_FRAME, st_fx->clas_dec, syn_fx, pitch_buf_tmp[3], &st_fx->enr_old_fx, L_FRAME, st_fx->Q_syn, 3, 0 ); } @@ -632,7 +631,7 @@ ivas_error amr_wb_dec_fx( { /* long burst frame erasures */ test(); - if( GT_16(st_fx->nbLostCmpt,5)&&GE_16(st_fx->clas_dec,VOICED_CLAS)) + if ( GT_16( st_fx->nbLostCmpt, 5 ) && GE_16( st_fx->clas_dec, VOICED_CLAS ) ) { st_fx->last_good = VOICED_TRANSITION; move16(); @@ -646,48 +645,48 @@ ivas_error amr_wb_dec_fx( /* LSF estimation and A(z) calculation */ lsf_dec_bfi( MODE1, lsf_new_fx, st_fx->lsf_old_fx, st_fx->lsf_adaptive_mean_fx, NULL, st_fx->mem_MA_fx, st_fx->mem_AR_fx, - st_fx->stab_fac_fx, st_fx->last_coder_type, st_fx->L_frame, st_fx->last_good, - st_fx->nbLostCmpt, 0, NULL, NULL, NULL, st_fx->hGSCDec->Last_GSC_pit_band_idx, st_fx->Opt_AMR_WB, 0, st_fx->bwidth); + st_fx->stab_fac_fx, st_fx->last_coder_type, st_fx->L_frame, st_fx->last_good, + st_fx->nbLostCmpt, 0, NULL, NULL, NULL, st_fx->hGSCDec->Last_GSC_pit_band_idx, st_fx->Opt_AMR_WB, 0, st_fx->bwidth ); FEC_lsf2lsp_interp( st_fx, st_fx->L_frame, Aq_fx, lsf_new_fx, lsp_new_fx ); /* calculation of excitation signal */ FEC_exc_estim_fx( st_fx, L_FRAME, exc_fx, exc2_fx, tmp_buffer_fx, pitch_buf_fx, voice_factors_fx, - &FEC_pitch_fx, dummy_buf_fx, lsf_new_fx, &st_fx->Q_exc, &tmp_noise_fx); + &FEC_pitch_fx, dummy_buf_fx, lsf_new_fx, &st_fx->Q_exc, &tmp_noise_fx ); /* synthesis for ACELP core switching and SWB BWE */ syn_12k8_fx( L_FRAME, Aq_fx, exc_fx, tmp_buffer_fx, st_fx->mem_syn1_fx, 1, st_fx->Q_exc, -1 ); /* update past excitation signals */ - Copy(hMusicPF->dct_post_old_exc_fx + L_FRAME, hMusicPF->dct_post_old_exc_fx, DCT_L_POST-L_FRAME-OFFSET2 ); - Copy( exc2_fx, hMusicPF->dct_post_old_exc_fx + (DCT_L_POST-L_FRAME-OFFSET2), L_FRAME ); + Copy( hMusicPF->dct_post_old_exc_fx + L_FRAME, hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2 ); + Copy( exc2_fx, hMusicPF->dct_post_old_exc_fx + ( DCT_L_POST - L_FRAME - OFFSET2 ), L_FRAME ); /* Update music post processing values */ /* Update circular buffer, keep last energy difference unchanged */ - FOR( i = 1; iLDm_lt_diff_etot_fx[i-1] = hMusicPF->LDm_lt_diff_etot_fx[i]; + hMusicPF->LDm_lt_diff_etot_fx[i - 1] = hMusicPF->LDm_lt_diff_etot_fx[i]; move16(); } /* Filter energies update */ FOR( i = 0; i < DCT_L_POST; i++ ) { /*st->filt_lfE[i] = 0.3f + 0.7f * st->filt_lfE[i];*/ - hMusicPF->filt_lfE_fx[i] = round_fx(L_mac(L_deposit_h(1229), 22938, hMusicPF->filt_lfE_fx[i])); + hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( L_deposit_h( 1229 ), 22938, hMusicPF->filt_lfE_fx[i] ) ); } Rescale_mem( st_fx->Q_exc, &st_fx->prev_Q_syn, &st_fx->Q_syn, st_fx->mem_syn2_fx, st_fx->mem_syn_clas_estim_fx, 4, &st_fx->mem_deemph_fx, - hBPF->pst_old_syn_fx, &hBPF->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], st_fx->hPFstat, 1, 0, tmp_buffer_fx ); + hBPF->pst_old_syn_fx, &hBPF->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], st_fx->hPFstat, 1, 0, tmp_buffer_fx ); Copy( st_fx->mem_syn2_fx, mem_tmp_fx, M ); /* synthesis at 12k8 Hz sampling rate */ - syn_12k8_fx( L_FRAME, Aq_fx, exc2_fx, syn_fx, st_fx->mem_syn2_fx, 1 , st_fx->Q_exc, st_fx->Q_syn ); + syn_12k8_fx( L_FRAME, Aq_fx, exc2_fx, syn_fx, st_fx->mem_syn2_fx, 1, st_fx->Q_exc, st_fx->Q_syn ); /* update old synthesis for classification */ Copy( syn_fx + L_FRAME - L_SYN_MEM_CLAS_ESTIM, st_fx->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM ); - FOR( i=0; iclas_dec, st_fx->last_good, syn_fx, pitch_buf_tmp, st_fx->enr_old_fx, L_enr_q_fx, -1, - MOVING_AVERAGE, &st_fx->scaling_flag, &st_fx->lp_ener_FEC_av, &st_fx->lp_ener_FEC_max, st_fx->bfi, st_fx->total_brate, - st_fx->prev_bfi, st_fx->last_core_brate, exc_fx, exc2_fx, Aq_fx, &st_fx->old_enr_LP, mem_tmp_fx, st_fx->mem_syn2_fx, - st_fx->Q_exc, st_fx->Q_syn, 0, 0 ); + MOVING_AVERAGE, &st_fx->scaling_flag, &st_fx->lp_ener_FEC_av, &st_fx->lp_ener_FEC_max, st_fx->bfi, st_fx->total_brate, + st_fx->prev_bfi, st_fx->last_core_brate, exc_fx, exc2_fx, Aq_fx, &st_fx->old_enr_LP, mem_tmp_fx, st_fx->mem_syn2_fx, + st_fx->Q_exc, st_fx->Q_syn, 0, 0 ); /* estimate the pitch-synchronous speech energy per sample to be used when normal operation recovers */ - frame_ener_fx( L_FRAME, st_fx->last_good, syn_fx, shr(FEC_pitch_fx, 6), &st_fx->enr_old_fx, L_FRAME, st_fx->Q_syn, 3, 0 ); + frame_ener_fx( L_FRAME, st_fx->last_good, syn_fx, shr( FEC_pitch_fx, 6 ), &st_fx->enr_old_fx, L_FRAME, st_fx->Q_syn, 3, 0 ); } /*--------------------------------------------------------* * NB post-filter *--------------------------------------------------------*/ test(); - IF( EQ_16(output_frame,L_FRAME8k)||EQ_16(st_fx->last_bwidth,NB)) + IF( EQ_16( output_frame, L_FRAME8k ) || EQ_16( st_fx->last_bwidth, NB ) ) { - FOR( i=0; ihPFstat->on = 1; move16(); @@ -737,26 +736,26 @@ ivas_error amr_wb_dec_fx( /* update old synthesis buffer - needed for ACELP internal sampling rate switching */ Copy( syn_fx + L_FRAME - L_SYN_MEM, st_fx->mem_syn_r, L_SYN_MEM ); - deemph_fx( syn_fx, PREEMPH_FAC, L_FRAME, &(st_fx->mem_deemph_fx) ); + deemph_fx( syn_fx, PREEMPH_FAC, L_FRAME, &( st_fx->mem_deemph_fx ) ); unscale_AGC( syn_fx, st_fx->Q_syn, syn_fx_tmp2, st_fx->agc_mem_fx, L_FRAME ); Copy( syn_fx_tmp2, syn_fx, L_FRAME ); /* TCX=Q-1, ACELP2 Q0 */ - Copy_Scale_sig( syn_fx + L_FRAME/2, hTcxDec->old_syn_Overl, L_FRAME/2, sub(-1,st_fx->Q_syn)); /*Q_syn*/ - Copy_Scale_sig( syn_fx + L_FRAME-M-1, st_fx->syn, M+1, sub(0,st_fx->Q_syn)); /*Q0*/ + Copy_Scale_sig( syn_fx + L_FRAME / 2, hTcxDec->old_syn_Overl, L_FRAME / 2, sub( -1, st_fx->Q_syn ) ); /*Q_syn*/ + Copy_Scale_sig( syn_fx + L_FRAME - M - 1, st_fx->syn, M + 1, sub( 0, st_fx->Q_syn ) ); /*Q0*/ /*------------------------------------------------------------------* * Formant post-filter *-----------------------------------------------------------------*/ Copy( syn_fx, tmp_buffer_fx + L_SYN_MEM, L_FRAME ); - IF( NE_16(output_frame,L_FRAME8k)&&NE_16(st_fx->last_bwidth,NB)) + IF( NE_16( output_frame, L_FRAME8k ) && NE_16( st_fx->last_bwidth, NB ) ) { st_fx->hPFstat->on = 1; move16(); test(); - formant_post_filt_fx( st_fx->hPFstat, tmp_buffer_fx + L_SYN_MEM, Aq_fx, syn_fx, L_FRAME, L_shl(st_fx->psf_lp_noise_fx,15), st_fx->total_brate, sub(amr_io_class,AUDIO_CLAS) == 0); + formant_post_filt_fx( st_fx->hPFstat, tmp_buffer_fx + L_SYN_MEM, Aq_fx, syn_fx, L_FRAME, L_shl( st_fx->psf_lp_noise_fx, 15 ), st_fx->total_brate, sub( amr_io_class, AUDIO_CLAS ) == 0 ); } /*----------------------------------------------------------------* @@ -766,11 +765,11 @@ ivas_error amr_wb_dec_fx( flag_cna = 0; move16(); test(); - IF( (GE_16(st_fx->psf_lp_noise_fx,15<<8))||(st_fx->coder_type==INACTIVE)) + IF( ( GE_16( st_fx->psf_lp_noise_fx, 15 << 8 ) ) || ( st_fx->coder_type == INACTIVE ) ) { /*VAD only for non inactive frame*/ test(); - IF( EQ_16(st_fx->VAD, 1)&&NE_16(st_fx->coder_type,INACTIVE)) + IF( EQ_16( st_fx->VAD, 1 ) && NE_16( st_fx->coder_type, INACTIVE ) ) { st_fx->VAD = 1; move16(); @@ -781,40 +780,40 @@ ivas_error amr_wb_dec_fx( move16(); } #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - PMT("Fixed point not done here ") - ApplyFdCng_fx(syn, NULL, NULL, NULL, st, 0, 0); + PMT( "Fixed point not done here " ) + ApplyFdCng_fx( syn, NULL, NULL, NULL, st, 0, 0 ); #else ApplyFdCng_fx( syn_fx, st_fx->Q_syn, NULL, NULL, NULL, st_fx, 0, 0 ); #endif st_fx->hFdCngDec->hFdCngCom->frame_type_previous = st_fx->m_frame_type; /*Noisy speech detector*/ - noisy_speech_detection_fx(st_fx->hFdCngDec, st_fx->VAD, syn_fx, st_fx->Q_syn); + noisy_speech_detection_fx( st_fx->hFdCngDec, st_fx->VAD, syn_fx, st_fx->Q_syn ); - st_fx->hFdCngDec->hFdCngCom->likelihood_noisy_speech = mult_r(st_fx->hFdCngDec->hFdCngCom->likelihood_noisy_speech, 32440/*0.99 Q15*/); - IF ( st_fx->hFdCngDec->hFdCngCom->flag_noisy_speech != 0 ) + st_fx->hFdCngDec->hFdCngCom->likelihood_noisy_speech = mult_r( st_fx->hFdCngDec->hFdCngCom->likelihood_noisy_speech, 32440 /*0.99 Q15*/ ); + IF( st_fx->hFdCngDec->hFdCngCom->flag_noisy_speech != 0 ) { - st_fx->hFdCngDec->hFdCngCom->likelihood_noisy_speech = add(st_fx->hFdCngDec->hFdCngCom->likelihood_noisy_speech, 328/*0.01 Q15*/); + st_fx->hFdCngDec->hFdCngCom->likelihood_noisy_speech = add( st_fx->hFdCngDec->hFdCngCom->likelihood_noisy_speech, 328 /*0.01 Q15*/ ); move16(); } st_fx->lp_noise = st_fx->hFdCngDec->lp_noise; move16(); test(); - IF( st_fx->flag_cna && GE_16(st_fx->psf_lp_noise_fx,15<<8)) + IF( st_fx->flag_cna && GE_16( st_fx->psf_lp_noise_fx, 15 << 8 ) ) { flag_cna = 1; move16(); generate_masking_noise_fx( syn_fx, st_fx->Q_syn, st_fx->hFdCngDec->hFdCngCom, st_fx->hFdCngDec->hFdCngCom->frameSize, AMR_WB_CORE ); } - ELSE IF ( st_fx->flag_cna ) + ELSE IF( st_fx->flag_cna ) { generate_masking_noise_update_seed_fx( st_fx->hFdCngDec->hFdCngCom ); } /*Copy(syn+L_FRAME-M-1, st_fx->syn, M+1);*/ } - ELSE IF ( st_fx->flag_cna ) + ELSE IF( st_fx->flag_cna ) { generate_masking_noise_update_seed_fx( st_fx->hFdCngDec->hFdCngCom ); } @@ -825,15 +824,15 @@ ivas_error amr_wb_dec_fx( test(); test(); test(); - IF( EQ_16(st_fx->last_flag_cna,1)&&((EQ_16(st_fx->last_core,ACELP_CORE)&&NE_16(st_fx->last_coder_type,AUDIO))||EQ_16(st_fx->last_core,AMR_WB_CORE))) + IF( EQ_16( st_fx->last_flag_cna, 1 ) && ( ( EQ_16( st_fx->last_core, ACELP_CORE ) && NE_16( st_fx->last_coder_type, AUDIO ) ) || EQ_16( st_fx->last_core, AMR_WB_CORE ) ) ) { - FOR (i=0; i < L_FRAME/2; i++) + FOR( i = 0; i < L_FRAME / 2; i++ ) { - syn_fx[i] = add( syn_fx[i], shr_r( st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[i+5*L_FRAME/4], -st_fx->Q_syn ) ); + syn_fx[i] = add( syn_fx[i], shr_r( st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * L_FRAME / 4], -st_fx->Q_syn ) ); move16(); } } - set16_fx( st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, shl(L_FRAME,1) ); + set16_fx( st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, shl( L_FRAME, 1 ) ); } /*----------------------------------------------------------------* @@ -842,25 +841,25 @@ ivas_error amr_wb_dec_fx( *----------------------------------------------------------------*/ /* check if the CLDFB works on the right sample rate */ - IF( (st_fx->cldfbAna->usb * st_fx->cldfbAna->no_col) != L_FRAME ) + IF( ( st_fx->cldfbAna->usb * st_fx->cldfbAna->no_col ) != L_FRAME ) { /* resample to ACELP internal sampling rate */ - Word16 newCldfbBands = CLDFB_getNumChannels(INT_FS_FX); + Word16 newCldfbBands = CLDFB_getNumChannels( INT_FS_FX ); resampleCldfb( st_fx->cldfbAna, newCldfbBands, L_FRAME, 0 ); resampleCldfb( st_fx->cldfbBPF, newCldfbBands, L_FRAME, 0 ); - if( st_fx->ini_frame > 0 ) + if ( st_fx->ini_frame > 0 ) { - st_fx->cldfbSyn->bandsToZero = sub(st_fx->cldfbSyn->no_channels,st_fx->cldfbAna->no_channels); + st_fx->cldfbSyn->bandsToZero = sub( st_fx->cldfbSyn->no_channels, st_fx->cldfbAna->no_channels ); } } - bass_psfilter_fx(st_fx->hBPF, st_fx->Opt_AMR_WB, syn_fx, L_FRAME, pitch_buf_fx, st_fx->bpf_off, st_fx->stab_fac_fx, - &st_fx->stab_fac_smooth_fx, GENERIC, st_fx->Q_syn, bpf_error_signal); + bass_psfilter_fx( st_fx->hBPF, st_fx->Opt_AMR_WB, syn_fx, L_FRAME, pitch_buf_fx, st_fx->bpf_off, st_fx->stab_fac_fx, + &st_fx->stab_fac_smooth_fx, GENERIC, st_fx->Q_syn, bpf_error_signal ); cldfbAnalysisFiltering( st_fx->cldfbAna, realBuffer, imagBuffer, &scaleFactor, syn_fx, - negate(st_fx->Q_syn), CLDFB_NO_COL_MAX, workBuffer ); + negate( st_fx->Q_syn ), CLDFB_NO_COL_MAX, workBuffer ); scaleFactor.hb_scale = scaleFactor.lb_scale; move16(); @@ -868,27 +867,27 @@ ivas_error amr_wb_dec_fx( /* CLDFB analysis and add the BPF error signal */ i = 0; move16(); - if( st_fx->bpf_off == 0 ) + if ( st_fx->bpf_off == 0 ) { i = CLDFB_NO_COL_MAX; move16(); } - addBassPostFilter_fx( bpf_error_signal, realBuffer, imagBuffer, st_fx->cldfbBPF, workBuffer, negate(st_fx->Q_syn), - i, st_fx->cldfbAna->no_col, st_fx->cldfbAna->no_channels, &scaleFactor ); + addBassPostFilter_fx( bpf_error_signal, realBuffer, imagBuffer, st_fx->cldfbBPF, workBuffer, negate( st_fx->Q_syn ), + i, st_fx->cldfbAna->no_col, st_fx->cldfbAna->no_channels, &scaleFactor ); st_fx->Q_syn2 = st_fx->Q_syn; move16(); - if( NE_16(st_fx->cldfbSyn->bandsToZero,sub(st_fx->cldfbSyn->no_channels,st_fx->cldfbAna->no_channels))) + if ( NE_16( st_fx->cldfbSyn->bandsToZero, sub( st_fx->cldfbSyn->no_channels, st_fx->cldfbAna->no_channels ) ) ) { /* in case of BW switching, re-init to default */ - st_fx->cldfbSyn->bandsToZero = sub(st_fx->cldfbSyn->no_channels, st_fx->cldfbAna->no_channels); + st_fx->cldfbSyn->bandsToZero = sub( st_fx->cldfbSyn->no_channels, st_fx->cldfbAna->no_channels ); } cldfb_synth_set_bandsToZero( st_fx, realBuffer, imagBuffer, CLDFB_NO_COL_MAX, scaleFactor ); /* CLDFB synthesis of the combined signal */ - cldfbSynthesisFiltering( st_fx->cldfbSyn, realBuffer, imagBuffer, &scaleFactor, synth_out_fx, negate(st_fx->Q_syn2), CLDFB_NO_COL_MAX, workBuffer ); + cldfbSynthesisFiltering( st_fx->cldfbSyn, realBuffer, imagBuffer, &scaleFactor, synth_out_fx, negate( st_fx->Q_syn2 ), CLDFB_NO_COL_MAX, workBuffer ); /* Bring CLDFB output to Q-1 */ - Scale_sig( synth_out_fx, output_frame, negate(st_fx->Q_syn2) ); + Scale_sig( synth_out_fx, output_frame, negate( st_fx->Q_syn2 ) ); st_fx->Q_syn2 = 0; move16(); @@ -900,19 +899,19 @@ ivas_error amr_wb_dec_fx( /*--------------------------------------------------------* * calculate the average frame energy *--------------------------------------------------------*/ - frame_ener_fx( L_FRAME, st_fx->clas_dec, syn_fx, mult_r(pitch_buf_fx[3],512), &L_Ng_ener, L_FRAME, st_fx->Q_syn, 3, 0 ); + frame_ener_fx( L_FRAME, st_fx->clas_dec, syn_fx, mult_r( pitch_buf_fx[3], 512 ), &L_Ng_ener, L_FRAME, st_fx->Q_syn, 3, 0 ); /*--------------------------------------------------------* * optimized for NO_S@-26dBov with street noise @ SNR=25dB *--------------------------------------------------------*/ /* ng_ener = 10.0f * (float)log10(ng_ener + 0.01f) - 90.3087f + 15; */ - L_Ng_ener = L_max(1, L_Ng_ener); - tmp16 = norm_l(L_Ng_ener); - exp2 = Log2_norm_lc(L_shl(L_Ng_ener, tmp16)); - tmp16 = sub(30, tmp16); - ng_ener = mac_r(L_shl(L_mac(-1233858L, tmp16, 24660), 8+2), exp2, 771); + L_Ng_ener = L_max( 1, L_Ng_ener ); + tmp16 = norm_l( L_Ng_ener ); + exp2 = Log2_norm_lc( L_shl( L_Ng_ener, tmp16 ) ); + tmp16 = sub( 30, tmp16 ); + ng_ener = mac_r( L_shl( L_mac( -1233858L, tmp16, 24660 ), 8 + 2 ), exp2, 771 ); /* st_fx->ng_ener_ST = 0.7f * st_fx->ng_ener_ST + 0.3f * ng_ener; */ - st_fx->Ng_ener_ST_fx = mac_r(L_mult(st_fx->Ng_ener_ST_fx, 22938), ng_ener, 9830); + st_fx->Ng_ener_ST_fx = mac_r( L_mult( st_fx->Ng_ener_ST_fx, 22938 ), ng_ener, 9830 ); move16(); /*-----------------------------------------------------------------* @@ -921,34 +920,35 @@ ivas_error amr_wb_dec_fx( test(); test(); - IF( GE_16(output_frame,L_FRAME16k)&&(NE_16(st_fx->cldfbSyn->bandsToZero,sub(st_fx->cldfbSyn->no_channels,10))||NE_16(st_fx->last_flag_filter_NB,1))) + IF( GE_16( output_frame, L_FRAME16k ) && ( NE_16( st_fx->cldfbSyn->bandsToZero, sub( st_fx->cldfbSyn->no_channels, 10 ) ) || NE_16( st_fx->last_flag_filter_NB, 1 ) ) ) { - hf_synth_amr_wb_fx( st_fx->hAmrwb_IO, st_fx->hBWE_zero, + hf_synth_amr_wb_fx( st_fx->hAmrwb_IO, st_fx->hBWE_zero, st_fx->core_brate, output_frame, Aq_fx, exc2_fx, syn_fx, &amr_io_class, synth_out_fx, class_para_fx, hf_gain_fx, voice_factors_fx, pitch_buf_fx, st_fx->Ng_ener_ST_fx, lsf_new_fx, st_fx->Q_exc, st_fx->Q_syn2 ); } ELSE { - hf_synth_amr_wb_reset_fx( st_fx->hBWE_zero, st_fx->hAmrwb_IO); + hf_synth_amr_wb_reset_fx( st_fx->hBWE_zero, st_fx->hAmrwb_IO ); } /*----------------------------------------------------------------------* * Updates *----------------------------------------------------------------------*/ - updt_dec_fx( st_fx, old_exc_fx, pitch_buf_fx, 0, Aq_fx , lsf_new_fx, lsp_new_fx, voice_factors_fx, dummy_buf_fx, gain_buf ); + updt_dec_fx( st_fx, old_exc_fx, pitch_buf_fx, 0, Aq_fx, lsf_new_fx, lsp_new_fx, voice_factors_fx, dummy_buf_fx, gain_buf ); /* update old_Aq[] - needed in improv_amr_wb_gs_fx() */ - Copy( Aq_fx, st_fx->hAmrwb_IO->old_Aq_fx, NB_SUBFR * (M+1) ); - - test();test();test();test();test();test();test();test(); - if (!st_fx->bfi - && st_fx->prev_bfi - && GE_32(st_fx->last_total_brate, HQ_48k) - && EQ_16(st_fx->last_codec_mode, MODE2) - && (EQ_16(st_fx->last_core_bfi, TCX_20_CORE) || EQ_16(st_fx->last_core_bfi, TCX_10_CORE) ) - && st_fx->plcInfo.concealment_method == TCX_NONTONAL - && LT_32(st_fx->plcInfo.nbLostCmpt, 4) ) + Copy( Aq_fx, st_fx->hAmrwb_IO->old_Aq_fx, NB_SUBFR * ( M + 1 ) ); + + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + if ( !st_fx->bfi && st_fx->prev_bfi && GE_32( st_fx->last_total_brate, HQ_48k ) && EQ_16( st_fx->last_codec_mode, MODE2 ) && ( EQ_16( st_fx->last_core_bfi, TCX_20_CORE ) || EQ_16( st_fx->last_core_bfi, TCX_10_CORE ) ) && st_fx->plcInfo.concealment_method == TCX_NONTONAL && LT_32( st_fx->plcInfo.nbLostCmpt, 4 ) ) { waveadj_rec = 1; move16(); @@ -985,59 +985,59 @@ ivas_error amr_wb_dec_fx( st_fx->last_flag_cna = flag_cna; move16(); - updt_dec_common_fx(st_fx, -1, -1, NULL, 0); + updt_dec_common_fx( st_fx, -1, -1, NULL, 0 ); /*----------------------------------------------------------------* * Overlap of ACELP synthesis with old MDCT memory *----------------------------------------------------------------*/ - if( st_fx->bfi ) + if ( st_fx->bfi ) { /* calculate another loss frame to fill gap in case of switching frame loss */ - if ((error = acelp_core_switch_dec_bfi_fx( st_fx, hHQ_core->fer_samples_fx, st_fx->coder_type )) != IVAS_ERR_OK) + if ( ( error = acelp_core_switch_dec_bfi_fx( st_fx, hHQ_core->fer_samples_fx, st_fx->coder_type ) ) != IVAS_ERR_OK ) { return error; } } - delay_comp = NS2SA_fx2(st_fx->output_Fs, DELAY_CLDFB_NS); - Scale_sig(st_fx->delay_buf_out_fx, delay_comp, sub(st_fx->Q_syn2, hHQ_core->Q_old_postdec)); - hHQ_core->Q_old_postdec=st_fx->Q_syn2; + delay_comp = NS2SA_fx2( st_fx->output_Fs, DELAY_CLDFB_NS ); + Scale_sig( st_fx->delay_buf_out_fx, delay_comp, sub( st_fx->Q_syn2, hHQ_core->Q_old_postdec ) ); + hHQ_core->Q_old_postdec = st_fx->Q_syn2; move16(); - IF( EQ_16(last_core_ori,HQ_CORE)) + IF( EQ_16( last_core_ori, HQ_CORE ) ) { - Word16 step, alpha,nz; + Word16 step, alpha, nz; - Scale_sig(hHQ_core->old_out_fx, L_FRAME48k, sub(st_fx->Q_syn2, hHQ_core->Q_old_wtda)); - hHQ_core->Q_old_wtda=st_fx->Q_syn2; + Scale_sig( hHQ_core->old_out_fx, L_FRAME48k, sub( st_fx->Q_syn2, hHQ_core->Q_old_wtda ) ); + hHQ_core->Q_old_wtda = st_fx->Q_syn2; move16(); - Copy( st_fx->delay_buf_out_fx,synth_out_fx, delay_comp ); /* copy the HQ/ACELP delay synchroniation buffer at the beginning of ACELP frame */ + Copy( st_fx->delay_buf_out_fx, synth_out_fx, delay_comp ); /* copy the HQ/ACELP delay synchroniation buffer at the beginning of ACELP frame */ i = 15; move16(); - tmps = NS2SA_fx2(st_fx->output_Fs, 6000000L); - nz = NS2SA_fx2(st_fx->output_Fs, N_ZERO_MDCT_NS); - step = Inv16(tmps, &i); - step = shl(step, i); + tmps = NS2SA_fx2( st_fx->output_Fs, 6000000L ); + nz = NS2SA_fx2( st_fx->output_Fs, N_ZERO_MDCT_NS ); + step = Inv16( tmps, &i ); + step = shl( step, i ); alpha = 0; move16(); test(); IF( st_fx->prev_bfi && hHQ_core->HqVoicing ) { - Copy_Scale_sig(hHQ_core->fer_samples_fx, &hHQ_core->old_out_fx[nz], tmps,negate(st_fx->Q_syn2)); + Copy_Scale_sig( hHQ_core->fer_samples_fx, &hHQ_core->old_out_fx[nz], tmps, negate( st_fx->Q_syn2 ) ); } - FOR (i = 0; i < tmps; i++) + FOR( i = 0; i < tmps; i++ ) { #ifdef BASOP_NOGLOB - synth_out_fx[i+delay_comp] = msu_r_sat(L_mult(synth_out_fx[i+delay_comp], alpha), hHQ_core->old_out_fx[i+nz], add(alpha, -32768)); + synth_out_fx[i + delay_comp] = msu_r_sat( L_mult( synth_out_fx[i + delay_comp], alpha ), hHQ_core->old_out_fx[i + nz], add( alpha, -32768 ) ); #else - synth_out_fx[i+delay_comp] = msu_r(L_mult(synth_out_fx[i+delay_comp], alpha), hHQ_core->old_out_fx[i+nz], add(alpha, -32768)); + synth_out_fx[i + delay_comp] = msu_r( L_mult( synth_out_fx[i + delay_comp], alpha ), hHQ_core->old_out_fx[i + nz], add( alpha, -32768 ) ); #endif move16(); - alpha = add(alpha, step); + alpha = add( alpha, step ); } } @@ -1047,40 +1047,40 @@ ivas_error amr_wb_dec_fx( *----------------------------------------------------------------*/ /* Delay ACELP synthesis by DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS delay */ - IF ( GE_16(output_frame,L_FRAME16k)) + IF( GE_16( output_frame, L_FRAME16k ) ) { - tmps = NS2SA_fx2(st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS); - Scale_sig( st_fx->prev_synth_buffer_fx, tmps, sub(st_fx->Q_syn2, st_fx->Qprev_synth_buffer_fx) ); - delay_signal(synth_out_fx, output_frame, st_fx->prev_synth_buffer_fx, tmps); + tmps = NS2SA_fx2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ); + Scale_sig( st_fx->prev_synth_buffer_fx, tmps, sub( st_fx->Q_syn2, st_fx->Qprev_synth_buffer_fx ) ); + delay_signal( synth_out_fx, output_frame, st_fx->prev_synth_buffer_fx, tmps ); } - if (waveadj_rec) + if ( waveadj_rec ) { tmps = 0; - IF( GE_16(output_frame,L_FRAME16k)) + IF( GE_16( output_frame, L_FRAME16k ) ) { - tmps = NS2SA_fx2(st_fx->output_Fs, DELAY_BWE_TOTAL_NS); + tmps = NS2SA_fx2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ); } - waveform_adj2_fix(st_fx->tonalMDCTconceal.secondLastPcmOut, synth_out_fx+tmps, st_fx->plcInfo.data_noise, &st_fx->plcInfo.outx_new_n1_fx, - &st_fx->plcInfo.nsapp_gain_fx, &st_fx->plcInfo.nsapp_gain_n_fx, &st_fx->plcInfo.recovery_gain, st_fx->plcInfo.step_concealgain_fx, - st_fx->plcInfo.Pitch_fx, st_fx->plcInfo.FrameSize, tmps, add(extract_l(st_fx->plcInfo.nbLostCmpt), 1), st_fx->bfi); + waveform_adj2_fix( st_fx->tonalMDCTconceal.secondLastPcmOut, synth_out_fx + tmps, st_fx->plcInfo.data_noise, &st_fx->plcInfo.outx_new_n1_fx, + &st_fx->plcInfo.nsapp_gain_fx, &st_fx->plcInfo.nsapp_gain_n_fx, &st_fx->plcInfo.recovery_gain, st_fx->plcInfo.step_concealgain_fx, + st_fx->plcInfo.Pitch_fx, st_fx->plcInfo.FrameSize, tmps, add( extract_l( st_fx->plcInfo.nbLostCmpt ), 1 ), st_fx->bfi ); } /* HP filter */ - Scale_sig32( st_fx->L_mem_hp_out_fx, 4, sub(st_fx->Q_syn2, st_fx->Qprev_synth_buffer_fx) ); + Scale_sig32( st_fx->L_mem_hp_out_fx, 4, sub( st_fx->Q_syn2, st_fx->Qprev_synth_buffer_fx ) ); st_fx->Qprev_synth_buffer_fx = st_fx->Q_syn2; - hp20( synth_out_fx, 1/*stride*/, output_frame, st_fx->L_mem_hp_out_fx, L_mult0(output_frame, 50) ); + hp20( synth_out_fx, 1 /*stride*/, output_frame, st_fx->L_mem_hp_out_fx, L_mult0( output_frame, 50 ) ); /* save synthesis for core switching */ - Copy_Scale_sig( synth_out_fx+NS2SA_fx2( st_fx->output_Fs,ACELP_LOOK_NS+DELAY_BWE_TOTAL_NS), st_fx->old_synth_sw_fx, NS2SA_fx2(st_fx->output_Fs,FRAME_SIZE_NS-ACELP_LOOK_NS-DELAY_BWE_TOTAL_NS), sub(hHQ_core->Q_old_postdec, st_fx->Q_syn2) ); + Copy_Scale_sig( synth_out_fx + NS2SA_fx2( st_fx->output_Fs, ACELP_LOOK_NS + DELAY_BWE_TOTAL_NS ), st_fx->old_synth_sw_fx, NS2SA_fx2( st_fx->output_Fs, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS ), sub( hHQ_core->Q_old_postdec, st_fx->Q_syn2 ) ); { /* TCX-LTP Postfilter: used in AMR-WB IO to update memories and to avoid discontinuities when the past frame was TCX */ Word16 delta = NS2SA_fx2( st_fx->output_Fs, TCXLTP_DELAY_NS ); - Scale_sig(hTcxLtpDec->tcxltp_mem_in, delta, sub(st_fx->Q_syn2, st_fx->Qprev_synth_buffer_fx)); - Scale_sig(hTcxLtpDec->tcxltp_mem_out, output_frame, sub(st_fx->Q_syn2, st_fx->Qprev_synth_buffer_fx)); - tcx_ltp_post(st_fx, hTcxLtpDec, ACELP_CORE, output_frame, 0, synth_out_fx, NULL); + Scale_sig( hTcxLtpDec->tcxltp_mem_in, delta, sub( st_fx->Q_syn2, st_fx->Qprev_synth_buffer_fx ) ); + Scale_sig( hTcxLtpDec->tcxltp_mem_out, output_frame, sub( st_fx->Q_syn2, st_fx->Qprev_synth_buffer_fx ) ); + tcx_ltp_post( st_fx, hTcxLtpDec, ACELP_CORE, output_frame, 0, synth_out_fx, NULL ); } /* final output of synthesis signal */ @@ -1101,29 +1101,32 @@ void amr_wb_dec_init_fx( { Word16 i; /* gain quantization memory (used in AMR-WB IO mode) */ - FOR(i = 0; i < GAIN_PRED_ORDER; i++) + FOR( i = 0; i < GAIN_PRED_ORDER; i++ ) { hAmrwb_IO->past_qua_en_fx[i] = -14336; - move16(); /* Q10; */ /* gain quantization memory (used also in AMR-WB IO mode) */ + move16(); /* Q10; */ /* gain quantization memory (used also in AMR-WB IO mode) */ } /* Improvement of unvoiced and audio signals in AMR-WB IO mode */ hAmrwb_IO->UV_cnt_fx = 30; move16(); - hAmrwb_IO->LT_UV_cnt_fx = (60<<6); + hAmrwb_IO->LT_UV_cnt_fx = ( 60 << 6 ); move16(); - set16_fx(hAmrwb_IO->lt_diff_etot_fx, 0, MAX_LT); + set16_fx( hAmrwb_IO->lt_diff_etot_fx, 0, MAX_LT ); hAmrwb_IO->Last_ener_fx = 0; move16(); - set16_fx(hAmrwb_IO->old_Aq_fx, 0, NB_SUBFR * (M + 1)); + set16_fx( hAmrwb_IO->old_Aq_fx, 0, NB_SUBFR * ( M + 1 ) ); hAmrwb_IO->old_Aq_fx[0] = 16384; hAmrwb_IO->old_Aq_fx[M + 1] = 16384; - hAmrwb_IO->old_Aq_fx[2 * (M + 1)] = 16384; - hAmrwb_IO->old_Aq_fx[3 * (M + 1)] = 16384; - move16(); move16(); move16(); move16(); + hAmrwb_IO->old_Aq_fx[2 * ( M + 1 )] = 16384; + hAmrwb_IO->old_Aq_fx[3 * ( M + 1 )] = 16384; + move16(); + move16(); + move16(); + move16(); hAmrwb_IO->lt_voice_fac_fx = 0; move16(); return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/ari_dec.c b/lib_dec/ari_dec.c index 8757e5c12..334e24195 100644 --- a/lib_dec/ari_dec.c +++ b/lib_dec/ari_dec.c @@ -103,29 +103,28 @@ int16_t ari_start_decoding_14bits_prm_ivas( #ifdef IVAS_FLOAT_FIXED Word16 ari_start_decoding_14bits_prm_ivas_fx( const Word16 *ptr, - Word16 bp, - Tastat *s -) + Word16 bp, + Tastat *s ) { - Word32 val; - Word16 i; + Word32 val; + Word16 i; const Word16 *p; - val = L_deposit_l(0); + val = L_deposit_l( 0 ); p = ptr + bp; - FOR(i = 0; i < cbitsnew; i++) + FOR( i = 0; i < cbitsnew; i++ ) { - val = L_or(L_shl(val, 1), *(p + i)); + val = L_or( L_shl( val, 1 ), *( p + i ) ); } - s->low = L_deposit_l(0); + s->low = L_deposit_l( 0 ); s->high = ari_q4new; move32(); s->value = val; move32(); - return add(bp, i); + return add( bp, i ); } #endif diff --git a/lib_dec/ari_dec_fx.c b/lib_dec/ari_dec_fx.c index 32e48b5f4..3fa319ad2 100644 --- a/lib_dec/ari_dec_fx.c +++ b/lib_dec/ari_dec_fx.c @@ -14,9 +14,9 @@ * Ari decode 14 bits routines -------------------------------------------------------------*/ -Word16 ari_decode_overflow_fx(Tastat *s) +Word16 ari_decode_overflow_fx( Tastat *s ) { - return L_sub(L_sub(s->high, 1), s->low) <= 0; + return L_sub( L_sub( s->high, 1 ), s->low ) <= 0; } /** @@ -26,57 +26,54 @@ Word16 ari_decode_overflow_fx(Tastat *s) * \param[o] s */ void ari_start_decoding_14bits_fx( - Decoder_State *st, - Tastat *s -) + Decoder_State *st, + Tastat *s ) { - Word32 val; + Word32 val; - val = L_and(L_deposit_l(get_next_indice(st, cbitsnew)), 0xffffL); + val = L_and( L_deposit_l( get_next_indice( st, cbitsnew ) ), 0xffffL ); - s->low = L_deposit_l(0); - s->high = ari_q4new+1; + s->low = L_deposit_l( 0 ); + s->high = ari_q4new + 1; move32(); s->value = val; move32(); } Word16 ari_start_decoding_14bits_prm_fx( - const Word16 *ptr, - Word16 bp, - Tastat *s -) + const Word16 *ptr, + Word16 bp, + Tastat *s ) { - Word32 val; - Word16 i; + Word32 val; + Word16 i; const Word16 *p; - val = L_deposit_l(0); + val = L_deposit_l( 0 ); - p = ptr+bp; + p = ptr + bp; - FOR (i=0; ilow = L_deposit_l(0); - s->high = ari_q4new+1; + s->low = L_deposit_l( 0 ); + s->high = ari_q4new + 1; move32(); s->value = val; move32(); - return add(bp,i); + return add( bp, i ); } static Word16 ari_lookup_s17_fx( - Word32 cum, - Word32 range, - UWord16 const *cum_freq -) + Word32 cum, + Word32 range, + UWord16 const *cum_freq ) { Word32 tmp; const UWord16 *p; @@ -89,52 +86,51 @@ static Word16 ari_lookup_s17_fx( /* tmp_p = p+8; if (tmp_p[0]*range>cum) p = tmp_p; */ /* max value in p[x] is 16384 => 14 bits */ - range_l = extract_l(L_and(range,0x7FFF)); - range_h = extract_l(L_shr(range,15)); + range_l = extract_l( L_and( range, 0x7FFF ) ); + range_h = extract_l( L_shr( range, 15 ) ); - tmp = L_multi31x16_X2(range_h, range_l,p[8]); - if (GT_32(tmp,cum)) + tmp = L_multi31x16_X2( range_h, range_l, p[8] ); + if ( GT_32( tmp, cum ) ) { p = p + 8; } - tmp = L_multi31x16_X2(range_h, range_l,p[4]); - if (GT_32(tmp,cum)) + tmp = L_multi31x16_X2( range_h, range_l, p[4] ); + if ( GT_32( tmp, cum ) ) { p = p + 4; } - tmp = L_multi31x16_X2(range_h, range_l,p[2]); - if (GT_32(tmp,cum)) + tmp = L_multi31x16_X2( range_h, range_l, p[2] ); + if ( GT_32( tmp, cum ) ) { p = p + 2; } - tmp = L_multi31x16_X2(range_h, range_l,p[1]); - IF (GT_32(tmp,cum)) + tmp = L_multi31x16_X2( range_h, range_l, p[1] ); + IF( GT_32( tmp, cum ) ) { p = p + 1; - tmp = L_multi31x16_X2(range_h, range_l,p[1]); + tmp = L_multi31x16_X2( range_h, range_l, p[1] ); test(); - if ( ((Word32)(&cum_freq[15] - p) == 0) && (GT_32(tmp,cum))) + if ( ( (Word32) ( &cum_freq[15] - p ) == 0 ) && ( GT_32( tmp, cum ) ) ) { p = p + 1; } } /* return extract_l(L_shr(L_sub((Word32)p,(Word32)cum_freq),1)); */ - L_sub(0,0); - L_shr(0,0); /* pointer subtraction */ - return extract_l(p - cum_freq); + L_sub( 0, 0 ); + L_shr( 0, 0 ); /* pointer subtraction */ + return extract_l( p - cum_freq ); } static Word16 ari_lookup_s27_fx( - Word32 cum, - Word32 range, - UWord16 const *cum_freq -) + Word32 cum, + Word32 range, + UWord16 const *cum_freq ) { Word32 tmp; Word16 range_l, range_h; @@ -145,8 +141,8 @@ static Word16 ari_lookup_s27_fx( /* tmp_p = p+8; if (tmp_p[0]*range>cum) p = tmp_p; */ /* max value in p[x] is 16384 => 14 bits */ - range_l = extract_l(L_and(range,0x7FFF)); - range_h = extract_l(L_shr(range,15)); + range_l = extract_l( L_and( range, 0x7FFF ) ); + range_h = extract_l( L_shr( range, 15 ) ); /* begin change when compared with ari_decode_14bits_s17_ext_fx, starting with line: tmp = L_multi31x16_X2(range_h, range_l, p[8]); */ @@ -158,68 +154,68 @@ static Word16 ari_lookup_s27_fx( /* do a five step binary search, using the interval [il, ih) */ im = 13; move16(); /* (il + ih) >> 1 */ - tmp = L_multi31x16_X2(range_h, range_l, cum_freq[im]); - tmp = L_sub(tmp, cum); - if (tmp > 0) + tmp = L_multi31x16_X2( range_h, range_l, cum_freq[im] ); + tmp = L_sub( tmp, cum ); + if ( tmp > 0 ) { il = im; move16(); } - if (tmp <= 0) + if ( tmp <= 0 ) { ih = im; move16(); } - im = shr(add(il, ih), 1); - tmp = L_multi31x16_X2(range_h, range_l, cum_freq[im]); - tmp = L_sub(tmp, cum); - if (tmp > 0) + im = shr( add( il, ih ), 1 ); + tmp = L_multi31x16_X2( range_h, range_l, cum_freq[im] ); + tmp = L_sub( tmp, cum ); + if ( tmp > 0 ) { il = im; move16(); } - if (tmp <= 0) + if ( tmp <= 0 ) { ih = im; move16(); } - im = shr(add(il, ih), 1); - tmp = L_multi31x16_X2(range_h, range_l, cum_freq[im]); - tmp = L_sub(tmp, cum); - if (tmp > 0) + im = shr( add( il, ih ), 1 ); + tmp = L_multi31x16_X2( range_h, range_l, cum_freq[im] ); + tmp = L_sub( tmp, cum ); + if ( tmp > 0 ) { il = im; move16(); } - if (tmp <= 0) + if ( tmp <= 0 ) { ih = im; move16(); } - im = shr(add(il, ih), 1); - tmp = L_multi31x16_X2(range_h, range_l, cum_freq[im]); - tmp = L_sub(tmp, cum); - if (tmp > 0) + im = shr( add( il, ih ), 1 ); + tmp = L_multi31x16_X2( range_h, range_l, cum_freq[im] ); + tmp = L_sub( tmp, cum ); + if ( tmp > 0 ) { il = im; move16(); } - if (tmp <= 0) + if ( tmp <= 0 ) { ih = im; move16(); } - IF (GT_16(sub(ih, il), 1)) /* if the interval has more than one symbol */ + IF( GT_16( sub( ih, il ), 1 ) ) /* if the interval has more than one symbol */ { /* here, only ih == il + 2 is possible, which means two symbols in the interval */ - im = add(il, 1); /* (il + ih) >> 1 */ - tmp = L_multi31x16_X2(range_h, range_l, cum_freq[im]); - tmp = L_sub(tmp, cum); - if (tmp > 0) + im = add( il, 1 ); /* (il + ih) >> 1 */ + tmp = L_multi31x16_X2( range_h, range_l, cum_freq[im] ); + tmp = L_sub( tmp, cum ); + if ( tmp > 0 ) { il = im; move16(); @@ -230,24 +226,23 @@ static Word16 ari_lookup_s27_fx( } static Word16 ari_lookup_bit_fx( - Word32 cum, - Word32 range, - UWord16 const *cum_freq -) + Word32 cum, + Word32 range, + UWord16 const *cum_freq ) { Word16 symbol = 0; /* initialize just to avoid compiler warning */ - (void)cum_freq; + (void) cum_freq; - range = L_shl(range, 13); /* L_multi31x16_X2(range_h, range_l, 8192) */ - cum = L_sub(range, cum); + range = L_shl( range, 13 ); /* L_multi31x16_X2(range_h, range_l, 8192) */ + cum = L_sub( range, cum ); - if (cum > 0) + if ( cum > 0 ) { symbol = 1; move16(); } - if (cum <= 0) + if ( cum <= 0 ) { symbol = 0; move16(); @@ -260,59 +255,58 @@ static Word16 ari_decode_14bits_ext_fx( Decoder_State *st, Tastat *s, UWord16 const *cum_freq, - Word16 (*lookup_fn)(Word32 cum, Word32 range, UWord16 const *cum_freq) -) + Word16 ( *lookup_fn )( Word32 cum, Word32 range, UWord16 const *cum_freq ) ) { - Word32 cum; - Word16 symbol; - Word32 low; - Word32 high; - Word32 range; - Word32 value; + Word32 cum; + Word16 symbol; + Word32 low; + Word32 high; + Word32 range; + Word32 value; Word16 i; - low = s->low; - move32(); - high = s->high; - move32(); + low = s->low; + move32(); + high = s->high; + move32(); value = s->value; - move32(); + move32(); - range = L_sub(high, low); + range = L_sub( high, low ); - cum = L_add(L_shl(L_sub(value, low), stat_bitsnew), sub(shl(1,stat_bitsnew),1)); - if (cum < 0) + cum = L_add( L_shl( L_sub( value, low ), stat_bitsnew ), sub( shl( 1, stat_bitsnew ), 1 ) ); + if ( cum < 0 ) { cum = 0x7fffffff; } - symbol = lookup_fn(cum, range, cum_freq); + symbol = lookup_fn( cum, range, cum_freq ); - high = L_add(low,mul_sbc_14bits(range,cum_freq[symbol])); - low = L_add(low,mul_sbc_14bits(range,cum_freq[symbol+1])); + high = L_add( low, mul_sbc_14bits( range, cum_freq[symbol] ) ); + low = L_add( low, mul_sbc_14bits( range, cum_freq[symbol + 1] ) ); - FOR (i = 0; i < 0x7FFF; i++) + FOR( i = 0; i < 0x7FFF; i++ ) { Word32 L_msb_diff, L_msb_low, L_msb_high; - L_msb_high = L_shr(L_sub(high,1),14); - L_msb_low = L_shr(low,14); - L_msb_diff = L_sub(L_msb_high, L_msb_low); - IF (GE_32(L_msb_diff,2)) + L_msb_high = L_shr( L_sub( high, 1 ), 14 ); + L_msb_low = L_shr( low, 14 ); + L_msb_diff = L_sub( L_msb_high, L_msb_low ); + IF( GE_32( L_msb_diff, 2 ) ) { BREAK; } - assert (tab_ari_qnew[L_msb_high][L_msb_low] != 0x0CCC); - assert (tab_ari_qnew[L_msb_high][L_msb_low] != 0x0BBB); - low = L_msu(low,1,tab_ari_qnew[L_msb_high][L_msb_low]); - low = L_shl(low,1); - high = L_msu(high,1,tab_ari_qnew[L_msb_high][L_msb_low]); - high = L_shl(high,1); - value = L_msu(value,1,tab_ari_qnew[L_msb_high][L_msb_low]); - value = L_mac0(L_shl(value,1),1,get_next_indice_1(st)); + assert( tab_ari_qnew[L_msb_high][L_msb_low] != 0x0CCC ); + assert( tab_ari_qnew[L_msb_high][L_msb_low] != 0x0BBB ); + low = L_msu( low, 1, tab_ari_qnew[L_msb_high][L_msb_low] ); + low = L_shl( low, 1 ); + high = L_msu( high, 1, tab_ari_qnew[L_msb_high][L_msb_low] ); + high = L_shl( high, 1 ); + value = L_msu( value, 1, tab_ari_qnew[L_msb_high][L_msb_low] ); + value = L_mac0( L_shl( value, 1 ), 1, get_next_indice_1( st ) ); } - s->low = low; + s->low = low; move32(); s->high = high; move32(); @@ -326,87 +320,87 @@ static Word16 ari_decode_14bits_ext_fx( /** * \brief Only for 17 symbols with new extended Tables */ -Word16 ari_decode_14bits_s17_ext_fx(Decoder_State *st, Tastat *s, UWord16 const *cum_freq) +Word16 ari_decode_14bits_s17_ext_fx( Decoder_State *st, Tastat *s, UWord16 const *cum_freq ) { - return ari_decode_14bits_ext_fx(st, s, cum_freq, ari_lookup_s17_fx); + return ari_decode_14bits_ext_fx( st, s, cum_freq, ari_lookup_s17_fx ); } /** * \brief Only for 27 symbols with new extended Tables */ -Word16 ari_decode_14bits_s27_ext_fx(Decoder_State *st, Tastat *s, UWord16 const *cum_freq) +Word16 ari_decode_14bits_s27_ext_fx( Decoder_State *st, Tastat *s, UWord16 const *cum_freq ) { - return ari_decode_14bits_ext_fx(st, s, cum_freq, ari_lookup_s27_fx); + return ari_decode_14bits_ext_fx( st, s, cum_freq, ari_lookup_s27_fx ); } /** * \brief Only for decoding one bit with uniform probability: * the equivalent cum_freq table used is {16384, 8192, 0} */ -Word16 ari_decode_14bits_bit_ext_fx(Decoder_State *st, Tastat *s) +Word16 ari_decode_14bits_bit_ext_fx( Decoder_State *st, Tastat *s ) { - static const UWord16 cum_freq[3] = {16384, 8192, 0}; - return ari_decode_14bits_ext_fx(st, s, cum_freq, ari_lookup_bit_fx); + static const UWord16 cum_freq[3] = { 16384, 8192, 0 }; + return ari_decode_14bits_ext_fx( st, s, cum_freq, ari_lookup_bit_fx ); } -static Word16 ari_lookup_pow_fx(Tastat *s, Word16 base) +static Word16 ari_lookup_pow_fx( Tastat *s, Word16 base ) { Word32 cum, range; Word16 symbol; Word16 range_h, range_l; - Word16 pows[12]; /* "base" to the power of 2, 4, 8,... 2^12 */ + Word16 pows[12]; /* "base" to the power of 2, 4, 8,... 2^12 */ Word16 lowlim, highlim, testval; Word16 k; - range = L_sub(s->high, s->low); - cum = L_add(L_shl(L_sub(s->value, s->low), stat_bitsnew), sub(shl(1,stat_bitsnew),1)); + range = L_sub( s->high, s->low ); + cum = L_add( L_shl( L_sub( s->value, s->low ), stat_bitsnew ), sub( shl( 1, stat_bitsnew ), 1 ) ); - range_h = extract_l(L_shr(range,15)); - range_l = extract_l(L_and(range,0x7FFF)); + range_h = extract_l( L_shr( range, 15 ) ); + range_l = extract_l( L_and( range, 0x7FFF ) ); symbol = 0; move16(); - lowlim = shr(base, 1); + lowlim = shr( base, 1 ); highlim = 16384; move16(); /* search for the interval where "cum" fits */ - IF (GT_32(L_multi31x16_X2(range_h, range_l, lowlim), cum)) /* below pow-1 */ + IF( GT_32( L_multi31x16_X2( range_h, range_l, lowlim ), cum ) ) /* below pow-1 */ { pows[0] = base; move16(); testval = base; move16(); /* increase exponent until it is smaller than "cum" */ - FOR (k = 1; k < 12; k++) + FOR( k = 1; k < 12; k++ ) { highlim = testval; move16(); - pows[k] = mult_r(pows[k-1], pows[k-1]); + pows[k] = mult_r( pows[k - 1], pows[k - 1] ); move16(); - testval = mult_r(pows[k], base); + testval = mult_r( pows[k], base ); - IF (LE_32(L_multi31x16_X2(range_h, range_l, shr(testval, 1)), cum)) /* found! big range is [lowlim,testval], (now narrow it down) */ + IF( LE_32( L_multi31x16_X2( range_h, range_l, shr( testval, 1 ) ), cum ) ) /* found! big range is [lowlim,testval], (now narrow it down) */ { lowlim = testval; move16(); - k = sub(k, 1); - symbol = shl(1, k); + k = sub( k, 1 ); + symbol = shl( 1, k ); BREAK; } } - assert(k < 12); /* maximum 2^10-1*/ + assert( k < 12 ); /* maximum 2^10-1*/ /* narrow the range down */ - FOR (k = sub(k, 2); k >= 0; k--) + FOR( k = sub( k, 2 ); k >= 0; k-- ) { - testval = mult_r(highlim, pows[k+1]); + testval = mult_r( highlim, pows[k + 1] ); - IF (LE_32(L_multi31x16_X2(range_h, range_l, shr(testval, 1)), cum)) + IF( LE_32( L_multi31x16_X2( range_h, range_l, shr( testval, 1 ) ), cum ) ) { lowlim = testval; move16(); - symbol = sub(symbol, shl(1, k)); + symbol = sub( symbol, shl( 1, k ) ); } ELSE { @@ -415,41 +409,41 @@ static Word16 ari_lookup_pow_fx(Tastat *s, Word16 base) } } - highlim = shr(highlim, 1); - lowlim = shr(lowlim, 1); + highlim = shr( highlim, 1 ); + lowlim = shr( lowlim, 1 ); } - s->high = L_add(s->low, mul_sbc_14bits(range, highlim)); + s->high = L_add( s->low, mul_sbc_14bits( range, highlim ) ); move32(); - s->low = L_add(s->low, mul_sbc_14bits(range, lowlim)); + s->low = L_add( s->low, mul_sbc_14bits( range, lowlim ) ); move32(); return symbol; } -static Word16 ari_lookup_sign_fx(Tastat *s, Word16 base) +static Word16 ari_lookup_sign_fx( Tastat *s, Word16 base ) { Word32 cum, range; Word16 symbol; - (void)base; + (void) base; - range = L_sub(s->high, s->low); - cum = L_sub(s->value, s->low); - range = L_shr(range, 1); + range = L_sub( s->high, s->low ); + cum = L_sub( s->value, s->low ); + range = L_shr( range, 1 ); - IF (GT_32(range, cum)) + IF( GT_32( range, cum ) ) { symbol = 1; move16(); - s->high = L_add(s->low, range); + s->high = L_add( s->low, range ); move32(); } ELSE { symbol = 0; move16(); - s->low = L_add(s->low, range); + s->low = L_add( s->low, range ); move32(); } @@ -463,44 +457,43 @@ static Word16 ari_decode_14bits_notbl_fx( Word16 *res, Tastat *s, Word16 base, - Word16 (*lookup_fn)(Tastat *s, Word16 base) -) + Word16 ( *lookup_fn )( Tastat *s, Word16 base ) ) { Word16 symbol; Word32 low, high, value; - symbol = lookup_fn(s, base); + symbol = lookup_fn( s, base ); - low = L_add(s->low, 0); - high = L_add(s->high, 0); - value = L_add(s->value, 0); + low = L_add( s->low, 0 ); + high = L_add( s->high, 0 ); + value = L_add( s->value, 0 ); - FOR (; bplow,low))&&(EQ_32(s->high,L_sub(high,1)))&&(EQ_32(s->value,value))))) + IF( ( lookup_fn != ari_lookup_sign_fx ) && !( NE_16( bp, bits ) || !( ( EQ_32( s->low, low ) ) && ( EQ_32( s->high, L_sub( high, 1 ) ) ) && ( EQ_32( s->value, value ) ) ) ) ) { /* This should not happen except of bit errors. */ s->high = 0; @@ -535,9 +528,9 @@ static Word16 ari_decode_14bits_notbl_fx( * p(x = q>0) = exp(- (q-0.5)*base* 2) - exp(- (q+0.5)*base*2 ) * *-------------------------------------------------------------------------*/ -Word16 ari_decode_14bits_pow_fx(Word16 *ptr, Word16 bp, Word16 bits, Word16 *res, Tastat *s, Word16 base) +Word16 ari_decode_14bits_pow_fx( Word16 *ptr, Word16 bp, Word16 bits, Word16 *res, Tastat *s, Word16 base ) { - return ari_decode_14bits_notbl_fx(ptr, bp, bits, res, s, base, ari_lookup_pow_fx); + return ari_decode_14bits_notbl_fx( ptr, bp, bits, res, s, base, ari_lookup_pow_fx ); } /*------------------------------------------------------------------------ @@ -545,8 +538,7 @@ Word16 ari_decode_14bits_pow_fx(Word16 *ptr, Word16 bp, Word16 bits, Word16 *res * * Decode a sign with equal probabilities. *-------------------------------------------------------------------------*/ -Word16 ari_decode_14bits_sign_fx(Word16 *ptr, Word16 bp, Word16 bits, Word16 *res, Tastat *s) +Word16 ari_decode_14bits_sign_fx( Word16 *ptr, Word16 bp, Word16 bits, Word16 *res, Tastat *s ) { - return ari_decode_14bits_notbl_fx(ptr, bp, bits, res, s, 0, ari_lookup_sign_fx); + return ari_decode_14bits_notbl_fx( ptr, bp, bits, res, s, 0, ari_lookup_sign_fx ); } - diff --git a/lib_dec/ari_hm_dec.c b/lib_dec/ari_hm_dec.c index 0072f3c69..0cf43fd5d 100644 --- a/lib_dec/ari_hm_dec.c +++ b/lib_dec/ari_hm_dec.c @@ -81,37 +81,37 @@ int16_t DecodeIndex( #ifdef IVAS_FLOAT_FIXED Word16 DecodeIndex_fx( - Decoder_State *st, - const Word16 Bandwidth, - Word16 *PeriodicityIndex) + Decoder_State *st, + const Word16 Bandwidth, + Word16 *PeriodicityIndex ) { - TCX_LTP_DEC_HANDLE hTcxLtpDec; - TCX_DEC_HANDLE hTcxDec; + TCX_LTP_DEC_HANDLE hTcxLtpDec; + TCX_DEC_HANDLE hTcxDec; - hTcxLtpDec = st->hTcxLtpDec; - hTcxDec = st->hTcxDec; + hTcxLtpDec = st->hTcxLtpDec; + hTcxDec = st->hTcxDec; - test(); - IF((hTcxDec->tcx_hm_LtpPitchLag > 0) && GT_16(hTcxLtpDec->tcxltp_gain, kLtpHmGainThr)) - { - Word16 LtpPitchIndex = sub(mult_r(hTcxDec->tcx_hm_LtpPitchLag, 1 << (15 - kLtpHmFractionalResolution)), 2); + test(); + IF( ( hTcxDec->tcx_hm_LtpPitchLag > 0 ) && GT_16( hTcxLtpDec->tcxltp_gain, kLtpHmGainThr ) ) + { + Word16 LtpPitchIndex = sub( mult_r( hTcxDec->tcx_hm_LtpPitchLag, 1 << ( 15 - kLtpHmFractionalResolution ) ), 2 ); - *PeriodicityIndex = kLtpHmFlag; - move16(); - *PeriodicityIndex = s_or(*PeriodicityIndex, get_next_indice_fx(st, NumRatioBits[Bandwidth][LtpPitchIndex])); - *PeriodicityIndex = add(*PeriodicityIndex, 1); - move16(); - *PeriodicityIndex = s_or(*PeriodicityIndex, shl(LtpPitchIndex, 9)); - move16(); + *PeriodicityIndex = kLtpHmFlag; + move16(); + *PeriodicityIndex = s_or( *PeriodicityIndex, get_next_indice_fx( st, NumRatioBits[Bandwidth][LtpPitchIndex] ) ); + *PeriodicityIndex = add( *PeriodicityIndex, 1 ); + move16(); + *PeriodicityIndex = s_or( *PeriodicityIndex, shl( LtpPitchIndex, 9 ) ); + move16(); - return NumRatioBits[Bandwidth][LtpPitchIndex]; - } - ELSE - { - *PeriodicityIndex = get_next_indice_fx(st, 8); - move16(); - return 8; - } + return NumRatioBits[Bandwidth][LtpPitchIndex]; + } + ELSE + { + *PeriodicityIndex = get_next_indice_fx( st, 8 ); + move16(); + return 8; + } } #endif @@ -143,17 +143,17 @@ static int16_t tcx_hm_dequantize_gain( static Word16 tcx_hm_dequantize_gain_fx( - Word16 coder_type, /* i : coder type Q0 */ - Word16 gain_idx, /* i: quantization index Q0 */ - Word16 *gain /* o: dequantized gain Q11 */ + Word16 coder_type, /* i : coder type Q0 */ + Word16 gain_idx, /* i: quantization index Q0 */ + Word16 *gain /* o: dequantized gain Q11 */ ) { - assert(0 <= coder_type && coder_type <= UNVOICED); + assert( 0 <= coder_type && coder_type <= UNVOICED ); /* safety check in case of bit errors */ test(); - IF(!(0 <= gain_idx && LT_16(gain_idx, (1 << kTcxHmNumGainBits)))) + IF( !( 0 <= gain_idx && LT_16( gain_idx, ( 1 << kTcxHmNumGainBits ) ) ) ) { *gain = 0; return 1; @@ -250,10 +250,10 @@ void tcx_hm_decode( *hm_bits = 0; move16(); - L_frame_m_256 = sub(L_frame, 256); + L_frame_m_256 = sub( L_frame, 256 ); test(); - IF(!(EQ_16(coder_type, VOICED) || EQ_16(coder_type, GENERIC))) + IF( !( EQ_16( coder_type, VOICED ) || EQ_16( coder_type, GENERIC ) ) ) { /* A bit error was encountered */ *hm_bits = -1; @@ -261,27 +261,27 @@ void tcx_hm_decode( return; } - NumTargetBits = CountIndexBits_fx((L_frame_m_256 >= 0), prm_hm[1]); + NumTargetBits = CountIndexBits_fx( ( L_frame_m_256 >= 0 ), prm_hm[1] ); - NumTargetBits = add(NumTargetBits, targetBits); + NumTargetBits = add( NumTargetBits, targetBits ); - if (EQ_16(coder_type, VOICED)) + if ( EQ_16( coder_type, VOICED ) ) { - NumTargetBits = add(NumTargetBits, kTcxHmNumGainBits); + NumTargetBits = add( NumTargetBits, kTcxHmNumGainBits ); } - *hm_bits = add(sub(NumTargetBits, targetBits), 1); + *hm_bits = add( sub( NumTargetBits, targetBits ), 1 ); move16(); /* Convert the index to lag */ - UnmapIndex_fx(prm_hm[1], (L_frame_m_256 >= 0), LtpPitchLag, - ((LE_16(NumTargetBits, kSmallerLagsTargetBitsThreshold)) || (L_frame_m_256 < 0)), - &fract_res, &lag); + UnmapIndex_fx( prm_hm[1], ( L_frame_m_256 >= 0 ), LtpPitchLag, + ( ( LE_16( NumTargetBits, kSmallerLagsTargetBitsThreshold ) ) || ( L_frame_m_256 < 0 ) ), + &fract_res, &lag ); test(); test(); /* Render the harmonic model */ - IF(tcx_hm_render_fx(lag, fract_res, p)) + IF( tcx_hm_render_fx( lag, fract_res, p ) ) { /* A bit error was encountered */ *hm_bits = -1; @@ -290,14 +290,14 @@ void tcx_hm_decode( } /* Dequantize gain */ - IF(tcx_hm_dequantize_gain_fx((Word16)EQ_16(coder_type, VOICED), prm_hm[2], &gain)) + IF( tcx_hm_dequantize_gain_fx( (Word16) EQ_16( coder_type, VOICED ), prm_hm[2], &gain ) ) { /* A bit error was encountered */ *hm_bits = -1; return; } - tcx_hm_modify_envelope_fx(gain, lag, fract_res, p, env, L_frame); + tcx_hm_modify_envelope_fx( gain, lag, fract_res, p, env, L_frame ); return; diff --git a/lib_dec/arith_coder_dec.c b/lib_dec/arith_coder_dec.c index 5cb38bf24..ee19c765d 100644 --- a/lib_dec/arith_coder_dec.c +++ b/lib_dec/arith_coder_dec.c @@ -134,19 +134,19 @@ static Word16 tcx_arith_decode_ivas_fx( Tastat as; UWord16 exp_k; Word16 tmp; - //Word32 L_tmp; + // Word32 L_tmp; bp = ari_start_decoding_14bits_prm_ivas_fx( prm, 0, &as ); - tmp = sub(envelope_e, 1); + tmp = sub( envelope_e, 1 ); - //L_tmp = L_deposit_l(0); + // L_tmp = L_deposit_l(0); - FOR (k = 0; k < L_frame; k++) + FOR( k = 0; k < L_frame; k++ ) { - IF( envelope[k] == 0 ) /* safety check in case of bit errors */ + IF( envelope[k] == 0 ) /* safety check in case of bit errors */ { - set32_fx(q_spectrum, 0, L_frame); + set32_fx( q_spectrum, 0, L_frame ); return -1; } ELSE @@ -157,33 +157,33 @@ static Word16 tcx_arith_decode_ivas_fx( /* decode line magnitude */ bp = ari_decode_14bits_pow_ivas( prm, bp, target_bits, &q, &as, exp_k ); - IF ( q != 0 ) + IF( q != 0 ) { /* line is non-zero, decode sign */ bp = ari_decode_14bits_sign_ivas( prm, bp, target_bits, &s, &as ); - q_spectrum[k] = L_mult(q, sub(3, shl(s, 1))); - q_spectrum[k] = L_shl(q_spectrum[k], 30 - SPEC_EXP_DEC); + q_spectrum[k] = L_mult( q, sub( 3, shl( s, 1 ) ) ); + q_spectrum[k] = L_shl( q_spectrum[k], 30 - SPEC_EXP_DEC ); } ELSE { /* line is zero, no sign needed */ - q_spectrum[k] = L_deposit_l(0); + q_spectrum[k] = L_deposit_l( 0 ); } - IF (LE_32(as.high, as.low)) + IF( LE_32( as.high, as.low ) ) { - IF ( LT_16(bp, target_bits) ) /* safety check in case of bit errors */ + IF( LT_16( bp, target_bits ) ) /* safety check in case of bit errors */ { bp = -1; move16(); } - BREAK; /* no bits left, so exit loop */ + BREAK; /* no bits left, so exit loop */ } } *q_spectrum_e = SPEC_EXP_DEC; move16(); - set32_fx(q_spectrum + k, 0, sub(L_frame, k)); + set32_fx( q_spectrum + k, 0, sub( L_frame, k ) ); return bp; } @@ -242,7 +242,7 @@ void tcx_arith_decode_envelope( gamma_uw = 1.0f / st->gamma_float; #define WMC_TOOL_SKIP - tcx_arith_render_envelope_flt( A_ind, L_frame, L_spec, FL2WORD16( hTcxCfg->preemph_fac_flt), FL2WORD16( gamma_w ), FL2WORD16( 0.5f * gamma_uw ), env ); + tcx_arith_render_envelope_flt( A_ind, L_frame, L_spec, FL2WORD16( hTcxCfg->preemph_fac_flt ), FL2WORD16( gamma_w ), FL2WORD16( 0.5f * gamma_uw ), env ); #undef WMC_TOOL_SKIP if ( use_hm ) @@ -322,10 +322,10 @@ void tcx_arith_decode_envelope_ivas_fx( Word16 gamma_w, gamma_uw; Word16 hm_bits; - IF(GT_16(L_spec, N_MAX_ARI) || (EQ_16(st->element_mode, EVS_MONO) && GT_16(target_bits, (ACELP_13k20 / FRAMES_PER_SEC))) || - (EQ_16(st->element_mode, IVAS_SCE) && (GT_16(st->bits_frame_nominal, (LPC_SHAPED_ARI_MAX_RATE / FRAMES_PER_SEC)))) || - (GT_16(st->element_mode, IVAS_SCE) && (GT_16(st->bits_frame_nominal, (LPC_SHAPED_ARI_MAX_RATE_CPE / FRAMES_PER_SEC)))) || - (target_bits <= 0)) + IF( GT_16( L_spec, N_MAX_ARI ) || ( EQ_16( st->element_mode, EVS_MONO ) && GT_16( target_bits, ( ACELP_13k20 / FRAMES_PER_SEC ) ) ) || + ( EQ_16( st->element_mode, IVAS_SCE ) && ( GT_16( st->bits_frame_nominal, ( LPC_SHAPED_ARI_MAX_RATE / FRAMES_PER_SEC ) ) ) ) || + ( GT_16( st->element_mode, IVAS_SCE ) && ( GT_16( st->bits_frame_nominal, ( LPC_SHAPED_ARI_MAX_RATE_CPE / FRAMES_PER_SEC ) ) ) ) || + ( target_bits <= 0 ) ) { /* this could happen in case of bit errors */ st->BER_detect = 1; @@ -355,13 +355,13 @@ void tcx_arith_decode_envelope_ivas_fx( tcx_arith_render_envelope_flt( A_ind, L_frame, L_spec, hTcxCfg->preemph_fac, gamma_w, gamma_uw, env ); #undef WMC_TOOL_SKIP - IF (use_hm != 0) + IF( use_hm != 0 ) { - IF (prm_hm[0] != 0) + IF( prm_hm[0] != 0 ) { - tcx_hm_decode( L_spec, env, target_bits, st->coder_type, prm_hm, tcxltp_pitch, &hm_bits ); + tcx_hm_decode( L_spec, env, target_bits, st->coder_type, prm_hm, tcxltp_pitch, &hm_bits ); - IF (hm_bits < 0) + IF( hm_bits < 0 ) { st->BER_detect = 1; move16(); @@ -379,7 +379,7 @@ void tcx_arith_decode_envelope_ivas_fx( hm_bits = 1; move16(); } - *signaling_bits = add(*signaling_bits, hm_bits); + *signaling_bits = add( *signaling_bits, hm_bits ); move16(); } @@ -397,14 +397,14 @@ void tcx_arith_decode_envelope_ivas_fx( move16(); /* safety check in case of bit errors */ - IF ( *arith_bits < 0 ) + IF( *arith_bits < 0 ) { st->BER_detect = 1; move16(); set32_fx( q_spectrum, 0, L_frame ); } - set32_fx(q_spectrum + L_spec, 0, sub(L_frame, L_spec)); + set32_fx( q_spectrum + L_spec, 0, sub( L_frame, L_spec ) ); return; } diff --git a/lib_dec/arith_coder_dec_fx.c b/lib_dec/arith_coder_dec_fx.c index 475f87572..b338cc3e0 100644 --- a/lib_dec/arith_coder_dec_fx.c +++ b/lib_dec/arith_coder_dec_fx.c @@ -13,14 +13,14 @@ /* Returns: number of bits consumed */ #ifdef IVAS_FLOAT_FIXED static Word16 tcx_arith_decode_fx( - Word16 L_frame, /* i: number of spectral lines Q0 */ - const Word16 envelope[], /* i: scaled envelope Q15-e */ - Word16 envelope_e, /* i: scaled envelope exponent Q0 */ - Word16 target_bits, /* i: target bit budget Q0 */ - Word16 prm[], /* i: bit-stream Q0 */ - Word32 q_spectrum[], /* o: scalar quantized spectrum Q31-e */ - Word16 *q_spectrum_e, /* o: spectrum exponent Q0 */ - Word16 *nf_seed /* o: noise filling seed Q0 */ + Word16 L_frame, /* i: number of spectral lines Q0 */ + const Word16 envelope[], /* i: scaled envelope Q15-e */ + Word16 envelope_e, /* i: scaled envelope exponent Q0 */ + Word16 target_bits, /* i: target bit budget Q0 */ + Word16 prm[], /* i: bit-stream Q0 */ + Word32 q_spectrum[], /* o: scalar quantized spectrum Q31-e */ + Word16 *q_spectrum_e, /* o: spectrum exponent Q0 */ + Word16 *nf_seed /* o: noise filling seed Q0 */ ) { Word16 bp, k, q, s; @@ -34,61 +34,62 @@ static Word16 tcx_arith_decode_fx( #endif - bp = ari_start_decoding_14bits_prm_fx(prm, 0, &as); + bp = ari_start_decoding_14bits_prm_fx( prm, 0, &as ); - tmp = sub(envelope_e, 1+15); - L_tmp = L_deposit_l(0); - FOR (k = 0; k < L_frame; k++) + tmp = sub( envelope_e, 1 + 15 ); + L_tmp = L_deposit_l( 0 ); + FOR( k = 0; k < L_frame; k++ ) { - IF( envelope[k] == 0 ) /* safety check in case of bit errors */ + IF( envelope[k] == 0 ) /* safety check in case of bit errors */ { - set32_fx(q_spectrum, 0, L_frame); + set32_fx( q_spectrum, 0, L_frame ); return -1; } ELSE { - exp_k = round_fx(expfp(envelope[k], tmp)); + exp_k = round_fx( expfp( envelope[k], tmp ) ); } /* decode line magnitude */ - bp = ari_decode_14bits_pow_fx(prm, bp, target_bits, &q, &as, exp_k); + bp = ari_decode_14bits_pow_fx( prm, bp, target_bits, &q, &as, exp_k ); - if (q == 0) + if ( q == 0 ) { - q_spectrum[k] = L_deposit_l(0); + q_spectrum[k] = L_deposit_l( 0 ); } - IF (q != 0) /* line is non-zero, decode sign */ + IF( q != 0 ) /* line is non-zero, decode sign */ { - bp = ari_decode_14bits_sign_fx(prm, bp, target_bits, &s, &as); + bp = ari_decode_14bits_sign_fx( prm, bp, target_bits, &s, &as ); #ifdef BASOP_NOGLOB - L_tmp = L_macNs_co(L_tmp, q, k, &Carry, &Overflow); + L_tmp = L_macNs_co( L_tmp, q, k, &Carry, &Overflow ); #else - L_tmp = L_macNs(L_tmp, q, k); + L_tmp = L_macNs( L_tmp, q, k ); #endif - Q = L_mult(q, -(1<<(30 - SPEC_EXP_DEC))); - if (s == 0) Q = L_mult(q, 1 << (30 - SPEC_EXP_DEC)); + Q = L_mult( q, -( 1 << ( 30 - SPEC_EXP_DEC ) ) ); + if ( s == 0 ) + Q = L_mult( q, 1 << ( 30 - SPEC_EXP_DEC ) ); q_spectrum[k] = Q; move32(); } - IF (ari_decode_overflow_fx(&as)) + IF( ari_decode_overflow_fx( &as ) ) { - if( LT_16(bp, target_bits)) /* safety check in case of bit errors */ + if ( LT_16( bp, target_bits ) ) /* safety check in case of bit errors */ { bp = -1; move16(); } - BREAK; /* no bits left, so exit loop */ + BREAK; /* no bits left, so exit loop */ } } *q_spectrum_e = SPEC_EXP_DEC; move16(); - set32_fx(q_spectrum+k, 0, sub(L_frame, k)); + set32_fx( q_spectrum + k, 0, sub( L_frame, k ) ); /* noise filling seed */ - *nf_seed = extract_l(L_tmp); + *nf_seed = extract_l( L_tmp ); return bp; @@ -97,28 +98,29 @@ static Word16 tcx_arith_decode_fx( #ifdef IVAS_FLOAT_FIXED void tcx_arith_decode_envelope_fx( - Word32 q_spectrum[], /* o: quantised MDCT coefficients Q31-e */ - Word16 *q_spectrum_e, /* o: MDCT exponent Q0 */ - Word16 L_frame, /* i: frame or MDCT length Q0 */ - Word16 L_spec, /* i: length w/o BW limitation Q0 */ + Word32 q_spectrum[], /* o: quantised MDCT coefficients Q31-e */ + Word16 *q_spectrum_e, /* o: MDCT exponent Q0 */ + Word16 L_frame, /* i: frame or MDCT length Q0 */ + Word16 L_spec, /* i: length w/o BW limitation Q0 */ Decoder_State *st, - const Word16 A_ind[], /* i: quantised LPC coefficients Q12 */ - Word16 target_bits, /* i: number of available bits Q0 */ - Word16 prm[], /* i: bitstream parameters Q0 */ - Word8 use_hm, /* i: use HM in current frame? */ - Word16 prm_hm[], /* i: HM parameter area Q0 */ - Word16 tcxltp_pitch, /* i: TCX LTP pitch in FD, -1 if n/a Q0*/ - Word16 *arith_bits, /* o: bits used for ari. coding Q0 */ - Word16 *signaling_bits, /* o: bits used for signaling Q0 */ - Word16 *nf_seed /* o: noise filling seed Q0 */ - ,Word16 low_complexity /* i: low-complexity flag Q0 */ + const Word16 A_ind[], /* i: quantised LPC coefficients Q12 */ + Word16 target_bits, /* i: number of available bits Q0 */ + Word16 prm[], /* i: bitstream parameters Q0 */ + Word8 use_hm, /* i: use HM in current frame? */ + Word16 prm_hm[], /* i: HM parameter area Q0 */ + Word16 tcxltp_pitch, /* i: TCX LTP pitch in FD, -1 if n/a Q0*/ + Word16 *arith_bits, /* o: bits used for ari. coding Q0 */ + Word16 *signaling_bits, /* o: bits used for signaling Q0 */ + Word16 *nf_seed /* o: noise filling seed Q0 */ + , + Word16 low_complexity /* i: low-complexity flag Q0 */ ) { - Word32 env[N_MAX_ARI]; /* unscaled envelope */ - Word16 *envelope; /* scaled envelope */ + Word32 env[N_MAX_ARI]; /* unscaled envelope */ + Word16 *envelope; /* scaled envelope */ Word16 envelope_e; Word16 L_spec_core; - TCX_CONFIG_HANDLE tcx_cfg; + TCX_CONFIG_HANDLE tcx_cfg; Word16 gamma_w, gamma_uw; Word16 hm_bits; tcx_cfg = st->hTcxCfg; @@ -126,10 +128,10 @@ void tcx_arith_decode_envelope_fx( test(); test(); - IF( GT_16(L_spec,N_MAX_ARI)|| (EQ_16(st->element_mode, EVS_MONO) && GT_16(target_bits,(ACELP_13k20/ FRAMES_PER_SEC))) || - (EQ_16(st->element_mode, IVAS_SCE) && (GT_16(st->bits_frame_nominal, (LPC_SHAPED_ARI_MAX_RATE / FRAMES_PER_SEC)))) || - (GT_16(st->element_mode, IVAS_SCE) && (GT_16(st->bits_frame_nominal, (LPC_SHAPED_ARI_MAX_RATE_CPE / FRAMES_PER_SEC)))) || - (target_bits <= 0)) + IF( GT_16( L_spec, N_MAX_ARI ) || ( EQ_16( st->element_mode, EVS_MONO ) && GT_16( target_bits, ( ACELP_13k20 / FRAMES_PER_SEC ) ) ) || + ( EQ_16( st->element_mode, IVAS_SCE ) && ( GT_16( st->bits_frame_nominal, ( LPC_SHAPED_ARI_MAX_RATE / FRAMES_PER_SEC ) ) ) ) || + ( GT_16( st->element_mode, IVAS_SCE ) && ( GT_16( st->bits_frame_nominal, ( LPC_SHAPED_ARI_MAX_RATE_CPE / FRAMES_PER_SEC ) ) ) ) || + ( target_bits <= 0 ) ) { /* this could happen in case of bit errors */ st->BER_detect = 1; @@ -148,22 +150,22 @@ void tcx_arith_decode_envelope_fx( *signaling_bits = 0; move16(); - assert(st->hTcxDec->enableTcxLpc); + assert( st->hTcxDec->enableTcxLpc ); - gamma_w = 32767/*1.0f Q15*/; + gamma_w = 32767 /*1.0f Q15*/; move16(); gamma_uw = st->inv_gamma; move16(); - tcx_arith_render_envelope(A_ind, L_frame, L_spec, tcx_cfg->preemph_fac, gamma_w, gamma_uw, env); + tcx_arith_render_envelope( A_ind, L_frame, L_spec, tcx_cfg->preemph_fac, gamma_w, gamma_uw, env ); - IF (use_hm != 0) + IF( use_hm != 0 ) { - IF (prm_hm[0] != 0) + IF( prm_hm[0] != 0 ) { - tcx_hm_decode(L_spec, env, target_bits, tcx_cfg->coder_type, prm_hm, tcxltp_pitch, &hm_bits); + tcx_hm_decode( L_spec, env, target_bits, tcx_cfg->coder_type, prm_hm, tcxltp_pitch, &hm_bits ); - IF (hm_bits < 0) + IF( hm_bits < 0 ) { st->BER_detect = 1; move16(); @@ -180,25 +182,26 @@ void tcx_arith_decode_envelope_fx( hm_bits = 1; move16(); } - *signaling_bits = add(*signaling_bits, hm_bits); + *signaling_bits = add( *signaling_bits, hm_bits ); move16(); } ELSE { - prm_hm[0] = 0; /* just to be sure */ move16(); + prm_hm[0] = 0; /* just to be sure */ + move16(); } L_spec_core = L_spec; move16(); - if (st->igf) + if ( st->igf ) { - L_spec_core = s_min(L_spec_core, st->hIGFDec->infoIGFStartLine); + L_spec_core = s_min( L_spec_core, st->hIGFDec->infoIGFStartLine ); } - envelope = (Word16*)env; + envelope = (Word16 *) env; - tcx_arith_scale_envelope(L_spec, L_spec_core, env, target_bits, low_complexity, envelope, &envelope_e); + tcx_arith_scale_envelope( L_spec, L_spec_core, env, target_bits, low_complexity, envelope, &envelope_e ); - *arith_bits = tcx_arith_decode_fx(L_spec, envelope, envelope_e, target_bits, prm, q_spectrum, q_spectrum_e, nf_seed); + *arith_bits = tcx_arith_decode_fx( L_spec, envelope, envelope_e, target_bits, prm, q_spectrum, q_spectrum_e, nf_seed ); move16(); /* safety check in case of bit errors */ @@ -206,9 +209,9 @@ void tcx_arith_decode_envelope_fx( { st->BER_detect = 1; move16(); - set32_fx(q_spectrum, 0, L_frame); + set32_fx( q_spectrum, 0, L_frame ); } - set32_fx(q_spectrum + L_spec, 0, sub(L_frame, L_spec)); + set32_fx( q_spectrum + L_spec, 0, sub( L_frame, L_spec ) ); } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/avq_dec.c b/lib_dec/avq_dec.c index 10cd09cd7..c92a899d9 100644 --- a/lib_dec/avq_dec.c +++ b/lib_dec/avq_dec.c @@ -55,7 +55,7 @@ static void read_cv( Decoder_State *st, uint16_t *I, int16_t *kv, int16_t nq, in * split algebraic vector dequantizer based on RE8 latice. *-----------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED +#ifndef IVAS_FLOAT_FIXED void AVQ_demuxdec( Decoder_State *st, /* i/o: decoder state structure */ int16_t xriq[], /* o : decoded subvectors [0..8*Nsv-1]*/ @@ -425,4 +425,4 @@ static void read_cv( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/avq_dec_fx.c b/lib_dec/avq_dec_fx.c index 9f0d0416b..e768e1ffd 100644 --- a/lib_dec/avq_dec_fx.c +++ b/lib_dec/avq_dec_fx.c @@ -4,12 +4,12 @@ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ /*-------------------------------------------------------------------* * Local prototypes @@ -287,80 +287,81 @@ void AVQ_demuxdec_fx( #ifdef IVAS_FLOAT_FIXED void AVQ_dec_lpc( - Word16 *indx, /* input: index[] (4 bits per words) */ - Word16 *nvecq, /* output: vector quantized */ - Word16 Nsv /* input: number of subvectors (lg=Nsv*8) */ + Word16 *indx, /* input: index[] (4 bits per words) */ + Word16 *nvecq, /* output: vector quantized */ + Word16 Nsv /* input: number of subvectors (lg=Nsv*8) */ ) { - Word16 i, l, n, nq, nk, pos, ival, c[8], kv[8]; - Word32 I; + Word16 i, l, n, nq, nk, pos, ival, c[8], kv[8]; + Word32 I; UWord16 I16; /* last index word */ - pos = sub(Nsv, 1); + pos = sub( Nsv, 1 ); - FOR (l=0; l < Nsv; l++) + FOR( l = 0; l < Nsv; l++ ) { - pos = add(pos, indx[l]); + pos = add( pos, indx[l] ); } /* decode all subvectors */ - FOR (l=Nsv-1; l>=0; l--) + FOR( l = Nsv - 1; l >= 0; l-- ) { - nq = indx[l]; /* quantizer number (0,2,3..n) */ move16(); + nq = indx[l]; /* quantizer number (0,2,3..n) */ + move16(); nk = 0; move16(); n = nq; move16(); - IF (GT_16(nq, 4)) + IF( GT_16( nq, 4 ) ) { - nk = shr(sub(nq, 3), 1); - n = sub(nq, shl(nk, 1)); + nk = shr( sub( nq, 3 ), 1 ); + n = sub( nq, shl( nk, 1 ) ); } /* read n groups of 4-bit for Voronoi index (k[]) */ - FOR (i=0; i<8; i++) + FOR( i = 0; i < 8; i++ ) { kv[i] = 0; move16(); } - FOR ( ; nk > 0; nk--) + FOR( ; nk > 0; nk-- ) { - ival = s_and(indx[pos--], 0x0F); - ival = shl(ival, 4); - ival = add(ival, s_and(indx[pos--], 0x0F)); + ival = s_and( indx[pos--], 0x0F ); + ival = shl( ival, 4 ); + ival = add( ival, s_and( indx[pos--], 0x0F ) ); - FOR (i=7; i>=0; i--) + FOR( i = 7; i >= 0; i-- ) { - kv[i] = shl(kv[i], 1); - kv[i] = add(kv[i], s_and(ival, 0x01)); + kv[i] = shl( kv[i], 1 ); + kv[i] = add( kv[i], s_and( ival, 0x01 ) ); move16(); - ival = shr(ival, 1); + ival = shr( ival, 1 ); } } /* read n groups of 4-bit for base codebook index (I) */ - I = L_deposit_l(0); - FOR (; n > 0; n--) + I = L_deposit_l( 0 ); + FOR( ; n > 0; n-- ) { - I = L_shl(I, 4); - I = L_add(I, (Word32) s_and(indx[pos--], 0x0F)); + I = L_shl( I, 4 ); + I = L_add( I, (Word32) s_and( indx[pos--], 0x0F ) ); } /* multi-rate RE8 decoder */ - I16 = (UWord16)extract_l(I); + I16 = (UWord16) extract_l( I ); cast16(); - re8_dec_fx(nq, I16, kv, c); + re8_dec_fx( nq, I16, kv, c ); /* write decoded RE8 vector */ - FOR (i=0; i<8; i++) + FOR( i = 0; i < 8; i++ ) { - nvecq[(l*8)+i] = c[i]; + nvecq[( l * 8 ) + i] = c[i]; move16(); } } @@ -427,4 +428,4 @@ static void read_cv_fx( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/bass_psfilter.c b/lib_dec/bass_psfilter.c index a58000d62..48d136367 100644 --- a/lib_dec/bass_psfilter.c +++ b/lib_dec/bass_psfilter.c @@ -57,8 +57,8 @@ #define NBPSF_L_EXTRA 120 #define BPF_STOP_STOPBAND_16 16 -#define K_PC_DEC -0.0357f /* <45, 17> */ -#define C_PC_DEC 1.6071f +#define K_PC_DEC -0.0357f /* <45, 17> */ +#define C_PC_DEC 1.6071f #define K_PC_DEC_FX -1170 /* -0.0357f in Q15 */ #define K_PC_DEC_FX32 -76665166 /* -0.0357f in Q31 */ #define C_PC_DEC_FX 6583 /*in Q8*/ @@ -599,7 +599,7 @@ void addBassPostFilter_ivas_fx( int16_t res_bpf_adapt( STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: DFT stereo decoder handle */ const float *bpf_error_signal_8k, /* i : BPF modification signal */ - float res_buf[STEREO_DFT_N_8k] /* i : residual buffer */ + float res_buf[STEREO_DFT_N_8k] /* i : residual buffer */ ) { float error_nrg; @@ -646,7 +646,7 @@ int16_t res_bpf_adapt( error_nrg *= 0.2f; /* Division by 5 for average value */ bpf_error_ratio = min( 2, error_nrg / res_hb_nrg ); /* Form decision variable and apply limit */ bpf_error_ratio = STEREO_DFT_BPF_ADAPT_BETA * bpf_error_ratio + ( 1 - STEREO_DFT_BPF_ADAPT_BETA ) * hStereoDft->bpf_error_ratio_mem; - //printf("\n%f\n", bpf_error_ratio); + // printf("\n%f\n", bpf_error_ratio); hStereoDft->bpf_error_ratio_mem = bpf_error_ratio; res_bpf_flag = bpf_error_ratio < 1; @@ -836,11 +836,11 @@ void bpf_pitch_coherence_ivas_fx( IF( LT_32( L_add( pcn1, L_add( pcn2, pcn3 ) ), 10240 ) ) { st->hBPF->psf_att_fx = 13107; /*Q15*/ - //st->hBPF->psf_att = 0.4f; + // st->hBPF->psf_att = 0.4f; set16_fx( &st->hBPF->Track_on_hist[L_TRACK_HIST - nb_subfr], 1, nb_subfr ); } } return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/bass_psfilter_fx.c b/lib_dec/bass_psfilter_fx.c index 95bece13e..0c70d5b78 100644 --- a/lib_dec/bass_psfilter_fx.c +++ b/lib_dec/bass_psfilter_fx.c @@ -4,9 +4,9 @@ #include #include -#include "options.h" /* Compilation switches */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ #include "cnst.h" /* Common constants */ #include "rom_com.h" /* Static table prototypes */ #include "rom_dec.h" /* Static table prototypes */ @@ -16,14 +16,14 @@ * Local constants *---------------------------------------------------------------------*/ -#define NBPSF_L_EXTRA 120 -#define BPF_STOP_STOPBAND_16 16 +#define NBPSF_L_EXTRA 120 +#define BPF_STOP_STOPBAND_16 16 /*---------------------------------------------------------------------* * Local function prototypes *---------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -static Word16 Pit_track_fx(Word16 syn[], Word16 T); +static Word16 Pit_track_fx( Word16 syn[], Word16 T ); #endif /*---------------------------------------------------------------------* @@ -40,11 +40,11 @@ void bass_psfilter_init_fx( hBPF->pst_mem_deemp_err_fx = 0; move16(); hBPF->pst_lp_ener_fx = 0; - move16();/*0 in Q8 */ - set16_fx(hBPF->pst_old_syn_fx, 0, NBPSF_PIT_MAX); - set16_fx(hBPF->Track_on_hist, 0, L_TRACK_HIST); - set16_fx(hBPF->vibrato_hist, 0, L_TRACK_HIST); - set16_fx(hBPF->mem_mean_pit_fx, 1280, L_TRACK_HIST); /* 80 in Q4*/ + move16(); /*0 in Q8 */ + set16_fx( hBPF->pst_old_syn_fx, 0, NBPSF_PIT_MAX ); + set16_fx( hBPF->Track_on_hist, 0, L_TRACK_HIST ); + set16_fx( hBPF->vibrato_hist, 0, L_TRACK_HIST ); + set16_fx( hBPF->mem_mean_pit_fx, 1280, L_TRACK_HIST ); /* 80 in Q4*/ hBPF->psf_att_fx = 32767; return; @@ -81,24 +81,24 @@ void bass_psfilter_init_fx( #ifdef IVAS_FLOAT_FIXED void bass_psfilter_fx( - BPF_DEC_HANDLE hBPF, /* i/o: BPF data handle */ - const Word16 Opt_AMR_WB, /* i : AMR-WB IO flag */ - Word16 synth_in_fx[], /* i : input synthesis (at 16kHz) */ - const Word16 L_frame, /* i : length of the last frame */ - Word16 pitch_buf_fx[], /* i : pitch for every subfr [0,1,2,3] */ - const Word16 bpf_off, /* i : do not use BPF when set to 1 */ - Word16 v_stab_fx, /* i : stability factor */ - Word16 *v_stab_smooth_fx, /* i/o: smoothed stability factor */ - const Word16 coder_type, /* i : coder_type */ + BPF_DEC_HANDLE hBPF, /* i/o: BPF data handle */ + const Word16 Opt_AMR_WB, /* i : AMR-WB IO flag */ + Word16 synth_in_fx[], /* i : input synthesis (at 16kHz) */ + const Word16 L_frame, /* i : length of the last frame */ + Word16 pitch_buf_fx[], /* i : pitch for every subfr [0,1,2,3] */ + const Word16 bpf_off, /* i : do not use BPF when set to 1 */ + Word16 v_stab_fx, /* i : stability factor */ + Word16 *v_stab_smooth_fx, /* i/o: smoothed stability factor */ + const Word16 coder_type, /* i : coder_type */ Word16 Q_syn, - Word16 bpf_noise_buf[] /* o : BPF error signal (at int_fs) */ + Word16 bpf_noise_buf[] /* o : BPF error signal (at int_fs) */ ) { Word16 i, j, i_subfr, T, exp, exp2; Word16 tmp, gain, alpha, tmp2; Word32 Lcorr, Lener; - Word32 Lcorr0,Lener0,Ltmp; - Word16 syn_buf_fx[NBPSF_PIT_MAX+L_FRAME16k+NBPSF_PIT_MAX], *syn_fx; + Word32 Lcorr0, Lener0, Ltmp; + Word16 syn_buf_fx[NBPSF_PIT_MAX + L_FRAME16k + NBPSF_PIT_MAX], *syn_fx; Word16 syn2_buf_fx[L_FRAME16k], *syn2_fx; Word16 err[L_HALFR16k], *sigPtr, *sigPtr1; Word16 T_sf[NB_SUBFR16k]; @@ -117,13 +117,13 @@ void bass_psfilter_fx( move16(); vibrato = 0; move16(); - IF(EQ_16(L_frame, L_FRAME8k)) + IF( EQ_16( L_frame, L_FRAME8k ) ) { subfr_len = STEREO_DFT_L_SUBFR_8k; move16(); nbpsf_pit_max = STEREO_DFT_NBPSF_PIT_MAX_8k; move16(); - nb_subfr = shr(L_frame,5); + nb_subfr = shr( L_frame, 5 ); } ELSE { @@ -131,7 +131,7 @@ void bass_psfilter_fx( move16(); nbpsf_pit_max = NBPSF_PIT_MAX; move16(); - nb_subfr = shr(L_frame,6); + nb_subfr = shr( L_frame, 6 ); } move16(); @@ -146,99 +146,100 @@ void bass_psfilter_fx( * |----bpf_noise_buf------| * *-------------------------------------------------------*/ - Q_syn2x = shl(Q_syn, 1); + Q_syn2x = shl( Q_syn, 1 ); move16(); - Copy(hBPF->pst_old_syn_fx, syn_buf_fx, nbpsf_pit_max); - Copy(synth_in_fx, syn_buf_fx+nbpsf_pit_max, L_frame); + Copy( hBPF->pst_old_syn_fx, syn_buf_fx, nbpsf_pit_max ); + Copy( synth_in_fx, syn_buf_fx + nbpsf_pit_max, L_frame ); test(); - IF( !(pitch_buf_fx == NULL || bpf_off) ) + IF( !( pitch_buf_fx == NULL || bpf_off ) ) { - FOR(i = L_TRACK_HIST-1; i > 0; i--) + FOR( i = L_TRACK_HIST - 1; i > 0; i-- ) { - hBPF->mem_mean_pit_fx[i] = hBPF->mem_mean_pit_fx[i-1]; + hBPF->mem_mean_pit_fx[i] = hBPF->mem_mean_pit_fx[i - 1]; move16(); /*Q6 */ } - Ltmp = L_deposit_l(0); - FOR(j=0; j Q4*/ - if(EQ_16(nb_subfr,5)) + tmp = mult_r( tmp, 8192 ); /*divide per 4 (when L_frame == L_FRAME) -> Q4*/ + if ( EQ_16( nb_subfr, 5 ) ) { - tmp = mult_r(tmp, 26214); /* multiply by 0.8 for case where L_frame == L_FRAME16k*/ + tmp = mult_r( tmp, 26214 ); /* multiply by 0.8 for case where L_frame == L_FRAME16k*/ } - hBPF->mem_mean_pit_fx[i] = tmp; /*Q4 */ move16(); + hBPF->mem_mean_pit_fx[i] = tmp; /*Q4 */ + move16(); } - idx_pit_min = minimum_fx(hBPF->mem_mean_pit_fx, L_TRACK_HIST, &loc_pit_min); - idx_pit_max = maximum_fx(hBPF->mem_mean_pit_fx, L_TRACK_HIST, &loc_pit_max); + idx_pit_min = minimum_fx( hBPF->mem_mean_pit_fx, L_TRACK_HIST, &loc_pit_min ); + idx_pit_max = maximum_fx( hBPF->mem_mean_pit_fx, L_TRACK_HIST, &loc_pit_max ); - dist_pit_diff = abs_s(sub(idx_pit_max,idx_pit_min)); - diff_pit = sub(loc_pit_max,loc_pit_min); /*Q4 */ + dist_pit_diff = abs_s( sub( idx_pit_max, idx_pit_min ) ); + diff_pit = sub( loc_pit_max, loc_pit_min ); /*Q4 */ test(); - if( EQ_16(L_frame,L_FRAME16k) || EQ_16(L_frame, L_FRAME8k)) + if ( EQ_16( L_frame, L_FRAME16k ) || EQ_16( L_frame, L_FRAME8k ) ) { - diff_pit = mult_r(diff_pit,26214); /*Q4 */ + diff_pit = mult_r( diff_pit, 26214 ); /*Q4 */ } test(); test(); test(); - if( coder_type != INACTIVE && GE_16(diff_pit,2<<4)&<_16(diff_pit,10<<4)&&GE_16(dist_pit_diff,3)) + if ( coder_type != INACTIVE && GE_16( diff_pit, 2 << 4 ) && LT_16( diff_pit, 10 << 4 ) && GE_16( dist_pit_diff, 3 ) ) { vibrato = 1; move16(); } - tmp = sum16_fx(hBPF->Track_on_hist,L_TRACK_HIST); + tmp = sum16_fx( hBPF->Track_on_hist, L_TRACK_HIST ); #ifdef BASOP_NOGLOB - TrackOnR = round_fx_sat(L_shl_sat(L_mult0(tmp,3277),16)); /*Q15 */ + TrackOnR = round_fx_sat( L_shl_sat( L_mult0( tmp, 3277 ), 16 ) ); /*Q15 */ #else - TrackOnR = round_fx(L_shl(L_mult0(tmp,3277),16)); /*Q15 */ + TrackOnR = round_fx( L_shl( L_mult0( tmp, 3277 ), 16 ) ); /*Q15 */ #endif - vibratR = sum16_fx(hBPF->vibrato_hist,L_TRACK_HIST); /*Q0 */ + vibratR = sum16_fx( hBPF->vibrato_hist, L_TRACK_HIST ); /*Q0 */ - alp_tmp = sub(32767,TrackOnR); /*Q15 */ + alp_tmp = sub( 32767, TrackOnR ); /*Q15 */ IF( vibrato ) { /* vibratR = vibratR * vibratR * -0.009f + 1.0f;move16(); */ - tmp = round_fx(L_shl(L_mult0(vibratR,vibratR),16)); /*Q0 */ - tmp = round_fx(L_shl(L_mult(tmp,18874),9)); /*Q15 */ - vibratR = sub(32767,tmp); /*Q15 */ - alp_tmp = mult_r(alp_tmp,vibratR); /*Q15 */ + tmp = round_fx( L_shl( L_mult0( vibratR, vibratR ), 16 ) ); /*Q0 */ + tmp = round_fx( L_shl( L_mult( tmp, 18874 ), 9 ) ); /*Q15 */ + vibratR = sub( 32767, tmp ); /*Q15 */ + alp_tmp = mult_r( alp_tmp, vibratR ); /*Q15 */ } alp_tmp = s_max( 3277, alp_tmp ); - IF( GT_16(alp_tmp, hBPF->psf_att_fx)) + IF( GT_16( alp_tmp, hBPF->psf_att_fx ) ) { /**psf_att = add(mult_r(1638,alp_tmp),mult_r(31130,*psf_att)); //Q15 */ - hBPF->psf_att_fx = round_fx(L_mac(L_mult(1638,alp_tmp),31130, hBPF->psf_att_fx)); /*Q15 */ + hBPF->psf_att_fx = round_fx( L_mac( L_mult( 1638, alp_tmp ), 31130, hBPF->psf_att_fx ) ); /*Q15 */ } ELSE { /**psf_att = add(mult_r(13107,alp_tmp),mult_r(19661,*psf_att)); //Q15 */ - hBPF->psf_att_fx = round_fx(L_mac(L_mult(13107,alp_tmp),19661,hBPF->psf_att_fx)); /*Q15 */ + hBPF->psf_att_fx = round_fx( L_mac( L_mult( 13107, alp_tmp ), 19661, hBPF->psf_att_fx ) ); /*Q15 */ } test(); IF( pitch_buf_fx == NULL || bpf_off ) { /* do not use BPF for HQ core */ T_update = 80; - if (EQ_16(L_frame, L_FRAME8k)) + if ( EQ_16( L_frame, L_FRAME8k ) ) { T_update = 40; } move16(); set16_fx( T_sf, 0, 5 ); - syn_fx = &syn_buf_fx[add(nbpsf_pit_max,L_frame)]; - sigPtr = syn_fx-T_update; - FOR (i=0; i< nbpsf_pit_max; i++) + syn_fx = &syn_buf_fx[add( nbpsf_pit_max, L_frame )]; + sigPtr = syn_fx - T_update; + FOR( i = 0; i < nbpsf_pit_max; i++ ) { syn_fx[i] = sigPtr[i]; move16(); @@ -247,34 +248,34 @@ void bass_psfilter_fx( ELSE { /* extrapolation of synth_in_fx */ - FOR ( i=0; ipst_lp_ener_fx), &tmp2); /* 2786635L is Q31 : 0.1xLog2(10) / 256 (/256 because lp_ener is Q8) */ + exp2 = L_Extract_lc( Mpy_32_16_1( 2786635L, hBPF->pst_lp_ener_fx ), &tmp2 ); /* 2786635L is Q31 : 0.1xLog2(10) / 256 (/256 because lp_ener is Q8) */ /* Note: 'Ltmp' is still the absolute value of 'Lcorr' 'tmp' is still 'Ltmp' normalized and rounded to 16 bits However, exp has to be recalculated because it is affected by exp = sub(exp, 1) before the div_s */ - exp = norm_l(Ltmp); - tmp2 = sub(tmp2, 1+4); /* substract 1 because 'Lener' is divided by two */ - tmp2 = add(tmp2, Q_syn2x); - tmp2 = s_max(0, s_min(30, tmp2)); + exp = norm_l( Ltmp ); + tmp2 = sub( tmp2, 1 + 4 ); /* substract 1 because 'Lener' is divided by two */ + tmp2 = add( tmp2, Q_syn2x ); + tmp2 = s_max( 0, s_min( 30, tmp2 ) ); #ifdef BASOP_NOGLOB - Lener = L_add_sat(Lener, Pow2(tmp2, exp2)); + Lener = L_add_sat( Lener, Pow2( tmp2, exp2 ) ); #else - Lener = L_add(Lener, Pow2(tmp2, exp2)); + Lener = L_add( Lener, Pow2( tmp2, exp2 ) ); #endif - exp2 = norm_l(Lener); + exp2 = norm_l( Lener ); #ifdef BASOP_NOGLOB - tmp2 = round_fx_sat(L_shl(Lener, exp2)); + tmp2 = round_fx_sat( L_shl( Lener, exp2 ) ); #else - tmp2 = round_fx(L_shl(Lener, exp2)); + tmp2 = round_fx( L_shl( Lener, exp2 ) ); #endif - if (GT_16(tmp, tmp2)) + if ( GT_16( tmp, tmp2 ) ) { - exp = sub(exp, 1); + exp = sub( exp, 1 ); } - exp2 = sub(exp, exp2); /* exponent num - exponent denom */ - /* alpha = corr / ener */ + exp2 = sub( exp, exp2 ); /* exponent num - exponent denom */ + /* alpha = corr / ener */ #ifdef BASOP_NOGLOB - alpha = shr_sat(div_s(round_fx_sat(L_shl_sat(Ltmp, exp)), tmp2), exp2); /*Q15 */ + alpha = shr_sat( div_s( round_fx_sat( L_shl_sat( Ltmp, exp ) ), tmp2 ), exp2 ); /*Q15 */ #else - alpha = shr(div_s(round_fx(L_shl(Ltmp, exp)), tmp2), exp2); /*Q15 */ + alpha = shr( div_s( round_fx( L_shl( Ltmp, exp ) ), tmp2 ), exp2 ); /*Q15 */ #endif - if (Lcorr < 0) + if ( Lcorr < 0 ) { - alpha = sub(0, alpha); + alpha = sub( 0, alpha ); } - alpha = s_min(alpha, 16384);/*Q15 */ + alpha = s_min( alpha, 16384 ); /*Q15 */ - alpha = mult_r(alpha,hBPF->psf_att_fx); + alpha = mult_r( alpha, hBPF->psf_att_fx ); test(); test(); - IF (GT_16(alpha,9830)&&Track_on) + IF( GT_16( alpha, 9830 ) && Track_on ) { alpha = 9830; move16(); } - ELSE if (GT_16(alpha,13107)&&vibrato) + ELSE if ( GT_16( alpha, 13107 ) && vibrato ) { alpha = 13107; move16(); } - alpha = s_max(alpha, 0); + alpha = s_max( alpha, 0 ); /**v_stab_smooth_fx = 0.8f * v_stab_fx + 0.2f * (*v_stab_smooth_fx); */ - tmp = mult(*v_stab_smooth_fx,6554); /*Q15 and 6554 is 0.2 in Q15 */ - tmp2= mult(v_stab_fx,26214);/*Q15 and 26214 is 0.8 in Q15 */ - *v_stab_smooth_fx = add(tmp2,tmp); + tmp = mult( *v_stab_smooth_fx, 6554 ); /*Q15 and 6554 is 0.2 in Q15 */ + tmp2 = mult( v_stab_fx, 26214 ); /*Q15 and 26214 is 0.8 in Q15 */ + *v_stab_smooth_fx = add( tmp2, tmp ); move16(); /*delta_v_stab = (float) fabs(*v_stab_smooth_fx - v_stab_fx); */ - tmp = sub(*v_stab_smooth_fx,v_stab_fx); /*Q15 */ - delta_v_stab = abs_s(tmp); + tmp = sub( *v_stab_smooth_fx, v_stab_fx ); /*Q15 */ + delta_v_stab = abs_s( tmp ); /*v_stab_fx = (float) pow(v_stab_fx, 0.5f); */ - v_stab_fx = Frac_sqrt(v_stab_fx); + v_stab_fx = Frac_sqrt( v_stab_fx ); /*alpha = (1.0f + 0.15f*v_stab_fx - 2.0f*delta_v_stab) * alpha; */ - tmp = mult(2458,v_stab_fx);/*Q14 */ - tmp = add(16384,tmp);/*Q14 */ - tmp = sub(tmp,delta_v_stab);/*Q14 */ - alpha = mult(tmp,alpha);/*Q14 */ + tmp = mult( 2458, v_stab_fx ); /*Q14 */ + tmp = add( 16384, tmp ); /*Q14 */ + tmp = sub( tmp, delta_v_stab ); /*Q14 */ + alpha = mult( tmp, alpha ); /*Q14 */ - FOR (i=0; i< subfr_len; i++) + FOR( i = 0; i < subfr_len; i++ ) { /*syn2_fx[i] = alpha*(syn_fx[i]-syn2_fx[i]); */ #ifdef BASOP_NOGLOB tmp = sub_sat( syn_fx[i], syn2_fx[i] ); - syn2_fx[i] = mult_sat(alpha, shl_sat(tmp, 1)); + syn2_fx[i] = mult_sat( alpha, shl_sat( tmp, 1 ) ); #else tmp = sub( syn_fx[i], syn2_fx[i] ); - syn2_fx[i] = mult(alpha,shl(tmp,1)); + syn2_fx[i] = mult( alpha, shl( tmp, 1 ) ); #endif - move16();/*Q_syn2 */ + move16(); /*Q_syn2 */ } /* low-frequency noise estimator (lp_ener is average in dB) */ - deemph_fx(err, 29491/*0.9*/, subfr_len, &(hBPF->pst_mem_deemp_err_fx)); /* +20dB at 50Hz */ - Lener = L_deposit_h(-32768); + deemph_fx( err, 29491 /*0.9*/, subfr_len, &( hBPF->pst_mem_deemp_err_fx ) ); /* +20dB at 50Hz */ + Lener = L_deposit_h( -32768 ); /* by using the maximum negative value it is possible to gain another bit of range for the 'Lener' sum. This sum is divided by 4 */ - FOR (i=0; i< subfr_len; i++) + FOR( i = 0; i < subfr_len; i++ ) { #ifdef BASOP_NOGLOB - Lener = L_mac0_sat(Lener, err[i], err[i]); + Lener = L_mac0_sat( Lener, err[i], err[i] ); #else - Lener = L_mac0(Lener, err[i], err[i]); + Lener = L_mac0( Lener, err[i], err[i] ); #endif } - exp2 = -1-2; + exp2 = -1 - 2; move16(); /* 'Lener' is divided by 2 */ - IF (EQ_32(Lener, 2147483647L)) + IF( EQ_32( Lener, 2147483647L ) ) { - Lener = L_deposit_h(-32768); - sigPtr = err + subfr_len /2; - FOR (i=0; i< subfr_len /2; i++) + Lener = L_deposit_h( -32768 ); + sigPtr = err + subfr_len / 2; + FOR( i = 0; i < subfr_len / 2; i++ ) { - Lener0 = L_mult0(sigPtr[i], sigPtr[i]); + Lener0 = L_mult0( sigPtr[i], sigPtr[i] ); #ifdef BASOP_NOGLOB - Lener = L_add(Lener, L_shr(L_mac0_sat(Lener0, err[i], err[i]), 5)); + Lener = L_add( Lener, L_shr( L_mac0_sat( Lener0, err[i], err[i] ), 5 ) ); #else - Lener = L_add(Lener, L_shr(L_mac0(Lener0, err[i], err[i]), 5)); + Lener = L_add( Lener, L_shr( L_mac0( Lener0, err[i], err[i] ), 5 ) ); #endif } - exp2 = sub(exp2, 5); + exp2 = sub( exp2, 5 ); } - Lener = L_shr(Lener, 1); - Lener = L_add(Lener, 0x40000001L); + Lener = L_shr( Lener, 1 ); + Lener = L_add( Lener, 0x40000001L ); /* ener = 10.0*log10(ener) */ /* *lp_ener = 0.99f * *lp_ener + 0.01f * ener */ - tmp = norm_l(Lener); - exp = Log2_norm_lc(L_shl(Lener, tmp)); - tmp = sub(30, tmp); - tmp = sub(tmp, Q_syn2x); - tmp = sub(tmp, exp2); /* take care of exponent of 'Lener' */ - - Lener = L_Comp(tmp, exp); - Lener = Mpy_32_16_1(Lener, 31565); /* 31565 = Log10(2) x 0.1 x 2^15 x 32 (*32 to utilize all 15 bits) */ - Lener = L_shl(Lener, 3); - hBPF->pst_lp_ener_fx = mac_r(Lener, hBPF->pst_lp_ener_fx, 32440); + tmp = norm_l( Lener ); + exp = Log2_norm_lc( L_shl( Lener, tmp ) ); + tmp = sub( 30, tmp ); + tmp = sub( tmp, Q_syn2x ); + tmp = sub( tmp, exp2 ); /* take care of exponent of 'Lener' */ + + Lener = L_Comp( tmp, exp ); + Lener = Mpy_32_16_1( Lener, 31565 ); /* 31565 = Log10(2) x 0.1 x 2^15 x 32 (*32 to utilize all 15 bits) */ + Lener = L_shl( Lener, 3 ); + hBPF->pst_lp_ener_fx = mac_r( Lener, hBPF->pst_lp_ener_fx, 32440 ); move16(); /* just write out the error signal */ @@ -534,24 +535,24 @@ void bass_psfilter_fx( ELSE { /* symetric pitch prediction : phase is opposite between harmonic */ - FOR (i=0; ipst_lp_ener_fx), &tmp2); /* 2786635L is Q31 : 0.1xLog2(10) / 256 (/256 because lp_ener is Q8) */ + exp2 = L_Extract_lc( Mpy_32_16_1( 2786635L, hBPF->pst_lp_ener_fx ), &tmp2 ); /* 2786635L is Q31 : 0.1xLog2(10) / 256 (/256 because lp_ener is Q8) */ /* Note: 'Ltmp' is still the absolute value of 'Lcorr' 'tmp' is still 'Ltmp' normalized and rounded to 16 bits However, exp has to be recalculated because it is affected by exp = sub(exp, 1) before the div_s */ - exp = norm_l(Ltmp); - tmp2 = sub(tmp2, 1+4); /* substract 1 because 'Lener' is divided by two */ - tmp2 = add(tmp2, Q_syn2x); - tmp2 = s_max(0, s_min(30, tmp2)); + exp = norm_l( Ltmp ); + tmp2 = sub( tmp2, 1 + 4 ); /* substract 1 because 'Lener' is divided by two */ + tmp2 = add( tmp2, Q_syn2x ); + tmp2 = s_max( 0, s_min( 30, tmp2 ) ); #ifdef BASOP_NOGLOB - Lener = L_add_sat(Lener, Pow2(tmp2, exp2)); + Lener = L_add_sat( Lener, Pow2( tmp2, exp2 ) ); #else - Lener = L_add(Lener, Pow2(tmp2, exp2)); + Lener = L_add( Lener, Pow2( tmp2, exp2 ) ); #endif - exp2 = norm_l(Lener); + exp2 = norm_l( Lener ); #ifdef BASOP_NOGLOB - tmp2 = round_fx_sat(L_shl(Lener, exp2)); + tmp2 = round_fx_sat( L_shl( Lener, exp2 ) ); #else - tmp2 = round_fx(L_shl(Lener, exp2)); + tmp2 = round_fx( L_shl( Lener, exp2 ) ); #endif - if (GT_16(tmp, tmp2)) + if ( GT_16( tmp, tmp2 ) ) { - exp = sub(exp, 1); + exp = sub( exp, 1 ); } - exp2 = sub(exp, exp2); /* exponent num - exponent denom */ + exp2 = sub( exp, exp2 ); /* exponent num - exponent denom */ alpha = 0; move16(); /**v_stab_smooth_fx = 0.8f * v_stab_fx + 0.2f * (*v_stab_smooth_fx); */ - tmp = mult(*v_stab_smooth_fx,6554);/*Q15 and 6554 is 0.2 in Q15 */ - tmp2= mult(v_stab_fx,26214);/*Q15 and 26214 is 0.8 in Q15 */ + tmp = mult( *v_stab_smooth_fx, 6554 ); /*Q15 and 6554 is 0.2 in Q15 */ + tmp2 = mult( v_stab_fx, 26214 ); /*Q15 and 26214 is 0.8 in Q15 */ - *v_stab_smooth_fx = add(tmp2,tmp); + *v_stab_smooth_fx = add( tmp2, tmp ); move16(); - FOR (i=0; ipst_mem_deemp_err_fx)); /* +20dB at 50Hz */ + deemph_fx( err, 29491 /*0.9*/, subfr_len, &( hBPF->pst_mem_deemp_err_fx ) ); /* +20dB at 50Hz */ - Lener = L_deposit_h(-32768); + Lener = L_deposit_h( -32768 ); /* by using the maximum negative value it is possible to gain another bit of range for the 'Lener' sum. This sum is divided by 4 */ - FOR (i=0; ipst_lp_ener_fx = mac_r(Lener, hBPF->pst_lp_ener_fx, 32440); + tmp = norm_l( Lener ); + exp = Log2_norm_lc( L_shl( Lener, tmp ) ); + tmp = sub( 30, tmp ); + tmp = sub( tmp, Q_syn2x ); + tmp = sub( tmp, exp2 ); /* take care of exponent of 'Lener' */ + + Lener = L_Comp( tmp, exp ); + Lener = Mpy_32_16_1( Lener, 31565 ); /* 31565 = Log10(2) x 0.1 x 2^15 x 32 (*32 to utilize all 15 bits) */ + Lener = L_shl( Lener, 3 ); + hBPF->pst_lp_ener_fx = mac_r( Lener, hBPF->pst_lp_ener_fx, 32440 ); move16(); /* just write out the error signal */ Copy( syn2_fx, bpf_noise_buf + i_subfr, subfr_len ); } - subfr_pos = add(subfr_pos, 1); + subfr_pos = add( subfr_pos, 1 ); } /*-------------------------------------------------------* * update memory for next frame *-------------------------------------------------------*/ - FOR( i = L_TRACK_HIST-1; i > 0; i-- ) + FOR( i = L_TRACK_HIST - 1; i > 0; i-- ) { - hBPF->Track_on_hist[i] = hBPF->Track_on_hist[i-1]; + hBPF->Track_on_hist[i] = hBPF->Track_on_hist[i - 1]; move16(); - hBPF->vibrato_hist[i] = hBPF->vibrato_hist[i-1]; + hBPF->vibrato_hist[i] = hBPF->vibrato_hist[i - 1]; move16(); } @@ -737,7 +738,7 @@ void bass_psfilter_fx( hBPF->vibrato_hist[i] = vibrato; move16(); - Copy( syn_buf_fx+L_frame, hBPF->pst_old_syn_fx, nbpsf_pit_max ); + Copy( syn_buf_fx + L_frame, hBPF->pst_old_syn_fx, nbpsf_pit_max ); return; @@ -760,9 +761,9 @@ void bass_psfilter_fx( /*==============================================================================*/ #ifdef IVAS_FLOAT_FIXED -static Word16 Pit_track_fx( /* o : Pitch */ - Word16 syn[], /* i : synthesis [-PIT_MAX..L_SUBFR] */ - Word16 T /* i : pitch period (>= PIT_MIN) */ +static Word16 Pit_track_fx( /* o : Pitch */ + Word16 syn[], /* i : synthesis [-PIT_MAX..L_SUBFR] */ + Word16 T /* i : pitch period (>= PIT_MIN) */ ) { Word16 T2; @@ -777,104 +778,104 @@ static Word16 Pit_track_fx( /* o : Pitch */ * (short pitch is limited to PIT_MIN (34 = 376Hz) by the encoder *----------------------------------------------------------------*/ - T2 = shr(T, 1); + T2 = shr( T, 1 ); v1 = &syn[-NBPSF_L_EXTRA]; - v2 = &syn[add(-T2, -NBPSF_L_EXTRA)]; + v2 = &syn[add( -T2, -NBPSF_L_EXTRA )]; - Lener = L_deposit_h(-32768); - Ltmp = L_deposit_h(-32768); - Lcorr = L_deposit_l(2); + Lener = L_deposit_h( -32768 ); + Ltmp = L_deposit_h( -32768 ); + Lcorr = L_deposit_l( 2 ); /* by using the maximum negative value it is possible to gain another bit of range for the 'Lener' sum. It cannot be done for Lcorr because it is a signed sum. */ - FOR (j = 0; j < 14; j++) + FOR( j = 0; j < 14; j++ ) { BASOP_SATURATE_WARNING_OFF_EVS - Lener0 = L_mult0(*v1, *v1); - Ltmp0 = L_mult0(*v2, *v2); - Lcorr0 = L_mult0(*v1++, *v2++); - FOR (i = 1; i < (L_HALFR16k+NBPSF_L_EXTRA)/14; i++) + Lener0 = L_mult0( *v1, *v1 ); + Ltmp0 = L_mult0( *v2, *v2 ); + Lcorr0 = L_mult0( *v1++, *v2++ ); + FOR( i = 1; i < ( L_HALFR16k + NBPSF_L_EXTRA ) / 14; i++ ) { #ifdef BASOP_NOGLOB - Lener0 = L_mac0_sat(Lener0, *v1, *v1); - Ltmp0 = L_mac0_sat(Ltmp0, *v2, *v2); - Lcorr0 = L_mac0_sat(Lcorr0, *v1++, *v2++); + Lener0 = L_mac0_sat( Lener0, *v1, *v1 ); + Ltmp0 = L_mac0_sat( Ltmp0, *v2, *v2 ); + Lcorr0 = L_mac0_sat( Lcorr0, *v1++, *v2++ ); #else - Lener0 = L_mac0(Lener0, *v1, *v1); - Ltmp0 = L_mac0(Ltmp0, *v2, *v2); - Lcorr0 = L_mac0(Lcorr0, *v1++, *v2++); + Lener0 = L_mac0( Lener0, *v1, *v1 ); + Ltmp0 = L_mac0( Ltmp0, *v2, *v2 ); + Lcorr0 = L_mac0( Lcorr0, *v1++, *v2++ ); #endif } BASOP_SATURATE_WARNING_ON_EVS test(); test(); test(); - IF (EQ_32(Lener0, 2147483647L)|| - EQ_32(Ltmp0, 2147483647L) || - EQ_32(Lcorr0, 2147483647L) || EQ_32(Lcorr0, -2147483647-1L)) + IF( EQ_32( Lener0, 2147483647L ) || + EQ_32( Ltmp0, 2147483647L ) || + EQ_32( Lcorr0, 2147483647L ) || EQ_32( Lcorr0, -2147483647 - 1L ) ) { v1 -= i; move16(); v2 -= i; move16(); - FOR (i = 0; i < (L_HALFR16k+NBPSF_L_EXTRA)/14; i++) + FOR( i = 0; i < ( L_HALFR16k + NBPSF_L_EXTRA ) / 14; i++ ) { - Lener = L_add(Lener, L_shr(L_mult0(*v1, *v1), 6)); - Ltmp = L_add(Ltmp, L_shr(L_mult0(*v2, *v2), 6)); - Lcorr = L_add(Lcorr, L_shr(L_mult0(*v1++, *v2++), 6)); + Lener = L_add( Lener, L_shr( L_mult0( *v1, *v1 ), 6 ) ); + Ltmp = L_add( Ltmp, L_shr( L_mult0( *v2, *v2 ), 6 ) ); + Lcorr = L_add( Lcorr, L_shr( L_mult0( *v1++, *v2++ ), 6 ) ); } } ELSE { - Lener = L_add(Lener, L_shr(Lener0, 6)); - Ltmp = L_add(Ltmp, L_shr(Ltmp0, 6)); - Lcorr = L_add(Lcorr, L_shr(Lcorr0, 6)); + Lener = L_add( Lener, L_shr( Lener0, 6 ) ); + Ltmp = L_add( Ltmp, L_shr( Ltmp0, 6 ) ); + Lcorr = L_add( Lcorr, L_shr( Lcorr0, 6 ) ); } } - Lener = L_shr(Lener, 1); - Lener = L_add(Lener, 0x40000001L); - Ltmp = L_shr(Ltmp, 1); - Ltmp = L_add(Ltmp, 0x40000001L); - Lcorr = L_shr(Lcorr, 1); + Lener = L_shr( Lener, 1 ); + Lener = L_add( Lener, 0x40000001L ); + Ltmp = L_shr( Ltmp, 1 ); + Ltmp = L_add( Ltmp, 0x40000001L ); + Lcorr = L_shr( Lcorr, 1 ); /* 'Lener', 'Ltmp' & 'Lcorr' are divided by 2 */ /* cn = corr / (float)sqrt(ener*tmp) */ - exp1 = norm_l(Lener); - exp2 = norm_l(Ltmp); + exp1 = norm_l( Lener ); + exp2 = norm_l( Ltmp ); /* Multiply the Most Significant 16 bits */ #ifdef BASOP_NOGLOB - Ltmp = L_mult0(round_fx_sat(L_shl_sat(Lener, exp1)), round_fx_sat(L_shl_sat(Ltmp, exp2))); + Ltmp = L_mult0( round_fx_sat( L_shl_sat( Lener, exp1 ) ), round_fx_sat( L_shl_sat( Ltmp, exp2 ) ) ); #else - Ltmp = L_mult0(round_fx(L_shl(Lener, exp1)), round_fx(L_shl(Ltmp, exp2))); + Ltmp = L_mult0( round_fx( L_shl( Lener, exp1 ) ), round_fx( L_shl( Ltmp, exp2 ) ) ); #endif - exp1 = add(exp1, exp2); + exp1 = add( exp1, exp2 ); /* Correct if Odd # of Shifts */ - exp2 = s_and(exp1, 1); - exp1 = sub(exp1, exp2); - Ltmp = L_shr(Ltmp, exp2); + exp2 = s_and( exp1, 1 ); + exp1 = sub( exp1, exp2 ); + Ltmp = L_shr( Ltmp, exp2 ); /* Call the Integer Square Root (it will normalize again if req.) */ - Ltmp = Isqrt(Ltmp); + Ltmp = Isqrt( Ltmp ); /* We now do corr * 1 / sqrt(1/product) with high part of ratio only */ - exp1 = mac_r((16-1)*65536L-0x8000L, exp1, 16384); - exp2 = norm_l(Ltmp); - Ltmp = L_shl(Ltmp, exp2); - exp1 = sub(exp1, exp2); - exp2 = norm_l(Lcorr); - Lcorr= L_shl(Lcorr, exp2); - exp1 = sub(exp1, exp2); - Ltmp = Mpy_32_16_1(Lcorr, round_fx(Ltmp)); + exp1 = mac_r( ( 16 - 1 ) * 65536L - 0x8000L, exp1, 16384 ); + exp2 = norm_l( Ltmp ); + Ltmp = L_shl( Ltmp, exp2 ); + exp1 = sub( exp1, exp2 ); + exp2 = norm_l( Lcorr ); + Lcorr = L_shl( Lcorr, exp2 ); + exp1 = sub( exp1, exp2 ); + Ltmp = Mpy_32_16_1( Lcorr, round_fx( Ltmp ) ); /* Go to Q31 */ #ifdef BASOP_NOGLOB - Ltmp = L_shl_sat(Ltmp, exp1); + Ltmp = L_shl_sat( Ltmp, exp1 ); #else - Ltmp = L_shl(Ltmp, exp1); + Ltmp = L_shl( Ltmp, exp1 ); #endif /* cn = normalized correlation of pitch/2 */ - if (GT_32(Ltmp, 2040109466L)) /* 0.95f in Q31 */ + if ( GT_32( Ltmp, 2040109466L ) ) /* 0.95f in Q31 */ { T = T2; move16(); @@ -892,24 +893,23 @@ static Word16 Pit_track_fx( /* o : Pitch */ #ifdef IVAS_FLOAT_FIXED void addBassPostFilter_fx( - const Word16 *harm_timeIn_Fx, - Word32 **rAnalysis_Fx, - Word32 **iAnalysis_Fx, - HANDLE_CLDFB_FILTER_BANK cldfbBank_bpf_Fx, - Word32 *workBuffer, + const Word16 *harm_timeIn_Fx, + Word32 **rAnalysis_Fx, + Word32 **iAnalysis_Fx, + HANDLE_CLDFB_FILTER_BANK cldfbBank_bpf_Fx, + Word32 *workBuffer, const Word16 timeIn_e, const Word16 nTimeSlots, const Word16 nTimeSlotsTotal, const Word16 nBandsTotal, - CLDFB_SCALE_FACTOR *cldfb_scale - ) + CLDFB_SCALE_FACTOR *cldfb_scale ) { - Word16 i, scale1, scale2; - Word16 b; - Word16 maxBand; - Word16 nChan; + Word16 i, scale1, scale2; + Word16 b; + Word16 maxBand; + Word16 nChan; CLDFB_SCALE_FACTOR scale; - const Word16 *weights_Fx; + const Word16 *weights_Fx; Word32 *tmp_R_Fx[CLDFB_NO_COL_MAX]; Word32 *tmp_I_Fx[CLDFB_NO_COL_MAX]; Word32 cldfbBufferReal[CLDFB_NO_COL_MAX][20]; @@ -921,11 +921,11 @@ void addBassPostFilter_fx( move16(); weights_Fx = bpf_weights_16_Fx; - maxBand = s_min(nChan, BPF_STOP_STOPBAND_16); + maxBand = s_min( nChan, BPF_STOP_STOPBAND_16 ); - assert(nChan <= 20); + assert( nChan <= 20 ); - FOR (i=0; i < nTimeSlots; i++) + FOR( i = 0; i < nTimeSlots; i++ ) { tmp_R_Fx[i] = cldfbBufferReal[i]; tmp_I_Fx[i] = cldfbBufferImag[i]; @@ -939,47 +939,46 @@ void addBassPostFilter_fx( harm_timeIn_Fx, timeIn_e, nTimeSlots, - workBuffer - ); + workBuffer ); /* now do the subtraction */ - IF (nTimeSlots > 0) + IF( nTimeSlots > 0 ) { /* Find common scale. */ - b = s_max(cldfb_scale->lb_scale, scale.lb_scale); - scale1 = limitScale32(sub(cldfb_scale->lb_scale, b)); - scale2 = limitScale32(sub(scale.lb_scale, b)); + b = s_max( cldfb_scale->lb_scale, scale.lb_scale ); + scale1 = limitScale32( sub( cldfb_scale->lb_scale, b ) ); + scale2 = limitScale32( sub( scale.lb_scale, b ) ); cldfb_scale->lb_scale = b; move16(); /* Rescale time slots which do not have BPF contribution. */ - FOR (i=nTimeSlots; i < nTimeSlotsTotal; i++) + FOR( i = nTimeSlots; i < nTimeSlotsTotal; i++ ) { - Scale_sig32(rAnalysis_Fx[i], nBandsTotal, scale1); - Scale_sig32(iAnalysis_Fx[i], nBandsTotal, scale1); + Scale_sig32( rAnalysis_Fx[i], nBandsTotal, scale1 ); + Scale_sig32( iAnalysis_Fx[i], nBandsTotal, scale1 ); } } - FOR (i=0; i < nTimeSlots; i++) + FOR( i = 0; i < nTimeSlots; i++ ) { /* Compensate first bpf_weights coefficient which is scaled by 0.5 */ - rAnalysis_Fx[i][0] = L_sub(L_shl(rAnalysis_Fx[i][0],scale1),L_shl(Mpy_32_16_1(tmp_R_Fx[i][0],weights_Fx[0]),add(1, scale2))); + rAnalysis_Fx[i][0] = L_sub( L_shl( rAnalysis_Fx[i][0], scale1 ), L_shl( Mpy_32_16_1( tmp_R_Fx[i][0], weights_Fx[0] ), add( 1, scale2 ) ) ); move32(); - iAnalysis_Fx[i][0] = L_sub(L_shl(iAnalysis_Fx[i][0],scale1),L_shl(Mpy_32_16_1(tmp_I_Fx[i][0],weights_Fx[0]),add(1, scale2))); + iAnalysis_Fx[i][0] = L_sub( L_shl( iAnalysis_Fx[i][0], scale1 ), L_shl( Mpy_32_16_1( tmp_I_Fx[i][0], weights_Fx[0] ), add( 1, scale2 ) ) ); move32(); /* loop over remaining low frequency bands */ - FOR (b=1; b < maxBand; b++) + FOR( b = 1; b < maxBand; b++ ) { - rAnalysis_Fx[i][b] = L_sub(L_shl(rAnalysis_Fx[i][b],scale1),L_shr(Mpy_32_16_1(tmp_R_Fx[i][b],weights_Fx[b]), scale2)); + rAnalysis_Fx[i][b] = L_sub( L_shl( rAnalysis_Fx[i][b], scale1 ), L_shr( Mpy_32_16_1( tmp_R_Fx[i][b], weights_Fx[b] ), scale2 ) ); move32(); - iAnalysis_Fx[i][b] = L_sub(L_shl(iAnalysis_Fx[i][b],scale1),L_shr(Mpy_32_16_1(tmp_I_Fx[i][b],weights_Fx[b]), scale2)); + iAnalysis_Fx[i][b] = L_sub( L_shl( iAnalysis_Fx[i][b], scale1 ), L_shr( Mpy_32_16_1( tmp_I_Fx[i][b], weights_Fx[b] ), scale2 ) ); move32(); } /* Rescale Bands with no BPF contribution. */ - Scale_sig32(rAnalysis_Fx[i]+maxBand, sub(nBandsTotal, maxBand), scale1); - Scale_sig32(iAnalysis_Fx[i]+maxBand, sub(nBandsTotal, maxBand), scale1); + Scale_sig32( rAnalysis_Fx[i] + maxBand, sub( nBandsTotal, maxBand ), scale1 ); + Scale_sig32( iAnalysis_Fx[i] + maxBand, sub( nBandsTotal, maxBand ), scale1 ); } return; @@ -994,10 +993,10 @@ void addBassPostFilter_fx( * residual signal *---------------------------------------------------------------------*/ - /*! r: Decision to enable or disable BPF on DFT stereo residual */ +/*! r: Decision to enable or disable BPF on DFT stereo residual */ int16_t res_bpf_adapt( STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: DFT stereo decoder handle */ - const float* bpf_error_signal_8k, /* i : BPF modification signal */ + const float *bpf_error_signal_8k, /* i : BPF modification signal */ float res_buf[STEREO_DFT_BUF_MAX] /* i : residual buffer */ ) { @@ -1011,7 +1010,7 @@ int16_t res_bpf_adapt( int16_t i_end; float bw_inv; - if (hStereoDft->res_cod_band_max == 6) + if ( hStereoDft->res_cod_band_max == 6 ) { i_start = 39; i_end = 64; @@ -1026,25 +1025,25 @@ int16_t res_bpf_adapt( /* Measure energy of high frequency band in MDCT domain */ res_hb_nrg = EPSILON; - for (i = i_start; i < i_end; i++) + for ( i = i_start; i < i_end; i++ ) { res_hb_nrg += res_buf[i] * res_buf[i]; } res_hb_nrg *= bw_inv; - res_hb_nrg = STEREO_DFT_BPF_ADAPT_ALPHA * res_hb_nrg + (1 - STEREO_DFT_BPF_ADAPT_ALPHA) * hStereoDft->res_hb_nrg_mem; + res_hb_nrg = STEREO_DFT_BPF_ADAPT_ALPHA * res_hb_nrg + ( 1 - STEREO_DFT_BPF_ADAPT_ALPHA ) * hStereoDft->res_hb_nrg_mem; hStereoDft->res_hb_nrg_mem = res_hb_nrg; /* Measure energy of discontinuities at subframe boundaries */ error_nrg = 0; - for (i = 0; i < L_FRAME8k; i += STEREO_DFT_L_SUBFR_8k) + for ( i = 0; i < L_FRAME8k; i += STEREO_DFT_L_SUBFR_8k ) { tmp = bpf_error_signal_8k[i] - hStereoDft->bpf_error_signal_last; error_nrg += tmp * tmp; hStereoDft->bpf_error_signal_last = bpf_error_signal_8k[i + STEREO_DFT_L_SUBFR_8k - 1]; } error_nrg *= 0.2f; /* Division by 5 for average value */ - bpf_error_ratio = min(2, error_nrg / res_hb_nrg); /* Form decision variable and apply limit */ - bpf_error_ratio = STEREO_DFT_BPF_ADAPT_BETA * bpf_error_ratio + (1 - STEREO_DFT_BPF_ADAPT_BETA) * hStereoDft->bpf_error_ratio_mem; + bpf_error_ratio = min( 2, error_nrg / res_hb_nrg ); /* Form decision variable and apply limit */ + bpf_error_ratio = STEREO_DFT_BPF_ADAPT_BETA * bpf_error_ratio + ( 1 - STEREO_DFT_BPF_ADAPT_BETA ) * hStereoDft->bpf_error_ratio_mem; hStereoDft->bpf_error_ratio_mem = bpf_error_ratio; res_bpf_flag = bpf_error_ratio < 1; @@ -1058,7 +1057,7 @@ int16_t res_bpf_adapt( * Analyse pitch coherence *---------------------------------------------------------------------*/ void bpf_pitch_coherence( - Decoder_State* st, /* i/o: decoder state structure */ + Decoder_State *st, /* i/o: decoder state structure */ const float pitch_buf[] /* i : pitch for every subfr [0,1,2,3] */ ) { @@ -1067,27 +1066,27 @@ void bpf_pitch_coherence( nb_subfr = st->L_frame / L_SUBFR; - if (st->clas_dec > UNVOICED_CLAS && st->element_mode != EVS_MONO) + if ( st->clas_dec > UNVOICED_CLAS && st->element_mode != EVS_MONO ) { - pc = (float)fabs(st->old_pitch_buf[nb_subfr + 3] + st->old_pitch_buf[nb_subfr + 2] - st->old_pitch_buf[nb_subfr] - st->old_pitch_buf[nb_subfr + 1]) * 256.0f / (float)st->L_frame; + pc = (float) fabs( st->old_pitch_buf[nb_subfr + 3] + st->old_pitch_buf[nb_subfr + 2] - st->old_pitch_buf[nb_subfr] - st->old_pitch_buf[nb_subfr + 1] ) * 256.0f / (float) st->L_frame; pcn1 = K_PC_DEC * pc + C_PC_DEC; - pcn1 = max(min(pcn1, 1.0f), 0.0f); + pcn1 = max( min( pcn1, 1.0f ), 0.0f ); - pc = (float)fabs(pitch_buf[nb_subfr - 1] + pitch_buf[nb_subfr - 2] - pitch_buf[1] - pitch_buf[0]) * 256.0f / (float)st->L_frame; + pc = (float) fabs( pitch_buf[nb_subfr - 1] + pitch_buf[nb_subfr - 2] - pitch_buf[1] - pitch_buf[0] ) * 256.0f / (float) st->L_frame; pcn2 = K_PC_DEC * pc + C_PC_DEC; - pcn2 = max(min(pcn2, 1.0f), 0.0f); + pcn2 = max( min( pcn2, 1.0f ), 0.0f ); - pc = (float)fabs(st->old_pitch_buf[nb_subfr + 3] + st->old_pitch_buf[nb_subfr + 2] - pitch_buf[1] - pitch_buf[0]) * 256.0f / (float)st->L_frame; + pc = (float) fabs( st->old_pitch_buf[nb_subfr + 3] + st->old_pitch_buf[nb_subfr + 2] - pitch_buf[1] - pitch_buf[0] ) * 256.0f / (float) st->L_frame; pcn3 = K_PC_DEC * pc + C_PC_DEC; - pcn3 = max(min(pcn3, 1.0f), 0.0f); + pcn3 = max( min( pcn3, 1.0f ), 0.0f ); - if (pcn1 + pcn2 + pcn3 < 2.5f) + if ( pcn1 + pcn2 + pcn3 < 2.5f ) { st->hBPF->psf_att = 0.4f; - set_s(&st->hBPF->Track_on_hist[L_TRACK_HIST - nb_subfr], 1, nb_subfr); + set_s( &st->hBPF->Track_on_hist[L_TRACK_HIST - nb_subfr], 1, nb_subfr ); } } return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/cng_dec.c b/lib_dec/cng_dec.c index a09cc90fc..cb202f38b 100644 --- a/lib_dec/cng_dec.c +++ b/lib_dec/cng_dec.c @@ -782,7 +782,7 @@ void td_cng_dec_init( hTdCngDec->old_enr_index = -1; #ifndef IVAS_FLOAT_FIXED hTdCngDec->Enew = 0.0f; - mvr2r(st->lsp_old, st->lspCNG, M); + mvr2r( st->lsp_old, st->lspCNG, M ); #endif hTdCngDec->last_allow_cn_step = 0; hTdCngDec->shb_cng_ener = -6.02f; @@ -845,78 +845,78 @@ void td_cng_dec_init( } #else void td_cng_dec_init( - DEC_CORE_HANDLE st /* i/o: decoder state structure */ + DEC_CORE_HANDLE st /* i/o: decoder state structure */ ) { - int16_t i; - TD_CNG_DEC_HANDLE hTdCngDec; - - hTdCngDec = st->hTdCngDec; - - hTdCngDec->cng_seed = RANDOM_INITSEED; - hTdCngDec->cng_ener_seed = RANDOM_INITSEED; - hTdCngDec->cng_ener_seed1 = RANDOM_INITSEED; - hTdCngDec->old_enr_index = -1; - hTdCngDec->Enew = 0.0f; - mvr2r(st->lsp_old, st->lspCNG, M); - hTdCngDec->last_allow_cn_step = 0; - hTdCngDec->shb_cng_ener = -6.02f; - if (st->element_mode != EVS_MONO) - { - set_f(hTdCngDec->shb_lpcCNG, 0.0f, LPC_SHB_ORDER + 1); - hTdCngDec->shb_lpcCNG[0] = 1.0f; - hTdCngDec->shb_cng_gain = -82.0; /* a dB value approximately corresponding to shb index 0(used as index -15) */ - } - - hTdCngDec->wb_cng_ener = -6.02f; - hTdCngDec->last_wb_cng_ener = -6.02f; - hTdCngDec->last_shb_cng_ener = -6.02f; - hTdCngDec->swb_cng_seed = RANDOM_INITSEED; - hTdCngDec->ho_hist_ptr = -1; - hTdCngDec->ho_sid_bw = 0; - set_f(hTdCngDec->ho_lsp_hist, 0, HO_HIST_SIZE * M); - set_f(hTdCngDec->ho_ener_hist, 0, HO_HIST_SIZE); - set_f(hTdCngDec->ho_env_hist, 0, HO_HIST_SIZE * NUM_ENV_CNG); - hTdCngDec->ho_hist_size = 0; - hTdCngDec->act_cnt = 0; - hTdCngDec->ho_circ_ptr = -1; - set_f(hTdCngDec->ho_lsp_circ, 0, HO_HIST_SIZE * M); - set_f(hTdCngDec->ho_ener_circ, 0, HO_HIST_SIZE); - set_f(hTdCngDec->ho_env_circ, 0, HO_HIST_SIZE * NUM_ENV_CNG); - hTdCngDec->ho_circ_size = 0; - - set_s(hTdCngDec->ho_16k_lsp, 0, HO_HIST_SIZE); - st->CNG_mode = -1; - hTdCngDec->act_cnt2 = 0; - hTdCngDec->num_ho = 0; - set_f(hTdCngDec->lp_env, 0.0f, NUM_ENV_CNG); - set_f(hTdCngDec->exc_mem, 0.0f, 24); - set_f(hTdCngDec->exc_mem1, 0.0f, 30); - set_f(hTdCngDec->old_env, 0.0f, NUM_ENV_CNG); - - for (i = 0; i < LPC_SHB_ORDER; i++) - { - if (st->element_mode != EVS_MONO) - { - hTdCngDec->lsp_shb_prev[i] = 0.5f * ((float)(i + 1)) / ((float)(LPC_SHB_ORDER + 1)); + int16_t i; + TD_CNG_DEC_HANDLE hTdCngDec; + + hTdCngDec = st->hTdCngDec; + + hTdCngDec->cng_seed = RANDOM_INITSEED; + hTdCngDec->cng_ener_seed = RANDOM_INITSEED; + hTdCngDec->cng_ener_seed1 = RANDOM_INITSEED; + hTdCngDec->old_enr_index = -1; + hTdCngDec->Enew = 0.0f; + mvr2r( st->lsp_old, st->lspCNG, M ); + hTdCngDec->last_allow_cn_step = 0; + hTdCngDec->shb_cng_ener = -6.02f; + if ( st->element_mode != EVS_MONO ) + { + set_f( hTdCngDec->shb_lpcCNG, 0.0f, LPC_SHB_ORDER + 1 ); + hTdCngDec->shb_lpcCNG[0] = 1.0f; + hTdCngDec->shb_cng_gain = -82.0; /* a dB value approximately corresponding to shb index 0(used as index -15) */ } - else + + hTdCngDec->wb_cng_ener = -6.02f; + hTdCngDec->last_wb_cng_ener = -6.02f; + hTdCngDec->last_shb_cng_ener = -6.02f; + hTdCngDec->swb_cng_seed = RANDOM_INITSEED; + hTdCngDec->ho_hist_ptr = -1; + hTdCngDec->ho_sid_bw = 0; + set_f( hTdCngDec->ho_lsp_hist, 0, HO_HIST_SIZE * M ); + set_f( hTdCngDec->ho_ener_hist, 0, HO_HIST_SIZE ); + set_f( hTdCngDec->ho_env_hist, 0, HO_HIST_SIZE * NUM_ENV_CNG ); + hTdCngDec->ho_hist_size = 0; + hTdCngDec->act_cnt = 0; + hTdCngDec->ho_circ_ptr = -1; + set_f( hTdCngDec->ho_lsp_circ, 0, HO_HIST_SIZE * M ); + set_f( hTdCngDec->ho_ener_circ, 0, HO_HIST_SIZE ); + set_f( hTdCngDec->ho_env_circ, 0, HO_HIST_SIZE * NUM_ENV_CNG ); + hTdCngDec->ho_circ_size = 0; + + set_s( hTdCngDec->ho_16k_lsp, 0, HO_HIST_SIZE ); + st->CNG_mode = -1; + hTdCngDec->act_cnt2 = 0; + hTdCngDec->num_ho = 0; + set_f( hTdCngDec->lp_env, 0.0f, NUM_ENV_CNG ); + set_f( hTdCngDec->exc_mem, 0.0f, 24 ); + set_f( hTdCngDec->exc_mem1, 0.0f, 30 ); + set_f( hTdCngDec->old_env, 0.0f, NUM_ENV_CNG ); + + for ( i = 0; i < LPC_SHB_ORDER; i++ ) { - hTdCngDec->lsp_shb_prev[i] = 0.5f * ((float)i) / ((float)LPC_SHB_ORDER); + if ( st->element_mode != EVS_MONO ) + { + hTdCngDec->lsp_shb_prev[i] = 0.5f * ( (float) ( i + 1 ) ) / ( (float) ( LPC_SHB_ORDER + 1 ) ); + } + else + { + hTdCngDec->lsp_shb_prev[i] = 0.5f * ( (float) i ) / ( (float) LPC_SHB_ORDER ); + } + hTdCngDec->lsp_shb_prev_prev[i] = hTdCngDec->lsp_shb_prev[i]; } - hTdCngDec->lsp_shb_prev_prev[i] = hTdCngDec->lsp_shb_prev[i]; - } - hTdCngDec->shb_dtx_count = 0; - hTdCngDec->trans_cnt = 0; - hTdCngDec->burst_cnt = 0; + hTdCngDec->shb_dtx_count = 0; + hTdCngDec->trans_cnt = 0; + hTdCngDec->burst_cnt = 0; - hTdCngDec->last_shb_ener = 0.001f; + hTdCngDec->last_shb_ener = 0.001f; - set_f(hTdCngDec->interpol_3_2_cng_dec, 0.0f, INTERP_3_2_MEM_LEN); + set_f( hTdCngDec->interpol_3_2_cng_dec, 0.0f, INTERP_3_2_MEM_LEN ); - return; + return; } #endif -#endif \ No newline at end of file +#endif diff --git a/lib_dec/cng_dec_fx.c b/lib_dec/cng_dec_fx.c index daa789153..6377fa019 100644 --- a/lib_dec/cng_dec_fx.c +++ b/lib_dec/cng_dec_fx.c @@ -3,7 +3,7 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ +#include "options.h" /* Compilation switches */ #include "cnst.h" #include "rom_com.h" #include "prot.h" @@ -12,15 +12,15 @@ #include "ivas_cnst.h" /*Temporary location to be move in prot* when merge is done*/ -void E_LPC_f_isp_a_conversion(const Word16 *isp, Word16 *a, const Word16 m); -void E_LPC_f_lsp_a_conversion(const Word16 *isp, Word16 *a, const Word16 m); +void E_LPC_f_isp_a_conversion( const Word16 *isp, Word16 *a, const Word16 m ); +void E_LPC_f_lsp_a_conversion( const Word16 *isp, Word16 *a, const Word16 m ); /*-----------------------------------------------------------------* * Local function prototypes *-----------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -static void shb_CNG_decod_fx( Decoder_State *st_fx, const Word16 *synth_fx, Word16 *shb_synth_fx, const Word16 sid_bw,const Word16 Qsyn); +static void shb_CNG_decod_fx( Decoder_State *st_fx, const Word16 *synth_fx, Word16 *shb_synth_fx, const Word16 sid_bw, const Word16 Qsyn ); #endif #ifdef IVAS_FLOAT_FIXED @@ -33,29 +33,29 @@ static void shb_CNG_decod_ivas_fx( Decoder_State *st_fx, const Word16 *synth_fx, #ifdef IVAS_FLOAT_FIXED void CNG_dec_fx( - Decoder_State *st_fx, /* i/o: State structure */ - const Word16 last_element_mode, /* i : last element mode Q0 */ - Word16 Aq[], /* o : LP coefficients Q12 */ - Word16 *lsp_new, /* i/o: current frame LSPs Q15 */ - Word16 *lsf_new, /* i/o: current frame LSFs Qlog2(2.56) */ - Word16 *allow_cn_step, /* o : allow CN step Q0 */ - Word16 *sid_bw /* i : 0-NB/WB, 1-SWB SID */ - ,Word32 *q_env -) + Decoder_State *st_fx, /* i/o: State structure */ + const Word16 last_element_mode, /* i : last element mode Q0 */ + Word16 Aq[], /* o : LP coefficients Q12 */ + Word16 *lsp_new, /* i/o: current frame LSPs Q15 */ + Word16 *lsf_new, /* i/o: current frame LSFs Qlog2(2.56) */ + Word16 *allow_cn_step, /* o : allow CN step Q0 */ + Word16 *sid_bw /* i : 0-NB/WB, 1-SWB SID */ + , + Word32 *q_env ) { Word16 istep; Word16 i, L_enr_index; Word32 L_ener; - Word16 ener_fra,ener_int; + Word16 ener_fra, ener_int; Word16 num_bits; Word16 weights, ptr, j, k; Word16 m1; Word16 m = 0; - Word16 tmp[HO_HIST_SIZE*M]; + Word16 tmp[HO_HIST_SIZE * M]; Word16 burst_ho_cnt = 0; - Word16 ll,s_ptr; - Word32 L_enr,L_tmp1; - Word16 tmp1,exp; + Word16 ll, s_ptr; + Word32 L_enr, L_tmp1; + Word16 tmp1, exp; Word16 lsf_tmp[M]; Word32 C[M]; Word32 max_val[2]; @@ -69,7 +69,7 @@ void CNG_dec_fx( Word16 env_idx[2]; Word32 enr1; Word32 env[NUM_ENV_CNG]; - Word32 tmp_env[HO_HIST_SIZE*NUM_ENV_CNG]; + Word32 tmp_env[HO_HIST_SIZE * NUM_ENV_CNG]; Word32 L_tmp; Word16 fra; Word16 temp_lo_fx, temp_hi_fx; @@ -77,7 +77,7 @@ void CNG_dec_fx( Word16 tmp_loop; Word16 enr_new, Aq_tmp[M + 1]; - Word16 LSF_Q_prediction; /* o : LSF prediction mode - just temporary variable in CNG */ + Word16 LSF_Q_prediction; /* o : LSF prediction mode - just temporary variable in CNG */ TD_CNG_DEC_HANDLE hTdCngDec; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; @@ -90,42 +90,43 @@ void CNG_dec_fx( * Decode CNG spectral envelope (only in SID frame) *-----------------------------------------------------------------*/ test(); - IF ( EQ_32(st_fx->core_brate,SID_1k75) || EQ_32(st_fx->core_brate,SID_2k40)) + IF( EQ_32( st_fx->core_brate, SID_1k75 ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) { /* de-quantize the LSF vector */ - IF ( st_fx->Opt_AMR_WB != 0 ) + IF( st_fx->Opt_AMR_WB != 0 ) { /* Flt function */ - isf_dec_amr_wb_fx( st_fx, Aq, lsf_new, lsp_new); + isf_dec_amr_wb_fx( st_fx, Aq, lsf_new, lsp_new ); /* check if ISPs may trigger too much synthesis energy */ - - E_LPC_f_isp_a_conversion(lsp_new, Aq_tmp, M); - enr_new = Enr_1_Az_fx(Aq_tmp, 2 * L_SUBFR); - - IF ((shr(enr_new, 14) > 0)) + + E_LPC_f_isp_a_conversion( lsp_new, Aq_tmp, M ); + enr_new = Enr_1_Az_fx( Aq_tmp, 2 * L_SUBFR ); + + IF( ( shr( enr_new, 14 ) > 0 ) ) { /* Use old LSP vector */ - Copy(st_fx->lsp_old_fx, lsp_new, M); - Copy(st_fx->lsf_old_fx, lsf_new, M); + Copy( st_fx->lsp_old_fx, lsp_new, M ); + Copy( st_fx->lsf_old_fx, lsf_new, M ); } } ELSE { lsf_dec_fx( st_fx, 0, Aq, &LSF_Q_prediction, lsf_new, lsp_new, 0, 0 #ifdef LSF_RE_USE_SECONDARY_CHANNEL - ,NULL + , + NULL #endif - ); + ); /* check if LSPs may trigger too much synthesis energy */ - - E_LPC_f_lsp_a_conversion(lsp_new, Aq_tmp, M); - enr_new = Enr_1_Az_fx(Aq_tmp, 2 * L_SUBFR); - - IF(shr(enr_new, 14) > 0) + + E_LPC_f_lsp_a_conversion( lsp_new, Aq_tmp, M ); + enr_new = Enr_1_Az_fx( Aq_tmp, 2 * L_SUBFR ); + + IF( shr( enr_new, 14 ) > 0 ) { /* Use old LSP vector */ - Copy(st_fx->lsp_old_fx, lsp_new, M); - Copy(st_fx->lsf_old_fx, lsf_new, M); + Copy( st_fx->lsp_old_fx, lsp_new, M ); + Copy( st_fx->lsf_old_fx, lsf_new, M ); } } } @@ -149,11 +150,11 @@ void CNG_dec_fx( *allow_cn_step = 0; move16(); test(); - IF( EQ_32(st_fx->core_brate,SID_1k75) || EQ_32(st_fx->core_brate,SID_2k40)) + IF( EQ_32( st_fx->core_brate, SID_1k75 ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) { - istep = ISTEP_AMR_WB_SID_FX; + istep = ISTEP_AMR_WB_SID_FX; move16(); - if( EQ_32(st_fx->core_brate,SID_2k40)) + if ( EQ_32( st_fx->core_brate, SID_2k40 ) ) { istep = ISTEP_SID_FX; move16(); @@ -162,7 +163,7 @@ void CNG_dec_fx( /* initialize the energy quantization parameters */ num_bits = 6; move16(); - if( st_fx->Opt_AMR_WB == 0 ) + if ( st_fx->Opt_AMR_WB == 0 ) { num_bits = 7; move16(); @@ -171,31 +172,32 @@ void CNG_dec_fx( /* decode the energy index */ L_enr_index = get_next_indice( st_fx, num_bits ); - IF( LE_32(st_fx->last_core_brate, SID_2k40) || EQ_16(st_fx->prev_bfi, 1) ) + IF( LE_32( st_fx->last_core_brate, SID_2k40 ) || EQ_16( st_fx->prev_bfi, 1 ) ) { - tmp1 = add(hTdCngDec->old_enr_index, 20); + tmp1 = add( hTdCngDec->old_enr_index, 20 ); } ELSE { - tmp1 = add(hTdCngDec->old_enr_index, 40); + tmp1 = add( hTdCngDec->old_enr_index, 40 ); } - IF( GT_16(L_enr_index, tmp1) && hTdCngDec->old_enr_index >= 0 ) /* Likely bit error and not startup */ + IF( GT_16( L_enr_index, tmp1 ) && hTdCngDec->old_enr_index >= 0 ) /* Likely bit error and not startup */ { - L_enr_index = tmp1; move16(); - L_enr_index = s_min(L_enr_index, 127); - if (st_fx->Opt_AMR_WB != 0) + L_enr_index = tmp1; + move16(); + L_enr_index = s_min( L_enr_index, 127 ); + if ( st_fx->Opt_AMR_WB != 0 ) { - L_enr_index = s_min(L_enr_index, 63); + L_enr_index = s_min( L_enr_index, 63 ); } } test(); test(); test(); - IF (GT_32(st_fx->last_core_brate,SID_1k75)&& - st_fx->first_CNG != 0 && - hTdCngDec->old_enr_index >= 0 && - GT_16(L_enr_index, add(hTdCngDec->old_enr_index,1))) + IF( GT_32( st_fx->last_core_brate, SID_1k75 ) && + st_fx->first_CNG != 0 && + hTdCngDec->old_enr_index >= 0 && + GT_16( L_enr_index, add( hTdCngDec->old_enr_index, 1 ) ) ) { *allow_cn_step = 1; move16(); @@ -209,37 +211,37 @@ void CNG_dec_fx( move16(); } /* st_fx->Enew = L_enr_index / step - 2.0f;*/ - L_ener = L_mult(L_enr_index, istep); /* Q16 (0+15) */ + L_ener = L_mult( L_enr_index, istep ); /* Q16 (0+15) */ /* subtract by 2 not done to leave Energy in Q2 */ /* extract integral and fractional parts */ - ener_fra = L_Extract_lc(L_ener, &ener_int); - ener_int = add(ener_int, 4); /* Q2 to Q6 */ + ener_fra = L_Extract_lc( L_ener, &ener_int ); + ener_int = add( ener_int, 4 ); /* Q2 to Q6 */ /* find the new energy value */ - hTdCngDec->Enew_fx = Pow2(ener_int, ener_fra); + hTdCngDec->Enew_fx = Pow2( ener_int, ener_fra ); - IF( EQ_32(st_fx->core_brate,SID_2k40)) + IF( EQ_32( st_fx->core_brate, SID_2k40 ) ) { burst_ho_cnt = get_next_indice( st_fx, 3 ); /* 3bit */ *sid_bw = get_next_indice( st_fx, 1 ); - IF ( *sid_bw == 0 ) + IF( *sid_bw == 0 ) { env_idx[0] = get_next_indice( st_fx, 6 ); move16(); /* get quantized res_env_details */ - FOR ( i=0; ibwidth,WB) && st_fx->first_CNG!=0 && NE_16(st_fx->L_frame,st_fx->last_CNG_L_frame)) + IF( EQ_16( st_fx->bwidth, WB ) && st_fx->first_CNG != 0 && NE_16( st_fx->L_frame, st_fx->last_CNG_L_frame ) ) { hTdCngDec->ho_hist_size = 0; move16(); @@ -256,19 +258,19 @@ void CNG_dec_fx( IF( st_fx->last_core_brate <= SID_2k40 ) { /* Reset hangover counter if not first SID period */ - if( GT_32(st_fx->core_brate,FRAME_NO_DATA)) + if ( GT_32( st_fx->core_brate, FRAME_NO_DATA ) ) { hTdCngDec->num_ho = 0; move16(); } /* Update LSPs if last SID energy not outliers or insufficient number of hangover frames */ test(); - IF( LT_16(hTdCngDec->num_ho,3) || LT_32(Mult_32_16(hTdCngDec->Enew_fx,21845/*1/1.5f, Q15*/),st_fx->lp_ener_fx)) + IF( LT_16( hTdCngDec->num_ho, 3 ) || LT_32( Mult_32_16( hTdCngDec->Enew_fx, 21845 /*1/1.5f, Q15*/ ), st_fx->lp_ener_fx ) ) { - FOR( i=0; ilspCNG_fx[i] = mac_r(L_mult(CNG_ISF_FACT_FX, st_fx->lspCNG_fx[i]), 32768-CNG_ISF_FACT_FX, lsp_new[i]); + st_fx->lspCNG_fx[i] = mac_r( L_mult( CNG_ISF_FACT_FX, st_fx->lspCNG_fx[i] ), 32768 - CNG_ISF_FACT_FX, lsp_new[i] ); move16(); /* Q15 (15+15+1-16) */ } } @@ -279,36 +281,35 @@ void CNG_dec_fx( test(); test(); test(); - IF( ( st_fx->Opt_AMR_WB || EQ_16(st_fx->bwidth,WB)) - && ( !st_fx->first_CNG || GE_16(hTdCngDec->act_cnt2,MIN_ACT_CNG_UPD) ) ) + IF( ( st_fx->Opt_AMR_WB || EQ_16( st_fx->bwidth, WB ) ) && ( !st_fx->first_CNG || GE_16( hTdCngDec->act_cnt2, MIN_ACT_CNG_UPD ) ) ) { - IF( GT_32(st_fx->last_active_brate,ACELP_16k40)) + IF( GT_32( st_fx->last_active_brate, ACELP_16k40 ) ) { st_fx->CNG_mode = -1; move16(); } ELSE { - st_fx->CNG_mode = get_cng_mode(st_fx->last_active_brate); + st_fx->CNG_mode = get_cng_mode( st_fx->last_active_brate ); move16(); } } /* If first sid after active burst update LSF history from circ buffer */ - burst_ho_cnt = s_min(burst_ho_cnt, hTdCngDec->ho_circ_size); /* MODE1_DTX_IN_CODEC_B_FIX */ + burst_ho_cnt = s_min( burst_ho_cnt, hTdCngDec->ho_circ_size ); /* MODE1_DTX_IN_CODEC_B_FIX */ hTdCngDec->act_cnt = 0; move16(); - s_ptr = add(sub(hTdCngDec->ho_circ_ptr, burst_ho_cnt),1); + s_ptr = add( sub( hTdCngDec->ho_circ_ptr, burst_ho_cnt ), 1 ); move16(); - if( s_ptr < 0 ) + if ( s_ptr < 0 ) { - s_ptr = add(s_ptr, hTdCngDec->ho_circ_size); + s_ptr = add( s_ptr, hTdCngDec->ho_circ_size ); } FOR( ll = burst_ho_cnt; ll > 0; ll-- ) { - hTdCngDec->ho_hist_ptr = add(hTdCngDec->ho_hist_ptr,1); - if( EQ_16(hTdCngDec->ho_hist_ptr, HO_HIST_SIZE)) + hTdCngDec->ho_hist_ptr = add( hTdCngDec->ho_hist_ptr, 1 ); + if ( EQ_16( hTdCngDec->ho_hist_ptr, HO_HIST_SIZE ) ) { hTdCngDec->ho_hist_ptr = 0; move16(); @@ -318,142 +319,144 @@ void CNG_dec_fx( test(); test(); test(); - IF( ( EQ_16(st_fx->L_frame,L_FRAME16k) && hTdCngDec->ho_16k_lsp[s_ptr]==0) || (EQ_16(st_fx->L_frame,L_FRAME) && EQ_16(hTdCngDec->ho_16k_lsp[s_ptr],1))) + IF( ( EQ_16( st_fx->L_frame, L_FRAME16k ) && hTdCngDec->ho_16k_lsp[s_ptr] == 0 ) || ( EQ_16( st_fx->L_frame, L_FRAME ) && EQ_16( hTdCngDec->ho_16k_lsp[s_ptr], 1 ) ) ) { /* Conversion from 16k LPSs to 12k8 */ - lsp_convert_poly_fx( &(hTdCngDec->ho_lsp_circ_fx[s_ptr*M]), st_fx->L_frame, 0 ); + lsp_convert_poly_fx( &( hTdCngDec->ho_lsp_circ_fx[s_ptr * M] ), st_fx->L_frame, 0 ); } /* update the circular buffers */ - Copy(&(hTdCngDec->ho_lsp_circ_fx[s_ptr*M]), &(hTdCngDec->ho_lsp_hist_fx[hTdCngDec->ho_hist_ptr*M]), M ); - Copy32(&(hTdCngDec->ho_ener_circ_fx[s_ptr]), &(hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr]), 1 ); - hTdCngDec->ho_sid_bw = L_shl(L_and(hTdCngDec->ho_sid_bw, (Word32) 0x3fffffffL ), 1); - Copy32(&(hTdCngDec->ho_env_circ_fx[s_ptr*NUM_ENV_CNG]), &(hTdCngDec->ho_env_hist_fx[hTdCngDec->ho_hist_ptr*NUM_ENV_CNG]), NUM_ENV_CNG ); + Copy( &( hTdCngDec->ho_lsp_circ_fx[s_ptr * M] ), &( hTdCngDec->ho_lsp_hist_fx[hTdCngDec->ho_hist_ptr * M] ), M ); + Copy32( &( hTdCngDec->ho_ener_circ_fx[s_ptr] ), &( hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr] ), 1 ); + hTdCngDec->ho_sid_bw = L_shl( L_and( hTdCngDec->ho_sid_bw, (Word32) 0x3fffffffL ), 1 ); + Copy32( &( hTdCngDec->ho_env_circ_fx[s_ptr * NUM_ENV_CNG] ), &( hTdCngDec->ho_env_hist_fx[hTdCngDec->ho_hist_ptr * NUM_ENV_CNG] ), NUM_ENV_CNG ); - hTdCngDec->ho_hist_size = add(hTdCngDec->ho_hist_size,1); + hTdCngDec->ho_hist_size = add( hTdCngDec->ho_hist_size, 1 ); - if (GT_16(hTdCngDec->ho_hist_size, HO_HIST_SIZE)) + if ( GT_16( hTdCngDec->ho_hist_size, HO_HIST_SIZE ) ) { hTdCngDec->ho_hist_size = HO_HIST_SIZE; move16(); } - s_ptr = add(s_ptr,1); - if( EQ_16(s_ptr, hTdCngDec->ho_circ_size)) + s_ptr = add( s_ptr, 1 ); + if ( EQ_16( s_ptr, hTdCngDec->ho_circ_size ) ) { s_ptr = 0; move16(); } } - IF(hTdCngDec->ho_hist_size > 0 ) /* can be -1 at init MODE1_DTX_IN_CODEC_B_FIX */ + IF( hTdCngDec->ho_hist_size > 0 ) /* can be -1 at init MODE1_DTX_IN_CODEC_B_FIX */ { /* *allow_cn_step |= ( st_fx->ho_ener_hist[st_fx->ho_hist_ptr] > 4.0f * st_fx->lp_ener );*/ - L_tmp1 = L_shr(hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr], 2); - L_tmp1 = L_sub(L_tmp1, st_fx->lp_ener_fx); + L_tmp1 = L_shr( hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr], 2 ); + L_tmp1 = L_sub( L_tmp1, st_fx->lp_ener_fx ); - test(); test(); - if( ( L_tmp1 > 0 && (st_fx->first_CNG || EQ_16(st_fx->element_mode, EVS_MONO) ) ) ) + test(); + test(); + if ( ( L_tmp1 > 0 && ( st_fx->first_CNG || EQ_16( st_fx->element_mode, EVS_MONO ) ) ) ) { - *allow_cn_step = s_or(*allow_cn_step,1); + *allow_cn_step = s_or( *allow_cn_step, 1 ); } } - IF ( EQ_16(last_element_mode, IVAS_CPE_TD) ) + IF( EQ_16( last_element_mode, IVAS_CPE_TD ) ) { *allow_cn_step = 1; move16(); } test(); - IF ( *allow_cn_step == 0 && hTdCngDec->ho_hist_size > 0 ) + IF( *allow_cn_step == 0 && hTdCngDec->ho_hist_size > 0 ) { /* Use average of energies below last energy */ ptr = hTdCngDec->ho_hist_ptr; move16(); - Copy( &(hTdCngDec->ho_lsp_hist_fx[ptr*M]), tmp, M ); + Copy( &( hTdCngDec->ho_lsp_hist_fx[ptr * M] ), tmp, M ); m1 = 0; move16(); - IF( L_and(hTdCngDec->ho_sid_bw, (Word32) 0x1) == 0 ) + IF( L_and( hTdCngDec->ho_sid_bw, (Word32) 0x1 ) == 0 ) { - Copy32( &hTdCngDec->ho_env_hist_fx[ptr*NUM_ENV_CNG], tmp_env, NUM_ENV_CNG ); + Copy32( &hTdCngDec->ho_env_hist_fx[ptr * NUM_ENV_CNG], tmp_env, NUM_ENV_CNG ); m1 = 1; move16(); } - L_enr = Mult_32_16(hTdCngDec->ho_ener_hist_fx[ptr],W_DTX_HO_FX[0]) ;/* Q6+15-15->Q6 */ + L_enr = Mult_32_16( hTdCngDec->ho_ener_hist_fx[ptr], W_DTX_HO_FX[0] ); /* Q6+15-15->Q6 */ weights = W_DTX_HO_FX[0]; /* Q15 */ m = 1; move16(); - FOR( k=1; k< hTdCngDec->ho_hist_size; k++ ) + FOR( k = 1; k < hTdCngDec->ho_hist_size; k++ ) { - ptr = sub(ptr,1); - if( ptr < 0 ) + ptr = sub( ptr, 1 ); + if ( ptr < 0 ) { ptr = HO_HIST_SIZE - 1; move16(); } test(); - IF ( LT_32(Mult_32_16(hTdCngDec->ho_ener_hist_fx[ptr],ONE_OVER_BUF_H_NRG_FX), hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr])&& - GT_32(hTdCngDec->ho_ener_hist_fx[ptr],Mult_32_16(hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr], BUF_L_NRG_FX))) + IF( LT_32( Mult_32_16( hTdCngDec->ho_ener_hist_fx[ptr], ONE_OVER_BUF_H_NRG_FX ), hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr] ) && + GT_32( hTdCngDec->ho_ener_hist_fx[ptr], Mult_32_16( hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr], BUF_L_NRG_FX ) ) ) { /*enr += W_DTX_HO[k] * st_fx->ho_ener_hist[ptr];*/ - L_tmp1 = Mult_32_16(hTdCngDec->ho_ener_hist_fx[ptr],W_DTX_HO_FX[k]) ; /* Q6+15-15->Q6 */ - L_enr = L_add(L_enr,L_tmp1); /* Q6 */ + L_tmp1 = Mult_32_16( hTdCngDec->ho_ener_hist_fx[ptr], W_DTX_HO_FX[k] ); /* Q6+15-15->Q6 */ + L_enr = L_add( L_enr, L_tmp1 ); /* Q6 */ /*weights += W_DTX_HO[k];*/ - weights = add( weights, W_DTX_HO_FX[k]); /* Q15 */ + weights = add( weights, W_DTX_HO_FX[k] ); /* Q15 */ - Copy( &hTdCngDec->ho_lsp_hist_fx[ptr*M], &tmp[m*M], M ); - IF( L_and(hTdCngDec->ho_sid_bw, L_shl((Word32)0x1,k)) == 0 ) + Copy( &hTdCngDec->ho_lsp_hist_fx[ptr * M], &tmp[m * M], M ); + IF( L_and( hTdCngDec->ho_sid_bw, L_shl( (Word32) 0x1, k ) ) == 0 ) { - Copy32( &hTdCngDec->ho_env_hist_fx[ptr*NUM_ENV_CNG], &tmp_env[m1*NUM_ENV_CNG], NUM_ENV_CNG ); - m1 = add(m1,1); + Copy32( &hTdCngDec->ho_env_hist_fx[ptr * NUM_ENV_CNG], &tmp_env[m1 * NUM_ENV_CNG], NUM_ENV_CNG ); + m1 = add( m1, 1 ); } - m = add(m,1); + m = add( m, 1 ); } } /*enr /= weights;*/ - exp = norm_s(weights); - tmp1 = div_s(shl(1,sub(14,exp)),weights); /* Q(15+14-exp-15) */ - L_tmp1 = Mult_32_16(L_enr,tmp1); /* Q(14-exp+6-15)->Q(5-exp) */ - L_enr = L_shl(L_tmp1,exp+1); /* Q6 */ + exp = norm_s( weights ); + tmp1 = div_s( shl( 1, sub( 14, exp ) ), weights ); /* Q(15+14-exp-15) */ + L_tmp1 = Mult_32_16( L_enr, tmp1 ); /* Q(14-exp+6-15)->Q(5-exp) */ + L_enr = L_shl( L_tmp1, exp + 1 ); /* Q6 */ st_fx->lp_ener_fx = L_enr; /* Q6 */ set32_fx( max_val, 0, 2 ); set16_fx( max_idx, 0, 2 ); - FOR( i=0; iL_frame,L_FRAME)) + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { - lsp2lsf_fx( &tmp[i*M], lsf_tmp, M, INT_FS_FX ); + lsp2lsf_fx( &tmp[i * M], lsf_tmp, M, INT_FS_FX ); ftmp_fx = 964; - move16();/*X2.56 */ - tmpv = sub(16384,add(lsf_tmp[M-1],ftmp_fx)); /*QX2.56*/ - L_tmp = L_mult0(tmpv,tmpv); /*QX6.5536*/ + move16(); /*X2.56 */ + tmpv = sub( 16384, add( lsf_tmp[M - 1], ftmp_fx ) ); /*QX2.56*/ + L_tmp = L_mult0( tmpv, tmpv ); /*QX6.5536*/ } ELSE { - lsp2lsf_fx( &tmp[i*M], lsf_tmp, M, INT_FS_16k_FX ); + lsp2lsf_fx( &tmp[i * M], lsf_tmp, M, INT_FS_16k_FX ); ftmp_fx = 1205; - move16();/*QX2.56*/ - tmpv = sub(20480,add(lsf_tmp[M-1],ftmp_fx)); /*QX2.56*/ - L_tmp = L_mult0(tmpv,tmpv); /*QX6.5536*/ + move16(); /*QX2.56*/ + tmpv = sub( 20480, add( lsf_tmp[M - 1], ftmp_fx ) ); /*QX2.56*/ + L_tmp = L_mult0( tmpv, tmpv ); /*QX6.5536*/ } - tmpv = sub(lsf_tmp[0],ftmp_fx); /*QX2.56*/ - L_tmp = L_mac0(L_tmp,tmpv,tmpv); /*QX6.5536*/ - FOR ( j=0; jlspCNG_fx[i] = lsp_tmp[i]; move16(); /*Q15*/ @@ -538,127 +541,128 @@ void CNG_dec_fx( } ELSE { - FOR( i=0; ilspCNG_fx[i] = add(mult_r(26214,lsp_tmp[i]),mult_r(6554,lsp_new[i])); + st_fx->lspCNG_fx[i] = add( mult_r( 26214, lsp_tmp[i] ), mult_r( 6554, lsp_new[i] ) ); } } IF( m1 > 0 ) { - FOR ( i=0; ilp_ener_fx; */ - IF(EQ_16(m1,1)) + IF( EQ_16( m1, 1 ) ) { #ifdef BASOP_NOGLOB L_tmp = L_sub_sat( L_tmp, L_add_sat( st_fx->lp_ener_fx, st_fx->lp_ener_fx ) ); #else - L_tmp = L_sub(L_tmp,L_add(st_fx->lp_ener_fx,st_fx->lp_ener_fx)); + L_tmp = L_sub( L_tmp, L_add( st_fx->lp_ener_fx, st_fx->lp_ener_fx ) ); #endif } ELSE { - tmp1 = div_s(1,m1); - L_tmp = Mult_32_16(L_tmp,tmp1); + tmp1 = div_s( 1, m1 ); + L_tmp = Mult_32_16( L_tmp, tmp1 ); #ifdef BASOP_NOGLOB L_tmp = L_sub_sat( L_tmp, L_add_sat( st_fx->lp_ener_fx, st_fx->lp_ener_fx ) ); #else - L_tmp = L_sub(L_tmp,L_add(st_fx->lp_ener_fx,st_fx->lp_ener_fx)); + L_tmp = L_sub( L_tmp, L_add( st_fx->lp_ener_fx, st_fx->lp_ener_fx ) ); #endif } env[i] = L_tmp; move32(); } - Copy32(env, hTdCngDec->lp_env_fx, NUM_ENV_CNG); + Copy32( env, hTdCngDec->lp_env_fx, NUM_ENV_CNG ); } } ELSE { - Copy( lsp_new, st_fx->lspCNG_fx, M ); /* use newly analyzed ISFs */ + Copy( lsp_new, st_fx->lspCNG_fx, M ); /* use newly analyzed ISFs */ } } test(); - IF( EQ_32(st_fx->core_brate, SID_1k75) || EQ_32(st_fx->core_brate,SID_2k40)) + IF( EQ_32( st_fx->core_brate, SID_1k75 ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) { /* Update hangover memory during CNG */ test(); #ifdef BASOP_NOGLOB IF( *allow_cn_step == 0 && LT_32( hTdCngDec->Enew_fx, L_add_sat( st_fx->lp_ener_fx, L_shr( st_fx->lp_ener_fx, 1 ) ) ) ) #else - IF ( *allow_cn_step == 0 && LT_32(hTdCngDec->Enew_fx,L_add(st_fx->lp_ener_fx,L_shr(st_fx->lp_ener_fx,1)))) + IF( *allow_cn_step == 0 && LT_32( hTdCngDec->Enew_fx, L_add( st_fx->lp_ener_fx, L_shr( st_fx->lp_ener_fx, 1 ) ) ) ) #endif { /* update the pointer to circular buffer of old LSP vectors */ - hTdCngDec->ho_hist_ptr = add(hTdCngDec->ho_hist_ptr, 1); - if( EQ_16(hTdCngDec->ho_hist_ptr,HO_HIST_SIZE)) + hTdCngDec->ho_hist_ptr = add( hTdCngDec->ho_hist_ptr, 1 ); + if ( EQ_16( hTdCngDec->ho_hist_ptr, HO_HIST_SIZE ) ) { hTdCngDec->ho_hist_ptr = 0; move16(); } /* update the circular buffer of old LSP vectors with the new LSP vector */ - Copy( lsp_new, &(hTdCngDec->ho_lsp_hist_fx[(hTdCngDec->ho_hist_ptr)*M]), M ); + Copy( lsp_new, &( hTdCngDec->ho_lsp_hist_fx[( hTdCngDec->ho_hist_ptr ) * M] ), M ); /* update the hangover energy buffer */ hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr] = hTdCngDec->Enew_fx; move32(); test(); - IF ( EQ_32(st_fx->core_brate,SID_2k40)&&*sid_bw==0) + IF( EQ_32( st_fx->core_brate, SID_2k40 ) && *sid_bw == 0 ) { /* enr1 = (float)log10( st->Enew*L_frame + 0.1f ) / (float)log10( 2.0f );*/ - exp = norm_l(hTdCngDec->Enew_fx); - L_tmp = L_shl(hTdCngDec->Enew_fx,exp);/*Q(exp+6)*/ - L_tmp = Mult_32_16(L_tmp,shl(st_fx->L_frame,5));/*Q(exp+6+5-15=exp-4)*/ + exp = norm_l( hTdCngDec->Enew_fx ); + L_tmp = L_shl( hTdCngDec->Enew_fx, exp ); /*Q(exp+6)*/ + L_tmp = Mult_32_16( L_tmp, shl( st_fx->L_frame, 5 ) ); /*Q(exp+6+5-15=exp-4)*/ #ifdef BASOP_NOGLOB L_tmp = L_shr_sat( L_tmp, sub( exp, 10 ) ); /*Q6*/ #else - L_tmp = L_shr( L_tmp, sub( exp, 10 ) ); /*Q6*/ + L_tmp = L_shr( L_tmp, sub( exp, 10 ) ); /*Q6*/ #endif - exp = norm_l(L_tmp); - fra = Log2_norm_lc(L_shl(L_tmp,exp)); - exp = sub(sub(30,exp),6); - L_tmp = L_Comp(exp,fra); - enr1 = L_shr(L_tmp,10);/* Q6 */ + exp = norm_l( L_tmp ); + fra = Log2_norm_lc( L_shl( L_tmp, exp ) ); + exp = sub( sub( 30, exp ), 6 ); + L_tmp = L_Comp( exp, fra ); + enr1 = L_shr( L_tmp, 10 ); /* Q6 */ - FOR ( i=0; iEnew;*/ - L_tmp = L_sub(enr1,q_env[i]);/* Q6 */ - L_tmp = L_shl(L_tmp, 10);/* 16 */ - temp_lo_fx = L_Extract_lc(L_tmp, &temp_hi_fx); - - exp_pow = sub(14, temp_hi_fx); - L_tmp = Pow2(14, temp_lo_fx); /* Qexp_pow */ - env[i] = L_shl(L_tmp, sub(6, exp_pow)); /* Q6 */ - L_tmp = L_add(hTdCngDec->Enew_fx, hTdCngDec->Enew_fx); - env[i] = L_add(env[i],L_tmp); /* Q6 */ move32(); + L_tmp = L_sub( enr1, q_env[i] ); /* Q6 */ + L_tmp = L_shl( L_tmp, 10 ); /* 16 */ + temp_lo_fx = L_Extract_lc( L_tmp, &temp_hi_fx ); + + exp_pow = sub( 14, temp_hi_fx ); + L_tmp = Pow2( 14, temp_lo_fx ); /* Qexp_pow */ + env[i] = L_shl( L_tmp, sub( 6, exp_pow ) ); /* Q6 */ + L_tmp = L_add( hTdCngDec->Enew_fx, hTdCngDec->Enew_fx ); + env[i] = L_add( env[i], L_tmp ); /* Q6 */ + move32(); } - hTdCngDec->ho_sid_bw = L_shl(L_and(hTdCngDec->ho_sid_bw, (Word32) 0x3fffffffL ), 1); - Copy32( env, &(hTdCngDec->ho_env_hist_fx[(hTdCngDec->ho_hist_ptr)*NUM_ENV_CNG]), NUM_ENV_CNG ); + hTdCngDec->ho_sid_bw = L_shl( L_and( hTdCngDec->ho_sid_bw, (Word32) 0x3fffffffL ), 1 ); + Copy32( env, &( hTdCngDec->ho_env_hist_fx[( hTdCngDec->ho_hist_ptr ) * NUM_ENV_CNG] ), NUM_ENV_CNG ); } ELSE IF( *sid_bw != 0 ) { - hTdCngDec->ho_sid_bw = L_shl(L_and(hTdCngDec->ho_sid_bw, (Word32) 0x3fffffffL ), 1); - hTdCngDec->ho_sid_bw = L_or(hTdCngDec->ho_sid_bw, 0x1L); + hTdCngDec->ho_sid_bw = L_shl( L_and( hTdCngDec->ho_sid_bw, (Word32) 0x3fffffffL ), 1 ); + hTdCngDec->ho_sid_bw = L_or( hTdCngDec->ho_sid_bw, 0x1L ); } - hTdCngDec->ho_hist_size = add(hTdCngDec->ho_hist_size,1); - if( GT_16(hTdCngDec->ho_hist_size,HO_HIST_SIZE)) + hTdCngDec->ho_hist_size = add( hTdCngDec->ho_hist_size, 1 ); + if ( GT_16( hTdCngDec->ho_hist_size, HO_HIST_SIZE ) ) { hTdCngDec->ho_hist_size = HO_HIST_SIZE; move16(); @@ -668,7 +672,7 @@ void CNG_dec_fx( st_fx->last_CNG_L_frame = st_fx->L_frame; move16(); - if( NE_32(st_fx->core_brate,SID_1k75)) + if ( NE_32( st_fx->core_brate, SID_1k75 ) ) { hTdCngDec->num_ho = m; move16(); @@ -678,13 +682,13 @@ void CNG_dec_fx( /* Update the frame length memory */ st_fx->last_CNG_L_frame = st_fx->L_frame; - if( NE_32(st_fx->core_brate,SID_1k75)) + if ( NE_32( st_fx->core_brate, SID_1k75 ) ) { hTdCngDec->num_ho = m; move16(); } - IF ( st_fx->Opt_AMR_WB ) + IF( st_fx->Opt_AMR_WB ) { E_LPC_f_isp_a_conversion( st_fx->lspCNG_fx, Aq, M ); } @@ -693,10 +697,10 @@ void CNG_dec_fx( E_LPC_f_lsp_a_conversion( st_fx->lspCNG_fx, Aq, M ); } - tmp_loop = shr(st_fx->L_frame,6); - FOR( i=1; iL_frame, 6 ); + FOR( i = 1; i < tmp_loop; i++ ) /* L_frame/L_SUBFR */ { - Copy( Aq, &Aq[i*(M+1)], M+1 ); + Copy( Aq, &Aq[i * ( M + 1 )], M + 1 ); } return; @@ -710,19 +714,20 @@ void CNG_dec_fx( *---------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED void swb_CNG_dec_fx( - Decoder_State *st_fx, /* i/o: State structure */ - const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz */ - Word16 *shb_synth_fx, /* o : high-band CNG synthesis */ - const Word16 sid_bw /* i : 0-NB/WB, 1-SWB SID */ - ,const Word16 Qsyn /* i : Q value of ACELP core synthesis */ + Decoder_State *st_fx, /* i/o: State structure */ + const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz */ + Word16 *shb_synth_fx, /* o : high-band CNG synthesis */ + const Word16 sid_bw /* i : 0-NB/WB, 1-SWB SID */ + , + const Word16 Qsyn /* i : Q value of ACELP core synthesis */ ) { test(); - IF ( st_fx->core_brate == FRAME_NO_DATA || EQ_32(st_fx->core_brate, SID_2k40)) + IF( st_fx->core_brate == FRAME_NO_DATA || EQ_32( st_fx->core_brate, SID_2k40 ) ) { /* SHB SID decoding and CNG */ test(); - IF (st_fx->cng_type == LP_CNG && EQ_16(st_fx->extl, SWB_CNG)) + IF( st_fx->cng_type == LP_CNG && EQ_16( st_fx->extl, SWB_CNG ) ) { shb_CNG_decod_fx( st_fx, synth_fx, shb_synth_fx, sid_bw, Qsyn ); } @@ -735,8 +740,8 @@ void swb_CNG_dec_fx( { st_fx->last_vad_fx = 1; move16(); - st_fx->hTdCngDec->burst_cnt = add(st_fx->hTdCngDec->burst_cnt, 1); - if ( GT_16(st_fx->hTdCngDec->burst_cnt, 10)) + st_fx->hTdCngDec->burst_cnt = add( st_fx->hTdCngDec->burst_cnt, 1 ); + if ( GT_16( st_fx->hTdCngDec->burst_cnt, 10 ) ) { st_fx->hTdCngDec->burst_cnt = 0; move16(); @@ -749,19 +754,20 @@ void swb_CNG_dec_fx( #ifdef IVAS_FLOAT_FIXED void swb_CNG_dec_ivas_fx( - Decoder_State *st_fx, /* i/o: State structure */ - const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz */ - Word16 *shb_synth_fx, /* o : high-band CNG synthesis */ - const Word16 sid_bw /* i : 0-NB/WB, 1-SWB SID */ - ,const Word16 Qsyn /* i : Q value of ACELP core synthesis */ + Decoder_State *st_fx, /* i/o: State structure */ + const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz */ + Word16 *shb_synth_fx, /* o : high-band CNG synthesis */ + const Word16 sid_bw /* i : 0-NB/WB, 1-SWB SID */ + , + const Word16 Qsyn /* i : Q value of ACELP core synthesis */ ) { test(); - IF ( st_fx->core_brate == FRAME_NO_DATA || EQ_32(st_fx->core_brate, SID_2k40)) + IF( st_fx->core_brate == FRAME_NO_DATA || EQ_32( st_fx->core_brate, SID_2k40 ) ) { /* SHB SID decoding and CNG */ test(); - IF (st_fx->cng_type == LP_CNG && EQ_16(st_fx->extl, SWB_CNG)) + IF( st_fx->cng_type == LP_CNG && EQ_16( st_fx->extl, SWB_CNG ) ) { shb_CNG_decod_ivas_fx( st_fx, synth_fx, shb_synth_fx, sid_bw, Qsyn ); } @@ -774,8 +780,8 @@ void swb_CNG_dec_ivas_fx( { st_fx->last_vad_fx = 1; move16(); - st_fx->hTdCngDec->burst_cnt = add_sat(st_fx->hTdCngDec->burst_cnt, 1); //saturation reached? - IF ( GT_16(st_fx->hTdCngDec->burst_cnt, 10)) + st_fx->hTdCngDec->burst_cnt = add_sat( st_fx->hTdCngDec->burst_cnt, 1 ); // saturation reached? + IF( GT_16( st_fx->hTdCngDec->burst_cnt, 10 ) ) { st_fx->hTdCngDec->burst_cnt = 0; move16(); @@ -793,16 +799,17 @@ void swb_CNG_dec_ivas_fx( *---------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED static void shb_CNG_decod_fx( - Decoder_State *st_fx, /* i/o: State structure */ - const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz */ - Word16 *shb_synth_fx, /* o : high-band CNG synthesis */ - const Word16 sid_bw /* i : 0-NB/WB, 1-SWB SID */ - ,const Word16 Qsyn /* i : Q value of ACELP core synthesis */ + Decoder_State *st_fx, /* i/o: State structure */ + const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz */ + Word16 *shb_synth_fx, /* o : high-band CNG synthesis */ + const Word16 sid_bw /* i : 0-NB/WB, 1-SWB SID */ + , + const Word16 Qsyn /* i : Q value of ACELP core synthesis */ ) { Word16 i; Word16 idx_ener_fx; - Word16 shb_lpcCNG_fx[LPC_SHB_ORDER+1]; + Word16 shb_lpcCNG_fx[LPC_SHB_ORDER + 1]; Word16 shb_lspCNG_fx[LPC_SHB_ORDER]; Word16 excTmp_fx[L_FRAME16k]; Word16 excSHB_fx[L_FRAME16k]; @@ -817,39 +824,39 @@ static void shb_CNG_decod_fx( Word16 step_fx; Word16 interp_fx; Word16 ener_fx; - Word16 exp,exp1; + Word16 exp, exp1; Word16 fra; Word32 L_tmp; Word16 tmp2; - Word16 allow_cn_step_fx=0; + Word16 allow_cn_step_fx = 0; Word16 q; TD_BWE_DEC_HANDLE hBWE_TD; hBWE_TD = st_fx->hBWE_TD; - IF ( st_fx->bfi == 0 ) + IF( st_fx->bfi == 0 ) { test(); - IF ( EQ_32(st_fx->core_brate, SID_2k40)&&EQ_16(sid_bw,1)) + IF( EQ_32( st_fx->core_brate, SID_2k40 ) && EQ_16( sid_bw, 1 ) ) { - idx_ener_fx = get_next_indice(st_fx, 4); + idx_ener_fx = get_next_indice( st_fx, 4 ); if ( idx_ener_fx == 0 ) { idx_ener_fx = -15; move16(); } - IF (EQ_16(st_fx->element_mode, EVS_MONO)) + IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) { /* de-quantization of SHB CNG parameters */ - L_tmp = L_mult(idx_ener_fx, 27400); /*Q14 */ - st_fx->last_shb_cng_ener_fx = extract_l(L_shr(L_sub(L_tmp, 295924), 6)); /*Q8 */ + L_tmp = L_mult( idx_ener_fx, 27400 ); /*Q14 */ + st_fx->last_shb_cng_ener_fx = extract_l( L_shr( L_sub( L_tmp, 295924 ), 6 ) ); /*Q8 */ } ELSE { #ifdef IVAS_CODE_CNG - /* de-quantization of SHB CNG parameters */ To be verified - L_tmp = L_mult(idx_ener_fx, 17615); /*Q13*/ - st_fx->last_shb_cng_ener_fx = extract_l(L_shr(L_sub(L_tmp, 147962), 5)); /*Q8 */ + /* de-quantization of SHB CNG parameters */ To be verified + L_tmp = L_mult( idx_ener_fx, 17615 ); /*Q13*/ + st_fx->last_shb_cng_ener_fx = extract_l( L_shr( L_sub( L_tmp, 147962 ), 5 ) ); /*Q8 */ #endif } } @@ -858,71 +865,71 @@ static void shb_CNG_decod_fx( /* SHB spectrum estimation */ - interp_fx = s_min(st_fx->shb_dtx_count_fx,32); + interp_fx = s_min( st_fx->shb_dtx_count_fx, 32 ); #ifdef BASOP_NOGLOB - interp_fx = shl_sat(interp_fx, 10); /*Q15*/ + interp_fx = shl_sat( interp_fx, 10 ); /*Q15*/ #else - interp_fx = shl(interp_fx, 10); /*Q15*/ + interp_fx = shl( interp_fx, 10 ); /*Q15*/ #endif - FOR ( i=0; ilsp_shb_prev_fx[i]); /*Q14*/ - tmp = mult(sub(32767, interp_fx), st_fx->lsp_shb_prev_prev_fx[i]); /*Q14*/ - shb_lspCNG_fx[i] = add(tmp2, tmp); + tmp2 = mult( interp_fx, st_fx->lsp_shb_prev_fx[i] ); /*Q14*/ + tmp = mult( sub( 32767, interp_fx ), st_fx->lsp_shb_prev_prev_fx[i] ); /*Q14*/ + shb_lspCNG_fx[i] = add( tmp2, tmp ); move16(); /*Q14*/ } - IF (NE_16(st_fx->element_mode, IVAS_CPE_DFT)) + IF( NE_16( st_fx->element_mode, IVAS_CPE_DFT ) ) { - if (LT_16(st_fx->shb_dtx_count_fx, 1000)) + if ( LT_16( st_fx->shb_dtx_count_fx, 1000 ) ) { - st_fx->shb_dtx_count_fx = add(st_fx->shb_dtx_count_fx, 1); + st_fx->shb_dtx_count_fx = add( st_fx->shb_dtx_count_fx, 1 ); } } - E_LPC_lsf_lsp_conversion(shb_lspCNG_fx, tmp_lsp, LPC_SHB_ORDER); /*Q14*/ - E_LPC_f_lsp_a_conversion(tmp_lsp, shb_lpcCNG_fx, LPC_SHB_ORDER); + E_LPC_lsf_lsp_conversion( shb_lspCNG_fx, tmp_lsp, LPC_SHB_ORDER ); /*Q14*/ + E_LPC_f_lsp_a_conversion( tmp_lsp, shb_lpcCNG_fx, LPC_SHB_ORDER ); - Copy_Scale_sig( shb_lpcCNG_fx, shb_lpcCNG_fx, LPC_SHB_ORDER+1, sub(norm_s(shb_lpcCNG_fx[0]),2) ); /* Q12 */ + Copy_Scale_sig( shb_lpcCNG_fx, shb_lpcCNG_fx, LPC_SHB_ORDER + 1, sub( norm_s( shb_lpcCNG_fx[0] ), 2 ) ); /* Q12 */ #ifdef IVAS_CODE_CNG - //mvr2r(shb_lpcCNG, st->hTdCngDec->shb_lpcCNG, LPC_SHB_ORDER + 1); + // mvr2r(shb_lpcCNG, st->hTdCngDec->shb_lpcCNG, LPC_SHB_ORDER + 1); #endif /* SHB energy estimation */ - wb_ener_fx = L_deposit_l(1);/*Q1 */ - FOR ( i=0; ifirst_CNG == 0 ) { st_fx->wb_cng_ener_fx = wb_ener16_fx; - move16();/*Q8 */ + move16(); /*Q8 */ } - if ( GT_16(abs_s(sub(wb_ener16_fx,st_fx->wb_cng_ener_fx)),3072)) + if ( GT_16( abs_s( sub( wb_ener16_fx, st_fx->wb_cng_ener_fx ) ), 3072 ) ) { allow_cn_step_fx = 1; move16(); } - IF ( EQ_16(allow_cn_step_fx, 1)) + IF( EQ_16( allow_cn_step_fx, 1 ) ) { st_fx->wb_cng_ener_fx = wb_ener16_fx; move16(); /*Q8 */ } ELSE { - tmp = sub(wb_ener16_fx, st_fx->wb_cng_ener_fx); /*Q8 */ - tmp = mult_r(tmp, 29491); /*Q8 */ - st_fx->wb_cng_ener_fx = add(st_fx->wb_cng_ener_fx, tmp); /*Q8 */ + tmp = sub( wb_ener16_fx, st_fx->wb_cng_ener_fx ); /*Q8 */ + tmp = mult_r( tmp, 29491 ); /*Q8 */ + st_fx->wb_cng_ener_fx = add( st_fx->wb_cng_ener_fx, tmp ); /*Q8 */ } test(); test(); - IF ( EQ_32(st_fx->core_brate, SID_2k40)&&EQ_16(sid_bw,1)&&st_fx->bfi==0) + IF( EQ_32( st_fx->core_brate, SID_2k40 ) && EQ_16( sid_bw, 1 ) && st_fx->bfi == 0 ) { st_fx->last_wb_cng_ener_fx = st_fx->wb_cng_ener_fx; move16(); @@ -934,27 +941,27 @@ static void shb_CNG_decod_fx( } } - gain_fx = sub(st_fx->wb_cng_ener_fx, st_fx->last_wb_cng_ener_fx); /*8 */ - if (GT_16(gain_fx, 15)) + gain_fx = sub( st_fx->wb_cng_ener_fx, st_fx->last_wb_cng_ener_fx ); /*8 */ + if ( GT_16( gain_fx, 15 ) ) { gain_fx = 15; move16(); } - step_fx = sub(add(gain_fx, st_fx->last_shb_cng_ener_fx), st_fx->shb_cng_ener_fx); /*Q8 */ + step_fx = sub( add( gain_fx, st_fx->last_shb_cng_ener_fx ), st_fx->shb_cng_ener_fx ); /*Q8 */ test(); - IF ( EQ_16(allow_cn_step_fx,1)||GT_32(st_fx->last_core_brate,SID_2k40)) + IF( EQ_16( allow_cn_step_fx, 1 ) || GT_32( st_fx->last_core_brate, SID_2k40 ) ) { - st_fx->shb_cng_ener_fx = add(st_fx->shb_cng_ener_fx, step_fx); + st_fx->shb_cng_ener_fx = add( st_fx->shb_cng_ener_fx, step_fx ); } ELSE { - st_fx->shb_cng_ener_fx = add(st_fx->shb_cng_ener_fx, mult(8192, step_fx)); /*Q8 */ + st_fx->shb_cng_ener_fx = add( st_fx->shb_cng_ener_fx, mult( 8192, step_fx ) ); /*Q8 */ } /* generate white noise excitation */ - FOR ( i=0; iswb_cng_seed), 8); - move16();/*Q-8*/ + excTmp_fx[i] = shr_r( Random( &st_fx->swb_cng_seed ), 8 ); + move16(); /*Q-8*/ } /* synthesis filtering */ @@ -963,20 +970,20 @@ static void shb_CNG_decod_fx( /* synthesis signal gain shaping */ L_tmp = 0; - FOR ( i=0; ilast_vad_fx, 1)) + ener_excSHB_fx = round_fx( L_tmp ); /*Qq */ + IF( EQ_16( st_fx->last_vad_fx, 1 ) ) { st_fx->trans_cnt_fx = 0; move16(); test(); - if ( GT_16(st_fx->hTdCngDec->burst_cnt, 3)&&NE_16(st_fx->last_core,HQ_CORE)) + if ( GT_16( st_fx->hTdCngDec->burst_cnt, 3 ) && NE_16( st_fx->last_core, HQ_CORE ) ) { st_fx->trans_cnt_fx = 5; move16(); @@ -984,87 +991,86 @@ static void shb_CNG_decod_fx( } ener_fx = st_fx->shb_cng_ener_fx; - move16();/*Q8 */ - IF ( st_fx->trans_cnt_fx > 0 ) + move16(); /*Q8 */ + IF( st_fx->trans_cnt_fx > 0 ) { - i = extract_l(L_mult0(st_fx->trans_cnt_fx, 17)); /*Q0 */ + i = extract_l( L_mult0( st_fx->trans_cnt_fx, 17 ) ); /*Q0 */ #ifdef BASOP_NOGLOB ener_fx = add_sat( st_fx->shb_cng_ener_fx, mult( sin_table256_fx[i], sub_sat( st_fx->last_shb_ener_fx, st_fx->shb_cng_ener_fx ) ) ); /*Q8 */ #else - ener_fx = add(st_fx->shb_cng_ener_fx, mult(sin_table256_fx[i], sub(st_fx->last_shb_ener_fx, st_fx->shb_cng_ener_fx))); /*Q8 */ + ener_fx = add( st_fx->shb_cng_ener_fx, mult( sin_table256_fx[i], sub( st_fx->last_shb_ener_fx, st_fx->shb_cng_ener_fx ) ) ); /*Q8 */ #endif - st_fx->trans_cnt_fx = sub(st_fx->trans_cnt_fx, 1); + st_fx->trans_cnt_fx = sub( st_fx->trans_cnt_fx, 1 ); } - tmp = mult(3277, ener_fx); /*Q8 */ - L_tmp = L_mult(27213, tmp); /*Q22, 27213=3.321928 in Q13 */ - L_tmp = L_shr(L_tmp, 6); /*Q16 */ - L_tmp = L_add(L_tmp, 10<<16); - if( L_tmp < 0 ) + tmp = mult( 3277, ener_fx ); /*Q8 */ + L_tmp = L_mult( 27213, tmp ); /*Q22, 27213=3.321928 in Q13 */ + L_tmp = L_shr( L_tmp, 6 ); /*Q16 */ + L_tmp = L_add( L_tmp, 10 << 16 ); + if ( L_tmp < 0 ) { L_tmp = 0; move32(); } - fra = L_Extract_lc(L_tmp, &exp); + fra = L_Extract_lc( L_tmp, &exp ); #ifdef BASOP_NOGLOB L_tmp = L_shl_sat( Pow2( exp, fra ), 5 ); /*Q5 */ #else - L_tmp = L_shl(Pow2(exp, fra), 5); /*Q5 */ + L_tmp = L_shl( Pow2( exp, fra ), 5 ); /*Q5 */ #endif - L_tmp = L_shr(L_tmp, 10); - if( L_tmp == 0 ) + L_tmp = L_shr( L_tmp, 10 ); + if ( L_tmp == 0 ) { L_tmp = 1; /*Q5 */ } - exp = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, exp); /*Q31*/ - tmp = extract_h(L_tmp); /*Q15*/ - exp = sub(exp, 16); - exp1 = norm_s(ener_excSHB_fx); - fra = shl(ener_excSHB_fx, exp1); /*Q15*/ - - IF ( GT_16(fra,tmp)) + exp = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, exp ); /*Q31*/ + tmp = extract_h( L_tmp ); /*Q15*/ + exp = sub( exp, 16 ); + exp1 = norm_s( ener_excSHB_fx ); + fra = shl( ener_excSHB_fx, exp1 ); /*Q15*/ + + IF( GT_16( fra, tmp ) ) { - fra = shr(fra, 1); /*Q15*/ - exp1 = sub(exp1, 1); + fra = shr( fra, 1 ); /*Q15*/ + exp1 = sub( exp1, 1 ); } - tmp = div_s(fra, tmp); /*Q15*/ + tmp = div_s( fra, tmp ); /*Q15*/ - L_tmp = L_deposit_h(tmp); /*Q31 */ - tmp = -(q+exp1)+(5+exp); - L_gain_fx = Isqrt_lc(L_tmp, &tmp); /*Q31-Qtmp */ + L_tmp = L_deposit_h( tmp ); /*Q31 */ + tmp = -( q + exp1 ) + ( 5 + exp ); + L_gain_fx = Isqrt_lc( L_tmp, &tmp ); /*Q31-Qtmp */ #ifdef IVAS_CODE_CNG st->hTdCngDec->shb_cng_gain = ener_fx; #endif - FOR ( i=0; ilast_extl, SWB_TBE)||EQ_16(st_fx->last_extl,FB_TBE)) + IF( EQ_16( st_fx->last_extl, SWB_TBE ) || EQ_16( st_fx->last_extl, FB_TBE ) ) { /* rescale the Hilbert memories to Q0 */ - FOR(i = 0; i < HILBERT_MEM_SIZE ; i++) + FOR( i = 0; i < HILBERT_MEM_SIZE; i++ ) { - hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i] = L_shr(hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i], st_fx->prev_Q_bwe_syn2); + hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i] = L_shr( hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i], st_fx->prev_Q_bwe_syn2 ); move32(); } - FOR(i = 0; i < 2*ALLPASSSECTIONS_STEEP; i++ ) + FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ ) { - hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i] = shr(hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i], st_fx->prev_Q_bwe_syn2); + hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i] = shr( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i], st_fx->prev_Q_bwe_syn2 ); } - } - GenSHBSynth_fx( shb_syn16k_fx, shb_synth_fx, hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, st_fx->L_frame, &(hBWE_TD->syn_dm_phase) ); + GenSHBSynth_fx( shb_syn16k_fx, shb_synth_fx, hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, st_fx->L_frame, &( hBWE_TD->syn_dm_phase ) ); - IF ( EQ_32(st_fx->output_Fs,48000)) + IF( EQ_32( st_fx->output_Fs, 48000 ) ) { interpolate_3_over_2_allpass_fx( shb_synth_fx, L_FRAME32k, shb_synth_fx, st_fx->interpol_3_2_cng_dec_fx, allpass_poles_3_ov_2 ); } #ifdef IVAS_CODE_CNG - ResetSHBbuffer_Dec(st->hBWE_TD, st->extl); + ResetSHBbuffer_Dec( st->hBWE_TD, st->extl ); #else ResetSHBbuffer_Dec_fx( st_fx ); #endif @@ -1075,16 +1081,15 @@ static void shb_CNG_decod_fx( #ifdef IVAS_FLOAT_FIXED static void shb_CNG_decod_ivas_fx( - Decoder_State *st, /* i/o: State structure */ - const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz */ - Word16 *shb_synth_fx, /* o : high-band CNG synthesis */ - const int16_t sid_bw, /* i : 0-NB/WB, 1-SWB SID */ - const Word16 Qsyn -) + Decoder_State *st, /* i/o: State structure */ + const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz */ + Word16 *shb_synth_fx, /* o : high-band CNG synthesis */ + const int16_t sid_bw, /* i : 0-NB/WB, 1-SWB SID */ + const Word16 Qsyn ) { Word16 i; Word16 idx_ener; - Word16 shb_lpcCNG_fx[LPC_SHB_ORDER+1]; + Word16 shb_lpcCNG_fx[LPC_SHB_ORDER + 1]; Word16 shb_lspCNG_fx[LPC_SHB_ORDER]; Word16 excTmp_fx[L_FRAME16k]; Word16 excSHB_fx[L_FRAME16k]; @@ -1099,137 +1104,137 @@ static void shb_CNG_decod_ivas_fx( Word32 step_fx; Word16 interp_fx; Word32 ener_fx; - Word16 exp,exp1; + Word16 exp, exp1; Word16 fra; Word32 L_tmp; - Word16 allow_cn_step_fx=0; + Word16 allow_cn_step_fx = 0; Word16 q; TD_BWE_DEC_HANDLE hBWE_TD; hBWE_TD = st->hBWE_TD; - IF ( EQ_16(st->bfi, 0) ) + IF( EQ_16( st->bfi, 0 ) ) { - IF ( EQ_32(st->core_brate, SID_2k40) && EQ_16(sid_bw, 1) ) + IF( EQ_32( st->core_brate, SID_2k40 ) && EQ_16( sid_bw, 1 ) ) { idx_ener = get_next_indice( st, 4 ); - IF ( EQ_16(idx_ener, 0) ) + IF( EQ_16( idx_ener, 0 ) ) { idx_ener = -15; move16(); } /* de-quantization of SHB CNG parameters */ - IF ( EQ_16(st->element_mode, EVS_MONO) ) + IF( EQ_16( st->element_mode, EVS_MONO ) ) { - st->hTdCngDec->last_shb_cng_ener_fx_32 = L_sub(L_mult0(idx_ener, 6850), 36991); // Q11 + st->hTdCngDec->last_shb_cng_ener_fx_32 = L_sub( L_mult0( idx_ener, 6850 ), 36991 ); // Q11 } ELSE { - st->hTdCngDec->last_shb_cng_ener_fx_32 = L_sub(L_mult0(idx_ener, 8807), 36991); // Q11 + st->hTdCngDec->last_shb_cng_ener_fx_32 = L_sub( L_mult0( idx_ener, 8807 ), 36991 ); // Q11 } } } /* SHB spectrum estimation */ - interp_fx = s_min(st->hTdCngDec->shb_dtx_count,32); + interp_fx = s_min( st->hTdCngDec->shb_dtx_count, 32 ); #ifdef BASOP_NOGLOB - interp_fx = shl_sat(interp_fx, 10); /*Q15*/ + interp_fx = shl_sat( interp_fx, 10 ); /*Q15*/ #else - interp_fx = shl(interp_fx, 10); /*Q15*/ + interp_fx = shl( interp_fx, 10 ); /*Q15*/ #endif - FOR ( i = 0; i < LPC_SHB_ORDER; i++ ) + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - shb_lspCNG_fx[i] = add( mult_r( interp_fx, st->hTdCngDec->lsp_shb_prev_fx[i] ), mult_r( sub( 32767, interp_fx ), st->hTdCngDec->lsp_shb_prev_prev_fx[i]) ); //Q14 + shb_lspCNG_fx[i] = add( mult_r( interp_fx, st->hTdCngDec->lsp_shb_prev_fx[i] ), mult_r( sub( 32767, interp_fx ), st->hTdCngDec->lsp_shb_prev_prev_fx[i] ) ); // Q14 } - IF ( LE_16(st->hTdCngDec->shb_dtx_count, 1000) ) + IF( LE_16( st->hTdCngDec->shb_dtx_count, 1000 ) ) { - st->hTdCngDec->shb_dtx_count = add(st->hTdCngDec->shb_dtx_count, 1); + st->hTdCngDec->shb_dtx_count = add( st->hTdCngDec->shb_dtx_count, 1 ); } - E_LPC_lsf_lsp_conversion(shb_lspCNG_fx, tmp_lsp, LPC_SHB_ORDER); /*Q14*/ - E_LPC_f_lsp_a_conversion(tmp_lsp, shb_lpcCNG_fx, LPC_SHB_ORDER); + E_LPC_lsf_lsp_conversion( shb_lspCNG_fx, tmp_lsp, LPC_SHB_ORDER ); /*Q14*/ + E_LPC_f_lsp_a_conversion( tmp_lsp, shb_lpcCNG_fx, LPC_SHB_ORDER ); - Copy_Scale_sig( shb_lpcCNG_fx, st->hTdCngDec->shb_lpcCNG_fx, LPC_SHB_ORDER+1, sub(norm_s(shb_lpcCNG_fx[0]),-1) ); /* Q15 */ + Copy_Scale_sig( shb_lpcCNG_fx, st->hTdCngDec->shb_lpcCNG_fx, LPC_SHB_ORDER + 1, sub( norm_s( shb_lpcCNG_fx[0] ), -1 ) ); /* Q15 */ - Copy_Scale_sig(shb_lpcCNG_fx, shb_lpcCNG_fx, LPC_SHB_ORDER + 1, sub(norm_s(shb_lpcCNG_fx[0]), 2)); /* Q12 */ + Copy_Scale_sig( shb_lpcCNG_fx, shb_lpcCNG_fx, LPC_SHB_ORDER + 1, sub( norm_s( shb_lpcCNG_fx[0] ), 2 ) ); /* Q12 */ - //mvs2s(shb_lpcCNG_fx, st->hTdCngDec->shb_lpcCNG_fx, LPC_SHB_ORDER + 1); + // mvs2s(shb_lpcCNG_fx, st->hTdCngDec->shb_lpcCNG_fx, LPC_SHB_ORDER + 1); /* SHB energy estimation */ - wb_ener_fx = L_deposit_l(1);/*Q1 */ - IF ( NE_16(st->element_mode, IVAS_CPE_DFT) ) + wb_ener_fx = L_deposit_l( 1 ); /*Q1 */ + IF( NE_16( st->element_mode, IVAS_CPE_DFT ) ) { - FOR(i = 0; i < L_FRAME32k; i++) + FOR( i = 0; i < L_FRAME32k; i++ ) { - wb_ener_fx = L_add(wb_ener_fx, Mpy_32_16_1(L_mult0(synth_fx[i], synth_fx[i]), 51)); /* 2*Qsyn */ + wb_ener_fx = L_add( wb_ener_fx, Mpy_32_16_1( L_mult0( synth_fx[i], synth_fx[i] ), 51 ) ); /* 2*Qsyn */ } } - exp = norm_l(wb_ener_fx); - fra = Log2_norm_lc(L_shl(wb_ener_fx, exp)); - exp = sub(30, add(exp, shl(Qsyn, 1))); - wb_ener_fx = Mpy_32_16(exp, fra, LG10); - wb_ener16_fx = round_fx(L_shl(wb_ener_fx, 10)); /*wb_ener_fx in Q8 */ - Word32 wb_ener32_fx = L_shl(wb_ener16_fx, 3); /*wb_ener_fx in Q11 */ - IF ( EQ_16(st->first_CNG, 0) ) + exp = norm_l( wb_ener_fx ); + fra = Log2_norm_lc( L_shl( wb_ener_fx, exp ) ); + exp = sub( 30, add( exp, shl( Qsyn, 1 ) ) ); + wb_ener_fx = Mpy_32_16( exp, fra, LG10 ); + wb_ener16_fx = round_fx( L_shl( wb_ener_fx, 10 ) ); /*wb_ener_fx in Q8 */ + Word32 wb_ener32_fx = L_shl( wb_ener16_fx, 3 ); /*wb_ener_fx in Q11 */ + IF( EQ_16( st->first_CNG, 0 ) ) { st->hTdCngDec->wb_cng_ener_fx_32 = wb_ener32_fx; - move32();/*Q11 */ + move32(); /*Q11 */ } - IF ( GT_32(L_abs(L_sub(wb_ener32_fx,st->hTdCngDec->wb_cng_ener_fx_32)),24576)) + IF( GT_32( L_abs( L_sub( wb_ener32_fx, st->hTdCngDec->wb_cng_ener_fx_32 ) ), 24576 ) ) { allow_cn_step_fx = 1; move16(); } - IF ( EQ_16(allow_cn_step_fx, 1)) + IF( EQ_16( allow_cn_step_fx, 1 ) ) { st->hTdCngDec->wb_cng_ener_fx_32 = wb_ener32_fx; move32(); /*Q11 */ } ELSE { - tmp = L_sub(wb_ener32_fx, st->hTdCngDec->wb_cng_ener_fx_32); /*Q11 */ - tmp = Mpy_32_16_1(tmp, 29491); /*Q11 */ - st->hTdCngDec->wb_cng_ener_fx_32 = L_add(st->hTdCngDec->wb_cng_ener_fx_32, tmp); /*Q11 */ + tmp = L_sub( wb_ener32_fx, st->hTdCngDec->wb_cng_ener_fx_32 ); /*Q11 */ + tmp = Mpy_32_16_1( tmp, 29491 ); /*Q11 */ + st->hTdCngDec->wb_cng_ener_fx_32 = L_add( st->hTdCngDec->wb_cng_ener_fx_32, tmp ); /*Q11 */ } test(); test(); - IF ( EQ_32(st->core_brate, SID_2k40)&&EQ_16(sid_bw,1)&&st->bfi==0) + IF( EQ_32( st->core_brate, SID_2k40 ) && EQ_16( sid_bw, 1 ) && st->bfi == 0 ) { st->hTdCngDec->last_wb_cng_ener_fx_32 = st->hTdCngDec->wb_cng_ener_fx_32; move32(); - IF ( st->first_CNG == 0 ) + IF( st->first_CNG == 0 ) { st->hTdCngDec->shb_cng_ener_fx_32 = st->hTdCngDec->last_shb_cng_ener_fx_32; move32(); } } - gain_fx = L_sub(st->hTdCngDec->wb_cng_ener_fx_32, st->hTdCngDec->last_wb_cng_ener_fx_32); /*Q11 */ - IF (GT_32(gain_fx, 30720)) + gain_fx = L_sub( st->hTdCngDec->wb_cng_ener_fx_32, st->hTdCngDec->last_wb_cng_ener_fx_32 ); /*Q11 */ + IF( GT_32( gain_fx, 30720 ) ) { gain_fx = 30720; move32(); } - step_fx = L_sub(L_add(gain_fx, st->hTdCngDec->last_shb_cng_ener_fx_32), st->hTdCngDec->shb_cng_ener_fx_32); /*Q11 */ + step_fx = L_sub( L_add( gain_fx, st->hTdCngDec->last_shb_cng_ener_fx_32 ), st->hTdCngDec->shb_cng_ener_fx_32 ); /*Q11 */ test(); - IF ( EQ_16(allow_cn_step_fx,1)||GT_32(st->last_core_brate,SID_2k40)) + IF( EQ_16( allow_cn_step_fx, 1 ) || GT_32( st->last_core_brate, SID_2k40 ) ) { - st->hTdCngDec->shb_cng_ener_fx_32 = L_add(st->hTdCngDec->shb_cng_ener_fx_32, step_fx); + st->hTdCngDec->shb_cng_ener_fx_32 = L_add( st->hTdCngDec->shb_cng_ener_fx_32, step_fx ); } ELSE { - st->hTdCngDec->shb_cng_ener_fx_32 = L_add(st->hTdCngDec->shb_cng_ener_fx_32, L_shr(step_fx, 2)); /*Q11 */ + st->hTdCngDec->shb_cng_ener_fx_32 = L_add( st->hTdCngDec->shb_cng_ener_fx_32, L_shr( step_fx, 2 ) ); /*Q11 */ } /* generate white noise excitation */ - FOR ( i=0; ihTdCngDec->swb_cng_seed), 8); - move16();/*Q-8*/ + excTmp_fx[i] = shr_r( Random( &st->hTdCngDec->swb_cng_seed ), 8 ); + move16(); /*Q-8*/ } /* synthesis filtering */ @@ -1238,24 +1243,24 @@ static void shb_CNG_decod_ivas_fx( /* synthesis signal gain shaping */ L_tmp = 0; - FOR ( i=0; ilast_vad_fx, 1)) + IF( EQ_16( st->last_vad_fx, 1 ) ) #else - IF ( EQ_16(st->last_vad, 1)) + IF( EQ_16( st->last_vad, 1 ) ) #endif { st->hTdCngDec->trans_cnt = 0; move16(); test(); - IF ( GT_16(st->hTdCngDec->burst_cnt, 3)&&NE_16(st->last_core,HQ_CORE)) + IF( GT_16( st->hTdCngDec->burst_cnt, 3 ) && NE_16( st->last_core, HQ_CORE ) ) { st->hTdCngDec->trans_cnt = 5; move16(); @@ -1263,75 +1268,75 @@ static void shb_CNG_decod_ivas_fx( } ener_fx = st->hTdCngDec->shb_cng_ener_fx_32; - move32();/*Q11 */ - IF ( GT_16(st->hTdCngDec->trans_cnt, 0) ) + move32(); /*Q11 */ + IF( GT_16( st->hTdCngDec->trans_cnt, 0 ) ) { - i = extract_l(L_mult0(st->hTdCngDec->trans_cnt, 17)); /*Q0 */ - ener_fx = L_add(st->hTdCngDec->shb_cng_ener_fx_32, Mpy_32_16_1(L_sub(st->hTdCngDec->last_shb_ener_fx, st->hTdCngDec->shb_cng_ener_fx_32), sin_table256_fx[i])); /*Q11 */ - st->hTdCngDec->trans_cnt = sub(st->hTdCngDec->trans_cnt, 1); + i = extract_l( L_mult0( st->hTdCngDec->trans_cnt, 17 ) ); /*Q0 */ + ener_fx = L_add( st->hTdCngDec->shb_cng_ener_fx_32, Mpy_32_16_1( L_sub( st->hTdCngDec->last_shb_ener_fx, st->hTdCngDec->shb_cng_ener_fx_32 ), sin_table256_fx[i] ) ); /*Q11 */ + st->hTdCngDec->trans_cnt = sub( st->hTdCngDec->trans_cnt, 1 ); } - tmp = L_shr(Mpy_32_16_1(ener_fx, 3277), 3); /*Q8 */ - IF(tmp > 32767) abort(); - Word16 tmp_16 = (Word16)tmp; - L_tmp = L_mult(27213, tmp_16); /*Q22, 27213=3.321928 in Q13 */ - L_tmp = L_shr(L_tmp, 6); /*Q16 */ - L_tmp = L_add(L_tmp, 10<<16); - IF( LT_32(L_tmp, 0) ) + tmp = L_shr( Mpy_32_16_1( ener_fx, 3277 ), 3 ); /*Q8 */ + IF( tmp > 32767 ) + abort(); + Word16 tmp_16 = (Word16) tmp; + L_tmp = L_mult( 27213, tmp_16 ); /*Q22, 27213=3.321928 in Q13 */ + L_tmp = L_shr( L_tmp, 6 ); /*Q16 */ + L_tmp = L_add( L_tmp, 10 << 16 ); + IF( LT_32( L_tmp, 0 ) ) { L_tmp = 0; move32(); } - fra = L_Extract_lc(L_tmp, &exp); - L_tmp = L_shl(Pow2(exp, fra), 5); /*Q5 */ - L_tmp = L_shr(L_tmp, 10); + fra = L_Extract_lc( L_tmp, &exp ); + L_tmp = L_shl( Pow2( exp, fra ), 5 ); /*Q5 */ + L_tmp = L_shr( L_tmp, 10 ); IF( L_tmp == 0 ) { L_tmp = 1; /*Q5 */ } - exp = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, exp); /*Q31*/ - tmp_16 = extract_h(L_tmp); /*Q15*/ - exp = sub(exp, 16); - exp1 = norm_s(ener_excSHB_fx); - fra = shl(ener_excSHB_fx, exp1); /*Q15*/ - - IF ( GT_16(fra,tmp_16)) + exp = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, exp ); /*Q31*/ + tmp_16 = extract_h( L_tmp ); /*Q15*/ + exp = sub( exp, 16 ); + exp1 = norm_s( ener_excSHB_fx ); + fra = shl( ener_excSHB_fx, exp1 ); /*Q15*/ + + IF( GT_16( fra, tmp_16 ) ) { - fra = shr(fra, 1); /*Q15*/ - exp1 = sub(exp1, 1); + fra = shr( fra, 1 ); /*Q15*/ + exp1 = sub( exp1, 1 ); } - tmp_16 = div_s(fra, tmp_16); /*Q15*/ + tmp_16 = div_s( fra, tmp_16 ); /*Q15*/ - L_tmp = L_deposit_h(tmp_16); /*Q31 */ - tmp_16 = -(q+exp1)+(5+exp); - L_gain_fx = Isqrt_lc(L_tmp, &tmp_16); /*Q31-Qtmp */ + L_tmp = L_deposit_h( tmp_16 ); /*Q31 */ + tmp_16 = -( q + exp1 ) + ( 5 + exp ); + L_gain_fx = Isqrt_lc( L_tmp, &tmp_16 ); /*Q31-Qtmp */ st->hTdCngDec->shb_cng_gain_fx_32 = ener_fx; move32(); - FOR ( i=0; ilast_extl, SWB_TBE)||EQ_16(st->last_extl,FB_TBE)) + IF( EQ_16( st->last_extl, SWB_TBE ) || EQ_16( st->last_extl, FB_TBE ) ) { /* rescale the Hilbert memories to Q0 */ - FOR(i = 0; i < HILBERT_MEM_SIZE ; i++) + FOR( i = 0; i < HILBERT_MEM_SIZE; i++ ) { - hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i] = L_shr(hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i], st->prev_Q_bwe_syn2); + hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i] = L_shr( hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i], st->prev_Q_bwe_syn2 ); move32(); } - FOR(i = 0; i < 2*ALLPASSSECTIONS_STEEP; i++ ) + FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ ) { - hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i] = shr(hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i], st->prev_Q_bwe_syn2); + hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i] = shr( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i], st->prev_Q_bwe_syn2 ); } - } - GenSHBSynth_fx( shb_syn16k_fx, shb_synth_fx, hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, st->L_frame, &(hBWE_TD->syn_dm_phase) ); + GenSHBSynth_fx( shb_syn16k_fx, shb_synth_fx, hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, st->L_frame, &( hBWE_TD->syn_dm_phase ) ); - IF ( EQ_32(st->output_Fs,48000)) + IF( EQ_32( st->output_Fs, 48000 ) ) { interpolate_3_over_2_allpass_fx( shb_synth_fx, L_FRAME32k, shb_synth_fx, st->interpol_3_2_cng_dec_fx, allpass_poles_3_ov_2 ); } @@ -1356,68 +1361,82 @@ void td_cng_dec_init_fx( hTdCngDec = st->hTdCngDec; - hTdCngDec->cng_seed = RANDOM_INITSEED; move16(); - hTdCngDec->cng_ener_seed = RANDOM_INITSEED; move16(); - hTdCngDec->cng_ener_seed1 = RANDOM_INITSEED; move16(); - hTdCngDec->old_enr_index = -1; move16(); - hTdCngDec->Enew_fx = L_deposit_l(0); - hTdCngDec->last_allow_cn_step = 0; move16(); + hTdCngDec->cng_seed = RANDOM_INITSEED; + move16(); + hTdCngDec->cng_ener_seed = RANDOM_INITSEED; + move16(); + hTdCngDec->cng_ener_seed1 = RANDOM_INITSEED; + move16(); + hTdCngDec->old_enr_index = -1; + move16(); + hTdCngDec->Enew_fx = L_deposit_l( 0 ); + hTdCngDec->last_allow_cn_step = 0; + move16(); #ifdef IVAS_CODE_CNG // mvr2r(st->lsp_old, st->lspCNG, M); -// hTdCngDec->shb_cng_ener = -6.02f; - IF (st->element_mode != EVS_MONO) + // hTdCngDec->shb_cng_ener = -6.02f; + IF( st->element_mode != EVS_MONO ) { - //set_f(hTdCngDec->shb_lpcCNG, 0.0f, LPC_SHB_ORDER + 1); - //hTdCngDec->shb_lpcCNG[0] = 1.0f; - //hTdCngDec->shb_cng_gain = -82.0; /* a dB value approximately corresponding to shb index 0(used as index -15) */ + // set_f(hTdCngDec->shb_lpcCNG, 0.0f, LPC_SHB_ORDER + 1); + // hTdCngDec->shb_lpcCNG[0] = 1.0f; + // hTdCngDec->shb_cng_gain = -82.0; /* a dB value approximately corresponding to shb index 0(used as index -15) */ } - //hTdCngDec->wb_cng_ener = -6.02f; - //hTdCngDec->last_wb_cng_ener = -6.02f; - //hTdCngDec->last_shb_cng_ener = -6.02f; - //hTdCngDec->swb_cng_seed = RANDOM_INITSEED; + // hTdCngDec->wb_cng_ener = -6.02f; + // hTdCngDec->last_wb_cng_ener = -6.02f; + // hTdCngDec->last_shb_cng_ener = -6.02f; + // hTdCngDec->swb_cng_seed = RANDOM_INITSEED; #endif - hTdCngDec->ho_hist_ptr = -1; move16(); - hTdCngDec->ho_sid_bw = L_deposit_l(0); - set16_fx(hTdCngDec->ho_lsp_hist_fx, 0, HO_HIST_SIZE* M); - set32_fx(hTdCngDec->ho_ener_hist_fx, 0, HO_HIST_SIZE); - set32_fx(hTdCngDec->ho_env_hist_fx, 0, HO_HIST_SIZE* NUM_ENV_CNG); - hTdCngDec->ho_hist_size = 0; move16(); - hTdCngDec->act_cnt = 0; move16(); - hTdCngDec->ho_circ_ptr = -1; move16(); - set16_fx(hTdCngDec->ho_lsp_circ_fx, 0, HO_HIST_SIZE* M); - set32_fx(hTdCngDec->ho_ener_circ_fx, 0, HO_HIST_SIZE); - set32_fx(hTdCngDec->ho_env_circ_fx, 0, HO_HIST_SIZE* NUM_ENV_CNG); - hTdCngDec->ho_circ_size = 0; move16(); - - set16_fx(hTdCngDec->ho_16k_lsp, 0, HO_HIST_SIZE); - hTdCngDec->act_cnt2 = 0; move16(); - hTdCngDec->num_ho = 0; move16(); - hTdCngDec->last_cng_type_fx = -1; move16(); - set32_fx(hTdCngDec->lp_env_fx, 0, NUM_ENV_CNG); - set16_fx(hTdCngDec->exc_mem_fx, 0, 24); - set16_fx(hTdCngDec->exc_mem1_fx, 0, 30); - set32_fx(hTdCngDec->old_env_fx, 0, NUM_ENV_CNG); + hTdCngDec->ho_hist_ptr = -1; + move16(); + hTdCngDec->ho_sid_bw = L_deposit_l( 0 ); + set16_fx( hTdCngDec->ho_lsp_hist_fx, 0, HO_HIST_SIZE * M ); + set32_fx( hTdCngDec->ho_ener_hist_fx, 0, HO_HIST_SIZE ); + set32_fx( hTdCngDec->ho_env_hist_fx, 0, HO_HIST_SIZE * NUM_ENV_CNG ); + hTdCngDec->ho_hist_size = 0; + move16(); + hTdCngDec->act_cnt = 0; + move16(); + hTdCngDec->ho_circ_ptr = -1; + move16(); + set16_fx( hTdCngDec->ho_lsp_circ_fx, 0, HO_HIST_SIZE * M ); + set32_fx( hTdCngDec->ho_ener_circ_fx, 0, HO_HIST_SIZE ); + set32_fx( hTdCngDec->ho_env_circ_fx, 0, HO_HIST_SIZE * NUM_ENV_CNG ); + hTdCngDec->ho_circ_size = 0; + move16(); + + set16_fx( hTdCngDec->ho_16k_lsp, 0, HO_HIST_SIZE ); + hTdCngDec->act_cnt2 = 0; + move16(); + hTdCngDec->num_ho = 0; + move16(); + hTdCngDec->last_cng_type_fx = -1; + move16(); + set32_fx( hTdCngDec->lp_env_fx, 0, NUM_ENV_CNG ); + set16_fx( hTdCngDec->exc_mem_fx, 0, 24 ); + set16_fx( hTdCngDec->exc_mem1_fx, 0, 30 ); + set32_fx( hTdCngDec->old_env_fx, 0, NUM_ENV_CNG ); #ifdef IVAS_CODE_CNG - //st->CNG_mode = -1; - //for (i = 0; i < LPC_SHB_ORDER; i++) + // st->CNG_mode = -1; + // for (i = 0; i < LPC_SHB_ORDER; i++) //{ - // if (st->element_mode != EVS_MONO) - // { - // hTdCngDec->lsp_shb_prev[i] = 0.5f * ((float)(i + 1)) / ((float)(LPC_SHB_ORDER + 1)); - // } - // else - // { - // hTdCngDec->lsp_shb_prev[i] = 0.5f * ((float)i) / ((float)LPC_SHB_ORDER); - // } - // hTdCngDec->lsp_shb_prev_prev[i] = hTdCngDec->lsp_shb_prev[i]; - //} - - //hTdCngDec->shb_dtx_count = 0; - //hTdCngDec->trans_cnt = 0; - //hTdCngDec->last_shb_ener = 0.001f; - //set_f(hTdCngDec->interpol_3_2_cng_dec, 0.0f, INTERP_3_2_MEM_LEN); + // if (st->element_mode != EVS_MONO) + // { + // hTdCngDec->lsp_shb_prev[i] = 0.5f * ((float)(i + 1)) / ((float)(LPC_SHB_ORDER + 1)); + // } + // else + // { + // hTdCngDec->lsp_shb_prev[i] = 0.5f * ((float)i) / ((float)LPC_SHB_ORDER); + // } + // hTdCngDec->lsp_shb_prev_prev[i] = hTdCngDec->lsp_shb_prev[i]; + // } + + // hTdCngDec->shb_dtx_count = 0; + // hTdCngDec->trans_cnt = 0; + // hTdCngDec->last_shb_ener = 0.001f; + // set_f(hTdCngDec->interpol_3_2_cng_dec, 0.0f, INTERP_3_2_MEM_LEN); #endif - hTdCngDec->burst_cnt = 0; move16(); + hTdCngDec->burst_cnt = 0; + move16(); return; } @@ -1443,12 +1462,12 @@ void td_cng_dec_init_ivas_fx( move16(); hTdCngDec->Enew_fx = 0; move32(); - mvs2s( st->lsp_old_fx, st->lspCNG_fx, M ); //Q(15) + mvs2s( st->lsp_old_fx, st->lspCNG_fx, M ); // Q(15) hTdCngDec->last_allow_cn_step = 0; move16(); hTdCngDec->shb_cng_ener_fx_32 = -12329; // -6.02 in Q(11) move32(); - IF ( NE_16(st->element_mode, EVS_MONO) ) + IF( NE_16( st->element_mode, EVS_MONO ) ) { set16_fx( hTdCngDec->shb_lpcCNG_fx, 0, LPC_SHB_ORDER + 1 ); hTdCngDec->shb_lpcCNG_fx[0] = 32767; // 1 in Q(15) @@ -1496,15 +1515,15 @@ void td_cng_dec_init_ivas_fx( set16_fx( hTdCngDec->exc_mem1_fx, 0, 30 ); set32_fx( hTdCngDec->old_env_fx, 0, NUM_ENV_CNG ); - FOR ( i = 0; i < LPC_SHB_ORDER; i++ ) + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - IF ( NE_16(st->element_mode, EVS_MONO) ) + IF( NE_16( st->element_mode, EVS_MONO ) ) { hTdCngDec->lsp_shb_prev_fx[i] = div_s( shr( i + 1, 1 ), LPC_SHB_ORDER + 1 ); } ELSE { - hTdCngDec->lsp_shb_prev_fx[i] = div_s( shr(i, 1), LPC_SHB_ORDER ); + hTdCngDec->lsp_shb_prev_fx[i] = div_s( shr( i, 1 ), LPC_SHB_ORDER ); } hTdCngDec->lsp_shb_prev_prev_fx[i] = hTdCngDec->lsp_shb_prev_fx[i]; move16(); diff --git a/lib_dec/core_dec_init.c b/lib_dec/core_dec_init.c index 04f66be5b..b043eab46 100644 --- a/lib_dec/core_dec_init.c +++ b/lib_dec/core_dec_init.c @@ -49,663 +49,663 @@ *-----------------------------------------------------------------------*/ #ifndef IVAS_FLOAT_FIXED void open_decoder_LPD( - Decoder_State *st, /* i/o: decoder state structure */ - const int32_t total_brate, /* i : total bitrate */ - const int32_t last_total_brate, /* i : last total bitrate */ - const int16_t bwidth, /* i : audio bandwidth */ - const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ - const int16_t last_element_mode, /* i : last element mode */ - const int16_t is_init /* i : indicate call during initialization */ + Decoder_State *st, /* i/o: decoder state structure */ + const int32_t total_brate, /* i : total bitrate */ + const int32_t last_total_brate, /* i : last total bitrate */ + const int16_t bwidth, /* i : audio bandwidth */ + const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ + const int16_t last_element_mode, /* i : last element mode */ + const int16_t is_init /* i : indicate call during initialization */ ) { - int16_t i; - int16_t mem_syn_r_size_old; - int16_t mem_syn_r_size_new; - int16_t fscaleFB; - int16_t encoderLookahead, encoderLookaheadFB; - TCX_LTP_DEC_HANDLE hTcxLtpDec = st->hTcxLtpDec; - TCX_DEC_HANDLE hTcxDec = st->hTcxDec; - - if (st->codec_mode != MODE1) /*already updated in MODE1*/ - { - st->fscale_old = st->fscale; - } - - st->sr_core = getCoreSamplerateMode2_flt(st->element_mode, total_brate, bwidth, st->flag_ACELP16k, st->rf_flag, st->is_ism_format); - st->fscale = sr2fscale(st->sr_core); - fscaleFB = sr2fscale(st->output_Fs); - - /* initializing variables for frame lengths etc. right in the beginning */ - st->L_frame = (int16_t)(st->sr_core / FRAMES_PER_SEC); - if (st->ini_frame == 0) - { - st->last_L_frame = st->L_frame_past = st->L_frame; - } - if (st->hTcxDec != NULL) - { - st->hTcxDec->L_frameTCX = (int16_t)(st->output_Fs / FRAMES_PER_SEC); - if (st->ini_frame == 0) - { - st->L_frameTCX_past = st->hTcxDec->L_frameTCX; - } - } - - st->tcxonly = getTcxonly_ivas(st->element_mode, total_brate, MCT_flag, st->is_ism_format); - - /* the TD TCX PLC in MODE1 still runs with 80ms subframes */ - if ((st->element_mode == EVS_MONO && st->L_frame == L_FRAME16k && total_brate <= ACELP_32k) || (st->element_mode > EVS_MONO && st->L_frame == L_FRAME16k && total_brate <= MAX_ACELP_BRATE) || (st->tcxonly && (st->sr_core == 32000 || st->sr_core == 16000))) - { - st->nb_subfr = NB_SUBFR16k; - } - else - { - st->nb_subfr = NB_SUBFR; - } - st->bits_frame = (int16_t)(((float)st->L_frame / (float)st->fscale) * (float)FSCALE_DENOM / 128.0f * (float)total_brate / 100.0f + 0.49f); - st->TcxBandwidth_float = getTcxBandwidth_flt(bwidth); - st->narrowBand = (bwidth == NB) ? 1 : 0; - encoderLookahead = (L_LOOK_12k8 * st->fscale) / FSCALE_DENOM; - encoderLookaheadFB = (L_LOOK_12k8 * fscaleFB) / FSCALE_DENOM; - - if (st->element_mode == IVAS_CPE_MDCT) - { - st->pit_res_max = initPitchLagParameters(12800, &st->pit_min, &st->pit_fr1, &st->pit_fr1b, &st->pit_fr2, &st->pit_max); - hTcxDec->pit_max_TCX = (int16_t)(st->pit_max * st->output_Fs / 12800); - hTcxDec->pit_min_TCX = (int16_t)(st->pit_min * st->output_Fs / 12800); - } - else - { - st->pit_res_max = initPitchLagParameters(st->sr_core, &st->pit_min, &st->pit_fr1, &st->pit_fr1b, &st->pit_fr2, &st->pit_max); - if (hTcxDec != NULL) - { - hTcxDec->pit_max_TCX = (int16_t)(st->pit_max * st->output_Fs / st->sr_core); - hTcxDec->pit_min_TCX = (int16_t)(st->pit_min * st->output_Fs / st->sr_core); - } - } - - if (st->ini_frame == 0) - { - st->pit_res_max_past = st->pit_res_max; - } - - /*Preemphasis param*/ - if (st->fscale < (16000 * FSCALE_DENOM) / 12800) - { - st->preemph_fac_float = PREEMPH_FAC_FLT; /*NB*/ - } - else if (st->fscale < (24000 * FSCALE_DENOM) / 12800) - { - st->preemph_fac_float = PREEMPH_FAC_16k_FLT; /*WB*/ - } - else - { - st->preemph_fac_float = PREEMPH_FAC_SWB_FLT; /*SWB*/ - } - - if (st->sr_core == INT_FS_16k) - { - st->gamma_float = GAMMA16k_FLT; - } - else if (st->sr_core > INT_FS_16k && st->element_mode == IVAS_CPE_MDCT) - { - st->gamma_float = GAMMA16k_FLT; - } - else - { - st->gamma_float = GAMMA1_FLT; - } - - /* LPC quantization */ - if (st->sr_core <= INT_FS_16k && st->tcxonly == 0) - { - st->lpcQuantization = 1; - } - else - { - st->lpcQuantization = 0; - } - - if (st->tcxonly == 0) - { - st->numlpc = 1; - } - else - { - st->numlpc = 2; - } - - /* Initialize TBE */ - st->prev_coder_type = GENERIC; - if (st->hBWE_TD != NULL) - { - set_f(st->hBWE_TD->prev_lsf_diff, 0.5f, LPC_SHB_ORDER - 2); - st->hBWE_TD->prev_tilt_para = 0.0f; - set_zero(st->hBWE_TD->cur_sub_Aq, M + 1); - } - - if (st->hIGFDec != NULL) - { - if (!is_init || st->element_mode != IVAS_CPE_MDCT) - { - init_tcx_cfg(st->hTcxCfg, total_brate, st->sr_core, st->output_Fs, st->L_frame, st->bwidth, st->hTcxDec->L_frameTCX, st->fscale, encoderLookahead, encoderLookaheadFB, st->preemph_fac_float, st->tcxonly, st->rf_flag, st->igf, st->hIGFDec->infoIGFStopFreq, st->element_mode, st->ini_frame, MCT_flag); + int16_t i; + int16_t mem_syn_r_size_old; + int16_t mem_syn_r_size_new; + int16_t fscaleFB; + int16_t encoderLookahead, encoderLookaheadFB; + TCX_LTP_DEC_HANDLE hTcxLtpDec = st->hTcxLtpDec; + TCX_DEC_HANDLE hTcxDec = st->hTcxDec; + + if ( st->codec_mode != MODE1 ) /*already updated in MODE1*/ + { + st->fscale_old = st->fscale; + } + + st->sr_core = getCoreSamplerateMode2_flt( st->element_mode, total_brate, bwidth, st->flag_ACELP16k, st->rf_flag, st->is_ism_format ); + st->fscale = sr2fscale( st->sr_core ); + fscaleFB = sr2fscale( st->output_Fs ); + + /* initializing variables for frame lengths etc. right in the beginning */ + st->L_frame = (int16_t) ( st->sr_core / FRAMES_PER_SEC ); + if ( st->ini_frame == 0 ) + { + st->last_L_frame = st->L_frame_past = st->L_frame; + } + if ( st->hTcxDec != NULL ) + { + st->hTcxDec->L_frameTCX = (int16_t) ( st->output_Fs / FRAMES_PER_SEC ); + if ( st->ini_frame == 0 ) + { + st->L_frameTCX_past = st->hTcxDec->L_frameTCX; + } + } + + st->tcxonly = getTcxonly_ivas( st->element_mode, total_brate, MCT_flag, st->is_ism_format ); + + /* the TD TCX PLC in MODE1 still runs with 80ms subframes */ + if ( ( st->element_mode == EVS_MONO && st->L_frame == L_FRAME16k && total_brate <= ACELP_32k ) || ( st->element_mode > EVS_MONO && st->L_frame == L_FRAME16k && total_brate <= MAX_ACELP_BRATE ) || ( st->tcxonly && ( st->sr_core == 32000 || st->sr_core == 16000 ) ) ) + { + st->nb_subfr = NB_SUBFR16k; } else { - st->hTcxCfg->tcx_curr_overlap_mode = st->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; - st->hTcxCfg->last_aldo = 1; + st->nb_subfr = NB_SUBFR; } - } + st->bits_frame = (int16_t) ( ( (float) st->L_frame / (float) st->fscale ) * (float) FSCALE_DENOM / 128.0f * (float) total_brate / 100.0f + 0.49f ); + st->TcxBandwidth_float = getTcxBandwidth_flt( bwidth ); + st->narrowBand = ( bwidth == NB ) ? 1 : 0; + encoderLookahead = ( L_LOOK_12k8 * st->fscale ) / FSCALE_DENOM; + encoderLookaheadFB = ( L_LOOK_12k8 * fscaleFB ) / FSCALE_DENOM; - if (st->hTECDec != NULL) - { - resetTecDec(st->hTECDec); - } + if ( st->element_mode == IVAS_CPE_MDCT ) + { + st->pit_res_max = initPitchLagParameters( 12800, &st->pit_min, &st->pit_fr1, &st->pit_fr1b, &st->pit_fr2, &st->pit_max ); + hTcxDec->pit_max_TCX = (int16_t) ( st->pit_max * st->output_Fs / 12800 ); + hTcxDec->pit_min_TCX = (int16_t) ( st->pit_min * st->output_Fs / 12800 ); + } + else + { + st->pit_res_max = initPitchLagParameters( st->sr_core, &st->pit_min, &st->pit_fr1, &st->pit_fr1b, &st->pit_fr2, &st->pit_max ); + if ( hTcxDec != NULL ) + { + hTcxDec->pit_max_TCX = (int16_t) ( st->pit_max * st->output_Fs / st->sr_core ); + hTcxDec->pit_min_TCX = (int16_t) ( st->pit_min * st->output_Fs / st->sr_core ); + } + } - if (st->element_mode != IVAS_SCE) - { - st->flag_cna = 0; - } - if (st->ini_frame == 0) - { - st->flag_cna = 0; - st->last_flag_cna = 0; - } + if ( st->ini_frame == 0 ) + { + st->pit_res_max_past = st->pit_res_max; + } - /* Static vectors to zero */ - if (st->ini_frame == 0) - { - st->last_is_cng = 0; + /*Preemphasis param*/ + if ( st->fscale < ( 16000 * FSCALE_DENOM ) / 12800 ) + { + st->preemph_fac_float = PREEMPH_FAC_FLT; /*NB*/ + } + else if ( st->fscale < ( 24000 * FSCALE_DENOM ) / 12800 ) + { + st->preemph_fac_float = PREEMPH_FAC_16k_FLT; /*WB*/ + } + else + { + st->preemph_fac_float = PREEMPH_FAC_SWB_FLT; /*SWB*/ + } - st->rate_switching_reset = 0; + if ( st->sr_core == INT_FS_16k ) + { + st->gamma_float = GAMMA16k_FLT; + } + else if ( st->sr_core > INT_FS_16k && st->element_mode == IVAS_CPE_MDCT ) + { + st->gamma_float = GAMMA16k_FLT; + } + else + { + st->gamma_float = GAMMA1_FLT; + } - if (st->hTcxDec != NULL) + /* LPC quantization */ + if ( st->sr_core <= INT_FS_16k && st->tcxonly == 0 ) { - reset_tcx_overl_buf(st->hTcxDec); + st->lpcQuantization = 1; + } + else + { + st->lpcQuantization = 0; + } - set_zero(st->hTcxDec->syn_OverlFB_float, L_FRAME_MAX / 2); - set_zero(st->hTcxDec->old_synth_float, OLD_SYNTH_INTERNAL_DEC); + if ( st->tcxonly == 0 ) + { + st->numlpc = 1; + } + else + { + st->numlpc = 2; + } - set_zero(st->hTcxDec->synth_history, L_PROT48k + L_FRAME_MAX); + /* Initialize TBE */ + st->prev_coder_type = GENERIC; + if ( st->hBWE_TD != NULL ) + { + set_f( st->hBWE_TD->prev_lsf_diff, 0.5f, LPC_SHB_ORDER - 2 ); + st->hBWE_TD->prev_tilt_para = 0.0f; + set_zero( st->hBWE_TD->cur_sub_Aq, M + 1 ); } - set_zero(st->syn_float, M + 1); + if ( st->hIGFDec != NULL ) + { + if ( !is_init || st->element_mode != IVAS_CPE_MDCT ) + { + init_tcx_cfg( st->hTcxCfg, total_brate, st->sr_core, st->output_Fs, st->L_frame, st->bwidth, st->hTcxDec->L_frameTCX, st->fscale, encoderLookahead, encoderLookaheadFB, st->preemph_fac_float, st->tcxonly, st->rf_flag, st->igf, st->hIGFDec->infoIGFStopFreq, st->element_mode, st->ini_frame, MCT_flag ); + } + else + { + st->hTcxCfg->tcx_curr_overlap_mode = st->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; + st->hTcxCfg->last_aldo = 1; + } + } - set_zero(st->mem_syn_r_float, L_SYN_MEM); + if ( st->hTECDec != NULL ) + { + resetTecDec( st->hTECDec ); + } - mem_syn_r_size_old = 0; /* just to avoid MSVC warnings */ - mem_syn_r_size_new = 0; /* just to avoid MSVC warnings */ + if ( st->element_mode != IVAS_SCE ) + { + st->flag_cna = 0; + } + if ( st->ini_frame == 0 ) + { + st->flag_cna = 0; + st->last_flag_cna = 0; + } - st->con_tcx = 0; - } - else - { - /* Reset old_synth in case of core sampling rate switching and Mode 1/2 switching*/ - if (st->hTcxDec != NULL && ((st->L_frame != st->last_L_frame) || (st->last_codec_mode == MODE1 && st->element_mode == EVS_MONO))) + /* Static vectors to zero */ + if ( st->ini_frame == 0 ) { - set_zero(st->hTcxDec->old_synth_float, OLD_SYNTH_INTERNAL_DEC); + st->last_is_cng = 0; + + st->rate_switching_reset = 0; + + if ( st->hTcxDec != NULL ) + { + reset_tcx_overl_buf( st->hTcxDec ); + + set_zero( st->hTcxDec->syn_OverlFB_float, L_FRAME_MAX / 2 ); + set_zero( st->hTcxDec->old_synth_float, OLD_SYNTH_INTERNAL_DEC ); + + set_zero( st->hTcxDec->synth_history, L_PROT48k + L_FRAME_MAX ); + } + + set_zero( st->syn_float, M + 1 ); + + set_zero( st->mem_syn_r_float, L_SYN_MEM ); + + mem_syn_r_size_old = 0; /* just to avoid MSVC warnings */ + mem_syn_r_size_new = 0; /* just to avoid MSVC warnings */ + + st->con_tcx = 0; } + else + { + /* Reset old_synth in case of core sampling rate switching and Mode 1/2 switching*/ + if ( st->hTcxDec != NULL && ( ( st->L_frame != st->last_L_frame ) || ( st->last_codec_mode == MODE1 && st->element_mode == EVS_MONO ) ) ) + { + set_zero( st->hTcxDec->old_synth_float, OLD_SYNTH_INTERNAL_DEC ); + } - /*Compute size of old and new memories*/ - mem_syn_r_size_old = (int16_t)(1.25 * st->last_L_frame / 20.f); - mem_syn_r_size_new = (int16_t)(1.25 * st->L_frame / 20.f); + /*Compute size of old and new memories*/ + mem_syn_r_size_old = (int16_t) ( 1.25 * st->last_L_frame / 20.f ); + mem_syn_r_size_new = (int16_t) ( 1.25 * st->L_frame / 20.f ); - /*Reset LPC mem*/ - if ((st->L_frame != st->last_L_frame) || (st->last_core == AMR_WB_CORE) || (st->last_core == HQ_CORE)) + /*Reset LPC mem*/ + if ( ( st->L_frame != st->last_L_frame ) || ( st->last_core == AMR_WB_CORE ) || ( st->last_core == HQ_CORE ) ) + { + set_zero( st->mem_MA, M ); + if ( st->sr_core == INT_FS_16k ) + { + mvr2r( GEWB2_Ave, st->mem_AR, M ); + } + else + { + mvr2r( GEWB_Ave, st->mem_AR, M ); + } + } + + /*Mode 1/2 switching*/ + if ( st->last_codec_mode == MODE1 && st->element_mode == EVS_MONO ) + { + mvr2r( st->lsp_old, st->lspold_uw_float, M ); + mvr2r( st->lsf_old, st->lsfold_uw_float, M ); + set_zero( st->syn_float, M ); + } + if ( st->last_core == AMR_WB_CORE ) + { + st->last_core = ACELP_CORE; + st->last_core_bfi = ACELP_CORE; + } + + if ( ( ( st->element_mode != IVAS_CPE_DFT ) || ( st->element_mode == IVAS_CPE_DFT && st->prev_bfi ) ) && st->last_codec_mode == MODE1 && st->last_core == ACELP_CORE ) + { + /* Switching from Mode 1 ACELP */ + st->last_core_bfi = ACELP_CORE; + acelp_plc_mdct_transition( st ); + } + + if ( st->last_codec_mode == MODE2 && + st->L_frame != st->last_L_frame && + ( ( st->m_frame_type == SID_FRAME && st->last_core > ACELP_CORE ) || + ( st->last_core > ACELP_CORE && st->core > ACELP_CORE ) || st->prev_bfi ) ) + { + lerp_flt( st->hHQ_core->old_outLB, st->hHQ_core->old_outLB, st->L_frame, st->last_L_frame ); + } + + /* Rate switching */ + if ( st->last_codec_mode == MODE1 && st->last_core == HQ_CORE ) + { + /* Switching from MDCT */ + + /*Reset of ACELP memories*/ + st->rate_switching_reset = 1; + st->tilt_code = TILT_CODE_FLT; + set_zero( st->old_exc, L_EXC_MEM_DEC ); + set_zero( st->syn_float, 1 + M ); + set_zero( st->mem_syn2, M ); + + /*OLA -> zero */ + if ( st->hTcxDec != NULL ) + { + reset_tcx_overl_buf( st->hTcxDec ); + } + + if ( st->hTcxCfg != NULL ) + { + mvr2r( st->hHQ_core->old_out + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), st->hTcxDec->syn_OverlFB_float, st->hTcxCfg->tcx_mdct_window_lengthFB ); + st->hTcxCfg->last_aldo = 1; /*It was previously ALDO*/ + st->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; + } + + /*OLA for Mode 2 TCX always reset in Mode switching cases*/ + if ( st->hHQ_core != NULL ) + { + set_f( st->hHQ_core->old_outLB, 0, st->L_frame ); + } + + st->last_core_bfi = TCX_20_CORE; + + if ( st->hPFstat != NULL ) + { + st->hPFstat->on = 0; + } + + /* reset CLDFB memories */ + cldfb_reset_memory_ivas( st->cldfbAna ); + cldfb_reset_memory_ivas( st->cldfbBPF ); + cldfb_reset_memory_ivas( st->cldfbSyn ); + if ( st->cldfbSynHB != NULL ) + { + cldfb_reset_memory_ivas( st->cldfbSynHB ); + } + } + else if ( ( st->L_frame != st->last_L_frame ) && ( st->L_frame <= L_FRAME16k ) && ( st->last_L_frame <= L_FRAME16k ) ) /* Rate switching between 12.8 and 16 kHz*/ + { + /*Interpolation of ACELP memories*/ + + /* convert quantized LSP vector */ + st->rate_switching_reset = lsp_convert_poly( st->lsp_old, st->L_frame, 0 ); + lsp2a_stab( st->lsp_old, st->old_Aq_12_8, M ); + + lsp2lsf( st->lsp_old, st->lsf_old, M, st->sr_core ); + mvr2r( st->lsp_old, st->lspold_uw_float, M ); + mvr2r( st->lsf_old, st->lsfold_uw_float, M ); + + if ( !st->last_con_tcx ) + { + synth_mem_updt2_flt( st->L_frame, st->last_L_frame, st->old_exc, st->mem_syn_r_float, st->mem_syn2, NULL, DEC ); + } + + /*mem of deemphasis stayed unchanged.*/ + } + else if ( st->L_frame != st->last_L_frame ) /* Rate switching involving TCX only modes */ + { + /*Partial reset of ACELP memories*/ + st->rate_switching_reset = 1; + + /*reset partly some memories*/ + st->tilt_code = TILT_CODE_FLT; + if ( !st->last_con_tcx ) + { + set_zero( st->old_exc, L_EXC_MEM_DEC ); + } + set_zero( st->old_Aq_12_8, M + 1 ); + + /*Resamp others memories*/ + /*Size of LPC syn memory*/ + lerp_flt( st->mem_syn_r_float + L_SYN_MEM - mem_syn_r_size_old, st->mem_syn_r_float + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); + mvr2r( st->mem_syn_r_float + L_SYN_MEM - M, st->mem_syn2, M ); + } + /* update of lsf_old only needed in BASOP */ + /* else if( !st->tcxonly && (st->L_frame == L_FRAME16k) && (st->last_total_brate > ACELP_32k) ) */ + /* { */ + /* lsp2lsf( st->lsp_old, st->lsf_old, M, st->sr_core ); */ + /* } */ + } + + if ( st->last_bwidth == NB && st->bwidth != NB && st->ini_frame != 0 ) { - set_zero(st->mem_MA, M); - if (st->sr_core == INT_FS_16k) - { - mvr2r(GEWB2_Ave, st->mem_AR, M); - } - else - { - mvr2r(GEWB_Ave, st->mem_AR, M); - } + st->rate_switching_reset = 1; } - /*Mode 1/2 switching*/ - if (st->last_codec_mode == MODE1 && st->element_mode == EVS_MONO) + if ( st->hTcxDec != NULL ) { - mvr2r(st->lsp_old, st->lspold_uw_float, M); - mvr2r(st->lsf_old, st->lsfold_uw_float, M); - set_zero(st->syn_float, M); + st->hTcxDec->old_synth_len = 2 * st->L_frame; + st->hTcxDec->old_synth_lenFB = 2 * st->hTcxDec->L_frameTCX; } - if (st->last_core == AMR_WB_CORE) + + /* bass pf reset */ + st->bpf_gain_param = 0; + if ( st->hBPF != NULL ) { - st->last_core = ACELP_CORE; - st->last_core_bfi = ACELP_CORE; + set_f( st->hBPF->pst_old_syn, 0, NBPSF_PIT_MAX ); } - if (((st->element_mode != IVAS_CPE_DFT) || (st->element_mode == IVAS_CPE_DFT && st->prev_bfi)) && st->last_codec_mode == MODE1 && st->last_core == ACELP_CORE) + /* Formant postfilter */ + if ( st->ini_frame == 0 ) + { + /* do nothing */ + } + else if ( st->last_codec_mode == MODE2 ) + { + if ( !st->tcxonly ) + { + if ( st->hPFstat->on ) + { + lerp_flt( st->hPFstat->mem_stp_flt + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_stp_flt + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); + lerp_flt( st->hPFstat->mem_pf_in_flt + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_pf_in_flt + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); + } + else + { + set_zero( st->hPFstat->mem_stp_flt, L_SYN_MEM ); + set_zero( st->hPFstat->mem_pf_in_flt, L_SYN_MEM ); + st->hPFstat->reset = 1; + st->hPFstat->gain_prec_flt = 1.f; + } + } + else if ( st->hPFstat->on ) + { + lerp_flt( st->hPFstat->mem_stp_flt + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_stp_flt + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); + lerp_flt( st->hPFstat->mem_pf_in_flt + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_pf_in_flt + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); + } + } + else { - /* Switching from Mode 1 ACELP */ - st->last_core_bfi = ACELP_CORE; - acelp_plc_mdct_transition(st); + /*codec mode switching*/ + + /*reset post-filter except for Narrowband*/ + if ( ( (int16_t) ( st->output_Fs / FRAMES_PER_SEC ) ) != L_FRAME8k ) + { + if ( st->hPFstat != NULL ) + { + st->hPFstat->reset = 1; + if ( st->hPFstat->on != 0 ) + { + st->hPFstat->reset = 0; + lerp_flt( st->hPFstat->mem_stp_flt + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_stp_flt + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); + lerp_flt( st->hPFstat->mem_pf_in_flt + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_pf_in_flt + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); + } + } + } + else + { + /*feed last value old_synth as it is used for pre-emphasis mem*/ + if ( st->hTcxDec != NULL ) + { + st->hTcxDec->old_synth_float[st->hTcxDec->old_synth_len - 1] = st->syn_float[M]; + } + if ( st->hBPF != NULL ) + { + st->hBPF->pst_old_syn[NBPSF_PIT_MAX - 1] = st->syn_float[M]; + } + } } - if (st->last_codec_mode == MODE2 && - st->L_frame != st->last_L_frame && - ((st->m_frame_type == SID_FRAME && st->last_core > ACELP_CORE) || - (st->last_core > ACELP_CORE && st->core > ACELP_CORE) || st->prev_bfi)) + /* lsf and lsp initialization */ + if ( st->ini_frame == 0 ) { - lerp_flt(st->hHQ_core->old_outLB, st->hHQ_core->old_outLB, st->L_frame, st->last_L_frame); + mvr2r( st->lsp_old, st->lspold_uw_float, M ); + mvr2r( st->lsf_old, st->lsfold_uw_float, M ); + + set_zero( st->lsf_cng_float, M ); } - /* Rate switching */ - if (st->last_codec_mode == MODE1 && st->last_core == HQ_CORE) + st->seed_tcx_plc = RANDOM_INITSEED; + st->past_gpit_float = 0.0f; + st->past_gcode_float = 0.0f; + st->gc_threshold = 0.0f; + + lsf2lsp( st->lsf_cng_float, st->lspold_cng_float, M, INT_FS_12k8 ); + lsp2a_stab( st->lspold_cng_float, st->Aq_cng_float, M ); + st->plcBackgroundNoiseUpdated = 0; + mvr2r( st->lsf_old, st->lsf_q_cng_float, M ); + mvr2r( st->lsf_old, st->old_lsf_q_cng_float, M ); + mvr2r( st->lsp_old, st->lsp_q_cng_float, M ); + mvr2r( st->lsp_old, st->old_lsp_q_cng_float, M ); + set_zero( st->mem_syn_unv_back_float, M ); + st->last_gain_syn_deemph_float = 1.f; + + if ( st->last_codec_mode == MODE1 || st->ini_frame == 0 ) { - /* Switching from MDCT */ + /* this assumes that MODE1 fades out in the frequency domain - + otherwise some data from MODE1 would be needed here */ + st->last_concealed_gain_syn_deemph_float = 1.f; + if ( hTcxDec != NULL ) + { + hTcxDec->conceal_eof_gain_float = 1.0f; + } + } + /* Post processing */ + set_zero( st->mem_Aq_float, NB_SUBFR16k * ( M + 1 ) ); - /*Reset of ACELP memories*/ - st->rate_switching_reset = 1; - st->tilt_code = TILT_CODE_FLT; - set_zero(st->old_exc, L_EXC_MEM_DEC); - set_zero(st->syn_float, 1 + M); - set_zero(st->mem_syn2, M); + st->lp_ener_bfi = 60.0f; + if ( st->ini_frame == 0 ) + { + st->prev_bfi = 0; + st->last_core_bfi = -1; + if ( st->hTcxDec != NULL ) + { + hTcxDec->tcxConceal_recalc_exc = 0; + } + } + st->prev_old_bfi = 0; - /*OLA -> zero */ - if (st->hTcxDec != NULL) - { - reset_tcx_overl_buf(st->hTcxDec); - } + if ( st->hTcxDec != NULL ) + { + st->hTcxDec->noise_filling_index[0] = st->hTcxDec->noise_filling_index[1] = 0; + st->hTcxDec->tnsActive[0] = st->hTcxDec->tnsActive[1] = 0; + set_f( st->hTcxDec->ltpGainMemory, 0.0f, N_LTP_GAIN_MEMS ); + } - if (st->hTcxCfg != NULL) - { - mvr2r(st->hHQ_core->old_out + NS2SA(st->output_Fs, N_ZERO_MDCT_NS), st->hTcxDec->syn_OverlFB_float, st->hTcxCfg->tcx_mdct_window_lengthFB); - st->hTcxCfg->last_aldo = 1; /*It was previously ALDO*/ - st->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; - } + mvr2r( st->lsf_old, st->lsf_adaptive_mean, M ); + mvr2r( st->lsf_old, st->lsfoldbfi0, M ); + mvr2r( st->lsf_old, st->lsfoldbfi1, M ); - /*OLA for Mode 2 TCX always reset in Mode switching cases*/ - if (st->hHQ_core != NULL) - { - set_f(st->hHQ_core->old_outLB, 0, st->L_frame); - } + st->clas_dec = UNVOICED_CLAS; - st->last_core_bfi = TCX_20_CORE; + if ( !st->last_con_tcx ) + { + st->old_enr_LP_float = 0.0f; /* LP filter E of last good voiced frame or local LP filter E in TD TCX PLC */ + } - if (st->hPFstat != NULL) - { - st->hPFstat->on = 0; - } - - /* reset CLDFB memories */ - cldfb_reset_memory_ivas(st->cldfbAna); - cldfb_reset_memory_ivas(st->cldfbBPF); - cldfb_reset_memory_ivas(st->cldfbSyn); - if (st->cldfbSynHB != NULL) - { - cldfb_reset_memory_ivas(st->cldfbSynHB); - } - } - else if ((st->L_frame != st->last_L_frame) && (st->L_frame <= L_FRAME16k) && (st->last_L_frame <= L_FRAME16k)) /* Rate switching between 12.8 and 16 kHz*/ - { - /*Interpolation of ACELP memories*/ - - /* convert quantized LSP vector */ - st->rate_switching_reset = lsp_convert_poly(st->lsp_old, st->L_frame, 0); - lsp2a_stab(st->lsp_old, st->old_Aq_12_8, M); - - lsp2lsf(st->lsp_old, st->lsf_old, M, st->sr_core); - mvr2r(st->lsp_old, st->lspold_uw_float, M); - mvr2r(st->lsf_old, st->lsfold_uw_float, M); - - if (!st->last_con_tcx) - { - synth_mem_updt2_flt(st->L_frame, st->last_L_frame, st->old_exc, st->mem_syn_r_float, st->mem_syn2, NULL, DEC); - } - - /*mem of deemphasis stayed unchanged.*/ - } - else if (st->L_frame != st->last_L_frame) /* Rate switching involving TCX only modes */ - { - /*Partial reset of ACELP memories*/ - st->rate_switching_reset = 1; - - /*reset partly some memories*/ - st->tilt_code = TILT_CODE_FLT; - if (!st->last_con_tcx) - { - set_zero(st->old_exc, L_EXC_MEM_DEC); - } - set_zero(st->old_Aq_12_8, M + 1); - - /*Resamp others memories*/ - /*Size of LPC syn memory*/ - lerp_flt(st->mem_syn_r_float + L_SYN_MEM - mem_syn_r_size_old, st->mem_syn_r_float + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old); - mvr2r(st->mem_syn_r_float + L_SYN_MEM - M, st->mem_syn2, M); - } - /* update of lsf_old only needed in BASOP */ - /* else if( !st->tcxonly && (st->L_frame == L_FRAME16k) && (st->last_total_brate > ACELP_32k) ) */ - /* { */ - /* lsp2lsf( st->lsp_old, st->lsf_old, M, st->sr_core ); */ - /* } */ - } - - if (st->last_bwidth == NB && st->bwidth != NB && st->ini_frame != 0) - { - st->rate_switching_reset = 1; - } - - if (st->hTcxDec != NULL) - { - st->hTcxDec->old_synth_len = 2 * st->L_frame; - st->hTcxDec->old_synth_lenFB = 2 * st->hTcxDec->L_frameTCX; - } - - /* bass pf reset */ - st->bpf_gain_param = 0; - if (st->hBPF != NULL) - { - set_f(st->hBPF->pst_old_syn, 0, NBPSF_PIT_MAX); - } - - /* Formant postfilter */ - if (st->ini_frame == 0) - { - /* do nothing */ - } - else if (st->last_codec_mode == MODE2) - { - if (!st->tcxonly) - { - if (st->hPFstat->on) - { - lerp_flt(st->hPFstat->mem_stp_flt + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_stp_flt + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old); - lerp_flt(st->hPFstat->mem_pf_in_flt + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_pf_in_flt + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old); - } - else - { - set_zero(st->hPFstat->mem_stp_flt, L_SYN_MEM); - set_zero(st->hPFstat->mem_pf_in_flt, L_SYN_MEM); - st->hPFstat->reset = 1; - st->hPFstat->gain_prec_flt = 1.f; - } - } - else if (st->hPFstat->on) - { - lerp_flt(st->hPFstat->mem_stp_flt + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_stp_flt + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old); - lerp_flt(st->hPFstat->mem_pf_in_flt + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_pf_in_flt + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old); - } - } - else - { - /*codec mode switching*/ - - /*reset post-filter except for Narrowband*/ - if (((int16_t)(st->output_Fs / FRAMES_PER_SEC)) != L_FRAME8k) - { - if (st->hPFstat != NULL) - { - st->hPFstat->reset = 1; - if (st->hPFstat->on != 0) + if ( st->prev_bfi ) + { + /* calculate energy at the end of the previous frame */ + if ( st->core == ACELP_CORE && st->last_core == HQ_CORE ) { - st->hPFstat->reset = 0; - lerp_flt(st->hPFstat->mem_stp_flt + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_stp_flt + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old); - lerp_flt(st->hPFstat->mem_pf_in_flt + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_pf_in_flt + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old); + fer_energy( st->hTcxDec->L_frameTCX, UNVOICED_CLAS, st->previoussynth, -1, &st->enr_old, 1 ); } - } } else { - /*feed last value old_synth as it is used for pre-emphasis mem*/ - if (st->hTcxDec != NULL) - { - st->hTcxDec->old_synth_float[st->hTcxDec->old_synth_len - 1] = st->syn_float[M]; - } - if (st->hBPF != NULL) - { - st->hBPF->pst_old_syn[NBPSF_PIT_MAX - 1] = st->syn_float[M]; - } - } - } - - /* lsf and lsp initialization */ - if (st->ini_frame == 0) - { - mvr2r(st->lsp_old, st->lspold_uw_float, M); - mvr2r(st->lsf_old, st->lsfold_uw_float, M); - - set_zero(st->lsf_cng_float, M); - } - - st->seed_tcx_plc = RANDOM_INITSEED; - st->past_gpit_float = 0.0f; - st->past_gcode_float = 0.0f; - st->gc_threshold = 0.0f; - - lsf2lsp(st->lsf_cng_float, st->lspold_cng_float, M, INT_FS_12k8); - lsp2a_stab(st->lspold_cng_float, st->Aq_cng_float, M); - st->plcBackgroundNoiseUpdated = 0; - mvr2r(st->lsf_old, st->lsf_q_cng_float, M); - mvr2r(st->lsf_old, st->old_lsf_q_cng_float, M); - mvr2r(st->lsp_old, st->lsp_q_cng_float, M); - mvr2r(st->lsp_old, st->old_lsp_q_cng_float, M); - set_zero(st->mem_syn_unv_back_float, M); - st->last_gain_syn_deemph_float = 1.f; - - if (st->last_codec_mode == MODE1 || st->ini_frame == 0) - { - /* this assumes that MODE1 fades out in the frequency domain - - otherwise some data from MODE1 would be needed here */ - st->last_concealed_gain_syn_deemph_float = 1.f; - if (hTcxDec != NULL) - { - hTcxDec->conceal_eof_gain_float = 1.0f; - } - } - /* Post processing */ - set_zero(st->mem_Aq_float, NB_SUBFR16k * (M + 1)); + st->last_good = UNVOICED_CLAS; /* last good received frame for concealment */ + st->enr_old = 0.0f; /* energy at the end of the previous frame */ + } + st->lp_gainc = 0.0f; + st->lp_gainp = 0.0f; + + if ( st->hTcxDec != NULL ) + { + st->hTcxDec->prev_widow_left_rect = 0; + + if ( is_init || MCT_flag || !( st->element_mode == IVAS_CPE_MDCT && st->element_mode == last_element_mode ) ) + { + st->hTcxDec->CngLevelBackgroundTrace_bfi = PLC_MIN_CNG_LEV_FLT; + st->hTcxDec->NoiseLevelIndex_bfi = PLC_MIN_STAT_BUFF_SIZE - 1; + st->hTcxDec->CurrLevelIndex_bfi = 0; + st->hTcxDec->LastFrameLevel_bfi = PLC_MIN_CNG_LEV_FLT; + set_f( st->hTcxDec->NoiseLevelMemory_bfi, PLC_MIN_CNG_LEV_FLT, PLC_MIN_STAT_BUFF_SIZE ); + + st->hTcxDec->cummulative_damping_tcx_float = 1.0f; + } + } + + st->cummulative_damping_float = 1.0f; + + for ( i = 0; i < 2 * NB_SUBFR16k + 2; i++ ) + { + st->old_pitch_buf[i] = (float) st->pit_min; + } - st->lp_ener_bfi = 60.0f; - if (st->ini_frame == 0) - { - st->prev_bfi = 0; - st->last_core_bfi = -1; - if (st->hTcxDec != NULL) + for ( i = 0; i < 2 * NB_SUBFR16k + 2; i++ ) { - hTcxDec->tcxConceal_recalc_exc = 0; + st->mem_pitch_gain_float[i] = 1.f; } - } - st->prev_old_bfi = 0; - if (st->hTcxDec != NULL) - { - st->hTcxDec->noise_filling_index[0] = st->hTcxDec->noise_filling_index[1] = 0; - st->hTcxDec->tnsActive[0] = st->hTcxDec->tnsActive[1] = 0; - set_f(st->hTcxDec->ltpGainMemory, 0.0f, N_LTP_GAIN_MEMS); - } + st->old_fpitch_float = (float) st->pit_min; - mvr2r(st->lsf_old, st->lsf_adaptive_mean, M); - mvr2r(st->lsf_old, st->lsfoldbfi0, M); - mvr2r(st->lsf_old, st->lsfoldbfi1, M); + st->rate_switching_init = 1; - st->clas_dec = UNVOICED_CLAS; + st->reset_mem_AR = 0; - if (!st->last_con_tcx) - { - st->old_enr_LP_float = 0.0f; /* LP filter E of last good voiced frame or local LP filter E in TD TCX PLC */ - } + /* For phase dispersion */ + set_zero( st->dispMem, 8 ); - if (st->prev_bfi) - { - /* calculate energy at the end of the previous frame */ - if (st->core == ACELP_CORE && st->last_core == HQ_CORE) + st->voice_fac_float = -1; /* purely unvoiced */ + + /* TCX-LTP */ + if ( hTcxLtpDec != NULL ) + { + tcxltp_dec_init( hTcxLtpDec, st->ini_frame, st->last_codec_mode, st->element_mode, st->pit_max, st->sr_core ); + } + + /* TCX */ + if ( hTcxDec != NULL ) { - fer_energy(st->hTcxDec->L_frameTCX, UNVOICED_CLAS, st->previoussynth, -1, &st->enr_old, 1); + st->old_fpitchFB_float = (float) hTcxDec->pit_min_TCX; + + if ( st->ini_frame == 0 || ( st->last_codec_mode == MODE1 && st->element_mode == EVS_MONO ) ) + { + hTcxDec->tcxltp_last_gain_unmodified_float = 0.f; + } + + /* TCX */ + hTcxDec->tcx_lpc_shaped_ari = getTcxLpcShapedAri( total_brate, st->rf_flag, st->element_mode ); + + hTcxDec->envWeighted = 0; } - } - else - { - st->last_good = UNVOICED_CLAS; /* last good received frame for concealment */ - st->enr_old = 0.0f; /* energy at the end of the previous frame */ - } - st->lp_gainc = 0.0f; - st->lp_gainp = 0.0f; - if (st->hTcxDec != NULL) - { - st->hTcxDec->prev_widow_left_rect = 0; + if ( st->hBPF != NULL ) + { + st->hBPF->pst_mem_deemp_err = 0.0f; + } - if (is_init || MCT_flag || !(st->element_mode == IVAS_CPE_MDCT && st->element_mode == last_element_mode)) + if ( st->tcxonly ) { - st->hTcxDec->CngLevelBackgroundTrace_bfi = PLC_MIN_CNG_LEV_FLT; - st->hTcxDec->NoiseLevelIndex_bfi = PLC_MIN_STAT_BUFF_SIZE - 1; - st->hTcxDec->CurrLevelIndex_bfi = 0; - st->hTcxDec->LastFrameLevel_bfi = PLC_MIN_CNG_LEV_FLT; - set_f(st->hTcxDec->NoiseLevelMemory_bfi, PLC_MIN_CNG_LEV_FLT, PLC_MIN_STAT_BUFF_SIZE); + st->p_bpf_noise_buf_float = NULL; + } + else + { + st->p_bpf_noise_buf_float = st->bpf_noise_buf_float; + } - st->hTcxDec->cummulative_damping_tcx_float = 1.0f; + if ( bwidth == SWB && ( total_brate == ACELP_16k40 || total_brate == ACELP_24k40 ) && st->element_mode == EVS_MONO ) + { + st->tec_tfa = 1; + } + else + { + st->tec_tfa = 0; } - } - st->cummulative_damping_float = 1.0f; + st->tec_flag = 0; + st->tfa_flag = 0; + + /* needed in decoder to read the bitstream */ + st->enableGplc = 0; + + st->flagGuidedAcelp = 0; + st->tonal_mdct_plc_active = 0; + st->T0_4th = L_SUBFR; + st->guidedT0 = st->T0_4th; + + if ( st->hPlcInfo != NULL && total_brate >= HQ_48k && st->element_mode == EVS_MONO ) + { + st->enablePlcWaveadjust = 1; + + if ( st->hTcxDec != NULL && ( st->ini_frame == 0 || last_total_brate < HQ_48k || st->last_codec_mode == MODE1 || st->force_lpd_reset ) ) + { + concealment_init( st->hTcxDec->L_frameTCX, st->hPlcInfo ); + } + } + else + { + st->enablePlcWaveadjust = 0; + } - for (i = 0; i < 2 * NB_SUBFR16k + 2; i++) - { - st->old_pitch_buf[i] = (float)st->pit_min; - } + /* PLC: [TCX: Tonal Concealment] */ + if ( st->hTonalMDCTConc != NULL && !( st->element_mode > EVS_MONO && st->ini_frame != 0 && st->hTonalMDCTConc->nSamples == st->hTcxDec->L_frameTCX ) ) + { + st->hTonalMDCTConc->nScaleFactors = 0; + st->hTonalMDCTConc->nSamples = 0; + st->hTonalMDCTConc->lastPcmOut_float = 0x0; + st->hTonalMDCTConc->lastBlockData.tonalConcealmentActive = 0; + st->hTonalMDCTConc->lastBlockData.nSamples = 0; - for (i = 0; i < 2 * NB_SUBFR16k + 2; i++) - { - st->mem_pitch_gain_float[i] = 1.f; - } + TonalMDCTConceal_Init_ivas( st->hTonalMDCTConc, st->hTcxDec->L_frameTCX, st->L_frame, FDNS_NPTS, st->hTcxCfg ); + } - st->old_fpitch_float = (float)st->pit_min; + st->last_tns_active = 0; + st->second_last_tns_active = 0; + st->second_last_core = -1; - st->rate_switching_init = 1; + if ( st->hTcxCfg != NULL && + st->element_mode != EVS_MONO ) + { + st->hTcxCfg->fIsTNSAllowed = getTnsAllowed( is_init ? total_brate : st->bits_frame_nominal * FRAMES_PER_SEC, st->igf, st->element_mode ); + } + if ( hTcxDec != NULL ) + { + hTcxDec->tcxltp_second_last_pitch_float = st->old_fpitch_float; + hTcxDec->tcxltp_third_last_pitch_float = st->old_fpitch_float; + } - st->reset_mem_AR = 0; + if ( ( total_brate == ACELP_9k60 || total_brate == ACELP_16k40 || total_brate == ACELP_24k40 ) && st->element_mode == EVS_MONO ) + { + st->dec_glr = 1; + } + else + { + st->dec_glr = 0; + } - /* For phase dispersion */ - set_zero(st->dispMem, 8); + st->dec_glr_idx = 0; - st->voice_fac_float = -1; /* purely unvoiced */ + st->VAD = 0; + if ( hTcxDec != NULL ) + { + hTcxDec->enableTcxLpc = 1; - /* TCX-LTP */ - if (hTcxLtpDec != NULL) - { - tcxltp_dec_init(hTcxLtpDec, st->ini_frame, st->last_codec_mode, st->element_mode, st->pit_max, st->sr_core); - } + hTcxDec->old_gaintcx_bfi_float = 0.0f; - /* TCX */ - if (hTcxDec != NULL) - { - st->old_fpitchFB_float = (float)hTcxDec->pit_min_TCX; + hTcxDec->tcx_hm_LtpPitchLag = -1; + } - if (st->ini_frame == 0 || (st->last_codec_mode == MODE1 && st->element_mode == EVS_MONO)) + if ( st->hTcxCfg != NULL ) { - hTcxDec->tcxltp_last_gain_unmodified_float = 0.f; + st->hTcxCfg->na_scale_flt = 1.f; } - /* TCX */ - hTcxDec->tcx_lpc_shaped_ari = getTcxLpcShapedAri(total_brate, st->rf_flag, st->element_mode); - - hTcxDec->envWeighted = 0; - } - - if (st->hBPF != NULL) - { - st->hBPF->pst_mem_deemp_err = 0.0f; - } - - if (st->tcxonly) - { - st->p_bpf_noise_buf_float = NULL; - } - else - { - st->p_bpf_noise_buf_float = st->bpf_noise_buf_float; - } - - if (bwidth == SWB && (total_brate == ACELP_16k40 || total_brate == ACELP_24k40) && st->element_mode == EVS_MONO) - { - st->tec_tfa = 1; - } - else - { - st->tec_tfa = 0; - } - - st->tec_flag = 0; - st->tfa_flag = 0; - - /* needed in decoder to read the bitstream */ - st->enableGplc = 0; - - st->flagGuidedAcelp = 0; - st->tonal_mdct_plc_active = 0; - st->T0_4th = L_SUBFR; - st->guidedT0 = st->T0_4th; - - if (st->hPlcInfo != NULL && total_brate >= HQ_48k && st->element_mode == EVS_MONO) - { - st->enablePlcWaveadjust = 1; - - if (st->hTcxDec != NULL && (st->ini_frame == 0 || last_total_brate < HQ_48k || st->last_codec_mode == MODE1 || st->force_lpd_reset)) - { - concealment_init(st->hTcxDec->L_frameTCX, st->hPlcInfo); - } - } - else - { - st->enablePlcWaveadjust = 0; - } - - /* PLC: [TCX: Tonal Concealment] */ - if (st->hTonalMDCTConc != NULL && !(st->element_mode > EVS_MONO && st->ini_frame != 0 && st->hTonalMDCTConc->nSamples == st->hTcxDec->L_frameTCX)) - { - st->hTonalMDCTConc->nScaleFactors = 0; - st->hTonalMDCTConc->nSamples = 0; - st->hTonalMDCTConc->lastPcmOut_float = 0x0; - st->hTonalMDCTConc->lastBlockData.tonalConcealmentActive = 0; - st->hTonalMDCTConc->lastBlockData.nSamples = 0; - - TonalMDCTConceal_Init_ivas(st->hTonalMDCTConc, st->hTcxDec->L_frameTCX, st->L_frame, FDNS_NPTS, st->hTcxCfg); - } - - st->last_tns_active = 0; - st->second_last_tns_active = 0; - st->second_last_core = -1; - - if (st->hTcxCfg != NULL && - st->element_mode != EVS_MONO) - { - st->hTcxCfg->fIsTNSAllowed = getTnsAllowed(is_init ? total_brate : st->bits_frame_nominal * FRAMES_PER_SEC, st->igf, st->element_mode); - } - if (hTcxDec != NULL) - { - hTcxDec->tcxltp_second_last_pitch_float = st->old_fpitch_float; - hTcxDec->tcxltp_third_last_pitch_float = st->old_fpitch_float; - } - - if ((total_brate == ACELP_9k60 || total_brate == ACELP_16k40 || total_brate == ACELP_24k40) && st->element_mode == EVS_MONO) - { - st->dec_glr = 1; - } - else - { - st->dec_glr = 0; - } - - st->dec_glr_idx = 0; - - st->VAD = 0; - if (hTcxDec != NULL) - { - hTcxDec->enableTcxLpc = 1; - - hTcxDec->old_gaintcx_bfi_float = 0.0f; - - hTcxDec->tcx_hm_LtpPitchLag = -1; - } - - if (st->hTcxCfg != NULL) - { - st->hTcxCfg->na_scale_flt = 1.f; - } - - return; + return; } #endif @@ -716,35 +716,35 @@ void open_decoder_LPD( *-----------------------------------------------------------------------*/ #ifndef IVAS_FLOAT_FIXED void tcxltp_dec_init( - TCX_LTP_DEC_HANDLE hTcxLtpDec, - const int16_t ini_frame, - const int16_t last_codec_mode, - const int16_t element_mode, - const int16_t pit_max, - const int32_t sr_core) + TCX_LTP_DEC_HANDLE hTcxLtpDec, + const int16_t ini_frame, + const int16_t last_codec_mode, + const int16_t element_mode, + const int16_t pit_max, + const int32_t sr_core ) { - hTcxLtpDec->tcxltp_gain_float = 0.0f; + hTcxLtpDec->tcxltp_gain_float = 0.0f; - hTcxLtpDec->tcxltp = getTcxLtp(sr_core); + hTcxLtpDec->tcxltp = getTcxLtp( sr_core ); - if (ini_frame == 0 || (last_codec_mode == MODE1 && element_mode == EVS_MONO)) - { + if ( ini_frame == 0 || ( last_codec_mode == MODE1 && element_mode == EVS_MONO ) ) + { - hTcxLtpDec->tcxltp_pitch_int = pit_max; - hTcxLtpDec->tcxltp_pitch_fr = 0; + hTcxLtpDec->tcxltp_pitch_int = pit_max; + hTcxLtpDec->tcxltp_pitch_fr = 0; - if (ini_frame == 0) - { - set_f(hTcxLtpDec->tcxltp_mem_in_float, 0.0f, TCXLTP_MAX_DELAY); - set_f(hTcxLtpDec->tcxltp_mem_out_float, 0.0f, L_FRAME48k); - hTcxLtpDec->tcxltp_pitch_int_post_prev = 0; - hTcxLtpDec->tcxltp_pitch_fr_post_prev = 0; - hTcxLtpDec->tcxltp_gain_post_prev_float = 0.f; - hTcxLtpDec->tcxltp_filt_idx_prev = -1; + if ( ini_frame == 0 ) + { + set_f( hTcxLtpDec->tcxltp_mem_in_float, 0.0f, TCXLTP_MAX_DELAY ); + set_f( hTcxLtpDec->tcxltp_mem_out_float, 0.0f, L_FRAME48k ); + hTcxLtpDec->tcxltp_pitch_int_post_prev = 0; + hTcxLtpDec->tcxltp_pitch_fr_post_prev = 0; + hTcxLtpDec->tcxltp_gain_post_prev_float = 0.f; + hTcxLtpDec->tcxltp_filt_idx_prev = -1; + } } - } - return; + return; } #endif /*-----------------------------------------------------------------------* @@ -768,18 +768,18 @@ void reset_tcx_overl_buf( #ifdef IVAS_FLOAT_FIXED void reset_tcx_overl_buf_fx( - TCX_DEC_HANDLE hTcxDec /* i/o: TCX decoder handle */ + TCX_DEC_HANDLE hTcxDec /* i/o: TCX decoder handle */ ) { - set16_fx(hTcxDec->old_syn_Overl, 0, L_FRAME32k / 2); /*HQ-CORE(bfi)->TCX don't need it*/ - hTcxDec->Q_old_syn_Overl = 0; - set16_fx(hTcxDec->syn_Overl_TDAC, 0, L_FRAME32k / 2); /*HQ-CORE(bfi)->TCX don't need it*/ - hTcxDec->Q_syn_Overl_TDAC = 0; - set16_fx(hTcxDec->syn_Overl, 0, L_FRAME32k / 2); /*HQ-CORE(bfi)->TCX don't need it*/ - hTcxDec->Q_syn_Overl = 0; - set16_fx(hTcxDec->syn_Overl_TDACFB, 0, L_FRAME_MAX / 2); /*HQ-CORE(bfi)->TCX don't need it*/ - hTcxDec->Q_syn_Overl_TDACFB = 0; - return; + set16_fx( hTcxDec->old_syn_Overl, 0, L_FRAME32k / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/ + hTcxDec->Q_old_syn_Overl = 0; + set16_fx( hTcxDec->syn_Overl_TDAC, 0, L_FRAME32k / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/ + hTcxDec->Q_syn_Overl_TDAC = 0; + set16_fx( hTcxDec->syn_Overl, 0, L_FRAME32k / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/ + hTcxDec->Q_syn_Overl = 0; + set16_fx( hTcxDec->syn_Overl_TDACFB, 0, L_FRAME_MAX / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/ + hTcxDec->Q_syn_Overl_TDACFB = 0; + return; } #endif @@ -826,4 +826,4 @@ void acelp_plc_mdct_transition( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/core_dec_init_fx.c b/lib_dec/core_dec_init_fx.c index 7b22bf9e5..835220694 100644 --- a/lib_dec/core_dec_init_fx.c +++ b/lib_dec/core_dec_init_fx.c @@ -21,14 +21,15 @@ *-----------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED void open_decoder_LPD_fx( - Decoder_State *st, - const Word32 total_brate, + Decoder_State *st, + const Word32 total_brate, #ifdef NEW_IVAS_OPEN_DEC const Word32 last_total_brate, #endif const Word16 bwidth #ifdef NEW_IVAS_OPEN_DEC - ,const Word16 is_mct, /* i : MCT mode flag */ + , + const Word16 is_mct, /* i : MCT mode flag */ #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT const Word16 last_element_mode, #endif @@ -56,21 +57,21 @@ void open_decoder_LPD_fx( st->total_brate = total_brate; #endif - IF (NE_16(st->codec_mode, MODE1)) /*already updated in MODE1*/ + IF( NE_16( st->codec_mode, MODE1 ) ) /*already updated in MODE1*/ { st->fscale_old = st->fscale; } - st->sr_core = getCoreSamplerateMode2(st->element_mode, st->total_brate, bwidth, st->flag_ACELP16k, st->rf_flag , st->is_ism_format ); + st->sr_core = getCoreSamplerateMode2( st->element_mode, st->total_brate, bwidth, st->flag_ACELP16k, st->rf_flag, st->is_ism_format ); - st->fscale = sr2fscale_fx(st->sr_core); - fscaleFB = sr2fscale_fx(st->output_Fs); + st->fscale = sr2fscale_fx( st->sr_core ); + fscaleFB = sr2fscale_fx( st->output_Fs ); /* initializing variables for frame lengths etc. right in the beginning */ - st->L_frame = extract_l(Mult_32_16(st->sr_core , 0x0290)); + st->L_frame = extract_l( Mult_32_16( st->sr_core, 0x0290 ) ); #ifndef NEW_IVAS_OPEN_DEC - hTcxDec->L_frameTCX = extract_l(Mult_32_16(st->output_Fs , 0x0290)); + hTcxDec->L_frameTCX = extract_l( Mult_32_16( st->output_Fs, 0x0290 ) ); #endif - IF (st->ini_frame == 0) + IF( st->ini_frame == 0 ) { st->last_L_frame = st->L_frame_past = st->L_frame; move16(); @@ -81,10 +82,10 @@ void open_decoder_LPD_fx( move16(); } #ifdef NEW_IVAS_OPEN_DEC - IF(st->hTcxDec != NULL) + IF( st->hTcxDec != NULL ) { - hTcxDec->L_frameTCX = extract_l(Mult_32_16(st->output_Fs, 0x0290)); - IF(st->ini_frame == 0) + hTcxDec->L_frameTCX = extract_l( Mult_32_16( st->output_Fs, 0x0290 ) ); + IF( st->ini_frame == 0 ) { st->L_frameTCX_past = st->hTcxDec->L_frameTCX; } @@ -92,96 +93,100 @@ void open_decoder_LPD_fx( #endif st->tcxonly = getTcxonly( #ifdef IVAS_CODE_SWITCHING - st->element_mode, + st->element_mode, #endif - st->total_brate + st->total_brate #ifdef IVAS_CODE_SWITCHING - ,is_mct + , + is_mct #endif - /*, st->is_ism_format Needed in the last version of float IVAS */ - ); + /*, st->is_ism_format Needed in the last version of float IVAS */ + ); move16(); /* the TD TCX PLC in MODE1 still runs with 80ms subframes */ st->nb_subfr = NB_SUBFR; move16(); - test();test();test();test(); + test(); + test(); + test(); + test(); - if ( (EQ_16(st->element_mode, EVS_MONO) && EQ_16(st->L_frame,L_FRAME16k) && LE_32(st->total_brate,32000)) || - (GT_16(st->element_mode, EVS_MONO) && EQ_16(st->L_frame, L_FRAME16k) && LE_32(total_brate, MAX_ACELP_BRATE)) || - (st->tcxonly != 0 && (EQ_32(st->sr_core,32000) || EQ_32(st->sr_core,16000)) ) - ) + if ( ( EQ_16( st->element_mode, EVS_MONO ) && EQ_16( st->L_frame, L_FRAME16k ) && LE_32( st->total_brate, 32000 ) ) || + ( GT_16( st->element_mode, EVS_MONO ) && EQ_16( st->L_frame, L_FRAME16k ) && LE_32( total_brate, MAX_ACELP_BRATE ) ) || + ( st->tcxonly != 0 && ( EQ_32( st->sr_core, 32000 ) || EQ_32( st->sr_core, 16000 ) ) ) ) { st->nb_subfr = NB_SUBFR16k; move16(); } /* (float)st->L_frame/(float)st->fscale * (float)FSCALE_DENOM/128.0f * (float)st->total_brate */ - st->bits_frame = extract_l(L_shr(Mpy_32_16_1( L_shl(st->total_brate, 1) , 20972), 6)); /* 20972 = 0.01 * 64 * 32768 */ + st->bits_frame = extract_l( L_shr( Mpy_32_16_1( L_shl( st->total_brate, 1 ), 20972 ), 6 ) ); /* 20972 = 0.01 * 64 * 32768 */ - assert(FSCALE_DENOM == 512); - assert(st->fscale == 2 * st->L_frame); /* this assumption is true if operated in 20ms frames with FSCALE_DENOM == 512, which is the current default */ - assert(st->bits_frame == (int)( (float)st->L_frame/(float)st->fscale * (float)FSCALE_DENOM/128.0f * (float)st->total_brate/100.0f + 0.49f )); + assert( FSCALE_DENOM == 512 ); + assert( st->fscale == 2 * st->L_frame ); /* this assumption is true if operated in 20ms frames with FSCALE_DENOM == 512, which is the current default */ + assert( st->bits_frame == (int) ( (float) st->L_frame / (float) st->fscale * (float) FSCALE_DENOM / 128.0f * (float) st->total_brate / 100.0f + 0.49f ) ); - st->TcxBandwidth = getTcxBandwidth(bwidth); - st->narrowBand = 0; + st->TcxBandwidth = getTcxBandwidth( bwidth ); + st->narrowBand = 0; move16(); - if (EQ_16(bwidth, NB)) + if ( EQ_16( bwidth, NB ) ) { - st->narrowBand = 1; + st->narrowBand = 1; move16(); } - IF (EQ_16(st->element_mode, IVAS_CPE_MDCT)) + IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) { - st->pit_res_max = initPitchLagParameters(INT_FS_12k8, &st->pit_min, &st->pit_fr1, &st->pit_fr1b, &st->pit_fr2, &st->pit_max); - IF(hTcxDec != NULL) + st->pit_res_max = initPitchLagParameters( INT_FS_12k8, &st->pit_min, &st->pit_fr1, &st->pit_fr1b, &st->pit_fr2, &st->pit_max ); + IF( hTcxDec != NULL ) { - //st->pit_res_max = initPitchLagParameters(12800, &st->pit_min, &st->pit_fr1, &st->pit_fr1b, &st->pit_fr2, &st->pit_max); - //hTcxDec->pit_max_TCX = (int16_t)(st->pit_max * st->output_Fs / 12800); - //hTcxDec->pit_min_TCX = (int16_t)(st->pit_min * st->output_Fs / 12800); + // st->pit_res_max = initPitchLagParameters(12800, &st->pit_min, &st->pit_fr1, &st->pit_fr1b, &st->pit_fr2, &st->pit_max); + // hTcxDec->pit_max_TCX = (int16_t)(st->pit_max * st->output_Fs / 12800); + // hTcxDec->pit_min_TCX = (int16_t)(st->pit_min * st->output_Fs / 12800); #if 0 PMT("Fixed point to be verified here") #endif - i = mult_r(hTcxDec->L_frameTCX, getInvFrameLen(L_FRAME)); - hTcxDec->pit_max_TCX = extract_l(L_shr(L_mult(st->pit_max, i), 7)); - hTcxDec->pit_min_TCX = extract_l(L_shr(L_mult(st->pit_min, i), 7)); - + i = mult_r( hTcxDec->L_frameTCX, getInvFrameLen( L_FRAME ) ); + hTcxDec->pit_max_TCX = extract_l( L_shr( L_mult( st->pit_max, i ), 7 ) ); + hTcxDec->pit_min_TCX = extract_l( L_shr( L_mult( st->pit_min, i ), 7 ) ); } } ELSE { - st->pit_res_max = initPitchLagParameters(st->sr_core, &st->pit_min, &st->pit_fr1, &st->pit_fr1b, &st->pit_fr2, &st->pit_max); - IF (hTcxDec != NULL) + st->pit_res_max = initPitchLagParameters( st->sr_core, &st->pit_min, &st->pit_fr1, &st->pit_fr1b, &st->pit_fr2, &st->pit_max ); + IF( hTcxDec != NULL ) { - i = mult_r(hTcxDec->L_frameTCX, getInvFrameLen(st->L_frame)); - hTcxDec->pit_max_TCX = extract_l(L_shr(L_mult(st->pit_max, i), 7)); - hTcxDec->pit_min_TCX = extract_l(L_shr(L_mult(st->pit_min, i), 7)); + i = mult_r( hTcxDec->L_frameTCX, getInvFrameLen( st->L_frame ) ); + hTcxDec->pit_max_TCX = extract_l( L_shr( L_mult( st->pit_max, i ), 7 ) ); + hTcxDec->pit_min_TCX = extract_l( L_shr( L_mult( st->pit_min, i ), 7 ) ); } } - IF ( st->ini_frame == 0) + IF( st->ini_frame == 0 ) { st->pit_res_max_past = st->pit_res_max; } /*Preemphasis param*/ - st->preemph_fac = PREEMPH_FAC_SWB; /*SWB*/ move16(); - IF ( LT_16(st->fscale, (16000*FSCALE_DENOM)/ INT_FS_12k8)) + st->preemph_fac = PREEMPH_FAC_SWB; /*SWB*/ + move16(); + IF( LT_16( st->fscale, ( 16000 * FSCALE_DENOM ) / INT_FS_12k8 ) ) { - st->preemph_fac = PREEMPH_FAC; /*WB*/ move16(); + st->preemph_fac = PREEMPH_FAC; /*WB*/ + move16(); } - ELSE if ( LT_16(st->fscale, (24000*FSCALE_DENOM)/ INT_FS_12k8)) + ELSE if ( LT_16( st->fscale, ( 24000 * FSCALE_DENOM ) / INT_FS_12k8 ) ) { - st->preemph_fac = PREEMPH_FAC_16k; /*WB*/ move16(); + st->preemph_fac = PREEMPH_FAC_16k; /*WB*/ + move16(); } st->gamma = GAMMA1; move16(); st->inv_gamma = GAMMA1_INV; move16(); - IF ( EQ_32(st->sr_core, INT_FS_16k) || - (GT_32(st->sr_core, INT_FS_16k) && EQ_16(st->element_mode, IVAS_CPE_MDCT) ) - ) + IF( EQ_32( st->sr_core, INT_FS_16k ) || + ( GT_32( st->sr_core, INT_FS_16k ) && EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) ) { st->gamma = GAMMA16k; move16(); @@ -190,17 +195,17 @@ void open_decoder_LPD_fx( } /* LPC quantization */ - st-> lpcQuantization = 0; + st->lpcQuantization = 0; move16(); test(); - if( st->tcxonly == 0 && LE_32(st->sr_core, INT_FS_16k)) + if ( st->tcxonly == 0 && LE_32( st->sr_core, INT_FS_16k ) ) { st->lpcQuantization = 1; } st->numlpc = 2; move16(); - if ( st->tcxonly==0 ) + if ( st->tcxonly == 0 ) { st->numlpc = 1; move16(); @@ -208,11 +213,11 @@ void open_decoder_LPD_fx( /* Initialize TBE */ st->prev_coder_type = GENERIC; - if (st->hBWE_TD != NULL) + if ( st->hBWE_TD != NULL ) { - set16_fx(hBWE_TD->prev_lsf_diff_fx, 16384, LPC_SHB_ORDER - 2); + set16_fx( hBWE_TD->prev_lsf_diff_fx, 16384, LPC_SHB_ORDER - 2 ); hBWE_TD->prev_tilt_para_fx = 0; - set16_fx(hBWE_TD->cur_sub_Aq_fx, 0, M + 1); + set16_fx( hBWE_TD->cur_sub_Aq_fx, 0, M + 1 ); } /*TCX config*/ @@ -221,8 +226,8 @@ void open_decoder_LPD_fx( move16(); st->hTcxCfg->tcx_mdct_window_length_old = st->hTcxCfg->tcx_mdct_window_length; move16(); - init_TCX_config( st->hTcxCfg, st->L_frame, st->fscale, hTcxDec->L_frameTCX, fscaleFB ); // TEMPORARY should be rename to init_TCX_config - IF(st->ini_frame == 0) + init_TCX_config( st->hTcxCfg, st->L_frame, st->fscale, hTcxDec->L_frameTCX, fscaleFB ); // TEMPORARY should be rename to init_TCX_config + IF( st->ini_frame == 0 ) { st->hTcxCfg->tcx_last_overlap_mode = st->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; move16(); @@ -230,81 +235,79 @@ void open_decoder_LPD_fx( } /* TCX Offset */ - st->hTcxCfg->tcx_offset = shr(st->hTcxCfg->tcx_mdct_window_delay, 1); - st->hTcxCfg->tcx_offsetFB = shr(st->hTcxCfg->tcx_mdct_window_delayFB, 1); + st->hTcxCfg->tcx_offset = shr( st->hTcxCfg->tcx_mdct_window_delay, 1 ); + st->hTcxCfg->tcx_offsetFB = shr( st->hTcxCfg->tcx_mdct_window_delayFB, 1 ); /* Initialize FAC */ - st->hTcxCfg->lfacNext = sub(st->hTcxCfg->tcx_offset, shr(st->L_frame, 2)); - st->hTcxCfg->lfacNextFB = sub(st->hTcxCfg->tcx_offsetFB, shr(hTcxDec->L_frameTCX, 2)); + st->hTcxCfg->lfacNext = sub( st->hTcxCfg->tcx_offset, shr( st->L_frame, 2 ) ); + st->hTcxCfg->lfacNextFB = sub( st->hTcxCfg->tcx_offsetFB, shr( hTcxDec->L_frameTCX, 2 ) ); /* set number of coded lines */ - st->hTcxCfg->tcx_coded_lines = getNumTcxCodedLines(st->bwidth); + st->hTcxCfg->tcx_coded_lines = getNumTcxCodedLines( st->bwidth ); /* TNS in TCX */ st->hTcxCfg->pCurrentTnsConfig = NULL; - st->hTcxCfg->fIsTNSAllowed = getTnsAllowed(st->total_brate, st->igf, st->element_mode); + st->hTcxCfg->fIsTNSAllowed = getTnsAllowed( st->total_brate, st->igf, st->element_mode ); - IF(st->hTcxCfg->fIsTNSAllowed != 0) + IF( st->hTcxCfg->fIsTNSAllowed != 0 ) { - InitTnsConfigs(st->bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFDec->infoIGFStopFreq, st->total_brate, st->element_mode, 0/*is_mct*/); - + InitTnsConfigs( st->bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFDec->infoIGFStopFreq, st->total_brate, st->element_mode, 0 /*is_mct*/ ); } /*Constraint for adaptive BPF, otherwise parameter estimation and post-processing not time aligned*/ - if (st->tcxonly == 0) + if ( st->tcxonly == 0 ) { - assert(0 == (st->hTcxCfg->lfacNext > 0 ? st->hTcxCfg->lfacNext : 0)); + assert( 0 == ( st->hTcxCfg->lfacNext > 0 ? st->hTcxCfg->lfacNext : 0 ) ); } - if (1)//st->element_mode == EVS_MONO) + if ( 1 ) // st->element_mode == EVS_MONO) { - if(st->hTECDec == NULL) + if ( st->hTECDec == NULL ) { - if ((st->hTECDec = (TEC_DEC_HANDLE)malloc(sizeof(TEC_DEC_DATA))) == NULL) + if ( ( st->hTECDec = (TEC_DEC_HANDLE) malloc( sizeof( TEC_DEC_DATA ) ) ) == NULL ) { - //return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TEC\n")); - assert(0); + // return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TEC\n")); + assert( 0 ); } } } else { - st->hTECDec = NULL; + st->hTECDec = NULL; } - resetTecDec_Fx(st->hTECDec); + resetTecDec_Fx( st->hTECDec ); #else - if (st->hIGFDec != NULL) + if ( st->hIGFDec != NULL ) { - PMT("To be done") - //if (!is_init || st->element_mode != IVAS_CPE_MDCT) + PMT( "To be done" ) + // if (!is_init || st->element_mode != IVAS_CPE_MDCT) //{ - // init_tcx_cfg(st->hTcxCfg, total_brate, st->sr_core, st->output_Fs, st->L_frame, st->bwidth, st->hTcxDec->L_frameTCX, st->fscale, encoderLookahead, encoderLookaheadFB, st->preemph_fac, st->tcxonly, st->rf_flag, st->igf, st->hIGFDec->infoIGFStopFreq, st->element_mode, st->ini_frame, MCT_flag); - //} - //else + // init_tcx_cfg(st->hTcxCfg, total_brate, st->sr_core, st->output_Fs, st->L_frame, st->bwidth, st->hTcxDec->L_frameTCX, st->fscale, encoderLookahead, encoderLookaheadFB, st->preemph_fac, st->tcxonly, st->rf_flag, st->igf, st->hIGFDec->infoIGFStopFreq, st->element_mode, st->ini_frame, MCT_flag); + // } + // else //{ - // st->hTcxCfg->tcx_curr_overlap_mode = st->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; - // st->hTcxCfg->last_aldo = 1; - //} + // st->hTcxCfg->tcx_curr_overlap_mode = st->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; + // st->hTcxCfg->last_aldo = 1; + // } } /*Constraint for adaptive BPF, otherwise parameter estimation and post-processing not time aligned*/ - if (st->tcxonly == 0) + if ( st->tcxonly == 0 ) { - assert(0 == (st->hTcxCfg->lfacNext > 0 ? st->hTcxCfg->lfacNext : 0)); + assert( 0 == ( st->hTcxCfg->lfacNext > 0 ? st->hTcxCfg->lfacNext : 0 ) ); } - //if (st->tecDec_fx != NULL) + // if (st->tecDec_fx != NULL) { - resetTecDec_Fx(&(st->tecDec_fx)); + resetTecDec_Fx( &( st->tecDec_fx ) ); } #endif - - - + + /* Initialize decoder delay */ - IF (NE_16(st->element_mode, IVAS_SCE)) + IF( NE_16( st->element_mode, IVAS_SCE ) ) { st->flag_cna = 0; move16(); @@ -317,7 +320,7 @@ void open_decoder_LPD_fx( } /* Static vectors to zero */ - IF (st->ini_frame == 0) + IF( st->ini_frame == 0 ) { st->last_is_cng = 0; @@ -325,26 +328,26 @@ void open_decoder_LPD_fx( st->rate_switching_reset = 0; move16(); - IF(hTcxDec != NULL) + IF( hTcxDec != NULL ) { - set16_fx(hTcxDec->old_syn_Overl, 0, L_FRAME32k / 2); + set16_fx( hTcxDec->old_syn_Overl, 0, L_FRAME32k / 2 ); - set16_fx(hTcxDec->syn_Overl_TDAC, 0, L_FRAME32k / 2); - set16_fx(hTcxDec->syn_OverlFB, 0, L_FRAME_MAX / 2); - set16_fx(hTcxDec->syn_Overl_TDACFB, 0, L_FRAME_MAX / 2); + set16_fx( hTcxDec->syn_Overl_TDAC, 0, L_FRAME32k / 2 ); + set16_fx( hTcxDec->syn_OverlFB, 0, L_FRAME_MAX / 2 ); + set16_fx( hTcxDec->syn_Overl_TDACFB, 0, L_FRAME_MAX / 2 ); - set16_fx(hTcxDec->syn_Overl, 0, L_FRAME32k / 2); + set16_fx( hTcxDec->syn_Overl, 0, L_FRAME32k / 2 ); - set16_fx(hTcxDec->old_synth, 0, OLD_SYNTH_INTERNAL_DEC); - set16_fx(hTcxDec->synth_history_fx, 0, L_PROT48k + L_FRAME_MAX); + set16_fx( hTcxDec->old_synth, 0, OLD_SYNTH_INTERNAL_DEC ); + set16_fx( hTcxDec->synth_history_fx, 0, L_PROT48k + L_FRAME_MAX ); hTcxDec->q_synth_history_fx = 0; } - set16_fx(st->syn, 0, M+1); + set16_fx( st->syn, 0, M + 1 ); - set16_fx(st->mem_syn_r, 0, L_SYN_MEM); + set16_fx( st->mem_syn_r, 0, L_SYN_MEM ); - mem_syn_r_size_old = 0; /* just to avoid MSVC warnings */ - mem_syn_r_size_new = 0; /* just to avoid MSVC warnings */ + mem_syn_r_size_old = 0; /* just to avoid MSVC warnings */ + mem_syn_r_size_new = 0; /* just to avoid MSVC warnings */ st->con_tcx = 0; } @@ -352,25 +355,24 @@ void open_decoder_LPD_fx( { /* Reset old_synth in case of core sampling rate switching and codec switching*/ test(); - IF(st->hTcxDec != NULL && ((NE_16(st->L_frame, st->last_L_frame))||(EQ_16(st->last_codec_mode,MODE1)))) + IF( st->hTcxDec != NULL && ( ( NE_16( st->L_frame, st->last_L_frame ) ) || ( EQ_16( st->last_codec_mode, MODE1 ) ) ) ) { - set16_fx(hTcxDec->old_synth, 0, OLD_SYNTH_INTERNAL_DEC); + set16_fx( hTcxDec->old_synth, 0, OLD_SYNTH_INTERNAL_DEC ); } /*Size of LPC syn memory*/ /* 1.25/20.0 = 1.0/16.0 -> shift 4 to the right. */ - mem_syn_r_size_old = shr(st->last_L_frame, 4); - mem_syn_r_size_new = shr(st->L_frame, 4); + mem_syn_r_size_old = shr( st->last_L_frame, 4 ); + mem_syn_r_size_new = shr( st->L_frame, 4 ); /*Reset LPC mem*/ test(); test(); - IF( (NE_16(st->L_frame,st->last_L_frame))||(EQ_16(st->last_core,AMR_WB_CORE)) - || EQ_16(st->last_core,HQ_CORE) ) + IF( ( NE_16( st->L_frame, st->last_L_frame ) ) || ( EQ_16( st->last_core, AMR_WB_CORE ) ) || EQ_16( st->last_core, HQ_CORE ) ) { /*LPC quant. mem*/ - set16_fx(st->mem_MA_fx, 0, M); - IF( EQ_32(st->sr_core, INT_FS_16k)) + set16_fx( st->mem_MA_fx, 0, M ); + IF( EQ_32( st->sr_core, INT_FS_16k ) ) { Copy( GEWB2_Ave_fx, st->mem_AR_fx, M ); } @@ -381,13 +383,13 @@ void open_decoder_LPD_fx( } /*Codec switching*/ - IF( EQ_16(st->last_codec_mode,MODE1) && EQ_16(st->element_mode, EVS_MONO)) + IF( EQ_16( st->last_codec_mode, MODE1 ) && EQ_16( st->element_mode, EVS_MONO ) ) { Copy( st->lsp_old_fx, st->lspold_uw, M ); Copy( st->lsf_old_fx, st->lsfold_uw, M ); set16_fx( st->syn, 0, M ); } - IF( EQ_16(st->last_core,AMR_WB_CORE)) + IF( EQ_16( st->last_core, AMR_WB_CORE ) ) { st->last_core = ACELP_CORE; move16(); @@ -396,56 +398,59 @@ void open_decoder_LPD_fx( } /*Codec switching from ACELP-A */ - test(); test(); test(); test(); - IF( (NE_16(st->element_mode, IVAS_CPE_DFT) || (EQ_16(st->element_mode, IVAS_CPE_DFT) && st->prev_bfi ) ) && EQ_16(st->last_codec_mode, MODE1) && EQ_16(st->last_core,ACELP_CORE) ) + test(); + test(); + test(); + test(); + IF( ( NE_16( st->element_mode, IVAS_CPE_DFT ) || ( EQ_16( st->element_mode, IVAS_CPE_DFT ) && st->prev_bfi ) ) && EQ_16( st->last_codec_mode, MODE1 ) && EQ_16( st->last_core, ACELP_CORE ) ) { st->last_core_bfi = ACELP_CORE; move16(); /*PLC*/ #ifndef NEW_IVAS_OPEN_DEC - IF(st->prev_bfi!=0) + IF( st->prev_bfi != 0 ) { - PWord16 const *w; - Word16 W1,W2,nz,delay_comp; + PWord16 const *w; + Word16 W1, W2, nz, delay_comp; W1 = st->hTcxCfg->tcx_mdct_window_lengthFB; move16(); - W2 = shr(st->hTcxCfg->tcx_mdct_window_lengthFB, 1); + W2 = shr( st->hTcxCfg->tcx_mdct_window_lengthFB, 1 ); w = st->hTcxCfg->tcx_mdct_windowFB; /*pointer - no need to instrument*/ - nz = NS2SA_fx2(st->output_Fs, N_ZERO_MDCT_NS); - delay_comp = NS2SA_fx2(st->output_Fs, DELAY_CLDFB_NS); /*CLDFB delay*/ + nz = NS2SA_fx2( st->output_Fs, N_ZERO_MDCT_NS ); + delay_comp = NS2SA_fx2( st->output_Fs, DELAY_CLDFB_NS ); /*CLDFB delay*/ - Copy(hHQ_core->fer_samples_fx+delay_comp, hTcxDec->syn_OverlFB, shr(hTcxDec->L_frameTCX,1)); + Copy( hHQ_core->fer_samples_fx + delay_comp, hTcxDec->syn_OverlFB, shr( hTcxDec->L_frameTCX, 1 ) ); - lerp(hHQ_core->fer_samples_fx+delay_comp, hTcxDec->syn_Overl , shr(st->L_frame,1), shr(hTcxDec->L_frameTCX,1)); /*Q0: ACELP(bfi)->TCX(rect)*/ + lerp( hHQ_core->fer_samples_fx + delay_comp, hTcxDec->syn_Overl, shr( st->L_frame, 1 ), shr( hTcxDec->L_frameTCX, 1 ) ); /*Q0: ACELP(bfi)->TCX(rect)*/ /*old_out needed for MODE1 routine and syn_Overl_TDAC for MODE2 routine*/ - hHQ_core->Q_old_wtda=-1; - set16_fx(hHQ_core->old_out_fx, 0, nz); - Copy_Scale_sig(hHQ_core->fer_samples_fx+delay_comp, hHQ_core->old_out_fx+nz,W1, hHQ_core->Q_old_wtda); /*Q-1*/ + hHQ_core->Q_old_wtda = -1; + set16_fx( hHQ_core->old_out_fx, 0, nz ); + Copy_Scale_sig( hHQ_core->fer_samples_fx + delay_comp, hHQ_core->old_out_fx + nz, W1, hHQ_core->Q_old_wtda ); /*Q-1*/ - FOR (i=0; i < W2; i++) + FOR( i = 0; i < W2; i++ ) { - hHQ_core->old_out_fx[i+nz] = round_fx(Mpy_32_16_1(L_mult(w[i].v.re,w[i].v.re), hHQ_core->old_out_fx[i+nz])); + hHQ_core->old_out_fx[i + nz] = round_fx( Mpy_32_16_1( L_mult( w[i].v.re, w[i].v.re ), hHQ_core->old_out_fx[i + nz] ) ); } - FOR ( ; i < W1; i++) + FOR( ; i < W1; i++ ) { - hHQ_core->old_out_fx[i+nz] = round_fx(Mpy_32_16_1(L_mult(w[W2-1-(i-W2)].v.im,w[W2-1-(i-W2)].v.im), hHQ_core->old_out_fx[i+nz])); + hHQ_core->old_out_fx[i + nz] = round_fx( Mpy_32_16_1( L_mult( w[W2 - 1 - ( i - W2 )].v.im, w[W2 - 1 - ( i - W2 )].v.im ), hHQ_core->old_out_fx[i + nz] ) ); } - set16_fx(&hHQ_core->old_out_fx[W1+nz], 0, nz); + set16_fx( &hHQ_core->old_out_fx[W1 + nz], 0, nz ); - lerp(hHQ_core->old_out_fx, hHQ_core->old_out_LB_fx,st->L_frame , hTcxDec->L_frameTCX); + lerp( hHQ_core->old_out_fx, hHQ_core->old_out_LB_fx, st->L_frame, hTcxDec->L_frameTCX ); - Copy(hHQ_core->old_out_fx +nz, hTcxDec->syn_Overl_TDACFB, shr(hTcxDec->L_frameTCX,1)); - nz = NS2SA_fx2(st->sr_core, N_ZERO_MDCT_NS); - Copy(hHQ_core->old_out_LB_fx+nz, hTcxDec->syn_Overl_TDAC , shr(st->L_frame,1)); + Copy( hHQ_core->old_out_fx + nz, hTcxDec->syn_Overl_TDACFB, shr( hTcxDec->L_frameTCX, 1 ) ); + nz = NS2SA_fx2( st->sr_core, N_ZERO_MDCT_NS ); + Copy( hHQ_core->old_out_LB_fx + nz, hTcxDec->syn_Overl_TDAC, shr( st->L_frame, 1 ) ); hHQ_core->Q_old_wtda_LB = hHQ_core->Q_old_wtda; } #else - PMT("acelp_plc_mdct_transition is missing") - //acelp_plc_mdct_transition(st); + PMT( "acelp_plc_mdct_transition is missing" ) + // acelp_plc_mdct_transition(st); #endif } @@ -456,61 +461,61 @@ void open_decoder_LPD_fx( test(); test(); test(); - IF( EQ_16(st->last_codec_mode,MODE2)&& - NE_16(st->L_frame, st->last_L_frame) && - ( ( EQ_16(st->m_frame_type, SID_FRAME) && GT_16(st->last_core, ACELP_CORE) ) || - ( GT_16(st->last_core, ACELP_CORE) && GT_16(st->core, ACELP_CORE) ) || + IF( EQ_16( st->last_codec_mode, MODE2 ) && + NE_16( st->L_frame, st->last_L_frame ) && + ( ( EQ_16( st->m_frame_type, SID_FRAME ) && GT_16( st->last_core, ACELP_CORE ) ) || + ( GT_16( st->last_core, ACELP_CORE ) && GT_16( st->core, ACELP_CORE ) ) || st->prev_bfi ) ) { - lerp(hHQ_core->old_out_LB_fx, hHQ_core->old_out_LB_fx, st->L_frame, st->last_L_frame); + lerp( hHQ_core->old_out_LB_fx, hHQ_core->old_out_LB_fx, st->L_frame, st->last_L_frame ); } /* Rate switching */ test(); test(); test(); - IF( EQ_16(st->last_codec_mode,MODE1)&&EQ_16(st->last_core,HQ_CORE)) + IF( EQ_16( st->last_codec_mode, MODE1 ) && EQ_16( st->last_core, HQ_CORE ) ) { /*Codec switching from MDCT */ /*Reset of ACELP memories*/ move16(); move16(); - st->rate_switching_reset=1; + st->rate_switching_reset = 1; st->tilt_code_fx = TILT_CODE; - set16_fx(st->old_exc_fx, 0, L_EXC_MEM_DEC); - set16_fx(st->syn, 0, 1+M); - set16_fx(st->mem_syn2_fx, 0, M); + set16_fx( st->old_exc_fx, 0, L_EXC_MEM_DEC ); + set16_fx( st->syn, 0, 1 + M ); + set16_fx( st->mem_syn2_fx, 0, M ); /*OLA -> zero */ - if (st->hTcxDec != NULL) + if ( st->hTcxDec != NULL ) { - set16_fx(hTcxDec->old_syn_Overl, 0, L_FRAME32k / 2); /*HQ-CORE(bfi)->TCX don't need it*/ - set16_fx(hTcxDec->syn_Overl_TDAC, 0, L_FRAME32k / 2); /*HQ-CORE(bfi)->TCX don't need it*/ - set16_fx(hTcxDec->syn_Overl_TDACFB, 0, L_FRAME_MAX / 2); /*HQ-CORE(bfi)->TCX don't need it*/ - set16_fx(hTcxDec->syn_Overl, 0, L_FRAME32k / 2); /*HQ-CORE(bfi)->TCX don't need it*/ + set16_fx( hTcxDec->old_syn_Overl, 0, L_FRAME32k / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/ + set16_fx( hTcxDec->syn_Overl_TDAC, 0, L_FRAME32k / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/ + set16_fx( hTcxDec->syn_Overl_TDACFB, 0, L_FRAME_MAX / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/ + set16_fx( hTcxDec->syn_Overl, 0, L_FRAME32k / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/ #if 0 PMT("to be moved to reset_tcx_overl_buf") #endif } - if (st->hTcxCfg != NULL) + if ( st->hTcxCfg != NULL ) { - Copy_Scale_sig(hHQ_core->old_out_fx + NS2SA(st->output_Fs, N_ZERO_MDCT_NS), hTcxDec->syn_OverlFB, st->hTcxCfg->tcx_mdct_window_lengthFB, negate(add(hHQ_core->Q_old_wtda, TCX_IMDCT_HEADROOM))); + Copy_Scale_sig( hHQ_core->old_out_fx + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->syn_OverlFB, st->hTcxCfg->tcx_mdct_window_lengthFB, negate( add( hHQ_core->Q_old_wtda, TCX_IMDCT_HEADROOM ) ) ); move16(); move16(); - st->hTcxCfg->last_aldo = 1; /*It was previously ALDO*/ + st->hTcxCfg->last_aldo = 1; /*It was previously ALDO*/ st->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; } /*OLA for MDCT-LB always reset in codec switching cases*/ - if (st->hHQ_core != NULL) + if ( st->hHQ_core != NULL ) { - set16_fx(hHQ_core->old_out_LB_fx, 0, st->L_frame); + set16_fx( hHQ_core->old_out_LB_fx, 0, st->L_frame ); } move16(); st->last_core_bfi = TCX_20_CORE; - if (st->hPFstat != NULL) + if ( st->hPFstat != NULL ) { st->hPFstat->on = 0; } @@ -523,18 +528,18 @@ void open_decoder_LPD_fx( #if 0 PMT("cldfbSynHB is missing ") #endif - //if (st->cldfbSynHB != NULL) + // if (st->cldfbSynHB != NULL) //{ - // cldfb_reset_memory(st->cldfbSynHB); - //} + // cldfb_reset_memory(st->cldfbSynHB); + // } #endif } - ELSE IF( (NE_16(st->L_frame,st->last_L_frame))&&(LE_16(st->L_frame,L_FRAME16k))&&(LE_16(st->last_L_frame,L_FRAME16k))) /* Rate switching between 12.8 and 16 kHz*/ + ELSE IF( ( NE_16( st->L_frame, st->last_L_frame ) ) && ( LE_16( st->L_frame, L_FRAME16k ) ) && ( LE_16( st->last_L_frame, L_FRAME16k ) ) ) /* Rate switching between 12.8 and 16 kHz*/ { /*Interpolation of ACELP memories*/ /* convert quantized LSP vector */ - st->rate_switching_reset=lsp_convert_poly_fx( st->lsp_old_fx, st->L_frame, 0 ); + st->rate_switching_reset = lsp_convert_poly_fx( st->lsp_old_fx, st->L_frame, 0 ); IF( st->tcxonly == 0 ) { lsp2lsf_fx( st->lsp_old_fx, st->lsf_old_fx, M, st->sr_core ); @@ -543,7 +548,7 @@ void open_decoder_LPD_fx( { E_LPC_lsp_lsf_conversion( st->lsp_old_fx, st->lsf_old_fx, M ); } - E_LPC_f_lsp_a_conversion(st->lsp_old_fx, st->old_Aq_12_8_fx, M); + E_LPC_f_lsp_a_conversion( st->lsp_old_fx, st->old_Aq_12_8_fx, M ); Copy( st->lsp_old_fx, st->lspold_uw, M ); @@ -556,7 +561,7 @@ void open_decoder_LPD_fx( /*mem of deemphasis stayed unchanged.*/ } - ELSE IF( NE_16(st->L_frame,st->last_L_frame)) /* Rate switching involving TCX only modes */ + ELSE IF( NE_16( st->L_frame, st->last_L_frame ) ) /* Rate switching involving TCX only modes */ { /*Partial reset of ACELP memories*/ st->rate_switching_reset = 1; @@ -567,16 +572,16 @@ void open_decoder_LPD_fx( { set16_fx( st->old_exc_fx, 0, L_EXC_MEM_DEC ); } - set16_fx( st->old_Aq_12_8_fx, 0, M+1 ); + set16_fx( st->old_Aq_12_8_fx, 0, M + 1 ); /*Resamp others memories*/ /*Size of LPC syn memory*/ - lerp( st->mem_syn_r+L_SYN_MEM-mem_syn_r_size_old, st->mem_syn_r+L_SYN_MEM-mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); - Copy( st->mem_syn_r+L_SYN_MEM-M, st->mem_syn2_fx, M ); + lerp( st->mem_syn_r + L_SYN_MEM - mem_syn_r_size_old, st->mem_syn_r + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); + Copy( st->mem_syn_r + L_SYN_MEM - M, st->mem_syn2_fx, M ); /*Untouched memories : st->syn */ } - ELSE IF( !st->tcxonly && EQ_16(st->L_frame,L_FRAME16k)&>_32(st->last_total_brate,ACELP_32k)) + ELSE IF( !st->tcxonly && EQ_16( st->L_frame, L_FRAME16k ) && GT_32( st->last_total_brate, ACELP_32k ) ) { lsp2lsf_fx( st->lsp_old_fx, st->lsf_old_fx, M, st->sr_core ); } @@ -584,86 +589,86 @@ void open_decoder_LPD_fx( test(); test(); - if(EQ_16(st->last_bwidth,NB)&&NE_16(st->bwidth,NB)&&st->ini_frame!=0) + if ( EQ_16( st->last_bwidth, NB ) && NE_16( st->bwidth, NB ) && st->ini_frame != 0 ) { - st->rate_switching_reset=1; + st->rate_switching_reset = 1; move16(); } - IF (st->hTcxDec != NULL) + IF( st->hTcxDec != NULL ) { - hTcxDec->old_synth_len = shl(st->L_frame, 1); - hTcxDec->old_synth_lenFB = shl(hTcxDec->L_frameTCX, 1); + hTcxDec->old_synth_len = shl( st->L_frame, 1 ); + hTcxDec->old_synth_lenFB = shl( hTcxDec->L_frameTCX, 1 ); } /* bass pf reset */ st->bpf_gain_param = 0; move16(); - if (st->hBPF != NULL) + if ( st->hBPF != NULL ) { - set16_fx(hBPF->pst_old_syn_fx, 0, NBPSF_PIT_MAX); + set16_fx( hBPF->pst_old_syn_fx, 0, NBPSF_PIT_MAX ); } /* Formant postfilter */ - IF ( st->ini_frame==0 ) + IF( st->ini_frame == 0 ) { /*do nothing*/ } - ELSE IF( EQ_16(st->last_codec_mode,MODE2)) + ELSE IF( EQ_16( st->last_codec_mode, MODE2 ) ) { - IF (st->tcxonly==0) + IF( st->tcxonly == 0 ) { - IF ( st->hPFstat->on!=0 ) + IF( st->hPFstat->on != 0 ) { - lerp( st->hPFstat->mem_stp+L_SYN_MEM-mem_syn_r_size_old, st->hPFstat->mem_stp+L_SYN_MEM-mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); - lerp( st->hPFstat->mem_pf_in+L_SYN_MEM-mem_syn_r_size_old, st->hPFstat->mem_pf_in+L_SYN_MEM-mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); + lerp( st->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); + lerp( st->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); } ELSE { - set16_fx( st->hPFstat->mem_stp, 0,L_SYN_MEM ); - set16_fx( st->hPFstat->mem_pf_in, 0,L_SYN_MEM ); + set16_fx( st->hPFstat->mem_stp, 0, L_SYN_MEM ); + set16_fx( st->hPFstat->mem_pf_in, 0, L_SYN_MEM ); st->hPFstat->reset = 1; st->hPFstat->gain_prec = 16384; move16(); } } - ELSE IF ( st->hPFstat->on!=0 ) + ELSE IF( st->hPFstat->on != 0 ) { - lerp( st->hPFstat->mem_stp+L_SYN_MEM-mem_syn_r_size_old, st->hPFstat->mem_stp+L_SYN_MEM-mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); - lerp( st->hPFstat->mem_pf_in+L_SYN_MEM-mem_syn_r_size_old, st->hPFstat->mem_pf_in+L_SYN_MEM-mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); + lerp( st->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); + lerp( st->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); } } ELSE { /*codec switching*/ /*reset post-filter except for Narrowband*/ - IF ( NE_32(st->output_Fs,8000)) + IF( NE_32( st->output_Fs, 8000 ) ) { - if (st->hPFstat != NULL) + if ( st->hPFstat != NULL ) { st->hPFstat->reset = 1; - if (st->hPFstat->on != 0) + if ( st->hPFstat->on != 0 ) { st->hPFstat->reset = 0; - Scale_sig(st->hPFstat->mem_pf_in, L_SUBFR, negate(st->Q_syn)); /* WB post_filter mem */ - Scale_sig(st->hPFstat->mem_stp, L_SUBFR, negate(st->Q_syn)); /* WB post_filter mem */ - lerp(st->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old); - lerp(st->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old); + Scale_sig( st->hPFstat->mem_pf_in, L_SUBFR, negate( st->Q_syn ) ); /* WB post_filter mem */ + Scale_sig( st->hPFstat->mem_stp, L_SUBFR, negate( st->Q_syn ) ); /* WB post_filter mem */ + lerp( st->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); + lerp( st->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); } } } ELSE { - if (st->hPFstat != NULL) + if ( st->hPFstat != NULL ) { - Scale_sig(st->hPFstat->mem_pf_in, L_SUBFR, negate(st->Q_syn)); /* NB post_filter mem */ - Scale_sig(st->hPFstat->mem_res2, DECMEM_RES2, negate(st->Q_syn)); /* NB post_filter mem */ - Scale_sig(st->hPFstat->mem_stp, L_SUBFR, negate(st->Q_syn)); /* NB post_filter mem */ + Scale_sig( st->hPFstat->mem_pf_in, L_SUBFR, negate( st->Q_syn ) ); /* NB post_filter mem */ + Scale_sig( st->hPFstat->mem_res2, DECMEM_RES2, negate( st->Q_syn ) ); /* NB post_filter mem */ + Scale_sig( st->hPFstat->mem_stp, L_SUBFR, negate( st->Q_syn ) ); /* NB post_filter mem */ } /*feed last value old_synth as it is used for pre-emphasis mem*/ - if (st->hTcxDec != NULL) + if ( st->hTcxDec != NULL ) { hTcxDec->old_synth[hTcxDec->old_synth_len - 1] = st->syn[M]; } move16(); - if (st->hBPF != NULL) + if ( st->hBPF != NULL ) { hBPF->pst_old_syn_fx[NBPSF_PIT_MAX - 1] = st->syn[M]; } @@ -672,55 +677,56 @@ void open_decoder_LPD_fx( } /* lsf and lsp initialization */ - IF ( st->ini_frame == 0 ) + IF( st->ini_frame == 0 ) { - Copy(st->lsp_old_fx, st->lspold_uw, M); - Copy(st->lsf_old_fx, st->lsfold_uw, M); + Copy( st->lsp_old_fx, st->lspold_uw, M ); + Copy( st->lsf_old_fx, st->lsfold_uw, M ); - set16_fx(st->lsf_cng, 0, M); + set16_fx( st->lsf_cng, 0, M ); } st->seed_tcx_plc = RANDOM_INITSEED; move16(); st->past_gpit = 0; move16(); - st->past_gcode = L_deposit_l(0); - st->gc_threshold_fx = L_deposit_l(0); + st->past_gcode = L_deposit_l( 0 ); + st->gc_threshold_fx = L_deposit_l( 0 ); - E_LPC_lsf_lsp_conversion(st->lsf_cng, st->lspold_cng, M); - E_LPC_f_lsp_a_conversion(st->lspold_cng, st->Aq_cng, M); + E_LPC_lsf_lsp_conversion( st->lsf_cng, st->lspold_cng, M ); + E_LPC_f_lsp_a_conversion( st->lspold_cng, st->Aq_cng, M ); st->plcBackgroundNoiseUpdated = 0; move16(); - Copy(st->lsf_old_fx, st->lsf_q_cng, M); - Copy(st->lsf_old_fx, st->old_lsf_q_cng, M); - Copy(st->lsp_old_fx, st->lsp_q_cng, M); - Copy(st->lsp_old_fx, st->old_lsp_q_cng, M); - set16_fx(st->mem_syn_unv_back, 0, M); + Copy( st->lsf_old_fx, st->lsf_q_cng, M ); + Copy( st->lsf_old_fx, st->old_lsf_q_cng, M ); + Copy( st->lsp_old_fx, st->lsp_q_cng, M ); + Copy( st->lsp_old_fx, st->old_lsp_q_cng, M ); + set16_fx( st->mem_syn_unv_back, 0, M ); - st->last_gain_syn_deemph = 32768/2; + st->last_gain_syn_deemph = 32768 / 2; move16(); st->last_gain_syn_deemph_e = 1; move16(); test(); - IF( EQ_16(st->last_codec_mode,MODE1)||st->ini_frame==0) + IF( EQ_16( st->last_codec_mode, MODE1 ) || st->ini_frame == 0 ) { /* this assumes that MODE1 fades out in the frequency domain - otherwise some data from MODE1 would be needed here */ - st->last_concealed_gain_syn_deemph = 32768/2; + st->last_concealed_gain_syn_deemph = 32768 / 2; move16(); st->last_concealed_gain_syn_deemph_e = 1; move16(); - if (hTcxDec != NULL) + if ( hTcxDec != NULL ) { - hTcxDec->conceal_eof_gain = 32768 / 2;/*Q14*/ move16(); + hTcxDec->conceal_eof_gain = 32768 / 2; /*Q14*/ + move16(); } } /* Post processing */ - set16_fx(st->mem_Aq,0,NB_SUBFR16k*(M+1)); + set16_fx( st->mem_Aq, 0, NB_SUBFR16k * ( M + 1 ) ); st->lp_ener_FER_fx = 15360; - move16(); /*60 in Q8*/ - IF (st->ini_frame == 0) + move16(); /*60 in Q8*/ + IF( st->ini_frame == 0 ) { st->prev_bfi = 0; move16(); @@ -732,24 +738,24 @@ void open_decoder_LPD_fx( /*st->noise_filling_index = 0;*/ /* not in BASOP */ - Copy(st->lsf_old_fx, st->lsf_adaptive_mean_fx, M); - Copy(st->lsf_old_fx, st->lsfoldbfi0_fx, M); - Copy(st->lsf_old_fx, st->lsfoldbfi1_fx, M); + Copy( st->lsf_old_fx, st->lsf_adaptive_mean_fx, M ); + Copy( st->lsf_old_fx, st->lsfoldbfi0_fx, M ); + Copy( st->lsf_old_fx, st->lsfoldbfi1_fx, M ); - st->clas_dec = UNVOICED_CLAS; + st->clas_dec = UNVOICED_CLAS; move16(); move16(); - IF (!st->last_con_tcx) + IF( !st->last_con_tcx ) { move16(); - st->old_enr_LP = 0; /* LP filter E of last good voiced frame or local LP filter E in TD TCX PLC */ + st->old_enr_LP = 0; /* LP filter E of last good voiced frame or local LP filter E in TD TCX PLC */ } - IF (st->prev_bfi) + IF( st->prev_bfi ) { /* calculate energy at the end of the previous frame */ test(); - IF( EQ_16(st->core,ACELP_CORE)&&EQ_16(st->last_core,HQ_CORE)) + IF( EQ_16( st->core, ACELP_CORE ) && EQ_16( st->last_core, HQ_CORE ) ) { /*_DIFF_FLOAT_FIX_*/ #if 0 @@ -760,61 +766,65 @@ void open_decoder_LPD_fx( } ELSE { - st->last_good = UNVOICED_CLAS; /* last good received frame for concealment */ move16(); - st->enr_old_fx = L_deposit_l(0); /* energy at the end of the previous frame */ + st->last_good = UNVOICED_CLAS; /* last good received frame for concealment */ + move16(); + st->enr_old_fx = L_deposit_l( 0 ); /* energy at the end of the previous frame */ } - st->Mode2_lp_gainc = L_deposit_l(0); - st->Mode2_lp_gainp = L_deposit_l(0); + st->Mode2_lp_gainc = L_deposit_l( 0 ); + st->Mode2_lp_gainp = L_deposit_l( 0 ); st->prev_widow_left_rect = 0; move16(); - if (st->hTcxDec != NULL) + if ( st->hTcxDec != NULL ) { #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT /* Todo: should be considered for other stereo modes as well */ - if (is_init || MCT_flag || !(st->element_mode == IVAS_CPE_MDCT && st->element_mode == last_element_mode)) - { PMT("Fixed point to be done") + if ( is_init || MCT_flag || !( st->element_mode == IVAS_CPE_MDCT && st->element_mode == last_element_mode ) ) + { + PMT( "Fixed point to be done" ) st->hTcxDec->CngLevelBackgroundTrace_bfi = PLC_MIN_CNG_LEV; st->hTcxDec->NoiseLevelIndex_bfi = PLC_MIN_STAT_BUFF_SIZE - 1; st->hTcxDec->CurrLevelIndex_bfi = 0; st->hTcxDec->LastFrameLevel_bfi = PLC_MIN_CNG_LEV; - set_f(st->hTcxDec->NoiseLevelMemory_bfi, PLC_MIN_CNG_LEV, PLC_MIN_STAT_BUFF_SIZE); + set_f( st->hTcxDec->NoiseLevelMemory_bfi, PLC_MIN_CNG_LEV, PLC_MIN_STAT_BUFF_SIZE ); st->hTcxDec->cummulative_damping_tcx = 1.0f; } #else - hTcxDec->conCngLevelBackgroundTrace = PLC_MIN_CNG_LEV_Q21; /*Q21*/ move16(); + hTcxDec->conCngLevelBackgroundTrace = PLC_MIN_CNG_LEV_Q21; /*Q21*/ + move16(); hTcxDec->conNoiseLevelIndex = PLC_MIN_STAT_BUFF_SIZE - 1; move16(); hTcxDec->conCurrLevelIndex = 0; move16(); - hTcxDec->conLastFrameLevel = PLC_MIN_CNG_LEV; /*Q15*/ move16(); - set16_fx(hTcxDec->conNoiseLevelMemory, PLC_MIN_CNG_LEV, PLC_MIN_STAT_BUFF_SIZE); /*Q15*/ - set16_fx(hTcxDec->conNoiseLevelMemory_e, 0, PLC_MIN_STAT_BUFF_SIZE); + hTcxDec->conLastFrameLevel = PLC_MIN_CNG_LEV; /*Q15*/ + move16(); + set16_fx( hTcxDec->conNoiseLevelMemory, PLC_MIN_CNG_LEV, PLC_MIN_STAT_BUFF_SIZE ); /*Q15*/ + set16_fx( hTcxDec->conNoiseLevelMemory_e, 0, PLC_MIN_STAT_BUFF_SIZE ); hTcxDec->conLastFrameLevel_e = 0; hTcxDec->conCngLevelBackgroundTrace_e = -6; - hTcxDec->cummulative_damping_tcx = 32767/*1.0f Q15*/; + hTcxDec->cummulative_damping_tcx = 32767 /*1.0f Q15*/; #endif } move16(); - st->cummulative_damping = 32767/*1.0f Q15*/; + st->cummulative_damping = 32767 /*1.0f Q15*/; move16(); - FOR ( i=0; i<2*NB_SUBFR16k+2; i++ ) + FOR( i = 0; i < 2 * NB_SUBFR16k + 2; i++ ) { - st->old_pitch_buf_fx[i] = L_deposit_h(st->pit_min); + st->old_pitch_buf_fx[i] = L_deposit_h( st->pit_min ); } - FOR ( i=0; i<2*NB_SUBFR16k+2; i++ ) + FOR( i = 0; i < 2 * NB_SUBFR16k + 2; i++ ) { - st->mem_pitch_gain[i] = 16384/*1.f Q14*/;/*Q14*/ + st->mem_pitch_gain[i] = 16384 /*1.f Q14*/; /*Q14*/ } - st->old_fpitch = L_deposit_h(st->pit_min); + st->old_fpitch = L_deposit_h( st->pit_min ); #ifndef NEW_IVAS_OPEN_DEC - st->old_fpitchFB = L_deposit_h(hTcxDec->pit_min_TCX); + st->old_fpitchFB = L_deposit_h( hTcxDec->pit_min_TCX ); #endif st->rate_switching_init = 1; move16(); @@ -823,22 +833,23 @@ void open_decoder_LPD_fx( move16(); /* For phase dispersion */ - st->dm_fx.prev_gain_code = L_deposit_l(0); - set16_fx(st->dm_fx.prev_gain_pit, 0, 6); + st->dm_fx.prev_gain_code = L_deposit_l( 0 ); + set16_fx( st->dm_fx.prev_gain_pit, 0, 6 ); st->dm_fx.prev_state = 0; move16(); - st->voice_fac = -1; /* purely unvoiced */ move16(); + st->voice_fac = -1; /* purely unvoiced */ + move16(); /* TCX-LTP */ - if (hTcxLtpDec != NULL) + if ( hTcxLtpDec != NULL ) { - hTcxLtpDec->tcxltp = getTcxLtp(st->sr_core); + hTcxLtpDec->tcxltp = getTcxLtp( st->sr_core ); } move16(); test(); - IF (hTcxLtpDec != NULL && (st->ini_frame == 0 || (EQ_16(st->last_codec_mode,MODE1) && EQ_16(st->element_mode, EVS_MONO)))) + IF( hTcxLtpDec != NULL && ( st->ini_frame == 0 || ( EQ_16( st->last_codec_mode, MODE1 ) && EQ_16( st->element_mode, EVS_MONO ) ) ) ) { #if 0 PMT("TO be verify, update seems to differ from float") @@ -847,15 +858,15 @@ void open_decoder_LPD_fx( move16(); hTcxLtpDec->tcxltp_pitch_fr = 0; move16(); - if (hTcxDec != NULL) + if ( hTcxDec != NULL ) { hTcxDec->tcxltp_last_gain_unmodified = 0; } move16(); - IF ( st->ini_frame == 0) + IF( st->ini_frame == 0 ) { - set16_fx(hTcxLtpDec->tcxltp_mem_in, 0, TCXLTP_MAX_DELAY ); - set16_fx(hTcxLtpDec->tcxltp_mem_out, 0, L_FRAME48k ); + set16_fx( hTcxLtpDec->tcxltp_mem_in, 0, TCXLTP_MAX_DELAY ); + set16_fx( hTcxLtpDec->tcxltp_mem_out, 0, L_FRAME48k ); hTcxLtpDec->tcxltp_pitch_int_post_prev = 0; move16(); hTcxLtpDec->tcxltp_pitch_fr_post_prev = 0; @@ -868,34 +879,35 @@ void open_decoder_LPD_fx( } /* in floating point implementation, different buffers are used: lp_error_ener <-> pst_lp_ener, mem_error <-> pst_mem_deemp_err */ - if (st->hBPF != NULL) + if ( st->hBPF != NULL ) { - st->lp_error_ener = Mpy_32_16_1(L_shl(hBPF->pst_lp_ener_fx, 8), 0x2a86); /* convert from 7Q8 10*log10 -> 15Q16, log2 */ + st->lp_error_ener = Mpy_32_16_1( L_shl( hBPF->pst_lp_ener_fx, 8 ), 0x2a86 ); /* convert from 7Q8 10*log10 -> 15Q16, log2 */ } else { st->lp_error_ener = 0; } - st->mem_error = L_deposit_l(0); - st->hTcxCfg->ctx_hm = getCtxHm (st->element_mode, total_brate, st->rf_flag); + st->mem_error = L_deposit_l( 0 ); + st->hTcxCfg->ctx_hm = getCtxHm( st->element_mode, total_brate, st->rf_flag ); st->last_ctx_hm_enabled = 0; move16(); - st->hTcxCfg->resq = getResq(total_brate); + st->hTcxCfg->resq = getResq( total_brate ); move16(); - st->hTcxCfg->sq_rounding = 12288/*0.375f Q15*/; /*deadzone of 1.25->rounding=1-1.25/2 (No deadzone=0.5)*/ move16(); - if (hTcxDec != NULL) + st->hTcxCfg->sq_rounding = 12288 /*0.375f Q15*/; /*deadzone of 1.25->rounding=1-1.25/2 (No deadzone=0.5)*/ + move16(); + if ( hTcxDec != NULL ) { - hTcxDec->tcx_lpc_shaped_ari = getTcxLpcShapedAri(total_brate, st->rf_flag, st->element_mode); + hTcxDec->tcx_lpc_shaped_ari = getTcxLpcShapedAri( total_brate, st->rf_flag, st->element_mode ); hTcxDec->envWeighted = 0; } move16(); st->p_bpf_noise_buf = NULL; - if (st->tcxonly == 0) + if ( st->tcxonly == 0 ) { st->p_bpf_noise_buf = st->bpf_noise_buf; } @@ -904,8 +916,8 @@ void open_decoder_LPD_fx( move16(); test(); test(); - if ( EQ_16(bwidth, SWB)&& - (EQ_32(st->total_brate, ACELP_16k40) || EQ_32(st->total_brate, ACELP_24k40)) && EQ_16(st->element_mode, EVS_MONO)) + if ( EQ_16( bwidth, SWB ) && + ( EQ_32( st->total_brate, ACELP_16k40 ) || EQ_32( st->total_brate, ACELP_24k40 ) ) && EQ_16( st->element_mode, EVS_MONO ) ) { st->tec_tfa = 1; move16(); @@ -931,16 +943,16 @@ void open_decoder_LPD_fx( st->enablePlcWaveadjust = 0; move16(); - IF(st->hTcxDec != NULL && GE_32(st->total_brate, 48000) && EQ_16(st->element_mode, EVS_MONO)) + IF( st->hTcxDec != NULL && GE_32( st->total_brate, 48000 ) && EQ_16( st->element_mode, EVS_MONO ) ) { st->enablePlcWaveadjust = 1; move16(); test(); test(); test(); - IF (st->ini_frame == 0 || LT_32(st->last_total_brate, HQ_48k)||EQ_16(st->last_codec_mode,MODE1)||st->force_lpd_reset) + IF( st->ini_frame == 0 || LT_32( st->last_total_brate, HQ_48k ) || EQ_16( st->last_codec_mode, MODE1 ) || st->force_lpd_reset ) { - concealment_init_x(hTcxDec->L_frameTCX, &st->plcInfo ); + concealment_init_x( hTcxDec->L_frameTCX, &st->plcInfo ); } } @@ -948,8 +960,8 @@ void open_decoder_LPD_fx( #if 0 PMT("handle to tonalMDCTconceal is missing") #endif -//#ifdef ADD_IVAS_HTONALMDCTCONC - if (/*st->ADD_IVAS_HTONALMDCTCONC != NULL &&*/ !(GT_16(st->element_mode, EVS_MONO) && NE_16(st->ini_frame,0) && EQ_16(st->tonalMDCTconceal.nSamples, st->hTcxDec->L_frameTCX))) + //#ifdef ADD_IVAS_HTONALMDCTCONC + if ( /*st->ADD_IVAS_HTONALMDCTCONC != NULL &&*/ !( GT_16( st->element_mode, EVS_MONO ) && NE_16( st->ini_frame, 0 ) && EQ_16( st->tonalMDCTconceal.nSamples, st->hTcxDec->L_frameTCX ) ) ) { st->tonalMDCTconceal.nScaleFactors = 0; move16(); @@ -968,12 +980,12 @@ void open_decoder_LPD_fx( st->second_last_tns_active = 0; st->second_last_core = -1; #ifdef NEW_IVAS_OPEN_DEC - if (st->hTcxCfg != NULL && NE_16(st->element_mode, EVS_MONO ) ) + if ( st->hTcxCfg != NULL && NE_16( st->element_mode, EVS_MONO ) ) { - st->hTcxCfg->fIsTNSAllowed = getTnsAllowed(is_init ? total_brate : st->bits_frame_nominal * FRAMES_PER_SEC, st->igf); + st->hTcxCfg->fIsTNSAllowed = getTnsAllowed( is_init ? total_brate : st->bits_frame_nominal * FRAMES_PER_SEC, st->igf ); } #endif - if (hTcxDec != NULL) + if ( hTcxDec != NULL ) { hTcxDec->tcxltp_second_last_pitch = st->old_fpitch; move16(); @@ -985,17 +997,18 @@ void open_decoder_LPD_fx( test(); test(); test(); - if ((total_brate == ACELP_9k60 || total_brate == ACELP_16k40 || total_brate == ACELP_24k40) && st->element_mode == EVS_MONO) + if ( ( total_brate == ACELP_9k60 || total_brate == ACELP_16k40 || total_brate == ACELP_24k40 ) && st->element_mode == EVS_MONO ) - if( ((EQ_32(st->total_brate, 9600))||(EQ_32(st->total_brate,16400))|| - (EQ_32(st->total_brate, 24400))) && st->element_mode == EVS_MONO) - { - move16(); - st->dec_glr = 1; - } + if ( ( ( EQ_32( st->total_brate, 9600 ) ) || ( EQ_32( st->total_brate, 16400 ) ) || + ( EQ_32( st->total_brate, 24400 ) ) ) && + st->element_mode == EVS_MONO ) + { + move16(); + st->dec_glr = 1; + } move16(); st->dec_glr_idx = 0; - if (hTcxDec != NULL) + if ( hTcxDec != NULL ) { hTcxDec->enableTcxLpc = 1; st->VAD = 0; @@ -1004,9 +1017,9 @@ void open_decoder_LPD_fx( hTcxDec->tcx_hm_LtpPitchLag = -1; } #ifndef NEW_IVAS_OPEN_DEC - st->hTcxCfg->na_scale = 32767/*1.0f Q15*/; + st->hTcxCfg->na_scale = 32767 /*1.0f Q15*/; #endif - if (hTcxLtpDec != NULL) + if ( hTcxLtpDec != NULL ) { hTcxLtpDec->tcxltp_gain = 0; } @@ -1035,8 +1048,8 @@ void tcxltp_dec_init_fx( { set16_fx( hTcxLtpDec->tcxltp_mem_in, 0, TCXLTP_MAX_DELAY ); set16_fx( hTcxLtpDec->tcxltp_mem_out, 0, L_FRAME48k ); - set32_fx(hTcxLtpDec->tcxltp_mem_in_32, 0, TCXLTP_MAX_DELAY); - set32_fx(hTcxLtpDec->tcxltp_mem_out_32, 0, L_FRAME48k); + set32_fx( hTcxLtpDec->tcxltp_mem_in_32, 0, TCXLTP_MAX_DELAY ); + set32_fx( hTcxLtpDec->tcxltp_mem_out_32, 0, L_FRAME48k ); hTcxLtpDec->tcxltp_pitch_int_post_prev = 0; hTcxLtpDec->tcxltp_pitch_fr_post_prev = 0; hTcxLtpDec->tcxltp_gain_post_prev = 0; @@ -1481,7 +1494,7 @@ void open_decoder_LPD_ivas_fx( *Q_old_Aq_12_8 = 14; IF( !st->last_con_tcx ) { - ivas_synth_mem_updt2_fx( st->L_frame, st->last_L_frame, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, DEC ,st->Q_syn); + ivas_synth_mem_updt2_fx( st->L_frame, st->last_L_frame, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, DEC, st->Q_syn ); } /*mem of deemphasis stayed unchanged.*/ @@ -1707,18 +1720,20 @@ void open_decoder_LPD_ivas_fx( st->hTcxDec->cummulative_damping_tcx = 32767 /*1.0f Q15*/; - hTcxDec->conCngLevelBackgroundTrace = PLC_MIN_CNG_LEV_Q21; /*Q21*/ move16(); + hTcxDec->conCngLevelBackgroundTrace = PLC_MIN_CNG_LEV_Q21; /*Q21*/ + move16(); hTcxDec->conNoiseLevelIndex = PLC_MIN_STAT_BUFF_SIZE - 1; move16(); hTcxDec->conCurrLevelIndex = 0; move16(); - hTcxDec->conLastFrameLevel = PLC_MIN_CNG_LEV; /*Q15*/ move16(); - set16_fx(hTcxDec->conNoiseLevelMemory, PLC_MIN_CNG_LEV, PLC_MIN_STAT_BUFF_SIZE); /*Q15*/ - set16_fx(hTcxDec->conNoiseLevelMemory_e, 0, PLC_MIN_STAT_BUFF_SIZE); + hTcxDec->conLastFrameLevel = PLC_MIN_CNG_LEV; /*Q15*/ + move16(); + set16_fx( hTcxDec->conNoiseLevelMemory, PLC_MIN_CNG_LEV, PLC_MIN_STAT_BUFF_SIZE ); /*Q15*/ + set16_fx( hTcxDec->conNoiseLevelMemory_e, 0, PLC_MIN_STAT_BUFF_SIZE ); hTcxDec->conLastFrameLevel_e = 0; hTcxDec->conCngLevelBackgroundTrace_e = -6; - hTcxDec->cummulative_damping_tcx = 32767/*1.0f Q15*/; + hTcxDec->cummulative_damping_tcx = 32767 /*1.0f Q15*/; } } st->cummulative_damping = 32767 /*1.0f Q15*/; @@ -1837,7 +1852,7 @@ void open_decoder_LPD_ivas_fx( IF( st->hTcxCfg != NULL && NE_16( st->element_mode, EVS_MONO ) ) { - st->hTcxCfg->fIsTNSAllowed = getTnsAllowed( is_init ? total_brate : L_mult(st->bits_frame_nominal , (FRAMES_PER_SEC>>1)), st->igf, st->element_mode ); + st->hTcxCfg->fIsTNSAllowed = getTnsAllowed( is_init ? total_brate : L_mult( st->bits_frame_nominal, ( FRAMES_PER_SEC >> 1 ) ), st->igf, st->element_mode ); } IF( hTcxDec != NULL ) { @@ -1876,4 +1891,4 @@ void open_decoder_LPD_ivas_fx( return; } #endif // IVAS_FLOAT_FIXED -#endif \ No newline at end of file +#endif diff --git a/lib_dec/core_dec_reconf.c b/lib_dec/core_dec_reconf.c index 4448e1310..13aa708dc 100644 --- a/lib_dec/core_dec_reconf.c +++ b/lib_dec/core_dec_reconf.c @@ -167,12 +167,12 @@ void reconfig_decoder_LPD_ivas( oldLen = L_SYN_MEM_CLAS_ESTIM; newLen = L_SYN_MEM_CLAS_ESTIM * st->L_frame / st->last_L_frame; } - lerp_flt(&st->mem_syn_clas_estim[L_SYN_MEM_CLAS_ESTIM - oldLen], &st->mem_syn_clas_estim[L_SYN_MEM_CLAS_ESTIM - newLen], newLen, oldLen); + lerp_flt( &st->mem_syn_clas_estim[L_SYN_MEM_CLAS_ESTIM - oldLen], &st->mem_syn_clas_estim[L_SYN_MEM_CLAS_ESTIM - newLen], newLen, oldLen ); } } else { - set_zero(st->mem_syn_clas_estim, L_SYN_MEM_CLAS_ESTIM); + set_zero( st->mem_syn_clas_estim, L_SYN_MEM_CLAS_ESTIM ); } } } diff --git a/lib_dec/core_dec_reconf_fx.c b/lib_dec/core_dec_reconf_fx.c index a99c92ddb..bb2f4c404 100644 --- a/lib_dec/core_dec_reconf_fx.c +++ b/lib_dec/core_dec_reconf_fx.c @@ -92,7 +92,7 @@ void reconfig_decoder_LPD_ivas_fx( } } /*if its not the first frame resample overlap buffer to new sampling rate */ - IF( NE_16(st->ini_frame , 0 )) + IF( NE_16( st->ini_frame, 0 ) ) { test(); test(); @@ -101,7 +101,7 @@ void reconfig_decoder_LPD_ivas_fx( ( NE_16( st->fscale, st->fscale_old ) && !( EQ_16( st->element_mode, EVS_MONO ) && EQ_16( st->last_codec_mode, MODE1 ) && - EQ_16( st->last_core, ACELP_CORE ) && NE_16(st->prev_bfi , 0 ) ) )) + EQ_16( st->last_core, ACELP_CORE ) && NE_16( st->prev_bfi, 0 ) ) ) ) /* no resempling is needed here when recovering from mode 1 ACELP PLC, since the buffers are already sampled with the correct sampling rate in open_decoder_LPD_fx() */ @@ -168,7 +168,7 @@ void reconfig_decoder_LPD_ivas_fx( } hTcxDec->enableTcxLpc = EQ_16( st->numlpc, 1 ) && EQ_16( st->lpcQuantization, 1 ) && ( LE_32( total_brate, lowrate_tcxlpc_max_br ) /*LOWRATE_TCXLPC_MAX_BR*/ || st->rf_flag ); - IF( EQ_16(st->ini_frame , 0 )) + IF( EQ_16( st->ini_frame, 0 ) ) { hTcxDec->envWeighted = 0; move16(); @@ -179,12 +179,12 @@ void reconfig_decoder_LPD_ivas_fx( #endif #ifdef IVAS_FLOAT_FIXED -void reconfig_decoder_LPD_fx( - Decoder_State *st, /* i/o: decoder state structure */ - Word16 bits_frame, /* i : bit budget */ - Word16 bwidth, /* i : audio bandwidth */ - Word32 total_brate, /* i : total bitrate */ - Word16 L_frame_old /* i : frame length */ +void reconfig_decoder_LPD_fx( + Decoder_State *st, /* i/o: decoder state structure */ + Word16 bits_frame, /* i : bit budget */ + Word16 bwidth, /* i : audio bandwidth */ + Word32 total_brate, /* i : total bitrate */ + Word16 L_frame_old /* i : frame length */ ) { Word16 newLen; @@ -198,20 +198,20 @@ void reconfig_decoder_LPD_fx( hTcxDec = st->hTcxDec; move16(); - st->bits_frame=bits_frame; + st->bits_frame = bits_frame; - IF (EQ_16(bwidth, NB)) + IF( EQ_16( bwidth, NB ) ) { move16(); st->narrowBand = 1; } - ELSE if (GT_16(bwidth,NB)) + ELSE if ( GT_16( bwidth, NB ) ) { move16(); st->narrowBand = 0; } - BITS_ALLOC_init_config_acelp(st->total_brate, st->narrowBand, st->nb_subfr, &(st->acelp_cfg)); + BITS_ALLOC_init_config_acelp( st->total_brate, st->narrowBand, st->nb_subfr, &( st->acelp_cfg ) ); /*Configuration of partial copy*/ st->acelp_cfg_rf.mode_index = 1; @@ -225,44 +225,43 @@ void reconfig_decoder_LPD_fx( st->acelp_cfg_rf.formant_enh_den = FORMANT_SHARPENING_G2; - IF (NE_16(st->element_mode, IVAS_SCE)) + IF( NE_16( st->element_mode, IVAS_SCE ) ) { - st->flag_cna = (Word8)getCnaPresent_fx(st->element_mode, st->element_brate, total_brate, bwidth); + st->flag_cna = (Word8) getCnaPresent_fx( st->element_mode, st->element_brate, total_brate, bwidth ); } move16(); /* TCX-LTP */ - IF (hTcxLtpDec != NULL) + IF( hTcxLtpDec != NULL ) { - hTcxLtpDec->tcxltp = getTcxLtp(st->sr_core); + hTcxLtpDec->tcxltp = getTcxLtp( st->sr_core ); } move16(); - if (st->hTcxCfg != NULL) + if ( st->hTcxCfg != NULL ) { Word16 i; /*Scale TCX for non-active frames to adjust loudness with ACELP*/ - st->hTcxCfg->na_scale=32767/*1.0f Q15*/; + st->hTcxCfg->na_scale = 32767 /*1.0f Q15*/; test(); - IF ((LT_16(bwidth,SWB))&&!(st->tcxonly)) + IF( ( LT_16( bwidth, SWB ) ) && !( st->tcxonly ) ) { - Word16 scaleTableSize = sizeof (scaleTcxTable) / sizeof (scaleTcxTable[0]); /* is a constant */ + Word16 scaleTableSize = sizeof( scaleTcxTable ) / sizeof( scaleTcxTable[0] ); /* is a constant */ - FOR (i = 0 ; i < scaleTableSize ; i++) + FOR( i = 0; i < scaleTableSize; i++ ) { test(); test(); - IF ( (EQ_16(bwidth,scaleTcxTable[i].bwmode)) && - (GE_32 (total_brate,scaleTcxTable[i].bitrateFrom) ) && - (LT_32 (total_brate,scaleTcxTable[i].bitrateTo) ) - ) + IF( ( EQ_16( bwidth, scaleTcxTable[i].bwmode ) ) && + ( GE_32( total_brate, scaleTcxTable[i].bitrateFrom ) ) && + ( LT_32( total_brate, scaleTcxTable[i].bitrateTo ) ) ) { - if( st->rf_flag ) + if ( st->rf_flag ) { i--; } - st->hTcxCfg->na_scale=scaleTcxTable[i].scale; + st->hTcxCfg->na_scale = scaleTcxTable[i].scale; move16(); BREAK; } @@ -271,15 +270,15 @@ void reconfig_decoder_LPD_fx( } /*if its not the first frame resample overlap buffer to new sampling rate */ - IF ( st->ini_frame != 0 ) + IF( st->ini_frame != 0 ) { test(); test(); test(); - IF(st->hTcxCfg != NULL && - (NE_16 (st->fscale,st->fscale_old) && - !(EQ_16(st->element_mode, EVS_MONO) && EQ_16(st->last_codec_mode, MODE1) && - EQ_16(st->last_core, ACELP_CORE) && st->prev_bfi != 0))) + IF( st->hTcxCfg != NULL && + ( NE_16( st->fscale, st->fscale_old ) && + !( EQ_16( st->element_mode, EVS_MONO ) && EQ_16( st->last_codec_mode, MODE1 ) && + EQ_16( st->last_core, ACELP_CORE ) && st->prev_bfi != 0 ) ) ) /* no resempling is needed here when recovering from mode 1 acelp plc, since the buffers are already sampled with the correct sampling rate in open_decoder_LPD_fx() */ @@ -291,49 +290,48 @@ void reconfig_decoder_LPD_fx( move16(); test(); test(); - IF( (st->prev_bfi && EQ_16(st->last_core_bfi,ACELP_CORE))||EQ_16(st->last_core,ACELP_CORE)) + IF( ( st->prev_bfi && EQ_16( st->last_core_bfi, ACELP_CORE ) ) || EQ_16( st->last_core, ACELP_CORE ) ) { - newLen = shr(st->L_frame,1); - oldLen = shr(L_frame_old,1); + newLen = shr( st->L_frame, 1 ); + oldLen = shr( L_frame_old, 1 ); } - IF (st->hTcxDec != NULL) + IF( st->hTcxDec != NULL ) { - lerp(hTcxDec->old_syn_Overl, hTcxDec->old_syn_Overl, newLen, oldLen); - lerp(hTcxDec->syn_Overl, hTcxDec->syn_Overl, newLen, oldLen); + lerp( hTcxDec->old_syn_Overl, hTcxDec->old_syn_Overl, newLen, oldLen ); + lerp( hTcxDec->syn_Overl, hTcxDec->syn_Overl, newLen, oldLen ); test(); - IF(st->prev_bfi && EQ_16(st->last_core_bfi, ACELP_CORE)) + IF( st->prev_bfi && EQ_16( st->last_core_bfi, ACELP_CORE ) ) { - lerp(hTcxDec->syn_Overl_TDAC, hTcxDec->syn_Overl_TDAC, newLen, oldLen); + lerp( hTcxDec->syn_Overl_TDAC, hTcxDec->syn_Overl_TDAC, newLen, oldLen ); } } } - IF (LE_16(st->L_frame,L_FRAME16k)) + IF( LE_16( st->L_frame, L_FRAME16k ) ) { - IF (LE_16(st->last_L_frame,L_FRAME16k)) + IF( LE_16( st->last_L_frame, L_FRAME16k ) ) { - IF (NE_16(st->L_frame,st->last_L_frame)) + IF( NE_16( st->L_frame, st->last_L_frame ) ) { - IF (GT_16(st->L_frame,st->last_L_frame)) + IF( GT_16( st->L_frame, st->last_L_frame ) ) { - oldLen = extract_l(L_shr(Mpy_32_16_1(L_mult0(st->last_L_frame,getInvFrameLen(st->L_frame)/*Q21*/)/*Q21*/,L_SYN_MEM_CLAS_ESTIM/*Q0*/)/*Q6*/,6)/*Q0*/); + oldLen = extract_l( L_shr( Mpy_32_16_1( L_mult0( st->last_L_frame, getInvFrameLen( st->L_frame ) /*Q21*/ ) /*Q21*/, L_SYN_MEM_CLAS_ESTIM /*Q0*/ ) /*Q6*/, 6 ) /*Q0*/ ); newLen = L_SYN_MEM_CLAS_ESTIM; move16(); - } ELSE { oldLen = L_SYN_MEM_CLAS_ESTIM; - newLen = extract_l(L_shr(Mpy_32_16_1(L_mult0(st->L_frame,getInvFrameLen(st->last_L_frame)/*Q21*/)/*Q21*/,L_SYN_MEM_CLAS_ESTIM/*Q0*/)/*Q6*/,6)/*Q0*/); + newLen = extract_l( L_shr( Mpy_32_16_1( L_mult0( st->L_frame, getInvFrameLen( st->last_L_frame ) /*Q21*/ ) /*Q21*/, L_SYN_MEM_CLAS_ESTIM /*Q0*/ ) /*Q6*/, 6 ) /*Q0*/ ); } - lerp( &st->mem_syn_clas_estim_fx[sub(L_SYN_MEM_CLAS_ESTIM, oldLen)], &st->mem_syn_clas_estim_fx[sub(L_SYN_MEM_CLAS_ESTIM, newLen)], newLen, oldLen); + lerp( &st->mem_syn_clas_estim_fx[sub( L_SYN_MEM_CLAS_ESTIM, oldLen )], &st->mem_syn_clas_estim_fx[sub( L_SYN_MEM_CLAS_ESTIM, newLen )], newLen, oldLen ); } } ELSE { - set16_fx(st->mem_syn_clas_estim_fx, 0, L_SYN_MEM_CLAS_ESTIM); + set16_fx( st->mem_syn_clas_estim_fx, 0, L_SYN_MEM_CLAS_ESTIM ); st->classifier_Q_mem_syn = 0; move16(); } @@ -344,12 +342,12 @@ void reconfig_decoder_LPD_fx( lowrate_tcxlpc_max_br = LOWRATE_TCXLPC_MAX_BR; move16(); - IF (GT_16(st->element_mode, IVAS_SCE)) + IF( GT_16( st->element_mode, IVAS_SCE ) ) { lowrate_tcxlpc_max_br = LOWRATE_TCXLPC_MAX_BR_CPE; } - hTcxDec->enableTcxLpc = EQ_16(st->numlpc, 1) && EQ_16(st->lpcQuantization, 1) && (LE_32(total_brate, lowrate_tcxlpc_max_br)/*LOWRATE_TCXLPC_MAX_BR*/ || st->rf_flag); - if (st->ini_frame == 0) + hTcxDec->enableTcxLpc = EQ_16( st->numlpc, 1 ) && EQ_16( st->lpcQuantization, 1 ) && ( LE_32( total_brate, lowrate_tcxlpc_max_br ) /*LOWRATE_TCXLPC_MAX_BR*/ || st->rf_flag ); + if ( st->ini_frame == 0 ) { hTcxDec->envWeighted = 0; move16(); @@ -358,4 +356,4 @@ void reconfig_decoder_LPD_fx( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/core_dec_switch.c b/lib_dec/core_dec_switch.c index 7e81b04cc..2c1adef8d 100644 --- a/lib_dec/core_dec_switch.c +++ b/lib_dec/core_dec_switch.c @@ -58,171 +58,169 @@ void mode_switch_decoder_LPD( const int16_t last_element_mode /* i : last element mode */ ) { -int16_t fscale, switchWB; -int32_t sr_core; -int16_t bSwitchFromAmrwbIO; -int16_t frame_size; -TCX_DEC_HANDLE hTcxDec = st->hTcxDec; - -switchWB = 0; -bSwitchFromAmrwbIO = 0; -if (st->last_core == AMR_WB_CORE) -{ - bSwitchFromAmrwbIO = 1; -} -sr_core = getCoreSamplerateMode2_flt(st->element_mode, total_brate, bwidth, st->flag_ACELP16k, st->rf_flag, st->is_ism_format); - -fscale = sr2fscale(sr_core); - -/* set number of coded lines */ -st->hTcxCfg->tcx_coded_lines = getNumTcxCodedLines(bwidth); - -if ((bwidth >= WB) && (fscale == (FSCALE_DENOM * 16000) / 12800) && (fscale == st->fscale)) -{ - if (((total_brate > ACELP_32k) && (st->tcxonly == 0)) || ((total_brate <= ACELP_32k) && (st->tcxonly == 1))) - { - switchWB = 1; - } -} - -if (st->last_L_frame > L_FRAME16k && total_brate <= ACELP_32k) -{ - switchWB = 1; /*force init when coming from MODE1*/ -} - -st->igf = getIgfPresent(st->element_mode, total_brate, bwidth, st->rf_flag); - -if (st->hIGFDec != NULL) -{ - st->hIGFDec->infoIGFStopFreq = -1; -} - -if (st->igf && (st->idchan == 0 || st->element_mode == IVAS_CPE_MDCT)) -{ - /* switch IGF configuration */ - IGFDecSetMode_flt(st->hIGFDec, total_brate, bwidth, st->element_mode, -1, -1, st->rf_flag); - -} - -if (fscale != st->fscale || switchWB || bSwitchFromAmrwbIO || st->last_codec_mode == MODE1 || st->force_lpd_reset) -{ - open_decoder_LPD(st, total_brate, last_total_brate, bwidth, MCT_flag, last_element_mode, 0); -} -else -{ - assert(fscale > (FSCALE_DENOM / 2)); - st->fscale_old = st->fscale; - st->fscale = fscale; - st->L_frame = (int16_t)(st->sr_core / FRAMES_PER_SEC); - if (st->hTcxDec != NULL) - { - st->hTcxDec->L_frameTCX = (int16_t)(st->output_Fs / FRAMES_PER_SEC); - } - - if (st->hTcxCfg != NULL) - { - st->hTcxCfg->ctx_hm = getCtxHm(st->element_mode, total_brate, st->rf_flag); - st->hTcxCfg->resq = getResq(total_brate); - } - - hTcxDec->tcx_lpc_shaped_ari = getTcxLpcShapedAri(total_brate, st->rf_flag, st->element_mode); - - if (bwidth == NB) - { - st->narrowBand = 1; - } - else - { - st->narrowBand = 0; - } - st->TcxBandwidth_float = getTcxBandwidth_flt(bwidth); - - if (st->hTcxCfg != NULL) - { - st->hTcxCfg->pCurrentTnsConfig = NULL; - st->hTcxCfg->fIsTNSAllowed = getTnsAllowed(total_brate, st->igf, st->element_mode); - } - - if (st->hTcxCfg->fIsTNSAllowed && st->hIGFDec != NULL && st->hTcxCfg != NULL) - { - InitTnsConfigs_flt(bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFDec->infoIGFStopFreq, total_brate, st->element_mode, MCT_flag); - - SetAllowTnsOnWhite_flt(st->hTcxCfg->tnsConfig, st->element_mode == IVAS_CPE_MDCT); - - } -} - -frame_size = FrameSizeConfig[frame_size_index].frame_net_bits; -reconfig_decoder_LPD_ivas(st, frame_size, bwidth, total_brate, st->last_L_frame); - -if (hTcxDec->envWeighted && !hTcxDec->enableTcxLpc) -{ - mvr2r(st->lspold_uw_float, st->lsp_old, M); - mvr2r(st->lsfold_uw_float, st->lsf_old, M); - hTcxDec->envWeighted = 0; -} - -/* update PLC LSF memories */ -lsp2lsf(st->lsp_old, st->lsfoldbfi1, M, st->sr_core); -mvr2r(st->lsfoldbfi1, st->lsfoldbfi0, M); -mvr2r(st->lsfoldbfi1, st->lsf_adaptive_mean, M); - -if (st->igf && st->hBWE_TD != NULL) -{ - /* reset TBE */ - if ((st->bwidth == WB && st->last_extl != WB_TBE) || - (st->bwidth == SWB && st->last_extl != SWB_TBE) || - (st->bwidth == FB && st->last_extl != FB_TBE)) - { - TBEreset_dec(st); - } - else - { - set_f(st->hBWE_TD->state_lpc_syn, 0.0f, LPC_SHB_ORDER); - set_f(st->hBWE_TD->state_syn_shbexc, 0.0f, L_SHB_LAHEAD); - set_f(st->hBWE_TD->mem_stp_swb, 0.0f, LPC_SHB_ORDER); - set_f(st->hBWE_TD->mem_zero_swb, 0, LPC_SHB_ORDER); - st->hBWE_TD->gain_prec_swb = 1.0f; - } -} - -if (bwidth == SWB && (total_brate == ACELP_16k40 || total_brate == ACELP_24k40) && st->element_mode == EVS_MONO) -{ - if (st->tec_tfa == 0 && st->hTECDec != NULL) - { - set_zero(st->hTECDec->loBuffer_flt, MAX_TEC_SMOOTHING_DEG); - } - st->tec_tfa = 1; -} -else -{ - st->tec_tfa = 0; -} - -st->tec_flag = 0; -st->tfa_flag = 0; - -/* needed in decoder to read the bitstream */ -if (bwidth >= WB && total_brate == ACELP_24k40 && st->element_mode == EVS_MONO) -{ - st->enableGplc = 1; -} -else -{ - st->enableGplc = 0; -} - -if ((total_brate == ACELP_9k60 || total_brate == ACELP_16k40 || total_brate == ACELP_24k40) && st->element_mode == EVS_MONO) -{ - st->dec_glr = 1; -} -else -{ - st->dec_glr = 0; -} - -st->dec_glr_idx = 0; - -return; + int16_t fscale, switchWB; + int32_t sr_core; + int16_t bSwitchFromAmrwbIO; + int16_t frame_size; + TCX_DEC_HANDLE hTcxDec = st->hTcxDec; + + switchWB = 0; + bSwitchFromAmrwbIO = 0; + if ( st->last_core == AMR_WB_CORE ) + { + bSwitchFromAmrwbIO = 1; + } + sr_core = getCoreSamplerateMode2_flt( st->element_mode, total_brate, bwidth, st->flag_ACELP16k, st->rf_flag, st->is_ism_format ); + + fscale = sr2fscale( sr_core ); + + /* set number of coded lines */ + st->hTcxCfg->tcx_coded_lines = getNumTcxCodedLines( bwidth ); + + if ( ( bwidth >= WB ) && ( fscale == ( FSCALE_DENOM * 16000 ) / 12800 ) && ( fscale == st->fscale ) ) + { + if ( ( ( total_brate > ACELP_32k ) && ( st->tcxonly == 0 ) ) || ( ( total_brate <= ACELP_32k ) && ( st->tcxonly == 1 ) ) ) + { + switchWB = 1; + } + } + + if ( st->last_L_frame > L_FRAME16k && total_brate <= ACELP_32k ) + { + switchWB = 1; /*force init when coming from MODE1*/ + } + + st->igf = getIgfPresent( st->element_mode, total_brate, bwidth, st->rf_flag ); + + if ( st->hIGFDec != NULL ) + { + st->hIGFDec->infoIGFStopFreq = -1; + } + + if ( st->igf && ( st->idchan == 0 || st->element_mode == IVAS_CPE_MDCT ) ) + { + /* switch IGF configuration */ + IGFDecSetMode_flt( st->hIGFDec, total_brate, bwidth, st->element_mode, -1, -1, st->rf_flag ); + } + + if ( fscale != st->fscale || switchWB || bSwitchFromAmrwbIO || st->last_codec_mode == MODE1 || st->force_lpd_reset ) + { + open_decoder_LPD( st, total_brate, last_total_brate, bwidth, MCT_flag, last_element_mode, 0 ); + } + else + { + assert( fscale > ( FSCALE_DENOM / 2 ) ); + st->fscale_old = st->fscale; + st->fscale = fscale; + st->L_frame = (int16_t) ( st->sr_core / FRAMES_PER_SEC ); + if ( st->hTcxDec != NULL ) + { + st->hTcxDec->L_frameTCX = (int16_t) ( st->output_Fs / FRAMES_PER_SEC ); + } + + if ( st->hTcxCfg != NULL ) + { + st->hTcxCfg->ctx_hm = getCtxHm( st->element_mode, total_brate, st->rf_flag ); + st->hTcxCfg->resq = getResq( total_brate ); + } + + hTcxDec->tcx_lpc_shaped_ari = getTcxLpcShapedAri( total_brate, st->rf_flag, st->element_mode ); + + if ( bwidth == NB ) + { + st->narrowBand = 1; + } + else + { + st->narrowBand = 0; + } + st->TcxBandwidth_float = getTcxBandwidth_flt( bwidth ); + + if ( st->hTcxCfg != NULL ) + { + st->hTcxCfg->pCurrentTnsConfig = NULL; + st->hTcxCfg->fIsTNSAllowed = getTnsAllowed( total_brate, st->igf, st->element_mode ); + } + + if ( st->hTcxCfg->fIsTNSAllowed && st->hIGFDec != NULL && st->hTcxCfg != NULL ) + { + InitTnsConfigs_flt( bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFDec->infoIGFStopFreq, total_brate, st->element_mode, MCT_flag ); + + SetAllowTnsOnWhite_flt( st->hTcxCfg->tnsConfig, st->element_mode == IVAS_CPE_MDCT ); + } + } + + frame_size = FrameSizeConfig[frame_size_index].frame_net_bits; + reconfig_decoder_LPD_ivas( st, frame_size, bwidth, total_brate, st->last_L_frame ); + + if ( hTcxDec->envWeighted && !hTcxDec->enableTcxLpc ) + { + mvr2r( st->lspold_uw_float, st->lsp_old, M ); + mvr2r( st->lsfold_uw_float, st->lsf_old, M ); + hTcxDec->envWeighted = 0; + } + + /* update PLC LSF memories */ + lsp2lsf( st->lsp_old, st->lsfoldbfi1, M, st->sr_core ); + mvr2r( st->lsfoldbfi1, st->lsfoldbfi0, M ); + mvr2r( st->lsfoldbfi1, st->lsf_adaptive_mean, M ); + + if ( st->igf && st->hBWE_TD != NULL ) + { + /* reset TBE */ + if ( ( st->bwidth == WB && st->last_extl != WB_TBE ) || + ( st->bwidth == SWB && st->last_extl != SWB_TBE ) || + ( st->bwidth == FB && st->last_extl != FB_TBE ) ) + { + TBEreset_dec( st ); + } + else + { + set_f( st->hBWE_TD->state_lpc_syn, 0.0f, LPC_SHB_ORDER ); + set_f( st->hBWE_TD->state_syn_shbexc, 0.0f, L_SHB_LAHEAD ); + set_f( st->hBWE_TD->mem_stp_swb, 0.0f, LPC_SHB_ORDER ); + set_f( st->hBWE_TD->mem_zero_swb, 0, LPC_SHB_ORDER ); + st->hBWE_TD->gain_prec_swb = 1.0f; + } + } + + if ( bwidth == SWB && ( total_brate == ACELP_16k40 || total_brate == ACELP_24k40 ) && st->element_mode == EVS_MONO ) + { + if ( st->tec_tfa == 0 && st->hTECDec != NULL ) + { + set_zero( st->hTECDec->loBuffer_flt, MAX_TEC_SMOOTHING_DEG ); + } + st->tec_tfa = 1; + } + else + { + st->tec_tfa = 0; + } + + st->tec_flag = 0; + st->tfa_flag = 0; + + /* needed in decoder to read the bitstream */ + if ( bwidth >= WB && total_brate == ACELP_24k40 && st->element_mode == EVS_MONO ) + { + st->enableGplc = 1; + } + else + { + st->enableGplc = 0; + } + + if ( ( total_brate == ACELP_9k60 || total_brate == ACELP_16k40 || total_brate == ACELP_24k40 ) && st->element_mode == EVS_MONO ) + { + st->dec_glr = 1; + } + else + { + st->dec_glr = 0; + } + + st->dec_glr_idx = 0; + + return; } #endif diff --git a/lib_dec/core_dec_switch_fx.c b/lib_dec/core_dec_switch_fx.c index 1d487992c..5241b42e0 100644 --- a/lib_dec/core_dec_switch_fx.c +++ b/lib_dec/core_dec_switch_fx.c @@ -10,22 +10,24 @@ #include "prot_fx2.h" #include "rom_com.h" - //Temporarily added +// Temporarily added #include "prot.h" -void mode_switch_decoder_LPD_fx( - Decoder_State *st, /* i/o: decoder state structure */ - Word16 bwidth, /* i : audio bandwidth */ - Word32 total_brate, /* i : total bitrate */ +void mode_switch_decoder_LPD_fx( + Decoder_State *st, /* i/o: decoder state structure */ + Word16 bwidth, /* i : audio bandwidth */ + Word32 total_brate, /* i : total bitrate */ #ifdef IVAS_CODE_SWITCHING const int32_t last_total_brate, /* i : last frame total bitrate */ #endif - Word16 frame_size_index /* i : index determining the frame size*/ + Word16 frame_size_index /* i : index determining the frame size*/ #ifdef IVAS_CODE_SWITCHING - ,const int16_t MCT_flag /* i : hMCT handle allocated (1) or not (0)*/ + , + const int16_t MCT_flag /* i : hMCT handle allocated (1) or not (0)*/ #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - ,const int16_t last_element_mode + , + const int16_t last_element_mode #endif #endif ) @@ -45,27 +47,27 @@ void mode_switch_decoder_LPD_fx( bSwitchFromAmrwbIO = 0; move16(); - if (EQ_16(st->last_core,AMR_WB_CORE)) + if ( EQ_16( st->last_core, AMR_WB_CORE ) ) { bSwitchFromAmrwbIO = 1; move16(); } - sr_core = getCoreSamplerateMode2(st->element_mode, total_brate, bwidth, st->flag_ACELP16k, st->rf_flag, st->is_ism_format ); + sr_core = getCoreSamplerateMode2( st->element_mode, total_brate, bwidth, st->flag_ACELP16k, st->rf_flag, st->is_ism_format ); - fscale = sr2fscale_fx(sr_core); + fscale = sr2fscale_fx( sr_core ); move16(); /* set number of coded lines */ - st->hTcxCfg->tcx_coded_lines = getNumTcxCodedLines(bwidth); + st->hTcxCfg->tcx_coded_lines = getNumTcxCodedLines( bwidth ); test(); - test(); - IF (( (GE_16(bwidth, WB)) && (EQ_16(fscale,(FSCALE_DENOM*16000)/12800)) && (EQ_16(fscale,st->fscale)))) + test(); + IF( ( ( GE_16( bwidth, WB ) ) && ( EQ_16( fscale, ( FSCALE_DENOM * 16000 ) / 12800 ) ) && ( EQ_16( fscale, st->fscale ) ) ) ) { test(); test(); test(); - if ( ((GT_32(total_brate, 32000)) && (st->tcxonly==0)) || ((LE_32(total_brate,32000)) && (st->tcxonly!=0))) + if ( ( ( GT_32( total_brate, 32000 ) ) && ( st->tcxonly == 0 ) ) || ( ( LE_32( total_brate, 32000 ) ) && ( st->tcxonly != 0 ) ) ) { switchWB = 1; move16(); @@ -73,85 +75,85 @@ void mode_switch_decoder_LPD_fx( } test(); - if( GT_16(st->last_L_frame,L_FRAME16k) && LE_32(total_brate ,ACELP_32k)) + if ( GT_16( st->last_L_frame, L_FRAME16k ) && LE_32( total_brate, ACELP_32k ) ) { switchWB = 1; move16(); } - st->igf = getIgfPresent_fx(st->element_mode, total_brate, bwidth, st->rf_flag); + st->igf = getIgfPresent_fx( st->element_mode, total_brate, bwidth, st->rf_flag ); - IF(st->hIGFDec != NULL) + IF( st->hIGFDec != NULL ) { st->hIGFDec->infoIGFStopFreq = -1; } move16(); - test(); test(); - IF( st->igf && (st->idchan == 0 || EQ_16(st->element_mode, IVAS_CPE_MDCT) ) ) + test(); + test(); + IF( st->igf && ( st->idchan == 0 || EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) ) { /* switch IGF configuration */ - IGFDecSetMode( st->hIGFDec, total_brate, bwidth, st->element_mode, -1, -1, st->rf_flag); + IGFDecSetMode( st->hIGFDec, total_brate, bwidth, st->element_mode, -1, -1, st->rf_flag ); } test(); test(); test(); test(); - IF ( NE_16(fscale, st->fscale)||switchWB!=0||bSwitchFromAmrwbIO!=0||EQ_16(st->last_codec_mode,MODE1)||st->force_lpd_reset) + IF( NE_16( fscale, st->fscale ) || switchWB != 0 || bSwitchFromAmrwbIO != 0 || EQ_16( st->last_codec_mode, MODE1 ) || st->force_lpd_reset ) { #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - open_decoder_LPD_fx(st, total_brate, last_total_brate, bwidth, MCT_flag, last_element_mode, 0); + open_decoder_LPD_fx( st, total_brate, last_total_brate, bwidth, MCT_flag, last_element_mode, 0 ); #else #ifdef IVAS_CODE - open_decoder_LPD_fx(st, total_brate, last_total_brate, bwidth, is_mct, 0); + open_decoder_LPD_fx( st, total_brate, last_total_brate, bwidth, is_mct, 0 ); #else - open_decoder_LPD_fx(st, total_brate, bwidth); + open_decoder_LPD_fx( st, total_brate, bwidth ); #endif #endif - } ELSE { - assert(fscale > (FSCALE_DENOM/2)); + assert( fscale > ( FSCALE_DENOM / 2 ) ); - st->fscale_old = st->fscale; + st->fscale_old = st->fscale; move16(); - st->fscale = fscale; + st->fscale = fscale; move16(); - st->L_frame = extract_l(Mult_32_16(st->sr_core , 0x0290)); - IF(hTcxDec != NULL) + st->L_frame = extract_l( Mult_32_16( st->sr_core, 0x0290 ) ); + IF( hTcxDec != NULL ) { - hTcxDec->L_frameTCX = extract_l(Mult_32_16(st->output_Fs, 0x0290)); + hTcxDec->L_frameTCX = extract_l( Mult_32_16( st->output_Fs, 0x0290 ) ); } - IF (st->hTcxCfg != NULL) + IF( st->hTcxCfg != NULL ) { - st->hTcxCfg->ctx_hm = getCtxHm(st->element_mode, total_brate, st->rf_flag); - st->hTcxCfg->resq = getResq(total_brate); + st->hTcxCfg->ctx_hm = getCtxHm( st->element_mode, total_brate, st->rf_flag ); + st->hTcxCfg->resq = getResq( total_brate ); } move16(); - hTcxDec->tcx_lpc_shaped_ari = getTcxLpcShapedAri(total_brate, st->rf_flag, st->element_mode ); + hTcxDec->tcx_lpc_shaped_ari = getTcxLpcShapedAri( total_brate, st->rf_flag, st->element_mode ); st->narrowBand = 0; move16(); - if ( EQ_16(bwidth, NB)) + if ( EQ_16( bwidth, NB ) ) { st->narrowBand = 1; move16(); } - st->TcxBandwidth = getTcxBandwidth(bwidth); + st->TcxBandwidth = getTcxBandwidth( bwidth ); - IF (st->hTcxCfg != NULL) + IF( st->hTcxCfg != NULL ) { st->hTcxCfg->pCurrentTnsConfig = NULL; - st->hTcxCfg->fIsTNSAllowed = getTnsAllowed(total_brate, st->igf, st->element_mode); + st->hTcxCfg->fIsTNSAllowed = getTnsAllowed( total_brate, st->igf, st->element_mode ); move16(); - IF(st->hTcxCfg->fIsTNSAllowed != 0 && st->hIGFDec != NULL) + IF( st->hTcxCfg->fIsTNSAllowed != 0 && st->hIGFDec != NULL ) { - InitTnsConfigs(bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFDec->infoIGFStopFreq, total_brate, st->element_mode, 0/* 0 should be replaced with MCT_flag*/); + InitTnsConfigs( bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFDec->infoIGFStopFreq, total_brate, st->element_mode, 0 /* 0 should be replaced with MCT_flag*/ ); #ifdef IVAS_CODE - SetAllowTnsOnWhite(st->hTcxCfg->tnsConfig, st->element_mode == IVAS_CPE_MDCT); + SetAllowTnsOnWhite( st->hTcxCfg->tnsConfig, st->element_mode == IVAS_CPE_MDCT ); #endif } } @@ -163,10 +165,10 @@ void mode_switch_decoder_LPD_fx( reconfig_decoder_LPD_fx( st, frame_size, bwidth, total_brate, st->last_L_frame ); test(); - IF (hTcxDec->envWeighted != 0 && hTcxDec->enableTcxLpc == 0) + IF( hTcxDec->envWeighted != 0 && hTcxDec->enableTcxLpc == 0 ) { - Copy(st->lspold_uw, st->lsp_old_fx, M); - Copy(st->lsfold_uw, st->lsf_old_fx, M); + Copy( st->lspold_uw, st->lsp_old_fx, M ); + Copy( st->lsfold_uw, st->lsf_old_fx, M ); hTcxDec->envWeighted = 0; move16(); } @@ -174,34 +176,38 @@ void mode_switch_decoder_LPD_fx( /* update PLC LSF memories */ IF( st->tcxonly == 0 ) { - lsp2lsf_fx( st->lsp_old_fx, st->lsfoldbfi1_fx, M, extract_l(st->sr_core) ); + lsp2lsf_fx( st->lsp_old_fx, st->lsfoldbfi1_fx, M, extract_l( st->sr_core ) ); } ELSE { E_LPC_lsp_lsf_conversion( st->lsp_old_fx, st->lsfoldbfi1_fx, M ); } - Copy(st->lsfoldbfi1_fx, st->lsfoldbfi0_fx,M); - Copy(st->lsfoldbfi1_fx, st->lsf_adaptive_mean_fx,M); + Copy( st->lsfoldbfi1_fx, st->lsfoldbfi0_fx, M ); + Copy( st->lsfoldbfi1_fx, st->lsf_adaptive_mean_fx, M ); - IF( st->igf != 0 && hBWE_TD != NULL) + IF( st->igf != 0 && hBWE_TD != NULL ) { - test();test();test();test();test(); - IF( (EQ_16(st->bwidth, WB)&&NE_16(st->last_extl,WB_TBE))|| - (EQ_16(st->bwidth, SWB) && NE_16(st->last_extl, SWB_TBE)) || - (EQ_16(st->bwidth, FB) && NE_16(st->last_extl,FB_TBE)) ) + test(); + test(); + test(); + test(); + test(); + IF( ( EQ_16( st->bwidth, WB ) && NE_16( st->last_extl, WB_TBE ) ) || + ( EQ_16( st->bwidth, SWB ) && NE_16( st->last_extl, SWB_TBE ) ) || + ( EQ_16( st->bwidth, FB ) && NE_16( st->last_extl, FB_TBE ) ) ) { #ifdef IVAS_CODE - TBEreset_dec_fx(st); + TBEreset_dec_fx( st ); #else - TBEreset_dec_fx(st, st->bwidth); + TBEreset_dec_fx( st, st->bwidth ); #endif } ELSE { - set16_fx(hBWE_TD->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); - set16_fx(hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD ); - set16_fx(hBWE_TD->mem_stp_swb_fx, 0, LPC_SHB_ORDER ); - set16_fx(hBWE_TD->mem_zero_swb_fx, 0, LPC_SHB_ORDER ); + set16_fx( hBWE_TD->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); + set16_fx( hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD ); + set16_fx( hBWE_TD->mem_stp_swb_fx, 0, LPC_SHB_ORDER ); + set16_fx( hBWE_TD->mem_zero_swb_fx, 0, LPC_SHB_ORDER ); hBWE_TD->gain_prec_swb_fx = 16384; move16(); /*Q14 = 1 */ } @@ -209,11 +215,11 @@ void mode_switch_decoder_LPD_fx( test(); test(); - IF( (EQ_16(bwidth, SWB))&& (EQ_32(total_brate, ACELP_16k40) || EQ_32(total_brate, ACELP_24k40)) && EQ_16(st->element_mode, EVS_MONO) ) + IF( ( EQ_16( bwidth, SWB ) ) && ( EQ_32( total_brate, ACELP_16k40 ) || EQ_32( total_brate, ACELP_24k40 ) ) && EQ_16( st->element_mode, EVS_MONO ) ) { - IF (st->tec_tfa == 0) + IF( st->tec_tfa == 0 ) { - set16_fx(st->hTECDec->loBuffer , 0, MAX_TEC_SMOOTHING_DEG); + set16_fx( st->hTECDec->loBuffer, 0, MAX_TEC_SMOOTHING_DEG ); } st->tec_tfa = 1; move16(); @@ -234,7 +240,7 @@ void mode_switch_decoder_LPD_fx( move16(); test(); test(); - IF ( GE_16(bwidth, WB) && EQ_32(total_brate, 24400) && EQ_16(st->element_mode, EVS_MONO) ) + IF( GE_16( bwidth, WB ) && EQ_32( total_brate, 24400 ) && EQ_16( st->element_mode, EVS_MONO ) ) { st->enableGplc = 1; move16(); @@ -244,24 +250,23 @@ void mode_switch_decoder_LPD_fx( test(); test(); test(); - IF (( EQ_32(total_brate, 9600) || EQ_32(total_brate,16400) || EQ_32(total_brate, 24400)) && EQ_16(st->element_mode, EVS_MONO) ) + IF( ( EQ_32( total_brate, 9600 ) || EQ_32( total_brate, 16400 ) || EQ_32( total_brate, 24400 ) ) && EQ_16( st->element_mode, EVS_MONO ) ) { st->dec_glr = 1; move16(); } move16(); st->dec_glr_idx = 0; - } #ifdef IVAS_FLOAT_FIXED void mode_switch_decoder_LPD_ivas_fx( - Decoder_State *st, /* i/o: decoder state structure */ - const Word16 bwidth, /* i : audio bandwidth */ - const Word32 total_brate, /* i : total bitrate */ - const Word32 last_total_brate, /* i : last frame total bitrate */ - const Word16 frame_size_index, /* i : index determining the frame size */ - const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0)*/ + Decoder_State *st, /* i/o: decoder state structure */ + const Word16 bwidth, /* i : audio bandwidth */ + const Word32 total_brate, /* i : total bitrate */ + const Word32 last_total_brate, /* i : last frame total bitrate */ + const Word16 frame_size_index, /* i : index determining the frame size */ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0)*/ const Word16 last_element_mode, /* i : last element mode */ Word16 *Q_syn_Overl_TDAC, Word16 *Q_fer_samples, @@ -270,8 +275,7 @@ void mode_switch_decoder_LPD_ivas_fx( Word16 *Q_syn_OverlFB, Word16 *Q_old_out, Word16 *Q_old_outLB, - Word16 *Q_old_Aq_12_8 -) + Word16 *Q_old_Aq_12_8 ) { Word16 fscale, switchWB; Word32 sr_core; @@ -391,7 +395,7 @@ void mode_switch_decoder_LPD_ivas_fx( { InitTnsConfigs( bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFDec->infoIGFStopFreq, total_brate, st->element_mode, MCT_flag ); - SetAllowTnsOnWhite( st->hTcxCfg->tnsConfig, (Word8)EQ_16(st->element_mode , IVAS_CPE_MDCT) ); + SetAllowTnsOnWhite( st->hTcxCfg->tnsConfig, (Word8) EQ_16( st->element_mode, IVAS_CPE_MDCT ) ); } } diff --git a/lib_dec/core_switching_dec.c b/lib_dec/core_switching_dec.c index ec718f6c9..653ef2523 100644 --- a/lib_dec/core_switching_dec.c +++ b/lib_dec/core_switching_dec.c @@ -70,7 +70,7 @@ ivas_error core_switching_pre_dec_ivas_fx( const Word32 last_core_brate_st0, /* i : channel 0 last core bitrate */ const Word16 nchan_out, /* i : number of output channels */ const Word16 last_element_mode, /* i : last_element_mode */ - const Word32 last_element_brate, /* i : last element bitrate */ + const Word32 last_element_brate, /* i : last element bitrate */ Word16 Q_old_synthFB, Word16 *Q_olapBufferSynth, Word16 *Q_olapBufferSynth2 ) @@ -204,7 +204,7 @@ ivas_error core_switching_pre_dec_ivas_fx( move16(); Copy32( st->hTcxDec->FBTCXdelayBuf_32, st->prev_synth_buffer32_fx, NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) ); - //Copy_Scale_sig_32_16( st->hTcxDec->FBTCXdelayBuf_32, st->prev_synth_buffer_fx, NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), -11 ); //Q11 -> Q0 + // Copy_Scale_sig_32_16( st->hTcxDec->FBTCXdelayBuf_32, st->prev_synth_buffer_fx, NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), -11 ); //Q11 -> Q0 } IF( st->hHQ_core != NULL ) @@ -304,13 +304,13 @@ ivas_error core_switching_pre_dec_ivas_fx( { IF( GT_16( st->L_frame, st->last_L_frame ) ) { - oldLenClasBuff = mult_r(L_SYN_MEM_CLAS_ESTIM , div_s(st->last_L_frame , st->L_frame)); + oldLenClasBuff = mult_r( L_SYN_MEM_CLAS_ESTIM, div_s( st->last_L_frame, st->L_frame ) ); newLenClasBuff = L_SYN_MEM_CLAS_ESTIM; } ELSE { oldLenClasBuff = L_SYN_MEM_CLAS_ESTIM; - newLenClasBuff = mult_r(L_SYN_MEM_CLAS_ESTIM , div_s(st->L_frame , st->last_L_frame)); + newLenClasBuff = mult_r( L_SYN_MEM_CLAS_ESTIM, div_s( st->L_frame, st->last_L_frame ) ); } move16(); move16(); @@ -391,7 +391,7 @@ ivas_error core_switching_pre_dec_ivas_fx( /* Reset ACELP parameters */ set16_fx( st->mem_MA_fx, 0, M ); - IF( EQ_32(st->sr_core , INT_FS_16k) ) + IF( EQ_32( st->sr_core, INT_FS_16k ) ) { Copy( GEWB2_Ave_fx, st->mem_AR_fx, M ); } @@ -434,7 +434,7 @@ ivas_error core_switching_pre_dec_ivas_fx( { set16_fx( st->old_exc_fx, 0, L_EXC_MEM_DEC ); } - ELSE IF( LT_16(st->L_frame , L_FRAME16k) ) + ELSE IF( LT_16( st->L_frame, L_FRAME16k ) ) { /* resample from 16kHz to 12.8kHZ */ synth_mem_updt2( st->L_frame, L_FRAME16k, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, DEC ); @@ -491,7 +491,7 @@ ivas_error core_switching_pre_dec_ivas_fx( move16(); move16(); - IF( GT_32(st->output_Fs , 16000) && st->hBWE_zero != NULL ) + IF( GT_32( st->output_Fs, 16000 ) && st->hBWE_zero != NULL ) { hf_synth_reset_fx( st->hBWE_zero ); #ifdef MSAN_FIX @@ -504,11 +504,11 @@ ivas_error core_switching_pre_dec_ivas_fx( set16_fx( st->hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); } - IF( EQ_16(nchan_out , 1) && EQ_16(st->element_mode , IVAS_CPE_DFT) && LE_32(st->element_brate , IVAS_24k4) && GT_32(last_element_brate , IVAS_24k4) ) + IF( EQ_16( nchan_out, 1 ) && EQ_16( st->element_mode, IVAS_CPE_DFT ) && LE_32( st->element_brate, IVAS_24k4 ) && GT_32( last_element_brate, IVAS_24k4 ) ) { /* update cldbf state with previous frame TCX synthesis when going from a bitrate with residual coding to a bitrate without it */ Word16 offset; - offset = sub(st->cldfbAna->p_filter_length , st->cldfbAna->no_channels); + offset = sub( st->cldfbAna->p_filter_length, st->cldfbAna->no_channels ); Word32 *old_synthFB_fx; IF( ( old_synthFB_fx = (Word32 *) malloc( st->hTcxDec->old_synth_lenFB * sizeof( Word32 ) ) ) == NULL ) { @@ -522,7 +522,7 @@ ivas_error core_switching_pre_dec_ivas_fx( } } - IF( EQ_16(st->core , HQ_CORE) && ( EQ_16(st->last_core , ACELP_CORE) || EQ_16(st->last_core , AMR_WB_CORE) || ( ( NE_16(st->element_mode , EVS_MONO) ) && ( NE_16(st->last_core , HQ_CORE) ) ) ) ) + IF( EQ_16( st->core, HQ_CORE ) && ( EQ_16( st->last_core, ACELP_CORE ) || EQ_16( st->last_core, AMR_WB_CORE ) || ( ( NE_16( st->element_mode, EVS_MONO ) ) && ( NE_16( st->last_core, HQ_CORE ) ) ) ) ) { set32_fx( st->hHQ_core->prev_env_fx, 0, SFM_N_WB ); set32_fx( st->hHQ_core->prev_normq_fx, 0, SFM_N_WB ); @@ -537,28 +537,28 @@ ivas_error core_switching_pre_dec_ivas_fx( st->hHQ_core->prev_stab_hfe2 = 0; move16(); move16(); - IF( GT_32(st->output_Fs , 16000) ) + IF( GT_32( st->output_Fs, 16000 ) ) { set32_fx( st->hHQ_core->prev_coeff_out_fx, 0, L_HQ_WB_BWE ); } - IF( NE_16(st->element_mode , EVS_MONO) ) + IF( NE_16( st->element_mode, EVS_MONO ) ) { /* Estimate mem_env_delta to reinit env_stab */ tmp_fx = L_max( 0, ENV_STAB_EST1_FX + Mult_32_16( st->stab_fac_smooth_lt_fx, ENV_STAB_EST2_FX ) + Mult_32_16( st->log_energy_diff_lt_fx, ENV_STAB_EST3_FX ) ); /*Q12*/ st->hHQ_core->mem_env_delta = extract_l( L_min( MAX16B, tmp_fx ) ); /* Convert to Q12 and handle saturation */ - IF( NE_16(st->last_core , TCX_20_CORE) && NE_16(st->last_core , TCX_10_CORE) ) + IF( NE_16( st->last_core, TCX_20_CORE ) && NE_16( st->last_core, TCX_10_CORE ) ) { set16_fx( st->hHQ_core->old_out_fx, 0, output_frame ); set32_fx( st->hHQ_core->old_outLB_fx, 0, L_FRAME16k ); - set16_fx(st->hHQ_core->old_out_LB_fx, 0, L_FRAME16k); + set16_fx( st->hHQ_core->old_out_LB_fx, 0, L_FRAME16k ); } st->hHQ_core->no_att_hangover = 0; move16(); - st->hHQ_core->energy_lt_fx = 2457600;/*300.0f Q13*/ + st->hHQ_core->energy_lt_fx = 2457600; /*300.0f Q13*/ move32(); set16_fx( st->hHQ_core->old_is_transient, 0, 3 ); set16_fx( st->hHQ_core->prev_noise_level_fx, 0, 2 ); @@ -582,18 +582,18 @@ ivas_error core_switching_pre_dec_ivas_fx( IF( st->hHQ_core != NULL ) { st->hHQ_core->pastpre--; - IF( LE_16(st->hHQ_core->pastpre , 0) ) + IF( LE_16( st->hHQ_core->pastpre, 0 ) ) { reset_preecho_dec_fx( st->hHQ_core ); } } - IF( EQ_32(st->core_brate , FRAME_NO_DATA) ) + IF( EQ_32( st->core_brate, FRAME_NO_DATA ) ) { st->VAD = 0; st->m_frame_type = ZERO_FRAME; } - ELSE IF( EQ_32(st->core_brate , SID_2k40) || EQ_32(st->core_brate , SID_1k75) ) + ELSE IF( EQ_32( st->core_brate, SID_2k40 ) || EQ_32( st->core_brate, SID_1k75 ) ) { st->VAD = 0; st->m_frame_type = SID_FRAME; @@ -607,31 +607,31 @@ ivas_error core_switching_pre_dec_ivas_fx( move16(); move16(); /*switch on CNA on active frames*/ - IF( EQ_16(st->element_mode , EVS_MONO) ) /* for IVAS modes, st->flag_cna is set earlier */ + IF( EQ_16( st->element_mode, EVS_MONO ) ) /* for IVAS modes, st->flag_cna is set earlier */ { - IF( st->VAD && ( ( NE_16(st->core , AMR_WB_CORE) && LE_32(st->total_brate , CNA_MAX_BRATE) ) || ( EQ_16(st->core , AMR_WB_CORE) && LE_32(st->total_brate , ACELP_8k85) ) ) ) + IF( st->VAD && ( ( NE_16( st->core, AMR_WB_CORE ) && LE_32( st->total_brate, CNA_MAX_BRATE ) ) || ( EQ_16( st->core, AMR_WB_CORE ) && LE_32( st->total_brate, ACELP_8k85 ) ) ) ) { st->flag_cna = 1; move16(); } - ELSE IF( st->VAD || ( EQ_16( st->cng_type , FD_CNG ) && EQ_16( st->L_frame , L_FRAME16k ) ) ) + ELSE IF( st->VAD || ( EQ_16( st->cng_type, FD_CNG ) && EQ_16( st->L_frame, L_FRAME16k ) ) ) { st->flag_cna = 0; move16(); } } - IF( EQ_16(st->core , AMR_WB_CORE) ) + IF( EQ_16( st->core, AMR_WB_CORE ) ) { st->cng_type = LP_CNG; move16(); } /* Reconfigure CNG */ - IF( st->hFdCngDec && ( NE_16( st->last_L_frame , st->L_frame ) || NE_16( st->hFdCngDec->hFdCngCom->frameSize , st->L_frame ) || EQ_16(st->ini_frame , 0) || NE_16(st->bwidth , st->last_bwidth) ) ) + IF( st->hFdCngDec && ( NE_16( st->last_L_frame, st->L_frame ) || NE_16( st->hFdCngDec->hFdCngCom->frameSize, st->L_frame ) || EQ_16( st->ini_frame, 0 ) || NE_16( st->bwidth, st->last_bwidth ) ) ) { /* || st->last_core == AMR_WB_CORE || st->last_codec_mode == MODE2)){*/ - IF( NE_16(st->core , AMR_WB_CORE) ) + IF( NE_16( st->core, AMR_WB_CORE ) ) { configureFdCngDec_ivas_fx( st->hFdCngDec, st->bwidth, st->rf_flag == 1 && st->total_brate == ACELP_13k20 ? ACELP_9k60 : st->total_brate, st->L_frame, st->last_L_frame, st->element_mode ); } @@ -645,29 +645,29 @@ ivas_error core_switching_pre_dec_ivas_fx( move32(); } } - IF( NE_16(st->last_L_frame , st->L_frame) && LE_16(st->L_frame , L_FRAME16k) && LE_16(st->last_L_frame , L_FRAME16k) ) + IF( NE_16( st->last_L_frame, st->L_frame ) && LE_16( st->L_frame, L_FRAME16k ) && LE_16( st->last_L_frame, L_FRAME16k ) ) { - IF( EQ_16(st->element_mode , IVAS_CPE_DFT) || EQ_16(st->element_mode , IVAS_CPE_TD) ) + IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) { lerp( st->hFdCngDec->hFdCngCom->olapBufferAna_fx + st->last_L_frame, st->hFdCngDec->hFdCngCom->olapBufferAna_fx + st->L_frame, st->L_frame, st->last_L_frame ); } L_lerp_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, st->L_frame * 2, st->last_L_frame * 2, Q_olapBufferSynth2 ); - IF( LE_32(st->total_brate , SID_2k40) && LE_32(st->last_total_brate , SID_2k40) ) + IF( LE_32( st->total_brate, SID_2k40 ) && LE_32( st->last_total_brate, SID_2k40 ) ) { L_lerp_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth_fx, st->L_frame * 2, st->last_L_frame * 2, Q_olapBufferSynth ); - IF( EQ_16(st->L_frame , L_FRAME) ) + IF( EQ_16( st->L_frame, L_FRAME ) ) { - FOR( i = 0; i < shl(st->L_frame,1); i++ ) + FOR( i = 0; i < shl( st->L_frame, 1 ); i++ ) { st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i] = Mult_32_16( st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i], (Word16) 20480 /* 0.6250f in Q15 */ ); } } ELSE { - FOR( i = 0; i < shl(st->L_frame ,1); i++ ) + FOR( i = 0; i < shl( st->L_frame, 1 ); i++ ) { st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i] = Mult_32_16( L_shl( st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i], 1 ), (Word16) 26214 /* 1.6f in Q14 */ ); } @@ -681,488 +681,488 @@ ivas_error core_switching_pre_dec_ivas_fx( #endif // IVAS_FLOAT_FIXED #ifndef IVAS_FLOAT_FIXED ivas_error core_switching_pre_dec( - Decoder_State *st, /* i/o: decoder state structure */ - const int16_t output_frame, /* i : frame length */ - const int32_t last_core_brate_st0, /* i : channel 0 last core bitrate */ - const int16_t nchan_out, /* i : number of output channels */ - const int16_t last_element_mode, /* i : last_element_mode */ - const int32_t last_element_brate /* i : last element bitrate */ + Decoder_State *st, /* i/o: decoder state structure */ + const int16_t output_frame, /* i : frame length */ + const int32_t last_core_brate_st0, /* i : channel 0 last core bitrate */ + const int16_t nchan_out, /* i : number of output channels */ + const int16_t last_element_mode, /* i : last_element_mode */ + const int32_t last_element_brate /* i : last element bitrate */ ) { - int16_t i, oldLenClasBuff, newLenClasBuff; - ivas_error error; - float tmp; + int16_t i, oldLenClasBuff, newLenClasBuff; + ivas_error error; + float tmp; - error = IVAS_ERR_OK; + error = IVAS_ERR_OK; - /* Codec mode switching */ - if (st->last_codec_mode == MODE2 || ((st->last_core == TCX_20_CORE || st->last_core == TCX_10_CORE) && st->element_mode > EVS_MONO)) - { - mvr2r(st->mem_syn2, st->mem_syn1, M); - set_f(st->agc_mem2, 0, 2); - st->mem_deemph = st->syn_float[M]; - st->bpf_off = 1; - if (st->hBPF != NULL) + /* Codec mode switching */ + if ( st->last_codec_mode == MODE2 || ( ( st->last_core == TCX_20_CORE || st->last_core == TCX_10_CORE ) && st->element_mode > EVS_MONO ) ) { - set_f(st->hBPF->pst_old_syn, 0, NBPSF_PIT_MAX); - st->hBPF->pst_mem_deemp_err = 0; - } - st->psf_lp_noise = st->lp_noise_float; + mvr2r( st->mem_syn2, st->mem_syn1, M ); + set_f( st->agc_mem2, 0, 2 ); + st->mem_deemph = st->syn_float[M]; + st->bpf_off = 1; + if ( st->hBPF != NULL ) + { + set_f( st->hBPF->pst_old_syn, 0, NBPSF_PIT_MAX ); + st->hBPF->pst_mem_deemp_err = 0; + } + st->psf_lp_noise = st->lp_noise_float; - /* reset old HB synthesis buffer */ - if (st->last_L_frame == L_FRAME) - { - st->old_bwe_delay = NS2SA(st->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_12k8_NS); - } - else - { - st->old_bwe_delay = NS2SA(st->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_16k_NS); - } - set_f(st->hb_prev_synth_buffer, 0, NS2SA(48000, DELAY_BWE_TOTAL_NS)); + /* reset old HB synthesis buffer */ + if ( st->last_L_frame == L_FRAME ) + { + st->old_bwe_delay = NS2SA( st->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_12k8_NS ); + } + else + { + st->old_bwe_delay = NS2SA( st->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_16k_NS ); + } + set_f( st->hb_prev_synth_buffer, 0, NS2SA( 48000, DELAY_BWE_TOTAL_NS ) ); - if (st->hBWE_TD != NULL && st->last_core != ACELP_CORE) - { - /* reset BWE memories */ - set_f(st->hBWE_TD->old_bwe_exc, 0, PIT16k_MAX * 2); - st->hBWE_TD->bwe_non_lin_prev_scale = 0.0f; - } + if ( st->hBWE_TD != NULL && st->last_core != ACELP_CORE ) + { + /* reset BWE memories */ + set_f( st->hBWE_TD->old_bwe_exc, 0, PIT16k_MAX * 2 ); + st->hBWE_TD->bwe_non_lin_prev_scale = 0.0f; + } - /* reset upd_cnt */ - st->upd_cnt = MAX_UPD_CNT; + /* reset upd_cnt */ + st->upd_cnt = MAX_UPD_CNT; - st->igf = 0; + st->igf = 0; - if (st->output_Fs >= 16000 && st->hBWE_zero != NULL) - { - hf_synth_reset(st->hBWE_zero); - } + if ( st->output_Fs >= 16000 && st->hBWE_zero != NULL ) + { + hf_synth_reset( st->hBWE_zero ); + } - if (st->hBWE_FD != NULL) - { - set_f(st->hBWE_FD->old_syn_12k8_16k, 0, NS2SA(16000, DELAY_FD_BWE_ENC_NS)); - } + if ( st->hBWE_FD != NULL ) + { + set_f( st->hBWE_FD->old_syn_12k8_16k, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); + } - if (st->hHQ_core != NULL) - { - set_f(st->hHQ_core->prev_env, 0, SFM_N_WB); - set_f(st->hHQ_core->prev_normq, 0, SFM_N_WB); + if ( st->hHQ_core != NULL ) + { + set_f( st->hHQ_core->prev_env, 0, SFM_N_WB ); + set_f( st->hHQ_core->prev_normq, 0, SFM_N_WB ); - set_f(st->hHQ_core->last_ni_gain, 0, BANDS_MAX); - set_f(st->hHQ_core->last_env, 0, BANDS_MAX); - st->hHQ_core->last_max_pos_pulse = 0; + set_f( st->hHQ_core->last_ni_gain, 0, BANDS_MAX ); + set_f( st->hHQ_core->last_env, 0, BANDS_MAX ); + st->hHQ_core->last_max_pos_pulse = 0; - if (st->output_Fs > 16000) - { - set_f(st->hHQ_core->prev_coeff_out, 0, L_HQ_WB_BWE); - } + if ( st->output_Fs > 16000 ) + { + set_f( st->hHQ_core->prev_coeff_out, 0, L_HQ_WB_BWE ); + } - /* pre-echo */ - st->hHQ_core->pastpre = 0; - } + /* pre-echo */ + st->hHQ_core->pastpre = 0; + } - /* reset the GSC pre echo energy threshold in case of switching */ - if (st->hGSCDec != NULL) - { - st->hGSCDec->Last_frame_ener = (float)MAX_32; - } + /* reset the GSC pre echo energy threshold in case of switching */ + if ( st->hGSCDec != NULL ) + { + st->hGSCDec->Last_frame_ener = (float) MAX_32; + } - if (st->last_core == TCX_20_CORE || st->last_core == TCX_10_CORE) - { - if (st->element_mode == EVS_MONO) - { - st->last_core = HQ_CORE; - mvr2r(st->hTcxDec->FBTCXdelayBuf_float, st->prev_synth_buffer, NS2SA(st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS)); - } + if ( st->last_core == TCX_20_CORE || st->last_core == TCX_10_CORE ) + { + if ( st->element_mode == EVS_MONO ) + { + st->last_core = HQ_CORE; + mvr2r( st->hTcxDec->FBTCXdelayBuf_float, st->prev_synth_buffer, NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) ); + } - if (st->hHQ_core != NULL) - { - set_f(st->hHQ_core->last_ni_gain, 0, BANDS_MAX); - set_f(st->hHQ_core->last_env, 0, BANDS_MAX); - st->hHQ_core->last_max_pos_pulse = 0; + if ( st->hHQ_core != NULL ) + { + set_f( st->hHQ_core->last_ni_gain, 0, BANDS_MAX ); + set_f( st->hHQ_core->last_env, 0, BANDS_MAX ); + st->hHQ_core->last_max_pos_pulse = 0; - set_s(st->hHQ_core->prev_SWB_peak_pos, 0, SPT_SHORTEN_SBNUM); - st->hHQ_core->prev_frm_hfe2 = 0; - st->hHQ_core->prev_stab_hfe2 = 0; - } - } + set_s( st->hHQ_core->prev_SWB_peak_pos, 0, SPT_SHORTEN_SBNUM ); + st->hHQ_core->prev_frm_hfe2 = 0; + st->hHQ_core->prev_stab_hfe2 = 0; + } + } - if (st->prev_bfi != 0) - { - int16_t delay_comp; + if ( st->prev_bfi != 0 ) + { + int16_t delay_comp; - /*switch off Hq Voicing as it was not updated in MODE2*/ - if (st->hHQ_core != NULL) - { - st->hHQ_core->oldHqVoicing = 0; - st->hHQ_core->HqVoicing = 0; - } + /*switch off Hq Voicing as it was not updated in MODE2*/ + if ( st->hHQ_core != NULL ) + { + st->hHQ_core->oldHqVoicing = 0; + st->hHQ_core->HqVoicing = 0; + } - delay_comp = NS2SA(st->output_Fs, DELAY_CLDFB_NS); + delay_comp = NS2SA( st->output_Fs, DELAY_CLDFB_NS ); - if (!st->last_con_tcx && st->last_core_bfi == ACELP_CORE && st->core == HQ_CORE) - { - float *realBuffer[CLDFB_NO_COL_MAX_SWITCH], *imagBuffer[CLDFB_NO_COL_MAX_SWITCH]; - float realBufferTmp[CLDFB_NO_COL_MAX_SWITCH][CLDFB_NO_CHANNELS_MAX], imagBufferTmp[CLDFB_NO_COL_MAX_SWITCH][CLDFB_NO_CHANNELS_MAX]; + if ( !st->last_con_tcx && st->last_core_bfi == ACELP_CORE && st->core == HQ_CORE ) + { + float *realBuffer[CLDFB_NO_COL_MAX_SWITCH], *imagBuffer[CLDFB_NO_COL_MAX_SWITCH]; + float realBufferTmp[CLDFB_NO_COL_MAX_SWITCH][CLDFB_NO_CHANNELS_MAX], imagBufferTmp[CLDFB_NO_COL_MAX_SWITCH][CLDFB_NO_CHANNELS_MAX]; - for (i = 0; i < CLDFB_NO_COL_MAX_SWITCH; i++) - { - set_f(realBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX); - set_f(imagBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX); - realBuffer[i] = realBufferTmp[i]; - imagBuffer[i] = imagBufferTmp[i]; - } + for ( i = 0; i < CLDFB_NO_COL_MAX_SWITCH; i++ ) + { + set_f( realBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX ); + set_f( imagBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX ); + realBuffer[i] = realBufferTmp[i]; + imagBuffer[i] = imagBufferTmp[i]; + } - /* CLDFB analysis of the synthesis at internal sampling rate */ - if ((error = cldfb_save_memory_ivas(st->cldfbAna)) != IVAS_ERR_OK) - { - return error; - } + /* CLDFB analysis of the synthesis at internal sampling rate */ + if ( ( error = cldfb_save_memory_ivas( st->cldfbAna ) ) != IVAS_ERR_OK ) + { + return error; + } - cldfbAnalysis_ivas(st->hTcxDec->syn_Overl_float, realBuffer, imagBuffer, delay_comp, st->cldfbAna); - cldfb_restore_memory_ivas(st->cldfbAna); + cldfbAnalysis_ivas( st->hTcxDec->syn_Overl_float, realBuffer, imagBuffer, delay_comp, st->cldfbAna ); + cldfb_restore_memory_ivas( st->cldfbAna ); - /* CLDFB synthesis of the combined signal */ - if ((error = cldfb_save_memory_ivas(st->cldfbSyn)) != IVAS_ERR_OK) - { - return error; - } + /* CLDFB synthesis of the combined signal */ + if ( ( error = cldfb_save_memory_ivas( st->cldfbSyn ) ) != IVAS_ERR_OK ) + { + return error; + } - cldfbSynthesis_ivas(realBuffer, imagBuffer, st->hHQ_core->fer_samples, delay_comp, st->cldfbSyn); - cldfb_restore_memory_ivas(st->cldfbSyn); - } + cldfbSynthesis_ivas( realBuffer, imagBuffer, st->hHQ_core->fer_samples, delay_comp, st->cldfbSyn ); + cldfb_restore_memory_ivas( st->cldfbSyn ); + } - if (!st->last_con_tcx && st->last_core_bfi == ACELP_CORE && st->core == HQ_CORE) - { - lerp_flt(st->hTcxDec->syn_Overl_float, st->hHQ_core->fer_samples + delay_comp, output_frame / 2, st->last_L_frame / 2); - /*Set to zero the remaining part*/ - set_f(st->hHQ_core->fer_samples + delay_comp + output_frame / 2, 0, (output_frame / 2) - delay_comp); - } - } + if ( !st->last_con_tcx && st->last_core_bfi == ACELP_CORE && st->core == HQ_CORE ) + { + lerp_flt( st->hTcxDec->syn_Overl_float, st->hHQ_core->fer_samples + delay_comp, output_frame / 2, st->last_L_frame / 2 ); + /*Set to zero the remaining part*/ + set_f( st->hHQ_core->fer_samples + delay_comp + output_frame / 2, 0, ( output_frame / 2 ) - delay_comp ); + } + } - st->use_acelp_preq = 0; - st->reset_mem_AR = 0; - } + st->use_acelp_preq = 0; + st->reset_mem_AR = 0; + } - /*FEC*/ - if (st->L_frame <= L_FRAME16k) - { - if (st->last_L_frame <= L_FRAME16k && st->core != HQ_CORE) + /*FEC*/ + if ( st->L_frame <= L_FRAME16k ) { - if (st->L_frame != st->last_L_frame) - { - if (st->L_frame > st->last_L_frame) + if ( st->last_L_frame <= L_FRAME16k && st->core != HQ_CORE ) { - oldLenClasBuff = L_SYN_MEM_CLAS_ESTIM * st->last_L_frame / st->L_frame; - newLenClasBuff = L_SYN_MEM_CLAS_ESTIM; + if ( st->L_frame != st->last_L_frame ) + { + if ( st->L_frame > st->last_L_frame ) + { + oldLenClasBuff = L_SYN_MEM_CLAS_ESTIM * st->last_L_frame / st->L_frame; + newLenClasBuff = L_SYN_MEM_CLAS_ESTIM; + } + else + { + oldLenClasBuff = L_SYN_MEM_CLAS_ESTIM; + newLenClasBuff = L_SYN_MEM_CLAS_ESTIM * st->L_frame / st->last_L_frame; + } + lerp_flt( &st->mem_syn_clas_estim[L_SYN_MEM_CLAS_ESTIM - oldLenClasBuff], &st->mem_syn_clas_estim[L_SYN_MEM_CLAS_ESTIM - newLenClasBuff], newLenClasBuff, oldLenClasBuff ); + } } else { - oldLenClasBuff = L_SYN_MEM_CLAS_ESTIM; - newLenClasBuff = L_SYN_MEM_CLAS_ESTIM * st->L_frame / st->last_L_frame; + set_zero( st->mem_syn_clas_estim, L_SYN_MEM_CLAS_ESTIM ); } - lerp_flt(&st->mem_syn_clas_estim[L_SYN_MEM_CLAS_ESTIM - oldLenClasBuff], &st->mem_syn_clas_estim[L_SYN_MEM_CLAS_ESTIM - newLenClasBuff], newLenClasBuff, oldLenClasBuff); - } } - else - { - set_zero(st->mem_syn_clas_estim, L_SYN_MEM_CLAS_ESTIM); - } - } - - /* Here we only handle cases where last_ppp and last_nelp not updated when coming from CodecB or other cores - within ACELP_CORE if switching from another bitarate to vbr, last_ppp and last_nelp is always updated in the previous frame */ - if (st->core == ACELP_CORE && (st->last_core != ACELP_CORE || st->last_codec_mode == MODE2)) - { - st->last_ppp_mode_dec = 0; - st->last_nelp_mode_dec = 0; - } - /* Handle state reset of stat_noise_uv_mod memory */ - if (st->core == ACELP_CORE && (st->last_core != ACELP_CORE || st->last_codec_mode == MODE2 || st->last_total_brate <= PPP_NELP_2k80)) - { - st->act_count = 3; - st->uv_count = 0; - } - - if (((st->core == ACELP_CORE || st->core == AMR_WB_CORE) && st->last_core == HQ_CORE) || ((st->element_mode == IVAS_CPE_DFT || st->element_mode == IVAS_CPE_TD || (st->element_mode == IVAS_CPE_MDCT && last_element_mode == IVAS_CPE_DFT)) && nchan_out == 2 && - st->core_brate != SID_2k40 && st->core_brate != FRAME_NO_DATA && (last_core_brate_st0 == FRAME_NO_DATA || last_core_brate_st0 == SID_2k40))) - { - if (st->element_mode == IVAS_CPE_DFT || st->element_mode == IVAS_CPE_TD) + /* Here we only handle cases where last_ppp and last_nelp not updated when coming from CodecB or other cores + within ACELP_CORE if switching from another bitarate to vbr, last_ppp and last_nelp is always updated in the previous frame */ + if ( st->core == ACELP_CORE && ( st->last_core != ACELP_CORE || st->last_codec_mode == MODE2 ) ) { - st->hPFstat->reset = 1; + st->last_ppp_mode_dec = 0; + st->last_nelp_mode_dec = 0; } - if (st->L_frame == L_FRAME16k) - { - mvr2r(TRWB2_Ave, st->lsf_old, M); /* init of LSP */ - mvr2r(TRWB2_Ave, st->lsfoldbfi1, M); - mvr2r(TRWB2_Ave, st->lsfoldbfi0, M); - mvr2r(TRWB2_Ave, st->lsf_adaptive_mean, M); - lsf2lsp(st->lsf_old, st->lsp_old, M, INT_FS_16k); - } - else + /* Handle state reset of stat_noise_uv_mod memory */ + if ( st->core == ACELP_CORE && ( st->last_core != ACELP_CORE || st->last_codec_mode == MODE2 || st->last_total_brate <= PPP_NELP_2k80 ) ) { - mvr2r(TRWB_Ave, st->lsf_old, M); /* init of LSP */ - mvr2r(TRWB_Ave, st->lsfoldbfi1, M); - mvr2r(TRWB_Ave, st->lsfoldbfi0, M); - mvr2r(TRWB_Ave, st->lsf_adaptive_mean, M); - lsf2lsp(st->lsf_old, st->lsp_old, M, INT_FS_12k8); + st->act_count = 3; + st->uv_count = 0; } - if ((st->element_mode == IVAS_CPE_DFT || st->element_mode == IVAS_CPE_TD) && nchan_out == 2 && st->core_brate > SID_2k40 && (last_core_brate_st0 == FRAME_NO_DATA || last_core_brate_st0 == SID_2k40) && st->hTcxDec != NULL) + if ( ( ( st->core == ACELP_CORE || st->core == AMR_WB_CORE ) && st->last_core == HQ_CORE ) || ( ( st->element_mode == IVAS_CPE_DFT || st->element_mode == IVAS_CPE_TD || ( st->element_mode == IVAS_CPE_MDCT && last_element_mode == IVAS_CPE_DFT ) ) && nchan_out == 2 && + st->core_brate != SID_2k40 && st->core_brate != FRAME_NO_DATA && ( last_core_brate_st0 == FRAME_NO_DATA || last_core_brate_st0 == SID_2k40 ) ) ) { - /* Last frame was Stereo CNG and the synthesis memory is outdated -- reset */ - set_f(st->hTcxDec->old_syn_Overl_float, 0.0f, L_FRAME32k / 2); - set_f(st->hFdCngDec->hFdCngCom->olapBufferAna_flt, 0.0f, FFTLEN); - } + if ( st->element_mode == IVAS_CPE_DFT || st->element_mode == IVAS_CPE_TD ) + { + st->hPFstat->reset = 1; + } - set_f(st->agc_mem2, 0, 2); - st->mem_deemph = 0; - if (!st->last_con_tcx) - { - set_f(st->mem_syn2, 0.0f, M); - } - set_f(st->mem_syn1, 0.0f, M); - if (st->hBWE_TD != NULL) - { - st->hBWE_TD->bwe_non_lin_prev_scale = 0.0f; - } + if ( st->L_frame == L_FRAME16k ) + { + mvr2r( TRWB2_Ave, st->lsf_old, M ); /* init of LSP */ + mvr2r( TRWB2_Ave, st->lsfoldbfi1, M ); + mvr2r( TRWB2_Ave, st->lsfoldbfi0, M ); + mvr2r( TRWB2_Ave, st->lsf_adaptive_mean, M ); + lsf2lsp( st->lsf_old, st->lsp_old, M, INT_FS_16k ); + } + else + { + mvr2r( TRWB_Ave, st->lsf_old, M ); /* init of LSP */ + mvr2r( TRWB_Ave, st->lsfoldbfi1, M ); + mvr2r( TRWB_Ave, st->lsfoldbfi0, M ); + mvr2r( TRWB_Ave, st->lsf_adaptive_mean, M ); + lsf2lsp( st->lsf_old, st->lsp_old, M, INT_FS_12k8 ); + } - /* Reset ACELP parameters */ - set_zero(st->mem_MA, M); - if (st->sr_core == INT_FS_16k) - { - mvr2r(GEWB2_Ave, st->mem_AR, M); - } - else - { - mvr2r(GEWB_Ave, st->mem_AR, M); - } - st->tilt_code = 0.0f; - st->gc_threshold = 0.0f; - set_f(st->dispMem, 0, 8); + if ( ( st->element_mode == IVAS_CPE_DFT || st->element_mode == IVAS_CPE_TD ) && nchan_out == 2 && st->core_brate > SID_2k40 && ( last_core_brate_st0 == FRAME_NO_DATA || last_core_brate_st0 == SID_2k40 ) && st->hTcxDec != NULL ) + { + /* Last frame was Stereo CNG and the synthesis memory is outdated -- reset */ + set_f( st->hTcxDec->old_syn_Overl_float, 0.0f, L_FRAME32k / 2 ); + set_f( st->hFdCngDec->hFdCngCom->olapBufferAna_flt, 0.0f, FFTLEN ); + } - st->last_coder_type = GENERIC; + set_f( st->agc_mem2, 0, 2 ); + st->mem_deemph = 0; + if ( !st->last_con_tcx ) + { + set_f( st->mem_syn2, 0.0f, M ); + } + set_f( st->mem_syn1, 0.0f, M ); + if ( st->hBWE_TD != NULL ) + { + st->hBWE_TD->bwe_non_lin_prev_scale = 0.0f; + } - fer_energy(output_frame, UNVOICED_CLAS, st->previoussynth, -1, &st->enr_old, 1); - st->lp_gainp = 0.0f; - st->lp_gainc = (float)sqrt(st->lp_ener); + /* Reset ACELP parameters */ + set_zero( st->mem_MA, M ); + if ( st->sr_core == INT_FS_16k ) + { + mvr2r( GEWB2_Ave, st->mem_AR, M ); + } + else + { + mvr2r( GEWB_Ave, st->mem_AR, M ); + } + st->tilt_code = 0.0f; + st->gc_threshold = 0.0f; + set_f( st->dispMem, 0, 8 ); - st->last_voice_factor = 0; - st->Last_GSC_noisy_speech_flag = 0; + st->last_coder_type = GENERIC; - /* reset CLDFB memories */ - cldfb_reset_memory_ivas(st->cldfbAna); - cldfb_reset_memory_ivas(st->cldfbBPF); - cldfb_reset_memory_ivas(st->cldfbSyn); + fer_energy( output_frame, UNVOICED_CLAS, st->previoussynth, -1, &st->enr_old, 1 ); + st->lp_gainp = 0.0f; + st->lp_gainc = (float) sqrt( st->lp_ener ); - /* reset TBE memories */ - if (!st->last_con_tcx && !((st->last_core == HQ_CORE) && st->element_mode > EVS_MONO)) - { - set_f(st->old_exc, 0, L_EXC_MEM_DEC); - } - else if (st->L_frame < L_FRAME16k) - { - /* resample from 16kHz to 12.8kHZ */ - synth_mem_updt2_flt(st->L_frame, L_FRAME16k, st->old_exc, st->mem_syn_r_float, st->mem_syn2, NULL, DEC); - } + st->last_voice_factor = 0; + st->Last_GSC_noisy_speech_flag = 0; - if (st->hBWE_TD != NULL) - { - set_f(st->hBWE_TD->old_bwe_exc, 0, PIT16k_MAX * 2); - } + /* reset CLDFB memories */ + cldfb_reset_memory_ivas( st->cldfbAna ); + cldfb_reset_memory_ivas( st->cldfbBPF ); + cldfb_reset_memory_ivas( st->cldfbSyn ); - if (st->output_Fs >= 16000 && st->hBWE_zero != NULL) - { - hf_synth_reset(st->hBWE_zero); - } + /* reset TBE memories */ + if ( !st->last_con_tcx && !( ( st->last_core == HQ_CORE ) && st->element_mode > EVS_MONO ) ) + { + set_f( st->old_exc, 0, L_EXC_MEM_DEC ); + } + else if ( st->L_frame < L_FRAME16k ) + { + /* resample from 16kHz to 12.8kHZ */ + synth_mem_updt2_flt( st->L_frame, L_FRAME16k, st->old_exc, st->mem_syn_r_float, st->mem_syn2, NULL, DEC ); + } - if (st->hBWE_FD != NULL) - { - set_f(st->hBWE_FD->old_syn_12k8_16k, 0, NS2SA(16000, DELAY_FD_BWE_ENC_NS)); - } + if ( st->hBWE_TD != NULL ) + { + set_f( st->hBWE_TD->old_bwe_exc, 0, PIT16k_MAX * 2 ); + } + + if ( st->output_Fs >= 16000 && st->hBWE_zero != NULL ) + { + hf_synth_reset( st->hBWE_zero ); + } + + if ( st->hBWE_FD != NULL ) + { + set_f( st->hBWE_FD->old_syn_12k8_16k, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); + } } - if ((st->core == ACELP_CORE || st->core == AMR_WB_CORE) && (st->last_core == TCX_20_CORE || st->last_core == TCX_10_CORE)) - { - if (st->hBWE_TD != NULL) + if ( ( st->core == ACELP_CORE || st->core == AMR_WB_CORE ) && ( st->last_core == TCX_20_CORE || st->last_core == TCX_10_CORE ) ) { - st->hBWE_TD->bwe_non_lin_prev_scale = 0.0f; - set_f(st->hBWE_TD->old_bwe_exc, 0, PIT16k_MAX * 2); - } + if ( st->hBWE_TD != NULL ) + { + st->hBWE_TD->bwe_non_lin_prev_scale = 0.0f; + set_f( st->hBWE_TD->old_bwe_exc, 0, PIT16k_MAX * 2 ); + } - st->tilt_code = 0.0f; - st->gc_threshold = 0.0f; - set_f(st->dispMem, 0, 8); + st->tilt_code = 0.0f; + st->gc_threshold = 0.0f; + set_f( st->dispMem, 0, 8 ); - st->last_coder_type = GENERIC; + st->last_coder_type = GENERIC; - fer_energy(output_frame, UNVOICED_CLAS, st->previoussynth, -1, &st->enr_old, 1); - st->lp_gainp = 0.0f; - st->lp_gainc = (float)sqrt(st->lp_ener); + fer_energy( output_frame, UNVOICED_CLAS, st->previoussynth, -1, &st->enr_old, 1 ); + st->lp_gainp = 0.0f; + st->lp_gainc = (float) sqrt( st->lp_ener ); - st->last_voice_factor = 0; - st->Last_GSC_noisy_speech_flag = 0; + st->last_voice_factor = 0; + st->Last_GSC_noisy_speech_flag = 0; - if (st->output_Fs >= 16000 && st->hBWE_zero != NULL) - { - hf_synth_reset(st->hBWE_zero); - } + if ( st->output_Fs >= 16000 && st->hBWE_zero != NULL ) + { + hf_synth_reset( st->hBWE_zero ); + } - if (st->hBWE_FD != NULL) - { - set_f(st->hBWE_FD->old_syn_12k8_16k, 0, NS2SA(16000, DELAY_FD_BWE_ENC_NS)); - } + if ( st->hBWE_FD != NULL ) + { + set_f( st->hBWE_FD->old_syn_12k8_16k, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); + } - if (nchan_out == 1 && st->element_mode == IVAS_CPE_DFT && st->element_brate <= IVAS_24k4 && last_element_brate > IVAS_24k4) - { - /* update cldbf state with previous frame TCX synthesis when going from a bitrate with residual coding to a bitrate without it */ - int16_t offset; - offset = st->cldfbAna->p_filter_length - st->cldfbAna->no_channels; - mvr2r(st->hTcxDec->old_synthFB + st->hTcxDec->old_synth_lenFB - offset, st->cldfbAna->cldfb_state, offset); + if ( nchan_out == 1 && st->element_mode == IVAS_CPE_DFT && st->element_brate <= IVAS_24k4 && last_element_brate > IVAS_24k4 ) + { + /* update cldbf state with previous frame TCX synthesis when going from a bitrate with residual coding to a bitrate without it */ + int16_t offset; + offset = st->cldfbAna->p_filter_length - st->cldfbAna->no_channels; + mvr2r( st->hTcxDec->old_synthFB + st->hTcxDec->old_synth_lenFB - offset, st->cldfbAna->cldfb_state, offset ); + } } - } - if (st->core == HQ_CORE && (st->last_core == ACELP_CORE || st->last_core == AMR_WB_CORE || ((st->element_mode != EVS_MONO) && (st->last_core != HQ_CORE)))) - { - set_f(st->hHQ_core->prev_env, 0, SFM_N_WB); - set_f(st->hHQ_core->prev_normq, 0, SFM_N_WB); + if ( st->core == HQ_CORE && ( st->last_core == ACELP_CORE || st->last_core == AMR_WB_CORE || ( ( st->element_mode != EVS_MONO ) && ( st->last_core != HQ_CORE ) ) ) ) + { + set_f( st->hHQ_core->prev_env, 0, SFM_N_WB ); + set_f( st->hHQ_core->prev_normq, 0, SFM_N_WB ); - set_f(st->hHQ_core->last_ni_gain, 0, BANDS_MAX); - set_f(st->hHQ_core->last_env, 0, BANDS_MAX); - st->hHQ_core->last_max_pos_pulse = 0; + set_f( st->hHQ_core->last_ni_gain, 0, BANDS_MAX ); + set_f( st->hHQ_core->last_env, 0, BANDS_MAX ); + st->hHQ_core->last_max_pos_pulse = 0; - set_s(st->hHQ_core->prev_SWB_peak_pos, 0, SPT_SHORTEN_SBNUM); - st->hHQ_core->prev_frm_hfe2 = 0; - st->hHQ_core->prev_stab_hfe2 = 0; - if (st->output_Fs > 16000) - { - set_f(st->hHQ_core->prev_coeff_out, 0, L_HQ_WB_BWE); - } + set_s( st->hHQ_core->prev_SWB_peak_pos, 0, SPT_SHORTEN_SBNUM ); + st->hHQ_core->prev_frm_hfe2 = 0; + st->hHQ_core->prev_stab_hfe2 = 0; + if ( st->output_Fs > 16000 ) + { + set_f( st->hHQ_core->prev_coeff_out, 0, L_HQ_WB_BWE ); + } - if (st->element_mode != EVS_MONO) - { - /* Estimate mem_env_delta to reinit env_stab */ - tmp = max(0, ENV_STAB_EST1 + (ENV_STAB_EST2 * st->stab_fac_smooth_lt) + (ENV_STAB_EST3 * st->log_energy_diff_lt)); - st->hHQ_core->mem_env_delta = (int16_t)min(MAX16B, (int32_t)(tmp * (1 << 12))); /* Convert to Q12 and handle saturation */ + if ( st->element_mode != EVS_MONO ) + { + /* Estimate mem_env_delta to reinit env_stab */ + tmp = max( 0, ENV_STAB_EST1 + ( ENV_STAB_EST2 * st->stab_fac_smooth_lt ) + ( ENV_STAB_EST3 * st->log_energy_diff_lt ) ); + st->hHQ_core->mem_env_delta = (int16_t) min( MAX16B, (int32_t) ( tmp * ( 1 << 12 ) ) ); /* Convert to Q12 and handle saturation */ - if (st->last_core != TCX_20_CORE && st->last_core != TCX_10_CORE) - { - set_f(st->hHQ_core->old_out, 0, output_frame); - set_f(st->hHQ_core->old_outLB, 0, L_FRAME16k); - } + if ( st->last_core != TCX_20_CORE && st->last_core != TCX_10_CORE ) + { + set_f( st->hHQ_core->old_out, 0, output_frame ); + set_f( st->hHQ_core->old_outLB, 0, L_FRAME16k ); + } - st->hHQ_core->no_att_hangover = 0; - st->hHQ_core->energy_lt = 300.0f; + st->hHQ_core->no_att_hangover = 0; + st->hHQ_core->energy_lt = 300.0f; - set_s(st->hHQ_core->old_is_transient, 0, 3); - set_f(st->hHQ_core->prev_noise_level, 0.0f, 2); - st->hHQ_core->prev_R = 0; - set_s(st->hHQ_core->mem_norm + 1, 39, SFM_N_ENV_STAB - 1); - st->hHQ_core->prev_hqswb_clas = HQ_NORMAL; - st->hHQ_core->prev_ni_ratio = 0.5f; - set_f(st->hHQ_core->prev_En_sb, 0.0f, NB_SWB_SUBBANDS); + set_s( st->hHQ_core->old_is_transient, 0, 3 ); + set_f( st->hHQ_core->prev_noise_level, 0.0f, 2 ); + st->hHQ_core->prev_R = 0; + set_s( st->hHQ_core->mem_norm + 1, 39, SFM_N_ENV_STAB - 1 ); + st->hHQ_core->prev_hqswb_clas = HQ_NORMAL; + st->hHQ_core->prev_ni_ratio = 0.5f; + set_f( st->hHQ_core->prev_En_sb, 0.0f, NB_SWB_SUBBANDS ); + } + else + { + set_f( st->hHQ_core->old_out, 0, output_frame ); + set_f( st->hHQ_core->old_outLB, 0, L_FRAME16k ); + } } - else + + /* handle switching cases where preecho_sb was not called in the last frame (memory not up to date) */ + if ( st->hHQ_core != NULL ) { - set_f(st->hHQ_core->old_out, 0, output_frame); - set_f(st->hHQ_core->old_outLB, 0, L_FRAME16k); + st->hHQ_core->pastpre--; + if ( st->hHQ_core->pastpre <= 0 ) + { + reset_preecho_dec( st->hHQ_core ); + } } - } - /* handle switching cases where preecho_sb was not called in the last frame (memory not up to date) */ - if (st->hHQ_core != NULL) - { - st->hHQ_core->pastpre--; - if (st->hHQ_core->pastpre <= 0) + if ( st->core_brate == FRAME_NO_DATA ) { - reset_preecho_dec(st->hHQ_core); + st->VAD = 0; + st->m_frame_type = ZERO_FRAME; } - } - - if (st->core_brate == FRAME_NO_DATA) - { - st->VAD = 0; - st->m_frame_type = ZERO_FRAME; - } - else if (st->core_brate == SID_2k40 || st->core_brate == SID_1k75) - { - st->VAD = 0; - st->m_frame_type = SID_FRAME; - } - else - { - st->VAD = 1; - st->m_frame_type = ACTIVE_FRAME; - } - - /*switch on CNA on active frames*/ - if (st->element_mode == EVS_MONO) /* for IVAS modes, st->flag_cna is set earlier */ - { - if (st->VAD && ((st->core != AMR_WB_CORE && st->total_brate <= CNA_MAX_BRATE) || (st->core == AMR_WB_CORE && st->total_brate <= ACELP_8k85))) + else if ( st->core_brate == SID_2k40 || st->core_brate == SID_1k75 ) { - st->flag_cna = 1; + st->VAD = 0; + st->m_frame_type = SID_FRAME; } - else if (st->VAD || ((st->cng_type == FD_CNG) && (st->L_frame == L_FRAME16k))) + else { - st->flag_cna = 0; + st->VAD = 1; + st->m_frame_type = ACTIVE_FRAME; } - } - if (st->core == AMR_WB_CORE) - { - st->cng_type = LP_CNG; - } - - /* Reconfigure CNG */ - if (st->hFdCngDec && ((st->last_L_frame != st->L_frame) || (st->hFdCngDec->hFdCngCom->frameSize != st->L_frame) || st->ini_frame == 0 || st->bwidth != st->last_bwidth)) - { - /* || st->last_core == AMR_WB_CORE || st->last_codec_mode == MODE2)){*/ - if (st->core != AMR_WB_CORE) + /*switch on CNA on active frames*/ + if ( st->element_mode == EVS_MONO ) /* for IVAS modes, st->flag_cna is set earlier */ { - configureFdCngDec(st->hFdCngDec, st->bwidth, st->rf_flag == 1 && st->total_brate == ACELP_13k20 ? ACELP_9k60 : st->total_brate, st->L_frame, st->last_L_frame, st->element_mode); + if ( st->VAD && ( ( st->core != AMR_WB_CORE && st->total_brate <= CNA_MAX_BRATE ) || ( st->core == AMR_WB_CORE && st->total_brate <= ACELP_8k85 ) ) ) + { + st->flag_cna = 1; + } + else if ( st->VAD || ( ( st->cng_type == FD_CNG ) && ( st->L_frame == L_FRAME16k ) ) ) + { + st->flag_cna = 0; + } } - else - { - configureFdCngDec(st->hFdCngDec, WB, ACELP_8k00, st->L_frame, st->last_L_frame, st->element_mode); - if (st->VAD) - { - st->hFdCngDec->hFdCngCom->CngBitrate = st->total_brate; - } - } - if (st->last_L_frame != st->L_frame && st->L_frame <= L_FRAME16k && st->last_L_frame <= L_FRAME16k) + if ( st->core == AMR_WB_CORE ) { - if (st->element_mode == IVAS_CPE_DFT || st->element_mode == IVAS_CPE_TD) - { - lerp_flt(st->hFdCngDec->hFdCngCom->olapBufferAna_flt + st->last_L_frame, st->hFdCngDec->hFdCngCom->olapBufferAna_flt + st->L_frame, st->L_frame, st->last_L_frame); - } - - lerp_flt(st->hFdCngDec->hFdCngCom->olapBufferSynth2_flt, st->hFdCngDec->hFdCngCom->olapBufferSynth2_flt, st->L_frame * 2, st->last_L_frame * 2); - - if (st->total_brate <= SID_2k40 && st->last_total_brate <= SID_2k40) - { - lerp_flt(st->hFdCngDec->hFdCngCom->olapBufferSynth_flt, st->hFdCngDec->hFdCngCom->olapBufferSynth_flt, st->L_frame * 2, st->last_L_frame * 2); + st->cng_type = LP_CNG; + } - if (st->L_frame == L_FRAME) + /* Reconfigure CNG */ + if ( st->hFdCngDec && ( ( st->last_L_frame != st->L_frame ) || ( st->hFdCngDec->hFdCngCom->frameSize != st->L_frame ) || st->ini_frame == 0 || st->bwidth != st->last_bwidth ) ) + { + /* || st->last_core == AMR_WB_CORE || st->last_codec_mode == MODE2)){*/ + if ( st->core != AMR_WB_CORE ) { - for (i = 0; i < st->L_frame * 2; i++) - { - st->hFdCngDec->hFdCngCom->olapBufferSynth_flt[i] = st->hFdCngDec->hFdCngCom->olapBufferSynth_flt[i] * 0.6250f; - } + configureFdCngDec( st->hFdCngDec, st->bwidth, st->rf_flag == 1 && st->total_brate == ACELP_13k20 ? ACELP_9k60 : st->total_brate, st->L_frame, st->last_L_frame, st->element_mode ); } else { - for (i = 0; i < st->L_frame * 2; i++) - { - st->hFdCngDec->hFdCngCom->olapBufferSynth_flt[i] = st->hFdCngDec->hFdCngCom->olapBufferSynth_flt[i] * 1.6f; - } + configureFdCngDec( st->hFdCngDec, WB, ACELP_8k00, st->L_frame, st->last_L_frame, st->element_mode ); + + if ( st->VAD ) + { + st->hFdCngDec->hFdCngCom->CngBitrate = st->total_brate; + } + } + if ( st->last_L_frame != st->L_frame && st->L_frame <= L_FRAME16k && st->last_L_frame <= L_FRAME16k ) + { + if ( st->element_mode == IVAS_CPE_DFT || st->element_mode == IVAS_CPE_TD ) + { + lerp_flt( st->hFdCngDec->hFdCngCom->olapBufferAna_flt + st->last_L_frame, st->hFdCngDec->hFdCngCom->olapBufferAna_flt + st->L_frame, st->L_frame, st->last_L_frame ); + } + + lerp_flt( st->hFdCngDec->hFdCngCom->olapBufferSynth2_flt, st->hFdCngDec->hFdCngCom->olapBufferSynth2_flt, st->L_frame * 2, st->last_L_frame * 2 ); + + if ( st->total_brate <= SID_2k40 && st->last_total_brate <= SID_2k40 ) + { + lerp_flt( st->hFdCngDec->hFdCngCom->olapBufferSynth_flt, st->hFdCngDec->hFdCngCom->olapBufferSynth_flt, st->L_frame * 2, st->last_L_frame * 2 ); + + if ( st->L_frame == L_FRAME ) + { + for ( i = 0; i < st->L_frame * 2; i++ ) + { + st->hFdCngDec->hFdCngCom->olapBufferSynth_flt[i] = st->hFdCngDec->hFdCngCom->olapBufferSynth_flt[i] * 0.6250f; + } + } + else + { + for ( i = 0; i < st->L_frame * 2; i++ ) + { + st->hFdCngDec->hFdCngCom->olapBufferSynth_flt[i] = st->hFdCngDec->hFdCngCom->olapBufferSynth_flt[i] * 1.6f; + } + } + } } } - } - } - return error; + return error; } #endif #ifndef IVAS_FLOAT_FIXED @@ -1172,374 +1172,374 @@ ivas_error core_switching_pre_dec( * Postprocessing for ACELP/HQ core switching *---------------------------------------------------------------------*/ ivas_error core_switching_post_dec( - Decoder_State *st, /* i/o: decoder state structure */ - float *synth, /* i/o: output synthesis */ - float *output, /* i/o: LB synth/upsampled LB synth */ - float output_mem[], /* i : OLA memory from last TCX/HQ frame */ - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const int16_t use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ - const int16_t output_frame, /* i : frame length */ - const int16_t core_switching_flag, /* i : ACELP->HQ switching flag */ - const int16_t sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC */ - const int16_t nchan_out, /* i : number of output channels */ - const int16_t last_element_mode /* i : element mode of previous frame */ + Decoder_State *st, /* i/o: decoder state structure */ + float *synth, /* i/o: output synthesis */ + float *output, /* i/o: LB synth/upsampled LB synth */ + float output_mem[], /* i : OLA memory from last TCX/HQ frame */ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const int16_t use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ + const int16_t output_frame, /* i : frame length */ + const int16_t core_switching_flag, /* i : ACELP->HQ switching flag */ + const int16_t sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC */ + const int16_t nchan_out, /* i : number of output channels */ + const int16_t last_element_mode /* i : element mode of previous frame */ ) { - int16_t i, delay_comp, delta; - float tmpF; - float tmpDelta; - float synth_subfr_out[SWITCH_MAX_GAP], synth_subfr_bwe[SWITCH_MAX_GAP]; - float mem_synth[NS2SA(16000, DELAY_CLDFB_NS) + 2]; - int16_t nZeros; - int16_t offset; - ivas_error error; - - error = IVAS_ERR_OK; - - if (st->core == ACELP_CORE && st->bfi && st->hHQ_core != NULL && !st->con_tcx) - { - if ((error = acelp_core_switch_dec_bfi(st)) != IVAS_ERR_OK) - { - return error; - } - } - - /* set multiplication factor according to the sampling rate */ - delta = 1; - if (output_frame == L_FRAME16k) - { - delta = 2; - } - else if (output_frame == L_FRAME32k) - { - delta = 4; - } - else if (output_frame == L_FRAME48k) - { - delta = 6; - } - - /* set delay compensation between HQ synthesis and ACELP synthesis */ - delay_comp = delta * HQ_DELAY_COMP; - - /* Core switching done in DFT domain afterward*/ - if ((st->element_mode != IVAS_CPE_DFT || use_cldfb_for_dft) && (!sba_dirac_stereo_flag || (sba_dirac_stereo_flag && st->core_brate == SID_2k40 && st->cng_type == FD_CNG))) - { - if (st->core == HQ_CORE || st->core == TCX_20_CORE || st->core == TCX_10_CORE || (st->core == ACELP_CORE && st->bfi == 1 && st->con_tcx == 1)) - { - st->use_acelp_preq = 0; - if (st->hBWE_FD != NULL) - { - st->hBWE_FD->mem_deemph_old_syn = 0.0f; - } - - if (st->element_mode == EVS_MONO && st->core == HQ_CORE) /* ACELP->HQ-CORE */ - { - if (core_switching_flag && st->last_L_frame == st->last_L_frame_ori && (st->last_core == ACELP_CORE || st->last_core == AMR_WB_CORE)) - { - if ((error = acelp_core_switch_dec(st, synth_subfr_out, synth_subfr_bwe, output_frame, core_switching_flag, mem_synth, nchan_out)) != IVAS_ERR_OK) - { - return error; - } - } - - if (core_switching_flag && st->last_core == HQ_CORE && st->prev_bfi) - { - mvr2r(st->delay_buf_out, synth_subfr_out, delay_comp); - } - } + int16_t i, delay_comp, delta; + float tmpF; + float tmpDelta; + float synth_subfr_out[SWITCH_MAX_GAP], synth_subfr_bwe[SWITCH_MAX_GAP]; + float mem_synth[NS2SA( 16000, DELAY_CLDFB_NS ) + 2]; + int16_t nZeros; + int16_t offset; + ivas_error error; - /* delay HQ synthesis to synchronize with ACELP synthesis */ - delay_signal_float(synth, output_frame, st->delay_buf_out, delay_comp); + error = IVAS_ERR_OK; - if (st->element_mode == EVS_MONO && st->core == HQ_CORE) /* ACELP->HQ-CORE */ - { - if (core_switching_flag && st->last_L_frame == st->last_L_frame_ori && (st->last_core == ACELP_CORE || st->last_core == AMR_WB_CORE)) - { - core_switching_OLA(mem_synth, st->last_L_frame, st->output_Fs, synth, synth_subfr_out, synth_subfr_bwe, output_frame, st->bwidth); - } - else if (core_switching_flag && st->last_core == HQ_CORE && st->prev_bfi) /* HQ | ACELP | TRANSITION with ACELP frame lost */ - { - /* Overlap between old->out[] (stocked in st->fer_samples[]) and good HQ frame on L/2 */ - nZeros = (int16_t)(NS2SA(st->output_Fs, N_ZERO_MDCT_NS)); - tmpDelta = 1.0f / (float)(output_frame >> 1); - for (i = 0; i < (output_frame >> 1); i++) - { - tmpF = (float)i * tmpDelta; - synth[i + delay_comp] = (1 - tmpF) * st->hHQ_core->fer_samples[i + nZeros] + synth[i + delay_comp] * tmpF; - } - } - else if ((!core_switching_flag && st->core == HQ_CORE && (st->last_core == ACELP_CORE || st->last_core == AMR_WB_CORE)) || /* ACELP | TRANSITION | HQ with TRANSITION lost */ - (core_switching_flag && st->prev_bfi && st->last_L_frame != st->last_L_frame_ori)) /* ACELP@12k8 | ACELP@16k | TRANSITION with ACELP@16k lost */ + if ( st->core == ACELP_CORE && st->bfi && st->hHQ_core != NULL && !st->con_tcx ) + { + if ( ( error = acelp_core_switch_dec_bfi( st ) ) != IVAS_ERR_OK ) { - /* Overlap between CELP estimation (BFI) and good HQ frame on L/2 */ - tmpDelta = 1.0f / (float)(output_frame >> 1); - for (i = 0; i < (output_frame >> 1); i++) - { - tmpF = (float)i * tmpDelta; - synth[i] = synth[i] * tmpF + (1 - tmpF) * st->hHQ_core->fer_samples[i]; - } + return error; } } - else if (((st->last_core == ACELP_CORE || st->last_core_bfi == ACELP_CORE) && !(st->prev_bfi == 1 && st->last_con_tcx == 1)) || st->last_core == AMR_WB_CORE) /*ACELP->TCX/HQ*/ - { - /* if this is first active MDCT-Stereo frame after a CNG frame and output format is mono DMX, this should only be done for the zero-th channel, the other one will simply be copied over after this function */ - if (((st->last_core_brate != SID_2k40 && st->last_core_brate != FRAME_NO_DATA) || (st->element_mode != IVAS_CPE_DFT && st->element_mode != IVAS_CPE_TD) || nchan_out == 1) && !(st->element_mode == IVAS_CPE_MDCT && st->idchan == 1 && (nchan_out == 1 || last_element_mode == IVAS_CPE_DFT))) - { - core_switch_lb_upsamp(st, output); - } - mvr2r(st->previoussynth, synth, delay_comp); + /* set multiplication factor according to the sampling rate */ + delta = 1; + if ( output_frame == L_FRAME16k ) + { + delta = 2; + } + else if ( output_frame == L_FRAME32k ) + { + delta = 4; + } + else if ( output_frame == L_FRAME48k ) + { + delta = 6; + } - /* Overlap between TCX-LB and TCX-FB*/ - tmpDelta = NS2SA(st->output_Fs, DELAY_BWE_TOTAL_NS); - for (i = 0; i < tmpDelta; i++) - { - synth[i + delay_comp] = (synth[i + delay_comp] * i + (tmpDelta - i) * st->previoussynth[i + delay_comp]) / tmpDelta; - } + /* set delay compensation between HQ synthesis and ACELP synthesis */ + delay_comp = delta * HQ_DELAY_COMP; - if ((st->element_mode == IVAS_CPE_MDCT || (ivas_format == ISM_FORMAT && st->core == TCX_20_CORE /* <- means TCX in general, TCX10 is forbidden after ACELP */)) && st->last_core_brate <= SID_2k40 && st->core_brate > SID_2k40) + /* Core switching done in DFT domain afterward*/ + if ( ( st->element_mode != IVAS_CPE_DFT || use_cldfb_for_dft ) && ( !sba_dirac_stereo_flag || ( sba_dirac_stereo_flag && st->core_brate == SID_2k40 && st->cng_type == FD_CNG ) ) ) + { + if ( st->core == HQ_CORE || st->core == TCX_20_CORE || st->core == TCX_10_CORE || ( st->core == ACELP_CORE && st->bfi == 1 && st->con_tcx == 1 ) ) { - /* smooth transitions to avoid pops in car noise items */ - smoothTransitionDtxToTcx(synth, output_frame, delay_comp); - } + st->use_acelp_preq = 0; + if ( st->hBWE_FD != NULL ) + { + st->hBWE_FD->mem_deemph_old_syn = 0.0f; + } - /* Reset memories of CLDFBs */ - if (st->cldfbAna != NULL) - { - if (st->cldfbAna->no_channels * st->cldfbAna->no_col != st->L_frame) - { - configureCldfb_ivas(st->cldfbAna, st->L_frame * FRAMES_PER_SEC); - configureCldfb_ivas(st->cldfbBPF, min(16000, st->L_frame * FRAMES_PER_SEC)); - } + if ( st->element_mode == EVS_MONO && st->core == HQ_CORE ) /* ACELP->HQ-CORE */ + { + if ( core_switching_flag && st->last_L_frame == st->last_L_frame_ori && ( st->last_core == ACELP_CORE || st->last_core == AMR_WB_CORE ) ) + { + if ( ( error = acelp_core_switch_dec( st, synth_subfr_out, synth_subfr_bwe, output_frame, core_switching_flag, mem_synth, nchan_out ) ) != IVAS_ERR_OK ) + { + return error; + } + } - cldfb_reset_memory_ivas(st->cldfbAna); - cldfb_reset_memory_ivas(st->cldfbBPF); - } - cldfb_reset_memory_ivas(st->cldfbSyn); + if ( core_switching_flag && st->last_core == HQ_CORE && st->prev_bfi ) + { + mvr2r( st->delay_buf_out, synth_subfr_out, delay_comp ); + } + } - /* Update memories for CLDFB ana for eventual next ACELP frame */ - if (st->cldfbAna != NULL) - { - delta = st->cldfbAna->no_channels; - offset = st->cldfbAna->p_filter_length - st->cldfbAna->no_channels; - for (i = 0; i < delta; i++) - { - st->cldfbAna->cldfb_state[offset - delta + i] = - output[st->L_frame - delta + i] * ((float)(i + 1)) / ((float)delta); - } - } - } - else if (st->element_mode != EVS_MONO) - { - /* Reset memories of CLDFBs */ - if (st->cldfbAna != NULL) - { - if (st->cldfbAna->no_channels * st->cldfbAna->no_col != st->L_frame) - { - configureCldfb_ivas(st->cldfbAna, st->L_frame * FRAMES_PER_SEC); - configureCldfb_ivas(st->cldfbBPF, min(16000, st->L_frame * FRAMES_PER_SEC)); - } + /* delay HQ synthesis to synchronize with ACELP synthesis */ + delay_signal_float( synth, output_frame, st->delay_buf_out, delay_comp ); - cldfb_reset_memory_ivas(st->cldfbAna); - cldfb_reset_memory_ivas(st->cldfbBPF); - } + if ( st->element_mode == EVS_MONO && st->core == HQ_CORE ) /* ACELP->HQ-CORE */ + { + if ( core_switching_flag && st->last_L_frame == st->last_L_frame_ori && ( st->last_core == ACELP_CORE || st->last_core == AMR_WB_CORE ) ) + { + core_switching_OLA( mem_synth, st->last_L_frame, st->output_Fs, synth, synth_subfr_out, synth_subfr_bwe, output_frame, st->bwidth ); + } + else if ( core_switching_flag && st->last_core == HQ_CORE && st->prev_bfi ) /* HQ | ACELP | TRANSITION with ACELP frame lost */ + { + /* Overlap between old->out[] (stocked in st->fer_samples[]) and good HQ frame on L/2 */ + nZeros = (int16_t) ( NS2SA( st->output_Fs, N_ZERO_MDCT_NS ) ); + tmpDelta = 1.0f / (float) ( output_frame >> 1 ); + for ( i = 0; i < ( output_frame >> 1 ); i++ ) + { + tmpF = (float) i * tmpDelta; + synth[i + delay_comp] = ( 1 - tmpF ) * st->hHQ_core->fer_samples[i + nZeros] + synth[i + delay_comp] * tmpF; + } + } + else if ( ( !core_switching_flag && st->core == HQ_CORE && ( st->last_core == ACELP_CORE || st->last_core == AMR_WB_CORE ) ) || /* ACELP | TRANSITION | HQ with TRANSITION lost */ + ( core_switching_flag && st->prev_bfi && st->last_L_frame != st->last_L_frame_ori ) ) /* ACELP@12k8 | ACELP@16k | TRANSITION with ACELP@16k lost */ + { + /* Overlap between CELP estimation (BFI) and good HQ frame on L/2 */ + tmpDelta = 1.0f / (float) ( output_frame >> 1 ); + for ( i = 0; i < ( output_frame >> 1 ); i++ ) + { + tmpF = (float) i * tmpDelta; + synth[i] = synth[i] * tmpF + ( 1 - tmpF ) * st->hHQ_core->fer_samples[i]; + } + } + } + else if ( ( ( st->last_core == ACELP_CORE || st->last_core_bfi == ACELP_CORE ) && !( st->prev_bfi == 1 && st->last_con_tcx == 1 ) ) || st->last_core == AMR_WB_CORE ) /*ACELP->TCX/HQ*/ + { + /* if this is first active MDCT-Stereo frame after a CNG frame and output format is mono DMX, this should only be done for the zero-th channel, the other one will simply be copied over after this function */ + if ( ( ( st->last_core_brate != SID_2k40 && st->last_core_brate != FRAME_NO_DATA ) || ( st->element_mode != IVAS_CPE_DFT && st->element_mode != IVAS_CPE_TD ) || nchan_out == 1 ) && !( st->element_mode == IVAS_CPE_MDCT && st->idchan == 1 && ( nchan_out == 1 || last_element_mode == IVAS_CPE_DFT ) ) ) + { + core_switch_lb_upsamp( st, output ); + } - if (st->cldfbSyn != NULL) - { - cldfb_reset_memory_ivas(st->cldfbSyn); - } + mvr2r( st->previoussynth, synth, delay_comp ); - /* Update memories for CLDFB ana for eventual next ACELP frame */ - /* Analysis CLDF memory is fed with ramped signal for last slot */ - if (st->cldfbAna != NULL) - { - delta = st->cldfbAna->no_channels; - offset = st->cldfbAna->p_filter_length - st->cldfbAna->no_channels; - for (i = 0; i < delta; i++) - { - st->cldfbAna->cldfb_state[offset - delta + i] = - output[st->L_frame - delta + i] * ((float)(i + 1)) / ((float)delta); - } - } - } + /* Overlap between TCX-LB and TCX-FB*/ + tmpDelta = NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS ); + for ( i = 0; i < tmpDelta; i++ ) + { + synth[i + delay_comp] = ( synth[i + delay_comp] * i + ( tmpDelta - i ) * st->previoussynth[i + delay_comp] ) / tmpDelta; + } + + if ( ( st->element_mode == IVAS_CPE_MDCT || ( ivas_format == ISM_FORMAT && st->core == TCX_20_CORE /* <- means TCX in general, TCX10 is forbidden after ACELP */ ) ) && st->last_core_brate <= SID_2k40 && st->core_brate > SID_2k40 ) + { + /* smooth transitions to avoid pops in car noise items */ + smoothTransitionDtxToTcx( synth, output_frame, delay_comp ); + } - if (st->hBWE_TD != NULL) - { - st->hBWE_TD->bwe_non_lin_prev_scale = 0.0; - } + /* Reset memories of CLDFBs */ + if ( st->cldfbAna != NULL ) + { + if ( st->cldfbAna->no_channels * st->cldfbAna->no_col != st->L_frame ) + { + configureCldfb_ivas( st->cldfbAna, st->L_frame * FRAMES_PER_SEC ); + configureCldfb_ivas( st->cldfbBPF, min( 16000, st->L_frame * FRAMES_PER_SEC ) ); + } - if (st->hHQ_core != NULL && !(inner_frame_tbl[st->bwidth] == L_FRAME16k && st->core_brate <= HQ_32k)) - { - set_f(st->hHQ_core->prev_env, 0, SFM_N_WB); - set_f(st->hHQ_core->prev_normq, 0, SFM_N_WB); - } + cldfb_reset_memory_ivas( st->cldfbAna ); + cldfb_reset_memory_ivas( st->cldfbBPF ); + } + cldfb_reset_memory_ivas( st->cldfbSyn ); - mvr2r(synth, st->previoussynth, output_frame); + /* Update memories for CLDFB ana for eventual next ACELP frame */ + if ( st->cldfbAna != NULL ) + { + delta = st->cldfbAna->no_channels; + offset = st->cldfbAna->p_filter_length - st->cldfbAna->no_channels; + for ( i = 0; i < delta; i++ ) + { + st->cldfbAna->cldfb_state[offset - delta + i] = + output[st->L_frame - delta + i] * ( (float) ( i + 1 ) ) / ( (float) delta ); + } + } + } + else if ( st->element_mode != EVS_MONO ) + { + /* Reset memories of CLDFBs */ + if ( st->cldfbAna != NULL ) + { + if ( st->cldfbAna->no_channels * st->cldfbAna->no_col != st->L_frame ) + { + configureCldfb_ivas( st->cldfbAna, st->L_frame * FRAMES_PER_SEC ); + configureCldfb_ivas( st->cldfbBPF, min( 16000, st->L_frame * FRAMES_PER_SEC ) ); + } - /*Set post-filtering flag to zero*/ - if (st->hBPF != NULL) - { - st->hPFstat->on = 0; - } -} - else - { - /* MDCT to ACELP transition */ - if (st->last_core == HQ_CORE || st->last_core == TCX_20_CORE || st->last_core == TCX_10_CORE) - { - nZeros = (int16_t)(NS2SA(st->output_Fs, N_ZERO_MDCT_NS)); - mvr2r(st->delay_buf_out, synth, delay_comp); /* copy the HQ/ACELP delay synchronization buffer at the beginning of ACELP frame */ + cldfb_reset_memory_ivas( st->cldfbAna ); + cldfb_reset_memory_ivas( st->cldfbBPF ); + } - if (st->prev_bfi && st->hHQ_core != NULL && st->hHQ_core->HqVoicing && st->last_core == HQ_CORE) - { - mvr2r(st->hHQ_core->fer_samples, st->hHQ_core->old_out + nZeros, NS2SA(st->output_Fs, 3000000)); - } + if ( st->cldfbSyn != NULL ) + { + cldfb_reset_memory_ivas( st->cldfbSyn ); + } - tmpF = 1.0f / (float)NS2SA(st->output_Fs, 3000000); + /* Update memories for CLDFB ana for eventual next ACELP frame */ + /* Analysis CLDF memory is fed with ramped signal for last slot */ + if ( st->cldfbAna != NULL ) + { + delta = st->cldfbAna->no_channels; + offset = st->cldfbAna->p_filter_length - st->cldfbAna->no_channels; + for ( i = 0; i < delta; i++ ) + { + st->cldfbAna->cldfb_state[offset - delta + i] = + output[st->L_frame - delta + i] * ( (float) ( i + 1 ) ) / ( (float) delta ); + } + } + } - if (st->element_mode == IVAS_CPE_TD && st->hHQ_core == NULL) - { - for (i = 0; i < NS2SA(st->output_Fs, 3000000); i++) - { - synth[i + delay_comp] = (1 - tmpF * (float)i) * output_mem[i] + tmpF * (float)i * synth[i + delay_comp]; - } - } - else if (st->element_mode == IVAS_CPE_MDCT && st->core_brate <= SID_2k40 && st->prev_bfi) - { - for (i = 0; i < NS2SA(st->output_Fs, 3000000); i++) - { - synth[i + delay_comp] = (1 - tmpF * (float)i) * st->hHQ_core->old_out[i + nZeros] * st->hTcxDec->conceal_eof_gain_float + tmpF * (float)i * synth[i + delay_comp]; - } + if ( st->hBWE_TD != NULL ) + { + st->hBWE_TD->bwe_non_lin_prev_scale = 0.0; + } + + if ( st->hHQ_core != NULL && !( inner_frame_tbl[st->bwidth] == L_FRAME16k && st->core_brate <= HQ_32k ) ) + { + set_f( st->hHQ_core->prev_env, 0, SFM_N_WB ); + set_f( st->hHQ_core->prev_normq, 0, SFM_N_WB ); + } + + mvr2r( synth, st->previoussynth, output_frame ); + + /*Set post-filtering flag to zero*/ + if ( st->hBPF != NULL ) + { + st->hPFstat->on = 0; + } } else { - for (i = 0; i < NS2SA(st->output_Fs, 3000000); i++) - { - synth[i + delay_comp] = (1 - tmpF * (float)i) * st->hHQ_core->old_out[i + nZeros] + tmpF * (float)i * synth[i + delay_comp]; - } - } - } + /* MDCT to ACELP transition */ + if ( st->last_core == HQ_CORE || st->last_core == TCX_20_CORE || st->last_core == TCX_10_CORE ) + { + nZeros = (int16_t) ( NS2SA( st->output_Fs, N_ZERO_MDCT_NS ) ); + mvr2r( st->delay_buf_out, synth, delay_comp ); /* copy the HQ/ACELP delay synchronization buffer at the beginning of ACELP frame */ - set_f(st->delay_buf_out, 0, HQ_DELTA_MAX * HQ_DELAY_COMP); - if (st->hHQ_core != NULL) - { - st->hHQ_core->oldHqVoicing = 0; - } - } - } - else - { - /* memory update needed for DFT stereo -> TD stereo switching */ - mvr2r(synth + output_frame - delay_comp, st->delay_buf_out, delay_comp); - } + if ( st->prev_bfi && st->hHQ_core != NULL && st->hHQ_core->HqVoicing && st->last_core == HQ_CORE ) + { + mvr2r( st->hHQ_core->fer_samples, st->hHQ_core->old_out + nZeros, NS2SA( st->output_Fs, 3000000 ) ); + } - /* reset SWB BWE buffers */ - if (st->bws_cnt == 0 || (st->bws_cnt > 0 && st->coder_type != INACTIVE && st->coder_type != AUDIO)) - { - st->attenu1 = 0.1f; - } + tmpF = 1.0f / (float) NS2SA( st->output_Fs, 3000000 ); - if (st->hBWE_FD != NULL && - ((st->last_extl != SWB_BWE && st->extl == SWB_BWE) || (st->last_extl != FB_BWE && st->extl == FB_BWE) || - ((st->last_core == HQ_CORE || st->last_core == TCX_20_CORE || st->last_core == TCX_10_CORE || st->last_extl == SWB_TBE) && st->extl < 0 && st->core == ACELP_CORE) || (st->last_core == ACELP_CORE && st->core == ACELP_CORE && ((st->prev_coder_type != INACTIVE && st->coder_type != INACTIVE) || (st->prev_coder_type != AUDIO && st->coder_type == AUDIO)) && st->bws_cnt > 0))) - { - set_f(st->hBWE_FD->old_wtda_swb, 0, output_frame); + if ( st->element_mode == IVAS_CPE_TD && st->hHQ_core == NULL ) + { + for ( i = 0; i < NS2SA( st->output_Fs, 3000000 ); i++ ) + { + synth[i + delay_comp] = ( 1 - tmpF * (float) i ) * output_mem[i] + tmpF * (float) i * synth[i + delay_comp]; + } + } + else if ( st->element_mode == IVAS_CPE_MDCT && st->core_brate <= SID_2k40 && st->prev_bfi ) + { + for ( i = 0; i < NS2SA( st->output_Fs, 3000000 ); i++ ) + { + synth[i + delay_comp] = ( 1 - tmpF * (float) i ) * st->hHQ_core->old_out[i + nZeros] * st->hTcxDec->conceal_eof_gain_float + tmpF * (float) i * synth[i + delay_comp]; + } + } + else + { + for ( i = 0; i < NS2SA( st->output_Fs, 3000000 ); i++ ) + { + synth[i + delay_comp] = ( 1 - tmpF * (float) i ) * st->hHQ_core->old_out[i + nZeros] + tmpF * (float) i * synth[i + delay_comp]; + } + } + } - if (st->last_extl != WB_BWE) + set_f( st->delay_buf_out, 0, HQ_DELTA_MAX * HQ_DELAY_COMP ); + if ( st->hHQ_core != NULL ) + { + st->hHQ_core->oldHqVoicing = 0; + } + } + } + else { - st->hBWE_FD->prev_mode = NORMAL; + /* memory update needed for DFT stereo -> TD stereo switching */ + mvr2r( synth + output_frame - delay_comp, st->delay_buf_out, delay_comp ); } - st->hBWE_FD->prev_Energy = 0.0f; - st->hBWE_FD->prev_L_swb_norm = 8; - st->hBWE_FD->prev_frica_flag = 0; - set_f(st->hBWE_FD->mem_imdct, 0, L_FRAME48k); - st->hBWE_FD->prev_td_energy = 0.0f; - st->hBWE_FD->prev_weight = 0.2f; - st->hBWE_FD->prev_fb_ener_adjust = 0.0f; - } - - /* reset WB BWE buffers */ - if (st->last_extl != WB_BWE && st->extl == WB_BWE && st->hBWE_FD != NULL) - { - set_f(st->hBWE_FD->old_wtda_swb, 0, output_frame); - - if (st->last_extl != SWB_BWE && st->last_extl != FB_BWE) + /* reset SWB BWE buffers */ + if ( st->bws_cnt == 0 || ( st->bws_cnt > 0 && st->coder_type != INACTIVE && st->coder_type != AUDIO ) ) { - st->hBWE_FD->prev_mode = NORMAL; + st->attenu1 = 0.1f; } - st->hBWE_FD->prev_Energy_wb = 0.0f; - st->hBWE_FD->prev_L_swb_norm = 8; - set_f(st->hBWE_FD->mem_imdct, 0, L_FRAME48k); - st->hBWE_FD->prev_flag = 0; - } - - /* reset TBE buffers */ - if (st->hBWE_TD != NULL) - { - /* reset SWB TBE buffers */ - if (((st->extl == SWB_TBE || st->extl == FB_TBE || st->extl == SWB_CNG) && - (st->L_frame != st->last_L_frame || (st->last_extl != SWB_TBE && st->last_extl != FB_TBE && st->last_core != TCX_20_CORE && st->last_core != TCX_10_CORE) || st->last_core == HQ_CORE)) || - (st->bwidth < st->last_bwidth && st->last_extl != SWB_TBE) || st->old_ppp_mode || ((st->prev_coder_type == AUDIO || st->prev_coder_type == INACTIVE) && st->bws_cnt > 0) || (st->bws_cnt == 0 && st->prev_bws_cnt == N_WS2N_FRAMES)) + if ( st->hBWE_FD != NULL && + ( ( st->last_extl != SWB_BWE && st->extl == SWB_BWE ) || ( st->last_extl != FB_BWE && st->extl == FB_BWE ) || + ( ( st->last_core == HQ_CORE || st->last_core == TCX_20_CORE || st->last_core == TCX_10_CORE || st->last_extl == SWB_TBE ) && st->extl < 0 && st->core == ACELP_CORE ) || ( st->last_core == ACELP_CORE && st->core == ACELP_CORE && ( ( st->prev_coder_type != INACTIVE && st->coder_type != INACTIVE ) || ( st->prev_coder_type != AUDIO && st->coder_type == AUDIO ) ) && st->bws_cnt > 0 ) ) ) { - swb_tbe_reset(st->hBWE_TD->mem_csfilt, st->hBWE_TD->mem_genSHBexc_filt_down_shb, st->hBWE_TD->state_lpc_syn, st->hBWE_TD->syn_overlap, st->hBWE_TD->state_syn_shbexc, &(st->hBWE_TD->tbe_demph), &(st->hBWE_TD->tbe_premph), st->hBWE_TD->mem_stp_swb, &(st->hBWE_TD->gain_prec_swb)); - - /* reset GainShape delay for SWB TBE FEC */ - set_f(st->hBWE_TD->GainShape_Delay, 0, NUM_SHB_SUBFR / 2); - - swb_tbe_reset_synth(st->hBWE_TD->genSHBsynth_Hilbert_Mem, st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local); + set_f( st->hBWE_FD->old_wtda_swb, 0, output_frame ); - if (output_frame == L_FRAME16k) - { - set_f(st->hBWE_TD->mem_resamp_HB_32k, 0, 2 * ALLPASSSECTIONS_STEEP + 1); /* reset in case that SWB TBE layer is transmitted, but the output is 16kHz sampled */ - } + if ( st->last_extl != WB_BWE ) + { + st->hBWE_FD->prev_mode = NORMAL; + } - set_f(st->hBWE_TD->int_3_over_2_tbemem_dec, 0.0f, INTERP_3_2_MEM_LEN); - st->hBWE_TD->prev_pow_exc16kWhtnd = 1.0f; - st->hBWE_TD->prev_mix_factor = 1.0f; - } - else if ((st->extl == SWB_TBE || st->extl == FB_TBE) && ((st->element_mode == IVAS_CPE_TD && st->last_extl != SWB_TBE && st->last_extl != FB_TBE) || (st->element_mode != IVAS_CPE_TD && st->last_total_brate != st->total_brate) || (st->last_bwidth != st->bwidth) || (st->last_codec_mode != MODE1) || (st->rf_flag != st->rf_flag_last))) - { - set_f(st->hBWE_TD->state_lpc_syn, 0.0f, LPC_SHB_ORDER); - set_f(st->hBWE_TD->state_syn_shbexc, 0.0f, L_SHB_LAHEAD); - set_f(st->hBWE_TD->mem_stp_swb, 0.0f, LPC_SHB_ORDER); - set_f(st->hBWE_TD->mem_zero_swb, 0, LPC_SHB_ORDER); - st->hBWE_TD->gain_prec_swb = 1.0f; - } - else if (st->hBWE_TD != NULL && (st->last_core == TCX_20_CORE || st->last_core == TCX_10_CORE)) - { - TBEreset_dec(st); + st->hBWE_FD->prev_Energy = 0.0f; + st->hBWE_FD->prev_L_swb_norm = 8; + st->hBWE_FD->prev_frica_flag = 0; + set_f( st->hBWE_FD->mem_imdct, 0, L_FRAME48k ); + st->hBWE_FD->prev_td_energy = 0.0f; + st->hBWE_FD->prev_weight = 0.2f; + st->hBWE_FD->prev_fb_ener_adjust = 0.0f; } - /* reset FB TBE buffers */ - if ((st->L_frame != st->last_L_frame || st->last_extl != FB_TBE) && st->extl == FB_TBE) + /* reset WB BWE buffers */ + if ( st->last_extl != WB_BWE && st->extl == WB_BWE && st->hBWE_FD != NULL ) { - set_f(st->hBWE_TD->fb_state_lpc_syn, 0, LPC_SHB_ORDER); - st->hBWE_TD->fb_tbe_demph = 0; - fb_tbe_reset_synth(st->hBWE_TD->fbbwe_hpf_mem, &st->hBWE_TD->prev_fbbwe_ratio); + set_f( st->hBWE_FD->old_wtda_swb, 0, output_frame ); + + if ( st->last_extl != SWB_BWE && st->last_extl != FB_BWE ) + { + st->hBWE_FD->prev_mode = NORMAL; + } + + st->hBWE_FD->prev_Energy_wb = 0.0f; + st->hBWE_FD->prev_L_swb_norm = 8; + set_f( st->hBWE_FD->mem_imdct, 0, L_FRAME48k ); + st->hBWE_FD->prev_flag = 0; } - /* reset WB TBE buffers */ - if (st->last_extl != WB_TBE && st->extl == WB_TBE && st->last_core != TCX_20_CORE && st->last_core != TCX_10_CORE) + /* reset TBE buffers */ + if ( st->hBWE_TD != NULL ) { - wb_tbe_extras_reset(st->hBWE_TD->mem_genSHBexc_filt_down_wb2, st->hBWE_TD->mem_genSHBexc_filt_down_wb3); - wb_tbe_extras_reset_synth(st->hBWE_TD->state_lsyn_filt_shb, st->hBWE_TD->state_lsyn_filt_dwn_shb, st->hBWE_TD->mem_resamp_HB); + /* reset SWB TBE buffers */ + if ( ( ( st->extl == SWB_TBE || st->extl == FB_TBE || st->extl == SWB_CNG ) && + ( st->L_frame != st->last_L_frame || ( st->last_extl != SWB_TBE && st->last_extl != FB_TBE && st->last_core != TCX_20_CORE && st->last_core != TCX_10_CORE ) || st->last_core == HQ_CORE ) ) || + ( st->bwidth < st->last_bwidth && st->last_extl != SWB_TBE ) || st->old_ppp_mode || ( ( st->prev_coder_type == AUDIO || st->prev_coder_type == INACTIVE ) && st->bws_cnt > 0 ) || ( st->bws_cnt == 0 && st->prev_bws_cnt == N_WS2N_FRAMES ) ) + { + swb_tbe_reset( st->hBWE_TD->mem_csfilt, st->hBWE_TD->mem_genSHBexc_filt_down_shb, st->hBWE_TD->state_lpc_syn, st->hBWE_TD->syn_overlap, st->hBWE_TD->state_syn_shbexc, &( st->hBWE_TD->tbe_demph ), &( st->hBWE_TD->tbe_premph ), st->hBWE_TD->mem_stp_swb, &( st->hBWE_TD->gain_prec_swb ) ); + + /* reset GainShape delay for SWB TBE FEC */ + set_f( st->hBWE_TD->GainShape_Delay, 0, NUM_SHB_SUBFR / 2 ); + + swb_tbe_reset_synth( st->hBWE_TD->genSHBsynth_Hilbert_Mem, st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local ); + + if ( output_frame == L_FRAME16k ) + { + set_f( st->hBWE_TD->mem_resamp_HB_32k, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); /* reset in case that SWB TBE layer is transmitted, but the output is 16kHz sampled */ + } + + set_f( st->hBWE_TD->int_3_over_2_tbemem_dec, 0.0f, INTERP_3_2_MEM_LEN ); + st->hBWE_TD->prev_pow_exc16kWhtnd = 1.0f; + st->hBWE_TD->prev_mix_factor = 1.0f; + } + else if ( ( st->extl == SWB_TBE || st->extl == FB_TBE ) && ( ( st->element_mode == IVAS_CPE_TD && st->last_extl != SWB_TBE && st->last_extl != FB_TBE ) || ( st->element_mode != IVAS_CPE_TD && st->last_total_brate != st->total_brate ) || ( st->last_bwidth != st->bwidth ) || ( st->last_codec_mode != MODE1 ) || ( st->rf_flag != st->rf_flag_last ) ) ) + { + set_f( st->hBWE_TD->state_lpc_syn, 0.0f, LPC_SHB_ORDER ); + set_f( st->hBWE_TD->state_syn_shbexc, 0.0f, L_SHB_LAHEAD ); + set_f( st->hBWE_TD->mem_stp_swb, 0.0f, LPC_SHB_ORDER ); + set_f( st->hBWE_TD->mem_zero_swb, 0, LPC_SHB_ORDER ); + st->hBWE_TD->gain_prec_swb = 1.0f; + } + else if ( st->hBWE_TD != NULL && ( st->last_core == TCX_20_CORE || st->last_core == TCX_10_CORE ) ) + { + TBEreset_dec( st ); + } + + /* reset FB TBE buffers */ + if ( ( st->L_frame != st->last_L_frame || st->last_extl != FB_TBE ) && st->extl == FB_TBE ) + { + set_f( st->hBWE_TD->fb_state_lpc_syn, 0, LPC_SHB_ORDER ); + st->hBWE_TD->fb_tbe_demph = 0; + fb_tbe_reset_synth( st->hBWE_TD->fbbwe_hpf_mem, &st->hBWE_TD->prev_fbbwe_ratio ); + } - set_f(st->hBWE_TD->state_syn_shbexc, 0, L_SHB_LAHEAD / 4); - set_f(st->hBWE_TD->syn_overlap, 0, L_SHB_LAHEAD); - set_f(st->hBWE_TD->mem_csfilt, 0, 2); + /* reset WB TBE buffers */ + if ( st->last_extl != WB_TBE && st->extl == WB_TBE && st->last_core != TCX_20_CORE && st->last_core != TCX_10_CORE ) + { + wb_tbe_extras_reset( st->hBWE_TD->mem_genSHBexc_filt_down_wb2, st->hBWE_TD->mem_genSHBexc_filt_down_wb3 ); + wb_tbe_extras_reset_synth( st->hBWE_TD->state_lsyn_filt_shb, st->hBWE_TD->state_lsyn_filt_dwn_shb, st->hBWE_TD->mem_resamp_HB ); + + set_f( st->hBWE_TD->state_syn_shbexc, 0, L_SHB_LAHEAD / 4 ); + set_f( st->hBWE_TD->syn_overlap, 0, L_SHB_LAHEAD ); + set_f( st->hBWE_TD->mem_csfilt, 0, 2 ); + } } - } - /* Interp_3_2 CNG buffers reset */ - if (st->hTdCngDec != NULL && st->output_Fs == 48000 && (st->last_core_brate > SID_2k40) && (st->core_brate == FRAME_NO_DATA || st->core_brate == SID_2k40) && st->hTdCngDec != NULL) - { - set_f(st->hTdCngDec->interpol_3_2_cng_dec, 0.0f, INTERP_3_2_MEM_LEN); - } + /* Interp_3_2 CNG buffers reset */ + if ( st->hTdCngDec != NULL && st->output_Fs == 48000 && ( st->last_core_brate > SID_2k40 ) && ( st->core_brate == FRAME_NO_DATA || st->core_brate == SID_2k40 ) && st->hTdCngDec != NULL ) + { + set_f( st->hTdCngDec->interpol_3_2_cng_dec, 0.0f, INTERP_3_2_MEM_LEN ); + } - return error; + return error; } #endif @@ -1679,16 +1679,18 @@ void bandwidth_switching_detect( } #else void bandwidth_switching_detect_ivas_fx( - Decoder_State *st_fx /* i/o: encoder state structure */ + Decoder_State *st_fx /* i/o: encoder state structure */ ) { - IF ((EQ_16(st_fx->element_mode, IVAS_CPE_TD) && EQ_16(st_fx->idchan, 1) ) || EQ_16(st_fx->element_mode, IVAS_CPE_MDCT)) + IF( ( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && EQ_16( st_fx->idchan, 1 ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) { /* there is no BWE in TD stereo secondary channel and in MDCT stereo, IGF is part of the core decoding -> no BW switching -> reset BWS counters */ st_fx->prev_bws_cnt = 0; st_fx->bws_cnt = 0; st_fx->bws_cnt1 = 0; - move16(); move16(); move16(); + move16(); + move16(); + move16(); return; } @@ -1696,22 +1698,21 @@ void bandwidth_switching_detect_ivas_fx( test(); test(); test(); - IF( GE_16(st_fx->bws_cnt1, N_NS2W_FRAMES)) + IF( GE_16( st_fx->bws_cnt1, N_NS2W_FRAMES ) ) { st_fx->bws_cnt1 = 0; move16(); } - ELSE IF( GT_32(st_fx->total_brate, ACELP_9k60)&<_32(st_fx->last_core_brate,ACELP_9k60) - && EQ_16(st_fx->bwidth, SWB) && EQ_16(st_fx->last_bwidth, WB) && EQ_16(st_fx->last_low_rate_mode , 0)) + ELSE IF( GT_32( st_fx->total_brate, ACELP_9k60 ) && LT_32( st_fx->last_core_brate, ACELP_9k60 ) && EQ_16( st_fx->bwidth, SWB ) && EQ_16( st_fx->last_bwidth, WB ) && EQ_16( st_fx->last_low_rate_mode, 0 ) ) { - st_fx->bws_cnt1 = add(st_fx->bws_cnt1,1); + st_fx->bws_cnt1 = add( st_fx->bws_cnt1, 1 ); move16(); } ELSE IF( st_fx->bws_cnt1 > 0 ) { - IF( LT_16(st_fx->bwidth, st_fx->last_bwidth)) + IF( LT_16( st_fx->bwidth, st_fx->last_bwidth ) ) { - st_fx->bws_cnt = sub( shl(sub(N_NS2W_FRAMES, st_fx->bws_cnt1), 1), 1 ); + st_fx->bws_cnt = sub( shl( sub( N_NS2W_FRAMES, st_fx->bws_cnt1 ), 1 ), 1 ); move16(); } ELSE @@ -1720,16 +1721,16 @@ void bandwidth_switching_detect_ivas_fx( move16(); } - IF( LT_16(st_fx->bwidth, st_fx->last_bwidth)) + IF( LT_16( st_fx->bwidth, st_fx->last_bwidth ) ) { st_fx->bws_cnt1 = 0; move16(); } ELSE { - IF(EQ_16(st_fx->bwidth, SWB)) + IF( EQ_16( st_fx->bwidth, SWB ) ) { - st_fx->bws_cnt1 = add(st_fx->bws_cnt1,1); + st_fx->bws_cnt1 = add( st_fx->bws_cnt1, 1 ); move16(); } ELSE @@ -1744,22 +1745,21 @@ void bandwidth_switching_detect_ivas_fx( test(); test(); test(); - IF( GE_16(st_fx->bws_cnt, N_WS2N_FRAMES)) + IF( GE_16( st_fx->bws_cnt, N_WS2N_FRAMES ) ) { st_fx->bws_cnt = 0; move16(); } - ELSE IF( LT_32(st_fx->total_brate, ACELP_9k60)&>_32(st_fx->last_core_brate,ACELP_9k60) - && LT_16(st_fx->bwidth, st_fx->last_bwidth) && EQ_16(st_fx->bwidth, WB) ) + ELSE IF( LT_32( st_fx->total_brate, ACELP_9k60 ) && GT_32( st_fx->last_core_brate, ACELP_9k60 ) && LT_16( st_fx->bwidth, st_fx->last_bwidth ) && EQ_16( st_fx->bwidth, WB ) ) { - st_fx->bws_cnt = add(st_fx->bws_cnt,1); + st_fx->bws_cnt = add( st_fx->bws_cnt, 1 ); move16(); } ELSE IF( st_fx->bws_cnt > 0 ) { - IF( GT_16(st_fx->bwidth, st_fx->last_bwidth)) + IF( GT_16( st_fx->bwidth, st_fx->last_bwidth ) ) { - st_fx->bws_cnt1 = shr(sub(N_WS2N_FRAMES, st_fx->bws_cnt), 1); + st_fx->bws_cnt1 = shr( sub( N_WS2N_FRAMES, st_fx->bws_cnt ), 1 ); move16(); } ELSE @@ -1768,16 +1768,16 @@ void bandwidth_switching_detect_ivas_fx( move16(); } - IF( GT_16(st_fx->bwidth, st_fx->last_bwidth)) + IF( GT_16( st_fx->bwidth, st_fx->last_bwidth ) ) { st_fx->bws_cnt = 0; move16(); } ELSE { - IF( EQ_16(st_fx->bwidth, WB)) + IF( EQ_16( st_fx->bwidth, WB ) ) { - st_fx->bws_cnt = add(st_fx->bws_cnt,1); + st_fx->bws_cnt = add( st_fx->bws_cnt, 1 ); move16(); } ELSE @@ -1906,23 +1906,22 @@ void bw_switching_pre_proc( #endif #ifdef IVAS_FLOAT_FIXED void ivas_bw_switching_pre_proc_fx( - Decoder_State *st, /* i/o: decoder state structure */ + Decoder_State *st, /* i/o: decoder state structure */ const Word32 last_element_brate, /* i : last element bitrate */ - const Word16 nchan_out /* i : number of output channels */, + const Word16 nchan_out /* i : number of output channels */, Word32 *old_syn_12k8_16k_fx, Word16 Q, - Word16 Q_audio -) + Word16 Q_audio ) { Word16 i; Word32 syn_dct_fx[L_FRAME]; - - + + Flag Overflow = 0; - - IF ( GT_16( st->element_mode, EVS_MONO ) ) + + IF( GT_16( st->element_mode, EVS_MONO ) ) { - IF ( EQ_16( st->core, ACELP_CORE ) && !( EQ_16( st->bfi, 1 ) && EQ_16( st->con_tcx, 1 ) ) && st->hBWE_FD != NULL && !( LE_32( st->core_brate, SID_2k40 ) && EQ_16( st->element_mode, IVAS_CPE_DFT ) && EQ_16( nchan_out, 2 ) ) && !( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( nchan_out, 1 ) && EQ_16( st->idchan, 1 ) && LE_32( last_element_brate, IVAS_SID_5k2 ) ) ) + IF( EQ_16( st->core, ACELP_CORE ) && !( EQ_16( st->bfi, 1 ) && EQ_16( st->con_tcx, 1 ) ) && st->hBWE_FD != NULL && !( LE_32( st->core_brate, SID_2k40 ) && EQ_16( st->element_mode, IVAS_CPE_DFT ) && EQ_16( nchan_out, 2 ) ) && !( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( nchan_out, 1 ) && EQ_16( st->idchan, 1 ) && LE_32( last_element_brate, IVAS_SID_5k2 ) ) ) { /* Calculate tilt of the ACELP core synthesis - needed in SWB BWE decoding */ Word16 old_syn_12k8_16k_tmp_16fx[L_FRAME16k]; @@ -1933,70 +1932,69 @@ void ivas_bw_switching_pre_proc_fx( return; } - IF ( EQ_16( st->core, ACELP_CORE ) && !( EQ_16( st->bfi, 1 ) && EQ_16( st->con_tcx, 1 ) ) ) + IF( EQ_16( st->core, ACELP_CORE ) && !( EQ_16( st->bfi, 1 ) && EQ_16( st->con_tcx, 1 ) ) ) { /*----------------------------------------------------------------------* * Calculate tilt of the ACELP core synthesis *----------------------------------------------------------------------*/ - st->tilt_wb_fx = ivas_calc_tilt_bwe_fx( old_syn_12k8_16k_fx, Q, st->L_frame ); + st->tilt_wb_fx = ivas_calc_tilt_bwe_fx( old_syn_12k8_16k_fx, Q, st->L_frame ); /*-------------------------------------------------------------------------------* * Calculate frequency energy of 0~3.2kHz and 3.2~6.4kHz the ACELP core synthesis *-------------------------------------------------------------------------------*/ - edct_fx(old_syn_12k8_16k_fx, syn_dct_fx, L_FRAME, &Q); + edct_fx( old_syn_12k8_16k_fx, syn_dct_fx, L_FRAME, &Q ); Word64 W_tmp = 0; Word32 tmp; Word16 shift; - FOR ( i = 0; i < L_FRAME / 2; i++ ) + FOR( i = 0; i < L_FRAME / 2; i++ ) { - W_tmp = W_add(W_tmp, W_shr( W_mult0_32_32( syn_dct_fx[i], syn_dct_fx[i]), Q) ); + W_tmp = W_add( W_tmp, W_shr( W_mult0_32_32( syn_dct_fx[i], syn_dct_fx[i] ), Q ) ); } - shift = W_norm(W_tmp); - W_tmp = W_shl(W_tmp, shift); - tmp = W_extract_h(W_tmp); - tmp = L_shr(tmp, 8); + shift = W_norm( W_tmp ); + W_tmp = W_shl( W_tmp, shift ); + tmp = W_extract_h( W_tmp ); + tmp = L_shr( tmp, 8 ); - tmp = getSqrtWord32(tmp); + tmp = getSqrtWord32( tmp ); st->enerLL_fx = tmp; - st->enerLL_fx_Q = (Q + shift - 32) / 2; + st->enerLL_fx_Q = ( Q + shift - 32 ) / 2; W_tmp = 0; - FOR ( ; i < L_FRAME; i++ ) + FOR( ; i < L_FRAME; i++ ) { - W_tmp = W_add(W_tmp, W_shr(W_mult0_32_32(syn_dct_fx[i], syn_dct_fx[i]), Q) ); + W_tmp = W_add( W_tmp, W_shr( W_mult0_32_32( syn_dct_fx[i], syn_dct_fx[i] ), Q ) ); } - shift = W_norm(W_tmp); - W_tmp = W_shl(W_tmp, shift); - tmp = W_extract_h(W_tmp); // Q = Q + shift - 32 - tmp = L_shr(tmp, 7); // divide by 128 - tmp = getSqrtWord32(tmp); + shift = W_norm( W_tmp ); + W_tmp = W_shl( W_tmp, shift ); + tmp = W_extract_h( W_tmp ); // Q = Q + shift - 32 + tmp = L_shr( tmp, 7 ); // divide by 128 + tmp = getSqrtWord32( tmp ); st->enerLH_fx = tmp; st->enerLH_fx_Q = ( Q + shift - 32 ) / 2; - } ELSE { - IF ( st->hHQ_core->old_is_transient[0] ) + IF( st->hHQ_core->old_is_transient[0] ) { Word32 tmp, L_tmp = 0; - FOR ( i = 0; i < 32; i++ ) + FOR( i = 0; i < 32; i++ ) { - L_tmp = L_mac0_o(L_tmp, st->t_audio_q_fx[i], st->t_audio_q_fx[i], &Overflow); + L_tmp = L_mac0_o( L_tmp, st->t_audio_q_fx[i], st->t_audio_q_fx[i], &Overflow ); } - tmp = L_shr(L_tmp, 5); // divide by 32 - tmp = getSqrtWord32(tmp); + tmp = L_shr( L_tmp, 5 ); // divide by 32 + tmp = getSqrtWord32( tmp ); st->enerLL_fx = tmp; st->enerLL_fx_Q = Q_audio; L_tmp = 0; - FOR ( ; i < 64; i++ ) + FOR( ; i < 64; i++ ) { - L_tmp = L_mac0_o(L_tmp, st->t_audio_q_fx[i], st->t_audio_q_fx[i], &Overflow); + L_tmp = L_mac0_o( L_tmp, st->t_audio_q_fx[i], st->t_audio_q_fx[i], &Overflow ); } - - tmp = L_shr(L_tmp, 5); // divide by 32 - tmp = getSqrtWord32(tmp); + + tmp = L_shr( L_tmp, 5 ); // divide by 32 + tmp = getSqrtWord32( tmp ); st->enerLH_fx = tmp; st->enerLH_fx_Q = Q_audio; } @@ -2004,44 +2002,44 @@ void ivas_bw_switching_pre_proc_fx( { Word32 tmp, L_tmp = 0; L_tmp = 0; - FOR ( i = 0; i < L_FRAME / 2; i++ ) + FOR( i = 0; i < L_FRAME / 2; i++ ) { - L_tmp = L_mac0_o(L_tmp, st->t_audio_q_fx[i], st->t_audio_q_fx[i], &Overflow); + L_tmp = L_mac0_o( L_tmp, st->t_audio_q_fx[i], st->t_audio_q_fx[i], &Overflow ); } - tmp = L_shr(L_tmp, 5); // divide by 32 - tmp = getSqrtWord32(tmp); + tmp = L_shr( L_tmp, 5 ); // divide by 32 + tmp = getSqrtWord32( tmp ); st->enerLL_fx = tmp; st->enerLL_fx_Q = Q_audio; L_tmp = 0; - FOR ( ; i < L_FRAME; i++ ) + FOR( ; i < L_FRAME; i++ ) { - L_tmp = L_mac0_o(L_tmp, st->t_audio_q_fx[i], st->t_audio_q_fx[i], &Overflow); + L_tmp = L_mac0_o( L_tmp, st->t_audio_q_fx[i], st->t_audio_q_fx[i], &Overflow ); } - tmp = L_shr(L_tmp, 5); // divide by 32 - tmp = getSqrtWord32(tmp); + tmp = L_shr( L_tmp, 5 ); // divide by 32 + tmp = getSqrtWord32( tmp ); st->enerLL_fx = tmp; st->enerLL_fx_Q = Q_audio; } } - IF ( EQ_16( st->last_bwidth, 0 ) && LE_16( st->extl, SWB_CNG ) ) + IF( EQ_16( st->last_bwidth, 0 ) && LE_16( st->extl, SWB_CNG ) ) { - //st->prev_ener_shb = 0.0f; + // st->prev_ener_shb = 0.0f; st->prev_ener_shb_fx = 0; IF( st->hBWE_FD != NULL ) { - //set_f( st->hBWE_FD->prev_SWB_fenv, 0, SWB_FENV ); + // set_f( st->hBWE_FD->prev_SWB_fenv, 0, SWB_FENV ); set_s( st->prev_SWB_fenv_fx, 0, SWB_FENV ); } } - ELSE IF ( ( ( EQ_16( st->core, ACELP_CORE ) && ( EQ_16( st->last_core, HQ_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) || EQ_16( st->last_core, TCX_20_CORE ) ) ) || ( EQ_16( st->core, st->last_core ) && NE_16( st->extl, st->last_extl ) ) ) && GE_16( st->last_bwidth, SWB ) ) + ELSE IF( ( ( EQ_16( st->core, ACELP_CORE ) && ( EQ_16( st->last_core, HQ_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) || EQ_16( st->last_core, TCX_20_CORE ) ) ) || ( EQ_16( st->core, st->last_core ) && NE_16( st->extl, st->last_extl ) ) ) && GE_16( st->last_bwidth, SWB ) ) { st->attenu_fx = 3277; } - IF ( EQ_16( st->last_core, HQ_CORE ) || ( EQ_16( st->last_core, ACELP_CORE ) && !( EQ_16( st->last_extl, WB_TBE ) || EQ_16( st->last_extl, SWB_TBE ) || EQ_16( st->last_extl, FB_TBE ) ) && GT_32( st->core_brate, ACELP_8k00 ) ) ) + IF( EQ_16( st->last_core, HQ_CORE ) || ( EQ_16( st->last_core, ACELP_CORE ) && !( EQ_16( st->last_extl, WB_TBE ) || EQ_16( st->last_extl, SWB_TBE ) || EQ_16( st->last_extl, FB_TBE ) ) && GT_32( st->core_brate, ACELP_8k00 ) ) ) { st->prev_fractive = 0; st->prev_fractive = 0; @@ -2096,7 +2094,7 @@ static void core_switch_lb_upsamp( cldfbAnalysis_ivas( output, realBuffer, imagBuffer, CLDFB_OVRLP_MIN_SLOTS * st->cldfbAna->no_channels, st->cldfbAna ); /* analysis and add the BPF error signal */ - if ( st->p_bpf_noise_buf_float) + if ( st->p_bpf_noise_buf_float ) { addBassPostFilter( st->p_bpf_noise_buf_float, st->bpf_off ? 0 : CLDFB_OVRLP_MIN_SLOTS * st->cldfbBPF->no_channels, realBuffer, imagBuffer, st->cldfbBPF ); } @@ -2192,4 +2190,4 @@ static void smoothTransitionDtxToTcx( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/core_switching_dec_fx.c b/lib_dec/core_switching_dec_fx.c index e5a94c5fe..5cd563a2f 100644 --- a/lib_dec/core_switching_dec_fx.c +++ b/lib_dec/core_switching_dec_fx.c @@ -3,12 +3,12 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "basop_util.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "basop_util.h" /* Function prototypes */ #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" #endif @@ -20,27 +20,29 @@ * *---------------------------------------------------------------------*/ #ifdef IVAS_CODE_SWITCHING -static void core_switch_lb_upsamp(Decoder_State* st, float* output); -static void smoothTransitionDtxToTcx(float synth[], const int16_t output_frame, const int16_t delay_comp); +static void core_switch_lb_upsamp( Decoder_State *st, float *output ); +static void smoothTransitionDtxToTcx( float synth[], const int16_t output_frame, const int16_t delay_comp ); #endif #ifdef IVAS_FLOAT_FIXED -static void smoothTransitionDtxToTcx_fx(Word16 synth[], const Word16 output_frame, const Word16 delay_comp); -static void core_switch_lb_upsamp_fx(Decoder_State* st, Word32* output); +static void smoothTransitionDtxToTcx_fx( Word16 synth[], const Word16 output_frame, const Word16 delay_comp ); +static void core_switch_lb_upsamp_fx( Decoder_State *st, Word32 *output ); #endif #ifdef IVAS_FLOAT_FIXED void bandwidth_switching_detect_fx( - Decoder_State *st_fx /* i/o: encoder state structure */ + Decoder_State *st_fx /* i/o: encoder state structure */ ) { - IF ((EQ_16(st_fx->element_mode, IVAS_CPE_TD) && EQ_16(st_fx->idchan, 1) ) || EQ_16(st_fx->element_mode, IVAS_CPE_MDCT)) + IF( ( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && EQ_16( st_fx->idchan, 1 ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) { /* there is no BWE in TD stereo secondary channel and in MDCT stereo, IGF is part of the core decoding -> no BW switching -> reset BWS counters */ st_fx->prev_bws_cnt = 0; st_fx->bws_cnt = 0; st_fx->bws_cnt1 = 0; - move16(); move16(); move16(); + move16(); + move16(); + move16(); return; } @@ -48,22 +50,21 @@ void bandwidth_switching_detect_fx( test(); test(); test(); - IF( GE_16(st_fx->bws_cnt1, N_NS2W_FRAMES)) + IF( GE_16( st_fx->bws_cnt1, N_NS2W_FRAMES ) ) { st_fx->bws_cnt1 = 0; move16(); } - ELSE IF( GT_32(st_fx->total_brate, ACELP_9k60)&<_32(st_fx->last_core_brate,ACELP_9k60) - && EQ_16(st_fx->bwidth, SWB) && EQ_16(st_fx->last_bwidth, WB) ) + ELSE IF( GT_32( st_fx->total_brate, ACELP_9k60 ) && LT_32( st_fx->last_core_brate, ACELP_9k60 ) && EQ_16( st_fx->bwidth, SWB ) && EQ_16( st_fx->last_bwidth, WB ) ) { - st_fx->bws_cnt1 = add(st_fx->bws_cnt1,1); + st_fx->bws_cnt1 = add( st_fx->bws_cnt1, 1 ); move16(); } ELSE IF( st_fx->bws_cnt1 > 0 ) { - IF( LT_16(st_fx->bwidth, st_fx->last_bwidth)) + IF( LT_16( st_fx->bwidth, st_fx->last_bwidth ) ) { - st_fx->bws_cnt = sub( shl(sub(N_NS2W_FRAMES, st_fx->bws_cnt1), 1), 1 ); + st_fx->bws_cnt = sub( shl( sub( N_NS2W_FRAMES, st_fx->bws_cnt1 ), 1 ), 1 ); move16(); } ELSE @@ -72,16 +73,16 @@ void bandwidth_switching_detect_fx( move16(); } - IF( LT_16(st_fx->bwidth, st_fx->last_bwidth)) + IF( LT_16( st_fx->bwidth, st_fx->last_bwidth ) ) { st_fx->bws_cnt1 = 0; move16(); } ELSE { - IF(EQ_16(st_fx->bwidth, SWB)) + IF( EQ_16( st_fx->bwidth, SWB ) ) { - st_fx->bws_cnt1 = add(st_fx->bws_cnt1,1); + st_fx->bws_cnt1 = add( st_fx->bws_cnt1, 1 ); move16(); } ELSE @@ -96,22 +97,21 @@ void bandwidth_switching_detect_fx( test(); test(); test(); - IF( GE_16(st_fx->bws_cnt, N_WS2N_FRAMES)) + IF( GE_16( st_fx->bws_cnt, N_WS2N_FRAMES ) ) { st_fx->bws_cnt = 0; move16(); } - ELSE IF( LT_32(st_fx->total_brate, ACELP_9k60)&>_32(st_fx->last_core_brate,ACELP_9k60) - && LT_16(st_fx->bwidth, st_fx->last_bwidth) && EQ_16(st_fx->bwidth, WB) ) + ELSE IF( LT_32( st_fx->total_brate, ACELP_9k60 ) && GT_32( st_fx->last_core_brate, ACELP_9k60 ) && LT_16( st_fx->bwidth, st_fx->last_bwidth ) && EQ_16( st_fx->bwidth, WB ) ) { - st_fx->bws_cnt = add(st_fx->bws_cnt,1); + st_fx->bws_cnt = add( st_fx->bws_cnt, 1 ); move16(); } ELSE IF( st_fx->bws_cnt > 0 ) { - IF( GT_16(st_fx->bwidth, st_fx->last_bwidth)) + IF( GT_16( st_fx->bwidth, st_fx->last_bwidth ) ) { - st_fx->bws_cnt1 = shr(sub(N_WS2N_FRAMES, st_fx->bws_cnt), 1); + st_fx->bws_cnt1 = shr( sub( N_WS2N_FRAMES, st_fx->bws_cnt ), 1 ); move16(); } ELSE @@ -120,16 +120,16 @@ void bandwidth_switching_detect_fx( move16(); } - IF( GT_16(st_fx->bwidth, st_fx->last_bwidth)) + IF( GT_16( st_fx->bwidth, st_fx->last_bwidth ) ) { st_fx->bws_cnt = 0; move16(); } ELSE { - IF( EQ_16(st_fx->bwidth, WB)) + IF( EQ_16( st_fx->bwidth, WB ) ) { - st_fx->bws_cnt = add(st_fx->bws_cnt,1); + st_fx->bws_cnt = add( st_fx->bws_cnt, 1 ); move16(); } ELSE @@ -151,25 +151,25 @@ void bandwidth_switching_detect_fx( *---------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -static Word32 Calc_freq_ener_fx(Word32 L_tmp, const Word16 Q_syn2) +static Word32 Calc_freq_ener_fx( Word32 L_tmp, const Word16 Q_syn2 ) { Word32 enerLL_fx; Word16 exp, tmp; - IF(L_tmp == 0) + IF( L_tmp == 0 ) { - enerLL_fx = L_deposit_l(0); + enerLL_fx = L_deposit_l( 0 ); } ELSE { - exp = norm_l(L_tmp); - tmp = extract_h(L_shl(L_tmp, exp)); - exp = sub(exp, sub(30,shl(Q_syn2,1))); + exp = norm_l( L_tmp ); + tmp = extract_h( L_shl( L_tmp, exp ) ); + exp = sub( exp, sub( 30, shl( Q_syn2, 1 ) ) ); - tmp = div_s(16384, tmp); - L_tmp = L_deposit_h(tmp); - L_tmp = Isqrt_lc(L_tmp, &exp); /*31-exp*/ + tmp = div_s( 16384, tmp ); + L_tmp = L_deposit_h( tmp ); + L_tmp = Isqrt_lc( L_tmp, &exp ); /*31-exp*/ - enerLL_fx = L_shr(L_tmp, sub(sub(31, exp), Q_syn2)); /*st_fx->Q_syn2-1*/ + enerLL_fx = L_shr( L_tmp, sub( sub( 31, exp ), Q_syn2 ) ); /*st_fx->Q_syn2-1*/ } return enerLL_fx; } @@ -183,8 +183,8 @@ static Word32 Calc_freq_ener_fx(Word32 L_tmp, const Word16 Q_syn2) #ifdef IVAS_FLOAT_FIXED void bw_switching_pre_proc_fx( - const Word16 *old_syn_12k8_16k_fx, /* i : ACELP core synthesis at 12.8kHz or 16kHz */ - Decoder_State *st_fx /* i/o: decoder state structure */ + const Word16 *old_syn_12k8_16k_fx, /* i : ACELP core synthesis at 12.8kHz or 16kHz */ + Decoder_State *st_fx /* i/o: decoder state structure */ ) { Word16 i; @@ -194,113 +194,122 @@ void bw_switching_pre_proc_fx( Flag Overflow = 0; #endif #ifdef IVAS_CODE_SWITCHING - IF (GT_16(st_fx->element_mode, EVS_MONO)) + IF( GT_16( st_fx->element_mode, EVS_MONO ) ) { - test(); test(); test(); test(); test(); test(); test(); test(); test(); test(); - IF (EQ_16(st_fx->core, ACELP_CORE) && !(EQ_16(st_fx->bfi, 1) && EQ_16(st_fx->con_tcx, 1)) && - st_fx->hBWE_FD != NULL && !(LE_16(st_fx->core_brate, SID_2k40) && EQ_16(st_fx->element_mode, IVAS_CPE_DFT) && EQ_16(nchan_out, 2)) && - !(EQ_16(st_fx->element_mode, IVAS_CPE_MDCT) && EQ_16(nchan_out, 1) && EQ_16(st_fx->idchan, 1) && LE_16(last_element_brate, IVAS_SID_4k4))) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( EQ_16( st_fx->core, ACELP_CORE ) && !( EQ_16( st_fx->bfi, 1 ) && EQ_16( st_fx->con_tcx, 1 ) ) && + st_fx->hBWE_FD != NULL && !( LE_16( st_fx->core_brate, SID_2k40 ) && EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) && EQ_16( nchan_out, 2 ) ) && + !( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) && EQ_16( nchan_out, 1 ) && EQ_16( st_fx->idchan, 1 ) && LE_16( last_element_brate, IVAS_SID_4k4 ) ) ) { /* Calculate tilt of the ACELP core synthesis - needed in SWB BWE decoding */ - calc_tilt_bwe(old_syn_12k8_16k, &st->tilt_wb, st->L_frame); + calc_tilt_bwe( old_syn_12k8_16k, &st->tilt_wb, st->L_frame ); } return; } #endif - test(); test(); - IF( EQ_16(st_fx->core, ACELP_CORE) && !(EQ_16(st_fx->bfi, 1) && EQ_16(st_fx->con_tcx, 1))) + test(); + test(); + IF( EQ_16( st_fx->core, ACELP_CORE ) && !( EQ_16( st_fx->bfi, 1 ) && EQ_16( st_fx->con_tcx, 1 ) ) ) { /*----------------------------------------------------------------------* * Calculate tilt of the ACELP core synthesis *----------------------------------------------------------------------*/ #ifdef BASOP_NOGLOB - st_fx->tilt_wb_fx = round_fx_o(L_shl_o(calc_tilt_bwe_fx(old_syn_12k8_16k_fx, -1, st_fx->L_frame), 3, &Overflow), &Overflow); + st_fx->tilt_wb_fx = round_fx_o( L_shl_o( calc_tilt_bwe_fx( old_syn_12k8_16k_fx, -1, st_fx->L_frame ), 3, &Overflow ), &Overflow ); #else - st_fx->tilt_wb_fx = round_fx(L_shl(calc_tilt_bwe_fx(old_syn_12k8_16k_fx, -1, st_fx->L_frame), 3)); + st_fx->tilt_wb_fx = round_fx( L_shl( calc_tilt_bwe_fx( old_syn_12k8_16k_fx, -1, st_fx->L_frame ), 3 ) ); #endif /*-------------------------------------------------------------------------------* * Calculate frequency energy of 0~3.2kHz and 3.2~6.4kHz the ACELP core synthesis *-------------------------------------------------------------------------------*/ - edct_16fx(old_syn_12k8_16k_fx, syn_dct_fx, L_FRAME, 6, st_fx->element_mode); + edct_16fx( old_syn_12k8_16k_fx, syn_dct_fx, L_FRAME, 6, st_fx->element_mode ); - L_tmp = L_deposit_l(0); - FOR ( i=0; i < L_FRAME/2; i++ ) + L_tmp = L_deposit_l( 0 ); + FOR( i = 0; i < L_FRAME / 2; i++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_mac0_o(L_tmp, syn_dct_fx[i], syn_dct_fx[i], &Overflow); + L_tmp = L_mac0_o( L_tmp, syn_dct_fx[i], syn_dct_fx[i], &Overflow ); #else - L_tmp = L_mac0(L_tmp, syn_dct_fx[i], syn_dct_fx[i]); + L_tmp = L_mac0( L_tmp, syn_dct_fx[i], syn_dct_fx[i] ); #endif } - L_tmp = L_shr(L_tmp, 7); /*2*(st_fx->Q_syn2-1)*/ - st_fx->enerLL_fx = Calc_freq_ener_fx(L_tmp, shl(st_fx->Q_syn2,1)); - L_tmp = L_deposit_l(0); - FOR (; iQ_syn2-1)*/ + st_fx->enerLL_fx = Calc_freq_ener_fx( L_tmp, shl( st_fx->Q_syn2, 1 ) ); + L_tmp = L_deposit_l( 0 ); + FOR( ; i < L_FRAME; i++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_mac0_o(L_tmp, syn_dct_fx[i], syn_dct_fx[i], &Overflow); + L_tmp = L_mac0_o( L_tmp, syn_dct_fx[i], syn_dct_fx[i], &Overflow ); #else - L_tmp = L_mac0(L_tmp, syn_dct_fx[i], syn_dct_fx[i]); + L_tmp = L_mac0( L_tmp, syn_dct_fx[i], syn_dct_fx[i] ); #endif } - L_tmp = L_shr(L_tmp, 7); /*2*(st_fx->Q_syn2-1)*/ - st_fx->enerLH_fx = Calc_freq_ener_fx(L_tmp, shl(st_fx->Q_syn2,1)); + L_tmp = L_shr( L_tmp, 7 ); /*2*(st_fx->Q_syn2-1)*/ + st_fx->enerLH_fx = Calc_freq_ener_fx( L_tmp, shl( st_fx->Q_syn2, 1 ) ); } ELSE { IF( st_fx->hHQ_core->old_is_transient[0] ) { - L_tmp = L_deposit_l(0); - FOR ( i=0; i<32; i++ ) + L_tmp = L_deposit_l( 0 ); + FOR( i = 0; i < 32; i++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_mac0_o(L_tmp, st_fx->t_audio_q_fx[i], st_fx->t_audio_q_fx[i], &Overflow); + L_tmp = L_mac0_o( L_tmp, st_fx->t_audio_q_fx[i], st_fx->t_audio_q_fx[i], &Overflow ); #else - L_tmp = L_mac0(L_tmp, st_fx->t_audio_q_fx[i], st_fx->t_audio_q_fx[i]); + L_tmp = L_mac0( L_tmp, st_fx->t_audio_q_fx[i], st_fx->t_audio_q_fx[i] ); #endif } - L_tmp = L_shr(L_tmp, 5); /*st_fx->Q_syn2-1*/ - st_fx->enerLL_fx = Calc_freq_ener_fx(L_tmp, shl(st_fx->Q_syn2,1)); - L_tmp = L_deposit_l(0); - FOR (; i<64; i++ ) + L_tmp = L_shr( L_tmp, 5 ); /*st_fx->Q_syn2-1*/ + st_fx->enerLL_fx = Calc_freq_ener_fx( L_tmp, shl( st_fx->Q_syn2, 1 ) ); + L_tmp = L_deposit_l( 0 ); + FOR( ; i < 64; i++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_mac0_o(L_tmp, st_fx->t_audio_q_fx[i], st_fx->t_audio_q_fx[i], &Overflow); + L_tmp = L_mac0_o( L_tmp, st_fx->t_audio_q_fx[i], st_fx->t_audio_q_fx[i], &Overflow ); #else - L_tmp = L_mac0(L_tmp, st_fx->t_audio_q_fx[i], st_fx->t_audio_q_fx[i]); + L_tmp = L_mac0( L_tmp, st_fx->t_audio_q_fx[i], st_fx->t_audio_q_fx[i] ); #endif } - L_tmp = L_shr(L_tmp, 5); /*st_fx->Q_syn2-1*/ - st_fx->enerLH_fx = Calc_freq_ener_fx(L_tmp, shl(st_fx->Q_syn2,1)); + L_tmp = L_shr( L_tmp, 5 ); /*st_fx->Q_syn2-1*/ + st_fx->enerLH_fx = Calc_freq_ener_fx( L_tmp, shl( st_fx->Q_syn2, 1 ) ); } ELSE { - L_tmp = L_deposit_l(0); - FOR ( i=0; i < L_FRAME/2; i++ ) + L_tmp = L_deposit_l( 0 ); + FOR( i = 0; i < L_FRAME / 2; i++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_mac0_o(L_tmp, st_fx->t_audio_q_fx[i], st_fx->t_audio_q_fx[i], &Overflow); + L_tmp = L_mac0_o( L_tmp, st_fx->t_audio_q_fx[i], st_fx->t_audio_q_fx[i], &Overflow ); #else - L_tmp = L_mac0(L_tmp, st_fx->t_audio_q_fx[i], st_fx->t_audio_q_fx[i]); + L_tmp = L_mac0( L_tmp, st_fx->t_audio_q_fx[i], st_fx->t_audio_q_fx[i] ); #endif } - L_tmp = L_shr(L_tmp, 7); /*st_fx->Q_syn2-1*/ - st_fx->enerLL_fx = Calc_freq_ener_fx(L_tmp, shl(st_fx->Q_syn2,1)); - L_tmp = L_deposit_l(0); - FOR (; iQ_syn2-1*/ + st_fx->enerLL_fx = Calc_freq_ener_fx( L_tmp, shl( st_fx->Q_syn2, 1 ) ); + L_tmp = L_deposit_l( 0 ); + FOR( ; i < L_FRAME; i++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_mac0_o(L_tmp, st_fx->t_audio_q_fx[i], st_fx->t_audio_q_fx[i], &Overflow); + L_tmp = L_mac0_o( L_tmp, st_fx->t_audio_q_fx[i], st_fx->t_audio_q_fx[i], &Overflow ); #else - L_tmp = L_mac0(L_tmp, st_fx->t_audio_q_fx[i], st_fx->t_audio_q_fx[i]); + L_tmp = L_mac0( L_tmp, st_fx->t_audio_q_fx[i], st_fx->t_audio_q_fx[i] ); #endif } - L_tmp = L_shr(L_tmp, 7); /*st_fx->Q_syn2-1*/ - st_fx->enerLH_fx = Calc_freq_ener_fx(L_tmp, shl(st_fx->Q_syn2,1)); - + L_tmp = L_shr( L_tmp, 7 ); /*st_fx->Q_syn2-1*/ + st_fx->enerLH_fx = Calc_freq_ener_fx( L_tmp, shl( st_fx->Q_syn2, 1 ) ); } } @@ -310,13 +319,13 @@ void bw_switching_pre_proc_fx( test(); test(); test(); - IF( st_fx->last_bwidth == 0 && LE_16(st_fx->extl, SWB_CNG)) + IF( st_fx->last_bwidth == 0 && LE_16( st_fx->extl, SWB_CNG ) ) { st_fx->prev_ener_shb_fx = 0; move16(); - set16_fx(st_fx->prev_SWB_fenv_fx, 0, SWB_FENV); + set16_fx( st_fx->prev_SWB_fenv_fx, 0, SWB_FENV ); } - ELSE if(((EQ_16(st_fx->core, ACELP_CORE) && ( EQ_16(st_fx->last_core,HQ_CORE) || EQ_16(st_fx->last_core, TCX_10_CORE) || EQ_16(st_fx->last_core, TCX_20_CORE)))||(EQ_16(st_fx->core,st_fx->last_core)&&NE_16(st_fx->extl,st_fx->last_extl)))&&GE_16(st_fx->last_bwidth,SWB)) + ELSE if ( ( ( EQ_16( st_fx->core, ACELP_CORE ) && ( EQ_16( st_fx->last_core, HQ_CORE ) || EQ_16( st_fx->last_core, TCX_10_CORE ) || EQ_16( st_fx->last_core, TCX_20_CORE ) ) ) || ( EQ_16( st_fx->core, st_fx->last_core ) && NE_16( st_fx->extl, st_fx->last_extl ) ) ) && GE_16( st_fx->last_bwidth, SWB ) ) { st_fx->attenu_fx = 3277; move16(); @@ -326,9 +335,7 @@ void bw_switching_pre_proc_fx( test(); test(); test(); - IF(EQ_16(st_fx->last_core, HQ_CORE) - || ( EQ_16(st_fx->last_core, ACELP_CORE) - && !(EQ_16(st_fx->last_extl, WB_TBE) || EQ_16(st_fx->last_extl, SWB_TBE) || EQ_16(st_fx->last_extl, FB_TBE) ) && GT_32(st_fx->core_brate, ACELP_8k00) )) + IF( EQ_16( st_fx->last_core, HQ_CORE ) || ( EQ_16( st_fx->last_core, ACELP_CORE ) && !( EQ_16( st_fx->last_extl, WB_TBE ) || EQ_16( st_fx->last_extl, SWB_TBE ) || EQ_16( st_fx->last_extl, FB_TBE ) ) && GT_32( st_fx->core_brate, ACELP_8k00 ) ) ) { st_fx->prev_fractive = 0; move16(); @@ -347,68 +354,68 @@ void bw_switching_pre_proc_fx( *---------------------------------------------------------------------*/ static void core_switch_lb_upsamp( - Decoder_State* st, /* i/o: Decoder state */ - float* output /* i/o: LB synth/upsampled LB synth */ + Decoder_State *st, /* i/o: Decoder state */ + float *output /* i/o: LB synth/upsampled LB synth */ ) { int16_t i; - float* realBuffer[CLDFB_OVRLP_MIN_SLOTS], * imagBuffer[CLDFB_OVRLP_MIN_SLOTS]; + float *realBuffer[CLDFB_OVRLP_MIN_SLOTS], *imagBuffer[CLDFB_OVRLP_MIN_SLOTS]; float realBufferTmp[CLDFB_OVRLP_MIN_SLOTS][CLDFB_NO_CHANNELS_MAX]; float imagBufferTmp[CLDFB_OVRLP_MIN_SLOTS][CLDFB_NO_CHANNELS_MAX]; /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */ - for (i = 0; i < CLDFB_OVRLP_MIN_SLOTS; i++) + for ( i = 0; i < CLDFB_OVRLP_MIN_SLOTS; i++ ) { - set_f(realBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX); - set_f(imagBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX); + set_f( realBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX ); + set_f( imagBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX ); realBuffer[i] = realBufferTmp[i]; imagBuffer[i] = imagBufferTmp[i]; } /* check if the CLDFB works on the right sample rate */ - if ((st->cldfbAna->no_channels * st->cldfbAna->no_col) != st->L_frame) + if ( ( st->cldfbAna->no_channels * st->cldfbAna->no_col ) != st->L_frame ) { - resampleCldfb(st->cldfbAna, st->L_frame * FRAMES_PER_SEC); + resampleCldfb( st->cldfbAna, st->L_frame * FRAMES_PER_SEC ); - if (st->cldfbBPF != NULL && st->L_frame <= L_FRAME16k) + if ( st->cldfbBPF != NULL && st->L_frame <= L_FRAME16k ) { - resampleCldfb(st->cldfbBPF, st->L_frame * FRAMES_PER_SEC); + resampleCldfb( st->cldfbBPF, st->L_frame * FRAMES_PER_SEC ); } - if (st->ini_frame > 0) + if ( st->ini_frame > 0 ) { st->cldfbSyn->bandsToZero = st->cldfbSyn->no_channels - st->cldfbAna->no_channels; } } /* analysis of the synthesis at internal sampling rate */ - cldfbAnalysis(output, realBuffer, imagBuffer, CLDFB_OVRLP_MIN_SLOTS * st->cldfbAna->no_channels, st->cldfbAna); + cldfbAnalysis( output, realBuffer, imagBuffer, CLDFB_OVRLP_MIN_SLOTS * st->cldfbAna->no_channels, st->cldfbAna ); /* analysis and add the BPF error signal */ - if (st->p_bpf_noise_buf) + if ( st->p_bpf_noise_buf ) { - addBassPostFilter(st->p_bpf_noise_buf, st->bpf_off ? 0 : CLDFB_OVRLP_MIN_SLOTS * st->cldfbBPF->no_channels, realBuffer, imagBuffer, st->cldfbBPF); + addBassPostFilter( st->p_bpf_noise_buf, st->bpf_off ? 0 : CLDFB_OVRLP_MIN_SLOTS * st->cldfbBPF->no_channels, realBuffer, imagBuffer, st->cldfbBPF ); } /* set output mask for upsampling */ - if (st->bwidth == NB) + if ( st->bwidth == NB ) { /* set NB mask for upsampling */ st->cldfbSyn->bandsToZero = st->cldfbSyn->no_channels - 10; } - else if (st->cldfbSyn->bandsToZero != st->cldfbSyn->no_channels - st->cldfbAna->no_channels) + else if ( st->cldfbSyn->bandsToZero != st->cldfbSyn->no_channels - st->cldfbAna->no_channels ) { /* in case of BW switching, re-init to default */ st->cldfbSyn->bandsToZero = st->cldfbSyn->no_channels - st->cldfbAna->no_channels; } /* synthesis of the combined signal */ - cldfbSynthesis(realBuffer, imagBuffer, output, CLDFB_OVRLP_MIN_SLOTS * st->cldfbSyn->no_channels, st->cldfbSyn); + cldfbSynthesis( realBuffer, imagBuffer, output, CLDFB_OVRLP_MIN_SLOTS * st->cldfbSyn->no_channels, st->cldfbSyn ); /* save synthesis - needed in case of core switching */ - if (st->hTcxDec != NULL) + if ( st->hTcxDec != NULL ) { - mvr2r(output, st->previoussynth, st->hTcxDec->L_frameTCX); + mvr2r( output, st->previoussynth, st->hTcxDec->L_frameTCX ); } return; @@ -432,30 +439,30 @@ static void smoothTransitionMdctStereoDtx( { int16_t i, filter_len; float w, mem, step, fade_in; - float smoothing_input_buffer[2 * NS2SA(48000, DELAY_CLDFB_NS) + TRANSITION_SMOOTHING_LEN_48k]; - float smoothing_out_buffer[2 * NS2SA(48000, DELAY_CLDFB_NS) + TRANSITION_SMOOTHING_LEN_48k]; + float smoothing_input_buffer[2 * NS2SA( 48000, DELAY_CLDFB_NS ) + TRANSITION_SMOOTHING_LEN_48k]; + float smoothing_out_buffer[2 * NS2SA( 48000, DELAY_CLDFB_NS ) + TRANSITION_SMOOTHING_LEN_48k]; filter_len = TRANSITION_SMOOTHING_LEN_16k; - if (output_frame == L_FRAME32k) + if ( output_frame == L_FRAME32k ) { filter_len = TRANSITION_SMOOTHING_LEN_32k; } - else if (output_frame == L_FRAME48k) + else if ( output_frame == L_FRAME48k ) { filter_len = TRANSITION_SMOOTHING_LEN_48k; } /* prepare buffer */ - for (i = 0; i < filter_len / 2; i++) + for ( i = 0; i < filter_len / 2; i++ ) { smoothing_input_buffer[i] = synth[0]; } - mvr2r(synth, smoothing_input_buffer + filter_len / 2, 2 * delay_comp + filter_len / 2); + mvr2r( synth, smoothing_input_buffer + filter_len / 2, 2 * delay_comp + filter_len / 2 ); /* apply Mean filter */ w = 1.f / filter_len; - mem = sum_f(smoothing_input_buffer, filter_len); - for (i = 0; i < 2 * delay_comp; i++) + mem = sum_f( smoothing_input_buffer, filter_len ); + for ( i = 0; i < 2 * delay_comp; i++ ) { smoothing_out_buffer[i] = w * mem; mem = mem - smoothing_input_buffer[i] + smoothing_input_buffer[i + filter_len]; @@ -464,16 +471,16 @@ static void smoothTransitionMdctStereoDtx( /* apply fades around transition */ step = 1.f / delay_comp; fade_in = 0.f; - for (i = 0; i < delay_comp; i++) + for ( i = 0; i < delay_comp; i++ ) { - synth[i] = smoothing_out_buffer[i] * fade_in + synth[i] * (1 - fade_in); + synth[i] = smoothing_out_buffer[i] * fade_in + synth[i] * ( 1 - fade_in ); fade_in += step; } fade_in = 0.f; - for (; i < 2 * delay_comp; i++) + for ( ; i < 2 * delay_comp; i++ ) { - synth[i] = synth[i] * fade_in + smoothing_out_buffer[i] * (1 - fade_in); + synth[i] = synth[i] * fade_in + smoothing_out_buffer[i] * ( 1 - fade_in ); fade_in += step; } @@ -481,14 +488,14 @@ static void smoothTransitionMdctStereoDtx( } #endif /*---------------------------------------------------------------------* -* core_switching_pre_dec_fx() -* -* Preprocessing/preparation for ACELP/HQ core switching -*---------------------------------------------------------------------*/ + * core_switching_pre_dec_fx() + * + * Preprocessing/preparation for ACELP/HQ core switching + *---------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED ivas_error core_switching_pre_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 output_frame /* i : frame length */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 output_frame /* i : frame length */ ) { Word16 oldLenClasBuff, newLenClasBuff, i; @@ -507,31 +514,31 @@ ivas_error core_switching_pre_dec_fx( error = IVAS_ERR_OK; /* Codec switching */ - IF( EQ_16(st_fx->last_codec_mode,MODE2) || ((EQ_16(st_fx->last_core, TCX_20_CORE) || EQ_16(st_fx->last_core, TCX_10_CORE)) && GT_16(st_fx->element_mode, EVS_MONO))) + IF( EQ_16( st_fx->last_codec_mode, MODE2 ) || ( ( EQ_16( st_fx->last_core, TCX_20_CORE ) || EQ_16( st_fx->last_core, TCX_10_CORE ) ) && GT_16( st_fx->element_mode, EVS_MONO ) ) ) { st_fx->mem_deemph_fx = st_fx->syn[M]; move16(); set16_fx( st_fx->agc_mem_fx, 0, 2 ); - Scale_sig(&(st_fx->mem_deemph_fx), 1, st_fx->Q_syn); /* Brings mem_deemph to Qsyn */ + Scale_sig( &( st_fx->mem_deemph_fx ), 1, st_fx->Q_syn ); /* Brings mem_deemph to Qsyn */ - Copy_Scale_sig(st_fx->mem_syn2_fx, st_fx->mem_syn1_fx, M, sub(-1,st_fx->Q_syn)); /*Q-1*/ + Copy_Scale_sig( st_fx->mem_syn2_fx, st_fx->mem_syn1_fx, M, sub( -1, st_fx->Q_syn ) ); /*Q-1*/ st_fx->bpf_off = 1; move16(); - Scale_sig(st_fx->hPFstat->mem_pf_in, L_SUBFR, st_fx->Q_syn); /* Post_filter mem */ - Scale_sig(st_fx->hPFstat->mem_res2, DECMEM_RES2, st_fx->Q_syn); /* NB post_filter mem */ - Scale_sig(st_fx->hPFstat->mem_stp, L_SUBFR, st_fx->Q_syn); /* Post_filter mem */ - IF (hBPF != NULL) + Scale_sig( st_fx->hPFstat->mem_pf_in, L_SUBFR, st_fx->Q_syn ); /* Post_filter mem */ + Scale_sig( st_fx->hPFstat->mem_res2, DECMEM_RES2, st_fx->Q_syn ); /* NB post_filter mem */ + Scale_sig( st_fx->hPFstat->mem_stp, L_SUBFR, st_fx->Q_syn ); /* Post_filter mem */ + IF( hBPF != NULL ) { - set16_fx(hBPF->pst_old_syn_fx, 0, NBPSF_PIT_MAX); /* BPF mem*/ - hBPF->pst_lp_ener_fx = round_fx(L_shl(Mpy_32_16_1(st_fx->lp_error_ener, 0x6054), 2 + 8)); /* convert from 15Q16, log2 -> 7Q8 10*log10 */ + set16_fx( hBPF->pst_old_syn_fx, 0, NBPSF_PIT_MAX ); /* BPF mem*/ + hBPF->pst_lp_ener_fx = round_fx( L_shl( Mpy_32_16_1( st_fx->lp_error_ener, 0x6054 ), 2 + 8 ) ); /* convert from 15Q16, log2 -> 7Q8 10*log10 */ hBPF->pst_mem_deemp_err_fx = 0; } move16(); - st_fx->psf_lp_noise_fx = round_fx(L_shl(st_fx->lp_noise,1)); + st_fx->psf_lp_noise_fx = round_fx( L_shl( st_fx->lp_noise, 1 ) ); /* reset old HB synthesis buffer */ - IF( EQ_16(st_fx->last_L_frame,L_FRAME)) + IF( EQ_16( st_fx->last_L_frame, L_FRAME ) ) { st_fx->old_bwe_delay = NS2SA_fx2( st_fx->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_12k8_NS ); } @@ -539,7 +546,7 @@ ivas_error core_switching_pre_dec_fx( { st_fx->old_bwe_delay = NS2SA_fx2( st_fx->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_16k_NS ); } - set16_fx( st_fx->hb_prev_synth_buffer_fx, 0, NS2SA(48000, DELAY_BWE_TOTAL_NS) ); + set16_fx( st_fx->hb_prev_synth_buffer_fx, 0, NS2SA( 48000, DELAY_BWE_TOTAL_NS ) ); /* reset upd_cnt */ st_fx->upd_cnt = MAX_UPD_CNT; @@ -548,36 +555,36 @@ ivas_error core_switching_pre_dec_fx( move16(); - IF(hBWE_TD != NULL && NE_16(st_fx->last_core,ACELP_CORE)) + IF( hBWE_TD != NULL && NE_16( st_fx->last_core, ACELP_CORE ) ) { hBWE_TD->prev_hb_synth_fx_exp = 31; move16(); /* reset BWE memories */ - set16_fx(hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX*2 ); - hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l(0); + set16_fx( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); + hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 ); } - IF( GE_32(st_fx->output_Fs,16000) && st_fx->hBWE_zero != NULL) + IF( GE_32( st_fx->output_Fs, 16000 ) && st_fx->hBWE_zero != NULL ) { - hf_synth_reset_fx(st_fx->hBWE_zero); + hf_synth_reset_fx( st_fx->hBWE_zero ); } - IF (st_fx->hBWE_FD != NULL) + IF( st_fx->hBWE_FD != NULL ) { - set16_fx(hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA(16000, DELAY_FD_BWE_ENC_NS)); + set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); } - IF(st_fx->hHQ_core != NULL) + IF( st_fx->hHQ_core != NULL ) { - set32_fx(hHQ_core->prev_env_fx, 0, SFM_N_WB); - set32_fx(hHQ_core->prev_normq_fx, 0, SFM_N_WB); + set32_fx( hHQ_core->prev_env_fx, 0, SFM_N_WB ); + set32_fx( hHQ_core->prev_normq_fx, 0, SFM_N_WB ); - set32_fx(hHQ_core->last_ni_gain_fx, 0, BANDS_MAX); - set16_fx(hHQ_core->last_env_fx, 0, BANDS_MAX); + set32_fx( hHQ_core->last_ni_gain_fx, 0, BANDS_MAX ); + set16_fx( hHQ_core->last_env_fx, 0, BANDS_MAX ); hHQ_core->last_max_pos_pulse = 0; move16(); - IF(GT_32(st_fx->output_Fs, 16000)) + IF( GT_32( st_fx->output_Fs, 16000 ) ) { - set32_fx(hHQ_core->prev_coeff_out_fx, 0, L_HQ_WB_BWE); + set32_fx( hHQ_core->prev_coeff_out_fx, 0, L_HQ_WB_BWE ); } /* pre-echo */ @@ -585,29 +592,29 @@ ivas_error core_switching_pre_dec_fx( move16(); } /* reset the GSC pre echo energy threshold in case of switching */ - IF (st_fx->hGSCDec != NULL) + IF( st_fx->hGSCDec != NULL ) { st_fx->hGSCDec->Last_frame_ener_fx = MAX_32; } move32(); test(); - IF( EQ_16(st_fx->last_core,TCX_20_CORE)||EQ_16(st_fx->last_core,TCX_10_CORE)) + IF( EQ_16( st_fx->last_core, TCX_20_CORE ) || EQ_16( st_fx->last_core, TCX_10_CORE ) ) { - IF (EQ_16(st_fx->element_mode, EVS_MONO)) + IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) { st_fx->last_core = HQ_CORE; move16(); - Copy(hTcxDec->FBTCXdelayBuf, st_fx->prev_synth_buffer_fx, NS2SA(st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS)); + Copy( hTcxDec->FBTCXdelayBuf, st_fx->prev_synth_buffer_fx, NS2SA( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) ); } - IF (hHQ_core != NULL) + IF( hHQ_core != NULL ) { - set32_fx(hHQ_core->last_ni_gain_fx, 0, BANDS_MAX); - set16_fx(hHQ_core->last_env_fx, 0, BANDS_MAX); + set32_fx( hHQ_core->last_ni_gain_fx, 0, BANDS_MAX ); + set16_fx( hHQ_core->last_env_fx, 0, BANDS_MAX ); hHQ_core->last_max_pos_pulse = 0; move16(); - set16_fx(hHQ_core->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM); + set16_fx( hHQ_core->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM ); hHQ_core->prev_frm_hfe2 = 0; move16(); hHQ_core->prev_stab_hfe2 = 0; @@ -615,87 +622,87 @@ ivas_error core_switching_pre_dec_fx( } } - IF(st_fx->prev_bfi!=0) + IF( st_fx->prev_bfi != 0 ) { Word16 delay_comp; /*switch off Hq Voicing as it was not uodated in MODE2*/ - IF(hHQ_core != NULL) + IF( hHQ_core != NULL ) { hHQ_core->oldHqVoicing = 0; hHQ_core->HqVoicing = 0; - move16();move16(); + move16(); + move16(); } - delay_comp = NS2SA_fx2(st_fx->output_Fs, DELAY_CLDFB_NS); + delay_comp = NS2SA_fx2( st_fx->output_Fs, DELAY_CLDFB_NS ); - IF( !st_fx->last_con_tcx && st_fx->last_core_bfi == ACELP_CORE && EQ_16(st_fx->core,HQ_CORE)) + IF( !st_fx->last_con_tcx && st_fx->last_core_bfi == ACELP_CORE && EQ_16( st_fx->core, HQ_CORE ) ) { Word16 no_col; Word32 *realBuffer[CLDFB_NO_COL_MAX_SWITCH], *imagBuffer[CLDFB_NO_COL_MAX_SWITCH]; Word32 realBufferTmp[CLDFB_NO_COL_MAX_SWITCH][CLDFB_NO_CHANNELS_MAX], imagBufferTmp[CLDFB_NO_COL_MAX_SWITCH][CLDFB_NO_CHANNELS_MAX]; CLDFB_SCALE_FACTOR scaleFactor; - Word32 workBuffer[128*3]; + Word32 workBuffer[128 * 3]; - FOR( i=0; i< CLDFB_NO_COL_MAX_SWITCH; i++ ) + FOR( i = 0; i < CLDFB_NO_COL_MAX_SWITCH; i++ ) { - set32_fx(realBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX); - set32_fx(imagBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX); + set32_fx( realBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX ); + set32_fx( imagBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX ); realBuffer[i] = realBufferTmp[i]; move32(); imagBuffer[i] = imagBufferTmp[i]; move32(); } - no_col = s_min(st_fx->cldfbAna->no_col, idiv1616(sub(add(delay_comp, st_fx->cldfbAna->no_channels),1) , st_fx->cldfbAna->no_channels)); + no_col = s_min( st_fx->cldfbAna->no_col, idiv1616( sub( add( delay_comp, st_fx->cldfbAna->no_channels ), 1 ), st_fx->cldfbAna->no_channels ) ); /* CLDFB analysis of the synthesis at internal sampling rate */ - IF ((error = cldfb_save_memory( st_fx->cldfbAna )) != IVAS_ERR_OK) + IF( ( error = cldfb_save_memory( st_fx->cldfbAna ) ) != IVAS_ERR_OK ) { return error; } - cldfbAnalysisFiltering( st_fx->cldfbAna, realBuffer, imagBuffer, &scaleFactor, hTcxDec->syn_Overl, 0, no_col, workBuffer); + cldfbAnalysisFiltering( st_fx->cldfbAna, realBuffer, imagBuffer, &scaleFactor, hTcxDec->syn_Overl, 0, no_col, workBuffer ); cldfb_restore_memory( st_fx->cldfbAna ); scaleFactor.hb_scale = scaleFactor.lb_scale; move16(); /* CLDFB synthesis of the combined signal */ - IF ((error = cldfb_save_memory( st_fx->cldfbSyn )) != IVAS_ERR_OK) + IF( ( error = cldfb_save_memory( st_fx->cldfbSyn ) ) != IVAS_ERR_OK ) { return error; } - cldfbSynthesisFiltering(st_fx->cldfbSyn, realBuffer, imagBuffer, &scaleFactor, hHQ_core->fer_samples_fx, 0, no_col, workBuffer); + cldfbSynthesisFiltering( st_fx->cldfbSyn, realBuffer, imagBuffer, &scaleFactor, hHQ_core->fer_samples_fx, 0, no_col, workBuffer ); cldfb_restore_memory( st_fx->cldfbSyn ); } - IF( !st_fx->last_con_tcx && st_fx->last_core_bfi == ACELP_CORE && EQ_16(st_fx->core,HQ_CORE)) + IF( !st_fx->last_con_tcx && st_fx->last_core_bfi == ACELP_CORE && EQ_16( st_fx->core, HQ_CORE ) ) { - lerp(hTcxDec->syn_Overl, hHQ_core->fer_samples_fx+delay_comp,shr(st_fx->output_frame_fx,1), shr(st_fx->last_L_frame,1)); + lerp( hTcxDec->syn_Overl, hHQ_core->fer_samples_fx + delay_comp, shr( st_fx->output_frame_fx, 1 ), shr( st_fx->last_L_frame, 1 ) ); /*Set to zero the remaining part*/ - set16_fx(hHQ_core->fer_samples_fx+delay_comp+shr(st_fx->output_frame_fx,1), 0, shr(st_fx->output_frame_fx,1)-delay_comp); + set16_fx( hHQ_core->fer_samples_fx + delay_comp + shr( st_fx->output_frame_fx, 1 ), 0, shr( st_fx->output_frame_fx, 1 ) - delay_comp ); } } st_fx->use_acelp_preq = 0; move16(); - st_fx->reset_mem_AR=0; + st_fx->reset_mem_AR = 0; move16(); - } /*FEC*/ - IF( LE_16(st_fx->L_frame,L_FRAME16k)) + IF( LE_16( st_fx->L_frame, L_FRAME16k ) ) { test(); - IF( LE_16(st_fx->last_L_frame,L_FRAME16k)&&NE_16(st_fx->core,HQ_CORE)) + IF( LE_16( st_fx->last_L_frame, L_FRAME16k ) && NE_16( st_fx->core, HQ_CORE ) ) { - IF( NE_16(st_fx->L_frame,st_fx->last_L_frame)) + IF( NE_16( st_fx->L_frame, st_fx->last_L_frame ) ) { - IF (GT_16(st_fx->L_frame,st_fx->last_L_frame)) + IF( GT_16( st_fx->L_frame, st_fx->last_L_frame ) ) { - oldLenClasBuff = extract_l(L_shr(Mpy_32_16_1(L_mult0(st_fx->last_L_frame,getInvFrameLen(st_fx->L_frame)/*Q21*/)/*Q21*/,L_SYN_MEM_CLAS_ESTIM/*Q0*/)/*Q6*/,6)/*Q0*/); + oldLenClasBuff = extract_l( L_shr( Mpy_32_16_1( L_mult0( st_fx->last_L_frame, getInvFrameLen( st_fx->L_frame ) /*Q21*/ ) /*Q21*/, L_SYN_MEM_CLAS_ESTIM /*Q0*/ ) /*Q6*/, 6 ) /*Q0*/ ); newLenClasBuff = L_SYN_MEM_CLAS_ESTIM; move16(); } @@ -703,14 +710,14 @@ ivas_error core_switching_pre_dec_fx( { oldLenClasBuff = L_SYN_MEM_CLAS_ESTIM; move16(); - newLenClasBuff = extract_l(L_shr(Mpy_32_16_1(L_mult0(st_fx->L_frame,getInvFrameLen(st_fx->last_L_frame)/*Q21*/)/*Q21*/,L_SYN_MEM_CLAS_ESTIM/*Q0*/)/*Q6*/,6)/*Q0*/); + newLenClasBuff = extract_l( L_shr( Mpy_32_16_1( L_mult0( st_fx->L_frame, getInvFrameLen( st_fx->last_L_frame ) /*Q21*/ ) /*Q21*/, L_SYN_MEM_CLAS_ESTIM /*Q0*/ ) /*Q6*/, 6 ) /*Q0*/ ); } - lerp( &st_fx->mem_syn_clas_estim_fx[L_SYN_MEM_CLAS_ESTIM-oldLenClasBuff], &st_fx->mem_syn_clas_estim_fx[L_SYN_MEM_CLAS_ESTIM-newLenClasBuff], newLenClasBuff, oldLenClasBuff ); + lerp( &st_fx->mem_syn_clas_estim_fx[L_SYN_MEM_CLAS_ESTIM - oldLenClasBuff], &st_fx->mem_syn_clas_estim_fx[L_SYN_MEM_CLAS_ESTIM - newLenClasBuff], newLenClasBuff, oldLenClasBuff ); } } ELSE { - set16_fx( st_fx->mem_syn_clas_estim_fx, 0,L_SYN_MEM_CLAS_ESTIM ); + set16_fx( st_fx->mem_syn_clas_estim_fx, 0, L_SYN_MEM_CLAS_ESTIM ); st_fx->classifier_Q_mem_syn = 0; move16(); } @@ -720,18 +727,18 @@ ivas_error core_switching_pre_dec_fx( within ACELP_CORE if switching from another bitarate to vbr, last_ppp and last_nelp is always updated in the previous frame */ test(); test(); - IF( EQ_16(st_fx->core, ACELP_CORE)&&(NE_16(st_fx->last_core,ACELP_CORE)||EQ_16(st_fx->last_codec_mode,MODE2))) + IF( EQ_16( st_fx->core, ACELP_CORE ) && ( NE_16( st_fx->last_core, ACELP_CORE ) || EQ_16( st_fx->last_codec_mode, MODE2 ) ) ) { st_fx->last_ppp_mode_dec = 0; move16(); - st_fx->last_nelp_mode_dec =0; + st_fx->last_nelp_mode_dec = 0; move16(); } test(); test(); test(); - IF( EQ_16(st_fx->core, ACELP_CORE)&&(NE_16(st_fx->last_core,ACELP_CORE)||EQ_16(st_fx->last_codec_mode,MODE2)||LE_32(st_fx->last_total_brate,PPP_NELP_2k80))) + IF( EQ_16( st_fx->core, ACELP_CORE ) && ( NE_16( st_fx->last_core, ACELP_CORE ) || EQ_16( st_fx->last_codec_mode, MODE2 ) || LE_32( st_fx->last_total_brate, PPP_NELP_2k80 ) ) ) { st_fx->act_count = 3; move16(); @@ -741,22 +748,22 @@ ivas_error core_switching_pre_dec_fx( test(); test(); - IF( ((EQ_16(st_fx->core,ACELP_CORE)||EQ_16(st_fx->core,AMR_WB_CORE))&&EQ_16(st_fx->last_core,HQ_CORE) ) -//#ifdef IVAS_CODE_SWITCHING -// || ((EQ_16(st_fx->element_mode, IVAS_CPE_DFT) || EQ_16(st_fx->element_mode, IVAS_CPE_TD) || -// (EQ_16(st_fx->element_mode, IVAS_CPE_MDCT) && last_element_mode == IVAS_CPE_DFT)) && EQ_16(nchan_out,2) && -// NE_16(st_fx->core_brate, SID_2k40) && NE_16(st_fx->core_brate, FRAME_NO_DATA) && (EQ_16(last_core_brate_st0, FRAME_NO_DATA) || EQ_16(last_core_brate_st0, SID_2k40))) -//#endif + IF( ( ( EQ_16( st_fx->core, ACELP_CORE ) || EQ_16( st_fx->core, AMR_WB_CORE ) ) && EQ_16( st_fx->last_core, HQ_CORE ) ) + //#ifdef IVAS_CODE_SWITCHING + // || ((EQ_16(st_fx->element_mode, IVAS_CPE_DFT) || EQ_16(st_fx->element_mode, IVAS_CPE_TD) || + // (EQ_16(st_fx->element_mode, IVAS_CPE_MDCT) && last_element_mode == IVAS_CPE_DFT)) && EQ_16(nchan_out,2) && + // NE_16(st_fx->core_brate, SID_2k40) && NE_16(st_fx->core_brate, FRAME_NO_DATA) && (EQ_16(last_core_brate_st0, FRAME_NO_DATA) || EQ_16(last_core_brate_st0, SID_2k40))) + //#endif ) { test(); - IF (EQ_16(st_fx->element_mode, IVAS_CPE_DFT) || EQ_16(st_fx->element_mode, IVAS_CPE_TD)) + IF( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) { st_fx->hPFstat->reset = 1; move16(); } - IF(EQ_16(st_fx->L_frame, L_FRAME16k)) + IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { Copy( TRWB2_Ave_fx, st_fx->lsf_old_fx, M ); Copy( TRWB2_Ave_fx, st_fx->lsfoldbfi1_fx, M ); @@ -774,11 +781,11 @@ ivas_error core_switching_pre_dec_fx( } #ifdef IVAS_CODE_SWITCHING - if ((st->element_mode == IVAS_CPE_DFT || st->element_mode == IVAS_CPE_TD) && nchan_out == 2 && st->core_brate > SID_2k40 && (last_core_brate_st0 == FRAME_NO_DATA || last_core_brate_st0 == SID_2k40) && st->hTcxDec != NULL) + if ( ( st->element_mode == IVAS_CPE_DFT || st->element_mode == IVAS_CPE_TD ) && nchan_out == 2 && st->core_brate > SID_2k40 && ( last_core_brate_st0 == FRAME_NO_DATA || last_core_brate_st0 == SID_2k40 ) && st->hTcxDec != NULL ) { /* Last frame was Stereo CNG and the synthesis memory is outdated -- reset */ - set_f(st->hTcxDec->old_syn_Overl, 0.0f, L_FRAME32k / 2); - set_f(st->hFdCngDec->hFdCngCom->olapBufferAna, 0.0f, FFTLEN); + set_f( st->hTcxDec->old_syn_Overl, 0.0f, L_FRAME32k / 2 ); + set_f( st->hFdCngDec->hFdCngCom->olapBufferAna, 0.0f, FFTLEN ); } #endif set16_fx( st_fx->agc_mem_fx, 0, 2 ); @@ -789,14 +796,14 @@ ivas_error core_switching_pre_dec_fx( set16_fx( st_fx->mem_syn2_fx, 0, M ); } set16_fx( st_fx->mem_syn1_fx, 0, M ); - IF(hBWE_TD != NULL) + IF( hBWE_TD != NULL ) { hBWE_TD->bwe_non_lin_prev_scale_fx = 0; move16(); } /* Reset ACELP parameters */ - set16_fx( st_fx->mem_MA_fx,0, M ); - IF( EQ_32(st_fx->sr_core, INT_FS_16k)) + set16_fx( st_fx->mem_MA_fx, 0, M ); + IF( EQ_32( st_fx->sr_core, INT_FS_16k ) ) { Copy( GEWB2_Ave_fx, st_fx->mem_AR_fx, M ); } @@ -808,8 +815,8 @@ ivas_error core_switching_pre_dec_fx( move16(); st_fx->gc_threshold_fx = 0; move16(); - st_fx->dm_fx.prev_gain_code = L_deposit_l(0); - set16_fx(st_fx->dm_fx.prev_gain_pit, 0, 6); + st_fx->dm_fx.prev_gain_code = L_deposit_l( 0 ); + set16_fx( st_fx->dm_fx.prev_gain_pit, 0, 6 ); st_fx->dm_fx.prev_state = 0; move16(); @@ -824,17 +831,17 @@ ivas_error core_switching_pre_dec_fx( /*st_fx->lp_gainc_fx = (float)sqrt( st_fx->lp_ener_fx ); */ IF( st_fx->lp_ener_fx != 0 ) { - Word32 L_tmp; + Word32 L_tmp; Word16 tmp, exp; - exp = norm_l(st_fx->lp_ener_fx); /* In Q6 */ - tmp = extract_h(L_shl(st_fx->lp_ener_fx, exp)); - exp = sub(exp, 30-6); + exp = norm_l( st_fx->lp_ener_fx ); /* In Q6 */ + tmp = extract_h( L_shl( st_fx->lp_ener_fx, exp ) ); + exp = sub( exp, 30 - 6 ); - tmp = div_s(16384, tmp); - L_tmp = L_deposit_h(tmp); - L_tmp = Isqrt_lc(L_tmp, &exp); + tmp = div_s( 16384, tmp ); + L_tmp = L_deposit_h( tmp ); + L_tmp = Isqrt_lc( L_tmp, &exp ); - st_fx->lp_gainc_fx = round_fx(L_shl(L_tmp, sub(exp, 12))); /* In Q3 */ + st_fx->lp_gainc_fx = round_fx( L_shl( L_tmp, sub( exp, 12 ) ) ); /* In Q3 */ } @@ -851,142 +858,146 @@ ivas_error core_switching_pre_dec_fx( /* reset TBE memories */ test(); - IF (!st_fx->last_con_tcx && !((EQ_16(st_fx->last_core, HQ_CORE)) && GT_16(st_fx->element_mode, EVS_MONO))) + IF( !st_fx->last_con_tcx && !( ( EQ_16( st_fx->last_core, HQ_CORE ) ) && GT_16( st_fx->element_mode, EVS_MONO ) ) ) { - set16_fx(st_fx->old_exc_fx,0, L_EXC_MEM_DEC ); + set16_fx( st_fx->old_exc_fx, 0, L_EXC_MEM_DEC ); } - ELSE IF (LT_16(st_fx->L_frame,L_FRAME16k)) + ELSE IF( LT_16( st_fx->L_frame, L_FRAME16k ) ) { /* resample from 16kHz to 12.8kHZ */ synth_mem_updt2( st_fx->L_frame, L_FRAME16k, st_fx->old_exc_fx, st_fx->mem_syn_r, st_fx->mem_syn2_fx, NULL, DEC ); } - IF (hBWE_TD != NULL) + IF( hBWE_TD != NULL ) { - set16_fx(hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2); + set16_fx( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); } - IF( GE_32(st_fx->output_Fs, 16000L) && st_fx->hBWE_zero != NULL) + IF( GE_32( st_fx->output_Fs, 16000L ) && st_fx->hBWE_zero != NULL ) { - hf_synth_reset_fx(st_fx->hBWE_zero); + hf_synth_reset_fx( st_fx->hBWE_zero ); } - IF(hBWE_FD != NULL) + IF( hBWE_FD != NULL ) { - set16_fx(hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA(16000, DELAY_FD_BWE_ENC_NS)); + set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); } } #ifdef IVAS_CODE_SWITCHING - if ((st->core == ACELP_CORE || st->core == AMR_WB_CORE) && (st->last_core == TCX_20_CORE || st->last_core == TCX_10_CORE)) + if ( ( st->core == ACELP_CORE || st->core == AMR_WB_CORE ) && ( st->last_core == TCX_20_CORE || st->last_core == TCX_10_CORE ) ) { - if (st->hBWE_TD != NULL) + if ( st->hBWE_TD != NULL ) { st->hBWE_TD->bwe_non_lin_prev_scale = 0.0f; - set_f(st->hBWE_TD->old_bwe_exc, 0, PIT16k_MAX * 2); + set_f( st->hBWE_TD->old_bwe_exc, 0, PIT16k_MAX * 2 ); } st->tilt_code = 0.0f; st->gc_threshold = 0.0f; - set_f(st->dispMem, 0, 8); + set_f( st->dispMem, 0, 8 ); - st->last_coder_type = GENERIC; + st->last_coder_type = GENERIC; - fer_energy(output_frame, UNVOICED_CLAS, st->previoussynth, -1, &st->enr_old, 1); + fer_energy( output_frame, UNVOICED_CLAS, st->previoussynth, -1, &st->enr_old, 1 ); st->lp_gainp = 0.0f; - st->lp_gainc = (float)sqrt(st->lp_ener); + st->lp_gainc = (float) sqrt( st->lp_ener ); st->last_voice_factor = 0; st->Last_GSC_noisy_speech_flag = 0; - if (st->output_Fs >= 16000 && st->hBWE_zero != NULL) + if ( st->output_Fs >= 16000 && st->hBWE_zero != NULL ) { - hf_synth_reset(st->hBWE_zero); + hf_synth_reset( st->hBWE_zero ); } - if (st->hBWE_FD != NULL) + if ( st->hBWE_FD != NULL ) { - set_f(st->hBWE_FD->old_syn_12k8_16k, 0, NS2SA(16000, DELAY_FD_BWE_ENC_NS)); + set_f( st->hBWE_FD->old_syn_12k8_16k, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); } - if (nchan_out == 1 && st->element_mode == IVAS_CPE_DFT && st->element_brate <= IVAS_24k4 && last_element_brate > IVAS_24k4) + if ( nchan_out == 1 && st->element_mode == IVAS_CPE_DFT && st->element_brate <= IVAS_24k4 && last_element_brate > IVAS_24k4 ) { /* update cldbf state with previous frame TCX synthesis when going from a bitrate with residual coding to a bitrate without it */ int16_t offset; offset = st->cldfbAna->p_filter_length - st->cldfbAna->no_channels; - mvr2r(st->hTcxDec->old_synthFB + st->hTcxDec->old_synth_lenFB - offset, st->cldfbAna->cldfb_state, offset); + mvr2r( st->hTcxDec->old_synthFB + st->hTcxDec->old_synth_lenFB - offset, st->cldfbAna->cldfb_state, offset ); } } #endif - test(); test(); test(); test(); test(); - IF(hHQ_core!= NULL && EQ_16(st_fx->core,HQ_CORE) && (EQ_16(st_fx->last_core,ACELP_CORE) || EQ_16(st_fx->last_core,AMR_WB_CORE) || (NE_16(st_fx->element_mode, EVS_MONO) && NE_16(st_fx->last_core, HQ_CORE ) ) ) ) + test(); + test(); + test(); + test(); + test(); + IF( hHQ_core != NULL && EQ_16( st_fx->core, HQ_CORE ) && ( EQ_16( st_fx->last_core, ACELP_CORE ) || EQ_16( st_fx->last_core, AMR_WB_CORE ) || ( NE_16( st_fx->element_mode, EVS_MONO ) && NE_16( st_fx->last_core, HQ_CORE ) ) ) ) { - set32_fx(hHQ_core->prev_env_fx, 0, SFM_N_WB ); - set32_fx(hHQ_core->prev_normq_fx, 0, SFM_N_WB ); + set32_fx( hHQ_core->prev_env_fx, 0, SFM_N_WB ); + set32_fx( hHQ_core->prev_normq_fx, 0, SFM_N_WB ); - set32_fx(hHQ_core->last_ni_gain_fx, 0, BANDS_MAX ); - set16_fx(hHQ_core->last_env_fx, 0, BANDS_MAX ); + set32_fx( hHQ_core->last_ni_gain_fx, 0, BANDS_MAX ); + set16_fx( hHQ_core->last_env_fx, 0, BANDS_MAX ); hHQ_core->last_max_pos_pulse = 0; - set16_fx(hHQ_core->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM ); + set16_fx( hHQ_core->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM ); hHQ_core->prev_frm_hfe2 = 0; hHQ_core->prev_stab_hfe2 = 0; - IF( GT_32(st_fx->output_Fs,16000)) + IF( GT_32( st_fx->output_Fs, 16000 ) ) { - set32_fx(hHQ_core->prev_coeff_out_fx, 0, L_HQ_WB_BWE ); + set32_fx( hHQ_core->prev_coeff_out_fx, 0, L_HQ_WB_BWE ); } #ifdef IVAS_CODE_SWITCHING - if (st->element_mode != EVS_MONO) + if ( st->element_mode != EVS_MONO ) { /* Estimate mem_env_delta to reinit env_stab */ - tmp = max(0, ENV_STAB_EST1 + (ENV_STAB_EST2 * st->stab_fac_smooth_lt) + (ENV_STAB_EST3 * st->log_energy_diff_lt)); - st->hHQ_core->mem_env_delta = (int16_t)min(MAX16B, (int32_t)(tmp * (1 << 12))); /* Convert to Q12 and handle saturation */ + tmp = max( 0, ENV_STAB_EST1 + ( ENV_STAB_EST2 * st->stab_fac_smooth_lt ) + ( ENV_STAB_EST3 * st->log_energy_diff_lt ) ); + st->hHQ_core->mem_env_delta = (int16_t) min( MAX16B, (int32_t) ( tmp * ( 1 << 12 ) ) ); /* Convert to Q12 and handle saturation */ - if (st->last_core != TCX_20_CORE && st->last_core != TCX_10_CORE) + if ( st->last_core != TCX_20_CORE && st->last_core != TCX_10_CORE ) { - set_f(st->hHQ_core->old_out, 0, output_frame); - set_f(st->hHQ_core->old_outLB, 0, L_FRAME16k); + set_f( st->hHQ_core->old_out, 0, output_frame ); + set_f( st->hHQ_core->old_outLB, 0, L_FRAME16k ); } st->hHQ_core->no_att_hangover = 0; st->hHQ_core->energy_lt = 300.0f; - set_s(st->hHQ_core->old_is_transient, 0, 3); - set_f(st->hHQ_core->prev_noise_level, 0.0f, 2); + set_s( st->hHQ_core->old_is_transient, 0, 3 ); + set_f( st->hHQ_core->prev_noise_level, 0.0f, 2 ); st->hHQ_core->prev_R = 0; - set_s(st->hHQ_core->mem_norm + 1, 39, SFM_N_ENV_STAB - 1); + set_s( st->hHQ_core->mem_norm + 1, 39, SFM_N_ENV_STAB - 1 ); st->hHQ_core->prev_hqswb_clas = HQ_NORMAL; st->hHQ_core->prev_ni_ratio = 0.5f; - set_f(st->hHQ_core->prev_En_sb, 0.0f, NB_SWB_SUBBANDS); + set_f( st->hHQ_core->prev_En_sb, 0.0f, NB_SWB_SUBBANDS ); } else #endif { - set16_fx(hHQ_core->old_out_fx, 0, output_frame); + set16_fx( hHQ_core->old_out_fx, 0, output_frame ); hHQ_core->Q_old_wtda_LB = 15; hHQ_core->Q_old_wtda = 15; #ifdef IVAS_CODE_SWITCHING - set_f(st->hHQ_core->old_outLB, 0, L_FRAME16k); + set_f( st->hHQ_core->old_outLB, 0, L_FRAME16k ); #endif } } /* handle switching cases where preecho_sb was not called in the last frame (memory not up to date) */ - IF (hHQ_core != NULL) + IF( hHQ_core != NULL ) { hHQ_core->pastpre--; - IF(hHQ_core->pastpre <= 0) + IF( hHQ_core->pastpre <= 0 ) { - reset_preecho_dec_fx(hHQ_core); + reset_preecho_dec_fx( hHQ_core ); } } - IF( EQ_32(st_fx->core_brate,FRAME_NO_DATA)) + IF( EQ_32( st_fx->core_brate, FRAME_NO_DATA ) ) { st_fx->VAD = 0; move16(); st_fx->m_frame_type = ZERO_FRAME; move16(); } - ELSE IF( EQ_32(st_fx->core_brate,SID_2k40) || EQ_32(st_fx->core_brate, SID_1k75) ) + ELSE IF( EQ_32( st_fx->core_brate, SID_2k40 ) || EQ_32( st_fx->core_brate, SID_1k75 ) ) { st_fx->VAD = 0; move16(); @@ -1006,25 +1017,25 @@ ivas_error core_switching_pre_dec_fx( test(); test(); test(); - IF(EQ_16(st_fx->element_mode, EVS_MONO)) /* for IVAS modes, st->flag_cna is set earlier */ + IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) /* for IVAS modes, st->flag_cna is set earlier */ { - IF(NE_16(st_fx->core, AMR_WB_CORE) && st_fx->VAD && LE_32(st_fx->total_brate, CNA_MAX_BRATE)) + IF( NE_16( st_fx->core, AMR_WB_CORE ) && st_fx->VAD && LE_32( st_fx->total_brate, CNA_MAX_BRATE ) ) { st_fx->flag_cna = 1; move16(); } - ELSE IF(EQ_16(st_fx->core, AMR_WB_CORE) && st_fx->VAD && LE_32(st_fx->total_brate, ACELP_8k85)) + ELSE IF( EQ_16( st_fx->core, AMR_WB_CORE ) && st_fx->VAD && LE_32( st_fx->total_brate, ACELP_8k85 ) ) { st_fx->flag_cna = 1; move16(); } - ELSE IF(st_fx->VAD || (EQ_16(st_fx->cng_type, FD_CNG) && EQ_16(st_fx->L_frame, L_FRAME16k))) + ELSE IF( st_fx->VAD || ( EQ_16( st_fx->cng_type, FD_CNG ) && EQ_16( st_fx->L_frame, L_FRAME16k ) ) ) { st_fx->flag_cna = 0; move16(); } } - if( EQ_16(st_fx->core,AMR_WB_CORE)) + if ( EQ_16( st_fx->core, AMR_WB_CORE ) ) { st_fx->cng_type = LP_CNG; move16(); @@ -1034,30 +1045,30 @@ ivas_error core_switching_pre_dec_fx( test(); test(); test(); - IF( st_fx->hFdCngDec && ((NE_16(st_fx->last_L_frame,st_fx->L_frame))|| - (NE_16(st_fx->hFdCngDec->hFdCngCom->frameSize,st_fx->L_frame)) || - st_fx->ini_frame == 0 || NE_16(st_fx->bwidth, st_fx->last_bwidth) )) + IF( st_fx->hFdCngDec && ( ( NE_16( st_fx->last_L_frame, st_fx->L_frame ) ) || + ( NE_16( st_fx->hFdCngDec->hFdCngCom->frameSize, st_fx->L_frame ) ) || + st_fx->ini_frame == 0 || NE_16( st_fx->bwidth, st_fx->last_bwidth ) ) ) { - IF( NE_16(st_fx->core,AMR_WB_CORE)) + IF( NE_16( st_fx->core, AMR_WB_CORE ) ) { Word32 tmp; tmp = st_fx->total_brate; move32(); test(); - if( EQ_16(st_fx->rf_flag,1)&&EQ_32(st_fx->total_brate,ACELP_13k20)) + if ( EQ_16( st_fx->rf_flag, 1 ) && EQ_32( st_fx->total_brate, ACELP_13k20 ) ) { tmp = ACELP_9k60; move32(); } - configureFdCngDec_fx(st_fx->hFdCngDec, st_fx->bwidth, tmp, st_fx->L_frame, st_fx->last_L_frame, st_fx->element_mode ); + configureFdCngDec_fx( st_fx->hFdCngDec, st_fx->bwidth, tmp, st_fx->L_frame, st_fx->last_L_frame, st_fx->element_mode ); } ELSE { - configureFdCngDec_fx(st_fx->hFdCngDec, 1, ACELP_8k00, st_fx->L_frame, st_fx->last_L_frame, st_fx->element_mode); + configureFdCngDec_fx( st_fx->hFdCngDec, 1, ACELP_8k00, st_fx->L_frame, st_fx->last_L_frame, st_fx->element_mode ); - if( st_fx->VAD ) + if ( st_fx->VAD ) { st_fx->hFdCngDec->hFdCngCom->CngBitrate = st_fx->total_brate; move32(); @@ -1066,39 +1077,39 @@ ivas_error core_switching_pre_dec_fx( test(); test(); - IF ( NE_16(st_fx->last_L_frame,st_fx->L_frame)&&LE_16(st_fx->L_frame,L_FRAME16k)&&LE_16(st_fx->last_L_frame,L_FRAME16k)) + IF( NE_16( st_fx->last_L_frame, st_fx->L_frame ) && LE_16( st_fx->L_frame, L_FRAME16k ) && LE_16( st_fx->last_L_frame, L_FRAME16k ) ) { test(); #ifdef IVAS_CODE_SWITCHING - IF (EQ_16(st_fx->element_mode, IVAS_CPE_DFT) || EQ_16(st_fx->element_mode, IVAS_CPE_TD)) + IF( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) { - lerp(st_fx->hFdCngDec->hFdCngCom->olapBufferAna + st_fx->last_L_frame, st_fx->hFdCngDec->hFdCngCom->olapBufferAna + st_fx->L_frame, st_fx->L_frame, st_fx->last_L_frame); + lerp( st_fx->hFdCngDec->hFdCngCom->olapBufferAna + st_fx->last_L_frame, st_fx->hFdCngDec->hFdCngCom->olapBufferAna + st_fx->L_frame, st_fx->L_frame, st_fx->last_L_frame ); } #endif - lerp(st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2, st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2, st_fx->L_frame * 2, st_fx->last_L_frame * 2); + lerp( st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2, st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2, st_fx->L_frame * 2, st_fx->last_L_frame * 2 ); test(); - IF( LE_32(st_fx->total_brate,SID_2k40)&&LE_32(st_fx->last_total_brate,SID_2k40)) + IF( LE_32( st_fx->total_brate, SID_2k40 ) && LE_32( st_fx->last_total_brate, SID_2k40 ) ) { - lerp( st_fx->hFdCngDec->hFdCngCom->olapBufferSynth, st_fx->hFdCngDec->hFdCngCom->olapBufferSynth, st_fx->L_frame*2, st_fx->last_L_frame*2 ); - IF( EQ_16(st_fx->L_frame, L_FRAME)) + lerp( st_fx->hFdCngDec->hFdCngCom->olapBufferSynth, st_fx->hFdCngDec->hFdCngCom->olapBufferSynth, st_fx->L_frame * 2, st_fx->last_L_frame * 2 ); + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { - FOR( i=0; i < st_fx->L_frame*2; i++ ) + FOR( i = 0; i < st_fx->L_frame * 2; i++ ) { st_fx->hFdCngDec->hFdCngCom->olapBufferSynth[i] = mult_r( st_fx->hFdCngDec->hFdCngCom->olapBufferSynth[i], 20480 ); } } ELSE { - FOR( i=0; i < st_fx->L_frame*2; i++ ) + FOR( i = 0; i < st_fx->L_frame * 2; i++ ) { - st_fx->hFdCngDec->hFdCngCom->olapBufferSynth[i] = mult_r( shl(st_fx->hFdCngDec->hFdCngCom->olapBufferSynth[i],1), 26214 ); + st_fx->hFdCngDec->hFdCngCom->olapBufferSynth[i] = mult_r( shl( st_fx->hFdCngDec->hFdCngCom->olapBufferSynth[i], 1 ), 26214 ); } } } } } - return error; + return error; } #endif @@ -1110,29 +1121,29 @@ ivas_error core_switching_pre_dec_fx( #ifdef IVAS_FLOAT_FIXED ivas_error core_switching_post_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *synth, /* i/o: output synthesis Qsynth */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *synth, /* i/o: output synthesis Qsynth */ #ifdef IVAS_CODE_SWITCHING - float* output, /* i/o: LB synth/upsampled LB synth */ - float output_mem[], /* i : OLA memory from last TCX/HQ frame */ - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ + float *output, /* i/o: LB synth/upsampled LB synth */ + float output_mem[], /* i : OLA memory from last TCX/HQ frame */ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ #endif - const Word16 output_frame, /* i : frame length */ - const Word16 core_switching_flag, /* i : ACELP->HQ switching flag */ + const Word16 output_frame, /* i : frame length */ + const Word16 core_switching_flag, /* i : ACELP->HQ switching flag */ #ifdef IVAS_CODE_SWITCHING const Word16 sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC */ const Word16 nchan_out, /* i : number of output channels */ #endif - const Word16 last_element_mode, /* i : element mode of previous frame */ - Word16 *Qsynth /* i/o: Scaling of ACELP exit (Q_syn2-1) or HQ exit (Qsynth); changes after this function */ + const Word16 last_element_mode, /* i : element mode of previous frame */ + Word16 *Qsynth /* i/o: Scaling of ACELP exit (Q_syn2-1) or HQ exit (Qsynth); changes after this function */ ) { Word16 i, delay_comp, delta; Word16 tmpF, tmp, Fs_kHz, shift, *ptmp1, *ptmp2; Word32 L_tmp; Word16 synth_subfr_out[SWITCH_MAX_GAP], synth_subfr_bwe[SWITCH_MAX_GAP]; - Word16 mem_synth[NS2SA(16000, DELAY_CLDFB_NS)+2]; + Word16 mem_synth[NS2SA( 16000, DELAY_CLDFB_NS ) + 2]; Word16 Qtmp; Word16 Qsubfr; TD_BWE_DEC_HANDLE hBWE_TD; @@ -1144,44 +1155,46 @@ ivas_error core_switching_post_dec_fx( int16_t offset; #endif #ifdef REMOVE_IVAS_UNUSED_PARAMETERS_WARNING - (void)(last_element_mode); + (void) ( last_element_mode ); #endif hBWE_TD = st_fx->hBWE_TD; hBWE_FD = st_fx->hBWE_FD; hHQ_core = st_fx->hHQ_core; error = IVAS_ERR_OK; - //PMT("core_switching_post_dec_fx : Only handles has been converted, code needs to be entirely reviewed ") + // PMT("core_switching_post_dec_fx : Only handles has been converted, code needs to be entirely reviewed ") /* Rescale synthesis in Q0 to avoid multiple rescaling after */ - tmp = Find_Max_Norm16(synth,output_frame); - Scale_sig(synth,output_frame,tmp); - *Qsynth=add(*Qsynth,tmp); + tmp = Find_Max_Norm16( synth, output_frame ); + Scale_sig( synth, output_frame, tmp ); + *Qsynth = add( *Qsynth, tmp ); - test(); test(); test(); - IF( EQ_16(st_fx->core, ACELP_CORE)&&st_fx->bfi && hHQ_core != NULL && !st_fx->con_tcx) + test(); + test(); + test(); + IF( EQ_16( st_fx->core, ACELP_CORE ) && st_fx->bfi && hHQ_core != NULL && !st_fx->con_tcx ) { - if ((error = acelp_core_switch_dec_bfi_fx( st_fx, hHQ_core->fer_samples_fx, st_fx->coder_type )) != IVAS_ERR_OK) + if ( ( error = acelp_core_switch_dec_bfi_fx( st_fx, hHQ_core->fer_samples_fx, st_fx->coder_type ) ) != IVAS_ERR_OK ) { return error; - } /*the output at Q0*/ + } /*the output at Q0*/ } /* set multiplication factor according to the sampling rate */ - tmp = extract_l(L_shr(st_fx->output_Fs,13)); - Fs_kHz = shl(add(tmp,1),3); + tmp = extract_l( L_shr( st_fx->output_Fs, 13 ) ); + Fs_kHz = shl( add( tmp, 1 ), 3 ); delta = 1; move16(); - if ( GE_16(output_frame, L_FRAME16k)) + if ( GE_16( output_frame, L_FRAME16k ) ) { - delta = shr(Fs_kHz, 3); + delta = shr( Fs_kHz, 3 ); } /* set delay compensation between HQ synthesis and ACELP synthesis */ - delay_comp = i_mult2(delta, HQ_DELAY_COMP); + delay_comp = i_mult2( delta, HQ_DELAY_COMP ); - IF( EQ_16(st_fx->core, HQ_CORE)) + IF( EQ_16( st_fx->core, HQ_CORE ) ) { st_fx->use_acelp_preq = 0; move16(); @@ -1196,32 +1209,32 @@ ivas_error core_switching_post_dec_fx( test(); test(); test(); - IF ( core_switching_flag && EQ_16(st_fx->last_L_frame, st_fx->last_L_frame_ori)&&(EQ_16(st_fx->last_core,ACELP_CORE)||EQ_16(st_fx->last_core,AMR_WB_CORE))) + IF( core_switching_flag && EQ_16( st_fx->last_L_frame, st_fx->last_L_frame_ori ) && ( EQ_16( st_fx->last_core, ACELP_CORE ) || EQ_16( st_fx->last_core, AMR_WB_CORE ) ) ) { - if ((error = acelp_core_switch_dec_fx( st_fx, synth_subfr_out, synth_subfr_bwe, output_frame, core_switching_flag, mem_synth, &Qsubfr )) != IVAS_ERR_OK) + if ( ( error = acelp_core_switch_dec_fx( st_fx, synth_subfr_out, synth_subfr_bwe, output_frame, core_switching_flag, mem_synth, &Qsubfr ) ) != IVAS_ERR_OK ) { return error; } } test(); test(); - IF( core_switching_flag && EQ_16(st_fx->last_core, HQ_CORE)&&st_fx->prev_bfi) + IF( core_switching_flag && EQ_16( st_fx->last_core, HQ_CORE ) && st_fx->prev_bfi ) { Copy( st_fx->delay_buf_out_fx, synth_subfr_out, delay_comp ); - Qsubfr= hHQ_core->Q_old_postdec; + Qsubfr = hHQ_core->Q_old_postdec; } /* delay HQ synthesis to synchronize with ACELP synthesis */ /* rescaling to the min exp of the 2 */ - Qtmp=s_min(*Qsynth, hHQ_core->Q_old_postdec); - Scale_sig(synth, output_frame, sub(Qtmp,*Qsynth)); - *Qsynth=Qtmp; + Qtmp = s_min( *Qsynth, hHQ_core->Q_old_postdec ); + Scale_sig( synth, output_frame, sub( Qtmp, *Qsynth ) ); + *Qsynth = Qtmp; move16(); - Scale_sig(st_fx->delay_buf_out_fx, delay_comp, sub(Qtmp, hHQ_core->Q_old_postdec)); - hHQ_core->Q_old_postdec=Qtmp; + Scale_sig( st_fx->delay_buf_out_fx, delay_comp, sub( Qtmp, hHQ_core->Q_old_postdec ) ); + hHQ_core->Q_old_postdec = Qtmp; move16(); - Copy( synth, &synth[delay_comp], output_frame); + Copy( synth, &synth[delay_comp], output_frame ); Copy( st_fx->delay_buf_out_fx, synth, delay_comp ); Copy( &synth[output_frame], st_fx->delay_buf_out_fx, delay_comp ); @@ -1236,69 +1249,69 @@ ivas_error core_switching_post_dec_fx( test(); test(); test(); - IF ( core_switching_flag && EQ_16(st_fx->last_L_frame, st_fx->last_L_frame_ori)&&(EQ_16(st_fx->last_core,ACELP_CORE)||EQ_16(st_fx->last_core,AMR_WB_CORE))) + IF( core_switching_flag && EQ_16( st_fx->last_L_frame, st_fx->last_L_frame_ori ) && ( EQ_16( st_fx->last_core, ACELP_CORE ) || EQ_16( st_fx->last_core, AMR_WB_CORE ) ) ) { /* mem_over_hp_fx : Qsubfr */ core_switching_OLA_fx( mem_synth, st_fx->last_L_frame, st_fx->output_Fs, synth, synth_subfr_out, synth_subfr_bwe, output_frame, st_fx->bwidth, Qsynth, &Qsubfr ); } - ELSE IF ( core_switching_flag && EQ_16(st_fx->last_core, HQ_CORE)&&st_fx->prev_bfi) /* HQ | ACELP | TRANSITION with ACELP frame lost */ + ELSE IF( core_switching_flag && EQ_16( st_fx->last_core, HQ_CORE ) && st_fx->prev_bfi ) /* HQ | ACELP | TRANSITION with ACELP frame lost */ { /* Overlapp between old->out (stocked in st_fx->fer_samples)and good HQ frame on L/2 */ ptmp1 = &synth[delay_comp]; - shift = i_mult2(Fs_kHz, 10); - tmp = i_mult2(delta,shr(N16_CORE_SW,1)); + shift = i_mult2( Fs_kHz, 10 ); + tmp = i_mult2( delta, shr( N16_CORE_SW, 1 ) ); - Scale_sig(hHQ_core->fer_samples_fx, output_frame, *Qsynth); + Scale_sig( hHQ_core->fer_samples_fx, output_frame, *Qsynth ); ptmp2 = &hHQ_core->fer_samples_fx[tmp]; - tmp = div_s(1, shift); /*Q15*/ + tmp = div_s( 1, shift ); /*Q15*/ tmpF = 0; move16(); - FOR( i=0; icore, HQ_CORE)&&(EQ_16(st_fx->last_core,ACELP_CORE)||EQ_16(st_fx->last_core,AMR_WB_CORE))) /* ACELP | TRANSITION | HQ with TRANSITION lost */ - || (core_switching_flag && st_fx->prev_bfi && NE_16(st_fx->last_L_frame, st_fx->last_L_frame_ori) ) ) + ELSE IF( ( !core_switching_flag && EQ_16( st_fx->core, HQ_CORE ) && ( EQ_16( st_fx->last_core, ACELP_CORE ) || EQ_16( st_fx->last_core, AMR_WB_CORE ) ) ) /* ACELP | TRANSITION | HQ with TRANSITION lost */ + || ( core_switching_flag && st_fx->prev_bfi && NE_16( st_fx->last_L_frame, st_fx->last_L_frame_ori ) ) ) { /* Overlapp between CELP estimation (BFI) and good HQ frame on L/2 */ - shift = i_mult2(Fs_kHz, 10); - tmp = div_s(1, shift); /*Q15*/ + shift = i_mult2( Fs_kHz, 10 ); + tmp = div_s( 1, shift ); /*Q15*/ tmpF = 0; move16(); ptmp1 = synth; - Scale_sig(hHQ_core->fer_samples_fx, output_frame, *Qsynth); + Scale_sig( hHQ_core->fer_samples_fx, output_frame, *Qsynth ); ptmp2 = hHQ_core->fer_samples_fx; - FOR( i=0; ibwe_non_lin_prev_scale_fx = L_deposit_l(0); - IF ( !(EQ_16(inner_frame_tbl[st_fx->bwidth], L_FRAME16k)&&EQ_32(st_fx->core_brate,HQ_32k))) + hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 ); + IF( !( EQ_16( inner_frame_tbl[st_fx->bwidth], L_FRAME16k ) && EQ_32( st_fx->core_brate, HQ_32k ) ) ) { - set32_fx(hHQ_core->prev_env_fx, 0, SFM_N_WB ); - set32_fx(hHQ_core->prev_normq_fx, 0, SFM_N_WB ); + set32_fx( hHQ_core->prev_env_fx, 0, SFM_N_WB ); + set32_fx( hHQ_core->prev_normq_fx, 0, SFM_N_WB ); } - Copy_Scale_sig( synth, st_fx->previoussynth_fx, output_frame, negate(*Qsynth) ); /*scaling of st_fx->previoussynth_fx set at Q0*/ + Copy_Scale_sig( synth, st_fx->previoussynth_fx, output_frame, negate( *Qsynth ) ); /*scaling of st_fx->previoussynth_fx set at Q0*/ /*Set post-filtering flag to zero*/ st_fx->hPFstat->on = 0; @@ -1306,48 +1319,48 @@ ivas_error core_switching_post_dec_fx( } ELSE { - IF ( EQ_16(st_fx->last_core, HQ_CORE)) /* MDCT to ACELP transition */ + IF( EQ_16( st_fx->last_core, HQ_CORE ) ) /* MDCT to ACELP transition */ { - Qtmp = s_min(s_min(*Qsynth, hHQ_core->Q_old_postdec), hHQ_core->Q_old_wtda); + Qtmp = s_min( s_min( *Qsynth, hHQ_core->Q_old_postdec ), hHQ_core->Q_old_wtda ); - Scale_sig(synth, output_frame, sub(Qtmp,*Qsynth)); - Scale_sig(st_fx->delay_buf_out_fx, delay_comp, sub(Qtmp, hHQ_core->Q_old_postdec)); - Scale_sig(hHQ_core->old_out_fx, L_FRAME48k, sub(Qtmp, hHQ_core->Q_old_wtda)); + Scale_sig( synth, output_frame, sub( Qtmp, *Qsynth ) ); + Scale_sig( st_fx->delay_buf_out_fx, delay_comp, sub( Qtmp, hHQ_core->Q_old_postdec ) ); + Scale_sig( hHQ_core->old_out_fx, L_FRAME48k, sub( Qtmp, hHQ_core->Q_old_wtda ) ); *Qsynth = Qtmp; move16(); - hHQ_core->Q_old_postdec=Qtmp; + hHQ_core->Q_old_postdec = Qtmp; move16(); - hHQ_core->Q_old_wtda=Qtmp; + hHQ_core->Q_old_wtda = Qtmp; move16(); - Copy( st_fx->delay_buf_out_fx, synth, delay_comp ); /* copy the HQ/ACELP delay synchroniation buffer at the beginning of ACELP frame */ + Copy( st_fx->delay_buf_out_fx, synth, delay_comp ); /* copy the HQ/ACELP delay synchroniation buffer at the beginning of ACELP frame */ - tmp = i_mult2(delta, N_ZERO_8); - shift = i_mult2(Fs_kHz, 3); + tmp = i_mult2( delta, N_ZERO_8 ); + shift = i_mult2( Fs_kHz, 3 ); test(); IF( st_fx->prev_bfi && hHQ_core->HqVoicing ) { - Copy_Scale_sig(hHQ_core->fer_samples_fx, &hHQ_core->old_out_fx[tmp], shift, *Qsynth ); + Copy_Scale_sig( hHQ_core->fer_samples_fx, &hHQ_core->old_out_fx[tmp], shift, *Qsynth ); } ptmp2 = &hHQ_core->old_out_fx[tmp]; - tmp = div_s(1, shift); + tmp = div_s( 1, shift ); ptmp1 = &synth[delay_comp]; tmpF = 0; move16(); - FOR( i=0; idelay_buf_out_fx, 0, HQ_DELTA_MAX*HQ_DELAY_COMP ); + set16_fx( st_fx->delay_buf_out_fx, 0, HQ_DELTA_MAX * HQ_DELAY_COMP ); hHQ_core->oldHqVoicing = 0; move16(); - set16_fx(hHQ_core->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM); + set16_fx( hHQ_core->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM ); hHQ_core->prev_frm_hfe2 = 0; move16(); hHQ_core->prev_stab_hfe2 = 0; @@ -1367,23 +1380,19 @@ ivas_error core_switching_post_dec_fx( test(); test(); test(); - IF(st_fx->bws_cnt == 0 || (st_fx->bws_cnt > 0 && NE_16(st_fx->coder_type, INACTIVE)&&NE_16(st_fx->coder_type,AUDIO))) + IF( st_fx->bws_cnt == 0 || ( st_fx->bws_cnt > 0 && NE_16( st_fx->coder_type, INACTIVE ) && NE_16( st_fx->coder_type, AUDIO ) ) ) { st_fx->attenu_fx = 3277; move16(); } - IF( ( NE_16(st_fx->last_extl, SWB_BWE)&&EQ_16(st_fx->extl,SWB_BWE))||(NE_16(st_fx->last_extl,FB_BWE)&&EQ_16(st_fx->extl,FB_BWE))|| - ((EQ_16(st_fx->last_core, HQ_CORE) || EQ_16(st_fx->last_extl, SWB_TBE) ) && st_fx->extl < 0 && NE_16(st_fx->core, HQ_CORE) ) - || (EQ_16(st_fx->last_core,ACELP_CORE) && EQ_16(st_fx->core,ACELP_CORE) - && ((NE_16(st_fx->prev_coder_type,INACTIVE) && EQ_16(st_fx->coder_type,INACTIVE) ) || (NE_16(st_fx->prev_coder_type,AUDIO) && EQ_16(st_fx->coder_type,AUDIO) )) - && st_fx->bws_cnt > 0) - ) + IF( ( NE_16( st_fx->last_extl, SWB_BWE ) && EQ_16( st_fx->extl, SWB_BWE ) ) || ( NE_16( st_fx->last_extl, FB_BWE ) && EQ_16( st_fx->extl, FB_BWE ) ) || + ( ( EQ_16( st_fx->last_core, HQ_CORE ) || EQ_16( st_fx->last_extl, SWB_TBE ) ) && st_fx->extl < 0 && NE_16( st_fx->core, HQ_CORE ) ) || ( EQ_16( st_fx->last_core, ACELP_CORE ) && EQ_16( st_fx->core, ACELP_CORE ) && ( ( NE_16( st_fx->prev_coder_type, INACTIVE ) && EQ_16( st_fx->coder_type, INACTIVE ) ) || ( NE_16( st_fx->prev_coder_type, AUDIO ) && EQ_16( st_fx->coder_type, AUDIO ) ) ) && st_fx->bws_cnt > 0 ) ) { - set16_fx(hBWE_FD->L_old_wtda_swb_fx, 0, output_frame ); + set16_fx( hBWE_FD->L_old_wtda_swb_fx, 0, output_frame ); hBWE_FD->old_wtda_swb_fx_exp = 0; move16(); - if( NE_16(st_fx->last_extl, WB_BWE)) + if ( NE_16( st_fx->last_extl, WB_BWE ) ) { hBWE_FD->prev_mode = NORMAL; move16(); @@ -1395,7 +1404,7 @@ ivas_error core_switching_post_dec_fx( move16(); hBWE_FD->prev_frica_flag = 0; move16(); - set16_fx(hBWE_FD->mem_imdct_fx, 0, L_FRAME48k ); + set16_fx( hBWE_FD->mem_imdct_fx, 0, L_FRAME48k ); hBWE_FD->prev_td_energy_fx = 0; move16(); hBWE_FD->prev_weight_fx = 6554; @@ -1406,12 +1415,12 @@ ivas_error core_switching_post_dec_fx( /* reset WB BWE buffers */ test(); - IF( NE_16(st_fx->last_extl, WB_BWE)&&EQ_16(st_fx->extl,WB_BWE)) + IF( NE_16( st_fx->last_extl, WB_BWE ) && EQ_16( st_fx->extl, WB_BWE ) ) { - set16_fx(hBWE_FD->L_old_wtda_swb_fx, 0, output_frame); + set16_fx( hBWE_FD->L_old_wtda_swb_fx, 0, output_frame ); test(); - if ( NE_16(st_fx->last_extl, SWB_BWE)&&NE_16(st_fx->last_extl,FB_BWE)) + if ( NE_16( st_fx->last_extl, SWB_BWE ) && NE_16( st_fx->last_extl, FB_BWE ) ) { hBWE_FD->prev_mode = NORMAL; move16(); @@ -1420,7 +1429,7 @@ ivas_error core_switching_post_dec_fx( move16(); hBWE_FD->prev_L_swb_norm = 8; move16(); - set16_fx(hBWE_FD->mem_imdct_fx, 0, L_FRAME48k ); + set16_fx( hBWE_FD->mem_imdct_fx, 0, L_FRAME48k ); hBWE_FD->prev_flag = 0; move16(); } @@ -1441,36 +1450,33 @@ ivas_error core_switching_post_dec_fx( test(); test(); test(); - IF( (( EQ_16(st_fx->extl, SWB_TBE)||EQ_16(st_fx->extl,FB_TBE)||EQ_16(st_fx->extl,SWB_CNG))&& - ( NE_16(st_fx->L_frame, st_fx->last_L_frame) || ( NE_16(st_fx->last_extl, SWB_TBE) && NE_16(st_fx->last_extl, FB_TBE) ) || EQ_16(st_fx->last_core, HQ_CORE) )) || - ( LT_16(st_fx->bwidth, st_fx->last_bwidth) && NE_16(st_fx->last_extl, SWB_TBE) ) || st_fx->old_ppp_mode - || ((EQ_16(st_fx->prev_coder_type, AUDIO) || EQ_16(st_fx->prev_coder_type, INACTIVE) ) && st_fx->bws_cnt > 0) - || (st_fx->bws_cnt == 0 && EQ_16(st_fx->prev_bws_cnt, N_WS2N_FRAMES)) ) + IF( ( ( EQ_16( st_fx->extl, SWB_TBE ) || EQ_16( st_fx->extl, FB_TBE ) || EQ_16( st_fx->extl, SWB_CNG ) ) && + ( NE_16( st_fx->L_frame, st_fx->last_L_frame ) || ( NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) ) || EQ_16( st_fx->last_core, HQ_CORE ) ) ) || + ( LT_16( st_fx->bwidth, st_fx->last_bwidth ) && NE_16( st_fx->last_extl, SWB_TBE ) ) || st_fx->old_ppp_mode || ( ( EQ_16( st_fx->prev_coder_type, AUDIO ) || EQ_16( st_fx->prev_coder_type, INACTIVE ) ) && st_fx->bws_cnt > 0 ) || ( st_fx->bws_cnt == 0 && EQ_16( st_fx->prev_bws_cnt, N_WS2N_FRAMES ) ) ) { - swb_tbe_reset_fx(hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, - hBWE_TD->syn_overlap_fx, hBWE_TD->state_syn_shbexc_fx, &(hBWE_TD->tbe_demph_fx), &(hBWE_TD->tbe_premph_fx) - , hBWE_TD->mem_stp_swb_fx, &(hBWE_TD->gain_prec_swb_fx) ); + swb_tbe_reset_fx( hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, + hBWE_TD->syn_overlap_fx, hBWE_TD->state_syn_shbexc_fx, &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), hBWE_TD->mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ) ); - set16_fx( st_fx->GainShape_Delay, 0, NUM_SHB_SUBFR/2 ); - swb_tbe_reset_synth_fx(hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx ); + set16_fx( st_fx->GainShape_Delay, 0, NUM_SHB_SUBFR / 2 ); + swb_tbe_reset_synth_fx( hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx ); - IF( EQ_16(output_frame, L_FRAME16k)) + IF( EQ_16( output_frame, L_FRAME16k ) ) { /* reset in case that SWB TBE layer is transmitted, but the output is 16kHz sampled */ - set16_fx(hBWE_TD->mem_resamp_HB_32k_fx, 0, 2*ALLPASSSECTIONS_STEEP+1 ); - set32_fx(hBWE_TD->mem_resamp_HB_32k_fx_32, 0, 2 * ALLPASSSECTIONS_STEEP + 1); + set16_fx( hBWE_TD->mem_resamp_HB_32k_fx, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); + set32_fx( hBWE_TD->mem_resamp_HB_32k_fx_32, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); } - set16_fx(hBWE_TD->int_3_over_2_tbemem_dec_fx, 0, INTERP_3_2_MEM_LEN); - set32_fx(hBWE_TD->int_3_over_2_tbemem_dec_fx_32, 0, INTERP_3_2_MEM_LEN); + set16_fx( hBWE_TD->int_3_over_2_tbemem_dec_fx, 0, INTERP_3_2_MEM_LEN ); + set32_fx( hBWE_TD->int_3_over_2_tbemem_dec_fx_32, 0, INTERP_3_2_MEM_LEN ); } - ELSE IF( ( EQ_16(st_fx->extl, SWB_TBE)||EQ_16(st_fx->extl,FB_TBE))&& - ( NE_32(st_fx->last_total_brate, st_fx->total_brate) || NE_16(st_fx->last_bwidth, st_fx->bwidth) || - NE_16(st_fx->last_codec_mode, MODE1) || NE_16(st_fx->rf_flag, st_fx->rf_flag_last) ) ) + ELSE IF( ( EQ_16( st_fx->extl, SWB_TBE ) || EQ_16( st_fx->extl, FB_TBE ) ) && + ( NE_32( st_fx->last_total_brate, st_fx->total_brate ) || NE_16( st_fx->last_bwidth, st_fx->bwidth ) || + NE_16( st_fx->last_codec_mode, MODE1 ) || NE_16( st_fx->rf_flag, st_fx->rf_flag_last ) ) ) { - set16_fx(hBWE_TD->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); - set16_fx(hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD ); - set16_fx(hBWE_TD->mem_stp_swb_fx, 0, LPC_SHB_ORDER ); - set16_fx(hBWE_TD->mem_zero_swb_fx, 0, LPC_SHB_ORDER ); + set16_fx( hBWE_TD->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); + set16_fx( hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD ); + set16_fx( hBWE_TD->mem_stp_swb_fx, 0, LPC_SHB_ORDER ); + set16_fx( hBWE_TD->mem_zero_swb_fx, 0, LPC_SHB_ORDER ); hBWE_TD->gain_prec_swb_fx = 16384; move16(); /*Q14 = 1 */ } @@ -1479,27 +1485,27 @@ ivas_error core_switching_post_dec_fx( test(); test(); test(); - IF(EQ_32(st_fx->output_Fs,48000)&&((GT_32(st_fx->last_core_brate,SID_2k40))&&(EQ_32(st_fx->core_brate,FRAME_NO_DATA)||EQ_32(st_fx->core_brate,SID_2k40)))) + IF( EQ_32( st_fx->output_Fs, 48000 ) && ( ( GT_32( st_fx->last_core_brate, SID_2k40 ) ) && ( EQ_32( st_fx->core_brate, FRAME_NO_DATA ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) ) ) { - set16_fx(st_fx->interpol_3_2_cng_dec_fx, 0, INTERP_3_2_MEM_LEN ); + set16_fx( st_fx->interpol_3_2_cng_dec_fx, 0, INTERP_3_2_MEM_LEN ); } /* reset FB TBE buffers */ test(); test(); - IF( EQ_16(st_fx->extl, FB_TBE)&&(NE_16(st_fx->last_extl,FB_TBE)||NE_16(st_fx->L_frame,st_fx->last_L_frame))) + IF( EQ_16( st_fx->extl, FB_TBE ) && ( NE_16( st_fx->last_extl, FB_TBE ) || NE_16( st_fx->L_frame, st_fx->last_L_frame ) ) ) { - set16_fx(hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); + set16_fx( hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); hBWE_TD->fb_tbe_demph_fx = 0; - fb_tbe_reset_synth_fx(hBWE_TD->fbbwe_hpf_mem_fx, hBWE_TD->fbbwe_hpf_mem_fx_Q,&hBWE_TD->prev_fbbwe_ratio_fx ); + fb_tbe_reset_synth_fx( hBWE_TD->fbbwe_hpf_mem_fx, hBWE_TD->fbbwe_hpf_mem_fx_Q, &hBWE_TD->prev_fbbwe_ratio_fx ); } /* reset WB TBE buffers */ test(); - IF( NE_16(st_fx->last_extl, WB_TBE)&&EQ_16(st_fx->extl,WB_TBE)) + IF( NE_16( st_fx->last_extl, WB_TBE ) && EQ_16( st_fx->extl, WB_TBE ) ) { - wb_tbe_extras_reset_fx(hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx ); - wb_tbe_extras_reset_synth_fx(hBWE_TD->state_lsyn_filt_shb_fx, hBWE_TD->state_lsyn_filt_dwn_shb_fx, hBWE_TD->state_32and48k_WB_upsample_fx, hBWE_TD->mem_resamp_HB_fx ); + wb_tbe_extras_reset_fx( hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx ); + wb_tbe_extras_reset_synth_fx( hBWE_TD->state_lsyn_filt_shb_fx, hBWE_TD->state_lsyn_filt_dwn_shb_fx, hBWE_TD->state_32and48k_WB_upsample_fx, hBWE_TD->mem_resamp_HB_fx ); set16_fx( hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD / 4 ); set16_fx( hBWE_TD->syn_overlap_fx, 0, L_SHB_LAHEAD ); @@ -1866,7 +1872,7 @@ ivas_error core_switching_post_dec_ivas_fx( hHQ_core->Q_old_wtda = Qtmp; move16(); } - IF ( output_mem_fx != NULL ) + IF( output_mem_fx != NULL ) { Scale_sig( output_mem_fx, NS2SA( st_fx->output_Fs, STEREO_DFT32MS_OVL_NS ), Qtmp ); } @@ -1878,7 +1884,7 @@ ivas_error core_switching_post_dec_ivas_fx( nzeroes = i_mult2( delta, N_ZERO_8 ); shift = i_mult2( Fs_kHz, 3 ); test(); - IF( st_fx->prev_bfi && st_fx->hHQ_core != NULL && hHQ_core->HqVoicing && st_fx->last_core == HQ_CORE ) + IF( st_fx->prev_bfi && st_fx->hHQ_core != NULL && hHQ_core->HqVoicing && st_fx->last_core == HQ_CORE ) { Copy_Scale_sig( hHQ_core->fer_samples_fx, &hHQ_core->old_out_fx[nzeroes], shift, *Qsynth ); } @@ -2031,8 +2037,7 @@ ivas_error core_switching_post_dec_ivas_fx( #ifdef FIX_747_TDBWE_ENERGY_BURST IF( ( ( EQ_16( st_fx->extl, SWB_TBE ) || EQ_16( st_fx->extl, FB_TBE ) || EQ_16( st_fx->extl, SWB_CNG ) ) && ( NE_16( st_fx->L_frame, st_fx->last_L_frame ) || ( NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) && NE_16( st_fx->last_core, TCX_20_CORE ) && NE_16( st_fx->last_core, TCX_10_CORE ) ) || EQ_16( st_fx->last_core, HQ_CORE ) ) ) || - ( LT_16( st_fx->bwidth, st_fx->last_bwidth ) && NE_16( st_fx->last_extl, SWB_TBE ) ) || st_fx->old_ppp_mode || ( ( EQ_16( st_fx->prev_coder_type, AUDIO ) || EQ_16( st_fx->prev_coder_type, INACTIVE ) ) && st_fx->bws_cnt > 0 ) - || ( st_fx->bws_cnt == 0 && EQ_16( st_fx->prev_bws_cnt, N_WS2N_FRAMES ) ) ) + ( LT_16( st_fx->bwidth, st_fx->last_bwidth ) && NE_16( st_fx->last_extl, SWB_TBE ) ) || st_fx->old_ppp_mode || ( ( EQ_16( st_fx->prev_coder_type, AUDIO ) || EQ_16( st_fx->prev_coder_type, INACTIVE ) ) && st_fx->bws_cnt > 0 ) || ( st_fx->bws_cnt == 0 && EQ_16( st_fx->prev_bws_cnt, N_WS2N_FRAMES ) ) ) #else IF( ( ( EQ_16( st_fx->extl, SWB_TBE ) || EQ_16( st_fx->extl, FB_TBE ) || EQ_16( st_fx->extl, SWB_CNG ) ) && ( NE_16( st_fx->L_frame, st_fx->last_L_frame ) || ( NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) ) || EQ_16( st_fx->last_core, HQ_CORE ) ) ) || @@ -2044,8 +2049,8 @@ ivas_error core_switching_post_dec_ivas_fx( hBWE_TD->syn_overlap_fx, hBWE_TD->state_syn_shbexc_fx, &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), hBWE_TD->mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ) ); set16_fx( st_fx->GainShape_Delay, 0, NUM_SHB_SUBFR / 2 ); - //swb_tbe_reset_synth_fx( hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx ); - swb_tbe_reset_synth_ivas_fx( hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32); + // swb_tbe_reset_synth_fx( hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx ); + swb_tbe_reset_synth_ivas_fx( hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32 ); st_fx->hBWE_TD->prev_pow_exc16kWhtnd_fx32 = 1; /* Q0 1.f */ st_fx->hBWE_TD->prev_mix_factor_fx = 32767; /* Q15 1.f */ @@ -2054,7 +2059,7 @@ ivas_error core_switching_post_dec_ivas_fx( { /* reset in case that SWB TBE layer is transmitted, but the output x`x`is 16kHz sampled */ set16_fx( hBWE_TD->mem_resamp_HB_32k_fx, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); - set32_fx(hBWE_TD->mem_resamp_HB_32k_fx_32, 0, 2 * ALLPASSSECTIONS_STEEP + 1); + set32_fx( hBWE_TD->mem_resamp_HB_32k_fx_32, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); } set16_fx( hBWE_TD->int_3_over_2_tbemem_dec_fx, 0, INTERP_3_2_MEM_LEN ); set32_fx( hBWE_TD->int_3_over_2_tbemem_dec_fx_32, 0, INTERP_3_2_MEM_LEN ); @@ -2113,82 +2118,81 @@ ivas_error core_switching_post_dec_ivas_fx( #endif /*---------------------------------------------------------------------* -* core_switching_hq_prepare_dec() -* -* Preprocessing in the first HQ frame after ACELP frame -* - modify bit allocation for HQ core by removing CELP subframe budget -*---------------------------------------------------------------------*/ + * core_switching_hq_prepare_dec() + * + * Preprocessing in the first HQ frame after ACELP frame + * - modify bit allocation for HQ core by removing CELP subframe budget + *---------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED void core_switching_hq_prepare_dec_fx( - Decoder_State *st_fx, /* i/o: encoder state structure */ - Word16 *num_bits, /* i/o: bit budget update */ - const Word16 output_frame /* i : output frame length */ + Decoder_State *st_fx, /* i/o: encoder state structure */ + Word16 *num_bits, /* i/o: bit budget update */ + const Word16 output_frame /* i : output frame length */ ) { Word32 cbrate; test(); - IF( EQ_16(st_fx->last_core, HQ_CORE)&&st_fx->prev_bfi) + IF( EQ_16( st_fx->last_core, HQ_CORE ) && st_fx->prev_bfi ) { - Copy_Scale_sig( st_fx->hHQ_core->old_out_fx, st_fx->hHQ_core->fer_samples_fx, output_frame, negate(st_fx->hHQ_core->Q_old_wtda) ); /*Q0*/ + Copy_Scale_sig( st_fx->hHQ_core->old_out_fx, st_fx->hHQ_core->fer_samples_fx, output_frame, negate( st_fx->hHQ_core->Q_old_wtda ) ); /*Q0*/ } /* set switching frame bitrate */ - IF( EQ_16(st_fx->last_L_frame, L_FRAME)) + IF( EQ_16( st_fx->last_L_frame, L_FRAME ) ) { - cbrate = L_add(st_fx->core_brate, 0); - if( GT_32(st_fx->core_brate, ACELP_24k40)) + cbrate = L_add( st_fx->core_brate, 0 ); + if ( GT_32( st_fx->core_brate, ACELP_24k40 ) ) { - cbrate = L_add(ACELP_24k40, 0); + cbrate = L_add( ACELP_24k40, 0 ); } /* subtract ACELP switching frame bits */ - if( GE_32(st_fx->core_brate, ACELP_11k60)) + if ( GE_32( st_fx->core_brate, ACELP_11k60 ) ) { - (*num_bits) = sub((*num_bits), 1); /* LP_FLAG bit */ + ( *num_bits ) = sub( ( *num_bits ), 1 ); /* LP_FLAG bit */ } - *num_bits = sub( (*num_bits), ACB_bits_tbl[BIT_ALLOC_IDX_fx(cbrate, GENERIC, 0, 0)] ); /* pitch bits*/ - *num_bits = sub( (*num_bits), gain_bits_tbl[BIT_ALLOC_IDX_fx(cbrate, TRANSITION, 0, 0)] ); /* gain bits */ - *num_bits = sub( (*num_bits), FCB_bits_tbl[BIT_ALLOC_IDX_fx(cbrate, GENERIC, 0, 0)] ); /* FCB bits */ + *num_bits = sub( ( *num_bits ), ACB_bits_tbl[BIT_ALLOC_IDX_fx( cbrate, GENERIC, 0, 0 )] ); /* pitch bits*/ + *num_bits = sub( ( *num_bits ), gain_bits_tbl[BIT_ALLOC_IDX_fx( cbrate, TRANSITION, 0, 0 )] ); /* gain bits */ + *num_bits = sub( ( *num_bits ), FCB_bits_tbl[BIT_ALLOC_IDX_fx( cbrate, GENERIC, 0, 0 )] ); /* FCB bits */ } - ELSE /* L_frame == L_FRAME16k */ + ELSE /* L_frame == L_FRAME16k */ { - IF( LE_32(st_fx->core_brate, ACELP_8k00)) + IF( LE_32( st_fx->core_brate, ACELP_8k00 ) ) { - cbrate = L_add(ACELP_8k00, 0); + cbrate = L_add( ACELP_8k00, 0 ); } - ELSE IF( LE_32(st_fx->core_brate, ACELP_14k80)) + ELSE IF( LE_32( st_fx->core_brate, ACELP_14k80 ) ) { - cbrate = L_add(ACELP_14k80, 0); + cbrate = L_add( ACELP_14k80, 0 ); } ELSE { - cbrate = L_min(st_fx->core_brate, ACELP_22k60); + cbrate = L_min( st_fx->core_brate, ACELP_22k60 ); } /* subtract ACELP switching frame bits */ - if( GE_32(st_fx->core_brate, ACELP_11k60)) + if ( GE_32( st_fx->core_brate, ACELP_11k60 ) ) { - (*num_bits) = sub((*num_bits), 1); /* LP_FLAG bit */ + ( *num_bits ) = sub( ( *num_bits ), 1 ); /* LP_FLAG bit */ } - *num_bits = sub((*num_bits), ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(cbrate, GENERIC, 0, 0)]); /* pitch bits*/ - *num_bits = sub((*num_bits), gain_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(cbrate, GENERIC, 0, 0)]); /* gain bits */ - *num_bits = sub((*num_bits), FCB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(cbrate, GENERIC, 0, 0)]); /* FCB bits */ + *num_bits = sub( ( *num_bits ), ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx( cbrate, GENERIC, 0, 0 )] ); /* pitch bits*/ + *num_bits = sub( ( *num_bits ), gain_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx( cbrate, GENERIC, 0, 0 )] ); /* gain bits */ + *num_bits = sub( ( *num_bits ), FCB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx( cbrate, GENERIC, 0, 0 )] ); /* FCB bits */ } /* subtract BWE bits */ test(); test(); - IF( !( ( EQ_16(inner_frame_tbl[st_fx->bwidth], L_FRAME16k)&&EQ_16(st_fx->last_L_frame,L_FRAME16k))||EQ_16(inner_frame_tbl[st_fx->bwidth],L_FRAME8k))) + IF( !( ( EQ_16( inner_frame_tbl[st_fx->bwidth], L_FRAME16k ) && EQ_16( st_fx->last_L_frame, L_FRAME16k ) ) || EQ_16( inner_frame_tbl[st_fx->bwidth], L_FRAME8k ) ) ) { - *num_bits = sub((*num_bits), (NOOFGAINBITS1 + AUDIODELAYBITS)); + *num_bits = sub( ( *num_bits ), ( NOOFGAINBITS1 + AUDIODELAYBITS ) ); } /* reset state of old_out if switching */ set16_fx( st_fx->hHQ_core->old_out_fx, 0, output_frame ); return; - } #endif @@ -2312,22 +2316,22 @@ static void smoothTransitionDtxToTcx_fx( /* apply Mean filter */ w = div_s( 1, filter_len ); - mem = 0; - FOR (i = 0; i < filter_len; i++) - { - mem = L_add(mem, L_deposit_l(smoothing_input_buffer[i])); - } - //mem = sum32_fx( smoothing_input_buffer, filter_len ); + mem = 0; + FOR( i = 0; i < filter_len; i++ ) + { + mem = L_add( mem, L_deposit_l( smoothing_input_buffer[i] ) ); + } + // mem = sum32_fx( smoothing_input_buffer, filter_len ); FOR( i = 0; i < 2 * delay_comp; i++ ) { - smoothing_out_buffer[i] = extract_l(Mpy_32_16_1( mem, w )); + smoothing_out_buffer[i] = extract_l( Mpy_32_16_1( mem, w ) ); move16(); - mem = L_add( mem, L_sub(L_deposit_l(smoothing_input_buffer[i + filter_len]), L_deposit_l(smoothing_input_buffer[i]) )); + mem = L_add( mem, L_sub( L_deposit_l( smoothing_input_buffer[i + filter_len] ), L_deposit_l( smoothing_input_buffer[i] ) ) ); } /* apply fades around transition */ step = div_s( 1, delay_comp ); -#ifndef FIX_680_CNG_FRAME_BOUNDARIES_ISSUE /* Step has to be in Q15, not in Q13 */ +#ifndef FIX_680_CNG_FRAME_BOUNDARIES_ISSUE /* Step has to be in Q15, not in Q13 */ step = shr( step, 2 ); #endif fade_in = extract_l( 0 ); diff --git a/lib_dec/d_gain2p_fx.c b/lib_dec/d_gain2p_fx.c index 335f964d1..fdba24b34 100644 --- a/lib_dec/d_gain2p_fx.c +++ b/lib_dec/d_gain2p_fx.c @@ -10,65 +10,64 @@ #include "stl.h" #include "rom_com.h" #ifdef IVAS_FLOAT_FIXED - /*-------------------------------------------------------------------* - * Decoding of pitch and codebook gains (see q_gain2_plus.c) * - *-------------------------------------------------------------------*/ +/*-------------------------------------------------------------------* + * Decoding of pitch and codebook gains (see q_gain2_plus.c) * + *-------------------------------------------------------------------*/ /********************* * private functions * *********************/ static Word32 calc_gcode0_fx( Word16 *gcode0, - Word16 *exp_gcode0 -) + Word16 *exp_gcode0 ) { Word32 L_tmp; - /*gcode0 = (float)pow(10.0,(gcode0)*0.05);*/ /* predicted gain */ + /*gcode0 = (float)pow(10.0,(gcode0)*0.05);*/ /* predicted gain */ - L_tmp = L_mult(*gcode0, 5443/*0.166096f Q15*/); - *exp_gcode0 = add(1,extract_l(L_shr(L_tmp, 24))); - L_tmp = L_lshl(L_tmp, 7); - L_tmp = L_and(0x7FFFFFFF, L_tmp); + L_tmp = L_mult( *gcode0, 5443 /*0.166096f Q15*/ ); + *exp_gcode0 = add( 1, extract_l( L_shr( L_tmp, 24 ) ) ); + L_tmp = L_lshl( L_tmp, 7 ); + L_tmp = L_and( 0x7FFFFFFF, L_tmp ); - L_tmp = Pow2(30,round_fx(L_tmp)); - *gcode0 = round_fx(L_tmp); + L_tmp = Pow2( 30, round_fx( L_tmp ) ); + *gcode0 = round_fx( L_tmp ); return L_tmp; } -static Word32 calc_gain_code_fx(Word16 g_code, Word16 gcode0, Word16 exp_gcode0) +static Word32 calc_gain_code_fx( Word16 g_code, Word16 gcode0, Word16 exp_gcode0 ) { Word32 L_tmp; - L_tmp = L_mult(g_code, gcode0); /* Q11*Q15 -> Q27 */ - exp_gcode0 = add(exp_gcode0,-11); -#ifdef BASOP_NOGLOB - L_tmp = L_shl_sat(L_tmp, exp_gcode0); /* Q27 -> Q16 */ + L_tmp = L_mult( g_code, gcode0 ); /* Q11*Q15 -> Q27 */ + exp_gcode0 = add( exp_gcode0, -11 ); +#ifdef BASOP_NOGLOB + L_tmp = L_shl_sat( L_tmp, exp_gcode0 ); /* Q27 -> Q16 */ #else - L_tmp = L_shl(L_tmp, exp_gcode0); /* Q27 -> Q16 */ + L_tmp = L_shl( L_tmp, exp_gcode0 ); /* Q27 -> Q16 */ #endif return L_tmp; } /*--------------------------------------------------------------------------* -* Mode2_gain_dec_mless_fx -* -* Decoding of pitch and codebook gains without updating long term energies -*-------------------------------------------------------------------------*/ + * Mode2_gain_dec_mless_fx + * + * Decoding of pitch and codebook gains without updating long term energies + *-------------------------------------------------------------------------*/ static void Mode2_gain_dec_mless_fx( - Word16 index, /* i : Quantization index vector Q0 */ - Word16 *code, /* i : algebraic code excitation Q9 */ - Word16 lcode, /* i : Subframe size Q0 */ - Word16 *gain_pit, /* o : Quantized pitch gain 1Q14 */ - Word32 *gain_code, /* o : Quantized codebook gain Q16 */ - Word16 mean_ener, /* i : mean_ener defined in open-loop Q8 */ - Word16 *past_gpit, /* i/o: past gain of pitch 1Q14 */ - Word32 *past_gcode, /* i/o: past energy of code Q16 */ - Word16 *gain_inov, /* o : unscaled innovation gain 3Q12 */ - Word16 coder_type /* i : coder type for number of bits */ + Word16 index, /* i : Quantization index vector Q0 */ + Word16 *code, /* i : algebraic code excitation Q9 */ + Word16 lcode, /* i : Subframe size Q0 */ + Word16 *gain_pit, /* o : Quantized pitch gain 1Q14 */ + Word32 *gain_code, /* o : Quantized codebook gain Q16 */ + Word16 mean_ener, /* i : mean_ener defined in open-loop Q8 */ + Word16 *past_gpit, /* i/o: past gain of pitch 1Q14 */ + Word32 *past_gcode, /* i/o: past energy of code Q16 */ + Word16 *gain_inov, /* o : unscaled innovation gain 3Q12 */ + Word16 coder_type /* i : coder type for number of bits */ ) { @@ -79,26 +78,25 @@ static void Mode2_gain_dec_mless_fx( Word32 L_tmp, L_tmp1; - /**gain_inov = 1.0f / (float)sqrt( ( dot_product( code, code, lcode ) + 0.01f ) / lcode);*/ - L_tmp = calc_gain_inov(code, lcode, &L_tmp1, &exp_L_tmp1); + L_tmp = calc_gain_inov( code, lcode, &L_tmp1, &exp_L_tmp1 ); move16(); -#ifdef BASOP_NOGLOB - *gain_inov = round_fx_sat(L_shl_sat(L_tmp, 15-3)); /* gain_inov in Q12 */ +#ifdef BASOP_NOGLOB + *gain_inov = round_fx_sat( L_shl_sat( L_tmp, 15 - 3 ) ); /* gain_inov in Q12 */ #else - *gain_inov = round_fx(L_shl(L_tmp, 15-3)); /* gain_inov in Q12 */ + *gain_inov = round_fx( L_shl( L_tmp, 15 - 3 ) ); /* gain_inov in Q12 */ #endif /*-----------------------------------------------------------------* * Select the gains quantization table *-----------------------------------------------------------------*/ t_qua_gain = E_ROM_qua_gain7b_const; - if( coder_type == 0 ) + if ( coder_type == 0 ) { t_qua_gain = E_ROM_qua_gain5b_const; } - if(EQ_16(coder_type,1)) + if ( EQ_16( coder_type, 1 ) ) { t_qua_gain = E_ROM_qua_gain6b_const; } @@ -106,40 +104,39 @@ static void Mode2_gain_dec_mless_fx( /*-----------------------------------------------------------------* * decode pitch gain *-----------------------------------------------------------------*/ - *gain_pit = t_qua_gain[index*2]; + *gain_pit = t_qua_gain[index * 2]; /*-----------------------------------------------------------------* * calculate the predicted gain code *-----------------------------------------------------------------*/ /*ener_code = 10 * log10((dot_product(code, code, lcode) + 0.01) / lcode) */ - L_tmp = BASOP_Util_Log2(L_tmp1); - L_tmp = L_add(L_tmp,L_shl(L_deposit_l(exp_L_tmp1),31-LD_DATA_SCALE)); + L_tmp = BASOP_Util_Log2( L_tmp1 ); + L_tmp = L_add( L_tmp, L_shl( L_deposit_l( exp_L_tmp1 ), 31 - LD_DATA_SCALE ) ); - L_tmp = Mpy_32_16_1(L_tmp, 24660/*(10.0f/3.3219280948873623478703194294894f)/4.0f Q15*/); + L_tmp = Mpy_32_16_1( L_tmp, 24660 /*(10.0f/3.3219280948873623478703194294894f)/4.0f Q15*/ ); /* exponent of L_tmp = 6+2 */ - ener_code = round_fx(L_shl(L_tmp, 6+2-7)); /* Q8 */ + ener_code = round_fx( L_shl( L_tmp, 6 + 2 - 7 ) ); /* Q8 */ /* predicted codebook gain */ - gcode0 = sub(mean_ener, ener_code); /* Q8 */ + gcode0 = sub( mean_ener, ener_code ); /* Q8 */ - /*gcode0 = (float)pow(10.0,(gcode0)*0.05);*/ /* predicted gain */ + /*gcode0 = (float)pow(10.0,(gcode0)*0.05);*/ /* predicted gain */ - calc_gcode0_fx(&gcode0, &exp_gcode0); + calc_gcode0_fx( &gcode0, &exp_gcode0 ); /*-----------------------------------------------------------------* * decode normalized codebook gain *-----------------------------------------------------------------*/ /* *gain_code = t_qua_gain[index*2+1] * gcode0;*/ - L_tmp = calc_gain_code_fx(t_qua_gain[index*2+1], gcode0, exp_gcode0); + L_tmp = calc_gain_code_fx( t_qua_gain[index * 2 + 1], gcode0, exp_gcode0 ); *gain_code = L_tmp; *past_gpit = *gain_pit; /**past_gcode = *gain_code / *gain_inov; */ /* Q16/Q12 => Q5 */ - L_tmp1 = L_deposit_h(BASOP_Util_Divide3216_Scale(L_tmp,*gain_inov,&exp_L_tmp1)); - *past_gcode = L_shl(L_tmp1,sub(exp_L_tmp1,15-12)); - + L_tmp1 = L_deposit_h( BASOP_Util_Divide3216_Scale( L_tmp, *gain_inov, &exp_L_tmp1 ) ); + *past_gcode = L_shl( L_tmp1, sub( exp_L_tmp1, 15 - 12 ) ); return; @@ -152,14 +149,14 @@ static void Mode2_gain_dec_mless_fx( *---------------------------------------------------------------------*/ static void gain_dec_uv_fx( - Word16 index, /* i : Quantization index vector Q0 */ - Word16 *code, /* i : algebraic code excitation Q9 */ - Word16 lcode, /* i : Subframe size Q0 */ - Word16 *gain_pit, /* o : Quantized pitch gain 1Q14 */ - Word32 *gain_code, /* o : Quantized codebook gain Q16 */ - Word16 *past_gpit, /* i/o: past gain of pitch 1Q14 */ - Word32 *past_gcode, /* i/o: past energy of code Q16 */ - Word16 *gain_inov /* o : unscaled innovation gain 3Q12 */ + Word16 index, /* i : Quantization index vector Q0 */ + Word16 *code, /* i : algebraic code excitation Q9 */ + Word16 lcode, /* i : Subframe size Q0 */ + Word16 *gain_pit, /* o : Quantized pitch gain 1Q14 */ + Word32 *gain_code, /* o : Quantized codebook gain Q16 */ + Word16 *past_gpit, /* i/o: past gain of pitch 1Q14 */ + Word32 *past_gcode, /* i/o: past energy of code Q16 */ + Word16 *gain_inov /* o : unscaled innovation gain 3Q12 */ ) { Word16 i, exp_L_tmp1; @@ -170,13 +167,13 @@ static void gain_dec_uv_fx( * Innovation energy (without gain) *-----------------------------------------------------------------*/ /* *gain_inov = 1.0f / (float)sqrt( ( dot_product( code, code, lcode ) + 0.01f ) / lcode );*/ - L_tmp = calc_gain_inov(code, lcode, &L_tmp1, &exp_L_tmp1); + L_tmp = calc_gain_inov( code, lcode, &L_tmp1, &exp_L_tmp1 ); move16(); - *gain_inov = round_fx(L_shl(L_tmp, 15-3)); /* gain_inov in Q12 */ + *gain_inov = round_fx( L_shl( L_tmp, 15 - 3 ) ); /* gain_inov in Q12 */ /*-----------------------------------------------------------------* - * Decode pitch gain - *-----------------------------------------------------------------*/ + * Decode pitch gain + *-----------------------------------------------------------------*/ *gain_pit = 0; move16(); @@ -184,13 +181,13 @@ static void gain_dec_uv_fx( * Decode codebook gain *-----------------------------------------------------------------*/ /* *gain_code= (float)pow(10.f,(((index*1.9f)-30.f)/20.f));*/ - L_tmp = L_mac(-167197708l/*-0.166096*30.0f Q25*/,shl(index, 16-7), 10341/*0.166096f*1.9f Q15*/); - i = add(1,extract_l(L_shr(L_tmp, 25))); - L_tmp = L_lshl(L_tmp, 6); - L_tmp = L_and(0x7FFFFFFF, L_tmp); + L_tmp = L_mac( -167197708l /*-0.166096*30.0f Q25*/, shl( index, 16 - 7 ), 10341 /*0.166096f*1.9f Q15*/ ); + i = add( 1, extract_l( L_shr( L_tmp, 25 ) ) ); + L_tmp = L_lshl( L_tmp, 6 ); + L_tmp = L_and( 0x7FFFFFFF, L_tmp ); - L_tmp = Pow2(30,round_fx(L_tmp)); - L_tmp = L_shl(L_tmp, i-(31-16)); /* Q16 */ + L_tmp = Pow2( 30, round_fx( L_tmp ) ); + L_tmp = L_shl( L_tmp, i - ( 31 - 16 ) ); /* Q16 */ /*-----------------------------------------------------------------* @@ -201,7 +198,7 @@ static void gain_dec_uv_fx( #ifdef BASOP_NOGLOB L_tmp = L_shl_sat( Mpy_32_16_1( L_tmp, *gain_inov ), 3 ); /* Q16*Q12 -> Q13 -> Q16 */ #else - L_tmp = L_shl(Mpy_32_16_1(L_tmp, *gain_inov), 3); /* Q16*Q12 -> Q13 -> Q16 */ + L_tmp = L_shl( Mpy_32_16_1( L_tmp, *gain_inov ), 3 ); /* Q16*Q12 -> Q13 -> Q16 */ #endif *gain_code = L_tmp; move32(); @@ -217,17 +214,17 @@ static void gain_dec_uv_fx( *---------------------------------------------------------------------*/ static void gain_dec_gacelp_uv_fx( - Word16 index, /* i : Quantization index vector Q0 */ - Word16 *code, /* i : algebraic code excitation Q9 */ - Word16 *code2, /* i : algebraic code excitation Q9 */ - Word16 mean_ener, /* i : Q8 */ - Word16 lcode, /* i : Subframe size Q0 */ - Word16 *gain_pit, /* o : Quantized pitch gain 1Q14 */ - Word32 *gain_code, /* o : Quantized codebook gain Q16 */ - Word32 *gain_code2, /* o : Quantized codebook gain Q16 */ - Word16 *past_gpit, /* i/o: past gain of pitch 1Q14 */ - Word32 *past_gcode, /* i/o: past energy of code Q16 */ - Word16 *gain_inov /* o : unscaled innovation gain 3Q12 */ + Word16 index, /* i : Quantization index vector Q0 */ + Word16 *code, /* i : algebraic code excitation Q9 */ + Word16 *code2, /* i : algebraic code excitation Q9 */ + Word16 mean_ener, /* i : Q8 */ + Word16 lcode, /* i : Subframe size Q0 */ + Word16 *gain_pit, /* o : Quantized pitch gain 1Q14 */ + Word32 *gain_code, /* o : Quantized codebook gain Q16 */ + Word32 *gain_code2, /* o : Quantized codebook gain Q16 */ + Word16 *past_gpit, /* i/o: past gain of pitch 1Q14 */ + Word32 *past_gcode, /* i/o: past energy of code Q16 */ + Word16 *gain_inov /* o : unscaled innovation gain 3Q12 */ ) { Word16 i, exp_L_tmp1; @@ -239,32 +236,30 @@ static void gain_dec_gacelp_uv_fx( Word16 index2, s; - - /* pred_nrg_frame = (float)pow(10.0,mean_ener/20.0); */ - L_tmp = L_mult(mean_ener, 10885/*0.166096f * 2 Q15*/); /* 6Q25 */ - pred_nrg_frame = BASOP_Util_InvLog2(L_sub(L_tmp, 503316480l/*15.f Q25*/)); /* 15Q16 */ + L_tmp = L_mult( mean_ener, 10885 /*0.166096f * 2 Q15*/ ); /* 6Q25 */ + pred_nrg_frame = BASOP_Util_InvLog2( L_sub( L_tmp, 503316480l /*15.f Q25*/ ) ); /* 15Q16 */ /*-----------------------------------------------------------------* * Prediction gains *-----------------------------------------------------------------*/ /* gain_inov = 1.0f / sqrt((dot_product(code, code, L_SUBFR) + 0.01) / L_SUBFR) */ - L_tmp = calc_gain_inov(code, lcode, NULL, NULL); - *gain_inov = round_fx(L_shl(L_tmp, 15-3)); /* gain_inov in Q12 */ + L_tmp = calc_gain_inov( code, lcode, NULL, NULL ); + *gain_inov = round_fx( L_shl( L_tmp, 15 - 3 ) ); /* gain_inov in Q12 */ /* gcode = pred_nrg_frame * (*gain_inov); */ - L_tmp = Mpy_32_16_1(pred_nrg_frame, *gain_inov); /* 18Q13 */ - i = norm_l(L_tmp); - g_code = round_fx(L_shl(L_tmp, i)); - exp_gcode = sub(18, i); + L_tmp = Mpy_32_16_1( pred_nrg_frame, *gain_inov ); /* 18Q13 */ + i = norm_l( L_tmp ); + g_code = round_fx( L_shl( L_tmp, i ) ); + exp_gcode = sub( 18, i ); /* norm_code2 = 1.0f / sqrt((dot_product(code2, code2, lcode) + 0.01f) / lcode); */ - L_tmp = calc_gain_inov(code2, lcode, NULL, NULL); - norm_code2 = round_fx(L_shl(L_tmp, 15-3)); /* Q12 */ + L_tmp = calc_gain_inov( code2, lcode, NULL, NULL ); + norm_code2 = round_fx( L_shl( L_tmp, 15 - 3 ) ); /* Q12 */ /* g_code2 = pred_nrg_frame * norm_code2; */ - L_tmp = Mpy_32_16_1(pred_nrg_frame, norm_code2); /* 18Q13 */ - i = norm_l(L_tmp); + L_tmp = Mpy_32_16_1( pred_nrg_frame, norm_code2 ); /* 18Q13 */ + i = norm_l( L_tmp ); #ifdef BASOP_NOGLOB g_code2 = round_fx_sat( L_shl_sat( L_tmp, i ) ); #else @@ -283,45 +278,46 @@ static void gain_dec_gacelp_uv_fx( /*-----------------------------------------------------------------* * past gains for error concealment *-----------------------------------------------------------------*/ - index2=shr(index,5); - index=s_and(index,0x1F); + index2 = shr( index, 5 ); + index = s_and( index, 0x1F ); /**gain_code= (float)pow(10.f,(((index*1.25f)-20.f)/20.f))*gcode;*/ - L_tmp = L_mac(-111465139l/*-0.166096*20.0f Q25*/,shl(index, 16-7), 6803/*0.166096f*1.25f Q15*/); + L_tmp = L_mac( -111465139l /*-0.166096*20.0f Q25*/, shl( index, 16 - 7 ), 6803 /*0.166096f*1.25f Q15*/ ); - i = add(1,extract_l(L_shr(L_tmp, 25))); - L_tmp = L_lshl(L_tmp, 6); - L_tmp = L_and(0x7FFFFFFF, L_tmp); + i = add( 1, extract_l( L_shr( L_tmp, 25 ) ) ); + L_tmp = L_lshl( L_tmp, 6 ); + L_tmp = L_and( 0x7FFFFFFF, L_tmp ); - L_tmp = Pow2(30,round_fx(L_tmp)); - L_tmp = L_shl(L_tmp, i-(31-16)); /* Q16 */ + L_tmp = Pow2( 30, round_fx( L_tmp ) ); + L_tmp = L_shl( L_tmp, i - ( 31 - 16 ) ); /* Q16 */ /* *past_gcode = L_tmp * pred_nrg_frame; */ - i = norm_l(L_tmp); - L_tmp1 = L_shl(L_tmp, i); - exp_L_tmp1 = sub(15, i); + i = norm_l( L_tmp ); + L_tmp1 = L_shl( L_tmp, i ); + exp_L_tmp1 = sub( 15, i ); - i = norm_l(pred_nrg_frame); - L_tmp1 = Mpy_32_32(L_tmp1, L_shl(pred_nrg_frame, i)); - exp_L_tmp1 = add(exp_L_tmp1, sub(15, i)); + i = norm_l( pred_nrg_frame ); + L_tmp1 = Mpy_32_32( L_tmp1, L_shl( pred_nrg_frame, i ) ); + exp_L_tmp1 = add( exp_L_tmp1, sub( 15, i ) ); - *past_gcode = L_shl(L_tmp1, sub(exp_L_tmp1, 15)); /* Q16 */ move32(); + *past_gcode = L_shl( L_tmp1, sub( exp_L_tmp1, 15 ) ); /* Q16 */ + move32(); #ifdef BASOP_NOGLOB *gain_code = L_shl_sat( Mpy_32_16_1( *past_gcode, *gain_inov ), 3 ); #else - *gain_code = L_shl(Mpy_32_16_1(*past_gcode, *gain_inov), 3); + *gain_code = L_shl( Mpy_32_16_1( *past_gcode, *gain_inov ), 3 ); #endif move32(); - L_tmp = Mpy_32_16_1(*gain_code, BASOP_Util_Divide1616_Scale(g_code2, g_code, &s)); - L_tmp = L_shl(L_tmp, sub(sub(add(s, exp_gcode2), exp_gcode), 2)); /* Q16 */ - L_tmp1 = L_add(L_tmp, 0); - FOR (i = 0; i < index2; i++) + L_tmp = Mpy_32_16_1( *gain_code, BASOP_Util_Divide1616_Scale( g_code2, g_code, &s ) ); + L_tmp = L_shl( L_tmp, sub( sub( add( s, exp_gcode2 ), exp_gcode ), 2 ) ); /* Q16 */ + L_tmp1 = L_add( L_tmp, 0 ); + FOR( i = 0; i < index2; i++ ) { - L_tmp1 = L_add(L_tmp1, L_tmp); + L_tmp1 = L_add( L_tmp1, L_tmp ); } *gain_code2 = L_tmp1; @@ -334,51 +330,50 @@ static void gain_dec_gacelp_uv_fx( *********************/ void decode_acelp_gains_fx( - Word16 *code, /* i : algebraic code excitation Q9 */ + Word16 *code, /* i : algebraic code excitation Q9 */ Word16 gains_mode, - Word16 mean_ener_code, /* i : mean_ener defined in open-loop Q8 */ - Word16 *gain_pit, /* o : Quantized pitch gain 1Q14 */ - Word32 *gain_code, /* o : Quantized codebook gain Q16 */ + Word16 mean_ener_code, /* i : mean_ener defined in open-loop Q8 */ + Word16 *gain_pit, /* o : Quantized pitch gain 1Q14 */ + Word32 *gain_code, /* o : Quantized codebook gain Q16 */ Word16 **pt_indice, - Word16 *past_gpit, /* i/o: past gain of pitch 1Q14 */ - Word32 *past_gcode, /* i/o: past energy of code Q16 */ - Word16 *gain_inov, /* o : unscaled innovation gain 3Q12 */ - Word16 L_subfr, /* i : Subframe size Q0 */ - Word16 *code2, /* i : algebraic code excitation Q9 */ - Word32 *gain_code2 /* o : Quantized codebook gain Q16 */ + Word16 *past_gpit, /* i/o: past gain of pitch 1Q14 */ + Word32 *past_gcode, /* i/o: past energy of code Q16 */ + Word16 *gain_inov, /* o : unscaled innovation gain 3Q12 */ + Word16 L_subfr, /* i : Subframe size Q0 */ + Word16 *code2, /* i : algebraic code excitation Q9 */ + Word32 *gain_code2 /* o : Quantized codebook gain Q16 */ ) { Word16 index = 0; index = **pt_indice; - (*pt_indice)++; + ( *pt_indice )++; - IF ( s_and(gains_mode > 0,(Word16) LT_16(gains_mode, 4))) + IF( s_and( gains_mode > 0, (Word16) LT_16( gains_mode, 4 ) ) ) { /* ACELP gains quantizer (5bits/subfr) */ - Mode2_gain_dec_mless_fx(index, code, L_subfr, gain_pit, gain_code, mean_ener_code, past_gpit, past_gcode, gain_inov, gains_mode-1 ); + Mode2_gain_dec_mless_fx( index, code, L_subfr, gain_pit, gain_code, mean_ener_code, past_gpit, past_gcode, gain_inov, gains_mode - 1 ); } - ELSE IF (s_or((Word16)EQ_16(gains_mode,4),(Word16)EQ_16(gains_mode,5))) + ELSE IF( s_or( (Word16) EQ_16( gains_mode, 4 ), (Word16) EQ_16( gains_mode, 5 ) ) ) { /* AMR-WB gains quantizer (6bits/subfr (mode 2) or 7bits/subfr (mode 3)) */ - assert(0); + assert( 0 ); } - ELSE IF ( EQ_16(gains_mode,6)) + ELSE IF( EQ_16( gains_mode, 6 ) ) { /* UV gains quantizer (6bits/subfr) */ gain_dec_uv_fx( index, code, L_subfr, gain_pit, gain_code, past_gpit, past_gcode, gain_inov ); } - ELSE IF (EQ_16(gains_mode,7)) + ELSE IF( EQ_16( gains_mode, 7 ) ) { /* GACELP_UV gains quantizer (7=5-2bits/subfr) */ gain_dec_gacelp_uv_fx( index, code, code2, mean_ener_code, L_subfr, gain_pit, gain_code, gain_code2, past_gpit, past_gcode, gain_inov ); } ELSE { - IVAS_ERROR(IVAS_ERR_INTERNAL, "invalid gains coding for acelp!"); + IVAS_ERROR( IVAS_ERR_INTERNAL, "invalid gains coding for acelp!" ); } - } @@ -389,35 +384,35 @@ void decode_acelp_gains_fx( * innovation energy in all subframes *---------------------------------------------------------------------*/ void d_gain_pred_fx( - Word16 nrg_mode, /* i : NRG moe */ - Word16 *Es_pred, /* o : predicted scaled innovation energy Q8 */ - Word16 **pt_indice /* i/o: pointer to the buffer of indices */ + Word16 nrg_mode, /* i : NRG moe */ + Word16 *Es_pred, /* o : predicted scaled innovation energy Q8 */ + Word16 **pt_indice /* i/o: pointer to the buffer of indices */ ) { Word16 indice; - indice = (Word16)**pt_indice; - (*pt_indice)++; + indice = ( Word16 ) * *pt_indice; + ( *pt_indice )++; *Es_pred = 0; move16(); - if( EQ_16(nrg_mode,1)) + if ( EQ_16( nrg_mode, 1 ) ) { *Es_pred = Es_pred_qua[indice]; move16(); } - if( EQ_16(nrg_mode,2)) + if ( EQ_16( nrg_mode, 2 ) ) { *Es_pred = Es_pred_qua_2[indice]; move16(); } - IF( GT_16(nrg_mode,2)) + IF( GT_16( nrg_mode, 2 ) ) { move16(); - *Es_pred= extract_l(L_mac(-335544320l/* -20.f Q24*/, indice, 224/* 1.75f Q7*/)); /*(Q8 - ((Q0*Q7)=Q8))*/ + *Es_pred = extract_l( L_mac( -335544320l /* -20.f Q24*/, indice, 224 /* 1.75f Q7*/ ) ); /*(Q8 - ((Q0*Q7)=Q8))*/ } return; diff --git a/lib_dec/dec2t32_fx.c b/lib_dec/dec2t32_fx.c index 85181bb88..519d8ed87 100644 --- a/lib_dec/dec2t32_fx.c +++ b/lib_dec/dec2t32_fx.c @@ -2,10 +2,10 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ /*==========================================================================*/ @@ -35,8 +35,8 @@ #ifdef IVAS_FLOAT_FIXED void dec_acelp_2t32_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 code[] /* o: algebraic (fixed) codebook excitation */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 code[] /* o: algebraic (fixed) codebook excitation */ ) { @@ -48,17 +48,17 @@ void dec_acelp_2t32_fx( set16_fx( code, 0, L_SUBFR ); /*------------------------------------------------------------------------------------------* - * decode the positions and signs of pulses and build the codeword - *------------------------------------------------------------------------------------------*/ + * decode the positions and signs of pulses and build the codeword + *------------------------------------------------------------------------------------------*/ - i0 = shl(s_and(shr(index, 6), NB_POS_FCB_2T-1), 1); + i0 = shl( s_and( shr( index, 6 ), NB_POS_FCB_2T - 1 ), 1 ); - i1 = add(shl(s_and(index, NB_POS_FCB_2T-1), 1), 1); + i1 = add( shl( s_and( index, NB_POS_FCB_2T - 1 ), 1 ), 1 ); code[i0] = -512; move16(); - if (s_and(index, 0x800) == 0) + if ( s_and( index, 0x800 ) == 0 ) { code[i0] = 512; move16(); @@ -66,12 +66,11 @@ void dec_acelp_2t32_fx( code[i1] = -512; move16(); - if (s_and(index, 0x20) == 0) + if ( s_and( index, 0x20 ) == 0 ) { code[i1] = 512; move16(); } - } /*==========================================================================*/ @@ -95,41 +94,40 @@ void dec_acelp_2t32_fx( /* CALLED FROM : */ /*==========================================================================*/ void dec_acelp_1t64_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 code[], /* o: algebraic (fixed) codebook excitation Q12*/ - const Word16 L_subfr /* i : sub frame lenght*/ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 code[], /* o: algebraic (fixed) codebook excitation Q12*/ + const Word16 L_subfr /* i : sub frame lenght*/ ) { - Word16 pos,sgn; + Word16 pos, sgn; /*-----------------------------------------------------------------* - * decode the positions and signs of pulses and build the codeword - *-----------------------------------------------------------------*/ - IF ( EQ_16(L_subfr, L_SUBFR) ) + * decode the positions and signs of pulses and build the codeword + *-----------------------------------------------------------------*/ + IF( EQ_16( L_subfr, L_SUBFR ) ) { - pos = (Word16)get_next_indice(st_fx, 7); + pos = (Word16) get_next_indice( st_fx, 7 ); move16(); } ELSE /* L_subfr == 2*L_SUBFR */ { - pos = (Word16)get_next_indice(st_fx, 8); + pos = (Word16) get_next_indice( st_fx, 8 ); move16(); } sgn = -512; move16(); - IF( GE_16(pos, L_subfr)) + IF( GE_16( pos, L_subfr ) ) { - pos = sub(pos, L_subfr); + pos = sub( pos, L_subfr ); move16(); sgn = 512; move16(); } - set16_fx(code, 0, L_subfr); + set16_fx( code, 0, L_subfr ); code[pos] = sgn; move16(); return; - } #endif diff --git a/lib_dec/dec4t64.c b/lib_dec/dec4t64.c index 4b02cfb2f..9563ac643 100644 --- a/lib_dec/dec4t64.c +++ b/lib_dec/dec4t64.c @@ -1027,4 +1027,4 @@ void dec_acelp_fast( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/dec4t64_fx.c b/lib_dec/dec4t64_fx.c index ec9dc300c..6186891de 100644 --- a/lib_dec/dec4t64_fx.c +++ b/lib_dec/dec4t64_fx.c @@ -2,25 +2,25 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "rom_com.h" /* Static table prototypes */ -#include "assert.h" /* Static table prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "rom_com.h" /* Static table prototypes */ +#include "assert.h" /* Static table prototypes */ #ifdef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * Local functions *-------------------------------------------------------------------*/ -static void add_pulses_fx(const Word16 pos[],const Word16 nb_pulse, const Word16 track,Word16 code[]); -static void dec_1p_N1_fx(const Word32 index, const Word16 N, const Word16 offset, Word16 pos[] ); -static void dec_2p_2N1_fx(const Word32 index, const Word16 N, const Word16 offset, Word16 pos[] ); -static void dec_3p_3N1_fx(const Word32 index, const Word16 N, const Word16 offset, Word16 pos[] ); -static void dec_4p_4N1_fx(const Word32 index, const Word16 N, const Word16 offset, Word16 pos[] ); -static void dec_4p_4N_fx(const Word32 index, const Word16 N, const Word16 offset, Word16 pos[]); -static void dec_5p_5N_fx(const Word32 index,const Word16 N,const Word16 offset,Word16 pos[]); -static void dec_6p_6N2_fx(const Word32 index,const Word16 N,const Word16 offset,Word16 pos[]); -static void fcb_decode_PI_fx(Word32 code_index,Word16 sector_6p[],Word16 pulse_num); +static void add_pulses_fx( const Word16 pos[], const Word16 nb_pulse, const Word16 track, Word16 code[] ); +static void dec_1p_N1_fx( const Word32 index, const Word16 N, const Word16 offset, Word16 pos[] ); +static void dec_2p_2N1_fx( const Word32 index, const Word16 N, const Word16 offset, Word16 pos[] ); +static void dec_3p_3N1_fx( const Word32 index, const Word16 N, const Word16 offset, Word16 pos[] ); +static void dec_4p_4N1_fx( const Word32 index, const Word16 N, const Word16 offset, Word16 pos[] ); +static void dec_4p_4N_fx( const Word32 index, const Word16 N, const Word16 offset, Word16 pos[] ); +static void dec_5p_5N_fx( const Word32 index, const Word16 N, const Word16 offset, Word16 pos[] ); +static void dec_6p_6N2_fx( const Word32 index, const Word16 N, const Word16 offset, Word16 pos[] ); +static void fcb_decode_PI_fx( Word32 code_index, Word16 sector_6p[], Word16 pulse_num ); /*==========================================================================*/ @@ -52,11 +52,10 @@ static void fcb_decode_PI_fx(Word32 code_index,Word16 sector_6p[],Word16 pulse_n /* CALLED FROM : */ /*==========================================================================*/ void dec_acelp_4t64_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 nbbits, /* i : number of bits per codebook */ - Word16 code[], /* o : algebraic (fixed) codebook excitation Q9*/ - const Word16 Opt_AMR_WB -) + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 nbbits, /* i : number of bits per codebook */ + Word16 code[], /* o : algebraic (fixed) codebook excitation Q9*/ + const Word16 Opt_AMR_WB ) { Word16 i, k, pos[7]; Word32 L_index; @@ -64,44 +63,44 @@ void dec_acelp_4t64_fx( PulseConfig config; Word16 indexing_indices[6], wordcnt, bitcnt, index2; - IF ( !Opt_AMR_WB ) + IF( !Opt_AMR_WB ) { - SWITCH (nbbits) + SWITCH( nbbits ) { - case 20: - config.nb_pulse = 4; - move16(); - BREAK; + case 20: + config.nb_pulse = 4; + move16(); + BREAK; - case 28: - config.nb_pulse = 6; - move16(); - BREAK; + case 28: + config.nb_pulse = 6; + move16(); + BREAK; - case 36: - config.nb_pulse = 8; - move16(); - BREAK; + case 36: + config.nb_pulse = 8; + move16(); + BREAK; - case 43: - config.nb_pulse = 10; - move16(); - BREAK; + case 43: + config.nb_pulse = 10; + move16(); + BREAK; - case 50: - config.nb_pulse = 12; - move16(); - BREAK; + case 50: + config.nb_pulse = 12; + move16(); + BREAK; - case 62: - config.nb_pulse = 16; - move16(); - BREAK; + case 62: + config.nb_pulse = 16; + move16(); + BREAK; - case 87: - config.nb_pulse = 26; - move16(); - BREAK; + case 87: + config.nb_pulse = 26; + move16(); + BREAK; } config.bits = nbbits; @@ -110,14 +109,14 @@ void dec_acelp_4t64_fx( move16(); - wordcnt = shr(nbbits, 4); - bitcnt = s_and(nbbits, 15); - FOR ( i = 0; i < wordcnt; i++ ) + wordcnt = shr( nbbits, 4 ); + bitcnt = s_and( nbbits, 15 ); + FOR( i = 0; i < wordcnt; i++ ) { indexing_indices[i] = get_next_indice( st_fx, 16 ); move16(); } - IF ( bitcnt ) + IF( bitcnt ) { indexing_indices[i] = get_next_indice( st_fx, bitcnt ); move16(); @@ -127,107 +126,107 @@ void dec_acelp_4t64_fx( } ELSE { - FOR (i=0; i> N) & 1); */ - i = L_shr(index, N) & 1L; + i = L_shr( index, N ) & 1L; - if (i != 0) + if ( i != 0 ) { - pos1 = add(pos1, NB_POS_FCB_4T); + pos1 = add( pos1, NB_POS_FCB_4T ); } pos[0] = pos1; move16(); @@ -311,48 +310,48 @@ void dec_1p_N1_fx( *-------------------------------------------------------*/ void dec_2p_2N1_fx( - const Word32 index, /* i: quantization index */ - const Word16 N, /* i: nb. of bits */ - const Word16 offset, /* i: pulse position offset */ - Word16 pos[] /* o: pulse position */ + const Word32 index, /* i: quantization index */ + const Word16 N, /* i: nb. of bits */ + const Word16 offset, /* i: pulse position offset */ + Word16 pos[] /* o: pulse position */ ) { - Word16 pos1, pos2, tmp; - Word32 mask, i; + Word16 pos1, pos2, tmp; + Word32 mask, i; - mask = L_deposit_l(sub(shl(1, N), 1)); /* mask = ((1<> N) & mask) + offset); */ logic16(); - pos1 = extract_l(L_add((L_shr(index, N) & mask), L_deposit_l(offset))); + pos1 = extract_l( L_add( ( L_shr( index, N ) & mask ), L_deposit_l( offset ) ) ); /* i = (index >> (2*N)) & 1; */ - tmp = shl(N, 1); - i = L_and(L_shr(index, tmp), 1L); + tmp = shl( N, 1 ); + i = L_and( L_shr( index, tmp ), 1L ); /* pos2 = ((index & mask) + offset); */ - pos2 = add(extract_l(index & mask), offset); + pos2 = add( extract_l( index & mask ), offset ); logic16(); - IF (LT_16(pos2, pos1)) + IF( LT_16( pos2, pos1 ) ) { - IF (i != 0) + IF( i != 0 ) { - pos1 = add(pos1, NB_POS_FCB_4T); + pos1 = add( pos1, NB_POS_FCB_4T ); } ELSE { - pos2 = add(pos2, NB_POS_FCB_4T); + pos2 = add( pos2, NB_POS_FCB_4T ); } } ELSE { - IF (i != 0) + IF( i != 0 ) { - pos1 = add(pos1, NB_POS_FCB_4T); - pos2 = add(pos2, NB_POS_FCB_4T); + pos1 = add( pos1, NB_POS_FCB_4T ); + pos2 = add( pos2, NB_POS_FCB_4T ); } } @@ -362,45 +361,44 @@ void dec_2p_2N1_fx( move16(); return; - } /*-------------------------------------------------------* -* Dec_3p_3N1 -* -* Decode 3 pulses with 3*N+1 bits: -*-------------------------------------------------------*/ + * Dec_3p_3N1 + * + * Decode 3 pulses with 3*N+1 bits: + *-------------------------------------------------------*/ static void dec_3p_3N1_fx( - const Word32 index, /* i : quantization index */ - const Word16 N, /* i : nb. of bits */ - const Word16 offset, /* i : pulse position offset */ - Word16 pos[] /* o : pulse position */ + const Word32 index, /* i : quantization index */ + const Word16 N, /* i : nb. of bits */ + const Word16 offset, /* i : pulse position offset */ + Word16 pos[] /* o : pulse position */ ) { Word16 j, tmp; Word32 mask, idx; - tmp = sub(shl(N, 1), 1); /* mask = ((1<<((2*N)-1))-1); */ - mask = L_sub(L_shl(1L, tmp), 1L); + tmp = sub( shl( N, 1 ), 1 ); /* mask = ((1<<((2*N)-1))-1); */ + mask = L_sub( L_shl( 1L, tmp ), 1L ); - idx = L_and(index, mask); + idx = L_and( index, mask ); j = offset; move16(); - tmp = sub(shl(N, 1), 1); + tmp = sub( shl( N, 1 ), 1 ); logic16(); - IF ((L_shr(index, tmp) & 1L) != 0) + IF( ( L_shr( index, tmp ) & 1L ) != 0 ) { /* IF (((index >> ((2*N)-1)) & 1) == 1){ */ - j = add(j, shl(1, sub(N, 1))); /* j += (1<<(N-1)); */ + j = add( j, shl( 1, sub( N, 1 ) ) ); /* j += (1<<(N-1)); */ } - dec_2p_2N1_fx(idx, sub(N, 1), j, pos); + dec_2p_2N1_fx( idx, sub( N, 1 ), j, pos ); - mask = sub(shl(1, add(N, 1)), 1); /* mask = ((1<<(N+1))-1); */ - tmp = shl(N, 1); /* idx = (index >> (2*N)) & mask; */ - idx = L_shr(index, tmp) & mask; + mask = sub( shl( 1, add( N, 1 ) ), 1 ); /* mask = ((1<<(N+1))-1); */ + tmp = shl( N, 1 ); /* idx = (index >> (2*N)) & mask; */ + idx = L_shr( index, tmp ) & mask; logic16(); - dec_1p_N1_fx(idx, N, offset, pos + 2); + dec_1p_N1_fx( idx, N, offset, pos + 2 ); } /*-------------------------------------------------------* @@ -409,93 +407,93 @@ static void dec_3p_3N1_fx( * Decode 4 pulses with 4*N+1 bits: *-------------------------------------------------------*/ static void dec_4p_4N1_fx( - const Word32 index, /* i : quantization index */ - const Word16 N, /* i : nb. of bits */ - const Word16 offset, /* i : pulse position offset */ - Word16 pos[] /* o : pulse position */ + const Word32 index, /* i : quantization index */ + const Word16 N, /* i : nb. of bits */ + const Word16 offset, /* i : pulse position offset */ + Word16 pos[] /* o : pulse position */ ) { Word16 j, tmp; Word32 mask, idx; - tmp = sub(shl(N, 1), 1); /* mask = ((1<<((2*N)-1))-1); */ - mask = L_sub(L_shl(1L, tmp), 1L); - idx = L_and(index, mask); + tmp = sub( shl( N, 1 ), 1 ); /* mask = ((1<<((2*N)-1))-1); */ + mask = L_sub( L_shl( 1L, tmp ), 1L ); + idx = L_and( index, mask ); j = offset; move16(); - tmp = sub(shl(N, 1), 1); + tmp = sub( shl( N, 1 ), 1 ); logic16(); - IF((L_shr(index, tmp) & 1L) != 0L) + IF( ( L_shr( index, tmp ) & 1L ) != 0L ) { /* (((index >> ((2*N)-1)) & 1) == 1) */ - j = add(j, shl(1, sub(N, 1))); /* j += (1<<(N-1)); */ + j = add( j, shl( 1, sub( N, 1 ) ) ); /* j += (1<<(N-1)); */ } - dec_2p_2N1_fx(idx, sub(N, 1), j, pos); + dec_2p_2N1_fx( idx, sub( N, 1 ), j, pos ); - tmp = add(shl(N, 1), 1); /* mask = ((1<<((2*N)+1))-1); */ - mask = L_sub(L_shl(1L, tmp), 1L); - idx = L_shr(index, shl(N, 1)) & mask; - logic16();/* idx = (index >> (2*N)) & mask; */ - dec_2p_2N1_fx(idx, N, offset, pos + 2); /* Dec_2p_2N1(idx, N, offset, pos+2); */ + tmp = add( shl( N, 1 ), 1 ); /* mask = ((1<<((2*N)+1))-1); */ + mask = L_sub( L_shl( 1L, tmp ), 1L ); + idx = L_shr( index, shl( N, 1 ) ) & mask; + logic16(); /* idx = (index >> (2*N)) & mask; */ + dec_2p_2N1_fx( idx, N, offset, pos + 2 ); /* Dec_2p_2N1(idx, N, offset, pos+2); */ } /*-------------------------------------------------------* -* Dec_4p_4N -* -* Decode 4 pulses with 4*N bits: -*-------------------------------------------------------*/ + * Dec_4p_4N + * + * Decode 4 pulses with 4*N bits: + *-------------------------------------------------------*/ static void dec_4p_4N_fx( - const Word32 index, /* i : quantization index */ - const Word16 N, /* i : nb. of bits */ - const Word16 offset, /* i : pulse position offset */ - Word16 pos[] /* o : pulse position */ + const Word32 index, /* i : quantization index */ + const Word16 N, /* i : nb. of bits */ + const Word16 offset, /* i : pulse position offset */ + Word16 pos[] /* o : pulse position */ ) { Word16 j, n_1, tmp; - n_1 = sub(N, 1); - j = add(offset, shl(1, n_1)); /* j = offset + (1 << n_1) */ + n_1 = sub( N, 1 ); + j = add( offset, shl( 1, n_1 ) ); /* j = offset + (1 << n_1) */ - tmp = sub(shl(N, 2), 2); + tmp = sub( shl( N, 2 ), 2 ); logic16(); - SWITCH (L_shr(index, tmp) & 3) + SWITCH( L_shr( index, tmp ) & 3 ) { - /* ((index >> ((4*N)-2)) & 3) */ - case 0: - tmp = add(shl(n_1, 2), 1); + /* ((index >> ((4*N)-2)) & 3) */ + case 0: + tmp = add( shl( n_1, 2 ), 1 ); - logic16(); - IF((L_shr(index, tmp) & 1) == 0) - { - /* (((index >> ((4*n_1)+1)) & 1) == 0) */ - dec_4p_4N1_fx(index, n_1, offset, pos); - } - ELSE - { - dec_4p_4N1_fx(index, n_1, j, pos); - } - BREAK; - case 1: - tmp = add(extract_l(L_shr(L_mult(3, n_1), 1)), 1); /* Dec_1p_N1((index>>((3*n_1)+1)), n_1, offset, pos) */ - dec_1p_N1_fx(L_shr(index, tmp), n_1, offset, pos); - dec_3p_3N1_fx(index, n_1, j, pos + 1); - move16(); - BREAK; - case 2: - tmp = add(shl(n_1, 1), 1); /* Dec_2p_2N1((index>>((2*n_1)+1)), n_1, offset, pos) */ - dec_2p_2N1_fx(L_shr(index, tmp), n_1, offset, pos); - dec_2p_2N1_fx(index, n_1, j, pos + 2); - move16(); - BREAK; - case 3: - tmp = add(n_1, 1); /* Dec_3p_3N1((index>>(n_1+1)), n_1, offset, pos) */ - dec_3p_3N1_fx(L_shr(index, tmp), n_1, offset, pos); - dec_1p_N1_fx(index, n_1, j, pos + 3); - move16(); - BREAK; + logic16(); + IF( ( L_shr( index, tmp ) & 1 ) == 0 ) + { + /* (((index >> ((4*n_1)+1)) & 1) == 0) */ + dec_4p_4N1_fx( index, n_1, offset, pos ); + } + ELSE + { + dec_4p_4N1_fx( index, n_1, j, pos ); + } + BREAK; + case 1: + tmp = add( extract_l( L_shr( L_mult( 3, n_1 ), 1 ) ), 1 ); /* Dec_1p_N1((index>>((3*n_1)+1)), n_1, offset, pos) */ + dec_1p_N1_fx( L_shr( index, tmp ), n_1, offset, pos ); + dec_3p_3N1_fx( index, n_1, j, pos + 1 ); + move16(); + BREAK; + case 2: + tmp = add( shl( n_1, 1 ), 1 ); /* Dec_2p_2N1((index>>((2*n_1)+1)), n_1, offset, pos) */ + dec_2p_2N1_fx( L_shr( index, tmp ), n_1, offset, pos ); + dec_2p_2N1_fx( index, n_1, j, pos + 2 ); + move16(); + BREAK; + case 3: + tmp = add( n_1, 1 ); /* Dec_3p_3N1((index>>(n_1+1)), n_1, offset, pos) */ + dec_3p_3N1_fx( L_shr( index, tmp ), n_1, offset, pos ); + dec_1p_N1_fx( index, n_1, j, pos + 3 ); + move16(); + BREAK; } } @@ -506,32 +504,32 @@ static void dec_4p_4N_fx( * Decode 5 pulses with 5*N bits: *-------------------------------------------------------*/ static void dec_5p_5N_fx( - const Word32 index, /* i : quantization index */ - const Word16 N, /* i : nb. of bits */ - const Word16 offset, /* i : pulse position offset */ - Word16 pos[] /* o : pulse position */ + const Word32 index, /* i : quantization index */ + const Word16 N, /* i : nb. of bits */ + const Word16 offset, /* i : pulse position offset */ + Word16 pos[] /* o : pulse position */ ) { Word16 j, n_1, tmp; Word32 idx; - n_1 = sub(N, 1); - j = add(offset, shl(1, n_1)); /* j = offset + (1 << n_1); */ - tmp = add(shl(N, 1), 1); /* idx = (index >> ((2*N)+1)); */ - idx = L_shr(index, tmp); - tmp = sub(extract_l(L_shr(L_mult(5, N), 1)), 1); /* ((5*N)-1)) */ + n_1 = sub( N, 1 ); + j = add( offset, shl( 1, n_1 ) ); /* j = offset + (1 << n_1); */ + tmp = add( shl( N, 1 ), 1 ); /* idx = (index >> ((2*N)+1)); */ + idx = L_shr( index, tmp ); + tmp = sub( extract_l( L_shr( L_mult( 5, N ), 1 ) ), 1 ); /* ((5*N)-1)) */ logic16(); - IF ((L_shr(index, tmp) & 1) == 0) /* ((index >> ((5*N)-1)) & 1) */ + IF( ( L_shr( index, tmp ) & 1 ) == 0 ) /* ((index >> ((5*N)-1)) & 1) */ { - dec_3p_3N1_fx(idx, n_1, offset, pos); - dec_2p_2N1_fx(index, N, offset, pos + 3); + dec_3p_3N1_fx( idx, n_1, offset, pos ); + dec_2p_2N1_fx( index, N, offset, pos + 3 ); move16(); } ELSE { - dec_3p_3N1_fx(idx, n_1, j, pos); - dec_2p_2N1_fx(index, N, offset, pos + 3); + dec_3p_3N1_fx( idx, n_1, j, pos ); + dec_2p_2N1_fx( index, N, offset, pos + 3 ); move16(); } } @@ -542,24 +540,24 @@ static void dec_5p_5N_fx( * Decode 6 pulses with 6*N+2 bits: *-------------------------------------------------------*/ static void dec_6p_6N2_fx( - const Word32 index, /* i : quantization index */ - const Word16 N, /* i : nb. of bits */ - const Word16 offset, /* i : pulse position offset */ - Word16 pos[] /* o : pulse position */ + const Word32 index, /* i : quantization index */ + const Word16 N, /* i : nb. of bits */ + const Word16 offset, /* i : pulse position offset */ + Word16 pos[] /* o : pulse position */ ) { Word16 j, n_1, offsetA, offsetB, n_6; - n_1 = sub(N, 1); - j = add(offset, shl(1, n_1)); /* j = offset + (1 << n_1); */ - n_6 = extract_l(L_mult0(N, 6)); + n_1 = sub( N, 1 ); + j = add( offset, shl( 1, n_1 ) ); /* j = offset + (1 << n_1); */ + n_6 = extract_l( L_mult0( N, 6 ) ); /* !! N and n_1 are constants -> it doesn't need to be operated by Basic Operators */ offsetA = offsetB = j; move16(); logic16(); - IF ((L_shr(index, sub(n_6, 5)) & 1L) == 0) + IF( ( L_shr( index, sub( n_6, 5 ) ) & 1L ) == 0 ) { /* IF (((index >> ((6*N)-5)) & 1) == 0) */ offsetA = offset; @@ -573,154 +571,150 @@ static void dec_6p_6N2_fx( logic16(); - SWITCH (L_shr(index, sub(n_6, 4)) & 3) + SWITCH( L_shr( index, sub( n_6, 4 ) ) & 3 ) { - /* (index >> ((6*N)-4)) & 3 */ - case 0: - dec_5p_5N_fx(L_shr(index, N), n_1, offsetA, pos); /* Dec_5p_5N(index>>N, n_1, offsetA, pos); */ - dec_1p_N1_fx(index, n_1, offsetA, pos + 5); - move16(); - BREAK; - case 1: - dec_5p_5N_fx(L_shr(index, N), n_1, offsetA, pos); /* Dec_5p_5N(index>>N, n_1, offsetA, pos); */ - dec_1p_N1_fx(index, n_1, offsetB, pos + 5); - move16(); - BREAK; - case 2: - dec_4p_4N_fx(L_shr(index, add(shl(n_1,1),1)), n_1, offsetA, pos); /* Dec_4p_4N(index>>((2*n_1)+1 ), n_1, offsetA, pos); */ - dec_2p_2N1_fx(index, n_1, offsetB, pos + 4); - move16(); - BREAK; - case 3: - dec_3p_3N1_fx(L_shr(index, add(add(shl(n_1, 1),n_1), 1)), n_1, offset, pos); /* Dec_3p_3N1(index>>((3*n_1)+ 1), n_1, offset, pos); */ - dec_3p_3N1_fx(index, n_1, j, pos + 3); - move16(); - BREAK; + /* (index >> ((6*N)-4)) & 3 */ + case 0: + dec_5p_5N_fx( L_shr( index, N ), n_1, offsetA, pos ); /* Dec_5p_5N(index>>N, n_1, offsetA, pos); */ + dec_1p_N1_fx( index, n_1, offsetA, pos + 5 ); + move16(); + BREAK; + case 1: + dec_5p_5N_fx( L_shr( index, N ), n_1, offsetA, pos ); /* Dec_5p_5N(index>>N, n_1, offsetA, pos); */ + dec_1p_N1_fx( index, n_1, offsetB, pos + 5 ); + move16(); + BREAK; + case 2: + dec_4p_4N_fx( L_shr( index, add( shl( n_1, 1 ), 1 ) ), n_1, offsetA, pos ); /* Dec_4p_4N(index>>((2*n_1)+1 ), n_1, offsetA, pos); */ + dec_2p_2N1_fx( index, n_1, offsetB, pos + 4 ); + move16(); + BREAK; + case 3: + dec_3p_3N1_fx( L_shr( index, add( add( shl( n_1, 1 ), n_1 ), 1 ) ), n_1, offset, pos ); /* Dec_3p_3N1(index>>((3*n_1)+ 1), n_1, offset, pos); */ + dec_3p_3N1_fx( index, n_1, j, pos + 3 ); + move16(); + BREAK; } } -static Word32 fcb_decode_class_all_p_fx( /* o: The index of pulse positions */ - Word32 *code_index, /* i: fcb index information */ - Word16 sector_6p_num[], /* o: Number of pulses for each position */ - Word16 pulse_num, /* i: Number of pulses on a track. */ - Word16 *pos_num /* o: Number of positions which have pulses on the track.*/ +static Word32 fcb_decode_class_all_p_fx( /* o: The index of pulse positions */ + Word32 *code_index, /* i: fcb index information */ + Word16 sector_6p_num[], /* o: Number of pulses for each position */ + Word16 pulse_num, /* i: Number of pulses on a track. */ + Word16 *pos_num /* o: Number of positions which have pulses on the track.*/ ) { Word16 i; - Word32 mn9,j,k; + Word32 mn9, j, k; Word16 pulse_pos_num; Word32 L_tmp, L_tmp1; - FOR (i=1; i<=pulse_num; i++) - { - IF (LT_32((*code_index),PI_offset[pulse_num][i])) - { + FOR( i = 1; i <= pulse_num; i++ ){ + IF( LT_32( ( *code_index ), PI_offset[pulse_num][i] ) ){ BREAK; - } - } +} +} - /* (*code_index) -= PI_offset[pulse_num][i-1];*/ - (*code_index) = L_sub((*code_index),PI_offset[pulse_num][i-1]); +/* (*code_index) -= PI_offset[pulse_num][i-1];*/ +( *code_index ) = L_sub( ( *code_index ), PI_offset[pulse_num][i - 1] ); - /*pulse_pos_num = pulse_num - i + 2;*/ - pulse_pos_num = add(sub(pulse_num , i) , 2); +/*pulse_pos_num = pulse_num - i + 2;*/ +pulse_pos_num = add( sub( pulse_num, i ), 2 ); - /* j = (*code_index)>>pulse_pos_num;*/ - j = L_shr((*code_index) , pulse_pos_num); - IF(LT_32(j,PI_select_table[16][pulse_pos_num])) - { - k = L_deposit_l(0); - mn9 = L_add(j, 0); - } - ELSE +/* j = (*code_index)>>pulse_pos_num;*/ +j = L_shr( ( *code_index ), pulse_pos_num ); +IF( LT_32( j, PI_select_table[16][pulse_pos_num] ) ) +{ + k = L_deposit_l( 0 ); + mn9 = L_add( j, 0 ); +} +ELSE +{ + L_tmp = L_deposit_l( 0 ); + L_tmp1 = L_add( j, 0 ); + WHILE( GE_32( L_tmp1, PI_select_table[16][pulse_pos_num] ) ) { - L_tmp = L_deposit_l(0); - L_tmp1 = L_add(j, 0); - WHILE(GE_32(L_tmp1,PI_select_table[16][pulse_pos_num])) - { - L_tmp = L_add(L_tmp,1); - L_tmp1 = L_sub(L_tmp1,PI_select_table[16][pulse_pos_num]); - } - k = L_add(L_tmp, 0); - mn9 = L_add(L_tmp1, 0); + L_tmp = L_add( L_tmp, 1 ); + L_tmp1 = L_sub( L_tmp1, PI_select_table[16][pulse_pos_num] ); } - /* mn9 = Mult_32_32(sub(j , k) , PI_select_table[16][pulse_pos_num]);*/ + k = L_add( L_tmp, 0 ); + mn9 = L_add( L_tmp1, 0 ); +} +/* mn9 = Mult_32_32(sub(j , k) , PI_select_table[16][pulse_pos_num]);*/ - test(); - IF ( (LT_16( pulse_pos_num,pulse_num))&&(GT_16(pulse_pos_num,1))) +test(); +IF( ( LT_16( pulse_pos_num, pulse_num ) ) && ( GT_16( pulse_pos_num, 1 ) ) ) +{ + FOR( i = 0; i < pulse_pos_num; i++ ) { - FOR (i=0; i= k; l+=2); + FOR( ; PI_select_table[16 - l][temp] >= k; l += 2 ); - if (GT_32(k,PI_select_table[L_sub(17,l)][temp])) + if ( GT_32( k, PI_select_table[L_sub( 17, l )][temp] ) ) { - l = L_sub(l,1); + l = L_sub( l, 1 ); } /* k = PI_select_table[17-l][temp--] - k ;*/ - k = L_sub(PI_select_table[L_sub(17,l)][temp--] , k); - pos_vector[i] = extract_l(L_sub(l,1)); + k = L_sub( PI_select_table[L_sub( 17, l )][temp--], k ); + pos_vector[i] = extract_l( L_sub( l, 1 ) ); } - pos_vector[i] = extract_l(L_add(l,k)); + pos_vector[i] = extract_l( L_add( l, k ) ); return; } -static void fcb_decode_PI_fx( /* o: return pulse position number */ - Word32 code_index, /* i: fcb index information */ - Word16 sector_6p[], /* o: decoded pulse position */ - Word16 pulse_num /* i: pulse number for the track */ +static void fcb_decode_PI_fx( /* o: return pulse position number */ + Word32 code_index, /* i: fcb index information */ + Word16 sector_6p[], /* o: decoded pulse position */ + Word16 pulse_num /* i: pulse number for the track */ ) { - Word16 i,l, j; + Word16 i, l, j; Word32 mn9; Word16 pulse_pos_num; Word16 sector_6p_temp[7], sector_6p_num_temp[7]; @@ -728,72 +722,70 @@ static void fcb_decode_PI_fx( /* o: return pulse position number */ Word16 *sector_6p_ptr1; /*get the position number and the pulse number on every position */ - mn9 = fcb_decode_class_all_p_fx(&code_index, sector_6p_num_temp, pulse_num, &pulse_pos_num); + mn9 = fcb_decode_class_all_p_fx( &code_index, sector_6p_num_temp, pulse_num, &pulse_pos_num ); /* rebuild the vector*/ /* decode the pulse position not same to the others*/ - fcb_decode_position_fx(mn9, sector_6p_temp, pulse_pos_num); - FOR (i=pulse_pos_num-1; i>=0; i--) + fcb_decode_position_fx( mn9, sector_6p_temp, pulse_pos_num ); + FOR( i = pulse_pos_num - 1; i >= 0; i-- ) { /*sector_6p_temp[i] += ((code_index&0x1)<<4) ;*/ - sector_6p_temp[i] = add(sector_6p_temp[i],extract_l(L_shl((code_index&0x1),4))) ; + sector_6p_temp[i] = add( sector_6p_temp[i], extract_l( L_shl( ( code_index & 0x1 ), 4 ) ) ); move16(); /*code_index = code_index>>1;*/ - code_index = L_shr(code_index , 1); - + code_index = L_shr( code_index, 1 ); } /* decode the pulse position maybe some pulse position same to other pulse */ sector_6p_ptr0 = §or_6p[pulse_num]; sector_6p_ptr1 = §or_6p_temp[pulse_pos_num]; - FOR (i=0; i> N) & 1; + mask = ( ( 1 << N ) - 1 ); + pos1 = (int16_t) ( index & mask ); + i = (int16_t) ( index >> N ) & 1; - if (i == 1) + if ( i == 1 ) { pos1 += nb_pos; } @@ -845,10 +837,10 @@ static void add_pulses_L_subfr( { int16_t i, k; - for (k = 0; k < nb_pulse; k++) + for ( k = 0; k < nb_pulse; k++ ) { - i = ((pos[k] & (nb_pos - 1)) * NB_TRACK_FCB_4T) + track; - if ((pos[k] & nb_pos) == 0) + i = ( ( pos[k] & ( nb_pos - 1 ) ) * NB_TRACK_FCB_4T ) + track; + if ( ( pos[k] & nb_pos ) == 0 ) { code[i] += 1.0f; } @@ -868,7 +860,7 @@ static void add_pulses_L_subfr( *----------------------------------------------------------------------------------*/ void dec_acelp_fast( - Decoder_State* st, /* i/o: decoder state structure */ + Decoder_State *st, /* i/o: decoder state structure */ const int16_t cdk_index, /* i : codebook index */ float code[], /* o : algebraic (fixed) codebook excitation */ const int16_t L_subfr /* i : subframe length */ @@ -879,81 +871,81 @@ void dec_acelp_fast( PulseConfig config; skip_track = -1; - set_f(code, 0.0f, L_subfr); + set_f( code, 0.0f, L_subfr ); - if (L_subfr == L_SUBFR) + if ( L_subfr == L_SUBFR ) { config = PulseConfTable[cdk_index]; - if (cdk_index == 2) + if ( cdk_index == 2 ) { - dec_acelp_2t32(st, code); + dec_acelp_2t32( st, code ); } - else if (config.nb_pulse == 2) + else if ( config.nb_pulse == 2 ) { /* 10 bits, 2 pulses, 4 tracks 1010 (used only even tracks) */ - for (k = 0; k < NB_TRACK_FCB_4T - 1; k += 2) + for ( k = 0; k < NB_TRACK_FCB_4T - 1; k += 2 ) { - L_index = get_next_indice(st, 5); - dec_1p_N1(L_index, 4, 0, pos); - add_pulses(pos, 1, k, code); + L_index = get_next_indice( st, 5 ); + dec_1p_N1( L_index, 4, 0, pos ); + add_pulses( pos, 1, k, code ); } } - else if (config.nb_pulse == 3) + else if ( config.nb_pulse == 3 ) { - if (config.codetrackpos == TRACKPOS_FIXED_FIRST) + if ( config.codetrackpos == TRACKPOS_FIXED_FIRST ) { /* 15 bits, 3 pulses, 4 tracks 1110 fixed track to first ? */ - for (k = 0; k < NB_TRACK_FCB_4T - 1; k++) + for ( k = 0; k < NB_TRACK_FCB_4T - 1; k++ ) { - L_index = get_next_indice(st, 5); - dec_1p_N1(L_index, 4, 0, pos); - add_pulses(pos, 1, k, code); + L_index = get_next_indice( st, 5 ); + dec_1p_N1( L_index, 4, 0, pos ); + add_pulses( pos, 1, k, code ); } } - else if (config.codetrackpos == TRACKPOS_FREE_THREE) + else if ( config.codetrackpos == TRACKPOS_FREE_THREE ) { /* 17 bits, 3 pulses, 4 tracks (used all tracks) - 1110, 1101, 1011, 0111 */ - skip_track = get_next_indice(st, 2); - for (k = 0; k < NB_TRACK_FCB_4T; k++) + skip_track = get_next_indice( st, 2 ); + for ( k = 0; k < NB_TRACK_FCB_4T; k++ ) { - if (k != skip_track) + if ( k != skip_track ) { - L_index = get_next_indice(st, 5); - dec_1p_N1(L_index, 4, 0, pos); - add_pulses(pos, 1, k, code); + L_index = get_next_indice( st, 5 ); + dec_1p_N1( L_index, 4, 0, pos ); + add_pulses( pos, 1, k, code ); } } } } else { - if (config.bits == 20) + if ( config.bits == 20 ) { skip_track = -1; } - else if (config.codetrackpos == TRACKPOS_FIXED_FIRST) + else if ( config.codetrackpos == TRACKPOS_FIXED_FIRST ) { skip_track = 0; } - else if (config.codetrackpos == TRACKPOS_FREE_ONE) + else if ( config.codetrackpos == TRACKPOS_FREE_ONE ) { - skip_track = get_next_indice(st, 2); + skip_track = get_next_indice( st, 2 ); } - for (k = 0; k < NB_TRACK_FCB_4T; k++) + for ( k = 0; k < NB_TRACK_FCB_4T; k++ ) { - if (k == skip_track) + if ( k == skip_track ) { - L_index = get_next_indice(st, 9); - dec_2p_2N1(L_index, 4, 0, pos); - add_pulses(pos, 2, k, code); + L_index = get_next_indice( st, 9 ); + dec_2p_2N1( L_index, 4, 0, pos ); + add_pulses( pos, 2, k, code ); } else { - L_index = get_next_indice(st, 5); - dec_1p_N1(L_index, 4, 0, pos); - add_pulses(pos, 1, k, code); + L_index = get_next_indice( st, 5 ); + dec_1p_N1( L_index, 4, 0, pos ); + add_pulses( pos, 1, k, code ); } } } @@ -962,70 +954,70 @@ void dec_acelp_fast( { config.bits = cdk_index; - if (cdk_index == 14) + if ( cdk_index == 14 ) { /* 14 bits, 2 pulses, 2 tracks: 11 (used all tracks) */ int16_t index, i0, i1; - index = get_next_indice(st, 14); + index = get_next_indice( st, 14 ); - i0 = ((index >> 7) & (NB_POS_FCB_2T_128 - 1)) * NB_TRACK_FCB_2T; - i1 = ((index & (NB_POS_FCB_2T_128 - 1)) * NB_TRACK_FCB_2T) + 1; + i0 = ( ( index >> 7 ) & ( NB_POS_FCB_2T_128 - 1 ) ) * NB_TRACK_FCB_2T; + i1 = ( ( index & ( NB_POS_FCB_2T_128 - 1 ) ) * NB_TRACK_FCB_2T ) + 1; code[i0] = -1.0f; - if ((index & 0x2000) == 0) + if ( ( index & 0x2000 ) == 0 ) { code[i0] = 1.0f; } code[i1] = -1.0f; - if ((index & 0x40) == 0) + if ( ( index & 0x40 ) == 0 ) { code[i1] = 1.0f; } } - else if (cdk_index == 12) + else if ( cdk_index == 12 ) { /* 12 bits, 2 pulses, 4 tracks: 1010 (used only even tracks) */ - for (k = 0; k < NB_TRACK_FCB_4T - 1; k += 2) + for ( k = 0; k < NB_TRACK_FCB_4T - 1; k += 2 ) { - L_index = get_next_indice(st, 6); - dec_1p_N1_L_subfr(L_index, NB_POS_FCB_4T_128, 5, pos); - add_pulses_L_subfr(NB_POS_FCB_4T_128, pos, 1, k, code); + L_index = get_next_indice( st, 6 ); + dec_1p_N1_L_subfr( L_index, NB_POS_FCB_4T_128, 5, pos ); + add_pulses_L_subfr( NB_POS_FCB_4T_128, pos, 1, k, code ); } } - else if (cdk_index == 18) + else if ( cdk_index == 18 ) { /* 18 bits, 3 pulses, 4 tracks: 1110 (used first three tracks) */ - for (k = 0; k < NB_TRACK_FCB_4T - 1; k++) + for ( k = 0; k < NB_TRACK_FCB_4T - 1; k++ ) { - L_index = get_next_indice(st, 6); - dec_1p_N1_L_subfr(L_index, NB_POS_FCB_4T_128, 5, pos); - add_pulses_L_subfr(NB_POS_FCB_4T_128, pos, 1, k, code); + L_index = get_next_indice( st, 6 ); + dec_1p_N1_L_subfr( L_index, NB_POS_FCB_4T_128, 5, pos ); + add_pulses_L_subfr( NB_POS_FCB_4T_128, pos, 1, k, code ); } } - else if (cdk_index == 20) + else if ( cdk_index == 20 ) { /* 20 bits, 3 pulses, 4 tracks (used all tracks): 1110, 1101, 1011, 0111 */ - skip_track = get_next_indice(st, 2); - for (k = 0; k < NB_TRACK_FCB_4T; k++) + skip_track = get_next_indice( st, 2 ); + for ( k = 0; k < NB_TRACK_FCB_4T; k++ ) { - if (k != skip_track) + if ( k != skip_track ) { - L_index = get_next_indice(st, 6); - dec_1p_N1_L_subfr(L_index, NB_POS_FCB_4T_128, 5, pos); - add_pulses_L_subfr(NB_POS_FCB_4T_128, pos, 1, k, code); + L_index = get_next_indice( st, 6 ); + dec_1p_N1_L_subfr( L_index, NB_POS_FCB_4T_128, 5, pos ); + add_pulses_L_subfr( NB_POS_FCB_4T_128, pos, 1, k, code ); } } } - else if (cdk_index == 24) + else if ( cdk_index == 24 ) { /* 24 bits, 4 pulses, 4 tracks: 1111 */ - for (k = 0; k < NB_TRACK_FCB_4T; k++) + for ( k = 0; k < NB_TRACK_FCB_4T; k++ ) { - L_index = get_next_indice(st, 6); - dec_1p_N1_L_subfr(L_index, NB_POS_FCB_4T_128, 5, pos); - add_pulses_L_subfr(NB_POS_FCB_4T_128, pos, 1, k, code); + L_index = get_next_indice( st, 6 ); + dec_1p_N1_L_subfr( L_index, NB_POS_FCB_4T_128, 5, pos ); + add_pulses_L_subfr( NB_POS_FCB_4T_128, pos, 1, k, code ); } } } @@ -1261,4 +1253,4 @@ void dec_acelp_fast_fx( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/dec_LPD.c b/lib_dec/dec_LPD.c index a58fb94a9..746e18e38 100644 --- a/lib_dec/dec_LPD.c +++ b/lib_dec/dec_LPD.c @@ -279,7 +279,7 @@ void decoder_LPD( mvr2r( &lsf[M], st->mem_AR, M ); hTcxDec->envWeighted = 1; - E_LPC_lsp_unweight_float( &lsp[M], lspnew_uw, lsfnew_uw, 1.0f / st->gamma_float); + E_LPC_lsp_unweight_float( &lsp[M], lspnew_uw, lsfnew_uw, 1.0f / st->gamma_float ); } else { @@ -476,7 +476,7 @@ void decoder_LPD( if ( bfi && st->last_core != ACELP_CORE ) { /* PLC: [TCX: TD PLC] */ - con_tcx( st, &synthFB[0], -1.f, NULL, 0, NULL ); + con_tcx( st, &synthFB[0], -1.f, NULL, 0, NULL ); lerp_flt( synthFB, synth, st->L_frame, st->hTcxDec->L_frameTCX ); st->con_tcx = 1; set_f( &st->mem_pitch_gain_float[2], st->lp_gainp, st->nb_subfr ); @@ -506,7 +506,7 @@ void decoder_LPD( } else { - decoder_acelp( st, prm, Aq, st->acelp_cfg, &synth[0], pitch, pit_gain, st->stab_fac, pitch_buf, voice_factors, LSF_Q_prediction, ptr_bwe_exc ); + decoder_acelp( st, prm, Aq, st->acelp_cfg, &synth[0], pitch, pit_gain, st->stab_fac, pitch_buf, voice_factors, LSF_Q_prediction, ptr_bwe_exc ); if ( st->flagGuidedAcelp > 0 ) { @@ -787,4 +787,4 @@ void decoder_LPD( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/dec_LPD_fx.c b/lib_dec/dec_LPD_fx.c index a79ab4358..7152a4f29 100644 --- a/lib_dec/dec_LPD_fx.c +++ b/lib_dec/dec_LPD_fx.c @@ -13,47 +13,47 @@ #ifdef IVAS_FLOAT_FIXED /* #if defined(_WIN32) && (_MSC_VER <= 1200) /\* disable global optimizations to overcome an internal compiler error *\/ */ -#if defined(_MSC_VER) && (_MSC_VER <= 1200) /* disable global optimizations to overcome an internal compiler error */ -#pragma optimize("g", off) +#if defined( _MSC_VER ) && ( _MSC_VER <= 1200 ) /* disable global optimizations to overcome an internal compiler error */ +#pragma optimize( "g", off ) #endif /*-------------------------------------------------------------------* -* decoder_LPD_fx() -* -* Core decoder MODE2 -*--------------------------------------------------------------------*/ + * decoder_LPD_fx() + * + * Core decoder MODE2 + *--------------------------------------------------------------------*/ void decoder_LPD_fx( - Word16 signal_out[], /* output: signal with LPD delay (7 subfrs) */ - Word16 signal_outFB[], /* o : synthesis @output_FS */ - Word16 *total_nbbits, /* i/o: number of bits / decoded bits */ - Decoder_State *st, /* i/o: decoder memory state pointer */ - Word16 * bpf_noise_buf, /* i/o: BPF noise buffer */ - Word16 bfi, /* i : BFI flag */ - Word16 *bitsRead, /* o : number of read bits */ - Word16 param[], /* o : buffer of parameters */ - Word16 *pitch_buf, /* i/o: floating pitch values for each subfr*/ - Word16 *voice_factors, /* o : voicing factors */ - Word16 *ptr_bwe_exc /* o : excitation for SWB TBE */ + Word16 signal_out[], /* output: signal with LPD delay (7 subfrs) */ + Word16 signal_outFB[], /* o : synthesis @output_FS */ + Word16 *total_nbbits, /* i/o: number of bits / decoded bits */ + Decoder_State *st, /* i/o: decoder memory state pointer */ + Word16 *bpf_noise_buf, /* i/o: BPF noise buffer */ + Word16 bfi, /* i : BFI flag */ + Word16 *bitsRead, /* o : number of read bits */ + Word16 param[], /* o : buffer of parameters */ + Word16 *pitch_buf, /* i/o: floating pitch values for each subfr*/ + Word16 *voice_factors, /* o : voicing factors */ + Word16 *ptr_bwe_exc /* o : excitation for SWB TBE */ ) { Word16 *param_lpc; - Word16 synth_buf[OLD_SYNTH_SIZE_DEC+L_FRAME_PLUS+M]; + Word16 synth_buf[OLD_SYNTH_SIZE_DEC + L_FRAME_PLUS + M]; Word16 *synth; - Word16 synth_bufFB[OLD_SYNTH_SIZE_DEC+L_FRAME_PLUS+M]; + Word16 synth_bufFB[OLD_SYNTH_SIZE_DEC + L_FRAME_PLUS + M]; Word16 *synthFB; - Word16 lsf[(NB_DIV+1)*M],lsp[(NB_DIV+1)*M],lspmid[M],lsfmid[M]; - Word16 Aq[(NB_SUBFR16k+1)*(M+1)]; /* Dyn RAM: it can be reduced by M+1 if insert branch for nb_subfr==5*/ + Word16 lsf[( NB_DIV + 1 ) * M], lsp[( NB_DIV + 1 ) * M], lspmid[M], lsfmid[M]; + Word16 Aq[( NB_SUBFR16k + 1 ) * ( M + 1 )]; /* Dyn RAM: it can be reduced by M+1 if insert branch for nb_subfr==5*/ Word16 pitch[NB_SUBFR16k]; Word16 pit_gain[NB_SUBFR16k]; Word16 i, k, *prm; - Word16 L_frame,nb_subfr; + Word16 L_frame, nb_subfr; Word16 L_frameTCX; - Word16 Aind[M+1], lspind[M]; - Word16 tmp_old[M+1], tmp_new[M+1], enr_old, enr_new; - Word16 xspnew_uw[NB_DIV*M], xsfnew_uw[NB_DIV*M]; - Word16 const* xsfBase; /* base for differential XSF coding */ - Word16 past_core_mode; + Word16 Aind[M + 1], lspind[M]; + Word16 tmp_old[M + 1], tmp_new[M + 1], enr_old, enr_new; + Word16 xspnew_uw[NB_DIV * M], xsfnew_uw[NB_DIV * M]; + Word16 const *xsfBase; /* base for differential XSF coding */ + Word16 past_core_mode; Word16 lsf_q_1st_rf[M], lsf_q_rf[M], lsp_q_rf[M]; Word32 lsp_diff; @@ -67,8 +67,8 @@ void decoder_LPD_fx( hTcxLtpDec = st->hTcxLtpDec; hTcxDec = st->hTcxDec; - st->core = 0; /* to avoid compilation warnings */ - prm = NULL; /* to avoid compilation warnings */ + st->core = 0; /* to avoid compilation warnings */ + prm = NULL; /* to avoid compilation warnings */ /*--------------------------------------------------------------------------------* * INIT @@ -79,30 +79,30 @@ void decoder_LPD_fx( enr_new = 0; move16(); - LSF_Q_prediction= -1; + LSF_Q_prediction = -1; move16(); - param_lpc = param+DEC_NPRM_DIV*NB_DIV; + param_lpc = param + DEC_NPRM_DIV * NB_DIV; past_core_mode = st->last_core_bfi; move16(); test(); test(); - if(st->use_partial_copy && GE_16(st->rf_frame_type, RF_TCXFD)&&LE_16(st->rf_frame_type,RF_TCXTD2)) + if ( st->use_partial_copy && GE_16( st->rf_frame_type, RF_TCXFD ) && LE_16( st->rf_frame_type, RF_TCXTD2 ) ) { bfi = st->bfi; move16(); } /*Adjust bit per frame*/ - if (bfi == 0) + if ( bfi == 0 ) { - st->bits_frame_core = sub(st->bits_frame, bitsRead[0]); + st->bits_frame_core = sub( st->bits_frame, bitsRead[0] ); } /* Framing parameters */ - L_frame = st->L_frame; + L_frame = st->L_frame; move16(); L_frameTCX = hTcxDec->L_frameTCX; move16(); @@ -113,28 +113,28 @@ void decoder_LPD_fx( /* Initialize pointers */ synth = synth_buf + hTcxDec->old_synth_len; /*st->old_synth: Q_0*/ - Copy(hTcxDec->old_synth, synth_buf, hTcxDec->old_synth_len); - set16_fx(synth, 0, L_FRAME_PLUS + M); + Copy( hTcxDec->old_synth, synth_buf, hTcxDec->old_synth_len ); + set16_fx( synth, 0, L_FRAME_PLUS + M ); synthFB = synth_bufFB + hTcxDec->old_synth_lenFB; - Copy(hTcxDec->old_synthFB_fx, synth_bufFB, hTcxDec->old_synth_lenFB); - set16_fx(synthFB, 0, L_FRAME_PLUS + M); + Copy( hTcxDec->old_synthFB_fx, synth_bufFB, hTcxDec->old_synth_lenFB ); + set16_fx( synthFB, 0, L_FRAME_PLUS + M ); /*For post-processing (post-filtering+blind BWE)*/ - IF (st->tcxonly==0) + IF( st->tcxonly == 0 ) { /* for bass postfilter */ - set16_fx(pitch, L_SUBFR, nb_subfr); + set16_fx( pitch, L_SUBFR, nb_subfr ); - set16_fx(pit_gain, 0, nb_subfr); + set16_fx( pit_gain, 0, nb_subfr ); } /* PLC: [Common: Memory update] * PLC: Update the number of lost frames */ - IF ( bfi != 0) + IF( bfi != 0 ) { move16(); - st->nbLostCmpt = add(st->nbLostCmpt, 1); + st->nbLostCmpt = add( st->nbLostCmpt, 1 ); } @@ -142,7 +142,7 @@ void decoder_LPD_fx( * BITSTREAM DECODING *--------------------------------------------------------------------------------*/ - IF (bfi == 0) + IF( bfi == 0 ) { /* PLC: [TCX: Tonal Concealment] */ st->second_last_core = st->last_core; @@ -151,8 +151,8 @@ void decoder_LPD_fx( move16(); tcx_current_overlap_mode = st->hTcxCfg->tcx_curr_overlap_mode; move16(); - dec_prm_fx(&st->coder_type, param, param_lpc, total_nbbits, st, L_frame, bitsRead); - IF(!st->rate_switching_init && EQ_16((st->last_codec_mode), MODE2)&&st->BER_detect) + dec_prm_fx( &st->coder_type, param, param_lpc, total_nbbits, st, L_frame, bitsRead ); + IF( !st->rate_switching_init && EQ_16( ( st->last_codec_mode ), MODE2 ) && st->BER_detect ) { st->coder_type = st->last_coder_type; move16(); @@ -174,19 +174,18 @@ void decoder_LPD_fx( move16(); st->core = GetPLCModeDecision_fx( st ); } - } ELSE { test(); test(); - IF( st->use_partial_copy && GE_16(st->rf_frame_type, RF_TCXFD)&&LE_16(st->rf_frame_type,RF_TCXTD2)) + IF( st->use_partial_copy && GE_16( st->rf_frame_type, RF_TCXFD ) && LE_16( st->rf_frame_type, RF_TCXTD2 ) ) { dec_prm_fx( &st->coder_type, param, param_lpc, total_nbbits, st, L_frame, bitsRead ); } - if (GT_16(st->nbLostCmpt, 1)) + if ( GT_16( st->nbLostCmpt, 1 ) ) { st->flagGuidedAcelp = 0; move16(); @@ -195,14 +194,14 @@ void decoder_LPD_fx( /* PLC: [Common: mode decision] * PLC: Decide which Concealment to use. Update pitch lags if needed */ - IF ( bfi!=0 ) + IF( bfi != 0 ) { - st->core = GetPLCModeDecision_fx(st); + st->core = GetPLCModeDecision_fx( st ); } - IF ( bfi == 0 ) + IF( bfi == 0 ) { - IF( EQ_16(st->prev_bfi, 1)) + IF( EQ_16( st->prev_bfi, 1 ) ) { st->prev_nbLostCmpt = st->nbLostCmpt; move16(); @@ -224,16 +223,16 @@ void decoder_LPD_fx( test(); test(); test(); - IF( (bfi == 0 ) || ( bfi != 0 && st->use_partial_copy != 0 && EQ_16(st->rf_frame_type,RF_TCXFD))) + IF( ( bfi == 0 ) || ( bfi != 0 && st->use_partial_copy != 0 && EQ_16( st->rf_frame_type, RF_TCXFD ) ) ) { test(); test(); test(); test(); test(); - IF(EQ_16(st->use_partial_copy,1)&&(LT_16(st->rf_frame_type,RF_TCXFD)||GT_16(st->rf_frame_type,RF_TCXTD2))) + IF( EQ_16( st->use_partial_copy, 1 ) && ( LT_16( st->rf_frame_type, RF_TCXFD ) || GT_16( st->rf_frame_type, RF_TCXTD2 ) ) ) { - IF( EQ_16((Word16)hTcxDec->envWeighted,1)) + IF( EQ_16( (Word16) hTcxDec->envWeighted, 1 ) ) { Copy( st->lspold_uw, st->lsp_old_fx, M ); Copy( st->lsfold_uw, st->lsf_old_fx, M ); @@ -242,20 +241,20 @@ void decoder_LPD_fx( } /* first stage VQ, 8 bits; reuse TCX high rate codebook */ - set16_fx(lsf_q_1st_rf, 0, M); - vlpc_1st_dec(param_lpc[0], lsf_q_1st_rf ); + set16_fx( lsf_q_1st_rf, 0, M ); + vlpc_1st_dec( param_lpc[0], lsf_q_1st_rf ); /* second stage vq */ /* quantized lsf from two stages */ /*v_add(lsf_q_1st_rf, lsf_q_diff_cb_8b_rf + M * param_lpc[1], lsf_q_rf, M);*/ - FOR (i=0; isr_core ); /* current n-th ACELP frame and its corresponding partial copy */ @@ -263,54 +262,52 @@ void decoder_LPD_fx( E_LPC_lsf_lsp_conversion( lsf_q_rf, lsp_q_rf, M ); /* copy the old and current lsfs and lsps into the lsf[] and lsp[] buffer for interpolation */ - Copy(st->lsf_old_fx, &lsf[0], M); - Copy(st->lsp_old_fx, &lsp[0], M); - Copy(lsf_q_rf, &lsf[M], M); - Copy(lsp_q_rf, &lsp[M], M); + Copy( st->lsf_old_fx, &lsf[0], M ); + Copy( st->lsp_old_fx, &lsp[0], M ); + Copy( lsf_q_rf, &lsf[M], M ); + Copy( lsp_q_rf, &lsp[M], M ); lsp_diff = 0; - FOR( i=0; i < M; i++ ) + FOR( i = 0; i < M; i++ ) { - lsp_diff = L_add(lsp_diff,(Word32)abs_s(sub(lsp[i+M],lsp[i]))); + lsp_diff = L_add( lsp_diff, (Word32) abs_s( sub( lsp[i + M], lsp[i] ) ) ); } - IF( EQ_16(st->core,ACELP_CORE)&&EQ_16(st->last_core,ACELP_CORE) - && LT_32(lsp_diff, 52428 )&>_32(lsp_diff,3932)&&EQ_16(st->next_coder_type,GENERIC) - && !st->prev_use_partial_copy && EQ_16(st->last_coder_type,UNVOICED) && GE_16(st->rf_frame_type,RF_GENPRED) ) + IF( EQ_16( st->core, ACELP_CORE ) && EQ_16( st->last_core, ACELP_CORE ) && LT_32( lsp_diff, 52428 ) && GT_32( lsp_diff, 3932 ) && EQ_16( st->next_coder_type, GENERIC ) && !st->prev_use_partial_copy && EQ_16( st->last_coder_type, UNVOICED ) && GE_16( st->rf_frame_type, RF_GENPRED ) ) { Copy( &lsp[0], &lsp[M], M ); } /* update mem_MA and mem_AR memories */ - lsf_update_memory( (Word16)st->narrowBand, &lsf[M], st->mem_MA_fx, st->mem_MA_fx, M ); - Copy(&lsf[M], st->mem_AR_fx, M); + lsf_update_memory( (Word16) st->narrowBand, &lsf[M], st->mem_MA_fx, st->mem_MA_fx, M ); + Copy( &lsf[M], st->mem_AR_fx, M ); - FOR( k=0; knumlpc; ++k ) + FOR( k = 0; k < st->numlpc; ++k ) { - Copy( &lsp[(k+1)*M], &xspnew_uw[k*M], M ); - Copy( &lsf[(k+1)*M], &xsfnew_uw[k*M], M ); + Copy( &lsp[( k + 1 ) * M], &xspnew_uw[k * M], M ); + Copy( &lsf[( k + 1 ) * M], &xsfnew_uw[k * M], M ); } } - ELSE IF ((hTcxDec->enableTcxLpc !=0 && NE_16(st->core , ACELP_CORE))||(bfi&&st->use_partial_copy&&st->rf_frame_type==RF_TCXFD)) + ELSE IF( ( hTcxDec->enableTcxLpc != 0 && NE_16( st->core, ACELP_CORE ) ) || ( bfi && st->use_partial_copy && st->rf_frame_type == RF_TCXFD ) ) { Word16 tcx_lpc_cdk; - IF(bfi && st->use_partial_copy && EQ_16(st->rf_frame_type, RF_TCXFD)) + IF( bfi && st->use_partial_copy && EQ_16( st->rf_frame_type, RF_TCXFD ) ) { - tcx_lpc_cdk = tcxlpc_get_cdk(GENERIC); + tcx_lpc_cdk = tcxlpc_get_cdk( GENERIC ); } ELSE { - tcx_lpc_cdk = tcxlpc_get_cdk(st->coder_type); /* inlined */ + tcx_lpc_cdk = tcxlpc_get_cdk( st->coder_type ); /* inlined */ } - Copy(st->lsf_old_fx, &lsf[0], M); - Copy(st->lsp_old_fx, &lsp[0], M); + Copy( st->lsf_old_fx, &lsf[0], M ); + Copy( st->lsp_old_fx, &lsp[0], M ); D_lsf_tcxlpc( param_lpc, &lsf[M], lspind, st->narrowBand, tcx_lpc_cdk, st->mem_MA_fx ); E_LPC_lsf_lsp_conversion( &lsf[M], &lsp[M], M ); - lsf_update_memory( (Word16)st->narrowBand, &lsf[M], st->mem_MA_fx, st->mem_MA_fx, M ); - Copy(&lsf[M], st->mem_AR_fx, M); + lsf_update_memory( (Word16) st->narrowBand, &lsf[M], st->mem_MA_fx, st->mem_MA_fx, M ); + Copy( &lsf[M], st->mem_AR_fx, M ); hTcxDec->envWeighted = 1; move16(); @@ -320,52 +317,51 @@ void decoder_LPD_fx( ELSE { - IF (hTcxDec->envWeighted) + IF( hTcxDec->envWeighted ) { - Copy(st->lspold_uw, st->lsp_old_fx, M); - Copy(st->lsfold_uw, st->lsf_old_fx, M); + Copy( st->lspold_uw, st->lsp_old_fx, M ); + Copy( st->lsfold_uw, st->lsf_old_fx, M ); hTcxDec->envWeighted = 0; move16(); } - IF (EQ_16(st->core, TCX_20_CORE)) + IF( EQ_16( st->core, TCX_20_CORE ) ) { - lpc_unquantize_fx( st, lsf, lsp, M, param_lpc, lspmid, lsfmid, AUDIO, &LSF_Q_prediction); + lpc_unquantize_fx( st, lsf, lsp, M, param_lpc, lspmid, lsfmid, AUDIO, &LSF_Q_prediction ); } ELSE { - lpc_unquantize_fx( st, lsf, lsp, M, param_lpc, lspmid, lsfmid, st->coder_type, &LSF_Q_prediction); + lpc_unquantize_fx( st, lsf, lsp, M, param_lpc, lspmid, lsfmid, st->coder_type, &LSF_Q_prediction ); - IF(EQ_16(st->prev_use_partial_copy,1)&&EQ_16(st->last_core,ACELP_CORE)&&EQ_16(st->core,ACELP_CORE) - && GE_16(st->prev_rf_frame_type, RF_GENPRED) && EQ_16(st->coder_type, UNVOICED)) + IF( EQ_16( st->prev_use_partial_copy, 1 ) && EQ_16( st->last_core, ACELP_CORE ) && EQ_16( st->core, ACELP_CORE ) && GE_16( st->prev_rf_frame_type, RF_GENPRED ) && EQ_16( st->coder_type, UNVOICED ) ) { - IF ( st->lpcQuantization && st->acelp_cfg.midLpc ) + IF( st->lpcQuantization && st->acelp_cfg.midLpc ) { - Copy(lspmid, &lsp[0], M ); - Copy(&lsp[M], lspmid, M ); + Copy( lspmid, &lsp[0], M ); + Copy( &lsp[M], lspmid, M ); } } } - FOR(k=0; knumlpc; ++k) + FOR( k = 0; k < st->numlpc; ++k ) { - Copy(&lsp[(k+1)*M], &xspnew_uw[k*M], M); - Copy(&lsf[(k+1)*M], &xsfnew_uw[k*M], M); + Copy( &lsp[( k + 1 ) * M], &xspnew_uw[k * M], M ); + Copy( &lsf[( k + 1 ) * M], &xsfnew_uw[k * M], M ); } } /* PLC: [LPD: LPC concealment] * built the moving average for the LPC concealment */ - FOR (k=0; knumlpc; k++) + FOR( k = 0; k < st->numlpc; k++ ) { - FOR (i=0; ilsf_adaptive_mean_fx[i] = add(add(mult_r(st->lsfoldbfi1_fx[i], 10923/*1.0f/3.0f Q15*/), mult_r(st->lsfoldbfi0_fx[i], 10923/*1.0f/3.0f Q15*/)), mult_r(xsfnew_uw[k*M+i], 10923/*1.0f/3.0f Q15*/)); + st->lsf_adaptive_mean_fx[i] = add( add( mult_r( st->lsfoldbfi1_fx[i], 10923 /*1.0f/3.0f Q15*/ ), mult_r( st->lsfoldbfi0_fx[i], 10923 /*1.0f/3.0f Q15*/ ) ), mult_r( xsfnew_uw[k * M + i], 10923 /*1.0f/3.0f Q15*/ ) ); move16(); st->lsfoldbfi1_fx[i] = st->lsfoldbfi0_fx[i]; move16(); - st->lsfoldbfi0_fx[i] = xsfnew_uw[k*M+i]; + st->lsfoldbfi0_fx[i] = xsfnew_uw[k * M + i]; } } } @@ -376,21 +372,21 @@ void decoder_LPD_fx( st->numlpc = 2; move16(); test(); - if ( st->tcxonly == 0 || LT_16(st->core, TCX_10_CORE)) + if ( st->tcxonly == 0 || LT_16( st->core, TCX_10_CORE ) ) { move16(); st->numlpc = 1; } - IF(EQ_16(st->nbLostCmpt,1)) + IF( EQ_16( st->nbLostCmpt, 1 ) ) { - Copy(st->lsf_old_fx, st->old_lsf_q_cng, M); - Copy(st->lsp_old_fx, st->old_lsp_q_cng, M); + Copy( st->lsf_old_fx, st->old_lsf_q_cng, M ); + Copy( st->lsp_old_fx, st->old_lsp_q_cng, M ); } move16(); - xsfBase = PlcGetLsfBase (st->lpcQuantization, (Word16)st->narrowBand, st->sr_core); + xsfBase = PlcGetLsfBase( st->lpcQuantization, (Word16) st->narrowBand, st->sr_core ); - dlpc_bfi( st->L_frame,xsfnew_uw,st->lsfold_uw,st->last_good,st->nbLostCmpt,st->mem_MA_fx,st->mem_AR_fx, - &(st->stab_fac_fx), st->lsf_adaptive_mean_fx, st->numlpc, st->lsf_cng, (Word8)st->plcBackgroundNoiseUpdated, st->lsf_q_cng, st->old_lsf_q_cng, xsfBase, (Word8)st->tcxonly); + dlpc_bfi( st->L_frame, xsfnew_uw, st->lsfold_uw, st->last_good, st->nbLostCmpt, st->mem_MA_fx, st->mem_AR_fx, + &( st->stab_fac_fx ), st->lsf_adaptive_mean_fx, st->numlpc, st->lsf_cng, (Word8) st->plcBackgroundNoiseUpdated, st->lsf_q_cng, st->old_lsf_q_cng, xsfBase, (Word8) st->tcxonly ); hTcxDec->envWeighted = 0; move16(); @@ -398,48 +394,48 @@ void decoder_LPD_fx( Copy( st->lspold_uw, lsp, M ); Copy( st->lsfold_uw, lsf, M ); - FOR ( k = 0; k < st->numlpc; k++ ) + FOR( k = 0; k < st->numlpc; k++ ) { - Copy( &xsfnew_uw[k*M], &lsf[(k+1)*M], M ); + Copy( &xsfnew_uw[k * M], &lsf[( k + 1 ) * M], M ); - IF ( st->tcxonly ) + IF( st->tcxonly ) { - E_LPC_lsf_lsp_conversion(&lsf[(k+1)*M], &lsp[(k+1)*M], M); - E_LPC_lsf_lsp_conversion(st->lsf_q_cng, st->lsp_q_cng, M); + E_LPC_lsf_lsp_conversion( &lsf[( k + 1 ) * M], &lsp[( k + 1 ) * M], M ); + E_LPC_lsf_lsp_conversion( st->lsf_q_cng, st->lsp_q_cng, M ); } ELSE { - lsf2lsp_fx( &lsf[(k+1)*M], &lsp[(k+1)*M], M, st->sr_core ); + lsf2lsp_fx( &lsf[( k + 1 ) * M], &lsp[( k + 1 ) * M], M, st->sr_core ); lsf2lsp_fx( st->lsf_q_cng, st->lsp_q_cng, M, st->sr_core ); } - Copy( &lsp[(k+1)*M], &xspnew_uw[k*M], M ); + Copy( &lsp[( k + 1 ) * M], &xspnew_uw[k * M], M ); } } /*--------------------------------------------------------------* * Rate switching *---------------------------------------------------------------*/ - IF( st->rate_switching_reset!=0 ) + IF( st->rate_switching_reset != 0 ) { - Copy( &(lsf[M]),&(lsf[0]), M ); - Copy( &(lsp[M]),&(lsp[0]), M ); - Copy( &(lsf[M]),st->lsf_old_fx, M ); - Copy( &(lsp[M]),st->lsp_old_fx, M ); - Copy( &(lsf[M]),lsfmid, M ); - Copy( &(lsp[M]),lspmid, M ); - E_LPC_f_lsp_a_conversion(st->lsp_old_fx, st->old_Aq_12_8_fx, M); + Copy( &( lsf[M] ), &( lsf[0] ), M ); + Copy( &( lsp[M] ), &( lsp[0] ), M ); + Copy( &( lsf[M] ), st->lsf_old_fx, M ); + Copy( &( lsp[M] ), st->lsp_old_fx, M ); + Copy( &( lsf[M] ), lsfmid, M ); + Copy( &( lsp[M] ), lspmid, M ); + E_LPC_f_lsp_a_conversion( st->lsp_old_fx, st->old_Aq_12_8_fx, M ); } - IF(st->enablePlcWaveadjust) + IF( st->enablePlcWaveadjust ) { - if(EQ_16(st->core, ACELP_CORE)) + if ( EQ_16( st->core, ACELP_CORE ) ) { st->tonality_flag = 0; move16(); } - if(bfi) + if ( bfi ) { st->plcInfo.nbLostCmpt++; move16(); @@ -452,7 +448,7 @@ void decoder_LPD_fx( test(); test(); test(); - IF( (st->prev_bfi!=0) && (bfi==0) && (EQ_16(st->coder_type,VOICED))&>_16(st->prev_nbLostCmpt,4)) + IF( ( st->prev_bfi != 0 ) && ( bfi == 0 ) && ( EQ_16( st->coder_type, VOICED ) ) && GT_16( st->prev_nbLostCmpt, 4 ) ) { st->dec_glr_idx = 1; move16(); @@ -460,60 +456,60 @@ void decoder_LPD_fx( move16(); } - IF ( st->core == ACELP_CORE ) + IF( st->core == ACELP_CORE ) { - IF (st->tcxonly==0) + IF( st->tcxonly == 0 ) { /* Set pointer to parameters */ prm = param; /* Stability Factor */ - IF ( bfi == 0 ) + IF( bfi == 0 ) { - st->stab_fac_fx = lsf_stab_fx(&lsf[M], &lsf[0], 0, st->L_frame); + st->stab_fac_fx = lsf_stab_fx( &lsf[M], &lsf[0], 0, st->L_frame ); } test(); - IF( bfi==0 && st->prev_bfi != 0 ) + IF( bfi == 0 && st->prev_bfi != 0 ) { /* check if LSP interpolation can be relaxed or if LPC power can be diffused*/ - E_LPC_f_lsp_a_conversion(&lsp[0], tmp_old, M); - enr_old = Enr_1_Az_fx(tmp_old, 2*L_SUBFR); + E_LPC_f_lsp_a_conversion( &lsp[0], tmp_old, M ); + enr_old = Enr_1_Az_fx( tmp_old, 2 * L_SUBFR ); - E_LPC_f_lsp_a_conversion(&lsp[M], tmp_new, M); - enr_new = Enr_1_Az_fx(tmp_new, 2*L_SUBFR); + E_LPC_f_lsp_a_conversion( &lsp[M], tmp_new, M ); + enr_new = Enr_1_Az_fx( tmp_new, 2 * L_SUBFR ); } test(); test(); test(); test(); - IF( (bfi == 0) && ((EQ_16(st->dec_glr_idx, 1))||((st->safety_net==0)&&(shr(enr_new,11)>0)&&(GT_16(shr(enr_new,1),enr_old))))&&(st->prev_bfi!=0)) + IF( ( bfi == 0 ) && ( ( EQ_16( st->dec_glr_idx, 1 ) ) || ( ( st->safety_net == 0 ) && ( shr( enr_new, 11 ) > 0 ) && ( GT_16( shr( enr_new, 1 ), enr_old ) ) ) ) && ( st->prev_bfi != 0 ) ) { Word16 reset_q = 0; - if( EQ_16(st->dec_glr_idx, 1)) + if ( EQ_16( st->dec_glr_idx, 1 ) ) { reset_q = 1; move16(); } - RecLpcSpecPowDiffuseLc( &lsp[M], &lsp[0], &lsf[M], st, reset_q); + RecLpcSpecPowDiffuseLc( &lsp[M], &lsp[0], &lsf[M], st, reset_q ); int_lsp_fx( L_frame, &lsp[0], &lsp[M], Aq, M, interpol_frac_fx, 0 ); - Copy(&lsf[M], xsfnew_uw, M); + Copy( &lsf[M], xsfnew_uw, M ); } ELSE { /* LPC Interpolation for ACELP */ test(); - IF ( bfi==0 && st->acelp_cfg.midLpc ) + IF( bfi == 0 && st->acelp_cfg.midLpc ) { st->relax_prev_lsf_interp = 0; move16(); - IF (st->prev_bfi) + IF( st->prev_bfi ) { /* check if LSP interpolation can be relaxed */ - IF ( LT_16(enr_new, shr(enr_old, 2))) + IF( LT_16( enr_new, shr( enr_old, 2 ) ) ) { st->relax_prev_lsf_interp = -1; move16(); @@ -521,7 +517,7 @@ void decoder_LPD_fx( test(); test(); test(); - IF ( EQ_16(st->clas_dec, UNVOICED_CLAS)||EQ_16(st->clas_dec,SIN_ONSET)||EQ_16(st->clas_dec,INACTIVE_CLAS)||EQ_16(st->coder_type,GENERIC)||EQ_16(st->coder_type,TRANSITION)) + IF( EQ_16( st->clas_dec, UNVOICED_CLAS ) || EQ_16( st->clas_dec, SIN_ONSET ) || EQ_16( st->clas_dec, INACTIVE_CLAS ) || EQ_16( st->coder_type, GENERIC ) || EQ_16( st->coder_type, TRANSITION ) ) { st->relax_prev_lsf_interp = 1; move16(); @@ -533,7 +529,7 @@ void decoder_LPD_fx( test(); test(); test(); - IF (st->stab_fac_fx == 0 && st->old_bfi_cnt > 0 && NE_16(st->clas_dec, VOICED_CLAS)&&NE_16(st->clas_dec,ONSET)&&st->relax_prev_lsf_interp==0) + IF( st->stab_fac_fx == 0 && st->old_bfi_cnt > 0 && NE_16( st->clas_dec, VOICED_CLAS ) && NE_16( st->clas_dec, ONSET ) && st->relax_prev_lsf_interp == 0 ) { st->relax_prev_lsf_interp = 2; move16(); @@ -549,58 +545,58 @@ void decoder_LPD_fx( } test(); - IF (bfi!=0 && st->last_core != ACELP_CORE) + IF( bfi != 0 && st->last_core != ACELP_CORE ) { /* PLC: [TCX: TD PLC] */ #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - con_tcx_fx(st, &synthFB[0], -1.f, NULL, 0, NULL); + con_tcx_fx( st, &synthFB[0], -1.f, NULL, 0, NULL ); #else con_tcx_fx( st, &synthFB[0] ); #endif lerp( synthFB, synth, st->L_frame, hTcxDec->L_frameTCX ); st->con_tcx = 1; move16(); - set16_fx (st->mem_pitch_gain+2,round_fx(L_shl(st->Mode2_lp_gainp , 1)), st->nb_subfr); + set16_fx( st->mem_pitch_gain + 2, round_fx( L_shl( st->Mode2_lp_gainp, 1 ) ), st->nb_subfr ); } ELSE { /* ACELP decoder */ - IF(hBWE_TD != NULL) + IF( hBWE_TD != NULL ) { - IF(EQ_16(st->L_frame,L_FRAME)) + IF( EQ_16( st->L_frame, L_FRAME ) ) { - Copy(Aq + 2 * (M + 1), hBWE_TD->cur_sub_Aq_fx, (M + 1)); + Copy( Aq + 2 * ( M + 1 ), hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) ); } ELSE { - Copy(Aq + 3 * (M + 1), hBWE_TD->cur_sub_Aq_fx, (M + 1)); + Copy( Aq + 3 * ( M + 1 ), hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) ); } } - IF ( bfi != 0 ) + IF( bfi != 0 ) { /* PLC: [ACELP: general] * PLC: Use the ACELP like concealment */ - con_acelp_fx(Aq,st->core_ext_mode,&synth[0],pitch,pit_gain,st->stab_fac_fx,st, - &st->Q_exc, &st->Q_syn, /*Q format of st->mem_syn*/ pitch_buf, voice_factors, ptr_bwe_exc); + con_acelp_fx( Aq, st->core_ext_mode, &synth[0], pitch, pit_gain, st->stab_fac_fx, st, + &st->Q_exc, &st->Q_syn, /*Q format of st->mem_syn*/ pitch_buf, voice_factors, ptr_bwe_exc ); - Copy(&st->mem_pitch_gain[2], &st->mem_pitch_gain[st->nb_subfr+2], st->nb_subfr); - set16_fx(&st->mem_pitch_gain[2],0,st->nb_subfr); + Copy( &st->mem_pitch_gain[2], &st->mem_pitch_gain[st->nb_subfr + 2], st->nb_subfr ); + set16_fx( &st->mem_pitch_gain[2], 0, st->nb_subfr ); } ELSE { - decoder_acelp_fx(st, prm, Aq, st->acelp_cfg, &synth[0], pitch, pit_gain, st->stab_fac_fx, pitch_buf, voice_factors, LSF_Q_prediction, ptr_bwe_exc); - - IF(st->flagGuidedAcelp > 0) + decoder_acelp_fx( st, prm, Aq, st->acelp_cfg, &synth[0], pitch, pit_gain, st->stab_fac_fx, pitch_buf, voice_factors, LSF_Q_prediction, ptr_bwe_exc ); + + IF( st->flagGuidedAcelp > 0 ) { - st->guidedT0 = s_max(s_min(add(st->T0_4th, st->guidedT0), NBPSF_PIT_MAX), PIT_MIN_16k); + st->guidedT0 = s_max( s_min( add( st->T0_4th, st->guidedT0 ), NBPSF_PIT_MAX ), PIT_MIN_16k ); } - FOR (i=0; inb_subfr; i++) + FOR( i = 0; i < st->nb_subfr; i++ ) { move16(); move16(); - st->mem_pitch_gain[2+(2*st->nb_subfr-1)-i] = st->mem_pitch_gain[2+ (st->nb_subfr-1) -i]; - st->mem_pitch_gain[2+(st->nb_subfr-1)-i] = pit_gain[i]; + st->mem_pitch_gain[2 + ( 2 * st->nb_subfr - 1 ) - i] = st->mem_pitch_gain[2 + ( st->nb_subfr - 1 ) - i]; + st->mem_pitch_gain[2 + ( st->nb_subfr - 1 ) - i] = pit_gain[i]; } } } @@ -609,143 +605,139 @@ void decoder_LPD_fx( /* LPC for ACELP/BBWE */ test(); test(); - IF( st->narrowBand || (EQ_32(st->sr_core, INT_FS_12k8))||(EQ_32(st->sr_core, INT_FS_16k))) + IF( st->narrowBand || ( EQ_32( st->sr_core, INT_FS_12k8 ) ) || ( EQ_32( st->sr_core, INT_FS_16k ) ) ) { - Copy(Aq, st->mem_Aq, nb_subfr*(M+1)); + Copy( Aq, st->mem_Aq, nb_subfr * ( M + 1 ) ); } /* PLC: [TCX: Tonal Concealment] */ /* Signal that this frame is not TCX */ - TonalMDCTConceal_UpdateState(&st->tonalMDCTconceal, 0, 0, 0, 0); + TonalMDCTConceal_UpdateState( &st->tonalMDCTconceal, 0, 0, 0, 0 ); - IF (bfi==0) + IF( bfi == 0 ) { st->second_last_tns_active = st->last_tns_active; st->last_tns_active = 0; hTcxDec->tcxltp_last_gain_unmodified = 0; move16(); } - } - /*--------------------------------------------------------------------------------* * TCX20 *--------------------------------------------------------------------------------*/ - IF ( EQ_16(st->core, TCX_20_CORE)) + IF( EQ_16( st->core, TCX_20_CORE ) ) { /* Set pointer to parameters */ prm = param; /* Stability Factor */ - IF ( bfi == 0 ) + IF( bfi == 0 ) { - IF ( st->tcxonly != 0 ) + IF( st->tcxonly != 0 ) { - st->stab_fac_fx = lsf_stab_fx(&lsf[M], &lsf[0],0, L_FRAME); + st->stab_fac_fx = lsf_stab_fx( &lsf[M], &lsf[0], 0, L_FRAME ); } ELSE { - st->stab_fac_fx = lsf_stab_fx(&lsf[M], &lsf[0],0, st->L_frame); + st->stab_fac_fx = lsf_stab_fx( &lsf[M], &lsf[0], 0, st->L_frame ); } } - IF (hTcxDec->enableTcxLpc) + IF( hTcxDec->enableTcxLpc ) { /* Convert quantized xSP to A */ - E_LPC_f_lsp_a_conversion(&lsp[M], Aq, M); + E_LPC_f_lsp_a_conversion( &lsp[M], Aq, M ); } ELSE { - IF (st->tcxonly == 0) + IF( st->tcxonly == 0 ) { test(); test(); test(); - IF( (bfi == 0) && (st->prev_bfi != 0 ) && (st->safety_net==0) && (st->rate_switching_reset != 0) ) + IF( ( bfi == 0 ) && ( st->prev_bfi != 0 ) && ( st->safety_net == 0 ) && ( st->rate_switching_reset != 0 ) ) { /* diffuse LPC power on rate switching*/ RecLpcSpecPowDiffuseLc( &lsp[M], &lsp[0], &lsf[M], st, 0 ); int_lsp_fx( L_frame, &lsp[0], &lsp[M], Aq, M, interpol_frac_fx, 0 ); - Copy(&lsf[M], xsfnew_uw, M); + Copy( &lsf[M], xsfnew_uw, M ); } ELSE { /* LPC Interpolation for TCX */ - E_LPC_int_lpc_tcx(&lsp[0], &lsp[M], Aq); + E_LPC_int_lpc_tcx( &lsp[0], &lsp[M], Aq ); } } ELSE { - E_LPC_f_lsp_a_conversion(&lsp[M], Aq, M); + E_LPC_f_lsp_a_conversion( &lsp[M], Aq, M ); } } test(); - IF ( bfi == 0 && hTcxDec->tcx_lpc_shaped_ari != 0 ) + IF( bfi == 0 && hTcxDec->tcx_lpc_shaped_ari != 0 ) { - E_LPC_f_lsp_a_conversion(lspind, Aind, M); + E_LPC_f_lsp_a_conversion( lspind, Aind, M ); } /* TCX decoder */ - decoder_tcx_fx(st->hTcxCfg,prm,Aq,Aind,L_frame,L_frameTCX,st->hTcxCfg->tcx_coded_lines,&synth[0],&synthFB[0],st, st->coder_type, bfi,0,st->stab_fac_fx); - + decoder_tcx_fx( st->hTcxCfg, prm, Aq, Aind, L_frame, L_frameTCX, st->hTcxCfg->tcx_coded_lines, &synth[0], &synthFB[0], st, st->coder_type, bfi, 0, st->stab_fac_fx ); } /*--------------------------------------------------------------------------------* * TCX10 *--------------------------------------------------------------------------------*/ - IF ( EQ_16(st->core, TCX_10_CORE)) + IF( EQ_16( st->core, TCX_10_CORE ) ) { - FOR (k=0; k<2; k++) + FOR( k = 0; k < 2; k++ ) { /* Set pointer to parameters */ - prm = param + (k*DEC_NPRM_DIV); + prm = param + ( k * DEC_NPRM_DIV ); /* Stability Factor */ - IF ( bfi==0 ) + IF( bfi == 0 ) { - st->stab_fac_fx = lsf_stab_fx(&lsf[(k+1)*M], &lsf[k*M],0, L_FRAME); + st->stab_fac_fx = lsf_stab_fx( &lsf[( k + 1 ) * M], &lsf[k * M], 0, L_FRAME ); } - E_LPC_f_lsp_a_conversion(&lsp[(k+1)*M], Aq, M); + E_LPC_f_lsp_a_conversion( &lsp[( k + 1 ) * M], Aq, M ); /* TCX decoder */ IGFDecRestoreTCX10SubFrameData( st->hIGFDec, k ); - decoder_tcx_fx(st->hTcxCfg,prm,Aq,Aind,shr(L_frame, 1),shr(L_frameTCX, 1), - shr(st->hTcxCfg->tcx_coded_lines, 1),&synth[k*L_frame/2],&synthFB[k*L_frameTCX/2],st, st->coder_type, bfi, k, st->stab_fac_fx ); + decoder_tcx_fx( st->hTcxCfg, prm, Aq, Aind, shr( L_frame, 1 ), shr( L_frameTCX, 1 ), + shr( st->hTcxCfg->tcx_coded_lines, 1 ), &synth[k * L_frame / 2], &synthFB[k * L_frameTCX / 2], st, st->coder_type, bfi, k, st->stab_fac_fx ); } - } test(); - IF (EQ_16(st->core, TCX_10_CORE)||EQ_16(st->core,TCX_20_CORE)) + IF( EQ_16( st->core, TCX_10_CORE ) || EQ_16( st->core, TCX_20_CORE ) ) { test(); test(); - IF(st->enablePlcWaveadjust || /* bfi */ - (GE_32(st->last_total_brate, HQ_48k) && /* recovery */ - EQ_16(st->last_codec_mode, MODE2) ) ) + IF( st->enablePlcWaveadjust || /* bfi */ + ( GE_32( st->last_total_brate, HQ_48k ) && /* recovery */ + EQ_16( st->last_codec_mode, MODE2 ) ) ) { /* waveform adjustment */ concealment_signal_tuning_fx( bfi, st->core, synthFB, &st->plcInfo, st->nbLostCmpt, st->prev_bfi, st->tonalMDCTconceal.secondLastPcmOut, - past_core_mode,st->tonalMDCTconceal.lastPcmOut, st ); + past_core_mode, st->tonalMDCTconceal.lastPcmOut, st ); test(); test(); test(); - IF ((bfi || st->prev_bfi) && st->plcInfo.Pitch_fx && (EQ_16(st->plcInfo.concealment_method, TCX_NONTONAL))) + IF( ( bfi || st->prev_bfi ) && st->plcInfo.Pitch_fx && ( EQ_16( st->plcInfo.concealment_method, TCX_NONTONAL ) ) ) { lerp( synthFB, synth, L_frame, L_frameTCX ); test(); - if( !bfi && st->prev_bfi ) + if ( !bfi && st->prev_bfi ) { st->plcInfo.Pitch_fx = 0; move16(); @@ -753,52 +745,52 @@ void decoder_LPD_fx( } } - IF (!bfi) + IF( !bfi ) { TonalMDCTConceal_SaveTimeSignal( &st->tonalMDCTconceal, synthFB, L_frameTCX ); } #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - decoder_tcx_post_fx(st, synth, synthFB, Aq, bfi, 0); + decoder_tcx_post_fx( st, synth, synthFB, Aq, bfi, 0 ); #else decoder_tcx_post_fx( st, synth, synthFB, Aq, bfi ); #endif - IF (EQ_16(st->core, TCX_20_CORE)) + IF( EQ_16( st->core, TCX_20_CORE ) ) { /* LPC Interpolation for BWE/post-processing */ test(); test(); - IF( st->narrowBand || (EQ_32(st->sr_core, INT_FS_12k8))||(EQ_32(st->sr_core, INT_FS_16k))) + IF( st->narrowBand || ( EQ_32( st->sr_core, INT_FS_12k8 ) ) || ( EQ_32( st->sr_core, INT_FS_16k ) ) ) { int_lsp_fx( L_frame, st->lspold_uw, xspnew_uw, Aq, M, interpol_frac_fx, 0 ); - Copy(Aq, st->mem_Aq, nb_subfr*(M+1)); + Copy( Aq, st->mem_Aq, nb_subfr * ( M + 1 ) ); } } } /* PLC: [Common: Classification] */ - IF( LE_32( st->sr_core, INT_FS_16k)) + IF( LE_32( st->sr_core, INT_FS_16k ) ) { test(); test(); test(); - IF ( EQ_16(st->core, TCX_20_CORE)||EQ_16(st->core,TCX_10_CORE)||(st->tcxonly&&st->bfi)) + IF( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || ( st->tcxonly && st->bfi ) ) { Word16 pitch_C[NB_SUBFR16k]; Word16 core_ext_mode, LTP_Gain; - set16_fx(pitch_C, shl(round_fx(st->old_fpitch), 6), NB_SUBFR16k); + set16_fx( pitch_C, shl( round_fx( st->old_fpitch ), 6 ), NB_SUBFR16k ); core_ext_mode = GENERIC; move16(); - if(st->tcxonly == 0) + if ( st->tcxonly == 0 ) { core_ext_mode = st->core_ext_mode; move16(); } - LTP_Gain = -32768/*-1.0f Q15*/; - if(hTcxLtpDec->tcxltp) + LTP_Gain = -32768 /*-1.0f Q15*/; + if ( hTcxLtpDec->tcxltp ) { LTP_Gain = hTcxDec->tcxltp_last_gain_unmodified; move16(); @@ -807,32 +799,30 @@ void decoder_LPD_fx( FEC_clas_estim_fx( st, - /*Opt_AMR_WB*/0, /*A*/ + /*Opt_AMR_WB*/ 0, /*A*/ st->L_frame, - &(st->clas_dec), + &( st->clas_dec ), core_ext_mode, pitch_C, synth, &st->lp_ener_FER_fx, - /**decision_hyst*/NULL, /* i/o: hysteresis of the music/speech decision */ - /**UV_cnt*/ NULL, /* i/o: number of consecutive frames classified as */ - /**LT_UV_cnt*/ NULL, /* i/o: long term consecutive frames classified as UV */ - /**Last_ener*/ NULL, /* i/o: last_energy frame */ - /**locattack*/ NULL, /* i/o: detection of attack (mainly to localized speech burst) */ - /**lt_diff_etot*/NULL, /* i/o: long-term total energy variation */ - /**amr_io_class*/ NULL, /* i/o: classification for AMR-WB IO mode */ - /*bitrate*/ 0 , /* i : Decoded bitrate */ - 0, /* i : Synthesis scaling */ - /**class_para*/ NULL, /* o : classification para. fmerit1 */ - st->mem_syn_clas_estim_fx, /* i/o: memory of the synthesis signal for frame class estimation */ - &st->classifier_Q_mem_syn, /* i/o: exponent for memory of synthesis signal for frame class estimation */ - LTP_Gain, /* i : means LTP Gain */ - 1 /*CLASSIFIER_TCX*/, /* i : signal classifier mode */ - bfi, /* i : bad frame indicator */ - st->last_core_brate, /* i : bitrate of previous frame */ - -1 - ); - + /**decision_hyst*/ NULL, /* i/o: hysteresis of the music/speech decision */ + /**UV_cnt*/ NULL, /* i/o: number of consecutive frames classified as */ + /**LT_UV_cnt*/ NULL, /* i/o: long term consecutive frames classified as UV */ + /**Last_ener*/ NULL, /* i/o: last_energy frame */ + /**locattack*/ NULL, /* i/o: detection of attack (mainly to localized speech burst) */ + /**lt_diff_etot*/ NULL, /* i/o: long-term total energy variation */ + /**amr_io_class*/ NULL, /* i/o: classification for AMR-WB IO mode */ + /*bitrate*/ 0, /* i : Decoded bitrate */ + 0, /* i : Synthesis scaling */ + /**class_para*/ NULL, /* o : classification para. fmerit1 */ + st->mem_syn_clas_estim_fx, /* i/o: memory of the synthesis signal for frame class estimation */ + &st->classifier_Q_mem_syn, /* i/o: exponent for memory of synthesis signal for frame class estimation */ + LTP_Gain, /* i : means LTP Gain */ + 1 /*CLASSIFIER_TCX*/, /* i : signal classifier mode */ + bfi, /* i : bad frame indicator */ + st->last_core_brate, /* i : bitrate of previous frame */ + -1 ); } } @@ -841,17 +831,17 @@ void decoder_LPD_fx( *--------------------------------------------------------------------------------*/ test(); - IF( bfi && NE_16(st->last_core_bfi , ACELP_CORE)) + IF( bfi && NE_16( st->last_core_bfi, ACELP_CORE ) ) { /* Update FEC_scale_syn parameters */ - IF(hTcxLtpDec->tcxltp_gain == 0) + IF( hTcxLtpDec->tcxltp_gain == 0 ) { - frame_ener_fx( L_frame, UNVOICED_CLAS, synth, shr(L_frame,1), &st->enr_old_fx, L_frame, 0, 0, 0 ); + frame_ener_fx( L_frame, UNVOICED_CLAS, synth, shr( L_frame, 1 ), &st->enr_old_fx, L_frame, 0, 0, 0 ); } ELSE { Word16 pitch_Q0; - pitch_Q0 = round_fx(st->old_fpitch); + pitch_Q0 = round_fx( st->old_fpitch ); frame_ener_fx( L_frame, st->clas_dec, synth, pitch_Q0, &st->enr_old_fx, L_frame, 0, 0, 0 ); } } @@ -859,14 +849,14 @@ void decoder_LPD_fx( test(); test(); - IF(!bfi && GE_16(st->clas_dec, VOICED_TRANSITION)&<_16(st->clas_dec,INACTIVE_CLAS)) + IF( !bfi && GE_16( st->clas_dec, VOICED_TRANSITION ) && LT_16( st->clas_dec, INACTIVE_CLAS ) ) { Word16 offset; - IF(EQ_16(st->core, ACELP_CORE)) + IF( EQ_16( st->core, ACELP_CORE ) ) { - offset = sub(st->nb_subfr,1); - offset = imult1616(offset,add(M,1)); + offset = sub( st->nb_subfr, 1 ); + offset = imult1616( offset, add( M, 1 ) ); } ELSE { @@ -874,66 +864,66 @@ void decoder_LPD_fx( move16(); } /* use latest LPC set */ - st->old_enr_LP = Enr_1_Az_fx(Aq+offset, L_SUBFR); /*Q3*/ + st->old_enr_LP = Enr_1_Az_fx( Aq + offset, L_SUBFR ); /*Q3*/ } /* Update */ - Copy(synth_buf+L_frame, hTcxDec->old_synth, hTcxDec->old_synth_len); + Copy( synth_buf + L_frame, hTcxDec->old_synth, hTcxDec->old_synth_len ); - Copy(hTcxDec->old_synthFB_fx + L_frameTCX - NS2SA_fx2(st->output_Fs, PH_ECU_MEM_NS), hTcxDec->synth_history_fx, NS2SA_fx2(st->output_Fs, PH_ECU_MEM_NS) ); - Copy(synth_bufFB+L_frameTCX, hTcxDec->old_synthFB_fx, hTcxDec->old_synth_lenFB); - Copy_Scale_sig( st->hHQ_core->old_out_fx+NS2SA_fx2(st->output_Fs, N_ZERO_MDCT_NS), hTcxDec->old_synthFB_fx+ hTcxDec->old_synth_lenFB, NS2SA_fx2(st->output_Fs, PH_ECU_LOOKAHEAD_NS), negate(st->hHQ_core->Q_old_wtda)); + Copy( hTcxDec->old_synthFB_fx + L_frameTCX - NS2SA_fx2( st->output_Fs, PH_ECU_MEM_NS ), hTcxDec->synth_history_fx, NS2SA_fx2( st->output_Fs, PH_ECU_MEM_NS ) ); + Copy( synth_bufFB + L_frameTCX, hTcxDec->old_synthFB_fx, hTcxDec->old_synth_lenFB ); + Copy_Scale_sig( st->hHQ_core->old_out_fx + NS2SA_fx2( st->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->old_synthFB_fx + hTcxDec->old_synth_lenFB, NS2SA_fx2( st->output_Fs, PH_ECU_LOOKAHEAD_NS ), negate( st->hHQ_core->Q_old_wtda ) ); - Copy(&xspnew_uw[(st->numlpc-1)*M], st->lspold_uw, M); - Copy(&xsfnew_uw[(st->numlpc-1)*M], st->lsfold_uw, M); + Copy( &xspnew_uw[( st->numlpc - 1 ) * M], st->lspold_uw, M ); + Copy( &xsfnew_uw[( st->numlpc - 1 ) * M], st->lsfold_uw, M ); - IF (bfi) + IF( bfi ) { - Copy(st->lspold_uw, st->lsp_old_fx, M); /* for recovery */ - Copy(st->lsfold_uw, st->lsf_old_fx, M); /* for recovery */ + Copy( st->lspold_uw, st->lsp_old_fx, M ); /* for recovery */ + Copy( st->lsfold_uw, st->lsf_old_fx, M ); /* for recovery */ } ELSE { - Copy(&lsp[st->numlpc*M], st->lsp_old_fx, M); - Copy(&lsf[st->numlpc*M], st->lsf_old_fx, M); + Copy( &lsp[st->numlpc * M], st->lsp_old_fx, M ); + Copy( &lsf[st->numlpc * M], st->lsf_old_fx, M ); } - Copy(st->lsp_q_cng, st->old_lsp_q_cng, M); - Copy(st->lsf_q_cng, st->old_lsf_q_cng, M); + Copy( st->lsp_q_cng, st->old_lsp_q_cng, M ); + Copy( st->lsf_q_cng, st->old_lsf_q_cng, M ); /* Update LP_CNG parameters */ IF( st->tcxonly == 0 && st->hTdCngDec != NULL ) { /* update CNG parameters in active frames */ - IF (EQ_16(st->bwidth,NB)&& hTcxDec->enableTcxLpc!=0&&NE_16(st->core,ACELP_CORE)) + IF( EQ_16( st->bwidth, NB ) && hTcxDec->enableTcxLpc != 0 && NE_16( st->core, ACELP_CORE ) ) { - Word16 buf[L_LP], res[L_FRAME], A[M+1], Qexc, r_l[M+1], r_h[M+1], lsptmp[M], Q_r, tmp; + Word16 buf[L_LP], res[L_FRAME], A[M + 1], Qexc, r_l[M + 1], r_h[M + 1], lsptmp[M], Q_r, tmp; - assert(st->L_frame==L_FRAME); - Copy(synth+L_FRAME-L_LP, buf, L_LP); - tmp = synth[L_FRAME-L_LP-1]; - Qexc = E_UTIL_f_preemph3(buf, st->preemph_fac, L_LP, &tmp, 1); + assert( st->L_frame == L_FRAME ); + Copy( synth + L_FRAME - L_LP, buf, L_LP ); + tmp = synth[L_FRAME - L_LP - 1]; + Qexc = E_UTIL_f_preemph3( buf, st->preemph_fac, L_LP, &tmp, 1 ); autocorr_fx( buf, M, r_h, r_l, &Q_r, L_LP, Assym_window_W16fx, 0, 0 ); - lag_wind(r_h, r_l, M, INT_FS_FX, LAGW_WEAK); - E_LPC_lev_dur(r_h, r_l, A, NULL, M, NULL); - E_LPC_a_lsp_conversion(A, lsptmp, &xspnew_uw[0], M); - Residu3_fx(A, buf+L_LP-L_FRAME, res, L_FRAME, 1); + lag_wind( r_h, r_l, M, INT_FS_FX, LAGW_WEAK ); + E_LPC_lev_dur( r_h, r_l, A, NULL, M, NULL ); + E_LPC_a_lsp_conversion( A, lsptmp, &xspnew_uw[0], M ); + Residu3_fx( A, buf + L_LP - L_FRAME, res, L_FRAME, 1 ); cng_params_upd_fx( lsptmp, res, st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ_fx, &st->hTdCngDec->ho_circ_size, st->hTdCngDec->ho_lsp_circ_fx, Qexc, DEC, st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate ); } ELSE { - cng_params_upd_fx( &lsp[M], st->old_exc_fx+L_EXC_MEM_DEC-st->L_frame, - st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ_fx, - &st->hTdCngDec->ho_circ_size, st->hTdCngDec->ho_lsp_circ_fx, st->Q_exc, DEC, - st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate ); + cng_params_upd_fx( &lsp[M], st->old_exc_fx + L_EXC_MEM_DEC - st->L_frame, + st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ_fx, + &st->hTdCngDec->ho_circ_size, st->hTdCngDec->ho_lsp_circ_fx, st->Q_exc, DEC, + st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate ); } /* Set 16k LSP flag for CNG buffer */ st->hTdCngDec->ho_16k_lsp[st->hTdCngDec->ho_circ_ptr] = 1; move16(); - if ( EQ_16(st->L_frame,L_FRAME)) + if ( EQ_16( st->L_frame, L_FRAME ) ) { st->hTdCngDec->ho_16k_lsp[st->hTdCngDec->ho_circ_ptr] = 0; move16(); @@ -944,23 +934,23 @@ void decoder_LPD_fx( st->last_is_cng = 0; /* Postfiltering */ - post_decoder( st, synth_buf, pit_gain, pitch, signal_out, bpf_noise_buf); + post_decoder( st, synth_buf, pit_gain, pitch, signal_out, bpf_noise_buf ); IF( signal_outFB ) { Copy( synthFB, signal_outFB, L_frameTCX ); } - IF( st->enablePlcWaveadjust) + IF( st->enablePlcWaveadjust ) { - if(!bfi) + if ( !bfi ) { - st->plcInfo.nbLostCmpt = (int16_t)L_deposit_l(0); + st->plcInfo.nbLostCmpt = (int16_t) L_deposit_l( 0 ); } - IF (st->core == 0) + IF( st->core == 0 ) { - set_state(st->plcInfo.Transient, st->core, MAX_POST_LEN); + set_state( st->plcInfo.Transient, st->core, MAX_POST_LEN ); } } @@ -968,4 +958,3 @@ void decoder_LPD_fx( return; } #endif - diff --git a/lib_dec/dec_ace.c b/lib_dec/dec_ace.c index 4cdbb8b12..ebdab29ea 100644 --- a/lib_dec/dec_ace.c +++ b/lib_dec/dec_ace.c @@ -304,7 +304,7 @@ void decoder_acelp( if ( st->igf ) { - tbe_celp_exc_flt( st->element_mode, st->idchan, bwe_exc, L_frame, L_SUBFR, i_subfr, T0, T0_frac, &error, 0 ); + tbe_celp_exc_flt( st->element_mode, st->idchan, bwe_exc, L_frame, L_SUBFR, i_subfr, T0, T0_frac, &error, 0 ); } pitch_buffer[i_subfr / L_SUBFR] = (float) T0 + (float) T0_frac / (float) T0_res; @@ -350,7 +350,7 @@ void decoder_acelp( if ( st->acelp_cfg.gains_mode[i_subfr / L_SUBFR] != 0 ) { - decode_acelp_gains( code, acelp_cfg.gains_mode[i_subfr / L_SUBFR], Es_pred, &gain_pit, &gain_code, &prm, &( st->past_gpit_float), &( st->past_gcode_float), &gain_inov, L_SUBFR, code2, &gain_code2 ); + decode_acelp_gains( code, acelp_cfg.gains_mode[i_subfr / L_SUBFR], Es_pred, &gain_pit, &gain_code, &prm, &( st->past_gpit_float ), &( st->past_gcode_float ), &gain_inov, L_SUBFR, code2, &gain_code2 ); } if ( st->use_partial_copy && st->rf_frame_type == RF_ALLPRED ) @@ -368,7 +368,7 @@ void decoder_acelp( * - tilt of code: 0.0 (unvoiced) to 0.5 (voiced) * *----------------------------------------------------------*/ - st->tilt_code = est_tilt( exc + i_subfr, gain_pit, code, gain_code, &( st->voice_fac_float), L_SUBFR, acelp_cfg.voice_tilt ); + st->tilt_code = est_tilt( exc + i_subfr, gain_pit, code, gain_code, &( st->voice_fac_float ), L_SUBFR, acelp_cfg.voice_tilt ); pgainT[i_subfr / L_SUBFR] = gain_pit; @@ -484,7 +484,7 @@ void decoder_acelp( set_zero( h1, L_SUBFR + 1 ); set_zero( mem, M ); h1[0] = 1.0f; - syn_filt( pA, M, h1, h1, L_SUBFR, mem, 0 ); /* impulse response of LPC */ + syn_filt( pA, M, h1, h1, L_SUBFR, mem, 0 ); /* impulse response of LPC */ deemph( h1, st->preemph_fac_float, L_SUBFR, &tmp ); /* impulse response of deemph */ /* impulse response level = gain introduced by synthesis+deemphasis */ st->last_gain_syn_deemph_float = (float) sqrt( dotp( h1, h1, L_SUBFR ) ); diff --git a/lib_dec/dec_ace_fx.c b/lib_dec/dec_ace_fx.c index f0bdb1eb7..0f623af53 100644 --- a/lib_dec/dec_ace_fx.c +++ b/lib_dec/dec_ace_fx.c @@ -21,27 +21,27 @@ #ifdef IVAS_FLOAT_FIXED void decoder_acelp_fx( Decoder_State *st, - Word16 prm[], /* i : parameters */ - Word16 A[], /* i : coefficients NxAz[M+1] */ - ACELP_config acelp_cfg, /* i : ACELP config */ - Word16 synth[], /* i/o: synth[-2*LFAC..L_DIV] Q0 */ - Word16 *pT, /* o : pitch for all subframe Q0 */ - Word16 *pgainT, /* o : pitch gain for all subfr 1Q14 */ - Word16 stab_fac, /* i : stability of isf */ - Word16 *pitch_buffer, /* o : pitch values for each subfr. */ - Word16 *voice_factors, /* o : voicing factors */ - const Word16 LSF_Q_prediction, /* i : LSF prediction mode */ - Word16 *bwe_exc /* o : excitation for SWB TBE */ + Word16 prm[], /* i : parameters */ + Word16 A[], /* i : coefficients NxAz[M+1] */ + ACELP_config acelp_cfg, /* i : ACELP config */ + Word16 synth[], /* i/o: synth[-2*LFAC..L_DIV] Q0 */ + Word16 *pT, /* o : pitch for all subframe Q0 */ + Word16 *pgainT, /* o : pitch gain for all subfr 1Q14 */ + Word16 stab_fac, /* i : stability of isf */ + Word16 *pitch_buffer, /* o : pitch values for each subfr. */ + Word16 *voice_factors, /* o : voicing factors */ + const Word16 LSF_Q_prediction, /* i : LSF prediction mode */ + Word16 *bwe_exc /* o : excitation for SWB TBE */ ) { Word16 i, j, i_subfr; Word16 T0, T0_frac, T0_min, T0_min_frac, T0_max, T0_max_frac, T0_res; - Word16 tmp, tmp2, gain_pit/*Q14*/, Es_pred, tmp_deemph; + Word16 tmp, tmp2, gain_pit /*Q14*/, Es_pred, tmp_deemph; Word32 Ltmp, Ltmp2, gain_code; Word16 code[L_SUBFR]; Word16 mem_syn[M]; - Word16 *syn, syn_buf[M+L_FRAME16k+L_FRAME16k/2]; - Word16 *exc, exc_buf[L_EXC_MEM_DEC+L_FRAME16k+1]; + Word16 *syn, syn_buf[M + L_FRAME16k + L_FRAME16k / 2]; + Word16 *exc, exc_buf[L_EXC_MEM_DEC + L_FRAME16k + 1]; Word16 exc2[L_FRAME_16k]; Word16 *p_A; Word32 pitch_buf[NB_SUBFR16k]; @@ -49,28 +49,28 @@ void decoder_acelp_fx( Word16 gain_inov; Word16 mem_back[M]; Word16 update_flg; - Word16 Q_mem_back; /*Q format of mem_back*/ - Word16 h1[L_FRAME_16k/4+1]; + Word16 Q_mem_back; /*Q format of mem_back*/ + Word16 h1[L_FRAME_16k / 4 + 1]; Word16 mem[M]; Word16 *pA; PulseConfig config; Word16 weights[5]; /* Q15 */ - Word16 reScaleLen_fx; /* rescaling length for the BWE buffers */ + Word16 reScaleLen_fx; /* rescaling length for the BWE buffers */ Word16 reSampLen; /*Q formats of buffers */ Word16 prev_Q_syn; - Word32 gain_code2=0; + Word32 gain_code2 = 0; Word16 code2[L_SUBFR]; Word16 error = 0; - Word16 gain_preQ = 0; /* Gain of prequantizer excitation */ - Word16 code_preQ[L_SUBFR]; /* Prequantizer excitation */ + Word16 gain_preQ = 0; /* Gain of prequantizer excitation */ + Word16 code_preQ[L_SUBFR]; /* Prequantizer excitation */ Word16 lp_flag; Word16 prev_gain_pit; - Word16 tmp_noise; /* Long term temporary noise energy */ + Word16 tmp_noise; /* Long term temporary noise energy */ Word32 gain_code_tmp; Word16 gain_pit_tmp; Word32 gain_code_pre; @@ -86,12 +86,12 @@ void decoder_acelp_fx( move16(); - set16_fx(code_preQ, 0, L_SUBFR); + set16_fx( code_preQ, 0, L_SUBFR ); - gain_inov = 0; /* to avoid compilation warnings */ - T0 = 0; /* to avoid compilation warnings */ - T0_frac = 0; /* to avoid compilation warnings */ - T0_res = 0; /* to avoid compilation warnings */ + gain_inov = 0; /* to avoid compilation warnings */ + T0 = 0; /* to avoid compilation warnings */ + T0_frac = 0; /* to avoid compilation warnings */ + T0_res = 0; /* to avoid compilation warnings */ prev_Q_syn = st->prev_Q_syn = st->Q_syn; move16(); move16(); @@ -104,43 +104,43 @@ void decoder_acelp_fx( move16(); update_flg = 0; move16(); - gain_code2=0; + gain_code2 = 0; prev_gain_pit = 0; tmp_noise = 0; - IF(EQ_16(st->nb_subfr,4)) + IF( EQ_16( st->nb_subfr, 4 ) ) { move16(); move16(); move16(); move16(); - weights[0] = 3277/*0.1f Q15*/; - weights[1] = 6554/*0.2f Q15*/; - weights[2] = 9830/*0.3f Q15*/; - weights[3] = 13107/*0.4f Q15*/; + weights[0] = 3277 /*0.1f Q15*/; + weights[1] = 6554 /*0.2f Q15*/; + weights[2] = 9830 /*0.3f Q15*/; + weights[3] = 13107 /*0.4f Q15*/; } - ELSE /*nb_subfr == 5*/ + ELSE /*nb_subfr == 5*/ { move16(); move16(); move16(); move16(); move16(); - weights[0] = 2185/*(float)1/15 Q15*/; - weights[1] = 4369/*(float)2/15 Q15*/; - weights[2] = 6554/*(float)3/15 Q15*/; - weights[3] = 8738/*(float)4/15 Q15*/; - weights[4] = 10923/*(float)5/15 Q15*/; + weights[0] = 2185 /*(float)1/15 Q15*/; + weights[1] = 4369 /*(float)2/15 Q15*/; + weights[2] = 6554 /*(float)3/15 Q15*/; + weights[3] = 8738 /*(float)4/15 Q15*/; + weights[4] = 10923 /*(float)5/15 Q15*/; } - st->Mode2_lp_gainp = L_deposit_l(0); - st->Mode2_lp_gainc = L_deposit_l(0); + st->Mode2_lp_gainp = L_deposit_l( 0 ); + st->Mode2_lp_gainc = L_deposit_l( 0 ); avoid_lpc_burst_on_recovery = 0; move16(); test(); test(); - if (st->last_con_tcx && (NE_16(st->L_frameTCX_past, st->L_frame))&&(st->last_core!=0)) + if ( st->last_con_tcx && ( NE_16( st->L_frameTCX_past, st->L_frame ) ) && ( st->last_core != 0 ) ) { avoid_lpc_burst_on_recovery = 1; move16(); @@ -153,10 +153,10 @@ void decoder_acelp_fx( /* Reset phase dispersion */ - IF ( st->last_core_bfi > ACELP_CORE ) + IF( st->last_core_bfi > ACELP_CORE ) { - st->dm_fx.prev_gain_code = L_deposit_l(0); - set16_fx(st->dm_fx.prev_gain_pit, 0, 6); + st->dm_fx.prev_gain_code = L_deposit_l( 0 ); + set16_fx( st->dm_fx.prev_gain_pit, 0, 6 ); st->dm_fx.prev_state = 0; move16(); } @@ -164,7 +164,7 @@ void decoder_acelp_fx( /* Update of synthesis filter memories in case of 12k8 core */ test(); test(); - IF ( st->prev_bfi && st->last_con_tcx && LT_16(st->L_frame, L_FRAME16k)) + IF( st->prev_bfi && st->last_con_tcx && LT_16( st->L_frame, L_FRAME16k ) ) { synth_mem_updt2( st->L_frame, L_FRAME16k, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, DEC ); } @@ -176,14 +176,14 @@ void decoder_acelp_fx( /* rescale excitation buffer if LPC energies differs too much */ enr_LP = Enr_1_Az_fx( A, L_SUBFR ); - IF(LT_16(st->old_enr_LP, enr_LP)) + IF( LT_16( st->old_enr_LP, enr_LP ) ) { - ratio = div_s(st->old_enr_LP,enr_LP); /* Q15 */ - IF (LT_16(ratio, 26215)) + ratio = div_s( st->old_enr_LP, enr_LP ); /* Q15 */ + IF( LT_16( ratio, 26215 ) ) { - FOR (i = 0; i < L_EXC_MEM_DEC; i++) + FOR( i = 0; i < L_EXC_MEM_DEC; i++ ) { - st->old_exc_fx[i] = mult_r(st->old_exc_fx[i], ratio); + st->old_exc_fx[i] = mult_r( st->old_exc_fx[i], ratio ); } } } @@ -192,16 +192,16 @@ void decoder_acelp_fx( /*------------------------------------------------------------------------* * Initialize buffers * *------------------------------------------------------------------------*/ - Copy( st->mem_syn2_fx, mem_back, M); + Copy( st->mem_syn2_fx, mem_back, M ); move16(); Q_mem_back = st->Q_syn; /* set ACELP synthesis memory */ Copy( st->mem_syn2_fx, mem_syn, M ); /* set excitation memory*/ - exc=exc_buf+L_EXC_MEM_DEC; - Copy( st->old_exc_fx, exc_buf, L_EXC_MEM_DEC); - *(exc+st->L_frame) = 0; + exc = exc_buf + L_EXC_MEM_DEC; + Copy( st->old_exc_fx, exc_buf, L_EXC_MEM_DEC ); + *( exc + st->L_frame ) = 0; /* Init syn buffer */ syn = syn_buf + M; @@ -211,10 +211,10 @@ void decoder_acelp_fx( * Fast recovery flag *------------------------------------------------------------------------*/ test(); - if(st->prev_bfi && EQ_16(st->coder_type,VOICED)) + if ( st->prev_bfi && EQ_16( st->coder_type, VOICED ) ) { /*Force BPF to be applied fully*/ - st->bpf_gain_param=3; + st->bpf_gain_param = 3; move16(); } @@ -223,9 +223,9 @@ void decoder_acelp_fx( *------------------------------------------------------------------------*/ Es_pred = 0; move16(); - IF ( acelp_cfg.nrg_mode>0 ) + IF( acelp_cfg.nrg_mode > 0 ) { - d_gain_pred_fx(acelp_cfg.nrg_mode, &Es_pred, &prm ); + d_gain_pred_fx( acelp_cfg.nrg_mode, &Es_pred, &prm ); } /*------------------------------------------------------------------------* @@ -249,17 +249,17 @@ void decoder_acelp_fx( p_A = A; - FOR (i_subfr = 0; i_subfr < st->L_frame; i_subfr += L_SUBFR) + FOR( i_subfr = 0; i_subfr < st->L_frame; i_subfr += L_SUBFR ) { test(); - IF( EQ_16(st->use_partial_copy,1)&&EQ_16(st->rf_frame_type,RF_NELP)) + IF( EQ_16( st->use_partial_copy, 1 ) && EQ_16( st->rf_frame_type, RF_NELP ) ) { IF( i_subfr == 0 ) { decod_nelp_fx( st, &tmp_noise, dummy_pitch_buf, exc, exc2, voice_factors, bwe_exc, &st->Q_exc, st->bfi, pgainT ); - set32_fx(pitch_buf, L_SUBFR_Q16, NB_SUBFR); - set16_fx(pitch_buffer, 4096, NB_SUBFR); /* L_SUBFR_Q16 in Q6 */ + set32_fx( pitch_buf, L_SUBFR_Q16, NB_SUBFR ); + set16_fx( pitch_buffer, 4096, NB_SUBFR ); /* L_SUBFR_Q16 in Q6 */ } } ELSE @@ -270,38 +270,38 @@ void decoder_acelp_fx( *-------------------------------------------------------*/ test(); - IF( EQ_16(st->use_partial_copy,1)&&st->acelp_cfg.gains_mode[i_subfr/L_SUBFR]==0) + IF( EQ_16( st->use_partial_copy, 1 ) && st->acelp_cfg.gains_mode[i_subfr / L_SUBFR] == 0 ) { gain_pit = prev_gain_pit; } - IF ( acelp_cfg.ltp_bits != 0 ) + IF( acelp_cfg.ltp_bits != 0 ) { - /* pitch lag decoding */ - pitch_buf[i_subfr/L_SUBFR] = Mode2_pit_decode( acelp_cfg.ltp_mode, i_subfr, L_SUBFR, &prm, &T0, &T0_frac, &T0_res, - &T0_min, &T0_min_frac, &T0_max, &T0_max_frac, st->pit_min, st->pit_fr1, st->pit_fr1b, st->pit_fr2, st->pit_max, st->pit_res_max); + /* pitch lag decoding */ + pitch_buf[i_subfr / L_SUBFR] = Mode2_pit_decode( acelp_cfg.ltp_mode, i_subfr, L_SUBFR, &prm, &T0, &T0_frac, &T0_res, + &T0_min, &T0_min_frac, &T0_max, &T0_max_frac, st->pit_min, st->pit_fr1, st->pit_fr1b, st->pit_fr2, st->pit_max, st->pit_res_max ); /* find pitch excitation */ test(); - IF( EQ_16(st->pit_res_max,6)&&!(st->use_partial_copy)) + IF( EQ_16( st->pit_res_max, 6 ) && !( st->use_partial_copy ) ) { - IF ( EQ_16(T0_res, shr(st->pit_res_max, 1))) + IF( EQ_16( T0_res, shr( st->pit_res_max, 1 ) ) ) { - pred_lt4( &exc[i_subfr], &exc[i_subfr], T0, shl(T0_frac,1), L_SUBFR+1, pitch_inter6_2, PIT_L_INTERPOL6_2, PIT_UP_SAMP6 ); + pred_lt4( &exc[i_subfr], &exc[i_subfr], T0, shl( T0_frac, 1 ), L_SUBFR + 1, pitch_inter6_2, PIT_L_INTERPOL6_2, PIT_UP_SAMP6 ); } ELSE { - pred_lt4( &exc[i_subfr],&exc[i_subfr], T0, T0_frac, L_SUBFR+1, pitch_inter6_2, PIT_L_INTERPOL6_2, PIT_UP_SAMP6 ); + pred_lt4( &exc[i_subfr], &exc[i_subfr], T0, T0_frac, L_SUBFR + 1, pitch_inter6_2, PIT_L_INTERPOL6_2, PIT_UP_SAMP6 ); } } ELSE { - IF ( EQ_16(T0_res, shr(st->pit_res_max, 1))) - { - pred_lt4( &exc[i_subfr], &exc[i_subfr], T0, shl(T0_frac,1), L_SUBFR+1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + IF( EQ_16( T0_res, shr( st->pit_res_max, 1 ) ) ) + { + pred_lt4( &exc[i_subfr], &exc[i_subfr], T0, shl( T0_frac, 1 ), L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); } ELSE { - pred_lt4( &exc[i_subfr], &exc[i_subfr], T0, T0_frac, L_SUBFR+1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + pred_lt4( &exc[i_subfr], &exc[i_subfr], T0, T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); } } @@ -309,33 +309,32 @@ void decoder_acelp_fx( lp_flag = acelp_cfg.ltf_mode; move16(); - IF( EQ_16(acelp_cfg.ltf_mode, NORMAL_OPERATION)) + IF( EQ_16( acelp_cfg.ltf_mode, NORMAL_OPERATION ) ) { lp_flag = *prm; move16(); prm++; } - lp_filt_exc_dec_fx(st, MODE2, i_subfr, L_SUBFR, st->L_frame, lp_flag, exc); - + lp_filt_exc_dec_fx( st, MODE2, i_subfr, L_SUBFR, st->L_frame, lp_flag, exc ); } ELSE { /* No adaptive codebook (UC) */ - set16_fx(&exc[i_subfr], 0, L_SUBFR); + set16_fx( &exc[i_subfr], 0, L_SUBFR ); T0 = L_SUBFR; T0_frac = 0; T0_res = 1; - pitch_buf[i_subfr/L_SUBFR] = L_deposit_h(L_SUBFR); + pitch_buf[i_subfr / L_SUBFR] = L_deposit_h( L_SUBFR ); } IF( st->igf != 0 ) { - tbe_celp_exc(st->L_frame, i_subfr, T0, T0_frac, &error, bwe_exc); + tbe_celp_exc( st->L_frame, i_subfr, T0, T0_frac, &error, bwe_exc ); } - pitch_buffer[i_subfr/L_SUBFR] = shl(add(shl(T0,2),T0_frac), 4); + pitch_buffer[i_subfr / L_SUBFR] = shl( add( shl( T0, 2 ), T0_frac ), 4 ); /*-------------------------------------------------------* * - Decode innovative codebook. * @@ -344,88 +343,88 @@ void decoder_acelp_fx( test(); test(); test(); - IF( EQ_16(st->use_partial_copy,1)&& - ( EQ_16(st->rf_frame_type,RF_ALLPRED) || - ( EQ_16(st->rf_frame_type,RF_GENPRED) && - ( EQ_16(i_subfr,L_SUBFR) || EQ_16(i_subfr,3*L_SUBFR) )) ) ) + IF( EQ_16( st->use_partial_copy, 1 ) && + ( EQ_16( st->rf_frame_type, RF_ALLPRED ) || + ( EQ_16( st->rf_frame_type, RF_GENPRED ) && + ( EQ_16( i_subfr, L_SUBFR ) || EQ_16( i_subfr, 3 * L_SUBFR ) ) ) ) ) { - set16_fx(code, 0, L_SUBFR); + set16_fx( code, 0, L_SUBFR ); } ELSE { - config = PulseConfTable[acelp_cfg.fixed_cdk_index[i_subfr/L_SUBFR]]; + config = PulseConfTable[acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR]]; D_ACELP_indexing_fx( code, config, NB_TRACK_FCB_4T, prm, &st->BER_detect ); - (prm) += 8; + ( prm ) += 8; /*-------------------------------------------------------* * - Add the fixed-gain pitch contribution to code[]. * *-------------------------------------------------------*/ cb_shape_fx( acelp_cfg.pre_emphasis, acelp_cfg.pitch_sharpening, acelp_cfg.phase_scrambling, acelp_cfg.formant_enh, acelp_cfg.formant_tilt, - acelp_cfg.formant_enh_num, acelp_cfg.formant_enh_den, p_A, code, st->tilt_code_fx, extract_h(L_add(pitch_buf[i_subfr/L_SUBFR],26216)), 1, L_SUBFR); + acelp_cfg.formant_enh_num, acelp_cfg.formant_enh_den, p_A, code, st->tilt_code_fx, extract_h( L_add( pitch_buf[i_subfr / L_SUBFR], 26216 ) ), 1, L_SUBFR ); } /*-------------------------------------------------------* * - Generate Gaussian excitation * *-------------------------------------------------------*/ test(); - IF( EQ_16(acelp_cfg.gains_mode[i_subfr/L_SUBFR],7)&&!st->use_partial_copy) + IF( EQ_16( acelp_cfg.gains_mode[i_subfr / L_SUBFR], 7 ) && !st->use_partial_copy ) { - gaus_L2_dec( code2, st->tilt_code_fx, p_A, acelp_cfg.formant_enh_num, &(st->seed_acelp) ); + gaus_L2_dec( code2, st->tilt_code_fx, p_A, acelp_cfg.formant_enh_num, &( st->seed_acelp ) ); } ELSE { - gain_code2 = L_deposit_l(0); - set16_fx(code2,0,L_SUBFR); + gain_code2 = L_deposit_l( 0 ); + set16_fx( code2, 0, L_SUBFR ); } /*-------------------------------------------------* * - Decode codebooks gains. * *-------------------------------------------------*/ - IF( st->acelp_cfg.gains_mode[i_subfr/L_SUBFR] != 0 ) + IF( st->acelp_cfg.gains_mode[i_subfr / L_SUBFR] != 0 ) { - decode_acelp_gains_fx( code, acelp_cfg.gains_mode[i_subfr/L_SUBFR], Es_pred, &gain_pit, &gain_code, &prm, &(st->past_gpit), - &(st->past_gcode), &gain_inov, L_SUBFR, code2, &gain_code2 ); + decode_acelp_gains_fx( code, acelp_cfg.gains_mode[i_subfr / L_SUBFR], Es_pred, &gain_pit, &gain_code, &prm, &( st->past_gpit ), + &( st->past_gcode ), &gain_inov, L_SUBFR, code2, &gain_code2 ); } - IF(st->use_partial_copy&& st->rf_frame_type == RF_ALLPRED) + IF( st->use_partial_copy && st->rf_frame_type == RF_ALLPRED ) { st->past_gcode = 0; } - IF(st->use_partial_copy&& st->rf_frame_type == RF_NOPRED) + IF( st->use_partial_copy && st->rf_frame_type == RF_NOPRED ) { st->past_gpit = 67; } IF( st->igf != 0 ) { /* Rescaling for 12.8k and 16k cores related to BWE */ - IF ( EQ_16(st->L_frame, L_FRAME)) + IF( EQ_16( st->L_frame, L_FRAME ) ) { /* 5/2 times resampled past memories*/ - reScaleLen_fx = add(shl(i_subfr, 1), shr(i_subfr, 1)); - reSampLen = (L_SUBFR * HIBND_ACB_L_FAC); + reScaleLen_fx = add( shl( i_subfr, 1 ), shr( i_subfr, 1 ) ); + reSampLen = ( L_SUBFR * HIBND_ACB_L_FAC ); } ELSE { /* 2 times resampled past memories*/ - reScaleLen_fx = shl(i_subfr, 1); - reSampLen = (L_SUBFR * 2); + reScaleLen_fx = shl( i_subfr, 1 ); + reSampLen = ( L_SUBFR * 2 ); } - Rescale_exc(NULL, &exc[i_subfr], &bwe_exc[reScaleLen_fx], - NULL, L_SUBFR, reSampLen, gain_code, &(st->Q_exc), st->Q_subfr, - exc2, i_subfr, GENERIC); + Rescale_exc( NULL, &exc[i_subfr], &bwe_exc[reScaleLen_fx], + NULL, L_SUBFR, reSampLen, gain_code, &( st->Q_exc ), st->Q_subfr, + exc2, i_subfr, GENERIC ); } ELSE { - Rescale_exc(NULL, &exc[i_subfr], NULL, NULL, L_SUBFR, 0, - gain_code, &(st->Q_exc), st->Q_subfr, exc2, i_subfr, GENERIC); + Rescale_exc( NULL, &exc[i_subfr], NULL, NULL, L_SUBFR, 0, + gain_code, &( st->Q_exc ), st->Q_subfr, exc2, i_subfr, GENERIC ); } /*----------------------------------------------------------* * Update parameters for the next subframe. * * - tilt of code: 0.0 (unvoiced) to 0.5 (voiced) * *----------------------------------------------------------*/ - E_UTIL_voice_factor( exc, i_subfr, code, gain_pit, gain_code, &(st->voice_fac), &(st->tilt_code_fx), L_SUBFR, acelp_cfg.voice_tilt, st->Q_exc, 0); + E_UTIL_voice_factor( exc, i_subfr, code, gain_pit, gain_code, &( st->voice_fac ), &( st->tilt_code_fx ), L_SUBFR, acelp_cfg.voice_tilt, st->Q_exc, 0 ); - pgainT[i_subfr/L_SUBFR] = gain_pit; + pgainT[i_subfr / L_SUBFR] = gain_pit; move16(); /*-------------------------------------------------------* @@ -437,51 +436,50 @@ void decoder_acelp_fx( { gain_code_pre = 0; } - IF ( EQ_16(st->core,ACELP_CORE)&&EQ_16(st->last_core,ACELP_CORE)&&(EQ_16(st->use_partial_copy,1)||EQ_16(st->prev_use_partial_copy,1))) + IF( EQ_16( st->core, ACELP_CORE ) && EQ_16( st->last_core, ACELP_CORE ) && ( EQ_16( st->use_partial_copy, 1 ) || EQ_16( st->prev_use_partial_copy, 1 ) ) ) { - IF( i_subfr > 0 && GT_16(gain_pit,20152)&>_16(st->prev_tilt_code_dec_fx,6553)&&EQ_16(st->next_coder_type,VOICED) - &&( EQ_16(st->use_partial_copy,1) || EQ_16(st->prev_use_partial_copy, 1) ) ) + IF( i_subfr > 0 && GT_16( gain_pit, 20152 ) && GT_16( st->prev_tilt_code_dec_fx, 6553 ) && EQ_16( st->next_coder_type, VOICED ) && ( EQ_16( st->use_partial_copy, 1 ) || EQ_16( st->prev_use_partial_copy, 1 ) ) ) { - gain_pit = mult(gain_pit,sub(26214, mult(i_subfr,51))); + gain_pit = mult( gain_pit, sub( 26214, mult( i_subfr, 51 ) ) ); } - ELSE IF( !st->prev_use_partial_copy && EQ_16(st->last_coder_type,UNVOICED)&&NE_16(st->next_coder_type,UNVOICED)&<_32(gain_code,gain_code_pre)) + ELSE IF( !st->prev_use_partial_copy && EQ_16( st->last_coder_type, UNVOICED ) && NE_16( st->next_coder_type, UNVOICED ) && LT_32( gain_code, gain_code_pre ) ) { gain_code = 0; } } gain_code_pre = gain_code; - st->tilt_code_dec_fx[i_subfr/L_SUBFR] = st->tilt_code_fx; + st->tilt_code_dec_fx[i_subfr / L_SUBFR] = st->tilt_code_fx; - tmp2 = shr(L_SUBFR, 1); - FOR (j = 0; j < 2; j++) + tmp2 = shr( L_SUBFR, 1 ); + FOR( j = 0; j < 2; j++ ) { - FOR (i = sub(tmp2, shr(L_SUBFR, 1)); i < tmp2; i++) + FOR( i = sub( tmp2, shr( L_SUBFR, 1 ) ); i < tmp2; i++ ) { /* code in Q9, gain_pit in Q14, gain_code in Q16; exc Q_new */ - Ltmp = Mpy_32_16_1(gain_code2, code2[i]); - Ltmp = L_shl(Ltmp, add(5,st->Q_exc)); - Ltmp = L_mac(Ltmp, gain_pit, exc[i+i_subfr]); + Ltmp = Mpy_32_16_1( gain_code2, code2[i] ); + Ltmp = L_shl( Ltmp, add( 5, st->Q_exc ) ); + Ltmp = L_mac( Ltmp, gain_pit, exc[i + i_subfr] ); #ifdef BASOP_NOGLOB exc2[i + i_subfr] = round_fx_sat( L_shl_sat( Ltmp, 1 ) ); #else - exc2[i + i_subfr] = round_fx(L_shl(Ltmp, 1)); + exc2[i + i_subfr] = round_fx( L_shl( Ltmp, 1 ) ); #endif - Ltmp2 = Mpy_32_16_1(gain_code, code[i]); - Ltmp2 = L_shl(Ltmp2, add(5,st->Q_exc)); - Ltmp = L_add(Ltmp, Ltmp2); + Ltmp2 = Mpy_32_16_1( gain_code, code[i] ); + Ltmp2 = L_shl( Ltmp2, add( 5, st->Q_exc ) ); + Ltmp = L_add( Ltmp, Ltmp2 ); BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB Ltmp = L_shl_sat( Ltmp, 1 ); /* saturation can occur here */ #else - Ltmp = L_shl(Ltmp, 1); /* saturation can occur here */ -#endif + Ltmp = L_shl( Ltmp, 1 ); /* saturation can occur here */ +#endif BASOP_SATURATE_WARNING_ON_EVS #ifdef BASOP_NOGLOB exc[i + i_subfr] = round_fx_sat( Ltmp ); #else - exc[i + i_subfr] = round_fx(Ltmp); + exc[i + i_subfr] = round_fx( Ltmp ); #endif } tmp2 = L_SUBFR; @@ -495,14 +493,15 @@ void decoder_acelp_fx( gain_pit = gain_pit_tmp; IF( st->igf != 0 ) { - prep_tbe_exc_fx( st->L_frame, + prep_tbe_exc_fx( st->L_frame, #ifdef ADD_IVAS_TBE_CODE - L_SUBFR, + L_SUBFR, #endif - i_subfr, gain_pit, gain_code, code, st->voice_fac, &voice_factors[i_subfr/L_SUBFR], bwe_exc, + i_subfr, gain_pit, gain_code, code, st->voice_fac, &voice_factors[i_subfr / L_SUBFR], bwe_exc, gain_preQ, code_preQ, st->Q_exc, T0, T0_frac, st->coder_type, st->core_brate #ifdef ADD_IVAS_TBE_CODE - , st->element_mode, st->idchan, st->hBWE_TD != NULL, 0 + , + st->element_mode, st->idchan, st->hBWE_TD != NULL, 0 #endif ); } @@ -510,30 +509,32 @@ void decoder_acelp_fx( /*---------------------------------------------------------* * Enhance the excitation * *---------------------------------------------------------*/ - E_UTIL_enhancer( st->voice_fac, stab_fac, st->past_gcode, gain_inov, &(st->gc_threshold_fx), code, &exc2[i_subfr], - gain_pit, & st->dm_fx.prev_gain_code, st->dm_fx.prev_gain_pit, & st->dm_fx.prev_state, st->coder_type, - acelp_cfg.fixed_cdk_index[i_subfr/L_SUBFR], L_SUBFR, st->L_frame, st->Q_exc ); + E_UTIL_enhancer( st->voice_fac, stab_fac, st->past_gcode, gain_inov, &( st->gc_threshold_fx ), code, &exc2[i_subfr], + gain_pit, &st->dm_fx.prev_gain_code, st->dm_fx.prev_gain_pit, &st->dm_fx.prev_state, st->coder_type, + acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR], L_SUBFR, st->L_frame, st->Q_exc ); } /* !RF_NELP frame partial copy */ /*----------------------------------------------------------* * - compute the synthesis speech * *----------------------------------------------------------*/ - rescale_mem(&st->Q_exc, &prev_Q_syn, &st->Q_syn, mem_syn, syn, M, i_subfr); + rescale_mem( &st->Q_exc, &prev_Q_syn, &st->Q_syn, mem_syn, syn, M, i_subfr ); - E_UTIL_synthesis(sub(st->Q_exc,st->Q_syn), p_A, &exc2[i_subfr], &syn[i_subfr], L_SUBFR, mem_syn, 1, M); + E_UTIL_synthesis( sub( st->Q_exc, st->Q_syn ), p_A, &exc2[i_subfr], &syn[i_subfr], L_SUBFR, mem_syn, 1, M ); /*-----------------------------------------------------------------* * update lp_filtered gains for the case of frame erasure *-----------------------------------------------------------------*/ - st->Mode2_lp_gainp = L_add(st->Mode2_lp_gainp, L_mult0(st->past_gpit, weights[i_subfr/L_SUBFR])); /* 2Q29=1Q14*Q15 */ move32(); - st->Mode2_lp_gainc = L_add(st->Mode2_lp_gainc, Mpy_32_16_1(st->past_gcode, weights[i_subfr/L_SUBFR])); /* 15Q16=15Q16*Q15 */ move32(); + st->Mode2_lp_gainp = L_add( st->Mode2_lp_gainp, L_mult0( st->past_gpit, weights[i_subfr / L_SUBFR] ) ); /* 2Q29=1Q14*Q15 */ + move32(); + st->Mode2_lp_gainc = L_add( st->Mode2_lp_gainc, Mpy_32_16_1( st->past_gcode, weights[i_subfr / L_SUBFR] ) ); /* 15Q16=15Q16*Q15 */ + move32(); /*----------------------------------------------------------* * - update pitch lag for guided ACELP * *----------------------------------------------------------*/ test(); - if( st->enableGplc && EQ_16( shr(i_subfr,6), sub(st->nb_subfr,1) )) + if ( st->enableGplc && EQ_16( shr( i_subfr, 6 ), sub( st->nb_subfr, 1 ) ) ) { st->T0_4th = T0; move16(); @@ -542,15 +543,15 @@ void decoder_acelp_fx( /*----------------------------------------------------------* * - Update LPC coeffs * *----------------------------------------------------------*/ - p_A += (M+1); + p_A += ( M + 1 ); /* copy current gain for next subframe use, in case there is no explicit encoding */ prev_gain_pit = gain_pit; } /* end of subframe loop */ - IF(st->BER_detect) + IF( st->BER_detect ) { - FOR (i=0; iL_frame; i++) + FOR( i = 0; i < st->L_frame; i++ ) { exc[i] = 0; move16(); @@ -559,129 +560,129 @@ void decoder_acelp_fx( int_lsp_fx( st->L_frame, st->old_lsp_q_cng, st->lsp_q_cng, st->Aq_cng, M, interpol_frac_fx, 0 ); p_A = st->Aq_cng; - IF(st->last_good < UNVOICED_TRANSITION ) + IF( st->last_good < UNVOICED_TRANSITION ) { - Copy(st->mem_syn2_fx, mem_syn, M ); + Copy( st->mem_syn2_fx, mem_syn, M ); } ELSE { set16_fx( mem_syn, 0, M ); } - FOR (i_subfr = 0; i_subfr < st->L_frame; i_subfr += L_SUBFR) + FOR( i_subfr = 0; i_subfr < st->L_frame; i_subfr += L_SUBFR ) { - E_UTIL_synthesis(sub(st->Q_exc,st->Q_syn), p_A, &exc[i_subfr], &syn[i_subfr], L_SUBFR, mem_syn, 1, M); - p_A += (M+1); + E_UTIL_synthesis( sub( st->Q_exc, st->Q_syn ), p_A, &exc[i_subfr], &syn[i_subfr], L_SUBFR, mem_syn, 1, M ); + p_A += ( M + 1 ); } } tmp = 0; move16(); - pA = A+(st->nb_subfr-1)*(M+1); - set16_fx(h1, 0, add(L_SUBFR,1)); - set16_fx(mem, 0, M); - h1[0] = 32768/32; + pA = A + ( st->nb_subfr - 1 ) * ( M + 1 ); + set16_fx( h1, 0, add( L_SUBFR, 1 ) ); + set16_fx( mem, 0, M ); + h1[0] = 32768 / 32; move16(); - E_UTIL_synthesis(0, pA, h1, h1, L_SUBFR, mem, 0, M); /* impulse response of LPC */ - deemph_fx(h1, st->preemph_fac, L_SUBFR, &tmp); /* impulse response of deemph */ + E_UTIL_synthesis( 0, pA, h1, h1, L_SUBFR, mem, 0, M ); /* impulse response of LPC */ + deemph_fx( h1, st->preemph_fac, L_SUBFR, &tmp ); /* impulse response of deemph */ /* impulse response level = gain introduced by synthesis+deemphasis */ - Ltmp = Dot_productSq16HQ( 0, h1, L_SUBFR, &st->last_gain_syn_deemph_e); - st->last_gain_syn_deemph_e= add(st->last_gain_syn_deemph_e,10/*scaling of h1[0] and E_UTIL_synthesis * 2*/); + Ltmp = Dot_productSq16HQ( 0, h1, L_SUBFR, &st->last_gain_syn_deemph_e ); + st->last_gain_syn_deemph_e = add( st->last_gain_syn_deemph_e, 10 /*scaling of h1[0] and E_UTIL_synthesis * 2*/ ); #ifdef BASOP_NOGLOB - st->last_gain_syn_deemph = round_fx_sat(Sqrt32(Ltmp,&st->last_gain_syn_deemph_e)); + st->last_gain_syn_deemph = round_fx_sat( Sqrt32( Ltmp, &st->last_gain_syn_deemph_e ) ); #else - st->last_gain_syn_deemph = round_fx(Sqrt32(Ltmp,&st->last_gain_syn_deemph_e)); + st->last_gain_syn_deemph = round_fx( Sqrt32( Ltmp, &st->last_gain_syn_deemph_e ) ); #endif /* Do the classification */ { Word16 pit16[NB_SUBFR16k]; Word16 k; - FOR(k = 0 ; k < st->nb_subfr ; k++) + FOR( k = 0; k < st->nb_subfr; k++ ) { - pit16[k] = shl(extract_h(pitch_buf[k]),6);/*Q6*/ + pit16[k] = shl( extract_h( pitch_buf[k] ), 6 ); /*Q6*/ } - FEC_clas_estim_fx(st, /*Opt_AMR_WB*/0, st->L_frame, &(st->clas_dec), st->core_ext_mode, pit16, syn, - &st->lp_ener_FER_fx, /**decision_hyst*/NULL, /**UV_cnt*/ NULL, /**LT_UV_cnt*/ NULL, /**Last_ener*/ NULL, /**locattack*/ NULL, - /**lt_diff_etot*/NULL, /**amr_io_class*/ NULL, /*bitrate*/ 0 , st->Q_syn, /**class_para*/ NULL, st->mem_syn_clas_estim_fx, - &st->classifier_Q_mem_syn, -32768/*-1.f Q15*/, 0/*CLASSIFIER_ACELP*/, 0/*bfi*/, st->last_core_brate, -1); + FEC_clas_estim_fx( st, /*Opt_AMR_WB*/ 0, st->L_frame, &( st->clas_dec ), st->core_ext_mode, pit16, syn, + &st->lp_ener_FER_fx, /**decision_hyst*/ NULL, /**UV_cnt*/ NULL, /**LT_UV_cnt*/ NULL, /**Last_ener*/ NULL, /**locattack*/ NULL, + /**lt_diff_etot*/ NULL, /**amr_io_class*/ NULL, /*bitrate*/ 0, st->Q_syn, /**class_para*/ NULL, st->mem_syn_clas_estim_fx, + &st->classifier_Q_mem_syn, -32768 /*-1.f Q15*/, 0 /*CLASSIFIER_ACELP*/, 0 /*bfi*/, st->last_core_brate, -1 ); } /* Update Pitch Lag memory */ - Copy32(&st->old_pitch_buf_fx[st->nb_subfr], st->old_pitch_buf_fx, st->nb_subfr); - Copy32(pitch_buf, &st->old_pitch_buf_fx[st->nb_subfr], st->nb_subfr); + Copy32( &st->old_pitch_buf_fx[st->nb_subfr], st->old_pitch_buf_fx, st->nb_subfr ); + Copy32( pitch_buf, &st->old_pitch_buf_fx[st->nb_subfr], st->nb_subfr ); { Word16 pBuf_scaleSyn[NB_SUBFR16k]; - FOR(i=0; i<(st->L_frame/L_SUBFR); i++) + FOR( i = 0; i < ( st->L_frame / L_SUBFR ); i++ ) { - pBuf_scaleSyn[i] = round_fx(pitch_buf[i]); + pBuf_scaleSyn[i] = round_fx( pitch_buf[i] ); } - Scale_sig(mem_back, M, sub(st->Q_syn,Q_mem_back)); + Scale_sig( mem_back, M, sub( st->Q_syn, Q_mem_back ) ); force_scale_syn = 0; move16(); test(); test(); test(); - IF ( (EQ_16(st->clas_dec,ONSET))||((GE_16(st->last_good,VOICED_TRANSITION))&&(LT_16(st->last_good,INACTIVE_CLAS)))) + IF( ( EQ_16( st->clas_dec, ONSET ) ) || ( ( GE_16( st->last_good, VOICED_TRANSITION ) ) && ( LT_16( st->last_good, INACTIVE_CLAS ) ) ) ) { force_scale_syn = 1; move16(); } - FEC_scale_syn_fx( st->L_frame, &update_flg,st->clas_dec, st->last_good, syn, pBuf_scaleSyn, st->enr_old_fx, 0, - st->coder_type, LSF_Q_prediction, &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate, - exc, exc2, A, &(st->old_enr_LP), mem_back, mem_syn, st->Q_exc, st->Q_syn , avoid_lpc_burst_on_recovery , force_scale_syn); + FEC_scale_syn_fx( st->L_frame, &update_flg, st->clas_dec, st->last_good, syn, pBuf_scaleSyn, st->enr_old_fx, 0, + st->coder_type, LSF_Q_prediction, &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate, + exc, exc2, A, &( st->old_enr_LP ), mem_back, mem_syn, st->Q_exc, st->Q_syn, avoid_lpc_burst_on_recovery, force_scale_syn ); } /* update ACELP synthesis memory */ Copy( mem_syn, st->mem_syn2_fx, M ); - Copy( syn+st->L_frame-L_SYN_MEM, st->mem_syn_r, L_SYN_MEM ); + Copy( syn + st->L_frame - L_SYN_MEM, st->mem_syn_r, L_SYN_MEM ); /* Deemphasis and output synth and ZIR */ tmp_deemph = st->syn[M]; move16(); - E_UTIL_deemph2(st->Q_syn, syn, st->preemph_fac, st->L_frame, &tmp_deemph); /* tmp_deemph and syn in Q0 starting from here*/ + E_UTIL_deemph2( st->Q_syn, syn, st->preemph_fac, st->L_frame, &tmp_deemph ); /* tmp_deemph and syn in Q0 starting from here*/ - bufferCopyFx(syn+st->L_frame- st->L_frame/2, hTcxDec->old_syn_Overl, shr(st->L_frame, 1),0 /*Qf_syn*/, -1 /*Qf_old_xnq*/, 0 , 0 /*Q_old_xnq*/); + bufferCopyFx( syn + st->L_frame - st->L_frame / 2, hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), 0 /*Qf_syn*/, -1 /*Qf_old_xnq*/, 0, 0 /*Q_old_xnq*/ ); - Copy(syn+st->L_frame-M-1, st->syn, 1+M); /*Q0*/ + Copy( syn + st->L_frame - M - 1, st->syn, 1 + M ); /*Q0*/ - Copy(syn, synth, st->L_frame); - IF (st->hBWE_TD != NULL) + Copy( syn, synth, st->L_frame ); + IF( st->hBWE_TD != NULL ) { - Copy(syn, hBWE_TD->old_core_synth_fx, st->L_frame); + Copy( syn, hBWE_TD->old_core_synth_fx, st->L_frame ); } /* update old_Aq */ - Copy(exc_buf+st->L_frame, st->old_exc_fx, L_EXC_MEM_DEC); + Copy( exc_buf + st->L_frame, st->old_exc_fx, L_EXC_MEM_DEC ); /* Output pitch parameters for bass post-filter */ - FOR (i_subfr = 0; i_subfr < st->L_frame; i_subfr += L_SUBFR) + FOR( i_subfr = 0; i_subfr < st->L_frame; i_subfr += L_SUBFR ) { - *pT++ = round_fx(pitch_buf[i_subfr/L_SUBFR]); + *pT++ = round_fx( pitch_buf[i_subfr / L_SUBFR] ); } hTcxDec->tcxltp_last_gain_unmodified = 0; /*Update MODE1*/ - Copy( p_A-(M+1), st->old_Aq_12_8_fx, M+1 ); + Copy( p_A - ( M + 1 ), st->old_Aq_12_8_fx, M + 1 ); st->old_Es_pred_fx = Es_pred; hTcxDec->tcxltp_third_last_pitch = hTcxDec->tcxltp_second_last_pitch; hTcxDec->tcxltp_second_last_pitch = st->old_fpitch; - st->old_fpitch = pitch_buf[shr(st->L_frame, 6) - 1]; + st->old_fpitch = pitch_buf[shr( st->L_frame, 6 ) - 1]; move32(); return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/dec_acelp.c b/lib_dec/dec_acelp.c index 3480a7794..cb735709a 100644 --- a/lib_dec/dec_acelp.c +++ b/lib_dec/dec_acelp.c @@ -365,4 +365,4 @@ void fcb_pulse_track_joint_decode_ivas( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/dec_acelp_fx.c b/lib_dec/dec_acelp_fx.c index 7766a32ca..d2bcffb6c 100644 --- a/lib_dec/dec_acelp_fx.c +++ b/lib_dec/dec_acelp_fx.c @@ -12,25 +12,24 @@ #include "rom_com.h" #include "rom_basop_util.h" #ifdef IVAS_FLOAT_FIXED -#define _1_CODE 0x200 /*codebook excitation Q9 */ +#define _1_CODE 0x200 /*codebook excitation Q9 */ /*---------------------------------------------------------------------* * Local function prototypes *---------------------------------------------------------------------*/ -static void D_ACELP_decode_arithtrack_fx(Word16 v[], Word32 s, Word16 p, Word16 trackstep, Word16 tracklen); +static void D_ACELP_decode_arithtrack_fx( Word16 v[], Word32 s, Word16 p, Word16 trackstep, Word16 tracklen ); /*---------------------------------------------------------------------* -* Function D_ACELP_indexing_fx() -* -*---------------------------------------------------------------------*/ + * Function D_ACELP_indexing_fx() + * + *---------------------------------------------------------------------*/ void D_ACELP_indexing_fx( Word16 code[], PulseConfig config, Word16 num_tracks, - Word16 index[] - ,Word16 *BER_detect -) + Word16 index[], + Word16 *BER_detect ) { Word16 track, pulses, k, pulsestrack[NB_TRACK_FCB_4T]; Word32 s; @@ -39,16 +38,16 @@ void D_ACELP_indexing_fx( UWord32 idxs32[4], index_n[NB_TRACK_FCB_4T]; Word16 restpulses, wordcnt, wordcnt32; - assert(num_tracks == NB_TRACK_FCB_4T); + assert( num_tracks == NB_TRACK_FCB_4T ); - wordcnt = shr(add(config.bits,15),4); /* ceil(bits/16) */ + wordcnt = shr( add( config.bits, 15 ), 4 ); /* ceil(bits/16) */ /* check if some tracks have more pulses */ - restpulses = s_and((Word16)config.nb_pulse, sub(num_tracks, 1)); + restpulses = s_and( (Word16) config.nb_pulse, sub( num_tracks, 1 ) ); /* cast to short */ - idxs= (UWord16 *)idxs32; - FOR (k=0; k=1; track--) + fcb_pulse_track_joint_decode_fx( idxs, wordcnt, index_n, pulsestrack, num_tracks ); + FOR( track = num_tracks - 1; track >= 1; track-- ) { pulses = pulsestrack[track]; move16(); - IF (pulses) + IF( pulses ) { /* divide by number of possible states: rest is actual state and * the integer part goes to next track */ s = index_n[track]; /* decode state to actual pulse positions on track */ - D_ACELP_decode_arithtrack_fx(code+track, s, pulses, num_tracks, 16); + D_ACELP_decode_arithtrack_fx( code + track, s, pulses, num_tracks, 16 ); } - ELSE /* track is empty */ + ELSE /* track is empty */ { - FOR (k=track; k < 16*num_tracks; k+=num_tracks) + FOR( k = track; k < 16 * num_tracks; k += num_tracks ) { code[k] = 0; move16(); @@ -165,12 +166,12 @@ void D_ACELP_indexing_fx( } } - s = L_add(index_n[0], 0); + s = L_add( index_n[0], 0 ); pulses = pulsestrack[0]; move16(); /* safety check in case of bit errors */ - IF( GE_32(s,pulsestostates[16][pulses-1])) + IF( GE_32( s, pulsestostates[16][pulses - 1] ) ) { set16_fx( code, 0, L_SUBFR ); *BER_detect = 1; @@ -178,12 +179,13 @@ void D_ACELP_indexing_fx( return; } - IF (pulses) + IF( pulses ) { - D_ACELP_decode_arithtrack_fx(code, s, pulses, num_tracks, 16); + D_ACELP_decode_arithtrack_fx( code, s, pulses, num_tracks, 16 ); } - ELSE {/* track is empty */ - FOR (k=0; k < 16*num_tracks; k+=num_tracks) + ELSE + { /* track is empty */ + FOR( k = 0; k < 16 * num_tracks; k += num_tracks ) { code[k] = 0; move16(); @@ -192,55 +194,60 @@ void D_ACELP_indexing_fx( } } -static void D_ACELP_decode_arithtrack_fx(Word16 v[], Word32 s, Word16 p, Word16 trackstep, Word16 tracklen) +static void D_ACELP_decode_arithtrack_fx( Word16 v[], Word32 s, Word16 p, Word16 trackstep, Word16 tracklen ) { Word16 k, idx; /*initialy s was UWords32 but it seems that s is never greater then 0x80000000*/ /*this assumption reduces complexity but if it is not true than exit*/ - assert(s >= 0); + assert( s >= 0 ); - FOR (k=(tracklen)-1; k>= 0; k--) + FOR( k = (tracklen) -1; k >= 0; k-- ) { - idx = imult1616(k,trackstep); - v[idx] = 0; /* default: there is no pulse here */ move16(); + idx = imult1616( k, trackstep ); + v[idx] = 0; /* default: there is no pulse here */ + move16(); - FOR(; p; p--) /* one pulse placed, so one less left */ + FOR( ; p; p-- ) /* one pulse placed, so one less left */ { - IF (LT_32(s, pulsestostates[k][p-1])) + IF( LT_32( s, pulsestostates[k][p - 1] ) ) { BREAK; } - s = L_sub(s, pulsestostates[k][p-1]); + s = L_sub( s, pulsestostates[k][p - 1] ); - IF (v[idx] != 0) /* there is a pulse here already = sign is known */ + IF( v[idx] != 0 ) /* there is a pulse here already = sign is known */ { - if (v[idx] > 0) + if ( v[idx] > 0 ) { - v[idx] = add(v[idx],_1_CODE); /* place one more pulse here */ move16(); + v[idx] = add( v[idx], _1_CODE ); /* place one more pulse here */ + move16(); } - if (v[idx] <= 0) + if ( v[idx] <= 0 ) { - v[idx] = sub(v[idx],_1_CODE); /* place one more pulse here */ move16(); + v[idx] = sub( v[idx], _1_CODE ); /* place one more pulse here */ + move16(); } } - ELSE /* this is the first pulse here -> determine sign */ + ELSE /* this is the first pulse here -> determine sign */ { - v[idx] = +_1_CODE; /* place a negative pulse here */ move16(); - if (L_and(s, 0x1) != 0) + v[idx] = +_1_CODE; /* place a negative pulse here */ + move16(); + if ( L_and( s, 0x1 ) != 0 ) { - v[idx] = -_1_CODE; /* place a negative pulse here */ move16(); + v[idx] = -_1_CODE; /* place a negative pulse here */ + move16(); } - s = L_lshr(s,1); + s = L_lshr( s, 1 ); } } } } -void fcb_pulse_track_joint_decode_fx(UWord16 *idxs, Word16 wordcnt, UWord32 *index_n, Word16 *pulse_num, Word16 track_num) +void fcb_pulse_track_joint_decode_fx( UWord16 *idxs, Word16 wordcnt, UWord32 *index_n, Word16 *pulse_num, Word16 track_num ) { - Word16 hi_to_low[10] = { 0, 0, 0, 3, 9, 5, 3, 1, 8, 8}; + Word16 hi_to_low[10] = { 0, 0, 0, 3, 9, 5, 3, 1, 8, 8 }; UWord32 index; Word32 indx_tmp; @@ -256,16 +263,16 @@ void fcb_pulse_track_joint_decode_fx(UWord16 *idxs, Word16 wordcnt, UWord32 *ind indx_flag_2 = 0; move16(); - FOR (track = 0; track < track_num; track++) + FOR( track = 0; track < track_num; track++ ) { - indx_flag = add(indx_flag, shr(pulse_num[track], 2)); - indx_flag_1 = add(indx_flag_1, shr(pulse_num[track], 1)); - indx_flag_2 = add(indx_flag_2, shr(pulse_num[track], 3)); + indx_flag = add( indx_flag, shr( pulse_num[track], 2 ) ); + indx_flag_1 = add( indx_flag_1, shr( pulse_num[track], 1 ) ); + indx_flag_2 = add( indx_flag_2, shr( pulse_num[track], 3 ) ); } hi_to_low[4] = 1; move16(); - if (GE_16(indx_flag, track_num)) + if ( GE_16( indx_flag, track_num ) ) { hi_to_low[4] = 9; move16(); @@ -273,39 +280,39 @@ void fcb_pulse_track_joint_decode_fx(UWord16 *idxs, Word16 wordcnt, UWord32 *ind hi_to_low[7] = 1; move16(); - if (GE_16(indx_flag_2, 1)) + if ( GE_16( indx_flag_2, 1 ) ) { hi_to_low[7] = 9; move16(); } - IF (GE_16(indx_flag_1, track_num)) + IF( GE_16( indx_flag_1, track_num ) ) { - IF (GE_16(indx_flag, track_num)) + IF( GE_16( indx_flag, track_num ) ) { - index = L_deposit_l(0); - IF (GE_16(indx_flag_2, 1)) + index = L_deposit_l( 0 ); + IF( GE_16( indx_flag_2, 1 ) ) { - FOR (track = sub(wordcnt, 1); track >= 6; track--) + FOR( track = sub( wordcnt, 1 ); track >= 6; track-- ) { - index = L_add(L_lshl(index, 16), (UWord32) idxs[track]); + index = L_add( L_lshl( index, 16 ), (UWord32) idxs[track] ); } - index_n[3] = L_add(L_lshl(idxs[5], 8), L_and(L_lshr(idxs[4], 8), 0xFF)); + index_n[3] = L_add( L_lshl( idxs[5], 8 ), L_and( L_lshr( idxs[4], 8 ), 0xFF ) ); move32(); - index_n[2] = L_and(L_add(L_lshl(idxs[4], 16), idxs[3]), 0xFFFFFF); + index_n[2] = L_and( L_add( L_lshl( idxs[4], 16 ), idxs[3] ), 0xFFFFFF ); move32(); - index_n[1] = L_add(L_lshl(idxs[2], 8), L_and(L_lshr(idxs[1], 8), 0xFF)); + index_n[1] = L_add( L_lshl( idxs[2], 8 ), L_and( L_lshr( idxs[1], 8 ), 0xFF ) ); move32(); - index_n[0] = L_and(L_add(L_lshl(idxs[1], 16), idxs[0]), 0xFFFFFF); + index_n[0] = L_and( L_add( L_lshl( idxs[1], 16 ), idxs[0] ), 0xFFFFFF ); move32(); } ELSE { - FOR (track = (wordcnt-1); track >= track_num; track--) + FOR( track = ( wordcnt - 1 ); track >= track_num; track-- ) { - index = L_add(L_lshl(index, 16), (UWord32) idxs[track]); + index = L_add( L_lshl( index, 16 ), (UWord32) idxs[track] ); } - FOR (track = 0; track < track_num; track++) + FOR( track = 0; track < track_num; track++ ) { index_n[track] = (UWord32) idxs[track]; move32(); @@ -314,58 +321,58 @@ void fcb_pulse_track_joint_decode_fx(UWord16 *idxs, Word16 wordcnt, UWord32 *ind } ELSE { - index = L_deposit_l(0); - FOR (track = (wordcnt-1); track >= 2; track--) + index = L_deposit_l( 0 ); + FOR( track = ( wordcnt - 1 ); track >= 2; track-- ) { - index = L_add(L_lshl(index, 16), (UWord32) idxs[track]); + index = L_add( L_lshl( index, 16 ), (UWord32) idxs[track] ); } - index_n[3] = L_and((Word32) idxs[1], 0xFF); + index_n[3] = L_and( (Word32) idxs[1], 0xFF ); move32(); - index_n[2] = L_lshr((Word32) idxs[1], 8); + index_n[2] = L_lshr( (Word32) idxs[1], 8 ); move32(); - index_n[1] = L_and((Word32) idxs[0], 0xFF); + index_n[1] = L_and( (Word32) idxs[0], 0xFF ); move32(); - index_n[0] = L_lshr((Word32) idxs[0], 8); + index_n[0] = L_lshr( (Word32) idxs[0], 8 ); move32(); } - track_num1 = sub(track_num, 1); + track_num1 = sub( track_num, 1 ); pulse_num1 = pulse_num[track_num1]; move16(); - index = L_add(L_lshl(index, hi_to_low[pulse_num1]), L_lshr(index_n[track_num1], low_len[pulse_num1])); - FOR (track = (track_num-1); track > 0; track--) + index = L_add( L_lshl( index, hi_to_low[pulse_num1] ), L_lshr( index_n[track_num1], low_len[pulse_num1] ) ); + FOR( track = ( track_num - 1 ); track > 0; track-- ) { - track_num1 = sub(track, 1); + track_num1 = sub( track, 1 ); pulse_num0 = pulse_num[track_num1]; move16(); pulse_num1 = pulse_num[track]; move16(); - index = L_add(L_lshl(index, hi_to_low[pulse_num0]), L_lshr(index_n[track_num1], low_len[pulse_num0])); + index = L_add( L_lshl( index, hi_to_low[pulse_num0] ), L_lshr( index_n[track_num1], low_len[pulse_num0] ) ); - iDiv_and_mod_32(index, indx_fact[pulse_num1], &div_tmp, &indx_tmp, 0); - index_n[track] = L_add(L_and(index_n[track], low_mask[pulse_num1]), L_lshl(indx_tmp, low_len[pulse_num1])); - index = L_add(div_tmp, 0); + iDiv_and_mod_32( index, indx_fact[pulse_num1], &div_tmp, &indx_tmp, 0 ); + index_n[track] = L_add( L_and( index_n[track], low_mask[pulse_num1] ), L_lshl( indx_tmp, low_len[pulse_num1] ) ); + index = L_add( div_tmp, 0 ); } pulse_num1 = pulse_num[0]; move16(); - index_n[0] = L_add(L_and(index_n[0], low_mask[pulse_num1]), L_lshl(index, low_len[pulse_num1])); + index_n[0] = L_add( L_and( index_n[0], low_mask[pulse_num1] ), L_lshl( index, low_len[pulse_num1] ) ); move32(); } ELSE { - index = L_deposit_l(0); - FOR (track = (wordcnt-1); track >= 0; track--) + index = L_deposit_l( 0 ); + FOR( track = ( wordcnt - 1 ); track >= 0; track-- ) { - index = L_add(L_lshl(index, 16), (UWord32) idxs[track]); + index = L_add( L_lshl( index, 16 ), (UWord32) idxs[track] ); } - FOR (track = 3; track > 0; track--) + FOR( track = 3; track > 0; track-- ) { pulse_num1 = pulse_num[track]; move16(); - index_n[track] = L_and(index, index_mask_ACELP[pulse_num1]); + index_n[track] = L_and( index, index_mask_ACELP[pulse_num1] ); move32(); - index = L_lshr(index, index_len[pulse_num1]); + index = L_lshr( index, index_len[pulse_num1] ); } index_n[0] = index; move32(); diff --git a/lib_dec/dec_acelp_tcx_main.c b/lib_dec/dec_acelp_tcx_main.c index adc2dfb76..26f182e35 100644 --- a/lib_dec/dec_acelp_tcx_main.c +++ b/lib_dec/dec_acelp_tcx_main.c @@ -53,216 +53,216 @@ static void decode_frame_type_flt( STEREO_CNG_DEC_HANDLE hStereoCng /* i/o: Stereo CNG data structure */ ) { - int16_t frame_size_index, n; - int32_t total_brate; + int16_t frame_size_index, n; + int32_t total_brate; - frame_size_index = 0; - total_brate = st->total_brate; + frame_size_index = 0; + total_brate = st->total_brate; - /* Get Frame Type (NULL,SID,ACTIVE) and Frame Mode (2kbps, 4kbps,...) */ + /* Get Frame Type (NULL,SID,ACTIVE) and Frame Mode (2kbps, 4kbps,...) */ - if (st->mdct_sw == MODE1) - { - st->m_frame_type = ACTIVE_FRAME; - - for (n = 0; n < FRAME_SIZE_NB; n++) - { - if (FrameSizeConfig[n].frame_bits == st->total_brate / FRAMES_PER_SEC) - { - frame_size_index = n; - break; - } - } - } - else - { - /* ZERO Frame */ - if (st->total_brate == FRAME_NO_DATA) + if ( st->mdct_sw == MODE1 ) { - st->bwidth = st->last_bwidth; - st->m_frame_type = ZERO_FRAME; - } - - /* SID frame */ - else if (st->total_brate == SID_2k40) - { - uint16_t frame_len_indicator; - - st->cng_type = get_next_indice(st, 1); - - if (st->cng_type != FD_CNG) - { - st->BER_detect = 1; - st->cng_type = FD_CNG; - } - st->m_frame_type = SID_FRAME; - frame_size_index = 1; - st->bwidth = get_next_indice(st, 2); - - frame_len_indicator = get_next_indice(st, 1); - if (st->bwidth == NB) - { - if (frame_len_indicator) - { - st->BER_detect = 1; - } - frame_len_indicator = 0; - } - if (frame_len_indicator == 0) - { - st->L_frame = L_FRAME; - st->total_brate = ACELP_9k60; - } - else - { - st->L_frame = L_FRAME16k; - if (st->last_total_brate == ACELP_16k40 || st->last_total_brate == ACELP_24k40) - { - st->total_brate = st->last_total_brate; - } - else - { - st->total_brate = 16400; - } - } + st->m_frame_type = ACTIVE_FRAME; - for (n = 0; n < FRAME_SIZE_NB; n++) - { - if (FrameSizeConfig[n].frame_bits == st->total_brate / FRAMES_PER_SEC) + for ( n = 0; n < FRAME_SIZE_NB; n++ ) { - frame_size_index = n; - break; + if ( FrameSizeConfig[n].frame_bits == st->total_brate / FRAMES_PER_SEC ) + { + frame_size_index = n; + break; + } } - } } - /* EVS MODES */ else { - /* Get Frame mode */ - st->m_frame_type = ACTIVE_FRAME; + /* ZERO Frame */ + if ( st->total_brate == FRAME_NO_DATA ) + { + st->bwidth = st->last_bwidth; + st->m_frame_type = ZERO_FRAME; + } - for (n = 0; n < FRAME_SIZE_NB; n++) - { - if (FrameSizeConfig[n].frame_bits == st->total_brate / FRAMES_PER_SEC) + /* SID frame */ + else if ( st->total_brate == SID_2k40 ) { - frame_size_index = n; - break; + uint16_t frame_len_indicator; + + st->cng_type = get_next_indice( st, 1 ); + + if ( st->cng_type != FD_CNG ) + { + st->BER_detect = 1; + st->cng_type = FD_CNG; + } + st->m_frame_type = SID_FRAME; + frame_size_index = 1; + st->bwidth = get_next_indice( st, 2 ); + + frame_len_indicator = get_next_indice( st, 1 ); + if ( st->bwidth == NB ) + { + if ( frame_len_indicator ) + { + st->BER_detect = 1; + } + frame_len_indicator = 0; + } + if ( frame_len_indicator == 0 ) + { + st->L_frame = L_FRAME; + st->total_brate = ACELP_9k60; + } + else + { + st->L_frame = L_FRAME16k; + if ( st->last_total_brate == ACELP_16k40 || st->last_total_brate == ACELP_24k40 ) + { + st->total_brate = st->last_total_brate; + } + else + { + st->total_brate = 16400; + } + } + + for ( n = 0; n < FRAME_SIZE_NB; n++ ) + { + if ( FrameSizeConfig[n].frame_bits == st->total_brate / FRAMES_PER_SEC ) + { + frame_size_index = n; + break; + } + } } - } - - if (st->rf_flag == 0) - { - /* Get bandwidth info */ - st->bwidth = get_next_indice(st, FrameSizeConfig[frame_size_index].bandwidth_bits); - st->bwidth += FrameSizeConfig[frame_size_index].bandwidth_min; - } - else - { - st->bwidth += FrameSizeConfig[frame_size_index].bandwidth_min; - } - - if (st->bwidth > FB) - { - st->bwidth = FB; - st->BER_detect = 1; - } - - if (st->bwidth > SWB && st->total_brate < ACELP_16k40) - { - st->bwidth = SWB; - st->BER_detect = 1; - } - - /* Get reserved bit */ - if (FrameSizeConfig[frame_size_index].reserved_bits && st->rf_flag == 0) - { - if (get_next_indice(st, 1) != 0) + /* EVS MODES */ + else { - st->BER_detect = 1; + /* Get Frame mode */ + st->m_frame_type = ACTIVE_FRAME; + + for ( n = 0; n < FRAME_SIZE_NB; n++ ) + { + if ( FrameSizeConfig[n].frame_bits == st->total_brate / FRAMES_PER_SEC ) + { + frame_size_index = n; + break; + } + } + + if ( st->rf_flag == 0 ) + { + /* Get bandwidth info */ + st->bwidth = get_next_indice( st, FrameSizeConfig[frame_size_index].bandwidth_bits ); + st->bwidth += FrameSizeConfig[frame_size_index].bandwidth_min; + } + else + { + st->bwidth += FrameSizeConfig[frame_size_index].bandwidth_min; + } + + if ( st->bwidth > FB ) + { + st->bwidth = FB; + st->BER_detect = 1; + } + + if ( st->bwidth > SWB && st->total_brate < ACELP_16k40 ) + { + st->bwidth = SWB; + st->BER_detect = 1; + } + + /* Get reserved bit */ + if ( FrameSizeConfig[frame_size_index].reserved_bits && st->rf_flag == 0 ) + { + if ( get_next_indice( st, 1 ) != 0 ) + { + st->BER_detect = 1; + } + assert( FrameSizeConfig[frame_size_index].reserved_bits == 1 ); + } } - assert(FrameSizeConfig[frame_size_index].reserved_bits == 1); - } } - } - st->rate_switching_init = 0; + st->rate_switching_init = 0; - if (st->last_codec_mode != MODE2 || !st->BER_detect) - { - /* Mode or Rate Change */ - if ((st->m_frame_type == ACTIVE_FRAME || st->m_frame_type == SID_FRAME) && ((st->total_brate != st->last_total_brate) || (st->bwidth != st->last_bwidth) || (st->last_codec_mode == MODE1) || (st->rf_flag != st->rf_flag_last) || st->force_lpd_reset)) + if ( st->last_codec_mode != MODE2 || !st->BER_detect ) { - st->rate_switching_init = 1; + /* Mode or Rate Change */ + if ( ( st->m_frame_type == ACTIVE_FRAME || st->m_frame_type == SID_FRAME ) && ( ( st->total_brate != st->last_total_brate ) || ( st->bwidth != st->last_bwidth ) || ( st->last_codec_mode == MODE1 ) || ( st->rf_flag != st->rf_flag_last ) || st->force_lpd_reset ) ) + { + st->rate_switching_init = 1; - /* Reconf Core */ - mode_switch_decoder_LPD(st, st->bwidth, st->total_brate, st->last_total_brate, frame_size_index, 0, st->element_mode); + /* Reconf Core */ + mode_switch_decoder_LPD( st, st->bwidth, st->total_brate, st->last_total_brate, frame_size_index, 0, st->element_mode ); - /* Reconf. CLDFB: check if the CLDFB works on the right sample rate */ - if ((st->cldfbAna->no_channels * st->cldfbAna->no_col) != st->L_frame) - { - resampleCldfb_ivas(st->cldfbAna, (st->L_frame * FRAMES_PER_SEC)); - if (st->L_frame <= L_FRAME16k) - { - resampleCldfb_ivas(st->cldfbBPF, (st->L_frame * FRAMES_PER_SEC)); - } - } - if (st->bwidth == NB) - { - int16_t nBand_nb = (int16_t)(8000 * st->cldfbSyn->no_channels / st->output_Fs); - st->cldfbSyn->bandsToZero = st->cldfbSyn->no_channels - nBand_nb; - } - else - { - st->cldfbSyn->bandsToZero = 0; - } - - /*Reconf Frequency-domain based CNG*/ - configureFdCngDec(st->hFdCngDec, st->bwidth, st->rf_flag == 1 && st->total_brate == ACELP_13k20 ? ACELP_9k60 : st->total_brate, st->L_frame, st->last_L_frame, st->element_mode); - if (st->last_L_frame != st->L_frame && st->L_frame <= L_FRAME16k && st->last_L_frame <= L_FRAME16k) - { - lerp_flt(st->hFdCngDec->hFdCngCom->olapBufferSynth2_flt, st->hFdCngDec->hFdCngCom->olapBufferSynth2_flt, st->L_frame * 2, st->last_L_frame * 2); - if (st->m_frame_type == SID_FRAME && st->hFdCngDec->hFdCngCom->frame_type_previous != ACTIVE_FRAME) - { - lerp_flt(st->hFdCngDec->hFdCngCom->olapBufferSynth_flt, st->hFdCngDec->hFdCngCom->olapBufferSynth_flt, st->L_frame * 2, st->last_L_frame * 2); - lerp_flt(hStereoCng->olapBufferSynth22, hStereoCng->olapBufferSynth22, st->L_frame * 2, st->last_L_frame * 2); + /* Reconf. CLDFB: check if the CLDFB works on the right sample rate */ + if ( ( st->cldfbAna->no_channels * st->cldfbAna->no_col ) != st->L_frame ) + { + resampleCldfb_ivas( st->cldfbAna, ( st->L_frame * FRAMES_PER_SEC ) ); + if ( st->L_frame <= L_FRAME16k ) + { + resampleCldfb_ivas( st->cldfbBPF, ( st->L_frame * FRAMES_PER_SEC ) ); + } + } + if ( st->bwidth == NB ) + { + int16_t nBand_nb = (int16_t) ( 8000 * st->cldfbSyn->no_channels / st->output_Fs ); + st->cldfbSyn->bandsToZero = st->cldfbSyn->no_channels - nBand_nb; + } + else + { + st->cldfbSyn->bandsToZero = 0; + } - if (st->L_frame == L_FRAME) - { - for (n = 0; n < st->L_frame * 2; n++) + /*Reconf Frequency-domain based CNG*/ + configureFdCngDec( st->hFdCngDec, st->bwidth, st->rf_flag == 1 && st->total_brate == ACELP_13k20 ? ACELP_9k60 : st->total_brate, st->L_frame, st->last_L_frame, st->element_mode ); + if ( st->last_L_frame != st->L_frame && st->L_frame <= L_FRAME16k && st->last_L_frame <= L_FRAME16k ) { - st->hFdCngDec->hFdCngCom->olapBufferSynth_flt[n] = st->hFdCngDec->hFdCngCom->olapBufferSynth_flt[n] * 1.25f; + lerp_flt( st->hFdCngDec->hFdCngCom->olapBufferSynth2_flt, st->hFdCngDec->hFdCngCom->olapBufferSynth2_flt, st->L_frame * 2, st->last_L_frame * 2 ); + if ( st->m_frame_type == SID_FRAME && st->hFdCngDec->hFdCngCom->frame_type_previous != ACTIVE_FRAME ) + { + lerp_flt( st->hFdCngDec->hFdCngCom->olapBufferSynth_flt, st->hFdCngDec->hFdCngCom->olapBufferSynth_flt, st->L_frame * 2, st->last_L_frame * 2 ); + lerp_flt( hStereoCng->olapBufferSynth22, hStereoCng->olapBufferSynth22, st->L_frame * 2, st->last_L_frame * 2 ); + + if ( st->L_frame == L_FRAME ) + { + for ( n = 0; n < st->L_frame * 2; n++ ) + { + st->hFdCngDec->hFdCngCom->olapBufferSynth_flt[n] = st->hFdCngDec->hFdCngCom->olapBufferSynth_flt[n] * 1.25f; + } + } + else + { + for ( n = 0; n < st->L_frame * 2; n++ ) + { + st->hFdCngDec->hFdCngCom->olapBufferSynth_flt[n] = st->hFdCngDec->hFdCngCom->olapBufferSynth_flt[n] / 1.25f; + } + } + } } - } - else - { - for (n = 0; n < st->L_frame * 2; n++) + + if ( st->bwidth != st->last_bwidth ) + { + st->hFdCngDec->hFdCngCom->msFrCnt_init_counter = 0; + st->hFdCngDec->hFdCngCom->init_old_flt = FLT_MAX; + } + + if ( st->tcxonly ) { - st->hFdCngDec->hFdCngCom->olapBufferSynth_flt[n] = st->hFdCngDec->hFdCngCom->olapBufferSynth_flt[n] / 1.25f; + st->p_bpf_noise_buf = NULL; + } + else + { + st->p_bpf_noise_buf = st->bpf_noise_buf; } - } } - } - - if (st->bwidth != st->last_bwidth) - { - st->hFdCngDec->hFdCngCom->msFrCnt_init_counter = 0; - st->hFdCngDec->hFdCngCom->init_old_flt = FLT_MAX; - } - - if (st->tcxonly) - { - st->p_bpf_noise_buf = NULL; - } - else - { - st->p_bpf_noise_buf = st->bpf_noise_buf; - } } - } - st->total_brate = total_brate; + st->total_brate = total_brate; - return; + return; } @@ -397,7 +397,7 @@ void dec_acelp_tcx_frame( /* Decode the LPD data */ if ( st->m_decodeMode == DEC_NO_FRAM_LOSS ) { - decoder_LPD( st, output, pcmbufFB, &tmp, bpf_noise_buf, 0, &bitsRead, param, pitch_buf, voice_factors, ptr_bwe_exc ); + decoder_LPD( st, output, pcmbufFB, &tmp, bpf_noise_buf, 0, &bitsRead, param, pitch_buf, voice_factors, ptr_bwe_exc ); if ( !st->rate_switching_init && ( st->last_codec_mode ) == MODE2 && !( st->use_partial_copy && st->rf_frame_type >= RF_TCXFD && st->rf_frame_type <= RF_TCXTD2 ) && st->bfi ) { @@ -408,7 +408,7 @@ void dec_acelp_tcx_frame( } else if ( st->m_decodeMode == DEC_CONCEALMENT_EXT ) { - decoder_LPD( st, output, pcmbufFB, NULL, bpf_noise_buf, 1, /* bfi - st->bfi can be 0 here - MODE2 stays in PLC when DTX appears after a loss */ + decoder_LPD( st, output, pcmbufFB, NULL, bpf_noise_buf, 1, /* bfi - st->bfi can be 0 here - MODE2 stays in PLC when DTX appears after a loss */ &bitsRead, NULL, pitch_buf, voice_factors, ptr_bwe_exc ); } @@ -479,4 +479,4 @@ void dec_acelp_tcx_frame( pop_wmops(); return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/dec_acelp_tcx_main_fx.c b/lib_dec/dec_acelp_tcx_main_fx.c index c4a0df619..7976b2763 100644 --- a/lib_dec/dec_acelp_tcx_main_fx.c +++ b/lib_dec/dec_acelp_tcx_main_fx.c @@ -12,10 +12,10 @@ #include "prot_fx2.h" #include "basop_util.h" #ifdef IVAS_FLOAT_FIXED -static -void decode_frame_type_fx(Decoder_State *st +static void decode_frame_type_fx( Decoder_State *st #ifdef IVAS_CODE_CNG - , STEREO_CNG_DEC_HANDLE hStereoCng + , + STEREO_CNG_DEC_HANDLE hStereoCng #endif ) { @@ -32,33 +32,32 @@ void decode_frame_type_fx(Decoder_State *st total_brate = st->total_brate; move16(); - Mpy_32_16_ss(st->total_brate, 5243, &L_tmp, &lsb); /* 5243 is 1/50 in Q18. (0+18-15=3) */ - num_bits = extract_l(L_shr(L_tmp, 3)); /* Q0 */ + Mpy_32_16_ss( st->total_brate, 5243, &L_tmp, &lsb ); /* 5243 is 1/50 in Q18. (0+18-15=3) */ + num_bits = extract_l( L_shr( L_tmp, 3 ) ); /* Q0 */ /* Get Frame Type (NULL,SID,ACTIVE) and Frame Mode (2kbps, 4kbps,...) */ - IF (EQ_16(st->mdct_sw, MODE1)) + IF( EQ_16( st->mdct_sw, MODE1 ) ) { st->m_frame_type = ACTIVE_FRAME; move16(); - FOR (n=0; ntotal_brate, FRAME_NO_DATA)) + IF( EQ_32( st->total_brate, FRAME_NO_DATA ) ) { st->bwidth = st->last_bwidth; move16(); @@ -67,10 +66,10 @@ void decode_frame_type_fx(Decoder_State *st } /* SID frame */ - ELSE IF ( EQ_32(st->total_brate, SID_2k40)) + ELSE IF( EQ_32( st->total_brate, SID_2k40 ) ) { - st->cng_type = get_next_indice(st, 1); - if( NE_16(st->cng_type, FD_CNG)) + st->cng_type = get_next_indice( st, 1 ); + if ( NE_16( st->cng_type, FD_CNG ) ) { st->BER_detect = 1; } @@ -78,13 +77,13 @@ void decode_frame_type_fx(Decoder_State *st move16(); frame_size_index = 1; move16(); - st->bwidth = get_next_indice(st, 2); + st->bwidth = get_next_indice( st, 2 ); move16(); - frame_len_indicator = get_next_indice(st, 1); - IF ( EQ_16(st->bwidth, NB)) + frame_len_indicator = get_next_indice( st, 1 ); + IF( EQ_16( st->bwidth, NB ) ) { - if( frame_len_indicator ) + if ( frame_len_indicator ) { st->BER_detect = 1; move16(); @@ -92,7 +91,7 @@ void decode_frame_type_fx(Decoder_State *st frame_len_indicator = 0; move16(); } - IF ( frame_len_indicator == 0 ) + IF( frame_len_indicator == 0 ) { st->L_frame = L_FRAME; st->total_brate = ACELP_9k60; @@ -100,7 +99,7 @@ void decode_frame_type_fx(Decoder_State *st ELSE { st->L_frame = L_FRAME16k; - IF ( st->last_total_brate== ACELP_16k40 || st->last_total_brate== ACELP_24k40) + IF( st->last_total_brate == ACELP_16k40 || st->last_total_brate == ACELP_24k40 ) { st->total_brate = st->last_total_brate; } @@ -110,11 +109,11 @@ void decode_frame_type_fx(Decoder_State *st } } - Mpy_32_16_ss(st->total_brate, 5243, &L_tmp, &lsb); /* 5243 is 1/50 in Q18. (0+18-15=3) */ - num_bits = extract_l(L_shr(L_tmp, 3)); /* Q0 */ - FOR (n=0; ntotal_brate, 5243, &L_tmp, &lsb ); /* 5243 is 1/50 in Q18. (0+18-15=3) */ + num_bits = extract_l( L_shr( L_tmp, 3 ) ); /* Q0 */ + FOR( n = 0; n < FRAME_SIZE_NB; n++ ) { - IF (EQ_16(FrameSizeConfig[n].frame_bits, num_bits)) + IF( EQ_16( FrameSizeConfig[n].frame_bits, num_bits ) ) { frame_size_index = n; move16(); @@ -130,33 +129,32 @@ void decode_frame_type_fx(Decoder_State *st st->m_frame_type = ACTIVE_FRAME; move16(); - FOR (n=0; nrf_flag == 0) + IF( st->rf_flag == 0 ) { /* Get bandwidth mode */ - st->bwidth = get_next_indice(st, FrameSizeConfig[frame_size_index].bandwidth_bits); - - st->bwidth = add(st->bwidth, FrameSizeConfig[frame_size_index].bandwidth_min); + st->bwidth = get_next_indice( st, FrameSizeConfig[frame_size_index].bandwidth_bits ); + st->bwidth = add( st->bwidth, FrameSizeConfig[frame_size_index].bandwidth_min ); } ELSE { st->bwidth += FrameSizeConfig[frame_size_index].bandwidth_min; } - IF (GT_16(st->bwidth, FB)) + IF( GT_16( st->bwidth, FB ) ) { st->bwidth = FB; move16(); @@ -165,7 +163,7 @@ void decode_frame_type_fx(Decoder_State *st } test(); - IF ( GT_16(st->bwidth, SWB)&<_32(st->total_brate,ACELP_16k40)) + IF( GT_16( st->bwidth, SWB ) && LT_32( st->total_brate, ACELP_16k40 ) ) { st->bwidth = SWB; move16(); @@ -174,17 +172,17 @@ void decode_frame_type_fx(Decoder_State *st } /* Get reserved bits */ - IF (FrameSizeConfig[frame_size_index].reserved_bits && st->rf_flag == 0) + IF( FrameSizeConfig[frame_size_index].reserved_bits && st->rf_flag == 0 ) { Word16 dummyBit; - dummyBit = (Word8)get_next_indice(st, 1); + dummyBit = (Word8) get_next_indice( st, 1 ); move16(); - if (dummyBit != 0) + if ( dummyBit != 0 ) { st->BER_detect = 1; move16(); } - assert( FrameSizeConfig[frame_size_index].reserved_bits == 1); + assert( FrameSizeConfig[frame_size_index].reserved_bits == 1 ); } } } @@ -192,37 +190,37 @@ void decode_frame_type_fx(Decoder_State *st st->rate_switching_init = 0; move16(); - if( st->last_codec_mode != MODE2 || !st->BER_detect ) + if ( st->last_codec_mode != MODE2 || !st->BER_detect ) { /* Mode or Rate Change */ test(); test(); test(); - IF ( (EQ_16(st->m_frame_type, ACTIVE_FRAME)||EQ_16(st->m_frame_type,SID_FRAME))&&(s_or(s_or(s_or(s_or((Word16)NE_32(st->total_brate,st->last_total_brate),(Word16)NE_16(st->bwidth,st->last_bwidth)),(Word16)EQ_16(st->last_codec_mode,MODE1)),(Word16)NE_16(st->rf_flag,st->rf_flag_last)),st->force_lpd_reset))) + IF( ( EQ_16( st->m_frame_type, ACTIVE_FRAME ) || EQ_16( st->m_frame_type, SID_FRAME ) ) && ( s_or( s_or( s_or( s_or( (Word16) NE_32( st->total_brate, st->last_total_brate ), (Word16) NE_16( st->bwidth, st->last_bwidth ) ), (Word16) EQ_16( st->last_codec_mode, MODE1 ) ), (Word16) NE_16( st->rf_flag, st->rf_flag_last ) ), st->force_lpd_reset ) ) ) { st->rate_switching_init = 1; move16(); /* Reconf Core */ #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - mode_switch_decoder_LPD_fx(st, st->bwidth, st->total_brate, st->last_total_brate, frame_size_index, 0, st->element_mode); + mode_switch_decoder_LPD_fx( st, st->bwidth, st->total_brate, st->last_total_brate, frame_size_index, 0, st->element_mode ); #else mode_switch_decoder_LPD_fx( st, st->bwidth, st->total_brate, frame_size_index ); #endif /* Reconf CLDFB */ - IF( NE_16 (i_mult(st->cldfbAna->no_channels,st->cldfbAna->no_col), st->L_frame) ) + IF( NE_16( i_mult( st->cldfbAna->no_channels, st->cldfbAna->no_col ), st->L_frame ) ) { - Word16 newCldfbBands = CLDFB_getNumChannels(L_mult0(st->L_frame,50)); + Word16 newCldfbBands = CLDFB_getNumChannels( L_mult0( st->L_frame, 50 ) ); resampleCldfb( st->cldfbAna, newCldfbBands, st->L_frame, 0 ); - IF ( LE_16(st->L_frame,L_FRAME16k) ) + IF( LE_16( st->L_frame, L_FRAME16k ) ) { resampleCldfb( st->cldfbBPF, newCldfbBands, st->L_frame, 0 ); } } - IF ( EQ_16(st->bwidth,NB)) + IF( EQ_16( st->bwidth, NB ) ) { - st->cldfbSyn->bandsToZero = sub (st->cldfbSyn->no_channels,10); + st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, 10 ); } ELSE { @@ -233,49 +231,49 @@ void decode_frame_type_fx(Decoder_State *st L_tmp = st->total_brate; move32(); test(); - if( EQ_16(st->rf_flag,1)&&EQ_32(st->total_brate,ACELP_13k20)) + if ( EQ_16( st->rf_flag, 1 ) && EQ_32( st->total_brate, ACELP_13k20 ) ) { L_tmp = ACELP_9k60; move32(); } - configureFdCngDec_fx( st->hFdCngDec, st->bwidth, L_tmp, st->L_frame, st->last_L_frame, st->element_mode); + configureFdCngDec_fx( st->hFdCngDec, st->bwidth, L_tmp, st->L_frame, st->last_L_frame, st->element_mode ); test(); test(); - IF ( (NE_16(st->last_L_frame,st->L_frame))&&(LE_16(st->L_frame, L_FRAME16k))&&(LE_16(st->last_L_frame, L_FRAME16k))) + IF( ( NE_16( st->last_L_frame, st->L_frame ) ) && ( LE_16( st->L_frame, L_FRAME16k ) ) && ( LE_16( st->last_L_frame, L_FRAME16k ) ) ) { - lerp( st->hFdCngDec->hFdCngCom->olapBufferSynth2, st->hFdCngDec->hFdCngCom->olapBufferSynth2, st->L_frame*2, st->last_L_frame*2 ); + lerp( st->hFdCngDec->hFdCngCom->olapBufferSynth2, st->hFdCngDec->hFdCngCom->olapBufferSynth2, st->L_frame * 2, st->last_L_frame * 2 ); test(); - IF ( EQ_16(st->m_frame_type, SID_FRAME)&&NE_16(st->hFdCngDec->hFdCngCom->frame_type_previous,ACTIVE_FRAME)) + IF( EQ_16( st->m_frame_type, SID_FRAME ) && NE_16( st->hFdCngDec->hFdCngCom->frame_type_previous, ACTIVE_FRAME ) ) { - lerp( st->hFdCngDec->hFdCngCom->olapBufferSynth, st->hFdCngDec->hFdCngCom->olapBufferSynth, st->L_frame*2, st->last_L_frame*2 ); + lerp( st->hFdCngDec->hFdCngCom->olapBufferSynth, st->hFdCngDec->hFdCngCom->olapBufferSynth, st->L_frame * 2, st->last_L_frame * 2 ); #ifdef IVAS_CODE_CNG - lerp(hStereoCng->olapBufferSynth22, hStereoCng->olapBufferSynth22, st->L_frame * 2, st->last_L_frame * 2); + lerp( hStereoCng->olapBufferSynth22, hStereoCng->olapBufferSynth22, st->L_frame * 2, st->last_L_frame * 2 ); #endif - IF( EQ_16(st->L_frame, L_FRAME)) + IF( EQ_16( st->L_frame, L_FRAME ) ) { - FOR( n=0; n < st->L_frame*2; n++ ) + FOR( n = 0; n < st->L_frame * 2; n++ ) { st->hFdCngDec->hFdCngCom->olapBufferSynth[n] = mult_r( st->hFdCngDec->hFdCngCom->olapBufferSynth[n], 20480 ); } } ELSE { - FOR( n=0; n < st->L_frame*2; n++ ) + FOR( n = 0; n < st->L_frame * 2; n++ ) { - st->hFdCngDec->hFdCngCom->olapBufferSynth[n] = mult_r( shl(st->hFdCngDec->hFdCngCom->olapBufferSynth[n],1), 26214 ); + st->hFdCngDec->hFdCngCom->olapBufferSynth[n] = mult_r( shl( st->hFdCngDec->hFdCngCom->olapBufferSynth[n], 1 ), 26214 ); } } } } - IF ( NE_16(st->bwidth,st->last_bwidth)) + IF( NE_16( st->bwidth, st->last_bwidth ) ) { st->hFdCngDec->hFdCngCom->msFrCnt_init_counter = 0; st->hFdCngDec->hFdCngCom->init_old = 32767; } /* Reconf BPF */ - st->p_bpf_noise_buf=NULL; - IF (st->tcxonly == 0) + st->p_bpf_noise_buf = NULL; + IF( st->tcxonly == 0 ) { st->p_bpf_noise_buf = st->bpf_noise_buf; } @@ -283,39 +281,39 @@ void decode_frame_type_fx(Decoder_State *st } st->total_brate = total_brate; - } Word16 dec_acelp_tcx_frame_fx( - Decoder_State *st, /* i/o: decoder state structure */ - Word16* concealWholeFrame, /* i/o: concealment flag */ - Word16* pcmBuf, /* o : synthesis */ - Word16* bpf_noise_buf, /* i/o: BPF noise buffer */ - Word16* pcmbufFB, /* o : synthesis @output_FS */ - Word32 bwe_exc_extended[], /* i/o: bandwidth extended excitation */ - Word16* voice_factors, /* o : voicing factors */ - Word16 pitch_buf[] /* o : floating pitch for each subframe */ -#ifdef IVAS_CODE_CNG - , STEREO_CNG_DEC_HANDLE hStereoCng /* i : stereo CNG handle */ + Decoder_State *st, /* i/o: decoder state structure */ + Word16 *concealWholeFrame, /* i/o: concealment flag */ + Word16 *pcmBuf, /* o : synthesis */ + Word16 *bpf_noise_buf, /* i/o: BPF noise buffer */ + Word16 *pcmbufFB, /* o : synthesis @output_FS */ + Word32 bwe_exc_extended[], /* i/o: bandwidth extended excitation */ + Word16 *voice_factors, /* o : voicing factors */ + Word16 pitch_buf[] /* o : floating pitch for each subframe */ +#ifdef IVAS_CODE_CNG + , + STEREO_CNG_DEC_HANDLE hStereoCng /* i : stereo CNG handle */ #endif - ) +) { - Word16 num_bits; - Word32 L_tmp; - UWord16 lsb; - Word16 bitsRead; - Word16 tmp; - Word16 i; - Word16 start_bit_pos; - Word16 param[DEC_NPRM_DIV*NB_DIV+NPRM_LPC_NEW]; - Word16 old_bwe_exc[(PIT16k_MAX + (L_FRAME16k + 1) + L_SUBFR16k) * 2]; /* excitation buffer */ - Word16 *ptr_bwe_exc; /* pointer to BWE excitation signal in the current frame */ + Word16 num_bits; + Word32 L_tmp; + UWord16 lsb; + Word16 bitsRead; + Word16 tmp; + Word16 i; + Word16 start_bit_pos; + Word16 param[DEC_NPRM_DIV * NB_DIV + NPRM_LPC_NEW]; + Word16 old_bwe_exc[( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2]; /* excitation buffer */ + Word16 *ptr_bwe_exc; /* pointer to BWE excitation signal in the current frame */ TD_BWE_DEC_HANDLE hBWE_TD; hBWE_TD = st->hBWE_TD; - Mpy_32_16_ss(st->total_brate, 5243, &L_tmp, &lsb); /* 5243 is 1/50 in Q18. (0+18-15=3) */ - num_bits = extract_l(L_shr(L_tmp, 3)); /* Q0 */ + Mpy_32_16_ss( st->total_brate, 5243, &L_tmp, &lsb ); /* 5243 is 1/50 in Q18. (0+18-15=3) */ + num_bits = extract_l( L_shr( L_tmp, 3 ) ); /* Q0 */ /* -------------------------------------------------------------- */ /* Set the bit-stream */ @@ -325,9 +323,9 @@ Word16 dec_acelp_tcx_frame_fx( start_bit_pos = st->next_bit_pos; move16(); - if( EQ_16(st->rf_flag,1)) + if ( EQ_16( st->rf_flag, 1 ) ) { - start_bit_pos = sub(start_bit_pos,2); + start_bit_pos = sub( start_bit_pos, 2 ); } /* -------------------------------------------------------------- */ /* IDENTIFY FRAME TYPE */ @@ -336,7 +334,7 @@ Word16 dec_acelp_tcx_frame_fx( st->m_old_frame_type = st->m_frame_type; move16(); - IF ( *concealWholeFrame == 0) + IF( *concealWholeFrame == 0 ) { Word16 m_frame_type = st->m_frame_type; @@ -345,9 +343,10 @@ Word16 dec_acelp_tcx_frame_fx( Word16 L_frame = st->L_frame; Word32 total_brate = st->last_total_brate; - decode_frame_type_fx( st -#ifdef IVAS_CODE_CNG - , hStereoCng + decode_frame_type_fx( st +#ifdef IVAS_CODE_CNG + , + hStereoCng #endif ); @@ -357,11 +356,11 @@ Word16 dec_acelp_tcx_frame_fx( test(); test(); test(); - IF( (EQ_16(st->last_codec_mode, MODE2))&&(st->BER_detect||(st->prev_bfi&&(EQ_16(st->m_frame_type,ZERO_FRAME))&&(EQ_16(st->m_old_frame_type,ACTIVE_FRAME))))) + IF( ( EQ_16( st->last_codec_mode, MODE2 ) ) && ( st->BER_detect || ( st->prev_bfi && ( EQ_16( st->m_frame_type, ZERO_FRAME ) ) && ( EQ_16( st->m_old_frame_type, ACTIVE_FRAME ) ) ) ) ) { /* Copy back parameters from previous frame, because there is a high risk they are corrupt * DO concealment with configuration used in previous frame */ - st->m_frame_type = (uint8_t)m_frame_type; + st->m_frame_type = (uint8_t) m_frame_type; move16(); st->bwidth = bwidth; move16(); @@ -369,7 +368,7 @@ Word16 dec_acelp_tcx_frame_fx( move16(); st->L_frame = L_frame; move16(); - if( st->ini_frame != 0 ) + if ( st->ini_frame != 0 ) { st->total_brate = total_brate; move32(); @@ -384,7 +383,7 @@ Word16 dec_acelp_tcx_frame_fx( test(); test(); - IF( (NE_16(st->bwidth, st->last_bwidth))||(NE_16(st->rf_flag,st->rf_flag_last))||(NE_32(st->total_brate,st->last_total_brate))) + IF( ( NE_16( st->bwidth, st->last_bwidth ) ) || ( NE_16( st->rf_flag, st->rf_flag_last ) ) || ( NE_32( st->total_brate, st->last_total_brate ) ) ) { st->force_lpd_reset = 1; move16(); @@ -394,9 +393,9 @@ Word16 dec_acelp_tcx_frame_fx( move32(); st->bfi = 1; move16(); - IF(st->ini_frame == 0 && st->hTcxCfg != NULL ) + IF( st->ini_frame == 0 && st->hTcxCfg != NULL ) { - st->hTcxCfg->tcx_coded_lines = getNumTcxCodedLines(SWB); + st->hTcxCfg->tcx_coded_lines = getNumTcxCodedLines( SWB ); } } ELSE @@ -411,38 +410,38 @@ Word16 dec_acelp_tcx_frame_fx( IF( *concealWholeFrame != 0 ) { /* add two zero bytes for arithmetic coder flush */ - FOR( i=0; i<8*2; i++ ) + FOR( i = 0; i < 8 * 2; i++ ) { st->bit_stream[i] = 0; } } - IF ( s_and((Word16)NE_16(st->m_frame_type,SID_FRAME),(Word16)NE_16(st->m_frame_type,ZERO_FRAME))) /* test */ + IF( s_and( (Word16) NE_16( st->m_frame_type, SID_FRAME ), (Word16) NE_16( st->m_frame_type, ZERO_FRAME ) ) ) /* test */ { /* -------------------------------------------------------------- */ /* DECODE CORE */ /* -------------------------------------------------------------- */ - tmp = sub(num_bits, sub(st->next_bit_pos, start_bit_pos)); + tmp = sub( num_bits, sub( st->next_bit_pos, start_bit_pos ) ); bitsRead = 0; move16(); - set16_fx( old_bwe_exc + PIT16k_MAX * 2, 0, ((L_FRAME16k + 1) + L_SUBFR16k) * 2 ); + set16_fx( old_bwe_exc + PIT16k_MAX * 2, 0, ( ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2 ); ptr_bwe_exc = old_bwe_exc + PIT16k_MAX * 2; - Copy(hBWE_TD->old_bwe_exc_fx, old_bwe_exc, PIT16k_MAX * 2 ); + Copy( hBWE_TD->old_bwe_exc_fx, old_bwe_exc, PIT16k_MAX * 2 ); - IF ( EQ_16(st->m_decodeMode, DEC_NO_FRAM_LOSS)) + IF( EQ_16( st->m_decodeMode, DEC_NO_FRAM_LOSS ) ) { - decoder_LPD_fx(pcmBuf, pcmbufFB, &tmp, st, bpf_noise_buf, 0, &bitsRead, param, pitch_buf, voice_factors, ptr_bwe_exc ); + decoder_LPD_fx( pcmBuf, pcmbufFB, &tmp, st, bpf_noise_buf, 0, &bitsRead, param, pitch_buf, voice_factors, ptr_bwe_exc ); test(); test(); test(); test(); test(); - IF( st->rate_switching_init == 0 && EQ_16((st->last_codec_mode), MODE2)&&!(st->use_partial_copy&&GE_16(st->rf_frame_type,RF_TCXFD)&&LE_16(st->rf_frame_type,RF_TCXTD2))&&EQ_16(st->bfi,1)) + IF( st->rate_switching_init == 0 && EQ_16( ( st->last_codec_mode ), MODE2 ) && !( st->use_partial_copy && GE_16( st->rf_frame_type, RF_TCXFD ) && LE_16( st->rf_frame_type, RF_TCXTD2 ) ) && EQ_16( st->bfi, 1 ) ) { *concealWholeFrame = 1; move16(); @@ -451,9 +450,8 @@ Word16 dec_acelp_tcx_frame_fx( st->BER_detect = 0; move16(); } - } - ELSE IF (EQ_16(st->m_decodeMode, DEC_CONCEALMENT_EXT)) + ELSE IF( EQ_16( st->m_decodeMode, DEC_CONCEALMENT_EXT ) ) { /* Decode the LPD data */ decoder_LPD_fx( pcmBuf, pcmbufFB, NULL, st, bpf_noise_buf, 1, &bitsRead, NULL, pitch_buf, voice_factors, ptr_bwe_exc ); @@ -463,26 +461,26 @@ Word16 dec_acelp_tcx_frame_fx( test(); test(); test(); - if (st->hBWE_TD != NULL) + if ( st->hBWE_TD != NULL ) { - IF((st->bfi == 0 && (EQ_16(st->prev_bfi, 1) || EQ_16(st->prev_use_partial_copy, 1))) || ((EQ_16(st->last_vbr_hw_BWE_disable_dec, 1)) && (st->vbr_hw_BWE_disable_dec == 0))) + IF( ( st->bfi == 0 && ( EQ_16( st->prev_bfi, 1 ) || EQ_16( st->prev_use_partial_copy, 1 ) ) ) || ( ( EQ_16( st->last_vbr_hw_BWE_disable_dec, 1 ) ) && ( st->vbr_hw_BWE_disable_dec == 0 ) ) ) { hBWE_TD->bwe_non_lin_prev_scale_fx = 0; - set16_fx(hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET); + set16_fx( hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); } test(); test(); - IF(st->core == ACELP_CORE && st->igf != 0 && st->con_tcx == 0) + IF( st->core == ACELP_CORE && st->igf != 0 && st->con_tcx == 0 ) { - non_linearity_fx(ptr_bwe_exc, bwe_exc_extended, L_FRAME32k, &hBWE_TD->bwe_non_lin_prev_scale_fx, st->Q_exc, st->coder_type, voice_factors, st->L_frame); + non_linearity_fx( ptr_bwe_exc, bwe_exc_extended, L_FRAME32k, &hBWE_TD->bwe_non_lin_prev_scale_fx, st->Q_exc, st->coder_type, voice_factors, st->L_frame ); /* update the old BWE exe memory */ - Copy(&old_bwe_exc[L_FRAME32k], hBWE_TD->old_bwe_exc_fx, PIT16k_MAX * 2); + Copy( &old_bwe_exc[L_FRAME32k], hBWE_TD->old_bwe_exc_fx, PIT16k_MAX * 2 ); } ELSE { - set16_fx(hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET); - set16_fx(hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2); + set16_fx( hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); + set16_fx( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); hBWE_TD->bwe_non_lin_prev_scale_fx = 0; move32(); } @@ -491,32 +489,33 @@ Word16 dec_acelp_tcx_frame_fx( /* for ACELP mode, skip core data to read TD-BWE side info */ test(); test(); - IF( (!st->bfi) && EQ_16(st->core,ACELP_CORE)&&st->total_brate>0) + IF( ( !st->bfi ) && EQ_16( st->core, ACELP_CORE ) && st->total_brate > 0 ) { /* target bs-position "-3": -2 as earlier "start_bit_pos -= 2;" are included in st->rf_target_bits -1 as flag-bit not considered in rf_target_bits */ - IF (EQ_16(st->rf_flag, 1)) + IF( EQ_16( st->rf_flag, 1 ) ) { - get_next_indice_tmp_fx(st, start_bit_pos + num_bits - st->rf_target_bits - 3 - get_tbe_bits_fx(st->total_brate, st->bwidth, st->rf_flag) - st->next_bit_pos); + get_next_indice_tmp_fx( st, start_bit_pos + num_bits - st->rf_target_bits - 3 - get_tbe_bits_fx( st->total_brate, st->bwidth, st->rf_flag ) - st->next_bit_pos ); } ELSE { - get_next_indice_tmp_fx(st, start_bit_pos + num_bits - st->rf_target_bits - get_tbe_bits_fx(st->total_brate, st->bwidth, st->rf_flag) - st->next_bit_pos); + get_next_indice_tmp_fx( st, start_bit_pos + num_bits - st->rf_target_bits - get_tbe_bits_fx( st->total_brate, st->bwidth, st->rf_flag ) - st->next_bit_pos ); } - tbe_read_bitstream_fx(st); + tbe_read_bitstream_fx( st ); } /* updates */ - st->last_voice_factor_fx = voice_factors[st->nb_subfr-1];; + st->last_voice_factor_fx = voice_factors[st->nb_subfr - 1]; + ; move16(); st->last_coder_type = st->coder_type; } ELSE { - IF ( EQ_16(st->m_frame_type,SID_FRAME)) + IF( EQ_16( st->m_frame_type, SID_FRAME ) ) { - FdCng_decodeSID_fx(st->hFdCngDec->hFdCngCom, st); + FdCng_decodeSID_fx( st->hFdCngDec->hFdCngCom, st ); } /* updates */ diff --git a/lib_dec/dec_amr_wb_fx.c b/lib_dec/dec_amr_wb_fx.c index dfa79cae1..6c0a668d2 100644 --- a/lib_dec/dec_amr_wb_fx.c +++ b/lib_dec/dec_amr_wb_fx.c @@ -3,11 +3,11 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ #ifdef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* @@ -18,25 +18,25 @@ void decod_amr_wb_fx( Decoder_State *st_fx, /* i/o: decoder static memory */ - const Word16 *Aq_fx, /* i : LP filter coefficients */ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ - Word16 *exc_fx, /* i/o: adapt. excitation exc */ - Word16 *exc2_fx, /* i/o: adapt. excitation/total exc */ - Word16 hf_gain_fx[NB_SUBFR], /* o : decoded HF gain */ - Word16 *voice_factors_fx, /* o : voicing factors */ - Word16 *gain_buf /* o : floating pitch gain for each subframe Q14 */ + const Word16 *Aq_fx, /* i : LP filter coefficients */ + Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ + Word16 *exc_fx, /* i/o: adapt. excitation exc */ + Word16 *exc2_fx, /* i/o: adapt. excitation/total exc */ + Word16 hf_gain_fx[NB_SUBFR], /* o : decoded HF gain */ + Word16 *voice_factors_fx, /* o : voicing factors */ + Word16 *gain_buf /* o : floating pitch gain for each subframe Q14 */ ) { - Word16 T0, T0_frac, T0_min, T0_max; /* integer pitch variables */ - Word16 gain_pit_fx, gain_code16; /* pitch gain */ - Word32 L_gain_code_fx; /* gain/normalized gain of the algebraic excitation */ - Word32 L_norm_gain_code_fx; /* normalized gain of the algebraic excitation */ - Word16 gain_inov_fx; /* Innovation gain */ - Word16 voice_fac_fx; /* voicing factor */ - Word16 code_fx[L_SUBFR]; /* algebraic codevector */ - const Word16 *p_Aq_fx; /* Pointer to frame LP coefficient */ - Word16 *pt_pitch_fx; /* pointer to floating pitch */ - Word16 i_subfr; /* tmp variables */ + Word16 T0, T0_frac, T0_min, T0_max; /* integer pitch variables */ + Word16 gain_pit_fx, gain_code16; /* pitch gain */ + Word32 L_gain_code_fx; /* gain/normalized gain of the algebraic excitation */ + Word32 L_norm_gain_code_fx; /* normalized gain of the algebraic excitation */ + Word16 gain_inov_fx; /* Innovation gain */ + Word16 voice_fac_fx; /* voicing factor */ + Word16 code_fx[L_SUBFR]; /* algebraic codevector */ + const Word16 *p_Aq_fx; /* Pointer to frame LP coefficient */ + Word16 *pt_pitch_fx; /* pointer to floating pitch */ + Word16 i_subfr; /* tmp variables */ Word16 pitch_limit_flag; Word32 L_Voice_fac_ave, L_tmp; Word16 lp_flag; @@ -49,18 +49,18 @@ void decod_amr_wb_fx( * Initializations *------------------------------------------------------------------*/ - p_Aq_fx = Aq_fx; /* pointer to interpolated LPC parameters */ - pt_pitch_fx = pitch_buf_fx; /* pointer to the pitch buffer */ - L_Voice_fac_ave = L_deposit_l(0); + p_Aq_fx = Aq_fx; /* pointer to interpolated LPC parameters */ + pt_pitch_fx = pitch_buf_fx; /* pointer to the pitch buffer */ + L_Voice_fac_ave = L_deposit_l( 0 ); pitch_limit_flag = 0; - move16(); /* always restrained pitch Q range in IO mode */ + move16(); /* always restrained pitch Q range in IO mode */ lp_flag = NORMAL_OPERATION; - move16(); /* always restrained pitch Q range in IO mode */ - IF (LT_32(st_fx->core_brate, ACELP_11k60) ) + move16(); /* always restrained pitch Q range in IO mode */ + IF( LT_32( st_fx->core_brate, ACELP_11k60 ) ) { lp_flag = LOW_PASS; - move16(); /* always restrained pitch Q range in IO mode */ + move16(); /* always restrained pitch Q range in IO mode */ } /*------------------------------------------------------------------* * ACELP subframe loop @@ -74,26 +74,27 @@ void decod_amr_wb_fx( *pt_pitch_fx = pit_decode_fx( st_fx, st_fx->core_brate, 1, L_FRAME, i_subfr, -1, &pitch_limit_flag, &T0, &T0_frac, &T0_min, &T0_max, L_SUBFR #ifdef ADD_LRTD - , 0 , NULL -#endif + , + 0, NULL +#endif ); /*--------------------------------------------------------------* * Find the adaptive codebook vector *--------------------------------------------------------------*/ - pred_lt4(&exc_fx[i_subfr],&exc_fx[i_subfr], T0, T0_frac, L_SUBFR+1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP); + pred_lt4( &exc_fx[i_subfr], &exc_fx[i_subfr], T0, T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); /*--------------------------------------------------------------* * LP filtering of the adaptive excitation *--------------------------------------------------------------*/ - lp_filt_exc_dec_fx(st_fx, MODE1, i_subfr, L_SUBFR, L_FRAME, lp_flag, exc_fx); + lp_filt_exc_dec_fx( st_fx, MODE1, i_subfr, L_SUBFR, L_FRAME, lp_flag, exc_fx ); /*--------------------------------------------------------------* * Innovation decoding *--------------------------------------------------------------*/ - inov_decode_fx( st_fx, st_fx->core_brate, 1, L_FRAME, 0, i_subfr, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_SUBFR); + inov_decode_fx( st_fx, st_fx->core_brate, 1, L_FRAME, 0, i_subfr, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_SUBFR ); /*--------------------------------------------------------------* * Gain decoding @@ -105,51 +106,51 @@ void decod_amr_wb_fx( /* update LP filtered gains for the case of frame erasures */ lp_gain_updt_fx( i_subfr, gain_pit_fx, L_norm_gain_code_fx, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_FRAME ); - st_fx->tilt_code_fx = est_tilt_fx( exc_fx+i_subfr, gain_pit_fx, code_fx, L_gain_code_fx, &voice_fac_fx, st_fx->Q_exc ); + st_fx->tilt_code_fx = est_tilt_fx( exc_fx + i_subfr, gain_pit_fx, code_fx, L_gain_code_fx, &voice_fac_fx, st_fx->Q_exc ); - Rescale_exc(hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr], NULL, st_fx->hGSCDec->last_exc_dct_in_fx, L_SUBFR, 0, - L_gain_code_fx, &(st_fx->Q_exc), st_fx->Q_subfr, exc2_fx, i_subfr, -1 ); + Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr], NULL, st_fx->hGSCDec->last_exc_dct_in_fx, L_SUBFR, 0, + L_gain_code_fx, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr, -1 ); - gain_code16 = round_fx(L_shl(L_gain_code_fx,st_fx->Q_exc)); /*Q_exc*/ + gain_code16 = round_fx( L_shl( L_gain_code_fx, st_fx->Q_exc ) ); /*Q_exc*/ /*----------------------------------------------------------------------* * Find the total excitation *----------------------------------------------------------------------*/ - Acelp_dec_total_exc( exc_fx, exc2_fx, gain_code16, gain_pit_fx, i_subfr, code_fx, L_SUBFR); + Acelp_dec_total_exc( exc_fx, exc2_fx, gain_code16, gain_pit_fx, i_subfr, code_fx, L_SUBFR ); /*----------------------------------------------------------------* * Excitation enhancements *----------------------------------------------------------------*/ enhancer_fx( st_fx->core_brate, 1, -1, i_subfr, L_FRAME, voice_fac_fx, st_fx->stab_fac_fx, - L_norm_gain_code_fx, gain_inov_fx, &st_fx->gc_threshold_fx, code_fx, exc2_fx, gain_pit_fx, &(st_fx->dm_fx),st_fx->Q_exc ); + L_norm_gain_code_fx, gain_inov_fx, &st_fx->gc_threshold_fx, code_fx, exc2_fx, gain_pit_fx, &( st_fx->dm_fx ), st_fx->Q_exc ); /*-----------------------------------------------------------------* * HF gain modification factors at 23.85 kbps *-----------------------------------------------------------------*/ - IF ( EQ_32(st_fx->core_brate,ACELP_23k85)) + IF( EQ_32( st_fx->core_brate, ACELP_23k85 ) ) { - hf_gain_fx[shr(i_subfr,6)] = (Word16)get_next_indice(st_fx, 4); + hf_gain_fx[shr( i_subfr, 6 )] = (Word16) get_next_indice( st_fx, 4 ); } /*voice_fac = VF_0th_PARAM + VF_1st_PARAM * voice_fac + VF_2nd_PARAM * voice_fac * voice_fac;*/ - L_tmp = L_mult(VF_2nd_PARAM_FX, mult_r(voice_fac_fx, voice_fac_fx)); - L_tmp = L_mac(L_tmp, VF_1st_PARAM_FX, voice_fac_fx); - voice_fac_fx = mac_r(L_tmp, VF_0th_PARAM_FX, 32767); + L_tmp = L_mult( VF_2nd_PARAM_FX, mult_r( voice_fac_fx, voice_fac_fx ) ); + L_tmp = L_mac( L_tmp, VF_1st_PARAM_FX, voice_fac_fx ); + voice_fac_fx = mac_r( L_tmp, VF_0th_PARAM_FX, 32767 ); /*voice_factors[i_subfr/L_SUBFR] = min( max(0.0f, voice_fac), 1.0f);*/ - voice_factors_fx[i_subfr/L_SUBFR] = s_min(s_max(0, voice_fac_fx),32767); + voice_factors_fx[i_subfr / L_SUBFR] = s_min( s_max( 0, voice_fac_fx ), 32767 ); move16(); - p_Aq_fx += (M+1); + p_Aq_fx += ( M + 1 ); pt_pitch_fx++; - L_Voice_fac_ave = L_mac(L_Voice_fac_ave, 8192, voice_fac_fx); - gain_buf[i_subfr/L_SUBFR] = gain_pit_fx; + L_Voice_fac_ave = L_mac( L_Voice_fac_ave, 8192, voice_fac_fx ); + gain_buf[i_subfr / L_SUBFR] = gain_pit_fx; } - hAmrwb_IO->lt_voice_fac_fx = round_fx(L_Voice_fac_ave); + hAmrwb_IO->lt_voice_fac_fx = round_fx( L_Voice_fac_ave ); return; } diff --git a/lib_dec/dec_gen_voic_fx.c b/lib_dec/dec_gen_voic_fx.c index 8e016830a..8f75dea7f 100644 --- a/lib_dec/dec_gen_voic_fx.c +++ b/lib_dec/dec_gen_voic_fx.c @@ -3,11 +3,11 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ #include "stl.h" #include "basop_util.h" #ifdef IVAS_FLOAT_FIXED @@ -39,43 +39,42 @@ /*======================================================================*/ ivas_error decod_gen_voic_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 sharpFlag_fx, /* i : formant sharpening flag */ - const Word16 *Aq_fx, /* i : LP filter coefficient */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - const Word16 do_WI_fx, /* i : do interpolation after a FER */ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ - Word16 *voice_factors_fx, /* o : voicing factors */ - Word16 *exc_fx, /* i/o: adapt. excitation exc */ - Word16 *exc2_fx, /* i/o: adapt. excitation/total exc */ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ - Word16 *unbits, /* number of unused bits */ - Word16 *gain_buf -) + Decoder_State *st_fx, /* i/o: decoder static memory */ + const Word16 L_frame, /* i : length of the frame */ + const Word16 sharpFlag_fx, /* i : formant sharpening flag */ + const Word16 *Aq_fx, /* i : LP filter coefficient */ + const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ + const Word16 do_WI_fx, /* i : do interpolation after a FER */ + Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ + Word16 *voice_factors_fx, /* o : voicing factors */ + Word16 *exc_fx, /* i/o: adapt. excitation exc */ + Word16 *exc2_fx, /* i/o: adapt. excitation/total exc */ + Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ + Word16 *unbits, /* number of unused bits */ + Word16 *gain_buf ) { - Word16 T0_fx, T0_frac_fx, T0_min_fx, T0_max_fx;/* integer pitch variables */ - Word16 gain_pit_fx = 0; /* pitch gain Q14 */ - Word32 gain_code_fx=0; /* gain/normalized gain of the algebraic excitation Q16 */ - Word32 norm_gain_code_fx=0; /* normalized gain of the algebraic excitation Q16 */ - Word16 gain_inov_fx=0; /* Innovation gain Q12 */ - Word32 gc_mem[NB_SUBFR-1]; /* gain_code from previous subframes */ - Word16 gp_mem[NB_SUBFR-1]; /* gain_pitch from previous subframes */ - Word16 voice_fac_fx; /* voicing factor Q15 */ - Word16 code_fx[L_SUBFR]; /* algebraic codevector Q12 */ + Word16 T0_fx, T0_frac_fx, T0_min_fx, T0_max_fx; /* integer pitch variables */ + Word16 gain_pit_fx = 0; /* pitch gain Q14 */ + Word32 gain_code_fx = 0; /* gain/normalized gain of the algebraic excitation Q16 */ + Word32 norm_gain_code_fx = 0; /* normalized gain of the algebraic excitation Q16 */ + Word16 gain_inov_fx = 0; /* Innovation gain Q12 */ + Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes */ + Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes */ + Word16 voice_fac_fx; /* voicing factor Q15 */ + Word16 code_fx[L_SUBFR]; /* algebraic codevector Q12 */ - const Word16 *p_Aq_fx; /* Pointer to frame LP coefficient Q12 */ - Word16 *pt_pitch_fx; /* pointer to floating pitch Q6 */ - Word16 i_subfr_fx, i; /* tmp variables */ + const Word16 *p_Aq_fx; /* Pointer to frame LP coefficient Q12 */ + Word16 *pt_pitch_fx; /* pointer to floating pitch Q6 */ + Word16 i_subfr_fx, i; /* tmp variables */ Word16 error_fx = 0; - Word16 gain_preQ_fx = 0; /* Gain of prequantizer excitation */ - Word16 code_preQ_fx[L_SUBFR]; /* Prequantizer excitation */ + Word16 gain_preQ_fx = 0; /* Gain of prequantizer excitation */ + Word16 code_preQ_fx[L_SUBFR]; /* Prequantizer excitation */ Word32 norm_gain_preQ_fx; Word16 pitch_limit_flag_fx; - Word16 tmp1_fx,gain_code16; + Word16 tmp1_fx, gain_code16; Word32 L_tmp_GC; Word32 L_tmp; @@ -96,7 +95,7 @@ ivas_error decod_gen_voic_fx( Word16 sp_enratio, Qsp_enratio; Word16 enratio, Qenratio; DTFS_STRUCTURE *PREVP, *CURRP; - Word16 S_fx[PIT_MAX*4+1], C_fx[PIT_MAX*4+1]; + Word16 S_fx[PIT_MAX * 4 + 1], C_fx[PIT_MAX * 4 + 1]; Word16 dummy2[2]; Word16 out_fx[L_FRAME16k]; @@ -126,9 +125,9 @@ ivas_error decod_gen_voic_fx( move16(); test(); test(); - IF( (GE_32(st_fx->core_brate, MIN_BRATE_AVQ_EXC)&&LE_32(st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD))&&EQ_16(st_fx->coder_type,GENERIC)) + IF( ( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && LE_32( st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD ) ) && EQ_16( st_fx->coder_type, GENERIC ) ) { - harm_flag_acelp = (Word16)get_next_indice( st_fx, 1 ); + harm_flag_acelp = (Word16) get_next_indice( st_fx, 1 ); } /*------------------------------------------------------------------* @@ -136,9 +135,9 @@ ivas_error decod_gen_voic_fx( *------------------------------------------------------------------*/ p_Aq_fx = Aq_fx; - move16(); /* pointer to interpolated LPC parameters */ + move16(); /* pointer to interpolated LPC parameters */ pt_pitch_fx = pitch_buf_fx; - move16(); /* pointer to the pitch buffer */ + move16(); /* pointer to the pitch buffer */ norm_gain_preQ_fx = 0; move16(); gain_preQ_fx = 0; @@ -159,42 +158,42 @@ ivas_error decod_gen_voic_fx( * Find the adaptive codebook vector *--------------------------------------------------------------*/ - pred_lt4( &exc_fx[i_subfr_fx], &exc_fx[i_subfr_fx], T0_fx, T0_frac_fx, L_SUBFR+1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + pred_lt4( &exc_fx[i_subfr_fx], &exc_fx[i_subfr_fx], T0_fx, T0_frac_fx, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); - tbe_celp_exc( L_frame,i_subfr_fx,T0_fx, T0_frac_fx, &error_fx, bwe_exc_fx ); + tbe_celp_exc( L_frame, i_subfr_fx, T0_fx, T0_frac_fx, &error_fx, bwe_exc_fx ); /*--------------------------------------------------------------* * LP filtering of the adaptive excitation *--------------------------------------------------------------*/ - lp_filt_exc_dec_fx(st_fx, MODE1, i_subfr_fx, L_SUBFR, L_frame, st_fx->acelp_cfg.ltf_mode, exc_fx); + lp_filt_exc_dec_fx( st_fx, MODE1, i_subfr_fx, L_SUBFR, L_frame, st_fx->acelp_cfg.ltf_mode, exc_fx ); /*-----------------------------------------------------------------* * Transform-domain contribution decoding (active frames) *-----------------------------------------------------------------*/ test(); - IF( GE_32(st_fx->core_brate, MIN_BRATE_AVQ_EXC)&&NE_16(st_fx->coder_type,INACTIVE)) + IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && NE_16( st_fx->coder_type, INACTIVE ) ) { gain_code_fx = 0; move16(); - transf_cdbk_dec_fx( st_fx, harm_flag_acelp, i_subfr_fx, Es_pred_fx, gain_code_fx, &gain_preQ_fx, &norm_gain_preQ_fx, code_preQ_fx, unbits ); + transf_cdbk_dec_fx( st_fx, harm_flag_acelp, i_subfr_fx, Es_pred_fx, gain_code_fx, &gain_preQ_fx, &norm_gain_preQ_fx, code_preQ_fx, unbits ); } /*--------------------------------------------------------------* * Innovation decoding *--------------------------------------------------------------*/ - inov_decode_fx( st_fx, st_fx->core_brate, 0, L_frame, sharpFlag_fx, i_subfr_fx, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_SUBFR); + inov_decode_fx( st_fx, st_fx->core_brate, 0, L_frame, sharpFlag_fx, i_subfr_fx, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_SUBFR ); /*--------------------------------------------------------------* * Gain decoding * Estimate spectrum tilt and voicing *--------------------------------------------------------------*/ - IF( LE_32(st_fx->core_brate,ACELP_8k00)) + IF( LE_32( st_fx->core_brate, ACELP_8k00 ) ) { - gain_dec_lbr_fx( st_fx, st_fx->coder_type, i_subfr_fx, code_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, gc_mem, gp_mem, L_SUBFR); + gain_dec_lbr_fx( st_fx, st_fx->coder_type, i_subfr_fx, code_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, gc_mem, gp_mem, L_SUBFR ); } - ELSE IF( GT_32(st_fx->core_brate,ACELP_32k)) + ELSE IF( GT_32( st_fx->core_brate, ACELP_32k ) ) { gain_dec_SQ_fx( st_fx, i_subfr_fx, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx ); } @@ -202,82 +201,81 @@ ivas_error decod_gen_voic_fx( { gain_dec_mless_fx( st_fx, L_frame, st_fx->coder_type, i_subfr_fx, -1, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx ); } - st_fx->tilt_code_fx = est_tilt_fx( exc_fx+i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, st_fx->Q_exc ); + st_fx->tilt_code_fx = est_tilt_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, st_fx->Q_exc ); /*-----------------------------------------------------------------* * Transform domain contribution decoding *-----------------------------------------------------------------*/ test(); - IF( GE_32( st_fx->core_brate, MAX_GSC_INACTIVE_BRATE) && EQ_16(st_fx->coder_type,INACTIVE)) + IF( GE_32( st_fx->core_brate, MAX_GSC_INACTIVE_BRATE ) && EQ_16( st_fx->coder_type, INACTIVE ) ) { transf_cdbk_dec_fx( st_fx, harm_flag_acelp, i_subfr_fx, Es_pred_fx, gain_code_fx, &gain_preQ_fx, &norm_gain_preQ_fx, code_preQ_fx, unbits ); } /* update LP filtered gains for the case of frame erasures */ - lp_gain_updt_fx( i_subfr_fx, gain_pit_fx, L_add(norm_gain_code_fx,norm_gain_preQ_fx), &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_frame ); + lp_gain_updt_fx( i_subfr_fx, gain_pit_fx, L_add( norm_gain_code_fx, norm_gain_preQ_fx ), &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_frame ); /*----------------------------------------------------------------------* - * Find the total excitation - *----------------------------------------------------------------------*/ + * Find the total excitation + *----------------------------------------------------------------------*/ - IF ( EQ_16(L_frame,L_FRAME)) /* Rescaling for 12.8k core */ + IF( EQ_16( L_frame, L_FRAME ) ) /* Rescaling for 12.8k core */ { - Rescale_exc(hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[i_subfr_fx * HIBND_ACB_L_FAC], hGSCDec->last_exc_dct_in_fx, - L_SUBFR, L_SUBFR * HIBND_ACB_L_FAC, gain_code_fx, &(st_fx->Q_exc), st_fx->Q_subfr, exc2_fx, i_subfr_fx, st_fx->coder_type ); - + Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[i_subfr_fx * HIBND_ACB_L_FAC], hGSCDec->last_exc_dct_in_fx, + L_SUBFR, L_SUBFR * HIBND_ACB_L_FAC, gain_code_fx, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr_fx, st_fx->coder_type ); } - ELSE /* Rescaling for 16k core */ + ELSE /* Rescaling for 16k core */ { - L_tmp_GC = L_max(gain_code_fx, L_shl(gain_preQ_fx,16)); /* Chose the maximum of gain_code or the prequantizer excitation x4 to keep some room*/ - Rescale_exc(hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[i_subfr_fx * 2], hGSCDec->last_exc_dct_in_fx, - L_SUBFR, L_SUBFR * 2, L_tmp_GC, &(st_fx->Q_exc), st_fx->Q_subfr, exc2_fx, i_subfr_fx, st_fx->coder_type ); + L_tmp_GC = L_max( gain_code_fx, L_shl( gain_preQ_fx, 16 ) ); /* Chose the maximum of gain_code or the prequantizer excitation x4 to keep some room*/ + Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[i_subfr_fx * 2], hGSCDec->last_exc_dct_in_fx, + L_SUBFR, L_SUBFR * 2, L_tmp_GC, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr_fx, st_fx->coder_type ); } - gain_code16 = round_fx(L_shl(gain_code_fx,st_fx->Q_exc)); /*Q_exc*/ + gain_code16 = round_fx( L_shl( gain_code_fx, st_fx->Q_exc ) ); /*Q_exc*/ /*-----------------------------------------------------------------* * Add the ACELP pre-quantizer contribution *-----------------------------------------------------------------*/ - IF (gain_preQ_fx != 0) + IF( gain_preQ_fx != 0 ) { - tmp1_fx = add(15-Q_AVQ_OUT_DEC-2,st_fx->Q_exc); + tmp1_fx = add( 15 - Q_AVQ_OUT_DEC - 2, st_fx->Q_exc ); FOR( i = 0; i < L_SUBFR; i++ ) { Word32 Ltmp1; /* Contribution from AVQ layer */ - Ltmp1 = L_mult(gain_preQ_fx, code_preQ_fx[i]); /* Q2 + Q6 -> Q9*/ - Ltmp1 = L_shl_sat(Ltmp1,tmp1_fx); /* Q16 + Q_exc */ + Ltmp1 = L_mult( gain_preQ_fx, code_preQ_fx[i] ); /* Q2 + Q6 -> Q9*/ + Ltmp1 = L_shl_sat( Ltmp1, tmp1_fx ); /* Q16 + Q_exc */ /* Compute exc2 */ #ifdef BASOP_NOGLOB L_tmp = L_shl_sat( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 ); - exc2_fx[i+i_subfr_fx] = round_fx_sat(L_add_sat(L_tmp, Ltmp1)); + exc2_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( L_tmp, Ltmp1 ) ); #else - L_tmp = L_shl(L_mult(gain_pit_fx,exc_fx[i+i_subfr_fx]),1); - exc2_fx[i+i_subfr_fx] = round_fx(L_add(L_tmp, Ltmp1)); + L_tmp = L_shl( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 ); + exc2_fx[i + i_subfr_fx] = round_fx( L_add( L_tmp, Ltmp1 ) ); #endif /* code in Q9, gain_pit in Q14 */ - L_tmp = L_mult(gain_code16, code_fx[i]); + L_tmp = L_mult( gain_code16, code_fx[i] ); #ifdef BASOP_NOGLOB L_tmp = L_shl_sat( L_tmp, 5 ); - L_tmp = L_mac_sat(L_tmp, exc_fx[i + i_subfr_fx], gain_pit_fx); - L_tmp = L_shl_sat(L_tmp, 1); /* saturation can occur here */ + L_tmp = L_mac_sat( L_tmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); + L_tmp = L_shl_sat( L_tmp, 1 ); /* saturation can occur here */ - exc_fx[i+i_subfr_fx] = round_fx_sat(L_add_sat(L_tmp, Ltmp1)); + exc_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( L_tmp, Ltmp1 ) ); #else - L_tmp = L_shl(L_tmp, 5); - L_tmp = L_mac(L_tmp, exc_fx[i + i_subfr_fx], gain_pit_fx); - L_tmp = L_shl(L_tmp, 1); /* saturation can occur here */ + L_tmp = L_shl( L_tmp, 5 ); + L_tmp = L_mac( L_tmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); + L_tmp = L_shl( L_tmp, 1 ); /* saturation can occur here */ - exc_fx[i+i_subfr_fx] = round_fx(L_add(L_tmp, Ltmp1)); + exc_fx[i + i_subfr_fx] = round_fx( L_add( L_tmp, Ltmp1 ) ); #endif } } ELSE { - Acelp_dec_total_exc( exc_fx, exc2_fx, gain_code16, gain_pit_fx, i_subfr_fx, code_fx, L_SUBFR); + Acelp_dec_total_exc( exc_fx, exc2_fx, gain_code16, gain_pit_fx, i_subfr_fx, code_fx, L_SUBFR ); } /*-----------------------------------------------------------------* @@ -285,7 +283,7 @@ ivas_error decod_gen_voic_fx( *-----------------------------------------------------------------*/ prep_tbe_exc_fx( L_frame, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, - &voice_factors_fx[i_subfr_fx/L_SUBFR], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, + &voice_factors_fx[i_subfr_fx / L_SUBFR], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, st_fx->Q_exc, T0_fx, T0_frac_fx, st_fx->coder_type, st_fx->core_brate ); @@ -294,20 +292,20 @@ ivas_error decod_gen_voic_fx( *----------------------------------------------------------------*/ test(); - IF( GT_32(st_fx->core_brate,ACELP_32k)||EQ_16(st_fx->coder_type,INACTIVE)) + IF( GT_32( st_fx->core_brate, ACELP_32k ) || EQ_16( st_fx->coder_type, INACTIVE ) ) { - Copy( exc_fx+i_subfr_fx, exc2_fx+i_subfr_fx, L_SUBFR ); + Copy( exc_fx + i_subfr_fx, exc2_fx + i_subfr_fx, L_SUBFR ); } ELSE { enhancer_fx( st_fx->core_brate, 0, st_fx->coder_type, i_subfr_fx, L_frame, voice_fac_fx, st_fx->stab_fac_fx, - norm_gain_code_fx, gain_inov_fx, &st_fx->gc_threshold_fx, code_fx, exc2_fx, gain_pit_fx, &(st_fx->dm_fx), st_fx->Q_exc ); + norm_gain_code_fx, gain_inov_fx, &st_fx->gc_threshold_fx, code_fx, exc2_fx, gain_pit_fx, &( st_fx->dm_fx ), st_fx->Q_exc ); } - p_Aq_fx += (M+1); + p_Aq_fx += ( M + 1 ); move16(); pt_pitch_fx++; - gain_buf[i_subfr_fx/L_SUBFR] = gain_pit_fx; + gain_buf[i_subfr_fx / L_SUBFR] = gain_pit_fx; move16(); } @@ -316,25 +314,25 @@ ivas_error decod_gen_voic_fx( IF( do_WI_fx ) { /* shft_prev = L_EXC_MEM - rint_new_fx(st_fx->bfi_pitch_fx);*/ - L_tmp = L_shl(L_deposit_l(st_fx->bfi_pitch_fx),10); /*Q16*/ - rint_bfi_pitch = rint_new_fx(L_tmp); /*Q0*/ - shft_prev = sub( L_EXC_MEM, rint_bfi_pitch ); /*Q0*/ + L_tmp = L_shl( L_deposit_l( st_fx->bfi_pitch_fx ), 10 ); /*Q16*/ + rint_bfi_pitch = rint_new_fx( L_tmp ); /*Q0*/ + shft_prev = sub( L_EXC_MEM, rint_bfi_pitch ); /*Q0*/ p_exc = st_fx->hWIDec->old_exc2_fx + shft_prev; p_syn = st_fx->hWIDec->old_syn2_fx + shft_prev; move16(); move16(); - prev_res_nrg = L_deposit_l(1); - prev_spch_nrg = L_deposit_l(1); - FOR( i=0; iprev_Q_exc_fr */ - prev_spch_nrg = L_mac0_sat(prev_spch_nrg, *p_syn, *p_syn); /* 2*st_fx->prev_Q_syn_fr */ + prev_spch_nrg = L_mac0_sat( prev_spch_nrg, *p_syn, *p_syn ); /* 2*st_fx->prev_Q_syn_fr */ #else prev_res_nrg = L_mac0( prev_res_nrg, *p_exc, *p_exc ); /* 2*st_fx->prev_Q_exc_fr */ - prev_spch_nrg = L_mac0(prev_spch_nrg, *p_syn, *p_syn); /* 2*st_fx->prev_Q_syn_fr */ + prev_spch_nrg = L_mac0( prev_spch_nrg, *p_syn, *p_syn ); /* 2*st_fx->prev_Q_syn_fr */ #endif p_exc++; p_syn++; @@ -344,52 +342,52 @@ ivas_error decod_gen_voic_fx( syn_12k8_fx( st_fx->L_frame, Aq_fx, exc2_fx, syn_tmp_fx, mem_tmp_fx, 1, st_fx->Q_exc, st_fx->Q_syn ); - L_tmp = L_shl(L_deposit_l(pitch_buf_fx[NB_SUBFR16k-1]),10); /*Q16*/ - rint_pitch = rint_new_fx(L_tmp); /*Q0*/ - shft_curr = sub( st_fx->L_frame, rint_pitch ); /*Q0*/ + L_tmp = L_shl( L_deposit_l( pitch_buf_fx[NB_SUBFR16k - 1] ), 10 ); /*Q16*/ + rint_pitch = rint_new_fx( L_tmp ); /*Q0*/ + shft_curr = sub( st_fx->L_frame, rint_pitch ); /*Q0*/ p_exc = exc2_fx + shft_curr; move16(); p_syn = syn_tmp_fx + shft_curr; move16(); - curr_res_nrg = L_deposit_l(1); - curr_spch_nrg = L_deposit_l(1); - FOR( i=0; iQ_exc */ - curr_spch_nrg = L_mac0_sat(curr_spch_nrg, *p_syn, *p_syn); /* 2*st_fx->Q_syn */ + curr_spch_nrg = L_mac0_sat( curr_spch_nrg, *p_syn, *p_syn ); /* 2*st_fx->Q_syn */ #else - curr_res_nrg = L_mac0(curr_res_nrg, *p_exc, *p_exc); /* 2*st_fx->Q_exc */ - curr_spch_nrg = L_mac0(curr_spch_nrg, *p_syn, *p_syn); /* 2*st_fx->Q_syn */ + curr_res_nrg = L_mac0( curr_res_nrg, *p_exc, *p_exc ); /* 2*st_fx->Q_exc */ + curr_spch_nrg = L_mac0( curr_spch_nrg, *p_syn, *p_syn ); /* 2*st_fx->Q_syn */ #endif p_exc++; p_syn++; } /* enratio = (curr_res_nrg / prev_res_nrg); */ - IF(prev_res_nrg>0) + IF( prev_res_nrg > 0 ) { - expa = norm_l(prev_res_nrg); - fraca = extract_h(L_shl(prev_res_nrg,expa)); - expa = sub(30,expa+(2*st_fx->prev_Q_exc_fr)); + expa = norm_l( prev_res_nrg ); + fraca = extract_h( L_shl( prev_res_nrg, expa ) ); + expa = sub( 30, expa + ( 2 * st_fx->prev_Q_exc_fr ) ); - expb = norm_l(curr_res_nrg); + expb = norm_l( curr_res_nrg ); #ifdef BASOP_NOGLOB fracb = round_fx_sat( L_shl_sat( curr_res_nrg, expb ) ); #else - fracb = round_fx(L_shl(curr_res_nrg,expb)); + fracb = round_fx( L_shl( curr_res_nrg, expb ) ); #endif - expb = sub(30,expb+(2*st_fx->Q_exc)); + expb = sub( 30, expb + ( 2 * st_fx->Q_exc ) ); - scale = shr(sub(fraca,fracb),15); - fracb = shl(fracb,scale); - expb = sub(expb,scale); + scale = shr( sub( fraca, fracb ), 15 ); + fracb = shl( fracb, scale ); + expb = sub( expb, scale ); - enratio = div_s(fracb,fraca); - exp1 = sub(expb,expa); - Qenratio = 15-exp1; + enratio = div_s( fracb, fraca ); + exp1 = sub( expb, expa ); + Qenratio = 15 - exp1; } ELSE { @@ -398,27 +396,27 @@ ivas_error decod_gen_voic_fx( } /* sp_enratio = curr_spch_nrg/prev_spch_nrg */ - IF(prev_spch_nrg>0) + IF( prev_spch_nrg > 0 ) { - expa = norm_l(prev_spch_nrg); - fraca = extract_h(L_shl(prev_spch_nrg,expa)); - expa = sub(30,expa+(2*st_fx->prev_Q_syn_fr)); + expa = norm_l( prev_spch_nrg ); + fraca = extract_h( L_shl( prev_spch_nrg, expa ) ); + expa = sub( 30, expa + ( 2 * st_fx->prev_Q_syn_fr ) ); - expb = norm_l(curr_spch_nrg); + expb = norm_l( curr_spch_nrg ); #ifdef BASOP_NOGLOB fracb = round_fx_sat( L_shl_sat( curr_spch_nrg, expb ) ); #else - fracb = round_fx(L_shl(curr_spch_nrg,expb)); + fracb = round_fx( L_shl( curr_spch_nrg, expb ) ); #endif - expb = sub(30,expb+(2*st_fx->Q_syn)); + expb = sub( 30, expb + ( 2 * st_fx->Q_syn ) ); - scale = shr(sub(fraca,fracb),15); - fracb = shl(fracb,scale); - expb = sub(expb,scale); + scale = shr( sub( fraca, fracb ), 15 ); + fracb = shl( fracb, scale ); + expb = sub( expb, scale ); - sp_enratio = div_s(fracb,fraca); - exp1 = sub(expb,expa); - Qsp_enratio = 15-exp1; + sp_enratio = div_s( fracb, fraca ); + exp1 = sub( expb, expa ); + Qsp_enratio = 15 - exp1; } ELSE { @@ -431,58 +429,57 @@ ivas_error decod_gen_voic_fx( test(); test(); #ifdef BASOP_NOGLOB - IF ( GT_16(shl_ro(enratio,15-Qenratio, &Overflow), 8192)&& /*compare with 0.25 in Q15*/ - LT_16(shl_ro(enratio,10-Qenratio, &Overflow), 15360) && /*compare with 15.0 in Q10*/ - GT_16(shl_ro(sp_enratio,15-Qsp_enratio, &Overflow), 4915) &&/*compare with 0.15 in Q15*/ - st_fx->bfi_pitch_fx < 9600 && /*Q6*/ - pitch_buf_fx[ sub( NB_SUBFR16k, 1 ) ] < 9600 ) /*Q6*/ + IF( GT_16( shl_ro( enratio, 15 - Qenratio, &Overflow ), 8192 ) && /*compare with 0.25 in Q15*/ + LT_16( shl_ro( enratio, 10 - Qenratio, &Overflow ), 15360 ) && /*compare with 15.0 in Q10*/ + GT_16( shl_ro( sp_enratio, 15 - Qsp_enratio, &Overflow ), 4915 ) && /*compare with 0.15 in Q15*/ + st_fx->bfi_pitch_fx < 9600 && /*Q6*/ + pitch_buf_fx[sub( NB_SUBFR16k, 1 )] < 9600 ) /*Q6*/ #else - IF ( GT_16(shl_r(enratio,15-Qenratio), 8192)&& /*compare with 0.25 in Q15*/ - LT_16(shl_r(enratio,10-Qenratio), 15360) && /*compare with 15.0 in Q10*/ - GT_16(shl_r(sp_enratio,15-Qsp_enratio), 4915) &&/*compare with 0.15 in Q15*/ - st_fx->bfi_pitch_fx < 9600 && /*Q6*/ - pitch_buf_fx[ sub( NB_SUBFR16k, 1 ) ] < 9600 ) /*Q6*/ + IF( GT_16( shl_r( enratio, 15 - Qenratio ), 8192 ) && /*compare with 0.25 in Q15*/ + LT_16( shl_r( enratio, 10 - Qenratio ), 15360 ) && /*compare with 15.0 in Q10*/ + GT_16( shl_r( sp_enratio, 15 - Qsp_enratio ), 4915 ) && /*compare with 0.15 in Q15*/ + st_fx->bfi_pitch_fx < 9600 && /*Q6*/ + pitch_buf_fx[sub( NB_SUBFR16k, 1 )] < 9600 ) /*Q6*/ #endif { - IF ((error = DTFS_new_fx(&PREVP)) != IVAS_ERR_OK) + IF( ( error = DTFS_new_fx( &PREVP ) ) != IVAS_ERR_OK ) { return error; } - IF ((error = DTFS_new_fx(&CURRP)) != IVAS_ERR_OK) + IF( ( error = DTFS_new_fx( &CURRP ) ) != IVAS_ERR_OK ) { return error; } - GetSinCosTab_fx(rint_bfi_pitch,S_fx,C_fx); - DTFS_to_fs_fx( st_fx->hWIDec->old_exc2_fx + shft_prev, rint_bfi_pitch, PREVP, (Word16)st_fx->output_Fs, do_WI_fx, S_fx, C_fx); - PREVP->Q = add(PREVP->Q, st_fx->prev_Q_exc_fr); + GetSinCosTab_fx( rint_bfi_pitch, S_fx, C_fx ); + DTFS_to_fs_fx( st_fx->hWIDec->old_exc2_fx + shft_prev, rint_bfi_pitch, PREVP, (Word16) st_fx->output_Fs, do_WI_fx, S_fx, C_fx ); + PREVP->Q = add( PREVP->Q, st_fx->prev_Q_exc_fr ); - GetSinCosTab_fx(rint_pitch,S_fx,C_fx); - DTFS_to_fs_fx( exc2_fx + shft_curr, rint_pitch, CURRP, (Word16)st_fx->output_Fs, do_WI_fx, S_fx, C_fx); - CURRP->Q = add(CURRP->Q, st_fx->Q_exc); + GetSinCosTab_fx( rint_pitch, S_fx, C_fx ); + DTFS_to_fs_fx( exc2_fx + shft_curr, rint_pitch, CURRP, (Word16) st_fx->output_Fs, do_WI_fx, S_fx, C_fx ); + CURRP->Q = add( CURRP->Q, st_fx->Q_exc ); ph_offset_fx = 0; move16(); - if ((error = WIsyn_fx(*PREVP, CURRP, dummy2, &(ph_offset_fx), out_fx, (Word16)st_fx->L_frame, 1, S_fx, C_fx, pf_temp1, pf_temp2, pf_temp, pf_n2)) != IVAS_ERR_OK) + if ( ( error = WIsyn_fx( *PREVP, CURRP, dummy2, &( ph_offset_fx ), out_fx, (Word16) st_fx->L_frame, 1, S_fx, C_fx, pf_temp1, pf_temp2, pf_temp, pf_n2 ) ) != IVAS_ERR_OK ) { return error; } Copy_Scale_sig( out_fx, exc2_fx, st_fx->L_frame, st_fx->Q_exc ); - Copy_Scale_sig( out_fx, exc_fx, st_fx->L_frame, st_fx->Q_exc ); + Copy_Scale_sig( out_fx, exc_fx, st_fx->L_frame, st_fx->Q_exc ); /* update bwe_exc for SWB-TBE */ - FOR (i_subfr_fx = 0; i_subfr_fx < L_frame; i_subfr_fx += L_SUBFR) + FOR( i_subfr_fx = 0; i_subfr_fx < L_frame; i_subfr_fx += L_SUBFR ) { - interp_code_4over2_fx( exc_fx + i_subfr_fx, bwe_exc_fx + (i_subfr_fx*2), L_SUBFR ); + interp_code_4over2_fx( exc_fx + i_subfr_fx, bwe_exc_fx + ( i_subfr_fx * 2 ), L_SUBFR ); } - count_free(PREVP); - count_free(CURRP); + count_free( PREVP ); + count_free( CURRP ); } - } /* SC-VBR */ @@ -521,41 +518,41 @@ ivas_error decod_gen_voic_fx( /*======================================================================*/ ivas_error decod_gen_voic_ivas_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 sharpFlag_fx, /* i : formant sharpening flag */ - const Word16 *Aq_fx, /* i : LP filter coefficient */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - const Word16 do_WI_fx, /* i : do interpolation after a FER */ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ - Word16 *voice_factors_fx, /* o : voicing factors */ - Word16 *exc_fx, /* i/o: adapt. excitation exc */ - Word16 *exc2_fx, /* i/o: adapt. excitation/total exc */ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ - Word16 *unbits, /* number of unused bits */ + Decoder_State *st_fx, /* i/o: decoder static memory */ + const Word16 L_frame, /* i : length of the frame */ + const Word16 sharpFlag_fx, /* i : formant sharpening flag */ + const Word16 *Aq_fx, /* i : LP filter coefficient */ + const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ + const Word16 do_WI_fx, /* i : do interpolation after a FER */ + Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ + Word16 *voice_factors_fx, /* o : voicing factors */ + Word16 *exc_fx, /* i/o: adapt. excitation exc */ + Word16 *exc2_fx, /* i/o: adapt. excitation/total exc */ + Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ + Word16 *unbits, /* number of unused bits */ Word16 *gain_buf, const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ - const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ + const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ ) { - Word16 T0_fx, T0_frac_fx, T0_min_fx, T0_max_fx;/* integer pitch variables */ - Word16 gain_pit_fx = 0; /* pitch gain Q14 */ - Word32 gain_code_fx = 0; /* gain/normalized gain of the algebraic excitation Q16 */ - Word32 norm_gain_code_fx = 0; /* normalized gain of the algebraic excitation Q16 */ - Word16 gain_inov_fx = 0; /* Innovation gain Q12 */ - Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes */ - Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes */ - Word16 voice_fac_fx; /* voicing factor Q15 */ - Word16 code_fx[L_SUBFR]; /* algebraic codevector Q12 */ + Word16 T0_fx, T0_frac_fx, T0_min_fx, T0_max_fx; /* integer pitch variables */ + Word16 gain_pit_fx = 0; /* pitch gain Q14 */ + Word32 gain_code_fx = 0; /* gain/normalized gain of the algebraic excitation Q16 */ + Word32 norm_gain_code_fx = 0; /* normalized gain of the algebraic excitation Q16 */ + Word16 gain_inov_fx = 0; /* Innovation gain Q12 */ + Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes */ + Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes */ + Word16 voice_fac_fx; /* voicing factor Q15 */ + Word16 code_fx[L_SUBFR]; /* algebraic codevector Q12 */ - const Word16 *p_Aq_fx; /* Pointer to frame LP coefficient Q12 */ - Word16 *pt_pitch_fx; /* pointer to floating pitch Q6 */ - Word16 i_subfr_fx, i; /* tmp variables */ + const Word16 *p_Aq_fx; /* Pointer to frame LP coefficient Q12 */ + Word16 *pt_pitch_fx; /* pointer to floating pitch Q6 */ + Word16 i_subfr_fx, i; /* tmp variables */ Word16 error_fx = 0; - Word16 gain_preQ_fx = 0; /* Gain of prequantizer excitation */ - Word16 code_preQ_fx[L_SUBFR]; /* Prequantizer excitation */ + Word16 gain_preQ_fx = 0; /* Gain of prequantizer excitation */ + Word16 code_preQ_fx[L_SUBFR]; /* Prequantizer excitation */ Word32 norm_gain_preQ_fx; Word16 pitch_limit_flag_fx; @@ -610,9 +607,9 @@ ivas_error decod_gen_voic_ivas_fx( move16(); test(); test(); - IF((GE_32(st_fx->core_brate, MIN_BRATE_AVQ_EXC) && LE_32(st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD)) && EQ_16(st_fx->coder_type, GENERIC)) + IF( ( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && LE_32( st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD ) ) && EQ_16( st_fx->coder_type, GENERIC ) ) { - harm_flag_acelp = (Word16)get_next_indice(st_fx, 1); + harm_flag_acelp = (Word16) get_next_indice( st_fx, 1 ); } /*------------------------------------------------------------------* @@ -620,16 +617,16 @@ ivas_error decod_gen_voic_ivas_fx( *------------------------------------------------------------------*/ p_Aq_fx = Aq_fx; - move16(); /* pointer to interpolated LPC parameters */ + move16(); /* pointer to interpolated LPC parameters */ pt_pitch_fx = pitch_buf_fx; - move16(); /* pointer to the pitch buffer */ + move16(); /* pointer to the pitch buffer */ norm_gain_preQ_fx = 0; move16(); gain_preQ_fx = 0; move16(); - set16_fx(code_preQ_fx, 0, L_SUBFR); + set16_fx( code_preQ_fx, 0, L_SUBFR ); - FOR(i_subfr_fx = 0; i_subfr_fx < L_frame; i_subfr_fx += L_SUBFR) + FOR( i_subfr_fx = 0; i_subfr_fx < L_frame; i_subfr_fx += L_SUBFR ) { /*----------------------------------------------------------------------* * Decode pitch lag @@ -637,157 +634,158 @@ ivas_error decod_gen_voic_ivas_fx( /**pt_pitch_fx = pit_decode_fx(st_fx, st_fx->core_brate, 0, L_frame, i_subfr_fx, st_fx->coder_type, &pitch_limit_flag_fx, &T0_fx, &T0_frac_fx, &T0_min_fx, &T0_max_fx, L_SUBFR);*/ - *pt_pitch_fx = pit_decode_ivas_fx(st_fx, st_fx->core_brate, 0, L_frame, i_subfr_fx, st_fx->coder_type, &pitch_limit_flag_fx, - &T0_fx, &T0_frac_fx, &T0_min_fx, &T0_max_fx, L_SUBFR, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf); + *pt_pitch_fx = pit_decode_ivas_fx( st_fx, st_fx->core_brate, 0, L_frame, i_subfr_fx, st_fx->coder_type, &pitch_limit_flag_fx, + &T0_fx, &T0_frac_fx, &T0_min_fx, &T0_max_fx, L_SUBFR, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); move16(); /*Q6*/ /*--------------------------------------------------------------* * Find the adaptive codebook vector *--------------------------------------------------------------*/ - pred_lt4(&exc_fx[i_subfr_fx], &exc_fx[i_subfr_fx], T0_fx, T0_frac_fx, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP); + pred_lt4( &exc_fx[i_subfr_fx], &exc_fx[i_subfr_fx], T0_fx, T0_frac_fx, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); - //tbe_celp_exc(L_frame, i_subfr_fx, T0_fx, T0_frac_fx, &error_fx, bwe_exc_fx); - tbe_celp_exc_ivas(st_fx->element_mode, st_fx->idchan, L_frame, L_SUBFR, i_subfr_fx, T0_fx, T0_frac_fx, &error_fx, bwe_exc_fx, st_fx->tdm_LRTD_flag); + // tbe_celp_exc(L_frame, i_subfr_fx, T0_fx, T0_frac_fx, &error_fx, bwe_exc_fx); + tbe_celp_exc_ivas( st_fx->element_mode, st_fx->idchan, L_frame, L_SUBFR, i_subfr_fx, T0_fx, T0_frac_fx, &error_fx, bwe_exc_fx, st_fx->tdm_LRTD_flag ); /*--------------------------------------------------------------* * LP filtering of the adaptive excitation *--------------------------------------------------------------*/ - lp_filt_exc_dec_fx(st_fx, MODE1, i_subfr_fx, L_SUBFR, L_frame, st_fx->acelp_cfg.ltf_mode, exc_fx); + lp_filt_exc_dec_fx( st_fx, MODE1, i_subfr_fx, L_SUBFR, L_frame, st_fx->acelp_cfg.ltf_mode, exc_fx ); /*-----------------------------------------------------------------* * Transform-domain contribution decoding (active frames) *-----------------------------------------------------------------*/ test(); - IF(GE_32(st_fx->core_brate, MIN_BRATE_AVQ_EXC) && NE_16(st_fx->coder_type, INACTIVE)) + IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && NE_16( st_fx->coder_type, INACTIVE ) ) { gain_code_fx = 0; move16(); - transf_cdbk_dec_fx(st_fx, harm_flag_acelp, i_subfr_fx, Es_pred_fx, gain_code_fx, &gain_preQ_fx, &norm_gain_preQ_fx, code_preQ_fx, unbits); + transf_cdbk_dec_fx( st_fx, harm_flag_acelp, i_subfr_fx, Es_pred_fx, gain_code_fx, &gain_preQ_fx, &norm_gain_preQ_fx, code_preQ_fx, unbits ); } /*--------------------------------------------------------------* * Innovation decoding *--------------------------------------------------------------*/ - inov_decode_fx(st_fx, st_fx->core_brate, 0, L_frame, sharpFlag_fx, i_subfr_fx, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_SUBFR); + inov_decode_fx( st_fx, st_fx->core_brate, 0, L_frame, sharpFlag_fx, i_subfr_fx, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_SUBFR ); /*--------------------------------------------------------------* * Gain decoding * Estimate spectrum tilt and voicing *--------------------------------------------------------------*/ - IF(LE_32(st_fx->core_brate, ACELP_8k00)) + IF( LE_32( st_fx->core_brate, ACELP_8k00 ) ) { - gain_dec_lbr_fx(st_fx, st_fx->coder_type, i_subfr_fx, code_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, gc_mem, gp_mem, L_SUBFR); + gain_dec_lbr_fx( st_fx, st_fx->coder_type, i_subfr_fx, code_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, gc_mem, gp_mem, L_SUBFR ); } - ELSE IF(GT_32(st_fx->core_brate, ACELP_32k)) + ELSE IF( GT_32( st_fx->core_brate, ACELP_32k ) ) { - gain_dec_SQ_fx(st_fx, i_subfr_fx, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx); + gain_dec_SQ_fx( st_fx, i_subfr_fx, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx ); } ELSE { - gain_dec_mless_fx(st_fx, L_frame, st_fx->coder_type, i_subfr_fx, -1, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx); + gain_dec_mless_fx( st_fx, L_frame, st_fx->coder_type, i_subfr_fx, -1, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx ); } - st_fx->tilt_code_fx = est_tilt_ivas_fx(exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, st_fx->Q_exc, L_SUBFR, 0); + st_fx->tilt_code_fx = est_tilt_ivas_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, st_fx->Q_exc, L_SUBFR, 0 ); /*-----------------------------------------------------------------* * Transform domain contribution decoding *-----------------------------------------------------------------*/ test(); - IF(GE_32(st_fx->total_brate, MAX_GSC_INACTIVE_BRATE) && EQ_16(st_fx->coder_type, INACTIVE)) + IF( GE_32( st_fx->total_brate, MAX_GSC_INACTIVE_BRATE ) && EQ_16( st_fx->coder_type, INACTIVE ) ) { - transf_cdbk_dec_fx(st_fx, harm_flag_acelp, i_subfr_fx, Es_pred_fx, gain_code_fx, &gain_preQ_fx, &norm_gain_preQ_fx, code_preQ_fx, unbits); + transf_cdbk_dec_fx( st_fx, harm_flag_acelp, i_subfr_fx, Es_pred_fx, gain_code_fx, &gain_preQ_fx, &norm_gain_preQ_fx, code_preQ_fx, unbits ); } /* update LP filtered gains for the case of frame erasures */ - lp_gain_updt_fx(i_subfr_fx, gain_pit_fx, L_add(norm_gain_code_fx, norm_gain_preQ_fx), &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_frame); + lp_gain_updt_fx( i_subfr_fx, gain_pit_fx, L_add( norm_gain_code_fx, norm_gain_preQ_fx ), &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_frame ); /*----------------------------------------------------------------------* - * Find the total excitation - *----------------------------------------------------------------------*/ + * Find the total excitation + *----------------------------------------------------------------------*/ - IF(EQ_16(L_frame, L_FRAME)) /* Rescaling for 12.8k core */ + IF( EQ_16( L_frame, L_FRAME ) ) /* Rescaling for 12.8k core */ { - Rescale_exc(hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], (bwe_exc_fx != NULL) ? &bwe_exc_fx[i_subfr_fx * HIBND_ACB_L_FAC] : NULL, hGSCDec->last_exc_dct_in_fx, - L_SUBFR, L_SUBFR * HIBND_ACB_L_FAC, gain_code_fx, &(st_fx->Q_exc), st_fx->Q_subfr, exc2_fx, i_subfr_fx, st_fx->coder_type); - + Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], ( bwe_exc_fx != NULL ) ? &bwe_exc_fx[i_subfr_fx * HIBND_ACB_L_FAC] : NULL, hGSCDec->last_exc_dct_in_fx, + L_SUBFR, L_SUBFR * HIBND_ACB_L_FAC, gain_code_fx, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr_fx, st_fx->coder_type ); } - ELSE /* Rescaling for 16k core */ + ELSE /* Rescaling for 16k core */ { - L_tmp_GC = L_max(gain_code_fx, L_shl(gain_preQ_fx,16)); /* Chose the maximum of gain_code or the prequantizer excitation x4 to keep some room*/ - Rescale_exc(hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], (bwe_exc_fx != NULL) ? &bwe_exc_fx[i_subfr_fx * 2] : NULL, hGSCDec->last_exc_dct_in_fx, - L_SUBFR, L_SUBFR * 2, L_tmp_GC, &(st_fx->Q_exc), st_fx->Q_subfr, exc2_fx, i_subfr_fx, st_fx->coder_type); + L_tmp_GC = L_max( gain_code_fx, L_shl( gain_preQ_fx, 16 ) ); /* Chose the maximum of gain_code or the prequantizer excitation x4 to keep some room*/ + Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], ( bwe_exc_fx != NULL ) ? &bwe_exc_fx[i_subfr_fx * 2] : NULL, hGSCDec->last_exc_dct_in_fx, + L_SUBFR, L_SUBFR * 2, L_tmp_GC, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr_fx, st_fx->coder_type ); } - gain_code16 = round_fx(L_shl(gain_code_fx, st_fx->Q_exc)); /*Q_exc*/ + gain_code16 = round_fx( L_shl( gain_code_fx, st_fx->Q_exc ) ); /*Q_exc*/ /*-----------------------------------------------------------------* * Add the ACELP pre-quantizer contribution *-----------------------------------------------------------------*/ - IF(gain_preQ_fx != 0) + IF( gain_preQ_fx != 0 ) { - if (st_fx->element_mode == EVS_MONO) { - tmp1_fx = add(15 - Q_AVQ_OUT_DEC - 2, st_fx->Q_exc); + if ( st_fx->element_mode == EVS_MONO ) + { + tmp1_fx = add( 15 - Q_AVQ_OUT_DEC - 2, st_fx->Q_exc ); } - else { - tmp1_fx = add(15 - Q_AVQ_OUT - 2, st_fx->Q_exc); + else + { + tmp1_fx = add( 15 - Q_AVQ_OUT - 2, st_fx->Q_exc ); } - FOR(i = 0; i < L_SUBFR; i++) + FOR( i = 0; i < L_SUBFR; i++ ) { Word32 Ltmp1; /* Contribution from AVQ layer */ - Ltmp1 = L_mult(gain_preQ_fx, code_preQ_fx[i]); /* Q2 + Q6 -> Q9*/ + Ltmp1 = L_mult( gain_preQ_fx, code_preQ_fx[i] ); /* Q2 + Q6 -> Q9*/ #ifdef BASOP_NOGLOB - Ltmp1 = L_shl_sat(Ltmp1, tmp1_fx); /* Q16 + Q_exc */ + Ltmp1 = L_shl_sat( Ltmp1, tmp1_fx ); /* Q16 + Q_exc */ #else - Ltmp1 = L_shl(Ltmp1, tmp1_fx); /* Q16 + Q_exc */ + Ltmp1 = L_shl( Ltmp1, tmp1_fx ); /* Q16 + Q_exc */ #endif /* Compute exc2 */ #ifdef BASOP_NOGLOB - L_tmp = L_shl_sat(L_mult(gain_pit_fx, exc_fx[i + i_subfr_fx]), 1); - exc2_fx[i + i_subfr_fx] = round_fx_sat(L_add_sat(L_tmp, Ltmp1)); + L_tmp = L_shl_sat( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 ); + exc2_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( L_tmp, Ltmp1 ) ); #else - L_tmp = L_shl(L_mult(gain_pit_fx, exc_fx[i + i_subfr_fx]), 1); - exc2_fx[i + i_subfr_fx] = round_fx(L_add(L_tmp, Ltmp1)); + L_tmp = L_shl( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 ); + exc2_fx[i + i_subfr_fx] = round_fx( L_add( L_tmp, Ltmp1 ) ); #endif /* code in Q9, gain_pit in Q14 */ - L_tmp = L_mult(gain_code16, code_fx[i]); + L_tmp = L_mult( gain_code16, code_fx[i] ); #ifdef BASOP_NOGLOB - L_tmp = L_shl_sat(L_tmp, 5); - L_tmp = L_mac_sat(L_tmp, exc_fx[i + i_subfr_fx], gain_pit_fx); - L_tmp = L_shl_sat(L_tmp, 1); /* saturation can occur here */ + L_tmp = L_shl_sat( L_tmp, 5 ); + L_tmp = L_mac_sat( L_tmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); + L_tmp = L_shl_sat( L_tmp, 1 ); /* saturation can occur here */ - exc_fx[i + i_subfr_fx] = round_fx_sat(L_add_sat(L_tmp, Ltmp1)); + exc_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( L_tmp, Ltmp1 ) ); #else - L_tmp = L_shl(L_tmp, 5); - L_tmp = L_mac(L_tmp, exc_fx[i + i_subfr_fx], gain_pit_fx); - L_tmp = L_shl(L_tmp, 1); /* saturation can occur here */ + L_tmp = L_shl( L_tmp, 5 ); + L_tmp = L_mac( L_tmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); + L_tmp = L_shl( L_tmp, 1 ); /* saturation can occur here */ - exc_fx[i + i_subfr_fx] = round_fx(L_add(L_tmp, Ltmp1)); + exc_fx[i + i_subfr_fx] = round_fx( L_add( L_tmp, Ltmp1 ) ); #endif } } ELSE { - Acelp_dec_total_exc(exc_fx, exc2_fx, gain_code16, gain_pit_fx, i_subfr_fx, code_fx, L_SUBFR); + Acelp_dec_total_exc( exc_fx, exc2_fx, gain_code16, gain_pit_fx, i_subfr_fx, code_fx, L_SUBFR ); } - /*-----------------------------------------------------------------* - * Prepare TBE excitation - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * Prepare TBE excitation + *-----------------------------------------------------------------*/ - /*prep_tbe_exc_fx(L_frame, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, - &voice_factors_fx[i_subfr_fx / L_SUBFR], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, - st_fx->Q_exc, T0_fx, T0_frac_fx, st_fx->coder_type, st_fx->core_brate);*/ - prep_tbe_exc_ivas_fx(L_frame, L_SUBFR, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, - &voice_factors_fx[i_subfr_fx / L_SUBFR], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, - st_fx->Q_exc, T0_fx, T0_frac_fx, st_fx->coder_type, st_fx->core_brate, - st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag); + /*prep_tbe_exc_fx(L_frame, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, + &voice_factors_fx[i_subfr_fx / L_SUBFR], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, + st_fx->Q_exc, T0_fx, T0_frac_fx, st_fx->coder_type, st_fx->core_brate);*/ + prep_tbe_exc_ivas_fx( L_frame, L_SUBFR, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, + &voice_factors_fx[i_subfr_fx / L_SUBFR], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, + st_fx->Q_exc, T0_fx, T0_frac_fx, st_fx->coder_type, st_fx->core_brate, + st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag ); /*----------------------------------------------------------------* @@ -795,17 +793,17 @@ ivas_error decod_gen_voic_ivas_fx( *----------------------------------------------------------------*/ test(); - IF(GT_32(st_fx->core_brate, ACELP_32k) || EQ_16(st_fx->coder_type, INACTIVE)) + IF( GT_32( st_fx->core_brate, ACELP_32k ) || EQ_16( st_fx->coder_type, INACTIVE ) ) { - Copy(exc_fx + i_subfr_fx, exc2_fx + i_subfr_fx, L_SUBFR); + Copy( exc_fx + i_subfr_fx, exc2_fx + i_subfr_fx, L_SUBFR ); } ELSE { - enhancer_fx(st_fx->core_brate, 0, st_fx->coder_type, i_subfr_fx, L_frame, voice_fac_fx, st_fx->stab_fac_fx, - norm_gain_code_fx, gain_inov_fx, &st_fx->gc_threshold_fx, code_fx, exc2_fx, gain_pit_fx, &(st_fx->dm_fx), st_fx->Q_exc); + enhancer_fx( st_fx->core_brate, 0, st_fx->coder_type, i_subfr_fx, L_frame, voice_fac_fx, st_fx->stab_fac_fx, + norm_gain_code_fx, gain_inov_fx, &st_fx->gc_threshold_fx, code_fx, exc2_fx, gain_pit_fx, &( st_fx->dm_fx ), st_fx->Q_exc ); } - p_Aq_fx += (M + 1); + p_Aq_fx += ( M + 1 ); move16(); pt_pitch_fx++; gain_buf[i_subfr_fx / L_SUBFR] = gain_pit_fx; @@ -814,73 +812,73 @@ ivas_error decod_gen_voic_ivas_fx( /* FEC fast recovery */ - IF(do_WI_fx) + IF( do_WI_fx ) { /* shft_prev = L_EXC_MEM - rint_new_fx(st_fx->bfi_pitch_fx);*/ - L_tmp = L_shl(L_deposit_l(st_fx->bfi_pitch_fx), 10); /*Q16*/ - rint_bfi_pitch = rint_new_fx(L_tmp); /*Q0*/ - shft_prev = sub(L_EXC_MEM, rint_bfi_pitch); /*Q0*/ + L_tmp = L_shl( L_deposit_l( st_fx->bfi_pitch_fx ), 10 ); /*Q16*/ + rint_bfi_pitch = rint_new_fx( L_tmp ); /*Q0*/ + shft_prev = sub( L_EXC_MEM, rint_bfi_pitch ); /*Q0*/ p_exc = st_fx->hWIDec->old_exc2_fx + shft_prev; p_syn = st_fx->hWIDec->old_syn2_fx + shft_prev; move16(); move16(); - prev_res_nrg = L_deposit_l(1); - prev_spch_nrg = L_deposit_l(1); - FOR(i = 0; i < rint_bfi_pitch; i++) + prev_res_nrg = L_deposit_l( 1 ); + prev_spch_nrg = L_deposit_l( 1 ); + FOR( i = 0; i < rint_bfi_pitch; i++ ) { #ifdef BASOP_NOGLOB - prev_res_nrg = L_mac0_sat(prev_res_nrg, *p_exc, *p_exc); /* 2*st_fx->prev_Q_exc_fr */ - prev_spch_nrg = L_mac0_sat(prev_spch_nrg, *p_syn, *p_syn); /* 2*st_fx->prev_Q_syn_fr */ + prev_res_nrg = L_mac0_sat( prev_res_nrg, *p_exc, *p_exc ); /* 2*st_fx->prev_Q_exc_fr */ + prev_spch_nrg = L_mac0_sat( prev_spch_nrg, *p_syn, *p_syn ); /* 2*st_fx->prev_Q_syn_fr */ #else - prev_res_nrg = L_mac0(prev_res_nrg, *p_exc, *p_exc); /* 2*st_fx->prev_Q_exc_fr */ - prev_spch_nrg = L_mac0(prev_spch_nrg, *p_syn, *p_syn); /* 2*st_fx->prev_Q_syn_fr */ + prev_res_nrg = L_mac0( prev_res_nrg, *p_exc, *p_exc ); /* 2*st_fx->prev_Q_exc_fr */ + prev_spch_nrg = L_mac0( prev_spch_nrg, *p_syn, *p_syn ); /* 2*st_fx->prev_Q_syn_fr */ #endif p_exc++; p_syn++; } - Copy(st_fx->mem_syn2_fx, mem_tmp_fx, M); + Copy( st_fx->mem_syn2_fx, mem_tmp_fx, M ); - syn_12k8_fx(st_fx->L_frame, Aq_fx, exc2_fx, syn_tmp_fx, mem_tmp_fx, 1, st_fx->Q_exc, st_fx->Q_syn); + syn_12k8_fx( st_fx->L_frame, Aq_fx, exc2_fx, syn_tmp_fx, mem_tmp_fx, 1, st_fx->Q_exc, st_fx->Q_syn ); - L_tmp = L_shl(L_deposit_l(pitch_buf_fx[NB_SUBFR16k - 1]), 10); /*Q16*/ - rint_pitch = rint_new_fx(L_tmp); /*Q0*/ - shft_curr = sub(st_fx->L_frame, rint_pitch); /*Q0*/ + L_tmp = L_shl( L_deposit_l( pitch_buf_fx[NB_SUBFR16k - 1] ), 10 ); /*Q16*/ + rint_pitch = rint_new_fx( L_tmp ); /*Q0*/ + shft_curr = sub( st_fx->L_frame, rint_pitch ); /*Q0*/ p_exc = exc2_fx + shft_curr; move16(); p_syn = syn_tmp_fx + shft_curr; move16(); - curr_res_nrg = L_deposit_l(1); - curr_spch_nrg = L_deposit_l(1); - FOR(i = 0; i < rint_pitch; i++) + curr_res_nrg = L_deposit_l( 1 ); + curr_spch_nrg = L_deposit_l( 1 ); + FOR( i = 0; i < rint_pitch; i++ ) { - curr_res_nrg = L_mac0(curr_res_nrg, *p_exc, *p_exc); /* 2*st_fx->Q_exc */ - curr_spch_nrg = L_mac0(curr_spch_nrg, *p_syn, *p_syn); /* 2*st_fx->Q_syn */ + curr_res_nrg = L_mac0( curr_res_nrg, *p_exc, *p_exc ); /* 2*st_fx->Q_exc */ + curr_spch_nrg = L_mac0( curr_spch_nrg, *p_syn, *p_syn ); /* 2*st_fx->Q_syn */ p_exc++; p_syn++; } /* enratio = (curr_res_nrg / prev_res_nrg); */ - IF(prev_res_nrg > 0) + IF( prev_res_nrg > 0 ) { - expa = norm_l(prev_res_nrg); - fraca = extract_h(L_shl(prev_res_nrg, expa)); - expa = sub(30, expa + (2 * st_fx->prev_Q_exc_fr)); + expa = norm_l( prev_res_nrg ); + fraca = extract_h( L_shl( prev_res_nrg, expa ) ); + expa = sub( 30, expa + ( 2 * st_fx->prev_Q_exc_fr ) ); - expb = norm_l(curr_res_nrg); - fracb = round_fx(L_shl(curr_res_nrg, expb)); - expb = sub(30, expb + (2 * st_fx->Q_exc)); + expb = norm_l( curr_res_nrg ); + fracb = round_fx( L_shl( curr_res_nrg, expb ) ); + expb = sub( 30, expb + ( 2 * st_fx->Q_exc ) ); - scale = shr(sub(fraca, fracb), 15); - fracb = shl(fracb, scale); - expb = sub(expb, scale); + scale = shr( sub( fraca, fracb ), 15 ); + fracb = shl( fracb, scale ); + expb = sub( expb, scale ); - enratio = div_s(fracb, fraca); - exp1 = sub(expb, expa); + enratio = div_s( fracb, fraca ); + exp1 = sub( expb, expa ); Qenratio = 15 - exp1; } ELSE @@ -889,23 +887,23 @@ ivas_error decod_gen_voic_ivas_fx( Qenratio = 0; } - /* sp_enratio = curr_spch_nrg/prev_spch_nrg */ - IF(prev_spch_nrg > 0) + /* sp_enratio = curr_spch_nrg/prev_spch_nrg */ + IF( prev_spch_nrg > 0 ) { - expa = norm_l(prev_spch_nrg); - fraca = extract_h(L_shl(prev_spch_nrg, expa)); - expa = sub(30, expa + (2 * st_fx->prev_Q_syn_fr)); + expa = norm_l( prev_spch_nrg ); + fraca = extract_h( L_shl( prev_spch_nrg, expa ) ); + expa = sub( 30, expa + ( 2 * st_fx->prev_Q_syn_fr ) ); - expb = norm_l(curr_spch_nrg); - fracb = round_fx(L_shl(curr_spch_nrg, expb)); - expb = sub(30, expb + (2 * st_fx->Q_syn)); + expb = norm_l( curr_spch_nrg ); + fracb = round_fx( L_shl( curr_spch_nrg, expb ) ); + expb = sub( 30, expb + ( 2 * st_fx->Q_syn ) ); - scale = shr(sub(fraca, fracb), 15); - fracb = shl(fracb, scale); - expb = sub(expb, scale); + scale = shr( sub( fraca, fracb ), 15 ); + fracb = shl( fracb, scale ); + expb = sub( expb, scale ); - sp_enratio = div_s(fracb, fraca); - exp1 = sub(expb, expa); + sp_enratio = div_s( fracb, fraca ); + exp1 = sub( expb, expa ); Qsp_enratio = 15 - exp1; } ELSE @@ -919,58 +917,57 @@ ivas_error decod_gen_voic_ivas_fx( test(); test(); #ifdef BASOP_NOGLOB - IF(GT_16(shl_ro(enratio, 15 - Qenratio, &Overflow), 8192) && /*compare with 0.25 in Q15*/ - LT_16(shl_ro(enratio, 10 - Qenratio, &Overflow), 15360) && /*compare with 15.0 in Q10*/ - GT_16(shl_ro(sp_enratio, 15 - Qsp_enratio, &Overflow), 4915) &&/*compare with 0.15 in Q15*/ - st_fx->bfi_pitch_fx < 9600 && /*Q6*/ - pitch_buf_fx[sub(NB_SUBFR16k, 1)] < 9600) /*Q6*/ + IF( GT_16( shl_ro( enratio, 15 - Qenratio, &Overflow ), 8192 ) && /*compare with 0.25 in Q15*/ + LT_16( shl_ro( enratio, 10 - Qenratio, &Overflow ), 15360 ) && /*compare with 15.0 in Q10*/ + GT_16( shl_ro( sp_enratio, 15 - Qsp_enratio, &Overflow ), 4915 ) && /*compare with 0.15 in Q15*/ + st_fx->bfi_pitch_fx < 9600 && /*Q6*/ + pitch_buf_fx[sub( NB_SUBFR16k, 1 )] < 9600 ) /*Q6*/ #else - IF(GT_16(shl_r(enratio, 15 - Qenratio), 8192) && /*compare with 0.25 in Q15*/ - LT_16(shl_r(enratio, 10 - Qenratio), 15360) && /*compare with 15.0 in Q10*/ - GT_16(shl_r(sp_enratio, 15 - Qsp_enratio), 4915) &&/*compare with 0.15 in Q15*/ - st_fx->bfi_pitch_fx < 9600 && /*Q6*/ - pitch_buf_fx[sub(NB_SUBFR16k, 1)] < 9600) /*Q6*/ + IF( GT_16( shl_r( enratio, 15 - Qenratio ), 8192 ) && /*compare with 0.25 in Q15*/ + LT_16( shl_r( enratio, 10 - Qenratio ), 15360 ) && /*compare with 15.0 in Q10*/ + GT_16( shl_r( sp_enratio, 15 - Qsp_enratio ), 4915 ) && /*compare with 0.15 in Q15*/ + st_fx->bfi_pitch_fx < 9600 && /*Q6*/ + pitch_buf_fx[sub( NB_SUBFR16k, 1 )] < 9600 ) /*Q6*/ #endif { - IF((error = DTFS_new_fx(&PREVP)) != IVAS_ERR_OK) + IF( ( error = DTFS_new_fx( &PREVP ) ) != IVAS_ERR_OK ) { return error; } - IF((error = DTFS_new_fx(&CURRP)) != IVAS_ERR_OK) + IF( ( error = DTFS_new_fx( &CURRP ) ) != IVAS_ERR_OK ) { return error; } - GetSinCosTab_fx(rint_bfi_pitch, S_fx, C_fx); - DTFS_to_fs_fx(st_fx->hWIDec->old_exc2_fx + shft_prev, rint_bfi_pitch, PREVP, (Word16)st_fx->output_Fs, do_WI_fx, S_fx, C_fx); - PREVP->Q = add(PREVP->Q, st_fx->prev_Q_exc_fr); + GetSinCosTab_fx( rint_bfi_pitch, S_fx, C_fx ); + DTFS_to_fs_fx( st_fx->hWIDec->old_exc2_fx + shft_prev, rint_bfi_pitch, PREVP, (Word16) st_fx->output_Fs, do_WI_fx, S_fx, C_fx ); + PREVP->Q = add( PREVP->Q, st_fx->prev_Q_exc_fr ); - GetSinCosTab_fx(rint_pitch, S_fx, C_fx); - DTFS_to_fs_fx(exc2_fx + shft_curr, rint_pitch, CURRP, (Word16)st_fx->output_Fs, do_WI_fx, S_fx, C_fx); - CURRP->Q = add(CURRP->Q, st_fx->Q_exc); + GetSinCosTab_fx( rint_pitch, S_fx, C_fx ); + DTFS_to_fs_fx( exc2_fx + shft_curr, rint_pitch, CURRP, (Word16) st_fx->output_Fs, do_WI_fx, S_fx, C_fx ); + CURRP->Q = add( CURRP->Q, st_fx->Q_exc ); ph_offset_fx = 0; move16(); - if ((error = WIsyn_fx(*PREVP, CURRP, dummy2, &(ph_offset_fx), out_fx, (Word16)st_fx->L_frame, 1, S_fx, C_fx, pf_temp1, pf_temp2, pf_temp, pf_n2)) != IVAS_ERR_OK) + if ( ( error = WIsyn_fx( *PREVP, CURRP, dummy2, &( ph_offset_fx ), out_fx, (Word16) st_fx->L_frame, 1, S_fx, C_fx, pf_temp1, pf_temp2, pf_temp, pf_n2 ) ) != IVAS_ERR_OK ) { return error; } - Copy_Scale_sig(out_fx, exc2_fx, st_fx->L_frame, st_fx->Q_exc); - Copy_Scale_sig(out_fx, exc_fx, st_fx->L_frame, st_fx->Q_exc); + Copy_Scale_sig( out_fx, exc2_fx, st_fx->L_frame, st_fx->Q_exc ); + Copy_Scale_sig( out_fx, exc_fx, st_fx->L_frame, st_fx->Q_exc ); /* update bwe_exc for SWB-TBE */ - FOR(i_subfr_fx = 0; i_subfr_fx < L_frame; i_subfr_fx += L_SUBFR) + FOR( i_subfr_fx = 0; i_subfr_fx < L_frame; i_subfr_fx += L_SUBFR ) { - interp_code_4over2_fx(exc_fx + i_subfr_fx, bwe_exc_fx + (i_subfr_fx * 2), L_SUBFR); + interp_code_4over2_fx( exc_fx + i_subfr_fx, bwe_exc_fx + ( i_subfr_fx * 2 ), L_SUBFR ); } - count_free(PREVP); - count_free(CURRP); + count_free( PREVP ); + count_free( CURRP ); } - } /* SC-VBR */ @@ -981,4 +978,4 @@ ivas_error decod_gen_voic_ivas_fx( return error; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/dec_higher_acelp_fx.c b/lib_dec/dec_higher_acelp_fx.c index dc20741ad..b9963725e 100644 --- a/lib_dec/dec_higher_acelp_fx.c +++ b/lib_dec/dec_higher_acelp_fx.c @@ -2,12 +2,12 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ +#include "options.h" /* Compilation switches */ #include -#include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "rom_com.h" /* Static table prototypes */ +#include "cnst.h" /* Common constants */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "rom_com.h" /* Static table prototypes */ #define IVAS_CODE #define IVAS_CODE_AVQ @@ -17,19 +17,19 @@ *-----------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED void transf_cdbk_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 harm_flag_acelp,/* i : harmonic flag for higher rates ACELP */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 Es_pred, /* i : predicited scaled innovation energy (Q8) */ - const Word32 gain_code, /* i : innovative excitation gain (Q16) */ - Word16 *gain_preQ, /* o : prequantizer excitation gain (Q2) */ - Word32 *norm_gain_preQ, /* o : normalized prequantizer excitation gain (Q16) */ - Word16 code_preQ[], /* o : prequantizer excitation (Q8) */ - Word16 *unbits /* o : number of AVQ unused bits */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 harm_flag_acelp, /* i : harmonic flag for higher rates ACELP */ + const Word16 i_subfr, /* i : subframe index */ + const Word16 Es_pred, /* i : predicited scaled innovation energy (Q8) */ + const Word32 gain_code, /* i : innovative excitation gain (Q16) */ + Word16 *gain_preQ, /* o : prequantizer excitation gain (Q2) */ + Word32 *norm_gain_preQ, /* o : normalized prequantizer excitation gain (Q16) */ + Word16 code_preQ[], /* o : prequantizer excitation (Q8) */ + Word16 *unbits /* o : number of AVQ unused bits */ ) { Word16 i, index, nBits; - Word16 nq[L_SUBFR/WIDTH_BAND]; + Word16 nq[L_SUBFR / WIDTH_BAND]; Word16 gain16, exp16, tmp16; Word32 L_tmp; Word32 dct_code32[L_SUBFR]; @@ -38,13 +38,13 @@ void transf_cdbk_dec_fx( Flag Overflow = 0; #endif #ifdef IVAS_CODE - Word16 avq_bit_sFlag; - Word16 trgtSvPos; - Word16 Nsv = 8; + Word16 avq_bit_sFlag; + Word16 trgtSvPos; + Word16 Nsv = 8; avq_bit_sFlag = 0; move16(); - IF (GT_16(st_fx->element_mode, EVS_MONO)) + IF( GT_16( st_fx->element_mode, EVS_MONO ) ) { move16(); avq_bit_sFlag = 1; @@ -54,45 +54,45 @@ void transf_cdbk_dec_fx( * Set bit-allocation *--------------------------------------------------------------*/ - nBits = st_fx->acelp_cfg.AVQ_cdk_bits[shr(i_subfr, 6)]; + nBits = st_fx->acelp_cfg.AVQ_cdk_bits[shr( i_subfr, 6 )]; move16(); /* increase # of AVQ allocated bits by unused bits from the previous subframe */ - nBits = add(nBits,*unbits); + nBits = add( nBits, *unbits ); /*--------------------------------------------------------------* * Dequantize prequantizer excitation gain *--------------------------------------------------------------*/ - index = (Word16)get_next_indice(st_fx, G_AVQ_BITS ); + index = (Word16) get_next_indice( st_fx, G_AVQ_BITS ); - IF(EQ_16(st_fx->coder_type, INACTIVE)) + IF( EQ_16( st_fx->coder_type, INACTIVE ) ) { - IF(GT_32(st_fx->core_brate, 56000)) + IF( GT_32( st_fx->core_brate, 56000 ) ) { - gain16 = usdequant_fx( index, G_AVQ_MIN_INACT_64k_Q12, G_AVQ_DELTA_INACT_64k_Q12>>1 ); + gain16 = usdequant_fx( index, G_AVQ_MIN_INACT_64k_Q12, G_AVQ_DELTA_INACT_64k_Q12 >> 1 ); } - ELSE IF( GT_32(st_fx->core_brate,42000)) + ELSE IF( GT_32( st_fx->core_brate, 42000 ) ) { - gain16 = usdequant_fx( index, G_AVQ_MIN_INACT_48k_Q12, G_AVQ_DELTA_INACT_48k_Q12>>1 ); + gain16 = usdequant_fx( index, G_AVQ_MIN_INACT_48k_Q12, G_AVQ_DELTA_INACT_48k_Q12 >> 1 ); } ELSE { - gain16 = usdequant_fx( index, G_AVQ_MIN_INACT_Q12, G_AVQ_DELTA_INACT_Q12>>1 ); + gain16 = usdequant_fx( index, G_AVQ_MIN_INACT_Q12, G_AVQ_DELTA_INACT_Q12 >> 1 ); } - L_tmp = Mult_32_16(gain_code,gain16); /* Q16 * Q12 - 15 -> Q13*/ + L_tmp = Mult_32_16( gain_code, gain16 ); /* Q16 * Q12 - 15 -> Q13*/ #ifdef BASOP_NOGLOB L_tmp = L_shl_sat( L_tmp, 5 ); /* Q13 -> Q18*/ - *gain_preQ = round_fx_sat(L_tmp); /* Q2*/ + *gain_preQ = round_fx_sat( L_tmp ); /* Q2*/ #else - L_tmp = L_shl(L_tmp,5); /* Q13 -> Q18*/ - *gain_preQ = round_fx(L_tmp); /* Q2*/ + L_tmp = L_shl( L_tmp, 5 ); /* Q13 -> Q18*/ + *gain_preQ = round_fx( L_tmp ); /* Q2*/ #endif } ELSE { - IF( GT_32(st_fx->core_brate,ACELP_24k40) && LE_32(st_fx->core_brate,42000)) + IF( GT_32( st_fx->core_brate, ACELP_24k40 ) && LE_32( st_fx->core_brate, 42000 ) ) { gain16 = gain_dequant_fx( index, G_AVQ_MIN_32kbps_Q15, G_AVQ_MAX_Q0, G_AVQ_BITS, &exp16 ); } @@ -103,24 +103,29 @@ void transf_cdbk_dec_fx( IF( Es_pred < 0 ) { - tmp16 = shr(negate(Es_pred),2); - L_tmp = L_mult(gain16,tmp16); /* Q0*Q8 -> Q9*/ + tmp16 = shr( negate( Es_pred ), 2 ); + L_tmp = L_mult( gain16, tmp16 ); /* Q0*Q8 -> Q9*/ } ELSE { - L_tmp = L_mult(gain16,Es_pred); /* Q0*Q8 -> Q9*/ + L_tmp = L_mult( gain16, Es_pred ); /* Q0*Q8 -> Q9*/ } - L_tmp = L_shl(L_tmp,add(exp16,9)); /* Q18*/ - *gain_preQ = round_fx(L_tmp); /* Q2*/ + L_tmp = L_shl( L_tmp, add( exp16, 9 ) ); /* Q18*/ + *gain_preQ = round_fx( L_tmp ); /* Q2*/ } #ifdef IVAS_CODE - trgtSvPos =sub(Nsv, 1); - test(); test(); test(); test(); test(); - IF (avq_bit_sFlag && GT_16(nBits, 85) && !harm_flag_acelp && (EQ_16(st_fx->coder_type, GENERIC) || EQ_16(st_fx->coder_type, TRANSITION) || EQ_16(st_fx->coder_type, INACTIVE) )) + trgtSvPos = sub( Nsv, 1 ); + test(); + test(); + test(); + test(); + test(); + IF( avq_bit_sFlag && GT_16( nBits, 85 ) && !harm_flag_acelp && ( EQ_16( st_fx->coder_type, GENERIC ) || EQ_16( st_fx->coder_type, TRANSITION ) || EQ_16( st_fx->coder_type, INACTIVE ) ) ) { trgtSvPos = 2; avq_bit_sFlag = 2; - move16(); move16(); + move16(); + move16(); } #endif /*--------------------------------------------------------------* @@ -128,25 +133,27 @@ void transf_cdbk_dec_fx( *--------------------------------------------------------------*/ #ifdef IVAS_CODE_AVQ - AVQ_demuxdec_fx(st_fx, code_preQ, &nBits, 8, nq, avq_bit_sFlag, trgtSvPos); + AVQ_demuxdec_fx( st_fx, code_preQ, &nBits, 8, nq, avq_bit_sFlag, trgtSvPos ); Word16 q_Code_preQ; - IF (st_fx->element_mode == EVS_MONO) { + IF( st_fx->element_mode == EVS_MONO ) + { q_Code_preQ = Q_AVQ_OUT_DEC; } - ELSE { + ELSE + { q_Code_preQ = Q_AVQ_OUT; } #else - AVQ_demuxdec_fx(st_fx, code_preQ, &nBits, 8, nq ); + AVQ_demuxdec_fx( st_fx, code_preQ, &nBits, 8, nq ); #endif - FOR( i=0; icoder_type,INACTIVE) || GT_32(st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD)||harm_flag_acelp) + IF( EQ_16( st_fx->coder_type, INACTIVE ) || GT_32( st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD ) || harm_flag_acelp ) { qdct = 0; move16(); edct2_fx( L_SUBFR, 1, code_preQ, dct_code32, &qdct, ip_edct2_64, w_edct2_64_fx ); /*qdct = sub(q_Code_preQ,qdct+q_Code_preQ);*/ - qdct = negate(qdct); - Copy_Scale_sig_32_16(dct_code32, code_preQ, L_SUBFR, qdct); /* Output in q_Code_preQ */ + qdct = negate( qdct ); + Copy_Scale_sig_32_16( dct_code32, code_preQ, L_SUBFR, qdct ); /* Output in q_Code_preQ */ /*qdct = q_Code_preQ;*/ } /*--------------------------------------------------------------* @@ -174,10 +181,10 @@ void transf_cdbk_dec_fx( *--------------------------------------------------------------*/ /* in extreme cases at subframe boundaries, lower the preemphasis memory to avoid a saturation */ test(); - if( (nq[7] != 0) && (GT_16( sub(st_fx->last_nq_preQ, nq[0]), 7))) + if ( ( nq[7] != 0 ) && ( GT_16( sub( st_fx->last_nq_preQ, nq[0] ), 7 ) ) ) { /* *mem_preemp /= 16; */ - st_fx->mem_preemp_preQ_fx= shr(st_fx->mem_preemp_preQ_fx,4); + st_fx->mem_preemp_preQ_fx = shr( st_fx->mem_preemp_preQ_fx, 4 ); move16(); } st_fx->last_nq_preQ = nq[7]; @@ -185,22 +192,22 @@ void transf_cdbk_dec_fx( #ifdef IVAS_CODE_AVQ /* TD pre-quantizer: in extreme cases at subframe boundaries, lower the preemphasis memory to avoid a saturation */ - IF(GT_16(st_fx->element_mode, EVS_MONO) && NE_16(st_fx->coder_type, INACTIVE) && GE_32(st_fx->core_brate, MIN_BRATE_AVQ_EXC) && LE_32(st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD) && !harm_flag_acelp && code_preQ[0] != 0) + IF( GT_16( st_fx->element_mode, EVS_MONO ) && NE_16( st_fx->coder_type, INACTIVE ) && GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && LE_32( st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD ) && !harm_flag_acelp && code_preQ[0] != 0 ) { - //PMT("Fixed point taking accound of the scaling needs to be done here ") - IF(GT_16(abs_s(st_fx->last_code_preq), shl_sat(abs_s(code_preQ[0]), 4))) + // PMT("Fixed point taking accound of the scaling needs to be done here ") + IF( GT_16( abs_s( st_fx->last_code_preq ), shl_sat( abs_s( code_preQ[0] ), 4 ) ) ) { - st_fx->mem_preemp_preQ_fx = shr(st_fx->mem_preemp_preQ_fx, 4); + st_fx->mem_preemp_preQ_fx = shr( st_fx->mem_preemp_preQ_fx, 4 ); } - ELSE IF(GT_16(abs_s((st_fx->last_code_preq)), shl_sat(abs_s(code_preQ[0]), 3))) + ELSE IF( GT_16( abs_s( ( st_fx->last_code_preq ) ), shl_sat( abs_s( code_preQ[0] ), 3 ) ) ) { - st_fx->mem_preemp_preQ_fx = shr(st_fx->mem_preemp_preQ_fx, 3); + st_fx->mem_preemp_preQ_fx = shr( st_fx->mem_preemp_preQ_fx, 3 ); } } - st_fx->last_code_preq = (Word16)code_preQ[L_SUBFR - 1]; + st_fx->last_code_preq = (Word16) code_preQ[L_SUBFR - 1]; #endif - preemph_fx( code_preQ, FAC_PRE_AVQ_FX, L_SUBFR, &st_fx->mem_preemp_preQ_fx); + preemph_fx( code_preQ, FAC_PRE_AVQ_FX, L_SUBFR, &st_fx->mem_preemp_preQ_fx ); /*--------------------------------------------------------------* * Compute normalized prequantizer excitation gain for FEC * @@ -210,9 +217,9 @@ void transf_cdbk_dec_fx( /*Ecode = (sum2_f( code_preQ, L_SUBFR ) + 0.01f) / L_SUBFR;*/ /*norm_gain_preQ = 0.8f * (*gain_preQ) * (float)sqrt( Ecode );*/ - L_tmp = Dot_product12(code_preQ, code_preQ, L_SUBFR, &exp16); + L_tmp = Dot_product12( code_preQ, code_preQ, L_SUBFR, &exp16 ); - IF( EQ_32(L_tmp,L_shl(1,sub(30,exp16)))) + IF( EQ_32( L_tmp, L_shl( 1, sub( 30, exp16 ) ) ) ) { /* pre-quantizer contribution is zero */ *norm_gain_preQ = 1; @@ -220,16 +227,16 @@ void transf_cdbk_dec_fx( } ELSE { - exp16 = sub(exp16, q_Code_preQ *2 + 6); /* exp: (code_preQ in q_Code_preQ), -6 (/L_SUBFR) */ - L_tmp = Isqrt_lc(L_tmp, &exp16); - tmp16 = extract_h(L_tmp); - exp16 = 15 - 10 - exp16; /* tmp16 in Q10+exp16*/ - tmp16 = div_s(16384,tmp16); /* Q15+Q14-(Q10+Qexp16) = Q19-exp16*/ - - L_tmp = L_mult(*gain_preQ,tmp16); /* Q2+Q19-exp16+1 -> Q22-exp16 */ - L_tmp = Mult_32_16(L_tmp, 26214 ); /* Q22-Qexp16+Q15+1-16 -> Q22-exp16*/ - *norm_gain_preQ = L_shr(L_tmp,6-exp16); - move32(); /* Q22-exp16 -> Q16*/ + exp16 = sub( exp16, q_Code_preQ * 2 + 6 ); /* exp: (code_preQ in q_Code_preQ), -6 (/L_SUBFR) */ + L_tmp = Isqrt_lc( L_tmp, &exp16 ); + tmp16 = extract_h( L_tmp ); + exp16 = 15 - 10 - exp16; /* tmp16 in Q10+exp16*/ + tmp16 = div_s( 16384, tmp16 ); /* Q15+Q14-(Q10+Qexp16) = Q19-exp16*/ + + L_tmp = L_mult( *gain_preQ, tmp16 ); /* Q2+Q19-exp16+1 -> Q22-exp16 */ + L_tmp = Mult_32_16( L_tmp, 26214 ); /* Q22-Qexp16+Q15+1-16 -> Q22-exp16*/ + *norm_gain_preQ = L_shr( L_tmp, 6 - exp16 ); + move32(); /* Q22-exp16 -> Q16*/ } @@ -237,7 +244,6 @@ void transf_cdbk_dec_fx( move16(); return; - } #endif @@ -249,7 +255,7 @@ void transf_cdbk_dec_fx( /* * range using the specified number of levels. */ /*--------------------------------------------------------------------------*/ /* INPUT ARGUMENTS : */ -/* Word16 index i: quantization index */ +/* Word16 index i: quantization index */ /* Word16 min_val i : value of lower limit */ /* Word16 max_val i : value of upper limit */ /* Word16 bits i : number of bits to dequantize */ @@ -265,20 +271,19 @@ void transf_cdbk_dec_fx( /* CALLED FROM : */ /*==========================================================================*/ #ifdef IVAS_FLOAT_FIXED -Word16 gain_dequant_fx( /* o: decoded gain */ - Word16 index, /* i: quantization index */ - const Word16 min_val, /* i: value of lower limit */ - const Word16 max_val, /* i: value of upper limit */ - const Word16 bits, /* i: number of bits to dequantize */ - Word16 *expg -) +Word16 gain_dequant_fx( /* o: decoded gain */ + Word16 index, /* i: quantization index */ + const Word16 min_val, /* i: value of lower limit */ + const Word16 max_val, /* i: value of upper limit */ + const Word16 bits, /* i: number of bits to dequantize */ + Word16 *expg ) { Word16 gain, c_min, c_max; Word16 levels; Word16 e_tmp, f_tmp; Word16 tmp, frac; Word32 L_tmp; - levels = 1<Q16*/ + L_tmp = Mult_32_16( L_tmp, 27213 ); /*Q28, 3.321928 in Q13*/ + L_tmp = L_shr( L_tmp, 12 ); /*Q28->Q16*/ - frac = L_Extract_lc(L_tmp, expg); /* Extract exponent of gcode0 */ + frac = L_Extract_lc( L_tmp, expg ); /* Extract exponent of gcode0 */ - gain = extract_l(Pow2(14, frac));/* Put 14 as exponent so that */ + gain = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ - *expg = sub(*expg, 14); + *expg = sub( *expg, 14 ); - return( gain ); + return ( gain ); } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/dec_nelp_fx.c b/lib_dec/dec_nelp_fx.c index 6ab48efb4..9732ce9f1 100644 --- a/lib_dec/dec_nelp_fx.c +++ b/lib_dec/dec_nelp_fx.c @@ -2,10 +2,10 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ #ifdef IVAS_FLOAT_FIXED /*======================================================================*/ /* FUNCTION : decod_nelp_fx() */ @@ -49,15 +49,15 @@ void decod_nelp_fx( Word16 *exc2_fx, Word16 *voice_factors, Word16 *bwe_exc_fx, - Word16 *Q_exc, Word16 bfi - , Word16 *gain_buf -) + Word16 *Q_exc, + Word16 bfi, + Word16 *gain_buf ) { Word16 i; Word16 exc_nelp_fx[L_FRAME]; Word16 coder_type; test(); - IF (st_fx->use_partial_copy && EQ_16(st_fx->rf_frame_type, RF_NELP)) + IF( st_fx->use_partial_copy && EQ_16( st_fx->rf_frame_type, RF_NELP ) ) { coder_type = UNVOICED; move16(); @@ -71,34 +71,34 @@ void decod_nelp_fx( *tmp_noise_fx = 0; move16(); - nelp_decoder_fx(st_fx, exc_nelp_fx, exc_fx, Q_exc, bfi, coder_type, gain_buf); + nelp_decoder_fx( st_fx, exc_nelp_fx, exc_fx, Q_exc, bfi, coder_type, gain_buf ); - Copy(exc_nelp_fx, exc_fx, L_FRAME); - Copy(exc_nelp_fx, exc2_fx, L_FRAME); + Copy( exc_nelp_fx, exc_fx, L_FRAME ); + Copy( exc_nelp_fx, exc2_fx, L_FRAME ); st_fx->tilt_code_fx = 0; - move16();/* purely unvoiced */ /* Q15 */ - set16_fx(st_fx->tilt_code_dec_fx, 0, NB_SUBFR16k); + move16(); /* purely unvoiced */ /* Q15 */ + set16_fx( st_fx->tilt_code_dec_fx, 0, NB_SUBFR16k ); st_fx->dm_fx.prev_state = 0; - move16();/* Q0 */ + move16(); /* Q0 */ st_fx->prev_gain_pit_dec_fx = 0; - move16(); /* Q14 */ - st_fx->dm_fx.prev_gain_pit[0]= st_fx->prev_gain_pit_dec_fx; + move16(); /* Q14 */ + st_fx->dm_fx.prev_gain_pit[0] = st_fx->prev_gain_pit_dec_fx; move16(); /* Q16 */ - FOR(i=1; i<5; i++) + FOR( i = 1; i < 5; i++ ) { - st_fx->dm_fx.prev_gain_pit[i] = st_fx->dm_fx.prev_gain_pit[i-1]; - move16(); /* Q14 */ + st_fx->dm_fx.prev_gain_pit[i] = st_fx->dm_fx.prev_gain_pit[i - 1]; + move16(); /* Q14 */ } - set16_fx(pitch_buf_fx, L_SUBFR_Q6, NB_SUBFR); /* L_SUBFR = 64, Q6 */ - set16_fx(voice_factors, 0, NB_SUBFR16k); - IF (st_fx->hBWE_TD != NULL) + set16_fx( pitch_buf_fx, L_SUBFR_Q6, NB_SUBFR ); /* L_SUBFR = 64, Q6 */ + set16_fx( voice_factors, 0, NB_SUBFR16k ); + IF( st_fx->hBWE_TD != NULL ) { - interp_code_5over2_fx(exc2_fx, bwe_exc_fx, L_FRAME); + interp_code_5over2_fx( exc2_fx, bwe_exc_fx, L_FRAME ); } return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/dec_pit_exc_fx.c b/lib_dec/dec_pit_exc_fx.c index 05eef0de0..024fcf809 100644 --- a/lib_dec/dec_pit_exc_fx.c +++ b/lib_dec/dec_pit_exc_fx.c @@ -2,11 +2,11 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ #ifdef IVAS_FLOAT_FIXED /*==========================================================================*/ @@ -32,38 +32,40 @@ /* _ None */ /*==========================================================================*/ void dec_pit_exc_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - const Word16 *Aq_fx, /* i : LP filter coefficient */ - const Word16 coder_type, /* i : coding type */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ - Word16 *code_fx, /* o : innovation */ - Word16 *exc_fx, /* i/o: adapt. excitation exc */ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ - const Word16 nb_subfr_fx /* i : Number of subframe considered */ - , Word16 *gain_buf /*Q14*/ + Decoder_State *st_fx, /* i/o: decoder static memory */ + const Word16 *Aq_fx, /* i : LP filter coefficient */ + const Word16 coder_type, /* i : coding type */ + const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ + Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ + Word16 *code_fx, /* o : innovation */ + Word16 *exc_fx, /* i/o: adapt. excitation exc */ + Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ + const Word16 nb_subfr_fx /* i : Number of subframe considered */ + , + Word16 *gain_buf /*Q14*/ #ifdef ADD_LRTD - , const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ - const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ + , + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ #endif ) { - Word16 T0_fx, T0_frac_fx, T0_min_fx, T0_max_fx;/* integer pitch variables */ - Word16 gain_pit_fx = 0; /* pitch gain Q14 */ - Word32 gain_code_fx; /* gain/normalized gain of the algebraic excitation Q16 */ - Word32 norm_gain_code_fx; /* normalized gain of the algebraic excitation Q16 */ - Word16 gain_inov_fx; /* Innovation gain Q12 */ - Word16 voice_fac_fx; /* voicing factor Q15 */ - Word16 L_subfr_fx,pit_idx_fx; - const Word16 *p_Aq_fx; /* Pointer to frame LP coefficient Q12 */ - Word16 *pt_pitch_fx; /* pointer to floating pitch Q6 */ - Word16 i_subfr_fx, i; /* tmp variables */ + Word16 T0_fx, T0_frac_fx, T0_min_fx, T0_max_fx; /* integer pitch variables */ + Word16 gain_pit_fx = 0; /* pitch gain Q14 */ + Word32 gain_code_fx; /* gain/normalized gain of the algebraic excitation Q16 */ + Word32 norm_gain_code_fx; /* normalized gain of the algebraic excitation Q16 */ + Word16 gain_inov_fx; /* Innovation gain Q12 */ + Word16 voice_fac_fx; /* voicing factor Q15 */ + Word16 L_subfr_fx, pit_idx_fx; + const Word16 *p_Aq_fx; /* Pointer to frame LP coefficient Q12 */ + Word16 *pt_pitch_fx; /* pointer to floating pitch Q6 */ + Word16 i_subfr_fx, i; /* tmp variables */ Word32 Local_BR_fx, Pitch_BR_fx; Word16 pitch_limit_flag, Pitch_CT_fx; Word16 exc2_bidon[L_SUBFR]; - Word16 *pt_gain; /* Pointer to floating gain values for each subframe */ + Word16 *pt_gain; /* Pointer to floating gain values for each subframe */ - Word16 gain_code16,gain_pitx2; + Word16 gain_code16, gain_pitx2; Word32 L_tmp; Word16 nbits; GSC_DEC_HANDLE hGSCDec; @@ -73,25 +75,29 @@ void dec_pit_exc_fx( hMusicPF = st_fx->hMusicPF; Word16 use_fcb; - Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes */ - Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes */ + Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes */ + Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes */ #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif use_fcb = 0; move16(); - test(); test(); test(); - IF (GT_16(st_fx->GSC_IVAS_mode, 0) && (EQ_16(st_fx->GSC_noisy_speech, 1) || GT_32(st_fx->core_brate, GSC_H_RATE_STG) ) ) + test(); + test(); + test(); + IF( GT_16( st_fx->GSC_IVAS_mode, 0 ) && ( EQ_16( st_fx->GSC_noisy_speech, 1 ) || GT_32( st_fx->core_brate, GSC_H_RATE_STG ) ) ) { Local_BR_fx = ACELP_8k00; Pitch_CT_fx = GENERIC; Pitch_BR_fx = ACELP_8k00; - move32(); move32(); move16(); - IF (EQ_16(st_fx->L_frame, L_FRAME16k)) + move32(); + move32(); + move16(); + IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { Local_BR_fx = ACELP_14k80; - IF (GT_16(st_fx->GSC_IVAS_mode, 0 ) ) + IF( GT_16( st_fx->GSC_IVAS_mode, 0 ) ) { Local_BR_fx = ACELP_9k60; move32(); @@ -100,7 +106,7 @@ void dec_pit_exc_fx( move32(); } } - ELSE IF( EQ_16(st_fx->GSC_noisy_speech,1)) + ELSE IF( EQ_16( st_fx->GSC_noisy_speech, 1 ) ) { Local_BR_fx = ACELP_7k20; move32(); @@ -108,7 +114,7 @@ void dec_pit_exc_fx( move16(); Pitch_BR_fx = ACELP_7k20; move32(); - IF(EQ_16(st_fx->L_frame, L_FRAME16k)) + IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { Pitch_BR_fx = st_fx->core_brate; move32(); @@ -122,7 +128,7 @@ void dec_pit_exc_fx( move16(); Pitch_BR_fx = st_fx->core_brate; move32(); - IF(EQ_16(st_fx->L_frame, L_FRAME16k)) + IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { Pitch_BR_fx = ACELP_13k20; move32(); @@ -130,41 +136,49 @@ void dec_pit_exc_fx( move16(); } } - L_subfr_fx = mult_r(st_fx->L_frame, div_s(1, nb_subfr_fx)); /* TV2Opt : this could be less complex with 2 ifs*/ + L_subfr_fx = mult_r( st_fx->L_frame, div_s( 1, nb_subfr_fx ) ); /* TV2Opt : this could be less complex with 2 ifs*/ gain_code_fx = 0; move16(); pitch_limit_flag = 1; - move16();/* always extended pitch Q range */ - test(); test(); test(); test(); test(); test(); - IF (((GE_32(st_fx->core_brate, MIN_RATE_FCB) || (EQ_16(st_fx->GSC_noisy_speech, 1) && ((EQ_16(st_fx->L_frame, L_FRAME) && GE_32(st_fx->core_brate, ACELP_13k20)) || (EQ_16(st_fx->L_frame, L_FRAME16k) && GE_32(st_fx->core_brate, GSC_H_RATE_STG)) || st_fx->GSC_IVAS_mode == 0))) && EQ_16(L_subfr_fx, L_SUBFR))) + move16(); /* always extended pitch Q range */ + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( ( GE_32( st_fx->core_brate, MIN_RATE_FCB ) || ( EQ_16( st_fx->GSC_noisy_speech, 1 ) && ( ( EQ_16( st_fx->L_frame, L_FRAME ) && GE_32( st_fx->core_brate, ACELP_13k20 ) ) || ( EQ_16( st_fx->L_frame, L_FRAME16k ) && GE_32( st_fx->core_brate, GSC_H_RATE_STG ) ) || st_fx->GSC_IVAS_mode == 0 ) ) ) && EQ_16( L_subfr_fx, L_SUBFR ) ) ) { - use_fcb = 1; move16(); + use_fcb = 1; + move16(); } - ELSE IF (GT_16(st_fx->GSC_IVAS_mode, 0) && EQ_16(L_subfr_fx, 2 * L_SUBFR) && LT_16(st_fx->GSC_IVAS_mode, 3) ) + ELSE IF( GT_16( st_fx->GSC_IVAS_mode, 0 ) && EQ_16( L_subfr_fx, 2 * L_SUBFR ) && LT_16( st_fx->GSC_IVAS_mode, 3 ) ) { use_fcb = 2; st_fx->acelp_cfg.fcb_mode = 1; - move16(); move16(); - set16_fx(st_fx->acelp_cfg.gains_mode, 6, 4); - set16_fx(st_fx->acelp_cfg.pitch_bits, 9, 4); - set16_fx(st_fx->acelp_cfg.fixed_cdk_index, 14, 5); + move16(); + move16(); + set16_fx( st_fx->acelp_cfg.gains_mode, 6, 4 ); + set16_fx( st_fx->acelp_cfg.pitch_bits, 9, 4 ); + set16_fx( st_fx->acelp_cfg.fixed_cdk_index, 14, 5 ); } /*------------------------------------------------------------------* * ACELP subframe loop *------------------------------------------------------------------*/ - p_Aq_fx = Aq_fx; /* pointer to interpolated LPC parameters */ + p_Aq_fx = Aq_fx; /* pointer to interpolated LPC parameters */ pt_pitch_fx = pitch_buf_fx; /* pointer to the pitch buffer */ pt_gain = gain_buf; /* pointer to the gain buffer */ - FOR ( i_subfr_fx = 0; i_subfr_fx < st_fx->L_frame; i_subfr_fx += L_subfr_fx ) + FOR( i_subfr_fx = 0; i_subfr_fx < st_fx->L_frame; i_subfr_fx += L_subfr_fx ) { /*----------------------------------------------------------------------* * Decode pitch lag - *----------------------------------------------------------------------*/ - *pt_pitch_fx = pit_decode_fx(st_fx, Pitch_BR_fx, 0, st_fx->L_frame, i_subfr_fx, Pitch_CT_fx, &pitch_limit_flag, &T0_fx, &T0_frac_fx, &T0_min_fx, &T0_max_fx, L_subfr_fx + *----------------------------------------------------------------------*/ + *pt_pitch_fx = pit_decode_fx( st_fx, Pitch_BR_fx, 0, st_fx->L_frame, i_subfr_fx, Pitch_CT_fx, &pitch_limit_flag, &T0_fx, &T0_frac_fx, &T0_min_fx, &T0_max_fx, L_subfr_fx #ifdef ADD_LRTD - , tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf + , + tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf #endif ); move16(); @@ -173,15 +187,15 @@ void dec_pit_exc_fx( * Find the adaptive codebook vector. *--------------------------------------------------------------*/ - pred_lt4( &exc_fx[i_subfr_fx], &exc_fx[i_subfr_fx], T0_fx, T0_frac_fx, L_subfr_fx+1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + pred_lt4( &exc_fx[i_subfr_fx], &exc_fx[i_subfr_fx], T0_fx, T0_frac_fx, L_subfr_fx + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); /*--------------------------------------------------------------* * Innovation decoding *--------------------------------------------------------------*/ - IF( EQ_16(use_fcb,1)) + IF( EQ_16( use_fcb, 1 ) ) { - inov_decode_fx( st_fx, Local_BR_fx, 0, st_fx->L_frame, 1, i_subfr_fx, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_subfr_fx); + inov_decode_fx( st_fx, Local_BR_fx, 0, st_fx->L_frame, 1, i_subfr_fx, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_subfr_fx ); /*--------------------------------------------------------------* * Gain decoding * Estimate spectrum tilt and voicing @@ -189,57 +203,58 @@ void dec_pit_exc_fx( gain_dec_mless_fx( st_fx, st_fx->L_frame, LOCAL_CT, i_subfr_fx, -1, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx ); - st_fx->tilt_code_fx = est_tilt_fx( exc_fx+i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx,0 + st_fx->tilt_code_fx = est_tilt_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, 0 #ifdef ADD_LRTD - , L_subfr_fx + , + L_subfr_fx #endif ); } - ELSE IF(EQ_16(use_fcb, 2)) /* IVAS only */ + ELSE IF( EQ_16( use_fcb, 2 ) ) /* IVAS only */ { - inov_decode_fx(st_fx, Local_BR_fx, 0, st_fx->L_frame, 1, i_subfr_fx, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_subfr_fx); + inov_decode_fx( st_fx, Local_BR_fx, 0, st_fx->L_frame, 1, i_subfr_fx, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_subfr_fx ); /*--------------------------------------------------------------* * Gain decoding * Estimate spectrum tilt and voicing *--------------------------------------------------------------*/ - gain_dec_lbr_fx(st_fx, GENERIC, i_subfr_fx, code_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, gc_mem, gp_mem, L_subfr_fx); + gain_dec_lbr_fx( st_fx, GENERIC, i_subfr_fx, code_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, gc_mem, gp_mem, L_subfr_fx ); - st_fx->tilt_code_fx = est_tilt_fx(exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, 0 + st_fx->tilt_code_fx = est_tilt_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, 0 #ifdef ADD_LRTD - , L_subfr_fx + , + L_subfr_fx #endif ); - } ELSE { nbits = 5; - IF ( LT_32(st_fx->core_brate, MIN_RATE_FCB) ) + IF( LT_32( st_fx->core_brate, MIN_RATE_FCB ) ) { nbits = 4; } move16(); - set16_fx(code_fx, 0, L_SUBFR); - gain_code_fx = L_deposit_l(0); + set16_fx( code_fx, 0, L_SUBFR ); + gain_code_fx = L_deposit_l( 0 ); st_fx->tilt_code_fx = 0; move16(); - pit_idx_fx = (Word16)get_next_indice( st_fx, nbits ); + pit_idx_fx = (Word16) get_next_indice( st_fx, nbits ); move16(); - gain_pit_fx = add(9590,dic_gp_fx[pit_idx_fx]); - move16(); /*Q14 0.5853 in Q14 9590*/ + gain_pit_fx = add( 9590, dic_gp_fx[pit_idx_fx] ); + move16(); /*Q14 0.5853 in Q14 9590*/ - if( st_fx->BER_detect ) /* Bitstream is corrupted, use the past pitch gain */ + if ( st_fx->BER_detect ) /* Bitstream is corrupted, use the past pitch gain */ { gain_pit_fx = st_fx->lp_gainp_fx; move16(); } #ifdef BASOP_NOGLOB - gain_code_fx = L_mult0(s_max(sub(32767, shl_o(gain_pit_fx, 1, &Overflow)), 16384), st_fx->lp_gainc_fx); /* Use gain pitch and past gain code as an indicator to help finding the best scaling value. gain_code_fx used a temp var*/ + gain_code_fx = L_mult0( s_max( sub( 32767, shl_o( gain_pit_fx, 1, &Overflow ) ), 16384 ), st_fx->lp_gainc_fx ); /* Use gain pitch and past gain code as an indicator to help finding the best scaling value. gain_code_fx used a temp var*/ #else - gain_code_fx = L_mult0(s_max(sub(32767, shl(gain_pit_fx,1)), 16384), st_fx->lp_gainc_fx); /* Use gain pitch and past gain code as an indicator to help finding the best scaling value. gain_code_fx used a temp var*/ + gain_code_fx = L_mult0( s_max( sub( 32767, shl( gain_pit_fx, 1 ) ), 16384 ), st_fx->lp_gainc_fx ); /* Use gain pitch and past gain code as an indicator to help finding the best scaling value. gain_code_fx used a temp var*/ #endif } @@ -247,147 +262,161 @@ void dec_pit_exc_fx( * Find the total excitation *----------------------------------------------------------------------*/ - Rescale_exc(hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[i_subfr_fx * HIBND_ACB_L_FAC], hGSCDec->last_exc_dct_in_fx, - L_subfr_fx, L_subfr_fx * HIBND_ACB_L_FAC, gain_code_fx, &(st_fx->Q_exc), st_fx->Q_subfr, NULL, i_subfr_fx, coder_type); + Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[i_subfr_fx * HIBND_ACB_L_FAC], hGSCDec->last_exc_dct_in_fx, + L_subfr_fx, L_subfr_fx * HIBND_ACB_L_FAC, gain_code_fx, &( st_fx->Q_exc ), st_fx->Q_subfr, NULL, i_subfr_fx, coder_type ); - gain_code16 = round_fx(L_shl(gain_code_fx,st_fx->Q_exc)); /*Q_exc*/ + gain_code16 = round_fx( L_shl( gain_code_fx, st_fx->Q_exc ) ); /*Q_exc*/ - IF( NE_16(use_fcb,0)) + IF( NE_16( use_fcb, 0 ) ) { - Acelp_dec_total_exc( exc_fx, exc2_bidon-i_subfr_fx, gain_code16, gain_pit_fx, i_subfr_fx, code_fx, L_subfr_fx); + Acelp_dec_total_exc( exc_fx, exc2_bidon - i_subfr_fx, gain_code16, gain_pit_fx, i_subfr_fx, code_fx, L_subfr_fx ); } ELSE { - IF (norm_s(s_or(gain_pit_fx, 1)) == 0) + IF( norm_s( s_or( gain_pit_fx, 1 ) ) == 0 ) { - FOR (i = 0; i < L_subfr_fx; i++) + FOR( i = 0; i < L_subfr_fx; i++ ) { #ifdef BASOP_NOGLOB L_tmp = L_shl_sat( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 ); /*Q16+Q_exc*/ exc_fx[i + i_subfr_fx] = round_fx_sat( L_tmp ); /*Q_exc*/ #else - L_tmp = L_shl(L_mult(gain_pit_fx, exc_fx[i+i_subfr_fx]), 1); /*Q16+Q_exc*/ - exc_fx[i+i_subfr_fx] = round_fx(L_tmp); /*Q_exc*/ + L_tmp = L_shl( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 ); /*Q16+Q_exc*/ + exc_fx[i + i_subfr_fx] = round_fx( L_tmp ); /*Q_exc*/ #endif } } ELSE { - gain_pitx2 = shl(gain_pit_fx, 1); /*Q15*/ + gain_pitx2 = shl( gain_pit_fx, 1 ); /*Q15*/ - FOR (i = 0; i < L_subfr_fx; i++) + FOR( i = 0; i < L_subfr_fx; i++ ) { - L_tmp = L_mult(gain_pitx2, exc_fx[i+i_subfr_fx]); /*Q16+Q_exc*/ + L_tmp = L_mult( gain_pitx2, exc_fx[i + i_subfr_fx] ); /*Q16+Q_exc*/ #ifdef BASOP_NOGLOB exc_fx[i + i_subfr_fx] = round_fx_sat( L_tmp ); /*Q_exc*/ #else - exc_fx[i+i_subfr_fx] = round_fx(L_tmp); /*Q_exc*/ + exc_fx[i + i_subfr_fx] = round_fx( L_tmp ); /*Q_exc*/ #endif } } } - IF (EQ_16(L_subfr_fx, L_FRAME16k)) + IF( EQ_16( L_subfr_fx, L_FRAME16k ) ) { /* update gains for FEC - equivalent to lp_gain_updt() */ - st_fx->lp_gainp_fx = gain_pit_fx; move16(); - st_fx->lp_gainc_fx = 0; move32(); + st_fx->lp_gainp_fx = gain_pit_fx; + move16(); + st_fx->lp_gainc_fx = 0; + move32(); pt_pitch_fx++; - *pt_pitch_fx = *(pt_pitch_fx - 1); + *pt_pitch_fx = *( pt_pitch_fx - 1 ); pt_pitch_fx++; - *pt_pitch_fx = *(pt_pitch_fx - 1); + *pt_pitch_fx = *( pt_pitch_fx - 1 ); pt_pitch_fx++; - *pt_pitch_fx = *(pt_pitch_fx - 1); + *pt_pitch_fx = *( pt_pitch_fx - 1 ); pt_pitch_fx++; - *pt_pitch_fx = *(pt_pitch_fx - 1); + *pt_pitch_fx = *( pt_pitch_fx - 1 ); pt_pitch_fx++; - move16(); move16(); move16(); move16(); move16(); - p_Aq_fx += 5 * (M + 1); + move16(); + move16(); + move16(); + move16(); + move16(); + p_Aq_fx += 5 * ( M + 1 ); } - ELSE IF (EQ_16(L_subfr_fx, L_FRAME16k/2)) + ELSE IF( EQ_16( L_subfr_fx, L_FRAME16k / 2 ) ) { - IF (i_subfr_fx == 0) + IF( i_subfr_fx == 0 ) { pt_pitch_fx++; - *pt_pitch_fx = *(pt_pitch_fx - 1); + *pt_pitch_fx = *( pt_pitch_fx - 1 ); pt_pitch_fx++; - p_Aq_fx += 2 * (M + 1); - move16(); move16(); move16(); move16(); + p_Aq_fx += 2 * ( M + 1 ); + move16(); + move16(); + move16(); + move16(); /* update gains for FEC - equivalent to lp_gain_updt() */ - st_fx->lp_gainp_fx = extract_h(L_mult(6554, gain_pit_fx)); /*Q14 (3/15 in Q15 9830)*/ - st_fx->lp_gainc_fx = 0; move32(); + st_fx->lp_gainp_fx = extract_h( L_mult( 6554, gain_pit_fx ) ); /*Q14 (3/15 in Q15 9830)*/ + st_fx->lp_gainc_fx = 0; + move32(); } ELSE { pt_pitch_fx++; - *pt_pitch_fx = *(pt_pitch_fx - 1); + *pt_pitch_fx = *( pt_pitch_fx - 1 ); pt_pitch_fx++; - *pt_pitch_fx = *(pt_pitch_fx - 1); + *pt_pitch_fx = *( pt_pitch_fx - 1 ); pt_pitch_fx++; - p_Aq_fx += 3 * (M + 1); - move16(); move16(); move16(); move16(); + p_Aq_fx += 3 * ( M + 1 ); + move16(); + move16(); + move16(); + move16(); /* update gains for FEC - equivalent to lp_gain_updt() */ - st_fx->lp_gainp_fx = extract_h(L_mult(26214, gain_pit_fx)); /*Q14 (12/15 in Q15 9830)*/ - st_fx->lp_gainc_fx = 0; move32(); + st_fx->lp_gainp_fx = extract_h( L_mult( 26214, gain_pit_fx ) ); /*Q14 (12/15 in Q15 9830)*/ + st_fx->lp_gainc_fx = 0; + move32(); } } - ELSE IF( EQ_16(L_subfr_fx,128)) /*2*L_SUBFR*/ + ELSE IF( EQ_16( L_subfr_fx, 128 ) ) /*2*L_SUBFR*/ { - p_Aq_fx += 2*(M+1); + p_Aq_fx += 2 * ( M + 1 ); move16(); pt_pitch_fx++; - *pt_pitch_fx = *(pt_pitch_fx-1); + *pt_pitch_fx = *( pt_pitch_fx - 1 ); move16(); pt_pitch_fx++; *pt_gain = gain_pit_fx; move16(); pt_gain++; - *pt_gain = *(pt_gain-1); + *pt_gain = *( pt_gain - 1 ); move16(); pt_gain++; IF( i_subfr_fx == 0 ) { /* update gains for FEC - equivalent to lp_gain_updt() */ - st_fx->lp_gainp_fx = extract_h(L_mult(9830,gain_pit_fx)); /*Q14 (3/10 in Q15 9830)*/ + st_fx->lp_gainp_fx = extract_h( L_mult( 9830, gain_pit_fx ) ); /*Q14 (3/10 in Q15 9830)*/ st_fx->lp_gainc_fx = 0; move16(); } ELSE { /* update gains for FEC - equivalent to lp_gain_updt() */ - st_fx->lp_gainp_fx = extract_h(L_mult(22938,gain_pit_fx)); /*Q14 (7/10 in Q15 22938)*/ + st_fx->lp_gainp_fx = extract_h( L_mult( 22938, gain_pit_fx ) ); /*Q14 (7/10 in Q15 22938)*/ st_fx->lp_gainc_fx = 0; move16(); } } - ELSE IF( EQ_16(L_subfr_fx,256)) /*4*L_SUBFR*/ + ELSE IF( EQ_16( L_subfr_fx, 256 ) ) /*4*L_SUBFR*/ { pt_pitch_fx++; - *pt_pitch_fx = *(pt_pitch_fx-1); + *pt_pitch_fx = *( pt_pitch_fx - 1 ); move16(); pt_pitch_fx++; - *pt_pitch_fx = *(pt_pitch_fx-1); + *pt_pitch_fx = *( pt_pitch_fx - 1 ); move16(); pt_pitch_fx++; - *pt_pitch_fx = *(pt_pitch_fx-1); + *pt_pitch_fx = *( pt_pitch_fx - 1 ); move16(); pt_pitch_fx++; *pt_gain = gain_pit_fx; move16(); pt_gain++; - *pt_gain = *(pt_gain-1); + *pt_gain = *( pt_gain - 1 ); move16(); pt_gain++; - *pt_gain = *(pt_gain-1); + *pt_gain = *( pt_gain - 1 ); move16(); pt_gain++; - *pt_gain = *(pt_gain-1); + *pt_gain = *( pt_gain - 1 ); move16(); pt_gain++; - p_Aq_fx += 4*(M+1); + p_Aq_fx += 4 * ( M + 1 ); move16(); /* update gains for FEC - equivalent to lp_gain_updt() */ @@ -398,7 +427,7 @@ void dec_pit_exc_fx( } ELSE { - p_Aq_fx += (M+1); + p_Aq_fx += ( M + 1 ); move16(); pt_pitch_fx++; move16(); @@ -406,7 +435,7 @@ void dec_pit_exc_fx( move16(); pt_gain++; - lp_gain_updt_fx( i_subfr_fx, gain_pit_fx, 0, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, st_fx->L_frame); + lp_gain_updt_fx( i_subfr_fx, gain_pit_fx, 0, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, st_fx->L_frame ); } } @@ -436,36 +465,38 @@ void dec_pit_exc_fx( /* _ None */ /*==========================================================================*/ void dec_pit_exc_ivas_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - const Word16 *Aq_fx, /* i : LP filter coefficient */ - const Word16 coder_type, /* i : coding type */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ - Word16 *code_fx, /* o : innovation */ - Word16 *exc_fx, /* i/o: adapt. excitation exc */ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ - const Word16 nb_subfr_fx /* i : Number of subframe considered */ - , Word16 *gain_buf /*Q14*/ -#if 1//def ADD_LRTD - , const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ - const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ + Decoder_State *st_fx, /* i/o: decoder static memory */ + const Word16 *Aq_fx, /* i : LP filter coefficient */ + const Word16 coder_type, /* i : coding type */ + const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ + Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ + Word16 *code_fx, /* o : innovation */ + Word16 *exc_fx, /* i/o: adapt. excitation exc */ + Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ + const Word16 nb_subfr_fx /* i : Number of subframe considered */ + , + Word16 *gain_buf /*Q14*/ +#if 1 // def ADD_LRTD + , + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ #endif ) { - Word16 T0_fx, T0_frac_fx, T0_min_fx, T0_max_fx;/* integer pitch variables */ - Word16 gain_pit_fx = 0; /* pitch gain Q14 */ - Word32 gain_code_fx; /* gain/normalized gain of the algebraic excitation Q16 */ - Word32 norm_gain_code_fx; /* normalized gain of the algebraic excitation Q16 */ - Word16 gain_inov_fx; /* Innovation gain Q12 */ - Word16 voice_fac_fx; /* voicing factor Q15 */ + Word16 T0_fx, T0_frac_fx, T0_min_fx, T0_max_fx; /* integer pitch variables */ + Word16 gain_pit_fx = 0; /* pitch gain Q14 */ + Word32 gain_code_fx; /* gain/normalized gain of the algebraic excitation Q16 */ + Word32 norm_gain_code_fx; /* normalized gain of the algebraic excitation Q16 */ + Word16 gain_inov_fx; /* Innovation gain Q12 */ + Word16 voice_fac_fx; /* voicing factor Q15 */ Word16 L_subfr_fx, pit_idx_fx; - const Word16 *p_Aq_fx; /* Pointer to frame LP coefficient Q12 */ - Word16 *pt_pitch_fx; /* pointer to floating pitch Q6 */ - Word16 i_subfr_fx, i; /* tmp variables */ + const Word16 *p_Aq_fx; /* Pointer to frame LP coefficient Q12 */ + Word16 *pt_pitch_fx; /* pointer to floating pitch Q6 */ + Word16 i_subfr_fx, i; /* tmp variables */ Word32 Local_BR_fx, Pitch_BR_fx; Word16 pitch_limit_flag, Pitch_CT_fx; Word16 exc2_bidon[L_SUBFR * 2]; - Word16 *pt_gain; /* Pointer to floating gain values for each subframe */ + Word16 *pt_gain; /* Pointer to floating gain values for each subframe */ Word16 gain_code16, gain_pitx2; Word32 L_tmp; @@ -477,25 +508,29 @@ void dec_pit_exc_ivas_fx( hMusicPF = st_fx->hMusicPF; Word16 use_fcb; - Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes */ - Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes */ + Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes */ + Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes */ #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif use_fcb = 0; move16(); - test(); test(); test(); - IF(GT_16(st_fx->GSC_IVAS_mode, 0) && (EQ_16(st_fx->GSC_noisy_speech, 1) || GT_32(st_fx->core_brate, GSC_H_RATE_STG))) + test(); + test(); + test(); + IF( GT_16( st_fx->GSC_IVAS_mode, 0 ) && ( EQ_16( st_fx->GSC_noisy_speech, 1 ) || GT_32( st_fx->core_brate, GSC_H_RATE_STG ) ) ) { Local_BR_fx = ACELP_8k00; Pitch_CT_fx = GENERIC; Pitch_BR_fx = ACELP_8k00; - move32(); move32(); move16(); - IF(EQ_16(st_fx->L_frame, L_FRAME16k)) + move32(); + move32(); + move16(); + IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { Local_BR_fx = ACELP_14k80; - IF(GT_16(st_fx->GSC_IVAS_mode, 0)) + IF( GT_16( st_fx->GSC_IVAS_mode, 0 ) ) { Local_BR_fx = ACELP_9k60; move32(); @@ -504,7 +539,7 @@ void dec_pit_exc_ivas_fx( move32(); } } - ELSE IF(EQ_16(st_fx->GSC_noisy_speech, 1)) + ELSE IF( EQ_16( st_fx->GSC_noisy_speech, 1 ) ) { Local_BR_fx = ACELP_7k20; move32(); @@ -512,7 +547,7 @@ void dec_pit_exc_ivas_fx( move16(); Pitch_BR_fx = ACELP_7k20; move32(); - IF(EQ_16(st_fx->L_frame, L_FRAME16k)) + IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { Pitch_BR_fx = st_fx->core_brate; move32(); @@ -526,7 +561,7 @@ void dec_pit_exc_ivas_fx( move16(); Pitch_BR_fx = st_fx->core_brate; move32(); - IF(EQ_16(st_fx->L_frame, L_FRAME16k)) + IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { Pitch_BR_fx = ACELP_13k20; move32(); @@ -534,41 +569,49 @@ void dec_pit_exc_ivas_fx( move16(); } } - L_subfr_fx = mult_r(st_fx->L_frame, div_s(1, nb_subfr_fx)); /* TV2Opt : this could be less complex with 2 ifs*/ + L_subfr_fx = mult_r( st_fx->L_frame, div_s( 1, nb_subfr_fx ) ); /* TV2Opt : this could be less complex with 2 ifs*/ gain_code_fx = 0; move16(); pitch_limit_flag = 1; - move16();/* always extended pitch Q range */ - test(); test(); test(); test(); test(); test(); - IF(((GE_32(st_fx->core_brate, MIN_RATE_FCB) || (EQ_16(st_fx->GSC_noisy_speech, 1) && ((EQ_16(st_fx->L_frame, L_FRAME) && GE_32(st_fx->core_brate, ACELP_13k20)) || (EQ_16(st_fx->L_frame, L_FRAME16k) && GE_32(st_fx->core_brate, GSC_H_RATE_STG)) || st_fx->GSC_IVAS_mode == 0))) && EQ_16(L_subfr_fx, L_SUBFR))) + move16(); /* always extended pitch Q range */ + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( ( GE_32( st_fx->core_brate, MIN_RATE_FCB ) || ( EQ_16( st_fx->GSC_noisy_speech, 1 ) && ( ( EQ_16( st_fx->L_frame, L_FRAME ) && GE_32( st_fx->core_brate, ACELP_13k20 ) ) || ( EQ_16( st_fx->L_frame, L_FRAME16k ) && GE_32( st_fx->core_brate, GSC_H_RATE_STG ) ) || st_fx->GSC_IVAS_mode == 0 ) ) ) && EQ_16( L_subfr_fx, L_SUBFR ) ) ) { - use_fcb = 1; move16(); + use_fcb = 1; + move16(); } - ELSE IF(GT_16(st_fx->GSC_IVAS_mode, 0) && EQ_16(L_subfr_fx, 2 * L_SUBFR) && LT_16(st_fx->GSC_IVAS_mode, 3)) + ELSE IF( GT_16( st_fx->GSC_IVAS_mode, 0 ) && EQ_16( L_subfr_fx, 2 * L_SUBFR ) && LT_16( st_fx->GSC_IVAS_mode, 3 ) ) { use_fcb = 2; st_fx->acelp_cfg.fcb_mode = 1; - move16(); move16(); - set16_fx(st_fx->acelp_cfg.gains_mode, 6, 4); - set16_fx(st_fx->acelp_cfg.pitch_bits, 9, 4); - set16_fx(st_fx->acelp_cfg.fixed_cdk_index, 14, 5); + move16(); + move16(); + set16_fx( st_fx->acelp_cfg.gains_mode, 6, 4 ); + set16_fx( st_fx->acelp_cfg.pitch_bits, 9, 4 ); + set16_fx( st_fx->acelp_cfg.fixed_cdk_index, 14, 5 ); } /*------------------------------------------------------------------* * ACELP subframe loop *------------------------------------------------------------------*/ - p_Aq_fx = Aq_fx; /* pointer to interpolated LPC parameters */ + p_Aq_fx = Aq_fx; /* pointer to interpolated LPC parameters */ pt_pitch_fx = pitch_buf_fx; /* pointer to the pitch buffer */ pt_gain = gain_buf; /* pointer to the gain buffer */ - FOR(i_subfr_fx = 0; i_subfr_fx < st_fx->L_frame; i_subfr_fx += L_subfr_fx) + FOR( i_subfr_fx = 0; i_subfr_fx < st_fx->L_frame; i_subfr_fx += L_subfr_fx ) { /*----------------------------------------------------------------------* * Decode pitch lag - *----------------------------------------------------------------------*/ - *pt_pitch_fx = pit_decode_ivas_fx(st_fx, Pitch_BR_fx, 0, st_fx->L_frame, i_subfr_fx, Pitch_CT_fx, &pitch_limit_flag, &T0_fx, &T0_frac_fx, &T0_min_fx, &T0_max_fx, L_subfr_fx -#if 1//def ADD_LRTD - , tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf + *----------------------------------------------------------------------*/ + *pt_pitch_fx = pit_decode_ivas_fx( st_fx, Pitch_BR_fx, 0, st_fx->L_frame, i_subfr_fx, Pitch_CT_fx, &pitch_limit_flag, &T0_fx, &T0_frac_fx, &T0_min_fx, &T0_max_fx, L_subfr_fx +#if 1 // def ADD_LRTD + , + tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf #endif ); move16(); @@ -577,235 +620,250 @@ void dec_pit_exc_ivas_fx( * Find the adaptive codebook vector. *--------------------------------------------------------------*/ - pred_lt4(&exc_fx[i_subfr_fx], &exc_fx[i_subfr_fx], T0_fx, T0_frac_fx, L_subfr_fx + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP); + pred_lt4( &exc_fx[i_subfr_fx], &exc_fx[i_subfr_fx], T0_fx, T0_frac_fx, L_subfr_fx + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); /*--------------------------------------------------------------* * Innovation decoding *--------------------------------------------------------------*/ - IF(EQ_16(use_fcb, 1)) + IF( EQ_16( use_fcb, 1 ) ) { - inov_decode_fx(st_fx, Local_BR_fx, 0, st_fx->L_frame, 1, i_subfr_fx, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_subfr_fx); + inov_decode_fx( st_fx, Local_BR_fx, 0, st_fx->L_frame, 1, i_subfr_fx, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_subfr_fx ); /*--------------------------------------------------------------* * Gain decoding * Estimate spectrum tilt and voicing *--------------------------------------------------------------*/ - gain_dec_mless_fx(st_fx, st_fx->L_frame, LOCAL_CT, i_subfr_fx, -1, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx); + gain_dec_mless_fx( st_fx, st_fx->L_frame, LOCAL_CT, i_subfr_fx, -1, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx ); - st_fx->tilt_code_fx = est_tilt_ivas_fx(exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, 0 -#if 1//def ADD_LRTD - , L_subfr_fx, 0 + st_fx->tilt_code_fx = est_tilt_ivas_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, 0 +#if 1 // def ADD_LRTD + , + L_subfr_fx, 0 #endif ); } - ELSE IF(EQ_16(use_fcb, 2)) /* IVAS only */ + ELSE IF( EQ_16( use_fcb, 2 ) ) /* IVAS only */ { /*inov_decode_fx(st_fx, Local_BR_fx, 0, st_fx->L_frame, 1, i_subfr_fx, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_subfr_fx);*/ - inov_decode_fx(st_fx, st_fx->core_brate, 0, st_fx->L_frame, 0, i_subfr_fx, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_subfr_fx); + inov_decode_fx( st_fx, st_fx->core_brate, 0, st_fx->L_frame, 0, i_subfr_fx, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_subfr_fx ); /*--------------------------------------------------------------* * Gain decoding * Estimate spectrum tilt and voicing *--------------------------------------------------------------*/ - gain_dec_lbr_fx(st_fx, GENERIC, i_subfr_fx, code_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, gc_mem, gp_mem, L_subfr_fx); + gain_dec_lbr_fx( st_fx, GENERIC, i_subfr_fx, code_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, gc_mem, gp_mem, L_subfr_fx ); - st_fx->tilt_code_fx = est_tilt_ivas_fx(exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, 0 -#if 1//def ADD_LRTD - , L_subfr_fx, 0 + st_fx->tilt_code_fx = est_tilt_ivas_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, 0 +#if 1 // def ADD_LRTD + , + L_subfr_fx, 0 #endif ); - } ELSE { nbits = 5; - IF(LT_32(st_fx->core_brate, MIN_RATE_FCB)) + IF( LT_32( st_fx->core_brate, MIN_RATE_FCB ) ) { nbits = 4; } move16(); - set16_fx(code_fx, 0, L_SUBFR); - gain_code_fx = L_deposit_l(0); + set16_fx( code_fx, 0, L_SUBFR ); + gain_code_fx = L_deposit_l( 0 ); st_fx->tilt_code_fx = 0; move16(); - pit_idx_fx = (Word16)get_next_indice(st_fx, nbits); + pit_idx_fx = (Word16) get_next_indice( st_fx, nbits ); move16(); - gain_pit_fx = add(9590,dic_gp_fx[pit_idx_fx]); - move16(); /*Q14 0.5853 in Q14 9590*/ + gain_pit_fx = add( 9590, dic_gp_fx[pit_idx_fx] ); + move16(); /*Q14 0.5853 in Q14 9590*/ - if (st_fx->BER_detect) /* Bitstream is corrupted, use the past pitch gain */ + if ( st_fx->BER_detect ) /* Bitstream is corrupted, use the past pitch gain */ { gain_pit_fx = st_fx->lp_gainp_fx; move16(); } #ifdef BASOP_NOGLOB - gain_code_fx = L_mult0(s_max(sub(32767, shl_o(gain_pit_fx, 1, &Overflow)), 16384), st_fx->lp_gainc_fx); /* Use gain pitch and past gain code as an indicator to help finding the best scaling value. gain_code_fx used a temp var*/ + gain_code_fx = L_mult0( s_max( sub( 32767, shl_o( gain_pit_fx, 1, &Overflow ) ), 16384 ), st_fx->lp_gainc_fx ); /* Use gain pitch and past gain code as an indicator to help finding the best scaling value. gain_code_fx used a temp var*/ #else - gain_code_fx = L_mult0(s_max(sub(32767, shl(gain_pit_fx,1)), 16384), st_fx->lp_gainc_fx); /* Use gain pitch and past gain code as an indicator to help finding the best scaling value. gain_code_fx used a temp var*/ + gain_code_fx = L_mult0( s_max( sub( 32767, shl( gain_pit_fx, 1 ) ), 16384 ), st_fx->lp_gainc_fx ); /* Use gain pitch and past gain code as an indicator to help finding the best scaling value. gain_code_fx used a temp var*/ #endif } - /*----------------------------------------------------------------------* - * Find the total excitation - *----------------------------------------------------------------------*/ + /*----------------------------------------------------------------------* + * Find the total excitation + *----------------------------------------------------------------------*/ - Rescale_exc(hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[i_subfr_fx * HIBND_ACB_L_FAC], hGSCDec->last_exc_dct_in_fx, - L_subfr_fx, L_subfr_fx * HIBND_ACB_L_FAC, gain_code_fx, &(st_fx->Q_exc), st_fx->Q_subfr, NULL, i_subfr_fx, coder_type); + Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[i_subfr_fx * HIBND_ACB_L_FAC], hGSCDec->last_exc_dct_in_fx, + L_subfr_fx, L_subfr_fx * HIBND_ACB_L_FAC, gain_code_fx, &( st_fx->Q_exc ), st_fx->Q_subfr, NULL, i_subfr_fx, coder_type ); - gain_code16 = round_fx(L_shl(gain_code_fx, st_fx->Q_exc)); /*Q_exc*/ + gain_code16 = round_fx( L_shl( gain_code_fx, st_fx->Q_exc ) ); /*Q_exc*/ - IF(NE_16(use_fcb, 0)) + IF( NE_16( use_fcb, 0 ) ) { - Acelp_dec_total_exc(exc_fx, exc2_bidon - i_subfr_fx, gain_code16, gain_pit_fx, i_subfr_fx, code_fx, L_subfr_fx); + Acelp_dec_total_exc( exc_fx, exc2_bidon - i_subfr_fx, gain_code16, gain_pit_fx, i_subfr_fx, code_fx, L_subfr_fx ); } ELSE { - IF(norm_s(s_or(gain_pit_fx, 1)) == 0) + IF( norm_s( s_or( gain_pit_fx, 1 ) ) == 0 ) { - FOR(i = 0; i < L_subfr_fx; i++) + FOR( i = 0; i < L_subfr_fx; i++ ) { - L_tmp = L_shl(L_mult(gain_pit_fx, exc_fx[i + i_subfr_fx]), 1); /*Q16+Q_exc*/ - exc_fx[i + i_subfr_fx] = round_fx(L_tmp); /*Q_exc*/ + L_tmp = L_shl( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 ); /*Q16+Q_exc*/ + exc_fx[i + i_subfr_fx] = round_fx( L_tmp ); /*Q_exc*/ } } ELSE { - gain_pitx2 = shl(gain_pit_fx, 1); /*Q15*/ + gain_pitx2 = shl( gain_pit_fx, 1 ); /*Q15*/ - FOR(i = 0; i < L_subfr_fx; i++) + FOR( i = 0; i < L_subfr_fx; i++ ) { - L_tmp = L_mult(gain_pitx2, exc_fx[i + i_subfr_fx]); /*Q16+Q_exc*/ - exc_fx[i + i_subfr_fx] = round_fx(L_tmp); /*Q_exc*/ + L_tmp = L_mult( gain_pitx2, exc_fx[i + i_subfr_fx] ); /*Q16+Q_exc*/ + exc_fx[i + i_subfr_fx] = round_fx( L_tmp ); /*Q_exc*/ } } } - IF(EQ_16(L_subfr_fx, L_FRAME16k)) - { - /* update gains for FEC - equivalent to lp_gain_updt() */ - st_fx->lp_gainp_fx = gain_pit_fx; move16(); - st_fx->lp_gainc_fx = 0; move32(); + IF( EQ_16( L_subfr_fx, L_FRAME16k ) ) + { + /* update gains for FEC - equivalent to lp_gain_updt() */ + st_fx->lp_gainp_fx = gain_pit_fx; + move16(); + st_fx->lp_gainc_fx = 0; + move32(); + pt_pitch_fx++; + *pt_pitch_fx = *( pt_pitch_fx - 1 ); + pt_pitch_fx++; + *pt_pitch_fx = *( pt_pitch_fx - 1 ); + pt_pitch_fx++; + *pt_pitch_fx = *( pt_pitch_fx - 1 ); + pt_pitch_fx++; + *pt_pitch_fx = *( pt_pitch_fx - 1 ); + pt_pitch_fx++; + move16(); + move16(); + move16(); + move16(); + move16(); + p_Aq_fx += 5 * ( M + 1 ); + } + ELSE IF( EQ_16( L_subfr_fx, L_FRAME16k / 2 ) ) + { + IF( i_subfr_fx == 0 ) + { pt_pitch_fx++; - *pt_pitch_fx = *(pt_pitch_fx - 1); - pt_pitch_fx++; - *pt_pitch_fx = *(pt_pitch_fx - 1); - pt_pitch_fx++; - *pt_pitch_fx = *(pt_pitch_fx - 1); - pt_pitch_fx++; - *pt_pitch_fx = *(pt_pitch_fx - 1); + *pt_pitch_fx = *( pt_pitch_fx - 1 ); pt_pitch_fx++; - move16(); move16(); move16(); move16(); move16(); - p_Aq_fx += 5 * (M + 1); - } - ELSE IF(EQ_16(L_subfr_fx, L_FRAME16k / 2)) - { - IF(i_subfr_fx == 0) - { - pt_pitch_fx++; - *pt_pitch_fx = *(pt_pitch_fx - 1); - pt_pitch_fx++; - p_Aq_fx += 2 * (M + 1); - move16(); move16(); move16(); move16(); - - /* update gains for FEC - equivalent to lp_gain_updt() */ - st_fx->lp_gainp_fx = extract_h(L_mult(6554, gain_pit_fx)); /*Q14 (3/15 in Q15 9830)*/ - st_fx->lp_gainc_fx = 0; move32(); - } - ELSE - { - pt_pitch_fx++; - *pt_pitch_fx = *(pt_pitch_fx - 1); - pt_pitch_fx++; - *pt_pitch_fx = *(pt_pitch_fx - 1); - pt_pitch_fx++; - p_Aq_fx += 3 * (M + 1); - move16(); move16(); move16(); move16(); - - /* update gains for FEC - equivalent to lp_gain_updt() */ - st_fx->lp_gainp_fx = extract_h(L_mult(26214, gain_pit_fx)); /*Q14 (12/15 in Q15 9830)*/ - st_fx->lp_gainc_fx = 0; move32(); - } - } - ELSE IF(EQ_16(L_subfr_fx, 128)) /*2*L_SUBFR*/ - { - p_Aq_fx += 2 * (M + 1); + p_Aq_fx += 2 * ( M + 1 ); move16(); - pt_pitch_fx++; - *pt_pitch_fx = *(pt_pitch_fx - 1); move16(); - pt_pitch_fx++; - *pt_gain = gain_pit_fx; move16(); - pt_gain++; - *pt_gain = *(pt_gain - 1); move16(); - pt_gain++; - IF(i_subfr_fx == 0) - { - /* update gains for FEC - equivalent to lp_gain_updt() */ - st_fx->lp_gainp_fx = extract_h(L_mult(9830, gain_pit_fx)); /*Q14 (3/10 in Q15 9830)*/ - st_fx->lp_gainc_fx = 0; - move16(); - } - ELSE - { - /* update gains for FEC - equivalent to lp_gain_updt() */ - st_fx->lp_gainp_fx = extract_h(L_mult(22938,gain_pit_fx)); /*Q14 (7/10 in Q15 22938)*/ - st_fx->lp_gainc_fx = 0; - move16(); - } + + /* update gains for FEC - equivalent to lp_gain_updt() */ + st_fx->lp_gainp_fx = extract_h( L_mult( 6554, gain_pit_fx ) ); /*Q14 (3/15 in Q15 9830)*/ + st_fx->lp_gainc_fx = 0; + move32(); } - ELSE IF(EQ_16(L_subfr_fx, 256)) /*4*L_SUBFR*/ + ELSE { pt_pitch_fx++; - *pt_pitch_fx = *(pt_pitch_fx - 1); - move16(); + *pt_pitch_fx = *( pt_pitch_fx - 1 ); pt_pitch_fx++; - *pt_pitch_fx = *(pt_pitch_fx - 1); - move16(); - pt_pitch_fx++; - *pt_pitch_fx = *(pt_pitch_fx - 1); - move16(); + *pt_pitch_fx = *( pt_pitch_fx - 1 ); pt_pitch_fx++; - *pt_gain = gain_pit_fx; + p_Aq_fx += 3 * ( M + 1 ); move16(); - pt_gain++; - *pt_gain = *(pt_gain - 1); move16(); - pt_gain++; - *pt_gain = *(pt_gain - 1); move16(); - pt_gain++; - *pt_gain = *(pt_gain - 1); - move16(); - pt_gain++; - p_Aq_fx += 4 * (M + 1); move16(); /* update gains for FEC - equivalent to lp_gain_updt() */ - st_fx->lp_gainp_fx = gain_pit_fx; - move16(); + st_fx->lp_gainp_fx = extract_h( L_mult( 26214, gain_pit_fx ) ); /*Q14 (12/15 in Q15 9830)*/ + st_fx->lp_gainc_fx = 0; + move32(); + } + } + ELSE IF( EQ_16( L_subfr_fx, 128 ) ) /*2*L_SUBFR*/ + { + p_Aq_fx += 2 * ( M + 1 ); + move16(); + pt_pitch_fx++; + *pt_pitch_fx = *( pt_pitch_fx - 1 ); + move16(); + pt_pitch_fx++; + *pt_gain = gain_pit_fx; + move16(); + pt_gain++; + *pt_gain = *( pt_gain - 1 ); + move16(); + pt_gain++; + IF( i_subfr_fx == 0 ) + { + /* update gains for FEC - equivalent to lp_gain_updt() */ + st_fx->lp_gainp_fx = extract_h( L_mult( 9830, gain_pit_fx ) ); /*Q14 (3/10 in Q15 9830)*/ st_fx->lp_gainc_fx = 0; move16(); } ELSE { - p_Aq_fx += (M + 1); - move16(); - pt_pitch_fx++; - move16(); - *pt_gain = gain_pit_fx; + /* update gains for FEC - equivalent to lp_gain_updt() */ + st_fx->lp_gainp_fx = extract_h( L_mult( 22938, gain_pit_fx ) ); /*Q14 (7/10 in Q15 22938)*/ + st_fx->lp_gainc_fx = 0; move16(); - pt_gain++; - - lp_gain_updt_fx(i_subfr_fx, gain_pit_fx, 0, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, st_fx->L_frame); } + } + ELSE IF( EQ_16( L_subfr_fx, 256 ) ) /*4*L_SUBFR*/ + { + pt_pitch_fx++; + *pt_pitch_fx = *( pt_pitch_fx - 1 ); + move16(); + pt_pitch_fx++; + *pt_pitch_fx = *( pt_pitch_fx - 1 ); + move16(); + pt_pitch_fx++; + *pt_pitch_fx = *( pt_pitch_fx - 1 ); + move16(); + pt_pitch_fx++; + *pt_gain = gain_pit_fx; + move16(); + pt_gain++; + *pt_gain = *( pt_gain - 1 ); + move16(); + pt_gain++; + *pt_gain = *( pt_gain - 1 ); + move16(); + pt_gain++; + *pt_gain = *( pt_gain - 1 ); + move16(); + pt_gain++; + p_Aq_fx += 4 * ( M + 1 ); + move16(); + + /* update gains for FEC - equivalent to lp_gain_updt() */ + st_fx->lp_gainp_fx = gain_pit_fx; + move16(); + st_fx->lp_gainc_fx = 0; + move16(); + } + ELSE + { + p_Aq_fx += ( M + 1 ); + move16(); + pt_pitch_fx++; + move16(); + *pt_gain = gain_pit_fx; + move16(); + pt_gain++; + + lp_gain_updt_fx( i_subfr_fx, gain_pit_fx, 0, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, st_fx->L_frame ); + } } return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/dec_post.c b/lib_dec/dec_post.c index 8c2059322..f4b8c3b63 100644 --- a/lib_dec/dec_post.c +++ b/lib_dec/dec_post.c @@ -222,7 +222,7 @@ void formant_post_filt_ivas( if ( L_frame == L_FRAME ) { post_G2 = 0.7f; - if ( lp_noise < LP_NOISE_THRESH_FLT) /* Clean speech */ + if ( lp_noise < LP_NOISE_THRESH_FLT ) /* Clean speech */ { if ( brate < ACELP_13k20 ) /*Low rates*/ { @@ -252,7 +252,7 @@ void formant_post_filt_ivas( else { post_G2 = 0.76f; - if ( lp_noise >= LP_NOISE_THRESH_FLT) + if ( lp_noise >= LP_NOISE_THRESH_FLT ) { post_G1 = 0.76f; } @@ -394,7 +394,7 @@ static void Dec_postfilt( filt_mu( sig_ltp, sig_out, parcor0, L_subfr, -1 ); /* Gain control */ - scale_st_ivas( signal_ptr, sig_out, &( pfstat->gain_prec_flt), L_subfr, -1 ); + scale_st_ivas( signal_ptr, sig_out, &( pfstat->gain_prec_flt ), L_subfr, -1 ); /* Update for next subframe */ mvr2r( &res2[L_subfr], pfstat->mem_res2_flt, DECMEM_RES2 ); diff --git a/lib_dec/dec_post_fx.c b/lib_dec/dec_post_fx.c index 17ef599cc..38ce6836b 100644 --- a/lib_dec/dec_post_fx.c +++ b/lib_dec/dec_post_fx.c @@ -10,30 +10,28 @@ #include "rom_com.h" #include "cnst.h" #ifdef IVAS_FLOAT_FIXED -#define FORMAT_POST_FILT_G1 24576/*0.75f Q15*/ /*0.75f*/ /*denominator 0.9,0.75,0.15,0.9*/ -#define FORMAT_POST_FILT_G2 22938/*0.7f Q15*/ /*0.7f*/ /*numerator 0.75,0.7,0.1,0.7*/ -#define FORMAT_POST_FILT_G1_MAX 26214/*0.8f Q15*/ /*for low bit-rates on clean speech*/ -#define FORMAT_POST_FILT_G1_MIN 24576/*0.75f Q15*/ /*for high bit-rates on clean speech and noisy speech*/ +#define FORMAT_POST_FILT_G1 24576 /*0.75f Q15*/ /*0.75f*/ /*denominator 0.9,0.75,0.15,0.9*/ +#define FORMAT_POST_FILT_G2 22938 /*0.7f Q15*/ /*0.7f*/ /*numerator 0.75,0.7,0.1,0.7*/ +#define FORMAT_POST_FILT_G1_MAX 26214 /*0.8f Q15*/ /*for low bit-rates on clean speech*/ +#define FORMAT_POST_FILT_G1_MIN 24576 /*0.75f Q15*/ /*for high bit-rates on clean speech and noisy speech*/ /*-------------------------------------------------------------------------- * Local function prototypes *--------------------------------------------------------------------------*/ -static void Dec_postfilt_fx( PFSTAT_HANDLE hPFstat, const Word16 t0, const Word16 *signal_ptr, const Word16 *coeff, - Word16 *sig_out, const Word16 gamma1, const Word16 gamma2, const Word16 Gain_factor, const Word16 disable_hpf ); +static void Dec_postfilt_fx( PFSTAT_HANDLE hPFstat, const Word16 t0, const Word16 *signal_ptr, const Word16 *coeff, Word16 *sig_out, const Word16 gamma1, const Word16 gamma2, const Word16 Gain_factor, const Word16 disable_hpf ); -static void pst_ltp_fx( Word16 t0, Word16 * ptr_sig_in, Word16 * ptr_sig_pst0, Word16 gain_factor ); +static void pst_ltp_fx( Word16 t0, Word16 *ptr_sig_in, Word16 *ptr_sig_pst0, Word16 gain_factor ); -static void search_del_fx( Word16 t0, Word16 * ptr_sig_in, Word16 * ltpdel, Word16 * phase, Word16 * num_gltp, Word16 * den_gltp, - Word16 * sh_num_gltp, Word16 * sh_den_gltp, Word16 * y_up, Word16 * off_yup ); +static void search_del_fx( Word16 t0, Word16 *ptr_sig_in, Word16 *ltpdel, Word16 *phase, Word16 *num_gltp, Word16 *den_gltp, Word16 *sh_num_gltp, Word16 *sh_den_gltp, Word16 *y_up, Word16 *off_yup ); -static void filt_plt_fx( Word16 * s_in, Word16 * s_ltp, Word16 * s_out, Word16 gain_plt ); +static void filt_plt_fx( Word16 *s_in, Word16 *s_ltp, Word16 *s_out, Word16 gain_plt ); -static void compute_ltp_l_fx( Word16 * s_in, Word16 ltpdel, Word16 phase, Word16 * y_up, Word16 * num, Word16 * den, Word16 * sh_num, Word16 * sh_den ); +static void compute_ltp_l_fx( Word16 *s_in, Word16 ltpdel, Word16 phase, Word16 *y_up, Word16 *num, Word16 *den, Word16 *sh_num, Word16 *sh_den ); static Word16 select_ltp_fx( Word16 num1, Word16 den1, Word16 sh_num1, Word16 sh_den1, Word16 num2, Word16 den2, Word16 sh_num2, Word16 sh_den2 ); -static void calc_st_filt_local_fx( Word16 * apond2, Word16 * apond1, Word16 * parcor0, Word16 * sig_ltp_ptr, Word16 * mem_zero ); +static void calc_st_filt_local_fx( Word16 *apond2, Word16 *apond1, Word16 *parcor0, Word16 *sig_ltp_ptr, Word16 *mem_zero ); static void modify_pst_param_fx( const Word16 lp_noise, Word16 *g1, Word16 *g2, const Word16 coder_type, Word16 *gain_factor ); @@ -52,7 +50,7 @@ static void calc_st_filt_ivas_fx( Word16 *apond2, Word16 *apond1, Word16 *parcor * post filter initialization *--------------------------------------------------------------------------*/ void Init_post_filter_fx( - PFSTAT_HANDLE hPFstat /* i : core decoder parameters */ + PFSTAT_HANDLE hPFstat /* i : core decoder parameters */ ) { /* It is off by default */ @@ -62,19 +60,20 @@ void Init_post_filter_fx( hPFstat->reset = 0; /* Initialize arrays and pointers */ - set16_fx(hPFstat->mem_pf_in, 0, L_SUBFR); + set16_fx( hPFstat->mem_pf_in, 0, L_SUBFR ); /* res2 = A(gamma2) residual */ - set16_fx(hPFstat->mem_res2, 0, DECMEM_RES2); + set16_fx( hPFstat->mem_res2, 0, DECMEM_RES2 ); /* 1/A(gamma1) memory */ - set16_fx(hPFstat->mem_stp, 0, L_SUBFR); + set16_fx( hPFstat->mem_stp, 0, L_SUBFR ); /* null memory to compute i.r. of A(gamma2)/A(gamma1) */ - set16_fx(hPFstat->mem_zero, 0, M); + set16_fx( hPFstat->mem_zero, 0, M ); /* for gain adjustment */ - hPFstat->gain_prec = 16384; /*Q14*/ move16(); + hPFstat->gain_prec = 16384; /*Q14*/ + move16(); return; } @@ -85,39 +84,39 @@ void Init_post_filter_fx( * Main routine to perform post filtering on NB synthesis *--------------------------------------------------------------------------*/ void nb_post_filt_fx( - const Word16 L_frame, /* i : frame length */ - PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ - Word16 *psf_lp_noise, /* i : Long term noise Q8 */ - const Word16 tmp_noise, /* i : noise energy Q0 */ - Word16 *Synth, /* i : 12k8 synthesis Qsyn */ - const Word16 *Aq, /* i : LP filter coefficient Q12 */ - const Word16 *Pitch_buf, /* i : Fractionnal subframe pitch buffer Q6 */ - const Word16 coder_type, /* i : coder_type */ - const Word16 BER_detect, /* i : BER detect flag */ - const Word16 disable_hpf /* i : flag to diabled HPF */ + const Word16 L_frame, /* i : frame length */ + PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ + Word16 *psf_lp_noise, /* i : Long term noise Q8 */ + const Word16 tmp_noise, /* i : noise energy Q0 */ + Word16 *Synth, /* i : 12k8 synthesis Qsyn */ + const Word16 *Aq, /* i : LP filter coefficient Q12 */ + const Word16 *Pitch_buf, /* i : Fractionnal subframe pitch buffer Q6 */ + const Word16 coder_type, /* i : coder_type */ + const Word16 BER_detect, /* i : BER detect flag */ + const Word16 disable_hpf /* i : flag to diabled HPF */ ) { Word16 i, j, Post_G1, Post_G2, Gain_factor; Word16 T0_first, *Pf_in; const Word16 *p_Aq; - Word16 pf_in_buffer[M+L_FRAME16k]; + Word16 pf_in_buffer[M + L_FRAME16k]; IF( BER_detect == 0 ) { /* update long-term background noise energy during inactive frames */ - IF( EQ_16(coder_type,INACTIVE)) + IF( EQ_16( coder_type, INACTIVE ) ) { - *psf_lp_noise = round_fx(L_mac(L_mult(31130, *psf_lp_noise), 26214 /*0.05 Q19*/, shl(tmp_noise,4))); /*Q8*Q15 + Q19*Q4 -> Q8 */ + *psf_lp_noise = round_fx( L_mac( L_mult( 31130, *psf_lp_noise ), 26214 /*0.05 Q19*/, shl( tmp_noise, 4 ) ) ); /*Q8*Q15 + Q19*Q4 -> Q8 */ } } modify_pst_param_fx( *psf_lp_noise, &Post_G1, &Post_G2, coder_type, &Gain_factor ); - if(hPFstat->reset) + if ( hPFstat->reset ) { - set16_fx(hPFstat->mem_res2, 0, DECMEM_RES2); - Copy( &Synth[L_frame-L_SYN_MEM], hPFstat->mem_pf_in, L_SYN_MEM); - Copy( &Synth[L_frame-L_SYN_MEM], hPFstat->mem_stp, L_SYN_MEM ); + set16_fx( hPFstat->mem_res2, 0, DECMEM_RES2 ); + Copy( &Synth[L_frame - L_SYN_MEM], hPFstat->mem_pf_in, L_SYN_MEM ); + Copy( &Synth[L_frame - L_SYN_MEM], hPFstat->mem_stp, L_SYN_MEM ); hPFstat->gain_prec = 16384; move16(); hPFstat->reset = 0; @@ -125,11 +124,11 @@ void nb_post_filt_fx( return; } Pf_in = &pf_in_buffer[M]; - Copy( hPFstat->mem_pf_in+L_SYN_MEM-M, &Pf_in[-M], M ); + Copy( hPFstat->mem_pf_in + L_SYN_MEM - M, &Pf_in[-M], M ); Copy( Synth, Pf_in, L_frame ); Copy( &Synth[L_frame - L_SYN_MEM], hPFstat->mem_pf_in, L_SYN_MEM ); /* deactivation of the post filter in case of AUDIO because it causes problems to singing sequences */ - if( EQ_16(coder_type,AUDIO)) + if ( EQ_16( coder_type, AUDIO ) ) { Post_G1 = 32767; move16(); @@ -145,14 +144,14 @@ void nb_post_filt_fx( move16(); j = 0; move16(); - FOR (i = 0; i < L_frame; i += L_SUBFR) + FOR( i = 0; i < L_frame; i += L_SUBFR ) { T0_first = Pitch_buf[j]; Dec_postfilt_fx( hPFstat, T0_first, &Pf_in[i], p_Aq, &Synth[i], Post_G1, Post_G2, Gain_factor, disable_hpf ); - p_Aq += (M+1); - j = add(j,1); + p_Aq += ( M + 1 ); + j = add( j, 1 ); } @@ -183,21 +182,20 @@ void nb_post_filt_fx( * 2. search around best integer with fract. delays (1/8) *----------------------------------------------------------------------------*/ static void Dec_postfilt_fx( - PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ - const Word16 t0, /* i : pitch delay given by coder */ - const Word16 * signal_ptr, /* i : input signal (pointer to current subframe */ - const Word16 * coeff, /* i : LPC coefficients for current subframe */ - Word16 * sig_out, /* o : postfiltered output */ - const Word16 gamma1, /* i : short term postfilt. den. weighting factor */ - const Word16 gamma2, /* i : short term postfilt. num. weighting factor */ - const Word16 Gain_factor, /* i : Gain Factor (Q15) */ - const Word16 disable_hpf -) + PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ + const Word16 t0, /* i : pitch delay given by coder */ + const Word16 *signal_ptr, /* i : input signal (pointer to current subframe */ + const Word16 *coeff, /* i : LPC coefficients for current subframe */ + Word16 *sig_out, /* o : postfiltered output */ + const Word16 gamma1, /* i : short term postfilt. den. weighting factor */ + const Word16 gamma2, /* i : short term postfilt. num. weighting factor */ + const Word16 Gain_factor, /* i : Gain Factor (Q15) */ + const Word16 disable_hpf ) { /* Local variables and arrays */ - Word16 apond1[M+1]; /* s.t. denominator coeff. */ + Word16 apond1[M + 1]; /* s.t. denominator coeff. */ Word16 apond2[LONG_H_ST]; - Word16 sig_ltp[L_SUBFR+1]; /* H0 output signal */ + Word16 sig_ltp[L_SUBFR + 1]; /* H0 output signal */ Word16 res2[SIZ_RES2]; Word16 *sig_ltp_ptr; @@ -210,26 +208,26 @@ static void Dec_postfilt_fx( /* Init pointers and restore memories */ res2_ptr = res2 + DECMEM_RES2; ptr_mem_stp = hPFstat->mem_stp + L_SYN_MEM - 1; - Copy(hPFstat->mem_res2, res2, DECMEM_RES2); + Copy( hPFstat->mem_res2, res2, DECMEM_RES2 ); /* Compute weighted LPC coefficients */ - weight_a_fx(coeff, apond1, gamma1, M); - weight_a_fx(coeff, apond2, gamma2, M); - set16_fx(&apond2[M+1], 0, LONG_H_ST-(M+1)); + weight_a_fx( coeff, apond1, gamma1, M ); + weight_a_fx( coeff, apond2, gamma2, M ); + set16_fx( &apond2[M + 1], 0, LONG_H_ST - ( M + 1 ) ); /* Compute A(gamma2) residual */ - Residu3_fx(apond2, signal_ptr, res2_ptr, L_SUBFR, 1); + Residu3_fx( apond2, signal_ptr, res2_ptr, L_SUBFR, 1 ); /* Harmonic filtering */ sig_ltp_ptr = sig_ltp + 1; - IF (disable_hpf == 0) + IF( disable_hpf == 0 ) { pst_ltp_fx( t0, res2_ptr, sig_ltp_ptr, Gain_factor ); } ELSE { - Copy(res2_ptr, sig_ltp_ptr, L_SUBFR); + Copy( res2_ptr, sig_ltp_ptr, L_SUBFR ); } /* Save last output of 1/A(gamma1) */ @@ -238,19 +236,19 @@ static void Dec_postfilt_fx( move16(); /* Controls short term pst filter gain and compute parcor0 */ - calc_st_filt_local_fx(apond2, apond1, &parcor0, sig_ltp_ptr, hPFstat->mem_zero ); + calc_st_filt_local_fx( apond2, apond1, &parcor0, sig_ltp_ptr, hPFstat->mem_zero ); - E_UTIL_synthesis(1, apond1, sig_ltp_ptr, sig_ltp_ptr, L_SUBFR, hPFstat->mem_stp+L_SYN_MEM-M, 0, M); - Copy( sig_ltp_ptr+L_SUBFR-L_SYN_MEM, hPFstat->mem_stp, L_SYN_MEM ); + E_UTIL_synthesis( 1, apond1, sig_ltp_ptr, sig_ltp_ptr, L_SUBFR, hPFstat->mem_stp + L_SYN_MEM - M, 0, M ); + Copy( sig_ltp_ptr + L_SUBFR - L_SYN_MEM, hPFstat->mem_stp, L_SYN_MEM ); /* Tilt filtering */ - Filt_mu_fx(sig_ltp, sig_out, parcor0, L_SUBFR); + Filt_mu_fx( sig_ltp, sig_out, parcor0, L_SUBFR ); /* Gain control */ - scale_st_fx(signal_ptr, sig_out, &hPFstat->gain_prec, L_SUBFR); + scale_st_fx( signal_ptr, sig_out, &hPFstat->gain_prec, L_SUBFR ); /* Update for next subframe */ - Copy(&res2[L_SUBFR], hPFstat->mem_res2, DECMEM_RES2); + Copy( &res2[L_SUBFR], hPFstat->mem_res2, DECMEM_RES2 ); return; @@ -262,14 +260,14 @@ static void Dec_postfilt_fx( * Main routine to perform formant post filtering *--------------------------------------------------------------------------*/ void formant_post_filt_fx( - PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ - Word16 *synth_in, /* i : 12k8 synthesis */ - Word16 *Aq, /* i : LP filter coefficient */ - Word16 *synth_out, /* i/o: input signal */ + PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ + Word16 *synth_in, /* i : 12k8 synthesis */ + Word16 *Aq, /* i : LP filter coefficient */ + Word16 *synth_out, /* i/o: input signal */ Word16 L_frame, - Word32 lp_noise, /* (i) : background noise energy (15Q16) */ - Word32 brate, /* (i) : bit-rate */ - const Word16 off_flag /* i : off flag */ + Word32 lp_noise, /* (i) : background noise energy (15Q16) */ + Word32 brate, /* (i) : bit-rate */ + const Word16 off_flag /* i : off flag */ ) { Word16 i_subfr; @@ -278,85 +276,85 @@ void formant_post_filt_fx( /*default parameter for noisy speech and high bit-rates*/ - IF (EQ_16(L_frame, L_FRAME)) + IF( EQ_16( L_frame, L_FRAME ) ) { - post_G2 = 22938/*0.7f Q15*/; + post_G2 = 22938 /*0.7f Q15*/; move16(); - IF (LT_32(lp_noise, LP_NOISE_THRESH)) + IF( LT_32( lp_noise, LP_NOISE_THRESH ) ) { /*Clean speech*/ - IF (LT_32(brate, ACELP_13k20)) + IF( LT_32( brate, ACELP_13k20 ) ) { /*Low rates*/ - post_G1 = 26214/*0.8f Q15*/; + post_G1 = 26214 /*0.8f Q15*/; move16(); } - ELSE IF (LT_32(brate, ACELP_24k40)) + ELSE IF( LT_32( brate, ACELP_24k40 ) ) { /*Low rates*/ - post_G1 = 24576/*0.75f Q15*/; + post_G1 = 24576 /*0.75f Q15*/; move16(); } ELSE { - post_G1 = 23593/*0.72f Q15*/; + post_G1 = 23593 /*0.72f Q15*/; move16(); } } - ELSE /*Noisy speech*/ + ELSE /*Noisy speech*/ { - post_G1 = 22938/*0.7f Q15*/; + post_G1 = 22938 /*0.7f Q15*/; move16(); - if (LT_32(brate, ACELP_15k85)) + if ( LT_32( brate, ACELP_15k85 ) ) { /*Low rates*/ - post_G1 = 24576/*0.75f Q15*/; + post_G1 = 24576 /*0.75f Q15*/; move16(); } } } ELSE { - post_G2 = 24904/*0.76f Q15*/; + post_G2 = 24904 /*0.76f Q15*/; move16(); test(); - IF (GE_32(lp_noise, LP_NOISE_THRESH)) + IF( GE_32( lp_noise, LP_NOISE_THRESH ) ) { - post_G1 = 24904/*0.76f Q15*/; + post_G1 = 24904 /*0.76f Q15*/; } - ELSE IF (EQ_32(brate, ACELP_13k20)) + ELSE IF( EQ_32( brate, ACELP_13k20 ) ) { - post_G1 = 26870/*0.82f Q15*/; + post_G1 = 26870 /*0.82f Q15*/; move16(); } - ELSE IF (EQ_32(brate, ACELP_16k40)) + ELSE IF( EQ_32( brate, ACELP_16k40 ) ) { - post_G1 = 26214/*0.80f Q15*/; + post_G1 = 26214 /*0.80f Q15*/; move16(); } - ELSE IF (EQ_32(brate, ACELP_24k40)||EQ_32(brate,ACELP_32k)) + ELSE IF( EQ_32( brate, ACELP_24k40 ) || EQ_32( brate, ACELP_32k ) ) { - post_G1 = 25559/*0.78f Q15*/; + post_G1 = 25559 /*0.78f Q15*/; move16(); } ELSE { - post_G1 = 24904/*0.76f Q15*/; + post_G1 = 24904 /*0.76f Q15*/; move16(); } } /* Switch off post-filter */ - if( off_flag != 0 ) + if ( off_flag != 0 ) { post_G1 = post_G2; move16(); } /* Reset post filter */ - if( hPFstat->reset != 0 ) + if ( hPFstat->reset != 0 ) { post_G1 = MAX16B; move16(); @@ -364,27 +362,26 @@ void formant_post_filt_fx( move16(); hPFstat->reset = 0; move16(); - Copy( &synth_in[L_frame-L_SYN_MEM], hPFstat->mem_pf_in, L_SYN_MEM); - Copy( &synth_in[L_frame-L_SYN_MEM], hPFstat->mem_stp, L_SYN_MEM ); + Copy( &synth_in[L_frame - L_SYN_MEM], hPFstat->mem_pf_in, L_SYN_MEM ); + Copy( &synth_in[L_frame - L_SYN_MEM], hPFstat->mem_stp, L_SYN_MEM ); hPFstat->gain_prec = 16384; move16(); - Copy( synth_in,synth_out, L_frame ); + Copy( synth_in, synth_out, L_frame ); return; } /* input memory*/ - Copy( hPFstat->mem_pf_in, synth_in-L_SYN_MEM, L_SYN_MEM); - Copy( &synth_in[L_frame-L_SYN_MEM], hPFstat->mem_pf_in, L_SYN_MEM); + Copy( hPFstat->mem_pf_in, synth_in - L_SYN_MEM, L_SYN_MEM ); + Copy( &synth_in[L_frame - L_SYN_MEM], hPFstat->mem_pf_in, L_SYN_MEM ); move16(); p_Aq = Aq; - FOR (i_subfr = 0; i_subfr < L_frame; i_subfr += L_SUBFR ) + FOR( i_subfr = 0; i_subfr < L_frame; i_subfr += L_SUBFR ) { - Dec_formant_postfilt_fx(hPFstat, &synth_in[i_subfr], p_Aq, &synth_out[i_subfr], post_G1, post_G2 ); - p_Aq += (M+1); + Dec_formant_postfilt_fx( hPFstat, &synth_in[i_subfr], p_Aq, &synth_out[i_subfr], post_G1, post_G2 ); + p_Aq += ( M + 1 ); } - } #ifdef IVAS_FLOAT_FIXED @@ -529,79 +526,79 @@ void formant_post_filt_ivas_fx( * gamma3 = gamma3_minus if k1<0, gamma3_plus if k1>0 *----------------------------------------------------------------------------*/ static void Dec_formant_postfilt_fx( - PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ - Word16 *signal_ptr, /* i : input signal (pointer to current subframe */ - Word16 *coeff, /* i : LPC coefficients for current subframe */ - Word16 *sig_out, /* o : postfiltered output */ - Word16 gamma1, /* i : short term postfilt. den. weighting factor*/ - Word16 gamma2 /* i : short term postfilt. num. weighting factor*/ + PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ + Word16 *signal_ptr, /* i : input signal (pointer to current subframe */ + Word16 *coeff, /* i : LPC coefficients for current subframe */ + Word16 *sig_out, /* o : postfiltered output */ + Word16 gamma1, /* i : short term postfilt. den. weighting factor*/ + Word16 gamma2 /* i : short term postfilt. num. weighting factor*/ ) { /* Local variables and arrays */ - Word16 apond1[M+1]; /* s.t. denominator coeff. */ + Word16 apond1[M + 1]; /* s.t. denominator coeff. */ Word16 apond2[LONG_H_ST]; Word16 res2[L_SUBFR]; - Word16 resynth[L_SUBFR+1]; + Word16 resynth[L_SUBFR + 1]; Word16 parcor0; Word16 i, max; Word16 scale_down; /* Compute weighted LPC coefficients */ - weight_a_fx(coeff, apond1, gamma1, M); - weight_a_fx(coeff, apond2, gamma2, M); - set16_fx(&apond2[M+1], 0, LONG_H_ST-(M+1)); + weight_a_fx( coeff, apond1, gamma1, M ); + weight_a_fx( coeff, apond2, gamma2, M ); + set16_fx( &apond2[M + 1], 0, LONG_H_ST - ( M + 1 ) ); - max = abs_s(signal_ptr[0]); - FOR (i = 1; i < L_SUBFR; i++) + max = abs_s( signal_ptr[0] ); + FOR( i = 1; i < L_SUBFR; i++ ) { - max = s_max(max, abs_s(signal_ptr[i])); + max = s_max( max, abs_s( signal_ptr[i] ) ); } scale_down = 0; move16(); - if (GT_16(max, 16384)) + if ( GT_16( max, 16384 ) ) { scale_down = 1; move16(); } /* Compute A(gamma2) residual */ - IF (!scale_down) + IF( !scale_down ) { - Residu3_fx(apond2, signal_ptr, res2, L_SUBFR, 1); + Residu3_fx( apond2, signal_ptr, res2, L_SUBFR, 1 ); } ELSE { - Residu3_fx(apond2, signal_ptr, res2, L_SUBFR, 0); - Scale_sig(hPFstat->mem_stp, L_SYN_MEM, -1); + Residu3_fx( apond2, signal_ptr, res2, L_SUBFR, 0 ); + Scale_sig( hPFstat->mem_stp, L_SYN_MEM, -1 ); } /* Controls short term pst filter gain and compute parcor0 */ - calc_st_filt_local_fx(apond2, apond1, &parcor0, res2, hPFstat->mem_zero ); + calc_st_filt_local_fx( apond2, apond1, &parcor0, res2, hPFstat->mem_zero ); /* 1/A(gamma1) filtering, mem_stp is updated */ - resynth[0] = *(hPFstat->mem_stp + sub(L_SYN_MEM, 1)); + resynth[0] = *( hPFstat->mem_stp + sub( L_SYN_MEM, 1 ) ); move16(); - E_UTIL_synthesis(1, apond1, res2, &(resynth[1]), L_SUBFR, hPFstat->mem_stp+L_SYN_MEM-M, 0, M); + E_UTIL_synthesis( 1, apond1, res2, &( resynth[1] ), L_SUBFR, hPFstat->mem_stp + L_SYN_MEM - M, 0, M ); - IF (!scale_down) + IF( !scale_down ) { - Copy( &(resynth[1])+L_SUBFR-L_SYN_MEM, hPFstat->mem_stp, L_SYN_MEM ); + Copy( &( resynth[1] ) + L_SUBFR - L_SYN_MEM, hPFstat->mem_stp, L_SYN_MEM ); } ELSE { - Copy_Scale_sig( &(resynth[1])+L_SUBFR-L_SYN_MEM, hPFstat->mem_stp, L_SYN_MEM, 1 ); + Copy_Scale_sig( &( resynth[1] ) + L_SUBFR - L_SYN_MEM, hPFstat->mem_stp, L_SYN_MEM, 1 ); } /* Tilt filtering */ - Filt_mu_fx(resynth, sig_out, parcor0, L_SUBFR); - IF (scale_down) + Filt_mu_fx( resynth, sig_out, parcor0, L_SUBFR ); + IF( scale_down ) { - Scale_sig(sig_out, L_SUBFR, 1); + Scale_sig( sig_out, L_SUBFR, 1 ); } /* Gain control */ - scale_st_fx(signal_ptr, sig_out, &hPFstat->gain_prec, L_SUBFR); + scale_st_fx( signal_ptr, sig_out, &hPFstat->gain_prec, L_SUBFR ); return; @@ -609,16 +606,16 @@ static void Dec_formant_postfilt_fx( #ifdef IVAS_FLOAT_FIXED static void Dec_formant_postfilt_ivas_fx( - PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ - Word16 *signal_ptr, /* i : input signal (pointer to current subframe */ - Word16 *coeff, /* i : LPC coefficients for current subframe */ - Word16 *sig_out, /* o : postfiltered output */ - Word16 gamma1, /* i : short term postfilt. den. weighting factor*/ - Word16 gamma2 /* i : short term postfilt. num. weighting factor*/ + PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ + Word16 *signal_ptr, /* i : input signal (pointer to current subframe */ + Word16 *coeff, /* i : LPC coefficients for current subframe */ + Word16 *sig_out, /* o : postfiltered output */ + Word16 gamma1, /* i : short term postfilt. den. weighting factor*/ + Word16 gamma2 /* i : short term postfilt. num. weighting factor*/ ) { /* Local variables and arrays */ - Word16 apond1[M + 1]; /* s.t. denominator coeff. */ + Word16 apond1[M + 1]; /* s.t. denominator coeff. */ Word16 apond2[LONG_H_ST]; Word16 res2[L_SUBFR]; Word16 resynth[L_SUBFR + 1]; @@ -627,61 +624,61 @@ static void Dec_formant_postfilt_ivas_fx( Word16 scale_down; /* Compute weighted LPC coefficients */ - weight_a_fx(coeff, apond1, gamma1, M); - weight_a_fx(coeff, apond2, gamma2, M); - set16_fx(&apond2[M + 1], 0, LONG_H_ST - (M + 1)); + weight_a_fx( coeff, apond1, gamma1, M ); + weight_a_fx( coeff, apond2, gamma2, M ); + set16_fx( &apond2[M + 1], 0, LONG_H_ST - ( M + 1 ) ); - max = abs_s(signal_ptr[0]); - FOR(i = 1; i < L_SUBFR; i++) + max = abs_s( signal_ptr[0] ); + FOR( i = 1; i < L_SUBFR; i++ ) { - max = s_max(max, abs_s(signal_ptr[i])); + max = s_max( max, abs_s( signal_ptr[i] ) ); } scale_down = 0; move16(); - if (GT_16(max, 16384)) + if ( GT_16( max, 16384 ) ) { scale_down = 1; move16(); } /* Compute A(gamma2) residual */ - IF(!scale_down) + IF( !scale_down ) { - Residu3_fx(apond2, signal_ptr, res2, L_SUBFR, 1); + Residu3_fx( apond2, signal_ptr, res2, L_SUBFR, 1 ); } ELSE { - Residu3_fx(apond2, signal_ptr, res2, L_SUBFR, 0); - Scale_sig(hPFstat->mem_stp, L_SYN_MEM, -1); + Residu3_fx( apond2, signal_ptr, res2, L_SUBFR, 0 ); + Scale_sig( hPFstat->mem_stp, L_SYN_MEM, -1 ); } - /* Controls short term pst filter gain and compute parcor0 */ - calc_st_filt_ivas_fx(apond2, apond1, &parcor0, res2, hPFstat->mem_zero , -1 ); + /* Controls short term pst filter gain and compute parcor0 */ + calc_st_filt_ivas_fx( apond2, apond1, &parcor0, res2, hPFstat->mem_zero, -1 ); /* 1/A(gamma1) filtering, mem_stp is updated */ - resynth[0] = *(hPFstat->mem_stp + sub(L_SYN_MEM, 1)); + resynth[0] = *( hPFstat->mem_stp + sub( L_SYN_MEM, 1 ) ); move16(); - E_UTIL_synthesis(1, apond1, res2, &(resynth[1]), L_SUBFR, hPFstat->mem_stp + L_SYN_MEM - M, 0, M); + E_UTIL_synthesis( 1, apond1, res2, &( resynth[1] ), L_SUBFR, hPFstat->mem_stp + L_SYN_MEM - M, 0, M ); - IF(!scale_down) + IF( !scale_down ) { - Copy(&(resynth[1]) + L_SUBFR - L_SYN_MEM, hPFstat->mem_stp, L_SYN_MEM); + Copy( &( resynth[1] ) + L_SUBFR - L_SYN_MEM, hPFstat->mem_stp, L_SYN_MEM ); } ELSE { - Copy_Scale_sig(&(resynth[1]) + L_SUBFR - L_SYN_MEM, hPFstat->mem_stp, L_SYN_MEM, 1); + Copy_Scale_sig( &( resynth[1] ) + L_SUBFR - L_SYN_MEM, hPFstat->mem_stp, L_SYN_MEM, 1 ); } - /* Tilt filtering */ - Filt_mu_ivas_fx(resynth, sig_out, parcor0, L_SUBFR , -1); - IF(scale_down) + /* Tilt filtering */ + Filt_mu_ivas_fx( resynth, sig_out, parcor0, L_SUBFR, -1 ); + IF( scale_down ) { - Scale_sig(sig_out, L_SUBFR, 1); + Scale_sig( sig_out, L_SUBFR, 1 ); } /* Gain control */ - scale_st_fx(signal_ptr, sig_out, &hPFstat->gain_prec, L_SUBFR); + scale_st_fx( signal_ptr, sig_out, &hPFstat->gain_prec, L_SUBFR ); return; @@ -695,11 +692,11 @@ static void Dec_formant_postfilt_ivas_fx( *-----------------------------------------------------------------------------------*/ static void modify_pst_param_fx( - const Word16 lp_noise, /* i : Long term noise energy Q8 */ - Word16 *g1, /* o : Gamma1 used in post filter Q15 */ - Word16 *g2, /* o : Gamma1 used in post filter Q15 */ - const Word16 coder_type, /* i : Vad information decoded in UV frame */ - Word16 *gain_factor /* o : Gain factor applied in post filtering */ + const Word16 lp_noise, /* i : Long term noise energy Q8 */ + Word16 *g1, /* o : Gamma1 used in post filter Q15 */ + Word16 *g2, /* o : Gamma1 used in post filter Q15 */ + const Word16 coder_type, /* i : Vad information decoded in UV frame */ + Word16 *gain_factor /* o : Gain factor applied in post filtering */ ) { Word16 tmp; @@ -711,30 +708,30 @@ static void modify_pst_param_fx( test(); - IF( NE_16(coder_type,INACTIVE)&<_16(lp_noise,LP_NOISE_THR_FX)) + IF( NE_16( coder_type, INACTIVE ) && LT_16( lp_noise, LP_NOISE_THR_FX ) ) { #ifdef BASOP_NOGLOB - lp_noiseQ12 = shl_o(lp_noise, 4, &Overflow); /* to go from Q8 to Q12 */ + lp_noiseQ12 = shl_o( lp_noise, 4, &Overflow ); /* to go from Q8 to Q12 */ #else - lp_noiseQ12 = shl(lp_noise, 4); /* to go from Q8 to Q12 */ + lp_noiseQ12 = shl( lp_noise, 4 ); /* to go from Q8 to Q12 */ #endif /* ftmp = lp_noise*BG1_FX + CG1_FX */ - tmp = mac_r(CG1_FX*65536L, lp_noiseQ12, BG1_FX*8); /* x8 to go from Q12 to Q15 */ - tmp = s_min(tmp, POST_G1_FX ); - tmp = s_max(tmp, GAMMA1_PST12K_MIN_FX ); + tmp = mac_r( CG1_FX * 65536L, lp_noiseQ12, BG1_FX * 8 ); /* x8 to go from Q12 to Q15 */ + tmp = s_min( tmp, POST_G1_FX ); + tmp = s_max( tmp, GAMMA1_PST12K_MIN_FX ); *g1 = tmp; move16(); /* ftmp = lp_noise*BG2_FX + CG2_FX */ - L_tmp = L_mac0(CG2_FX/2*65536L, lp_noiseQ12, BG2_FX*8);/* L_mac0 and /2 to go from Q12 to Q14 */ + L_tmp = L_mac0( CG2_FX / 2 * 65536L, lp_noiseQ12, BG2_FX * 8 ); /* L_mac0 and /2 to go from Q12 to Q14 */ /* we go to Q30 to avoid overflow CG2_FX*/ - L_tmp = L_min(L_tmp, POST_G2_FX*65536L/2); /* /2 because L_tmp is Q30 */ - L_tmp = L_max(L_tmp, GAMMA2_PST12K_MIN_FX*65536L/2); + L_tmp = L_min( L_tmp, POST_G2_FX * 65536L / 2 ); /* /2 because L_tmp is Q30 */ + L_tmp = L_max( L_tmp, GAMMA2_PST12K_MIN_FX * 65536L / 2 ); - *g2 = extract_h(L_shl(L_tmp, 1)); /* Q30=>Q31=>Q15 */ + *g2 = extract_h( L_shl( L_tmp, 1 ) ); /* Q30=>Q31=>Q15 */ } ELSE { @@ -746,12 +743,12 @@ static void modify_pst_param_fx( /* Set gain_factor of the harmonic filtering*/ /* ftmp = (lp_noise - K_LP_NOISE)*C_LP_NOISE_FX */ - L_tmp = L_mac(-CK_LP_NOISE_FX, lp_noise, C_LP_NOISE_FX); /* tmp is in Q24 (from Q8) */ + L_tmp = L_mac( -CK_LP_NOISE_FX, lp_noise, C_LP_NOISE_FX ); /* tmp is in Q24 (from Q8) */ - L_tmp = L_min(L_tmp, 64*65536L); /* 0.25 in Q24 */ - L_tmp = L_max(L_tmp, 0); + L_tmp = L_min( L_tmp, 64 * 65536L ); /* 0.25 in Q24 */ + L_tmp = L_max( L_tmp, 0 ); - *gain_factor = extract_h(L_shl(L_tmp, 7)); /* Q24=>Q31=>Q15 */ + *gain_factor = extract_h( L_shl( L_tmp, 7 ) ); /* Q24=>Q31=>Q15 */ return; @@ -763,10 +760,10 @@ static void modify_pst_param_fx( * Perform harmonic postfilter *----------------------------------------------------------------------------*/ static void pst_ltp_fx( - Word16 t0, /* i : pitch delay given by coder */ - Word16 * ptr_sig_in, /* i : postfilter i filter (residu2) */ - Word16 * ptr_sig_pst0, /* o : harmonic postfilter o */ - Word16 gain_factor /* i : Gain Factor (Q15) */ + Word16 t0, /* i : pitch delay given by coder */ + Word16 *ptr_sig_in, /* i : postfilter i filter (residu2) */ + Word16 *ptr_sig_pst0, /* o : harmonic postfilter o */ + Word16 gain_factor /* i : Gain Factor (Q15) */ ) { Word32 L_temp; @@ -793,47 +790,46 @@ static void pst_ltp_fx( #endif - /* i signal justified on 13 bits */ ptr_sig = ptr_sig_in - DECMEM_RES2; - nb_sh_sig = getScaleFactor16(ptr_sig, add(DECMEM_RES2, L_SUBFR)); - nb_sh_sig = sub(3, nb_sh_sig); + nb_sh_sig = getScaleFactor16( ptr_sig, add( DECMEM_RES2, L_SUBFR ) ); + nb_sh_sig = sub( 3, nb_sh_sig ); - FOR (i = 0; i < DECMEM_RES2+L_SUBFR; i++) + FOR( i = 0; i < DECMEM_RES2 + L_SUBFR; i++ ) { /* nb_sh_sig may be >0, <0 or =0 */ - sig_cadr[i] = shr(ptr_sig[i], nb_sh_sig); + sig_cadr[i] = shr( ptr_sig[i], nb_sh_sig ); move16(); } ptr_sig_cadr = sig_cadr + DECMEM_RES2; /* Sub optimal delay search */ - search_del_fx(t0, ptr_sig_cadr, <pdel, &phase, &num_gltp, &den_gltp, &sh_num, &sh_den, y_up, &off_yup); + search_del_fx( t0, ptr_sig_cadr, <pdel, &phase, &num_gltp, &den_gltp, &sh_num, &sh_den, y_up, &off_yup ); - IF (num_gltp == 0) + IF( num_gltp == 0 ) { - Copy(ptr_sig_in, ptr_sig_pst0, L_SUBFR); + Copy( ptr_sig_in, ptr_sig_pst0, L_SUBFR ); } ELSE { - IF (phase == 0) + IF( phase == 0 ) { ptr_y_up = ptr_sig_in - ltpdel; } ELSE { /* Filtering with long filter */ - compute_ltp_l_fx(ptr_sig_cadr, ltpdel, phase, ptr_sig_pst0, &num2_gltp, &den2_gltp, &sh_num2, &sh_den2); + compute_ltp_l_fx( ptr_sig_cadr, ltpdel, phase, ptr_sig_pst0, &num2_gltp, &den2_gltp, &sh_num2, &sh_den2 ); - IF (EQ_16(select_ltp_fx(num_gltp, den_gltp, sh_num, sh_den, num2_gltp, den2_gltp, sh_num2, sh_den2), 1)) + IF( EQ_16( select_ltp_fx( num_gltp, den_gltp, sh_num, sh_den, num2_gltp, den2_gltp, sh_num2, sh_den2 ), 1 ) ) { /* select short filter */ - temp = sub(phase, 1); - L_temp = L_mult0(temp, L_SUBFR + 1); - temp = extract_l(L_temp); - temp = add(temp, off_yup); + temp = sub( phase, 1 ); + L_temp = L_mult0( temp, L_SUBFR + 1 ); + temp = extract_l( L_temp ); + temp = add( temp, off_yup ); /* ptr_y_up = y_up + (phase-1) * (L_SUBFR+1) + off_yup */ ptr_y_up = y_up + temp; @@ -853,28 +849,28 @@ static void pst_ltp_fx( } /* rescale y_up */ - FOR (i = 0; i < L_SUBFR; i++) + FOR( i = 0; i < L_SUBFR; i++ ) { /* nb_sh_sig may be >0, <0 or =0 */ #ifdef BASOP_NOGLOB ptr_y_up[i] = shl_sat( ptr_y_up[i], nb_sh_sig ); #else - ptr_y_up[i] = shl(ptr_y_up[i], nb_sh_sig); + ptr_y_up[i] = shl( ptr_y_up[i], nb_sh_sig ); #endif move16(); } } - temp = sub(sh_num, sh_den); - IF (temp >= 0) + temp = sub( sh_num, sh_den ); + IF( temp >= 0 ) { - den_gltp = shr(den_gltp, temp); + den_gltp = shr( den_gltp, temp ); } ELSE { - num_gltp = shl(num_gltp, temp); /* >> (-temp) */ + num_gltp = shl( num_gltp, temp ); /* >> (-temp) */ } - IF (GE_16(num_gltp, den_gltp)) + IF( GE_16( num_gltp, den_gltp ) ) { /* beta bounded to 1 */ gain_plt = MIN_GPLT_FX; @@ -885,25 +881,24 @@ static void pst_ltp_fx( /* GAMMA_G = 0.5 */ /* gain_plt = den_gltp x 2**15 / (den_gltp + 0.5 num_gltp) */ /* shift 1 bit to avoid overflows in add */ - num_gltp = shr(num_gltp, 2); - den_gltp = shr(den_gltp, 1); - temp = add(den_gltp, num_gltp); - gain_plt = div_s(den_gltp, temp); /* Q15 */ + num_gltp = shr( num_gltp, 2 ); + den_gltp = shr( den_gltp, 1 ); + temp = add( den_gltp, num_gltp ); + gain_plt = div_s( den_gltp, temp ); /* Q15 */ } /* decrease gain in noisy condition */ /* gain_plt += (1.0f-gain_plt) * gain_factor */ /* gain_plt = gain_plt + gain_factor - gain_plt*gain_factor */ #ifdef BASOP_NOGLOB - gain_plt = msu_ro(L_msu(L_deposit_h(gain_plt), gain_plt, gain_factor), -32768, gain_factor, &Overflow); + gain_plt = msu_ro( L_msu( L_deposit_h( gain_plt ), gain_plt, gain_factor ), -32768, gain_factor, &Overflow ); #else - gain_plt = msu_r(L_msu(L_deposit_h(gain_plt), gain_plt, gain_factor), -32768, gain_factor); + gain_plt = msu_r( L_msu( L_deposit_h( gain_plt ), gain_plt, gain_factor ), -32768, gain_factor ); #endif /** filtering by H0(z) = harmonic filter **/ - filt_plt_fx(ptr_sig_in, ptr_y_up, ptr_sig_pst0, gain_plt); + filt_plt_fx( ptr_sig_in, ptr_y_up, ptr_sig_pst0, gain_plt ); } - } /*---------------------------------------------------------------------------- @@ -912,16 +907,16 @@ static void pst_ltp_fx( * Computes best (shortest) integer LTP delay + fine search *---------------------------------------------------------------------------*/ static void search_del_fx( - Word16 t0, /* i : pitch delay given by coder */ - Word16 * ptr_sig_in, /* i : i signal (with delay line) */ - Word16 * ltpdel, /* o : delay = *ltpdel - *phase / f_up */ - Word16 * phase, /* o : phase */ - Word16 * num_gltp, /* o : 16 bits numerator of LTP gain */ - Word16 * den_gltp, /* o : 16 bits denominator of LTP gain */ - Word16 * sh_num_gltp, /* o : justification for num_gltp */ - Word16 * sh_den_gltp, /* o : justification for den_gltp */ - Word16 * y_up, /* o : LT delayed signal if fract. delay */ - Word16 * off_yup /* o : offset in y_up */ + Word16 t0, /* i : pitch delay given by coder */ + Word16 *ptr_sig_in, /* i : i signal (with delay line) */ + Word16 *ltpdel, /* o : delay = *ltpdel - *phase / f_up */ + Word16 *phase, /* o : phase */ + Word16 *num_gltp, /* o : 16 bits numerator of LTP gain */ + Word16 *den_gltp, /* o : 16 bits denominator of LTP gain */ + Word16 *sh_num_gltp, /* o : justification for num_gltp */ + Word16 *sh_den_gltp, /* o : justification for den_gltp */ + Word16 *y_up, /* o : LT delayed signal if fract. delay */ + Word16 *off_yup /* o : offset in y_up */ ) { Word32 L_den0[F_UP_PST - 1]; @@ -952,16 +947,16 @@ static void search_del_fx( * Computes energy of current signal *-------------------------------------*/ - L_acc = L_mult(ptr_sig_in[0], ptr_sig_in[0]); - FOR(i = 1; i < L_SUBFR; i++) + L_acc = L_mult( ptr_sig_in[0], ptr_sig_in[0] ); + FOR( i = 1; i < L_SUBFR; i++ ) { #ifdef BASOP_NOGLOB - L_acc = L_mac_sat(L_acc, ptr_sig_in[i], ptr_sig_in[i]); + L_acc = L_mac_sat( L_acc, ptr_sig_in[i], ptr_sig_in[i] ); #else - L_acc = L_mac(L_acc, ptr_sig_in[i], ptr_sig_in[i]); + L_acc = L_mac( L_acc, ptr_sig_in[i], ptr_sig_in[i] ); #endif } - IF (L_acc == 0) + IF( L_acc == 0 ) { *num_gltp = 0; move16(); @@ -974,52 +969,52 @@ static void search_del_fx( return; } - sh_ener = sub(16, norm_l(L_acc)); + sh_ener = sub( 16, norm_l( L_acc ) ); /* save energy for final decision */ - sh_ener = s_max(0, sh_ener); - ener = extract_l(L_shr(L_acc, sh_ener)); + sh_ener = s_max( 0, sh_ener ); + ener = extract_l( L_shr( L_acc, sh_ener ) ); /*------------------------------------- * Selects best of 3 integer delays * Maximum of 3 numerators around t0 *-------------------------------------*/ - lambda = sub(t0, 1); + lambda = sub( t0, 1 ); ptr_sig_past = ptr_sig_in - lambda; - L_num_int = L_deposit_l(-1); + L_num_int = L_deposit_l( -1 ); /* initialization used only to suppress Microsoft Visual C++ warnings */ i_max = (Word16) 0; move16(); - FOR (i = 0; i < 3; i++) + FOR( i = 0; i < 3; i++ ) { - L_acc = L_mult(ptr_sig_in[0], ptr_sig_past[0]); - FOR (n = 1; n < L_SUBFR; n++) + L_acc = L_mult( ptr_sig_in[0], ptr_sig_past[0] ); + FOR( n = 1; n < L_SUBFR; n++ ) { #ifdef BASOP_NOGLOB - L_acc = L_mac_sat(L_acc, ptr_sig_in[n], ptr_sig_past[n]); + L_acc = L_mac_sat( L_acc, ptr_sig_in[n], ptr_sig_past[n] ); #else - L_acc = L_mac(L_acc, ptr_sig_in[n], ptr_sig_past[n]); + L_acc = L_mac( L_acc, ptr_sig_in[n], ptr_sig_past[n] ); #endif } - L_acc = L_max(L_acc, 0); + L_acc = L_max( L_acc, 0 ); #ifdef BASOP_NOGLOB - L_temp = L_sub_sat(L_acc, L_num_int); + L_temp = L_sub_sat( L_acc, L_num_int ); #else - L_temp = L_sub(L_acc, L_num_int); + L_temp = L_sub( L_acc, L_num_int ); #endif - if (L_temp > 0L) + if ( L_temp > 0L ) { i_max = (Word16) i; move16(); } - L_num_int = L_max(L_num_int, L_acc); + L_num_int = L_max( L_num_int, L_acc ); ptr_sig_past--; } - IF (L_num_int == 0) + IF( L_num_int == 0 ) { *num_gltp = 0; move16(); @@ -1034,22 +1029,22 @@ static void search_del_fx( } /* Compute den for i_max */ - lambda = add(lambda, (Word16) i_max); + lambda = add( lambda, (Word16) i_max ); ptr_sig_past = ptr_sig_in - lambda; temp = *ptr_sig_past++; move16(); - L_acc = L_mult(temp, temp); - FOR (i = 1; i < L_SUBFR; i++) + L_acc = L_mult( temp, temp ); + FOR( i = 1; i < L_SUBFR; i++ ) { temp = *ptr_sig_past++; move16(); #ifdef BASOP_NOGLOB - L_acc = L_mac_sat(L_acc, temp, temp); + L_acc = L_mac_sat( L_acc, temp, temp ); #else - L_acc = L_mac(L_acc, temp, temp); + L_acc = L_mac( L_acc, temp, temp ); #endif } - IF (L_acc == 0L) + IF( L_acc == 0L ) { *num_gltp = 0; move16(); @@ -1063,7 +1058,7 @@ static void search_del_fx( return; } L_den_int = L_acc; /* sets to 'L_acc' in 1 clock */ - move32(); + move32(); /*---------------------------------- * Select best phase around lambda @@ -1073,80 +1068,80 @@ static void search_del_fx( ptr_y_up = y_up; L_den_max = L_den_int; /* sets to 'L_acc' in 1 clock */ - move32(); + move32(); ptr_L_den0 = L_den0; ptr_L_den1 = L_den1; ptr_h = Tab_hup_s; - temp = sub(lambda, LH_UP_S - 1); + temp = sub( lambda, LH_UP_S - 1 ); ptr_sig_past0 = ptr_sig_in - temp; /* Loop on phase */ - FOR (phi = 1; phi < F_UP_PST; phi++) + FOR( phi = 1; phi < F_UP_PST; phi++ ) { /* Compute y_up for lambda+1 - phi/F_UP_PST */ /* and lambda - phi/F_UP_PST */ ptr_sig_past = ptr_sig_past0; - FOR (n = 0; n <= L_SUBFR; n++) + FOR( n = 0; n <= L_SUBFR; n++ ) { ptr1 = ptr_sig_past++; - L_acc = L_mult(ptr_h[0], ptr1[0]); - FOR (i = 1; i < LH2_S; i++) + L_acc = L_mult( ptr_h[0], ptr1[0] ); + FOR( i = 1; i < LH2_S; i++ ) { - L_acc = L_mac(L_acc, ptr_h[i], ptr1[-i]); + L_acc = L_mac( L_acc, ptr_h[i], ptr1[-i] ); } - ptr_y_up[n] = round_fx(L_acc); + ptr_y_up[n] = round_fx( L_acc ); } /* compute den0 (lambda+1) and den1 (lambda) */ /* part common to den0 and den1 */ - L_acc = L_mult(ptr_y_up[1], ptr_y_up[1]); - FOR (n = 2; n < L_SUBFR; n++) + L_acc = L_mult( ptr_y_up[1], ptr_y_up[1] ); + FOR( n = 2; n < L_SUBFR; n++ ) { #ifdef BASOP_NOGLOB - L_acc = L_mac_sat(L_acc, ptr_y_up[n], ptr_y_up[n]); + L_acc = L_mac_sat( L_acc, ptr_y_up[n], ptr_y_up[n] ); #else - L_acc = L_mac(L_acc, ptr_y_up[n], ptr_y_up[n]); + L_acc = L_mac( L_acc, ptr_y_up[n], ptr_y_up[n] ); #endif } L_temp0 = L_acc; /* sets to 'L_acc' in 1 clock (saved for den1) */ - move32(); + move32(); /* den0 */ #ifdef BASOP_NOGLOB - L_acc = L_mac_sat(L_acc, ptr_y_up[0], ptr_y_up[0]); + L_acc = L_mac_sat( L_acc, ptr_y_up[0], ptr_y_up[0] ); #else - L_acc = L_mac(L_acc, ptr_y_up[0], ptr_y_up[0]); + L_acc = L_mac( L_acc, ptr_y_up[0], ptr_y_up[0] ); #endif *ptr_L_den0 = L_acc; move32(); /* den1 */ #ifdef BASOP_NOGLOB - L_acc = L_mac_sat(L_temp0, ptr_y_up[L_SUBFR], ptr_y_up[L_SUBFR]); + L_acc = L_mac_sat( L_temp0, ptr_y_up[L_SUBFR], ptr_y_up[L_SUBFR] ); #else - L_acc = L_mac(L_temp0, ptr_y_up[L_SUBFR], ptr_y_up[L_SUBFR]); + L_acc = L_mac( L_temp0, ptr_y_up[L_SUBFR], ptr_y_up[L_SUBFR] ); #endif *ptr_L_den1 = L_acc; move32(); - IF (GT_16(abs_s(ptr_y_up[0]), abs_s(ptr_y_up[L_SUBFR]))) + IF( GT_16( abs_s( ptr_y_up[0] ), abs_s( ptr_y_up[L_SUBFR] ) ) ) { - L_den_max = L_max(*ptr_L_den0, L_den_max); + L_den_max = L_max( *ptr_L_den0, L_den_max ); } ELSE { - L_den_max = L_max(*ptr_L_den1, L_den_max); + L_den_max = L_max( *ptr_L_den1, L_den_max ); } ptr_L_den0++; ptr_L_den1++; - ptr_y_up += (L_SUBFR+1); + ptr_y_up += ( L_SUBFR + 1 ); ptr_h += LH2_S; } - IF (L_den_max == 0) + IF( L_den_max == 0 ) { *num_gltp = 0; move16(); @@ -1160,10 +1155,10 @@ static void search_del_fx( return; } - sh_den = sub(16, norm_l(L_den_max)); + sh_den = sub( 16, norm_l( L_den_max ) ); /* if sh_den <= 0 : dynamic between current frame */ /* and delay line too high */ - IF (sh_den <= 0) + IF( sh_den <= 0 ) { *num_gltp = 0; move16(); @@ -1181,7 +1176,7 @@ static void search_del_fx( /* sh_num = Max(sh_den, sh_ener) */ sh_num = sh_ener; move16(); - if (GE_16(sh_den, sh_ener)) + if ( GE_16( sh_den, sh_ener ) ) { sh_num = sh_den; move16(); @@ -1192,11 +1187,11 @@ static void search_del_fx( /* for non null phases */ /* Initialize with null phase */ - L_acc = L_shr(L_den_int, sh_den); /* sh_den > 0 */ - den_max = extract_l(L_acc); - L_acc = L_shr(L_num_int, sh_num); /* sh_num > 0 */ - num_max = extract_l(L_acc); - L_numsq_max = L_mult(num_max, num_max); + L_acc = L_shr( L_den_int, sh_den ); /* sh_den > 0 */ + den_max = extract_l( L_acc ); + L_acc = L_shr( L_num_int, sh_num ); /* sh_num > 0 */ + num_max = extract_l( L_acc ); + L_numsq_max = L_mult( num_max, num_max ); phi_max = 0; move16(); @@ -1213,35 +1208,35 @@ static void search_del_fx( /* degenerated seldom cases, switch off LT is OK */ /* Loop on phase */ - FOR (phi = 1; phi < F_UP_PST; phi++) + FOR( phi = 1; phi < F_UP_PST; phi++ ) { /* compute num for lambda+1 - phi/F_UP_PST */ - L_acc = L_mult(ptr_sig_in[0], ptr_y_up[0]); - FOR (n = 1; n < L_SUBFR; n++) + L_acc = L_mult( ptr_sig_in[0], ptr_y_up[0] ); + FOR( n = 1; n < L_SUBFR; n++ ) { #ifdef BASOP_NOGLOB - L_acc = L_mac_sat(L_acc, ptr_sig_in[n], ptr_y_up[n]); + L_acc = L_mac_sat( L_acc, ptr_sig_in[n], ptr_y_up[n] ); #else - L_acc = L_mac(L_acc, ptr_sig_in[n], ptr_y_up[n]); + L_acc = L_mac( L_acc, ptr_sig_in[n], ptr_y_up[n] ); #endif } - L_acc = L_shr(L_acc, sh_num); /* sh_num > 0 */ - L_acc = L_max(0, L_acc); - num = extract_l(L_acc); + L_acc = L_shr( L_acc, sh_num ); /* sh_num > 0 */ + L_acc = L_max( 0, L_acc ); + num = extract_l( L_acc ); /* selection if num**2/den0 max */ - L_temp1 = L_mult(num, num); - L_temp0 = Mpy_32_16_1(L_temp1, den_max); - L_acc = L_add(*ptr_L_den0++, 0); - L_acc = L_shr(L_acc, sh_den); /* sh_den > 0 */ - den0 = extract_l(L_acc); - L_temp = Msub_32_16(L_temp0, L_numsq_max, den0); - IF (L_temp > 0L) + L_temp1 = L_mult( num, num ); + L_temp0 = Mpy_32_16_1( L_temp1, den_max ); + L_acc = L_add( *ptr_L_den0++, 0 ); + L_acc = L_shr( L_acc, sh_den ); /* sh_den > 0 */ + den0 = extract_l( L_acc ); + L_temp = Msub_32_16( L_temp0, L_numsq_max, den0 ); + IF( L_temp > 0L ) { num_max = num; move16(); L_numsq_max = L_temp1; /* sets to 'L_temp1' in 1 clock */ - move32(); + move32(); den_max = den0; move16(); ioff = 0; @@ -1253,32 +1248,32 @@ static void search_del_fx( /* compute num for lambda - phi/F_UP_PST */ ptr_y_up++; - L_acc = L_mult(ptr_sig_in[0], ptr_y_up[0]); - FOR (n = 1; n < L_SUBFR; n++) + L_acc = L_mult( ptr_sig_in[0], ptr_y_up[0] ); + FOR( n = 1; n < L_SUBFR; n++ ) { #ifdef BASOP_NOGLOB - L_acc = L_mac_sat(L_acc, ptr_sig_in[n], ptr_y_up[n]); + L_acc = L_mac_sat( L_acc, ptr_sig_in[n], ptr_y_up[n] ); #else - L_acc = L_mac(L_acc, ptr_sig_in[n], ptr_y_up[n]); + L_acc = L_mac( L_acc, ptr_sig_in[n], ptr_y_up[n] ); #endif } - L_acc = L_shr(L_acc, sh_num); /* sh_num > 0 */ - L_acc = L_max(0, L_acc); - num = extract_l(L_acc); + L_acc = L_shr( L_acc, sh_num ); /* sh_num > 0 */ + L_acc = L_max( 0, L_acc ); + num = extract_l( L_acc ); /* selection if num**2/den1 max */ - L_temp1 = L_mult(num, num); - L_temp0 = Mpy_32_16_1(L_temp1, den_max); - L_acc = L_add(*ptr_L_den1++, 0); - L_acc = L_shr(L_acc, sh_den); /* sh_den > 0 */ - den1 = extract_l(L_acc); - L_temp = Msub_32_16(L_temp0, L_numsq_max, den1); - IF (L_temp > 0L) + L_temp1 = L_mult( num, num ); + L_temp0 = Mpy_32_16_1( L_temp1, den_max ); + L_acc = L_add( *ptr_L_den1++, 0 ); + L_acc = L_shr( L_acc, sh_den ); /* sh_den > 0 */ + den1 = extract_l( L_acc ); + L_temp = Msub_32_16( L_temp0, L_numsq_max, den1 ); + IF( L_temp > 0L ) { num_max = num; move16(); L_numsq_max = L_temp1; /* sets to 'L_temp1' in 1 clock */ - move32(); + move32(); den_max = den1; move16(); ioff = 1; @@ -1294,7 +1289,7 @@ static void search_del_fx( * test if normalized crit0[iopt] > THRESHCRIT *--------------------------------------------------*/ test(); - IF (num_max == 0 || LE_16(den_max, 1)) + IF( num_max == 0 || LE_16( den_max, 1 ) ) { *num_gltp = 0; move16(); @@ -1311,31 +1306,31 @@ static void search_del_fx( /* compare num**2 */ /* to ener * den * 0.5 */ /* (THRESHCRIT = 0.5) */ - L_temp1 = L_mult(den_max, ener); + L_temp1 = L_mult( den_max, ener ); /* temp = 2 * sh_num - sh_den - sh_ener + 1 */ /* 16 bits with no overflows */ - temp = shl(sh_num, 1); - temp = sub(temp, sh_den); - temp = sub(temp, sh_ener); - temp = add(temp, 1); - IF (temp < 0) + temp = shl( sh_num, 1 ); + temp = sub( temp, sh_den ); + temp = sub( temp, sh_ener ); + temp = add( temp, 1 ); + IF( temp < 0 ) { - temp = negate(temp); /* no overflow */ - L_numsq_max = L_shr(L_numsq_max, temp); + temp = negate( temp ); /* no overflow */ + L_numsq_max = L_shr( L_numsq_max, temp ); } ELSE { - if (temp > 0) + if ( temp > 0 ) { - L_temp1 = L_shr(L_temp1, temp); + L_temp1 = L_shr( L_temp1, temp ); } } - L_temp = L_sub(L_numsq_max, L_temp1); - IF (L_temp >= 0L) + L_temp = L_sub( L_numsq_max, L_temp1 ); + IF( L_temp >= 0L ) { - temp = add(lambda, 1); - *ltpdel = sub(temp, ioff); + temp = add( lambda, 1 ); + *ltpdel = sub( temp, ioff ); *off_yup = ioff; move16(); *phase = phi_max; @@ -1371,10 +1366,10 @@ static void search_del_fx( * Perform long term postfilter *----------------------------------------------------------------------------*/ static void filt_plt_fx( - Word16 * s_in, /* i : i signal with past */ - Word16 * s_ltp, /* i : filtered signal with gain 1 */ - Word16 * s_out, /* o : signal */ - Word16 gain_plt /* i : filter gain */ + Word16 *s_in, /* i : i signal with past */ + Word16 *s_ltp, /* i : filtered signal with gain 1 */ + Word16 *s_out, /* o : signal */ + Word16 gain_plt /* i : filter gain */ ) { @@ -1385,14 +1380,14 @@ static void filt_plt_fx( Word16 gain_plt_1; - gain_plt_1 = sub(32767, gain_plt); - gain_plt_1 = add(gain_plt_1, 1); /* 2**15 (1 - g) */ + gain_plt_1 = sub( 32767, gain_plt ); + gain_plt_1 = add( gain_plt_1, 1 ); /* 2**15 (1 - g) */ - FOR (n = 0; n < L_SUBFR; n++) + FOR( n = 0; n < L_SUBFR; n++ ) { /* s_out(n) = gain_plt x s_in(n) + gain_plt_1 x s_ltp(n) */ - L_acc = L_mult(gain_plt, s_in[n]); - s_out[n] = mac_r(L_acc, gain_plt_1, s_ltp[n]); + L_acc = L_mult( gain_plt, s_in[n] ); + s_out[n] = mac_r( L_acc, gain_plt_1, s_ltp[n] ); move16(); /* no overflow */ } @@ -1408,14 +1403,14 @@ static void filt_plt_fx( * with long interpolation filter *----------------------------------------------------------------------------*/ static void compute_ltp_l_fx( - Word16 * s_in, /* i/o: signal with past */ - Word16 ltpdel, /* i : delay factor */ - Word16 phase, /* i : phase factor */ - Word16 * y_up, /* i : delayed signal */ - Word16 * num, /* i : numerator of LTP gain */ - Word16 * den, /* i : denominator of LTP gain */ - Word16 * sh_num, /* i : justification factor of num */ - Word16 * sh_den /* i : justification factor of den */ + Word16 *s_in, /* i/o: signal with past */ + Word16 ltpdel, /* i : delay factor */ + Word16 phase, /* i : phase factor */ + Word16 *y_up, /* i : delayed signal */ + Word16 *num, /* i : numerator of LTP gain */ + Word16 *den, /* i : denominator of LTP gain */ + Word16 *sh_num, /* i : justification factor of num */ + Word16 *sh_den /* i : justification factor of den */ ) { Word32 L_acc; @@ -1424,33 +1419,33 @@ static void compute_ltp_l_fx( Word16 n, i; Word16 temp; - temp = sub(phase, 1); - temp = shl(temp, L2_LH2_L); + temp = sub( phase, 1 ); + temp = shl( temp, L2_LH2_L ); ptr_h = Tab_hup_l + temp; /* Tab_hup_l + LH2_L * (phase-1) */ - temp = sub(LH_UP_L, ltpdel); + temp = sub( LH_UP_L, ltpdel ); ptr2 = s_in + temp; /* Compute y_up */ - FOR (n = 0; n < L_SUBFR; n++) + FOR( n = 0; n < L_SUBFR; n++ ) { - L_acc = L_mult(ptr_h[0], *ptr2--); + L_acc = L_mult( ptr_h[0], *ptr2-- ); - FOR (i = 1; i < LH2_L; i++) + FOR( i = 1; i < LH2_L; i++ ) { - L_acc = L_mac(L_acc, ptr_h[i], *ptr2--); + L_acc = L_mac( L_acc, ptr_h[i], *ptr2-- ); } - y_up[n] = round_fx(L_acc); + y_up[n] = round_fx( L_acc ); ptr2 += LH2_L_P1; } /* Compute num */ - L_acc = L_mult(y_up[0], s_in[0]); - FOR (n = 1; n < L_SUBFR; n++) + L_acc = L_mult( y_up[0], s_in[0] ); + FOR( n = 1; n < L_SUBFR; n++ ) { - L_acc = L_mac(L_acc, y_up[n], s_in[n]); + L_acc = L_mac( L_acc, y_up[n], s_in[n] ); } - IF (L_acc < 0L) + IF( L_acc < 0L ) { *num = 0; move16(); @@ -1459,28 +1454,28 @@ static void compute_ltp_l_fx( } ELSE { - temp = sub(16, norm_l(L_acc)); - temp = s_max(temp, 0); - L_acc = L_shr(L_acc, temp); /* with temp >= 0 */ - *num = extract_l(L_acc); + temp = sub( 16, norm_l( L_acc ) ); + temp = s_max( temp, 0 ); + L_acc = L_shr( L_acc, temp ); /* with temp >= 0 */ + *num = extract_l( L_acc ); *sh_num = temp; move16(); } /* Compute den */ - L_acc = L_mult(y_up[0], y_up[0]); - FOR (n = 1; n < L_SUBFR; n++) + L_acc = L_mult( y_up[0], y_up[0] ); + FOR( n = 1; n < L_SUBFR; n++ ) { #ifdef BASOP_NOGLOB L_acc = L_mac_sat( L_acc, y_up[n], y_up[n] ); #else - L_acc = L_mac(L_acc, y_up[n], y_up[n]); + L_acc = L_mac( L_acc, y_up[n], y_up[n] ); #endif } - temp = sub(16, norm_l(L_acc)); - temp = s_max(temp, 0); - L_acc = L_shr(L_acc, temp); /* with temp >= 0 */ - *den = extract_l(L_acc); + temp = sub( 16, norm_l( L_acc ) ); + temp = s_max( temp, 0 ); + L_acc = L_shr( L_acc, temp ); /* with temp >= 0 */ + *den = extract_l( L_acc ); *sh_den = temp; move16(); @@ -1495,15 +1490,15 @@ static void compute_ltp_l_fx( * with gain1 = num1 * 2** sh_num1 / den1 * 2** sh_den1 * and gain2 = num2 * 2** sh_num2 / den2 * 2** sh_den2 *----------------------------------------------------------------------------*/ -static Word16 select_ltp_fx( /* o : 1 = 1st gain, 2 = 2nd gain */ - Word16 num1, /* i : numerator of gain1 */ - Word16 den1, /* i : denominator of gain1 */ - Word16 sh_num1, /* i : just. factor for num1 */ - Word16 sh_den1, /* i : just. factor for den1 */ - Word16 num2, /* i : numerator of gain2 */ - Word16 den2, /* i : denominator of gain2 */ - Word16 sh_num2, /* i : just. factor for num2 */ - Word16 sh_den2 /* i : just. factor for den2 */ +static Word16 select_ltp_fx( /* o : 1 = 1st gain, 2 = 2nd gain */ + Word16 num1, /* i : numerator of gain1 */ + Word16 den1, /* i : denominator of gain1 */ + Word16 sh_num1, /* i : just. factor for num1 */ + Word16 sh_den1, /* i : just. factor for den1 */ + Word16 num2, /* i : numerator of gain2 */ + Word16 den2, /* i : denominator of gain2 */ + Word16 sh_num2, /* i : just. factor for num2 */ + Word16 sh_den2 /* i : just. factor for den2 */ ) { Word32 L_temp1, L_temp2; @@ -1512,39 +1507,39 @@ static Word16 select_ltp_fx( /* o : 1 = 1st gain, 2 = 2nd gain */ Word16 temp1, temp2; - IF (den2 == 0) + IF( den2 == 0 ) { return 1; } /* compares criteria = num**2/den */ - L_temp1 = L_mult(num1, num1); - L_temp1 = Mpy_32_16_1(L_temp1, den2); + L_temp1 = L_mult( num1, num1 ); + L_temp1 = Mpy_32_16_1( L_temp1, den2 ); - L_temp2 = L_mult(num2, num2); - L_temp2 = Mpy_32_16_1(L_temp2, den1); + L_temp2 = L_mult( num2, num2 ); + L_temp2 = Mpy_32_16_1( L_temp2, den1 ); /* temp1 = sh_den2 + 2 * sh_num1 */ - temp1 = shl(sh_num1, 1); - temp1 = add(temp1, sh_den2); + temp1 = shl( sh_num1, 1 ); + temp1 = add( temp1, sh_den2 ); /* temp2 = sh_den1 + 2 * sh_num2; */ - temp2 = shl(sh_num2, 1); - temp2 = add(temp2, sh_den1); + temp2 = shl( sh_num2, 1 ); + temp2 = add( temp2, sh_den1 ); - temp2 = sub(temp2, temp1); - if (temp2 > 0) + temp2 = sub( temp2, temp1 ); + if ( temp2 > 0 ) { - L_temp1 = L_shr(L_temp1, temp2); /* temp2 > 0 */ + L_temp1 = L_shr( L_temp1, temp2 ); /* temp2 > 0 */ } - if (temp2 < 0) + if ( temp2 < 0 ) { - L_temp2 = L_shl(L_temp2, temp2); /* temp2 < 0 */ + L_temp2 = L_shl( L_temp2, temp2 ); /* temp2 < 0 */ } - L_temp = L_sub(L_temp2, L_temp1); + L_temp = L_sub( L_temp2, L_temp1 ); temp1 = 1; move16(); - if (L_temp > 0L) + if ( L_temp > 0L ) { temp1 = 2; move16(); @@ -1561,11 +1556,11 @@ static Word16 select_ltp_fx( /* o : 1 = 1st gain, 2 = 2nd gain */ * SUMn (abs (h[n])) and computes parcor0 *---------------------------------------------------------------------------- */ static void calc_st_filt_local_fx( - Word16 * apond2, /* i : coefficients of numerator */ - Word16 * apond1, /* i : coefficients of denominator */ - Word16 * parcor0, /* o : 1st parcor calcul. on composed filter */ - Word16 * sig_ltp_ptr, /* i/o: i of 1/A(gamma1) : scaled by 1/g0 */ - Word16 * mem_zero /* i : All zero memory */ + Word16 *apond2, /* i : coefficients of numerator */ + Word16 *apond1, /* i : coefficients of denominator */ + Word16 *parcor0, /* o : 1st parcor calcul. on composed filter */ + Word16 *sig_ltp_ptr, /* i/o: i of 1/A(gamma1) : scaled by 1/g0 */ + Word16 *mem_zero /* i : All zero memory */ ) { Word32 L_g0; @@ -1579,26 +1574,26 @@ static void calc_st_filt_local_fx( temp = sub( 2, norm_s( apond2[0] ) ); /* compute i.r. of composed filter apond2 / apond1 */ - E_UTIL_synthesis(temp, apond1, apond2, h, LONG_H_ST, mem_zero, 0, M); + E_UTIL_synthesis( temp, apond1, apond2, h, LONG_H_ST, mem_zero, 0, M ); /* compute 1st parcor */ - Calc_rc0_h(h, parcor0); + Calc_rc0_h( h, parcor0 ); /* compute g0 */ - L_g0 = L_mult0(1, abs_s(h[0])); - FOR (i = 1; i < LONG_H_ST; i++) + L_g0 = L_mult0( 1, abs_s( h[0] ) ); + FOR( i = 1; i < LONG_H_ST; i++ ) { - L_g0 = L_mac0(L_g0, 1, abs_s(h[i])); + L_g0 = L_mac0( L_g0, 1, abs_s( h[i] ) ); } - g0 = extract_h(L_shl(L_g0, 14)); + g0 = extract_h( L_shl( L_g0, 14 ) ); /* Scale signal i of 1/A(gamma1) */ - IF (GT_16(g0, 1024)) + IF( GT_16( g0, 1024 ) ) { - temp = div_s(1024, g0); /* temp = 2**15 / gain0 */ - FOR (i = 0; i < L_SUBFR; i++) + temp = div_s( 1024, g0 ); /* temp = 2**15 / gain0 */ + FOR( i = 0; i < L_SUBFR; i++ ) { - sig_ltp_ptr[i] = mult_r(sig_ltp_ptr[i], temp); + sig_ltp_ptr[i] = mult_r( sig_ltp_ptr[i], temp ); move16(); } } @@ -1609,12 +1604,12 @@ static void calc_st_filt_local_fx( #ifdef IVAS_FLOAT_FIXED static void calc_st_filt_ivas_fx( - Word16 * apond2, /* i : coefficients of numerator */ - Word16 * apond1, /* i : coefficients of denominator */ - Word16 * parcor0, /* o : 1st parcor calcul. on composed filter */ - Word16 * sig_ltp_ptr, /* i/o: i of 1/A(gamma1) : scaled by 1/g0 */ - Word16 * mem_zero, /* i : All zero memory */ - const Word16 extl /* i : extension layer info */ + Word16 *apond2, /* i : coefficients of numerator */ + Word16 *apond1, /* i : coefficients of denominator */ + Word16 *parcor0, /* o : 1st parcor calcul. on composed filter */ + Word16 *sig_ltp_ptr, /* i/o: i of 1/A(gamma1) : scaled by 1/g0 */ + Word16 *mem_zero, /* i : All zero memory */ + const Word16 extl /* i : extension layer info */ ) { Word32 L_g0; @@ -1625,35 +1620,36 @@ static void calc_st_filt_ivas_fx( Word16 i; - temp = sub(2, norm_s(apond2[0])); + temp = sub( 2, norm_s( apond2[0] ) ); /* compute i.r. of composed filter apond2 / apond1 */ - if (extl == SWB_TBE) + if ( extl == SWB_TBE ) { - E_UTIL_synthesis(temp, apond1, apond2, h, LONG_H_ST, mem_zero, 0, LPC_SHB_ORDER); + E_UTIL_synthesis( temp, apond1, apond2, h, LONG_H_ST, mem_zero, 0, LPC_SHB_ORDER ); } - else { - E_UTIL_synthesis(temp, apond1, apond2, h, LONG_H_ST, mem_zero, 0, M); + else + { + E_UTIL_synthesis( temp, apond1, apond2, h, LONG_H_ST, mem_zero, 0, M ); } /* compute 1st parcor */ - Calc_rc0_h(h, parcor0); + Calc_rc0_h( h, parcor0 ); /* compute g0 */ - L_g0 = L_mult0(1, abs_s(h[0])); - FOR(i = 1; i < LONG_H_ST; i++) + L_g0 = L_mult0( 1, abs_s( h[0] ) ); + FOR( i = 1; i < LONG_H_ST; i++ ) { - L_g0 = L_mac0(L_g0, 1, abs_s(h[i])); + L_g0 = L_mac0( L_g0, 1, abs_s( h[i] ) ); } - g0 = extract_h(L_shl(L_g0, 14)); + g0 = extract_h( L_shl( L_g0, 14 ) ); /* Scale signal i of 1/A(gamma1) */ - IF(GT_16(g0, 1024)) + IF( GT_16( g0, 1024 ) ) { - temp = div_s(1024, g0); /* temp = 2**15 / gain0 */ - FOR(i = 0; i < L_SUBFR; i++) + temp = div_s( 1024, g0 ); /* temp = 2**15 / gain0 */ + FOR( i = 0; i < L_SUBFR; i++ ) { - sig_ltp_ptr[i] = mult_r(sig_ltp_ptr[i], temp); + sig_ltp_ptr[i] = mult_r( sig_ltp_ptr[i], temp ); move16(); } } @@ -1669,10 +1665,10 @@ static void calc_st_filt_ivas_fx( * computes y[n] = (1/1-|mu|) (x[n]+mu*x[n-1]) *---------------------------------------------------------------------------*/ void Filt_mu_fx( - Word16 * sig_in, /* i : signal (beginning at sample -1) */ - Word16 * sig_out, /* o : signal with tilt */ - Word16 parcor0, /* i : parcor0 (mu = parcor0 * gamma3) */ - Word16 L_subfr /* i : the length of subframe */ + Word16 *sig_in, /* i : signal (beginning at sample -1) */ + Word16 *sig_out, /* o : signal with tilt */ + Word16 parcor0, /* i : parcor0 (mu = parcor0 * gamma3) */ + Word16 L_subfr /* i : the length of subframe */ ) { Word32 L_acc, L_temp, L_fact; @@ -1687,58 +1683,58 @@ void Filt_mu_fx( #endif - IF (parcor0 > 0) + IF( parcor0 > 0 ) { - mu = mult_r(parcor0, GAMMA3_PLUS_FX); + mu = mult_r( parcor0, GAMMA3_PLUS_FX ); /* GAMMA3_PLUS_FX < 0.5 */ sh_fact = 14; move16(); /* sh_fact */ fact = (Word16) 0x4000; - move16(); /* 2**sh_fact */ - L_fact = (Word32) L_deposit_l(0x2000); /* fact >> 1 */ + move16(); /* 2**sh_fact */ + L_fact = (Word32) L_deposit_l( 0x2000 ); /* fact >> 1 */ } ELSE { - mu = mult_r(parcor0, GAMMA3_MINUS_FX); + mu = mult_r( parcor0, GAMMA3_MINUS_FX ); /* GAMMA3_MINUS_FX < 0.9375 */ sh_fact = 11; move16(); /* sh_fact */ fact = (Word16) 0x0800; - move16(); /* 2**sh_fact */ - L_fact = (Word32) L_deposit_l(0x0400); /* fact >> 1 */ + move16(); /* 2**sh_fact */ + L_fact = (Word32) L_deposit_l( 0x0400 ); /* fact >> 1 */ } - temp = sub(1, abs_s(mu)); + temp = sub( 1, abs_s( mu ) ); BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB - mu2 = add_o(32767, temp, &Overflow); /* 2**15 (1 - |mu|) */ + mu2 = add_o( 32767, temp, &Overflow ); /* 2**15 (1 - |mu|) */ #else - mu2 = add(32767, temp); /* 2**15 (1 - |mu|) */ + mu2 = add( 32767, temp ); /* 2**15 (1 - |mu|) */ #endif BASOP_SATURATE_WARNING_ON_EVS; - ga = div_s(fact, mu2); /* 2**sh_fact / (1 - |mu|) */ + ga = div_s( fact, mu2 ); /* 2**sh_fact / (1 - |mu|) */ ptrs = sig_in; /* points on sig_in(-1) */ - sh_fact = sub(sh_fact,16); /* to remove the saturate(), should shl by 16 before rounding */ + sh_fact = sub( sh_fact, 16 ); /* to remove the saturate(), should shl by 16 before rounding */ - FOR (n = 0; n < L_subfr; n++) + FOR( n = 0; n < L_subfr; n++ ) { - L_acc = L_mult0(mu, *ptrs++); - L_temp = L_mac(L_acc, 16384, *ptrs); /* sig_in(n) * 2**15 */ + L_acc = L_mult0( mu, *ptrs++ ); + L_temp = L_mac( L_acc, 16384, *ptrs ); /* sig_in(n) * 2**15 */ - L_temp = Madd_32_16(L_fact, L_temp, ga); + L_temp = Madd_32_16( L_fact, L_temp, ga ); #ifdef BASOP_NOGLOB L_temp = L_shr_sat( L_temp, sh_fact ); /* mult. temp x ga */ #else - L_temp = L_shr(L_temp, sh_fact); /* mult. temp x ga */ + L_temp = L_shr( L_temp, sh_fact ); /* mult. temp x ga */ #endif BASOP_SATURATE_WARNING_OFF_EVS; /*sig_out[n] = saturate(L_temp); move16();*/ #ifdef BASOP_NOGLOB sig_out[n] = round_fx_sat( L_temp ); #else - sig_out[n] = round_fx(L_temp); + sig_out[n] = round_fx( L_temp ); #endif BASOP_SATURATE_WARNING_ON_EVS; } @@ -1749,12 +1745,11 @@ void Filt_mu_fx( #ifdef IVAS_FLOAT_FIXED void Filt_mu_ivas_fx( - Word16 * sig_in, /* i : signal (beginning at sample -1) */ - Word16 * sig_out, /* o : signal with tilt */ - Word16 parcor0, /* i : parcor0 (mu = parcor0 * gamma3) */ - Word16 L_subfr, /* i : the length of subframe */ - const Word16 extl -) + Word16 *sig_in, /* i : signal (beginning at sample -1) */ + Word16 *sig_out, /* o : signal with tilt */ + Word16 parcor0, /* i : parcor0 (mu = parcor0 * gamma3) */ + Word16 L_subfr, /* i : the length of subframe */ + const Word16 extl ) { Word32 L_acc, L_temp, L_fact; @@ -1814,34 +1809,34 @@ void Filt_mu_ivas_fx( } } - temp = sub(1, abs_s(mu)); + temp = sub( 1, abs_s( mu ) ); BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB - mu2 = add_o(32767, temp, &Overflow); /* 2**15 (1 - |mu|) */ + mu2 = add_o( 32767, temp, &Overflow ); /* 2**15 (1 - |mu|) */ #else - mu2 = add(32767, temp); /* 2**15 (1 - |mu|) */ + mu2 = add( 32767, temp ); /* 2**15 (1 - |mu|) */ #endif BASOP_SATURATE_WARNING_ON_EVS; - ga = div_s(fact, mu2); /* 2**sh_fact / (1 - |mu|) */ + ga = div_s( fact, mu2 ); /* 2**sh_fact / (1 - |mu|) */ ptrs = sig_in; /* points on sig_in(-1) */ - sh_fact = sub(sh_fact, 16); /* to remove the saturate(), should shl by 16 before rounding */ + sh_fact = sub( sh_fact, 16 ); /* to remove the saturate(), should shl by 16 before rounding */ - FOR(n = 0; n < L_subfr; n++) + FOR( n = 0; n < L_subfr; n++ ) { - L_acc = L_mult0(mu, *ptrs++); - L_temp = L_mac(L_acc, 16384, *ptrs); /* sig_in(n) * 2**15 */ + L_acc = L_mult0( mu, *ptrs++ ); + L_temp = L_mac( L_acc, 16384, *ptrs ); /* sig_in(n) * 2**15 */ - L_temp = Madd_32_16(L_fact, L_temp, ga); - L_temp = L_shr(L_temp, sh_fact); /* mult. temp x ga */ + L_temp = Madd_32_16( L_fact, L_temp, ga ); + L_temp = L_shr( L_temp, sh_fact ); /* mult. temp x ga */ BASOP_SATURATE_WARNING_OFF_EVS; /*sig_out[n] = saturate(L_temp); move16();*/ #ifdef BASOP_NOGLOB sig_out[n] = round_fx_sat( L_temp ); #else - sig_out[n] = round_fx(L_temp); + sig_out[n] = round_fx( L_temp ); #endif BASOP_SATURATE_WARNING_ON_EVS; } @@ -1857,11 +1852,10 @@ void Filt_mu_ivas_fx( * gain[n] = AGC_FAC_FX * gain[n-1] + (1 - AGC_FAC_FX) g_in/g_out *---------------------------------------------------------------------------*/ void scale_st_fx( - const Word16 * sig_in, /* i : postfilter i signal */ - Word16 * sig_out, /* i/o: postfilter o signal */ - Word16 * gain_prec, /* i/o: last value of gain for subframe */ - Word16 L_subfr -) + const Word16 *sig_in, /* i : postfilter i signal */ + Word16 *sig_out, /* i/o: postfilter o signal */ + Word16 *gain_prec, /* i/o: last value of gain for subframe */ + Word16 L_subfr ) { Word32 L_acc, L_temp; @@ -1872,85 +1866,85 @@ void scale_st_fx( /* compute i gain */ - L_acc = L_deposit_l(0); - FOR (i = 0; i < L_subfr; i++) + L_acc = L_deposit_l( 0 ); + FOR( i = 0; i < L_subfr; i++ ) { - if(sig_in[i] > 0) + if ( sig_in[i] > 0 ) { - L_acc = L_mac0(L_acc, 1, sig_in[i]); + L_acc = L_mac0( L_acc, 1, sig_in[i] ); } - if(sig_in[i] < 0) + if ( sig_in[i] < 0 ) { - L_acc = L_msu0(L_acc, 1, sig_in[i]); + L_acc = L_msu0( L_acc, 1, sig_in[i] ); } } g0 = 0; move16(); - IF (L_acc != 0L) + IF( L_acc != 0L ) { - scal_in = norm_l(L_acc); - L_acc = L_shl(L_acc, scal_in); - s_g_in = extract_h(L_acc); /* normalized */ + scal_in = norm_l( L_acc ); + L_acc = L_shl( L_acc, scal_in ); + s_g_in = extract_h( L_acc ); /* normalized */ /* Compute o gain */ { Word64 acc64 = 0; - FOR (i = 0; i < L_subfr; i++) + FOR( i = 0; i < L_subfr; i++ ) { - acc64 = W_mac0_16_16(acc64, 1, abs_s(sig_out[i])); + acc64 = W_mac0_16_16( acc64, 1, abs_s( sig_out[i] ) ); } - L_acc = W_sat_l(acc64); + L_acc = W_sat_l( acc64 ); } - IF (L_acc == 0L) + IF( L_acc == 0L ) { *gain_prec = 0; move16(); return; } - scal_out = norm_l(L_acc); - L_acc = L_shl(L_acc, scal_out); - s_g_out = extract_h(L_acc); /* normalized */ + scal_out = norm_l( L_acc ); + L_acc = L_shl( L_acc, scal_out ); + s_g_out = extract_h( L_acc ); /* normalized */ - sh_g0 = add(scal_in, 1); - sh_g0 = sub(sh_g0, scal_out); /* scal_in - scal_out + 1 */ - IF (LT_16(s_g_in, s_g_out)) + sh_g0 = add( scal_in, 1 ); + sh_g0 = sub( sh_g0, scal_out ); /* scal_in - scal_out + 1 */ + IF( LT_16( s_g_in, s_g_out ) ) { - g0 = div_s(s_g_in, s_g_out); /* s_g_in/s_g_out in Q15 */ + g0 = div_s( s_g_in, s_g_out ); /* s_g_in/s_g_out in Q15 */ } ELSE { - temp = sub(s_g_in, s_g_out); /* sufficient since normalized */ - g0 = shr(div_s(temp, s_g_out), 1); - g0 = add(g0, (Word16) 0x4000); /* s_g_in/s_g_out in Q14 */ - sh_g0 = sub(sh_g0, 1); + temp = sub( s_g_in, s_g_out ); /* sufficient since normalized */ + g0 = shr( div_s( temp, s_g_out ), 1 ); + g0 = add( g0, (Word16) 0x4000 ); /* s_g_in/s_g_out in Q14 */ + sh_g0 = sub( sh_g0, 1 ); } /* L_gain_in/L_gain_out in Q14 */ /* overflows if L_gain_in > 2 * L_gain_out */ #ifdef BASOP_NOGLOB - g0 = shr_sat(g0, sh_g0); /* sh_g0 may be >0, <0, or =0 */ + g0 = shr_sat( g0, sh_g0 ); /* sh_g0 may be >0, <0, or =0 */ #else - g0 = shr(g0, sh_g0); /* sh_g0 may be >0, <0, or =0 */ + g0 = shr( g0, sh_g0 ); /* sh_g0 may be >0, <0, or =0 */ #endif - g0 = mult_r(g0, AGC_FAC1_FX); /* L_gain_in/L_gain_out * AGC_FAC1_FX */ + g0 = mult_r( g0, AGC_FAC1_FX ); /* L_gain_in/L_gain_out * AGC_FAC1_FX */ } /* gain(n) = AGC_FAC gain(n-1) + AGC_FAC1 gain_in/gain_out */ /* sig_out(n) = gain(n) sig_out(n) */ gain = *gain_prec; move16(); - FOR (i = 0; i < L_subfr; i++) + FOR( i = 0; i < L_subfr; i++ ) { - temp = mult_r(AGC_FAC_FX, gain); - gain = add(temp, g0); /* in Q14 */ - L_temp = L_mult(gain, sig_out[i]); + temp = mult_r( AGC_FAC_FX, gain ); + gain = add( temp, g0 ); /* in Q14 */ + L_temp = L_mult( gain, sig_out[i] ); #ifdef BASOP_NOGLOB - L_temp = L_shl_sat(L_temp, 1); - sig_out[i] = round_fx_sat(L_temp); + L_temp = L_shl_sat( L_temp, 1 ); + sig_out[i] = round_fx_sat( L_temp ); #else - L_temp = L_shl(L_temp, 1); - sig_out[i] = round_fx(L_temp); + L_temp = L_shl( L_temp, 1 ); + sig_out[i] = round_fx( L_temp ); #endif } *gain_prec = gain; @@ -1969,26 +1963,25 @@ void scale_st_fx( void blend_subfr2_fx( Word16 *sigIn1, Word16 *sigIn2, - Word16 *sigOut -) + Word16 *sigOut ) { Word16 fac1 = 32768 - 512; - Word16 fac2 = 0 + 512; + Word16 fac2 = 0 + 512; Word16 step = 1024; Word16 i; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - FOR( i=0; i #include -#include "options.h" /* Compilation switches */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ #ifdef IVAS_FLOAT_FIXED /*===================================================================*/ /* FUNCTION : void decod_ppp_fx () */ @@ -48,36 +48,36 @@ /* CALLED FROM : RX */ /*===================================================================*/ ivas_error decod_ppp_fx( - Decoder_State *st_fx, /* i/o: state structure */ - const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ - Word16 *pitch_buf_fx, /* i/o: fixed pitch values for each subframe */ - Word16 *exc_fx, /* i/o: current non-enhanced excitation */ - Word16 *exc2_fx, /* i/o: current enhanced excitation */ - Word16 bfi, /* i : bad frame indicator */ + Decoder_State *st_fx, /* i/o: state structure */ + const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ + Word16 *pitch_buf_fx, /* i/o: fixed pitch values for each subframe */ + Word16 *exc_fx, /* i/o: current non-enhanced excitation */ + Word16 *exc2_fx, /* i/o: current enhanced excitation */ + Word16 bfi, /* i : bad frame indicator */ Word16 *gain_buf, - Word16 *voice_factors, /* o : voicing factors */ - Word16 *bwe_exc_fx /* o : excitation for SWB TBE */ + Word16 *voice_factors, /* o : voicing factors */ + Word16 *bwe_exc_fx /* o : excitation for SWB TBE */ ) { Word16 k; - Word16 LPC_de_curr_fx[M+1], p_Aq_curr_fx[M], p_Aq_old_fx[M+1]; - Word16 excQ_ppp_fx[L_FRAME], pitch_fx[NB_SUBFR], LPC_de_old_fx[M+1]; + Word16 LPC_de_curr_fx[M + 1], p_Aq_curr_fx[M], p_Aq_old_fx[M + 1]; + Word16 excQ_ppp_fx[L_FRAME], pitch_fx[NB_SUBFR], LPC_de_old_fx[M + 1]; ivas_error error; error = IVAS_ERR_OK; /* call voiced decoder at this point */ - FOR( k=0; ktilt_code_fx = st_fx->tilt_code_dec_fx[3]; move16(); - Copy(excQ_ppp_fx, exc_fx, L_FRAME); - Copy(exc_fx, exc2_fx, L_FRAME); + Copy( excQ_ppp_fx, exc_fx, L_FRAME ); + Copy( exc_fx, exc2_fx, L_FRAME ); st_fx->dm_fx.prev_state = 2; move16(); st_fx->dm_fx.prev_gain_pit[0] = st_fx->prev_gain_pit_dec_fx; - move16();/*Q14 */ + move16(); /*Q14 */ - FOR(k=3; k<7; k++) + FOR( k = 3; k < 7; k++ ) { - st_fx->dm_fx.prev_gain_pit[k-2] = st_fx->dm_fx.prev_gain_pit[k-3]; - move16();/*Q14 */ + st_fx->dm_fx.prev_gain_pit[k - 2] = st_fx->dm_fx.prev_gain_pit[k - 3]; + move16(); /*Q14 */ } - Copy(pitch_fx, pitch_buf_fx, NB_SUBFR);/*Q6 */ + Copy( pitch_fx, pitch_buf_fx, NB_SUBFR ); /*Q6 */ - IF(st_fx->hBWE_TD != NULL) + IF( st_fx->hBWE_TD != NULL ) { - interp_code_5over2_fx(exc2_fx, bwe_exc_fx, L_FRAME); + interp_code_5over2_fx( exc2_fx, bwe_exc_fx, L_FRAME ); } set16_fx( voice_factors, 0, NB_SUBFR16k ); - - set16_fx(gain_buf,0,NB_SUBFR16k); + set16_fx( gain_buf, 0, NB_SUBFR16k ); return error; } #endif diff --git a/lib_dec/dec_prm.c b/lib_dec/dec_prm.c index f16965fa6..edbec1ebe 100644 --- a/lib_dec/dec_prm.c +++ b/lib_dec/dec_prm.c @@ -50,14 +50,14 @@ *--------------------------------------------------------------------*/ void getTCXMode_ivas( - Decoder_State *st, /* i/o: decoder memory state */ - Decoder_State *st0, /* i : bitstream */ + Decoder_State *st, /* i/o: decoder memory state */ + Decoder_State *st0, /* i : bitstream */ const Word16 MCT_flag /* i : hMCT handle allocated (1) or not (0) */ ) { UWord16 ind; - IF ( st->tcxonly ) + IF( st->tcxonly ) { /* get core */ #ifdef IVAS_FLOAT_FIXED @@ -66,7 +66,7 @@ void getTCXMode_ivas( ind = get_next_indice( st0, 1 ); #endif // IVAS_FLOAT_FIXED - st->core =add( ind , TCX_20_CORE); + st->core = add( ind, TCX_20_CORE ); /* get class */ #ifdef IVAS_FLOAT_FIXED @@ -76,13 +76,13 @@ void getTCXMode_ivas( #endif // IVAS_FLOAT_FIXED st->clas_dec = ONSET; - IF ( ind == 0 ) + IF( ind == 0 ) { st->clas_dec = UNVOICED_CLAS; } - ELSE IF ( ind == 1 ) + ELSE IF( ind == 1 ) { - IF (GE_16( st->last_good , VOICED_TRANSITION )) + IF( GE_16( st->last_good, VOICED_TRANSITION ) ) { st->clas_dec = VOICED_TRANSITION; } @@ -91,13 +91,13 @@ void getTCXMode_ivas( st->clas_dec = UNVOICED_TRANSITION; } } - ELSE IF ( ind == 2 ) + ELSE IF( ind == 2 ) { st->clas_dec = VOICED_CLAS; } st->coder_type = INACTIVE; - IF ( EQ_16( st->element_mode , IVAS_CPE_MDCT ) && !MCT_flag ) + IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && !MCT_flag ) { #ifdef IVAS_FLOAT_FIXED st->VAD = get_next_indice_fx( st0, 1 ); @@ -112,7 +112,7 @@ void getTCXMode_ivas( } ELSE { - IF ( EQ_16( st->mdct_sw , MODE1 ) ) + IF( EQ_16( st->mdct_sw, MODE1 ) ) { /* 2 bits instead of 3 as TCX is already signaled */ st->core = TCX_20_CORE; @@ -125,13 +125,13 @@ void getTCXMode_ivas( } ELSE { - IF ( EQ_16( st->mdct_sw_enable , MODE2 ) ) + IF( EQ_16( st->mdct_sw_enable, MODE2 ) ) { #ifdef IVAS_FLOAT_FIXED IF( get_next_indice_1_fx( st0 ) ) #else - IF ( get_next_indice_1( st0 ) ) /* TCX */ + IF( get_next_indice_1( st0 ) ) /* TCX */ #endif // IVAS_FLOAT_FIXED { #ifdef IVAS_FLOAT_FIXED @@ -156,16 +156,16 @@ void getTCXMode_ivas( } ELSE { - IF ( EQ_16( st->rf_flag , 1 ) ) + IF( EQ_16( st->rf_flag, 1 ) ) { - IF ( !st->use_partial_copy ) + IF( !st->use_partial_copy ) { #ifdef IVAS_FLOAT_FIXED ind = get_next_indice_fx( st0, 1 ); #else ind = get_next_indice( st0, 1 ); #endif // IVAS_FLOAT_FIXED - IF ( ind == 0 ) + IF( ind == 0 ) { st->core = ACELP_CORE; } @@ -180,10 +180,10 @@ void getTCXMode_ivas( { #ifdef IVAS_FLOAT_FIXED ind = get_next_indice_fx( st, 3 ); -#else +#else ind = get_next_indice( st, 3 ); #endif // IVAS_FLOAT_FIXED - IF (LT_16( ind , ACELP_MODE_MAX )) + IF( LT_16( ind, ACELP_MODE_MAX ) ) { st->core = ACELP_CORE; st->coder_type = ind; @@ -191,16 +191,16 @@ void getTCXMode_ivas( ELSE { st->core = TCX_20_CORE; - st->hTcxCfg->coder_type =sub( ind , ACELP_MODE_MAX ); + st->hTcxCfg->coder_type = sub( ind, ACELP_MODE_MAX ); st->coder_type = st->hTcxCfg->coder_type; } } } } - IF(EQ_16( st->element_mode , EVS_MONO )) + IF( EQ_16( st->element_mode, EVS_MONO ) ) { - IF ( st->igf && EQ_16( st->core , ACELP_CORE ) ) + IF( st->igf && EQ_16( st->core, ACELP_CORE ) ) { #ifdef IVAS_FLOAT_FIXED st->bits_frame_core = sub( st->bits_frame_core, get_tbe_bits_fx( st->total_brate, st->bwidth, st->rf_flag ) ); @@ -209,14 +209,14 @@ void getTCXMode_ivas( #endif // IVAS_FLOAT_FIXED } - IF ( st->rf_flag ) + IF( st->rf_flag ) { - st->bits_frame_core = sub( st->bits_frame_core, add( st->rf_target_bits , 1 ) ); /* +1 as flag-bit not considered in rf_target_bits */ + st->bits_frame_core = sub( st->bits_frame_core, add( st->rf_target_bits, 1 ) ); /* +1 as flag-bit not considered in rf_target_bits */ } } /* Inactive frame detection on non-DTX mode */ - IF(EQ_16( st->coder_type , INACTIVE )) + IF( EQ_16( st->coder_type, INACTIVE ) ) { st->VAD = 0; } @@ -228,7 +228,7 @@ void getTCXMode_ivas( /*Core extended mode mapping for correct PLC classification*/ st->core_ext_mode = st->coder_type; - IF(EQ_16( st->coder_type , INACTIVE )) + IF( EQ_16( st->coder_type, INACTIVE ) ) { st->core_ext_mode = UNVOICED; } @@ -247,8 +247,8 @@ void getTCXWindowing_ivas( const Word16 core, /* i : current core */ const Word16 last_core, /* i : last frame core */ const Word16 element_mode, /* i : element mode */ - TCX_CONFIG_HANDLE hTcxCfg, /* i/o: TCX configuration handle */ - Decoder_State *st0 /* i : bitstream */ + TCX_CONFIG_HANDLE hTcxCfg, /* i/o: TCX configuration handle */ + Decoder_State *st0 /* i : bitstream */ ) { Word16 overlap_code; @@ -361,7 +361,7 @@ void getLPCparam_ivas( { if ( st->lpcQuantization == 0 ) { - decode_lpc_avq( st0, st->numlpc, param_lpc, ch, st->element_mode, sns_low_br_mode ); + decode_lpc_avq( st0, st->numlpc, param_lpc, ch, st->element_mode, sns_low_br_mode ); } else if ( st->lpcQuantization == 1 ) { @@ -373,7 +373,7 @@ void getLPCparam_ivas( } else { - lsf_msvq_ma_decprm_ivas( st0, param_lpc ); + lsf_msvq_ma_decprm_ivas( st0, param_lpc ); } } else @@ -595,7 +595,7 @@ void getTCXparam_ivas( } else { - ReadTnsData_ivas( st->hTcxCfg->pCurrentTnsConfig, st0, &nTnsBits, prm + j, &nTnsParams ); + ReadTnsData_ivas( st->hTcxCfg->pCurrentTnsConfig, st0, &nTnsBits, prm + j, &nTnsParams ); } hTcxDec->tnsActive[k] = ( prm[j] != 0 ? 1 : 0 ) * nTnsParams; if ( nTnsBitsTCX10 != NULL ) @@ -1032,10 +1032,10 @@ void dec_prm_ivas( else if ( st->rf_frame_type >= RF_ALLPRED && st->use_partial_copy ) { int16_t tmp = BITS_ALLOC_config_acelp_IVAS( st->rf_target_bits, /* target bits ranges from 56 to 72 depending on rf_type */ - st->rf_frame_type, /* already offset by 4 to parse the config elements for partial copy */ - &( st->acelp_cfg ), /* acelp_cfg_rf*/ - 0, /* is narrowBand */ - st->nb_subfr ); + st->rf_frame_type, /* already offset by 4 to parse the config elements for partial copy */ + &( st->acelp_cfg ), /* acelp_cfg_rf*/ + 0, /* is narrowBand */ + st->nb_subfr ); if ( tmp < 0 ) { /* erroneous configuration, resulting from a corrupt bitstream */ @@ -1169,4 +1169,4 @@ void dec_prm_ivas( } return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/dec_prm_fx.c b/lib_dec/dec_prm_fx.c index f1195d5c6..719661039 100644 --- a/lib_dec/dec_prm_fx.c +++ b/lib_dec/dec_prm_fx.c @@ -3,7 +3,6 @@ ====================================================================================*/ - #include #include #include @@ -14,11 +13,11 @@ #include "prot_fx2.h" #include "basop_util.h" #ifdef IVAS_FLOAT_FIXED - /*-------------------------------------------------------------------* - * getLPCparam_ivas() - * - * get LPC parameters - *--------------------------------------------------------------------*/ +/*-------------------------------------------------------------------* + * getLPCparam_ivas() + * + * get LPC parameters + *--------------------------------------------------------------------*/ void getLPCparam_fx( Decoder_State *st, /* i/o: decoder memory state */ @@ -96,14 +95,13 @@ void getLPCparam_fx( void dec_prm_hm_fx( Decoder_State *st, Word16 *prm_hm, - const Word16 L_frame -) + const Word16 L_frame ) { Word16 tmp; /* Disable HM for non-GC,VC modes */ test(); - IF (NE_16(st->hTcxCfg->coder_type, VOICED)&&NE_16(st->hTcxCfg->coder_type,GENERIC)) + IF( NE_16( st->hTcxCfg->coder_type, VOICED ) && NE_16( st->hTcxCfg->coder_type, GENERIC ) ) { prm_hm[0] = 0; move16(); @@ -117,25 +115,25 @@ void dec_prm_hm_fx( move16(); /* Flag */ - prm_hm[0] = get_next_indice_fx(st, 1); + prm_hm[0] = get_next_indice_fx( st, 1 ); move16(); - IF (prm_hm[0] != 0) + IF( prm_hm[0] != 0 ) { tmp = 0; move16(); - if (GE_16(L_frame, 256)) + if ( GE_16( L_frame, 256 ) ) { tmp = 1; move16(); } /* Periodicity index */ - DecodeIndex_fx(st, tmp, &prm_hm[1]); + DecodeIndex_fx( st, tmp, &prm_hm[1] ); /* Gain index */ - IF (EQ_16(st->hTcxCfg->coder_type, VOICED)) + IF( EQ_16( st->hTcxCfg->coder_type, VOICED ) ) { - prm_hm[2] = get_next_indice_fx(st, kTcxHmNumGainBits); + prm_hm[2] = get_next_indice_fx( st, kTcxHmNumGainBits ); move16(); } } @@ -313,7 +311,7 @@ void getTCXparam_fx( last_core = TCX_20_CORE; } - SetTnsConfig( st->hTcxCfg, (Word16)EQ_16( core, TCX_20_CORE ), (Word16)EQ_16( st->last_core_from_bs, ACELP_CORE ) && ( k == 0 ) ); + SetTnsConfig( st->hTcxCfg, (Word16) EQ_16( core, TCX_20_CORE ), (Word16) EQ_16( st->last_core_from_bs, ACELP_CORE ) && ( k == 0 ) ); ix = 0; IF( no_param_tns ) @@ -371,7 +369,7 @@ void getTCXparam_fx( IF( useHarmonicModel ) { - ix = DecodeIndex_fx( st0, (Word16)GE_16( hm_size, 256 ), prm + add( j, 1 ) ); + ix = DecodeIndex_fx( st0, (Word16) GE_16( hm_size, 256 ), prm + add( j, 1 ) ); flag_ctx_hm = 1; PeriodicityIndex = *( prm + add( j, 1 ) ); @@ -465,14 +463,13 @@ void dec_prm_fx( Word16 *total_nbbits, /* i/o : number of bits / decoded bits */ Decoder_State *st, Word16 L_frame, - Word16 *bitsRead -) + Word16 *bitsRead ) { Word16 j, k, n, sfr, *prm; Word16 lg; Word16 lgFB; Word16 start_bit_pos; - Word16 acelp_target_bits=-1; + Word16 acelp_target_bits = -1; Word16 tmp; Word16 nTnsParams; Word16 nTnsBits; @@ -482,8 +479,8 @@ void dec_prm_fx( Word16 hm_size; Word16 *prms; CONTEXT_HM_CONFIG hm_cfg; - CONTEXT_HM_CONFIG * phm_cfg; - Word16 indexBuffer[N_MAX+1]; + CONTEXT_HM_CONFIG *phm_cfg; + Word16 indexBuffer[N_MAX + 1]; Word8 flag_ctx_hm; Word32 L_tmp; Word16 num_bits; @@ -504,29 +501,30 @@ void dec_prm_fx( hm_cfg.indexBuffer = indexBuffer; move16(); - IF (EQ_16(st->mdct_sw, MODE1)) + IF( EQ_16( st->mdct_sw, MODE1 ) ) { - start_bit_pos = 0; /* count from frame start */ move16(); + start_bit_pos = 0; /* count from frame start */ + move16(); /* Adjust st->bits_frame_core not to subtract MODE2 bandwidth signaling */ - FOR (n=0; ntotal_brate, 5243, &L_tmp, &lsb); /* 5243 is 1/50 in Q18. (0+18-15=3) */ - num_bits = extract_l(L_shr(L_tmp, 3)); /* Q0 */ - assert(num_bits == st->total_brate/50); - IF (EQ_16(FrameSizeConfig[n].frame_bits, num_bits)) + Mpy_32_16_ss( st->total_brate, 5243, &L_tmp, &lsb ); /* 5243 is 1/50 in Q18. (0+18-15=3) */ + num_bits = extract_l( L_shr( L_tmp, 3 ) ); /* Q0 */ + assert( num_bits == st->total_brate / 50 ); + IF( EQ_16( FrameSizeConfig[n].frame_bits, num_bits ) ) { - st->bits_frame_core = add(st->bits_frame_core, FrameSizeConfig[n].bandwidth_bits); + st->bits_frame_core = add( st->bits_frame_core, FrameSizeConfig[n].bandwidth_bits ); BREAK; } } } ELSE { - IF( EQ_16(st->rf_flag,1)) + IF( EQ_16( st->rf_flag, 1 ) ) { /*Inherent adjustment to accommodate the compact packing used in the RF mode*/ - start_bit_pos = sub(st->next_bit_pos,2); + start_bit_pos = sub( st->next_bit_pos, 2 ); } ELSE { @@ -556,57 +554,57 @@ void dec_prm_fx( *--------------------------------------------------------------------------------*/ /* Modes (ACE_GC, ACE_UC, TCX20, TCX10...) */ - IF ( st->tcxonly ) + IF( st->tcxonly ) { - st->core = add(get_next_indice(st, 1), 1); + st->core = add( get_next_indice( st, 1 ), 1 ); move16(); - ind = get_next_indice(st, 2); - st->clas_dec = ONSET; + ind = get_next_indice( st, 2 ); + st->clas_dec = ONSET; + move16(); + IF( ind == 0 ) + { + st->clas_dec = UNVOICED_CLAS; move16(); - IF( ind == 0 ) - { - st->clas_dec = UNVOICED_CLAS; - move16(); - } - ELSE IF( EQ_16(ind, 1)) - { - st->clas_dec = UNVOICED_TRANSITION; - move16(); - if( GE_16(st->last_good, VOICED_TRANSITION)) - { - st->clas_dec = VOICED_TRANSITION; - move16(); - } - } - ELSE if( EQ_16(ind, 2)) + } + ELSE IF( EQ_16( ind, 1 ) ) + { + st->clas_dec = UNVOICED_TRANSITION; + move16(); + if ( GE_16( st->last_good, VOICED_TRANSITION ) ) { - st->clas_dec = VOICED_CLAS; + st->clas_dec = VOICED_TRANSITION; move16(); } + } + ELSE if ( EQ_16( ind, 2 ) ) + { + st->clas_dec = VOICED_CLAS; + move16(); + } *coder_type = INACTIVE; st->VAD = 0; move16(); } ELSE { - IF (EQ_16(st->mdct_sw, MODE1)) + IF( EQ_16( st->mdct_sw, MODE1 ) ) { /* 2 bits instead of 3 as TCX is already signaled */ st->core = TCX_20_CORE; move16(); - st->hTcxCfg->coder_type = get_next_indice(st, 2); + st->hTcxCfg->coder_type = get_next_indice( st, 2 ); move16(); *coder_type = st->hTcxCfg->coder_type; move16(); } ELSE { - IF (EQ_16(st->mdct_sw_enable, MODE2)) + IF( EQ_16( st->mdct_sw_enable, MODE2 ) ) { - IF (get_next_indice_1(st) != 0) /* TCX */ + IF( get_next_indice_1( st ) != 0 ) /* TCX */ { - tmp = get_next_indice(st, 3); - assert(!(tmp & 4) || !"HQ_CORE encountered in dec_prm_fx"); + tmp = get_next_indice( st, 3 ); + assert( !( tmp & 4 ) || !"HQ_CORE encountered in dec_prm_fx" ); st->core = TCX_20_CORE; move16(); st->hTcxCfg->coder_type = tmp; @@ -618,18 +616,18 @@ void dec_prm_fx( { st->core = ACELP_CORE; move16(); - *coder_type = get_next_indice(st, 2); + *coder_type = get_next_indice( st, 2 ); move16(); } } ELSE { - IF(EQ_16(st->rf_flag,1)) + IF( EQ_16( st->rf_flag, 1 ) ) { IF( !( st->use_partial_copy ) ) { - tmp = get_next_indice(st, 1); - IF(tmp == 0) + tmp = get_next_indice( st, 1 ); + IF( tmp == 0 ) { st->core = ACELP_CORE; move16(); @@ -647,13 +645,13 @@ void dec_prm_fx( { st->core = ACELP_CORE; move16(); - *coder_type = get_next_indice(st, 3); + *coder_type = get_next_indice( st, 3 ); move16(); - IF ( GE_16(*coder_type, ACELP_MODE_MAX)) + IF( GE_16( *coder_type, ACELP_MODE_MAX ) ) { st->core = TCX_20_CORE; move16(); - *coder_type=sub(*coder_type,ACELP_MODE_MAX); + *coder_type = sub( *coder_type, ACELP_MODE_MAX ); st->hTcxCfg->coder_type = *coder_type; move16(); } @@ -662,20 +660,20 @@ void dec_prm_fx( } test(); - IF ( st->igf != 0 && EQ_16(st->core, ACELP_CORE) ) + IF( st->igf != 0 && EQ_16( st->core, ACELP_CORE ) ) { - st->bits_frame_core = sub( st->bits_frame_core, get_tbe_bits_fx(st->total_brate, st->bwidth, st->rf_flag) ); + st->bits_frame_core = sub( st->bits_frame_core, get_tbe_bits_fx( st->total_brate, st->bwidth, st->rf_flag ) ); } - IF( EQ_16(st->rf_flag,1)) + IF( EQ_16( st->rf_flag, 1 ) ) { - st->bits_frame_core = sub(st->bits_frame_core, add(st->rf_target_bits, 1)); /* +1 as flag-bit not considered in rf_target_bits */ + st->bits_frame_core = sub( st->bits_frame_core, add( st->rf_target_bits, 1 ) ); /* +1 as flag-bit not considered in rf_target_bits */ } /* Inactive frame detection on non-DTX mode */ st->VAD = 1; move16(); - if( EQ_16(*coder_type, INACTIVE)) + if ( EQ_16( *coder_type, INACTIVE ) ) { st->VAD = 0; move16(); @@ -686,7 +684,7 @@ void dec_prm_fx( st->core_ext_mode = *coder_type; move16(); - if( EQ_16(*coder_type, INACTIVE)) + if ( EQ_16( *coder_type, INACTIVE ) ) { st->core_ext_mode = UNVOICED; move16(); @@ -697,27 +695,27 @@ void dec_prm_fx( move16(); test(); test(); - IF( ( NE_16(st->core, ACELP_CORE) || st->hTcxCfg->lfacNext > 0 ) && st->use_partial_copy == 0 ) + IF( ( NE_16( st->core, ACELP_CORE ) || st->hTcxCfg->lfacNext > 0 ) && st->use_partial_copy == 0 ) { - st->last_core_from_bs = get_next_indice(st, 1); + st->last_core_from_bs = get_next_indice( st, 1 ); move16(); - /* + /* need to introduce special error handling for lost transition frames from CNG: in such cases, the bitstream reader continues with CNG, setting bfi = 0, total_brate = 0 - this might result in a not matching last_core transmitted in the BS - we should use this - only for interpreting the bitstream and re-use the internal state for the proper + this might result in a not matching last_core transmitted in the BS - we should use this + only for interpreting the bitstream and re-use the internal state for the proper transition handling; still, for voiced onsets rather stick to wrong windowing... */ - if( (!((st->last_total_brate == 0) && (sub(st->clas_dec, VOICED_CLAS) != 0))) && (sub(st->last_core_from_bs, st->last_core) != 0) ) + if ( ( !( ( st->last_total_brate == 0 ) && ( sub( st->clas_dec, VOICED_CLAS ) != 0 ) ) ) && ( sub( st->last_core_from_bs, st->last_core ) != 0 ) ) { st->last_core = st->last_core_from_bs; - } + } /*for TCX 10 force last_core to be TCX since ACELP as previous core is forbidden*/ - IF( EQ_16(st->core, TCX_10_CORE)) + IF( EQ_16( st->core, TCX_10_CORE ) ) { st->last_core = TCX_20_CORE; - st->last_core_from_bs = TCX_20_CORE; + st->last_core_from_bs = TCX_20_CORE; move16(); move16(); } @@ -725,22 +723,22 @@ void dec_prm_fx( test(); test(); - IF(EQ_16(st->rf_flag,1)&&EQ_16(st->use_partial_copy,1)&&!st->tcxonly) + IF( EQ_16( st->rf_flag, 1 ) && EQ_16( st->use_partial_copy, 1 ) && !st->tcxonly ) { st->bits_frame_core = st->rf_target_bits; /* offset the indices to read the acelp partial copy */ - Mpy_32_16_ss(st->total_brate, 5243, &L_tmp, &lsb); /* 5243 is 1/50 in Q18. (0+18-15=3) */ - num_bits = extract_l(L_shr(L_tmp, 3)); /* Q0 */ + Mpy_32_16_ss( st->total_brate, 5243, &L_tmp, &lsb ); /* 5243 is 1/50 in Q18. (0+18-15=3) */ + num_bits = extract_l( L_shr( L_tmp, 3 ) ); /* Q0 */ - get_next_indice_tmp_fx(st, start_bit_pos + num_bits - st->rf_target_bits - 3 - st->next_bit_pos); + get_next_indice_tmp_fx( st, start_bit_pos + num_bits - st->rf_target_bits - 3 - st->next_bit_pos ); } IF( st->use_partial_copy == 0 ) { /* Set the last overlap mode based on the previous and current frame type and coded overlap mode */ test(); - IF ((EQ_16(st->last_core, ACELP_CORE))||(EQ_16(st->last_core,AMR_WB_CORE))) + IF( ( EQ_16( st->last_core, ACELP_CORE ) ) || ( EQ_16( st->last_core, AMR_WB_CORE ) ) ) { st->hTcxCfg->tcx_last_overlap_mode = TRANSITION_OVERLAP; move16(); @@ -748,7 +746,7 @@ void dec_prm_fx( ELSE { test(); - IF ((EQ_16(st->core, TCX_10_CORE))&&(EQ_16(st->hTcxCfg->tcx_curr_overlap_mode,ALDO_WINDOW))) + IF( ( EQ_16( st->core, TCX_10_CORE ) ) && ( EQ_16( st->hTcxCfg->tcx_curr_overlap_mode, ALDO_WINDOW ) ) ) { st->hTcxCfg->tcx_last_overlap_mode = FULL_OVERLAP; move16(); @@ -758,7 +756,7 @@ void dec_prm_fx( st->hTcxCfg->tcx_last_overlap_mode = st->hTcxCfg->tcx_curr_overlap_mode; move16(); test(); - if ((NE_16(st->core, TCX_10_CORE))&&(EQ_16(st->hTcxCfg->tcx_curr_overlap_mode,FULL_OVERLAP))) + if ( ( NE_16( st->core, TCX_10_CORE ) ) && ( EQ_16( st->hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) ) ) { st->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; move16(); @@ -769,14 +767,14 @@ void dec_prm_fx( st->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; move16(); - IF (NE_16(st->core, ACELP_CORE)) + IF( NE_16( st->core, ACELP_CORE ) ) { tmp = 0; move16(); /* if current TCX mode is not 0 (full overlap), read another bit */ - IF (get_next_indice(st, 1)) + IF( get_next_indice( st, 1 ) ) { - tmp = add(2, get_next_indice(st, 1)); + tmp = add( 2, get_next_indice( st, 1 ) ); } st->hTcxCfg->tcx_curr_overlap_mode = tmp; move16(); @@ -785,7 +783,7 @@ void dec_prm_fx( test(); test(); test(); - if ((EQ_16(st->core, TCX_20_CORE))&&(tmp==0)&&(NE_16(st->last_core,ACELP_CORE))&&(NE_16(st->last_core,AMR_WB_CORE))) + if ( ( EQ_16( st->core, TCX_20_CORE ) ) && ( tmp == 0 ) && ( NE_16( st->last_core, ACELP_CORE ) ) && ( NE_16( st->last_core, AMR_WB_CORE ) ) ) { st->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; move16(); @@ -793,7 +791,7 @@ void dec_prm_fx( } /* SIDE INFO. DECODING */ - IF(st->enableGplc) + IF( st->enableGplc ) { Word16 pitchDiff; Word16 bits_per_subfr, search_range; @@ -802,20 +800,20 @@ void dec_prm_fx( search_range = 8; move16(); - st->flagGuidedAcelp = get_next_indice(st, 1); + st->flagGuidedAcelp = get_next_indice( st, 1 ); move16(); pitchDiff = 0; move16(); - IF(st->flagGuidedAcelp) + IF( st->flagGuidedAcelp ) { - pitchDiff = get_next_indice(st, bits_per_subfr); + pitchDiff = get_next_indice( st, bits_per_subfr ); move16(); - st->guidedT0 = sub(pitchDiff, search_range); + st->guidedT0 = sub( pitchDiff, search_range ); move16(); } test(); - if( (pitchDiff == 0) && st->flagGuidedAcelp) + if ( ( pitchDiff == 0 ) && st->flagGuidedAcelp ) { st->flagGuidedAcelp = 0; move16(); @@ -831,9 +829,9 @@ void dec_prm_fx( { move16(); st->dec_glr_idx = -1; - IF( EQ_16(st->core, ACELP_CORE) ) + IF( EQ_16( st->core, ACELP_CORE ) ) { - st->dec_glr_idx = get_next_indice(st, G_LPC_RECOVERY_BITS); + st->dec_glr_idx = get_next_indice( st, G_LPC_RECOVERY_BITS ); } } } @@ -846,7 +844,7 @@ void dec_prm_fx( move16(); test(); test(); - IF( (EQ_16(st->lpcQuantization, 1)&&(EQ_16(*coder_type,VOICED)))||(st->use_partial_copy)) + IF( ( EQ_16( st->lpcQuantization, 1 ) && ( EQ_16( *coder_type, VOICED ) ) ) || ( st->use_partial_copy ) ) { st->acelp_cfg.midLpc = 0; move16(); @@ -858,7 +856,7 @@ void dec_prm_fx( st->numlpc = 2; move16(); test(); - if ( st->tcxonly==0 || LT_16(st->core, TCX_10_CORE)) + if ( st->tcxonly == 0 || LT_16( st->core, TCX_10_CORE ) ) { st->numlpc = 1; move16(); @@ -866,40 +864,40 @@ void dec_prm_fx( /* Decode LPC parameters */ test(); - IF (hTcxDec->enableTcxLpc && NE_16(st->core, ACELP_CORE)) + IF( hTcxDec->enableTcxLpc && NE_16( st->core, ACELP_CORE ) ) { Word16 tcx_lpc_cdk; - tcx_lpc_cdk = tcxlpc_get_cdk(*coder_type); - dec_lsf_tcxlpc(st, ¶m_lpc, st->narrowBand, tcx_lpc_cdk); + tcx_lpc_cdk = tcxlpc_get_cdk( *coder_type ); + dec_lsf_tcxlpc( st, ¶m_lpc, st->narrowBand, tcx_lpc_cdk ); } ELSE { - IF (st->lpcQuantization==0) + IF( st->lpcQuantization == 0 ) { decode_lpc_avq_fx( st, st->numlpc, param_lpc #ifdef IVAS_CODE_AVQ_LPC - , , , + , + , , #endif ); move16(); } - ELSE IF (EQ_16(st->lpcQuantization, 1)) + ELSE IF( EQ_16( st->lpcQuantization, 1 ) ) { test(); test(); - IF(EQ_32(st->sr_core, 16000)&&EQ_16(*coder_type,VOICED)&&EQ_16(st->core,ACELP_CORE)) + IF( EQ_32( st->sr_core, 16000 ) && EQ_16( *coder_type, VOICED ) && EQ_16( st->core, ACELP_CORE ) ) { - lsf_bctcvq_decprm(st, param_lpc); + lsf_bctcvq_decprm( st, param_lpc ); } ELSE { - lsf_msvq_ma_decprm( st, param_lpc); + lsf_msvq_ma_decprm( st, param_lpc ); } - } ELSE { - assert(0 && "LPC quant not supported!"); + assert( 0 && "LPC quant not supported!" ); } } } @@ -909,23 +907,23 @@ void dec_prm_fx( move16(); test(); - IF( EQ_16(st->rf_frame_type, RF_TCXFD)) + IF( EQ_16( st->rf_frame_type, RF_TCXFD ) ) { param_lpc[0] = 0; move16(); - param_lpc[1] = get_next_indice(st, lsf_numbits[0]); /* VQ 1 */ - param_lpc[2] = get_next_indice(st, lsf_numbits[1]); /* VQ 2 */ - param_lpc[3] = get_next_indice(st, lsf_numbits[2]); /* VQ 3 */ + param_lpc[1] = get_next_indice( st, lsf_numbits[0] ); /* VQ 1 */ + param_lpc[2] = get_next_indice( st, lsf_numbits[1] ); /* VQ 2 */ + param_lpc[3] = get_next_indice( st, lsf_numbits[2] ); /* VQ 3 */ } - ELSE IF( GE_16(st->rf_frame_type, RF_ALLPRED)&&LE_16(st->rf_frame_type,RF_NELP)) + ELSE IF( GE_16( st->rf_frame_type, RF_ALLPRED ) && LE_16( st->rf_frame_type, RF_NELP ) ) { /* LSF indices */ - param_lpc[0] = get_next_indice(st, 8); /* VQ 1 */ - param_lpc[1] = get_next_indice(st, 8); /* VQ 2 */ + param_lpc[0] = get_next_indice( st, 8 ); /* VQ 1 */ + param_lpc[1] = get_next_indice( st, 8 ); /* VQ 2 */ } } - st->bits_common = sub(st->next_bit_pos, start_bit_pos); + st->bits_common = sub( st->next_bit_pos, start_bit_pos ); move16(); @@ -934,15 +932,15 @@ void dec_prm_fx( *--------------------------------------------------------------------------------*/ test(); test(); - IF( EQ_16(st->core,ACELP_CORE)&&st->use_partial_copy==0) + IF( EQ_16( st->core, ACELP_CORE ) && st->use_partial_copy == 0 ) { /* Target Bits */ - acelp_target_bits = sub(st->bits_frame_core, st->bits_common); + acelp_target_bits = sub( st->bits_frame_core, st->bits_common ); { Word16 acelp_bits; move16(); - acelp_bits = BITS_ALLOC_config_acelp( acelp_target_bits, *coder_type, &(st->acelp_cfg), st->narrowBand, st->nb_subfr ); + acelp_bits = BITS_ALLOC_config_acelp( acelp_target_bits, *coder_type, &( st->acelp_cfg ), st->narrowBand, st->nb_subfr ); if ( acelp_bits < 0 ) { @@ -952,13 +950,13 @@ void dec_prm_fx( } /* Adaptive BPF (2 bits)*/ - n=ACELP_BPF_BITS[st->acelp_cfg.bpf_mode]; + n = ACELP_BPF_BITS[st->acelp_cfg.bpf_mode]; move16(); - st->bpf_gain_param = shl(st->acelp_cfg.bpf_mode, 1); - IF( n != 0) + st->bpf_gain_param = shl( st->acelp_cfg.bpf_mode, 1 ); + IF( n != 0 ) { - st->bpf_gain_param = get_next_indice(st, n); + st->bpf_gain_param = get_next_indice( st, n ); move16(); } @@ -967,27 +965,27 @@ void dec_prm_fx( move16(); IF( n != 0 ) { - prm[j++] = get_next_indice(st, n); + prm[j++] = get_next_indice( st, n ); move16(); } /* Subframe parameters */ - FOR (sfr=0; sfracelp_cfg.ltp_mode][sfr]; move16(); - IF(n!=0) + IF( n != 0 ) { - prm[j++] = get_next_indice(st, n); + prm[j++] = get_next_indice( st, n ); move16(); } /* Adaptive codebook filtering (1 bit) */ - IF ( EQ_16(st->acelp_cfg.ltf_mode, 2)) + IF( EQ_16( st->acelp_cfg.ltf_mode, 2 ) ) { - prm[j++] = get_next_indice(st, 1); + prm[j++] = get_next_indice( st, 1 ); move16(); } @@ -996,12 +994,12 @@ void dec_prm_fx( /* Decode pulse positions. */ j_old = j; move16(); - wordcnt = shr(ACELP_FIXED_CDK_BITS(st->acelp_cfg.fixed_cdk_index[sfr]), 4); - bitcnt = s_and(ACELP_FIXED_CDK_BITS(st->acelp_cfg.fixed_cdk_index[sfr]), 0xF); + wordcnt = shr( ACELP_FIXED_CDK_BITS( st->acelp_cfg.fixed_cdk_index[sfr] ), 4 ); + bitcnt = s_and( ACELP_FIXED_CDK_BITS( st->acelp_cfg.fixed_cdk_index[sfr] ), 0xF ); /* sanity check for testing - not instrumented */ test(); - if ( GE_16(st->acelp_cfg.fixed_cdk_index[sfr], ACELP_FIXED_CDK_NB)||(st->acelp_cfg.fixed_cdk_index[sfr]<0)) + if ( GE_16( st->acelp_cfg.fixed_cdk_index[sfr], ACELP_FIXED_CDK_NB ) || ( st->acelp_cfg.fixed_cdk_index[sfr] < 0 ) ) { st->acelp_cfg.fixed_cdk_index[sfr] = 0; move16(); @@ -1009,38 +1007,37 @@ void dec_prm_fx( move16(); } - FOR (ix = 0; ix < wordcnt; ix++) + FOR( ix = 0; ix < wordcnt; ix++ ) { - prm[j++] = get_next_indice(st, 16); + prm[j++] = get_next_indice( st, 16 ); move16(); } - IF (bitcnt) + IF( bitcnt ) { - prm[j] = get_next_indice(st, bitcnt); + prm[j] = get_next_indice( st, bitcnt ); move16(); } - j = add(j_old, 8); - + j = add( j_old, 8 ); } /* Gains (5b, 6b or 7b / subfr) */ n = ACELP_GAINS_BITS[st->acelp_cfg.gains_mode[sfr]]; move16(); - prm[j++] = get_next_indice(st, n); + prm[j++] = get_next_indice( st, n ); move16(); - }/*end of subfr loop*/ + } /*end of subfr loop*/ } - ELSE IF( GE_16(st->rf_frame_type,RF_ALLPRED)&&st->use_partial_copy) + ELSE IF( GE_16( st->rf_frame_type, RF_ALLPRED ) && st->use_partial_copy ) { - Word16 acelp_bits = - BITS_ALLOC_config_acelp( st->rf_target_bits, /* target bits ranges from 56 to 72 depending on rf_type */ - st->rf_frame_type, /* already offset by 4 to parse the config elements for partial copy */ - &(st->acelp_cfg), /* acelp_cfg_rf*/ - 0, /* is narrowBand */ - st->nb_subfr ); + Word16 acelp_bits = + BITS_ALLOC_config_acelp( st->rf_target_bits, /* target bits ranges from 56 to 72 depending on rf_type */ + st->rf_frame_type, /* already offset by 4 to parse the config elements for partial copy */ + &( st->acelp_cfg ), /* acelp_cfg_rf*/ + 0, /* is narrowBand */ + st->nb_subfr ); if ( acelp_bits < 0 ) { @@ -1049,7 +1046,7 @@ void dec_prm_fx( } /* rf_frame_type NELP: 7 */ - IF(EQ_16(st->rf_frame_type,RF_NELP)) + IF( EQ_16( st->rf_frame_type, RF_NELP ) ) { /* NELP gain indices */ st->rf_indx_nelp_iG1 = get_next_indice( st, 5 ); @@ -1066,7 +1063,7 @@ void dec_prm_fx( { /* rf_frame_type ALL_PRED: 4, NO_PRED: 5, GEN_PRED: 6*/ /* ES pred */ - prm[j++] = get_next_indice(st, 3); + prm[j++] = get_next_indice( st, 3 ); ltp_mode = ACELP_LTP_MODE[1][1][st->rf_frame_type]; gains_mode = ACELP_GAINS_MODE[1][1][st->rf_frame_type]; @@ -1076,30 +1073,29 @@ void dec_prm_fx( { /* Pitch lag (5, or 8 bits) */ n = ACELP_LTP_BITS_SFR[ltp_mode][sfr]; - IF (n != 0) + IF( n != 0 ) { - prm[j++] = get_next_indice(st, n); + prm[j++] = get_next_indice( st, n ); } /*Innovative codebook*/ test(); test(); test(); - IF( EQ_16(st->rf_frame_type,RF_NOPRED) - || ( EQ_16(st->rf_frame_type,RF_GENPRED) && (sfr == 0 || EQ_16(sfr,2) )) ) + IF( EQ_16( st->rf_frame_type, RF_NOPRED ) || ( EQ_16( st->rf_frame_type, RF_GENPRED ) && ( sfr == 0 || EQ_16( sfr, 2 ) ) ) ) { /* NOTE: FCB actual bits need to be backed up as well */ /*n = ACELP_FIXED_CDK_BITS(st->rf_indx_fcb[fec_offset][sfr]) & 15;*/ - prm[j] = get_next_indice(st, 7); - j = add(j,8); + prm[j] = get_next_indice( st, 7 ); + j = add( j, 8 ); } /* Gains (5b, 6b or 7b / subfr) */ test(); - IF( sfr == 0 || EQ_16(sfr,2)) + IF( sfr == 0 || EQ_16( sfr, 2 ) ) { n = ACELP_GAINS_BITS[gains_mode]; - prm[j++] = get_next_indice(st, n); + prm[j++] = get_next_indice( st, n ); } } @@ -1111,52 +1107,52 @@ void dec_prm_fx( * TCX20 *--------------------------------------------------------------------------------*/ test(); - IF( EQ_16(st->core, TCX_20_CORE)&&st->use_partial_copy==0) + IF( EQ_16( st->core, TCX_20_CORE ) && st->use_partial_copy == 0 ) { flag_ctx_hm = 0; move16(); - IF (st->enablePlcWaveadjust) + IF( st->enablePlcWaveadjust ) { - st->tonality_flag = get_next_indice(st, 1); + st->tonality_flag = get_next_indice( st, 1 ); move16(); } /* TCX Gain = 7 bits */ - prm[j++] = get_next_indice(st, 7); + prm[j++] = get_next_indice( st, 7 ); move16(); /* TCX Noise Filling = NBITS_NOISE_FILL_LEVEL bits */ - prm[j++] = get_next_indice(st, NBITS_NOISE_FILL_LEVEL); + prm[j++] = get_next_indice( st, NBITS_NOISE_FILL_LEVEL ); move16(); /* LTP data */ /* PLC pitch info for HB */ test(); - IF (hTcxLtpDec->tcxltp != 0 || GT_32(st->sr_core, 25600)) + IF( hTcxLtpDec->tcxltp != 0 || GT_32( st->sr_core, 25600 ) ) { - prm[j] = get_next_indice(st, 1); + prm[j] = get_next_indice( st, 1 ); move16(); - IF ( prm[j] ) + IF( prm[j] ) { - prm[j+1] = get_next_indice(st, 9); + prm[j + 1] = get_next_indice( st, 9 ); move16(); - prm[j+2] = get_next_indice(st, 2); + prm[j + 2] = get_next_indice( st, 2 ); move16(); } st->BER_detect = st->BER_detect | - tcx_ltp_decode_params(&prm[j], - &(hTcxLtpDec->tcxltp_pitch_int), - &(hTcxLtpDec->tcxltp_pitch_fr), - &(hTcxLtpDec->tcxltp_gain), - st->pit_min, - st->pit_fr1, - st->pit_fr2, - st->pit_max, - st->pit_res_max); + tcx_ltp_decode_params( &prm[j], + &( hTcxLtpDec->tcxltp_pitch_int ), + &( hTcxLtpDec->tcxltp_pitch_fr ), + &( hTcxLtpDec->tcxltp_gain ), + st->pit_min, + st->pit_fr1, + st->pit_fr2, + st->pit_max, + st->pit_res_max ); hTcxDec->tcx_hm_LtpPitchLag = -1; move16(); @@ -1164,32 +1160,32 @@ void dec_prm_fx( move16(); test(); - IF ((st->tcxonly == 0) && (LT_16(hTcxLtpDec->tcxltp_pitch_int, L_frame))) + IF( ( st->tcxonly == 0 ) && ( LT_16( hTcxLtpDec->tcxltp_pitch_int, L_frame ) ) ) { - Word32 tmp32 = L_shl(L_mult0(st->L_frame, st->pit_res_max), 1+kLtpHmFractionalResolution+1); - Word16 tmp1 = add(imult1616(hTcxLtpDec->tcxltp_pitch_int, st->pit_res_max), hTcxLtpDec->tcxltp_pitch_fr); - hTcxDec->tcx_hm_LtpPitchLag = div_l(tmp32, tmp1); + Word32 tmp32 = L_shl( L_mult0( st->L_frame, st->pit_res_max ), 1 + kLtpHmFractionalResolution + 1 ); + Word16 tmp1 = add( imult1616( hTcxLtpDec->tcxltp_pitch_int, st->pit_res_max ), hTcxLtpDec->tcxltp_pitch_fr ); + hTcxDec->tcx_hm_LtpPitchLag = div_l( tmp32, tmp1 ); } } - j = add(j, 3); + j = add( j, 3 ); /* TCX spectral data */ lg = L_frame; move16(); - lgFB = st->hTcxCfg->tcx_coded_lines; + lgFB = st->hTcxCfg->tcx_coded_lines; move16(); - IF (st->last_core_from_bs == ACELP_CORE ) + IF( st->last_core_from_bs == ACELP_CORE ) { /* ACE->TCX transition */ - lg = add(lg, st->hTcxCfg->tcx_offset); - if (st->hTcxCfg->lfacNext < 0) + lg = add( lg, st->hTcxCfg->tcx_offset ); + if ( st->hTcxCfg->lfacNext < 0 ) { - lg = sub(lg, st->hTcxCfg->lfacNext); + lg = sub( lg, st->hTcxCfg->lfacNext ); } - lgFB = add(lgFB, shr(lgFB, 2)); + lgFB = add( lgFB, shr( lgFB, 2 ) ); } /* TNS data */ @@ -1198,49 +1194,49 @@ void dec_prm_fx( nTnsBits = 0; move16(); - IF (st->hTcxCfg->fIsTNSAllowed) + IF( st->hTcxCfg->fIsTNSAllowed ) { - SetTnsConfig(st->hTcxCfg, 1, st->last_core_from_bs == ACELP_CORE); - ReadTnsData(st->hTcxCfg->pCurrentTnsConfig, st, &nTnsBits, prm+j, &nTnsParams); + SetTnsConfig( st->hTcxCfg, 1, st->last_core_from_bs == ACELP_CORE ); + ReadTnsData( st->hTcxCfg->pCurrentTnsConfig, st, &nTnsBits, prm + j, &nTnsParams ); - j = add(j, nTnsParams); + j = add( j, nTnsParams ); } - hm_size = shl(mult(st->TcxBandwidth, lg), 1); + hm_size = shl( mult( st->TcxBandwidth, lg ), 1 ); test(); - IF (hTcxDec->tcx_lpc_shaped_ari != 0 && NE_16(st->last_core_from_bs, ACELP_CORE)) + IF( hTcxDec->tcx_lpc_shaped_ari != 0 && NE_16( st->last_core_from_bs, ACELP_CORE ) ) { - dec_prm_hm_fx(st, &prm[j], hm_size); + dec_prm_hm_fx( st, &prm[j], hm_size ); } - nbits_tcx = sub(st->bits_frame_core, sub(st->next_bit_pos, start_bit_pos)); - if (st->enableGplc != 0) + nbits_tcx = sub( st->bits_frame_core, sub( st->next_bit_pos, start_bit_pos ) ); + if ( st->enableGplc != 0 ) { - nbits_tcx = sub(nbits_tcx, 7); + nbits_tcx = sub( nbits_tcx, 7 ); } /*Context HM flag*/ test(); - IF ( st->hTcxCfg->ctx_hm && NE_16(st->last_core_from_bs, ACELP_CORE)) + IF( st->hTcxCfg->ctx_hm && NE_16( st->last_core_from_bs, ACELP_CORE ) ) { - prm[j] = get_next_indice(st, 1); + prm[j] = get_next_indice( st, 1 ); move16(); - nbits_tcx = sub(nbits_tcx, 1); + nbits_tcx = sub( nbits_tcx, 1 ); - IF (prm[j]) + IF( prm[j] ) { Word16 NumIndexBits; tmp = 0; move16(); - if(GE_16(hm_size, 256)) + if ( GE_16( hm_size, 256 ) ) { tmp = 1; move16(); } - NumIndexBits = DecodeIndex_fx(st, - tmp, - prm + j + 1); + NumIndexBits = DecodeIndex_fx( st, + tmp, + prm + j + 1 ); flag_ctx_hm = 1; move16(); @@ -1248,22 +1244,22 @@ void dec_prm_fx( ConfigureContextHm( lgFB, nbits_tcx, - *(prm+j+1), + *( prm + j + 1 ), hTcxDec->tcx_hm_LtpPitchLag, - &hm_cfg); + &hm_cfg ); - nbits_tcx = sub(nbits_tcx, NumIndexBits); + nbits_tcx = sub( nbits_tcx, NumIndexBits ); } } - j = add(j, NPRM_CTX_HM); + j = add( j, NPRM_CTX_HM ); /* read IGF payload */ - IF (st->igf) + IF( st->igf ) { n = st->next_bit_pos; move16(); - IF (EQ_16(st->last_core_from_bs, ACELP_CORE)) + IF( EQ_16( st->last_core_from_bs, ACELP_CORE ) ) { IGFDecReadLevel( st->hIGFDec, st, IGF_GRID_LB_TRAN, 1 ); IGFDecReadData( st->hIGFDec, st, IGF_GRID_LB_TRAN, 1 ); @@ -1274,43 +1270,43 @@ void dec_prm_fx( IGFDecReadData( st->hIGFDec, st, IGF_GRID_LB_NORM, 1 ); } - nbits_tcx = sub(nbits_tcx, sub(st->next_bit_pos, n)); - + nbits_tcx = sub( nbits_tcx, sub( st->next_bit_pos, n ) ); } - nbits_tcx = sub(st->bits_frame_core, sub(st->next_bit_pos, start_bit_pos)); - IF (hTcxDec->tcx_lpc_shaped_ari != 0) + nbits_tcx = sub( st->bits_frame_core, sub( st->next_bit_pos, start_bit_pos ) ); + IF( hTcxDec->tcx_lpc_shaped_ari != 0 ) { - prm[j++] = nbits_tcx; /* store length of buffer */ move16(); + prm[j++] = nbits_tcx; /* store length of buffer */ + move16(); prms = &prm[j]; - FOR (ix = 0; ix < nbits_tcx; ix++) + FOR( ix = 0; ix < nbits_tcx; ix++ ) { - prms[ix] = get_next_indice_1(st); + prms[ix] = get_next_indice_1( st ); move16(); } - set16_fx(prms+nbits_tcx, 1, 32); - j = add(j, nbits_tcx); + set16_fx( prms + nbits_tcx, 1, 32 ); + j = add( j, nbits_tcx ); } ELSE { phm_cfg = NULL; move16(); - if (flag_ctx_hm) + if ( flag_ctx_hm ) { phm_cfg = &hm_cfg; move16(); } - hTcxDec->resQBits[0] = ACcontextMapping_decode2_no_mem_s17_LC(st, prm+j, lgFB, nbits_tcx,NPRM_RESQ*st->hTcxCfg->resq,phm_cfg); + hTcxDec->resQBits[0] = ACcontextMapping_decode2_no_mem_s17_LC( st, prm + j, lgFB, nbits_tcx, NPRM_RESQ * st->hTcxCfg->resq, phm_cfg ); move16(); - j = add(j, lg); + j = add( j, lg ); } } test(); test(); - IF( GE_16(st->rf_frame_type,RF_TCXFD)&&LE_16(st->rf_frame_type,RF_TCXTD2)&&EQ_16(st->use_partial_copy,1)) + IF( GE_16( st->rf_frame_type, RF_TCXFD ) && LE_16( st->rf_frame_type, RF_TCXTD2 ) && EQ_16( st->use_partial_copy, 1 ) ) { /* classification */ - ind = get_next_indice(st, 2); + ind = get_next_indice( st, 2 ); st->clas_dec = ONSET; move16(); @@ -1319,9 +1315,9 @@ void dec_prm_fx( st->clas_dec = UNVOICED_CLAS; move16(); } - ELSE IF( EQ_16(ind, 1)) + ELSE IF( EQ_16( ind, 1 ) ) { - IF( GE_16(st->last_good, VOICED_TRANSITION)) + IF( GE_16( st->last_good, VOICED_TRANSITION ) ) { st->clas_dec = VOICED_TRANSITION; move16(); @@ -1332,35 +1328,35 @@ void dec_prm_fx( move16(); } } - ELSE IF( EQ_16(ind, 2)) + ELSE IF( EQ_16( ind, 2 ) ) { st->clas_dec = VOICED_CLAS; move16(); } - IF( EQ_16(st->rf_frame_type, RF_TCXFD)) + IF( EQ_16( st->rf_frame_type, RF_TCXFD ) ) { /* TCX Gain = 7 bits */ - hTcxDec->old_gaintcx_bfi = get_next_indice(st, 7); + hTcxDec->old_gaintcx_bfi = get_next_indice( st, 7 ); } ELSE { /* LTP data */ - IF(hTcxLtpDec->tcxltp != 0 ) + IF( hTcxLtpDec->tcxltp != 0 ) { - IF( EQ_16(st->rf_frame_type, RF_TCXTD2)||EQ_16(st->rf_frame_type,RF_TCXTD1)) + IF( EQ_16( st->rf_frame_type, RF_TCXTD2 ) || EQ_16( st->rf_frame_type, RF_TCXTD1 ) ) { prm_ltp[0] = 1; move16(); /* LTP active*/ - prm_ltp[1] = get_next_indice(st, 9); + prm_ltp[1] = get_next_indice( st, 9 ); prm_ltp[2] = 3; move16(); /* max ampl. quantizer output (2bits), anyway not used later*/ IF( st->prev_bfi == 0 ) { st->BER_detect = st->BER_detect | - tcx_ltp_decode_params(&prm_ltp[0], &(hTcxLtpDec->tcxltp_pitch_int), &(hTcxLtpDec->tcxltp_pitch_fr), &(hTcxLtpDec->tcxltp_gain), - st->pit_min, st->pit_fr1, st->pit_fr2, st->pit_max, st->pit_res_max ); + tcx_ltp_decode_params( &prm_ltp[0], &( hTcxLtpDec->tcxltp_pitch_int ), &( hTcxLtpDec->tcxltp_pitch_fr ), &( hTcxLtpDec->tcxltp_gain ), + st->pit_min, st->pit_fr1, st->pit_fr2, st->pit_max, st->pit_res_max ); hTcxDec->tcxltp_last_gain_unmodified = hTcxLtpDec->tcxltp_gain; move16(); @@ -1374,100 +1370,99 @@ void dec_prm_fx( /*--------------------------------------------------------------------------------* * TCX10 *--------------------------------------------------------------------------------*/ - IF ( EQ_16(st->core, TCX_10_CORE)) + IF( EQ_16( st->core, TCX_10_CORE ) ) { Word16 tcxltp_prm_0 = 0; Word16 tcxltp_prm_1 = 0; Word16 tcxltp_prm_2 = 0; - Word16 nbits_igf = 0; + Word16 nbits_igf = 0; move16(); move16(); move16(); move16(); move16(); /* read IGF payload */ - IF (st->igf) + IF( st->igf ) { n = st->next_bit_pos; move16(); - IGFDecReadLevel( st->hIGFDec, st, IGF_GRID_LB_SHORT, 1); - IGFDecReadData( st->hIGFDec, st, IGF_GRID_LB_SHORT, 1); + IGFDecReadLevel( st->hIGFDec, st, IGF_GRID_LB_SHORT, 1 ); + IGFDecReadData( st->hIGFDec, st, IGF_GRID_LB_SHORT, 1 ); IGFDecStoreTCX10SubFrameData( st->hIGFDec, 0 ); - IGFDecReadLevel( st->hIGFDec, st, IGF_GRID_LB_SHORT, 0); - IGFDecReadData( st->hIGFDec, st, IGF_GRID_LB_SHORT, 0); + IGFDecReadLevel( st->hIGFDec, st, IGF_GRID_LB_SHORT, 0 ); + IGFDecReadData( st->hIGFDec, st, IGF_GRID_LB_SHORT, 0 ); IGFDecStoreTCX10SubFrameData( st->hIGFDec, 1 ); - nbits_igf = sub(st->next_bit_pos, n); - + nbits_igf = sub( st->next_bit_pos, n ); } - FOR (k = 0; k < 2; k++) + FOR( k = 0; k < 2; k++ ) { flag_ctx_hm = 0; move16(); - prm = param + (k*DEC_NPRM_DIV); + prm = param + ( k * DEC_NPRM_DIV ); j = 0; move16(); - nbits_tcx = sub(st->next_bit_pos, start_bit_pos); + nbits_tcx = sub( st->next_bit_pos, start_bit_pos ); test(); - IF (st->enablePlcWaveadjust && k) + IF( st->enablePlcWaveadjust && k ) { - st->tonality_flag = get_next_indice(st, 1); + st->tonality_flag = get_next_indice( st, 1 ); move16(); } /* TCX Gain = 7 bits */ - prm[j++] = get_next_indice(st, 7); + prm[j++] = get_next_indice( st, 7 ); move16(); /* TCX Noise Filling = NBITS_NOISE_FILL_LEVEL bits */ - prm[j++] = get_next_indice(st, NBITS_NOISE_FILL_LEVEL); + prm[j++] = get_next_indice( st, NBITS_NOISE_FILL_LEVEL ); move16(); /* LTP data */ test(); test(); - IF ( (k == 0) && ((hTcxLtpDec->tcxltp != 0) || (GT_32(st->sr_core, 25600)))) + IF( ( k == 0 ) && ( ( hTcxLtpDec->tcxltp != 0 ) || ( GT_32( st->sr_core, 25600 ) ) ) ) { - prm[j] = get_next_indice(st, 1); + prm[j] = get_next_indice( st, 1 ); move16(); - IF ( prm[j] ) + IF( prm[j] ) { - prm[j+1] = get_next_indice(st, 9); + prm[j + 1] = get_next_indice( st, 9 ); move16(); - prm[j+2] = get_next_indice(st, 2); + prm[j + 2] = get_next_indice( st, 2 ); move16(); tcxltp_prm_0 = prm[j]; move16(); - tcxltp_prm_1 = prm[j+1]; + tcxltp_prm_1 = prm[j + 1]; move16(); - tcxltp_prm_2 = prm[j+2]; + tcxltp_prm_2 = prm[j + 2]; move16(); } st->BER_detect = st->BER_detect | - tcx_ltp_decode_params(&prm[j], - &(hTcxLtpDec->tcxltp_pitch_int), - &(hTcxLtpDec->tcxltp_pitch_fr), - &(hTcxLtpDec->tcxltp_gain), - st->pit_min, - st->pit_fr1, - st->pit_fr2, - st->pit_max, - st->pit_res_max); + tcx_ltp_decode_params( &prm[j], + &( hTcxLtpDec->tcxltp_pitch_int ), + &( hTcxLtpDec->tcxltp_pitch_fr ), + &( hTcxLtpDec->tcxltp_gain ), + st->pit_min, + st->pit_fr1, + st->pit_fr2, + st->pit_max, + st->pit_res_max ); hTcxDec->tcxltp_last_gain_unmodified = hTcxLtpDec->tcxltp_gain; move16(); hTcxDec->tcx_hm_LtpPitchLag = -1; move16(); - j = add(j, 3); + j = add( j, 3 ); } ELSE { @@ -1480,20 +1475,20 @@ void dec_prm_fx( } /* TCX spectral data */ - lg = shr(L_frame, 1); - lgFB = shr(st->hTcxCfg->tcx_coded_lines, 1); + lg = shr( L_frame, 1 ); + lgFB = shr( st->hTcxCfg->tcx_coded_lines, 1 ); test(); - IF ( k == 0 && st->last_core_from_bs == ACELP_CORE ) + IF( k == 0 && st->last_core_from_bs == ACELP_CORE ) { /* ACE->TCX transition */ - lg = add(lg, st->hTcxCfg->tcx_offset); - if(st->hTcxCfg->lfacNext<0) + lg = add( lg, st->hTcxCfg->tcx_offset ); + if ( st->hTcxCfg->lfacNext < 0 ) { - lg = sub(lg,st->hTcxCfg->lfacNext); + lg = sub( lg, st->hTcxCfg->lfacNext ); } - lgFB = add(lgFB, shr(lgFB, 1)); + lgFB = add( lgFB, shr( lgFB, 1 ) ); } /* TNS data */ @@ -1502,73 +1497,75 @@ void dec_prm_fx( nTnsBits = 0; move16(); - IF (st->hTcxCfg->fIsTNSAllowed) + IF( st->hTcxCfg->fIsTNSAllowed ) { - IF( EQ_16(st->last_core_from_bs, ACELP_CORE)&&(k==0)) + IF( EQ_16( st->last_core_from_bs, ACELP_CORE ) && ( k == 0 ) ) { st->BER_detect = 1; - st->last_core = TCX_20_CORE; move16(); - st->last_core_from_bs = TCX_20_CORE; move16(); + st->last_core = TCX_20_CORE; + move16(); + st->last_core_from_bs = TCX_20_CORE; + move16(); } test(); test(); - SetTnsConfig(st->hTcxCfg, 0, (st->last_core_from_bs == ACELP_CORE) && (k == 0)); + SetTnsConfig( st->hTcxCfg, 0, ( st->last_core_from_bs == ACELP_CORE ) && ( k == 0 ) ); - ReadTnsData(st->hTcxCfg->pCurrentTnsConfig, st, &nTnsBits, prm+j, &nTnsParams); - j = add(j, nTnsParams); + ReadTnsData( st->hTcxCfg->pCurrentTnsConfig, st, &nTnsBits, prm + j, &nTnsParams ); + j = add( j, nTnsParams ); } - hm_size = shl(mult(st->TcxBandwidth, lgFB), 1); + hm_size = shl( mult( st->TcxBandwidth, lgFB ), 1 ); /*compute target bits*/ - nbits_tcx = sub(shr(sub(add(sub(sub(st->bits_frame_core, st->bits_common), nbits_igf), 1), k), 1), sub(sub(st->next_bit_pos, start_bit_pos), nbits_tcx)); + nbits_tcx = sub( shr( sub( add( sub( sub( st->bits_frame_core, st->bits_common ), nbits_igf ), 1 ), k ), 1 ), sub( sub( st->next_bit_pos, start_bit_pos ), nbits_tcx ) ); /*Context HM flag*/ test(); test(); - IF ( st->hTcxCfg->ctx_hm && !(st->last_core_from_bs == ACELP_CORE && k == 0) ) + IF( st->hTcxCfg->ctx_hm && !( st->last_core_from_bs == ACELP_CORE && k == 0 ) ) { - prm[j] = get_next_indice_fx(st, 1); + prm[j] = get_next_indice_fx( st, 1 ); move16(); - nbits_tcx = sub(nbits_tcx, 1); + nbits_tcx = sub( nbits_tcx, 1 ); move16(); - IF (prm[j]) /* Read PeriodicityIndex */ + IF( prm[j] ) /* Read PeriodicityIndex */ { - Word16 NumIndexBits = DecodeIndex_fx(st,(Word16)GE_16(hm_size , 256),prm+j+1); + Word16 NumIndexBits = DecodeIndex_fx( st, (Word16) GE_16( hm_size, 256 ), prm + j + 1 ); flag_ctx_hm = 1; move16(); - ConfigureContextHm(lgFB,nbits_tcx,*(prm+j+1),-1,&hm_cfg); + ConfigureContextHm( lgFB, nbits_tcx, *( prm + j + 1 ), -1, &hm_cfg ); - nbits_tcx = sub(nbits_tcx, NumIndexBits); + nbits_tcx = sub( nbits_tcx, NumIndexBits ); } } - j = add(j, NPRM_CTX_HM); + j = add( j, NPRM_CTX_HM ); phm_cfg = NULL; move16(); - if (flag_ctx_hm) + if ( flag_ctx_hm ) { phm_cfg = &hm_cfg; move16(); } - hTcxDec->resQBits[k] = ACcontextMapping_decode2_no_mem_s17_LC(st, prm+j,lgFB,nbits_tcx,NPRM_RESQ*st->hTcxCfg->resq,phm_cfg); + hTcxDec->resQBits[k] = ACcontextMapping_decode2_no_mem_s17_LC( st, prm + j, lgFB, nbits_tcx, NPRM_RESQ * st->hTcxCfg->resq, phm_cfg ); move16(); - j = add(j, lgFB); + j = add( j, lgFB ); } /* k, window index */ } - IF(!st->use_partial_copy) + IF( !st->use_partial_copy ) { - IF (LT_16(sub(*total_nbbits, bitsRead[0]), sub(st->next_bit_pos, start_bit_pos))) + IF( LT_16( sub( *total_nbbits, bitsRead[0] ), sub( st->next_bit_pos, start_bit_pos ) ) ) { st->BER_detect = 1; move16(); - st->next_bit_pos = add(start_bit_pos, sub(*total_nbbits, bitsRead[0])); + st->next_bit_pos = add( start_bit_pos, sub( *total_nbbits, bitsRead[0] ) ); } - bitsRead[0] = sub(st->next_bit_pos, start_bit_pos); + bitsRead[0] = sub( st->next_bit_pos, start_bit_pos ); move16(); } diff --git a/lib_dec/dec_tcx.c b/lib_dec/dec_tcx.c index 0c7d6c194..4692a482e 100644 --- a/lib_dec/dec_tcx.c +++ b/lib_dec/dec_tcx.c @@ -430,7 +430,7 @@ void IMDCT( } tcx_windowing_synthesis_current_frame_flt( win, tcx_aldo_window_2, tcx_mdct_window_half, tcx_mdct_window_minimum, L_ola, tcx_mdct_window_half_length, tcx_mdct_window_min_length, 0, - /* left_rect */ MIN_OVERLAP, /* left_mode */ acelp_zir, hTcxDec->old_syn_Overl_float, syn_Overl_TDAC, st->old_Aq_12_8, tcx_mdct_window_trans, L_win, tcx_offset < 0 ? -tcx_offset : 0, 1, /* st->last_mode_bfi */ 0, /* st->last_is_cng */ fullbandScale ); + /* left_rect */ MIN_OVERLAP, /* left_mode */ acelp_zir, hTcxDec->old_syn_Overl_float, syn_Overl_TDAC, st->old_Aq_12_8, tcx_mdct_window_trans, L_win, tcx_offset < 0 ? -tcx_offset : 0, 1, /* st->last_mode_bfi */ 0, /* st->last_is_cng */ fullbandScale ); tcx_windowing_synthesis_past_frame_flt( xn_buf + ( overlap >> 1 ) + L_win - ( L_ola >> 1 ), tcx_aldo_window_1_trunc, tcx_mdct_window_half, tcx_mdct_window_minimum, L_ola, tcx_mdct_window_half_length, tcx_mdct_window_min_length, 2 ); @@ -561,7 +561,7 @@ void IMDCT( mvr2r( xn_buf + overlap / 2 + 2 * acelp_mem_len, &buf[0], analysis_len ); /* get LPC from that signal part to use for acelp zir smoothing */ - + float window_buf[L_FRAME_MAX / 4]; float r[M + 1]; ham_cos_window_flt( &window_buf[0], analysis_len / 2, analysis_len / 2 ); @@ -981,7 +981,7 @@ void decoder_tcx_invQ( set_zero( h1, L_SUBFR + 1 ); set_zero( mem, M ); h1[0] = 1.0f; - syn_filt( Ap, M, h1, h1, L_SUBFR, mem, 0 ); /* impulse response of LPC */ + syn_filt( Ap, M, h1, h1, L_SUBFR, mem, 0 ); /* impulse response of LPC */ deemph( h1, st->preemph_fac_float, L_SUBFR, &tmp2 ); /* impulse response of deemph */ } @@ -1583,7 +1583,7 @@ void decoder_tcx_tns( #ifdef IVAS_FLOAT_FIXED void decoder_tcx_tns_fx( - Decoder_State *st, /* i/o: coder memory state */ + Decoder_State *st, /* i/o: coder memory state */ const Word16 L_frame_glob, /* i : frame length */ const Word16 L_spec, const Word16 L_frame, @@ -1606,30 +1606,30 @@ void decoder_tcx_tns_fx( L = L_frameTCX; move16(); - IF ( EQ_16( L_frame, shr(st->L_frame, 1) ) && NE_16(st->tcxonly, 0) ) + IF( EQ_16( L_frame, shr( st->L_frame, 1 ) ) && NE_16( st->tcxonly, 0 ) ) { - IF ( NE_16(frame_cnt, 0) && EQ_16(bfi, 0) && NE_16(st->last_core, ACELP_CORE )) + IF( NE_16( frame_cnt, 0 ) && EQ_16( bfi, 0 ) && NE_16( st->last_core, ACELP_CORE ) ) { /* fix sub-window overlap */ hTcxCfg->tcx_last_overlap_mode = hTcxCfg->tcx_curr_overlap_mode; move16(); } - IF ( ( NE_16(hTcxCfg->fIsTNSAllowed, 0) && NE_16(fUseTns, 0) && NE_16(bfi, 1) ) || GT_16( L_spec, L_frameTCX ) ) + IF( ( NE_16( hTcxCfg->fIsTNSAllowed, 0 ) && NE_16( fUseTns, 0 ) && NE_16( bfi, 1 ) ) || GT_16( L_spec, L_frameTCX ) ) { L = L_spec; move16(); } - IF ( ( EQ_16( bfi, 0 ) && ( NE_16( hTcxCfg->tcx_last_overlap_mode, FULL_OVERLAP ) || - ( EQ_16( hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) && EQ_16( frame_cnt, 0 ) && EQ_16( index, 0 ) ) ) ) || - ( NE_16( bfi, 0 ) && ( NE_16( hTcxCfg->tcx_last_overlap_mode, FULL_OVERLAP ) && - NE_16( hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) ) ) ) + IF( ( EQ_16( bfi, 0 ) && ( NE_16( hTcxCfg->tcx_last_overlap_mode, FULL_OVERLAP ) || + ( EQ_16( hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) && EQ_16( frame_cnt, 0 ) && EQ_16( index, 0 ) ) ) ) || + ( NE_16( bfi, 0 ) && ( NE_16( hTcxCfg->tcx_last_overlap_mode, FULL_OVERLAP ) && + NE_16( hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) ) ) ) { isTCX5 = 1; move16(); - tcx5SpectrumDeinterleaving_fx( shr(L, 1), x_fx ); + tcx5SpectrumDeinterleaving_fx( shr( L, 1 ), x_fx ); } } @@ -1638,38 +1638,37 @@ void decoder_tcx_tns_fx( *-----------------------------------------------------------*/ - IF ( NE_16(hTcxCfg->fIsTNSAllowed, 0) && NE_16(fUseTns, 0) && NE_16(bfi, 1) && EQ_16(tnsData->tnsOnWhitenedSpectra, whitenedDomain) ) + IF( NE_16( hTcxCfg->fIsTNSAllowed, 0 ) && NE_16( fUseTns, 0 ) && NE_16( bfi, 1 ) && EQ_16( tnsData->tnsOnWhitenedSpectra, whitenedDomain ) ) { /* Apply TNS to get the reconstructed signal */ SetTnsConfig( hTcxCfg, L_frame_glob == st->L_frame, ( st->last_core == ACELP_CORE ) && ( frame_cnt == 0 ) ); - IF ( EQ_16( L_frame, shr(st->L_frame, 1) ) && NE_16(st->tcxonly, 0) && NE_16(isTCX5, 0) ) + IF( EQ_16( L_frame, shr( st->L_frame, 1 ) ) && NE_16( st->tcxonly, 0 ) && NE_16( isTCX5, 0 ) ) { - tcx5TnsGrouping_fx( shr(L, 1), shr(hTcxCfg->tnsConfig[0][0].iFilterBorders[0], 1), x_fx ); - + tcx5TnsGrouping_fx( shr( L, 1 ), shr( hTcxCfg->tnsConfig[0][0].iFilterBorders[0], 1 ), x_fx ); } ApplyTnsFilter( hTcxCfg->pCurrentTnsConfig, tnsData, x_fx, 0 ); - IF ( EQ_16( L_frame, shr(st->L_frame, 1) ) && NE_16(st->tcxonly, 0) && NE_16(isTCX5, 0) ) + IF( EQ_16( L_frame, shr( st->L_frame, 1 ) ) && NE_16( st->tcxonly, 0 ) && NE_16( isTCX5, 0 ) ) { - IF ( EQ_16(st->element_mode, EVS_MONO) || LT_16(L_spec, L_frameTCX) ) /* todo: this is temporary to maintain EVS BE, this is a bug and should be fixed also for EVS (see issue 13) */ + IF( EQ_16( st->element_mode, EVS_MONO ) || LT_16( L_spec, L_frameTCX ) ) /* todo: this is temporary to maintain EVS BE, this is a bug and should be fixed also for EVS (see issue 13) */ { - tcx5TnsUngrouping_fx( shr(L_frameTCX, 1), shr(hTcxCfg->tnsConfig[0][0].iFilterBorders[0], 1), x_fx, DEC ); + tcx5TnsUngrouping_fx( shr( L_frameTCX, 1 ), shr( hTcxCfg->tnsConfig[0][0].iFilterBorders[0], 1 ), x_fx, DEC ); } ELSE { - tcx5TnsUngrouping_fx( shr(L, 1), shr(hTcxCfg->tnsConfig[0][0].iFilterBorders[0], 1), x_fx, DEC ); + tcx5TnsUngrouping_fx( shr( L, 1 ), shr( hTcxCfg->tnsConfig[0][0].iFilterBorders[0], 1 ), x_fx, DEC ); } } } - IF ( NE_16(whitenedDomain, 0) && NE_16(isTCX5, 0) ) + IF( NE_16( whitenedDomain, 0 ) && NE_16( isTCX5, 0 ) ) { - tcx5SpectrumInterleaving_fx( shr(L, 1), x_fx ); + tcx5SpectrumInterleaving_fx( shr( L, 1 ), x_fx ); } /* restore index */ - IF ( EQ_16( L_frame, shr(st->L_frame, 1) ) && NE_16(st->tcxonly, 0) && NE_16(frame_cnt, 0) && EQ_16(bfi, 0) && NE_16(st->last_core, ACELP_CORE) ) + IF( EQ_16( L_frame, shr( st->L_frame, 1 ) ) && NE_16( st->tcxonly, 0 ) && NE_16( frame_cnt, 0 ) && EQ_16( bfi, 0 ) && NE_16( st->last_core, ACELP_CORE ) ) { /* restore sub-window overlap */ hTcxCfg->tcx_last_overlap_mode = index; @@ -1846,7 +1845,7 @@ void decoder_tcx_imdct( { mvr2r( x, xn_bufFB, max( L_spec, max( L_frame, L_frameTCX ) ) ); - + IMDCT( xn_bufFB, hTcxDec->syn_Overl_float, hTcxDec->syn_Overl_TDAC_float, xn_buf, hTcxCfg->tcx_aldo_window_1_trunc_flt, hTcxCfg->tcx_aldo_window_2_flt, hTcxCfg->tcx_mdct_window_half_flt, hTcxCfg->tcx_mdct_window_minimum_flt, hTcxCfg->tcx_mdct_window_trans_flt, hTcxCfg->tcx_mdct_window_half_length, hTcxCfg->tcx_mdct_window_min_length, index, kernelType, left_rect, tcx_offset, overlap, L_frame, L_frameTCX, max( L_frameTCX, L_spec ) >> 1, L_frame_glob, frame_cnt, bfi, st->hHQ_core->old_outLB, 0, st, 0, acelp_zir ); } @@ -1904,7 +1903,7 @@ void decoder_tcx_imdct( #ifdef IVAS_FLOAT_FIXED void decoder_tcx_imdct_fx( - Decoder_State *st, /* i/o: coder memory state */ + Decoder_State *st, /* i/o: coder memory state */ const Word16 L_frame_glob, /* i : frame length */ const Word16 L_frameTCX_glob, const Word16 L_spec, @@ -1913,14 +1912,14 @@ void decoder_tcx_imdct_fx( const Word16 L_frame, const Word16 L_frameTCX, const Word16 left_rect, - Word32 x_fx[N_MAX], //Q(11) + Word32 x_fx[N_MAX], // Q(11) Word16 q_x, - Word16 xn_buf_fx[], //Q(-2) + Word16 xn_buf_fx[], // Q(-2) Word16 q_win, - const UWord16 kernelType, /* i : TCX transform kernel type */ - const Word16 fUseTns, /* i : flag that is set if TNS data is present */ - Word16 synth_fx[], //Q(-2) /* i/o: synth[-M..L_frame] */ - Word16 synthFB_fx[], //Q(-2) + const UWord16 kernelType, /* i : TCX transform kernel type */ + const Word16 fUseTns, /* i : flag that is set if TNS data is present */ + Word16 synth_fx[], // Q(-2) /* i/o: synth[-M..L_frame] */ + Word16 synthFB_fx[], // Q(-2) const Word16 bfi, /* i : Bad frame indicator */ const Word16 frame_cnt, /* i : frame counter in the super frame */ const Word16 sba_dirac_stereo_flag /* i : signal stereo output for SBA DirAC */ @@ -1954,25 +1953,25 @@ void decoder_tcx_imdct_fx( index = hTcxCfg->tcx_last_overlap_mode; /* backup last TCX overlap mode */ move16(); - IF ( EQ_16( L_frame, shr(st->L_frame, 1) ) && NE_16(st->tcxonly, 0) && NE_16(frame_cnt, 0) && EQ_16(bfi, 0) && NE_16(st->last_core, ACELP_CORE) ) + IF( EQ_16( L_frame, shr( st->L_frame, 1 ) ) && NE_16( st->tcxonly, 0 ) && NE_16( frame_cnt, 0 ) && EQ_16( bfi, 0 ) && NE_16( st->last_core, ACELP_CORE ) ) { /* fix sub-window overlap */ hTcxCfg->tcx_last_overlap_mode = hTcxCfg->tcx_curr_overlap_mode; move16(); } - IF ( NE_16(st->igf, 0) ) + IF( NE_16( st->igf, 0 ) ) { proc = st->hIGFDec->flatteningTrigger; move16(); - IF ( proc && fUseTns != 0 ) + IF( proc && fUseTns != 0 ) { proc = 0; move16(); } - IF ( proc ) + IF( proc ) { startLine = st->hIGFDec->infoIGFStartLine; @@ -1989,29 +1988,29 @@ void decoder_tcx_imdct_fx( move16(); /* interleave again for ITF */ - IF ( EQ_16( L_frame, shr(st->L_frame, 1) ) && st->tcxonly ) + IF( EQ_16( L_frame, shr( st->L_frame, 1 ) ) && st->tcxonly ) { - IF ( ( hTcxCfg->fIsTNSAllowed && NE_16(fUseTns, 0) && NE_16(bfi, 1) ) || GT_16( L_spec, L_frameTCX ) ) + IF( ( hTcxCfg->fIsTNSAllowed && NE_16( fUseTns, 0 ) && NE_16( bfi, 1 ) ) || GT_16( L_spec, L_frameTCX ) ) { L = L_spec; move16(); } - IF ( ( EQ_16( bfi, 0 ) && ( NE_16( hTcxCfg->tcx_last_overlap_mode, FULL_OVERLAP ) || - ( EQ_16( hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) && EQ_16( frame_cnt, 0 ) && EQ_16( index, 0 ) ) ) ) || - ( NE_16( bfi, 0 ) && ( NE_16( hTcxCfg->tcx_last_overlap_mode, FULL_OVERLAP ) && - NE_16( hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) ) ) ) + IF( ( EQ_16( bfi, 0 ) && ( NE_16( hTcxCfg->tcx_last_overlap_mode, FULL_OVERLAP ) || + ( EQ_16( hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) && EQ_16( frame_cnt, 0 ) && EQ_16( index, 0 ) ) ) ) || + ( NE_16( bfi, 0 ) && ( NE_16( hTcxCfg->tcx_last_overlap_mode, FULL_OVERLAP ) && + NE_16( hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) ) ) ) { isTCX5 = 1; move16(); - tcx5SpectrumInterleaving_fx( shr(L, 1), x_fx ); + tcx5SpectrumInterleaving_fx( shr( L, 1 ), x_fx ); } } - FOR ( j = startLine; j < endLine; j++ ) + FOR( j = startLine; j < endLine; j++ ) { - IF ( EQ_16(st->hIGFDec->flag_sparse[j - IGF_START_MN], 2) ) + IF( EQ_16( st->hIGFDec->flag_sparse[j - IGF_START_MN], 2 ) ) { x_itf_fx[j - IGF_START_MN] = x_fx[j]; move32(); @@ -2020,13 +2019,13 @@ void decoder_tcx_imdct_fx( } } - ITF_Detect_ivas_fx( x_fx + IGF_START_MN, startLine, endLine, 8 /*maxOrder*/, A_itf_fx, &q_a_itf, &predictionGain_fx, &curr_order,shl(x_e, 1) ); + ITF_Detect_ivas_fx( x_fx + IGF_START_MN, startLine, endLine, 8 /*maxOrder*/, A_itf_fx, &q_a_itf, &predictionGain_fx, &curr_order, shl( x_e, 1 ) ); ITF_Apply_fx( x_fx, startLine, endLine, A_itf_fx, q_a_itf, curr_order ); - FOR ( j = startLine; j < endLine; j++ ) + FOR( j = startLine; j < endLine; j++ ) { - IF ( st->hIGFDec->flag_sparse[j - IGF_START_MN] == 2 ) + IF( st->hIGFDec->flag_sparse[j - IGF_START_MN] == 2 ) { x_fx[j] = x_itf_fx[j - IGF_START_MN]; move32(); @@ -2034,9 +2033,9 @@ void decoder_tcx_imdct_fx( } /* deinterleave */ - IF ( NE_16(isTCX5, 0) ) + IF( NE_16( isTCX5, 0 ) ) { - tcx5SpectrumDeinterleaving_fx( shr(L, 1), x_fx ); + tcx5SpectrumDeinterleaving_fx( shr( L, 1 ), x_fx ); } } } @@ -2047,13 +2046,13 @@ void decoder_tcx_imdct_fx( *-----------------------------------------------------------*/ - IF ( EQ_16(st->element_mode, IVAS_CPE_MDCT) ) + IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) { set32_fx( x_tmp_fx, 0, L_FRAME_PLUS ); mvl2l( x_fx, x_tmp_fx, s_min( L_FRAME48k, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ) ); mvl2l( x_fx, xn_bufFB_fx, s_min( L_FRAME48k, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ) ); } - ELSE IF ( EQ_16(st->element_mode, EVS_MONO) ) + ELSE IF( EQ_16( st->element_mode, EVS_MONO ) ) { mvl2l( x_fx, xn_bufFB_fx, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ); } @@ -2063,56 +2062,59 @@ void decoder_tcx_imdct_fx( mvl2l( x_fx, xn_bufFB_fx, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ); } - IF ( NE_16(st->igf, 0) ) + IF( NE_16( st->igf, 0 ) ) { set32_fx( xn_bufFB_fx + st->hIGFDec->infoIGFStartLine, 0, L_frameTCX - st->hIGFDec->infoIGFStartLine ); } - IF ( st->element_mode != IVAS_CPE_DFT && !sba_dirac_stereo_flag ) + IF( st->element_mode != IVAS_CPE_DFT && !sba_dirac_stereo_flag ) { IMDCT_ivas_fx( xn_bufFB_fx, q_x, hTcxDec->syn_Overl, hTcxDec->syn_Overl_TDAC, xn_buf_fx, hTcxCfg->tcx_aldo_window_1, hTcxCfg->tcx_aldo_window_1_trunc, hTcxCfg->tcx_aldo_window_2, - hTcxCfg->tcx_mdct_window_half, hTcxCfg->tcx_mdct_window_minimum, hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_half_length, hTcxCfg->tcx_mdct_window_min_length, index, - kernelType, left_rect, tcx_offset, overlap, L_frame, L_frameTCX, shr(s_max( L_frameTCX, L_spec ), 1), L_frame_glob, frame_cnt, bfi, st->hHQ_core->old_out_LB_fx, 0, st, 0, acelp_zir_fx, q_win ); + hTcxCfg->tcx_mdct_window_half, hTcxCfg->tcx_mdct_window_minimum, hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_half_length, hTcxCfg->tcx_mdct_window_min_length, index, + kernelType, left_rect, tcx_offset, overlap, L_frame, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frame_glob, frame_cnt, bfi, st->hHQ_core->old_out_LB_fx, 0, st, 0, acelp_zir_fx, q_win ); } /* Generate additional comfort noise to mask potential coding artefacts */ - IF ( NE_16(st->flag_cna, 0) && NE_16(st->element_mode, IVAS_CPE_TD) && NE_16(st->element_mode, IVAS_CPE_DFT) && EQ_16(st->cna_dirac_flag, 0) ) + IF( NE_16( st->flag_cna, 0 ) && NE_16( st->element_mode, IVAS_CPE_TD ) && NE_16( st->element_mode, IVAS_CPE_DFT ) && EQ_16( st->cna_dirac_flag, 0 ) ) { generate_masking_noise_mdct_fx( x_fx, &x_e, st->hFdCngDec->hFdCngCom, L_frame ); - FOR(Word16 ind = 0; ind < L_frame; ind++) { - x_fx[ind] = L_shr(x_fx[ind], sub(31, add(x_e, q_x))); + FOR( Word16 ind = 0; ind < L_frame; ind++ ) + { + x_fx[ind] = L_shr( x_fx[ind], sub( 31, add( x_e, q_x ) ) ); } } - IF ( EQ_16(st->element_mode, IVAS_CPE_DFT) || NE_16(sba_dirac_stereo_flag, 0) ) + IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) || NE_16( sba_dirac_stereo_flag, 0 ) ) { mvl2l( x_fx, xn_bufFB_fx, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ); IMDCT_ivas_fx( xn_bufFB_fx, q_x, hTcxDec->syn_Overl, hTcxDec->syn_Overl_TDAC, xn_buf_fx, hTcxCfg->tcx_aldo_window_1, hTcxCfg->tcx_aldo_window_1_trunc, hTcxCfg->tcx_aldo_window_2, hTcxCfg->tcx_mdct_window_half, hTcxCfg->tcx_mdct_window_minimum, hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_half_length, hTcxCfg->tcx_mdct_window_min_length, index, - kernelType, left_rect, tcx_offset, overlap, L_frame, L_frameTCX, shr(s_max( L_frameTCX, L_spec ), 1), L_frame_glob, frame_cnt, bfi, st->hHQ_core->old_out_LB_fx, 0, st, 0, acelp_zir_fx, q_win ); + kernelType, left_rect, tcx_offset, overlap, L_frame, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frame_glob, frame_cnt, bfi, st->hHQ_core->old_out_LB_fx, 0, st, 0, acelp_zir_fx, q_win ); } - FOR(Word16 ind = 0; ind < L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX; ind++) { - xn_bufFB_fx_16[ind] = (Word16)L_shr(xn_bufFB_fx[ind], (q_x - q_win)); + FOR( Word16 ind = 0; ind < L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX; ind++ ) + { + xn_bufFB_fx_16[ind] = (Word16) L_shr( xn_bufFB_fx[ind], ( q_x - q_win ) ); } - IF ( NE_16(st->element_mode, EVS_MONO) ) + IF( NE_16( st->element_mode, EVS_MONO ) ) { IMDCT_ivas_fx( x_tmp_fx, q_x, hTcxDec->syn_OverlFB, hTcxDec->syn_Overl_TDACFB, xn_bufFB_fx_16, hTcxCfg->tcx_aldo_window_1_FB, hTcxCfg->tcx_aldo_window_1_FB_trunc, hTcxCfg->tcx_aldo_window_2_FB, - hTcxCfg->tcx_mdct_window_halfFB, hTcxCfg->tcx_mdct_window_minimumFB, hTcxCfg->tcx_mdct_window_transFB, hTcxCfg->tcx_mdct_window_half_lengthFB, hTcxCfg->tcx_mdct_window_min_lengthFB, index, - kernelType, left_rect, tcx_offsetFB, overlapFB, L_frameTCX, L_frameTCX, max( L_frameTCX, L_spec ) >> 1, L_frameTCX_glob, frame_cnt, bfi, st->hHQ_core->old_out_fx, 1, st, FSCALE_DENOM * L_frameTCX_glob / L_frame_glob, acelp_zir_fx, q_win ); + hTcxCfg->tcx_mdct_window_halfFB, hTcxCfg->tcx_mdct_window_minimumFB, hTcxCfg->tcx_mdct_window_transFB, hTcxCfg->tcx_mdct_window_half_lengthFB, hTcxCfg->tcx_mdct_window_min_lengthFB, index, + kernelType, left_rect, tcx_offsetFB, overlapFB, L_frameTCX, L_frameTCX, max( L_frameTCX, L_spec ) >> 1, L_frameTCX_glob, frame_cnt, bfi, st->hHQ_core->old_out_fx, 1, st, FSCALE_DENOM * L_frameTCX_glob / L_frame_glob, acelp_zir_fx, q_win ); } ELSE { - IMDCT_ivas_fx( x_fx, q_x, hTcxDec->syn_OverlFB, hTcxDec->syn_Overl_TDACFB, xn_bufFB_fx_16, hTcxCfg->tcx_aldo_window_1_FB, hTcxCfg->tcx_aldo_window_1_FB_trunc, hTcxCfg->tcx_aldo_window_2_FB, hTcxCfg->tcx_mdct_window_halfFB, hTcxCfg->tcx_mdct_window_minimumFB, hTcxCfg->tcx_mdct_window_transFB, hTcxCfg->tcx_mdct_window_half_lengthFB, hTcxCfg->tcx_mdct_window_min_lengthFB, index, - kernelType, left_rect, tcx_offsetFB, overlapFB, L_frameTCX, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frameTCX_glob, frame_cnt, bfi, st->hHQ_core->old_out_fx, 1, st, FSCALE_DENOM * L_frameTCX_glob / L_frame_glob, acelp_zir_fx, q_win ); + IMDCT_ivas_fx( x_fx, q_x, hTcxDec->syn_OverlFB, hTcxDec->syn_Overl_TDACFB, xn_bufFB_fx_16, hTcxCfg->tcx_aldo_window_1_FB, hTcxCfg->tcx_aldo_window_1_FB_trunc, hTcxCfg->tcx_aldo_window_2_FB, hTcxCfg->tcx_mdct_window_halfFB, hTcxCfg->tcx_mdct_window_minimumFB, hTcxCfg->tcx_mdct_window_transFB, hTcxCfg->tcx_mdct_window_half_lengthFB, hTcxCfg->tcx_mdct_window_min_lengthFB, index, + kernelType, left_rect, tcx_offsetFB, overlapFB, L_frameTCX, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frameTCX_glob, frame_cnt, bfi, st->hHQ_core->old_out_fx, 1, st, FSCALE_DENOM * L_frameTCX_glob / L_frame_glob, acelp_zir_fx, q_win ); } - FOR(Word16 ind = 0; ind < L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX; ind++) { - xn_bufFB_fx[ind] = L_shl(xn_bufFB_fx_16[ind], (q_x - q_win)); + FOR( Word16 ind = 0; ind < L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX; ind++ ) + { + xn_bufFB_fx[ind] = L_shl( xn_bufFB_fx_16[ind], ( q_x - q_win ) ); } - IF ( EQ_16(bfi, 0) ) + IF( EQ_16( bfi, 0 ) ) { Word16 res_m, res_e = 0; st->second_last_tns_active = st->last_tns_active; @@ -2123,44 +2125,45 @@ void decoder_tcx_imdct_fx( move32(); hTcxDec->tcxltp_second_last_pitch = st->old_fpitch; move32(); - res_m = BASOP_Util_Divide1616_Scale(hTcxLtpDec->tcxltp_pitch_fr, st->pit_res_max, &res_e); - st->old_fpitch = L_add(L_shl(hTcxLtpDec->tcxltp_pitch_int, 16), L_shl(res_m, add(res_e, 1))); + res_m = BASOP_Util_Divide1616_Scale( hTcxLtpDec->tcxltp_pitch_fr, st->pit_res_max, &res_e ); + st->old_fpitch = L_add( L_shl( hTcxLtpDec->tcxltp_pitch_int, 16 ), L_shl( res_m, add( res_e, 1 ) ) ); - IF ( EQ_16(st->element_mode, IVAS_CPE_MDCT) ) + IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) { - res_m = BASOP_Util_Divide1616_Scale(L_frame_glob, L_FRAME, &res_e); - st->old_fpitch = L_shl(Mpy_32_16_1(st->old_fpitch, res_m), res_e); + res_m = BASOP_Util_Divide1616_Scale( L_frame_glob, L_FRAME, &res_e ); + st->old_fpitch = L_shl( Mpy_32_16_1( st->old_fpitch, res_m ), res_e ); } - IF ( GT_16(st->element_mode, EVS_MONO) ) + IF( GT_16( st->element_mode, EVS_MONO ) ) { - res_m = BASOP_Util_Divide1616_Scale(L_frameTCX_glob, L_frame_glob, &res_e); - st->old_fpitchFB = L_shl(Mpy_32_16_1(st->old_fpitch, res_m), res_e); + res_m = BASOP_Util_Divide1616_Scale( L_frameTCX_glob, L_frame_glob, &res_e ); + st->old_fpitchFB = L_shl( Mpy_32_16_1( st->old_fpitch, res_m ), res_e ); } ELSE { - res_m = BASOP_Util_Divide1616_Scale(L_frameTCX, L_frame, &res_e); - st->old_fpitchFB = L_shl(Mpy_32_16_1(st->old_fpitch, res_m), res_e); + res_m = BASOP_Util_Divide1616_Scale( L_frameTCX, L_frame, &res_e ); + st->old_fpitchFB = L_shl( Mpy_32_16_1( st->old_fpitch, res_m ), res_e ); } } /* Update old_syn_overl */ - IF ( EQ_16(hTcxCfg->last_aldo, 0) ) + IF( EQ_16( hTcxCfg->last_aldo, 0 ) ) { mvs2s( xn_buf_fx + L_frame, hTcxDec->syn_Overl, overlap ); - FOR(Word16 ind = 0; ind < overlapFB; ind++) { - hTcxDec->syn_OverlFB[ind] = (Word16)L_shr(xn_bufFB_fx[ add(ind, L_frameTCX) ], sub(q_x, q_win)); + FOR( Word16 ind = 0; ind < overlapFB; ind++ ) + { + hTcxDec->syn_OverlFB[ind] = (Word16) L_shr( xn_bufFB_fx[add( ind, L_frameTCX )], sub( q_x, q_win ) ); } } /* Output */ - mvs2s( xn_buf_fx + sub( shr( overlap, 1 ), tcx_offset), synth_fx, L_frame_glob ); - FOR(Word16 ind = 0; ind < L_frameTCX_glob; ind++) { - synthFB_fx[ind] = (Word16)L_shr(xn_bufFB_fx[ add( ind, sub( shr( overlapFB, 1 ), tcx_offsetFB)) ], sub(q_x, q_win)); + mvs2s( xn_buf_fx + sub( shr( overlap, 1 ), tcx_offset ), synth_fx, L_frame_glob ); + FOR( Word16 ind = 0; ind < L_frameTCX_glob; ind++ ) + { + synthFB_fx[ind] = (Word16) L_shr( xn_bufFB_fx[add( ind, sub( shr( overlapFB, 1 ), tcx_offsetFB ) )], sub( q_x, q_win ) ); } - return; } #endif @@ -2285,7 +2288,7 @@ void decoder_tcx_IGF_mono( int16_t igfGridIdx; IGFDecUpdateInfo_flt( st->hIGFDec, frame_cnt, ( L_frame == st->L_frame >> 1 ) && ( st->tcxonly ) ? IGF_GRID_LB_SHORT : ( st->last_core == ACELP_CORE || left_rect ) ? IGF_GRID_LB_TRAN - : IGF_GRID_LB_NORM ); + : IGF_GRID_LB_NORM ); if ( st->igf ) { @@ -2352,10 +2355,10 @@ void decoder_tcx_IGF_stereo( } IGFDecUpdateInfo_flt( sts[0]->hIGFDec, k, ( L_frame == sts[0]->L_frame >> 1 ) && ( sts[0]->tcxonly ) ? IGF_GRID_LB_SHORT : ( sts[0]->last_core == ACELP_CORE || left_rect ) ? IGF_GRID_LB_TRAN - : IGF_GRID_LB_NORM ); + : IGF_GRID_LB_NORM ); IGFDecUpdateInfo_flt( sts[1]->hIGFDec, k, ( L_frame == sts[1]->L_frame >> 1 ) && ( sts[1]->tcxonly ) ? IGF_GRID_LB_SHORT : ( sts[1]->last_core == ACELP_CORE || left_rect ) ? IGF_GRID_LB_TRAN - : IGF_GRID_LB_NORM ); + : IGF_GRID_LB_NORM ); if ( sts[0]->igf ) { @@ -2370,4 +2373,4 @@ void decoder_tcx_IGF_stereo( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 1c8b8ec1d..394cec09c 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -17,48 +17,48 @@ #include "ivas_rom_com.h" #include "ivas_rom_com_fx.h" #ifdef IVAS_FLOAT_FIXED -extern const Word16 T_DIV_L_Frame[];/*0Q15 * 2^-7 */ +extern const Word16 T_DIV_L_Frame[]; /*0Q15 * 2^-7 */ -static Word32 CalculateAbsEnergy_fx( /* o : normalized result Q31 */ - const Word32 L_off, /* i : initial sum value Qn */ - const Word16 x[], /* i : x vector Qn */ - const Word16 lg, /* i : vector length, range [0..7FFF] Q0 */ - Word16 * exp /* o : exponent of result in [-32,31] Q0 */ +static Word32 CalculateAbsEnergy_fx( /* o : normalized result Q31 */ + const Word32 L_off, /* i : initial sum value Qn */ + const Word16 x[], /* i : x vector Qn */ + const Word16 lg, /* i : vector length, range [0..7FFF] Q0 */ + Word16 *exp /* o : exponent of result in [-32,31] Q0 */ ); void decoder_tcx_fx( - TCX_CONFIG_HANDLE hTcxCfg, - Word16 prm[], /* input: parameters */ - Word16 A[], /* input: coefficients NxAz[M+1] */ - Word16 Aind[], /* input: frame-independent coefficients Az[M+1] */ - Word16 L_frame_glob, /* input: frame length */ + TCX_CONFIG_HANDLE hTcxCfg, + Word16 prm[], /* input: parameters */ + Word16 A[], /* input: coefficients NxAz[M+1] */ + Word16 Aind[], /* input: frame-independent coefficients Az[M+1] */ + Word16 L_frame_glob, /* input: frame length */ Word16 L_frameTCX_glob, Word16 L_spec, - Word16 synth[], /* in/out: synth[-M-LFAC..L_frame] */ + Word16 synth[], /* in/out: synth[-M-LFAC..L_frame] */ Word16 synthFB[], Decoder_State *st, - Word16 coder_type, /* input : coder type */ - Word16 bfi, /* input: Bad frame indicator */ - Word16 frame_cnt, /* input: frame counter in the super frame */ - Word16 stab_fac /* input: stability of isf (1Q14) */ + Word16 coder_type, /* input : coder type */ + Word16 bfi, /* input: Bad frame indicator */ + Word16 frame_cnt, /* input: frame counter in the super frame */ + Word16 stab_fac /* input: stability of isf (1Q14) */ ) { Word16 i, index, L_frame, tcx_offset; Word16 L_frameTCX, tcx_offsetFB; Word16 firstLine; Word16 gain_tcx, gain_tcx_e, fac_ns; - Word16 Ap[M+2]; + Word16 Ap[M + 2]; Word32 x[N_MAX]; Word16 x_e; Word16 *xn_buf; - Word16 xn_bufFB[L_MDCT_OVLP_MAX+L_FRAME_PLUS+L_MDCT_OVLP_MAX]; + Word16 xn_bufFB[L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX]; Word32 xn_buf32[N_MAX]; Word16 overlap; Word16 overlapFB; Word16 noiseFillingSize; Word16 noiseTransWidth; Word16 tnsSize; /* number of tns parameters put into prm */ - Word8 fUseTns; /* flag that is set if TNS data is present */ + Word8 fUseTns; /* flag that is set if TNS data is present */ STnsData tnsData; Word16 left_rect; Word16 gainlpc2[FDNS_NPTS]; @@ -71,13 +71,13 @@ void decoder_tcx_fx( Word16 gamma1; Word16 gamma; Word16 gainCompensate, gainCompensate_e; - Word16 h1[L_FRAME_MAX/4+1]; + Word16 h1[L_FRAME_MAX / 4 + 1]; Word16 mem[M]; Word16 temp_concealment_method = 0; Word16 arith_bits, signaling_bits; Word16 *prm_ltp, *prm_tns, *prm_hm, *prm_sqQ, *prm_target; - Word16*pInfoTCXNoise; - Word16 acelp_zir[L_FRAME_MAX/2]; + Word16 *pInfoTCXNoise; + Word16 acelp_zir[L_FRAME_MAX / 2]; Word16 noise_filling_index; Word16 infoIGFStartLine; Word16 L_spec_con; @@ -91,12 +91,11 @@ void decoder_tcx_fx( hTcxLtpDec = st->hTcxLtpDec; hTcxDec = st->hTcxDec; - prm_target = NULL; /* just to suppress MSVC warnigs */ - + prm_target = NULL; /* just to suppress MSVC warnigs */ - x_e = 0; /* to avoid compilation warnings */ - nf_seed = 0; /* to avoid compilation warnings */ + x_e = 0; /* to avoid compilation warnings */ + nf_seed = 0; /* to avoid compilation warnings */ /* Overlay xn_buf32 with xn_buf */ @@ -108,21 +107,21 @@ void decoder_tcx_fx( move16(); fUseTns = 0; move16(); - gainCompensate = 32768/2; + gainCompensate = 32768 / 2; move16(); gainCompensate_e = 1; move16(); - FOR (i=0 ; i < (L_MDCT_OVLP_MAX+L_FRAME_PLUS+L_MDCT_OVLP_MAX)/2; i++) + FOR( i = 0; i < ( L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX ) / 2; i++ ) { - xn_buf32[i] = L_deposit_l(0); + xn_buf32[i] = L_deposit_l( 0 ); } /* Init lengths */ - overlap = hTcxCfg->tcx_mdct_window_length; + overlap = hTcxCfg->tcx_mdct_window_length; move16(); - overlapFB = hTcxCfg->tcx_mdct_window_lengthFB; + overlapFB = hTcxCfg->tcx_mdct_window_lengthFB; move16(); /* Modified the overlap to the delay in case of short blocks*/ tcx_offset = hTcxCfg->tcx_offset; @@ -131,22 +130,22 @@ void decoder_tcx_fx( move16(); L_spec_con = L_spec; move16(); - gamma1 = st->gamma; + gamma1 = st->gamma; move16(); - if (hTcxDec->enableTcxLpc != 0) + if ( hTcxDec->enableTcxLpc != 0 ) { gamma1 = 0x7FFF; move16(); } - IF (bfi != 0) + IF( bfi != 0 ) { /* PLC: [TCX: Memory update] * PLC: Init buffers */ - assert(st->L_frame_past > 0); - L_frame = st->L_frame_past; + assert( st->L_frame_past > 0 ); + L_frame = st->L_frame_past; move16(); L_frameTCX = st->L_frameTCX_past; move16(); @@ -154,35 +153,35 @@ void decoder_tcx_fx( left_rect = st->prev_widow_left_rect; move16(); - IF (left_rect != 0) + IF( left_rect != 0 ) { tcx_offset = hTcxCfg->lfacNext; move16(); tcx_offsetFB = hTcxCfg->lfacNextFB; move16(); - L_spec = add(L_spec, shr(st->hTcxCfg->tcx_coded_lines, 2)); - L_spec_con = add(L_spec_con, shr(st->hTcxCfg->tcx_coded_lines, 2)); + L_spec = add( L_spec, shr( st->hTcxCfg->tcx_coded_lines, 2 ) ); + L_spec_con = add( L_spec_con, shr( st->hTcxCfg->tcx_coded_lines, 2 ) ); } } ELSE { test(); - IF ( frame_cnt == 0 && st->last_core == ACELP_CORE ) + IF( frame_cnt == 0 && st->last_core == ACELP_CORE ) { - if (st->prev_bfi == 0) + if ( st->prev_bfi == 0 ) { hTcxCfg->last_aldo = 0; move16(); } /* if past frame is ACELP */ - L_frame = add(L_frame_glob, tcx_offset); - L_frameTCX = add(L_frameTCX_glob, tcx_offsetFB); - L_spec_con = add(L_spec_con, shr(st->hTcxCfg->tcx_coded_lines, 2)); - assert(hTcxCfg->lfacNext<=0); - L_frame = sub(L_frame , hTcxCfg->lfacNext); - L_frameTCX = sub(L_frameTCX, hTcxCfg->lfacNextFB); - tcx_offset = hTcxCfg->lfacNext; + L_frame = add( L_frame_glob, tcx_offset ); + L_frameTCX = add( L_frameTCX_glob, tcx_offsetFB ); + L_spec_con = add( L_spec_con, shr( st->hTcxCfg->tcx_coded_lines, 2 ) ); + assert( hTcxCfg->lfacNext <= 0 ); + L_frame = sub( L_frame, hTcxCfg->lfacNext ); + L_frameTCX = sub( L_frameTCX, hTcxCfg->lfacNextFB ); + tcx_offset = hTcxCfg->lfacNext; move16(); tcx_offsetFB = hTcxCfg->lfacNextFB; move16(); @@ -204,7 +203,7 @@ void decoder_tcx_fx( move16(); } - IF ( frame_cnt == 0 && EQ_16(st->last_core_from_bs, ACELP_CORE) ) + IF( frame_cnt == 0 && EQ_16( st->last_core_from_bs, ACELP_CORE ) ) { L_spec += st->hTcxCfg->tcx_coded_lines >> 2; } @@ -216,55 +215,55 @@ void decoder_tcx_fx( } test(); - IF ( (EQ_16(L_frame, shr(st->L_frame, 1)))&&(st->tcxonly)) + IF( ( EQ_16( L_frame, shr( st->L_frame, 1 ) ) ) && ( st->tcxonly ) ) { - IGFDecUpdateInfo( st->hIGFDec,IGF_GRID_LB_SHORT); + IGFDecUpdateInfo( st->hIGFDec, IGF_GRID_LB_SHORT ); } ELSE { test(); test(); - IF ((EQ_16(st->last_core, ACELP_CORE))||(left_rect&&st->bfi)) + IF( ( EQ_16( st->last_core, ACELP_CORE ) ) || ( left_rect && st->bfi ) ) { - IGFDecUpdateInfo(st->hIGFDec,IGF_GRID_LB_TRAN); + IGFDecUpdateInfo( st->hIGFDec, IGF_GRID_LB_TRAN ); } ELSE { - IGFDecUpdateInfo(st->hIGFDec,IGF_GRID_LB_NORM); + IGFDecUpdateInfo( st->hIGFDec, IGF_GRID_LB_NORM ); } } - IF (0 == st->igf) + IF( 0 == st->igf ) { - IF (st->narrowBand == 0) + IF( st->narrowBand == 0 ) { /* minimum needed for output with sampling rates lower then the nominal sampling rate */ - infoIGFStartLine = s_min(L_frameTCX, L_frame); + infoIGFStartLine = s_min( L_frameTCX, L_frame ); move16(); } ELSE { - infoIGFStartLine = L_frameTCX; + infoIGFStartLine = L_frameTCX; move16(); } } ELSE { - infoIGFStartLine = s_min(st->hIGFDec->infoIGFStartLine,L_frameTCX); + infoIGFStartLine = s_min( st->hIGFDec->infoIGFStartLine, L_frameTCX ); move16(); } noiseFillingSize = L_spec; move16(); - if (st->igf != 0) + if ( st->igf != 0 ) { noiseFillingSize = st->hIGFDec->infoIGFStartLine; move16(); } - prm_ltp = &prm[1+NOISE_FILL_RANGES]; + prm_ltp = &prm[1 + NOISE_FILL_RANGES]; move16(); prm_tns = prm_ltp + LTPSIZE; move16(); @@ -276,7 +275,7 @@ void decoder_tcx_fx( index = 0; move16(); - IF (bfi == 0) + IF( bfi == 0 ) { index = prm[0]; @@ -287,7 +286,7 @@ void decoder_tcx_fx( noise_filling_index = prm[1]; move16(); - fac_ns = extract_l(L_shr(L_mult0(noise_filling_index, 0x6000), NBITS_NOISE_FILL_LEVEL)); + fac_ns = extract_l( L_shr( L_mult0( noise_filling_index, 0x6000 ), NBITS_NOISE_FILL_LEVEL ) ); } ELSE { @@ -297,14 +296,14 @@ void decoder_tcx_fx( /* read TNS data */ test(); - IF ((bfi == 0) && (hTcxCfg->fIsTNSAllowed != 0)) + IF( ( bfi == 0 ) && ( hTcxCfg->fIsTNSAllowed != 0 ) ) { cast16(); - fUseTns = (Word8)DecodeTnsData(hTcxCfg->pCurrentTnsConfig, - prm_tns, - &tnsSize, - &tnsData); + fUseTns = (Word8) DecodeTnsData( hTcxCfg->pCurrentTnsConfig, + prm_tns, + &tnsSize, + &tnsData ); } ELSE { @@ -321,7 +320,7 @@ void decoder_tcx_fx( * Spectrum data * *-----------------------------------------------------------*/ - IF (bfi == 0) + IF( bfi == 0 ) { /*-----------------------------------------------------------* @@ -329,26 +328,26 @@ void decoder_tcx_fx( *-----------------------------------------------------------*/ test(); test(); - IF(hTcxCfg->ctx_hm != 0 && ( (st->last_core_from_bs != ACELP_CORE) || (frame_cnt > 0) ) ) + IF( hTcxCfg->ctx_hm != 0 && ( ( st->last_core_from_bs != ACELP_CORE ) || ( frame_cnt > 0 ) ) ) { st->last_ctx_hm_enabled = prm_hm[0]; move16(); { - FOR (i = 0; i < L_spec; i++) /* no context harmonic model, copy MDCT coefficients to x */ + FOR( i = 0; i < L_spec; i++ ) /* no context harmonic model, copy MDCT coefficients to x */ { - x[i] = L_mult(prm_sqQ[i], - 1 << (30 - SPEC_EXP_DEC)); + x[i] = L_mult( prm_sqQ[i], + 1 << ( 30 - SPEC_EXP_DEC ) ); move32(); } } x_e = SPEC_EXP_DEC; move16(); } - ELSE /* hTcxCfg->ctx_hm == 0 */ + ELSE /* hTcxCfg->ctx_hm == 0 */ { - IF (hTcxDec->tcx_lpc_shaped_ari != 0) /* low rates: new arithmetic coder */ + IF( hTcxDec->tcx_lpc_shaped_ari != 0 ) /* low rates: new arithmetic coder */ { prm_target = prm_sqQ; move16(); @@ -357,7 +356,7 @@ void decoder_tcx_fx( tmp8 = 1; move16(); - if (EQ_16(st->last_core_from_bs, ACELP_CORE)) + if ( EQ_16( st->last_core_from_bs, ACELP_CORE ) ) { tmp8 = 0; move16(); @@ -377,48 +376,48 @@ void decoder_tcx_fx( &arith_bits, &signaling_bits, &nf_seed, - shr(st->bwidth, 1) /* equivalent to: (st->bwidth > WB)?1:0 */ + shr( st->bwidth, 1 ) /* equivalent to: (st->bwidth > WB)?1:0 */ ); - hTcxDec->resQBits[frame_cnt] = sub(*prm_target, arith_bits); + hTcxDec->resQBits[frame_cnt] = sub( *prm_target, arith_bits ); move16(); } - ELSE /* TCX-only: old arithmetic coder */ + ELSE /* TCX-only: old arithmetic coder */ { - FOR (i = 0; i < L_spec; i++) + FOR( i = 0; i < L_spec; i++ ) { - x[i] = L_mult(prm_sqQ[i], - 1 << (30 - SPEC_EXP_DEC)); + x[i] = L_mult( prm_sqQ[i], + 1 << ( 30 - SPEC_EXP_DEC ) ); move32(); } - set32_fx(x+L_spec, 0, sub(L_frameTCX, L_spec)); + set32_fx( x + L_spec, 0, sub( L_frameTCX, L_spec ) ); x_e = SPEC_EXP_DEC; move16(); } - } /* else of if hTcxCfg->ctx_hm */ - tmp1 = s_max(L_frame, L_frameTCX); - tmp1 = s_max(tmp1, L_spec_con); - set32_fx(x+L_spec, 0, sub(tmp1, L_spec)); + } /* else of if hTcxCfg->ctx_hm */ + tmp1 = s_max( L_frame, L_frameTCX ); + tmp1 = s_max( tmp1, L_spec_con ); + set32_fx( x + L_spec, 0, sub( tmp1, L_spec ) ); /*-----------------------------------------------------------* * adaptive low frequency deemphasis. * *-----------------------------------------------------------*/ - weight_a_fx(A, Ap, gamma1, M); + weight_a_fx( A, Ap, gamma1, M ); - lpc2mdct(Ap, M, NULL, NULL, gainlpc2, gainlpc2_e, FDNS_NPTS, 0); + lpc2mdct( Ap, M, NULL, NULL, gainlpc2, gainlpc2_e, FDNS_NPTS, 0 ); /* initialize LF deemphasis factors in xn_buf */ - tmp1 = s_max(L_spec, L_frameTCX); - set16_fx(xn_buf, 0x4000, tmp1); + tmp1 = s_max( L_spec, L_frameTCX ); + set16_fx( xn_buf, 0x4000, tmp1 ); - IF (st->tcxonly == 0) + IF( st->tcxonly == 0 ) { AdaptLowFreqDeemph( x, x_e, hTcxDec->tcx_lpc_shaped_ari, gainlpc2, gainlpc2_e, L_frame, xn_buf /* LF deemphasis factors */ ); @@ -428,38 +427,38 @@ void decoder_tcx_fx( /* Global Gain */ hTcxDec->damping = 0; - IF(bfi==0) + IF( bfi == 0 ) { /*-----------------------------------------------------------* * Compute global gain * *-----------------------------------------------------------*/ - tmp32 = L_shl(L_mult0(index, 0x797D), 7); /* 6Q25; 0x797D -> log2(10)/28 (Q18) */ - gain_tcx_e = add(extract_l(L_shr(tmp32, 25)), 1); /* get exponent */ - gain_tcx = round_fx(BASOP_Util_InvLog2(L_or(tmp32, 0xFE000000))); + tmp32 = L_shl( L_mult0( index, 0x797D ), 7 ); /* 6Q25; 0x797D -> log2(10)/28 (Q18) */ + gain_tcx_e = add( extract_l( L_shr( tmp32, 25 ) ), 1 ); /* get exponent */ + gain_tcx = round_fx( BASOP_Util_InvLog2( L_or( tmp32, 0xFE000000 ) ) ); #ifdef BASOP_NOGLOB - tmp1 = mult_r(shl_sat(L_spec, 5), 26214/*128.f/NORM_MDCT_FACTOR Q15*/); + tmp1 = mult_r( shl_sat( L_spec, 5 ), 26214 /*128.f/NORM_MDCT_FACTOR Q15*/ ); #else - tmp1 = mult_r(shl(L_spec, 5), 26214/*128.f/NORM_MDCT_FACTOR Q15*/); + tmp1 = mult_r( shl( L_spec, 5 ), 26214 /*128.f/NORM_MDCT_FACTOR Q15*/ ); #endif - s = 15-5-7; - if(L_spec>=1024) /*reduce precision for avoiding overflow*/ + s = 15 - 5 - 7; + if ( L_spec >= 1024 ) /*reduce precision for avoiding overflow*/ { - tmp1 = mult_r(shl(L_spec, 4), 26214/*128.f/NORM_MDCT_FACTOR Q15*/); - s = 15-4-7; + tmp1 = mult_r( shl( L_spec, 4 ), 26214 /*128.f/NORM_MDCT_FACTOR Q15*/ ); + s = 15 - 4 - 7; } - tmp1 = ISqrt16(tmp1, &s); + tmp1 = ISqrt16( tmp1, &s ); - gain_tcx = mult(gain_tcx, tmp1); - gain_tcx_e = add(gain_tcx_e, s); + gain_tcx = mult( gain_tcx, tmp1 ); + gain_tcx_e = add( gain_tcx_e, s ); hTcxDec->old_gaintcx_bfi = gain_tcx; move16(); hTcxDec->old_gaintcx_bfi_e = gain_tcx_e; move16(); - hTcxDec->cummulative_damping_tcx = 32767/*1.0f Q15*/; + hTcxDec->cummulative_damping_tcx = 32767 /*1.0f Q15*/; move16(); } ELSE /* bfi = 1 */ @@ -470,18 +469,18 @@ void decoder_tcx_fx( IF( st->use_partial_copy != 0 ) { - IF( EQ_16(st->rf_frame_type, RF_TCXFD)) + IF( EQ_16( st->rf_frame_type, RF_TCXFD ) ) { - tmp32 = L_shl(L_mult0(hTcxDec->old_gaintcx_bfi, 0x797D), 7); /* 6Q25; 0x797D -> log2(10)/28 (Q18) */ - gain_tcx_e = add(extract_l(L_shr(tmp32, 25)), 1); /* get exponent */ - gain_tcx = round_fx(BASOP_Util_InvLog2(L_or(tmp32, 0xFE000000))); + tmp32 = L_shl( L_mult0( hTcxDec->old_gaintcx_bfi, 0x797D ), 7 ); /* 6Q25; 0x797D -> log2(10)/28 (Q18) */ + gain_tcx_e = add( extract_l( L_shr( tmp32, 25 ) ), 1 ); /* get exponent */ + gain_tcx = round_fx( BASOP_Util_InvLog2( L_or( tmp32, 0xFE000000 ) ) ); - tmp1 = mult_r(shl(L_spec, 5), 26214/*128.f/NORM_MDCT_FACTOR Q15*/); - s = 15-5-7; - tmp1 = ISqrt16(tmp1, &s); + tmp1 = mult_r( shl( L_spec, 5 ), 26214 /*128.f/NORM_MDCT_FACTOR Q15*/ ); + s = 15 - 5 - 7; + tmp1 = ISqrt16( tmp1, &s ); - gain_tcx = mult(gain_tcx, tmp1); - gain_tcx_e = add(gain_tcx_e, s); + gain_tcx = mult( gain_tcx, tmp1 ); + gain_tcx_e = add( gain_tcx_e, s ); hTcxDec->old_gaintcx_bfi = gain_tcx; move16(); @@ -496,26 +495,26 @@ void decoder_tcx_fx( move16(); } - hTcxDec->damping = 16384/*1.f Q14*/; /*Q14*/ move16(); + hTcxDec->damping = 16384 /*1.f Q14*/; /*Q14*/ + move16(); } ELSE { - hTcxDec->damping = Damping_fact_fx(coder_type, st->nbLostCmpt, st->last_good, stab_fac, &(st->Mode2_lp_gainp), st->last_core); + hTcxDec->damping = Damping_fact_fx( coder_type, st->nbLostCmpt, st->last_good, stab_fac, &( st->Mode2_lp_gainp ), st->last_core ); gain_tcx = hTcxDec->old_gaintcx_bfi; move16(); gain_tcx_e = hTcxDec->old_gaintcx_bfi_e; move16(); } - hTcxDec->cummulative_damping_tcx = shl(mult(hTcxDec->cummulative_damping_tcx,hTcxDec->damping),1);/*shl(Q15*Q14,1)=shl(Q14,1) = Q15*/ - + hTcxDec->cummulative_damping_tcx = shl( mult( hTcxDec->cummulative_damping_tcx, hTcxDec->damping ), 1 ); /*shl(Q15*Q14,1)=shl(Q14,1) = Q15*/ } { - IF(bfi) + IF( bfi ) { gamma = gamma1; move16(); - if (hTcxDec->envWeighted) + if ( hTcxDec->envWeighted ) { gamma = st->gamma; move16(); @@ -523,82 +522,81 @@ void decoder_tcx_fx( /* PLC: [TCX: Fade-out] * PLC: invert LPC weighting in case of PLC */ - IF (hTcxDec->enableTcxLpc != 0) + IF( hTcxDec->enableTcxLpc != 0 ) { - gamma = add(mult_r(hTcxDec->cummulative_damping_tcx,sub(st->gamma, 32767/*1.0f Q15*/)), 32767/*1.0f Q15*/); + gamma = add( mult_r( hTcxDec->cummulative_damping_tcx, sub( st->gamma, 32767 /*1.0f Q15*/ ) ), 32767 /*1.0f Q15*/ ); } ELSE { - gamma = add(mult_r(hTcxDec->cummulative_damping_tcx,sub(gamma1, 32767/*1.0f Q15*/)), 32767/*1.0f Q15*/); + gamma = add( mult_r( hTcxDec->cummulative_damping_tcx, sub( gamma1, 32767 /*1.0f Q15*/ ) ), 32767 /*1.0f Q15*/ ); } - weight_a_fx(A, Ap, gamma, M); - - lpc2mdct(Ap, M, NULL, NULL, gainlpc2, gainlpc2_e, FDNS_NPTS, 0); + weight_a_fx( A, Ap, gamma, M ); + lpc2mdct( Ap, M, NULL, NULL, gainlpc2, gainlpc2_e, FDNS_NPTS, 0 ); } tmp2 = 0; move16(); - set16_fx(h1, 0, add(L_SUBFR,1)); - set16_fx(mem, 0, M); - h1[0] = 32768/32; + set16_fx( h1, 0, add( L_SUBFR, 1 ) ); + set16_fx( mem, 0, M ); + h1[0] = 32768 / 32; move16(); - E_UTIL_synthesis(0,Ap, h1, h1, L_SUBFR, mem, 0, M ); - deemph_fx(h1, st->preemph_fac, L_SUBFR, &tmp2); + E_UTIL_synthesis( 0, Ap, h1, h1, L_SUBFR, mem, 0, M ); + deemph_fx( h1, st->preemph_fac, L_SUBFR, &tmp2 ); /* impulse response level = gain introduced by synthesis+deemphasis */ test(); - IF (bfi==0) + IF( bfi == 0 ) { /* st->last_gain_syn_deemph = (float)sqrt(dot_product( h1, h1, L_SUBFR)); */ - tmp32 = Dot_productSq16HQ( 0, h1, L_SUBFR, &st->last_gain_syn_deemph_e)/*Q15, st->last_gain_syn_deemph_e*/; - st->last_gain_syn_deemph_e = add(st->last_gain_syn_deemph_e,10/*scaling of h1[0] and E_UTIL_synthesis * 2*/); - tmp32 = Sqrt32(tmp32,&st->last_gain_syn_deemph_e); + tmp32 = Dot_productSq16HQ( 0, h1, L_SUBFR, &st->last_gain_syn_deemph_e ) /*Q15, st->last_gain_syn_deemph_e*/; + st->last_gain_syn_deemph_e = add( st->last_gain_syn_deemph_e, 10 /*scaling of h1[0] and E_UTIL_synthesis * 2*/ ); + tmp32 = Sqrt32( tmp32, &st->last_gain_syn_deemph_e ); #ifdef BASOP_NOGLOB - st->last_gain_syn_deemph = round_fx_o(tmp32, &Overflow); + st->last_gain_syn_deemph = round_fx_o( tmp32, &Overflow ); #else - st->last_gain_syn_deemph = round_fx(tmp32); + st->last_gain_syn_deemph = round_fx( tmp32 ); #endif /*for avoiding compiler warnings*/ - hTcxDec->gainHelper = 32768/2; + hTcxDec->gainHelper = 32768 / 2; move16(); - hTcxDec->gainHelper_e = 1; + hTcxDec->gainHelper_e = 1; move16(); - hTcxDec->stepCompensate = 0; + hTcxDec->stepCompensate = 0; move16(); - hTcxDec->stepCompensate_e = 0; + hTcxDec->stepCompensate_e = 0; move16(); } /* not instrumenting the additional test() here seems to be common practice */ - ELSE IF (EQ_16(TCX_20_CORE, st->core)||EQ_16(frame_cnt,1)) + ELSE IF( EQ_16( TCX_20_CORE, st->core ) || EQ_16( frame_cnt, 1 ) ) { /* gainCompensate = st->last_gain_syn_deemph/(float)sqrt(dot_product( h1, h1, L_SUBFR)); */ - tmp32 = Dot_productSq16HQ( 0, h1, L_SUBFR, &gainCompensate_e)/*Q15, gainCompensate_e*/; - gainCompensate_e = add(gainCompensate_e,10/*scaling of h1[0] and E_UTIL:synthesis*/); + tmp32 = Dot_productSq16HQ( 0, h1, L_SUBFR, &gainCompensate_e ) /*Q15, gainCompensate_e*/; + gainCompensate_e = add( gainCompensate_e, 10 /*scaling of h1[0] and E_UTIL:synthesis*/ ); #ifdef BASOP_NOGLOB gainCompensate = round_fx_sat( Sqrt32( tmp32, &gainCompensate_e ) ) /*Q15, gainCompensate_e*/; #else - gainCompensate = round_fx(Sqrt32(tmp32,&gainCompensate_e))/*Q15, gainCompensate_e*/; + gainCompensate = round_fx( Sqrt32( tmp32, &gainCompensate_e ) ) /*Q15, gainCompensate_e*/; #endif - BASOP_Util_Divide_MantExp ( st->last_gain_syn_deemph, - st->last_gain_syn_deemph_e, - gainCompensate, - gainCompensate_e, - &gainCompensate, - &gainCompensate_e); + BASOP_Util_Divide_MantExp( st->last_gain_syn_deemph, + st->last_gain_syn_deemph_e, + gainCompensate, + gainCompensate_e, + &gainCompensate, + &gainCompensate_e ); - tmp1 = T_DIV_L_Frame[L_shl(L_mac(-28000,st->L_frame,95),1-15)]; + tmp1 = T_DIV_L_Frame[L_shl( L_mac( -28000, st->L_frame, 95 ), 1 - 15 )]; - IF (EQ_16(st->nbLostCmpt,1)) + IF( EQ_16( st->nbLostCmpt, 1 ) ) { /* stepCompensate = (1.f - gainCompensate)/st->L_frame; */ hTcxDec->stepCompensate_e = BASOP_Util_Add_MantExp( - tmp1, - -7, - negate(mult(gainCompensate,tmp1)), - add(-7,gainCompensate_e), - &hTcxDec->stepCompensate); + tmp1, + -7, + negate( mult( gainCompensate, tmp1 ) ), + add( -7, gainCompensate_e ), + &hTcxDec->stepCompensate ); - hTcxDec->gainHelper = 32768/2; + hTcxDec->gainHelper = 32768 / 2; move16(); hTcxDec->gainHelper_e = 1; move16(); @@ -607,11 +605,11 @@ void decoder_tcx_fx( { /* stepCompensate = (st->last_concealed_gain_syn_deemph - gainCompensate)/st->L_frame; */ hTcxDec->stepCompensate_e = BASOP_Util_Add_MantExp( - mult(tmp1,st->last_concealed_gain_syn_deemph), - add(-7, st->last_concealed_gain_syn_deemph_e), - negate(mult(tmp1,gainCompensate)), - add(-7, gainCompensate_e), - &hTcxDec->stepCompensate); + mult( tmp1, st->last_concealed_gain_syn_deemph ), + add( -7, st->last_concealed_gain_syn_deemph_e ), + negate( mult( tmp1, gainCompensate ) ), + add( -7, gainCompensate_e ), + &hTcxDec->stepCompensate ); move16(); move16(); hTcxDec->gainHelper = st->last_concealed_gain_syn_deemph; @@ -622,7 +620,6 @@ void decoder_tcx_fx( st->last_concealed_gain_syn_deemph = gainCompensate; st->last_concealed_gain_syn_deemph_e = gainCompensate_e; } - } @@ -630,58 +627,58 @@ void decoder_tcx_fx( * Residual inv. Q. * *-----------------------------------------------------------*/ test(); - IF ((bfi == 0) && (hTcxCfg->resq != 0)) + IF( ( bfi == 0 ) && ( hTcxCfg->resq != 0 ) ) { - IF (hTcxDec->tcx_lpc_shaped_ari != 0) /* new arithmetic coder */ + IF( hTcxDec->tcx_lpc_shaped_ari != 0 ) /* new arithmetic coder */ { Word16 *prm_resq; - prm_resq = prm_sqQ - + *prm_target /* = targetBits */ + prm_resq = prm_sqQ + *prm_target /* = targetBits */ - hTcxDec->resQBits[frame_cnt]; - i = tcx_ari_res_invQ_spec(x, x_e, L_spec, - prm_resq, - hTcxDec->resQBits[frame_cnt], - 0, - hTcxCfg->sq_rounding, - xn_buf /* LF deemphasis factors */ ); + i = tcx_ari_res_invQ_spec( x, x_e, L_spec, + prm_resq, + hTcxDec->resQBits[frame_cnt], + 0, + hTcxCfg->sq_rounding, + xn_buf /* LF deemphasis factors */ ); } - ELSE /* old arithmetic coder */ + ELSE /* old arithmetic coder */ { - i = tcx_res_invQ_gain(&gain_tcx, &gain_tcx_e, &prm_sqQ[L_spec], hTcxDec->resQBits[frame_cnt]); + i = tcx_res_invQ_gain( &gain_tcx, &gain_tcx_e, &prm_sqQ[L_spec], hTcxDec->resQBits[frame_cnt] ); tmpP16 = xn_buf; - if (st->tcxonly != 0) tmpP16 = NULL; + if ( st->tcxonly != 0 ) + tmpP16 = NULL; - tcx_res_invQ_spec(x, x_e, L_spec, &prm_sqQ[L_spec],hTcxDec->resQBits[frame_cnt],i,hTcxCfg->sq_rounding,tmpP16 /* LF deemphasis factors */ ); + tcx_res_invQ_spec( x, x_e, L_spec, &prm_sqQ[L_spec], hTcxDec->resQBits[frame_cnt], i, hTcxCfg->sq_rounding, tmpP16 /* LF deemphasis factors */ ); } } test(); - IF (bfi == 0 && st->tcxonly != 0) + IF( bfi == 0 && st->tcxonly != 0 ) { test(); test(); - IF (hTcxLtpDec->tcxltp && (hTcxLtpDec->tcxltp_gain > 0) && !fUseTns) + IF( hTcxLtpDec->tcxltp && ( hTcxLtpDec->tcxltp_gain > 0 ) && !fUseTns ) { - PsychAdaptLowFreqDeemph(x, gainlpc2, gainlpc2_e, NULL); + PsychAdaptLowFreqDeemph( x, gainlpc2, gainlpc2_e, NULL ); } } /* for FAC */ test(); - IF (bfi == 0 && st->tcxonly == 0) + IF( bfi == 0 && st->tcxonly == 0 ) { /* Replication of ACELP formant enhancement for low rates */ - IF (LT_32(st->total_brate, ACELP_13k20)||st->rf_flag!=0) + IF( LT_32( st->total_brate, ACELP_13k20 ) || st->rf_flag != 0 ) { - tcxFormantEnhancement(xn_buf, gainlpc2, gainlpc2_e, x, &x_e, L_frame, L_frameTCX); + tcxFormantEnhancement( xn_buf, gainlpc2, gainlpc2_e, x, &x_e, L_frame, L_frameTCX ); } } @@ -689,17 +686,17 @@ void decoder_tcx_fx( * Add gain to the lpc gains * *-----------------------------------------------------------*/ - if(st->VAD==0 ) + if ( st->VAD == 0 ) { - gain_tcx = mult_r(gain_tcx, hTcxCfg->na_scale); + gain_tcx = mult_r( gain_tcx, hTcxCfg->na_scale ); } - i = norm_s(gain_tcx); - gain_tcx = shl(gain_tcx, i); - gain_tcx_e = sub(gain_tcx_e, i); - FOR (i = 0; i < FDNS_NPTS; i++) + i = norm_s( gain_tcx ); + gain_tcx = shl( gain_tcx, i ); + gain_tcx_e = sub( gain_tcx_e, i ); + FOR( i = 0; i < FDNS_NPTS; i++ ) { - gainlpc2[i] = mult_r(gainlpc2[i], gain_tcx); + gainlpc2[i] = mult_r( gainlpc2[i], gain_tcx ); move16(); } @@ -709,13 +706,13 @@ void decoder_tcx_fx( *-----------------------------------------------------------*/ test(); - IF (bfi==0 && (fac_ns > 0)) + IF( bfi == 0 && ( fac_ns > 0 ) ) { tmp1 = 0; move16(); test(); - if ( GE_16(st->bits_frame, 256)&&st->rf_flag==0) + if ( GE_16( st->bits_frame, 256 ) && st->rf_flag == 0 ) { tmp1 = 1; move16(); @@ -723,46 +720,47 @@ void decoder_tcx_fx( firstLine = tcxGetNoiseFillingTilt( A, M, L_frame, tmp1, &noiseTiltFactor ); - IF (st->tcxonly != 0) + IF( st->tcxonly != 0 ) { tmp1 = 0; move16(); test(); test(); - if ((hTcxCfg->ctx_hm != 0) && (st->last_core != ACELP_CORE) && (st->last_ctx_hm_enabled != 0)) + if ( ( hTcxCfg->ctx_hm != 0 ) && ( st->last_core != ACELP_CORE ) && ( st->last_ctx_hm_enabled != 0 ) ) { - tmp1 = 10240/*0.3125f Q15*/; + tmp1 = 10240 /*0.3125f Q15*/; move16(); } - noiseTransWidth = HOLE_SIZE_FROM_LTP(s_max(hTcxLtpDec->tcxltp_gain, tmp1)); + noiseTransWidth = HOLE_SIZE_FROM_LTP( s_max( hTcxLtpDec->tcxltp_gain, tmp1 ) ); - if (EQ_16(L_frame, shr(st->L_frame, 1))) + if ( EQ_16( L_frame, shr( st->L_frame, 1 ) ) ) { - noiseTransWidth = 3; /* minimum transition fading for noise filling in TCX-10 */ move16(); + noiseTransWidth = 3; /* minimum transition fading for noise filling in TCX-10 */ + move16(); } } - IF (hTcxDec->tcx_lpc_shaped_ari == 0) /* old arithmetic coder */ + IF( hTcxDec->tcx_lpc_shaped_ari == 0 ) /* old arithmetic coder */ { /* noise filling seed */ - tmp32 = L_deposit_l(0); - FOR (i = 0; i < L_spec; i++) + tmp32 = L_deposit_l( 0 ); + FOR( i = 0; i < L_spec; i++ ) { #ifdef BASOP_NOGLOB - tmp32 = L_macNs_co(tmp32, abs_s(prm_sqQ[i]), i, &Carry, &Overflow); + tmp32 = L_macNs_co( tmp32, abs_s( prm_sqQ[i] ), i, &Carry, &Overflow ); #else - tmp32 = L_macNs(tmp32, abs_s(prm_sqQ[i]), i); + tmp32 = L_macNs( tmp32, abs_s( prm_sqQ[i] ), i ); #endif } - nf_seed = extract_l(tmp32); + nf_seed = extract_l( tmp32 ); } tmp1 = nf_seed; move16(); pInfoTCXNoise = NULL; - if (st->igf) + if ( st->igf ) { #if 0 //pointer changed from 8bit to 16bit @@ -771,50 +769,48 @@ void decoder_tcx_fx( pInfoTCXNoise = st->hIGFDec->infoTCXNoise_evs; move16(); } - tcx_noise_filling(x, x_e,tmp1 /* seed */, firstLine, noiseFillingSize, noiseTransWidth, L_frame, noiseTiltFactor, - fac_ns, pInfoTCXNoise, st->element_mode); + tcx_noise_filling( x, x_e, tmp1 /* seed */, firstLine, noiseFillingSize, noiseTransWidth, L_frame, noiseTiltFactor, + fac_ns, pInfoTCXNoise, st->element_mode ); st->seed_tcx_plc = tmp1; move16(); } - IF (st->enablePlcWaveadjust) + IF( st->enablePlcWaveadjust ) { - IF (bfi) + IF( bfi ) { - IF (EQ_16(st->nbLostCmpt, 1)) + IF( EQ_16( st->nbLostCmpt, 1 ) ) { st->plcInfo.concealment_method = TCX_NONTONAL; move16(); /* tonal/non-tonal decision */ test(); test(); - IF (EQ_16(st->plcInfo.Transient[0],1) - && EQ_16(st->plcInfo.Transient[1], 1) - && EQ_16(st->plcInfo.Transient[2], 1)) + IF( EQ_16( st->plcInfo.Transient[0], 1 ) && EQ_16( st->plcInfo.Transient[1], 1 ) && EQ_16( st->plcInfo.Transient[2], 1 ) ) { Word16 sum_word16 = 0; move16(); - FOR (i = 9; i >= 0; i--) + FOR( i = 9; i >= 0; i-- ) { - sum_word16 = add(sum_word16, st->plcInfo.TCX_Tonality[i]); + sum_word16 = add( sum_word16, st->plcInfo.TCX_Tonality[i] ); } - if(GE_16(sum_word16, 6)) + if ( GE_16( sum_word16, 6 ) ) { st->plcInfo.concealment_method = TCX_TONAL; move16(); } } - if(st->tonal_mdct_plc_active) + if ( st->tonal_mdct_plc_active ) { st->plcInfo.concealment_method = TCX_TONAL; move16(); } } - if (GT_16(L_frameTCX, hTcxDec->L_frameTCX)) + if ( GT_16( L_frameTCX, hTcxDec->L_frameTCX ) ) { st->plcInfo.concealment_method = TCX_TONAL; move16(); @@ -823,16 +819,16 @@ void decoder_tcx_fx( temp_concealment_method = st->plcInfo.concealment_method; move16(); - if (EQ_16(st->core, TCX_10_CORE)) + if ( EQ_16( st->core, TCX_10_CORE ) ) { temp_concealment_method = TCX_TONAL; move16(); } } /* get the starting location of the subframe in the frame */ - IF (EQ_16(st->core, TCX_10_CORE)) + IF( EQ_16( st->core, TCX_10_CORE ) ) { - st->plcInfo.subframe_fx =extract_l( L_mult0(frame_cnt,L_frameTCX_glob)); + st->plcInfo.subframe_fx = extract_l( L_mult0( frame_cnt, L_frameTCX_glob ) ); } } @@ -840,15 +836,15 @@ void decoder_tcx_fx( /* PLC: [TCX: Fade-out] * PLC: Fade out to white noise */ - IF (bfi == 0) + IF( bfi == 0 ) { - TonalMDCTConceal_SaveFreqSignal(&st->tonalMDCTconceal,x, x_e, L_frameTCX, - L_frame, gainlpc2, gainlpc2_e, gain_tcx_e); + TonalMDCTConceal_SaveFreqSignal( &st->tonalMDCTconceal, x, x_e, L_frameTCX, + L_frame, gainlpc2, gainlpc2_e, gain_tcx_e ); } ELSE { test(); - IF( !st->enablePlcWaveadjust || EQ_16(temp_concealment_method, TCX_TONAL)) + IF( !st->enablePlcWaveadjust || EQ_16( temp_concealment_method, TCX_TONAL ) ) { Word16 f, tmp; @@ -856,61 +852,58 @@ void decoder_tcx_fx( /* set f to 0 to immediately switch to white noise */ f = hTcxDec->cummulative_damping_tcx; move16(); - if (0 != st->tcxonly) + if ( 0 != st->tcxonly ) { - f = 32767/*1.0f Q15*/; + f = 32767 /*1.0f Q15*/; move16(); } test(); test(); - IF ( (frame_cnt == 0) && (EQ_16(L_frameTCX, shr(hTcxDec->L_frameTCX, 1))) - && (st->tcxonly) && (!st->tonal_mdct_plc_active) && (EQ_16(st->nbLostCmpt, 1)) - && (hTcxCfg->tcx_last_overlap_mode != FULL_OVERLAP) - && (hTcxCfg->tcx_curr_overlap_mode != FULL_OVERLAP) ) + IF( ( frame_cnt == 0 ) && ( EQ_16( L_frameTCX, shr( hTcxDec->L_frameTCX, 1 ) ) ) && ( st->tcxonly ) && ( !st->tonal_mdct_plc_active ) && ( EQ_16( st->nbLostCmpt, 1 ) ) && ( hTcxCfg->tcx_last_overlap_mode != FULL_OVERLAP ) && ( hTcxCfg->tcx_curr_overlap_mode != FULL_OVERLAP ) ) { Word16 exp1, exp2; Word32 E_2ndlast, E_last; - E_2ndlast = CalculateAbsEnergy_fx(1, &(st->tonalMDCTconceal.lastBlockData.spectralData[0]), infoIGFStartLine, &exp2); - E_last = CalculateAbsEnergy_fx(1, &(st->tonalMDCTconceal.lastBlockData.spectralData[1]), infoIGFStartLine, &exp1); + E_2ndlast = CalculateAbsEnergy_fx( 1, &( st->tonalMDCTconceal.lastBlockData.spectralData[0] ), infoIGFStartLine, &exp2 ); + E_last = CalculateAbsEnergy_fx( 1, &( st->tonalMDCTconceal.lastBlockData.spectralData[1] ), infoIGFStartLine, &exp1 ); - BASOP_Util_Divide_MantExp(extract_h(E_2ndlast), exp2, extract_h(E_last), exp1, &tmp1, &tmp2); + BASOP_Util_Divide_MantExp( extract_h( E_2ndlast ), exp2, extract_h( E_last ), exp1, &tmp1, &tmp2 ); - tmp1 = shr(tmp1,2); /*Q13*/ + tmp1 = shr( tmp1, 2 ); /*Q13*/ #ifdef BASOP_NOGLOB - tmp1 = shl_sat(tmp1,tmp2); + tmp1 = shl_sat( tmp1, tmp2 ); #else - tmp1 = shl(tmp1,tmp2); + tmp1 = shl( tmp1, tmp2 ); #endif test(); test(); /* replace higher energy TCX5 frame by lower one to avoid energy fluctuation */ - IF(GT_16(tmp1,16384 /*2 in Q13*/)) + IF( GT_16( tmp1, 16384 /*2 in Q13*/ ) ) { - FOR(i=0; itonalMDCTconceal.lastBlockData.spectralData[i] = st->tonalMDCTconceal.lastBlockData.spectralData[i+1]; + st->tonalMDCTconceal.lastBlockData.spectralData[i] = st->tonalMDCTconceal.lastBlockData.spectralData[i + 1]; } } - ELSE IF(LT_16(tmp1,4096/*0.5 in Q13*/)) + ELSE IF( LT_16( tmp1, 4096 /*0.5 in Q13*/ ) ) { - FOR(i=0; itonalMDCTconceal.lastBlockData.spectralData[i+1] = st->tonalMDCTconceal.lastBlockData.spectralData[i]; + st->tonalMDCTconceal.lastBlockData.spectralData[i + 1] = st->tonalMDCTconceal.lastBlockData.spectralData[i]; } } } - noiseTiltFactor = 32767/*1.0f Q15*/; + noiseTiltFactor = 32767 /*1.0f Q15*/; move16(); tmp = 0; move16(); test(); - IF( GE_16(st->bits_frame, 256)&&st->rf_flag==0) + IF( GE_16( st->bits_frame, 256 ) && st->rf_flag == 0 ) { tmp = 1; move16(); @@ -918,24 +911,23 @@ void decoder_tcx_fx( tcxGetNoiseFillingTilt( A, M, L_frame, tmp, &noiseTiltFactor ); - TonalMDCTConceal_InsertNoise(&st->tonalMDCTconceal, x, &x_e, st->tonal_mdct_plc_active, &st->seed_tcx_plc, - noiseTiltFactor, f, + TonalMDCTConceal_InsertNoise( &st->tonalMDCTconceal, x, &x_e, st->tonal_mdct_plc_active, &st->seed_tcx_plc, + noiseTiltFactor, f, #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - concealment_noise, + concealment_noise, #endif - infoIGFStartLine ); - + infoIGFStartLine ); } } - IF (LT_16(L_spec, L_frame)) + IF( LT_16( L_spec, L_frame ) ) { - set32_fx(x+L_spec, 0, sub(L_frame,L_spec)); + set32_fx( x + L_spec, 0, sub( L_frame, L_spec ) ); } - ELSE IF (GT_16(L_spec, L_frameTCX)) + ELSE IF( GT_16( L_spec, L_frameTCX ) ) { - set32_fx(x+L_frameTCX, 0, sub(L_spec,L_frameTCX)); + set32_fx( x + L_frameTCX, 0, sub( L_spec, L_frameTCX ) ); } test(); @@ -947,36 +939,32 @@ void decoder_tcx_fx( test(); test(); test(); - IF ( bfi && (!st->enablePlcWaveadjust || EQ_16(temp_concealment_method, TCX_TONAL)) - && st->igf && (frame_cnt == 0) && (EQ_16(L_frameTCX, shr(hTcxDec->L_frameTCX, 1))) - && (st->tcxonly) && (!st->tonal_mdct_plc_active) && (EQ_16(st->nbLostCmpt, 1)) - && (hTcxCfg->tcx_last_overlap_mode != FULL_OVERLAP) - && (hTcxCfg->tcx_curr_overlap_mode != FULL_OVERLAP) ) + IF( bfi && ( !st->enablePlcWaveadjust || EQ_16( temp_concealment_method, TCX_TONAL ) ) && st->igf && ( frame_cnt == 0 ) && ( EQ_16( L_frameTCX, shr( hTcxDec->L_frameTCX, 1 ) ) ) && ( st->tcxonly ) && ( !st->tonal_mdct_plc_active ) && ( EQ_16( st->nbLostCmpt, 1 ) ) && ( hTcxCfg->tcx_last_overlap_mode != FULL_OVERLAP ) && ( hTcxCfg->tcx_curr_overlap_mode != FULL_OVERLAP ) ) { IGFDecCopyLPCFlatSpectrum( st->hIGFDec, x, x_e, IGF_GRID_LB_SHORT ); - Copy(st->hIGFDec->igfData.igf_curr_subframe[0][0], st->hIGFDec->igfData.igf_curr_subframe[1][0], IGF_MAX_SFB); + Copy( st->hIGFDec->igfData.igf_curr_subframe[0][0], st->hIGFDec->igfData.igf_curr_subframe[1][0], IGF_MAX_SFB ); } /*-----------------------------------------------------------* * Noise shaping in frequency domain (1/Wz) * *-----------------------------------------------------------*/ test(); - IF(st->igf && ! bfi) + IF( st->igf && !bfi ) { test(); - IF ( (EQ_16(L_frame, shr(st->L_frame, 1)))&&(st->tcxonly)) + IF( ( EQ_16( L_frame, shr( st->L_frame, 1 ) ) ) && ( st->tcxonly ) ) { - IGFDecCopyLPCFlatSpectrum( st->hIGFDec, x, x_e, IGF_GRID_LB_SHORT); + IGFDecCopyLPCFlatSpectrum( st->hIGFDec, x, x_e, IGF_GRID_LB_SHORT ); } ELSE { - IF (EQ_16(st->last_core, ACELP_CORE)) + IF( EQ_16( st->last_core, ACELP_CORE ) ) { - IGFDecCopyLPCFlatSpectrum(st->hIGFDec, x, x_e, IGF_GRID_LB_TRAN ); + IGFDecCopyLPCFlatSpectrum( st->hIGFDec, x, x_e, IGF_GRID_LB_TRAN ); } ELSE { - IGFDecCopyLPCFlatSpectrum(st->hIGFDec, x, x_e, IGF_GRID_LB_NORM ); + IGFDecCopyLPCFlatSpectrum( st->hIGFDec, x, x_e, IGF_GRID_LB_NORM ); } } } @@ -984,80 +972,80 @@ void decoder_tcx_fx( /* LPC gains already available */ test(); test(); - IF(!st->enablePlcWaveadjust || !bfi || (EQ_16(temp_concealment_method, TCX_TONAL))) + IF( !st->enablePlcWaveadjust || !bfi || ( EQ_16( temp_concealment_method, TCX_TONAL ) ) ) { - x_e = add(x_e, gain_tcx_e); - mdct_shaping(x, L_frame, gainlpc2, gainlpc2_e); - IF ( bfi == 0 ) + x_e = add( x_e, gain_tcx_e ); + mdct_shaping( x, L_frame, gainlpc2, gainlpc2_e ); + IF( bfi == 0 ) { - FOR (i = L_frame; i < L_spec; i++) + FOR( i = L_frame; i < L_spec; i++ ) { - x[i] = L_shl(Mpy_32_16_1(x[i], gainlpc2[FDNS_NPTS-1]), gainlpc2_e[FDNS_NPTS-1]); + x[i] = L_shl( Mpy_32_16_1( x[i], gainlpc2[FDNS_NPTS - 1] ), gainlpc2_e[FDNS_NPTS - 1] ); move32(); } } - set32_fx(x+L_spec, 0, sub(L_frameTCX, L_spec)); + set32_fx( x + L_spec, 0, sub( L_frameTCX, L_spec ) ); test(); test(); - IF (( bfi != 0) && ( !st->enablePlcWaveadjust || EQ_16(temp_concealment_method, TCX_TONAL))) + IF( ( bfi != 0 ) && ( !st->enablePlcWaveadjust || EQ_16( temp_concealment_method, TCX_TONAL ) ) ) { - scale_sig32(x+infoIGFStartLine, sub(L_spec, infoIGFStartLine), negate(gain_tcx_e)); + scale_sig32( x + infoIGFStartLine, sub( L_spec, infoIGFStartLine ), negate( gain_tcx_e ) ); } } /* PLC: [TCX: Tonal Concealment] */ IF( bfi && st->tonal_mdct_plc_active ) { - TonalMDCTConceal_Apply(&st->tonalMDCTconceal, x, &x_e); + TonalMDCTConceal_Apply( &st->tonalMDCTconceal, x, &x_e ); } - tmp32 = L_deposit_h(0); - if(hTcxDec->tcxltp_last_gain_unmodified > 0) + tmp32 = L_deposit_h( 0 ); + if ( hTcxDec->tcxltp_last_gain_unmodified > 0 ) { - tmp32 = L_add(st->old_fpitch, 0); + tmp32 = L_add( st->old_fpitch, 0 ); } tmp8 = 0; move16(); test(); - if(bfi && st->tonal_mdct_plc_active) + if ( bfi && st->tonal_mdct_plc_active ) { tmp8 = 1; move16(); } - TonalMDCTConceal_UpdateState(&st->tonalMDCTconceal, - L_frameTCX, - tmp32, - bfi, - tmp8); + TonalMDCTConceal_UpdateState( &st->tonalMDCTconceal, + L_frameTCX, + tmp32, + bfi, + tmp8 ); - IF (st->enablePlcWaveadjust) + IF( st->enablePlcWaveadjust ) { Word16 core; core = st->core; move16(); /* spectrum concealment */ - IF (bfi && (EQ_16(temp_concealment_method, TCX_NONTONAL))) + IF( bfi && ( EQ_16( temp_concealment_method, TCX_NONTONAL ) ) ) { /* x_e =31-x_scale; */ - concealment_decode_fix(core, x, &x_e, &st->plcInfo); + concealment_decode_fix( core, x, &x_e, &st->plcInfo ); } /* update spectrum buffer, tonality flag, etc. */ - concealment_update_x(bfi, core, st->tonality_flag, x, &x_e, &st->plcInfo); + concealment_update_x( bfi, core, st->tonality_flag, x, &x_e, &st->plcInfo ); } /*-----------------------------------------------------------* - * IGF * - *-----------------------------------------------------------*/ + * IGF * + *-----------------------------------------------------------*/ test(); test(); - IF (st->igf && !((EQ_16(L_frame, shr(st->L_frame, 1)))&&(st->tcxonly))) + IF( st->igf && !( ( EQ_16( L_frame, shr( st->L_frame, 1 ) ) ) && ( st->tcxonly ) ) ) { Word16 igfGridIdx; test(); test(); - IF ((EQ_16(st->last_core, ACELP_CORE))||(left_rect&&bfi)) + IF( ( EQ_16( st->last_core, ACELP_CORE ) ) || ( left_rect && bfi ) ) { /* packet loss after first TCX must be handled like transition frame */ igfGridIdx = IGF_GRID_LB_TRAN; @@ -1067,41 +1055,42 @@ void decoder_tcx_fx( igfGridIdx = IGF_GRID_LB_NORM; } - *st->hIGFDec->igfData.igfInfo.nfSeed = extract_l(L_mac0(13849L, nf_seed, 31821)); - IGFDecApplyMono(st->hIGFDec, x, &x_e, igfGridIdx, bfi); + *st->hIGFDec->igfData.igfInfo.nfSeed = extract_l( L_mac0( 13849L, nf_seed, 31821 ) ); + IGFDecApplyMono( st->hIGFDec, x, &x_e, igfGridIdx, bfi ); } test(); test(); - IF (st->igf && ((EQ_16(L_frame, shr(st->L_frame, 1)))&&(st->tcxonly))) + IF( st->igf && ( ( EQ_16( L_frame, shr( st->L_frame, 1 ) ) ) && ( st->tcxonly ) ) ) { - *st->hIGFDec->igfData.igfInfo.nfSeed = extract_l(L_mac0(13849L, nf_seed, 31821)); - IGFDecApplyMono(st->hIGFDec,x,&x_e,IGF_GRID_LB_SHORT,bfi); + *st->hIGFDec->igfData.igfInfo.nfSeed = extract_l( L_mac0( 13849L, nf_seed, 31821 ) ); + IGFDecApplyMono( st->hIGFDec, x, &x_e, IGF_GRID_LB_SHORT, bfi ); } - index = hTcxCfg->tcx_last_overlap_mode; /* backup last TCX overlap mode */ move16(); + index = hTcxCfg->tcx_last_overlap_mode; /* backup last TCX overlap mode */ + move16(); /* normalize spectrum to minimize IMDCT_fx noise */ - tmp1 = s_max(s_max(L_frame,L_frameTCX), L_spec); - s = s_max(0, sub(getScaleFactor32(x, tmp1), 4)); /* Keep 4 bits headroom for TNS */ - Scale_sig32(x, tmp1, s); - x_e = sub(x_e, s); + tmp1 = s_max( s_max( L_frame, L_frameTCX ), L_spec ); + s = s_max( 0, sub( getScaleFactor32( x, tmp1 ), 4 ) ); /* Keep 4 bits headroom for TNS */ + Scale_sig32( x, tmp1, s ); + x_e = sub( x_e, s ); - IF(st->igf) + IF( st->igf ) { test(); - IF(st->hIGFDec->flatteningTrigger != 0 && fUseTns == 0) + IF( st->hIGFDec->flatteningTrigger != 0 && fUseTns == 0 ) { Word16 startLine = st->hIGFDec->infoIGFStartLine; Word16 endLine = st->hIGFDec->infoIGFStopLine; - Word32 x_itf[N_MAX_TCX-IGF_START_MN]; + Word32 x_itf[N_MAX_TCX - IGF_START_MN]; Word16 j; - const Word16* chk_sparse = st->hIGFDec->flag_sparseBuf; - const Word32* virtualSpec = st->hIGFDec->virtualSpec; + const Word16 *chk_sparse = st->hIGFDec->flag_sparseBuf; + const Word32 *virtualSpec = st->hIGFDec->virtualSpec; const Word16 maxOrder = 8; Word16 curr_order = 0; /* not counted */ - Word16 A_itf[ITF_MAX_FILTER_ORDER+1]; + Word16 A_itf[ITF_MAX_FILTER_ORDER + 1]; Word16 Q_A_itf; Word16 predictionGain = 0; /* not counted */ @@ -1110,38 +1099,38 @@ void decoder_tcx_fx( move16(); - FOR (j = startLine; j < endLine; j++) + FOR( j = startLine; j < endLine; j++ ) { - IF (EQ_16(chk_sparse[j-IGF_START_MN], 2)) + IF( EQ_16( chk_sparse[j - IGF_START_MN], 2 ) ) { - x_itf[j-IGF_START_MN] = x[j]; + x_itf[j - IGF_START_MN] = x[j]; move32(); - x[j] = virtualSpec[j-IGF_START_MN]; + x[j] = virtualSpec[j - IGF_START_MN]; move32(); } } - ITF_Detect_fx(x+IGF_START_MN, startLine, endLine, maxOrder, A_itf, &Q_A_itf, &predictionGain, &curr_order, shl(x_e, 1)); - s = getScaleFactor32(&x[startLine], sub(endLine, startLine)); - s = sub(s, 2); - FOR(j = startLine; j < endLine; j++) + ITF_Detect_fx( x + IGF_START_MN, startLine, endLine, maxOrder, A_itf, &Q_A_itf, &predictionGain, &curr_order, shl( x_e, 1 ) ); + s = getScaleFactor32( &x[startLine], sub( endLine, startLine ) ); + s = sub( s, 2 ); + FOR( j = startLine; j < endLine; j++ ) { - x[j] = L_shl(x[j], s); + x[j] = L_shl( x[j], s ); move32(); } - ITF_Apply_fx(x, startLine, endLine, A_itf, Q_A_itf, curr_order); + ITF_Apply_fx( x, startLine, endLine, A_itf, Q_A_itf, curr_order ); - FOR(j = startLine; j < endLine; j++) + FOR( j = startLine; j < endLine; j++ ) { - x[j] = L_shr(x[j], s); + x[j] = L_shr( x[j], s ); move32(); } - FOR (j = startLine; j < endLine; j++) + FOR( j = startLine; j < endLine; j++ ) { - if (EQ_16(chk_sparse[j-IGF_START_MN],2)) + if ( EQ_16( chk_sparse[j - IGF_START_MN], 2 ) ) { - x[j] = x_itf[j-IGF_START_MN]; + x[j] = x_itf[j - IGF_START_MN]; move32(); } } @@ -1149,7 +1138,7 @@ void decoder_tcx_fx( } test(); - IF ((EQ_16(L_frame, shr(st->L_frame, 1)))&&(st->tcxonly!=0)) + IF( ( EQ_16( L_frame, shr( st->L_frame, 1 ) ) ) && ( st->tcxonly != 0 ) ) { Word16 L = L_frameTCX; move16(); @@ -1157,22 +1146,21 @@ void decoder_tcx_fx( test(); test(); test(); - if ((hTcxCfg->fIsTNSAllowed != 0 && fUseTns != 0 && bfi == 0) || (GT_16(L_spec, L_frameTCX))) + if ( ( hTcxCfg->fIsTNSAllowed != 0 && fUseTns != 0 && bfi == 0 ) || ( GT_16( L_spec, L_frameTCX ) ) ) { L = L_spec; move16(); } - tcxInvertWindowGrouping(hTcxCfg, - xn_buf32, - x, - L, - fUseTns, - st->last_core, - index, - frame_cnt, - bfi - ); + tcxInvertWindowGrouping( hTcxCfg, + xn_buf32, + x, + L, + fUseTns, + st->last_core, + index, + frame_cnt, + bfi ); } @@ -1182,43 +1170,41 @@ void decoder_tcx_fx( test(); test(); - IF ((hTcxCfg->fIsTNSAllowed != 0) && (fUseTns != 0) && bfi == 0 ) + IF( ( hTcxCfg->fIsTNSAllowed != 0 ) && ( fUseTns != 0 ) && bfi == 0 ) { /* Apply TNS to get the reconstructed signal */ test(); test(); - SetTnsConfig(hTcxCfg, L_frame_glob == st->L_frame, (st->last_core == ACELP_CORE) && (frame_cnt == 0)); - ApplyTnsFilter(hTcxCfg->pCurrentTnsConfig, &tnsData, x, 0); + SetTnsConfig( hTcxCfg, L_frame_glob == st->L_frame, ( st->last_core == ACELP_CORE ) && ( frame_cnt == 0 ) ); + ApplyTnsFilter( hTcxCfg->pCurrentTnsConfig, &tnsData, x, 0 ); test(); - IF ((EQ_16(L_frame, shr(st->L_frame, 1)))&&(st->tcxonly!=0)) + IF( ( EQ_16( L_frame, shr( st->L_frame, 1 ) ) ) && ( st->tcxonly != 0 ) ) { test(); test(); test(); - IF ((hTcxCfg->tcx_last_overlap_mode != FULL_OVERLAP) || - ((hTcxCfg->tcx_curr_overlap_mode == FULL_OVERLAP) && (frame_cnt == 0) && (index == 0)) - ) + IF( ( hTcxCfg->tcx_last_overlap_mode != FULL_OVERLAP ) || + ( ( hTcxCfg->tcx_curr_overlap_mode == FULL_OVERLAP ) && ( frame_cnt == 0 ) && ( index == 0 ) ) ) { - tmp1 = shr(hTcxCfg->tnsConfig[0][0].iFilterBorders[0], 1); + tmp1 = shr( hTcxCfg->tnsConfig[0][0].iFilterBorders[0], 1 ); /* undo rearrangement of LF sub-window lines for TNS synthesis filtering */ - IF (s_max(L_frameTCX, L_spec) > hTcxCfg->tnsConfig[0][0].iFilterBorders[0]) + IF( s_max( L_frameTCX, L_spec ) > hTcxCfg->tnsConfig[0][0].iFilterBorders[0] ) { - tmp2 = shr(s_max(L_frameTCX, L_spec), 1); - Copy32(x+tmp1+8, x+tmp2+8, sub(tmp1, 8)); - Copy32(x+8, x+tmp2, 8); - Copy32(x+16, x+8, sub(tmp1, 8)); - set32_fx(x+tmp1, 0, sub(tmp2, tmp1)); - set32_fx(x+tmp2+tmp1, 0, sub(tmp2, tmp1)); + tmp2 = shr( s_max( L_frameTCX, L_spec ), 1 ); + Copy32( x + tmp1 + 8, x + tmp2 + 8, sub( tmp1, 8 ) ); + Copy32( x + 8, x + tmp2, 8 ); + Copy32( x + 16, x + 8, sub( tmp1, 8 ) ); + set32_fx( x + tmp1, 0, sub( tmp2, tmp1 ) ); + set32_fx( x + tmp2 + tmp1, 0, sub( tmp2, tmp1 ) ); } ELSE { - Copy32(x+8, xn_buf32, 8); - Copy32(x+16, x+8, sub(tmp1,8)); - Copy32(xn_buf32, x+tmp1, 8); + Copy32( x + 8, xn_buf32, 8 ); + Copy32( x + 16, x + 8, sub( tmp1, 8 ) ); + Copy32( xn_buf32, x + tmp1, 8 ); } - } } } @@ -1229,78 +1215,75 @@ void decoder_tcx_fx( *-----------------------------------------------------------*/ - Copy32(x, xn_buf32, s_max(s_max(L_frame,L_frameTCX), L_spec)); + Copy32( x, xn_buf32, s_max( s_max( L_frame, L_frameTCX ), L_spec ) ); - IF(st->igf != 0) + IF( st->igf != 0 ) { - set32_fx( xn_buf32+st->hIGFDec->infoIGFStartLine, 0, sub(L_frameTCX, st->hIGFDec->infoIGFStartLine) ); + set32_fx( xn_buf32 + st->hIGFDec->infoIGFStartLine, 0, sub( L_frameTCX, st->hIGFDec->infoIGFStartLine ) ); } - IMDCT_fx(xn_buf32, x_e, hTcxDec->syn_Overl, hTcxDec->syn_Overl_TDAC, xn_buf, hTcxCfg->tcx_aldo_window_1, hTcxCfg->tcx_aldo_window_1_trunc, hTcxCfg->tcx_aldo_window_2, - st->hTcxCfg->tcx_mdct_window_half, hTcxCfg->tcx_mdct_window_minimum, st->hTcxCfg->tcx_mdct_window_trans, st->hTcxCfg->tcx_mdct_window_half_length, hTcxCfg->tcx_mdct_window_min_length, - index, left_rect, tcx_offset, overlap, L_frame, L_frameTCX, shr(s_max(L_frameTCX, L_spec), 1), L_frame_glob, frame_cnt, bfi, st->hHQ_core->old_out_LB_fx, - &st->hHQ_core->Q_old_wtda_LB,st, 0, acelp_zir); + IMDCT_fx( xn_buf32, x_e, hTcxDec->syn_Overl, hTcxDec->syn_Overl_TDAC, xn_buf, hTcxCfg->tcx_aldo_window_1, hTcxCfg->tcx_aldo_window_1_trunc, hTcxCfg->tcx_aldo_window_2, + st->hTcxCfg->tcx_mdct_window_half, hTcxCfg->tcx_mdct_window_minimum, st->hTcxCfg->tcx_mdct_window_trans, st->hTcxCfg->tcx_mdct_window_half_length, hTcxCfg->tcx_mdct_window_min_length, + index, left_rect, tcx_offset, overlap, L_frame, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frame_glob, frame_cnt, bfi, st->hHQ_core->old_out_LB_fx, + &st->hHQ_core->Q_old_wtda_LB, st, 0, acelp_zir ); /* Generate additional comfort noise to mask potential coding artefacts */ - IF ( st->flag_cna != 0 ) + IF( st->flag_cna != 0 ) { - generate_masking_noise_mdct_fx (x, &x_e, st->hFdCngDec->hFdCngCom, s_max(s_max(L_frame,L_frameTCX), L_spec) ); + generate_masking_noise_mdct_fx( x, &x_e, st->hFdCngDec->hFdCngCom, s_max( s_max( L_frame, L_frameTCX ), L_spec ) ); } - IMDCT_fx(x, x_e, hTcxDec->syn_OverlFB, hTcxDec->syn_Overl_TDACFB, xn_bufFB, hTcxCfg->tcx_aldo_window_1_FB, hTcxCfg->tcx_aldo_window_1_FB_trunc, hTcxCfg->tcx_aldo_window_2_FB, - hTcxCfg->tcx_mdct_window_halfFB, hTcxCfg->tcx_mdct_window_minimumFB, hTcxCfg->tcx_mdct_window_transFB, hTcxCfg->tcx_mdct_window_half_lengthFB, hTcxCfg->tcx_mdct_window_min_lengthFB, - index, left_rect, tcx_offsetFB, overlapFB, L_frameTCX, L_frameTCX, shr(s_max(L_frameTCX, L_spec), 1), L_frameTCX_glob, - frame_cnt, bfi, st->hHQ_core->old_out_fx, &st->hHQ_core->Q_old_wtda, st, div_l(L_mult(FSCALE_DENOM, L_frameTCX_glob), L_frame_glob), acelp_zir); + IMDCT_fx( x, x_e, hTcxDec->syn_OverlFB, hTcxDec->syn_Overl_TDACFB, xn_bufFB, hTcxCfg->tcx_aldo_window_1_FB, hTcxCfg->tcx_aldo_window_1_FB_trunc, hTcxCfg->tcx_aldo_window_2_FB, + hTcxCfg->tcx_mdct_window_halfFB, hTcxCfg->tcx_mdct_window_minimumFB, hTcxCfg->tcx_mdct_window_transFB, hTcxCfg->tcx_mdct_window_half_lengthFB, hTcxCfg->tcx_mdct_window_min_lengthFB, + index, left_rect, tcx_offsetFB, overlapFB, L_frameTCX, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frameTCX_glob, + frame_cnt, bfi, st->hHQ_core->old_out_fx, &st->hHQ_core->Q_old_wtda, st, div_l( L_mult( FSCALE_DENOM, L_frameTCX_glob ), L_frame_glob ), acelp_zir ); /* PLC: [TCX: Tonal Concealment] */ - IF (!bfi) + IF( !bfi ) { st->second_last_tns_active = st->last_tns_active; st->last_tns_active = 0; move16(); test(); - if ( hTcxCfg->fIsTNSAllowed && fUseTns) + if ( hTcxCfg->fIsTNSAllowed && fUseTns ) { st->last_tns_active = 1; move16(); } - hTcxDec->tcxltp_third_last_pitch = hTcxDec->tcxltp_second_last_pitch; + hTcxDec->tcxltp_third_last_pitch = hTcxDec->tcxltp_second_last_pitch; move32(); hTcxDec->tcxltp_second_last_pitch = st->old_fpitch; move32(); - st->old_fpitch = L_add(L_deposit_h(hTcxLtpDec->tcxltp_pitch_int), L_mult(hTcxLtpDec->tcxltp_pitch_fr, div_s(1,st->pit_res_max) /*Q16*/)); - st->old_fpitchFB = Mpy_32_16_1(st->old_fpitch/*Q16*/, mult_r(L_frameTCX/*Q0*/,getInvFrameLen(L_frame)/*Q21*/)/*Q6*/)/*Q7*/; - st->old_fpitchFB = L_shr(st->old_fpitchFB,7-16);/*->Q16*/ + st->old_fpitch = L_add( L_deposit_h( hTcxLtpDec->tcxltp_pitch_int ), L_mult( hTcxLtpDec->tcxltp_pitch_fr, div_s( 1, st->pit_res_max ) /*Q16*/ ) ); + st->old_fpitchFB = Mpy_32_16_1( st->old_fpitch /*Q16*/, mult_r( L_frameTCX /*Q0*/, getInvFrameLen( L_frame ) /*Q21*/ ) /*Q6*/ ) /*Q7*/; + st->old_fpitchFB = L_shr( st->old_fpitchFB, 7 - 16 ); /*->Q16*/ } /* Update old_syn_overl */ - IF (st->hTcxCfg->last_aldo == 0) + IF( st->hTcxCfg->last_aldo == 0 ) { - Copy(xn_buf+L_frame, hTcxDec->syn_Overl, overlap); - Copy(xn_bufFB+L_frameTCX, hTcxDec->syn_OverlFB, overlapFB); + Copy( xn_buf + L_frame, hTcxDec->syn_Overl, overlap ); + Copy( xn_bufFB + L_frameTCX, hTcxDec->syn_OverlFB, overlapFB ); } /* Output */ - Copy(xn_buf+shr(overlap,1)-tcx_offset, synth, L_frame_glob); - Copy(xn_bufFB+shr(overlapFB,1)-tcx_offsetFB, synthFB, L_frameTCX_glob); - + Copy( xn_buf + shr( overlap, 1 ) - tcx_offset, synth, L_frame_glob ); + Copy( xn_bufFB + shr( overlapFB, 1 ) - tcx_offsetFB, synthFB, L_frameTCX_glob ); } - -void decoder_tcx_post_fx(Decoder_State *st_fx, - Word16 *synth, - Word16 *synthFB, - Word16 *A, - Word16 bfi - ) +void decoder_tcx_post_fx( Decoder_State *st_fx, + Word16 *synth, + Word16 *synthFB, + Word16 *A, + Word16 bfi ) { Word16 i; Word16 level_syn; Word16 level_syn_e; Word32 step; - Word16 gainCNG,gainCNG_e; + Word16 gainCNG, gainCNG_e; Word16 xn_buf[L_FRAME_MAX]; Word16 tmp1, tmp2, s; Word32 tmp32; @@ -1318,50 +1301,50 @@ void decoder_tcx_post_fx(Decoder_State *st_fx, /* first TCX frame after ACELP; overwrite ltp initialization done during acelp PLC */ test(); test(); - if (!st_fx->bfi && st_fx->prev_bfi && EQ_16(st_fx->last_core,ACELP_CORE)) + if ( !st_fx->bfi && st_fx->prev_bfi && EQ_16( st_fx->last_core, ACELP_CORE ) ) { hTcxDec->tcxltp_last_gain_unmodified = 0; move16(); } - IF (bfi != 0 && st_fx->use_partial_copy == 0) + IF( bfi != 0 && st_fx->use_partial_copy == 0 ) { test(); /* run lpc gain compensation not for waveform adjustment */ - IF ( 0 == st_fx->enablePlcWaveadjust || EQ_16(st_fx->plcInfo.concealment_method,TCX_TONAL)) + IF( 0 == st_fx->enablePlcWaveadjust || EQ_16( st_fx->plcInfo.concealment_method, TCX_TONAL ) ) { UWord32 dmy; - tmp32_1 /*gainHelperFB*/ = L_shl_r(L_deposit_h(hTcxDec->gainHelper) ,sub(hTcxDec->gainHelper_e, 31-28));/*Q28*/ - tmp32_2 /*stepCompensateFB*/= L_shl_r(L_deposit_h(hTcxDec->stepCompensate),sub(hTcxDec->stepCompensate_e,31-28));/*Q28*/ + tmp32_1 /*gainHelperFB*/ = L_shl_r( L_deposit_h( hTcxDec->gainHelper ), sub( hTcxDec->gainHelper_e, 31 - 28 ) ); /*Q28*/ + tmp32_2 /*stepCompensateFB*/ = L_shl_r( L_deposit_h( hTcxDec->stepCompensate ), sub( hTcxDec->stepCompensate_e, 31 - 28 ) ); /*Q28*/ - Mpy_32_32_ss(tmp32_2/*Q28*/, - L_shl(L_mult0(st_fx->L_frame, - getInvFrameLen(hTcxDec->L_frameTCX)/*Q21*/)/*Q21*/, - 8)/*Q29*/, - &tmp32_2, - &dmy ); /*Q26*/ + Mpy_32_32_ss( tmp32_2 /*Q28*/, + L_shl( L_mult0( st_fx->L_frame, + getInvFrameLen( hTcxDec->L_frameTCX ) /*Q21*/ ) /*Q21*/, + 8 ) /*Q29*/, + &tmp32_2, + &dmy ); /*Q26*/ - tmp32_2 = L_shl(tmp32_2,3-1); /*Q28*/ + tmp32_2 = L_shl( tmp32_2, 3 - 1 ); /*Q28*/ - FOR( i=0; i < hTcxDec->L_frameTCX; i++ ) + FOR( i = 0; i < hTcxDec->L_frameTCX; i++ ) { - tmp32 = L_shl(tmp32_1/*Q28*/,-(28-15)); /*16Q15*/ + tmp32 = L_shl( tmp32_1 /*Q28*/, -( 28 - 15 ) ); /*16Q15*/ #ifdef BASOP_NOGLOB - synthFB[i] = round_fx_sat(L_shl_sat(Mpy_32_16_1(tmp32,synthFB[i]), 16)); + synthFB[i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( tmp32, synthFB[i] ), 16 ) ); #else - synthFB[i] = round_fx(L_shl(Mpy_32_16_1(tmp32,synthFB[i]), 16)); + synthFB[i] = round_fx( L_shl( Mpy_32_16_1( tmp32, synthFB[i] ), 16 ) ); #endif move16(); - tmp32_1 = L_sub(tmp32_1 , tmp32_2); + tmp32_1 = L_sub( tmp32_1, tmp32_2 ); } } - tmp32_1 /*gainHelper*/ = L_shl_r(L_deposit_h(hTcxDec->gainHelper) ,sub(hTcxDec->gainHelper_e, 31-28));/*Q28*/ - tmp32_2 /*stepCompensate*/= L_shl_r(L_deposit_h(hTcxDec->stepCompensate),sub(hTcxDec->stepCompensate_e,31-28));/*Q28*/ - FOR( i=0; i < st_fx->L_frame; i++ ) + tmp32_1 /*gainHelper*/ = L_shl_r( L_deposit_h( hTcxDec->gainHelper ), sub( hTcxDec->gainHelper_e, 31 - 28 ) ); /*Q28*/ + tmp32_2 /*stepCompensate*/ = L_shl_r( L_deposit_h( hTcxDec->stepCompensate ), sub( hTcxDec->stepCompensate_e, 31 - 28 ) ); /*Q28*/ + FOR( i = 0; i < st_fx->L_frame; i++ ) { - tmp32 = L_shl(tmp32_1/*Q28*/,-(28-15)); /*16Q15*/ - xn_buf[i] = extract_l(Mpy_32_16_1(tmp32,xn_buf[i])); + tmp32 = L_shl( tmp32_1 /*Q28*/, -( 28 - 15 ) ); /*16Q15*/ + xn_buf[i] = extract_l( Mpy_32_16_1( tmp32, xn_buf[i] ) ); move16(); - tmp32_1 = L_sub(tmp32_1 , tmp32_2); + tmp32_1 = L_sub( tmp32_1, tmp32_2 ); } } @@ -1369,53 +1352,53 @@ void decoder_tcx_post_fx(Decoder_State *st_fx, * PLC: estimate and update CNG energy */ /* level_syn = (float)sqrt(( dot_product(synthFB, synthFB, L_frame)) / L_frame ); */ - s = sub(getScaleFactor16(synthFB, hTcxDec->L_frameTCX), 4); + s = sub( getScaleFactor16( synthFB, hTcxDec->L_frameTCX ), 4 ); { Word64 tmp64 = 0; move64(); - FOR (i = 0; i < hTcxDec->L_frameTCX; i++) + FOR( i = 0; i < hTcxDec->L_frameTCX; i++ ) { - tmp1 = shl(synthFB[i], s); - tmp64 = W_mac0_16_16(tmp64, tmp1, tmp1); + tmp1 = shl( synthFB[i], s ); + tmp64 = W_mac0_16_16( tmp64, tmp1, tmp1 ); } - tmp32 = W_sat_l(tmp64); + tmp32 = W_sat_l( tmp64 ); } - tmp32 = Mpy_32_16_1(tmp32, getInvFrameLen(hTcxDec->L_frameTCX)); - tmp2 = norm_l(tmp32); + tmp32 = Mpy_32_16_1( tmp32, getInvFrameLen( hTcxDec->L_frameTCX ) ); + tmp2 = norm_l( tmp32 ); #ifdef BASOP_NOGLOB - tmp1 = round_fx_o(L_shl(tmp32, tmp2), &Overflow); + tmp1 = round_fx_o( L_shl( tmp32, tmp2 ), &Overflow ); #else - tmp1 = round_fx(L_shl(tmp32, tmp2)); + tmp1 = round_fx( L_shl( tmp32, tmp2 ) ); #endif - s = sub(sub(sub(1, shl(s, 1)), 6/*table lookup for inverse framelength*/), tmp2); - tmp1 = Sqrt16(tmp1, &s); + s = sub( sub( sub( 1, shl( s, 1 ) ), 6 /*table lookup for inverse framelength*/ ), tmp2 ); + tmp1 = Sqrt16( tmp1, &s ); move16(); level_syn = tmp1; /*Q0*/ /* PLC: [TCX: Fade-out] * PLC: estimate and update CNG energy */ - level_syn_e = add(s,15); + level_syn_e = add( s, 15 ); test(); test(); - IF (bfi == 0 && st_fx->tcxonly != 0 && EQ_16(st_fx->clas_dec , UNVOICED_CLAS)) + IF( bfi == 0 && st_fx->tcxonly != 0 && EQ_16( st_fx->clas_dec, UNVOICED_CLAS ) ) { Word16 Qnew_levelBackgroundTrace; Qnew_levelBackgroundTrace = 0; move16(); - minimumStatistics_fx(hTcxDec->conNoiseLevelMemory, /*Q15*/ - &hTcxDec->conNoiseLevelIndex, /*Q0 */ - &hTcxDec->conCurrLevelIndex, /*Q0 */ - &hTcxDec->conCngLevelBackgroundTrace, /*Q15*/ - &hTcxDec->conLastFrameLevel, /*Q15*/ - level_syn, /*Q15*/ - hTcxDec->conNoiseLevelMemory_e, - hTcxDec->conCngLevelBackgroundTrace_e, - &Qnew_levelBackgroundTrace, - &hTcxDec->conLastFrameLevel_e, - level_syn_e /*scaling of level_syn*/ - ); + minimumStatistics_fx( hTcxDec->conNoiseLevelMemory, /*Q15*/ + &hTcxDec->conNoiseLevelIndex, /*Q0 */ + &hTcxDec->conCurrLevelIndex, /*Q0 */ + &hTcxDec->conCngLevelBackgroundTrace, /*Q15*/ + &hTcxDec->conLastFrameLevel, /*Q15*/ + level_syn, /*Q15*/ + hTcxDec->conNoiseLevelMemory_e, + hTcxDec->conCngLevelBackgroundTrace_e, + &Qnew_levelBackgroundTrace, + &hTcxDec->conLastFrameLevel_e, + level_syn_e /*scaling of level_syn*/ + ); /*note: All parameters being different from Q0 have to have the same Q-format*/ @@ -1425,91 +1408,92 @@ void decoder_tcx_post_fx(Decoder_State *st_fx, /* PLC: [TCX: Fade-out] * PLC: fade-out in time domain */ - IF (bfi != 0) + IF( bfi != 0 ) { Word32 conceal_eof_gain32; Word32 conceal_eof_gainFB; move16(); move16(); gainCNG = 1; - gainCNG_e = 14+15+6; /*gainCNG is 2`097`152 - should be enough in case tracinglevel =~0 */ - IF (st_fx->tcxonly != 0) + gainCNG_e = 14 + 15 + 6; /*gainCNG is 2`097`152 - should be enough in case tracinglevel =~0 */ + IF( st_fx->tcxonly != 0 ) { /*gainCNG = st_fx->conCngLevelBackgroundTrace/(tracingLevel+0.01f);*/ - IF(level_syn != 0) + IF( level_syn != 0 ) { - BASOP_Util_Divide_MantExp ( + BASOP_Util_Divide_MantExp( hTcxDec->conCngLevelBackgroundTrace, hTcxDec->conCngLevelBackgroundTrace_e, level_syn, level_syn_e, &gainCNG, - &gainCNG_e); + &gainCNG_e ); } } ELSE { /*gainCNG = st_fx->cngTDLevel/(tracingLevel+0.01f);*/ - IF(level_syn != 0) + IF( level_syn != 0 ) { - BASOP_Util_Divide_MantExp ( + BASOP_Util_Divide_MantExp( st_fx->cngTDLevel, st_fx->cngTDLevel_e, level_syn, level_syn_e, &gainCNG, - &gainCNG_e); + &gainCNG_e ); } } - if ((EQ_16(st_fx->nbLostCmpt, 1))) + if ( ( EQ_16( st_fx->nbLostCmpt, 1 ) ) ) { - hTcxDec->conceal_eof_gain = 16384/*1.0f Q14*/; /*Q14*/ move16(); + hTcxDec->conceal_eof_gain = 16384 /*1.0f Q14*/; /*Q14*/ + move16(); } /* step = (st_fx->conceal_eof_gain - ( st_fx->conceal_eof_gain * st_fx->damping + gainCNG * (1 - st_fx->damping) )) / st_fx->L_frame; */ tmp2 = BASOP_Util_Add_MantExp( - mult_r(hTcxDec->conceal_eof_gain /*Q14*/, - hTcxDec->damping /*Q14*/), - 15-13/*->Q15*/, - mult_r(gainCNG/*Q15*/,sub(0x4000, hTcxDec->damping/*Q14*/)) /*Q14*/, - add(gainCNG_e,15-14)/*->Q15*/, - &tmp1); - tmp2 = BASOP_Util_Add_MantExp(hTcxDec->conceal_eof_gain, 15-14, negate(tmp1), tmp2, &tmp1); + mult_r( hTcxDec->conceal_eof_gain /*Q14*/, + hTcxDec->damping /*Q14*/ ), + 15 - 13 /*->Q15*/, + mult_r( gainCNG /*Q15*/, sub( 0x4000, hTcxDec->damping /*Q14*/ ) ) /*Q14*/, + add( gainCNG_e, 15 - 14 ) /*->Q15*/, + &tmp1 ); + tmp2 = BASOP_Util_Add_MantExp( hTcxDec->conceal_eof_gain, 15 - 14, negate( tmp1 ), tmp2, &tmp1 ); #ifdef BASOP_NOGLOB - step = L_shl_o(L_mult(tmp1, getInvFrameLen(st_fx->L_frame)), sub(tmp2, 6/*scaling from table lookup*/ + 1/*go to Q30*/), &Overflow); /*Q30*/ + step = L_shl_o( L_mult( tmp1, getInvFrameLen( st_fx->L_frame ) ), sub( tmp2, 6 /*scaling from table lookup*/ + 1 /*go to Q30*/ ), &Overflow ); /*Q30*/ #else - step = L_shl(L_mult(tmp1, getInvFrameLen(st_fx->L_frame)), sub(tmp2,6/*scaling from table lookup*/ +1/*go to Q30*/)); /*Q30*/ + step = L_shl( L_mult( tmp1, getInvFrameLen( st_fx->L_frame ) ), sub( tmp2, 6 /*scaling from table lookup*/ + 1 /*go to Q30*/ ) ); /*Q30*/ #endif { Word32 stepFB; UWord32 dmy; - conceal_eof_gainFB = L_deposit_h(hTcxDec->conceal_eof_gain); /*Q30*/ - Mpy_32_32_ss(step,L_shl(L_mult0(st_fx->L_frame, getInvFrameLen(hTcxDec->L_frameTCX)),8),&stepFB ,&dmy ); + conceal_eof_gainFB = L_deposit_h( hTcxDec->conceal_eof_gain ); /*Q30*/ + Mpy_32_32_ss( step, L_shl( L_mult0( st_fx->L_frame, getInvFrameLen( hTcxDec->L_frameTCX ) ), 8 ), &stepFB, &dmy ); #ifdef BASOP_NOGLOB - stepFB = L_shl_o(stepFB, 3 - 1, &Overflow); /*Q30*/ + stepFB = L_shl_o( stepFB, 3 - 1, &Overflow ); /*Q30*/ #else - stepFB = L_shl(stepFB,3-1); /*Q30*/ + stepFB = L_shl( stepFB, 3 - 1 ); /*Q30*/ #endif - FOR( i=0; i < hTcxDec->L_frameTCX; i++ ) + FOR( i = 0; i < hTcxDec->L_frameTCX; i++ ) { #ifdef BASOP_NOGLOB synthFB[i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( conceal_eof_gainFB, synthFB[i] ), 1 ) ); #else - synthFB[i] = round_fx(L_shl(Mpy_32_16_1(conceal_eof_gainFB, synthFB[i]),1)); + synthFB[i] = round_fx( L_shl( Mpy_32_16_1( conceal_eof_gainFB, synthFB[i] ), 1 ) ); #endif move16(); #ifdef BASOP_NOGLOB - conceal_eof_gainFB = L_sub_o(conceal_eof_gainFB, stepFB, &Overflow); + conceal_eof_gainFB = L_sub_o( conceal_eof_gainFB, stepFB, &Overflow ); #else - conceal_eof_gainFB = L_sub(conceal_eof_gainFB, stepFB); + conceal_eof_gainFB = L_sub( conceal_eof_gainFB, stepFB ); #endif } } - conceal_eof_gain32 = L_deposit_h(hTcxDec->conceal_eof_gain); /*Q30*/ - FOR( i=0; i < st_fx->L_frame; i++ ) + conceal_eof_gain32 = L_deposit_h( hTcxDec->conceal_eof_gain ); /*Q30*/ + FOR( i = 0; i < st_fx->L_frame; i++ ) { #ifdef BASOP_NOGLOB xn_buf[i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( conceal_eof_gain32 /*Q30*/, xn_buf[i] ), 1 ) ); @@ -1518,42 +1502,43 @@ void decoder_tcx_post_fx(Decoder_State *st_fx, #endif move16(); #ifdef BASOP_NOGLOB - conceal_eof_gain32 = L_sub_o(conceal_eof_gain32, step, &Overflow); + conceal_eof_gain32 = L_sub_o( conceal_eof_gain32, step, &Overflow ); #else - conceal_eof_gain32 = L_sub(conceal_eof_gain32,step); + conceal_eof_gain32 = L_sub( conceal_eof_gain32, step ); #endif } #ifdef BASOP_NOGLOB - hTcxDec->conceal_eof_gain = round_fx_o(conceal_eof_gain32, &Overflow); /*Q14*/ move16(); + hTcxDec->conceal_eof_gain = round_fx_o( conceal_eof_gain32, &Overflow ); /*Q14*/ + move16(); #else - hTcxDec->conceal_eof_gain = round_fx(conceal_eof_gain32); /*Q14*/ move16(); + hTcxDec->conceal_eof_gain = round_fx( conceal_eof_gain32 ); /*Q14*/ + move16(); #endif - /* run lpc gain compensation not for waveform adjustment */ test(); - IF ( 0 == st_fx->enablePlcWaveadjust || EQ_16(st_fx->plcInfo.concealment_method,TCX_TONAL)) + /* run lpc gain compensation not for waveform adjustment */ test(); + IF( 0 == st_fx->enablePlcWaveadjust || EQ_16( st_fx->plcInfo.concealment_method, TCX_TONAL ) ) { #ifdef BASOP_NOGLOB - st_fx->plcInfo.recovery_gain = extract_h(L_shl_o(Mpy_32_16_1(conceal_eof_gainFB, - st_fx->last_concealed_gain_syn_deemph), - st_fx->last_concealed_gain_syn_deemph_e, &Overflow - ));/*Q30->Q14*/ + st_fx->plcInfo.recovery_gain = extract_h( L_shl_o( Mpy_32_16_1( conceal_eof_gainFB, + st_fx->last_concealed_gain_syn_deemph ), + st_fx->last_concealed_gain_syn_deemph_e, &Overflow ) ); /*Q30->Q14*/ #else - st_fx->plcInfo.recovery_gain = extract_h(L_shl(Mpy_32_16_1(conceal_eof_gainFB, - st_fx->last_concealed_gain_syn_deemph), - st_fx->last_concealed_gain_syn_deemph_e - ));/*Q30->Q14*/ + st_fx->plcInfo.recovery_gain = extract_h( L_shl( Mpy_32_16_1( conceal_eof_gainFB, + st_fx->last_concealed_gain_syn_deemph ), + st_fx->last_concealed_gain_syn_deemph_e ) ); /*Q30->Q14*/ #endif } ELSE { - st_fx->plcInfo.recovery_gain = extract_h(conceal_eof_gainFB); /*Q14*/ + st_fx->plcInfo.recovery_gain = extract_h( conceal_eof_gainFB ); /*Q14*/ } st_fx->plcInfo.step_concealgain_fx = #ifdef BASOP_NOGLOB - round_fx_sat(L_shl_sat(L_mult0( round_fx_sat(step), round_fx_sat(L_shl_sat(L_mult0(st_fx->L_frame, getInvFrameLen(hTcxDec->L_frameTCX)), 8))), 3)); /*Q15*/ + round_fx_sat( L_shl_sat( L_mult0( round_fx_sat( step ), round_fx_sat( L_shl_sat( L_mult0( st_fx->L_frame, getInvFrameLen( hTcxDec->L_frameTCX ) ), 8 ) ) ), 3 ) ); /*Q15*/ #else - round_fx(L_shl(L_mult0( - round_fx(step), - round_fx(L_shl(L_mult0(st_fx->L_frame, getInvFrameLen(hTcxDec->L_frameTCX)),8))),3)); /*Q15*/ + round_fx( L_shl( L_mult0( + round_fx( step ), + round_fx( L_shl( L_mult0( st_fx->L_frame, getInvFrameLen( hTcxDec->L_frameTCX ) ), 8 ) ) ), + 3 ) ); /*Q15*/ #endif } @@ -1562,58 +1547,56 @@ void decoder_tcx_post_fx(Decoder_State *st_fx, *-----------------------------------------------------------*/ /* Update synth, exc and old_Aq */ - tcx_decoder_memory_update(xn_buf, /*Q0*/ - synth, /*Q0*/ - A, - st_fx, - 0 - ); + tcx_decoder_memory_update( xn_buf, /*Q0*/ + synth, /*Q0*/ + A, + st_fx, + 0 ); /* PLC: [TCX: Memory update] */ st_fx->old_pitch_buf_fx[0] = st_fx->old_pitch_buf_fx[st_fx->nb_subfr]; move32(); - st_fx->old_pitch_buf_fx[1] = st_fx->old_pitch_buf_fx[st_fx->nb_subfr+1]; + st_fx->old_pitch_buf_fx[1] = st_fx->old_pitch_buf_fx[st_fx->nb_subfr + 1]; move32(); - Copy32(&st_fx->old_pitch_buf_fx[st_fx->nb_subfr+2], &st_fx->old_pitch_buf_fx[2], st_fx->nb_subfr); - set32_fx(&st_fx->old_pitch_buf_fx[st_fx->nb_subfr+2], st_fx->old_fpitch, st_fx->nb_subfr); -#ifdef BASOP_NOGLOB /*TBV st_fx->old_fpitch seems to have an odd value for this bitstream stv48n1_dtx_sw_164_1280_48kHz.f06.COD at frame 10 */ - st_fx->bfi_pitch_fx = shl_sat(round_fx(st_fx->old_fpitch),6); + Copy32( &st_fx->old_pitch_buf_fx[st_fx->nb_subfr + 2], &st_fx->old_pitch_buf_fx[2], st_fx->nb_subfr ); + set32_fx( &st_fx->old_pitch_buf_fx[st_fx->nb_subfr + 2], st_fx->old_fpitch, st_fx->nb_subfr ); +#ifdef BASOP_NOGLOB /*TBV st_fx->old_fpitch seems to have an odd value for this bitstream stv48n1_dtx_sw_164_1280_48kHz.f06.COD at frame 10 */ + st_fx->bfi_pitch_fx = shl_sat( round_fx( st_fx->old_fpitch ), 6 ); #else - st_fx->bfi_pitch_fx = shl(round_fx(st_fx->old_fpitch),6); + st_fx->bfi_pitch_fx = shl( round_fx( st_fx->old_fpitch ), 6 ); #endif st_fx->bfi_pitch_frame = st_fx->L_frame; move16(); - st_fx->mem_pitch_gain[2*st_fx->nb_subfr+1] = st_fx->mem_pitch_gain[st_fx->nb_subfr+1]; + st_fx->mem_pitch_gain[2 * st_fx->nb_subfr + 1] = st_fx->mem_pitch_gain[st_fx->nb_subfr + 1]; move16(); - st_fx->mem_pitch_gain[2*st_fx->nb_subfr] = st_fx->mem_pitch_gain[st_fx->nb_subfr]; + st_fx->mem_pitch_gain[2 * st_fx->nb_subfr] = st_fx->mem_pitch_gain[st_fx->nb_subfr]; move16(); - FOR (i = 0; i < st_fx->nb_subfr; i++) + FOR( i = 0; i < st_fx->nb_subfr; i++ ) { - st_fx->mem_pitch_gain[2*st_fx->nb_subfr-1 - i] = st_fx->mem_pitch_gain[st_fx->nb_subfr-1 - i]; + st_fx->mem_pitch_gain[2 * st_fx->nb_subfr - 1 - i] = st_fx->mem_pitch_gain[st_fx->nb_subfr - 1 - i]; move16(); - st_fx->mem_pitch_gain[st_fx->nb_subfr-1 - i] = hTcxDec->tcxltp_last_gain_unmodified; + st_fx->mem_pitch_gain[st_fx->nb_subfr - 1 - i] = hTcxDec->tcxltp_last_gain_unmodified; move16(); } } #ifdef IVAS_FLOAT_FIXED -void decoder_tcx_post_ivas_fx(Decoder_State *st_fx, - Word16 *synth, - Word16 *synthFB, - Word16 *A, - Word16 bfi, - Word16 MCT_flag - ) +void decoder_tcx_post_ivas_fx( Decoder_State *st_fx, + Word16 *synth, + Word16 *synthFB, + Word16 *A, + Word16 bfi, + Word16 MCT_flag ) { Word16 i; Word16 level_syn; Word16 level_syn_e; Word32 step; - Word16 gainCNG,gainCNG_e; + Word16 gainCNG, gainCNG_e; Word16 xn_buf[L_FRAME_MAX]; Word16 tmp1, tmp2, s; Word32 tmp32; @@ -1631,13 +1614,13 @@ void decoder_tcx_post_ivas_fx(Decoder_State *st_fx, /* first TCX frame after ACELP; overwrite ltp initialization done during acelp PLC */ test(); test(); - IF (!st_fx->bfi && st_fx->prev_bfi && EQ_16(st_fx->last_core,ACELP_CORE)) + IF( !st_fx->bfi && st_fx->prev_bfi && EQ_16( st_fx->last_core, ACELP_CORE ) ) { hTcxDec->tcxltp_last_gain_unmodified = 0; move16(); } - IF ( st_fx->hTcxLtpDec != NULL && st_fx->element_mode > EVS_MONO && ( st_fx->clas_dec == UNVOICED_CLAS || st_fx->clas_dec == INACTIVE_CLAS ) ) + IF( st_fx->hTcxLtpDec != NULL && st_fx->element_mode > EVS_MONO && ( st_fx->clas_dec == UNVOICED_CLAS || st_fx->clas_dec == INACTIVE_CLAS ) ) { /* deactivate TCX LTP for non-voiced frames */ st_fx->hTcxLtpDec->tcxltp = 0; @@ -1646,45 +1629,45 @@ void decoder_tcx_post_ivas_fx(Decoder_State *st_fx, move16(); } - IF (bfi != 0 && st_fx->use_partial_copy == 0) + IF( bfi != 0 && st_fx->use_partial_copy == 0 ) { test(); /* run lpc gain compensation not for waveform adjustment */ - IF ( 0 == st_fx->enablePlcWaveadjust || ( st_fx->hPlcInfo != NULL && EQ_16(st_fx->plcInfo.concealment_method,TCX_TONAL))) + IF( 0 == st_fx->enablePlcWaveadjust || ( st_fx->hPlcInfo != NULL && EQ_16( st_fx->plcInfo.concealment_method, TCX_TONAL ) ) ) { UWord32 dmy; - tmp32_1 /*gainHelperFB*/ = L_shl_r(L_deposit_h(hTcxDec->gainHelper) ,sub(hTcxDec->gainHelper_e, 31-28));/*Q28*/ - tmp32_2 /*stepCompensateFB*/= L_shl_r(L_deposit_h(hTcxDec->stepCompensate),sub(hTcxDec->stepCompensate_e,31-28));/*Q28*/ + tmp32_1 /*gainHelperFB*/ = L_shl_r( L_deposit_h( hTcxDec->gainHelper ), sub( hTcxDec->gainHelper_e, 31 - 28 ) ); /*Q28*/ + tmp32_2 /*stepCompensateFB*/ = L_shl_r( L_deposit_h( hTcxDec->stepCompensate ), sub( hTcxDec->stepCompensate_e, 31 - 28 ) ); /*Q28*/ - Mpy_32_32_ss(tmp32_2/*Q28*/, - L_shl(L_mult0(st_fx->L_frame, - getInvFrameLen(hTcxDec->L_frameTCX)/*Q21*/)/*Q21*/, - 8)/*Q29*/, - &tmp32_2, - &dmy ); /*Q26*/ + Mpy_32_32_ss( tmp32_2 /*Q28*/, + L_shl( L_mult0( st_fx->L_frame, + getInvFrameLen( hTcxDec->L_frameTCX ) /*Q21*/ ) /*Q21*/, + 8 ) /*Q29*/, + &tmp32_2, + &dmy ); /*Q26*/ - tmp32_2 = L_shl(tmp32_2,3-1); /*Q28*/ + tmp32_2 = L_shl( tmp32_2, 3 - 1 ); /*Q28*/ - FOR( i=0; i < hTcxDec->L_frameTCX; i++ ) + FOR( i = 0; i < hTcxDec->L_frameTCX; i++ ) { - tmp32 = L_shl(tmp32_1/*Q28*/,-(28-15)); /*16Q15*/ + tmp32 = L_shl( tmp32_1 /*Q28*/, -( 28 - 15 ) ); /*16Q15*/ #ifdef BASOP_NOGLOB - synthFB[i] = round_fx_sat(L_shl_sat(Mpy_32_16_1(tmp32,synthFB[i]), 16)); + synthFB[i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( tmp32, synthFB[i] ), 16 ) ); #else - synthFB[i] = round_fx(L_shl(Mpy_32_16_1(tmp32,synthFB[i]), 16)); + synthFB[i] = round_fx( L_shl( Mpy_32_16_1( tmp32, synthFB[i] ), 16 ) ); #endif move16(); - tmp32_1 = L_sub(tmp32_1 , tmp32_2); + tmp32_1 = L_sub( tmp32_1, tmp32_2 ); } } - tmp32_1 /*gainHelper*/ = L_shl_r(L_deposit_h(hTcxDec->gainHelper) ,sub(hTcxDec->gainHelper_e, 31-28));/*Q28*/ - tmp32_2 /*stepCompensate*/= L_shl_r(L_deposit_h(hTcxDec->stepCompensate),sub(hTcxDec->stepCompensate_e,31-28));/*Q28*/ - FOR( i=0; i < st_fx->L_frame; i++ ) + tmp32_1 /*gainHelper*/ = L_shl_r( L_deposit_h( hTcxDec->gainHelper ), sub( hTcxDec->gainHelper_e, 31 - 28 ) ); /*Q28*/ + tmp32_2 /*stepCompensate*/ = L_shl_r( L_deposit_h( hTcxDec->stepCompensate ), sub( hTcxDec->stepCompensate_e, 31 - 28 ) ); /*Q28*/ + FOR( i = 0; i < st_fx->L_frame; i++ ) { - tmp32 = L_shl(tmp32_1/*Q28*/,-(28-15)); /*16Q15*/ - xn_buf[i] = extract_l(Mpy_32_16_1(tmp32,xn_buf[i])); + tmp32 = L_shl( tmp32_1 /*Q28*/, -( 28 - 15 ) ); /*16Q15*/ + xn_buf[i] = extract_l( Mpy_32_16_1( tmp32, xn_buf[i] ) ); move16(); - tmp32_1 = L_sub(tmp32_1 , tmp32_2); + tmp32_1 = L_sub( tmp32_1, tmp32_2 ); } } @@ -1692,54 +1675,54 @@ void decoder_tcx_post_ivas_fx(Decoder_State *st_fx, * PLC: estimate and update CNG energy */ /* level_syn = (float)sqrt(( dot_product(synthFB, synthFB, L_frame)) / L_frame ); */ - s = sub(getScaleFactor16(synthFB, hTcxDec->L_frameTCX), 4); + s = sub( getScaleFactor16( synthFB, hTcxDec->L_frameTCX ), 4 ); { Word64 tmp64 = 0; move64(); - FOR (i = 0; i < hTcxDec->L_frameTCX; i++) + FOR( i = 0; i < hTcxDec->L_frameTCX; i++ ) { - tmp1 = shl(synthFB[i], s); - tmp64 = W_mac0_16_16(tmp64, tmp1, tmp1); + tmp1 = shl( synthFB[i], s ); + tmp64 = W_mac0_16_16( tmp64, tmp1, tmp1 ); } - tmp32 = W_sat_l(tmp64); + tmp32 = W_sat_l( tmp64 ); } - tmp32 = Mpy_32_16_1(tmp32, getInvFrameLen(hTcxDec->L_frameTCX)); - tmp2 = norm_l(tmp32); + tmp32 = Mpy_32_16_1( tmp32, getInvFrameLen( hTcxDec->L_frameTCX ) ); + tmp2 = norm_l( tmp32 ); #ifdef BASOP_NOGLOB - tmp1 = round_fx_o(L_shl(tmp32, tmp2), &Overflow); + tmp1 = round_fx_o( L_shl( tmp32, tmp2 ), &Overflow ); #else - tmp1 = round_fx(L_shl(tmp32, tmp2)); + tmp1 = round_fx( L_shl( tmp32, tmp2 ) ); #endif - //s = sub(sub(sub(1, shl(s, 1)), 6/*table lookup for inverse framelength*/), tmp2); - s = sub(25, add(shl(add(-2, s), 1), tmp2)); - tmp1 = Sqrt16(tmp1, &s); + // s = sub(sub(sub(1, shl(s, 1)), 6/*table lookup for inverse framelength*/), tmp2); + s = sub( 25, add( shl( add( -2, s ), 1 ), tmp2 ) ); + tmp1 = Sqrt16( tmp1, &s ); move16(); level_syn = tmp1; /*Q0*/ /* PLC: [TCX: Fade-out] * PLC: estimate and update CNG energy */ - level_syn_e = s;// add(s, 15); + level_syn_e = s; // add(s, 15); test(); test(); - IF (bfi == 0 && st_fx->tcxonly != 0 && ( NE_16(st_fx->element_mode, IVAS_CPE_MDCT) || MCT_flag ) && EQ_16(st_fx->clas_dec , UNVOICED_CLAS)) + IF( bfi == 0 && st_fx->tcxonly != 0 && ( NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) || MCT_flag ) && EQ_16( st_fx->clas_dec, UNVOICED_CLAS ) ) { Word16 Qnew_levelBackgroundTrace; Qnew_levelBackgroundTrace = 0; move16(); - minimumStatistics_fx(hTcxDec->conNoiseLevelMemory, /*Q15*/ - &hTcxDec->NoiseLevelIndex_bfi, /*Q0 */ - &hTcxDec->CurrLevelIndex_bfi, /*Q0 */ - &hTcxDec->conCngLevelBackgroundTrace, /*Q15*/ - &hTcxDec->conLastFrameLevel, /*Q15*/ - level_syn, /*Q15*/ - hTcxDec->conNoiseLevelMemory_e, - hTcxDec->conCngLevelBackgroundTrace_e, - &Qnew_levelBackgroundTrace, - &hTcxDec->conLastFrameLevel_e, - level_syn_e /*scaling of level_syn*/ - ); + minimumStatistics_fx( hTcxDec->conNoiseLevelMemory, /*Q15*/ + &hTcxDec->NoiseLevelIndex_bfi, /*Q0 */ + &hTcxDec->CurrLevelIndex_bfi, /*Q0 */ + &hTcxDec->conCngLevelBackgroundTrace, /*Q15*/ + &hTcxDec->conLastFrameLevel, /*Q15*/ + level_syn, /*Q15*/ + hTcxDec->conNoiseLevelMemory_e, + hTcxDec->conCngLevelBackgroundTrace_e, + &Qnew_levelBackgroundTrace, + &hTcxDec->conLastFrameLevel_e, + level_syn_e /*scaling of level_syn*/ + ); /*note: All parameters being different from Q0 have to have the same Q-format*/ @@ -1749,27 +1732,27 @@ void decoder_tcx_post_ivas_fx(Decoder_State *st_fx, /* PLC: [TCX: Fade-out] * PLC: fade-out in time domain */ - IF (bfi != 0) + IF( bfi != 0 ) { Word32 conceal_eof_gain32; Word32 conceal_eof_gainFB; move16(); move16(); gainCNG = 1; - gainCNG_e = 14+15+6; /*gainCNG is 2`097`152 - should be enough in case tracinglevel =~0 */ - IF (st_fx->tcxonly != 0) + gainCNG_e = 14 + 15 + 6; /*gainCNG is 2`097`152 - should be enough in case tracinglevel =~0 */ + IF( st_fx->tcxonly != 0 ) { /*gainCNG = st_fx->conCngLevelBackgroundTrace/(tracingLevel+0.01f);*/ - IF(level_syn != 0) + IF( level_syn != 0 ) { - BASOP_Util_Divide_MantExp ( + BASOP_Util_Divide_MantExp( hTcxDec->conCngLevelBackgroundTrace, hTcxDec->conCngLevelBackgroundTrace_e, level_syn, level_syn_e, &gainCNG, - &gainCNG_e); + &gainCNG_e ); } if ( st_fx->element_mode == IVAS_CPE_MDCT && !MCT_flag ) { @@ -1779,112 +1762,114 @@ void decoder_tcx_post_ivas_fx(Decoder_State *st_fx, } else if ( st_fx->nbLostCmpt > MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME ) { - Word16 tmp, q_tmp; - tmp = BASOP_Util_Divide1616_Scale(sub(st_fx->nbLostCmpt, MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME), MDCT_ST_PLC_FADEOUT_TO_ZERO_LEN, &q_tmp); - q_tmp = sub(15, q_tmp); - gainCNG = extract_l(L_shr(L_mult0(gainCNG, sub(shl(1, q_tmp), tmp)), q_tmp)); - //gainCNG *= 1.f - (float) sub( st_fx->nbLostCmpt, MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME ) / MDCT_ST_PLC_FADEOUT_TO_ZERO_LEN; + Word16 tmp, q_tmp; + tmp = BASOP_Util_Divide1616_Scale( sub( st_fx->nbLostCmpt, MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME ), MDCT_ST_PLC_FADEOUT_TO_ZERO_LEN, &q_tmp ); + q_tmp = sub( 15, q_tmp ); + gainCNG = extract_l( L_shr( L_mult0( gainCNG, sub( shl( 1, q_tmp ), tmp ) ), q_tmp ) ); + // gainCNG *= 1.f - (float) sub( st_fx->nbLostCmpt, MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME ) / MDCT_ST_PLC_FADEOUT_TO_ZERO_LEN; } } } ELSE { /*gainCNG = st_fx->cngTDLevel/(tracingLevel+0.01f);*/ - IF(level_syn != 0) + IF( level_syn != 0 ) { - BASOP_Util_Divide_MantExp ( + BASOP_Util_Divide_MantExp( st_fx->cngTDLevel, st_fx->cngTDLevel_e, level_syn, level_syn_e, &gainCNG, - &gainCNG_e); + &gainCNG_e ); } } - if ((EQ_16(st_fx->nbLostCmpt, 1))) + if ( ( EQ_16( st_fx->nbLostCmpt, 1 ) ) ) { - hTcxDec->conceal_eof_gain = 16384/*1.0f Q14*/; /*Q14*/ move16(); + hTcxDec->conceal_eof_gain = 16384 /*1.0f Q14*/; /*Q14*/ + move16(); } /* step = (st_fx->conceal_eof_gain - ( st_fx->conceal_eof_gain * st_fx->damping + gainCNG * (1 - st_fx->damping) )) / st_fx->L_frame; */ tmp2 = BASOP_Util_Add_MantExp( - mult_r(hTcxDec->conceal_eof_gain /*Q14*/, - hTcxDec->damping /*Q14*/), - 15-13/*->Q15*/, - mult_r(gainCNG/*Q15*/,sub(0x4000, hTcxDec->damping/*Q14*/)) /*Q14*/, - add(gainCNG_e,15-14)/*->Q15*/, - &tmp1); - tmp2 = BASOP_Util_Add_MantExp(hTcxDec->conceal_eof_gain, 15-14, negate(tmp1), tmp2, &tmp1); + mult_r( hTcxDec->conceal_eof_gain /*Q14*/, + hTcxDec->damping /*Q14*/ ), + 15 - 13 /*->Q15*/, + mult_r( gainCNG /*Q15*/, sub( 0x4000, hTcxDec->damping /*Q14*/ ) ) /*Q14*/, + add( gainCNG_e, 15 - 14 ) /*->Q15*/, + &tmp1 ); + tmp2 = BASOP_Util_Add_MantExp( hTcxDec->conceal_eof_gain, 15 - 14, negate( tmp1 ), tmp2, &tmp1 ); #ifdef BASOP_NOGLOB - step = L_shl_o(L_mult(tmp1, getInvFrameLen(st_fx->L_frame)), sub(tmp2, 6/*scaling from table lookup*/ + 1/*go to Q30*/), &Overflow); /*Q30*/ + step = L_shl_o( L_mult( tmp1, getInvFrameLen( st_fx->L_frame ) ), sub( tmp2, 6 /*scaling from table lookup*/ + 1 /*go to Q30*/ ), &Overflow ); /*Q30*/ #else - step = L_shl(L_mult(tmp1, getInvFrameLen(st_fx->L_frame)), sub(tmp2,6/*scaling from table lookup*/ +1/*go to Q30*/)); /*Q30*/ + step = L_shl( L_mult( tmp1, getInvFrameLen( st_fx->L_frame ) ), sub( tmp2, 6 /*scaling from table lookup*/ + 1 /*go to Q30*/ ) ); /*Q30*/ #endif { Word32 stepFB; UWord32 dmy; - conceal_eof_gainFB = L_deposit_h(hTcxDec->conceal_eof_gain); /*Q30*/ - Mpy_32_32_ss(step,L_shl(L_mult0(st_fx->L_frame, getInvFrameLen(hTcxDec->L_frameTCX)),8),&stepFB ,&dmy ); + conceal_eof_gainFB = L_deposit_h( hTcxDec->conceal_eof_gain ); /*Q30*/ + Mpy_32_32_ss( step, L_shl( L_mult0( st_fx->L_frame, getInvFrameLen( hTcxDec->L_frameTCX ) ), 8 ), &stepFB, &dmy ); #ifdef BASOP_NOGLOB - stepFB = L_shl_o(stepFB, 3 - 1, &Overflow); /*Q30*/ + stepFB = L_shl_o( stepFB, 3 - 1, &Overflow ); /*Q30*/ #else - stepFB = L_shl(stepFB,3-1); /*Q30*/ + stepFB = L_shl( stepFB, 3 - 1 ); /*Q30*/ #endif - FOR( i=0; i < hTcxDec->L_frameTCX; i++ ) + FOR( i = 0; i < hTcxDec->L_frameTCX; i++ ) { - synthFB[i] = round_fx(L_shl(Mpy_32_16_1(conceal_eof_gainFB, synthFB[i]),1)); + synthFB[i] = round_fx( L_shl( Mpy_32_16_1( conceal_eof_gainFB, synthFB[i] ), 1 ) ); move16(); #ifdef BASOP_NOGLOB - conceal_eof_gainFB = L_sub_o(conceal_eof_gainFB, stepFB, &Overflow); + conceal_eof_gainFB = L_sub_o( conceal_eof_gainFB, stepFB, &Overflow ); #else - conceal_eof_gainFB = L_sub(conceal_eof_gainFB, stepFB); + conceal_eof_gainFB = L_sub( conceal_eof_gainFB, stepFB ); #endif } } - conceal_eof_gain32 = L_deposit_h(hTcxDec->conceal_eof_gain); /*Q30*/ - FOR( i=0; i < st_fx->L_frame; i++ ) + conceal_eof_gain32 = L_deposit_h( hTcxDec->conceal_eof_gain ); /*Q30*/ + FOR( i = 0; i < st_fx->L_frame; i++ ) { - xn_buf[i] = round_fx(L_shl(Mpy_32_16_1(conceal_eof_gain32 /*Q30*/, xn_buf[i]),1)); + xn_buf[i] = round_fx( L_shl( Mpy_32_16_1( conceal_eof_gain32 /*Q30*/, xn_buf[i] ), 1 ) ); move16(); #ifdef BASOP_NOGLOB - conceal_eof_gain32 = L_sub_o(conceal_eof_gain32, step, &Overflow); + conceal_eof_gain32 = L_sub_o( conceal_eof_gain32, step, &Overflow ); #else - conceal_eof_gain32 = L_sub(conceal_eof_gain32,step); + conceal_eof_gain32 = L_sub( conceal_eof_gain32, step ); #endif } #ifdef BASOP_NOGLOB - hTcxDec->conceal_eof_gain = round_fx_o(conceal_eof_gain32, &Overflow); /*Q14*/ move16(); + hTcxDec->conceal_eof_gain = round_fx_o( conceal_eof_gain32, &Overflow ); /*Q14*/ + move16(); #else - hTcxDec->conceal_eof_gain = round_fx(conceal_eof_gain32); /*Q14*/ move16(); + hTcxDec->conceal_eof_gain = round_fx( conceal_eof_gain32 ); /*Q14*/ + move16(); #endif - /* run lpc gain compensation not for waveform adjustment */ test(); - IF ( 0 == st_fx->enablePlcWaveadjust || EQ_16(st_fx->plcInfo.concealment_method,TCX_TONAL)) + /* run lpc gain compensation not for waveform adjustment */ test(); + IF( 0 == st_fx->enablePlcWaveadjust || EQ_16( st_fx->plcInfo.concealment_method, TCX_TONAL ) ) { #ifdef BASOP_NOGLOB - st_fx->plcInfo.recovery_gain = extract_h(L_shl_o(Mpy_32_16_1(conceal_eof_gainFB, - st_fx->last_concealed_gain_syn_deemph), - st_fx->last_concealed_gain_syn_deemph_e, &Overflow - ));/*Q30->Q14*/ + st_fx->plcInfo.recovery_gain = extract_h( L_shl_o( Mpy_32_16_1( conceal_eof_gainFB, + st_fx->last_concealed_gain_syn_deemph ), + st_fx->last_concealed_gain_syn_deemph_e, &Overflow ) ); /*Q30->Q14*/ #else - st_fx->plcInfo.recovery_gain = extract_h(L_shl(Mpy_32_16_1(conceal_eof_gainFB, - st_fx->last_concealed_gain_syn_deemph), - st_fx->last_concealed_gain_syn_deemph_e - ));/*Q30->Q14*/ + st_fx->plcInfo.recovery_gain = extract_h( L_shl( Mpy_32_16_1( conceal_eof_gainFB, + st_fx->last_concealed_gain_syn_deemph ), + st_fx->last_concealed_gain_syn_deemph_e ) ); /*Q30->Q14*/ #endif } ELSE { - st_fx->plcInfo.recovery_gain = extract_h(conceal_eof_gainFB); /*Q14*/ + st_fx->plcInfo.recovery_gain = extract_h( conceal_eof_gainFB ); /*Q14*/ } st_fx->plcInfo.step_concealgain_fx = #ifdef BASOP_NOGLOB - round_fx_sat(L_shl_sat(L_mult0( round_fx_sat(step), round_fx_sat(L_shl_sat(L_mult0(st_fx->L_frame, getInvFrameLen(hTcxDec->L_frameTCX)), 8))), 3)); /*Q15*/ + round_fx_sat( L_shl_sat( L_mult0( round_fx_sat( step ), round_fx_sat( L_shl_sat( L_mult0( st_fx->L_frame, getInvFrameLen( hTcxDec->L_frameTCX ) ), 8 ) ) ), 3 ) ); /*Q15*/ #else - round_fx(L_shl(L_mult0( - round_fx(step), - round_fx(L_shl(L_mult0(st_fx->L_frame, getInvFrameLen(hTcxDec->L_frameTCX)),8))),3)); /*Q15*/ + round_fx( L_shl( L_mult0( + round_fx( step ), + round_fx( L_shl( L_mult0( st_fx->L_frame, getInvFrameLen( hTcxDec->L_frameTCX ) ), 8 ) ) ), + 3 ) ); /*Q15*/ #endif } @@ -1893,50 +1878,49 @@ void decoder_tcx_post_ivas_fx(Decoder_State *st_fx, *-----------------------------------------------------------*/ /* Update synth, exc and old_Aq */ - tcx_decoder_memory_update(xn_buf, /*Q0*/ - synth, /*Q0*/ - A, - st_fx, - 0 - ); + tcx_decoder_memory_update( xn_buf, /*Q0*/ + synth, /*Q0*/ + A, + st_fx, + 0 ); /* PLC: [TCX: Memory update] */ st_fx->old_pitch_buf_fx[0] = st_fx->old_pitch_buf_fx[st_fx->nb_subfr]; move32(); - st_fx->old_pitch_buf_fx[1] = st_fx->old_pitch_buf_fx[st_fx->nb_subfr+1]; + st_fx->old_pitch_buf_fx[1] = st_fx->old_pitch_buf_fx[st_fx->nb_subfr + 1]; move32(); - Copy32(&st_fx->old_pitch_buf_fx[st_fx->nb_subfr+2], &st_fx->old_pitch_buf_fx[2], st_fx->nb_subfr); - set32_fx(&st_fx->old_pitch_buf_fx[st_fx->nb_subfr+2], st_fx->old_fpitch, st_fx->nb_subfr); -#ifdef BASOP_NOGLOB /*TBV st_fx->old_fpitch seems to have an odd value for this bitstream stv48n1_dtx_sw_164_1280_48kHz.f06.COD at frame 10 */ - st_fx->bfi_pitch_fx = shl_sat(round_fx(st_fx->old_fpitch),6); + Copy32( &st_fx->old_pitch_buf_fx[st_fx->nb_subfr + 2], &st_fx->old_pitch_buf_fx[2], st_fx->nb_subfr ); + set32_fx( &st_fx->old_pitch_buf_fx[st_fx->nb_subfr + 2], st_fx->old_fpitch, st_fx->nb_subfr ); +#ifdef BASOP_NOGLOB /*TBV st_fx->old_fpitch seems to have an odd value for this bitstream stv48n1_dtx_sw_164_1280_48kHz.f06.COD at frame 10 */ + st_fx->bfi_pitch_fx = shl_sat( round_fx( st_fx->old_fpitch ), 6 ); #else - st_fx->bfi_pitch_fx = shl(round_fx(st_fx->old_fpitch),6); + st_fx->bfi_pitch_fx = shl( round_fx( st_fx->old_fpitch ), 6 ); #endif st_fx->bfi_pitch_frame = st_fx->L_frame; move16(); - st_fx->mem_pitch_gain[2*st_fx->nb_subfr+1] = st_fx->mem_pitch_gain[st_fx->nb_subfr+1]; + st_fx->mem_pitch_gain[2 * st_fx->nb_subfr + 1] = st_fx->mem_pitch_gain[st_fx->nb_subfr + 1]; move16(); - st_fx->mem_pitch_gain[2*st_fx->nb_subfr] = st_fx->mem_pitch_gain[st_fx->nb_subfr]; + st_fx->mem_pitch_gain[2 * st_fx->nb_subfr] = st_fx->mem_pitch_gain[st_fx->nb_subfr]; move16(); - FOR (i = 0; i < st_fx->nb_subfr; i++) + FOR( i = 0; i < st_fx->nb_subfr; i++ ) { - st_fx->mem_pitch_gain[2*st_fx->nb_subfr-1 - i] = st_fx->mem_pitch_gain[st_fx->nb_subfr-1 - i]; + st_fx->mem_pitch_gain[2 * st_fx->nb_subfr - 1 - i] = st_fx->mem_pitch_gain[st_fx->nb_subfr - 1 - i]; move16(); - st_fx->mem_pitch_gain[st_fx->nb_subfr-1 - i] = hTcxDec->tcxltp_last_gain_unmodified; + st_fx->mem_pitch_gain[st_fx->nb_subfr - 1 - i] = hTcxDec->tcxltp_last_gain_unmodified; move16(); } } #endif -static Word32 CalculateAbsEnergy_fx( /* o : normalized result Q31 */ - const Word32 L_off, /* i : initial sum value Qn */ - const Word16 x[], /* i : x vector Qn */ - const Word16 lg, /* i : vector length, range [0..7FFF] Q0 */ - Word16 * exp /* o : exponent of result in [-32,31] Q0 */ +static Word32 CalculateAbsEnergy_fx( /* o : normalized result Q31 */ + const Word32 L_off, /* i : initial sum value Qn */ + const Word16 x[], /* i : x vector Qn */ + const Word16 lg, /* i : vector length, range [0..7FFF] Q0 */ + Word16 *exp /* o : exponent of result in [-32,31] Q0 */ ) { Word16 i; @@ -1948,73 +1932,47 @@ static Word32 CalculateAbsEnergy_fx( /* o : normalized result Q31 * /* Clear carry flag and init sum */ Carry = 0; L_c = 0; - move32(); -#ifdef BASOP_NOGLOB /* Critical Overflow/Carry */ - L_sum = L_macNs_co(L_off,0,0, &Carry, &Overflow); - if (L_sum > 0) + move32(); +#ifdef BASOP_NOGLOB /* Critical Overflow/Carry */ + L_sum = L_macNs_co( L_off, 0, 0, &Carry, &Overflow ); + if ( L_sum > 0 ) { - L_c = L_macNs_co(L_c, 0, 0, &Carry, &Overflow); + L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); } - if (L_sum < 0) + if ( L_sum < 0 ) { - L_c = L_msuNs_co(L_c, 0, 0, &Carry, &Overflow); + L_c = L_msuNs_co( L_c, 0, 0, &Carry, &Overflow ); } #else - L_sum = L_macNs(L_off,0,0); - if (L_sum > 0) - L_c = L_macNs(L_c,0,0); - if (L_sum < 0) - L_c = L_msuNs(L_c,0,0); + L_sum = L_macNs( L_off, 0, 0 ); + if ( L_sum > 0 ) + L_c = L_macNs( L_c, 0, 0 ); + if ( L_sum < 0 ) + L_c = L_msuNs( L_c, 0, 0 ); #endif - FOR (i=0; i < lg; i+=2) + FOR( i = 0; i < lg; i += 2 ) { Carry = 0; BASOP_SATURATE_WARNING_OFF_EVS /*multiplication of -32768 * -32768 throws an overflow, but is not critical*/ -#ifdef BASOP_NOGLOB /* Critical Overflow/Carry */ - L_sum = L_macNs_co(L_sum, x[i], x[i], &Carry, &Overflow); +#ifdef BASOP_NOGLOB /* Critical Overflow/Carry */ + L_sum = L_macNs_co( L_sum, x[i], x[i], &Carry, &Overflow ); #else - L_sum = L_macNs(L_sum, x[i], x[i]); + L_sum = L_macNs( L_sum, x[i], x[i] ); #endif BASOP_SATURATE_WARNING_ON_EVS - Overflow = 0; /* to avoid useless warning in L_macNs calling L_mult */ -#ifdef BASOP_NOGLOB /* Critical Overflow/Carry */ - L_c = L_macNs_co(L_c,0,0, &Carry, &Overflow); + Overflow = 0; /* to avoid useless warning in L_macNs calling L_mult */ +#ifdef BASOP_NOGLOB /* Critical Overflow/Carry */ + L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); #else - L_c = L_macNs(L_c,0,0); + L_c = L_macNs( L_c, 0, 0 ); #endif } - L_sum = norm_llQ31(L_c,L_sum,exp); + L_sum = norm_llQ31( L_c, L_sum, exp ); return L_sum; } -void IMDCT_fx(Word32 *x, Word16 x_e, - Word16 *old_syn_overl, - Word16 *syn_Overl_TDAC, - Word16 *xn_buf, - const Word16 *tcx_aldo_window_1, - const PWord16 *tcx_aldo_window_1_trunc, - const PWord16 *tcx_aldo_window_2, - const PWord16 *tcx_mdct_window_half, - const PWord16 *tcx_mdct_window_minimum, - const PWord16 *tcx_mdct_window_trans, - Word16 tcx_mdct_window_half_length, - Word16 tcx_mdct_window_min_length, - Word16 index, - Word16 left_rect, - Word16 tcx_offset, - Word16 overlap, - Word16 L_frame, - Word16 L_frameTCX, - Word16 L_spec_TCX5, - Word16 L_frame_glob, - Word16 frame_cnt, - Word16 bfi, - Word16 *old_out, - Word16 *Q_old_wtda, - Decoder_State *st, - Word16 fullbandScale, - Word16 *acelp_zir) +void IMDCT_fx( Word32 *x, Word16 x_e, Word16 *old_syn_overl, Word16 *syn_Overl_TDAC, Word16 *xn_buf, const Word16 *tcx_aldo_window_1, const PWord16 *tcx_aldo_window_1_trunc, const PWord16 *tcx_aldo_window_2, const PWord16 *tcx_mdct_window_half, const PWord16 *tcx_mdct_window_minimum, const PWord16 *tcx_mdct_window_trans, Word16 tcx_mdct_window_half_length, Word16 tcx_mdct_window_min_length, Word16 index, Word16 left_rect, Word16 tcx_offset, Word16 overlap, Word16 L_frame, Word16 L_frameTCX, Word16 L_spec_TCX5, Word16 L_frame_glob, Word16 frame_cnt, Word16 bfi, Word16 *old_out, Word16 *Q_old_wtda, Decoder_State *st, Word16 fullbandScale, Word16 *acelp_zir ) { const TCX_CONFIG_HANDLE tcx_cfg = st->hTcxCfg; Word16 tmp_offset; @@ -2023,27 +1981,27 @@ void IMDCT_fx(Word32 *x, Word16 x_e, Word8 tmp8; Word16 i; Word16 nz; - Word16 aldo=0; + Word16 aldo = 0; TCX_DEC_HANDLE hTcxDec; hTcxDec = st->hTcxDec; /* number of zero for ALDO windows*/ - tmp32 = L_add(st->sr_core, 0); - if (fullbandScale != 0) + tmp32 = L_add( st->sr_core, 0 ); + if ( fullbandScale != 0 ) { - tmp32 = L_add(st->output_Fs, 0); + tmp32 = L_add( st->output_Fs, 0 ); } - nz = NS2SA_fx2(tmp32, N_ZERO_MDCT_NS); + nz = NS2SA_fx2( tmp32, N_ZERO_MDCT_NS ); tmp_offset = 0; move16(); - if (tcx_offset < 0) + if ( tcx_offset < 0 ) { - tmp_offset = negate(tcx_offset); + tmp_offset = negate( tcx_offset ); } test(); - IF ((EQ_16(L_frameTCX, shr(hTcxDec->L_frameTCX, 1)))&&(st->tcxonly!=0)) + IF( ( EQ_16( L_frameTCX, shr( hTcxDec->L_frameTCX, 1 ) ) ) && ( st->tcxonly != 0 ) ) { /* Mode decision in PLC @@ -2065,29 +2023,29 @@ void IMDCT_fx(Word32 *x, Word16 x_e, test(); test(); test(); - IF ((bfi == 0 && tcx_cfg->tcx_last_overlap_mode != FULL_OVERLAP) || (bfi!=0 && (tcx_cfg->tcx_last_overlap_mode != FULL_OVERLAP) && (tcx_cfg->tcx_curr_overlap_mode != FULL_OVERLAP))) + IF( ( bfi == 0 && tcx_cfg->tcx_last_overlap_mode != FULL_OVERLAP ) || ( bfi != 0 && ( tcx_cfg->tcx_last_overlap_mode != FULL_OVERLAP ) && ( tcx_cfg->tcx_curr_overlap_mode != FULL_OVERLAP ) ) ) { /* minimum or half overlap, two transforms, grouping into one window */ - Word16 win[(L_FRAME_PLUS+L_MDCT_OVLP_MAX)/2]; + Word16 win[( L_FRAME_PLUS + L_MDCT_OVLP_MAX ) / 2]; Word16 w; Word16 L_win, L_ola; - L_win = shr(L_frame, 1); + L_win = shr( L_frame, 1 ); L_ola = tcx_mdct_window_half_length; move16(); - if (EQ_16(tcx_cfg->tcx_last_overlap_mode, MIN_OVERLAP)) + if ( EQ_16( tcx_cfg->tcx_last_overlap_mode, MIN_OVERLAP ) ) { L_ola = tcx_mdct_window_min_length; move16(); } - set16_fx(xn_buf, 0, add(tcx_offset,shr(L_ola,1))); /* zero left end of buffer */ - set16_fx(win, 0, (L_FRAME_PLUS+L_MDCT_OVLP_MAX)/2); + set16_fx( xn_buf, 0, add( tcx_offset, shr( L_ola, 1 ) ) ); /* zero left end of buffer */ + set16_fx( win, 0, ( L_FRAME_PLUS + L_MDCT_OVLP_MAX ) / 2 ); - FOR (w = 0; w < 2 ; w++) + FOR( w = 0; w < 2; w++ ) { - TCX_MDCT_Inverse(x+L_mult0(w,L_spec_TCX5), sub(x_e,TCX_IMDCT_SCALE+TCX_IMDCT_HEADROOM),win, L_ola, sub(L_win,L_ola), L_ola, st->element_mode); + TCX_MDCT_Inverse( x + L_mult0( w, L_spec_TCX5 ), sub( x_e, TCX_IMDCT_SCALE + TCX_IMDCT_HEADROOM ), win, L_ola, sub( L_win, L_ola ), L_ola, st->element_mode ); tmp1 = left_rect; move16(); @@ -2095,9 +2053,9 @@ void IMDCT_fx(Word32 *x, Word16 x_e, move16(); tmp3 = st->last_core_bfi; move16(); - tmp8 = (Word8)st->last_is_cng; + tmp8 = (Word8) st->last_is_cng; move16(); - IF (w > 0) + IF( w > 0 ) { tmp1 = 0; move16(); @@ -2105,183 +2063,177 @@ void IMDCT_fx(Word32 *x, Word16 x_e, move16(); tmp3 = 1; move16(); - tmp8 = (Word8)0; + tmp8 = (Word8) 0; move16(); } test(); - if(w == 0 && EQ_16(index,2)) + if ( w == 0 && EQ_16( index, 2 ) ) { tmp2 = MIN_OVERLAP; move16(); } - IF (frame_cnt>0) + IF( frame_cnt > 0 ) { tmp3 = 1; move16(); - tmp8 = (Word8)0; + tmp8 = (Word8) 0; move16(); } - tcx_windowing_synthesis_current_frame(win, - tcx_aldo_window_2, - tcx_mdct_window_half, - tcx_mdct_window_minimum, - L_ola, - tcx_mdct_window_half_length, - tcx_mdct_window_min_length, - tmp1, - tmp2, - acelp_zir, - hTcxDec->old_syn_Overl, - syn_Overl_TDAC, - st->old_Aq_12_8_fx, - tcx_mdct_window_trans, - L_win, - tmp_offset, - tmp3, - tmp8, - fullbandScale - ); - - IF (w > 0) - { - tcx_windowing_synthesis_past_frame(xn_buf+tcx_offset-shr(L_ola , 1)+ imult1616(w,L_win), - tcx_aldo_window_1_trunc, + tcx_windowing_synthesis_current_frame( win, + tcx_aldo_window_2, tcx_mdct_window_half, tcx_mdct_window_minimum, L_ola, tcx_mdct_window_half_length, tcx_mdct_window_min_length, - MIN_OVERLAP - ); + tmp1, + tmp2, + acelp_zir, + hTcxDec->old_syn_Overl, + syn_Overl_TDAC, + st->old_Aq_12_8_fx, + tcx_mdct_window_trans, + L_win, + tmp_offset, + tmp3, + tmp8, + fullbandScale ); + + IF( w > 0 ) + { + tcx_windowing_synthesis_past_frame( xn_buf + tcx_offset - shr( L_ola, 1 ) + imult1616( w, L_win ), + tcx_aldo_window_1_trunc, + tcx_mdct_window_half, + tcx_mdct_window_minimum, + L_ola, + tcx_mdct_window_half_length, + tcx_mdct_window_min_length, + MIN_OVERLAP ); } /* add part of current sub-window overlapping with previous window */ - Vr_add(win, - xn_buf+tcx_offset-shr(L_ola,1)+w*L_win, /*instrumented only shr because in fact, its only L_win+L_win+L_win...*/ - xn_buf+tcx_offset-shr(L_ola,1)+w*L_win, - L_ola); + Vr_add( win, + xn_buf + tcx_offset - shr( L_ola, 1 ) + w * L_win, /*instrumented only shr because in fact, its only L_win+L_win+L_win...*/ + xn_buf + tcx_offset - shr( L_ola, 1 ) + w * L_win, + L_ola ); /* copy new sub-window region not overlapping with previous window */ Copy( - win+L_ola, - xn_buf+tcx_offset+shr(L_ola,1)+w*L_win, - L_win); + win + L_ola, + xn_buf + tcx_offset + shr( L_ola, 1 ) + w * L_win, + L_win ); } /* To assure that no garbage values are passed to overlap */ - set16_fx(xn_buf+L_frame+tcx_offset+shr(L_ola,1), 0, overlap-tcx_offset-shr(L_ola,1)); + set16_fx( xn_buf + L_frame + tcx_offset + shr( L_ola, 1 ), 0, overlap - tcx_offset - shr( L_ola, 1 ) ); } - ELSE IF ( bfi == 0 && (frame_cnt == 0) && (tcx_cfg->tcx_curr_overlap_mode == FULL_OVERLAP)) + ELSE IF( bfi == 0 && ( frame_cnt == 0 ) && ( tcx_cfg->tcx_curr_overlap_mode == FULL_OVERLAP ) ) { - Word16 win[(L_FRAME_PLUS+L_MDCT_OVLP_MAX)/2]; + Word16 win[( L_FRAME_PLUS + L_MDCT_OVLP_MAX ) / 2]; Word16 L_win, L_ola, w; /* special overlap attempt, two transforms, grouping into one window */ - L_win = shr(L_frame, 1); + L_win = shr( L_frame, 1 ); L_ola = tcx_mdct_window_min_length; move16(); - set16_fx(win, 0, (L_FRAME_PLUS+L_MDCT_OVLP_MAX)/2); + set16_fx( win, 0, ( L_FRAME_PLUS + L_MDCT_OVLP_MAX ) / 2 ); /* 1st TCX-5 window, special MDCT with minimum overlap on right side */ - TCX_MDCT_Inverse(x, sub(x_e, TCX_IMDCT_SCALE+TCX_IMDCT_HEADROOM), - win + L_win, - 0, sub(L_win, shr(L_ola, 1)), L_ola, st->element_mode); + TCX_MDCT_Inverse( x, sub( x_e, TCX_IMDCT_SCALE + TCX_IMDCT_HEADROOM ), + win + L_win, + 0, sub( L_win, shr( L_ola, 1 ) ), L_ola, st->element_mode ); - set16_fx(xn_buf, 0, shr(overlap,1)); + set16_fx( xn_buf, 0, shr( overlap, 1 ) ); /* copy new sub-window region not overlapping with previous window */ - Copy(win+L_win, xn_buf+shr(overlap,1), add(L_win,shr(L_ola,1)) ); + Copy( win + L_win, xn_buf + shr( overlap, 1 ), add( L_win, shr( L_ola, 1 ) ) ); /* 2nd TCX-5 window, regular MDCT with minimum overlap on both sides */ - TCX_MDCT_Inverse(x + L_spec_TCX5, sub(x_e, TCX_IMDCT_SCALE+TCX_IMDCT_HEADROOM), - win, - L_ola, sub(L_win, L_ola), L_ola, st->element_mode); - - tcx_windowing_synthesis_current_frame(win, - tcx_aldo_window_2, - tcx_mdct_window_half, - tcx_mdct_window_minimum, - L_ola, - tcx_mdct_window_half_length, - tcx_mdct_window_min_length, - 0, /* left_rect */ - MIN_OVERLAP, /* left_mode */ - acelp_zir, - hTcxDec->old_syn_Overl, - syn_Overl_TDAC, - st->old_Aq_12_8_fx, - tcx_mdct_window_trans, - L_win, - tmp_offset, - 1, /* st->last_core_bfi */ - 0, /* st->last_is_cng */ - fullbandScale - ); - - tmpP16 = xn_buf + add(sub(L_win, shr(L_ola, 1)), shr(overlap,1)); - - tcx_windowing_synthesis_past_frame(tmpP16, - tcx_aldo_window_1_trunc, - tcx_mdct_window_half, - tcx_mdct_window_minimum, - L_ola, - tcx_mdct_window_half_length, - tcx_mdct_window_min_length, - MIN_OVERLAP - ); + TCX_MDCT_Inverse( x + L_spec_TCX5, sub( x_e, TCX_IMDCT_SCALE + TCX_IMDCT_HEADROOM ), + win, + L_ola, sub( L_win, L_ola ), L_ola, st->element_mode ); + + tcx_windowing_synthesis_current_frame( win, + tcx_aldo_window_2, + tcx_mdct_window_half, + tcx_mdct_window_minimum, + L_ola, + tcx_mdct_window_half_length, + tcx_mdct_window_min_length, + 0, /* left_rect */ + MIN_OVERLAP, /* left_mode */ + acelp_zir, + hTcxDec->old_syn_Overl, + syn_Overl_TDAC, + st->old_Aq_12_8_fx, + tcx_mdct_window_trans, + L_win, + tmp_offset, + 1, /* st->last_core_bfi */ + 0, /* st->last_is_cng */ + fullbandScale ); + + tmpP16 = xn_buf + add( sub( L_win, shr( L_ola, 1 ) ), shr( overlap, 1 ) ); + + tcx_windowing_synthesis_past_frame( tmpP16, + tcx_aldo_window_1_trunc, + tcx_mdct_window_half, + tcx_mdct_window_minimum, + L_ola, + tcx_mdct_window_half_length, + tcx_mdct_window_min_length, + MIN_OVERLAP ); /* add part of current sub-window overlapping with previous window */ - FOR (i = 0; i < L_ola; i++) + FOR( i = 0; i < L_ola; i++ ) { - tmpP16[i] = add(tmpP16[i], win[i]); + tmpP16[i] = add( tmpP16[i], win[i] ); move16(); } /* copy new sub-window region not overlapping with previous window */ - Copy(win + L_ola, - xn_buf + add(add(shr(overlap,1), shr(L_ola, 1)), L_win), - L_win); + Copy( win + L_ola, + xn_buf + add( add( shr( overlap, 1 ), shr( L_ola, 1 ) ), L_win ), + L_win ); /* extra folding-out on left side of win, for perfect reconstruction */ - FOR (w = shr(overlap,1); w < overlap; w++) + FOR( w = shr( overlap, 1 ); w < overlap; w++ ) { - xn_buf[overlap-1-w] = negate(xn_buf[w]); + xn_buf[overlap - 1 - w] = negate( xn_buf[w] ); move16(); } - tcx_windowing_synthesis_current_frame(xn_buf, - tcx_aldo_window_2, - tcx_mdct_window_half, - tcx_mdct_window_minimum, - overlap, - tcx_mdct_window_half_length, - tcx_mdct_window_min_length, - left_rect, - 0, /* left_mode */ - acelp_zir, - hTcxDec->old_syn_Overl, - syn_Overl_TDAC, - st->old_Aq_12_8_fx, - tcx_mdct_window_trans, - shl(L_win,1), - tmp_offset, - st->last_core_bfi, - (Word8)st->last_is_cng, - fullbandScale - ); - - } - ELSE /* default i.e. maximum overlap, single transform, no grouping */ - { - - TCX_MDCT_Inverse(x, sub(x_e, TCX_IMDCT_SCALE+TCX_IMDCT_HEADROOM),xn_buf, overlap, sub(L_frame, overlap), overlap, st->element_mode); + tcx_windowing_synthesis_current_frame( xn_buf, + tcx_aldo_window_2, + tcx_mdct_window_half, + tcx_mdct_window_minimum, + overlap, + tcx_mdct_window_half_length, + tcx_mdct_window_min_length, + left_rect, + 0, /* left_mode */ + acelp_zir, + hTcxDec->old_syn_Overl, + syn_Overl_TDAC, + st->old_Aq_12_8_fx, + tcx_mdct_window_trans, + shl( L_win, 1 ), + tmp_offset, + st->last_core_bfi, + (Word8) st->last_is_cng, + fullbandScale ); + } + ELSE /* default i.e. maximum overlap, single transform, no grouping */ + { + + TCX_MDCT_Inverse( x, sub( x_e, TCX_IMDCT_SCALE + TCX_IMDCT_HEADROOM ), xn_buf, overlap, sub( L_frame, overlap ), overlap, st->element_mode ); tmp1 = index; move16(); test(); test(); test(); - if ( bfi==0 && (frame_cnt > 0) && (index == 0) && (st->last_core != ACELP_CORE)) + if ( bfi == 0 && ( frame_cnt > 0 ) && ( index == 0 ) && ( st->last_core != ACELP_CORE ) ) { tmp1 = MIN_OVERLAP; move16(); @@ -2289,101 +2241,100 @@ void IMDCT_fx(Word32 *x, Word16 x_e, tmp3 = st->last_core_bfi; move16(); - if (frame_cnt > 0) + if ( frame_cnt > 0 ) { tmp3 = 1; move16(); } - tmp8 = (Word8)st->last_is_cng; + tmp8 = (Word8) st->last_is_cng; move16(); - if (frame_cnt > 0) + if ( frame_cnt > 0 ) { tmp8 = 0; move16(); } - tcx_windowing_synthesis_current_frame(xn_buf, - tcx_aldo_window_2, - tcx_mdct_window_half, - tcx_mdct_window_minimum, - overlap, - tcx_mdct_window_half_length, - tcx_mdct_window_min_length, - left_rect, - tmp1, - acelp_zir, - hTcxDec->old_syn_Overl, - syn_Overl_TDAC, - st->old_Aq_12_8_fx, - tcx_mdct_window_trans, - shr(L_frame_glob, 1), - tmp_offset, - tmp3, - tmp8, - fullbandScale - ); - } - } - ELSE /* frame is TCX-20 or not TCX-only */ - { - assert(frame_cnt == 0); - - IF (NE_16(st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP)) + tcx_windowing_synthesis_current_frame( xn_buf, + tcx_aldo_window_2, + tcx_mdct_window_half, + tcx_mdct_window_minimum, + overlap, + tcx_mdct_window_half_length, + tcx_mdct_window_min_length, + left_rect, + tmp1, + acelp_zir, + hTcxDec->old_syn_Overl, + syn_Overl_TDAC, + st->old_Aq_12_8_fx, + tcx_mdct_window_trans, + shr( L_frame_glob, 1 ), + tmp_offset, + tmp3, + tmp8, + fullbandScale ); + } + } + ELSE /* frame is TCX-20 or not TCX-only */ + { + assert( frame_cnt == 0 ); + + IF( NE_16( st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) ) { Word32 tmp_buf[L_FRAME_PLUS]; Word16 Q; /* DCT */ - Q = sub(31, x_e); - edct_fx(x, tmp_buf, L_frame, &Q); + Q = sub( 31, x_e ); + edct_fx( x, tmp_buf, L_frame, &Q ); /* scale by sqrt(L / NORM_MDCT_FACTOR) */ - tmp1 = mult_r(shl(L_frame, 4), 26214/*128.f / NORM_MDCT_FACTOR Q15*/); /* 4Q11 */ + tmp1 = mult_r( shl( L_frame, 4 ), 26214 /*128.f / NORM_MDCT_FACTOR Q15*/ ); /* 4Q11 */ tmp2 = 4; move16(); - tmp1 = Sqrt16(tmp1, &tmp2); + tmp1 = Sqrt16( tmp1, &tmp2 ); - FOR (i = 0; i < L_frame; i++) + FOR( i = 0; i < L_frame; i++ ) { - tmp_buf[i] = Mpy_32_16_1(tmp_buf[i], tmp1); + tmp_buf[i] = Mpy_32_16_1( tmp_buf[i], tmp1 ); move32(); } - Q = sub(Q, tmp2); + Q = sub( Q, tmp2 ); - window_ola_fx(tmp_buf, - xn_buf, - &Q, - old_out, - Q_old_wtda, - L_frame, - tcx_cfg->tcx_last_overlap_mode, - tcx_cfg->tcx_curr_overlap_mode, - 0, - 0, - NULL); + window_ola_fx( tmp_buf, + xn_buf, + &Q, + old_out, + Q_old_wtda, + L_frame, + tcx_cfg->tcx_last_overlap_mode, + tcx_cfg->tcx_curr_overlap_mode, + 0, + 0, + NULL ); /* scale output */ - IF (Q <= 0) + IF( Q <= 0 ) { - FOR (i = 0; i < L_frame; i++) + FOR( i = 0; i < L_frame; i++ ) { #ifdef BASOP_NOGLOB - xn_buf[i] = shr_sat(xn_buf[i], Q); + xn_buf[i] = shr_sat( xn_buf[i], Q ); #else - xn_buf[i] = shr(xn_buf[i], Q); + xn_buf[i] = shr( xn_buf[i], Q ); #endif move16(); } } ELSE { - tmp1 = shr(0x4000, sub(Q,1)); + tmp1 = shr( 0x4000, sub( Q, 1 ) ); - FOR (i = 0; i < L_frame; i++) + FOR( i = 0; i < L_frame; i++ ) { - xn_buf[i] = mult_r(xn_buf[i], tmp1); + xn_buf[i] = mult_r( xn_buf[i], tmp1 ); move16(); } } @@ -2394,7 +2345,7 @@ void IMDCT_fx(Word32 *x, Word16 x_e, ELSE { - TCX_MDCT_Inverse(x, sub(x_e, TCX_IMDCT_SCALE+TCX_IMDCT_HEADROOM), xn_buf, overlap, sub(L_frame, overlap), overlap, st->element_mode); + TCX_MDCT_Inverse( x, sub( x_e, TCX_IMDCT_SCALE + TCX_IMDCT_HEADROOM ), xn_buf, overlap, sub( L_frame, overlap ), overlap, st->element_mode ); /*-----------------------------------------------------------* @@ -2406,102 +2357,102 @@ void IMDCT_fx(Word32 *x, Word16 x_e, tmp3 = st->last_core_bfi; move16(); - tmp8 = (Word8)st->last_is_cng; + tmp8 = (Word8) st->last_is_cng; move16(); - tcx_windowing_synthesis_current_frame( xn_buf, - tcx_aldo_window_2, - tcx_mdct_window_half, - tcx_mdct_window_minimum, - overlap, - tcx_mdct_window_half_length, - tcx_mdct_window_min_length, - left_rect, - tcx_cfg->tcx_last_overlap_mode, - acelp_zir, - hTcxDec->old_syn_Overl, - syn_Overl_TDAC, - st->old_Aq_12_8_fx, - tcx_mdct_window_trans, - shr(L_frame_glob, 1), - tmp_offset, - tmp3, - tmp8, - fullbandScale - ); + tcx_windowing_synthesis_current_frame( xn_buf, + tcx_aldo_window_2, + tcx_mdct_window_half, + tcx_mdct_window_minimum, + overlap, + tcx_mdct_window_half_length, + tcx_mdct_window_min_length, + left_rect, + tcx_cfg->tcx_last_overlap_mode, + acelp_zir, + hTcxDec->old_syn_Overl, + syn_Overl_TDAC, + st->old_Aq_12_8_fx, + tcx_mdct_window_trans, + shr( L_frame_glob, 1 ), + tmp_offset, + tmp3, + tmp8, + fullbandScale ); } /* TRANSITION_OVERLAP */ - } /* TCX-20 and TCX-only */ + } /* TCX-20 and TCX-only */ /* Window and overlap-add past frame if past frame is TCX */ test(); - IF ((frame_cnt != 0) || (st->last_core_bfi > ACELP_CORE)) + IF( ( frame_cnt != 0 ) || ( st->last_core_bfi > ACELP_CORE ) ) { test(); test(); - IF (((EQ_16(L_frameTCX, shr(hTcxDec->L_frameTCX, 1)))&&(st->tcxonly!=0))||(EQ_16(st->hTcxCfg->tcx_last_overlap_mode,TRANSITION_OVERLAP))) + IF( ( ( EQ_16( L_frameTCX, shr( hTcxDec->L_frameTCX, 1 ) ) ) && ( st->tcxonly != 0 ) ) || ( EQ_16( st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) ) ) { test(); test(); test(); test(); - if ((bfi == 0) && (frame_cnt > 0) && (index == 0) && - (tcx_cfg->tcx_curr_overlap_mode == FULL_OVERLAP) && (st->last_core != ACELP_CORE)) + if ( ( bfi == 0 ) && ( frame_cnt > 0 ) && ( index == 0 ) && + ( tcx_cfg->tcx_curr_overlap_mode == FULL_OVERLAP ) && ( st->last_core != ACELP_CORE ) ) { - index = MIN_OVERLAP; /* use minimum overlap between the two TCX-10 windows */ move16(); + index = MIN_OVERLAP; /* use minimum overlap between the two TCX-10 windows */ + move16(); } - IF (tcx_cfg->last_aldo != 0) + IF( tcx_cfg->last_aldo != 0 ) { Word16 tmp4; - tmp2 = add(*Q_old_wtda, TCX_IMDCT_HEADROOM); - tmp4 = sub(shr(overlap, 1), tcx_offset); + tmp2 = add( *Q_old_wtda, TCX_IMDCT_HEADROOM ); + tmp4 = sub( shr( overlap, 1 ), tcx_offset ); - FOR (i = 0; i < tmp4; i++) + FOR( i = 0; i < tmp4; i++ ) { - xn_buf[i] = shl(xn_buf[i], TCX_IMDCT_HEADROOM); + xn_buf[i] = shl( xn_buf[i], TCX_IMDCT_HEADROOM ); move16(); } - tmp1 = sub(overlap, tcx_mdct_window_min_length); - FOR (i=0; i < tmp1; i++) + tmp1 = sub( overlap, tcx_mdct_window_min_length ); + FOR( i = 0; i < tmp1; i++ ) { #ifdef BASOP_NOGLOB xn_buf[i + tmp4] = shl_sat( add_sat( xn_buf[i + tmp4], shr_sat( old_out[i + nz], tmp2 ) ), TCX_IMDCT_HEADROOM ); #else - xn_buf[i+tmp4] = shl(add(xn_buf[i+tmp4], shr(old_out[i+nz], tmp2)), TCX_IMDCT_HEADROOM); + xn_buf[i + tmp4] = shl( add( xn_buf[i + tmp4], shr( old_out[i + nz], tmp2 ) ), TCX_IMDCT_HEADROOM ); #endif move16(); } /* fade truncated ALDO window */ - tmp1 = sub(overlap, shr(tcx_mdct_window_min_length, 1)); - FOR ( ; i < tmp1; i++) + tmp1 = sub( overlap, shr( tcx_mdct_window_min_length, 1 ) ); + FOR( ; i < tmp1; i++ ) { - tmp3 = mult_r(shr(old_out[i+nz], tmp2), tcx_mdct_window_minimum[i-overlap+tcx_mdct_window_min_length].v.re); + tmp3 = mult_r( shr( old_out[i + nz], tmp2 ), tcx_mdct_window_minimum[i - overlap + tcx_mdct_window_min_length].v.re ); #ifdef BASOP_NOGLOB xn_buf[i + tmp4] = shl_sat( add_sat( xn_buf[i + tmp4], tmp3 ), TCX_IMDCT_HEADROOM ); #else - xn_buf[i+tmp4] = shl(add(xn_buf[i+tmp4], tmp3), TCX_IMDCT_HEADROOM); + xn_buf[i + tmp4] = shl( add( xn_buf[i + tmp4], tmp3 ), TCX_IMDCT_HEADROOM ); #endif move16(); } - FOR ( ; i < overlap; i++) + FOR( ; i < overlap; i++ ) { - tmp3 = mult_r(shr(old_out[i+nz], tmp2), tcx_mdct_window_minimum[overlap-1-i].v.im); + tmp3 = mult_r( shr( old_out[i + nz], tmp2 ), tcx_mdct_window_minimum[overlap - 1 - i].v.im ); #ifdef BASOP_NOGLOB xn_buf[i + tmp4] = shl_sat( add_sat( xn_buf[i + tmp4], tmp3 ), TCX_IMDCT_HEADROOM ); #else - xn_buf[i+tmp4] = shl(add(xn_buf[i+tmp4], tmp3), TCX_IMDCT_HEADROOM); + xn_buf[i + tmp4] = shl( add( xn_buf[i + tmp4], tmp3 ), TCX_IMDCT_HEADROOM ); #endif move16(); } - FOR (i = add(i, tmp4) ; i < L_frame; i++) + FOR( i = add( i, tmp4 ); i < L_frame; i++ ) { #ifdef BASOP_NOGLOB xn_buf[i] = shl_sat( xn_buf[i], TCX_IMDCT_HEADROOM ); #else - xn_buf[i] = shl(xn_buf[i], TCX_IMDCT_HEADROOM); + xn_buf[i] = shl( xn_buf[i], TCX_IMDCT_HEADROOM ); #endif move16(); } @@ -2511,74 +2462,72 @@ void IMDCT_fx(Word32 *x, Word16 x_e, tmp1 = index; move16(); test(); - if ((index == 0) || (EQ_16(tcx_cfg->tcx_last_overlap_mode, MIN_OVERLAP))) + if ( ( index == 0 ) || ( EQ_16( tcx_cfg->tcx_last_overlap_mode, MIN_OVERLAP ) ) ) { tmp1 = tcx_cfg->tcx_last_overlap_mode; move16(); } - tcx_windowing_synthesis_past_frame( old_syn_overl - , - tcx_aldo_window_1_trunc, - tcx_mdct_window_half, - tcx_mdct_window_minimum, - overlap, - tcx_mdct_window_half_length, - tcx_mdct_window_min_length, - tmp1 - ); + tcx_windowing_synthesis_past_frame( old_syn_overl, + tcx_aldo_window_1_trunc, + tcx_mdct_window_half, + tcx_mdct_window_minimum, + overlap, + tcx_mdct_window_half_length, + tcx_mdct_window_min_length, + tmp1 ); BASOP_SATURATE_WARNING_OFF_EVS; - IF ( bfi ) + IF( bfi ) { - tmp1 = sub(shr(overlap, 1), tcx_offset); - tmp3 = shr(tcx_mdct_window_half_length, 1); - FOR (i=0; i < tmp1; i++) + tmp1 = sub( shr( overlap, 1 ), tcx_offset ); + tmp3 = shr( tcx_mdct_window_half_length, 1 ); + FOR( i = 0; i < tmp1; i++ ) { #ifdef BASOP_NOGLOB xn_buf[i] = shl_sat( xn_buf[i], TCX_IMDCT_HEADROOM ); #else - xn_buf[i] = shl(xn_buf[i], TCX_IMDCT_HEADROOM); + xn_buf[i] = shl( xn_buf[i], TCX_IMDCT_HEADROOM ); #endif move16(); } - FOR (i = 0; i < tmp3; i++) + FOR( i = 0; i < tmp3; i++ ) { #ifdef BASOP_NOGLOB tmp2 = add_sat( xn_buf[i + tmp1], mult_r( old_syn_overl[i], tcx_mdct_window_half[i].v.re ) ); xn_buf[i + tmp1] = shl_sat( tmp2, TCX_IMDCT_HEADROOM ); #else - tmp2 = add(xn_buf[i+tmp1], mult_r(old_syn_overl[i], tcx_mdct_window_half[i].v.re)); - xn_buf[i+tmp1] = shl(tmp2, TCX_IMDCT_HEADROOM); + tmp2 = add( xn_buf[i + tmp1], mult_r( old_syn_overl[i], tcx_mdct_window_half[i].v.re ) ); + xn_buf[i + tmp1] = shl( tmp2, TCX_IMDCT_HEADROOM ); #endif move16(); } - FOR ( ; i < tcx_mdct_window_half_length; i++) + FOR( ; i < tcx_mdct_window_half_length; i++ ) { - tmp2 = add(xn_buf[i+tmp1], mult_r(old_syn_overl[i], tcx_mdct_window_half[tcx_mdct_window_half_length-1-i].v.im)); + tmp2 = add( xn_buf[i + tmp1], mult_r( old_syn_overl[i], tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.im ) ); #ifdef BASOP_NOGLOB xn_buf[i + tmp1] = shl_sat( tmp2, TCX_IMDCT_HEADROOM ); #else - xn_buf[i+tmp1] = shl(tmp2, TCX_IMDCT_HEADROOM); + xn_buf[i + tmp1] = shl( tmp2, TCX_IMDCT_HEADROOM ); #endif move16(); } - IF (LT_16(add(i, tmp1), L_frame)) + IF( LT_16( add( i, tmp1 ), L_frame ) ) { - FOR (i = add(i, tmp1); i < L_frame; i++) + FOR( i = add( i, tmp1 ); i < L_frame; i++ ) { #ifdef BASOP_NOGLOB xn_buf[i] = shl_sat( xn_buf[i], TCX_IMDCT_HEADROOM ); #else - xn_buf[i] = shl(xn_buf[i], TCX_IMDCT_HEADROOM); + xn_buf[i] = shl( xn_buf[i], TCX_IMDCT_HEADROOM ); #endif move16(); } } } - ELSE IF (left_rect == 0) + ELSE IF( left_rect == 0 ) { - FOR (i=0; iL_frameTCX >> 1 && st->tcxonly) || st->hTcxCfg->tcx_last_overlap_mode == TRANSITION_OVERLAP); + assert( aldo != 0 || ( L_frameTCX == hTcxDec->L_frameTCX >> 1 && st->tcxonly ) || st->hTcxCfg->tcx_last_overlap_mode == TRANSITION_OVERLAP ); } ELSE { - IF (aldo == 0) + IF( aldo == 0 ) { BASOP_SATURATE_WARNING_OFF_EVS; - FOR (i = 0; i < L_frame; i++) + FOR( i = 0; i < L_frame; i++ ) { #ifdef BASOP_NOGLOB - xn_buf[i] = shl_sat(xn_buf[i], TCX_IMDCT_HEADROOM); + xn_buf[i] = shl_sat( xn_buf[i], TCX_IMDCT_HEADROOM ); #else - xn_buf[i] = shl(xn_buf[i], TCX_IMDCT_HEADROOM); + xn_buf[i] = shl( xn_buf[i], TCX_IMDCT_HEADROOM ); #endif move16(); } @@ -2666,35 +2615,34 @@ void IMDCT_fx(Word32 *x, Word16 x_e, test(); test(); test(); - IF ( (aldo == 0) && - ((EQ_16(L_frameTCX, shr(hTcxDec->L_frameTCX, 1)) && frame_cnt > 0) || - NE_16(L_frameTCX, shr(hTcxDec->L_frameTCX, 1)) ) ) + IF( ( aldo == 0 ) && + ( ( EQ_16( L_frameTCX, shr( hTcxDec->L_frameTCX, 1 ) ) && frame_cnt > 0 ) || + NE_16( L_frameTCX, shr( hTcxDec->L_frameTCX, 1 ) ) ) ) { /*Compute windowed synthesis in case of switching to ALDO windows in next frame*/ - FOR (i = 0; i < nz; i++) + FOR( i = 0; i < nz; i++ ) { - old_out[i] = shr(xn_buf[L_frame-nz+i], TCX_IMDCT_HEADROOM); + old_out[i] = shr( xn_buf[L_frame - nz + i], TCX_IMDCT_HEADROOM ); move16(); } - Copy(xn_buf+L_frame, old_out+nz, overlap); - set16_fx(old_out+nz+overlap, 0, nz); + Copy( xn_buf + L_frame, old_out + nz, overlap ); + set16_fx( old_out + nz + overlap, 0, nz ); - tcx_windowing_synthesis_past_frame( old_out+nz, + tcx_windowing_synthesis_past_frame( old_out + nz, tcx_aldo_window_1_trunc, tcx_mdct_window_half, tcx_mdct_window_minimum, overlap, tcx_mdct_window_half_length, tcx_mdct_window_min_length, - tcx_cfg->tcx_curr_overlap_mode - ); + tcx_cfg->tcx_curr_overlap_mode ); /* If current overlap mode = FULL_OVERLAP -> ALDO_WINDOW */ - IF (EQ_16(tcx_cfg->tcx_curr_overlap_mode, FULL_OVERLAP)) + IF( EQ_16( tcx_cfg->tcx_curr_overlap_mode, FULL_OVERLAP ) ) { - FOR (i=0; ihTcxCfg->last_aldo = aldo; move16(); @@ -2714,60 +2662,59 @@ void IMDCT_fx(Word32 *x, Word16 x_e, test(); test(); test(); - IF (left_rect && (frame_cnt == 0) && (st->last_core_bfi == ACELP_CORE) - && st->prev_bfi) + IF( left_rect && ( frame_cnt == 0 ) && ( st->last_core_bfi == ACELP_CORE ) && st->prev_bfi ) { - IF (fullbandScale) + IF( fullbandScale ) { - tmp1 = sub(shr(overlap, 1), tcx_offset); - tmp3 = shr(tcx_mdct_window_half_length, 1); - FOR (i = 0; i < tmp3; i++) + tmp1 = sub( shr( overlap, 1 ), tcx_offset ); + tmp3 = shr( tcx_mdct_window_half_length, 1 ); + FOR( i = 0; i < tmp3; i++ ) { #ifdef BASOP_NOGLOB xn_buf[i + tmp1] = mult_r_sat( xn_buf[i + tmp1], tcx_mdct_window_half[i].v.im ); - xn_buf[i+tmp1] = add_sat( xn_buf[i+tmp1], mult_r_sat(hTcxDec->syn_OverlFB[i], mult_r_sat( tcx_mdct_window_half[i].v.re, tcx_mdct_window_half[i].v.re ) ) ); + xn_buf[i + tmp1] = add_sat( xn_buf[i + tmp1], mult_r_sat( hTcxDec->syn_OverlFB[i], mult_r_sat( tcx_mdct_window_half[i].v.re, tcx_mdct_window_half[i].v.re ) ) ); #else - xn_buf[i+tmp1] = mult_r( xn_buf[i+tmp1], tcx_mdct_window_half[i].v.im ); - xn_buf[i+tmp1] = add( xn_buf[i+tmp1], mult_r(hTcxDec->syn_OverlFB[i], mult_r( tcx_mdct_window_half[i].v.re, tcx_mdct_window_half[i].v.re ) ) ); + xn_buf[i + tmp1] = mult_r( xn_buf[i + tmp1], tcx_mdct_window_half[i].v.im ); + xn_buf[i + tmp1] = add( xn_buf[i + tmp1], mult_r( hTcxDec->syn_OverlFB[i], mult_r( tcx_mdct_window_half[i].v.re, tcx_mdct_window_half[i].v.re ) ) ); #endif move16(); } - FOR ( ; i < tcx_mdct_window_half_length; i++) + FOR( ; i < tcx_mdct_window_half_length; i++ ) { #ifdef BASOP_NOGLOB xn_buf[i + tmp1] = mult_r_sat( xn_buf[i + tmp1], tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.re ); - xn_buf[i+tmp1] = add_sat( xn_buf[i+tmp1], mult_r_sat(hTcxDec->syn_OverlFB[i], mult_r_sat( tcx_mdct_window_half[tcx_mdct_window_half_length-1-i].v.im, tcx_mdct_window_half[tcx_mdct_window_half_length-1-i].v.im ) ) ); + xn_buf[i + tmp1] = add_sat( xn_buf[i + tmp1], mult_r_sat( hTcxDec->syn_OverlFB[i], mult_r_sat( tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.im, tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.im ) ) ); #else - xn_buf[i+tmp1] = mult_r( xn_buf[i+tmp1], tcx_mdct_window_half[tcx_mdct_window_half_length-1-i].v.re ); - xn_buf[i+tmp1] = add( xn_buf[i+tmp1], mult_r(hTcxDec->syn_OverlFB[i], mult_r( tcx_mdct_window_half[tcx_mdct_window_half_length-1-i].v.im, tcx_mdct_window_half[tcx_mdct_window_half_length-1-i].v.im ) ) ); + xn_buf[i + tmp1] = mult_r( xn_buf[i + tmp1], tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.re ); + xn_buf[i + tmp1] = add( xn_buf[i + tmp1], mult_r( hTcxDec->syn_OverlFB[i], mult_r( tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.im, tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.im ) ) ); #endif move16(); } } ELSE { - tmp1 = sub(shr(overlap, 1), tcx_offset); - tmp3 = shr(tcx_mdct_window_half_length, 1); - FOR (i = 0; i < tmp3; i++) + tmp1 = sub( shr( overlap, 1 ), tcx_offset ); + tmp3 = shr( tcx_mdct_window_half_length, 1 ); + FOR( i = 0; i < tmp3; i++ ) { #ifdef BASOP_NOGLOB xn_buf[i + tmp1] = mult_r_sat( xn_buf[i + tmp1], tcx_mdct_window_half[i].v.im ); xn_buf[i + tmp1] = add_sat( xn_buf[i + tmp1], mult_r_sat( hTcxDec->syn_Overl[i], mult_r_sat( tcx_mdct_window_half[i].v.re, tcx_mdct_window_half[i].v.re ) ) ); #else - xn_buf[i+tmp1] = mult_r( xn_buf[i+tmp1], tcx_mdct_window_half[i].v.im ); - xn_buf[i+tmp1] = add( xn_buf[i+tmp1], mult_r(hTcxDec->syn_Overl[i], mult_r( tcx_mdct_window_half[i].v.re, tcx_mdct_window_half[i].v.re ) ) ); + xn_buf[i + tmp1] = mult_r( xn_buf[i + tmp1], tcx_mdct_window_half[i].v.im ); + xn_buf[i + tmp1] = add( xn_buf[i + tmp1], mult_r( hTcxDec->syn_Overl[i], mult_r( tcx_mdct_window_half[i].v.re, tcx_mdct_window_half[i].v.re ) ) ); #endif move16(); } - FOR ( ; i < tcx_mdct_window_half_length; i++) + FOR( ; i < tcx_mdct_window_half_length; i++ ) { #ifdef BASOP_NOGLOB xn_buf[i + tmp1] = mult_r_sat( xn_buf[i + tmp1], tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.re ); xn_buf[i + tmp1] = add_sat( xn_buf[i + tmp1], mult_r_sat( hTcxDec->syn_Overl[i], mult_r_sat( tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.im, tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.im ) ) ); #else - xn_buf[i+tmp1] = mult_r( xn_buf[i+tmp1], tcx_mdct_window_half[tcx_mdct_window_half_length-1-i].v.re ); - xn_buf[i+tmp1] = add( xn_buf[i+tmp1], mult_r(hTcxDec->syn_Overl[i], mult_r( tcx_mdct_window_half[tcx_mdct_window_half_length-1-i].v.im, tcx_mdct_window_half[tcx_mdct_window_half_length-1-i].v.im ) ) ); + xn_buf[i + tmp1] = mult_r( xn_buf[i + tmp1], tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.re ); + xn_buf[i + tmp1] = add( xn_buf[i + tmp1], mult_r( hTcxDec->syn_Overl[i], mult_r( tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.im, tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.im ) ) ); #endif move16(); } @@ -2777,19 +2724,19 @@ void IMDCT_fx(Word32 *x, Word16 x_e, #ifdef IVAS_FLOAT_FIXED void IMDCT_ivas_fx( - Word32 *x_fx, //Q(q_x) + Word32 *x_fx, // Q(q_x) Word16 q_x, - Word16 *old_syn_overl_fx, //Q(-2) - Word16 *syn_Overl_TDAC_fx, //Q(-2) - Word16 *xn_buf_fx, //Q(-2) - const Word16 *tcx_aldo_window_1_fx, //Q(15) - const PWord16 *tcx_aldo_window_1_trunc_fx, //Q(15) - const PWord16 *tcx_aldo_window_2_fx, //Q(15) - const PWord16 *tcx_mdct_window_half_fx, //Q(15) - const PWord16 *tcx_mdct_window_minimum_fx, //Q(15) - const PWord16 *tcx_mdct_window_trans_fx, //Q(15) - const Word16 tcx_mdct_window_half_length, //Q(15) - const Word16 tcx_mdct_window_min_length, //Q(15) + Word16 *old_syn_overl_fx, // Q(-2) + Word16 *syn_Overl_TDAC_fx, // Q(-2) + Word16 *xn_buf_fx, // Q(-2) + const Word16 *tcx_aldo_window_1_fx, // Q(15) + const PWord16 *tcx_aldo_window_1_trunc_fx, // Q(15) + const PWord16 *tcx_aldo_window_2_fx, // Q(15) + const PWord16 *tcx_mdct_window_half_fx, // Q(15) + const PWord16 *tcx_mdct_window_minimum_fx, // Q(15) + const PWord16 *tcx_mdct_window_trans_fx, // Q(15) + const Word16 tcx_mdct_window_half_length, // Q(15) + const Word16 tcx_mdct_window_min_length, // Q(15) Word16 index, const UWord16 kernel_type, /* i : TCX transform kernel type */ const Word16 left_rect, @@ -2801,33 +2748,34 @@ void IMDCT_ivas_fx( const Word16 L_frame_glob, const Word16 frame_cnt, const Word16 bfi, - Word16 *old_out_fx, //Q(-2) + Word16 *old_out_fx, // Q(-2) const Word16 FB_flag, Decoder_State *st, const Word16 fullbandScale, Word16 *acelp_zir_fx, - Word16 q_win) //Q(-2) + Word16 q_win ) // Q(-2) { int16_t i, nz, aldo, w, L_win, L_ola; - Word16 win_fx[(L_FRAME_PLUS + L_MDCT_OVLP_MAX) / 2]; + Word16 win_fx[( L_FRAME_PLUS + L_MDCT_OVLP_MAX ) / 2]; TCX_DEC_HANDLE hTcxDec = st->hTcxDec; TCX_CONFIG_HANDLE hTcxCfg = st->hTcxCfg; Word16 x_e_hdrm; - x_e_hdrm = add(q_win, sub(Q16, q_x)); + x_e_hdrm = add( q_win, sub( Q16, q_x ) ); aldo = 0; nz = NS2SA( st->output_Fs, N_ZERO_MDCT_NS ) * L_frame / L_frameTCX; - IF ( NE_16(st->element_mode, EVS_MONO) && EQ_16(frame_cnt, 0) && EQ_16(bfi, 0) && NE_16(st->prev_bfi, 0) && ( EQ_16(st->last_core_bfi, TCX_20_CORE) || EQ_16(st->last_core_bfi, TCX_10_CORE) ) && EQ_16(hTcxCfg->last_aldo, 0) ) + IF( NE_16( st->element_mode, EVS_MONO ) && EQ_16( frame_cnt, 0 ) && EQ_16( bfi, 0 ) && NE_16( st->prev_bfi, 0 ) && ( EQ_16( st->last_core_bfi, TCX_20_CORE ) || EQ_16( st->last_core_bfi, TCX_10_CORE ) ) && EQ_16( hTcxCfg->last_aldo, 0 ) ) { - Word16 fac = shl(mult_r(hTcxDec->conceal_eof_gain, st->last_concealed_gain_syn_deemph), 1); - FOR(Word16 ind = 0; ind < overlap; ind++) { - old_syn_overl_fx[ind] = mult_r(old_syn_overl_fx[ind], fac); + Word16 fac = shl( mult_r( hTcxDec->conceal_eof_gain, st->last_concealed_gain_syn_deemph ), 1 ); + FOR( Word16 ind = 0; ind < overlap; ind++ ) + { + old_syn_overl_fx[ind] = mult_r( old_syn_overl_fx[ind], fac ); } } - IF ( EQ_16( L_frameTCX, shr(hTcxDec->L_frameTCX, 1) ) && st->tcxonly ) + IF( EQ_16( L_frameTCX, shr( hTcxDec->L_frameTCX, 1 ) ) && st->tcxonly ) { /* Mode decision in PLC @@ -2844,7 +2792,7 @@ void IMDCT_ivas_fx( 3 3 2x TCX-5 2x TCX-5 */ - IF( ( EQ_16(bfi, 0) && NE_16(hTcxCfg->tcx_last_overlap_mode, FULL_OVERLAP) ) || ( NE_16(bfi, 0) && NE_16( hTcxCfg->tcx_last_overlap_mode, FULL_OVERLAP ) && NE_16( hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) ) ) + IF( ( EQ_16( bfi, 0 ) && NE_16( hTcxCfg->tcx_last_overlap_mode, FULL_OVERLAP ) ) || ( NE_16( bfi, 0 ) && NE_16( hTcxCfg->tcx_last_overlap_mode, FULL_OVERLAP ) && NE_16( hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) ) ) { /* minimum or half overlap, two transforms, grouping into one window */ L_win = shr( L_frame, 1 ); @@ -2856,11 +2804,11 @@ void IMDCT_ivas_fx( FOR( w = 0; w < 2; w++ ) { - IF( EQ_16(kernel_type, MDST_IV) || s_and( kernel_type, w ) ) + IF( EQ_16( kernel_type, MDST_IV ) || s_and( kernel_type, w ) ) { TCX_MDST_Inverse_fx( x_fx + w * L_spec_TCX5, x_e_hdrm, win_fx, L_ola, L_win - L_ola, L_ola ); } - ELSE IF( NE_16(kernel_type, 0) && EQ_16(w, 0) ) /* type 1 or 2 */ + ELSE IF( NE_16( kernel_type, 0 ) && EQ_16( w, 0 ) ) /* type 1 or 2 */ { TCX_MDXT_Inverse_fx( x_fx + w * L_spec_TCX5, x_e_hdrm, win_fx, L_ola, L_win - L_ola, L_ola, kernel_type ); } @@ -2871,129 +2819,129 @@ void IMDCT_ivas_fx( tcx_windowing_synthesis_current_frame( win_fx, tcx_aldo_window_2_fx, tcx_mdct_window_half_fx, tcx_mdct_window_minimum_fx, L_ola, tcx_mdct_window_half_length, tcx_mdct_window_min_length, ( w > 0 ) ? 0 : left_rect, ( w > 0 ) || ( w == 0 && index == 2 ) ? MIN_OVERLAP : hTcxCfg->tcx_last_overlap_mode, acelp_zir_fx, hTcxDec->old_syn_Overl, syn_Overl_TDAC_fx, st->old_Aq_12_8_fx, tcx_mdct_window_trans_fx, L_win, tcx_offset < 0 ? -tcx_offset : 0, ( w > 0 ) || ( frame_cnt > 0 ) ? 1 : st->last_core, ( w > 0 ) || ( frame_cnt > 0 ) ? 0 : (Word8) st->last_is_cng, fullbandScale ); - IF( GT_16(w, 0) ) + IF( GT_16( w, 0 ) ) { tcx_windowing_synthesis_past_frame( xn_buf_fx + tcx_offset - shr( L_ola, 1 ) + w * L_win, tcx_aldo_window_1_trunc_fx, tcx_mdct_window_half_fx, tcx_mdct_window_minimum_fx, L_ola, tcx_mdct_window_half_length, tcx_mdct_window_min_length, MIN_OVERLAP ); } /* add part of current sub-window overlapping with previous window */ - v_add_16( win_fx, xn_buf_fx + add(sub(tcx_offset, shr( L_ola, 1 )), i_mult(w, L_win)), xn_buf_fx + add(sub(tcx_offset, shr( L_ola, 1 )), i_mult(w, L_win)), L_ola ); + v_add_16( win_fx, xn_buf_fx + add( sub( tcx_offset, shr( L_ola, 1 ) ), i_mult( w, L_win ) ), xn_buf_fx + add( sub( tcx_offset, shr( L_ola, 1 ) ), i_mult( w, L_win ) ), L_ola ); /* copy new sub-window region not overlapping with previous window */ - mvs2s( win_fx + L_ola, xn_buf_fx + add(tcx_offset, add(shr( L_ola, 1 ), i_mult(w, L_win))), L_win ); + mvs2s( win_fx + L_ola, xn_buf_fx + add( tcx_offset, add( shr( L_ola, 1 ), i_mult( w, L_win ) ) ), L_win ); } /* To assure that no garbage values are passed to overlap */ - set16_fx( xn_buf_fx + add(L_frame, add(tcx_offset, shr( L_ola, 1 ))), 0, sub(overlap, add(tcx_offset, shr( L_ola, 1 ))) ); + set16_fx( xn_buf_fx + add( L_frame, add( tcx_offset, shr( L_ola, 1 ) ) ), 0, sub( overlap, add( tcx_offset, shr( L_ola, 1 ) ) ) ); - IF( NE_16(st->prev_bfi, 0) && EQ_16(frame_cnt, 0) && NE_16(st->last_core, st->last_core_bfi) && EQ_16(st->last_core_bfi, ACELP_CORE) ) + IF( NE_16( st->prev_bfi, 0 ) && EQ_16( frame_cnt, 0 ) && NE_16( st->last_core, st->last_core_bfi ) && EQ_16( st->last_core_bfi, ACELP_CORE ) ) { tcx_windowing_synthesis_past_frame( old_syn_overl_fx, tcx_aldo_window_1_trunc_fx, tcx_mdct_window_half_fx, tcx_mdct_window_minimum_fx, overlap, tcx_mdct_window_half_length, tcx_mdct_window_min_length, hTcxCfg->tcx_last_overlap_mode ); v_add_16( xn_buf_fx, old_syn_overl_fx, xn_buf_fx, overlap ); } } - ELSE IF ( EQ_16(bfi, 0) && EQ_16( frame_cnt, 0 ) && EQ_16( hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) ) + ELSE IF( EQ_16( bfi, 0 ) && EQ_16( frame_cnt, 0 ) && EQ_16( hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) ) { /* special overlap attempt, two transforms, grouping into one window */ - L_win = shr(L_frame, 1); + L_win = shr( L_frame, 1 ); L_ola = tcx_mdct_window_min_length; move16(); - set16_fx( win_fx, 0, shr(add( L_FRAME_PLUS, L_MDCT_OVLP_MAX ), 1) ); + set16_fx( win_fx, 0, shr( add( L_FRAME_PLUS, L_MDCT_OVLP_MAX ), 1 ) ); /* 1st TCX-5 window, special MDCT with minimum overlap on right side */ - IF ( EQ_16(kernel_type, MDST_IV) ) + IF( EQ_16( kernel_type, MDST_IV ) ) { - TCX_MDST_Inverse_fx( x_fx, x_e_hdrm, win_fx + L_win, 0, sub(L_win, shr( L_ola, 1 )), L_ola ); + TCX_MDST_Inverse_fx( x_fx, x_e_hdrm, win_fx + L_win, 0, sub( L_win, shr( L_ola, 1 ) ), L_ola ); } - ELSE IF ( NE_16(kernel_type, MDCT_IV) ) /* type 1 or 2 */ + ELSE IF( NE_16( kernel_type, MDCT_IV ) ) /* type 1 or 2 */ { - TCX_MDXT_Inverse_fx( x_fx, x_e_hdrm, win_fx + L_win, 0, sub(L_win, shr( L_ola, 1 )), L_ola, kernel_type ); + TCX_MDXT_Inverse_fx( x_fx, x_e_hdrm, win_fx + L_win, 0, sub( L_win, shr( L_ola, 1 ) ), L_ola, kernel_type ); } ELSE { - TCX_MDCT_Inverse( x_fx, x_e_hdrm, win_fx + L_win, 0, sub(L_win, shr( L_ola, 1 )), L_ola, st->element_mode ); + TCX_MDCT_Inverse( x_fx, x_e_hdrm, win_fx + L_win, 0, sub( L_win, shr( L_ola, 1 ) ), L_ola, st->element_mode ); } set16_fx( xn_buf_fx, 0, shr( overlap, 1 ) ); /* copy new sub-window region not overlapping with previous window */ - mvs2s( win_fx + L_win, xn_buf_fx + shr( overlap, 1 ), add(L_win, shr( L_ola, 1 )) ); + mvs2s( win_fx + L_win, xn_buf_fx + shr( overlap, 1 ), add( L_win, shr( L_ola, 1 ) ) ); /* 2nd TCX-5 window, regular MDCT with minimum overlap on both sides */ - IF ( s_and(kernel_type, 1) ) + IF( s_and( kernel_type, 1 ) ) { - TCX_MDST_Inverse_fx( x_fx + L_spec_TCX5, x_e_hdrm, win_fx, L_ola, sub(L_win, L_ola), L_ola ); + TCX_MDST_Inverse_fx( x_fx + L_spec_TCX5, x_e_hdrm, win_fx, L_ola, sub( L_win, L_ola ), L_ola ); } ELSE { - TCX_MDCT_Inverse( x_fx + L_spec_TCX5, x_e_hdrm, win_fx, L_ola, sub(L_win, L_ola), L_ola, st->element_mode ); + TCX_MDCT_Inverse( x_fx + L_spec_TCX5, x_e_hdrm, win_fx, L_ola, sub( L_win, L_ola ), L_ola, st->element_mode ); } tcx_windowing_synthesis_current_frame( win_fx, tcx_aldo_window_2_fx, tcx_mdct_window_half_fx, tcx_mdct_window_minimum_fx, L_ola, tcx_mdct_window_half_length, tcx_mdct_window_min_length, 0, - /* left_rect */ MIN_OVERLAP, /* left_mode */ acelp_zir_fx, hTcxDec->old_syn_Overl, syn_Overl_TDAC_fx, st->old_Aq_12_8_fx, tcx_mdct_window_trans_fx, L_win, LT_16(tcx_offset, 0) ? -tcx_offset : 0, 1, /* st->last_mode_bfi */ 0, /* st->last_is_cng */ fullbandScale ); + /* left_rect */ MIN_OVERLAP, /* left_mode */ acelp_zir_fx, hTcxDec->old_syn_Overl, syn_Overl_TDAC_fx, st->old_Aq_12_8_fx, tcx_mdct_window_trans_fx, L_win, LT_16( tcx_offset, 0 ) ? -tcx_offset : 0, 1, /* st->last_mode_bfi */ 0, /* st->last_is_cng */ fullbandScale ); - tcx_windowing_synthesis_past_frame( xn_buf_fx + shr( overlap, 1 ) + sub(L_win, shr( L_ola, 1 )), tcx_aldo_window_1_trunc_fx, tcx_mdct_window_half_fx, tcx_mdct_window_minimum_fx, L_ola, tcx_mdct_window_half_length, tcx_mdct_window_min_length, 2 ); + tcx_windowing_synthesis_past_frame( xn_buf_fx + shr( overlap, 1 ) + sub( L_win, shr( L_ola, 1 ) ), tcx_aldo_window_1_trunc_fx, tcx_mdct_window_half_fx, tcx_mdct_window_minimum_fx, L_ola, tcx_mdct_window_half_length, tcx_mdct_window_min_length, 2 ); /* add part of current sub-window overlapping with previous window */ - v_add_16( win_fx, xn_buf_fx + add(shr( overlap, 1 ), sub(L_win, shr( L_ola, 1 ))), xn_buf_fx + sub(add(shr( overlap, 1 ), L_win), shr( L_ola, 1 )), L_ola ); + v_add_16( win_fx, xn_buf_fx + add( shr( overlap, 1 ), sub( L_win, shr( L_ola, 1 ) ) ), xn_buf_fx + sub( add( shr( overlap, 1 ), L_win ), shr( L_ola, 1 ) ), L_ola ); /* copy new sub-window region not overlapping with previous window */ - mvs2s( win_fx + L_ola, xn_buf_fx + add(add(shr( overlap, 1 ), L_win), shr( L_ola, 1 )), L_win ); + mvs2s( win_fx + L_ola, xn_buf_fx + add( add( shr( overlap, 1 ), L_win ), shr( L_ola, 1 ) ), L_win ); /* extra folding-out on left side of win, for perfect reconstruction */ - IF ( GE_16(kernel_type, MDCT_II) ) + IF( GE_16( kernel_type, MDCT_II ) ) { - FOR ( w = shr( overlap, 1 ); w < overlap; w++ ) + FOR( w = shr( overlap, 1 ); w < overlap; w++ ) { - xn_buf_fx[sub(sub(overlap, 1), w)] = xn_buf_fx[w]; + xn_buf_fx[sub( sub( overlap, 1 ), w )] = xn_buf_fx[w]; move16(); } } ELSE { - FOR ( w = shr( overlap, 1 ); w < overlap; w++ ) + FOR( w = shr( overlap, 1 ); w < overlap; w++ ) { - xn_buf_fx[sub(sub(overlap, 1), w)] = negate(xn_buf_fx[w]); + xn_buf_fx[sub( sub( overlap, 1 ), w )] = negate( xn_buf_fx[w] ); move16(); } } - tcx_windowing_synthesis_current_frame( xn_buf_fx, tcx_aldo_window_2_fx, tcx_mdct_window_half_fx, tcx_mdct_window_minimum_fx, overlap, tcx_mdct_window_half_length, tcx_mdct_window_min_length, left_rect, 0, /* left_mode */ acelp_zir_fx, hTcxDec->old_syn_Overl, syn_Overl_TDAC_fx, st->old_Aq_12_8_fx, tcx_mdct_window_trans_fx, shl(L_win, 1), LT_16(tcx_offset, 0) ? -tcx_offset : 0, st->last_core_bfi, (Word8)st->last_is_cng, fullbandScale ); + tcx_windowing_synthesis_current_frame( xn_buf_fx, tcx_aldo_window_2_fx, tcx_mdct_window_half_fx, tcx_mdct_window_minimum_fx, overlap, tcx_mdct_window_half_length, tcx_mdct_window_min_length, left_rect, 0, /* left_mode */ acelp_zir_fx, hTcxDec->old_syn_Overl, syn_Overl_TDAC_fx, st->old_Aq_12_8_fx, tcx_mdct_window_trans_fx, shl( L_win, 1 ), LT_16( tcx_offset, 0 ) ? -tcx_offset : 0, st->last_core_bfi, (Word8) st->last_is_cng, fullbandScale ); } ELSE { /* default, i.e. maximum overlap, single transform, no grouping */ - IF ( EQ_16(kernel_type, MDST_IV) ) + IF( EQ_16( kernel_type, MDST_IV ) ) { - TCX_MDST_Inverse_fx( x_fx, x_e_hdrm, xn_buf_fx, overlap, sub(L_frame, overlap), overlap ); + TCX_MDST_Inverse_fx( x_fx, x_e_hdrm, xn_buf_fx, overlap, sub( L_frame, overlap ), overlap ); } - ELSE IF ( NE_16(kernel_type, MDCT_IV) ) /* type 1 or 2 */ + ELSE IF( NE_16( kernel_type, MDCT_IV ) ) /* type 1 or 2 */ { - TCX_MDXT_Inverse_fx( x_fx, x_e_hdrm, xn_buf_fx, overlap, sub(L_frame, overlap), overlap, kernel_type ); + TCX_MDXT_Inverse_fx( x_fx, x_e_hdrm, xn_buf_fx, overlap, sub( L_frame, overlap ), overlap, kernel_type ); } ELSE { - TCX_MDCT_Inverse( x_fx, x_e_hdrm, xn_buf_fx, overlap, sub(L_frame, overlap), overlap, st->element_mode ); + TCX_MDCT_Inverse( x_fx, x_e_hdrm, xn_buf_fx, overlap, sub( L_frame, overlap ), overlap, st->element_mode ); } - tcx_windowing_synthesis_current_frame( xn_buf_fx, tcx_aldo_window_2_fx, tcx_mdct_window_half_fx, tcx_mdct_window_minimum_fx, overlap, tcx_mdct_window_half_length, tcx_mdct_window_min_length, left_rect, !bfi && GT_16( frame_cnt, 0 ) && EQ_16( index, 0 ) && NE_16( st->last_core, ACELP_CORE ) ? MIN_OVERLAP : index, acelp_zir_fx, hTcxDec->old_syn_Overl, syn_Overl_TDAC_fx, st->old_Aq_12_8_fx, tcx_mdct_window_trans_fx, shr(L_frame_glob, 1), LT_16(tcx_offset, 0) ? -tcx_offset : 0, GT_16( frame_cnt, 0 /*|| (st->last_con_tcx )*/ ) ? 1 : st->last_core_bfi, GT_16( frame_cnt, 0 ) ? 0 : (Word8)st->last_is_cng, fullbandScale ); + tcx_windowing_synthesis_current_frame( xn_buf_fx, tcx_aldo_window_2_fx, tcx_mdct_window_half_fx, tcx_mdct_window_minimum_fx, overlap, tcx_mdct_window_half_length, tcx_mdct_window_min_length, left_rect, !bfi && GT_16( frame_cnt, 0 ) && EQ_16( index, 0 ) && NE_16( st->last_core, ACELP_CORE ) ? MIN_OVERLAP : index, acelp_zir_fx, hTcxDec->old_syn_Overl, syn_Overl_TDAC_fx, st->old_Aq_12_8_fx, tcx_mdct_window_trans_fx, shr( L_frame_glob, 1 ), LT_16( tcx_offset, 0 ) ? -tcx_offset : 0, GT_16( frame_cnt, 0 /*|| (st->last_con_tcx )*/ ) ? 1 : st->last_core_bfi, GT_16( frame_cnt, 0 ) ? 0 : (Word8) st->last_is_cng, fullbandScale ); } /* tcx_last_overlap_mode != FULL_OVERLAP */ } ELSE { /* frame is TCX-20 or not TCX-only */ - assert( EQ_16(frame_cnt, 0) ); - IF ( NE_16(hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP) ) + assert( EQ_16( frame_cnt, 0 ) ); + IF( NE_16( hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) ) { - + Word16 q_tmp_fx_32 = 15, q_xn_buf_fx_32 = q_x; Word32 xn_buf_fx_32[2000] = { 0 }, tmp_fx_32[1200], old_out_fx_32[1200]; - IF ( NE_16(kernel_type, MDCT_IV) ) /* inverse transform */ + IF( NE_16( kernel_type, MDCT_IV ) ) /* inverse transform */ { - IF ( EQ_16(kernel_type, MDST_IV) ) + IF( EQ_16( kernel_type, MDST_IV ) ) { edst_fx( x_fx, xn_buf_fx_32 + overlap / 2 + nz, L_frame, &q_xn_buf_fx_32 ); } @@ -3003,26 +2951,27 @@ void IMDCT_ivas_fx( } Word16 res_m, res_e = 0; - res_m = BASOP_Util_Divide1616_Scale(L_frame, NORM_MDCT_FACTOR, &res_e); - res_m = Sqrt16(res_m, &res_e); + res_m = BASOP_Util_Divide1616_Scale( L_frame, NORM_MDCT_FACTOR, &res_e ); + res_m = Sqrt16( res_m, &res_e ); - FOR(Word16 ind = 0; ind < L_frame; ind++) { - tmp_fx_32[ind] = L_shl(Mpy_32_16_1(xn_buf_fx_32[shr(overlap, 1) + nz + ind], res_m), res_e); + FOR( Word16 ind = 0; ind < L_frame; ind++ ) + { + tmp_fx_32[ind] = L_shl( Mpy_32_16_1( xn_buf_fx_32[shr( overlap, 1 ) + nz + ind], res_m ), res_e ); } q_tmp_fx_32 = q_xn_buf_fx_32; move16(); - FOR ( Word16 ind = 0; ind < L_frame; ind++ ) + FOR( Word16 ind = 0; ind < L_frame; ind++ ) { - old_out_fx_32[ind] = L_shl(old_out_fx[ind], sub(q_tmp_fx_32, q_win) ); + old_out_fx_32[ind] = L_shl( old_out_fx[ind], sub( q_tmp_fx_32, q_win ) ); } window_ola_ext_fx( tmp_fx_32, xn_buf_fx_32, old_out_fx_32, L_frame, hTcxCfg->tcx_last_overlap_mode, hTcxCfg->tcx_curr_overlap_mode, kernel_type ); - FOR ( Word16 ind = 0; ind < L_frame; ind++ ) + FOR( Word16 ind = 0; ind < L_frame; ind++ ) { - old_out_fx[ind] = (Word16) L_shr( old_out_fx_32[ind], sub(q_tmp_fx_32, q_win) ); - xn_buf_fx[ind] = (Word16)L_shr(xn_buf_fx_32[ind], sub(q_tmp_fx_32, q_win) ); + old_out_fx[ind] = (Word16) L_shr( old_out_fx_32[ind], sub( q_tmp_fx_32, q_win ) ); + xn_buf_fx[ind] = (Word16) L_shr( xn_buf_fx_32[ind], sub( q_tmp_fx_32, q_win ) ); } } ELSE @@ -3032,24 +2981,27 @@ void IMDCT_ivas_fx( edct_fx( x_fx, xn_buf_fx_32 + overlap / 2 + nz, L_frame, &q_xn_buf_fx_32 ); Word16 res_m, res_e = 0; move16(); - res_m = BASOP_Util_Divide1616_Scale(L_frame, NORM_MDCT_FACTOR, &res_e); - res_m = Sqrt16(res_m, &res_e); + res_m = BASOP_Util_Divide1616_Scale( L_frame, NORM_MDCT_FACTOR, &res_e ); + res_m = Sqrt16( res_m, &res_e ); - FOR(Word16 ind = 0; ind < L_frame; ind++) { - tmp_fx_32[ind] = Mpy_32_16_1(xn_buf_fx_32[shr(overlap, 1) + nz + ind], res_m); + FOR( Word16 ind = 0; ind < L_frame; ind++ ) + { + tmp_fx_32[ind] = Mpy_32_16_1( xn_buf_fx_32[shr( overlap, 1 ) + nz + ind], res_m ); } - q_tmp_fx_32 = sub(q_xn_buf_fx_32, res_e); - //v_multc_fixed( xn_buf_fx_32 + overlap / 2 + nz, (float) sqrt( (float) L_frame / NORM_MDCT_FACTOR ), tmp_fx_32, L_frame ); + q_tmp_fx_32 = sub( q_xn_buf_fx_32, res_e ); + // v_multc_fixed( xn_buf_fx_32 + overlap / 2 + nz, (float) sqrt( (float) L_frame / NORM_MDCT_FACTOR ), tmp_fx_32, L_frame ); - FOR(Word16 ind = 0; ind < L_frame; ind++) { - xn_buf_fx[add( add(ind, shr(overlap, 1)), nz)] = (Word16)L_shr(xn_buf_fx_32[add( add(ind, shr(overlap, 1)), nz)], sub(q_xn_buf_fx_32, q_win)); + FOR( Word16 ind = 0; ind < L_frame; ind++ ) + { + xn_buf_fx[add( add( ind, shr( overlap, 1 ) ), nz )] = (Word16) L_shr( xn_buf_fx_32[add( add( ind, shr( overlap, 1 ) ), nz )], sub( q_xn_buf_fx_32, q_win ) ); } window_ola_fx( tmp_fx_32, xn_buf_fx, &q_tmp_fx_32, old_out_fx, &q_old_out, L_frame, hTcxCfg->tcx_last_overlap_mode, hTcxCfg->tcx_curr_overlap_mode, 0, 0, NULL ); - FOR(Word16 ind = 0; ind < L_frame; ind++) { - old_out_fx[ind] = shr_sat(old_out_fx[ind], sub(q_old_out, q_win)); - xn_buf_fx[ind] = shr_sat(xn_buf_fx[ind], sub(q_tmp_fx_32, q_win)); + FOR( Word16 ind = 0; ind < L_frame; ind++ ) + { + old_out_fx[ind] = shr_sat( old_out_fx[ind], sub( q_old_out, q_win ) ); + xn_buf_fx[ind] = shr_sat( xn_buf_fx[ind], sub( q_tmp_fx_32, q_win ) ); } } aldo = 1; @@ -3060,11 +3012,11 @@ void IMDCT_ivas_fx( Word16 acelp_mem_len = tcx_offset < 0 ? -tcx_offset : 0; move16(); - IF ( EQ_16(kernel_type, MDST_IV) ) + IF( EQ_16( kernel_type, MDST_IV ) ) { TCX_MDST_Inverse_fx( x_fx, x_e_hdrm, xn_buf_fx, overlap, L_frame - overlap, overlap ); } - ELSE IF ( kernel_type != MDCT_IV ) /* type 1 or 2 */ + ELSE IF( kernel_type != MDCT_IV ) /* type 1 or 2 */ { TCX_MDXT_Inverse_fx( x_fx, x_e_hdrm, xn_buf_fx, overlap, L_frame - overlap, overlap, kernel_type ); } @@ -3077,7 +3029,7 @@ void IMDCT_ivas_fx( * Windowing, overlap and add * *-----------------------------------------------------------*/ - IF ( EQ_16(st->element_mode, IVAS_CPE_MDCT) && (LE_32( st->last_core_brate, SID_2k40) || EQ_16(st->last_core, ACELP_CORE) ) && EQ_16(fullbandScale, 0) ) + IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && ( LE_32( st->last_core_brate, SID_2k40 ) || EQ_16( st->last_core, ACELP_CORE ) ) && EQ_16( fullbandScale, 0 ) ) { /* get LPC from that signal part to use for acelp zir smoothing */ const Word16 analysis_len = L_frame_glob / 4; @@ -3087,131 +3039,132 @@ void IMDCT_ivas_fx( Word16 q_r, q_buf; /* get the first 5 ms of non-aliased TCX syntesis */ - mvs2s( xn_buf_fx + add(shr(overlap, 1), shl(acelp_mem_len, 1)), &buf_fx[0], analysis_len ); - + mvs2s( xn_buf_fx + add( shr( overlap, 1 ), shl( acelp_mem_len, 1 ) ), &buf_fx[0], analysis_len ); + q_buf = q_win; move16(); - //q_old_Aq_12_8 = 28; + // q_old_Aq_12_8 = 28; move16(); ham_cos_window_ivas( &window_buf_fx[0], analysis_len / 2, analysis_len / 2 ); autocorr_fx_32( &buf_fx[0], M, &r_fx[0], &q_r, analysis_len, &window_buf_fx[0], 0, 0 ); lag_wind_32( r_fx, M, L_frame_glob * FRAMES_PER_SEC, LAGW_STRONG ); - lev_dur_fx( &st->old_Aq_12_8_fx_32[0], &r_fx[0], M, NULL, 28/*Q(st->q_old_Aq_12_8_fx_32)*/, add( add( shl(q_buf, 1), q_r), 1) ); - FOR(Word16 ind = 0; ind <= M; ind++) { - st->old_Aq_12_8_fx[ind] = (Word16) L_shr(st->old_Aq_12_8_fx_32[ind], 16); + lev_dur_fx( &st->old_Aq_12_8_fx_32[0], &r_fx[0], M, NULL, 28 /*Q(st->q_old_Aq_12_8_fx_32)*/, add( add( shl( q_buf, 1 ), q_r ), 1 ) ); + FOR( Word16 ind = 0; ind <= M; ind++ ) + { + st->old_Aq_12_8_fx[ind] = (Word16) L_shr( st->old_Aq_12_8_fx_32[ind], 16 ); } } /* Window current frame */ - tcx_windowing_synthesis_current_frame( xn_buf_fx, tcx_aldo_window_2_fx, tcx_mdct_window_half_fx, tcx_mdct_window_minimum_fx, overlap, tcx_mdct_window_half_length, tcx_mdct_window_min_length, left_rect, hTcxCfg->tcx_last_overlap_mode, acelp_zir_fx, hTcxDec->old_syn_Overl, syn_Overl_TDAC_fx, st->old_Aq_12_8_fx, tcx_mdct_window_trans_fx, shr(L_frame_glob, 1), acelp_mem_len, st->last_core_bfi, (Word8)st->last_is_cng, fullbandScale ); + tcx_windowing_synthesis_current_frame( xn_buf_fx, tcx_aldo_window_2_fx, tcx_mdct_window_half_fx, tcx_mdct_window_minimum_fx, overlap, tcx_mdct_window_half_length, tcx_mdct_window_min_length, left_rect, hTcxCfg->tcx_last_overlap_mode, acelp_zir_fx, hTcxDec->old_syn_Overl, syn_Overl_TDAC_fx, st->old_Aq_12_8_fx, tcx_mdct_window_trans_fx, shr( L_frame_glob, 1 ), acelp_mem_len, st->last_core_bfi, (Word8) st->last_is_cng, fullbandScale ); } } /* TCX-20 and TCX-only */ - IF ( NE_16( frame_cnt, 0 ) || GT_16( st->last_core_bfi, ACELP_CORE ) ) + IF( NE_16( frame_cnt, 0 ) || GT_16( st->last_core_bfi, ACELP_CORE ) ) { - IF ( ( EQ_16( L_frameTCX, shr(hTcxDec->L_frameTCX, 1 ) ) && NE_16( st->tcxonly, 0 ) ) || - EQ_16( hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) ) + IF( ( EQ_16( L_frameTCX, shr( hTcxDec->L_frameTCX, 1 ) ) && NE_16( st->tcxonly, 0 ) ) || + EQ_16( hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) ) { - IF ( EQ_16(bfi, 0) && GT_16( frame_cnt, 0 ) && EQ_16( index, 0 ) && EQ_16( hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) && NE_16( st->last_core, ACELP_CORE ) ) + IF( EQ_16( bfi, 0 ) && GT_16( frame_cnt, 0 ) && EQ_16( index, 0 ) && EQ_16( hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) && NE_16( st->last_core, ACELP_CORE ) ) { index = MIN_OVERLAP; /* use minimum overlap between the two TCX-10 windows */ move16(); } - IF ( NE_16(hTcxCfg->last_aldo, 0) ) + IF( NE_16( hTcxCfg->last_aldo, 0 ) ) { - FOR ( i = 0; i < sub(overlap, tcx_mdct_window_min_length); i++ ) + FOR( i = 0; i < sub( overlap, tcx_mdct_window_min_length ); i++ ) { - xn_buf_fx[add(i, sub(shr(overlap, 1), tcx_offset))] = add(xn_buf_fx[add(i, sub(shr(overlap, 1), tcx_offset))], old_out_fx[add(i, nz)]); + xn_buf_fx[add( i, sub( shr( overlap, 1 ), tcx_offset ) )] = add( xn_buf_fx[add( i, sub( shr( overlap, 1 ), tcx_offset ) )], old_out_fx[add( i, nz )] ); } /* fade truncated ALDO window */ - IF ( EQ_16(L_frameTCX, shr(hTcxDec->L_frameTCX, 1)) && EQ_16(st->element_mode, IVAS_CPE_MDCT) && EQ_16(frame_cnt, 0) && EQ_16(hTcxCfg->tcx_last_overlap_mode, FULL_OVERLAP) ) + IF( EQ_16( L_frameTCX, shr( hTcxDec->L_frameTCX, 1 ) ) && EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( frame_cnt, 0 ) && EQ_16( hTcxCfg->tcx_last_overlap_mode, FULL_OVERLAP ) ) { // tested - FOR ( ; i < overlap; i++ ) /* perfectly reconstructing ALDO shortening */ + FOR( ; i < overlap; i++ ) /* perfectly reconstructing ALDO shortening */ { - xn_buf_fx[sub(add(i, shr(overlap, 1)), tcx_offset)] = add(xn_buf_fx[sub(add(i, shr(overlap, 1)), tcx_offset)], old_out_fx[add(i, nz)]); + xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], old_out_fx[add( i, nz )] ); } - FOR ( i = 0; i < shr(tcx_mdct_window_min_length, 1); i++ ) + FOR( i = 0; i < shr( tcx_mdct_window_min_length, 1 ); i++ ) { - xn_buf_fx[add(sub(add(i, shr(overlap, 1)), tcx_offset), overlap)] = add(xn_buf_fx[add(sub(add(i, shr(overlap, 1)), tcx_offset), overlap)], mult_r(old_out_fx[add(add(i, nz), overlap)], tcx_mdct_window_minimum_fx[i].v.re)); + xn_buf_fx[add( sub( add( i, shr( overlap, 1 ) ), tcx_offset ), overlap )] = add( xn_buf_fx[add( sub( add( i, shr( overlap, 1 ) ), tcx_offset ), overlap )], mult_r( old_out_fx[add( add( i, nz ), overlap )], tcx_mdct_window_minimum_fx[i].v.re ) ); } - FOR ( ; i < tcx_mdct_window_min_length; i++ ) + FOR( ; i < tcx_mdct_window_min_length; i++ ) { - xn_buf_fx[add(sub(add(i, shr(overlap, 1)), tcx_offset), overlap)] = add(xn_buf_fx[add(sub(add(i, shr(overlap, 1)), tcx_offset), overlap)], mult_r(old_out_fx[add(add(i, nz), overlap)], tcx_mdct_window_minimum_fx[sub(tcx_mdct_window_min_length, add(1, i))].v.im)); + xn_buf_fx[add( sub( add( i, shr( overlap, 1 ) ), tcx_offset ), overlap )] = add( xn_buf_fx[add( sub( add( i, shr( overlap, 1 ) ), tcx_offset ), overlap )], mult_r( old_out_fx[add( add( i, nz ), overlap )], tcx_mdct_window_minimum_fx[sub( tcx_mdct_window_min_length, add( 1, i ) )].v.im ) ); } } ELSE { - FOR ( ; i < sub(overlap, shr(tcx_mdct_window_min_length, 1)); i++ ) + FOR( ; i < sub( overlap, shr( tcx_mdct_window_min_length, 1 ) ); i++ ) { - xn_buf_fx[sub(add(i, shr(overlap, 1)), tcx_offset)] = add(xn_buf_fx[sub(add(i, shr(overlap, 1)), tcx_offset)], mult_r(old_out_fx[add(i, nz)], tcx_mdct_window_minimum_fx[add(sub(tcx_mdct_window_min_length, overlap), i)].v.re)); + xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], mult_r( old_out_fx[add( i, nz )], tcx_mdct_window_minimum_fx[add( sub( tcx_mdct_window_min_length, overlap ), i )].v.re ) ); } - FOR ( ; i < overlap; i++ ) + FOR( ; i < overlap; i++ ) { - xn_buf_fx[add(i, sub(shr(overlap, 1), tcx_offset))] = add(xn_buf_fx[sub(add(i, shr(overlap, 1)), tcx_offset)], mult_r(old_out_fx[add(i, nz)], tcx_mdct_window_minimum_fx[sub(overlap, add(1, i))].v.im)); + xn_buf_fx[add( i, sub( shr( overlap, 1 ), tcx_offset ) )] = add( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], mult_r( old_out_fx[add( i, nz )], tcx_mdct_window_minimum_fx[sub( overlap, add( 1, i ) )].v.im ) ); } } } ELSE { - tcx_windowing_synthesis_past_frame( old_syn_overl_fx, tcx_aldo_window_1_trunc_fx, tcx_mdct_window_half_fx, tcx_mdct_window_minimum_fx, overlap, tcx_mdct_window_half_length, tcx_mdct_window_min_length, ( EQ_16(index, 0) || EQ_16(hTcxCfg->tcx_last_overlap_mode, MIN_OVERLAP) ) ? hTcxCfg->tcx_last_overlap_mode : index ); + tcx_windowing_synthesis_past_frame( old_syn_overl_fx, tcx_aldo_window_1_trunc_fx, tcx_mdct_window_half_fx, tcx_mdct_window_minimum_fx, overlap, tcx_mdct_window_half_length, tcx_mdct_window_min_length, ( EQ_16( index, 0 ) || EQ_16( hTcxCfg->tcx_last_overlap_mode, MIN_OVERLAP ) ) ? hTcxCfg->tcx_last_overlap_mode : index ); - IF ( NE_16(bfi, 0) ) + IF( NE_16( bfi, 0 ) ) { - FOR ( i = 0; i < shr(tcx_mdct_window_half_length, 1); i++ ) + FOR( i = 0; i < shr( tcx_mdct_window_half_length, 1 ); i++ ) { - xn_buf_fx[sub(add(i, shr(overlap, 1)), tcx_offset)] = add(xn_buf_fx[sub(add(i, shr(overlap, 1)), tcx_offset)], mult_r(old_syn_overl_fx[i], tcx_mdct_window_half_fx[i].v.re)); + xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], mult_r( old_syn_overl_fx[i], tcx_mdct_window_half_fx[i].v.re ) ); } - FOR ( ; i < tcx_mdct_window_half_length; i++ ) + FOR( ; i < tcx_mdct_window_half_length; i++ ) { - xn_buf_fx[sub(add(i, shr(overlap, 1)), tcx_offset)] = add(xn_buf_fx[sub(add(i, shr(overlap, 1)), tcx_offset)], mult_r(old_syn_overl_fx[i], tcx_mdct_window_half_fx[sub(tcx_mdct_window_half_length, add(1, i))].v.im)); + xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], mult_r( old_syn_overl_fx[i], tcx_mdct_window_half_fx[sub( tcx_mdct_window_half_length, add( 1, i ) )].v.im ) ); } } - ELSE IF ( EQ_16(left_rect, 0) ) + ELSE IF( EQ_16( left_rect, 0 ) ) { - FOR ( i = 0; i < overlap; i++ ) + FOR( i = 0; i < overlap; i++ ) { - xn_buf_fx[i] = add(xn_buf_fx[i], old_syn_overl_fx[i]); + xn_buf_fx[i] = add( xn_buf_fx[i], old_syn_overl_fx[i] ); } } ELSE { - FOR ( i = 0; i < overlap; i++ ) + FOR( i = 0; i < overlap; i++ ) { - xn_buf_fx[i + shr( overlap, 1 )] = add(xn_buf_fx[i + shr( overlap, 1 )], old_syn_overl_fx[i]); + xn_buf_fx[i + shr( overlap, 1 )] = add( xn_buf_fx[i + shr( overlap, 1 )], old_syn_overl_fx[i] ); } } } } } - IF ( EQ_16(aldo, 0) && ( ( EQ_16( L_frameTCX, shr(hTcxDec->L_frameTCX, 1) ) && GT_16(frame_cnt, 0) ) || NE_16(L_frameTCX, shr( hTcxDec->L_frameTCX, 1 ) ) ) ) + IF( EQ_16( aldo, 0 ) && ( ( EQ_16( L_frameTCX, shr( hTcxDec->L_frameTCX, 1 ) ) && GT_16( frame_cnt, 0 ) ) || NE_16( L_frameTCX, shr( hTcxDec->L_frameTCX, 1 ) ) ) ) { /* Compute windowed synthesis in case of switching to ALDO windows in next frame */ - mvs2s( xn_buf_fx + sub(L_frame, nz), old_out_fx, add(nz, overlap) ); - set16_fx( old_out_fx + add(nz, overlap), 0, nz ); + mvs2s( xn_buf_fx + sub( L_frame, nz ), old_out_fx, add( nz, overlap ) ); + set16_fx( old_out_fx + add( nz, overlap ), 0, nz ); tcx_windowing_synthesis_past_frame( old_out_fx + nz, tcx_aldo_window_1_trunc_fx, tcx_mdct_window_half_fx, tcx_mdct_window_minimum_fx, overlap, tcx_mdct_window_half_length, tcx_mdct_window_min_length, hTcxCfg->tcx_curr_overlap_mode ); /* If current overlap mode = FULL_OVERLAP -> ALDO_WINDOW */ - IF ( EQ_16(hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP) ) + IF( EQ_16( hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) ) { - //tested - IF ( s_and(kernel_type, 1) ) + // tested + IF( s_and( kernel_type, 1 ) ) { - FOR ( i = 0; i < nz; i++ ) + FOR( i = 0; i < nz; i++ ) { - old_out_fx[add(add(nz, overlap), i)] = negate( mult_r( xn_buf_fx[sub(L_frame, add(1, i))], tcx_aldo_window_1_fx[sub(nz, add(1, i))] ) ); + old_out_fx[add( add( nz, overlap ), i )] = negate( mult_r( xn_buf_fx[sub( L_frame, add( 1, i ) )], tcx_aldo_window_1_fx[sub( nz, add( 1, i ) )] ) ); } } ELSE { - FOR ( i = 0; i < nz; i++ ) + FOR( i = 0; i < nz; i++ ) { - old_out_fx[add(add(nz, overlap), i)] = mult_r( xn_buf_fx[sub(L_frame, add(1, i))], tcx_aldo_window_1_fx[sub(nz, add(1, i))]); + old_out_fx[add( add( nz, overlap ), i )] = mult_r( xn_buf_fx[sub( L_frame, add( 1, i ) )], tcx_aldo_window_1_fx[sub( nz, add( 1, i ) )] ); } } aldo = 1; @@ -3219,39 +3172,39 @@ void IMDCT_ivas_fx( } } - IF ( NE_16(FB_flag , 0) ) + IF( NE_16( FB_flag, 0 ) ) { hTcxCfg->last_aldo = aldo; move16(); } /* Smoothing between the ACELP PLC and TCX Transition frame. Using the shape of the half overlap window for the crossfading. */ - IF ( NE_16(left_rect, 0) && EQ_16( frame_cnt, 0 ) && EQ_16( st->last_core_bfi, ACELP_CORE ) && NE_16(st->prev_bfi, 0) ) + IF( NE_16( left_rect, 0 ) && EQ_16( frame_cnt, 0 ) && EQ_16( st->last_core_bfi, ACELP_CORE ) && NE_16( st->prev_bfi, 0 ) ) { - IF ( NE_16(FB_flag, 0) ) + IF( NE_16( FB_flag, 0 ) ) { - FOR ( i = 0; i < shr(tcx_mdct_window_half_length, 1); i++ ) + FOR( i = 0; i < shr( tcx_mdct_window_half_length, 1 ); i++ ) { - xn_buf_fx[sub(add(i, shr(overlap, 1)), tcx_offset)] = mult_r(xn_buf_fx[sub(add(i, shr(overlap, 1)), tcx_offset)], tcx_mdct_window_half_fx[i].v.im); - xn_buf_fx[sub(add(i, shr(overlap, 1)), tcx_offset)] = add(xn_buf_fx[sub(add(i, shr(overlap, 1)), tcx_offset)], mult_r( mult_r( hTcxDec->syn_OverlFB[i], tcx_mdct_window_half_fx[i].v.re), tcx_mdct_window_half_fx[i].v.re)); + xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = mult_r( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], tcx_mdct_window_half_fx[i].v.im ); + xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], mult_r( mult_r( hTcxDec->syn_OverlFB[i], tcx_mdct_window_half_fx[i].v.re ), tcx_mdct_window_half_fx[i].v.re ) ); } - FOR ( ; i < tcx_mdct_window_half_length; i++ ) + FOR( ; i < tcx_mdct_window_half_length; i++ ) { - xn_buf_fx[sub(add(i, shr(overlap, 1)), tcx_offset)] = mult_r(xn_buf_fx[sub(add(i, shr(overlap, 1)), tcx_offset)], tcx_mdct_window_half_fx[sub(tcx_mdct_window_half_length, add(1, i))].v.re ); - xn_buf_fx[sub(add(i, shr(overlap, 1)), tcx_offset)] = add(xn_buf_fx[sub(add(i, shr(overlap, 1)), tcx_offset)], mult_r( mult_r( hTcxDec->syn_OverlFB[i], tcx_mdct_window_half_fx[sub(tcx_mdct_window_half_length, add(1, i))].v.im), tcx_mdct_window_half_fx[sub(tcx_mdct_window_half_length, add(1, i))].v.im)); + xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = mult_r( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], tcx_mdct_window_half_fx[sub( tcx_mdct_window_half_length, add( 1, i ) )].v.re ); + xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], mult_r( mult_r( hTcxDec->syn_OverlFB[i], tcx_mdct_window_half_fx[sub( tcx_mdct_window_half_length, add( 1, i ) )].v.im ), tcx_mdct_window_half_fx[sub( tcx_mdct_window_half_length, add( 1, i ) )].v.im ) ); } } ELSE { - FOR ( i = 0; i < shr(tcx_mdct_window_half_length, 1); i++ ) + FOR( i = 0; i < shr( tcx_mdct_window_half_length, 1 ); i++ ) { - xn_buf_fx[sub(add(i, shr(overlap, 1)), tcx_offset)] = mult_r(xn_buf_fx[sub(add(i, shr(overlap, 1)), tcx_offset)], tcx_mdct_window_half_fx[i].v.im); - xn_buf_fx[sub(add(i, shr(overlap, 1)), tcx_offset)] = add(xn_buf_fx[sub(add(i, shr(overlap, 1)), tcx_offset)], mult_r( mult_r( hTcxDec->syn_Overl[i], tcx_mdct_window_half_fx[i].v.re), tcx_mdct_window_half_fx[i].v.re)); + xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = mult_r( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], tcx_mdct_window_half_fx[i].v.im ); + xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], mult_r( mult_r( hTcxDec->syn_Overl[i], tcx_mdct_window_half_fx[i].v.re ), tcx_mdct_window_half_fx[i].v.re ) ); } - FOR ( ; i < tcx_mdct_window_half_length; i++ ) + FOR( ; i < tcx_mdct_window_half_length; i++ ) { - xn_buf_fx[sub(add(i, shr(overlap, 1)), tcx_offset)] = mult_r(xn_buf_fx[sub(add(i, shr(overlap, 1)), tcx_offset)], tcx_mdct_window_half_fx[sub(tcx_mdct_window_half_length, add(1, i))].v.re); - xn_buf_fx[sub(add(i, shr(overlap, 1)), tcx_offset)] = add(xn_buf_fx[sub(add(i, shr(overlap, 1)), tcx_offset)], mult_r( mult_r( hTcxDec->syn_Overl[i], tcx_mdct_window_half_fx[sub(tcx_mdct_window_half_length, add(1, i))].v.im), tcx_mdct_window_half_fx[sub(tcx_mdct_window_half_length, add(1, i))].v.im)); + xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = mult_r( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], tcx_mdct_window_half_fx[sub( tcx_mdct_window_half_length, add( 1, i ) )].v.re ); + xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], mult_r( mult_r( hTcxDec->syn_Overl[i], tcx_mdct_window_half_fx[sub( tcx_mdct_window_half_length, add( 1, i ) )].v.im ), tcx_mdct_window_half_fx[sub( tcx_mdct_window_half_length, add( 1, i ) )].v.im ) ); } } } @@ -3359,7 +3312,7 @@ void init_tcx_info_fx( test(); IF( st->igf ) { - IF ( EQ_16( *L_frame, shr( st->L_frame, 1 ) ) && ( st->tcxonly ) ) + IF( EQ_16( *L_frame, shr( st->L_frame, 1 ) ) && ( st->tcxonly ) ) { IGFDecUpdateInfo_ivas_fx( st->hIGFDec, frame_cnt, IGF_GRID_LB_SHORT ); } @@ -3412,16 +3365,16 @@ void decoder_tcx_IGF_mono_fx( IGFDecUpdateInfo_ivas_fx( st->hIGFDec, frame_cnt, igfGridIdx ); - IF ( st->igf ) + IF( st->igf ) { igfGridIdx = IGF_GRID_LB_SHORT; move16(); /*st->hIGFDec.igfData.igfInfo.nfSeed = (int16_t)(*nf_seed * 31821L + 13849L);*/ test(); - IF ( NE_16( L_frame, shr(st->L_frame, 1) ) && st->tcxonly ) + IF( NE_16( L_frame, shr( st->L_frame, 1 ) ) && st->tcxonly ) { - IF ( EQ_16( st->last_core, ACELP_CORE ) || ( left_rect && bfi ) ) + IF( EQ_16( st->last_core, ACELP_CORE ) || ( left_rect && bfi ) ) { igfGridIdx = IGF_GRID_LB_TRAN; move16(); @@ -3437,7 +3390,6 @@ void decoder_tcx_IGF_mono_fx( *x_len = st->hIGFDec->igfData.igfInfo.grid[igfGridIdx].stopLine; move16(); - } return; @@ -3482,7 +3434,7 @@ void decoder_tcx_IGF_stereo_fx( sfbConf = &hStereoMdct->stbParamsTCX10; } - IF ( EQ_16( sts[0]->last_core, ACELP_CORE ) ) + IF( EQ_16( sts[0]->last_core, ACELP_CORE ) ) { sfbConf = &hStereoMdct->stbParamsTCX20afterACELP; } @@ -3490,12 +3442,12 @@ void decoder_tcx_IGF_stereo_fx( /* create line wise ms mask for the core bands */ set16_fx( coreMsMask, 0, N_MAX ); - FOR ( sfb = 0; sfb < sfbConf->sfbCnt; sfb++ ) + FOR( sfb = 0; sfb < sfbConf->sfbCnt; sfb++ ) { set16_fx( &coreMsMask[sfbConf->sfbOffset[sfb]], ms_mask[k][sfb], sfbConf->sfbOffset[sfb + 1] - sfbConf->sfbOffset[sfb] ); } - IF( EQ_16( L_frame, shr( sts[0]->L_frame, 1 )) && ( sts[0]->tcxonly ) ) + IF( EQ_16( L_frame, shr( sts[0]->L_frame, 1 ) ) && ( sts[0]->tcxonly ) ) { igfGridIdx = IGF_GRID_LB_SHORT; move16(); @@ -3537,14 +3489,14 @@ void decoder_tcx_IGF_stereo_fx( IGFDecUpdateInfo_ivas_fx( sts[1]->hIGFDec, k, igfGridIdx ); - IF ( sts[0]->igf ) + IF( sts[0]->igf ) { igfGridIdx = IGF_GRID_LB_SHORT; move16(); test(); - IF ( NE_16( L_frame, shr( sts[0]->L_frame, 1 ) ) && ( sts[0]->tcxonly ) ) + IF( NE_16( L_frame, shr( sts[0]->L_frame, 1 ) ) && ( sts[0]->tcxonly ) ) { - IF ( EQ_16( sts[0]->last_core, ACELP_CORE ) || ( left_rect && bfi ) ) + IF( EQ_16( sts[0]->last_core, ACELP_CORE ) || ( left_rect && bfi ) ) { igfGridIdx = IGF_GRID_LB_TRAN; move16(); @@ -3637,15 +3589,15 @@ void decoder_tcx_ivas_fx( decoder_tcx_noiseshaping_igf_fx( st, L_spec, L_frame, L_frameTCX, left_rect, x_fx, &x_e, &x_len, gainlpc2_fx, gainlpc2_e, &tmp_concealment_method, bfi ); - shift = sub(Find_Max_Norm32( x_fx, N_MAX ) , 6); //6 -> guardbits// + shift = sub( Find_Max_Norm32( x_fx, N_MAX ), 6 ); // 6 -> guardbits// move16(); - Scale_sig32( x_fx, N_MAX, shift); + Scale_sig32( x_fx, N_MAX, shift ); x_e = sub( x_e, shift ); move16(); decoder_tcx_tns_fx( st, L_frame_glob, L_spec, L_frame, L_frameTCX, x_fx, fUseTns, &tnsData, bfi, frame_cnt, 0 ); - Scale_sig32( x_fx, N_MAX, sub( x_e, 20 ) ); // Scaling x_fx to Q11 + Scale_sig32( x_fx, N_MAX, sub( x_e, 20 ) ); // Scaling x_fx to Q11 Scale_sig( xn_buf_fx, L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX, st->Q_syn - 14 ); // Scaling xn_buf_fx to Q_syn x_e = sub( 31, 11 ); move16(); @@ -3657,8 +3609,8 @@ void decoder_tcx_ivas_fx( } /* Scaling down buffers for decoder_tcx_imdct_fx*/ - Scale_sig( st->hTcxDec->syn_Overl, 320, -1 ); // Scaling to Q_syn - Scale_sig( st->hTcxDec->old_syn_Overl, 320, 1 ); // Scaling to Q_syn + Scale_sig( st->hTcxDec->syn_Overl, 320, -1 ); // Scaling to Q_syn + Scale_sig( st->hTcxDec->old_syn_Overl, 320, 1 ); // Scaling to Q_syn Copy_Scale_sig_16_32_no_sat( st->old_Aq_12_8_fx, st->old_Aq_12_8_fx_32, M + 1, ( 28 - ( 15 - norm_s( st->old_Aq_12_8_fx[0] - 1 ) ) ) ); Scale_sig( synth_fx, L_frame_glob, st->Q_syn ); // Scaling to Q_syn @@ -3668,12 +3620,12 @@ void decoder_tcx_ivas_fx( fUseTns, &synth_fx[0], &synthFB_fx[0], bfi, frame_cnt, sba_dirac_stereo_flag ); /* Scaling up again */ - Scale_sig( synth_fx, L_frame_glob, negate(st->Q_syn) ); - Scale_sig( synthFB_fx, L_frameTCX_glob, negate(st->Q_syn) ); + Scale_sig( synth_fx, L_frame_glob, negate( st->Q_syn ) ); + Scale_sig( synthFB_fx, L_frameTCX_glob, negate( st->Q_syn ) ); Scale_sig( st->hTcxDec->syn_Overl, L_FRAME32k / 2, 1 ); Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, ( st->hHQ_core->Q_old_wtda - st->Q_syn ) ); Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, ( st->hHQ_core->Q_old_wtda - st->Q_syn ) ); - Scale_sig( st->hTcxDec->old_syn_Overl, 320, ( -2 + st->Q_syn ) ); // Scaling to Q-2 + Scale_sig( st->hTcxDec->old_syn_Overl, 320, ( -2 + st->Q_syn ) ); // Scaling to Q-2 } #endif @@ -3920,7 +3872,7 @@ void decoder_tcx_invQ_fx( tmp32 = L_shl( L_mult0( index, 0x797D ), 7 ); /* 6Q25; 0x797D -> log2(10)/28 (Q18) */ *gain_tcx_e = add( extract_l( L_shr( tmp32, 25 ) ), 1 ); /* get exponent */ - *gain_tcx = round_fx( BASOP_Util_InvLog2( L_or( tmp32, (Word32)0xFE000000 ) ) ); + *gain_tcx = round_fx( BASOP_Util_InvLog2( L_or( tmp32, (Word32) 0xFE000000 ) ) ); #ifdef BASOP_NOGLOB tmp1 = mult_r( shl_sat( L_spec, 5 ), 26214 /*128.f/NORM_MDCT_FACTOR Q15*/ ); @@ -3988,9 +3940,9 @@ void decoder_tcx_invQ_fx( move16(); hTcxDec->damping = Damping_fact_fx( st->coder_type, st->nbLostCmpt, st->last_good, - st->stab_fac_fx, - &st->Mode2_lp_gainp, - st->last_core ); + st->stab_fac_fx, + &st->Mode2_lp_gainp, + st->last_core ); } hTcxDec->cummulative_damping_tcx = shl( mult( hTcxDec->cummulative_damping_tcx, hTcxDec->damping ), 1 ); /*shl(Q15*Q14,1)=shl(Q14,1) = Q15*/ @@ -4226,7 +4178,7 @@ void decoder_tcx_noisefilling_fx( Decoder_State *st, /* i/o: coder memory state */ const Word32 concealment_noise[L_FRAME48k], const Word16 concealment_noise_exp, - const Word16 A[], /* i : coefficients NxAz[M+1] */ + const Word16 A[], /* i : coefficients NxAz[M+1] */ const Word16 L_frameTCX_glob, const Word16 L_spec, const Word16 L_frame, @@ -4451,7 +4403,7 @@ void decoder_tcx_noisefilling_fx( IF( bfi == 0 && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { TonalMDCTConceal_SaveFreqSignal_ivas_fx( st->hTonalMDCTConc, x, *x_e, L_frameTCX, L_frame, gainlpc2, gainlpc2_e, gain_tcx_e, infoIGFStartLine ); - //st->hTonalMDCTConc->last_block_nrg_flt = me2f( st->hTonalMDCTConc->last_block_nrg, st->hTonalMDCTConc->last_block_nrg_exp ); + // st->hTonalMDCTConc->last_block_nrg_flt = me2f( st->hTonalMDCTConc->last_block_nrg, st->hTonalMDCTConc->last_block_nrg_exp ); } ELSE IF( bfi ) { @@ -4543,7 +4495,7 @@ void decoder_tcx_noisefilling_fx( tcxGetNoiseFillingTilt( A, M, L_frame, tmp, &noiseTiltFactor ); - Word32 CngLevelBackgroundTrace_bfi_fx = L_deposit_l(hTcxDec->conCngLevelBackgroundTrace); + Word32 CngLevelBackgroundTrace_bfi_fx = L_deposit_l( hTcxDec->conCngLevelBackgroundTrace ); Word16 CngLevelBackgroundTrace_bfi_exp = hTcxDec->conCngLevelBackgroundTrace_e + 16; IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && MCT_flag == 0 ) { diff --git a/lib_dec/dec_tran_fx.c b/lib_dec/dec_tran_fx.c index 32227b458..081cf20b8 100644 --- a/lib_dec/dec_tran_fx.c +++ b/lib_dec/dec_tran_fx.c @@ -2,10 +2,10 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ #ifdef IVAS_FLOAT_FIXED /*======================================================================*/ /* FUNCTION : decod_tran_fx() */ @@ -34,27 +34,27 @@ /*=======================================================================*/ void decod_tran_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - const Word16 L_frame_fx, /* i : length of the frame */ - const Word16 tc_subfr_fx, /* i : TC subframe index */ - const Word16 *Aq_fx, /* i : LP filter coefficient */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe*/ - Word16 *voice_factors_fx, /* o : voicing factors */ - Word16 *exc_fx, /* i/o: adapt. excitation exc */ - Word16 *exc2_fx, /* i/o: adapt. excitation/total exc */ - Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE */ - Word16 *unbits, /* i/o: number of unused bits */ - const Word16 sharpFlag, /* i : formant sharpening flag */ - Word16 *gain_buf /* o : floating pitch gain for each subframe */ + Decoder_State *st_fx, /* i/o: decoder static memory */ + const Word16 L_frame_fx, /* i : length of the frame */ + const Word16 tc_subfr_fx, /* i : TC subframe index */ + const Word16 *Aq_fx, /* i : LP filter coefficient */ + const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ + Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe*/ + Word16 *voice_factors_fx, /* o : voicing factors */ + Word16 *exc_fx, /* i/o: adapt. excitation exc */ + Word16 *exc2_fx, /* i/o: adapt. excitation/total exc */ + Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE */ + Word16 *unbits, /* i/o: number of unused bits */ + const Word16 sharpFlag, /* i : formant sharpening flag */ + Word16 *gain_buf /* o : floating pitch gain for each subframe */ ) { Word16 T0, T0_frac, T0_min, T0_max; /* integer pitch variables */ - Word32 gain_code_fx=0; /* Quantized algebraic codeebook gain */ - Word32 norm_gain_code_fx=0; /* normalized algebraic codeebook gain */ + Word32 gain_code_fx = 0; /* Quantized algebraic codeebook gain */ + Word32 norm_gain_code_fx = 0; /* normalized algebraic codeebook gain */ Word16 gain_pit_fx = 0; /* Quantized pitch gain */ Word16 voice_fac_fx; /* Voicing factor */ - Word16 gain_inov_fx=0; /* inovation gain */ + Word16 gain_inov_fx = 0; /* inovation gain */ Word16 code_fx[L_SUBFR]; /* algebraic codevector */ const Word16 *p_Aq_fx; /* pointer to lp filter coefficient */ Word16 *pt_pitch_fx; /* pointer to floating pitch */ @@ -96,13 +96,13 @@ void decod_tran_fx( *------------------------------------------------------------*/ test(); - IF( i_subfr == 0 && GT_16(st_fx->Q_exc,2)) + IF( i_subfr == 0 && GT_16( st_fx->Q_exc, 2 ) ) { - tmp16 = sub(2, st_fx->Q_exc); - Scale_sig(exc_fx-L_EXC_MEM, L_EXC_MEM, tmp16); - Scale_sig(bwe_exc_fx-PIT16k_MAX*2, PIT16k_MAX*2, tmp16); - Scale_sig(hGSCDec->last_exc_dct_in_fx, L_FRAME, tmp16); - st_fx->Q_exc = add(st_fx->Q_exc,tmp16); + tmp16 = sub( 2, st_fx->Q_exc ); + Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, tmp16 ); + Scale_sig( bwe_exc_fx - PIT16k_MAX * 2, PIT16k_MAX * 2, tmp16 ); + Scale_sig( hGSCDec->last_exc_dct_in_fx, L_FRAME, tmp16 ); + st_fx->Q_exc = add( st_fx->Q_exc, tmp16 ); } transition_dec_fx( st_fx, 0, L_frame_fx, i_subfr, tc_subfr_fx, &Jopt_flag, exc_fx, @@ -110,18 +110,18 @@ void decod_tran_fx( /*-----------------------------------------------------------------* * Transform domain contribution decoding - active frames *-----------------------------------------------------------------*/ - IF( GE_32(st_fx->core_brate, MIN_BRATE_AVQ_EXC)) + IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) ) { gain_code_fx = 0; move16(); - transf_cdbk_dec_fx( st_fx, 0, i_subfr, Es_pred_fx, gain_code_fx, &gain_preQ_fx, &norm_gain_preQ_fx, code_preQ_fx, unbits); + transf_cdbk_dec_fx( st_fx, 0, i_subfr, Es_pred_fx, gain_code_fx, &gain_preQ_fx, &norm_gain_preQ_fx, code_preQ_fx, unbits ); } /*-----------------------------------------------------------------* * ACELP codebook search + pitch sharpening *-----------------------------------------------------------------*/ - inov_decode_fx( st_fx, st_fx->core_brate, 0, L_frame_fx, sharpFlag, i_subfr, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_SUBFR); + inov_decode_fx( st_fx, st_fx->core_brate, 0, L_frame_fx, sharpFlag, i_subfr, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_SUBFR ); /*-----------------------------------------------------------------* * De-quantize the gains @@ -131,87 +131,89 @@ void decod_tran_fx( IF( Jopt_flag == 0 ) { /* 2/3-bit decoding */ - if (st_fx->element_mode == EVS_MONO) { - gain_dec_tc_fx(st_fx, code_fx, i_subfr, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx); + if ( st_fx->element_mode == EVS_MONO ) + { + gain_dec_tc_fx( st_fx, code_fx, i_subfr, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx ); } - else { - gain_dec_tc_ivas_fx(st_fx, code_fx, i_subfr, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx); + else + { + gain_dec_tc_ivas_fx( st_fx, code_fx, i_subfr, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx ); } } ELSE { /* 5-bit decoding */ - IF( GT_32(st_fx->core_brate,ACELP_32k)) + IF( GT_32( st_fx->core_brate, ACELP_32k ) ) { gain_dec_SQ_fx( st_fx, i_subfr, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx ); } ELSE { - gain_dec_mless_fx( st_fx, L_frame_fx, st_fx->coder_type, i_subfr, tc_subfr_fx , code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx ); - + gain_dec_mless_fx( st_fx, L_frame_fx, st_fx->coder_type, i_subfr, tc_subfr_fx, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx ); } } /* update LP filtered gains for the case of frame erasures */ - lp_gain_updt_fx( i_subfr, gain_pit_fx, L_add(norm_gain_code_fx,norm_gain_preQ_fx), &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_frame_fx ); + lp_gain_updt_fx( i_subfr, gain_pit_fx, L_add( norm_gain_code_fx, norm_gain_preQ_fx ), &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_frame_fx ); - IF ( st_fx->element_mode == EVS_MONO ) + IF( st_fx->element_mode == EVS_MONO ) { st_fx->tilt_code_fx = est_tilt_fx( exc_fx + i_subfr, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, st_fx->Q_exc ); } else { - st_fx->tilt_code_fx = est_tilt_ivas_fx( exc_fx+i_subfr, gain_pit_fx, code_fx, gain_code_fx,&voice_fac_fx,st_fx->Q_exc, L_SUBFR, 0); + st_fx->tilt_code_fx = est_tilt_ivas_fx( exc_fx + i_subfr, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, st_fx->Q_exc, L_SUBFR, 0 ); } /*----------------------------------------------------------------------* * Find the total excitation *----------------------------------------------------------------------*/ - IF ( EQ_16(L_frame_fx,L_FRAME)) /* Rescaling for 12.8k core */ + IF( EQ_16( L_frame_fx, L_FRAME ) ) /* Rescaling for 12.8k core */ { - Rescale_exc(hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr], &bwe_exc_fx[i_subfr * HIBND_ACB_L_FAC], hGSCDec->last_exc_dct_in_fx, - L_SUBFR, L_SUBFR * HIBND_ACB_L_FAC, gain_code_fx, &(st_fx->Q_exc), st_fx->Q_subfr, exc2_fx, i_subfr, st_fx->coder_type ); + Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr], &bwe_exc_fx[i_subfr * HIBND_ACB_L_FAC], hGSCDec->last_exc_dct_in_fx, + L_SUBFR, L_SUBFR * HIBND_ACB_L_FAC, gain_code_fx, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr, st_fx->coder_type ); } - ELSE /* Rescaling for 16k core */ + ELSE /* Rescaling for 16k core */ { - Rescale_exc(hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr], &bwe_exc_fx[i_subfr * 2], hGSCDec->last_exc_dct_in_fx, - L_SUBFR, L_SUBFR * 2, gain_code_fx, &(st_fx->Q_exc), st_fx->Q_subfr, exc2_fx, i_subfr,st_fx->coder_type ); + Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr], &bwe_exc_fx[i_subfr * 2], hGSCDec->last_exc_dct_in_fx, + L_SUBFR, L_SUBFR * 2, gain_code_fx, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr, st_fx->coder_type ); } - gain_code16 = round_fx(L_shl(gain_code_fx,st_fx->Q_exc)); /*Q_exc*/ - Acelp_dec_total_exc( exc_fx, exc2_fx, gain_code16, gain_pit_fx, i_subfr, code_fx, L_SUBFR); + gain_code16 = round_fx( L_shl( gain_code_fx, st_fx->Q_exc ) ); /*Q_exc*/ + Acelp_dec_total_exc( exc_fx, exc2_fx, gain_code16, gain_pit_fx, i_subfr, code_fx, L_SUBFR ); /*-----------------------------------------------------------------* * Add the ACELP pre-quantizer contribution *-----------------------------------------------------------------*/ - IF(GE_32(st_fx->core_brate, MIN_BRATE_AVQ_EXC)) + IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) ) { - IF (st_fx->element_mode == EVS_MONO) { + IF( st_fx->element_mode == EVS_MONO ) + { tmp1_fx = add( 15 - Q_AVQ_OUT_DEC - 2, st_fx->Q_exc ); } - ELSE { - tmp1_fx = add(15 - Q_AVQ_OUT - 2, st_fx->Q_exc); + ELSE + { + tmp1_fx = add( 15 - Q_AVQ_OUT - 2, st_fx->Q_exc ); } FOR( i = 0; i < L_SUBFR; i++ ) { - L_tmp = L_mult(gain_preQ_fx, code_preQ_fx[i]); /* Q2 + Q10 -> Q13*/ + L_tmp = L_mult( gain_preQ_fx, code_preQ_fx[i] ); /* Q2 + Q10 -> Q13*/ #ifdef BASOP_NOGLOB L_tmp = L_shl_sat( L_tmp, tmp1_fx ); /* Q16 + Q_exc */ - tmp_fx = round_fx_sat(L_tmp); + tmp_fx = round_fx_sat( L_tmp ); exc2_fx[i + i_subfr] = add_sat( exc2_fx[i + i_subfr], tmp_fx ); move16(); exc_fx[i + i_subfr] = add_sat( exc_fx[i + i_subfr], tmp_fx ); move16(); #else L_tmp = L_shl( L_tmp, tmp1_fx ); /* Q16 + Q_exc */ - tmp_fx = round_fx(L_tmp); - exc2_fx[i+i_subfr] = add(exc2_fx[i+i_subfr],tmp_fx); + tmp_fx = round_fx( L_tmp ); + exc2_fx[i + i_subfr] = add( exc2_fx[i + i_subfr], tmp_fx ); move16(); - exc_fx[i+i_subfr] = add(exc_fx[i+i_subfr],tmp_fx); + exc_fx[i + i_subfr] = add( exc_fx[i + i_subfr], tmp_fx ); move16(); #endif - } } @@ -220,29 +222,29 @@ void decod_tran_fx( *-----------------------------------------------------------------*/ prep_tbe_exc_fx( L_frame_fx, i_subfr, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, - &voice_factors_fx[i_subfr/L_SUBFR], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, + &voice_factors_fx[i_subfr / L_SUBFR], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, st_fx->Q_exc, T0, T0_frac, st_fx->coder_type, st_fx->core_brate ); /*----------------------------------------------------------------* * Excitation enhancements (update of total excitation signal) *----------------------------------------------------------------*/ - IF( GT_32(st_fx->core_brate,ACELP_32k)) + IF( GT_32( st_fx->core_brate, ACELP_32k ) ) { - Copy( exc_fx+i_subfr, exc2_fx+i_subfr, L_SUBFR ); + Copy( exc_fx + i_subfr, exc2_fx + i_subfr, L_SUBFR ); } ELSE { enhancer_fx( st_fx->core_brate, 0, st_fx->coder_type, i_subfr, L_frame_fx, voice_fac_fx, st_fx->stab_fac_fx, - norm_gain_code_fx, gain_inov_fx, &st_fx->gc_threshold_fx, code_fx, exc2_fx, gain_pit_fx, &(st_fx->dm_fx), st_fx->Q_exc ); + norm_gain_code_fx, gain_inov_fx, &st_fx->gc_threshold_fx, code_fx, exc2_fx, gain_pit_fx, &( st_fx->dm_fx ), st_fx->Q_exc ); } - p_Aq_fx += (M+1); + p_Aq_fx += ( M + 1 ); move16(); pt_pitch_fx++; - st_fx->tilt_code_dec_fx[i_subfr/L_SUBFR] = st_fx->tilt_code_fx; + st_fx->tilt_code_dec_fx[i_subfr / L_SUBFR] = st_fx->tilt_code_fx; move16(); - gain_buf[i_subfr/L_SUBFR] = gain_pit_fx; + gain_buf[i_subfr / L_SUBFR] = gain_pit_fx; move16(); } diff --git a/lib_dec/dec_uv.c b/lib_dec/dec_uv.c index e9a0823f7..513f32a8d 100644 --- a/lib_dec/dec_uv.c +++ b/lib_dec/dec_uv.c @@ -120,7 +120,7 @@ void decod_unvoiced( *-----------------------------------------------------------------*/ index = get_next_indice( st, st->acelp_cfg.gains_mode[i_subfr / L_SUBFR] ); - gain_dec_gacelp_uv( index, code, code2, Es_pred, L_SUBFR, &gain_pit, &gain_code, &gain_code2, &( st->past_gpit_float), &norm_gain_code, &gain_inov ); + gain_dec_gacelp_uv( index, code, code2, Es_pred, L_SUBFR, &gain_pit, &gain_code, &gain_code2, &( st->past_gpit_float ), &norm_gain_code, &gain_inov ); st->tilt_code = est_tilt( exc + i_subfr, gain_pit, code, gain_code, &voice_fac, L_SUBFR, 0 ); diff --git a/lib_dec/dec_uv_fx.c b/lib_dec/dec_uv_fx.c index cc33c23b0..7439b79d0 100644 --- a/lib_dec/dec_uv_fx.c +++ b/lib_dec/dec_uv_fx.c @@ -2,23 +2,23 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ #ifdef IVAS_FLOAT_FIXED static void gain_dec_gacelp_uv_fx( - Word16 index, /* i : Quantization index vector Q0 */ - Word16 *code, /* i : algebraic code excitation Q9 */ - Word16 *code2, /* i : algebraic code excitation Q9 */ - Word16 mean_ener, /* i : Q8 */ - Word16 lcode, /* i : Subframe size Q0 */ - Word16 *gain_pit, /* o : Quantized pitch gain 1Q14 */ - Word32 *gain_code, /* o : Quantized codebook gain Q16 */ - Word32 *gain_code2, /* o : Quantized codebook gain Q16 */ - Word16 *past_gpit, /* i/o: past gain of pitch 1Q14 */ - Word32 *past_gcode, /* i/o: past energy of code Q16 */ - Word16 *gain_inov /* o : unscaled innovation gain 3Q12 */ + Word16 index, /* i : Quantization index vector Q0 */ + Word16 *code, /* i : algebraic code excitation Q9 */ + Word16 *code2, /* i : algebraic code excitation Q9 */ + Word16 mean_ener, /* i : Q8 */ + Word16 lcode, /* i : Subframe size Q0 */ + Word16 *gain_pit, /* o : Quantized pitch gain 1Q14 */ + Word32 *gain_code, /* o : Quantized codebook gain Q16 */ + Word32 *gain_code2, /* o : Quantized codebook gain Q16 */ + Word16 *past_gpit, /* i/o: past gain of pitch 1Q14 */ + Word32 *past_gcode, /* i/o: past energy of code Q16 */ + Word16 *gain_inov /* o : unscaled innovation gain 3Q12 */ ); /*-------------------------------------------------------------------* @@ -28,67 +28,66 @@ static void gain_dec_gacelp_uv_fx( *-------------------------------------------------------------------*/ void decod_unvoiced_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - const Word16 *Aq_fx, /* Q12 i : LP filter coefficient */ - const Word16 coder_type, /* Q0 i : coding type */ - Word16 *tmp_noise_fx, /* Q0 o : long term temporary noise energy */ - Word16 *pitch_buf_fx, /* Q6 o : floating pitch values for each subframe*/ - Word16 *voice_factors_fx, /* Q15 o : voicing factors */ - Word16 *exc_fx, /* Q_X o : adapt. excitation exc */ - Word16 *exc2_fx, /* Q_X o : adapt. excitation/total exc */ - Word16 *bwe_exc_fx, /* Q_X i/o: excitation for SWB TBE */ - Word16 *gain_buf -) + Decoder_State *st_fx, /* i/o: decoder static memory */ + const Word16 *Aq_fx, /* Q12 i : LP filter coefficient */ + const Word16 coder_type, /* Q0 i : coding type */ + Word16 *tmp_noise_fx, /* Q0 o : long term temporary noise energy */ + Word16 *pitch_buf_fx, /* Q6 o : floating pitch values for each subframe*/ + Word16 *voice_factors_fx, /* Q15 o : voicing factors */ + Word16 *exc_fx, /* Q_X o : adapt. excitation exc */ + Word16 *exc2_fx, /* Q_X o : adapt. excitation/total exc */ + Word16 *bwe_exc_fx, /* Q_X i/o: excitation for SWB TBE */ + Word16 *gain_buf ) { - Word16 gain_pit_fx = 0; /* Quantized pitch gain */ - Word32 gain_code_fx; /* Quantized algebraic codeebook gain */ - Word16 gain_inov_fx; /* inovation gain */ - Word32 norm_gain_code_fx; /* normalized algebraic codeebook gain */ - Word16 voice_fac_fx; /* Voicing factor */ - Word16 code_fx[L_SUBFR]; /* algebraic codevector */ + Word16 gain_pit_fx = 0; /* Quantized pitch gain */ + Word32 gain_code_fx; /* Quantized algebraic codeebook gain */ + Word16 gain_inov_fx; /* inovation gain */ + Word32 norm_gain_code_fx; /* normalized algebraic codeebook gain */ + Word16 voice_fac_fx; /* Voicing factor */ + Word16 code_fx[L_SUBFR]; /* algebraic codevector */ Word16 i_subfr_fx; const Word16 *p_Aq_fx; Word16 *pt_pitch_fx; test(); - IF ( EQ_16(st_fx->last_ppp_mode_dec,1)||EQ_16(st_fx->last_nelp_mode_dec,1)) + IF( EQ_16( st_fx->last_ppp_mode_dec, 1 ) || EQ_16( st_fx->last_nelp_mode_dec, 1 ) ) { /* SC_VBR - reset the decoder, to avoid memory not updated issue for this unrealistic case */ CNG_reset_dec_fx( st_fx, pitch_buf_fx, voice_factors_fx ); } p_Aq_fx = Aq_fx; - move16(); /*Q12*/ /* pointer to interpolated LPC parameters */ + move16(); /*Q12*/ /* pointer to interpolated LPC parameters */ pt_pitch_fx = pitch_buf_fx; - move16(); /* pointer to the pitch buffer */ + move16(); /* pointer to the pitch buffer */ - FOR( i_subfr_fx=0; i_subfr_fxlp_gainp_fx, &st_fx->lp_gainc_fx, &gain_inov_fx, &st_fx->tilt_code_fx, - &voice_fac_fx, &gain_pit_fx, pt_pitch_fx, exc_fx, &gain_code_fx, exc2_fx, bwe_exc_fx,&(st_fx->Q_exc),st_fx->Q_subfr ); + gaus_dec_fx( st_fx, i_subfr_fx, code_fx, &norm_gain_code_fx, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, &gain_inov_fx, &st_fx->tilt_code_fx, + &voice_fac_fx, &gain_pit_fx, pt_pitch_fx, exc_fx, &gain_code_fx, exc2_fx, bwe_exc_fx, &( st_fx->Q_exc ), st_fx->Q_subfr ); - *tmp_noise_fx = extract_h(norm_gain_code_fx); /*Q16*/ + *tmp_noise_fx = extract_h( norm_gain_code_fx ); /*Q16*/ /*----------------------------------------------------------------* * Excitation enhancements (update of total excitation signal) *----------------------------------------------------------------*/ enhancer_fx( st_fx->core_brate, 0, coder_type, i_subfr_fx, L_FRAME, voice_fac_fx, st_fx->stab_fac_fx, - norm_gain_code_fx, gain_inov_fx, &st_fx->gc_threshold_fx, code_fx, exc2_fx, gain_pit_fx, &(st_fx->dm_fx), st_fx->Q_exc ); + norm_gain_code_fx, gain_inov_fx, &st_fx->gc_threshold_fx, code_fx, exc2_fx, gain_pit_fx, &( st_fx->dm_fx ), st_fx->Q_exc ); - voice_factors_fx[i_subfr_fx/L_SUBFR] = 0; + voice_factors_fx[i_subfr_fx / L_SUBFR] = 0; move16(); interp_code_5over2_fx( &exc_fx[i_subfr_fx], &bwe_exc_fx[i_subfr_fx * HIBND_ACB_L_FAC], L_SUBFR ); - p_Aq_fx += (M+1); + p_Aq_fx += ( M + 1 ); move16(); pt_pitch_fx++; - st_fx->tilt_code_dec_fx[i_subfr_fx/L_SUBFR] = st_fx->tilt_code_fx; + st_fx->tilt_code_dec_fx[i_subfr_fx / L_SUBFR] = st_fx->tilt_code_fx; move16(); } @@ -108,119 +107,121 @@ void decod_unvoiced_fx( *-------------------------------------------------------------------*/ void decod_unvoiced_ivas_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - const Word16 *Aq_fx, /* Q12 i : LP filter coefficient */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ + Decoder_State *st_fx, /* i/o: decoder static memory */ + const Word16 *Aq_fx, /* Q12 i : LP filter coefficient */ + const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ const int16_t uc_two_stage_flag, /* i : flag indicating two-stage UC */ - const Word16 coder_type, /* Q0 i : coding type */ - Word16 *tmp_noise_fx, /* Q0 o : long term temporary noise energy */ - Word16 *pitch_buf_fx, /* Q6 o : floating pitch values for each subframe*/ - Word16 *voice_factors_fx, /* Q15 o : voicing factors */ - Word16 *exc_fx, /* Q_X o : adapt. excitation exc */ - Word16 *exc2_fx, /* Q_X o : adapt. excitation/total exc */ - Word16 *bwe_exc_fx, /* Q_X i/o: excitation for SWB TBE */ - Word16 *gain_buf -) + const Word16 coder_type, /* Q0 i : coding type */ + Word16 *tmp_noise_fx, /* Q0 o : long term temporary noise energy */ + Word16 *pitch_buf_fx, /* Q6 o : floating pitch values for each subframe*/ + Word16 *voice_factors_fx, /* Q15 o : voicing factors */ + Word16 *exc_fx, /* Q_X o : adapt. excitation exc */ + Word16 *exc2_fx, /* Q_X o : adapt. excitation/total exc */ + Word16 *bwe_exc_fx, /* Q_X i/o: excitation for SWB TBE */ + Word16 *gain_buf ) { - Word16 gain_pit_fx = 0; /* Quantized pitch gain */ - Word32 gain_code_fx; /* Quantized algebraic codeebook gain */ + Word16 gain_pit_fx = 0; /* Quantized pitch gain */ + Word32 gain_code_fx; /* Quantized algebraic codeebook gain */ Word32 gain_code2_fx; - Word16 gain_inov_fx; /* inovation gain */ - Word32 norm_gain_code_fx; /* normalized algebraic codeebook gain */ - Word16 voice_fac_fx; /* Voicing factor */ - Word16 code_fx[L_SUBFR]; /* algebraic codevector */ + Word16 gain_inov_fx; /* inovation gain */ + Word32 norm_gain_code_fx; /* normalized algebraic codeebook gain */ + Word16 voice_fac_fx; /* Voicing factor */ + Word16 code_fx[L_SUBFR]; /* algebraic codevector */ Word16 i_subfr_fx; const Word16 *p_Aq_fx; Word16 *pt_pitch_fx; Word16 code2_fx[L_SUBFR]; test(); - IF(EQ_16(st_fx->last_ppp_mode_dec, 1) || EQ_16(st_fx->last_nelp_mode_dec, 1)) + IF( EQ_16( st_fx->last_ppp_mode_dec, 1 ) || EQ_16( st_fx->last_nelp_mode_dec, 1 ) ) { /* SC_VBR - reset the decoder, to avoid memory not updated issue for this unrealistic case */ - CNG_reset_dec_fx(st_fx, pitch_buf_fx, voice_factors_fx); + CNG_reset_dec_fx( st_fx, pitch_buf_fx, voice_factors_fx ); } p_Aq_fx = Aq_fx; - move16(); /*Q12*/ /* pointer to interpolated LPC parameters */ + move16(); /*Q12*/ /* pointer to interpolated LPC parameters */ pt_pitch_fx = pitch_buf_fx; - move16(); /* pointer to the pitch buffer */ + move16(); /* pointer to the pitch buffer */ - FOR(i_subfr_fx = 0; i_subfr_fx < L_FRAME; i_subfr_fx += L_SUBFR) + FOR( i_subfr_fx = 0; i_subfr_fx < L_FRAME; i_subfr_fx += L_SUBFR ) { - if (!uc_two_stage_flag) { + if ( !uc_two_stage_flag ) + { /*----------------------------------------------------------------* * Unvoiced subframe processing *----------------------------------------------------------------*/ - gaus_dec_fx(st_fx, i_subfr_fx, code_fx, &norm_gain_code_fx, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, &gain_inov_fx, &st_fx->tilt_code_fx, - &voice_fac_fx, &gain_pit_fx, pt_pitch_fx, exc_fx, &gain_code_fx, exc2_fx, bwe_exc_fx, &(st_fx->Q_exc), st_fx->Q_subfr); + gaus_dec_fx( st_fx, i_subfr_fx, code_fx, &norm_gain_code_fx, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, &gain_inov_fx, &st_fx->tilt_code_fx, + &voice_fac_fx, &gain_pit_fx, pt_pitch_fx, exc_fx, &gain_code_fx, exc2_fx, bwe_exc_fx, &( st_fx->Q_exc ), st_fx->Q_subfr ); } - else {/*----------------------------------------------------------------* - * Unvoiced subframe processing in two stages - *----------------------------------------------------------------*/ + else + { /*----------------------------------------------------------------* + * Unvoiced subframe processing in two stages + *----------------------------------------------------------------*/ /* No adaptive codebook (UC) */ - set16_fx(exc_fx + i_subfr_fx, 0, L_SUBFR); + set16_fx( exc_fx + i_subfr_fx, 0, L_SUBFR ); - *pt_pitch_fx = shl(L_SUBFR, Q6); + *pt_pitch_fx = shl( L_SUBFR, Q6 ); /*--------------------------------------------------------------* * Innovation decoding *--------------------------------------------------------------*/ - //inov_decode(st, st->core_brate, 0, L_FRAME, 1, i_subfr, p_Aq, st->tilt_code, *pt_pitch, code, L_SUBFR); - inov_decode_fx(st_fx, st_fx->core_brate, 0, L_FRAME, 1, i_subfr_fx, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_SUBFR); + // inov_decode(st, st->core_brate, 0, L_FRAME, 1, i_subfr, p_Aq, st->tilt_code, *pt_pitch, code, L_SUBFR); + inov_decode_fx( st_fx, st_fx->core_brate, 0, L_FRAME, 1, i_subfr_fx, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_SUBFR ); /*-------------------------------------------------------* * Generate Gaussian excitation * *-------------------------------------------------------*/ - //gaus_L2_dec_flt(code2, st->tilt_code, p_Aq, FORMANT_SHARPENING_G1_FLT, &(st->seed_acelp)); - gaus_L2_dec(code2_fx, st_fx->tilt_code_fx, p_Aq_fx, FORMANT_SHARPENING_G1, &(st_fx->seed_acelp)); + // gaus_L2_dec_flt(code2, st->tilt_code, p_Aq, FORMANT_SHARPENING_G1_FLT, &(st->seed_acelp)); + gaus_L2_dec( code2_fx, st_fx->tilt_code_fx, p_Aq_fx, FORMANT_SHARPENING_G1, &( st_fx->seed_acelp ) ); /*-----------------------------------------------------------------* * Gain encoding *-----------------------------------------------------------------*/ - Word16 index = get_next_indice(st_fx, st_fx->acelp_cfg.gains_mode[i_subfr_fx / L_SUBFR]); - //gain_dec_gacelp_uv(index, code, code2, Es_pred, L_SUBFR, &gain_pit, &gain_code, &gain_code2, &(st->past_gpit_float), &norm_gain_code, &gain_inov); - gain_dec_gacelp_uv_fx(index, code_fx, code2_fx, Es_pred_fx, L_SUBFR, &gain_pit_fx, &gain_code_fx, &gain_code2_fx, &(st_fx->past_gpit), &norm_gain_code_fx, &gain_inov_fx); + Word16 index = get_next_indice( st_fx, st_fx->acelp_cfg.gains_mode[i_subfr_fx / L_SUBFR] ); + // gain_dec_gacelp_uv(index, code, code2, Es_pred, L_SUBFR, &gain_pit, &gain_code, &gain_code2, &(st->past_gpit_float), &norm_gain_code, &gain_inov); + gain_dec_gacelp_uv_fx( index, code_fx, code2_fx, Es_pred_fx, L_SUBFR, &gain_pit_fx, &gain_code_fx, &gain_code2_fx, &( st_fx->past_gpit ), &norm_gain_code_fx, &gain_inov_fx ); - //st->tilt_code = est_tilt(exc + i_subfr, gain_pit, code, gain_code, &voice_fac, L_SUBFR, 0); - st_fx->tilt_code_fx = est_tilt_ivas_fx(exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, st_fx->Q_exc, L_SUBFR, 0); + // st->tilt_code = est_tilt(exc + i_subfr, gain_pit, code, gain_code, &voice_fac, L_SUBFR, 0); + st_fx->tilt_code_fx = est_tilt_ivas_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, st_fx->Q_exc, L_SUBFR, 0 ); /* update LP filtered gains for the case of frame erasures */ - //lp_gain_updt(i_subfr, gain_pit, norm_gain_code, &st->lp_gainp, &st->lp_gainc, L_FRAME); - lp_gain_updt_fx(i_subfr_fx, gain_pit_fx, norm_gain_code_fx, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_FRAME); + // lp_gain_updt(i_subfr, gain_pit, norm_gain_code, &st->lp_gainp, &st->lp_gainc, L_FRAME); + lp_gain_updt_fx( i_subfr_fx, gain_pit_fx, norm_gain_code_fx, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_FRAME ); /*-------------------------------------------------------* * - Find the total excitation. * *-------------------------------------------------------*/ - IF(EQ_16(st_fx->L_frame, L_FRAME)) + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { - Rescale_exc(st_fx->hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], (bwe_exc_fx != NULL) ? &bwe_exc_fx[i_subfr_fx * HIBND_ACB_L_FAC] : NULL, st_fx->hGSCDec->last_exc_dct_in_fx, - L_SUBFR, L_SUBFR* HIBND_ACB_L_FAC, L_max(gain_code2_fx, gain_code_fx), &(st_fx->Q_exc), st_fx->Q_subfr, exc2_fx, i_subfr_fx, UNVOICED); + Rescale_exc( st_fx->hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], ( bwe_exc_fx != NULL ) ? &bwe_exc_fx[i_subfr_fx * HIBND_ACB_L_FAC] : NULL, st_fx->hGSCDec->last_exc_dct_in_fx, + L_SUBFR, L_SUBFR * HIBND_ACB_L_FAC, L_max( gain_code2_fx, gain_code_fx ), &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr_fx, UNVOICED ); } ELSE { - Rescale_exc(st_fx->hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], (bwe_exc_fx != NULL) ? &bwe_exc_fx[i_subfr_fx * 2] : NULL, st_fx->hGSCDec->last_exc_dct_in_fx, - L_SUBFR, L_SUBFR * 2, L_max(gain_code2_fx, gain_code_fx), &(st_fx->Q_exc), st_fx->Q_subfr, exc2_fx, i_subfr_fx, UNVOICED); + Rescale_exc( st_fx->hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], ( bwe_exc_fx != NULL ) ? &bwe_exc_fx[i_subfr_fx * 2] : NULL, st_fx->hGSCDec->last_exc_dct_in_fx, + L_SUBFR, L_SUBFR * 2, L_max( gain_code2_fx, gain_code_fx ), &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr_fx, UNVOICED ); } - for (int i = 0; i < L_SUBFR; i++) + for ( int i = 0; i < L_SUBFR; i++ ) { /*exc2[i + i_subfr] = gain_pit * exc[i + i_subfr]; //Q14 exc2[i + i_subfr] += gain_code2 * code2[i]; //Q16 - exc[i + i_subfr] = exc2[i + i_subfr] + gain_code * code[i];*/ //Q16 - exc2_fx[i + i_subfr_fx] = shl( mult_r( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 2 ); // Q_exc - exc2_fx[i + i_subfr_fx] = add( exc2_fx[i + i_subfr_fx], extract_l( L_shr( Mpy_32_16_1( gain_code2_fx, code2_fx[i] ), Q10 - st_fx->Q_exc) ) ); // Q_exc - exc_fx[i + i_subfr_fx] = add( exc2_fx[i + i_subfr_fx], extract_l( L_shr( Mpy_32_16_1( gain_code_fx, code_fx[i] ), Q10 - st_fx->Q_exc) ) ); // Q_exc + exc[i + i_subfr] = exc2[i + i_subfr] + gain_code * code[i];*/ + // Q16 + exc2_fx[i + i_subfr_fx] = shl( mult_r( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 2 ); // Q_exc + exc2_fx[i + i_subfr_fx] = add( exc2_fx[i + i_subfr_fx], extract_l( L_shr( Mpy_32_16_1( gain_code2_fx, code2_fx[i] ), Q10 - st_fx->Q_exc ) ) ); // Q_exc + exc_fx[i + i_subfr_fx] = add( exc2_fx[i + i_subfr_fx], extract_l( L_shr( Mpy_32_16_1( gain_code_fx, code_fx[i] ), Q10 - st_fx->Q_exc ) ) ); // Q_exc } - //Scale_sig(code_fx, L_SUBFR, 3); //Q12 + // Scale_sig(code_fx, L_SUBFR, 3); //Q12 } - *tmp_noise_fx = extract_h(norm_gain_code_fx); /*Q16*/ + *tmp_noise_fx = extract_h( norm_gain_code_fx ); /*Q16*/ /*----------------------------------------------------------------* * Excitation enhancements (update of total excitation signal) @@ -228,15 +229,15 @@ void decod_unvoiced_ivas_fx( /*enhancer_fx(st_fx->core_brate, 0, coder_type, i_subfr_fx, L_FRAME, voice_fac_fx, st_fx->stab_fac_fx, norm_gain_code_fx, gain_inov_fx, &st_fx->gc_threshold_fx, code_fx, exc2_fx, gain_pit_fx, &(st_fx->dm_fx), st_fx->Q_exc);*/ - enhancer_ivas_fx(MODE1, st_fx->core_brate, uc_two_stage_flag, 0, coder_type, i_subfr_fx, L_FRAME, voice_fac_fx, st_fx->stab_fac_fx, - norm_gain_code_fx, gain_inov_fx, &st_fx->gc_threshold_fx, code_fx/*Q9/Q12?*/, exc2_fx, gain_pit_fx, &(st_fx->dm_fx), st_fx->Q_exc); + enhancer_ivas_fx( MODE1, st_fx->core_brate, uc_two_stage_flag, 0, coder_type, i_subfr_fx, L_FRAME, voice_fac_fx, st_fx->stab_fac_fx, + norm_gain_code_fx, gain_inov_fx, &st_fx->gc_threshold_fx, code_fx /*Q9/Q12?*/, exc2_fx, gain_pit_fx, &( st_fx->dm_fx ), st_fx->Q_exc ); voice_factors_fx[i_subfr_fx / L_SUBFR] = 0; move16(); - interp_code_5over2_fx(&exc_fx[i_subfr_fx], &bwe_exc_fx[i_subfr_fx * HIBND_ACB_L_FAC], L_SUBFR); + interp_code_5over2_fx( &exc_fx[i_subfr_fx], &bwe_exc_fx[i_subfr_fx * HIBND_ACB_L_FAC], L_SUBFR ); - p_Aq_fx += (M + 1); + p_Aq_fx += ( M + 1 ); move16(); pt_pitch_fx++; st_fx->tilt_code_dec_fx[i_subfr_fx / L_SUBFR] = st_fx->tilt_code_fx; @@ -247,7 +248,7 @@ void decod_unvoiced_ivas_fx( st_fx->prev_gain_pit_dec_fx = gain_pit_fx; move16(); - set16_fx(gain_buf, 0, NB_SUBFR); + set16_fx( gain_buf, 0, NB_SUBFR ); return; } @@ -260,17 +261,17 @@ void decod_unvoiced_ivas_fx( *---------------------------------------------------------------------*/ static void gain_dec_gacelp_uv_fx( - Word16 index, /* i : Quantization index vector Q0 */ - Word16 *code, /* i : algebraic code excitation Q9 */ - Word16 *code2, /* i : algebraic code excitation Q9 */ - Word16 mean_ener, /* i : Q8 */ - Word16 lcode, /* i : Subframe size Q0 */ - Word16 *gain_pit, /* o : Quantized pitch gain 1Q14 */ - Word32 *gain_code, /* o : Quantized codebook gain Q16 */ - Word32 *gain_code2, /* o : Quantized codebook gain Q16 */ - Word16 *past_gpit, /* i/o: past gain of pitch 1Q14 */ - Word32 *past_gcode, /* i/o: past energy of code Q16 */ - Word16 *gain_inov /* o : unscaled innovation gain 3Q12 */ + Word16 index, /* i : Quantization index vector Q0 */ + Word16 *code, /* i : algebraic code excitation Q9 */ + Word16 *code2, /* i : algebraic code excitation Q9 */ + Word16 mean_ener, /* i : Q8 */ + Word16 lcode, /* i : Subframe size Q0 */ + Word16 *gain_pit, /* o : Quantized pitch gain 1Q14 */ + Word32 *gain_code, /* o : Quantized codebook gain Q16 */ + Word32 *gain_code2, /* o : Quantized codebook gain Q16 */ + Word16 *past_gpit, /* i/o: past gain of pitch 1Q14 */ + Word32 *past_gcode, /* i/o: past energy of code Q16 */ + Word16 *gain_inov /* o : unscaled innovation gain 3Q12 */ ) { Word16 i, exp_L_tmp1; @@ -282,33 +283,31 @@ static void gain_dec_gacelp_uv_fx( Word16 index2, s; - - /* pred_nrg_frame = (float)pow(10.0,mean_ener/20.0); */ - L_tmp = L_mult(mean_ener, 10885/*0.166096f * 2 Q15*/); /* 6Q25 */ - pred_nrg_frame = BASOP_Util_InvLog2(L_sub(L_tmp, 503316480l/*15.f Q25*/)); /* 15Q16 */ + L_tmp = L_mult( mean_ener, 10885 /*0.166096f * 2 Q15*/ ); /* 6Q25 */ + pred_nrg_frame = BASOP_Util_InvLog2( L_sub( L_tmp, 503316480l /*15.f Q25*/ ) ); /* 15Q16 */ /*-----------------------------------------------------------------* * Prediction gains *-----------------------------------------------------------------*/ - /* gain_inov = 1.0f / sqrt((dot_product(code, code, L_SUBFR) + 0.01) / L_SUBFR) */ - L_tmp = calc_gain_inov(code, lcode, NULL, NULL); - *gain_inov = round_fx(L_shl(L_tmp, 15 - 3)); /* gain_inov in Q12 */ + /* gain_inov = 1.0f / sqrt((dot_product(code, code, L_SUBFR) + 0.01) / L_SUBFR) */ + L_tmp = calc_gain_inov( code, lcode, NULL, NULL ); + *gain_inov = round_fx( L_shl( L_tmp, 15 - 3 ) ); /* gain_inov in Q12 */ /* gcode = pred_nrg_frame * (*gain_inov); */ - L_tmp = Mpy_32_16_1(pred_nrg_frame, *gain_inov); /* 18Q13 */ - i = sub(norm_l(L_tmp),1); //gaurd-bits - g_code = round_fx(L_shl(L_tmp, i)); - exp_gcode = sub(18, i); + L_tmp = Mpy_32_16_1( pred_nrg_frame, *gain_inov ); /* 18Q13 */ + i = sub( norm_l( L_tmp ), 1 ); // gaurd-bits + g_code = round_fx( L_shl( L_tmp, i ) ); + exp_gcode = sub( 18, i ); /* norm_code2 = 1.0f / sqrt((dot_product(code2, code2, lcode) + 0.01f) / lcode); */ - L_tmp = calc_gain_inov(code2, lcode, NULL, NULL); - norm_code2 = round_fx(L_shl(L_tmp, 15 - 3)); /* Q12 */ + L_tmp = calc_gain_inov( code2, lcode, NULL, NULL ); + norm_code2 = round_fx( L_shl( L_tmp, 15 - 3 ) ); /* Q12 */ /* g_code2 = pred_nrg_frame * norm_code2; */ - L_tmp = Mpy_32_16_1(pred_nrg_frame, norm_code2); /* 18Q13 */ - i = norm_l(L_tmp); - g_code2 = round_fx(L_shl(L_tmp, i)); - exp_gcode2 = sub(18, i); + L_tmp = Mpy_32_16_1( pred_nrg_frame, norm_code2 ); /* 18Q13 */ + i = norm_l( L_tmp ); + g_code2 = round_fx( L_shl( L_tmp, i ) ); + exp_gcode2 = sub( 18, i ); /*-----------------------------------------------------------------* * Decode pitch gain @@ -321,41 +320,42 @@ static void gain_dec_gacelp_uv_fx( /*-----------------------------------------------------------------* * past gains for error concealment *-----------------------------------------------------------------*/ - index2 = shr(index, 5); - index = s_and(index, 0x1F); + index2 = shr( index, 5 ); + index = s_and( index, 0x1F ); /**gain_code= (float)pow(10.f,(((index*1.25f)-20.f)/20.f))*gcode;*/ - L_tmp = L_mac(-111465139l/*-0.166096*20.0f Q25*/, shl(index, 16 - 7), 6803/*0.166096f*1.25f Q15*/); + L_tmp = L_mac( -111465139l /*-0.166096*20.0f Q25*/, shl( index, 16 - 7 ), 6803 /*0.166096f*1.25f Q15*/ ); - i = add(1, extract_l(L_shr(L_tmp, 25))); - L_tmp = L_lshl(L_tmp, 6); - L_tmp = L_and(0x7FFFFFFF, L_tmp); + i = add( 1, extract_l( L_shr( L_tmp, 25 ) ) ); + L_tmp = L_lshl( L_tmp, 6 ); + L_tmp = L_and( 0x7FFFFFFF, L_tmp ); - L_tmp = Pow2(30, round_fx(L_tmp)); - L_tmp = L_shl(L_tmp, i - (31 - 16)); /* Q16 */ + L_tmp = Pow2( 30, round_fx( L_tmp ) ); + L_tmp = L_shl( L_tmp, i - ( 31 - 16 ) ); /* Q16 */ /* *past_gcode = L_tmp * pred_nrg_frame; */ - i = norm_l(L_tmp); - L_tmp1 = L_shl(L_tmp, i); - exp_L_tmp1 = sub(15, i); + i = norm_l( L_tmp ); + L_tmp1 = L_shl( L_tmp, i ); + exp_L_tmp1 = sub( 15, i ); - i = norm_l(pred_nrg_frame); - L_tmp1 = Mpy_32_32(L_tmp1, L_shl(pred_nrg_frame, i)); - exp_L_tmp1 = add(exp_L_tmp1, sub(15, i)); + i = norm_l( pred_nrg_frame ); + L_tmp1 = Mpy_32_32( L_tmp1, L_shl( pred_nrg_frame, i ) ); + exp_L_tmp1 = add( exp_L_tmp1, sub( 15, i ) ); - *past_gcode = L_shl(L_tmp1, sub(exp_L_tmp1, 15)); /* Q16 */ move32(); + *past_gcode = L_shl( L_tmp1, sub( exp_L_tmp1, 15 ) ); /* Q16 */ + move32(); - *gain_code = L_shl(Mpy_32_16_1(*past_gcode, *gain_inov), 3); + *gain_code = L_shl( Mpy_32_16_1( *past_gcode, *gain_inov ), 3 ); move32(); - L_tmp = Mpy_32_16_1(*gain_code, BASOP_Util_Divide1616_Scale(g_code2, g_code, &s)); - L_tmp = L_shl(L_tmp, sub(sub(add(s, exp_gcode2), exp_gcode), 2)); /* Q16 */ - L_tmp1 = L_add(L_tmp, 0); - FOR(i = 0; i < index2; i++) + L_tmp = Mpy_32_16_1( *gain_code, BASOP_Util_Divide1616_Scale( g_code2, g_code, &s ) ); + L_tmp = L_shl( L_tmp, sub( sub( add( s, exp_gcode2 ), exp_gcode ), 2 ) ); /* Q16 */ + L_tmp1 = L_add( L_tmp, 0 ); + FOR( i = 0; i < index2; i++ ) { - L_tmp1 = L_add(L_tmp1, L_tmp); + L_tmp1 = L_add( L_tmp1, L_tmp ); } *gain_code2 = L_tmp1; diff --git a/lib_dec/decision_matrix_dec.c b/lib_dec/decision_matrix_dec.c index 8f540d8fa..97a4e6f59 100644 --- a/lib_dec/decision_matrix_dec.c +++ b/lib_dec/decision_matrix_dec.c @@ -567,4 +567,4 @@ void decision_matrix_dec( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/decision_matrix_dec_fx.c b/lib_dec/decision_matrix_dec_fx.c index bb2a0546e..a2b1108a8 100644 --- a/lib_dec/decision_matrix_dec_fx.c +++ b/lib_dec/decision_matrix_dec_fx.c @@ -20,10 +20,10 @@ *-----------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED void decision_matrix_dec_fx( - Decoder_State *st, /* i/o: decoder state structure */ - Word16 *sharpFlag, /* o : formant sharpening flag */ - Word16 *hq_core_type, /* o : HQ core type */ - Word16 *core_switching_flag/* o : ACELP->HQ switching frame flag */ + Decoder_State *st, /* i/o: decoder state structure */ + Word16 *sharpFlag, /* o : formant sharpening flag */ + Word16 *hq_core_type, /* o : HQ core type */ + Word16 *core_switching_flag /* o : ACELP->HQ switching frame flag */ ) { Word16 start_idx; @@ -35,7 +35,7 @@ void decision_matrix_dec_fx( /* init */ st->core = -1; move16(); - st->core_brate = L_deposit_l(0); + st->core_brate = L_deposit_l( 0 ); st->extl = -1; move16(); st->extl_brate = 0; @@ -47,13 +47,13 @@ void decision_matrix_dec_fx( st->igf = 0; move16(); - if( GT_32(st->total_brate,ACELP_8k00)) + if ( GT_32( st->total_brate, ACELP_8k00 ) ) { st->vbr_hw_BWE_disable_dec = 0; move16(); } - IF (EQ_16(st->mdct_sw, MODE2)) + IF( EQ_16( st->mdct_sw, MODE2 ) ) { st->core = HQ_CORE; move16(); @@ -61,24 +61,24 @@ void decision_matrix_dec_fx( ELSE { test(); - IF( EQ_32(st->total_brate,FRAME_NO_DATA)||EQ_32(st->total_brate,SID_2k40)) + IF( EQ_32( st->total_brate, FRAME_NO_DATA ) || EQ_32( st->total_brate, SID_2k40 ) ) { st->core = ACELP_CORE; move16(); st->core_brate = st->total_brate; move32(); - IF( NE_32(st->total_brate,FRAME_NO_DATA)) + IF( NE_32( st->total_brate, FRAME_NO_DATA ) ) { st->cng_type = get_next_indice( st, 1 ); - IF( EQ_16(st->cng_type,LP_CNG)) + IF( EQ_16( st->cng_type, LP_CNG ) ) { st->L_frame = L_FRAME; move16(); tmp16 = get_next_indice( st, 1 ); - if( EQ_16(tmp16,1)) + if ( EQ_16( tmp16, 1 ) ) { st->L_frame = L_FRAME16k; move16(); @@ -86,14 +86,14 @@ void decision_matrix_dec_fx( } ELSE { - st->bwidth = get_next_indice(st, 2); + st->bwidth = get_next_indice( st, 2 ); - tmp16 = get_next_indice(st, 1); + tmp16 = get_next_indice( st, 1 ); move16(); st->L_frame = L_FRAME16k; move16(); - if( tmp16 == 0 ) + if ( tmp16 == 0 ) { st->L_frame = L_FRAME; move16(); @@ -102,7 +102,7 @@ void decision_matrix_dec_fx( } test(); - if( GE_32(st->output_Fs,32000)&&GE_16(st->bwidth,SWB)) + if ( GE_32( st->output_Fs, 32000 ) && GE_16( st->bwidth, SWB ) ) { st->extl = SWB_CNG; move16(); @@ -111,7 +111,7 @@ void decision_matrix_dec_fx( test(); test(); test(); - if( EQ_32(st->total_brate,FRAME_NO_DATA)&&st->prev_bfi&&!st->bfi&>_16(st->L_frame,L_FRAME16k)) + if ( EQ_32( st->total_brate, FRAME_NO_DATA ) && st->prev_bfi && !st->bfi && GT_16( st->L_frame, L_FRAME16k ) ) { st->L_frame = st->last_CNG_L_frame; move16(); @@ -121,7 +121,7 @@ void decision_matrix_dec_fx( } /* SC-VBR */ - ELSE IF( EQ_32(st->total_brate,PPP_NELP_2k80)) + ELSE IF( EQ_32( st->total_brate, PPP_NELP_2k80 ) ) { st->core = ACELP_CORE; move16(); @@ -129,10 +129,10 @@ void decision_matrix_dec_fx( move32(); st->L_frame = L_FRAME; move16(); - st->fscale = sr2fscale_fx(INT_FS_FX); + st->fscale = sr2fscale_fx( INT_FS_FX ); move16(); - IF ( st->ini_frame == 0 ) + IF( st->ini_frame == 0 ) { /* avoid switching of internal ACELP Fs in the very first frame */ st->last_L_frame = st->L_frame; @@ -157,7 +157,7 @@ void decision_matrix_dec_fx( st->bwidth = NB; move16(); } - ELSE IF( EQ_16(ppp_nelp_mode,1)) + ELSE IF( EQ_16( ppp_nelp_mode, 1 ) ) { st->ppp_mode_dec = 1; move16(); @@ -166,7 +166,7 @@ void decision_matrix_dec_fx( st->bwidth = WB; move16(); } - ELSE IF( EQ_16(ppp_nelp_mode,2)) + ELSE IF( EQ_16( ppp_nelp_mode, 2 ) ) { st->nelp_mode_dec = 1; move16(); @@ -175,7 +175,7 @@ void decision_matrix_dec_fx( st->bwidth = NB; move16(); } - ELSE IF( EQ_16(ppp_nelp_mode,3)) + ELSE IF( EQ_16( ppp_nelp_mode, 3 ) ) { st->nelp_mode_dec = 1; move16(); @@ -194,19 +194,19 @@ void decision_matrix_dec_fx( *---------------------------------------------------------------------*/ test(); - IF( LT_32(st->total_brate,ACELP_24k40)) + IF( LT_32( st->total_brate, ACELP_24k40 ) ) { st->core = ACELP_CORE; move16(); } - ELSE IF( GE_32(st->total_brate,ACELP_24k40)&&LE_32(st->total_brate,ACELP_64k)) + ELSE IF( GE_32( st->total_brate, ACELP_24k40 ) && LE_32( st->total_brate, ACELP_64k ) ) { /* read the ACELP/HQ core selection bit */ temp_core = get_next_indice( st, 1 ); st->core = HQ_CORE; move16(); - if( temp_core == 0 ) + if ( temp_core == 0 ) { st->core = ACELP_CORE; move16(); @@ -218,15 +218,15 @@ void decision_matrix_dec_fx( * Read ACELP signaling bits from the bitstream *-----------------------------------------------------------------*/ - IF( EQ_16(st->core,ACELP_CORE)) + IF( EQ_16( st->core, ACELP_CORE ) ) { /* find the section in the ACELP signaling table corresponding to bitrate */ start_idx = 0; move16(); - WHILE( NE_32(acelp_sig_tbl[start_idx],st->total_brate)) + WHILE( NE_32( acelp_sig_tbl[start_idx], st->total_brate ) ) { - start_idx = add(start_idx,1); - IF( GE_16(start_idx,MAX_ACELP_SIG)) + start_idx = add( start_idx, 1 ); + IF( GE_16( start_idx, MAX_ACELP_SIG ) ) { st->BER_detect = 1; move16(); @@ -237,13 +237,13 @@ void decision_matrix_dec_fx( } /* skip the bitrate */ - start_idx = add(start_idx,1); + start_idx = add( start_idx, 1 ); /* retrieve the number of bits */ - nBits = extract_l(acelp_sig_tbl[start_idx]); - start_idx = add(start_idx,1); + nBits = extract_l( acelp_sig_tbl[start_idx] ); + start_idx = add( start_idx, 1 ); - start_idx = add(start_idx,get_next_indice( st, nBits )); + start_idx = add( start_idx, get_next_indice( st, nBits ) ); IF( start_idx >= MAX_ACELP_SIG ) { ind = 0; @@ -257,18 +257,17 @@ void decision_matrix_dec_fx( ind = acelp_sig_tbl[start_idx]; /* convert signaling indice into signaling information */ - st->coder_type = extract_l(L_and(ind,0x7L)); - IF(EQ_16(st->coder_type, LR_MDCT)) + st->coder_type = extract_l( L_and( ind, 0x7L ) ); + IF( EQ_16( st->coder_type, LR_MDCT ) ) { st->core = HQ_CORE; move16(); - st->bwidth = extract_l(L_shr(ind,3) & 0x7L); + st->bwidth = extract_l( L_shr( ind, 3 ) & 0x7L ); } ELSE { - st->bwidth = extract_l(L_and(L_shr(ind,3),0x7L)); - *sharpFlag = extract_l(L_and(L_shr(ind,6),0x1L)); - + st->bwidth = extract_l( L_and( L_shr( ind, 3 ), 0x7L ) ); + *sharpFlag = extract_l( L_and( L_shr( ind, 6 ), 0x1L ) ); } } @@ -290,14 +289,13 @@ void decision_matrix_dec_fx( test(); test(); IF( ( st->BER_detect ) || - ( GE_32(ind,1<<7) ) || - ( LE_32(st->total_brate,ACELP_13k20) && EQ_16(st->bwidth,FB) ) || - ( GE_32(st->total_brate,ACELP_32k) && EQ_16(st->bwidth,NB) ) || - ( GE_32(st->total_brate,ACELP_32k) && !(EQ_16(st->coder_type,GENERIC) || EQ_16(st->coder_type,TRANSITION) || EQ_16(st->coder_type,INACTIVE) ) ) || - ( LT_32(st->total_brate,ACELP_13k20) && NE_16(st->bwidth,NB) && EQ_16(st->coder_type,LR_MDCT) ) || - ( GE_32(st->total_brate,ACELP_13k20) && EQ_16(st->coder_type,UNVOICED) ) || - ( GE_32(st->total_brate,ACELP_13k20) && EQ_16(st->coder_type,AUDIO) && EQ_16(st->bwidth,NB) ) - ) + ( GE_32( ind, 1 << 7 ) ) || + ( LE_32( st->total_brate, ACELP_13k20 ) && EQ_16( st->bwidth, FB ) ) || + ( GE_32( st->total_brate, ACELP_32k ) && EQ_16( st->bwidth, NB ) ) || + ( GE_32( st->total_brate, ACELP_32k ) && !( EQ_16( st->coder_type, GENERIC ) || EQ_16( st->coder_type, TRANSITION ) || EQ_16( st->coder_type, INACTIVE ) ) ) || + ( LT_32( st->total_brate, ACELP_13k20 ) && NE_16( st->bwidth, NB ) && EQ_16( st->coder_type, LR_MDCT ) ) || + ( GE_32( st->total_brate, ACELP_13k20 ) && EQ_16( st->coder_type, UNVOICED ) ) || + ( GE_32( st->total_brate, ACELP_13k20 ) && EQ_16( st->coder_type, AUDIO ) && EQ_16( st->bwidth, NB ) ) ) { st->BER_detect = 0; move16(); @@ -315,7 +313,7 @@ void decision_matrix_dec_fx( st->last_core_brate = st->core_brate; move32(); } - ELSE IF( EQ_32(st->last_total_brate, -1)) /* can happen in case of BER when no good frame was received before */ + ELSE IF( EQ_32( st->last_total_brate, -1 ) ) /* can happen in case of BER when no good frame was received before */ { st->coder_type = st->last_coder_type; move16(); @@ -324,14 +322,14 @@ void decision_matrix_dec_fx( st->total_brate = st->last_total_brate_ber; move32(); test(); - IF( EQ_16(st->last_core, AMR_WB_CORE)) + IF( EQ_16( st->last_core, AMR_WB_CORE ) ) { st->core = ACELP_CORE; move16(); st->codec_mode = MODE1; move16(); } - ELSE IF( EQ_16(st->last_core_bfi, TCX_20_CORE)||EQ_16(st->last_core_bfi,TCX_10_CORE)) + ELSE IF( EQ_16( st->last_core_bfi, TCX_20_CORE ) || EQ_16( st->last_core_bfi, TCX_10_CORE ) ) { st->core = st->last_core_bfi; move16(); @@ -349,7 +347,7 @@ void decision_matrix_dec_fx( move32(); st->extl = st->last_extl; move16(); - st->extl_brate = L_sub(st->total_brate, st->core_brate); + st->extl_brate = L_sub( st->total_brate, st->core_brate ); move32(); } ELSE @@ -362,14 +360,14 @@ void decision_matrix_dec_fx( move16(); test(); - IF( EQ_16(st->last_core,AMR_WB_CORE)) + IF( EQ_16( st->last_core, AMR_WB_CORE ) ) { st->core = ACELP_CORE; move16(); st->codec_mode = MODE1; move16(); } - ELSE IF( EQ_16(st->last_core,TCX_20_CORE)||EQ_16(st->last_core,TCX_10_CORE)) + ELSE IF( EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) ) { st->core = st->last_core; move16(); @@ -387,7 +385,7 @@ void decision_matrix_dec_fx( move32(); st->extl = st->last_extl; move16(); - st->extl_brate = L_sub(st->total_brate,st->core_brate); + st->extl_brate = L_sub( st->total_brate, st->core_brate ); } return; @@ -412,19 +410,19 @@ void decision_matrix_dec_fx( test(); test(); test(); - IF( EQ_16(st->core,ACELP_CORE)&&EQ_16(st->bwidth,WB)&<_32(st->total_brate,ACELP_9k60)) + IF( EQ_16( st->core, ACELP_CORE ) && EQ_16( st->bwidth, WB ) && LT_32( st->total_brate, ACELP_9k60 ) ) { - if( st->vbr_hw_BWE_disable_dec == 0 ) + if ( st->vbr_hw_BWE_disable_dec == 0 ) { st->extl = WB_BWE; move16(); } } - ELSE IF( EQ_16(st->core,ACELP_CORE)&&EQ_16(st->bwidth,WB)&&GE_32(st->total_brate,ACELP_9k60)&&LE_32(st->total_brate,ACELP_16k40)) + ELSE IF( EQ_16( st->core, ACELP_CORE ) && EQ_16( st->bwidth, WB ) && GE_32( st->total_brate, ACELP_9k60 ) && LE_32( st->total_brate, ACELP_16k40 ) ) { /* read the WB TBE/BWE selection bit */ tmp16 = get_next_indice( st, 1 ); - IF( EQ_16(tmp16,1)) + IF( EQ_16( tmp16, 1 ) ) { st->extl = WB_BWE; move16(); @@ -439,13 +437,13 @@ void decision_matrix_dec_fx( move32(); } } - ELSE IF( EQ_16(st->core,ACELP_CORE)&&(EQ_16(st->bwidth,SWB)||EQ_16(st->bwidth,FB))&&GE_32(st->total_brate,ACELP_13k20)) + ELSE IF( EQ_16( st->core, ACELP_CORE ) && ( EQ_16( st->bwidth, SWB ) || EQ_16( st->bwidth, FB ) ) && GE_32( st->total_brate, ACELP_13k20 ) ) { - IF( GE_32(st->total_brate,ACELP_48k)) + IF( GE_32( st->total_brate, ACELP_48k ) ) { st->extl = SWB_BWE_HIGHRATE; move16(); - if( EQ_16(st->bwidth,FB)) + if ( EQ_16( st->bwidth, FB ) ) { st->extl = FB_BWE_HIGHRATE; move16(); @@ -472,7 +470,7 @@ void decision_matrix_dec_fx( move16(); st->extl_brate = SWB_TBE_1k6; move32(); - if( GE_32(st->total_brate,ACELP_24k40)) + if ( GE_32( st->total_brate, ACELP_24k40 ) ) { st->extl_brate = SWB_TBE_2k8; move32(); @@ -482,16 +480,16 @@ void decision_matrix_dec_fx( /* set FB TBE and FB BWE extension layers */ test(); - IF( EQ_16(st->bwidth,FB)&&GE_32(st->total_brate,ACELP_24k40)) + IF( EQ_16( st->bwidth, FB ) && GE_32( st->total_brate, ACELP_24k40 ) ) { - IF( EQ_16(st->extl,SWB_BWE)) + IF( EQ_16( st->extl, SWB_BWE ) ) { st->extl = FB_BWE; move16(); st->extl_brate = FB_BWE_1k8; move32(); } - ELSE IF( EQ_16(st->extl,SWB_TBE)) + ELSE IF( EQ_16( st->extl, SWB_TBE ) ) { st->extl = FB_TBE; move16(); @@ -504,7 +502,7 @@ void decision_matrix_dec_fx( } /* set core bitrate */ - st->core_brate = L_sub(st->total_brate,st->extl_brate); + st->core_brate = L_sub( st->total_brate, st->extl_brate ); /*-----------------------------------------------------------------* * Read HQ signaling bits from the bitstream @@ -512,9 +510,9 @@ void decision_matrix_dec_fx( *-----------------------------------------------------------------*/ - IF( EQ_16(st->core,HQ_CORE)) + IF( EQ_16( st->core, HQ_CORE ) ) { - IF( NE_16(st->mdct_sw, MODE2)) + IF( NE_16( st->mdct_sw, MODE2 ) ) { /* skip the HQ/TCX core switching flag */ get_next_indice_tmp_fx( st, 1 ); @@ -523,7 +521,7 @@ void decision_matrix_dec_fx( /* read ACELP->HQ core switching flag */ *core_switching_flag = get_next_indice( st, 1 ); - IF( EQ_16(*core_switching_flag,1)) + IF( EQ_16( *core_switching_flag, 1 ) ) { st->last_L_frame_ori = st->last_L_frame; move16(); @@ -532,18 +530,18 @@ void decision_matrix_dec_fx( st->last_L_frame = L_FRAME16k; move16(); tmp16 = get_next_indice( st, 1 ); - if( tmp16 == 0 ) + if ( tmp16 == 0 ) { st->last_L_frame = L_FRAME; move16(); } } - IF( NE_16(st->mdct_sw, MODE2)) + IF( NE_16( st->mdct_sw, MODE2 ) ) { /* read/set band-width (needed for different I/O sampling rate support) */ - IF( GT_32(st->total_brate,ACELP_16k40)) + IF( GT_32( st->total_brate, ACELP_16k40 ) ) { tmp16 = get_next_indice( st, 2 ); @@ -552,12 +550,12 @@ void decision_matrix_dec_fx( st->bwidth = NB; move16(); } - ELSE IF( EQ_16(tmp16,1)) + ELSE IF( EQ_16( tmp16, 1 ) ) { st->bwidth = WB; move16(); } - ELSE IF( EQ_16(tmp16,2)) + ELSE IF( EQ_16( tmp16, 2 ) ) { st->bwidth = SWB; move16(); @@ -575,9 +573,8 @@ void decision_matrix_dec_fx( test(); test(); test(); - IF( ( GE_32(st->total_brate,ACELP_24k40)&&EQ_16(st->bwidth,NB))|| - ( EQ_16(st->core,HQ_CORE) && LE_32(st->total_brate,LRMDCT_CROSSOVER_POINT) && EQ_16(st->bwidth,FB) ) - ) + IF( ( GE_32( st->total_brate, ACELP_24k40 ) && EQ_16( st->bwidth, NB ) ) || + ( EQ_16( st->core, HQ_CORE ) && LE_32( st->total_brate, LRMDCT_CROSSOVER_POINT ) && EQ_16( st->bwidth, FB ) ) ) { st->bfi = 1; move16(); @@ -588,7 +585,7 @@ void decision_matrix_dec_fx( move16(); st->extl_brate = 0; move32(); - IF( EQ_16(st->last_core,AMR_WB_CORE)) + IF( EQ_16( st->last_core, AMR_WB_CORE ) ) { st->core = ACELP_CORE; move16(); @@ -599,7 +596,7 @@ void decision_matrix_dec_fx( st->last_L_frame = L_FRAME; move16(); - IF( GE_32(st->total_brate,ACELP_16k40)) + IF( GE_32( st->total_brate, ACELP_16k40 ) ) { st->total_brate = ACELP_13k20; move32(); @@ -621,12 +618,12 @@ void decision_matrix_dec_fx( test(); test(); - IF( (EQ_16(st->bwidth,SWB)||EQ_16(st->bwidth,WB))&&LE_32(st->total_brate,LRMDCT_CROSSOVER_POINT)) + IF( ( EQ_16( st->bwidth, SWB ) || EQ_16( st->bwidth, WB ) ) && LE_32( st->total_brate, LRMDCT_CROSSOVER_POINT ) ) { *hq_core_type = LOW_RATE_HQ_CORE; move16(); } - ELSE IF( EQ_16(st->bwidth,NB)) + ELSE IF( EQ_16( st->bwidth, NB ) ) { *hq_core_type = LOW_RATE_HQ_CORE; move16(); @@ -646,20 +643,20 @@ void decision_matrix_dec_fx( test(); test(); test(); - IF( EQ_32(st->core_brate,FRAME_NO_DATA)) + IF( EQ_32( st->core_brate, FRAME_NO_DATA ) ) { /* prevent "L_frame" changes in CNG segments */ st->L_frame = st->last_L_frame; move16(); } - ELSE IF( EQ_32(st->core_brate,SID_2k40)&&EQ_16(st->bwidth,WB)&&st->first_CNG&<_16(st->hTdCngDec->act_cnt2,MIN_ACT_CNG_UPD)) + ELSE IF( EQ_32( st->core_brate, SID_2k40 ) && EQ_16( st->bwidth, WB ) && st->first_CNG && LT_16( st->hTdCngDec->act_cnt2, MIN_ACT_CNG_UPD ) ) { /* prevent "L_frame" changes in SID frame after short segment of active frames */ st->L_frame = st->last_CNG_L_frame; move16(); } - ELSE IF( ( EQ_32(st->core_brate,SID_2k40)&&GE_32(st->total_brate,ACELP_9k60)&&EQ_16(st->bwidth,WB))|| - ( GE_32(st->total_brate, ACELP_32k) && LT_32(st->total_brate,HQ_96k) ) || ( EQ_32(st->total_brate,ACELP_24k40) && GE_16(st->bwidth,WB) ) ) + ELSE IF( ( EQ_32( st->core_brate, SID_2k40 ) && GE_32( st->total_brate, ACELP_9k60 ) && EQ_16( st->bwidth, WB ) ) || + ( GE_32( st->total_brate, ACELP_32k ) && LT_32( st->total_brate, HQ_96k ) ) || ( EQ_32( st->total_brate, ACELP_24k40 ) && GE_16( st->bwidth, WB ) ) ) { st->L_frame = L_FRAME16k; move16(); @@ -672,26 +669,26 @@ void decision_matrix_dec_fx( st->nb_subfr = NB_SUBFR; move16(); - if ( EQ_16(st->L_frame,L_FRAME16k)) + if ( EQ_16( st->L_frame, L_FRAME16k ) ) { st->nb_subfr = NB_SUBFR16k; move16(); } -#if 1//def ADD_IVAS_BWE 0> NEEDED for IO with conf_acelp1 +#if 1 // def ADD_IVAS_BWE 0> NEEDED for IO with conf_acelp1 st->extl_orig = st->extl; st->extl_brate_orig = st->extl_brate; #endif test(); - IF( EQ_32(st->output_Fs,8000)) + IF( EQ_32( st->output_Fs, 8000 ) ) { st->extl = -1; move16(); } - ELSE IF( EQ_32(st->output_Fs,16000)&&EQ_16(st->L_frame,L_FRAME16k)) + ELSE IF( EQ_32( st->output_Fs, 16000 ) && EQ_16( st->L_frame, L_FRAME16k ) ) { st->extl = -1; move16(); - st->extl_brate = L_deposit_l(0); + st->extl_brate = L_deposit_l( 0 ); } IF( st->ini_frame == 0 ) @@ -709,4 +706,4 @@ void decision_matrix_dec_fx( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/dlpc_avq.c b/lib_dec/dlpc_avq.c index 0a9dfe053..94b3172f0 100644 --- a/lib_dec/dlpc_avq.c +++ b/lib_dec/dlpc_avq.c @@ -322,4 +322,4 @@ int16_t decode_lpc_avq( return st->next_bit_pos - start_bit_pos; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/dlpc_avq_fx.c b/lib_dec/dlpc_avq_fx.c index ac1232536..4067fe76b 100644 --- a/lib_dec/dlpc_avq_fx.c +++ b/lib_dec/dlpc_avq_fx.c @@ -9,20 +9,20 @@ #include "prot_fx1.h" #include "prot_fx2.h" #ifdef IVAS_FLOAT_FIXED - /* Constants */ +/* Constants */ -#define M 16 /* length of LPC */ -#define BFI_FAC 29491/*0.9f Q15*/ +#define M 16 /* length of LPC */ +#define BFI_FAC 29491 /*0.9f Q15*/ /***********************************************/ /* Variable bit-rate multiple LPC un-quantizer */ /***********************************************/ Word16 dlpc_avq_fx( - Word16 *index, /* i : Quantization indices */ - Word16 *LSF_Q, /* o : Quantized LSF vectors */ - Word16 numlpc, /* i : Number of sets of lpc */ - Word32 sr_core /* i : Core sampling rate */ + Word16 *index, /* i : Quantization indices */ + Word16 *LSF_Q, /* o : Quantized LSF vectors */ + Word16 numlpc, /* i : Number of sets of lpc */ + Word32 sr_core /* i : Core sampling rate */ ) { Word16 i, nbi, last; @@ -33,7 +33,7 @@ Word16 dlpc_avq_fx( move16(); last = 0; - if ( NE_16(numlpc,1)) + if ( NE_16( numlpc, 1 ) ) { move16(); last = M; @@ -44,58 +44,57 @@ Word16 dlpc_avq_fx( /* Decode last LPC */ - FOR (i=0; iBER_detect) + WHILE( ( get_next_indice_1_fx( st ) != 0 ) && !st->BER_detect ) { move16(); - *ind = add(*ind,1); + *ind = add( *ind, 1 ); } - IF (*ind != 0) + IF( *ind != 0 ) { move16(); - *ind = add(*ind, 1); + *ind = add( *ind, 1 ); } - return sub(st->next_bit_pos, start_bit_pos); - + return sub( st->next_bit_pos, start_bit_pos ); } static Word16 pack4bits_fx( - Word16 nbits, - Decoder_State *st, - Word16 *prm -) + Word16 nbits, + Decoder_State *st, + Word16 *prm ) { Word16 i; move16(); - i=0; + i = 0; - FOR ( ; nbits > 4; nbits -= 4 ) + FOR( ; nbits > 4; nbits -= 4 ) { move16(); - prm[i] = get_next_indice_fx(st, 4); - i = add(i,1); - - + prm[i] = get_next_indice_fx( st, 4 ); + i = add( i, 1 ); } - prm[i] = get_next_indice_fx(st, nbits); + prm[i] = get_next_indice_fx( st, nbits ); move16(); - i = add(i,1); + i = add( i, 1 ); - return(i); + return ( i ); } Word16 decode_lpc_avq_fx( - Decoder_State *st, /* i/o: decoder state structure */ - const Word16 numlpc, /* i : Number of sets of lpc */ - Word16* param_lpc /* o : lpc parameters */ + Decoder_State *st, /* i/o: decoder state structure */ + const Word16 numlpc, /* i : Number of sets of lpc */ + Word16 *param_lpc /* o : lpc parameters */ #ifdef IVAS_CODE_AVQ_LPC - ,const Word16 ch, /* i : channel */ + , + const Word16 ch, /* i : channel */ const Word16 element_mode, /* i : element mode */ const Word16 sns_low_br_mode /* i : SNS low-bitrate mode */ #endif ) { - Word16 k,j; + Word16 k, j; Word16 nb, qn1, qn2, avqBits, q_type; Word16 start_bit_pos; #ifdef IVAS_CODE_AVQ_LPC @@ -174,11 +170,11 @@ Word16 decode_lpc_avq_fx( j = 0; start_bit_pos = st->next_bit_pos; - FOR (k=0; knext_bit_pos, start_bit_pos); + return sub( st->next_bit_pos, start_bit_pos ); } Word16 decode_lpc_avq_ivas_fx( Decoder_State *st, /* i/o: decoder state structure */ @@ -417,7 +413,7 @@ Word16 decode_lpc_avq_ivas_fx( ELSE { move16(); - param_lpc[j] = get_next_indice_fx( st, LPC_ABS_QUANT_BITS); + param_lpc[j] = get_next_indice_fx( st, LPC_ABS_QUANT_BITS ); } j = add( j, 1 ); } diff --git a/lib_dec/dlpc_stoch.c b/lib_dec/dlpc_stoch.c index dc853a8b2..6d18ffbda 100644 --- a/lib_dec/dlpc_stoch.c +++ b/lib_dec/dlpc_stoch.c @@ -118,4 +118,4 @@ void lpc_unquantize( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/dlpc_stoch_fx.c b/lib_dec/dlpc_stoch_fx.c index e28044c19..c024f1622 100644 --- a/lib_dec/dlpc_stoch_fx.c +++ b/lib_dec/dlpc_stoch_fx.c @@ -12,96 +12,96 @@ #include "prot_fx2.h" #ifdef IVAS_FLOAT_FIXED /* Constants */ -#define M 16 +#define M 16 #define BFI_FAC 0.9f void lpc_unquantize_fx( - Decoder_State * st, + Decoder_State *st, Word16 *lsf, Word16 *lsp, const Word16 m, - Word16* param_lpc, + Word16 *param_lpc, Word16 *lspmid, Word16 *lsfmid, Word16 coder_type, - Word16 *LSF_Q_prediction /* o : LSF prediction mode */ + Word16 *LSF_Q_prediction /* o : LSF prediction mode */ ) { Word16 nb_indices, k; Word16 i; - nb_indices = 0; /* to avoid compilation warnings */ + nb_indices = 0; /* to avoid compilation warnings */ - Copy(st->lsf_old_fx, &lsf[0], m); - Copy(st->lsp_old_fx, &lsp[0], m); + Copy( st->lsf_old_fx, &lsf[0], m ); + Copy( st->lsp_old_fx, &lsp[0], m ); - IF(st->lpcQuantization == 0 ) + IF( st->lpcQuantization == 0 ) { - nb_indices = dlpc_avq_fx(param_lpc, &lsf[m], st->numlpc, st->sr_core); - FOR ( k=0; k< st->numlpc; k++ ) + nb_indices = dlpc_avq_fx( param_lpc, &lsf[m], st->numlpc, st->sr_core ); + FOR( k = 0; k < st->numlpc; k++ ) { - E_LPC_lsf_lsp_conversion(&lsf[(k+1)*m], &lsp[(k+1)*m], m); + E_LPC_lsf_lsp_conversion( &lsf[( k + 1 ) * m], &lsp[( k + 1 ) * m], m ); } } - ELSE IF ( EQ_16(st->lpcQuantization, 1)) + ELSE IF( EQ_16( st->lpcQuantization, 1 ) ) { test(); - IF ((EQ_32(st->sr_core, INT_FS_16k))&&(EQ_16(coder_type,UNVOICED))) + IF( ( EQ_32( st->sr_core, INT_FS_16k ) ) && ( EQ_16( coder_type, UNVOICED ) ) ) { - lsf_end_dec_fx( st, 1, GENERIC, sub(1, st->narrowBand) /* st->bwidth */ , ENDLSF_NBITS, &lsf[m], param_lpc, LSF_Q_prediction, &nb_indices + lsf_end_dec_fx( st, 1, GENERIC, sub( 1, st->narrowBand ) /* st->bwidth */, ENDLSF_NBITS, &lsf[m], param_lpc, LSF_Q_prediction, &nb_indices #ifdef LSF_RE_USE_SECONDARY_CHANNEL - ,NULL + , + NULL #endif - ); + ); } ELSE { - IF (EQ_16(st->core, TCX_20_CORE)) + IF( EQ_16( st->core, TCX_20_CORE ) ) { - lsf_end_dec_fx( st, 1, AUDIO, sub(1, st->narrowBand) /* st->bwidth */ , ENDLSF_NBITS, &lsf[m], param_lpc, LSF_Q_prediction, &nb_indices + lsf_end_dec_fx( st, 1, AUDIO, sub( 1, st->narrowBand ) /* st->bwidth */, ENDLSF_NBITS, &lsf[m], param_lpc, LSF_Q_prediction, &nb_indices #ifdef LSF_RE_USE_SECONDARY_CHANNEL - ,NULL + , + NULL #endif - ); - + ); } ELSE { - lsf_end_dec_fx( st, 1, coder_type, sub(1, st->narrowBand) /* st->bwidth */ , ENDLSF_NBITS, &lsf[m], param_lpc, LSF_Q_prediction, &nb_indices + lsf_end_dec_fx( st, 1, coder_type, sub( 1, st->narrowBand ) /* st->bwidth */, ENDLSF_NBITS, &lsf[m], param_lpc, LSF_Q_prediction, &nb_indices #ifdef LSF_RE_USE_SECONDARY_CHANNEL - ,NULL + , + NULL #endif - ); - + ); } } - lsf2lsp_fx(&lsf[m], &lsp[m], M, st->sr_core); + lsf2lsp_fx( &lsf[m], &lsp[m], M, st->sr_core ); } ELSE { - assert(0); + assert( 0 ); } - st->seed_acelp=0; + st->seed_acelp = 0; move16(); - FOR(i=nb_indices-1; i>=0; i--) + FOR( i = nb_indices - 1; i >= 0; i-- ) { - st->seed_acelp = extract_l(L_mac0(L_mac0(13849, shr(st->seed_acelp, 1), 31821), param_lpc[i], 31821)); + st->seed_acelp = extract_l( L_mac0( L_mac0( 13849, shr( st->seed_acelp, 1 ), 31821 ), param_lpc[i], 31821 ) ); } /* Decoded mid-frame isf */ test(); test(); test(); - IF (st->lpcQuantization && st->acelp_cfg.midLpc&& st->core==ACELP_CORE && st->rate_switching_reset==0) + IF( st->lpcQuantization && st->acelp_cfg.midLpc && st->core == ACELP_CORE && st->rate_switching_reset == 0 ) { - midlsf_dec ( &lsf[0], &lsf[m], param_lpc[nb_indices], lsfmid - ,coder_type ,&(st->mid_lsf_int), st->prev_bfi, st->safety_net); + midlsf_dec( &lsf[0], &lsf[m], param_lpc[nb_indices], lsfmid, coder_type, &( st->mid_lsf_int ), st->prev_bfi, st->safety_net ); reorder_lsf_fx( lsfmid, LSF_GAP_MID_FX, M, st->sr_core ); - lsf2lsp_fx(lsfmid, lspmid, M, st->sr_core); + lsf2lsp_fx( lsfmid, lspmid, M, st->sr_core ); } diff --git a/lib_dec/er_dec_acelp.c b/lib_dec/er_dec_acelp.c index d598cf7aa..7d49094ad 100644 --- a/lib_dec/er_dec_acelp.c +++ b/lib_dec/er_dec_acelp.c @@ -208,7 +208,7 @@ void con_acelp( { /* pitch cycle is first low-pass filtered */ /*get filter coefficients*/ - genPlcFiltBWAdap( st->sr_core, &lpFiltAdapt[0], 0, st->cummulative_damping_float); + genPlcFiltBWAdap( st->sr_core, &lpFiltAdapt[0], 0, st->cummulative_damping_float ); for ( i = 0; i < Tc; i++ ) { *pt_exc++ = ( lpFiltAdapt[0] * pt1_exc[-1] + lpFiltAdapt[1] * pt1_exc[0] + lpFiltAdapt[2] * pt1_exc[1] ); @@ -258,9 +258,9 @@ void con_acelp( { if ( fUseExtrapolatedPitch != 0 ) { - get_subframe_pitch_flt( st->nb_subfr, st->old_fpitch_float, predPitchLag, pitch_buf ); + get_subframe_pitch_flt( st->nb_subfr, st->old_fpitch_float, predPitchLag, pitch_buf ); - PulseResynchronization( harmonic_exc_buf, exc, L_frame, st->nb_subfr, st->old_fpitch_float, predPitchLag ); + PulseResynchronization( harmonic_exc_buf, exc, L_frame, st->nb_subfr, st->old_fpitch_float, predPitchLag ); } else { @@ -391,7 +391,7 @@ void con_acelp( } /*get filter coefficients*/ - genPlcFiltBWAdap( st->sr_core, &hp_filt[0], 1, st->cummulative_damping_float); + genPlcFiltBWAdap( st->sr_core, &hp_filt[0], 1, st->cummulative_damping_float ); /* PLC: [ACELP: Fade-out] * PLC: retrieve background level */ @@ -434,7 +434,7 @@ void con_acelp( { float tilt_code; - tilt_code = (float) ( 0.10f * ( 1.0f + st->voice_fac_float) ); + tilt_code = (float) ( 0.10f * ( 1.0f + st->voice_fac_float ) ); gain_inov *= ( 1.f - tilt_code ); } @@ -537,7 +537,7 @@ void con_acelp( set_zero( h1, L_SUBFR + 1 ); set_zero( mem, M ); h1[0] = 1.0f; - syn_filt( p_A, M, h1, h1, L_SUBFR, mem, 0 ); /* impulse response of LPC */ + syn_filt( p_A, M, h1, h1, L_SUBFR, mem, 0 ); /* impulse response of LPC */ deemph( h1, st->preemph_fac_float, L_SUBFR, &tmp ); /* impulse response of deemph */ /* impulse response level = gain introduced by synthesis+deemphasis */ gain_lpc[i_subfr / L_SUBFR] = 1.f / (float) sqrt( dotp( h1, h1, L_SUBFR ) ); @@ -582,7 +582,7 @@ void con_acelp( set_zero( h1, L_SUBFR + 1 ); set_zero( mem, M ); h1[0] = 1.0f; - syn_filt( p_A, M, h1, h1, L_SUBFR, mem, 0 ); /* impulse response of LPC */ + syn_filt( p_A, M, h1, h1, L_SUBFR, mem, 0 ); /* impulse response of LPC */ deemph( h1, st->preemph_fac_float, L_SUBFR, &tmp ); /* impulse response of deemph */ /* impulse response level = gain introduced by synthesis+deemphasis */ gain_lpc[i_subfr / L_SUBFR] = 1.f / (float) sqrt( dotp( h1, h1, L_SUBFR ) ); diff --git a/lib_dec/er_dec_acelp_fx.c b/lib_dec/er_dec_acelp_fx.c index e4907163c..e3fceb149 100644 --- a/lib_dec/er_dec_acelp_fx.c +++ b/lib_dec/er_dec_acelp_fx.c @@ -13,63 +13,61 @@ #include "basop_util.h" #include "rom_dec.h" #ifdef IVAS_FLOAT_FIXED -extern const Word16 T_DIV_L_Frame[];/*0Q15 * 2^-7 */ +extern const Word16 T_DIV_L_Frame[]; /*0Q15 * 2^-7 */ /*Table 2^7 * 1/L_frame */ -#define L_SYN_BUF M+L_DIV_MAX+L_DIV_MAX -#define L_EXC_BUF OLD_EXC_SIZE_DEC_16k+L_DIV_MAX+L_SUBFR+1+L_DIV_MAX/2 +#define L_SYN_BUF M + L_DIV_MAX + L_DIV_MAX +#define L_EXC_BUF OLD_EXC_SIZE_DEC_16k + L_DIV_MAX + L_SUBFR + 1 + L_DIV_MAX / 2 /*LOCAL FUNCTIONS*/ -static void memsynPrecission_fx(Word16 nbLostCmpt,Word16* mem_syn, Word16* exc, Word16 len, Word16*s_16); - +static void memsynPrecission_fx( Word16 nbLostCmpt, Word16 *mem_syn, Word16 *exc, Word16 len, Word16 *s_16 ); /*************************************************************** * \brief Main concealment function for ACELP * * -****************************************************************/ + ****************************************************************/ void con_acelp_fx( - const Word16 A[], /*mem_syn >rescaling done */ + const Word16 *Qf_exc, /*mem_syn >rescaling done */ Word16 *pitch_buffer, Word16 *voice_factors, - Word16 *bwe_exc -) + Word16 *bwe_exc ) { Word16 i_subfr, i, T0; /*Q0*/ Word16 tmp, tmp2, tmp_deemph; Word16 mem_syn[M], mem_syn2[M], *syn; Word16 *noise_buf; - Word16 *exc, *harmonic_exc_buf, buf[L_EXC_MEM_DEC+M+L_FRAME_16k+L_FRAME_16k/2]; /*Qf_exc*/ + Word16 *exc, *harmonic_exc_buf, buf[L_EXC_MEM_DEC + M + L_FRAME_16k + L_FRAME_16k / 2]; /*Qf_exc*/ const Word16 *p_A; Word32 pitch_buf[NB_SUBFR16k] /*15Q16*/; Word16 alpha; /*Q14*/ - Word16 step, gain, gainCNG,ftmp; + Word16 step, gain, gainCNG, ftmp; Word16 *pt_exc; Word16 gain_inov; - Word16 gainCNG_e ; /*scaling Factor (exponent) of gainCNG*/ + Word16 gainCNG_e; /*scaling Factor (exponent) of gainCNG*/ Word16 Qf_syn; /*Q format and exponent of new synthesis*/ Word16 *pt1_exc; Word32 tmp_tc; /*15Q16*/ Word16 extrapolationFailed; - Word32 predPitchLag; /*15Q16*/ - Word32 pc; /*float 15Q16*/ - Word16 fUseExtrapolatedPitch;/*int*/ - Word16 tmpSeed, Tc; /*Q0*/ + Word32 predPitchLag; /*15Q16*/ + Word32 pc; /*float 15Q16*/ + Word16 fUseExtrapolatedPitch; /*int*/ + Word16 tmpSeed, Tc; /*Q0*/ Word16 s_32; Word16 synthScaling; - PWord16 const *w = st->hTcxCfg->tcx_mdct_window; + PWord16 const *w = st->hTcxCfg->tcx_mdct_window; Word16 W1, W2; Word16 nSubframes; Word16 s_16, s_gain_inov, s2; @@ -79,13 +77,13 @@ void con_acelp_fx( Word16 lpFiltAdapt[3]; Word16 hp_filt[3]; Word16 Qf_syn_new; - Word16 exc_unv[L_FRAME_16k+L_FRAME_16k/2]; - Word16 syn_unv[L_FRAME_16k+L_FRAME_16k/2]; + Word16 exc_unv[L_FRAME_16k + L_FRAME_16k / 2]; + Word16 syn_unv[L_FRAME_16k + L_FRAME_16k / 2]; Word16 mem_syn_unv[M]; Word16 gain_lpc[NB_SUBFR16k]; Word16 gain_lpc_e[NB_SUBFR16k]; Word16 mem[M]; - Word16 h1[L_FRAME_16k/4+1]; + Word16 h1[L_FRAME_16k / 4 + 1]; Word16 gainSynthDeemph; Word16 gainSynthDeemph_e; Word16 l; @@ -112,19 +110,19 @@ void con_acelp_fx( move16(); alpha = 0; /*st->Mode2_lp_gainc = L_shl(st->Mode2_lp_gainc,7);*/ /*rudiment, could be changed in the whole file but should work also*/ - pc=L_deposit_l(0); + pc = L_deposit_l( 0 ); /*------------------------------------------------------------------------* * Initialize buffers * *------------------------------------------------------------------------*/ /* set ACELP synthesis memory */ - Copy( st->mem_syn2_fx, mem_syn, M); + Copy( st->mem_syn2_fx, mem_syn, M ); /* set excitation memory*/ - harmonic_exc_buf = buf+M; - exc = harmonic_exc_buf+L_EXC_MEM_DEC; - Copy( st->old_exc_fx, harmonic_exc_buf, L_EXC_MEM_DEC); + harmonic_exc_buf = buf + M; + exc = harmonic_exc_buf + L_EXC_MEM_DEC; + Copy( st->old_exc_fx, harmonic_exc_buf, L_EXC_MEM_DEC ); exc[st->L_frame] = 0; move16(); @@ -132,26 +130,26 @@ void con_acelp_fx( * PLC: [ACELP:Extrapolate Pitch Lag] *------------------------------------------------------------------------*/ - if (EQ_16(st->flagGuidedAcelp, 1)) + if ( EQ_16( st->flagGuidedAcelp, 1 ) ) { T0 = st->guidedT0; move16(); } - pitch_pred_linear_fit(st->nbLostCmpt, st->last_good, - st->old_pitch_buf_fx, - &st->old_fpitch, - &predPitchLag, st->pit_min, st->pit_max, st->mem_pitch_gain, 0, - st->plc_use_future_lag, &extrapolationFailed, st->nb_subfr); - T0 = round_fx(predPitchLag); + pitch_pred_linear_fit( st->nbLostCmpt, st->last_good, + st->old_pitch_buf_fx, + &st->old_fpitch, + &predPitchLag, st->pit_min, st->pit_max, st->mem_pitch_gain, 0, + st->plc_use_future_lag, &extrapolationFailed, st->nb_subfr ); + T0 = round_fx( predPitchLag ); - IF (extrapolationFailed != 0) + IF( extrapolationFailed != 0 ) { /*------------------------------------------------------------------------* * - Construct adaptive codebook from side information * *------------------------------------------------------------------------*/ - IF (st->flagGuidedAcelp == 0) + IF( st->flagGuidedAcelp == 0 ) { nSubframes = 0; move16(); @@ -161,10 +159,10 @@ void con_acelp_fx( nSubframes = 2; move16(); /* Construct adaptive codebook with T0, T0_frac, T0_res, gain_pit for 2 sub-frames */ - l = shl(L_SUBFR,1); - FOR (i = 0; i < l; i++) + l = shl( L_SUBFR, 1 ); + FOR( i = 0; i < l; i++ ) { - exc[i] = exc[sub(i,st->guidedT0)]; + exc[i] = exc[sub( i, st->guidedT0 )]; move16(); } } @@ -176,19 +174,19 @@ void con_acelp_fx( } tmp_tc = st->old_fpitch; - move16(); /* take the previous frame last pitch*/ - if( nSubframes > 0 ) + move16(); /* take the previous frame last pitch*/ + if ( nSubframes > 0 ) { - tmp_tc = L_deposit_h(st->guidedT0); /* take the transmit pitch*/ + tmp_tc = L_deposit_h( st->guidedT0 ); /* take the transmit pitch*/ } /* PLC: [ACELP: Fade-out] * PLC: calculate damping factor */ - alpha = Damping_fact_fx(coder_type, st->nbLostCmpt, st->last_good, stab_fac, &(st->Mode2_lp_gainp), 0); /*Q14*/ - st->cummulative_damping = shl(mult(st->cummulative_damping,alpha),1);/*shl(Q15*Q14,1)=shl(Q14,1) = Q15*/ - if (EQ_16(st->nbLostCmpt,1)) + alpha = Damping_fact_fx( coder_type, st->nbLostCmpt, st->last_good, stab_fac, &( st->Mode2_lp_gainp ), 0 ); /*Q14*/ + st->cummulative_damping = shl( mult( st->cummulative_damping, alpha ), 1 ); /*shl(Q15*Q14,1)=shl(Q14,1) = Q15*/ + if ( EQ_16( st->nbLostCmpt, 1 ) ) { - st->cummulative_damping = 32767/*1.f Q15*/; /*Q15*/ + st->cummulative_damping = 32767 /*1.f Q15*/; /*Q15*/ } /*-----------------------------------------------------------------* @@ -196,49 +194,47 @@ void con_acelp_fx( * PLC: Construct the harmonic part of excitation *-----------------------------------------------------------------*/ - IF( GE_16(st->last_good , UNVOICED_TRANSITION )) + IF( GE_16( st->last_good, UNVOICED_TRANSITION ) ) { /*---------------------------------------------------------------* * Last pitch cycle of the previous frame is repeatedly copied. * *---------------------------------------------------------------*/ - Tc = round_fx(tmp_tc); + Tc = round_fx( tmp_tc ); BASOP_SATURATE_WARNING_OFF_EVS /*if this ever saturates, it doesn't matter*/ #ifdef BASOP_NOGLOB - tmp = sub( shl_sat( abs_s( sub( T0, Tc ) ), 6 ), mult( 19661 /*0.15f Q17*/, shl_sat( Tc, 4 ) ) /*Q6*/ ); + tmp = sub( shl_sat( abs_s( sub( T0, Tc ) ), 6 ), mult( 19661 /*0.15f Q17*/, shl_sat( Tc, 4 ) ) /*Q6*/ ); #else - tmp = sub(shl(abs_s(sub(T0,Tc)),6) , mult(19661/*0.15f Q17*/,shl(Tc,4)) /*Q6*/); + tmp = sub( shl( abs_s( sub( T0, Tc ) ), 6 ), mult( 19661 /*0.15f Q17*/, shl( Tc, 4 ) ) /*Q6*/ ); #endif BASOP_SATURATE_WARNING_ON_EVS test(); test(); test(); - if ((T0 > 0) && (NE_16(T0 , Tc)) - && ( tmp < 0 ) - && extrapolationFailed == 0 ) + if ( ( T0 > 0 ) && ( NE_16( T0, Tc ) ) && ( tmp < 0 ) && extrapolationFailed == 0 ) { fUseExtrapolatedPitch = 1; move16(); } pt_exc = exc; - if (st->enableGplc != 0) + if ( st->enableGplc != 0 ) { - pt_exc = &exc[nSubframes*L_SUBFR]; + pt_exc = &exc[nSubframes * L_SUBFR]; } pt1_exc = pt_exc - Tc; - IF (fUseExtrapolatedPitch != 0) + IF( fUseExtrapolatedPitch != 0 ) { /* Required because later pt1_exc[1] used in filtering points to exc[0]. To make it safe also for GPL pt_exc is used instead of exc */ pt_exc[0] = 0; move16(); pt_exc = harmonic_exc_buf; - assert(pt_exc < pt1_exc-1); + assert( pt_exc < pt1_exc - 1 ); } - IF (EQ_16(st->nbLostCmpt, 1)) + IF( EQ_16( st->nbLostCmpt, 1 ) ) { /* pitch cycle is first low-pass filtered */ @@ -249,15 +245,15 @@ void con_acelp_fx( 0, st->cummulative_damping /*Q15*/ ); - FOR( i=0 ; i< Tc; i++ ) + FOR( i = 0; i < Tc; i++ ) { /* *pt_exc++ = ( lpFiltAdapt[0] * pt1_exc[-1] + lpFiltAdapt[1] * pt1_exc[0] + lpFiltAdapt[2] * pt1_exc[1]);*/ - tmp_32 = L_mult( lpFiltAdapt[0] , pt1_exc[-1]) ; - tmp_32 = L_mac(tmp_32, lpFiltAdapt[1] , pt1_exc[0]) ; - tmp_16 = mac_r(tmp_32, lpFiltAdapt[2] , pt1_exc[1]); + tmp_32 = L_mult( lpFiltAdapt[0], pt1_exc[-1] ); + tmp_32 = L_mac( tmp_32, lpFiltAdapt[1], pt1_exc[0] ); + tmp_16 = mac_r( tmp_32, lpFiltAdapt[2], pt1_exc[1] ); move16(); - *pt_exc = tmp_16; + *pt_exc = tmp_16; pt_exc++; pt1_exc++; } @@ -265,20 +261,20 @@ void con_acelp_fx( ELSE { /* copy the first pitch cycle without low-pass filtering */ - FOR( i=0 ; i< Tc; i++ ) + FOR( i = 0; i < Tc; i++ ) { move16(); *pt_exc++ = *pt1_exc++; } } - if (fUseExtrapolatedPitch != 0) + if ( fUseExtrapolatedPitch != 0 ) { pt1_exc = harmonic_exc_buf; } - l = add(st->L_frame,sub(imult1616(L_SUBFR,sub(1,nSubframes)),Tc)); - FOR( i= 0; i < l; i++ ) + l = add( st->L_frame, sub( imult1616( L_SUBFR, sub( 1, nSubframes ) ), Tc ) ); + FOR( i = 0; i < l; i++ ) { move16(); *pt_exc++ = *pt1_exc++; @@ -293,16 +289,16 @@ void con_acelp_fx( { move16(); move16(); - pitch_buf[0] = L_deposit_h(st->guidedT0); - pitch_buf[1] = L_deposit_h(st->guidedT0); + pitch_buf[0] = L_deposit_h( st->guidedT0 ); + pitch_buf[1] = L_deposit_h( st->guidedT0 ); } - IF (nSubframes>0) + IF( nSubframes > 0 ) { move16(); move16(); pitch_buf[3] = pitch_buf[2] = pitch_buf[1]; /* do not resync on second half of frame */ - if (EQ_16(st->nb_subfr, 5)) + if ( EQ_16( st->nb_subfr, 5 ) ) { /* for guided acelp cases and nSubframes=2, set pitch_buf[4] to avoid memory_access issues in post_decoder() */ pitch_buf[4] = pitch_buf[3]; @@ -311,14 +307,15 @@ void con_acelp_fx( } ELSE { - IF (fUseExtrapolatedPitch != 0) + IF( fUseExtrapolatedPitch != 0 ) { - get_subframe_pitch(st->nb_subfr, st->old_fpitch, predPitchLag, pitch_buf); - PulseResynchronization_fx(harmonic_exc_buf, exc, st->L_frame, st->nb_subfr, st->old_fpitch, predPitchLag); + get_subframe_pitch( st->nb_subfr, st->old_fpitch, predPitchLag, pitch_buf ); + PulseResynchronization_fx( harmonic_exc_buf, exc, st->L_frame, st->nb_subfr, st->old_fpitch, predPitchLag ); } - ELSE { - set32_fx(pitch_buf, st->old_fpitch, st->nb_subfr); + ELSE + { + set32_fx( pitch_buf, st->old_fpitch, st->nb_subfr ); } } @@ -326,14 +323,14 @@ void con_acelp_fx( * PLC: [ACELP: adaptive codebook] * PLC: Create the harmonic part needed for the overlap-add. *------------------------------------------------------------*/ - pt_exc = exc+st->L_frame; + pt_exc = exc + st->L_frame; pt1_exc = pt_exc - T0; - if (T0 == 0) + if ( T0 == 0 ) { pt1_exc = pt_exc - Tc; } - l = shr(st->L_frame, 1); - FOR (i = 0; i < l; i++) + l = shr( st->L_frame, 1 ); + FOR( i = 0; i < l; i++ ) { *pt_exc++ = *pt1_exc++; move16(); @@ -344,13 +341,13 @@ void con_acelp_fx( * PLC: update the floating point pitch for consecutive loss *-------------------------------------------------------*/ - IF (fUseExtrapolatedPitch != 0) + IF( fUseExtrapolatedPitch != 0 ) { move32(); st->old_fpitch = predPitchLag; - if (EQ_16(st->flagGuidedAcelp ,1)) + if ( EQ_16( st->flagGuidedAcelp, 1 ) ) { - st->old_fpitch = L_deposit_h(T0); + st->old_fpitch = L_deposit_h( T0 ); } } @@ -359,7 +356,8 @@ void con_acelp_fx( * PLC: Accommodate the BPF *-------------------------------------------------------*/ - st->bpf_gain_param = 3 ; /*full BPF*/ move16(); + st->bpf_gain_param = 3; /*full BPF*/ + move16(); /*-------------------------------------------------------* * PLC: [ACELP: adaptive codebook] @@ -368,35 +366,33 @@ void con_acelp_fx( /* Compute pitch coherence (copied from decoder classifier)*/ - pc = L_abs(L_sub(L_add(pitch_buf[3], L_sub(pitch_buf[2], pitch_buf[1])), pitch_buf[0])); /*9Q6*/ /*> 15Q16*/ + pc = L_abs( L_sub( L_add( pitch_buf[3], L_sub( pitch_buf[2], pitch_buf[1] ) ), pitch_buf[0] ) ); /*9Q6*/ /*> 15Q16*/ /* mapping: floor(( 0.824[15Q15]-x[15Q0]*0.0733[0Q15] )*4) */ - pc = Mpy_32_16_1( L_shl(pc,1)/*precompensate Q14 from table*/, /*15Q16*/ - T_256DIV_L_Frame[L_shr(L_msu0(54000,shr(st->L_frame,5),2402),15-2)]); + pc = Mpy_32_16_1( L_shl( pc, 1 ) /*precompensate Q14 from table*/, /*15Q16*/ + T_256DIV_L_Frame[L_shr( L_msu0( 54000, shr( st->L_frame, 5 ), 2402 ), 15 - 2 )] ); test(); - test();/*test();*/ - IF (LE_16(st->last_good , UNVOICED_TRANSITION) - && (EQ_16(coder_type , GENERIC ) ) - && GT_32(pc , 6*2*32768/*6(15Q16)*/ ) /*&& (stab_fac <= 0.5f)*/ - ) + test(); /*test();*/ + IF( LE_16( st->last_good, UNVOICED_TRANSITION ) && ( EQ_16( coder_type, GENERIC ) ) && GT_32( pc, 6 * 2 * 32768 /*6(15Q16)*/ ) /*&& (stab_fac <= 0.5f)*/ + ) { gain = 0; move16(); - st->Mode2_lp_gainp = L_deposit_l(0); + st->Mode2_lp_gainp = L_deposit_l( 0 ); } ELSE { - gain = 0x4000 /*1 (1Q14)*/; /* start-of-the-frame gain */ - st->Mode2_lp_gainp = L_shl(L_deposit_l(alpha),15); /*1Q14->2Q29*/ + gain = 0x4000 /*1 (1Q14)*/; /* start-of-the-frame gain */ + st->Mode2_lp_gainp = L_shl( L_deposit_l( alpha ), 15 ); /*1Q14->2Q29*/ } - tmp_16 = extract_l(L_shl(L_mac(-28000,st->L_frame,95),1-15)); + tmp_16 = extract_l( L_shl( L_mac( -28000, st->L_frame, 95 ), 1 - 15 ) ); tmp_16 = T_DIV_L_Frame[tmp_16]; - tmp_32 = L_mult0(tmp_16 , sub(gain , alpha));/* 0Q15 * 2^-7 * 1Q14 -> 2Q29 * 2^-7*/ - tmp_32 = L_shr(tmp_32,6); /*-> 1Q30*/ - step = round_fx(tmp_32); /*->1Q14*/ + tmp_32 = L_mult0( tmp_16, sub( gain, alpha ) ); /* 0Q15 * 2^-7 * 1Q14 -> 2Q29 * 2^-7*/ + tmp_32 = L_shr( tmp_32, 6 ); /*-> 1Q30*/ + step = round_fx( tmp_32 ); /*->1Q14*/ /*FLC: step: 6.25e-5 .. 0.0045*/ /*-> s_step = -7*/ /*lp_gainp : 0..0.2856..0.98*/ @@ -410,58 +406,59 @@ void con_acelp_fx( move16(); l = 0; move16(); - FOR (i_subfr = 0; i_subfr < st->nb_subfr; i_subfr++) + FOR( i_subfr = 0; i_subfr < st->nb_subfr; i_subfr++ ) { - pgainT[i_subfr] = gain; /*Q14*/ move16(); + pgainT[i_subfr] = gain; /*Q14*/ + move16(); i = l; move16(); - l = add(l, L_SUBFR); - FOR (; i < l; i++) + l = add( l, L_SUBFR ); + FOR( ; i < l; i++ ) { move16(); BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB - exc[i] = mult_r(exc[i], shl_sat(gain, 1)); /*overflow is first iteration because gain may be 1 after shift*/ + exc[i] = mult_r( exc[i], shl_sat( gain, 1 ) ); /*overflow is first iteration because gain may be 1 after shift*/ #else - exc[i] = mult_r(exc[i] , shl(gain,1)); /*overflow is first iteration because gain may be 1 after shift*/ + exc[i] = mult_r( exc[i], shl( gain, 1 ) ); /*overflow is first iteration because gain may be 1 after shift*/ #endif BASOP_SATURATE_WARNING_ON_EVS - gain = sub(gain , step); + gain = sub( gain, step ); } } - l = add(st->L_frame,shr(st->L_frame,1)); - FOR (; i < l; i++ ) + l = add( st->L_frame, shr( st->L_frame, 1 ) ); + FOR( ; i < l; i++ ) { move16(); BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB - exc[i] = mult_r(exc[i] , shl_sat(gain,1)); /*overflow is first iteration because gain may become 1 due to shift*/ + exc[i] = mult_r( exc[i], shl_sat( gain, 1 ) ); /*overflow is first iteration because gain may become 1 due to shift*/ #else - exc[i] = mult_r(exc[i] , shl(gain,1)); /*overflow is first iteration because gain may become 1 due to shift*/ + exc[i] = mult_r( exc[i], shl( gain, 1 ) ); /*overflow is first iteration because gain may become 1 due to shift*/ #endif BASOP_SATURATE_WARNING_ON_EVS - gain = sub(gain , step); + gain = sub( gain, step ); } - FOR (i = 0; i < st->nb_subfr; i ++) + FOR( i = 0; i < st->nb_subfr; i++ ) { - pT[i] = round_fx(pitch_buf[i]); /*Q0*/ - pitch_buffer[i] = round_fx(pitch_buf[i]); + pT[i] = round_fx( pitch_buf[i] ); /*Q0*/ + pitch_buffer[i] = round_fx( pitch_buf[i] ); } /* update old exc without random part*/ - Copy(harmonic_exc_buf+st->L_frame, st->old_exc_fx, L_EXC_MEM_DEC); + Copy( harmonic_exc_buf + st->L_frame, st->old_exc_fx, L_EXC_MEM_DEC ); } ELSE { /* No harmonic part */ - assert( (int)(sizeof(buf)/sizeof(buf[0])) - M - L_EXC_MEM_DEC >= st->L_frame + st->L_frame/2); - set16_fx(&exc[0], 0, add(st->L_frame, shr(st->L_frame,1))); + assert( (int) ( sizeof( buf ) / sizeof( buf[0] ) ) - M - L_EXC_MEM_DEC >= st->L_frame + st->L_frame / 2 ); + set16_fx( &exc[0], 0, add( st->L_frame, shr( st->L_frame, 1 ) ) ); - FOR (i = 0; i < st->nb_subfr; i ++) + FOR( i = 0; i < st->nb_subfr; i++ ) { - pitch_buf[i] = L_deposit_h(st->pit_max); /*15Q16*/ + pitch_buf[i] = L_deposit_h( st->pit_max ); /*15Q16*/ pgainT[i] = 0; move16(); pT[i] = L_SUBFR; @@ -470,7 +467,8 @@ void con_acelp_fx( move16(); } - st->bpf_gain_param = 0; /*no BPF*/ move16(); + st->bpf_gain_param = 0; /*no BPF*/ + move16(); } /*-----------------------------------------------------------------* @@ -485,73 +483,75 @@ void con_acelp_fx( move16(); tmpSeed = st->seed_acelp; move16(); - l = add(st->L_frame,sub(l_fir_fer,1)); - FOR (i = 0; i < l; i++) + l = add( st->L_frame, sub( l_fir_fer, 1 ) ); + FOR( i = 0; i < l; i++ ) { - tmpSeed = own_random2_fx(tmpSeed); - noise_buf[i] = tmpSeed; /*Q0*/ move16(); + tmpSeed = own_random2_fx( tmpSeed ); + noise_buf[i] = tmpSeed; /*Q0*/ + move16(); } st->seed_acelp = tmpSeed; move16(); - l = add(add(st->L_frame,shr(st->L_frame,1)),sub(l_fir_fer,1)); - FOR ( ; i < l; i++) + l = add( add( st->L_frame, shr( st->L_frame, 1 ) ), sub( l_fir_fer, 1 ) ); + FOR( ; i < l; i++ ) { - tmpSeed = own_random2_fx(tmpSeed); - noise_buf[i] = tmpSeed; /*Q0*/ move16(); + tmpSeed = own_random2_fx( tmpSeed ); + noise_buf[i] = tmpSeed; /*Q0*/ + move16(); } /*get filter coefficients*/ - genPlcFiltBWAdap_fx(st->sr_core, /*W32 Q0*/ - &hp_filt[0], /*Q15*/ - 1, - st->cummulative_damping); /*Q15*/ + genPlcFiltBWAdap_fx( st->sr_core, /*W32 Q0*/ + &hp_filt[0], /*Q15*/ + 1, + st->cummulative_damping ); /*Q15*/ /* PLC: [ACELP: Fade-out] * PLC: retrieve background level */ - tmp2 = shl(div_s(st->L_frame,shl(L_SUBFR,3)),3-15); - + tmp2 = shl( div_s( st->L_frame, shl( L_SUBFR, 3 ) ), 3 - 15 ); - tmp = 32767/*1.0f Q15*/; - gainSynthDeemph=getLevelSynDeemph_fx(&(tmp), - A, - M, - L_SUBFR, - st->preemph_fac, - tmp2, - &gainSynthDeemph_e); + tmp = 32767 /*1.0f Q15*/; + gainSynthDeemph = getLevelSynDeemph_fx( &( tmp ), + A, + M, + L_SUBFR, + st->preemph_fac, + tmp2, + &gainSynthDeemph_e ); /*gainCNG=st->cngTDLevel/gainSynthDeemph;*/ - BASOP_Util_Divide_MantExp(st->cngTDLevel, st->cngTDLevel_e, gainSynthDeemph, gainSynthDeemph_e,&gainCNG, &gainCNG_e); - gainCNG_e=sub(gainCNG_e,15-5);/*Q15->Q5*/ - if(gainCNG==0) + BASOP_Util_Divide_MantExp( st->cngTDLevel, st->cngTDLevel_e, gainSynthDeemph, gainSynthDeemph_e, &gainCNG, &gainCNG_e ); + gainCNG_e = sub( gainCNG_e, 15 - 5 ); /*Q15->Q5*/ + if ( gainCNG == 0 ) { gainCNG_e = 0; move16(); } - gain_32 = st->Mode2_lp_gainc; /*15Q16 *//* start-of-the-frame gain */ move16(); + gain_32 = st->Mode2_lp_gainc; /*15Q16 */ /* start-of-the-frame gain */ + move16(); #ifdef BASOP_NOGLOB ftmp = round_fx_sat( L_shl_sat( gain_32, 1 ) ); /*Q0*/ #else - ftmp = round_fx(L_shl(gain_32,1));/*Q0*/ + ftmp = round_fx( L_shl( gain_32, 1 ) ); /*Q0*/ #endif BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB - tmp_16 = sub(shl_sat(gainCNG,sub(gainCNG_e,5/*Q5*/)),ftmp); + tmp_16 = sub( shl_sat( gainCNG, sub( gainCNG_e, 5 /*Q5*/ ) ), ftmp ); #else - tmp_16 = sub(shl(gainCNG,sub(gainCNG_e,5/*Q5*/)),ftmp); + tmp_16 = sub( shl( gainCNG, sub( gainCNG_e, 5 /*Q5*/ ) ), ftmp ); #endif /*in case of overflow:*/ test(); #ifdef BASOP_NOGLOB - if ((EQ_16(shl_sat(ftmp,sub(gainCNG_e,1)),MAXVAL_WORD16))&&(gainCNG==MAXVAL_WORD16)) + if ( ( EQ_16( shl_sat( ftmp, sub( gainCNG_e, 1 ) ), MAXVAL_WORD16 ) ) && ( gainCNG == MAXVAL_WORD16 ) ) #else - if ((EQ_16(shl(ftmp,sub(gainCNG_e,1)),MAXVAL_WORD16))&&(gainCNG==MAXVAL_WORD16)) + if ( ( EQ_16( shl( ftmp, sub( gainCNG_e, 1 ) ), MAXVAL_WORD16 ) ) && ( gainCNG == MAXVAL_WORD16 ) ) #endif { move16(); @@ -559,63 +559,63 @@ void con_acelp_fx( } BASOP_SATURATE_WARNING_ON_EVS - IF (tmp_16 > 0 ) + IF( tmp_16 > 0 ) { - gainCNG = ftmp/*Q0*/; + gainCNG = ftmp /*Q0*/; gainCNG_e = 5; /*-> Q5*/ - s_16 = norm_s(gainCNG); - gainCNG = shl(gainCNG,s_16); - gainCNG_e = sub(gainCNG_e,s_16); + s_16 = norm_s( gainCNG ); + gainCNG = shl( gainCNG, s_16 ); + gainCNG_e = sub( gainCNG_e, s_16 ); } /* end-of-the-frame gain */ /* st->Mode2_lp_gainc = alpha * st->Mode2_lp_gainc + (1.0f - alpha) * gainCNG;*/ - tmp_32 = Mpy_32_16_1(st->Mode2_lp_gainc /*Q16*/,alpha/*Q14*/);/*Q31-16 = Q15*/ - s_32 = norm_l(tmp_32); - tmp_32 = L_shl(tmp_32,s_32); - tmp_16 = round_fx(tmp_32); - s_16 = negate(s_32); - s_16 = sub(s_16,-1-15); /*->Q15*/ - - tmp2 = sub(16384/*1 in Q14*/,alpha); /*Q14*/ - tmp2 = mult(tmp2,gainCNG); /*Q14+Q5 +1 -16 = Q4*/ - s2 = norm_s(tmp2); - tmp2 = shl(tmp2,s2); - s2 = add(negate(s2),gainCNG_e); - s2 = sub(s2,4-15);/*->Q15*/ - - s_16 = BASOP_Util_Add_MantExp(tmp_16,s_16,tmp2,s2,&tmp_16); - st->Mode2_lp_gainc = L_shl(L_deposit_l(tmp_16),add(s_16,1)); + tmp_32 = Mpy_32_16_1( st->Mode2_lp_gainc /*Q16*/, alpha /*Q14*/ ); /*Q31-16 = Q15*/ + s_32 = norm_l( tmp_32 ); + tmp_32 = L_shl( tmp_32, s_32 ); + tmp_16 = round_fx( tmp_32 ); + s_16 = negate( s_32 ); + s_16 = sub( s_16, -1 - 15 ); /*->Q15*/ + + tmp2 = sub( 16384 /*1 in Q14*/, alpha ); /*Q14*/ + tmp2 = mult( tmp2, gainCNG ); /*Q14+Q5 +1 -16 = Q4*/ + s2 = norm_s( tmp2 ); + tmp2 = shl( tmp2, s2 ); + s2 = add( negate( s2 ), gainCNG_e ); + s2 = sub( s2, 4 - 15 ); /*->Q15*/ + + s_16 = BASOP_Util_Add_MantExp( tmp_16, s_16, tmp2, s2, &tmp_16 ); + st->Mode2_lp_gainc = L_shl( L_deposit_l( tmp_16 ), add( s_16, 1 ) ); test(); - IF( (EQ_16(st->last_good, UNVOICED_TRANSITION))&&(EQ_16(coder_type,GENERIC))) + IF( ( EQ_16( st->last_good, UNVOICED_TRANSITION ) ) && ( EQ_16( coder_type, GENERIC ) ) ) { - st->Mode2_lp_gainc = L_deposit_h(gainCNG);/*Q21*/ - st->Mode2_lp_gainc = L_shr(st->Mode2_lp_gainc,sub(5,gainCNG_e)); /*15Q16, no scaling*/ + st->Mode2_lp_gainc = L_deposit_h( gainCNG ); /*Q21*/ + st->Mode2_lp_gainc = L_shr( st->Mode2_lp_gainc, sub( 5, gainCNG_e ) ); /*15Q16, no scaling*/ } - highPassFiltering_fx(st->last_good, add(st->L_frame,shr(l_fir_fer,1)), noise_buf, hp_filt, l_fir_fer); + highPassFiltering_fx( st->last_good, add( st->L_frame, shr( l_fir_fer, 1 ) ), noise_buf, hp_filt, l_fir_fer ); - pt_exc = noise_buf + l_fir_fer/2; + pt_exc = noise_buf + l_fir_fer / 2; /*** Find energy normalization factor ***/ - /*gain_inov = 1.0f / (float)sqrt( dot_product( pt_exc, pt_exc, st->L_frame ) / st->L_frame );*//* normalize energy */ /*<--- FLC*/ + /*gain_inov = 1.0f / (float)sqrt( dot_product( pt_exc, pt_exc, st->L_frame ) / st->L_frame );*/ /* normalize energy */ /*<--- FLC*/ BASOP_SATURATE_WARNING_OFF_EVS /*norm_llQ31 at the end of Dot_productSq16HQ may throw an overflow, but result is okay*/ - tmp_32 = Dot_productSq16HQ(0,pt_exc,st->L_frame,&s_32); + tmp_32 = Dot_productSq16HQ( 0, pt_exc, st->L_frame, &s_32 ); BASOP_SATURATE_WARNING_ON_EVS - s_32 = add(s_32, 31-1); + s_32 = add( s_32, 31 - 1 ); /*scalingfactor is twice the headroom (at noise insertion onto the buffer), -1 (because of mult) +31 (Result is Q31) +s_32 (output scalingfactor of dot_product)*/ - tmp_16 = T_DIV_L_Frame[L_shl(L_mac(-28000,st->L_frame,95),1-15)]; - tmp_32 = Mpy_32_16_1(tmp_32,tmp_16 ); /* Q31 * 2^s_32 * 0Q15 * 2^-7 */ + tmp_16 = T_DIV_L_Frame[L_shl( L_mac( -28000, st->L_frame, 95 ), 1 - 15 )]; + tmp_32 = Mpy_32_16_1( tmp_32, tmp_16 ); /* Q31 * 2^s_32 * 0Q15 * 2^-7 */ - s_32 = sub(s_32,7); /*tmp_32 is Q31 * 2^s_32 */ + s_32 = sub( s_32, 7 ); /*tmp_32 is Q31 * 2^s_32 */ /*assure doing Isqrt not for 0*/ - IF (tmp_32 != 0) + IF( tmp_32 != 0 ) { s_gain_inov = s_32; - tmp_32 = ISqrt32(tmp_32, &s_gain_inov); + tmp_32 = ISqrt32( tmp_32, &s_gain_inov ); } ELSE { @@ -624,30 +624,30 @@ void con_acelp_fx( } - gain_inov = round_fx(tmp_32);/*Inverse sqrt*/ /* Q15 * 2^s_gain_inov */ + gain_inov = round_fx( tmp_32 ); /*Inverse sqrt*/ /* Q15 * 2^s_gain_inov */ /* PLC: [ACELP: Fade-out] * PLC: Linearly attenuate the gain through the frame */ - step_32 = L_sub(gain_32, st->Mode2_lp_gainc); /* 15Q16 */ - tmp_16 = extract_l(L_shl(L_mac(-28000,st->L_frame,95),1-15)); - step_32 = Mpy_32_16_1(step_32, T_DIV_L_Frame[tmp_16]); /* 15Q16 * 2^-7 = 15Q16 * Q15 * 2^-7 */ - step_32 = L_shr(step_32, 7); /* 15Q16 */ + step_32 = L_sub( gain_32, st->Mode2_lp_gainc ); /* 15Q16 */ + tmp_16 = extract_l( L_shl( L_mac( -28000, st->L_frame, 95 ), 1 - 15 ) ); + step_32 = Mpy_32_16_1( step_32, T_DIV_L_Frame[tmp_16] ); /* 15Q16 * 2^-7 = 15Q16 * Q15 * 2^-7 */ + step_32 = L_shr( step_32, 7 ); /* 15Q16 */ test(); - if ((EQ_16(st->last_good ,UNVOICED_CLAS))&&(NE_16(coder_type,UNVOICED))) /* Attenuate somewhat on unstable unvoiced */ + if ( ( EQ_16( st->last_good, UNVOICED_CLAS ) ) && ( NE_16( coder_type, UNVOICED ) ) ) /* Attenuate somewhat on unstable unvoiced */ { - gain_inov = mult_r(gain_inov, 26214/*0.8f Q15*/); /*Q15 * 2^s_gain_inov*/ + gain_inov = mult_r( gain_inov, 26214 /*0.8f Q15*/ ); /*Q15 * 2^s_gain_inov*/ } - IF ( GE_16(st->last_good , UNVOICED_TRANSITION)) + IF( GE_16( st->last_good, UNVOICED_TRANSITION ) ) { Word16 tilt_code; /*tilt_code = (float)(0.10f*(1.0f + st->voice_fac));*/ - tilt_code = mac_r(214748368l/*0.1f Q31*/, 3277/*0.1f Q15*/ , st->voice_fac); + tilt_code = mac_r( 214748368l /*0.1f Q31*/, 3277 /*0.1f Q15*/, st->voice_fac ); - gain_inov = mult_r(gain_inov, sub(32767/*1.0f Q15*/, tilt_code)); /* Q15 * 2^s_gain_inov */ + gain_inov = mult_r( gain_inov, sub( 32767 /*1.0f Q15*/, tilt_code ) ); /* Q15 * 2^s_gain_inov */ } pt_exc = noise_buf; @@ -655,58 +655,62 @@ void con_acelp_fx( /* non-causal ringing of the FIR filter */ /* gain_16 = gain_32 = gain_inov * gain */ - gain_32 = Mpy_32_16_1(gain_32, gain_inov); /* 15Q16 * Q15 * 2^s_gain_inov */ + gain_32 = Mpy_32_16_1( gain_32, gain_inov ); /* 15Q16 * Q15 * 2^s_gain_inov */ #ifdef BASOP_NOGLOB gain_32 = L_shl_sat( gain_32, add( 15, s_gain_inov ) ); /* Q31 */ - gain_16 = round_fx_sat( gain_32 ); /* Q15 */ + gain_16 = round_fx_sat( gain_32 ); /* Q15 */ #else - gain_32 = L_shl(gain_32, add(15, s_gain_inov)); /* Q31 */ - gain_16 = round_fx(gain_32); /* Q15 */ + gain_32 = L_shl( gain_32, add( 15, s_gain_inov ) ); /* Q31 */ + gain_16 = round_fx( gain_32 ); /* Q15 */ #endif /* step_32 = gain_inov * step */ - step_32 = Mpy_32_16_1(step_32, gain_inov); /* 15Q16 * Q15 * 2^s_gain_inov */ - step_32 = L_shl(step_32, add(15, s_gain_inov)); /* Q31 */ + step_32 = Mpy_32_16_1( step_32, gain_inov ); /* 15Q16 * Q15 * 2^s_gain_inov */ + step_32 = L_shl( step_32, add( 15, s_gain_inov ) ); /* Q31 */ #ifdef BASOP_NOGLOB g_e = norm_s( round_fx_sat( L_shl_sat( Mpy_32_16_1( st->Mode2_lp_gainc, gain_inov ), add( 15, s_gain_inov ) ) ) ); /* norm_s for gain*gain_inov at the end of the following loops */ #else - g_e = norm_s(round_fx(L_shl(Mpy_32_16_1(st->Mode2_lp_gainc, gain_inov), add(15, s_gain_inov)))); /* norm_s for gain*gain_inov at the end of the following loops */ + g_e = norm_s( round_fx( L_shl( Mpy_32_16_1( st->Mode2_lp_gainc, gain_inov ), add( 15, s_gain_inov ) ) ) ); /* norm_s for gain*gain_inov at the end of the following loops */ #endif - g_e = s_min(norm_s(gain_16), g_e); - gain_16 = shl(gain_16, g_e); - gain_32 = L_shl(gain_32, g_e); - step_32 = L_shl(step_32, g_e); - l = shr(l_fir_fer,1); - FOR( i=0 ; i < l; i++ ) + g_e = s_min( norm_s( gain_16 ), g_e ); + gain_16 = shl( gain_16, g_e ); + gain_32 = L_shl( gain_32, g_e ); + step_32 = L_shl( step_32, g_e ); + l = shr( l_fir_fer, 1 ); + FOR( i = 0; i < l; i++ ) { /* *pt_exc++ *= (gain_inov * gain); <=> *pt_exc++ *= gain_16; */ /*<-- FLC*/ - *pt_exc = mult_r(*pt_exc , gain_16); /* Q0 = Q0 * Q15 */ move16(); + *pt_exc = mult_r( *pt_exc, gain_16 ); /* Q0 = Q0 * Q15 */ + move16(); pt_exc++; } /* gain -= step; gain is updated after the loop and inside the loop gain_16 = gain_inov * gain is modified using gain_inov * (gain-step) = gain_inov * gain - gain_inov * step */ /*<-- FLC*/ - FOR( i=0 ; i < st->L_frame; i++ ) + FOR( i = 0; i < st->L_frame; i++ ) { /* *pt_exc++ *= (gain_inov * gain); <=> *pt_exc++ *= gain_16; */ /*<-- FLC*/ - *pt_exc = mult_r(*pt_exc , gain_16); /* Q0 = Q0 * Q15 */ move16(); + *pt_exc = mult_r( *pt_exc, gain_16 ); /* Q0 = Q0 * Q15 */ + move16(); pt_exc++; - gain_32 = L_sub(gain_32, step_32); - gain_16 = round_fx(gain_32); + gain_32 = L_sub( gain_32, step_32 ); + gain_16 = round_fx( gain_32 ); } - l = add(shr(st->L_frame,1),l_fir_fer/2); - FOR( i=0 ; i < l; i++ ) + l = add( shr( st->L_frame, 1 ), l_fir_fer / 2 ); + FOR( i = 0; i < l; i++ ) { /* *pt_exc++ *= (gain_inov * gain); <=> *pt_exc++ *= gain_16; */ /*<-- FLC*/ - *pt_exc = mult_r(*pt_exc , gain_16); /* Q0 = Q0 * Q15 */ move16(); + *pt_exc = mult_r( *pt_exc, gain_16 ); /* Q0 = Q0 * Q15 */ + move16(); pt_exc++; } /*store st->past_gcode*/ /* at this point gain is equal to st->Mode2_lp_gainc, so we don't need to calculate gain at all */ - st->past_gcode = st->Mode2_lp_gainc; /*15Q16 */ move16(); + st->past_gcode = st->Mode2_lp_gainc; /*15Q16 */ + move16(); /*-----------------------------------------------------------------* * PLC: [ACELP: general] @@ -715,36 +719,36 @@ void con_acelp_fx( IF( st->last_good < UNVOICED_TRANSITION ) { - bufferCopyFx(noise_buf+l_fir_fer/2, exc, add(st->L_frame,shr(st->L_frame,1)), 0, *Qf_exc, negate(g_e), 0); /*copy between different formats*/ - Copy(harmonic_exc_buf+st->L_frame, st->old_exc_fx, L_EXC_MEM_DEC); - Copy(exc, exc_unv, add(st->L_frame, shr(st->L_frame,1))); /* Update exc_unv */ + bufferCopyFx( noise_buf + l_fir_fer / 2, exc, add( st->L_frame, shr( st->L_frame, 1 ) ), 0, *Qf_exc, negate( g_e ), 0 ); /*copy between different formats*/ + Copy( harmonic_exc_buf + st->L_frame, st->old_exc_fx, L_EXC_MEM_DEC ); + Copy( exc, exc_unv, add( st->L_frame, shr( st->L_frame, 1 ) ) ); /* Update exc_unv */ } ELSE { /* Update exc_unv */ - bufferCopyFx(noise_buf+l_fir_fer/2, exc_unv, add(st->L_frame,shr(st->L_frame,1)), 0, *Qf_exc, negate(g_e), 0); /*copy between different formats*/ + bufferCopyFx( noise_buf + l_fir_fer / 2, exc_unv, add( st->L_frame, shr( st->L_frame, 1 ) ), 0, *Qf_exc, negate( g_e ), 0 ); /*copy between different formats*/ } /* Compute total excitation in noisebuffer to save memories */ - IF( GE_16( st->last_good, UNVOICED_TRANSITION )) + IF( GE_16( st->last_good, UNVOICED_TRANSITION ) ) { - Vr_add(exc, exc_unv, noise_buf, add(st->L_frame, 1)); + Vr_add( exc, exc_unv, noise_buf, add( st->L_frame, 1 ) ); } ELSE { noise_buf = exc_unv; } - IF(st->hBWE_TD != NULL) + IF( st->hBWE_TD != NULL ) { - IF(EQ_16(st->L_frame, L_FRAME)) + IF( EQ_16( st->L_frame, L_FRAME ) ) { - interp_code_5over2_fx(noise_buf, bwe_exc, st->L_frame); - set16_fx(voice_factors, st->last_voice_factor_fx, NB_SUBFR); + interp_code_5over2_fx( noise_buf, bwe_exc, st->L_frame ); + set16_fx( voice_factors, st->last_voice_factor_fx, NB_SUBFR ); } ELSE { - interp_code_4over2_fx(noise_buf, bwe_exc, st->L_frame); - set16_fx(voice_factors, st->last_voice_factor_fx, NB_SUBFR16k); + interp_code_4over2_fx( noise_buf, bwe_exc, st->L_frame ); + set16_fx( voice_factors, st->last_voice_factor_fx, NB_SUBFR16k ); } } /*----------------------------------------------------------* @@ -753,13 +757,13 @@ void con_acelp_fx( /* Init syn buffer */ syn = buf + M; - Copy(st->mem_syn2_fx, buf, M ); + Copy( st->mem_syn2_fx, buf, M ); - IF (EQ_16(st->nbLostCmpt,1)) + IF( EQ_16( st->nbLostCmpt, 1 ) ) { IF( st->last_good < UNVOICED_TRANSITION ) { - Copy(st->mem_syn2_fx, mem_syn_unv, M ); + Copy( st->mem_syn2_fx, mem_syn_unv, M ); } ELSE { @@ -772,56 +776,56 @@ void con_acelp_fx( } /* voiced synth */ - IF(st->last_good >= UNVOICED_TRANSITION) + IF( st->last_good >= UNVOICED_TRANSITION ) { p_A = A; - FOR (i_subfr = 0; i_subfr < st->L_frame; i_subfr += L_SUBFR) + FOR( i_subfr = 0; i_subfr < st->L_frame; i_subfr += L_SUBFR ) { tmp = 0; move16(); - set16_fx(h1, 0, L_SUBFR+1); - set16_fx(mem, 0, M); - h1[0] = 1024/*1.0f/((float)(1 << scale_h1)) Q15*/; + set16_fx( h1, 0, L_SUBFR + 1 ); + set16_fx( mem, 0, M ); + h1[0] = 1024 /*1.0f/((float)(1 << scale_h1)) Q15*/; move16(); - E_UTIL_synthesis(0, p_A, h1, h1, L_SUBFR, mem, 0, M); /* impulse response of LPC */ - deemph_fx(h1, st->preemph_fac, L_SUBFR, &tmp); /* impulse response of deemph */ + E_UTIL_synthesis( 0, p_A, h1, h1, L_SUBFR, mem, 0, M ); /* impulse response of LPC */ + deemph_fx( h1, st->preemph_fac, L_SUBFR, &tmp ); /* impulse response of deemph */ /* impulse response level = gain introduced by synthesis+deemphasis */ /* gain_lpc[i_subfr/L_SUBFR] = 1.f/(float)sqrt(dotp( h1, h1, L_SUBFR)); */ - tmp_32 = Dot_productSq16HQ(0, h1, L_SUBFR, &gain_lpc_e[i_subfr/L_SUBFR]); - tmp_32 = L_max(tmp_32, 1); - gain_lpc_e[i_subfr/L_SUBFR] = add(gain_lpc_e[i_subfr/L_SUBFR], 2*scale_h1); + tmp_32 = Dot_productSq16HQ( 0, h1, L_SUBFR, &gain_lpc_e[i_subfr / L_SUBFR] ); + tmp_32 = L_max( tmp_32, 1 ); + gain_lpc_e[i_subfr / L_SUBFR] = add( gain_lpc_e[i_subfr / L_SUBFR], 2 * scale_h1 ); move16(); - gain_lpc[i_subfr/L_SUBFR] = round_fx(ISqrt32(tmp_32, &gain_lpc_e[i_subfr/L_SUBFR])); + gain_lpc[i_subfr / L_SUBFR] = round_fx( ISqrt32( tmp_32, &gain_lpc_e[i_subfr / L_SUBFR] ) ); - p_A += (M+1); /* Pointer move */ + p_A += ( M + 1 ); /* Pointer move */ } g = 0; move16(); - FOR (i_subfr = 0; i_subfr < st->L_frame; i_subfr += L_SUBFR) + FOR( i_subfr = 0; i_subfr < st->L_frame; i_subfr += L_SUBFR ) { - g = mult_r(st->last_gain_syn_deemph, gain_lpc[i_subfr/L_SUBFR]); + g = mult_r( st->last_gain_syn_deemph, gain_lpc[i_subfr / L_SUBFR] ); #ifdef BASOP_NOGLOB - g_e = add_sat(st->last_gain_syn_deemph_e, gain_lpc_e[i_subfr / L_SUBFR]); - g = shl_sat(g, g_e); + g_e = add_sat( st->last_gain_syn_deemph_e, gain_lpc_e[i_subfr / L_SUBFR] ); + g = shl_sat( g, g_e ); #else - g_e = add(st->last_gain_syn_deemph_e, gain_lpc_e[i_subfr/L_SUBFR]); - g = shl(g, g_e); + g_e = add( st->last_gain_syn_deemph_e, gain_lpc_e[i_subfr / L_SUBFR] ); + g = shl( g, g_e ); #endif - FOR (i=0; i < L_SUBFR; i++) + FOR( i = 0; i < L_SUBFR; i++ ) { /* exc[i_subfr + i] *= st->last_gain_syn_deemph*gain_lpc[j]; */ - exc[i_subfr + i] = mult_r(exc[i_subfr + i], g); + exc[i_subfr + i] = mult_r( exc[i_subfr + i], g ); move16(); } } - l = add(st->L_frame, shr(st->L_frame, 1)); - FOR (i = st->L_frame; i < l; i++) + l = add( st->L_frame, shr( st->L_frame, 1 ) ); + FOR( i = st->L_frame; i < l; i++ ) { - exc[i] = mult_r(exc[i], g); + exc[i] = mult_r( exc[i], g ); move16(); } @@ -830,31 +834,31 @@ void con_acelp_fx( move16(); Qf_syn = *Qf_mem_syn; move16(); - rescale_mem(Qf_exc, &Qf_syn_new, &Qf_syn, mem_syn, NULL, M, st->L_frame); - synthScaling = sub(*Qf_exc,Qf_syn); + rescale_mem( Qf_exc, &Qf_syn_new, &Qf_syn, mem_syn, NULL, M, st->L_frame ); + synthScaling = sub( *Qf_exc, Qf_syn ); p_A = A; /*in case of more than 5 consecutive concealed frames, improve precision of synthesis*/ - memsynPrecission_fx(st->nbLostCmpt,mem_syn, exc, st->L_frame, &s_16); - FOR (i_subfr = 0; i_subfr < st->L_frame; i_subfr += L_SUBFR) + memsynPrecission_fx( st->nbLostCmpt, mem_syn, exc, st->L_frame, &s_16 ); + FOR( i_subfr = 0; i_subfr < st->L_frame; i_subfr += L_SUBFR ) { - E_UTIL_synthesis(synthScaling, p_A, &exc[i_subfr], &syn[i_subfr], L_SUBFR, mem_syn, 1, M); - p_A += (M+1); + E_UTIL_synthesis( synthScaling, p_A, &exc[i_subfr], &syn[i_subfr], L_SUBFR, mem_syn, 1, M ); + p_A += ( M + 1 ); } Copy( mem_syn, mem_syn2, M ); /* synthesize ola*/ - E_UTIL_synthesis(synthScaling, p_A-(M+1), &exc[i_subfr], &syn[i_subfr], (st->L_frame/2), mem_syn2, 0, M); + E_UTIL_synthesis( synthScaling, p_A - ( M + 1 ), &exc[i_subfr], &syn[i_subfr], ( st->L_frame / 2 ), mem_syn2, 0, M ); } test(); - IF(GT_16(st->nbLostCmpt,5)&&(s_16>0)) + IF( GT_16( st->nbLostCmpt, 5 ) && ( s_16 > 0 ) ) { /*scale back mem_syn, exc and synthesis*/ - Scale_sig(mem_syn,M,negate(s_16)); - Scale_sig(syn, add(shr(st->L_frame,1),st->L_frame) ,negate(s_16)); + Scale_sig( mem_syn, M, negate( s_16 ) ); + Scale_sig( syn, add( shr( st->L_frame, 1 ), st->L_frame ), negate( s_16 ) ); /*Scale_sig(exc, add(shr(st->L_frame,1),st->L_frame) ,negate(s_16));*/ } @@ -865,48 +869,48 @@ void con_acelp_fx( move16(); p_A = st->Aq_cng; - FOR (i_subfr = 0; i_subfr < st->L_frame; i_subfr += L_SUBFR) + FOR( i_subfr = 0; i_subfr < st->L_frame; i_subfr += L_SUBFR ) { - set16_fx(h1, 0, L_SUBFR+1); - set16_fx(mem, 0, M); - h1[0] = 1024/*1.0f/((float)(1 << scale_h1)) Q15*/; + set16_fx( h1, 0, L_SUBFR + 1 ); + set16_fx( mem, 0, M ); + h1[0] = 1024 /*1.0f/((float)(1 << scale_h1)) Q15*/; move16(); - E_UTIL_synthesis(0, p_A, h1, h1, L_SUBFR, mem, 0, M); /* impulse response of LPC */ - deemph_fx(h1, st->preemph_fac, L_SUBFR, &tmp); /* impulse response of deemph */ + E_UTIL_synthesis( 0, p_A, h1, h1, L_SUBFR, mem, 0, M ); /* impulse response of LPC */ + deemph_fx( h1, st->preemph_fac, L_SUBFR, &tmp ); /* impulse response of deemph */ /* impulse response level = gain introduced by synthesis+deemphasis */ /* gain_lpc[i_subfr/L_SUBFR] = 1.f/(float)sqrt(dotp( h1, h1, L_SUBFR)); */ - tmp_32 = Dot_productSq16HQ(0, h1, L_SUBFR, &gain_lpc_e[i_subfr/L_SUBFR]); - tmp_32 = L_max(tmp_32, 1); - gain_lpc_e[i_subfr/L_SUBFR] = add(gain_lpc_e[i_subfr/L_SUBFR], 2*scale_h1); + tmp_32 = Dot_productSq16HQ( 0, h1, L_SUBFR, &gain_lpc_e[i_subfr / L_SUBFR] ); + tmp_32 = L_max( tmp_32, 1 ); + gain_lpc_e[i_subfr / L_SUBFR] = add( gain_lpc_e[i_subfr / L_SUBFR], 2 * scale_h1 ); move16(); - gain_lpc[i_subfr/L_SUBFR] = round_fx(ISqrt32(tmp_32, &gain_lpc_e[i_subfr/L_SUBFR])); + gain_lpc[i_subfr / L_SUBFR] = round_fx( ISqrt32( tmp_32, &gain_lpc_e[i_subfr / L_SUBFR] ) ); - p_A += (M+1); /* Pointer move */ + p_A += ( M + 1 ); /* Pointer move */ } g = 0; move16(); - FOR (i_subfr = 0; i_subfr < st->L_frame; i_subfr += L_SUBFR) + FOR( i_subfr = 0; i_subfr < st->L_frame; i_subfr += L_SUBFR ) { - g = mult_r(st->last_gain_syn_deemph, gain_lpc[i_subfr/L_SUBFR]); - g_e = add(st->last_gain_syn_deemph_e, gain_lpc_e[i_subfr/L_SUBFR]); + g = mult_r( st->last_gain_syn_deemph, gain_lpc[i_subfr / L_SUBFR] ); + g_e = add( st->last_gain_syn_deemph_e, gain_lpc_e[i_subfr / L_SUBFR] ); #ifdef BASOP_NOGLOB - g = shl_sat(g, g_e); + g = shl_sat( g, g_e ); #else - g = shl(g, g_e); + g = shl( g, g_e ); #endif - FOR (i=0; i < L_SUBFR; i++) + FOR( i = 0; i < L_SUBFR; i++ ) { /* exc[i_subfr + i] *= st->last_gain_syn_deemph*gain_lpc[j]; */ - exc_unv[i_subfr + i] = mult_r(exc_unv[i_subfr + i], g); + exc_unv[i_subfr + i] = mult_r( exc_unv[i_subfr + i], g ); move16(); } } - l = add(st->L_frame, shr(st->L_frame, 1)); - FOR (i = st->L_frame; i < l; i++) + l = add( st->L_frame, shr( st->L_frame, 1 ) ); + FOR( i = st->L_frame; i < l; i++ ) { - exc_unv[i] = mult_r(exc_unv[i], g); + exc_unv[i] = mult_r( exc_unv[i], g ); move16(); } @@ -915,65 +919,65 @@ void con_acelp_fx( move16(); Qf_syn = *Qf_mem_syn; move16(); - rescale_mem(Qf_exc, &Qf_syn_new, &Qf_syn, mem_syn_unv, NULL, M, st->L_frame); - synthScaling = sub(*Qf_exc,Qf_syn); + rescale_mem( Qf_exc, &Qf_syn_new, &Qf_syn, mem_syn_unv, NULL, M, st->L_frame ); + synthScaling = sub( *Qf_exc, Qf_syn ); *Qf_mem_syn = Qf_syn; p_A = st->Aq_cng; /*in case of more than 5 consecutive concealed frames, improve precision of synthesis*/ - memsynPrecission_fx(st->nbLostCmpt,mem_syn_unv, exc_unv, st->L_frame, &s_16); + memsynPrecission_fx( st->nbLostCmpt, mem_syn_unv, exc_unv, st->L_frame, &s_16 ); - FOR (i_subfr = 0; i_subfr < st->L_frame; i_subfr += L_SUBFR) + FOR( i_subfr = 0; i_subfr < st->L_frame; i_subfr += L_SUBFR ) { - E_UTIL_synthesis(synthScaling, p_A, &exc_unv[i_subfr], &syn_unv[i_subfr], L_SUBFR, mem_syn_unv, 1, M); - p_A += (M+1); + E_UTIL_synthesis( synthScaling, p_A, &exc_unv[i_subfr], &syn_unv[i_subfr], L_SUBFR, mem_syn_unv, 1, M ); + p_A += ( M + 1 ); } - Copy(mem_syn_unv,st->mem_syn_unv_back,M); + Copy( mem_syn_unv, st->mem_syn_unv_back, M ); - IF(LT_16(st->last_good,UNVOICED_TRANSITION)) + IF( LT_16( st->last_good, UNVOICED_TRANSITION ) ) { - Copy(mem_syn_unv,mem_syn,M); + Copy( mem_syn_unv, mem_syn, M ); /* unvoiced for ola */ - E_UTIL_synthesis(synthScaling, p_A-(M+1), &exc_unv[i_subfr], &syn_unv[i_subfr], shr(st->L_frame,1), mem_syn_unv, 0, M); + E_UTIL_synthesis( synthScaling, p_A - ( M + 1 ), &exc_unv[i_subfr], &syn_unv[i_subfr], shr( st->L_frame, 1 ), mem_syn_unv, 0, M ); } test(); - IF(GT_16(st->nbLostCmpt,5)&&(s_16>0)) + IF( GT_16( st->nbLostCmpt, 5 ) && ( s_16 > 0 ) ) { /*scale back mem_syn_unv, exc_unv and synthesis*/ - Scale_sig(mem_syn_unv,M,negate(s_16)); - IF(LT_16(st->last_good,UNVOICED_TRANSITION)) + Scale_sig( mem_syn_unv, M, negate( s_16 ) ); + IF( LT_16( st->last_good, UNVOICED_TRANSITION ) ) { - Scale_sig(mem_syn,M,negate(s_16)); - Scale_sig(syn_unv, add(shr(st->L_frame,1),st->L_frame) ,negate(s_16)); + Scale_sig( mem_syn, M, negate( s_16 ) ); + Scale_sig( syn_unv, add( shr( st->L_frame, 1 ), st->L_frame ), negate( s_16 ) ); } ELSE { - Scale_sig(syn_unv, st->L_frame ,negate(s_16)); + Scale_sig( syn_unv, st->L_frame, negate( s_16 ) ); } - Scale_sig(st->mem_syn_unv_back,M,negate(s_16)); + Scale_sig( st->mem_syn_unv_back, M, negate( s_16 ) ); /*Scale_sig(exc_unv, add(shr(st->L_frame,1),st->L_frame) ,negate(s_16));*/ } /* add separate synthesis buffers */ - IF (GE_16(st->last_good,UNVOICED_TRANSITION)) + IF( GE_16( st->last_good, UNVOICED_TRANSITION ) ) { - FOR( i=0 ; i < st->L_frame; i++ ) + FOR( i = 0; i < st->L_frame; i++ ) { #ifdef BASOP_NOGLOB syn[i] = add_sat( syn[i], syn_unv[i] ); #else - syn[i] = add(syn[i], syn_unv[i]); + syn[i] = add( syn[i], syn_unv[i] ); #endif move16(); } } ELSE { - Copy(syn_unv,syn,add(st->L_frame, shr(st->L_frame,1))); + Copy( syn_unv, syn, add( st->L_frame, shr( st->L_frame, 1 ) ) ); } @@ -981,155 +985,152 @@ void con_acelp_fx( { Word16 pit16[NB_SUBFR16k]; Word16 k; - FOR(k = 0 ; k < st->nb_subfr; k++) + FOR( k = 0; k < st->nb_subfr; k++ ) { - pit16[k] = shl(extract_h(pitch_buf[k]),6);/*Q6*/ + pit16[k] = shl( extract_h( pitch_buf[k] ), 6 ); /*Q6*/ } FEC_clas_estim_fx( st, - /*Opt_AMR_WB*/0, /*A*/ + /*Opt_AMR_WB*/ 0, /*A*/ st->L_frame, - &(st->clas_dec), + &( st->clas_dec ), coder_type, pit16, syn, &st->lp_ener_FER_fx, - /**decision_hyst*/NULL, /* i/o: hysteresis of the music/speech decision */ - /**UV_cnt*/ NULL, /* i/o: number of consecutives frames classified as UV */ - /**LT_UV_cnt*/ NULL, /* i/o: long term consecutives frames classified as UV */ - /**Last_ener*/ NULL, /* i/o: last_energy frame */ - /**locattack*/ NULL, /* i/o: detection of attack (mainly to localized speech burst) */ - /**lt_diff_etot*/NULL, /* i/o: long-term total energy variation */ - /**amr_io_class*/ NULL, /* i/o: classification for AMR-WB IO mode */ - /*bitrate*/ 0 , /* i : Decoded bitrate */ - Qf_syn, /* i : Synthesis scaling */ - /**class_para*/ NULL, /* o : classification para. fmerit1 */ - st->mem_syn_clas_estim_fx, /* i/o: memory of the synthesis signal for frame class estimation */ + /**decision_hyst*/ NULL, /* i/o: hysteresis of the music/speech decision */ + /**UV_cnt*/ NULL, /* i/o: number of consecutives frames classified as UV */ + /**LT_UV_cnt*/ NULL, /* i/o: long term consecutives frames classified as UV */ + /**Last_ener*/ NULL, /* i/o: last_energy frame */ + /**locattack*/ NULL, /* i/o: detection of attack (mainly to localized speech burst) */ + /**lt_diff_etot*/ NULL, /* i/o: long-term total energy variation */ + /**amr_io_class*/ NULL, /* i/o: classification for AMR-WB IO mode */ + /*bitrate*/ 0, /* i : Decoded bitrate */ + Qf_syn, /* i : Synthesis scaling */ + /**class_para*/ NULL, /* o : classification para. fmerit1 */ + st->mem_syn_clas_estim_fx, /* i/o: memory of the synthesis signal for frame class estimation */ &st->classifier_Q_mem_syn, /*i/o : exponent for memory of synthesis signal for frame class estimation */ - -32768/*-1.f Q15*/, /* i : LTP Gain */ - 0/*CLASSIFIER_ACELP*/, /* i : signal classifier mode */ - 1/*bfi*/, /* i : bad frame indicator */ - st->last_core_brate, /* i : bitrate of previous frame */ - -1 - ); + -32768 /*-1.f Q15*/, /* i : LTP Gain */ + 0 /*CLASSIFIER_ACELP*/, /* i : signal classifier mode */ + 1 /*bfi*/, /* i : bad frame indicator */ + st->last_core_brate, /* i : bitrate of previous frame */ + -1 ); } /* Update Pitch Lag memory */ - Copy32(&st->old_pitch_buf_fx[st->nb_subfr], st->old_pitch_buf_fx, st->nb_subfr); - Copy32(pitch_buf, &st->old_pitch_buf_fx[st->nb_subfr], st->nb_subfr); + Copy32( &st->old_pitch_buf_fx[st->nb_subfr], st->old_pitch_buf_fx, st->nb_subfr ); + Copy32( pitch_buf, &st->old_pitch_buf_fx[st->nb_subfr], st->nb_subfr ); /*updating enr_old parameters*/ - frame_ener_fx( st->L_frame, st->last_good, syn, round_fx(tmp_tc), &(st->enr_old_fx), 1, 0, 0, 0 ); + frame_ener_fx( st->L_frame, st->last_good, syn, round_fx( tmp_tc ), &( st->enr_old_fx ), 1, 0, 0, 0 ); #ifdef BASOP_NOGLOB st->enr_old_fx = L_shl_sat( st->enr_old_fx, shl( negate( Qf_syn ), 1 ) ); #else - st->enr_old_fx = L_shl(st->enr_old_fx,shl(negate(Qf_syn),1)); + st->enr_old_fx = L_shl( st->enr_old_fx, shl( negate( Qf_syn ), 1 ) ); #endif /* update ACELP synthesis memory */ - Copy(mem_syn, st->mem_syn2_fx , M); - Copy(syn+st->L_frame-L_SYN_MEM, st->mem_syn_r , L_SYN_MEM); + Copy( mem_syn, st->mem_syn2_fx, M ); + Copy( syn + st->L_frame - L_SYN_MEM, st->mem_syn_r, L_SYN_MEM ); - /*Q_mem_syn_new = Q_mem_syn;*//*NOT "+synthScaling", cause mem_syn format is not changed*/ + /*Q_mem_syn_new = Q_mem_syn;*/ /*NOT "+synthScaling", cause mem_syn format is not changed*/ /* Deemphasis and output synth */ tmp_deemph = st->syn[M]; - E_UTIL_deemph2(*Qf_mem_syn, syn, st->preemph_fac, add(st->L_frame,shr(st->L_frame,1)), &tmp_deemph); + E_UTIL_deemph2( *Qf_mem_syn, syn, st->preemph_fac, add( st->L_frame, shr( st->L_frame, 1 ) ), &tmp_deemph ); - Copy(syn, synth, st->L_frame); + Copy( syn, synth, st->L_frame ); - bufferCopyFx(syn+st->L_frame-st->L_frame/2, hTcxDec->old_syn_Overl, shr(st->L_frame,1),0 /*Qf_syn*/, -1 /*Qf_old_xnq*/, 0 , 0 /*Q_old_xnq*/); + bufferCopyFx( syn + st->L_frame - st->L_frame / 2, hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), 0 /*Qf_syn*/, -1 /*Qf_old_xnq*/, 0, 0 /*Q_old_xnq*/ ); /* save last half frame if next frame is TCX */ - bufferCopyFx(syn+st->L_frame, hTcxDec->syn_Overl_TDAC, shr(st->L_frame,1),0 /*Qf_syn*/, -1 /*Qf_old_xnq*/, 0 , 0 /*Q_old_xnq*/ ); - Copy(syn+st->L_frame-M-1, st->syn, add(1,M)); + bufferCopyFx( syn + st->L_frame, hTcxDec->syn_Overl_TDAC, shr( st->L_frame, 1 ), 0 /*Qf_syn*/, -1 /*Qf_old_xnq*/, 0, 0 /*Q_old_xnq*/ ); + Copy( syn + st->L_frame - M - 1, st->syn, add( 1, M ) ); /* update old_Aq */ - Copy(p_A-(M+1), st->old_Aq_12_8_fx, add(M,1)); + Copy( p_A - ( M + 1 ), st->old_Aq_12_8_fx, add( M, 1 ) ); - Copy(syn+st->L_frame, hTcxDec->syn_Overl, shr(st->L_frame,1)); + Copy( syn + st->L_frame, hTcxDec->syn_Overl, shr( st->L_frame, 1 ) ); /* create aliasing and windowing */ W1 = st->hTcxCfg->tcx_mdct_window_length; move16(); - W2 = shr(W1,1); + W2 = shr( W1, 1 ); st->hTcxCfg->tcx_curr_overlap_mode = FULL_OVERLAP; move16(); - n = extract_h(L_mult(st->L_frame,9216/*(float)N_ZERO_MDCT_NS/(float)FRAME_SIZE_NS Q15*/)); + n = extract_h( L_mult( st->L_frame, 9216 /*(float)N_ZERO_MDCT_NS/(float)FRAME_SIZE_NS Q15*/ ) ); - hHQ_core->Q_old_wtda_LB = getScaleFactor16(syn+st->L_frame-n, - sub(st->L_frame,n)); + hHQ_core->Q_old_wtda_LB = getScaleFactor16( syn + st->L_frame - n, + sub( st->L_frame, n ) ); move16(); - bufferCopyFx(syn+st->L_frame-n, hHQ_core->old_out_LB_fx, sub(st->L_frame, n), 0, 0, hHQ_core->Q_old_wtda_LB, 0); - FOR (i=0; i < W2; i++) + bufferCopyFx( syn + st->L_frame - n, hHQ_core->old_out_LB_fx, sub( st->L_frame, n ), 0, 0, hHQ_core->Q_old_wtda_LB, 0 ); + FOR( i = 0; i < W2; i++ ) { - hHQ_core->old_out_LB_fx[i+n] = round_fx(Mpy_32_16_1(L_mult(w[i].v.re,w[i].v.re), hHQ_core->old_out_LB_fx[i+n])); + hHQ_core->old_out_LB_fx[i + n] = round_fx( Mpy_32_16_1( L_mult( w[i].v.re, w[i].v.re ), hHQ_core->old_out_LB_fx[i + n] ) ); } - FOR ( ; i < W1; i++) + FOR( ; i < W1; i++ ) { - hHQ_core->old_out_LB_fx[i+n] = round_fx(Mpy_32_16_1(L_mult(w[W2-1-(i-W2)].v.im,w[W2-1-(i-W2)].v.im), hHQ_core->old_out_LB_fx[i+n])); + hHQ_core->old_out_LB_fx[i + n] = round_fx( Mpy_32_16_1( L_mult( w[W2 - 1 - ( i - W2 )].v.im, w[W2 - 1 - ( i - W2 )].v.im ), hHQ_core->old_out_LB_fx[i + n] ) ); } - set16_fx(&hHQ_core->old_out_LB_fx[W1+n], 0, n); + set16_fx( &hHQ_core->old_out_LB_fx[W1 + n], 0, n ); hHQ_core->Q_old_wtda = hHQ_core->Q_old_wtda_LB; - - FOR (i=0; isyn_Overl_TDAC[i],w[i].v.re); - + buf[i] = mult_r( hTcxDec->syn_Overl_TDAC[i], w[i].v.re ); } - FOR(; isyn_Overl_TDAC[i],w[W1-1-i].v.im); + buf[i] = mult_r( hTcxDec->syn_Overl_TDAC[i], w[W1 - 1 - i].v.im ); } - FOR (i=0; isyn_Overl_TDAC[i] = add(buf[i],buf[W1-1-i]); /* A-D */ + hTcxDec->syn_Overl_TDAC[i] = add( buf[i], buf[W1 - 1 - i] ); /* A-D */ } /*-2*/ - FOR (i=0; isyn_Overl_TDAC[W2+i] = add(buf[W2+i],buf[W1-1-W2-i]);/* B-C */ + hTcxDec->syn_Overl_TDAC[W2 + i] = add( buf[W2 + i], buf[W1 - 1 - W2 - i] ); /* B-C */ } - FOR (i=0; isyn_Overl_TDAC[i] = mult_r(hTcxDec->syn_Overl_TDAC[i],w[i].v.re); + hTcxDec->syn_Overl_TDAC[i] = mult_r( hTcxDec->syn_Overl_TDAC[i], w[i].v.re ); } - FOR(; isyn_Overl_TDAC[i] = mult_r(hTcxDec->syn_Overl_TDAC[i],w[W1-1-i].v.im); + hTcxDec->syn_Overl_TDAC[i] = mult_r( hTcxDec->syn_Overl_TDAC[i], w[W1 - 1 - i].v.im ); } /* update memory for full band */ - lerp(hTcxDec->syn_Overl_TDAC, hTcxDec->syn_Overl_TDACFB, shr(hTcxDec->L_frameTCX, 1), shr(st->L_frame, 1)); - lerp(hTcxDec->syn_Overl, hTcxDec->syn_OverlFB, shr(hTcxDec->L_frameTCX, 1), shr(st->L_frame, 1)); - lerp(hHQ_core->old_out_LB_fx, hHQ_core->old_out_fx, hTcxDec->L_frameTCX, st->L_frame); + lerp( hTcxDec->syn_Overl_TDAC, hTcxDec->syn_Overl_TDACFB, shr( hTcxDec->L_frameTCX, 1 ), shr( st->L_frame, 1 ) ); + lerp( hTcxDec->syn_Overl, hTcxDec->syn_OverlFB, shr( hTcxDec->L_frameTCX, 1 ), shr( st->L_frame, 1 ) ); + lerp( hHQ_core->old_out_LB_fx, hHQ_core->old_out_fx, hTcxDec->L_frameTCX, st->L_frame ); /* copy total excitation exc2 as 16kHz for acelp mode1 decoding */ - IF(st->hWIDec != NULL) + IF( st->hWIDec != NULL ) { - lerp(exc, st->hWIDec->old_exc2_fx, L_EXC_MEM, st->L_frame); - lerp(syn, st->hWIDec->old_syn2_fx, L_EXC_MEM, st->L_frame); + lerp( exc, st->hWIDec->old_exc2_fx, L_EXC_MEM, st->L_frame ); + lerp( syn, st->hWIDec->old_syn2_fx, L_EXC_MEM, st->L_frame ); } - st->bfi_pitch_fx = shl(round_fx(pitch_buf[st->nb_subfr-1]),6); + st->bfi_pitch_fx = shl( round_fx( pitch_buf[st->nb_subfr - 1] ), 6 ); move16(); st->bfi_pitch_frame = st->L_frame; move16(); @@ -1137,11 +1138,11 @@ void con_acelp_fx( return; } -static void memsynPrecission_fx(Word16 nbLostCmpt,Word16* mem_syn, Word16* exc, Word16 len, Word16*s_16) +static void memsynPrecission_fx( Word16 nbLostCmpt, Word16 *mem_syn, Word16 *exc, Word16 len, Word16 *s_16 ) { - IF(GT_16(nbLostCmpt,5)) + IF( GT_16( nbLostCmpt, 5 ) ) { - Word16 sf_mem_syn, sf_exc,k, tmp_loop, max, tmp, i; + Word16 sf_mem_syn, sf_exc, k, tmp_loop, max, tmp, i; tmp = 0; move16(); *s_16 = 0; @@ -1150,39 +1151,38 @@ static void memsynPrecission_fx(Word16 nbLostCmpt,Word16* mem_syn, Word16* exc, move16(); /*check energy of mem_syn*/ - FOR(i=0; i 0 ) + IF( abs_s( tmp ) > 0 ) { - sf_mem_syn = getScaleFactor16(mem_syn,M); + sf_mem_syn = getScaleFactor16( mem_syn, M ); /*sf_exc = getScaleFactor16(exc, add(shr(len,1),len));*/ /*this returns 0 if signal is 0*/ - tmp_loop = add(shr(len,1),len); - FOR(k=0; knbLostCmpt, st->last_good, old_pitch_buf, &( st->old_fpitchFB_float ), &predPitchLag, hTcxDec->pit_min_TCX, hTcxDec->pit_max_TCX, st->mem_pitch_gain_float, st->output_Fs > 25600, st->plc_use_future_lag, &extrapolationFailed, st->nb_subfr ); + pitch_pred_linear_fit_flt( st->nbLostCmpt, st->last_good, old_pitch_buf, &( st->old_fpitchFB_float ), &predPitchLag, hTcxDec->pit_min_TCX, hTcxDec->pit_max_TCX, st->mem_pitch_gain_float, st->output_Fs > 25600, st->plc_use_future_lag, &extrapolationFailed, st->nb_subfr ); T0 = (int16_t) ( predPitchLag + 0.5f ); @@ -249,9 +249,9 @@ void con_tcx( if ( fUseExtrapolatedPitch != 0 ) { - get_subframe_pitch_flt( st->nb_subfr, st->old_fpitch_float, predPitchLag * st->L_frame / L_frame, pitch_buf ); + get_subframe_pitch_flt( st->nb_subfr, st->old_fpitch_float, predPitchLag * st->L_frame / L_frame, pitch_buf ); - PulseResynchronization( buf, exc, L_frame, st->nb_subfr, st->old_fpitchFB_float, predPitchLag ); + PulseResynchronization( buf, exc, L_frame, st->nb_subfr, st->old_fpitchFB_float, predPitchLag ); } else { @@ -425,7 +425,7 @@ void con_tcx( { for ( i = 0; i < L_frame + L_frame / 2 + L_FIR_FER2; i++ ) { - noise[i] = ( 1 - st->cummulative_damping_float) * noise[i] + st->cummulative_damping_float * dotp( &noise[i], hp_filt, L_FIR_FER2 ); + noise[i] = ( 1 - st->cummulative_damping_float ) * noise[i] + st->cummulative_damping_float * dotp( &noise[i], hp_filt, L_FIR_FER2 ); } } } diff --git a/lib_dec/er_dec_tcx_fx.c b/lib_dec/er_dec_tcx_fx.c index 0e42d360e..312049e70 100644 --- a/lib_dec/er_dec_tcx_fx.c +++ b/lib_dec/er_dec_tcx_fx.c @@ -15,9 +15,9 @@ /***************************************************** calcGainc calculates st->lp_gainc ******************************************************/ -static void calcGainc_fx(Word16* exc, Word16 Q_exc, Word32 old_fpitch, Word16 L_subfr, Word32 lp_gainp, Word32* lp_gainc) +static void calcGainc_fx( Word16 *exc, Word16 Q_exc, Word32 old_fpitch, Word16 L_subfr, Word32 lp_gainp, Word32 *lp_gainc ) { - Word32 L_c ; + Word32 L_c; Word16 tmp16, tmp16_2, tmp16_3, tmp_e, tmp2_e, tmp_loop, i; Word32 L_acc, L_tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL @@ -26,62 +26,61 @@ static void calcGainc_fx(Word16* exc, Word16 Q_exc, Word32 old_fpitch, Word16 L_ #endif - L_acc = L_deposit_l(0); - L_c = L_deposit_l(0); + L_acc = L_deposit_l( 0 ); + L_c = L_deposit_l( 0 ); Overflow = 0; Carry = 0; - tmp16 = round_fx(old_fpitch);/*Q0*/ - tmp_loop = shl(L_subfr,1); + tmp16 = round_fx( old_fpitch ); /*Q0*/ + tmp_loop = shl( L_subfr, 1 ); BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB - tmp16_2 = round_fx_o(L_shl_o(lp_gainp,2, &Overflow), &Overflow); /*Q31->Q15, no severe saturation, because st->lp_gainp here is [0,1]*/ + tmp16_2 = round_fx_o( L_shl_o( lp_gainp, 2, &Overflow ), &Overflow ); /*Q31->Q15, no severe saturation, because st->lp_gainp here is [0,1]*/ #else - tmp16_2 = round_fx(L_shl(lp_gainp,2)); /*Q31->Q15, no severe saturation, because st->lp_gainp here is [0,1]*/ + tmp16_2 = round_fx( L_shl( lp_gainp, 2 ) ); /*Q31->Q15, no severe saturation, because st->lp_gainp here is [0,1]*/ #endif BASOP_SATURATE_WARNING_ON_EVS - FOR ( i=0; i< tmp_loop; i++ ) + FOR( i = 0; i < tmp_loop; i++ ) { /*st->lp_gainc += ( exc[i-2*L_subfr] - st->Mode2_lp_gainp * exc[i-2*L_subfr-(int)(st->old_fpitch+0.5f)] ) * ( exc[i-2*L_subfr] - st->Mode2_lp_gainp * exc[i-2*L_subfr-(int)(st->old_fpitch+0.5f)] );*/ #ifdef BASOP_NOGLOB - tmp16_3 = sub_o(exc[i-2*L_subfr] /*Q1*/,mult_r(tmp16_2 /*Q15*/, exc[i-2*L_subfr-tmp16]/*Q1*/)/*Q1*/, &Overflow); + tmp16_3 = sub_o( exc[i - 2 * L_subfr] /*Q1*/, mult_r( tmp16_2 /*Q15*/, exc[i - 2 * L_subfr - tmp16] /*Q1*/ ) /*Q1*/, &Overflow ); #else - tmp16_3 = sub(exc[i-2*L_subfr] /*Q1*/,mult_r(tmp16_2 /*Q15*/, exc[i-2*L_subfr-tmp16]/*Q1*/)/*Q1*/); + tmp16_3 = sub( exc[i - 2 * L_subfr] /*Q1*/, mult_r( tmp16_2 /*Q15*/, exc[i - 2 * L_subfr - tmp16] /*Q1*/ ) /*Q1*/ ); #endif #ifdef BASOP_NOGLOB - L_acc = L_macNs_co(L_acc, tmp16_3, tmp16_3, &Carry, &Overflow); /*Q3*/ + L_acc = L_macNs_co( L_acc, tmp16_3, tmp16_3, &Carry, &Overflow ); /*Q3*/ #else - L_acc = L_macNs(L_acc,tmp16_3,tmp16_3); /*Q3*/ + L_acc = L_macNs( L_acc, tmp16_3, tmp16_3 ); /*Q3*/ #endif Overflow = 0; #ifdef BASOP_NOGLOB - L_c = L_macNs_co(L_c, 0, 0, &Carry, &Overflow); /*Accumulate Carrys*/ + L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); /*Accumulate Carrys*/ #else - L_c = L_macNs(L_c,0,0); /*Accumulate Carrys*/ + L_c = L_macNs( L_c, 0, 0 ); /*Accumulate Carrys*/ #endif Carry = 0; } - L_tmp = norm_llQ31(L_c,L_acc,&tmp_e);/*Q3,norm,tmp_e*/ - tmp_e = add(tmp_e,31-(add(shl(Q_exc,1),1))); /*L_tmp is Q31, now*/ - tmp16 = BASOP_Util_Divide3216_Scale(L_tmp/*Q31,norm,tmp_e*/,shl(L_subfr,1)/*Q15,15*/,&tmp2_e)/*Q15,tmp2_e+tmp_e-15*/; - tmp_e = sub(add(tmp2_e,tmp_e), 15); + L_tmp = norm_llQ31( L_c, L_acc, &tmp_e ); /*Q3,norm,tmp_e*/ + tmp_e = add( tmp_e, 31 - ( add( shl( Q_exc, 1 ), 1 ) ) ); /*L_tmp is Q31, now*/ + tmp16 = BASOP_Util_Divide3216_Scale( L_tmp /*Q31,norm,tmp_e*/, shl( L_subfr, 1 ) /*Q15,15*/, &tmp2_e ) /*Q15,tmp2_e+tmp_e-15*/; + tmp_e = sub( add( tmp2_e, tmp_e ), 15 ); - IF (tmp16 != 0) + IF( tmp16 != 0 ) { - tmp16 = Sqrt16(tmp16,&tmp_e); /*Q15,norm,tmp_e*/ + tmp16 = Sqrt16( tmp16, &tmp_e ); /*Q15,norm,tmp_e*/ } - *lp_gainc = L_shl(L_deposit_l(tmp16),add(tmp_e,1)); /*15Q16*/ - + *lp_gainc = L_shl( L_deposit_l( tmp16 ), add( tmp_e, 1 ) ); /*15Q16*/ } -static void calcGainc2_fx(Word16 *exc, Word16 Q_exc, Word16 L_subfr, Word32* lp_gainc) +static void calcGainc2_fx( Word16 *exc, Word16 Q_exc, Word16 L_subfr, Word32 *lp_gainc ) { - Word16 i, cnt, tmp16 , tmp_e, tmp2_e; + Word16 i, cnt, tmp16, tmp_e, tmp2_e; Word32 L_c, L_acc, L_tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; + Flag Overflow = 0; Flag Carry = 0; #endif @@ -89,39 +88,39 @@ static void calcGainc2_fx(Word16 *exc, Word16 Q_exc, Word16 L_subfr, Word32* lp_ Carry = 0; Overflow = 0; - L_c = L_deposit_l(0); - L_acc = L_deposit_l(0); + L_c = L_deposit_l( 0 ); + L_acc = L_deposit_l( 0 ); - cnt = shl(L_subfr,1); + cnt = shl( L_subfr, 1 ); - FOR (i=0; i < cnt; i++) + FOR( i = 0; i < cnt; i++ ) { /* *gainc += ( exc[i-2*L_subfr] ) * ( exc[i-2*L_subfr]); */ -#ifdef BASOP_NOGLOB /* Critical Carry/Overflow */ - L_acc = L_macNs_co(L_acc, exc[i-2*L_subfr] /*Q1*/, exc[i-2*L_subfr] /*Q1*/, &Carry, &Overflow); /*Q3*/ +#ifdef BASOP_NOGLOB /* Critical Carry/Overflow */ + L_acc = L_macNs_co( L_acc, exc[i - 2 * L_subfr] /*Q1*/, exc[i - 2 * L_subfr] /*Q1*/, &Carry, &Overflow ); /*Q3*/ #else - L_acc = L_macNs(L_acc, exc[i-2*L_subfr] /*Q1*/, exc[i-2*L_subfr] /*Q1*/); /*Q3*/ + L_acc = L_macNs( L_acc, exc[i - 2 * L_subfr] /*Q1*/, exc[i - 2 * L_subfr] /*Q1*/ ); /*Q3*/ #endif Overflow = 0; -#ifdef BASOP_NOGLOB /* Critical Carry/Overflow */ - L_c = L_macNs_co(L_c,0,0, &Carry, &Overflow); /* Accumulate Carrys */ +#ifdef BASOP_NOGLOB /* Critical Carry/Overflow */ + L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); /* Accumulate Carrys */ #else - L_c = L_macNs(L_c,0,0); /* Accumulate Carrys */ + L_c = L_macNs( L_c, 0, 0 ); /* Accumulate Carrys */ #endif Carry = 0; } - L_tmp = norm_llQ31(L_c,L_acc,&tmp_e); /*Q3,norm,tmp_e*/ - tmp_e = add(tmp_e,31-(add(shl(Q_exc,1),1))); /*L_tmp is Q31, now*/ - tmp16 = BASOP_Util_Divide3216_Scale(L_tmp/*Q31,norm,tmp_e*/,shl(L_subfr,1)/*Q15,15*/,&tmp2_e)/*Q15,tmp2_e+tmp_e-15*/; - tmp_e = sub(add(tmp2_e,tmp_e), 15); + L_tmp = norm_llQ31( L_c, L_acc, &tmp_e ); /*Q3,norm,tmp_e*/ + tmp_e = add( tmp_e, 31 - ( add( shl( Q_exc, 1 ), 1 ) ) ); /*L_tmp is Q31, now*/ + tmp16 = BASOP_Util_Divide3216_Scale( L_tmp /*Q31,norm,tmp_e*/, shl( L_subfr, 1 ) /*Q15,15*/, &tmp2_e ) /*Q15,tmp2_e+tmp_e-15*/; + tmp_e = sub( add( tmp2_e, tmp_e ), 15 ); - IF ( tmp16 != 0 ) + IF( tmp16 != 0 ) { - tmp16 = Sqrt16(tmp16,&tmp_e); /*Q15,norm,tmp_e*/ + tmp16 = Sqrt16( tmp16, &tmp_e ); /*Q15,norm,tmp_e*/ } - *lp_gainc = L_shl(L_deposit_l(tmp16),add(tmp_e,1)); /*15Q16*/ move32(); - + *lp_gainc = L_shl( L_deposit_l( tmp16 ), add( tmp_e, 1 ) ); /*15Q16*/ + move32(); } /****************************************************** @@ -133,45 +132,47 @@ con_tcx *******************************************************/ void con_tcx_fx( - Decoder_State *st, /* i/o: coder memory state */ - Word16 synth[] /* i/o: synth[] *//*Q0 */ + Decoder_State *st, /* i/o: coder memory state */ + Word16 synth[] /* i/o: synth[] */ /*Q0 */ #ifdef IVAS_CODE_CON_TCX - ,const Word16 coh, /* i : coherence of stereo signal */ - Word16 * noise_seed, /* i/o: noise seed for stereo */ - const Word16 only_left /* i : TD-PLC only in left channel */ + , + const Word16 coh, /* i : coherence of stereo signal */ + Word16 *noise_seed, /* i/o: noise seed for stereo */ + const Word16 only_left /* i : TD-PLC only in left channel */ #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - ,const float* A_cng /* i : CNG LP filter coefficients */ + , + const float *A_cng /* i : CNG LP filter coefficients */ #endif #endif ) { - Word16 i, s, c, L_frame, L_subfr, fLowPassFilter, T0; - Word16 n, mem_syn_r_size_old, mem_syn_r_size_new; - Word16 *noise; - Word16 mem_syn[M], *syn; - Word16 *exc, buf[OLD_EXC_SIZE_DEC+L_FRAME_MAX+L_FRAME_MAX/NB_SUBFR+1+L_FRAME_MAX/2]; - Word16 pre_emph_buf; - Word16 hp_filt[L_FIR_FER2]; - Word16 alpha; - Word16 tmp_deemph, gain, gainCNG, gain_inov; - Word16 *pt_exc, *pt1_exc; - Word16 Tc, tmpSeed; - Word16 fUseExtrapolatedPitch; - Word16 *ana_window; - Word16 r_h[M+1], A_local[M+1], mem, r_l[M+1]; - PWord16 const *w; - Word16 W1, W2, W12; + Word16 i, s, c, L_frame, L_subfr, fLowPassFilter, T0; + Word16 n, mem_syn_r_size_old, mem_syn_r_size_new; + Word16 *noise; + Word16 mem_syn[M], *syn; + Word16 *exc, buf[OLD_EXC_SIZE_DEC + L_FRAME_MAX + L_FRAME_MAX / NB_SUBFR + 1 + L_FRAME_MAX / 2]; + Word16 pre_emph_buf; + Word16 hp_filt[L_FIR_FER2]; + Word16 alpha; + Word16 tmp_deemph, gain, gainCNG, gain_inov; + Word16 *pt_exc, *pt1_exc; + Word16 Tc, tmpSeed; + Word16 fUseExtrapolatedPitch; + Word16 *ana_window; + Word16 r_h[M + 1], A_local[M + 1], mem, r_l[M + 1]; + PWord16 const *w; + Word16 W1, W2, W12; Word16 Q_r; - Word16 tmp16, tmp16_2, tmp_loop, tmp_e, gain_tmp; - Word16 gainCNG_e, noise_e, gain_inov_e ;/*Exponents for gainCNG, noise, gain_inov*/ - Word16 Q_syn; /*Q format of temporary synthesis buffer syn*/ + Word16 tmp16, tmp16_2, tmp_loop, tmp_e, gain_tmp; + Word16 gainCNG_e, noise_e, gain_inov_e; /*Exponents for gainCNG, noise, gain_inov*/ + Word16 Q_syn; /*Q format of temporary synthesis buffer syn*/ Word32 L_tmp, L_tmp2, step32_tmp; Word32 predPitchLag, pitch_buf[NB_SUBFR16k], step32, gain32; - Word16 extrapolationFailed; - Word16 gainSynthDeemph; - Word16 gainSynthDeemph_e; - Word32 old_pitch_buf[2*NB_SUBFR16k+2]; + Word16 extrapolationFailed; + Word16 gainSynthDeemph; + Word16 gainSynthDeemph_e; + Word32 old_pitch_buf[2 * NB_SUBFR16k + 2]; Word16 Q_exc, new_Q, exp_scale; Word16 offset; HQ_DEC_HANDLE hHQ_core; @@ -192,7 +193,8 @@ void con_tcx_fx( noise_e = 0; move16(); - Q_syn = -1; /*Q format of temporary synthesis buffer syn*/ move16(); + Q_syn = -1; /*Q format of temporary synthesis buffer syn*/ + move16(); offset = 0; move16(); @@ -200,98 +202,98 @@ void con_tcx_fx( L_frame = hTcxDec->L_frameTCX; move16(); /* L_subfr = st->L_frameTCX/st->nb_subfr */ - L_subfr = mult_r(hTcxDec->L_frameTCX,div_s(1,st->nb_subfr)); - assert( L_subfr == hTcxDec->L_frameTCX/st->nb_subfr ); + L_subfr = mult_r( hTcxDec->L_frameTCX, div_s( 1, st->nb_subfr ) ); + assert( L_subfr == hTcxDec->L_frameTCX / st->nb_subfr ); move32(); w = st->hTcxCfg->tcx_mdct_windowFB; /*pointer - no need to instrument*/ W1 = st->hTcxCfg->tcx_mdct_window_lengthFB; move16(); - W2 = shr(st->hTcxCfg->tcx_mdct_window_lengthFB, 1); - W12 = shr(W1,1); + W2 = shr( st->hTcxCfg->tcx_mdct_window_lengthFB, 1 ); + W12 = shr( W1, 1 ); /* take the previous frame last pitch */ - Tc = round_fx(st->old_fpitchFB); + Tc = round_fx( st->old_fpitchFB ); - set16_fx(buf,0, OLD_EXC_SIZE_DEC + L_FRAME_MAX + L_FRAME_MAX / NB_SUBFR + 1 + L_FRAME_MAX / 2); /* initialize buf with 0 */ - //set16_fx(buf,0,shr(sizeof(buf),1)); /* initialize buf with 0 */ + set16_fx( buf, 0, OLD_EXC_SIZE_DEC + L_FRAME_MAX + L_FRAME_MAX / NB_SUBFR + 1 + L_FRAME_MAX / 2 ); /* initialize buf with 0 */ + // set16_fx(buf,0,shr(sizeof(buf),1)); /* initialize buf with 0 */ c = BASOP_Util_Divide1616_Scale( - L_frame, - st->L_frame, - &s - ); + L_frame, + st->L_frame, + &s ); - FOR (i=0; i < (2*NB_SUBFR16k+2); i++) + FOR( i = 0; i < ( 2 * NB_SUBFR16k + 2 ); i++ ) { - old_pitch_buf[i] = L_shl(Mpy_32_16_1(st->old_pitch_buf_fx[i],c),s); + old_pitch_buf[i] = L_shl( Mpy_32_16_1( st->old_pitch_buf_fx[i], c ), s ); move32(); } /* set excitation memory*/ - exc = buf+OLD_EXC_SIZE_DEC; + exc = buf + OLD_EXC_SIZE_DEC; tmp_deemph = synth[-1]; move16(); pre_emph_buf = synth[-1]; move16(); test(); - IF ( (EQ_16( st->nbLostCmpt, 1 ))|| hTcxDec->tcxConceal_recalc_exc) + IF( ( EQ_16( st->nbLostCmpt, 1 ) ) || hTcxDec->tcxConceal_recalc_exc ) { /* apply pre-emphasis to the signal */ - mem = synth[-((shr(L_frame,1))+ hTcxDec->pit_max_TCX+M+M)-1]; - Q_exc = E_UTIL_f_preemph3(&(synth[-((shr(L_frame,1))+ hTcxDec->pit_max_TCX+2*M)]), st->preemph_fac, add(add(shr(L_frame,1), hTcxDec->pit_max_TCX),shl(M,1)), &mem,1); - st->Mode2_lp_gainc = L_deposit_l(0); + mem = synth[-( ( shr( L_frame, 1 ) ) + hTcxDec->pit_max_TCX + M + M ) - 1]; + Q_exc = E_UTIL_f_preemph3( &( synth[-( ( shr( L_frame, 1 ) ) + hTcxDec->pit_max_TCX + 2 * M )] ), st->preemph_fac, add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), shl( M, 1 ) ), &mem, 1 ); + st->Mode2_lp_gainc = L_deposit_l( 0 ); - st->Mode2_lp_gainp = get_gain2( synth-2*L_subfr, synth-2*L_subfr-Tc, shl(L_subfr,1) ); + st->Mode2_lp_gainp = get_gain2( synth - 2 * L_subfr, synth - 2 * L_subfr - Tc, shl( L_subfr, 1 ) ); move32(); - st->Mode2_lp_gainp = L_max(st->Mode2_lp_gainp,0); - st->Mode2_lp_gainp = L_min(st->Mode2_lp_gainp,65536l/*1.0f Q16*/); - st->Mode2_lp_gainp = L_shl(st->Mode2_lp_gainp, 13); + st->Mode2_lp_gainp = L_max( st->Mode2_lp_gainp, 0 ); + st->Mode2_lp_gainp = L_min( st->Mode2_lp_gainp, 65536l /*1.0f Q16*/ ); + st->Mode2_lp_gainp = L_shl( st->Mode2_lp_gainp, 13 ); ana_window = buf; - ham_cos_window(ana_window, mult(L_frame,24576/*0.75f Q15*/), shr(L_frame,2)); + ham_cos_window( ana_window, mult( L_frame, 24576 /*0.75f Q15*/ ), shr( L_frame, 2 ) ); /* Autocorrelation */ - autocorr_fx(&(synth[-L_frame-1]), M, r_h ,r_l , &Q_r , L_frame, ana_window, 0, 0); + autocorr_fx( &( synth[-L_frame - 1] ), M, r_h, r_l, &Q_r, L_frame, ana_window, 0, 0 ); /* Lag windowing */ - lag_wind( r_h,r_l, M, st->output_Fs, LAGW_STRONG ); + lag_wind( r_h, r_l, M, st->output_Fs, LAGW_STRONG ); /* Levinson Durbin */ - E_LPC_lev_dur(r_h, r_l, A_local, NULL, M, NULL); + E_LPC_lev_dur( r_h, r_l, A_local, NULL, M, NULL ); /* copy for multiple frame loss */ - Copy(A_local, st->old_Aq_12_8_fx, M+1); + Copy( A_local, st->old_Aq_12_8_fx, M + 1 ); /* Residu */ - assert((2*L_subfr+Tc+1+M) <= hTcxDec->old_synth_lenFB); + assert( ( 2 * L_subfr + Tc + 1 + M ) <= hTcxDec->old_synth_lenFB ); BASOP_SATURATE_WARNING_OFF_EVS /*saturation possible in case of spiky synthesis*/ - Residu3_fx( - A_local, - &(synth[-(2*L_subfr+Tc+1+M)]), /*Qx = Q0*/ - &(exc[-(2*L_subfr+Tc+1+M)]), /*Qx+1 = Q1*/ - add(add(add(shl(L_subfr,1),Tc),1),M), - 1); + Residu3_fx( + A_local, + &( synth[-( 2 * L_subfr + Tc + 1 + M )] ), /*Qx = Q0*/ + &( exc[-( 2 * L_subfr + Tc + 1 + M )] ), /*Qx+1 = Q1*/ + add( add( add( shl( L_subfr, 1 ), Tc ), 1 ), M ), + 1 ); BASOP_SATURATE_WARNING_ON_EVS } ELSE { /* apply pre-emphasis to the signal */ - mem = synth[-L_frame-1]; - Q_exc = E_UTIL_f_preemph3(&(synth[-L_frame]), st->preemph_fac, L_frame, &mem, 1); - Copy(st->old_Aq_12_8_fx, A_local, M+1); + mem = synth[-L_frame - 1]; + Q_exc = E_UTIL_f_preemph3( &( synth[-L_frame] ), st->preemph_fac, L_frame, &mem, 1 ); + Copy( st->old_Aq_12_8_fx, A_local, M + 1 ); - offset = shr(L_frame,1); - IF(GE_16(st->last_good, UNVOICED_TRANSITION)) + offset = shr( L_frame, 1 ); + IF( GE_16( st->last_good, UNVOICED_TRANSITION ) ) { - tmp16 = s_max(Tc - shr(L_frame,1), 0); - Copy_Scale_sig(hTcxDec->old_excFB_fx, &(exc[-tmp16]), offset+tmp16, Q_exc-st->Q_exc); + tmp16 = s_max( Tc - shr( L_frame, 1 ), 0 ); + Copy_Scale_sig( hTcxDec->old_excFB_fx, &( exc[-tmp16] ), offset + tmp16, Q_exc - st->Q_exc ); } - ELSE { - Copy_Scale_sig(hTcxDec->old_excFB_fx, &(exc[-2*L_subfr]), 2*L_subfr+offset, Q_exc-st->Q_exc); + ELSE + { + Copy_Scale_sig( hTcxDec->old_excFB_fx, &( exc[-2 * L_subfr] ), 2 * L_subfr + offset, Q_exc - st->Q_exc ); } } @@ -301,17 +303,17 @@ void con_tcx_fx( test(); test(); - IF( GT_16(st->last_good, UNVOICED_CLAS)&&!(EQ_16(st->last_good,UNVOICED_TRANSITION)&&EQ_16(st->core_ext_mode,GENERIC))) + IF( GT_16( st->last_good, UNVOICED_CLAS ) && !( EQ_16( st->last_good, UNVOICED_TRANSITION ) && EQ_16( st->core_ext_mode, GENERIC ) ) ) { - IF ( EQ_16(st->nbLostCmpt,1)|| hTcxDec->tcxConceal_recalc_exc) + IF( EQ_16( st->nbLostCmpt, 1 ) || hTcxDec->tcxConceal_recalc_exc ) { - calcGainc_fx( exc, Q_exc, st->old_fpitchFB, L_subfr, st->Mode2_lp_gainp, &(st->Mode2_lp_gainc)); + calcGainc_fx( exc, Q_exc, st->old_fpitchFB, L_subfr, st->Mode2_lp_gainp, &( st->Mode2_lp_gainc ) ); } tmp16 = 0; move16(); - if (GT_32(st->output_Fs , 25600)) + if ( GT_32( st->output_Fs, 25600 ) ) { tmp16 = 1; move16(); @@ -321,22 +323,19 @@ void con_tcx_fx( test(); test(); test(); - IF( ((EQ_16(st->nbLostCmpt,1))|| hTcxDec->tcxConceal_recalc_exc)&&GE_16(st->rf_frame_type,RF_TCXFD)&&LE_16(st->rf_frame_type,RF_TCXTD2)&&st->use_partial_copy) + IF( ( ( EQ_16( st->nbLostCmpt, 1 ) ) || hTcxDec->tcxConceal_recalc_exc ) && GE_16( st->rf_frame_type, RF_TCXFD ) && LE_16( st->rf_frame_type, RF_TCXTD2 ) && st->use_partial_copy ) { - Word32 tcxltp_pitch_tmp = L_add(L_deposit_h(hTcxLtpDec->tcxltp_pitch_int), L_shl(L_deposit_l(div_s(hTcxLtpDec->tcxltp_pitch_fr,st->pit_res_max)),1)); /*15Q16*/ - Word16 scale_tmp = mult_r(hTcxDec->L_frameTCX, getInvFrameLen(st->L_frame)); /*getInvFrameLen()->9Q6*/ - Word16 tmp_shift = norm_s(scale_tmp); - predPitchLag = L_shl(Mpy_32_16_1(tcxltp_pitch_tmp, shl(scale_tmp, tmp_shift)), sub(9, tmp_shift)); + Word32 tcxltp_pitch_tmp = L_add( L_deposit_h( hTcxLtpDec->tcxltp_pitch_int ), L_shl( L_deposit_l( div_s( hTcxLtpDec->tcxltp_pitch_fr, st->pit_res_max ) ), 1 ) ); /*15Q16*/ + Word16 scale_tmp = mult_r( hTcxDec->L_frameTCX, getInvFrameLen( st->L_frame ) ); /*getInvFrameLen()->9Q6*/ + Word16 tmp_shift = norm_s( scale_tmp ); + predPitchLag = L_shl( Mpy_32_16_1( tcxltp_pitch_tmp, shl( scale_tmp, tmp_shift ) ), sub( 9, tmp_shift ) ); - T0 = round_fx(predPitchLag); + T0 = round_fx( predPitchLag ); test(); test(); test(); - if ( (T0 > 0) - && (NE_16(T0,Tc) ) - && (LT_32(L_deposit_h(abs_s(sub(T0,Tc)))/*Q16*/ , L_mult(4915/*.15f Q15*//*Q15*/,Tc/*Q0*/) /*Q16*/ ) ) - ) + if ( ( T0 > 0 ) && ( NE_16( T0, Tc ) ) && ( LT_32( L_deposit_h( abs_s( sub( T0, Tc ) ) ) /*Q16*/, L_mult( 4915 /*.15f Q15*/ /*Q15*/, Tc /*Q0*/ ) /*Q16*/ ) ) ) { fUseExtrapolatedPitch = 1; move16(); @@ -349,7 +348,7 @@ void con_tcx_fx( st->nbLostCmpt, st->last_good, old_pitch_buf, - &(st->old_fpitchFB), + &( st->old_fpitchFB ), &predPitchLag, hTcxDec->pit_min_TCX, hTcxDec->pit_max_TCX, @@ -357,18 +356,13 @@ void con_tcx_fx( tmp16, st->plc_use_future_lag, &extrapolationFailed, - st->nb_subfr - ); + st->nb_subfr ); - T0 = round_fx(predPitchLag); + T0 = round_fx( predPitchLag ); test(); test(); test(); - if ( (T0 > 0) - && (NE_16(T0,Tc) ) - && (LT_32(L_deposit_h(abs_s(sub(T0,Tc)))/*Q16*/ , L_mult(4915/*.15f Q15*//*Q15*/,Tc/*Q0*/) /*Q16*/ ) ) - && (extrapolationFailed == 0) - ) + if ( ( T0 > 0 ) && ( NE_16( T0, Tc ) ) && ( LT_32( L_deposit_h( abs_s( sub( T0, Tc ) ) ) /*Q16*/, L_mult( 4915 /*.15f Q15*/ /*Q15*/, Tc /*Q0*/ ) /*Q16*/ ) ) && ( extrapolationFailed == 0 ) ) { fUseExtrapolatedPitch = 1; move16(); @@ -381,81 +375,81 @@ void con_tcx_fx( pt_exc = exc + offset; pt1_exc = pt_exc - Tc; - if (fUseExtrapolatedPitch != 0) + if ( fUseExtrapolatedPitch != 0 ) { pt_exc = buf; } test(); - IF( LT_16(st->stab_fac_fx ,32767/*1.f Q15*/)&&EQ_16(st->nbLostCmpt,1)) + IF( LT_16( st->stab_fac_fx, 32767 /*1.f Q15*/ ) && EQ_16( st->nbLostCmpt, 1 ) ) { /* pitch cycle is first low-pass filtered */ - IF (LE_32(st->output_Fs , 16000)) + IF( LE_32( st->output_Fs, 16000 ) ) { - FOR( i=0 ; i< Tc; i++ ) + FOR( i = 0; i < Tc; i++ ) { move16(); #ifdef BASOP_NOGLOB *pt_exc++ = mac_r_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( - L_mult(174/* 0.0053f Q15*/, pt1_exc[-5]), - 0/* 0.0000f Q15*/, pt1_exc[-4]), - -1442/*-0.0440f Q15*/, pt1_exc[-3]), - 0/* 0.0000f Q15*/, pt1_exc[-2]), - 8641/* 0.2637f Q15*/, pt1_exc[-1]), - 18022/* 0.5500f Q15*/, pt1_exc[0] ), - 8641/* 0.2637f Q15*/, pt1_exc[1] ), - 0/* 0.0000f Q15*/, pt1_exc[2] ), - -1442/*-0.0440f Q15*/, pt1_exc[3] ), - 0/* 0.0000f Q15*/, pt1_exc[4] ), - 174/* 0.0053f Q15*/, pt1_exc[5] ); + L_mult( 174 /* 0.0053f Q15*/, pt1_exc[-5] ), + 0 /* 0.0000f Q15*/, pt1_exc[-4] ), + -1442 /*-0.0440f Q15*/, pt1_exc[-3] ), + 0 /* 0.0000f Q15*/, pt1_exc[-2] ), + 8641 /* 0.2637f Q15*/, pt1_exc[-1] ), + 18022 /* 0.5500f Q15*/, pt1_exc[0] ), + 8641 /* 0.2637f Q15*/, pt1_exc[1] ), + 0 /* 0.0000f Q15*/, pt1_exc[2] ), + -1442 /*-0.0440f Q15*/, pt1_exc[3] ), + 0 /* 0.0000f Q15*/, pt1_exc[4] ), + 174 /* 0.0053f Q15*/, pt1_exc[5] ); #else - *pt_exc++ = mac_r(L_mac(L_mac(L_mac(L_mac(L_mac(L_mac(L_mac(L_mac(L_mac( - L_mult(174/* 0.0053f Q15*/, pt1_exc[-5]), - 0/* 0.0000f Q15*/, pt1_exc[-4]), - -1442/*-0.0440f Q15*/, pt1_exc[-3]), - 0/* 0.0000f Q15*/, pt1_exc[-2]), - 8641/* 0.2637f Q15*/, pt1_exc[-1]), - 18022/* 0.5500f Q15*/, pt1_exc[0] ), - 8641/* 0.2637f Q15*/, pt1_exc[1] ), - 0/* 0.0000f Q15*/, pt1_exc[2] ), - -1442/*-0.0440f Q15*/, pt1_exc[3] ), - 0/* 0.0000f Q15*/, pt1_exc[4] ), - 174/* 0.0053f Q15*/, pt1_exc[5] ); + *pt_exc++ = mac_r( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( + L_mult( 174 /* 0.0053f Q15*/, pt1_exc[-5] ), + 0 /* 0.0000f Q15*/, pt1_exc[-4] ), + -1442 /*-0.0440f Q15*/, pt1_exc[-3] ), + 0 /* 0.0000f Q15*/, pt1_exc[-2] ), + 8641 /* 0.2637f Q15*/, pt1_exc[-1] ), + 18022 /* 0.5500f Q15*/, pt1_exc[0] ), + 8641 /* 0.2637f Q15*/, pt1_exc[1] ), + 0 /* 0.0000f Q15*/, pt1_exc[2] ), + -1442 /*-0.0440f Q15*/, pt1_exc[3] ), + 0 /* 0.0000f Q15*/, pt1_exc[4] ), + 174 /* 0.0053f Q15*/, pt1_exc[5] ); #endif pt1_exc++; } } ELSE /*(st->output_Fs >= 32000)*/ { - FOR( i=0 ; i< Tc; i++ ) + FOR( i = 0; i < Tc; i++ ) { move16(); #ifdef BASOP_NOGLOB *pt_exc++ = mac_r_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( - L_mult(-174/*-0.0053f Q15*/, pt1_exc[-5]), - -121/*-0.0037f Q15*/, pt1_exc[-4]), - -459/*-0.0140f Q15*/, pt1_exc[-3]), - 590/* 0.0180f Q15*/, pt1_exc[-2]), - 8743/* 0.2668f Q15*/, pt1_exc[-1]), - 16355/* 0.4991f Q15*/, pt1_exc[0] ), - 8743/* 0.2668f Q15*/, pt1_exc[1] ), - 590/* 0.0180f Q15*/, pt1_exc[2] ), - -459/*-0.0140f Q15*/, pt1_exc[3] ), - -121/*-0.0037f Q15*/, pt1_exc[4] ), - -174/*-0.0053f Q15*/, pt1_exc[5] ); + L_mult( -174 /*-0.0053f Q15*/, pt1_exc[-5] ), + -121 /*-0.0037f Q15*/, pt1_exc[-4] ), + -459 /*-0.0140f Q15*/, pt1_exc[-3] ), + 590 /* 0.0180f Q15*/, pt1_exc[-2] ), + 8743 /* 0.2668f Q15*/, pt1_exc[-1] ), + 16355 /* 0.4991f Q15*/, pt1_exc[0] ), + 8743 /* 0.2668f Q15*/, pt1_exc[1] ), + 590 /* 0.0180f Q15*/, pt1_exc[2] ), + -459 /*-0.0140f Q15*/, pt1_exc[3] ), + -121 /*-0.0037f Q15*/, pt1_exc[4] ), + -174 /*-0.0053f Q15*/, pt1_exc[5] ); #else - *pt_exc++ = mac_r(L_mac(L_mac(L_mac(L_mac(L_mac(L_mac(L_mac(L_mac(L_mac( - L_mult(-174/*-0.0053f Q15*/, pt1_exc[-5]), - -121/*-0.0037f Q15*/, pt1_exc[-4]), - -459/*-0.0140f Q15*/, pt1_exc[-3]), - 590/* 0.0180f Q15*/, pt1_exc[-2]), - 8743/* 0.2668f Q15*/, pt1_exc[-1]), - 16355/* 0.4991f Q15*/, pt1_exc[0] ), - 8743/* 0.2668f Q15*/, pt1_exc[1] ), - 590/* 0.0180f Q15*/, pt1_exc[2] ), - -459/*-0.0140f Q15*/, pt1_exc[3] ), - -121/*-0.0037f Q15*/, pt1_exc[4] ), - -174/*-0.0053f Q15*/, pt1_exc[5] ); + *pt_exc++ = mac_r( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( + L_mult( -174 /*-0.0053f Q15*/, pt1_exc[-5] ), + -121 /*-0.0037f Q15*/, pt1_exc[-4] ), + -459 /*-0.0140f Q15*/, pt1_exc[-3] ), + 590 /* 0.0180f Q15*/, pt1_exc[-2] ), + 8743 /* 0.2668f Q15*/, pt1_exc[-1] ), + 16355 /* 0.4991f Q15*/, pt1_exc[0] ), + 8743 /* 0.2668f Q15*/, pt1_exc[1] ), + 590 /* 0.0180f Q15*/, pt1_exc[2] ), + -459 /*-0.0140f Q15*/, pt1_exc[3] ), + -121 /*-0.0037f Q15*/, pt1_exc[4] ), + -174 /*-0.0053f Q15*/, pt1_exc[5] ); #endif pt1_exc++; } @@ -467,7 +461,7 @@ void con_tcx_fx( ELSE { /* copy the first pitch cycle without low-pass filtering */ - FOR( i=0 ; i < Tc; i++ ) + FOR( i = 0; i < Tc; i++ ) { *pt_exc++ = *pt1_exc++; move16(); @@ -476,41 +470,41 @@ void con_tcx_fx( move16(); } - if (fUseExtrapolatedPitch != 0) + if ( fUseExtrapolatedPitch != 0 ) { pt1_exc = buf; } - tmp16 = add(sub(L_frame,imult1616(fLowPassFilter,Tc)),L_subfr); - FOR (i = 0; i < tmp16; i++) + tmp16 = add( sub( L_frame, imult1616( fLowPassFilter, Tc ) ), L_subfr ); + FOR( i = 0; i < tmp16; i++ ) { *pt_exc++ = *pt1_exc++; move16(); } - IF (fUseExtrapolatedPitch != 0) + IF( fUseExtrapolatedPitch != 0 ) { - get_subframe_pitch(st->nb_subfr, - st->old_fpitch, - /* predPitchLag * L_frame/st->L_frame, */ - L_shr(Mpy_32_16_1(predPitchLag/*Q16*/, - mult_r(st->L_frame/*Q0*/, - getInvFrameLen(L_frame)/*Q21*/ - )/*Q6*/ - )/*Q7*/, - 7-16)/*Q16*/, - pitch_buf); + get_subframe_pitch( st->nb_subfr, + st->old_fpitch, + /* predPitchLag * L_frame/st->L_frame, */ + L_shr( Mpy_32_16_1( predPitchLag /*Q16*/, + mult_r( st->L_frame /*Q0*/, + getInvFrameLen( L_frame ) /*Q21*/ + ) /*Q6*/ + ) /*Q7*/, + 7 - 16 ) /*Q16*/, + pitch_buf ); - PulseResynchronization_fx(buf, exc, L_frame, st->nb_subfr, st->old_fpitchFB, predPitchLag); + PulseResynchronization_fx( buf, exc, L_frame, st->nb_subfr, st->old_fpitchFB, predPitchLag ); } ELSE { - set32_fx( pitch_buf, st->old_fpitch, st->nb_subfr); + set32_fx( pitch_buf, st->old_fpitch, st->nb_subfr ); } - IF ( EQ_16(st->nbLostCmpt , 1)) + IF( EQ_16( st->nbLostCmpt, 1 ) ) { - pt_exc = exc+L_frame; - IF (T0 == 0) + pt_exc = exc + L_frame; + IF( T0 == 0 ) { pt1_exc = pt_exc - Tc; } @@ -519,15 +513,15 @@ void con_tcx_fx( pt1_exc = pt_exc - T0; } - tmp_loop = shr(L_frame,1); - FOR (i = 0; i < tmp_loop; i++) + tmp_loop = shr( L_frame, 1 ); + FOR( i = 0; i < tmp_loop; i++ ) { *pt_exc++ = *pt1_exc++; move16(); } } - if (fUseExtrapolatedPitch != 0) + if ( fUseExtrapolatedPitch != 0 ) { st->old_fpitchFB = predPitchLag; move16(); @@ -538,100 +532,100 @@ void con_tcx_fx( /* PLC: calculate damping factor */ #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT alpha = 1.0f; - if (st->element_mode == IVAS_CPE_MDCT && st->nbLostCmpt >= MDCT_ST_PLC_FADEOUT_START_FRAME) + if ( st->element_mode == IVAS_CPE_MDCT && st->nbLostCmpt >= MDCT_ST_PLC_FADEOUT_START_FRAME ) { - alpha = Damping_fact_fx(st->core_ext_mode, st->nbLostCmpt - MDCT_ST_PLC_FADEOUT_START_FRAME, st->last_good, st->stab_fac, &(st->lp_gainp), 0); + alpha = Damping_fact_fx( st->core_ext_mode, st->nbLostCmpt - MDCT_ST_PLC_FADEOUT_START_FRAME, st->last_good, st->stab_fac, &( st->lp_gainp ), 0 ); } - else if (st->element_mode != IVAS_CPE_MDCT) + else if ( st->element_mode != IVAS_CPE_MDCT ) { - alpha = Damping_fact_fx(st->core_ext_mode, st->nbLostCmpt, st->last_good, st->stab_fac, &(st->lp_gainp), 0); + alpha = Damping_fact_fx( st->core_ext_mode, st->nbLostCmpt, st->last_good, st->stab_fac, &( st->lp_gainp ), 0 ); } #else - alpha = Damping_fact_fx(st->core_ext_mode, st->nbLostCmpt, st->last_good, st->stab_fac_fx, &(st->Mode2_lp_gainp), 0);/*Q14*/ + alpha = Damping_fact_fx( st->core_ext_mode, st->nbLostCmpt, st->last_good, st->stab_fac_fx, &( st->Mode2_lp_gainp ), 0 ); /*Q14*/ #endif - IF ( EQ_16(st->nbLostCmpt , 1)) + IF( EQ_16( st->nbLostCmpt, 1 ) ) { - st->cummulative_damping = 32767/*1.f Q15*/; + st->cummulative_damping = 32767 /*1.f Q15*/; move16(); } ELSE { #ifdef BASOP_NOGLOB - st->cummulative_damping = shl_sat(mult_r_sat(st->cummulative_damping/*Q15*/,alpha/*Q14*/),1)/*Q15*/; + st->cummulative_damping = shl_sat( mult_r_sat( st->cummulative_damping /*Q15*/, alpha /*Q14*/ ), 1 ) /*Q15*/; #else - st->cummulative_damping = shl(mult_r(st->cummulative_damping/*Q15*/,alpha/*Q14*/),1)/*Q15*/; + st->cummulative_damping = shl( mult_r( st->cummulative_damping /*Q15*/, alpha /*Q14*/ ), 1 ) /*Q15*/; #endif } - gain32 = L_add(2147483647l/*1.f Q31*/, 0); /*Q31*/ - gain = 32767/*1.f Q15*/; /*Q15*/ move16(); - if( EQ_16(st->rf_frame_type, RF_TCXTD1)&&EQ_16(st->use_partial_copy,1)) + gain32 = L_add( 2147483647l /*1.f Q31*/, 0 ); /*Q31*/ + gain = 32767 /*1.f Q15*/; /*Q15*/ + move16(); + if ( EQ_16( st->rf_frame_type, RF_TCXTD1 ) && EQ_16( st->use_partial_copy, 1 ) ) { - gain32 = 1073741824l/*0.5f Q31*/; - gain = 16384/*0.5f Q15*/; + gain32 = 1073741824l /*0.5f Q31*/; + gain = 16384 /*0.5f Q15*/; } /*step = (1.0f/(L_frame+(L_frame/2))) * (gain - alpha);*/ - tmp16 = shr(imult1616(3,L_frame),1); - tmp_e = norm_s(tmp16); - tmp16 = shl(tmp16,tmp_e); - tmp16 = div_s(16384/*1.f Q14*/,tmp16);/*Q15,1+tmp_e-15*/ - tmp16_2 = sub(shr(gain,1),alpha)/*Q14*/; - step32 = L_shl(L_mult(tmp16,tmp16_2)/*Q30, 1+tmp_e-15*/,add(1-14,tmp_e))/*Q31*/; + tmp16 = shr( imult1616( 3, L_frame ), 1 ); + tmp_e = norm_s( tmp16 ); + tmp16 = shl( tmp16, tmp_e ); + tmp16 = div_s( 16384 /*1.f Q14*/, tmp16 ); /*Q15,1+tmp_e-15*/ + tmp16_2 = sub( shr( gain, 1 ), alpha ) /*Q14*/; + step32 = L_shl( L_mult( tmp16, tmp16_2 ) /*Q30, 1+tmp_e-15*/, add( 1 - 14, tmp_e ) ) /*Q31*/; /* PLC: Apply fade out */ - tmp_loop = shr(imult1616(L_frame,3),1); - FOR ( i=offset; i < tmp_loop; i++ ) + tmp_loop = shr( imult1616( L_frame, 3 ), 1 ); + FOR( i = offset; i < tmp_loop; i++ ) { #ifdef BASOP_NOGLOB - exc[i] = mult_r(exc[i], round_fx_sat(gain32))/*Q1*/; + exc[i] = mult_r( exc[i], round_fx_sat( gain32 ) ) /*Q1*/; move16(); - gain32 = L_sub_sat(gain32, step32); + gain32 = L_sub_sat( gain32, step32 ); #else - exc[i] = mult_r(exc[i],round_fx(gain32))/*Q1*/; + exc[i] = mult_r( exc[i], round_fx( gain32 ) ) /*Q1*/; move16(); - gain32 = L_sub(gain32, step32); + gain32 = L_sub( gain32, step32 ); #endif - } /* update old exc without random part */ - offset = s_max(round_fx(st->old_fpitchFB) - shr(L_frame,1), 0); - Copy(exc+L_frame-offset, hTcxDec->old_excFB_fx, shr(L_frame,1)+offset); + offset = s_max( round_fx( st->old_fpitchFB ) - shr( L_frame, 1 ), 0 ); + Copy( exc + L_frame - offset, hTcxDec->old_excFB_fx, shr( L_frame, 1 ) + offset ); /* copy old_exc as 16kHz for acelp decoding */ - IF ( EQ_16(st->nbLostCmpt, 1)) + IF( EQ_16( st->nbLostCmpt, 1 ) ) { - lerp(exc - shr(L_frame,1), st->old_exc_fx, L_EXC_MEM_DEC, add(L_frame, shr(L_frame,1))); + lerp( exc - shr( L_frame, 1 ), st->old_exc_fx, L_EXC_MEM_DEC, add( L_frame, shr( L_frame, 1 ) ) ); } ELSE { - Copy(st->old_exc_fx+L_FRAME16k, st->old_exc_fx, L_FRAME16k/2); - lerp(exc, st->old_exc_fx+L_FRAME16k/2, L_FRAME16k, L_frame); + Copy( st->old_exc_fx + L_FRAME16k, st->old_exc_fx, L_FRAME16k / 2 ); + lerp( exc, st->old_exc_fx + L_FRAME16k / 2, L_FRAME16k, L_frame ); } st->Q_exc = Q_exc; } ELSE { /* No harmonic part */ - set16_fx(&exc[0], 0, add(L_frame,shr(L_frame,1))); - IF ( EQ_16(st->nbLostCmpt , 1)) + set16_fx( &exc[0], 0, add( L_frame, shr( L_frame, 1 ) ) ); + IF( EQ_16( st->nbLostCmpt, 1 ) ) { - calcGainc2_fx(&exc[0], Q_exc, L_subfr, &(st->Mode2_lp_gainc)); + calcGainc2_fx( &exc[0], Q_exc, L_subfr, &( st->Mode2_lp_gainc ) ); } - set32_fx( pitch_buf, L_deposit_h(L_SUBFR), st->nb_subfr); + set32_fx( pitch_buf, L_deposit_h( L_SUBFR ), st->nb_subfr ); /* PLC: calculate damping factor */ #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT alpha = 1.0f; - if (st->element_mode == IVAS_CPE_MDCT && st->nbLostCmpt >= MDCT_ST_PLC_FADEOUT_START_FRAME) + if ( st->element_mode == IVAS_CPE_MDCT && st->nbLostCmpt >= MDCT_ST_PLC_FADEOUT_START_FRAME ) { - alpha = Damping_fact_fx(st->core_ext_mode, st->nbLostCmpt - MDCT_ST_PLC_FADEOUT_START_FRAME, st->last_good, st->stab_fac, &(st->lp_gainp), 0); + alpha = Damping_fact_fx( st->core_ext_mode, st->nbLostCmpt - MDCT_ST_PLC_FADEOUT_START_FRAME, st->last_good, st->stab_fac, &( st->lp_gainp ), 0 ); } - else if (st->element_mode != IVAS_CPE_MDCT) + else if ( st->element_mode != IVAS_CPE_MDCT ) { - alpha = Damping_fact_fx(st->core_ext_mode, st->nbLostCmpt, st->last_good, st->stab_fac, &(st->lp_gainp), 0); + alpha = Damping_fact_fx( st->core_ext_mode, st->nbLostCmpt, st->last_good, st->stab_fac, &( st->lp_gainp ), 0 ); } #else - alpha = Damping_fact_fx(st->core_ext_mode, st->nbLostCmpt, st->last_good, st->stab_fac_fx, &(st->Mode2_lp_gainp), 0);/*Q14*/ + alpha = Damping_fact_fx( st->core_ext_mode, st->nbLostCmpt, st->last_good, st->stab_fac_fx, &( st->Mode2_lp_gainp ), 0 ); /*Q14*/ #endif } @@ -639,7 +633,7 @@ void con_tcx_fx( * Construct the random part of excitation *-----------------------------------------------------------------*/ #ifdef IVAS_CODE_CON_TCX - if (coh != -1.f) + if ( coh != -1.f ) { int16_t tmpSeed1; float alpha_coh; @@ -648,28 +642,28 @@ void con_tcx_fx( tmpSeed1 = *noise_seed; noise = buf; - alpha_coh = sqrtf((1 - coh) / (1 + coh)); - if (st->idchan == 1) + alpha_coh = sqrtf( ( 1 - coh ) / ( 1 + coh ) ); + if ( st->idchan == 1 ) { alpha_coh = -alpha_coh; } - for (i = 0; i < L_frame + L_FIR_FER2 - 1; i++) + for ( i = 0; i < L_frame + L_FIR_FER2 - 1; i++ ) { - random1 = (float)own_random(&tmpSeed1); - random2 = (float)own_random(&tmpSeed1); + random1 = (float) own_random( &tmpSeed1 ); + random2 = (float) own_random( &tmpSeed1 ); noise[i] = random1 + alpha_coh * random2; } - if (st->idchan == 1 || only_left) + if ( st->idchan == 1 || only_left ) { *noise_seed = tmpSeed1; } - for (; i < L_frame + (L_frame / 2) + 2 * L_FIR_FER2; i++) + for ( ; i < L_frame + ( L_frame / 2 ) + 2 * L_FIR_FER2; i++ ) { - random1 = (float)own_random(&tmpSeed1); - random2 = (float)own_random(&tmpSeed1); + random1 = (float) own_random( &tmpSeed1 ); + random2 = (float) own_random( &tmpSeed1 ); noise[i] = random1 + alpha_coh * random2; } } @@ -679,45 +673,46 @@ void con_tcx_fx( tmpSeed = st->seed_acelp; move16(); noise = buf; - noise_e = 1;/*set exponent of noise to 1*/ move16(); + noise_e = 1; /*set exponent of noise to 1*/ + move16(); - tmp_loop = add(L_frame, L_FIR_FER2 - 1); - FOR(i = 0; i < tmp_loop; i++) + tmp_loop = add( L_frame, L_FIR_FER2 - 1 ); + FOR( i = 0; i < tmp_loop; i++ ) { - tmpSeed = own_random2_fx(tmpSeed); - noise[i] = shr(tmpSeed, noise_e); + tmpSeed = own_random2_fx( tmpSeed ); + noise[i] = shr( tmpSeed, noise_e ); move16(); } st->seed_acelp = tmpSeed; move16(); - tmp_loop = add(add(L_frame, shr(L_frame, 1)), shl(L_FIR_FER2, 1)); - FOR(; i < tmp_loop; i++) + tmp_loop = add( add( L_frame, shr( L_frame, 1 ) ), shl( L_FIR_FER2, 1 ) ); + FOR( ; i < tmp_loop; i++ ) { - tmpSeed = own_random2_fx(tmpSeed); - noise[i] = shr(tmpSeed, noise_e); + tmpSeed = own_random2_fx( tmpSeed ); + noise[i] = shr( tmpSeed, noise_e ); move16(); } } test(); - IF (EQ_16(st->last_good , VOICED_CLAS)||EQ_16(st->last_good,ONSET)) + IF( EQ_16( st->last_good, VOICED_CLAS ) || EQ_16( st->last_good, ONSET ) ) { - tmp16 = 19661/*0.6f Q15*/; + tmp16 = 19661 /*0.6f Q15*/; move16(); - if ( LE_32(st->output_Fs,16000)) + if ( LE_32( st->output_Fs, 16000 ) ) { - tmp16 = 6554/*0.2f Q15*/; + tmp16 = 6554 /*0.2f Q15*/; move16(); } mem = noise[0]; move16(); - preemph_copy_fx(&noise[1], &noise[1], tmp16, L_frame+(L_frame/2)+L_FIR_FER2, &mem); + preemph_copy_fx( &noise[1], &noise[1], tmp16, L_frame + ( L_frame / 2 ) + L_FIR_FER2, &mem ); } /* high rate filter tuning */ - IF ( LE_32(st->output_Fs,16000)) + IF( LE_32( st->output_Fs, 16000 ) ) { - FOR( i=0; i< L_FIR_FER2; i++ ) + FOR( i = 0; i < L_FIR_FER2; i++ ) { hp_filt[i] = h_high3_16[i]; move16(); @@ -725,68 +720,69 @@ void con_tcx_fx( } ELSE /*(st->output_Fs==32000)*/ { - FOR( i=0; i< L_FIR_FER2; i++ ) + FOR( i = 0; i < L_FIR_FER2; i++ ) { hp_filt[i] = h_high3_32[i]; move16(); } } - IF ( EQ_16(st->nbLostCmpt,1)) + IF( EQ_16( st->nbLostCmpt, 1 ) ) { - highPassFiltering_fx(st->last_good, add(add(L_frame, shr(L_frame,1)),L_FIR_FER2), noise, hp_filt, L_FIR_FER2); + highPassFiltering_fx( st->last_good, add( add( L_frame, shr( L_frame, 1 ) ), L_FIR_FER2 ), noise, hp_filt, L_FIR_FER2 ); } ELSE { - IF(GT_16( st->last_good , UNVOICED_TRANSITION)) + IF( GT_16( st->last_good, UNVOICED_TRANSITION ) ) { - tmp_loop = add(add(L_frame,shr(L_frame,1)),L_FIR_FER2); - gain_tmp = negate(add(-32768,st->cummulative_damping));/*Q15*/ - FOR( i=0 ; i < tmp_loop; i++ ) + tmp_loop = add( add( L_frame, shr( L_frame, 1 ) ), L_FIR_FER2 ); + gain_tmp = negate( add( -32768, st->cummulative_damping ) ); /*Q15*/ + FOR( i = 0; i < tmp_loop; i++ ) { - Word16 j; - L_tmp2 = 0; move32(); - for (j=11; j>0; j--) - { - L_tmp2 = L_mac(L_tmp2, noise[i+L_FIR_FER2-j], hp_filt[L_FIR_FER2-j]); - } - L_tmp2 = Mpy_32_16_1(L_tmp2, st->cummulative_damping/*Q15*/);/*Q0, noise_e*/ - noise[i] = mac_r(L_tmp2, gain_tmp,noise[i]);/*Q15, noise_e*/ + Word16 j; + L_tmp2 = 0; + move32(); + for ( j = 11; j > 0; j-- ) + { + L_tmp2 = L_mac( L_tmp2, noise[i + L_FIR_FER2 - j], hp_filt[L_FIR_FER2 - j] ); + } + L_tmp2 = Mpy_32_16_1( L_tmp2, st->cummulative_damping /*Q15*/ ); /*Q0, noise_e*/ + noise[i] = mac_r( L_tmp2, gain_tmp, noise[i] ); /*Q15, noise_e*/ } } } /* PLC: [TCX: Fade-out] retrieve background level */ #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - if (A_cng != NULL) - { - gainSynthDeemph = getLevelSynDeemph_fx(&(tmp), A_cng, L_frame / 4, st->preemph_fac, 1) / 4.f; - } - else - { - gainSynthDeemph = getLevelSynDeemph_fx(&(tmp), A_local, L_frame / 4, st->preemph_fac, 1); - } + if ( A_cng != NULL ) + { + gainSynthDeemph = getLevelSynDeemph_fx( &( tmp ), A_cng, L_frame / 4, st->preemph_fac, 1 ) / 4.f; + } + else + { + gainSynthDeemph = getLevelSynDeemph_fx( &( tmp ), A_local, L_frame / 4, st->preemph_fac, 1 ); + } #else tmp16 = 32767; move16(); - gainSynthDeemph = getLevelSynDeemph_fx(&(tmp16), A_local, M, shr(L_frame,2), st->preemph_fac, 1, &gainSynthDeemph_e); + gainSynthDeemph = getLevelSynDeemph_fx( &( tmp16 ), A_local, M, shr( L_frame, 2 ), st->preemph_fac, 1, &gainSynthDeemph_e ); #endif - IF (0 != st->tcxonly) + IF( 0 != st->tcxonly ) { /* gainCNG = st->conCngLevelBackgroundTrace/gainSynthDeemph; */ - BASOP_Util_Divide_MantExp(hTcxDec->conCngLevelBackgroundTrace, - hTcxDec->conCngLevelBackgroundTrace_e, - gainSynthDeemph, gainSynthDeemph_e, - &gainCNG, &gainCNG_e); + BASOP_Util_Divide_MantExp( hTcxDec->conCngLevelBackgroundTrace, + hTcxDec->conCngLevelBackgroundTrace_e, + gainSynthDeemph, gainSynthDeemph_e, + &gainCNG, &gainCNG_e ); #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - if (st->element_mode == IVAS_CPE_MDCT && A_cng != NULL) + if ( st->element_mode == IVAS_CPE_MDCT && A_cng != NULL ) { - if (st->nbLostCmpt > MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME + MDCT_ST_PLC_FADEOUT_TO_ZERO_LEN) + if ( st->nbLostCmpt > MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME + MDCT_ST_PLC_FADEOUT_TO_ZERO_LEN ) { gainCNG = 0.f; } - else if (st->nbLostCmpt > MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME) + else if ( st->nbLostCmpt > MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME ) { - gainCNG *= 1.f - (float)(st->nbLostCmpt - MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME) / MDCT_ST_PLC_FADEOUT_TO_ZERO_LEN; + gainCNG *= 1.f - (float) ( st->nbLostCmpt - MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME ) / MDCT_ST_PLC_FADEOUT_TO_ZERO_LEN; } } #endif @@ -794,137 +790,142 @@ void con_tcx_fx( ELSE { /* gainCNG = st->cngTDLevel/gainSynthDeemph; */ - BASOP_Util_Divide_MantExp(st->cngTDLevel, - st->cngTDLevel_e, - gainSynthDeemph, gainSynthDeemph_e, - &gainCNG, &gainCNG_e); + BASOP_Util_Divide_MantExp( st->cngTDLevel, + st->cngTDLevel_e, + gainSynthDeemph, gainSynthDeemph_e, + &gainCNG, &gainCNG_e ); } - gain32 = L_add(st->Mode2_lp_gainc, 0); /* start-of-the-frame gain - Q16*/ - if( EQ_16(st->rf_frame_type, RF_TCXTD1)&&EQ_16(st->use_partial_copy,1)) + gain32 = L_add( st->Mode2_lp_gainc, 0 ); /* start-of-the-frame gain - Q16*/ + if ( EQ_16( st->rf_frame_type, RF_TCXTD1 ) && EQ_16( st->use_partial_copy, 1 ) ) { - gain32 = Mpy_32_16_1(gain32, 22938/*0.7f Q15*/); + gain32 = Mpy_32_16_1( gain32, 22938 /*0.7f Q15*/ ); } #ifdef BASOP_NOGLOB /* Critical Overflow */ L_tmp = L_shl_sat( gain32, 1 ); #else - L_tmp = L_shl(gain32,1); + L_tmp = L_shl( gain32, 1 ); #endif - IF (GT_32(L_shl(L_deposit_h(gainCNG),sub(gainCNG_e,31-16)/*Q16*/) , L_tmp)) + IF( GT_32( L_shl( L_deposit_h( gainCNG ), sub( gainCNG_e, 31 - 16 ) /*Q16*/ ), L_tmp ) ) { - gainCNG_e = sub(15+1,norm_l(L_tmp)); - gainCNG = extract_l(L_shr(L_tmp,gainCNG_e));/*Q15,gainCNG_e*/ - gainCNG_e = sub(gainCNG_e,1); + gainCNG_e = sub( 15 + 1, norm_l( L_tmp ) ); + gainCNG = extract_l( L_shr( L_tmp, gainCNG_e ) ); /*Q15,gainCNG_e*/ + gainCNG_e = sub( gainCNG_e, 1 ); } - /* st->Mode2_lp_gainc = alpha * (st->Mode2_lp_gainc) + (1.0f - alpha) * gainCNG;*/ /* end-of-the-frame gain */ + /* st->Mode2_lp_gainc = alpha * (st->Mode2_lp_gainc) + (1.0f - alpha) * gainCNG;*/ /* end-of-the-frame gain */ - L_tmp = Mpy_32_16_1(st->Mode2_lp_gainc,alpha)/*Q15*/; - L_tmp2 = L_mult(sub(16384/*1.f Q14*/,alpha)/*Q14*/,gainCNG/*Q15,gainCNG_e*/);/*Q30,gainCNG_e*/ - st->Mode2_lp_gainc = BASOP_Util_Add_Mant32Exp(L_tmp,31-15,L_tmp2,add(gainCNG_e,31-30),&tmp_e);/*Q31*/ move32(); - st->Mode2_lp_gainc = L_shl(st->Mode2_lp_gainc,sub(tmp_e,31-16)); + L_tmp = Mpy_32_16_1( st->Mode2_lp_gainc, alpha ) /*Q15*/; + L_tmp2 = L_mult( sub( 16384 /*1.f Q14*/, alpha ) /*Q14*/, gainCNG /*Q15,gainCNG_e*/ ); /*Q30,gainCNG_e*/ + st->Mode2_lp_gainc = BASOP_Util_Add_Mant32Exp( L_tmp, 31 - 15, L_tmp2, add( gainCNG_e, 31 - 30 ), &tmp_e ); /*Q31*/ + move32(); + st->Mode2_lp_gainc = L_shl( st->Mode2_lp_gainc, sub( tmp_e, 31 - 16 ) ); move32(); /* PLC: [TCX: Fade-out] Linearly attenuate the gain through the frame */ /*step = (1.0f/L_frame) * (gain - (st->Mode2_lp_gainc));*/ - L_tmp = L_sub(gain32,st->Mode2_lp_gainc);/*Q16*/ - tmp_e = norm_l(L_tmp); - L_tmp = L_shl(L_tmp,tmp_e);/*Q16,-tmp_e*/ - step32 = Mpy_32_16_1(L_tmp/*Q16,-tmp_e*/,getInvFrameLen(L_frame)/*W16Q21*/);/*Q22,-tmp_e*/ - step32 = L_shl(step32,sub((25-22),tmp_e));/*Q25*/ - - pt_exc = noise + L_FIR_FER2/2; - - /*gain_inov = 1.0f / (float)sqrt( dot_product( pt_exc, pt_exc, L_frame ) / L_frame + 0.01f );*//* normalize energy */ - L_tmp = Dot_productSq16HQ(0,pt_exc/*Q0,15+1*/,L_frame,&tmp_e)/*Q31,tmp_e+16+16*/; - L_tmp = Mpy_32_16_1(L_tmp,getInvFrameLen(L_frame)/*W16Q21*/)/*W32Q37,tmp_e+16+16*//*Q5,tmp_e*/; - tmp_e = add(tmp_e,31-5);/*-->Q31*/ - gain_inov = round_fx(ISqrt32(L_tmp,&tmp_e));/*Q15,tmp_e*/ + L_tmp = L_sub( gain32, st->Mode2_lp_gainc ); /*Q16*/ + tmp_e = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, tmp_e ); /*Q16,-tmp_e*/ + step32 = Mpy_32_16_1( L_tmp /*Q16,-tmp_e*/, getInvFrameLen( L_frame ) /*W16Q21*/ ); /*Q22,-tmp_e*/ + step32 = L_shl( step32, sub( ( 25 - 22 ), tmp_e ) ); /*Q25*/ + + pt_exc = noise + L_FIR_FER2 / 2; + + /*gain_inov = 1.0f / (float)sqrt( dot_product( pt_exc, pt_exc, L_frame ) / L_frame + 0.01f );*/ /* normalize energy */ + L_tmp = Dot_productSq16HQ( 0, pt_exc /*Q0,15+1*/, L_frame, &tmp_e ) /*Q31,tmp_e+16+16*/; + L_tmp = Mpy_32_16_1( L_tmp, getInvFrameLen( L_frame ) /*W16Q21*/ ) /*W32Q37,tmp_e+16+16*/ /*Q5,tmp_e*/; + tmp_e = add( tmp_e, 31 - 5 ); /*-->Q31*/ + gain_inov = round_fx( ISqrt32( L_tmp, &tmp_e ) ); /*Q15,tmp_e*/ gain_inov_e = tmp_e; move16(); test(); test(); - IF (EQ_16(st->last_good , UNVOICED_CLAS)&&NE_16(st->core_ext_mode,UNVOICED)) + IF( EQ_16( st->last_good, UNVOICED_CLAS ) && NE_16( st->core_ext_mode, UNVOICED ) ) { - gain_inov = mult_r(gain_inov,26214/*0.8f Q15*/); + gain_inov = mult_r( gain_inov, 26214 /*0.8f Q15*/ ); } - ELSE IF (!( EQ_16(st->last_good , UNVOICED_CLAS)||EQ_16(st->last_good,UNVOICED_TRANSITION))) + ELSE IF( !( EQ_16( st->last_good, UNVOICED_CLAS ) || EQ_16( st->last_good, UNVOICED_TRANSITION ) ) ) { /*gain_inov *= (1.1f- 0.75*st->lp_gainp);*/ - L_tmp = Mpy_32_16_1(L_sub(590558016l/*1.1f Q29*/, Mpy_32_16_1(st->Mode2_lp_gainp,24576))/*Q29*/,gain_inov/*Q15,gain_inov_e*/);/*Q29,gain_inov_e*/ - tmp_e = norm_l(L_tmp); - L_tmp = L_shl(L_tmp,tmp_e); - gain_inov_e = add(sub(gain_inov_e,tmp_e),31-29);/*->Q31*/ + L_tmp = Mpy_32_16_1( L_sub( 590558016l /*1.1f Q29*/, Mpy_32_16_1( st->Mode2_lp_gainp, 24576 ) ) /*Q29*/, gain_inov /*Q15,gain_inov_e*/ ); /*Q29,gain_inov_e*/ + tmp_e = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, tmp_e ); + gain_inov_e = add( sub( gain_inov_e, tmp_e ), 31 - 29 ); /*->Q31*/ #ifdef BASOP_NOGLOB /* Critical Overflow */ - gain_inov = round_fx_sat( L_tmp ); /*Q15,gain_inov_e*/ + gain_inov = round_fx_sat( L_tmp ); /*Q15,gain_inov_e*/ #else - gain_inov = round_fx(L_tmp);/*Q15,gain_inov_e*/ + gain_inov = round_fx( L_tmp ); /*Q15,gain_inov_e*/ #endif } - st->Mode2_lp_gainp = L_shr(L_deposit_h(alpha/*Q14*/)/*Q14+16*/,1);/*Q29*/ - pt_exc = noise; /* non-causal ringing of the FIR filter */ + st->Mode2_lp_gainp = L_shr( L_deposit_h( alpha /*Q14*/ ) /*Q14+16*/, 1 ); /*Q29*/ + pt_exc = noise; /* non-causal ringing of the FIR filter */ - tmp_e = norm_l(gain32); - tmp_e = sub(tmp_e,5); /*5 Bit additional Headroom for the gain - should be enough*/ - gain32 = L_shl(gain32,tmp_e);/*Q16,-tmp_e*/ - L_tmp = Mpy_32_16_1(gain32/*Q16,-tmp_e*/, gain_inov/*Q15,gain_inov_e*/)/*Q16,gain_inov_e-tmp_e*/; + tmp_e = norm_l( gain32 ); + tmp_e = sub( tmp_e, 5 ); /*5 Bit additional Headroom for the gain - should be enough*/ + gain32 = L_shl( gain32, tmp_e ); /*Q16,-tmp_e*/ + L_tmp = Mpy_32_16_1( gain32 /*Q16,-tmp_e*/, gain_inov /*Q15,gain_inov_e*/ ) /*Q16,gain_inov_e-tmp_e*/; - gain_tmp = round_fx(L_tmp);/*Q0, gain_inov_e-tmp_e*/ + gain_tmp = round_fx( L_tmp ); /*Q0, gain_inov_e-tmp_e*/ - FOR( i=0 ; i< L_FIR_FER2/2; i++ ) + FOR( i = 0; i < L_FIR_FER2 / 2; i++ ) { - *pt_exc = mult_r(*pt_exc,gain_tmp);/*Q-15,noise_e+gain_inov_e-tmp_e*/ move16(); + *pt_exc = mult_r( *pt_exc, gain_tmp ); /*Q-15,noise_e+gain_inov_e-tmp_e*/ + move16(); pt_exc++; } - tmp16 = add(L_frame,L_FIR_FER2/2); - step32_tmp = L_shl(step32/*Q25*/,sub(tmp_e,(25-16)));/*Q16,-tmp_e*/ - FOR( i=0 ; i< tmp16; i++ ) /* Actual filtered random part of excitation */ + tmp16 = add( L_frame, L_FIR_FER2 / 2 ); + step32_tmp = L_shl( step32 /*Q25*/, sub( tmp_e, ( 25 - 16 ) ) ); /*Q16,-tmp_e*/ + FOR( i = 0; i < tmp16; i++ ) /* Actual filtered random part of excitation */ { - *pt_exc = mult_r(*pt_exc, gain_tmp); + *pt_exc = mult_r( *pt_exc, gain_tmp ); move16(); pt_exc++; - gain32 = L_sub(gain32/*Q16,-tmp_e*/,step32_tmp);/*Q16,-tmp_e*/ - gain_tmp = mult_r(round_fx(gain32/*Q16,-tmp_e*/)/*Q0*/, gain_inov/*Q15,gain_inov_e*/)/*Q0,gain_inov_e-tmp_e*/; + gain32 = L_sub( gain32 /*Q16,-tmp_e*/, step32_tmp ); /*Q16,-tmp_e*/ + gain_tmp = mult_r( round_fx( gain32 /*Q16,-tmp_e*/ ) /*Q0*/, gain_inov /*Q15,gain_inov_e*/ ) /*Q0,gain_inov_e-tmp_e*/; } - tmp16 = shr(L_frame,1); - FOR( i=0 ; i< tmp16; i++ ) /* causal ringing of the FIR filter */ + tmp16 = shr( L_frame, 1 ); + FOR( i = 0; i < tmp16; i++ ) /* causal ringing of the FIR filter */ { - *pt_exc = mult_r(*pt_exc , gain_tmp); + *pt_exc = mult_r( *pt_exc, gain_tmp ); move16(); pt_exc++; } - noise_e = add(sub(add(noise_e,gain_inov_e),tmp_e),15);/*--> noise is Q0, noise_e*/ + noise_e = add( sub( add( noise_e, gain_inov_e ), tmp_e ), 15 ); /*--> noise is Q0, noise_e*/ /*buf[0;L_FIR_FER2 + L_Frame + L_Frame/2] Q0, noise_e*/ /*-----------------------------------------------------------------* * Construct the total excitation *-----------------------------------------------------------------*/ - IF( GE_16(st->last_good , UNVOICED_TRANSITION)) + IF( GE_16( st->last_good, UNVOICED_TRANSITION ) ) { - tmp16 = add(L_frame,shr(L_frame,1)); - FOR( i=0 ; i< tmp16; i++ ) + tmp16 = add( L_frame, shr( L_frame, 1 ) ); + FOR( i = 0; i < tmp16; i++ ) { #ifdef BASOP_NOGLOB - exc[i] = add_sat(exc[i], shl_sat(noise[i + (L_FIR_FER2 / 2)], Q_exc + noise_e));/*Q1*/ move16(); + exc[i] = add_sat( exc[i], shl_sat( noise[i + ( L_FIR_FER2 / 2 )], Q_exc + noise_e ) ); /*Q1*/ + move16(); #else - exc[i] = add(exc[i] , shl(noise[i+(L_FIR_FER2/2)],Q_exc+noise_e));/*Q1*/ move16(); + exc[i] = add( exc[i], shl( noise[i + ( L_FIR_FER2 / 2 )], Q_exc + noise_e ) ); /*Q1*/ + move16(); #endif } } ELSE { - bufferCopyFx(noise+L_FIR_FER2/2, exc, add(L_frame , shr(L_frame,1)),0/*Q_noise*/, noise_e, Q_exc, 0/*exc_e*/); - Copy(exc+L_frame-2*L_subfr, hTcxDec->old_excFB_fx, 2*L_subfr+shr(L_frame,1)); + bufferCopyFx( noise + L_FIR_FER2 / 2, exc, add( L_frame, shr( L_frame, 1 ) ), 0 /*Q_noise*/, noise_e, Q_exc, 0 /*exc_e*/ ); + Copy( exc + L_frame - 2 * L_subfr, hTcxDec->old_excFB_fx, 2 * L_subfr + shr( L_frame, 1 ) ); /* copy old_exc as 16kHz for acelp decoding */ - IF ( EQ_16(st->nbLostCmpt, 1)) + IF( EQ_16( st->nbLostCmpt, 1 ) ) { - lerp(exc, st->old_exc_fx, L_EXC_MEM_DEC, add(L_frame, shr(L_frame,1))); + lerp( exc, st->old_exc_fx, L_EXC_MEM_DEC, add( L_frame, shr( L_frame, 1 ) ) ); } - ELSE { - Copy(st->old_exc_fx+L_FRAME16k, st->old_exc_fx, L_FRAME16k/2); - lerp(exc, st->old_exc_fx+L_FRAME16k/2, L_FRAME16k, L_frame); + ELSE + { + Copy( st->old_exc_fx + L_FRAME16k, st->old_exc_fx, L_FRAME16k / 2 ); + lerp( exc, st->old_exc_fx + L_FRAME16k / 2, L_FRAME16k, L_frame ); } st->Q_exc = Q_exc; } @@ -940,101 +941,101 @@ void con_tcx_fx( *----------------------------------------------------------*/ syn = buf + M; - Copy(synth-M, buf, M); + Copy( synth - M, buf, M ); - new_Q = sub(Q_exc, 3); - new_Q = s_max(new_Q, -1); + new_Q = sub( Q_exc, 3 ); + new_Q = s_max( new_Q, -1 ); - tmp16 = s_min(new_Q, st->prev_Q_syn); + tmp16 = s_min( new_Q, st->prev_Q_syn ); st->prev_Q_syn = new_Q; - move16(); + move16(); - exp_scale = sub(tmp16, Q_exc-1); + exp_scale = sub( tmp16, Q_exc - 1 ); Q_syn = tmp16; move16(); - Copy_Scale_sig(buf, mem_syn, M, exp_scale); + Copy_Scale_sig( buf, mem_syn, M, exp_scale ); #ifdef BASOP_NOGLOB - tmp_deemph = shl_sat(tmp_deemph,Q_syn); + tmp_deemph = shl_sat( tmp_deemph, Q_syn ); #else - tmp_deemph = shl(tmp_deemph,Q_syn); + tmp_deemph = shl( tmp_deemph, Q_syn ); #endif st->Q_syn = Q_syn; /*buf[OLD_EXC_SIZE_DEC;3/2 L_frame] Q1: exc*/ /*buf[0;M] Q0: mem_syn*/ #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - if (A_cng != NULL) + if ( A_cng != NULL ) { float alpha_delayed; alpha_delayed = 1.0f; - if (st->nbLostCmpt > MDCT_ST_PLC_FADEOUT_DELAY_4_LSP_FADE) + if ( st->nbLostCmpt > MDCT_ST_PLC_FADEOUT_DELAY_4_LSP_FADE ) { - alpha_delayed = Damping_fact_fx(st->core_ext_mode, st->nbLostCmpt - MDCT_ST_PLC_FADEOUT_DELAY_4_LSP_FADE, st->last_good, st->stab_fac, &(st->lp_gainp), ACELP_CORE); + alpha_delayed = Damping_fact_fx( st->core_ext_mode, st->nbLostCmpt - MDCT_ST_PLC_FADEOUT_DELAY_4_LSP_FADE, st->last_good, st->stab_fac, &( st->lp_gainp ), ACELP_CORE ); } - if (st->plcBackgroundNoiseUpdated && alpha_delayed != 1.0f) + if ( st->plcBackgroundNoiseUpdated && alpha_delayed != 1.0f ) { float lsp_local[M], lsp_fade[M], alpha_inv; alpha_inv = 1.0f - alpha_delayed; - a2lsp_stab(A_local, lsp_local, lsp_local); + a2lsp_stab( A_local, lsp_local, lsp_local ); - for (i = 0; i < M; i++) + for ( i = 0; i < M; i++ ) { lsp_fade[i] = alpha_delayed * lsp_local[i] + alpha_inv * st->lspold_cng[i]; } - lsp2a_stab(lsp_fade, A_local, M); + lsp2a_stab( lsp_fade, A_local, M ); } } #endif E_UTIL_synthesis( - sub(Q_exc, Q_syn), + sub( Q_exc, Q_syn ), A_local, &exc[0], &syn[0], - add(L_frame, shr(L_frame,1)), + add( L_frame, shr( L_frame, 1 ) ), mem_syn, 1, - M); + M ); /*buf[OLD_EXC_SIZE_DEC;3/2 L_frame-1] Q1: exc*/ /*buf[0;M-1] Q0: mem_syn*/ /*buf[M;3/2 L_frame-1] Q-1: syn*/ - n = extract_h(L_mult(L_frame,9216/*(float)N_ZERO_MDCT_NS/(float)FRAME_SIZE_NS Q15*/)); + n = extract_h( L_mult( L_frame, 9216 /*(float)N_ZERO_MDCT_NS/(float)FRAME_SIZE_NS Q15*/ ) ); /* update ACELP synthesis memory */ - mem_syn_r_size_old = shr(L_frame,4); /* replace 1.25/20.0 by shr(4) */ + mem_syn_r_size_old = shr( L_frame, 4 ); /* replace 1.25/20.0 by shr(4) */ /* copy mem_syn as 16kHz */ - mem_syn_r_size_new = shr(L_FRAME16k,4); /* replace 1.25/20.0 by shr(4) */ + mem_syn_r_size_new = shr( L_FRAME16k, 4 ); /* replace 1.25/20.0 by shr(4) */ - Copy(syn+L_frame-L_SYN_MEM, st->mem_syn_r, L_SYN_MEM); - lerp(st->mem_syn_r+L_SYN_MEM-mem_syn_r_size_old, st->mem_syn_r+L_SYN_MEM-mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old); - Copy(st->mem_syn_r+L_SYN_MEM-M, st->mem_syn2_fx, M); + Copy( syn + L_frame - L_SYN_MEM, st->mem_syn_r, L_SYN_MEM ); + lerp( st->mem_syn_r + L_SYN_MEM - mem_syn_r_size_old, st->mem_syn_r + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); + Copy( st->mem_syn_r + L_SYN_MEM - M, st->mem_syn2_fx, M ); /* Deemphasis and output synth and ZIR */ - deemph_fx(syn, st->preemph_fac, add(L_frame,shr(L_frame,1)), &tmp_deemph); - bufferCopyFx(syn+L_frame-M-1, st->syn, 1+M, Q_syn, 0, 0, 0); + deemph_fx( syn, st->preemph_fac, add( L_frame, shr( L_frame, 1 ) ), &tmp_deemph ); + bufferCopyFx( syn + L_frame - M - 1, st->syn, 1 + M, Q_syn, 0, 0, 0 ); - lerp( syn+L_frame-shr(L_frame, 1), hTcxDec->old_syn_Overl, shr(st->L_frame, 1), shr(L_frame, 1) ); - Copy(syn+L_frame-n, hHQ_core->old_out_fx, sub(L_frame,n)); + lerp( syn + L_frame - shr( L_frame, 1 ), hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), shr( L_frame, 1 ) ); + Copy( syn + L_frame - n, hHQ_core->old_out_fx, sub( L_frame, n ) ); - FOR (i=0; i < W12; i++) + FOR( i = 0; i < W12; i++ ) { - hHQ_core->old_out_fx[i+n] = round_fx(Mpy_32_16_1(L_mult(w[i].v.re,w[i].v.re), hHQ_core->old_out_fx[i+n])); + hHQ_core->old_out_fx[i + n] = round_fx( Mpy_32_16_1( L_mult( w[i].v.re, w[i].v.re ), hHQ_core->old_out_fx[i + n] ) ); } - FOR ( ; i < W1; i++) + FOR( ; i < W1; i++ ) { - hHQ_core->old_out_fx[i+n] = round_fx(Mpy_32_16_1(L_mult(w[W12-1-(i-W12)].v.im,w[W12-1-(i-W12)].v.im), hHQ_core->old_out_fx[i+n])); + hHQ_core->old_out_fx[i + n] = round_fx( Mpy_32_16_1( L_mult( w[W12 - 1 - ( i - W12 )].v.im, w[W12 - 1 - ( i - W12 )].v.im ), hHQ_core->old_out_fx[i + n] ) ); } - set16_fx(&hHQ_core->old_out_fx[W1+n], 0, n); + set16_fx( &hHQ_core->old_out_fx[W1 + n], 0, n ); hHQ_core->Q_old_wtda = Q_syn; move16(); @@ -1042,43 +1043,43 @@ void con_tcx_fx( /* As long as there is no synth scaling factor introduced, which is given to the outside, there might occur overflows here */ BASOP_SATURATE_WARNING_OFF_EVS - bufferCopyFx(syn, synth, L_frame, Q_syn, 0, 0, 0); + bufferCopyFx( syn, synth, L_frame, Q_syn, 0, 0, 0 ); BASOP_SATURATE_WARNING_ON_EVS - Copy_Scale_sig(syn+L_frame, hTcxDec->syn_OverlFB, shr(L_frame,1), negate(Q_syn)); + Copy_Scale_sig( syn + L_frame, hTcxDec->syn_OverlFB, shr( L_frame, 1 ), negate( Q_syn ) ); /* copy total excitation exc2 as 16kHz for acelp mode1 decoding */ - IF(st->hWIDec != NULL) + IF( st->hWIDec != NULL ) { - lerp(exc, st->hWIDec->old_exc2_fx, L_EXC_MEM, L_frame); - lerp(syn, st->hWIDec->old_syn2_fx, L_EXC_MEM, L_frame); + lerp( exc, st->hWIDec->old_exc2_fx, L_EXC_MEM, L_frame ); + lerp( syn, st->hWIDec->old_syn2_fx, L_EXC_MEM, L_frame ); } #ifdef BASOP_NOGLOB - st->bfi_pitch_fx/*Q6*/ = round_fx_sat(L_shl_sat(pitch_buf[st->nb_subfr-1]/*15Q16*/,6/*Q6*/)); + st->bfi_pitch_fx /*Q6*/ = round_fx_sat( L_shl_sat( pitch_buf[st->nb_subfr - 1] /*15Q16*/, 6 /*Q6*/ ) ); #else - st->bfi_pitch_fx/*Q6*/ = round_fx(L_shl(pitch_buf[st->nb_subfr-1]/*15Q16*/,6/*Q6*/)); + st->bfi_pitch_fx /*Q6*/ = round_fx( L_shl( pitch_buf[st->nb_subfr - 1] /*15Q16*/, 6 /*Q6*/ ) ); #endif move16(); st->bfi_pitch_frame = st->L_frame; move16(); /* create aliasing and windowing need for transition to TCX10/5 */ - bufferCopyFx(syn+L_frame, hTcxDec->syn_Overl_TDACFB, shr(L_frame,1),Q_syn,0,-1,0); + bufferCopyFx( syn + L_frame, hTcxDec->syn_Overl_TDACFB, shr( L_frame, 1 ), Q_syn, 0, -1, 0 ); - FOR (i=0 ; i < W12 ; i++) + FOR( i = 0; i < W12; i++ ) { - buf[i] = mult_r(hTcxDec->syn_Overl_TDACFB[i] , w[i].v.re); + buf[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[i].v.re ); move16(); } - FOR ( ; i syn_Overl_TDACFB[i],w[W12-1-(i-W12)].v.im); + buf[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[W12 - 1 - ( i - W12 )].v.im ); move16(); } - FOR (i=0; isyn_Overl_TDACFB[i] = add_sat( buf[i], buf[W1 - 1 - i] ); @@ -1088,7 +1089,7 @@ void con_tcx_fx( move16(); } - FOR (i=0; isyn_Overl_TDACFB[W2 + i] = add_sat( buf[W2 + i], buf[W1 - 1 - W2 - i] ); @@ -1098,14 +1099,14 @@ void con_tcx_fx( move16(); } - FOR (i=0 ; i < W12 ; i++) + FOR( i = 0; i < W12; i++ ) { - hTcxDec->syn_Overl_TDACFB[i] = mult_r(hTcxDec->syn_Overl_TDACFB[i],w[i].v.re); + hTcxDec->syn_Overl_TDACFB[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[i].v.re ); move16(); } - FOR ( ; i syn_Overl_TDACFB[i] = mult_r(hTcxDec->syn_Overl_TDACFB[i],w[W12-1-(i-W12)].v.im); + hTcxDec->syn_Overl_TDACFB[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[W12 - 1 - ( i - W12 )].v.im ); move16(); } @@ -1115,52 +1116,53 @@ void con_tcx_fx( move16(); /* update memory for low band */ - Scale_sig(hTcxDec->old_syn_Overl, shr(st->L_frame, 1), sub(-1, Q_syn)); - lerp(hTcxDec->syn_OverlFB, hTcxDec->syn_Overl, shr(st->L_frame, 1), shr(L_frame, 1) ); - lerp(hTcxDec->syn_Overl_TDACFB, hTcxDec->syn_Overl_TDAC, shr(st->L_frame, 1), shr(L_frame, 1) ); + Scale_sig( hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), sub( -1, Q_syn ) ); + lerp( hTcxDec->syn_OverlFB, hTcxDec->syn_Overl, shr( st->L_frame, 1 ), shr( L_frame, 1 ) ); + lerp( hTcxDec->syn_Overl_TDACFB, hTcxDec->syn_Overl_TDAC, shr( st->L_frame, 1 ), shr( L_frame, 1 ) ); lerp( st->hHQ_core->old_out_fx, st->hHQ_core->old_out_LB_fx, st->L_frame, L_frame ); - st->old_enr_LP = Enr_1_Az_fx(A_local, L_SUBFR); /*Q3*/ + st->old_enr_LP = Enr_1_Az_fx( A_local, L_SUBFR ); /*Q3*/ return; } #ifdef IVAS_FLOAT_FIXED void con_tcx_ivas_fx( - Decoder_State *st, /* i/o: coder memory state */ - Word16 synth[], /* i/o: synth[] *//*Q0 */ - const Word16 coh, /* i : coherence of stereo signal */ - Word16 * noise_seed, /* i/o: noise seed for stereo */ - const Word16 only_left, /* i : TD-PLC only in left channel */ - const Word16* A_cng /* i : CNG LP filter coefficients */ + Decoder_State *st, /* i/o: coder memory state */ + Word16 synth[], + /* i/o: synth[] */ /*Q0 */ + const Word16 coh, /* i : coherence of stereo signal */ + Word16 *noise_seed, /* i/o: noise seed for stereo */ + const Word16 only_left, /* i : TD-PLC only in left channel */ + const Word16 *A_cng /* i : CNG LP filter coefficients */ ) { - Word16 i, s, c, L_frame, L_subfr, fLowPassFilter, T0; - Word16 n, mem_syn_r_size_old, mem_syn_r_size_new; - Word16 *noise; - Word16 mem_syn[M], *syn; - Word16 *exc, buf[OLD_EXC_SIZE_DEC+L_FRAME_MAX+L_FRAME_MAX/NB_SUBFR+1+L_FRAME_MAX/2]; - Word16 pre_emph_buf; - Word16 hp_filt[L_FIR_FER2]; - Word16 alpha; - Word16 tmp_deemph, gain, gainCNG, gain_inov; - Word16 *pt_exc, *pt1_exc; - Word16 Tc, tmpSeed; - Word16 fUseExtrapolatedPitch; - Word16 *ana_window; - Word16 r_h[M+1], A_local[M+1], mem, r_l[M+1]; - PWord16 const *w; - Word16 W1, W2, W12; + Word16 i, s, c, L_frame, L_subfr, fLowPassFilter, T0; + Word16 n, mem_syn_r_size_old, mem_syn_r_size_new; + Word16 *noise; + Word16 mem_syn[M], *syn; + Word16 *exc, buf[OLD_EXC_SIZE_DEC + L_FRAME_MAX + L_FRAME_MAX / NB_SUBFR + 1 + L_FRAME_MAX / 2]; + Word16 pre_emph_buf; + Word16 hp_filt[L_FIR_FER2]; + Word16 alpha; + Word16 tmp_deemph, gain, gainCNG, gain_inov; + Word16 *pt_exc, *pt1_exc; + Word16 Tc, tmpSeed; + Word16 fUseExtrapolatedPitch; + Word16 *ana_window; + Word16 r_h[M + 1], A_local[M + 1], mem, r_l[M + 1]; + PWord16 const *w; + Word16 W1, W2, W12; Word16 Q_r; - Word16 tmp16, tmp16_2, tmp_loop, tmp_e, gain_tmp; - Word16 gainCNG_e, noise_e, gain_inov_e ;/*Exponents for gainCNG, noise, gain_inov*/ - Word16 Q_syn; /*Q format of temporary synthesis buffer syn*/ + Word16 tmp16, tmp16_2, tmp_loop, tmp_e, gain_tmp; + Word16 gainCNG_e, noise_e, gain_inov_e; /*Exponents for gainCNG, noise, gain_inov*/ + Word16 Q_syn; /*Q format of temporary synthesis buffer syn*/ Word32 L_tmp, L_tmp2, step32_tmp; Word32 predPitchLag, pitch_buf[NB_SUBFR16k], step32, gain32; - Word16 extrapolationFailed; - Word16 gainSynthDeemph; - Word16 gainSynthDeemph_e; - Word32 old_pitch_buf[2*NB_SUBFR16k+2]; + Word16 extrapolationFailed; + Word16 gainSynthDeemph; + Word16 gainSynthDeemph_e; + Word32 old_pitch_buf[2 * NB_SUBFR16k + 2]; Word16 Q_exc, new_Q, exp_scale; Word16 offset; HQ_DEC_HANDLE hHQ_core; @@ -1181,7 +1183,8 @@ void con_tcx_ivas_fx( noise_e = 0; move16(); - Q_syn = -1; /*Q format of temporary synthesis buffer syn*/ move16(); + Q_syn = -1; /*Q format of temporary synthesis buffer syn*/ + move16(); offset = 0; move16(); @@ -1189,98 +1192,98 @@ void con_tcx_ivas_fx( L_frame = hTcxDec->L_frameTCX; move16(); /* L_subfr = st->L_frameTCX/st->nb_subfr */ - L_subfr = mult_r(hTcxDec->L_frameTCX,div_s(1,st->nb_subfr)); - assert( L_subfr == hTcxDec->L_frameTCX/st->nb_subfr ); + L_subfr = mult_r( hTcxDec->L_frameTCX, div_s( 1, st->nb_subfr ) ); + assert( L_subfr == hTcxDec->L_frameTCX / st->nb_subfr ); move32(); w = st->hTcxCfg->tcx_mdct_windowFB; /*pointer - no need to instrument*/ W1 = st->hTcxCfg->tcx_mdct_window_lengthFB; move16(); - W2 = shr(st->hTcxCfg->tcx_mdct_window_lengthFB, 1); - W12 = shr(W1,1); + W2 = shr( st->hTcxCfg->tcx_mdct_window_lengthFB, 1 ); + W12 = shr( W1, 1 ); /* take the previous frame last pitch */ - Tc = round_fx(st->old_fpitchFB); + Tc = round_fx( st->old_fpitchFB ); - set16_fx(buf,0, OLD_EXC_SIZE_DEC + L_FRAME_MAX + L_FRAME_MAX / NB_SUBFR + 1 + L_FRAME_MAX / 2); /* initialize buf with 0 */ - //set16_fx(buf,0,shr(sizeof(buf),1)); /* initialize buf with 0 */ + set16_fx( buf, 0, OLD_EXC_SIZE_DEC + L_FRAME_MAX + L_FRAME_MAX / NB_SUBFR + 1 + L_FRAME_MAX / 2 ); /* initialize buf with 0 */ + // set16_fx(buf,0,shr(sizeof(buf),1)); /* initialize buf with 0 */ c = BASOP_Util_Divide1616_Scale( - L_frame, - st->L_frame, - &s - ); + L_frame, + st->L_frame, + &s ); - FOR (i=0; i < (2*NB_SUBFR16k+2); i++) + FOR( i = 0; i < ( 2 * NB_SUBFR16k + 2 ); i++ ) { - old_pitch_buf[i] = L_shl(Mpy_32_16_1(st->old_pitch_buf_fx[i],c),s); + old_pitch_buf[i] = L_shl( Mpy_32_16_1( st->old_pitch_buf_fx[i], c ), s ); move32(); } /* set excitation memory*/ - exc = buf+OLD_EXC_SIZE_DEC; + exc = buf + OLD_EXC_SIZE_DEC; tmp_deemph = synth[-1]; move16(); pre_emph_buf = synth[-1]; move16(); test(); - IF ( (EQ_16( st->nbLostCmpt, 1 ))|| hTcxDec->tcxConceal_recalc_exc) + IF( ( EQ_16( st->nbLostCmpt, 1 ) ) || hTcxDec->tcxConceal_recalc_exc ) { /* apply pre-emphasis to the signal */ - mem = synth[-((shr(L_frame,1))+ hTcxDec->pit_max_TCX+M+M)-1]; - Q_exc = E_UTIL_f_preemph3(&(synth[-((shr(L_frame,1))+ hTcxDec->pit_max_TCX+2*M)]), st->preemph_fac, add(add(shr(L_frame,1), hTcxDec->pit_max_TCX),shl(M,1)), &mem,1); - st->Mode2_lp_gainc = L_deposit_l(0); + mem = synth[-( ( shr( L_frame, 1 ) ) + hTcxDec->pit_max_TCX + M + M ) - 1]; + Q_exc = E_UTIL_f_preemph3( &( synth[-( ( shr( L_frame, 1 ) ) + hTcxDec->pit_max_TCX + 2 * M )] ), st->preemph_fac, add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), shl( M, 1 ) ), &mem, 1 ); + st->Mode2_lp_gainc = L_deposit_l( 0 ); - st->Mode2_lp_gainp = get_gain2( synth-2*L_subfr, synth-2*L_subfr-Tc, shl(L_subfr,1) ); + st->Mode2_lp_gainp = get_gain2( synth - 2 * L_subfr, synth - 2 * L_subfr - Tc, shl( L_subfr, 1 ) ); move32(); - st->Mode2_lp_gainp = L_max(st->Mode2_lp_gainp,0); - st->Mode2_lp_gainp = L_min(st->Mode2_lp_gainp,65536l/*1.0f Q16*/); - st->Mode2_lp_gainp = L_shl(st->Mode2_lp_gainp, 13); + st->Mode2_lp_gainp = L_max( st->Mode2_lp_gainp, 0 ); + st->Mode2_lp_gainp = L_min( st->Mode2_lp_gainp, 65536l /*1.0f Q16*/ ); + st->Mode2_lp_gainp = L_shl( st->Mode2_lp_gainp, 13 ); ana_window = buf; - ham_cos_window(ana_window, mult(L_frame,24576/*0.75f Q15*/), shr(L_frame,2)); + ham_cos_window( ana_window, mult( L_frame, 24576 /*0.75f Q15*/ ), shr( L_frame, 2 ) ); /* Autocorrelation */ - autocorr_fx(&(synth[-L_frame-1]), M, r_h ,r_l , &Q_r , L_frame, ana_window, 0, 0); + autocorr_fx( &( synth[-L_frame - 1] ), M, r_h, r_l, &Q_r, L_frame, ana_window, 0, 0 ); /* Lag windowing */ - lag_wind( r_h,r_l, M, st->output_Fs, LAGW_STRONG ); + lag_wind( r_h, r_l, M, st->output_Fs, LAGW_STRONG ); /* Levinson Durbin */ - E_LPC_lev_dur(r_h, r_l, A_local, NULL, M, NULL); + E_LPC_lev_dur( r_h, r_l, A_local, NULL, M, NULL ); /* copy for multiple frame loss */ - Copy(A_local, st->old_Aq_12_8_fx, M+1); + Copy( A_local, st->old_Aq_12_8_fx, M + 1 ); /* Residu */ - assert((2*L_subfr+Tc+1+M) <= hTcxDec->old_synth_lenFB); + assert( ( 2 * L_subfr + Tc + 1 + M ) <= hTcxDec->old_synth_lenFB ); BASOP_SATURATE_WARNING_OFF_EVS /*saturation possible in case of spiky synthesis*/ - Residu3_fx( - A_local, - &(synth[-(2*L_subfr+Tc+1+M)]), /*Qx = Q0*/ - &(exc[-(2*L_subfr+Tc+1+M)]), /*Qx+1 = Q1*/ - add(add(add(shl(L_subfr,1),Tc),1),M), - 1); + Residu3_fx( + A_local, + &( synth[-( 2 * L_subfr + Tc + 1 + M )] ), /*Qx = Q0*/ + &( exc[-( 2 * L_subfr + Tc + 1 + M )] ), /*Qx+1 = Q1*/ + add( add( add( shl( L_subfr, 1 ), Tc ), 1 ), M ), + 1 ); BASOP_SATURATE_WARNING_ON_EVS } ELSE { /* apply pre-emphasis to the signal */ - mem = synth[-L_frame-1]; - Q_exc = E_UTIL_f_preemph3(&(synth[-L_frame]), st->preemph_fac, L_frame, &mem, 1); - Copy(st->old_Aq_12_8_fx, A_local, M+1); + mem = synth[-L_frame - 1]; + Q_exc = E_UTIL_f_preemph3( &( synth[-L_frame] ), st->preemph_fac, L_frame, &mem, 1 ); + Copy( st->old_Aq_12_8_fx, A_local, M + 1 ); - offset = shr(L_frame,1); - IF(GE_16(st->last_good, UNVOICED_TRANSITION)) + offset = shr( L_frame, 1 ); + IF( GE_16( st->last_good, UNVOICED_TRANSITION ) ) { - tmp16 = s_max(Tc - shr(L_frame,1), 0); - Copy_Scale_sig(hTcxDec->old_excFB_fx, &(exc[-tmp16]), offset+tmp16, Q_exc-st->Q_exc); + tmp16 = s_max( Tc - shr( L_frame, 1 ), 0 ); + Copy_Scale_sig( hTcxDec->old_excFB_fx, &( exc[-tmp16] ), offset + tmp16, Q_exc - st->Q_exc ); } - ELSE { - Copy_Scale_sig(hTcxDec->old_excFB_fx, &(exc[-2*L_subfr]), 2*L_subfr+offset, Q_exc-st->Q_exc); + ELSE + { + Copy_Scale_sig( hTcxDec->old_excFB_fx, &( exc[-2 * L_subfr] ), 2 * L_subfr + offset, Q_exc - st->Q_exc ); } } @@ -1290,17 +1293,17 @@ void con_tcx_ivas_fx( test(); test(); - IF( GT_16(st->last_good, UNVOICED_CLAS)&&!(EQ_16(st->last_good,UNVOICED_TRANSITION)&&EQ_16(st->core_ext_mode,GENERIC))) + IF( GT_16( st->last_good, UNVOICED_CLAS ) && !( EQ_16( st->last_good, UNVOICED_TRANSITION ) && EQ_16( st->core_ext_mode, GENERIC ) ) ) { - IF ( EQ_16(st->nbLostCmpt,1)|| hTcxDec->tcxConceal_recalc_exc) + IF( EQ_16( st->nbLostCmpt, 1 ) || hTcxDec->tcxConceal_recalc_exc ) { - calcGainc_fx( exc, Q_exc, st->old_fpitchFB, L_subfr, st->Mode2_lp_gainp, &(st->Mode2_lp_gainc)); + calcGainc_fx( exc, Q_exc, st->old_fpitchFB, L_subfr, st->Mode2_lp_gainp, &( st->Mode2_lp_gainc ) ); } tmp16 = 0; move16(); - if (GT_32(st->output_Fs , 25600)) + if ( GT_32( st->output_Fs, 25600 ) ) { tmp16 = 1; move16(); @@ -1310,22 +1313,19 @@ void con_tcx_ivas_fx( test(); test(); test(); - IF( ((EQ_16(st->nbLostCmpt,1))|| hTcxDec->tcxConceal_recalc_exc)&&GE_16(st->rf_frame_type,RF_TCXFD)&&LE_16(st->rf_frame_type,RF_TCXTD2)&&st->use_partial_copy) + IF( ( ( EQ_16( st->nbLostCmpt, 1 ) ) || hTcxDec->tcxConceal_recalc_exc ) && GE_16( st->rf_frame_type, RF_TCXFD ) && LE_16( st->rf_frame_type, RF_TCXTD2 ) && st->use_partial_copy ) { - Word32 tcxltp_pitch_tmp = L_add(L_deposit_h(hTcxLtpDec->tcxltp_pitch_int), L_shl(L_deposit_l(div_s(hTcxLtpDec->tcxltp_pitch_fr,st->pit_res_max)),1)); /*15Q16*/ - Word16 scale_tmp = mult_r(hTcxDec->L_frameTCX, getInvFrameLen(st->L_frame)); /*getInvFrameLen()->9Q6*/ - Word16 tmp_shift = norm_s(scale_tmp); - predPitchLag = L_shl(Mpy_32_16_1(tcxltp_pitch_tmp, shl(scale_tmp, tmp_shift)), sub(9, tmp_shift)); + Word32 tcxltp_pitch_tmp = L_add( L_deposit_h( hTcxLtpDec->tcxltp_pitch_int ), L_shl( L_deposit_l( div_s( hTcxLtpDec->tcxltp_pitch_fr, st->pit_res_max ) ), 1 ) ); /*15Q16*/ + Word16 scale_tmp = mult_r( hTcxDec->L_frameTCX, getInvFrameLen( st->L_frame ) ); /*getInvFrameLen()->9Q6*/ + Word16 tmp_shift = norm_s( scale_tmp ); + predPitchLag = L_shl( Mpy_32_16_1( tcxltp_pitch_tmp, shl( scale_tmp, tmp_shift ) ), sub( 9, tmp_shift ) ); - T0 = round_fx(predPitchLag); + T0 = round_fx( predPitchLag ); test(); test(); test(); - if ( (T0 > 0) - && (NE_16(T0,Tc) ) - && (LT_32(L_deposit_h(abs_s(sub(T0,Tc)))/*Q16*/ , L_mult(4915/*.15f Q15*//*Q15*/,Tc/*Q0*/) /*Q16*/ ) ) - ) + if ( ( T0 > 0 ) && ( NE_16( T0, Tc ) ) && ( LT_32( L_deposit_h( abs_s( sub( T0, Tc ) ) ) /*Q16*/, L_mult( 4915 /*.15f Q15*/ /*Q15*/, Tc /*Q0*/ ) /*Q16*/ ) ) ) { fUseExtrapolatedPitch = 1; move16(); @@ -1338,7 +1338,7 @@ void con_tcx_ivas_fx( st->nbLostCmpt, st->last_good, old_pitch_buf, - &(st->old_fpitchFB), + &( st->old_fpitchFB ), &predPitchLag, hTcxDec->pit_min_TCX, hTcxDec->pit_max_TCX, @@ -1346,18 +1346,13 @@ void con_tcx_ivas_fx( tmp16, st->plc_use_future_lag, &extrapolationFailed, - st->nb_subfr - ); + st->nb_subfr ); - T0 = round_fx(predPitchLag); + T0 = round_fx( predPitchLag ); test(); test(); test(); - if ( (T0 > 0) - && (NE_16(T0,Tc) ) - && (LT_32(L_deposit_h(abs_s(sub(T0,Tc)))/*Q16*/ , L_mult(4915/*.15f Q15*//*Q15*/,Tc/*Q0*/) /*Q16*/ ) ) - && (extrapolationFailed == 0) - ) + if ( ( T0 > 0 ) && ( NE_16( T0, Tc ) ) && ( LT_32( L_deposit_h( abs_s( sub( T0, Tc ) ) ) /*Q16*/, L_mult( 4915 /*.15f Q15*/ /*Q15*/, Tc /*Q0*/ ) /*Q16*/ ) ) && ( extrapolationFailed == 0 ) ) { fUseExtrapolatedPitch = 1; move16(); @@ -1370,52 +1365,52 @@ void con_tcx_ivas_fx( pt_exc = exc + offset; pt1_exc = pt_exc - Tc; - if (fUseExtrapolatedPitch != 0) + if ( fUseExtrapolatedPitch != 0 ) { pt_exc = buf; } test(); - IF( LT_16(st->stab_fac_fx ,32767/*1.f Q15*/)&&EQ_16(st->nbLostCmpt,1)) + IF( LT_16( st->stab_fac_fx, 32767 /*1.f Q15*/ ) && EQ_16( st->nbLostCmpt, 1 ) ) { /* pitch cycle is first low-pass filtered */ - IF (LE_32(st->output_Fs , 16000)) + IF( LE_32( st->output_Fs, 16000 ) ) { - FOR( i=0 ; i< Tc; i++ ) + FOR( i = 0; i < Tc; i++ ) { move16(); - *pt_exc++ = mac_r(L_mac(L_mac(L_mac(L_mac(L_mac(L_mac(L_mac(L_mac(L_mac( - L_mult(174/* 0.0053f Q15*/, pt1_exc[-5]), - 0/* 0.0000f Q15*/, pt1_exc[-4]), - -1442/*-0.0440f Q15*/, pt1_exc[-3]), - 0/* 0.0000f Q15*/, pt1_exc[-2]), - 8641/* 0.2637f Q15*/, pt1_exc[-1]), - 18022/* 0.5500f Q15*/, pt1_exc[0] ), - 8641/* 0.2637f Q15*/, pt1_exc[1] ), - 0/* 0.0000f Q15*/, pt1_exc[2] ), - -1442/*-0.0440f Q15*/, pt1_exc[3] ), - 0/* 0.0000f Q15*/, pt1_exc[4] ), - 174/* 0.0053f Q15*/, pt1_exc[5] ); + *pt_exc++ = mac_r( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( + L_mult( 174 /* 0.0053f Q15*/, pt1_exc[-5] ), + 0 /* 0.0000f Q15*/, pt1_exc[-4] ), + -1442 /*-0.0440f Q15*/, pt1_exc[-3] ), + 0 /* 0.0000f Q15*/, pt1_exc[-2] ), + 8641 /* 0.2637f Q15*/, pt1_exc[-1] ), + 18022 /* 0.5500f Q15*/, pt1_exc[0] ), + 8641 /* 0.2637f Q15*/, pt1_exc[1] ), + 0 /* 0.0000f Q15*/, pt1_exc[2] ), + -1442 /*-0.0440f Q15*/, pt1_exc[3] ), + 0 /* 0.0000f Q15*/, pt1_exc[4] ), + 174 /* 0.0053f Q15*/, pt1_exc[5] ); pt1_exc++; } } ELSE /*(st->output_Fs >= 32000)*/ { - FOR( i=0 ; i< Tc; i++ ) + FOR( i = 0; i < Tc; i++ ) { move16(); - *pt_exc++ = mac_r(L_mac(L_mac(L_mac(L_mac(L_mac(L_mac(L_mac(L_mac(L_mac( - L_mult(-174/*-0.0053f Q15*/, pt1_exc[-5]), - -121/*-0.0037f Q15*/, pt1_exc[-4]), - -459/*-0.0140f Q15*/, pt1_exc[-3]), - 590/* 0.0180f Q15*/, pt1_exc[-2]), - 8743/* 0.2668f Q15*/, pt1_exc[-1]), - 16355/* 0.4991f Q15*/, pt1_exc[0] ), - 8743/* 0.2668f Q15*/, pt1_exc[1] ), - 590/* 0.0180f Q15*/, pt1_exc[2] ), - -459/*-0.0140f Q15*/, pt1_exc[3] ), - -121/*-0.0037f Q15*/, pt1_exc[4] ), - -174/*-0.0053f Q15*/, pt1_exc[5] ); + *pt_exc++ = mac_r( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( + L_mult( -174 /*-0.0053f Q15*/, pt1_exc[-5] ), + -121 /*-0.0037f Q15*/, pt1_exc[-4] ), + -459 /*-0.0140f Q15*/, pt1_exc[-3] ), + 590 /* 0.0180f Q15*/, pt1_exc[-2] ), + 8743 /* 0.2668f Q15*/, pt1_exc[-1] ), + 16355 /* 0.4991f Q15*/, pt1_exc[0] ), + 8743 /* 0.2668f Q15*/, pt1_exc[1] ), + 590 /* 0.0180f Q15*/, pt1_exc[2] ), + -459 /*-0.0140f Q15*/, pt1_exc[3] ), + -121 /*-0.0037f Q15*/, pt1_exc[4] ), + -174 /*-0.0053f Q15*/, pt1_exc[5] ); pt1_exc++; } } @@ -1426,7 +1421,7 @@ void con_tcx_ivas_fx( ELSE { /* copy the first pitch cycle without low-pass filtering */ - FOR( i=0 ; i < Tc; i++ ) + FOR( i = 0; i < Tc; i++ ) { *pt_exc++ = *pt1_exc++; move16(); @@ -1435,41 +1430,41 @@ void con_tcx_ivas_fx( move16(); } - if (fUseExtrapolatedPitch != 0) + if ( fUseExtrapolatedPitch != 0 ) { pt1_exc = buf; } - tmp16 = add(sub(L_frame,imult1616(fLowPassFilter,Tc)),L_subfr); - FOR (i = 0; i < tmp16; i++) + tmp16 = add( sub( L_frame, imult1616( fLowPassFilter, Tc ) ), L_subfr ); + FOR( i = 0; i < tmp16; i++ ) { *pt_exc++ = *pt1_exc++; move16(); } - IF (fUseExtrapolatedPitch != 0) + IF( fUseExtrapolatedPitch != 0 ) { - get_subframe_pitch(st->nb_subfr, - st->old_fpitch, - /* predPitchLag * L_frame/st->L_frame, */ - L_shr(Mpy_32_16_1(predPitchLag/*Q16*/, - mult_r(st->L_frame/*Q0*/, - getInvFrameLen(L_frame)/*Q21*/ - )/*Q6*/ - )/*Q7*/, - 7-16)/*Q16*/, - pitch_buf); + get_subframe_pitch( st->nb_subfr, + st->old_fpitch, + /* predPitchLag * L_frame/st->L_frame, */ + L_shr( Mpy_32_16_1( predPitchLag /*Q16*/, + mult_r( st->L_frame /*Q0*/, + getInvFrameLen( L_frame ) /*Q21*/ + ) /*Q6*/ + ) /*Q7*/, + 7 - 16 ) /*Q16*/, + pitch_buf ); - PulseResynchronization_fx(buf, exc, L_frame, st->nb_subfr, st->old_fpitchFB, predPitchLag); + PulseResynchronization_fx( buf, exc, L_frame, st->nb_subfr, st->old_fpitchFB, predPitchLag ); } ELSE { - set32_fx( pitch_buf, st->old_fpitch, st->nb_subfr); + set32_fx( pitch_buf, st->old_fpitch, st->nb_subfr ); } - IF ( EQ_16(st->nbLostCmpt , 1)) + IF( EQ_16( st->nbLostCmpt, 1 ) ) { - pt_exc = exc+L_frame; - IF (T0 == 0) + pt_exc = exc + L_frame; + IF( T0 == 0 ) { pt1_exc = pt_exc - Tc; } @@ -1478,15 +1473,15 @@ void con_tcx_ivas_fx( pt1_exc = pt_exc - T0; } - tmp_loop = shr(L_frame,1); - FOR (i = 0; i < tmp_loop; i++) + tmp_loop = shr( L_frame, 1 ); + FOR( i = 0; i < tmp_loop; i++ ) { *pt_exc++ = *pt1_exc++; move16(); } } - if (fUseExtrapolatedPitch != 0) + if ( fUseExtrapolatedPitch != 0 ) { st->old_fpitchFB = predPitchLag; move16(); @@ -1497,100 +1492,100 @@ void con_tcx_ivas_fx( /* PLC: calculate damping factor */ #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT alpha = 1.0f; - if (st->element_mode == IVAS_CPE_MDCT && st->nbLostCmpt >= MDCT_ST_PLC_FADEOUT_START_FRAME) + if ( st->element_mode == IVAS_CPE_MDCT && st->nbLostCmpt >= MDCT_ST_PLC_FADEOUT_START_FRAME ) { - alpha = Damping_fact_fx(st->core_ext_mode, st->nbLostCmpt - MDCT_ST_PLC_FADEOUT_START_FRAME, st->last_good, st->stab_fac, &(st->lp_gainp), 0); + alpha = Damping_fact_fx( st->core_ext_mode, st->nbLostCmpt - MDCT_ST_PLC_FADEOUT_START_FRAME, st->last_good, st->stab_fac, &( st->lp_gainp ), 0 ); } - else if (st->element_mode != IVAS_CPE_MDCT) + else if ( st->element_mode != IVAS_CPE_MDCT ) { - alpha = Damping_fact_fx(st->core_ext_mode, st->nbLostCmpt, st->last_good, st->stab_fac, &(st->lp_gainp), 0); + alpha = Damping_fact_fx( st->core_ext_mode, st->nbLostCmpt, st->last_good, st->stab_fac, &( st->lp_gainp ), 0 ); } #else - alpha = Damping_fact_fx(st->core_ext_mode, st->nbLostCmpt, st->last_good, st->stab_fac_fx, &(st->Mode2_lp_gainp), 0);/*Q14*/ + alpha = Damping_fact_fx( st->core_ext_mode, st->nbLostCmpt, st->last_good, st->stab_fac_fx, &( st->Mode2_lp_gainp ), 0 ); /*Q14*/ #endif - IF ( EQ_16(st->nbLostCmpt , 1)) + IF( EQ_16( st->nbLostCmpt, 1 ) ) { - st->cummulative_damping = 32767/*1.f Q15*/; + st->cummulative_damping = 32767 /*1.f Q15*/; move16(); } ELSE { #ifdef BASOP_NOGLOB - st->cummulative_damping = shl_sat(mult_r_sat(st->cummulative_damping/*Q15*/,alpha/*Q14*/),1)/*Q15*/; + st->cummulative_damping = shl_sat( mult_r_sat( st->cummulative_damping /*Q15*/, alpha /*Q14*/ ), 1 ) /*Q15*/; #else - st->cummulative_damping = shl(mult_r(st->cummulative_damping/*Q15*/,alpha/*Q14*/),1)/*Q15*/; + st->cummulative_damping = shl( mult_r( st->cummulative_damping /*Q15*/, alpha /*Q14*/ ), 1 ) /*Q15*/; #endif } - gain32 = L_add(2147483647l/*1.f Q31*/, 0); /*Q31*/ - gain = 32767/*1.f Q15*/; /*Q15*/ move16(); - if( EQ_16(st->rf_frame_type, RF_TCXTD1)&&EQ_16(st->use_partial_copy,1)) + gain32 = L_add( 2147483647l /*1.f Q31*/, 0 ); /*Q31*/ + gain = 32767 /*1.f Q15*/; /*Q15*/ + move16(); + if ( EQ_16( st->rf_frame_type, RF_TCXTD1 ) && EQ_16( st->use_partial_copy, 1 ) ) { - gain32 = 1073741824l/*0.5f Q31*/; - gain = 16384/*0.5f Q15*/; + gain32 = 1073741824l /*0.5f Q31*/; + gain = 16384 /*0.5f Q15*/; } /*step = (1.0f/(L_frame+(L_frame/2))) * (gain - alpha);*/ - tmp16 = shr(imult1616(3,L_frame),1); - tmp_e = norm_s(tmp16); - tmp16 = shl(tmp16,tmp_e); - tmp16 = div_s(16384/*1.f Q14*/,tmp16);/*Q15,1+tmp_e-15*/ - tmp16_2 = sub(shr(gain,1),alpha)/*Q14*/; - step32 = L_shl(L_mult(tmp16,tmp16_2)/*Q30, 1+tmp_e-15*/,add(1-14,tmp_e))/*Q31*/; + tmp16 = shr( imult1616( 3, L_frame ), 1 ); + tmp_e = norm_s( tmp16 ); + tmp16 = shl( tmp16, tmp_e ); + tmp16 = div_s( 16384 /*1.f Q14*/, tmp16 ); /*Q15,1+tmp_e-15*/ + tmp16_2 = sub( shr( gain, 1 ), alpha ) /*Q14*/; + step32 = L_shl( L_mult( tmp16, tmp16_2 ) /*Q30, 1+tmp_e-15*/, add( 1 - 14, tmp_e ) ) /*Q31*/; /* PLC: Apply fade out */ - tmp_loop = shr(imult1616(L_frame,3),1); - FOR ( i=offset; i < tmp_loop; i++ ) + tmp_loop = shr( imult1616( L_frame, 3 ), 1 ); + FOR( i = offset; i < tmp_loop; i++ ) { #ifdef BASOP_NOGLOB - exc[i] = mult_r(exc[i], round_fx_sat(gain32))/*Q1*/; + exc[i] = mult_r( exc[i], round_fx_sat( gain32 ) ) /*Q1*/; move16(); - gain32 = L_sub_sat(gain32, step32); + gain32 = L_sub_sat( gain32, step32 ); #else - exc[i] = mult_r(exc[i],round_fx(gain32))/*Q1*/; + exc[i] = mult_r( exc[i], round_fx( gain32 ) ) /*Q1*/; move16(); - gain32 = L_sub(gain32, step32); + gain32 = L_sub( gain32, step32 ); #endif - } /* update old exc without random part */ - offset = s_max(round_fx(st->old_fpitchFB) - shr(L_frame,1), 0); - Copy(exc+L_frame-offset, hTcxDec->old_excFB_fx, shr(L_frame,1)+offset); + offset = s_max( round_fx( st->old_fpitchFB ) - shr( L_frame, 1 ), 0 ); + Copy( exc + L_frame - offset, hTcxDec->old_excFB_fx, shr( L_frame, 1 ) + offset ); /* copy old_exc as 16kHz for acelp decoding */ - IF ( EQ_16(st->nbLostCmpt, 1)) + IF( EQ_16( st->nbLostCmpt, 1 ) ) { - lerp(exc - shr(L_frame,1), st->old_exc_fx, L_EXC_MEM_DEC, add(L_frame, shr(L_frame,1))); + lerp( exc - shr( L_frame, 1 ), st->old_exc_fx, L_EXC_MEM_DEC, add( L_frame, shr( L_frame, 1 ) ) ); } ELSE { - Copy(st->old_exc_fx+L_FRAME16k, st->old_exc_fx, L_FRAME16k/2); - lerp(exc, st->old_exc_fx+L_FRAME16k/2, L_FRAME16k, L_frame); + Copy( st->old_exc_fx + L_FRAME16k, st->old_exc_fx, L_FRAME16k / 2 ); + lerp( exc, st->old_exc_fx + L_FRAME16k / 2, L_FRAME16k, L_frame ); } st->Q_exc = Q_exc; } ELSE { /* No harmonic part */ - set16_fx(&exc[0], 0, add(L_frame,shr(L_frame,1))); - IF ( EQ_16(st->nbLostCmpt , 1)) + set16_fx( &exc[0], 0, add( L_frame, shr( L_frame, 1 ) ) ); + IF( EQ_16( st->nbLostCmpt, 1 ) ) { - calcGainc2_fx(&exc[0], Q_exc, L_subfr, &(st->Mode2_lp_gainc)); + calcGainc2_fx( &exc[0], Q_exc, L_subfr, &( st->Mode2_lp_gainc ) ); } - set32_fx( pitch_buf, L_deposit_h(L_SUBFR), st->nb_subfr); + set32_fx( pitch_buf, L_deposit_h( L_SUBFR ), st->nb_subfr ); /* PLC: calculate damping factor */ #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT alpha = 1.0f; - if (st->element_mode == IVAS_CPE_MDCT && st->nbLostCmpt >= MDCT_ST_PLC_FADEOUT_START_FRAME) + if ( st->element_mode == IVAS_CPE_MDCT && st->nbLostCmpt >= MDCT_ST_PLC_FADEOUT_START_FRAME ) { - alpha = Damping_fact_fx(st->core_ext_mode, st->nbLostCmpt - MDCT_ST_PLC_FADEOUT_START_FRAME, st->last_good, st->stab_fac, &(st->lp_gainp), 0); + alpha = Damping_fact_fx( st->core_ext_mode, st->nbLostCmpt - MDCT_ST_PLC_FADEOUT_START_FRAME, st->last_good, st->stab_fac, &( st->lp_gainp ), 0 ); } - else if (st->element_mode != IVAS_CPE_MDCT) + else if ( st->element_mode != IVAS_CPE_MDCT ) { - alpha = Damping_fact_fx(st->core_ext_mode, st->nbLostCmpt, st->last_good, st->stab_fac, &(st->lp_gainp), 0); + alpha = Damping_fact_fx( st->core_ext_mode, st->nbLostCmpt, st->last_good, st->stab_fac, &( st->lp_gainp ), 0 ); } #else - alpha = Damping_fact_fx(st->core_ext_mode, st->nbLostCmpt, st->last_good, st->stab_fac_fx, &(st->Mode2_lp_gainp), 0);/*Q14*/ + alpha = Damping_fact_fx( st->core_ext_mode, st->nbLostCmpt, st->last_good, st->stab_fac_fx, &( st->Mode2_lp_gainp ), 0 ); /*Q14*/ #endif } @@ -1598,7 +1593,7 @@ void con_tcx_ivas_fx( * Construct the random part of excitation *-----------------------------------------------------------------*/ #ifndef IVAS_CODE_CON_TCX - IF (coh != -16384) + IF( coh != -16384 ) { Word16 tmpSeed1; Word16 alpha_coh; @@ -1610,32 +1605,32 @@ void con_tcx_ivas_fx( Word16 e = 0; alpha_coh = 0; - IF(NE_16(coh, 16384)) + IF( NE_16( coh, 16384 ) ) { - alpha_coh = Sqrt16(div_s((16384 - coh), (16384 + coh)), &e); + alpha_coh = Sqrt16( div_s( ( 16384 - coh ), ( 16384 + coh ) ), &e ); } - IF (st->idchan == 1) + IF( st->idchan == 1 ) { - alpha_coh = negate(alpha_coh); + alpha_coh = negate( alpha_coh ); } - FOR (i = 0; i < L_frame + L_FIR_FER2 - 1; i++) + FOR( i = 0; i < L_frame + L_FIR_FER2 - 1; i++ ) { - random1 = own_random2_fx(tmpSeed1); - random2 = own_random2_fx(tmpSeed1); - noise[i] = add(shr(random1, noise_e), shr(mult(alpha_coh, random2), noise_e)); + random1 = own_random2_fx( tmpSeed1 ); + random2 = own_random2_fx( tmpSeed1 ); + noise[i] = add( shr( random1, noise_e ), shr( mult( alpha_coh, random2 ), noise_e ) ); } - IF (st->idchan == 1 || only_left) + IF( st->idchan == 1 || only_left ) { *noise_seed = tmpSeed1; } - FOR (; i < L_frame + (L_frame / 2) + 2 * L_FIR_FER2; i++) + FOR( ; i < L_frame + ( L_frame / 2 ) + 2 * L_FIR_FER2; i++ ) { - random1 = own_random2_fx(tmpSeed1); - random2 = own_random2_fx(tmpSeed1); - noise[i] = add(shr(random1, noise_e), shr(mult(alpha_coh, random2), noise_e)); + random1 = own_random2_fx( tmpSeed1 ); + random2 = own_random2_fx( tmpSeed1 ); + noise[i] = add( shr( random1, noise_e ), shr( mult( alpha_coh, random2 ), noise_e ) ); } } ELSE @@ -1644,45 +1639,46 @@ void con_tcx_ivas_fx( tmpSeed = st->seed_acelp; move16(); noise = buf; - noise_e = 1;/*set exponent of noise to 1*/ move16(); + noise_e = 1; /*set exponent of noise to 1*/ + move16(); - tmp_loop = add(L_frame, L_FIR_FER2 - 1); - FOR(i = 0; i < tmp_loop; i++) + tmp_loop = add( L_frame, L_FIR_FER2 - 1 ); + FOR( i = 0; i < tmp_loop; i++ ) { - tmpSeed = own_random2_fx(tmpSeed); - noise[i] = shr(tmpSeed, noise_e); + tmpSeed = own_random2_fx( tmpSeed ); + noise[i] = shr( tmpSeed, noise_e ); move16(); } st->seed_acelp = tmpSeed; move16(); - tmp_loop = add(add(L_frame, shr(L_frame, 1)), shl(L_FIR_FER2, 1)); - FOR(; i < tmp_loop; i++) + tmp_loop = add( add( L_frame, shr( L_frame, 1 ) ), shl( L_FIR_FER2, 1 ) ); + FOR( ; i < tmp_loop; i++ ) { - tmpSeed = own_random2_fx(tmpSeed); - noise[i] = shr(tmpSeed, noise_e); + tmpSeed = own_random2_fx( tmpSeed ); + noise[i] = shr( tmpSeed, noise_e ); move16(); } } test(); - IF (EQ_16(st->last_good , VOICED_CLAS)||EQ_16(st->last_good,ONSET)) + IF( EQ_16( st->last_good, VOICED_CLAS ) || EQ_16( st->last_good, ONSET ) ) { - tmp16 = 19661/*0.6f Q15*/; + tmp16 = 19661 /*0.6f Q15*/; move16(); - if ( LE_32(st->output_Fs,16000)) + if ( LE_32( st->output_Fs, 16000 ) ) { - tmp16 = 6554/*0.2f Q15*/; + tmp16 = 6554 /*0.2f Q15*/; move16(); } mem = noise[0]; move16(); - preemph_copy_fx(&noise[1], &noise[1], tmp16, L_frame+(L_frame/2)+L_FIR_FER2, &mem); + preemph_copy_fx( &noise[1], &noise[1], tmp16, L_frame + ( L_frame / 2 ) + L_FIR_FER2, &mem ); } /* high rate filter tuning */ - IF ( LE_32(st->output_Fs,16000)) + IF( LE_32( st->output_Fs, 16000 ) ) { - FOR( i=0; i< L_FIR_FER2; i++ ) + FOR( i = 0; i < L_FIR_FER2; i++ ) { hp_filt[i] = h_high3_16[i]; move16(); @@ -1690,32 +1686,33 @@ void con_tcx_ivas_fx( } ELSE /*(st->output_Fs==32000)*/ { - FOR( i=0; i< L_FIR_FER2; i++ ) + FOR( i = 0; i < L_FIR_FER2; i++ ) { hp_filt[i] = h_high3_32[i]; move16(); } } - IF ( EQ_16(st->nbLostCmpt,1)) + IF( EQ_16( st->nbLostCmpt, 1 ) ) { - highPassFiltering_fx(st->last_good, add(add(L_frame, shr(L_frame,1)),L_FIR_FER2), noise, hp_filt, L_FIR_FER2); + highPassFiltering_fx( st->last_good, add( add( L_frame, shr( L_frame, 1 ) ), L_FIR_FER2 ), noise, hp_filt, L_FIR_FER2 ); } ELSE { - IF(GT_16( st->last_good , UNVOICED_TRANSITION)) + IF( GT_16( st->last_good, UNVOICED_TRANSITION ) ) { - tmp_loop = add(add(L_frame,shr(L_frame,1)),L_FIR_FER2); - gain_tmp = negate(add(-32768,st->cummulative_damping));/*Q15*/ - FOR( i=0 ; i < tmp_loop; i++ ) + tmp_loop = add( add( L_frame, shr( L_frame, 1 ) ), L_FIR_FER2 ); + gain_tmp = negate( add( -32768, st->cummulative_damping ) ); /*Q15*/ + FOR( i = 0; i < tmp_loop; i++ ) { - Word16 j; - L_tmp2 = 0; move32(); - for (j=11; j>0; j--) - { - L_tmp2 = L_mac(L_tmp2, noise[i+L_FIR_FER2-j], hp_filt[L_FIR_FER2-j]); - } - L_tmp2 = Mpy_32_16_1(L_tmp2, st->cummulative_damping/*Q15*/);/*Q0, noise_e*/ - noise[i] = mac_r(L_tmp2, gain_tmp,noise[i]);/*Q15, noise_e*/ + Word16 j; + L_tmp2 = 0; + move32(); + for ( j = 11; j > 0; j-- ) + { + L_tmp2 = L_mac( L_tmp2, noise[i + L_FIR_FER2 - j], hp_filt[L_FIR_FER2 - j] ); + } + L_tmp2 = Mpy_32_16_1( L_tmp2, st->cummulative_damping /*Q15*/ ); /*Q0, noise_e*/ + noise[i] = mac_r( L_tmp2, gain_tmp, noise[i] ); /*Q15, noise_e*/ } } } @@ -1723,40 +1720,40 @@ void con_tcx_ivas_fx( /* PLC: [TCX: Fade-out] retrieve background level */ #ifndef IVAS_CODE_CNG_FIX185_PLC_FADEOUT tmp16 = 32767; - IF (A_cng != NULL) + IF( A_cng != NULL ) { - gainSynthDeemph = shr(getLevelSynDeemph_fx(&(tmp16), A_cng, M, shr(L_frame, 2), st->preemph_fac, 1, &gainSynthDeemph_e) , 2); + gainSynthDeemph = shr( getLevelSynDeemph_fx( &( tmp16 ), A_cng, M, shr( L_frame, 2 ), st->preemph_fac, 1, &gainSynthDeemph_e ), 2 ); } ELSE { - gainSynthDeemph = getLevelSynDeemph_fx(&(tmp16), A_local, M, shr(L_frame, 2), st->preemph_fac, 1, &gainSynthDeemph_e); + gainSynthDeemph = getLevelSynDeemph_fx( &( tmp16 ), A_local, M, shr( L_frame, 2 ), st->preemph_fac, 1, &gainSynthDeemph_e ); } #else tmp16 = 32767; move16(); - gainSynthDeemph = getLevelSynDeemph_fx(&(tmp16), A_local, M, shr(L_frame,2), st->preemph_fac, 1, &gainSynthDeemph_e); + gainSynthDeemph = getLevelSynDeemph_fx( &( tmp16 ), A_local, M, shr( L_frame, 2 ), st->preemph_fac, 1, &gainSynthDeemph_e ); #endif - IF (0 != st->tcxonly) + IF( 0 != st->tcxonly ) { /* gainCNG = st->conCngLevelBackgroundTrace/gainSynthDeemph; */ - BASOP_Util_Divide_MantExp(hTcxDec->conCngLevelBackgroundTrace, - hTcxDec->conCngLevelBackgroundTrace_e, - gainSynthDeemph, gainSynthDeemph_e, - &gainCNG, &gainCNG_e); + BASOP_Util_Divide_MantExp( hTcxDec->conCngLevelBackgroundTrace, + hTcxDec->conCngLevelBackgroundTrace_e, + gainSynthDeemph, gainSynthDeemph_e, + &gainCNG, &gainCNG_e ); #ifndef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - IF (st->element_mode == IVAS_CPE_MDCT && A_cng != NULL) + IF( st->element_mode == IVAS_CPE_MDCT && A_cng != NULL ) { - IF (GT_16(st->nbLostCmpt, add(MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME, MDCT_ST_PLC_FADEOUT_TO_ZERO_LEN))) + IF( GT_16( st->nbLostCmpt, add( MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME, MDCT_ST_PLC_FADEOUT_TO_ZERO_LEN ) ) ) { gainCNG = 0; } - ELSE IF (GT_16(st->nbLostCmpt, MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME)) + ELSE IF( GT_16( st->nbLostCmpt, MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME ) ) { - Word16 tmp, q_tmp; - tmp = BASOP_Util_Divide1616_Scale(sub(st->nbLostCmpt, MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME), MDCT_ST_PLC_FADEOUT_TO_ZERO_LEN, &q_tmp); - q_tmp = sub(15, q_tmp); - gainCNG = extract_l(L_shr(L_mult0(gainCNG, sub(shl(1, q_tmp), tmp)), q_tmp)); - //gainCNG *= 1.f - (float)(st->nbLostCmpt - MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME) / MDCT_ST_PLC_FADEOUT_TO_ZERO_LEN; + Word16 tmp, q_tmp; + tmp = BASOP_Util_Divide1616_Scale( sub( st->nbLostCmpt, MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME ), MDCT_ST_PLC_FADEOUT_TO_ZERO_LEN, &q_tmp ); + q_tmp = sub( 15, q_tmp ); + gainCNG = extract_l( L_shr( L_mult0( gainCNG, sub( shl( 1, q_tmp ), tmp ) ), q_tmp ) ); + // gainCNG *= 1.f - (float)(st->nbLostCmpt - MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME) / MDCT_ST_PLC_FADEOUT_TO_ZERO_LEN; } } #endif @@ -1764,137 +1761,142 @@ void con_tcx_ivas_fx( ELSE { /* gainCNG = st->cngTDLevel/gainSynthDeemph; */ - BASOP_Util_Divide_MantExp(st->cngTDLevel, - st->cngTDLevel_e, - gainSynthDeemph, gainSynthDeemph_e, - &gainCNG, &gainCNG_e); + BASOP_Util_Divide_MantExp( st->cngTDLevel, + st->cngTDLevel_e, + gainSynthDeemph, gainSynthDeemph_e, + &gainCNG, &gainCNG_e ); } - gain32 = L_add(st->Mode2_lp_gainc, 0); /* start-of-the-frame gain - Q16*/ - IF( EQ_16(st->rf_frame_type, RF_TCXTD1)&&EQ_16(st->use_partial_copy,1)) + gain32 = L_add( st->Mode2_lp_gainc, 0 ); /* start-of-the-frame gain - Q16*/ + IF( EQ_16( st->rf_frame_type, RF_TCXTD1 ) && EQ_16( st->use_partial_copy, 1 ) ) { - gain32 = Mpy_32_16_1(gain32, 22938/*0.7f Q15*/); + gain32 = Mpy_32_16_1( gain32, 22938 /*0.7f Q15*/ ); } - L_tmp = L_shl(gain32,1); + L_tmp = L_shl( gain32, 1 ); - IF (GT_32(L_shl(L_deposit_h(gainCNG),sub(gainCNG_e,31-16)/*Q16*/) , L_tmp)) + IF( GT_32( L_shl( L_deposit_h( gainCNG ), sub( gainCNG_e, 31 - 16 ) /*Q16*/ ), L_tmp ) ) { - gainCNG_e = sub(15+1,norm_l(L_tmp)); - gainCNG = extract_l(L_shr(L_tmp,gainCNG_e));/*Q15,gainCNG_e*/ - gainCNG_e = sub(gainCNG_e,1); + gainCNG_e = sub( 15 + 1, norm_l( L_tmp ) ); + gainCNG = extract_l( L_shr( L_tmp, gainCNG_e ) ); /*Q15,gainCNG_e*/ + gainCNG_e = sub( gainCNG_e, 1 ); } - /* st->Mode2_lp_gainc = alpha * (st->Mode2_lp_gainc) + (1.0f - alpha) * gainCNG;*/ /* end-of-the-frame gain */ + /* st->Mode2_lp_gainc = alpha * (st->Mode2_lp_gainc) + (1.0f - alpha) * gainCNG;*/ /* end-of-the-frame gain */ - L_tmp = Mpy_32_16_1(st->Mode2_lp_gainc,alpha)/*Q15*/; - L_tmp2 = L_mult(sub(16384/*1.f Q14*/,alpha)/*Q14*/,gainCNG/*Q15,gainCNG_e*/);/*Q30,gainCNG_e*/ - st->Mode2_lp_gainc = BASOP_Util_Add_Mant32Exp(L_tmp,31-15,L_tmp2,add(gainCNG_e,31-30),&tmp_e);/*Q31*/ move32(); - st->Mode2_lp_gainc = L_shl(st->Mode2_lp_gainc,sub(tmp_e,31-16)); + L_tmp = Mpy_32_16_1( st->Mode2_lp_gainc, alpha ) /*Q15*/; + L_tmp2 = L_mult( sub( 16384 /*1.f Q14*/, alpha ) /*Q14*/, gainCNG /*Q15,gainCNG_e*/ ); /*Q30,gainCNG_e*/ + st->Mode2_lp_gainc = BASOP_Util_Add_Mant32Exp( L_tmp, 31 - 15, L_tmp2, add( gainCNG_e, 31 - 30 ), &tmp_e ); /*Q31*/ + move32(); + st->Mode2_lp_gainc = L_shl( st->Mode2_lp_gainc, sub( tmp_e, 31 - 16 ) ); move32(); /* PLC: [TCX: Fade-out] Linearly attenuate the gain through the frame */ /*step = (1.0f/L_frame) * (gain - (st->Mode2_lp_gainc));*/ - L_tmp = L_sub(gain32,st->Mode2_lp_gainc);/*Q16*/ - tmp_e = norm_l(L_tmp); - L_tmp = L_shl(L_tmp,tmp_e);/*Q16,-tmp_e*/ - step32 = Mpy_32_16_1(L_tmp/*Q16,-tmp_e*/,getInvFrameLen(L_frame)/*W16Q21*/);/*Q22,-tmp_e*/ - step32 = L_shl(step32,sub((25-22),tmp_e));/*Q25*/ - - pt_exc = noise + L_FIR_FER2/2; - - /*gain_inov = 1.0f / (float)sqrt( dot_product( pt_exc, pt_exc, L_frame ) / L_frame + 0.01f );*//* normalize energy */ - L_tmp = Dot_productSq16HQ(0,pt_exc/*Q0,15+1*/,L_frame,&tmp_e)/*Q31,tmp_e+16+16*/; - L_tmp = Mpy_32_16_1(L_tmp,getInvFrameLen(L_frame)/*W16Q21*/)/*W32Q37,tmp_e+16+16*//*Q5,tmp_e*/; - tmp_e = add(tmp_e,31-5);/*-->Q31*/ + L_tmp = L_sub( gain32, st->Mode2_lp_gainc ); /*Q16*/ + tmp_e = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, tmp_e ); /*Q16,-tmp_e*/ + step32 = Mpy_32_16_1( L_tmp /*Q16,-tmp_e*/, getInvFrameLen( L_frame ) /*W16Q21*/ ); /*Q22,-tmp_e*/ + step32 = L_shl( step32, sub( ( 25 - 22 ), tmp_e ) ); /*Q25*/ + + pt_exc = noise + L_FIR_FER2 / 2; + + /*gain_inov = 1.0f / (float)sqrt( dot_product( pt_exc, pt_exc, L_frame ) / L_frame + 0.01f );*/ /* normalize energy */ + L_tmp = Dot_productSq16HQ( 0, pt_exc /*Q0,15+1*/, L_frame, &tmp_e ) /*Q31,tmp_e+16+16*/; + L_tmp = Mpy_32_16_1( L_tmp, getInvFrameLen( L_frame ) /*W16Q21*/ ) /*W32Q37,tmp_e+16+16*/ /*Q5,tmp_e*/; + tmp_e = add( tmp_e, 31 - 5 ); /*-->Q31*/ gain_inov = 0; gain_inov_e = 0; move16(); move16(); - IF(NE_32(L_tmp, 0)) + IF( NE_32( L_tmp, 0 ) ) { - gain_inov = round_fx(ISqrt32(L_tmp,&tmp_e));/*Q15,tmp_e*/ + gain_inov = round_fx( ISqrt32( L_tmp, &tmp_e ) ); /*Q15,tmp_e*/ gain_inov_e = tmp_e; move16(); } test(); test(); - IF (EQ_16(st->last_good , UNVOICED_CLAS)&&NE_16(st->core_ext_mode,UNVOICED)) + IF( EQ_16( st->last_good, UNVOICED_CLAS ) && NE_16( st->core_ext_mode, UNVOICED ) ) { - gain_inov = mult_r(gain_inov,26214/*0.8f Q15*/); + gain_inov = mult_r( gain_inov, 26214 /*0.8f Q15*/ ); } - ELSE IF (!( EQ_16(st->last_good , UNVOICED_CLAS)||EQ_16(st->last_good,UNVOICED_TRANSITION))) + ELSE IF( !( EQ_16( st->last_good, UNVOICED_CLAS ) || EQ_16( st->last_good, UNVOICED_TRANSITION ) ) ) { /*gain_inov *= (1.1f- 0.75*st->lp_gainp);*/ - L_tmp = Mpy_32_16_1(L_sub(590558016l/*1.1f Q29*/, Mpy_32_16_1(st->Mode2_lp_gainp,24576))/*Q29*/,gain_inov/*Q15,gain_inov_e*/);/*Q29,gain_inov_e*/ - tmp_e = norm_l(L_tmp); - L_tmp = L_shl(L_tmp,tmp_e); - gain_inov_e = add(sub(gain_inov_e,tmp_e),31-29);/*->Q31*/ - gain_inov = round_fx_sat(L_tmp);/*Q15,gain_inov_e*/ + L_tmp = Mpy_32_16_1( L_sub( 590558016l /*1.1f Q29*/, Mpy_32_16_1( st->Mode2_lp_gainp, 24576 ) ) /*Q29*/, gain_inov /*Q15,gain_inov_e*/ ); /*Q29,gain_inov_e*/ + tmp_e = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, tmp_e ); + gain_inov_e = add( sub( gain_inov_e, tmp_e ), 31 - 29 ); /*->Q31*/ + gain_inov = round_fx_sat( L_tmp ); /*Q15,gain_inov_e*/ } - st->Mode2_lp_gainp = L_shr(L_deposit_h(alpha/*Q14*/)/*Q14+16*/,1);/*Q29*/ - pt_exc = noise; /* non-causal ringing of the FIR filter */ + st->Mode2_lp_gainp = L_shr( L_deposit_h( alpha /*Q14*/ ) /*Q14+16*/, 1 ); /*Q29*/ + pt_exc = noise; /* non-causal ringing of the FIR filter */ - tmp_e = norm_l(gain32); - tmp_e = sub(tmp_e,5); /*5 Bit additional Headroom for the gain - should be enough*/ - gain32 = L_shl(gain32,tmp_e);/*Q16,-tmp_e*/ - L_tmp = Mpy_32_16_1(gain32/*Q16,-tmp_e*/, gain_inov/*Q15,gain_inov_e*/)/*Q16,gain_inov_e-tmp_e*/; + tmp_e = norm_l( gain32 ); + tmp_e = sub( tmp_e, 5 ); /*5 Bit additional Headroom for the gain - should be enough*/ + gain32 = L_shl( gain32, tmp_e ); /*Q16,-tmp_e*/ + L_tmp = Mpy_32_16_1( gain32 /*Q16,-tmp_e*/, gain_inov /*Q15,gain_inov_e*/ ) /*Q16,gain_inov_e-tmp_e*/; - gain_tmp = round_fx(L_tmp);/*Q0, gain_inov_e-tmp_e*/ + gain_tmp = round_fx( L_tmp ); /*Q0, gain_inov_e-tmp_e*/ - FOR( i=0 ; i< L_FIR_FER2/2; i++ ) + FOR( i = 0; i < L_FIR_FER2 / 2; i++ ) { - *pt_exc = mult_r(*pt_exc,gain_tmp);/*Q-15,noise_e+gain_inov_e-tmp_e*/ move16(); + *pt_exc = mult_r( *pt_exc, gain_tmp ); /*Q-15,noise_e+gain_inov_e-tmp_e*/ + move16(); pt_exc++; } - tmp16 = add(L_frame,L_FIR_FER2/2); - step32_tmp = L_shl(step32/*Q25*/,sub(tmp_e,(25-16)));/*Q16,-tmp_e*/ - FOR( i=0 ; i< tmp16; i++ ) /* Actual filtered random part of excitation */ + tmp16 = add( L_frame, L_FIR_FER2 / 2 ); + step32_tmp = L_shl( step32 /*Q25*/, sub( tmp_e, ( 25 - 16 ) ) ); /*Q16,-tmp_e*/ + FOR( i = 0; i < tmp16; i++ ) /* Actual filtered random part of excitation */ { - *pt_exc = mult_r(*pt_exc, gain_tmp); + *pt_exc = mult_r( *pt_exc, gain_tmp ); move16(); pt_exc++; - gain32 = L_sub(gain32/*Q16,-tmp_e*/,step32_tmp);/*Q16,-tmp_e*/ - gain_tmp = mult_r(round_fx(gain32/*Q16,-tmp_e*/)/*Q0*/, gain_inov/*Q15,gain_inov_e*/)/*Q0,gain_inov_e-tmp_e*/; + gain32 = L_sub( gain32 /*Q16,-tmp_e*/, step32_tmp ); /*Q16,-tmp_e*/ + gain_tmp = mult_r( round_fx( gain32 /*Q16,-tmp_e*/ ) /*Q0*/, gain_inov /*Q15,gain_inov_e*/ ) /*Q0,gain_inov_e-tmp_e*/; } - tmp16 = shr(L_frame,1); - FOR( i=0 ; i< tmp16; i++ ) /* causal ringing of the FIR filter */ + tmp16 = shr( L_frame, 1 ); + FOR( i = 0; i < tmp16; i++ ) /* causal ringing of the FIR filter */ { - *pt_exc = mult_r(*pt_exc , gain_tmp); + *pt_exc = mult_r( *pt_exc, gain_tmp ); move16(); pt_exc++; } - noise_e = add(sub(add(noise_e,gain_inov_e),tmp_e),15);/*--> noise is Q0, noise_e*/ + noise_e = add( sub( add( noise_e, gain_inov_e ), tmp_e ), 15 ); /*--> noise is Q0, noise_e*/ /*buf[0;L_FIR_FER2 + L_Frame + L_Frame/2] Q0, noise_e*/ /*-----------------------------------------------------------------* * Construct the total excitation *-----------------------------------------------------------------*/ - IF( GE_16(st->last_good , UNVOICED_TRANSITION)) + IF( GE_16( st->last_good, UNVOICED_TRANSITION ) ) { - tmp16 = add(L_frame,shr(L_frame,1)); - FOR( i=0 ; i< tmp16; i++ ) + tmp16 = add( L_frame, shr( L_frame, 1 ) ); + FOR( i = 0; i < tmp16; i++ ) { #ifdef BASOP_NOGLOB - exc[i] = add_sat(exc[i], shl_sat(noise[i + (L_FIR_FER2 / 2)], Q_exc + noise_e));/*Q1*/ move16(); + exc[i] = add_sat( exc[i], shl_sat( noise[i + ( L_FIR_FER2 / 2 )], Q_exc + noise_e ) ); /*Q1*/ + move16(); #else - exc[i] = add(exc[i] , shl(noise[i+(L_FIR_FER2/2)],Q_exc+noise_e));/*Q1*/ move16(); + exc[i] = add( exc[i], shl( noise[i + ( L_FIR_FER2 / 2 )], Q_exc + noise_e ) ); /*Q1*/ + move16(); #endif } } ELSE { - bufferCopyFx(noise+L_FIR_FER2/2, exc, add(L_frame , shr(L_frame,1)),0/*Q_noise*/, noise_e, Q_exc, 0/*exc_e*/); - Copy(exc+L_frame-2*L_subfr, hTcxDec->old_excFB_fx, 2*L_subfr+shr(L_frame,1)); + bufferCopyFx( noise + L_FIR_FER2 / 2, exc, add( L_frame, shr( L_frame, 1 ) ), 0 /*Q_noise*/, noise_e, Q_exc, 0 /*exc_e*/ ); + Copy( exc + L_frame - 2 * L_subfr, hTcxDec->old_excFB_fx, 2 * L_subfr + shr( L_frame, 1 ) ); /* copy old_exc as 16kHz for acelp decoding */ - IF ( EQ_16(st->nbLostCmpt, 1)) + IF( EQ_16( st->nbLostCmpt, 1 ) ) { - lerp(exc, st->old_exc_fx, L_EXC_MEM_DEC, add(L_frame, shr(L_frame,1))); + lerp( exc, st->old_exc_fx, L_EXC_MEM_DEC, add( L_frame, shr( L_frame, 1 ) ) ); } - ELSE { - Copy(st->old_exc_fx+L_FRAME16k, st->old_exc_fx, L_FRAME16k/2); - lerp(exc, st->old_exc_fx+L_FRAME16k/2, L_FRAME16k, L_frame); + ELSE + { + Copy( st->old_exc_fx + L_FRAME16k, st->old_exc_fx, L_FRAME16k / 2 ); + lerp( exc, st->old_exc_fx + L_FRAME16k / 2, L_FRAME16k, L_frame ); } st->Q_exc = Q_exc; } @@ -1910,101 +1912,101 @@ void con_tcx_ivas_fx( *----------------------------------------------------------*/ syn = buf + M; - Copy(synth-M, buf, M); + Copy( synth - M, buf, M ); - new_Q = sub(Q_exc, 3); - new_Q = s_max(new_Q, -1); + new_Q = sub( Q_exc, 3 ); + new_Q = s_max( new_Q, -1 ); - tmp16 = s_min(new_Q, st->prev_Q_syn); + tmp16 = s_min( new_Q, st->prev_Q_syn ); st->prev_Q_syn = new_Q; - move16(); + move16(); - exp_scale = sub(tmp16, Q_exc-1); + exp_scale = sub( tmp16, Q_exc - 1 ); Q_syn = tmp16; move16(); - Copy_Scale_sig(buf, mem_syn, M, exp_scale); + Copy_Scale_sig( buf, mem_syn, M, exp_scale ); #ifdef BASOP_NOGLOB - tmp_deemph = shl_sat(tmp_deemph,Q_syn); + tmp_deemph = shl_sat( tmp_deemph, Q_syn ); #else - tmp_deemph = shl(tmp_deemph,Q_syn); + tmp_deemph = shl( tmp_deemph, Q_syn ); #endif st->Q_syn = Q_syn; /*buf[OLD_EXC_SIZE_DEC;3/2 L_frame] Q1: exc*/ /*buf[0;M] Q0: mem_syn*/ #ifndef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - if (A_cng != NULL) + if ( A_cng != NULL ) { Word16 alpha_delayed; alpha_delayed = 16384; - IF (st->nbLostCmpt > MDCT_ST_PLC_FADEOUT_DELAY_4_LSP_FADE) + IF( st->nbLostCmpt > MDCT_ST_PLC_FADEOUT_DELAY_4_LSP_FADE ) { - alpha_delayed = Damping_fact_fx(st->core_ext_mode, st->nbLostCmpt - MDCT_ST_PLC_FADEOUT_DELAY_4_LSP_FADE, st->last_good, st->stab_fac_fx, &(st->Mode2_lp_gainp), ACELP_CORE); + alpha_delayed = Damping_fact_fx( st->core_ext_mode, st->nbLostCmpt - MDCT_ST_PLC_FADEOUT_DELAY_4_LSP_FADE, st->last_good, st->stab_fac_fx, &( st->Mode2_lp_gainp ), ACELP_CORE ); } - IF (st->plcBackgroundNoiseUpdated && alpha_delayed != 16384) + IF( st->plcBackgroundNoiseUpdated && alpha_delayed != 16384 ) { Word16 lsp_local[M], lsp_fade[M], alpha_inv; - alpha_inv = sub(16384, alpha_delayed); + alpha_inv = sub( 16384, alpha_delayed ); - E_LPC_a_lsp_conversion(A_local, lsp_local, lsp_local, M); + E_LPC_a_lsp_conversion( A_local, lsp_local, lsp_local, M ); - FOR (i = 0; i < M; i++) + FOR( i = 0; i < M; i++ ) { - lsp_fade[i] = add(mult_r(alpha_delayed, lsp_local[i]), mult_r(alpha_inv, st->lspold_cng[i])); + lsp_fade[i] = add( mult_r( alpha_delayed, lsp_local[i] ), mult_r( alpha_inv, st->lspold_cng[i] ) ); } - E_LPC_f_lsp_a_conversion(lsp_fade, A_local, M); + E_LPC_f_lsp_a_conversion( lsp_fade, A_local, M ); } } #endif E_UTIL_synthesis( - sub(Q_exc, Q_syn), + sub( Q_exc, Q_syn ), A_local, &exc[0], &syn[0], - add(L_frame, shr(L_frame,1)), + add( L_frame, shr( L_frame, 1 ) ), mem_syn, 1, - M); + M ); /*buf[OLD_EXC_SIZE_DEC;3/2 L_frame-1] Q1: exc*/ /*buf[0;M-1] Q0: mem_syn*/ /*buf[M;3/2 L_frame-1] Q-1: syn*/ - n = extract_h(L_mult(L_frame,9216/*(float)N_ZERO_MDCT_NS/(float)FRAME_SIZE_NS Q15*/)); + n = extract_h( L_mult( L_frame, 9216 /*(float)N_ZERO_MDCT_NS/(float)FRAME_SIZE_NS Q15*/ ) ); /* update ACELP synthesis memory */ - mem_syn_r_size_old = shr(L_frame,4); /* replace 1.25/20.0 by shr(4) */ + mem_syn_r_size_old = shr( L_frame, 4 ); /* replace 1.25/20.0 by shr(4) */ /* copy mem_syn as 16kHz */ - mem_syn_r_size_new = shr(L_FRAME16k,4); /* replace 1.25/20.0 by shr(4) */ + mem_syn_r_size_new = shr( L_FRAME16k, 4 ); /* replace 1.25/20.0 by shr(4) */ - Copy(syn+L_frame-L_SYN_MEM, st->mem_syn_r, L_SYN_MEM); - lerp(st->mem_syn_r+L_SYN_MEM-mem_syn_r_size_old, st->mem_syn_r+L_SYN_MEM-mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old); - Copy(st->mem_syn_r+L_SYN_MEM-M, st->mem_syn2_fx, M); + Copy( syn + L_frame - L_SYN_MEM, st->mem_syn_r, L_SYN_MEM ); + lerp( st->mem_syn_r + L_SYN_MEM - mem_syn_r_size_old, st->mem_syn_r + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); + Copy( st->mem_syn_r + L_SYN_MEM - M, st->mem_syn2_fx, M ); /* Deemphasis and output synth and ZIR */ - deemph_fx(syn, st->preemph_fac, add(L_frame,shr(L_frame,1)), &tmp_deemph); - bufferCopyFx(syn+L_frame-M-1, st->syn, 1+M, Q_syn, 0, 0, 0); + deemph_fx( syn, st->preemph_fac, add( L_frame, shr( L_frame, 1 ) ), &tmp_deemph ); + bufferCopyFx( syn + L_frame - M - 1, st->syn, 1 + M, Q_syn, 0, 0, 0 ); - lerp( syn+L_frame-shr(L_frame, 1), hTcxDec->old_syn_Overl, shr(st->L_frame, 1), shr(L_frame, 1) ); - Copy(syn+L_frame-n, hHQ_core->old_out_fx, sub(L_frame,n)); + lerp( syn + L_frame - shr( L_frame, 1 ), hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), shr( L_frame, 1 ) ); + Copy( syn + L_frame - n, hHQ_core->old_out_fx, sub( L_frame, n ) ); - FOR (i=0; i < W12; i++) + FOR( i = 0; i < W12; i++ ) { - hHQ_core->old_out_fx[i+n] = round_fx(Mpy_32_16_1(L_mult(w[i].v.re,w[i].v.re), hHQ_core->old_out_fx[i+n])); + hHQ_core->old_out_fx[i + n] = round_fx( Mpy_32_16_1( L_mult( w[i].v.re, w[i].v.re ), hHQ_core->old_out_fx[i + n] ) ); } - FOR ( ; i < W1; i++) + FOR( ; i < W1; i++ ) { - hHQ_core->old_out_fx[i+n] = round_fx(Mpy_32_16_1(L_mult(w[W12-1-(i-W12)].v.im,w[W12-1-(i-W12)].v.im), hHQ_core->old_out_fx[i+n])); + hHQ_core->old_out_fx[i + n] = round_fx( Mpy_32_16_1( L_mult( w[W12 - 1 - ( i - W12 )].v.im, w[W12 - 1 - ( i - W12 )].v.im ), hHQ_core->old_out_fx[i + n] ) ); } - set16_fx(&hHQ_core->old_out_fx[W1+n], 0, n); + set16_fx( &hHQ_core->old_out_fx[W1 + n], 0, n ); hHQ_core->Q_old_wtda = Q_syn; move16(); @@ -2012,62 +2014,62 @@ void con_tcx_ivas_fx( /* As long as there is no synth scaling factor introduced, which is given to the outside, there might occur overflows here */ BASOP_SATURATE_WARNING_OFF_EVS - bufferCopyFx(syn, synth, L_frame, Q_syn, 0, 0, 0); + bufferCopyFx( syn, synth, L_frame, Q_syn, 0, 0, 0 ); BASOP_SATURATE_WARNING_ON_EVS - Copy_Scale_sig(syn+L_frame, hTcxDec->syn_OverlFB, shr(L_frame,1), negate(Q_syn)); + Copy_Scale_sig( syn + L_frame, hTcxDec->syn_OverlFB, shr( L_frame, 1 ), negate( Q_syn ) ); /* copy total excitation exc2 as 16kHz for acelp mode1 decoding */ - IF(st->hWIDec != NULL) + IF( st->hWIDec != NULL ) { - lerp(exc, st->hWIDec->old_exc2_fx, L_EXC_MEM, L_frame); - lerp(syn, st->hWIDec->old_syn2_fx, L_EXC_MEM, L_frame); + lerp( exc, st->hWIDec->old_exc2_fx, L_EXC_MEM, L_frame ); + lerp( syn, st->hWIDec->old_syn2_fx, L_EXC_MEM, L_frame ); } #ifdef BASOP_NOGLOB - st->bfi_pitch_fx/*Q6*/ = round_fx_sat(L_shl_sat(pitch_buf[st->nb_subfr-1]/*15Q16*/,6/*Q6*/)); + st->bfi_pitch_fx /*Q6*/ = round_fx_sat( L_shl_sat( pitch_buf[st->nb_subfr - 1] /*15Q16*/, 6 /*Q6*/ ) ); #else - st->bfi_pitch_fx/*Q6*/ = round_fx(L_shl(pitch_buf[st->nb_subfr-1]/*15Q16*/,6/*Q6*/)); + st->bfi_pitch_fx /*Q6*/ = round_fx( L_shl( pitch_buf[st->nb_subfr - 1] /*15Q16*/, 6 /*Q6*/ ) ); #endif move16(); st->bfi_pitch_frame = st->L_frame; move16(); /* create aliasing and windowing need for transition to TCX10/5 */ - bufferCopyFx(syn+L_frame, hTcxDec->syn_Overl_TDACFB, shr(L_frame,1),Q_syn,0,-1,0); + bufferCopyFx( syn + L_frame, hTcxDec->syn_Overl_TDACFB, shr( L_frame, 1 ), Q_syn, 0, -1, 0 ); - FOR (i=0 ; i < W12 ; i++) + FOR( i = 0; i < W12; i++ ) { - buf[i] = mult_r(hTcxDec->syn_Overl_TDACFB[i] , w[i].v.re); + buf[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[i].v.re ); move16(); } - FOR ( ; i syn_Overl_TDACFB[i],w[W12-1-(i-W12)].v.im); + buf[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[W12 - 1 - ( i - W12 )].v.im ); move16(); } - FOR (i=0; isyn_Overl_TDACFB[i] = add_sat(buf[i] , buf[W1-1-i]); + hTcxDec->syn_Overl_TDACFB[i] = add_sat( buf[i], buf[W1 - 1 - i] ); move16(); } - FOR (i=0; isyn_Overl_TDACFB[W2+i] = add_sat(buf[W2+i] , buf[W1-1-W2-i]); + hTcxDec->syn_Overl_TDACFB[W2 + i] = add_sat( buf[W2 + i], buf[W1 - 1 - W2 - i] ); move16(); } - FOR (i=0 ; i < W12 ; i++) + FOR( i = 0; i < W12; i++ ) { - hTcxDec->syn_Overl_TDACFB[i] = mult_r(hTcxDec->syn_Overl_TDACFB[i],w[i].v.re); + hTcxDec->syn_Overl_TDACFB[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[i].v.re ); move16(); } - FOR ( ; i syn_Overl_TDACFB[i] = mult_r(hTcxDec->syn_Overl_TDACFB[i],w[W12-1-(i-W12)].v.im); + hTcxDec->syn_Overl_TDACFB[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[W12 - 1 - ( i - W12 )].v.im ); move16(); } @@ -2077,12 +2079,12 @@ void con_tcx_ivas_fx( move16(); /* update memory for low band */ - Scale_sig(hTcxDec->old_syn_Overl, shr(st->L_frame, 1), sub(-1, Q_syn)); - lerp(hTcxDec->syn_OverlFB, hTcxDec->syn_Overl, shr(st->L_frame, 1), shr(L_frame, 1) ); - lerp(hTcxDec->syn_Overl_TDACFB, hTcxDec->syn_Overl_TDAC, shr(st->L_frame, 1), shr(L_frame, 1) ); + Scale_sig( hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), sub( -1, Q_syn ) ); + lerp( hTcxDec->syn_OverlFB, hTcxDec->syn_Overl, shr( st->L_frame, 1 ), shr( L_frame, 1 ) ); + lerp( hTcxDec->syn_Overl_TDACFB, hTcxDec->syn_Overl_TDAC, shr( st->L_frame, 1 ), shr( L_frame, 1 ) ); lerp( st->hHQ_core->old_out_fx, st->hHQ_core->old_out_LB_fx, st->L_frame, L_frame ); - st->old_enr_LP = Enr_1_Az_fx(A_local, L_SUBFR); /*Q3*/ + st->old_enr_LP = Enr_1_Az_fx( A_local, L_SUBFR ); /*Q3*/ return; } diff --git a/lib_dec/er_scale_syn.c b/lib_dec/er_scale_syn.c index 06947c5a4..44a379b2e 100644 --- a/lib_dec/er_scale_syn.c +++ b/lib_dec/er_scale_syn.c @@ -138,4 +138,4 @@ float Damping_fact_flt( return alpha; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/er_scale_syn_fx.c b/lib_dec/er_scale_syn_fx.c index 847798483..d9d80c6ed 100644 --- a/lib_dec/er_scale_syn_fx.c +++ b/lib_dec/er_scale_syn_fx.c @@ -13,23 +13,25 @@ #ifdef IVAS_FLOAT_FIXED /*----------------------------------------------------------------------------------* -* Damping_fact_fx() -* -* Estimate damping factor -*----------------------------------------------------------------------------------*/ + * Damping_fact_fx() + * + * Estimate damping factor + *----------------------------------------------------------------------------------*/ /*This BASOP version was ported based on trunk rev. 27621 and updated based on trunk rev. 29287, re-updated based on trunk rev. 32244 */ -Word16 Damping_fact_fx( /* o : damping factor *//*Q14*/ - const Word16 coder_type, /* i : coding type in last good received frame */ - const Word16 nbLostCmpt, /* i : counter of consecutive bfi frames */ - const Word16 last_good, /* i : last good frame class */ - const Word16 stab_fac, /* i : ISF stability factor *//*Q15*/ - Word32 *lp_gainp, /*i/o: damped pitch gain *//*2Q29 Word32!*/ - const Word16 core /* i : current coding mode */ +Word16 Damping_fact_fx( /* o : damping factor */ /*Q14*/ + const Word16 coder_type, /* i : coding type in last good received frame */ + const Word16 nbLostCmpt, /* i : counter of consecutive bfi frames */ + const Word16 last_good, /* i : last good frame class */ + const Word16 stab_fac, + /* i : ISF stability factor */ /*Q15*/ + Word32 *lp_gainp, + /*i/o: damped pitch gain */ /*2Q29 Word32!*/ + const Word16 core /* i : current coding mode */ ) { Word16 alpha; /*Q14*/ - Word16 gain; /*Q14*/ + Word16 gain; /*Q14*/ Word32 lp_tmp; Word16 s_gainp; Word32 gain32; @@ -38,83 +40,83 @@ Word16 Damping_fact_fx( /* o : damping factor #endif - IF (core == ACELP_CORE) + IF( core == ACELP_CORE ) { - alpha = mult_r(_ALPHA_VT_FX,16384); /* rapid convergence to 0 *//*Q14*/ + alpha = mult_r( _ALPHA_VT_FX, 16384 ); /* rapid convergence to 0 */ /*Q14*/ test(); test(); - test();/*ELSEIF*/ + test(); /*ELSEIF*/ test(); - test();/*ELSEIF*/ - IF( ( EQ_16(coder_type, UNVOICED))&&(LE_16(nbLostCmpt,3))) /* Clear unvoiced last good frame */ + test(); /*ELSEIF*/ + IF( ( EQ_16( coder_type, UNVOICED ) ) && ( LE_16( nbLostCmpt, 3 ) ) ) /* Clear unvoiced last good frame */ { - alpha = mult_r(_ALPHA_UU_FX,16384); /*Q14*/ + alpha = mult_r( _ALPHA_UU_FX, 16384 ); /*Q14*/ } - ELSE IF( EQ_16(last_good, UNVOICED_CLAS)) + ELSE IF( EQ_16( last_good, UNVOICED_CLAS ) ) { - IF( EQ_16(nbLostCmpt,1)) + IF( EQ_16( nbLostCmpt, 1 ) ) { /* If stable, do not decrease the energy, pitch gain = 0 */ /* * (1.0f - 2.0f*_ALPHA_U_FX) + 2.0f*MODE2_ALPHA_U; */ /* [0.8, 1.0] */ - alpha = add(mult_r(stab_fac,sub(16384,_ALPHA_U_FX)),_ALPHA_U_FX); + alpha = add( mult_r( stab_fac, sub( 16384, _ALPHA_U_FX ) ), _ALPHA_U_FX ); } - ELSE IF (EQ_16(nbLostCmpt, 2)) + ELSE IF( EQ_16( nbLostCmpt, 2 ) ) { - /*alpha = _ALPHA_U_FX * 1.5f;*/ /* 0.6 */ - alpha = mult_r(_ALPHA_U_FX, 24576/*1.5f Q14*/); /*Q14*/ + /*alpha = _ALPHA_U_FX * 1.5f;*/ /* 0.6 */ + alpha = mult_r( _ALPHA_U_FX, 24576 /*1.5f Q14*/ ); /*Q14*/ } ELSE { - alpha = mult_r(_ALPHA_U_FX,16384); /*Q14*/ /* 0.4 go rapidly to CNG gain, pitch gain = 0 */ + alpha = mult_r( _ALPHA_U_FX, 16384 ); /*Q14*/ /* 0.4 go rapidly to CNG gain, pitch gain = 0 */ } } - ELSE IF( EQ_16(last_good, UNVOICED_TRANSITION)) + ELSE IF( EQ_16( last_good, UNVOICED_TRANSITION ) ) { - alpha = mult_r(_ALPHA_UT_FX,16384); /*Q14*/ + alpha = mult_r( _ALPHA_UT_FX, 16384 ); /*Q14*/ } - ELSE IF( (EQ_16(last_good, ONSET))&&(LE_16(nbLostCmpt,3))&&(EQ_16(coder_type,GENERIC))) + ELSE IF( ( EQ_16( last_good, ONSET ) ) && ( LE_16( nbLostCmpt, 3 ) ) && ( EQ_16( coder_type, GENERIC ) ) ) { - alpha = 13107/*0.8f Q14*/; /*Q14*/ + alpha = 13107 /*0.8f Q14*/; /*Q14*/ } - ELSE if( ( (EQ_16(last_good, VOICED_CLAS))||(EQ_16(last_good,ONSET)))&&(LE_16(nbLostCmpt,3))) + ELSE if ( ( ( EQ_16( last_good, VOICED_CLAS ) ) || ( EQ_16( last_good, ONSET ) ) ) && ( LE_16( nbLostCmpt, 3 ) ) ) { - alpha = mult_r(_ALPHA_V_FX,16384); /* constant for the first 3 erased frames */ + alpha = mult_r( _ALPHA_V_FX, 16384 ); /* constant for the first 3 erased frames */ } - IF (GE_16(last_good, VOICED_CLAS)) + IF( GE_16( last_good, VOICED_CLAS ) ) { move16(); lp_tmp = *lp_gainp; - IF( EQ_16(nbLostCmpt, 1)) /* if first erased frame in a block, reset harmonic gain */ + IF( EQ_16( nbLostCmpt, 1 ) ) /* if first erased frame in a block, reset harmonic gain */ { /*lp_gainp_E = 1;*/ /*For sqrt, because *lp_gain is Q14 */ - /*gain = (float)sqrt( *lp_gainp );*/ /* move pitch gain towards 1 for voiced to remove energy fluctuations */ + /*gain = (float)sqrt( *lp_gainp );*/ /* move pitch gain towards 1 for voiced to remove energy fluctuations */ /*BASOP_Util_Sqrt_MantExp(lp_gainp,&lp_gainp_E);*/ - s_gainp = 31-29; + s_gainp = 31 - 29; move16(); - gain32 = Sqrt32(lp_tmp, &s_gainp); + gain32 = Sqrt32( lp_tmp, &s_gainp ); #ifdef BASOP_NOGLOB - gain = round_fx_o(L_shl_o(gain32, s_gainp, &Overflow), &Overflow); /* Q15*/ + gain = round_fx_o( L_shl_o( gain32, s_gainp, &Overflow ), &Overflow ); /* Q15*/ #else - gain = round_fx(L_shl(gain32,s_gainp)); /* Q15*/ + gain = round_fx( L_shl( gain32, s_gainp ) ); /* Q15*/ #endif - gain = s_min(gain, 32113/*0.98f Q15*/); /*Q15*/ - gain = s_max(gain, 27853/*0.85f Q15*/); /*Q15*/ - alpha = mult_r(alpha , gain); /*Q14*/ + gain = s_min( gain, 32113 /*0.98f Q15*/ ); /*Q15*/ + gain = s_max( gain, 27853 /*0.85f Q15*/ ); /*Q15*/ + alpha = mult_r( alpha, gain ); /*Q14*/ } - ELSE IF ( EQ_16(nbLostCmpt, 2)) + ELSE IF( EQ_16( nbLostCmpt, 2 ) ) { /*0.6 + 0.35*stab_fac*/ - alpha = mult_r(mac_r(1288490240l/*0.6f Q31*/, 11469/*0.35f Q15*/, stab_fac), round_fx(L_shl(lp_tmp,1))); + alpha = mult_r( mac_r( 1288490240l /*0.6f Q31*/, 11469 /*0.35f Q15*/, stab_fac ), round_fx( L_shl( lp_tmp, 1 ) ) ); } ELSE { - /*0.7 + 0.2*stab_fac*/ move16(); - lp_tmp = Mpy_32_16_1(lp_tmp, mac_r(1503238528l/*0.7f Q31*/, 6554/*0.2f Q15*/, stab_fac)); /*2Q29*/ - alpha = round_fx(L_shl(lp_tmp,1)); /*1Q14*/ + /*0.7 + 0.2*stab_fac*/ move16(); + lp_tmp = Mpy_32_16_1( lp_tmp, mac_r( 1503238528l /*0.7f Q31*/, 6554 /*0.2f Q15*/, stab_fac ) ); /*2Q29*/ + alpha = round_fx( L_shl( lp_tmp, 1 ) ); /*1Q14*/ } move16(); *lp_gainp = lp_tmp; /*store*/ @@ -122,17 +124,16 @@ Word16 Damping_fact_fx( /* o : damping factor } ELSE { - alpha = mac_r(375809632l/*0.35f Q30*/,6554/*0.4f Q14*/,stab_fac); /*Q14*/ - if (LT_16(nbLostCmpt,2)) + alpha = mac_r( 375809632l /*0.35f Q30*/, 6554 /*0.4f Q14*/, stab_fac ); /*Q14*/ + if ( LT_16( nbLostCmpt, 2 ) ) { - alpha = mac_r(751619264l/*0.70f Q30*/,4915/*0.3f Q14*/,stab_fac); /*Q14*/ + alpha = mac_r( 751619264l /*0.70f Q30*/, 4915 /*0.3f Q14*/, stab_fac ); /*Q14*/ } - if (EQ_16(nbLostCmpt, 2)) + if ( EQ_16( nbLostCmpt, 2 ) ) { - alpha = mac_r(483183808l/*0.45f Q30*/,6554/*0.4f Q14*/,stab_fac); /*Q14*/ + alpha = mac_r( 483183808l /*0.45f Q30*/, 6554 /*0.4f Q14*/, stab_fac ); /*Q14*/ } - } return alpha; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/er_sync_exc.c b/lib_dec/er_sync_exc.c index f419be764..ea14a7f4b 100644 --- a/lib_dec/er_sync_exc.c +++ b/lib_dec/er_sync_exc.c @@ -334,4 +334,4 @@ void PulseResynchronization( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/er_sync_exc_fx.c b/lib_dec/er_sync_exc_fx.c index c6898cd23..44c6230d2 100644 --- a/lib_dec/er_sync_exc_fx.c +++ b/lib_dec/er_sync_exc_fx.c @@ -14,113 +14,111 @@ #include "basop_util.h" #ifdef IVAS_FLOAT_FIXED /*------------------------------------------------------------------------- -* -* Perform resynchronisation of the last glottal pulse in voiced lost frame -* -*------------------------------------------------------------------------*/ + * + * Perform resynchronisation of the last glottal pulse in voiced lost frame + * + *------------------------------------------------------------------------*/ /** Get the location of the minimum energy in the given signal. - * @returns Index of the position of the minimum energy, that is the position i where filter(x[i-filterLength/2],...,x[i+(filterLength-filterLength/2)-1]) is at maximum. - */ + * @returns Index of the position of the minimum energy, that is the position i where filter(x[i-filterLength/2],...,x[i+(filterLength-filterLength/2)-1]) is at maximum. + */ static Word16 GetMinimumPosition_fx( - Word16 const * x, /* Input signal. Qx*/ + Word16 const *x, /* Input signal. Qx*/ Word16 length, /* The length of the input signal. Q0*/ Word16 filterLength /* the length of the filter length used for the energy calculation. Q0*/ ) { Word16 iMinEnergyPos, center, i; - Word16 cnt, tmp_e, tmp16; + Word16 cnt, tmp_e, tmp16; Word32 energy, energy_old, tmptest; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - filterLength = s_min(filterLength, length); - center = shr(filterLength,1); + filterLength = s_min( filterLength, length ); + center = shr( filterLength, 1 ); iMinEnergyPos = center; move16(); - IF (filterLength > 0) + IF( filterLength > 0 ) { - center = add(center,1); - energy = L_deposit_l(0); - energy_old = L_deposit_l(0); + center = add( center, 1 ); + energy = L_deposit_l( 0 ); + energy_old = L_deposit_l( 0 ); - cnt = sub(length,filterLength); + cnt = sub( length, filterLength ); tmp_e = 0; move16(); - FOR (i = 0; i < cnt; i++) + FOR( i = 0; i < cnt; i++ ) { - tmp16 = shr(x[i],tmp_e); + tmp16 = shr( x[i], tmp_e ); #ifdef BASOP_NOGLOB energy = L_msu_sat( energy_old, tmp16, tmp16 ); #else - energy = L_msu(energy_old,tmp16,tmp16); + energy = L_msu( energy_old, tmp16, tmp16 ); #endif - tmp16 = shr(x[i+filterLength],tmp_e); + tmp16 = shr( x[i + filterLength], tmp_e ); BASOP_SATURATE_WARNING_OFF_EVS /*Saturation will be handled*/ #ifdef BASOP_NOGLOB - energy = L_mac_sat( energy, tmp16, tmp16 ); + energy = L_mac_sat( energy, tmp16, tmp16 ); #else - energy = L_mac(energy,tmp16,tmp16); + energy = L_mac( energy, tmp16, tmp16 ); #endif BASOP_SATURATE_WARNING_ON_EVS /*if (energy == MAXVAL_WORD32)*/ BASOP_SATURATE_WARNING_OFF_EVS /*saturates if energy < 0*/ #ifdef BASOP_NOGLOB - tmptest = L_sub_o(energy,MAXVAL_WORD32, &Overflow); + tmptest = L_sub_o( energy, MAXVAL_WORD32, &Overflow ); #else - tmptest = L_sub(energy,MAXVAL_WORD32); + tmptest = L_sub( energy, MAXVAL_WORD32 ); #endif BASOP_SATURATE_WARNING_ON_EVS - IF (tmptest == 0) + IF( tmptest == 0 ) { - tmp_e = add(tmp_e,1); - energy = L_shr(energy_old,2); - tmp16 = shr(x[i],tmp_e); - energy = L_msu(energy,tmp16,tmp16); - tmp16 = shr(x[i+filterLength],tmp_e); - energy = L_mac(energy,tmp16,tmp16); + tmp_e = add( tmp_e, 1 ); + energy = L_shr( energy_old, 2 ); + tmp16 = shr( x[i], tmp_e ); + energy = L_msu( energy, tmp16, tmp16 ); + tmp16 = shr( x[i + filterLength], tmp_e ); + energy = L_mac( energy, tmp16, tmp16 ); } - IF (energy < 0) + IF( energy < 0 ) { - iMinEnergyPos = add(i,center); + iMinEnergyPos = add( i, center ); tmp_e = 0; move16(); energy = 0; move16(); } - energy_old = L_add(energy, 0); + energy_old = L_add( energy, 0 ); } - } return iMinEnergyPos; } /*! - * \brief FindMaxPeak - Get the location of the maximum peak in the given signal. - * - * \returns Index of the position of the maximum peak, that is the position i where abs(x[i]) has it's maximum. - */ - -static Word16 FindMaxPeak_fx -( - Word16 /*float*/ const * x, /* 0; j--) + FOR( j = min_pos[i] - last_min_pos; j > 0; j-- ) { *pt_dest++ = *pt_src++; move16(); } /* Add some samples */ - ftmp = negate(mult(*pt_src,1638/*.05f Q15*/)); + ftmp = negate( mult( *pt_src, 1638 /*.05f Q15*/ ) ); - FOR (j = 0; j < points_by_pos[i]; j++) + FOR( j = 0; j < points_by_pos[i]; j++ ) { *pt_dest++ = ftmp; move16(); - ftmp = negate(ftmp); + ftmp = negate( ftmp ); } /* Prepare for the next loop iteration */ last_min_pos = min_pos[i]; move16(); } /* Copy remaining length */ - FOR (j = sub(L_frame , add(n_samples_to_add , last_min_pos)); j > 0; j--) + FOR( j = sub( L_frame, add( n_samples_to_add, last_min_pos ) ); j > 0; j-- ) { *pt_dest++ = *pt_src++; move16(); } - } static void RemoveSamples_fx( - Word16 /*float*/const * const old_exc, /*i : Qx */ - Word16 /*float*/ * const new_exc, /*o : Qx */ - Word16 /*int*/ const L_frame, /*i : Q0 */ - Word16 /*int*/ const n_samples_to_add, /*i : Q0 */ - Word16 /*int*/ const min_pos[], /*i : Q0 */ - Word16 /*int*/ const points_by_pos[], /*i : Q0 */ - Word16 /*int*/ const nb_min /*i : Q0*/ + Word16 /*float*/ const *const old_exc, /*i : Qx */ + Word16 /*float*/ *const new_exc, /*o : Qx */ + Word16 /*int*/ const L_frame, /*i : Q0 */ + Word16 /*int*/ const n_samples_to_add, /*i : Q0 */ + Word16 /*int*/ const min_pos[], /*i : Q0 */ + Word16 /*int*/ const points_by_pos[], /*i : Q0 */ + Word16 /*int*/ const nb_min /*i : Q0*/ ) { - Word16 /*float*/ * pt_dest; - Word16 /*float*/ const * pt_src; + Word16 /*float*/ *pt_dest; + Word16 /*float*/ const *pt_src; Word16 /*int*/ last_min_pos, i, j; + pt_dest = new_exc + L_frame; + last_min_pos = sub( L_frame, n_samples_to_add ); - pt_dest = new_exc+L_frame; - last_min_pos = sub(L_frame,n_samples_to_add); - - FOR(i = sub(nb_min,1); i >= 0; i--) + FOR( i = sub( nb_min, 1 ); i >= 0; i-- ) { /* Compute len to copy */ /* Copy section, removing some samples */ - pt_src = old_exc+last_min_pos; + pt_src = old_exc + last_min_pos; - FOR (j = sub(last_min_pos , add(min_pos[i],points_by_pos[i])); j > 0; j--) + FOR( j = sub( last_min_pos, add( min_pos[i], points_by_pos[i] ) ); j > 0; j-- ) { *--pt_dest = *--pt_src; move16(); @@ -217,183 +213,177 @@ static void RemoveSamples_fx( move16(); } /* Copy remaining length */ - pt_src = old_exc+last_min_pos; + pt_src = old_exc + last_min_pos; - FOR (j = last_min_pos; j > 0; j--) + FOR( j = last_min_pos; j > 0; j-- ) { *--pt_dest = *--pt_src; move16(); } - } /** Resynchronize glotal pulse positions of the signal in src_exc and store it in dst_exc. - * src_exc holds on call the harmonic part of the signal with the constant pitch, constructed by repeating the last pitch cycle of length pitchStart. - * dst_exc holds on return the harmonic part of the signal with the pitch changing from pitchStart to pitchEnd. - * src_exc and dst_exc can overlap, but src_exc < dst_exc must be fullfiled. - */ + * src_exc holds on call the harmonic part of the signal with the constant pitch, constructed by repeating the last pitch cycle of length pitchStart. + * dst_exc holds on return the harmonic part of the signal with the pitch changing from pitchStart to pitchEnd. + * src_exc and dst_exc can overlap, but src_exc < dst_exc must be fullfiled. + */ /*This BASOP port is up to date with trunk rev 8779(svnext2)*/ void PulseResynchronization_fx( - Word16 /*float*/ const * const src_exc, /*= 0)) + IF( ( LT_32( L_deposit_h( nFrameLength ), pitchStart ) ) || ( pitchStart <= 0 ) || ( pitchEnd <= 0 ) || ( LT_16( nSubframes, 1 ) ) || ( GT_16( nSubframes, 5 ) ) || ( LE_32( Mpy_32_16_1( pitchEnd, add( nSubframes, 1 ) ), Mpy_32_16_1( pitchStart, sub( nSubframes, 1 ) ) ) ) || ( src_exc - dst_exc >= 0 ) ) { /* This is error handling and recovery that should never occur. */ test(); - IF (src_exc != dst_exc && LE_16(nFrameLength, 1200)) + IF( src_exc != dst_exc && LE_16( nFrameLength, 1200 ) ) { - Copy(src_exc, dst_exc, nFrameLength); + Copy( src_exc, dst_exc, nFrameLength ); } return; } - roundedPitchStart = round_fx(pitchStart); /*Q0*/ + roundedPitchStart = round_fx( pitchStart ); /*Q0*/ /* freqStart = 1.0f/roundedPitchStart; */ freqStart_e = 15; move16(); - freqStart = Inv16(roundedPitchStart, &freqStart_e); /*Q15,freqStart_e*/ + freqStart = Inv16( roundedPitchStart, &freqStart_e ); /*Q15,freqStart_e*/ /* Calculate number of samples to be removed (if negative) or added (if positive) */ /*samplesDelta = 0.5f*pitchDelta*nFrameLength*(nSubframes+1)*freqStart;*/ /* pitchDelta*freqStart = ((pitchEnd - pitchStart)/roundedPitchStart)/nSubframes */ - tmp16 = shl(roundedPitchStart, 2); /*Q0*/ - if (EQ_16(nSubframes, 5)) + tmp16 = shl( roundedPitchStart, 2 ); /*Q0*/ + if ( EQ_16( nSubframes, 5 ) ) { - tmp16 = add(tmp16, roundedPitchStart);/*Q0*/ /*tmp16=roundedPitchStart*nSubframes*/ + tmp16 = add( tmp16, roundedPitchStart ); /*Q0*/ /*tmp16=roundedPitchStart*nSubframes*/ } - tmp_e = norm_s(tmp16); - tmp16 = shl(tmp16, tmp_e);/*Q0,-tmp_e*/ /*tmp16=roundedPitchStart*nSubframes*/ - tmp_e = sub(15, tmp_e); - tmp16 = Inv16(tmp16, &tmp_e); /*Q15,tmp_e*/ /*tmp16=1.0/(roundedPitchStart*nSubframes)*/ - tmp32 = L_sub(pitchEnd,pitchStart); - tmp2_e = norm_l(tmp32); - tmp32 = L_shl(tmp32, tmp2_e);/*Q16,-tmp2_e*/ - tmp32 = Mpy_32_16_1(tmp32, tmp16);/*Q16,tmp_e-tmp2_e*/ /*tmp32=pitchDelta*freqStart*/ - tmp_e = sub(tmp_e, tmp2_e); /* sum up all the scalings for tmp32 */ - - tmp16 = imult1616(nFrameLength,add(nSubframes,1));/*Q0*//*tmp16=nFrameLength*(nSubframes+1)*/ - tmp2_e = norm_s(tmp16); - tmp16 = shl(tmp16,tmp2_e); - - tmp32 = Mpy_32_16_1(tmp32,tmp16);/*Q1 scaling (tmp_e-tmp2_e-1), -1 because of 0.5f*/ /*tmp32=0.5f*pitchDelta*nFrameLength*(nSubframes+1)*freqStart*/ - tmp_e = sub(sub(tmp_e,tmp2_e),1); /* sum up all the scalings for tmp32 */ - tmp_e = add(tmp_e,31-1); /* tmp32 is now regarded as Q31 with scaling tmp_e */ + tmp_e = norm_s( tmp16 ); + tmp16 = shl( tmp16, tmp_e ); /*Q0,-tmp_e*/ /*tmp16=roundedPitchStart*nSubframes*/ + tmp_e = sub( 15, tmp_e ); + tmp16 = Inv16( tmp16, &tmp_e ); /*Q15,tmp_e*/ /*tmp16=1.0/(roundedPitchStart*nSubframes)*/ + tmp32 = L_sub( pitchEnd, pitchStart ); + tmp2_e = norm_l( tmp32 ); + tmp32 = L_shl( tmp32, tmp2_e ); /*Q16,-tmp2_e*/ + tmp32 = Mpy_32_16_1( tmp32, tmp16 ); /*Q16,tmp_e-tmp2_e*/ /*tmp32=pitchDelta*freqStart*/ + tmp_e = sub( tmp_e, tmp2_e ); /* sum up all the scalings for tmp32 */ + + tmp16 = imult1616( nFrameLength, add( nSubframes, 1 ) ); /*Q0*/ /*tmp16=nFrameLength*(nSubframes+1)*/ + tmp2_e = norm_s( tmp16 ); + tmp16 = shl( tmp16, tmp2_e ); + + tmp32 = Mpy_32_16_1( tmp32, tmp16 ); /*Q1 scaling (tmp_e-tmp2_e-1), -1 because of 0.5f*/ /*tmp32=0.5f*pitchDelta*nFrameLength*(nSubframes+1)*freqStart*/ + tmp_e = sub( sub( tmp_e, tmp2_e ), 1 ); /* sum up all the scalings for tmp32 */ + tmp_e = add( tmp_e, 31 - 1 ); /* tmp32 is now regarded as Q31 with scaling tmp_e */ /*samplesDelta -= nFrameLength*(1.0f-pitchStart*freqStart);*/ - tmp2_e = norm_l(pitchStart); - tmp32_a = L_shl(pitchStart,tmp2_e); - tmp32_a = Mpy_32_16_1(tmp32_a/*Q16,-tmp2_e*/,freqStart/*Q15,freqStart_e*/);/*Q16, scaling (freqStart_e-tmp2_e)*/ /*tmp32_a=pitchStart*freqStart*/ - tmp16 = norm_l(tmp32_a); - tmp32_a = L_shl(tmp32_a,tmp16); - tmp2_e = sub(sub(freqStart_e,tmp16),tmp2_e); /* sum up all scalings for tmp32_a */ - tmp2_e = add(tmp2_e,31-16); /* tmp32_a is now regarded as Q31 with scaling tmp2_e */ + tmp2_e = norm_l( pitchStart ); + tmp32_a = L_shl( pitchStart, tmp2_e ); + tmp32_a = Mpy_32_16_1( tmp32_a /*Q16,-tmp2_e*/, freqStart /*Q15,freqStart_e*/ ); /*Q16, scaling (freqStart_e-tmp2_e)*/ /*tmp32_a=pitchStart*freqStart*/ + tmp16 = norm_l( tmp32_a ); + tmp32_a = L_shl( tmp32_a, tmp16 ); + tmp2_e = sub( sub( freqStart_e, tmp16 ), tmp2_e ); /* sum up all scalings for tmp32_a */ + tmp2_e = add( tmp2_e, 31 - 16 ); /* tmp32_a is now regarded as Q31 with scaling tmp2_e */ tmp3_e = tmp2_e; - tmp32_a = L_negate(tmp32_a); + tmp32_a = L_negate( tmp32_a ); #ifdef BASOP_NOGLOB - tmp32_a = L_add(L_shl_o(1, sub(31, tmp3_e), &Overflow), tmp32_a); /*Q31,tmp3_e*//*tmp32_a= 1.0f-pitchStart*freqStart*/ + tmp32_a = L_add( L_shl_o( 1, sub( 31, tmp3_e ), &Overflow ), tmp32_a ); /*Q31,tmp3_e*/ /*tmp32_a= 1.0f-pitchStart*freqStart*/ #else - tmp32_a = L_add(L_shl(1, sub(31, tmp3_e)), tmp32_a); /*Q31,tmp3_e*//*tmp32_a= 1.0f-pitchStart*freqStart*/ + tmp32_a = L_add( L_shl( 1, sub( 31, tmp3_e ) ), tmp32_a ); /*Q31,tmp3_e*/ /*tmp32_a= 1.0f-pitchStart*freqStart*/ #endif - tmp2_e = norm_s(nFrameLength); - tmp16_a = shl(nFrameLength,tmp2_e); - tmp32_a = Mpy_32_16_1(tmp32_a/*Q31,tmp3_e*/,tmp16_a/*Q0,-tmp2_e*/);/*Q16,tmp3_e-tmp2_e*/ /*tmp32_a= nFrameLength*(1.0f-pitchStart*freqStart)*/ - tmp2_e = add(sub(tmp3_e, tmp2_e), 15); - samplesDelta = BASOP_Util_Add_Mant32Exp(tmp32, tmp_e, L_negate(tmp32_a), tmp2_e, &samplesDelta_e); /*Q31,samplesDelta_e*/ + tmp2_e = norm_s( nFrameLength ); + tmp16_a = shl( nFrameLength, tmp2_e ); + tmp32_a = Mpy_32_16_1( tmp32_a /*Q31,tmp3_e*/, tmp16_a /*Q0,-tmp2_e*/ ); /*Q16,tmp3_e-tmp2_e*/ /*tmp32_a= nFrameLength*(1.0f-pitchStart*freqStart)*/ + tmp2_e = add( sub( tmp3_e, tmp2_e ), 15 ); + samplesDelta = BASOP_Util_Add_Mant32Exp( tmp32, tmp_e, L_negate( tmp32_a ), tmp2_e, &samplesDelta_e ); /*Q31,samplesDelta_e*/ /* To have enough samples in the buffer of length nFrameLength*(nSubframes+1)/nSubframes, pitchEnd/pitchEnd must be bigger than (nSubframes-1)/(nSubframes+1)=1-2/(nSubframes+1) */ /* Thus nSubframes must be bigger than 1 */ - nSamplesDelta = round_fx(L_shl(samplesDelta,sub(samplesDelta_e,31-16))); /*Q0*/ - nSamplesDeltaRemain = abs_s(nSamplesDelta); + nSamplesDelta = round_fx( L_shl( samplesDelta, sub( samplesDelta_e, 31 - 16 ) ) ); /*Q0*/ + nSamplesDeltaRemain = abs_s( nSamplesDelta ); /* Find the location of the glottal pulse */ - T0 = FindMaxPeak_fx(src_exc, roundedPitchStart); /*Q0*/ + T0 = FindMaxPeak_fx( src_exc, roundedPitchStart ); /*Q0*/ /* Get the index of the last pulse in the resynchronized frame */ /*k = (int)ceil((nFrameLength-nSamplesDelta-T0)*freqStart - 1);*/ - tmp32 = BASOP_Util_Add_Mant32Exp(L_mult(sub(nFrameLength,add(nSamplesDelta,T0)),freqStart)/*Q16*/,add(freqStart_e,31-16),0x80000000/*-1.f Q31*/,0,&tmp_e); - tmp32 = L_shl(tmp32,sub(tmp_e,31-16))/*Q16*/; - tmp32 = L_add(tmp32,65536l/*1.f Q16*/); - k=extract_h(tmp32); + tmp32 = BASOP_Util_Add_Mant32Exp( L_mult( sub( nFrameLength, add( nSamplesDelta, T0 ) ), freqStart ) /*Q16*/, add( freqStart_e, 31 - 16 ), 0x80000000 /*-1.f Q31*/, 0, &tmp_e ); + tmp32 = L_shl( tmp32, sub( tmp_e, 31 - 16 ) ) /*Q16*/; + tmp32 = L_add( tmp32, 65536l /*1.f Q16*/ ); + k = extract_h( tmp32 ); test(); - IF ((k >= 0) && LE_16(add(k,1) , NB_PULSES_MAX)) + IF( ( k >= 0 ) && LE_16( add( k, 1 ), NB_PULSES_MAX ) ) { - absPitchDiff = L_abs(L_sub(L_deposit_h(roundedPitchStart),pitchEnd));/*Q16*/ + absPitchDiff = L_abs( L_sub( L_deposit_h( roundedPitchStart ), pitchEnd ) ); /*Q16*/ /* Calculate the delta of the samples to be added/removed between consecutive cycles */ /*perCycleDeltaDelta = (absPitchDiff*(nFrameLength-samplesDelta) - (float)fabs(samplesDelta)*roundedPitchStart) / ((k+1)*(T0+0.5f*k*roundedPitchStart));*/ - tmp32 = L_sub(L_deposit_h(nFrameLength),L_shl(samplesDelta,sub(samplesDelta_e,31-16)));/*Q16*/ - tmp_e = 15; /*tmp32 = Q31,tmp_e*/ move16(); - tmp2_e = norm_l(tmp32); - tmp32 = L_shl(tmp32,tmp2_e); - tmp_e = sub(tmp_e,tmp2_e); /*tmp32 = Q31,tmp_e*/ - tmp2_e = norm_l(absPitchDiff); - tmp32_b = L_shl(absPitchDiff,tmp2_e); - tmp_e = sub(tmp_e,tmp2_e); - tmp32 = Mpy_32_16_1(tmp32_b,round_fx(tmp32));/*Q16,tmp_e*/ /*tmp32 = absPitchDiff*(nFrameLength-samplesDelta)*/ - tmp32_a = Mpy_32_16_1(L_abs(samplesDelta)/*Q31,samplesDelta_e*/,roundedPitchStart/*Q0*/);/*Q16,samplesDelta_e*/ /*tmp32_a=fabs(samplesDelta)*roundedPitchStart*/ - tmp32 = BASOP_Util_Add_Mant32Exp(tmp32, add(tmp_e,31-16), L_negate(tmp32_a), add(samplesDelta_e,31-16),&tmp_e);/*Q31,tmp_e*/ /*tmp32=absPitchDiff*(nFrameLength-samplesDelta)-fabs(samplesDelta)*roundedPitchStart*/ - tmp16 = imult1616(add(k,1),add(shl(T0,1),imult1616(k,roundedPitchStart)));/*Q0,-1*/ /*tmp16=(k+1)*(T0+0.5f*k*roundedPitchStart)*/ - perCycleDeltaDelta = BASOP_Util_Divide3216_Scale(tmp32/*Q31,tmp_e*/,tmp16/*Q0,-1*/,&perCycleDeltaDelta_e); /*Q15,perCycleDeltaDelta_e*/ - perCycleDeltaDelta_e = add(perCycleDeltaDelta_e,sub(tmp_e,-1+15)); - tmp_e = norm_s(perCycleDeltaDelta); - perCycleDeltaDelta_e = sub(perCycleDeltaDelta_e,tmp_e); - perCycleDeltaDelta = shl(perCycleDeltaDelta,tmp_e);/*Q15,perCycleDeltaDelta_e*/ + tmp32 = L_sub( L_deposit_h( nFrameLength ), L_shl( samplesDelta, sub( samplesDelta_e, 31 - 16 ) ) ); /*Q16*/ + tmp_e = 15; /*tmp32 = Q31,tmp_e*/ + move16(); + tmp2_e = norm_l( tmp32 ); + tmp32 = L_shl( tmp32, tmp2_e ); + tmp_e = sub( tmp_e, tmp2_e ); /*tmp32 = Q31,tmp_e*/ + tmp2_e = norm_l( absPitchDiff ); + tmp32_b = L_shl( absPitchDiff, tmp2_e ); + tmp_e = sub( tmp_e, tmp2_e ); + tmp32 = Mpy_32_16_1( tmp32_b, round_fx( tmp32 ) ); /*Q16,tmp_e*/ /*tmp32 = absPitchDiff*(nFrameLength-samplesDelta)*/ + tmp32_a = Mpy_32_16_1( L_abs( samplesDelta ) /*Q31,samplesDelta_e*/, roundedPitchStart /*Q0*/ ); /*Q16,samplesDelta_e*/ /*tmp32_a=fabs(samplesDelta)*roundedPitchStart*/ + tmp32 = BASOP_Util_Add_Mant32Exp( tmp32, add( tmp_e, 31 - 16 ), L_negate( tmp32_a ), add( samplesDelta_e, 31 - 16 ), &tmp_e ); /*Q31,tmp_e*/ /*tmp32=absPitchDiff*(nFrameLength-samplesDelta)-fabs(samplesDelta)*roundedPitchStart*/ + tmp16 = imult1616( add( k, 1 ), add( shl( T0, 1 ), imult1616( k, roundedPitchStart ) ) ); /*Q0,-1*/ /*tmp16=(k+1)*(T0+0.5f*k*roundedPitchStart)*/ + perCycleDeltaDelta = BASOP_Util_Divide3216_Scale( tmp32 /*Q31,tmp_e*/, tmp16 /*Q0,-1*/, &perCycleDeltaDelta_e ); /*Q15,perCycleDeltaDelta_e*/ + perCycleDeltaDelta_e = add( perCycleDeltaDelta_e, sub( tmp_e, -1 + 15 ) ); + tmp_e = norm_s( perCycleDeltaDelta ); + perCycleDeltaDelta_e = sub( perCycleDeltaDelta_e, tmp_e ); + perCycleDeltaDelta = shl( perCycleDeltaDelta, tmp_e ); /*Q15,perCycleDeltaDelta_e*/ /* Calculate the integer number of samples to be added/removed in each pitch cycle */ /*cycleDelta = max(0, (absPitchDiff-(k+1)*perCycleDeltaDelta)*T0*freqStart); */ - tmp_e = norm_s(k+1); - tmp32 = L_mult(perCycleDeltaDelta/*Q15,perCycleDeltaDelta_e*/,shl(add(k,1),tmp_e)/*Q0, tmp_e*/)/*Q0+16, perCycleDeltaDelta_e-tmp_e*/; - tmp32 = BASOP_Util_Add_Mant32Exp(absPitchDiff/*Q16*/,31-16,L_negate(tmp32),add(sub(perCycleDeltaDelta_e,tmp_e),31-16),&tmp_e);/*Q31,tmp_e*/ - tmp32 = Mpy_32_16_1(tmp32,T0/*Q0*/);/*Q16,tmp_e*/ - tmp32 = Mpy_32_16_1(tmp32/*Q16,tmp_e*/,freqStart/*Q15,freqStart_e*/)/*Q16, tmp_e+(freqStart_e)*/; - tmp32 = L_max(0,tmp32); - cycleDelta_e = add(tmp_e,freqStart_e); - tmp32_a = L_shl(tmp32,cycleDelta_e); - roundedCycleDelta = extract_h(L_abs(tmp32_a)); - if (tmp32<0) + tmp_e = norm_s( k + 1 ); + tmp32 = L_mult( perCycleDeltaDelta /*Q15,perCycleDeltaDelta_e*/, shl( add( k, 1 ), tmp_e ) /*Q0, tmp_e*/ ) /*Q0+16, perCycleDeltaDelta_e-tmp_e*/; + tmp32 = BASOP_Util_Add_Mant32Exp( absPitchDiff /*Q16*/, 31 - 16, L_negate( tmp32 ), add( sub( perCycleDeltaDelta_e, tmp_e ), 31 - 16 ), &tmp_e ); /*Q31,tmp_e*/ + tmp32 = Mpy_32_16_1( tmp32, T0 /*Q0*/ ); /*Q16,tmp_e*/ + tmp32 = Mpy_32_16_1( tmp32 /*Q16,tmp_e*/, freqStart /*Q15,freqStart_e*/ ) /*Q16, tmp_e+(freqStart_e)*/; + tmp32 = L_max( 0, tmp32 ); + cycleDelta_e = add( tmp_e, freqStart_e ); + tmp32_a = L_shl( tmp32, cycleDelta_e ); + roundedCycleDelta = extract_h( L_abs( tmp32_a ) ); + if ( tmp32 < 0 ) { - roundedCycleDelta = negate(roundedCycleDelta); + roundedCycleDelta = negate( roundedCycleDelta ); } - fractionalLeft = lshr(extract_l(tmp32_a),1);/*Q15*/ - tmp_e = sub(15,norm_l(tmp32)); - cycleDelta_e = add(cycleDelta_e,tmp_e); - tmp32 = L_shr(tmp32,sub(tmp_e,15));/*Q31 frac, cycleDelta_e*/ + fractionalLeft = lshr( extract_l( tmp32_a ), 1 ); /*Q15*/ + tmp_e = sub( 15, norm_l( tmp32 ) ); + cycleDelta_e = add( cycleDelta_e, tmp_e ); + tmp32 = L_shr( tmp32, sub( tmp_e, 15 ) ); /*Q31 frac, cycleDelta_e*/ #ifdef BASOP_NOGLOB - cycleDelta = round_fx_o(tmp32, &Overflow);/*Q15, cycleDelta_e*/ + cycleDelta = round_fx_o( tmp32, &Overflow ); /*Q15, cycleDelta_e*/ #else - cycleDelta = round_fx(tmp32);/*Q15, cycleDelta_e*/ + cycleDelta = round_fx( tmp32 ); /*Q15, cycleDelta_e*/ #endif - if (cycleDelta == 0) + if ( cycleDelta == 0 ) { move16(); cycleDelta_e = 0; @@ -401,162 +391,160 @@ void PulseResynchronization_fx( /*roundedCycleDelta = (int)(cycleDelta); */ /*done above*/ move16(); - iDeltaSamples[0] = roundedCycleDelta;/*Q0*/ - /*fractionalLeft = cycleDelta-roundedCycleDelta;*/ /*done above*/ - nSamplesDeltaRemain = sub(nSamplesDeltaRemain,roundedCycleDelta);/*Q0*/ + iDeltaSamples[0] = roundedCycleDelta; /*Q0*/ + /*fractionalLeft = cycleDelta-roundedCycleDelta;*/ /*done above*/ + nSamplesDeltaRemain = sub( nSamplesDeltaRemain, roundedCycleDelta ); /*Q0*/ - tmp_e = (s_max(2,k)); - tmp_e = norm_s(tmp_e);/*maximum norming factor for following loop*/ + tmp_e = ( s_max( 2, k ) ); + tmp_e = norm_s( tmp_e ); /*maximum norming factor for following loop*/ - FOR (i = 1; i <= k; i++) + FOR( i = 1; i <= k; i++ ) { /*cycleDelta = (absPitchDiff-(k+1-i)*perCycleDeltaDelta) + fractionalLeft; */ - tmp32 = L_mult(perCycleDeltaDelta/*Q15,perCycleDeltaDelta_e*/,shl(sub(add(k,1),i),tmp_e)/*Q0, tmp_e*/)/*Q0+16, perCycleDeltaDelta_e-tmp_e*/; /*calcultion of base for first iteration*/ - tmp32 = L_shl(tmp32,sub(perCycleDeltaDelta_e,tmp_e));/*Q16*/ - tmp32_a = L_sub(absPitchDiff,tmp32); - tmp32_b = L_lshl(L_deposit_l(fractionalLeft/*Q15*/),1)/*Q16*/; - cycleDelta32 = L_add(tmp32_a,tmp32_b);/*Q16*/ - cycleDelta32 = L_max(0, cycleDelta32); + tmp32 = L_mult( perCycleDeltaDelta /*Q15,perCycleDeltaDelta_e*/, shl( sub( add( k, 1 ), i ), tmp_e ) /*Q0, tmp_e*/ ) /*Q0+16, perCycleDeltaDelta_e-tmp_e*/; /*calcultion of base for first iteration*/ + tmp32 = L_shl( tmp32, sub( perCycleDeltaDelta_e, tmp_e ) ); /*Q16*/ + tmp32_a = L_sub( absPitchDiff, tmp32 ); + tmp32_b = L_lshl( L_deposit_l( fractionalLeft /*Q15*/ ), 1 ) /*Q16*/; + cycleDelta32 = L_add( tmp32_a, tmp32_b ); /*Q16*/ + cycleDelta32 = L_max( 0, cycleDelta32 ); /* Make sure that the number of samples increases */ - IF (GT_32(L_deposit_h(roundedCycleDelta), cycleDelta32)) + IF( GT_32( L_deposit_h( roundedCycleDelta ), cycleDelta32 ) ) { iDeltaSamples[i] = roundedCycleDelta; move16(); - roundedCycleDelta = extract_h(cycleDelta32); /* cycleDelta32 should never be < 0 here */ - iDeltaSamples[i-1] = roundedCycleDelta; + roundedCycleDelta = extract_h( cycleDelta32 ); /* cycleDelta32 should never be < 0 here */ + iDeltaSamples[i - 1] = roundedCycleDelta; move16(); - } ELSE { - roundedCycleDelta = extract_h(cycleDelta32); /* cycleDelta32 should never be < 0 here */ + roundedCycleDelta = extract_h( cycleDelta32 ); /* cycleDelta32 should never be < 0 here */ iDeltaSamples[i] = roundedCycleDelta; move16(); } /*fractionalLeft = cycleDelta-roundedCycleDelta = cycleDelta-(int)cycleDelta;*/ - fractionalLeft = lshr(extract_l(cycleDelta32),1); /*Q15*/ /* cycleDelta32 should never be < 0 here */ - nSamplesDeltaRemain = sub(nSamplesDeltaRemain,roundedCycleDelta); + fractionalLeft = lshr( extract_l( cycleDelta32 ), 1 ); /*Q15*/ /* cycleDelta32 should never be < 0 here */ + nSamplesDeltaRemain = sub( nSamplesDeltaRemain, roundedCycleDelta ); } - iDeltaSamples[k+1] = s_max(0, nSamplesDeltaRemain); + iDeltaSamples[k + 1] = s_max( 0, nSamplesDeltaRemain ); move16(); - maxDeltaSamples = s_max(iDeltaSamples[k], iDeltaSamples[k+1]);/*Q0*/ + maxDeltaSamples = s_max( iDeltaSamples[k], iDeltaSamples[k + 1] ); /*Q0*/ /* Find the location of the minimum energy between the first two pulses */ /*iMinPos1 = T0+GetMinimumPosition_fx(src_exc+T0, min(roundedPitchStart, (nSubframes+1)*nFrameLength/nSubframes-T0), maxDeltaSamples);*/ - BASOP_Util_Divide_MantExp(add(nSubframes,1),15,nSubframes,15,&tmp16,&tmp_e); - tmp32 = L_mult(nFrameLength/*Q0*/,tmp16/*Q15,tmp_e*/);/*Q16,tmp_e*/ - tmp16 = round_fx(L_shl(tmp32,tmp_e)); - tmp16 = sub(tmp16,T0); - tmp16 = s_min(roundedPitchStart,tmp16); + BASOP_Util_Divide_MantExp( add( nSubframes, 1 ), 15, nSubframes, 15, &tmp16, &tmp_e ); + tmp32 = L_mult( nFrameLength /*Q0*/, tmp16 /*Q15,tmp_e*/ ); /*Q16,tmp_e*/ + tmp16 = round_fx( L_shl( tmp32, tmp_e ) ); + tmp16 = sub( tmp16, T0 ); + tmp16 = s_min( roundedPitchStart, tmp16 ); iMinPos1 = GetMinimumPosition_fx( - src_exc+T0, /*Qx*/ - tmp16, /*Q0*/ - maxDeltaSamples /*Q0*/ - ); - iMinPos1 = add(iMinPos1,T0); + src_exc + T0, /*Qx*/ + tmp16, /*Q0*/ + maxDeltaSamples /*Q0*/ + ); + iMinPos1 = add( iMinPos1, T0 ); - IF (nSamplesDelta < 0) + IF( nSamplesDelta < 0 ) { /* Find the location of the minimum energy before the first pulse */ - IF (GT_16(iMinPos1 , add(roundedPitchStart , shr(iDeltaSamples[0],1)))) + IF( GT_16( iMinPos1, add( roundedPitchStart, shr( iDeltaSamples[0], 1 ) ) ) ) { - iMinPos[0] = sub(iMinPos1 , sub(roundedPitchStart , shr(iDeltaSamples[0],1))); + iMinPos[0] = sub( iMinPos1, sub( roundedPitchStart, shr( iDeltaSamples[0], 1 ) ) ); move16(); } ELSE { move16(); - iMinPos[0] = sub(GetMinimumPosition_fx(src_exc, T0, iDeltaSamples[0]) , shr(iDeltaSamples[0],1)); + iMinPos[0] = sub( GetMinimumPosition_fx( src_exc, T0, iDeltaSamples[0] ), shr( iDeltaSamples[0], 1 ) ); } /* Find the location of the minimum energy between the pulses */ - FOR (i = 1; i <= k; i++) + FOR( i = 1; i <= k; i++ ) { move16(); - iMinPos[i] = add(iMinPos1 , sub(imult1616(sub(i,1),roundedPitchStart) , shr(iDeltaSamples[i],1))); + iMinPos[i] = add( iMinPos1, sub( imult1616( sub( i, 1 ), roundedPitchStart ), shr( iDeltaSamples[i], 1 ) ) ); } /* Find the location of the minimum energy after the last pulse */ - IF (LT_16(add(iMinPos1 , add(imult1616(k,roundedPitchStart) , sub(iDeltaSamples[k+1] , shr(iDeltaSamples[k+1],1)))) , sub(nFrameLength,nSamplesDelta) )) + IF( LT_16( add( iMinPos1, add( imult1616( k, roundedPitchStart ), sub( iDeltaSamples[k + 1], shr( iDeltaSamples[k + 1], 1 ) ) ) ), sub( nFrameLength, nSamplesDelta ) ) ) { move16(); - iMinPos[k+1] = add(iMinPos1 , sub(imult1616(k,roundedPitchStart) , shr(iDeltaSamples[k+1],1))); + iMinPos[k + 1] = add( iMinPos1, sub( imult1616( k, roundedPitchStart ), shr( iDeltaSamples[k + 1], 1 ) ) ); } ELSE { /*iMinPos[k+1] = T0+k*roundedPitchStart + GetMinimumPosition_fx(src_exc+T0+k*roundedPitchStart, nFrameLength-nSamplesDelta-(T0+k*roundedPitchStart), iDeltaSamples[k+1]) - iDeltaSamples[k+1]/2; */ - tmp16 = GetMinimumPosition_fx(src_exc+T0+k*roundedPitchStart, sub(nFrameLength,add(nSamplesDelta,add(T0,imult1616(k,roundedPitchStart)))), iDeltaSamples[k+1]); - tmp16 = add(add(T0,imult1616(k,roundedPitchStart)),tmp16); - tmp16 = sub(tmp16,shr(iDeltaSamples[k+1],1)); - iMinPos[k+1] = tmp16; + tmp16 = GetMinimumPosition_fx( src_exc + T0 + k * roundedPitchStart, sub( nFrameLength, add( nSamplesDelta, add( T0, imult1616( k, roundedPitchStart ) ) ) ), iDeltaSamples[k + 1] ); + tmp16 = add( add( T0, imult1616( k, roundedPitchStart ) ), tmp16 ); + tmp16 = sub( tmp16, shr( iDeltaSamples[k + 1], 1 ) ); + iMinPos[k + 1] = tmp16; move16(); } - IF (GT_16(add(iMinPos[k+1],iDeltaSamples[k+1]) , sub(nFrameLength,nSamplesDelta))) + IF( GT_16( add( iMinPos[k + 1], iDeltaSamples[k + 1] ), sub( nFrameLength, nSamplesDelta ) ) ) { - iDeltaSamples[k] += add(iMinPos[k+1] , sub(iDeltaSamples[k+1] , sub(nFrameLength,nSamplesDelta))); - iDeltaSamples[k+1] = sub(nFrameLength , add(nSamplesDelta , iMinPos[k+1])); + iDeltaSamples[k] += add( iMinPos[k + 1], sub( iDeltaSamples[k + 1], sub( nFrameLength, nSamplesDelta ) ) ); + iDeltaSamples[k + 1] = sub( nFrameLength, add( nSamplesDelta, iMinPos[k + 1] ) ); } /* Remove samples at the given positions */ - RemoveSamples_fx(src_exc, dst_exc, nFrameLength, nSamplesDelta, iMinPos, iDeltaSamples, k+2); + RemoveSamples_fx( src_exc, dst_exc, nFrameLength, nSamplesDelta, iMinPos, iDeltaSamples, k + 2 ); } ELSE { /* Find the location of the minimum energy before the first pulse */ - IF (GT_16(iMinPos1 , roundedPitchStart)) + IF( GT_16( iMinPos1, roundedPitchStart ) ) { - iMinPos[0] = sub(iMinPos1 , roundedPitchStart); + iMinPos[0] = sub( iMinPos1, roundedPitchStart ); move16(); } ELSE { - iMinPos[0] = GetMinimumPosition_fx(src_exc, T0, iDeltaSamples[0]); + iMinPos[0] = GetMinimumPosition_fx( src_exc, T0, iDeltaSamples[0] ); move16(); } /* Find the location of the minimum energy between the pulses */ - FOR (i = 1; i <= k; i++) + FOR( i = 1; i <= k; i++ ) { iMinPos[i] = iMinPos1; move16(); - iMinPos1 = add(iMinPos1,roundedPitchStart); + iMinPos1 = add( iMinPos1, roundedPitchStart ); } /* Find the location of the minimum energy after the last pulse */ - IF (LT_16(iMinPos1 , sub(nFrameLength,nSamplesDelta))) + IF( LT_16( iMinPos1, sub( nFrameLength, nSamplesDelta ) ) ) { - iMinPos[k+1] = iMinPos1; + iMinPos[k + 1] = iMinPos1; move16(); } ELSE { - tmp16 = GetMinimumPosition_fx(src_exc+T0+k*roundedPitchStart, sub(nFrameLength,add(nSamplesDelta,add(T0,imult1616(k,roundedPitchStart)))), iDeltaSamples[k+1]); - tmp16 = add(add(tmp16,T0),imult1616(k,roundedPitchStart)); - iMinPos[k+1] = tmp16; + tmp16 = GetMinimumPosition_fx( src_exc + T0 + k * roundedPitchStart, sub( nFrameLength, add( nSamplesDelta, add( T0, imult1616( k, roundedPitchStart ) ) ) ), iDeltaSamples[k + 1] ); + tmp16 = add( add( tmp16, T0 ), imult1616( k, roundedPitchStart ) ); + iMinPos[k + 1] = tmp16; move16(); } - IF (GT_16(add(iMinPos[k+1],iDeltaSamples[k+1]) , sub(nFrameLength,nSamplesDelta))) + IF( GT_16( add( iMinPos[k + 1], iDeltaSamples[k + 1] ), sub( nFrameLength, nSamplesDelta ) ) ) { move16(); move16(); - iDeltaSamples[k] = add(iDeltaSamples[k] , add(iMinPos[k+1] , sub(iDeltaSamples[k+1] , sub(nFrameLength,nSamplesDelta)))); - iDeltaSamples[k+1] = sub(sub(nFrameLength, nSamplesDelta),iMinPos[k+1]); + iDeltaSamples[k] = add( iDeltaSamples[k], add( iMinPos[k + 1], sub( iDeltaSamples[k + 1], sub( nFrameLength, nSamplesDelta ) ) ) ); + iDeltaSamples[k + 1] = sub( sub( nFrameLength, nSamplesDelta ), iMinPos[k + 1] ); } /* Add samples at the given positions */ - AddSamples_fx(src_exc, dst_exc, nFrameLength, nSamplesDelta, iMinPos, iDeltaSamples, k+2); + AddSamples_fx( src_exc, dst_exc, nFrameLength, nSamplesDelta, iMinPos, iDeltaSamples, k + 2 ); } } - } #endif diff --git a/lib_dec/er_util.c b/lib_dec/er_util.c index 821403276..aa9f77287 100644 --- a/lib_dec/er_util.c +++ b/lib_dec/er_util.c @@ -311,7 +311,7 @@ int16_t GetPLCModeDecision( { TonalMDCTConceal_Detect_ivas( st->hTonalMDCTConc, ( hTcxDec->tcxltp_last_gain_unmodified_float > 0 ) ? st->old_fpitch_float : 0, &numIndices, - ( st->element_mode == IVAS_CPE_MDCT ? &( st->hTcxCfg->psychParamsTCX20 ) : st->hTcxCfg->psychParamsCurrent ) ); + ( st->element_mode == IVAS_CPE_MDCT ? &( st->hTcxCfg->psychParamsTCX20 ) : st->hTcxCfg->psychParamsCurrent ) ); if ( ( numIndices > 10 ) || ( ( numIndices > 5 ) && ( fabs( hTcxDec->tcxltp_third_last_pitch_float - hTcxDec->tcxltp_second_last_pitch_float ) < 0.5f ) ) || ( ( numIndices > 0 ) && ( ( st->last_good <= UNVOICED_TRANSITION ) || ( hTcxDec->tcxltp_last_gain_unmodified_float <= 0.4f ) ) && ( fabs( hTcxDec->tcxltp_third_last_pitch_float - hTcxDec->tcxltp_second_last_pitch_float ) < 0.5f ) ) ) { diff --git a/lib_dec/er_util_fx.c b/lib_dec/er_util_fx.c index 4989d744d..f526a6103 100644 --- a/lib_dec/er_util_fx.c +++ b/lib_dec/er_util_fx.c @@ -17,7 +17,7 @@ * * Helper function - updates buffer for minimumStatistics_fx function */ -static void setnoiseLevelMemory_fx(Word16 f, Word16* new_noiseEstimate_e, Word16* noiseLevelMemory_e, Word16* noiseLevelMemory, Word16* currLevelIndex) +static void setnoiseLevelMemory_fx( Word16 f, Word16 *new_noiseEstimate_e, Word16 *noiseLevelMemory_e, Word16 *noiseLevelMemory, Word16 *currLevelIndex ) { noiseLevelMemory[*currLevelIndex] = f; move16(); @@ -30,21 +30,21 @@ static void setnoiseLevelMemory_fx(Word16 f, Word16* new_noiseEstimate_e, Word16 * PLC: and for PLC fade out */ void minimumStatistics_fx( - Word16* noiseLevelMemory, /* Qx, internal state */ - Word16* noiseLevelIndex, /* Q0, internal state */ - Word16* currLevelIndex, /* Q0, internal state (circular buffer) */ - Word16* noiseEstimate, /* Qx, previous estimate of background noise */ - Word16* lastFrameLevel, /* Qx, level of the last frame */ - Word16 currentFrameLevel, /* Qx, level of the current frame */ - Word16* noiseLevelMemory_e, /* scaling factor for noiseLevelMemory */ - Word16 const noiseEstimate_e, /* exponent of noiseEstimate */ - Word16* new_noiseEstimate_e, /* new exponent of noise Estimate*/ - Word16* const lastFrameLevel_e, /* exponent of lastFrameLevel */ - Word16 currentFrameLevel_e) /* exponent of currentFrameLevel */ + Word16 *noiseLevelMemory, /* Qx, internal state */ + Word16 *noiseLevelIndex, /* Q0, internal state */ + Word16 *currLevelIndex, /* Q0, internal state (circular buffer) */ + Word16 *noiseEstimate, /* Qx, previous estimate of background noise */ + Word16 *lastFrameLevel, /* Qx, level of the last frame */ + Word16 currentFrameLevel, /* Qx, level of the current frame */ + Word16 *noiseLevelMemory_e, /* scaling factor for noiseLevelMemory */ + Word16 const noiseEstimate_e, /* exponent of noiseEstimate */ + Word16 *new_noiseEstimate_e, /* new exponent of noise Estimate*/ + Word16 *const lastFrameLevel_e, /* exponent of lastFrameLevel */ + Word16 currentFrameLevel_e ) /* exponent of currentFrameLevel */ { Word16 aOpt, aOpt_e; Word16 f, p, i; - Word16 tmp,tmp2, tmp_e; + Word16 tmp, tmp2, tmp_e; Word32 tmp32; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; @@ -55,9 +55,9 @@ void minimumStatistics_fx( BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB - IF (LT_16(shl_o(currentFrameLevel, currentFrameLevel_e, &Overflow),PLC_MIN_CNG_LEV)) + IF( LT_16( shl_o( currentFrameLevel, currentFrameLevel_e, &Overflow ), PLC_MIN_CNG_LEV ) ) #else - IF (LT_16(shl(currentFrameLevel, currentFrameLevel_e),PLC_MIN_CNG_LEV)) + IF( LT_16( shl( currentFrameLevel, currentFrameLevel_e ), PLC_MIN_CNG_LEV ) ) #endif { BASOP_SATURATE_WARNING_ON_EVS @@ -69,22 +69,22 @@ void minimumStatistics_fx( BASOP_SATURATE_WARNING_ON_EVS /* compute optimal factor aOpt for recursive smoothing of frame minima */ - tmp2 = BASOP_Util_Add_MantExp(*lastFrameLevel,*lastFrameLevel_e,negate(*noiseEstimate),noiseEstimate_e,&tmp); - IF (tmp >= 0) + tmp2 = BASOP_Util_Add_MantExp( *lastFrameLevel, *lastFrameLevel_e, negate( *noiseEstimate ), noiseEstimate_e, &tmp ); + IF( tmp >= 0 ) { /* aOpt = *noiseEstimate / *lastFrameLevel; */ - aOpt = BASOP_Util_Divide1616_Scale(*noiseEstimate, *lastFrameLevel, &aOpt_e); - aOpt_e = add(aOpt_e, sub(noiseEstimate_e, *lastFrameLevel_e)); + aOpt = BASOP_Util_Divide1616_Scale( *noiseEstimate, *lastFrameLevel, &aOpt_e ); + aOpt_e = add( aOpt_e, sub( noiseEstimate_e, *lastFrameLevel_e ) ); } ELSE { /* aOpt = *lastFrameLevel / *noiseEstimate; */ - aOpt = BASOP_Util_Divide1616_Scale(*lastFrameLevel, *noiseEstimate, &aOpt_e); - aOpt_e = add(aOpt_e, sub(*lastFrameLevel_e, noiseEstimate_e)); + aOpt = BASOP_Util_Divide1616_Scale( *lastFrameLevel, *noiseEstimate, &aOpt_e ); + aOpt_e = add( aOpt_e, sub( *lastFrameLevel_e, noiseEstimate_e ) ); } - aOpt = mult_r(aOpt, aOpt); /* Q15 */ - aOpt_e = shl(aOpt_e,1); - if (aOpt == 0) + aOpt = mult_r( aOpt, aOpt ); /* Q15 */ + aOpt_e = shl( aOpt_e, 1 ); + if ( aOpt == 0 ) { move16(); aOpt_e = 0; @@ -99,45 +99,44 @@ void minimumStatistics_fx( tmp = *currLevelIndex; move16(); move16(); - if (tmp == 0) + if ( tmp == 0 ) { tmp = PLC_MIN_STAT_BUFF_SIZE; move16(); - } /*f = msu_r(L_mult(aOpt, noiseLevelMemory[sub(tmp, 1)]), add(aOpt, 0x8000), currentFrameLevel);*/ /*f = (aOpt * noiseLevelMemory[tmp-1]) - (currentFrameLevel * (aOpt-1))*/ - /*tmp32*/ /*tmp*/ + /*tmp32*/ /*tmp*/ - tmp32 = L_mult(aOpt,noiseLevelMemory[tmp-1]); /*Q_tmp32 = aOpt_e + noiseLevelMemory_e[tmp - 1]*/ + tmp32 = L_mult( aOpt, noiseLevelMemory[tmp - 1] ); /*Q_tmp32 = aOpt_e + noiseLevelMemory_e[tmp - 1]*/ move16(); tmp_e = tmp; - tmp2 = BASOP_Util_Add_MantExp(aOpt,aOpt_e,negate(32768/2),1,&tmp); - tmp = mult_r(tmp,currentFrameLevel); /*Q_tmp = tmp2 + currentFrameLevel_e*/ - tmp2 = add(tmp2,currentFrameLevel_e); + tmp2 = BASOP_Util_Add_MantExp( aOpt, aOpt_e, negate( 32768 / 2 ), 1, &tmp ); + tmp = mult_r( tmp, currentFrameLevel ); /*Q_tmp = tmp2 + currentFrameLevel_e*/ + tmp2 = add( tmp2, currentFrameLevel_e ); - IF(EQ_16(tmp, 0)) + IF( EQ_16( tmp, 0 ) ) { tmp2 = 0; move16(); } - *new_noiseEstimate_e = BASOP_Util_Add_MantExp(round_fx(tmp32),add(aOpt_e,noiseLevelMemory_e[tmp_e - 1]),negate(s_max(tmp,-32767)/*to avoid negate(-32768)*/),tmp2,&f); + *new_noiseEstimate_e = BASOP_Util_Add_MantExp( round_fx( tmp32 ), add( aOpt_e, noiseLevelMemory_e[tmp_e - 1] ), negate( s_max( tmp, -32767 ) /*to avoid negate(-32768)*/ ), tmp2, &f ); - assert(f >= 0); + assert( f >= 0 ); /* if current frame min is a new local min, set index to current index */ p = *noiseLevelIndex; move16(); - tmp2 = BASOP_Util_Add_MantExp(noiseLevelMemory[p],noiseLevelMemory_e[p],negate(f),*new_noiseEstimate_e,&tmp); - IF (tmp >= 0) + tmp2 = BASOP_Util_Add_MantExp( noiseLevelMemory[p], noiseLevelMemory_e[p], negate( f ), *new_noiseEstimate_e, &tmp ); + IF( tmp >= 0 ) { /*rescale noiseLevelMemory*/ - setnoiseLevelMemory_fx(f,new_noiseEstimate_e,noiseLevelMemory_e, noiseLevelMemory, currLevelIndex); + setnoiseLevelMemory_fx( f, new_noiseEstimate_e, noiseLevelMemory_e, noiseLevelMemory, currLevelIndex ); p = *currLevelIndex; move16(); } @@ -145,21 +144,22 @@ void minimumStatistics_fx( { move16(); - setnoiseLevelMemory_fx(f,new_noiseEstimate_e, noiseLevelMemory_e, noiseLevelMemory, currLevelIndex); + setnoiseLevelMemory_fx( f, new_noiseEstimate_e, noiseLevelMemory_e, noiseLevelMemory, currLevelIndex ); /* current min is not a new min, so check if min must be re-searched */ - IF (NE_16(p, *currLevelIndex)) + IF( NE_16( p, *currLevelIndex ) ) { - f = noiseLevelMemory[p]; /* min is still in memory, so return it */ + f = noiseLevelMemory[p]; /* min is still in memory, so return it */ move16(); *new_noiseEstimate_e = noiseLevelMemory_e[p]; } - ELSE { + ELSE + { /* p == currLevelIndex; min was removed from memory, re-search min */ - FOR (i = 0; i < PLC_MIN_STAT_BUFF_SIZE; i++) + FOR( i = 0; i < PLC_MIN_STAT_BUFF_SIZE; i++ ) { - tmp2 = BASOP_Util_Add_MantExp(noiseLevelMemory[p],noiseLevelMemory_e[p],negate(noiseLevelMemory[i]),noiseLevelMemory_e[i],&tmp); - if ( tmp > 0) + tmp2 = BASOP_Util_Add_MantExp( noiseLevelMemory[p], noiseLevelMemory_e[p], negate( noiseLevelMemory[i] ), noiseLevelMemory_e[i], &tmp ); + if ( tmp > 0 ) { p = i; move16(); @@ -174,10 +174,10 @@ void minimumStatistics_fx( /* update local-minimum-value index and current circular-buffer index */ *noiseLevelIndex = p; move16(); - p = add(*currLevelIndex,1); - *currLevelIndex = add(*currLevelIndex, 1); + p = add( *currLevelIndex, 1 ); + *currLevelIndex = add( *currLevelIndex, 1 ); move16(); - if (EQ_16(*currLevelIndex, PLC_MIN_STAT_BUFF_SIZE)) + if ( EQ_16( *currLevelIndex, PLC_MIN_STAT_BUFF_SIZE ) ) { *currLevelIndex = 0; move16(); @@ -193,152 +193,158 @@ void minimumStatistics_fx( * of LPC synthesis and deeemphasis based on the given input *----------------------------------------------------------------------*/ Word16 getLevelSynDeemph_fx( /*10Q5*/ - Word16 h1Init[], /* i: input value or vector to be processed */ /* Q15 */ - Word16 const A[], /* i: LPC coefficients */ /* Qx */ - Word16 const lpcorder, /* i: LPC order */ /* Q0 */ - Word16 const lenLpcExc, /* i: length of the LPC excitation buffer */ /* Q0 */ - Word16 const preemph_fac, /* i: preemphasis factor */ /* Q15 */ - Word16 const numLoops, /* i: number of loops */ /* Q0 */ - Word16 *Exp /* o: exponent of return value Q15 */ + Word16 h1Init[], + /* i: input value or vector to be processed */ /* Q15 */ + Word16 const A[], + /* i: LPC coefficients */ /* Qx */ + Word16 const lpcorder, + /* i: LPC order */ /* Q0 */ + Word16 const lenLpcExc, + /* i: length of the LPC excitation buffer */ /* Q0 */ + Word16 const preemph_fac, + /* i: preemphasis factor */ /* Q15 */ + Word16 const numLoops, + /* i: number of loops */ /* Q0 */ + Word16 *Exp /* o: exponent of return value Q15 */ ) { - Word32 levelSynDeemphSub; - Word32 levelSynDeemph ; - Word16 h1[L_FRAME_PLUS/4]; /*Q15*/ - Word16 mem[M]; - Word16 tmp; - Word16 loop; + Word32 levelSynDeemphSub; + Word32 levelSynDeemph; + Word16 h1[L_FRAME_PLUS / 4]; /*Q15*/ + Word16 mem[M]; + Word16 tmp; + Word16 loop; Word16 s16, tmp16, Hr16; Word16 Q_h1; - levelSynDeemphSub = L_deposit_l(0); - levelSynDeemph = L_deposit_l(0); + levelSynDeemphSub = L_deposit_l( 0 ); + levelSynDeemph = L_deposit_l( 0 ); tmp = 0; - Q_h1 = 9; /*synthesis scaling for */ move16(); + Q_h1 = 9; /*synthesis scaling for */ + move16(); /*calculate headroom for dotproduct*/ - Hr16 = sub(15,norm_s(lenLpcExc)); + Hr16 = sub( 15, norm_s( lenLpcExc ) ); - Q_h1 = s_max(sub(Q_h1,Hr16),0); /*compensate synthesis scaling with Headroom as much as possible to retain as much precision as possible*/ + Q_h1 = s_max( sub( Q_h1, Hr16 ), 0 ); /*compensate synthesis scaling with Headroom as much as possible to retain as much precision as possible*/ /*Factor to be multiplied in order to calculate dotproduct with headroom*/ - tmp16 = shr(32768/2,sub(Hr16,1)); + tmp16 = shr( 32768 / 2, sub( Hr16, 1 ) ); /*moved from inside loop, before synthesis*/ - h1Init[0] = mult_r(h1Init[0],tmp16); + h1Init[0] = mult_r( h1Init[0], tmp16 ); move16(); - FOR (loop = 0; loop < numLoops; loop++) + FOR( loop = 0; loop < numLoops; loop++ ) { - set16_fx(h1, 0, lenLpcExc); - set16_fx(mem, 0, lpcorder); + set16_fx( h1, 0, lenLpcExc ); + set16_fx( mem, 0, lpcorder ); - Copy(h1Init, h1, 1); + Copy( h1Init, h1, 1 ); /*h1 will be scaled down, Q_h1 */ - E_UTIL_synthesis(Q_h1, A, h1, h1, lenLpcExc, mem, 0, lpcorder); - deemph_fx(h1, preemph_fac, lenLpcExc, &tmp); - A += (M+1); + E_UTIL_synthesis( Q_h1, A, h1, h1, lenLpcExc, mem, 0, lpcorder ); + deemph_fx( h1, preemph_fac, lenLpcExc, &tmp ); + A += ( M + 1 ); /* gain introduced by synthesis+deemphasis */ /*levelSynDeemphSub = (float)sqrt(dot_product( h1, h1, lenLpcExc));*/ - levelSynDeemphSub = Dot_product12_offs(h1, h1, lenLpcExc, &s16, 0); - s16 = sub(shl(add(Q_h1,Hr16),1), sub(30, s16)); + levelSynDeemphSub = Dot_product12_offs( h1, h1, lenLpcExc, &s16, 0 ); + s16 = sub( shl( add( Q_h1, Hr16 ), 1 ), sub( 30, s16 ) ); - levelSynDeemphSub = Sqrt32(levelSynDeemphSub,&s16); /*Q31*/ + levelSynDeemphSub = Sqrt32( levelSynDeemphSub, &s16 ); /*Q31*/ /* mean of the above across all subframes -- moved outta loop*/ /*levelSynDeemph += (1.0/(float)numLoops) * levelSynDeemphSub;*/ - tmp16 = 32767/*1.0f Q15*/; + tmp16 = 32767 /*1.0f Q15*/; move16(); - if (GT_16(numLoops , 1)) + if ( GT_16( numLoops, 1 ) ) { - tmp16 = div_s(1,numLoops); + tmp16 = div_s( 1, numLoops ); } - levelSynDeemph = L_add(levelSynDeemph , L_shl(Mpy_32_16_1(levelSynDeemphSub,tmp16),sub(s16,10))); /*10Q21*/ - + levelSynDeemph = L_add( levelSynDeemph, L_shl( Mpy_32_16_1( levelSynDeemphSub, tmp16 ), sub( s16, 10 ) ) ); /*10Q21*/ } - s16 = norm_l(levelSynDeemph); - levelSynDeemph = L_shl(levelSynDeemph, s16); + s16 = norm_l( levelSynDeemph ); + levelSynDeemph = L_shl( levelSynDeemph, s16 ); move16(); - *Exp = sub(10,s16); /*Set exponent in order to transform returnvalue to Q15*/ + *Exp = sub( 10, s16 ); /*Set exponent in order to transform returnvalue to Q15*/ #ifdef BASOP_NOGLOB - return round_fx_sat(levelSynDeemph); /*Q15*/ + return round_fx_sat( levelSynDeemph ); /*Q15*/ #else - return round_fx(levelSynDeemph); /*Q15*/ + return round_fx( levelSynDeemph ); /*Q15*/ #endif } /* BASOP version: up to date with rev 7422 */ void genPlcFiltBWAdap_fx( - const Word32 sr_core, /* i : core sampling rate */ - Word16* lpFiltAdapt, /* o : filter coefficients for filtering codebooks in case of flc */ - const Word16 type, /* i : type of filter, either 0 : lowpass or 1 : highpass */ - const Word16 alpha /* i : fade out factor [0 1) used decrease filter tilt */ + const Word32 sr_core, /* i : core sampling rate */ + Word16 *lpFiltAdapt, /* o : filter coefficients for filtering codebooks in case of flc */ + const Word16 type, /* i : type of filter, either 0 : lowpass or 1 : highpass */ + const Word16 alpha /* i : fade out factor [0 1) used decrease filter tilt */ ) { Word16 a, b, exp; - assert(type == 0 || type == 1); + assert( type == 0 || type == 1 ); - IF ( EQ_32(sr_core, INT_FS_16k)) + IF( EQ_32( sr_core, INT_FS_16k ) ) { - IF (type == 0) + IF( type == 0 ) { move16(); move16(); move16(); - *lpFiltAdapt++ = 7282/* 0.4000f/(2.f*0.4000f+1.f) Q15*/; - *lpFiltAdapt++ = 18204/* 1.f/(2.f*0.4000f+1.f) Q15*/; - *lpFiltAdapt = 7282/* 0.4000f/(2.f*0.4000f+1.f) Q15*/; + *lpFiltAdapt++ = 7282 /* 0.4000f/(2.f*0.4000f+1.f) Q15*/; + *lpFiltAdapt++ = 18204 /* 1.f/(2.f*0.4000f+1.f) Q15*/; + *lpFiltAdapt = 7282 /* 0.4000f/(2.f*0.4000f+1.f) Q15*/; } ELSE { - a = mult_r(13107/*0.4000f Q15*/, alpha); + a = mult_r( 13107 /*0.4000f Q15*/, alpha ); exp = 0; move16(); - b = Inv16(add(a, 16384/*0.5f Q15*/), &exp); - b = shr(b, sub(1, exp)); - a = negate(mult_r(a, b)); + b = Inv16( add( a, 16384 /*0.5f Q15*/ ), &exp ); + b = shr( b, sub( 1, exp ) ); + a = negate( mult_r( a, b ) ); move16(); move16(); move16(); *lpFiltAdapt++ = a; *lpFiltAdapt++ = b; - *lpFiltAdapt = a; + *lpFiltAdapt = a; } } - ELSE /*sr_core = INT_FS_12k8 */ + ELSE /*sr_core = INT_FS_12k8 */ { - IF (type == 0) + IF( type == 0 ) { move16(); move16(); move16(); - *lpFiltAdapt++ = 5899/* 0.2813f/(2.f*0.2813f+1.f) Q15*/; - *lpFiltAdapt++ = 20970/* 1.f/(2.f*0.2813f+1.f) Q15*/; - *lpFiltAdapt = 5899/* 0.2813f/(2.f*0.2813f+1.f) Q15*/; + *lpFiltAdapt++ = 5899 /* 0.2813f/(2.f*0.2813f+1.f) Q15*/; + *lpFiltAdapt++ = 20970 /* 1.f/(2.f*0.2813f+1.f) Q15*/; + *lpFiltAdapt = 5899 /* 0.2813f/(2.f*0.2813f+1.f) Q15*/; } - ELSE { - a = mult_r(9218/*0.2813f Q15*/, alpha); + ELSE + { + a = mult_r( 9218 /*0.2813f Q15*/, alpha ); exp = 0; move16(); - b = Inv16(add(a, 16384/*0.5f Q15*/), &exp); - b = shr(b, sub(1, exp)); - a = negate(mult_r(a, b)); + b = Inv16( add( a, 16384 /*0.5f Q15*/ ), &exp ); + b = shr( b, sub( 1, exp ) ); + a = negate( mult_r( a, b ) ); move16(); move16(); move16(); *lpFiltAdapt++ = a; *lpFiltAdapt++ = b; - *lpFiltAdapt = a; + *lpFiltAdapt = a; } } - } @@ -348,21 +354,21 @@ void genPlcFiltBWAdap_fx( *-----------------------------------------------------------------*/ /*VERSIONINFO: This port is up to date with trunk rev. 32434*/ void highPassFiltering_fx( - const Word16 last_good, /* i: short last classification type */ - const Word16 L_buffer, /* i: int buffer length */ - Word16 exc2[], /* i/o: Qx unvoiced excitation before the high pass filtering */ - const Word16 hp_filt[], /* i: Q15 high pass filter coefficients */ - const Word16 l_fir_fer) /* i: high pass filter length */ + const Word16 last_good, /* i: short last classification type */ + const Word16 L_buffer, /* i: int buffer length */ + Word16 exc2[], /* i/o: Qx unvoiced excitation before the high pass filtering */ + const Word16 hp_filt[], /* i: Q15 high pass filter coefficients */ + const Word16 l_fir_fer ) /* i: high pass filter length */ { - Word16 i; /*int*/ + Word16 i; /*int*/ - IF( GT_16(last_good , UNVOICED_TRANSITION)) + IF( GT_16( last_good, UNVOICED_TRANSITION ) ) { - FOR( i=0 ; i< L_buffer; i++ ) + FOR( i = 0; i < L_buffer; i++ ) { - exc2[i] = round_fx(L_sub(Dot_product(&exc2[i], hp_filt, l_fir_fer), 1)); + exc2[i] = round_fx( L_sub( Dot_product( &exc2[i], hp_filt, l_fir_fer ), 1 ) ); } } } @@ -373,7 +379,7 @@ void highPassFiltering_fx( *----------------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED Word16 GetPLCModeDecision_ivas_fx( - Decoder_State *st /* i/o: decoder memory state pointer */ + Decoder_State *st /* i/o: decoder memory state pointer */ ) { Word16 /*int*/ core; @@ -383,32 +389,30 @@ Word16 GetPLCModeDecision_ivas_fx( hTcxDec = st->hTcxDec; - IF( EQ_16(st->flagGuidedAcelp,1)) + IF( EQ_16( st->flagGuidedAcelp, 1 ) ) { - st->old_pitch_buf_fx[2*st->nb_subfr] = L_deposit_h(st->guidedT0); - st->old_pitch_buf_fx[2*st->nb_subfr+1] = L_deposit_h(st->guidedT0); - st->mem_pitch_gain[0] = st->mem_pitch_gain[1] = 16384/*1.f Q14*/;/*Q14*/ + st->old_pitch_buf_fx[2 * st->nb_subfr] = L_deposit_h( st->guidedT0 ); + st->old_pitch_buf_fx[2 * st->nb_subfr + 1] = L_deposit_h( st->guidedT0 ); + st->mem_pitch_gain[0] = st->mem_pitch_gain[1] = 16384 /*1.f Q14*/; /*Q14*/ } st->plc_use_future_lag = 0; move16(); test(); test(); - if(( st->last_core > ACELP_CORE && hTcxDec->tcxltp_last_gain_unmodified!=0 ) - || ( EQ_16(st->flagGuidedAcelp,1) ) - ) + if ( ( st->last_core > ACELP_CORE && hTcxDec->tcxltp_last_gain_unmodified != 0 ) || ( EQ_16( st->flagGuidedAcelp, 1 ) ) ) { /* no updates needed here, because already updated in last good frame */ st->plc_use_future_lag = 1; move16(); } - IF (EQ_16(st->last_core,-1)) + IF( EQ_16( st->last_core, -1 ) ) { core = TCX_20_CORE; move16(); st->last_core = ACELP_CORE; move16(); - if(st->Opt_AMR_WB) + if ( st->Opt_AMR_WB ) { core = ACELP_CORE; move16(); @@ -420,19 +424,19 @@ Word16 GetPLCModeDecision_ivas_fx( { core = ACELP_CORE; move16(); - if (GT_16(st->nbLostCmpt,1)) + if ( GT_16( st->nbLostCmpt, 1 ) ) { core = st->last_core_bfi; move16(); } - IF (EQ_16(st->nbLostCmpt,1)) + IF( EQ_16( st->nbLostCmpt, 1 ) ) { st->tonal_mdct_plc_active = 0; move16(); test(); test(); test(); - IF ( !(st->rf_flag && st->use_partial_copy && (EQ_16(st->rf_frame_type, RF_TCXTD1)||EQ_16(st->rf_frame_type,RF_TCXTD2)))) + IF( !( st->rf_flag && st->use_partial_copy && ( EQ_16( st->rf_frame_type, RF_TCXTD1 ) || EQ_16( st->rf_frame_type, RF_TCXTD2 ) ) ) ) { test(); test(); @@ -440,32 +444,28 @@ Word16 GetPLCModeDecision_ivas_fx( test(); test(); test(); -//PMT("handle to tonalMDCTconceal is missing") -//#ifdef ADD_IVAS_HTONALMDCTCONC - IF ((st->hTonalMDCTConc != NULL && EQ_16(st->last_core,TCX_20_CORE))&&(EQ_16(st->second_last_core,TCX_20_CORE)) - && ((LE_32(st->old_fpitch,L_deposit_h(shr(st->L_frame,1)))) - || (LE_16(hTcxDec->tcxltp_last_gain_unmodified,13107/*0.4f Q15*/))) - /* it is fine to call the detection even if no ltp information - is available, meaning that st->old_fpitch == - st->tcxltp_second_last_pitch == st->L_frame */ - && (EQ_32(st->old_fpitch, hTcxDec->tcxltp_second_last_pitch)) - && !st->last_tns_active && !st->second_last_tns_active) + // PMT("handle to tonalMDCTconceal is missing") + //#ifdef ADD_IVAS_HTONALMDCTCONC + IF( ( st->hTonalMDCTConc != NULL && EQ_16( st->last_core, TCX_20_CORE ) ) && ( EQ_16( st->second_last_core, TCX_20_CORE ) ) && ( ( LE_32( st->old_fpitch, L_deposit_h( shr( st->L_frame, 1 ) ) ) ) || ( LE_16( hTcxDec->tcxltp_last_gain_unmodified, 13107 /*0.4f Q15*/ ) ) ) + /* it is fine to call the detection even if no ltp information + is available, meaning that st->old_fpitch == + st->tcxltp_second_last_pitch == st->L_frame */ + && ( EQ_32( st->old_fpitch, hTcxDec->tcxltp_second_last_pitch ) ) && !st->last_tns_active && !st->second_last_tns_active ) { Word32 pitch; - pitch = L_deposit_h(0); - if(hTcxDec->tcxltp_last_gain_unmodified > 0) + pitch = L_deposit_h( 0 ); + if ( hTcxDec->tcxltp_last_gain_unmodified > 0 ) { - pitch = L_add(st->old_fpitch, 0); + pitch = L_add( st->old_fpitch, 0 ); } - //TonalMDCTConceal_Detect_ivas_fx(&st->tonalMDCTconceal, pitch, &numIndices - // , (st->element_mode == IVAS_CPE_MDCT ? &(st->hTcxCfg->psychParamsTCX20) : st->hTcxCfg->psychParamsCurrent) + // TonalMDCTConceal_Detect_ivas_fx(&st->tonalMDCTconceal, pitch, &numIndices + // , (st->element_mode == IVAS_CPE_MDCT ? &(st->hTcxCfg->psychParamsTCX20) : st->hTcxCfg->psychParamsCurrent) //); - TonalMDCTConceal_Detect_ivas_fx(st->hTonalMDCTConc, pitch, &numIndices - , (st->element_mode == IVAS_CPE_MDCT ? &(st->hTcxCfg->psychParamsTCX20) : st->hTcxCfg->psychParamsCurrent), - st->element_mode); + TonalMDCTConceal_Detect_ivas_fx( st->hTonalMDCTConc, pitch, &numIndices, ( st->element_mode == IVAS_CPE_MDCT ? &( st->hTcxCfg->psychParamsTCX20 ) : st->hTcxCfg->psychParamsCurrent ), + st->element_mode ); test(); test(); @@ -473,27 +473,23 @@ Word16 GetPLCModeDecision_ivas_fx( test(); test(); test(); - IF ((GT_16(numIndices,10)) - || ((GT_16(numIndices,5) ) - && (LT_32(L_abs(L_sub(hTcxDec->tcxltp_third_last_pitch, hTcxDec->tcxltp_second_last_pitch)),32768l/*0.5f Q16*/) )) - || ((numIndices > 0) && ((LE_16(st->last_good,UNVOICED_TRANSITION))||(LE_16(hTcxDec->tcxltp_last_gain_unmodified,13107/*0.4f Q15*/))) - && (LT_32(L_abs(L_sub(hTcxDec->tcxltp_third_last_pitch, hTcxDec->tcxltp_second_last_pitch)),32768l/*0.5f Q16*/) ))) + IF( ( GT_16( numIndices, 10 ) ) || ( ( GT_16( numIndices, 5 ) ) && ( LT_32( L_abs( L_sub( hTcxDec->tcxltp_third_last_pitch, hTcxDec->tcxltp_second_last_pitch ) ), 32768l /*0.5f Q16*/ ) ) ) || ( ( numIndices > 0 ) && ( ( LE_16( st->last_good, UNVOICED_TRANSITION ) ) || ( LE_16( hTcxDec->tcxltp_last_gain_unmodified, 13107 /*0.4f Q15*/ ) ) ) && ( LT_32( L_abs( L_sub( hTcxDec->tcxltp_third_last_pitch, hTcxDec->tcxltp_second_last_pitch ) ), 32768l /*0.5f Q16*/ ) ) ) ) { core = TCX_20_CORE; move16(); st->tonal_mdct_plc_active = 1; move16(); } - ELSE IF (LE_16(st->last_good,UNVOICED_TRANSITION)||LE_16(hTcxDec->tcxltp_last_gain_unmodified,13107/*0.4f Q15*/)) + ELSE IF( LE_16( st->last_good, UNVOICED_TRANSITION ) || LE_16( hTcxDec->tcxltp_last_gain_unmodified, 13107 /*0.4f Q15*/ ) ) { core = TCX_20_CORE; move16(); } } - ELSE IF (st->last_core != ACELP_CORE) + ELSE IF( st->last_core != ACELP_CORE ) { test(); - if (LE_16(st->last_good,UNVOICED_TRANSITION)||LE_16(hTcxDec->tcxltp_last_gain_unmodified,13107/*0.4f Q15*/)) + if ( LE_16( st->last_good, UNVOICED_TRANSITION ) || LE_16( hTcxDec->tcxltp_last_gain_unmodified, 13107 /*0.4f Q15*/ ) ) { core = st->last_core; move16(); @@ -507,7 +503,7 @@ Word16 GetPLCModeDecision_ivas_fx( #endif Word16 GetPLCModeDecision_fx( - Decoder_State *st /* i/o: decoder memory state pointer */ + Decoder_State *st /* i/o: decoder memory state pointer */ ) { Word16 /*int*/ core; @@ -517,32 +513,30 @@ Word16 GetPLCModeDecision_fx( hTcxDec = st->hTcxDec; - IF( EQ_16(st->flagGuidedAcelp,1)) + IF( EQ_16( st->flagGuidedAcelp, 1 ) ) { - st->old_pitch_buf_fx[2*st->nb_subfr] = L_deposit_h(st->guidedT0); - st->old_pitch_buf_fx[2*st->nb_subfr+1] = L_deposit_h(st->guidedT0); - st->mem_pitch_gain[0] = st->mem_pitch_gain[1] = 16384/*1.f Q14*/;/*Q14*/ + st->old_pitch_buf_fx[2 * st->nb_subfr] = L_deposit_h( st->guidedT0 ); + st->old_pitch_buf_fx[2 * st->nb_subfr + 1] = L_deposit_h( st->guidedT0 ); + st->mem_pitch_gain[0] = st->mem_pitch_gain[1] = 16384 /*1.f Q14*/; /*Q14*/ } st->plc_use_future_lag = 0; move16(); test(); test(); - if(( st->last_core > ACELP_CORE && hTcxDec->tcxltp_last_gain_unmodified!=0 ) - || ( EQ_16(st->flagGuidedAcelp,1) ) - ) + if ( ( st->last_core > ACELP_CORE && hTcxDec->tcxltp_last_gain_unmodified != 0 ) || ( EQ_16( st->flagGuidedAcelp, 1 ) ) ) { /* no updates needed here, because already updated in last good frame */ st->plc_use_future_lag = 1; move16(); } - IF (EQ_16(st->last_core,-1)) + IF( EQ_16( st->last_core, -1 ) ) { core = TCX_20_CORE; move16(); st->last_core = ACELP_CORE; move16(); - if(st->Opt_AMR_WB) + if ( st->Opt_AMR_WB ) { core = ACELP_CORE; move16(); @@ -554,19 +548,19 @@ Word16 GetPLCModeDecision_fx( { core = ACELP_CORE; move16(); - if (GT_16(st->nbLostCmpt,1)) + if ( GT_16( st->nbLostCmpt, 1 ) ) { core = st->last_core_bfi; move16(); } - IF (EQ_16(st->nbLostCmpt,1)) + IF( EQ_16( st->nbLostCmpt, 1 ) ) { st->tonal_mdct_plc_active = 0; move16(); test(); test(); test(); - IF ( !(st->rf_flag && st->use_partial_copy && (EQ_16(st->rf_frame_type, RF_TCXTD1)||EQ_16(st->rf_frame_type,RF_TCXTD2)))) + IF( !( st->rf_flag && st->use_partial_copy && ( EQ_16( st->rf_frame_type, RF_TCXTD1 ) || EQ_16( st->rf_frame_type, RF_TCXTD2 ) ) ) ) { test(); test(); @@ -574,39 +568,39 @@ Word16 GetPLCModeDecision_fx( test(); test(); test(); -//PMT("handle to tonalMDCTconceal is missing") -//#ifdef ADD_IVAS_HTONALMDCTCONC - IF ((/*st->ADD_IVAS_HTONALMDCTCONC != NULL &&*/ EQ_16(st->last_core,TCX_20_CORE))&&(EQ_16(st->second_last_core,TCX_20_CORE)) - && ((LE_32(st->old_fpitch,L_deposit_h(shr(st->L_frame,1)))) - || (LE_16(hTcxDec->tcxltp_last_gain_unmodified,13107/*0.4f Q15*/))) - /* it is fine to call the detection even if no ltp information - is available, meaning that st->old_fpitch == - st->tcxltp_second_last_pitch == st->L_frame */ - && (EQ_32(st->old_fpitch, hTcxDec->tcxltp_second_last_pitch)) - && !st->last_tns_active && !st->second_last_tns_active) + // PMT("handle to tonalMDCTconceal is missing") + //#ifdef ADD_IVAS_HTONALMDCTCONC + IF( ( /*st->ADD_IVAS_HTONALMDCTCONC != NULL &&*/ EQ_16( st->last_core, TCX_20_CORE ) ) && ( EQ_16( st->second_last_core, TCX_20_CORE ) ) && ( ( LE_32( st->old_fpitch, L_deposit_h( shr( st->L_frame, 1 ) ) ) ) || ( LE_16( hTcxDec->tcxltp_last_gain_unmodified, 13107 /*0.4f Q15*/ ) ) ) + /* it is fine to call the detection even if no ltp information + is available, meaning that st->old_fpitch == + st->tcxltp_second_last_pitch == st->L_frame */ + && ( EQ_32( st->old_fpitch, hTcxDec->tcxltp_second_last_pitch ) ) && !st->last_tns_active && !st->second_last_tns_active ) { Word32 pitch; - pitch = L_deposit_h(0); - if(hTcxDec->tcxltp_last_gain_unmodified > 0) + pitch = L_deposit_h( 0 ); + if ( hTcxDec->tcxltp_last_gain_unmodified > 0 ) { - pitch = L_add(st->old_fpitch, 0); + pitch = L_add( st->old_fpitch, 0 ); } - if (st->element_mode == EVS_MONO) + if ( st->element_mode == EVS_MONO ) { - TonalMDCTConceal_Detect(&st->tonalMDCTconceal, pitch, &numIndices, st->element_mode + TonalMDCTConceal_Detect( &st->tonalMDCTconceal, pitch, &numIndices, st->element_mode #ifdef ADD_IVAS_HTONALMDCTCONC - , (st->element_mode == IVAS_CPE_MDCT ? &(st->hTcxCfg->psychParamsTCX20) : st->hTcxCfg->psychParamsCurrent) + , + ( st->element_mode == IVAS_CPE_MDCT ? &( st->hTcxCfg->psychParamsTCX20 ) : st->hTcxCfg->psychParamsCurrent ) #endif - ); + ); } - else { - TonalMDCTConceal_Detect(st->hTonalMDCTConc, pitch, &numIndices, st->element_mode + else + { + TonalMDCTConceal_Detect( st->hTonalMDCTConc, pitch, &numIndices, st->element_mode #ifdef ADD_IVAS_HTONALMDCTCONC - , (st->element_mode == IVAS_CPE_MDCT ? &(st->hTcxCfg->psychParamsTCX20) : st->hTcxCfg->psychParamsCurrent) + , + ( st->element_mode == IVAS_CPE_MDCT ? &( st->hTcxCfg->psychParamsTCX20 ) : st->hTcxCfg->psychParamsCurrent ) #endif - ); + ); } test(); @@ -615,27 +609,23 @@ Word16 GetPLCModeDecision_fx( test(); test(); test(); - IF ((GT_16(numIndices,10)) - || ((GT_16(numIndices,5) ) - && (LT_32(L_abs(L_sub(hTcxDec->tcxltp_third_last_pitch, hTcxDec->tcxltp_second_last_pitch)),32768l/*0.5f Q16*/) )) - || ((numIndices > 0) && ((LE_16(st->last_good,UNVOICED_TRANSITION))||(LE_16(hTcxDec->tcxltp_last_gain_unmodified,13107/*0.4f Q15*/))) - && (LT_32(L_abs(L_sub(hTcxDec->tcxltp_third_last_pitch, hTcxDec->tcxltp_second_last_pitch)),32768l/*0.5f Q16*/) ))) + IF( ( GT_16( numIndices, 10 ) ) || ( ( GT_16( numIndices, 5 ) ) && ( LT_32( L_abs( L_sub( hTcxDec->tcxltp_third_last_pitch, hTcxDec->tcxltp_second_last_pitch ) ), 32768l /*0.5f Q16*/ ) ) ) || ( ( numIndices > 0 ) && ( ( LE_16( st->last_good, UNVOICED_TRANSITION ) ) || ( LE_16( hTcxDec->tcxltp_last_gain_unmodified, 13107 /*0.4f Q15*/ ) ) ) && ( LT_32( L_abs( L_sub( hTcxDec->tcxltp_third_last_pitch, hTcxDec->tcxltp_second_last_pitch ) ), 32768l /*0.5f Q16*/ ) ) ) ) { core = TCX_20_CORE; move16(); st->tonal_mdct_plc_active = 1; move16(); } - ELSE IF (LE_16(st->last_good,UNVOICED_TRANSITION)||LE_16(hTcxDec->tcxltp_last_gain_unmodified,13107/*0.4f Q15*/)) + ELSE IF( LE_16( st->last_good, UNVOICED_TRANSITION ) || LE_16( hTcxDec->tcxltp_last_gain_unmodified, 13107 /*0.4f Q15*/ ) ) { core = TCX_20_CORE; move16(); } } - ELSE IF (st->last_core != ACELP_CORE) + ELSE IF( st->last_core != ACELP_CORE ) { test(); - if (LE_16(st->last_good,UNVOICED_TRANSITION)||LE_16(hTcxDec->tcxltp_last_gain_unmodified,13107/*0.4f Q15*/)) + if ( LE_16( st->last_good, UNVOICED_TRANSITION ) || LE_16( hTcxDec->tcxltp_last_gain_unmodified, 13107 /*0.4f Q15*/ ) ) { core = st->last_core; move16(); diff --git a/lib_dec/evs_dec_fx.c b/lib_dec/evs_dec_fx.c index 0952a6359..33515f491 100644 --- a/lib_dec/evs_dec_fx.c +++ b/lib_dec/evs_dec_fx.c @@ -2,13 +2,13 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include /* Debug prototypes */ -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "basop_util.h" /* Function prototypes */ +#include /* Debug prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "basop_util.h" /* Function prototypes */ #ifdef IVAS_FLOAT_FIXED /*--------------------------------------------------------------------------* @@ -18,9 +18,9 @@ *--------------------------------------------------------------------------*/ ivas_error evs_dec_fx( - Decoder_State *st_fx, /* i/o : Decoder state structure */ - Word16 output_sp[], /* o : output synthesis signal */ - frameMode_fx frameMode /* i : Decoder frame mode */ + Decoder_State *st_fx, /* i/o : Decoder state structure */ + Word16 output_sp[], /* o : output synthesis signal */ + frameMode_fx frameMode /* i : Decoder frame mode */ ) { Word16 i, j, output_frame; @@ -30,26 +30,26 @@ ivas_error evs_dec_fx( Word16 unbits; Word16 hq_core_type; Word16 post_hq_delay; - Word32 bwe_exc_extended_fx[L_FRAME32k+NL_BUFF_OFFSET]; + Word32 bwe_exc_extended_fx[L_FRAME32k + NL_BUFF_OFFSET]; Word16 voice_factors_fx[NB_SUBFR16k]; Word16 hb_synth_fx[L_FRAME48k]; Word16 hb_synth_fx_exp; Word32 L_tmp; - Word16 exp,fra; + Word16 exp, fra; Word16 tmp_buffer_fx[L_FRAME48k]; - Word16 tmp16,tmp16_2; + Word16 tmp16, tmp16_2; #ifdef IVAS_CODE Word16 synth_fx[L_FRAME48k]; #else - Word16 synth_fx[L_FRAME48k + HQ_DELTA_MAX*HQ_DELAY_COMP]; + Word16 synth_fx[L_FRAME48k + HQ_DELTA_MAX * HQ_DELAY_COMP]; #endif Word16 fb_exc_fx[L_FRAME16k]; Word16 pitch_buf_fx[NB_SUBFR16k] = { 0 }; Word16 Q_fb_exc; Word16 old_syn_12k8_16k_fx[L_FRAME16k]; - Word16 sid_bw=-1; + Word16 sid_bw = -1; Word16 pcmbufFB[L_FRAME_MAX]; - Word32 workBuffer[128*3]; + Word32 workBuffer[128 * 3]; Word16 delta; Word16 nab; Word16 concealWholeFrame; @@ -80,9 +80,9 @@ ivas_error evs_dec_fx( timeIn_e = 0; move16(); - delay_tdbwe = 0; /* for compiler warning*/ + delay_tdbwe = 0; /* for compiler warning*/ Qpostd = 0; - move16(); /* default and used for MODE2 */ + move16(); /* default and used for MODE2 */ concealWholeFrame = -1; move16(); @@ -92,16 +92,16 @@ ivas_error evs_dec_fx( st_fx->idchan = 0; st_fx->element_brate = st_fx->total_brate; - st_fx->flag_ACELP16k = set_ACELP_flag(EVS_MONO, -1, st_fx->total_brate, 0, 0, -1, -1); + st_fx->flag_ACELP16k = set_ACELP_flag( EVS_MONO, -1, st_fx->total_brate, 0, 0, -1, -1 ); - FOR( i=0; ibfi == 0 ) + if ( st_fx->bfi == 0 ) { st_fx->extl = -1; move16(); @@ -125,7 +125,7 @@ ivas_error evs_dec_fx( Qpostd_prev = st_fx->Qprev_synth_buffer_fx; move16(); - IF( EQ_16(st_fx->bfi,1)) + IF( EQ_16( st_fx->bfi, 1 ) ) { hq_core_type = hHQ_core->last_hq_core_type; move16(); @@ -142,15 +142,12 @@ ivas_error evs_dec_fx( /* PLC: [TCX: Fade-out-recovery] - * PLC: overlapping part needs to be attenuated for first good frame */ test(); + * PLC: overlapping part needs to be attenuated for first good frame */ test(); test(); test(); - IF (!st_fx->bfi - && st_fx->prev_bfi - && (EQ_16(st_fx->last_codec_mode, MODE2) ) - && (EQ_16(st_fx->last_core_bfi, TCX_20_CORE) - || EQ_16(st_fx->last_core_bfi, TCX_10_CORE) )) + test(); + IF( !st_fx->bfi && st_fx->prev_bfi && ( EQ_16( st_fx->last_codec_mode, MODE2 ) ) && ( EQ_16( st_fx->last_core_bfi, TCX_20_CORE ) || EQ_16( st_fx->last_core_bfi, TCX_10_CORE ) ) ) { /* v_multc(st_fx->old_out_fx, st_fx->plcInfo.recovery_gain, */ /* st_fx->old_out_fx, st_fx->L_frameTCX); */ @@ -159,7 +156,7 @@ ivas_error evs_dec_fx( #ifdef BASOP_NOGLOB hHQ_core->old_out_fx[i] = shl_sat( mult_r( hHQ_core->old_out_fx[i], st_fx->plcInfo.recovery_gain ), 1 ); #else - hHQ_core->old_out_fx[i] = shl(mult_r(hHQ_core->old_out_fx[i] , st_fx->plcInfo.recovery_gain), 1); + hHQ_core->old_out_fx[i] = shl( mult_r( hHQ_core->old_out_fx[i], st_fx->plcInfo.recovery_gain ), 1 ); #endif } FOR( i = 0; i < st_fx->L_frame; i++ ) @@ -167,40 +164,39 @@ ivas_error evs_dec_fx( #ifdef BASOP_NOGLOB hHQ_core->old_out_LB_fx[i] = shl_sat( mult_r( hHQ_core->old_out_LB_fx[i], st_fx->plcInfo.recovery_gain ), 1 ); #else - hHQ_core->old_out_LB_fx[i] = shl(mult_r(hHQ_core->old_out_LB_fx[i], st_fx->plcInfo.recovery_gain), 1); + hHQ_core->old_out_LB_fx[i] = shl( mult_r( hHQ_core->old_out_LB_fx[i], st_fx->plcInfo.recovery_gain ), 1 ); #endif } /* attenuate PLC buffers, if no aldo window is used and if no sid or zero frame is received */ - IF ( 0 == st_fx->hTcxCfg->last_aldo ) + IF( 0 == st_fx->hTcxCfg->last_aldo ) { Word32 f; Word16 s; Word16 tmp1; - f = L_deposit_l(hTcxDec->conceal_eof_gain); /*Q14*/ - s = norm_l(f); - s = sub(16,s); - tmp1 = extract_l(L_shr_r(f,s)); - FOR( i=0; i < st_fx->hTcxCfg->tcx_mdct_window_lengthFB; i++ ) + f = L_deposit_l( hTcxDec->conceal_eof_gain ); /*Q14*/ + s = norm_l( f ); + s = sub( 16, s ); + tmp1 = extract_l( L_shr_r( f, s ) ); + FOR( i = 0; i < st_fx->hTcxCfg->tcx_mdct_window_lengthFB; i++ ) { #ifdef BASOP_NOGLOB hTcxDec->syn_OverlFB[i] = shl_sat( mult_sat( tmp1, hTcxDec->syn_OverlFB[i] ), add( s, 1 ) ); #else - hTcxDec->syn_OverlFB[i] = shl(mult(tmp1, hTcxDec->syn_OverlFB[i]), add(s,1)); + hTcxDec->syn_OverlFB[i] = shl( mult( tmp1, hTcxDec->syn_OverlFB[i] ), add( s, 1 ) ); #endif move16(); - } - s = norm_l(f); - s = sub(16,s); - tmp1 = extract_l(L_shr_r(f,s)); - FOR( i=0; i < st_fx->hTcxCfg->tcx_mdct_window_length; i++ ) + s = norm_l( f ); + s = sub( 16, s ); + tmp1 = extract_l( L_shr_r( f, s ) ); + FOR( i = 0; i < st_fx->hTcxCfg->tcx_mdct_window_length; i++ ) { #ifdef BASOP_NOGLOB hTcxDec->syn_Overl[i] = shl_sat( mult_sat( tmp1, hTcxDec->syn_Overl[i] ), s ); #else - hTcxDec->syn_Overl[i] = shl(mult(tmp1, hTcxDec->syn_Overl[i]),s); + hTcxDec->syn_Overl[i] = shl( mult( tmp1, hTcxDec->syn_Overl[i] ), s ); #endif move16(); } @@ -215,7 +211,7 @@ ivas_error evs_dec_fx( st_fx->rate_switching_reset = 0; move16(); - if(!st_fx->bfi) + if ( !st_fx->bfi ) { st_fx->flagGuidedAcelp = 0; } @@ -224,19 +220,19 @@ ivas_error evs_dec_fx( * Updates in case of AMR-WB IO mode -> EVS primary switching *----------------------------------------------------------------*/ - IF( EQ_16(st_fx->last_core,AMR_WB_CORE)) + IF( EQ_16( st_fx->last_core, AMR_WB_CORE ) ) { updt_IO_switch_dec_fx( output_frame, st_fx ); } - IF( NE_16(frameMode,FRAMEMODE_MISSING)) /* frame mode normal or future frame */ + IF( NE_16( frameMode, FRAMEMODE_MISSING ) ) /* frame mode normal or future frame */ { - getPartialCopyInfo(st_fx, &st_fx->coder_type, &sharpFlag); + getPartialCopyInfo( st_fx, &st_fx->coder_type, &sharpFlag ); frameMode = st_fx->bfi; } test(); - IF( EQ_16(st_fx->rf_frame_type,RF_NO_DATA)&&EQ_16(st_fx->use_partial_copy,1)) + IF( EQ_16( st_fx->rf_frame_type, RF_NO_DATA ) && EQ_16( st_fx->use_partial_copy, 1 ) ) { /* the partial copy is a RF FRAME_NO_DATA frame and should follow the concealment path*/ st_fx->bfi = 1; @@ -253,8 +249,8 @@ ivas_error evs_dec_fx( test(); test(); test(); - IF( EQ_16(st_fx->use_partial_copy,1)&&EQ_16(st_fx->core,TCX_20_CORE)&& - EQ_16(st_fx->prev_bfi,1) && EQ_16(st_fx->last_core,ACELP_CORE) ) + IF( EQ_16( st_fx->use_partial_copy, 1 ) && EQ_16( st_fx->core, TCX_20_CORE ) && + EQ_16( st_fx->prev_bfi, 1 ) && EQ_16( st_fx->last_core, ACELP_CORE ) ) { st_fx->bfi = 1; move16(); @@ -269,7 +265,7 @@ ivas_error evs_dec_fx( } /* if previous frame was HQ Core or TCX10, drop partial copy info and continue HQ Core/TCX10 concealment */ - IF( st_fx->use_partial_copy && ((sub(st_fx->last_core, HQ_CORE) == 0) || (sub(st_fx->last_core, TCX_10_CORE) == 0) || ((sub(st_fx->last_core, TCX_20_CORE) == 0) && getTcxonly(/*EVS_MONO, */st_fx->last_total_brate/*, 0, 0*/))) ) + IF( st_fx->use_partial_copy && ( ( sub( st_fx->last_core, HQ_CORE ) == 0 ) || ( sub( st_fx->last_core, TCX_10_CORE ) == 0 ) || ( ( sub( st_fx->last_core, TCX_20_CORE ) == 0 ) && getTcxonly( /*EVS_MONO, */ st_fx->last_total_brate /*, 0, 0*/ ) ) ) ) { st_fx->bfi = 1; move16(); @@ -286,37 +282,37 @@ ivas_error evs_dec_fx( /*------------------------------------------------------------------* * Decoding *-----------------------------------------------------------------*/ - IF( EQ_16(st_fx->codec_mode,MODE1)) + IF( EQ_16( st_fx->codec_mode, MODE1 ) ) { /*------------------------------------------------------------------* - * Decision matrix (selection of technologies) - *-----------------------------------------------------------------*/ + * Decision matrix (selection of technologies) + *-----------------------------------------------------------------*/ - IF ( NE_16(st_fx->bfi,1)) + IF( NE_16( st_fx->bfi, 1 ) ) { decision_matrix_dec_fx( st_fx, &sharpFlag, &hq_core_type, &core_switching_flag ); - IF( NE_16(st_fx->bfi,1)) + IF( NE_16( st_fx->bfi, 1 ) ) { - st_fx->sr_core = i_mult(st_fx->L_frame, FRAMES_PER_SEC); - st_fx->fscale_old = st_fx->fscale; - st_fx->fscale = sr2fscale_fx(st_fx->sr_core); + st_fx->sr_core = i_mult( st_fx->L_frame, FRAMES_PER_SEC ); + st_fx->fscale_old = st_fx->fscale; + st_fx->fscale = sr2fscale_fx( st_fx->sr_core ); } ELSE { - frameMode = FRAMEMODE_MISSING; + frameMode = FRAMEMODE_MISSING; move16(); } } } - IF( EQ_16(st_fx->codec_mode,MODE1)) + IF( EQ_16( st_fx->codec_mode, MODE1 ) ) { /*------------------------------------------------------------------* * Initialization *-----------------------------------------------------------------*/ - IF( EQ_16(st_fx->bfi,1)) + IF( EQ_16( st_fx->bfi, 1 ) ) { - st_fx->nbLostCmpt = add(st_fx->nbLostCmpt,1); + st_fx->nbLostCmpt = add( st_fx->nbLostCmpt, 1 ); } ELSE { @@ -330,13 +326,13 @@ ivas_error evs_dec_fx( * Detect bandwidth switching *---------------------------------------------------------------------*/ - bandwidth_switching_detect_fx(st_fx); + bandwidth_switching_detect_fx( st_fx ); /*---------------------------------------------------------------------* * Preprocessing (preparing) for ACELP/HQ core switching *---------------------------------------------------------------------*/ - //PMT("core_switching_pre_dec_fx missign args") - if ((error = core_switching_pre_dec_fx( st_fx, output_frame )) != IVAS_ERR_OK) + // PMT("core_switching_pre_dec_fx missign args") + if ( ( error = core_switching_pre_dec_fx( st_fx, output_frame ) ) != IVAS_ERR_OK ) { return error; } @@ -345,11 +341,11 @@ ivas_error evs_dec_fx( * ACELP core decoding * HQ core decoding *---------------------------------------------------------------------*/ - IF ( EQ_16(st_fx->core,ACELP_CORE)) + IF( EQ_16( st_fx->core, ACELP_CORE ) ) { /* ACELP core decoder */ - if ((error = acelp_core_dec_fx(st_fx, NULL, synth_fx, NULL, bwe_exc_extended_fx, voice_factors_fx, old_syn_12k8_16k_fx, sharpFlag, pitch_buf_fx, &unbits, &sid_bw, NULL, NULL, NULL, 0, EVS_MONO, 0, 0, 1, NULL, 1)) != IVAS_ERR_OK) + if ( ( error = acelp_core_dec_fx( st_fx, NULL, synth_fx, NULL, bwe_exc_extended_fx, voice_factors_fx, old_syn_12k8_16k_fx, sharpFlag, pitch_buf_fx, &unbits, &sid_bw, NULL, NULL, NULL, 0, EVS_MONO, 0, 0, 1, NULL, 1 ) ) != IVAS_ERR_OK ) { return error; } @@ -358,7 +354,7 @@ ivas_error evs_dec_fx( } ELSE { - //PMT("HQ core missing args") + // PMT("HQ core missing args") hq_core_dec_fx( st_fx, synth_fx, &Q_synth, output_frame, hq_core_type, core_switching_flag ); Qpostd = Q_synth; @@ -368,15 +364,15 @@ ivas_error evs_dec_fx( * Postprocessing for ACELP/HQ core switching *---------------------------------------------------------------------*/ - if ((error = core_switching_post_dec_fx( st_fx, synth_fx, + if ( ( error = core_switching_post_dec_fx( st_fx, synth_fx, #ifdef IVAS_CODE_SWITCHING - output, output_mem[], IVAS_FORMAT ivas_format, use_cldfb_for_dft, + output, output_mem[], IVAS_FORMAT ivas_format, use_cldfb_for_dft, #endif - output_frame, core_switching_flag, + output_frame, core_switching_flag, #ifdef IVAS_CODE_SWITCHING - sba_dirac_stereo_flag, nchan_out, + sba_dirac_stereo_flag, nchan_out, #endif - st_fx->last_element_mode, &Qpostd )) != IVAS_ERR_OK) + st_fx->last_element_mode, &Qpostd ) ) != IVAS_ERR_OK ) { return error; } @@ -384,7 +380,7 @@ ivas_error evs_dec_fx( * Pre-processing for bandwidth switching *---------------------------------------------------------------------*/ - ///PMT("bw_switching_pre_proc_fx missing args") + /// PMT("bw_switching_pre_proc_fx missing args") bw_switching_pre_proc_fx( old_syn_12k8_16k_fx, st_fx ); /*---------------------------------------------------------------------* @@ -392,23 +388,23 @@ ivas_error evs_dec_fx( * WB BWE decoding *---------------------------------------------------------------------*/ - IF ( EQ_16(st_fx->extl,WB_TBE)) + IF( EQ_16( st_fx->extl, WB_TBE ) ) { /* WB TBE decoder */ wb_tbe_dec_fx( st_fx, st_fx->coder_type, bwe_exc_extended_fx, st_fx->Q_exc, voice_factors_fx, hb_synth_fx, &hb_synth_fx_exp ); } - ELSE IF ( EQ_16(st_fx->extl,WB_BWE)&&st_fx->bws_cnt==0) + ELSE IF( EQ_16( st_fx->extl, WB_BWE ) && st_fx->bws_cnt == 0 ) { /* WB BWE decoder */ - hb_synth_fx_exp = wb_bwe_dec_fx( + hb_synth_fx_exp = wb_bwe_dec_fx( #ifdef ADD_IVAS_BWE - NULL, + NULL, #endif - synth_fx, hb_synth_fx, + synth_fx, hb_synth_fx, #ifdef ADD_IVAS_BWE - 0, + 0, #endif - output_frame, voice_factors_fx, pitch_buf_fx, st_fx, &Qpostd ); + output_frame, voice_factors_fx, pitch_buf_fx, st_fx, &Qpostd ); } /*---------------------------------------------------------------------* @@ -427,36 +423,32 @@ ivas_error evs_dec_fx( test(); test(); test(); - IF ( EQ_16(st_fx->extl,SWB_TBE)||EQ_16(st_fx->extl,FB_TBE) - || (NE_16(st_fx->coder_type,AUDIO) && NE_16(st_fx->coder_type,INACTIVE) && GT_32(st_fx->core_brate,SID_2k40) && EQ_16(st_fx->core,ACELP_CORE) - && GE_32(st_fx->output_Fs,32000) && GT_16(st_fx->bwidth,NB) && st_fx->bws_cnt > 0 && !st_fx->ppp_mode_dec - && !( EQ_16( st_fx->nelp_mode_dec, 1) && EQ_16( st_fx->bfi, 1) ) ) ) + IF( EQ_16( st_fx->extl, SWB_TBE ) || EQ_16( st_fx->extl, FB_TBE ) || ( NE_16( st_fx->coder_type, AUDIO ) && NE_16( st_fx->coder_type, INACTIVE ) && GT_32( st_fx->core_brate, SID_2k40 ) && EQ_16( st_fx->core, ACELP_CORE ) && GE_32( st_fx->output_Fs, 32000 ) && GT_16( st_fx->bwidth, NB ) && st_fx->bws_cnt > 0 && !st_fx->ppp_mode_dec && !( EQ_16( st_fx->nelp_mode_dec, 1 ) && EQ_16( st_fx->bfi, 1 ) ) ) ) { swb_tbe_dec_fx( st_fx, st_fx->coder_type, bwe_exc_extended_fx, st_fx->Q_exc, voice_factors_fx, old_syn_12k8_16k_fx, fb_exc_fx, &Q_fb_exc, hb_synth_fx, &hb_synth_fx_exp, pitch_buf_fx ); /* FB TBE decoder/synthesis */ test(); - IF ( EQ_16(output_frame,L_FRAME48k)&&EQ_16(st_fx->extl,FB_TBE)) + IF( EQ_16( output_frame, L_FRAME48k ) && EQ_16( st_fx->extl, FB_TBE ) ) { - fb_tbe_dec_fx( st_fx, fb_exc_fx, Q_fb_exc, hb_synth_fx, hb_synth_fx_exp); + fb_tbe_dec_fx( st_fx, fb_exc_fx, Q_fb_exc, hb_synth_fx, hb_synth_fx_exp ); } } - ELSE IF( EQ_16(st_fx->extl,SWB_BWE)||EQ_16(st_fx->extl,FB_BWE)|| - (GE_32(st_fx->output_Fs,32000) && EQ_16(st_fx->core,ACELP_CORE) && GT_16(st_fx->bwidth,NB) && st_fx->bws_cnt > 0 && !st_fx->ppp_mode_dec - && !( EQ_16( st_fx->nelp_mode_dec, 1) && EQ_16( st_fx->bfi, 1) ) ) ) + ELSE IF( EQ_16( st_fx->extl, SWB_BWE ) || EQ_16( st_fx->extl, FB_BWE ) || + ( GE_32( st_fx->output_Fs, 32000 ) && EQ_16( st_fx->core, ACELP_CORE ) && GT_16( st_fx->bwidth, NB ) && st_fx->bws_cnt > 0 && !st_fx->ppp_mode_dec && !( EQ_16( st_fx->nelp_mode_dec, 1 ) && EQ_16( st_fx->bfi, 1 ) ) ) ) { /* SWB BWE decoder */ - hb_synth_fx_exp = swb_bwe_dec_fx( + hb_synth_fx_exp = swb_bwe_dec_fx( #ifdef ADD_IVAS_BWE - NULL, + NULL, #endif - st_fx, synth_fx, hb_synth_fx, + st_fx, synth_fx, hb_synth_fx, #ifdef ADD_IVAS_BWE - 0, + 0, #endif - output_frame, &Qpostd); + output_frame, &Qpostd ); } - ELSE IF( EQ_16(st_fx->extl,SWB_BWE_HIGHRATE)||EQ_16(st_fx->extl,FB_BWE_HIGHRATE)) + ELSE IF( EQ_16( st_fx->extl, SWB_BWE_HIGHRATE ) || EQ_16( st_fx->extl, FB_BWE_HIGHRATE ) ) { hb_synth_fx_exp = swb_bwe_dec_hr_fx( st_fx, old_syn_12k8_16k_fx, Qpostd, hb_synth_fx, output_frame, unbits, pitch_buf_fx ); } @@ -467,28 +459,28 @@ ivas_error evs_dec_fx( test(); test(); - IF ( st_fx->prev_bfi && EQ_16(st_fx->last_core,HQ_CORE)&&NE_16(st_fx->extl,-1)) + IF( st_fx->prev_bfi && EQ_16( st_fx->last_core, HQ_CORE ) && NE_16( st_fx->extl, -1 ) ) { /*tmp = FRAC_BWE_SMOOTH/output_frame;*/ - tmp16 = shr(410,shr(output_frame,8)); - if(EQ_16(output_frame, L_FRAME48k)) + tmp16 = shr( 410, shr( output_frame, 8 ) ); + if ( EQ_16( output_frame, L_FRAME48k ) ) { tmp16 = 68; move16(); } /*output_frame/FRAC_BWE_SMOOTH*/ - j = shr(output_frame,1); + j = shr( output_frame, 1 ); tmp16_2 = 0; move16(); - FOR (i = 0; i < j; i++) + FOR( i = 0; i < j; i++ ) { /*hb_synth[i] *= (i*tmp);*/ - hb_synth_fx[i] = mult_r(hb_synth_fx[i], tmp16_2); + hb_synth_fx[i] = mult_r( hb_synth_fx[i], tmp16_2 ); move16(); #ifdef BASOP_NOGLOB - tmp16_2 = add_o(tmp16_2, tmp16, &Overflow); + tmp16_2 = add_o( tmp16_2, tmp16, &Overflow ); #else - tmp16_2 = add(tmp16_2, tmp16); + tmp16_2 = add( tmp16_2, tmp16 ); #endif } } @@ -496,13 +488,13 @@ ivas_error evs_dec_fx( /*---------------------------------------------------------------------* * SWB CNG *---------------------------------------------------------------------*/ - IF( GE_16(output_frame,L_FRAME32k)) + IF( GE_16( output_frame, L_FRAME32k ) ) { /* SHB CNG decoder */ swb_CNG_dec_fx( st_fx, synth_fx, hb_synth_fx, sid_bw, Qpostd ); test(); - if( LE_32(st_fx->core_brate, SID_2k40)&&st_fx->bws_cnt==0) + if ( LE_32( st_fx->core_brate, SID_2k40 ) && st_fx->bws_cnt == 0 ) { hb_synth_fx_exp = 3; move16(); @@ -513,29 +505,29 @@ ivas_error evs_dec_fx( * Delay ACELP core synthesis to be synchronized with the components of bandwidth extension layers *----------------------------------------------------------------*/ - IF ( GE_16(output_frame,L_FRAME16k)) + IF( GE_16( output_frame, L_FRAME16k ) ) { - tmps = NS2SA_fx2(st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS); + tmps = NS2SA_fx2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ); - exp=s_min(Qpostd, st_fx->Qprev_synth_buffer_fx); - Scale_sig(synth_fx, output_frame, sub(exp,Qpostd)); - Qpostd=exp; + exp = s_min( Qpostd, st_fx->Qprev_synth_buffer_fx ); + Scale_sig( synth_fx, output_frame, sub( exp, Qpostd ) ); + Qpostd = exp; move16(); - Scale_sig(st_fx->prev_synth_buffer_fx, tmps, sub(exp, st_fx->Qprev_synth_buffer_fx)); - st_fx->Qprev_synth_buffer_fx=exp; + Scale_sig( st_fx->prev_synth_buffer_fx, tmps, sub( exp, st_fx->Qprev_synth_buffer_fx ) ); + st_fx->Qprev_synth_buffer_fx = exp; move16(); - Copy(synth_fx, tmp_buffer_fx, output_frame); - Copy(st_fx->prev_synth_buffer_fx, synth_fx, tmps); - Copy(tmp_buffer_fx, synth_fx + tmps, output_frame - tmps); - Copy(tmp_buffer_fx + output_frame - tmps, st_fx->prev_synth_buffer_fx, tmps); + Copy( synth_fx, tmp_buffer_fx, output_frame ); + Copy( st_fx->prev_synth_buffer_fx, synth_fx, tmps ); + Copy( tmp_buffer_fx, synth_fx + tmps, output_frame - tmps ); + Copy( tmp_buffer_fx + output_frame - tmps, st_fx->prev_synth_buffer_fx, tmps ); } ELSE { - exp=s_min(Qpostd, st_fx->Qprev_synth_buffer_fx); - Scale_sig(synth_fx, output_frame, sub(exp,Qpostd)); - Qpostd=exp; + exp = s_min( Qpostd, st_fx->Qprev_synth_buffer_fx ); + Scale_sig( synth_fx, output_frame, sub( exp, Qpostd ) ); + Qpostd = exp; move16(); - st_fx->Qprev_synth_buffer_fx=exp; + st_fx->Qprev_synth_buffer_fx = exp; move16(); } @@ -548,34 +540,27 @@ ivas_error evs_dec_fx( test(); test(); test(); - IF (EQ_16(st_fx->core,ACELP_CORE) - && !st_fx->bfi - && st_fx->prev_bfi - && GE_32(st_fx->last_total_brate, HQ_48k) - && EQ_16(st_fx->last_codec_mode, MODE2) - && (EQ_16(st_fx->last_core_bfi, TCX_20_CORE) || EQ_16(st_fx->last_core_bfi, TCX_10_CORE) ) - && st_fx->plcInfo.concealment_method == TCX_NONTONAL - && LT_32(st_fx->plcInfo.nbLostCmpt, 4) ) + IF( EQ_16( st_fx->core, ACELP_CORE ) && !st_fx->bfi && st_fx->prev_bfi && GE_32( st_fx->last_total_brate, HQ_48k ) && EQ_16( st_fx->last_codec_mode, MODE2 ) && ( EQ_16( st_fx->last_core_bfi, TCX_20_CORE ) || EQ_16( st_fx->last_core_bfi, TCX_10_CORE ) ) && st_fx->plcInfo.concealment_method == TCX_NONTONAL && LT_32( st_fx->plcInfo.nbLostCmpt, 4 ) ) { tmps = 0; - IF( GE_16(output_frame,L_FRAME16k)) + IF( GE_16( output_frame, L_FRAME16k ) ) { - tmps = NS2SA_fx2(st_fx->output_Fs, DELAY_BWE_TOTAL_NS); + tmps = NS2SA_fx2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ); } - waveform_adj2_fix(st_fx->tonalMDCTconceal.secondLastPcmOut, - synth_fx+tmps, - st_fx->plcInfo.data_noise, - &st_fx->plcInfo.outx_new_n1_fx, - &st_fx->plcInfo.nsapp_gain_fx, - &st_fx->plcInfo.nsapp_gain_n_fx, - &st_fx->plcInfo.recovery_gain, - st_fx->plcInfo.step_concealgain_fx, - st_fx->plcInfo.Pitch_fx, - st_fx->plcInfo.FrameSize, - tmps, - add(extract_l(st_fx->plcInfo.nbLostCmpt), 1), - st_fx->bfi); + waveform_adj2_fix( st_fx->tonalMDCTconceal.secondLastPcmOut, + synth_fx + tmps, + st_fx->plcInfo.data_noise, + &st_fx->plcInfo.outx_new_n1_fx, + &st_fx->plcInfo.nsapp_gain_fx, + &st_fx->plcInfo.nsapp_gain_n_fx, + &st_fx->plcInfo.recovery_gain, + st_fx->plcInfo.step_concealgain_fx, + st_fx->plcInfo.Pitch_fx, + st_fx->plcInfo.FrameSize, + tmps, + add( extract_l( st_fx->plcInfo.nbLostCmpt ), 1 ), + st_fx->bfi ); st_fx->plcInfo.Pitch_fx = 0; } @@ -585,10 +570,10 @@ ivas_error evs_dec_fx( test(); test(); - IF ( NE_16(st_fx->extl,-1)||(st_fx->bws_cnt>0&&EQ_16(st_fx->core,ACELP_CORE))) + IF( NE_16( st_fx->extl, -1 ) || ( st_fx->bws_cnt > 0 && EQ_16( st_fx->core, ACELP_CORE ) ) ) { /* Calculate an additional delay of extension layer components to be synchronized with ACELP synthesis */ - IF ( EQ_16(st_fx->L_frame,L_FRAME)) + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { /* TBE on top of ACELP@12.8kHz */ tmps = NS2SA_fx2( st_fx->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_12k8_NS ); @@ -596,7 +581,7 @@ ivas_error evs_dec_fx( ELSE { test(); - IF( EQ_16(st_fx->extl,SWB_BWE_HIGHRATE)||EQ_16(st_fx->extl,FB_BWE_HIGHRATE)) + IF( EQ_16( st_fx->extl, SWB_BWE_HIGHRATE ) || EQ_16( st_fx->extl, FB_BWE_HIGHRATE ) ) { /* HR SWB BWE on top of ACELP@16kHz */ tmps = NS2SA_fx2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ); @@ -613,70 +598,68 @@ ivas_error evs_dec_fx( test(); test(); test(); - IF ( (NE_16(st_fx->extl,st_fx->last_extl)||(EQ_16(st_fx->extl,st_fx->last_extl)&&EQ_16((st_fx->core^st_fx->last_core),HQ_CORE))) - && !(EQ_16(st_fx->extl,SWB_CNG) && EQ_16(st_fx->last_extl,SWB_TBE)) ) + IF( ( NE_16( st_fx->extl, st_fx->last_extl ) || ( EQ_16( st_fx->extl, st_fx->last_extl ) && EQ_16( ( st_fx->core ^ st_fx->last_core ), HQ_CORE ) ) ) && !( EQ_16( st_fx->extl, SWB_CNG ) && EQ_16( st_fx->last_extl, SWB_TBE ) ) ) { /*incr = (short) ( L_FRAME / (tmps + 0.5f) );*/ - incr = idiv1616(L_FRAME*2, add(shl(tmps,1),1)); + incr = idiv1616( L_FRAME * 2, add( shl( tmps, 1 ), 1 ) ); tmp16 = 0; move16(); - FOR (i=0; ihb_prev_synth_buffer_fx, 0, tmps ); } - ELSE IF ( LT_16(tmps,st_fx->old_bwe_delay)) + ELSE IF( LT_16( tmps, st_fx->old_bwe_delay ) ) { /* the previous frame was TBE on top of ACELP@16kHz and the current frame is TBE on top of ACELP@12.8kHz */ /*incr = (short) ( L_FRAME / (tmps + 0.5f) );*/ - incr = idiv1616(L_FRAME*2, add(shl(tmps,1),1)); + incr = idiv1616( L_FRAME * 2, add( shl( tmps, 1 ), 1 ) ); tmp16 = 0; move16(); - FOR (i=0; ihb_prev_synth_buffer_fx[i], sin_table256_fx[255 - tmp16]), - st_fx->hb_prev_synth_buffer_fx[st_fx->old_bwe_delay - 1 - i], sin_table256_fx[tmp16])); - tmp16 = add(tmp16, incr); + tmp_buffer_fx[i] = round_fx( L_mac( L_mult( st_fx->hb_prev_synth_buffer_fx[i], sin_table256_fx[255 - tmp16] ), + st_fx->hb_prev_synth_buffer_fx[st_fx->old_bwe_delay - 1 - i], sin_table256_fx[tmp16] ) ); + tmp16 = add( tmp16, incr ); } - Copy(tmp_buffer_fx, st_fx->hb_prev_synth_buffer_fx, tmps); + Copy( tmp_buffer_fx, st_fx->hb_prev_synth_buffer_fx, tmps ); } - ELSE IF (GT_16(tmps,st_fx->old_bwe_delay)) + ELSE IF( GT_16( tmps, st_fx->old_bwe_delay ) ) { /* the previous frame was TBE on top of ACELP@12.8kHz and the current frame is TBE on top of ACELP@16kHz */ /*incr = (short)( L_FRAME / (st->old_bwe_delay + 0.5f) );*/ - incr = idiv1616(L_FRAME*2, add(shl(st_fx->old_bwe_delay,1),1)); + incr = idiv1616( L_FRAME * 2, add( shl( st_fx->old_bwe_delay, 1 ), 1 ) ); tmp16 = 0; move16(); - FOR (i=0; iold_bwe_delay; i++) + FOR( i = 0; i < st_fx->old_bwe_delay; i++ ) { - tmp_buffer_fx[i] = mult_r(st_fx->hb_prev_synth_buffer_fx[i], sin_table256_fx[255 - tmp16]); + tmp_buffer_fx[i] = mult_r( st_fx->hb_prev_synth_buffer_fx[i], sin_table256_fx[255 - tmp16] ); move16(); - tmp16 = add(tmp16, incr); - + tmp16 = add( tmp16, incr ); } - FOR (; iold_bwe_delay; i++) + FOR( i = 0; i < st_fx->old_bwe_delay; i++ ) { /*tmp_buffer[tmps - 1 - i] += st->hb_prev_synth_buffer[st->old_bwe_delay - 1 - i] * sin_table256[i * incr];*/ - tmp_buffer_fx[tmps - 1 - i] = round_fx(L_mac(L_mult(tmp_buffer_fx[tmps - 1 - i], 32767), st_fx->hb_prev_synth_buffer_fx[st_fx->old_bwe_delay - 1 - i], sin_table256_fx[tmp16/*i * incr*/])); - tmp16 = add(tmp16, incr); + tmp_buffer_fx[tmps - 1 - i] = round_fx( L_mac( L_mult( tmp_buffer_fx[tmps - 1 - i], 32767 ), st_fx->hb_prev_synth_buffer_fx[st_fx->old_bwe_delay - 1 - i], sin_table256_fx[tmp16 /*i * incr*/] ) ); + tmp16 = add( tmp16, incr ); } Copy( tmp_buffer_fx, st_fx->hb_prev_synth_buffer_fx, tmps ); } /* Delay hb_synth */ - tmp16 = sub(hb_synth_fx_exp, hBWE_TD->prev_hb_synth_fx_exp); - IF ( tmp16 != 0 ) + tmp16 = sub( hb_synth_fx_exp, hBWE_TD->prev_hb_synth_fx_exp ); + IF( tmp16 != 0 ) { - Scale_sig(st_fx->hb_prev_synth_buffer_fx, tmps, tmp16 ); + Scale_sig( st_fx->hb_prev_synth_buffer_fx, tmps, tmp16 ); } Copy( hb_synth_fx, tmp_buffer_fx, output_frame ); Copy( st_fx->hb_prev_synth_buffer_fx, hb_synth_fx, tmps ); @@ -692,13 +675,13 @@ ivas_error evs_dec_fx( test(); test(); test(); - IF( ( st_fx->ppp_mode_dec || (EQ_16(st_fx->nelp_mode_dec,1)&&EQ_16(st_fx->bfi,1)))&&EQ_16(st_fx->L_frame,st_fx->last_L_frame)&&(st_fx->bws_cnt>1||st_fx->last_extl!=-1)) + IF( ( st_fx->ppp_mode_dec || ( EQ_16( st_fx->nelp_mode_dec, 1 ) && EQ_16( st_fx->bfi, 1 ) ) ) && EQ_16( st_fx->L_frame, st_fx->last_L_frame ) && ( st_fx->bws_cnt > 1 || st_fx->last_extl != -1 ) ) { - Copy(hBWE_TD->old_hb_synth_fx, hb_synth_fx, output_frame ); - IF(LT_16(hBWE_TD->prev_hb_synth_fx_exp, 14)) + Copy( hBWE_TD->old_hb_synth_fx, hb_synth_fx, output_frame ); + IF( LT_16( hBWE_TD->prev_hb_synth_fx_exp, 14 ) ) { - hb_synth_fx_exp = add(hBWE_TD->prev_hb_synth_fx_exp, 1); + hb_synth_fx_exp = add( hBWE_TD->prev_hb_synth_fx_exp, 1 ); } ELSE { @@ -714,37 +697,37 @@ ivas_error evs_dec_fx( /* SWB CNG/DTX - calculate SHB energy */ test(); - IF ( GE_16(output_frame, L_FRAME32k)&>_16(st_fx->extl,SWB_CNG)) + IF( GE_16( output_frame, L_FRAME32k ) && GT_16( st_fx->extl, SWB_CNG ) ) { - SWITCH (output_frame) + SWITCH( output_frame ) { - case L_FRAME8k: - tmp16 = 205; - BREAK; /*Q15*/ - case L_FRAME16k: - tmp16 = 102; - BREAK; /*Q15*/ - case L_FRAME32k: - tmp16 = 51; - BREAK; /*Q15*/ - case L_FRAME48k: - tmp16 = 34; - BREAK; /*Q15*/ + case L_FRAME8k: + tmp16 = 205; + BREAK; /*Q15*/ + case L_FRAME16k: + tmp16 = 102; + BREAK; /*Q15*/ + case L_FRAME32k: + tmp16 = 51; + BREAK; /*Q15*/ + case L_FRAME48k: + tmp16 = 34; + BREAK; /*Q15*/ } - L_tmp = L_deposit_l(1); /*Q2*hb_synth_fx_exp*/ - FOR ( i=0; ilast_shb_ener_fx = round_fx_sat(L_shl_sat(L_tmp, 10)); /*Q8*/ + st_fx->last_shb_ener_fx = round_fx_sat( L_shl_sat( L_tmp, 10 ) ); /*Q8*/ #else - st_fx->last_shb_ener_fx = round_fx(L_shl(L_tmp, 10)); /*Q8*/ + st_fx->last_shb_ener_fx = round_fx( L_shl( L_tmp, 10 ) ); /*Q8*/ #endif } } @@ -753,15 +736,13 @@ ivas_error evs_dec_fx( /* TCX-LTP Postfilter: used in MODE1 to update memories and to avoid discontinuities when the past frame was TCX */ delta = NS2SA_fx2( st_fx->output_Fs, TCXLTP_DELAY_NS ); - Scale_sig(hTcxLtpDec->tcxltp_mem_in, delta, sub(Qpostd, Qpostd_prev)); - Scale_sig(hTcxLtpDec->tcxltp_mem_out, output_frame, sub(Qpostd, Qpostd_prev)); - tcx_ltp_post(st_fx, hTcxLtpDec, ACELP_CORE, output_frame, 0, synth_fx, NULL); + Scale_sig( hTcxLtpDec->tcxltp_mem_in, delta, sub( Qpostd, Qpostd_prev ) ); + Scale_sig( hTcxLtpDec->tcxltp_mem_out, output_frame, sub( Qpostd, Qpostd_prev ) ); + tcx_ltp_post( st_fx, hTcxLtpDec, ACELP_CORE, output_frame, 0, synth_fx, NULL ); /* final output of synthesis signal */ Copy( synth_fx, output_sp, output_frame ); - - } ELSE /* MODE2 PART */ { @@ -773,17 +754,17 @@ ivas_error evs_dec_fx( concealWholeFrame = 0; move16(); - if( EQ_16(frameMode, FRAMEMODE_NORMAL)) + if ( EQ_16( frameMode, FRAMEMODE_NORMAL ) ) { st_fx->m_decodeMode = DEC_NO_FRAM_LOSS; move16(); } - IF( EQ_16(frameMode, FRAMEMODE_MISSING)) + IF( EQ_16( frameMode, FRAMEMODE_MISSING ) ) { test(); test(); - IF( st_fx->use_partial_copy && GE_16(st_fx->rf_frame_type, RF_TCXFD)&&LE_16(st_fx->rf_frame_type,RF_TCXTD2)) + IF( st_fx->use_partial_copy && GE_16( st_fx->rf_frame_type, RF_TCXFD ) && LE_16( st_fx->rf_frame_type, RF_TCXTD2 ) ) { st_fx->m_decodeMode = DEC_NO_FRAM_LOSS; move16(); @@ -797,12 +778,12 @@ ivas_error evs_dec_fx( SWITCH( st_fx->m_decodeMode ) { - case DEC_NO_FRAM_LOSS: - BREAK; - case DEC_CONCEALMENT_EXT: - concealWholeFrame = 1; - move16(); - BREAK; + case DEC_NO_FRAM_LOSS: + BREAK; + case DEC_CONCEALMENT_EXT: + concealWholeFrame = 1; + move16(); + BREAK; } @@ -810,12 +791,12 @@ ivas_error evs_dec_fx( /* DECODE CORE */ /* -------------------------------------------------------------- */ - dec_acelp_tcx_frame_fx(st_fx, &concealWholeFrame, output_sp, - st_fx->p_bpf_noise_buf, pcmbufFB, bwe_exc_extended_fx, voice_factors_fx, pitch_buf_fx); + dec_acelp_tcx_frame_fx( st_fx, &concealWholeFrame, output_sp, + st_fx->p_bpf_noise_buf, pcmbufFB, bwe_exc_extended_fx, voice_factors_fx, pitch_buf_fx ); concealWholeFrameTmp = concealWholeFrame; move16(); - if(st_fx->bfi) + if ( st_fx->bfi ) { frameMode = FRAMEMODE_MISSING; move16(); @@ -826,66 +807,66 @@ ivas_error evs_dec_fx( /* TBE interface */ test(); test(); - IF( (st_fx->bfi == 0 || st_fx->last_core == ACELP_CORE) && st_fx->core == ACELP_CORE ) + IF( ( st_fx->bfi == 0 || st_fx->last_core == ACELP_CORE ) && st_fx->core == ACELP_CORE ) { test(); test(), test(); - SWITCH (st_fx->bwidth) + SWITCH( st_fx->bwidth ) { - case WB: - st_fx->extl = WB_TBE; - move16(); - st_fx->extl_brate = WB_TBE_0k35; - move32(); - BREAK; - - case SWB: - st_fx->extl = SWB_TBE; - move16(); - st_fx->extl_brate = SWB_TBE_1k6; - move32(); - - IF ( LT_32(st_fx->total_brate, ACELP_13k20)) - { - st_fx->extl_brate = SWB_TBE_0k95; + case WB: + st_fx->extl = WB_TBE; + move16(); + st_fx->extl_brate = WB_TBE_0k35; move32(); - } - ELSE IF (GE_32(st_fx->total_brate, ACELP_24k40)) - { - st_fx->extl_brate = SWB_TBE_2k8; + BREAK; + + case SWB: + st_fx->extl = SWB_TBE; + move16(); + st_fx->extl_brate = SWB_TBE_1k6; move32(); - } - BREAK; - case FB: - st_fx->extl = FB_TBE; - move16(); - st_fx->extl_brate = FB_TBE_1k8; - move32(); - IF(GE_32(st_fx->total_brate, ACELP_24k40)) - { - st_fx->extl_brate = FB_TBE_3k0; + IF( LT_32( st_fx->total_brate, ACELP_13k20 ) ) + { + st_fx->extl_brate = SWB_TBE_0k95; + move32(); + } + ELSE IF( GE_32( st_fx->total_brate, ACELP_24k40 ) ) + { + st_fx->extl_brate = SWB_TBE_2k8; + move32(); + } + BREAK; + + case FB: + st_fx->extl = FB_TBE; + move16(); + st_fx->extl_brate = FB_TBE_1k8; move32(); - } - BREAK; + IF( GE_32( st_fx->total_brate, ACELP_24k40 ) ) + { + st_fx->extl_brate = FB_TBE_3k0; + move32(); + } + BREAK; } } ELSE { st_fx->extl = IGF_BWE; move16(); - st_fx->extl_brate = L_deposit_l(0); + st_fx->extl_brate = L_deposit_l( 0 ); } test(); test(); - if( EQ_32(st_fx->output_Fs,8000)||(EQ_32(st_fx->output_Fs, INT_FS_16k)&&EQ_16(st_fx->L_frame,L_FRAME16k))) + if ( EQ_32( st_fx->output_Fs, 8000 ) || ( EQ_32( st_fx->output_Fs, INT_FS_16k ) && EQ_16( st_fx->L_frame, L_FRAME16k ) ) ) { st_fx->extl = -1; move16(); } - st_fx->core_brate = L_sub(st_fx->total_brate, st_fx->extl_brate); + st_fx->core_brate = L_sub( st_fx->total_brate, st_fx->extl_brate ); st_fx->bws_cnt = 0; move16(); @@ -894,24 +875,24 @@ ivas_error evs_dec_fx( st_fx->tilt_wb_fx = 0; move16(); - IF( EQ_16(st_fx->m_frame_type, ACTIVE_FRAME)) + IF( EQ_16( st_fx->m_frame_type, ACTIVE_FRAME ) ) { test(); test(); IF( ( st_fx->bfi == 0 || st_fx->last_core == ACELP_CORE ) && st_fx->core == ACELP_CORE ) { test(); - IF( EQ_16(st_fx->extl, WB_TBE)) + IF( EQ_16( st_fx->extl, WB_TBE ) ) { wb_tbe_dec_fx( st_fx, st_fx->coder_type, bwe_exc_extended_fx, st_fx->Q_exc, voice_factors_fx, hb_synth_fx, &hb_synth_fx_exp ); } - ELSE IF( EQ_16(st_fx->extl, SWB_TBE)||EQ_16(st_fx->extl,FB_TBE)) + ELSE IF( EQ_16( st_fx->extl, SWB_TBE ) || EQ_16( st_fx->extl, FB_TBE ) ) { /* SWB TBE decoder */ swb_tbe_dec_fx( st_fx, st_fx->coder_type, bwe_exc_extended_fx, st_fx->Q_exc, voice_factors_fx, hBWE_TD->old_core_synth_fx, fb_exc_fx, &Q_fb_exc, hb_synth_fx, &hb_synth_fx_exp, pitch_buf_fx ); test(); - IF( EQ_16(st_fx->extl, FB_TBE)&&EQ_16(output_frame,L_FRAME48k)) + IF( EQ_16( st_fx->extl, FB_TBE ) && EQ_16( output_frame, L_FRAME48k ) ) { fb_tbe_dec_fx( st_fx, fb_exc_fx, Q_fb_exc, hb_synth_fx, hb_synth_fx_exp ); } @@ -920,26 +901,26 @@ ivas_error evs_dec_fx( } ELSE { - IF( EQ_16(st_fx->last_core,ACELP_CORE)) + IF( EQ_16( st_fx->last_core, ACELP_CORE ) ) { test(); test(); test(); test(); - IF( ( EQ_16(st_fx->bwidth, SWB)||EQ_16(st_fx->bwidth,FB))&& - (( EQ_16(st_fx->last_extl, SWB_TBE) || EQ_16(st_fx->last_extl, FB_TBE) ) && EQ_16(st_fx->last_codec_mode, MODE2) ) ) + IF( ( EQ_16( st_fx->bwidth, SWB ) || EQ_16( st_fx->bwidth, FB ) ) && + ( ( EQ_16( st_fx->last_extl, SWB_TBE ) || EQ_16( st_fx->last_extl, FB_TBE ) ) && EQ_16( st_fx->last_codec_mode, MODE2 ) ) ) { - GenTransition_fx(hBWE_TD->syn_overlap_fx, hBWE_TD->old_tbe_synth_fx, 2*NS2SA(st_fx->output_Fs, DELAY_BWE_TOTAL_NS), hb_synth_fx, + GenTransition_fx( hBWE_TD->syn_overlap_fx, hBWE_TD->old_tbe_synth_fx, 2 * NS2SA( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ), hb_synth_fx, hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, - hBWE_TD->mem_resamp_HB_32k_fx, - &(hBWE_TD->syn_dm_phase), st_fx->output_Fs, hBWE_TD->int_3_over_2_tbemem_dec_fx, st_fx->rf_flag, st_fx->total_brate ); + hBWE_TD->mem_resamp_HB_32k_fx, + &( hBWE_TD->syn_dm_phase ), st_fx->output_Fs, hBWE_TD->int_3_over_2_tbemem_dec_fx, st_fx->rf_flag, st_fx->total_brate ); hb_synth_fx_exp = st_fx->prev_Q_bwe_syn2; move16(); } - ELSE IF ( st_fx->bwidth == WB && st_fx->last_extl == WB_TBE ) + ELSE IF( st_fx->bwidth == WB && st_fx->last_extl == WB_TBE ) { - GenTransition_WB_fx(hBWE_TD->syn_overlap_fx, hBWE_TD->old_tbe_synth_fx, st_fx->prev_Qx, 2*NS2SA(st_fx->output_Fs, DELAY_BWE_TOTAL_NS), hb_synth_fx, + GenTransition_WB_fx( hBWE_TD->syn_overlap_fx, hBWE_TD->old_tbe_synth_fx, st_fx->prev_Qx, 2 * NS2SA( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ), hb_synth_fx, hBWE_TD->state_lsyn_filt_shb_fx, hBWE_TD->state_lsyn_filt_dwn_shb_fx, st_fx->output_Fs, hBWE_TD->mem_resamp_HB_fx ); hb_synth_fx_exp = st_fx->prev_Qx; @@ -948,27 +929,27 @@ ivas_error evs_dec_fx( TBEreset_dec_fx( st_fx, st_fx->bwidth ); } - ELSE IF ( EQ_16(st_fx->last_codec_mode,MODE1)) + ELSE IF( EQ_16( st_fx->last_codec_mode, MODE1 ) ) { - swb_tbe_reset_fx(hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, - hBWE_TD->syn_overlap_fx, hBWE_TD->state_syn_shbexc_fx, &(hBWE_TD->tbe_demph_fx), &(hBWE_TD->tbe_premph_fx), hBWE_TD->mem_stp_swb_fx, &(hBWE_TD->gain_prec_swb_fx) ); - IF( EQ_16(st_fx->extl, FB_TBE)) + swb_tbe_reset_fx( hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, + hBWE_TD->syn_overlap_fx, hBWE_TD->state_syn_shbexc_fx, &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), hBWE_TD->mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ) ); + IF( EQ_16( st_fx->extl, FB_TBE ) ) { - set16_fx(hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); + set16_fx( hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); hBWE_TD->fb_tbe_demph_fx = 0; - fb_tbe_reset_synth_fx(hBWE_TD->fbbwe_hpf_mem_fx, hBWE_TD->fbbwe_hpf_mem_fx_Q,&hBWE_TD->prev_fbbwe_ratio_fx ); + fb_tbe_reset_synth_fx( hBWE_TD->fbbwe_hpf_mem_fx, hBWE_TD->fbbwe_hpf_mem_fx_Q, &hBWE_TD->prev_fbbwe_ratio_fx ); } - swb_tbe_reset_synth_fx(hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx ); + swb_tbe_reset_synth_fx( hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx ); } } } } - IF( NE_16(st_fx->m_frame_type,ACTIVE_FRAME)) + IF( NE_16( st_fx->m_frame_type, ACTIVE_FRAME ) ) { st_fx->extl = -1; move16(); - st_fx->extl_brate = L_deposit_l(0); + st_fx->extl_brate = L_deposit_l( 0 ); } /* -------------------------------------------------------------- */ @@ -977,7 +958,7 @@ ivas_error evs_dec_fx( { nab = s_min( st_fx->cldfbAna->no_channels, st_fx->cldfbSyn->no_channels ); - st_fx->cldfbSyn->lsb = s_min(st_fx->cldfbAna->no_channels, st_fx->cldfbSyn->no_channels); + st_fx->cldfbSyn->lsb = s_min( st_fx->cldfbAna->no_channels, st_fx->cldfbSyn->no_channels ); move16(); st_fx->cldfbSyn->usb = st_fx->cldfbSyn->no_channels; move16(); @@ -990,7 +971,7 @@ ivas_error evs_dec_fx( test(); test(); test(); - IF ( st_fx->hFdCngDec != NULL && (EQ_32(st_fx->sr_core,8000)||EQ_32(st_fx->sr_core, INT_FS_12k8)||EQ_32(st_fx->sr_core, INT_FS_16k))&&LE_32(st_fx->total_brate,ACELP_32k)) + IF( st_fx->hFdCngDec != NULL && ( EQ_32( st_fx->sr_core, 8000 ) || EQ_32( st_fx->sr_core, INT_FS_12k8 ) || EQ_32( st_fx->sr_core, INT_FS_16k ) ) && LE_32( st_fx->total_brate, ACELP_32k ) ) { /*************************************** In CLDFB domain: @@ -999,28 +980,27 @@ ivas_error evs_dec_fx( ****************************************/ HANDLE_FD_CNG_DEC hFdCngDec = st_fx->hFdCngDec; move16(); - noisy_speech_detection_fx(st_fx->hFdCngDec, st_fx->VAD && st_fx->m_frame_type == ACTIVE_FRAME, output_sp, 0); + noisy_speech_detection_fx( st_fx->hFdCngDec, st_fx->VAD && st_fx->m_frame_type == ACTIVE_FRAME, output_sp, 0 ); - hFdCngDec->hFdCngCom->likelihood_noisy_speech = mult_r(hFdCngDec->hFdCngCom->likelihood_noisy_speech, 32440/*0.99 Q15*/); - IF ( hFdCngDec->hFdCngCom->flag_noisy_speech != 0 ) + hFdCngDec->hFdCngCom->likelihood_noisy_speech = mult_r( hFdCngDec->hFdCngCom->likelihood_noisy_speech, 32440 /*0.99 Q15*/ ); + IF( hFdCngDec->hFdCngCom->flag_noisy_speech != 0 ) { - hFdCngDec->hFdCngCom->likelihood_noisy_speech = add(hFdCngDec->hFdCngCom->likelihood_noisy_speech, 328/*0.01 Q15*/); + hFdCngDec->hFdCngCom->likelihood_noisy_speech = add( hFdCngDec->hFdCngCom->likelihood_noisy_speech, 328 /*0.01 Q15*/ ); move16(); } st_fx->lp_noise = hFdCngDec->lp_noise; move32(); #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - ApplyFdCng_fx(output, NULL, realBuffer, imagBuffer, st, concealWholeFrame, 0); + ApplyFdCng_fx( output, NULL, realBuffer, imagBuffer, st, concealWholeFrame, 0 ); #else - ApplyFdCng_fx( output_sp, 0, realBuffer, imagBuffer, &st_fx->scaleFactor.hb_scale, st_fx, concealWholeFrame, 0); + ApplyFdCng_fx( output_sp, 0, realBuffer, imagBuffer, &st_fx->scaleFactor.hb_scale, st_fx, concealWholeFrame, 0 ); #endif /* Generate additional comfort noise to mask potential coding artefacts */ test(); - IF( EQ_16(st_fx->m_frame_type,ACTIVE_FRAME)&&st_fx->flag_cna) + IF( EQ_16( st_fx->m_frame_type, ACTIVE_FRAME ) && st_fx->flag_cna ) { generate_masking_noise_fx( output_sp, 0, hFdCngDec->hFdCngCom, hFdCngDec->hFdCngCom->frameSize, 0 ); } - } test(); @@ -1029,26 +1009,25 @@ ivas_error evs_dec_fx( test(); test(); test(); - IF( st_fx->flag_cna == 0 && EQ_16(st_fx->L_frame,L_FRAME16k)&&EQ_16(st_fx->last_flag_cna,1) - && ( (st_fx->last_core == ACELP_CORE && NE_16(st_fx->last_coder_type,AUDIO) ) || EQ_16(st_fx->last_core,TCX_20_CORE) || EQ_16(st_fx->last_core,AMR_WB_CORE) ) ) + IF( st_fx->flag_cna == 0 && EQ_16( st_fx->L_frame, L_FRAME16k ) && EQ_16( st_fx->last_flag_cna, 1 ) && ( ( st_fx->last_core == ACELP_CORE && NE_16( st_fx->last_coder_type, AUDIO ) ) || EQ_16( st_fx->last_core, TCX_20_CORE ) || EQ_16( st_fx->last_core, AMR_WB_CORE ) ) ) { - FOR (i=0; i < st_fx->L_frame/2; i++) + FOR( i = 0; i < st_fx->L_frame / 2; i++ ) { #ifdef BASOP_NOGLOB output_sp[i] = add_sat( output_sp[i], st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * st_fx->L_frame / 4] ); #else - output_sp[i] = add( output_sp[i], st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[i+5*st_fx->L_frame/4] ); + output_sp[i] = add( output_sp[i], st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * st_fx->L_frame / 4] ); #endif move16(); } } - IF( EQ_16(st_fx->m_frame_type,ACTIVE_FRAME)) + IF( EQ_16( st_fx->m_frame_type, ACTIVE_FRAME ) ) { - timeIn_e = s_max(0, sub(getScaleFactor16( output_sp, st_fx->L_frame ), 3)); - IF( NE_16(st_fx->core,ACELP_CORE)) + timeIn_e = s_max( 0, sub( getScaleFactor16( output_sp, st_fx->L_frame ), 3 ) ); + IF( NE_16( st_fx->core, ACELP_CORE ) ) { - timeIn_e = s_max(0, s_min(sub(getScaleFactor16( pcmbufFB, hTcxDec->L_frameTCX ), 3),timeIn_e)); + timeIn_e = s_max( 0, s_min( sub( getScaleFactor16( pcmbufFB, hTcxDec->L_frameTCX ), 3 ), timeIn_e ) ); } Scale_sig( output_sp, st_fx->L_frame, timeIn_e ); timeIn_e = negate( timeIn_e ); @@ -1059,10 +1038,10 @@ ivas_error evs_dec_fx( ELSE { Word16 timeDomainBuffer[L_FRAME16k]; - Word16 A[M+1]; + Word16 A[M + 1]; Copy( st_fx->hFdCngDec->hFdCngCom->timeDomainBuffer, timeDomainBuffer, st_fx->L_frame ); - Copy( st_fx->hFdCngDec->hFdCngCom->A_cng, A, M+1 ); + Copy( st_fx->hFdCngDec->hFdCngCom->A_cng, A, M + 1 ); update_decoder_LPD_cng( st_fx, st_fx->coder_type, timeDomainBuffer, A, st_fx->p_bpf_noise_buf ); /* Generate additional comfort noise to mask potential coding artefacts */ @@ -1070,18 +1049,18 @@ ivas_error evs_dec_fx( { generate_masking_noise_fx( timeDomainBuffer, 0, st_fx->hFdCngDec->hFdCngCom, st_fx->hFdCngDec->hFdCngCom->frameSize, 0 ); } - ELSE IF( EQ_16(st_fx->L_frame,L_FRAME16k)&&EQ_16(st_fx->last_flag_cna,1)&&((EQ_16(st_fx->last_core,ACELP_CORE)&&NE_16(st_fx->last_coder_type,AUDIO))||EQ_16(st_fx->last_core,TCX_20_CORE)||EQ_16(st_fx->last_core,AMR_WB_CORE))) + ELSE IF( EQ_16( st_fx->L_frame, L_FRAME16k ) && EQ_16( st_fx->last_flag_cna, 1 ) && ( ( EQ_16( st_fx->last_core, ACELP_CORE ) && NE_16( st_fx->last_coder_type, AUDIO ) ) || EQ_16( st_fx->last_core, TCX_20_CORE ) || EQ_16( st_fx->last_core, AMR_WB_CORE ) ) ) { - FOR( i=0; i < st_fx->L_frame/2; i++ ) + FOR( i = 0; i < st_fx->L_frame / 2; i++ ) { - timeDomainBuffer[i] = add( timeDomainBuffer[i], st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[i+5*st_fx->L_frame/4] ); + timeDomainBuffer[i] = add( timeDomainBuffer[i], st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * st_fx->L_frame / 4] ); move16(); } } /* check if the CLDFB works on the right sample rate */ - IF( NE_16((st_fx->cldfbAna->no_channels * st_fx->cldfbAna->no_col),st_fx->L_frame)) + IF( NE_16( ( st_fx->cldfbAna->no_channels * st_fx->cldfbAna->no_col ), st_fx->L_frame ) ) { - Word16 newCldfbBands = CLDFB_getNumChannels(L_mult0(st_fx->L_frame, 50)); + Word16 newCldfbBands = CLDFB_getNumChannels( L_mult0( st_fx->L_frame, 50 ) ); resampleCldfb( st_fx->cldfbAna, newCldfbBands, st_fx->L_frame, 0 ); resampleCldfb( st_fx->cldfbBPF, newCldfbBands, st_fx->L_frame, 0 ); @@ -1090,28 +1069,28 @@ ivas_error evs_dec_fx( st_fx->cldfbSyn->bandsToZero = 0; move16(); test(); - IF ( EQ_16( st_fx->bwidth, NB )&>_16(st_fx->cldfbSyn->no_channels,10)) + IF( EQ_16( st_fx->bwidth, NB ) && GT_16( st_fx->cldfbSyn->no_channels, 10 ) ) { st_fx->cldfbSyn->bandsToZero = sub( st_fx->cldfbSyn->no_channels, 10 ); } - ELSE IF ( st_fx->hFdCngDec->hFdCngCom->regularStopBand < st_fx->cldfbSyn->no_channels ) + ELSE IF( st_fx->hFdCngDec->hFdCngCom->regularStopBand < st_fx->cldfbSyn->no_channels ) { st_fx->cldfbSyn->bandsToZero = st_fx->cldfbSyn->no_channels - st_fx->hFdCngDec->hFdCngCom->regularStopBand; } timeIn_e = 2; move16(); - Scale_sig(timeDomainBuffer, st_fx->L_frame, timeIn_e); - IF ( st_fx->p_bpf_noise_buf ) + Scale_sig( timeDomainBuffer, st_fx->L_frame, timeIn_e ); + IF( st_fx->p_bpf_noise_buf ) { - Scale_sig(st_fx->p_bpf_noise_buf, st_fx->L_frame, timeIn_e); + Scale_sig( st_fx->p_bpf_noise_buf, st_fx->L_frame, timeIn_e ); } - timeIn_e = negate(timeIn_e); - cldfbAnalysisFiltering( st_fx->cldfbAna, realBuffer, imagBuffer, &st_fx->scaleFactor, timeDomainBuffer, timeIn_e, CLDFB_NO_COL_MAX, workBuffer) ; + timeIn_e = negate( timeIn_e ); + cldfbAnalysisFiltering( st_fx->cldfbAna, realBuffer, imagBuffer, &st_fx->scaleFactor, timeDomainBuffer, timeIn_e, CLDFB_NO_COL_MAX, workBuffer ); } - if( st_fx->flag_cna == 0 ) + if ( st_fx->flag_cna == 0 ) { set16_fx( st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, st_fx->hFdCngDec->hFdCngCom->fftlen ); } @@ -1120,104 +1099,103 @@ ivas_error evs_dec_fx( { Word16 timeInBpf_e = timeIn_e; move16(); - if( EQ_16(st_fx->m_frame_type,ACTIVE_FRAME)) + if ( EQ_16( st_fx->m_frame_type, ACTIVE_FRAME ) ) { timeInBpf_e = 0; move16(); } addBassPostFilter_fx( st_fx->p_bpf_noise_buf, realBuffer, imagBuffer, st_fx->cldfbBPF, workBuffer, - timeInBpf_e, CLDFB_NO_COL_MAX, st_fx->cldfbAna->no_col, st_fx->cldfbAna->no_channels, &st_fx->scaleFactor ); + timeInBpf_e, CLDFB_NO_COL_MAX, st_fx->cldfbAna->no_col, st_fx->cldfbAna->no_channels, &st_fx->scaleFactor ); - IF( NE_16(st_fx->m_frame_type,ACTIVE_FRAME)) + IF( NE_16( st_fx->m_frame_type, ACTIVE_FRAME ) ) { - Scale_sig(st_fx->p_bpf_noise_buf, st_fx->L_frame, timeIn_e); + Scale_sig( st_fx->p_bpf_noise_buf, st_fx->L_frame, timeIn_e ); } - } - IF (GT_32(st_fx->output_Fs, 8000)) + IF( GT_32( st_fx->output_Fs, 8000 ) ) { - st_fx->hTECDec->cldfbExp = add(15, st_fx->scaleFactor.lb_scale); + st_fx->hTECDec->cldfbExp = add( 15, st_fx->scaleFactor.lb_scale ); calcGainTemp_TBE_Fx( realBuffer, imagBuffer, st_fx->hTECDec->cldfbExp, st_fx->hTECDec->loBuffer, - 0, /*startPos,*//*!< Start position of the current envelope. */ - st_fx->cldfbAna->no_col, /*stopPos,*/ /*!< Stop position of the current envelope. */ + 0, /*startPos,*/ /*!< Start position of the current envelope. */ + st_fx->cldfbAna->no_col, + /*stopPos,*/ /*!< Stop position of the current envelope. */ st_fx->cldfbAna->no_channels, /*lowSubband*/ - st_fx->hTECDec->pGainTemp_m, st_fx->hTECDec->pGainTemp_e, st_fx->tec_flag - ); + st_fx->hTECDec->pGainTemp_m, st_fx->hTECDec->pGainTemp_e, st_fx->tec_flag ); } /* set high band buffers to zero. Covering the current frame and the overlap area. */ - IF( EQ_16(st_fx->m_frame_type,ACTIVE_FRAME)) + IF( EQ_16( st_fx->m_frame_type, ACTIVE_FRAME ) ) { FOR( i = 0; i < 16; i++ ) { - set32_fx( &realBuffer[i][nab], 0, sub(st_fx->cldfbSyn->no_channels,nab) ); - set32_fx( &imagBuffer[i][nab], 0, sub(st_fx->cldfbSyn->no_channels,nab) ); + set32_fx( &realBuffer[i][nab], 0, sub( st_fx->cldfbSyn->no_channels, nab ) ); + set32_fx( &imagBuffer[i][nab], 0, sub( st_fx->cldfbSyn->no_channels, nab ) ); } } - timeIn_e = s_min(0, add(timeIn_e, 2)); - cldfbSynthesisFiltering(st_fx->cldfbSyn, realBuffer, imagBuffer, &st_fx->scaleFactor, output_sp, timeIn_e, CLDFB_NO_COL_MAX, workBuffer ); + timeIn_e = s_min( 0, add( timeIn_e, 2 ) ); + cldfbSynthesisFiltering( st_fx->cldfbSyn, realBuffer, imagBuffer, &st_fx->scaleFactor, output_sp, timeIn_e, CLDFB_NO_COL_MAX, workBuffer ); /*CLDFB output always in timeIn_e*/ /* MODE1 MDCT to ACELP 2 transition */ - delay_comp = NS2SA_fx2(st_fx->output_Fs, DELAY_CLDFB_NS); - Scale_sig(st_fx->delay_buf_out_fx, delay_comp, negate(hHQ_core->Q_old_postdec)); + delay_comp = NS2SA_fx2( st_fx->output_Fs, DELAY_CLDFB_NS ); + Scale_sig( st_fx->delay_buf_out_fx, delay_comp, negate( hHQ_core->Q_old_postdec ) ); hHQ_core->Q_old_postdec = 0; move16(); - delay_tdbwe= NS2SA_fx2(st_fx->output_Fs, DELAY_BWE_TOTAL_NS- DELAY_CLDFB_NS); - IF( GE_16(output_frame,L_FRAME16k)) + delay_tdbwe = NS2SA_fx2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ); + IF( GE_16( output_frame, L_FRAME16k ) ) { - Scale_sig(st_fx->prev_synth_buffer_fx, delay_tdbwe, sub(Qpostd, st_fx->Qprev_synth_buffer_fx)); + Scale_sig( st_fx->prev_synth_buffer_fx, delay_tdbwe, sub( Qpostd, st_fx->Qprev_synth_buffer_fx ) ); } test(); - IF( EQ_16(st_fx->last_codec_mode,MODE1)&>_16(st_fx->last_core_bfi,ACELP_CORE)) + IF( EQ_16( st_fx->last_codec_mode, MODE1 ) && GT_16( st_fx->last_core_bfi, ACELP_CORE ) ) { - Copy_Scale_sig( st_fx->delay_buf_out_fx, output_sp, delay_comp, negate(timeIn_e) ); /* copy the HQ/ACELP delay synchronization buffer at the beginning of ACELP frame */ - IF( EQ_16(st_fx->core,ACELP_CORE)) + Copy_Scale_sig( st_fx->delay_buf_out_fx, output_sp, delay_comp, negate( timeIn_e ) ); /* copy the HQ/ACELP delay synchronization buffer at the beginning of ACELP frame */ + IF( EQ_16( st_fx->core, ACELP_CORE ) ) { Word16 step, alpha, nz; i = 15; move16(); - tmps = NS2SA_fx2(st_fx->output_Fs, 3000000L); - nz = NS2SA_fx2(st_fx->output_Fs, N_ZERO_MDCT_NS); - step = Inv16(tmps, &i); - step = shl(step, i); + tmps = NS2SA_fx2( st_fx->output_Fs, 3000000L ); + nz = NS2SA_fx2( st_fx->output_Fs, N_ZERO_MDCT_NS ); + step = Inv16( tmps, &i ); + step = shl( step, i ); alpha = 0; move16(); test(); IF( st_fx->prev_bfi && hHQ_core->HqVoicing ) { - Copy(hHQ_core->fer_samples_fx, &hHQ_core->old_out_fx[nz], tmps); + Copy( hHQ_core->fer_samples_fx, &hHQ_core->old_out_fx[nz], tmps ); } ELSE { - Scale_sig(hHQ_core->old_out_fx, nz+tmps, negate(hHQ_core->Q_old_wtda)); + Scale_sig( hHQ_core->old_out_fx, nz + tmps, negate( hHQ_core->Q_old_wtda ) ); } hHQ_core->Q_old_wtda = 0; move16(); - FOR (i = 0; i < tmps; i++) + FOR( i = 0; i < tmps; i++ ) { #ifdef BASOP_NOGLOB output_sp[i + delay_comp] = msu_r_sat( L_mult_sat( output_sp[i + delay_comp], alpha ), shr( hHQ_core->old_out_fx[i + nz], timeIn_e ), add( alpha, -32768 ) ); #else - output_sp[i+delay_comp] = msu_r(L_mult(output_sp[i+delay_comp], alpha), shr(hHQ_core->old_out_fx[i+nz], timeIn_e), add(alpha, -32768)); + output_sp[i + delay_comp] = msu_r( L_mult( output_sp[i + delay_comp], alpha ), shr( hHQ_core->old_out_fx[i + nz], timeIn_e ), add( alpha, -32768 ) ); #endif move16(); - alpha = add(alpha, step); + alpha = add( alpha, step ); } } ELSE { - IF( EQ_32(st_fx->output_Fs,8000)) + IF( EQ_32( st_fx->output_Fs, 8000 ) ) { - Copy(st_fx->delay_buf_out_fx, hTcxDec->FBTCXdelayBuf, delay_comp); + Copy( st_fx->delay_buf_out_fx, hTcxDec->FBTCXdelayBuf, delay_comp ); } ELSE { @@ -1229,54 +1207,54 @@ ivas_error evs_dec_fx( /* set delay compensation between HQ synthesis and ACELP synthesis */ test(); - IF( EQ_16(st_fx->core,ACELP_CORE)&&!(st_fx->con_tcx)) + IF( EQ_16( st_fx->core, ACELP_CORE ) && !( st_fx->con_tcx ) ) { set16_fx( st_fx->delay_buf_out_fx, 0, delay_comp ); Copy_Scale_sig( output_sp, st_fx->previoussynth_fx, output_frame, timeIn_e ); } ELSE { - Copy(hTcxDec->old_synthFB_fx+ hTcxDec->old_synth_lenFB-delay_comp, st_fx->delay_buf_out_fx, delay_comp ); - IF( EQ_32(st_fx->output_Fs, 8000)) + Copy( hTcxDec->old_synthFB_fx + hTcxDec->old_synth_lenFB - delay_comp, st_fx->delay_buf_out_fx, delay_comp ); + IF( EQ_32( st_fx->output_Fs, 8000 ) ) { - Copy(hTcxDec->FBTCXdelayBuf, st_fx->previoussynth_fx, delay_comp); + Copy( hTcxDec->FBTCXdelayBuf, st_fx->previoussynth_fx, delay_comp ); } ELSE { - Copy(hTcxDec->FBTCXdelayBuf + delay_tdbwe, st_fx->previoussynth_fx, delay_comp ); + Copy( hTcxDec->FBTCXdelayBuf + delay_tdbwe, st_fx->previoussynth_fx, delay_comp ); } - Copy(pcmbufFB, st_fx->previoussynth_fx + delay_comp, sub(output_frame, delay_comp)); + Copy( pcmbufFB, st_fx->previoussynth_fx + delay_comp, sub( output_frame, delay_comp ) ); } } /* Delay compensation for TD-BWE*/ - IF( GE_16(output_frame,L_FRAME16k)) + IF( GE_16( output_frame, L_FRAME16k ) ) { Copy( output_sp, tmp_buffer_fx, output_frame ); - Copy_Scale_sig( st_fx->prev_synth_buffer_fx, output_sp, delay_tdbwe, negate(timeIn_e) ); + Copy_Scale_sig( st_fx->prev_synth_buffer_fx, output_sp, delay_tdbwe, negate( timeIn_e ) ); Copy( tmp_buffer_fx, output_sp + delay_tdbwe, output_frame - delay_tdbwe ); - Copy_Scale_sig( tmp_buffer_fx + output_frame - delay_tdbwe, st_fx->prev_synth_buffer_fx, delay_tdbwe, timeIn_e); + Copy_Scale_sig( tmp_buffer_fx + output_frame - delay_tdbwe, st_fx->prev_synth_buffer_fx, delay_tdbwe, timeIn_e ); } test(); - IF( st_fx->igf != 0 && EQ_16( st_fx->m_frame_type, ACTIVE_FRAME )) + IF( st_fx->igf != 0 && EQ_16( st_fx->m_frame_type, ACTIVE_FRAME ) ) { test(); test(); test(); test(); - IF( st_fx->bfi == 0 && EQ_16(st_fx->core, ACELP_CORE)&&(st_fx->tec_flag!=0||st_fx->tfa_flag!=0)&>_32(st_fx->output_Fs,8000) /*&& st_fx->hTECDec_fx != NULL*/) + IF( st_fx->bfi == 0 && EQ_16( st_fx->core, ACELP_CORE ) && ( st_fx->tec_flag != 0 || st_fx->tfa_flag != 0 ) && GT_32( st_fx->output_Fs, 8000 ) /*&& st_fx->hTECDec_fx != NULL*/ ) { tmp16 = 0; move16(); - if (EQ_16(st_fx->tec_flag, 2)) + if ( EQ_16( st_fx->tec_flag, 2 ) ) { tmp16 = 1; move16(); } hb_synth_fx_exp = procTecTfa_TBE_Fx( hb_synth_fx, hb_synth_fx_exp, st_fx->hTECDec->pGainTemp_m, st_fx->hTECDec->pGainTemp_e, - st_fx->tfa_flag, st_fx->last_core, shr(output_frame, 4 ), tmp16 ); + st_fx->tfa_flag, st_fx->last_core, shr( output_frame, 4 ), tmp16 ); } test(); @@ -1285,38 +1263,38 @@ ivas_error evs_dec_fx( test(); test(); test(); - IF( (( ( st_fx->bfi == 0 || st_fx->last_core == ACELP_CORE ) && st_fx->core == ACELP_CORE ) || - ( ( EQ_16(st_fx->last_core, ACELP_CORE) ) && (NE_16(st_fx->bwidth, NB) && EQ_16(st_fx->last_codec_mode, MODE2) ) )) - && (GT_32( st_fx->output_Fs, 8000 ) ) ) + IF( ( ( ( st_fx->bfi == 0 || st_fx->last_core == ACELP_CORE ) && st_fx->core == ACELP_CORE ) || + ( ( EQ_16( st_fx->last_core, ACELP_CORE ) ) && ( NE_16( st_fx->bwidth, NB ) && EQ_16( st_fx->last_codec_mode, MODE2 ) ) ) ) && + ( GT_32( st_fx->output_Fs, 8000 ) ) ) { - add_vec_fx( output_sp, negate(timeIn_e), hb_synth_fx, hb_synth_fx_exp, output_sp, negate(timeIn_e), output_frame ); + add_vec_fx( output_sp, negate( timeIn_e ), hb_synth_fx, hb_synth_fx_exp, output_sp, negate( timeIn_e ), output_frame ); } } - IF( EQ_32( st_fx->output_Fs, 8000 )) + IF( EQ_32( st_fx->output_Fs, 8000 ) ) { - tmps = NS2SA_fx2(st_fx->output_Fs, DELAY_CLDFB_NS ); + tmps = NS2SA_fx2( st_fx->output_Fs, DELAY_CLDFB_NS ); } ELSE { - tmps = NS2SA_fx2(st_fx->output_Fs, DELAY_BWE_TOTAL_NS ); + tmps = NS2SA_fx2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ); } delta = NS2SA_fx2( st_fx->output_Fs, TCXLTP_DELAY_NS ); test(); test(); test(); - IF ( (st_fx->bfi && GT_16(st_fx->last_core, ACELP_CORE))||GT_16(st_fx->core,ACELP_CORE)) + IF( ( st_fx->bfi && GT_16( st_fx->last_core, ACELP_CORE ) ) || GT_16( st_fx->core, ACELP_CORE ) ) { test(); test(); test(); test(); - IF ( GT_16(st_fx->last_core_bfi, ACELP_CORE)||(st_fx->bfi&&st_fx->last_core>ACELP_CORE)||(st_fx->prev_bfi&&st_fx->last_con_tcx)) + IF( GT_16( st_fx->last_core_bfi, ACELP_CORE ) || ( st_fx->bfi && st_fx->last_core > ACELP_CORE ) || ( st_fx->prev_bfi && st_fx->last_con_tcx ) ) { - Copy_Scale_sig(hTcxDec->FBTCXdelayBuf, output_sp, tmps, negate(timeIn_e)); - Copy_Scale_sig(pcmbufFB, output_sp + tmps, sub(hTcxDec->L_frameTCX, tmps), negate(timeIn_e)); + Copy_Scale_sig( hTcxDec->FBTCXdelayBuf, output_sp, tmps, negate( timeIn_e ) ); + Copy_Scale_sig( pcmbufFB, output_sp + tmps, sub( hTcxDec->L_frameTCX, tmps ), negate( timeIn_e ) ); } ELSE { @@ -1324,114 +1302,114 @@ ivas_error evs_dec_fx( i = 15; move16(); - step = Inv16(tmps, &i); - step = shl(step, i); + step = Inv16( tmps, &i ); + step = shl( step, i ); alpha = 0; move16(); - FOR (i = 0; i < tmps; i++) + FOR( i = 0; i < tmps; i++ ) { #ifdef BASOP_NOGLOB output_sp[i + tmps] = msu_r_sat( L_mult_sat( shr( pcmbufFB[i], timeIn_e ), alpha ), output_sp[i + tmps], add( alpha, -32768 ) ); #else - output_sp[i+tmps] = msu_r(L_mult(shr(pcmbufFB[i], timeIn_e), alpha), output_sp[i+tmps], add(alpha, -32768)); + output_sp[i + tmps] = msu_r( L_mult( shr( pcmbufFB[i], timeIn_e ), alpha ), output_sp[i + tmps], add( alpha, -32768 ) ); #endif move16(); - alpha = add(alpha, step); + alpha = add( alpha, step ); } - Copy_Scale_sig( pcmbufFB + tmps, output_sp + shl(tmps,1), sub(hTcxDec->L_frameTCX, shl(tmps,1)), negate(timeIn_e) ); + Copy_Scale_sig( pcmbufFB + tmps, output_sp + shl( tmps, 1 ), sub( hTcxDec->L_frameTCX, shl( tmps, 1 ) ), negate( timeIn_e ) ); } Copy( pcmbufFB + hTcxDec->L_frameTCX - tmps, hTcxDec->FBTCXdelayBuf, tmps ); test(); - IF( st_fx->bfi && GT_16(st_fx->last_core, ACELP_CORE)) + IF( st_fx->bfi && GT_16( st_fx->last_core, ACELP_CORE ) ) { - IF( EQ_32(st_fx->output_Fs, 8000)) + IF( EQ_32( st_fx->output_Fs, 8000 ) ) { - Copy(hTcxDec->FBTCXdelayBuf, st_fx->delay_buf_out_fx, NS2SA(st_fx->output_Fs, DELAY_CLDFB_NS)); + Copy( hTcxDec->FBTCXdelayBuf, st_fx->delay_buf_out_fx, NS2SA( st_fx->output_Fs, DELAY_CLDFB_NS ) ); } ELSE { - Copy(hTcxDec->FBTCXdelayBuf, st_fx->prev_synth_buffer_fx, NS2SA(st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS) ); - Copy(hTcxDec->FBTCXdelayBuf + NS2SA(st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS), st_fx->delay_buf_out_fx, NS2SA(st_fx->output_Fs, DELAY_CLDFB_NS) ); + Copy( hTcxDec->FBTCXdelayBuf, st_fx->prev_synth_buffer_fx, NS2SA( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) ); + Copy( hTcxDec->FBTCXdelayBuf + NS2SA( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), st_fx->delay_buf_out_fx, NS2SA( st_fx->output_Fs, DELAY_CLDFB_NS ) ); } } } - ELSE IF( (EQ_16(st_fx->last_codec_mode,MODE2))&&(GT_16(st_fx->last_core,ACELP_CORE))) + ELSE IF( ( EQ_16( st_fx->last_codec_mode, MODE2 ) ) && ( GT_16( st_fx->last_core, ACELP_CORE ) ) ) { Word16 step, alpha; - Copy_Scale_sig(hTcxDec->FBTCXdelayBuf, output_sp, delta, negate(timeIn_e)); + Copy_Scale_sig( hTcxDec->FBTCXdelayBuf, output_sp, delta, negate( timeIn_e ) ); i = 15; move16(); - step = Inv16(sub(tmps,delta), &i); - step = shl(step, i); + step = Inv16( sub( tmps, delta ), &i ); + step = shl( step, i ); alpha = 0; move16(); - FOR (i = delta; i < tmps; i++) + FOR( i = delta; i < tmps; i++ ) { #ifdef BASOP_NOGLOB output_sp[i] = msu_r_sat( L_mult( output_sp[i], alpha ), shr_sat( hTcxDec->FBTCXdelayBuf[i], timeIn_e ), add( alpha, -32768 ) ); #else - output_sp[i] = msu_r(L_mult(output_sp[i], alpha), shr(hTcxDec->FBTCXdelayBuf[i], timeIn_e), add(alpha, -32768)); + output_sp[i] = msu_r( L_mult( output_sp[i], alpha ), shr( hTcxDec->FBTCXdelayBuf[i], timeIn_e ), add( alpha, -32768 ) ); #endif move16(); #ifdef BASOP_NOGLOB - alpha = add_sat(alpha, step); + alpha = add_sat( alpha, step ); #else - alpha = add(alpha, step); + alpha = add( alpha, step ); #endif } } - Scale_sig(hTcxLtpDec->tcxltp_mem_in, delta, sub(Qpostd, Qpostd_prev)); - Scale_sig(hTcxLtpDec->tcxltp_mem_out, output_frame, sub(Qpostd, Qpostd_prev)); + Scale_sig( hTcxLtpDec->tcxltp_mem_in, delta, sub( Qpostd, Qpostd_prev ) ); + Scale_sig( hTcxLtpDec->tcxltp_mem_out, output_frame, sub( Qpostd, Qpostd_prev ) ); test(); Scale_sig( output_sp, output_frame, timeIn_e ); - tcx_ltp_post(st_fx, hTcxLtpDec, st_fx->core, output_frame/*hTcxDec->L_frameTCX*/, NS2SA_fx2( st_fx->output_Fs, ACELP_LOOK_NS ) + tmps, - output_sp, hTcxDec->FBTCXdelayBuf); + tcx_ltp_post( st_fx, hTcxLtpDec, st_fx->core, output_frame /*hTcxDec->L_frameTCX*/, NS2SA_fx2( st_fx->output_Fs, ACELP_LOOK_NS ) + tmps, + output_sp, hTcxDec->FBTCXdelayBuf ); Copy( output_sp, synth_fx, output_frame ); - } /* end of MODE2 */ + } /* end of MODE2 */ /*----------------------------------------------------------------* * Save synthesis for HQ FEC *----------------------------------------------------------------*/ - //PMT("The code below could be move to save_synthesis_hq_fec") + // PMT("The code below could be move to save_synthesis_hq_fec") post_hq_delay = NS2SA_fx2( st_fx->output_Fs, POST_HQ_DELAY_NS ); - IF (EQ_16(st_fx->codec_mode, MODE1)) + IF( EQ_16( st_fx->codec_mode, MODE1 ) ) { - Copy(hTcxDec->synth_history_fx+output_frame, hTcxDec->synth_history_fx, output_frame-post_hq_delay+NS2SA_fx2( st_fx->output_Fs, PH_ECU_MEM_NS )); - Copy_Scale_sig( synth_fx, hTcxDec->old_synthFB_fx+output_frame-post_hq_delay, output_frame,negate(Qpostd)); /* output_sp not initialized yet */ + Copy( hTcxDec->synth_history_fx + output_frame, hTcxDec->synth_history_fx, output_frame - post_hq_delay + NS2SA_fx2( st_fx->output_Fs, PH_ECU_MEM_NS ) ); + Copy_Scale_sig( synth_fx, hTcxDec->old_synthFB_fx + output_frame - post_hq_delay, output_frame, negate( Qpostd ) ); /* output_sp not initialized yet */ /* reset the remaining buffer, which is read in TCX concealment the necessary samples to fill this buffer are not available for all cases, the impact on the output is limited */ - set16_fx(hTcxDec->old_synthFB_fx+2*output_frame-post_hq_delay, 0, post_hq_delay ); + set16_fx( hTcxDec->old_synthFB_fx + 2 * output_frame - post_hq_delay, 0, post_hq_delay ); - IF( GE_16(output_frame, L_FRAME16k)) + IF( GE_16( output_frame, L_FRAME16k ) ) { - Copy_Scale_sig( st_fx->prev_synth_buffer_fx, hTcxDec->old_synthFB_fx+2*output_frame-NS2SA_fx2(st_fx->output_Fs, DELAY_BWE_TOTAL_NS), NS2SA_fx2(st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS),negate(st_fx->Qprev_synth_buffer_fx)); + Copy_Scale_sig( st_fx->prev_synth_buffer_fx, hTcxDec->old_synthFB_fx + 2 * output_frame - NS2SA_fx2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ), NS2SA_fx2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), negate( st_fx->Qprev_synth_buffer_fx ) ); } - IF( NE_16(st_fx->core,ACELP_CORE)) + IF( NE_16( st_fx->core, ACELP_CORE ) ) { - IF( GE_16(output_frame, L_FRAME16k)) + IF( GE_16( output_frame, L_FRAME16k ) ) { - Copy_Scale_sig( synth_fx+output_frame, hTcxDec->old_synthFB_fx+2*output_frame-NS2SA_fx2(st_fx->output_Fs, DELAY_CLDFB_NS), NS2SA_fx2(st_fx->output_Fs, DELAY_CLDFB_NS),negate(Qpostd)); - Copy_Scale_sig(hHQ_core->old_out_fx+NS2SA_fx2(st_fx->output_Fs, N_ZERO_MDCT_NS), hTcxDec->old_synthFB_fx+2*output_frame, NS2SA_fx2(st_fx->output_Fs, PH_ECU_LOOKAHEAD_NS), negate(hHQ_core->Q_old_wtda)); + Copy_Scale_sig( synth_fx + output_frame, hTcxDec->old_synthFB_fx + 2 * output_frame - NS2SA_fx2( st_fx->output_Fs, DELAY_CLDFB_NS ), NS2SA_fx2( st_fx->output_Fs, DELAY_CLDFB_NS ), negate( Qpostd ) ); + Copy_Scale_sig( hHQ_core->old_out_fx + NS2SA_fx2( st_fx->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->old_synthFB_fx + 2 * output_frame, NS2SA_fx2( st_fx->output_Fs, PH_ECU_LOOKAHEAD_NS ), negate( hHQ_core->Q_old_wtda ) ); } ELSE { - Copy_Scale_sig( synth_fx+output_frame, hTcxDec->old_synthFB_fx+2*output_frame-NS2SA_fx2(st_fx->output_Fs, DELAY_BWE_TOTAL_NS), NS2SA_fx2(st_fx->output_Fs, DELAY_CLDFB_NS),negate(Qpostd)); - Copy_Scale_sig(hHQ_core->old_out_fx+NS2SA_fx2(st_fx->output_Fs, N_ZERO_MDCT_NS), hTcxDec->old_synthFB_fx+2*output_frame-NS2SA_fx2(st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS), NS2SA_fx2(st_fx->output_Fs, PH_ECU_LOOKAHEAD_NS), negate(hHQ_core->Q_old_wtda)); + Copy_Scale_sig( synth_fx + output_frame, hTcxDec->old_synthFB_fx + 2 * output_frame - NS2SA_fx2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ), NS2SA_fx2( st_fx->output_Fs, DELAY_CLDFB_NS ), negate( Qpostd ) ); + Copy_Scale_sig( hHQ_core->old_out_fx + NS2SA_fx2( st_fx->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->old_synthFB_fx + 2 * output_frame - NS2SA_fx2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), NS2SA_fx2( st_fx->output_Fs, PH_ECU_LOOKAHEAD_NS ), negate( hHQ_core->Q_old_wtda ) ); } } } @@ -1439,19 +1417,19 @@ ivas_error evs_dec_fx( * HP filtering *----------------------------------------------------------------*/ - st_fx->Qprev_synth_buffer_fx=Qpostd; + st_fx->Qprev_synth_buffer_fx = Qpostd; move16(); - Scale_sig32(st_fx->L_mem_hp_out_fx, 4, sub(Qpostd, Qpostd_prev)); - hp20(synth_fx, 1/*stride*/, output_frame, st_fx->L_mem_hp_out_fx, L_mult0(output_frame, 50)); + Scale_sig32( st_fx->L_mem_hp_out_fx, 4, sub( Qpostd, Qpostd_prev ) ); + hp20( synth_fx, 1 /*stride*/, output_frame, st_fx->L_mem_hp_out_fx, L_mult0( output_frame, 50 ) ); /*----------------------------------------------------------------* * Synthesis output *----------------------------------------------------------------*/ - IF( EQ_16(st_fx->codec_mode,MODE1)) + IF( EQ_16( st_fx->codec_mode, MODE1 ) ) { /* final output of synthesis signal */ - syn_output_fx( st_fx->codec_mode, synth_fx, output_frame, output_sp, Qpostd ); + syn_output_fx( st_fx->codec_mode, synth_fx, output_frame, output_sp, Qpostd ); } ELSE { @@ -1463,35 +1441,34 @@ ivas_error evs_dec_fx( *--------------------------------------------------------*/ test(); - IF( st_fx->last_is_cng == 0 && EQ_16(st_fx->codec_mode,MODE2)) + IF( st_fx->last_is_cng == 0 && EQ_16( st_fx->codec_mode, MODE2 ) ) { st_fx->bfi = 0; move16(); - IF( st_fx->use_partial_copy && GE_16(st_fx->rf_frame_type, RF_TCXFD)&&LE_16(st_fx->rf_frame_type,RF_TCXTD2)) + IF( st_fx->use_partial_copy && GE_16( st_fx->rf_frame_type, RF_TCXFD ) && LE_16( st_fx->rf_frame_type, RF_TCXTD2 ) ) { - if( EQ_16(frameMode, FRAMEMODE_MISSING)) + if ( EQ_16( frameMode, FRAMEMODE_MISSING ) ) { st_fx->bfi = 1; move16(); } } - ELSE IF( EQ_16(st_fx->m_decodeMode, DEC_CONCEALMENT_EXT)) + ELSE IF( EQ_16( st_fx->m_decodeMode, DEC_CONCEALMENT_EXT ) ) { st_fx->bfi = 1; move16(); } - updt_dec_common_fx( st_fx, -1, concealWholeFrameTmp, output_sp, Qpostd); + updt_dec_common_fx( st_fx, -1, concealWholeFrameTmp, output_sp, Qpostd ); } ELSE { - if( EQ_16(st_fx->codec_mode,MODE2)) + if ( EQ_16( st_fx->codec_mode, MODE2 ) ) { st_fx->bfi = 0; move16(); } - updt_dec_common_fx( st_fx, hq_core_type, concealWholeFrameTmp, output_sp, Qpostd); + updt_dec_common_fx( st_fx, hq_core_type, concealWholeFrameTmp, output_sp, Qpostd ); } return IVAS_ERR_OK; - } #endif diff --git a/lib_dec/fd_cng_dec.c b/lib_dec/fd_cng_dec.c index 11b68e171..7ad0bd0a0 100644 --- a/lib_dec/fd_cng_dec.c +++ b/lib_dec/fd_cng_dec.c @@ -57,10 +57,10 @@ #define DELTA_MASKING_NOISE 1e-20f #define DELTA_MASKING_NOISE_Q31 0 -#define CNA_ACT_DN_LARGE_PARTITION 50 /* index of the first larger partition */ -#define ST_PERIODOG_FACT 0.9 /* short-term filter factor for periodogram */ -#define CNA_ACT_DN_FACT 0.7 /* downward updating factor for CNA during active frames */ -#define FIRST_CNA_NOISE_UPD_FRAMES 5 /* minimum number of CN initialization frames */ +#define CNA_ACT_DN_LARGE_PARTITION 50 /* index of the first larger partition */ +#define ST_PERIODOG_FACT 0.9 /* short-term filter factor for periodogram */ +#define CNA_ACT_DN_FACT 0.7 /* downward updating factor for CNA during active frames */ +#define FIRST_CNA_NOISE_UPD_FRAMES 5 /* minimum number of CN initialization frames */ #define LOG_10_BASE_2 1783446566 /* Q29 */ #ifdef IVAS_FLOAT_FIXED #define GAIN_Q_OFFSET_IVAS_FX 45 @@ -119,7 +119,7 @@ ivas_error createFdCngDec( *-------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED void initFdCngDec( - DEC_CORE_HANDLE st /* i/o: decoder state structure */ + DEC_CORE_HANDLE st /* i/o: decoder state structure */ ) { HANDLE_FD_CNG_DEC hFdCngDec; @@ -139,8 +139,8 @@ void initFdCngDec( set_f( hFdCngDec->bandNoiseShape_float, 0.0f, FFTLEN2 ); set_f( hFdCngDec->partNoiseShape_float, 0.0f, NPART ); set_f( hFdCngDec->msPeriodog_float, 0.0f, NPART_SHAPING ); - set_f( hFdCngDec->msAlpha_float, 0.0f, NPART_SHAPING ); - set_f( hFdCngDec->msBminWin_float, 0.0f, NPART_SHAPING ); + set_f( hFdCngDec->msAlpha_float, 0.0f, NPART_SHAPING ); + set_f( hFdCngDec->msBminWin_float, 0.0f, NPART_SHAPING ); set_f( hFdCngDec->msBminSubWin_float, 0.0f, NPART_SHAPING ); set_f( hFdCngDec->msPsd_float, 0.0f, NPART_SHAPING ); set_f( hFdCngDec->msNoiseFloor_float, 0.0f, NPART_SHAPING ); @@ -149,13 +149,13 @@ void initFdCngDec( set_f( hFdCngDec->msCurrentMin_float, FLT_MAX, NPART_SHAPING ); set_f( hFdCngDec->msCurrentMinOut_float, FLT_MAX, NPART_SHAPING ); set_f( hFdCngDec->msCurrentMinSubWindow_float, FLT_MAX, NPART_SHAPING ); -#endif +#endif set_s( hFdCngDec->msLocalMinFlag, 0, NPART_SHAPING ); set_s( hFdCngDec->msNewMinFlag, 0, NPART_SHAPING ); #ifndef IVAS_FLOAT_FIXED set_f( hFdCngDec->msPsdFirstMoment_float, 0.0f, NPART_SHAPING ); set_f( hFdCngDec->msPsdSecondMoment_float, 0.0f, NPART_SHAPING ); -#endif +#endif hFdCngDec->msPeriodogBufPtr = 0; #ifndef IVAS_FLOAT_FIXED @@ -163,21 +163,21 @@ void initFdCngDec( set_f( hFdCngDec->msLogPeriodog_float, 0.0f, NPART_SHAPING ); set_f( hFdCngDec->msLogNoiseEst_float, 0.0f, NPART_SHAPING ); set_f( hFdCngDec->psize_shaping_float, 0.0f, NPART_SHAPING ); -#endif +#endif hFdCngDec->nFFTpart_shaping = 0; #ifndef IVAS_FLOAT_FIXED set_f( hFdCngDec->hFdCngCom->sidNoiseEstLp_flt, 0.0f, NPART ); set_f( hFdCngDec->smoothed_psd, 0.0f, L_FRAME16k ); set_f( hFdCngDec->msPeriodog_ST, 0.0f, NPART_SHAPING ); -#endif +#endif hFdCngDec->ms_last_inactive_bwidth = NB; hFdCngDec->ms_cnt_bw_up = 0; #ifndef IVAS_FLOAT_FIXED hFdCngDec->cna_LR_LT = 0.5f; hFdCngDec->cna_ILD_LT = 0.0f; -#endif +#endif hFdCngDec->first_cna_noise_updated = 0; hFdCngDec->first_cna_noise_update_cnt = 0; hFdCngDec->cna_nbands = CNA_INIT_NBANDS; @@ -190,86 +190,86 @@ void initFdCngDec( #else hFdCngDec->cna_act_fact_fx = MAX_WORD16; hFdCngDec->cna_rescale_fact_fx = 0; -#endif +#endif hFdCngDec->cna_seed = 5687; #ifndef IVAS_FLOAT_FIXED set_zero( hFdCngDec->cna_cm, STEREO_DFT_BAND_MAX ); set_zero( hFdCngDec->cna_g_state, STEREO_DFT_BAND_MAX ); -#endif +#endif st->CNG_mode = -1; #ifndef IVAS_FLOAT_FIXED - mvr2r(st->lsp_old, st->lspCNG, M); + mvr2r( st->lsp_old, st->lspCNG, M ); #endif // #ifndef IVAS_FLOAT_FIXED return; } #else void initFdCngDec( - DEC_CORE_HANDLE st /* i/o: decoder state structure */ + DEC_CORE_HANDLE st /* i/o: decoder state structure */ ) { - HANDLE_FD_CNG_DEC hFdCngDec; - - hFdCngDec = st->hFdCngDec; - - /* Initialize common */ - initFdCngCom_flt(hFdCngDec->hFdCngCom, st->cldfbSyn->scale_flt); - - /* Set some counters and flags */ - hFdCngDec->flag_dtx_mode = 0; - hFdCngDec->lp_noise_float = -20.f; - hFdCngDec->lp_speech_float = 25.f; - - /* Initialize noise estimation algorithm */ - set_f(hFdCngDec->bandNoiseShape_float, 0.0f, FFTLEN2); - set_f(hFdCngDec->partNoiseShape_float, 0.0f, NPART); - set_f(hFdCngDec->msPeriodog_float, 0.0f, NPART_SHAPING); - set_f(hFdCngDec->msAlpha_float, 0.0f, NPART_SHAPING); - set_f(hFdCngDec->msBminWin_float, 0.0f, NPART_SHAPING); - set_f(hFdCngDec->msBminSubWin_float, 0.0f, NPART_SHAPING); - set_f(hFdCngDec->msPsd_float, 0.0f, NPART_SHAPING); - set_f(hFdCngDec->msNoiseFloor_float, 0.0f, NPART_SHAPING); - set_f(hFdCngDec->msNoiseEst_float, 0.0f, NPART_SHAPING); - set_f(hFdCngDec->msMinBuf_float, FLT_MAX, MSNUMSUBFR * NPART_SHAPING); - set_f(hFdCngDec->msCurrentMin_float, FLT_MAX, NPART_SHAPING); - set_f(hFdCngDec->msCurrentMinOut_float, FLT_MAX, NPART_SHAPING); - set_f(hFdCngDec->msCurrentMinSubWindow_float, FLT_MAX, NPART_SHAPING); - set_s(hFdCngDec->msLocalMinFlag, 0, NPART_SHAPING); - set_s(hFdCngDec->msNewMinFlag, 0, NPART_SHAPING); - set_f(hFdCngDec->msPsdFirstMoment_float, 0.0f, NPART_SHAPING); - set_f(hFdCngDec->msPsdSecondMoment_float, 0.0f, NPART_SHAPING); - hFdCngDec->msPeriodogBufPtr = 0; - set_f(hFdCngDec->msPeriodogBuf_float, 0.0f, MSBUFLEN * NPART_SHAPING); - set_f(hFdCngDec->msLogPeriodog_float, 0.0f, NPART_SHAPING); - set_f(hFdCngDec->msLogNoiseEst_float, 0.0f, NPART_SHAPING); - set_f(hFdCngDec->psize_shaping_float, 0.0f, NPART_SHAPING); - hFdCngDec->nFFTpart_shaping = 0; - - set_f(hFdCngDec->hFdCngCom->sidNoiseEstLp_flt, 0.0f, NPART); - - set_f(hFdCngDec->smoothed_psd, 0.0f, L_FRAME16k); - set_f(hFdCngDec->msPeriodog_ST, 0.0f, NPART_SHAPING); - - hFdCngDec->ms_last_inactive_bwidth = NB; - hFdCngDec->ms_cnt_bw_up = 0; - - hFdCngDec->cna_LR_LT = 0.5f; - hFdCngDec->cna_ILD_LT = 0.0f; - hFdCngDec->first_cna_noise_updated = 0; - hFdCngDec->first_cna_noise_update_cnt = 0; - hFdCngDec->cna_nbands = CNA_INIT_NBANDS; - mvs2s(cna_init_bands, hFdCngDec->cna_band_limits, CNA_INIT_NBANDS + 1); - hFdCngDec->cna_act_fact = 1.0f; - hFdCngDec->cna_rescale_fact = 0.0f; - hFdCngDec->cna_seed = 5687; - set_zero(hFdCngDec->cna_cm, STEREO_DFT_BAND_MAX); - set_zero(hFdCngDec->cna_g_state, STEREO_DFT_BAND_MAX); - - st->CNG_mode = -1; - mvr2r(st->lsp_old, st->lspCNG, M); - - return; + HANDLE_FD_CNG_DEC hFdCngDec; + + hFdCngDec = st->hFdCngDec; + + /* Initialize common */ + initFdCngCom_flt( hFdCngDec->hFdCngCom, st->cldfbSyn->scale_flt ); + + /* Set some counters and flags */ + hFdCngDec->flag_dtx_mode = 0; + hFdCngDec->lp_noise_float = -20.f; + hFdCngDec->lp_speech_float = 25.f; + + /* Initialize noise estimation algorithm */ + set_f( hFdCngDec->bandNoiseShape_float, 0.0f, FFTLEN2 ); + set_f( hFdCngDec->partNoiseShape_float, 0.0f, NPART ); + set_f( hFdCngDec->msPeriodog_float, 0.0f, NPART_SHAPING ); + set_f( hFdCngDec->msAlpha_float, 0.0f, NPART_SHAPING ); + set_f( hFdCngDec->msBminWin_float, 0.0f, NPART_SHAPING ); + set_f( hFdCngDec->msBminSubWin_float, 0.0f, NPART_SHAPING ); + set_f( hFdCngDec->msPsd_float, 0.0f, NPART_SHAPING ); + set_f( hFdCngDec->msNoiseFloor_float, 0.0f, NPART_SHAPING ); + set_f( hFdCngDec->msNoiseEst_float, 0.0f, NPART_SHAPING ); + set_f( hFdCngDec->msMinBuf_float, FLT_MAX, MSNUMSUBFR * NPART_SHAPING ); + set_f( hFdCngDec->msCurrentMin_float, FLT_MAX, NPART_SHAPING ); + set_f( hFdCngDec->msCurrentMinOut_float, FLT_MAX, NPART_SHAPING ); + set_f( hFdCngDec->msCurrentMinSubWindow_float, FLT_MAX, NPART_SHAPING ); + set_s( hFdCngDec->msLocalMinFlag, 0, NPART_SHAPING ); + set_s( hFdCngDec->msNewMinFlag, 0, NPART_SHAPING ); + set_f( hFdCngDec->msPsdFirstMoment_float, 0.0f, NPART_SHAPING ); + set_f( hFdCngDec->msPsdSecondMoment_float, 0.0f, NPART_SHAPING ); + hFdCngDec->msPeriodogBufPtr = 0; + set_f( hFdCngDec->msPeriodogBuf_float, 0.0f, MSBUFLEN * NPART_SHAPING ); + set_f( hFdCngDec->msLogPeriodog_float, 0.0f, NPART_SHAPING ); + set_f( hFdCngDec->msLogNoiseEst_float, 0.0f, NPART_SHAPING ); + set_f( hFdCngDec->psize_shaping_float, 0.0f, NPART_SHAPING ); + hFdCngDec->nFFTpart_shaping = 0; + + set_f( hFdCngDec->hFdCngCom->sidNoiseEstLp_flt, 0.0f, NPART ); + + set_f( hFdCngDec->smoothed_psd, 0.0f, L_FRAME16k ); + set_f( hFdCngDec->msPeriodog_ST, 0.0f, NPART_SHAPING ); + + hFdCngDec->ms_last_inactive_bwidth = NB; + hFdCngDec->ms_cnt_bw_up = 0; + + hFdCngDec->cna_LR_LT = 0.5f; + hFdCngDec->cna_ILD_LT = 0.0f; + hFdCngDec->first_cna_noise_updated = 0; + hFdCngDec->first_cna_noise_update_cnt = 0; + hFdCngDec->cna_nbands = CNA_INIT_NBANDS; + mvs2s( cna_init_bands, hFdCngDec->cna_band_limits, CNA_INIT_NBANDS + 1 ); + hFdCngDec->cna_act_fact = 1.0f; + hFdCngDec->cna_rescale_fact = 0.0f; + hFdCngDec->cna_seed = 5687; + set_zero( hFdCngDec->cna_cm, STEREO_DFT_BAND_MAX ); + set_zero( hFdCngDec->cna_g_state, STEREO_DFT_BAND_MAX ); + + st->CNG_mode = -1; + mvr2r( st->lsp_old, st->lspCNG, M ); + + return; } #endif @@ -459,21 +459,21 @@ void configureFdCngDec_ivas_fx( hsCom->CngBandwidth = bwidth; move16(); - IF ( EQ_16( hsCom->CngBandwidth, FB ) ) + IF( EQ_16( hsCom->CngBandwidth, FB ) ) { hsCom->CngBandwidth = SWB; move16(); } test(); - IF ( NE_32( total_brate, FRAME_NO_DATA ) && NE_32( total_brate, SID_2k40 ) ) + IF( NE_32( total_brate, FRAME_NO_DATA ) && NE_32( total_brate, SID_2k40 ) ) { hsCom->CngBitrate = total_brate; move32(); } - ELSE IF ( EQ_32( hsCom->CngBitrate, -1 ) ) + ELSE IF( EQ_32( hsCom->CngBitrate, -1 ) ) { /* set minimum active CBR bitrate IF CngBitrate is uninitialized */ - IF ( GT_16( element_mode, EVS_MONO ) ) + IF( GT_16( element_mode, EVS_MONO ) ) { hsCom->CngBitrate = IVAS_13k2; move32(); @@ -487,7 +487,7 @@ void configureFdCngDec_ivas_fx( /* FD-CNG config for MDCT-Stereo is always the same (since for > 48 kbps only) */ /* This may need adjustment in the future IF 2TC DTX for some mode uses MDCT-Stereo DTX for lower bitrates too */ - IF ( EQ_16( element_mode, IVAS_CPE_MDCT ) ) + IF( EQ_16( element_mode, IVAS_CPE_MDCT ) ) { hsCom->CngBitrate = IVAS_48k; move32(); @@ -496,7 +496,7 @@ void configureFdCngDec_ivas_fx( move32(); /* NB configuration */ - IF ( EQ_16( bwidth, NB ) ) + IF( EQ_16( bwidth, NB ) ) { hsCom->FdCngSetup = FdCngSetup_nb; hsCom->numCoreBands = 16; @@ -506,12 +506,12 @@ void configureFdCngDec_ivas_fx( } /* WB configuration */ - ELSE IF ( EQ_16( bwidth, WB ) ) + ELSE IF( EQ_16( bwidth, WB ) ) { /* FFT 6.4kHz, no CLDFB */ test(); test(); - IF ( LE_32( hsCom->CngBitrate, ACELP_8k00 ) && EQ_16( L_frame, L_FRAME ) ) + IF( LE_32( hsCom->CngBitrate, ACELP_8k00 ) && EQ_16( L_frame, L_FRAME ) ) { hsCom->FdCngSetup = FdCngSetup_wb1; hsCom->numCoreBands = 16; @@ -520,14 +520,14 @@ void configureFdCngDec_ivas_fx( move16(); } /* FFT 6.4kHz, CLDFB 8.0kHz */ - ELSE IF ( LE_32( hsCom->CngBitrate, ACELP_13k20 ) || EQ_16( L_frame, L_FRAME ) ) + ELSE IF( LE_32( hsCom->CngBitrate, ACELP_13k20 ) || EQ_16( L_frame, L_FRAME ) ) { hsCom->FdCngSetup = FdCngSetup_wb2; hsCom->numCoreBands = 16; move16(); hsCom->regularStopBand = 20; move16(); - IF ( EQ_16( L_frame, L_FRAME16k ) ) + IF( EQ_16( L_frame, L_FRAME16k ) ) { hsCom->FdCngSetup = FdCngSetup_wb2; hsCom->numCoreBands = 20; @@ -555,7 +555,7 @@ void configureFdCngDec_ivas_fx( ELSE { /* FFT 6.4kHz, CLDFB 14kHz */ - IF ( EQ_16( L_frame, L_FRAME ) ) + IF( EQ_16( L_frame, L_FRAME ) ) { hsCom->FdCngSetup = FdCngSetup_swb1; hsCom->numCoreBands = 16; @@ -572,7 +572,7 @@ void configureFdCngDec_ivas_fx( hsCom->regularStopBand = 40; move16(); test(); - IF ( EQ_16( last_L_frame, L_FRAME ) && EQ_16( element_mode, IVAS_CPE_DFT ) ) + IF( EQ_16( last_L_frame, L_FRAME ) && EQ_16( element_mode, IVAS_CPE_DFT ) ) { hsCom->regularStopBand = 35; move16(); @@ -594,16 +594,16 @@ void configureFdCngDec_ivas_fx( #ifndef IVAS_FLOAT_FIXED /* remove floating point dependency */ initPartitions_flt( hsCom->FdCngSetup.sidPartitions, hsCom->FdCngSetup.numPartitions, hsCom->startBand, hsCom->stopBand, hsCom->part, &hsCom->npart, hsCom->midband, hsCom->psize_flt, hsCom->psize_inv_flt, 0 ); -#else // IVAS_FLOAT_FIXED - initPartitions(hsCom->FdCngSetup.sidPartitions, hsCom->FdCngSetup.numPartitions, hsCom->startBand, hsCom->stopBand, hsCom->part, &hsCom->npart, hsCom->midband, hsCom->psize, hsCom->psize_norm, &hsCom->psize_norm_exp, hsCom->psize_inv, 0); +#else // IVAS_FLOAT_FIXED + initPartitions( hsCom->FdCngSetup.sidPartitions, hsCom->FdCngSetup.numPartitions, hsCom->startBand, hsCom->stopBand, hsCom->part, &hsCom->npart, hsCom->midband, hsCom->psize, hsCom->psize_norm, &hsCom->psize_norm_exp, hsCom->psize_inv, 0 ); #endif // IVAS_FLOAT_FIXED - IF ( EQ_16( hsCom->stopFFTbin, 160 ) ) + IF( EQ_16( hsCom->stopFFTbin, 160 ) ) { hsCom->nFFTpart = 17; move16(); } - ELSE IF ( EQ_16( hsCom->stopFFTbin, 256 ) ) + ELSE IF( EQ_16( hsCom->stopFFTbin, 256 ) ) { hsCom->nFFTpart = 20; move16(); @@ -614,7 +614,7 @@ void configureFdCngDec_ivas_fx( move16(); } hsCom->nCLDFBpart = sub( hsCom->npart, hsCom->nFFTpart ); - FOR ( j = 0; j < hsCom->nCLDFBpart; j++ ) + FOR( j = 0; j < hsCom->nCLDFBpart; j++ ) { hsCom->CLDFBpart[j] = sub( hsCom->part[j + hsCom->nFFTpart], sub( hsCom->stopFFTbin, hsCom->startBand ) ); #ifndef IVAS_FLOAT_FIXED @@ -626,7 +626,7 @@ void configureFdCngDec_ivas_fx( stopBandFR = 40; //(Word16)floor(1000.f /*Hz*/ / 25.f /*Hz/Bin*/); move16(); - IF ( GT_16( stopBandFR, hsCom->stopFFTbin ) ) + IF( GT_16( stopBandFR, hsCom->stopFFTbin ) ) { stopBandFR = hsCom->stopFFTbin; move16(); @@ -634,7 +634,7 @@ void configureFdCngDec_ivas_fx( #ifdef IVAS_FLOAT_FIXED initPartitions( hsCom->FdCngSetup.shapingPartitions, hsCom->FdCngSetup.numShapingPartitions, hsCom->startBand, hsCom->stopFFTbin, hFdCngDec->part_shaping, &hFdCngDec->npart_shaping, hFdCngDec->midband_shaping, hFdCngDec->psize_shaping, hFdCngDec->psize_shaping_norm, &hFdCngDec->psize_shaping_norm_exp, hFdCngDec->psize_inv_shaping, stopBandFR ); -#else // IVAS_FLOAT_FIXED +#else // IVAS_FLOAT_FIXED /* remove floating point dependency */ initPartitions_flt( hsCom->FdCngSetup.shapingPartitions, hsCom->FdCngSetup.numShapingPartitions, hsCom->startBand, hsCom->stopFFTbin, hFdCngDec->part_shaping, &hFdCngDec->npart_shaping, hFdCngDec->midband_shaping, hFdCngDec->psize_shaping_float, hFdCngDec->psize_inv_shaping_float, stopBandFR ); #endif // IVAS_FLOAT_FIXED @@ -642,10 +642,10 @@ void configureFdCngDec_ivas_fx( hFdCngDec->nFFTpart_shaping = hFdCngDec->npart_shaping; move16(); - BASOP_getTables(&hsCom->olapWinAna, NULL, NULL, shr(hsCom->fftlen, 1)); - BASOP_getTables(&hsCom->olapWinSyn, NULL, NULL, shr(hsCom->fftlen, 2)); + BASOP_getTables( &hsCom->olapWinAna, NULL, NULL, shr( hsCom->fftlen, 1 ) ); + BASOP_getTables( &hsCom->olapWinSyn, NULL, NULL, shr( hsCom->fftlen, 2 ) ); - SWITCH ( hsCom->fftlen ) + SWITCH( hsCom->fftlen ) { case 512: hsCom->olapWinAna_fx = olapWinAna512_fx; @@ -659,7 +659,7 @@ void configureFdCngDec_ivas_fx( #endif hsCom->fftlenShift = 8; move16(); - hsCom->fftlenFac = 32767/*1.0 Q15*/; + hsCom->fftlenFac = 32767 /*1.0 Q15*/; move16(); BREAK; case 640: @@ -674,15 +674,15 @@ void configureFdCngDec_ivas_fx( #endif hsCom->fftlenShift = 9; move16(); - hsCom->fftlenFac = 20480/*0.625 Q15*/; + hsCom->fftlenFac = 20480 /*0.625 Q15*/; move16(); BREAK; default: assert( !"Unsupported FFT length for FD-based CNG" ); BREAK; } - BASOP_getTables(&hsCom->olapWinAna, NULL, NULL, shr(hsCom->fftlen, 1)); - BASOP_getTables(&hsCom->olapWinSyn, NULL, NULL, shr(hsCom->fftlen, 2)); + BASOP_getTables( &hsCom->olapWinAna, NULL, NULL, shr( hsCom->fftlen, 1 ) ); + BASOP_getTables( &hsCom->olapWinSyn, NULL, NULL, shr( hsCom->fftlen, 2 ) ); hsCom->frameSize = shr( hsCom->fftlen, 1 ); return; @@ -700,7 +700,7 @@ void deleteFdCngDec( { HANDLE_FD_CNG_DEC hsDec = *hFdCngDec; - IF ( hsDec != NULL ) + IF( hsDec != NULL ) { deleteFdCngCom_flt( &( hsDec->hFdCngCom ) ); free( hsDec ); @@ -718,252 +718,251 @@ void deleteFdCngDec( *-------------------------------------------------------------------*/ #ifndef IVAS_FLOAT_FIXED void ApplyFdCng( - float *timeDomainInput, - float *powerSpectrum, - float **realBuffer, /* i/o: Real part of the buffer */ - float **imagBuffer, /* i/o: Imaginary part of the buffer */ - Decoder_State *st, - const int16_t concealWholeFrame, - const int16_t is_music ) + float *timeDomainInput, + float *powerSpectrum, + float **realBuffer, /* i/o: Real part of the buffer */ + float **imagBuffer, /* i/o: Imaginary part of the buffer */ + Decoder_State *st, + const int16_t concealWholeFrame, + const int16_t is_music ) { - HANDLE_FD_CNG_DEC hFdCngDec = st->hFdCngDec; - HANDLE_FD_CNG_COM hFdCngCom = hFdCngDec->hFdCngCom; - float *cngNoiseLevel_flt = hFdCngCom->cngNoiseLevel_flt; - float *sidNoiseEst_flt = hFdCngCom->sidNoiseEst_flt; - int16_t j, k; - float factor; - float lsp_cng[M]; - int16_t L_frame, last_L_frame; - int32_t sr_core; - - push_wmops( "ApplyFdCng" ); - - /* limit L_frame and core Fs values for MDCT-Stereo modes which can have higher core sampling than 16kHz, but use a downsampled buffer */ - L_frame = min( st->L_frame, L_FRAME16k ); - last_L_frame = min( st->last_L_frame, L_FRAME16k ); - sr_core = min( st->sr_core, INT_FS_16k ); - - if ( hFdCngCom->frame_type_previous == ACTIVE_FRAME ) - { - hFdCngCom->inactive_frame_counter = 0; - } - - if ( st->element_mode == IVAS_CPE_TD ) - { - hFdCngDec->flag_dtx_mode = hFdCngDec->flag_dtx_mode || st->first_CNG; - } - - switch ( st->m_frame_type ) - { - - case ACTIVE_FRAME: - /************************** - * ACTIVE_FRAME at DECODER * - **************************/ - - hFdCngCom->inactive_frame_counter = 0; - hFdCngCom->sid_frame_counter = 0; - /* set noise estimation inactive during concealment, as no update with noise generated by concealment should be performed. */ - /* set noise estimation inactive when we have bit errors, as no update with noise generated by corrupt frame (biterror) should be performed. */ - if ( concealWholeFrame == 0 && - ( timeDomainInput == NULL || - ( *timeDomainInput( -FLT_MAX ) && - *( timeDomainInput + hFdCngCom->frameSize - 1 ) < FLT_MAX && - *( timeDomainInput + hFdCngCom->frameSize - 1 ) > ( -FLT_MAX ) ) ) && - ( ( ( ( st->element_mode != IVAS_CPE_TD && st->element_mode != IVAS_CPE_DFT && hFdCngDec->flag_dtx_mode ) || !st->VAD || ( st->ini_frame < 100 && st->is_ism_format ) ) && - !( st->cng_type == LP_CNG && hFdCngDec->flag_dtx_mode ) && ( is_music == 0 ) ) || - ( st->element_mode == IVAS_CPE_TD ) ) && - ( !st->BER_detect ) ) - { - /* Perform noise estimation at the decoder */ - perform_noise_estimation_dec( timeDomainInput, powerSpectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD ); - - if ( st->element_mode != IVAS_CPE_TD && st->element_mode != IVAS_CPE_DFT ) - { - /* Update the shaping parameters */ - scalebands_flt( hFdCngDec->msNoiseEst_float, hFdCngDec->part_shaping, hFdCngDec->nFFTpart_shaping, hFdCngDec->midband_shaping, hFdCngDec->nFFTpart_shaping, hFdCngCom->stopFFTbin - hFdCngCom->startBand, hFdCngDec->bandNoiseShape_float, 1 ); - } - - /* Update CNG levels */ - if ( hFdCngDec->flag_dtx_mode && st->cng_type == FD_CNG ) - { - bandcombinepow_flt( hFdCngDec->bandNoiseShape_float, hFdCngCom->stopFFTbin - hFdCngCom->startBand, hFdCngCom->part, hFdCngCom->nFFTpart, hFdCngCom->psize_inv_flt, hFdCngDec->partNoiseShape_float); /* This needs to be done only once per inactive phase */ - - j = 0; - for ( k = 0; k < hFdCngCom->nFFTpart; k++ ) - { - factor = ( hFdCngCom->sidNoiseEst_flt[k] + DELTA ) / ( hFdCngDec->partNoiseShape_float[k] + DELTA ); - for ( ; j <= hFdCngCom->part[k]; j++ ) - { - cngNoiseLevel_flt[j] = hFdCngDec->bandNoiseShape_float[j] * factor; - } - } - } - else - { - /* This sets the new CNG levels until a SID update overwrites it */ - if ( !( st->element_mode == IVAS_CPE_TD ) || ( st->element_mode == IVAS_CPE_TD && !hFdCngDec->flag_dtx_mode && !st->VAD ) ) - { - mvr2r( hFdCngDec->bandNoiseShape_float, cngNoiseLevel_flt, hFdCngCom->stopFFTbin - hFdCngCom->startBand ); /* This sets the new CNG levels until a SID update overwrites it */ - } - } - - if ( st->element_mode == IVAS_CPE_MDCT && timeDomainInput == NULL ) - { - st->hTcxDec->CngLevelBackgroundTrace_bfi = sqrtf( sum_f( cngNoiseLevel_flt, hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / NORM_MDCT_FACTOR ); - } - else - { - st->hTcxDec->CngLevelBackgroundTrace_bfi = (float) sqrt( ( sum_f( cngNoiseLevel_flt, hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / 2 * hFdCngCom->fftlen ) / L_frame ); - } - st->cngTDLevel_float = (float) sqrt( ( sum_f( cngNoiseLevel_flt, hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / 2 * hFdCngCom->fftlen ) / st->L_frame ); - } - else if ( st->element_mode == IVAS_CPE_TD || st->element_mode == IVAS_CPE_DFT ) - { - if ( hFdCngCom->active_frame_counter > 0 ) - { - /* Perform noise estimation in active frames in the decoder for downward updates */ - perform_noise_estimation_dec( timeDomainInput, powerSpectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD ); - } - } - - if ( ( concealWholeFrame == 1 ) && ( st->nbLostCmpt == 1 ) ) - { - /* update lsf cng estimate for concealment. Do that during concealment, in order to avoid addition clean channel complexity*/ - - /* always set psychParameters for MDCT-Stereo ... */ - if ( st->element_mode == IVAS_CPE_MDCT && st->hTonalMDCTConc != NULL ) - { - st->hTonalMDCTConc->psychParams = ( st->core == TCX_20_CORE ) ? &st->hTonalMDCTConc->psychParamsTCX20 : &st->hTonalMDCTConc->psychParamsTCX10; - } - - /* ... but do actual computations only if sufficient energy in noise shape */ - if ( sum_f( cngNoiseLevel_flt + hFdCngCom->startBand, hFdCngCom->stopFFTbin - hFdCngCom->startBand ) > 0.01f ) - { - if ( st->element_mode == IVAS_CPE_MDCT && st->core != ACELP_CORE ) - { - TonalMdctConceal_whiten_noise_shape_ivas( st, L_frame, ON_FIRST_LOST_FRAME ); - } - else if ( st->element_mode != IVAS_CPE_MDCT || st->core == ACELP_CORE ) - { - lpc_from_spectrum_flt( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, 0.f ); - a2lsp_stab( hFdCngCom->A_cng_flt, lsp_cng, st->lspold_cng_float); - mvr2r( lsp_cng, st->lspold_cng_float, M ); - lsp2lsf( lsp_cng, st->lsf_cng_float, M, sr_core ); - } - st->plcBackgroundNoiseUpdated = 1; - } - } - break; - - case SID_FRAME: - hFdCngDec->flag_dtx_mode = 1; - /* FALLTHRU */ - - case ZERO_FRAME: - - if ( st != NULL && st->cng_type == LP_CNG ) - { - /* Perform noise estimation on inactive phase at the decoder */ - perform_noise_estimation_dec( timeDomainInput, powerSpectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD ); - - if ( st->element_mode != IVAS_CPE_TD && st->element_mode != IVAS_CPE_DFT ) - { - /* Update the shaping parameters */ - scalebands_flt( hFdCngDec->msNoiseEst_float, hFdCngDec->part_shaping, hFdCngDec->nFFTpart_shaping, hFdCngDec->midband_shaping, hFdCngDec->nFFTpart_shaping, hFdCngCom->stopFFTbin - hFdCngCom->startBand, hFdCngDec->bandNoiseShape_float, 1 ); - } - - /* This sets the new CNG levels until a SID update overwrites it */ - mvr2r( hFdCngDec->bandNoiseShape_float, cngNoiseLevel_flt, hFdCngCom->stopFFTbin - hFdCngCom->startBand ); /* This sets the new CNG levels until a SID update overwrites it */ - - st->cngTDLevel_float = (float) sqrt( ( sum_f( cngNoiseLevel_flt, hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / 2 * hFdCngCom->fftlen ) / L_frame ); - break; - } - - hFdCngCom->inactive_frame_counter++; - - /************************************* - * SID_FRAME or ZERO_FRAME at DECODER * - *************************************/ - - /* Detect first non-active frame */ - if ( hFdCngCom->inactive_frame_counter == 1 ) - { - /* Compute the fine spectral structure of the comfort noise shape using the decoder-side noise estimates */ - bandcombinepow_flt( hFdCngDec->bandNoiseShape_float, hFdCngCom->stopFFTbin - hFdCngCom->startBand, hFdCngCom->part, hFdCngCom->nFFTpart, hFdCngCom->psize_inv_flt, hFdCngDec->partNoiseShape_float); - - if ( st->element_mode == IVAS_CPE_DFT ) - { - mvr2r( st->hFdCngDec->hFdCngCom->sidNoiseEst_flt, st->hFdCngDec->hFdCngCom->sidNoiseEstLp_flt, NPART ); - } - } - - if ( st->m_frame_type == SID_FRAME ) - { - if ( hFdCngCom->msFrCnt_init_counter < hFdCngCom->msFrCnt_init_thresh ) - { - /* At initialization, interpolate the bin/band-wise levels from the partition levels */ - scalebands_flt( sidNoiseEst_flt, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, hFdCngCom->stopBand - hFdCngCom->startBand, cngNoiseLevel_flt, 1 ); - } - else - { - if ( st->element_mode == IVAS_CPE_DFT ) - { - sidNoiseEst_flt = hFdCngCom->sidNoiseEstLp_flt; - } - - /* Interpolate the CLDFB band levels from the SID (partition) levels */ - if ( hFdCngCom->regularStopBand > hFdCngCom->numCoreBands ) - { - scalebands_flt( sidNoiseEst_flt, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, hFdCngCom->stopBand - hFdCngCom->startBand, cngNoiseLevel_flt, 0 ); - } - - - /* Shape the SID noise levels in each FFT bin */ - j = 0; - for ( k = 0; k < hFdCngCom->nFFTpart; k++ ) - { - factor = ( sidNoiseEst_flt[k] + DELTA ) / ( hFdCngDec->partNoiseShape_float[k] + DELTA ); - for ( ; j <= hFdCngCom->part[k]; j++ ) - { - cngNoiseLevel_flt[j] = hFdCngDec->bandNoiseShape_float[j] * factor; - } - } - } - } - else if ( st->element_mode == IVAS_CPE_DFT ) - { - if ( !( hFdCngCom->msFrCnt_init_counter < hFdCngCom->msFrCnt_init_thresh ) ) - { - sidNoiseEst_flt = hFdCngCom->sidNoiseEstLp_flt; - j = 0; - for ( k = 0; k < hFdCngCom->nFFTpart; k++ ) - { - factor = ( sidNoiseEst_flt[k] + DELTA ) / ( hFdCngDec->partNoiseShape_float[k] + DELTA ); - for ( ; j <= hFdCngCom->part[k]; j++ ) - { - cngNoiseLevel_flt[j] = hFdCngDec->bandNoiseShape_float[j] * factor; - } - } - } - } - if ( st->codec_mode == MODE2 ) - { - /* Generate comfort noise during SID or zero frames */ - generate_comfort_noise_dec( realBuffer, imagBuffer, st, -1 ); - } - - break; - - default: - break; - } - - pop_wmops(); - - return; -} + HANDLE_FD_CNG_DEC hFdCngDec = st->hFdCngDec; + HANDLE_FD_CNG_COM hFdCngCom = hFdCngDec->hFdCngCom; + float *cngNoiseLevel_flt = hFdCngCom->cngNoiseLevel_flt; + float *sidNoiseEst_flt = hFdCngCom->sidNoiseEst_flt; + int16_t j, k; + float factor; + float lsp_cng[M]; + int16_t L_frame, last_L_frame; + int32_t sr_core; + + push_wmops( "ApplyFdCng" ); + + /* limit L_frame and core Fs values for MDCT-Stereo modes which can have higher core sampling than 16kHz, but use a downsampled buffer */ + L_frame = min( st->L_frame, L_FRAME16k ); + last_L_frame = min( st->last_L_frame, L_FRAME16k ); + sr_core = min( st->sr_core, INT_FS_16k ); + + if ( hFdCngCom->frame_type_previous == ACTIVE_FRAME ) + { + hFdCngCom->inactive_frame_counter = 0; + } + + if ( st->element_mode == IVAS_CPE_TD ) + { + hFdCngDec->flag_dtx_mode = hFdCngDec->flag_dtx_mode || st->first_CNG; + } + + switch ( st->m_frame_type ) + { + + case ACTIVE_FRAME: + /************************** + * ACTIVE_FRAME at DECODER * + **************************/ + + hFdCngCom->inactive_frame_counter = 0; + hFdCngCom->sid_frame_counter = 0; + /* set noise estimation inactive during concealment, as no update with noise generated by concealment should be performed. */ + /* set noise estimation inactive when we have bit errors, as no update with noise generated by corrupt frame (biterror) should be performed. */ + if ( concealWholeFrame == 0 && + ( timeDomainInput == NULL || + ( *timeDomainInput( -FLT_MAX ) && + *( timeDomainInput + hFdCngCom->frameSize - 1 ) < FLT_MAX && + *( timeDomainInput + hFdCngCom->frameSize - 1 ) > ( -FLT_MAX ) ) ) && + ( ( ( ( st->element_mode != IVAS_CPE_TD && st->element_mode != IVAS_CPE_DFT && hFdCngDec->flag_dtx_mode ) || !st->VAD || ( st->ini_frame < 100 && st->is_ism_format ) ) && + !( st->cng_type == LP_CNG && hFdCngDec->flag_dtx_mode ) && ( is_music == 0 ) ) || + ( st->element_mode == IVAS_CPE_TD ) ) && + ( !st->BER_detect ) ) + { + /* Perform noise estimation at the decoder */ + perform_noise_estimation_dec( timeDomainInput, powerSpectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD ); + + if ( st->element_mode != IVAS_CPE_TD && st->element_mode != IVAS_CPE_DFT ) + { + /* Update the shaping parameters */ + scalebands_flt( hFdCngDec->msNoiseEst_float, hFdCngDec->part_shaping, hFdCngDec->nFFTpart_shaping, hFdCngDec->midband_shaping, hFdCngDec->nFFTpart_shaping, hFdCngCom->stopFFTbin - hFdCngCom->startBand, hFdCngDec->bandNoiseShape_float, 1 ); + } + + /* Update CNG levels */ + if ( hFdCngDec->flag_dtx_mode && st->cng_type == FD_CNG ) + { + bandcombinepow_flt( hFdCngDec->bandNoiseShape_float, hFdCngCom->stopFFTbin - hFdCngCom->startBand, hFdCngCom->part, hFdCngCom->nFFTpart, hFdCngCom->psize_inv_flt, hFdCngDec->partNoiseShape_float ); /* This needs to be done only once per inactive phase */ + + j = 0; + for ( k = 0; k < hFdCngCom->nFFTpart; k++ ) + { + factor = ( hFdCngCom->sidNoiseEst_flt[k] + DELTA ) / ( hFdCngDec->partNoiseShape_float[k] + DELTA ); + for ( ; j <= hFdCngCom->part[k]; j++ ) + { + cngNoiseLevel_flt[j] = hFdCngDec->bandNoiseShape_float[j] * factor; + } + } + } + else + { + /* This sets the new CNG levels until a SID update overwrites it */ + if ( !( st->element_mode == IVAS_CPE_TD ) || ( st->element_mode == IVAS_CPE_TD && !hFdCngDec->flag_dtx_mode && !st->VAD ) ) + { + mvr2r( hFdCngDec->bandNoiseShape_float, cngNoiseLevel_flt, hFdCngCom->stopFFTbin - hFdCngCom->startBand ); /* This sets the new CNG levels until a SID update overwrites it */ + } + } + + if ( st->element_mode == IVAS_CPE_MDCT && timeDomainInput == NULL ) + { + st->hTcxDec->CngLevelBackgroundTrace_bfi = sqrtf( sum_f( cngNoiseLevel_flt, hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / NORM_MDCT_FACTOR ); + } + else + { + st->hTcxDec->CngLevelBackgroundTrace_bfi = (float) sqrt( ( sum_f( cngNoiseLevel_flt, hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / 2 * hFdCngCom->fftlen ) / L_frame ); + } + st->cngTDLevel_float = (float) sqrt( ( sum_f( cngNoiseLevel_flt, hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / 2 * hFdCngCom->fftlen ) / st->L_frame ); + } + else if ( st->element_mode == IVAS_CPE_TD || st->element_mode == IVAS_CPE_DFT ) + { + if ( hFdCngCom->active_frame_counter > 0 ) + { + /* Perform noise estimation in active frames in the decoder for downward updates */ + perform_noise_estimation_dec( timeDomainInput, powerSpectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD ); + } + } + + if ( ( concealWholeFrame == 1 ) && ( st->nbLostCmpt == 1 ) ) + { + /* update lsf cng estimate for concealment. Do that during concealment, in order to avoid addition clean channel complexity*/ + /* always set psychParameters for MDCT-Stereo ... */ + if ( st->element_mode == IVAS_CPE_MDCT && st->hTonalMDCTConc != NULL ) + { + st->hTonalMDCTConc->psychParams = ( st->core == TCX_20_CORE ) ? &st->hTonalMDCTConc->psychParamsTCX20 : &st->hTonalMDCTConc->psychParamsTCX10; + } + + /* ... but do actual computations only if sufficient energy in noise shape */ + if ( sum_f( cngNoiseLevel_flt + hFdCngCom->startBand, hFdCngCom->stopFFTbin - hFdCngCom->startBand ) > 0.01f ) + { + if ( st->element_mode == IVAS_CPE_MDCT && st->core != ACELP_CORE ) + { + TonalMdctConceal_whiten_noise_shape_ivas( st, L_frame, ON_FIRST_LOST_FRAME ); + } + else if ( st->element_mode != IVAS_CPE_MDCT || st->core == ACELP_CORE ) + { + lpc_from_spectrum_flt( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, 0.f ); + a2lsp_stab( hFdCngCom->A_cng_flt, lsp_cng, st->lspold_cng_float ); + mvr2r( lsp_cng, st->lspold_cng_float, M ); + lsp2lsf( lsp_cng, st->lsf_cng_float, M, sr_core ); + } + st->plcBackgroundNoiseUpdated = 1; + } + } + break; + + case SID_FRAME: + hFdCngDec->flag_dtx_mode = 1; + /* FALLTHRU */ + + case ZERO_FRAME: + + if ( st != NULL && st->cng_type == LP_CNG ) + { + /* Perform noise estimation on inactive phase at the decoder */ + perform_noise_estimation_dec( timeDomainInput, powerSpectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD ); + + if ( st->element_mode != IVAS_CPE_TD && st->element_mode != IVAS_CPE_DFT ) + { + /* Update the shaping parameters */ + scalebands_flt( hFdCngDec->msNoiseEst_float, hFdCngDec->part_shaping, hFdCngDec->nFFTpart_shaping, hFdCngDec->midband_shaping, hFdCngDec->nFFTpart_shaping, hFdCngCom->stopFFTbin - hFdCngCom->startBand, hFdCngDec->bandNoiseShape_float, 1 ); + } + + /* This sets the new CNG levels until a SID update overwrites it */ + mvr2r( hFdCngDec->bandNoiseShape_float, cngNoiseLevel_flt, hFdCngCom->stopFFTbin - hFdCngCom->startBand ); /* This sets the new CNG levels until a SID update overwrites it */ + + st->cngTDLevel_float = (float) sqrt( ( sum_f( cngNoiseLevel_flt, hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / 2 * hFdCngCom->fftlen ) / L_frame ); + break; + } + + hFdCngCom->inactive_frame_counter++; + + /************************************* + * SID_FRAME or ZERO_FRAME at DECODER * + *************************************/ + + /* Detect first non-active frame */ + if ( hFdCngCom->inactive_frame_counter == 1 ) + { + /* Compute the fine spectral structure of the comfort noise shape using the decoder-side noise estimates */ + bandcombinepow_flt( hFdCngDec->bandNoiseShape_float, hFdCngCom->stopFFTbin - hFdCngCom->startBand, hFdCngCom->part, hFdCngCom->nFFTpart, hFdCngCom->psize_inv_flt, hFdCngDec->partNoiseShape_float ); + + if ( st->element_mode == IVAS_CPE_DFT ) + { + mvr2r( st->hFdCngDec->hFdCngCom->sidNoiseEst_flt, st->hFdCngDec->hFdCngCom->sidNoiseEstLp_flt, NPART ); + } + } + + if ( st->m_frame_type == SID_FRAME ) + { + if ( hFdCngCom->msFrCnt_init_counter < hFdCngCom->msFrCnt_init_thresh ) + { + /* At initialization, interpolate the bin/band-wise levels from the partition levels */ + scalebands_flt( sidNoiseEst_flt, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, hFdCngCom->stopBand - hFdCngCom->startBand, cngNoiseLevel_flt, 1 ); + } + else + { + if ( st->element_mode == IVAS_CPE_DFT ) + { + sidNoiseEst_flt = hFdCngCom->sidNoiseEstLp_flt; + } + + /* Interpolate the CLDFB band levels from the SID (partition) levels */ + if ( hFdCngCom->regularStopBand > hFdCngCom->numCoreBands ) + { + scalebands_flt( sidNoiseEst_flt, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, hFdCngCom->stopBand - hFdCngCom->startBand, cngNoiseLevel_flt, 0 ); + } + + + /* Shape the SID noise levels in each FFT bin */ + j = 0; + for ( k = 0; k < hFdCngCom->nFFTpart; k++ ) + { + factor = ( sidNoiseEst_flt[k] + DELTA ) / ( hFdCngDec->partNoiseShape_float[k] + DELTA ); + for ( ; j <= hFdCngCom->part[k]; j++ ) + { + cngNoiseLevel_flt[j] = hFdCngDec->bandNoiseShape_float[j] * factor; + } + } + } + } + else if ( st->element_mode == IVAS_CPE_DFT ) + { + if ( !( hFdCngCom->msFrCnt_init_counter < hFdCngCom->msFrCnt_init_thresh ) ) + { + sidNoiseEst_flt = hFdCngCom->sidNoiseEstLp_flt; + j = 0; + for ( k = 0; k < hFdCngCom->nFFTpart; k++ ) + { + factor = ( sidNoiseEst_flt[k] + DELTA ) / ( hFdCngDec->partNoiseShape_float[k] + DELTA ); + for ( ; j <= hFdCngCom->part[k]; j++ ) + { + cngNoiseLevel_flt[j] = hFdCngDec->bandNoiseShape_float[j] * factor; + } + } + } + } + if ( st->codec_mode == MODE2 ) + { + /* Generate comfort noise during SID or zero frames */ + generate_comfort_noise_dec( realBuffer, imagBuffer, st, -1 ); + } + + break; + + default: + break; + } + + pop_wmops(); + + return; +} /*------------------------------------------------------------------- @@ -1285,7 +1284,7 @@ static void perform_noise_estimation_dec( /* Call the minimum statistics routine for noise estimation */ minimum_statistics_flt( npart, nFFTpart, psize_flt, msLogPeriodog, hFdCngDec->msNoiseFloor_float, msLogNoiseEst, hFdCngDec->msAlpha_float, hFdCngDec->msPsd_float, hFdCngDec->msPsdFirstMoment_float, hFdCngDec->msPsdSecondMoment_float, hFdCngDec->msMinBuf_float, hFdCngDec->msBminWin_float, hFdCngDec->msBminSubWin_float, hFdCngDec->msCurrentMin_float, hFdCngDec->msCurrentMinOut_float, hFdCngDec->msCurrentMinSubWindow_float, hFdCngDec->msLocalMinFlag, hFdCngDec->msNewMinFlag, hFdCngDec->msPeriodogBuf_float, &( hFdCngDec->msPeriodogBufPtr ), hFdCngDec->hFdCngCom, - DEC, element_mode ); + DEC, element_mode ); /* Expand MS outputs */ expand_range_flt( msLogNoiseEst, msNoiseEst, npart ); @@ -1344,7 +1343,7 @@ void FdCng_decodeSID( } else { /* Legacy EVS_MONO MSVQ tables */ - msvq_dec_float(cdk_37bits_flt, NULL, NULL, FD_CNG_stages_37bits, N, FD_CNG_maxN_37bits, indices, 0, NULL, v, NULL ); + msvq_dec_float( cdk_37bits_flt, NULL, NULL, FD_CNG_stages_37bits, N, FD_CNG_maxN_37bits, indices, 0, NULL, v, NULL ); } @@ -1371,7 +1370,7 @@ void FdCng_decodeSID( scalebands_flt( sidNoiseEst_flt, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, hFdCngCom->stopBand - hFdCngCom->startBand, hFdCngCom->cngNoiseLevel_flt, 1 ); - lpc_from_spectrum_flt( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, st->preemph_fac_float); + lpc_from_spectrum_flt( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, st->preemph_fac_float ); return; } @@ -1399,11 +1398,11 @@ void FdCng_decodeSID_ivas_fx( Word32 *invTrfMatrix_fx; Word32 tmpRAM_fx[FDCNG_VQ_MAX_LEN][FDCNG_VQ_DCT_MAXTRUNC]; - const Word16 gain_q_offset = (Word16)((st->element_mode == EVS_MONO) ? GAIN_Q_OFFSET_EVS : GAIN_Q_OFFSET_IVAS); //Q0 + const Word16 gain_q_offset = (Word16) ( ( st->element_mode == EVS_MONO ) ? GAIN_Q_OFFSET_EVS : GAIN_Q_OFFSET_IVAS ); // Q0 - invTrfMatrix_fx = (Word32 *)tmpRAM_fx; + invTrfMatrix_fx = (Word32 *) tmpRAM_fx; - hFdCngCom = (st->hFdCngDec)->hFdCngCom; + hFdCngCom = ( st->hFdCngDec )->hFdCngCom; sidNoiseEst = hFdCngCom->sidNoiseEst; @@ -1412,64 +1411,66 @@ void FdCng_decodeSID_ivas_fx( hFdCngCom->sid_frame_counter++; /* Read bitstream */ - for (i = 0; i < FD_CNG_stages_37bits; i++) + for ( i = 0; i < FD_CNG_stages_37bits; i++ ) { - indices[i] = get_next_indice(st, bits_37bits[i]); + indices[i] = get_next_indice( st, bits_37bits[i] ); } - index = get_next_indice(st, 7); + index = get_next_indice( st, 7 ); /* MSVQ decoder */ - if (st->element_mode != EVS_MONO) + if ( st->element_mode != EVS_MONO ) { - create_IDCT_N_Matrix_fx(invTrfMatrix_fx, FDCNG_VQ_MAX_LEN, FDCNG_VQ_DCT_MAXTRUNC, sizeof(tmpRAM_fx) / (sizeof(Word32))); - msvq_dec_fx(ivas_cdk_37bits_fx, NULL, NULL, FD_CNG_stages_37bits, N, FD_CNG_maxN_37bits, indices, 1, invTrfMatrix_fx, v, NULL, 7); + create_IDCT_N_Matrix_fx( invTrfMatrix_fx, FDCNG_VQ_MAX_LEN, FDCNG_VQ_DCT_MAXTRUNC, sizeof( tmpRAM_fx ) / ( sizeof( Word32 ) ) ); + msvq_dec_fx( ivas_cdk_37bits_fx, NULL, NULL, FD_CNG_stages_37bits, N, FD_CNG_maxN_37bits, indices, 1, invTrfMatrix_fx, v, NULL, 7 ); } else { /* Legacy EVS_MONO MSVQ tables */ - msvq_dec_fx(cdk_37bits, NULL, NULL, FD_CNG_stages_37bits, N, FD_CNG_maxN_37bits, indices, 0, NULL, v, NULL, 7); + msvq_dec_fx( cdk_37bits, NULL, NULL, FD_CNG_stages_37bits, N, FD_CNG_maxN_37bits, indices, 0, NULL, v, NULL, 7 ); } /* Decode gain */ - //gain = ((float)index - gain_q_offset) / 1.5f; - gain = L_mult0((index - gain_q_offset), 21845); // Q15 + // gain = ((float)index - gain_q_offset) / 1.5f; + gain = L_mult0( ( index - gain_q_offset ), 21845 ); // Q15 /* Apply gain and undo log */ Word16 res_exp[NPART]; Word16 max_res_exp = 0; - for (i = 0; i < N; i++) + for ( i = 0; i < N; i++ ) { - //sidNoiseEst_flt[i] = (float)pow(10.f, (v[i] + gain) / 10.f); - sidNoiseEst[i] = BASOP_util_Pow2( Mpy_32_32( L_add(v[i], gain), LOG_10_BASE_2_BY_10_Q31), Q16, &res_exp[i]); - if (max_res_exp < res_exp[i]) { + // sidNoiseEst_flt[i] = (float)pow(10.f, (v[i] + gain) / 10.f); + sidNoiseEst[i] = BASOP_util_Pow2( Mpy_32_32( L_add( v[i], gain ), LOG_10_BASE_2_BY_10_Q31 ), Q16, &res_exp[i] ); + if ( max_res_exp < res_exp[i] ) + { max_res_exp = res_exp[i]; } } - for (i = 0; i < N; i++) { - sidNoiseEst[i] = L_shr(sidNoiseEst[i], max_res_exp - res_exp[i]); + for ( i = 0; i < N; i++ ) + { + sidNoiseEst[i] = L_shr( sidNoiseEst[i], max_res_exp - res_exp[i] ); } hFdCngCom->sidNoiseEstExp = max_res_exp; /* NB last band energy compensation */ - if (hFdCngCom->CngBandwidth == NB) + if ( hFdCngCom->CngBandwidth == NB ) { - sidNoiseEst[N - 1] = Mpy_32_16_1(sidNoiseEst[N - 1], NB_LAST_BAND_SCALE); + sidNoiseEst[N - 1] = Mpy_32_16_1( sidNoiseEst[N - 1], NB_LAST_BAND_SCALE ); } - if (hFdCngCom->CngBandwidth == SWB && hFdCngCom->CngBitrate <= ACELP_13k20) + if ( hFdCngCom->CngBandwidth == SWB && hFdCngCom->CngBitrate <= ACELP_13k20 ) { - sidNoiseEst[N - 1] = Mpy_32_16_1(sidNoiseEst[N - 1], SWB_13k2_LAST_BAND_SCALE); + sidNoiseEst[N - 1] = Mpy_32_16_1( sidNoiseEst[N - 1], SWB_13k2_LAST_BAND_SCALE ); } - scalebands(sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, hFdCngCom->stopBand - hFdCngCom->startBand, hFdCngCom->cngNoiseLevel, 1); + scalebands( sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, hFdCngCom->stopBand - hFdCngCom->startBand, hFdCngCom->cngNoiseLevel, 1 ); hFdCngCom->cngNoiseLevelExp = hFdCngCom->sidNoiseEstExp; - lpc_from_spectrum(hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, st->preemph_fac); + lpc_from_spectrum( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, st->preemph_fac ); return; } @@ -1510,7 +1511,7 @@ void noisy_speech_detection( return; } -#endif +#endif /*------------------------------------------------------------------- * generate_comfort_noise_dec() @@ -1544,8 +1545,8 @@ void generate_comfort_noise_dec( scale = 1.f; scaleCldfb = CLDFB_SCALING_FLT / hFdCngCom->scalingFactor_flt; - c1 = (float) sqrt( hFdCngCom->coherence_flt); - c2 = (float) sqrt( 1 - hFdCngCom->coherence_flt); + c1 = (float) sqrt( hFdCngCom->coherence_flt ); + c2 = (float) sqrt( 1 - hFdCngCom->coherence_flt ); seed2 = &( hFdCngCom->seed2 ); if ( st->element_mode == IVAS_CPE_MDCT && st->idchan == 1 ) @@ -1715,7 +1716,7 @@ void generate_comfort_noise_dec( if ( st->core > ACELP_CORE ) { tcx_windowing_synthesis_current_frame_flt( timeDomainOutput, st->hTcxCfg->tcx_mdct_window_flt, /*Keep sine windows for limiting Time modulation*/ - st->hTcxCfg->tcx_mdct_window_half_flt, st->hTcxCfg->tcx_mdct_window_minimum_flt, st->hTcxCfg->tcx_mdct_window_length, st->hTcxCfg->tcx_mdct_window_half_length, st->hTcxCfg->tcx_mdct_window_min_length, 0, st->hTcxCfg->tcx_last_overlap_mode == ALDO_WINDOW ? FULL_OVERLAP : st->hTcxCfg->tcx_last_overlap_mode, NULL, NULL, NULL, NULL, NULL, N / 2, st->hTcxCfg->tcx_offset < 0 ? -st->hTcxCfg->tcx_offset : 0, 1, 0, 0 ); + st->hTcxCfg->tcx_mdct_window_half_flt, st->hTcxCfg->tcx_mdct_window_minimum_flt, st->hTcxCfg->tcx_mdct_window_length, st->hTcxCfg->tcx_mdct_window_half_length, st->hTcxCfg->tcx_mdct_window_min_length, 0, st->hTcxCfg->tcx_last_overlap_mode == ALDO_WINDOW ? FULL_OVERLAP : st->hTcxCfg->tcx_last_overlap_mode, NULL, NULL, NULL, NULL, NULL, N / 2, st->hTcxCfg->tcx_offset < 0 ? -st->hTcxCfg->tcx_offset : 0, 1, 0, 0 ); if ( st->hTcxCfg->last_aldo ) { @@ -1807,8 +1808,8 @@ void generate_comfort_noise_dec_hf( { seed2 = &( hFdCngCom->seed2 ); - c1 = (float) sqrt( hFdCngCom->coherence_flt); - c2 = (float) sqrt( 1 - hFdCngCom->coherence_flt); + c1 = (float) sqrt( hFdCngCom->coherence_flt ); + c2 = (float) sqrt( 1 - hFdCngCom->coherence_flt ); } ptr_level = hFdCngCom->cngNoiseLevel_flt + hFdCngCom->stopFFTbin - hFdCngCom->startBand; @@ -2022,13 +2023,13 @@ void generate_masking_noise_ivas_fx( Word32 scale_fx = 0x40000000; // 1.0 in Q30 move32(); - Word16 shift = getScaleFactor32(hFdCngCom->cngNoiseLevel, FFTCLDFBLEN); - IF(LT_16(sub(hFdCngCom->cngNoiseLevelExp, shift), 4)) + Word16 shift = getScaleFactor32( hFdCngCom->cngNoiseLevel, FFTCLDFBLEN ); + IF( LT_16( sub( hFdCngCom->cngNoiseLevelExp, shift ), 4 ) ) { - shift = sub(hFdCngCom->cngNoiseLevelExp, 4); + shift = sub( hFdCngCom->cngNoiseLevelExp, 4 ); } - scale_sig32(hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift); - hFdCngCom->cngNoiseLevelExp = sub(hFdCngCom->cngNoiseLevelExp, shift); + scale_sig32( hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); + hFdCngCom->cngNoiseLevelExp = sub( hFdCngCom->cngNoiseLevelExp, shift ); /* skip noise generating if level is very low, to avoid problems with possibly running into denormals */ *exp_out = Q15; @@ -2411,7 +2412,7 @@ void generate_stereo_masking_noise( *-------------------------------------------------------------------*/ void generate_stereo_masking_noise_fx( - Word16 *syn, /* i/o: time-domain signal */ + Word16 *syn, /* i/o: time-domain signal */ Word16 Q_syn, Decoder_State *st, /* i/o: decoder state structure */ STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i : TD stereo structure */ @@ -2430,92 +2431,92 @@ void generate_stereo_masking_noise_fx( Word16 N1_fx_exp, N2_fx_exp; int16_t i; - IF(st->idchan == 0) + IF( st->idchan == 0 ) { hFdCngCom = st->hFdCngDec->hFdCngCom; Copy_Scale_sig_16_32( hStereoCng->olapBufferSynth22_fx, Ns_fx, hFdCngCom->frameSize / 2, Q6 - st->Q_syn ); - Copy32(hFdCngCom->olapBufferSynth2_fx, Np_fx, hFdCngCom->frameSize / 2); + Copy32( hFdCngCom->olapBufferSynth2_fx, Np_fx, hFdCngCom->frameSize / 2 ); - set_l(&Np_fx[hFdCngCom->frameSize / 2], 0, hFdCngCom->frameSize / 2); - set_l(&Ns_fx[hFdCngCom->frameSize / 2], 0, hFdCngCom->frameSize / 2); + set_l( &Np_fx[hFdCngCom->frameSize / 2], 0, hFdCngCom->frameSize / 2 ); + set_l( &Ns_fx[hFdCngCom->frameSize / 2], 0, hFdCngCom->frameSize / 2 ); - IF(!fadeOut) + IF( !fadeOut ) { // generate_masking_noise(N1, hFdCngCom, hFdCngCom->frameSize, 0, 1, 0, st->element_mode, hStereoCng, nchan_out); - Copy_Scale_sig_16_32( hStereoCng->olapBufferSynth22_fx, hStereoCng->olapBufferSynth22_32fx, hFdCngCom->fftlen, -(st->Q_syn - 15) ); + Copy_Scale_sig_16_32( hStereoCng->olapBufferSynth22_fx, hStereoCng->olapBufferSynth22_32fx, hFdCngCom->fftlen, -( st->Q_syn - 15 ) ); - generate_masking_noise_ivas_fx(N1_fx, &N1_fx_exp, hFdCngCom, hFdCngCom->frameSize, 0, 1, 0, st->element_mode, hStereoCng, nchan_out); // N1_fx Q6 + generate_masking_noise_ivas_fx( N1_fx, &N1_fx_exp, hFdCngCom, hFdCngCom->frameSize, 0, 1, 0, st->element_mode, hStereoCng, nchan_out ); // N1_fx Q6 /* Generate masking noise for secondary channel */ - IF(flag_sec_CNA) + IF( flag_sec_CNA ) { // generate_masking_noise(N2, hFdCngCom, hFdCngCom->frameSize, 0, 1, 1, st->element_mode, hStereoCng, nchan_out); - generate_masking_noise_ivas_fx(N2_fx, &N2_fx_exp, hFdCngCom, hFdCngCom->frameSize, 0, 1, 1, st->element_mode, hStereoCng, nchan_out); // N2_fx Q6 + generate_masking_noise_ivas_fx( N2_fx, &N2_fx_exp, hFdCngCom, hFdCngCom->frameSize, 0, 1, 1, st->element_mode, hStereoCng, nchan_out ); // N2_fx Q6 // gamma = hStereoCng->c_PS_LT * hStereoCng->c_PS_LT; gamma_fx = L_shr( Mpy_32_32( hStereoCng->c_PS_LT_fx, hStereoCng->c_PS_LT_fx ), 1 ); // scale = 1.0f; scale_fx = ONE_IN_Q30; // if (gamma < 0.9f) - IF(gamma_fx < 966367642) + IF( gamma_fx < 966367642 ) { // gamma = gamma / (1 - gamma); // gamma = (float)sqrt(gamma + 1) - (float)sqrt(gamma); // scale = 1.0f / (float)sqrt(1 + gamma * gamma); Word16 exp_gamma = 0; - Word16 divisor1 = Inv16((Word16)L_shr(L_sub(ONE_IN_Q30, gamma_fx), Q15), &exp_gamma); // Q15-exp_gamma - gamma_fx = L_shl(Mpy_32_16_1(gamma_fx, divisor1), exp_gamma); // Q30 + Word16 divisor1 = Inv16( (Word16) L_shr( L_sub( ONE_IN_Q30, gamma_fx ), Q15 ), &exp_gamma ); // Q15-exp_gamma + gamma_fx = L_shl( Mpy_32_16_1( gamma_fx, divisor1 ), exp_gamma ); // Q30 Word16 exp_gamma1 = Q1, exp_gamma2 = Q1, exp_gamma3 = Q1; - gamma_fx = Sqrt32(L_add(gamma_fx, ONE_IN_Q30), &exp_gamma1); + gamma_fx = Sqrt32( L_add( gamma_fx, ONE_IN_Q30 ), &exp_gamma1 ); // gamma_fx = L_shl( gamma_fx, exp_gamma1 ); - Word32 temp = Sqrt32(gamma_fx, &exp_gamma2); // Q31-exp_gamma1 - gamma_fx = L_sub(gamma_fx, L_shl(temp, exp_gamma2 - exp_gamma1)); // Q31-exp_gamma1 - gamma_fx = L_shl(gamma_fx, exp_gamma1 - Q1); // Q30 - Word32 divisor2 = Sqrt32(L_add(ONE_IN_Q30, L_shl(Mpy_32_32(gamma_fx, gamma_fx), Q1)), &exp_gamma3); // Q31 - exp_gamma3 - scale_fx = L_shl(divide3232(ONE_IN_Q30, divisor2), Q15 + exp_gamma3); // Q30 + Word32 temp = Sqrt32( gamma_fx, &exp_gamma2 ); // Q31-exp_gamma1 + gamma_fx = L_sub( gamma_fx, L_shl( temp, exp_gamma2 - exp_gamma1 ) ); // Q31-exp_gamma1 + gamma_fx = L_shl( gamma_fx, exp_gamma1 - Q1 ); // Q30 + Word32 divisor2 = Sqrt32( L_add( ONE_IN_Q30, L_shl( Mpy_32_32( gamma_fx, gamma_fx ), Q1 ) ), &exp_gamma3 ); // Q31 - exp_gamma3 + scale_fx = L_shl( divide3232( ONE_IN_Q30, divisor2 ), Q15 + exp_gamma3 ); // Q30 } ELSE { gamma_fx = 0; } - FOR(i = 0; i < 2 * hFdCngCom->frameSize / 4; i++) + FOR( i = 0; i < 2 * hFdCngCom->frameSize / 4; i++ ) { // Np[i] += scale * (N1[i] + gamma * N2[i]); // Ns[i] += scale * sign(hStereoCng->c_PS_LT) * (N1[i] - gamma * N2[i]); - Np_fx[i] = L_add(Np_fx[i], - Mpy_32_32(scale_fx, L_shl(L_add(N1_fx[i], Mpy_32_32(gamma_fx, L_shl(N2_fx[i], Q1))), Q1))); // Q6 - Word32 add2 = Mpy_32_32(scale_fx, L_shl(L_sub(N1_fx[i], Mpy_32_32(gamma_fx, L_shl(N2_fx[i], Q1))), Q1)); // Q6 - if (hStereoCng->c_PS_LT_fx < 0) + Np_fx[i] = L_add( Np_fx[i], + Mpy_32_32( scale_fx, L_shl( L_add( N1_fx[i], Mpy_32_32( gamma_fx, L_shl( N2_fx[i], Q1 ) ) ), Q1 ) ) ); // Q6 + Word32 add2 = Mpy_32_32( scale_fx, L_shl( L_sub( N1_fx[i], Mpy_32_32( gamma_fx, L_shl( N2_fx[i], Q1 ) ) ), Q1 ) ); // Q6 + if ( hStereoCng->c_PS_LT_fx < 0 ) { - add2 = L_negate(add2); + add2 = L_negate( add2 ); } - Ns_fx[i] = L_add(Ns_fx[i], add2); + Ns_fx[i] = L_add( Ns_fx[i], add2 ); } - FOR(; i < hFdCngCom->frameSize; i++) + FOR( ; i < hFdCngCom->frameSize; i++ ) { // Np[i] = scale * (N1[i] + gamma * N2[i]); // Ns[i] = scale * sign(hStereoCng->c_PS_LT) * (N1[i] - gamma * N2[i]); - Np_fx[i] = Mpy_32_32(scale_fx, L_shl(L_add(N1_fx[i], Mpy_32_32(gamma_fx, L_shl(N2_fx[i], Q1))), Q1)); // Q6 - Ns_fx[i] = Mpy_32_32(scale_fx, L_shl(L_sub(N1_fx[i], Mpy_32_32(gamma_fx, L_shl(N2_fx[i], Q1))), Q1)); // Q6 - IF(hStereoCng->c_PS_LT_fx < 0) + Np_fx[i] = Mpy_32_32( scale_fx, L_shl( L_add( N1_fx[i], Mpy_32_32( gamma_fx, L_shl( N2_fx[i], Q1 ) ) ), Q1 ) ); // Q6 + Ns_fx[i] = Mpy_32_32( scale_fx, L_shl( L_sub( N1_fx[i], Mpy_32_32( gamma_fx, L_shl( N2_fx[i], Q1 ) ) ), Q1 ) ); // Q6 + IF( hStereoCng->c_PS_LT_fx < 0 ) { - Ns_fx[i] = L_negate(Ns_fx[i]); + Ns_fx[i] = L_negate( Ns_fx[i] ); } } /* Below code to be converted */ - Word32 scale_fx_tmp = Mpy_32_32(scale_fx, L_shl(hFdCngCom->fftlen / 2, Q22)); // Q21 + Word32 scale_fx_tmp = Mpy_32_32( scale_fx, L_shl( hFdCngCom->fftlen / 2, Q22 ) ); // Q21 // scale_fx = L_shr(scale_fx, Q1) * hFdCngCom->fftlen; - for (i = 0; i < hFdCngCom->frameSize / 2; i++) + for ( i = 0; i < hFdCngCom->frameSize / 2; i++ ) { - //hFdCngCom->olapBufferSynth2_flt[i] = scale * (hFdCngCom->olapBufferSynth2_flt[i + 5 * hFdCngCom->frameSize / 4] + gamma * hStereoCng->olapBufferSynth22[i + 5 * hFdCngCom->frameSize / 4]); - //hStereoCng->olapBufferSynth22[i] = sign(hStereoCng->c_PS_LT) * scale * (hFdCngCom->olapBufferSynth2_flt[i + 5 * hFdCngCom->frameSize / 4] - gamma * hStereoCng->olapBufferSynth22[i + 5 * hFdCngCom->frameSize / 4]); - hFdCngCom->olapBufferSynth2[i] = (Word16)L_shr(Mpy_32_32(scale_fx_tmp, - L_add(L_shr(hFdCngCom->olapBufferSynth2[i + 5 * hFdCngCom->frameSize / 4], Q15), - Mpy_32_16_1(gamma_fx, hStereoCng->olapBufferSynth22_fx[i + 5 * hFdCngCom->frameSize / 4]))), - Q14); // Q_olap - hStereoCng->olapBufferSynth22_fx[i] = (Word16)L_shr(Mpy_32_32(scale_fx_tmp, - L_sub(L_shr(hFdCngCom->olapBufferSynth2[i + 5 * hFdCngCom->frameSize / 4], Q15), - Mpy_32_16_1(gamma_fx, hStereoCng->olapBufferSynth22_fx[i + 5 * hFdCngCom->frameSize / 4]))), - Q14); // Q_olap + // hFdCngCom->olapBufferSynth2_flt[i] = scale * (hFdCngCom->olapBufferSynth2_flt[i + 5 * hFdCngCom->frameSize / 4] + gamma * hStereoCng->olapBufferSynth22[i + 5 * hFdCngCom->frameSize / 4]); + // hStereoCng->olapBufferSynth22[i] = sign(hStereoCng->c_PS_LT) * scale * (hFdCngCom->olapBufferSynth2_flt[i + 5 * hFdCngCom->frameSize / 4] - gamma * hStereoCng->olapBufferSynth22[i + 5 * hFdCngCom->frameSize / 4]); + hFdCngCom->olapBufferSynth2[i] = (Word16) L_shr( Mpy_32_32( scale_fx_tmp, + L_add( L_shr( hFdCngCom->olapBufferSynth2[i + 5 * hFdCngCom->frameSize / 4], Q15 ), + Mpy_32_16_1( gamma_fx, hStereoCng->olapBufferSynth22_fx[i + 5 * hFdCngCom->frameSize / 4] ) ) ), + Q14 ); // Q_olap + hStereoCng->olapBufferSynth22_fx[i] = (Word16) L_shr( Mpy_32_32( scale_fx_tmp, + L_sub( L_shr( hFdCngCom->olapBufferSynth2[i + 5 * hFdCngCom->frameSize / 4], Q15 ), + Mpy_32_16_1( gamma_fx, hStereoCng->olapBufferSynth22_fx[i + 5 * hFdCngCom->frameSize / 4] ) ) ), + Q14 ); // Q_olap } } else @@ -2536,56 +2537,55 @@ void generate_stereo_masking_noise_fx( } } - Copy_Scale_sig_32_16(hStereoCng->olapBufferSynth22_32fx, hStereoCng->olapBufferSynth22_fx, hFdCngCom->fftlen, (st->Q_syn - 15)); - + Copy_Scale_sig_32_16( hStereoCng->olapBufferSynth22_32fx, hStereoCng->olapBufferSynth22_fx, hFdCngCom->fftlen, ( st->Q_syn - 15 ) ); } else { - set_s(hFdCngCom->olapBufferSynth2, 0, hFdCngCom->frameSize / 2); - set_s(hStereoCng->olapBufferSynth22_fx, 0, hFdCngCom->frameSize / 2); + set_s( hFdCngCom->olapBufferSynth2, 0, hFdCngCom->frameSize / 2 ); + set_s( hStereoCng->olapBufferSynth22_fx, 0, hFdCngCom->frameSize / 2 ); } - if (flag_sec_CNA) + if ( flag_sec_CNA ) { - Copy_Scale_sig_32_16(Ns_fx, hStereoCng->maskingNoiseS_fx, hFdCngCom->frameSize, 0); // Q6 + Copy_Scale_sig_32_16( Ns_fx, hStereoCng->maskingNoiseS_fx, hFdCngCom->frameSize, 0 ); // Q6 hStereoCng->enableSecCNA = 1; } else { - set_s(hStereoCng->olapBufferSynth22_fx, 0, hFdCngCom->frameSize); + set_s( hStereoCng->olapBufferSynth22_fx, 0, hFdCngCom->frameSize ); } /* add masking noise */ // v_add(Np, syn, syn, hFdCngCom->frameSize); - for (i = 0; i < hFdCngCom->frameSize; i++) + for ( i = 0; i < hFdCngCom->frameSize; i++ ) { - syn[i] = syn[i] + (Word16)L_shr(Np_fx[i], Q16 + Q6 - Q_syn); // Q_syn + syn[i] = syn[i] + (Word16) L_shr( Np_fx[i], Q16 + Q6 - Q_syn ); // Q_syn } } - else if (hStereoCng->enableSecCNA) - { - Word16 SP_ratio_fx = extract_h( hStereoTD->SP_ratio_LT_fx ); /* Use long-term SP ratio based on L/R synthesis */ - Word16 prevSP_ratio_fx = hStereoTD->prevSP_ratio_fx; /* Use long-term SP ratio based on L/R synthesis */ - /* scale and add masking noise */ - for (i = 0; i < *hStereoCng->frameSize / 4; i++) - { - //Word16 scale_fx_tmp = idiv1616( add( imult1616( prevSP_ratio_fx, sub( shr( *hStereoCng->frameSize, 2 ), i ) ), imult1616( SP_ratio_fx, i ) ), shr( *hStereoCng->frameSize, 2 ) ); // Q15 - Word16 s; - Word16 scale_fx_tmp = BASOP_Util_Divide3216_Scale( L_add( L_mult0( prevSP_ratio_fx, sub( shr( *hStereoCng->frameSize, 2 ), i ) ), L_mult0( SP_ratio_fx, i ) ), shr( *hStereoCng->frameSize, 2 ), &s ); // Q15 - scale_fx_tmp = shl(scale_fx_tmp, s); - //syn[i] += scale * hStereoCng->maskingNoiseS[i]; - syn[i] = add( syn[i], mult( scale_fx_tmp, shr( hStereoCng->maskingNoiseS_fx[i], Q6 - Q_syn ) ) ); - } - for (; i < *hStereoCng->frameSize / 2; i++) - { - //syn[i] += SP_ratio * hStereoCng->maskingNoiseS[i]; - syn[i] = add( syn[i], mult( SP_ratio_fx, shr( hStereoCng->maskingNoiseS_fx[i], Q6 - Q_syn ) ) ); - } - for (; i < *hStereoCng->frameSize; i++) + else if ( hStereoCng->enableSecCNA ) { - //syn[i] += SP_ratio * hStereoCng->maskingNoiseS[i]; - syn[i] = add( syn[i], mult( SP_ratio_fx, shr( hStereoCng->maskingNoiseS_fx[i], Q6 - Q_syn ) ) ); - } - hStereoTD->prevSP_ratio_fx = extract_h(hStereoTD->SP_ratio_LT_fx); + Word16 SP_ratio_fx = extract_h( hStereoTD->SP_ratio_LT_fx ); /* Use long-term SP ratio based on L/R synthesis */ + Word16 prevSP_ratio_fx = hStereoTD->prevSP_ratio_fx; /* Use long-term SP ratio based on L/R synthesis */ + /* scale and add masking noise */ + for ( i = 0; i < *hStereoCng->frameSize / 4; i++ ) + { + // Word16 scale_fx_tmp = idiv1616( add( imult1616( prevSP_ratio_fx, sub( shr( *hStereoCng->frameSize, 2 ), i ) ), imult1616( SP_ratio_fx, i ) ), shr( *hStereoCng->frameSize, 2 ) ); // Q15 + Word16 s; + Word16 scale_fx_tmp = BASOP_Util_Divide3216_Scale( L_add( L_mult0( prevSP_ratio_fx, sub( shr( *hStereoCng->frameSize, 2 ), i ) ), L_mult0( SP_ratio_fx, i ) ), shr( *hStereoCng->frameSize, 2 ), &s ); // Q15 + scale_fx_tmp = shl( scale_fx_tmp, s ); + // syn[i] += scale * hStereoCng->maskingNoiseS[i]; + syn[i] = add( syn[i], mult( scale_fx_tmp, shr( hStereoCng->maskingNoiseS_fx[i], Q6 - Q_syn ) ) ); + } + for ( ; i < *hStereoCng->frameSize / 2; i++ ) + { + // syn[i] += SP_ratio * hStereoCng->maskingNoiseS[i]; + syn[i] = add( syn[i], mult( SP_ratio_fx, shr( hStereoCng->maskingNoiseS_fx[i], Q6 - Q_syn ) ) ); + } + for ( ; i < *hStereoCng->frameSize; i++ ) + { + // syn[i] += SP_ratio * hStereoCng->maskingNoiseS[i]; + syn[i] = add( syn[i], mult( SP_ratio_fx, shr( hStereoCng->maskingNoiseS_fx[i], Q6 - Q_syn ) ) ); + } + hStereoTD->prevSP_ratio_fx = extract_h( hStereoTD->SP_ratio_LT_fx ); } return; @@ -2691,7 +2691,6 @@ void generate_masking_noise_lb_dirac( /* Perform STFT synthesis */ SynthesisSTFT_dirac_flt( fftBuffer, tdBuffer + n_samples_start, hFdCngCom->olapBufferSynth2_flt, hFdCngCom->olapWinSyn_flt, n_samples_out_loop, hFdCngCom ); - } else @@ -2703,7 +2702,6 @@ void generate_masking_noise_lb_dirac( /* Perform STFT synthesis */ SynthesisSTFT_dirac_flt( fftBuffer, tdBuffer + n_samples_start, hFdCngCom->olapBufferSynth2_flt, hFdCngCom->olapWinSyn_flt, n_samples_out_loop, hFdCngCom ); - } n_samples_out -= hFdCngCom->frameSize; n_samples_start += hFdCngCom->frameSize; @@ -2718,9 +2716,9 @@ void generate_masking_noise_lb_dirac( #ifdef IVAS_FLOAT_FIXED void generate_masking_noise_lb_dirac_fx( HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ - Word32 *tdBuffer, /* i/o: time-domain signal, if NULL no LB-CNA */ - const Word16 nCldfbTs, /* i : number of CLDFB slots that will be rendered */ - const Word16 cna_flag /* i : CNA flag for LB and HB */ + Word32 *tdBuffer, /* i/o: time-domain signal, if NULL no LB-CNA */ + const Word16 nCldfbTs, /* i : number of CLDFB slots that will be rendered */ + const Word16 cna_flag /* i : CNA flag for LB and HB */ ) { Word16 i; @@ -2737,92 +2735,93 @@ void generate_masking_noise_lb_dirac_fx( /* Init */ scale = 0; - n_samples_out = i_mult(shr(hFdCngCom->frameSize, 4), nCldfbTs); + n_samples_out = i_mult( shr( hFdCngCom->frameSize, 4 ), nCldfbTs ); n_samples_start = 0; Word16 exp_out = Q15; /*LB CLDFB - CNA from STFT*/ - IF ( cna_flag ) + IF( cna_flag ) { /* skip noise generating if level is very low, to avoid problems with possibly running into denormals */ - IF ( GT_32(hFdCngCom->likelihood_noisy_speech_32fx, DELTA_MASKING_NOISE_Q31 )) + IF( GT_32( hFdCngCom->likelihood_noisy_speech_32fx, DELTA_MASKING_NOISE_Q31 ) ) { /* Compute additional CN level */ - FOR ( i = 0; i < 15; i++ ) + FOR( i = 0; i < 15; i++ ) { - test(); test(); - IF ( ( EQ_16(hFdCngCom->CngBandwidth, scaleTable_cn_dirac[i].bwmode )) && - GE_32( hFdCngCom->CngBitrate, scaleTable_cn_dirac[i].bitrateFrom ) && - LT_32( hFdCngCom->CngBitrate, scaleTable_cn_dirac[i].bitrateTo ) ) + test(); + test(); + IF( ( EQ_16( hFdCngCom->CngBandwidth, scaleTable_cn_dirac[i].bwmode ) ) && + GE_32( hFdCngCom->CngBitrate, scaleTable_cn_dirac[i].bitrateFrom ) && + LT_32( hFdCngCom->CngBitrate, scaleTable_cn_dirac[i].bitrateTo ) ) { break; } } Word16 exp; - Word16 div1 = BASOP_Util_Divide1616_Scale(negate(scaleTable_cn_dirac[i].scale_ivas), shl(10, Q11), &exp); - exp = add(exp, sub(sub( 15, 13) , sub(15, 11))); - Word32 scale_temp = BASOP_util_Pow2(Mpy_32_16_1(LOG_10_BASE_2, div1), add(exp, 2), &exp); - scale_temp = L_sub(scale_temp, L_shl(1, Q31 - exp)); - scale = L_shl(scale_temp, exp - Q1); // Q30 + Word16 div1 = BASOP_Util_Divide1616_Scale( negate( scaleTable_cn_dirac[i].scale_ivas ), shl( 10, Q11 ), &exp ); + exp = add( exp, sub( sub( 15, 13 ), sub( 15, 11 ) ) ); + Word32 scale_temp = BASOP_util_Pow2( Mpy_32_16_1( LOG_10_BASE_2, div1 ), add( exp, 2 ), &exp ); + scale_temp = L_sub( scale_temp, L_shl( 1, Q31 - exp ) ); + scale = L_shl( scale_temp, exp - Q1 ); // Q30 - scale = Mpy_32_32(scale, hFdCngCom->likelihood_noisy_speech_32fx); //Q30 + scale = Mpy_32_32( scale, hFdCngCom->likelihood_noisy_speech_32fx ); // Q30 } } /* LB CLDFB - CNA from STFT: CNA applied only in channel 0*/ - test(); test(); - IF ( cna_flag && tdBuffer != NULL ) + test(); + test(); + IF( cna_flag && tdBuffer != NULL ) { - WHILE ( GT_16(n_samples_out, 0 )) + WHILE( GT_16( n_samples_out, 0 ) ) { n_samples_out_loop = s_min( hFdCngCom->frameSize, n_samples_out ); - IF ( NE_32(scale, 0 )) + IF( NE_32( scale, 0 ) ) { /*Generate LF comfort noise only at first slot, for the whole frame*/ ptr_level = cngNoiseLevel; /* Generate Gaussian random noise in real and imaginary parts of the FFT bins Amplitudes are adjusted to the estimated noise level cngNoiseLevel_flt in each bin */ - IF ( EQ_16(hFdCngCom->startBand, 0 )) + IF( EQ_16( hFdCngCom->startBand, 0 ) ) { - rand_gauss_fx( &fftBuffer[0], seed, exp_out); + rand_gauss_fx( &fftBuffer[0], seed, exp_out ); ptr_r = fftBuffer + 2; Word16 exp2 = 31 - hFdCngCom->cngNoiseLevelExp; - Word32 sqr = Sqrt32(L_shr(Mpy_32_32(scale, *ptr_level), 1), &exp2); /* DC component in FFT */ - sqr = L_shl(sqr, exp2); - fftBuffer[0] = Mpy_32_32(fftBuffer[0], sqr); /* DC component in FFT */ + Word32 sqr = Sqrt32( L_shr( Mpy_32_32( scale, *ptr_level ), 1 ), &exp2 ); /* DC component in FFT */ + sqr = L_shl( sqr, exp2 ); + fftBuffer[0] = Mpy_32_32( fftBuffer[0], sqr ); /* DC component in FFT */ ptr_level++; } ELSE { fftBuffer[0] = 0; - set32_fx( fftBuffer + 2, 0, shl(sub( hFdCngCom->startBand, 1 ), 1) ); - ptr_r = fftBuffer + shl(hFdCngCom->startBand, 1); + set32_fx( fftBuffer + 2, 0, shl( sub( hFdCngCom->startBand, 1 ), 1 ) ); + ptr_r = fftBuffer + shl( hFdCngCom->startBand, 1 ); } ptr_i = ptr_r + 1; - FOR ( ; ptr_level < cngNoiseLevel + hFdCngCom->stopFFTbin - hFdCngCom->startBand; ptr_level++ ) + FOR( ; ptr_level < cngNoiseLevel + hFdCngCom->stopFFTbin - hFdCngCom->startBand; ptr_level++ ) { - rand_gauss_fx(ptr_r, seed, exp_out); - Word16 exp2 = sub(31, hFdCngCom->cngNoiseLevelExp); - Word32 mpy2 = Sqrt32(Mpy_32_32(scale, *ptr_level), &exp2); - (*ptr_r) = L_shl(Mpy_32_32(*ptr_r, mpy2), exp2); // hFdCngCom->fftBuffer_exp + exp2 - 31 + rand_gauss_fx( ptr_r, seed, exp_out ); + Word16 exp2 = sub( 31, hFdCngCom->cngNoiseLevelExp ); + Word32 mpy2 = Sqrt32( Mpy_32_32( scale, *ptr_level ), &exp2 ); + ( *ptr_r ) = L_shl( Mpy_32_32( *ptr_r, mpy2 ), exp2 ); // hFdCngCom->fftBuffer_exp + exp2 - 31 ptr_r += 2; /* Imaginary part in FFT bins */ - rand_gauss_fx(ptr_i, seed, exp_out); - (*ptr_i) = L_shl(Mpy_32_32(*ptr_i, mpy2), exp2); + rand_gauss_fx( ptr_i, seed, exp_out ); + ( *ptr_i ) = L_shl( Mpy_32_32( *ptr_i, mpy2 ), exp2 ); ptr_i += 2; } /* Remaining FFT bins are set to zero */ - set32_fx( fftBuffer + shl(hFdCngCom->stopFFTbin,1), 0, sub(hFdCngCom->fftlen, shl(hFdCngCom->stopFFTbin, 1)) ); + set32_fx( fftBuffer + shl( hFdCngCom->stopFFTbin, 1 ), 0, sub( hFdCngCom->fftlen, shl( hFdCngCom->stopFFTbin, 1 ) ) ); /* Nyquist frequency is discarded */ fftBuffer[1] = 0; /* Perform STFT synthesis */ SynthesisSTFT_dirac_fx( fftBuffer, tdBuffer + n_samples_start, hFdCngCom->olapBufferSynth2_fx, hFdCngCom->olapWinSyn_fx, n_samples_out_loop, hFdCngCom ); - } ELSE @@ -2833,11 +2832,10 @@ void generate_masking_noise_lb_dirac_fx( set32_fx( fftBuffer, 0, hFdCngCom->fftlen ); /* Perform STFT synthesis */ SynthesisSTFT_dirac_fx( fftBuffer, tdBuffer + n_samples_start, hFdCngCom->olapBufferSynth2_fx, hFdCngCom->olapWinSyn_fx, n_samples_out_loop, hFdCngCom ); - } - hFdCngCom->fftBuffer_exp = sub(31, 15); - n_samples_out = sub(n_samples_out, hFdCngCom->frameSize); - n_samples_start = add(n_samples_start, hFdCngCom->frameSize); + hFdCngCom->fftBuffer_exp = sub( 31, 15 ); + n_samples_out = sub( n_samples_out, hFdCngCom->frameSize ); + n_samples_start = add( n_samples_start, hFdCngCom->frameSize ); } } @@ -2951,15 +2949,14 @@ void generate_masking_noise_dirac( void generate_masking_noise_dirac_ivas_fx( HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i : filterbank state */ - Word32 *tdBuffer_fx, /* i/o: time-domain signal, if NULL no LB-CNA */ - Word32 *Cldfb_RealBuffer_fx, /* o : CLDFD real buffer */ - Word32 *Cldfb_ImagBuffer_fx, /* o : CLDFD imaginary buffer */ - const Word16 slot_index, /* i : CLDFB slot index */ - const Word16 cna_flag, /* i : CNA flag for LB and HB */ + Word32 *tdBuffer_fx, /* i/o: time-domain signal, if NULL no LB-CNA */ + Word32 *Cldfb_RealBuffer_fx, /* o : CLDFD real buffer */ + Word32 *Cldfb_ImagBuffer_fx, /* o : CLDFD imaginary buffer */ + const Word16 slot_index, /* i : CLDFB slot index */ + const Word16 cna_flag, /* i : CNA flag for LB and HB */ const Word16 fd_cng_flag, /* i : FD-CNG flag for HB */ Word16 q_input, - Word16 *q_cldfb -) + Word16 *q_cldfb ) { Word16 i; Word32 *ptr_level_fx; @@ -2974,7 +2971,7 @@ void generate_masking_noise_dirac_ivas_fx( move32(); /* Resample CLDFB memories if necessary*/ - IF ( NE_16( i_mult( h_cldfb->no_channels, h_cldfb->no_col ), hFdCngCom->frameSize ) ) + IF( NE_16( i_mult( h_cldfb->no_channels, h_cldfb->no_col ), hFdCngCom->frameSize ) ) { resampleCldfb_ivas_fx( h_cldfb, hFdCngCom->frameSize * FRAMES_PER_SEC ); } @@ -2983,31 +2980,31 @@ void generate_masking_noise_dirac_ivas_fx( set32_fx( Cldfb_ImagBuffer_fx, 0, CLDFB_NO_CHANNELS_MAX ); /*LB CLDFB - CNA from STFT*/ - IF ( NE_16(cna_flag, 0) ) + IF( NE_16( cna_flag, 0 ) ) { /* skip noise generating if level is very low, to avoid problems with possibly running into denormals */ - IF ( GT_16(hFdCngCom->likelihood_noisy_speech, 0) ) + IF( GT_16( hFdCngCom->likelihood_noisy_speech, 0 ) ) { /* Compute additional CN level */ - FOR ( i = 0; i < 15; i++ ) + FOR( i = 0; i < 15; i++ ) { - IF ( ( EQ_16(hFdCngCom->CngBandwidth, scaleTable_cn_dirac[i].bwmode) ) && - ( GE_32(hFdCngCom->CngBitrate, scaleTable_cn_dirac[i].bitrateFrom) ) && - ( LT_32(hFdCngCom->CngBitrate, scaleTable_cn_dirac[i].bitrateTo) ) ) + IF( ( EQ_16( hFdCngCom->CngBandwidth, scaleTable_cn_dirac[i].bwmode ) ) && + ( GE_32( hFdCngCom->CngBitrate, scaleTable_cn_dirac[i].bitrateFrom ) ) && + ( LT_32( hFdCngCom->CngBitrate, scaleTable_cn_dirac[i].bitrateTo ) ) ) { BREAK; } } - scale_fx = L_sub(pow_10_q11[shr(negate(scaleTable_cn_dirac[i].scale_ivas) / 10, 13 - 7)], 2048); // Q11 - scale_fx = Mpy_32_16_1(scale_fx, hFdCngCom->likelihood_noisy_speech); + scale_fx = L_sub( pow_10_q11[shr( negate( scaleTable_cn_dirac[i].scale_ivas ) / 10, 13 - 7 )], 2048 ); // Q11 + scale_fx = Mpy_32_16_1( scale_fx, hFdCngCom->likelihood_noisy_speech ); } } /* LB CLDFB - CNA from STFT: CNA applied only in channel 0*/ - IF ( cna_flag && tdBuffer_fx != NULL ) + IF( cna_flag && tdBuffer_fx != NULL ) { *q_cldfb = q_input; - IF ( scale_fx != 0 ) + IF( scale_fx != 0 ) { /* LF CLDFB*/ cldfbAnalysis_ts_fx_fixed_q( &( tdBuffer_fx[hFdCngCom->numCoreBands * slot_index] ), Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hFdCngCom->numCoreBands, h_cldfb, q_cldfb ); @@ -3020,41 +3017,41 @@ void generate_masking_noise_dirac_ivas_fx( } /*HF CLDFB - CNA and/or FD-CNG*/ - IF ( fd_cng_flag ) + IF( fd_cng_flag ) { scale_fx += 2048; // 1 in Q11 move16(); } - IF ( scale_fx != 0 ) + IF( scale_fx != 0 ) { q_scale = 11; move16(); - q_shift = norm_l(scale_fx); - scale_fx = L_shl(scale_fx, q_shift); - q_scale = add(q_scale, q_shift); - scale_fx = Mpy_32_32(scale_fx, Mpy_32_16_1(L_mult(h_cldfb->scale, h_cldfb->scale), CLDFB_SCALING)); //Q = q_scale + 2q -34 - q_scale = sub(add(q_scale, i_mult(2, h_cldfb->q_scale)), 34); + q_shift = norm_l( scale_fx ); + scale_fx = L_shl( scale_fx, q_shift ); + q_scale = add( q_scale, q_shift ); + scale_fx = Mpy_32_32( scale_fx, Mpy_32_16_1( L_mult( h_cldfb->scale, h_cldfb->scale ), CLDFB_SCALING ) ); // Q = q_scale + 2q -34 + q_scale = sub( add( q_scale, i_mult( 2, h_cldfb->q_scale ) ), 34 ); ptr_level_fx = hFdCngCom->cngNoiseLevel + hFdCngCom->stopFFTbin - hFdCngCom->startBand; q_ptr_level = 31 - hFdCngCom->cngNoiseLevelExp; move16(); - FOR ( i = hFdCngCom->numCoreBands; i < hFdCngCom->regularStopBand; i++ ) + FOR( i = hFdCngCom->numCoreBands; i < hFdCngCom->regularStopBand; i++ ) { Word32 num; Word16 exp, q_num; - q_shift = norm_l(scale_fx); - scale_fx = L_shl(scale_fx, q_shift); - q_scale = add(q_scale, q_shift); - num = Mpy_32_32(scale_fx, *ptr_level_fx); - q_num = sub(add(q_scale, q_ptr_level), 30); - exp = sub(31, q_num); - num = Sqrt32(num, &exp); + q_shift = norm_l( scale_fx ); + scale_fx = L_shl( scale_fx, q_shift ); + q_scale = add( q_scale, q_shift ); + num = Mpy_32_32( scale_fx, *ptr_level_fx ); + q_num = sub( add( q_scale, q_ptr_level ), 30 ); + exp = sub( 31, q_num ); + num = Sqrt32( num, &exp ); /* Real part in CLDFB band */ rand_gauss_fx( &Cldfb_RealBuffer_fx[i], seed, *q_cldfb ); - Cldfb_RealBuffer_fx[i] = L_shl(Mpy_32_32(Cldfb_RealBuffer_fx[i], num), exp); + Cldfb_RealBuffer_fx[i] = L_shl( Mpy_32_32( Cldfb_RealBuffer_fx[i], num ), exp ); /* Imaginary part in CLDFB band */ rand_gauss_fx( &Cldfb_ImagBuffer_fx[i], seed, *q_cldfb ); - Cldfb_ImagBuffer_fx[i] = L_shl(Mpy_32_32(Cldfb_ImagBuffer_fx[i], num), exp); + Cldfb_ImagBuffer_fx[i] = L_shl( Mpy_32_32( Cldfb_ImagBuffer_fx[i], num ), exp ); ptr_level_fx++; } @@ -3314,7 +3311,7 @@ void FdCngDecodeMDCTStereoSID( scalebands_flt( hFdCngCom->sidNoiseEst_flt, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, hFdCngCom->stopBand - hFdCngCom->startBand, hFdCngCom->cngNoiseLevel_flt, 1 ); - lpc_from_spectrum_flt( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, sts[ch]->preemph_fac_float); + lpc_from_spectrum_flt( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, sts[ch]->preemph_fac_float ); } if ( hCPE->nchan_out == 1 && hCPE->last_element_brate <= IVAS_SID_5k2 ) @@ -3537,7 +3534,7 @@ void FdCngDecodeDiracMDCTStereoSID( scalebands_flt( hFdCngCom->sidNoiseEst_flt, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, hFdCngCom->stopBand - hFdCngCom->startBand, hFdCngCom->cngNoiseLevel_flt, 1 ); - lpc_from_spectrum_flt( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, sts[ch]->preemph_fac_float); + lpc_from_spectrum_flt( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, sts[ch]->preemph_fac_float ); } sts[0]->hFdCngDec->hFdCngCom->coherence_flt = 0.0f; sts[1]->hFdCngDec->hFdCngCom->coherence_flt = 0.0f; diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index 4aa367379..91022457e 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -20,16 +20,16 @@ #endif -#define CNA_ACT_DN_LARGE_PARTITION 50 /* index of the first larger partition */ -#define ST_PERIODOG_FACT_Q15 29491 /* 0.9 in Q15, short-term filter factor for periodogram */ -#define CNA_ACT_DN_FACT_Q15 22938 /* 0.7 in Q15, downward updating factor for CNA during active frames */ -#define FIRST_CNA_NOISE_UPD_FRAMES 5 /* minimum number of CN initialization frames */ +#define CNA_ACT_DN_LARGE_PARTITION 50 /* index of the first larger partition */ +#define ST_PERIODOG_FACT_Q15 29491 /* 0.9 in Q15, short-term filter factor for periodogram */ +#define CNA_ACT_DN_FACT_Q15 22938 /* 0.7 in Q15, downward updating factor for CNA during active frames */ +#define FIRST_CNA_NOISE_UPD_FRAMES 5 /* minimum number of CN initialization frames */ /******************************** -* External tables * -********************************/ + * External tables * + ********************************/ -extern const Word16 T_DIV_L_Frame[]; /* format: 0Q15 * 2^-7 */ +extern const Word16 T_DIV_L_Frame[]; /* format: 0Q15 * 2^-7 */ const Word16 maxN_37bits = FD_CNG_maxN_37bits; const Word16 maxC_37bits = FD_CNG_maxC_37bits; @@ -45,20 +45,20 @@ const Word16 stages_37bits = FD_CNG_stages_37bits; create an instance of type FD_CNG */ #ifdef IVAS_FLOAT_FIXED -ivas_error createFdCngDec_fx (HANDLE_FD_CNG_DEC *hFdCngDec) +ivas_error createFdCngDec_fx( HANDLE_FD_CNG_DEC *hFdCngDec ) { HANDLE_FD_CNG_DEC hs; ivas_error error; error = IVAS_ERR_OK; /* Allocate memory */ - hs = (HANDLE_FD_CNG_DEC)count_malloc(sizeof (FD_CNG_DEC)); + hs = (HANDLE_FD_CNG_DEC) count_malloc( sizeof( FD_CNG_DEC ) ); - if (hs == NULL) + if ( hs == NULL ) { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for FD CNG DEC structure"); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for FD CNG DEC structure" ); } - if ((error = createFdCngCom(&(hs->hFdCngCom))) != IVAS_ERR_OK) + if ( ( error = createFdCngCom( &( hs->hFdCngCom ) ) ) != IVAS_ERR_OK ) { return error; } @@ -79,7 +79,7 @@ void initFdCngDec_ivas_fx( hFdCngDec = st->hFdCngDec; ivas_initFdCngCom_fx( hFdCngDec->hFdCngCom, scale ); - set16_fx( hFdCngDec->olapBufferAna, 0, FFTLEN); + set16_fx( hFdCngDec->olapBufferAna, 0, FFTLEN ); hFdCngDec->hFdCngCom->olapBufferAna = hFdCngDec->olapBufferAna; move16(); set16_fx( hFdCngDec->olapBufferSynth2, 0, FFTLEN ); @@ -188,8 +188,7 @@ void initFdCngDec_ivas_fx( void initFdCngDec_fx( DEC_CORE_HANDLE st, /* i/o: decoder state structure */ - Word16 scale -) + Word16 scale ) { /* Initialize common */ HANDLE_FD_CNG_DEC hFdCngDec; @@ -198,7 +197,7 @@ void initFdCngDec_fx( initFdCngCom( hFdCngDec->hFdCngCom, scale ); set16_fx( hFdCngDec->olapBufferAna, 0, 320 ); - hFdCngDec->hFdCngCom->olapBufferAna = hFdCngDec->olapBufferAna; + hFdCngDec->hFdCngCom->olapBufferAna = hFdCngDec->olapBufferAna; move16(); set16_fx( hFdCngDec->olapBufferSynth2, 0, FFTLEN ); hFdCngDec->hFdCngCom->olapBufferSynth2 = hFdCngDec->olapBufferSynth2; @@ -208,19 +207,19 @@ void initFdCngDec_fx( hFdCngDec->flag_dtx_mode = 0; move16(); - hFdCngDec->lp_noise = -167772160l/*-20.f Q23*/; /* format: Q8.24 */ - hFdCngDec->lp_speech = 209715200l/* 25.f Q23*/; /* format: Q8.24 */ + hFdCngDec->lp_noise = -167772160l /*-20.f Q23*/; /* format: Q8.24 */ + hFdCngDec->lp_speech = 209715200l /* 25.f Q23*/; /* format: Q8.24 */ /* Initialization of the noise estimation algorithm */ set32_fx( hFdCngDec->bandNoiseShape, 0, FFTLEN2 ); - set16_fx( &hFdCngDec->bandNoiseShape_exp, 0, 1); + set16_fx( &hFdCngDec->bandNoiseShape_exp, 0, 1 ); - set32_fx (hFdCngDec->partNoiseShape, 0, NPART ); - set16_fx( &hFdCngDec->partNoiseShape_exp, 0, 1); + set32_fx( hFdCngDec->partNoiseShape, 0, NPART ); + set16_fx( &hFdCngDec->partNoiseShape_exp, 0, 1 ); set32_fx( hFdCngDec->msPeriodog, 0, NPART_SHAPING ); - set16_fx( &hFdCngDec->msPeriodog_exp, 0, 1); + set16_fx( &hFdCngDec->msPeriodog_exp, 0, 1 ); set32_fx( hFdCngDec->msAlpha, 0, NPART_SHAPING ); @@ -233,23 +232,23 @@ void initFdCngDec_fx( set16_fx( hFdCngDec->msNoiseFloor, 0, NPART_SHAPING ); set32_fx( hFdCngDec->msNoiseEst, 0, NPART_SHAPING ); - set16_fx( &hFdCngDec->msNoiseEst_exp, 0, 1); + set16_fx( &hFdCngDec->msNoiseEst_exp, 0, 1 ); - set32_fx( hFdCngDec->msMinBuf, 2147483647l/*1.0 Q31*/, MSNUMSUBFR*NPART_SHAPING ); + set32_fx( hFdCngDec->msMinBuf, 2147483647l /*1.0 Q31*/, MSNUMSUBFR * NPART_SHAPING ); - set32_fx( hFdCngDec->msCurrentMin, 2147483647l/*1.0 Q31*/, NPART_SHAPING ); + set32_fx( hFdCngDec->msCurrentMin, 2147483647l /*1.0 Q31*/, NPART_SHAPING ); - set32_fx( hFdCngDec->msCurrentMinOut, 2147483647l/*1.0 Q31*/, NPART_SHAPING ); + set32_fx( hFdCngDec->msCurrentMinOut, 2147483647l /*1.0 Q31*/, NPART_SHAPING ); - set32_fx( hFdCngDec->msCurrentMinSubWindow, 2147483647l/*1.0 Q31*/, NPART_SHAPING ); + set32_fx( hFdCngDec->msCurrentMinSubWindow, 2147483647l /*1.0 Q31*/, NPART_SHAPING ); - set16_fx( hFdCngDec->msLocalMinFlag, 0, NPART_SHAPING ); + set16_fx( hFdCngDec->msLocalMinFlag, 0, NPART_SHAPING ); set16_fx( hFdCngDec->msNewMinFlag, 0, NPART_SHAPING ); set16_fx( hFdCngDec->msPsdFirstMoment, 0, NPART_SHAPING ); set32_fx( hFdCngDec->msPsdSecondMoment, 0, NPART_SHAPING ); - set16_fx( hFdCngDec->msPeriodogBuf, 0, MSBUFLEN*NPART_SHAPING ); + set16_fx( hFdCngDec->msPeriodogBuf, 0, MSBUFLEN * NPART_SHAPING ); hFdCngDec->msPeriodogBufPtr = 0; move16(); @@ -260,20 +259,20 @@ void initFdCngDec_fx( set16_fx( hFdCngDec->psize_shaping, 0, NPART_SHAPING ); move16(); hFdCngDec->nFFTpart_shaping = 0; - set32_fx(hFdCngDec->msPeriodog_ST_fx, 0, NPART_SHAPING); + set32_fx( hFdCngDec->msPeriodog_ST_fx, 0, NPART_SHAPING ); hFdCngDec->msPeriodog_ST_exp = 0; hFdCngDec->hFdCngCom->fftBuffer_exp = 0; hFdCngDec->hFdCngCom->periodog_exp = 0; - set32_fx(hFdCngDec->smoothed_psd_fx, 0, L_FRAME16k); + set32_fx( hFdCngDec->smoothed_psd_fx, 0, L_FRAME16k ); #ifdef IVAS_FLOAT_FIXED hFdCngDec->q_smoothed_psd = Q4; #endif #ifdef IVAS_CODE_CNG - set_f(hFdCngDec->hFdCngCom->sidNoiseEstLp, 0.0f, NPART); + set_f( hFdCngDec->hFdCngCom->sidNoiseEstLp, 0.0f, NPART ); - set_f(hFdCngDec->smoothed_psd, 0.0f, L_FRAME16k); - set_f(hFdCngDec->msPeriodog_ST, 0.0f, NPART_SHAPING); + set_f( hFdCngDec->smoothed_psd, 0.0f, L_FRAME16k ); + set_f( hFdCngDec->msPeriodog_ST, 0.0f, NPART_SHAPING ); hFdCngDec->ms_last_inactive_bwidth = NB; hFdCngDec->ms_cnt_bw_up = 0; @@ -283,18 +282,17 @@ void initFdCngDec_fx( hFdCngDec->first_cna_noise_updated = 0; hFdCngDec->first_cna_noise_update_cnt = 0; hFdCngDec->cna_nbands = 6; - mvs2s(cna_init_bands, hFdCngDec->cna_band_limits, MAX_CNA_NBANDS + 1); + mvs2s( cna_init_bands, hFdCngDec->cna_band_limits, MAX_CNA_NBANDS + 1 ); hFdCngDec->cna_act_fact = 1.0f; hFdCngDec->cna_rescale_fact = 0.0f; hFdCngDec->cna_seed = 5687; - set_zero(hFdCngDec->cna_cm, STEREO_DFT_BAND_MAX); - set_zero(hFdCngDec->cna_g_state, STEREO_DFT_BAND_MAX); + set_zero( hFdCngDec->cna_cm, STEREO_DFT_BAND_MAX ); + set_zero( hFdCngDec->cna_g_state, STEREO_DFT_BAND_MAX ); st->CNG_mode = -1; - mvr2r(st->lsp_old, st->lspCNG, M); + mvr2r( st->lsp_old, st->lspCNG, M ); #endif return; - } #endif /* @@ -314,35 +312,34 @@ void initFdCngDec_fx( Returns: void */ -void configureFdCngDec_fx ( - HANDLE_FD_CNG_DEC hFdCngDec, /* i/o: Contains the variables related to the CLDFB-based CNG process */ +void configureFdCngDec_fx( + HANDLE_FD_CNG_DEC hFdCngDec, /* i/o: Contains the variables related to the CLDFB-based CNG process */ Word16 bwidth, Word32 total_brate, Word16 L_frame, const Word16 Last_L_frame, - const Word16 element_mode - ) + const Word16 element_mode ) { Word16 j, stopBandFR; HANDLE_FD_CNG_COM hsCom = hFdCngDec->hFdCngCom; hsCom->CngBandwidth = bwidth; - IF ( EQ_16( hsCom->CngBandwidth, FB )) + IF( EQ_16( hsCom->CngBandwidth, FB ) ) { hsCom->CngBandwidth = SWB; } test(); - if ( total_brate != FRAME_NO_DATA && NE_32(total_brate, SID_2k40)) + if ( total_brate != FRAME_NO_DATA && NE_32( total_brate, SID_2k40 ) ) { hsCom->CngBitrate = total_brate; move32(); } - ELSE IF (EQ_32(hsCom->CngBitrate, -1 )) + ELSE IF( EQ_32( hsCom->CngBitrate, -1 ) ) { /* set minimum active CBR bitrate if CngBitrate is uninitialized */ hsCom->CngBitrate = ACELP_7k20; - IF (GT_16(element_mode, EVS_MONO)) + IF( GT_16( element_mode, EVS_MONO ) ) { hsCom->CngBitrate = IVAS_13k2; move32(); @@ -352,7 +349,7 @@ void configureFdCngDec_fx ( /* FD-CNG config for MDCT-Stereo is always the same (since for > 48 kbps only) */ /* This may need adjustment in the future if 2TC DTX for some mode uses MDCT-Stereo DTX for lower bitrates too */ - IF (EQ_16(element_mode, IVAS_CPE_MDCT)) + IF( EQ_16( element_mode, IVAS_CPE_MDCT ) ) { hsCom->CngBitrate = IVAS_48k; move32(); @@ -362,7 +359,7 @@ void configureFdCngDec_fx ( move16(); /* NB configuration */ - IF ( bwidth == NB ) + IF( bwidth == NB ) { hsCom->FdCngSetup = FdCngSetup_nb; hsCom->numCoreBands = 16; @@ -372,14 +369,12 @@ void configureFdCngDec_fx ( } /* WB configuration */ - ELSE IF ( EQ_16(bwidth, WB)) + ELSE IF( EQ_16( bwidth, WB ) ) { /* FFT 6.4kHz, no CLDFB */ test(); test(); - IF ( LE_32(hsCom->CngBitrate, ACELP_8k00) - && EQ_16(L_frame,L_FRAME) - ) + IF( LE_32( hsCom->CngBitrate, ACELP_8k00 ) && EQ_16( L_frame, L_FRAME ) ) { hsCom->FdCngSetup = FdCngSetup_wb1; hsCom->numCoreBands = 16; @@ -388,18 +383,15 @@ void configureFdCngDec_fx ( move16(); } /* FFT 6.4kHz, CLDFB 8.0kHz */ - ELSE IF ( LE_32(hsCom->CngBitrate, ACELP_13k20) - || EQ_16(L_frame,L_FRAME) - ) + ELSE IF( LE_32( hsCom->CngBitrate, ACELP_13k20 ) || EQ_16( L_frame, L_FRAME ) ) { hsCom->FdCngSetup = FdCngSetup_wb2; hsCom->numCoreBands = 16; move16(); hsCom->regularStopBand = 20; move16(); - IF ( - EQ_16(L_frame,L_FRAME16k) - ) + IF( + EQ_16( L_frame, L_FRAME16k ) ) { hsCom->FdCngSetup = FdCngSetup_wb2; hsCom->numCoreBands = 20; @@ -420,18 +412,15 @@ void configureFdCngDec_fx ( move16(); hsCom->regularStopBand = 20; move16(); - } - } /* SWB/FB configuration */ ELSE { /* FFT 6.4kHz, CLDFB 14kHz */ - IF ( - EQ_16(L_frame,L_FRAME) - ) + IF( + EQ_16( L_frame, L_FRAME ) ) { hsCom->FdCngSetup = FdCngSetup_swb1; hsCom->numCoreBands = 16; @@ -448,7 +437,7 @@ void configureFdCngDec_fx ( hsCom->regularStopBand = 40; move16(); test(); - IF(EQ_16(Last_L_frame, L_FRAME) && EQ_16(element_mode, IVAS_CPE_DFT)) + IF( EQ_16( Last_L_frame, L_FRAME ) && EQ_16( element_mode, IVAS_CPE_DFT ) ) { hsCom->regularStopBand = 35; move16(); @@ -464,67 +453,66 @@ void configureFdCngDec_fx ( hsCom->startBand = 2; move16(); - hsCom->stopBand = add( hsCom->FdCngSetup.sidPartitions[hsCom->FdCngSetup.numPartitions-1], 1 ); - initPartitions(hsCom->FdCngSetup.sidPartitions, hsCom->FdCngSetup.numPartitions, hsCom->startBand, hsCom->stopBand, hsCom->part, - &hsCom->npart, hsCom->midband, hsCom->psize, hsCom->psize_norm, &hsCom->psize_norm_exp, hsCom->psize_inv, 0); + hsCom->stopBand = add( hsCom->FdCngSetup.sidPartitions[hsCom->FdCngSetup.numPartitions - 1], 1 ); + initPartitions( hsCom->FdCngSetup.sidPartitions, hsCom->FdCngSetup.numPartitions, hsCom->startBand, hsCom->stopBand, hsCom->part, + &hsCom->npart, hsCom->midband, hsCom->psize, hsCom->psize_norm, &hsCom->psize_norm_exp, hsCom->psize_inv, 0 ); hsCom->nFFTpart = 21; move16(); - if ( EQ_16(hsCom->stopFFTbin, 256)) + if ( EQ_16( hsCom->stopFFTbin, 256 ) ) { hsCom->nFFTpart = 20; move16(); } - if ( EQ_16(hsCom->stopFFTbin, 160)) + if ( EQ_16( hsCom->stopFFTbin, 160 ) ) { hsCom->nFFTpart = 17; move16(); } hsCom->nCLDFBpart = sub( hsCom->npart, hsCom->nFFTpart ); - FOR(j=0; jnCLDFBpart; j++) + FOR( j = 0; j < hsCom->nCLDFBpart; j++ ) { - hsCom->CLDFBpart[j] = sub( hsCom->part[j+hsCom->nFFTpart], (hsCom->stopFFTbin-hsCom->startBand) ); + hsCom->CLDFBpart[j] = sub( hsCom->part[j + hsCom->nFFTpart], ( hsCom->stopFFTbin - hsCom->startBand ) ); move16(); - hsCom->CLDFBpsize_inv[j] = hsCom->psize_inv[j+hsCom->nFFTpart]; + hsCom->CLDFBpsize_inv[j] = hsCom->psize_inv[j + hsCom->nFFTpart]; move16(); } - stopBandFR = 1000/25; - if ( GT_16(stopBandFR, hsCom->stopFFTbin)) + stopBandFR = 1000 / 25; + if ( GT_16( stopBandFR, hsCom->stopFFTbin ) ) { stopBandFR = hsCom->stopFFTbin; move16(); } - initPartitions(hsCom->FdCngSetup.shapingPartitions, hsCom->FdCngSetup.numShapingPartitions, - hsCom->startBand, hsCom->stopFFTbin, hFdCngDec->part_shaping, &hFdCngDec->npart_shaping, hFdCngDec->midband_shaping, - hFdCngDec->psize_shaping, hFdCngDec->psize_shaping_norm, &hFdCngDec->psize_shaping_norm_exp, hFdCngDec->psize_inv_shaping, - stopBandFR ); + initPartitions( hsCom->FdCngSetup.shapingPartitions, hsCom->FdCngSetup.numShapingPartitions, + hsCom->startBand, hsCom->stopFFTbin, hFdCngDec->part_shaping, &hFdCngDec->npart_shaping, hFdCngDec->midband_shaping, + hFdCngDec->psize_shaping, hFdCngDec->psize_shaping_norm, &hFdCngDec->psize_shaping_norm_exp, hFdCngDec->psize_inv_shaping, + stopBandFR ); hFdCngDec->nFFTpart_shaping = hFdCngDec->npart_shaping; move16(); - SWITCH (hsCom->fftlen) + SWITCH( hsCom->fftlen ) { - case 512: - hsCom->fftlenShift = 8; - move16(); - hsCom->fftlenFac = 32767/*1.0 Q15*/; - move16(); - BREAK; - case 640: - hsCom->fftlenShift = 9; - move16(); - hsCom->fftlenFac = 20480/*0.625 Q15*/; - move16(); - BREAK; - default: - assert(!"Unsupported FFT length for FD-based CNG"); - BREAK; + case 512: + hsCom->fftlenShift = 8; + move16(); + hsCom->fftlenFac = 32767 /*1.0 Q15*/; + move16(); + BREAK; + case 640: + hsCom->fftlenShift = 9; + move16(); + hsCom->fftlenFac = 20480 /*0.625 Q15*/; + move16(); + BREAK; + default: + assert( !"Unsupported FFT length for FD-based CNG" ); + BREAK; } - BASOP_getTables( &hsCom->olapWinAna, NULL, NULL, shr(hsCom->fftlen, 1)); - BASOP_getTables( &hsCom->olapWinSyn, NULL, NULL, shr(hsCom->fftlen, 2)); - hsCom->frameSize = shr(hsCom->fftlen,1); - + BASOP_getTables( &hsCom->olapWinAna, NULL, NULL, shr( hsCom->fftlen, 1 ) ); + BASOP_getTables( &hsCom->olapWinSyn, NULL, NULL, shr( hsCom->fftlen, 2 ) ); + hsCom->frameSize = shr( hsCom->fftlen, 1 ); } @@ -541,14 +529,14 @@ void configureFdCngDec_fx ( Returns: void */ -void deleteFdCngDec_fx (HANDLE_FD_CNG_DEC *hFdCngDec) +void deleteFdCngDec_fx( HANDLE_FD_CNG_DEC *hFdCngDec ) { HANDLE_FD_CNG_DEC hsDec = *hFdCngDec; - IF ( hsDec != NULL ) + IF( hsDec != NULL ) { - deleteFdCngCom (&(hsDec->hFdCngCom)); - count_free(hsDec); + deleteFdCngCom( &( hsDec->hFdCngCom ) ); + count_free( hsDec ); *hFdCngDec = NULL; } } @@ -576,19 +564,18 @@ void deleteFdCngDec_fx (HANDLE_FD_CNG_DEC *hFdCngDec) Returns: error */ -Word16 ApplyFdCng_fx ( - Word16 *timeDomainInput, /* i : pointer to time domain input */ - Word16 Q, +Word16 ApplyFdCng_fx( + Word16 *timeDomainInput, /* i : pointer to time domain input */ + Word16 Q, #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - Word16* powerSpectrum, + Word16 *powerSpectrum, #endif - Word32 **cldfbBufferReal, /* i/o: real part of the CLDFB buffer */ - Word32 **cldfbBufferImag, /* i/o: imaginary part of the CLDFB buffer */ - Word16 *cldfbBufferScale, /* o : pointer to the scalefactor for real and imaginary part of the CLDFB buffer */ + Word32 **cldfbBufferReal, /* i/o: real part of the CLDFB buffer */ + Word32 **cldfbBufferImag, /* i/o: imaginary part of the CLDFB buffer */ + Word16 *cldfbBufferScale, /* o : pointer to the scalefactor for real and imaginary part of the CLDFB buffer */ Decoder_State *st, - const Word16 concealWholeFrame, /* i : binary flag indicating frame loss */ - Word16 is_music - ) + const Word16 concealWholeFrame, /* i : binary flag indicating frame loss */ + Word16 is_music ) { Word16 j, k, nBins; Word16 s, s1, s2, num, denom; @@ -611,566 +598,569 @@ Word16 ApplyFdCng_fx ( int16_t L_frame, last_L_frame; int32_t sr_core; - PMT("Fix point code missing for IVAS_CODE_CNG_FIX185_PLC_FADEOUT") + PMT( "Fix point code missing for IVAS_CODE_CNG_FIX185_PLC_FADEOUT" ) /* limit L_frame and core fs values for MDCT-Stereo modes which can have higher core sampling than 16kHz, but use a downsampled buffer */ - L_frame = min(st->L_frame, L_FRAME16k); - last_L_frame = min(st->last_L_frame, L_FRAME16k); - sr_core = min(st->sr_core, INT_FS_16k); + L_frame = min( st->L_frame, L_FRAME16k ); + last_L_frame = min( st->last_L_frame, L_FRAME16k ); + sr_core = min( st->sr_core, INT_FS_16k ); #endif hFdCngDec = st->hFdCngDec; hFdCngCom = hFdCngDec->hFdCngCom; - if(EQ_16(hFdCngCom->frame_type_previous,ACTIVE_FRAME)) + if ( EQ_16( hFdCngCom->frame_type_previous, ACTIVE_FRAME ) ) { hFdCngCom->inactive_frame_counter = 0; move16(); } - IF (EQ_16(st->element_mode, IVAS_CPE_TD)) + IF( EQ_16( st->element_mode, IVAS_CPE_TD ) ) { hFdCngDec->flag_dtx_mode = hFdCngDec->flag_dtx_mode || st->first_CNG; - test(); move16(); + test(); + move16(); } cngNoiseLevel = hFdCngCom->cngNoiseLevel; cngNoiseLevel_exp = &hFdCngCom->cngNoiseLevelExp; - move16(); move16(); - nBins = sub(hFdCngCom->stopFFTbin,hFdCngCom->startBand); + move16(); + move16(); + nBins = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); - SWITCH ( st->m_frame_type ) + SWITCH( st->m_frame_type ) { - case ACTIVE_FRAME: + case ACTIVE_FRAME: - /************************** - * ACTIVE_FRAME at DECODER * - **************************/ + /************************** + * ACTIVE_FRAME at DECODER * + **************************/ - hFdCngCom->inactive_frame_counter = 0; - move16(); - hFdCngCom->sid_frame_counter = 0; - move16(); + hFdCngCom->inactive_frame_counter = 0; + move16(); + hFdCngCom->sid_frame_counter = 0; + move16(); - /* set noise estimation inactive during concealment, as no update with noise generated by concealment should be performed. */ - /* set noise estimation inactive during concealment, no update with noise generated by concealment should be performed. */ + /* set noise estimation inactive during concealment, as no update with noise generated by concealment should be performed. */ + /* set noise estimation inactive during concealment, no update with noise generated by concealment should be performed. */ - test();test();test();test();test();test(); - test();test();test();test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - if (concealWholeFrame == 0 && - (timeDomainInput == NULL || - (*timeDomainInput(-FLT_MAX) && - *(timeDomainInput + hFdCngCom->frameSize - 1) < FLT_MAX && - *(timeDomainInput + hFdCngCom->frameSize - 1) > (-FLT_MAX))) && - ((((st->element_mode != IVAS_CPE_TD && st->element_mode != IVAS_CPE_DFT && hFdCngDec->flag_dtx_mode) || !st->VAD) && - !(st->cng_type == LP_CNG && hFdCngDec->flag_dtx_mode) && (is_music == 0)) || - (st->element_mode == IVAS_CPE_TD)) && - (!st->BER_detect)) + if ( concealWholeFrame == 0 && + ( timeDomainInput == NULL || + ( *timeDomainInput( -FLT_MAX ) && + *( timeDomainInput + hFdCngCom->frameSize - 1 ) < FLT_MAX && + *( timeDomainInput + hFdCngCom->frameSize - 1 ) > ( -FLT_MAX ) ) ) && + ( ( ( ( st->element_mode != IVAS_CPE_TD && st->element_mode != IVAS_CPE_DFT && hFdCngDec->flag_dtx_mode ) || !st->VAD ) && + !( st->cng_type == LP_CNG && hFdCngDec->flag_dtx_mode ) && ( is_music == 0 ) ) || + ( st->element_mode == IVAS_CPE_TD ) ) && + ( !st->BER_detect ) ) #else - IF( - (concealWholeFrame == 0) && - (*timeDomainInput < MAXVAL_WORD16) && (*timeDomainInput > MINVAL_WORD16) && (*(timeDomainInput+hFdCngCom->frameSize-1) < MAXVAL_WORD16) && (*(timeDomainInput+hFdCngCom->frameSize-1) > MINVAL_WORD16) - && ( ((hFdCngDec->flag_dtx_mode == 0) && (st->VAD != 0)) == 0 ) - && ( ((st->cng_type == LP_CNG) && (hFdCngDec->flag_dtx_mode != 0)) == 0) - && ( is_music == 0 ) - && (st->BER_detect == 0) - ) + IF( + ( concealWholeFrame == 0 ) && + ( *timeDomainInput < MAXVAL_WORD16 ) && ( *timeDomainInput > MINVAL_WORD16 ) && ( *( timeDomainInput + hFdCngCom->frameSize - 1 ) < MAXVAL_WORD16 ) && ( *( timeDomainInput + hFdCngCom->frameSize - 1 ) > MINVAL_WORD16 ) && ( ( ( hFdCngDec->flag_dtx_mode == 0 ) && ( st->VAD != 0 ) ) == 0 ) && ( ( ( st->cng_type == LP_CNG ) && ( hFdCngDec->flag_dtx_mode != 0 ) ) == 0 ) && ( is_music == 0 ) && ( st->BER_detect == 0 ) ) #endif - { - /* Perform noise estimation at the decoder */ + { + /* Perform noise estimation at the decoder */ #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - perform_noise_estimation_dec_fx(timeDomainInput, powerSpectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD); + perform_noise_estimation_dec_fx( timeDomainInput, powerSpectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD ); #else - perform_noise_estimation_dec_fx (timeDomainInput, Q, hFdCngDec); + perform_noise_estimation_dec_fx( timeDomainInput, Q, hFdCngDec ); #endif - /* Update the shaping parameters */ - test(); - IF (NE_16(st->element_mode, IVAS_CPE_TD) && NE_16(st->element_mode, IVAS_CPE_DFT)) - { - scalebands(hFdCngDec->msNoiseEst, hFdCngDec->part_shaping, hFdCngDec->nFFTpart_shaping, hFdCngDec->midband_shaping, hFdCngDec->nFFTpart_shaping, nBins, hFdCngDec->bandNoiseShape,1 ); - } - hFdCngDec->bandNoiseShape_exp = hFdCngDec->msNoiseEst_exp; - move16(); - - - /* Update CNG levels */ - test(); - IF ( hFdCngDec->flag_dtx_mode != 0 && st->cng_type == FD_CNG ) - { - /* This needs to be done only once per inactive phase */ - bandcombinepow ( - hFdCngDec->bandNoiseShape, - hFdCngDec->bandNoiseShape_exp, - nBins, - hFdCngCom->part, - hFdCngCom->nFFTpart, - hFdCngCom->psize_inv, - hFdCngDec->partNoiseShape, - &hFdCngDec->partNoiseShape_exp - ); + /* Update the shaping parameters */ + test(); + IF( NE_16( st->element_mode, IVAS_CPE_TD ) && NE_16( st->element_mode, IVAS_CPE_DFT ) ) + { + scalebands( hFdCngDec->msNoiseEst, hFdCngDec->part_shaping, hFdCngDec->nFFTpart_shaping, hFdCngDec->midband_shaping, hFdCngDec->nFFTpart_shaping, nBins, hFdCngDec->bandNoiseShape, 1 ); + } + hFdCngDec->bandNoiseShape_exp = hFdCngDec->msNoiseEst_exp; + move16(); - j = 0; - move16(); - s2 = -(WORD32_BITS-1); - move16(); - FOR (k=0; k < hFdCngCom->nFFTpart; k++) + /* Update CNG levels */ + test(); + IF( hFdCngDec->flag_dtx_mode != 0 && st->cng_type == FD_CNG ) { - assert(hFdCngDec->partNoiseShape[k]>=0); - assert(hFdCngCom->sidNoiseEst[k]>=0); + /* This needs to be done only once per inactive phase */ + bandcombinepow( + hFdCngDec->bandNoiseShape, + hFdCngDec->bandNoiseShape_exp, + nBins, + hFdCngCom->part, + hFdCngCom->nFFTpart, + hFdCngCom->psize_inv, + hFdCngDec->partNoiseShape, + &hFdCngDec->partNoiseShape_exp ); + - /* add DELTA as it is done in FLC version, in order to avoid num > denom */ - facTab[k] = 0; + j = 0; move16(); - IF ( hFdCngDec->partNoiseShape[k] != 0) - { - s1 = norm_l(hFdCngCom->sidNoiseEst[k]); - L_tmp = L_shl(hFdCngCom->sidNoiseEst[k], s1); - L_tmp_exp = sub(hFdCngCom->sidNoiseEstExp, s1); - L_tmp = BASOP_Util_Add_Mant32Exp(L_tmp, L_tmp_exp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp); - L_tmp = L_shr(L_tmp, 1); - s = add(L_tmp_exp, 1); - num = extract_h(L_tmp); - - s1 = norm_l(hFdCngDec->partNoiseShape[k]); - L_tmp = L_shl(hFdCngDec->partNoiseShape[k], s1); - L_tmp_exp = sub(hFdCngDec->partNoiseShape_exp, s1); - L_tmp = BASOP_Util_Add_Mant32Exp(L_tmp, L_tmp_exp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp); - s = sub(s, L_tmp_exp); - denom = extract_h(L_tmp); - - facTab[k] = div_s(num,denom); - move16(); - facTabExp[k] = s; - move16(); - } - /* Set unique exponent, if mantissa is equal to zero */ - if (facTab[k] == 0) + s2 = -( WORD32_BITS - 1 ); + move16(); + FOR( k = 0; k < hFdCngCom->nFFTpart; k++ ) { - facTabExp[k] = -(WORD32_BITS-1); + assert( hFdCngDec->partNoiseShape[k] >= 0 ); + assert( hFdCngCom->sidNoiseEst[k] >= 0 ); + + /* add DELTA as it is done in FLC version, in order to avoid num > denom */ + facTab[k] = 0; move16(); - } - s2 = s_max(s2,facTabExp[k]); - } + IF( hFdCngDec->partNoiseShape[k] != 0 ) + { + s1 = norm_l( hFdCngCom->sidNoiseEst[k] ); + L_tmp = L_shl( hFdCngCom->sidNoiseEst[k], s1 ); + L_tmp_exp = sub( hFdCngCom->sidNoiseEstExp, s1 ); + L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, L_tmp_exp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp ); + L_tmp = L_shr( L_tmp, 1 ); + s = add( L_tmp_exp, 1 ); + num = extract_h( L_tmp ); - FOR (k=0; k < hFdCngCom->nFFTpart; k++) - { - s = sub(facTabExp[k],s2); - s = s_max(s_min(s,WORD32_BITS-1),-(WORD32_BITS-1)); - FOR ( ; j <= hFdCngCom->part[k]; j++) - { - cngNoiseLevel[j] = L_shl(Mpy_32_16_1(hFdCngDec->bandNoiseShape[j],facTab[k]),s); - move32(); + s1 = norm_l( hFdCngDec->partNoiseShape[k] ); + L_tmp = L_shl( hFdCngDec->partNoiseShape[k], s1 ); + L_tmp_exp = sub( hFdCngDec->partNoiseShape_exp, s1 ); + L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, L_tmp_exp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp ); + s = sub( s, L_tmp_exp ); + denom = extract_h( L_tmp ); + + facTab[k] = div_s( num, denom ); + move16(); + facTabExp[k] = s; + move16(); + } + /* Set unique exponent, if mantissa is equal to zero */ + if ( facTab[k] == 0 ) + { + facTabExp[k] = -( WORD32_BITS - 1 ); + move16(); + } + s2 = s_max( s2, facTabExp[k] ); } - } - /* adapt scaling for rest of the buffer */ - IF (NE_16(s2,-(WORD32_BITS-1))) - { - s = sub(*cngNoiseLevel_exp,add(hFdCngDec->bandNoiseShape_exp,s2)); - FOR ( ; k < hFdCngCom->npart; k++) + FOR( k = 0; k < hFdCngCom->nFFTpart; k++ ) { - FOR( ; j <= hFdCngCom->part[k]; j++) + s = sub( facTabExp[k], s2 ); + s = s_max( s_min( s, WORD32_BITS - 1 ), -( WORD32_BITS - 1 ) ); + FOR( ; j <= hFdCngCom->part[k]; j++ ) { - cngNoiseLevel[j] = L_shl(cngNoiseLevel[j],s); + cngNoiseLevel[j] = L_shl( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); move32(); } } - *cngNoiseLevel_exp = add(hFdCngDec->bandNoiseShape_exp,s2); - move16(); + /* adapt scaling for rest of the buffer */ + IF( NE_16( s2, -( WORD32_BITS - 1 ) ) ) + { + s = sub( *cngNoiseLevel_exp, add( hFdCngDec->bandNoiseShape_exp, s2 ) ); + FOR( ; k < hFdCngCom->npart; k++ ) + { + FOR( ; j <= hFdCngCom->part[k]; j++ ) + { + cngNoiseLevel[j] = L_shl( cngNoiseLevel[j], s ); + move32(); + } + } + + *cngNoiseLevel_exp = add( hFdCngDec->bandNoiseShape_exp, s2 ); + move16(); + } } - } - ELSE - { - /* This sets the new CNG levels until a SID update overwrites it */ - test(); test(); test(); - IF(!(EQ_16(st->element_mode, IVAS_CPE_TD)) || (EQ_16(st->element_mode, IVAS_CPE_TD) && !hFdCngDec->flag_dtx_mode && !st->VAD)) + ELSE { - Copy32(hFdCngDec->bandNoiseShape,cngNoiseLevel,nBins); - *cngNoiseLevel_exp = hFdCngDec->bandNoiseShape_exp; - move16(); - } - } + /* This sets the new CNG levels until a SID update overwrites it */ + test(); + test(); + test(); + IF( !( EQ_16( st->element_mode, IVAS_CPE_TD ) ) || ( EQ_16( st->element_mode, IVAS_CPE_TD ) && !hFdCngDec->flag_dtx_mode && !st->VAD ) ) + { + Copy32( hFdCngDec->bandNoiseShape, cngNoiseLevel, nBins ); + *cngNoiseLevel_exp = hFdCngDec->bandNoiseShape_exp; + move16(); + } + } #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - if (st->element_mode == IVAS_CPE_MDCT && timeDomainInput == NULL) - { - st->hTcxDec->CngLevelBackgroundTrace_bfi = sqrtf(sum_f(cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand) / NORM_MDCT_FACTOR); - } - else - { - st->hTcxDec->CngLevelBackgroundTrace_bfi = (float)sqrt((sum_f(cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand) / 2 * hFdCngCom->fftlen) / L_frame); - } + if ( st->element_mode == IVAS_CPE_MDCT && timeDomainInput == NULL ) + { + st->hTcxDec->CngLevelBackgroundTrace_bfi = sqrtf( sum_f( cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / NORM_MDCT_FACTOR ); + } + else + { + st->hTcxDec->CngLevelBackgroundTrace_bfi = (float) sqrt( ( sum_f( cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / 2 * hFdCngCom->fftlen ) / L_frame ); + } #endif - /*st->cngTDLevel = (float)sqrt( (sumFLOAT(cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand) / 2 * hFdCngCom->fftlen) / st->Mode2_L_frame);*/ - tmp_loop = sub(hFdCngCom->stopFFTbin , hFdCngCom->startBand); - L_tmp = L_deposit_h(0); - L_c = L_deposit_h(0); - FOR(j = 0 ; j < tmp_loop; j++) - { + /*st->cngTDLevel = (float)sqrt( (sumFLOAT(cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand) / 2 * hFdCngCom->fftlen) / st->Mode2_L_frame);*/ + tmp_loop = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); + L_tmp = L_deposit_h( 0 ); + L_c = L_deposit_h( 0 ); + FOR( j = 0; j < tmp_loop; j++ ) + { - Carry = 0; + Carry = 0; #ifdef BASOP_NOGLOB - L_tmp = L_add_co(L_tmp, *(cngNoiseLevel + j), &Carry, &Overflow); + L_tmp = L_add_co( L_tmp, *( cngNoiseLevel + j ), &Carry, &Overflow ); #else - L_tmp = L_add_c(L_tmp,*(cngNoiseLevel+j)); + L_tmp = L_add_c( L_tmp, *( cngNoiseLevel + j ) ); #endif - Overflow = 0; + Overflow = 0; - if(*(cngNoiseLevel+j) < 0) - { - L_c = L_msuNs(L_c,0,0); - } - if(*(cngNoiseLevel+j) >= 0) - { + if ( *( cngNoiseLevel + j ) < 0 ) + { + L_c = L_msuNs( L_c, 0, 0 ); + } + if ( *( cngNoiseLevel + j ) >= 0 ) + { #ifdef BASOP_NOGLOB - L_c = L_macNs_co(L_c, 0, 0, &Carry, &Overflow); + L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); #else - L_c = L_macNs(L_c,0,0); + L_c = L_macNs( L_c, 0, 0 ); #endif + } } - } - L_tmp = norm_llQ31(L_c,L_tmp,&L_tmp_exp); - L_tmp_exp = sub(add(L_tmp_exp,*cngNoiseLevel_exp),1); + L_tmp = norm_llQ31( L_c, L_tmp, &L_tmp_exp ); + L_tmp_exp = sub( add( L_tmp_exp, *cngNoiseLevel_exp ), 1 ); - L_tmp = Mpy_32_16_1(L_tmp,hFdCngCom->fftlen); /*Q16*/ + L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16*/ - L_tmp = Mpy_32_16_1(L_tmp,T_DIV_L_Frame[L_shl(L_mac(-28000,st->L_frame,95),1-15)]);/*Q16,exp -7*/ - L_tmp_exp = add(L_tmp_exp,-7); /*->Q16, L_tmp_exp */ - L_tmp_exp = add(L_tmp_exp,31-16); /*->Q31, L_tmp_exp*/ + L_tmp = Mpy_32_16_1( L_tmp, T_DIV_L_Frame[L_shl( L_mac( -28000, st->L_frame, 95 ), 1 - 15 )] ); /*Q16,exp -7*/ + L_tmp_exp = add( L_tmp_exp, -7 ); /*->Q16, L_tmp_exp */ + L_tmp_exp = add( L_tmp_exp, 31 - 16 ); /*->Q31, L_tmp_exp*/ #ifdef BASOP_NOGLOB - st->cngTDLevel = round_fx_sat(Sqrt32(L_tmp, &L_tmp_exp)); + st->cngTDLevel = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); #else - st->cngTDLevel = round_fx(Sqrt32(L_tmp, &L_tmp_exp)); + st->cngTDLevel = round_fx( Sqrt32( L_tmp, &L_tmp_exp ) ); #endif - st->cngTDLevel_e = L_tmp_exp; - move16(); - - - } - ELSE IF (EQ_16(st->element_mode, IVAS_CPE_TD) || EQ_16(st->element_mode, IVAS_CPE_DFT)) - { - IF (hFdCngCom->active_frame_counter > 0) + st->cngTDLevel_e = L_tmp_exp; + move16(); + } + ELSE IF( EQ_16( st->element_mode, IVAS_CPE_TD ) || EQ_16( st->element_mode, IVAS_CPE_DFT ) ) { - /* Perform noise estimation in active frames in the decoder for downward updates */ + IF( hFdCngCom->active_frame_counter > 0 ) + { + /* Perform noise estimation in active frames in the decoder for downward updates */ #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - perform_noise_estimation_dec_fx(timeDomainInput, powerSpectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD); + perform_noise_estimation_dec_fx( timeDomainInput, powerSpectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD ); #else - perform_noise_estimation_dec_fx(timeDomainInput, Q, hFdCngDec); + perform_noise_estimation_dec_fx( timeDomainInput, Q, hFdCngDec ); #endif + } } - } - test(); - test(); - L_tmp = 0; - FOR( j=hFdCngCom->startBand; jstopFFTbin; j++ ) - { - L_tmp = L_add(L_tmp,L_shr(cngNoiseLevel[j],16)); - } - L_tmp_exp = add(*cngNoiseLevel_exp,16); + test(); + test(); + L_tmp = 0; + FOR( j = hFdCngCom->startBand; j < hFdCngCom->stopFFTbin; j++ ) + { + L_tmp = L_add( L_tmp, L_shr( cngNoiseLevel[j], 16 ) ); + } + L_tmp_exp = add( *cngNoiseLevel_exp, 16 ); #ifdef BASOP_NOGLOB - IF(EQ_16(concealWholeFrame, 1) && EQ_16(st->nbLostCmpt, 1) && (L_shl_o(L_tmp, L_tmp_exp, &Overflow) > 21474836 /*0.01f Q31*/)) + IF( EQ_16( concealWholeFrame, 1 ) && EQ_16( st->nbLostCmpt, 1 ) && ( L_shl_o( L_tmp, L_tmp_exp, &Overflow ) > 21474836 /*0.01f Q31*/ ) ) #else - IF (EQ_16(concealWholeFrame,1)&&EQ_16(st->nbLostCmpt,1)&&(L_shl(L_tmp,L_tmp_exp)>21474836 /*0.01f Q31*/)) + IF( EQ_16( concealWholeFrame, 1 ) && EQ_16( st->nbLostCmpt, 1 ) && ( L_shl( L_tmp, L_tmp_exp ) > 21474836 /*0.01f Q31*/ ) ) #endif - { - /* update isf cng estimate for concealment. Do that during concealment, in order to avoid addition clean channel complexity*/ + { + /* update isf cng estimate for concealment. Do that during concealment, in order to avoid addition clean channel complexity*/ #ifndef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - lpc_from_spectrum(hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, 0); - E_LPC_a_lsp_conversion( hFdCngCom->A_cng, lsp_cng, st->lspold_cng, M ); - Copy( lsp_cng, st->lspold_cng, M); + lpc_from_spectrum( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, 0 ); + E_LPC_a_lsp_conversion( hFdCngCom->A_cng, lsp_cng, st->lspold_cng, M ); + Copy( lsp_cng, st->lspold_cng, M ); - lsp2lsf_fx( lsp_cng, st->lsf_cng, M, st->sr_core ); + lsp2lsf_fx( lsp_cng, st->lsf_cng, M, st->sr_core ); #else - if (st->element_mode == IVAS_CPE_MDCT && st->core != ACELP_CORE) - { - float scf[SNS_NPTS]; - float scf_int[FDNS_NPTS]; - float whitenend_noise_shape[L_FRAME16k]; - int16_t inc, start_idx, stop_idx; - float* noiseLevelPtr; + if ( st->element_mode == IVAS_CPE_MDCT && st->core != ACELP_CORE ) + { + float scf[SNS_NPTS]; + float scf_int[FDNS_NPTS]; + float whitenend_noise_shape[L_FRAME16k]; + int16_t inc, start_idx, stop_idx; + float *noiseLevelPtr; - inc = (st->core > TCX_20) ? 2 : 1; - start_idx = hFdCngCom->startBand / inc; - stop_idx = L_frame / inc; - noiseLevelPtr = cngNoiseLevel; + inc = ( st->core > TCX_20 ) ? 2 : 1; + start_idx = hFdCngCom->startBand / inc; + stop_idx = L_frame / inc; + noiseLevelPtr = cngNoiseLevel; - set_zero(whitenend_noise_shape, start_idx); - for (j = start_idx; j < stop_idx; j++, noiseLevelPtr += inc) - { - whitenend_noise_shape[j] = *noiseLevelPtr; - } - if (st->core == TCX_20_CORE) - { - st->hTonalMDCTConc->psychParams = &st->hTonalMDCTConc->psychParamsTCX20; + set_zero( whitenend_noise_shape, start_idx ); + for ( j = start_idx; j < stop_idx; j++, noiseLevelPtr += inc ) + { + whitenend_noise_shape[j] = *noiseLevelPtr; + } + if ( st->core == TCX_20_CORE ) + { + st->hTonalMDCTConc->psychParams = &st->hTonalMDCTConc->psychParamsTCX20; + } + else + { + st->hTonalMDCTConc->psychParams = &st->hTonalMDCTConc->psychParamsTCX10; + } + + sns_compute_scf( whitenend_noise_shape, st->hTonalMDCTConc->psychParams, L_frame, scf ); + sns_interpolate_scalefactors( scf_int, scf, ENC ); + sns_interpolate_scalefactors( st->hTonalMDCTConc->scaleFactorsBackground_flt, scf, DEC ); + sns_shape_spectrum( whitenend_noise_shape, st->hTonalMDCTConc->psychParams, scf_int, L_frame ); + + mvr2r( whitenend_noise_shape + start_idx, cngNoiseLevel, stop_idx - start_idx ); + wmops_sub_end(); } - else + else if ( st->element_mode != IVAS_CPE_MDCT ) { - st->hTonalMDCTConc->psychParams = &st->hTonalMDCTConc->psychParamsTCX10; + lpc_from_spectrum( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, 0.f ); + a2lsp_stab( hFdCngCom->A_cng, lsp_cng, st->lspold_cng ); + mvr2r( lsp_cng, st->lspold_cng, M ); + lsp2lsf( lsp_cng, st->lsf_cng, M, sr_core ); } - sns_compute_scf(whitenend_noise_shape, st->hTonalMDCTConc->psychParams, L_frame, scf); - sns_interpolate_scalefactors(scf_int, scf, ENC); - sns_interpolate_scalefactors(st->hTonalMDCTConc->scaleFactorsBackground_flt, scf, DEC); - sns_shape_spectrum(whitenend_noise_shape, st->hTonalMDCTConc->psychParams, scf_int, L_frame); - - mvr2r(whitenend_noise_shape + start_idx, cngNoiseLevel, stop_idx - start_idx); - wmops_sub_end(); - } - else if (st->element_mode != IVAS_CPE_MDCT) - { - lpc_from_spectrum(hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, 0.f); - a2lsp_stab(hFdCngCom->A_cng, lsp_cng, st->lspold_cng); - mvr2r(lsp_cng, st->lspold_cng, M); - lsp2lsf(lsp_cng, st->lsf_cng, M, sr_core); - } - #endif - st->plcBackgroundNoiseUpdated = 1; - move16(); - } - BREAK; + st->plcBackgroundNoiseUpdated = 1; + move16(); + } + BREAK; - case SID_FRAME: + case SID_FRAME: - hFdCngDec->flag_dtx_mode = 1; - move16(); - /* no break */ + hFdCngDec->flag_dtx_mode = 1; + move16(); + /* no break */ - case ZERO_FRAME: + case ZERO_FRAME: - test(); - IF(st!=NULL && st->cng_type==LP_CNG) - { - /* Perform noise estimation on inactive phase at the decoder */ + test(); + IF( st != NULL && st->cng_type == LP_CNG ) + { + /* Perform noise estimation on inactive phase at the decoder */ #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - perform_noise_estimation_dec_fx(timeDomainInput, powerSpectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD); + perform_noise_estimation_dec_fx( timeDomainInput, powerSpectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD ); #else - perform_noise_estimation_dec_fx(timeDomainInput, Q, hFdCngDec); + perform_noise_estimation_dec_fx( timeDomainInput, Q, hFdCngDec ); #endif - /* Update the shaping parameters */ + /* Update the shaping parameters */ - IF (NE_16(st->element_mode, IVAS_CPE_TD) && NE_16(st->element_mode, IVAS_CPE_DFT)) - { - scalebands(hFdCngDec->msNoiseEst, hFdCngDec->part_shaping, hFdCngDec->nFFTpart_shaping, hFdCngDec->midband_shaping, hFdCngDec->nFFTpart_shaping, hFdCngCom->stopFFTbin - hFdCngCom->startBand, hFdCngDec->bandNoiseShape, 1); - } - hFdCngDec->bandNoiseShape_exp = hFdCngDec->msNoiseEst_exp; - move16(); - /* This sets the new CNG levels until a SID update overwrites it */ - Copy32(hFdCngDec->bandNoiseShape, cngNoiseLevel, hFdCngCom->stopFFTbin-hFdCngCom->startBand); /* This sets the new CNG levels until a SID update overwrites it */ - *cngNoiseLevel_exp = hFdCngDec->bandNoiseShape_exp; - move16(); + IF( NE_16( st->element_mode, IVAS_CPE_TD ) && NE_16( st->element_mode, IVAS_CPE_DFT ) ) + { + scalebands( hFdCngDec->msNoiseEst, hFdCngDec->part_shaping, hFdCngDec->nFFTpart_shaping, hFdCngDec->midband_shaping, hFdCngDec->nFFTpart_shaping, hFdCngCom->stopFFTbin - hFdCngCom->startBand, hFdCngDec->bandNoiseShape, 1 ); + } + hFdCngDec->bandNoiseShape_exp = hFdCngDec->msNoiseEst_exp; + move16(); + /* This sets the new CNG levels until a SID update overwrites it */ + Copy32( hFdCngDec->bandNoiseShape, cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand ); /* This sets the new CNG levels until a SID update overwrites it */ + *cngNoiseLevel_exp = hFdCngDec->bandNoiseShape_exp; + move16(); #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - st->cngTDLevel = (float)sqrt((sum_f(cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand) / 2 * hFdCngCom->fftlen) / L_frame); + st->cngTDLevel = (float) sqrt( ( sum_f( cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / 2 * hFdCngCom->fftlen ) / L_frame ); #else - /*st->cngTDLevel = (float)sqrt( (sumFLOAT(cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand) / 2 * hFdCngCom->fftlen) / st->Mode2_L_frame);*/ - tmp_loop = sub(hFdCngCom->stopFFTbin , hFdCngCom->startBand); - L_tmp = L_deposit_h(0); - L_c = L_deposit_h(0); - FOR(j = 0 ; j < tmp_loop; j++) - { + /*st->cngTDLevel = (float)sqrt( (sumFLOAT(cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand) / 2 * hFdCngCom->fftlen) / st->Mode2_L_frame);*/ + tmp_loop = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); + L_tmp = L_deposit_h( 0 ); + L_c = L_deposit_h( 0 ); + FOR( j = 0; j < tmp_loop; j++ ) + { - Carry = 0; + Carry = 0; #ifdef BASOP_NOGLOB /* Critical Carry/Overflow */ - L_tmp = L_add_co(L_tmp,*(cngNoiseLevel+j), &Carry, &Overflow); - Overflow = 0; + L_tmp = L_add_co( L_tmp, *( cngNoiseLevel + j ), &Carry, &Overflow ); + Overflow = 0; - if(*(cngNoiseLevel+j) < 0) - { - L_c = L_msuNs_co(L_c,0,0, &Carry, &Overflow); - } - if(*(cngNoiseLevel+j) >= 0) - { - L_c = L_macNs_co(L_c,0,0, &Carry, &Overflow); - } + if ( *( cngNoiseLevel + j ) < 0 ) + { + L_c = L_msuNs_co( L_c, 0, 0, &Carry, &Overflow ); + } + if ( *( cngNoiseLevel + j ) >= 0 ) + { + L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); + } #else - L_tmp = L_add_c(L_tmp,*(cngNoiseLevel+j)); - Overflow = 0; + L_tmp = L_add_c( L_tmp, *( cngNoiseLevel + j ) ); + Overflow = 0; - if(*(cngNoiseLevel+j) < 0) - { - L_c = L_msuNs(L_c,0,0); - } - if(*(cngNoiseLevel+j) >= 0) - { - L_c = L_macNs(L_c,0,0); - } + if ( *( cngNoiseLevel + j ) < 0 ) + { + L_c = L_msuNs( L_c, 0, 0 ); + } + if ( *( cngNoiseLevel + j ) >= 0 ) + { + L_c = L_macNs( L_c, 0, 0 ); + } #endif - } - L_tmp = norm_llQ31(L_c,L_tmp,&L_tmp_exp); - L_tmp_exp = sub(add(L_tmp_exp,*cngNoiseLevel_exp),1); + } + L_tmp = norm_llQ31( L_c, L_tmp, &L_tmp_exp ); + L_tmp_exp = sub( add( L_tmp_exp, *cngNoiseLevel_exp ), 1 ); - L_tmp = Mpy_32_16_1(L_tmp,hFdCngCom->fftlen); /*Q16*/ + L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16*/ - L_tmp = Mpy_32_16_1(L_tmp,T_DIV_L_Frame[L_shl(L_mac(-28000,st->L_frame,95),1-15)]);/*Q16,exp -7*/ - L_tmp_exp = add(L_tmp_exp,-7); /*->Q16, L_tmp_exp */ - L_tmp_exp = add(L_tmp_exp,31-16); /*->Q31, L_tmp_exp*/ + L_tmp = Mpy_32_16_1( L_tmp, T_DIV_L_Frame[L_shl( L_mac( -28000, st->L_frame, 95 ), 1 - 15 )] ); /*Q16,exp -7*/ + L_tmp_exp = add( L_tmp_exp, -7 ); /*->Q16, L_tmp_exp */ + L_tmp_exp = add( L_tmp_exp, 31 - 16 ); /*->Q31, L_tmp_exp*/ #ifdef BASOP_NOGLOB /* Critical Carry/Overflow */ - st->cngTDLevel = round_fx_o(Sqrt32(L_tmp, &L_tmp_exp), &Overflow); + st->cngTDLevel = round_fx_o( Sqrt32( L_tmp, &L_tmp_exp ), &Overflow ); #else - st->cngTDLevel = round_fx(Sqrt32(L_tmp, &L_tmp_exp)); -#endif - st->cngTDLevel_e = L_tmp_exp; - move16(); -#endif - BREAK; - } - hFdCngCom->inactive_frame_counter = add(hFdCngCom->inactive_frame_counter,1); - move16(); - - /************************************* - * SID_FRAME or ZERO_FRAME at DECODER * - *************************************/ - - /* Detect first non-active frame */ - IF ( EQ_16(hFdCngCom->inactive_frame_counter,1)) - { - /* Compute the fine spectral structure of the comfort noise shape using the decoder-side noise estimates */ - bandcombinepow ( - hFdCngDec->bandNoiseShape, - hFdCngDec->bandNoiseShape_exp, - nBins, - hFdCngCom->part, - hFdCngCom->nFFTpart, - hFdCngCom->psize_inv, - hFdCngDec->partNoiseShape, - &hFdCngDec->partNoiseShape_exp - ); - IF (EQ_16(st->element_mode, IVAS_CPE_DFT)) - { -#ifdef IVAS_CODE_CNG - Copy(hFdCngDec->hFdCngCom->sidNoiseEst, hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART); + st->cngTDLevel = round_fx( Sqrt32( L_tmp, &L_tmp_exp ) ); #endif - } - } - - IF ( EQ_16(st->m_frame_type,SID_FRAME)) - { - IF ( LT_32(hFdCngCom->msFrCnt_init_counter,L_deposit_l(hFdCngCom->msFrCnt_init_thresh))) - { - /* At initialization, interpolate the bin/band-wise levels from the partition levels */ - scalebands (hFdCngCom->sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, - hFdCngCom->nFFTpart, sub(hFdCngCom->stopBand,hFdCngCom->startBand), cngNoiseLevel,1 ); - *cngNoiseLevel_exp = hFdCngCom->sidNoiseEstExp; + st->cngTDLevel_e = L_tmp_exp; move16(); +#endif + BREAK; } - ELSE + hFdCngCom->inactive_frame_counter = add( hFdCngCom->inactive_frame_counter, 1 ); + move16(); + + /************************************* + * SID_FRAME or ZERO_FRAME at DECODER * + *************************************/ + + /* Detect first non-active frame */ + IF( EQ_16( hFdCngCom->inactive_frame_counter, 1 ) ) { - if (EQ_16(st->element_mode, IVAS_CPE_DFT)) + /* Compute the fine spectral structure of the comfort noise shape using the decoder-side noise estimates */ + bandcombinepow( + hFdCngDec->bandNoiseShape, + hFdCngDec->bandNoiseShape_exp, + nBins, + hFdCngCom->part, + hFdCngCom->nFFTpart, + hFdCngCom->psize_inv, + hFdCngDec->partNoiseShape, + &hFdCngDec->partNoiseShape_exp ); + IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) { #ifdef IVAS_CODE_CNG - sidNoiseEst = hFdCngCom->sidNoiseEstLp; + Copy( hFdCngDec->hFdCngCom->sidNoiseEst, hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART ); #endif - move16(); } - /* Interpolate the CLDFB band levels from the SID (partition) levels */ - IF ( GT_16( hFdCngCom->regularStopBand, hFdCngCom->numCoreBands )) - { - scalebands ( hFdCngCom->sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, - hFdCngCom->nFFTpart, sub(hFdCngCom->stopBand,hFdCngCom->startBand), cngNoiseLevel, 0); + } + IF( EQ_16( st->m_frame_type, SID_FRAME ) ) + { + IF( LT_32( hFdCngCom->msFrCnt_init_counter, L_deposit_l( hFdCngCom->msFrCnt_init_thresh ) ) ) + { + /* At initialization, interpolate the bin/band-wise levels from the partition levels */ + scalebands( hFdCngCom->sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, + hFdCngCom->nFFTpart, sub( hFdCngCom->stopBand, hFdCngCom->startBand ), cngNoiseLevel, 1 ); *cngNoiseLevel_exp = hFdCngCom->sidNoiseEstExp; move16(); } - - s2 = -(WORD32_BITS-1); - move16(); - /* Shape the SID noise levels in each FFT bin */ - j = 0; - move16(); - FOR (k=0; k < hFdCngCom->nFFTpart ; k++) + ELSE { - assert(hFdCngDec->partNoiseShape[k]>=0); - - /* add DELTA as it is done in FLC version, in order to avoid num > denom */ - facTab[k] = 0; - move16(); - IF ( hFdCngDec->partNoiseShape[k] != 0) + if ( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) { - s1 = norm_l(hFdCngCom->sidNoiseEst[k]); - L_tmp = L_shl(hFdCngCom->sidNoiseEst[k], s1); - L_tmp_exp = sub(hFdCngCom->sidNoiseEstExp, s1); - L_tmp = BASOP_Util_Add_Mant32Exp(hFdCngCom->sidNoiseEst[k], hFdCngCom->sidNoiseEstExp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp); - L_tmp = L_shr(L_tmp, 1); - s = add(L_tmp_exp, 1); - num = extract_h(L_tmp); - - s1 = norm_l(hFdCngDec->partNoiseShape[k]); - L_tmp = L_shl(hFdCngDec->partNoiseShape[k], s1); - L_tmp_exp = sub(hFdCngDec->partNoiseShape_exp, s1); - L_tmp = BASOP_Util_Add_Mant32Exp(L_tmp, L_tmp_exp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp); - s = sub(s, L_tmp_exp); - denom = extract_h(L_tmp); - - facTab[k] = div_s(num,denom); +#ifdef IVAS_CODE_CNG + sidNoiseEst = hFdCngCom->sidNoiseEstLp; +#endif move16(); - facTabExp[k] = s; + } + /* Interpolate the CLDFB band levels from the SID (partition) levels */ + IF( GT_16( hFdCngCom->regularStopBand, hFdCngCom->numCoreBands ) ) + { + scalebands( hFdCngCom->sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, + hFdCngCom->nFFTpart, sub( hFdCngCom->stopBand, hFdCngCom->startBand ), cngNoiseLevel, 0 ); + + *cngNoiseLevel_exp = hFdCngCom->sidNoiseEstExp; move16(); } - /* Set unique exponent, if mantissa is equal to zero */ - if (facTab[k] == 0) + + s2 = -( WORD32_BITS - 1 ); + move16(); + /* Shape the SID noise levels in each FFT bin */ + j = 0; + move16(); + FOR( k = 0; k < hFdCngCom->nFFTpart; k++ ) { - facTabExp[k] = -(WORD32_BITS-1); + assert( hFdCngDec->partNoiseShape[k] >= 0 ); + + /* add DELTA as it is done in FLC version, in order to avoid num > denom */ + facTab[k] = 0; move16(); + IF( hFdCngDec->partNoiseShape[k] != 0 ) + { + s1 = norm_l( hFdCngCom->sidNoiseEst[k] ); + L_tmp = L_shl( hFdCngCom->sidNoiseEst[k], s1 ); + L_tmp_exp = sub( hFdCngCom->sidNoiseEstExp, s1 ); + L_tmp = BASOP_Util_Add_Mant32Exp( hFdCngCom->sidNoiseEst[k], hFdCngCom->sidNoiseEstExp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp ); + L_tmp = L_shr( L_tmp, 1 ); + s = add( L_tmp_exp, 1 ); + num = extract_h( L_tmp ); + + s1 = norm_l( hFdCngDec->partNoiseShape[k] ); + L_tmp = L_shl( hFdCngDec->partNoiseShape[k], s1 ); + L_tmp_exp = sub( hFdCngDec->partNoiseShape_exp, s1 ); + L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, L_tmp_exp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp ); + s = sub( s, L_tmp_exp ); + denom = extract_h( L_tmp ); + + facTab[k] = div_s( num, denom ); + move16(); + facTabExp[k] = s; + move16(); + } + /* Set unique exponent, if mantissa is equal to zero */ + if ( facTab[k] == 0 ) + { + facTabExp[k] = -( WORD32_BITS - 1 ); + move16(); + } + s2 = s_max( s2, facTabExp[k] ); } - s2 = s_max(s2,facTabExp[k]); - } - FOR (k=0; k < hFdCngCom->nFFTpart; k++) - { - s = sub(facTabExp[k],s2); - s = s_max(s_min(s,WORD32_BITS-1),-(WORD32_BITS-1)); - FOR( ; j <= hFdCngCom->part[k]; j++) + FOR( k = 0; k < hFdCngCom->nFFTpart; k++ ) { - cngNoiseLevel[j] = L_shl(Mpy_32_16_1(hFdCngDec->bandNoiseShape[j],facTab[k]),s); - move32(); + s = sub( facTabExp[k], s2 ); + s = s_max( s_min( s, WORD32_BITS - 1 ), -( WORD32_BITS - 1 ) ); + FOR( ; j <= hFdCngCom->part[k]; j++ ) + { + cngNoiseLevel[j] = L_shl( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); + move32(); + } } - } - /* adapt scaling for rest of the buffer */ - s = sub(*cngNoiseLevel_exp,add(hFdCngDec->bandNoiseShape_exp,s2)); - FOR ( ; k < hFdCngCom->npart; k++) - { - FOR( ; j <= hFdCngCom->part[k]; j++) + /* adapt scaling for rest of the buffer */ + s = sub( *cngNoiseLevel_exp, add( hFdCngDec->bandNoiseShape_exp, s2 ) ); + FOR( ; k < hFdCngCom->npart; k++ ) { - cngNoiseLevel[j] = L_shl(cngNoiseLevel[j],s); - move32(); + FOR( ; j <= hFdCngCom->part[k]; j++ ) + { + cngNoiseLevel[j] = L_shl( cngNoiseLevel[j], s ); + move32(); + } } + *cngNoiseLevel_exp = add( hFdCngDec->bandNoiseShape_exp, s2 ); + move16(); } - *cngNoiseLevel_exp = add(hFdCngDec->bandNoiseShape_exp,s2); - move16(); } - } #ifdef IVAS_CODE_CNG - else if (st->element_mode == IVAS_CPE_DFT) - { - if (!(hFdCngCom->msFrCnt_init_counter < hFdCngCom->msFrCnt_init_thresh)) + else if ( st->element_mode == IVAS_CPE_DFT ) { - sidNoiseEst = hFdCngCom->sidNoiseEstLp; - j = 0; - for (k = 0; k < hFdCngCom->nFFTpart; k++) + if ( !( hFdCngCom->msFrCnt_init_counter < hFdCngCom->msFrCnt_init_thresh ) ) { - factor = (sidNoiseEst[k] + DELTA) / (hFdCngDec->partNoiseShape[k] + DELTA); - for (; j <= hFdCngCom->part[k]; j++) + sidNoiseEst = hFdCngCom->sidNoiseEstLp; + j = 0; + for ( k = 0; k < hFdCngCom->nFFTpart; k++ ) { - cngNoiseLevel[j] = hFdCngDec->bandNoiseShape[j] * factor; + factor = ( sidNoiseEst[k] + DELTA ) / ( hFdCngDec->partNoiseShape[k] + DELTA ); + for ( ; j <= hFdCngCom->part[k]; j++ ) + { + cngNoiseLevel[j] = hFdCngDec->bandNoiseShape[j] * factor; + } } } } - } #endif - IF ( EQ_16(st->codec_mode, MODE2)) - { - /* Generate comfort noise during SID or zero frames */ - generate_comfort_noise_dec_fx (cldfbBufferReal, cldfbBufferImag, cldfbBufferScale, st, &(st->Q_exc), 2, -1); - } + IF( EQ_16( st->codec_mode, MODE2 ) ) + { + /* Generate comfort noise during SID or zero frames */ + generate_comfort_noise_dec_fx( cldfbBufferReal, cldfbBufferImag, cldfbBufferScale, st, &( st->Q_exc ), 2, -1 ); + } - BREAK; + BREAK; - default: - return -1; + default: + return -1; } @@ -1208,11 +1198,11 @@ Word16 ApplyFdCng_ivas_fx( Flag Carry = 0; #endif Word16 L_frame, last_L_frame; - //Word32 *sidNoiseEst; + // Word32 *sidNoiseEst; hFdCngDec = st->hFdCngDec; hFdCngCom = hFdCngDec->hFdCngCom; - //sidNoiseEst = hFdCngCom->sidNoiseEst; + // sidNoiseEst = hFdCngCom->sidNoiseEst; /* limit L_frame and core fs values for MDCT-Stereo modes which can have higher core sampling than 16kHz, but use a downsampled buffer */ L_frame = s_min( st->L_frame, L_FRAME16k ); @@ -1388,7 +1378,7 @@ Word16 ApplyFdCng_ivas_fx( IF( ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && timeDomainInput == NULL ) ) { - //st->hTcxDec->CngLevelBackgroundTrace_bfi = sqrtf(sum_f(cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand) / NORM_MDCT_FACTOR); + // st->hTcxDec->CngLevelBackgroundTrace_bfi = sqrtf(sum_f(cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand) / NORM_MDCT_FACTOR); tmp_loop = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); L_tmp = L_deposit_h( 0 ); @@ -1427,20 +1417,20 @@ Word16 ApplyFdCng_ivas_fx( L_tmp_exp = add( L_tmp_exp, 31 - 16 ); /*->Q31, L_tmp_exp*/ #ifdef BASOP_NOGLOB - //st->hTcxDec->CngLevelBackgroundTrace_bfi_fx = ( Sqrt32( L_tmp, &L_tmp_exp ) ); + // st->hTcxDec->CngLevelBackgroundTrace_bfi_fx = ( Sqrt32( L_tmp, &L_tmp_exp ) ); st->hTcxDec->conCngLevelBackgroundTrace = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); #else st->hTcxDec->conCngLevelBackgroundTrace = round_fx( Sqrt32( L_tmp, &L_tmp_exp ) ); - //st->hTcxDec->CngLevelBackgroundTrace_bfi_fx = ( Sqrt32( L_tmp, &L_tmp_exp ) ); + // st->hTcxDec->CngLevelBackgroundTrace_bfi_fx = ( Sqrt32( L_tmp, &L_tmp_exp ) ); #endif L_tmp_exp = add( L_tmp_exp, 1 ); - //st->hTcxDec->CngLevelBackgroundTrace_bfi_exp = L_tmp_exp; + // st->hTcxDec->CngLevelBackgroundTrace_bfi_exp = L_tmp_exp; st->hTcxDec->conCngLevelBackgroundTrace_e = L_tmp_exp; move16(); } ELSE { - //st->hTcxDec->CngLevelBackgroundTrace_bfi = (float)sqrt((sum_f(cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand) / 2 * hFdCngCom->fftlen) / L_frame); + // st->hTcxDec->CngLevelBackgroundTrace_bfi = (float)sqrt((sum_f(cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand) / 2 * hFdCngCom->fftlen) / L_frame); tmp_loop = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); L_tmp = L_deposit_h( 0 ); @@ -1479,13 +1469,13 @@ Word16 ApplyFdCng_ivas_fx( L_tmp_exp = add( L_tmp_exp, 31 - 16 ); /*->Q31, L_tmp_exp*/ #ifdef BASOP_NOGLOB - //st->hTcxDec->CngLevelBackgroundTrace_bfi_fx = ( Sqrt32( L_tmp, &L_tmp_exp ) ); + // st->hTcxDec->CngLevelBackgroundTrace_bfi_fx = ( Sqrt32( L_tmp, &L_tmp_exp ) ); st->hTcxDec->conCngLevelBackgroundTrace = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); #else st->hTcxDec->conCngLevelBackgroundTrace = round_fx( Sqrt32( L_tmp, &L_tmp_exp ) ); st->hTcxDec->CngLevelBackgroundTrace_bfi_fx = ( Sqrt32( L_tmp, &L_tmp_exp ) ); #endif - //st->hTcxDec->CngLevelBackgroundTrace_bfi_exp = L_tmp_exp; + // st->hTcxDec->CngLevelBackgroundTrace_bfi_exp = L_tmp_exp; st->hTcxDec->conCngLevelBackgroundTrace_e = L_tmp_exp; move16(); } @@ -1545,7 +1535,7 @@ Word16 ApplyFdCng_ivas_fx( } test(); test(); - + IF( EQ_16( concealWholeFrame, 1 ) && EQ_16( st->nbLostCmpt, 1 ) ) { /* always set psychParameters for MDCT-Stereo ... */ @@ -1559,27 +1549,27 @@ Word16 ApplyFdCng_ivas_fx( move32(); FOR( j = hFdCngCom->startBand; j < hFdCngCom->stopFFTbin; j++ ) { - L_tmp = L_add_sat( L_tmp, L_shl_sat(cngNoiseLevel[j], 31 - *cngNoiseLevel_exp) ); + L_tmp = L_add_sat( L_tmp, L_shl_sat( cngNoiseLevel[j], 31 - *cngNoiseLevel_exp ) ); } L_tmp_exp = 0; move16(); #ifdef BASOP_NOGLOB - IF(L_shl_o(L_tmp, L_tmp_exp, &Overflow) > 21474836 /*0.01f Q31*/) + IF( L_shl_o( L_tmp, L_tmp_exp, &Overflow ) > 21474836 /*0.01f Q31*/ ) #else IF( L_shl( L_tmp, L_tmp_exp ) > 21474836 /*0.01f Q31*/ ) #endif { - IF(EQ_16(st->element_mode, IVAS_CPE_MDCT) && NE_16(st->core, ACELP_CORE)) + IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && NE_16( st->core, ACELP_CORE ) ) { - TonalMdctConceal_whiten_noise_shape_ivas_fx(st, L_frame, ON_FIRST_LOST_FRAME); + TonalMdctConceal_whiten_noise_shape_ivas_fx( st, L_frame, ON_FIRST_LOST_FRAME ); } - ELSE IF(NE_16(st->element_mode, IVAS_CPE_MDCT) || EQ_16(st->core, ACELP_CORE)) + ELSE IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) || EQ_16( st->core, ACELP_CORE ) ) { - lpc_from_spectrum(hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, 0); - E_LPC_a_lsp_conversion(hFdCngCom->A_cng, lsp_cng, st->lspold_cng, M); - Copy(lsp_cng, st->lspold_cng, M); + lpc_from_spectrum( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, 0 ); + E_LPC_a_lsp_conversion( hFdCngCom->A_cng, lsp_cng, st->lspold_cng, M ); + Copy( lsp_cng, st->lspold_cng, M ); - lsp2lsf_fx(lsp_cng, st->lsf_cng, M, st->sr_core); + lsp2lsf_fx( lsp_cng, st->lsf_cng, M, st->sr_core ); } st->plcBackgroundNoiseUpdated = 1; @@ -1699,22 +1689,22 @@ Word16 ApplyFdCng_ivas_fx( { /* At initialization, interpolate the bin/band-wise levels from the partition levels */ scalebands_fx( hFdCngCom->sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, - hFdCngCom->nFFTpart, sub( hFdCngCom->stopBand, hFdCngCom->startBand ), cngNoiseLevel, 1 ); + hFdCngCom->nFFTpart, sub( hFdCngCom->stopBand, hFdCngCom->startBand ), cngNoiseLevel, 1 ); *cngNoiseLevel_exp = hFdCngCom->sidNoiseEstExp; move16(); } ELSE { - //IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) + // IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) //{ - // sidNoiseEst = hFdCngCom->sidNoiseEstLp; - // move16(); - //} + // sidNoiseEst = hFdCngCom->sidNoiseEstLp; + // move16(); + // } /* Interpolate the CLDFB band levels from the SID (partition) levels */ IF( GT_16( hFdCngCom->regularStopBand, hFdCngCom->numCoreBands ) ) { scalebands_fx( hFdCngCom->sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, - hFdCngCom->nFFTpart, sub( hFdCngCom->stopBand, hFdCngCom->startBand ), cngNoiseLevel, 0 ); + hFdCngCom->nFFTpart, sub( hFdCngCom->stopBand, hFdCngCom->startBand ), cngNoiseLevel, 0 ); *cngNoiseLevel_exp = hFdCngCom->sidNoiseEstExp; move16(); @@ -1762,9 +1752,10 @@ Word16 ApplyFdCng_ivas_fx( } s2 = s_max( s2, facTabExp[k] ); } - IF(EQ_16(s2, -31)) + IF( EQ_16( s2, -31 ) ) { - s2 = 0; move16(); + s2 = 0; + move16(); } FOR( k = 0; k < hFdCngCom->nFFTpart; k++ ) { @@ -1794,7 +1785,7 @@ Word16 ApplyFdCng_ivas_fx( { IF( !( hFdCngCom->msFrCnt_init_counter < hFdCngCom->msFrCnt_init_thresh ) ) { - //sidNoiseEst = hFdCngCom->sidNoiseEstLp; + // sidNoiseEst = hFdCngCom->sidNoiseEstLp; s2 = negate( sub( WORD32_BITS, 1 ) ); move16(); @@ -1838,9 +1829,10 @@ Word16 ApplyFdCng_ivas_fx( } s2 = s_max( s2, facTabExp[k] ); } - IF(EQ_16(s2, -31)) + IF( EQ_16( s2, -31 ) ) { - s2 = 0; move16(); + s2 = 0; + move16(); } FOR( k = 0; k < hFdCngCom->nFFTpart; k++ ) { @@ -1898,36 +1890,37 @@ Word16 ApplyFdCng_ivas_fx( Returns: void */ -void perform_noise_estimation_dec_fx ( +void perform_noise_estimation_dec_fx( const Word16 *timeDomainInput, /* i: pointer to time domain input */ - const Word16 Q, + const Word16 Q, #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - float* power_spectrum, + float *power_spectrum, #endif - HANDLE_FD_CNG_DEC hFdCngDec /* i/o: FD_CNG structure containing all buffers and variables */ + HANDLE_FD_CNG_DEC hFdCngDec /* i/o: FD_CNG structure containing all buffers and variables */ #ifdef IVAS_CODE_CNG - ,const int16_t element_mode, /* i : element mode */ + , + const int16_t element_mode, /* i : element mode */ const int16_t bwidth, /* i : audio bandwidth */ const int16_t L_frame, /* i : frame length at internal Fs */ const int16_t last_L_frame, /* i : frame length of the last frame at internal Fs */ const int32_t last_core_brate, /* i : previous frame core bitrate */ const int16_t VAD /* i : VAD flag in the decoder */ #endif - ) +) { - Word16 i, tmp_r, tmp_i, fac, fftBuffer_exp; - Word16 s, len, npart, nFFTpart; - Word16 startBand, stopFFTbin; + Word16 i, tmp_r, tmp_i, fac, fftBuffer_exp; + Word16 s, len, npart, nFFTpart; + Word16 startBand, stopFFTbin; Word16 *part, *psize_inv, *psize_norm; Word32 tmp, *fftBuffer, *periodog, *ptr_per, *ptr_r, *ptr_i; #ifdef IVAS_CODE_CNG - PMT("lots of code related to IVAS needs to be done ") + PMT( "lots of code related to IVAS needs to be done " ) #endif /* pointer initialization */ - periodog = hFdCngDec->hFdCngCom->periodog; + periodog = hFdCngDec->hFdCngCom->periodog; fftBuffer = hFdCngDec->hFdCngCom->fftBuffer; part = hFdCngDec->part_shaping; @@ -1935,7 +1928,7 @@ void perform_noise_estimation_dec_fx ( psize_norm = hFdCngDec->psize_shaping_norm; /* variable initialization */ - startBand = hFdCngDec->hFdCngCom->startBand; + startBand = hFdCngDec->hFdCngCom->startBand; move16(); stopFFTbin = hFdCngDec->hFdCngCom->stopFFTbin; move16(); @@ -1947,23 +1940,23 @@ void perform_noise_estimation_dec_fx ( /* Perform STFT analysis */ #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - IF (!(EQ_16(element_mode, IVAS_CPE_MDCT) && power_spectrum != NULL)) + IF( !( EQ_16( element_mode, IVAS_CPE_MDCT ) && power_spectrum != NULL ) ) { /* Perform STFT analysis */ - AnalysisSTFT(timeDomainInput, Q, fftBuffer, &fftBuffer_exp, hFdCngDec->hFdCngCom); + AnalysisSTFT( timeDomainInput, Q, fftBuffer, &fftBuffer_exp, hFdCngDec->hFdCngCom ); } #else /* Perform STFT analysis */ - AnalysisSTFT (timeDomainInput, Q, fftBuffer, &fftBuffer_exp, hFdCngDec->hFdCngCom); + AnalysisSTFT( timeDomainInput, Q, fftBuffer, &fftBuffer_exp, hFdCngDec->hFdCngCom ); #endif - fftBuffer_exp = add(fftBuffer_exp,WORD16_BITS-1); + fftBuffer_exp = add( fftBuffer_exp, WORD16_BITS - 1 ); #ifdef IVAS_CODE_CNG - if (element_mode == IVAS_CPE_TD || element_mode == IVAS_CPE_DFT) + if ( element_mode == IVAS_CPE_TD || element_mode == IVAS_CPE_DFT ) { /* Calculate periodogram (squared magnitude in each FFT bin) */ - if (startBand == 0) + if ( startBand == 0 ) { - (*ptr_per) = fftBuffer[0] * fftBuffer[0]; + ( *ptr_per ) = fftBuffer[0] * fftBuffer[0]; ptr_per++; ptr_r = fftBuffer + 2; } @@ -1974,24 +1967,24 @@ void perform_noise_estimation_dec_fx ( ptr_i = ptr_r + 1; - for (; ptr_per < periodog + stopFFTbin - startBand; ptr_per++) + for ( ; ptr_per < periodog + stopFFTbin - startBand; ptr_per++ ) { - (*ptr_per) = (*ptr_r) * (*ptr_r) + (*ptr_i) * (*ptr_i); + ( *ptr_per ) = ( *ptr_r ) * ( *ptr_r ) + ( *ptr_i ) * ( *ptr_i ); ptr_r += 2; ptr_i += 2; } /* Rescale to get energy/sample: it should be 2*(1/N)*(2/N), parseval relation with 1/N,*2 for nrg computed till Nyquist only, 2/N as windowed samples correspond to half a frame*/ - v_multc(periodog, 4.f / (float)(hFdCngDec->hFdCngCom->fftlen * hFdCngDec->hFdCngCom->fftlen), periodog, stopFFTbin - startBand); + v_multc( periodog, 4.f / (float) ( hFdCngDec->hFdCngCom->fftlen * hFdCngDec->hFdCngCom->fftlen ), periodog, stopFFTbin - startBand ); /* Combine bins of power spectrum into partitions */ i = 0; - for (p = 0; p < npart; p++) + for ( p = 0; p < npart; p++ ) { /* calculate mean over all bins in power partition */ temp = 0; - for (; i <= part[p]; i++) + for ( ; i <= part[p]; i++ ) { temp += periodog[i]; } @@ -1999,14 +1992,14 @@ void perform_noise_estimation_dec_fx ( } /* compensate for the loss of variance - don't do when first noise update is not completed yet due to risk of msPeriodog[p] < 0 */ - if (hFdCngDec->first_cna_noise_updated) + if ( hFdCngDec->first_cna_noise_updated ) { i = 0; - for (p = 0; p < npart; p++) + for ( p = 0; p < npart; p++ ) { /* calculate variance over all bins in power partition */ temp = 0; - for (; i <= part[p]; i++) + for ( ; i <= part[p]; i++ ) { delta = periodog[i] - msPeriodog[p]; temp += delta * delta; @@ -2014,9 +2007,9 @@ void perform_noise_estimation_dec_fx ( temp *= psize_inv[p]; /* compensate for the loss of variance */ - msPeriodog[p] = (float)(msPeriodog[p] + sqrt(temp) * rand_gauss(&ftemp, &hFdCngDec->cna_seed)); + msPeriodog[p] = (float) ( msPeriodog[p] + sqrt( temp ) * rand_gauss( &ftemp, &hFdCngDec->cna_seed ) ); - if (msPeriodog[p] < 1e-5f) + if ( msPeriodog[p] < 1e-5f ) { msPeriodog[p] = 1e-5f; } @@ -2024,20 +2017,20 @@ void perform_noise_estimation_dec_fx ( } /* calculate total energy (short-term and long-term) */ - enr_tot = sum_f(msPeriodog, npart) + EPSILON; - enr_tot0 = sum_f(msNoiseEst, npart) + EPSILON; + enr_tot = sum_f( msPeriodog, npart ) + EPSILON; + enr_tot0 = sum_f( msNoiseEst, npart ) + EPSILON; /* update short-term periodogram on larger partitions */ - for (p = CNA_ACT_DN_LARGE_PARTITION; p < npart; p++) + for ( p = CNA_ACT_DN_LARGE_PARTITION; p < npart; p++ ) { - if (L_frame != last_L_frame || last_core_brate <= SID_2k40) + if ( L_frame != last_L_frame || last_core_brate <= SID_2k40 ) { /* core Fs has changed or last frame was SID/NO_DATA -> re-initialize short-term periodogram */ hFdCngDec->msPeriodog_ST[p] = msPeriodog[p]; } else { - hFdCngDec->msPeriodog_ST[p] = (float)(ST_PERIODOG_FACT * hFdCngDec->msPeriodog_ST[p] + (1 - ST_PERIODOG_FACT) * msPeriodog[p]); + hFdCngDec->msPeriodog_ST[p] = (float) ( ST_PERIODOG_FACT * hFdCngDec->msPeriodog_ST[p] + ( 1 - ST_PERIODOG_FACT ) * msPeriodog[p] ); } } @@ -2052,20 +2045,20 @@ void perform_noise_estimation_dec_fx ( /* [60] 317 230 */ /* [61] 253 */ - if (last_L_frame == L_FRAME16k && L_frame == L_FRAME) + if ( last_L_frame == L_FRAME16k && L_frame == L_FRAME ) { msNoiseEst[61] = msNoiseEst[58]; - msNoiseEst[60] = min(msNoiseEst[58], msNoiseEst[57]); + msNoiseEst[60] = min( msNoiseEst[58], msNoiseEst[57] ); msNoiseEst[59] = msNoiseEst[57]; msNoiseEst[58] = msNoiseEst[56]; msNoiseEst[57] = msNoiseEst[56]; - msNoiseEst[56] = min(msNoiseEst[56], msNoiseEst[55]); + msNoiseEst[56] = min( msNoiseEst[56], msNoiseEst[55] ); } - else if (last_L_frame == L_FRAME && L_frame == L_FRAME16k) + else if ( last_L_frame == L_FRAME && L_frame == L_FRAME16k ) { - msNoiseEst[56] = min(msNoiseEst[56], msNoiseEst[57]); - msNoiseEst[57] = min(msNoiseEst[58], msNoiseEst[59]); - msNoiseEst[58] = min(msNoiseEst[60], msNoiseEst[61]); + msNoiseEst[56] = min( msNoiseEst[56], msNoiseEst[57] ); + msNoiseEst[57] = min( msNoiseEst[58], msNoiseEst[59] ); + msNoiseEst[58] = min( msNoiseEst[60], msNoiseEst[61] ); msNoiseEst[59] = 0.0f; msNoiseEst[60] = 0.0f; msNoiseEst[61] = 0.0f; @@ -2074,26 +2067,26 @@ void perform_noise_estimation_dec_fx ( } /* Smooth with IIR filter */ - if (!hFdCngDec->first_cna_noise_updated) + if ( !hFdCngDec->first_cna_noise_updated ) { - if (!VAD) + if ( !VAD ) { /* background noise update with moving average */ - alpha = 1.0f / (hFdCngDec->first_cna_noise_update_cnt + 1); - for (p = 0; p < npart; p++) + alpha = 1.0f / ( hFdCngDec->first_cna_noise_update_cnt + 1 ); + for ( p = 0; p < npart; p++ ) { - msNoiseEst[p] = (1 - alpha) * msNoiseEst[p] + alpha * msPeriodog[p]; + msNoiseEst[p] = ( 1 - alpha ) * msNoiseEst[p] + alpha * msPeriodog[p]; } /* check, if we reached the required number of first CNA noise update frames */ - if (hFdCngDec->first_cna_noise_update_cnt < FIRST_CNA_NOISE_UPD_FRAMES - 1) + if ( hFdCngDec->first_cna_noise_update_cnt < FIRST_CNA_NOISE_UPD_FRAMES - 1 ) { hFdCngDec->first_cna_noise_update_cnt++; } else { hFdCngDec->first_cna_noise_updated = 1; - if (hFdCngDec->hFdCngCom->msFrCnt_init_counter == 0) + if ( hFdCngDec->hFdCngCom->msFrCnt_init_counter == 0 ) { hFdCngDec->hFdCngCom->msFrCnt_init_counter = 1; } @@ -2107,30 +2100,30 @@ void perform_noise_estimation_dec_fx ( else { hFdCngDec->hFdCngCom->msFrCnt_init_counter = 1; - if (VAD) + if ( VAD ) { /* no updates during active frames except for significant energy drops */ enr_ratio = enr_tot / enr_tot0; - if (enr_ratio < 0.5f) + if ( enr_ratio < 0.5f ) { /* total energy significantly decreases during active frames -> downward update */ - wght = lin_interp(enr_ratio, 0.0f, 0.8f, 0.5f, 0.95f, 1); - for (p = 0; p < npart; p++) + wght = lin_interp( enr_ratio, 0.0f, 0.8f, 0.5f, 0.95f, 1 ); + for ( p = 0; p < npart; p++ ) { - if (msPeriodog[p] < msNoiseEst[p]) + if ( msPeriodog[p] < msNoiseEst[p] ) { - msNoiseEst[p] = wght * msNoiseEst[p] + (1 - wght) * msPeriodog[p]; + msNoiseEst[p] = wght * msNoiseEst[p] + ( 1 - wght ) * msPeriodog[p]; } } } else { /* energy significantly decreases in one of the larger partitions during active frames -> downward update */ - for (p = CNA_ACT_DN_LARGE_PARTITION; p < npart; p++) + for ( p = CNA_ACT_DN_LARGE_PARTITION; p < npart; p++ ) { - if (hFdCngDec->msPeriodog_ST[p] < msNoiseEst[p]) + if ( hFdCngDec->msPeriodog_ST[p] < msNoiseEst[p] ) { - msNoiseEst[p] = (float)(CNA_ACT_DN_FACT * msNoiseEst[p] + (1 - CNA_ACT_DN_FACT) * hFdCngDec->msPeriodog_ST[p]); + msNoiseEst[p] = (float) ( CNA_ACT_DN_FACT * msNoiseEst[p] + ( 1 - CNA_ACT_DN_FACT ) * hFdCngDec->msPeriodog_ST[p] ); } } } @@ -2138,7 +2131,7 @@ void perform_noise_estimation_dec_fx ( else { - if (bwidth >= WB && hFdCngDec->ms_last_inactive_bwidth == NB) + if ( bwidth >= WB && hFdCngDec->ms_last_inactive_bwidth == NB ) { /* bandwidth increased -> set counter for fast initilization */ hFdCngDec->ms_cnt_bw_up = FIRST_CNA_NOISE_UPD_FRAMES; @@ -2146,52 +2139,52 @@ void perform_noise_estimation_dec_fx ( hFdCngDec->ms_last_inactive_bwidth = bwidth; /* update background noise during inactive frames */ ptr_per = msNoiseEst; - for (p = 0; p < npart; p++) + for ( p = 0; p < npart; p++ ) { enr = msPeriodog[p]; alpha = 0.95f; /* bandwidth increased -> do fast re-initilization */ - if (hFdCngDec->ms_cnt_bw_up > 0 && p > 55) + if ( hFdCngDec->ms_cnt_bw_up > 0 && p > 55 ) { - alpha = 1.0f / (hFdCngDec->ms_cnt_bw_up + 1); + alpha = 1.0f / ( hFdCngDec->ms_cnt_bw_up + 1 ); } - else if (enr < *ptr_per && part[p] == 1) + else if ( enr < *ptr_per && part[p] == 1 ) { /* faster downward update for single-bin partitions */ alpha = 0.8f; } - else if (enr > 2.0f * (*ptr_per)) + else if ( enr > 2.0f * ( *ptr_per ) ) { /* prevent abrupt upward updates */ - enr = 2.0f * (*ptr_per); + enr = 2.0f * ( *ptr_per ); } /* IIR smoothing */ *ptr_per *= alpha; - *ptr_per += (1 - alpha) * enr; + *ptr_per += ( 1 - alpha ) * enr; ptr_per++; } - if (hFdCngDec->ms_cnt_bw_up > 0) + if ( hFdCngDec->ms_cnt_bw_up > 0 ) { hFdCngDec->ms_cnt_bw_up--; } } } - mvr2r(msNoiseEst, hFdCngDec->msPsd, npart); + mvr2r( msNoiseEst, hFdCngDec->msPsd, npart ); /* Expand partitions into bins of power spectrum */ - scalebands(msNoiseEst, part, nFFTpart, hFdCngDec->midband_shaping, nFFTpart, stopFFTbin - startBand, hFdCngDec->bandNoiseShape, 1); + scalebands( msNoiseEst, part, nFFTpart, hFdCngDec->midband_shaping, nFFTpart, stopFFTbin - startBand, hFdCngDec->bandNoiseShape, 1 ); - mvr2r(hFdCngDec->bandNoiseShape, &hFdCngDec->smoothed_psd[startBand], stopFFTbin - startBand); - set_zero(&hFdCngDec->smoothed_psd[stopFFTbin], L_FRAME16k - stopFFTbin); + mvr2r( hFdCngDec->bandNoiseShape, &hFdCngDec->smoothed_psd[startBand], stopFFTbin - startBand ); + set_zero( &hFdCngDec->smoothed_psd[stopFFTbin], L_FRAME16k - stopFFTbin ); } else #endif { #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - if (element_mode == IVAS_CPE_MDCT && power_spectrum != NULL) + if ( element_mode == IVAS_CPE_MDCT && power_spectrum != NULL ) { /* use power spectrum calculated in the MDCT-domain instead of calculating new power spectrum */ periodog = power_spectrum; @@ -2199,9 +2192,9 @@ void perform_noise_estimation_dec_fx ( else { /* Compute the squared magnitude in each FFT bin */ - if (startBand == 0) + if ( startBand == 0 ) { - (*ptr_per) = fftBuffer[0] * fftBuffer[0]; /* DC component */ + ( *ptr_per ) = fftBuffer[0] * fftBuffer[0]; /* DC component */ ptr_per++; ptr_r = fftBuffer + 2; } @@ -2212,112 +2205,112 @@ void perform_noise_estimation_dec_fx ( ptr_i = ptr_r + 1; - for (; ptr_per < periodog + stopFFTbin - startBand; ptr_per++) + for ( ; ptr_per < periodog + stopFFTbin - startBand; ptr_per++ ) { - (*ptr_per) = (*ptr_r) * (*ptr_r) + (*ptr_i) * (*ptr_i); + ( *ptr_per ) = ( *ptr_r ) * ( *ptr_r ) + ( *ptr_i ) * ( *ptr_i ); ptr_r += 2; ptr_i += 2; } /* Nyquist frequency is discarded */ /* Rescale to get energy/sample: it should be 2*(1/N)*(2/N), parseval relation with 1/N,*2 for nrg computed till Nyquist only, 2/N as windowed samples correspond to half a frame*/ - v_multc(periodog, 4.f / (float)(hFdCngDec->hFdCngCom->fftlen * hFdCngDec->hFdCngCom->fftlen), periodog, stopFFTbin - startBand); + v_multc( periodog, 4.f / (float) ( hFdCngDec->hFdCngCom->fftlen * hFdCngDec->hFdCngCom->fftlen ), periodog, stopFFTbin - startBand ); } #else - assert(startBand != 0); + assert( startBand != 0 ); - len = sub(stopFFTbin, startBand); + len = sub( stopFFTbin, startBand ); - s = getScaleFactor32 (&fftBuffer[2*startBand], 2*len); - s = sub(s,1); + s = getScaleFactor32( &fftBuffer[2 * startBand], 2 * len ); + s = sub( s, 1 ); - ptr_per = periodog; - IF ( startBand == 0 ) - { - /* DC component */ - tmp_r = extract_h(L_shl(fftBuffer[0],s)); + ptr_per = periodog; + IF( startBand == 0 ) + { + /* DC component */ + tmp_r = extract_h( L_shl( fftBuffer[0], s ) ); - tmp = L_mult(tmp_r, tmp_r); - *ptr_per = tmp; + tmp = L_mult( tmp_r, tmp_r ); + *ptr_per = tmp; - ptr_per++; - ptr_r = fftBuffer + 2; - len = sub(len, 1); - } - ELSE - { - ptr_r = fftBuffer + shl(startBand, 1); - } + ptr_per++; + ptr_r = fftBuffer + 2; + len = sub( len, 1 ); + } + ELSE + { + ptr_r = fftBuffer + shl( startBand, 1 ); + } - ptr_i = ptr_r+1; - FOR (i=0; i < len; i++) - { - tmp_r = extract_h(L_shl(*ptr_r,s)); - tmp_i = extract_h(L_shl(*ptr_i,s)); + ptr_i = ptr_r + 1; + FOR( i = 0; i < len; i++ ) + { + tmp_r = extract_h( L_shl( *ptr_r, s ) ); + tmp_i = extract_h( L_shl( *ptr_i, s ) ); - tmp = L_mac(L_mult(tmp_r, tmp_r),tmp_i, tmp_i); - *ptr_per = tmp; + tmp = L_mac( L_mult( tmp_r, tmp_r ), tmp_i, tmp_i ); + *ptr_per = tmp; - ptr_r += 2; - ptr_i += 2; - ptr_per++; - } + ptr_r += 2; + ptr_i += 2; + ptr_per++; + } - hFdCngDec->hFdCngCom->periodog_exp = shl(sub(fftBuffer_exp, s), 1); + hFdCngDec->hFdCngCom->periodog_exp = shl( sub( fftBuffer_exp, s ), 1 ); - /* Rescale */ - assert((hFdCngDec->hFdCngCom->fftlen == 640) || (hFdCngDec->hFdCngCom->fftlen == 512) || (hFdCngDec->hFdCngCom->fftlen == 320)); + /* Rescale */ + assert( ( hFdCngDec->hFdCngCom->fftlen == 640 ) || ( hFdCngDec->hFdCngCom->fftlen == 512 ) || ( hFdCngDec->hFdCngCom->fftlen == 320 ) ); - fac = 20972/*0.64 Q15*/; - move16(); - if (EQ_16(hFdCngDec->hFdCngCom->fftlen, 512)) - { - fac = 16384/*0.5 Q15*/; + fac = 20972 /*0.64 Q15*/; move16(); - } + if ( EQ_16( hFdCngDec->hFdCngCom->fftlen, 512 ) ) + { + fac = 16384 /*0.5 Q15*/; + move16(); + } - if (EQ_16(hFdCngDec->hFdCngCom->fftlen, 640)) - { - s = 18; - move16(); - } - if (EQ_16(hFdCngDec->hFdCngCom->fftlen, 512)) - { - s = 17; - move16(); - } - if (EQ_16(hFdCngDec->hFdCngCom->fftlen, 320)) - { - s = 16; - move16(); - } + if ( EQ_16( hFdCngDec->hFdCngCom->fftlen, 640 ) ) + { + s = 18; + move16(); + } + if ( EQ_16( hFdCngDec->hFdCngCom->fftlen, 512 ) ) + { + s = 17; + move16(); + } + if ( EQ_16( hFdCngDec->hFdCngCom->fftlen, 320 ) ) + { + s = 16; + move16(); + } - len = sub(stopFFTbin, startBand); - FOR (i=0; i < len; i++) - { - hFdCngDec->hFdCngCom->periodog[i] = Mpy_32_16_1(hFdCngDec->hFdCngCom->periodog[i], fac); - } - hFdCngDec->hFdCngCom->periodog_exp = add(hFdCngDec->hFdCngCom->periodog_exp, sub(2, s)); + len = sub( stopFFTbin, startBand ); + FOR( i = 0; i < len; i++ ) + { + hFdCngDec->hFdCngCom->periodog[i] = Mpy_32_16_1( hFdCngDec->hFdCngCom->periodog[i], fac ); + } + hFdCngDec->hFdCngCom->periodog_exp = add( hFdCngDec->hFdCngCom->periodog_exp, sub( 2, s ) ); #endif - /* Adjust to the desired frequency resolution by averaging over spectral partitions for SID transmission */ - bandcombinepow(periodog, hFdCngDec->hFdCngCom->periodog_exp, sub(stopFFTbin, startBand), part, npart, psize_inv, hFdCngDec->msPeriodog, &hFdCngDec->msPeriodog_exp); + /* Adjust to the desired frequency resolution by averaging over spectral partitions for SID transmission */ + bandcombinepow( periodog, hFdCngDec->hFdCngCom->periodog_exp, sub( stopFFTbin, startBand ), part, npart, psize_inv, hFdCngDec->msPeriodog, &hFdCngDec->msPeriodog_exp ); hFdCngDec->msPeriodog_exp_fft = hFdCngDec->msPeriodog_exp; - move16(); + move16(); hFdCngDec->msPeriodog_exp_cldfb = hFdCngDec->msPeriodog_exp; - move16(); + move16(); - /* Compress MS inputs */ - compress_range(hFdCngDec->msPeriodog, hFdCngDec->msPeriodog_exp, hFdCngDec->msLogPeriodog, npart); + /* Compress MS inputs */ + compress_range( hFdCngDec->msPeriodog, hFdCngDec->msPeriodog_exp, hFdCngDec->msLogPeriodog, npart ); - /* Call the minimum statistics routine for noise estimation */ - minimum_statistics ( - npart, - nFFTpart, - psize_norm, + /* Call the minimum statistics routine for noise estimation */ + minimum_statistics( + npart, + nFFTpart, + psize_norm, hFdCngDec->msLogPeriodog, hFdCngDec->msNoiseFloor, hFdCngDec->msLogNoiseEst, @@ -2334,16 +2327,17 @@ void perform_noise_estimation_dec_fx ( hFdCngDec->msLocalMinFlag, hFdCngDec->msNewMinFlag, hFdCngDec->msPeriodogBuf, - &(hFdCngDec->msPeriodogBufPtr), + &( hFdCngDec->msPeriodogBufPtr ), hFdCngDec->hFdCngCom #ifdef IVAS_CODE_CNG - , DEC, element_mode + , + DEC, element_mode #endif - ); + ); - /* Expand MS outputs */ - expand_range(hFdCngDec->msLogNoiseEst, hFdCngDec->msNoiseEst, &hFdCngDec->msNoiseEst_exp, npart); -} + /* Expand MS outputs */ + expand_range( hFdCngDec->msLogNoiseEst, hFdCngDec->msNoiseEst, &hFdCngDec->msNoiseEst_exp, npart ); + } } #ifdef IVAS_FLOAT_FIXED @@ -2716,37 +2710,40 @@ void perform_noise_estimation_dec_ivas_fx( IF( LE_16( scale, 0 ) ) { enr_ratio = shl( enr_ratio, scale ); - scale = 15; move16(); + scale = 15; + move16(); } ELSE { - scale = sub(15, scale); + scale = sub( 15, scale ); } - IF( LT_16( enr_ratio, shl(1, sub(scale, 1)) ) ) + IF( LT_16( enr_ratio, shl( 1, sub( scale, 1 ) ) ) ) { /* total energy significantly decreases during active frames -> downward update */ - wght = lin_interp_fx( enr_ratio, 0, shr(26214, sub(15, scale)) /*0.8f in Q15*/, shr(16384, sub(15, scale)) /*0.5f in Q15*/, shr(31130, sub(15, scale)) /*0.95f in Q15*/, shr(32767, sub(15, scale)) /*1 in Q15*/ ); + wght = lin_interp_fx( enr_ratio, 0, shr( 26214, sub( 15, scale ) ) /*0.8f in Q15*/, shr( 16384, sub( 15, scale ) ) /*0.5f in Q15*/, shr( 31130, sub( 15, scale ) ) /*0.95f in Q15*/, shr( 32767, sub( 15, scale ) ) /*1 in Q15*/ ); Word16 temp_q_msNoiseEst[NPART_SHAPING]; Word16 min_q_msNoiseEst = MAX_16; - FOR(p = 0; p < NPART_SHAPING; p++) + FOR( p = 0; p < NPART_SHAPING; p++ ) { - temp_q_msNoiseEst[p] = hFdCngDec->msNoiseEst_exp; move16(); + temp_q_msNoiseEst[p] = hFdCngDec->msNoiseEst_exp; + move16(); } FOR( p = 0; p < npart; p++ ) { L_tmp = L_shr( msPeriodog[p], sub( sub( 31, hFdCngDec->hFdCngCom->periodog_exp ), 4 ) ); IF( LT_32( L_tmp, msNoiseEst[p] ) ) { - msNoiseEst[p] = L_add( Mpy_32_16_1( msNoiseEst[p], wght ), Mpy_32_16_1( L_tmp, (Word16) L_sub( shr(MAX_16, sub(15, scale)), wght ) ) ); - temp_q_msNoiseEst[p] = sub(add(hFdCngDec->msNoiseEst_exp, scale), 15); + msNoiseEst[p] = L_add( Mpy_32_16_1( msNoiseEst[p], wght ), Mpy_32_16_1( L_tmp, (Word16) L_sub( shr( MAX_16, sub( 15, scale ) ), wght ) ) ); + temp_q_msNoiseEst[p] = sub( add( hFdCngDec->msNoiseEst_exp, scale ), 15 ); } - min_q_msNoiseEst = s_min(temp_q_msNoiseEst[p], min_q_msNoiseEst); + min_q_msNoiseEst = s_min( temp_q_msNoiseEst[p], min_q_msNoiseEst ); } - FOR(p = 0; p < NPART_SHAPING; p++) + FOR( p = 0; p < NPART_SHAPING; p++ ) { - msNoiseEst[p] = L_shl(msNoiseEst[p], sub(min_q_msNoiseEst, temp_q_msNoiseEst[p])); + msNoiseEst[p] = L_shl( msNoiseEst[p], sub( min_q_msNoiseEst, temp_q_msNoiseEst[p] ) ); } - hFdCngDec->msNoiseEst_exp = min_q_msNoiseEst; move16(); + hFdCngDec->msNoiseEst_exp = min_q_msNoiseEst; + move16(); } ELSE { @@ -2815,10 +2812,10 @@ void perform_noise_estimation_dec_ivas_fx( hFdCngDec->msPsd_exp_fft = hFdCngDec->msNoiseEst_exp; /* Expand partitions into bins of power spectrum */ - scalebands_fx( msNoiseEst, part, nFFTpart, hFdCngDec->midband_shaping, nFFTpart, sub( stopFFTbin, startBand ), hFdCngDec->bandNoiseShape, 1 ); + scalebands_fx( msNoiseEst, part, nFFTpart, hFdCngDec->midband_shaping, nFFTpart, sub( stopFFTbin, startBand ), hFdCngDec->bandNoiseShape, 1 ); hFdCngDec->bandNoiseShape_exp = hFdCngDec->msNoiseEst_exp; Copy32( hFdCngDec->bandNoiseShape, &hFdCngDec->smoothed_psd_fx[startBand], sub( stopFFTbin, startBand ) ); - hFdCngDec->q_smoothed_psd = sub(Q31, hFdCngDec->bandNoiseShape_exp); + hFdCngDec->q_smoothed_psd = sub( Q31, hFdCngDec->bandNoiseShape_exp ); set32_fx( &hFdCngDec->smoothed_psd_fx[stopFFTbin], 0, sub( L_FRAME16k, stopFFTbin ) ); } ELSE @@ -2970,7 +2967,6 @@ void perform_noise_estimation_dec_ivas_fx( #endif // IVAS_FLOAT_FIXED - /* FdCng_decodeSID_fx @@ -2988,9 +2984,9 @@ void perform_noise_estimation_dec_ivas_fx( void */ #ifdef IVAS_FLOAT_FIXED -void FdCng_decodeSID_fx (HANDLE_FD_CNG_COM st, Decoder_State *corest) +void FdCng_decodeSID_fx( HANDLE_FD_CNG_COM st, Decoder_State *corest ) { - Word16 i, N, index; + Word16 i, N, index; Word32 *sidNoiseEst; Word16 indices[32], v16[32]; @@ -3003,7 +2999,7 @@ void FdCng_decodeSID_fx (HANDLE_FD_CNG_COM st, Decoder_State *corest) #ifdef IVAS_FLOAT_FIXED Word32 *invTrfMatrix_fx; Word32 tmpRAM_fx[FDCNG_VQ_MAX_LEN][FDCNG_VQ_DCT_MAXTRUNC]; - invTrfMatrix_fx = (Word32 *)tmpRAM_fx; + invTrfMatrix_fx = (Word32 *) tmpRAM_fx; #endif @@ -3015,22 +3011,23 @@ void FdCng_decodeSID_fx (HANDLE_FD_CNG_COM st, Decoder_State *corest) N = st->npart; move16(); - st->sid_frame_counter = add(st->sid_frame_counter,1); + st->sid_frame_counter = add( st->sid_frame_counter, 1 ); move16(); /* Read bitstream */ - FOR (i=0; ielement_mode != EVS_MONO) { - create_IDCT_N_Matrix_fx(invTrfMatrix_fx, FDCNG_VQ_MAX_LEN, FDCNG_VQ_DCT_MAXTRUNC, sizeof(tmpRAM_fx) / (sizeof(Word32))); - msvq_dec_fx(ivas_cdk_37bits_fx, NULL, NULL, stages_37bits, N, maxN_37bits, indices, 1, invTrfMatrix_fx, v, NULL, 7); + if ( corest->element_mode != EVS_MONO ) + { + create_IDCT_N_Matrix_fx( invTrfMatrix_fx, FDCNG_VQ_MAX_LEN, FDCNG_VQ_DCT_MAXTRUNC, sizeof( tmpRAM_fx ) / ( sizeof( Word32 ) ) ); + msvq_dec_fx( ivas_cdk_37bits_fx, NULL, NULL, stages_37bits, N, maxN_37bits, indices, 1, invTrfMatrix_fx, v, NULL, 7 ); } else #endif @@ -3041,77 +3038,74 @@ void FdCng_decodeSID_fx (HANDLE_FD_CNG_COM st, Decoder_State *corest) N, maxN_37bits, indices, - v16 - ); + v16 ); - FOR(i = 0; i < N; i++) + FOR( i = 0; i < N; i++ ) { - v[i] = L_deposit_h(v16[i]); + v[i] = L_deposit_h( v16[i] ); } } /* decode gain, format gain: Q9.23 */ - gain = L_shl(L_deposit_l(index),WORD32_BITS-1-8); - gain = L_sub(gain,503316480l/*60.0 Q23*/); - gain = Mpy_32_16_1(gain,21845/*2.0f/3.0f Q15*/); + gain = L_shl( L_deposit_l( index ), WORD32_BITS - 1 - 8 ); + gain = L_sub( gain, 503316480l /*60.0 Q23*/ ); + gain = Mpy_32_16_1( gain, 21845 /*2.0f/3.0f Q15*/ ); /* Apply gain and undo log */ /* calculate worst case for scaling */ - maxVal = L_add(0x80000000/*-1.0 Q31*/, 0); - FOR (i=0; i= 0; maxVal -= 33554432l/*0.015625 Q31*/) + FOR( ; maxVal >= 0; maxVal -= 33554432l /*0.015625 Q31*/ ) { - sidNoiseEst_Exp = add(sidNoiseEst_Exp,1); + sidNoiseEst_Exp = add( sidNoiseEst_Exp, 1 ); } st->sidNoiseEstExp = sidNoiseEst_Exp; move16(); - E_ExpLd64 = L_shl(sidNoiseEst_Exp, WORD32_BITS-1-LD_DATA_SCALE); + E_ExpLd64 = L_shl( sidNoiseEst_Exp, WORD32_BITS - 1 - LD_DATA_SCALE ); /* format v: Q9.23, format sidNoiseEst: Q6.26, 0.66438561897 = log10(10)/log10(2.0) / 10.0 * 2.0 */ - FOR (i=0; isidNoiseEst[i] = BASOP_Util_InvLog2(tmp); + tmp = L_add( v[i], gain ); + tmp = L_shl( Mpy_32_16_1( tmp, 21771 /*0.66438561897 Q15*/ ), 1 ); + tmp = L_sub( tmp, E_ExpLd64 ); + assert( tmp < 0 ); + st->sidNoiseEst[i] = BASOP_Util_InvLog2( tmp ); move32(); } /* NB last band energy compensation */ - IF ( st->CngBandwidth == NB ) + IF( st->CngBandwidth == NB ) { - st->sidNoiseEst[N-1] = Mpy_32_16_1(st->sidNoiseEst[N-1], NB_LAST_BAND_SCALE); + st->sidNoiseEst[N - 1] = Mpy_32_16_1( st->sidNoiseEst[N - 1], NB_LAST_BAND_SCALE ); move32(); } test(); if ( st->CngBandwidth == SWB && st->CngBitrate <= ACELP_13k20 ) { - st->sidNoiseEst[N-1] = Mpy_32_16_1(st->sidNoiseEst[N-1], SWB_13k2_LAST_BAND_SCALE); + st->sidNoiseEst[N - 1] = Mpy_32_16_1( st->sidNoiseEst[N - 1], SWB_13k2_LAST_BAND_SCALE ); } - scalebands (sidNoiseEst, st->part, st->npart, st->midband, st->nFFTpart, st->stopBand-st->startBand, st->cngNoiseLevel, 1); + scalebands( sidNoiseEst, st->part, st->npart, st->midband, st->nFFTpart, st->stopBand - st->startBand, st->cngNoiseLevel, 1 ); st->cngNoiseLevelExp = st->sidNoiseEstExp; move16(); - lpc_from_spectrum (st, st->startBand, st->stopFFTbin, preemph_fac); - - + lpc_from_spectrum( st, st->startBand, st->stopFFTbin, preemph_fac ); } #endif @@ -3136,12 +3130,11 @@ void FdCng_decodeSID_fx (HANDLE_FD_CNG_COM st, Decoder_State *corest) void */ #ifdef IVAS_FLOAT_FIXED -void noisy_speech_detection_fx ( - HANDLE_FD_CNG_DEC hFdCngDec,/* i/o: FD_CNG structure */ +void noisy_speech_detection_fx( + HANDLE_FD_CNG_DEC hFdCngDec, /* i/o: FD_CNG structure */ const Word16 vad, - const Word16 * syn, /* i : input time-domain frame */ - const Word16 Q -) + const Word16 *syn, /* i : input time-domain frame */ + const Word16 Q ) { Word16 i; Word32 tmp; @@ -3155,9 +3148,9 @@ void noisy_speech_detection_fx ( Word32 logTotalNoiseExp; - IF ( vad == 0 ) + IF( vad == 0 ) { - totalNoise = dotWord32_16_Mant32Exp(hFdCngDec->msNoiseEst, hFdCngDec->msNoiseEst_exp, hFdCngDec->psize_shaping_norm, hFdCngDec->psize_shaping_norm_exp, hFdCngDec->nFFTpart_shaping, &totalNoise_exp); + totalNoise = dotWord32_16_Mant32Exp( hFdCngDec->msNoiseEst, hFdCngDec->msNoiseEst_exp, hFdCngDec->psize_shaping_norm, hFdCngDec->psize_shaping_norm_exp, hFdCngDec->nFFTpart_shaping, &totalNoise_exp ); /* - logTotalNoise is scaled by LD_DATA_SCALE+2 @@ -3165,18 +3158,18 @@ void noisy_speech_detection_fx ( - constant: -0.78125 = 10.0*log10(DELTA)/(1<<(LD_DATA_SCALE+2)) - constant: 0.75257498916 = 10.0 * log10(2.0)/log10(10.0)/(1<<2) */ - IF ( totalNoise == 0 ) + IF( totalNoise == 0 ) { - logTotalNoise = L_add(-1677721600l/*-0.78125 Q31*/, 0); + logTotalNoise = L_add( -1677721600l /*-0.78125 Q31*/, 0 ); } ELSE { - logTotalNoise = BASOP_Util_Log2(totalNoise); - logTotalNoiseExp = L_shl(L_deposit_l(totalNoise_exp),WORD32_BITS-1-LD_DATA_SCALE); - logTotalNoise = Mpy_32_16_1(L_add(logTotalNoise,logTotalNoiseExp),24660/*0.75257498916 Q15*/); + logTotalNoise = BASOP_Util_Log2( totalNoise ); + logTotalNoiseExp = L_shl( L_deposit_l( totalNoise_exp ), WORD32_BITS - 1 - LD_DATA_SCALE ); + logTotalNoise = Mpy_32_16_1( L_add( logTotalNoise, logTotalNoiseExp ), 24660 /*0.75257498916 Q15*/ ); } - hFdCngDec->lp_noise = L_add(Mpy_32_16_1(hFdCngDec->lp_noise,32604/*0.995 Q15*/),L_shr(Mpy_32_16_1(logTotalNoise,20972/*0.64 Q15*/),7)); + hFdCngDec->lp_noise = L_add( Mpy_32_16_1( hFdCngDec->lp_noise, 32604 /*0.995 Q15*/ ), L_shr( Mpy_32_16_1( logTotalNoise, 20972 /*0.64 Q15*/ ), 7 ) ); move32(); } ELSE @@ -3185,7 +3178,7 @@ void noisy_speech_detection_fx ( Etot_exp = 31; FOR( i = 0; i < hFdCngDec->hFdCngCom->frameSize; i++ ) { - tmp = L_shr_r( L_mult0(syn[i], syn[i] ), sub( Etot_exp, 31 ) ); + tmp = L_shr_r( L_mult0( syn[i], syn[i] ), sub( Etot_exp, 31 ) ); IF( L_sub( maxWord32, tmp ) < Etot ) { Etot_exp = add( Etot_exp, 1 ); @@ -3202,32 +3195,32 @@ void noisy_speech_detection_fx ( - constant: -0.78125 = 10.0*log10(DELTA)/(1<<(LD_DATA_SCALE+2)) - constant: 0.75257498916 = 10.0 * log10(2.0)/log10(10.0)/(1<<2) */ - IF ( Etot == 0 ) + IF( Etot == 0 ) { - logEtot = L_add(-1677721600l/*-0.78125 Q31*/, 0); + logEtot = L_add( -1677721600l /*-0.78125 Q31*/, 0 ); } ELSE { - logEtot = BASOP_Util_Log2(Etot); - logEtotExp = L_shl(L_deposit_l(Etot_exp),WORD32_BITS-1-LD_DATA_SCALE); - logEtot = Mpy_32_16_1(L_add(logEtot,logEtotExp),24660/*0.75257498916 Q15*/); - IF ( EQ_16( hFdCngDec->hFdCngCom->frameSize, L_FRAME16k )) + logEtot = BASOP_Util_Log2( Etot ); + logEtotExp = L_shl( L_deposit_l( Etot_exp ), WORD32_BITS - 1 - LD_DATA_SCALE ); + logEtot = Mpy_32_16_1( L_add( logEtot, logEtotExp ), 24660 /*0.75257498916 Q15*/ ); + IF( EQ_16( hFdCngDec->hFdCngCom->frameSize, L_FRAME16k ) ) { - logEtot = L_add( logEtot, -184894985l/*-0.086098436822497 Q31*/ ); + logEtot = L_add( logEtot, -184894985l /*-0.086098436822497 Q31*/ ); } ELSE { - logEtot = L_add( logEtot, -176765584l/*-0.082312889439370 Q31*/ ); + logEtot = L_add( logEtot, -176765584l /*-0.082312889439370 Q31*/ ); } } - hFdCngDec->lp_speech = L_add(Mpy_32_16_1(hFdCngDec->lp_speech,32604/*0.995 Q15*/),L_shr(Mpy_32_16_1(logEtot,20972/*0.64 Q15*/),7)); + hFdCngDec->lp_speech = L_add( Mpy_32_16_1( hFdCngDec->lp_speech, 32604 /*0.995 Q15*/ ), L_shr( Mpy_32_16_1( logEtot, 20972 /*0.64 Q15*/ ), 7 ) ); move32(); } - tmp = L_sub(hFdCngDec->lp_speech,377487360l/*45.0 Q23*/); + tmp = L_sub( hFdCngDec->lp_speech, 377487360l /*45.0 Q23*/ ); - if ( LT_32(hFdCngDec->lp_noise,tmp)) + if ( LT_32( hFdCngDec->lp_noise, tmp ) ) { hFdCngDec->lp_noise = tmp; move32(); @@ -3235,7 +3228,7 @@ void noisy_speech_detection_fx ( hFdCngDec->hFdCngCom->flag_noisy_speech = 0; move16(); - if ( LT_32(L_sub(hFdCngDec->lp_speech, hFdCngDec->lp_noise),234881024l/*28.0 Q23*/)) + if ( LT_32( L_sub( hFdCngDec->lp_speech, hFdCngDec->lp_noise ), 234881024l /*28.0 Q23*/ ) ) { hFdCngDec->hFdCngCom->flag_noisy_speech = 1; move16(); @@ -3247,33 +3240,32 @@ void noisy_speech_detection_fx ( #endif #ifdef IVAS_FLOAT_FIXED -void -generate_comfort_noise_dec_fx ( - Word32 **bufferReal, /* o : matrix to real part of input bands */ - Word32 **bufferImag, /* o : matrix to imaginary part of input bands */ - Word16 *bufferScale, /* o : pointer to scalefactor for real and imaginary part of input bands */ +void generate_comfort_noise_dec_fx( + Word32 **bufferReal, /* o : matrix to real part of input bands */ + Word32 **bufferImag, /* o : matrix to imaginary part of input bands */ + Word16 *bufferScale, /* o : pointer to scalefactor for real and imaginary part of input bands */ Decoder_State *st, Word16 *Q_new, Word16 gen_exc, - const Word16 nchan_out /* i : number of output channels */ + const Word16 nchan_out /* i : number of output channels */ ) { - Word16 i, j, s, sc, sn, cnt; - Word16 startBand2; - Word16 stopFFTbin2; - Word16 scaleCLDFB; - Word16 preemph_fac; - Word32 sqrtNoiseLevel; - Word16 randGaussExp; - Word16 fftBufferExp; - Word16 cngNoiseLevelExp; + Word16 i, j, s, sc, sn, cnt; + Word16 startBand2; + Word16 stopFFTbin2; + Word16 scaleCLDFB; + Word16 preemph_fac; + Word32 sqrtNoiseLevel; + Word16 randGaussExp; + Word16 fftBufferExp; + Word16 cngNoiseLevelExp; Word16 *seed; Word16 *timeDomainOutput; Word32 *ptr_r, *ptr_i; Word32 *cngNoiseLevel; Word32 *ptr_level; Word32 *fftBuffer; - Word16 old_syn_pe_tmp[16]; + Word16 old_syn_pe_tmp[16]; Word16 tcx_transition = 0; HANDLE_FD_CNG_DEC hFdCngDec = st->hFdCngDec; HANDLE_FD_CNG_COM hFdCngCom = hFdCngDec->hFdCngCom; @@ -3283,19 +3275,19 @@ generate_comfort_noise_dec_fx ( /* Warning fix */ s = 0; -//PMTE(); /*IVAS CODE need to be added */ + // PMTE(); /*IVAS CODE need to be added */ /* pointer initialization */ cngNoiseLevel = hFdCngCom->cngNoiseLevel; cngNoiseLevelExp = hFdCngCom->cngNoiseLevelExp; ptr_level = cngNoiseLevel; - seed = &(hFdCngCom->seed); + seed = &( hFdCngCom->seed ); fftBuffer = hFdCngCom->fftBuffer; timeDomainOutput = hFdCngCom->timeDomainBuffer; /* scaleCLDFB: CLDFBinvScalingFactor_EXP + 1 */ - scaleCLDFB = mult(hFdCngCom->invScalingFactor,CLDFB_SCALING); + scaleCLDFB = mult( hFdCngCom->invScalingFactor, CLDFB_SCALING ); /* Generate Gaussian random noise in real and imaginary parts of the FFT bins @@ -3304,54 +3296,54 @@ generate_comfort_noise_dec_fx ( */ sn = 0; move16(); - IF ( s_and(cngNoiseLevelExp,1) != 0 ) + IF( s_and( cngNoiseLevelExp, 1 ) != 0 ) { - sn = add(sn,1); - cngNoiseLevelExp = add(cngNoiseLevelExp,sn); + sn = add( sn, 1 ); + cngNoiseLevelExp = add( cngNoiseLevelExp, sn ); move16(); } randGaussExp = CNG_RAND_GAUSS_SHIFT; move16(); - cnt = sub(hFdCngCom->stopFFTbin, hFdCngCom->startBand); - IF ( hFdCngCom->startBand == 0 ) + cnt = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); + IF( hFdCngCom->startBand == 0 ) { /* DC component in FFT */ s = 0; move16(); - sqrtNoiseLevel = Sqrt32(L_shr(*ptr_level,sn), &s); + sqrtNoiseLevel = Sqrt32( L_shr( *ptr_level, sn ), &s ); - fftBuffer[0] = L_shl(Mpy_32_32(rand_gauss(seed),sqrtNoiseLevel),s); + fftBuffer[0] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), s ); move32(); /* Nyquist frequency is discarded */ - fftBuffer[1] = L_deposit_l(0); + fftBuffer[1] = L_deposit_l( 0 ); ptr_level = ptr_level + 1; ptr_r = fftBuffer + 2; - cnt = sub(cnt, 1); + cnt = sub( cnt, 1 ); } ELSE { - startBand2 = shl(hFdCngCom->startBand,1); - set32_fx(fftBuffer, 0, startBand2); + startBand2 = shl( hFdCngCom->startBand, 1 ); + set32_fx( fftBuffer, 0, startBand2 ); ptr_r = fftBuffer + startBand2; } - sn = add(sn,1); + sn = add( sn, 1 ); ptr_i = ptr_r + 1; - FOR (i=0; i < cnt; i++) + FOR( i = 0; i < cnt; i++ ) { s = 0; move16(); - sqrtNoiseLevel = Sqrt32(L_shr(*ptr_level,sn), &s); + sqrtNoiseLevel = Sqrt32( L_shr( *ptr_level, sn ), &s ); /* Real part in FFT bins */ - *ptr_r = L_shl(Mpy_32_32(rand_gauss(seed),sqrtNoiseLevel),s); + *ptr_r = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), s ); move32(); /* Imaginary part in FFT bins */ - *ptr_i = L_shl(Mpy_32_32(rand_gauss(seed),sqrtNoiseLevel),s); + *ptr_i = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), s ); move32(); ptr_r = ptr_r + 2; @@ -3360,15 +3352,15 @@ generate_comfort_noise_dec_fx ( } /* Remaining FFT bins are set to zero */ - stopFFTbin2 = shl(hFdCngCom->stopFFTbin,1); - set32_fx(fftBuffer+stopFFTbin2, 0, sub(hFdCngCom->fftlen,stopFFTbin2)); + stopFFTbin2 = shl( hFdCngCom->stopFFTbin, 1 ); + set32_fx( fftBuffer + stopFFTbin2, 0, sub( hFdCngCom->fftlen, stopFFTbin2 ) ); - fftBufferExp = add(shr(cngNoiseLevelExp,1),randGaussExp); + fftBufferExp = add( shr( cngNoiseLevelExp, 1 ), randGaussExp ); /* If previous frame is active, reset the overlap-add buffer */ - IF ( hFdCngCom->frame_type_previous == ACTIVE_FRAME ) + IF( hFdCngCom->frame_type_previous == ACTIVE_FRAME ) { - set16_fx(hFdCngCom->olapBufferSynth, 0, hFdCngCom->fftlen); + set16_fx( hFdCngCom->olapBufferSynth, 0, hFdCngCom->fftlen ); test(); test(); if ( ( st->last_core_bfi > ACELP_CORE && st->codec_mode == MODE2 ) || st->codec_mode == MODE1 ) @@ -3379,8 +3371,8 @@ generate_comfort_noise_dec_fx ( } /* Perform STFT synthesis */ - SynthesisSTFT (fftBuffer, fftBufferExp, timeDomainOutput, hFdCngCom->olapBufferSynth, hFdCngCom->olapWinSyn, - tcx_transition, hFdCngCom, gen_exc, Q_new, st->element_mode, nchan_out); + SynthesisSTFT( fftBuffer, fftBufferExp, timeDomainOutput, hFdCngCom->olapBufferSynth, hFdCngCom->olapWinSyn, + tcx_transition, hFdCngCom, gen_exc, Q_new, st->element_mode, nchan_out ); { Word32 Lener, att; @@ -3389,46 +3381,46 @@ generate_comfort_noise_dec_fx ( /* calculate the residual signal energy */ /*enr = dotp( hFdCngCom->exc_cng, hFdCngCom->exc_cng, hFdCngCom->frameSize ) / hFdCngCom->frameSize;*/ - Lener = Dot_productSq16HQ(1,hFdCngCom->exc_cng,st->L_frame,&exp); - exp = add(sub(shl(sub(15,*Q_new),1),8),exp); /*8 = log2(256)*/ + Lener = Dot_productSq16HQ( 1, hFdCngCom->exc_cng, st->L_frame, &exp ); + exp = add( sub( shl( sub( 15, *Q_new ), 1 ), 8 ), exp ); /*8 = log2(256)*/ /* convert log2 of residual signal energy */ /*(float)log10( enr + 0.1f ) / (float)log10( 2.0f );*/ - Lener = BASOP_Util_Log2(Lener); - Lener = L_add(Lener,L_shl(L_deposit_l(exp),WORD32_BITS-1-LD_DATA_SCALE)); /*Q25*/ - if(st->L_frame == L_FRAME16k) + Lener = BASOP_Util_Log2( Lener ); + Lener = L_add( Lener, L_shl( L_deposit_l( exp ), WORD32_BITS - 1 - LD_DATA_SCALE ) ); /*Q25*/ + if ( st->L_frame == L_FRAME16k ) { - Lener = L_sub(Lener, 10802114l/*0.3219280949f Q25*/); /*log2(320) = 8.3219280949f*/ + Lener = L_sub( Lener, 10802114l /*0.3219280949f Q25*/ ); /*log2(320) = 8.3219280949f*/ } /* decrease the energy in case of WB input */ - IF( NE_16(st->bwidth, NB)) + IF( NE_16( st->bwidth, NB ) ) { - IF( EQ_16(st->bwidth,WB)) + IF( EQ_16( st->bwidth, WB ) ) { IF( st->CNG_mode >= 0 ) { /* Bitrate adapted attenuation */ - att = L_shl(L_deposit_l(ENR_ATT_fx[st->CNG_mode]),17); + att = L_shl( L_deposit_l( ENR_ATT_fx[st->CNG_mode] ), 17 ); } ELSE { /* Use least attenuation for higher bitrates */ - att = L_shl(L_deposit_l(ENR_ATT_fx[4]),17); + att = L_shl( L_deposit_l( ENR_ATT_fx[4] ), 17 ); } } ELSE { - att = 384<<17; - move16();/*1.5 Q8<<17=Q25*/ + att = 384 << 17; + move16(); /*1.5 Q8<<17=Q25*/ } - Lener = L_sub(Lener, att ); + Lener = L_sub( Lener, att ); } /*st->lp_ener = 0.8f * stcod->lp_ener + 0.2f * pow( 2.0f, enr );*/ - Lener = BASOP_util_Pow2(Lener, 6, &exp); - Lener = Mult_32_16(Lener, 6554/*0.2f Q15*/); - exp = sub(25,exp); - Lener = L_shr(Lener, exp); /*Q6*/ - st->lp_ener_fx = L_add(Mult_32_16(st->lp_ener_fx, 26214/*0.8f Q15*/), Lener); /*Q6*/ + Lener = BASOP_util_Pow2( Lener, 6, &exp ); + Lener = Mult_32_16( Lener, 6554 /*0.2f Q15*/ ); + exp = sub( 25, exp ); + Lener = L_shr( Lener, exp ); /*Q6*/ + st->lp_ener_fx = L_add( Mult_32_16( st->lp_ener_fx, 26214 /*0.8f Q15*/ ), Lener ); /*Q6*/ } /* @@ -3436,42 +3428,42 @@ generate_comfort_noise_dec_fx ( Amplitudes are adjusted to the estimated noise level cngNoiseLevel in each band */ test(); - IF ( bufferReal!=NULL && (LT_16(hFdCngCom->numCoreBands,hFdCngCom->regularStopBand))) + IF( bufferReal != NULL && ( LT_16( hFdCngCom->numCoreBands, hFdCngCom->regularStopBand ) ) ) { - sn = sub(sn,1); - sc = add(shr(add(cngNoiseLevelExp,CLDFBinvScalingFactor_EXP+1-1),1),randGaussExp); + sn = sub( sn, 1 ); + sc = add( shr( add( cngNoiseLevelExp, CLDFBinvScalingFactor_EXP + 1 - 1 ), 1 ), randGaussExp ); move16(); - assert( ((cngNoiseLevelExp+CLDFBinvScalingFactor_EXP+1-1)&1) == 0); + assert( ( ( cngNoiseLevelExp + CLDFBinvScalingFactor_EXP + 1 - 1 ) & 1 ) == 0 ); - FOR (j=hFdCngCom->numCoreBands; jregularStopBand; j++) + FOR( j = hFdCngCom->numCoreBands; j < hFdCngCom->regularStopBand; j++ ) { /* scaleCLDFB: CLDFBinvScalingFactor_EXP + 1 */ s = 0; move16(); - sqrtNoiseLevel = Sqrt32(L_shr(Mpy_32_16_1(*ptr_level,scaleCLDFB),sn), &s); + sqrtNoiseLevel = Sqrt32( L_shr( Mpy_32_16_1( *ptr_level, scaleCLDFB ), sn ), &s ); - FOR (i=0; inumSlots; i++) + FOR( i = 0; i < hFdCngCom->numSlots; i++ ) { /* Real part in CLDFB band */ - bufferReal[i][j] = L_shl(Mpy_32_32(rand_gauss(seed),sqrtNoiseLevel),s); + bufferReal[i][j] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), s ); move32(); /*fprintf(pFile,"%13.10f\n",WORD322FL_SCALE(bufferReal[i][j],sc));*/ /* Imaginary part in CLDFB band */ - bufferImag[i][j] = L_shl(Mpy_32_32(rand_gauss(seed),sqrtNoiseLevel),s); + bufferImag[i][j] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), s ); move32(); /*fprintf(pFile,"%13.10f\n",WORD322FL_SCALE(bufferImag[i][j],sc));*/ } ptr_level = ptr_level + 1; } - *bufferScale = sub(sc,15); + *bufferScale = sub( sc, 15 ); move16(); } /* Overlap-add when previous frame is active */ test(); - IF ( hFdCngCom->frame_type_previous == ACTIVE_FRAME && st->codec_mode == MODE2 ) + IF( hFdCngCom->frame_type_previous == ACTIVE_FRAME && st->codec_mode == MODE2 ) { Word32 old_exc_ener, gain, noise32; Word16 seed_loc, lpcorder, old_syn, tmp, gain16, N, N2, N4, N8; @@ -3483,42 +3475,42 @@ generate_comfort_noise_dec_fx ( Word16 Q_exc, Q_syn; - assert(hFdCngCom->frameSize <= 640); + assert( hFdCngCom->frameSize <= 640 ); seed_loc = hFdCngCom->seed; move16(); N = hFdCngCom->frameSize; move16(); - N2 = shr(hFdCngCom->frameSize,1); + N2 = shr( hFdCngCom->frameSize, 1 ); - IF ( st->last_core_bfi > ACELP_CORE ) + IF( st->last_core_bfi > ACELP_CORE ) { Word16 left_overlap_mode; left_overlap_mode = st->hTcxCfg->tcx_last_overlap_mode; move16(); - if (EQ_16(left_overlap_mode, ALDO_WINDOW)) + if ( EQ_16( left_overlap_mode, ALDO_WINDOW ) ) { left_overlap_mode = FULL_OVERLAP; move16(); } - tcx_windowing_synthesis_current_frame( timeDomainOutput,st->hTcxCfg->tcx_mdct_window, st->hTcxCfg->tcx_mdct_window_half,st->hTcxCfg->tcx_mdct_window_minimum,st->hTcxCfg->tcx_mdct_window_length,st->hTcxCfg->tcx_mdct_window_half_length, - st->hTcxCfg->tcx_mdct_window_min_length,0,left_overlap_mode,NULL,NULL,NULL,NULL,NULL,N/2,shr(sub(abs_s(st->hTcxCfg->tcx_offset), st->hTcxCfg->tcx_offset), 1), 1,0,0); + tcx_windowing_synthesis_current_frame( timeDomainOutput, st->hTcxCfg->tcx_mdct_window, st->hTcxCfg->tcx_mdct_window_half, st->hTcxCfg->tcx_mdct_window_minimum, st->hTcxCfg->tcx_mdct_window_length, st->hTcxCfg->tcx_mdct_window_half_length, + st->hTcxCfg->tcx_mdct_window_min_length, 0, left_overlap_mode, NULL, NULL, NULL, NULL, NULL, N / 2, shr( sub( abs_s( st->hTcxCfg->tcx_offset ), st->hTcxCfg->tcx_offset ), 1 ), 1, 0, 0 ); - IF (st->hTcxCfg->last_aldo != 0) + IF( st->hTcxCfg->last_aldo != 0 ) { - FOR (i=0; iframeSize,NS2SA(st->sr_core, N_ZERO_MDCT_NS)); i++) + FOR( i = 0; i < sub( hFdCngCom->frameSize, NS2SA( st->sr_core, N_ZERO_MDCT_NS ) ); i++ ) { - timeDomainOutput[i] = add(timeDomainOutput[i], shr_r(st->hHQ_core->old_out_LB_fx[i+NS2SA(st->sr_core, N_ZERO_MDCT_NS)],st->hHQ_core->Q_old_wtda_LB)); + timeDomainOutput[i] = add( timeDomainOutput[i], shr_r( st->hHQ_core->old_out_LB_fx[i + NS2SA( st->sr_core, N_ZERO_MDCT_NS )], st->hHQ_core->Q_old_wtda_LB ) ); } } ELSE { - tcx_windowing_synthesis_past_frame(hTcxDec->syn_Overl,st->hTcxCfg->tcx_mdct_window, st->hTcxCfg->tcx_mdct_window_half, st->hTcxCfg->tcx_mdct_window_minimum, - st->hTcxCfg->tcx_mdct_window_length, st->hTcxCfg->tcx_mdct_window_half_length, st->hTcxCfg->tcx_mdct_window_min_length, st->hTcxCfg->tcx_last_overlap_mode); + tcx_windowing_synthesis_past_frame( hTcxDec->syn_Overl, st->hTcxCfg->tcx_mdct_window, st->hTcxCfg->tcx_mdct_window_half, st->hTcxCfg->tcx_mdct_window_minimum, + st->hTcxCfg->tcx_mdct_window_length, st->hTcxCfg->tcx_mdct_window_half_length, st->hTcxCfg->tcx_mdct_window_min_length, st->hTcxCfg->tcx_last_overlap_mode ); - FOR (i=0; ihTcxCfg->tcx_mdct_window_length; i++) + FOR( i = 0; i < st->hTcxCfg->tcx_mdct_window_length; i++ ) { - timeDomainOutput[i] += shl(hTcxDec->syn_Overl[i],TCX_IMDCT_HEADROOM); + timeDomainOutput[i] += shl( hTcxDec->syn_Overl[i], TCX_IMDCT_HEADROOM ); } } } @@ -3540,7 +3532,7 @@ generate_comfort_noise_dec_fx ( lpcorder = M; move16(); old_Aq = st->old_Aq_12_8_fx; - old_exc = st->old_exc_fx+sub(L_EXC_MEM_DEC,N2); + old_exc = st->old_exc_fx + sub( L_EXC_MEM_DEC, N2 ); old_syn_pe = st->mem_syn2_fx; old_syn = st->syn[lpcorder]; move16(); @@ -3552,184 +3544,181 @@ generate_comfort_noise_dec_fx ( move16(); /* shift to be in the range of values supported by getNormReciprocalWord16() */ - N8 = shr(N2, CNG_NORM_RECIPROCAL_RANGE_SHIFT); + N8 = shr( N2, CNG_NORM_RECIPROCAL_RANGE_SHIFT ); - assert( N2 == (N8<olapWinSyn[i].v.re); - timeDomainOutput[i] = add(timeDomainOutput[i],tmp); + tmp = mult( noise[i], hFdCngCom->olapWinSyn[i].v.re ); + timeDomainOutput[i] = add( timeDomainOutput[i], tmp ); move16(); - tmp = mult(noise[i+N4],hFdCngCom->olapWinSyn[N4-1-i].v.im); - timeDomainOutput[i+N4] = add(timeDomainOutput[i+N4],tmp); + tmp = mult( noise[i + N4], hFdCngCom->olapWinSyn[N4 - 1 - i].v.im ); + timeDomainOutput[i + N4] = add( timeDomainOutput[i + N4], tmp ); move16(); } } } - } -void -generate_comfort_noise_dec_hf_fx ( - Word32 **bufferReal, /* o : matrix to real part of input bands */ - Word32 **bufferImag, /* o : matrix to imaginary part of input bands */ - Word16 *bufferScale, /* o : pointer to scalefactor for real and imaginary part of input bands */ - Decoder_State *st - ) +void generate_comfort_noise_dec_hf_fx( + Word32 **bufferReal, /* o : matrix to real part of input bands */ + Word32 **bufferImag, /* o : matrix to imaginary part of input bands */ + Word16 *bufferScale, /* o : pointer to scalefactor for real and imaginary part of input bands */ + Decoder_State *st ) { - Word16 i, j, s, sc, sn; - Word16 scaleCLDFB; - Word32 sqrtNoiseLevel; - Word16 randGaussExp; - Word16 cngNoiseLevelExp; + Word16 i, j, s, sc, sn; + Word16 scaleCLDFB; + Word32 sqrtNoiseLevel; + Word16 randGaussExp; + Word16 cngNoiseLevelExp; Word16 *seed; Word32 *cngNoiseLevel; Word32 *ptr_level; HANDLE_FD_CNG_COM hFdCngCom = st->hFdCngDec->hFdCngCom; - cngNoiseLevel = hFdCngCom->cngNoiseLevel+hFdCngCom->stopFFTbin-hFdCngCom->startBand; + cngNoiseLevel = hFdCngCom->cngNoiseLevel + hFdCngCom->stopFFTbin - hFdCngCom->startBand; cngNoiseLevelExp = hFdCngCom->cngNoiseLevelExp; ptr_level = cngNoiseLevel; - seed = &(hFdCngCom->seed); + seed = &( hFdCngCom->seed ); /* scaleCLDFB: CLDFBinvScalingFactor_EXP + 1 */ - scaleCLDFB = mult(hFdCngCom->invScalingFactor,CLDFB_SCALING); + scaleCLDFB = mult( hFdCngCom->invScalingFactor, CLDFB_SCALING ); sn = 0; move16(); - IF ( s_and(cngNoiseLevelExp,1) != 0 ) + IF( s_and( cngNoiseLevelExp, 1 ) != 0 ) { - sn = add(sn,1); - cngNoiseLevelExp = add(cngNoiseLevelExp,sn); + sn = add( sn, 1 ); + cngNoiseLevelExp = add( cngNoiseLevelExp, sn ); move16(); } randGaussExp = CNG_RAND_GAUSS_SHIFT; move16(); - IF ( LT_16(hFdCngCom->numCoreBands,hFdCngCom->regularStopBand)) + IF( LT_16( hFdCngCom->numCoreBands, hFdCngCom->regularStopBand ) ) { - sc = add(shr(add(cngNoiseLevelExp,CLDFBinvScalingFactor_EXP+1-1),1),randGaussExp); + sc = add( shr( add( cngNoiseLevelExp, CLDFBinvScalingFactor_EXP + 1 - 1 ), 1 ), randGaussExp ); move16(); - assert( ((cngNoiseLevelExp+CLDFBinvScalingFactor_EXP+1-1)&1) == 0); + assert( ( ( cngNoiseLevelExp + CLDFBinvScalingFactor_EXP + 1 - 1 ) & 1 ) == 0 ); - FOR (j=hFdCngCom->numCoreBands; jregularStopBand; j++) + FOR( j = hFdCngCom->numCoreBands; j < hFdCngCom->regularStopBand; j++ ) { /* scaleCLDFB: CLDFBinvScalingFactor_EXP + 1 */ s = 0; move16(); - sqrtNoiseLevel = Sqrt32(L_shr(Mpy_32_16_1(*ptr_level,scaleCLDFB),sn), &s); + sqrtNoiseLevel = Sqrt32( L_shr( Mpy_32_16_1( *ptr_level, scaleCLDFB ), sn ), &s ); - FOR (i=0; inumSlots; i++) + FOR( i = 0; i < hFdCngCom->numSlots; i++ ) { /* Real part in CLDFB band */ - bufferReal[i][j] = L_shl(Mpy_32_32(rand_gauss(seed),sqrtNoiseLevel),s); + bufferReal[i][j] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), s ); move32(); /*fprintf(pFile,"%13.10f\n",WORD322FL_SCALE(bufferReal[i][j],sc));*/ /* Imaginary part in CLDFB band */ - bufferImag[i][j] = L_shl(Mpy_32_32(rand_gauss(seed),sqrtNoiseLevel),s); + bufferImag[i][j] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), s ); move32(); /*fprintf(pFile,"%13.10f\n",WORD322FL_SCALE(bufferImag[i][j],sc));*/ } ptr_level = ptr_level + 1; } - *bufferScale = sub(sc,15); + *bufferScale = sub( sc, 15 ); move16(); } } @@ -3880,69 +3869,67 @@ void generate_comfort_noise_dec_hf_ivas_fx( void */ #ifdef IVAS_FLOAT_FIXED -void generate_masking_noise_fx ( - Word16 *timeDomainBuffer, /* i/o : pointer to time domain output buffer 15Q0 */ - Word16 Q, +void generate_masking_noise_fx( + Word16 *timeDomainBuffer, /* i/o : pointer to time domain output buffer 15Q0 */ + Word16 Q, HANDLE_FD_CNG_COM hFdCngCom /* i/o : pointer to FD_CNG_COM structure */ - ,Word16 length - ,Word16 core - ) + , + Word16 length, + Word16 core ) { - Word16 i, s, s1, s2, sq, cnt, startBand2, stopFFTbin2; - Word16 scaleExp,fftBufferExp,cngNoiseLevelExp; - Word16 scale, scaleTableSize; - Word16 maskingNoise[L_FRAME16k]; - Word32 sqrtNoiseLevel; + Word16 i, s, s1, s2, sq, cnt, startBand2, stopFFTbin2; + Word16 scaleExp, fftBufferExp, cngNoiseLevelExp; + Word16 scale, scaleTableSize; + Word16 maskingNoise[L_FRAME16k]; + Word32 sqrtNoiseLevel; Word32 *cngNoiseLevel; Word32 *fftBuffer; Word16 *seed; - // PMTE(); /*IVAS CODE need to be added */ + // PMTE(); /*IVAS CODE need to be added */ /* pointer initializations */ cngNoiseLevel = hFdCngCom->cngNoiseLevel; fftBuffer = hFdCngCom->fftBuffer; - seed = &(hFdCngCom->seed); + seed = &( hFdCngCom->seed ); /* Compute additional CN level */ cngNoiseLevelExp = hFdCngCom->cngNoiseLevelExp; move16(); - IF(core!=AMR_WB_CORE) + IF( core != AMR_WB_CORE ) { scaleTableSize = 18; move16(); - assert( scaleTableSize == (sizeof (scaleTable_cn_only) / sizeof (scaleTable_cn_only[0])) ); + assert( scaleTableSize == ( sizeof( scaleTable_cn_only ) / sizeof( scaleTable_cn_only[0] ) ) ); scale = -1; move16(); - FOR (i=0; i < scaleTableSize; i++) + FOR( i = 0; i < scaleTableSize; i++ ) { test(); test(); - IF ( ( EQ_16(hFdCngCom->CngBandwidth,scaleTable_cn_only[i].bwmode)) - && (GE_32(hFdCngCom->CngBitrate,scaleTable_cn_only[i].bitrateFrom) ) - && ( LT_32(hFdCngCom->CngBitrate,scaleTable_cn_only[i].bitrateTo) )) - + IF( ( EQ_16( hFdCngCom->CngBandwidth, scaleTable_cn_only[i].bwmode ) ) && ( GE_32( hFdCngCom->CngBitrate, scaleTable_cn_only[i].bitrateFrom ) ) && ( LT_32( hFdCngCom->CngBitrate, scaleTable_cn_only[i].bitrateTo ) ) ) + { scale = scaleTable_cn_only[i].scale; move16(); BREAK; } } - assert(scale >= 0); + assert( scale >= 0 ); } ELSE { scaleTableSize = 3; move16(); - assert( scaleTableSize == (sizeof (scaleTable_cn_only_amrwbio) / sizeof (scaleTable_cn_only_amrwbio[0])) ); + assert( scaleTableSize == ( sizeof( scaleTable_cn_only_amrwbio ) / sizeof( scaleTable_cn_only_amrwbio[0] ) ) ); scale = 0; move16(); - FOR (i=0; i < scaleTableSize; i++) + FOR( i = 0; i < scaleTableSize; i++ ) { - IF ( GE_32(hFdCngCom->CngBitrate,scaleTable_cn_only_amrwbio[i][0])) + IF( GE_32( hFdCngCom->CngBitrate, scaleTable_cn_only_amrwbio[i][0] ) ) { scale = scaleTable_cn_only_amrwbio[i][1]; move16(); @@ -3953,42 +3940,42 @@ void generate_masking_noise_fx ( /* Exclude clean speech */ - s1 = norm_s(scale); - s2 = norm_s(hFdCngCom->likelihood_noisy_speech); + s1 = norm_s( scale ); + s2 = norm_s( hFdCngCom->likelihood_noisy_speech ); /* scaleTable_cn_only[i].scale is scaled by 1 bit */ - scaleExp = sub(1,add(s1,s2)); - scale = mult_r(shl(scale,s1),shl(hFdCngCom->likelihood_noisy_speech,s2)); + scaleExp = sub( 1, add( s1, s2 ) ); + scale = mult_r( shl( scale, s1 ), shl( hFdCngCom->likelihood_noisy_speech, s2 ) ); { /* add exponent of scale and cngNoiseLevel */ - fftBufferExp = add(scaleExp,cngNoiseLevelExp); + fftBufferExp = add( scaleExp, cngNoiseLevelExp ); /* even scalefactor needed for sqrt calculation */ - s = s_and(fftBufferExp,1); - fftBufferExp = add(fftBufferExp,s); + s = s_and( fftBufferExp, 1 ); + fftBufferExp = add( fftBufferExp, s ); /* sqrt calculation => shift exponent */ - fftBufferExp = shr(fftBufferExp,1); + fftBufferExp = shr( fftBufferExp, 1 ); /* consider scaling of random noise */ - fftBufferExp = add(fftBufferExp,CNG_RAND_GAUSS_SHIFT); + fftBufferExp = add( fftBufferExp, CNG_RAND_GAUSS_SHIFT ); - cnt = sub(hFdCngCom->stopFFTbin,hFdCngCom->startBand); + cnt = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); /* Generate Gaussian random noise in real and imaginary parts of the FFT bins Amplitudes are adjusted to the estimated noise level cngNoiseLevel in each bin */ - IF ( hFdCngCom->startBand == 0 ) + IF( hFdCngCom->startBand == 0 ) { /* random noise is scaled by CNG_RAND_GAUSS_SHIFT bits */ /* DC component in FFT */ /* -s => consider scalefactor adaptation for sqrt calculation */ - sq = sub(0,s); - sqrtNoiseLevel = Sqrt32(Mpy_32_16_1(*cngNoiseLevel,scale),&sq); - hFdCngCom->fftBuffer[0] = L_shl(Mpy_32_32(rand_gauss(seed),sqrtNoiseLevel),sq); + sq = sub( 0, s ); + sqrtNoiseLevel = Sqrt32( Mpy_32_16_1( *cngNoiseLevel, scale ), &sq ); + hFdCngCom->fftBuffer[0] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), sq ); move32(); hFdCngCom->fftBuffer[1] = 0; move32(); @@ -3996,32 +3983,32 @@ void generate_masking_noise_fx ( fftBuffer = hFdCngCom->fftBuffer + 2; cngNoiseLevel++; - cnt = sub(cnt,1); + cnt = sub( cnt, 1 ); } ELSE { - startBand2 = shl(hFdCngCom->startBand,1); - set32_fx(hFdCngCom->fftBuffer,0,startBand2); + startBand2 = shl( hFdCngCom->startBand, 1 ); + set32_fx( hFdCngCom->fftBuffer, 0, startBand2 ); fftBuffer = hFdCngCom->fftBuffer + startBand2; } - FOR (i=0; i weighting with 0.5, -s => consider scalefactor adaptation for sqrt calculation */ - sq = sub(-1,s); - sqrtNoiseLevel = Sqrt32(Mpy_32_16_1(*cngNoiseLevel,scale),&sq); + sq = sub( -1, s ); + sqrtNoiseLevel = Sqrt32( Mpy_32_16_1( *cngNoiseLevel, scale ), &sq ); /* real part in FFT bins */ /* random noise is scaled by CNG_RAND_GAUSS_SHIFT bits */ - *fftBuffer = L_shl(Mpy_32_32(rand_gauss(seed),sqrtNoiseLevel),sq); + *fftBuffer = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), sq ); move32(); fftBuffer++; /* imaginary part in FFT bins */ /* random noise is scaled by CNG_RAND_GAUSS_SHIFT bits */ - *fftBuffer = L_shl(Mpy_32_32(rand_gauss(seed),sqrtNoiseLevel),sq); + *fftBuffer = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), sq ); move32(); fftBuffer++; @@ -4029,40 +4016,39 @@ void generate_masking_noise_fx ( } /* remaining FFT bins are set to zero */ - stopFFTbin2 = shl(hFdCngCom->stopFFTbin,1); - set32_fx(hFdCngCom->fftBuffer+stopFFTbin2, 0, sub(hFdCngCom->fftlen,stopFFTbin2)); + stopFFTbin2 = shl( hFdCngCom->stopFFTbin, 1 ); + set32_fx( hFdCngCom->fftBuffer + stopFFTbin2, 0, sub( hFdCngCom->fftlen, stopFFTbin2 ) ); /* perform STFT synthesis */ - assert(hFdCngCom->olapBufferSynth2 != NULL); - SynthesisSTFT(hFdCngCom->fftBuffer, fftBufferExp, maskingNoise, hFdCngCom->olapBufferSynth2, hFdCngCom->olapWinSyn, - 0, hFdCngCom, 0, NULL, -1/*st->element_mode*/, -1/*nchan_out*/); - //PMT("parameters need update") + assert( hFdCngCom->olapBufferSynth2 != NULL ); + SynthesisSTFT( hFdCngCom->fftBuffer, fftBufferExp, maskingNoise, hFdCngCom->olapBufferSynth2, hFdCngCom->olapWinSyn, + 0, hFdCngCom, 0, NULL, -1 /*st->element_mode*/, -1 /*nchan_out*/ ); + // PMT("parameters need update") /* add some comfort noise on top of decoded signal */ - IF ( hFdCngCom->frameSize > length ) + IF( hFdCngCom->frameSize > length ) { - FOR (i=0; iframeSize; i++) + FOR( i = 0; i < hFdCngCom->frameSize; i++ ) { #ifdef BASOP_NOGLOB - timeDomainBuffer[i] = add_sat(timeDomainBuffer[i],shr_r_sat (maskingNoise[i],-Q)); + timeDomainBuffer[i] = add_sat( timeDomainBuffer[i], shr_r_sat( maskingNoise[i], -Q ) ); #else - timeDomainBuffer[i] = add(timeDomainBuffer[i],shr_r(maskingNoise[i],-Q)); + timeDomainBuffer[i] = add( timeDomainBuffer[i], shr_r( maskingNoise[i], -Q ) ); #endif move16(); } } } - } #endif @@ -4074,28 +4060,28 @@ void generate_masking_noise_fx ( *-------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -void generate_masking_noise_update_seed_fx ( - HANDLE_FD_CNG_COM hFdCngCom /* i/o : pointer to FD_CNG_COM structure */ +void generate_masking_noise_update_seed_fx( + HANDLE_FD_CNG_COM hFdCngCom /* i/o : pointer to FD_CNG_COM structure */ ) { Word16 *seed; Word16 cnt, i; /* pointer initializations */ - seed = &(hFdCngCom->seed); + seed = &( hFdCngCom->seed ); - cnt = sub(hFdCngCom->stopFFTbin, hFdCngCom->startBand); + cnt = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); - IF ( hFdCngCom->startBand == 0 ) + IF( hFdCngCom->startBand == 0 ) { - rand_gauss(seed); - cnt = sub(cnt,1); + rand_gauss( seed ); + cnt = sub( cnt, 1 ); } - FOR (i=0; icngNoiseLevel; - seed = &(hFdCngCom->seed); + seed = &( hFdCngCom->seed ); /* Compute additional CN level */ cngNoiseLevelExp = hFdCngCom->cngNoiseLevelExp; @@ -4136,86 +4122,83 @@ void generate_masking_noise_mdct_fx ( /* Compute additional CN level */ scaleTableSize = 18; move16(); - assert( scaleTableSize == (sizeof (scaleTable_cn_only) / sizeof (scaleTable_cn_only[0])) ); + assert( scaleTableSize == ( sizeof( scaleTable_cn_only ) / sizeof( scaleTable_cn_only[0] ) ) ); scale = -1; move16(); - FOR (i=0; i < scaleTableSize; i++) + FOR( i = 0; i < scaleTableSize; i++ ) { test(); test(); - IF ( ( EQ_16(hFdCngCom->CngBandwidth,scaleTable_cn_only[i].bwmode)) - && ( GE_32(hFdCngCom->CngBitrate,scaleTable_cn_only[i].bitrateFrom) ) - && ( LT_32(hFdCngCom->CngBitrate,scaleTable_cn_only[i].bitrateTo) ) - ) + IF( ( EQ_16( hFdCngCom->CngBandwidth, scaleTable_cn_only[i].bwmode ) ) && ( GE_32( hFdCngCom->CngBitrate, scaleTable_cn_only[i].bitrateFrom ) ) && ( LT_32( hFdCngCom->CngBitrate, scaleTable_cn_only[i].bitrateTo ) ) ) { scale = scaleTable_cn_only[i].scale; move16(); BREAK; } } - assert(scale >= 0); + assert( scale >= 0 ); /* Exclude clean speech */ - s1 = norm_s(scale); - s2 = norm_s(hFdCngCom->likelihood_noisy_speech); + s1 = norm_s( scale ); + s2 = norm_s( hFdCngCom->likelihood_noisy_speech ); /* scaleTable_cn_only[i].scale is scaled by 1 bit */ - scaleExp = sub(1,add(s1,s2)); - scale = mult_r(shl(scale,s1),shl(hFdCngCom->likelihood_noisy_speech,s2)); + scaleExp = sub( 1, add( s1, s2 ) ); + scale = mult_r( shl( scale, s1 ), shl( hFdCngCom->likelihood_noisy_speech, s2 ) ); /* add exponent of scale and cngNoiseLevel */ - maskingNoiseExp = add(scaleExp,cngNoiseLevelExp); + maskingNoiseExp = add( scaleExp, cngNoiseLevelExp ); /* even scalefactor needed for sqrt calculation */ - s = s_and(maskingNoiseExp,1); - maskingNoiseExp = add(maskingNoiseExp,s); + s = s_and( maskingNoiseExp, 1 ); + maskingNoiseExp = add( maskingNoiseExp, s ); /* sqrt calculation => shift exponent */ - maskingNoiseExp = shr(maskingNoiseExp,1); + maskingNoiseExp = shr( maskingNoiseExp, 1 ); /* consider scaling of random noise */ - maskingNoiseExp = add(maskingNoiseExp,CNG_RAND_GAUSS_SHIFT); + maskingNoiseExp = add( maskingNoiseExp, CNG_RAND_GAUSS_SHIFT ); - cnt = sub(hFdCngCom->stopFFTbin,hFdCngCom->startBand); + cnt = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); /* Generate Gaussian random noise in real and imaginary parts of the FFT bins Amplitudes are adjusted to the estimated noise level cngNoiseLevel in each bin */ - IF ( hFdCngCom->startBand == 0 ) + IF( hFdCngCom->startBand == 0 ) { /* random noise is scaled by CNG_RAND_GAUSS_SHIFT bits */ /* DC component in FFT */ /* -1 => weighting with 0.5, -s => consider scalefactor adaptation for sqrt calculation */ - sq = sub(-1,s); - sqrtNoiseLevel = Sqrt32(Mpy_32_16_1(*cngNoiseLevel,scale),&sq); - maskingNoise[0] = L_shl(Mpy_32_32(rand_gauss(seed),sqrtNoiseLevel),sq); + sq = sub( -1, s ); + sqrtNoiseLevel = Sqrt32( Mpy_32_16_1( *cngNoiseLevel, scale ), &sq ); + maskingNoise[0] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), sq ); move32(); pMaskingNoise = &maskingNoise[1]; cngNoiseLevel++; - cnt = sub(cnt,1); + cnt = sub( cnt, 1 ); } ELSE { - set32_fx(maskingNoise,0,hFdCngCom->startBand); + set32_fx( maskingNoise, 0, hFdCngCom->startBand ); pMaskingNoise = maskingNoise + hFdCngCom->startBand; } - FOR (i=0; i weighting with 0.5, -s => consider scalefactor adaptation for sqrt calculation */ - sq = sub(-1,s); - sqrtNoiseLevel = Sqrt32(Mpy_32_16_1(*cngNoiseLevel,scale),&sq); + sq = sub( -1, s ); + sqrtNoiseLevel = Sqrt32( Mpy_32_16_1( *cngNoiseLevel, scale ), &sq ); /* real part in FFT bins */ /* random noise is scaled by CNG_RAND_GAUSS_SHIFT bits */ - *pMaskingNoise = L_shl(Mpy_32_32(rand_gauss(seed),sqrtNoiseLevel),sq); + *pMaskingNoise = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), sq ); move32(); pMaskingNoise++; @@ -4228,51 +4211,50 @@ void generate_masking_noise_mdct_fx ( assert( NORM_MDCT_FACTOR == 160 ); /* do weighting with factor 0.79056941504 later */ - maskingNoiseExp = add(maskingNoiseExp,4); + maskingNoiseExp = add( maskingNoiseExp, 4 ); - s = s_max(*mdctBuffer_e,maskingNoiseExp); - s1 = sub(s,*mdctBuffer_e); - s2 = sub(s,maskingNoiseExp); + s = s_max( *mdctBuffer_e, maskingNoiseExp ); + s1 = sub( s, *mdctBuffer_e ); + s2 = sub( s, maskingNoiseExp ); /* avoid rescaling of mdct samples if no comfort noise is added */ - IF ( scale != 0 ) + IF( scale != 0 ) { /* Add some comfort noise on top of decoded signal */ - IF ( s1 == 0 ) + IF( s1 == 0 ) { - FOR (i=0; i < hFdCngCom->stopFFTbin; i++) + FOR( i = 0; i < hFdCngCom->stopFFTbin; i++ ) { /* If shifting negative noise values the lowest result is -1 but never 0. Shift positive noise values to avoid unwanted amplification of these small values later */ - noise = L_shr(Mpy_32_16_1(L_abs(maskingNoise[i]),25905/*0.79056941504 Q15*/),s2); + noise = L_shr( Mpy_32_16_1( L_abs( maskingNoise[i] ), 25905 /*0.79056941504 Q15*/ ), s2 ); if ( maskingNoise[i] < 0 ) { - noise = L_negate(noise); + noise = L_negate( noise ); } - mdctBuffer[i] = L_add(mdctBuffer[i], noise); + mdctBuffer[i] = L_add( mdctBuffer[i], noise ); move32(); } } ELSE { - FOR (i=0; i < hFdCngCom->stopFFTbin; i++) + FOR( i = 0; i < hFdCngCom->stopFFTbin; i++ ) { - mdctBuffer[i] = L_add(L_shr(mdctBuffer[i],s1), - Mpy_32_16_1(maskingNoise[i],25905/*0.79056941504 Q15*/)); + mdctBuffer[i] = L_add( L_shr( mdctBuffer[i], s1 ), + Mpy_32_16_1( maskingNoise[i], 25905 /*0.79056941504 Q15*/ ) ); move32(); } - FOR (i=hFdCngCom->stopFFTbin; i < L_frame; i++) + FOR( i = hFdCngCom->stopFFTbin; i < L_frame; i++ ) { - mdctBuffer[i] = L_shr(mdctBuffer[i],s1); + mdctBuffer[i] = L_shr( mdctBuffer[i], s1 ); move32(); } *mdctBuffer_e = s; move16(); } } - } #endif @@ -4285,8 +4267,8 @@ void generate_masking_noise_mdct_fx ( *-------------------------------------------------------------------*/ void generate_stereo_masking_noise( - float* syn, /* i/o: time-domain signal */ - Decoder_State* st, /* i/o: decoder state structure */ + float *syn, /* i/o: time-domain signal */ + Decoder_State *st, /* i/o: decoder state structure */ STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i : TD stereo structure */ const int16_t flag_sec_CNA, /* i : CNA flag for secondary channel */ const int16_t fadeOut, /* i : only fade out of previous state */ @@ -4302,60 +4284,60 @@ void generate_stereo_masking_noise( float N2[L_FRAME16k]; int16_t i; - if (st->idchan == 0) + if ( st->idchan == 0 ) { hFdCngCom = st->hFdCngDec->hFdCngCom; - mvr2r(hFdCngCom->olapBufferSynth2, Np, hFdCngCom->frameSize / 2); - mvr2r(hStereoCng->olapBufferSynth22, Ns, hFdCngCom->frameSize / 2); - set_f(&Np[hFdCngCom->frameSize / 2], 0.0f, hFdCngCom->frameSize / 2); - set_f(&Ns[hFdCngCom->frameSize / 2], 0.0f, hFdCngCom->frameSize / 2); + mvr2r( hFdCngCom->olapBufferSynth2, Np, hFdCngCom->frameSize / 2 ); + mvr2r( hStereoCng->olapBufferSynth22, Ns, hFdCngCom->frameSize / 2 ); + set_f( &Np[hFdCngCom->frameSize / 2], 0.0f, hFdCngCom->frameSize / 2 ); + set_f( &Ns[hFdCngCom->frameSize / 2], 0.0f, hFdCngCom->frameSize / 2 ); - if (!fadeOut) + if ( !fadeOut ) { - generate_masking_noise_fx(N1, hFdCngCom, hFdCngCom->frameSize, 0, 1, 0, st->element_mode, hStereoCng, nchan_out); + generate_masking_noise_fx( N1, hFdCngCom, hFdCngCom->frameSize, 0, 1, 0, st->element_mode, hStereoCng, nchan_out ); /* Generate masking noise for secondary channel */ - if (flag_sec_CNA) + if ( flag_sec_CNA ) { - generate_masking_noise_fx(N2, hFdCngCom, hFdCngCom->frameSize, 0, 1, 1, st->element_mode, hStereoCng, nchan_out); + generate_masking_noise_fx( N2, hFdCngCom, hFdCngCom->frameSize, 0, 1, 1, st->element_mode, hStereoCng, nchan_out ); gamma = hStereoCng->c_PS_LT * hStereoCng->c_PS_LT; scale = 1.0f; - if (gamma < 0.9f) + if ( gamma < 0.9f ) { - gamma = gamma / (1 - gamma); - gamma = (float)sqrt(gamma + 1) - (float)sqrt(gamma); - scale = 1.0f / (float)sqrt(1 + gamma * gamma); + gamma = gamma / ( 1 - gamma ); + gamma = (float) sqrt( gamma + 1 ) - (float) sqrt( gamma ); + scale = 1.0f / (float) sqrt( 1 + gamma * gamma ); } else { gamma = 0.0f; } - for (i = 0; i < 2 * hFdCngCom->frameSize / 4; i++) + for ( i = 0; i < 2 * hFdCngCom->frameSize / 4; i++ ) { - Np[i] += scale * (N1[i] + gamma * N2[i]); - Ns[i] += scale * sign(hStereoCng->c_PS_LT) * (N1[i] - gamma * N2[i]); + Np[i] += scale * ( N1[i] + gamma * N2[i] ); + Ns[i] += scale * sign( hStereoCng->c_PS_LT ) * ( N1[i] - gamma * N2[i] ); } - for (; i < hFdCngCom->frameSize; i++) + for ( ; i < hFdCngCom->frameSize; i++ ) { - Np[i] = scale * (N1[i] + gamma * N2[i]); - Ns[i] = scale * sign(hStereoCng->c_PS_LT) * (N1[i] - gamma * N2[i]); + Np[i] = scale * ( N1[i] + gamma * N2[i] ); + Ns[i] = scale * sign( hStereoCng->c_PS_LT ) * ( N1[i] - gamma * N2[i] ); } - scale *= (float)(hFdCngCom->fftlen / 2); - for (i = 0; i < hFdCngCom->frameSize / 2; i++) + scale *= (float) ( hFdCngCom->fftlen / 2 ); + for ( i = 0; i < hFdCngCom->frameSize / 2; i++ ) { - hFdCngCom->olapBufferSynth2[i] = scale * (hFdCngCom->olapBufferSynth2[i + 5 * hFdCngCom->frameSize / 4] + gamma * hStereoCng->olapBufferSynth22[i + 5 * hFdCngCom->frameSize / 4]); - hStereoCng->olapBufferSynth22[i] = sign(hStereoCng->c_PS_LT) * scale * (hFdCngCom->olapBufferSynth2[i + 5 * hFdCngCom->frameSize / 4] - gamma * hStereoCng->olapBufferSynth22[i + 5 * hFdCngCom->frameSize / 4]); + hFdCngCom->olapBufferSynth2[i] = scale * ( hFdCngCom->olapBufferSynth2[i + 5 * hFdCngCom->frameSize / 4] + gamma * hStereoCng->olapBufferSynth22[i + 5 * hFdCngCom->frameSize / 4] ); + hStereoCng->olapBufferSynth22[i] = sign( hStereoCng->c_PS_LT ) * scale * ( hFdCngCom->olapBufferSynth2[i + 5 * hFdCngCom->frameSize / 4] - gamma * hStereoCng->olapBufferSynth22[i + 5 * hFdCngCom->frameSize / 4] ); } } else { - for (i = 0; i < hFdCngCom->frameSize / 2; i++) + for ( i = 0; i < hFdCngCom->frameSize / 2; i++ ) { Np[i] += N1[i]; } - mvr2r(&N1[hFdCngCom->frameSize / 2], &Np[hFdCngCom->frameSize / 2], hFdCngCom->frameSize / 2); - scale = (float)(hFdCngCom->fftlen / 2); - for (i = 0; i < hFdCngCom->frameSize; i++) + mvr2r( &N1[hFdCngCom->frameSize / 2], &Np[hFdCngCom->frameSize / 2], hFdCngCom->frameSize / 2 ); + scale = (float) ( hFdCngCom->fftlen / 2 ); + for ( i = 0; i < hFdCngCom->frameSize; i++ ) { hFdCngCom->olapBufferSynth2[i] = scale * hFdCngCom->olapBufferSynth2[i + 5 * hFdCngCom->frameSize / 4]; } @@ -4363,36 +4345,36 @@ void generate_stereo_masking_noise( } else { - set_f(hFdCngCom->olapBufferSynth2, 0.0f, hFdCngCom->frameSize / 2); - set_f(hStereoCng->olapBufferSynth22, 0.0f, hFdCngCom->frameSize / 2); + set_f( hFdCngCom->olapBufferSynth2, 0.0f, hFdCngCom->frameSize / 2 ); + set_f( hStereoCng->olapBufferSynth22, 0.0f, hFdCngCom->frameSize / 2 ); } - if (flag_sec_CNA) + if ( flag_sec_CNA ) { - mvr2r(Ns, hStereoCng->maskingNoiseS, hFdCngCom->frameSize); + mvr2r( Ns, hStereoCng->maskingNoiseS, hFdCngCom->frameSize ); hStereoCng->enableSecCNA = 1; } else { - set_f(hStereoCng->olapBufferSynth22, 0.0f, hFdCngCom->frameSize); + set_f( hStereoCng->olapBufferSynth22, 0.0f, hFdCngCom->frameSize ); } /* add masking noise */ - v_add(Np, syn, syn, hFdCngCom->frameSize); + v_add( Np, syn, syn, hFdCngCom->frameSize ); } - else if (hStereoCng->enableSecCNA) + else if ( hStereoCng->enableSecCNA ) { SP_ratio = hStereoTD->SP_ratio_LT; /* Use long-term SP ratio based on L/R synthesis */ /* scale and add masking noise */ - for (i = 0; i < *hStereoCng->frameSize / 4; i++) + for ( i = 0; i < *hStereoCng->frameSize / 4; i++ ) { - scale = ((hStereoTD->prevSP_ratio * (*hStereoCng->frameSize / 4 - (float)i) + SP_ratio * (float)i) / (*hStereoCng->frameSize / 4)); + scale = ( ( hStereoTD->prevSP_ratio * ( *hStereoCng->frameSize / 4 - (float) i ) + SP_ratio * (float) i ) / ( *hStereoCng->frameSize / 4 ) ); syn[i] += scale * hStereoCng->maskingNoiseS[i]; } - for (; i < *hStereoCng->frameSize / 2; i++) + for ( ; i < *hStereoCng->frameSize / 2; i++ ) { syn[i] += SP_ratio * hStereoCng->maskingNoiseS[i]; } - for (; i < *hStereoCng->frameSize; i++) + for ( ; i < *hStereoCng->frameSize; i++ ) { syn[i] += SP_ratio * hStereoCng->maskingNoiseS[i]; } @@ -4411,177 +4393,177 @@ void generate_stereo_masking_noise( void generate_masking_noise_dirac( HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i : filterbank state */ - float* tdBuffer, /* i/o: time-domain signal, if NULL no LB-CNA */ - float* Cldfb_RealBuffer, /* o : CLDFD real buffer */ - float* Cldfb_ImagBuffer, /* o : CLDFD imaginary buffer */ + float *tdBuffer, /* i/o: time-domain signal, if NULL no LB-CNA */ + float *Cldfb_RealBuffer, /* o : CLDFD real buffer */ + float *Cldfb_ImagBuffer, /* o : CLDFD imaginary buffer */ const int16_t slot_index, /* i : CLDFB slot index */ const int16_t cna_flag, /* i : CNA flag for LB and HB */ const int16_t fd_cng_flag /* i : FD-CNG flag for HB */ ) { int16_t i; - float* cngNoiseLevel = hFdCngCom->cngNoiseLevel; - float* fftBuffer = hFdCngCom->fftBuffer; - float* ptr_r; - float* ptr_i; - float* ptr_level; - int16_t* seed = &(hFdCngCom->seed); + float *cngNoiseLevel = hFdCngCom->cngNoiseLevel; + float *fftBuffer = hFdCngCom->fftBuffer; + float *ptr_r; + float *ptr_i; + float *ptr_level; + int16_t *seed = &( hFdCngCom->seed ); float scale; - wmops_sub_start("fd_cng_dirac"); + wmops_sub_start( "fd_cng_dirac" ); /* Init */ scale = 0.f; /* Resample CLDFB memories if necessary*/ - if ((h_cldfb->no_channels * h_cldfb->no_col) != hFdCngCom->frameSize) + if ( ( h_cldfb->no_channels * h_cldfb->no_col ) != hFdCngCom->frameSize ) { - resampleCldfb(h_cldfb, hFdCngCom->frameSize * FRAMES_PER_SEC); + resampleCldfb( h_cldfb, hFdCngCom->frameSize * FRAMES_PER_SEC ); } - set_zero(Cldfb_RealBuffer, CLDFB_NO_CHANNELS_MAX); - set_zero(Cldfb_ImagBuffer, CLDFB_NO_CHANNELS_MAX); + set_zero( Cldfb_RealBuffer, CLDFB_NO_CHANNELS_MAX ); + set_zero( Cldfb_ImagBuffer, CLDFB_NO_CHANNELS_MAX ); /*LB CLDFB - CNA from STFT*/ #ifdef DEBUG_MODE_DIRAC { int16_t tmp_s; - tmp_s = (int16_t)(32768.f * 0.5f * hFdCngCom->likelihood_noisy_speech * cna_flag + 0.5f); - dbgwrite(&tmp_s, sizeof(int16_t), 1, hFdCngCom->frameSize / 16, "./res/ivas_dirac_likelihood_noisy.pcm"); + tmp_s = (int16_t) ( 32768.f * 0.5f * hFdCngCom->likelihood_noisy_speech * cna_flag + 0.5f ); + dbgwrite( &tmp_s, sizeof( int16_t ), 1, hFdCngCom->frameSize / 16, "./res/ivas_dirac_likelihood_noisy.pcm" ); } #endif - if (cna_flag) + if ( cna_flag ) { /* skip noise generating if level is very low, to avoid problems with possibly running into denormals */ - if (hFdCngCom->likelihood_noisy_speech > DELTA_MASKING_NOISE) + if ( hFdCngCom->likelihood_noisy_speech > DELTA_MASKING_NOISE ) { /* Compute additional CN level */ - for (i = 0; i < 15; i++) + for ( i = 0; i < 15; i++ ) { - if ((hFdCngCom->CngBandwidth == scaleTable_cn_dirac[i].bwmode) && - (hFdCngCom->CngBitrate >= scaleTable_cn_dirac[i].bitrateFrom) && - (hFdCngCom->CngBitrate < scaleTable_cn_dirac[i].bitrateTo)) + if ( ( hFdCngCom->CngBandwidth == scaleTable_cn_dirac[i].bwmode ) && + ( hFdCngCom->CngBitrate >= scaleTable_cn_dirac[i].bitrateFrom ) && + ( hFdCngCom->CngBitrate < scaleTable_cn_dirac[i].bitrateTo ) ) { break; } } - scale = (float)pow(10.f, -scaleTable_cn_dirac[i].scale / 10.f) - 1.f; + scale = (float) pow( 10.f, -scaleTable_cn_dirac[i].scale / 10.f ) - 1.f; scale *= hFdCngCom->likelihood_noisy_speech; } } /* LB CLDFB - CNA from STFT: CNA applied only in channel 0*/ - if (cna_flag && tdBuffer != NULL) + if ( cna_flag && tdBuffer != NULL ) { - if (scale != 0) + if ( scale != 0 ) { /*Generate LF comfort noise only at first slot, for the whole frame*/ - if (slot_index == 0) + if ( slot_index == 0 ) { ptr_level = cngNoiseLevel; /* Generate Gaussian random noise in real and imaginary parts of the FFT bins Amplitudes are adjusted to the estimated noise level cngNoiseLevel in each bin */ - if (hFdCngCom->startBand == 0) + if ( hFdCngCom->startBand == 0 ) { - rand_gauss(&fftBuffer[0], seed); + rand_gauss( &fftBuffer[0], seed ); ptr_r = fftBuffer + 2; - fftBuffer[0] *= (float)sqrt(scale * *ptr_level); /* DC component in FFT */ + fftBuffer[0] *= (float) sqrt( scale * *ptr_level ); /* DC component in FFT */ ptr_level++; } else { fftBuffer[0] = 0.f; - set_f(fftBuffer + 2, 0.0f, 2 * (hFdCngCom->startBand - 1)); + set_f( fftBuffer + 2, 0.0f, 2 * ( hFdCngCom->startBand - 1 ) ); ptr_r = fftBuffer + 2 * hFdCngCom->startBand; } ptr_i = ptr_r + 1; - for (; ptr_level < cngNoiseLevel + hFdCngCom->stopFFTbin - hFdCngCom->startBand; ptr_level++) + for ( ; ptr_level < cngNoiseLevel + hFdCngCom->stopFFTbin - hFdCngCom->startBand; ptr_level++ ) { /* Real part in FFT bins */ - rand_gauss(ptr_r, seed); - (*ptr_r) *= (float)sqrt((scale * *ptr_level) * 0.5f); + rand_gauss( ptr_r, seed ); + ( *ptr_r ) *= (float) sqrt( ( scale * *ptr_level ) * 0.5f ); ptr_r += 2; /* Imaginary part in FFT bins */ - rand_gauss(ptr_i, seed); - (*ptr_i) *= (float)sqrt((scale * *ptr_level) * 0.5f); + rand_gauss( ptr_i, seed ); + ( *ptr_i ) *= (float) sqrt( ( scale * *ptr_level ) * 0.5f ); ptr_i += 2; } /* Remaining FFT bins are set to zero */ - set_f(fftBuffer + 2 * hFdCngCom->stopFFTbin, 0.0f, hFdCngCom->fftlen - 2 * hFdCngCom->stopFFTbin); + set_f( fftBuffer + 2 * hFdCngCom->stopFFTbin, 0.0f, hFdCngCom->fftlen - 2 * hFdCngCom->stopFFTbin ); /* Nyquist frequency is discarded */ fftBuffer[1] = 0.f; /* Perform STFT synthesis */ - SynthesisSTFT(fftBuffer, tdBuffer, hFdCngCom->olapBufferSynth2, hFdCngCom->olapWinSyn, 0, hFdCngCom, X, Y, -1, -1); + SynthesisSTFT( fftBuffer, tdBuffer, hFdCngCom->olapBufferSynth2, hFdCngCom->olapWinSyn, 0, hFdCngCom, X, Y, -1, -1 ); #ifdef DEBUG_MODE_DIRAC { int16_t tmp[1000]; - for (i = 0; i < hFdCngCom->frameSize; i++) + for ( i = 0; i < hFdCngCom->frameSize; i++ ) { - tmp[i] = (int16_t)(tdBuffer[i] + 0.5f); + tmp[i] = (int16_t) ( tdBuffer[i] + 0.5f ); } - dbgwrite(tmp, sizeof(int16_t), hFdCngCom->frameSize, 1, "./res/ivas_dirac_cna_fft.pcm"); + dbgwrite( tmp, sizeof( int16_t ), hFdCngCom->frameSize, 1, "./res/ivas_dirac_cna_fft.pcm" ); } #endif } /* LF CLDFB*/ - cldfbAnalysis_ts(&(tdBuffer[hFdCngCom->numCoreBands * slot_index]), Cldfb_RealBuffer, Cldfb_ImagBuffer, hFdCngCom->numCoreBands, h_cldfb); + cldfbAnalysis_ts( &( tdBuffer[hFdCngCom->numCoreBands * slot_index] ), Cldfb_RealBuffer, Cldfb_ImagBuffer, hFdCngCom->numCoreBands, h_cldfb ); } else { - if (slot_index == 0) + if ( slot_index == 0 ) { /* very low level case - update random seeds */ - generate_masking_noise_update_seed_fx(hFdCngCom); + generate_masking_noise_update_seed_fx( hFdCngCom ); - set_f(fftBuffer, 0.f, hFdCngCom->fftlen); + set_f( fftBuffer, 0.f, hFdCngCom->fftlen ); /* Perform STFT synthesis */ - SynthesisSTFT(fftBuffer, tdBuffer, hFdCngCom->olapBufferSynth2, hFdCngCom->olapWinSyn, 0, hFdCngCom,X, Y , -1, -1); + SynthesisSTFT( fftBuffer, tdBuffer, hFdCngCom->olapBufferSynth2, hFdCngCom->olapWinSyn, 0, hFdCngCom, X, Y, -1, -1 ); #ifdef DEBUG_MODE_DIRAC { int16_t tmp[1000]; - for (i = 0; i < hFdCngCom->frameSize; i++) + for ( i = 0; i < hFdCngCom->frameSize; i++ ) { - tmp[i] = (int16_t)(tdBuffer[i] + 0.5f); + tmp[i] = (int16_t) ( tdBuffer[i] + 0.5f ); } - dbgwrite(tmp, sizeof(int16_t), hFdCngCom->frameSize, 1, "./res/ivas_dirac_cna_fft.pcm"); + dbgwrite( tmp, sizeof( int16_t ), hFdCngCom->frameSize, 1, "./res/ivas_dirac_cna_fft.pcm" ); } #endif } /* LB ana CLDFB*/ - cldfbAnalysis_ts(&(tdBuffer[hFdCngCom->numCoreBands * slot_index]), Cldfb_RealBuffer, Cldfb_ImagBuffer, hFdCngCom->numCoreBands, h_cldfb); + cldfbAnalysis_ts( &( tdBuffer[hFdCngCom->numCoreBands * slot_index] ), Cldfb_RealBuffer, Cldfb_ImagBuffer, hFdCngCom->numCoreBands, h_cldfb ); } } /*HF CLDFB - CNA and/or FD-CNG*/ - if (fd_cng_flag) + if ( fd_cng_flag ) { scale += 1.f; } - if (scale != 0) + if ( scale != 0 ) { - scale *= CLDFB_SCALING_FLT * (h_cldfb->scale * h_cldfb->scale * 8.f); + scale *= CLDFB_SCALING_FLT * ( h_cldfb->scale * h_cldfb->scale * 8.f ); ptr_level = hFdCngCom->cngNoiseLevel + hFdCngCom->stopFFTbin - hFdCngCom->startBand; - for (i = hFdCngCom->numCoreBands; i < hFdCngCom->regularStopBand; i++) + for ( i = hFdCngCom->numCoreBands; i < hFdCngCom->regularStopBand; i++ ) { /* Real part in CLDFB band */ - rand_gauss(&Cldfb_RealBuffer[i], seed); - Cldfb_RealBuffer[i] *= (float)sqrt((scale * *ptr_level) * 0.5f); + rand_gauss( &Cldfb_RealBuffer[i], seed ); + Cldfb_RealBuffer[i] *= (float) sqrt( ( scale * *ptr_level ) * 0.5f ); /* Imaginary part in CLDFB band */ - rand_gauss(&Cldfb_ImagBuffer[i], seed); - Cldfb_ImagBuffer[i] *= (float)sqrt((scale * *ptr_level) * 0.5f); + rand_gauss( &Cldfb_ImagBuffer[i], seed ); + Cldfb_ImagBuffer[i] *= (float) sqrt( ( scale * *ptr_level ) * 0.5f ); ptr_level++; } @@ -4606,8 +4588,8 @@ void FdCngDecodeMDCTStereoSID( { DEC_CORE_HANDLE sts[CPE_CHANNELS]; HANDLE_FD_CNG_COM hFdCngCom; - float* ms_ptr[CPE_CHANNELS]; - float* lr_ptr[CPE_CHANNELS]; + float *ms_ptr[CPE_CHANNELS]; + float *lr_ptr[CPE_CHANNELS]; float logNoiseEst[CPE_CHANNELS][NPART]; float gain[CPE_CHANNELS]; int16_t indices[FD_CNG_stages_37bits]; @@ -4615,14 +4597,14 @@ void FdCngDecodeMDCTStereoSID( int16_t is_out_ms; is_out_ms = 0; - if (hCPE->hCoreCoder[0]->cng_sba_flag) + if ( hCPE->hCoreCoder[0]->cng_sba_flag ) { is_out_ms = 1; } N = 0; /* to avoid compilation warning */ - for (ch = 0; ch < CPE_CHANNELS; ch++) + for ( ch = 0; ch < CPE_CHANNELS; ch++ ) { sts[ch] = hCPE->hCoreCoder[ch]; ms_ptr[ch] = &logNoiseEst[ch][0]; @@ -4630,14 +4612,14 @@ void FdCngDecodeMDCTStereoSID( } /* decode noise shapes and gains */ - for (ch = 0; ch < CPE_CHANNELS; ch++) + for ( ch = 0; ch < CPE_CHANNELS; ch++ ) { sts[ch] = hCPE->hCoreCoder[ch]; - hFdCngCom = (sts[ch]->hFdCngDec)->hFdCngCom; + hFdCngCom = ( sts[ch]->hFdCngDec )->hFdCngCom; N = hFdCngCom->npart; hFdCngCom->sid_frame_counter++; - if (ch) + if ( ch ) { stages = FD_CNG_JOINT_stages_25bits; } @@ -4647,47 +4629,47 @@ void FdCngDecodeMDCTStereoSID( } /* read bitstream */ - for (i = 0; i < stages; i++) + for ( i = 0; i < stages; i++ ) { - indices[i] = get_next_indice(sts[ch], bits_37bits[i]); + indices[i] = get_next_indice( sts[ch], bits_37bits[i] ); } { - gain[ch] = ((float)get_next_indice(sts[ch], 7) - GAIN_Q_OFFSET_IVAS) / 1.5f; + gain[ch] = ( (float) get_next_indice( sts[ch], 7 ) - GAIN_Q_OFFSET_IVAS ) / 1.5f; } /* MSVQ decoder */ - msvq_dec(cdk_37bits_ivas, NULL, NULL, stages, N, FD_CNG_maxN_37bits, indices, ms_ptr[ch], NULL); + msvq_dec( cdk_37bits_ivas, NULL, NULL, stages, N, FD_CNG_maxN_37bits, indices, ms_ptr[ch], NULL ); } - if (sts[0]->hFdCngDec->hFdCngCom->no_side_flag) + if ( sts[0]->hFdCngDec->hFdCngCom->no_side_flag ) { - set_zero(ms_ptr[1], NPART); + set_zero( ms_ptr[1], NPART ); } - if (is_out_ms == 0) + if ( is_out_ms == 0 ) { - inverseMS(N, ms_ptr[0], ms_ptr[1], 1.f); + inverseMS( N, ms_ptr[0], ms_ptr[1], 1.f ); } - for (ch = 0; ch < CPE_CHANNELS; ch++) + for ( ch = 0; ch < CPE_CHANNELS; ch++ ) { hFdCngCom = sts[ch]->hFdCngDec->hFdCngCom; - for (p = 0; p < N; p++) + for ( p = 0; p < N; p++ ) { - lr_ptr[ch][p] = powf(10.f, (ms_ptr[ch][p] + gain[ch]) / 10.f); + lr_ptr[ch][p] = powf( 10.f, ( ms_ptr[ch][p] + gain[ch] ) / 10.f ); } - scalebands(hFdCngCom->sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, hFdCngCom->stopBand - hFdCngCom->startBand, hFdCngCom->cngNoiseLevel, 1); + scalebands( hFdCngCom->sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, hFdCngCom->stopBand - hFdCngCom->startBand, hFdCngCom->cngNoiseLevel, 1 ); - lpc_from_spectrum(hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, sts[ch]->preemph_fac); + lpc_from_spectrum( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, sts[ch]->preemph_fac ); } - if (hCPE->nchan_out == 1 && hCPE->last_element_brate <= IVAS_SID_4k4) + if ( hCPE->nchan_out == 1 && hCPE->last_element_brate <= IVAS_SID_4k4 ) { /* create proper M noise shape in channel zero after gains have been applied */ - for (p = 0; p < N; p++) + for ( p = 0; p < N; p++ ) { - sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] = 0.5f * (sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] + sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst[p]); + sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] = 0.5f * ( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] + sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst[p] ); } } @@ -4707,70 +4689,70 @@ void FdCngDecodeDiracMDCTStereoSID( { DEC_CORE_HANDLE sts[CPE_CHANNELS]; HANDLE_FD_CNG_COM hFdCngCom; - float* ms_ptr[CPE_CHANNELS]; - float* lr_ptr[CPE_CHANNELS]; + float *ms_ptr[CPE_CHANNELS]; + float *lr_ptr[CPE_CHANNELS]; float logNoiseEst[CPE_CHANNELS][NPART]; float gain[CPE_CHANNELS]; int16_t indices[FD_CNG_stages_37bits]; int16_t N, i, ch, p; - for (ch = 0; ch < CPE_CHANNELS; ch++) + for ( ch = 0; ch < CPE_CHANNELS; ch++ ) { sts[ch] = hCPE->hCoreCoder[ch]; ms_ptr[ch] = &logNoiseEst[ch][0]; lr_ptr[ch] = &sts[ch]->hFdCngDec->hFdCngCom->sidNoiseEst[0]; - (sts[ch]->hFdCngDec)->hFdCngCom->sid_frame_counter++; + ( sts[ch]->hFdCngDec )->hFdCngCom->sid_frame_counter++; } /* decode noise shapes and gains */ - hFdCngCom = (sts[0]->hFdCngDec)->hFdCngCom; + hFdCngCom = ( sts[0]->hFdCngDec )->hFdCngCom; N = hFdCngCom->npart; /* read bitstream */ - for (i = 0; i < FD_CNG_stages_37bits; i++) + for ( i = 0; i < FD_CNG_stages_37bits; i++ ) { - indices[i] = get_next_indice(sts[0], bits_37bits[i]); + indices[i] = get_next_indice( sts[0], bits_37bits[i] ); } - gain[0] = ((float)get_next_indice(sts[0], 7) - GAIN_Q_OFFSET_IVAS) / 1.5f; + gain[0] = ( (float) get_next_indice( sts[0], 7 ) - GAIN_Q_OFFSET_IVAS ) / 1.5f; gain[1] = gain[0]; /* MSVQ decoder */ - msvq_dec(cdk_37bits_ivas, NULL, NULL, FD_CNG_stages_37bits, N, FD_CNG_maxN_37bits, indices, ms_ptr[0], NULL); - mvr2r(ms_ptr[0], ms_ptr[1], N); + msvq_dec( cdk_37bits_ivas, NULL, NULL, FD_CNG_stages_37bits, N, FD_CNG_maxN_37bits, indices, ms_ptr[0], NULL ); + mvr2r( ms_ptr[0], ms_ptr[1], N ); /*inverseMS( N, ms_ptr[0], ms_ptr[1], 1.f );*/ - for (ch = 0; ch < CPE_CHANNELS; ch++) + for ( ch = 0; ch < CPE_CHANNELS; ch++ ) { hFdCngCom = sts[ch]->hFdCngDec->hFdCngCom; - for (p = 0; p < N; p++) + for ( p = 0; p < N; p++ ) { - lr_ptr[ch][p] = powf(10.f, (ms_ptr[ch][p] + gain[ch]) / 10.f); + lr_ptr[ch][p] = powf( 10.f, ( ms_ptr[ch][p] + gain[ch] ) / 10.f ); } /* NB last band energy compensation */ - if (hFdCngCom->CngBandwidth == NB) + if ( hFdCngCom->CngBandwidth == NB ) { lr_ptr[ch][N - 1] *= NB_LAST_BAND_SCALE; } - else if (hFdCngCom->CngBandwidth == SWB && hFdCngCom->CngBitrate <= ACELP_13k20) + else if ( hFdCngCom->CngBandwidth == SWB && hFdCngCom->CngBitrate <= ACELP_13k20 ) { lr_ptr[ch][N - 1] *= SWB_13k2_LAST_BAND_SCALE; } - scalebands(hFdCngCom->sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, hFdCngCom->stopBand - hFdCngCom->startBand, hFdCngCom->cngNoiseLevel, 1); + scalebands( hFdCngCom->sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, hFdCngCom->stopBand - hFdCngCom->startBand, hFdCngCom->cngNoiseLevel, 1 ); - lpc_from_spectrum(hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, sts[ch]->preemph_fac); + lpc_from_spectrum( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, sts[ch]->preemph_fac ); } sts[0]->hFdCngDec->hFdCngCom->coherence = 0.0f; sts[1]->hFdCngDec->hFdCngCom->coherence = 0.0f; - if (hCPE->nchan_out == 1) + if ( hCPE->nchan_out == 1 ) { /* create proper M noise shape in channel zero after gains have been applied */ - for (p = 0; p < N; p++) + for ( p = 0; p < N; p++ ) { - sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] = 0.5f * (sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] + sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst[p]); + sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] = 0.5f * ( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] + sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst[p] ); } sts[0]->hFdCngDec->hFdCngCom->coherence = 0.0f; sts[1]->hFdCngDec->hFdCngCom->coherence = 0.0f; @@ -4778,4 +4760,4 @@ void FdCngDecodeDiracMDCTStereoSID( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/gain_dec_fx.c b/lib_dec/gain_dec_fx.c index 0c686ad6d..dd8b57681 100644 --- a/lib_dec/gain_dec_fx.c +++ b/lib_dec/gain_dec_fx.c @@ -2,11 +2,11 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ /*===========================================================================*/ @@ -30,34 +30,34 @@ /* _ None */ /*===========================================================================*/ void Es_pred_dec_fx( - Word16 *Es_pred, /* o : predicited scaled innovation energy Q8*/ - const Word16 enr_idx, /* i : indice */ - const Word16 nb_bits, /* i : number of bits */ - const Word16 no_ltp /* i : no LTP flag */ + Word16 *Es_pred, /* o : predicited scaled innovation energy Q8*/ + const Word16 enr_idx, /* i : indice */ + const Word16 nb_bits, /* i : number of bits */ + const Word16 no_ltp /* i : no LTP flag */ ) { #ifdef IVAS_GAIN_MOD - PMT("Verify if Es_pred_dec_fx should use noltp parameters") + PMT( "Verify if Es_pred_dec_fx should use noltp parameters" ) #endif - IF(no_ltp == 0) + IF( no_ltp == 0 ) { - SWITCH(nb_bits) + SWITCH( nb_bits ) { - case 5: - *Es_pred = Es_pred_qua_5b_fx[enr_idx]; - move16(); - BREAK; - case 4: - *Es_pred = Es_pred_qua_4b_fx[enr_idx]; - move16(); - BREAK; - case 3: - *Es_pred = Es_pred_qua_3b_fx[enr_idx]; - break; - default: - *Es_pred = Es_pred_qua_5b_fx[enr_idx]; - move16(); - BREAK; + case 5: + *Es_pred = Es_pred_qua_5b_fx[enr_idx]; + move16(); + BREAK; + case 4: + *Es_pred = Es_pred_qua_4b_fx[enr_idx]; + move16(); + BREAK; + case 3: + *Es_pred = Es_pred_qua_3b_fx[enr_idx]; + break; + default: + *Es_pred = Es_pred_qua_5b_fx[enr_idx]; + move16(); + BREAK; } } ELSE @@ -93,10 +93,10 @@ void Es_pred_dec_fx( /*======================================================================================*/ void gain_dec_tc_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 *code_fx, /* i : algebraic code excitation */ - const Word16 i_subfr_fx, /* i : subframe number */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 *code_fx, /* i : algebraic code excitation */ + const Word16 i_subfr_fx, /* i : subframe number */ + const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ Word16 *gain_pit_fx, /* o : pitch gain */ Word32 *gain_code_fx, /* o : Quantized codeebook gain */ Word16 *gain_inov_fx, /* o : unscaled innovation gain */ @@ -108,70 +108,70 @@ void gain_dec_tc_fx( Word16 Ei_fx; Word16 expg, expg2, e_tmp, f_tmp, exp_gcode0, tmp_fx, frac; Word32 L_tmp, L_tmp1; - Word16 wgain_code=0; + Word16 wgain_code = 0; move16(); *gain_pit_fx = 0; move16(); /*----------------------------------------------------------------* - * find number of bits for gain dequantization - *----------------------------------------------------------------*/ - nBits = st_fx->acelp_cfg.gains_mode[shr(i_subfr_fx, 6)]; + * find number of bits for gain dequantization + *----------------------------------------------------------------*/ + nBits = st_fx->acelp_cfg.gains_mode[shr( i_subfr_fx, 6 )]; /*-----------------------------------------------------------------* * calculate the predicted gain code *-----------------------------------------------------------------*/ /*Ecode = (dotp( code, code, L_SUBFR) + 0.01f) / L_SUBFR; - *gain_inov = 1.0f / (float)sqrt( Ecode );*/ - L_tmp = Dot_product12(code_fx, code_fx, L_SUBFR, &expg); - expg = sub(expg, 18 + 6); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ + *gain_inov = 1.0f / (float)sqrt( Ecode );*/ + L_tmp = Dot_product12( code_fx, code_fx, L_SUBFR, &expg ); + expg = sub( expg, 18 + 6 ); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ expg2 = expg; move16(); L_tmp1 = L_tmp; /* sets to 'L_tmp' in 1 clock */ - move32(); - L_tmp = Isqrt_lc(L_tmp, &expg); + move32(); + L_tmp = Isqrt_lc( L_tmp, &expg ); - *gain_inov_fx = extract_h(L_shl(L_tmp, sub(expg, 3))); + *gain_inov_fx = extract_h( L_shl( L_tmp, sub( expg, 3 ) ) ); move16(); /* gain_inov in Q12 */ /* Ei = 10 * (float)log10( Ecode );*/ - e_tmp = norm_l(L_tmp1); - f_tmp = Log2_norm_lc(L_shl(L_tmp1, e_tmp)); - e_tmp = sub(expg2,add(1,e_tmp)); - L_tmp1 = Mpy_32_16(e_tmp, f_tmp, 12330); /* Q13 */ /* 10*log10(2) in Q12*/ - Ei_fx = round_fx(L_shl(L_tmp1, 11)); /* Q8 */ + e_tmp = norm_l( L_tmp1 ); + f_tmp = Log2_norm_lc( L_shl( L_tmp1, e_tmp ) ); + e_tmp = sub( expg2, add( 1, e_tmp ) ); + L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 12330 ); /* Q13 */ /* 10*log10(2) in Q12*/ + Ei_fx = round_fx( L_shl( L_tmp1, 11 ) ); /* Q8 */ /* gcode0 = (float) pow(10, 0.05 * (Es_pred - Ei));*/ - gcode0_fx = sub(Es_pred_fx, Ei_fx); /* Q8 */ + gcode0_fx = sub( Es_pred_fx, Ei_fx ); /* Q8 */ /*-----------------------------------------------------------------* * gcode0 = pow(10.0, gcode0/20) * = pow(2, 3.321928*gcode0/20) * = pow(2, 0.166096*gcode0) *-----------------------------------------------------------------*/ - L_tmp = L_mult(gcode0_fx, 21771); /* *0.166096 in Q17 -> Q26 */ - L_tmp = L_shr(L_tmp, 10); /* From Q26 to Q16 */ - frac = L_Extract_lc(L_tmp, &exp_gcode0); /* Extract exponent of gcode0 */ - gcode0_fx = extract_l(Pow2(14, frac));/* Put 14 as exponent so that */ + L_tmp = L_mult( gcode0_fx, 21771 ); /* *0.166096 in Q17 -> Q26 */ + L_tmp = L_shr( L_tmp, 10 ); /* From Q26 to Q16 */ + frac = L_Extract_lc( L_tmp, &exp_gcode0 ); /* Extract exponent of gcode0 */ + gcode0_fx = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ - exp_gcode0 = sub(exp_gcode0, 14); + exp_gcode0 = sub( exp_gcode0, 14 ); /*------------------------------------------------------------------------------------------* * Select the gain quantization table and dequantize the gain *------------------------------------------------------------------------------------------*/ /* index = (Word16)get_indice( st_fx,"gain_code", i_subfr_fx, ACELP_CORE);move16();*/ - index = (Word16)get_next_indice( st_fx, nBits ); + index = (Word16) get_next_indice( st_fx, nBits ); move16(); - IF( GT_16(nBits,3)) + IF( GT_16( nBits, 3 ) ) { wgain_code = gain_dequant_fx( index, G_CODE_MIN_TC_Q15, G_CODE_MAX_TC_Q0, nBits, &expg ); #ifdef BASOP_NOGLOB wgain_code = shl_sat( wgain_code, add( expg, 13 ) ); /* wgain_code in Q13*/ #else - wgain_code = shl(wgain_code,add(expg,13)); /* wgain_code in Q13*/ + wgain_code = shl( wgain_code, add( expg, 13 ) ); /* wgain_code in Q13*/ #endif } ELSE /* nBits == 3 */ @@ -185,20 +185,20 @@ void gain_dec_tc_fx( *-----------------------------------------------------------------*/ /* *gain_code *= gcode0;*/ - L_tmp = L_mult(wgain_code, gcode0_fx); /* Q13*Q0 -> Q14 */ + L_tmp = L_mult( wgain_code, gcode0_fx ); /* Q13*Q0 -> Q14 */ #ifdef BASOP_NOGLOB *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 2 ) ); #else - *gain_code_fx= L_shl(L_tmp, add(exp_gcode0, 2)); + *gain_code_fx = L_shl( L_tmp, add( exp_gcode0, 2 ) ); #endif move32(); /* Q14 -> Q16 */ /**norm_gain_code = *gain_code / *gain_inov;*/ - expg = sub(norm_s(*gain_inov_fx),1); - expg = s_max(expg, 0); + expg = sub( norm_s( *gain_inov_fx ), 1 ); + expg = s_max( expg, 0 ); - tmp_fx = div_s(shr(8192,expg),*gain_inov_fx); - *norm_gain_code_fx = L_shr(Mult_32_16(*gain_code_fx, tmp_fx),sub(1,expg)); + tmp_fx = div_s( shr( 8192, expg ), *gain_inov_fx ); + *norm_gain_code_fx = L_shr( Mult_32_16( *gain_code_fx, tmp_fx ), sub( 1, expg ) ); move32(); return; @@ -232,10 +232,10 @@ void gain_dec_tc_fx( /*======================================================================================*/ void gain_dec_tc_ivas_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 *code_fx, /* i : algebraic code excitation */ - const Word16 i_subfr_fx, /* i : subframe number */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 *code_fx, /* i : algebraic code excitation */ + const Word16 i_subfr_fx, /* i : subframe number */ + const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ Word16 *gain_pit_fx, /* o : pitch gain */ Word32 *gain_code_fx, /* o : Quantized codeebook gain */ Word16 *gain_inov_fx, /* o : unscaled innovation gain */ @@ -247,71 +247,71 @@ void gain_dec_tc_ivas_fx( Word16 Ei_fx; Word16 expg, expg2, e_tmp, f_tmp, exp_gcode0, tmp_fx, frac; Word32 L_tmp, L_tmp1; - Word16 wgain_code=0; + Word16 wgain_code = 0; move16(); *gain_pit_fx = 0; move16(); /*----------------------------------------------------------------* - * find number of bits for gain dequantization - *----------------------------------------------------------------*/ - nBits = st_fx->acelp_cfg.gains_mode[shr(i_subfr_fx, 6)]; + * find number of bits for gain dequantization + *----------------------------------------------------------------*/ + nBits = st_fx->acelp_cfg.gains_mode[shr( i_subfr_fx, 6 )]; /*-----------------------------------------------------------------* * calculate the predicted gain code *-----------------------------------------------------------------*/ /*Ecode = (dotp( code, code, L_SUBFR) + 0.01f) / L_SUBFR; - *gain_inov = 1.0f / (float)sqrt( Ecode );*/ - L_tmp = Dot_product12(code_fx, code_fx, L_SUBFR, &expg); - expg = sub(expg, 18 + 6); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ + *gain_inov = 1.0f / (float)sqrt( Ecode );*/ + L_tmp = Dot_product12( code_fx, code_fx, L_SUBFR, &expg ); + expg = sub( expg, 18 + 6 ); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ expg2 = expg; move16(); L_tmp1 = L_tmp; /* sets to 'L_tmp' in 1 clock */ - move32(); - L_tmp = Isqrt_lc(L_tmp, &expg); + move32(); + L_tmp = Isqrt_lc( L_tmp, &expg ); - *gain_inov_fx = extract_h(L_shl(L_tmp, sub(expg, 3))); + *gain_inov_fx = extract_h( L_shl( L_tmp, sub( expg, 3 ) ) ); move16(); /* gain_inov in Q12 */ /* Ei = 10 * (float)log10( Ecode );*/ - e_tmp = norm_l(L_tmp1); - f_tmp = Log2_norm_lc(L_shl(L_tmp1, e_tmp)); - e_tmp = sub(expg2,add(1,e_tmp)); - L_tmp1 = Mpy_32_16(e_tmp, f_tmp, 12330); /* Q13 */ /* 10*log10(2) in Q12*/ - Ei_fx = round_fx(L_shl(L_tmp1, 11)); /* Q8 */ + e_tmp = norm_l( L_tmp1 ); + f_tmp = Log2_norm_lc( L_shl( L_tmp1, e_tmp ) ); + e_tmp = sub( expg2, add( 1, e_tmp ) ); + L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 12330 ); /* Q13 */ /* 10*log10(2) in Q12*/ + Ei_fx = round_fx( L_shl( L_tmp1, 11 ) ); /* Q8 */ /* gcode0 = (float) pow(10, 0.05 * (Es_pred - Ei));*/ - gcode0_fx = sub(Es_pred_fx, Ei_fx); /* Q8 */ + gcode0_fx = sub( Es_pred_fx, Ei_fx ); /* Q8 */ /*-----------------------------------------------------------------* * gcode0 = pow(10.0, gcode0/20) * = pow(2, 3.321928*gcode0/20) * = pow(2, 0.166096*gcode0) *-----------------------------------------------------------------*/ - L_tmp = L_mult(gcode0_fx, 21771); /* *0.166096 in Q17 -> Q26 */ - L_tmp = L_shr(L_tmp, 10); /* From Q26 to Q16 */ - frac = L_Extract_lc(L_tmp, &exp_gcode0); /* Extract exponent of gcode0 */ - gcode0_fx = extract_l(Pow2(14, frac));/* Put 14 as exponent so that */ + L_tmp = L_mult( gcode0_fx, 21771 ); /* *0.166096 in Q17 -> Q26 */ + L_tmp = L_shr( L_tmp, 10 ); /* From Q26 to Q16 */ + frac = L_Extract_lc( L_tmp, &exp_gcode0 ); /* Extract exponent of gcode0 */ + gcode0_fx = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ - exp_gcode0 = sub(exp_gcode0, 14); + exp_gcode0 = sub( exp_gcode0, 14 ); /*------------------------------------------------------------------------------------------* * Select the gain quantization table and dequantize the gain *------------------------------------------------------------------------------------------*/ /* index = (Word16)get_indice( st_fx,"gain_code", i_subfr_fx, ACELP_CORE);move16();*/ - index = (Word16)get_next_indice( st_fx, nBits ); + index = (Word16) get_next_indice( st_fx, nBits ); move16(); - IF( GT_16(nBits,3)) + IF( GT_16( nBits, 3 ) ) { wgain_code = gain_dequant_fx( index, G_CODE_MIN_TC_Q15, G_CODE_MAX_TC_Q0, nBits, &expg ); - wgain_code = shl(wgain_code,add(expg,12)); /* wgain_code in Q12*/ + wgain_code = shl( wgain_code, add( expg, 12 ) ); /* wgain_code in Q12*/ } ELSE /* nBits == 3 */ { - wgain_code = shr(tbl_gain_code_tc_fx[index], 1); //Q12 + wgain_code = shr( tbl_gain_code_tc_fx[index], 1 ); // Q12 move16(); } @@ -320,16 +320,16 @@ void gain_dec_tc_ivas_fx( *-----------------------------------------------------------------*/ /* *gain_code *= gcode0;*/ - L_tmp = L_mult(wgain_code, gcode0_fx); /* Q12*Q0 -> Q13 */ - *gain_code_fx= L_shl(L_tmp, add(exp_gcode0, 3)); + L_tmp = L_mult( wgain_code, gcode0_fx ); /* Q12*Q0 -> Q13 */ + *gain_code_fx = L_shl( L_tmp, add( exp_gcode0, 3 ) ); move32(); /* Q13 -> Q16 */ /**norm_gain_code = *gain_code / *gain_inov;*/ - expg = sub(norm_s(*gain_inov_fx),1); - expg = s_max(expg, 0); + expg = sub( norm_s( *gain_inov_fx ), 1 ); + expg = s_max( expg, 0 ); - tmp_fx = div_s(shr(8192,expg),*gain_inov_fx); - *norm_gain_code_fx = L_shr(Mult_32_16(*gain_code_fx, tmp_fx),sub(1,expg)); + tmp_fx = div_s( shr( 8192, expg ), *gain_inov_fx ); + *norm_gain_code_fx = L_shr( Mult_32_16( *gain_code_fx, tmp_fx ), sub( 1, expg ) ); move32(); return; @@ -365,17 +365,17 @@ void gain_dec_tc_ivas_fx( /* _ None */ /*======================================================================================*/ void gain_dec_mless_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 L_frame_fx, /* i : length of the frame */ - const Word16 coder_type, /* i : coding type */ - const Word16 i_subfr_fx, /* i : subframe number */ - const Word16 tc_subfr_fx, /* i : TC subframe index */ - const Word16 *code_fx, /* i : algebraic code excitation */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - Word16 *gain_pit_fx, /* o : Quantized pitch gain Q14*/ - Word32 *gain_code_fx, /* o : Quantized codeebook gain Q16*/ - Word16 *gain_inov_fx, /* o : unscaled innovation gain Q12*/ - Word32 *norm_gain_code_fx /* o : norm. gain of the codebook excitation Q16*/ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 L_frame_fx, /* i : length of the frame */ + const Word16 coder_type, /* i : coding type */ + const Word16 i_subfr_fx, /* i : subframe number */ + const Word16 tc_subfr_fx, /* i : TC subframe index */ + const Word16 *code_fx, /* i : algebraic code excitation */ + const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ + Word16 *gain_pit_fx, /* o : Quantized pitch gain Q14*/ + Word32 *gain_code_fx, /* o : Quantized codeebook gain Q16*/ + Word16 *gain_inov_fx, /* o : unscaled innovation gain Q12*/ + Word32 *norm_gain_code_fx /* o : norm. gain of the codebook excitation Q16*/ ) { Word16 index, nBits; @@ -387,22 +387,22 @@ void gain_dec_mless_fx( /*-----------------------------------------------------------------* * decode pitch gain *-----------------------------------------------------------------*/ - nBits = st_fx->acelp_cfg.gains_mode[shr(i_subfr_fx, 6) ]; + nBits = st_fx->acelp_cfg.gains_mode[shr( i_subfr_fx, 6 )]; test(); test(); test(); test(); test(); - IF( (EQ_16(tc_subfr_fx,3*L_SUBFR )&&EQ_16(i_subfr_fx,3*L_SUBFR)&&EQ_16(L_frame_fx,L_FRAME))|| - (EQ_16(tc_subfr_fx,4*L_SUBFR ) && EQ_16(i_subfr_fx,4*L_SUBFR) && EQ_16(L_frame_fx,L_FRAME16k)) ) + IF( ( EQ_16( tc_subfr_fx, 3 * L_SUBFR ) && EQ_16( i_subfr_fx, 3 * L_SUBFR ) && EQ_16( L_frame_fx, L_FRAME ) ) || + ( EQ_16( tc_subfr_fx, 4 * L_SUBFR ) && EQ_16( i_subfr_fx, 4 * L_SUBFR ) && EQ_16( L_frame_fx, L_FRAME16k ) ) ) { /* decode pitch gain */ - index = (Word16)get_next_indice( st_fx, shr(nBits,1) ); + index = (Word16) get_next_indice( st_fx, shr( nBits, 1 ) ); move16(); - /*Ei = (G_PITCH_MAX_TC192 - G_PITCH_MIN_TC192) / ((1 << (nBits>>1)) - 1);*/ /* set quantization step */ - tmp_fx = div_s(1,sub(shl(1,shr(nBits,1)),1)); /*Q15*/ - Ei_fx = mult_r(G_PITCH_MAX_MINUS_MIN_TC192_Q13,tmp_fx); /*Q13*/ + /*Ei = (G_PITCH_MAX_TC192 - G_PITCH_MIN_TC192) / ((1 << (nBits>>1)) - 1);*/ /* set quantization step */ + tmp_fx = div_s( 1, sub( shl( 1, shr( nBits, 1 ) ), 1 ) ); /*Q15*/ + Ei_fx = mult_r( G_PITCH_MAX_MINUS_MIN_TC192_Q13, tmp_fx ); /*Q13*/ /**gain_pit = usdequant( index, G_PITCH_MIN_TC192, Ei );*/ *gain_pit_fx = usdequant_fx( index, G_PITCH_MIN_TC192_Q14, Ei_fx ); @@ -410,91 +410,91 @@ void gain_dec_mless_fx( /* calculate the predicted gain code */ /*Ecode = (dotp( code, code, L_SUBFR) + 0.01f) / L_SUBFR; - *gain_inov = 1.0f / (float)sqrt( Ecode );*/ - L_tmp = Dot_product12(code_fx, code_fx, L_SUBFR, &expg); - expg = sub(expg, 18 + 6); /* exp: -18 (code in Q12), -6 (/L_SUBFR) */ + *gain_inov = 1.0f / (float)sqrt( Ecode );*/ + L_tmp = Dot_product12( code_fx, code_fx, L_SUBFR, &expg ); + expg = sub( expg, 18 + 6 ); /* exp: -18 (code in Q12), -6 (/L_SUBFR) */ expg2 = expg; move16(); L_tmp1 = L_tmp; /* sets to 'L_tmp' in 1 clock */ - move32(); - L_tmp = Isqrt_lc(L_tmp, &expg); + move32(); + L_tmp = Isqrt_lc( L_tmp, &expg ); - *gain_inov_fx = extract_h(L_shl(L_tmp, sub(expg, 3))); /* gain_inov in Q12 */ + *gain_inov_fx = extract_h( L_shl( L_tmp, sub( expg, 3 ) ) ); /* gain_inov in Q12 */ /*Ei = 10 * (float)log10( Ecode );*/ - e_tmp = norm_l(L_tmp1); - f_tmp = Log2_norm_lc(L_shl(L_tmp1, e_tmp)); - e_tmp = sub(expg2,add(1,e_tmp)); - L_tmp1 = Mpy_32_16(e_tmp, f_tmp, 12330); /* Q13 */ /* 10*log10(2) in Q12*/ - Ei_fx = round_fx(L_shl(L_tmp1, 11)); /* Q8 */ + e_tmp = norm_l( L_tmp1 ); + f_tmp = Log2_norm_lc( L_shl( L_tmp1, e_tmp ) ); + e_tmp = sub( expg2, add( 1, e_tmp ) ); + L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 12330 ); /* Q13 */ /* 10*log10(2) in Q12*/ + Ei_fx = round_fx( L_shl( L_tmp1, 11 ) ); /* Q8 */ /*-----------------------------------------------------------------* * calculate the predicted gain code *-----------------------------------------------------------------*/ /*gcode0 = (float) pow(10, 0.05 * (Es_pred - Ei));*/ - gcode0_fx = sub(Es_pred_fx, Ei_fx); /* Q8 */ + gcode0_fx = sub( Es_pred_fx, Ei_fx ); /* Q8 */ /*-----------------------------------------------------------------* * gcode0 = pow(10.0, gcode0/20) * = pow(2, 3.321928*gcode0/20) * = pow(2, 0.166096*gcode0) *-----------------------------------------------------------------*/ - L_tmp = L_mult(gcode0_fx, 21771); /* *0.166096 in Q17 -> Q26 */ - L_tmp = L_shr(L_tmp, 10); /* From Q26 to Q16 */ - frac = L_Extract_lc(L_tmp, &exp_gcode0); /* Extract exponent of gcode0 */ + L_tmp = L_mult( gcode0_fx, 21771 ); /* *0.166096 in Q17 -> Q26 */ + L_tmp = L_shr( L_tmp, 10 ); /* From Q26 to Q16 */ + frac = L_Extract_lc( L_tmp, &exp_gcode0 ); /* Extract exponent of gcode0 */ - gcode0_fx = extract_l(Pow2(14, frac));/* Put 14 as exponent so that */ + gcode0_fx = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ - exp_gcode0 = sub(exp_gcode0, 14); + exp_gcode0 = sub( exp_gcode0, 14 ); /* decode normalized codebook gain */ /*index = (short)get_indice( st_fx, "gain_code", i_subfr_fx, ACELP_CORE );move16();*/ - index = (Word16)get_next_indice( st_fx, shr(add(nBits,1),1) ); + index = (Word16) get_next_indice( st_fx, shr( add( nBits, 1 ), 1 ) ); move16(); /**gain_code = gain_dequant( index, G_CODE_MIN_TC192, G_CODE_MAX_TC192, (nBits+1)>>1 );*/ - gain_code16 = gain_dequant_fx( index, G_CODE_MIN_TC192_Q15, G_CODE_MAX_TC192_Q0, shr(add(nBits,1),1), &expg ); + gain_code16 = gain_dequant_fx( index, G_CODE_MIN_TC192_Q15, G_CODE_MAX_TC192_Q0, shr( add( nBits, 1 ), 1 ), &expg ); move16(); /**gain_code *= gcode0;*/ - L_tmp = L_mult(gain_code16,gcode0_fx); /*Q0*Q0 -> Q1*/ + L_tmp = L_mult( gain_code16, gcode0_fx ); /*Q0*Q0 -> Q1*/ #ifdef BASOP_NOGLOB *gain_code_fx = L_shl_sat( L_tmp, add( add( expg, exp_gcode0 ), 15 ) ); #else - *gain_code_fx = L_shl(L_tmp,add(add(expg,exp_gcode0),15)); + *gain_code_fx = L_shl( L_tmp, add( add( expg, exp_gcode0 ), 15 ) ); #endif - move32(); /*Q16*/ + move32(); /*Q16*/ } ELSE { - SWITCH ( nBits ) + SWITCH( nBits ) { - case 7: + case 7: { qua_table_fx = gain_qua_mless_7b_fx; move16(); BREAK; } - case 6: + case 6: { qua_table_fx = gain_qua_mless_6b_fx; move16(); - IF (GT_16(st_fx->element_mode, EVS_MONO) ) + IF( GT_16( st_fx->element_mode, EVS_MONO ) ) { - //PMT("gain_qua_mless_6b_stereo to fixed point") + // PMT("gain_qua_mless_6b_stereo to fixed point") qua_table_fx = gain_qua_mless_6b_stereo_fx; } BREAK; } - case 5: + case 5: { qua_table_fx = gain_qua_mless_5b_fx; move16(); BREAK; } - default: + default: { qua_table_fx = gain_qua_mless_6b_fx; move16(); @@ -503,78 +503,78 @@ void gain_dec_mless_fx( } test(); - if( EQ_16(coder_type,INACTIVE)&&EQ_16(nBits,6)) + if ( EQ_16( coder_type, INACTIVE ) && EQ_16( nBits, 6 ) ) { - nBits = sub(nBits, 1); + nBits = sub( nBits, 1 ); } - index = (Word16)get_next_indice( st_fx, nBits ); + index = (Word16) get_next_indice( st_fx, nBits ); move16(); *gain_pit_fx = qua_table_fx[index * 2]; move16(); /*Ecode = (dotp( code, code, L_SUBFR) + 0.01f) / L_SUBFR; - *gain_inov = 1.0f / (float)sqrt( Ecode );*/ + *gain_inov = 1.0f / (float)sqrt( Ecode );*/ - L_tmp = Dot_product12(code_fx, code_fx, L_SUBFR, &expg); - expg = sub(expg, 18 + 6); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ + L_tmp = Dot_product12( code_fx, code_fx, L_SUBFR, &expg ); + expg = sub( expg, 18 + 6 ); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ expg2 = expg; move16(); L_tmp1 = L_tmp; /* sets to 'L_tmp' in 1 clock */ - move32(); - L_tmp = Isqrt_lc(L_tmp, &expg); + move32(); + L_tmp = Isqrt_lc( L_tmp, &expg ); - *gain_inov_fx = extract_h(L_shl(L_tmp, sub(expg, 3))); /* gain_inov in Q12 */ + *gain_inov_fx = extract_h( L_shl( L_tmp, sub( expg, 3 ) ) ); /* gain_inov in Q12 */ /*Ei = 10 * (float)log10( Ecode );*/ - e_tmp = norm_l(L_tmp1); - f_tmp = Log2_norm_lc(L_shl(L_tmp1, e_tmp)); - e_tmp = sub(expg2,add(1,e_tmp)); - L_tmp1 = Mpy_32_16(e_tmp, f_tmp, 12330); /* Q13 */ /* 10*log10(2) in Q12*/ - Ei_fx = round_fx(L_shl(L_tmp1, 11)); /* Q8 */ + e_tmp = norm_l( L_tmp1 ); + f_tmp = Log2_norm_lc( L_shl( L_tmp1, e_tmp ) ); + e_tmp = sub( expg2, add( 1, e_tmp ) ); + L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 12330 ); /* Q13 */ /* 10*log10(2) in Q12*/ + Ei_fx = round_fx( L_shl( L_tmp1, 11 ) ); /* Q8 */ /*-----------------------------------------------------------------* * calculate the predicted gain code *-----------------------------------------------------------------*/ /*gcode0 = (float) pow(10, 0.05 * (Es_pred - Ei));*/ - gcode0_fx = sub(Es_pred_fx, Ei_fx); /* Q8 */ + gcode0_fx = sub( Es_pred_fx, Ei_fx ); /* Q8 */ /*-----------------------------------------------------------------* * gcode0 = pow(10.0, gcode0/20) * = pow(2, 3.321928*gcode0/20) * = pow(2, 0.166096*gcode0) *-----------------------------------------------------------------*/ - L_tmp = L_mult(gcode0_fx, 21771); /* *0.166096 in Q17 -> Q26 */ - L_tmp = L_shr(L_tmp, 10); /* From Q26 to Q16 */ - frac = L_Extract_lc(L_tmp, &exp_gcode0); /* Extract exponent of gcode0 */ + L_tmp = L_mult( gcode0_fx, 21771 ); /* *0.166096 in Q17 -> Q26 */ + L_tmp = L_shr( L_tmp, 10 ); /* From Q26 to Q16 */ + frac = L_Extract_lc( L_tmp, &exp_gcode0 ); /* Extract exponent of gcode0 */ - gcode0_fx = extract_l(Pow2(14, frac));/* Put 14 as exponent so that */ + gcode0_fx = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ - exp_gcode0 = sub(exp_gcode0, 14); + exp_gcode0 = sub( exp_gcode0, 14 ); /*-----------------------------------------------------------------* * decode normalized codebook gain *-----------------------------------------------------------------*/ /**gain_code = qua_table[index * 2 + 1] * gcode0;*/ - L_tmp = L_mult(qua_table_fx[add(shl(index,1),1)] , gcode0_fx); /* Q9*Q0 -> Q10 */ + L_tmp = L_mult( qua_table_fx[add( shl( index, 1 ), 1 )], gcode0_fx ); /* Q9*Q0 -> Q10 */ #ifdef BASOP_NOGLOB *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 6 ) ); #else *gain_code_fx = L_shl( L_tmp, add( exp_gcode0, 6 ) ); #endif - move32(); /* Q10 -> Q16*/ + move32(); /* Q10 -> Q16*/ } /**norm_gain_code = *gain_code / *gain_inov;*/ - expg = sub(norm_s(*gain_inov_fx),1); - expg = s_max(expg, 0); + expg = sub( norm_s( *gain_inov_fx ), 1 ); + expg = s_max( expg, 0 ); - tmp_fx = div_s(shr(8192,expg),*gain_inov_fx); - *norm_gain_code_fx = L_shr(Mult_32_16(*gain_code_fx, tmp_fx),sub(1,expg)); + tmp_fx = div_s( shr( 8192, expg ), *gain_inov_fx ); + *norm_gain_code_fx = L_shr( Mult_32_16( *gain_code_fx, tmp_fx ), sub( 1, expg ) ); move32(); return; @@ -607,82 +607,82 @@ void gain_dec_mless_fx( /* _ None */ /*==================================================================================*/ void gain_dec_lbr_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 coder_type, /* i : coding type */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 *code_fx, /* i : algebraic excitation Q9 */ - Word16 *gain_pit_fx, /* o : quantized pitch gain Q14*/ - Word32 *gain_code_fx, /* o : quantized codebook gain Q16*/ - Word16 *gain_inov_fx, /* o : gain of the innovation (used for normalization) Q12*/ - Word32 *norm_gain_code_fx, /* o : norm. gain of the codebook excitation Q16*/ - Word32 gc_mem[], /* i/o: gain_code from previous subframes */ - Word16 gp_mem[], /* i/o: gain_pitch from previous subframes */ - const Word16 L_subfr /* i : subfr lenght */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 coder_type, /* i : coding type */ + const Word16 i_subfr, /* i : subframe index */ + const Word16 *code_fx, /* i : algebraic excitation Q9 */ + Word16 *gain_pit_fx, /* o : quantized pitch gain Q14*/ + Word32 *gain_code_fx, /* o : quantized codebook gain Q16*/ + Word16 *gain_inov_fx, /* o : gain of the innovation (used for normalization) Q12*/ + Word32 *norm_gain_code_fx, /* o : norm. gain of the codebook excitation Q16*/ + Word32 gc_mem[], /* i/o: gain_code from previous subframes */ + Word16 gp_mem[], /* i/o: gain_pitch from previous subframes */ + const Word16 L_subfr /* i : subfr lenght */ ) { Word16 index, nBits, n_pred, ctype; - Word16 gcode0_fx, aux_fx[10]; + Word16 gcode0_fx, aux_fx[10]; Word32 L_tmp, L_tmp1, L_tmp2; Word16 expg, expg2, e_tmp, exp_gcode0, f_tmp, frac, tmp_fx; - const Word16 *b_fx ,*cdbk_fx = 0; + const Word16 *b_fx, *cdbk_fx = 0; /* Ecode = ( dotp( code, code, L_SUBFR ) + 0.01f ) / L_SUBFR; - *gain_inov = 1.0f / (float)sqrt(Ecode); */ + *gain_inov = 1.0f / (float)sqrt(Ecode); */ Word16 shift_L_subfr; shift_L_subfr = 6; move16(); - IF(GT_16(L_subfr, L_SUBFR)) + IF( GT_16( L_subfr, L_SUBFR ) ) { - shift_L_subfr = add(shift_L_subfr, 1); + shift_L_subfr = add( shift_L_subfr, 1 ); } - L_tmp = Dot_product12(code_fx, code_fx, L_subfr, &expg); - expg = sub(expg, add(18, shift_L_subfr)); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ + L_tmp = Dot_product12( code_fx, code_fx, L_subfr, &expg ); + expg = sub( expg, add( 18, shift_L_subfr ) ); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ expg2 = expg; move16(); L_tmp2 = L_tmp; /* sets to 'L_tmp' in 1 clock */ - move32(); - L_tmp = Isqrt_lc(L_tmp, &expg); + move32(); + L_tmp = Isqrt_lc( L_tmp, &expg ); - *gain_inov_fx = extract_h(L_shl_sat(L_tmp, sub(expg, 3))); /* gain_inov in Q12 */ + *gain_inov_fx = extract_h( L_shl_sat( L_tmp, sub( expg, 3 ) ) ); /* gain_inov in Q12 */ /*-----------------------------------------------------------------* * select the codebook, size and number of bits * set the gains searching range *-----------------------------------------------------------------*/ - nBits = st_fx->acelp_cfg.gains_mode[shr(i_subfr, shift_L_subfr)]; + nBits = st_fx->acelp_cfg.gains_mode[shr( i_subfr, shift_L_subfr )]; move16(); - ctype = shl(sub(coder_type, 1),1); + ctype = shl( sub( coder_type, 1 ), 1 ); /*-----------------------------------------------------------------* * calculate prediction of gcode * search for the best codeword *-----------------------------------------------------------------*/ - IF (i_subfr == 0) + IF( i_subfr == 0 ) { b_fx = b_1sfr_fx; move16(); n_pred = 2; move16(); cdbk_fx = gp_gamma_1sfr_6b_fx; - SWITCH ( nBits ) + SWITCH( nBits ) { - case 8: + case 8: { - cdbk_fx = gp_gamma_1sfr_8b_fx; /* Q14/Q9*/ + cdbk_fx = gp_gamma_1sfr_8b_fx; /* Q14/Q9*/ move16(); BREAK; } - case 7: + case 7: { - cdbk_fx = gp_gamma_1sfr_7b_fx; /* Q14/Q9*/ + cdbk_fx = gp_gamma_1sfr_7b_fx; /* Q14/Q9*/ move16(); BREAK; } - case 6: + case 6: { - cdbk_fx = gp_gamma_1sfr_6b_fx; /* Q14/Q9*/ + cdbk_fx = gp_gamma_1sfr_6b_fx; /* Q14/Q9*/ move16(); BREAK; } @@ -691,22 +691,22 @@ void gain_dec_lbr_fx( /* calculate predicted gain */ aux_fx[0] = 4096; move16(); - aux_fx[1] = shl(ctype,12); + aux_fx[1] = shl( ctype, 12 ); /* gcode0 = (float)pow(10, dotp(b, aux, n_pred) - 0.5f * (float)log10(Ecode)); gcode0 = (float)pow(10, dotp(b, aux, n_pred) - 0.05f * 10 * (float)log10(Ecode)); gcode0 = (float)pow(10, 0.05(20 * dotp(b, aux, n_pred) - 10 * (float)log10(Ecode))); */ - e_tmp = norm_l(L_tmp2); - f_tmp = Log2_norm_lc(L_shl(L_tmp2, e_tmp)); - e_tmp = sub(expg2,add(1,e_tmp)); - L_tmp1 = Mpy_32_16(e_tmp, f_tmp, 12330); /* Q13 */ /* 10*log10(2) in Q12*/ + e_tmp = norm_l( L_tmp2 ); + f_tmp = Log2_norm_lc( L_shl( L_tmp2, e_tmp ) ); + e_tmp = sub( expg2, add( 1, e_tmp ) ); + L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 12330 ); /* Q13 */ /* 10*log10(2) in Q12*/ - L_tmp = Dot_product(b_fx, aux_fx, n_pred); /*Q25*/ - L_tmp = Mult_32_16(L_tmp,160);/*Q13, 20 in Q3*/ - L_tmp = L_sub(L_tmp,L_tmp1);/*Q13*/ + L_tmp = Dot_product( b_fx, aux_fx, n_pred ); /*Q25*/ + L_tmp = Mult_32_16( L_tmp, 160 ); /*Q13, 20 in Q3*/ + L_tmp = L_sub( L_tmp, L_tmp1 ); /*Q13*/ - gcode0_fx = round_fx(L_shl(L_tmp, 11)); /* Q8 */ + gcode0_fx = round_fx( L_shl( L_tmp, 11 ) ); /* Q8 */ /*-----------------------------------------------------------------* @@ -715,37 +715,37 @@ void gain_dec_lbr_fx( * = pow(2, 0.166096*gcode0) *-----------------------------------------------------------------*/ - L_tmp = L_mult(gcode0_fx, 21771); /* *0.166096 in Q17 -> Q26 */ - L_tmp = L_shr(L_tmp, 10); /* From Q26 to Q16 */ - frac = L_Extract_lc(L_tmp, &exp_gcode0); /* Extract exponent of gcode0 */ + L_tmp = L_mult( gcode0_fx, 21771 ); /* *0.166096 in Q17 -> Q26 */ + L_tmp = L_shr( L_tmp, 10 ); /* From Q26 to Q16 */ + frac = L_Extract_lc( L_tmp, &exp_gcode0 ); /* Extract exponent of gcode0 */ - gcode0_fx = extract_l(Pow2(14, frac));/* Put 14 as exponent so that */ + gcode0_fx = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ - exp_gcode0 = sub(exp_gcode0, 14); + exp_gcode0 = sub( exp_gcode0, 14 ); /* retrieve the codebook index and calculate both gains */ /*index = (Word16)get_indice( st_fx,"gain", i_subfr, ACELP_CORE);move16();*/ - index = (Word16)get_next_indice( st_fx, nBits ); + index = (Word16) get_next_indice( st_fx, nBits ); move16(); *gain_pit_fx = cdbk_fx[index * 2]; move16(); - L_tmp = L_mult(cdbk_fx[add(shl(index,1),1)] , gcode0_fx); /* Q9*Q0 -> Q10 */ + L_tmp = L_mult( cdbk_fx[add( shl( index, 1 ), 1 )], gcode0_fx ); /* Q9*Q0 -> Q10 */ #ifdef BASOP_NOGLOB *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 6 ) ); #else - *gain_code_fx = L_shl(L_tmp, add(exp_gcode0, 6)); + *gain_code_fx = L_shl( L_tmp, add( exp_gcode0, 6 ) ); #endif - move16(); /* Q10 -> Q16*/ + move16(); /* Q10 -> Q16*/ gc_mem[0] = *gain_code_fx; - move32(); /*Q16*/ + move32(); /*Q16*/ gp_mem[0] = *gain_pit_fx; - move16(); /*Q14*/ + move16(); /*Q14*/ } - ELSE IF (EQ_16(i_subfr,L_SUBFR) || EQ_16(L_subfr, 2*L_SUBFR)) + ELSE IF( EQ_16( i_subfr, L_SUBFR ) || EQ_16( L_subfr, 2 * L_SUBFR ) ) { b_fx = b_2sfr_fx; move16(); @@ -753,17 +753,17 @@ void gain_dec_lbr_fx( move16(); cdbk_fx = gp_gamma_1sfr_6b_fx; - SWITCH ( nBits ) + SWITCH( nBits ) { - case 7: + case 7: { - cdbk_fx = gp_gamma_2sfr_7b_fx; /* Q14/Q9*/ + cdbk_fx = gp_gamma_2sfr_7b_fx; /* Q14/Q9*/ move16(); BREAK; } - case 6: + case 6: { - cdbk_fx = gp_gamma_2sfr_6b_fx; /* Q14/Q9*/ + cdbk_fx = gp_gamma_2sfr_6b_fx; /* Q14/Q9*/ move16(); BREAK; } @@ -772,53 +772,53 @@ void gain_dec_lbr_fx( /* calculate predicted gain */ aux_fx[0] = 4096; move16(); - aux_fx[1] = shl(ctype,12); + aux_fx[1] = shl( ctype, 12 ); /*aux_fx[2] = (float)log10(gc_mem[0]); = log2(gc_mem[0])*log10(2);*/ - e_tmp = norm_l(gc_mem[0]); - f_tmp = Log2_norm_lc(L_shl(gc_mem[0], e_tmp)); - e_tmp = sub(sub(30,e_tmp),16); /*Q_format(gc_mem[0])=16*/ - L_tmp1 = Mpy_32_16(e_tmp, f_tmp, 9864); /* Q16 */ - aux_fx[2] = round_fx(L_shl(L_tmp1, 12)); /* Q12 */ + e_tmp = norm_l( gc_mem[0] ); + f_tmp = Log2_norm_lc( L_shl( gc_mem[0], e_tmp ) ); + e_tmp = sub( sub( 30, e_tmp ), 16 ); /*Q_format(gc_mem[0])=16*/ + L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 9864 ); /* Q16 */ + aux_fx[2] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ - aux_fx[3] = shr(gp_mem[0],2); /*Q12*/ + aux_fx[3] = shr( gp_mem[0], 2 ); /*Q12*/ /*-----------------------------------------------------------------* * gcode0 = pow(10.0, dotp(b, aux, n_pred) * = pow(2, 3.321928*dotp(b, aux, n_pred) *-----------------------------------------------------------------*/ - L_tmp = Dot_product(b_fx, aux_fx, n_pred); /*Q25*/ - L_tmp = Mult_32_16(L_tmp, 27213); /* *3.321928 in Q13 -> Q23 */ - L_tmp = L_shr(L_tmp, 7); /* From Q23 to Q16 */ - frac = L_Extract_lc(L_tmp, &exp_gcode0); /* Extract exponent of gcode0 */ + L_tmp = Dot_product( b_fx, aux_fx, n_pred ); /*Q25*/ + L_tmp = Mult_32_16( L_tmp, 27213 ); /* *3.321928 in Q13 -> Q23 */ + L_tmp = L_shr( L_tmp, 7 ); /* From Q23 to Q16 */ + frac = L_Extract_lc( L_tmp, &exp_gcode0 ); /* Extract exponent of gcode0 */ - gcode0_fx = extract_l(Pow2(14, frac));/* Put 14 as exponent so that */ + gcode0_fx = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ - exp_gcode0 = sub(exp_gcode0, 14); + exp_gcode0 = sub( exp_gcode0, 14 ); /* retrieve the codebook index and calculate both gains */ - index = (Word16)get_next_indice( st_fx, nBits ); + index = (Word16) get_next_indice( st_fx, nBits ); move16(); *gain_pit_fx = cdbk_fx[index * 2]; move16(); - L_tmp = L_mult(cdbk_fx[add(shl(index,1),1)] , gcode0_fx); /* Q9*Q0 -> Q10 */ + L_tmp = L_mult( cdbk_fx[add( shl( index, 1 ), 1 )], gcode0_fx ); /* Q9*Q0 -> Q10 */ #ifdef BASOP_NOGLOB *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 6 ) ); #else *gain_code_fx = L_shl( L_tmp, add( exp_gcode0, 6 ) ); #endif - move16(); /* Q10 -> Q16*/ + move16(); /* Q10 -> Q16*/ gc_mem[1] = *gain_code_fx; move32(); gp_mem[1] = *gain_pit_fx; move16(); } - ELSE IF (EQ_16(i_subfr,2*L_SUBFR)) + ELSE IF( EQ_16( i_subfr, 2 * L_SUBFR ) ) { b_fx = b_3sfr_fx; move16(); @@ -827,73 +827,73 @@ void gain_dec_lbr_fx( cdbk_fx = gp_gamma_3sfr_6b_fx; - IF(EQ_16(nBits, 7)) + IF( EQ_16( nBits, 7 ) ) { cdbk_fx = gp_gamma_3sfr_7b_fx; - //PMT("verify if gp_gamma_3sfr_7b_fx is correct") + // PMT("verify if gp_gamma_3sfr_7b_fx is correct") } - move16(); /* Q14/Q9*/ + move16(); /* Q14/Q9*/ /* calculate predicted gain */ aux_fx[0] = 4096; move16(); - aux_fx[1] = shl(ctype,12); + aux_fx[1] = shl( ctype, 12 ); move16(); /*aux_fx[2] = (float)log10(gc_mem[0]); = log2(gc_mem[0])*log10(2);*/ - e_tmp = norm_l(gc_mem[0]); - f_tmp = Log2_norm_lc(L_shl(gc_mem[0], e_tmp)); - e_tmp = sub(sub(30,e_tmp),16); /*Q_format(gc_mem[0])=16*/ - L_tmp1 = Mpy_32_16(e_tmp, f_tmp, 9864); /* Q16 */ - aux_fx[2] = round_fx(L_shl(L_tmp1, 12)); /* Q12 */ + e_tmp = norm_l( gc_mem[0] ); + f_tmp = Log2_norm_lc( L_shl( gc_mem[0], e_tmp ) ); + e_tmp = sub( sub( 30, e_tmp ), 16 ); /*Q_format(gc_mem[0])=16*/ + L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 9864 ); /* Q16 */ + aux_fx[2] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ /*aux[3] = (float)log10(gc_mem[1]); = log2(gc_mem[1])*log10(2);*/ - e_tmp = norm_l(gc_mem[1]); - f_tmp = Log2_norm_lc(L_shl(gc_mem[1], e_tmp)); - e_tmp = sub(sub(30,e_tmp),16); /*Q_format(gc_mem[1])=16*/ - L_tmp1 = Mpy_32_16(e_tmp, f_tmp, 9864); /* Q16 */ - aux_fx[3] = round_fx(L_shl(L_tmp1, 12)); /* Q12 */ + e_tmp = norm_l( gc_mem[1] ); + f_tmp = Log2_norm_lc( L_shl( gc_mem[1], e_tmp ) ); + e_tmp = sub( sub( 30, e_tmp ), 16 ); /*Q_format(gc_mem[1])=16*/ + L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 9864 ); /* Q16 */ + aux_fx[3] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ - aux_fx[4] = shr(gp_mem[0],2); + aux_fx[4] = shr( gp_mem[0], 2 ); move16(); - aux_fx[5] = shr(gp_mem[1],2); + aux_fx[5] = shr( gp_mem[1], 2 ); move16(); /*-----------------------------------------------------------------* * gcode0 = pow(10.0, dotp(b, aux, n_pred) * = pow(2, 3.321928*dotp(b, aux, n_pred) *-----------------------------------------------------------------*/ - L_tmp = Dot_product(b_fx, aux_fx, n_pred); /*Q25*/ - L_tmp = Mult_32_16(L_tmp, 27213); /* *3.321928 in Q13 -> Q23 */ - L_tmp = L_shr(L_tmp, 7); /* From Q23 to Q16 */ - frac = L_Extract_lc(L_tmp, &exp_gcode0); /* Extract exponent of gcode0 */ + L_tmp = Dot_product( b_fx, aux_fx, n_pred ); /*Q25*/ + L_tmp = Mult_32_16( L_tmp, 27213 ); /* *3.321928 in Q13 -> Q23 */ + L_tmp = L_shr( L_tmp, 7 ); /* From Q23 to Q16 */ + frac = L_Extract_lc( L_tmp, &exp_gcode0 ); /* Extract exponent of gcode0 */ - gcode0_fx = extract_l(Pow2(14, frac));/* Put 14 as exponent so that */ + gcode0_fx = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ - exp_gcode0 = sub(exp_gcode0, 14); + exp_gcode0 = sub( exp_gcode0, 14 ); /* retrieve the codebook index and calculate both gains */ - index = (Word16)get_next_indice( st_fx, nBits ); + index = (Word16) get_next_indice( st_fx, nBits ); move16(); *gain_pit_fx = cdbk_fx[index * 2]; move16(); - L_tmp = L_mult(cdbk_fx[add(shl(index,1),1)] , gcode0_fx); /* Q9*Q0 -> Q10 */ + L_tmp = L_mult( cdbk_fx[add( shl( index, 1 ), 1 )], gcode0_fx ); /* Q9*Q0 -> Q10 */ #ifdef BASOP_NOGLOB *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 6 ) ); /* Q10 -> Q16*/ #else - *gain_code_fx = L_shl(L_tmp, add(exp_gcode0, 6)); /* Q10 -> Q16*/ + *gain_code_fx = L_shl( L_tmp, add( exp_gcode0, 6 ) ); /* Q10 -> Q16*/ #endif gc_mem[2] = *gain_code_fx; move32(); gp_mem[2] = *gain_pit_fx; move16(); } - ELSE IF (EQ_16(i_subfr,3*L_SUBFR)) + ELSE IF( EQ_16( i_subfr, 3 * L_SUBFR ) ) { b_fx = b_4sfr_fx; move16(); @@ -903,10 +903,10 @@ void gain_dec_lbr_fx( cdbk_fx = gp_gamma_4sfr_6b_fx; #ifdef IVAS_GAIN_MOD - IF(EQ_16(nBits, 7)) + IF( EQ_16( nBits, 7 ) ) { cdbk_fx = gp_gamma_4sfr_7b_fx; - PMT("verify if gp_gamma_4sfr_7b_fx is correct") + PMT( "verify if gp_gamma_4sfr_7b_fx is correct" ) } #endif move16(); /* Q14/Q9*/ @@ -914,72 +914,75 @@ void gain_dec_lbr_fx( /* calculate predicted gain */ aux_fx[0] = 4096; move16(); - aux_fx[1] = shl(ctype,12); + aux_fx[1] = shl( ctype, 12 ); move16(); /*aux[2] = (float)log10(gc_mem[0]); = log2(gc_mem[0])*log10(2);*/ - e_tmp = norm_l(gc_mem[0]); - f_tmp = Log2_norm_lc(L_shl(gc_mem[0], e_tmp)); - e_tmp = sub(sub(30,e_tmp),16); /*Q_format(gc_mem[0])=16*/ - L_tmp1 = Mpy_32_16(e_tmp, f_tmp, 9864); /* Q16 */ - aux_fx[2] = round_fx(L_shl(L_tmp1, 12)); /* Q12 */ + e_tmp = norm_l( gc_mem[0] ); + f_tmp = Log2_norm_lc( L_shl( gc_mem[0], e_tmp ) ); + e_tmp = sub( sub( 30, e_tmp ), 16 ); /*Q_format(gc_mem[0])=16*/ + L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 9864 ); /* Q16 */ + aux_fx[2] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ /*aux[3] = (float)log10(gc_mem[1]); = log2(gc_mem[1])*log10(2);*/ - e_tmp = norm_l(gc_mem[1]); - f_tmp = Log2_norm_lc(L_shl(gc_mem[1], e_tmp)); - e_tmp = sub(sub(30,e_tmp),16); /*Q_format(gc_mem[1])=16*/ - L_tmp1 = Mpy_32_16(e_tmp, f_tmp, 9864); /* Q16 */ - aux_fx[3] = round_fx(L_shl(L_tmp1, 12)); /* Q12 */ + e_tmp = norm_l( gc_mem[1] ); + f_tmp = Log2_norm_lc( L_shl( gc_mem[1], e_tmp ) ); + e_tmp = sub( sub( 30, e_tmp ), 16 ); /*Q_format(gc_mem[1])=16*/ + L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 9864 ); /* Q16 */ + aux_fx[3] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ /*aux[4] = (float)log10(gc_mem[2]); = log2(gc_mem[2])*log10(2);*/ - e_tmp = norm_l(gc_mem[2]); - f_tmp = Log2_norm_lc(L_shl(gc_mem[2], e_tmp)); - e_tmp = sub(sub(30,e_tmp),16); /*Q_format(gc_mem[2])=16*/ - L_tmp1 = Mpy_32_16(e_tmp, f_tmp, 9864); /* Q16 */ - aux_fx[4] = round_fx(L_shl(L_tmp1, 12)); /* Q12 */ + e_tmp = norm_l( gc_mem[2] ); + f_tmp = Log2_norm_lc( L_shl( gc_mem[2], e_tmp ) ); + e_tmp = sub( sub( 30, e_tmp ), 16 ); /*Q_format(gc_mem[2])=16*/ + L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 9864 ); /* Q16 */ + aux_fx[4] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ - aux_fx[5] = shr(gp_mem[0],2);/*Q12*/ move16(); - aux_fx[6] = shr(gp_mem[1],2);/*Q12*/ move16(); - aux_fx[7] = shr(gp_mem[2],2);/*Q12*/ move16(); + aux_fx[5] = shr( gp_mem[0], 2 ); /*Q12*/ + move16(); + aux_fx[6] = shr( gp_mem[1], 2 ); /*Q12*/ + move16(); + aux_fx[7] = shr( gp_mem[2], 2 ); /*Q12*/ + move16(); /*-----------------------------------------------------------------* * gcode0 = pow(10.0, dotp(b, aux, n_pred) * = pow(2, 3.321928*dotp(b, aux, n_pred) *-----------------------------------------------------------------*/ - L_tmp = Dot_product(b_fx, aux_fx, n_pred); /*Q25*/ - L_tmp = Mult_32_16(L_tmp, 27213); /* *3.321928 in Q13 -> Q23 */ - L_tmp = L_shr(L_tmp, 7); /* From Q23 to Q16 */ - frac = L_Extract_lc(L_tmp, &exp_gcode0); /* Extract exponent of gcode0 */ + L_tmp = Dot_product( b_fx, aux_fx, n_pred ); /*Q25*/ + L_tmp = Mult_32_16( L_tmp, 27213 ); /* *3.321928 in Q13 -> Q23 */ + L_tmp = L_shr( L_tmp, 7 ); /* From Q23 to Q16 */ + frac = L_Extract_lc( L_tmp, &exp_gcode0 ); /* Extract exponent of gcode0 */ - gcode0_fx = extract_l(Pow2(14, frac));/* Put 14 as exponent so that */ + gcode0_fx = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ - exp_gcode0 = sub(exp_gcode0, 14); + exp_gcode0 = sub( exp_gcode0, 14 ); /* retrieve the codebook index and calculate both gains */ - index = (Word16)get_next_indice( st_fx, nBits ); + index = (Word16) get_next_indice( st_fx, nBits ); move16(); *gain_pit_fx = cdbk_fx[index * 2]; move16(); - L_tmp = L_mult(cdbk_fx[add(shl(index,1),1)] , gcode0_fx); /* Q9*Q0 -> Q10 */ + L_tmp = L_mult( cdbk_fx[add( shl( index, 1 ), 1 )], gcode0_fx ); /* Q9*Q0 -> Q10 */ #ifdef BASOP_NOGLOB *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 6 ) ); #else - *gain_code_fx = L_shl(L_tmp, add(exp_gcode0, 6)); + *gain_code_fx = L_shl( L_tmp, add( exp_gcode0, 6 ) ); #endif - move32(); /* Q10 -> Q16*/ + move32(); /* Q10 -> Q16*/ } /* *norm_gain_code = *gain_code / *gain_inov; */ - expg = sub(norm_s(*gain_inov_fx),1); - expg = s_max(expg, 0); + expg = sub( norm_s( *gain_inov_fx ), 1 ); + expg = s_max( expg, 0 ); - tmp_fx = div_s(shr(8192,expg),*gain_inov_fx); - *norm_gain_code_fx = L_shr(Mult_32_16(*gain_code_fx, tmp_fx),sub(1,expg)); + tmp_fx = div_s( shr( 8192, expg ), *gain_inov_fx ); + *norm_gain_code_fx = L_shr( Mult_32_16( *gain_code_fx, tmp_fx ), sub( 1, expg ) ); move32(); return; @@ -1014,100 +1017,99 @@ void gain_dec_lbr_fx( void lp_gain_updt_fx( - const Word16 i_subfr, /* i : subframe number Q0 */ - const Word16 gain_pit, /* i : Decoded gain pitch Q14 */ - const Word32 norm_gain_code, /* i : Normalised gain code Q16 */ - Word16 *lp_gainp, /* i/o: LP-filtered pitch gain(FEC) Q14 */ - Word16 *lp_gainc, /* i/o: LP-filtered code gain (FEC) Q3 */ - const Word16 L_frame /* i : length of the frame */ + const Word16 i_subfr, /* i : subframe number Q0 */ + const Word16 gain_pit, /* i : Decoded gain pitch Q14 */ + const Word32 norm_gain_code, /* i : Normalised gain code Q16 */ + Word16 *lp_gainp, /* i/o: LP-filtered pitch gain(FEC) Q14 */ + Word16 *lp_gainc, /* i/o: LP-filtered code gain (FEC) Q3 */ + const Word16 L_frame /* i : length of the frame */ ) { Word16 tmp; #ifdef BASOP_NOGLOB - tmp = extract_h(L_shl_sat(norm_gain_code, 3)); /*(16+3)-16 -> Q3*/ + tmp = extract_h( L_shl_sat( norm_gain_code, 3 ) ); /*(16+3)-16 -> Q3*/ #else - tmp = extract_h(L_shl(norm_gain_code,3)); /*(16+3)-16 -> Q3*/ + tmp = extract_h( L_shl( norm_gain_code, 3 ) ); /*(16+3)-16 -> Q3*/ #endif - IF( EQ_16(L_frame,L_FRAME)) + IF( EQ_16( L_frame, L_FRAME ) ) { - IF(i_subfr == 0) + IF( i_subfr == 0 ) { - *lp_gainp = mult(3277,gain_pit); - move16(); /*0.1 in Q15 = 3277 , (15+14)-15 -> Q14*/ - *lp_gainc = mult_r(3277,tmp); - move16(); /* (15+3)-15 -> Q3*/ + *lp_gainp = mult( 3277, gain_pit ); + move16(); /*0.1 in Q15 = 3277 , (15+14)-15 -> Q14*/ + *lp_gainc = mult_r( 3277, tmp ); + move16(); /* (15+3)-15 -> Q3*/ } - ELSE IF( EQ_16(i_subfr,L_SUBFR)) + ELSE IF( EQ_16( i_subfr, L_SUBFR ) ) { - *lp_gainp = add(*lp_gainp, mult(6554, gain_pit)); - move16(); /*Q14 (0.2 in Q15 = 6554)*/ - *lp_gainc = mac_r(L_deposit_h(*lp_gainc), 6554, tmp); - move16(); /*Q3*/ + *lp_gainp = add( *lp_gainp, mult( 6554, gain_pit ) ); + move16(); /*Q14 (0.2 in Q15 = 6554)*/ + *lp_gainc = mac_r( L_deposit_h( *lp_gainc ), 6554, tmp ); + move16(); /*Q3*/ } - ELSE IF( EQ_16(i_subfr,2*L_SUBFR)) + ELSE IF( EQ_16( i_subfr, 2 * L_SUBFR ) ) { - *lp_gainp = add( *lp_gainp, mult(9830, gain_pit)); - move16(); /*Q14 (0.3 in Q15 = 9830)*/ - *lp_gainc = mac_r(L_deposit_h(*lp_gainc), 9830, tmp); - move16(); /*Q3*/ + *lp_gainp = add( *lp_gainp, mult( 9830, gain_pit ) ); + move16(); /*Q14 (0.3 in Q15 = 9830)*/ + *lp_gainc = mac_r( L_deposit_h( *lp_gainc ), 9830, tmp ); + move16(); /*Q3*/ } - ELSE /* i_subfr == 3*L_SUBFR */ + ELSE /* i_subfr == 3*L_SUBFR */ { - *lp_gainp = add( *lp_gainp, mult(13107, gain_pit)); - move16(); /*Q14 (0.4 in Q15 = 13107)*/ + *lp_gainp = add( *lp_gainp, mult( 13107, gain_pit ) ); + move16(); /*Q14 (0.4 in Q15 = 13107)*/ #ifdef BASOP_NOGLOB - *lp_gainc = mac_r_sat(L_deposit_h(*lp_gainc), 13107, tmp); + *lp_gainc = mac_r_sat( L_deposit_h( *lp_gainc ), 13107, tmp ); #else - *lp_gainc = mac_r(L_deposit_h(*lp_gainc), 13107, tmp); + *lp_gainc = mac_r( L_deposit_h( *lp_gainc ), 13107, tmp ); #endif - move16(); /*Q3*/ + move16(); /*Q3*/ } } ELSE { IF( i_subfr == 0 ) { - *lp_gainp = mult(2185,gain_pit); - move16(); /*(1.0/15.0) in Q15 = 2185 , (15+14)-15 -> Q14*/ - *lp_gainc = mult_r(2185,tmp); - move16(); /* (15+3)-15 -> Q3*/ + *lp_gainp = mult( 2185, gain_pit ); + move16(); /*(1.0/15.0) in Q15 = 2185 , (15+14)-15 -> Q14*/ + *lp_gainc = mult_r( 2185, tmp ); + move16(); /* (15+3)-15 -> Q3*/ } - ELSE IF( EQ_16(i_subfr,L_SUBFR )) + ELSE IF( EQ_16( i_subfr, L_SUBFR ) ) { - *lp_gainp = add(*lp_gainp, mult(4369, gain_pit)); - move16(); /*Q14 (2.0/15.0 in Q15 = 4369)*/ - *lp_gainc = mac_r(L_deposit_h(*lp_gainc), 4369, tmp); - move16(); /*Q3*/ + *lp_gainp = add( *lp_gainp, mult( 4369, gain_pit ) ); + move16(); /*Q14 (2.0/15.0 in Q15 = 4369)*/ + *lp_gainc = mac_r( L_deposit_h( *lp_gainc ), 4369, tmp ); + move16(); /*Q3*/ } - ELSE IF( EQ_16(i_subfr,2*L_SUBFR)) + ELSE IF( EQ_16( i_subfr, 2 * L_SUBFR ) ) { - *lp_gainp = add(*lp_gainp, mult(6554, gain_pit)); - move16(); /*Q14 (3.0/15.0 in Q15 = 6554)*/ - *lp_gainc = mac_r(L_deposit_h(*lp_gainc), 6554, tmp); - move16(); /*Q3*/ + *lp_gainp = add( *lp_gainp, mult( 6554, gain_pit ) ); + move16(); /*Q14 (3.0/15.0 in Q15 = 6554)*/ + *lp_gainc = mac_r( L_deposit_h( *lp_gainc ), 6554, tmp ); + move16(); /*Q3*/ } - ELSE IF( EQ_16(i_subfr,3*L_SUBFR)) + ELSE IF( EQ_16( i_subfr, 3 * L_SUBFR ) ) { - *lp_gainp = add(*lp_gainp, mult(8738, gain_pit)); - move16(); /*Q14 (4.0/15.0 in Q15 = 8738)*/ - *lp_gainc = mac_r(L_deposit_h(*lp_gainc), 8738, tmp); - move16(); /*Q3*/ + *lp_gainp = add( *lp_gainp, mult( 8738, gain_pit ) ); + move16(); /*Q14 (4.0/15.0 in Q15 = 8738)*/ + *lp_gainc = mac_r( L_deposit_h( *lp_gainc ), 8738, tmp ); + move16(); /*Q3*/ } - ELSE /* i_subfr == 4*L_SUBFR */ + ELSE /* i_subfr == 4*L_SUBFR */ { - *lp_gainp = add(*lp_gainp, mult(10923, gain_pit)); - move16(); /*Q14 (5.0/15.0 in Q15 = 10923)*/ + *lp_gainp = add( *lp_gainp, mult( 10923, gain_pit ) ); + move16(); /*Q14 (5.0/15.0 in Q15 = 10923)*/ #ifdef BASOP_NOGLOB - *lp_gainc = mac_r_sat(L_deposit_h(*lp_gainc), 10923, tmp); + *lp_gainc = mac_r_sat( L_deposit_h( *lp_gainc ), 10923, tmp ); #else - *lp_gainc = mac_r(L_deposit_h(*lp_gainc), 10923, tmp); + *lp_gainc = mac_r( L_deposit_h( *lp_gainc ), 10923, tmp ); #endif - move16(); /*Q3*/ + move16(); /*Q3*/ } } return; - } /*-------------------------------------------------* @@ -1115,13 +1117,13 @@ void lp_gain_updt_fx( * * Decode gains of purely unvoiced sounds *-------------------------------------------------*/ -Word32 gain_dec_gaus_fx( /* o : quantized codebook gain Q16 */ - Word16 index, /* i : quantization index */ - const Word16 bits, /* i : number of bits to quantize */ - const Word16 lowBound, /* i : lower bound of quantizer (dB) */ - const Word16 topBound, /* i : upper bound of quantizer (dB) */ - const Word16 inv_gain_inov, /* o : unscaled innovation gain Q12 */ - Word32 *L_norm_gain_code /* o : gain of normalized gaussian excitation Q16 */ +Word32 gain_dec_gaus_fx( /* o : quantized codebook gain Q16 */ + Word16 index, /* i : quantization index */ + const Word16 bits, /* i : number of bits to quantize */ + const Word16 lowBound, /* i : lower bound of quantizer (dB) */ + const Word16 topBound, /* i : upper bound of quantizer (dB) */ + const Word16 inv_gain_inov, /* o : unscaled innovation gain Q12 */ + Word32 *L_norm_gain_code /* o : gain of normalized gaussian excitation Q16 */ ) { Word16 stepSize, gain, expg, frac, expi, tmp_igi; @@ -1131,16 +1133,16 @@ Word32 gain_dec_gaus_fx( /* o : quantized codebook gain * Quantize linearly the log E *------------------------------------------------------------------------------------------*/ - stepSize = shl(sub(topBound,lowBound),sub(14, bits)); /* Q14 */ + stepSize = shl( sub( topBound, lowBound ), sub( 14, bits ) ); /* Q14 */ /*------------------------------------------------------------------------------------------* * Gaussian codebook gain *------------------------------------------------------------------------------------------*/ /* enr_q = (float)index*stepSize ,lowBound); */ - L_enr_q = L_mult(index, stepSize); /* Q0 * Q14 -> Q15 */ - L_enr_q = L_shl(L_enr_q, 9); /* Q15 -> Q24 */ - L_enr_q = L_add(L_enr_q, L_shl(L_deposit_h(lowBound),8)); /* Q24 */ + L_enr_q = L_mult( index, stepSize ); /* Q0 * Q14 -> Q15 */ + L_enr_q = L_shl( L_enr_q, 9 ); /* Q15 -> Q24 */ + L_enr_q = L_add( L_enr_q, L_shl( L_deposit_h( lowBound ), 8 ) ); /* Q24 */ /*------------------------------------------------------------* * gain = pow(10.0, enr/20) @@ -1149,48 +1151,50 @@ Word32 gain_dec_gaus_fx( /* o : quantized codebook gain *------------------------------------------------------------*/ /* gain = (float)pow( 10.0f, enr/20.0f ); quantized codebook gain */ - L_tmp = Mult_32_16(L_enr_q, 21771); /* *0.166096 in Q17 -> Q26 */ - L_tmp = L_shr(L_tmp, 10); /* From Q26 to Q16 */ - frac = L_Extract_lc(L_tmp, &expg); /* Extract exponent of enr */ - L_gain = Pow2(30, frac); /* Put 30 as exponent so that the */ - expg = add(expg, 16-30); /* output of Pow2() will be */ + L_tmp = Mult_32_16( L_enr_q, 21771 ); /* *0.166096 in Q17 -> Q26 */ + L_tmp = L_shr( L_tmp, 10 ); /* From Q26 to Q16 */ + frac = L_Extract_lc( L_tmp, &expg ); /* Extract exponent of enr */ + L_gain = Pow2( 30, frac ); /* Put 30 as exponent so that the */ + expg = add( expg, 16 - 30 ); /* output of Pow2() will be */ /* Normalized, set result in Q16 */ - gain = round_fx(L_gain); + gain = round_fx( L_gain ); #ifdef BASOP_NOGLOB - L_gain = L_shl_sat(L_gain, expg); /* In Q16*/ + L_gain = L_shl_sat( L_gain, expg ); /* In Q16*/ #else - L_gain = L_shl(L_gain, expg); /* In Q16*/ + L_gain = L_shl( L_gain, expg ); /* In Q16*/ #endif /* *norm_gain_code = gain / *inv_gain_inov;*/ - expi = norm_s(inv_gain_inov); - tmp_igi = shl(inv_gain_inov, expi); - L_tmp = div_s(shr(gain,1), tmp_igi); + expi = norm_s( inv_gain_inov ); + tmp_igi = shl( inv_gain_inov, expi ); + L_tmp = div_s( shr( gain, 1 ), tmp_igi ); #ifdef BASOP_NOGLOB - L_tmp = L_shl_sat(L_tmp, add(1,expi)); - *L_norm_gain_code = L_shl_sat(L_tmp, add(expg,13)); /* Q16 */ move32(); + L_tmp = L_shl_sat( L_tmp, add( 1, expi ) ); + *L_norm_gain_code = L_shl_sat( L_tmp, add( expg, 13 ) ); /* Q16 */ + move32(); #else - L_tmp = L_shl(L_tmp, add(1,expi)); - *L_norm_gain_code = L_shl(L_tmp, add(expg,13)); /* Q16 */ move32(); + L_tmp = L_shl( L_tmp, add( 1, expi ) ); + *L_norm_gain_code = L_shl( L_tmp, add( expg, 13 ) ); /* Q16 */ + move32(); #endif return L_gain; } /*--------------------------------------------------------------------------* -* gain_dec_SQ() -* -* Decoding of pitch and codebook gains using scalar quantizers -*-------------------------------------------------------------------------*/ + * gain_dec_SQ() + * + * Decoding of pitch and codebook gains using scalar quantizers + *-------------------------------------------------------------------------*/ void gain_dec_SQ_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 i_subfr, /* i : subframe number */ - const Word16 *code, /* i : algebraic code excitation Q9*/ - const Word16 Es_pred, /* i : predicted scaled innov. energy Q8 */ - Word16 *gain_pit, /* o : Quantized pitch gain Q14*/ - Word32 *gain_code, /* o : Quantized codeebook gain Q16*/ - Word16 *gain_inov, /* o : unscaled innovation gain Q12*/ - Word32 *norm_gain_code /* o : norm. gain of the codebook excitation Q16*/ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 i_subfr, /* i : subframe number */ + const Word16 *code, /* i : algebraic code excitation Q9*/ + const Word16 Es_pred, /* i : predicted scaled innov. energy Q8 */ + Word16 *gain_pit, /* o : Quantized pitch gain Q14*/ + Word32 *gain_code, /* o : Quantized codeebook gain Q16*/ + Word16 *gain_inov, /* o : unscaled innovation gain Q12*/ + Word32 *norm_gain_code /* o : norm. gain of the codebook excitation Q16*/ ) { Word16 index, nBits; @@ -1202,22 +1206,22 @@ void gain_dec_SQ_fx( * get number of bits *-----------------------------------------------------------------*/ - nBits = st_fx->acelp_cfg.gains_mode[shr(i_subfr, 6)]; + nBits = st_fx->acelp_cfg.gains_mode[shr( i_subfr, 6 )]; move16(); /*-----------------------------------------------------------------* * decode pitch gain *-----------------------------------------------------------------*/ - index = (Word16)get_next_indice(st_fx, shr(nBits,1) ); + index = (Word16) get_next_indice( st_fx, shr( nBits, 1 ) ); /*Ei = (G_PITCH_MAX - G_PITCH_MIN) / ((1 << (nBits>>1)) - 1); set quantization step */ - tmp16 = div_s(1,sub(shl(1,shr(nBits,1)),1)); /* Q15*/ - Ei = mult_r(G_PITCH_MAX_MINUS_MIN_Q13,tmp16); /* Q13*/ + tmp16 = div_s( 1, sub( shl( 1, shr( nBits, 1 ) ), 1 ) ); /* Q15*/ + Ei = mult_r( G_PITCH_MAX_MINUS_MIN_Q13, tmp16 ); /* Q13*/ /**gain_pit = usdequant( index, G_PITCH_MIN, Ei );*/ *gain_pit = usdequant_fx( index, G_PITCH_MIN_Q14, Ei ); - move16(); /*Q14 */ + move16(); /*Q14 */ /*-----------------------------------------------------------------* * calculate the predicted gain code @@ -1226,58 +1230,58 @@ void gain_dec_SQ_fx( /*Ecode = (dotp( code, code, L_SUBFR) + 0.01f) / L_SUBFR;*/ /**gain_inov = 1.0f / (float)sqrt( Ecode );*/ - L_tmp = Dot_product12(code, code, L_SUBFR, &expg); - expg = sub(expg, 18 + 6); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ + L_tmp = Dot_product12( code, code, L_SUBFR, &expg ); + expg = sub( expg, 18 + 6 ); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ expg2 = expg; move16(); L_tmp1 = L_tmp; /* sets to 'L_tmp' in 1 clock */ - move32(); - L_tmp = Isqrt_lc(L_tmp, &expg); + move32(); + L_tmp = Isqrt_lc( L_tmp, &expg ); - *gain_inov = extract_h(L_shl(L_tmp, sub(expg, 3))); /* gain_inov in Q12 */ + *gain_inov = extract_h( L_shl( L_tmp, sub( expg, 3 ) ) ); /* gain_inov in Q12 */ /*Ei = 10 * (float)log10( Ecode );*/ - e_tmp = norm_l(L_tmp1); - f_tmp = Log2_norm_lc(L_shl(L_tmp1, e_tmp)); - e_tmp = sub(expg2,add(1,e_tmp)); - L_tmp1 = Mpy_32_16(e_tmp, f_tmp, 12330); /* Q13 */ /* 10*log10(2) in Q12*/ - Ei = round_fx(L_shl(L_tmp1, 11)); /* Q8 */ + e_tmp = norm_l( L_tmp1 ); + f_tmp = Log2_norm_lc( L_shl( L_tmp1, e_tmp ) ); + e_tmp = sub( expg2, add( 1, e_tmp ) ); + L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 12330 ); /* Q13 */ /* 10*log10(2) in Q12*/ + Ei = round_fx( L_shl( L_tmp1, 11 ) ); /* Q8 */ /*gcode0 = (float) pow(10, 0.05 * (Es_pred - Ei));*/ - gcode0 = sub(Es_pred, Ei); /* Q8 */ + gcode0 = sub( Es_pred, Ei ); /* Q8 */ /* gcode0 = pow(10.0, gcode0/20) = pow(2, 3.321928*gcode0/20) = pow(2, 0.166096*gcode0) */ - L_tmp = L_mult(gcode0, 21771); /* *0.166096 in Q17 -> Q26 */ - L_tmp = L_shr(L_tmp, 10); /* From Q26 to Q16 */ - frac = L_Extract_lc(L_tmp, &exp_gcode0); /* Extract exponent of gcode0 */ + L_tmp = L_mult( gcode0, 21771 ); /* *0.166096 in Q17 -> Q26 */ + L_tmp = L_shr( L_tmp, 10 ); /* From Q26 to Q16 */ + frac = L_Extract_lc( L_tmp, &exp_gcode0 ); /* Extract exponent of gcode0 */ - gcode0 = extract_l(Pow2(14, frac));/* Put 14 as exponent so that output of Pow2() will be: 16384 < Pow2() <= 32767 */ - exp_gcode0 = sub(exp_gcode0, 14); + gcode0 = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that output of Pow2() will be: 16384 < Pow2() <= 32767 */ + exp_gcode0 = sub( exp_gcode0, 14 ); /*-----------------------------------------------------------------* * decode normalized codebook gain *-----------------------------------------------------------------*/ - index = (Word16)get_next_indice(st_fx, shr(add(nBits,1),1) ); + index = (Word16) get_next_indice( st_fx, shr( add( nBits, 1 ), 1 ) ); - tmp16 = gain_dequant_fx( index, G_CODE_MIN_TC_Q15, G_CODE_MAX_TC_Q0, shr(add(nBits,1),1), &expg ); + tmp16 = gain_dequant_fx( index, G_CODE_MIN_TC_Q15, G_CODE_MAX_TC_Q0, shr( add( nBits, 1 ), 1 ), &expg ); /**gain_code *= gcode0;*/ - L_tmp = L_mult(tmp16,gcode0); /* Q0*Q0 -> Q1*/ + L_tmp = L_mult( tmp16, gcode0 ); /* Q0*Q0 -> Q1*/ /**gain_code = L_shl(L_tmp,add(expg,15)); Q16*/ #ifdef BASOP_NOGLOB *gain_code = L_shl_sat( L_tmp, add( add( expg, exp_gcode0 ), 15 ) ); #else - *gain_code = L_shl(L_tmp,add(add(expg,exp_gcode0),15)); + *gain_code = L_shl( L_tmp, add( add( expg, exp_gcode0 ), 15 ) ); #endif - move32(); /*Q16*/ + move32(); /*Q16*/ /**norm_gain_code = *gain_code / *gain_inov;*/ - expg = sub(norm_s(*gain_inov),1); - expg = s_max(expg, 0); + expg = sub( norm_s( *gain_inov ), 1 ); + expg = s_max( expg, 0 ); - tmp16 = div_s(shr(8192,expg),*gain_inov); - *norm_gain_code = L_shr(Mult_32_16(*gain_code,tmp16),sub(1,expg)); + tmp16 = div_s( shr( 8192, expg ), *gain_inov ); + *norm_gain_code = L_shr( Mult_32_16( *gain_code, tmp16 ), sub( 1, expg ) ); move32(); return; @@ -1290,13 +1294,13 @@ void gain_dec_SQ_fx( *---------------------------------------------------------------------*/ void gain_dec_amr_wb_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word32 core_brate, /* i : core bitrate */ Word16 *gain_pit, /* o : Quantized pitch gain */ Word32 *gain_code, /* o : Quantized codeebook gain */ Word16 *past_qua_en, /* i/o: gain quantization memory (4 words) */ Word16 *gain_inov, /* o : unscaled innovation gain */ - const Word16 *code, /* i : algebraic code excitation */ + const Word16 *code, /* i : algebraic code excitation */ Word32 *norm_gain_code /* o : norm. gain of the codebook excitation */ ) { @@ -1314,11 +1318,11 @@ void gain_dec_amr_wb_fx( /**gain_inov = 1.0f/ (float)sqrt( ( dotp( code, code, L_SUBFR ) + 0.01f ) / L_SUBFR );*/ - L_tmp = Dot_product12(code, code, L_SUBFR, &expg); - expg = sub(expg, 18 + 6); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ - L_tmp = Isqrt_lc(L_tmp, &expg); + L_tmp = Dot_product12( code, code, L_SUBFR, &expg ); + expg = sub( expg, 18 + 6 ); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ + L_tmp = Isqrt_lc( L_tmp, &expg ); - *gain_inov = extract_h(L_shl(L_tmp, sub(expg, 3))); /* gain_inov in Q12 */ + *gain_inov = extract_h( L_shl( L_tmp, sub( expg, 3 ) ) ); /* gain_inov in Q12 */ /*-----------------------------------------------------------------* * Select the gain quantization table @@ -1327,7 +1331,7 @@ void gain_dec_amr_wb_fx( move16(); t_qua_gain = t_qua_gain7b_fx; - IF( LT_32(core_brate,ACELP_12k65)) + IF( LT_32( core_brate, ACELP_12k65 ) ) { nbits = 6; move16(); @@ -1342,70 +1346,70 @@ void gain_dec_amr_wb_fx( /**for (i=0; i Q25 */ + L_tmp = L_mac( L_tmp, pred_gain_fx[i], past_qua_en[i] ); /* Q14*Q10 -> Q25 */ } /* predicted codebook gain */ - gcode0 = extract_h(L_tmp); /* From Q25 to Q9 */ + gcode0 = extract_h( L_tmp ); /* From Q25 to Q9 */ /*-----------------------------------------------------------------* * gcode0 = pow(10.0, gcode0/20) * = pow(2, 3.321928*gcode0/20) * = pow(2, 0.166096*gcode0) *-----------------------------------------------------------------*/ - L_tmp = L_mult(gcode0, 21771); /* *0.166096 in Q17 -> Q27 */ - L_tmp = L_shr(L_tmp, 9+2); /* From Q27 to Q16 */ - L_Extract(L_tmp, &exp_gcode0, &fracg); /* Extract exponent of gcode0 */ + L_tmp = L_mult( gcode0, 21771 ); /* *0.166096 in Q17 -> Q27 */ + L_tmp = L_shr( L_tmp, 9 + 2 ); /* From Q27 to Q16 */ + L_Extract( L_tmp, &exp_gcode0, &fracg ); /* Extract exponent of gcode0 */ - gcode0 = extract_l(Pow2(14, fracg));/* Put 14 as exponent so that */ + gcode0 = extract_l( Pow2( 14, fracg ) ); /* Put 14 as exponent so that */ /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ - exp_gcode0 = sub(exp_gcode0, 14); + exp_gcode0 = sub( exp_gcode0, 14 ); /*-----------------------------------------------------------------* * Decode pitch gain *-----------------------------------------------------------------*/ - index = (Word16)get_next_indice( st_fx, nbits ); - index2 = shl(index,1); + index = (Word16) get_next_indice( st_fx, nbits ); + index2 = shl( index, 1 ); *gain_pit = t_qua_gain[index2]; move16(); /*-----------------------------------------------------------------* * Decode code gain *-----------------------------------------------------------------*/ - qua_en = t_qua_gain[add(index2,1)]; + qua_en = t_qua_gain[add( index2, 1 )]; move16(); /* *gain_code = t_qua_gain[indice*2+1] * gcode0; */ - L_tmp = L_mult(qua_en, gcode0); /* Q11*Q0 -> Q12 */ - tmp = round_fx(L_tmp); + L_tmp = L_mult( qua_en, gcode0 ); /* Q11*Q0 -> Q12 */ + tmp = round_fx( L_tmp ); move16(); /* Q-4 */ - *gain_code = L_shl(L_tmp, add(exp_gcode0, 4)); + *gain_code = L_shl( L_tmp, add( exp_gcode0, 4 ) ); move32(); /* Q12 -> Q16 */ /* adjust gain according to energy of code */ - L_tmp = Mult_32_16(*gain_code, *gain_inov); + L_tmp = Mult_32_16( *gain_code, *gain_inov ); #ifdef BASOP_NOGLOB - *gain_code = L_shl_o(L_tmp, 3, &Overflow); + *gain_code = L_shl_o( L_tmp, 3, &Overflow ); #else - *gain_code = L_shl(L_tmp, 3); + *gain_code = L_shl( L_tmp, 3 ); #endif - move32(); /* gcode_inov in Q12*/ + move32(); /* gcode_inov in Q12*/ /*-----------------------------------------------------------------* * update table of past quantized energies *-----------------------------------------------------------------*/ - FOR (i=GAIN_PRED_ORDER-1; i>0; i--) + FOR( i = GAIN_PRED_ORDER - 1; i > 0; i-- ) { - past_qua_en[i] = past_qua_en[i-1]; + past_qua_en[i] = past_qua_en[i - 1]; move16(); } /*past_qua_en[0] = (float)(20.0*log10(qua_en));*/ @@ -1414,12 +1418,12 @@ void gain_dec_amr_wb_fx( * = 6.0206*log2(t_qua_gain[indice*2+1]) * = 6.0206*(log2(t_qua_gain[indice*2+1]Q11 -11) *----------------------------------------------------------*/ - tmp = norm_l(qua_en); - fracg = Log2_norm_lc(L_shl(qua_en, tmp)); - expg = sub(30,tmp); - expg = sub(expg, 11); - L_tmp = Mpy_32_16(expg, fracg, 24660); /* x 6.0206 in Q12 */ - qua_en = extract_h(L_shl(L_tmp, 13)); /* result in Q10 */ + tmp = norm_l( qua_en ); + fracg = Log2_norm_lc( L_shl( qua_en, tmp ) ); + expg = sub( 30, tmp ); + expg = sub( expg, 11 ); + L_tmp = Mpy_32_16( expg, fracg, 24660 ); /* x 6.0206 in Q12 */ + qua_en = extract_h( L_shl( L_tmp, 13 ) ); /* result in Q10 */ past_qua_en[0] = qua_en; move16(); /* in Q10 */ @@ -1428,11 +1432,11 @@ void gain_dec_amr_wb_fx( * Normalized code gain *-----------------------------------------------------------------*/ /**norm_gain_code = *gain_code / *gain_inov;*/ - expg = sub(norm_s(*gain_inov),1); - expg = s_max(expg, 0); + expg = sub( norm_s( *gain_inov ), 1 ); + expg = s_max( expg, 0 ); - tmp = div_s(shr(8192,expg),*gain_inov); - *norm_gain_code = L_shr(Mult_32_16(*gain_code,tmp),sub(1,expg)); + tmp = div_s( shr( 8192, expg ), *gain_inov ); + *norm_gain_code = L_shr( Mult_32_16( *gain_code, tmp ), sub( 1, expg ) ); move32(); return; diff --git a/lib_dec/gaus_dec_fx.c b/lib_dec/gaus_dec_fx.c index 0f3047042..ae394105d 100644 --- a/lib_dec/gaus_dec_fx.c +++ b/lib_dec/gaus_dec_fx.c @@ -3,18 +3,18 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ /*---------------------------------------------------------------------* * Local function prototypes *---------------------------------------------------------------------*/ -void gaus_dec2v_fx( Decoder_State *st_fx, Word16 *code, const Word16 lg, const Word16 nb_bits); -static void dec_2pos_fx(Word16 index, Word16 *ind1, Word16 *ind2, Word16 *sign1, Word16 *sign2, Word16 log2_n); +void gaus_dec2v_fx( Decoder_State *st_fx, Word16 *code, const Word16 lg, const Word16 nb_bits ); +static void dec_2pos_fx( Word16 index, Word16 *ind1, Word16 *ind2, Word16 *sign1, Word16 *sign2, Word16 log2_n ); /*---------------------------------------------------------------------* * gaus_dec() @@ -24,23 +24,23 @@ static void dec_2pos_fx(Word16 index, Word16 *ind1, Word16 *ind2, Word16 *sign1, * - find the excitation *---------------------------------------------------------------------*/ void gaus_dec_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - const Word16 i_subfr, /* i : subframe index */ - Word16 *code, /* o : unvoiced excitation Q12 */ - Word32 *L_norm_gain_code, /* o : gain of normalized gaussian excitation Q16 */ - Word16 *lp_gainp, /* i/o : lp filtered pitch gain(FER) Q14 */ - Word16 *lp_gainc, /* i/o : lp filtered code gain (FER) Q3 */ - Word16 *inv_gain_inov, /* o : unscaled innovation gain Q12 */ - Word16 *tilt_code, /* o : synthesis excitation spectrum tilt Q15 */ - Word16 *voice_fac, /* o : estimated voicing factor Q15 */ - Word16 *gain_pit, /* o : pitch gain Q14 */ - Word16 *pt_pitch_1, /* o : floating pitch buffer Q6 */ - Word16 *exc, /* o : excitation signal frame */ - Word32 *L_gain_code, /* o : gain of the gaussian excitation Q16 */ - Word16 *exc2, /* o : Scaled excitation signal frame */ - Word16 *bwe_exc_fx, - Word16 *sQ_exc, /* i/o : Excitation scaling factor (Decoder state) */ - Word16 *sQsubfr /* i/o : Past excitation scaling factors (Decoder State) */ + Decoder_State *st_fx, /* i/o: decoder static memory */ + const Word16 i_subfr, /* i : subframe index */ + Word16 *code, /* o : unvoiced excitation Q12 */ + Word32 *L_norm_gain_code, /* o : gain of normalized gaussian excitation Q16 */ + Word16 *lp_gainp, /* i/o : lp filtered pitch gain(FER) Q14 */ + Word16 *lp_gainc, /* i/o : lp filtered code gain (FER) Q3 */ + Word16 *inv_gain_inov, /* o : unscaled innovation gain Q12 */ + Word16 *tilt_code, /* o : synthesis excitation spectrum tilt Q15 */ + Word16 *voice_fac, /* o : estimated voicing factor Q15 */ + Word16 *gain_pit, /* o : pitch gain Q14 */ + Word16 *pt_pitch_1, /* o : floating pitch buffer Q6 */ + Word16 *exc, /* o : excitation signal frame */ + Word32 *L_gain_code, /* o : gain of the gaussian excitation Q16 */ + Word16 *exc2, /* o : Scaled excitation signal frame */ + Word16 *bwe_exc_fx, + Word16 *sQ_exc, /* i/o : Excitation scaling factor (Decoder state) */ + Word16 *sQsubfr /* i/o : Past excitation scaling factors (Decoder State) */ ) { Word16 i, exp, gain_code; @@ -54,27 +54,27 @@ void gaus_dec_fx( /*------------------------------------------------------------------------------------------* * Unvoiced : Gaussian codebook *------------------------------------------------------------------------------------------*/ - nb_bits = st_fx->acelp_cfg.fixed_cdk_index[shr(i_subfr,6)]; + nb_bits = st_fx->acelp_cfg.fixed_cdk_index[shr( i_subfr, 6 )]; move16(); - gaus_dec2v_fx( st_fx, code, L_SUBFR, shr(nb_bits,1)); + gaus_dec2v_fx( st_fx, code, L_SUBFR, shr( nb_bits, 1 ) ); /*------------------------------------------------------------------------------------------* * - Gain of Gaussian excitation and normalized Gaussian excitation *------------------------------------------------------------------------------------------*/ /* gain_inov = 1.0f / (float)sqrt((dot_product(code, code, L_SUBFR) + 0.01f) / L_SUBFR) */ - L_tmp = Dot_product12(code, code, L_SUBFR, &exp); - exp = sub(exp, 18/*24*/ + 6); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ - L_tmp = Isqrt_lc(L_tmp, &exp); - *inv_gain_inov = extract_h(L_shl(L_tmp, sub(exp, 3))); /* inv_gain_inov in Q12 */ + L_tmp = Dot_product12( code, code, L_SUBFR, &exp ); + exp = sub( exp, 18 /*24*/ + 6 ); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ + L_tmp = Isqrt_lc( L_tmp, &exp ); + *inv_gain_inov = extract_h( L_shl( L_tmp, sub( exp, 3 ) ) ); /* inv_gain_inov in Q12 */ - nb_bits = st_fx->acelp_cfg.gains_mode[shr(i_subfr, 6)]; + nb_bits = st_fx->acelp_cfg.gains_mode[shr( i_subfr, 6 )]; move16(); - idx = (Word16)get_next_indice( st_fx, nb_bits ); + idx = (Word16) get_next_indice( st_fx, nb_bits ); move16(); /* safety check in case of bit errors */ - IF( GT_16(idx,78) && EQ_16(st_fx->element_mode, EVS_MONO)) + IF( GT_16( idx, 78 ) && EQ_16( st_fx->element_mode, EVS_MONO ) ) { idx = 78; move16(); @@ -82,10 +82,10 @@ void gaus_dec_fx( move16(); } - *L_gain_code = gain_dec_gaus_fx( idx, nb_bits,-30,190, *inv_gain_inov, L_norm_gain_code ); + *L_gain_code = gain_dec_gaus_fx( idx, nb_bits, -30, 190, *inv_gain_inov, L_norm_gain_code ); /* update LP filtered gains for the case of frame erasures */ - lp_gain_updt_fx( i_subfr, 0, *L_norm_gain_code, lp_gainp, lp_gainc, L_FRAME ); /* supposes that gain_dec_gaus() is used for ACELP@12k8 only */ + lp_gain_updt_fx( i_subfr, 0, *L_norm_gain_code, lp_gainp, lp_gainc, L_FRAME ); /* supposes that gain_dec_gaus() is used for ACELP@12k8 only */ /*------------------------------------------------------------------------------------------* * Updates @@ -93,40 +93,42 @@ void gaus_dec_fx( *tilt_code = 0; move16(); - *voice_fac = -32768; /* only unvoiced */ move16(); - *gain_pit = 0; /* needed for BASS postfitler */ move16(); - *pt_pitch_1 = 4096; /* floating pitch buffer Q6 */ move16(); + *voice_fac = -32768; /* only unvoiced */ + move16(); + *gain_pit = 0; /* needed for BASS postfitler */ + move16(); + *pt_pitch_1 = 4096; /* floating pitch buffer Q6 */ + move16(); /*------------------------------------------------------------------------------------------* * Construct scaled excitation *------------------------------------------------------------------------------------------*/ - set16_fx(&exc[i_subfr],0, L_SUBFR); - set16_fx(&exc2[i_subfr],0, L_SUBFR); + set16_fx( &exc[i_subfr], 0, L_SUBFR ); + set16_fx( &exc2[i_subfr], 0, L_SUBFR ); - IF( EQ_16(st_fx->L_frame,L_FRAME)) + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { - Rescale_exc(hMusicPF->dct_post_old_exc_fx, &exc[i_subfr], &bwe_exc_fx[i_subfr * HIBND_ACB_L_FAC], hGSCDec->last_exc_dct_in_fx, - L_SUBFR, L_SUBFR* HIBND_ACB_L_FAC, *L_gain_code, sQ_exc, sQsubfr, exc2, i_subfr, UNVOICED ); + Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc[i_subfr], &bwe_exc_fx[i_subfr * HIBND_ACB_L_FAC], hGSCDec->last_exc_dct_in_fx, + L_SUBFR, L_SUBFR * HIBND_ACB_L_FAC, *L_gain_code, sQ_exc, sQsubfr, exc2, i_subfr, UNVOICED ); } ELSE { - Rescale_exc(hMusicPF->dct_post_old_exc_fx, &exc[i_subfr], &bwe_exc_fx[i_subfr * 2], hGSCDec->last_exc_dct_in_fx, - L_SUBFR, L_SUBFR* 2, *L_gain_code, sQ_exc, sQsubfr, exc2, i_subfr, UNVOICED ); + Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc[i_subfr], &bwe_exc_fx[i_subfr * 2], hGSCDec->last_exc_dct_in_fx, + L_SUBFR, L_SUBFR * 2, *L_gain_code, sQ_exc, sQsubfr, exc2, i_subfr, UNVOICED ); } - gain_code = round_fx(L_shl(*L_gain_code, *sQ_exc)); - FOR (i = 0; i < L_SUBFR; i++) + gain_code = round_fx( L_shl( *L_gain_code, *sQ_exc ) ); + FOR( i = 0; i < L_SUBFR; i++ ) { - L_tmp = L_shl(L_mult(gain_code, code[i]), 6/*3*/); - exc[i+i_subfr] = round_fx(L_tmp); + L_tmp = L_shl( L_mult( gain_code, code[i] ), 6 /*3*/ ); + exc[i + i_subfr] = round_fx( L_tmp ); } return; } - /*-----------------------------------------------------* * gaus_dec2v() * @@ -137,13 +139,13 @@ void gaus_dec_fx( *-----------------------------------------------------*/ void gaus_dec2v_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *code, /* o : decoded gaussian vector Q12-exp */ - const Word16 lg, /* i : codevector length Q0 */ - const Word16 nb_bits /* i : nb ob bits per track (max 6) */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *code, /* o : decoded gaussian vector Q12-exp */ + const Word16 lg, /* i : codevector length Q0 */ + const Word16 nb_bits /* i : nb ob bits per track (max 6) */ ) { - Word16 i, ind1, ind2,idx; + Word16 i, ind1, ind2, idx; Word16 step; Word16 sign1, sign2; Word16 delta, delta2, inv_delta; @@ -152,47 +154,47 @@ void gaus_dec2v_fx( const Word16 *pt1, *pt2; Word16 index_delta; - step = shr(0x80, nb_bits); + step = shr( 0x80, nb_bits ); - idx = (Word16)get_next_indice( st_fx, add(shl(nb_bits,1),1) ); - index_delta = (Word16)get_next_indice( st_fx, 3 ); + idx = (Word16) get_next_indice( st_fx, add( shl( nb_bits, 1 ), 1 ) ); + index_delta = (Word16) get_next_indice( st_fx, 3 ); dec_2pos_fx( idx, &ind1, &ind2, &sign1, &sign2, nb_bits ); - delta = shl(index_delta, STEP_DELTA_FX); - delta2 = mac_r(16384*65536, shr(delta,1), delta); - inv_delta = div_s(16384, delta2); + delta = shl( index_delta, STEP_DELTA_FX ); + delta2 = mac_r( 16384 * 65536, shr( delta, 1 ), delta ); + inv_delta = div_s( 16384, delta2 ); - IF (delta > 0) + IF( delta > 0 ) { gaus_dico2_fx[0] = gaus_dico_fx[0]; move16(); /*Q12 */ - FOR (i=1; i<190; i++) + FOR( i = 1; i < 190; i++ ) { /* gaus_dico2[i] = (gaus_dico_fx[i] - delta*gaus_dico_fx[i-1])/(1+delta*delta) */ - tmp16 = msu_r(L_deposit_h(gaus_dico_fx[i]), delta, gaus_dico_fx[i-1]); - gaus_dico2_fx[i] = mult_r(tmp16, inv_delta); + tmp16 = msu_r( L_deposit_h( gaus_dico_fx[i] ), delta, gaus_dico_fx[i - 1] ); + gaus_dico2_fx[i] = mult_r( tmp16, inv_delta ); } } ELSE { - FOR (i=0; i<190; i++) + FOR( i = 0; i < 190; i++ ) { gaus_dico2_fx[i] = gaus_dico_fx[i]; - move16(); /*Q12 */ + move16(); /*Q12 */ } } - pt1 = &gaus_dico2_fx[i_mult2(ind1, step)]; + pt1 = &gaus_dico2_fx[i_mult2( ind1, step )]; move16(); - pt2 = &gaus_dico2_fx[i_mult2(ind2, step)]; + pt2 = &gaus_dico2_fx[i_mult2( ind2, step )]; move16(); - FOR (i = 0; i < lg; i++) + FOR( i = 0; i < lg; i++ ) { /* code is Q9, Gaussian codebook is Q12 */ /* code[i] = pt1[i] * sign1 + pt2[i] * sign2 */ - code[i] = add(mult(pt1[i], sign1), mult(pt2[i], sign2)); + code[i] = add( mult( pt1[i], sign1 ), mult( pt2[i], sign2 ) ); } return; @@ -215,33 +217,34 @@ static void dec_2pos_fx( { Word16 i; - i = s_and(index, 1); - *sign1 = (-32768); /* -1 (Q15) */ move16(); - if (i == 0) + i = s_and( index, 1 ); + *sign1 = ( -32768 ); /* -1 (Q15) */ + move16(); + if ( i == 0 ) { - *sign1 = MAX_16; /* 1 (Q15) */ move16(); + *sign1 = MAX_16; /* 1 (Q15) */ + move16(); } - *sign1 = shr(*sign1,3); - move16(); /* To have code dec in Q9 instead of Q12 */ + *sign1 = shr( *sign1, 3 ); + move16(); /* To have code dec in Q9 instead of Q12 */ - index = shr(index, 1); + index = shr( index, 1 ); - *ind1 = shr(index, log2_n); + *ind1 = shr( index, log2_n ); move16(); - *ind2 = sub(index, shl(*ind1, log2_n)); + *ind2 = sub( index, shl( *ind1, log2_n ) ); move16(); *sign2 = *sign1; move16(); - if (GT_16(*ind1, *ind2)) + if ( GT_16( *ind1, *ind2 ) ) { - *sign2 = negate(*sign1); + *sign2 = negate( *sign1 ); move16(); } return; } - /*-----------------------------------------------------* * gaus_L2_dec : * @@ -250,11 +253,11 @@ static void dec_2pos_fx( * One Gaussian vector *-----------------------------------------------------*/ void gaus_L2_dec( - Word16 *code, /* o : decoded gaussian codevector Q9 */ - Word16 tilt_code, /* i : tilt of code Q15 */ - const Word16 *A, /* i : quantized LPCs Q12 */ - Word16 formant_enh, /* i : formant enhancement factor Q15 */ - Word16 *seed_acelp /*i/o : random seed Q0 */ + Word16 *code, /* o : decoded gaussian codevector Q9 */ + Word16 tilt_code, /* i : tilt of code Q15 */ + const Word16 *A, /* i : quantized LPCs Q12 */ + Word16 formant_enh, /* i : formant enhancement factor Q15 */ + Word16 *seed_acelp /*i/o : random seed Q0 */ ) { Word16 i, seed; @@ -263,25 +266,24 @@ void gaus_L2_dec( /*Generate white gaussian noise using central limit theorem method (N only 4 as E_util_random is not purely uniform)*/ seed = *seed_acelp; move16(); - FOR (i = 0; i < L_SUBFR; i++) + FOR( i = 0; i < L_SUBFR; i++ ) { - seed = own_random2_fx(seed); - tmp32 = L_mac(0, seed, 1<<9); + seed = own_random2_fx( seed ); + tmp32 = L_mac( 0, seed, 1 << 9 ); - seed = own_random2_fx(seed); - tmp32 = L_mac(tmp32, seed, 1<<9); + seed = own_random2_fx( seed ); + tmp32 = L_mac( tmp32, seed, 1 << 9 ); - seed = own_random2_fx(seed); - code[i] = mac_r(tmp32, seed, 1<<9); + seed = own_random2_fx( seed ); + code[i] = mac_r( tmp32, seed, 1 << 9 ); move16(); } *seed_acelp = seed; move16(); /*Shape the gaussian excitation*/ - cb_shape_fx( 1, 0, 0, 1, 0, formant_enh, FORMANT_SHARPENING_G2, A, code, tilt_code, 0, 1 , L_SUBFR); + cb_shape_fx( 1, 0, 0, 1, 0, formant_enh, FORMANT_SHARPENING_G2, A, code, tilt_code, 0, 1, L_SUBFR ); return; } - diff --git a/lib_dec/gs_dec.c b/lib_dec/gs_dec.c index abdbc52f6..010aad694 100644 --- a/lib_dec/gs_dec.c +++ b/lib_dec/gs_dec.c @@ -710,7 +710,7 @@ void GSC_dec_init_ivas( { hGSCDec->seed_tcx = 15687; hGSCDec->cor_strong_limit = 1; - set_f( hGSCDec->old_y_gain, 0, MBANDS_GN16k); + set_f( hGSCDec->old_y_gain, 0, MBANDS_GN16k ); hGSCDec->noise_lev = NOISE_LEVEL_SP0; set_f( hGSCDec->Last_GSC_spectrum, 0.0f, L_FRAME16k ); hGSCDec->Last_GSC_pit_band_idx = 0; diff --git a/lib_dec/gs_dec_amr_wb_fx.c b/lib_dec/gs_dec_amr_wb_fx.c index 2f709cb84..f55b5e877 100644 --- a/lib_dec/gs_dec_amr_wb_fx.c +++ b/lib_dec/gs_dec_amr_wb_fx.c @@ -3,45 +3,45 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ /*-------------------------------------------------------------------* * Local constants *-------------------------------------------------------------------*/ -#define ALP_FX 22938 /* 0.70f */ -#define MALP_FX (Word16)(32768L-ALP_FX) -#define ALPMY_FX 28180 /* 0.86f */ +#define ALP_FX 22938 /* 0.70f */ +#define MALP_FX ( Word16 )( 32768L - ALP_FX ) +#define ALPMY_FX 28180 /* 0.86f */ -#define BAND3k 15 -#define BIN_1k2 48 -#define BAND_2k 12 -#define BAND_0k4 4 +#define BAND3k 15 +#define BIN_1k2 48 +#define BAND_2k 12 +#define BAND_0k4 4 #define NORMALIZE_SPECS_Q_OUT 6 -#define ENER_FX_Q_GUARD 1 +#define ENER_FX_Q_GUARD 1 #ifdef ADD_IVAS_GS_DEC_IMPR #define CONTR_LIMIT 3012 to be verified for fixed point /* Threshold to allow an increase in the contribution length */ #endif - /*-------------------------------------------------------------------* - * Local functions - *-------------------------------------------------------------------*/ -static void NoiseFill_fx(Word16* exc_diffQ_fx, Word16* seed_tcx, const Word16 Mbands_gn, const Word16 Q_out); -static void Ener_per_band_fx(const Word16 exc_diff_fx[], const Word16 exc_diff_exp, Word32 y_gain4_fx[]); -static void Apply_gain_fx(Word16 exc_diffQ_fx[], Word32 L_Ener_per_bd_iQ[], Word32 L_Ener_per_bd_yQ[], const Word16 Q_out); -static void normalize_spec_fx(Word16 fac_up_fx, Word16 fy_norm_fx[], const Word16 L_frame, const Word16 Q_out); -static void gs_dec_amr_wb_fx(const long core_brate, Word16* seed_tcx, const Word16 dct_in_fx[], const Word16 Q_dct_in, - Word16 dct_out_fx[], Word16 Q_dct_out, const Word16 pitch_fx[], const Word16 voice_fac, const Word16 clas, const Word16 coder_type +/*-------------------------------------------------------------------* + * Local functions + *-------------------------------------------------------------------*/ +static void NoiseFill_fx( Word16 *exc_diffQ_fx, Word16 *seed_tcx, const Word16 Mbands_gn, const Word16 Q_out ); +static void Ener_per_band_fx( const Word16 exc_diff_fx[], const Word16 exc_diff_exp, Word32 y_gain4_fx[] ); +static void Apply_gain_fx( Word16 exc_diffQ_fx[], Word32 L_Ener_per_bd_iQ[], Word32 L_Ener_per_bd_yQ[], const Word16 Q_out ); +static void normalize_spec_fx( Word16 fac_up_fx, Word16 fy_norm_fx[], const Word16 L_frame, const Word16 Q_out ); +static void gs_dec_amr_wb_fx( const long core_brate, Word16 *seed_tcx, const Word16 dct_in_fx[], const Word16 Q_dct_in, Word16 dct_out_fx[], Word16 Q_dct_out, const Word16 pitch_fx[], const Word16 voice_fac, const Word16 clas, const Word16 coder_type #ifdef ADD_IVAS_GS_DEC_IMPR - , const Word16 VeryLowRateSTflag + , + const Word16 VeryLowRateSTflag #endif - ); +); /*-------------------------------------------------------------------* * NoiseFill_fx() @@ -50,10 +50,10 @@ static void gs_dec_amr_wb_fx(const long core_brate, Word16* seed_tcx, const Word *-------------------------------------------------------------------*/ static void NoiseFill_fx( - Word16 *exc_diffQ_fx, /* i/o: Noise per band */ - Word16 *seed_tcx, /* i : Seed for noise */ - const Word16 Mbands_gn, /* i : number of bands */ - const Word16 Q_out /* i : Q of exc_diffQ_fx[] */ + Word16 *exc_diffQ_fx, /* i/o: Noise per band */ + Word16 *seed_tcx, /* i : Seed for noise */ + const Word16 Mbands_gn, /* i : number of bands */ + const Word16 Q_out /* i : Q of exc_diffQ_fx[] */ ) { Word16 i_band, CurBin, EndBin; @@ -61,16 +61,16 @@ static void NoiseFill_fx( Word16 fact; CurBin = 0; move16(); - fact = shr(24576/*0.75f*/, sub(15, Q_out)); + fact = shr( 24576 /*0.75f*/, sub( 15, Q_out ) ); FOR( i_band = 0; i_band < Mbands_gn; i_band++ ) { - EndBin = add(CurBin, crit_bins[i_band]); - FOR( ; CurBin Q9 */ - L_temp = L_mult(exc_diffQ_fx[i],s_max(temp2,512)); /*Q(Qexc_diffQ+10) */ - exc_diffQ_fx[i] = round_fx(L_shl(L_temp,16-10));/*Qexc_diffQ */ + temp2 = msu_r( -7680 * 65536, -17564, shl( i, 6 ) ); /*-15 in Q9; -0.067 in Q18 and i in Q6= Q9 */ + temp2 = mult_r( temp2, temp ); /* Q15*Q9+1-16 -> Q9 */ + L_temp = L_mult( exc_diffQ_fx[i], s_max( temp2, 512 ) ); /*Q(Qexc_diffQ+10) */ + exc_diffQ_fx[i] = round_fx( L_shl( L_temp, 16 - 10 ) ); /*Qexc_diffQ */ } /*--------------------------------------------------------------------------------------* * Match the energy of the modified excitation vector to the decoded excitation *--------------------------------------------------------------------------------------*/ - Apply_gain_fx( exc_diffQ_fx, Ener_per_bd_iQ_fx, Ener_per_bd_yQ_fx,sub(NORMALIZE_SPECS_Q_OUT, Q_dct_out) ); + Apply_gain_fx( exc_diffQ_fx, Ener_per_bd_iQ_fx, Ener_per_bd_yQ_fx, sub( NORMALIZE_SPECS_Q_OUT, Q_dct_out ) ); /*--------------------------------------------------------------------------------------* * Copy to the output vector *--------------------------------------------------------------------------------------*/ - Copy(exc_diffQ_fx, dct_out_fx, L_FRAME); + Copy( exc_diffQ_fx, dct_out_fx, L_FRAME ); return; } @@ -380,32 +383,33 @@ static void gs_dec_amr_wb_fx( * unvoiced and audio signals (used only in AMR-WB IO mode) *-------------------------------------------------------------------*/ void improv_amr_wb_gs_fx( - const Word16 clas, /* i : signal frame class */ - const Word16 coder_type, /* i : coder type */ - const Word32 core_brate, /* i : bitrate allocated to the core */ - Word16 *seed_tcx, /* i/o: Seed used for noise generation */ - Word16 *old_Aq_fx, /* i/o: old LPC filter coefficient */ - Word16 *mem_syn2_fx, /* i/o: synthesis memory */ - const Word16 lt_voice_fac_fx, /* i/o: long term voice factor Q14 */ - const Word16 locattack, /* i : Flag for a detected attack */ - Word16 *Aq_fx, /* i/o: Decoded LP filter coefficient */ - Word16 *exc2_fx, /* i/o: Decoded complete excitation */ - const Word16 Q_exc2, /* i : Exponent of Exc2 */ - Word16 *mem_tmp_fx, /* i/o: synthesis temporary memory */ - Word16 *syn_fx, /* o: Decoded synthesis to be updated */ - const Word16 Q_syn, /* i : Synthesis scaling Q0 */ - const Word16 *pitch_buf_fx, /* i : Decoded pitch buffer Q6 */ - const Word16 Last_ener_fx, /* i : Last energy (Q8) */ - const Word16 rate_switching_reset, /* i : rate switching reset flag */ - const Word16 last_coder_type /* i : Last coder_type */ + const Word16 clas, /* i : signal frame class */ + const Word16 coder_type, /* i : coder type */ + const Word32 core_brate, /* i : bitrate allocated to the core */ + Word16 *seed_tcx, /* i/o: Seed used for noise generation */ + Word16 *old_Aq_fx, /* i/o: old LPC filter coefficient */ + Word16 *mem_syn2_fx, /* i/o: synthesis memory */ + const Word16 lt_voice_fac_fx, /* i/o: long term voice factor Q14 */ + const Word16 locattack, /* i : Flag for a detected attack */ + Word16 *Aq_fx, /* i/o: Decoded LP filter coefficient */ + Word16 *exc2_fx, /* i/o: Decoded complete excitation */ + const Word16 Q_exc2, /* i : Exponent of Exc2 */ + Word16 *mem_tmp_fx, /* i/o: synthesis temporary memory */ + Word16 *syn_fx, /* o: Decoded synthesis to be updated */ + const Word16 Q_syn, /* i : Synthesis scaling Q0 */ + const Word16 *pitch_buf_fx, /* i : Decoded pitch buffer Q6 */ + const Word16 Last_ener_fx, /* i : Last energy (Q8) */ + const Word16 rate_switching_reset, /* i : rate switching reset flag */ + const Word16 last_coder_type /* i : Last coder_type */ #ifdef ADD_IVAS_GS_DEC_IMPR - ,const Word16 VeryLowRateSTflag /* i : Enable the noise enhancement for very low rate stereo generic mode */ + , + const Word16 VeryLowRateSTflag /* i : Enable the noise enhancement for very low rate stereo generic mode */ #endif ) { Word16 i, exp_a, exp_b, exp_diff, j; Word16 dct_exc_in_fx[L_FRAME], dct_exc_out_fx[L_FRAME]; - Word16 Aq_orig[NB_SUBFR*(M+1)], enr_LP_old, enr_LP_new; + Word16 Aq_orig[NB_SUBFR * ( M + 1 )], enr_LP_old, enr_LP_new; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif @@ -423,14 +427,16 @@ void improv_amr_wb_gs_fx( test(); test(); #ifdef ADD_IVAS_GS_DEC_IMPR - IF(VeryLowRateSTflag || - ((locattack == 0 && LE_32(core_brate, ACELP_12k65)) && - ((LT_32(core_brate, ACELP_8k85) && NE_16(clas, AUDIO_CLAS) && - (EQ_16(clas, UNVOICED_CLAS) || EQ_16(clas, VOICED_TRANSITION))) || EQ_16(coder_type, INACTIVE)))) + IF( VeryLowRateSTflag || + ( ( locattack == 0 && LE_32( core_brate, ACELP_12k65 ) ) && + ( ( LT_32( core_brate, ACELP_8k85 ) && NE_16( clas, AUDIO_CLAS ) && + ( EQ_16( clas, UNVOICED_CLAS ) || EQ_16( clas, VOICED_TRANSITION ) ) ) || + EQ_16( coder_type, INACTIVE ) ) ) ) #else - IF( ( locattack == 0 && LE_32(core_brate, ACELP_12k65))&& - ( (LT_32(core_brate, ACELP_8k85) && NE_16(clas, AUDIO_CLAS) && - (EQ_16(clas, UNVOICED_CLAS) || EQ_16(clas, VOICED_TRANSITION) )) || EQ_16(coder_type, INACTIVE) ) ) + IF( ( locattack == 0 && LE_32( core_brate, ACELP_12k65 ) ) && + ( ( LT_32( core_brate, ACELP_8k85 ) && NE_16( clas, AUDIO_CLAS ) && + ( EQ_16( clas, UNVOICED_CLAS ) || EQ_16( clas, VOICED_TRANSITION ) ) ) || + EQ_16( coder_type, INACTIVE ) ) ) #endif { /*------------------------------------------------------------* @@ -439,34 +445,33 @@ void improv_amr_wb_gs_fx( * generic audio sound * LP filter smoothing for inactive parts *------------------------------------------------------------*/ - *seed_tcx = extract_l(L_mult0(pitch_buf_fx[0],pitch_buf_fx[3])); + *seed_tcx = extract_l( L_mult0( pitch_buf_fx[0], pitch_buf_fx[3] ) ); /* last_coder_type == UNVOICED should be understand as INACTIVE, but it is forced to UNVOICED in update_dec */ test(); test(); test(); - IF( EQ_16(coder_type, INACTIVE)&>_16(Last_ener_fx,-3*256)&&EQ_16(last_coder_type,UNVOICED)&&rate_switching_reset==0) /* 3.0 x 256 to Go to Q8 */ + IF( EQ_16( coder_type, INACTIVE ) && GT_16( Last_ener_fx, -3 * 256 ) && EQ_16( last_coder_type, UNVOICED ) && rate_switching_reset == 0 ) /* 3.0 x 256 to Go to Q8 */ { - FOR(i =0; i < NB_SUBFR; i++) + FOR( i = 0; i < NB_SUBFR; i++ ) { - Copy( Aq_fx, Aq_orig, NB_SUBFR*(M+1) ); + Copy( Aq_fx, Aq_orig, NB_SUBFR * ( M + 1 ) ); - exp_a = norm_s(Aq_fx[i*(M+1)]); - exp_b = norm_s(old_Aq_fx[i*(M+1)]); - exp_diff = sub(exp_a, exp_b); - IF(exp_diff>0) + exp_a = norm_s( Aq_fx[i * ( M + 1 )] ); + exp_b = norm_s( old_Aq_fx[i * ( M + 1 )] ); + exp_diff = sub( exp_a, exp_b ); + IF( exp_diff > 0 ) { - Scale_sig(&old_Aq_fx[i*(M+1)], (M+1), negate(exp_diff)); + Scale_sig( &old_Aq_fx[i * ( M + 1 )], ( M + 1 ), negate( exp_diff ) ); } ELSE { - Scale_sig(&Aq_fx[i*(M+1)], (M+1), exp_diff); - + Scale_sig( &Aq_fx[i * ( M + 1 )], ( M + 1 ), exp_diff ); } - FOR(j = i*(M+1); j < (i+1)*(M+1); j++) + FOR( j = i * ( M + 1 ); j < ( i + 1 ) * ( M + 1 ); j++ ) { - Aq_fx[j] = round_fx(L_mac(L_mult(ALP_FX, old_Aq_fx[j]), MALP_FX, Aq_fx[j])); + Aq_fx[j] = round_fx( L_mac( L_mult( ALP_FX, old_Aq_fx[j] ), MALP_FX, Aq_fx[j] ) ); } } @@ -475,17 +480,17 @@ void improv_amr_wb_gs_fx( Overflow = 0; move16(); - FOR( i=0; i < NB_SUBFR; i++ ) + FOR( i = 0; i < NB_SUBFR; i++ ) { #ifdef BASOP_NOGLOB - enr_LP_new = Enr_1_Az_fx_o( Aq_fx+i*(M+1), L_SUBFR, &Overflow ); + enr_LP_new = Enr_1_Az_fx_o( Aq_fx + i * ( M + 1 ), L_SUBFR, &Overflow ); #else - enr_LP_new = Enr_1_Az_fx( Aq_fx+i*(M+1), L_SUBFR ); + enr_LP_new = Enr_1_Az_fx( Aq_fx + i * ( M + 1 ), L_SUBFR ); #endif - IF( (shr(enr_LP_new,7) > enr_LP_old) || Overflow ) + IF( ( shr( enr_LP_new, 7 ) > enr_LP_old ) || Overflow ) { /* filter is unstable, do not modify the excitation */ - Copy( Aq_orig, Aq_fx, NB_SUBFR*(M+1) ); + Copy( Aq_orig, Aq_fx, NB_SUBFR * ( M + 1 ) ); Overflow = 0; move16(); @@ -502,20 +507,21 @@ void improv_amr_wb_gs_fx( * Do the excitation modification according to the content * Go back to time domain -> Overwrite exctiation *------------------------------------------------------------*/ - edct_16fx(exc2_fx, dct_exc_in_fx, L_FRAME, 6, EVS_MONO); + edct_16fx( exc2_fx, dct_exc_in_fx, L_FRAME, 6, EVS_MONO ); gs_dec_amr_wb_fx( core_brate, seed_tcx, dct_exc_in_fx, Q_exc2, dct_exc_out_fx, Q_exc2, pitch_buf_fx, lt_voice_fac_fx, clas, coder_type #ifdef ADD_IVAS_GS_DEC_IMPR - , VeryLowRateSTflag + , + VeryLowRateSTflag #endif ); - edct_16fx(dct_exc_out_fx, exc2_fx, L_FRAME, 6, EVS_MONO); + edct_16fx( dct_exc_out_fx, exc2_fx, L_FRAME, 6, EVS_MONO ); /*------------------------------------------------------------* * Redo core synthesis at 12k8 Hz with the modified excitation *------------------------------------------------------------*/ Copy( mem_tmp_fx, mem_syn2_fx, M ); - syn_12k8_fx(L_FRAME, Aq_fx, exc2_fx, syn_fx, mem_syn2_fx, 1, Q_exc2, Q_syn ); + syn_12k8_fx( L_FRAME, Aq_fx, exc2_fx, syn_fx, mem_syn2_fx, 1, Q_exc2, Q_syn ); } return; diff --git a/lib_dec/gs_dec_fx.c b/lib_dec/gs_dec_fx.c index 430b1653e..4c2925369 100644 --- a/lib_dec/gs_dec_fx.c +++ b/lib_dec/gs_dec_fx.c @@ -34,20 +34,21 @@ /* _ None */ /*==========================================================================*/ void decod_audio_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - Word16 dct_epit[], /* o : GSC excitation in DCT domain */ - const Word16 *Aq, /* i : LP filter coefficient */ - Word16 *pitch_buf, /* o : floating pitch values for each subframe */ - Word16 *voice_factors, /* o : voicing factors */ - Word16 *exc, /* i/o: adapt. excitation exc */ - Word16 *exc2, /* i/o: adapt. excitation/total exc */ - Word16 *bwe_exc, /* o : excitation for SWB TBE */ - Word16 *lsf_new /* i : ISFs at the end of the frame */ - , Word16 *gain_buf /*Q14*/ + Decoder_State *st_fx, /* i/o: decoder static memory */ + Word16 dct_epit[], /* o : GSC excitation in DCT domain */ + const Word16 *Aq, /* i : LP filter coefficient */ + Word16 *pitch_buf, /* o : floating pitch values for each subframe */ + Word16 *voice_factors, /* o : voicing factors */ + Word16 *exc, /* i/o: adapt. excitation exc */ + Word16 *exc2, /* i/o: adapt. excitation/total exc */ + Word16 *bwe_exc, /* o : excitation for SWB TBE */ + Word16 *lsf_new /* i : ISFs at the end of the frame */ + , + Word16 *gain_buf /*Q14*/ ) { Word16 tmp_nb_bits_tot, pit_band_idx; - Word16 code[4*L_SUBFR]; + Word16 code[4 * L_SUBFR]; Word16 Diff_len, nb_subfr, i; Word16 nb_frame_flg; Word16 Es_pred = 0; @@ -66,7 +67,7 @@ void decod_audio_fx( /*---------------------------------------------------------------* * Initialization *---------------------------------------------------------------*/ - Diff_len = 0; + Diff_len = 0; move16(); /* decode GSC attack flag (used to reduce possible pre-echo) */ @@ -75,10 +76,10 @@ void decod_audio_fx( /* decode GSC SWB speech flag */ test(); #if !defined ADD_LRTD - IF( NE_16(st_fx->coder_type,INACTIVE)&&GE_32(st_fx->total_brate,ACELP_13k20)) -#else - if (st_fx->GSC_IVAS_mode >= 1 || (st_fx->coder_type != INACTIVE && ((st_fx->element_mode == EVS_MONO && st_fx->total_brate >= ACELP_13k20) || - (st_fx->element_mode > EVS_MONO && st_fx->total_brate > MIN_BRATE_GSC_NOISY_FLAG && st_fx->bwidth >= SWB && !st_fx->flag_ACELP16k)))) + IF( NE_16( st_fx->coder_type, INACTIVE ) && GE_32( st_fx->total_brate, ACELP_13k20 ) ) +#else + if ( st_fx->GSC_IVAS_mode >= 1 || ( st_fx->coder_type != INACTIVE && ( ( st_fx->element_mode == EVS_MONO && st_fx->total_brate >= ACELP_13k20 ) || + ( st_fx->element_mode > EVS_MONO && st_fx->total_brate > MIN_BRATE_GSC_NOISY_FLAG && st_fx->bwidth >= SWB && !st_fx->flag_ACELP16k ) ) ) ) #endif { st_fx->GSC_noisy_speech = (Word16) get_next_indice( st_fx, 1 ); @@ -86,7 +87,7 @@ void decod_audio_fx( /* safety check in case of bit errors */ test(); - IF(st_fx->GSC_noisy_speech && LT_16(st_fx->bwidth, SWB) && st_fx->GSC_IVAS_mode == 0) + IF( st_fx->GSC_noisy_speech && LT_16( st_fx->bwidth, SWB ) && st_fx->GSC_IVAS_mode == 0 ) { st_fx->BER_detect = 1; move16(); @@ -95,18 +96,19 @@ void decod_audio_fx( } /* set bit-allocation */ #ifdef ADD_LRTD - config_acelp1(DEC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl_orig, st_fx->extl_brate_orig, st_fx->L_frame, st_fx->GSC_noisy_speech, &(st_fx->acelp_cfg), st_fx->next_bit_pos, st_fx->coder_type, -1, 1, &nbits, NULL, st_fx->element_mode, &nbits /*dummy*/, tdm_lp_reuse_flag, tdm_low_rate_mode, st_fx->idchan, st_fx->active_cnt, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode); + config_acelp1( DEC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl_orig, st_fx->extl_brate_orig, st_fx->L_frame, st_fx->GSC_noisy_speech, &( st_fx->acelp_cfg ), st_fx->next_bit_pos, st_fx->coder_type, -1, 1, &nbits, NULL, st_fx->element_mode, &nbits /*dummy*/, tdm_lp_reuse_flag, tdm_low_rate_mode, st_fx->idchan, st_fx->active_cnt, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode ); #else - config_acelp1(DEC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl_orig, st_fx->extl_brate_orig, st_fx->L_frame, st_fx->GSC_noisy_speech, &(st_fx->acelp_cfg), st_fx->next_bit_pos, st_fx->coder_type, -1, 1, &nbits, NULL, st_fx->element_mode, &nbits /*dummy*/, 0, 0, st_fx->idchan, st_fx->active_cnt, 0, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode); + config_acelp1( DEC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl_orig, st_fx->extl_brate_orig, st_fx->L_frame, st_fx->GSC_noisy_speech, &( st_fx->acelp_cfg ), st_fx->next_bit_pos, st_fx->coder_type, -1, 1, &nbits, NULL, st_fx->element_mode, &nbits /*dummy*/, 0, 0, st_fx->idchan, st_fx->active_cnt, 0, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode ); #endif /*---------------------------------------------------------------* * Decode energy dynamics *---------------------------------------------------------------*/ #if defined ADD_LRTD - test(); test(); - IF (st_fx->GSC_IVAS_mode >= 1 || (EQ_16(st_fx->GSC_noisy_speech, 1) && st_fx->GSC_IVAS_mode == 0)) -#else - IF( EQ_16(st_fx->GSC_noisy_speech,1)) + test(); + test(); + IF( st_fx->GSC_IVAS_mode >= 1 || ( EQ_16( st_fx->GSC_noisy_speech, 1 ) && st_fx->GSC_IVAS_mode == 0 ) ) +#else + IF( EQ_16( st_fx->GSC_noisy_speech, 1 ) ) #endif { nb_subfr = NB_SUBFR; @@ -115,20 +117,20 @@ void decod_audio_fx( move16(); hGSCDec->noise_lev = NOISE_LEVEL_SP3; move16(); -#ifdef ADD_LRTD - if (st_fx->GSC_IVAS_mode >= 1) +#ifdef ADD_LRTD + if ( st_fx->GSC_IVAS_mode >= 1 ) { - if (st_fx->core_brate < GSC_L_RATE_STG && st_fx->GSC_IVAS_mode < 3) + if ( st_fx->core_brate < GSC_L_RATE_STG && st_fx->GSC_IVAS_mode < 3 ) { nb_subfr = 2; } hGSCDec->noise_lev = NOISE_LEVEL_SP2; - if (st_fx->GSC_IVAS_mode == 3) /* Music like */ + if ( st_fx->GSC_IVAS_mode == 3 ) /* Music like */ { hGSCDec->noise_lev = NOISE_LEVEL_SP0; } - else if (st_fx->GSC_noisy_speech == 0) /* speech like but not noisy */ + else if ( st_fx->GSC_noisy_speech == 0 ) /* speech like but not noisy */ { hGSCDec->noise_lev = NOISE_LEVEL_SP3; } @@ -137,20 +139,20 @@ void decod_audio_fx( } ELSE { - IF( LE_32(st_fx->core_brate,ACELP_8k00)) + IF( LE_32( st_fx->core_brate, ACELP_8k00 ) ) { - hGSCDec->noise_lev = add((Word16)get_next_indice( st_fx, 2 ), NOISE_LEVEL_SP2); + hGSCDec->noise_lev = add( (Word16) get_next_indice( st_fx, 2 ), NOISE_LEVEL_SP2 ); } ELSE { - hGSCDec->noise_lev = add((Word16)get_next_indice( st_fx, 3 ), NOISE_LEVEL_SP0); + hGSCDec->noise_lev = add( (Word16) get_next_indice( st_fx, 3 ), NOISE_LEVEL_SP0 ); } /*---------------------------------------------------------------* - * Decode number of subframes - *---------------------------------------------------------------*/ -#ifdef ADD_LRTD - if (st_fx->L_frame == L_FRAME16k && (st_fx->core_brate <= ACELP_13k20 || st_fx->coder_type == INACTIVE)) + * Decode number of subframes + *---------------------------------------------------------------*/ +#ifdef ADD_LRTD + if ( st_fx->L_frame == L_FRAME16k && ( st_fx->core_brate <= ACELP_13k20 || st_fx->coder_type == INACTIVE ) ) { hGSCDec->cor_strong_limit = 0; nb_subfr = 1; @@ -163,32 +165,32 @@ void decod_audio_fx( nb_subfr = SWNB_SUBFR; move16(); - IF(GE_32(st_fx->core_brate,ACELP_9k60)) + IF( GE_32( st_fx->core_brate, ACELP_9k60 ) ) { nbits = 1; move16(); -#ifdef ADD_LRTD - if (st_fx->L_frame == L_FRAME16k && st_fx->core_brate >= MIN_RATE_4SBFR) +#ifdef ADD_LRTD + if ( st_fx->L_frame == L_FRAME16k && st_fx->core_brate >= MIN_RATE_4SBFR ) { nbits = 2; } #endif - nb_frame_flg = (Word16)get_next_indice(st_fx, nbits); + nb_frame_flg = (Word16) get_next_indice( st_fx, nbits ); - IF(s_and(nb_frame_flg,0x1) == 0) + IF( s_and( nb_frame_flg, 0x1 ) == 0 ) { nb_subfr = 2 * SWNB_SUBFR; move16(); hGSCDec->cor_strong_limit = 0; move16(); } -#ifdef ADD_LRTD - else if (st_fx->L_frame == L_FRAME16k && st_fx->core_brate >= MIN_RATE_4SBFR) +#ifdef ADD_LRTD + else if ( st_fx->L_frame == L_FRAME16k && st_fx->core_brate >= MIN_RATE_4SBFR ) { nb_subfr = 2 * SWNB_SUBFR; /* cor_strong already set to 1 */ } - if ((nb_frame_flg >> 1) == 1) + if ( ( nb_frame_flg >> 1 ) == 1 ) { nb_subfr *= 2; } @@ -206,12 +208,12 @@ void decod_audio_fx( * Decode the last band where the adaptive (pitch) contribution is significant *---------------------------------------------------------------*/ - IF( LT_32(st_fx->core_brate,CFREQ_BITRATE)) + IF( LT_32( st_fx->core_brate, CFREQ_BITRATE ) ) { nbits = 3; move16(); test(); - if( LT_32(st_fx->core_brate,ACELP_9k60)&&(EQ_16(st_fx->coder_type,INACTIVE))) + if ( LT_32( st_fx->core_brate, ACELP_9k60 ) && ( EQ_16( st_fx->coder_type, INACTIVE ) ) ) { nbits = 1; move16(); @@ -223,30 +225,30 @@ void decod_audio_fx( move16(); } test(); - IF( LT_32(st_fx->core_brate,ACELP_9k60)&&NE_16(st_fx->coder_type,INACTIVE)) + IF( LT_32( st_fx->core_brate, ACELP_9k60 ) && NE_16( st_fx->coder_type, INACTIVE ) ) { pit_band_idx = 1; move16(); } ELSE { - pit_band_idx = (Word16)get_next_indice( st_fx, nbits ); + pit_band_idx = (Word16) get_next_indice( st_fx, nbits ); } IF( pit_band_idx != 0 ) { - IF( LT_32(st_fx->core_brate,ACELP_9k60)) + IF( LT_32( st_fx->core_brate, ACELP_9k60 ) ) { - pit_band_idx = 7+BAND1k2; - move16(); /* At low rate, if pitch model is chosen, then for to be use on extented and constant frequency range */ + pit_band_idx = 7 + BAND1k2; + move16(); /* At low rate, if pitch model is chosen, then for to be use on extented and constant frequency range */ } ELSE { - pit_band_idx = add(pit_band_idx, BAND1k2); + pit_band_idx = add( pit_band_idx, BAND1k2 ); } /* detect bit errors in the bitstream */ - IF( GT_16(pit_band_idx,13)) /* The maximum decodable index is 10 + BAND1k2 (3) = 13 */ + IF( GT_16( pit_band_idx, 13 ) ) /* The maximum decodable index is 10 + BAND1k2 (3) = 13 */ { pit_band_idx = 13; move16(); @@ -264,61 +266,61 @@ void decod_audio_fx( * Decode adaptive (pitch) excitation contribution * Reset unvaluable part of the adaptive (pitch) excitation contribution *--------------------------------------------------------------------------------------*/ - IF( GT_16(pit_band_idx,BAND1k2)) + IF( GT_16( pit_band_idx, BAND1k2 ) ) { /*---------------------------------------------------------------* * Decode adaptive (pitch) excitation contribution *---------------------------------------------------------------*/ test(); -#ifdef ADD_LRTD - if (!(st_fx->GSC_IVAS_mode > 0 && st_fx->L_frame / nb_subfr == 2 * L_SUBFR && st_fx->GSC_IVAS_mode < 3) && - ((st_fx->core_brate >= MIN_RATE_FCB || st_fx->GSC_noisy_speech) && - ((nb_subfr == NB_SUBFR && st_fx->L_frame == L_FRAME) || (nb_subfr == NB_SUBFR16k && st_fx->L_frame == L_FRAME16k)))) -#else - IF( EQ_16(st_fx->GSC_noisy_speech,1)&&EQ_16(nb_subfr,NB_SUBFR)) +#ifdef ADD_LRTD + if ( !( st_fx->GSC_IVAS_mode > 0 && st_fx->L_frame / nb_subfr == 2 * L_SUBFR && st_fx->GSC_IVAS_mode < 3 ) && + ( ( st_fx->core_brate >= MIN_RATE_FCB || st_fx->GSC_noisy_speech ) && + ( ( nb_subfr == NB_SUBFR && st_fx->L_frame == L_FRAME ) || ( nb_subfr == NB_SUBFR16k && st_fx->L_frame == L_FRAME16k ) ) ) ) +#else + IF( EQ_16( st_fx->GSC_noisy_speech, 1 ) && EQ_16( nb_subfr, NB_SUBFR ) ) #endif { Word16 indice; - nbits = Es_pred_bits_tbl[BIT_ALLOC_IDX_fx(st_fx->core_brate, GENERIC, -1, -1)]; + nbits = Es_pred_bits_tbl[BIT_ALLOC_IDX_fx( st_fx->core_brate, GENERIC, -1, -1 )]; move16(); - IF (GT_16(st_fx->element_mode, EVS_MONO)) + IF( GT_16( st_fx->element_mode, EVS_MONO ) ) { nbits = 5; move16(); } - indice = get_next_indice(st_fx, nbits); + indice = get_next_indice( st_fx, nbits ); - Es_pred_dec_fx( &Es_pred, indice, nbits, 0); + Es_pred_dec_fx( &Es_pred, indice, nbits, 0 ); } -#ifdef ADD_LRTD - dec_pit_exc_fx(st_fx, Aq, coder_type, Es_pred, pitch_buf, code, exc, bwe_exc, nb_subfr, gain_buf, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf); -#else - dec_pit_exc_fx(st_fx, Aq, st_fx->coder_type, Es_pred, pitch_buf, code, exc, bwe_exc, nb_subfr, gain_buf); +#ifdef ADD_LRTD + dec_pit_exc_fx( st_fx, Aq, coder_type, Es_pred, pitch_buf, code, exc, bwe_exc, nb_subfr, gain_buf, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); +#else + dec_pit_exc_fx( st_fx, Aq, st_fx->coder_type, Es_pred, pitch_buf, code, exc, bwe_exc, nb_subfr, gain_buf ); #endif - IF( LT_32(st_fx->core_brate,ACELP_9k60)) + IF( LT_32( st_fx->core_brate, ACELP_9k60 ) ) { - minimum_fx(pitch_buf, shr(st_fx->L_frame, 6), &low_pit); - low_pit = shr(low_pit, 6); /*Q6 -> Q0 */ + minimum_fx( pitch_buf, shr( st_fx->L_frame, 6 ), &low_pit ); + low_pit = shr( low_pit, 6 ); /*Q6 -> Q0 */ - IF( LT_16(low_pit,64)) + IF( LT_16( low_pit, 64 ) ) { - pit_band_idx = 9+BAND1k2; + pit_band_idx = 9 + BAND1k2; move16(); - if(EQ_16(st_fx->bwidth,NB)) + if ( EQ_16( st_fx->bwidth, NB ) ) { - pit_band_idx = 7+BAND1k2; + pit_band_idx = 7 + BAND1k2; move16(); } } - ELSE IF ( LT_16(low_pit,128)) + ELSE IF( LT_16( low_pit, 128 ) ) { - pit_band_idx = 5+BAND1k2; + pit_band_idx = 5 + BAND1k2; move16(); } ELSE { - pit_band_idx = 3+BAND1k2; + pit_band_idx = 3 + BAND1k2; move16(); } @@ -331,57 +333,57 @@ void decod_audio_fx( /*---------------------------------------------------------------* * DCT transform *---------------------------------------------------------------*/ - edct_16fx( exc, dct_epit, st_fx->L_frame, 7 , st_fx->element_mode); + edct_16fx( exc, dct_epit, st_fx->L_frame, 7, st_fx->element_mode ); /*---------------------------------------------------------------* * Reset unvaluable part of the adaptive (pitch) excitation contribution *---------------------------------------------------------------*/ - max_len = sub(st_fx->L_frame, Diff_len ); + max_len = sub( st_fx->L_frame, Diff_len ); - if(EQ_16(st_fx->bwidth,NB)) + if ( EQ_16( st_fx->bwidth, NB ) ) { - max_len = sub(160,Diff_len); + max_len = sub( 160, Diff_len ); } Len = 80; move16(); - if( max_len < 80 ) + if ( max_len < 80 ) { Len = max_len; move16(); } test(); - IF(EQ_32(st_fx->core_brate,ACELP_8k00)&&NE_16(st_fx->bwidth,NB)) + IF( EQ_32( st_fx->core_brate, ACELP_8k00 ) && NE_16( st_fx->bwidth, NB ) ) { - FOR (i=0; i < max_len; i++) + FOR( i = 0; i < max_len; i++ ) { - dct_epit[i+Diff_len] = 0; + dct_epit[i + Diff_len] = 0; move16(); } } ELSE { - FOR (i = 0; i < Len; i++) + FOR( i = 0; i < Len; i++ ) { - dct_epit[i + Diff_len] = mult_r(dct_epit[i + Diff_len],sm_table_fx[i]); + dct_epit[i + Diff_len] = mult_r( dct_epit[i + Diff_len], sm_table_fx[i] ); move16(); } - FOR (; i < max_len; i++) + FOR( ; i < max_len; i++ ) { dct_epit[i + Diff_len] = 0; move16(); } } - //PMT("in the rare case of 4 subfr, bfi_pitch_fx might be wrong") - st_fx->bfi_pitch_fx = mean_fx(pitch_buf, nb_subfr); + // PMT("in the rare case of 4 subfr, bfi_pitch_fx might be wrong") + st_fx->bfi_pitch_fx = mean_fx( pitch_buf, nb_subfr ); move16(); st_fx->bfi_pitch_frame = st_fx->L_frame; move16(); - Diff_len = add(Diff_len,1); + Diff_len = add( Diff_len, 1 ); st_fx->bpf_off = 0; move16(); } @@ -390,20 +392,20 @@ void decod_audio_fx( /* No adaptive (pitch) excitation contribution */ st_fx->bpf_off = 1; move16(); - set16_fx(dct_epit, 0, st_fx->L_frame); + set16_fx( dct_epit, 0, st_fx->L_frame ); - IF (EQ_16(st_fx->L_frame, L_FRAME16k)) + IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { - set16_fx(pitch_buf, shl(L_SUBFR16k, 6), NB_SUBFR16k); + set16_fx( pitch_buf, shl( L_SUBFR16k, 6 ), NB_SUBFR16k ); } ELSE { - set16_fx(pitch_buf, shl(L_SUBFR, 6), NB_SUBFR); + set16_fx( pitch_buf, shl( L_SUBFR, 6 ), NB_SUBFR ); } - set16_fx( gain_buf, 0, NB_SUBFR16k); + set16_fx( gain_buf, 0, NB_SUBFR16k ); - st_fx->bfi_pitch_fx = shl(L_SUBFR,6); + st_fx->bfi_pitch_fx = shl( L_SUBFR, 6 ); st_fx->bfi_pitch_frame = st_fx->L_frame; move16(); st_fx->lp_gainp_fx = 0; @@ -427,73 +429,72 @@ void decod_audio_fx( tmp_nb_bits_tot = st_fx->next_bit_pos; move16(); #ifdef IVAS_CODE - if( st_fx->extl_brate_fx_orig > 0 ) -#else - if( st_fx->extl_brate > 0 ) + if ( st_fx->extl_brate_fx_orig > 0 ) +#else + if ( st_fx->extl_brate > 0 ) #endif { /* subtract 1 bit for TBE/BWE BWE flag (bit counted in extl_brate) */ - tmp_nb_bits_tot = sub(tmp_nb_bits_tot, 1); + tmp_nb_bits_tot = sub( tmp_nb_bits_tot, 1 ); } test(); #if defined ADD_LRTD test(); - if( EQ_16(st_fx->coder_type,INACTIVE) && LE_32(st_fx->core_brate,ACELP_9k60) && st_fx->idchan == 0) -#else - if (EQ_16(st_fx->coder_type, INACTIVE) && LE_32(st_fx->core_brate, ACELP_9k60)) + if ( EQ_16( st_fx->coder_type, INACTIVE ) && LE_32( st_fx->core_brate, ACELP_9k60 ) && st_fx->idchan == 0 ) +#else + if ( EQ_16( st_fx->coder_type, INACTIVE ) && LE_32( st_fx->core_brate, ACELP_9k60 ) ) #endif { - tmp_nb_bits_tot = add(tmp_nb_bits_tot,5); + tmp_nb_bits_tot = add( tmp_nb_bits_tot, 5 ); } #ifdef ADD_LRTD - IF (EQ_16(st_fx->idchan, 1) ) + IF( EQ_16( st_fx->idchan, 1 ) ) { - tmp_nb_bits_tot = add(tmp_nb_bits_tot, TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS); - IF (EQ_16(st_fx->tdm_LRTD_flag, 1)) + tmp_nb_bits_tot = add( tmp_nb_bits_tot, TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS ); + IF( EQ_16( st_fx->tdm_LRTD_flag, 1 ) ) { - tmp_nb_bits_tot = sub(tmp_nb_bits_tot, STEREO_BITS_TCA); + tmp_nb_bits_tot = sub( tmp_nb_bits_tot, STEREO_BITS_TCA ); } } #endif - gsc_dec_fx(st_fx, dct_epit, pit_band_idx, Diff_len, tmp_nb_bits_tot, nb_subfr, st_fx->coder_type, &last_bin, lsf_new, exc_wo_nf, st_fx->Q_exc ); + gsc_dec_fx( st_fx, dct_epit, pit_band_idx, Diff_len, tmp_nb_bits_tot, nb_subfr, st_fx->coder_type, &last_bin, lsf_new, exc_wo_nf, st_fx->Q_exc ); /*--------------------------------------------------------------------------------------* * iDCT transform *--------------------------------------------------------------------------------------*/ - edct_16fx( dct_epit, exc, st_fx->L_frame, 7, st_fx->element_mode); - edct_16fx( exc_wo_nf, exc_wo_nf, st_fx->L_frame, 7, st_fx->element_mode); + edct_16fx( dct_epit, exc, st_fx->L_frame, 7, st_fx->element_mode ); + edct_16fx( exc_wo_nf, exc_wo_nf, st_fx->L_frame, 7, st_fx->element_mode ); /*----------------------------------------------------------------------* * Remove potential pre-echo in case an onset has been detected *----------------------------------------------------------------------*/ - pre_echo_att_fx( &hGSCDec->Last_frame_ener_fx, exc, gsc_attack_flag - ,st_fx->Q_exc ,st_fx->last_coder_type, st_fx->L_frame); + pre_echo_att_fx( &hGSCDec->Last_frame_ener_fx, exc, gsc_attack_flag, st_fx->Q_exc, st_fx->last_coder_type, st_fx->L_frame ); /*--------------------------------------------------------------------------------------* * Update BWE excitation *--------------------------------------------------------------------------------------*/ - if (st_fx->hBWE_TD != NULL) + if ( st_fx->hBWE_TD != NULL ) { - set16_fx(voice_factors, 0, NB_SUBFR16k); - IF (EQ_16(st_fx->L_frame, L_FRAME16k)) + set16_fx( voice_factors, 0, NB_SUBFR16k ); + IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { - interp_code_4over2_fx(exc, bwe_exc, st_fx->L_frame); + interp_code_4over2_fx( exc, bwe_exc, st_fx->L_frame ); } ELSE { - interp_code_5over2_fx(exc, bwe_exc, L_FRAME); + interp_code_5over2_fx( exc, bwe_exc, L_FRAME ); } } /*--------------------------------------------------------------------------------------* * Updates *--------------------------------------------------------------------------------------*/ - Copy( exc, exc2, st_fx->L_frame); - Copy( exc_wo_nf, exc, st_fx->L_frame); + Copy( exc, exc2, st_fx->L_frame ); + Copy( exc_wo_nf, exc, st_fx->L_frame ); /*--------------------------------------------------------------------------------------* * Channel aware mode parameters @@ -527,20 +528,21 @@ void decod_audio_fx( /* _ None */ /*==========================================================================*/ void decod_audio_ivas_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - Word16 dct_epit[], /* o : GSC excitation in DCT domain */ - const Word16 *Aq, /* i : LP filter coefficient */ - Word16 *pitch_buf, /* o : floating pitch values for each subframe */ - Word16 *voice_factors, /* o : voicing factors */ - Word16 *exc, /* i/o: adapt. excitation exc */ - Word16 *exc2, /* i/o: adapt. excitation/total exc */ - Word16 *bwe_exc, /* o : excitation for SWB TBE */ - Word16 *lsf_new /* i : ISFs at the end of the frame */ - , Word16 *gain_buf, /*Q14*/ + Decoder_State *st_fx, /* i/o: decoder static memory */ + Word16 dct_epit[], /* o : GSC excitation in DCT domain */ + const Word16 *Aq, /* i : LP filter coefficient */ + Word16 *pitch_buf, /* o : floating pitch values for each subframe */ + Word16 *voice_factors, /* o : voicing factors */ + Word16 *exc, /* i/o: adapt. excitation exc */ + Word16 *exc2, /* i/o: adapt. excitation/total exc */ + Word16 *bwe_exc, /* o : excitation for SWB TBE */ + Word16 *lsf_new /* i : ISFs at the end of the frame */ + , + Word16 *gain_buf, /*Q14*/ const Word16 tdm_lp_reuse_flag, /* i : LPC reuse flag */ const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag */ const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ - const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ + const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ ) { Word16 tmp_nb_bits_tot, pit_band_idx; @@ -567,23 +569,23 @@ void decod_audio_ivas_fx( move16(); /* decode GSC attack flag (used to reduce possible pre-echo) */ - gsc_attack_flag = (Word16)get_next_indice(st_fx, 1); + gsc_attack_flag = (Word16) get_next_indice( st_fx, 1 ); /* decode GSC SWB speech flag */ test(); -#if 0// !defined ADD_LRTD +#if 0 // !defined ADD_LRTD IF(NE_16(st_fx->coder_type, INACTIVE) && GE_32(st_fx->total_brate, ACELP_13k20)) -#else - if (st_fx->GSC_IVAS_mode >= 1 || (st_fx->coder_type != INACTIVE && ((st_fx->element_mode == EVS_MONO && st_fx->total_brate >= ACELP_13k20) || - (st_fx->element_mode > EVS_MONO && st_fx->total_brate > MIN_BRATE_GSC_NOISY_FLAG && st_fx->bwidth >= SWB && !st_fx->flag_ACELP16k)))) +#else + if ( st_fx->GSC_IVAS_mode >= 1 || ( st_fx->coder_type != INACTIVE && ( ( st_fx->element_mode == EVS_MONO && st_fx->total_brate >= ACELP_13k20 ) || + ( st_fx->element_mode > EVS_MONO && st_fx->total_brate > MIN_BRATE_GSC_NOISY_FLAG && st_fx->bwidth >= SWB && !st_fx->flag_ACELP16k ) ) ) ) #endif { - st_fx->GSC_noisy_speech = (Word16)get_next_indice(st_fx, 1); + st_fx->GSC_noisy_speech = (Word16) get_next_indice( st_fx, 1 ); } /* safety check in case of bit errors */ test(); - IF(st_fx->GSC_noisy_speech && LT_16(st_fx->bwidth, SWB) && st_fx->GSC_IVAS_mode == 0) + IF( st_fx->GSC_noisy_speech && LT_16( st_fx->bwidth, SWB ) && st_fx->GSC_IVAS_mode == 0 ) { st_fx->BER_detect = 1; move16(); @@ -591,19 +593,20 @@ void decod_audio_ivas_fx( move16(); } /* set bit-allocation */ -#if 1//def ADD_LRTD - config_acelp1_IVAS(DEC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl_orig, st_fx->extl_brate_orig, st_fx->L_frame, st_fx->GSC_noisy_speech, &(st_fx->acelp_cfg), st_fx->next_bit_pos, st_fx->coder_type, -1, 1, &nbits, NULL, st_fx->element_mode, &nbits /*dummy*/, tdm_lp_reuse_flag, tdm_low_rate_mode, st_fx->idchan, st_fx->active_cnt, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode); +#if 1 // def ADD_LRTD + config_acelp1_IVAS( DEC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl_orig, st_fx->extl_brate_orig, st_fx->L_frame, st_fx->GSC_noisy_speech, &( st_fx->acelp_cfg ), st_fx->next_bit_pos, st_fx->coder_type, -1, 1, &nbits, NULL, st_fx->element_mode, &nbits /*dummy*/, tdm_lp_reuse_flag, tdm_low_rate_mode, st_fx->idchan, st_fx->active_cnt, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode ); #else - config_acelp1(DEC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl_orig, st_fx->extl_brate_orig, st_fx->L_frame, st_fx->GSC_noisy_speech, &(st_fx->acelp_cfg), st_fx->next_bit_pos, st_fx->coder_type, -1, 1, &nbits, NULL, st_fx->element_mode, &nbits /*dummy*/, 0, 0, st_fx->idchan, st_fx->active_cnt, 0, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode); + config_acelp1( DEC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl_orig, st_fx->extl_brate_orig, st_fx->L_frame, st_fx->GSC_noisy_speech, &( st_fx->acelp_cfg ), st_fx->next_bit_pos, st_fx->coder_type, -1, 1, &nbits, NULL, st_fx->element_mode, &nbits /*dummy*/, 0, 0, st_fx->idchan, st_fx->active_cnt, 0, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode ); #endif /*---------------------------------------------------------------* * Decode energy dynamics *---------------------------------------------------------------*/ -#if 1// defined ADD_LRTD - test(); test(); - IF(st_fx->GSC_IVAS_mode >= 1 || (EQ_16(st_fx->GSC_noisy_speech, 1) && st_fx->GSC_IVAS_mode == 0)) -#else - IF(EQ_16(st_fx->GSC_noisy_speech, 1)) +#if 1 // defined ADD_LRTD + test(); + test(); + IF( st_fx->GSC_IVAS_mode >= 1 || ( EQ_16( st_fx->GSC_noisy_speech, 1 ) && st_fx->GSC_IVAS_mode == 0 ) ) +#else + IF( EQ_16( st_fx->GSC_noisy_speech, 1 ) ) #endif { nb_subfr = NB_SUBFR; @@ -612,20 +615,20 @@ void decod_audio_ivas_fx( move16(); hGSCDec->noise_lev = NOISE_LEVEL_SP3; move16(); -#if 1//def ADD_LRTD - if (st_fx->GSC_IVAS_mode >= 1) +#if 1 // def ADD_LRTD + if ( st_fx->GSC_IVAS_mode >= 1 ) { - if (st_fx->core_brate < GSC_L_RATE_STG && st_fx->GSC_IVAS_mode < 3) + if ( st_fx->core_brate < GSC_L_RATE_STG && st_fx->GSC_IVAS_mode < 3 ) { nb_subfr = 2; } hGSCDec->noise_lev = NOISE_LEVEL_SP2; - if (st_fx->GSC_IVAS_mode == 3) /* Music like */ + if ( st_fx->GSC_IVAS_mode == 3 ) /* Music like */ { hGSCDec->noise_lev = NOISE_LEVEL_SP0; } - else if (st_fx->GSC_noisy_speech == 0) /* speech like but not noisy */ + else if ( st_fx->GSC_noisy_speech == 0 ) /* speech like but not noisy */ { hGSCDec->noise_lev = NOISE_LEVEL_SP3; } @@ -634,81 +637,81 @@ void decod_audio_ivas_fx( } ELSE { - IF(LE_32(st_fx->core_brate,ACELP_8k00)) + IF( LE_32( st_fx->core_brate, ACELP_8k00 ) ) { - hGSCDec->noise_lev = add((Word16)get_next_indice(st_fx, 2), NOISE_LEVEL_SP2); + hGSCDec->noise_lev = add( (Word16) get_next_indice( st_fx, 2 ), NOISE_LEVEL_SP2 ); } ELSE { - hGSCDec->noise_lev = add((Word16)get_next_indice(st_fx, 3), NOISE_LEVEL_SP0); + hGSCDec->noise_lev = add( (Word16) get_next_indice( st_fx, 3 ), NOISE_LEVEL_SP0 ); } - /*---------------------------------------------------------------* - * Decode number of subframes - *---------------------------------------------------------------*/ - #if 1//def ADD_LRTD - if (st_fx->L_frame == L_FRAME16k && (st_fx->core_brate <= ACELP_13k20 || st_fx->coder_type == INACTIVE)) - { - hGSCDec->cor_strong_limit = 0; - nb_subfr = 1; - } - else - #endif + /*---------------------------------------------------------------* + * Decode number of subframes + *---------------------------------------------------------------*/ +#if 1 // def ADD_LRTD + if ( st_fx->L_frame == L_FRAME16k && ( st_fx->core_brate <= ACELP_13k20 || st_fx->coder_type == INACTIVE ) ) + { + hGSCDec->cor_strong_limit = 0; + nb_subfr = 1; + } + else +#endif + { + hGSCDec->cor_strong_limit = 1; + move16(); + nb_subfr = SWNB_SUBFR; + move16(); + + IF( GE_32( st_fx->core_brate, ACELP_9k60 ) ) { - hGSCDec->cor_strong_limit = 1; - move16(); - nb_subfr = SWNB_SUBFR; + nbits = 1; move16(); +#if 1 // def ADD_LRTD + if ( st_fx->L_frame == L_FRAME16k && st_fx->core_brate >= MIN_RATE_4SBFR ) + { + nbits = 2; + } +#endif + nb_frame_flg = (Word16) get_next_indice( st_fx, nbits ); - IF(GE_32(st_fx->core_brate,ACELP_9k60)) + IF( s_and( nb_frame_flg, 0x1 ) == 0 ) { - nbits = 1; + nb_subfr = 2 * SWNB_SUBFR; + move16(); + hGSCDec->cor_strong_limit = 0; move16(); - #if 1//def ADD_LRTD - if (st_fx->L_frame == L_FRAME16k && st_fx->core_brate >= MIN_RATE_4SBFR) - { - nbits = 2; - } - #endif - nb_frame_flg = (Word16)get_next_indice(st_fx, nbits); - - IF(s_and(nb_frame_flg,0x1) == 0) - { - nb_subfr = 2 * SWNB_SUBFR; - move16(); - hGSCDec->cor_strong_limit = 0; - move16(); - } - #if 1//def ADD_LRTD - else if (st_fx->L_frame == L_FRAME16k && st_fx->core_brate >= MIN_RATE_4SBFR) - { - nb_subfr = 2 * SWNB_SUBFR; /* cor_strong already set to 1 */ - } - - if ((nb_frame_flg >> 1) == 1) - { - nb_subfr *= 2; - } - #endif } +#if 1 // def ADD_LRTD + else if ( st_fx->L_frame == L_FRAME16k && st_fx->core_brate >= MIN_RATE_4SBFR ) + { + nb_subfr = 2 * SWNB_SUBFR; /* cor_strong already set to 1 */ + } + + if ( ( nb_frame_flg >> 1 ) == 1 ) + { + nb_subfr *= 2; + } +#endif } + } } #if 1 - if (st_fx->L_frame == L_FRAME16k && nb_subfr == NB_SUBFR) - { - nb_subfr = NB_SUBFR16k; - } + if ( st_fx->L_frame == L_FRAME16k && nb_subfr == NB_SUBFR ) + { + nb_subfr = NB_SUBFR16k; + } #endif /*---------------------------------------------------------------* * Decode the last band where the adaptive (pitch) contribution is significant *---------------------------------------------------------------*/ - IF(LT_32(st_fx->core_brate, CFREQ_BITRATE)) + IF( LT_32( st_fx->core_brate, CFREQ_BITRATE ) ) { nbits = 3; move16(); test(); - if (LT_32(st_fx->core_brate, ACELP_9k60) && (EQ_16(st_fx->coder_type, INACTIVE))) + if ( LT_32( st_fx->core_brate, ACELP_9k60 ) && ( EQ_16( st_fx->coder_type, INACTIVE ) ) ) { nbits = 1; move16(); @@ -720,30 +723,30 @@ void decod_audio_ivas_fx( move16(); } test(); - IF(LT_32(st_fx->core_brate, ACELP_9k60) && NE_16(st_fx->coder_type, INACTIVE)) + IF( LT_32( st_fx->core_brate, ACELP_9k60 ) && NE_16( st_fx->coder_type, INACTIVE ) ) { pit_band_idx = 1; move16(); } ELSE { - pit_band_idx = (Word16)get_next_indice(st_fx, nbits); + pit_band_idx = (Word16) get_next_indice( st_fx, nbits ); } - IF(pit_band_idx != 0) + IF( pit_band_idx != 0 ) { - IF(LT_32(st_fx->core_brate, ACELP_9k60)) + IF( LT_32( st_fx->core_brate, ACELP_9k60 ) ) { pit_band_idx = 7 + BAND1k2; - move16(); /* At low rate, if pitch model is chosen, then for to be use on extented and constant frequency range */ + move16(); /* At low rate, if pitch model is chosen, then for to be use on extented and constant frequency range */ } ELSE { - pit_band_idx = add(pit_band_idx, BAND1k2); + pit_band_idx = add( pit_band_idx, BAND1k2 ); } - /* detect bit errors in the bitstream */ - IF(GT_16(pit_band_idx, 13)) /* The maximum decodable index is 10 + BAND1k2 (3) = 13 */ + /* detect bit errors in the bitstream */ + IF( GT_16( pit_band_idx, 13 ) ) /* The maximum decodable index is 10 + BAND1k2 (3) = 13 */ { pit_band_idx = 13; move16(); @@ -761,54 +764,54 @@ void decod_audio_ivas_fx( * Decode adaptive (pitch) excitation contribution * Reset unvaluable part of the adaptive (pitch) excitation contribution *--------------------------------------------------------------------------------------*/ - IF(GT_16(pit_band_idx, BAND1k2)) + IF( GT_16( pit_band_idx, BAND1k2 ) ) { /*---------------------------------------------------------------* * Decode adaptive (pitch) excitation contribution *---------------------------------------------------------------*/ test(); -#if 1//def ADD_LRTD - if (!(st_fx->GSC_IVAS_mode > 0 && st_fx->L_frame / nb_subfr == 2 * L_SUBFR && st_fx->GSC_IVAS_mode < 3) && - ((st_fx->core_brate >= MIN_RATE_FCB || st_fx->GSC_noisy_speech) && - ((nb_subfr == NB_SUBFR && st_fx->L_frame == L_FRAME) || (nb_subfr == NB_SUBFR16k && st_fx->L_frame == L_FRAME16k)))) -#else - IF(EQ_16(st_fx->GSC_noisy_speech, 1) && EQ_16(nb_subfr, NB_SUBFR)) +#if 1 // def ADD_LRTD + if ( !( st_fx->GSC_IVAS_mode > 0 && st_fx->L_frame / nb_subfr == 2 * L_SUBFR && st_fx->GSC_IVAS_mode < 3 ) && + ( ( st_fx->core_brate >= MIN_RATE_FCB || st_fx->GSC_noisy_speech ) && + ( ( nb_subfr == NB_SUBFR && st_fx->L_frame == L_FRAME ) || ( nb_subfr == NB_SUBFR16k && st_fx->L_frame == L_FRAME16k ) ) ) ) +#else + IF( EQ_16( st_fx->GSC_noisy_speech, 1 ) && EQ_16( nb_subfr, NB_SUBFR ) ) #endif { Word16 indice; - nbits = Es_pred_bits_tbl[BIT_ALLOC_IDX_fx(st_fx->core_brate, GENERIC, -1, -1)]; + nbits = Es_pred_bits_tbl[BIT_ALLOC_IDX_fx( st_fx->core_brate, GENERIC, -1, -1 )]; move16(); - IF(GT_16(st_fx->element_mode, EVS_MONO)) + IF( GT_16( st_fx->element_mode, EVS_MONO ) ) { nbits = 5; move16(); } - indice = get_next_indice(st_fx, nbits); + indice = get_next_indice( st_fx, nbits ); - Es_pred_dec_fx(&Es_pred, indice, nbits, 0); + Es_pred_dec_fx( &Es_pred, indice, nbits, 0 ); } -#if 1//def ADD_LRTD - dec_pit_exc_ivas_fx(st_fx, Aq, st_fx->coder_type, Es_pred, pitch_buf, code, exc, bwe_exc, nb_subfr, gain_buf, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf); -#else - dec_pit_exc_fx(st_fx, Aq, st_fx->coder_type, Es_pred, pitch_buf, code, exc, bwe_exc, nb_subfr, gain_buf); +#if 1 // def ADD_LRTD + dec_pit_exc_ivas_fx( st_fx, Aq, st_fx->coder_type, Es_pred, pitch_buf, code, exc, bwe_exc, nb_subfr, gain_buf, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); +#else + dec_pit_exc_fx( st_fx, Aq, st_fx->coder_type, Es_pred, pitch_buf, code, exc, bwe_exc, nb_subfr, gain_buf ); #endif - IF(LT_32(st_fx->core_brate, ACELP_9k60)) + IF( LT_32( st_fx->core_brate, ACELP_9k60 ) ) { - minimum_fx(pitch_buf, shr(st_fx->L_frame, 6), &low_pit); - low_pit = shr(low_pit, 6); /*Q6 -> Q0 */ + minimum_fx( pitch_buf, shr( st_fx->L_frame, 6 ), &low_pit ); + low_pit = shr( low_pit, 6 ); /*Q6 -> Q0 */ - IF(LT_16(low_pit, 64)) + IF( LT_16( low_pit, 64 ) ) { pit_band_idx = 9 + BAND1k2; move16(); - if (EQ_16(st_fx->bwidth, NB)) + if ( EQ_16( st_fx->bwidth, NB ) ) { pit_band_idx = 7 + BAND1k2; move16(); } } - ELSE IF(LT_16(low_pit, 128)) + ELSE IF( LT_16( low_pit, 128 ) ) { pit_band_idx = 5 + BAND1k2; move16(); @@ -828,31 +831,31 @@ void decod_audio_ivas_fx( /*---------------------------------------------------------------* * DCT transform *---------------------------------------------------------------*/ - edct_16fx(exc, dct_epit, st_fx->L_frame, 7, st_fx->element_mode); + edct_16fx( exc, dct_epit, st_fx->L_frame, 7, st_fx->element_mode ); /*---------------------------------------------------------------* * Reset unvaluable part of the adaptive (pitch) excitation contribution *---------------------------------------------------------------*/ - max_len = sub(st_fx->L_frame, Diff_len); + max_len = sub( st_fx->L_frame, Diff_len ); - if (EQ_16(st_fx->bwidth, NB)) + if ( EQ_16( st_fx->bwidth, NB ) ) { - max_len = sub(160, Diff_len); + max_len = sub( 160, Diff_len ); } Len = 80; move16(); - if (max_len < 80) + if ( max_len < 80 ) { Len = max_len; move16(); } test(); - IF(EQ_32(st_fx->core_brate, ACELP_8k00) && NE_16(st_fx->bwidth, NB)) + IF( EQ_32( st_fx->core_brate, ACELP_8k00 ) && NE_16( st_fx->bwidth, NB ) ) { - FOR(i = 0; i < max_len; i++) + FOR( i = 0; i < max_len; i++ ) { dct_epit[i + Diff_len] = 0; move16(); @@ -860,25 +863,25 @@ void decod_audio_ivas_fx( } ELSE { - FOR(i = 0; i < Len; i++) + FOR( i = 0; i < Len; i++ ) { - dct_epit[i + Diff_len] = mult_r(dct_epit[i + Diff_len],sm_table_fx[i]); + dct_epit[i + Diff_len] = mult_r( dct_epit[i + Diff_len], sm_table_fx[i] ); move16(); } - FOR(; i < max_len; i++) + FOR( ; i < max_len; i++ ) { dct_epit[i + Diff_len] = 0; move16(); } } - //PMT("in the rare case of 4 subfr, bfi_pitch_fx might be wrong") - st_fx->bfi_pitch_fx = mean_fx(pitch_buf, nb_subfr); + // PMT("in the rare case of 4 subfr, bfi_pitch_fx might be wrong") + st_fx->bfi_pitch_fx = mean_fx( pitch_buf, nb_subfr ); move16(); st_fx->bfi_pitch_frame = st_fx->L_frame; move16(); - Diff_len = add(Diff_len, 1); + Diff_len = add( Diff_len, 1 ); st_fx->bpf_off = 0; move16(); } @@ -887,20 +890,20 @@ void decod_audio_ivas_fx( /* No adaptive (pitch) excitation contribution */ st_fx->bpf_off = 1; move16(); - set16_fx(dct_epit, 0, st_fx->L_frame); + set16_fx( dct_epit, 0, st_fx->L_frame ); - IF(EQ_16(st_fx->L_frame, L_FRAME16k)) + IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { - set16_fx(pitch_buf, shl(L_SUBFR16k, 6), NB_SUBFR16k); + set16_fx( pitch_buf, shl( L_SUBFR16k, 6 ), NB_SUBFR16k ); } ELSE { - set16_fx(pitch_buf, shl(L_SUBFR, 6), NB_SUBFR); + set16_fx( pitch_buf, shl( L_SUBFR, 6 ), NB_SUBFR ); } - set16_fx(gain_buf, 0, NB_SUBFR16k); + set16_fx( gain_buf, 0, NB_SUBFR16k ); - st_fx->bfi_pitch_fx = shl(L_SUBFR,6); + st_fx->bfi_pitch_fx = shl( L_SUBFR, 6 ); st_fx->bfi_pitch_frame = st_fx->L_frame; move16(); st_fx->lp_gainp_fx = 0; @@ -915,89 +918,88 @@ void decod_audio_ivas_fx( move16(); } - /*--------------------------------------------------------------------------------------* - * GSC decoder - *--------------------------------------------------------------------------------------*/ + /*--------------------------------------------------------------------------------------* + * GSC decoder + *--------------------------------------------------------------------------------------*/ - /* find the current total number of bits used */ + /* find the current total number of bits used */ tmp_nb_bits_tot = st_fx->next_bit_pos; move16(); -#if 1//def IVAS_CODE - if (st_fx->extl_brate_orig > 0) -#else - if (st_fx->extl_brate > 0) +#if 1 // def IVAS_CODE + if ( st_fx->extl_brate_orig > 0 ) +#else + if ( st_fx->extl_brate > 0 ) #endif { /* subtract 1 bit for TBE/BWE BWE flag (bit counted in extl_brate) */ - tmp_nb_bits_tot = sub(tmp_nb_bits_tot, 1); + tmp_nb_bits_tot = sub( tmp_nb_bits_tot, 1 ); } test(); -#if 1//defined ADD_LRTD +#if 1 // defined ADD_LRTD test(); - if (EQ_16(st_fx->coder_type, INACTIVE) && LE_32(st_fx->core_brate, ACELP_9k60) && st_fx->idchan == 0) -#else - if (EQ_16(st_fx->coder_type, INACTIVE) && LE_32(st_fx->core_brate, ACELP_9k60)) + if ( EQ_16( st_fx->coder_type, INACTIVE ) && LE_32( st_fx->core_brate, ACELP_9k60 ) && st_fx->idchan == 0 ) +#else + if ( EQ_16( st_fx->coder_type, INACTIVE ) && LE_32( st_fx->core_brate, ACELP_9k60 ) ) #endif { - tmp_nb_bits_tot = add(tmp_nb_bits_tot, 5); + tmp_nb_bits_tot = add( tmp_nb_bits_tot, 5 ); } -#if 1//ydef ADD_LRTD - IF(EQ_16(st_fx->idchan, 1)) +#if 1 // ydef ADD_LRTD + IF( EQ_16( st_fx->idchan, 1 ) ) { - tmp_nb_bits_tot = add(tmp_nb_bits_tot, TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS); - IF(EQ_16(st_fx->tdm_LRTD_flag, 1)) + tmp_nb_bits_tot = add( tmp_nb_bits_tot, TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS ); + IF( EQ_16( st_fx->tdm_LRTD_flag, 1 ) ) { - tmp_nb_bits_tot = sub(tmp_nb_bits_tot, STEREO_BITS_TCA); + tmp_nb_bits_tot = sub( tmp_nb_bits_tot, STEREO_BITS_TCA ); } } #endif - //gsc_dec_fx(st_fx, dct_epit, pit_band_idx, Diff_len, tmp_nb_bits_tot, nb_subfr, st_fx->coder_type, &last_bin, lsf_new, exc_wo_nf, st_fx->Q_exc ); - gsc_dec_ivas_fx(st_fx, dct_epit, pit_band_idx, Diff_len, tmp_nb_bits_tot, nb_subfr, st_fx->coder_type, &last_bin, lsf_new, exc_wo_nf, st_fx->Q_exc); + // gsc_dec_fx(st_fx, dct_epit, pit_band_idx, Diff_len, tmp_nb_bits_tot, nb_subfr, st_fx->coder_type, &last_bin, lsf_new, exc_wo_nf, st_fx->Q_exc ); + gsc_dec_ivas_fx( st_fx, dct_epit, pit_band_idx, Diff_len, tmp_nb_bits_tot, nb_subfr, st_fx->coder_type, &last_bin, lsf_new, exc_wo_nf, st_fx->Q_exc ); /*--------------------------------------------------------------------------------------* * iDCT transform *--------------------------------------------------------------------------------------*/ - edct_16fx(dct_epit, exc, st_fx->L_frame, 7, st_fx->element_mode); - edct_16fx(exc_wo_nf, exc_wo_nf, st_fx->L_frame, 7, st_fx->element_mode); + edct_16fx( dct_epit, exc, st_fx->L_frame, 7, st_fx->element_mode ); + edct_16fx( exc_wo_nf, exc_wo_nf, st_fx->L_frame, 7, st_fx->element_mode ); /*----------------------------------------------------------------------* * Remove potential pre-echo in case an onset has been detected *----------------------------------------------------------------------*/ - pre_echo_att_fx(&hGSCDec->Last_frame_ener_fx, exc, gsc_attack_flag - , st_fx->Q_exc, st_fx->last_coder_type, st_fx->L_frame); + pre_echo_att_fx( &hGSCDec->Last_frame_ener_fx, exc, gsc_attack_flag, st_fx->Q_exc, st_fx->last_coder_type, st_fx->L_frame ); /*--------------------------------------------------------------------------------------* * Update BWE excitation *--------------------------------------------------------------------------------------*/ - if (st_fx->hBWE_TD != NULL) + if ( st_fx->hBWE_TD != NULL ) { - set16_fx(voice_factors, 0, NB_SUBFR16k); - IF(EQ_16(st_fx->L_frame, L_FRAME16k)) + set16_fx( voice_factors, 0, NB_SUBFR16k ); + IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { - interp_code_4over2_fx(exc, bwe_exc, st_fx->L_frame); + interp_code_4over2_fx( exc, bwe_exc, st_fx->L_frame ); } ELSE { - interp_code_5over2_fx(exc, bwe_exc, L_FRAME); + interp_code_5over2_fx( exc, bwe_exc, L_FRAME ); } } /*--------------------------------------------------------------------------------------* * Updates *--------------------------------------------------------------------------------------*/ - Copy(exc, exc2, st_fx->L_frame); - Copy(exc_wo_nf, exc, st_fx->L_frame); + Copy( exc, exc2, st_fx->L_frame ); + Copy( exc_wo_nf, exc, st_fx->L_frame ); /*--------------------------------------------------------------------------------------* * Channel aware mode parameters *--------------------------------------------------------------------------------------*/ - set16_fx(st_fx->tilt_code_dec_fx, 0, NB_SUBFR16k); + set16_fx( st_fx->tilt_code_dec_fx, 0, NB_SUBFR16k ); return; } @@ -1026,21 +1028,20 @@ void decod_audio_ivas_fx( /* _None */ /*==========================================================================*/ void gsc_dec_fx( - Decoder_State *st_fx, /* i/o: State structure */ - Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation */ - const Word16 pit_band_idx, /* i : bin position of the cut-off frequency */ - const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral)*/ - const Word16 bits_used, /* i : Number of bit used before frequency Q */ - const Word16 nb_subfr, /* i : Number of subframe considered */ - const Word16 coder_type, /* i : coding type */ - Word16 *last_bin, /* i : last bin of bit allocation */ - const Word16 *lsf_new, /* i : ISFs at the end of the frame */ - Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill */ - Word16 Q_exc -) + Decoder_State *st_fx, /* i/o: State structure */ + Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation */ + const Word16 pit_band_idx, /* i : bin position of the cut-off frequency */ + const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral)*/ + const Word16 bits_used, /* i : Number of bit used before frequency Q */ + const Word16 nb_subfr, /* i : Number of subframe considered */ + const Word16 coder_type, /* i : coding type */ + Word16 *last_bin, /* i : last bin of bit allocation */ + const Word16 *lsf_new, /* i : ISFs at the end of the frame */ + Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill */ + Word16 Q_exc ) { Word16 i, j, bit, nb_subbands, pvq_len; -#if 1//def ADD_LRTD +#if 1 // def ADD_LRTD Word16 bitallocation_band[MBANDS_GN_BITALLOC16k]; Word16 bitallocation_exc[2]; Word16 Ener_per_bd_iQ[MBANDS_GN_BITALLOC16k]; @@ -1068,8 +1069,8 @@ void gsc_dec_fx( GSC_DEC_HANDLE hGSCDec; hGSCDec = st_fx->hGSCDec; - set16_fx(inpulses_fx, 0,NB_SFM); - set16_fx(imaxpulse_fx, 0,NB_SFM); + set16_fx( inpulses_fx, 0, NB_SFM ); + set16_fx( imaxpulse_fx, 0, NB_SFM ); /*--------------------------------------------------------------------------------------* * Initialization @@ -1077,13 +1078,16 @@ void gsc_dec_fx( bit = bits_used; move16(); #ifdef ADD_LRTD - test(); test(); test(); test(); - IF (EQ_16(coder_type, INACTIVE) && (EQ_16(st_fx->tdm_LRTD_flag, 1) || EQ_16(st_fx->element_mode, IVAS_SCE) ) && LE_32(st_fx->core_brate, GSC_LRES_GAINQ_LIMIT) ) + test(); + test(); + test(); + test(); + IF( EQ_16( coder_type, INACTIVE ) && ( EQ_16( st_fx->tdm_LRTD_flag, 1 ) || EQ_16( st_fx->element_mode, IVAS_SCE ) ) && LE_32( st_fx->core_brate, GSC_LRES_GAINQ_LIMIT ) ) { - bit = add( bit, GSC_LRES_NB_NITS); + bit = add( bit, GSC_LRES_NB_NITS ); } - IF (EQ_16(st_fx->L_frame, L_FRAME16k) ) + IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { Mbands_gn = MBANDS_GN16k; move16(); @@ -1099,14 +1103,15 @@ void gsc_dec_fx( IF( st_fx->bfi || st_fx->BER_detect ) { /* copy old gain */ - Copy(hGSCDec->old_y_gain_fx, Ener_per_bd_iQ, Mbands_gn ); - mean_gain = mult_r(st_fx->lp_gainc_fx,3277); /*Q3*/ - FOR( i=0; iold_y_gain_fx, Ener_per_bd_iQ, Mbands_gn ); + mean_gain = mult_r( st_fx->lp_gainc_fx, 3277 ); /*Q3*/ + FOR( i = 0; i < Mbands_gn; i++ ) { - Ener_per_bd_iQ[i] = add(Ener_per_bd_iQ[i],shl(mean_gain,9)); /*Q12*/ move16(); + Ener_per_bd_iQ[i] = add( Ener_per_bd_iQ[i], shl( mean_gain, 9 ) ); /*Q12*/ + move16(); } - st_fx->lp_gainc_fx = mult_r(st_fx->lp_gainc_fx,32112); /*Q3*/ + st_fx->lp_gainc_fx = mult_r( st_fx->lp_gainc_fx, 32112 ); /*Q3*/ } ELSE { @@ -1114,33 +1119,36 @@ void gsc_dec_fx( #ifdef ADD_LRTD i = 0; move16(); - While (LT_16(i, SIZE_BRATE_INTERMED_TBL)) + While( LT_16( i, SIZE_BRATE_INTERMED_TBL ) ) { - IF (LQ_32(st_fx->core_brate, brate_intermed_tbl[i])) + IF( LQ_32( st_fx->core_brate, brate_intermed_tbl[i] ) ) { break; } - i = add(i,1); + i = add( i, 1 ); } - test(); test(); test(); test(); - IF (GT_16(st_fx->element_mode, EVS_MONO) > && EQ_16(coder_type, AUDIO) && - LE_32(st_fx->core_brate, STEREO_GSC_BIT_RATE_ALLOC) && EQ_32(brate_intermed_tbl[i],ACELP_9k60) ) /* Bit allocation is mapped to 8 kb/s instead of 9.6 kb/s in this case */ + test(); + test(); + test(); + test(); + IF( GT_16( st_fx->element_mode, EVS_MONO ) > &&EQ_16( coder_type, AUDIO ) && + LE_32( st_fx->core_brate, STEREO_GSC_BIT_RATE_ALLOC ) && EQ_32( brate_intermed_tbl[i], ACELP_9k60 ) ) /* Bit allocation is mapped to 8 kb/s instead of 9.6 kb/s in this case */ { i--; } - mean_gain = gsc_gaindec_fx(st_fx, Ener_per_bd_iQ, brate_intermed_tbl[i], hGSCDec->old_y_gain_fx, coder_type, st_fx->bwidth); + mean_gain = gsc_gaindec_fx( st_fx, Ener_per_bd_iQ, brate_intermed_tbl[i], hGSCDec->old_y_gain_fx, coder_type, st_fx->bwidth ); -#else +#else mean_gain = gsc_gaindec_fx( st_fx, Ener_per_bd_iQ, st_fx->core_brate, hGSCDec->old_y_gain_fx, coder_type, st_fx->bwidth ); #endif - st_fx->lp_gainc_fx = mult_r(640,mean_gain); /*10 in Q6 x Q12 -> lp_gainc in Q3 */ + st_fx->lp_gainc_fx = mult_r( 640, mean_gain ); /*10 in Q6 x Q12 -> lp_gainc in Q3 */ } *last_bin = 0; move16(); test(); - IF( EQ_32(st_fx->core_brate,ACELP_8k00)&&NE_16(st_fx->bwidth,NB)) + IF( EQ_32( st_fx->core_brate, ACELP_8k00 ) && NE_16( st_fx->bwidth, NB ) ) { bitallocation_exc[0] = 0; move16(); @@ -1151,7 +1159,7 @@ void gsc_dec_fx( set16_fx( bitallocation_band, 0, MBANDS_GN ); test(); - IF( (EQ_16(st_fx->bfi,1))||st_fx->BER_detect) + IF( ( EQ_16( st_fx->bfi, 1 ) ) || st_fx->BER_detect ) { /*--------------------------------------------------------------------------------------* * Copy old spectrum @@ -1163,23 +1171,23 @@ void gsc_dec_fx( move16(); #endif test(); - IF( EQ_16(st_fx->last_good,INACTIVE_CLAS)||EQ_16(st_fx->Last_GSC_noisy_speech_flag,1)) + IF( EQ_16( st_fx->last_good, INACTIVE_CLAS ) || EQ_16( st_fx->Last_GSC_noisy_speech_flag, 1 ) ) { - FOR( i=0; iL_frame; i++ ) + FOR( i = 0; i < st_fx->L_frame; i++ ) { - L_tmp = L_shr(L_mult(Random(&hGSCDec->seed_tcx),26214),5); /*Q10*/ - L_tmp = L_mac(L_tmp, hGSCDec->Last_GSC_spectrum_fx[i],6554); - hGSCDec->Last_GSC_spectrum_fx[i] = round_fx(L_tmp); /*Q10*/ + L_tmp = L_shr( L_mult( Random( &hGSCDec->seed_tcx ), 26214 ), 5 ); /*Q10*/ + L_tmp = L_mac( L_tmp, hGSCDec->Last_GSC_spectrum_fx[i], 6554 ); + hGSCDec->Last_GSC_spectrum_fx[i] = round_fx( L_tmp ); /*Q10*/ } } - Copy(hGSCDec->Last_GSC_spectrum_fx, exc_diffQ, st_fx->L_frame); + Copy( hGSCDec->Last_GSC_spectrum_fx, exc_diffQ, st_fx->L_frame ); - FOR( i=0; i< st_fx->L_frame; i++ ) + FOR( i = 0; i < st_fx->L_frame; i++ ) { - hGSCDec->Last_GSC_spectrum_fx[i] = mult_r(hGSCDec->Last_GSC_spectrum_fx[i],24576); /*Q10*/ move16(); + hGSCDec->Last_GSC_spectrum_fx[i] = mult_r( hGSCDec->Last_GSC_spectrum_fx[i], 24576 ); /*Q10*/ + move16(); } - } ELSE { @@ -1187,19 +1195,19 @@ void gsc_dec_fx( * PVQ decoder *--------------------------------------------------------------------------------------*/ - bands_and_bit_alloc_fx(hGSCDec->cor_strong_limit, hGSCDec->noise_lev, st_fx->core_brate, Diff_len, bit, &bit, Ener_per_bd_iQ, - max_ener_band, bits_per_bands, &nb_subbands, NULL, NULL, &pvq_len, coder_type, st_fx->bwidth, st_fx->GSC_noisy_speech, - st_fx->L_frame, st_fx->element_mode, st_fx->GSC_IVAS_mode ); + bands_and_bit_alloc_fx( hGSCDec->cor_strong_limit, hGSCDec->noise_lev, st_fx->core_brate, Diff_len, bit, &bit, Ener_per_bd_iQ, + max_ener_band, bits_per_bands, &nb_subbands, NULL, NULL, &pvq_len, coder_type, st_fx->bwidth, st_fx->GSC_noisy_speech, + st_fx->L_frame, st_fx->element_mode, st_fx->GSC_IVAS_mode ); #ifdef ADD_LRTD - if (bit == 0) + if ( bit == 0 ) { - set16_fx(concact_out, 0, L_FRAME16k); + set16_fx( concact_out, 0, L_FRAME16k ); } #endif { - pvq_core_dec_fx(st_fx, gsc_sfm_start, gsc_sfm_end, gsc_sfm_size, concat_out, &Q_tmp, bit, nb_subbands, bits_per_bands, NULL, inpulses_fx, imaxpulse_fx, ACELP_CORE); - Scale_sig(concat_out, gsc_sfm_end[nb_subbands - 1], sub(Q_PVQ_OUT, Q_tmp)); + pvq_core_dec_fx( st_fx, gsc_sfm_start, gsc_sfm_end, gsc_sfm_size, concat_out, &Q_tmp, bit, nb_subbands, bits_per_bands, NULL, inpulses_fx, imaxpulse_fx, ACELP_CORE ); + Scale_sig( concat_out, gsc_sfm_end[nb_subbands - 1], sub( Q_PVQ_OUT, Q_tmp ) ); } seed_init = 0; move16(); @@ -1208,39 +1216,39 @@ void gsc_dec_fx( max_eq = 0.0f; max_eq_val = 1.0f; - if (((st_fx->core_brate < ACELP_7k20 && st_fx->GSC_noisy_speech == 1) || st_fx->core_brate < 6000) && coder_type <= UNVOICED) + if ( ( ( st_fx->core_brate < ACELP_7k20 && st_fx->GSC_noisy_speech == 1 ) || st_fx->core_brate < 6000 ) && coder_type <= UNVOICED ) { - j = emaximum(concat_out, nb_subbands * 16, &max_eq); - max_eq = (float)(max_eq_val / (fabs(concat_out[j]) + 0.01f)); - max_eq = min(max_eq_val, max_eq); + j = emaximum( concat_out, nb_subbands * 16, &max_eq ); + max_eq = (float) ( max_eq_val / ( fabs( concat_out[j] ) + 0.01f ) ); + max_eq = min( max_eq_val, max_eq ); } #endif /* Reorder Q bands */ - FOR(j = 0; j < nb_subbands; j++) + FOR( j = 0; j < nb_subbands; j++ ) { - Copy( concat_out+j*16, exc_diffQ + max_ener_band[j]*16, 16); + Copy( concat_out + j * 16, exc_diffQ + max_ener_band[j] * 16, 16 ); - *last_bin = s_max(*last_bin,max_ener_band[j]); + *last_bin = s_max( *last_bin, max_ener_band[j] ); move16(); bitallocation_band[max_ener_band[j]] = 1; move16(); - seed_init =add(seed_init,inpulses_fx[j]); + seed_init = add( seed_init, inpulses_fx[j] ); } test(); - IF( NE_16(st_fx->last_coder_type, AUDIO) /* First audio frame */ - && NE_16(st_fx->last_coder_type, UNVOICED) )/* last_coder_type == INACTIVE is overwritten in update_dec to UNVOICED */ + IF( NE_16( st_fx->last_coder_type, AUDIO ) /* First audio frame */ + && NE_16( st_fx->last_coder_type, UNVOICED ) ) /* last_coder_type == INACTIVE is overwritten in update_dec to UNVOICED */ { - FOR( j = 0; j < shl(nb_subbands,4); j++ ) + FOR( j = 0; j < shl( nb_subbands, 4 ); j++ ) { IF( concat_out[j] > 0 ) { - seed_init = extract_l(L_shl(seed_init,3)); + seed_init = extract_l( L_shl( seed_init, 3 ) ); } IF( concat_out[j] < 0 ) { - seed_init = add(seed_init,3); + seed_init = add( seed_init, 3 ); move16(); } } @@ -1249,15 +1257,15 @@ void gsc_dec_fx( move16(); } test(); - IF( EQ_32(st_fx->core_brate,ACELP_8k00)&&NE_16(st_fx->bwidth,NB)) + IF( EQ_32( st_fx->core_brate, ACELP_8k00 ) && NE_16( st_fx->bwidth, NB ) ) { - if( exc_diffQ[L_FRAME8k - 2] != 0 ) + if ( exc_diffQ[L_FRAME8k - 2] != 0 ) { bitallocation_exc[0] = 1; move16(); } - if( exc_diffQ[L_FRAME8k - 1] != 0 ) + if ( exc_diffQ[L_FRAME8k - 1] != 0 ) { bitallocation_exc[1] = 1; move16(); @@ -1272,27 +1280,32 @@ void gsc_dec_fx( * Gain is based on the inter-correlation gain between the pulses found and residual signal *--------------------------------------------------------------------------------------*/ #ifdef ADD_LRTD - test(); test(); test(); test(); test(); test(); - IF (GE_16(st_fx->GSC_IVAS_mode, 1) && EQ_16(st_fx->GSC_noisy_speech, 1)) + test(); + test(); + test(); + test(); + test(); + test(); + IF( GE_16( st_fx->GSC_IVAS_mode, 1 ) && EQ_16( st_fx->GSC_noisy_speech, 1 ) ) { - FOR (i = 64; i < st_fx->L_frame; i++) + FOR( i = 64; i < st_fx->L_frame; i++ ) { - PMT("GSC FIX point to be done here") - exc_diffQ[i] *= max_eq; + PMT( "GSC FIX point to be done here" ) + exc_diffQ[i] *= max_eq; } } - ELSE IF (((LT_32(st_fx->core_brate, ACELP_7k20) && EQ_16(st_fx->GSC_noisy_speech, 1) ) || LT_32(st_fx->core_brate, 6000) ) && LE_16(st_fx->coder_type, UNVOICED)) + ELSE IF( ( ( LT_32( st_fx->core_brate, ACELP_7k20 ) && EQ_16( st_fx->GSC_noisy_speech, 1 ) ) || LT_32( st_fx->core_brate, 6000 ) ) && LE_16( st_fx->coder_type, UNVOICED ) ) { - FOR (i = 0; i < L_FRAME; i++) + FOR( i = 0; i < L_FRAME; i++ ) { - PMT("GSC FIX point to be done here") + PMT( "GSC FIX point to be done here" ) exc_diffQ[i] *= max_eq; } } else #endif { - freq_dnw_scaling_fx(hGSCDec->cor_strong_limit, st_fx->coder_type, hGSCDec->noise_lev, st_fx->core_brate, exc_diffQ, Qexc_diffQ, st_fx->L_frame); + freq_dnw_scaling_fx( hGSCDec->cor_strong_limit, st_fx->coder_type, hGSCDec->noise_lev, st_fx->core_brate, exc_diffQ, Qexc_diffQ, st_fx->L_frame ); } } @@ -1303,15 +1316,12 @@ void gsc_dec_fx( highband_exc_dct_in_fx( st_fx->core_brate, mfreq_bindiv_loc, *last_bin, Diff_len, hGSCDec->noise_lev, pit_band_idx, exc_diffQ, &hGSCDec->seed_tcx, Ener_per_bd_iQ, nb_subfr, exc_dct_in, st_fx->last_coder_type, bitallocation_band, lsf_new, hGSCDec->last_exc_dct_in_fx, &hGSCDec->last_ener_fx, hGSCDec->last_bitallocation_band, bitallocation_exc, st_fx->bfi, coder_type, - st_fx->bwidth, exc_wo_nf, Qexc_diffQ, Q_exc, st_fx->GSC_noisy_speech, hGSCDec->lt_ener_per_band_fx - , st_fx->L_frame, st_fx->element_mode, st_fx->GSC_IVAS_mode - ); + st_fx->bwidth, exc_wo_nf, Qexc_diffQ, Q_exc, st_fx->GSC_noisy_speech, hGSCDec->lt_ener_per_band_fx, st_fx->L_frame, st_fx->element_mode, st_fx->GSC_IVAS_mode ); exc_dct_in[0] = 0; move16(); return; - } /*==========================================================================*/ @@ -1338,21 +1348,20 @@ void gsc_dec_fx( /* _None */ /*==========================================================================*/ void gsc_dec_ivas_fx( - Decoder_State *st_fx, /* i/o: State structure */ - Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation */ - const Word16 pit_band_idx, /* i : bin position of the cut-off frequency */ - const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral)*/ - const Word16 bits_used, /* i : Number of bit used before frequency Q */ - const Word16 nb_subfr, /* i : Number of subframe considered */ - const Word16 coder_type, /* i : coding type */ - Word16 *last_bin, /* i : last bin of bit allocation */ - const Word16 *lsf_new, /* i : ISFs at the end of the frame */ - Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill */ - Word16 Q_exc -) + Decoder_State *st_fx, /* i/o: State structure */ + Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation */ + const Word16 pit_band_idx, /* i : bin position of the cut-off frequency */ + const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral)*/ + const Word16 bits_used, /* i : Number of bit used before frequency Q */ + const Word16 nb_subfr, /* i : Number of subframe considered */ + const Word16 coder_type, /* i : coding type */ + Word16 *last_bin, /* i : last bin of bit allocation */ + const Word16 *lsf_new, /* i : ISFs at the end of the frame */ + Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill */ + Word16 Q_exc ) { Word16 i, j, bit, nb_subbands, pvq_len; -#if 1//def ADD_LRTD +#if 1 // def ADD_LRTD Word16 bitallocation_band[MBANDS_GN_BITALLOC16k]; Word16 bitallocation_exc[2]; Word16 Ener_per_bd_iQ[MBANDS_GN_BITALLOC16k]; @@ -1381,79 +1390,86 @@ void gsc_dec_ivas_fx( GSC_DEC_HANDLE hGSCDec; hGSCDec = st_fx->hGSCDec; - set16_fx(inpulses_fx, 0, NB_SFM); - set16_fx(imaxpulse_fx, 0, NB_SFM); + set16_fx( inpulses_fx, 0, NB_SFM ); + set16_fx( imaxpulse_fx, 0, NB_SFM ); /*--------------------------------------------------------------------------------------* * Initialization *--------------------------------------------------------------------------------------*/ bit = bits_used; move16(); -#if 1//def ADD_LRTD - test(); test(); test(); test(); - IF(EQ_16(coder_type, INACTIVE) && (EQ_16(st_fx->tdm_LRTD_flag, 1) || EQ_16(st_fx->element_mode, IVAS_SCE)) && LE_32(st_fx->core_brate, GSC_LRES_GAINQ_LIMIT)) +#if 1 // def ADD_LRTD + test(); + test(); + test(); + test(); + IF( EQ_16( coder_type, INACTIVE ) && ( EQ_16( st_fx->tdm_LRTD_flag, 1 ) || EQ_16( st_fx->element_mode, IVAS_SCE ) ) && LE_32( st_fx->core_brate, GSC_LRES_GAINQ_LIMIT ) ) { - bit = add(bit, GSC_LRES_NB_NITS); + bit = add( bit, GSC_LRES_NB_NITS ); } - IF(EQ_16(st_fx->L_frame, L_FRAME16k)) + IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { Mbands_gn = MBANDS_GN16k; move16(); } #endif - set16_fx(exc_diffQ, 0, st_fx->L_frame); + set16_fx( exc_diffQ, 0, st_fx->L_frame ); /*--------------------------------------------------------------------------------------* * Gain decoding *--------------------------------------------------------------------------------------*/ test(); - IF(st_fx->bfi || st_fx->BER_detect) + IF( st_fx->bfi || st_fx->BER_detect ) { /* copy old gain */ - Copy(hGSCDec->old_y_gain_fx, Ener_per_bd_iQ, Mbands_gn); - mean_gain = mult_r(st_fx->lp_gainc_fx, 3277); /*Q3*/ - FOR(i = 0; i < Mbands_gn; i++) + Copy( hGSCDec->old_y_gain_fx, Ener_per_bd_iQ, Mbands_gn ); + mean_gain = mult_r( st_fx->lp_gainc_fx, 3277 ); /*Q3*/ + FOR( i = 0; i < Mbands_gn; i++ ) { - Ener_per_bd_iQ[i] = add(Ener_per_bd_iQ[i], shl(mean_gain, 9)); /*Q12*/ move16(); + Ener_per_bd_iQ[i] = add( Ener_per_bd_iQ[i], shl( mean_gain, 9 ) ); /*Q12*/ + move16(); } - st_fx->lp_gainc_fx = mult_r(st_fx->lp_gainc_fx, 32112); /*Q3*/ + st_fx->lp_gainc_fx = mult_r( st_fx->lp_gainc_fx, 32112 ); /*Q3*/ } ELSE { -#if 1//def ADD_LRTD +#if 1 // def ADD_LRTD i = 0; move16(); - WHILE(LT_16(i, SIZE_BRATE_INTERMED_TBL)) + WHILE( LT_16( i, SIZE_BRATE_INTERMED_TBL ) ) { - IF(LE_32(st_fx->core_brate, brate_intermed_tbl[i])) + IF( LE_32( st_fx->core_brate, brate_intermed_tbl[i] ) ) { break; } - i = add(i,1); + i = add( i, 1 ); } - test(); test(); test(); test(); - IF(GT_16(st_fx->element_mode, EVS_MONO) && EQ_16(coder_type, AUDIO) && - LE_32(st_fx->core_brate, STEREO_GSC_BIT_RATE_ALLOC) && EQ_32(brate_intermed_tbl[i],ACELP_9k60)) /* Bit allocation is mapped to 8 kb/s instead of 9.6 kb/s in this case */ + test(); + test(); + test(); + test(); + IF( GT_16( st_fx->element_mode, EVS_MONO ) && EQ_16( coder_type, AUDIO ) && + LE_32( st_fx->core_brate, STEREO_GSC_BIT_RATE_ALLOC ) && EQ_32( brate_intermed_tbl[i], ACELP_9k60 ) ) /* Bit allocation is mapped to 8 kb/s instead of 9.6 kb/s in this case */ { i--; } - mean_gain = gsc_gaindec_ivas_fx(st_fx, Ener_per_bd_iQ, brate_intermed_tbl[i], hGSCDec->old_y_gain_fx, coder_type, st_fx->bwidth); + mean_gain = gsc_gaindec_ivas_fx( st_fx, Ener_per_bd_iQ, brate_intermed_tbl[i], hGSCDec->old_y_gain_fx, coder_type, st_fx->bwidth ); -#else - mean_gain = gsc_gaindec_fx(st_fx, Ener_per_bd_iQ, st_fx->core_brate, hGSCDec->old_y_gain_fx, coder_type, st_fx->bwidth); +#else + mean_gain = gsc_gaindec_fx( st_fx, Ener_per_bd_iQ, st_fx->core_brate, hGSCDec->old_y_gain_fx, coder_type, st_fx->bwidth ); #endif - st_fx->lp_gainc_fx = mult_r(640,mean_gain); /*10 in Q6 x Q12 -> lp_gainc in Q3 */ + st_fx->lp_gainc_fx = mult_r( 640, mean_gain ); /*10 in Q6 x Q12 -> lp_gainc in Q3 */ } *last_bin = 0; move16(); test(); - IF(EQ_32(st_fx->core_brate, ACELP_8k00) && NE_16(st_fx->bwidth, NB)) + IF( EQ_32( st_fx->core_brate, ACELP_8k00 ) && NE_16( st_fx->bwidth, NB ) ) { bitallocation_exc[0] = 0; move16(); @@ -1461,38 +1477,38 @@ void gsc_dec_ivas_fx( move16(); } - set16_fx(bitallocation_band, 0, MBANDS_GN); + set16_fx( bitallocation_band, 0, MBANDS_GN ); test(); - IF((EQ_16(st_fx->bfi, 1)) || st_fx->BER_detect) + IF( ( EQ_16( st_fx->bfi, 1 ) ) || st_fx->BER_detect ) { /*--------------------------------------------------------------------------------------* * Copy old spectrum * reduce spectral dynamic * save spectrum *--------------------------------------------------------------------------------------*/ -#if 1//def ADD_LRTD +#if 1 // def ADD_LRTD max_eq = 32767; move16(); #endif test(); - IF(EQ_16(st_fx->last_good, INACTIVE_CLAS) || EQ_16(st_fx->Last_GSC_noisy_speech_flag, 1)) + IF( EQ_16( st_fx->last_good, INACTIVE_CLAS ) || EQ_16( st_fx->Last_GSC_noisy_speech_flag, 1 ) ) { - FOR(i = 0; i < st_fx->L_frame; i++) + FOR( i = 0; i < st_fx->L_frame; i++ ) { - L_tmp = L_shr(L_mult(Random(&hGSCDec->seed_tcx), 26214), 5); /*Q10*/ - L_tmp = L_mac(L_tmp, hGSCDec->Last_GSC_spectrum_fx[i], 6554); - hGSCDec->Last_GSC_spectrum_fx[i] = round_fx(L_tmp); /*Q10*/ + L_tmp = L_shr( L_mult( Random( &hGSCDec->seed_tcx ), 26214 ), 5 ); /*Q10*/ + L_tmp = L_mac( L_tmp, hGSCDec->Last_GSC_spectrum_fx[i], 6554 ); + hGSCDec->Last_GSC_spectrum_fx[i] = round_fx( L_tmp ); /*Q10*/ } } - Copy(hGSCDec->Last_GSC_spectrum_fx, exc_diffQ, st_fx->L_frame); + Copy( hGSCDec->Last_GSC_spectrum_fx, exc_diffQ, st_fx->L_frame ); - FOR(i = 0; i < st_fx->L_frame; i++) + FOR( i = 0; i < st_fx->L_frame; i++ ) { - hGSCDec->Last_GSC_spectrum_fx[i] = mult_r(hGSCDec->Last_GSC_spectrum_fx[i], 24576); /*Q10*/ move16(); + hGSCDec->Last_GSC_spectrum_fx[i] = mult_r( hGSCDec->Last_GSC_spectrum_fx[i], 24576 ); /*Q10*/ + move16(); } - } ELSE { @@ -1500,33 +1516,33 @@ void gsc_dec_ivas_fx( * PVQ decoder *--------------------------------------------------------------------------------------*/ - bands_and_bit_alloc_ivas_fx(hGSCDec->cor_strong_limit, hGSCDec->noise_lev, st_fx->core_brate, Diff_len, bit, &bit, Ener_per_bd_iQ, - max_ener_band, bits_per_bands, &nb_subbands, NULL, NULL, &pvq_len, coder_type, st_fx->bwidth, st_fx->GSC_noisy_speech, - st_fx->L_frame, st_fx->element_mode, st_fx->GSC_IVAS_mode); + bands_and_bit_alloc_ivas_fx( hGSCDec->cor_strong_limit, hGSCDec->noise_lev, st_fx->core_brate, Diff_len, bit, &bit, Ener_per_bd_iQ, + max_ener_band, bits_per_bands, &nb_subbands, NULL, NULL, &pvq_len, coder_type, st_fx->bwidth, st_fx->GSC_noisy_speech, + st_fx->L_frame, st_fx->element_mode, st_fx->GSC_IVAS_mode ); -#if 1//def ADD_LRTD - IF(bit == 0) +#if 1 // def ADD_LRTD + IF( bit == 0 ) { - set16_fx(concat_out, 0, L_FRAME16k); + set16_fx( concat_out, 0, L_FRAME16k ); } #endif { - pvq_core_dec_fx(st_fx, gsc_sfm_start, gsc_sfm_end, gsc_sfm_size, concat_out, &Q_tmp, bit, nb_subbands, bits_per_bands, NULL, inpulses_fx, imaxpulse_fx, ACELP_CORE); - //ivas_pvq_core_dec_fx(st_fx, gsc_sfm_start, gsc_sfm_end, gsc_sfm_size, concat_out, &Q_tmp, bit, nb_subbands, bits_per_bands, NULL, inpulses_fx, imaxpulse_fx, ACELP_CORE); - Scale_sig(concat_out, gsc_sfm_end[nb_subbands - 1], sub(Q_PVQ_OUT, Q_tmp)); + pvq_core_dec_fx( st_fx, gsc_sfm_start, gsc_sfm_end, gsc_sfm_size, concat_out, &Q_tmp, bit, nb_subbands, bits_per_bands, NULL, inpulses_fx, imaxpulse_fx, ACELP_CORE ); + // ivas_pvq_core_dec_fx(st_fx, gsc_sfm_start, gsc_sfm_end, gsc_sfm_size, concat_out, &Q_tmp, bit, nb_subbands, bits_per_bands, NULL, inpulses_fx, imaxpulse_fx, ACELP_CORE); + Scale_sig( concat_out, gsc_sfm_end[nb_subbands - 1], sub( Q_PVQ_OUT, Q_tmp ) ); } seed_init = 0; move16(); -#if 1//def ADD_LRTD +#if 1 // def ADD_LRTD max_eq = 0; max_eq_val = 32767; - IF(((st_fx->core_brate < ACELP_7k20 && st_fx->GSC_noisy_speech == 1) || st_fx->core_brate < 6000) && coder_type <= UNVOICED) + IF( ( ( st_fx->core_brate < ACELP_7k20 && st_fx->GSC_noisy_speech == 1 ) || st_fx->core_brate < 6000 ) && coder_type <= UNVOICED ) { - j = maximum_fx(concat_out, nb_subbands * 16, &max_eq); - //max_eq = max_eq_val / (abs_s(concat_out[j]) + 328 /*0.01f*/ ); - Word16 temp_max_eq = abs_s(concat_out[j]) + 10 /*0.01f in Q10*/; + j = maximum_fx( concat_out, nb_subbands * 16, &max_eq ); + // max_eq = max_eq_val / (abs_s(concat_out[j]) + 328 /*0.01f*/ ); + Word16 temp_max_eq = abs_s( concat_out[j] ) + 10 /*0.01f in Q10*/; IF( LE_16( temp_max_eq, ONE_IN_Q10 ) ) { max_eq = max_eq_val; @@ -1535,39 +1551,39 @@ void gsc_dec_ivas_fx( { Word16 exp = 5; max_eq = Inv16( temp_max_eq, &exp ); - max_eq = shl(max_eq, exp); + max_eq = shl( max_eq, exp ); } } #endif /* Reorder Q bands */ - FOR(j = 0; j < nb_subbands; j++) + FOR( j = 0; j < nb_subbands; j++ ) { - Copy(concat_out + j * 16, exc_diffQ + max_ener_band[j] * 16, 16); + Copy( concat_out + j * 16, exc_diffQ + max_ener_band[j] * 16, 16 ); - *last_bin = s_max(*last_bin,max_ener_band[j]); + *last_bin = s_max( *last_bin, max_ener_band[j] ); move16(); bitallocation_band[max_ener_band[j]] = 1; move16(); - seed_init = add(seed_init,inpulses_fx[j]); + seed_init = add( seed_init, inpulses_fx[j] ); } test(); - IF(NE_16(st_fx->last_coder_type, AUDIO) /* First audio frame */ - && NE_16(st_fx->last_coder_type, UNVOICED))/* last_coder_type == INACTIVE is overwritten in update_dec to UNVOICED */ + IF( NE_16( st_fx->last_coder_type, AUDIO ) /* First audio frame */ + && NE_16( st_fx->last_coder_type, UNVOICED ) ) /* last_coder_type == INACTIVE is overwritten in update_dec to UNVOICED */ { - FOR(j = 0; j < shl(nb_subbands,4); j++) + FOR( j = 0; j < shl( nb_subbands, 4 ); j++ ) { - IF(concat_out[j] > 0) + IF( concat_out[j] > 0 ) { - seed_init = extract_l(L_shl(seed_init,3)); + seed_init = extract_l( L_shl( seed_init, 3 ) ); } - IF(concat_out[j] < 0) + IF( concat_out[j] < 0 ) { #ifdef BASOP_NOGLOB_TMP_715 seed_init = add_sat( seed_init, 3 ); #else - seed_init = add(seed_init,3); + seed_init = add( seed_init, 3 ); #endif move16(); } @@ -1577,78 +1593,80 @@ void gsc_dec_ivas_fx( move16(); } test(); - IF(EQ_32(st_fx->core_brate,ACELP_8k00) && NE_16(st_fx->bwidth,NB)) + IF( EQ_32( st_fx->core_brate, ACELP_8k00 ) && NE_16( st_fx->bwidth, NB ) ) { - IF(exc_diffQ[L_FRAME8k - 2] != 0) + IF( exc_diffQ[L_FRAME8k - 2] != 0 ) { bitallocation_exc[0] = 1; move16(); } - IF(exc_diffQ[L_FRAME8k - 1] != 0) + IF( exc_diffQ[L_FRAME8k - 1] != 0 ) { bitallocation_exc[1] = 1; move16(); } } - Copy(exc_diffQ, hGSCDec->Last_GSC_spectrum_fx, st_fx->L_frame); + Copy( exc_diffQ, hGSCDec->Last_GSC_spectrum_fx, st_fx->L_frame ); /*--------------------------------------------------------------------------------------* * Skip adaptive (pitch) contribution frequency band (no noise added over the time contribution) * Find x pulses between 1.6-3.2kHz to code in the spectrum of the residual signal * Gain is based on the inter-correlation gain between the pulses found and residual signal *--------------------------------------------------------------------------------------*/ -#if 1//def ADD_LRTD - test(); test(); test(); test(); test(); test(); - IF(GE_16(st_fx->GSC_IVAS_mode, 1) && EQ_16(st_fx->GSC_noisy_speech, 1)) +#if 1 // def ADD_LRTD + test(); + test(); + test(); + test(); + test(); + test(); + IF( GE_16( st_fx->GSC_IVAS_mode, 1 ) && EQ_16( st_fx->GSC_noisy_speech, 1 ) ) { - FOR(i = 64; i < st_fx->L_frame; i++) + FOR( i = 64; i < st_fx->L_frame; i++ ) { - //PMT("GSC FIX point to be done here") - //exc_diffQ[i] *= max_eq; - exc_diffQ[i] = mult_r(exc_diffQ[i], max_eq); + // PMT("GSC FIX point to be done here") + // exc_diffQ[i] *= max_eq; + exc_diffQ[i] = mult_r( exc_diffQ[i], max_eq ); } } - ELSE IF(((LT_32(st_fx->core_brate, ACELP_7k20) && EQ_16(st_fx->GSC_noisy_speech, 1)) || LT_32(st_fx->core_brate, 6000)) && LE_16(st_fx->coder_type, UNVOICED)) + ELSE IF( ( ( LT_32( st_fx->core_brate, ACELP_7k20 ) && EQ_16( st_fx->GSC_noisy_speech, 1 ) ) || LT_32( st_fx->core_brate, 6000 ) ) && LE_16( st_fx->coder_type, UNVOICED ) ) { - FOR(i = 0; i < L_FRAME; i++) + FOR( i = 0; i < L_FRAME; i++ ) { - //PMT("GSC FIX point to be done here") - //exc_diffQ[i] *= max_eq; - exc_diffQ[i] = mult_r(exc_diffQ[i], max_eq); + // PMT("GSC FIX point to be done here") + // exc_diffQ[i] *= max_eq; + exc_diffQ[i] = mult_r( exc_diffQ[i], max_eq ); } } ELSE #endif { - freq_dnw_scaling_fx(hGSCDec->cor_strong_limit, st_fx->coder_type, hGSCDec->noise_lev, st_fx->core_brate, exc_diffQ, Qexc_diffQ, st_fx->L_frame); + freq_dnw_scaling_fx( hGSCDec->cor_strong_limit, st_fx->coder_type, hGSCDec->noise_lev, st_fx->core_brate, exc_diffQ, Qexc_diffQ, st_fx->L_frame ); } } - /*--------------------------------------------------------------------------------------* - * Estimate noise level - *--------------------------------------------------------------------------------------*/ + /*--------------------------------------------------------------------------------------* + * Estimate noise level + *--------------------------------------------------------------------------------------*/ - highband_exc_dct_in_ivas_fx(st_fx->core_brate, mfreq_bindiv_loc, *last_bin, Diff_len, hGSCDec->noise_lev, pit_band_idx, exc_diffQ, - &hGSCDec->seed_tcx, Ener_per_bd_iQ, nb_subfr, exc_dct_in, st_fx->last_coder_type, bitallocation_band, lsf_new, - hGSCDec->last_exc_dct_in_fx, &hGSCDec->last_ener_fx, hGSCDec->last_bitallocation_band, bitallocation_exc, st_fx->bfi, coder_type, - st_fx->bwidth, exc_wo_nf, Qexc_diffQ, Q_exc, st_fx->GSC_noisy_speech, hGSCDec->lt_ener_per_band_fx - , st_fx->L_frame, st_fx->element_mode, st_fx->GSC_IVAS_mode - ); + highband_exc_dct_in_ivas_fx( st_fx->core_brate, mfreq_bindiv_loc, *last_bin, Diff_len, hGSCDec->noise_lev, pit_band_idx, exc_diffQ, + &hGSCDec->seed_tcx, Ener_per_bd_iQ, nb_subfr, exc_dct_in, st_fx->last_coder_type, bitallocation_band, lsf_new, + hGSCDec->last_exc_dct_in_fx, &hGSCDec->last_ener_fx, hGSCDec->last_bitallocation_band, bitallocation_exc, st_fx->bfi, coder_type, + st_fx->bwidth, exc_wo_nf, Qexc_diffQ, Q_exc, st_fx->GSC_noisy_speech, hGSCDec->lt_ener_per_band_fx, st_fx->L_frame, st_fx->element_mode, st_fx->GSC_IVAS_mode ); exc_dct_in[0] = 0; move16(); return; - } /*-------------------------------------------------------------------* -* GSC_dec_init() -* -* Initialize GSC decoder state structure -*-------------------------------------------------------------------*/ + * GSC_dec_init() + * + * Initialize GSC decoder state structure + *-------------------------------------------------------------------*/ void GSC_dec_init( GSC_DEC_HANDLE hGSCDec /* i/o: GSC data handle */ @@ -1665,19 +1683,19 @@ void GSC_dec_init( move16(); #ifdef ADD_LRTD - set16_fx(hGSCDec->Last_GSC_spectrum_fx, 0, L_FRAME16k); - set16_fx(hGSCDec->last_exc_dct_in_fx, 0, L_FRAME16k); - set16_fx(hGSCDec->lt_ener_per_band_fx, 4096, MBANDS_GN_BITALLOC16k); - set16_fx(hGSCDec->old_y_gain_fx, 0, MBANDS_GN_BITALLOC16k); -#else - set16_fx(hGSCDec->Last_GSC_spectrum_fx, 0, L_FRAME); - set16_fx(hGSCDec->last_exc_dct_in_fx, 0, L_FRAME); - set16_fx(hGSCDec->old_y_gain_fx, 0, MBANDS_GN); - set16_fx(hGSCDec->lt_ener_per_band_fx, 4096, MBANDS_GN);/*Q12*/ + set16_fx( hGSCDec->Last_GSC_spectrum_fx, 0, L_FRAME16k ); + set16_fx( hGSCDec->last_exc_dct_in_fx, 0, L_FRAME16k ); + set16_fx( hGSCDec->lt_ener_per_band_fx, 4096, MBANDS_GN_BITALLOC16k ); + set16_fx( hGSCDec->old_y_gain_fx, 0, MBANDS_GN_BITALLOC16k ); +#else + set16_fx( hGSCDec->Last_GSC_spectrum_fx, 0, L_FRAME ); + set16_fx( hGSCDec->last_exc_dct_in_fx, 0, L_FRAME ); + set16_fx( hGSCDec->old_y_gain_fx, 0, MBANDS_GN ); + set16_fx( hGSCDec->lt_ener_per_band_fx, 4096, MBANDS_GN ); /*Q12*/ #endif hGSCDec->last_ener_fx = 0; move16(); - set16_fx(hGSCDec->last_bitallocation_band, 0, 6); + set16_fx( hGSCDec->last_bitallocation_band, 0, 6 ); hGSCDec->Last_frame_ener_fx = MAX_32; move32(); @@ -1685,29 +1703,29 @@ void GSC_dec_init( } void GSC_dec_init_ivas_fx( - GSC_DEC_HANDLE hGSCDec /* i/o: GSC data handle */ + GSC_DEC_HANDLE hGSCDec /* i/o: GSC data handle */ ) { - hGSCDec->seed_tcx = 15687; - move16(); - hGSCDec->cor_strong_limit = 1; - move16(); - set16_fx(hGSCDec->old_y_gain_fx, 0, MBANDS_GN); - hGSCDec->noise_lev = NOISE_LEVEL_SP0; - move16(); - set16_fx(hGSCDec->Last_GSC_spectrum_fx, 0, L_FRAME16k); - hGSCDec->Last_GSC_pit_band_idx = 0; - move16(); - - set16_fx(hGSCDec->lt_ener_per_band_fx, 4096, MBANDS_GN16k); /*Q12*/ - set16_fx(hGSCDec->last_exc_dct_in_fx, 0, L_FRAME16k); - hGSCDec->last_ener_fx = 0; - move16(); - set16_fx(hGSCDec->last_bitallocation_band, 0, 6); - - hGSCDec->Last_frame_ener_fx = MAX_32; - move32(); - - return; + hGSCDec->seed_tcx = 15687; + move16(); + hGSCDec->cor_strong_limit = 1; + move16(); + set16_fx( hGSCDec->old_y_gain_fx, 0, MBANDS_GN ); + hGSCDec->noise_lev = NOISE_LEVEL_SP0; + move16(); + set16_fx( hGSCDec->Last_GSC_spectrum_fx, 0, L_FRAME16k ); + hGSCDec->Last_GSC_pit_band_idx = 0; + move16(); + + set16_fx( hGSCDec->lt_ener_per_band_fx, 4096, MBANDS_GN16k ); /*Q12*/ + set16_fx( hGSCDec->last_exc_dct_in_fx, 0, L_FRAME16k ); + hGSCDec->last_ener_fx = 0; + move16(); + set16_fx( hGSCDec->last_bitallocation_band, 0, 6 ); + + hGSCDec->Last_frame_ener_fx = MAX_32; + move32(); + + return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/hdecnrm_fx.c b/lib_dec/hdecnrm_fx.c index e815efcc2..40946cb20 100644 --- a/lib_dec/hdecnrm_fx.c +++ b/lib_dec/hdecnrm_fx.c @@ -2,7 +2,7 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ +#include "options.h" /* Compilation switches */ #include "prot_fx1.h" #include "prot_fx2.h" #include "rom_dec.h" @@ -14,67 +14,67 @@ /* Huffman decoding for indices of quantized norms */ /*--------------------------------------------------------------------------*/ void hdecnrm_fx( - Decoder_State *st_fx,/* i/o: decoder state structure */ - const Word16 numNorms, /* i : number of norms */ - Word16 *index) /* o : indices of quantized norms */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 numNorms, /* i : number of norms */ + Word16 *index ) /* o : indices of quantized norms */ { Word16 i, j, k, n, m; Word16 temp; Word16 *pidx; - pidx = index; + pidx = index; - m = sub(numNorms, 1); - FOR (i=0; i 0) + hufftab_idx = L_deposit_l( 0 ); + WHILE( hufftab[hufftab_idx] > 0 ) { - tmp_h = shr(hufftab[hufftab_idx],4); - tmp_l = sub(hufftab[hufftab_idx],shl(tmp_h,4)); - *rbits = add(*rbits,tmp_l); - hufftab_idx = L_add(hufftab_idx, L_add(L_deposit_l(tmp_h), get_next_indice( st_fx, tmp_l ) )); + tmp_h = shr( hufftab[hufftab_idx], 4 ); + tmp_l = sub( hufftab[hufftab_idx], shl( tmp_h, 4 ) ); + *rbits = add( *rbits, tmp_l ); + hufftab_idx = L_add( hufftab_idx, L_add( L_deposit_l( tmp_h ), get_next_indice( st_fx, tmp_l ) ) ); } - return negate(hufftab[hufftab_idx]); + return negate( hufftab[hufftab_idx] ); } @@ -129,36 +128,35 @@ Word16 decode_huff_context_fx( /*--------------------------------------------------------------------------*/ void hdecnrm_context_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ + Decoder_State *st_fx, /* i/o: decoder state structure */ const Word16 N, Word16 *index, - Word16 *n_length -) + Word16 *n_length ) { Word16 i, prevj, tmp; - prevj = add(index[0], OFFSET_NORM); - FOR( i=1; i < N; i++) + prevj = add( index[0], OFFSET_NORM ); + FOR( i = 1; i < N; i++ ) { - IF( GT_16(prevj, HTH_NORM)) + IF( GT_16( prevj, HTH_NORM ) ) { /* above */ - tmp = decode_huff_context_fx( st_fx, hntable, n_length); - index[i] = sub(31 , tmp); + tmp = decode_huff_context_fx( st_fx, hntable, n_length ); + index[i] = sub( 31, tmp ); move16(); } ELSE { - IF( LT_16(prevj, LTH_NORM)) + IF( LT_16( prevj, LTH_NORM ) ) { /* less */ - index[i] = decode_huff_context_fx(st_fx, hntable, n_length); + index[i] = decode_huff_context_fx( st_fx, hntable, n_length ); move16(); } ELSE { /* equal */ - index[i] = decode_huff_context_fx(st_fx, hetable, n_length); + index[i] = decode_huff_context_fx( st_fx, hetable, n_length ); move16(); } } @@ -169,31 +167,31 @@ void hdecnrm_context_fx( } void hdecnrm_resize_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 N, /* (i) number of SFMs */ - Word16 *index /* (o) norm quantization index vector */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 N, /* (i) number of SFMs */ + Word16 *index /* (o) norm quantization index vector */ ) { Word16 i, j, k, m; Word16 temp; Word16 *pidx; - pidx = index; + pidx = index; - m = sub(N, 1); + m = sub( N, 1 ); move16(); - FOR (i=0; inext_bit_pos = sub(st_fx->next_bit_pos, j); + st_fx->next_bit_pos = sub( st_fx->next_bit_pos, j ); return; } @@ -298,9 +293,9 @@ void huff_dec_fx( *--------------------------------------------------------------------------*/ void hdecnrm_tran_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 N, /* i : number of norms */ - Word16 *index /* o : indices of quantized norms */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 N, /* i : number of norms */ + Word16 *index /* o : indices of quantized norms */ ) { Word16 i, j, k, n, m; @@ -308,98 +303,94 @@ void hdecnrm_tran_fx( Word16 *pidx; Word16 l; - pidx = index; + pidx = index; move16(); - m = sub(N, 1); - FOR (i=0; i -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "rom_com.h" /* Static table prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "rom_com.h" /* Static table prototypes */ #include "basop32.h" #include "prot.h" @@ -14,31 +14,23 @@ * Local constants *---------------------------------------------------------------------*/ -#define L_SUBFR48k 240 -#define L_SUBFR32k 160 +#define L_SUBFR48k 240 +#define L_SUBFR32k 160 /*---------------------------------------------------------------------* * Local function prototypes *---------------------------------------------------------------------*/ -static void filt_6k_7k_scale_fx(Word16 signal[], Word16 lg, Word16 mem[], Word16 fact, Word16 exp); +static void filt_6k_7k_scale_fx( Word16 signal[], Word16 lg, Word16 mem[], Word16 fact, Word16 exp ); -static void hf_synthesis_fx(ZERO_BWE_DEC_HANDLE hBWE_zero, const Word32 core_brate, const Word16 output_subfr,const Word16 Aq[], - const Word16 exc[], const Word16 Q_exc,Word16 synth[],Word16 synth16k[] - , const Word16 Q_syn, Word16* delay_syn_hf, Word16 *memExp1, Word16* mem_hp_interp, const Word16 extl, const Word16 CNG_mode ); +static void hf_synthesis_fx( ZERO_BWE_DEC_HANDLE hBWE_zero, const Word32 core_brate, const Word16 output_subfr, const Word16 Aq[], const Word16 exc[], const Word16 Q_exc, Word16 synth[], Word16 synth16k[], const Word16 Q_syn, Word16 *delay_syn_hf, Word16 *memExp1, Word16 *mem_hp_interp, const Word16 extl, const Word16 CNG_mode ); #ifdef IVAS_FLOAT_FIXED -static void hf_synthesis_ivas_fx(ZERO_BWE_DEC_HANDLE hBWE_zero, const Word32 core_brate, const Word16 output_subfr, const Word16 Aq[], - const Word16 exc[], const Word16 Q_exc, Word16 synth[], Word16 synth16k[] - , const Word16 Q_syn, Word16* delay_syn_hf, Word16 *memExp1, Word16* mem_hp_interp, const Word16 extl, const Word16 CNG_mode, Word16 element_mode); +static void hf_synthesis_ivas_fx( ZERO_BWE_DEC_HANDLE hBWE_zero, const Word32 core_brate, const Word16 output_subfr, const Word16 Aq[], const Word16 exc[], const Word16 Q_exc, Word16 synth[], Word16 synth16k[], const Word16 Q_syn, Word16 *delay_syn_hf, Word16 *memExp1, Word16 *mem_hp_interp, const Word16 extl, const Word16 CNG_mode, Word16 element_mode ); #endif -static void hf_synthesis_amr_wb_fx( const Word32 core_brate, const Word16 output_subfr, const Word16 Ap[], Word16 exc16k[], - Word16 synth_out[], Word16 *mem_syn_hf, Word16 *delay_syn_hf, Word16 *mem_hp_interp, Word16 p_r, - Word16 HF_corr_gain, Word16 til, Word16 voice_factors, const Word16 exc[], const Word16 Q_exc, const Word16 Q_out, Word16 qhf ); -static void envelope_fx(AMRWB_IO_DEC_HANDLE hAmrwb_IO, const Word32 core_brate, const Word16 Aq[], Word16 Ap[], Word16 *r, Word16 tilt0, Word16 tilt, Word16 voice_factor); -static void AdaptiveStartBand_fx( Word16 *start_band, const Word32 rate, const Word16 *lsf, const Word16 voicing_fac, const Word16 clas, Word16 *voicing_flag, - Word16 *start_band_old, Word32 *OptCrit_old ); - +static void hf_synthesis_amr_wb_fx( const Word32 core_brate, const Word16 output_subfr, const Word16 Ap[], Word16 exc16k[], Word16 synth_out[], Word16 *mem_syn_hf, Word16 *delay_syn_hf, Word16 *mem_hp_interp, Word16 p_r, Word16 HF_corr_gain, Word16 til, Word16 voice_factors, const Word16 exc[], const Word16 Q_exc, const Word16 Q_out, Word16 qhf ); +static void envelope_fx( AMRWB_IO_DEC_HANDLE hAmrwb_IO, const Word32 core_brate, const Word16 Aq[], Word16 Ap[], Word16 *r, Word16 tilt0, Word16 tilt, Word16 voice_factor ); +static void AdaptiveStartBand_fx( Word16 *start_band, const Word32 rate, const Word16 *lsf, const Word16 voicing_fac, const Word16 clas, Word16 *voicing_flag, Word16 *start_band_old, Word32 *OptCrit_old ); /*-------------------------------------------------------------------* @@ -50,37 +42,37 @@ static void AdaptiveStartBand_fx( Word16 *start_band, const Word32 rate, const *-------------------------------------------------------------------*/ void hf_synth_init_fx( - ZERO_BWE_DEC_HANDLE hBWE_zero /* o : zero BWE decoder handle */ + ZERO_BWE_DEC_HANDLE hBWE_zero /* o : zero BWE decoder handle */ ) { - hBWE_zero->seed2 = RANDOM_INITSEED; - set16_fx(hBWE_zero->mem_hf_fx, 0, (L_FIR - 1)); - set16_fx(hBWE_zero->mem_syn_hf_fx, 0, M); - set16_fx(hBWE_zero->mem_hp400_fx, 0, 4); - set16_fx(hBWE_zero->delay_syn_hf_fx, 0, NS2SA(16000, DELAY_CLDFB_NS)); - set16_fx(hBWE_zero->mem_hp_interp_fx, 0, INTERP_3_1_MEM_LEN); - - return; + hBWE_zero->seed2 = RANDOM_INITSEED; + set16_fx( hBWE_zero->mem_hf_fx, 0, ( L_FIR - 1 ) ); + set16_fx( hBWE_zero->mem_syn_hf_fx, 0, M ); + set16_fx( hBWE_zero->mem_hp400_fx, 0, 4 ); + set16_fx( hBWE_zero->delay_syn_hf_fx, 0, NS2SA( 16000, DELAY_CLDFB_NS ) ); + set16_fx( hBWE_zero->mem_hp_interp_fx, 0, INTERP_3_1_MEM_LEN ); + + return; } void hf_synth_reset_fx( - ZERO_BWE_DEC_HANDLE hBWE_zero /* o : zero BWE decoder handle */ + ZERO_BWE_DEC_HANDLE hBWE_zero /* o : zero BWE decoder handle */ ) { - Word16 i; + Word16 i; - FOR(i = 0; i < L_FRAME16k; i++) - { - Random(&hBWE_zero->seed2); - } + FOR( i = 0; i < L_FRAME16k; i++ ) + { + Random( &hBWE_zero->seed2 ); + } - set16_fx(hBWE_zero->mem_hf_fx, 0, (L_FIR - 1)); - set16_fx(hBWE_zero->mem_syn_hf_fx, 0, M); - set16_fx(hBWE_zero->mem_hp400_fx, 0, 4); + set16_fx( hBWE_zero->mem_hf_fx, 0, ( L_FIR - 1 ) ); + set16_fx( hBWE_zero->mem_syn_hf_fx, 0, M ); + set16_fx( hBWE_zero->mem_hp400_fx, 0, 4 ); - set16_fx(hBWE_zero->delay_syn_hf_fx, 0, NS2SA(16000, DELAY_CLDFB_NS)); - set16_fx(hBWE_zero->mem_hp_interp_fx, 0, INTERP_3_1_MEM_LEN); + set16_fx( hBWE_zero->delay_syn_hf_fx, 0, NS2SA( 16000, DELAY_CLDFB_NS ) ); + set16_fx( hBWE_zero->mem_hp_interp_fx, 0, INTERP_3_1_MEM_LEN ); - return; + return; } /*---------------------------------------------------------------------* @@ -90,36 +82,36 @@ void hf_synth_reset_fx( *---------------------------------------------------------------------*/ void hf_synth_fx( - ZERO_BWE_DEC_HANDLE hBWE_zero, /* i/o: handle to 0 bit BWE parameters */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 output_frame, /* i : output frame length */ - const Word16 *Aq, /* i : quantized Az */ - const Word16 *exc, /* i : excitation at 12.8 kHz */ - Word16 *synth, /* i : 12.8kHz synthesis signal */ - Word16 *synth16k, /* o : 16kHz synthesis signal */ - const Word16 Q_exc, /* i : excitation scaling */ - const Word16 Q_syn2, /* i : synthesis scaling */ - Word16 *delay_syn_hf, /*i/o: HF synthesis memory */ - Word16 *memExp1, /* o : HF excitation exponent */ - Word16 *mem_hp_interp, /* i/o: interpol. memory */ - const Word16 extl, /* i : flag indicating BWE */ - const Word16 CNG_mode /* i : CNG_mode */ + ZERO_BWE_DEC_HANDLE hBWE_zero, /* i/o: handle to 0 bit BWE parameters */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 output_frame, /* i : output frame length */ + const Word16 *Aq, /* i : quantized Az */ + const Word16 *exc, /* i : excitation at 12.8 kHz */ + Word16 *synth, /* i : 12.8kHz synthesis signal */ + Word16 *synth16k, /* o : 16kHz synthesis signal */ + const Word16 Q_exc, /* i : excitation scaling */ + const Word16 Q_syn2, /* i : synthesis scaling */ + Word16 *delay_syn_hf, /*i/o: HF synthesis memory */ + Word16 *memExp1, /* o : HF excitation exponent */ + Word16 *mem_hp_interp, /* i/o: interpol. memory */ + const Word16 extl, /* i : flag indicating BWE */ + const Word16 CNG_mode /* i : CNG_mode */ ) { const Word16 *p_Aq; Word16 i_subfr, output_subfr; - output_subfr = output_frame/NB_SUBFR; + output_subfr = output_frame / NB_SUBFR; move16(); p_Aq = Aq; move16(); - FOR( i_subfr=0; i_subfrseed2, L_SUBFR16k, HF_exc, 3); /* 3 = Shift Right by 3 */ + Random_Fill( &hBWE_zero->seed2, L_SUBFR16k, HF_exc, 3 ); /* 3 = Shift Right by 3 */ /* o: HF_exc in Q-3 */ @@ -219,27 +211,27 @@ static void hf_synthesis_fx( *-----------------------------------------------------------------*/ /*ener = sum2_f( exc, L_SUBFR ) + 0.01f*/ - ener = extract_h(Dot_product12(exc, exc, L_SUBFR, &exp2)); - exp2 = sub(exp2, add(Q_exc, Q_exc)); + ener = extract_h( Dot_product12( exc, exc, L_SUBFR, &exp2 ) ); + exp2 = sub( exp2, add( Q_exc, Q_exc ) ); /*tmp = round_fx(Dot_product12(HF_exc, HF_exc, output_subfr, &exp1)); */ - L_tmp = Dot_product12(HF_exc, HF_exc, L_SUBFR16k, &exp1); - tmp = round_fx(L_tmp); + L_tmp = Dot_product12( HF_exc, HF_exc, L_SUBFR16k, &exp1 ); + tmp = round_fx( L_tmp ); /* tmp = (float)(sqrt(ener/tmp)) */ /* scale is -1 if tmp > ener */ - scale = shr(sub(ener, tmp), 15); - tmp = shl(tmp, scale); - exp1 = sub(exp1, scale); + scale = shr( sub( ener, tmp ), 15 ); + tmp = shl( tmp, scale ); + exp1 = sub( exp1, scale ); - tmp = div_s(tmp, ener); - exp1 = sub(exp1, exp2); + tmp = div_s( tmp, ener ); + exp1 = sub( exp1, exp2 ); - L_tmp = L_deposit_h(tmp); + L_tmp = L_deposit_h( tmp ); - L_tmp = Isqrt_lc(L_tmp, &exp1); - scale = round_fx(L_tmp);/* Q18 when Q_exc=-1, HF_exc in Q-3 */ + L_tmp = Isqrt_lc( L_tmp, &exp1 ); + scale = round_fx( L_tmp ); /* Q18 when Q_exc=-1, HF_exc in Q-3 */ - exp2 = sub(*memExp1, exp1); + exp2 = sub( *memExp1, exp1 ); move16(); *memExp1 = exp1; move16(); @@ -251,44 +243,44 @@ static void hf_synthesis_fx( #ifdef EVS_MONO hp400_12k8_fx( synth, L_SUBFR, hBWE_zero->mem_hp400_fx ); #else - hp400_12k8_ivas_fx(synth, L_SUBFR, hBWE_zero->mem_hp400_fx); + hp400_12k8_ivas_fx( synth, L_SUBFR, hBWE_zero->mem_hp400_fx ); #endif /* i: mem_hp400 in Q_syn */ /* i: synth in Q_syn */ /* o: synth in Q_syn-3 */ - L_tmp = L_mac(1L, synth[0], synth[0]); - FOR (i = 1; i < L_SUBFR; i++) + L_tmp = L_mac( 1L, synth[0], synth[0] ); + FOR( i = 1; i < L_SUBFR; i++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_mac_sat(L_tmp, synth[i], synth[i]); + L_tmp = L_mac_sat( L_tmp, synth[i], synth[i] ); #else - L_tmp = L_mac(L_tmp, synth[i], synth[i]); + L_tmp = L_mac( L_tmp, synth[i], synth[i] ); #endif } - tmp = norm_l(L_tmp); - ener = extract_h(L_shl(L_tmp, tmp)); /* ener = r[0] */ + tmp = norm_l( L_tmp ); + ener = extract_h( L_shl( L_tmp, tmp ) ); /* ener = r[0] */ /*ener in Q = 2*(Q_syn-3)+1 = Q-5 when Q_syn=0*/ - L_tmp = L_mac(1L, synth[1], synth[0]); - FOR (i = 2; i < L_SUBFR; i++) + L_tmp = L_mac( 1L, synth[1], synth[0] ); + FOR( i = 2; i < L_SUBFR; i++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_mac_sat(L_tmp, synth[i], synth[i - 1]); + L_tmp = L_mac_sat( L_tmp, synth[i], synth[i - 1] ); #else - L_tmp = L_mac(L_tmp, synth[i], synth[i - 1]); + L_tmp = L_mac( L_tmp, synth[i], synth[i - 1] ); #endif } - tmp = extract_h(L_shl(L_tmp, tmp)); /* tmp = r[1] */ + tmp = extract_h( L_shl( L_tmp, tmp ) ); /* tmp = r[1] */ /*tmp in Q = 2*(Q_syn-3)+1 = Q-5 when Q_syn=0 */ /*we use the same normalization factor for both ener and tmp, */ /*if the headroom in "tmp" is less than "ener", tmp can saturate */ /*but this is ok since below we apply some thresholds to tmp */ - tmp = s_max(0, tmp); - if (tmp > 0) + tmp = s_max( 0, tmp ); + if ( tmp > 0 ) { - tmp = div_s(tmp, ener); + tmp = div_s( tmp, ener ); } /*-----------------------------------------------------------------* @@ -297,31 +289,31 @@ static void hf_synthesis_fx( /* tmp = 1.0 - fac */ #ifdef BASOP_NOGLOB - tmp = add_o(1, sub(32767, tmp), &Overflow); + tmp = add_o( 1, sub( 32767, tmp ), &Overflow ); #else - tmp = add(1, sub(32767, tmp)); + tmp = add( 1, sub( 32767, tmp ) ); #endif test(); - if( EQ_32(core_brate,FRAME_NO_DATA)||EQ_32(core_brate,SID_2k40)) + if ( EQ_32( core_brate, FRAME_NO_DATA ) || EQ_32( core_brate, SID_2k40 ) ) { /* emphasize HF noise in CNG */ /*fac *= 2.0f;*/ #ifdef BASOP_NOGLOB - tmp = add_o(tmp, tmp, &Overflow); + tmp = add_o( tmp, tmp, &Overflow ); #else - tmp = add(tmp, tmp); + tmp = add( tmp, tmp ); #endif } - tmp = s_max(tmp, 3277); /* 0.1 in Q15 */ + tmp = s_max( tmp, 3277 ); /* 0.1 in Q15 */ /*scale *= fac;*/ - tmp = mult_r(scale, tmp); + tmp = mult_r( scale, tmp ); /*-----------------------------------------------------------------* * modify HF excitation according to both calculated scaling factors * high pass filtering (0.94ms of delay) *-----------------------------------------------------------------*/ - filt_6k_7k_scale_fx( HF_exc, L_SUBFR16k, hBWE_zero->mem_hf_fx,tmp,exp2 ); + filt_6k_7k_scale_fx( HF_exc, L_SUBFR16k, hBWE_zero->mem_hf_fx, tmp, exp2 ); /* i: input HF_exc is scaled in float, here scaling is done inside this filter */ /* i: mem_hf in Q-2 */ /* o: HF_exc in Q0 */ @@ -331,7 +323,7 @@ static void hf_synthesis_fx( *-----------------------------------------------------------------*/ /*weight_a( Aq, Ap, 0.6f, M );*/ - weight_a_lc_fx(Aq, Ap, Gamma_19661_Tbl_fx, M); + weight_a_lc_fx( Aq, Ap, Gamma_19661_Tbl_fx, M ); /* o: Ap in Q14 */ Syn_filt_s( 0, Ap, M, HF_exc, HF_syn, L_SUBFR16k, hBWE_zero->mem_syn_hf_fx, 1 ); @@ -340,49 +332,50 @@ static void hf_synthesis_fx( /* o: HF_syn in Q0 */ /* i/o: mem_syn_hf in Q0 */ - Scale_sig(HF_syn, L_SUBFR16k, (add(Q_syn, exp1))); /* bring HF_syn to (Q_syn+exp1) */ + Scale_sig( HF_syn, L_SUBFR16k, ( add( Q_syn, exp1 ) ) ); /* bring HF_syn to (Q_syn+exp1) */ /*-----------------------------------------------------------------* * add filtered HF noise to speech synthesis *-----------------------------------------------------------------*/ /* delay by 5 samples @16kHz to compensate CLDFB resampling delay (20samples) and HP filtering delay (roughly 15 samples) */ - delay = NS2SA(16000,DELAY_CLDFB_NS) - 15; - Copy( HF_syn+L_SUBFR16k-delay, temp_buffer, delay ); - Copy( HF_syn, HF_syn+delay, L_SUBFR16k-delay ); + delay = NS2SA( 16000, DELAY_CLDFB_NS ) - 15; + Copy( HF_syn + L_SUBFR16k - delay, temp_buffer, delay ); + Copy( HF_syn, HF_syn + delay, L_SUBFR16k - delay ); Copy( delay_syn_hf, HF_syn, delay ); Copy( temp_buffer, delay_syn_hf, delay ); /* interpolate the HF synthesis */ - IF( EQ_16(output_subfr,L_SUBFR48k)) /* 48kHz sampled output */ + IF( EQ_16( output_subfr, L_SUBFR48k ) ) /* 48kHz sampled output */ { { Word16 s; - s = s_max(s_min(sub(s_min(Find_Max_Norm16(HF_syn, L_SUBFR16k), Find_Max_Norm16(mem_hp_interp, INTERP_3_1_MEM_LEN - 3)), 3), - sub(Find_Max_Norm16(mem_hp_interp + INTERP_3_1_MEM_LEN - 3, 3), 1)), 0 ); - Scale_sig(HF_syn, L_SUBFR16k, s); - Scale_sig(mem_hp_interp, INTERP_3_1_MEM_LEN, s); - interpolate_3_over_1_allpass_fx( HF_syn, L_SUBFR16k, upsampled_HF_syn, mem_hp_interp); - Scale_sig(upsampled_HF_syn, 3*L_SUBFR16k, -s); - Scale_sig(mem_hp_interp, INTERP_3_1_MEM_LEN, -s); - Scale_sig(HF_syn, L_SUBFR16k, -s); + s = s_max( s_min( sub( s_min( Find_Max_Norm16( HF_syn, L_SUBFR16k ), Find_Max_Norm16( mem_hp_interp, INTERP_3_1_MEM_LEN - 3 ) ), 3 ), + sub( Find_Max_Norm16( mem_hp_interp + INTERP_3_1_MEM_LEN - 3, 3 ), 1 ) ), + 0 ); + Scale_sig( HF_syn, L_SUBFR16k, s ); + Scale_sig( mem_hp_interp, INTERP_3_1_MEM_LEN, s ); + interpolate_3_over_1_allpass_fx( HF_syn, L_SUBFR16k, upsampled_HF_syn, mem_hp_interp ); + Scale_sig( upsampled_HF_syn, 3 * L_SUBFR16k, -s ); + Scale_sig( mem_hp_interp, INTERP_3_1_MEM_LEN, -s ); + Scale_sig( HF_syn, L_SUBFR16k, -s ); } Scale_sig( upsampled_HF_syn, L_SUBFR48k, -1 ); } - ELSE IF( EQ_16(output_subfr,L_SUBFR32k)) /* 32kHz sampled output */ + ELSE IF( EQ_16( output_subfr, L_SUBFR32k ) ) /* 32kHz sampled output */ { { Word16 s; - s = s_max(sub(s_min(Find_Max_Norm16(HF_syn, L_SUBFR16k), Find_Max_Norm16(mem_hp_interp, 2*ALLPASSSECTIONS_STEEP)),2), 0); - Scale_sig(HF_syn, L_SUBFR16k, s); - Scale_sig(mem_hp_interp, 2*ALLPASSSECTIONS_STEEP, s); + s = s_max( sub( s_min( Find_Max_Norm16( HF_syn, L_SUBFR16k ), Find_Max_Norm16( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP ) ), 2 ), 0 ); + Scale_sig( HF_syn, L_SUBFR16k, s ); + Scale_sig( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP, s ); Interpolate_allpass_steep_fx( HF_syn, mem_hp_interp, L_SUBFR16k, upsampled_HF_syn ); - Scale_sig(upsampled_HF_syn, 2*L_SUBFR16k, -s); - Scale_sig(mem_hp_interp, 2*ALLPASSSECTIONS_STEEP, -s); - Scale_sig(HF_syn, L_SUBFR16k, -s); + Scale_sig( upsampled_HF_syn, 2 * L_SUBFR16k, -s ); + Scale_sig( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP, -s ); + Scale_sig( HF_syn, L_SUBFR16k, -s ); } } - ELSE /* 16kHz sampled output */ + ELSE /* 16kHz sampled output */ { Copy( HF_syn, upsampled_HF_syn, L_SUBFR16k ); } @@ -629,46 +622,47 @@ static void hf_synthesis_ivas_fx( * (gain=4.0) *-------------------------------------------------------------------*/ static void filt_6k_7k_scale_fx( - Word16 signal[], /* i/o: signal */ - Word16 lg, /* i : length of input */ - Word16 mem[], /* i/o: memory (size=30) */ - Word16 fact, /* i : multiply factor */ - Word16 exp /* i : Mem Exponent */ + Word16 signal[], /* i/o: signal */ + Word16 lg, /* i : length of input */ + Word16 mem[], /* i/o: memory (size=30) */ + Word16 fact, /* i : multiply factor */ + Word16 exp /* i : Mem Exponent */ ) { - Word16 i, x[L_FRAME48k/NB_SUBFR+(L_FIR-1)]; + Word16 i, x[L_FRAME48k / NB_SUBFR + ( L_FIR - 1 )]; Word32 L_tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - Copy_Scale_sig(mem, x, L_FIR - 1, exp); + Copy_Scale_sig( mem, x, L_FIR - 1, exp ); - FOR (i = 0; i < lg; i++) + FOR( i = 0; i < lg; i++ ) { - x[i + L_FIR - 1] = shr(mult(signal[i], fact), 2); - move16(); /* gain of filter = 4 */ + x[i + L_FIR - 1] = shr( mult( signal[i], fact ), 2 ); + move16(); /* gain of filter = 4 */ } - FOR (i = 0; i < lg; i++) + FOR( i = 0; i < lg; i++ ) { - Word16 j; - L_tmp = 0; move32(); - for (j = 0; j<31; j++) - { + Word16 j; + L_tmp = 0; + move32(); + for ( j = 0; j < 31; j++ ) + { #ifdef BASOP_NOGLOB - L_tmp = L_mac_o(L_tmp, x[i+j], fir_6k_7k_fx[j], &Overflow); + L_tmp = L_mac_o( L_tmp, x[i + j], fir_6k_7k_fx[j], &Overflow ); #else - L_tmp = L_mac(L_tmp, x[i+j], fir_6k_7k_fx[j]); + L_tmp = L_mac( L_tmp, x[i + j], fir_6k_7k_fx[j] ); #endif - } + } #ifdef BASOP_NOGLOB - signal[i] = round_fx_o(L_tmp, &Overflow); + signal[i] = round_fx_o( L_tmp, &Overflow ); #else - signal[i] = round_fx(L_tmp); + signal[i] = round_fx( L_tmp ); #endif } - Copy(x + lg, mem, L_FIR - 1); + Copy( x + lg, mem, L_FIR - 1 ); } /*-------------------------------------------------------------------* @@ -706,7 +700,8 @@ void hf_synth_amr_wb_init_fx( hAmrwb_IO->start_band_old_fx = 160; move16(); hAmrwb_IO->OptCrit_old_fx = 32768; - move32(); /*Q15*/; + move32(); /*Q15*/ + ; return; } @@ -718,21 +713,21 @@ void hf_synth_amr_wb_init_fx( * - needed in switching scenarios *-------------------------------------------------------------------*/ void hf_synth_amr_wb_reset_fx( - ZERO_BWE_DEC_HANDLE hBWE_zero, /* o : zero BWE decoder handle */ - AMRWB_IO_DEC_HANDLE hAmrwb_IO /* i/o: AMR-WB IO data handle */ + ZERO_BWE_DEC_HANDLE hBWE_zero, /* o : zero BWE decoder handle */ + AMRWB_IO_DEC_HANDLE hAmrwb_IO /* i/o: AMR-WB IO data handle */ ) { Word16 i; - FOR(i = 0; i < L_FRAME16k; i++) + FOR( i = 0; i < L_FRAME16k; i++ ) { - Random(&hBWE_zero->seed2); + Random( &hBWE_zero->seed2 ); } - set16_fx(hBWE_zero->mem_syn_hf_fx, 0, M); - set16_fx(hBWE_zero->delay_syn_hf_fx, 0, NS2SA(16000, DELAY_CLDFB_NS)); - set16_fx(hBWE_zero->mem_hp_interp_fx, 0, INTERP_3_1_MEM_LEN); + set16_fx( hBWE_zero->mem_syn_hf_fx, 0, M ); + set16_fx( hBWE_zero->delay_syn_hf_fx, 0, NS2SA( 16000, DELAY_CLDFB_NS ) ); + set16_fx( hBWE_zero->mem_hp_interp_fx, 0, INTERP_3_1_MEM_LEN ); hAmrwb_IO->prev_r_fx = 0; move16(); @@ -770,22 +765,22 @@ void hf_synth_amr_wb_reset_fx( void hf_synth_amr_wb_fx( AMRWB_IO_DEC_HANDLE hAmrwb_IO, /* i/o: AMR-WB IO data handle */ - ZERO_BWE_DEC_HANDLE hBWE_zero, /* o : zero BWE decoder handle */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 output_frame, /* i : output frame length */ - const Word16 *Aq, /* i : quantized Az : Q12 */ - const Word16 *exc, /* i : excitation at 12.8 kHz : Q_exc */ - Word16 *synth, /* i/o: synthesis signal at 12.8k : Q_syn */ - Word16 *amr_io_class, /* i : signal class (determined by FEC algorithm) */ - Word16 *synth_out, /* i/o: output signal at output Fs : Q_out */ - Word16 fmerit, /* i : classify parameter from FEC : Q14 */ - const Word16 *hf_gain, /* i : decoded HF gain */ - const Word16 *voice_factors, /* i : voicing factors : Q15 */ - const Word16 pitch_buf[], /* i : pitch buffer : Q5 */ - const Word16 ng_ener_ST, /* i : Noise gate - short-term energy : Q8 */ - const Word16 *lsf_new, /* i : ISF vector : Q2 */ - const Word16 Q_exc, /* i : exc scaling */ - const Word16 Q_out /* i : Q_syn2-1 */ + ZERO_BWE_DEC_HANDLE hBWE_zero, /* o : zero BWE decoder handle */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 output_frame, /* i : output frame length */ + const Word16 *Aq, /* i : quantized Az : Q12 */ + const Word16 *exc, /* i : excitation at 12.8 kHz : Q_exc */ + Word16 *synth, /* i/o: synthesis signal at 12.8k : Q_syn */ + Word16 *amr_io_class, /* i : signal class (determined by FEC algorithm) */ + Word16 *synth_out, /* i/o: output signal at output Fs : Q_out */ + Word16 fmerit, /* i : classify parameter from FEC : Q14 */ + const Word16 *hf_gain, /* i : decoded HF gain */ + const Word16 *voice_factors, /* i : voicing factors : Q15 */ + const Word16 pitch_buf[], /* i : pitch buffer : Q5 */ + const Word16 ng_ener_ST, /* i : Noise gate - short-term energy : Q8 */ + const Word16 *lsf_new, /* i : ISF vector : Q2 */ + const Word16 Q_exc, /* i : exc scaling */ + const Word16 Q_out /* i : Q_syn2-1 */ ) { Word16 core_type = 1; @@ -807,9 +802,9 @@ void hf_synth_amr_wb_fx( Word16 fmerit_m; Word16 *p_Ap; const Word16 *p_Aq; - Word16 Ap[(M16k+1)*NB_SUBFR]; + Word16 Ap[( M16k + 1 ) * NB_SUBFR]; Word16 sub_gain[NB_SUBFR]; - Word16 exc16k[L_FRAME16k] ; + Word16 exc16k[L_FRAME16k]; Word16 qhf; Word16 dct_exc[L_FRAME], dct_hb[L_FRAME16k], filt_weight[L_SUBFR16k]; Word16 hb_ener, g, hb_tonal[L_SUBFR16k], tonal_ener, hb_amb[L_SUBFR16k], inv_g; @@ -820,25 +815,25 @@ void hf_synth_amr_wb_fx( Word16 q_tmp; Word16 gamma; - Scale_sig(synth, L_FRAME, -3); + Scale_sig( synth, L_FRAME, -3 ); - pt1 = synth+1; + pt1 = synth + 1; pt2 = synth; pt3 = til; pt4 = til0; - FOR( i=0; i30-exp */ - *pt3 = round_fx(L_shl(L_tmp, sub(exp,1))); /*13 */ + exp = norm_s( tmp1 ); + tmp1 = div_s( shl( 1, sub( 14, exp ) ), tmp1 ); /*Q(29-exp-2*(Q_syn-3)-1) */ + L_tmp = L_mult( tmp2, tmp1 ); /*30-exp-2*(Q_syn-3)-1+2*(Q_syn-3)+1 - >30-exp */ + *pt3 = round_fx( L_shl( L_tmp, sub( exp, 1 ) ) ); /*13 */ *pt4++ = *pt3++; move16(); @@ -846,9 +841,9 @@ void hf_synth_amr_wb_fx( pt2 += L_SUBFR; } - output_subfr = shr(output_frame , 2); + output_subfr = shr( output_frame, 2 ); - if( NE_16(*amr_io_class, 7)) + if ( NE_16( *amr_io_class, 7 ) ) { core_type = 0; move16(); @@ -858,92 +853,92 @@ void hf_synth_amr_wb_fx( pitch_var_cur = 0; move16(); pt6 = pitch_buf; - pt7 = pitch_buf+1; + pt7 = pitch_buf + 1; FOR( i = 0; i < 3; i++ ) { - tmp1 = abs_s(sub(*pt6++, *pt7++)); /*Q5 */ - pitch_var_cur = add(pitch_var_cur, shr(tmp1,1)); /*Q6 -> Q5 */ + tmp1 = abs_s( sub( *pt6++, *pt7++ ) ); /*Q5 */ + pitch_var_cur = add( pitch_var_cur, shr( tmp1, 1 ) ); /*Q6 -> Q5 */ } test(); - IF( GT_16(hAmrwb_IO->frame_count_fx, FRAME_COUNT_HF_SYNTH) && *amr_io_class == UNVOICED_CLAS) + IF( GT_16( hAmrwb_IO->frame_count_fx, FRAME_COUNT_HF_SYNTH ) && *amr_io_class == UNVOICED_CLAS ) { hAmrwb_IO->frame_count_fx = 0; hAmrwb_IO->ne_min_fx = -7680; move16(); - move16();/*Q8; */ + move16(); /*Q8; */ } ELSE { move16(); - hAmrwb_IO->frame_count_fx = s_min(hAmrwb_IO->frame_count_fx, 2 * FRAME_COUNT_HF_SYNTH-1); - hAmrwb_IO->frame_count_fx = add(hAmrwb_IO->frame_count_fx, 1); - hAmrwb_IO->ne_min_fx = s_min(hAmrwb_IO->ne_min_fx, ng_ener_ST); + hAmrwb_IO->frame_count_fx = s_min( hAmrwb_IO->frame_count_fx, 2 * FRAME_COUNT_HF_SYNTH - 1 ); + hAmrwb_IO->frame_count_fx = add( hAmrwb_IO->frame_count_fx, 1 ); + hAmrwb_IO->ne_min_fx = s_min( hAmrwb_IO->ne_min_fx, ng_ener_ST ); } pt6 = voice_factors; - L_tmp = L_mult(*pt6++,4096); - FOR(i = 1; i < 4; i++) + L_tmp = L_mult( *pt6++, 4096 ); + FOR( i = 1; i < 4; i++ ) { - L_tmp = L_mac(L_tmp, *pt6++,4096); + L_tmp = L_mac( L_tmp, *pt6++, 4096 ); } - voice_fac = round_fx(L_tmp); + voice_fac = round_fx( L_tmp ); /*fmerit_w = fmerit > 5734 ? 5734 : (fmerit < 2458 ? 2458 : fmerit); //Q14 */ - fmerit_w = s_min(fmerit,5734); - fmerit_w = s_max(fmerit_w,2458); + fmerit_w = s_min( fmerit, 5734 ); + fmerit_w = s_max( fmerit_w, 2458 ); - if ( EQ_16(core_type, 1)) + if ( EQ_16( core_type, 1 ) ) { - fmerit_w = shr(fmerit_w, 1); /*Q14; */ + fmerit_w = shr( fmerit_w, 1 ); /*Q14; */ } #ifdef BASOP_NOGLOB - L_tmp = L_mult(fmerit_w, add_sat(16384, voice_fac)); + L_tmp = L_mult( fmerit_w, add_sat( 16384, voice_fac ) ); #else - L_tmp = L_mult(fmerit_w, add(16384, voice_fac)); + L_tmp = L_mult( fmerit_w, add( 16384, voice_fac ) ); #endif - fmerit_w = extract_l(L_shr(L_tmp, 15)); /*Q14 */ + fmerit_w = extract_l( L_shr( L_tmp, 15 ) ); /*Q14 */ /**fmerit_w_sm = add(mult_r(*fmerit_w_sm, 29491), mult_r(fmerit_w, 3277)); //Q14 */ - hAmrwb_IO->fmerit_w_sm_fx = round_fx(L_mac(L_mult(hAmrwb_IO->fmerit_w_sm_fx, 29491), fmerit_w, 3277)); /*Q14 */ + hAmrwb_IO->fmerit_w_sm_fx = round_fx( L_mac( L_mult( hAmrwb_IO->fmerit_w_sm_fx, 29491 ), fmerit_w, 3277 ) ); /*Q14 */ fmerit_w = hAmrwb_IO->fmerit_w_sm_fx; move16(); tmp1 = fmerit; move16(); - if(LT_16(fmerit, 8192)) + if ( LT_16( fmerit, 8192 ) ) { tmp1 = 16384; move16(); } - fmerit_m = negate(add(-32768, tmp1)); - hAmrwb_IO->fmerit_m_sm_fx = add(shr(hAmrwb_IO->fmerit_m_sm_fx, 1), shr(fmerit_m, 1)); /*Q14 */ + fmerit_m = negate( add( -32768, tmp1 ) ); + hAmrwb_IO->fmerit_m_sm_fx = add( shr( hAmrwb_IO->fmerit_m_sm_fx, 1 ), shr( fmerit_m, 1 ) ); /*Q14 */ fmerit_m = hAmrwb_IO->fmerit_m_sm_fx; move16(); pt1 = til; FOR( i = 0; i < NB_SUBFR; i++ ) { - tmp = sub(pitch_var_cur, 320); - tmp = s_and(tmp, *pt1); - if (tmp < 0 ) + tmp = sub( pitch_var_cur, 320 ); + tmp = s_and( tmp, *pt1 ); + if ( tmp < 0 ) { *pt1 = 1638; move16(); } - tmp1 = sub(8192, *pt1); - *pt1 = s_max(6554, tmp1); + tmp1 = sub( 8192, *pt1 ); + *pt1 = s_max( 6554, tmp1 ); move16(); - tmp1 = add(hAmrwb_IO->ne_min_fx, 7680); /*Q8 */ - tmp1 = mult_r(tmp1, 7340); /*Q20 - > 0.007 //Q13 */ - *pt1 = add(*pt1, tmp1); - move16();/*Q13 */ + tmp1 = add( hAmrwb_IO->ne_min_fx, 7680 ); /*Q8 */ + tmp1 = mult_r( tmp1, 7340 ); /*Q20 - > 0.007 //Q13 */ + *pt1 = add( *pt1, tmp1 ); + move16(); /*Q13 */ - L_tmp = L_mult0(*pt1, fmerit_m); /*Q13+14 */ - *pt1++ = extract_l(L_shr(L_tmp, 14)); /*Q13 */ + L_tmp = L_mult0( *pt1, fmerit_m ); /*Q13+14 */ + *pt1++ = extract_l( L_shr( L_tmp, 14 ) ); /*Q13 */ } /* predict LPC coefficents and calculate sub-frame gains */ p_Aq = Aq; @@ -954,164 +949,164 @@ void hf_synth_amr_wb_fx( pt6 = voice_factors; FOR( i = 0; i < NB_SUBFR; i++ ) { - envelope_fx(hAmrwb_IO, core_brate, p_Aq, p_Ap, pt1, *pt2, *pt3, *pt6); + envelope_fx( hAmrwb_IO, core_brate, p_Aq, p_Ap, pt1, *pt2, *pt3, *pt6 ); pt1++; pt2++; pt3++; pt6++; - p_Aq += (M+1); - p_Ap += (M+1); + p_Aq += ( M + 1 ); + p_Ap += ( M + 1 ); } AdaptiveStartBand_fx( &start_band, core_brate, lsf_new, voice_fac, *amr_io_class, &hAmrwb_IO->voicing_flag_fx, &hAmrwb_IO->start_band_old_fx, &hAmrwb_IO->OptCrit_old_fx ); - q_tmp = Exp16Array(L_FRAME, exc); - qdct = sub(q_tmp, 1); - Copy_Scale_sig_16_32(exc, exc32, L_FRAME, qdct); + q_tmp = Exp16Array( L_FRAME, exc ); + qdct = sub( q_tmp, 1 ); + Copy_Scale_sig_16_32( exc, exc32, L_FRAME, qdct ); - qdct = add(qdct, Q_exc); - edct_fx(exc32, dct_exc32, L_FRAME, &qdct); - q_tmp = Exp32Array(L_FRAME, dct_exc32); + qdct = add( qdct, Q_exc ); + edct_fx( exc32, dct_exc32, L_FRAME, &qdct ); + q_tmp = Exp32Array( L_FRAME, dct_exc32 ); - q_tmp = sub(q_tmp,16); - Copy_Scale_sig_32_16(dct_exc32, dct_exc, L_FRAME, q_tmp); - qdct = add(qdct, q_tmp); + q_tmp = sub( q_tmp, 16 ); + Copy_Scale_sig_32_16( dct_exc32, dct_exc, L_FRAME, q_tmp ); + qdct = add( qdct, q_tmp ); - set16_fx( dct_hb, 0, L_FRAME16k); + set16_fx( dct_hb, 0, L_FRAME16k ); pt1 = &dct_hb[200]; pt2 = &dct_exc[200]; - FOR ( i = 200; i < 240; i++) + FOR( i = 200; i < 240; i++ ) { *pt1++ = *pt2++; - move16();/*qdct */ + move16(); /*qdct */ } - set16_fx(signum, 1, L_SUBFR16k); - pt1 = dct_hb+240; - pt2 = dct_exc+start_band; + set16_fx( signum, 1, L_SUBFR16k ); + pt1 = dct_hb + 240; + pt2 = dct_exc + start_band; pt3 = signum; - FOR ( i = 240; i < L_FRAME16k; i++ ) + FOR( i = 240; i < L_FRAME16k; i++ ) { - if (*pt2<0) + if ( *pt2 < 0 ) { *pt3 = -1; move16(); } - *pt1++ = abs_s(*pt2++); + *pt1++ = abs_s( *pt2++ ); move16(); /*qdct */ pt3++; } - hb_ener = dot_prod_satcontr(&dct_hb[240], &dct_hb[240], qdct, qdct, &q1, L_SUBFR16k); + hb_ener = dot_prod_satcontr( &dct_hb[240], &dct_hb[240], qdct, qdct, &q1, L_SUBFR16k ); - L_tmp = L_shl(L_mult(start_band, 205), 14); /*Q30 */ - tmp = round_fx(L_tmp); /*Q14 */ - tmp = sub(18022, tmp); /*Q14 */ - fmerit_w = round_fx(L_shl(L_mult(fmerit_w, tmp), 1)); /*Q: 14+14+1+1-16 = 14 */ + L_tmp = L_shl( L_mult( start_band, 205 ), 14 ); /*Q30 */ + tmp = round_fx( L_tmp ); /*Q14 */ + tmp = sub( 18022, tmp ); /*Q14 */ + fmerit_w = round_fx( L_shl( L_mult( fmerit_w, tmp ), 1 ) ); /*Q: 14+14+1+1-16 = 14 */ - L_tmp = L_deposit_l(fmerit_w); /*Q14 */ - L_tmp = Isqrt(L_tmp); /*Q(31-7) */ - tmp = round_fx(L_tmp); /*Q8 */ - q2 = norm_s(tmp); - alpha = div_s(shl(1, sub(14, q2)), tmp); /*Q(29-q2-8); */ - alpha = shl(alpha, sub(q2, 7));/*Q14 */ + L_tmp = L_deposit_l( fmerit_w ); /*Q14 */ + L_tmp = Isqrt( L_tmp ); /*Q(31-7) */ + tmp = round_fx( L_tmp ); /*Q8 */ + q2 = norm_s( tmp ); + alpha = div_s( shl( 1, sub( 14, q2 ) ), tmp ); /*Q(29-q2-8); */ + alpha = shl( alpha, sub( q2, 7 ) ); /*Q14 */ - beta = sub(16384, fmerit_w); /*Q14 */ + beta = sub( 16384, fmerit_w ); /*Q14 */ - L_tmp = L_mult(alpha, 31130); /*Q30 */ - gamma = round_fx(L_tmp); /*Q14 */ - gamma = sub(17203, gamma); /*Q14 */ - gamma = s_min(16384, gamma); - gamma = s_max(4915, gamma); + L_tmp = L_mult( alpha, 31130 ); /*Q30 */ + gamma = round_fx( L_tmp ); /*Q14 */ + gamma = sub( 17203, gamma ); /*Q14 */ + gamma = s_min( 16384, gamma ); + gamma = s_max( 4915, gamma ); - IF ( LT_16(beta, 16384)) + IF( LT_16( beta, 16384 ) ) { L_tmp = 1; /*variable for tonal energy*/ pt1 = hb_amb; pt2 = hb_tonal; pt3 = &dct_hb[240]; - FOR (i=0; i<8; i++) + FOR( i = 0; i < 8; i++ ) { - fn = add(i,8); - tmp1 = div_s(1, fn); /*Q15 */ + fn = add( i, 8 ); + tmp1 = div_s( 1, fn ); /*Q15 */ tmp = 0; move16(); pt4 = &dct_hb[240]; - FOR (j=0; j 0 ) + IF( *pt2 > 0 ) { - L_tmp = L_mac0(L_tmp, shr(*pt2,1), shr(*pt2,1)); + L_tmp = L_mac0( L_tmp, shr( *pt2, 1 ), shr( *pt2, 1 ) ); } pt1++; pt2++; pt3++; } - FOR (; i < L_SUBFR16k-8; i++) + FOR( ; i < L_SUBFR16k - 8; i++ ) { - fb = sub(i,7); - fn = add(fb,15); + fb = sub( i, 7 ); + fn = add( fb, 15 ); tmp = 0; - pt4 = &dct_hb[fb+240]; - FOR (j=fb; j 0 ) + IF( *pt2 > 0 ) { #ifdef BASOP_NOGLOB - L_tmp = L_mac0_sat(L_tmp, shr(*pt2,1), shr(*pt2,1)); + L_tmp = L_mac0_sat( L_tmp, shr( *pt2, 1 ), shr( *pt2, 1 ) ); #else - L_tmp = L_mac0(L_tmp, shr(*pt2,1), shr(*pt2,1)); + L_tmp = L_mac0( L_tmp, shr( *pt2, 1 ), shr( *pt2, 1 ) ); #endif } pt1++; pt2++; pt3++; } - FOR (; i 0 ) + IF( *pt2 > 0 ) { #ifdef BASOP_NOGLOB - L_tmp = L_mac0_sat(L_tmp, shr(*pt2,1), shr(*pt2,1)); /*2*qdct-2 */ + L_tmp = L_mac0_sat( L_tmp, shr( *pt2, 1 ), shr( *pt2, 1 ) ); /*2*qdct-2 */ #else - L_tmp = L_mac0(L_tmp, shr(*pt2,1), shr(*pt2,1)); /*2*qdct-2 */ + L_tmp = L_mac0( L_tmp, shr( *pt2, 1 ), shr( *pt2, 1 ) ); /*2*qdct-2 */ #endif } pt1++; @@ -1120,64 +1115,66 @@ void hf_synth_amr_wb_fx( } /*scaling of hb_ener is q1; tonal_ener0) + if ( *pt1 > 0 ) { - *pt1 = mult_r(*pt1,g); /*qdct */ move16(); + *pt1 = mult_r( *pt1, g ); /*qdct */ + move16(); } #ifdef BASOP_NOGLOB - * pt2 = round_fx_sat(L_shl_sat(L_mult(*pt2, inv_g), 3)); /*qdct */ - *pt3 = add_sat(*pt1, *pt2); + *pt2 = round_fx_sat( L_shl_sat( L_mult( *pt2, inv_g ), 3 ) ); /*qdct */ + *pt3 = add_sat( *pt1, *pt2 ); #else - * pt2 = round_fx(L_shl(L_mult(*pt2, inv_g), 3)); /*qdct */ - *pt3 = add(*pt1, *pt2); + *pt2 = round_fx( L_shl( L_mult( *pt2, inv_g ), 3 ) ); /*qdct */ + *pt3 = add( *pt1, *pt2 ); #endif move16(); - *pt3 = extract_l(L_mult0(*pt3, *pt4)); /*qdct */ + *pt3 = extract_l( L_mult0( *pt3, *pt4 ) ); /*qdct */ pt1++; pt2++; pt3++; pt4++; } - ener = dot_prod_satcontr(&dct_hb[240], &dct_hb[240], qdct, qdct, &q2, L_SUBFR16k); - scale = div_s(shl(1, 14), hb_ener); /*Q(29-q1) */ - L_tmp = L_mult(ener, scale); /*30-q1+q2 */ - q2 = sub(q1, q2); /*30-q2 */ - scale = round_fx(Isqrt(L_shl(L_tmp, sub(q2, 24)))); /*Q12 */ + ener = dot_prod_satcontr( &dct_hb[240], &dct_hb[240], qdct, qdct, &q2, L_SUBFR16k ); + scale = div_s( shl( 1, 14 ), hb_ener ); /*Q(29-q1) */ + L_tmp = L_mult( ener, scale ); /*30-q1+q2 */ + q2 = sub( q1, q2 ); /*30-q2 */ + scale = round_fx( Isqrt( L_shl( L_tmp, sub( q2, 24 ) ) ) ); /*Q12 */ #ifdef BASOP_NOGLOB - scale = round_fx_sat(L_shl_sat(L_mult(scale, gamma),4)); /*Q15 */ + scale = round_fx_sat( L_shl_sat( L_mult( scale, gamma ), 4 ) ); /*Q15 */ #else - scale = round_fx(L_shl(L_mult(scale, gamma),4)); /*Q15 */ + scale = round_fx( L_shl( L_mult( scale, gamma ), 4 ) ); /*Q15 */ #endif } ELSE { - scale = 32767; /*~1 in Q15 */ move16(); + scale = 32767; /*~1 in Q15 */ + move16(); } - IF ( EQ_32(core_brate, ACELP_6k60)) + IF( EQ_32( core_brate, ACELP_6k60 ) ) { filt_weight_coeff = 60; move16(); rev_filt_weight_coeff = 555; move16(); /* 1/(filt_weight_coeff-1) Q15 */ } - ELSE IF ( EQ_32(core_brate, ACELP_8k85)) + ELSE IF( EQ_32( core_brate, ACELP_8k85 ) ) { filt_weight_coeff = 40; move16(); @@ -1193,41 +1190,42 @@ void hf_synth_amr_wb_fx( } pt1 = filt_weight; - FOR ( i = 0; i < filt_weight_coeff; i++) + FOR( i = 0; i < filt_weight_coeff; i++ ) { - L_tmp = L_mult(-32735, rev_filt_weight_coeff); /*Q31 */ - L_tmp = L_shl(Mult_32_16(L_tmp, i), 14); /*Q16+14 */ - *pt1++ = add(round_fx(L_tmp), 16384); - move16();/*Q14 */ + L_tmp = L_mult( -32735, rev_filt_weight_coeff ); /*Q31 */ + L_tmp = L_shl( Mult_32_16( L_tmp, i ), 14 ); /*Q16+14 */ + *pt1++ = add( round_fx( L_tmp ), 16384 ); + move16(); /*Q14 */ } - IF ( EQ_32(core_brate, ACELP_23k85)) + IF( EQ_32( core_brate, ACELP_23k85 ) ) { - pt1 = dct_hb+240; - tmp = sub(filt_weight_coeff, 80); - pt3 = filt_weight+tmp; + pt1 = dct_hb + 240; + tmp = sub( filt_weight_coeff, 80 ); + pt3 = filt_weight + tmp; FOR( i = 240; i < L_FRAME16k; i++ ) { - *pt1 = mult_r(*pt1, scale); /*qdct */ move16(); + *pt1 = mult_r( *pt1, scale ); /*qdct */ + move16(); - IF ( GE_16(i, sub(L_FRAME16k, filt_weight_coeff))) + IF( GE_16( i, sub( L_FRAME16k, filt_weight_coeff ) ) ) { - *pt1 = round_fx(L_shl(L_mult(*pt3, *pt1), 1)); /*qdct */ + *pt1 = round_fx( L_shl( L_mult( *pt3, *pt1 ), 1 ) ); /*qdct */ } pt1++; pt3++; } - pt1 = dct_hb+200; + pt1 = dct_hb + 200; pt6 = filt_hp_fx; FOR( i = 200; i < 256; i++ ) { - *pt1 = mult_r(*pt6++, *pt1); + *pt1 = mult_r( *pt6++, *pt1 ); move16(); /*qdct */ pt1++; } pt1 = HF_corr_gain; pt6 = hf_gain; - FOR ( i = 0; i < NB_SUBFR; i++) + FOR( i = 0; i < NB_SUBFR; i++ ) { tmp = *pt6++; move16(); @@ -1237,102 +1235,102 @@ void hf_synth_amr_wb_fx( } ELSE { - pt1 = dct_hb+240; - tmp = sub(filt_weight_coeff, 80); - pt3 = filt_weight+tmp; + pt1 = dct_hb + 240; + tmp = sub( filt_weight_coeff, 80 ); + pt3 = filt_weight + tmp; FOR( i = 240; i < L_FRAME16k; i++ ) { - *pt1 = mult_r(*pt1, scale); /*qdct */ - IF ( GT_16(i, 255)) + *pt1 = mult_r( *pt1, scale ); /*qdct */ + IF( GT_16( i, 255 ) ) { - *pt1 = mult_r(19505, *pt1); + *pt1 = mult_r( 19505, *pt1 ); move16(); } - IF ( GE_16(i, sub(L_FRAME16k, filt_weight_coeff))) + IF( GE_16( i, sub( L_FRAME16k, filt_weight_coeff ) ) ) { - *pt1 = round_fx(L_shl(L_mult(*pt3, *pt1), 1)); /*qdct */ + *pt1 = round_fx( L_shl( L_mult( *pt3, *pt1 ), 1 ) ); /*qdct */ } pt1++; pt3++; } - pt1 = dct_hb+200; + pt1 = dct_hb + 200; pt6 = filt_hp_fx; pt7 = deem_tab_fx; FOR( i = 200; i < 256; i++ ) { - *pt1 = mult_r(*pt6++, *pt1); - move16();/*qdct */ - *pt1 = mult_r(*pt7++, *pt1); + *pt1 = mult_r( *pt6++, *pt1 ); + move16(); /*qdct */ + *pt1 = mult_r( *pt7++, *pt1 ); move16(); pt1++; } } - q_tmp = Exp16Array(L_FRAME16k, dct_hb); - qhf = sub(q_tmp, 1); - Copy_Scale_sig_16_32(dct_hb, dct_hb32, L_FRAME16k, qhf); - qhf = add(qhf, qdct); - edct_fx(dct_hb32, exc16k32, L_FRAME16k, &qhf); - q_tmp = Exp32Array(L_FRAME16k, exc16k32); - q_tmp = sub(q_tmp,16); - Copy_Scale_sig_32_16(exc16k32, exc16k, L_FRAME16k, q_tmp); - qhf = add(qhf, q_tmp); + q_tmp = Exp16Array( L_FRAME16k, dct_hb ); + qhf = sub( q_tmp, 1 ); + Copy_Scale_sig_16_32( dct_hb, dct_hb32, L_FRAME16k, qhf ); + qhf = add( qhf, qdct ); + edct_fx( dct_hb32, exc16k32, L_FRAME16k, &qhf ); + q_tmp = Exp32Array( L_FRAME16k, exc16k32 ); + q_tmp = sub( q_tmp, 16 ); + Copy_Scale_sig_32_16( exc16k32, exc16k, L_FRAME16k, q_tmp ); + qhf = add( qhf, q_tmp ); - ener = dot_prod_satcontr(exc, exc, Q_exc, Q_exc, &q1, L_FRAME); - tmp = dot_prod_satcontr(exc16k, exc16k, qhf, qhf, &q2, L_FRAME16k); + ener = dot_prod_satcontr( exc, exc, Q_exc, Q_exc, &q1, L_FRAME ); + tmp = dot_prod_satcontr( exc16k, exc16k, qhf, qhf, &q2, L_FRAME16k ); pt6 = exc; pt2 = exc16k; - FOR ( i = 0; i < NB_SUBFR; i++ ) + FOR( i = 0; i < NB_SUBFR; i++ ) { - e_subfr1 = dot_prod_satcontr(pt6, pt6, Q_exc, Q_exc, &q3, L_SUBFR); - e_subfr2 = dot_prod_satcontr(pt2, pt2, qhf, qhf, &q4, L_SUBFR16k); + e_subfr1 = dot_prod_satcontr( pt6, pt6, Q_exc, Q_exc, &q3, L_SUBFR ); + e_subfr2 = dot_prod_satcontr( pt2, pt2, qhf, qhf, &q4, L_SUBFR16k ); - L_tmp = L_mult(e_subfr1, tmp); /*Q(q2+q3+1) */ - q3 = add(add(q2, q3), 1); - shift = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, shift); /*Q(q3+shift); */ - q3 = add(q3, shift); + L_tmp = L_mult( e_subfr1, tmp ); /*Q(q2+q3+1) */ + q3 = add( add( q2, q3 ), 1 ); + shift = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, shift ); /*Q(q3+shift); */ + q3 = add( q3, shift ); #ifdef BASOP_NOGLOB - scale = round_fx_sat(L_tmp); /*Q(q3-16); */ + scale = round_fx_sat( L_tmp ); /*Q(q3-16); */ #else - scale = round_fx(L_tmp); /*Q(q3-16); */ + scale = round_fx( L_tmp ); /*Q(q3-16); */ #endif - q3 = sub(q3, 16); - scale = div_s(shl(1, 14), scale); /*Q(29-q3) */ - L_tmp = L_mult(scale, ener); /*Q(29-q3+q1+1) */ - shift = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, shift); /*Q(29-q3+q1+1+shift) */ + q3 = sub( q3, 16 ); + scale = div_s( shl( 1, 14 ), scale ); /*Q(29-q3) */ + L_tmp = L_mult( scale, ener ); /*Q(29-q3+q1+1) */ + shift = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, shift ); /*Q(29-q3+q1+1+shift) */ #ifdef BASOP_NOGLOB - scale = round_fx_sat(L_tmp); /*Q(29-q3+q1+1+shift-16) */ + scale = round_fx_sat( L_tmp ); /*Q(29-q3+q1+1+shift-16) */ #else - scale = round_fx(L_tmp); /*Q(29-q3+q1+1+shift-16) */ + scale = round_fx( L_tmp ); /*Q(29-q3+q1+1+shift-16) */ #endif - L_tmp = L_mult(scale, e_subfr2); /*Q(29-q3+q1+1+shift-16+q4+1)=Q(15+q1-q3+q4+shift) */ - q3 = sub(15, q3); - q3 = add(q3, q1); - q3 = add(q3, shift); - q3 = add(q3, q4); + L_tmp = L_mult( scale, e_subfr2 ); /*Q(29-q3+q1+1+shift-16+q4+1)=Q(15+q1-q3+q4+shift) */ + q3 = sub( 15, q3 ); + q3 = add( q3, q1 ); + q3 = add( q3, shift ); + q3 = add( q3, q4 ); #ifdef BASOP_NOGLOB - scale = round_fx_sat(Isqrt(L_shl_sat(L_tmp, sub(6, q3)))); /*Q12 */ + scale = round_fx_sat( Isqrt( L_shl_sat( L_tmp, sub( 6, q3 ) ) ) ); /*Q12 */ #else - scale = round_fx(Isqrt(L_shl(L_tmp, sub(6, q3)))); /*Q12 */ + scale = round_fx( Isqrt( L_shl( L_tmp, sub( 6, q3 ) ) ) ); /*Q12 */ #endif pt6 += L_SUBFR; - FOR ( j = 0; j < L_SUBFR16k; j++ ) + FOR( j = 0; j < L_SUBFR16k; j++ ) { #ifdef BASOP_NOGLOB - *pt2 = round_fx_sat(L_shl_sat(L_mult(*pt2, scale), 2)); /*qhf-1 */ + *pt2 = round_fx_sat( L_shl_sat( L_mult( *pt2, scale ), 2 ) ); /*qhf-1 */ #else - *pt2 = round_fx(L_shl(L_mult(*pt2, scale), 2)); /*qhf-1 */ + *pt2 = round_fx( L_shl( L_mult( *pt2, scale ), 2 ) ); /*qhf-1 */ #endif pt2++; } } - qhf = sub(qhf, 1); + qhf = sub( qhf, 1 ); p_Ap = Ap; pt1 = exc16k; @@ -1345,9 +1343,9 @@ void hf_synth_amr_wb_fx( FOR( i = 0; i < NB_SUBFR; i++ ) { - hf_synthesis_amr_wb_fx( core_brate, output_subfr, p_Ap, pt1, pt2, hBWE_zero->mem_syn_hf_fx, hBWE_zero->delay_syn_hf_fx, - hBWE_zero->mem_hp_interp_fx, *pt3, *pt4, *pt5, *pt6, pt7, Q_exc, Q_out, qhf); - p_Ap += (M+1); + hf_synthesis_amr_wb_fx( core_brate, output_subfr, p_Ap, pt1, pt2, hBWE_zero->mem_syn_hf_fx, hBWE_zero->delay_syn_hf_fx, + hBWE_zero->mem_hp_interp_fx, *pt3, *pt4, *pt5, *pt6, pt7, Q_exc, Q_out, qhf ); + p_Ap += ( M + 1 ); pt1 += L_SUBFR16k; pt2 += output_subfr; pt3++; @@ -1360,90 +1358,91 @@ void hf_synth_amr_wb_fx( return; } static void hf_synthesis_amr_wb_fx( - const Word32 core_brate, /* i : core bitrate : Q0 */ - const Word16 output_subfr, /* i : output sub-frame length : Q0 */ - const Word16 Ap[], /* i : quantized Aq : Q12 */ - Word16 exc16k[], /* i : excitation at 16 kHz : Qhf */ - Word16 synth_out[], /* i/o: synthesis signal at output Fs : Qo */ - Word16 *mem_syn_hf, /* i/o: HF synthesis memory : Qo */ - Word16 *delay_syn_hf, /* i/o: HF synthesis memory : Qo */ - Word16 *mem_hp_interp, /* i/o: interpol. memory : Qo */ - Word16 p_r, /* i : sub-frame gain : Q12 */ - Word16 HF_corr_gain, /* i : HF gain index : Q14 */ - Word16 til, /*Q14*/ - Word16 voice_factors, /*Q14*/ - const Word16 exc[], /* i : excitation at 12.8 kHz : Qi */ - const Word16 Q_exc, /*exc scaling*/ - const Word16 Q_out, /*synth_out scaling*/ - Word16 qhf /*exc16k scaling*/ + const Word32 core_brate, /* i : core bitrate : Q0 */ + const Word16 output_subfr, /* i : output sub-frame length : Q0 */ + const Word16 Ap[], /* i : quantized Aq : Q12 */ + Word16 exc16k[], /* i : excitation at 16 kHz : Qhf */ + Word16 synth_out[], /* i/o: synthesis signal at output Fs : Qo */ + Word16 *mem_syn_hf, /* i/o: HF synthesis memory : Qo */ + Word16 *delay_syn_hf, /* i/o: HF synthesis memory : Qo */ + Word16 *mem_hp_interp, /* i/o: interpol. memory : Qo */ + Word16 p_r, /* i : sub-frame gain : Q12 */ + Word16 HF_corr_gain, /* i : HF gain index : Q14 */ + Word16 til, /*Q14*/ + Word16 voice_factors, /*Q14*/ + const Word16 exc[], /* i : excitation at 12.8 kHz : Qi */ + const Word16 Q_exc, /*exc scaling*/ + const Word16 Q_out, /*synth_out scaling*/ + Word16 qhf /*exc16k scaling*/ ) { Word16 i; Word16 HF_syn[L_SUBFR16k], upsampled_HF_syn[L_SUBFR48k]; Word16 ener, tmp, scale, exc2385[L_SUBFR16k]; Word32 L_tmp; - Word16 q1, q2,q3, shift; + Word16 q1, q2, q3, shift; Word16 *pt1, *pt2, flag; - IF ( EQ_32(core_brate, ACELP_23k85)) + IF( EQ_32( core_brate, ACELP_23k85 ) ) { - ener = dot_prod_satcontr(exc, exc, Q_exc, Q_exc, &q1, L_SUBFR); - tmp = dot_prod_satcontr(exc16k, exc16k, qhf, qhf, &q2, L_SUBFR16k); + ener = dot_prod_satcontr( exc, exc, Q_exc, Q_exc, &q1, L_SUBFR ); + tmp = dot_prod_satcontr( exc16k, exc16k, qhf, qhf, &q2, L_SUBFR16k ); - L_tmp = L_mult(ener, 6554); /*Q(q1+16) */ - q3 = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, q3); /*Q(q1+q3+16) */ - ener = extract_h(L_tmp); /*Q(q1+q3); */ - q1 = add(q1, q3); + L_tmp = L_mult( ener, 6554 ); /*Q(q1+16) */ + q3 = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, q3 ); /*Q(q1+q3+16) */ + ener = extract_h( L_tmp ); /*Q(q1+q3); */ + q1 = add( q1, q3 ); - scale = div_s(shl(1, 14), ener); /*Q(29-q1) */ - L_tmp = L_mult(tmp, scale); /*30-q1+q2 */ - q2 = sub(q1, q2); /*30-q2 */ + scale = div_s( shl( 1, 14 ), ener ); /*Q(29-q1) */ + L_tmp = L_mult( tmp, scale ); /*30-q1+q2 */ + q2 = sub( q1, q2 ); /*30-q2 */ #ifdef BASOP_NOGLOB - scale = round_fx_sat(Isqrt(L_shl_sat(L_tmp, sub(q2, 24)))); /*Q12 */ + scale = round_fx_sat( Isqrt( L_shl_sat( L_tmp, sub( q2, 24 ) ) ) ); /*Q12 */ #else - scale = round_fx(Isqrt(L_shl(L_tmp, sub(q2, 24)))); /*Q12 */ + scale = round_fx( Isqrt( L_shl( L_tmp, sub( q2, 24 ) ) ) ); /*Q12 */ #endif pt1 = exc16k; pt2 = exc2385; - FOR ( i = 0; i < L_SUBFR16k; i++ ) + FOR( i = 0; i < L_SUBFR16k; i++ ) { - L_tmp = L_mult(*pt1++, HF_corr_gain); /*qhf+15*/ - L_tmp = Mult_32_16(L_tmp, scale); /*qhf-1+12+1*/ - *pt2++ = round_fx(L_shl(L_tmp, 1)); /*qhf-3*/ + L_tmp = L_mult( *pt1++, HF_corr_gain ); /*qhf+15*/ + L_tmp = Mult_32_16( L_tmp, scale ); /*qhf-1+12+1*/ + *pt2++ = round_fx( L_shl( L_tmp, 1 ) ); /*qhf-3*/ } pt1 = exc16k; - FOR ( i = 0; i < L_SUBFR16k; i++ ) + FOR( i = 0; i < L_SUBFR16k; i++ ) { - *pt1 = mult_r(*pt1, p_r); /*qhf-3*/ move16(); + *pt1 = mult_r( *pt1, p_r ); /*qhf-3*/ + move16(); pt1++; } - qhf = sub(qhf, 3); + qhf = sub( qhf, 3 ); - ener = dot_prod_satcontr(exc16k, exc16k, qhf, qhf, &q1, L_SUBFR16k); - tmp = dot_prod_satcontr(exc2385, exc2385, qhf, qhf, &q2, L_SUBFR16k); - L_tmp = L_mult(ener, 9830); /*Q(q1+16) */ - q3 = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, q3); /*Q(q1+q3+16) */ - ener = extract_h(L_tmp); /*Q(q1+q3); */ - q1 = add(q1, q3); + ener = dot_prod_satcontr( exc16k, exc16k, qhf, qhf, &q1, L_SUBFR16k ); + tmp = dot_prod_satcontr( exc2385, exc2385, qhf, qhf, &q2, L_SUBFR16k ); + L_tmp = L_mult( ener, 9830 ); /*Q(q1+16) */ + q3 = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, q3 ); /*Q(q1+q3+16) */ + ener = extract_h( L_tmp ); /*Q(q1+q3); */ + q1 = add( q1, q3 ); - scale = div_s(shl(1, 14), ener); /*Q(29-q1) */ - L_tmp = L_mult(tmp, scale); /*30-q1+q2 */ - q2 = sub(q1, q2); /*30-q2 */ + scale = div_s( shl( 1, 14 ), ener ); /*Q(29-q1) */ + L_tmp = L_mult( tmp, scale ); /*30-q1+q2 */ + q2 = sub( q1, q2 ); /*30-q2 */ #ifdef BASOP_NOGLOB - scale = round_fx_sat(Isqrt(L_shl_sat(L_tmp, sub(q2, 24)))); /*Q12 */ + scale = round_fx_sat( Isqrt( L_shl_sat( L_tmp, sub( q2, 24 ) ) ) ); /*Q12 */ #else - scale = round_fx(Isqrt(L_shl(L_tmp, sub(q2, 24)))); /*Q12 */ + scale = round_fx( Isqrt( L_shl( L_tmp, sub( q2, 24 ) ) ) ); /*Q12 */ #endif - flag = negate(s_and(til,-0x8000)); - if (GT_16(scale, 4096)) + flag = negate( s_and( til, -0x8000 ) ); + if ( GT_16( scale, 4096 ) ) { flag = 1; move16(); } - IF ( flag ) + IF( flag ) { Copy( exc2385, exc16k, L_SUBFR16k ); } @@ -1451,31 +1450,31 @@ static void hf_synthesis_amr_wb_fx( { pt1 = exc16k; pt2 = exc2385; - FOR ( i = 0; i < L_SUBFR16k; i++ ) + FOR( i = 0; i < L_SUBFR16k; i++ ) { - tmp = sub(16348, shl(til, 1));/*Q14 */ - L_tmp = L_mult(tmp, sub(26214, shr(voice_factors, 1))); /*Q29*/ - tmp = round_fx(L_shr(L_tmp, 1)); /*Q12*/ - tmp = s_min(tmp, 4096); - tmp = s_max(tmp, scale); - *pt1++ = round_fx(L_shl(L_mult(*pt2++, tmp), 3))/*qhf*/; + tmp = sub( 16348, shl( til, 1 ) ); /*Q14 */ + L_tmp = L_mult( tmp, sub( 26214, shr( voice_factors, 1 ) ) ); /*Q29*/ + tmp = round_fx( L_shr( L_tmp, 1 ) ); /*Q12*/ + tmp = s_min( tmp, 4096 ); + tmp = s_max( tmp, scale ); + *pt1++ = round_fx( L_shl( L_mult( *pt2++, tmp ), 3 ) ) /*qhf*/; } } - } ELSE { pt1 = exc16k; - FOR ( i = 0; i < L_SUBFR16k; i++ ) + FOR( i = 0; i < L_SUBFR16k; i++ ) { - *pt1 = mult_r(*pt1, p_r); /*qhf-3*/ move16(); + *pt1 = mult_r( *pt1, p_r ); /*qhf-3*/ + move16(); pt1++; } - qhf = sub(qhf, 3); + qhf = sub( qhf, 3 ); } - shift = sub(qhf, Q_out); + shift = sub( qhf, Q_out ); Syn_filt_s( shift, Ap, M, exc16k, HF_syn, L_SUBFR16k, mem_syn_hf, 1 ); /*Q_out=qhf-shift */ /*-----------------------------------------------------------------* @@ -1483,41 +1482,42 @@ static void hf_synthesis_amr_wb_fx( * Synchronize LB and HB components (delay componsation) * Add synthesised high band to speech synthesis *-----------------------------------------------------------------*/ - delay_signal(HF_syn, L_SUBFR16k, delay_syn_hf, NS2SA(16000, DELAY_CLDFB_NS)); + delay_signal( HF_syn, L_SUBFR16k, delay_syn_hf, NS2SA( 16000, DELAY_CLDFB_NS ) ); - IF( EQ_16(output_subfr, L_SUBFR48k)) /* 48kHz sampled output */ + IF( EQ_16( output_subfr, L_SUBFR48k ) ) /* 48kHz sampled output */ { Word16 s; - s = s_max(s_min(sub(s_min(Find_Max_Norm16(HF_syn, L_SUBFR16k), Find_Max_Norm16(mem_hp_interp, INTERP_3_1_MEM_LEN - 3)), 3), - sub(Find_Max_Norm16(mem_hp_interp + INTERP_3_1_MEM_LEN - 3, 3), 1)), 0 ); + s = s_max( s_min( sub( s_min( Find_Max_Norm16( HF_syn, L_SUBFR16k ), Find_Max_Norm16( mem_hp_interp, INTERP_3_1_MEM_LEN - 3 ) ), 3 ), + sub( Find_Max_Norm16( mem_hp_interp + INTERP_3_1_MEM_LEN - 3, 3 ), 1 ) ), + 0 ); Scale_sig( HF_syn, L_SUBFR16k, s ); Scale_sig( mem_hp_interp, INTERP_3_1_MEM_LEN, s ); - interpolate_3_over_1_allpass_fx( HF_syn, L_SUBFR16k, upsampled_HF_syn, mem_hp_interp); + interpolate_3_over_1_allpass_fx( HF_syn, L_SUBFR16k, upsampled_HF_syn, mem_hp_interp ); - Scale_sig( upsampled_HF_syn, L_SUBFR48k, add(-s,-1) ); + Scale_sig( upsampled_HF_syn, L_SUBFR48k, add( -s, -1 ) ); Scale_sig( mem_hp_interp, INTERP_3_1_MEM_LEN, -s ); Scale_sig( HF_syn, L_SUBFR16k, -s ); } - ELSE IF( EQ_16(output_subfr, L_SUBFR32k)) /* 32kHz sampled output */ + ELSE IF( EQ_16( output_subfr, L_SUBFR32k ) ) /* 32kHz sampled output */ { Word16 s; - s = s_max( sub(s_min(Find_Max_Norm16(HF_syn, L_SUBFR16k), Find_Max_Norm16(mem_hp_interp, 2*ALLPASSSECTIONS_STEEP)),2), 0 ); + s = s_max( sub( s_min( Find_Max_Norm16( HF_syn, L_SUBFR16k ), Find_Max_Norm16( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP ) ), 2 ), 0 ); Scale_sig( HF_syn, L_SUBFR16k, s ); - Scale_sig( mem_hp_interp, 2*ALLPASSSECTIONS_STEEP, s ); + Scale_sig( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP, s ); Interpolate_allpass_steep_fx( HF_syn, mem_hp_interp, L_SUBFR16k, upsampled_HF_syn ); - Scale_sig( upsampled_HF_syn, 2*L_SUBFR16k, -s ); - Scale_sig( mem_hp_interp, 2*ALLPASSSECTIONS_STEEP, -s ); + Scale_sig( upsampled_HF_syn, 2 * L_SUBFR16k, -s ); + Scale_sig( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP, -s ); Scale_sig( HF_syn, L_SUBFR16k, -s ); } - ELSE /* 16kHz sampled output */ + ELSE /* 16kHz sampled output */ { Copy( HF_syn, upsampled_HF_syn, L_SUBFR16k ); } - Vr_add( synth_out, upsampled_HF_syn, synth_out, output_subfr); + Vr_add( synth_out, upsampled_HF_syn, synth_out, output_subfr ); return; } @@ -1525,13 +1525,13 @@ static void hf_synthesis_amr_wb_fx( static Word16 EnhanceClass_fx( const Word16 qq_fx, const Word16 pp_fx, - const Word16 tilt0_fx, /* i : spectrum tilt */ - const Word16 tilt_fx, /* i : spectrum tilt */ - const Word16 voice_factor_fx, /* i : voice factor */ - Word16 *voice_fac_fx, /* i/o: smoothed voiced parameter */ - Word16 *unvoicing_fx, /* i/o: unvoiced parameter */ - Word16 *unvoicing_sm_fx, /* i/o: smoothed unvoiced parameter */ - Word16 *unvoicing_flag /* i/o: unvoiced flag */ + const Word16 tilt0_fx, /* i : spectrum tilt */ + const Word16 tilt_fx, /* i : spectrum tilt */ + const Word16 voice_factor_fx, /* i : voice factor */ + Word16 *voice_fac_fx, /* i/o: smoothed voiced parameter */ + Word16 *unvoicing_fx, /* i/o: unvoiced parameter */ + Word16 *unvoicing_sm_fx, /* i/o: smoothed unvoiced parameter */ + Word16 *unvoicing_flag /* i/o: unvoiced flag */ ) { Word16 unvoicing_tmp_fx; @@ -1544,87 +1544,87 @@ static Word16 EnhanceClass_fx( /* Decide (*unvoicing_flag) to allow BWE enhancement when qq>pp */ /**voice_fac_fx = add(mult_r(*voice_fac_fx, 24576), mult_r(voice_factor_fx, 8192)); //Q15 */ - *voice_fac_fx = round_fx(L_mac(L_mult(*voice_fac_fx, 24576), voice_factor_fx, 8192)); /*Q15 */ + *voice_fac_fx = round_fx( L_mac( L_mult( *voice_fac_fx, 24576 ), voice_factor_fx, 8192 ) ); /*Q15 */ - tmp = mult_r(sub(8192, tilt0_fx), 16384); /*Q13 */ + tmp = mult_r( sub( 8192, tilt0_fx ), 16384 ); /*Q13 */ - L_tmp = L_sub(32768, *voice_fac_fx); /*Q15 */ + L_tmp = L_sub( 32768, *voice_fac_fx ); /*Q15 */ - L_tmp = Mult_32_16(L_tmp, tmp); /*Q13 */ - tmp = extract_l(L_tmp); /*Q13 */ + L_tmp = Mult_32_16( L_tmp, tmp ); /*Q13 */ + tmp = extract_l( L_tmp ); /*Q13 */ - tmp1 = mult_r(tilt_fx, 21845); /*Q15->1/1.5 ->Q13+15-15->Q13 */ - tmp1 = s_min(tmp1, 8192); + tmp1 = mult_r( tilt_fx, 21845 ); /*Q15->1/1.5 ->Q13+15-15->Q13 */ + tmp1 = s_min( tmp1, 8192 ); - L_tmp = L_mult(tmp, tmp1); /*Q13+Q13+1 */ - unvoicing_tmp_fx = extract_l(L_shr(L_tmp, 12)); /*Q15 */ + L_tmp = L_mult( tmp, tmp1 ); /*Q13+Q13+1 */ + unvoicing_tmp_fx = extract_l( L_shr( L_tmp, 12 ) ); /*Q15 */ /**unvoicing_fx = add(mult_r(16384, *unvoicing_fx), mult_r(16384, unvoicing_tmp_fx)); //Q15 */ - *unvoicing_fx = round_fx(L_mac(L_mult(16384, *unvoicing_fx), 16384, unvoicing_tmp_fx)); /*Q15 */ + *unvoicing_fx = round_fx( L_mac( L_mult( 16384, *unvoicing_fx ), 16384, unvoicing_tmp_fx ) ); /*Q15 */ - IF( GT_16(*unvoicing_sm_fx, *unvoicing_fx)) + IF( GT_16( *unvoicing_sm_fx, *unvoicing_fx ) ) { /**unvoicing_sm_fx = add(mult_r(29491, *unvoicing_sm_fx), mult_r(3277, *unvoicing_fx)); //Q15 */ - *unvoicing_sm_fx = round_fx(L_mac(L_mult(29491, *unvoicing_sm_fx), 3277, *unvoicing_fx)); /*Q15 */ + *unvoicing_sm_fx = round_fx( L_mac( L_mult( 29491, *unvoicing_sm_fx ), 3277, *unvoicing_fx ) ); /*Q15 */ } ELSE { /**unvoicing_sm_fx = add(mult_r(32440, *unvoicing_sm_fx), mult_r(328, *unvoicing_fx)); //Q15 */ - *unvoicing_sm_fx = round_fx(L_mac(L_mult(32440, *unvoicing_sm_fx), 328, *unvoicing_fx)); /*Q15 */ + *unvoicing_sm_fx = round_fx( L_mac( L_mult( 32440, *unvoicing_sm_fx ), 328, *unvoicing_fx ) ); /*Q15 */ } #ifdef BASOP_NOGLOB - if (GT_16(sub_o(*unvoicing_fx, *unvoicing_sm_fx, &Overflow), 3277)) + if ( GT_16( sub_o( *unvoicing_fx, *unvoicing_sm_fx, &Overflow ), 3277 ) ) #else - if ( GT_16(sub(*unvoicing_fx, *unvoicing_sm_fx),3277)) + if ( GT_16( sub( *unvoicing_fx, *unvoicing_sm_fx ), 3277 ) ) #endif { *unvoicing_flag = 1; } #ifdef BASOP_NOGLOB - if (LT_16(sub_o(*unvoicing_fx, *unvoicing_sm_fx, &Overflow), 1638)) + if ( LT_16( sub_o( *unvoicing_fx, *unvoicing_sm_fx, &Overflow ), 1638 ) ) #else - if ( LT_16(sub(*unvoicing_fx, *unvoicing_sm_fx),1638)) + if ( LT_16( sub( *unvoicing_fx, *unvoicing_sm_fx ), 1638 ) ) #endif { *unvoicing_flag = 0; } test(); - return ( *unvoicing_flag && GT_16(qq_fx, pp_fx) ); + return ( *unvoicing_flag && GT_16( qq_fx, pp_fx ) ); } static void envelope_fx( AMRWB_IO_DEC_HANDLE hAmrwb_IO, - const Word32 core_brate, /* i : core bitrate */ - const Word16 Aq_dyn_scal[], /* i : de-quant. LPC coefficents, dynamic scaling */ - Word16 Ap[], /* o : extended LPC coefficents, Q12 */ - Word16 *sub_gain, /* o : sub-frame gain, Q12 */ - Word16 tilt0, /* i : spectrum tilt, Q14 */ - Word16 tilt, /* i : spectrum tilt, Q13 */ - Word16 voice_factor /* i : voice factor, Q15 */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 Aq_dyn_scal[], /* i : de-quant. LPC coefficents, dynamic scaling */ + Word16 Ap[], /* o : extended LPC coefficents, Q12 */ + Word16 *sub_gain, /* o : sub-frame gain, Q12 */ + Word16 tilt0, /* i : spectrum tilt, Q14 */ + Word16 tilt, /* i : spectrum tilt, Q13 */ + Word16 voice_factor /* i : voice factor, Q15 */ ) { Word16 px, py, rx, ry, pp, rr, qx, qy, qq; /*Q10*/ Word16 i, Unvoicing_flag; - Word16 alpha; /*Q14*/ + Word16 alpha; /*Q14*/ Word16 est_level1, est_level2; /*Q10*/ Word32 L_tmp; Word16 tmp, q1, q2, q3, shift; Word16 As[3], k1, k2; Word16 *pt1; const Word16 *pt2, *pt3; - Word16 Aq[M+1]; + Word16 Aq[M + 1]; /* Aq has dynamic scaling go back to Q12 to make sure there's no overflow while calculating qx,qy*/ - shift = sub(norm_s(Aq_dyn_scal[0]),2); - Copy_Scale_sig(Aq_dyn_scal, Aq, M+1, shift); + shift = sub( norm_s( Aq_dyn_scal[0] ), 2 ); + Copy_Scale_sig( Aq_dyn_scal, Aq, M + 1, shift ); /* LPC envelope weighting */ - IF( EQ_32(core_brate,ACELP_6k60)) + IF( EQ_32( core_brate, ACELP_6k60 ) ) { weight_a_lc_fx( Aq, Ap, Gamma_29491_Tbl, M ); } @@ -1634,110 +1634,110 @@ static void envelope_fx( } /* Ap has dynamic scaling go back to Q12 to make sure there's no overflow while calculating px,py*/ - shift = sub(norm_s(Ap[0]),2); - IF(shift != 0) + shift = sub( norm_s( Ap[0] ), 2 ); + IF( shift != 0 ) { - Scale_sig(Ap, M+1, shift); + Scale_sig( Ap, M + 1, shift ); } /* LPC envelope level estimate */ - L_tmp = L_deposit_l(0); + L_tmp = L_deposit_l( 0 ); pt1 = Ap; pt2 = exp_tab_p_fx; - FOR ( i = 0; i <= M; i++ ) + FOR( i = 0; i <= M; i++ ) { - L_tmp = L_mac(L_tmp, *pt1++, *pt2++); + L_tmp = L_mac( L_tmp, *pt1++, *pt2++ ); } - q1 = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, q1);/*Q(27+q1)*/ - px = round_fx(L_shr(L_tmp, 1)); /*Q(10+q1)*/ + q1 = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, q1 ); /*Q(27+q1)*/ + px = round_fx( L_shr( L_tmp, 1 ) ); /*Q(10+q1)*/ - L_tmp = L_deposit_l(0); + L_tmp = L_deposit_l( 0 ); pt1 = Ap; - pt2 = exp_tab_p_fx+33; - FOR ( i = 0; i <= M; i++ ) + pt2 = exp_tab_p_fx + 33; + FOR( i = 0; i <= M; i++ ) { - L_tmp = L_mac(L_tmp, *pt1++, *pt2--); + L_tmp = L_mac( L_tmp, *pt1++, *pt2-- ); } - q2 = norm_l(L_tmp); - shift = sub(q1, q2); - IF ( shift >= 0 ) + q2 = norm_l( L_tmp ); + shift = sub( q1, q2 ); + IF( shift >= 0 ) { - px = shr(px, shift); - L_tmp = L_shl(L_tmp, q2);/*Q(27+q2)*/ + px = shr( px, shift ); + L_tmp = L_shl( L_tmp, q2 ); /*Q(27+q2)*/ q1 = q2; move16(); } ELSE { - L_tmp = L_shl(L_tmp, q1);/*Q(27+q1)*/ + L_tmp = L_shl( L_tmp, q1 ); /*Q(27+q1)*/ } - py = round_fx(L_shr(L_tmp, 1)); /*Q(10+q1)*/ + py = round_fx( L_shr( L_tmp, 1 ) ); /*Q(10+q1)*/ - L_tmp = L_deposit_l(0); + L_tmp = L_deposit_l( 0 ); pt2 = Aq; pt3 = exp_tab_q_fx; - FOR ( i = 0; i <= M; i++ ) + FOR( i = 0; i <= M; i++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_mac_sat(L_tmp, *pt2++, *pt3++); + L_tmp = L_mac_sat( L_tmp, *pt2++, *pt3++ ); #else - L_tmp = L_mac(L_tmp, *pt2++, *pt3++); + L_tmp = L_mac( L_tmp, *pt2++, *pt3++ ); #endif } - q2 = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, q2);/*Q(27+q2)*/ - rx = round_fx(L_shr(L_tmp, 1)); /*Q(10+q2)*/ + q2 = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, q2 ); /*Q(27+q2)*/ + rx = round_fx( L_shr( L_tmp, 1 ) ); /*Q(10+q2)*/ - L_tmp = L_deposit_l(0); + L_tmp = L_deposit_l( 0 ); pt2 = Aq; - pt3 = exp_tab_q_fx+33; - FOR ( i = 0; i <= M; i++ ) + pt3 = exp_tab_q_fx + 33; + FOR( i = 0; i <= M; i++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_mac_sat(L_tmp, *pt2++, *pt3--); + L_tmp = L_mac_sat( L_tmp, *pt2++, *pt3-- ); #else - L_tmp = L_mac(L_tmp, *pt2++, *pt3--); + L_tmp = L_mac( L_tmp, *pt2++, *pt3-- ); #endif } - q3 = norm_l(L_tmp); - shift = sub(q2, q3); - IF ( shift >= 0 ) + q3 = norm_l( L_tmp ); + shift = sub( q2, q3 ); + IF( shift >= 0 ) { - rx = shr(rx, shift); - L_tmp = L_shl(L_tmp, q3);/*Q(27+q3)*/ + rx = shr( rx, shift ); + L_tmp = L_shl( L_tmp, q3 ); /*Q(27+q3)*/ q2 = q3; move16(); } ELSE { - L_tmp = L_shl(L_tmp, q2);/*Q(27+q2)*/ + L_tmp = L_shl( L_tmp, q2 ); /*Q(27+q2)*/ } - ry = round_fx(L_shr(L_tmp, 1)); /*Q(10+q2)*/ + ry = round_fx( L_shr( L_tmp, 1 ) ); /*Q(10+q2)*/ - L_tmp = L_mult(px, px); - L_tmp = L_mac(L_tmp, py, py); /*Q(21+2*q1)*/ + L_tmp = L_mult( px, px ); + L_tmp = L_mac( L_tmp, py, py ); /*Q(21+2*q1)*/ #ifdef BASOP_NOGLOB - pp = round_fx_sat(Isqrt(L_shr(L_tmp, add(11, shl(q1, 1))))); /*Q10*/ + pp = round_fx_sat( Isqrt( L_shr( L_tmp, add( 11, shl( q1, 1 ) ) ) ) ); /*Q10*/ #else - pp = round_fx(Isqrt(L_shr(L_tmp, add(11, shl(q1, 1))))); /*Q10*/ + pp = round_fx( Isqrt( L_shr( L_tmp, add( 11, shl( q1, 1 ) ) ) ) ); /*Q10*/ #endif - L_tmp = L_mult(rx, rx); - L_tmp = L_mac(L_tmp, ry, ry); /*Q(21+2*q1)*/ + L_tmp = L_mult( rx, rx ); + L_tmp = L_mac( L_tmp, ry, ry ); /*Q(21+2*q1)*/ #ifdef BASOP_NOGLOB - rr = round_fx_sat(Isqrt(L_shr(L_tmp, add(11, shl(q2, 1))))); /*Q10*/ + rr = round_fx_sat( Isqrt( L_shr( L_tmp, add( 11, shl( q2, 1 ) ) ) ) ); /*Q10*/ #else - rr = round_fx(Isqrt(L_shr(L_tmp, add(11, shl(q2, 1))))); /*Q10*/ + rr = round_fx( Isqrt( L_shr( L_tmp, add( 11, shl( q2, 1 ) ) ) ) ); /*Q10*/ #endif - Copy(Aq, As, 3); - IF ( EQ_16(shr(As[2],1),-2048) ) + Copy( Aq, As, 3 ); + IF( EQ_16( shr( As[2], 1 ), -2048 ) ) { k2 = -2458; move16(); k1 = 4055; move16(); - if (As[1]<0) + if ( As[1] < 0 ) { k1 = -k1; move16(); @@ -1745,182 +1745,181 @@ static void envelope_fx( } ELSE { - k1 = add(2048, shr(As[2],1)); /*Q11 */ + k1 = add( 2048, shr( As[2], 1 ) ); /*Q11 */ q1 = 11; move16(); - q2 = norm_s(k1); - k1 = (shl(k1, q2)); /*q1+q2 */ - tmp = abs_s(k1); - q1 = add(q1, q2); - tmp = div_s(shl(1, 14), tmp); /*Q(29-q1) */ + q2 = norm_s( k1 ); + k1 = ( shl( k1, q2 ) ); /*q1+q2 */ + tmp = abs_s( k1 ); + q1 = add( q1, q2 ); + tmp = div_s( shl( 1, 14 ), tmp ); /*Q(29-q1) */ if ( k1 < 0 ) { - tmp = negate(tmp); + tmp = negate( tmp ); move16(); } - L_tmp = L_mult(As[1], tmp); /*Q(42-q1) */ - q1 = sub(q1, 14); + L_tmp = L_mult( As[1], tmp ); /*Q(42-q1) */ + q1 = sub( q1, 14 ); #ifdef BASOP_NOGLOB - k1 = round_fx_sat(L_shl_sat(L_tmp, q1)); /*Q12 */ + k1 = round_fx_sat( L_shl_sat( L_tmp, q1 ) ); /*Q12 */ #else - k1 = round_fx(L_shl(L_tmp, q1)); /*Q12 */ + k1 = round_fx( L_shl( L_tmp, q1 ) ); /*Q12 */ #endif k2 = As[2]; move16(); /*Q12 */ - if ( GT_16(k2, 2458)) + if ( GT_16( k2, 2458 ) ) { k2 = 2458; move16(); } - if ( LT_16(k2, -2458) ) + if ( LT_16( k2, -2458 ) ) { k2 = -2458; move16(); } - if ( GT_16(k1, 4055)) + if ( GT_16( k1, 4055 ) ) { k1 = 4055; move16(); } - if ( LT_16(k1, -4055) ) + if ( LT_16( k1, -4055 ) ) { k1 = -4055; move16(); } } - As[1] = add(4096, k2); + As[1] = add( 4096, k2 ); move16(); - L_tmp = L_mult(As[1], k1); /*Q25 */ - As[1] = round_fx(L_shl(L_tmp, 3)); /*Q12 */ + L_tmp = L_mult( As[1], k1 ); /*Q25 */ + As[1] = round_fx( L_shl( L_tmp, 3 ) ); /*Q12 */ As[2] = k2; move16(); /*Q12 */ - L_tmp = L_deposit_l(0); + L_tmp = L_deposit_l( 0 ); pt1 = As; pt2 = exp_tab_q_fx; - FOR ( i = 0; i < 3; i++ ) + FOR( i = 0; i < 3; i++ ) { - L_tmp = L_mac(L_tmp, *pt1++, *pt2++); + L_tmp = L_mac( L_tmp, *pt1++, *pt2++ ); } - q1 = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, q1);/*Q(27+q1)*/ - qx = round_fx(L_shr(L_tmp, 1)); /*Q(10+q1)*/ + q1 = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, q1 ); /*Q(27+q1)*/ + qx = round_fx( L_shr( L_tmp, 1 ) ); /*Q(10+q1)*/ - L_tmp = L_deposit_l(0); + L_tmp = L_deposit_l( 0 ); pt1 = As; - pt2 = exp_tab_q_fx+33; - FOR ( i = 0; i < 3; i++ ) + pt2 = exp_tab_q_fx + 33; + FOR( i = 0; i < 3; i++ ) { - L_tmp = L_mac(L_tmp, *pt1++, *pt2--); + L_tmp = L_mac( L_tmp, *pt1++, *pt2-- ); } - q2 = norm_l(L_tmp); - shift = sub(q1, q2); - IF ( shift >= 0 ) + q2 = norm_l( L_tmp ); + shift = sub( q1, q2 ); + IF( shift >= 0 ) { - qx = shr(qx, shift); - L_tmp = L_shl(L_tmp, q2);/*Q(27+q2)*/ + qx = shr( qx, shift ); + L_tmp = L_shl( L_tmp, q2 ); /*Q(27+q2)*/ q1 = q2; move16(); } ELSE { - L_tmp = L_shl(L_tmp, q1);/*Q(27+q1)*/ + L_tmp = L_shl( L_tmp, q1 ); /*Q(27+q1)*/ } - qy = round_fx(L_shr(L_tmp, 1)); /*Q(10+q1)*/ + qy = round_fx( L_shr( L_tmp, 1 ) ); /*Q(10+q1)*/ - L_tmp = L_mult(qx, qx); - L_tmp = L_mac(L_tmp, qy, qy); - qq = round_fx(Isqrt(L_shr(L_tmp, add(11, shl(q1, 1))))); /*Q10*/ + L_tmp = L_mult( qx, qx ); + L_tmp = L_mac( L_tmp, qy, qy ); + qq = round_fx( Isqrt( L_shr( L_tmp, add( 11, shl( q1, 1 ) ) ) ) ); /*Q10*/ Unvoicing_flag = EnhanceClass_fx( rr, pp, tilt0, tilt, voice_factor, &hAmrwb_IO->voice_fac_amr_wb_hf, &hAmrwb_IO->unvoicing_fx, &hAmrwb_IO->unvoicing_sm_fx, &hAmrwb_IO->unvoicing_flag_fx ); - alpha = 0; + alpha = 0; move16(); - IF ( Unvoicing_flag ) + IF( Unvoicing_flag ) { - IF ( GT_16(rr, (hAmrwb_IO->prev_r_fx))) + IF( GT_16( rr, ( hAmrwb_IO->prev_r_fx ) ) ) { #ifdef BASOP_NOGLOB - rr = shr(add_sat(rr, (hAmrwb_IO->prev_r_fx)), 1); + rr = shr( add_sat( rr, ( hAmrwb_IO->prev_r_fx ) ), 1 ); #else - rr = shr(add(rr, (hAmrwb_IO->prev_r_fx)), 1); + rr = shr( add( rr, ( hAmrwb_IO->prev_r_fx ) ), 1 ); #endif } hAmrwb_IO->prev_r_fx = rr; move16(); - L_tmp = L_mult(tilt, sub(26214, shr(voice_factor, 1))); /*Q28*/ + L_tmp = L_mult( tilt, sub( 26214, shr( voice_factor, 1 ) ) ); /*Q28*/ - L_tmp = L_min(L_tmp, 268435456); + L_tmp = L_min( L_tmp, 268435456 ); - L_tmp = Mult_32_16(L_tmp, rr); /*Q23*/ - rr = round_fx(L_shl(L_tmp, 3)); /*Q10*/ - L_tmp = L_mult(tilt, sub(26214, shr(voice_factor, 1))); /*Q28*/ - L_tmp = L_max(L_tmp, 268435456); - L_tmp = Mult_32_16(L_tmp, qq); /*Q23*/ + L_tmp = Mult_32_16( L_tmp, rr ); /*Q23*/ + rr = round_fx( L_shl( L_tmp, 3 ) ); /*Q10*/ + L_tmp = L_mult( tilt, sub( 26214, shr( voice_factor, 1 ) ) ); /*Q28*/ + L_tmp = L_max( L_tmp, 268435456 ); + L_tmp = Mult_32_16( L_tmp, qq ); /*Q23*/ #ifdef BASOP_NOGLOB - qq = round_fx_sat(L_shl_sat(L_tmp, 3)); /*Q10*/ + qq = round_fx_sat( L_shl_sat( L_tmp, 3 ) ); /*Q10*/ #else - qq = round_fx(L_shl(L_tmp, 3)); /*Q10*/ + qq = round_fx( L_shl( L_tmp, 3 ) ); /*Q10*/ #endif - rr = s_min(rr, qq); - rr= s_max(rr, pp); + rr = s_min( rr, qq ); + rr = s_max( rr, pp ); } ELSE { test(); - IF ( LT_16(rr, 1024)&<_16((hAmrwb_IO->prev_r_fx),1024)) + IF( LT_16( rr, 1024 ) && LT_16( ( hAmrwb_IO->prev_r_fx ), 1024 ) ) { - L_tmp = L_mult(rr, rr); /*Q21*/ - tmp = round_fx(L_shl(L_tmp, 9)); /*Q14*/ - L_tmp = L_sub(2097152, L_tmp); /*Q21*/ - alpha = round_fx(L_shl(L_tmp, 9)); /*Q14*/ - L_tmp = L_mult(alpha, (hAmrwb_IO->prev_r_fx)); /*Q25*/ - L_tmp = L_mac(L_tmp, tmp, rr); /*Q25*/ + L_tmp = L_mult( rr, rr ); /*Q21*/ + tmp = round_fx( L_shl( L_tmp, 9 ) ); /*Q14*/ + L_tmp = L_sub( 2097152, L_tmp ); /*Q21*/ + alpha = round_fx( L_shl( L_tmp, 9 ) ); /*Q14*/ + L_tmp = L_mult( alpha, ( hAmrwb_IO->prev_r_fx ) ); /*Q25*/ + L_tmp = L_mac( L_tmp, tmp, rr ); /*Q25*/ #ifdef BASOP_NOGLOB - rr = round_fx_sat(L_shl_sat(L_tmp, 1)); /*Q10*/ + rr = round_fx_sat( L_shl_sat( L_tmp, 1 ) ); /*Q10*/ #else - rr = round_fx(L_shl(L_tmp, 1)); /*Q10*/ + rr = round_fx( L_shl( L_tmp, 1 ) ); /*Q10*/ #endif } hAmrwb_IO->prev_r_fx = rr; move16(); - L_tmp = L_mult(tilt, sub(26214, shr(voice_factor, 1))); /*Q28*/ + L_tmp = L_mult( tilt, sub( 26214, shr( voice_factor, 1 ) ) ); /*Q28*/ - L_tmp = L_min(L_tmp, 268435456); - L_tmp = Mult_32_16(L_tmp, qq); /*Q23*/ - est_level1 = round_fx(L_shl(L_tmp, 3)); /*Q10*/ + L_tmp = L_min( L_tmp, 268435456 ); + L_tmp = Mult_32_16( L_tmp, qq ); /*Q23*/ + est_level1 = round_fx( L_shl( L_tmp, 3 ) ); /*Q10*/ tmp = pp; move16(); - tmp = s_min(tmp, qq); - rr = s_min(tmp, rr); + tmp = s_min( tmp, qq ); + rr = s_min( tmp, rr ); - L_tmp = L_mult(abs_s(sub(tilt, 8192)), sub(26214, shr(voice_factor, 1))); /*Q28*/ - L_tmp = L_add(L_tmp, 268435456); - L_tmp = Mult_32_16(L_tmp, rr); /*Q23*/ - est_level2 = round_fx(L_shl(L_tmp, 3)); /*Q10*/ + L_tmp = L_mult( abs_s( sub( tilt, 8192 ) ), sub( 26214, shr( voice_factor, 1 ) ) ); /*Q28*/ + L_tmp = L_add( L_tmp, 268435456 ); + L_tmp = Mult_32_16( L_tmp, rr ); /*Q23*/ + est_level2 = round_fx( L_shl( L_tmp, 3 ) ); /*Q10*/ - rr = s_min(est_level1, est_level2); + rr = s_min( est_level1, est_level2 ); } - q1 = norm_s(pp); - tmp = div_s(shl(1, sub(14, q1)), pp); /*Q(29-q1-10) */ - L_tmp = L_mult(rr, tmp);/*Q(30-q1-10+10) */ + q1 = norm_s( pp ); + tmp = div_s( shl( 1, sub( 14, q1 ) ), pp ); /*Q(29-q1-10) */ + L_tmp = L_mult( rr, tmp ); /*Q(30-q1-10+10) */ #ifdef BASOP_NOGLOB - *sub_gain = s_min(20480,round_fx_sat(L_shl_sat(L_tmp, sub(q1, 2)))); /*Q12 */ + *sub_gain = s_min( 20480, round_fx_sat( L_shl_sat( L_tmp, sub( q1, 2 ) ) ) ); /*Q12 */ #else - *sub_gain = s_min(20480,round_fx(L_shl(L_tmp, sub(q1, 2)))); /*Q12 */ + *sub_gain = s_min( 20480, round_fx( L_shl( L_tmp, sub( q1, 2 ) ) ) ); /*Q12 */ #endif return; - } /*---------------------------------------------------------------------* @@ -1930,14 +1929,14 @@ static void envelope_fx( *---------------------------------------------------------------------*/ void AdaptiveStartBand_fx( - Word16 *start_band, /* o : start point of copied band */ - const Word32 core_rate, /* i : core bitrate */ - const Word16 *lsf_fx, /* i : Q2 lsf frequency */ - const Word16 voicing_fac_fx, /* i : Q14 voicing factors */ - const Word16 clas, /* i : signal class (determined by FEC algorithm)*/ + Word16 *start_band, /* o : start point of copied band */ + const Word32 core_rate, /* i : core bitrate */ + const Word16 *lsf_fx, /* i : Q2 lsf frequency */ + const Word16 voicing_fac_fx, /* i : Q14 voicing factors */ + const Word16 clas, /* i : signal class (determined by FEC algorithm)*/ Word16 *voicing_flag, Word16 *start_band_old, - Word32 *OptCrit_old_fx /*i/o : Q15 */ + Word32 *OptCrit_old_fx /*i/o : Q15 */ ) { Word16 i, pos, M2, voicing_flag_old; @@ -1954,14 +1953,14 @@ void AdaptiveStartBand_fx( test(); test(); test(); - if( GT_16(voicing_fac_fx, 6554)||(GT_16(voicing_fac_fx,4915)&&GE_16(clas,VOICED_CLAS))||EQ_16(clas,AUDIO_CLAS)) + if ( GT_16( voicing_fac_fx, 6554 ) || ( GT_16( voicing_fac_fx, 4915 ) && GE_16( clas, VOICED_CLAS ) ) || EQ_16( clas, AUDIO_CLAS ) ) { *voicing_flag = 1; move16(); } test(); - if( LT_16(voicing_fac_fx, 3277)&<_16(clas,VOICED_CLAS)) + if ( LT_16( voicing_fac_fx, 3277 ) && LT_16( clas, VOICED_CLAS ) ) { *voicing_flag = 0; move16(); @@ -1970,86 +1969,86 @@ void AdaptiveStartBand_fx( /* core_rate adaptive start band */ *start_band = 160; move16(); - IF( LT_32(core_rate, ACELP_23k05)) + IF( LT_32( core_rate, ACELP_23k05 ) ) { - pt1 = lsf_diff_fx+1; - pt2 = lsf_fx+1; + pt1 = lsf_diff_fx + 1; + pt2 = lsf_fx + 1; pt3 = lsf_fx; - FOR(i=1; i<(M-1); i++) + FOR( i = 1; i < ( M - 1 ); i++ ) { - *pt1++ = sub(*pt2++, *pt3++); - move16();/*Q2 */ + *pt1++ = sub( *pt2++, *pt3++ ); + move16(); /*Q2 */ } - tmp1 = extract_l(Mult_32_16(core_rate, 27046)); /*Q14 */ - L_tmp = L_shr(L_mult0(tmp1, 22370), 15); /*Q27->1/6000 ->Q26 */ - tmp2 = extract_l(L_tmp); /*Q26 */ - W_fx = mult_r(tmp1, tmp2); /*Q25 */ + tmp1 = extract_l( Mult_32_16( core_rate, 27046 ) ); /*Q14 */ + L_tmp = L_shr( L_mult0( tmp1, 22370 ), 15 ); /*Q27->1/6000 ->Q26 */ + tmp2 = extract_l( L_tmp ); /*Q26 */ + W_fx = mult_r( tmp1, tmp2 ); /*Q25 */ - if (EQ_16(clas,AUDIO_CLAS)) + if ( EQ_16( clas, AUDIO_CLAS ) ) { - W_fx = mult_r(W_fx, 24576); /*Q25 */ + W_fx = mult_r( W_fx, 24576 ); /*Q25 */ } pos = 2; move16(); - M2 = sub(M, 2); - IF( EQ_16(*voicing_flag,1)) + M2 = sub( M, 2 ); + IF( EQ_16( *voicing_flag, 1 ) ) { - IF( LE_32(core_rate, ACELP_8k85)) + IF( LE_32( core_rate, ACELP_8k85 ) ) { - M2 = sub(M, 8); + M2 = sub( M, 8 ); } - ELSE IF( LE_32(core_rate, ACELP_12k65)) + ELSE IF( LE_32( core_rate, ACELP_12k65 ) ) { - M2 = sub(M, 6); + M2 = sub( M, 6 ); } - ELSE IF( LE_32(core_rate, ACELP_15k85)) + ELSE IF( LE_32( core_rate, ACELP_15k85 ) ) { - M2 = sub(M, 4); + M2 = sub( M, 4 ); } } /*do the procedure for i==2*/ - L_tmp = L_max(L_msu(171798692, lsf_fx[2], W_fx), 171799); /* Q2.56+25+1 */ - Crit_fx = Mult_32_16(L_tmp, lsf_diff_fx[2]); /* Q2.56+25+1+2.56-15 = Q11+2.56+2.56 */ + L_tmp = L_max( L_msu( 171798692, lsf_fx[2], W_fx ), 171799 ); /* Q2.56+25+1 */ + Crit_fx = Mult_32_16( L_tmp, lsf_diff_fx[2] ); /* Q2.56+25+1+2.56-15 = Q11+2.56+2.56 */ - OptCrit_fx = L_add(Crit_fx, 0); + OptCrit_fx = L_add( Crit_fx, 0 ); pos = 2; move16(); /*----------------------------------------------------------------*/ pt2 = &lsf_fx[3]; pt1 = &lsf_diff_fx[3]; - FOR(i=3; i 0 ) ) + IF( NE_16( voicing_flag_old, *voicing_flag ) || ( *voicing_flag == 0 && LT_32( OptCrit_fx, *OptCrit_old_fx ) ) || + ( LT_32( OptCrit_fx, L_tmp ) && GT_32( *OptCrit_old_fx, 858993 ) > 0 ) ) { *OptCrit_old_fx = OptCrit_fx; move16(); test(); test(); - if ( LT_16(abs_s(sub((*start_band),(*start_band_old))), 20)&&EQ_16(*voicing_flag,1)&&EQ_16(voicing_flag_old,1)) + if ( LT_16( abs_s( sub( ( *start_band ), ( *start_band_old ) ) ), 20 ) && EQ_16( *voicing_flag, 1 ) && EQ_16( voicing_flag_old, 1 ) ) { *start_band = *start_band_old; move16(); @@ -2058,7 +2057,7 @@ void AdaptiveStartBand_fx( ELSE { test(); - if (LT_32(OptCrit_fx, (*OptCrit_old_fx))&&EQ_16((*voicing_flag),1)) + if ( LT_32( OptCrit_fx, ( *OptCrit_old_fx ) ) && EQ_16( ( *voicing_flag ), 1 ) ) { *OptCrit_old_fx = OptCrit_fx; move16(); @@ -2068,16 +2067,16 @@ void AdaptiveStartBand_fx( move16(); } - if (EQ_16(clas,AUDIO_CLAS)) + if ( EQ_16( clas, AUDIO_CLAS ) ) { - *start_band = s_min(*start_band, 120); + *start_band = s_min( *start_band, 120 ); move16(); } - flag = sub(s_and(*start_band, 0x0001),1); - if (flag == 0) + flag = sub( s_and( *start_band, 0x0001 ), 1 ); + if ( flag == 0 ) { - *start_band = sub(*start_band, 1); + *start_band = sub( *start_band, 1 ); move16(); } } @@ -2087,4 +2086,3 @@ void AdaptiveStartBand_fx( return; } - diff --git a/lib_dec/hq_classifier_dec_fx.c b/lib_dec/hq_classifier_dec_fx.c index bf263e431..d8ce93970 100644 --- a/lib_dec/hq_classifier_dec_fx.c +++ b/lib_dec/hq_classifier_dec_fx.c @@ -2,9 +2,9 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" #endif @@ -86,12 +86,12 @@ Word16 ivas_hq_classifier_dec_fx( /* o : Consumed bits #endif #ifdef IVAS_FLOAT_FIXED -Word16 hq_classifier_dec_fx( /* o : Consumed bits Q0 */ - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : Core bit rate Q0 */ - const Word16 length, /* i : Frame length Q0 */ - Word16 *is_transient, /* o : Transient flag Q0 */ - Word16 *hqswb_clas /* o : HQ class Q0 */ +Word16 hq_classifier_dec_fx( /* o : Consumed bits Q0 */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word32 core_brate, /* i : Core bit rate Q0 */ + const Word16 length, /* i : Frame length Q0 */ + Word16 *is_transient, /* o : Transient flag Q0 */ + Word16 *hqswb_clas /* o : HQ class Q0 */ ) { Word16 bits; @@ -99,28 +99,29 @@ Word16 hq_classifier_dec_fx( /* o : Consumed bits Q0 */ max_brate = HQ_32k; move32(); - if (GT_16(st_fx->element_mode, EVS_MONO)) + if ( GT_16( st_fx->element_mode, EVS_MONO ) ) { max_brate = HQ_48k; move32(); } #ifndef SOLVED_COMP_ENC_DEC - IF((EQ_16(length, L_SPEC32k) || EQ_16(length, L_FRAME48k)) && LE_32(core_brate, max_brate)) + IF( ( EQ_16( length, L_SPEC32k ) || EQ_16( length, L_FRAME48k ) ) && LE_32( core_brate, max_brate ) ) #else /*_DIFF_FLOAT_FIX_ -> could this modification break the interoperability with EVS ?? */ test(); - IF ((EQ_16(length, L_SPEC32k) || EQ_16(length, L_SPEC48k)) && LE_32(core_brate, max_brate)) + IF( ( EQ_16( length, L_SPEC32k ) || EQ_16( length, L_SPEC48k ) ) && LE_32( core_brate, max_brate ) ) #endif { *hqswb_clas = get_next_indice( st_fx, 2 ); bits = 2; move16(); } - ELSE IF( EQ_16(length, L_SPEC16k_EXT) || EQ_16(length, L_SPEC48k_EXT) ) + ELSE IF( EQ_16( length, L_SPEC16k_EXT ) || EQ_16( length, L_SPEC48k_EXT ) ) { *hqswb_clas = HQ_NORMAL; bits = 0; - move16(); move16(); + move16(); + move16(); } ELSE { @@ -131,25 +132,25 @@ Word16 hq_classifier_dec_fx( /* o : Consumed bits Q0 */ *is_transient = 0; move16(); - if ( EQ_16(*hqswb_clas, HQ_TRANSIENT)) + if ( EQ_16( *hqswb_clas, HQ_TRANSIENT ) ) { *is_transient = 1; move16(); } test(); - IF (LE_32(st_fx->core_brate, HQ_32k) && EQ_16(*hqswb_clas, HQ_NORMAL)) + IF( LE_32( st_fx->core_brate, HQ_32k ) && EQ_16( *hqswb_clas, HQ_NORMAL ) ) { move16(); - IF (EQ_16(length, L_SPEC32k) ) + IF( EQ_16( length, L_SPEC32k ) ) { *hqswb_clas = HQ_GEN_SWB; move16(); } #ifndef SOLVED_COMP_ENC_DEC - ELSE IF (EQ_16(length, L_FRAME48k)) + ELSE IF( EQ_16( length, L_FRAME48k ) ) #else - ELSE IF (EQ_16(length, L_SPEC48k)) + ELSE IF( EQ_16( length, L_SPEC48k ) ) #endif { *hqswb_clas = HQ_GEN_FB; diff --git a/lib_dec/hq_conf_fec.c b/lib_dec/hq_conf_fec.c index fc1431311..0a21d82a6 100644 --- a/lib_dec/hq_conf_fec.c +++ b/lib_dec/hq_conf_fec.c @@ -66,4 +66,4 @@ void hq_configure_bfi( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/hq_conf_fec_fx.c b/lib_dec/hq_conf_fec_fx.c index 86bdfd6bc..dacd23a76 100644 --- a/lib_dec/hq_conf_fec_fx.c +++ b/lib_dec/hq_conf_fec_fx.c @@ -4,7 +4,7 @@ #include #include "options.h" -#include "rom_com.h" /* Static table prototypes */ +#include "rom_com.h" /* Static table prototypes */ #include "prot_fx1.h" #include "prot_fx2.h" #include "cnst.h" @@ -17,12 +17,12 @@ * Initialization of HQ bands and subframes *--------------------------------------------------------------------------*/ void hq_configure_bfi_fx( - Word16 *nb_sfm, /* o : Number of sub bands Q0 */ - Word16 *num_Sb, /* o : Number of FEC sub bands ? Q0 */ - Word16 *num_bands_p, /* o : FEC sub bands Q0 */ - const Word16 **sfmsize, /* o : Subband bandwidths */ - const Word16 **sfm_start, /* o : Subband start coefficients */ - const Word16 **sfm_end /* o : Subband end coefficients */ + Word16 *nb_sfm, /* o : Number of sub bands Q0 */ + Word16 *num_Sb, /* o : Number of FEC sub bands ? Q0 */ + Word16 *num_bands_p, /* o : FEC sub bands Q0 */ + const Word16 **sfmsize, /* o : Subband bandwidths */ + const Word16 **sfm_start, /* o : Subband start coefficients */ + const Word16 **sfm_end /* o : Subband end coefficients */ ) { *num_Sb = MAX_SB_NB; diff --git a/lib_dec/hq_core_dec.c b/lib_dec/hq_core_dec.c index a1f61cf3c..503b1396f 100644 --- a/lib_dec/hq_core_dec.c +++ b/lib_dec/hq_core_dec.c @@ -503,76 +503,76 @@ void hq_core_dec( *-------------------------------------------------------------------*/ #ifndef IVAS_FLOAT_FIXED void HQ_core_dec_init_flt( - HQ_DEC_HANDLE hHQ_core /* i/o: HQ core data handle */ + HQ_DEC_HANDLE hHQ_core /* i/o: HQ core data handle */ ) { - set_f(hHQ_core->old_out, 0, L_FRAME48k); - set_f(hHQ_core->old_outLB, 0, L_FRAME32k); - set_s(hHQ_core->old_is_transient, 0, 3); - - hHQ_core->oldHqVoicing = 0; - - set_f(hHQ_core->prev_noise_level, 0.0f, 2); - hHQ_core->prev_R = 0; - set_f(hHQ_core->prev_coeff_out, 0, L_HQ_WB_BWE); - set_s(hHQ_core->prev_SWB_peak_pos, 0, SPT_SHORTEN_SBNUM); - - /* HQ GENERIC */ - hHQ_core->hq_generic_seed = RANDOM_INITSEED; - - hHQ_core->mem_norm[0] = 31; - set_s(hHQ_core->mem_norm + 1, 39, SFM_N_ENV_STAB - 1); - hHQ_core->mem_env_delta = 0; - hHQ_core->no_att_hangover = 0; - hHQ_core->energy_lt = 300.0f; - - hHQ_core->HqVoicing = 0; - set_f(hHQ_core->fer_samples, 0, L_FRAME48k); - set_f(hHQ_core->prev_env, 0, SFM_N_WB); - set_f(hHQ_core->prev_normq, 0, SFM_N_WB); - hHQ_core->prev_hqswb_clas = HQ_NORMAL; - - set_f(hHQ_core->last_ni_gain, 0, BANDS_MAX); - set_f(hHQ_core->last_env, 0, BANDS_MAX); - hHQ_core->last_max_pos_pulse = 0; - hHQ_core->prev_frm_hfe2 = 0; - hHQ_core->prev_stab_hfe2 = 0; - hHQ_core->prev_ni_ratio = 0.5f; - set_f(hHQ_core->prev_En_sb, 0.0f, NB_SWB_SUBBANDS); - - - /*----------------------------------------------------------------------------------* - * HQ FEC - *----------------------------------------------------------------------------------*/ - - set_f(hHQ_core->X_sav, 0.0f, PH_ECU_SPEC_SIZE); - hHQ_core->num_p = 0; - hHQ_core->ph_ecu_active = 0; - hHQ_core->ni_seed_forfec = 0; - hHQ_core->last_fec = 0; - hHQ_core->ph_ecu_HqVoicing = 0; - set_f(hHQ_core->oldgapsynth, 0.0f, L_FRAME48k); - hHQ_core->env_stab = 0.75f; - hHQ_core->mem_norm_hqfec[0] = 31; - set_s(hHQ_core->mem_norm_hqfec + 1, 39, SFM_N_ENV_STAB - 1); - hHQ_core->mem_env_delta_hqfec = 0; - hHQ_core->env_stab_plc = 0.0f; - set_f(hHQ_core->env_stab_state_p, 1.0f / NUM_ENV_STAB_PLC_STATES, NUM_ENV_STAB_PLC_STATES); - hHQ_core->envstabplc_hocnt = 0; - - set_f(hHQ_core->mag_chg_1st, 1.0f, LGW_MAX); - set_f(hHQ_core->Xavg, 0.0f, LGW_MAX); - hHQ_core->beta_mute = BETA_MUTE_FAC_INI_FLT; - - hHQ_core->time_offs = 0; - hHQ_core->ber_occured_in_pvq = 0; - - hHQ_core->last_hq_core_type = -1; - - reset_preecho_dec(hHQ_core); - - return; + set_f( hHQ_core->old_out, 0, L_FRAME48k ); + set_f( hHQ_core->old_outLB, 0, L_FRAME32k ); + set_s( hHQ_core->old_is_transient, 0, 3 ); + + hHQ_core->oldHqVoicing = 0; + + set_f( hHQ_core->prev_noise_level, 0.0f, 2 ); + hHQ_core->prev_R = 0; + set_f( hHQ_core->prev_coeff_out, 0, L_HQ_WB_BWE ); + set_s( hHQ_core->prev_SWB_peak_pos, 0, SPT_SHORTEN_SBNUM ); + + /* HQ GENERIC */ + hHQ_core->hq_generic_seed = RANDOM_INITSEED; + + hHQ_core->mem_norm[0] = 31; + set_s( hHQ_core->mem_norm + 1, 39, SFM_N_ENV_STAB - 1 ); + hHQ_core->mem_env_delta = 0; + hHQ_core->no_att_hangover = 0; + hHQ_core->energy_lt = 300.0f; + + hHQ_core->HqVoicing = 0; + set_f( hHQ_core->fer_samples, 0, L_FRAME48k ); + set_f( hHQ_core->prev_env, 0, SFM_N_WB ); + set_f( hHQ_core->prev_normq, 0, SFM_N_WB ); + hHQ_core->prev_hqswb_clas = HQ_NORMAL; + + set_f( hHQ_core->last_ni_gain, 0, BANDS_MAX ); + set_f( hHQ_core->last_env, 0, BANDS_MAX ); + hHQ_core->last_max_pos_pulse = 0; + hHQ_core->prev_frm_hfe2 = 0; + hHQ_core->prev_stab_hfe2 = 0; + hHQ_core->prev_ni_ratio = 0.5f; + set_f( hHQ_core->prev_En_sb, 0.0f, NB_SWB_SUBBANDS ); + + + /*----------------------------------------------------------------------------------* + * HQ FEC + *----------------------------------------------------------------------------------*/ + + set_f( hHQ_core->X_sav, 0.0f, PH_ECU_SPEC_SIZE ); + hHQ_core->num_p = 0; + hHQ_core->ph_ecu_active = 0; + hHQ_core->ni_seed_forfec = 0; + hHQ_core->last_fec = 0; + hHQ_core->ph_ecu_HqVoicing = 0; + set_f( hHQ_core->oldgapsynth, 0.0f, L_FRAME48k ); + hHQ_core->env_stab = 0.75f; + hHQ_core->mem_norm_hqfec[0] = 31; + set_s( hHQ_core->mem_norm_hqfec + 1, 39, SFM_N_ENV_STAB - 1 ); + hHQ_core->mem_env_delta_hqfec = 0; + hHQ_core->env_stab_plc = 0.0f; + set_f( hHQ_core->env_stab_state_p, 1.0f / NUM_ENV_STAB_PLC_STATES, NUM_ENV_STAB_PLC_STATES ); + hHQ_core->envstabplc_hocnt = 0; + + set_f( hHQ_core->mag_chg_1st, 1.0f, LGW_MAX ); + set_f( hHQ_core->Xavg, 0.0f, LGW_MAX ); + hHQ_core->beta_mute = BETA_MUTE_FAC_INI_FLT; + + hHQ_core->time_offs = 0; + hHQ_core->ber_occured_in_pvq = 0; + + hHQ_core->last_hq_core_type = -1; + + reset_preecho_dec( hHQ_core ); + + return; } #endif diff --git a/lib_dec/hq_core_dec_fx.c b/lib_dec/hq_core_dec_fx.c index 9157a79b6..ee61b4b43 100644 --- a/lib_dec/hq_core_dec_fx.c +++ b/lib_dec/hq_core_dec_fx.c @@ -2,11 +2,11 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "rom_com.h" /* Static table prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "rom_com.h" /* Static table prototypes */ #ifdef IVAS_FLOAT_FIXED #include "prot.h" #include "ivas_prot_fx.h" @@ -19,25 +19,25 @@ *--------------------------------------------------------------------------*/ void hq_core_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure fx */ - Word16 synth[], /* o : output synthesis */ - Word16 *Q_synth, /* o : Q value of synth */ - const Word16 output_frame, /* i : output frame length */ - const Word16 hq_core_type, /* i : HQ core type */ - const Word16 core_switching_flag /* i : ACELP->HQ switching frame flag */ + Decoder_State *st_fx, /* i/o: decoder state structure fx */ + Word16 synth[], /* o : output synthesis */ + Word16 *Q_synth, /* o : Q value of synth */ + const Word16 output_frame, /* i : output frame length */ + const Word16 hq_core_type, /* i : HQ core type */ + const Word16 core_switching_flag /* i : ACELP->HQ switching frame flag */ ) { Word16 num_bits, is_transient, hqswb_clas, inner_frame; Word16 i, j, flag_uv, num_Sb, nb_sfm; Word16 ynrm[NB_SFM], num_bands_p[MAX_SB_NB]; - Word16 ener_match; /* Q13 */ - Word32 t_audio_q[L_FRAME48k_EXT]; /* Q12 */ + Word16 ener_match; /* Q13 */ + Word32 t_audio_q[L_FRAME48k_EXT]; /* Q12 */ Word16 Q_audio; - Word32 wtda_audio[2*L_FRAME48k]; + Word32 wtda_audio[2 * L_FRAME48k]; Word16 delay_comp; Word32 normq_fx[NB_SFM]; Word16 mean_en_high_fx; - Word16 SWB_fenv_fx[SWB_FENV+DIM_FB]; + Word16 SWB_fenv_fx[SWB_FENV + DIM_FB]; const Word16 *sfmsize, *sfm_start, *sfm_end; Word16 gapsynth_fx[L_FRAME48k]; Word16 tmp, tmp_loop; @@ -53,10 +53,10 @@ void hq_core_dec_fx( * Initializations *--------------------------------------------------------------------------*/ - set32_fx( t_audio_q, 0, L_FRAME48k_EXT); + set32_fx( t_audio_q, 0, L_FRAME48k_EXT ); set16_fx( gapsynth_fx, 0, L_FRAME48k ); set16_fx( num_bands_p, 0, MAX_SB_NB ); - set16_fx( ynrm, 39, NB_SFM ); /* Initialize to the smallest value */ + set16_fx( ynrm, 39, NB_SFM ); /* Initialize to the smallest value */ mean_en_high_fx = 0; move16(); Q_audio = 12; @@ -66,7 +66,7 @@ void hq_core_dec_fx( st_fx->hTcxCfg->tcx_last_overlap_mode = st_fx->hTcxCfg->tcx_curr_overlap_mode; move16(); - if (EQ_16(st_fx->hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP)) + if ( EQ_16( st_fx->hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) ) { st_fx->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; move16(); @@ -79,8 +79,8 @@ void hq_core_dec_fx( /* set the total bit-budget */ /*num_bits = (short)(st->total_brate / 50); */ - Mpy_32_16_ss(st_fx->total_brate, 5243, &L_tmp, &lsb); /* 5243 is 1/50 in Q18. (0+18-15=3) */ - num_bits = extract_l(L_shr(L_tmp, 3)); /*Q0 */ + Mpy_32_16_ss( st_fx->total_brate, 5243, &L_tmp, &lsb ); /* 5243 is 1/50 in Q18. (0+18-15=3) */ + num_bits = extract_l( L_shr( L_tmp, 3 ) ); /*Q0 */ #ifdef ADD_IVAS_HQ_CODE_L_SPEC /* Set default spectrum length */ @@ -88,50 +88,50 @@ void hq_core_dec_fx( #endif IF( !st_fx->bfi ) { - IF ( EQ_16(core_switching_flag, 1)) + IF( EQ_16( core_switching_flag, 1 ) ) { #ifdef ADD_IVAS_HQ_CODE_L_SPEC - IF (NE_16(st_fx->element_mode, EVS_MONO)) + IF( NE_16( st_fx->element_mode, EVS_MONO ) ) { L_spec = l_spec_ext_tbl[st_fx->bwidth]; } ELSE #endif { - core_switching_hq_prepare_dec_fx(st_fx, &num_bits, output_frame); + core_switching_hq_prepare_dec_fx( st_fx, &num_bits, output_frame ); /* During ACELP->HQ core switching, limit the HQ core bitrate to 48kbps */ - if (GT_16(num_bits, HQ_48k / 50)) + if ( GT_16( num_bits, HQ_48k / 50 ) ) { - num_bits = (Word16)(HQ_48k / 50); + num_bits = (Word16) ( HQ_48k / 50 ); move16(); } } } #ifdef ADD_IVAS_HQ_CODE - IF (hq_recovery_flag) + IF( hq_recovery_flag ) { - acelp_plc_mdct_transition(st); + acelp_plc_mdct_transition( st ); } #endif /* subtract signalling bits */ - num_bits = sub(num_bits, st_fx->next_bit_pos); + num_bits = sub( num_bits, st_fx->next_bit_pos ); /* set FEC parameters */ - flag_uv = sub(1, hHQ_core->HqVoicing); + flag_uv = sub( 1, hHQ_core->HqVoicing ); /* subtract the number of bits for pitch & gain at higher bitrates */ test(); - IF ( !(core_switching_flag) && GT_32(st_fx->core_brate, MINIMUM_RATE_TO_ENCODE_VOICING_FLAG)) + IF( !( core_switching_flag ) && GT_32( st_fx->core_brate, MINIMUM_RATE_TO_ENCODE_VOICING_FLAG ) ) { hHQ_core->HqVoicing = get_next_indice( st_fx, 1 ); - num_bits = sub(num_bits, 1); + num_bits = sub( num_bits, 1 ); } ELSE { hHQ_core->HqVoicing = 0; move16(); - if ( GT_32(st_fx->core_brate, MINIMUM_RATE_TO_ENCODE_VOICING_FLAG)) + if ( GT_32( st_fx->core_brate, MINIMUM_RATE_TO_ENCODE_VOICING_FLAG ) ) { hHQ_core->HqVoicing = 1; move16(); @@ -151,18 +151,18 @@ void hq_core_dec_fx( #endif move16(); - IF ( st_fx->bfi == 0) + IF( st_fx->bfi == 0 ) { hHQ_core->ph_ecu_HqVoicing = 0; move16(); - if ( GE_16(output_frame, L_FRAME16k)) + if ( GE_16( output_frame, L_FRAME16k ) ) { hHQ_core->ph_ecu_HqVoicing = hHQ_core->HqVoicing; move16(); } } - IF ( EQ_16(output_frame, L_FRAME8k)) + IF( EQ_16( output_frame, L_FRAME8k ) ) { hq_configure_bfi_fx( &nb_sfm, &num_Sb, num_bands_p, &sfmsize, &sfm_start, &sfm_end ); } @@ -171,11 +171,11 @@ void hq_core_dec_fx( * transform-domain decoding *--------------------------------------------------------------------------*/ - IF( EQ_16(st_fx->bfi, 1)) + IF( EQ_16( st_fx->bfi, 1 ) ) { is_transient = hHQ_core->old_is_transient[0]; move16(); - IF ( GE_16(output_frame, L_FRAME16k)) /* Apply phase ecu for WB, SWB and FB */ + IF( GE_16( output_frame, L_FRAME16k ) ) /* Apply phase ecu for WB, SWB and FB */ { /* ecu_rec sent to OLA, env_stab passed in ph_ecu_st */ hq_ecu_fx( st_fx->hTcxDec->prev_good_synth_fx, t_audio_q, &hHQ_core->time_offs, hHQ_core->X_sav_fx, &hHQ_core->Q_X_sav, &hHQ_core->num_p, hHQ_core->plocs, hHQ_core->plocsi_fx, hHQ_core->env_stab_fx, @@ -185,7 +185,7 @@ void hq_core_dec_fx( ELSE { HQ_FEC_processing_fx( st_fx, t_audio_q, is_transient, hHQ_nbfec->ynrm_values_fx, hHQ_nbfec->r_p_values_fx, num_Sb, nb_sfm, num_bands_p, - output_frame, sfm_start, sfm_end ); + output_frame, sfm_start, sfm_end ); } hHQ_core->old_is_transient[2] = hHQ_core->old_is_transient[1]; @@ -193,34 +193,34 @@ void hq_core_dec_fx( hHQ_core->old_is_transient[1] = hHQ_core->old_is_transient[0]; move16(); - IF ( GE_16(output_frame, L_FRAME16k)) + IF( GE_16( output_frame, L_FRAME16k ) ) { /* keep st->previoussynth updated as in FEC_HQ_pitch_analysis but no LP analysis */ - delay_comp = NS2SA_fx2(st_fx->output_Fs, DELAY_CLDFB_NS); + delay_comp = NS2SA_fx2( st_fx->output_Fs, DELAY_CLDFB_NS ); - Copy( st_fx->previoussynth_fx + delay_comp, st_fx->previoussynth_fx, sub(output_frame, delay_comp) ); + Copy( st_fx->previoussynth_fx + delay_comp, st_fx->previoussynth_fx, sub( output_frame, delay_comp ) ); Copy( st_fx->delay_buf_out_fx, st_fx->previoussynth_fx + output_frame - delay_comp, delay_comp ); flag_uv = 1; - move16(); /* disable costly pitch out synthesis in bfi frame */ - hHQ_core->HqVoicing = sub(1, flag_uv); /* safety setting for HQ->ACELP switch logic */ - set16_fx(hHQ_core->fer_samples_fx, 0, L_FRAME48k ); /* safety, create a known signal state for HQ->ACELP switch logic */ + move16(); /* disable costly pitch out synthesis in bfi frame */ + hHQ_core->HqVoicing = sub( 1, flag_uv ); /* safety setting for HQ->ACELP switch logic */ + set16_fx( hHQ_core->fer_samples_fx, 0, L_FRAME48k ); /* safety, create a known signal state for HQ->ACELP switch logic */ } } ELSE { - IF( EQ_16(hq_core_type, LOW_RATE_HQ_CORE)) + IF( EQ_16( hq_core_type, LOW_RATE_HQ_CORE ) ) { - IF( EQ_16(st_fx->prev_bfi, 1)) + IF( EQ_16( st_fx->prev_bfi, 1 ) ) { - set32_fx(hHQ_core->last_ni_gain_fx, 0, BANDS_MAX ); - set16_fx(hHQ_core->last_env_fx, 0, BANDS_MAX ); + set32_fx( hHQ_core->last_ni_gain_fx, 0, BANDS_MAX ); + set16_fx( hHQ_core->last_env_fx, 0, BANDS_MAX ); hHQ_core->last_max_pos_pulse = 0; move16(); } /* HQ low rate decoder */ - hq_lr_dec_fx(st_fx, t_audio_q, inner_frame, num_bits, &is_transient); + hq_lr_dec_fx( st_fx, t_audio_q, inner_frame, num_bits, &is_transient ); hqswb_clas = is_transient; move16(); Q_audio = 12; @@ -229,37 +229,39 @@ void hq_core_dec_fx( ELSE { /* HQ high rate decoder */ - hq_hr_dec_fx(st_fx, t_audio_q, L_spec, num_bits, ynrm, &is_transient, &hqswb_clas, SWB_fenv_fx, core_switching_flag); + hq_hr_dec_fx( st_fx, t_audio_q, L_spec, num_bits, ynrm, &is_transient, &hqswb_clas, SWB_fenv_fx, core_switching_flag ); Q_audio = 12; move16(); } #ifdef ADD_IVAS_HQ_CODE - test(); test(); test(); - IF (EQ_16(st_fx->element_mode, EVS_MONO) || (!core_switching_flag && !hq_recovery_flag)) + test(); + test(); + test(); + IF( EQ_16( st_fx->element_mode, EVS_MONO ) || ( !core_switching_flag && !hq_recovery_flag ) ) #endif { /* scaling (coefficients are in nominal level) */ - IF(NE_16(output_frame, NORM_MDCT_FACTOR)) + IF( NE_16( output_frame, NORM_MDCT_FACTOR ) ) { - IF(EQ_16(output_frame, L_FRAME32k)) + IF( EQ_16( output_frame, L_FRAME32k ) ) { - Q_audio = sub(Q_audio, 1); /* Multiply by 2 */ + Q_audio = sub( Q_audio, 1 ); /* Multiply by 2 */ } ELSE { - tmp = mult_r(output_frame, 410 / 2); /* 1/8000 in Q15 */ + tmp = mult_r( output_frame, 410 / 2 ); /* 1/8000 in Q15 */ ener_match = hq_nominal_scaling_inv[tmp]; - FOR(i = 0; i < inner_frame; i++) + FOR( i = 0; i < inner_frame; i++ ) { /*t_audio_q[i] *= ener_match;*/ - Mpy_32_16_ss(t_audio_q[i], ener_match, &L_tmp, &lsb); /*12+13-15=10 */ + Mpy_32_16_ss( t_audio_q[i], ener_match, &L_tmp, &lsb ); /*12+13-15=10 */ #ifdef BASOP_NOGLOB - t_audio_q[i] = L_add_sat(L_shl_sat(L_tmp, 2), lshr(lsb, 14)); + t_audio_q[i] = L_add_sat( L_shl_sat( L_tmp, 2 ), lshr( lsb, 14 ) ); #else - t_audio_q[i] = L_add(L_shl(L_tmp, 2), lshr(lsb, 14)); + t_audio_q[i] = L_add( L_shl( L_tmp, 2 ), lshr( lsb, 14 ) ); #endif - move16(); /* Q12 */ + move16(); /* Q12 */ } } } @@ -273,48 +275,49 @@ void hq_core_dec_fx( /* attenuate HFs in case of band-width switching */ IF( st_fx->bws_cnt1 > 0 ) { - IF( EQ_16(st_fx->bws_cnt1,N_NS2W_FRAMES)) + IF( EQ_16( st_fx->bws_cnt1, N_NS2W_FRAMES ) ) { ener_match = 32767; move16(); /*Q15*/ } ELSE { - ener_match = div_s(st_fx->bws_cnt1,N_NS2W_FRAMES); /*Q15*/ + ener_match = div_s( st_fx->bws_cnt1, N_NS2W_FRAMES ); /*Q15*/ } IF( is_transient ) { FOR( i = 0; i < NUM_TIME_SWITCHING_BLOCKS; i++ ) { - tmp_loop = mult(inner_frame,8192); - FOR( j=mult(inner_frame_tbl[sub(st_fx->bwidth,1)],8192); jbwidth, 1 )], 8192 ); j < tmp_loop; j++ ) { - tmp = i_mult(i,inner_frame); /*Q0*/ - tmp = mult(tmp,8192); /*Q0*/ - tmp = add(tmp,j); - t_audio_q[tmp] = Mult_32_16(t_audio_q[tmp],ener_match); + tmp = i_mult( i, inner_frame ); /*Q0*/ + tmp = mult( tmp, 8192 ); /*Q0*/ + tmp = add( tmp, j ); + t_audio_q[tmp] = Mult_32_16( t_audio_q[tmp], ener_match ); move32(); /*Q12*/ } } } ELSE { - FOR( i=inner_frame_tbl[sub(st_fx->bwidth,1)]; ibwidth, 1 )]; i < inner_frame; i++ ) { - t_audio_q[i] = Mult_32_16(t_audio_q[i],ener_match); /*Q12*/ move32(); + t_audio_q[i] = Mult_32_16( t_audio_q[i], ener_match ); /*Q12*/ + move32(); } } } /* WB/SWB bandwidth switching */ - IF(is_transient) + IF( is_transient ) { - Copy_Scale_sig_32_16(&t_audio_q[240], st_fx->t_audio_q_fx, 80, -13); + Copy_Scale_sig_32_16( &t_audio_q[240], st_fx->t_audio_q_fx, 80, -13 ); } ELSE { - Copy_Scale_sig_32_16(t_audio_q, st_fx->t_audio_q_fx, L_FRAME, -13); + Copy_Scale_sig_32_16( t_audio_q, st_fx->t_audio_q_fx, L_FRAME, -13 ); } @@ -324,20 +327,20 @@ void hq_core_dec_fx( * Pre-echo reduction *--------------------------------------------------------------------------*/ #ifdef ADD_IVAS_HQ_CODE - if (st->element_mode > EVS_MONO && (core_switching_flag || hq_recovery_flag)) + if ( st->element_mode > EVS_MONO && ( core_switching_flag || hq_recovery_flag ) ) { /* Initializations for TCX MDCT framework, to be used for switching frame */ tcx_cfg = st->hTcxCfg; L_frameTCX_glob = hTcxDec->L_frameTCX; L_frame_glob = st->L_frame; L_spec = hTcxDec->L_frameTCX; - st->fscale = sr2fscale(st->sr_core); - fscaleFB = sr2fscale(st->output_Fs); - encoderLookahead = (L_LOOK_12k8 * st->fscale) / FSCALE_DENOM; - encoderLookaheadFB = (L_LOOK_12k8 * fscaleFB) / FSCALE_DENOM; - mdctWindowLength = getMdctWindowLength(st->fscale); - mdctWindowLengthFB = (int16_t)(mdctWindowLength * st->output_Fs / st->sr_core); - if (core_switching_flag) + st->fscale = sr2fscale( st->sr_core ); + fscaleFB = sr2fscale( st->output_Fs ); + encoderLookahead = ( L_LOOK_12k8 * st->fscale ) / FSCALE_DENOM; + encoderLookaheadFB = ( L_LOOK_12k8 * fscaleFB ) / FSCALE_DENOM; + mdctWindowLength = getMdctWindowLength( st->fscale ); + mdctWindowLengthFB = (int16_t) ( mdctWindowLength * st->output_Fs / st->sr_core ); + if ( core_switching_flag ) { tcx_cfg->tcx_last_overlap_mode = TRANSITION_OVERLAP; tcx_cfg->tcx_curr_overlap_mode = FULL_OVERLAP; @@ -349,27 +352,27 @@ void hq_core_dec_fx( st->last_core = HQ_CORE; /* Needed to decode non-transition frame */ } - init_tcx_window_cfg(tcx_cfg, st->sr_core, st->output_Fs, st->L_frame, hTcxDec->L_frameTCX, encoderLookahead, encoderLookaheadFB, mdctWindowLength, mdctWindowLengthFB, st->element_mode); + init_tcx_window_cfg( tcx_cfg, st->sr_core, st->output_Fs, st->L_frame, hTcxDec->L_frameTCX, encoderLookahead, encoderLookaheadFB, mdctWindowLength, mdctWindowLengthFB, st->element_mode ); - init_tcx_info(st, L_frame_glob, L_frameTCX_glob, 0, st->bfi, &tcx_offset, &tcx_offsetFB, &L_frame, &L_frameTCX, &left_rect, &L_spec); + init_tcx_info( st, L_frame_glob, L_frameTCX_glob, 0, st->bfi, &tcx_offset, &tcx_offsetFB, &L_frame, &L_frameTCX, &left_rect, &L_spec ); overlap = tcx_cfg->tcx_mdct_window_length; overlapFB = tcx_cfg->tcx_mdct_window_lengthFB; index = tcx_cfg->tcx_last_overlap_mode; /* LB synthesis */ - IMDCT_fx(t_audio_q, hTcxDec->syn_Overl, hTcxDec->syn_Overl_TDAC, wtda_audio, tcx_cfg->tcx_aldo_window_1_trunc, tcx_cfg->tcx_aldo_window_2, tcx_cfg->tcx_mdct_window_half, tcx_cfg->tcx_mdct_window_minimum, tcx_cfg->tcx_mdct_window_trans, tcx_cfg->tcx_mdct_window_half_length, tcx_cfg->tcx_mdct_window_min_length, index, - MDCT_IV, left_rect, tcx_offset, overlap, L_frame, L_frameTCX, max(L_frameTCX, L_spec) >> 1, L_frame_glob, 0, st->bfi, hHQ_core->old_outLB, 0, st, 0, acelp_zir); + IMDCT_fx( t_audio_q, hTcxDec->syn_Overl, hTcxDec->syn_Overl_TDAC, wtda_audio, tcx_cfg->tcx_aldo_window_1_trunc, tcx_cfg->tcx_aldo_window_2, tcx_cfg->tcx_mdct_window_half, tcx_cfg->tcx_mdct_window_minimum, tcx_cfg->tcx_mdct_window_trans, tcx_cfg->tcx_mdct_window_half_length, tcx_cfg->tcx_mdct_window_min_length, index, + MDCT_IV, left_rect, tcx_offset, overlap, L_frame, L_frameTCX, max( L_frameTCX, L_spec ) >> 1, L_frame_glob, 0, st->bfi, hHQ_core->old_outLB, 0, st, 0, acelp_zir ); - mvr2r(wtda_audio + (overlap >> 1) - tcx_offset, output, L_frame_glob); + mvr2r( wtda_audio + ( overlap >> 1 ) - tcx_offset, output, L_frame_glob ); /* FB synthesis */ - IMDCT_fx(t_audio_q, hTcxDec->syn_OverlFB, hTcxDec->syn_Overl_TDACFB, wtda_audio, tcx_cfg->tcx_aldo_window_1_FB_trunc, tcx_cfg->tcx_aldo_window_2_FB, tcx_cfg->tcx_mdct_window_halfFB, tcx_cfg->tcx_mdct_window_minimumFB, tcx_cfg->tcx_mdct_window_transFB, tcx_cfg->tcx_mdct_window_half_lengthFB, tcx_cfg->tcx_mdct_window_min_lengthFB, index, - MDCT_IV, left_rect, tcx_offsetFB, overlapFB, L_frameTCX, L_frameTCX, max(L_frameTCX, L_spec) >> 1, L_frameTCX_glob, 0, st->bfi, hHQ_core->old_out, 1, st, FSCALE_DENOM * L_frameTCX_glob / L_frame_glob, acelp_zir); + IMDCT_fx( t_audio_q, hTcxDec->syn_OverlFB, hTcxDec->syn_Overl_TDACFB, wtda_audio, tcx_cfg->tcx_aldo_window_1_FB_trunc, tcx_cfg->tcx_aldo_window_2_FB, tcx_cfg->tcx_mdct_window_halfFB, tcx_cfg->tcx_mdct_window_minimumFB, tcx_cfg->tcx_mdct_window_transFB, tcx_cfg->tcx_mdct_window_half_lengthFB, tcx_cfg->tcx_mdct_window_min_lengthFB, index, + MDCT_IV, left_rect, tcx_offsetFB, overlapFB, L_frameTCX, L_frameTCX, max( L_frameTCX, L_spec ) >> 1, L_frameTCX_glob, 0, st->bfi, hHQ_core->old_out, 1, st, FSCALE_DENOM * L_frameTCX_glob / L_frame_glob, acelp_zir ); - mvr2r(wtda_audio + (overlapFB >> 1) - tcx_offsetFB, synth, L_frameTCX_glob); + mvr2r( wtda_audio + ( overlapFB >> 1 ) - tcx_offsetFB, synth, L_frameTCX_glob ); - if (!core_switching_flag) + if ( !core_switching_flag ) { st->last_core = ACELP_CORE; /* Restore last core */ } @@ -378,70 +381,70 @@ void hq_core_dec_fx( #endif { test(); - IF(EQ_16(output_frame, L_FRAME8k) || st_fx->bfi == 0) + IF( EQ_16( output_frame, L_FRAME8k ) || st_fx->bfi == 0 ) { test(); - IF(NE_16(inner_frame, output_frame) && EQ_16(st_fx->bfi, 1)) + IF( NE_16( inner_frame, output_frame ) && EQ_16( st_fx->bfi, 1 ) ) { - Inverse_Transform(t_audio_q, &Q_audio, wtda_audio, is_transient, output_frame, output_frame, st_fx->element_mode); + Inverse_Transform( t_audio_q, &Q_audio, wtda_audio, is_transient, output_frame, output_frame, st_fx->element_mode ); } ELSE { - Inverse_Transform(t_audio_q, &Q_audio, wtda_audio, is_transient, output_frame, inner_frame, st_fx->element_mode); + Inverse_Transform( t_audio_q, &Q_audio, wtda_audio, is_transient, output_frame, inner_frame, st_fx->element_mode ); } *Q_synth = Q_audio; move16(); } } #ifdef ADD_IVAS_HQ_CODE - if (st->element_mode > EVS_MONO) + if ( st->element_mode > EVS_MONO ) { - if (st->bfi) + if ( st->bfi ) { /* Rough resampling, but reduces energy loss in case of switch to ACELP in first good frame */ - lerp(t_audio_q, wtda_audio_LB, st->L_frame, inner_frame); - v_multc(t_audio_q, 0.5f, wtda_audio_LB, st->L_frame); + lerp( t_audio_q, wtda_audio_LB, st->L_frame, inner_frame ); + v_multc( t_audio_q, 0.5f, wtda_audio_LB, st->L_frame ); } else { /* LB synthesis for potential switch to ACELP */ - ener_match = (float)sqrt((float)st->L_frame / (float)output_frame); - v_multc(t_audio_q, ener_match, t_audio_q, inner_frame); - inverse_transform(t_audio_q, wtda_audio_LB, is_transient, st->L_frame, inner_frame, st->element_mode); + ener_match = (float) sqrt( (float) st->L_frame / (float) output_frame ); + v_multc( t_audio_q, ener_match, t_audio_q, inner_frame ); + inverse_transform( t_audio_q, wtda_audio_LB, is_transient, st->L_frame, inner_frame, st->element_mode ); } } #endif - IF ( EQ_16(output_frame, L_FRAME8k)) + IF( EQ_16( output_frame, L_FRAME8k ) ) { test(); - IF( st_fx->bfi == 0 && st_fx->prev_bfi == 0) + IF( st_fx->bfi == 0 && st_fx->prev_bfi == 0 ) { - Copy_Scale_sig(hHQ_core->old_out_fx+N_ZERO_NB, hHQ_nbfec->prev_oldauOut_fx, output_frame-N_ZERO_NB, negate(hHQ_core->Q_old_wtda) ); + Copy_Scale_sig( hHQ_core->old_out_fx + N_ZERO_NB, hHQ_nbfec->prev_oldauOut_fx, output_frame - N_ZERO_NB, negate( hHQ_core->Q_old_wtda ) ); } - ELSE IF( EQ_16(st_fx->prev_bfi, 1)) + ELSE IF( EQ_16( st_fx->prev_bfi, 1 ) ) { - set16_fx(hHQ_nbfec->prev_oldauOut_fx, 0, output_frame ); + set16_fx( hHQ_nbfec->prev_oldauOut_fx, 0, output_frame ); } test(); test(); test(); test(); - IF( (EQ_16(st_fx->prev_bfi, 1)||EQ_16(st_fx->bfi,1))&& hHQ_core->old_is_transient[2]==0&&EQ_16(st_fx->last_core,HQ_CORE)&&EQ_16(st_fx->last_codec_mode,MODE1)) + IF( ( EQ_16( st_fx->prev_bfi, 1 ) || EQ_16( st_fx->bfi, 1 ) ) && hHQ_core->old_is_transient[2] == 0 && EQ_16( st_fx->last_core, HQ_CORE ) && EQ_16( st_fx->last_codec_mode, MODE1 ) ) { time_domain_FEC_HQ_fx( st_fx, wtda_audio, synth, mean_en_high_fx, output_frame, Q_synth ); } ELSE { window_ola_fx( wtda_audio, synth, Q_synth, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, output_frame, - st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, st_fx->prev_bfi, hHQ_core->oldHqVoicing , hHQ_core->oldgapsynth_fx ); - hHQ_nbfec->phase_mat_next = 0; + st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, st_fx->prev_bfi, hHQ_core->oldHqVoicing, hHQ_core->oldgapsynth_fx ); + hHQ_nbfec->phase_mat_next = 0; move16(); } test(); test(); - IF ( (st_fx->bfi == 0 && st_fx->prev_bfi == 0) || !(GE_16(output_frame, L_FRAME16k))) + IF( ( st_fx->bfi == 0 && st_fx->prev_bfi == 0 ) || !( GE_16( output_frame, L_FRAME16k ) ) ) { preecho_sb_fx( st_fx->core_brate, wtda_audio, Q_audio, synth, *Q_synth, output_frame, &hHQ_core->memfilt_lb_fx, &hHQ_core->mean_prev_hb_fx, &hHQ_core->smoothmem_fx, &hHQ_core->mean_prev_fx, &hHQ_core->mean_prev_nc_fx, &hHQ_core->wmold_hb_fx, &hHQ_core->prevflag, &hHQ_core->pastpre, st_fx->bwidth ); @@ -450,13 +453,13 @@ void hq_core_dec_fx( ELSE { test(); - IF (EQ_16(st_fx->bfi, 1)&&GE_16(output_frame,L_FRAME16k)) + IF( EQ_16( st_fx->bfi, 1 ) && GE_16( output_frame, L_FRAME16k ) ) { /* PHASE_ECU active */ Q_audio = 15; move16(); window_ola_fx( t_audio_q, synth, &Q_audio, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, output_frame, - ALDO_WINDOW, ALDO_WINDOW, st_fx->prev_bfi && !hHQ_core->ph_ecu_active, hHQ_core->oldHqVoicing, hHQ_core->oldgapsynth_fx ); + ALDO_WINDOW, ALDO_WINDOW, st_fx->prev_bfi && !hHQ_core->ph_ecu_active, hHQ_core->oldHqVoicing, hHQ_core->oldgapsynth_fx ); *Q_synth = Q_audio; move16(); } @@ -464,22 +467,22 @@ void hq_core_dec_fx( { /* no BFI or baseline PLC active */ window_ola_fx( wtda_audio, synth, Q_synth, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, output_frame, - st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, st_fx->prev_bfi && !hHQ_core->ph_ecu_active, hHQ_core->oldHqVoicing, hHQ_core->oldgapsynth_fx); + st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, st_fx->prev_bfi && !hHQ_core->ph_ecu_active, hHQ_core->oldHqVoicing, hHQ_core->oldgapsynth_fx ); } #ifdef ADD_IVAS_HQ_CODE - if (st->element_mode > EVS_MONO) + if ( st->element_mode > EVS_MONO ) { /* LB synthesis for potential switch to ACELP */ - window_ola(wtda_audio_LB, output, hHQ_core->old_outLB, L_FRAME16k, st->hTcxCfg->tcx_last_overlap_mode, st->hTcxCfg->tcx_curr_overlap_mode, st->prev_bfi && !hHQ_core->ph_ecu_active, hHQ_core->oldHqVoicing, hHQ_core->oldgapsynth); + window_ola( wtda_audio_LB, output, hHQ_core->old_outLB, L_FRAME16k, st->hTcxCfg->tcx_last_overlap_mode, st->hTcxCfg->tcx_curr_overlap_mode, st->prev_bfi && !hHQ_core->ph_ecu_active, hHQ_core->oldHqVoicing, hHQ_core->oldgapsynth ); } #endif test(); test(); - IF ( (st_fx->bfi == 0 && st_fx->prev_bfi == 0) || !(GE_16(output_frame, L_FRAME16k))) + IF( ( st_fx->bfi == 0 && st_fx->prev_bfi == 0 ) || !( GE_16( output_frame, L_FRAME16k ) ) ) { - preecho_sb_fx( st_fx->core_brate, wtda_audio, Q_audio, synth,*Q_synth, output_frame, &hHQ_core->memfilt_lb_fx, - &hHQ_core->mean_prev_hb_fx, &hHQ_core->smoothmem_fx, &hHQ_core->mean_prev_fx, &hHQ_core->mean_prev_nc_fx, - &hHQ_core->wmold_hb_fx, &hHQ_core->prevflag, &hHQ_core->pastpre, st_fx->bwidth ); + preecho_sb_fx( st_fx->core_brate, wtda_audio, Q_audio, synth, *Q_synth, output_frame, &hHQ_core->memfilt_lb_fx, + &hHQ_core->mean_prev_hb_fx, &hHQ_core->smoothmem_fx, &hHQ_core->mean_prev_fx, &hHQ_core->mean_prev_nc_fx, + &hHQ_core->wmold_hb_fx, &hHQ_core->prevflag, &hHQ_core->pastpre, st_fx->bwidth ); } } @@ -491,37 +494,31 @@ void hq_core_dec_fx( test(); test(); test(); - IF (!st_fx->bfi - && st_fx->prev_bfi - && GE_32(st_fx->last_total_brate, HQ_48k) - && EQ_16(st_fx->last_codec_mode, MODE2) - && (EQ_16(st_fx->last_core_bfi, TCX_20_CORE) || EQ_16(st_fx->last_core_bfi, TCX_10_CORE) ) - && st_fx->plcInfo.concealment_method == TCX_NONTONAL - && LT_32(st_fx->plcInfo.nbLostCmpt, 4) ) + IF( !st_fx->bfi && st_fx->prev_bfi && GE_32( st_fx->last_total_brate, HQ_48k ) && EQ_16( st_fx->last_codec_mode, MODE2 ) && ( EQ_16( st_fx->last_core_bfi, TCX_20_CORE ) || EQ_16( st_fx->last_core_bfi, TCX_10_CORE ) ) && st_fx->plcInfo.concealment_method == TCX_NONTONAL && LT_32( st_fx->plcInfo.nbLostCmpt, 4 ) ) { #ifdef BASOP_NOGLOB - st_fx->plcInfo.recovery_gain = shl_sat(st_fx->plcInfo.recovery_gain, *Q_synth); + st_fx->plcInfo.recovery_gain = shl_sat( st_fx->plcInfo.recovery_gain, *Q_synth ); #else - st_fx->plcInfo.recovery_gain = shl(st_fx->plcInfo.recovery_gain, *Q_synth); + st_fx->plcInfo.recovery_gain = shl( st_fx->plcInfo.recovery_gain, *Q_synth ); #endif - waveform_adj2_fix(st_fx->tonalMDCTconceal.secondLastPcmOut, - synth, - st_fx->plcInfo.data_noise, - &st_fx->plcInfo.outx_new_n1_fx, - &st_fx->plcInfo.nsapp_gain_fx, - &st_fx->plcInfo.nsapp_gain_n_fx, - &st_fx->plcInfo.recovery_gain, - st_fx->plcInfo.step_concealgain_fx, - st_fx->plcInfo.Pitch_fx, - st_fx->plcInfo.FrameSize, - 0, - add(extract_l(st_fx->plcInfo.nbLostCmpt), 1), - st_fx->bfi); + waveform_adj2_fix( st_fx->tonalMDCTconceal.secondLastPcmOut, + synth, + st_fx->plcInfo.data_noise, + &st_fx->plcInfo.outx_new_n1_fx, + &st_fx->plcInfo.nsapp_gain_fx, + &st_fx->plcInfo.nsapp_gain_n_fx, + &st_fx->plcInfo.recovery_gain, + st_fx->plcInfo.step_concealgain_fx, + st_fx->plcInfo.Pitch_fx, + st_fx->plcInfo.FrameSize, + 0, + add( extract_l( st_fx->plcInfo.nbLostCmpt ), 1 ), + st_fx->bfi ); } - IF (GE_16(output_frame, L_FRAME16k)) + IF( GE_16( output_frame, L_FRAME16k ) ) { - IF (EQ_16(hHQ_core->ph_ecu_HqVoicing, 1)) + IF( EQ_16( hHQ_core->ph_ecu_HqVoicing, 1 ) ) { hHQ_core->oldHqVoicing = 1; move16(); @@ -539,17 +536,17 @@ void hq_core_dec_fx( move16(); } - if( EQ_16(st_fx->nbLostCmpt, FRAMECTTOSTART_MDCT)) + if ( EQ_16( st_fx->nbLostCmpt, FRAMECTTOSTART_MDCT ) ) { hHQ_core->HqVoicing = 0; move16(); } - IF( EQ_16(output_frame, L_FRAME8k)) + IF( EQ_16( output_frame, L_FRAME8k ) ) { - Copy32( wtda_audio, hHQ_nbfec->oldIMDCTout_fx, L_FRAME8k/2 ); - Copy(&hHQ_nbfec->old_auOut_2fr_fx[output_frame], hHQ_nbfec->old_auOut_2fr_fx, output_frame); - Copy_Scale_sig(synth, &hHQ_nbfec->old_auOut_2fr_fx[output_frame], output_frame, negate(*Q_synth)); + Copy32( wtda_audio, hHQ_nbfec->oldIMDCTout_fx, L_FRAME8k / 2 ); + Copy( &hHQ_nbfec->old_auOut_2fr_fx[output_frame], hHQ_nbfec->old_auOut_2fr_fx, output_frame ); + Copy_Scale_sig( synth, &hHQ_nbfec->old_auOut_2fr_fx[output_frame], output_frame, negate( *Q_synth ) ); } /* prepare synthesis output buffer (as recent as possible) for HQ FEC */ @@ -558,7 +555,7 @@ void hq_core_dec_fx( Word16 nbsubfr; /*nbsubfr = extract_l(L_mult0(st_fx->L_frame,FL2WORD16(1/L_SUBFR)));*/ nbsubfr = 4; - if(EQ_16(st_fx->L_frame,320)) + if ( EQ_16( st_fx->L_frame, 320 ) ) { nbsubfr = 5; move16(); @@ -566,20 +563,20 @@ void hq_core_dec_fx( /* update buffer of old subframe pitch values */ test(); - IF( EQ_16(st_fx->last_core,HQ_CORE)&&NE_16(st_fx->L_frame,st_fx->last_L_frame)) + IF( EQ_16( st_fx->last_core, HQ_CORE ) && NE_16( st_fx->L_frame, st_fx->last_L_frame ) ) { - set32_fx( &st_fx->old_pitch_buf_fx[nbsubfr], (L_SUBFR<<16), nbsubfr ); + set32_fx( &st_fx->old_pitch_buf_fx[nbsubfr], ( L_SUBFR << 16 ), nbsubfr ); } Copy32( &st_fx->old_pitch_buf_fx[nbsubfr], &st_fx->old_pitch_buf_fx[0], nbsubfr ); - set32_fx( &st_fx->old_pitch_buf_fx[nbsubfr], (L_SUBFR<<16), nbsubfr ); - Copy( &st_fx->mem_pitch_gain[2], &st_fx->mem_pitch_gain[nbsubfr+2], nbsubfr ); + set32_fx( &st_fx->old_pitch_buf_fx[nbsubfr], ( L_SUBFR << 16 ), nbsubfr ); + Copy( &st_fx->mem_pitch_gain[2], &st_fx->mem_pitch_gain[nbsubfr + 2], nbsubfr ); set16_fx( &st_fx->mem_pitch_gain[2], 0, nbsubfr ); } #ifdef ADD_IVAS_HQ_CODE /* Move LB excitation to old_exc memory in case of switch HQ->ACELP */ - if (st->element_mode > EVS_MONO) + if ( st->element_mode > EVS_MONO ) { - mvr2r(output, st->old_exc + L_EXC_MEM_DEC - st->L_frame, st->L_frame); + mvr2r( output, st->old_exc + L_EXC_MEM_DEC - st->L_frame, st->L_frame ); } #endif return; @@ -626,7 +623,7 @@ void ivas_hq_core_dec_fx( Word16 tcx_offset, overlap, L_frame; Word16 L_frameTCX_glob, L_frame_glob; Word16 acelp_zir[L_FRAME_MAX / 2]; - //Word16 encoderLookahead, encoderLookaheadFB; + // Word16 encoderLookahead, encoderLookaheadFB; Word16 hq_recovery_flag; Word16 mdctWindowLength; Word16 mdctWindowLengthFB; @@ -786,7 +783,7 @@ void ivas_hq_core_dec_fx( flag_uv = 1; move16(); /* disable costly pitch out synthesis in bfi frame */ - hHQ_core->HqVoicing = sub( 1, flag_uv ); /* safety setting for HQ->ACELP switch logic */ + hHQ_core->HqVoicing = sub( 1, flag_uv ); /* safety setting for HQ->ACELP switch logic */ set16_fx( hHQ_core->fer_samples_fx, 0, L_FRAME48k ); /* safety, create a known signal state for HQ->ACELP switch logic */ } } @@ -843,9 +840,9 @@ void ivas_hq_core_dec_fx( /*t_audio_q[i] *= ener_match;*/ Mpy_32_16_ss( t_audio_q[i], ener_match, &L_tmp, &lsb ); /*12+13-15=10 */ #ifdef BASOP_NOGLOB - t_audio_q[i] = L_add_sat( L_shl_sat( L_tmp, 2 ), lshr( (Word16)lsb, 14 ) ); + t_audio_q[i] = L_add_sat( L_shl_sat( L_tmp, 2 ), lshr( (Word16) lsb, 14 ) ); #else - t_audio_q[i] = L_add( L_shl( L_tmp, 2 ), lshr( (Word16)lsb, 14 ) ); + t_audio_q[i] = L_add( L_shl( L_tmp, 2 ), lshr( (Word16) lsb, 14 ) ); #endif move16(); /* Q12 */ } @@ -923,9 +920,9 @@ void ivas_hq_core_dec_fx( L_spec = hTcxDec->L_frameTCX; move16(); st_fx->fscale = sr2fscale( st_fx->sr_core ); - //fscaleFB = sr2fscale( st_fx->output_Fs ); - //encoderLookahead = ( L_LOOK_12k8 * st_fx->fscale ) / FSCALE_DENOM; - //encoderLookaheadFB = ( L_LOOK_12k8 * fscaleFB ) / FSCALE_DENOM; + // fscaleFB = sr2fscale( st_fx->output_Fs ); + // encoderLookahead = ( L_LOOK_12k8 * st_fx->fscale ) / FSCALE_DENOM; + // encoderLookaheadFB = ( L_LOOK_12k8 * fscaleFB ) / FSCALE_DENOM; mdctWindowLength = getMdctWindowLength( st_fx->fscale ); mdctWindowLengthFB = (int16_t) ( mdctWindowLength * st_fx->output_Fs / st_fx->sr_core ); IF( core_switching_flag ) @@ -964,7 +961,7 @@ void ivas_hq_core_dec_fx( E_audio = 31 - Q_audio; move16(); IMDCT_fx( t_audio_q, E_audio, hTcxDec->syn_Overl, hTcxDec->syn_Overl_TDAC, wtda_audio_16, tcx_cfg->tcx_aldo_window_1, tcx_cfg->tcx_aldo_window_1_trunc, tcx_cfg->tcx_aldo_window_2, tcx_cfg->tcx_mdct_window_half, tcx_cfg->tcx_mdct_window_minimum, tcx_cfg->tcx_mdct_window_trans, tcx_cfg->tcx_mdct_window_half_length, tcx_cfg->tcx_mdct_window_min_length, index, - left_rect, tcx_offset, overlap, L_frame, L_frameTCX, max( L_frameTCX, L_spec ) >> 1, L_frame_glob, 0, st_fx->bfi, hHQ_core->old_out_LB_fx, &hHQ_core->Q_old_wtda_LB, st_fx, 0, acelp_zir ); + left_rect, tcx_offset, overlap, L_frame, L_frameTCX, max( L_frameTCX, L_spec ) >> 1, L_frame_glob, 0, st_fx->bfi, hHQ_core->old_out_LB_fx, &hHQ_core->Q_old_wtda_LB, st_fx, 0, acelp_zir ); // values till L_frame same Scale_sig( wtda_audio_16 + L_frame, overlap, Q1 ); @@ -974,7 +971,7 @@ void ivas_hq_core_dec_fx( /* FB synthesis */ IMDCT_fx( t_audio_q, E_audio, hTcxDec->syn_OverlFB, hTcxDec->syn_Overl_TDACFB, wtda_audio_16, tcx_cfg->tcx_aldo_window_1_FB, tcx_cfg->tcx_aldo_window_1_FB_trunc, tcx_cfg->tcx_aldo_window_2_FB, tcx_cfg->tcx_mdct_window_halfFB, tcx_cfg->tcx_mdct_window_minimumFB, tcx_cfg->tcx_mdct_window_transFB, tcx_cfg->tcx_mdct_window_half_lengthFB, tcx_cfg->tcx_mdct_window_min_lengthFB, index, - left_rect, tcx_offsetFB, overlapFB, L_frameTCX, L_frameTCX, max( L_frameTCX, L_spec ) >> 1, L_frameTCX_glob, 0, st_fx->bfi, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, st_fx, FSCALE_DENOM * L_frameTCX_glob / L_frame_glob, acelp_zir ); + left_rect, tcx_offsetFB, overlapFB, L_frameTCX, L_frameTCX, max( L_frameTCX, L_spec ) >> 1, L_frameTCX_glob, 0, st_fx->bfi, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, st_fx, FSCALE_DENOM * L_frameTCX_glob / L_frame_glob, acelp_zir ); Scale_sig( wtda_audio_16 + L_frameTCX, overlapFB, Q1 ); @@ -1209,85 +1206,92 @@ void HQ_core_dec_init_fx( HQ_DEC_HANDLE hHQ_core /* i/o: HQ core data handle */ ) { - set16_fx(hHQ_core->old_out_fx, 0, L_FRAME48k); - set16_fx(hHQ_core->old_out_LB_fx, 0, L_FRAME32k); - set32_fx(hHQ_core->oldOut_fx, 0, L_FRAME48k); - set32_fx(hHQ_core->old_outLB_fx, 0, L_FRAME32k); - hHQ_core->Q_old_wtda = 15; - hHQ_core->Q_old_postdec = 0; + set16_fx( hHQ_core->old_out_fx, 0, L_FRAME48k ); + set16_fx( hHQ_core->old_out_LB_fx, 0, L_FRAME32k ); + set32_fx( hHQ_core->oldOut_fx, 0, L_FRAME48k ); + set32_fx( hHQ_core->old_outLB_fx, 0, L_FRAME32k ); + hHQ_core->Q_old_wtda = 15; + hHQ_core->Q_old_postdec = 0; hHQ_core->Q_old_wtda_LB = 0; hHQ_core->Q_old_out = 0; hHQ_core->Q_old_outLB = 0; - hHQ_core->last_hq_core_type = -1; - set16_fx(hHQ_core->old_is_transient, 0, 3); - - hHQ_core->mem_norm[0] = 31; - set16_fx(hHQ_core->mem_norm + 1, 39, SFM_N_ENV_STAB - 1); - hHQ_core->mem_env_delta = 0; - hHQ_core->no_att_hangover = 0; - move16(); move16(); move16(); move16(); - hHQ_core->energy_lt_fx = 2457600; /*Q13*/ - hHQ_core->hq_generic_seed = RANDOM_INITSEED; - set16_fx(hHQ_core->prev_noise_level_fx, 0, 2); - hHQ_core->prev_hqswb_clas = HQ_NORMAL; - hHQ_core->prev_R = 0; + hHQ_core->last_hq_core_type = -1; + set16_fx( hHQ_core->old_is_transient, 0, 3 ); + + hHQ_core->mem_norm[0] = 31; + set16_fx( hHQ_core->mem_norm + 1, 39, SFM_N_ENV_STAB - 1 ); + hHQ_core->mem_env_delta = 0; + hHQ_core->no_att_hangover = 0; + move16(); + move16(); + move16(); + move16(); + hHQ_core->energy_lt_fx = 2457600; /*Q13*/ + hHQ_core->hq_generic_seed = RANDOM_INITSEED; + set16_fx( hHQ_core->prev_noise_level_fx, 0, 2 ); + hHQ_core->prev_hqswb_clas = HQ_NORMAL; + hHQ_core->prev_R = 0; move16(); - set32_fx(hHQ_core->prev_coeff_out_fx, 0, L_HQ_WB_BWE); - set16_fx(hHQ_core->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM); - - hHQ_core->HqVoicing = 0; - set16_fx(hHQ_core->fer_samples_fx, 0, L_FRAME48k); - set32_fx(hHQ_core->prev_env_fx, 0, SFM_N_WB); - set32_fx(hHQ_core->prev_normq_fx, 0, SFM_N_WB); - set16_fx(hHQ_core->prev_env_Q, 0, SFM_N_WB); - - set32_fx(hHQ_core->last_ni_gain_fx, 0, BANDS_MAX); - set16_fx(hHQ_core->last_env_fx, 0, BANDS_MAX); - hHQ_core->last_max_pos_pulse = 0; + set32_fx( hHQ_core->prev_coeff_out_fx, 0, L_HQ_WB_BWE ); + set16_fx( hHQ_core->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM ); + + hHQ_core->HqVoicing = 0; + set16_fx( hHQ_core->fer_samples_fx, 0, L_FRAME48k ); + set32_fx( hHQ_core->prev_env_fx, 0, SFM_N_WB ); + set32_fx( hHQ_core->prev_normq_fx, 0, SFM_N_WB ); + set16_fx( hHQ_core->prev_env_Q, 0, SFM_N_WB ); + + set32_fx( hHQ_core->last_ni_gain_fx, 0, BANDS_MAX ); + set16_fx( hHQ_core->last_env_fx, 0, BANDS_MAX ); + hHQ_core->last_max_pos_pulse = 0; move16(); hHQ_core->Q_fer_samples = 0; - reset_preecho_dec_fx(hHQ_core); - - hHQ_core->prev_frm_hfe2 = 0; + reset_preecho_dec_fx( hHQ_core ); + + hHQ_core->prev_frm_hfe2 = 0; move16(); - hHQ_core->prev_stab_hfe2 = 0; + hHQ_core->prev_stab_hfe2 = 0; move16(); - hHQ_core->prev_ni_ratio_fx = 16384; /*Q15*/ + hHQ_core->prev_ni_ratio_fx = 16384; /*Q15*/ move16(); - set16_fx(hHQ_core->prev_En_sb_fx, 0, NB_SWB_SUBBANDS); + set16_fx( hHQ_core->prev_En_sb_fx, 0, NB_SWB_SUBBANDS ); /*----------------------------------------------------------------------------------* * HQ FEC *----------------------------------------------------------------------------------*/ - hHQ_core->time_offs = 0; - set16_fx(hHQ_core->X_sav_fx, 0, PH_ECU_SPEC_SIZE); - hHQ_core->Q_X_sav = 0; + hHQ_core->time_offs = 0; + set16_fx( hHQ_core->X_sav_fx, 0, PH_ECU_SPEC_SIZE ); + hHQ_core->Q_X_sav = 0; hHQ_core->num_p = 0; - //set16_fx(hHQ_core->plocs, 0, MAX_PLOCS); - //set32_fx(hHQ_core->plocsi_fx, 0, MAX_PLOCS); - hHQ_core->env_stab_fx = 0x6000; /*0.75 Q15*/ - hHQ_core->mem_norm_hqfec[0] = 31; + // set16_fx(hHQ_core->plocs, 0, MAX_PLOCS); + // set32_fx(hHQ_core->plocsi_fx, 0, MAX_PLOCS); + hHQ_core->env_stab_fx = 0x6000; /*0.75 Q15*/ + hHQ_core->mem_norm_hqfec[0] = 31; + move16(); + set16_fx( hHQ_core->mem_norm_hqfec + 1, 39, SFM_N_ENV_STAB - 1 ); + hHQ_core->mem_env_delta_hqfec = 0; + hHQ_core->env_stab_plc_fx = 0; + set16_fx( hHQ_core->env_stab_state_p_fx, INV_NUM_ENV_STAB_PLC_STATES, NUM_ENV_STAB_PLC_STATES ); + hHQ_core->envstabplc_hocnt = 0; + set16_fx( hHQ_core->mag_chg_1st_fx, 32767, LGW_MAX ); + set16_fx( hHQ_core->Xavg_fx, 0, LGW_MAX ); + hHQ_core->beta_mute_fx = BETA_MUTE_FAC_INI; + hHQ_core->last_fec = 0; + hHQ_core->ph_ecu_HqVoicing = 0; + hHQ_core->oldHqVoicing = 0; + set16_fx( hHQ_core->oldgapsynth_fx, 0, L_FRAME48k ); + hHQ_core->ph_ecu_active = 0; + hHQ_core->ni_seed_forfec = 0; + hHQ_core->ber_occured_in_pvq = 0; + move16(); + move16(); + move16(); + move16(); move16(); - set16_fx(hHQ_core->mem_norm_hqfec + 1, 39, SFM_N_ENV_STAB - 1); - hHQ_core->mem_env_delta_hqfec = 0; - hHQ_core->env_stab_plc_fx = 0; - set16_fx(hHQ_core->env_stab_state_p_fx, INV_NUM_ENV_STAB_PLC_STATES, NUM_ENV_STAB_PLC_STATES); - hHQ_core->envstabplc_hocnt = 0; - set16_fx(hHQ_core->mag_chg_1st_fx, 32767, LGW_MAX); - set16_fx(hHQ_core->Xavg_fx, 0, LGW_MAX); - hHQ_core->beta_mute_fx = BETA_MUTE_FAC_INI; - hHQ_core->last_fec = 0; - hHQ_core->ph_ecu_HqVoicing = 0; - hHQ_core->oldHqVoicing = 0; - set16_fx(hHQ_core->oldgapsynth_fx, 0, L_FRAME48k); - hHQ_core->ph_ecu_active = 0; - hHQ_core->ni_seed_forfec = 0; - hHQ_core->ber_occured_in_pvq = 0; - move16(); move16(); move16(); move16(); move16(); return; @@ -1305,45 +1309,49 @@ void HQ_nbfec_init_fx( { int16_t i, j; - hHQ_nbfec->prev_last_core = -1; - hHQ_nbfec->diff_energy_fx = 0; + hHQ_nbfec->prev_last_core = -1; + hHQ_nbfec->diff_energy_fx = 0; hHQ_nbfec->stat_mode_out = 0; hHQ_nbfec->stat_mode_old = 0; - move16(); move16(); + move16(); + move16(); hHQ_nbfec->phase_mat_flag = 0; hHQ_nbfec->phase_mat_next = 0; hHQ_nbfec->old_Min_ind = 0; - move16(); move16(); move16(); move16(); - set16_fx(hHQ_nbfec->old_auOut_2fr_fx, 0, L_FRAME8k * 2); - set16_fx(hHQ_nbfec->old_out_pha_fx[0], 0, N_LEAD_NB); - set16_fx(hHQ_nbfec->old_out_pha_fx[1], 0, N_LEAD_NB); + move16(); + move16(); + move16(); + move16(); + set16_fx( hHQ_nbfec->old_auOut_2fr_fx, 0, L_FRAME8k * 2 ); + set16_fx( hHQ_nbfec->old_out_pha_fx[0], 0, N_LEAD_NB ); + set16_fx( hHQ_nbfec->old_out_pha_fx[1], 0, N_LEAD_NB ); - FOR(i = 0; i < MAX_SB_NB; i++) + FOR( i = 0; i < MAX_SB_NB; i++ ) { - FOR(j = 0; j < MAX_PGF; j++) + FOR( j = 0; j < MAX_PGF; j++ ) { hHQ_nbfec->ynrm_values_fx[i][j] = 0; move16(); } - FOR(j = 0; j < MAX_ROW; j++) + FOR( j = 0; j < MAX_ROW; j++ ) { hHQ_nbfec->r_p_values_fx[i][j] = 0; move16(); } } - set16_fx(hHQ_nbfec->Norm_gain_fx, 1, SFM_N_NB); + set16_fx( hHQ_nbfec->Norm_gain_fx, 1, SFM_N_NB ); hHQ_nbfec->HQ_FEC_seed = RANDOM_INITSEED; - set16_fx(hHQ_nbfec->energy_MA_Curr_fx, 100, 2); + set16_fx( hHQ_nbfec->energy_MA_Curr_fx, 100, 2 ); - set16_fx(hHQ_nbfec->prev_sign_switch, 0, HQ_FEC_SIGN_SFM); - set16_fx(hHQ_nbfec->prev_sign_switch_2, 0, HQ_FEC_SIGN_SFM); + set16_fx( hHQ_nbfec->prev_sign_switch, 0, HQ_FEC_SIGN_SFM ); + set16_fx( hHQ_nbfec->prev_sign_switch_2, 0, HQ_FEC_SIGN_SFM ); - set32_fx(hHQ_nbfec->old_coeffs_fx, 0, L_FRAME8k); - set32_fx(hHQ_nbfec->oldIMDCTout_fx, 0, L_FRAME8k / 2); - set16_fx(hHQ_nbfec->prev_oldauOut_fx, 0, L_FRAME8k); + set32_fx( hHQ_nbfec->old_coeffs_fx, 0, L_FRAME8k ); + set32_fx( hHQ_nbfec->oldIMDCTout_fx, 0, L_FRAME8k / 2 ); + set16_fx( hHQ_nbfec->prev_oldauOut_fx, 0, L_FRAME8k ); return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/hq_env_dec_fx.c b/lib_dec/hq_env_dec_fx.c index 8ecc8b6da..d89c24fc1 100644 --- a/lib_dec/hq_env_dec_fx.c +++ b/lib_dec/hq_env_dec_fx.c @@ -3,10 +3,10 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "rom_com.h" /* Static table prototypes */ +#include "options.h" /* Compilation switches */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "rom_com.h" /* Static table prototypes */ #ifdef IVAS_FLOAT_FIXED /*------------------------------------------------------------------------* @@ -15,51 +15,52 @@ * Decode envelope indices *------------------------------------------------------------------------*/ -Word16 decode_envelope_indices_fx( /* o : Number of bits */ - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 start_norm, /* i : starting band index */ - const Word16 num_sfm, /* i : Number of subbands */ - const Word16 numnrmibits, /* i : Bitrate of fall-back coding mode */ - Word16 *difidx, /* o : Diff indices/encoded diff indices */ - const Word16 flag_HQ2 /* i : indicator of HQ2 core */ - ,const Word16 is_transient /* i : indicator of HQ_TRANSIENT */ +Word16 decode_envelope_indices_fx( /* o : Number of bits */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 start_norm, /* i : starting band index */ + const Word16 num_sfm, /* i : Number of subbands */ + const Word16 numnrmibits, /* i : Bitrate of fall-back coding mode */ + Word16 *difidx, /* o : Diff indices/encoded diff indices */ + const Word16 flag_HQ2 /* i : indicator of HQ2 core */ + , + const Word16 is_transient /* i : indicator of HQ_TRANSIENT */ ) { Word16 hcode_l; - Word16 i,j; + Word16 i, j; Word16 LCmode; - Word16 startNormPlus1,numSfmMinus1,numSfmMinus2,offset; - Word16 *pDifidx,*pDifidx1; + Word16 startNormPlus1, numSfmMinus1, numSfmMinus2, offset; + Word16 *pDifidx, *pDifidx1; test(); - IF( EQ_16(flag_HQ2, LOW_RATE_HQ_CORE)||EQ_16(flag_HQ2,LOW_RATE_HQ_CORE_TRAN)) + IF( EQ_16( flag_HQ2, LOW_RATE_HQ_CORE ) || EQ_16( flag_HQ2, LOW_RATE_HQ_CORE_TRAN ) ) { - LCmode = (Word16)get_next_indice ( st_fx, BITS_DE_HMODE); - difidx[start_norm] = (Word16)get_next_indice ( st_fx, BITS_DE_FCOMP); + LCmode = (Word16) get_next_indice( st_fx, BITS_DE_HMODE ); + difidx[start_norm] = (Word16) get_next_indice( st_fx, BITS_DE_FCOMP ); } ELSE { - LCmode = (Word16)get_next_indice( st_fx, 2 ); - difidx[start_norm] = (Word16)get_next_indice( st_fx, NORM0_BITS ); + LCmode = (Word16) get_next_indice( st_fx, 2 ); + difidx[start_norm] = (Word16) get_next_indice( st_fx, NORM0_BITS ); } test(); - IF( is_transient && EQ_16(flag_HQ2, LOW_RATE_HQ_CORE_TRAN)) + IF( is_transient && EQ_16( flag_HQ2, LOW_RATE_HQ_CORE_TRAN ) ) { hcode_l = 0; move16(); - IF( EQ_16(LCmode, 1)) + IF( EQ_16( LCmode, 1 ) ) { - hdecnrm_tran_fx(st_fx, num_sfm, &difidx[start_norm + 1] ); - j = add(start_norm, num_sfm); + hdecnrm_tran_fx( st_fx, num_sfm, &difidx[start_norm + 1] ); + j = add( start_norm, num_sfm ); FOR( i = start_norm + 1; i < j; i++ ) { - hcode_l = add(hcode_l, huffsizn_tran[difidx[i]]); + hcode_l = add( hcode_l, huffsizn_tran[difidx[i]] ); } } ELSE { - hdecnrm_context_fx(st_fx, num_sfm, &difidx[start_norm], &hcode_l); + hdecnrm_context_fx( st_fx, num_sfm, &difidx[start_norm], &hcode_l ); } } ELSE @@ -67,67 +68,67 @@ Word16 decode_envelope_indices_fx( /* o : Number of bits */ hcode_l = 0; IF( LCmode == 0 ) { - hdecnrm_context_fx( st_fx, num_sfm, &difidx[start_norm], &hcode_l); + hdecnrm_context_fx( st_fx, num_sfm, &difidx[start_norm], &hcode_l ); } ELSE IF( LCmode == 1 ) { - startNormPlus1 = add(start_norm, 1); + startNormPlus1 = add( start_norm, 1 ); hdecnrm_resize_fx( st_fx, num_sfm, &difidx[startNormPlus1] ); pDifidx = &difidx[startNormPlus1]; move16(); - numSfmMinus1 = sub(num_sfm, 1); + numSfmMinus1 = sub( num_sfm, 1 ); FOR( i = 0; i < numSfmMinus1; i++ ) { j = *pDifidx++; move16(); - hcode_l = add(hcode_l, resize_huffsizn[j]); + hcode_l = add( hcode_l, resize_huffsizn[j] ); } pDifidx1 = &difidx[startNormPlus1]; move16(); - numSfmMinus2 = sub(num_sfm, 2); + numSfmMinus2 = sub( num_sfm, 2 ); FOR( i = 0; i < numSfmMinus2; i++ ) { pDifidx = pDifidx1++; move16(); IF( *pDifidx > 17 ) { - offset = sub(*pDifidx, 17); - offset = s_min(offset, 3); - *pDifidx1 = sub(*pDifidx1, offset); + offset = sub( *pDifidx, 17 ); + offset = s_min( offset, 3 ); + *pDifidx1 = sub( *pDifidx1, offset ); } ELSE IF( *pDifidx < 13 ) { - offset = sub(*pDifidx, 13); - offset = s_max(offset, -3); - *pDifidx1 = sub(*pDifidx1, offset); + offset = sub( *pDifidx, 13 ); + offset = s_max( offset, -3 ); + *pDifidx1 = sub( *pDifidx1, offset ); } } } ELSE IF( LCmode == 2 ) { - startNormPlus1 = add(start_norm, 1); + startNormPlus1 = add( start_norm, 1 ); hdecnrm_fx( st_fx, num_sfm, &difidx[start_norm + 1] ); pDifidx = &difidx[startNormPlus1]; move16(); - numSfmMinus1 = sub(num_sfm, 1); + numSfmMinus1 = sub( num_sfm, 1 ); FOR( i = 0; i < numSfmMinus1; i++ ) { j = *pDifidx++; move16(); - hcode_l = add(hcode_l, huffsizn[j]); + hcode_l = add( hcode_l, huffsizn[j] ); } } ELSE { - startNormPlus1 = add(start_norm, 1); - numSfmMinus1 = sub(num_sfm, 1); + startNormPlus1 = add( start_norm, 1 ); + numSfmMinus1 = sub( num_sfm, 1 ); pDifidx = &difidx[startNormPlus1]; FOR( i = 0; i < numSfmMinus1; i++ ) { - *pDifidx++ = (Word16)get_next_indice( st_fx, NORMI_BITS ); + *pDifidx++ = (Word16) get_next_indice( st_fx, NORMI_BITS ); move16(); } hcode_l = numnrmibits; @@ -147,15 +148,15 @@ Word16 decode_envelope_indices_fx( /* o : Number of bits */ *------------------------------------------------------------------------*/ void dequantize_norms_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 start_norm, /* i : First SDE encoded norm */ - const Word16 num_sfm, /* i : Number of norms */ - const Word16 is_transient, /* i : Transient flag */ - Word16 *ynrm, /* o : Decoded norm indices */ - Word16 *normqlg2 /* o : Log2 of decoded norms */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 start_norm, /* i : First SDE encoded norm */ + const Word16 num_sfm, /* i : Number of norms */ + const Word16 is_transient, /* i : Transient flag */ + Word16 *ynrm, /* o : Decoded norm indices */ + Word16 *normqlg2 /* o : Log2 of decoded norms */ ) { - Word16 i,j; + Word16 i, j; Word16 idxbuf[NB_SFM]; Word16 *pYnrm, *pNormqlg2; @@ -166,18 +167,18 @@ void dequantize_norms_fx( move16(); /* Other sub-frames */ - IF ( is_transient ) + IF( is_transient ) { /* Recover quantization indices and quantized norms */ idxbuf[0] = ynrm[0]; move16(); - FOR ( i = 1; i < num_sfm; i++ ) + FOR( i = 1; i < num_sfm; i++ ) { - idxbuf[i] = sub( add(ynrm[i],idxbuf[i-1]), 15 ); + idxbuf[i] = sub( add( ynrm[i], idxbuf[i - 1] ), 15 ); move16(); /* safety check in case of bit errors */ test(); - IF ( idxbuf[i] < 0 || GT_16( idxbuf[i], 39 )) + IF( idxbuf[i] < 0 || GT_16( idxbuf[i], 39 ) ) { idxbuf[i] = 39; move16(); @@ -192,17 +193,17 @@ void dequantize_norms_fx( { pYnrm = &ynrm[start_norm]; move16(); - pNormqlg2 = &normqlg2[start_norm+1]; + pNormqlg2 = &normqlg2[start_norm + 1]; move16(); - FOR ( i = 1; i < num_sfm; i++ ) + FOR( i = 1; i < num_sfm; i++ ) { - j = sub(*pYnrm++,15); + j = sub( *pYnrm++, 15 ); move16(); - *pYnrm = add(*pYnrm,j); + *pYnrm = add( *pYnrm, j ); move16(); /* safety check in case of bit errors */ test(); - IF ( *pYnrm < 0 || GT_16( *pYnrm, 39 )) + IF( *pYnrm < 0 || GT_16( *pYnrm, 39 ) ) { *pYnrm = 39; move16(); @@ -217,4 +218,3 @@ void dequantize_norms_fx( return; } #endif - diff --git a/lib_dec/hq_hr_dec_fx.c b/lib_dec/hq_hr_dec_fx.c index f8b66cb29..d42acd11b 100644 --- a/lib_dec/hq_hr_dec_fx.c +++ b/lib_dec/hq_hr_dec_fx.c @@ -2,10 +2,10 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "rom_com.h" /* Static table prototypes */ +#include "options.h" /* Compilation switches */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "rom_com.h" /* Static table prototypes */ #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" #endif @@ -70,37 +70,37 @@ void ivas_hq_pred_hb_bws_fx( } void hq_pred_hb_bws_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 *ynrm, /* i : norm quantization index vector */ - const Word16 length, /* i : frame length */ - const Word16 hqswb_clas, /* i : HQ SWB class */ - const Word16 *SWB_fenv /* i : SWB frequency envelopes Q1 */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 *ynrm, /* i : norm quantization index vector */ + const Word16 length, /* i : frame length */ + const Word16 hqswb_clas, /* i : HQ SWB class */ + const Word16 *SWB_fenv /* i : SWB frequency envelopes Q1 */ ) { Word16 i; Word32 L_tmp; - IF( GE_16(length,L_FRAME32k)) + IF( GE_16( length, L_FRAME32k ) ) { /* calculate the switching parameters */ test(); test(); - IF( ( NE_16(hqswb_clas,HQ_GEN_SWB)&&LE_32(st_fx->core_brate,HQ_32k))||GT_32(st_fx->core_brate,HQ_32k)) + IF( ( NE_16( hqswb_clas, HQ_GEN_SWB ) && LE_32( st_fx->core_brate, HQ_32k ) ) || GT_32( st_fx->core_brate, HQ_32k ) ) { st_fx->prev_ener_shb_fx = 0; move16(); - L_tmp = L_deposit_l(0); - FOR(i=25; iprev_ener_shb_fx = extract_l(L_tmp);/*Q1*/ - st_fx->prev_ener_shb_fx = mult(st_fx->prev_ener_shb_fx,5461); /*Q1*/ + L_tmp = L_min( 8191, L_shr( L_tmp, 13 ) ); + st_fx->prev_ener_shb_fx = extract_l( L_tmp ); /*Q1*/ + st_fx->prev_ener_shb_fx = mult( st_fx->prev_ener_shb_fx, 5461 ); /*Q1*/ } ELSE { @@ -117,22 +117,21 @@ void hq_pred_hb_bws_fx( #else st_fx->prev_ener_shb_fx = 0; move16(); - FOR(i=0; iprev_ener_shb_fx = add(st_fx->prev_ener_shb_fx,SWB_fenv[i]);/*Q1*/ + st_fx->prev_ener_shb_fx = add( st_fx->prev_ener_shb_fx, SWB_fenv[i] ); /*Q1*/ } - st_fx->prev_ener_shb_fx = mult(st_fx->prev_ener_shb_fx, 2979); /*Q1*/ + st_fx->prev_ener_shb_fx = mult( st_fx->prev_ener_shb_fx, 2979 ); /*Q1*/ #endif } } - IF( GE_16(st_fx->last_inner_frame,L_FRAME32k)) + IF( GE_16( st_fx->last_inner_frame, L_FRAME32k ) ) { - set16_fx(st_fx->prev_SWB_fenv_fx, st_fx->prev_ener_shb_fx, SWB_FENV); + set16_fx( st_fx->prev_SWB_fenv_fx, st_fx->prev_ener_shb_fx, SWB_FENV ); } return; - } #endif /*--------------------------------------------------------------------------* @@ -300,7 +299,7 @@ void ivas_hq_hr_dec_fx( test(); test(); - IF( EQ_16( *hqswb_clas, HQ_GEN_SWB ) && GT_16(st_fx->bws_cnt1, 0) && LT_32( st_fx->core_brate, HQ_32k ) ) + IF( EQ_16( *hqswb_clas, HQ_GEN_SWB ) && GT_16( st_fx->bws_cnt1, 0 ) && LT_32( st_fx->core_brate, HQ_32k ) ) { tmp = i_mult( st_fx->bws_cnt1, 1638 ); move16(); @@ -407,14 +406,14 @@ void ivas_hq_hr_dec_fx( void hq_hr_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure fx */ - Word32 *t_audio_q, /* o : transform-domain coefficients Q12 */ - const Word16 length, /* i : frame length Q0 */ - Word16 num_bits, /* i : number of available bits Q0 */ - Word16 *ynrm, /* o : norm quantization index vector Q0 */ - Word16 *is_transient, /* o : transient flag Q0 */ - Word16 *hqswb_clas, /* o : HQ SWB class Q0 */ - Word16 *SWB_fenv, /* o : SWB frequency envelopes Q1 */ - const Word16 core_switching_flag /* i : Core switching flag */ + Word32 *t_audio_q, /* o : transform-domain coefficients Q12 */ + const Word16 length, /* i : frame length Q0 */ + Word16 num_bits, /* i : number of available bits Q0 */ + Word16 *ynrm, /* o : norm quantization index vector Q0 */ + Word16 *is_transient, /* o : transient flag Q0 */ + Word16 *hqswb_clas, /* o : HQ SWB class Q0 */ + Word16 *SWB_fenv, /* o : SWB frequency envelopes Q1 */ + const Word16 core_switching_flag /* i : Core switching flag */ ) { Word16 nb_sfm; @@ -424,10 +423,10 @@ void hq_hr_dec_fx( Word16 nf_idx; Word16 normqlg2[NB_SFM], R[NB_SFM]; Word16 pulses[NB_SFM], maxpulse[NB_SFM]; - Word16 env_stab; /*Q15*/ - Word16 Rsubband[NB_SFM]; /*Q3*/ + Word16 env_stab; /*Q15*/ + Word16 Rsubband[NB_SFM]; /*Q3*/ Word16 start_norm, Npeaks = 0; - Word16 noise_level[HVQ_BWE_NOISE_BANDS]; /*Q15*/ + Word16 noise_level[HVQ_BWE_NOISE_BANDS]; /*Q15*/ Word16 peak_idx[HVQ_MAX_PEAKS]; Word16 hq_generic_offset; Word16 num_env_bands; @@ -441,7 +440,7 @@ void hq_hr_dec_fx( Word16 t_audio_q_norm[L_FRAME48k]; Word16 Q_audio; Word16 b_delta_env; - Word16 tmp,n_band; + Word16 tmp, n_band; Word16 Q_shift; Word16 bits_left; Word16 csw_flag1, csw_flag2; @@ -450,7 +449,7 @@ void hq_hr_dec_fx( move16(); - Q_audio = 0; /* to avoid compilation warnings */ + Q_audio = 0; /* to avoid compilation warnings */ /*------------------------------------------------------------------* * Initializations @@ -464,20 +463,20 @@ void hq_hr_dec_fx( move16(); har_freq_est2 = 0; move16(); - set16_fx( peak_idx, 0, HVQ_MAX_PEAKS); + set16_fx( peak_idx, 0, HVQ_MAX_PEAKS ); /*------------------------------------------------------------------* * Decode classification *------------------------------------------------------------------*/ - bits = hq_classifier_dec_fx( st_fx, st_fx->core_brate, length, is_transient, hqswb_clas); - bits_left = sub(num_bits, bits); + bits = hq_classifier_dec_fx( st_fx, st_fx->core_brate, length, is_transient, hqswb_clas ); + bits_left = sub( num_bits, bits ); /*------------------------------------------------------------------* * set quantization parameters *------------------------------------------------------------------*/ hq_configure_evs_fx( length, *hqswb_clas, st_fx->core_brate, &num_sfm, &nb_sfm, &start_norm, - &num_env_bands, &numnrmibits, &hq_generic_offset, sfmsize, sfm_start, sfm_end ); + &num_env_bands, &numnrmibits, &hq_generic_offset, sfmsize, sfm_start, sfm_end ); /*------------------------------------------------------------------* * Unpacking bitstream @@ -488,7 +487,7 @@ void hq_hr_dec_fx( test(); test(); test(); - IF( !*is_transient && NE_16(*hqswb_clas, HQ_HVQ) && !(EQ_16(length,L_FRAME16k) && LE_32(st_fx->core_brate,HQ_32k))) + IF( !*is_transient && NE_16( *hqswb_clas, HQ_HVQ ) && !( EQ_16( length, L_FRAME16k ) && LE_32( st_fx->core_brate, HQ_32k ) ) ) { nf_idx = get_next_indice( st_fx, 2 ); } @@ -498,35 +497,35 @@ void hq_hr_dec_fx( *------------------------------------------------------------------*/ hcode_l = decode_envelope_indices_fx( st_fx, start_norm, num_env_bands, numnrmibits, ynrm, NORMAL_HQ_CORE, *is_transient ); - bits_left = sub(bits_left, add(hcode_l, NORM0_BITS + FLAGS_BITS)); + bits_left = sub( bits_left, add( hcode_l, NORM0_BITS + FLAGS_BITS ) ); dequantize_norms_fx( st_fx, start_norm, num_env_bands, *is_transient, ynrm, normqlg2 ); test(); - IF ( EQ_16(*hqswb_clas, HQ_GEN_SWB)||EQ_16(*hqswb_clas,HQ_GEN_FB)) + IF( EQ_16( *hqswb_clas, HQ_GEN_SWB ) || EQ_16( *hqswb_clas, HQ_GEN_FB ) ) { - hq_generic_exc_clas = swb_bwe_gain_deq_fx( st_fx, HQ_CORE, NULL, SWB_fenv, st_fx->core_brate >= HQ_32k, *hqswb_clas ); /* Use (st->core_brate >= HQ_32k) to be consistent with hq_configure */ - if ( EQ_16(hq_generic_exc_clas , HQ_GENERIC_SP_EXC)) + hq_generic_exc_clas = swb_bwe_gain_deq_fx( st_fx, HQ_CORE, NULL, SWB_fenv, st_fx->core_brate >= HQ_32k, *hqswb_clas ); /* Use (st->core_brate >= HQ_32k) to be consistent with hq_configure */ + if ( EQ_16( hq_generic_exc_clas, HQ_GENERIC_SP_EXC ) ) { - bits_left = add(bits_left,1); /* conditional 1 bit saving for representing HQ GENERIC excitation class */ + bits_left = add( bits_left, 1 ); /* conditional 1 bit saving for representing HQ GENERIC excitation class */ } map_hq_generic_fenv_norm_fx( *hqswb_clas, SWB_fenv, ynrm, normqlg2, num_env_bands, nb_sfm, hq_generic_offset ); } env_stab = 0; move16(); - - csw_flag1 = s_and(core_switching_flag, (Word16)NE_16(st_fx->element_mode, EVS_MONO) ); - csw_flag2 = s_and(csw_flag1, (Word16)EQ_16(length, L_SPEC32k_EXT)); + + csw_flag1 = s_and( core_switching_flag, (Word16) NE_16( st_fx->element_mode, EVS_MONO ) ); + csw_flag2 = s_and( csw_flag1, (Word16) EQ_16( length, L_SPEC32k_EXT ) ); test(); - IF( EQ_16(*hqswb_clas, HQ_HVQ)) + IF( EQ_16( *hqswb_clas, HQ_HVQ ) ) { hHQ_core->mem_env_delta = 0; move16(); } - ELSE IF (EQ_16(length, L_FRAME32k) || csw_flag2 ) + ELSE IF( EQ_16( length, L_FRAME32k ) || csw_flag2 ) { - env_stab = env_stability_fx( ynrm, SFM_N_ENV_STAB, hHQ_core->mem_norm, &hHQ_core->mem_env_delta, csw_flag1); + env_stab = env_stability_fx( ynrm, SFM_N_ENV_STAB, hHQ_core->mem_norm, &hHQ_core->mem_env_delta, csw_flag1 ); } ELSE { @@ -536,24 +535,24 @@ void hq_hr_dec_fx( move16(); } - IF ( EQ_16(*hqswb_clas, HQ_HVQ)) + IF( EQ_16( *hqswb_clas, HQ_HVQ ) ) { hHQ_core->env_stab_fx = 32767; - move16(); /* 1 in Q15, stable by definition */ + move16(); /* 1 in Q15, stable by definition */ } ELSE { - IF ( EQ_16(length, L_FRAME32k) || csw_flag2) + IF( EQ_16( length, L_FRAME32k ) || csw_flag2 ) { - move16(); /* calculated stability */ + move16(); /* calculated stability */ hHQ_core->env_stab_fx = env_stab; } ELSE { - hHQ_core->env_stab_fx = env_stability_fx( ynrm, SFM_N_ENV_STAB_WB, hHQ_core->mem_norm_hqfec, &hHQ_core->mem_env_delta_hqfec, csw_flag1); + hHQ_core->env_stab_fx = env_stability_fx( ynrm, SFM_N_ENV_STAB_WB, hHQ_core->mem_norm_hqfec, &hHQ_core->mem_env_delta_hqfec, csw_flag1 ); } } - hHQ_core->env_stab_plc_fx = env_stab_smo_fx(s_min(hHQ_core->env_stab_fx, sub(32767, stab_trans_fx[L_STAB_TBL-1])), hHQ_core->env_stab_state_p_fx, &hHQ_core->envstabplc_hocnt); + hHQ_core->env_stab_plc_fx = env_stab_smo_fx( s_min( hHQ_core->env_stab_fx, sub( 32767, stab_trans_fx[L_STAB_TBL - 1] ) ), hHQ_core->env_stab_state_p_fx, &hHQ_core->envstabplc_hocnt ); /*------------------------------------------------------------------* * Bit allocation @@ -564,48 +563,48 @@ void hq_hr_dec_fx( test(); test(); - IF( EQ_16(*hqswb_clas, HQ_GEN_SWB) && st_fx->bws_cnt1>0 && LT_32(st_fx->core_brate,HQ_32k)) + IF( EQ_16( *hqswb_clas, HQ_GEN_SWB ) && st_fx->bws_cnt1 > 0 && LT_32( st_fx->core_brate, HQ_32k ) ) { - tmp = i_mult(st_fx->bws_cnt1, 1638); + tmp = i_mult( st_fx->bws_cnt1, 1638 ); move16(); - IF( EQ_16(st_fx->L_frame, L_FRAME16k)) + IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { - FOR (n_band = 0; n_band < 4; n_band++) + FOR( n_band = 0; n_band < 4; n_band++ ) { - SWB_fenv[n_band] = mult_r(SWB_fenv[n_band], tmp); + SWB_fenv[n_band] = mult_r( SWB_fenv[n_band], tmp ); move16(); } } - FOR (n_band = 4; n_band < SWB_FENV; n_band++) + FOR( n_band = 4; n_band < SWB_FENV; n_band++ ) { - SWB_fenv[n_band] = mult_r(SWB_fenv[n_band], tmp); + SWB_fenv[n_band] = mult_r( SWB_fenv[n_band], tmp ); move16(); } } test(); - IF ( EQ_16(*hqswb_clas , HQ_GEN_SWB)||EQ_16(*hqswb_clas,HQ_GEN_FB)) + IF( EQ_16( *hqswb_clas, HQ_GEN_SWB ) || EQ_16( *hqswb_clas, HQ_GEN_FB ) ) { - b_delta_env = get_nor_delta_hf_fx(st_fx, ynrm, Rsubband, num_env_bands, nb_sfm, core_sfm ); - sum = sub(sum,b_delta_env); + b_delta_env = get_nor_delta_hf_fx( st_fx, ynrm, Rsubband, num_env_bands, nb_sfm, core_sfm ); + sum = sub( sum, b_delta_env ); } /*------------------------------------------------------------------* * Decode spectral fine structure using HVQ/PVQ *------------------------------------------------------------------*/ - IF( EQ_16(*hqswb_clas, HQ_HVQ)) + IF( EQ_16( *hqswb_clas, HQ_HVQ ) ) { hvq_dec_fx( st_fx, bits_left, st_fx->core_brate, ynrm, R, noise_level, peak_idx, &Npeaks, t_audio_q, st_fx->core ); } ELSE { - pvq_core_dec_fx(st_fx, sfm_start, sfm_end, sfmsize, t_audio_q_norm, &Q_audio, sum, nb_sfm, Rsubband, R, pulses, maxpulse, HQ_CORE ); + pvq_core_dec_fx( st_fx, sfm_start, sfm_end, sfmsize, t_audio_q_norm, &Q_audio, sum, nb_sfm, Rsubband, R, pulses, maxpulse, HQ_CORE ); } test(); - IF ( EQ_16(*hqswb_clas, HQ_HVQ)||EQ_16(*hqswb_clas,HQ_HARMONIC)) + IF( EQ_16( *hqswb_clas, HQ_HVQ ) || EQ_16( *hqswb_clas, HQ_HARMONIC ) ) { subband_search_offset = subband_search_offsets_13p2kbps_Har; wBands[0] = SWB_SB_BW_LEN0_16KBPS_HAR; @@ -613,16 +612,16 @@ void hq_hr_dec_fx( wBands[1] = SWB_SB_BW_LEN1_16KBPS_HAR; move16(); - IF (EQ_16(*hqswb_clas, HQ_HARMONIC)) + IF( EQ_16( *hqswb_clas, HQ_HARMONIC ) ) { - Q_shift = sub(SWB_BWE_LR_Qs, Q_audio); - FOR (i = 0; i < 300; i++) + Q_shift = sub( SWB_BWE_LR_Qs, Q_audio ); + FOR( i = 0; i < 300; i++ ) { - t_audio_q[i] = L_shl(L_deposit_l(t_audio_q_norm[i]), Q_shift); /* Q12 */ + t_audio_q[i] = L_shl( L_deposit_l( t_audio_q_norm[i] ), Q_shift ); /* Q12 */ } } - har_est_fx( t_audio_q, 300 ,&har_freq_est1, &har_freq_est2, &flag_dis, &hHQ_core->prev_frm_hfe2, subband_search_offset, wBands, &hHQ_core->prev_stab_hfe2 ); + har_est_fx( t_audio_q, 300, &har_freq_est1, &har_freq_est2, &flag_dis, &hHQ_core->prev_frm_hfe2, subband_search_offset, wBands, &hHQ_core->prev_stab_hfe2 ); hHQ_core->prev_frm_hfe2 = har_freq_est2; move16(); @@ -632,10 +631,12 @@ void hq_hr_dec_fx( test(); #if 0 IF ( NE_16(*hqswb_clas, HQ_HARMONIC)||NE_16(*hqswb_clas,HQ_HVQ)||flag_dis==0) // TV2VE -> always reset in floating point code, is it OK -#endif +#endif { - hHQ_core->prev_frm_hfe2 = 0; /*reset*/ move16(); - hHQ_core->prev_stab_hfe2 = 0; /*reset*/ move16(); + hHQ_core->prev_frm_hfe2 = 0; /*reset*/ + move16(); + hHQ_core->prev_stab_hfe2 = 0; /*reset*/ + move16(); } /*------------------------------------------------------------------* @@ -644,14 +645,13 @@ void hq_hr_dec_fx( fill_spectrum_fx( t_audio_q_norm, t_audio_q, R, *is_transient, ynrm, SWB_fenv, hq_generic_offset, nf_idx, length, env_stab, &hHQ_core->no_att_hangover, &hHQ_core->energy_lt_fx, &hHQ_core->hq_generic_seed, hq_generic_exc_clas, core_sfm, *hqswb_clas, noise_level, st_fx->core_brate, hHQ_core->prev_noise_level_fx, &hHQ_core->prev_R, hHQ_core->prev_coeff_out_fx, peak_idx, Npeaks, pulses, hHQ_core->old_is_transient[0], - hHQ_core->prev_normq_fx, hHQ_core->prev_env_fx, st_fx->prev_bfi, sfmsize, sfm_start, sfm_end, - &st_fx->hBWE_FD->prev_L_swb_norm, hHQ_core->prev_hqswb_clas, num_sfm, hHQ_core->prev_env_Q, num_env_bands - ,st_fx->element_mode); + hHQ_core->prev_normq_fx, hHQ_core->prev_env_fx, st_fx->prev_bfi, sfmsize, sfm_start, sfm_end, + &st_fx->hBWE_FD->prev_L_swb_norm, hHQ_core->prev_hqswb_clas, num_sfm, hHQ_core->prev_env_Q, num_env_bands, st_fx->element_mode ); enforce_zero_for_min_envelope_fx( *hqswb_clas, ynrm, t_audio_q, nb_sfm, sfm_start, sfm_end ); - IF( EQ_16(*is_transient, 1)) + IF( EQ_16( *is_transient, 1 ) ) { de_interleave_spectrum_fx( t_audio_q, length ); } @@ -659,7 +659,7 @@ void hq_hr_dec_fx( /*------------------------------------------------------------------* * WB/SWB bandwidth switching *------------------------------------------------------------------*/ - hq_pred_hb_bws_fx(st_fx, ynrm, length, *hqswb_clas, SWB_fenv ); + hq_pred_hb_bws_fx( st_fx, ynrm, length, *hqswb_clas, SWB_fenv ); /* update */ hHQ_core->prev_hqswb_clas = *hqswb_clas; @@ -667,4 +667,4 @@ void hq_hr_dec_fx( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/hq_lr_dec.c b/lib_dec/hq_lr_dec.c index 302d0ba15..665d489f5 100644 --- a/lib_dec/hq_lr_dec.c +++ b/lib_dec/hq_lr_dec.c @@ -1411,4 +1411,4 @@ static void spt_shorten_domain_set_dec( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/hq_lr_dec_fx.c b/lib_dec/hq_lr_dec_fx.c index e233a420a..0a615b317 100644 --- a/lib_dec/hq_lr_dec_fx.c +++ b/lib_dec/hq_lr_dec_fx.c @@ -15,27 +15,24 @@ * Local function prototypes *--------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -static Word16 p2a_threshold_dequant_fx( Decoder_State *st_fx, Word16 *p2a_flags, const Word16 bands, const Word16 p2a_bands ); +static Word16 p2a_threshold_dequant_fx( Decoder_State *st_fx, Word16 *p2a_flags, const Word16 bands, const Word16 p2a_bands ); -static void mdct_spectrum_fine_gain_dec_fx( Decoder_State *st_fx, Word32 L_y2[], const Word16 band_start[], const Word16 band_end[], - const Word16 k_sort[], const Word16 bands, - const Word32 L_qint,const Word16 Ngq, const Word16 gqlevs, const Word16 gqbits ); +static void mdct_spectrum_fine_gain_dec_fx( Decoder_State *st_fx, Word32 L_y2[], const Word16 band_start[], const Word16 band_end[], const Word16 k_sort[], const Word16 bands, const Word32 L_qint, const Word16 Ngq, const Word16 gqlevs, const Word16 gqbits ); -static Word16 band_energy_dequant_fx( Decoder_State *st_fx, Word32 L_band_energy[], const Word16 bands, - const Word32 L_qint,const Word16 eref_fx, const Word16 is_transient_fx ); +static Word16 band_energy_dequant_fx( Decoder_State *st_fx, Word32 L_band_energy[], const Word16 bands, const Word32 L_qint, const Word16 eref_fx, const Word16 is_transient_fx ); -static Word16 Calc_inv(Word32 L_tmp, Word16 *exp) +static Word16 Calc_inv( Word32 L_tmp, Word16 *exp ) { Word16 exp2, tmp; - tmp = extract_h(L_tmp); + tmp = extract_h( L_tmp ); - IF(tmp != 0) + IF( tmp != 0 ) { - exp2 = norm_s(tmp); - tmp = shl(tmp,exp2);/*Q(exp) */ - tmp = div_s(16384,tmp);/*Q(15+14-exp=29-exp) */ - *exp = sub(29,exp2); + exp2 = norm_s( tmp ); + tmp = shl( tmp, exp2 ); /*Q(exp) */ + tmp = div_s( 16384, tmp ); /*Q(15+14-exp=29-exp) */ + *exp = sub( 29, exp2 ); move16(); } ELSE @@ -54,44 +51,44 @@ static Word16 Calc_inv(Word32 L_tmp, Word16 *exp) * update the shorten band information based on p2a analysis *--------------------------------------------------------------------------*/ -static void spt_shorten_domain_set_dec_fx( - Decoder_State *st_fx, /* i: encoder state structure */ - const Word16 p2a_flags[], /* i: p2a anlysis information */ - const Word16 new_band_start[], /* i: new band start position */ - const Word16 new_band_end[], /* i: new band end position */ - const Word16 new_band_width[], /* i: new subband band width */ - const Word16 bands, /* i: total number of subbands */ - Word16 band_start[], /* o: band start position */ - Word16 band_end[], /* o: band end position */ - Word16 band_width[], /* o: sub band band width */ - Word16 *bit_budget /* i/o: bit budget */ +static void spt_shorten_domain_set_dec_fx( + Decoder_State *st_fx, /* i: encoder state structure */ + const Word16 p2a_flags[], /* i: p2a anlysis information */ + const Word16 new_band_start[], /* i: new band start position */ + const Word16 new_band_end[], /* i: new band end position */ + const Word16 new_band_width[], /* i: new subband band width */ + const Word16 bands, /* i: total number of subbands */ + Word16 band_start[], /* o: band start position */ + Word16 band_end[], /* o: band end position */ + Word16 band_width[], /* o: sub band band width */ + Word16 *bit_budget /* i/o: bit budget */ ) { - Word16 j,k; + Word16 j, k; Word16 spt_shorten_flag[SPT_SHORTEN_SBNUM]; j = 0; move16(); - FOR( k = sub(bands,SPT_SHORTEN_SBNUM); k < bands; k++ ) + FOR( k = sub( bands, SPT_SHORTEN_SBNUM ); k < bands; k++ ) { spt_shorten_flag[j] = 0; move16(); - IF( EQ_16(p2a_flags[k], 1)) + IF( EQ_16( p2a_flags[k], 1 ) ) { - spt_shorten_flag[j] = get_next_indice (st_fx, 1 ); - *bit_budget = sub(*bit_budget, 1); - IF( EQ_16(spt_shorten_flag[j], 1)) + spt_shorten_flag[j] = get_next_indice( st_fx, 1 ); + *bit_budget = sub( *bit_budget, 1 ); + IF( EQ_16( spt_shorten_flag[j], 1 ) ) { band_start[k] = new_band_start[j]; move16(); - band_end[k] = new_band_end[j]; + band_end[k] = new_band_end[j]; move16(); band_width[k] = new_band_width[j]; move16(); } } - j = add(j, 1); + j = add( j, 1 ); } return; @@ -104,9 +101,9 @@ static void spt_shorten_domain_set_dec_fx( *-------------------------------------------------------------------*/ void hq_lr_dec_fx( - Decoder_State *st_fx, /* i/o: : decoder state structure */ + Decoder_State *st_fx, /* i/o: : decoder state structure */ Word32 L_yout[], /* o : Q12 : transform-domain output coefs. */ - const Word16 inner_frame, /* i : Q0 : inner frame length */ + const Word16 inner_frame, /* i : Q0 : inner frame length */ Word16 num_bits, /* i : Q0 : number of available bits */ Word16 *is_transient_fx /* o : Q0 : transient flag */ ) @@ -128,18 +125,18 @@ void hq_lr_dec_fx( Word32 L_bwe_br; Word16 prev_SWB_peak_pos_tmp_fx[SPT_SHORTEN_SBNUM]; - Word16 band_start[BANDS_MAX], band_end[BANDS_MAX], band_width[BANDS_MAX],trans_bit_fx; + Word16 band_start[BANDS_MAX], band_end[BANDS_MAX], band_width[BANDS_MAX], trans_bit_fx; /* hq2_core_configure */ Word32 L_qint; /*Word16 Qqint=29;*/ - Word16 eref_fx/*, Qeref=10*/; - Word16 bit_alloc_weight_fx/*, Qbaw=13*/; - Word16 ld_slope_fx/*, Qldslope=15*/; - Word16 p2a_th_fx/*, Qp2ath=11*/; - Word16 pd_thresh_fx/*, Qpdth=15*/; - Word16 ni_coef_fx/*, Qnicoef=14*/; + Word16 eref_fx /*, Qeref=10*/; + Word16 bit_alloc_weight_fx /*, Qbaw=13*/; + Word16 ld_slope_fx /*, Qldslope=15*/; + Word16 p2a_th_fx /*, Qp2ath=11*/; + Word16 pd_thresh_fx /*, Qpdth=15*/; + Word16 ni_coef_fx /*, Qnicoef=14*/; Word32 L_Rk[BANDS_MAX]; Word16 bit_budget_fx; @@ -163,9 +160,9 @@ void hq_lr_dec_fx( Word16 k_sort_fx[BANDS_MAX]; Word16 last_bitalloc_max_band[2]; Word32 L_tmp; - Word16 lowband,highband,p2a_flags_tmp[BANDS_MAX]; - Word32 L_tmp2,L_tmp3; - Word16 exp,exp2,tmp,tmp1,tmp2,tmp3,frac1,alpha_fx,Q_band_energy; + Word16 lowband, highband, p2a_flags_tmp[BANDS_MAX]; + Word32 L_tmp2, L_tmp3; + Word16 exp, exp2, tmp, tmp1, tmp2, tmp3, frac1, alpha_fx, Q_band_energy; Word32 enerH_fx; Word32 enerL_fx; Word32 Ep_fx[BANDS_MAX]; @@ -173,44 +170,44 @@ void hq_lr_dec_fx( Word32 Ep_avrgL_fx; Word32 Ep_peak_fx; Word32 Ep_tmp_fx[BANDS_MAX]; - Word16 gama_fx;/*Q15 0.85f;// */ - Word16 beta_fx;/*Q14 1.05f; */ + Word16 gama_fx; /*Q15 0.85f;// */ + Word16 beta_fx; /*Q14 1.05f; */ Word16 adjustFlag; Word16 bw_low, bw_high; HQ_DEC_HANDLE hHQ_core = st_fx->hHQ_core; - tmp2 = 0; /* to avoid compilation flags */ + tmp2 = 0; /* to avoid compilation flags */ - set16_fx(last_bitalloc_max_band, 0, 2); + set16_fx( last_bitalloc_max_band, 0, 2 ); set32_fx( L_y2, 0x0L, L_FRAME48k ); set16_fx( inp_vector_fx, 0, inner_frame ); flag_spt_fx = 0; move16(); - set16_fx(prev_SWB_peak_pos_tmp_fx, 0, SPT_SHORTEN_SBNUM); + set16_fx( prev_SWB_peak_pos_tmp_fx, 0, SPT_SHORTEN_SBNUM ); adjustFlag = 0; move16(); bw_low = 0; move16(); bw_high = 20; move16(); - enerL_fx = L_deposit_l(0); - enerH_fx = L_deposit_l(0); + enerL_fx = L_deposit_l( 0 ); + enerH_fx = L_deposit_l( 0 ); - L_bwe_br = L_add(st_fx->core_brate, 0); + L_bwe_br = L_add( st_fx->core_brate, 0 ); hqswb_clas_fx = 0; move16(); test(); test(); - IF( EQ_16(st_fx->bwidth, SWB)&&(EQ_32(L_bwe_br,HQ_16k40)||EQ_32(L_bwe_br,HQ_13k20))) + IF( EQ_16( st_fx->bwidth, SWB ) && ( EQ_32( L_bwe_br, HQ_16k40 ) || EQ_32( L_bwe_br, HQ_13k20 ) ) ) { - hqswb_clas_fx = get_next_indice(st_fx, 2); - num_bits = sub(num_bits, 2); + hqswb_clas_fx = get_next_indice( st_fx, 2 ); + num_bits = sub( num_bits, 2 ); *is_transient_fx = 0; move16(); - if ( EQ_16(hqswb_clas_fx, HQ_TRANSIENT)) + if ( EQ_16( hqswb_clas_fx, HQ_TRANSIENT ) ) { *is_transient_fx = 1; move16(); @@ -219,16 +216,15 @@ void hq_lr_dec_fx( ELSE { /* decode transient flag */ - *is_transient_fx = get_next_indice(st_fx, 1); - num_bits = sub(num_bits, 1); + *is_transient_fx = get_next_indice( st_fx, 1 ); + num_bits = sub( num_bits, 1 ); } /* Configure decoder for different bandwidths, bit rates, etc. */ hq2_core_configure_fx( inner_frame, num_bits, *is_transient_fx, &bands_fx, &length_fx, band_width, band_start, band_end, - &L_qint, &eref_fx, &bit_alloc_weight_fx, &gqlevs_fx, &Ngq_fx, &p2a_bands_fx, &p2a_th_fx, &pd_thresh_fx, &ld_slope_fx, &ni_coef_fx - ,L_bwe_br); + &L_qint, &eref_fx, &bit_alloc_weight_fx, &gqlevs_fx, &Ngq_fx, &p2a_bands_fx, &p2a_th_fx, &pd_thresh_fx, &ld_slope_fx, &ni_coef_fx, L_bwe_br ); - highlength_fx = band_end[bands_fx-1]; + highlength_fx = band_end[bands_fx - 1]; move16(); har_bands_fx = bands_fx; move16(); @@ -236,15 +232,15 @@ void hq_lr_dec_fx( test(); test(); test(); - IF( EQ_16(st_fx->bwidth, SWB)&&*is_transient_fx==0&&(EQ_32(L_bwe_br,HQ_16k40)||EQ_32(L_bwe_br,HQ_13k20))) + IF( EQ_16( st_fx->bwidth, SWB ) && *is_transient_fx == 0 && ( EQ_32( L_bwe_br, HQ_16k40 ) || EQ_32( L_bwe_br, HQ_13k20 ) ) ) { /* reserve bits for HQ_NORMAL2 and HQ_HARMONIC modes */ test(); - IF( EQ_16(hqswb_clas_fx, HQ_NORMAL)||EQ_16(hqswb_clas_fx,HQ_HARMONIC)) + IF( EQ_16( hqswb_clas_fx, HQ_NORMAL ) || EQ_16( hqswb_clas_fx, HQ_HARMONIC ) ) { - num_bits = sub(num_bits, get_usebit_npswb_fx(hqswb_clas_fx)); + num_bits = sub( num_bits, get_usebit_npswb_fx( hqswb_clas_fx ) ); } - if( EQ_16(hqswb_clas_fx, HQ_NORMAL)) + if ( EQ_16( hqswb_clas_fx, HQ_NORMAL ) ) { flag_spt_fx = 1; move16(); @@ -253,17 +249,17 @@ void hq_lr_dec_fx( test(); test(); - IF(( EQ_32(L_bwe_br, HQ_16k40)||EQ_32(L_bwe_br,HQ_13k20))&&EQ_16(st_fx->bwidth,SWB)) + IF( ( EQ_32( L_bwe_br, HQ_16k40 ) || EQ_32( L_bwe_br, HQ_13k20 ) ) && EQ_16( st_fx->bwidth, SWB ) ) { - IF( NE_16(hHQ_core->prev_hqswb_clas, HQ_NORMAL)) + IF( NE_16( hHQ_core->prev_hqswb_clas, HQ_NORMAL ) ) { j = 0; move16(); - FOR(k=sub(bands_fx,SPT_SHORTEN_SBNUM); kprev_SWB_peak_pos_fx[j] = 0; move16(); - j = add(j, 1); + j = add( j, 1 ); } } } @@ -272,11 +268,11 @@ void hq_lr_dec_fx( ebits_fx = band_energy_dequant_fx( st_fx, L_band_energy, bands_fx, L_qint, eref_fx, *is_transient_fx ); /* simple check: band_energy is too large, Abnormal Situation of bit errors */ - FOR( k=0; kBER_detect = 1; move16(); @@ -286,28 +282,28 @@ void hq_lr_dec_fx( } /* First pass bit budget for TCQ of spectral band information */ - exp_norm = norm_s(gqlevs_fx); - gqbits_fx = sub(14, exp_norm); + exp_norm = norm_s( gqlevs_fx ); + gqbits_fx = sub( 14, exp_norm ); - bit_budget_fx = sub(sub(num_bits, ebits_fx), round_fx(L_shl(L_mult(Ngq_fx, gqbits_fx), 15))); /* (*num_bits) - (short) ceil (ebits) - Ngq * gqbits; */ + bit_budget_fx = sub( sub( num_bits, ebits_fx ), round_fx( L_shl( L_mult( Ngq_fx, gqbits_fx ), 15 ) ) ); /* (*num_bits) - (short) ceil (ebits) - Ngq * gqbits; */ pbits_fx = 0; move16(); test(); test(); - IF( EQ_16(st_fx->bwidth, SWB)&&(EQ_32(L_bwe_br,HQ_16k40)||EQ_32(L_bwe_br,HQ_13k20))) + IF( EQ_16( st_fx->bwidth, SWB ) && ( EQ_32( L_bwe_br, HQ_16k40 ) || EQ_32( L_bwe_br, HQ_13k20 ) ) ) { - IF ( EQ_16(hqswb_clas_fx, HQ_HARMONIC)) + IF( EQ_16( hqswb_clas_fx, HQ_HARMONIC ) ) { set16_fx( p2a_flags_fx, 1, har_bands_fx ); } ELSE { pbits_fx = p2a_threshold_dequant_fx( st_fx, p2a_flags_fx, bands_fx, p2a_bands_fx ); - bit_budget_fx = sub(bit_budget_fx, pbits_fx); + bit_budget_fx = sub( bit_budget_fx, pbits_fx ); - IF( EQ_16(hqswb_clas_fx, HQ_NORMAL)) + IF( EQ_16( hqswb_clas_fx, HQ_NORMAL ) ) { return_bits_normal2_fx( &bit_budget_fx, p2a_flags_fx, bands_fx, bits_lagIndices_modeNormal ); } @@ -316,19 +312,19 @@ void hq_lr_dec_fx( ELSE { pbits_fx = p2a_threshold_dequant_fx( st_fx, p2a_flags_fx, bands_fx, p2a_bands_fx ); - bit_budget_fx = sub(bit_budget_fx, pbits_fx); + bit_budget_fx = sub( bit_budget_fx, pbits_fx ); } - IF( EQ_16(flag_spt_fx, 1)) + IF( EQ_16( flag_spt_fx, 1 ) ) { /* initialize the desired parameters for SPT */ - spt_shorten_domain_band_save_fx(bands_fx, band_start, band_end, band_width, org_band_start, org_band_end, org_band_width); - spt_shorten_domain_pre_fx(band_start, band_end, hHQ_core->prev_SWB_peak_pos_fx, bands_fx, L_bwe_br, new_band_start, new_band_end, new_band_width); - spt_shorten_domain_set_dec_fx(st_fx, p2a_flags_fx, new_band_start, new_band_end, new_band_width, bands_fx, band_start, band_end, band_width, &bit_budget_fx); + spt_shorten_domain_band_save_fx( bands_fx, band_start, band_end, band_width, org_band_start, org_band_end, org_band_width ); + spt_shorten_domain_pre_fx( band_start, band_end, hHQ_core->prev_SWB_peak_pos_fx, bands_fx, L_bwe_br, new_band_start, new_band_end, new_band_width ); + spt_shorten_domain_set_dec_fx( st_fx, p2a_flags_fx, new_band_start, new_band_end, new_band_width, bands_fx, band_start, band_end, band_width, &bit_budget_fx ); } /* safety check in case of bit errors */ - IF( LT_16(bit_budget_fx, 2)) + IF( LT_16( bit_budget_fx, 2 ) ) { st_fx->BER_detect = 1; move16(); @@ -337,46 +333,47 @@ void hq_lr_dec_fx( } Q_band_energy = SWB_BWE_LR_Qbe; - FOR(i = 0; i < bands_fx; i++) + FOR( i = 0; i < bands_fx; i++ ) { - L_tmp = L_shl(L_band_energy[i],sub(16,Q_band_energy));/*Q16 */ + L_tmp = L_shl( L_band_energy[i], sub( 16, Q_band_energy ) ); /*Q16 */ - frac1 = L_Extract_lc(L_tmp, &exp); /* Extract exponent of L_tmp */ - L_tmp = Pow2(30, frac1); - exp = sub(exp, 30); + frac1 = L_Extract_lc( L_tmp, &exp ); /* Extract exponent of L_tmp */ + L_tmp = Pow2( 30, frac1 ); + exp = sub( exp, 30 ); #ifdef BASOP_NOGLOB Ep_fx[i] = L_shl_sat( L_tmp, s_max( sub( exp, 6 ), -31 ) ); /* Q -6 */ #else - Ep_fx[i] = L_shl(L_tmp , s_max(sub(exp,6), -31)); /* Q -6 */ + Ep_fx[i] = L_shl( L_tmp, s_max( sub( exp, 6 ), -31 ) ); /* Q -6 */ #endif } FOR( i = 0; i < bands_fx; i++ ) { L_tmp2 = Ep_fx[i]; - L_tmp = L_max(1, L_tmp2); - exp = norm_l(L_tmp); - tmp = extract_h(L_shl(L_tmp, exp)); + L_tmp = L_max( 1, L_tmp2 ); + exp = norm_l( L_tmp ); + tmp = extract_h( L_shl( L_tmp, exp ) ); - L_tmp3 = (Word32)band_width[i]; - exp2 = norm_l(L_tmp3); - tmp2 = extract_h(L_shl(L_tmp3, exp2)); + L_tmp3 = (Word32) band_width[i]; + exp2 = norm_l( L_tmp3 ); + tmp2 = extract_h( L_shl( L_tmp3, exp2 ) ); - exp2 = sub(exp, exp2); /* Denormalize and substract */ + exp2 = sub( exp, exp2 ); /* Denormalize and substract */ - tmp3 = sub(tmp2, tmp); - if (tmp3 > 0) + tmp3 = sub( tmp2, tmp ); + if ( tmp3 > 0 ) { - tmp2 = shr(tmp2, 1); + tmp2 = shr( tmp2, 1 ); } - if (tmp3 > 0) + if ( tmp3 > 0 ) { - exp2 = add(exp2, 1); + exp2 = add( exp2, 1 ); } - tmp = div_s(tmp2, tmp); - L_tmp = L_deposit_h(tmp); - L_tmp = Isqrt_lc(L_tmp, &exp2);/*Q(31-exp2) */ - Ep_tmp_fx[i] = L_shr(L_tmp,sub(15,exp2));/*Q13 */ move32(); + tmp = div_s( tmp2, tmp ); + L_tmp = L_deposit_h( tmp ); + L_tmp = Isqrt_lc( L_tmp, &exp2 ); /*Q(31-exp2) */ + Ep_tmp_fx[i] = L_shr( L_tmp, sub( 15, exp2 ) ); /*Q13 */ + move32(); } test(); @@ -385,11 +382,11 @@ void hq_lr_dec_fx( test(); test(); test(); - IF ( *is_transient_fx == 0 && EQ_16(inner_frame, L_FRAME8k)&&LE_32(st_fx->core_brate,ACELP_13k20)) + IF( *is_transient_fx == 0 && EQ_16( inner_frame, L_FRAME8k ) && LE_32( st_fx->core_brate, ACELP_13k20 ) ) { /* decode the last p2a_bands-1 subbands bit-allocation index of the previous frame */ j = 0; - FOR(i = 0; i < 2; i++) + FOR( i = 0; i < 2; i++ ) { last_bitalloc_max_band[i] = get_next_indice( st_fx, 1 ); } @@ -397,38 +394,38 @@ void hq_lr_dec_fx( move16(); trans_bit_fx = 2; move16(); - bit_budget_fx = sub(bit_budget_fx,trans_bit_fx); + bit_budget_fx = sub( bit_budget_fx, trans_bit_fx ); gama_fx = 27852; move16(); /*Q15 0.85f; */ beta_fx = 17203; move16(); /*Q14 1.05f; */ - set16_fx(&p2a_flags_tmp[sub(bands_fx,trans_bit_fx)], 0, 2); + set16_fx( &p2a_flags_tmp[sub( bands_fx, trans_bit_fx )], 0, 2 ); - IF( EQ_32(st_fx->core_brate, ACELP_13k20)) + IF( EQ_32( st_fx->core_brate, ACELP_13k20 ) ) { beta_fx = 13107; - move16();/*14 1.25f; */ + move16(); /*14 1.25f; */ gama_fx = 31130; - move16();/*0.95f; */ - Copy(&p2a_flags_fx[sub(bands_fx,trans_bit_fx)], &p2a_flags_tmp[sub(bands_fx,trans_bit_fx)], trans_bit_fx); + move16(); /*0.95f; */ + Copy( &p2a_flags_fx[sub( bands_fx, trans_bit_fx )], &p2a_flags_tmp[sub( bands_fx, trans_bit_fx )], trans_bit_fx ); } /* calculate the the low band/high band energy and the variance/avrage of the envelopes */ - Ep_vari_fx = L_deposit_l(0); - Ep_avrg_fx = L_deposit_l(0); - Ep_avrgL_fx = L_deposit_l(0); - Ep_peak_fx = L_deposit_l(0); + Ep_vari_fx = L_deposit_l( 0 ); + Ep_avrg_fx = L_deposit_l( 0 ); + Ep_avrgL_fx = L_deposit_l( 0 ); + Ep_peak_fx = L_deposit_l( 0 ); FOR( i = 0; i < bands_fx; i++ ) { - IF( GE_16(i,lowband)) + IF( GE_16( i, lowband ) ) { #ifdef BASOP_NOGLOB Ep_vari_fx = L_add_sat( Ep_vari_fx, L_abs( L_sub_sat( Ep_tmp_fx[i], Ep_tmp_fx[sub( i, 1 )] ) ) ); /*Q15 */ - Ep_avrg_fx = L_add_sat(Ep_avrg_fx,Ep_tmp_fx[i]);/*Q15 */ + Ep_avrg_fx = L_add_sat( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ #else - Ep_vari_fx = L_add(Ep_vari_fx,L_abs(L_sub(Ep_tmp_fx[i],Ep_tmp_fx[sub(i,1)])));/*Q15 */ - Ep_avrg_fx = L_add(Ep_avrg_fx,Ep_tmp_fx[i]);/*Q15 */ + Ep_vari_fx = L_add( Ep_vari_fx, L_abs( L_sub( Ep_tmp_fx[i], Ep_tmp_fx[sub( i, 1 )] ) ) ); /*Q15 */ + Ep_avrg_fx = L_add( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ #endif } ELSE @@ -436,62 +433,62 @@ void hq_lr_dec_fx( #ifdef BASOP_NOGLOB Ep_avrgL_fx = L_add_sat( Ep_avrgL_fx, Ep_tmp_fx[i] ); /*Q15 */ #else - Ep_avrgL_fx = L_add(Ep_avrgL_fx,Ep_tmp_fx[i]);/*Q15 */ + Ep_avrgL_fx = L_add( Ep_avrgL_fx, Ep_tmp_fx[i] ); /*Q15 */ #endif - if(GT_32(Ep_tmp_fx[i],Ep_peak_fx)) + if ( GT_32( Ep_tmp_fx[i], Ep_peak_fx ) ) { - Ep_peak_fx = L_add(Ep_tmp_fx[i], 0); /*Q15 */ + Ep_peak_fx = L_add( Ep_tmp_fx[i], 0 ); /*Q15 */ } } - } /* modify the last p2a_bands subbands band_energies */ - Copy32( L_band_energy,L_band_energy_tmp,bands_fx ); /*Q_band_energy */ - L_tmp = Mult_32_16(Ep_peak_fx,24576);/*Q(13+14-15 = 12) 1.5 lowband = 6; */ - L_tmp2 =Mult_32_16(Ep_peak_fx,shl(sub(bands_fx,lowband),9));/*Q(13+9-15 = 7) */ - L_tmp3 =Mult_32_16(Ep_avrg_fx,1126);/*Q(13+9-15 = 7) */ + Copy32( L_band_energy, L_band_energy_tmp, bands_fx ); /*Q_band_energy */ + L_tmp = Mult_32_16( Ep_peak_fx, 24576 ); /*Q(13+14-15 = 12) 1.5 lowband = 6; */ + L_tmp2 = Mult_32_16( Ep_peak_fx, shl( sub( bands_fx, lowband ), 9 ) ); /*Q(13+9-15 = 7) */ + L_tmp3 = Mult_32_16( Ep_avrg_fx, 1126 ); /*Q(13+9-15 = 7) */ test(); test(); test(); test(); - IF(( (LT_32(L_tmp, L_shr(Ep_avrgL_fx,1))&&EQ_32(st_fx->core_brate,ACELP_13k20))||LT_32(st_fx->core_brate,ACELP_13k20))&& - LT_32(L_tmp2, L_tmp3) && GT_32(L_tmp2, L_shr(Ep_avrg_fx,7)) ) + IF( ( ( LT_32( L_tmp, L_shr( Ep_avrgL_fx, 1 ) ) && EQ_32( st_fx->core_brate, ACELP_13k20 ) ) || LT_32( st_fx->core_brate, ACELP_13k20 ) ) && + LT_32( L_tmp2, L_tmp3 ) && GT_32( L_tmp2, L_shr( Ep_avrg_fx, 7 ) ) ) { - FOR(i = lowband; i < bands_fx; i++) + FOR( i = lowband; i < bands_fx; i++ ) { - L_tmp = Mult_32_16(Ep_avrg_fx,24576);/*Q(13+14-15 = 12) 1.5 */ - IF(LT_32(L_shr(Ep_tmp_fx[i],1), L_tmp)) + L_tmp = Mult_32_16( Ep_avrg_fx, 24576 ); /*Q(13+14-15 = 12) 1.5 */ + IF( LT_32( L_shr( Ep_tmp_fx[i], 1 ), L_tmp ) ) { - L_tmp = Mult_32_16(Ep_peak_fx,sub(bands_fx,lowband));/*Q(13+0-15 = -2) */ - tmp = Calc_inv(L_shl(L_tmp,14), &exp); - L_tmp = L_shl(Mult_32_16(Ep_avrg_fx,tmp),sub(13,exp));/*Q(13+exp-15 +13-exp +4 = 15) */ - L_tmp2 = L_add(L_tmp,13107); /*15 */ - tmp2 = extract_l(L_min(L_max(L_tmp2,16384),gama_fx)); /*15 = 15 */ - L_band_energy_tmp[i] = Mult_32_16(L_band_energy_tmp[i],tmp2);/*Q(Q_band_energy+15-15 = Q_band_energy) */ move32(); + L_tmp = Mult_32_16( Ep_peak_fx, sub( bands_fx, lowband ) ); /*Q(13+0-15 = -2) */ + tmp = Calc_inv( L_shl( L_tmp, 14 ), &exp ); + L_tmp = L_shl( Mult_32_16( Ep_avrg_fx, tmp ), sub( 13, exp ) ); /*Q(13+exp-15 +13-exp +4 = 15) */ + L_tmp2 = L_add( L_tmp, 13107 ); /*15 */ + tmp2 = extract_l( L_min( L_max( L_tmp2, 16384 ), gama_fx ) ); /*15 = 15 */ + L_band_energy_tmp[i] = Mult_32_16( L_band_energy_tmp[i], tmp2 ); /*Q(Q_band_energy+15-15 = Q_band_energy) */ + move32(); } } } ELSE { - FOR(i = sub(bands_fx,trans_bit_fx); i < bands_fx; i++) + FOR( i = sub( bands_fx, trans_bit_fx ); i < bands_fx; i++ ) { alpha_fx = 16384; - move16();/*Q14 */ - IF( EQ_16(p2a_flags_tmp[i],1)) + move16(); /*Q14 */ + IF( EQ_16( p2a_flags_tmp[i], 1 ) ) { - L_tmp = Mult_32_16(Ep_tmp_fx[i],sub(bands_fx,lowband));/*Q(13+0-15 = -2) */ - tmp = Calc_inv(L_shl(L_tmp,14), &exp); - L_tmp =Mult_32_16(Ep_vari_fx,3277);/*13+15-15=13 */ - L_tmp = L_shl(Mult_32_16(L_tmp,tmp),sub(12,exp));/*Q(13+exp-15 +12-exp +4 = 14) */ + L_tmp = Mult_32_16( Ep_tmp_fx[i], sub( bands_fx, lowband ) ); /*Q(13+0-15 = -2) */ + tmp = Calc_inv( L_shl( L_tmp, 14 ), &exp ); + L_tmp = Mult_32_16( Ep_vari_fx, 3277 ); /*13+15-15=13 */ + L_tmp = L_shl( Mult_32_16( L_tmp, tmp ), sub( 12, exp ) ); /*Q(13+exp-15 +12-exp +4 = 14) */ - tmp2 = extract_h(Ep_avrg_fx);/*Q13-16=-3 */ - IF(tmp2 != 0) + tmp2 = extract_h( Ep_avrg_fx ); /*Q13-16=-3 */ + IF( tmp2 != 0 ) { - exp = norm_s(tmp2); - tmp2 = shl(tmp2,exp);/*Q(exp) */ - tmp2 = div_s(16384,tmp2);/*Q(15+14-exp=29-exp) */ - exp = sub(29,exp); + exp = norm_s( tmp2 ); + tmp2 = shl( tmp2, exp ); /*Q(exp) */ + tmp2 = div_s( 16384, tmp2 ); /*Q(15+14-exp=29-exp) */ + exp = sub( 29, exp ); } ELSE { @@ -501,36 +498,35 @@ void hq_lr_dec_fx( exp = 0; move16(); } - L_tmp2 =Mult_32_16(Ep_vari_fx,6554);/*13+15-15=13 */ - L_tmp2 = L_shl(Mult_32_16(L_tmp2,tmp2),sub(13,exp));/*Q(13+exp-15 +13-exp +3 = 14) */ - L_tmp=L_min(L_tmp,L_tmp2);/*14 */ - tmp=extract_l(L_min(L_tmp,13107));/*14 */ - alpha_fx =add(16384,tmp); - + L_tmp2 = Mult_32_16( Ep_vari_fx, 6554 ); /*13+15-15=13 */ + L_tmp2 = L_shl( Mult_32_16( L_tmp2, tmp2 ), sub( 13, exp ) ); /*Q(13+exp-15 +13-exp +3 = 14) */ + L_tmp = L_min( L_tmp, L_tmp2 ); /*14 */ + tmp = extract_l( L_min( L_tmp, 13107 ) ); /*14 */ + alpha_fx = add( 16384, tmp ); } - IF(EQ_16(last_bitalloc_max_band[j++], 1)) + IF( EQ_16( last_bitalloc_max_band[j++], 1 ) ) { - L_tmp = Mult_32_16(Ep_tmp_fx[i],sub(bands_fx,lowband));/*Q(13+0-15 = -2) */ + L_tmp = Mult_32_16( Ep_tmp_fx[i], sub( bands_fx, lowband ) ); /*Q(13+0-15 = -2) */ #ifdef BASOP_NOGLOB tmp = Calc_inv( L_shl_sat( L_tmp, 14 ), &exp ); - L_tmp = L_shl_sat(Mult_32_16(Ep_avrg_fx, tmp), sub(14, exp));/*Q(13+exp-15 +14-exp+2 = 14) */ + L_tmp = L_shl_sat( Mult_32_16( Ep_avrg_fx, tmp ), sub( 14, exp ) ); /*Q(13+exp-15 +14-exp+2 = 14) */ #else tmp = Calc_inv( L_shl( L_tmp, 14 ), &exp ); - L_tmp = L_shl(Mult_32_16(Ep_avrg_fx,tmp),sub(14,exp));/*Q(13+exp-15 +14-exp+2 = 14) */ + L_tmp = L_shl( Mult_32_16( Ep_avrg_fx, tmp ), sub( 14, exp ) ); /*Q(13+exp-15 +14-exp+2 = 14) */ #endif - L_tmp =L_max(L_tmp,16384); /*14 */ - tmp=extract_l(L_min(L_tmp,beta_fx)); /*14 */ - alpha_fx=shl(mult(alpha_fx,tmp),1);/*14+14-15 +1=14 */ + L_tmp = L_max( L_tmp, 16384 ); /*14 */ + tmp = extract_l( L_min( L_tmp, beta_fx ) ); /*14 */ + alpha_fx = shl( mult( alpha_fx, tmp ), 1 ); /*14+14-15 +1=14 */ } ELSE { - tmp2 = extract_h(Ep_avrg_fx);/*13 -16 =-3 */ - IF(tmp2 != 0) + tmp2 = extract_h( Ep_avrg_fx ); /*13 -16 =-3 */ + IF( tmp2 != 0 ) { - exp = norm_s(tmp2); - tmp2 = shl(tmp2,exp);/*Q(exp) */ - tmp2 = div_s(16384,tmp2);/*Q(15+14-exp=29-exp) */ - exp = sub(29,exp); + exp = norm_s( tmp2 ); + tmp2 = shl( tmp2, exp ); /*Q(exp) */ + tmp2 = div_s( 16384, tmp2 ); /*Q(15+14-exp=29-exp) */ + exp = sub( 29, exp ); } ELSE { @@ -540,68 +536,70 @@ void hq_lr_dec_fx( exp = 0; move16(); } - L_tmp = L_shl(Mult_32_16(Ep_tmp_fx[i],tmp2),sub(19,exp));/*Q(13+exp-15 +19-exp +3 = 20) */ - L_tmp = Mult_32_16(L_tmp,shl(sub(bands_fx,lowband),9));/*20 +9 -15 =14 */ - L_tmp =L_max(L_tmp,13926); /*14 */ - tmp2 =extract_l(L_min(L_tmp,16384)); /*14 */ - alpha_fx=shl(mult(alpha_fx,tmp2),1);/*14+14-15+1 =14 */ + L_tmp = L_shl( Mult_32_16( Ep_tmp_fx[i], tmp2 ), sub( 19, exp ) ); /*Q(13+exp-15 +19-exp +3 = 20) */ + L_tmp = Mult_32_16( L_tmp, shl( sub( bands_fx, lowband ), 9 ) ); /*20 +9 -15 =14 */ + L_tmp = L_max( L_tmp, 13926 ); /*14 */ + tmp2 = extract_l( L_min( L_tmp, 16384 ) ); /*14 */ + alpha_fx = shl( mult( alpha_fx, tmp2 ), 1 ); /*14+14-15+1 =14 */ } - L_band_energy_tmp[i] = L_shl(Mult_32_16(L_band_energy_tmp[i],alpha_fx),1);/*Q(Q_band_energy+14-15 +1= Q_band_energy) */ move32(); + L_band_energy_tmp[i] = L_shl( Mult_32_16( L_band_energy_tmp[i], alpha_fx ), 1 ); /*Q(Q_band_energy+14-15 +1= Q_band_energy) */ + move32(); } } lowband = 3; move16(); - Ep_avrg_fx = L_deposit_l(0); - Ep_avrgL_fx = L_deposit_l(0); - Ep_peak_fx = L_deposit_l(0); - FOR(i = 0; i < bands_fx; i++) + Ep_avrg_fx = L_deposit_l( 0 ); + Ep_avrgL_fx = L_deposit_l( 0 ); + Ep_peak_fx = L_deposit_l( 0 ); + FOR( i = 0; i < bands_fx; i++ ) { - IF(GE_16(i,lowband)) + IF( GE_16( i, lowband ) ) { #ifdef BASOP_NOGLOB Ep_avrg_fx = L_add_sat( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ #else - Ep_avrg_fx = L_add(Ep_avrg_fx,Ep_tmp_fx[i]);/*Q15 */ + Ep_avrg_fx = L_add( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ #endif } ELSE { - Ep_avrgL_fx = L_add(Ep_avrgL_fx,L_shr(Ep_tmp_fx[i],1));/*Q12 */ - if(GT_32(Ep_tmp_fx[i],Ep_peak_fx)) + Ep_avrgL_fx = L_add( Ep_avrgL_fx, L_shr( Ep_tmp_fx[i], 1 ) ); /*Q12 */ + if ( GT_32( Ep_tmp_fx[i], Ep_peak_fx ) ) { - Ep_peak_fx = L_add(Ep_tmp_fx[i], 0); /*Q13 */ + Ep_peak_fx = L_add( Ep_tmp_fx[i], 0 ); /*Q13 */ } } } - L_tmp = Mult_32_16(Ep_peak_fx,28262);/*Q(13+14-15 = 12) 1.725 lowband = 3; */ - L_tmp2 =Mult_32_16(Ep_avrgL_fx,24576);/*Q(12+14-15 = 11) */ + L_tmp = Mult_32_16( Ep_peak_fx, 28262 ); /*Q(13+14-15 = 12) 1.725 lowband = 3; */ + L_tmp2 = Mult_32_16( Ep_avrgL_fx, 24576 ); /*Q(12+14-15 = 11) */ test(); test(); - IF( GT_32(L_shr(Ep_avrg_fx,2), L_tmp2)&<_32(L_shr(Ep_avrg_fx,4),L_tmp2)&>_32(L_tmp,Ep_avrgL_fx)) + IF( GT_32( L_shr( Ep_avrg_fx, 2 ), L_tmp2 ) && LT_32( L_shr( Ep_avrg_fx, 4 ), L_tmp2 ) && GT_32( L_tmp, Ep_avrgL_fx ) ) { adjustFlag = 1; move16(); - FOR (i = 0; i < lowband; i++) + FOR( i = 0; i < lowband; i++ ) { - tmp = Calc_inv(Ep_avrgL_fx, &exp); - L_tmp = Mult_32_16(Ep_peak_fx,tmp);/*Q(13+exp-15+4 = exp+2) */ - L_tmp = Mult_32_16(L_tmp,lowband);/*Q(exp+2+0-15 = exp-13) */ - L_tmp = Mult_32_16(L_tmp,18842);/*Q(exp-13+16-16 = exp-13) */ - L_tmp = L_shl(L_tmp,sub(27,exp));/*Q14 0.5 */ - tmp2=extract_l(L_min(L_tmp,19661));/*14 */ - L_tmp = Mult_32_16(L_band_energy_tmp[i],tmp2);/*Q(Q_band_energy+14-15 = Q_band_energy-1) */ - L_band_energy_tmp[i] = L_shl(L_tmp,1); /*Q_band_energy */ move32(); + tmp = Calc_inv( Ep_avrgL_fx, &exp ); + L_tmp = Mult_32_16( Ep_peak_fx, tmp ); /*Q(13+exp-15+4 = exp+2) */ + L_tmp = Mult_32_16( L_tmp, lowband ); /*Q(exp+2+0-15 = exp-13) */ + L_tmp = Mult_32_16( L_tmp, 18842 ); /*Q(exp-13+16-16 = exp-13) */ + L_tmp = L_shl( L_tmp, sub( 27, exp ) ); /*Q14 0.5 */ + tmp2 = extract_l( L_min( L_tmp, 19661 ) ); /*14 */ + L_tmp = Mult_32_16( L_band_energy_tmp[i], tmp2 ); /*Q(Q_band_energy+14-15 = Q_band_energy-1) */ + L_band_energy_tmp[i] = L_shl( L_tmp, 1 ); /*Q_band_energy */ + move32(); } } hq2_bit_alloc_fx( L_band_energy_tmp, bands_fx, L_Rk, &bit_budget_fx, p2a_flags_fx, bit_alloc_weight_fx, band_width, num_bits, hqswb_clas_fx, st_fx->bwidth, *is_transient_fx ); } - ELSE IF( *is_transient_fx == 0 && EQ_16(inner_frame, L_FRAME16k)) + ELSE IF( *is_transient_fx == 0 && EQ_16( inner_frame, L_FRAME16k ) ) { - bit_budget_fx = sub(bit_budget_fx,2);/* bits in high bands to indicate the last 2 subbands is allocated bits or not */ + bit_budget_fx = sub( bit_budget_fx, 2 ); /* bits in high bands to indicate the last 2 subbands is allocated bits or not */ - FOR(i = 0; i < 2; i++) + FOR( i = 0; i < 2; i++ ) { last_bitalloc_max_band[i] = get_next_indice( st_fx, 1 ); move16(); @@ -609,20 +607,20 @@ void hq_lr_dec_fx( FOR( i = 0; i < bands_fx; i++ ) { #ifdef BASOP_NOGLOB - Ep_tmp_fx[i] = L_shl_sat(Ep_tmp_fx[i],2); + Ep_tmp_fx[i] = L_shl_sat( Ep_tmp_fx[i], 2 ); #else - Ep_tmp_fx[i] = L_shl(Ep_tmp_fx[i],2); + Ep_tmp_fx[i] = L_shl( Ep_tmp_fx[i], 2 ); #endif move32(); } - IF( EQ_32( st_fx->core_brate, ACELP_13k20 )) + IF( EQ_32( st_fx->core_brate, ACELP_13k20 ) ) { lowband = 8; move16(); highband = 15; move16(); - bw_low = sub(band_start[highband],band_start[lowband]); - bw_high = sub(add(band_end[sub(bands_fx,1)],1),band_start[highband]); + bw_low = sub( band_start[highband], band_start[lowband] ); + bw_high = sub( add( band_end[sub( bands_fx, 1 )], 1 ), band_start[highband] ); } ELSE { @@ -630,74 +628,74 @@ void hq_lr_dec_fx( move16(); highband = 16; move16(); - bw_low = sub(band_start[highband],band_start[lowband]); - bw_high = sub(add(band_end[sub(bands_fx,1)],1),band_start[highband]); + bw_low = sub( band_start[highband], band_start[lowband] ); + bw_high = sub( add( band_end[sub( bands_fx, 1 )], 1 ), band_start[highband] ); } /* calculate the the low band/high band energy and the variance/avrage of the envelopes */ - enerL_fx = L_deposit_l(0); - enerH_fx = L_deposit_l(0); - Ep_vari_fx = L_deposit_l(0); - Ep_avrg_fx = L_deposit_l(0); + enerL_fx = L_deposit_l( 0 ); + enerH_fx = L_deposit_l( 0 ); + Ep_vari_fx = L_deposit_l( 0 ); + Ep_avrg_fx = L_deposit_l( 0 ); FOR( i = 0; i < bands_fx; i++ ) { test(); - IF( GE_16(i,lowband)&&add(sub(i,bands_fx),p2a_bands_fx)<0) + IF( GE_16( i, lowband ) && add( sub( i, bands_fx ), p2a_bands_fx ) < 0 ) { #ifdef BASOP_NOGLOB - Ep_vari_fx = L_add_sat(Ep_vari_fx, L_abs(L_sub(Ep_tmp_fx[i], Ep_tmp_fx[sub(i, 1)])));/*Q15 */ - Ep_avrg_fx = L_add_sat(Ep_avrg_fx,Ep_tmp_fx[i]);/*Q15 */ + Ep_vari_fx = L_add_sat( Ep_vari_fx, L_abs( L_sub( Ep_tmp_fx[i], Ep_tmp_fx[sub( i, 1 )] ) ) ); /*Q15 */ + Ep_avrg_fx = L_add_sat( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ #else - Ep_vari_fx = L_add(Ep_vari_fx, L_abs(L_sub(Ep_tmp_fx[i], Ep_tmp_fx[sub(i, 1)])));/*Q15 */ - Ep_avrg_fx = L_add(Ep_avrg_fx,Ep_tmp_fx[i]);/*Q15 */ + Ep_vari_fx = L_add( Ep_vari_fx, L_abs( L_sub( Ep_tmp_fx[i], Ep_tmp_fx[sub( i, 1 )] ) ) ); /*Q15 */ + Ep_avrg_fx = L_add( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ #endif } - IF(GE_16(i,highband)) + IF( GE_16( i, highband ) ) { #ifdef BASOP_NOGLOB - enerH_fx = L_add_sat(enerH_fx,L_shl_sat(Ep_fx[i],2));/*Q0 */ + enerH_fx = L_add_sat( enerH_fx, L_shl_sat( Ep_fx[i], 2 ) ); /*Q0 */ #else - enerH_fx = L_add(enerH_fx,L_shl(Ep_fx[i],2));/*Q0 */ + enerH_fx = L_add( enerH_fx, L_shl( Ep_fx[i], 2 ) ); /*Q0 */ #endif } - ELSE IF(GE_16(i,lowband)) + ELSE IF( GE_16( i, lowband ) ) { #ifdef BASOP_NOGLOB - enerL_fx = L_add_sat(enerL_fx,L_shl_sat(Ep_fx[i],2));/*Q0 */ + enerL_fx = L_add_sat( enerL_fx, L_shl_sat( Ep_fx[i], 2 ) ); /*Q0 */ #else - enerL_fx = L_add(enerL_fx,L_shl(Ep_fx[i],2));/*Q0 */ + enerL_fx = L_add( enerL_fx, L_shl( Ep_fx[i], 2 ) ); /*Q0 */ #endif } } /* modify the last p2a_bands subbands band_energies */ - Copy32( L_band_energy,L_band_energy_tmp,bands_fx ); /*Q_band_energy */ - L_tmp = L_max(enerH_fx,enerL_fx); - tmp = s_max(bw_low,bw_high); - i = norm_l(L_tmp); - j = norm_s(tmp); - L_tmp = Mult_32_16(L_shl(enerH_fx,i), shl(bw_low,j)); /* i + j -15 */ - L_tmp2 = Mult_32_16(L_shl(enerL_fx,i), shl(bw_high,j)); /*i + j -15 */ - L_tmp2 = L_sub(L_tmp,L_tmp2); - FOR( i = sub(bands_fx,p2a_bands_fx); i < bands_fx; i++ ) + Copy32( L_band_energy, L_band_energy_tmp, bands_fx ); /*Q_band_energy */ + L_tmp = L_max( enerH_fx, enerL_fx ); + tmp = s_max( bw_low, bw_high ); + i = norm_l( L_tmp ); + j = norm_s( tmp ); + L_tmp = Mult_32_16( L_shl( enerH_fx, i ), shl( bw_low, j ) ); /* i + j -15 */ + L_tmp2 = Mult_32_16( L_shl( enerL_fx, i ), shl( bw_high, j ) ); /*i + j -15 */ + L_tmp2 = L_sub( L_tmp, L_tmp2 ); + FOR( i = sub( bands_fx, p2a_bands_fx ); i < bands_fx; i++ ) { test(); - IF( EQ_16(p2a_flags_fx[i],1)||L_tmp2>0) + IF( EQ_16( p2a_flags_fx[i], 1 ) || L_tmp2 > 0 ) { - tmp = sub(bands_fx,p2a_bands_fx); - tmp = sub(tmp,lowband);/*Q0 */ + tmp = sub( bands_fx, p2a_bands_fx ); + tmp = sub( tmp, lowband ); /*Q0 */ #ifdef BASOP_NOGLOB tmp1 = extract_h( L_shl_sat( Ep_avrg_fx, 1 ) ); /*Q0 */ #else - tmp1 = extract_h( L_shl( Ep_avrg_fx, 1 ) ); /*Q0 */ + tmp1 = extract_h( L_shl( Ep_avrg_fx, 1 ) ); /*Q0 */ #endif - IF(tmp1 != 0) + IF( tmp1 != 0 ) { - exp = norm_s(tmp1); - tmp1 = shl(tmp1,exp);/*Q(exp) */ - tmp1 = div_s(16384,tmp1);/*Q(15+14-exp = 29-exp) */ - exp = sub(29,exp); + exp = norm_s( tmp1 ); + tmp1 = shl( tmp1, exp ); /*Q(exp) */ + tmp1 = div_s( 16384, tmp1 ); /*Q(15+14-exp = 29-exp) */ + exp = sub( 29, exp ); } ELSE { @@ -707,57 +705,57 @@ void hq_lr_dec_fx( exp = 0; move16(); } - L_tmp = Mult_32_16(Ep_tmp_fx[i],tmp1);/*Q(15+exp-15 = exp) */ - L_tmp = Mult_32_16(L_tmp,tmp);/*Q(exp+0-15 = exp-15) */ - L_tmp = Mult_32_16(L_tmp,16384);/*Q(exp-15+13-15 = exp-17) */ - L_tmp = L_shl(L_tmp,sub(32,exp));/*Q15 */ - tmp = extract_l(L_min(L_tmp,6554));/*Q15 */ - L_tmp = Mult_32_16(Ep_vari_fx,tmp1);/*Q(15+exp-15 = exp) */ - L_tmp = Mult_32_16(L_tmp,tmp);/*Q(exp+15-15 = exp) */ - L_tmp = L_shl(L_tmp,sub(15,exp));/*Q15 */ - tmp = extract_l(L_shr(L_min(L_tmp,13107),1));/*Q14 */ - - alpha_fx = add(tmp,16384);/*Q14 */ + L_tmp = Mult_32_16( Ep_tmp_fx[i], tmp1 ); /*Q(15+exp-15 = exp) */ + L_tmp = Mult_32_16( L_tmp, tmp ); /*Q(exp+0-15 = exp-15) */ + L_tmp = Mult_32_16( L_tmp, 16384 ); /*Q(exp-15+13-15 = exp-17) */ + L_tmp = L_shl( L_tmp, sub( 32, exp ) ); /*Q15 */ + tmp = extract_l( L_min( L_tmp, 6554 ) ); /*Q15 */ + L_tmp = Mult_32_16( Ep_vari_fx, tmp1 ); /*Q(15+exp-15 = exp) */ + L_tmp = Mult_32_16( L_tmp, tmp ); /*Q(exp+15-15 = exp) */ + L_tmp = L_shl( L_tmp, sub( 15, exp ) ); /*Q15 */ + tmp = extract_l( L_shr( L_min( L_tmp, 13107 ), 1 ) ); /*Q14 */ + + alpha_fx = add( tmp, 16384 ); /*Q14 */ } ELSE { alpha_fx = 16384; - move16();/*Q14 */ + move16(); /*Q14 */ } - IF(add(sub(i,bands_fx),p2a_bands_fx) > 0) + IF( add( sub( i, bands_fx ), p2a_bands_fx ) > 0 ) { - tmp = sub(bands_fx, p2a_bands_fx); - IF(EQ_16(last_bitalloc_max_band[sub(i, add(tmp, 1))], 1)) + tmp = sub( bands_fx, p2a_bands_fx ); + IF( EQ_16( last_bitalloc_max_band[sub( i, add( tmp, 1 ) )], 1 ) ) { - tmp = sub(tmp,lowband); - L_tmp = Mult_32_16(Ep_tmp_fx[i],tmp);/*Q(15+0-15 = 0) */ + tmp = sub( tmp, lowband ); + L_tmp = Mult_32_16( Ep_tmp_fx[i], tmp ); /*Q(15+0-15 = 0) */ #ifdef BASOP_NOGLOB - tmp = Calc_inv(L_shl_sat(L_tmp,16), &exp); + tmp = Calc_inv( L_shl_sat( L_tmp, 16 ), &exp ); #else - tmp = Calc_inv(L_shl(L_tmp,16), &exp); + tmp = Calc_inv( L_shl( L_tmp, 16 ), &exp ); #endif - L_tmp = Mult_32_16(Ep_avrg_fx,tmp);/*Q(15+exp-15 = exp) */ - L_tmp = L_shl(L_tmp,sub(14,exp));/*Q14 */ - tmp = extract_l(L_min(L_max(L_tmp,16384),20480));/*Q14 */ - L_tmp = L_mult(alpha_fx,tmp);/*Q(14+14+1=29) */ - alpha_fx = extract_l(L_shr(L_tmp,15)); /*Q14 */ + L_tmp = Mult_32_16( Ep_avrg_fx, tmp ); /*Q(15+exp-15 = exp) */ + L_tmp = L_shl( L_tmp, sub( 14, exp ) ); /*Q14 */ + tmp = extract_l( L_min( L_max( L_tmp, 16384 ), 20480 ) ); /*Q14 */ + L_tmp = L_mult( alpha_fx, tmp ); /*Q(14+14+1=29) */ + alpha_fx = extract_l( L_shr( L_tmp, 15 ) ); /*Q14 */ } ELSE { - tmp = sub(tmp,lowband); + tmp = sub( tmp, lowband ); #ifdef BASOP_NOGLOB tmp1 = extract_h( L_shl_sat( Ep_avrg_fx, 1 ) ); /*Q0 */ #else - tmp1 = extract_h( L_shl( Ep_avrg_fx, 1 ) ); /*Q0 */ + tmp1 = extract_h( L_shl( Ep_avrg_fx, 1 ) ); /*Q0 */ #endif - IF(tmp1 != 0) + IF( tmp1 != 0 ) { - exp = norm_s(tmp1); - tmp1 = shl(tmp1,exp);/*Q(exp) */ - tmp1 = div_s(16384,tmp1);/*Q(15+14-exp=29-exp) */ - exp = sub(29,exp); + exp = norm_s( tmp1 ); + tmp1 = shl( tmp1, exp ); /*Q(exp) */ + tmp1 = div_s( 16384, tmp1 ); /*Q(15+14-exp=29-exp) */ + exp = sub( 29, exp ); } ELSE { @@ -767,74 +765,75 @@ void hq_lr_dec_fx( exp = 0; move16(); } - L_tmp = Mult_32_16(Ep_tmp_fx[i],tmp1);/*Q(15+exp-15 = exp) */ - L_tmp = Mult_32_16(L_tmp,tmp);/*Q(exp+0-15 = exp-15) */ - L_tmp = L_shl(L_tmp,sub(29,exp));/*Q14 */ - tmp = extract_l(L_min(L_max(L_tmp,13926),16384));/*Q14 */ - L_tmp = L_mult(alpha_fx,tmp);/*Q(14+14+1=29) */ - alpha_fx = extract_l(L_shr(L_tmp,15)); /*Q14 */ + L_tmp = Mult_32_16( Ep_tmp_fx[i], tmp1 ); /*Q(15+exp-15 = exp) */ + L_tmp = Mult_32_16( L_tmp, tmp ); /*Q(exp+0-15 = exp-15) */ + L_tmp = L_shl( L_tmp, sub( 29, exp ) ); /*Q14 */ + tmp = extract_l( L_min( L_max( L_tmp, 13926 ), 16384 ) ); /*Q14 */ + L_tmp = L_mult( alpha_fx, tmp ); /*Q(14+14+1=29) */ + alpha_fx = extract_l( L_shr( L_tmp, 15 ) ); /*Q14 */ } } - L_tmp = Mult_32_16(L_band_energy_tmp[i],alpha_fx);/*Q(Q_band_energy+14-15=Q_band_energy-1) */ - L_band_energy_tmp[i] = L_shl(L_tmp,1);/*Q Q_band_energy */ + L_tmp = Mult_32_16( L_band_energy_tmp[i], alpha_fx ); /*Q(Q_band_energy+14-15=Q_band_energy-1) */ + L_band_energy_tmp[i] = L_shl( L_tmp, 1 ); /*Q Q_band_energy */ } lowband = 6; move16(); - Ep_avrg_fx = L_deposit_l(0); - Ep_avrgL_fx = L_deposit_l(0); - Ep_peak_fx = L_deposit_l(0); - FOR(i = 0; i < bands_fx; i++) + Ep_avrg_fx = L_deposit_l( 0 ); + Ep_avrgL_fx = L_deposit_l( 0 ); + Ep_peak_fx = L_deposit_l( 0 ); + FOR( i = 0; i < bands_fx; i++ ) { - IF(GE_16(i,lowband)) + IF( GE_16( i, lowband ) ) { #ifdef BASOP_NOGLOB - Ep_avrg_fx = L_add_sat(Ep_avrg_fx,Ep_tmp_fx[i]);/*Q15 */ + Ep_avrg_fx = L_add_sat( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ #else - Ep_avrg_fx = L_add(Ep_avrg_fx,Ep_tmp_fx[i]);/*Q15 */ + Ep_avrg_fx = L_add( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ #endif } ELSE { #ifdef BASOP_NOGLOB - Ep_avrgL_fx = L_add_sat(Ep_avrgL_fx,Ep_tmp_fx[i]);/*Q15 */ + Ep_avrgL_fx = L_add_sat( Ep_avrgL_fx, Ep_tmp_fx[i] ); /*Q15 */ #else - Ep_avrgL_fx = L_add(Ep_avrgL_fx,Ep_tmp_fx[i]);/*Q15 */ + Ep_avrgL_fx = L_add( Ep_avrgL_fx, Ep_tmp_fx[i] ); /*Q15 */ #endif - if(GT_32(Ep_tmp_fx[i],Ep_peak_fx)) + if ( GT_32( Ep_tmp_fx[i], Ep_peak_fx ) ) { - Ep_peak_fx = L_add(Ep_tmp_fx[i], 0); /*Q15 */ + Ep_peak_fx = L_add( Ep_tmp_fx[i], 0 ); /*Q15 */ } } } - L_tmp = Mult_32_16(Ep_peak_fx,24576);/*Q(15+13-15 = 13) lowband = 6; */ - L_tmp2 =Mult_32_16(Ep_peak_fx,19661);/*Q(15+14-15 = 14) */ - L_tmp3 =Mult_32_16(Ep_avrgL_fx,24576);/*Q(15+12-15 = 12) */ + L_tmp = Mult_32_16( Ep_peak_fx, 24576 ); /*Q(15+13-15 = 13) lowband = 6; */ + L_tmp2 = Mult_32_16( Ep_peak_fx, 19661 ); /*Q(15+14-15 = 14) */ + L_tmp3 = Mult_32_16( Ep_avrgL_fx, 24576 ); /*Q(15+12-15 = 12) */ test(); test(); test(); test(); test(); - IF( (GT_32(L_shr(Ep_avrgL_fx,1), Ep_avrg_fx)&>_32(L_tmp,L_shr(Ep_avrgL_fx,2))&<_32(L_shr(Ep_avrgL_fx,1),L_tmp2))|| - (GT_32(L_shr(Ep_avrg_fx,1), Ep_avrgL_fx) && LT_32(L_shr(Ep_avrg_fx,3),L_tmp3) && GT_32(L_tmp,L_shr(Ep_avrgL_fx,2)) ) ) + IF( ( GT_32( L_shr( Ep_avrgL_fx, 1 ), Ep_avrg_fx ) && GT_32( L_tmp, L_shr( Ep_avrgL_fx, 2 ) ) && LT_32( L_shr( Ep_avrgL_fx, 1 ), L_tmp2 ) ) || + ( GT_32( L_shr( Ep_avrg_fx, 1 ), Ep_avrgL_fx ) && LT_32( L_shr( Ep_avrg_fx, 3 ), L_tmp3 ) && GT_32( L_tmp, L_shr( Ep_avrgL_fx, 2 ) ) ) ) { adjustFlag = 1; move16(); - FOR (i = 0; i < lowband; i++) + FOR( i = 0; i < lowband; i++ ) { #ifdef BASOP_NOGLOB tmp = Calc_inv( L_shl_sat( Ep_avrgL_fx, 1 ), &exp ); #else tmp = Calc_inv( L_shl( Ep_avrgL_fx, 1 ), &exp ); #endif - L_tmp = Mult_32_16(Ep_peak_fx,tmp);/*Q(15+exp-15 = exp) */ - L_tmp = Mult_32_16(L_tmp,lowband);/*Q(exp+0-15 = exp-15) */ - L_tmp = L_shl(L_tmp,sub(28,exp));/*Q14 0.5 */ - tmp = extract_l(L_min(L_tmp,19661));/*//Q14 */ - L_tmp = Mult_32_16(L_band_energy_tmp[i],tmp);/*Q(Q_band_energy+14-15 = Q_band_energy-1) */ - L_band_energy_tmp[i] = L_shl(L_tmp,1); /*Q_band_energy */ move32(); + L_tmp = Mult_32_16( Ep_peak_fx, tmp ); /*Q(15+exp-15 = exp) */ + L_tmp = Mult_32_16( L_tmp, lowband ); /*Q(exp+0-15 = exp-15) */ + L_tmp = L_shl( L_tmp, sub( 28, exp ) ); /*Q14 0.5 */ + tmp = extract_l( L_min( L_tmp, 19661 ) ); /*//Q14 */ + L_tmp = Mult_32_16( L_band_energy_tmp[i], tmp ); /*Q(Q_band_energy+14-15 = Q_band_energy-1) */ + L_band_energy_tmp[i] = L_shl( L_tmp, 1 ); /*Q_band_energy */ + move32(); } } @@ -842,7 +841,7 @@ void hq_lr_dec_fx( L_band_energy_tmp, bands_fx, L_Rk, &bit_budget_fx, p2a_flags_fx, bit_alloc_weight_fx, band_width, num_bits, hqswb_clas_fx, st_fx->bwidth, *is_transient_fx ); } - ELSE IF( EQ_16(st_fx->bwidth, SWB)&&EQ_16(hqswb_clas_fx,HQ_HARMONIC)&&(EQ_32(L_bwe_br,HQ_16k40)||EQ_32(L_bwe_br,HQ_13k20))) + ELSE IF( EQ_16( st_fx->bwidth, SWB ) && EQ_16( hqswb_clas_fx, HQ_HARMONIC ) && ( EQ_32( L_bwe_br, HQ_16k40 ) || EQ_32( L_bwe_br, HQ_13k20 ) ) ) { hq2_bit_alloc_har_fx( L_band_energy, bit_budget_fx, bands_fx, L_Rk, p2a_bands_fx, L_bwe_br, p2a_flags_fx, band_width ); } @@ -857,10 +856,10 @@ void hq_lr_dec_fx( { st_fx->BER_detect = 1; move16(); - bit_budget_fx = 0; + bit_budget_fx = 0; move16(); } - tcq_core_LR_dec_fx( st_fx, /*inp_vector*/inp_vector_fx, bit_budget_fx, bands_fx, band_start, band_width, /*Rk, */L_Rk, npulses_fx, k_sort_fx, + tcq_core_LR_dec_fx( st_fx, /*inp_vector*/ inp_vector_fx, bit_budget_fx, bands_fx, band_start, band_width, /*Rk, */ L_Rk, npulses_fx, k_sort_fx, p2a_flags_fx, p2a_bands_fx, last_bitalloc_max_band, inner_frame, adjustFlag, is_transient_fx ); /* Denormalize the coded MDCT spectrum */ @@ -874,16 +873,16 @@ void hq_lr_dec_fx( test(); test(); /* Restore the band information */ - IF( EQ_16(flag_spt_fx, 1)) + IF( EQ_16( flag_spt_fx, 1 ) ) { - spt_shorten_domain_band_restore_fx(bands_fx, band_start, band_end, band_width, org_band_start, org_band_end, org_band_width); + spt_shorten_domain_band_restore_fx( bands_fx, band_start, band_end, band_width, org_band_start, org_band_end, org_band_width ); } Copy32( L_y2, L_y2_org, L_FRAME32k ); /* Inject noise into components having relatively low pulse energy per band */ - ni_seed_fx = add(add(add(npulses_fx[0], npulses_fx[1]), npulses_fx[2]), npulses_fx[3]); - Copy32( L_y2, L_y2_ni, band_end[bands_fx-1]+1 ); + ni_seed_fx = add( add( add( npulses_fx[0], npulses_fx[1] ), npulses_fx[2] ), npulses_fx[3] ); + Copy32( L_y2, L_y2_ni, band_end[bands_fx - 1] + 1 ); hq2_noise_inject_fx( L_y2_ni, band_start, band_end, band_width, Ep_fx, L_Rk, npulses_fx, ni_seed_fx, bands_fx, 0, bw_low, bw_high, enerL_fx, enerH_fx, hHQ_core->last_ni_gain_fx, hHQ_core->last_env_fx, &hHQ_core->last_max_pos_pulse, p2a_flags_fx, p2a_bands_fx, @@ -891,26 +890,25 @@ void hq_lr_dec_fx( test(); test(); - IF( EQ_16(st_fx->bwidth, SWB)&&(EQ_32(L_bwe_br,HQ_16k40)||EQ_32(L_bwe_br,HQ_13k20))) + IF( EQ_16( st_fx->bwidth, SWB ) && ( EQ_32( L_bwe_br, HQ_16k40 ) || EQ_32( L_bwe_br, HQ_13k20 ) ) ) { test(); - IF( EQ_16(hqswb_clas_fx, HQ_NORMAL)||EQ_16(hqswb_clas_fx,HQ_HARMONIC)) + IF( EQ_16( hqswb_clas_fx, HQ_NORMAL ) || EQ_16( hqswb_clas_fx, HQ_HARMONIC ) ) { - preset_hq2_swb_fx( hqswb_clas_fx, band_end, &har_bands_fx, p2a_bands_fx,length_fx, bands_fx, &lowlength_fx, &highlength_fx, L_m ); + preset_hq2_swb_fx( hqswb_clas_fx, band_end, &har_bands_fx, p2a_bands_fx, length_fx, bands_fx, &lowlength_fx, &highlength_fx, L_m ); - swb_bwe_dec_lr_fx(st_fx, L_y2, SWB_BWE_LR_Qs, L_m, L_bwe_br, bands_fx, band_start, band_end, L_band_energy, SWB_BWE_LR_Qbe, - p2a_flags_fx, hqswb_clas_fx, lowlength_fx, highlength_fx, har_bands_fx, &hHQ_core->prev_frm_hfe2, &hHQ_core->prev_stab_hfe2 - , band_width, L_y2_ni, &ni_seed_fx); + swb_bwe_dec_lr_fx( st_fx, L_y2, SWB_BWE_LR_Qs, L_m, L_bwe_br, bands_fx, band_start, band_end, L_band_energy, SWB_BWE_LR_Qbe, + p2a_flags_fx, hqswb_clas_fx, lowlength_fx, highlength_fx, har_bands_fx, &hHQ_core->prev_frm_hfe2, &hHQ_core->prev_stab_hfe2, band_width, L_y2_ni, &ni_seed_fx ); post_hq2_swb_fx( L_m, lowlength_fx, highlength_fx, hqswb_clas_fx, har_bands_fx, bands_fx, p2a_flags_fx, band_start, band_end, L_y2, npulses_fx ); - IF( EQ_16(hqswb_clas_fx, HQ_NORMAL)) + IF( EQ_16( hqswb_clas_fx, HQ_NORMAL ) ) { - spt_swb_peakpos_tmp_save_fx(L_y2, bands_fx, band_start, band_end, prev_SWB_peak_pos_tmp_fx); - FOR( k=0; klast_inner_frame, L_FRAME16k)&&st_fx->bws_cnt>0)) + IF( !( GE_16( st_fx->last_inner_frame, L_FRAME16k ) && st_fx->bws_cnt > 0 ) ) { - k1_fx = sub(bands_fx,2); - if(NE_16(*is_transient_fx,1)) + k1_fx = sub( bands_fx, 2 ); + if ( NE_16( *is_transient_fx, 1 ) ) { - k1_fx = sub(bands_fx,6); + k1_fx = sub( bands_fx, 6 ); } - L_tmp = L_deposit_l(0); - FOR(i = k1_fx; i < bands_fx; i++) + L_tmp = L_deposit_l( 0 ); + FOR( i = k1_fx; i < bands_fx; i++ ) { - tmp = div_s(1,sub(bands_fx,k1_fx));/*Q15 */ - L_tmp = L_add(L_tmp,Mult_32_16(Ep_tmp_fx[i],tmp));/*Q15 */ + tmp = div_s( 1, sub( bands_fx, k1_fx ) ); /*Q15 */ + L_tmp = L_add( L_tmp, Mult_32_16( Ep_tmp_fx[i], tmp ) ); /*Q15 */ } - st_fx->prev_ener_shb_fx = extract_l(L_shr(L_tmp, 14)); + st_fx->prev_ener_shb_fx = extract_l( L_shr( L_tmp, 14 ) ); } test(); - IF(GE_16(st_fx->last_inner_frame, L_FRAME32k) && st_fx->hBWE_FD != NULL) + IF( GE_16( st_fx->last_inner_frame, L_FRAME32k ) && st_fx->hBWE_FD != NULL ) { - set16_fx(st_fx->prev_SWB_fenv_fx, st_fx->prev_ener_shb_fx, SWB_FENV); + set16_fx( st_fx->prev_SWB_fenv_fx, st_fx->prev_ener_shb_fx, SWB_FENV ); } updat_prev_frm_fx( L_y2, L_yout, L_bwe_br, length_fx, inner_frame, bands_fx, st_fx->bwidth, *is_transient_fx, hqswb_clas_fx, &hHQ_core->prev_hqswb_clas, - hHQ_core->prev_SWB_peak_pos_fx, prev_SWB_peak_pos_tmp_fx, &hHQ_core->prev_frm_hfe2, &hHQ_core->prev_stab_hfe2, st_fx->bws_cnt ); + hHQ_core->prev_SWB_peak_pos_fx, prev_SWB_peak_pos_tmp_fx, &hHQ_core->prev_frm_hfe2, &hHQ_core->prev_stab_hfe2, st_fx->bws_cnt ); return; } @@ -964,30 +962,30 @@ void hq_lr_dec_fx( *--------------------------------------------------------------------------------------*/ static Word16 small_symbol_dec_tran_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *qbidx, /* o : output of dequantized differential energy */ - const Word16 bands, /* i : number of bands */ - const Word16 is_transient /* i : transient flag */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *qbidx, /* o : output of dequantized differential energy */ + const Word16 bands, /* i : number of bands */ + const Word16 is_transient /* i : transient flag */ ) { - Word16 i, bits; + Word16 i, bits; Word16 difidx[BANDS_MAX]; /* Decoding differential energies*/ - bits = decode_envelope_indices_fx(st_fx, 0, bands, 0, difidx, LOW_RATE_HQ_CORE_TRAN ,is_transient); - bits = add(bits, BITS_DE_FCOMP); + bits = decode_envelope_indices_fx( st_fx, 0, bands, 0, difidx, LOW_RATE_HQ_CORE_TRAN, is_transient ); + bits = add( bits, BITS_DE_FCOMP ); /* counting 1 bit for band_energy_huff_coding_mode */ - bits = add(bits, BITS_DE_HMODE); + bits = add( bits, BITS_DE_HMODE ); /* converting to original values */ - FOR( i=0; i 0 ) { - *rbits = add(*rbits, s_and(*hufftab, 0xf)); - bit = get_next_indice( st_fx, s_and(*hufftab, 0xf) ); - hufftab += add(shr(*hufftab, 4), bit); + *rbits = add( *rbits, s_and( *hufftab, 0xf ) ); + bit = get_next_indice( st_fx, s_and( *hufftab, 0xf ) ); + hufftab += add( shr( *hufftab, 4 ), bit ); } - return negate(*hufftab); + return negate( *hufftab ); } -static Word16 large_symbol_dec_fx( /* o : bits */ - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *qbidx, /* o : output of dequantized differential energy */ - const Word16 bands /* i : number of bands */ +static Word16 large_symbol_dec_fx( /* o : bits */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *qbidx, /* o : output of dequantized differential energy */ + const Word16 bands /* i : number of bands */ ) { Word16 i, bits; Word16 LSB[BANDS_MAX]; - Word16 basic_shift,cntbits,ns2mode; + Word16 basic_shift, cntbits, ns2mode; Word16 pos_outlyer; - Word16 ns2mode0,ns2mode1; + Word16 ns2mode0, ns2mode1; cntbits = BITS_DE_8SMODE; move16(); - ns2mode = get_next_indice (st_fx, BITS_DE_8SMODE); + ns2mode = get_next_indice( st_fx, BITS_DE_8SMODE ); - IF ( ns2mode == 0 ) + IF( ns2mode == 0 ) { - ns2mode0 = get_next_indice (st_fx, BITS_DE_8SMODE_N0); - ns2mode1 = get_next_indice (st_fx, BITS_DE_8SMODE_N1); - cntbits = add(cntbits, BITS_DE_8SMODE_N0+BITS_DE_8SMODE_N1); + ns2mode0 = get_next_indice( st_fx, BITS_DE_8SMODE_N0 ); + ns2mode1 = get_next_indice( st_fx, BITS_DE_8SMODE_N1 ); + cntbits = add( cntbits, BITS_DE_8SMODE_N0 + BITS_DE_8SMODE_N1 ); - IF ( ns2mode0 == 0 ) + IF( ns2mode0 == 0 ) { - IF ( EQ_16(ns2mode1, 1)) + IF( EQ_16( ns2mode1, 1 ) ) { - pos_outlyer = get_next_indice (st_fx, BITS_DE_8SPOS); - cntbits = add(cntbits, BITS_DE_8SPOS); - qbidx[pos_outlyer] = sub(get_next_indice (st_fx, BITS_ABS_ENG), ABS_ENG_OFFSET); + pos_outlyer = get_next_indice( st_fx, BITS_DE_8SPOS ); + cntbits = add( cntbits, BITS_DE_8SPOS ); + qbidx[pos_outlyer] = sub( get_next_indice( st_fx, BITS_ABS_ENG ), ABS_ENG_OFFSET ); move16(); - cntbits = add(cntbits, BITS_ABS_ENG); + cntbits = add( cntbits, BITS_ABS_ENG ); } ELSE { @@ -1095,91 +1091,91 @@ static Word16 large_symbol_dec_fx( /* o : bits move16(); } - FOR( i=0; i Qbe(Q14) */ + L_band_energy[k] = Mpy_32_16_1( L_qint, bq1_fx[k] ); + move32(); /* 29+0-15 -> Qbe(Q14) */ } - IF (is_transient_fx) + IF( is_transient_fx ) { reverse_transient_frame_energies_fx( L_band_energy, bands_fx ); } - return( deng_bits ); + return ( deng_bits ); } @@ -1272,16 +1267,16 @@ static Word16 band_energy_dequant_fx( * *--------------------------------------------------------------------------*/ -static Word16 p2a_threshold_dequant_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *p2a_flags, /* o : tonaly indicator */ - const Word16 bands, /* i : number of subbands */ - const Word16 p2a_bands /* i : number of subbnads for computing tonality */ +static Word16 p2a_threshold_dequant_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *p2a_flags, /* o : tonaly indicator */ + const Word16 bands, /* i : number of subbands */ + const Word16 p2a_bands /* i : number of subbnads for computing tonality */ ) { Word16 j, k; - j = sub(bands, p2a_bands); + j = sub( bands, p2a_bands ); FOR( k = 0; k < j; k++ ) { p2a_flags[k] = 1; @@ -1290,14 +1285,14 @@ static Word16 p2a_threshold_dequant_fx( j = 0; move16(); - FOR( k = sub(bands, p2a_bands); k < bands; k++ ) + FOR( k = sub( bands, p2a_bands ); k < bands; k++ ) { p2a_flags[k] = get_next_indice( st_fx, 1 ); move16(); - j = add(j, 1); + j = add( j, 1 ); } - return( j ); + return ( j ); } @@ -1307,17 +1302,17 @@ static Word16 p2a_threshold_dequant_fx( * *--------------------------------------------------------------------------*/ -static void mdct_spectrum_fine_gain_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word32 L_y2[], /* i/o: Q12 : decoded spectrum */ - const Word16 band_start[], /* i : Q0 : table of start freq for every subband */ - const Word16 band_end[], /* i : Q0 : table of end freq for every subband */ - const Word16 k_sort[], /* i : Q0 : sort table by band_energy */ - const Word16 bands, /* i : Q0 : nubmber of subbands */ - const Word32 L_qint, /* i : Q0 : */ - const Word16 Ngq, /* i : Q0 : */ - const Word16 gqlevs, /* i : Q0 : quantized level */ - const Word16 gqbits /* i : Q0 : quantized bits */ +static void mdct_spectrum_fine_gain_dec_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word32 L_y2[], /* i/o: Q12 : decoded spectrum */ + const Word16 band_start[], /* i : Q0 : table of start freq for every subband */ + const Word16 band_end[], /* i : Q0 : table of end freq for every subband */ + const Word16 k_sort[], /* i : Q0 : sort table by band_energy */ + const Word16 bands, /* i : Q0 : nubmber of subbands */ + const Word32 L_qint, /* i : Q0 : */ + const Word16 Ngq, /* i : Q0 : */ + const Word16 gqlevs, /* i : Q0 : quantized level */ + const Word16 gqbits /* i : Q0 : quantized bits */ ) { Word16 i, k, imin_fx; @@ -1337,29 +1332,30 @@ static void mdct_spectrum_fine_gain_dec_fx( /* Fine gain quantization on only the most significant energy bands */ - exp_normn = norm_l(L_qint); - exp_normn = sub(exp_normn, 1); - exp_normd = norm_s(gqlevs); - delta_fx = div_l(L_shl(L_qint, exp_normn), shl(gqlevs, exp_normd)); - Qdelta = add(sub(exp_normn, exp_normd), 28); /* 29+exp_normn-(exp_normd)-1; */ - L_delta = L_shl(L_deposit_h(delta_fx), sub(13, Qdelta)); + exp_normn = norm_l( L_qint ); + exp_normn = sub( exp_normn, 1 ); + exp_normd = norm_s( gqlevs ); + delta_fx = div_l( L_shl( L_qint, exp_normn ), shl( gqlevs, exp_normd ) ); + Qdelta = add( sub( exp_normn, exp_normd ), 28 ); /* 29+exp_normn-(exp_normd)-1; */ + L_delta = L_shl( L_deposit_h( delta_fx ), sub( 13, Qdelta ) ); - L_q = L_shr(L_sub(L_delta, L_qint), 1); + L_q = L_shr( L_sub( L_delta, L_qint ), 1 ); - FOR ( i=0; i Q14 */ move16(); + L_q = L_add( L_q, L_delta ); + gain_table_fx[i] = shl( gain_table_fx[i], sub( 14, Qgt ) ); /* Qgt -> Q14 */ + move16(); } - FOR( k = sub(bands, Ngq); k < bands; k++ ) + FOR( k = sub( bands, Ngq ); k < bands; k++ ) { imin_fx = get_next_indice( st_fx, gqbits ); @@ -1367,20 +1363,20 @@ static void mdct_spectrum_fine_gain_dec_fx( gamma_fx = gain_table_fx[imin_fx]; move16(); - FOR (i = band_start[k_sort[k]]; i <= band_end[k_sort[k]]; i++) + FOR( i = band_start[k_sort[k]]; i <= band_end[k_sort[k]]; i++ ) { /* This IF statement for keeping same mantissa evenif y2 is plus or minus */ - IF ( L_y2[i] >= 0x0 ) + IF( L_y2[i] >= 0x0 ) { - L_y2[i] = L_shl(Mpy_32_16_1(L_y2[i], gamma_fx), 1); + L_y2[i] = L_shl( Mpy_32_16_1( L_y2[i], gamma_fx ), 1 ); } ELSE { - L_y2[i] = L_negate(L_shl(Mpy_32_16_1(L_abs(L_y2[i]), gamma_fx), 1)); + L_y2[i] = L_negate( L_shl( Mpy_32_16_1( L_abs( L_y2[i] ), gamma_fx ), 1 ) ); } } } return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/igf_dec.c b/lib_dec/igf_dec.c index d6eb6d466..6ef921b52 100644 --- a/lib_dec/igf_dec.c +++ b/lib_dec/igf_dec.c @@ -1127,7 +1127,7 @@ int16_t IGFDecReadLevel_flt( } else { - IGFSCFDecoderReset_ivas( &hPrivateData->hArithSCFdec ); + IGFSCFDecoderReset_ivas( &hPrivateData->hArithSCFdec ); set_s( &hPrivateData->igf_curr[m_igfSfbStart], 0, hGrid->stopSfb - m_igfSfbStart ); } @@ -1395,9 +1395,9 @@ void IGFDecSetMode_flt( hPrivateData = &hIGFDec->igfData; hIGFDec->isIGFActive = 0; - if (IGFCommonFuncsIGFConfiguration_flt( total_brate, bwidth, element_mode, &hPrivateData->igfInfo, rf_mode ) ) + if ( IGFCommonFuncsIGFConfiguration_flt( total_brate, bwidth, element_mode, &hPrivateData->igfInfo, rf_mode ) ) { - IGFSCFDecoderOpen_ivas( &hPrivateData->hArithSCFdec, &hPrivateData->igfInfo, total_brate, bwidth, element_mode, rf_mode ); + IGFSCFDecoderOpen_ivas( &hPrivateData->hArithSCFdec, &hPrivateData->igfInfo, total_brate, bwidth, element_mode, rf_mode ); hIGFDec->infoIGFAllZero = 0; hIGFDec->isIGFActive = 1; @@ -1497,7 +1497,7 @@ void IGFDecReplicateTCX10State_flt( mvr2r( &hIGFDec->virtualSpecBuf[( N_MAX_TCX - IGF_START_MN ) / 2], &hIGFDec->virtualSpecBuf[0], ( N_MAX_TCX - IGF_START_MN ) / 2 ); mvr2r( &hIGFDec->igfData.pSpecFlatBuf[IGF_START_MX / 2], &hIGFDec->igfData.pSpecFlatBuf[0], IGF_START_MX / 2 ); #ifdef IVAS_FLOAT_FIXED - Copy32(&hIGFDec->igfData.pSpecFlatBuf_fx[IGF_START_MX / 2], &hIGFDec->igfData.pSpecFlatBuf_fx[0], IGF_START_MX / 2); + Copy32( &hIGFDec->igfData.pSpecFlatBuf_fx[IGF_START_MX / 2], &hIGFDec->igfData.pSpecFlatBuf_fx[0], IGF_START_MX / 2 ); #endif hIGFDec->igfData.igfInfo.nfSeedBuf[0] = hIGFDec->igfData.igfInfo.nfSeedBuf[1]; @@ -1609,20 +1609,20 @@ void IGFDecRestoreTCX10SubFrameData_flt( *-----------------------------------------------------------------------*/ #ifndef IVAS_FLOAT_FIXED void init_igf_dec_flt( - IGF_DEC_INSTANCE_HANDLE hIGFDec /* i/o: IGF decoder handle */ + IGF_DEC_INSTANCE_HANDLE hIGFDec /* i/o: IGF decoder handle */ ) { - set_c((int8_t *)(hIGFDec->infoTCXNoiseBuf), 0, IGF_START_MX); - set_f(hIGFDec->igfData.pSpecFlatBuf, 0, IGF_START_MX); - hIGFDec->igfData.igfInfo.nfSeedBuf[0] = 9733; - hIGFDec->igfData.igfInfo.nfSeedBuf[1] = 9733; - hIGFDec->igfData.igfInfo.nfSeed = &hIGFDec->igfData.igfInfo.nfSeedBuf[0]; - hIGFDec->igfData.pSpecFlat_float = &hIGFDec->igfData.pSpecFlatBuf[0]; - hIGFDec->flag_sparse = &hIGFDec->flag_sparseBuf[0]; - hIGFDec->infoTCXNoise = &hIGFDec->infoTCXNoiseBuf[0]; - hIGFDec->virtualSpec_float = &hIGFDec->virtualSpecBuf[0]; - - return; + set_c( (int8_t *) ( hIGFDec->infoTCXNoiseBuf ), 0, IGF_START_MX ); + set_f( hIGFDec->igfData.pSpecFlatBuf, 0, IGF_START_MX ); + hIGFDec->igfData.igfInfo.nfSeedBuf[0] = 9733; + hIGFDec->igfData.igfInfo.nfSeedBuf[1] = 9733; + hIGFDec->igfData.igfInfo.nfSeed = &hIGFDec->igfData.igfInfo.nfSeedBuf[0]; + hIGFDec->igfData.pSpecFlat_float = &hIGFDec->igfData.pSpecFlatBuf[0]; + hIGFDec->flag_sparse = &hIGFDec->flag_sparseBuf[0]; + hIGFDec->infoTCXNoise = &hIGFDec->infoTCXNoiseBuf[0]; + hIGFDec->virtualSpec_float = &hIGFDec->virtualSpecBuf[0]; + + return; } #endif /*-----------------------------------------------------------------------* diff --git a/lib_dec/igf_dec_fx.c b/lib_dec/igf_dec_fx.c index 0442b2c68..cddeec0de 100644 --- a/lib_dec/igf_dec_fx.c +++ b/lib_dec/igf_dec_fx.c @@ -16,8 +16,8 @@ #include "cnst.h" #include "stat_dec.h" #include "basop_util.h" -//Temporarily added -#define MID 57/* (.89*1<<6)*/ +// Temporarily added +#define MID 57 /* (.89*1<<6)*/ #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" #endif @@ -26,10 +26,10 @@ /**********************************************************************/ /* get scalefactor of an Word32 array with condition **************************************************************************/ -static Word16 IGF_getScaleFactor32Cond( /**< out: Q0 | measured headroom in range [0..31], 0 if all x[i] == 0 */ - const Word16 *cond, /**< in: Q0 | array conating the condition */ - const Word32 *x, /**< in: Q31 | array containing 32-bit data */ - const Word16 len_x /**< in: Q0 | length of the array to scan */ +static Word16 IGF_getScaleFactor32Cond( /**< out: Q0 | measured headroom in range [0..31], 0 if all x[i] == 0 */ + const Word16 *cond, /**< in: Q0 | array conating the condition */ + const Word32 *x, /**< in: Q31 | array containing 32-bit data */ + const Word16 len_x /**< in: Q0 | length of the array to scan */ ) { Word16 i; @@ -40,27 +40,27 @@ static Word16 IGF_getScaleFactor32Cond( Word32 tmp32; - x_max = 0; - move32(); - x_min = 0; - move32(); - FOR (i = 0; i < len_x; i++) + x_max = 0; + move32(); + x_min = 0; + move32(); + FOR( i = 0; i < len_x; i++ ) { - tmp32 = L_add(x[i], 0); /*L_and(x[i], cond[i]);*/ + tmp32 = L_add( x[i], 0 ); /*L_and(x[i], cond[i]);*/ - if (cond[i] == 0) + if ( cond[i] == 0 ) { - tmp32 = L_deposit_h(0); + tmp32 = L_deposit_h( 0 ); } - if (tmp32>= 0) + if ( tmp32 >= 0 ) { - x_max = L_max(x_max, tmp32); + x_max = L_max( x_max, tmp32 ); } - if (tmp32< 0) + if ( tmp32 < 0 ) { - x_min = L_min(x_min, tmp32); + x_min = L_min( x_min, tmp32 ); } } @@ -69,16 +69,16 @@ static Word16 IGF_getScaleFactor32Cond( i_min = 0x20; move16(); - if (x_max != 0) + if ( x_max != 0 ) { - i_max = norm_l(x_max); + i_max = norm_l( x_max ); } - if (x_min != 0) + if ( x_min != 0 ) { - i_min = norm_l(x_min); + i_min = norm_l( x_min ); } - i = s_and(s_min(i_max, i_min), 0x1F); + i = s_and( s_min( i_max, i_min ), 0x1F ); return i; } @@ -86,13 +86,13 @@ static Word16 IGF_getScaleFactor32Cond( /**********************************************************************/ /* measures TCX noise **************************************************************************/ -static Word16 IGF_replaceTCXNoise_1( /**< out: Q0 | number of noise bands */ - const Word32 *in, /**< in: Q31 | MDCT spectrum */ - Word16 s_l, /**< in: Q0 | noise headroom */ - const Word16 *TCXNoise, /**< in: | tcx noise indicator vector */ - const Word16 start, /**< in: Q0 | start MDCT subband index */ - const Word16 stop, /**< in: Q0 | stop MDCT subband index */ - Word32 *totalNoiseNrg /**< out: | measured noise energy */ +static Word16 IGF_replaceTCXNoise_1( /**< out: Q0 | number of noise bands */ + const Word32 *in, /**< in: Q31 | MDCT spectrum */ + Word16 s_l, /**< in: Q0 | noise headroom */ + const Word16 *TCXNoise, /**< in: | tcx noise indicator vector */ + const Word16 start, /**< in: Q0 | start MDCT subband index */ + const Word16 stop, /**< in: Q0 | stop MDCT subband index */ + Word32 *totalNoiseNrg /**< out: | measured noise energy */ ) { Word16 sb; @@ -105,23 +105,23 @@ static Word16 IGF_replaceTCXNoise_1( move16(); noise = 0; move16(); - s_l = sub(s_l, 5); - nE = 0; - move32(); + s_l = sub( s_l, 5 ); + nE = 0; + move32(); - FOR (sb = start; sb < stop; sb++) + FOR( sb = start; sb < stop; sb++ ) { - if (TCXNoise[sb]) + if ( TCXNoise[sb] ) { - tmp16 = extract_h(L_shl(in[sb], s_l)); + tmp16 = extract_h( L_shl( in[sb], s_l ) ); } - if (TCXNoise[sb]) + if ( TCXNoise[sb] ) { - nE = L_mac(nE, tmp16, tmp16); + nE = L_mac( nE, tmp16, tmp16 ); } - if (TCXNoise[sb]) + if ( TCXNoise[sb] ) { - noise = add(noise, 1); + noise = add( noise, 1 ); } } @@ -134,14 +134,14 @@ static Word16 IGF_replaceTCXNoise_1( /**********************************************************************/ /* replaces TCX noise **************************************************************************/ -static void IGF_replaceTCXNoise_2(Word32 *in, /**< in/out: | MDCT spectrum */ - const Word16 *TCXNoise, /**< in: Q0 | tcx noise indicator vector */ - const Word16 start, /**< in: Q0 | start MDCT subband index */ - const Word16 stop, /**< in: Q0 | stop MDCT subband index */ - Word32 totalNoiseNrg, /**< in: | measured noise energy */ - const Word16 s_l, /**< in: Q0 | noise headroom */ - Word16 *nfSeed /**< in: | random generator noise seed */ - ) +static void IGF_replaceTCXNoise_2( Word32 *in, /**< in/out: | MDCT spectrum */ + const Word16 *TCXNoise, /**< in: Q0 | tcx noise indicator vector */ + const Word16 start, /**< in: Q0 | start MDCT subband index */ + const Word16 stop, /**< in: Q0 | stop MDCT subband index */ + Word32 totalNoiseNrg, /**< in: | measured noise energy */ + const Word16 s_l, /**< in: Q0 | noise headroom */ + Word16 *nfSeed /**< in: | random generator noise seed */ +) { Word16 sb; Word16 g; @@ -152,65 +152,64 @@ static void IGF_replaceTCXNoise_2(Word32 *in, val = 0; move16(); - rE = 0; - move32(); + rE = 0; + move32(); - FOR (sb = start; sb < stop; sb++) + FOR( sb = start; sb < stop; sb++ ) { - if (TCXNoise[sb]) + if ( TCXNoise[sb] ) { - val = Random(nfSeed); + val = Random( nfSeed ); } - if (TCXNoise[sb]) + if ( TCXNoise[sb] ) { - in[sb] = L_deposit_l(val); + in[sb] = L_deposit_l( val ); } - if (TCXNoise[sb]) + if ( TCXNoise[sb] ) { - val = shr(val, 5); + val = shr( val, 5 ); } - if (TCXNoise[sb]) + if ( TCXNoise[sb] ) { - rE = L_mac(rE, val, val); + rE = L_mac( rE, val, val ); } } - totalNoiseNrg = L_shr(totalNoiseNrg, 1); + totalNoiseNrg = L_shr( totalNoiseNrg, 1 ); /* make sure that rE is never 0 */ - if (rE == 0) + if ( rE == 0 ) { - rE = L_add(totalNoiseNrg, 0); /* save move32() -> use L_add(x, 0) = x; */ + rE = L_add( totalNoiseNrg, 0 ); /* save move32() -> use L_add(x, 0) = x; */ } /* if totalNoiseNrg == 0, then rE must be at least 0x00010000, otherwise division by 0 will occur */ - if (totalNoiseNrg == 0) + if ( totalNoiseNrg == 0 ) { - rE = L_max(rE, 0x00010000); + rE = L_max( rE, 0x00010000 ); } /* make sure that rE is never smaller than totalNoiseNrg */ - L_tmp = L_sub(rE, totalNoiseNrg); - if (L_tmp < 0) + L_tmp = L_sub( rE, totalNoiseNrg ); + if ( L_tmp < 0 ) { - rE = totalNoiseNrg; /* save move32() -> use L_add(x, 0) = x; */ - move32(); + rE = totalNoiseNrg; /* save move32() -> use L_add(x, 0) = x; */ + move32(); } - g = getSqrtWord32(L_mult(divide3232(totalNoiseNrg, rE), 8192/*1.0f / 4.0f Q15*/)); - g = shl(g, 1); + g = getSqrtWord32( L_mult( divide3232( totalNoiseNrg, rE ), 8192 /*1.0f / 4.0f Q15*/ ) ); + g = shl( g, 1 ); - FOR (sb = start; sb < stop; sb++) + FOR( sb = start; sb < stop; sb++ ) { - if (TCXNoise[sb]) + if ( TCXNoise[sb] ) { - in[sb] = L_shr(L_mult(extract_l(in[sb]), g), s_l); + in[sb] = L_shr( L_mult( extract_l( in[sb] ), g ), s_l ); move32(); } } - } /**********************************************************************/ /* @@ -244,7 +243,7 @@ static void IGF_replaceTCXNoise_2_new_ivas( Word32 *in, /**< in FOR( sb = start; sb < stop; sb++ ) { - IF ( TCXNoise[sb] ) + IF( TCXNoise[sb] ) { val = Random( nfSeed ); move16(); @@ -281,7 +280,7 @@ static void IGF_replaceTCXNoise_2_new_ivas( Word32 *in, /**< in FOR( sb = start; sb < stop; sb++ ) { - IF ( TCXNoise[sb] ) + IF( TCXNoise[sb] ) { Word16 nrm = norm_l( in[sb] ); in[sb] = L_shl( in[sb], nrm ); // exp: 31 - tmp @@ -294,9 +293,9 @@ static void IGF_replaceTCXNoise_2_new_ivas( Word32 *in, /**< in } -/**********************************************************************/ /* -replaces TCX noise with noise band ratio (for IVAS) -**************************************************************************/ +/**********************************************************************/ /* + replaces TCX noise with noise band ratio (for IVAS) + **************************************************************************/ static void IGF_replaceTCXNoise_2_new_ivas_with_var_shift( Word32 *in, /**< in/out: | MDCT spectrum */ Word16 *in_e_arr, /**< in/out: | MDCT spectrum exp */ const Word16 *TCXNoise, /**< in: | tcx noise indicator vector */ @@ -379,20 +378,20 @@ static void IGF_replaceTCXNoise_2_new_ivas_with_var_shift( Word32 *in, } } -/**********************************************************************/ /* -reads whitening levels -**************************************************************************/ -static void IGF_decode_whitening_level(Decoder_State *st, /**< in: | decoder state */ - IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in: | instance handle of IGF Deccoder */ - const Word16 p /**< in: Q0 | tile index, p = [0, 3] */ - ) +/**********************************************************************/ /* + reads whitening levels + **************************************************************************/ +static void IGF_decode_whitening_level( Decoder_State *st, /**< in: | decoder state */ + IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in: | instance handle of IGF Deccoder */ + const Word16 p /**< in: Q0 | tile index, p = [0, 3] */ +) { Word16 tmp; - tmp = get_next_indice(st, 1); + tmp = get_next_indice( st, 1 ); - IF (tmp == 0) + IF( tmp == 0 ) { hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_MID; move16(); @@ -400,50 +399,48 @@ static void IGF_decode_whitening_level(Decoder_State *st, return; } - tmp = get_next_indice(st, 1); - hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_STRONG; + tmp = get_next_indice( st, 1 ); + hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_STRONG; move16(); - if (tmp == 0) + if ( tmp == 0 ) { hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_OFF; move16(); } - } -/**********************************************************************/ /* -reads flattening trigger -**************************************************************************/ -static void IGF_decode_temp_flattening_trigger(Decoder_State *st, /**< in: | decoder state */ - IGF_DEC_INSTANCE_HANDLE hInstance /**< in: | instance handle of IGF Deccoder */ - ) +/**********************************************************************/ /* + reads flattening trigger + **************************************************************************/ +static void IGF_decode_temp_flattening_trigger( Decoder_State *st, /**< in: | decoder state */ + IGF_DEC_INSTANCE_HANDLE hInstance /**< in: | instance handle of IGF Deccoder */ +) { - hInstance->flatteningTrigger = get_next_indice(st, 1); + hInstance->flatteningTrigger = get_next_indice( st, 1 ); } /**********************************************************************/ /* set power spectrum values to zero, needed for energy calculation **************************************************************************/ -static void IGF_setLinesToZero(const Word16 startLine, /**< in: Q0 | start MDCT subband index */ - const Word16 stopLine, /**< in: Q0 | stop MDCT subband index */ - const Word32 *pSpectralData, /**< in: | original MDCT spectrum */ - Word32 *pPowerSpecIGF /**< in/out: | prepared IGF energy spectrum */ - ) +static void IGF_setLinesToZero( const Word16 startLine, /**< in: Q0 | start MDCT subband index */ + const Word16 stopLine, /**< in: Q0 | stop MDCT subband index */ + const Word32 *pSpectralData, /**< in: | original MDCT spectrum */ + Word32 *pPowerSpecIGF /**< in/out: | prepared IGF energy spectrum */ +) { Word16 i; /* set energy values in the IGF "power spectrum" to 0, if there is content in the original MDCT spectrum */ - FOR (i = startLine; i < stopLine; i++) + FOR( i = startLine; i < stopLine; i++ ) { - if (pSpectralData[i] != 0) + if ( pSpectralData[i] != 0 ) { - pPowerSpecIGF[i] = L_deposit_l(0); + pPowerSpecIGF[i] = L_deposit_l( 0 ); } } - } /**********************************************************************/ /* @@ -482,15 +479,15 @@ static void IGF_convert_exponent_per_idx_to_per_tile( H_IGF_GRID hGrid, /**********************************************************************/ /* prepare IGF spectrum **************************************************************************/ -static void IGF_prep(IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in: | IGF private data handle */ - const Word16 igfGridIdx, /**< in: Q0 | in case of CELP->TCX switching, use 1.25 framelength */ - const Word16 *TCXNoise, /**< in: Q0 | TCX noise vector */ - Word32 *igf_spec, /**< in: Q31 | prepared IGF spectrum */ - Word16 *igf_spec_e, /**< in: | array exponents of igf_spec, one exponent per tile */ - const Word32 *src_spec, /**< in: | source spectrum */ - const Word16 src_spec_e, /**< in: | exponent of src_spec, whitening off */ - const Word16 specMed_e /**< in: | exponent of medium flattening level */ - ) +static void IGF_prep( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in: | IGF private data handle */ + const Word16 igfGridIdx, /**< in: Q0 | in case of CELP->TCX switching, use 1.25 framelength */ + const Word16 *TCXNoise, /**< in: Q0 | TCX noise vector */ + Word32 *igf_spec, /**< in: Q31 | prepared IGF spectrum */ + Word16 *igf_spec_e, /**< in: | array exponents of igf_spec, one exponent per tile */ + const Word32 *src_spec, /**< in: | source spectrum */ + const Word16 src_spec_e, /**< in: | exponent of src_spec, whitening off */ + const Word16 specMed_e /**< in: | exponent of medium flattening level */ +) { H_IGF_GRID hGrid; H_IGF_INFO hInfo; @@ -510,59 +507,59 @@ static void IGF_prep(IGF_DEC_PRIVATE_DATA_HANDLE hPrivate /* initialize variables */ - hInfo = &hPrivateData->igfInfo; - hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; - n_noise_bands = hPrivateData->n_noise_bands; + hInfo = &hPrivateData->igfInfo; + hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; + n_noise_bands = hPrivateData->n_noise_bands; move16(); - n_noise_bands_off = hPrivateData->n_noise_bands_off; + n_noise_bands_off = hPrivateData->n_noise_bands_off; move16(); - totalNoiseNrg = hPrivateData->totalNoiseNrg; + totalNoiseNrg = hPrivateData->totalNoiseNrg; move32(); - totalNoiseNrg_off = hPrivateData->totalNoiseNrg_off; + totalNoiseNrg_off = hPrivateData->totalNoiseNrg_off; move32(); - nTiles = hGrid->nTiles; + nTiles = hGrid->nTiles; move16(); - startLine = hGrid->startLine; + startLine = hGrid->startLine; move16(); - minSrcSubband = hGrid->minSrcSubband; + minSrcSubband = hGrid->minSrcSubband; move16(); - tile_idx = 0; + tile_idx = 0; move16(); - FOR (tile_idx = 0; tile_idx < nTiles; tile_idx++) + FOR( tile_idx = 0; tile_idx < nTiles; tile_idx++ ) { strt_cpy = hGrid->sbWrap[tile_idx]; move16(); /* strong whitening detected */ - IF (EQ_16(IGF_WHITENING_STRONG, hPrivateData->currWhiteningLevel[tile_idx])) + IF( EQ_16( IGF_WHITENING_STRONG, hPrivateData->currWhiteningLevel[tile_idx] ) ) { Word32 abs_sum; - abs_sum = 0; - move32(); + abs_sum = 0; + move32(); - FOR(i = strt_cpy; i < hGrid->startLine; i++) + FOR( i = strt_cpy; i < hGrid->startLine; i++ ) { - abs_sum = L_add(abs_sum, L_abs(src_spec[i])); + abs_sum = L_add( abs_sum, L_abs( src_spec[i] ) ); } /* fill igf_spec with random noise */ tb = hGrid->swb_offset[hGrid->sfbWrap[tile_idx]]; move16(); - IF (abs_sum != 0) + IF( abs_sum != 0 ) { - FOR (i = strt_cpy; i < startLine; i++) + FOR( i = strt_cpy; i < startLine; i++ ) { - igf_spec[tb++] = L_deposit_l(Random(hInfo->nfSeed)); /* 31Q0, fill LSBs */ + igf_spec[tb++] = L_deposit_l( Random( hInfo->nfSeed ) ); /* 31Q0, fill LSBs */ } } ELSE { - FOR (i = strt_cpy; i < startLine; i++) + FOR( i = strt_cpy; i < startLine; i++ ) { - igf_spec[tb++] = 0; - move32(); + igf_spec[tb++] = 0; + move32(); } } @@ -573,18 +570,18 @@ static void IGF_prep(IGF_DEC_PRIVATE_DATA_HANDLE hPrivate ELSE { /* medium whitening detected */ - IF (EQ_16(IGF_WHITENING_MID, hPrivateData->currWhiteningLevel[tile_idx])) + IF( EQ_16( IGF_WHITENING_MID, hPrivateData->currWhiteningLevel[tile_idx] ) ) { - IF (n_noise_bands != 0) + IF( n_noise_bands != 0 ) { - IGF_replaceTCXNoise_2(igf_spec, - TCXNoise, - - minSrcSubband, - startLine, - totalNoiseNrg, - hPrivateData->headroom_TCX_noise_white, - hInfo->nfSeed); + IGF_replaceTCXNoise_2( igf_spec, + TCXNoise, + + minSrcSubband, + startLine, + totalNoiseNrg, + hPrivateData->headroom_TCX_noise_white, + hInfo->nfSeed ); } /* selected source spectrum is igf_spec, igf_spec contains the whitened signal in the core region */ @@ -598,16 +595,15 @@ static void IGF_prep(IGF_DEC_PRIVATE_DATA_HANDLE hPrivate /* off whitening detectded */ ELSE { - IF (n_noise_bands_off != 0) + IF( n_noise_bands_off != 0 ) { - IGF_replaceTCXNoise_2(hPrivateData->pSpecFlat, - TCXNoise, - minSrcSubband, - startLine, - totalNoiseNrg_off, - hPrivateData->headroom_TCX_noise, - hInfo->nfSeed); - + IGF_replaceTCXNoise_2( hPrivateData->pSpecFlat, + TCXNoise, + minSrcSubband, + startLine, + totalNoiseNrg_off, + hPrivateData->headroom_TCX_noise, + hInfo->nfSeed ); } /* selected source spectrum is pSpecFlat, pSpecFlat contains the signal before the LPC reshaping */ sel_spec = src_spec; @@ -618,18 +614,17 @@ static void IGF_prep(IGF_DEC_PRIVATE_DATA_HANDLE hPrivate move16(); } /* generate the raw IGF spectrum out if the selected spectrum */ - FOR (sfb = hGrid->sfbWrap[tile_idx]; sfb < hGrid->sfbWrap[tile_idx + 1]; sfb++) + FOR( sfb = hGrid->sfbWrap[tile_idx]; sfb < hGrid->sfbWrap[tile_idx + 1]; sfb++ ) { - FOR (tb = hGrid->swb_offset[sfb]; tb < hGrid->swb_offset[sfb + 1]; tb++) + FOR( tb = hGrid->swb_offset[sfb]; tb < hGrid->swb_offset[sfb + 1]; tb++ ) { igf_spec[tb] = sel_spec[strt_cpy]; move32(); - strt_cpy = add(strt_cpy, 1); + strt_cpy = add( strt_cpy, 1 ); } } } } - } /**********************************************************************/ /* @@ -1213,80 +1208,79 @@ static void IGF_prepStereo( /**********************************************************************/ /* calculates IGF energies **************************************************************************/ -static void IGF_calc(IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in: | IGF private data handle */ - const Word16 igfGridIdx, /**< in: Q0 | in case of CELP->TCX switching, use 1.25 framelength */ - const Word32 *spectrum, /**< in: Q31 | MDCT spectrum */ - const Word16 spectrum_e, /**< in: | exponent of pSpectralData */ - Word32 *igf_spec, /**< in: Q31 | prepared IGF spectrum */ - Word16 *igf_spec_e /**< in: | array exponents of igf_spec, one exponent per tile */ - ) +static void IGF_calc( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in: | IGF private data handle */ + const Word16 igfGridIdx, /**< in: Q0 | in case of CELP->TCX switching, use 1.25 framelength */ + const Word32 *spectrum, /**< in: Q31 | MDCT spectrum */ + const Word16 spectrum_e, /**< in: | exponent of pSpectralData */ + Word32 *igf_spec, /**< in: Q31 | prepared IGF spectrum */ + Word16 *igf_spec_e /**< in: | array exponents of igf_spec, one exponent per tile */ +) { H_IGF_GRID hGrid; Word16 i; - Word32 *igf_pN; /* Q31 | processed energy */ - Word16 *igf_pN_e; /* | exponents of igf_pN, one for each entry of igf_pN */ - Word32 *igf_sN; /* Q31 | survived energy */ - Word16 *igf_sN_e; /* | exponents of igf_sN, one for each entry of igf_sN */ - Word32 squaredSpectra[IGF_MAX_GRANULE_LEN]; /* Q31 | MDCT^2 spectra */ - Word16 squaredSpectra_e[IGF_MAX_TILES]; /* | exponents of squaredSpectra, one exponent per tile! */ + Word32 *igf_pN; /* Q31 | processed energy */ + Word16 *igf_pN_e; /* | exponents of igf_pN, one for each entry of igf_pN */ + Word32 *igf_sN; /* Q31 | survived energy */ + Word16 *igf_sN_e; /* | exponents of igf_sN, one for each entry of igf_sN */ + Word32 squaredSpectra[IGF_MAX_GRANULE_LEN]; /* Q31 | MDCT^2 spectra */ + Word16 squaredSpectra_e[IGF_MAX_TILES]; /* | exponents of squaredSpectra, one exponent per tile! */ /* initialize variables */ - hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; - igf_pN = hPrivateData->igf_pN; + hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; + igf_pN = hPrivateData->igf_pN; igf_pN_e = hPrivateData->igf_pN_e; - igf_sN = hPrivateData->igf_sN; + igf_sN = hPrivateData->igf_sN; igf_sN_e = hPrivateData->igf_sN_e; - set32_fx(squaredSpectra, 0, IGF_MAX_GRANULE_LEN); - set16_fx(squaredSpectra_e, 0, IGF_MAX_TILES); + set32_fx( squaredSpectra, 0, IGF_MAX_GRANULE_LEN ); + set16_fx( squaredSpectra_e, 0, IGF_MAX_TILES ); /* square the original spectrum */ - IGFCommonFuncsMDCTSquareSpec(hGrid->startLine, - hGrid->stopLine, - spectrum, - spectrum_e, - squaredSpectra, - squaredSpectra_e, - 0); + IGFCommonFuncsMDCTSquareSpec( hGrid->startLine, + hGrid->stopLine, + spectrum, + spectrum_e, + squaredSpectra, + squaredSpectra_e, + 0 ); /* calculate the energy per SFB of the survied subbands */ - IGFCommonFuncsCalcSfbEnergyPowerSpec(hGrid->startSfb, - hGrid->stopSfb, - hGrid->swb_offset, - squaredSpectra, - squaredSpectra_e, - igf_sN, - igf_sN_e); + IGFCommonFuncsCalcSfbEnergyPowerSpec( hGrid->startSfb, + hGrid->stopSfb, + hGrid->swb_offset, + squaredSpectra, + squaredSpectra_e, + igf_sN, + igf_sN_e ); /* loop over tiles, every tile has his own exponent! */ - FOR (i = 0; i < hGrid->nTiles; i++) + FOR( i = 0; i < hGrid->nTiles; i++ ) { /* square the prepared IGF spectrum */ - IGFCommonFuncsMDCTSquareSpec(hGrid->tile[i], - hGrid->tile[i + 1], - igf_spec, - igf_spec_e[i], - squaredSpectra, - &squaredSpectra_e[i], - 0); + IGFCommonFuncsMDCTSquareSpec( hGrid->tile[i], + hGrid->tile[i + 1], + igf_spec, + igf_spec_e[i], + squaredSpectra, + &squaredSpectra_e[i], + 0 ); /* set all squared values to 0, if the core contains survied lines */ - IGF_setLinesToZero(hGrid->tile[i], - hGrid->tile[i + 1], - spectrum, - squaredSpectra); + IGF_setLinesToZero( hGrid->tile[i], + hGrid->tile[i + 1], + spectrum, + squaredSpectra ); /* calculate the energy per SFB of the processed subbands */ - IGFCommonFuncsCalcSfbEnergyPowerSpec(hGrid->sfbWrap[i], - hGrid->sfbWrap[i + 1], - hGrid->swb_offset, - squaredSpectra, - &squaredSpectra_e[i], - igf_pN, - igf_pN_e); + IGFCommonFuncsCalcSfbEnergyPowerSpec( hGrid->sfbWrap[i], + hGrid->sfbWrap[i + 1], + hGrid->swb_offset, + squaredSpectra, + &squaredSpectra_e[i], + igf_pN, + igf_pN_e ); } - } @@ -1371,16 +1365,16 @@ static void IGF_calc_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /**********************************************************************/ /* apply IGF **************************************************************************/ -static void IGF_appl(IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in: | IGF private data handle */ - const Word16 igfGridIdx, /**< in: Q0 | in case of CELP->TCX switching, use 1.25 framelength */ - Word32 *spectrum, /**< in: Q31 | MDCT spectrum */ - Word16 *spectrum_e, /**< in: | exponent of pSpectralData */ - const Word32 *igf_spec, /**< in: Q31 | prepared IGF spectrum */ - const Word16 *igf_spec_e, /**< in: | array exponents of igf_spec, one exponent per tile */ - Word32 *virtualSpec, /**< out:Q31 | virtual IGF spectrum, used for temp flattening */ - Word16 *virtualSpec_e, /**< out: | exponent of virtualSpec */ - Word16 *flag_sparse /**< out: Q0 | temp flattening indicator */ - ) +static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in: | IGF private data handle */ + const Word16 igfGridIdx, /**< in: Q0 | in case of CELP->TCX switching, use 1.25 framelength */ + Word32 *spectrum, /**< in: Q31 | MDCT spectrum */ + Word16 *spectrum_e, /**< in: | exponent of pSpectralData */ + const Word32 *igf_spec, /**< in: Q31 | prepared IGF spectrum */ + const Word16 *igf_spec_e, /**< in: | array exponents of igf_spec, one exponent per tile */ + Word32 *virtualSpec, /**< out:Q31 | virtual IGF spectrum, used for temp flattening */ + Word16 *virtualSpec_e, /**< out: | exponent of virtualSpec */ + Word16 *flag_sparse /**< out: Q0 | temp flattening indicator */ +) { H_IGF_GRID hGrid; Word16 i; @@ -1396,19 +1390,19 @@ static void IGF_appl(IGF_DEC_PRIVATE_DATA_HANDLE hPrivate Word16 hopsize; Word16 sum; Word16 tileIdx; - Word16 width; /* Q0 | width of the current sfb */ - Word16 width_e; /* | exponent of widthent sfb, initialized as 15! */ - Word16 gFactor; /* 1Q14 | general SCF adaption */ - Word16 fFactor; /* 1Q14 | first SCF adaption */ - Word16 lFactor; /* 1Q14 | last SCF adaption */ - Word16 w0; /* Q15 | float value: 0.201f */ - Word16 w1; /* Q15 | float value: 0.389f */ - Word16 w2; /* Q15 | float value: 0.410f */ - Word16 dE; /* Q31 | energy below igfBgn */ - Word16 dE_e ; /* | exponent of dE */ - Word16 gn; /* Q0 | gain read from bitstream + processing */ - Word16 gn_e; /* | exponent of gn */ - Word16 maxGain_e; /* | maximal gain exponent over sfbs */ + Word16 width; /* Q0 | width of the current sfb */ + Word16 width_e; /* | exponent of widthent sfb, initialized as 15! */ + Word16 gFactor; /* 1Q14 | general SCF adaption */ + Word16 fFactor; /* 1Q14 | first SCF adaption */ + Word16 lFactor; /* 1Q14 | last SCF adaption */ + Word16 w0; /* Q15 | float value: 0.201f */ + Word16 w1; /* Q15 | float value: 0.389f */ + Word16 w2; /* Q15 | float value: 0.410f */ + Word16 dE; /* Q31 | energy below igfBgn */ + Word16 dE_e; /* | exponent of dE */ + Word16 gn; /* Q0 | gain read from bitstream + processing */ + Word16 gn_e; /* | exponent of gn */ + Word16 maxGain_e; /* | maximal gain exponent over sfbs */ Word16 tmp; Word16 tmp_e; Word16 tmp_loop; @@ -1441,263 +1435,263 @@ static void IGF_appl(IGF_DEC_PRIVATE_DATA_HANDLE hPrivate /* initialize variables */ - w0 = 6586; + w0 = 6586; move16(); - w1 = 12747; + w1 = 12747; move16(); - w2 = 13435; + w2 = 13435; move16(); - dE = 0; + dE = 0; move16(); - dE_e = 0; + dE_e = 0; move16(); - tmp = 0; + tmp = 0; move16(); - s = 0; + s = 0; move16(); - tmp_e = 0; + tmp_e = 0; move16(); - gn = 0; + gn = 0; move16(); - gn_e = 0; + gn_e = 0; move16(); - maxGain_e = 0; + maxGain_e = 0; move16(); - L_tmp_e = 0; + L_tmp_e = 0; move16(); - dNlocal_e = 0; + dNlocal_e = 0; move16(); - L_tmp = 0; - move32(); - dNlocal = 0; - move32(); + L_tmp = 0; + move32(); + dNlocal = 0; + move32(); - set16_fx(gain, 0, IGF_MAX_SFB); - set16_fx(gain_e, 0, IGF_MAX_SFB); - set16_fx(dN, 0, add(IGF_MAX_SFB,1)); - set16_fx(dN_e, 0, add(IGF_MAX_SFB,1)); - set16_fx(dS, 0, IGF_MAX_SFB); - set16_fx(dS_e, 0, IGF_MAX_SFB); - set32_fx(energyTmp, 0, 24); + set16_fx( gain, 0, IGF_MAX_SFB ); + set16_fx( gain_e, 0, IGF_MAX_SFB ); + set16_fx( dN, 0, add( IGF_MAX_SFB, 1 ) ); + set16_fx( dN_e, 0, add( IGF_MAX_SFB, 1 ) ); + set16_fx( dS, 0, IGF_MAX_SFB ); + set16_fx( dS_e, 0, IGF_MAX_SFB ); + set32_fx( energyTmp, 0, 24 ); /* more inits */ - hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; - sN = hPrivateData->igf_sN; - sN_e = hPrivateData->igf_sN_e; - pN = hPrivateData->igf_pN; - pN_e = hPrivateData->igf_pN_e; - start_sfb = hGrid->startSfb; + hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; + sN = hPrivateData->igf_sN; + sN_e = hPrivateData->igf_sN_e; + pN = hPrivateData->igf_pN; + pN_e = hPrivateData->igf_pN_e; + start_sfb = hGrid->startSfb; move16(); - stop_sfb = hGrid->stopSfb; + stop_sfb = hGrid->stopSfb; move16(); - gFactor = hGrid->gFactor; + gFactor = hGrid->gFactor; move16(); - fFactor = hGrid->fFactor; + fFactor = hGrid->fFactor; move16(); - lFactor = hGrid->lFactor; + lFactor = hGrid->lFactor; move16(); /* reset virtual spec */ - set16_fx(flag_sparse, 0, N_MAX_TCX-IGF_START_MN); - set32_fx(virtualSpec, 0, N_MAX_TCX-IGF_START_MN); + set16_fx( flag_sparse, 0, N_MAX_TCX - IGF_START_MN ); + set32_fx( virtualSpec, 0, N_MAX_TCX - IGF_START_MN ); *virtualSpec_e = *spectrum_e; move16(); /* collect energy below hGrid->startLine: */ - tmp = sub(hGrid->startLine, 24); - IGFCommonFuncsMDCTSquareSpec(tmp, - hGrid->startLine, - spectrum, - *spectrum_e, - energyTmp, - &dE_e, - negate(tmp)); + tmp = sub( hGrid->startLine, 24 ); + IGFCommonFuncsMDCTSquareSpec( tmp, + hGrid->startLine, + spectrum, + *spectrum_e, + energyTmp, + &dE_e, + negate( tmp ) ); L_c = 0; - move32(); - FOR (tb = 0; tb < 24; tb++) + move32(); + FOR( tb = 0; tb < 24; tb++ ) { - Carry = 0; -#ifdef BASOP_NOGLOB /* Critical Carry/Overflow*/ - L_tmp = L_add_co(L_tmp, energyTmp[tb], &Carry, &Overflow); + Carry = 0; +#ifdef BASOP_NOGLOB /* Critical Carry/Overflow*/ + L_tmp = L_add_co( L_tmp, energyTmp[tb], &Carry, &Overflow ); Overflow = 0; - L_c = L_macNs_co(L_c, 0, 0, &Carry, &Overflow); + L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); #else - L_tmp = L_add_c(L_tmp, energyTmp[tb]); + L_tmp = L_add_c( L_tmp, energyTmp[tb] ); Overflow = 0; - L_c = L_macNs(L_c, 0, 0); + L_c = L_macNs( L_c, 0, 0 ); #endif } - L_tmp = norm_llQ31(L_c, L_tmp, &shift); + L_tmp = norm_llQ31( L_c, L_tmp, &shift ); /* float: dE = (float)sqrt(dE / 24.f); basop: */ - shift = add(sub(shift, 4), dE_e); /* x/24 = (x >> 4) * 1/1.5 */ - dE = Sqrt16norm(extract_h(L_tmp), &shift); - dE = mult_r(dE, 26755/*0.81649658092772603273242802490196f Q15*/); /* 0.81649658092772603273242802490196f = sqrt(1/1.5)) */ - dE_e = shift; + shift = add( sub( shift, 4 ), dE_e ); /* x/24 = (x >> 4) * 1/1.5 */ + dE = Sqrt16norm( extract_h( L_tmp ), &shift ); + dE = mult_r( dE, 26755 /*0.81649658092772603273242802490196f Q15*/ ); /* 0.81649658092772603273242802490196f = sqrt(1/1.5)) */ + dE_e = shift; move16(); /* select correct hopsize for envelope refinement */ hopsize = 2; move16(); - if (EQ_16(hPrivateData->currWhiteningLevel[0], IGF_WHITENING_OFF)) + if ( EQ_16( hPrivateData->currWhiteningLevel[0], IGF_WHITENING_OFF ) ) { hopsize = 4; move16(); } - if (EQ_16(hPrivateData->currWhiteningLevel[0], IGF_WHITENING_STRONG)) + if ( EQ_16( hPrivateData->currWhiteningLevel[0], IGF_WHITENING_STRONG ) ) { hopsize = 1; move16(); } - hopsize = s_min(hopsize, hPrivateData->igfInfo.maxHopsize); + hopsize = s_min( hopsize, hPrivateData->igfInfo.maxHopsize ); - IF (hopsize > 1) + IF( hopsize > 1 ) { - FOR (sfb = start_sfb; sfb < stop_sfb; sfb += hopsize) + FOR( sfb = start_sfb; sfb < stop_sfb; sfb += hopsize ) { - tmp_loop = s_min(add(sfb, hopsize), stop_sfb); - FOR (tb = add(sfb, 1); tb < tmp_loop; tb++) + tmp_loop = s_min( add( sfb, hopsize ), stop_sfb ); + FOR( tb = add( sfb, 1 ); tb < tmp_loop; tb++ ) { - sN[sfb] = BASOP_Util_Add_Mant32Exp(sN[sfb], - sN_e[sfb], - sN[tb], - sN_e[tb], - &sN_e[sfb]); + sN[sfb] = BASOP_Util_Add_Mant32Exp( sN[sfb], + sN_e[sfb], + sN[tb], + sN_e[tb], + &sN_e[sfb] ); move32(); - pN[sfb] = BASOP_Util_Add_Mant32Exp(pN[sfb], - pN_e[sfb], - pN[tb], - pN_e[tb], - &pN_e[sfb]); + pN[sfb] = BASOP_Util_Add_Mant32Exp( pN[sfb], + pN_e[sfb], + pN[tb], + pN_e[tb], + &pN_e[sfb] ); move32(); - sN[tb] = L_deposit_l(0); - pN[tb] = L_deposit_l(0); + sN[tb] = L_deposit_l( 0 ); + pN[tb] = L_deposit_l( 0 ); } } } /* IGF_rescale_SCF */ - IF (hGrid->infoIsRefined != 0) + IF( hGrid->infoIsRefined != 0 ) { - FOR (sfb = start_sfb; sfb < stop_sfb; sfb += 2) + FOR( sfb = start_sfb; sfb < stop_sfb; sfb += 2 ) { /* calculate and normalize the width of the current sfb */ - width = sub(hGrid->swb_offset[sfb + 2], hGrid->swb_offset[sfb]); - shift = norm_s(width); - width = shl(width, shift); - width_e = sub(15, shift); /* initial value of width_e is 15, -> width = 15Q0 */ + width = sub( hGrid->swb_offset[sfb + 2], hGrid->swb_offset[sfb] ); + shift = norm_s( width ); + width = shl( width, shift ); + width_e = sub( 15, shift ); /* initial value of width_e is 15, -> width = 15Q0 */ /* float: gn = 0.25f * igf_curr - 4.f; basop: */ - gn = hPrivateData->igf_curr[shr(sfb,1)]; + gn = hPrivateData->igf_curr[shr( sfb, 1 )]; move16(); move16(); - gn_e = 13; /* set exponent of igf_curr to 13 = 15 - 2; -> igf_curr = igf_curr * 0.25, virtual division by 4 */ - gn = sub(gn, 16); /* 13Q2 | 4 = 16 * 2^(-15 + 13); ("4" has same exponent as igf_curr now) */ + gn_e = 13; /* set exponent of igf_curr to 13 = 15 - 2; -> igf_curr = igf_curr * 0.25, virtual division by 4 */ + gn = sub( gn, 16 ); /* 13Q2 | 4 = 16 * 2^(-15 + 13); ("4" has same exponent as igf_curr now) */ /* float: tmp = pow(2.f, gn); basop: */ - L_tmp = BASOP_util_Pow2(L_deposit_h(gn), gn_e, &L_tmp_e); + L_tmp = BASOP_util_Pow2( L_deposit_h( gn ), gn_e, &L_tmp_e ); /* float: tmp = tmp * tmp; basop: */ - tmp = round_fx(L_tmp); - L_tmp = L_mult(tmp, tmp); - L_tmp_e = add(L_tmp_e, L_tmp_e); + tmp = round_fx( L_tmp ); + L_tmp = L_mult( tmp, tmp ); + L_tmp_e = add( L_tmp_e, L_tmp_e ); /* get sNlocal | float: sNlocal = sN[ sfb ] + sN[ sfb+ 1 ]; basop: */ - sNlocal = BASOP_Util_Add_Mant32Exp(sN[sfb], - sN_e[sfb], - sN[sfb + 1], - sN_e[sfb + 1], - &sNlocal_e); + sNlocal = BASOP_Util_Add_Mant32Exp( sN[sfb], + sN_e[sfb], + sN[sfb + 1], + sN_e[sfb + 1], + &sNlocal_e ); /* float: sNlocal /= width; basop: */ - shift = sub(norm_l(sNlocal), 1); /* leave MSB empty, so in the division sNlocal is always smaller than width */ - sNlocal = L_deposit_h(div_s(extract_h(L_shl(sNlocal, shift)), width)); - sNlocal_e = sub(sub(sNlocal_e, shift), width_e); + shift = sub( norm_l( sNlocal ), 1 ); /* leave MSB empty, so in the division sNlocal is always smaller than width */ + sNlocal = L_deposit_h( div_s( extract_h( L_shl( sNlocal, shift ) ), width ) ); + sNlocal_e = sub( sub( sNlocal_e, shift ), width_e ); /* float: tmp = max(0.001 * sNlocal, tmp - sNlocal); basop: */ - L_tmp = BASOP_Util_Add_Mant32Exp(L_tmp, - L_tmp_e, - L_negate(sNlocal), - sNlocal_e, - &L_tmp_e); /* float: tmp = tmp - sNlocal */ + L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, + L_tmp_e, + L_negate( sNlocal ), + sNlocal_e, + &L_tmp_e ); /* float: tmp = tmp - sNlocal */ /* max(0.001 * sNlocal, L_tmp) */ /* Build a threshold and compare with L_tmp. Build negated threshold and compare with negated L_tmp to cover also fullscale L_tmp case */ BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB - L_tmp2 = L_shl_sat(L_negate(Mpy_32_16_1(sNlocal, 33/*0.001f Q15*/)), sub(sNlocal_e, L_tmp_e)); - L_tmp2 = L_sub_sat(L_tmp2, L_negate(L_tmp)); + L_tmp2 = L_shl_sat( L_negate( Mpy_32_16_1( sNlocal, 33 /*0.001f Q15*/ ) ), sub( sNlocal_e, L_tmp_e ) ); + L_tmp2 = L_sub_sat( L_tmp2, L_negate( L_tmp ) ); #else - L_tmp2 = L_shl(L_negate(Mpy_32_16_1(sNlocal, 33/*0.001f Q15*/)), sub(sNlocal_e, L_tmp_e)); - L_tmp2 = L_sub(L_tmp2, L_negate(L_tmp)); + L_tmp2 = L_shl( L_negate( Mpy_32_16_1( sNlocal, 33 /*0.001f Q15*/ ) ), sub( sNlocal_e, L_tmp_e ) ); + L_tmp2 = L_sub( L_tmp2, L_negate( L_tmp ) ); #endif BASOP_SATURATE_WARNING_ON_EVS - IF (L_tmp2 < 0) + IF( L_tmp2 < 0 ) { - L_tmp = Mpy_32_16_1( sNlocal,33/*0.001f Q15*/); + L_tmp = Mpy_32_16_1( sNlocal, 33 /*0.001f Q15*/ ); L_tmp_e = sNlocal_e; move16(); } /* calc square root of L_tmp and store result in dN */ - L_tmp = Sqrt32(L_tmp, &L_tmp_e); + L_tmp = Sqrt32( L_tmp, &L_tmp_e ); #ifdef BASOP_NOGLOB dN[sfb] = round_fx_sat( L_tmp ); #else - dN[sfb] = round_fx(L_tmp); + dN[sfb] = round_fx( L_tmp ); #endif - dN_e[sfb] = L_tmp_e; + dN_e[sfb] = L_tmp_e; move16(); - dN[sfb+1] = dN[sfb]; + dN[sfb + 1] = dN[sfb]; move16(); - dN_e[sfb+1] = dN_e[sfb]; + dN_e[sfb + 1] = dN_e[sfb]; move16(); } } ELSE { - FOR (sfb = start_sfb; sfb < stop_sfb; sfb++) + FOR( sfb = start_sfb; sfb < stop_sfb; sfb++ ) { /* calculate and normalize the width of the current sfb */ - width = sub(hGrid->swb_offset[sfb + 1], hGrid->swb_offset[sfb]); - shift = norm_s(width); - width = shl(width, shift); - width_e = sub(15, shift); /* initial value of width_e is 15, -> width = 15Q0 */ + width = sub( hGrid->swb_offset[sfb + 1], hGrid->swb_offset[sfb] ); + shift = norm_s( width ); + width = shl( width, shift ); + width_e = sub( 15, shift ); /* initial value of width_e is 15, -> width = 15Q0 */ /* float: gn = 0.25f * igf_curr - 4.f; basop: */ - gn = hPrivateData->igf_curr[sfb]; + gn = hPrivateData->igf_curr[sfb]; move16(); move16(); - gn_e = 13; /* set exponent of igf_curr to 13 = 15 - 2; -> igf_curr = igf_curr * 0.25, virtual division by 4 */ - gn = sub(gn, 16); /* 13Q2 | 4 = 16 * 2^(-15 + 13); ("4" has same exponent as igf_curr now) */ + gn_e = 13; /* set exponent of igf_curr to 13 = 15 - 2; -> igf_curr = igf_curr * 0.25, virtual division by 4 */ + gn = sub( gn, 16 ); /* 13Q2 | 4 = 16 * 2^(-15 + 13); ("4" has same exponent as igf_curr now) */ /* float: tmp = pow(2.f, gn); basop: */ - L_tmp = BASOP_util_Pow2(L_deposit_h(gn), gn_e, &L_tmp_e); + L_tmp = BASOP_util_Pow2( L_deposit_h( gn ), gn_e, &L_tmp_e ); /* float: tmp = tmp * tmp; basop: */ - tmp = round_fx(L_tmp); - L_tmp = L_mult(tmp, tmp); - L_tmp_e = add(L_tmp_e, L_tmp_e); + tmp = round_fx( L_tmp ); + L_tmp = L_mult( tmp, tmp ); + L_tmp_e = add( L_tmp_e, L_tmp_e ); /* get sNlocal */ - sNlocal = sN[sfb]; + sNlocal = sN[sfb]; move32(); sNlocal_e = sN_e[sfb]; move16(); /* float: sNlocal /= width; basop: */ - shift = sub(norm_l(sNlocal), 1); /* leave MSB empty, so in the division sNlocal is always smaller than width */ - sNlocal = L_deposit_h(div_s(extract_h(L_shl(sNlocal, shift)), width)); - sNlocal_e = sub(sub(sNlocal_e, shift), width_e); + shift = sub( norm_l( sNlocal ), 1 ); /* leave MSB empty, so in the division sNlocal is always smaller than width */ + sNlocal = L_deposit_h( div_s( extract_h( L_shl( sNlocal, shift ) ), width ) ); + sNlocal_e = sub( sub( sNlocal_e, shift ), width_e ); /* float: tmp = max(0.001 * sNlocal, tmp - sNlocal); basop: */ - L_tmp = BASOP_Util_Add_Mant32Exp(L_tmp, - L_tmp_e, - L_negate(sNlocal), - sNlocal_e, - &L_tmp_e); /* float: tmp = tmp - sNlocal */ + L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, + L_tmp_e, + L_negate( sNlocal ), + sNlocal_e, + &L_tmp_e ); /* float: tmp = tmp - sNlocal */ /* max(0.001 * sNlocal, L_tmp) */ /* Build a threshold and compare with L_tmp. @@ -1705,207 +1699,207 @@ static void IGF_appl(IGF_DEC_PRIVATE_DATA_HANDLE hPrivate BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB L_tmp2 = L_shl_sat( L_negate( Mpy_32_16_1( sNlocal, 33 /*0.001f Q15*/ ) ), sub( sNlocal_e, L_tmp_e ) ); - L_tmp2 = L_sub_sat(L_tmp2, L_negate(L_tmp)); + L_tmp2 = L_sub_sat( L_tmp2, L_negate( L_tmp ) ); #else - L_tmp2 = L_shl(L_negate(Mpy_32_16_1(sNlocal, 33/*0.001f Q15*/)), sub(sNlocal_e,L_tmp_e)); - L_tmp2 = L_sub(L_tmp2, L_negate(L_tmp)); + L_tmp2 = L_shl( L_negate( Mpy_32_16_1( sNlocal, 33 /*0.001f Q15*/ ) ), sub( sNlocal_e, L_tmp_e ) ); + L_tmp2 = L_sub( L_tmp2, L_negate( L_tmp ) ); #endif BASOP_SATURATE_WARNING_ON_EVS - IF (L_tmp2 < 0 ) + IF( L_tmp2 < 0 ) { - L_tmp = Mpy_32_16_1(sNlocal,33/*0.001f Q15*/); + L_tmp = Mpy_32_16_1( sNlocal, 33 /*0.001f Q15*/ ); L_tmp_e = sNlocal_e; } /* calc square root of L_tmp and store result in dN */ - L_tmp = Sqrt32(L_tmp, &L_tmp_e); - dN[sfb] = round_fx(L_tmp); + L_tmp = Sqrt32( L_tmp, &L_tmp_e ); + dN[sfb] = round_fx( L_tmp ); dN_e[sfb] = L_tmp_e; move16(); } } - dS[start_sfb] = dN[start_sfb]; + dS[start_sfb] = dN[start_sfb]; move16(); dS_e[start_sfb] = dN_e[start_sfb]; move16(); /* first value with adaption to core energy: */ - tmp_e = BASOP_Util_Add_MantExp(dE, - dE_e, - negate(dN[start_sfb]), - dN_e[start_sfb], - &tmp); /* float: tmp = dE - dN[start_sfb] */ - IF (tmp < 0) + tmp_e = BASOP_Util_Add_MantExp( dE, + dE_e, + negate( dN[start_sfb] ), + dN_e[start_sfb], + &tmp ); /* float: tmp = dE - dN[start_sfb] */ + IF( tmp < 0 ) { /* float: dS[start_sfb] = dN[start_sfb] + fFactor * (dE-dN[start_sfb]); basop: */ - L_tmp = L_mult(fFactor, tmp); - L_tmp_e = add(tmp_e, 1); /* 1Q14 | fFactor is 1Q14 */ - dS_e[start_sfb] = BASOP_Util_Add_MantExp(dN[start_sfb], - dN_e[start_sfb], - round_fx(L_tmp), - L_tmp_e, - &dS[start_sfb]); + L_tmp = L_mult( fFactor, tmp ); + L_tmp_e = add( tmp_e, 1 ); /* 1Q14 | fFactor is 1Q14 */ + dS_e[start_sfb] = BASOP_Util_Add_MantExp( dN[start_sfb], + dN_e[start_sfb], + round_fx( L_tmp ), + L_tmp_e, + &dS[start_sfb] ); move16(); } /* last value with less energy: */ - dS[stop_sfb - 1] = mult_r(lFactor, dN[stop_sfb - 1]); + dS[stop_sfb - 1] = mult_r( lFactor, dN[stop_sfb - 1] ); move16(); move16(); - dS_e[stop_sfb - 1] = add(dN_e[stop_sfb - 1], 1); /* 1Q14 | lFactor is 1Q14 */ + dS_e[stop_sfb - 1] = add( dN_e[stop_sfb - 1], 1 ); /* 1Q14 | lFactor is 1Q14 */ - sfb_p1 = add(start_sfb, 1); - sfb_m1 = sub(stop_sfb, 1); + sfb_p1 = add( start_sfb, 1 ); + sfb_m1 = sub( stop_sfb, 1 ); test(); - IF (hGrid->infoIsRefined != 0 && EQ_16(hopsize, 1)) + IF( hGrid->infoIsRefined != 0 && EQ_16( hopsize, 1 ) ) { /* apply filter to absolute energy values: */ - FOR (sfb = sfb_p1; sfb < sfb_m1; sfb++) + FOR( sfb = sfb_p1; sfb < sfb_m1; sfb++ ) { /* float: dS[sfb] = w0 * dN[sfb-1] + w1 * dN[sfb+0] + w2 * dN[sfb+1]; basop: */ - L_tmp = L_mult(w0, dN[sfb - 1]); - dS[sfb] = round_fx(L_tmp); + L_tmp = L_mult( w0, dN[sfb - 1] ); + dS[sfb] = round_fx( L_tmp ); move16(); - dS_e[sfb] = dN_e[sfb-1]; /* w0 is Q15, so no need to add an exponent */ - L_tmp = L_mult(w1, dN[sfb]); - dS_e[sfb] = BASOP_Util_Add_MantExp(dS[sfb], - dS_e[sfb], - round_fx(L_tmp), - dN_e[sfb], /* w1 is Q15, so no need to add an exponent */ - &tmp); + dS_e[sfb] = dN_e[sfb - 1]; /* w0 is Q15, so no need to add an exponent */ + L_tmp = L_mult( w1, dN[sfb] ); + dS_e[sfb] = BASOP_Util_Add_MantExp( dS[sfb], + dS_e[sfb], + round_fx( L_tmp ), + dN_e[sfb], /* w1 is Q15, so no need to add an exponent */ + &tmp ); move16(); - dS[sfb] = tmp; + dS[sfb] = tmp; move16(); - L_tmp = L_mult(w2, dN[sfb + 1]); - dS_e[sfb] = BASOP_Util_Add_MantExp(dS[sfb], - dS_e[sfb], - round_fx(L_tmp), - dN_e[sfb + 1], /* w2 is Q15, so no need to add an exponent */ - &tmp); + L_tmp = L_mult( w2, dN[sfb + 1] ); + dS_e[sfb] = BASOP_Util_Add_MantExp( dS[sfb], + dS_e[sfb], + round_fx( L_tmp ), + dN_e[sfb + 1], /* w2 is Q15, so no need to add an exponent */ + &tmp ); move16(); - dS[sfb] = tmp; + dS[sfb] = tmp; move16(); } } ELSE { - FOR (sfb = sfb_p1; sfb < sfb_m1; sfb++) + FOR( sfb = sfb_p1; sfb < sfb_m1; sfb++ ) { - dS[sfb] = dN[sfb]; + dS[sfb] = dN[sfb]; move16(); dS_e[sfb] = dN_e[sfb]; move16(); } } - Hr = 0; + Hr = 0; move16(); tileIdx = -1; move16(); - FOR (sfb = start_sfb; sfb < stop_sfb; sfb += hopsize) + FOR( sfb = start_sfb; sfb < stop_sfb; sfb += hopsize ) { - E = 0; - move32(); + E = 0; + move32(); E_e = 0; move16(); sum = 0; move16(); - FOR (tb = 0; tb < hopsize; tb++) + FOR( tb = 0; tb < hopsize; tb++ ) { /* calculate of the current sfb width */ - width = sub(hGrid->swb_offset[s_min(add(add(sfb, tb), 1), stop_sfb)], /* 15Q0 | width is Q0 */ - hGrid->swb_offset[s_min(add(sfb, tb), stop_sfb)]); + width = sub( hGrid->swb_offset[s_min( add( add( sfb, tb ), 1 ), stop_sfb )], /* 15Q0 | width is Q0 */ + hGrid->swb_offset[s_min( add( sfb, tb ), stop_sfb )] ); - tmp = dS[s_min(add(sfb, tb), sub(stop_sfb, 1))]; - tmp_e = dS_e[s_min(add(sfb, tb), sub(stop_sfb, 1))]; + tmp = dS[s_min( add( sfb, tb ), sub( stop_sfb, 1 ) )]; + tmp_e = dS_e[s_min( add( sfb, tb ), sub( stop_sfb, 1 ) )]; /* square tmp */ - L_tmp = L_mult(tmp, tmp); - L_tmp_e = add(tmp_e, tmp_e); + L_tmp = L_mult( tmp, tmp ); + L_tmp_e = add( tmp_e, tmp_e ); /* mult L_tmp times width */ - L_tmp = L_mult(round_fx(L_tmp), width); - L_tmp_e = add(L_tmp_e, 15); /* 15Q0 | width is Q0 */ + L_tmp = L_mult( round_fx( L_tmp ), width ); + L_tmp_e = add( L_tmp_e, 15 ); /* 15Q0 | width is Q0 */ /* calculate resulting energy */ - E = BASOP_Util_Add_Mant32Exp(E, - E_e, - L_tmp, - L_tmp_e, - &E_e); - sum = add(sum, width); /* 15Q0 | sum shares its exponent with width */ + E = BASOP_Util_Add_Mant32Exp( E, + E_e, + L_tmp, + L_tmp_e, + &E_e ); + sum = add( sum, width ); /* 15Q0 | sum shares its exponent with width */ } /* normalize sum for the following division */ - shift = norm_s(sum); - sum = shl(sum, shift); /* exponent of sum: sub(15, shift) */ + shift = norm_s( sum ); + sum = shl( sum, shift ); /* exponent of sum: sub(15, shift) */ /* divide E by sum */ -#ifdef BASOP_NOGLOB /* Critical Carry/Overflow*/ - tmp = div_s(shr(round_fx_o(E, &Overflow), 1), sum); /* shift E 1 bit to the right in order to make it smaller than sum */ +#ifdef BASOP_NOGLOB /* Critical Carry/Overflow*/ + tmp = div_s( shr( round_fx_o( E, &Overflow ), 1 ), sum ); /* shift E 1 bit to the right in order to make it smaller than sum */ #else - tmp = div_s(shr(round_fx(E), 1), sum); /* shift E 1 bit to the right in order to make it smaller than sum */ + tmp = div_s( shr( round_fx( E ), 1 ), sum ); /* shift E 1 bit to the right in order to make it smaller than sum */ #endif - tmp_e = sub(add(E_e, 1), sub(15, shift)); /* 15Q0 | sum is 15Q0 */ + tmp_e = sub( add( E_e, 1 ), sub( 15, shift ) ); /* 15Q0 | sum is 15Q0 */ /* multiply the result by the hopsize */ - L_tmp = L_mult(tmp, hopsize); - L_tmp_e = add(tmp_e, 15); /* 15Q0 | hopsize is 15Q0 */ + L_tmp = L_mult( tmp, hopsize ); + L_tmp_e = add( tmp_e, 15 ); /* 15Q0 | hopsize is 15Q0 */ /* take the square root and store the result in dS */ - L_tmp = Sqrt32(L_tmp, &L_tmp_e); - dS[sfb] = round_fx(L_tmp); + L_tmp = Sqrt32( L_tmp, &L_tmp_e ); + dS[sfb] = round_fx( L_tmp ); dS_e[sfb] = L_tmp_e; move16(); /* calculate the new dN */ - dN[sfb] = mult_r(gFactor, dS[sfb]); + dN[sfb] = mult_r( gFactor, dS[sfb] ); move16(); move16(); - dN_e[sfb] = add(dS_e[sfb], 1); /* 1Q14 | gFactor is 1Q14 */ + dN_e[sfb] = add( dS_e[sfb], 1 ); /* 1Q14 | gFactor is 1Q14 */ /* calculate of the current sfb width */ - width = sub(hGrid->swb_offset[sfb + 1], /* 15Q0 | width is Q0 */ - hGrid->swb_offset[sfb]); + width = sub( hGrid->swb_offset[sfb + 1], /* 15Q0 | width is Q0 */ + hGrid->swb_offset[sfb] ); /* square dN */ - L_tmp = L_mult(dN[sfb], dN[sfb]); - L_tmp_e = add(dN_e[sfb], dN_e[sfb]); + L_tmp = L_mult( dN[sfb], dN[sfb] ); + L_tmp_e = add( dN_e[sfb], dN_e[sfb] ); /* mult L_tmp times width */ - shift = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, shift); - L_tmp = L_mult(round_fx(L_tmp), width); - L_tmp_e = sub(add(L_tmp_e, 15), shift); /* 15Q0 | width is Q0 */ - shift = norm_l(L_tmp); + shift = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, shift ); + L_tmp = L_mult( round_fx( L_tmp ), width ); + L_tmp_e = sub( add( L_tmp_e, 15 ), shift ); /* 15Q0 | width is Q0 */ + shift = norm_l( L_tmp ); /* store normalized result */ - dNlocal = L_shl(L_tmp, shift); - dNlocal_e = sub(L_tmp_e, shift); + dNlocal = L_shl( L_tmp, shift ); + dNlocal_e = sub( L_tmp_e, shift ); /* gain calculation */ gain[sfb] = 0; move16(); - IF (pN[sfb] != 0) + IF( pN[sfb] != 0 ) { - tmp = BASOP_Util_Divide3232_Scale(dNlocal, pN[sfb],&s); - s = sub(add(s, dNlocal_e), pN_e[sfb]); - gain[sfb] = Sqrt16(tmp, &s); + tmp = BASOP_Util_Divide3232_Scale( dNlocal, pN[sfb], &s ); + s = sub( add( s, dNlocal_e ), pN_e[sfb] ); + gain[sfb] = Sqrt16( tmp, &s ); move16(); gain_e[sfb] = s; move16(); /* get the maximal exponent of the gain array, needed for exponent adjustment of the spectrum */ - maxGain_e = s_max(maxGain_e, gain_e[sfb]); + maxGain_e = s_max( maxGain_e, gain_e[sfb] ); } - sfb_p1 = add(sfb, 1); - sfb_m1 = s_min(add(sfb, hopsize), stop_sfb); - FOR (s_sfb = sfb_p1; s_sfb < sfb_m1; s_sfb++) + sfb_p1 = add( sfb, 1 ); + sfb_m1 = s_min( add( sfb, hopsize ), stop_sfb ); + FOR( s_sfb = sfb_p1; s_sfb < sfb_m1; s_sfb++ ) { - gain[s_sfb] = gain[sfb]; + gain[s_sfb] = gain[sfb]; move16(); gain_e[s_sfb] = gain_e[sfb]; move16(); @@ -1913,25 +1907,25 @@ static void IGF_appl(IGF_DEC_PRIVATE_DATA_HANDLE hPrivate /*--- check gains /spectrum exponents for possible overflows --- */ /* get tile index */ - if (LE_16(hGrid->sfbWrap[tileIdx + 1], sfb)) + if ( LE_16( hGrid->sfbWrap[tileIdx + 1], sfb ) ) { - tileIdx = add(tileIdx, 1); + tileIdx = add( tileIdx, 1 ); } /*do a test multiplication with the highest possible value*/ - L_tmp = Mpy_32_16_1(0xFFFF8000/*igf_spec occupies only the 16LSBs */, gain[sfb]); - L_tmp_e = add(igf_spec_e[tileIdx], gain_e[sfb]); + L_tmp = Mpy_32_16_1( 0xFFFF8000 /*igf_spec occupies only the 16LSBs */, gain[sfb] ); + L_tmp_e = add( igf_spec_e[tileIdx], gain_e[sfb] ); /*check whether overflow would occur and calculate Headroom, needed*/ - shift = sub(L_tmp_e, *spectrum_e); - tmp = sub(shift , sub(norm_l(L_tmp), TCX_IMDCT_HEADROOM)); - if (tmp > 0) + shift = sub( L_tmp_e, *spectrum_e ); + tmp = sub( shift, sub( norm_l( L_tmp ), TCX_IMDCT_HEADROOM ) ); + if ( tmp > 0 ) { - Hr = s_max(Hr, tmp); + Hr = s_max( Hr, tmp ); } /* disable rescaling if gain is smaler than 1 */ /* gain < 1, if norm_s(gain[sfb]) >= gain_e[sfb] */ - tmp = sub(norm_s(gain[sfb]), gain_e[sfb]); - if (tmp >= 0) + tmp = sub( norm_s( gain[sfb] ), gain_e[sfb] ); + if ( tmp >= 0 ) { Hr = 0; move16(); @@ -1941,131 +1935,130 @@ static void IGF_appl(IGF_DEC_PRIVATE_DATA_HANDLE hPrivate /* Rescale spectrum if overflow may occur */ tileIdx = -1; move16(); - IF (Hr > 0) + IF( Hr > 0 ) { /* rescale virtual Spec, cheap and easy: reset scalingfactor */ - *virtualSpec_e = add(*virtualSpec_e, Hr); + *virtualSpec_e = add( *virtualSpec_e, Hr ); move16(); /* rescale spectrum */ - FOR (i = 0; i < hGrid->stopLine; i++) + FOR( i = 0; i < hGrid->stopLine; i++ ) { - spectrum[i] = L_shr(spectrum[i], Hr); + spectrum[i] = L_shr( spectrum[i], Hr ); move16(); } - *spectrum_e = add(*spectrum_e, Hr); + *spectrum_e = add( *spectrum_e, Hr ); move16(); } /* tiling */ tileIdx = -1; move16(); - FOR (sfb = start_sfb; sfb < stop_sfb; sfb++) + FOR( sfb = start_sfb; sfb < stop_sfb; sfb++ ) { /* get tile index */ - if (EQ_16(hGrid->sfbWrap[tileIdx + 1], sfb)) + if ( EQ_16( hGrid->sfbWrap[tileIdx + 1], sfb ) ) { - tileIdx = add(tileIdx, 1); + tileIdx = add( tileIdx, 1 ); } - IF (hPrivateData->frameLossCounter > 0) + IF( hPrivateData->frameLossCounter > 0 ) { /* normalize gain */ - tmp = norm_s(gain[sfb]); - gain[sfb] = shl(gain[sfb], tmp); - gain_e[sfb] = sub(gain_e[sfb], tmp); + tmp = norm_s( gain[sfb] ); + gain[sfb] = shl( gain[sfb], tmp ); + gain_e[sfb] = sub( gain_e[sfb], tmp ); /* gain[sfb] = min(gain[sfb], 12.f); */ - BASOP_SATURATE_WARNING_OFF_EVS /* threshold, may overflow */ + BASOP_SATURATE_WARNING_OFF_EVS /* threshold, may overflow */ #ifdef BASOP_NOGLOB - tmp = shl_sat( gain[sfb], sub( gain_e[sfb], 15 - 5 ) ); /* 10Q5 | tmp is in 10Q5 */ + tmp = shl_sat( gain[sfb], sub( gain_e[sfb], 15 - 5 ) ); /* 10Q5 | tmp is in 10Q5 */ #else - tmp = shl(gain[sfb], sub(gain_e[sfb], 15 - 5)); /* 10Q5 | tmp is in 10Q5 */ + tmp = shl( gain[sfb], sub( gain_e[sfb], 15 - 5 ) ); /* 10Q5 | tmp is in 10Q5 */ #endif BASOP_SATURATE_WARNING_ON_EVS - IF (tmp > 384) /* 10Q5 | 384 = 12 in 10Q5 */ + IF( tmp > 384 ) /* 10Q5 | 384 = 12 in 10Q5 */ { - gain[sfb] = 384; + gain[sfb] = 384; move16(); gain_e[sfb] = 10; move16(); } - IF (LT_16(hPrivateData->frameLossCounter, 5)) + IF( LT_16( hPrivateData->frameLossCounter, 5 ) ) { /* gain[sfb] -= gain[sfb] / 8 * hPrivateData->frameLossCounter; -> multiply with 0Q15 -> adaption of the exponent not needed */ - IF (EQ_16(hPrivateData->frameLossCounter, 1)) + IF( EQ_16( hPrivateData->frameLossCounter, 1 ) ) { /* 0Q15 | >> 3 ^= * 0.125 = 1 / 8 */ - gain[sfb] = sub(gain[sfb], shr_r(gain[sfb], 3)); + gain[sfb] = sub( gain[sfb], shr_r( gain[sfb], 3 ) ); move16(); } - ELSE IF (EQ_16(hPrivateData->frameLossCounter, 2)) + ELSE IF( EQ_16( hPrivateData->frameLossCounter, 2 ) ) { /* 0Q15 | >> 2 ^= * 0.25 = 2 / 8 */ - gain[sfb] = sub(gain[sfb], shr_r(gain[sfb], 2)); + gain[sfb] = sub( gain[sfb], shr_r( gain[sfb], 2 ) ); move16(); } - ELSE IF (EQ_16(hPrivateData->frameLossCounter, 3)) + ELSE IF( EQ_16( hPrivateData->frameLossCounter, 3 ) ) { /* 0Q15 | * 12288 ^= * 0.3750 = 3 / 8 */ - gain[sfb] = sub(gain[sfb], mult_r(gain[sfb], 12288)); + gain[sfb] = sub( gain[sfb], mult_r( gain[sfb], 12288 ) ); move16(); } ELSE { /* 0Q15 | >> 1 ^= * 0.5 = 4 / 8 */ - gain[sfb] = sub(gain[sfb], shr_r(gain[sfb], 1)); + gain[sfb] = sub( gain[sfb], shr_r( gain[sfb], 1 ) ); move16(); } } ELSE { /* gain[sfb] /= 2; -> reduce exponent by 1 */ - gain_e[sfb] = sub(gain_e[sfb], 1); + gain_e[sfb] = sub( gain_e[sfb], 1 ); move16(); } } - FOR (tb = hGrid->swb_offset[sfb]; tb < hGrid->swb_offset[sfb + 1]; tb++) + FOR( tb = hGrid->swb_offset[sfb]; tb < hGrid->swb_offset[sfb + 1]; tb++ ) { /* multiply the prepared IGF spectrum with the gain */ - L_tmp2 = 0; /* set L_tmp2 to default value */ + L_tmp2 = 0; /* set L_tmp2 to default value */ move32(); - L_tmp = Mpy_32_16_1(igf_spec[tb], gain[sfb]); - L_tmp_e = add(igf_spec_e[tileIdx], gain_e[sfb]); + L_tmp = Mpy_32_16_1( igf_spec[tb], gain[sfb] ); + L_tmp_e = add( igf_spec_e[tileIdx], gain_e[sfb] ); /* store the finalized IGF spectrum */ - IF (spectrum[tb] == 0) + IF( spectrum[tb] == 0 ) { - shift = sub(L_tmp_e, *spectrum_e); - tmp = norm_l(L_tmp) - shift - 32; - if (tmp < 0) + shift = sub( L_tmp_e, *spectrum_e ); + tmp = norm_l( L_tmp ) - shift - 32; + if ( tmp < 0 ) { - L_tmp2 = L_shl(L_tmp, shift); + L_tmp2 = L_shl( L_tmp, shift ); } - spectrum[tb] = L_tmp2; + spectrum[tb] = L_tmp2; move32(); - flag_sparse[tb-IGF_START_MN] = 1; + flag_sparse[tb - IGF_START_MN] = 1; move16(); } ELSE { - shift = sub(L_tmp_e, *virtualSpec_e); - tmp = norm_l(L_tmp) - shift - 32; - if (tmp < 0) + shift = sub( L_tmp_e, *virtualSpec_e ); + tmp = norm_l( L_tmp ) - shift - 32; + if ( tmp < 0 ) { - L_tmp2 = L_shl(L_tmp, shift); + L_tmp2 = L_shl( L_tmp, shift ); } - virtualSpec[tb-IGF_START_MN] = L_tmp2; + virtualSpec[tb - IGF_START_MN] = L_tmp2; move32(); - flag_sparse[tb-IGF_START_MN] = 2; + flag_sparse[tb - IGF_START_MN] = 2; move16(); } } } - } /**********************************************************************/ /* @@ -2541,7 +2534,7 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in #ifdef BASOP_NOGLOB /* Critical Carry/Overflow*/ tmp = div_s( shr( round_fx_o( E, &Overflow ), 1 ), sum ); /* shift E 1 bit to the right in order to make it smaller than sum */ #else - tmp = div_s( shr( round_fx( E ), 1 ), sum ); /* shift E 1 bit to the right in order to make it smaller than sum */ + tmp = div_s( shr( round_fx( E ), 1 ), sum ); /* shift E 1 bit to the right in order to make it smaller than sum */ #endif tmp_e = sub( add( E_e, 1 ), sub( 15, shift ) ); /* 15Q0 | sum is 15Q0 */ @@ -2627,9 +2620,9 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in gain_e[sfb] = sub( gain_e[sfb], tmp ); /* gain[sfb] = min(gain[sfb], 12.f); */ - BASOP_SATURATE_WARNING_OFF_EVS /* threshold, may overflow */ + BASOP_SATURATE_WARNING_OFF_EVS /* threshold, may overflow */ #ifdef BASOP_NOGLOB - tmp = shl_sat( gain[sfb], sub( gain_e[sfb], 15 - 5 ) ); /* 10Q5 | tmp is in 10Q5 */ + tmp = shl_sat( gain[sfb], sub( gain_e[sfb], 15 - 5 ) ); /* 10Q5 | tmp is in 10Q5 */ #else tmp = shl( gain[sfb], sub( gain_e[sfb], 15 - 5 ) ); /* 10Q5 | tmp is in 10Q5 */ #endif @@ -2742,85 +2735,84 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /**********************************************************************/ /* spectral whitening **************************************************************************/ -static void IGF_getWhiteSpectralData(const Word32 *in, /**< in: Q31 | MDCT spectrum */ - Word16 s_l, /**< in: Q0 | getScaleFactor32() of in */ - Word32 *out, /**< out: Q31| whitened spectrum */ - const Word16 start, /**< in: Q0 | start MDCT subband index */ - const Word16 stop, /**< in: Q0 | stop MDCT subband index */ - const Word16 level /**< in: Q0 | whitening strength */ - ) +static void IGF_getWhiteSpectralData( const Word32 *in, /**< in: Q31 | MDCT spectrum */ + Word16 s_l, /**< in: Q0 | getScaleFactor32() of in */ + Word32 *out, /**< out: Q31| whitened spectrum */ + const Word16 start, /**< in: Q0 | start MDCT subband index */ + const Word16 stop, /**< in: Q0 | stop MDCT subband index */ + const Word16 level /**< in: Q0 | whitening strength */ +) { Word16 j; - Word32 ak; /* moving average */ + Word32 ak; /* moving average */ Word32 ak_norm; Word16 tmp_16; Word16 div; Word16 nrm_i; - Word16 nrm_tab[] = {2341 /* 1/14 */, 2521 /* 1/13 */, 2731 /* 1/12 */, 2979 /* 1/11 */, 3277 /* 1/10 */, 3641 /* 1/9 */, 4096 /* 1/8 */, 4681 /* 1/7 */}; + Word16 nrm_tab[] = { 2341 /* 1/14 */, 2521 /* 1/13 */, 2731 /* 1/12 */, 2979 /* 1/11 */, 3277 /* 1/10 */, 3641 /* 1/9 */, 4096 /* 1/8 */, 4681 /* 1/7 */ }; /* inits */ div = 0; move16(); - s_l = sub(s_l, 2); - ak = 0; - move32(); + s_l = sub( s_l, 2 ); + ak = 0; + move32(); - FOR (j = start - level; j < start + level; j++) + FOR( j = start - level; j < start + level; j++ ) { - tmp_16 = extract_h(L_shl(in[j], s_l)); // e: in_e - s_l - ak = L_mac(ak, tmp_16, tmp_16); // e: 2 * (in_e - s_l) + tmp_16 = extract_h( L_shl( in[j], s_l ) ); // e: in_e - s_l + ak = L_mac( ak, tmp_16, tmp_16 ); // e: 2 * (in_e - s_l) } - FOR (j = start; j < stop - level; j++) + FOR( j = start; j < stop - level; j++ ) { - tmp_16 = extract_h(L_shl(in[j + level], s_l)); // in_e - s_l - ak = L_mac(ak, tmp_16, tmp_16); // 2 * (in_e - s_l) - ak_norm = Mpy_32_16_r(ak, 2185); - tmp_16 = sub(31, norm_l(ak_norm)); + tmp_16 = extract_h( L_shl( in[j + level], s_l ) ); // in_e - s_l + ak = L_mac( ak, tmp_16, tmp_16 ); // 2 * (in_e - s_l) + ak_norm = Mpy_32_16_r( ak, 2185 ); + tmp_16 = sub( 31, norm_l( ak_norm ) ); - if (ak == 0) + if ( ak == 0 ) { tmp_16 = 0; move16(); } - tmp_16 = s_min(14, sub(15, shr(tmp_16, 1))); - div = shl(1, tmp_16); - out[j] = Mpy_32_16_1(L_shl(in[j], s_l), div); + tmp_16 = s_min( 14, sub( 15, shr( tmp_16, 1 ) ) ); + div = shl( 1, tmp_16 ); + out[j] = Mpy_32_16_1( L_shl( in[j], s_l ), div ); move32(); - tmp_16 = extract_h(L_shl(in[j - level], s_l)); - ak = L_msu(ak, tmp_16, tmp_16); + tmp_16 = extract_h( L_shl( in[j - level], s_l ) ); + ak = L_msu( ak, tmp_16, tmp_16 ); } nrm_i = 0; move16(); - FOR (; j < stop; j++) + FOR( ; j < stop; j++ ) { - ak_norm = Mpy_32_16_r(ak, nrm_tab[nrm_i++]); - tmp_16 = sub(31, norm_l(ak_norm)); + ak_norm = Mpy_32_16_r( ak, nrm_tab[nrm_i++] ); + tmp_16 = sub( 31, norm_l( ak_norm ) ); - if (ak == 0) + if ( ak == 0 ) { tmp_16 = 0; move16(); } - tmp_16 = s_min(14, sub(15, shr(tmp_16, 1))); - div = shl(1, tmp_16); + tmp_16 = s_min( 14, sub( 15, shr( tmp_16, 1 ) ) ); + div = shl( 1, tmp_16 ); - if (LT_32(ak, 16)) + if ( LT_32( ak, 16 ) ) { div = 1; move16(); } - out[j] = Mpy_32_16_1(L_shl(in[j], s_l), div); + out[j] = Mpy_32_16_1( L_shl( in[j], s_l ), div ); move32(); - tmp_16 = extract_h(L_shl(in[j - level], s_l)); - ak = L_msu(ak, tmp_16, tmp_16); + tmp_16 = extract_h( L_shl( in[j - level], s_l ) ); + ak = L_msu( ak, tmp_16, tmp_16 ); } - } /*-------------------------------------------------------------------* @@ -2830,14 +2822,14 @@ static void IGF_getWhiteSpectralData(const Word32 *in, *-------------------------------------------------------------------*/ static void IGF_getWhiteSpectralData_ivas( - const Word32 *in, /* i : MDCT spectrum */ - const Word16 in_e, /* i : MDCT spectrum exp */ - Word16 s_l, /* i : getScaleFactor32() of in */ - Word32 *out, /* o : whitened spectrum */ - Word16 *out_e, /* o : whitened spectrum exp */ - const Word16 start, /* i : start MDCT subband index */ - const Word16 stop, /* i : stop MDCT subband index */ - const Word16 level /* i : whitening strength */ + const Word32 *in, /* i : MDCT spectrum */ + const Word16 in_e, /* i : MDCT spectrum exp */ + Word16 s_l, /* i : getScaleFactor32() of in */ + Word32 *out, /* o : whitened spectrum */ + Word16 *out_e, /* o : whitened spectrum exp */ + const Word16 start, /* i : start MDCT subband index */ + const Word16 stop, /* i : stop MDCT subband index */ + const Word16 level /* i : whitening strength */ ) { Word16 i; @@ -2920,10 +2912,10 @@ static void IGF_getWhiteSpectralData_ivas( /**********************************************************************/ /* refines the IGF grid **************************************************************************/ -static void IGF_RefineGrid(H_IGF_GRID hGrid /**< in/out: | IGF grid handle */ - ) +static void IGF_RefineGrid( H_IGF_GRID hGrid /**< in/out: | IGF grid handle */ +) { - Word16 a[IGF_MAX_SFB+1]; + Word16 a[IGF_MAX_SFB + 1]; Word16 sfb; Word16 tmp; Word16 delta; @@ -2931,44 +2923,43 @@ static void IGF_RefineGrid(H_IGF_GRID hGrid Flag Overflow = 0; #endif - set16_fx(a, 0, IGF_MAX_SFB+1); + set16_fx( a, 0, IGF_MAX_SFB + 1 ); hGrid->infoIsRefined = 1; move16(); - FOR (sfb = 0; sfb < hGrid->swb_offset_len; sfb++) + FOR( sfb = 0; sfb < hGrid->swb_offset_len; sfb++ ) { - tmp = shl(sfb, 1); + tmp = shl( sfb, 1 ); a[tmp] = hGrid->swb_offset[sfb]; move16(); - tmp = add(tmp, 1); - delta = sub(hGrid->swb_offset[sfb+1], hGrid->swb_offset[sfb]); -#ifdef BASOP_NOGLOB /* TBV for 16 kHz, 9.6kbps dtx condition, hGrid->swb_offset[sfb+1] points to an uninit value */ - delta = mac_r(0x00195000, 29491/*0.45f Q16*/, shl_o(delta, 5, &Overflow)); + tmp = add( tmp, 1 ); + delta = sub( hGrid->swb_offset[sfb + 1], hGrid->swb_offset[sfb] ); +#ifdef BASOP_NOGLOB /* TBV for 16 kHz, 9.6kbps dtx condition, hGrid->swb_offset[sfb+1] points to an uninit value */ + delta = mac_r( 0x00195000, 29491 /*0.45f Q16*/, shl_o( delta, 5, &Overflow ) ); #else - delta = mac_r(0x00195000, 29491/*0.45f Q16*/, shl(delta, 5)); + delta = mac_r( 0x00195000, 29491 /*0.45f Q16*/, shl( delta, 5 ) ); #endif - a[tmp] = add(hGrid->swb_offset[sfb], shr(delta, 6)); + a[tmp] = add( hGrid->swb_offset[sfb], shr( delta, 6 ) ); move16(); - IF(s_and(a[tmp], 1) != 0) + IF( s_and( a[tmp], 1 ) != 0 ) { - a[tmp] = sub(a[tmp], 1); + a[tmp] = sub( a[tmp], 1 ); move16(); } } - hGrid->stopSfb = shl(hGrid->stopSfb, 1); - FOR (sfb = 0; sfb <= hGrid->stopSfb; sfb++) + hGrid->stopSfb = shl( hGrid->stopSfb, 1 ); + FOR( sfb = 0; sfb <= hGrid->stopSfb; sfb++ ) { hGrid->swb_offset[sfb] = a[sfb]; move16(); } - FOR (sfb = 0; sfb <= hGrid->nTiles; sfb++) + FOR( sfb = 0; sfb <= hGrid->nTiles; sfb++ ) { - hGrid->sfbWrap[sfb] = shl(hGrid->sfbWrap[sfb], 1); + hGrid->sfbWrap[sfb] = shl( hGrid->sfbWrap[sfb], 1 ); move16(); } - } static void IGF_RefineGrid_ivas_fx( H_IGF_GRID hGrid /**< in/out: | IGF grid handle */ @@ -3030,10 +3021,10 @@ static void IGF_RefineGrid_ivas_fx( H_IGF_GRID hGrid /**< in/out: | IGF grid han /**********************************************************************/ /* reads whitening information from the bitstream **************************************************************************/ -void IGFDecReadData_ivas_fx( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Deccoder */ - Decoder_State *st, /**< in: | decoder state */ - const Word16 igfGridIdx, /**< in: Q0 | in case of CELP->TCX switching, use 1.25 framelength */ - const Word16 isIndepFrame /**< in: Q0 | if 1: arith dec force reset, if 0: no reset */ +void IGFDecReadData_ivas_fx( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Deccoder */ + Decoder_State *st, /**< in: | decoder state */ + const Word16 igfGridIdx, /**< in: Q0 | in case of CELP->TCX switching, use 1.25 framelength */ + const Word16 isIndepFrame /**< in: Q0 | if 1: arith dec force reset, if 0: no reset */ ) { IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData; @@ -3113,11 +3104,11 @@ void IGFDecReadData_ivas_fx( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: } } -void IGFDecReadData(const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Deccoder */ - Decoder_State *st, /**< in: | decoder state */ - const Word16 igfGridIdx, /**< in: Q0 | in case of CELP->TCX switching, use 1.25 framelength */ - const Word16 isIndepFrame /**< in: Q0 | if 1: arith dec force reset, if 0: no reset */ - ) +void IGFDecReadData( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Deccoder */ + Decoder_State *st, /**< in: | decoder state */ + const Word16 igfGridIdx, /**< in: Q0 | in case of CELP->TCX switching, use 1.25 framelength */ + const Word16 isIndepFrame /**< in: Q0 | if 1: arith dec force reset, if 0: no reset */ +) { IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData; H_IGF_GRID hGrid; @@ -3126,30 +3117,30 @@ void IGFDecReadData(const IGF_DEC_INSTANCE_HANDLE hInstance, Word16 tmp; - IF (hInstance != NULL) + IF( hInstance != NULL ) { hPrivateData = &hInstance->igfData; - hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; - nT = hGrid->nTiles; + hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; + nT = hGrid->nTiles; move16(); - tmp = 0; + tmp = 0; move16(); /* set/reset all values to default = IGF_WHITENING_OFF */ - FOR (p = 0; p < IGF_MAX_TILES; p++) + FOR( p = 0; p < IGF_MAX_TILES; p++ ) { hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_OFF; move16(); } - IF (isIndepFrame == 0) + IF( isIndepFrame == 0 ) { - tmp = get_next_indice(st, 1); + tmp = get_next_indice( st, 1 ); } - IF (tmp == 1) + IF( tmp == 1 ) { - FOR (p = 0; p < nT; p++) + FOR( p = 0; p < nT; p++ ) { hPrivateData->currWhiteningLevel[p] = hPrivateData->prevWhiteningLevel[p]; move16(); @@ -3157,18 +3148,18 @@ void IGFDecReadData(const IGF_DEC_INSTANCE_HANDLE hInstance, } ELSE { - IGF_decode_whitening_level(st, hPrivateData, 0); - tmp = get_next_indice(st, 1); - IF (tmp == 1) + IGF_decode_whitening_level( st, hPrivateData, 0 ); + tmp = get_next_indice( st, 1 ); + IF( tmp == 1 ) { - FOR (p = 1; p < nT; p++) + FOR( p = 1; p < nT; p++ ) { - IGF_decode_whitening_level(st, hPrivateData, p); + IGF_decode_whitening_level( st, hPrivateData, p ); } } ELSE { - FOR (p = 1; p < nT; p++) + FOR( p = 1; p < nT; p++ ) { hPrivateData->currWhiteningLevel[p] = hPrivateData->currWhiteningLevel[0]; move16(); @@ -3177,26 +3168,25 @@ void IGFDecReadData(const IGF_DEC_INSTANCE_HANDLE hInstance, } /* save current level for concealment */ - FOR (p = 0; p < IGF_MAX_TILES; p++) + FOR( p = 0; p < IGF_MAX_TILES; p++ ) { hPrivateData->prevWhiteningLevel[p] = hPrivateData->currWhiteningLevel[p]; move16(); } /* read flattening trigger from bitstream */ - IGF_decode_temp_flattening_trigger(st, hInstance); + IGF_decode_temp_flattening_trigger( st, hInstance ); } - } /**********************************************************************/ /* read the IGF level information from the bitsream **************************************************************************/ -void IGFDecReadLevel( /**< out: Q0 | return igfAllZero flag indicating if no envelope is transmitted */ - const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ - Decoder_State *st, /**< in: | decoder state */ - const Word16 igfGridIdx, /**< in: Q0 | in case of CELP->TCX switching, use 1.25 framelength */ - const Word16 isIndepFrame /**< in: Q0 | if 1: arith dec force reset, if 0: no reset */ +void IGFDecReadLevel( /**< out: Q0 | return igfAllZero flag indicating if no envelope is transmitted */ + const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ + Decoder_State *st, /**< in: | decoder state */ + const Word16 igfGridIdx, /**< in: Q0 | in case of CELP->TCX switching, use 1.25 framelength */ + const Word16 isIndepFrame /**< in: Q0 | if 1: arith dec force reset, if 0: no reset */ ) { IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData; @@ -3207,23 +3197,23 @@ void IGFDecReadLevel( IGFAllZero = 1; move16(); - IF (hInstance != NULL) + IF( hInstance != NULL ) { - hPrivateData = &hInstance->igfData; - hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; + hPrivateData = &hInstance->igfData; + hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; m_igfSfbStart = hGrid->startSfb; move16(); - IGFAllZero = get_next_indice(st, 1); + IGFAllZero = get_next_indice( st, 1 ); - IF (IGFAllZero == 0) + IF( IGFAllZero == 0 ) { - Copy(hPrivateData->igf_curr, hPrivateData->igf_prev, hGrid->stopSfb); - IGFSCFDecoderDecode(&hPrivateData->hArithSCFdec, st, &hPrivateData->igf_curr[m_igfSfbStart],/* 0Q15, hPrivateData->igf_curr = [0, 91] */igfGridIdx, isIndepFrame ); + Copy( hPrivateData->igf_curr, hPrivateData->igf_prev, hGrid->stopSfb ); + IGFSCFDecoderDecode( &hPrivateData->hArithSCFdec, st, &hPrivateData->igf_curr[m_igfSfbStart], /* 0Q15, hPrivateData->igf_curr = [0, 91] */ igfGridIdx, isIndepFrame ); } ELSE { - IGFSCFDecoderReset(&hPrivateData->hArithSCFdec); - set16_fx(&hPrivateData->igf_curr[m_igfSfbStart], 0, sub(hGrid->stopSfb, m_igfSfbStart)); + IGFSCFDecoderReset( &hPrivateData->hArithSCFdec ); + set16_fx( &hPrivateData->igf_curr[m_igfSfbStart], 0, sub( hGrid->stopSfb, m_igfSfbStart ) ); } } @@ -3234,49 +3224,51 @@ void IGFDecReadLevel( /**********************************************************************/ /* apply the IGF decoder **************************************************************************/ -void IGFDecApplyMono(const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ - Word32 *spectrum, /**< in/out: | MDCT spectrum */ - Word16 *spectrum_e, /**< in/out: | exponent of spectrum */ - const Word16 igfGridIdx, /**< in: | in case of CELP->TCX switching, use 1.25 framelength */ - Word16 bfi /**< in: | frame loss == 1, frame good == 0 */ - ) +void IGFDecApplyMono( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ + Word32 *spectrum, /**< in/out: | MDCT spectrum */ + Word16 *spectrum_e, /**< in/out: | exponent of spectrum */ + const Word16 igfGridIdx, /**< in: | in case of CELP->TCX switching, use 1.25 framelength */ + Word16 bfi /**< in: | frame loss == 1, frame good == 0 */ +) { IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData; H_IGF_GRID hGrid; Word16 i; Word16 whiteningLevel; - Word16 s_l; /* | headroom of pSpecFlat */ - Word16 specMed_e; /* | exponent of the medium whitened spectrum */ - Word32 igf_spec[IGF_MAX_GRANULE_LEN]; /* Q31 | prepared IGF spectrum */ - Word16 igf_spec_e[IGF_MAX_TILES]; /* | exponents of igf_spec, one exponent per tile */ + Word16 s_l; /* | headroom of pSpecFlat */ + Word16 specMed_e; /* | exponent of the medium whitened spectrum */ + Word32 igf_spec[IGF_MAX_GRANULE_LEN]; /* Q31 | prepared IGF spectrum */ + Word16 igf_spec_e[IGF_MAX_TILES]; /* | exponents of igf_spec, one exponent per tile */ hPrivateData = &hInstance->igfData; - hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; + hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; /* initialize variables */ - whiteningLevel = 7; + whiteningLevel = 7; move16(); - specMed_e = 0; + specMed_e = 0; move16(); - hPrivateData->n_noise_bands = 0; + hPrivateData->n_noise_bands = 0; move16(); - hPrivateData->n_noise_bands_off = 0; + hPrivateData->n_noise_bands_off = 0; move16(); - hPrivateData->headroom_TCX_noise_white = 0; + hPrivateData->headroom_TCX_noise_white = 0; move16(); - hPrivateData->headroom_TCX_noise = 0; + hPrivateData->headroom_TCX_noise = 0; move16(); - hPrivateData->totalNoiseNrg = 0; move32(); - hPrivateData->totalNoiseNrg_off = 0; move32(); + hPrivateData->totalNoiseNrg = 0; + move32(); + hPrivateData->totalNoiseNrg_off = 0; + move32(); - set32_fx(igf_spec, 0, IGF_MAX_GRANULE_LEN); - set16_fx(igf_spec_e, 0, IGF_MAX_TILES); + set32_fx( igf_spec, 0, IGF_MAX_GRANULE_LEN ); + set16_fx( igf_spec_e, 0, IGF_MAX_TILES ); /* concealment counter */ - IF (bfi != 0) + IF( bfi != 0 ) { - hPrivateData->frameLossCounter = add(hPrivateData->frameLossCounter, 1); + hPrivateData->frameLossCounter = add( hPrivateData->frameLossCounter, 1 ); } ELSE { @@ -3284,89 +3276,87 @@ void IGFDecApplyMono(const IGF_DEC_INSTANCE_HANDLE hInstance, } /* skip IGF processing if all IGF levels are zero */ - IF (hInstance->infoIGFAllZero == 0) + IF( hInstance->infoIGFAllZero == 0 ) { - FOR (i = 0; i < hGrid->nTiles; i++) + FOR( i = 0; i < hGrid->nTiles; i++ ) { - IF (EQ_16(hPrivateData->currWhiteningLevel[i], IGF_WHITENING_MID)) + IF( EQ_16( hPrivateData->currWhiteningLevel[i], IGF_WHITENING_MID ) ) { - s_l = getScaleFactor32(hPrivateData->pSpecFlat + hGrid->minSrcSubband - whiteningLevel, - add(sub(hGrid->startLine, hGrid->minSrcSubband), whiteningLevel)); + s_l = getScaleFactor32( hPrivateData->pSpecFlat + hGrid->minSrcSubband - whiteningLevel, + add( sub( hGrid->startLine, hGrid->minSrcSubband ), whiteningLevel ) ); specMed_e = hPrivateData->pSpecFlat_exp; move16(); - IGF_getWhiteSpectralData(hPrivateData->pSpecFlat, - s_l, - igf_spec, - hGrid->minSrcSubband, - hGrid->startLine, - whiteningLevel); + IGF_getWhiteSpectralData( hPrivateData->pSpecFlat, + s_l, + igf_spec, + hGrid->minSrcSubband, + hGrid->startLine, + whiteningLevel ); /*14 seems to be precise enough*/ - hPrivateData->headroom_TCX_noise_white = IGF_getScaleFactor32Cond(hInstance->infoTCXNoise_evs + hGrid->minSrcSubband, - igf_spec + hGrid->minSrcSubband, - sub(hGrid->startLine, hGrid->minSrcSubband)); - hPrivateData->n_noise_bands = IGF_replaceTCXNoise_1(igf_spec, - hPrivateData->headroom_TCX_noise_white, - hInstance->infoTCXNoise_evs, - hGrid->minSrcSubband, - hGrid->startLine, - &hPrivateData->totalNoiseNrg); + hPrivateData->headroom_TCX_noise_white = IGF_getScaleFactor32Cond( hInstance->infoTCXNoise_evs + hGrid->minSrcSubband, + igf_spec + hGrid->minSrcSubband, + sub( hGrid->startLine, hGrid->minSrcSubband ) ); + hPrivateData->n_noise_bands = IGF_replaceTCXNoise_1( igf_spec, + hPrivateData->headroom_TCX_noise_white, + hInstance->infoTCXNoise_evs, + hGrid->minSrcSubband, + hGrid->startLine, + &hPrivateData->totalNoiseNrg ); BREAK; } } - FOR (i = 0; i < hGrid->nTiles; i++) + FOR( i = 0; i < hGrid->nTiles; i++ ) { - IF (hPrivateData->currWhiteningLevel[ i ] == IGF_WHITENING_OFF) + IF( hPrivateData->currWhiteningLevel[i] == IGF_WHITENING_OFF ) { - hPrivateData->headroom_TCX_noise = IGF_getScaleFactor32Cond(hInstance->infoTCXNoise_evs + hGrid->minSrcSubband, - hPrivateData->pSpecFlat + hGrid->minSrcSubband, - sub(hGrid->startLine, hGrid->minSrcSubband)); - - hPrivateData->n_noise_bands_off = IGF_replaceTCXNoise_1(hPrivateData->pSpecFlat, - hPrivateData->headroom_TCX_noise, - hInstance->infoTCXNoise_evs, - hGrid->minSrcSubband, - hGrid->startLine, - &hPrivateData->totalNoiseNrg_off); + hPrivateData->headroom_TCX_noise = IGF_getScaleFactor32Cond( hInstance->infoTCXNoise_evs + hGrid->minSrcSubband, + hPrivateData->pSpecFlat + hGrid->minSrcSubband, + sub( hGrid->startLine, hGrid->minSrcSubband ) ); + + hPrivateData->n_noise_bands_off = IGF_replaceTCXNoise_1( hPrivateData->pSpecFlat, + hPrivateData->headroom_TCX_noise, + hInstance->infoTCXNoise_evs, + hGrid->minSrcSubband, + hGrid->startLine, + &hPrivateData->totalNoiseNrg_off ); BREAK; } } /* apply IGF in three steps: */ - IGF_prep(hPrivateData, - igfGridIdx, - hInstance->infoTCXNoise_evs, - igf_spec, - igf_spec_e, - hPrivateData->pSpecFlat, - hPrivateData->pSpecFlat_exp, - specMed_e); - IGF_calc(hPrivateData, - igfGridIdx, - spectrum, - *spectrum_e, - igf_spec, - igf_spec_e); - IGF_appl(hPrivateData, - igfGridIdx, - spectrum, - spectrum_e, - igf_spec, - igf_spec_e, - hInstance->virtualSpec, - &hInstance->virtualSpec_e, - hInstance->flag_sparseBuf); - + IGF_prep( hPrivateData, + igfGridIdx, + hInstance->infoTCXNoise_evs, + igf_spec, + igf_spec_e, + hPrivateData->pSpecFlat, + hPrivateData->pSpecFlat_exp, + specMed_e ); + IGF_calc( hPrivateData, + igfGridIdx, + spectrum, + *spectrum_e, + igf_spec, + igf_spec_e ); + IGF_appl( hPrivateData, + igfGridIdx, + spectrum, + spectrum_e, + igf_spec, + igf_spec_e, + hInstance->virtualSpec, + &hInstance->virtualSpec_e, + hInstance->flag_sparseBuf ); } /* reset TCX noise indicator vector */ - set16_fx(hInstance->infoTCXNoise_evs, 0, IGF_START_MX); - + set16_fx( hInstance->infoTCXNoise_evs, 0, IGF_START_MX ); } /**********************************************************************/ /* @@ -3588,33 +3578,33 @@ void IGFDecApplyStereo( Word16 igf_specL_e_arr[IGF_MAX_GRANULE_LEN]; Word16 igf_specR_e_arr[IGF_MAX_GRANULE_LEN]; - Word16 specMedL_e; /* | exponent of the medium whitened spectrum */ - Word16 specMedR_e; /* | exponent of the medium whitened spectrum */ + Word16 specMedL_e; /* | exponent of the medium whitened spectrum */ + Word16 specMedR_e; /* | exponent of the medium whitened spectrum */ Word16 v_len; Word16 s_l; set_f( igf_specL, 0.f, IGF_MAX_GRANULE_LEN ); set_f( igf_specR, 0.f, IGF_MAX_GRANULE_LEN ); - set32_fx(igf_specL_fx, 0, IGF_MAX_GRANULE_LEN); - set32_fx(igf_specR_fx, 0, IGF_MAX_GRANULE_LEN); - set16_fx(igf_specL_e, 0, IGF_MAX_TILES); - set16_fx(igf_specR_e, 0, IGF_MAX_TILES); - set16_fx(igf_specL_e_arr, 0, IGF_MAX_GRANULE_LEN); - set16_fx(igf_specR_e_arr, 0, IGF_MAX_GRANULE_LEN); + set32_fx( igf_specL_fx, 0, IGF_MAX_GRANULE_LEN ); + set32_fx( igf_specR_fx, 0, IGF_MAX_GRANULE_LEN ); + set16_fx( igf_specL_e, 0, IGF_MAX_TILES ); + set16_fx( igf_specR_e, 0, IGF_MAX_TILES ); + set16_fx( igf_specL_e_arr, 0, IGF_MAX_GRANULE_LEN ); + set16_fx( igf_specR_e_arr, 0, IGF_MAX_GRANULE_LEN ); /* initialize variables */ whiteningLevel = IGF_MID_WHITENING_LEVEL2; move16(); - IF(EQ_16(igfGridIdx, IGF_GRID_LB_SHORT)) + IF( EQ_16( igfGridIdx, IGF_GRID_LB_SHORT ) ) { v_len = ( N_MAX_TCX - IGF_START_MN ) / 2; move16(); } ELSE { - v_len = (N_MAX_TCX - IGF_START_MN); + v_len = ( N_MAX_TCX - IGF_START_MN ); move16(); } @@ -3663,10 +3653,10 @@ void IGFDecApplyStereo( move16(); /* concealment counter */ - IF ( bfi ) + IF( bfi ) { - hPrivateDataL->frameLossCounter = add(hPrivateDataL->frameLossCounter,1); - hPrivateDataR->frameLossCounter = add(hPrivateDataR->frameLossCounter,1); + hPrivateDataL->frameLossCounter = add( hPrivateDataL->frameLossCounter, 1 ); + hPrivateDataR->frameLossCounter = add( hPrivateDataR->frameLossCounter, 1 ); } ELSE { @@ -3678,17 +3668,17 @@ void IGFDecApplyStereo( /* skip IGF processing if all IGF levels are zero */ test(); - IF ( !hIGFDecL->infoIGFAllZero || !hIGFDecR->infoIGFAllZero ) + IF( !hIGFDecL->infoIGFAllZero || !hIGFDecR->infoIGFAllZero ) { - FOR ( i = 0; i < hGrid->nTiles; i++ ) + FOR( i = 0; i < hGrid->nTiles; i++ ) { test(); - IF ( EQ_16(hPrivateDataL->currWhiteningLevel[i], IGF_WHITENING_MID) || EQ_16(hPrivateDataR->currWhiteningLevel[i], IGF_WHITENING_MID) ) + IF( EQ_16( hPrivateDataL->currWhiteningLevel[i], IGF_WHITENING_MID ) || EQ_16( hPrivateDataR->currWhiteningLevel[i], IGF_WHITENING_MID ) ) { - IF ( !bfi ) + IF( !bfi ) { - s_l = getScaleFactor32(hPrivateDataL->pSpecFlat + hGrid->minSrcSubband - whiteningLevel, - add(sub(hGrid->startLine, hGrid->minSrcSubband), whiteningLevel)); + s_l = getScaleFactor32( hPrivateDataL->pSpecFlat + hGrid->minSrcSubband - whiteningLevel, + add( sub( hGrid->startLine, hGrid->minSrcSubband ), whiteningLevel ) ); IGF_getWhiteSpectralData_ivas( hPrivateDataL->pSpecFlat, hPrivateDataL->pSpecFlat_exp, s_l, @@ -3717,10 +3707,10 @@ void IGFDecApplyStereo( hPrivateDataL->totalNoiseNrg_exp = shl( sub( specMedL_e, sub( hPrivateDataL->headroom_TCX_noise_white, 5 ) ), 1 ); - IF ( !bfi ) + IF( !bfi ) { - s_l = getScaleFactor32(hPrivateDataR->pSpecFlat + hGrid->minSrcSubband - whiteningLevel, - add(sub(hGrid->startLine, hGrid->minSrcSubband), whiteningLevel)); + s_l = getScaleFactor32( hPrivateDataR->pSpecFlat + hGrid->minSrcSubband - whiteningLevel, + add( sub( hGrid->startLine, hGrid->minSrcSubband ), whiteningLevel ) ); IGF_getWhiteSpectralData_ivas( hPrivateDataR->pSpecFlat, hPrivateDataR->pSpecFlat_exp, s_l, @@ -3821,46 +3811,46 @@ void IGFDecApplyStereo( igf_specR_e ); // Fixed to float - FOR(i = 0; i < hGrid->nTiles; i++) + FOR( i = 0; i < hGrid->nTiles; i++ ) { Word16 start = hGrid->tile[i]; Word16 stop = hGrid->tile[i + 1]; - me2f_buf(igf_specL_fx + start, igf_specL_e[i], igf_specL + start, stop - start); - me2f_buf(igf_specR_fx + start, igf_specR_e[i], igf_specR + start, stop - start); + me2f_buf( igf_specL_fx + start, igf_specL_e[i], igf_specL + start, stop - start ); + me2f_buf( igf_specR_fx + start, igf_specR_e[i], igf_specR + start, stop - start ); } IGF_calc_ivas( hPrivateDataL, - igfGridIdx, - spectrumL_fx, - *spectrumL_e, - igf_specL_fx, - igf_specL_e); - IGF_calc_ivas(hPrivateDataR, - igfGridIdx, - spectrumR_fx, - *spectrumR_e, - igf_specR_fx, - igf_specR_e); - IGF_appl_ivas(hPrivateDataL, - igfGridIdx, - spectrumL_fx, - spectrumL_e, - igf_specL_fx, - igf_specL_e, - hIGFDecL->virtualSpec, - &hIGFDecL->virtualSpec_e, - hIGFDecL->flag_sparseBuf, - bfi_apply_damping); - IGF_appl_ivas(hPrivateDataR, - igfGridIdx, - spectrumR_fx, - spectrumR_e, - igf_specR_fx, - igf_specR_e, - hIGFDecR->virtualSpec, - &hIGFDecR->virtualSpec_e, - hIGFDecR->flag_sparseBuf, - bfi_apply_damping); + igfGridIdx, + spectrumL_fx, + *spectrumL_e, + igf_specL_fx, + igf_specL_e ); + IGF_calc_ivas( hPrivateDataR, + igfGridIdx, + spectrumR_fx, + *spectrumR_e, + igf_specR_fx, + igf_specR_e ); + IGF_appl_ivas( hPrivateDataL, + igfGridIdx, + spectrumL_fx, + spectrumL_e, + igf_specL_fx, + igf_specL_e, + hIGFDecL->virtualSpec, + &hIGFDecL->virtualSpec_e, + hIGFDecL->flag_sparseBuf, + bfi_apply_damping ); + IGF_appl_ivas( hPrivateDataR, + igfGridIdx, + spectrumR_fx, + spectrumR_e, + igf_specR_fx, + igf_specR_e, + hIGFDecR->virtualSpec, + &hIGFDecR->virtualSpec_e, + hIGFDecR->flag_sparseBuf, + bfi_apply_damping ); } /* reset TCX noise indicator vector */ @@ -3884,59 +3874,58 @@ set mode is used to init the IGF dec with a new bitrate **************************************************************************/ void IGFDecSetMode( const IGF_DEC_INSTANCE_HANDLE hIGFDec, /* o : instance handle of IGF Decoder */ - const Word32 total_brate, /* i : bitrate */ - const Word16 bwidth, /* i : audio bandwidth */ - const Word16 element_mode, /* i : IVAS element mode */ - const Word16 defaultStartLine, /* i : default start subband index */ - const Word16 defaultStopLine, /* i : default stop subband index */ - const Word16 rf_mode /* i : flag to signal the RF mode */ + const Word32 total_brate, /* i : bitrate */ + const Word16 bwidth, /* i : audio bandwidth */ + const Word16 element_mode, /* i : IVAS element mode */ + const Word16 defaultStartLine, /* i : default start subband index */ + const Word16 defaultStopLine, /* i : default stop subband index */ + const Word16 rf_mode /* i : flag to signal the RF mode */ ) { IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData; - hPrivateData = &hIGFDec->igfData; + hPrivateData = &hIGFDec->igfData; hIGFDec->isIGFActive = 0; move16(); - IF (IGFCommonFuncsIGFConfiguration(total_brate, bwidth, element_mode, &hPrivateData->igfInfo, rf_mode) != 0) + IF( IGFCommonFuncsIGFConfiguration( total_brate, bwidth, element_mode, &hPrivateData->igfInfo, rf_mode ) != 0 ) { - IGFSCFDecoderOpen(&hPrivateData->hArithSCFdec, &hPrivateData->igfInfo, total_brate, bwidth, element_mode, rf_mode); + IGFSCFDecoderOpen( &hPrivateData->hArithSCFdec, &hPrivateData->igfInfo, total_brate, bwidth, element_mode, rf_mode ); - hIGFDec->infoIGFStopLine = hPrivateData->igfInfo.grid[0].stopLine; + hIGFDec->infoIGFStopLine = hPrivateData->igfInfo.grid[0].stopLine; move16(); - hIGFDec->infoIGFStartLine = hPrivateData->igfInfo.grid[0].startLine; + hIGFDec->infoIGFStartLine = hPrivateData->igfInfo.grid[0].startLine; move16(); - hIGFDec->infoIGFStopFreq = hPrivateData->igfInfo.grid[0].stopFrequency; + hIGFDec->infoIGFStopFreq = hPrivateData->igfInfo.grid[0].stopFrequency; move16(); - hIGFDec->infoIGFStartFreq = hPrivateData->igfInfo.grid[0].startFrequency; + hIGFDec->infoIGFStartFreq = hPrivateData->igfInfo.grid[0].startFrequency; move16(); - hIGFDec->infoIGFAllZero = 0; + hIGFDec->infoIGFAllZero = 0; move16(); - hIGFDec->isIGFActive = 1; + hIGFDec->isIGFActive = 1; move16(); test(); - IF ((LE_16(hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_48000))||(LE_16(hPrivateData->igfInfo.bitRateIndex,IGF_BITRATE_FB_48000))) + IF( ( LE_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_48000 ) ) || ( LE_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_48000 ) ) ) { - IGF_RefineGrid(&hPrivateData->igfInfo.grid[IGF_GRID_LB_NORM]); - IGF_RefineGrid(&hPrivateData->igfInfo.grid[IGF_GRID_LB_TRAN]); - IGF_RefineGrid(&hPrivateData->igfInfo.grid[IGF_GRID_LB_SHORT]); + IGF_RefineGrid( &hPrivateData->igfInfo.grid[IGF_GRID_LB_NORM] ); + IGF_RefineGrid( &hPrivateData->igfInfo.grid[IGF_GRID_LB_TRAN] ); + IGF_RefineGrid( &hPrivateData->igfInfo.grid[IGF_GRID_LB_SHORT] ); } } ELSE { - hIGFDec->infoIGFStopLine = defaultStopLine; + hIGFDec->infoIGFStopLine = defaultStopLine; move16(); - hIGFDec->infoIGFStartLine = defaultStartLine; + hIGFDec->infoIGFStartLine = defaultStartLine; move16(); - hIGFDec->infoIGFStopFreq = -1; + hIGFDec->infoIGFStopFreq = -1; move16(); - hIGFDec->infoIGFStartFreq = -1; + hIGFDec->infoIGFStartFreq = -1; move16(); - fprintf(stderr,"IGFDecSetMode: initialization error!\n"); + fprintf( stderr, "IGFDecSetMode: initialization error!\n" ); } - } void IGFDecSetMode_ivas_fx( @@ -4003,25 +3992,25 @@ void IGFDecSetMode_ivas_fx( /**********************************************************************/ /* updates the start/stop frequency of IGF according to igfGridIdx **************************************************************************/ -void IGFDecUpdateInfo(const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ - const Word16 igfGridIdx /**< in: | IGF grid index */ - ) +void IGFDecUpdateInfo( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ + const Word16 igfGridIdx /**< in: | IGF grid index */ +) { IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData; H_IGF_GRID hGrid; hPrivateData = &hInstance->igfData; - IF (hInstance->isIGFActive != 0) + IF( hInstance->isIGFActive != 0 ) { - hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; + hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; hInstance->infoIGFStartFreq = hGrid->startFrequency; move16(); - hInstance->infoIGFStopFreq = hGrid->stopFrequency; + hInstance->infoIGFStopFreq = hGrid->stopFrequency; move16(); hInstance->infoIGFStartLine = hGrid->startLine; move16(); - hInstance->infoIGFStopLine = hGrid->stopLine; + hInstance->infoIGFStopLine = hGrid->stopLine; move16(); } } @@ -4049,13 +4038,13 @@ void IGFDecUpdateInfo_ivas_fx( hIGFDec->igfData.igfInfo.nfSeed = &hIGFDec->igfData.igfInfo.nfSeedBuf[0]; - IF ( EQ_16( igfGridIdx, IGF_GRID_LB_SHORT ) ) + IF( EQ_16( igfGridIdx, IGF_GRID_LB_SHORT ) ) { IGFDecRestoreTCX10SubFrameData_fx( hIGFDec, subFrameIdx ); } hPrivateData = &hIGFDec->igfData; - IF ( hIGFDec->isIGFActive ) + IF( hIGFDec->isIGFActive ) { hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; hIGFDec->infoIGFStartFreq = hGrid->startFrequency; @@ -4065,10 +4054,10 @@ void IGFDecUpdateInfo_ivas_fx( } /* TODO: this was added to keep the EVS 16-bit noise info in sync. */ - FOR(int l = 0; l < IGF_START_MX; l++) + FOR( int l = 0; l < IGF_START_MX; l++ ) { // u8bit to 16bit - hIGFDec->infoTCXNoise_evs[l] = (Word16)hIGFDec->infoTCXNoise[l]; + hIGFDec->infoTCXNoise_evs[l] = (Word16) hIGFDec->infoTCXNoise[l]; } return; @@ -4082,8 +4071,8 @@ void IGFDecReplicateTCX10State_fx( mvc2c( &hIGFDec->infoTCXNoiseBuf[( IGF_START_MX ) / 2], &hIGFDec->infoTCXNoiseBuf[0], ( IGF_START_MX ) / 2 ); /* TODO: remove float dependency */ - //mvr2r( &hIGFDec->virtualSpecBuf[( N_MAX_TCX - IGF_START_MN ) / 2], &hIGFDec->virtualSpecBuf[0], ( N_MAX_TCX - IGF_START_MN ) / 2 ); - //mvr2r( &hIGFDec->igfData.pSpecFlatBuf[IGF_START_MX / 2], &hIGFDec->igfData.pSpecFlatBuf[0], IGF_START_MX / 2 ); + // mvr2r( &hIGFDec->virtualSpecBuf[( N_MAX_TCX - IGF_START_MN ) / 2], &hIGFDec->virtualSpecBuf[0], ( N_MAX_TCX - IGF_START_MN ) / 2 ); + // mvr2r( &hIGFDec->igfData.pSpecFlatBuf[IGF_START_MX / 2], &hIGFDec->igfData.pSpecFlatBuf[0], IGF_START_MX / 2 ); Copy32( &hIGFDec->virtualSpec[( N_MAX_TCX - IGF_START_MN ) / 2], &hIGFDec->virtualSpec[0], ( N_MAX_TCX - IGF_START_MN ) / 2 ); Copy32( &hIGFDec->igfData.pSpecFlatBuf_fx[IGF_START_MX / 2], &hIGFDec->igfData.pSpecFlatBuf_fx[0], IGF_START_MX / 2 ); @@ -4098,29 +4087,28 @@ void IGFDecReplicateTCX10State_fx( /**********************************************************************/ /* copy the LPC flat spectrum to IGF buffer **************************************************************************/ -void IGFDecCopyLPCFlatSpectrum(const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ - const Word32 *pSpectrumFlat, /**< in: Q31 | LPC flattend spectrum from TCX dec */ - const Word16 pSpectrumFlat_exp, /**< in: | exponent of pSpectrumFlat */ - const Word16 igfGridIdx /**< in: Q0 | IGF grid index */ - ) +void IGFDecCopyLPCFlatSpectrum( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ + const Word32 *pSpectrumFlat, /**< in: Q31 | LPC flattend spectrum from TCX dec */ + const Word16 pSpectrumFlat_exp, /**< in: | exponent of pSpectrumFlat */ + const Word16 igfGridIdx /**< in: Q0 | IGF grid index */ +) { IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData; H_IGF_GRID hGrid; - IF (hInstance) + IF( hInstance ) { hPrivateData = &hInstance->igfData; - hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; + hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; /* pSpectrumFlat_exp has to be multiplied with 1024 = 2^10 go achive proper gain values */ - hPrivateData->pSpecFlat_exp = add(pSpectrumFlat_exp, 10); + hPrivateData->pSpecFlat_exp = add( pSpectrumFlat_exp, 10 ); move16(); - Copy32(pSpectrumFlat, hPrivateData->pSpecFlat, hGrid->startLine); + Copy32( pSpectrumFlat, hPrivateData->pSpecFlat, hGrid->startLine ); } - } void IGFDecCopyLPCFlatSpectrum_fx( @@ -4144,16 +4132,15 @@ void IGFDecCopyLPCFlatSpectrum_fx( move16(); Copy32( pSpectrumFlat, hPrivateData->pSpecFlat, hGrid->startLine ); - } } -/**********************************************************************/ /* -store the IGF bitstream information for TCX10 subframes -**************************************************************************/ -void IGFDecStoreTCX10SubFrameData(const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ - const Word16 subFrameIdx /**< in: Q0 | index of subframe */ - ) +/**********************************************************************/ /* + store the IGF bitstream information for TCX10 subframes + **************************************************************************/ +void IGFDecStoreTCX10SubFrameData( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ + const Word16 subFrameIdx /**< in: Q0 | index of subframe */ +) { IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData; @@ -4161,24 +4148,23 @@ void IGFDecStoreTCX10SubFrameData(const IGF_DEC_INSTANCE_HANDLE hInstance, hPrivateData = &hInstance->igfData; /* store igf energies for subframe*/ - Copy(hPrivateData->igf_curr, hPrivateData->igf_curr_subframe[subFrameIdx][0], IGF_MAX_SFB); - Copy(hPrivateData->igf_prev, hPrivateData->igf_prev_subframe[subFrameIdx], IGF_MAX_SFB); + Copy( hPrivateData->igf_curr, hPrivateData->igf_curr_subframe[subFrameIdx][0], IGF_MAX_SFB ); + Copy( hPrivateData->igf_prev, hPrivateData->igf_prev_subframe[subFrameIdx], IGF_MAX_SFB ); /* store spectral whitening information for current subframe */ - Copy(hPrivateData->currWhiteningLevel, hPrivateData->currWhiteningLevel_subframe[subFrameIdx], IGF_MAX_TILES); - Copy(hPrivateData->prevWhiteningLevel, hPrivateData->prevWhiteningLevel_subframe[subFrameIdx], IGF_MAX_TILES); + Copy( hPrivateData->currWhiteningLevel, hPrivateData->currWhiteningLevel_subframe[subFrameIdx], IGF_MAX_TILES ); + Copy( hPrivateData->prevWhiteningLevel, hPrivateData->prevWhiteningLevel_subframe[subFrameIdx], IGF_MAX_TILES ); /* store flattening trigger for current subframe */ hPrivateData->igf_flatteningTrigger_subframe[subFrameIdx] = hInstance->flatteningTrigger; move16(); - } -/**********************************************************************/ /* -restore the IGF bitstream information for TCX10 subframes -**************************************************************************/ -void IGFDecRestoreTCX10SubFrameData(const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ - const Word16 subFrameIdx /**< in: Q0 | index of subframe */ - ) +/**********************************************************************/ /* + restore the IGF bitstream information for TCX10 subframes + **************************************************************************/ +void IGFDecRestoreTCX10SubFrameData( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ + const Word16 subFrameIdx /**< in: Q0 | index of subframe */ +) { IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData; @@ -4186,16 +4172,15 @@ void IGFDecRestoreTCX10SubFrameData(const IGF_DEC_INSTANCE_HANDLE hInstance, hPrivateData = &hInstance->igfData; /* store igf energies for subframe*/ - Copy(hPrivateData->igf_curr_subframe[subFrameIdx][0], hPrivateData->igf_curr, IGF_MAX_SFB); - Copy(hPrivateData->igf_prev_subframe[subFrameIdx], hPrivateData->igf_prev, IGF_MAX_SFB); + Copy( hPrivateData->igf_curr_subframe[subFrameIdx][0], hPrivateData->igf_curr, IGF_MAX_SFB ); + Copy( hPrivateData->igf_prev_subframe[subFrameIdx], hPrivateData->igf_prev, IGF_MAX_SFB ); /* store spectral whitening information for current subframe */ - Copy(hPrivateData->currWhiteningLevel_subframe[subFrameIdx], hPrivateData->currWhiteningLevel, IGF_MAX_TILES); - Copy(hPrivateData->prevWhiteningLevel_subframe[subFrameIdx], hPrivateData->prevWhiteningLevel, IGF_MAX_TILES); + Copy( hPrivateData->currWhiteningLevel_subframe[subFrameIdx], hPrivateData->currWhiteningLevel, IGF_MAX_TILES ); + Copy( hPrivateData->prevWhiteningLevel_subframe[subFrameIdx], hPrivateData->prevWhiteningLevel, IGF_MAX_TILES ); /* restore flattening trigger for current subframe */ hInstance->flatteningTrigger = hPrivateData->igf_flatteningTrigger_subframe[subFrameIdx]; move16(); - } void IGFDecRestoreTCX10SubFrameData_fx( @@ -4303,4 +4288,4 @@ Word16 get_igf_startline( return igf_startline; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/igf_scf_dec.c b/lib_dec/igf_scf_dec.c index f92142600..244a73d11 100644 --- a/lib_dec/igf_scf_dec.c +++ b/lib_dec/igf_scf_dec.c @@ -115,7 +115,7 @@ static int16_t arith_decode_bits( for ( i = 0; i < nBits; ++i ) { /* decode one bit using the new raw AC function */ - ari_decode_14bits_bit_ext_ivas( st, &bit, ac_state ); + ari_decode_14bits_bit_ext_ivas( st, &bit, ac_state ); x = ( x << 1 ) | bit; } @@ -219,7 +219,7 @@ static void decode_sfe_vector( if ( f == 0 ) { /* decode one of the IGF_SYMBOLS_IN_TABLE == 27 alphabet symbols using the new raw AC function */ - ari_decode_14bits_s27_ext_ivas( st, &pred, &hPrivateData->acState, hPrivateData->cf_se00 ); + ari_decode_14bits_s27_ext_ivas( st, &pred, &hPrivateData->acState, hPrivateData->cf_se00 ); x[f] = pred << 2; x[f] += arith_decode_bits( &hPrivateData->acState, st, 2 ); /* LSBs as 2 bit raw */ } @@ -326,4 +326,4 @@ void IGFSCFDecoderDecode_ivas( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/igf_scf_dec_fx.c b/lib_dec/igf_scf_dec_fx.c index b08bcf499..ec6d6276a 100644 --- a/lib_dec/igf_scf_dec_fx.c +++ b/lib_dec/igf_scf_dec_fx.c @@ -23,26 +23,27 @@ void IGFSCFDecoderOpen( const Word32 total_brate, const Word16 bwidth, const Word16 element_mode, - const Word16 rf_mode -) + const Word16 rf_mode ) { hPublicData->scfCountLongBlock[0] = hIgfInfo->grid[0].swb_offset_len - 1; hPublicData->scfCountLongBlock[1] = hIgfInfo->grid[1].swb_offset_len - 1; hPublicData->scfCountLongBlock[2] = hIgfInfo->grid[2].swb_offset_len - 1; - move16();move16();move16();move16(); + move16(); + move16(); + move16(); + move16(); hPublicData->t = 0; move16(); /* protect against the invalid request of starting decoding with a dependent block */ - IGFCommonFuncsIGFGetCFTables(total_brate, bwidth, element_mode, rf_mode, &hPublicData->cf_se00, &hPublicData->cf_se01, &hPublicData->cf_off_se01, &hPublicData->cf_se02, &hPublicData->cf_off_se02, &hPublicData->cf_se10, &hPublicData->cf_off_se10, &hPublicData->cf_se11, &hPublicData->cf_off_se11); - + IGFCommonFuncsIGFGetCFTables( total_brate, bwidth, element_mode, rf_mode, &hPublicData->cf_se00, &hPublicData->cf_se01, &hPublicData->cf_off_se01, &hPublicData->cf_se02, &hPublicData->cf_off_se02, &hPublicData->cf_se10, &hPublicData->cf_off_se10, &hPublicData->cf_se11, &hPublicData->cf_off_se11 ); } static Word16 quant_ctx_fx( - Word16 ctx /* i: the context value to be quantized */ + Word16 ctx /* i: the context value to be quantized */ ) { /* @@ -52,19 +53,19 @@ static Word16 quant_ctx_fx( Word16 result; - result = s_min(abs_s(ctx), IGF_CTX_OFFSET); /* limit the absolute value to IGF_CTX_OFFSET */ - if (ctx < 0) /* add the sign back, if needed */ + result = s_min( abs_s( ctx ), IGF_CTX_OFFSET ); /* limit the absolute value to IGF_CTX_OFFSET */ + if ( ctx < 0 ) /* add the sign back, if needed */ { - result = negate(result); + result = negate( result ); } return result; } static Word16 arith_decode_bits_fx( - IGFSCFDEC_INSTANCE_HANDLE hPrivateData, /* i/o: instance handle */ - Decoder_State *st, /* i/o: pointer to bitstream decoder state */ - Word16 nBits /* i: number of bits to decode */ + IGFSCFDEC_INSTANCE_HANDLE hPrivateData, /* i/o: instance handle */ + Decoder_State *st, /* i/o: pointer to bitstream decoder state */ + Word16 nBits /* i: number of bits to decode */ ) { Word16 i; @@ -74,14 +75,14 @@ static Word16 arith_decode_bits_fx( x = 0; move16(); - FOR (i = 0; i < nBits; ++i) /* nBits > 0 */ + FOR( i = 0; i < nBits; ++i ) /* nBits > 0 */ { - x = lshl(x, 1); + x = lshl( x, 1 ); /* decode one bit using the new raw AC function */ - bit = ari_decode_14bits_bit_ext_fx(st, &hPrivateData->acState); - if (bit != 0) + bit = ari_decode_14bits_bit_ext_fx( st, &hPrivateData->acState ); + if ( bit != 0 ) { - x = s_or(x, 1); + x = s_or( x, 1 ); } } @@ -90,8 +91,8 @@ static Word16 arith_decode_bits_fx( static Word16 arith_decode_residual_fx( IGFSCFDEC_INSTANCE_HANDLE hPrivateData, /* i/o: instance handle */ - Decoder_State *st, /* i/o: pointer to decoder state */ - const UWord16 *cumulativeFrequencyTable, /* i: cumulative frequency table to be used */ + Decoder_State *st, /* i/o: pointer to decoder state */ + const UWord16 *cumulativeFrequencyTable, /* i: cumulative frequency table to be used */ Word16 tableOffset /* i: offset used to align the table */ ) { @@ -101,69 +102,68 @@ static Word16 arith_decode_residual_fx( /* decode one of the IGF_SYMBOLS_IN_TABLE == 27 alphabet symbols using the new raw AC function */ - val = ari_decode_14bits_s27_ext_fx(st, &hPrivateData->acState, cumulativeFrequencyTable); + val = ari_decode_14bits_s27_ext_fx( st, &hPrivateData->acState, cumulativeFrequencyTable ); /* meaning of the values of val: */ /* esc_{0} IGF_MIN_ENC_SEPARATE ... IGF_MAX_ENC_SEPARATE esc_{IGF_SYMBOLS_IN_TABLE - 1} */ test(); - IF ((val != 0) && (NE_16(val, IGF_SYMBOLS_IN_TABLE - 1))) + IF( ( val != 0 ) && ( NE_16( val, IGF_SYMBOLS_IN_TABLE - 1 ) ) ) { - x = add(val, - 1 + IGF_MIN_ENC_SEPARATE); /* (val - 1) + IGF_MIN_ENC_SEPARATE */ + x = add( val, -1 + IGF_MIN_ENC_SEPARATE ); /* (val - 1) + IGF_MIN_ENC_SEPARATE */ - x = sub(x, tableOffset); + x = sub( x, tableOffset ); return x; } /* decode one of the tails of the distribution */ /* decode extra with 4 bits */ - extra = arith_decode_bits_fx(hPrivateData, st, 4); - IF (EQ_16(extra, 15)) /* escape code 15 to indicate extra >= 15 */ + extra = arith_decode_bits_fx( hPrivateData, st, 4 ); + IF( EQ_16( extra, 15 ) ) /* escape code 15 to indicate extra >= 15 */ { /* decode addtional extra with 6 bits */ - extra = arith_decode_bits_fx(hPrivateData, st, 6); - IF (EQ_16(extra, 63)) /* escape code 63 to indicate extra >= 63 */ + extra = arith_decode_bits_fx( hPrivateData, st, 6 ); + IF( EQ_16( extra, 63 ) ) /* escape code 63 to indicate extra >= 63 */ { /* decode safety extra with 7 bits */ - extra = arith_decode_bits_fx(hPrivateData, st, 7); - extra = add(63, extra); + extra = arith_decode_bits_fx( hPrivateData, st, 7 ); + extra = add( 63, extra ); } - extra = add(15, extra); + extra = add( 15, extra ); } - if (val == 0) + if ( val == 0 ) { /* escape code 0 to indicate x <= IGF_MIN_ENC_SEPARATE - 1 */ - x = sub(IGF_MIN_ENC_SEPARATE - 1, extra); + x = sub( IGF_MIN_ENC_SEPARATE - 1, extra ); } - if (EQ_16(val, IGF_SYMBOLS_IN_TABLE - 1)) + if ( EQ_16( val, IGF_SYMBOLS_IN_TABLE - 1 ) ) { /* escape code (IGF_SYMBOLS_IN_TABLE - 1) to indicate x >= IGF_MAX_ENC_SEPARATE + 1 */ - x = add(IGF_MAX_ENC_SEPARATE + 1, extra); + x = add( IGF_MAX_ENC_SEPARATE + 1, extra ); } - x = sub(x, tableOffset); + x = sub( x, tableOffset ); return x; } static void arith_decode_flush_fx( - Decoder_State *st /* i/o: pointer to decoder state */ + Decoder_State *st /* i/o: pointer to decoder state */ ) { - get_next_indice_tmp_fx(st, -14); /* return back the least significant 14 bits to the bitstream */ - + get_next_indice_tmp_fx( st, -14 ); /* return back the least significant 14 bits to the bitstream */ } static void decode_sfe_vector_fx( - IGFSCFDEC_INSTANCE_HANDLE hPrivateData, /* i/o: instance handle */ - Decoder_State *st, /* i/o: pointer to decoder state */ - Word16 t, /* i: counter reset to 0 at each independent block */ - Word16 *prev_x, /* i: previous vector */ - Word16 *x, /* o: current vector to decode */ - Word16 length /* i: number of elements to decode */ + IGFSCFDEC_INSTANCE_HANDLE hPrivateData, /* i/o: instance handle */ + Decoder_State *st, /* i/o: pointer to decoder state */ + Word16 t, /* i: counter reset to 0 at each independent block */ + Word16 *prev_x, /* i: previous vector */ + Word16 *x, /* o: current vector to decode */ + Word16 length /* i: number of elements to decode */ ) { /* @@ -184,83 +184,82 @@ static void decode_sfe_vector_fx( Word32 index2; - - FOR (f = 0; f < length; ++f) + FOR( f = 0; f < length; ++f ) { - IF (t == 0) + IF( t == 0 ) { - IF (f == 0) + IF( f == 0 ) { /* (t == 0) && (f == 0) */ /* decode one of the IGF_SYMBOLS_IN_TABLE == 27 alphabet symbols using the new raw AC function */ - res = ari_decode_14bits_s27_ext_fx(st, &hPrivateData->acState, (const UWord16*) hPrivateData->cf_se00); + res = ari_decode_14bits_s27_ext_fx( st, &hPrivateData->acState, (const UWord16 *) hPrivateData->cf_se00 ); - pred = arith_decode_bits_fx(hPrivateData, st, 2); /* LSBs as 2 bit raw */ - x[f] = add(shl(res, 2), pred); + pred = arith_decode_bits_fx( hPrivateData, st, 2 ); /* LSBs as 2 bit raw */ + x[f] = add( shl( res, 2 ), pred ); move16(); } - ELSE IF (EQ_16(f, 1)) + ELSE IF( EQ_16( f, 1 ) ) { /* (t == 0) && (f == 1) */ - res = arith_decode_residual_fx(hPrivateData, - st, - hPrivateData->cf_se01, - hPrivateData->cf_off_se01); - x[f] = add(x[0], res); + res = arith_decode_residual_fx( hPrivateData, + st, + hPrivateData->cf_se01, + hPrivateData->cf_off_se01 ); + x[f] = add( x[0], res ); move16(); /* f - increment is 0, pred = b */ } ELSE { /* (t == 0) && (f >= 2) */ - prev_offset = sub(f, 1); - ctx = quant_ctx_fx(sub(x[prev_offset], x[sub(prev_offset, 1)])); /* Q(b - e) */ + prev_offset = sub( f, 1 ); + ctx = quant_ctx_fx( sub( x[prev_offset], x[sub( prev_offset, 1 )] ) ); /* Q(b - e) */ /* index1 is (IGF_SYMBOLS_IN_TABLE + 1) * (CTX_OFFSET + ctx) */ - index1 = L_mac0((IGF_SYMBOLS_IN_TABLE + 1) * IGF_CTX_OFFSET, (IGF_SYMBOLS_IN_TABLE + 1), ctx); + index1 = L_mac0( ( IGF_SYMBOLS_IN_TABLE + 1 ) * IGF_CTX_OFFSET, ( IGF_SYMBOLS_IN_TABLE + 1 ), ctx ); /* index2 is IGF_CTX_OFFSET + ctx */ - index2 = L_mac0(IGF_CTX_OFFSET, 1, ctx); - res = arith_decode_residual_fx(hPrivateData, - st, - hPrivateData->cf_se02 + index1, - hPrivateData->cf_off_se02[index2]); - x[f] = add(x[prev_offset], res); + index2 = L_mac0( IGF_CTX_OFFSET, 1, ctx ); + res = arith_decode_residual_fx( hPrivateData, + st, + hPrivateData->cf_se02 + index1, + hPrivateData->cf_off_se02[index2] ); + x[f] = add( x[prev_offset], res ); move16(); /* pred = b */ } } ELSE { /* t == 1 */ - IF (f == 0) + IF( f == 0 ) { /* (t == 1) && (f == 0) */ - res = arith_decode_residual_fx(hPrivateData, - st, - hPrivateData->cf_se10, - hPrivateData->cf_off_se10); - x[f] = add(prev_x[f], res); + res = arith_decode_residual_fx( hPrivateData, + st, + hPrivateData->cf_se10, + hPrivateData->cf_off_se10 ); + x[f] = add( prev_x[f], res ); move16(); /* pred = a */ } ELSE { /* (t == 1) && (f >= 1) */ - prev_offset = sub(f, 1); - pred = add(prev_x[f], x[prev_offset]); - pred = sub(pred, prev_x[prev_offset]); /* pred = a + b - c */ - ctx_f = quant_ctx_fx(sub(prev_x[f], prev_x[prev_offset])); /* Q(a - c) */ - ctx_t = quant_ctx_fx(sub(x[prev_offset], prev_x[prev_offset])); /* Q(b - c) */ + prev_offset = sub( f, 1 ); + pred = add( prev_x[f], x[prev_offset] ); + pred = sub( pred, prev_x[prev_offset] ); /* pred = a + b - c */ + ctx_f = quant_ctx_fx( sub( prev_x[f], prev_x[prev_offset] ) ); /* Q(a - c) */ + ctx_t = quant_ctx_fx( sub( x[prev_offset], prev_x[prev_offset] ) ); /* Q(b - c) */ /* index1 is (IGF_SYMBOLS_IN_TABLE + 1) * IGF_CTX_COUNT * (IGF_CTX_OFFSET + ctx_t) + (IGF_SYMBOLS_IN_TABLE + 1) * (IGF_CTX_OFFSET + ctx_f) */ index1 = L_mac0( - ((IGF_SYMBOLS_IN_TABLE + 1) * IGF_CTX_COUNT + (IGF_SYMBOLS_IN_TABLE + 1)) * IGF_CTX_OFFSET, - (IGF_SYMBOLS_IN_TABLE + 1) * IGF_CTX_COUNT, ctx_t); - index1 = L_mac0(index1, (IGF_SYMBOLS_IN_TABLE + 1), ctx_f); + ( ( IGF_SYMBOLS_IN_TABLE + 1 ) * IGF_CTX_COUNT + ( IGF_SYMBOLS_IN_TABLE + 1 ) ) * IGF_CTX_OFFSET, + ( IGF_SYMBOLS_IN_TABLE + 1 ) * IGF_CTX_COUNT, ctx_t ); + index1 = L_mac0( index1, ( IGF_SYMBOLS_IN_TABLE + 1 ), ctx_f ); /* index2 is IGF_CTX_COUNT * (IGF_CTX_OFFSET + ctx_t) + (IGF_CTX_OFFSET + ctx_f) */ - index2 = L_mac0((IGF_CTX_COUNT + 1) * IGF_CTX_OFFSET, IGF_CTX_COUNT, ctx_t); - index2 = L_mac0(index2, 1, ctx_f); - res = arith_decode_residual_fx(hPrivateData, - st, - hPrivateData->cf_se11 + index1, - hPrivateData->cf_off_se11[index2]); - x[f] = add(pred, res); + index2 = L_mac0( ( IGF_CTX_COUNT + 1 ) * IGF_CTX_OFFSET, IGF_CTX_COUNT, ctx_t ); + index2 = L_mac0( index2, 1, ctx_f ); + res = arith_decode_residual_fx( hPrivateData, + st, + hPrivateData->cf_se11 + index1, + hPrivateData->cf_off_se11[index2] ); + x[f] = add( pred, res ); move16(); } } @@ -273,7 +272,7 @@ static void decode_sfe_vector_fx( move16(); } - IF (GT_16(x[f],91)) + IF( GT_16( x[f], 91 ) ) { x[f] = 91; move16(); @@ -281,14 +280,13 @@ static void decode_sfe_vector_fx( move16(); } } - } /**********************************************************************/ /** resets the internal decoder memory (context memory) **************************************************************************/ void IGFSCFDecoderReset( - IGFSCFDEC_INSTANCE_HANDLE hPublicData /* i/o: handle to public data */ + IGFSCFDEC_INSTANCE_HANDLE hPublicData /* i/o: handle to public data */ ) { @@ -296,7 +294,6 @@ void IGFSCFDecoderReset( /* reset of coder */ hPublicData->t = 0; /* indicate that an independent block follows */ /* we do not need to fill hPublicData->prev with zeros, because when t = 0 no previous information is used */ - } /**********************************************************************/ /** @@ -304,35 +301,34 @@ main decoder function **************************************************************************/ void IGFSCFDecoderDecode( IGFSCFDEC_INSTANCE_HANDLE hPublicData, /* i/o: handle to public data or NULL in case there was no instance created */ - Decoder_State* st, /* i/o: pointer to decoder state */ - int16_t* sfe, /* o : ptr to an array which will contain the decoded quantized coefficients */ - const Word16 igfGridIdx, /* i : igf grid index see declaration of IGF_GRID_IDX for details */ - const Word16 indepFlag /* i : if 1 on input the decoder will be forced to reset, - if 0 on input the decoder will be forced to encode without a reset */ + Decoder_State *st, /* i/o: pointer to decoder state */ + int16_t *sfe, /* o : ptr to an array which will contain the decoded quantized coefficients */ + const Word16 igfGridIdx, /* i : igf grid index see declaration of IGF_GRID_IDX for details */ + const Word16 indepFlag /* i : if 1 on input the decoder will be forced to reset, + if 0 on input the decoder will be forced to encode without a reset */ ) { - /* insert data */ + /* insert data */ hPublicData->bitsRead = st->next_bit_pos; move16(); - ari_start_decoding_14bits_fx(st, &hPublicData->acState); /* start AC decoding */ + ari_start_decoding_14bits_fx( st, &hPublicData->acState ); /* start AC decoding */ /* check if coder needs a reset and do it if necessary */ - IF (indepFlag != 0) + IF( indepFlag != 0 ) { /* reset of coder */ - IGFSCFDecoderReset(hPublicData); + IGFSCFDecoderReset( hPublicData ); } - decode_sfe_vector_fx(hPublicData, st, hPublicData->t, hPublicData->prev, sfe, hPublicData->scfCountLongBlock[igfGridIdx] ); + decode_sfe_vector_fx( hPublicData, st, hPublicData->t, hPublicData->prev, sfe, hPublicData->scfCountLongBlock[igfGridIdx] ); - arith_decode_flush_fx(st); /* finish AC decoding */ + arith_decode_flush_fx( st ); /* finish AC decoding */ /* advance history */ - Copy(sfe, hPublicData->prev, hPublicData->scfCountLongBlock[igfGridIdx]); - hPublicData->t = add(hPublicData->t, 1); - - hPublicData->bitsRead = sub(st->next_bit_pos, hPublicData->bitsRead); + Copy( sfe, hPublicData->prev, hPublicData->scfCountLongBlock[igfGridIdx] ); + hPublicData->t = add( hPublicData->t, 1 ); + hPublicData->bitsRead = sub( st->next_bit_pos, hPublicData->bitsRead ); } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/init_dec.c b/lib_dec/init_dec.c index 954ed19fa..3a56b99e5 100644 --- a/lib_dec/init_dec.c +++ b/lib_dec/init_dec.c @@ -746,7 +746,7 @@ ivas_error init_decoder( void reset_preecho_dec( HQ_DEC_HANDLE hHQ_core /* i/o: HQ decoder handle */ ) -{ +{ hHQ_core->memfilt_lb = 0; hHQ_core->mean_prev_hb = 0; hHQ_core->smoothmem = 1; @@ -796,4 +796,4 @@ void destroy_cldfb_decoder_flt( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/init_dec_fx.c b/lib_dec/init_dec_fx.c index 195c656cd..3f94cea06 100644 --- a/lib_dec/init_dec_fx.c +++ b/lib_dec/init_dec_fx.c @@ -2,12 +2,12 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include "options.h" /* Compilation switches */ +#include "options.h" /* Compilation switches */ #include "prot_fx1.h" #include "prot_fx2.h" -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "stl.h" /* required for wmc_tool */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "stl.h" /* required for wmc_tool */ #include "basop_util.h" #include "prot.h" #ifdef IVAS_FLOAT_FIXED @@ -22,10 +22,11 @@ *----------------------------------------------------------------------*/ ivas_error init_decoder_fx( - Decoder_State *st_fx, /* o: Decoder static variables structure */ - const Word16 idchan /* i : channel ID */ + Decoder_State *st_fx, /* o: Decoder static variables structure */ + const Word16 idchan /* i : channel ID */ #ifdef IVAS_CODE - ,const MC_MODE mc_mode /* i : MC mode */ + , + const MC_MODE mc_mode /* i : MC mode */ #endif ) { @@ -50,9 +51,9 @@ ivas_error init_decoder_fx( move16(); st_fx->core = ACELP_CORE; move16(); - st_fx->L_frame = L_FRAME; + st_fx->L_frame = L_FRAME; move16(); - st_fx->extl = -1; + st_fx->extl = -1; move16(); st_fx->total_brate = 8000; move16(); @@ -60,7 +61,7 @@ ivas_error init_decoder_fx( move16(); st_fx->last_total_brate_ber = -1; move32(); - st_fx->core_brate = 8000; + st_fx->core_brate = 8000; move16(); st_fx->ini_frame = 0; move16(); @@ -70,11 +71,11 @@ ivas_error init_decoder_fx( move16(); - st_fx->last_coder_type = GENERIC; + st_fx->last_coder_type = GENERIC; move16(); - st_fx->last_L_frame = st_fx->L_frame; + st_fx->last_L_frame = st_fx->L_frame; move16(); - st_fx->last_core_brate = st_fx->core_brate ; + st_fx->last_core_brate = st_fx->core_brate; move16(); st_fx->last_core = -1; @@ -91,17 +92,17 @@ ivas_error init_decoder_fx( set16_fx( st_fx->mem_MA_fx, 0, M ); st_fx->dm_fx.prev_state = 0; - move16(); /* This corresponds to st_fx->dispMem in FLP */ - st_fx->dm_fx.prev_gain_code = L_deposit_l(0); - FOR(i=2; i<8; i++) + move16(); /* This corresponds to st_fx->dispMem in FLP */ + st_fx->dm_fx.prev_gain_code = L_deposit_l( 0 ); + FOR( i = 2; i < 8; i++ ) { - st_fx->dm_fx.prev_gain_pit[i-2] = 0; + st_fx->dm_fx.prev_gain_pit[i - 2] = 0; move16(); } st_fx->tilt_code_fx = 0; move16(); - st_fx->gc_threshold_fx = L_deposit_l(0); + st_fx->gc_threshold_fx = L_deposit_l( 0 ); st_fx->last_good = UNVOICED_CLAS; move16(); st_fx->clas_dec = UNVOICED_CLAS; @@ -128,14 +129,14 @@ ivas_error init_decoder_fx( * SWB BWE parameters *-----------------------------------------------------------------*/ - IF (idchan == 0 && NE_16(st_fx->element_mode, IVAS_CPE_MDCT)) + IF( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) { - IF ((st_fx->hBWE_FD = (FD_BWE_DEC_HANDLE)count_malloc(sizeof(FD_BWE_DEC_DATA))) == NULL) + IF( ( st_fx->hBWE_FD = (FD_BWE_DEC_HANDLE) count_malloc( sizeof( FD_BWE_DEC_DATA ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FD BWE\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FD BWE\n" ) ); } - fd_bwe_dec_init(st_fx, st_fx->hBWE_FD); + fd_bwe_dec_init( st_fx, st_fx->hBWE_FD ); } ELSE { @@ -143,14 +144,14 @@ ivas_error init_decoder_fx( } /*-----------------------------------------------------------------* - * IGF - *-----------------------------------------------------------------*/ + * IGF + *-----------------------------------------------------------------*/ - IF ((idchan == 0 || EQ_16(st_fx->element_mode, IVAS_CPE_MDCT)) ) + IF( ( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) { - IF ((st_fx->hIGFDec = (IGF_DEC_INSTANCE_HANDLE)count_malloc(sizeof(IGFDEC_INSTANCE))) == NULL) + IF( ( st_fx->hIGFDec = (IGF_DEC_INSTANCE_HANDLE) count_malloc( sizeof( IGFDEC_INSTANCE ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for IGF\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for IGF\n" ) ); } st_fx->igf = 0; @@ -166,14 +167,14 @@ ivas_error init_decoder_fx( * HR SWB BWE parameters *-----------------------------------------------------------------*/ - IF (EQ_16(st_fx->element_mode, EVS_MONO)) + IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) { - IF ((st_fx->hBWE_FD_HR = (HR_BWE_DEC_HANDLE)count_malloc(sizeof(HR_BWE_DEC_DATA))) == NULL) + IF( ( st_fx->hBWE_FD_HR = (HR_BWE_DEC_HANDLE) count_malloc( sizeof( HR_BWE_DEC_DATA ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HR BWE\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HR BWE\n" ) ); } - hr_bwe_dec_init(st_fx->hBWE_FD_HR); + hr_bwe_dec_init( st_fx->hBWE_FD_HR ); } ELSE { @@ -202,16 +203,16 @@ ivas_error init_decoder_fx( st_fx->last_voice_factor_fx = 0; move16(); - set16_fx(st_fx->prev_lpc_wb_fx, 0, LPC_SHB_ORDER_WB); + set16_fx( st_fx->prev_lpc_wb_fx, 0, LPC_SHB_ORDER_WB ); - IF ((idchan == 0 && NE_16(st_fx->element_mode, IVAS_CPE_MDCT)) || EQ_16(st_fx->element_mode, IVAS_CPE_TD)) + IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) { - IF ((st_fx->hGSCDec = (GSC_DEC_HANDLE)count_malloc(sizeof(GSC_DEC_DATA))) == NULL) + IF( ( st_fx->hGSCDec = (GSC_DEC_HANDLE) count_malloc( sizeof( GSC_DEC_DATA ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for GSC\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for GSC\n" ) ); } - GSC_dec_init(st_fx->hGSCDec); + GSC_dec_init( st_fx->hGSCDec ); } ELSE { @@ -221,16 +222,17 @@ ivas_error init_decoder_fx( /*-----------------------------------------------------------------* * parameters for fast recovery (WI) *-----------------------------------------------------------------*/ - test(); test(); - IF (EQ_32(st_fx->output_Fs, 16000) && EQ_16(st_fx->element_mode, EVS_MONO ) ) + test(); + test(); + IF( EQ_32( st_fx->output_Fs, 16000 ) && EQ_16( st_fx->element_mode, EVS_MONO ) ) { - IF ((st_fx->hWIDec = (WI_DEC_HANDLE)count_malloc(sizeof(WI_DEC_DATA))) == NULL) + IF( ( st_fx->hWIDec = (WI_DEC_HANDLE) count_malloc( sizeof( WI_DEC_DATA ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FEC WI\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FEC WI\n" ) ); } - set16_fx(st_fx->hWIDec->old_exc2_fx, 0, L_EXC_MEM); - set16_fx(st_fx->hWIDec->old_syn2_fx, 0, L_EXC_MEM); + set16_fx( st_fx->hWIDec->old_exc2_fx, 0, L_EXC_MEM ); + set16_fx( st_fx->hWIDec->old_syn2_fx, 0, L_EXC_MEM ); } else { @@ -241,20 +243,20 @@ ivas_error init_decoder_fx( /*-----------------------------------------------------------------* * NB/formant post-filter *-----------------------------------------------------------------*/ - IF ((idchan == 0 && NE_16(st_fx->element_mode,IVAS_CPE_MDCT)) || EQ_16(st_fx->element_mode, IVAS_CPE_TD)) - { - IF ((st_fx->hPFstat = (PFSTAT_HANDLE)count_malloc(sizeof(PFSTAT))) == NULL) - { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for NB/formant postflter\n")); - } - - Init_post_filter_fx(st_fx->hPFstat); - st_fx->psf_lp_noise_fx = 0; - } - ELSE - { - st_fx->hPFstat = NULL; - } + IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) + { + IF( ( st_fx->hPFstat = (PFSTAT_HANDLE) count_malloc( sizeof( PFSTAT ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for NB/formant postflter\n" ) ); + } + + Init_post_filter_fx( st_fx->hPFstat ); + st_fx->psf_lp_noise_fx = 0; + } + ELSE + { + st_fx->hPFstat = NULL; + } st_fx->psf_lp_noise_fx = 0; move16(); @@ -268,11 +270,11 @@ ivas_error init_decoder_fx( st_fx->prev_bfi = 0; move16(); st_fx->lp_ener_FER_fx = 15360; - move16(); /*60 in Q8*/ + move16(); /*60 in Q8*/ st_fx->old_enr_LP = 0; move16(); - st_fx->lp_ener_fx = L_deposit_l(0); - st_fx->enr_old_fx = L_deposit_l(0); + st_fx->lp_ener_fx = L_deposit_l( 0 ); + st_fx->enr_old_fx = L_deposit_l( 0 ); st_fx->bfi_pitch_fx = L_SUBFR_Q6; move16(); st_fx->bfi_pitch_frame = L_SUBFR; @@ -283,10 +285,10 @@ ivas_error init_decoder_fx( st_fx->last_con_tcx = 0; move16(); - FOR (i=0; i<2*NB_SUBFR16k; i++) + FOR( i = 0; i < 2 * NB_SUBFR16k; i++ ) { - st_fx->old_pitch_buf_fx[i] = L_SUBFR<<16; - move32(); /*15Q16*/ + st_fx->old_pitch_buf_fx[i] = L_SUBFR << 16; + move32(); /*15Q16*/ } st_fx->upd_cnt = MAX_UPD_CNT; @@ -308,7 +310,7 @@ ivas_error init_decoder_fx( /* Stationary noise UV modification */ st_fx->unv_cnt = 0; move16(); - st_fx->ge_sm_fx = L_deposit_l(640); /*Q(GE_SHIFT)*/ + st_fx->ge_sm_fx = L_deposit_l( 640 ); /*Q(GE_SHIFT)*/ st_fx->uv_count = 0; move16(); st_fx->act_count = 3; @@ -317,7 +319,7 @@ ivas_error init_decoder_fx( st_fx->noimix_seed = RANDOM_INITSEED; move16(); st_fx->min_alpha_fx = 32767; - move16(); /*1; Q15*/ + move16(); /*1; Q15*/ st_fx->exc_pe_fx = 0; move16(); #ifdef MSAN_FIX @@ -326,14 +328,14 @@ ivas_error init_decoder_fx( /*-----------------------------------------------------------------* * LD music post-filter *-----------------------------------------------------------------*/ - IF ((idchan == 0 && NE_16(st_fx->element_mode, IVAS_CPE_MDCT)) || EQ_16(st_fx->element_mode, IVAS_CPE_TD)) + IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) { - IF ((st_fx->hMusicPF = (MUSIC_POSTFILT_HANDLE)count_malloc(sizeof(MUSIC_POSTFILT_DATA))) == NULL) + IF( ( st_fx->hMusicPF = (MUSIC_POSTFILT_HANDLE) count_malloc( sizeof( MUSIC_POSTFILT_DATA ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LD music postflter\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LD music postflter\n" ) ); } - music_postfilt_init(st_fx->hMusicPF); + music_postfilt_init( st_fx->hMusicPF ); } ELSE { @@ -341,15 +343,17 @@ ivas_error init_decoder_fx( } /* CNG and DTX */ - test(); test(); test(); - IF (idchan == 0 && (EQ_16(st_fx->element_mode, EVS_MONO) || EQ_16(st_fx->element_mode, IVAS_CPE_DFT) || EQ_16(st_fx->element_mode, IVAS_CPE_TD) )) + test(); + test(); + test(); + IF( idchan == 0 && ( EQ_16( st_fx->element_mode, EVS_MONO ) || EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) ) { - if ((st_fx->hTdCngDec = (TD_CNG_DEC_HANDLE)count_malloc(sizeof(TD_CNG_DEC_DATA))) == NULL) + if ( ( st_fx->hTdCngDec = (TD_CNG_DEC_HANDLE) count_malloc( sizeof( TD_CNG_DEC_DATA ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX/TD CNG\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX/TD CNG\n" ) ); } - td_cng_dec_init_fx(st_fx); + td_cng_dec_init_fx( st_fx ); } ELSE { @@ -357,9 +361,9 @@ ivas_error init_decoder_fx( } st_fx->cng_type = -1; st_fx->CNG_fx = 0; - move16(); /* RTXDTX handler CNG=1 nonCNG= 0,*/ + move16(); /* RTXDTX handler CNG=1 nonCNG= 0,*/ st_fx->prev_ft_speech_fx = 1; - move16(); /* RXDTX handeler previous frametype flag for G.192 format AMRWB SID_FIRST detection */ + move16(); /* RXDTX handeler previous frametype flag for G.192 format AMRWB SID_FIRST detection */ st_fx->first_CNG = 0; move16(); Copy( st_fx->lsp_old_fx, st_fx->lspCNG_fx, M ); @@ -382,7 +386,7 @@ ivas_error init_decoder_fx( move16(); move16(); - FOR ( i=0; ilsp_shb_prev_fx[i] = lsp_shb_prev_tbl_fx[i]; st_fx->lsp_shb_prev_prev_fx[i] = st_fx->lsp_shb_prev_fx[i]; @@ -406,30 +410,34 @@ ivas_error init_decoder_fx( st_fx->cngTDLevel_e = 0; move16(); - /*-----------------------------------------------------------------* * HQ core parameters *-----------------------------------------------------------------*/ - test(); test(); test(); test(); test(); test(); - IF ((idchan == 0 || EQ_16(st_fx->element_mode, IVAS_CPE_MDCT) || EQ_16(st_fx->element_mode, IVAS_SCE) || EQ_16(st_fx->element_mode, EVS_MONO)) ) - { - IF ((st_fx->hHQ_core = (HQ_DEC_HANDLE)count_malloc(sizeof(HQ_DEC_DATA))) == NULL) + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) || EQ_16( st_fx->element_mode, IVAS_SCE ) || EQ_16( st_fx->element_mode, EVS_MONO ) ) ) + { + IF( ( st_fx->hHQ_core = (HQ_DEC_HANDLE) count_malloc( sizeof( HQ_DEC_DATA ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HQ core\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HQ core\n" ) ); } /* HQ core initialization */ - HQ_core_dec_init_fx(st_fx->hHQ_core); + HQ_core_dec_init_fx( st_fx->hHQ_core ); - IF (EQ_16(st_fx->element_mode, EVS_MONO)) + IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) { /* HQ NB FEC initialization */ - IF ((st_fx->hHQ_nbfec = (HQ_NBFEC_HANDLE)count_malloc(sizeof(HQ_NBFEC_DATA))) == NULL) + IF( ( st_fx->hHQ_nbfec = (HQ_NBFEC_HANDLE) count_malloc( sizeof( HQ_NBFEC_DATA ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HQ NB FEC\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HQ NB FEC\n" ) ); } - HQ_nbfec_init_fx(st_fx->hHQ_nbfec); + HQ_nbfec_init_fx( st_fx->hHQ_nbfec ); } ELSE { @@ -441,27 +449,28 @@ ivas_error init_decoder_fx( { st_fx->hHQ_core = NULL; st_fx->hHQ_nbfec = NULL; - move16(); move16(); + move16(); + move16(); } st_fx->Qprev_synth_buffer_fx = 15; st_fx->old_bfi_cnt = 0; st_fx->prev_old_bfi = 0; - set16_fx(st_fx->delay_buf_out_fx, 0, HQ_DELTA_MAX* HQ_DELAY_COMP); - set16_fx(st_fx->previoussynth_fx, 0, L_FRAME48k); - IF (EQ_16(st_fx->element_mode, EVS_MONO ) ) + set16_fx( st_fx->delay_buf_out_fx, 0, HQ_DELTA_MAX * HQ_DELAY_COMP ); + set16_fx( st_fx->previoussynth_fx, 0, L_FRAME48k ); + IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) { - set16_fx(st_fx->old_synth_sw_fx, 0, NS2SA(48000, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS)); + set16_fx( st_fx->old_synth_sw_fx, 0, NS2SA( 48000, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS ) ); } /*-----------------------------------------------------------------* * TCX core *-----------------------------------------------------------------*/ - /* TCX-LTP */ - IF ((idchan == 0 || EQ_16(st_fx->element_mode, IVAS_CPE_MDCT)) ) + /* TCX-LTP */ + IF( ( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) { - IF ((st_fx->hTcxLtpDec = (TCX_LTP_DEC_HANDLE)count_malloc(sizeof(TCX_LTP_DEC_DATA))) == NULL) + IF( ( st_fx->hTcxLtpDec = (TCX_LTP_DEC_HANDLE) count_malloc( sizeof( TCX_LTP_DEC_DATA ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TCX-LTP handle\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TCX-LTP handle\n" ) ); } } ELSE @@ -471,28 +480,28 @@ ivas_error init_decoder_fx( /* TCX core */ // VE: reduction possible for MCT_CHAN_MODE_LFE channel - see I1-172 - IF (idchan == 0 || EQ_16(st_fx->element_mode, IVAS_CPE_MDCT)) + IF( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) { - IF ((st_fx->hTcxDec = (TCX_DEC_HANDLE)count_malloc(sizeof(TCX_DEC_DATA))) == NULL) + IF( ( st_fx->hTcxDec = (TCX_DEC_HANDLE) count_malloc( sizeof( TCX_DEC_DATA ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxDec\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxDec\n" ) ); } - set16_fx(st_fx->hTcxDec->FBTCXdelayBuf, 0, 111); + set16_fx( st_fx->hTcxDec->FBTCXdelayBuf, 0, 111 ); - st_fx->hTcxDec->old_synthFB_fx = st_fx->hTcxDec->synth_history_fx + NS2SA(st_fx->output_Fs, PH_ECU_MEM_NS); - st_fx->hTcxDec->prev_good_synth_fx = st_fx->hTcxDec->old_synthFB_fx + NS2SA(st_fx->output_Fs, PH_ECU_LOOKAHEAD_NS); + st_fx->hTcxDec->old_synthFB_fx = st_fx->hTcxDec->synth_history_fx + NS2SA( st_fx->output_Fs, PH_ECU_MEM_NS ); + st_fx->hTcxDec->prev_good_synth_fx = st_fx->hTcxDec->old_synthFB_fx + NS2SA( st_fx->output_Fs, PH_ECU_LOOKAHEAD_NS ); } ELSE { st_fx->hTcxDec = NULL; } - /* TCX config. data structure */ - IF ((idchan == 0 || EQ_16(st_fx->element_mode, IVAS_CPE_MDCT))) + /* TCX config. data structure */ + IF( ( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) { - IF ((st_fx->hTcxCfg = (TCX_CONFIG_HANDLE)count_malloc(sizeof(TCX_config))) == NULL) + IF( ( st_fx->hTcxCfg = (TCX_CONFIG_HANDLE) count_malloc( sizeof( TCX_config ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxCfg\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxCfg\n" ) ); } } ELSE @@ -506,27 +515,28 @@ ivas_error init_decoder_fx( st_fx->tilt_wb_fx = 0; move16(); - set16_fx(st_fx->prev_synth_buffer_fx, 0, NS2SA_fx2(48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS)); - set16_fx(st_fx->hb_prev_synth_buffer_fx, 0, NS2SA_fx2(48000, DELAY_BWE_TOTAL_NS)); - st_fx->old_bwe_delay = -1; /*Q0*/ move16(); + set16_fx( st_fx->prev_synth_buffer_fx, 0, NS2SA_fx2( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) ); + set16_fx( st_fx->hb_prev_synth_buffer_fx, 0, NS2SA_fx2( 48000, DELAY_BWE_TOTAL_NS ) ); + st_fx->old_bwe_delay = -1; /*Q0*/ + move16(); /*-----------------------------------------------------------------* * TBE parameters *-----------------------------------------------------------------*/ - IF (idchan == 0 && NE_16(st_fx->element_mode, IVAS_CPE_MDCT)) + IF( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) { - if ((st_fx->hBWE_TD = (TD_BWE_DEC_HANDLE)count_malloc(sizeof(TD_BWE_DEC_DATA))) == NULL) + if ( ( st_fx->hBWE_TD = (TD_BWE_DEC_HANDLE) count_malloc( sizeof( TD_BWE_DEC_DATA ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD BWE\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD BWE\n" ) ); } - td_bwe_dec_init_fx(st_fx, st_fx->hBWE_TD, -#ifdef ADD_IVAS_BWE - st_fx->extl, + td_bwe_dec_init_fx( st_fx, st_fx->hBWE_TD, +#ifdef ADD_IVAS_BWE + st_fx->extl, #endif - st_fx->output_Fs); + st_fx->output_Fs ); #ifdef MSAN_FIX st_fx->hBWE_TD->prev_hb_synth_fx_exp = 31; @@ -544,8 +554,8 @@ ivas_error init_decoder_fx( move16(); st_fx->prev_enerLH_fx = 0; move16(); - st_fx->enerLH_fx = L_deposit_l(0); - st_fx->enerLL_fx = L_deposit_l(0); + st_fx->enerLH_fx = L_deposit_l( 0 ); + st_fx->enerLL_fx = L_deposit_l( 0 ); st_fx->prev_enerLL_fx = 0; move16(); st_fx->prev_fractive = 0; @@ -595,21 +605,21 @@ ivas_error init_decoder_fx( st_fx->rf_indx_tbeGainFr = 0; move16(); - /*----------------------------------------------------------------------------------* - * AMR-WB IO mode parameters - *----------------------------------------------------------------------------------*/ - IF (st_fx->Opt_AMR_WB || EQ_16(st_fx->element_mode, EVS_MONO) ) + /*----------------------------------------------------------------------------------* + * AMR-WB IO mode parameters + *----------------------------------------------------------------------------------*/ + IF( st_fx->Opt_AMR_WB || EQ_16( st_fx->element_mode, EVS_MONO ) ) { - IF ((st_fx->hAmrwb_IO = (AMRWB_IO_DEC_HANDLE)count_malloc(sizeof(AMRWB_IO_DEC_DATA))) == NULL) + IF( ( st_fx->hAmrwb_IO = (AMRWB_IO_DEC_HANDLE) count_malloc( sizeof( AMRWB_IO_DEC_DATA ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for AMR-WB IO\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for AMR-WB IO\n" ) ); } /* AMR-WB IO init */ - amr_wb_dec_init_fx(st_fx->hAmrwb_IO); + amr_wb_dec_init_fx( st_fx->hAmrwb_IO ); /* AMR-WB IO HF synth init */ - hf_synth_amr_wb_init_fx(st_fx->hAmrwb_IO); + hf_synth_amr_wb_init_fx( st_fx->hAmrwb_IO ); } ELSE { @@ -619,17 +629,16 @@ ivas_error init_decoder_fx( * HF (6-7kHz) (zero) BWE parameters *-----------------------------------------------------------------*/ - IF ((idchan == 0 && NE_16(st_fx->element_mode, IVAS_CPE_MDCT)) || EQ_16(st_fx->element_mode, IVAS_CPE_TD)) + IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) { - IF ((st_fx->hBWE_zero = (ZERO_BWE_DEC_HANDLE)count_malloc(sizeof(ZERO_BWE_DEC_DATA))) == NULL) + IF( ( st_fx->hBWE_zero = (ZERO_BWE_DEC_HANDLE) count_malloc( sizeof( ZERO_BWE_DEC_DATA ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for zero BWE\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for zero BWE\n" ) ); } - hf_synth_init_fx(st_fx->hBWE_zero); + hf_synth_init_fx( st_fx->hBWE_zero ); /* TBV Hack for bit exactness with 26.452, Issue should be corrected there as the the reset is not perform on all values of mem_hp400_fx*/ - set16_fx(st_fx->hBWE_zero->mem_hp400_fx, 0, 6); - + set16_fx( st_fx->hBWE_zero->mem_hp400_fx, 0, 6 ); } ELSE { @@ -637,23 +646,24 @@ ivas_error init_decoder_fx( } /* HF synth init */ - hf_synth_amr_wb_init_fx(st_fx->hAmrwb_IO); - + hf_synth_amr_wb_init_fx( st_fx->hAmrwb_IO ); st_fx->bpf_off = 0; /*-----------------------------------------------------------------* * Bass post-filter parameters *-----------------------------------------------------------------*/ - test(); test(); test(); - IF ((idchan == 0 && NE_16(st_fx->element_mode, IVAS_CPE_MDCT)) || EQ_16(st_fx->element_mode, IVAS_CPE_TD)) + test(); + test(); + test(); + IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) { - IF ((st_fx->hBPF = (BPF_DEC_HANDLE)count_malloc(sizeof(BPF_DEC_DATA))) == NULL) + IF( ( st_fx->hBPF = (BPF_DEC_HANDLE) count_malloc( sizeof( BPF_DEC_DATA ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for BPF\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for BPF\n" ) ); } - bass_psfilter_init_fx(st_fx->hBPF); + bass_psfilter_init_fx( st_fx->hBPF ); } ELSE { @@ -663,18 +673,18 @@ ivas_error init_decoder_fx( * FD BPF & resampling tools parameters *-----------------------------------------------------------------*/ /* open analysis for max. SR 48kHz */ - if ((error = openCldfb(&st_fx->cldfbAna, CLDFB_ANALYSIS, CLDFB_getNumChannels(48000), 320)) != IVAS_ERR_OK) + if ( ( error = openCldfb( &st_fx->cldfbAna, CLDFB_ANALYSIS, CLDFB_getNumChannels( 48000 ), 320 ) ) != IVAS_ERR_OK ) { return error; } /* open analysis BPF for max. SR 16kHz */ - if ((error = openCldfb(&st_fx->cldfbBPF, CLDFB_ANALYSIS, CLDFB_getNumChannels(16000), 320)) != IVAS_ERR_OK) + if ( ( error = openCldfb( &st_fx->cldfbBPF, CLDFB_ANALYSIS, CLDFB_getNumChannels( 16000 ), 320 ) ) != IVAS_ERR_OK ) { return error; } /* open synthesis for output SR */ - if ((error = openCldfb(&st_fx->cldfbSyn, CLDFB_SYNTHESIS, CLDFB_getNumChannels(st_fx->output_Fs), st_fx->output_frame_fx)) != IVAS_ERR_OK) + if ( ( error = openCldfb( &st_fx->cldfbSyn, CLDFB_SYNTHESIS, CLDFB_getNumChannels( st_fx->output_Fs ), st_fx->output_frame_fx ) ) != IVAS_ERR_OK ) { return error; } @@ -690,29 +700,29 @@ ivas_error init_decoder_fx( st_fx->last_flag_filter_NB = 0; st_fx->active_frame_cnt_bwddec = 0; st_fx->total_frame_cnt_bwddec = 0; - set16_fx(st_fx->flag_buffer, 0, 20); + set16_fx( st_fx->flag_buffer, 0, 20 ); st_fx->avg_nrg_LT = 0; st_fx->Ng_ener_ST_fx = -13056; - move16(); /*-51 IN Q8*/ + move16(); /*-51 IN Q8*/ st_fx->old_Es_pred_fx = 0; move16(); - set16_fx(st_fx->old_Aq_12_8_fx + 1, 0, M ); + set16_fx( st_fx->old_Aq_12_8_fx + 1, 0, M ); st_fx->old_Aq_12_8_fx[0] = 4096; - move16(); /*1 in Q12*/ + move16(); /*1 in Q12*/ /*-----------------------------------------------------------------* * SC-VBR parameters *-----------------------------------------------------------------*/ - IF (EQ_16(st_fx->element_mode, EVS_MONO)) + IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) { - IF ((st_fx->hSC_VBR = (SC_VBR_DEC_HANDLE)count_malloc(sizeof(SC_VBR_DEC_DATA))) == NULL) + IF( ( st_fx->hSC_VBR = (SC_VBR_DEC_HANDLE) count_malloc( sizeof( SC_VBR_DEC_DATA ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SC-VBR\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SC-VBR\n" ) ); } - sc_vbr_dec_init(st_fx->hSC_VBR); + sc_vbr_dec_init( st_fx->hSC_VBR ); } ELSE { @@ -739,13 +749,11 @@ ivas_error init_decoder_fx( move16(); - - st_fx->enablePlcWaveadjust = 0; move16(); /* Init Decoder */ - open_decoder_LPD_fx( st_fx, st_fx->total_brate, st_fx->bwidth); + open_decoder_LPD_fx( st_fx, st_fx->total_brate, st_fx->bwidth ); st_fx->m_decodeMode = DEC_NO_FRAM_LOSS; move16(); @@ -755,19 +763,19 @@ ivas_error init_decoder_fx( move16(); - newCldfbBands = CLDFB_getNumChannels(L_mult0(st_fx->L_frame, 50)); + newCldfbBands = CLDFB_getNumChannels( L_mult0( st_fx->L_frame, 50 ) ); resampleCldfb( st_fx->cldfbAna, newCldfbBands, st_fx->L_frame, 1 ); resampleCldfb( st_fx->cldfbBPF, newCldfbBands, st_fx->L_frame, 1 ); #ifdef IVAS_CODE - IF((EQ_16(st_fx->element_mode, IVAS_CPE_MDCT) || idchan == 0 ) && NE_16(mc_mode, MC_MODE_MCT) && NE_16(mc_mode, MC_MODE_PARAMUPMIX) ) // TBV Fixed point missing + IF( ( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) || idchan == 0 ) && NE_16( mc_mode, MC_MODE_MCT ) && NE_16( mc_mode, MC_MODE_PARAMUPMIX ) ) // TBV Fixed point missing #else - IF ( ( EQ_16(st_fx->element_mode, IVAS_CPE_MDCT) || idchan == 0) /*&& mc_mode != MC_MODE_MCT && mc_mode != MC_MODE_PARAMUPMIX*/) + IF( ( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) || idchan == 0 ) /*&& mc_mode != MC_MODE_MCT && mc_mode != MC_MODE_PARAMUPMIX*/ ) #endif { /* Create FD_CNG instance */ - if ((error = createFdCngDec_fx(&st_fx->hFdCngDec)) != IVAS_ERR_OK ) + if ( ( error = createFdCngDec_fx( &st_fx->hFdCngDec ) ) != IVAS_ERR_OK ) { return error; } @@ -780,7 +788,7 @@ ivas_error init_decoder_fx( st_fx->hFdCngDec = NULL; } - st_fx->lp_noise = -167772160l/*-20.f Q23*/; + st_fx->lp_noise = -167772160l /*-20.f Q23*/; st_fx->force_lpd_reset = 0; move16(); @@ -798,7 +806,7 @@ ivas_error init_decoder_fx( st_fx->prev_Q_syn = 0; move16(); - FOR(i=0; iQ_subfr[i] = 8; move16(); @@ -812,27 +820,26 @@ ivas_error init_decoder_fx( /*----------------------------------------------------------------------------------* * Stereo/IVAS parameters *----------------------------------------------------------------------------------*/ -#if 1 // IVAS_CODE -> To be verified - st_fx->tdm_LRTD_flag = 0; /* LRTD stereo mode flag */ - st_fx->cna_dirac_flag = 0; /* CNA in DirAC flag */ - st_fx->cng_sba_flag = 0; /* CNG in SBA flag */ - st_fx->element_mode = EVS_MONO; /* element mode */ +#if 1 // IVAS_CODE -> To be verified + st_fx->tdm_LRTD_flag = 0; /* LRTD stereo mode flag */ + st_fx->cna_dirac_flag = 0; /* CNA in DirAC flag */ + st_fx->cng_sba_flag = 0; /* CNG in SBA flag */ + st_fx->element_mode = EVS_MONO; /* element mode */ st_fx->last_element_mode = st_fx->element_mode; /* element mode */ - st_fx->element_brate = -1; /* element bitrate */ - st_fx->low_rate_mode = 0; /* low-rate mode flag */ - st_fx->last_low_rate_mode = 0; /* low-rate mode flag */ - //st_fx->cng_ism_flag = 0; - //st_fx->coder_type = GENERIC; /* low-rate mode flag */ + st_fx->element_brate = -1; /* element bitrate */ + st_fx->low_rate_mode = 0; /* low-rate mode flag */ + st_fx->last_low_rate_mode = 0; /* low-rate mode flag */ + // st_fx->cng_ism_flag = 0; + // st_fx->coder_type = GENERIC; /* low-rate mode flag */ #endif #ifdef DEBUGGING st_fx->id_element = -1; /* element ID */ #endif - st_fx->extl_orig = -1; /* extension layer */ - st_fx->extl_brate_orig = 0; /* extension layer bitrate */ + st_fx->extl_orig = -1; /* extension layer */ + st_fx->extl_brate_orig = 0; /* extension layer bitrate */ return error; - } @@ -1728,11 +1735,11 @@ void reset_preecho_dec_fx( { hHQ_core->memfilt_lb_fx = 0; move16(); - hHQ_core->mean_prev_hb_fx = L_deposit_l(0); + hHQ_core->mean_prev_hb_fx = L_deposit_l( 0 ); hHQ_core->smoothmem_fx = 32767; move16(); - hHQ_core->mean_prev_fx = L_deposit_l(0); - hHQ_core->mean_prev_nc_fx = L_deposit_l(0); + hHQ_core->mean_prev_fx = L_deposit_l( 0 ); + hHQ_core->mean_prev_nc_fx = L_deposit_l( 0 ); hHQ_core->wmold_hb_fx = 32767; move16(); hHQ_core->prevflag = 0; @@ -1750,23 +1757,23 @@ void reset_preecho_dec_fx( *----------------------------------------------------------------------*/ void destroy_cldfb_decoder_fx( - Decoder_State *st_fx /* o: Decoder static variables structure */ + Decoder_State *st_fx /* o: Decoder static variables structure */ ) { /* CLDFB BPF & resampling tools */ /* delete analysis for max. SR 16kHz */ - deleteCldfb(&st_fx->cldfbAna); + deleteCldfb( &st_fx->cldfbAna ); /* delete analysis BPF for max. SR 16kHz */ - deleteCldfb(&st_fx->cldfbBPF); + deleteCldfb( &st_fx->cldfbBPF ); /* delete synthesis for output SR */ - deleteCldfb(&st_fx->cldfbSyn); + deleteCldfb( &st_fx->cldfbSyn ); deleteFdCngDec_fx( &st_fx->hFdCngDec ); return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/inov_dec.c b/lib_dec/inov_dec.c index 83b66adf8..ad5df5d4a 100644 --- a/lib_dec/inov_dec.c +++ b/lib_dec/inov_dec.c @@ -192,4 +192,4 @@ void inov_decode( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/inov_dec_fx.c b/lib_dec/inov_dec_fx.c index 53aab75bc..cedf36a6e 100644 --- a/lib_dec/inov_dec_fx.c +++ b/lib_dec/inov_dec_fx.c @@ -3,11 +3,11 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "rom_com.h" /* Static table prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "rom_com.h" /* Static table prototypes */ #ifdef IVAS_FLOAT_FIXED /*======================================================================*/ /* FUNCTION : inov_decode_fx() */ @@ -41,23 +41,23 @@ /*=======================================================================*/ void inov_decode_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 sharpFlag, /* i : formant sharpening flag */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 *p_Aq, /* i : LP filter coefficients Q12 */ - const Word16 tilt_code, /* i : tilt of the excitation of previous subframe Q15 */ - const Word16 pt_pitch, /* i : pointer to current subframe fractional pitch Q6*/ - Word16 *code, /* o : algebraic excitation */ - const Word16 L_subfr /* i : subframe length */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const Word16 L_frame, /* i : length of the frame */ + const Word16 sharpFlag, /* i : formant sharpening flag */ + const Word16 i_subfr, /* i : subframe index */ + const Word16 *p_Aq, /* i : LP filter coefficients Q12 */ + const Word16 tilt_code, /* i : tilt of the excitation of previous subframe Q15 */ + const Word16 pt_pitch, /* i : pointer to current subframe fractional pitch Q6*/ + Word16 *code, /* o : algebraic excitation */ + const Word16 L_subfr /* i : subframe length */ ) { Word16 nBits; Word16 g1, g2; - IF( EQ_16(L_frame,L_FRAME)) + IF( EQ_16( L_frame, L_FRAME ) ) { g1 = FORMANT_SHARPENING_G1; g2 = FORMANT_SHARPENING_G2; @@ -68,74 +68,74 @@ void inov_decode_fx( g2 = FORMANT_SHARPENING_G2_16k; } - IF ( !Opt_AMR_WB ) + IF( !Opt_AMR_WB ) { - if (st_fx->acelp_cfg.fcb_mode) + if ( st_fx->acelp_cfg.fcb_mode ) { int16_t i; int16_t indexing_indices[8], wordcnt, bitcnt; PulseConfig config; - if (st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_subfr] >= 0) + if ( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_subfr] >= 0 ) { - if (L_subfr == 2 * L_SUBFR) + if ( L_subfr == 2 * L_SUBFR ) { nBits = st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_subfr]; - if (nBits == 8) + if ( nBits == 8 ) { - //dec_acelp_1t64(st_fx, code, L_subfr); - dec_acelp_1t64_fx(st_fx, code, L_subfr); + // dec_acelp_1t64(st_fx, code, L_subfr); + dec_acelp_1t64_fx( st_fx, code, L_subfr ); } else { - //dec_acelp_fast(st_fx, nBits, code, L_subfr); - dec_acelp_fast_fx(st_fx, nBits, code, L_subfr); + // dec_acelp_fast(st_fx, nBits, code, L_subfr); + dec_acelp_fast_fx( st_fx, nBits, code, L_subfr ); } } - else if ((st_fx->idchan == 1 && st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] <= 7) || (st_fx->idchan == 0 && st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] <= 3)) + else if ( ( st_fx->idchan == 1 && st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] <= 7 ) || ( st_fx->idchan == 0 && st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] <= 3 ) ) { - if (st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] == 0) + if ( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] == 0 ) { - //dec_acelp_1t64(st_fx, code, L_SUBFR); - dec_acelp_1t64_fx(st_fx, code, L_SUBFR); + // dec_acelp_1t64(st_fx, code, L_SUBFR); + dec_acelp_1t64_fx( st_fx, code, L_SUBFR ); } else { - //dec_acelp_fast(st_fx, st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR], code, L_SUBFR); - dec_acelp_fast_fx(st_fx, st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR], code, L_SUBFR); + // dec_acelp_fast(st_fx, st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR], code, L_SUBFR); + dec_acelp_fast_fx( st_fx, st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR], code, L_SUBFR ); } } else { - wordcnt = ACELP_FIXED_CDK_BITS(st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR]) >> 4; - bitcnt = ACELP_FIXED_CDK_BITS(st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR]) & 15; -//PMT("CONDITION above is missing -> idchan") - for (i = 0; i < wordcnt; i++) + wordcnt = ACELP_FIXED_CDK_BITS( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] ) >> 4; + bitcnt = ACELP_FIXED_CDK_BITS( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] ) & 15; + // PMT("CONDITION above is missing -> idchan") + for ( i = 0; i < wordcnt; i++ ) { - indexing_indices[i] = get_next_indice(st_fx, 16); + indexing_indices[i] = get_next_indice( st_fx, 16 ); } - if (bitcnt) + if ( bitcnt ) { - indexing_indices[i] = get_next_indice(st_fx, bitcnt); + indexing_indices[i] = get_next_indice( st_fx, bitcnt ); } config = PulseConfTable[st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR]]; - D_ACELP_indexing_fx(code, config, NB_TRACK_FCB_4T, indexing_indices, &st_fx->BER_detect); + D_ACELP_indexing_fx( code, config, NB_TRACK_FCB_4T, indexing_indices, &st_fx->BER_detect ); } } else { - set16_fx(code, 0, L_SUBFR); + set16_fx( code, 0, L_SUBFR ); } } else { nBits = st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR]; - IF(EQ_16(nBits,7)) + IF( EQ_16( nBits, 7 ) ) { - dec_acelp_1t64_fx(st_fx, code, L_SUBFR); + dec_acelp_1t64_fx( st_fx, code, L_SUBFR ); } - ELSE IF( EQ_16(nBits,12)) + ELSE IF( EQ_16( nBits, 12 ) ) { dec_acelp_2t32_fx( st_fx, code ); } @@ -147,31 +147,31 @@ void inov_decode_fx( } ELSE { - IF ( EQ_32(core_brate,ACELP_6k60)) + IF( EQ_32( core_brate, ACELP_6k60 ) ) { dec_acelp_2t32_fx( st_fx, code ); } - ELSE IF ( EQ_32(core_brate,ACELP_8k85)) + ELSE IF( EQ_32( core_brate, ACELP_8k85 ) ) { dec_acelp_4t64_fx( st_fx, 20, code, Opt_AMR_WB ); } - ELSE IF ( EQ_32(core_brate,ACELP_12k65)) + ELSE IF( EQ_32( core_brate, ACELP_12k65 ) ) { dec_acelp_4t64_fx( st_fx, 36, code, Opt_AMR_WB ); } - ELSE IF ( EQ_32(core_brate,ACELP_14k25)) + ELSE IF( EQ_32( core_brate, ACELP_14k25 ) ) { dec_acelp_4t64_fx( st_fx, 44, code, Opt_AMR_WB ); } - ELSE IF ( EQ_32(core_brate,ACELP_15k85)) + ELSE IF( EQ_32( core_brate, ACELP_15k85 ) ) { dec_acelp_4t64_fx( st_fx, 52, code, Opt_AMR_WB ); } - ELSE IF ( EQ_32(core_brate,ACELP_18k25)) + ELSE IF( EQ_32( core_brate, ACELP_18k25 ) ) { dec_acelp_4t64_fx( st_fx, 64, code, Opt_AMR_WB ); } - ELSE IF ( EQ_32(core_brate,ACELP_19k85)) + ELSE IF( EQ_32( core_brate, ACELP_19k85 ) ) { dec_acelp_4t64_fx( st_fx, 72, code, Opt_AMR_WB ); } @@ -181,9 +181,8 @@ void inov_decode_fx( } } - cb_shape_fx( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, code, tilt_code, shr(add(pt_pitch,26),6), 0, L_subfr); + cb_shape_fx( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, code, tilt_code, shr( add( pt_pitch, 26 ), 6 ), 0, L_subfr ); return; - } #ifdef IVAS_FLOAT_FIXED @@ -365,4 +364,4 @@ void inov_decode_ivas_fx( return; } #endif -#endif \ No newline at end of file +#endif diff --git a/lib_dec/ivas_binRenderer_internal.c b/lib_dec/ivas_binRenderer_internal.c index e7fd85edf..910469008 100644 --- a/lib_dec/ivas_binRenderer_internal.c +++ b/lib_dec/ivas_binRenderer_internal.c @@ -61,7 +61,7 @@ static void ivas_binRenderer_filterModule( float out_Conv_CLDFB_imag[BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : imag part of Binaural signals */ float CLDFB_real[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : real part of LS signals */ float CLDFB_imag[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : imag part of LS signals */ - const int16_t numTimeSlots, /* i : number of time slots to process */ + const int16_t numTimeSlots, /* i : number of time slots to process */ BINAURAL_RENDERER_HANDLE hBinRenderer /* i/o: fastconv binaural renderer handle */ ) { @@ -260,49 +260,60 @@ static ivas_error ivas_binRenderer_convModuleOpen( hBinRenderer->nInChannels = sub( audioCfg2channels( input_config ), isLoudspeaker ); } - IF(EQ_16( renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM )) + IF( EQ_16( renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) { - hBinRenConvModule->numTaps = BINAURAL_NTAPS_MAX; move16(); + hBinRenConvModule->numTaps = BINAURAL_NTAPS_MAX; + move16(); /* Use variable order filtering */ - bandIdx = 0; move16(); + bandIdx = 0; + move16(); FOR( ; bandIdx < 5; bandIdx++ ) { - hBinRenConvModule->numTapsArray[bandIdx] = hBinRenConvModule->numTaps; move16(); + hBinRenConvModule->numTapsArray[bandIdx] = hBinRenConvModule->numTaps; + move16(); } FOR( ; bandIdx < 10; bandIdx++ ) { - hBinRenConvModule->numTapsArray[bandIdx] = NUM_TAPS_F0_6; move16(); + hBinRenConvModule->numTapsArray[bandIdx] = NUM_TAPS_F0_6; + move16(); } FOR( ; bandIdx < 20; bandIdx++ ) { - hBinRenConvModule->numTapsArray[bandIdx] = NUM_TAPS_F0_5; move16(); + hBinRenConvModule->numTapsArray[bandIdx] = NUM_TAPS_F0_5; + move16(); } FOR( ; bandIdx < 30; bandIdx++ ) { - hBinRenConvModule->numTapsArray[bandIdx] = NUM_TAPS_F0_4; move16(); + hBinRenConvModule->numTapsArray[bandIdx] = NUM_TAPS_F0_4; + move16(); } FOR( ; bandIdx < hBinRenderer->conv_band; bandIdx++ ) { - hBinRenConvModule->numTapsArray[bandIdx] = NUM_TAPS_F0_3; move16(); + hBinRenConvModule->numTapsArray[bandIdx] = NUM_TAPS_F0_3; + move16(); } } ELSE { - IF( EQ_16(hBinRenderer->ivas_format, SBA_FORMAT )) + IF( EQ_16( hBinRenderer->ivas_format, SBA_FORMAT ) ) { - hBinRenConvModule->numTaps = BINAURAL_NTAPS_SBA; move16(); + hBinRenConvModule->numTaps = BINAURAL_NTAPS_SBA; + move16(); } ELSE { - hBinRenConvModule->numTaps = BINAURAL_NTAPS; move16(); + hBinRenConvModule->numTaps = BINAURAL_NTAPS; + move16(); } /* Use fixed order filtering */ - bandIdx = 0; move16(); + bandIdx = 0; + move16(); FOR( ; bandIdx < hBinRenderer->conv_band; bandIdx++ ) { - hBinRenConvModule->numTapsArray[bandIdx] = hBinRenConvModule->numTaps; move16(); + hBinRenConvModule->numTapsArray[bandIdx] = hBinRenConvModule->numTaps; + move16(); } } @@ -406,33 +417,39 @@ static ivas_error ivas_binRenderer_convModuleOpen( { FOR( chIdx = 0; chIdx < hBinRenderer->nInChannels; chIdx++ ) { - Word16 tmp = 0; move16(); + Word16 tmp = 0; + move16(); IF( isLoudspeaker ) { - IF( EQ_16(input_config, IVAS_AUDIO_CONFIG_5_1 )) + IF( EQ_16( input_config, IVAS_AUDIO_CONFIG_5_1 ) ) { - tmp = channelIndex_CICP6[chIdx]; move16(); + tmp = channelIndex_CICP6[chIdx]; + move16(); } - ELSE IF( EQ_16(input_config, IVAS_AUDIO_CONFIG_7_1 )) + ELSE IF( EQ_16( input_config, IVAS_AUDIO_CONFIG_7_1 ) ) { - tmp = channelIndex_CICP12[chIdx]; move16(); + tmp = channelIndex_CICP12[chIdx]; + move16(); } - ELSE IF( EQ_16(input_config, IVAS_AUDIO_CONFIG_5_1_2 )) + ELSE IF( EQ_16( input_config, IVAS_AUDIO_CONFIG_5_1_2 ) ) { - tmp = channelIndex_CICP14[chIdx]; move16(); + tmp = channelIndex_CICP14[chIdx]; + move16(); } - ELSE IF( EQ_16(input_config, IVAS_AUDIO_CONFIG_5_1_4 )) + ELSE IF( EQ_16( input_config, IVAS_AUDIO_CONFIG_5_1_4 ) ) { - tmp = channelIndex_CICP16[chIdx]; move16(); + tmp = channelIndex_CICP16[chIdx]; + move16(); } - ELSE IF( EQ_16(input_config, IVAS_AUDIO_CONFIG_7_1_4 )) + ELSE IF( EQ_16( input_config, IVAS_AUDIO_CONFIG_7_1_4 ) ) { - tmp = channelIndex_CICP19[chIdx]; move16(); + tmp = channelIndex_CICP19[chIdx]; + move16(); } } - IF( EQ_16(renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM )) + IF( EQ_16( renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) { /* set the memories to zero */ set32_fx( hBinRenConvModule->filterStatesLeftReal_fx[bandIdx][chIdx], 0, hBinRenConvModule->numTapsArray[bandIdx] ); @@ -461,7 +478,7 @@ static ivas_error ivas_binRenderer_convModuleOpen( } ELSE { - IF( EQ_16(input_config, IVAS_AUDIO_CONFIG_HOA3 )) + IF( EQ_16( input_config, IVAS_AUDIO_CONFIG_HOA3 ) ) { /* HOA3 filter coefficients */ hBinRenConvModule->filterTapsLeftReal_fx[bandIdx][chIdx] = hHrtf->leftHRIRReal_HOA3_fx[bandIdx][chIdx]; @@ -469,7 +486,7 @@ static ivas_error ivas_binRenderer_convModuleOpen( hBinRenConvModule->filterTapsRightReal_fx[bandIdx][chIdx] = hHrtf->rightHRIRReal_HOA3_fx[bandIdx][chIdx]; hBinRenConvModule->filterTapsRightImag_fx[bandIdx][chIdx] = hHrtf->rightHRIRImag_HOA3_fx[bandIdx][chIdx]; } - ELSE IF( EQ_16(input_config, IVAS_AUDIO_CONFIG_HOA2 )) + ELSE IF( EQ_16( input_config, IVAS_AUDIO_CONFIG_HOA2 ) ) { /* HOA2 filter coefficients */ hBinRenConvModule->filterTapsLeftReal_fx[bandIdx][chIdx] = hHrtf->leftHRIRReal_HOA2_fx[bandIdx][chIdx]; @@ -477,7 +494,7 @@ static ivas_error ivas_binRenderer_convModuleOpen( hBinRenConvModule->filterTapsRightReal_fx[bandIdx][chIdx] = hHrtf->rightHRIRReal_HOA2_fx[bandIdx][chIdx]; hBinRenConvModule->filterTapsRightImag_fx[bandIdx][chIdx] = hHrtf->rightHRIRImag_HOA2_fx[bandIdx][chIdx]; } - ELSE IF( EQ_16(input_config, IVAS_AUDIO_CONFIG_FOA )) + ELSE IF( EQ_16( input_config, IVAS_AUDIO_CONFIG_FOA ) ) { /* FOA filter coefficients */ hBinRenConvModule->filterTapsLeftReal_fx[bandIdx][chIdx] = hHrtf->leftHRIRReal_FOA_fx[bandIdx][chIdx]; @@ -502,257 +519,256 @@ static ivas_error ivas_binRenderer_convModuleOpen( #else static ivas_error ivas_binRenderer_convModuleOpen( - BINAURAL_RENDERER_HANDLE hBinRenderer, - const int16_t renderer_type, - const int16_t isLoudspeaker, - const AUDIO_CONFIG input_config, - const HRTFS_FASTCONV_HANDLE hHrtf -) + BINAURAL_RENDERER_HANDLE hBinRenderer, + const int16_t renderer_type, + const int16_t isLoudspeaker, + const AUDIO_CONFIG input_config, + const HRTFS_FASTCONV_HANDLE hHrtf ) { - int16_t bandIdx, chIdx; - BINRENDERER_CONV_MODULE_HANDLE hBinRenConvModule; - - /*-----------------------------------------------------------------* - * prepare library opening - *-----------------------------------------------------------------*/ - - if ((hBinRenConvModule = (BINRENDERER_CONV_MODULE_HANDLE)malloc(sizeof(BINRENDERER_CONV_MODULE))) == NULL) - { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n")); - } - - if (!isLoudspeaker) - { - hBinRenderer->nInChannels = audioCfg2channels(input_config); - } - else - { - /* Note: needs to be revisited if multiple LFE support is required */ - hBinRenderer->nInChannels = (audioCfg2channels(input_config) - isLoudspeaker); - } + int16_t bandIdx, chIdx; + BINRENDERER_CONV_MODULE_HANDLE hBinRenConvModule; - if (renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM) - { - hBinRenConvModule->numTaps = BINAURAL_NTAPS_MAX; + /*-----------------------------------------------------------------* + * prepare library opening + *-----------------------------------------------------------------*/ - /* Use variable order filtering */ - bandIdx = 0; - for (; bandIdx < 5; bandIdx++) - { - hBinRenConvModule->numTapsArray[bandIdx] = hBinRenConvModule->numTaps; - } - for (; bandIdx < 10; bandIdx++) - { - hBinRenConvModule->numTapsArray[bandIdx] = (int16_t)ceilf(0.6f * hBinRenConvModule->numTaps); - } - for (; bandIdx < 20; bandIdx++) + if ( ( hBinRenConvModule = (BINRENDERER_CONV_MODULE_HANDLE) malloc( sizeof( BINRENDERER_CONV_MODULE ) ) ) == NULL ) { - hBinRenConvModule->numTapsArray[bandIdx] = (int16_t)ceilf(0.5f * hBinRenConvModule->numTaps); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } - for (; bandIdx < 30; bandIdx++) + + if ( !isLoudspeaker ) { - hBinRenConvModule->numTapsArray[bandIdx] = (int16_t)ceilf(0.4f * hBinRenConvModule->numTaps); + hBinRenderer->nInChannels = audioCfg2channels( input_config ); } - for (; bandIdx < hBinRenderer->conv_band; bandIdx++) + else { - hBinRenConvModule->numTapsArray[bandIdx] = (int16_t)ceilf(0.3f * hBinRenConvModule->numTaps); + /* Note: needs to be revisited if multiple LFE support is required */ + hBinRenderer->nInChannels = ( audioCfg2channels( input_config ) - isLoudspeaker ); } - } - else - { - if (hBinRenderer->ivas_format == SBA_FORMAT) + + if ( renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) { - hBinRenConvModule->numTaps = BINAURAL_NTAPS_SBA; + hBinRenConvModule->numTaps = BINAURAL_NTAPS_MAX; + + /* Use variable order filtering */ + bandIdx = 0; + for ( ; bandIdx < 5; bandIdx++ ) + { + hBinRenConvModule->numTapsArray[bandIdx] = hBinRenConvModule->numTaps; + } + for ( ; bandIdx < 10; bandIdx++ ) + { + hBinRenConvModule->numTapsArray[bandIdx] = (int16_t) ceilf( 0.6f * hBinRenConvModule->numTaps ); + } + for ( ; bandIdx < 20; bandIdx++ ) + { + hBinRenConvModule->numTapsArray[bandIdx] = (int16_t) ceilf( 0.5f * hBinRenConvModule->numTaps ); + } + for ( ; bandIdx < 30; bandIdx++ ) + { + hBinRenConvModule->numTapsArray[bandIdx] = (int16_t) ceilf( 0.4f * hBinRenConvModule->numTaps ); + } + for ( ; bandIdx < hBinRenderer->conv_band; bandIdx++ ) + { + hBinRenConvModule->numTapsArray[bandIdx] = (int16_t) ceilf( 0.3f * hBinRenConvModule->numTaps ); + } } else { - hBinRenConvModule->numTaps = BINAURAL_NTAPS; - } + if ( hBinRenderer->ivas_format == SBA_FORMAT ) + { + hBinRenConvModule->numTaps = BINAURAL_NTAPS_SBA; + } + else + { + hBinRenConvModule->numTaps = BINAURAL_NTAPS; + } - /* Use fixed order filtering */ - bandIdx = 0; - for (; bandIdx < hBinRenderer->conv_band; bandIdx++) - { - hBinRenConvModule->numTapsArray[bandIdx] = hBinRenConvModule->numTaps; + /* Use fixed order filtering */ + bandIdx = 0; + for ( ; bandIdx < hBinRenderer->conv_band; bandIdx++ ) + { + hBinRenConvModule->numTapsArray[bandIdx] = hBinRenConvModule->numTaps; + } } - } - - /* allocate memory for filter states */ - if ((hBinRenConvModule->filterTapsLeftReal = (float ***)malloc(hBinRenderer->conv_band * sizeof(float **))) == NULL) - { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n")); - } - - if ((hBinRenConvModule->filterTapsLeftImag = (float ***)malloc(hBinRenderer->conv_band * sizeof(float **))) == NULL) - { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n")); - } - - if ((hBinRenConvModule->filterTapsRightReal = (float ***)malloc(hBinRenderer->conv_band * sizeof(float **))) == NULL) - { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n")); - } - - if ((hBinRenConvModule->filterTapsRightImag = (float ***)malloc(hBinRenderer->conv_band * sizeof(float **))) == NULL) - { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n")); - } - for (bandIdx = 0; bandIdx < hBinRenderer->conv_band; bandIdx++) - { - if ((hBinRenConvModule->filterTapsLeftReal[bandIdx] = (float **)malloc(hBinRenderer->nInChannels * sizeof(float *))) == NULL) + /* allocate memory for filter states */ + if ( ( hBinRenConvModule->filterTapsLeftReal = (float ***) malloc( hBinRenderer->conv_band * sizeof( float ** ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } - if ((hBinRenConvModule->filterTapsLeftImag[bandIdx] = (float **)malloc(hBinRenderer->nInChannels * sizeof(float *))) == NULL) + if ( ( hBinRenConvModule->filterTapsLeftImag = (float ***) malloc( hBinRenderer->conv_band * sizeof( float ** ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } - if ((hBinRenConvModule->filterTapsRightReal[bandIdx] = (float **)malloc(hBinRenderer->nInChannels * sizeof(float *))) == NULL) + if ( ( hBinRenConvModule->filterTapsRightReal = (float ***) malloc( hBinRenderer->conv_band * sizeof( float ** ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } - if ((hBinRenConvModule->filterTapsRightImag[bandIdx] = (float **)malloc(hBinRenderer->nInChannels * sizeof(float *))) == NULL) + if ( ( hBinRenConvModule->filterTapsRightImag = (float ***) malloc( hBinRenderer->conv_band * sizeof( float ** ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } - } + for ( bandIdx = 0; bandIdx < hBinRenderer->conv_band; bandIdx++ ) + { + if ( ( hBinRenConvModule->filterTapsLeftReal[bandIdx] = (float **) malloc( hBinRenderer->nInChannels * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); + } - if ((hBinRenConvModule->filterStatesLeftReal = (float ***)malloc(hBinRenderer->conv_band * sizeof(float **))) == NULL) - { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n")); - } + if ( ( hBinRenConvModule->filterTapsLeftImag[bandIdx] = (float **) malloc( hBinRenderer->nInChannels * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); + } - if ((hBinRenConvModule->filterStatesLeftImag = (float ***)malloc(hBinRenderer->conv_band * sizeof(float **))) == NULL) - { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n")); - } + if ( ( hBinRenConvModule->filterTapsRightReal[bandIdx] = (float **) malloc( hBinRenderer->nInChannels * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); + } - for (bandIdx = 0; bandIdx < hBinRenderer->conv_band; bandIdx++) - { - if ((hBinRenConvModule->filterStatesLeftReal[bandIdx] = (float **)malloc(hBinRenderer->nInChannels * sizeof(float *))) == NULL) - { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n")); + if ( ( hBinRenConvModule->filterTapsRightImag[bandIdx] = (float **) malloc( hBinRenderer->nInChannels * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); + } } - if ((hBinRenConvModule->filterStatesLeftImag[bandIdx] = (float **)malloc(hBinRenderer->nInChannels * sizeof(float *))) == NULL) + + if ( ( hBinRenConvModule->filterStatesLeftReal = (float ***) malloc( hBinRenderer->conv_band * sizeof( float ** ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } - for (chIdx = 0; chIdx < hBinRenderer->nInChannels; chIdx++) + if ( ( hBinRenConvModule->filterStatesLeftImag = (float ***) malloc( hBinRenderer->conv_band * sizeof( float ** ) ) ) == NULL ) { - if ((hBinRenConvModule->filterStatesLeftReal[bandIdx][chIdx] = (float *)malloc(hBinRenConvModule->numTapsArray[bandIdx] * sizeof(float))) == NULL) - { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n")); - } - - if ((hBinRenConvModule->filterStatesLeftImag[bandIdx][chIdx] = (float *)malloc(hBinRenConvModule->numTapsArray[bandIdx] * sizeof(float))) == NULL) - { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n")); - } + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } - } - /* set memories */ - for (bandIdx = 0; bandIdx < hBinRenderer->conv_band; bandIdx++) - { - for (chIdx = 0; chIdx < hBinRenderer->nInChannels; chIdx++) + for ( bandIdx = 0; bandIdx < hBinRenderer->conv_band; bandIdx++ ) { - int16_t tmp = 0; - - if (isLoudspeaker) - { - if (input_config == IVAS_AUDIO_CONFIG_5_1) - { - tmp = channelIndex_CICP6[chIdx]; - } - else if (input_config == IVAS_AUDIO_CONFIG_7_1) - { - tmp = channelIndex_CICP12[chIdx]; - } - else if (input_config == IVAS_AUDIO_CONFIG_5_1_2) + if ( ( hBinRenConvModule->filterStatesLeftReal[bandIdx] = (float **) malloc( hBinRenderer->nInChannels * sizeof( float * ) ) ) == NULL ) { - tmp = channelIndex_CICP14[chIdx]; - } - else if (input_config == IVAS_AUDIO_CONFIG_5_1_4) - { - tmp = channelIndex_CICP16[chIdx]; + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } - else if (input_config == IVAS_AUDIO_CONFIG_7_1_4) + + if ( ( hBinRenConvModule->filterStatesLeftImag[bandIdx] = (float **) malloc( hBinRenderer->nInChannels * sizeof( float * ) ) ) == NULL ) { - tmp = channelIndex_CICP19[chIdx]; + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } - } - if (renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM) - { - /* set the memories to zero */ - set_zero(hBinRenConvModule->filterStatesLeftReal[bandIdx][chIdx], hBinRenConvModule->numTapsArray[bandIdx]); - set_zero(hBinRenConvModule->filterStatesLeftImag[bandIdx][chIdx], hBinRenConvModule->numTapsArray[bandIdx]); - if (isLoudspeaker) + for ( chIdx = 0; chIdx < hBinRenderer->nInChannels; chIdx++ ) { - hBinRenConvModule->filterTapsLeftReal[bandIdx][chIdx] = hHrtf->leftBRIRReal[bandIdx][tmp]; - hBinRenConvModule->filterTapsLeftImag[bandIdx][chIdx] = hHrtf->leftBRIRImag[bandIdx][tmp]; - hBinRenConvModule->filterTapsRightReal[bandIdx][chIdx] = hHrtf->rightBRIRReal[bandIdx][tmp]; - hBinRenConvModule->filterTapsRightImag[bandIdx][chIdx] = hHrtf->rightBRIRImag[bandIdx][tmp]; + if ( ( hBinRenConvModule->filterStatesLeftReal[bandIdx][chIdx] = (float *) malloc( hBinRenConvModule->numTapsArray[bandIdx] * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); + } + + if ( ( hBinRenConvModule->filterStatesLeftImag[bandIdx][chIdx] = (float *) malloc( hBinRenConvModule->numTapsArray[bandIdx] * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); + } } - } - else - { - /* set the memories to zero */ - set_zero(hBinRenConvModule->filterStatesLeftReal[bandIdx][chIdx], hBinRenConvModule->numTaps); - set_zero(hBinRenConvModule->filterStatesLeftImag[bandIdx][chIdx], hBinRenConvModule->numTaps); - if (isLoudspeaker) + } + + /* set memories */ + for ( bandIdx = 0; bandIdx < hBinRenderer->conv_band; bandIdx++ ) + { + for ( chIdx = 0; chIdx < hBinRenderer->nInChannels; chIdx++ ) { - hBinRenConvModule->filterTapsLeftReal[bandIdx][chIdx] = hHrtf->leftHRIRReal[bandIdx][tmp]; - hBinRenConvModule->filterTapsLeftImag[bandIdx][chIdx] = hHrtf->leftHRIRImag[bandIdx][tmp]; - hBinRenConvModule->filterTapsRightReal[bandIdx][chIdx] = hHrtf->rightHRIRReal[bandIdx][tmp]; - hBinRenConvModule->filterTapsRightImag[bandIdx][chIdx] = hHrtf->rightHRIRImag[bandIdx][tmp]; + int16_t tmp = 0; + + if ( isLoudspeaker ) + { + if ( input_config == IVAS_AUDIO_CONFIG_5_1 ) + { + tmp = channelIndex_CICP6[chIdx]; + } + else if ( input_config == IVAS_AUDIO_CONFIG_7_1 ) + { + tmp = channelIndex_CICP12[chIdx]; + } + else if ( input_config == IVAS_AUDIO_CONFIG_5_1_2 ) + { + tmp = channelIndex_CICP14[chIdx]; + } + else if ( input_config == IVAS_AUDIO_CONFIG_5_1_4 ) + { + tmp = channelIndex_CICP16[chIdx]; + } + else if ( input_config == IVAS_AUDIO_CONFIG_7_1_4 ) + { + tmp = channelIndex_CICP19[chIdx]; + } + } + + if ( renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) + { + /* set the memories to zero */ + set_zero( hBinRenConvModule->filterStatesLeftReal[bandIdx][chIdx], hBinRenConvModule->numTapsArray[bandIdx] ); + set_zero( hBinRenConvModule->filterStatesLeftImag[bandIdx][chIdx], hBinRenConvModule->numTapsArray[bandIdx] ); + if ( isLoudspeaker ) + { + hBinRenConvModule->filterTapsLeftReal[bandIdx][chIdx] = hHrtf->leftBRIRReal[bandIdx][tmp]; + hBinRenConvModule->filterTapsLeftImag[bandIdx][chIdx] = hHrtf->leftBRIRImag[bandIdx][tmp]; + hBinRenConvModule->filterTapsRightReal[bandIdx][chIdx] = hHrtf->rightBRIRReal[bandIdx][tmp]; + hBinRenConvModule->filterTapsRightImag[bandIdx][chIdx] = hHrtf->rightBRIRImag[bandIdx][tmp]; + } + } + else + { + /* set the memories to zero */ + set_zero( hBinRenConvModule->filterStatesLeftReal[bandIdx][chIdx], hBinRenConvModule->numTaps ); + set_zero( hBinRenConvModule->filterStatesLeftImag[bandIdx][chIdx], hBinRenConvModule->numTaps ); + if ( isLoudspeaker ) + { + hBinRenConvModule->filterTapsLeftReal[bandIdx][chIdx] = hHrtf->leftHRIRReal[bandIdx][tmp]; + hBinRenConvModule->filterTapsLeftImag[bandIdx][chIdx] = hHrtf->leftHRIRImag[bandIdx][tmp]; + hBinRenConvModule->filterTapsRightReal[bandIdx][chIdx] = hHrtf->rightHRIRReal[bandIdx][tmp]; + hBinRenConvModule->filterTapsRightImag[bandIdx][chIdx] = hHrtf->rightHRIRImag[bandIdx][tmp]; + } + else + { + if ( input_config == IVAS_AUDIO_CONFIG_HOA3 ) + { + /* HOA3 filter coefficients */ + hBinRenConvModule->filterTapsLeftReal[bandIdx][chIdx] = hHrtf->leftHRIRReal_HOA3[bandIdx][chIdx]; + hBinRenConvModule->filterTapsLeftImag[bandIdx][chIdx] = hHrtf->leftHRIRImag_HOA3[bandIdx][chIdx]; + hBinRenConvModule->filterTapsRightReal[bandIdx][chIdx] = hHrtf->rightHRIRReal_HOA3[bandIdx][chIdx]; + hBinRenConvModule->filterTapsRightImag[bandIdx][chIdx] = hHrtf->rightHRIRImag_HOA3[bandIdx][chIdx]; + } + else if ( input_config == IVAS_AUDIO_CONFIG_HOA2 ) + { + /* HOA2 filter coefficients */ + hBinRenConvModule->filterTapsLeftReal[bandIdx][chIdx] = hHrtf->leftHRIRReal_HOA2[bandIdx][chIdx]; + hBinRenConvModule->filterTapsLeftImag[bandIdx][chIdx] = hHrtf->leftHRIRImag_HOA2[bandIdx][chIdx]; + hBinRenConvModule->filterTapsRightReal[bandIdx][chIdx] = hHrtf->rightHRIRReal_HOA2[bandIdx][chIdx]; + hBinRenConvModule->filterTapsRightImag[bandIdx][chIdx] = hHrtf->rightHRIRImag_HOA2[bandIdx][chIdx]; + } + else if ( input_config == IVAS_AUDIO_CONFIG_FOA ) + { + /* FOA filter coefficients */ + hBinRenConvModule->filterTapsLeftReal[bandIdx][chIdx] = hHrtf->leftHRIRReal_FOA[bandIdx][chIdx]; + hBinRenConvModule->filterTapsLeftImag[bandIdx][chIdx] = hHrtf->leftHRIRImag_FOA[bandIdx][chIdx]; + hBinRenConvModule->filterTapsRightReal[bandIdx][chIdx] = hHrtf->rightHRIRReal_FOA[bandIdx][chIdx]; + hBinRenConvModule->filterTapsRightImag[bandIdx][chIdx] = hHrtf->rightHRIRImag_FOA[bandIdx][chIdx]; + } + else + { + return IVAS_ERR_INVALID_INPUT_FORMAT; + } + } + } } - else - { - if (input_config == IVAS_AUDIO_CONFIG_HOA3) - { - /* HOA3 filter coefficients */ - hBinRenConvModule->filterTapsLeftReal[bandIdx][chIdx] = hHrtf->leftHRIRReal_HOA3[bandIdx][chIdx]; - hBinRenConvModule->filterTapsLeftImag[bandIdx][chIdx] = hHrtf->leftHRIRImag_HOA3[bandIdx][chIdx]; - hBinRenConvModule->filterTapsRightReal[bandIdx][chIdx] = hHrtf->rightHRIRReal_HOA3[bandIdx][chIdx]; - hBinRenConvModule->filterTapsRightImag[bandIdx][chIdx] = hHrtf->rightHRIRImag_HOA3[bandIdx][chIdx]; - } - else if (input_config == IVAS_AUDIO_CONFIG_HOA2) - { - /* HOA2 filter coefficients */ - hBinRenConvModule->filterTapsLeftReal[bandIdx][chIdx] = hHrtf->leftHRIRReal_HOA2[bandIdx][chIdx]; - hBinRenConvModule->filterTapsLeftImag[bandIdx][chIdx] = hHrtf->leftHRIRImag_HOA2[bandIdx][chIdx]; - hBinRenConvModule->filterTapsRightReal[bandIdx][chIdx] = hHrtf->rightHRIRReal_HOA2[bandIdx][chIdx]; - hBinRenConvModule->filterTapsRightImag[bandIdx][chIdx] = hHrtf->rightHRIRImag_HOA2[bandIdx][chIdx]; - } - else if (input_config == IVAS_AUDIO_CONFIG_FOA) - { - /* FOA filter coefficients */ - hBinRenConvModule->filterTapsLeftReal[bandIdx][chIdx] = hHrtf->leftHRIRReal_FOA[bandIdx][chIdx]; - hBinRenConvModule->filterTapsLeftImag[bandIdx][chIdx] = hHrtf->leftHRIRImag_FOA[bandIdx][chIdx]; - hBinRenConvModule->filterTapsRightReal[bandIdx][chIdx] = hHrtf->rightHRIRReal_FOA[bandIdx][chIdx]; - hBinRenConvModule->filterTapsRightImag[bandIdx][chIdx] = hHrtf->rightHRIRImag_FOA[bandIdx][chIdx]; - } - else - { - return IVAS_ERR_INVALID_INPUT_FORMAT; - } - } - } - } - } - - - hBinRenderer->hBinRenConvModule = hBinRenConvModule; - - return IVAS_ERR_OK; + } + + + hBinRenderer->hBinRenConvModule = hBinRenConvModule; + + return IVAS_ERR_OK; } #endif @@ -873,32 +889,30 @@ static ivas_error ivas_alloc_pppMem_fx( Word16 i, j; Word32 ***localMem = NULL; - IF( ( localMem = (Word32 ***) malloc( dim1 * sizeof(Word32 ** ) ) ) == NULL ) + IF( ( localMem = (Word32 ***) malloc( dim1 * sizeof( Word32 ** ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HRTF memory" ); } - FOR( i = 0; i < dim1; i++ ) + FOR( i = 0; i < dim1; i++ ){ + IF( ( localMem[i] = (Word32 **) malloc( dim2 * sizeof( Word32 * ) ) ) == NULL ){ + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HRTF memory" ); +} +IF( allocate_init_flag == 0 ) +{ + FOR( j = 0; j < dim2; j++ ) { - IF( ( localMem[i] = (Word32 **) malloc( dim2 * sizeof(Word32 * ) ) ) == NULL ) + IF( ( localMem[i][j] = (Word32 *) malloc( dim3 * sizeof( Word32 ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HRTF memory" ); } - IF( allocate_init_flag == 0 ) - { - FOR( j = 0; j < dim2; j++ ) - { - IF( ( localMem[i][j] = (Word32 *) malloc( dim3 * sizeof(Word32) ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HRTF memory" ); - } - } - } } +} +} - *pppMem = localMem; +*pppMem = localMem; - return IVAS_ERR_OK; +return IVAS_ERR_OK; } #else static ivas_error ivas_alloc_pppMem( @@ -962,21 +976,21 @@ ivas_error ivas_allocate_binaural_hrtf_fx( } ELSE { - IF(IVAS_ERR_OK != ivas_alloc_pppMem_fx(&HrtfFastConv->leftHRIRReal_HOA3_fx, BINAURAL_CONVBANDS, HOA3_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag)) + IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->leftHRIRReal_HOA3_fx, BINAURAL_CONVBANDS, HOA3_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftHRIRReal_HOA3"); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftHRIRReal_HOA3" ); } - IF(IVAS_ERR_OK != ivas_alloc_pppMem_fx(&HrtfFastConv->leftHRIRImag_HOA3_fx, BINAURAL_CONVBANDS, HOA3_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag)) + IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->leftHRIRImag_HOA3_fx, BINAURAL_CONVBANDS, HOA3_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftHRIRImag_HOA3"); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftHRIRImag_HOA3" ); } - IF(IVAS_ERR_OK != ivas_alloc_pppMem_fx(&HrtfFastConv->rightHRIRReal_HOA3_fx, BINAURAL_CONVBANDS, HOA3_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag)) + IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->rightHRIRReal_HOA3_fx, BINAURAL_CONVBANDS, HOA3_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightHRIRReal_HOA3"); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightHRIRReal_HOA3" ); } - IF(IVAS_ERR_OK != ivas_alloc_pppMem_fx(&HrtfFastConv->rightHRIRImag_HOA3_fx, BINAURAL_CONVBANDS, HOA3_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag)) + IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->rightHRIRImag_HOA3_fx, BINAURAL_CONVBANDS, HOA3_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightHRIRImag_HOA3"); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightHRIRImag_HOA3" ); } } } @@ -989,21 +1003,21 @@ ivas_error ivas_allocate_binaural_hrtf_fx( } ELSE { - IF(IVAS_ERR_OK != ivas_alloc_pppMem_fx(&HrtfFastConv->leftHRIRReal_HOA2_fx, BINAURAL_CONVBANDS, HOA2_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag)) + IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->leftHRIRReal_HOA2_fx, BINAURAL_CONVBANDS, HOA2_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftHRIRReal_HOA2"); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftHRIRReal_HOA2" ); } - IF(IVAS_ERR_OK != ivas_alloc_pppMem_fx(&HrtfFastConv->leftHRIRImag_HOA2_fx, BINAURAL_CONVBANDS, HOA2_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag)) + IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->leftHRIRImag_HOA2_fx, BINAURAL_CONVBANDS, HOA2_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftHRIRImag_HOA2"); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftHRIRImag_HOA2" ); } - IF(IVAS_ERR_OK != ivas_alloc_pppMem_fx(&HrtfFastConv->rightHRIRReal_HOA2_fx, BINAURAL_CONVBANDS, HOA2_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag)) + IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->rightHRIRReal_HOA2_fx, BINAURAL_CONVBANDS, HOA2_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightHRIRReal_HOA2"); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightHRIRReal_HOA2" ); } - IF(IVAS_ERR_OK != ivas_alloc_pppMem_fx(&HrtfFastConv->rightHRIRImag_HOA2_fx, BINAURAL_CONVBANDS, HOA2_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag)) + IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->rightHRIRImag_HOA2_fx, BINAURAL_CONVBANDS, HOA2_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightHRIRImag_HOA2"); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightHRIRImag_HOA2" ); } } } @@ -1043,21 +1057,21 @@ ivas_error ivas_allocate_binaural_hrtf_fx( } ELSE { - IF(IVAS_ERR_OK != ivas_alloc_pppMem_fx(&HrtfFastConv->leftHRIRReal_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS, allocate_init_flag)) + IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->leftHRIRReal_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS, allocate_init_flag ) ) { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftHRIRReal"); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftHRIRReal" ); } - IF(IVAS_ERR_OK != ivas_alloc_pppMem_fx(&HrtfFastConv->leftHRIRImag_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS, allocate_init_flag)) + IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->leftHRIRImag_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS, allocate_init_flag ) ) { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftHRIRImag"); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftHRIRImag" ); } - IF(IVAS_ERR_OK != ivas_alloc_pppMem_fx(&HrtfFastConv->rightHRIRReal_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS, allocate_init_flag)) + IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->rightHRIRReal_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS, allocate_init_flag ) ) { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightHRIRReal"); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightHRIRReal" ); } - IF(IVAS_ERR_OK != ivas_alloc_pppMem_fx(&HrtfFastConv->rightHRIRImag_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS, allocate_init_flag)) + IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->rightHRIRImag_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS, allocate_init_flag ) ) { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightHRIRImag"); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightHRIRImag" ); } } } @@ -1070,21 +1084,21 @@ ivas_error ivas_allocate_binaural_hrtf_fx( } ELSE { - IF(IVAS_ERR_OK != ivas_alloc_pppMem_fx(&HrtfFastConv->leftBRIRReal_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS_MAX, allocate_init_flag)) + IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->leftBRIRReal_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS_MAX, allocate_init_flag ) ) { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftBRIRReal"); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftBRIRReal" ); } - IF(IVAS_ERR_OK != ivas_alloc_pppMem_fx(&HrtfFastConv->leftBRIRImag_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS_MAX, allocate_init_flag)) + IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->leftBRIRImag_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS_MAX, allocate_init_flag ) ) { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftBRIRImag"); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftBRIRImag" ); } - IF(IVAS_ERR_OK != ivas_alloc_pppMem_fx(&HrtfFastConv->rightBRIRReal_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS_MAX, allocate_init_flag)) + IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->rightBRIRReal_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS_MAX, allocate_init_flag ) ) { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightBRIRReal"); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightBRIRReal" ); } - IF(IVAS_ERR_OK != ivas_alloc_pppMem_fx(&HrtfFastConv->rightBRIRImag_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS_MAX, allocate_init_flag)) + IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->rightBRIRImag_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS_MAX, allocate_init_flag ) ) { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightBRIRImag"); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightBRIRImag" ); } } } @@ -1352,8 +1366,8 @@ static ivas_error ivas_binaural_hrtf_open_fx( } } } - mvl2l(fastconvReverberationTimes_fx, HrtfFastConv->fastconvReverberationTimes_fx, CLDFB_NO_CHANNELS_MAX); - mvl2l(fastconvReverberationEneCorrections_fx, HrtfFastConv->fastconvReverberationEneCorrections_fx, CLDFB_NO_CHANNELS_MAX); + mvl2l( fastconvReverberationTimes_fx, HrtfFastConv->fastconvReverberationTimes_fx, CLDFB_NO_CHANNELS_MAX ); + mvl2l( fastconvReverberationEneCorrections_fx, HrtfFastConv->fastconvReverberationEneCorrections_fx, CLDFB_NO_CHANNELS_MAX ); *hHrtfFastConv = HrtfFastConv; } @@ -1643,16 +1657,16 @@ static void ivas_binaural_obtain_DMX_fx( { FOR( k = 0; k < numTimeSlots; k++ ) { - //temp1 = RealBuffer[chIdx][k][bandIdx] * dmxConst; - //temp2 = ImagBuffer[chIdx][k][bandIdx] * dmxConst; - //realDMX[chOutIdx][k][bandIdx] += temp1; - //imagDMX[chOutIdx][k][bandIdx] += temp2; - temp1_fx = Mpy_32_32(RealBuffer[chIdx][k][bandIdx], dmxConst); // Q_in - temp2_fx = Mpy_32_32( ImagBuffer[chIdx][k][bandIdx], dmxConst ); // Q_in + // temp1 = RealBuffer[chIdx][k][bandIdx] * dmxConst; + // temp2 = ImagBuffer[chIdx][k][bandIdx] * dmxConst; + // realDMX[chOutIdx][k][bandIdx] += temp1; + // imagDMX[chOutIdx][k][bandIdx] += temp2; + temp1_fx = Mpy_32_32( RealBuffer[chIdx][k][bandIdx], dmxConst ); // Q_in + temp2_fx = Mpy_32_32( ImagBuffer[chIdx][k][bandIdx], dmxConst ); // Q_in realDMX[chOutIdx][k][bandIdx] = L_add( realDMX[chOutIdx][k][bandIdx], temp1_fx ); // Q_in imagDMX[chOutIdx][k][bandIdx] = L_add( imagDMX[chOutIdx][k][bandIdx], temp2_fx ); // Q_in - //P_in[bandIdx] += temp1 * temp1 + temp2 * temp2; + // P_in[bandIdx] += temp1 * temp1 + temp2 * temp2; P_in_fx[bandIdx] = L_add( P_in_fx[bandIdx], L_add( Mpy_32_32( temp1_fx, temp1_fx ), Mpy_32_32( temp2_fx, temp2_fx ) ) ); // Q31-2*Q_in } } @@ -1665,13 +1679,13 @@ static void ivas_binaural_obtain_DMX_fx( { temp1_fx = realDMX[chOutIdx][k][bandIdx]; temp2_fx = imagDMX[chOutIdx][k][bandIdx]; - //P_out += temp1 * temp1 + temp2 * temp2; - P_out_fx = L_add( P_out_fx, L_add( Mpy_32_32( temp1_fx, temp1_fx ), Mpy_32_32( temp2_fx, temp2_fx ) ) ); //Q31-2*Q_in + // P_out += temp1 * temp1 + temp2 * temp2; + P_out_fx = L_add( P_out_fx, L_add( Mpy_32_32( temp1_fx, temp1_fx ), Mpy_32_32( temp2_fx, temp2_fx ) ) ); // Q31-2*Q_in } // if ( ( factEQ <= 1e-20f ) || ( P_in[bandIdx] <= 1e-20f ) || ( P_out <= 1e-20f ) ) IF( LE_32( P_in_fx[bandIdx], 0 ) || LE_32( P_out_fx, 0 ) ) { - //factEQ = 1.0f; + // factEQ = 1.0f; factEQ_fx = 0x40000000; } ELSE @@ -1687,22 +1701,22 @@ static void ivas_binaural_obtain_DMX_fx( factEQ_fx = 0x40000000; } - //factEQ = max( min( factEQ, 2.0f ), 0.5f ); + // factEQ = max( min( factEQ, 2.0f ), 0.5f ); factEQ_fx = L_max( L_min( factEQ_fx, 0x7fffffff ), 0x20000000 ); // Q30 FOR( k = 0; k < numTimeSlots; k++ ) { - //realDMX[chOutIdx][k][bandIdx] *= factEQ; - //imagDMX[chOutIdx][k][bandIdx] *= factEQ; - realDMX[chOutIdx][k][bandIdx] = Mpy_32_32( realDMX[chOutIdx][k][bandIdx], factEQ_fx ); //Q_in - 1 - imagDMX[chOutIdx][k][bandIdx] = Mpy_32_32( imagDMX[chOutIdx][k][bandIdx], factEQ_fx ); //Q_in - 1 + // realDMX[chOutIdx][k][bandIdx] *= factEQ; + // imagDMX[chOutIdx][k][bandIdx] *= factEQ; + realDMX[chOutIdx][k][bandIdx] = Mpy_32_32( realDMX[chOutIdx][k][bandIdx], factEQ_fx ); // Q_in - 1 + imagDMX[chOutIdx][k][bandIdx] = Mpy_32_32( imagDMX[chOutIdx][k][bandIdx], factEQ_fx ); // Q_in - 1 } } } } ELSE IF( hBinRenderer->ivas_format == SBA_FORMAT || hBinRenderer->ivas_format == MASA_FORMAT ) { - //float *outRealLeftPtr, *outImagLeftPtr, *outRealRightPtr, *outImagRightPtr; - //float *inRealPtr, *inImagPtr; + // float *outRealLeftPtr, *outImagLeftPtr, *outRealRightPtr, *outImagRightPtr; + // float *inRealPtr, *inImagPtr; Word32 *outRealLeftPtr_fx, *outImagLeftPtr_fx, *outRealRightPtr_fx, *outImagRightPtr_fx; Word32 *inRealPtr_fx, *inImagPtr_fx; @@ -1720,23 +1734,23 @@ static void ivas_binaural_obtain_DMX_fx( FOR( chIdx = 0; chIdx < hBinRenderer->nInChannels; chIdx++ ) { - //float foa_const = hBinRenderer->hReverb->foa_enc[chIdx][1]; - Word32 foa_const_fx = L_shl(hBinRenderer->hReverb->foa_enc_fx[chIdx][1], 1); // Q30 + // float foa_const = hBinRenderer->hReverb->foa_enc[chIdx][1]; + Word32 foa_const_fx = L_shl( hBinRenderer->hReverb->foa_enc_fx[chIdx][1], 1 ); // Q30 inRealPtr_fx = (Word32 *) &( RealBuffer[chIdx][k][0] ); inImagPtr_fx = (Word32 *) &( ImagBuffer[chIdx][k][0] ); FOR( bandIdx = 0; bandIdx < hBinRenderer->conv_band; bandIdx++ ) { - //outRealLeftPtr[bandIdx] += inRealPtr[bandIdx] * ( 1.f + foa_const ); - //outImagLeftPtr[bandIdx] += inImagPtr[bandIdx] * ( 1.f + foa_const ); - outRealLeftPtr_fx[bandIdx] = L_add( outRealLeftPtr_fx[bandIdx], Mpy_32_32( inRealPtr_fx[bandIdx], L_add( ONE_IN_Q30, foa_const_fx ) ) ); //Q_in - 1 - outImagLeftPtr_fx[bandIdx] = L_add( outImagLeftPtr_fx[bandIdx], Mpy_32_32( inImagPtr_fx[bandIdx], L_add( ONE_IN_Q30, foa_const_fx ) ) ); //Q_in - 1 - - //outRealRightPtr[bandIdx] += inRealPtr[bandIdx] * ( 1.f - foa_const ); - //outImagRightPtr[bandIdx] += inImagPtr[bandIdx] * ( 1.f - foa_const ); - outRealRightPtr_fx[bandIdx] = L_add( outRealRightPtr_fx[bandIdx], Mpy_32_32( inRealPtr_fx[bandIdx], L_sub( ONE_IN_Q30, foa_const_fx ) ) ); //Q_in - 1 - outImagRightPtr_fx[bandIdx] = L_add( outImagRightPtr_fx[bandIdx], Mpy_32_32( inImagPtr_fx[bandIdx], L_sub( ONE_IN_Q30, foa_const_fx ) ) ); //Q_in - 1 + // outRealLeftPtr[bandIdx] += inRealPtr[bandIdx] * ( 1.f + foa_const ); + // outImagLeftPtr[bandIdx] += inImagPtr[bandIdx] * ( 1.f + foa_const ); + outRealLeftPtr_fx[bandIdx] = L_add( outRealLeftPtr_fx[bandIdx], Mpy_32_32( inRealPtr_fx[bandIdx], L_add( ONE_IN_Q30, foa_const_fx ) ) ); // Q_in - 1 + outImagLeftPtr_fx[bandIdx] = L_add( outImagLeftPtr_fx[bandIdx], Mpy_32_32( inImagPtr_fx[bandIdx], L_add( ONE_IN_Q30, foa_const_fx ) ) ); // Q_in - 1 + + // outRealRightPtr[bandIdx] += inRealPtr[bandIdx] * ( 1.f - foa_const ); + // outImagRightPtr[bandIdx] += inImagPtr[bandIdx] * ( 1.f - foa_const ); + outRealRightPtr_fx[bandIdx] = L_add( outRealRightPtr_fx[bandIdx], Mpy_32_32( inRealPtr_fx[bandIdx], L_sub( ONE_IN_Q30, foa_const_fx ) ) ); // Q_in - 1 + outImagRightPtr_fx[bandIdx] = L_add( outImagRightPtr_fx[bandIdx], Mpy_32_32( inImagPtr_fx[bandIdx], L_sub( ONE_IN_Q30, foa_const_fx ) ) ); // Q_in - 1 } } } @@ -2419,30 +2433,30 @@ void ivas_binaural_hrtf_close( allocate_init_flag = ( *hHrtfFastConv )->allocate_init_flag; - ivas_free_pppHrtfMem_fx(&(*hHrtfFastConv)->leftHRIRReal_fx, HRTF_LS_CHANNELS, allocate_init_flag); - ivas_free_pppHrtfMem_fx(&(*hHrtfFastConv)->leftHRIRImag_fx, HRTF_LS_CHANNELS, allocate_init_flag); - ivas_free_pppHrtfMem_fx(&(*hHrtfFastConv)->rightHRIRReal_fx, HRTF_LS_CHANNELS, allocate_init_flag); - ivas_free_pppHrtfMem_fx(&(*hHrtfFastConv)->rightHRIRImag_fx, HRTF_LS_CHANNELS, allocate_init_flag); + ivas_free_pppHrtfMem_fx( &( *hHrtfFastConv )->leftHRIRReal_fx, HRTF_LS_CHANNELS, allocate_init_flag ); + ivas_free_pppHrtfMem_fx( &( *hHrtfFastConv )->leftHRIRImag_fx, HRTF_LS_CHANNELS, allocate_init_flag ); + ivas_free_pppHrtfMem_fx( &( *hHrtfFastConv )->rightHRIRReal_fx, HRTF_LS_CHANNELS, allocate_init_flag ); + ivas_free_pppHrtfMem_fx( &( *hHrtfFastConv )->rightHRIRImag_fx, HRTF_LS_CHANNELS, allocate_init_flag ); - ivas_free_pppHrtfMem_fx(&(*hHrtfFastConv)->leftBRIRReal_fx, HRTF_LS_CHANNELS, allocate_init_flag); - ivas_free_pppHrtfMem_fx(&(*hHrtfFastConv)->leftBRIRImag_fx, HRTF_LS_CHANNELS, allocate_init_flag); - ivas_free_pppHrtfMem_fx(&(*hHrtfFastConv)->rightBRIRReal_fx, HRTF_LS_CHANNELS, allocate_init_flag); - ivas_free_pppHrtfMem_fx(&(*hHrtfFastConv)->rightBRIRImag_fx, HRTF_LS_CHANNELS, allocate_init_flag); + ivas_free_pppHrtfMem_fx( &( *hHrtfFastConv )->leftBRIRReal_fx, HRTF_LS_CHANNELS, allocate_init_flag ); + ivas_free_pppHrtfMem_fx( &( *hHrtfFastConv )->leftBRIRImag_fx, HRTF_LS_CHANNELS, allocate_init_flag ); + ivas_free_pppHrtfMem_fx( &( *hHrtfFastConv )->rightBRIRReal_fx, HRTF_LS_CHANNELS, allocate_init_flag ); + ivas_free_pppHrtfMem_fx( &( *hHrtfFastConv )->rightBRIRImag_fx, HRTF_LS_CHANNELS, allocate_init_flag ); - ivas_free_pppHrtfMem_fx(&(*hHrtfFastConv)->leftHRIRReal_HOA3_fx, HOA3_CHANNELS, allocate_init_flag); - ivas_free_pppHrtfMem_fx(&(*hHrtfFastConv)->leftHRIRImag_HOA3_fx, HOA3_CHANNELS, allocate_init_flag); - ivas_free_pppHrtfMem_fx(&(*hHrtfFastConv)->rightHRIRReal_HOA3_fx, HOA3_CHANNELS, allocate_init_flag); - ivas_free_pppHrtfMem_fx(&(*hHrtfFastConv)->rightHRIRImag_HOA3_fx, HOA3_CHANNELS, allocate_init_flag); + ivas_free_pppHrtfMem_fx( &( *hHrtfFastConv )->leftHRIRReal_HOA3_fx, HOA3_CHANNELS, allocate_init_flag ); + ivas_free_pppHrtfMem_fx( &( *hHrtfFastConv )->leftHRIRImag_HOA3_fx, HOA3_CHANNELS, allocate_init_flag ); + ivas_free_pppHrtfMem_fx( &( *hHrtfFastConv )->rightHRIRReal_HOA3_fx, HOA3_CHANNELS, allocate_init_flag ); + ivas_free_pppHrtfMem_fx( &( *hHrtfFastConv )->rightHRIRImag_HOA3_fx, HOA3_CHANNELS, allocate_init_flag ); - ivas_free_pppHrtfMem_fx(&(*hHrtfFastConv)->leftHRIRReal_HOA2_fx, HOA2_CHANNELS, allocate_init_flag); - ivas_free_pppHrtfMem_fx(&(*hHrtfFastConv)->leftHRIRImag_HOA2_fx, HOA2_CHANNELS, allocate_init_flag); - ivas_free_pppHrtfMem_fx(&(*hHrtfFastConv)->rightHRIRReal_HOA2_fx, HOA2_CHANNELS, allocate_init_flag); - ivas_free_pppHrtfMem_fx(&(*hHrtfFastConv)->rightHRIRImag_HOA2_fx, HOA2_CHANNELS, allocate_init_flag); + ivas_free_pppHrtfMem_fx( &( *hHrtfFastConv )->leftHRIRReal_HOA2_fx, HOA2_CHANNELS, allocate_init_flag ); + ivas_free_pppHrtfMem_fx( &( *hHrtfFastConv )->leftHRIRImag_HOA2_fx, HOA2_CHANNELS, allocate_init_flag ); + ivas_free_pppHrtfMem_fx( &( *hHrtfFastConv )->rightHRIRReal_HOA2_fx, HOA2_CHANNELS, allocate_init_flag ); + ivas_free_pppHrtfMem_fx( &( *hHrtfFastConv )->rightHRIRImag_HOA2_fx, HOA2_CHANNELS, allocate_init_flag ); - ivas_free_pppHrtfMem_fx(&(*hHrtfFastConv)->leftHRIRReal_FOA_fx, FOA_CHANNELS, allocate_init_flag); - ivas_free_pppHrtfMem_fx(&(*hHrtfFastConv)->leftHRIRImag_FOA_fx, FOA_CHANNELS, allocate_init_flag); - ivas_free_pppHrtfMem_fx(&(*hHrtfFastConv)->rightHRIRReal_FOA_fx, FOA_CHANNELS, allocate_init_flag); - ivas_free_pppHrtfMem_fx(&(*hHrtfFastConv)->rightHRIRImag_FOA_fx, FOA_CHANNELS, allocate_init_flag); + ivas_free_pppHrtfMem_fx( &( *hHrtfFastConv )->leftHRIRReal_FOA_fx, FOA_CHANNELS, allocate_init_flag ); + ivas_free_pppHrtfMem_fx( &( *hHrtfFastConv )->leftHRIRImag_FOA_fx, FOA_CHANNELS, allocate_init_flag ); + ivas_free_pppHrtfMem_fx( &( *hHrtfFastConv )->rightHRIRReal_FOA_fx, FOA_CHANNELS, allocate_init_flag ); + ivas_free_pppHrtfMem_fx( &( *hHrtfFastConv )->rightHRIRImag_FOA_fx, FOA_CHANNELS, allocate_init_flag ); return; } @@ -2520,11 +2534,11 @@ void ivas_binaural_add_LFE( if ( st_ivas->renderer_type == RENDERER_BINAURAL_OBJECTS_TD ) { gain = GAIN_LFE; - } else { - gain = ( ( st_ivas->hCrendWrapper != NULL ) && ( st_ivas->hCrendWrapper->hHrtfCrend != NULL ) ) ? st_ivas->hCrendWrapper->hHrtfCrend->gain_lfe : GAIN_LFE; } + gain = ( ( st_ivas->hCrendWrapper != NULL ) && ( st_ivas->hCrendWrapper->hHrtfCrend != NULL ) ) ? st_ivas->hCrendWrapper->hHrtfCrend->gain_lfe : GAIN_LFE; + } for ( idx_lfe = 0; idx_lfe < st_ivas->hIntSetup.num_lfe; idx_lfe++ ) { @@ -2594,73 +2608,73 @@ void ivas_binaural_add_LFE_fx( #ifdef IVAS_FLOAT_FIXED void ivas_binRenderer_fx( - BINAURAL_RENDERER_HANDLE hBinRenderer, /* i/o: binaural renderer handle */ - COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i : combined head and external orientation handle*/ - const int16_t numTimeSlots, /* i : number of time slots to render */ + BINAURAL_RENDERER_HANDLE hBinRenderer, /* i/o: binaural renderer handle */ + COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i : combined head and external orientation handle*/ + const int16_t numTimeSlots, /* i : number of time slots to render */ Word32 Cldfb_RealBuffer_Binaural_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : Binaural signals */ Word32 Cldfb_ImagBuffer_Binaural_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : Binaural signals */ Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals */ Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals */ - Word16 *Q_in /* i : LS signals exp */ + Word16 *Q_in /* i : LS signals exp */ ) { Word16 chIdx, i, j, k; - //to be checked: feasibility with 32 bit buffers + // to be checked: feasibility with 32 bit buffers Word64 Cldfb_RealBuffer_Binaural_64fx[BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; Word64 Cldfb_ImagBuffer_Binaural_64fx[BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; - push_wmops("fastconv_binaural_rendering"); + push_wmops( "fastconv_binaural_rendering" ); /* Compute Convolution */ /* memory reset for the binaural output */ - FOR(chIdx = 0; chIdx < BINAURAL_CHANNELS; chIdx++) + FOR( chIdx = 0; chIdx < BINAURAL_CHANNELS; chIdx++ ) { - FOR(k = 0; k < numTimeSlots; k++) + FOR( k = 0; k < numTimeSlots; k++ ) { - set32_fx(Cldfb_RealBuffer_Binaural_fx[chIdx][k], 0, CLDFB_NO_CHANNELS_MAX); - set32_fx(Cldfb_ImagBuffer_Binaural_fx[chIdx][k], 0, CLDFB_NO_CHANNELS_MAX); - set64_fx(Cldfb_RealBuffer_Binaural_64fx[chIdx][k], 0, CLDFB_NO_CHANNELS_MAX); - set64_fx(Cldfb_ImagBuffer_Binaural_64fx[chIdx][k], 0, CLDFB_NO_CHANNELS_MAX); + set32_fx( Cldfb_RealBuffer_Binaural_fx[chIdx][k], 0, CLDFB_NO_CHANNELS_MAX ); + set32_fx( Cldfb_ImagBuffer_Binaural_fx[chIdx][k], 0, CLDFB_NO_CHANNELS_MAX ); + set64_fx( Cldfb_RealBuffer_Binaural_64fx[chIdx][k], 0, CLDFB_NO_CHANNELS_MAX ); + set64_fx( Cldfb_ImagBuffer_Binaural_64fx[chIdx][k], 0, CLDFB_NO_CHANNELS_MAX ); } } /* Head rotation in HOA3 or CICPx */ - IF(hCombinedOrientationData != NULL && hCombinedOrientationData->enableCombinedOrientation[hCombinedOrientationData->subframe_idx] && hBinRenderer->rotInCldfb) + IF( hCombinedOrientationData != NULL && hCombinedOrientationData->enableCombinedOrientation[hCombinedOrientationData->subframe_idx] && hBinRenderer->rotInCldfb ) { - IF(hBinRenderer->hInputSetup->is_loudspeaker_setup == 0) + IF( hBinRenderer->hInputSetup->is_loudspeaker_setup == 0 ) { /* Rotation in SHD (HOA3) */ - IF(hCombinedOrientationData->shd_rot_max_order == -1) + IF( hCombinedOrientationData->shd_rot_max_order == -1 ) { - rotateFrame_shd_cldfb(RealBuffer_fx, ImagBuffer_fx, hCombinedOrientationData->Rmat_fx[hCombinedOrientationData->subframe_idx], hBinRenderer->hInputSetup->nchan_out_woLFE, numTimeSlots, 3); - *Q_in = sub(*Q_in, 1); //( Q_in + 14 - 15 ) + rotateFrame_shd_cldfb( RealBuffer_fx, ImagBuffer_fx, hCombinedOrientationData->Rmat_fx[hCombinedOrientationData->subframe_idx], hBinRenderer->hInputSetup->nchan_out_woLFE, numTimeSlots, 3 ); + *Q_in = sub( *Q_in, 1 ); //( Q_in + 14 - 15 ) } - ELSE IF(hCombinedOrientationData->shd_rot_max_order > 0) + ELSE IF( hCombinedOrientationData->shd_rot_max_order > 0 ) { - rotateFrame_shd_cldfb(RealBuffer_fx, ImagBuffer_fx, hCombinedOrientationData->Rmat_fx[hCombinedOrientationData->subframe_idx], hBinRenderer->hInputSetup->nchan_out_woLFE, numTimeSlots, hCombinedOrientationData->shd_rot_max_order); - *Q_in = sub(*Q_in, 1); //( Q_in + 14 - 15 ) + rotateFrame_shd_cldfb( RealBuffer_fx, ImagBuffer_fx, hCombinedOrientationData->Rmat_fx[hCombinedOrientationData->subframe_idx], hBinRenderer->hInputSetup->nchan_out_woLFE, numTimeSlots, hCombinedOrientationData->shd_rot_max_order ); + *Q_in = sub( *Q_in, 1 ); //( Q_in + 14 - 15 ) } } ELSE { /* Rotation in SD (CICPx) */ - rotateFrame_sd_cldfb_fixed(hCombinedOrientationData->Rmat_fx[hCombinedOrientationData->subframe_idx], RealBuffer_fx, ImagBuffer_fx, - hBinRenderer->hInputSetup, hBinRenderer->hEFAPdata, numTimeSlots, hBinRenderer->conv_band); + rotateFrame_sd_cldfb_fixed( hCombinedOrientationData->Rmat_fx[hCombinedOrientationData->subframe_idx], RealBuffer_fx, ImagBuffer_fx, + hBinRenderer->hInputSetup, hBinRenderer->hEFAPdata, numTimeSlots, hBinRenderer->conv_band ); } } /* HOA decoding to CICP19 if needed*/ - IF(hBinRenderer->hInputSetup->is_loudspeaker_setup == 0 && hBinRenderer->nInChannels != 16) + IF( hBinRenderer->hInputSetup->is_loudspeaker_setup == 0 && hBinRenderer->nInChannels != 16 ) { - ivas_sba2mc_cldfb_fixed(*(hBinRenderer->hInputSetup), RealBuffer_fx, ImagBuffer_fx, - hBinRenderer->nInChannels, hBinRenderer->conv_band, numTimeSlots, hBinRenderer->hoa_dec_mtx); + ivas_sba2mc_cldfb_fixed( *( hBinRenderer->hInputSetup ), RealBuffer_fx, ImagBuffer_fx, + hBinRenderer->nInChannels, hBinRenderer->conv_band, numTimeSlots, hBinRenderer->hoa_dec_mtx ); } - ivas_binRenderer_filterModule_fx(Cldfb_RealBuffer_Binaural_64fx, Cldfb_ImagBuffer_Binaural_64fx, RealBuffer_fx, ImagBuffer_fx, numTimeSlots, hBinRenderer, *Q_in); + ivas_binRenderer_filterModule_fx( Cldfb_RealBuffer_Binaural_64fx, Cldfb_ImagBuffer_Binaural_64fx, RealBuffer_fx, ImagBuffer_fx, numTimeSlots, hBinRenderer, *Q_in ); - FOR(i = 0; i < BINAURAL_CHANNELS; i++) + FOR( i = 0; i < BINAURAL_CHANNELS; i++ ) { - FOR(j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++) + FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) { - FOR(k = 0; k < CLDFB_NO_CHANNELS_MAX; k++) + FOR( k = 0; k < CLDFB_NO_CHANNELS_MAX; k++ ) { Cldfb_RealBuffer_Binaural_fx[i][j][k] = W_extract_l( W_shr( Cldfb_RealBuffer_Binaural_64fx[i][j][k], 29 ) ); //(*Q_in + 29) - 29 Cldfb_ImagBuffer_Binaural_fx[i][j][k] = W_extract_l( W_shr( Cldfb_ImagBuffer_Binaural_64fx[i][j][k], 29 ) ); //(*Q_in + 29) - 29 @@ -2668,49 +2682,49 @@ void ivas_binRenderer_fx( } } /* Obtain the binaural dmx and compute the reverb */ - IF(hBinRenderer->hReverb != NULL) + IF( hBinRenderer->hReverb != NULL ) { Word32 reverbRe_fx[BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; Word32 reverbIm_fx[BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; Word32 inRe_fx[BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; Word32 inIm_fx[BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; - ivas_binaural_obtain_DMX_fx(numTimeSlots, hBinRenderer, RealBuffer_fx, ImagBuffer_fx, inRe_fx, inIm_fx); + ivas_binaural_obtain_DMX_fx( numTimeSlots, hBinRenderer, RealBuffer_fx, ImagBuffer_fx, inRe_fx, inIm_fx ); // inRe_fx, inIm_fx Q = *Q_in - Q1 - FOR(chIdx = 0; chIdx < BINAURAL_CHANNELS; chIdx++) + FOR( chIdx = 0; chIdx < BINAURAL_CHANNELS; chIdx++ ) { - FOR(k = 0; k < numTimeSlots; k++) + FOR( k = 0; k < numTimeSlots; k++ ) { - set32_fx(reverbRe_fx[chIdx][k], 0, hBinRenderer->max_band); - set32_fx(reverbIm_fx[chIdx][k], 0, hBinRenderer->max_band); + set32_fx( reverbRe_fx[chIdx][k], 0, hBinRenderer->max_band ); + set32_fx( reverbIm_fx[chIdx][k], 0, hBinRenderer->max_band ); } } - ivas_binaural_reverb_processSubframe_fx(hBinRenderer->hReverb, BINAURAL_CHANNELS, numTimeSlots, inRe_fx, inIm_fx, reverbRe_fx, reverbIm_fx); + ivas_binaural_reverb_processSubframe_fx( hBinRenderer->hReverb, BINAURAL_CHANNELS, numTimeSlots, inRe_fx, inIm_fx, reverbRe_fx, reverbIm_fx ); // reverbRe_fx, reverbIm_fx Q = *Q_in - 1 // - FOR(i = 0; i < BINAURAL_CHANNELS; i++) + FOR( i = 0; i < BINAURAL_CHANNELS; i++ ) { - FOR(j = 0; j < numTimeSlots; j++) + FOR( j = 0; j < numTimeSlots; j++ ) { - FOR(k = 0; k < hBinRenderer->hReverb->numBins; k++) + FOR( k = 0; k < hBinRenderer->hReverb->numBins; k++ ) { - reverbRe_fx[i][j][k] = L_shl(reverbRe_fx[i][j][k], 1); //*Q_in - reverbIm_fx[i][j][k] = L_shl(reverbIm_fx[i][j][k], 1); //*Q_in + reverbRe_fx[i][j][k] = L_shl( reverbRe_fx[i][j][k], 1 ); //*Q_in + reverbIm_fx[i][j][k] = L_shl( reverbIm_fx[i][j][k], 1 ); //*Q_in } } } /* Add the conv module and reverb module output */ - FOR(chIdx = 0; chIdx < BINAURAL_CHANNELS; chIdx++) + FOR( chIdx = 0; chIdx < BINAURAL_CHANNELS; chIdx++ ) { - FOR(k = 0; k < numTimeSlots; k++) + FOR( k = 0; k < numTimeSlots; k++ ) { /* Combine first and second parts to generate binaural output signal with room effect */ - v_add_32(Cldfb_RealBuffer_Binaural_fx[chIdx][k], reverbRe_fx[chIdx][k], Cldfb_RealBuffer_Binaural_fx[chIdx][k], hBinRenderer->conv_band); - v_add_32(Cldfb_ImagBuffer_Binaural_fx[chIdx][k], reverbIm_fx[chIdx][k], Cldfb_ImagBuffer_Binaural_fx[chIdx][k], hBinRenderer->conv_band); + v_add_32( Cldfb_RealBuffer_Binaural_fx[chIdx][k], reverbRe_fx[chIdx][k], Cldfb_RealBuffer_Binaural_fx[chIdx][k], hBinRenderer->conv_band ); + v_add_32( Cldfb_ImagBuffer_Binaural_fx[chIdx][k], reverbIm_fx[chIdx][k], Cldfb_ImagBuffer_Binaural_fx[chIdx][k], hBinRenderer->conv_band ); } } } diff --git a/lib_dec/ivas_core_dec.c b/lib_dec/ivas_core_dec.c index 222aae2a8..9272d884f 100644 --- a/lib_dec/ivas_core_dec.c +++ b/lib_dec/ivas_core_dec.c @@ -60,7 +60,7 @@ ivas_error ivas_core_dec( MCT_DEC_HANDLE hMCT, /* i/o: MCT decoder structure */ const int16_t n_channels, /* i : number of channels to be decoded */ Word32 *output_32_fx[], /* o : output synthesis signal */ - Word32 hb_synth_32_fx[][L_FRAME48k], /* o : output HB synthesis signal */ + Word32 hb_synth_32_fx[][L_FRAME48k], /* o : output HB synthesis signal */ Word32 DFT_fx[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* o : DFT buffers */ const int16_t sba_dirac_stereo_flag /* i : signal stereo output for SBA DirAC */ ) @@ -71,7 +71,7 @@ ivas_error ivas_core_dec( STEREO_TD_DEC_DATA_HANDLE hStereoTD; int16_t sharpFlag[CPE_CHANNELS]; Word16 tmp_buffer_fx[L_FRAME48k]; - set_s(tmp_buffer_fx, 0, L_FRAME48k); + set_s( tmp_buffer_fx, 0, L_FRAME48k ); Word16 tmp16 = 0, tmp16_2, j; Word16 Q_white_exc; Q_white_exc = 0; @@ -83,7 +83,7 @@ ivas_error ivas_core_dec( int16_t core_switching_flag[CPE_CHANNELS]; Word16 pitch_buf_fx[CPE_CHANNELS][NB_SUBFR16k]; - Word32 old_syn_12k8_16k_fx[CPE_CHANNELS][L_FRAME16k]; + Word32 old_syn_12k8_16k_fx[CPE_CHANNELS][L_FRAME16k]; int16_t unbits[CPE_CHANNELS]; int16_t sid_bw[CPE_CHANNELS]; @@ -92,20 +92,20 @@ ivas_error ivas_core_dec( int32_t element_brate, output_Fs; int32_t last_element_brate; int16_t use_cldfb_for_dft; - Word32 *p_output_mem_fx; + Word32 *p_output_mem_fx; int16_t flag_sec_CNA; int16_t read_sid_info; int16_t last_element_mode; int16_t nchan_out; - Word32 *save_hb_synth_32_fx; + Word32 *save_hb_synth_32_fx; ivas_error error; Word32 L_tmp; Word16 Q_synth; - Word16 output_16_fx[CPE_CHANNELS][L_FRAME48k]; - Word16 hb_synth_16_fx[CPE_CHANNELS][L_FRAME48k]; + Word16 output_16_fx[CPE_CHANNELS][L_FRAME48k]; + Word16 hb_synth_16_fx[CPE_CHANNELS][L_FRAME48k]; - Word16 synth_16_fx[CPE_CHANNELS][L_FRAME48k]; - Word32 synth_32_fx[CPE_CHANNELS][L_FRAME48k]; + Word16 synth_16_fx[CPE_CHANNELS][L_FRAME48k]; + Word32 synth_32_fx[CPE_CHANNELS][L_FRAME48k]; FOR( i = 0; i < CPE_CHANNELS; i++ ) { @@ -172,17 +172,17 @@ ivas_error ivas_core_dec( } } - FOR(n = 0; n < n_channels; n++) + FOR( n = 0; n < n_channels; n++ ) { st = sts[n]; IF( st->cldfbAna ) { - scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, sub(Q10, Q11) ); + scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, sub( Q10, Q11 ) ); st->cldfbAna->Q_cldfb_state = Q10; } - IF(st->cldfbSynHB) + IF( st->cldfbSynHB ) { - scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->cldfb_size, sub(Q10, Q11) ); + scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->cldfb_size, sub( Q10, Q11 ) ); st->cldfbSynHB->Q_cldfb_state = Q10; } } @@ -252,7 +252,7 @@ ivas_error ivas_core_dec( set16_fx( voice_factors_fx[n], 0, NB_SUBFR16k ); set32_fx( hb_synth_32_fx[n], 0, L_FRAME48k ); - set16_fx(hb_synth_16_fx[n], 0, L_FRAME48k); + set16_fx( hb_synth_16_fx[n], 0, L_FRAME48k ); /*------------------------------------------------------------------* * Decision matrix (selection of technologies) *-----------------------------------------------------------------*/ @@ -288,7 +288,7 @@ ivas_error ivas_core_dec( { Copy_Scale_sig_16_32( sts[0]->hHQ_core->old_out_LB_fx, sts[0]->hHQ_core->old_outLB_fx, L_FRAME32k, Q11 - sts[0]->hHQ_core->Q_old_wtda_LB ); L_lerp_fx_q11( sts[0]->hHQ_core->old_outLB_fx, sts[0]->hHQ_core->old_outLB_fx, sts[0]->L_frame, sts[0]->last_L_frame ); - Copy_Scale_sig_32_16( sts[0]->hHQ_core->old_outLB_fx, sts[0]->hHQ_core->old_out_LB_fx, L_FRAME32k, sts[0]->hHQ_core->Q_old_wtda_LB - Q11); + Copy_Scale_sig_32_16( sts[0]->hHQ_core->old_outLB_fx, sts[0]->hHQ_core->old_out_LB_fx, L_FRAME32k, sts[0]->hHQ_core->Q_old_wtda_LB - Q11 ); } IF( sts[0]->L_frame != L_FRAME16k ) { @@ -343,7 +343,7 @@ ivas_error ivas_core_dec( * Core Decoding *-----------------------------------------------------------------*/ - FOR ( n = 0; n < n_channels; n++ ) + FOR( n = 0; n < n_channels; n++ ) { st = sts[n]; @@ -351,13 +351,13 @@ ivas_error ivas_core_dec( * Initialization *-----------------------------------------------------------------*/ - IF ( st->bfi == 1 ) + IF( st->bfi == 1 ) { st->nbLostCmpt++; } ELSE { - IF ( st->prev_bfi == 1 ) + IF( st->prev_bfi == 1 ) { st->prev_nbLostCmpt = st->nbLostCmpt; } @@ -370,7 +370,7 @@ ivas_error ivas_core_dec( } st->enablePlcWaveadjust = 0; - IF ( n == 1 ) + IF( n == 1 ) { sts[1]->BER_detect |= sts[0]->BER_detect; } @@ -388,13 +388,13 @@ ivas_error ivas_core_dec( Copy_Scale_sig_16_32( st->previoussynth_fx, st->previoussynth_fx_32, L_FRAME48k, 0 ); - IF ( ( error = core_switching_pre_dec_ivas_fx( st, output_frame, sts[0]->last_core_brate, nchan_out, last_element_mode, last_element_brate, st->Q_syn, &Q_olapBufferSynth, &Q_olapBufferSynth2) ) != IVAS_ERR_OK ) + IF( ( error = core_switching_pre_dec_ivas_fx( st, output_frame, sts[0]->last_core_brate, nchan_out, last_element_mode, last_element_brate, st->Q_syn, &Q_olapBufferSynth, &Q_olapBufferSynth2 ) ) != IVAS_ERR_OK ) { return error; } flag_sec_CNA = -1; - IF ( hCPE != NULL ) + IF( hCPE != NULL ) { flag_sec_CNA = sts[1]->flag_cna; } @@ -405,33 +405,35 @@ ivas_error ivas_core_dec( * HQ core decoding *---------------------------------------------------------------------*/ - IF ( st->core == ACELP_CORE ) + IF( st->core == ACELP_CORE ) { /* ACELP core decoder */ Word16 old_syn_12k8_16k_fx_16[L_FRAME16k]; - set_s(output_16_fx[n], 0, L_FRAME48k); + set_s( output_16_fx[n], 0, L_FRAME48k ); Word16 save_hb_synth_fx_arr[L_FRAME48k], *save_hb_synth_16_fx; - IF (save_hb_synth_32_fx) { + IF( save_hb_synth_32_fx ) + { save_hb_synth_16_fx = save_hb_synth_fx_arr; } - ELSE { + ELSE + { save_hb_synth_16_fx = NULL; } /* float2fix, to be removed */ - IF(st->cldfbAna) + IF( st->cldfbAna ) { - scale_sig32(st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, sub(Q11, Q10)); + scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, sub( Q11, Q10 ) ); st->cldfbAna->Q_cldfb_state = Q11; } - IF(st->cldfbBPF) + IF( st->cldfbBPF ) { - scale_sig32(st->cldfbBPF->cldfb_state_fx, st->cldfbBPF->cldfb_size, sub(Q10, Q11)); + scale_sig32( st->cldfbBPF->cldfb_state_fx, st->cldfbBPF->cldfb_size, sub( Q10, Q11 ) ); st->cldfbBPF->Q_cldfb_state = Q10; } - IF(st->cldfbSyn) + IF( st->cldfbSyn ) { - scale_sig32(st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->cldfb_size, sub(Q10, Q11)); + scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->cldfb_size, sub( Q10, Q11 ) ); st->cldfbSyn->Q_cldfb_state = Q10; } @@ -449,21 +451,21 @@ ivas_error ivas_core_dec( } /* fix2float, to be removed */ - Copy_Scale_sig_16_32(output_16_fx[n],output_32_fx[n],L_FRAME48k, Q11 - st->Q_syn2); - Scale_sig(output_16_fx[n], L_FRAME48k, -st->Q_syn2); - IF(st->cldfbAna) + Copy_Scale_sig_16_32( output_16_fx[n], output_32_fx[n], L_FRAME48k, Q11 - st->Q_syn2 ); + Scale_sig( output_16_fx[n], L_FRAME48k, -st->Q_syn2 ); + IF( st->cldfbAna ) { - scale_sig32(st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, sub(Q10, Q11)); /* 9 * (Word16)(st->L_frame * FRAMES_PER_SEC * INV_CLDFB_BANDWIDTH + 0.5f) */ + scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, sub( Q10, Q11 ) ); /* 9 * (Word16)(st->L_frame * FRAMES_PER_SEC * INV_CLDFB_BANDWIDTH + 0.5f) */ st->cldfbAna->Q_cldfb_state = Q10; } - IF(st->cldfbBPF) + IF( st->cldfbBPF ) { - scale_sig32(st->cldfbBPF->cldfb_state_fx, st->cldfbBPF->cldfb_size, sub(Q11, Q10)); + scale_sig32( st->cldfbBPF->cldfb_state_fx, st->cldfbBPF->cldfb_size, sub( Q11, Q10 ) ); st->cldfbBPF->Q_cldfb_state = Q11; } - IF(st->cldfbSyn) + IF( st->cldfbSyn ) { - scale_sig32(st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->cldfb_size, sub(Q11, Q10)); + scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->cldfb_size, sub( Q11, Q10 ) ); st->cldfbSyn->Q_cldfb_state = Q11; } st->prev_Q_syn = st->Q_syn; @@ -474,10 +476,10 @@ ivas_error ivas_core_dec( hSCE->q_save_hb_synth_fx = Q11; } - Copy_Scale_sig_16_32(old_syn_12k8_16k_fx_16, old_syn_12k8_16k_fx[n],L_FRAME16k,Q11 - (-1)); + Copy_Scale_sig_16_32( old_syn_12k8_16k_fx_16, old_syn_12k8_16k_fx[n], L_FRAME16k, Q11 - ( -1 ) ); } - Copy_Scale_sig_32_16(st->previoussynth_fx_32, st->previoussynth_fx, L_FRAME48k, 0); + Copy_Scale_sig_32_16( st->previoussynth_fx_32, st->previoussynth_fx, L_FRAME48k, 0 ); IF( ( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { @@ -490,9 +492,9 @@ ivas_error ivas_core_dec( st->mem_error = st->hBPF->pst_mem_deemp_err_fx; // u8bit to 16bit - FOR(int l = 0; l < IGF_START_MX; l++) + FOR( int l = 0; l < IGF_START_MX; l++ ) { - st->hIGFDec->infoTCXNoise_evs[l] = (Word16)st->hIGFDec->infoTCXNoise[l]; + st->hIGFDec->infoTCXNoise_evs[l] = (Word16) st->hIGFDec->infoTCXNoise[l]; } /* TCX decoder */ @@ -513,38 +515,38 @@ ivas_error ivas_core_dec( st->hTcxDec->conCurrLevelIndex = st->hTcxDec->CurrLevelIndex_bfi; st->hTcxDec->conLastFrameLevel = st->hTcxDec->LastFrameLevel_bfi_fx; } - st->hBPF->pst_mem_deemp_err_fx = (Word16)st->mem_error; + st->hBPF->pst_mem_deemp_err_fx = (Word16) st->mem_error; } - IF ( EQ_16(st->core, HQ_CORE) ) + IF( EQ_16( st->core, HQ_CORE ) ) { /* HQ core decoder */ - Q_synth = 0; - Word16 Q_output = 0; + Q_synth = 0; + Word16 Q_output = 0; ivas_hq_core_dec_fx( st, synth_16_fx[n], &Q_synth, output_frame, NORMAL_HQ_CORE, core_switching_flag[n], output_16_fx[n], &Q_output ); - Copy_Scale_sig_16_32(output_16_fx[n], output_32_fx[n], L_FRAME48k, Q11 - Q_output); + Copy_Scale_sig_16_32( output_16_fx[n], output_32_fx[n], L_FRAME48k, Q11 - Q_output ); #ifdef MSAN_FIX - Scale_sig(synth_16_fx[n], output_frame, -Q_synth); + Scale_sig( synth_16_fx[n], output_frame, -Q_synth ); #else - Scale_sig(synth_16_fx[n], L_FRAME48k, -Q_synth); + Scale_sig( synth_16_fx[n], L_FRAME48k, -Q_synth ); #endif - Scale_sig(output_16_fx[n], L_FRAME48k, -Q_output); + Scale_sig( output_16_fx[n], L_FRAME48k, -Q_output ); } /*---------------------------------------------------------------------* * TD stereo updates *---------------------------------------------------------------------*/ - IF ( st->element_mode == IVAS_CPE_TD && n == 0 ) + IF( st->element_mode == IVAS_CPE_TD && n == 0 ) { - Copy_Scale_sig_32_16(hCPE->hCoreCoder[0]->old_pitch_buf_fx, hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, 2 * NB_SUBFR16k + 2, -10); + Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->old_pitch_buf_fx, hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, 2 * NB_SUBFR16k + 2, -10 ); td_stereo_param_updt_fx( st->lsp_old_fx, st->lsf_old_fx, st->old_pitch_buf_16_fx + st->nb_subfr, tdm_lspQ_PCh_fx, tdm_lsfQ_PCh_fx, hStereoTD->tdm_Pri_pitch_buf_fx, st->flag_ACELP16k, hStereoTD->tdm_use_IAWB_Ave_lpc, Q6 ); - Copy_Scale_sig_16_32(hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, hCPE->hCoreCoder[0]->old_pitch_buf_fx, 2 * NB_SUBFR16k + 2, 10); + Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, hCPE->hCoreCoder[0]->old_pitch_buf_fx, 2 * NB_SUBFR16k + 2, 10 ); } } /* n_channels loop */ @@ -554,24 +556,24 @@ ivas_error ivas_core_dec( * MDCT stereo: joint TCX Core Decoding *---------------------------------------------------------------------*/ - IF ( EQ_16(sts[0]->element_mode, IVAS_CPE_MDCT )) + IF( EQ_16( sts[0]->element_mode, IVAS_CPE_MDCT ) ) { /* active-frame decoding */ - IF ( GT_32(sts[0]->core_brate, SID_2k40 )) + IF( GT_32( sts[0]->core_brate, SID_2k40 ) ) { - IF ( hMCT ) + IF( hMCT ) { - FOR(n = 0; n < n_channels; n++) + FOR( n = 0; n < n_channels; n++ ) { st = sts[n]; - IF(st->cldfbAna) + IF( st->cldfbAna ) { - scale_sig32(st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, sub(Q11, Q10)); + scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, sub( Q11, Q10 ) ); st->cldfbAna->Q_cldfb_state = Q11; } - IF(st->cldfbSynHB) + IF( st->cldfbSynHB ) { - scale_sig32(st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->cldfb_size, sub(Q11, Q10)); + scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->cldfb_size, sub( Q11, Q10 ) ); st->cldfbSynHB->Q_cldfb_state = Q11; } } @@ -628,28 +630,28 @@ ivas_error ivas_core_dec( sts[0] = hCPE->hCoreCoder[0]; sts[1] = hCPE->hCoreCoder[1]; - IF ( hCPE->last_element_brate <= IVAS_SID_5k2 ) + IF( hCPE->last_element_brate <= IVAS_SID_5k2 ) { sts[0]->hHQ_core->exp_old_out = 15 - sts[0]->hHQ_core->Q_old_wtda; sts[1]->hHQ_core->exp_old_out = 15 - sts[1]->hHQ_core->Q_old_wtda; } updateBuffersForDmxMdctStereo_fx( hCPE, output_frame, output_32_fx[0], output_32_fx[1], synth_16_fx ); - IF ( hCPE->last_element_brate <= IVAS_SID_5k2 ) + IF( hCPE->last_element_brate <= IVAS_SID_5k2 ) { sts[0]->hHQ_core->Q_old_wtda = 15 - sts[0]->hHQ_core->exp_old_out; sts[1]->hHQ_core->Q_old_wtda = 15 - sts[1]->hHQ_core->exp_old_out; } } test(); - IF ( EQ_16(sts[0]->bfi, 0) && EQ_16(sts[0]->prev_bfi, 1 )) + IF( EQ_16( sts[0]->bfi, 0 ) && EQ_16( sts[0]->prev_bfi, 1 ) ) { /* On first good frame after frameloss undo the whitening of the bg noise shape */ - FOR ( n = 0; n < n_channels; ++n ) + FOR( n = 0; n < n_channels; ++n ) { - IF ( NE_16(sts[n]->last_core_bfi, ACELP_CORE) ) + IF( NE_16( sts[n]->last_core_bfi, ACELP_CORE ) ) { - Scale_sig32(sts[n]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, sub(sts[n]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 27)); + Scale_sig32( sts[n]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, sub( sts[n]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 27 ) ); sts[n]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 27; TonalMdctConceal_whiten_noise_shape_ivas_fx( sts[n], L_FRAME16k, ON_FIRST_GOOD_FRAME ); @@ -662,25 +664,24 @@ ivas_error ivas_core_dec( * Stereo CNG updates *---------------------------------------------------------------------*/ - IF ( EQ_16(sts[0]->element_mode, IVAS_CPE_TD) && hCPE->hStereoCng != NULL ) + IF( EQ_16( sts[0]->element_mode, IVAS_CPE_TD ) && hCPE->hStereoCng != NULL ) { /* To be cleaned up once the caller function is converted // These changes are for system testing of fixed changes made */ Word16 Q_c_PS_LT = 31, Q_output = 11; - Word32 c_PS_LT_fx = L_deposit_h( hCPE->hStereoCng->c_PS_LT_fx); + Word32 c_PS_LT_fx = L_deposit_h( hCPE->hStereoCng->c_PS_LT_fx ); Q_c_PS_LT = Q31; stereo_cng_compute_PScorr_fx( output_32_fx[0], output_32_fx[1], &Q_output, &c_PS_LT_fx, Q_c_PS_LT, sts[0]->L_frame, sts[1]->L_frame ); hCPE->hStereoCng->c_PS_LT_fx = extract_h( c_PS_LT_fx ); - } /*---------------------------------------------------------------------* * Postprocessing, BWEs and updates *---------------------------------------------------------------------*/ - FOR ( n = 0; n < n_channels; n++ ) + FOR( n = 0; n < n_channels; n++ ) { st = sts[n]; @@ -688,31 +689,31 @@ ivas_error ivas_core_dec( * TD-BWE for ACELP to TCX transitions *---------------------------------------------------------------------*/ - /*core_switching_post_dec*/ + /*core_switching_post_dec*/ Q_synth = 0; - if (st->hHQ_core != NULL) + if ( st->hHQ_core != NULL ) { - st->hHQ_core->Q_old_postdec = 0; - //st->hHQ_core->Q_old_wtda = 0; + st->hHQ_core->Q_old_postdec = 0; + // st->hHQ_core->Q_old_wtda = 0; } /*------------------fix-to-fix-end-----------------------*/ - Word16 output_mem_16_fx[L_FRAME48k]; - Word16 *p_output_mem_16; + Word16 output_mem_16_fx[L_FRAME48k]; + Word16 *p_output_mem_16; - IF(p_output_mem_fx != NULL) + IF( p_output_mem_fx != NULL ) { - p_output_mem_16 = output_mem_16_fx; - Copy_Scale_sig_32_16(p_output_mem_fx, p_output_mem_16, NS2SA_fx2(output_Fs, STEREO_DFT32MS_OVL_NS), negate(Q11)); + p_output_mem_16 = output_mem_16_fx; + Copy_Scale_sig_32_16( p_output_mem_fx, p_output_mem_16, NS2SA_fx2( output_Fs, STEREO_DFT32MS_OVL_NS ), negate( Q11 ) ); } ELSE { - p_output_mem_16 = NULL; - set16_fx(output_mem_16_fx, 0, NS2SA(st->output_Fs, 3125000)); + p_output_mem_16 = NULL; + set16_fx( output_mem_16_fx, 0, NS2SA( st->output_Fs, 3125000 ) ); } - Scale_sig32(output_32_fx[n], L_FRAME48k, Q4 - Q11); + Scale_sig32( output_32_fx[n], L_FRAME48k, Q4 - Q11 ); IF( st->hHQ_core != NULL ) { @@ -723,24 +724,30 @@ ivas_error ivas_core_dec( /*size of synth is choosen as delay comp to start with*/ /*-------------------cldfb-start-------------------------*/ - IF (st->cldfbSyn != NULL) + IF( st->cldfbSyn != NULL ) { - scale_sig32(st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub(Q4, Q11)); - st->cldfbSyn->Q_cldfb_state = Q4; + scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q4, Q11 ) ); + st->cldfbSyn->Q_cldfb_state = Q4; } Word16 q_audio, old_syn_fx; old_syn_fx = Q11; q_audio = Q12; - test(); test(); test(); test(); - IF ( EQ_16(st->last_core, ACELP_CORE) && (EQ_16(st->core, TCX_20_CORE) || EQ_16(st->core, TCX_10_CORE) || EQ_16(st->core, HQ_CORE) ) && st->hBWE_TD != NULL ) + test(); + test(); + test(); + test(); + IF( EQ_16( st->last_core, ACELP_CORE ) && ( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || EQ_16( st->core, HQ_CORE ) ) && st->hBWE_TD != NULL ) { - test(); test(); test(); test(); - IF ( (EQ_16(st->bwidth, SWB) || EQ_16(st->bwidth, FB) ) && (EQ_16(st->last_extl, SWB_TBE) || EQ_16(st->last_extl, FB_TBE) ) ) + test(); + test(); + test(); + test(); + IF( ( EQ_16( st->bwidth, SWB ) || EQ_16( st->bwidth, FB ) ) && ( EQ_16( st->last_extl, SWB_TBE ) || EQ_16( st->last_extl, FB_TBE ) ) ) { GenTransition_fixed( st->hBWE_TD, hb_synth_32_fx[n], output_Fs, st->element_mode, st->L_frame, st->rf_flag, st->total_brate ); } - ELSE IF (EQ_16(st->bwidth, WB) && EQ_16(st->last_extl, WB_TBE) ) + ELSE IF( EQ_16( st->bwidth, WB ) && EQ_16( st->last_extl, WB_TBE ) ) { GenTransition_WB_fixed( st->hBWE_TD, hb_synth_32_fx[n], output_Fs ); @@ -748,51 +755,59 @@ ivas_error ivas_core_dec( } /* Memories Scaling */ - Copy_Scale_sig_32_16(st->hBWE_TD->syn_overlap_fx_32, st->hBWE_TD->syn_overlap_fx, L_SHB_LAHEAD, st->prev_Q_bwe_syn2 - Q11); - Copy_Scale_sig_32_16(st->hBWE_TD->old_tbe_synth_fx_32, st->hBWE_TD->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH, st->prev_Qx - Q11); - Copy_Scale_sig_32_16(st->hBWE_TD->state_lsyn_filt_dwn_shb_fx_32, st->hBWE_TD->state_lsyn_filt_dwn_shb_fx, shl(ALLPASSSECTIONS_STEEP, 1), st->prev_Qx - Q11); - Copy_Scale_sig_32_16(st->hBWE_TD->state_lsyn_filt_shb_fx_32, st->hBWE_TD->state_lsyn_filt_shb_fx, shl(ALLPASSSECTIONS_STEEP, 1), st->prev_Qx - Q11); - Copy_Scale_sig_32_16(st->hBWE_TD->mem_resamp_HB_fx_32, st->hBWE_TD->mem_resamp_HB_fx, INTERP_3_1_MEM_LEN, st->prev_Qx - Q11); + Copy_Scale_sig_32_16( st->hBWE_TD->syn_overlap_fx_32, st->hBWE_TD->syn_overlap_fx, L_SHB_LAHEAD, st->prev_Q_bwe_syn2 - Q11 ); + Copy_Scale_sig_32_16( st->hBWE_TD->old_tbe_synth_fx_32, st->hBWE_TD->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH, st->prev_Qx - Q11 ); + Copy_Scale_sig_32_16( st->hBWE_TD->state_lsyn_filt_dwn_shb_fx_32, st->hBWE_TD->state_lsyn_filt_dwn_shb_fx, shl( ALLPASSSECTIONS_STEEP, 1 ), st->prev_Qx - Q11 ); + Copy_Scale_sig_32_16( st->hBWE_TD->state_lsyn_filt_shb_fx_32, st->hBWE_TD->state_lsyn_filt_shb_fx, shl( ALLPASSSECTIONS_STEEP, 1 ), st->prev_Qx - Q11 ); + Copy_Scale_sig_32_16( st->hBWE_TD->mem_resamp_HB_fx_32, st->hBWE_TD->mem_resamp_HB_fx, INTERP_3_1_MEM_LEN, st->prev_Qx - Q11 ); } /* Memories Re-Scaling */ - IF(st->hBWE_TD != NULL) + IF( st->hBWE_TD != NULL ) { - Copy_Scale_sig_16_32(st->hBWE_TD->syn_overlap_fx, st->hBWE_TD->syn_overlap_fx_32, L_SHB_LAHEAD, Q11 - st->prev_Q_bwe_syn2); - Copy_Scale_sig_16_32(st->hBWE_TD->old_tbe_synth_fx, st->hBWE_TD->old_tbe_synth_fx_32, L_SHB_TRANSITION_LENGTH, Q11 - st->prev_Qx); - Copy_Scale_sig_16_32(st->hBWE_TD->state_lsyn_filt_dwn_shb_fx, st->hBWE_TD->state_lsyn_filt_dwn_shb_fx_32, shl(ALLPASSSECTIONS_STEEP, 1), Q11 - st->prev_Qx); - Copy_Scale_sig_16_32(st->hBWE_TD->state_lsyn_filt_shb_fx, st->hBWE_TD->state_lsyn_filt_shb_fx_32, shl(ALLPASSSECTIONS_STEEP, 1), Q11 - st->prev_Qx); - Copy_Scale_sig_16_32(st->hBWE_TD->mem_resamp_HB_fx, st->hBWE_TD->mem_resamp_HB_fx_32, INTERP_3_1_MEM_LEN, Q11 - st->prev_Qx); - Copy(st->hBWE_TD->mem_resamp_HB_fx, st->hBWE_TD->state_32and48k_WB_upsample_fx, 2 * ALLPASSSECTIONS_STEEP); + Copy_Scale_sig_16_32( st->hBWE_TD->syn_overlap_fx, st->hBWE_TD->syn_overlap_fx_32, L_SHB_LAHEAD, Q11 - st->prev_Q_bwe_syn2 ); + Copy_Scale_sig_16_32( st->hBWE_TD->old_tbe_synth_fx, st->hBWE_TD->old_tbe_synth_fx_32, L_SHB_TRANSITION_LENGTH, Q11 - st->prev_Qx ); + Copy_Scale_sig_16_32( st->hBWE_TD->state_lsyn_filt_dwn_shb_fx, st->hBWE_TD->state_lsyn_filt_dwn_shb_fx_32, shl( ALLPASSSECTIONS_STEEP, 1 ), Q11 - st->prev_Qx ); + Copy_Scale_sig_16_32( st->hBWE_TD->state_lsyn_filt_shb_fx, st->hBWE_TD->state_lsyn_filt_shb_fx_32, shl( ALLPASSSECTIONS_STEEP, 1 ), Q11 - st->prev_Qx ); + Copy_Scale_sig_16_32( st->hBWE_TD->mem_resamp_HB_fx, st->hBWE_TD->mem_resamp_HB_fx_32, INTERP_3_1_MEM_LEN, Q11 - st->prev_Qx ); + Copy( st->hBWE_TD->mem_resamp_HB_fx, st->hBWE_TD->state_32and48k_WB_upsample_fx, 2 * ALLPASSSECTIONS_STEEP ); } /*---------------------------------------------------------------------* * Postprocessing for ACELP/MDCT core switching *---------------------------------------------------------------------*/ /* save synth and output in case of SBA DirAC stereo output as core switching is done outside of core decoder */ - test(); test(); test(); - IF (sba_dirac_stereo_flag && NE_16(st->element_mode, IVAS_CPE_MDCT) && !(EQ_32(st->core_brate, SID_2k40) && EQ_16(st->cng_type, FD_CNG))) + test(); + test(); + test(); + IF( sba_dirac_stereo_flag && NE_16( st->element_mode, IVAS_CPE_MDCT ) && !( EQ_32( st->core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) ) ) { - Copy_Scale_sig_16_32(synth_16_fx[n], hSCE->save_synth_fx, output_frame, hSCE->q_save_synth_fx - Q_synth); + Copy_Scale_sig_16_32( synth_16_fx[n], hSCE->save_synth_fx, output_frame, hSCE->q_save_synth_fx - Q_synth ); } - IF ( ( error = core_switching_post_dec_ivas_fx( st, synth_16_fx[n], output_32_fx[n], p_output_mem_16, ( st_ivas != NULL ) ? st_ivas->ivas_format : UNDEFINED_FORMAT, use_cldfb_for_dft, output_frame, 0 /*core_switching_flag*/, sba_dirac_stereo_flag, nchan_out, ( hCPE != NULL ) ? hCPE->last_element_mode : IVAS_SCE, &Q_synth ) ) != IVAS_ERR_OK ) + IF( ( error = core_switching_post_dec_ivas_fx( st, synth_16_fx[n], output_32_fx[n], p_output_mem_16, ( st_ivas != NULL ) ? st_ivas->ivas_format : UNDEFINED_FORMAT, use_cldfb_for_dft, output_frame, 0 /*core_switching_flag*/, sba_dirac_stereo_flag, nchan_out, ( hCPE != NULL ) ? hCPE->last_element_mode : IVAS_SCE, &Q_synth ) ) != IVAS_ERR_OK ) { return error; } /* for FD-CNG we need the delay compensation in the synth, so do this afterwards */ - test(); test(); test(); - IF (sba_dirac_stereo_flag && hSCE && EQ_32(st->core_brate, SID_2k40) && EQ_16(st->cng_type, FD_CNG)) + test(); + test(); + test(); + IF( sba_dirac_stereo_flag && hSCE && EQ_32( st->core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) ) { - Copy_Scale_sig_16_32(synth_16_fx[n], hSCE->save_synth_fx, output_frame, hSCE->q_save_synth_fx - Q_synth); + Copy_Scale_sig_16_32( synth_16_fx[n], hSCE->save_synth_fx, output_frame, hSCE->q_save_synth_fx - Q_synth ); } /* if we transition from inactive to active coding in MDCT-Stereo DTX and the output format is mono DMX, we need to sync the upsampled buffer between channels here */ - test(); test(); test(); test(); test(); - IF (EQ_16(n, 0) && EQ_16(st->element_mode, IVAS_CPE_MDCT) && EQ_16(st->last_core, ACELP_CORE) && NE_16(st->core, ACELP_CORE) && (EQ_16(nchan_out, 1) || (hCPE != NULL && EQ_16(hCPE->last_element_mode, IVAS_CPE_DFT)))) + test(); + test(); + test(); + test(); + test(); + IF( EQ_16( n, 0 ) && EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( st->last_core, ACELP_CORE ) && NE_16( st->core, ACELP_CORE ) && ( EQ_16( nchan_out, 1 ) || ( hCPE != NULL && EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) ) ) ) { - Copy(sts[0]->previoussynth_fx, sts[1]->previoussynth_fx, st->hTcxDec->L_frameTCX); + Copy( sts[0]->previoussynth_fx, sts[1]->previoussynth_fx, st->hTcxDec->L_frameTCX ); } /*---------------------------------------------------------------------* * Pre-processing for bandwidth switching @@ -800,35 +815,35 @@ ivas_error ivas_core_dec( ivas_bw_switching_pre_proc_fx( st, last_element_brate, nchan_out, old_syn_12k8_16k_fx[n], old_syn_fx, q_audio ); - Copy_Scale_sig_16_32(st->delay_buf_out_fx, st->delay_buf_out32_fx, HQ_DELTA_MAX * HQ_DELAY_COMP, Q11); - Scale_sig32(output_32_fx[n], L_FRAME48k, Q11 - Q4); + Copy_Scale_sig_16_32( st->delay_buf_out_fx, st->delay_buf_out32_fx, HQ_DELTA_MAX * HQ_DELAY_COMP, Q11 ); + Scale_sig32( output_32_fx[n], L_FRAME48k, Q11 - Q4 ); /*note : cldfb_size here signifies the original size which was assigned to cldfb_state_fx buffer not its current size*/ - IF (st->cldfbSyn != NULL) + IF( st->cldfbSyn != NULL ) { - scale_sig32(st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub(Q11, Q4)); - st->cldfbSyn->Q_cldfb_state = Q11; + scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q11, Q4 ) ); + st->cldfbSyn->Q_cldfb_state = Q11; } #ifdef MSAN_FIX - Scale_sig(synth_16_fx[n], output_frame, negate(Q_synth)); + Scale_sig( synth_16_fx[n], output_frame, negate( Q_synth ) ); #else - Scale_sig(synth_16_fx[n], L_FRAME48k, negate(Q_synth)); + Scale_sig( synth_16_fx[n], L_FRAME48k, negate( Q_synth ) ); #endif /*------------------reset-code-start---------------------*/ - IF(NE_16(st->last_extl, WB_BWE) && EQ_16(st->extl, WB_BWE) && st->hBWE_FD != NULL) + IF( NE_16( st->last_extl, WB_BWE ) && EQ_16( st->extl, WB_BWE ) && st->hBWE_FD != NULL ) { - IF(NE_16(st->last_extl, SWB_BWE) && NE_16(st->last_extl, FB_BWE)) - { - st->hBWE_FD->prev_mode = st->hBWE_FD->prev_mode; - } - st->hBWE_FD->prev_L_swb_norm = st->hBWE_FD->prev_L_swb_norm; - st->hBWE_FD->prev_flag = st->hBWE_FD->prev_flag; + IF( NE_16( st->last_extl, SWB_BWE ) && NE_16( st->last_extl, FB_BWE ) ) + { + st->hBWE_FD->prev_mode = st->hBWE_FD->prev_mode; + } + st->hBWE_FD->prev_L_swb_norm = st->hBWE_FD->prev_L_swb_norm; + st->hBWE_FD->prev_flag = st->hBWE_FD->prev_flag; } /*---------------------------------------------------------------------* @@ -903,16 +918,18 @@ ivas_error ivas_core_dec( IF( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, FB_TBE ) || ( NE_16( st->coder_type, AUDIO ) && NE_16( st->coder_type, INACTIVE ) && GE_32( st->core_brate, SID_2k40 ) && EQ_16( st->core, ACELP_CORE ) && !st->con_tcx && GE_32( output_Fs, 32000 ) && GT_16( st->bwidth, NB ) && GT_16( st->bws_cnt, 0 ) ) ) { /* SWB TBE decoder */ - Q_white_exc = 0; move16(); + Q_white_exc = 0; + move16(); ivas_swb_tbe_dec_fx( st, hStereoICBWE, bwe_exc_extended_fx[n], st->Q_exc, voice_factors_fx[n], old_syn_12k8_16k_fx[n], tmp_buffer_fx /*fb_exc*/, hb_synth_32_fx[n], pitch_buf_fx[n], &Q_white_exc ); Copy_Scale_sig_32_16( st->hBWE_TD->old_tbe_synth_fx_32, st->hBWE_TD->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH, st->prev_Qx - Q11 ); - IF( GT_16(Q_white_exc, 31 )) + IF( GT_16( Q_white_exc, 31 ) ) { Scale_sig( tmp_buffer_fx, L_FRAME48k, 31 - Q_white_exc ); - Q_white_exc = 31; move16(); + Q_white_exc = 31; + move16(); } /* FB TBE decoder */ @@ -966,35 +983,35 @@ ivas_error ivas_core_dec( * SWB CNG *---------------------------------------------------------------------*/ - IF ( ( output_frame >= L_FRAME32k && st->hTdCngDec != NULL ) || ( st->element_mode == IVAS_CPE_DFT && st->bwidth >= SWB && st->hTdCngDec != NULL ) ) + IF( ( output_frame >= L_FRAME32k && st->hTdCngDec != NULL ) || ( st->element_mode == IVAS_CPE_DFT && st->bwidth >= SWB && st->hTdCngDec != NULL ) ) { /* SHB CNG decoder */ Word16 synth_fxl[960]; /* Q-2 */ Word16 q = 2; - Copy_Scale_sig_32_16(hb_synth_32_fx[n], hb_synth_16_fx[n], L_FRAME48k, -(Q11 + q)); + Copy_Scale_sig_32_16( hb_synth_32_fx[n], hb_synth_16_fx[n], L_FRAME48k, -( Q11 + q ) ); #ifdef MSAN_FIX - Copy_Scale_sig_32_16(synth_32_fx[n], synth_fxl, output_frame, -(Q11 + q)); + Copy_Scale_sig_32_16( synth_32_fx[n], synth_fxl, output_frame, -( Q11 + q ) ); #else - Copy_Scale_sig_32_16(synth_32_fx[n], synth_fxl, L_FRAME48k, -(Q11 + q)); + Copy_Scale_sig_32_16( synth_32_fx[n], synth_fxl, L_FRAME48k, -( Q11 + q ) ); #endif - Scale_sig(st->hBWE_TD->state_lpc_syn_fx, LPC_SHB_ORDER, (Q8 - st->prev_Q_bwe_syn)); - Scale_sig32(st->hBWE_TD->genSHBsynth_Hilbert_Mem_fx, HILBERT_MEM_SIZE, (st->prev_Q_bwe_syn2 - Q11)); - Copy_Scale_sig_32_16(st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, 2 * ALLPASSSECTIONS_STEEP, (st->prev_Q_bwe_syn2 - Q11)); + Scale_sig( st->hBWE_TD->state_lpc_syn_fx, LPC_SHB_ORDER, ( Q8 - st->prev_Q_bwe_syn ) ); + Scale_sig32( st->hBWE_TD->genSHBsynth_Hilbert_Mem_fx, HILBERT_MEM_SIZE, ( st->prev_Q_bwe_syn2 - Q11 ) ); + Copy_Scale_sig_32_16( st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, 2 * ALLPASSSECTIONS_STEEP, ( st->prev_Q_bwe_syn2 - Q11 ) ); swb_CNG_dec_ivas_fx( st, synth_fxl, hb_synth_16_fx[n], sid_bw[n], -q ); - Copy_Scale_sig_16_32(hb_synth_16_fx[n], hb_synth_32_fx[n], L_FRAME48k, (Q11 + q)); - Copy_Scale_sig_16_32(synth_fxl, synth_32_fx[n], L_FRAME48k, (Q11 + q)); - Scale_sig(st->hBWE_TD->state_lpc_syn_fx, LPC_SHB_ORDER, -(Q8 - st->prev_Q_bwe_syn)); - Scale_sig32(st->hBWE_TD->genSHBsynth_Hilbert_Mem_fx, HILBERT_MEM_SIZE, -(st->prev_Q_bwe_syn2 - Q11)); - Copy_Scale_sig_16_32(st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, 2 * ALLPASSSECTIONS_STEEP, -(st->prev_Q_bwe_syn2 - Q11)); + Copy_Scale_sig_16_32( hb_synth_16_fx[n], hb_synth_32_fx[n], L_FRAME48k, ( Q11 + q ) ); + Copy_Scale_sig_16_32( synth_fxl, synth_32_fx[n], L_FRAME48k, ( Q11 + q ) ); + Scale_sig( st->hBWE_TD->state_lpc_syn_fx, LPC_SHB_ORDER, -( Q8 - st->prev_Q_bwe_syn ) ); + Scale_sig32( st->hBWE_TD->genSHBsynth_Hilbert_Mem_fx, HILBERT_MEM_SIZE, -( st->prev_Q_bwe_syn2 - Q11 ) ); + Copy_Scale_sig_16_32( st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, 2 * ALLPASSSECTIONS_STEEP, -( st->prev_Q_bwe_syn2 - Q11 ) ); } /*-------------------------------------------------------------------* * Inter-channel BWE decoding *-------------------------------------------------------------------*/ test(); - IF ( EQ_16(n, 0) && GE_16(st->element_mode, IVAS_CPE_DFT )) + IF( EQ_16( n, 0 ) && GE_16( st->element_mode, IVAS_CPE_DFT ) ) { Word16 q = 11; @@ -1005,14 +1022,14 @@ ivas_error ivas_core_dec( Scale_sig( tmp_buffer_fx, L_FRAME48k, Q11 - Q_white_exc ); stereo_icBWE_dec_fx( hCPE, hb_synth_32_fx[0], hb_synth_32_fx[1], tmp_buffer_fx /*fb_synth_ref*/, voice_factors_fx[0], output_frame, &q ); #ifdef MSAN_FIX - IF( (GT_32( st->core_brate, SID_2k40 ) && ( !( ((EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && EQ_16( hCPE->nchan_out, 1 )) || (( NE_16( st->core, ACELP_CORE ) || EQ_16( st->extl, -1 )) || ( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && NE_16( hCPE->hCoreCoder[0]->tdm_LRTD_flag, 0 ) ) )) ) )) ) + IF( ( GT_32( st->core_brate, SID_2k40 ) && ( !( ( ( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && EQ_16( hCPE->nchan_out, 1 ) ) || ( ( NE_16( st->core, ACELP_CORE ) || EQ_16( st->extl, -1 ) ) || ( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && NE_16( hCPE->hCoreCoder[0]->tdm_LRTD_flag, 0 ) ) ) ) ) ) ) ) { Scale_sig32( hb_synth_32_fx[0], output_frame, sub( Q11, q ) ); Scale_sig32( hb_synth_32_fx[1], output_frame, sub( Q11, q ) ); } #else - Scale_sig32(hb_synth_32_fx[0], L_FRAME48k, sub(Q11 , q)); - Scale_sig32(hb_synth_32_fx[1], L_FRAME48k, sub(Q11 , q)); + Scale_sig32( hb_synth_32_fx[0], L_FRAME48k, sub( Q11, q ) ); + Scale_sig32( hb_synth_32_fx[1], L_FRAME48k, sub( Q11, q ) ); #endif } @@ -1038,18 +1055,21 @@ ivas_error ivas_core_dec( * Transition and synchronization of BWE components *----------------------------------------------------------------*/ - test(); test(); test(); test(); - IF ( ( NE_16(st->extl, -1) && ( NE_16(st->extl, IGF_BWE) || EQ_16(st->last_core, ACELP_CORE) ) ) || ( GT_16(st->bws_cnt, 0) && EQ_16(st->core, ACELP_CORE) ) ) + test(); + test(); + test(); + test(); + IF( ( NE_16( st->extl, -1 ) && ( NE_16( st->extl, IGF_BWE ) || EQ_16( st->last_core, ACELP_CORE ) ) ) || ( GT_16( st->bws_cnt, 0 ) && EQ_16( st->core, ACELP_CORE ) ) ) { /* Calculate an additional delay of extension layer components to be synchronized with ACELP synthesis */ - IF ( EQ_16(st->L_frame, L_FRAME )) + IF( EQ_16( st->L_frame, L_FRAME ) ) { /* TBE on top of ACELP@12.8kHz */ tmps = NS2SA( output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_12k8_NS ); } ELSE { - IF ( EQ_16(st->extl, SWB_BWE_HIGHRATE) || EQ_16(st->extl, FB_BWE_HIGHRATE )) + IF( EQ_16( st->extl, SWB_BWE_HIGHRATE ) || EQ_16( st->extl, FB_BWE_HIGHRATE ) ) { /* HR SWB BWE on top of ACELP@16kHz */ tmps = NS2SA( output_Fs, DELAY_BWE_TOTAL_NS ); @@ -1062,121 +1082,131 @@ ivas_error ivas_core_dec( } /* Smooth transitions when switching between different technologies */ - test(); test(); test(); test(); test(); test(); test(); test(); test(); - - IF ( !( ( EQ_16(st->core, TCX_20_CORE) || EQ_16(st->core, TCX_10_CORE) || EQ_16(st->core, HQ_CORE) ) && EQ_16(st->last_core, ACELP_CORE) ) && - ( NE_16(st->extl, st->last_extl) || ( EQ_16(st->extl, st->last_extl) && ( st->core ^ st->last_core ) == HQ_CORE ) ) && !( EQ_16(st->extl, SWB_CNG) && EQ_16(st->last_extl, SWB_TBE) ) && ( NE_16(st->element_mode, IVAS_CPE_TD) || ( EQ_16(hCPE->element_mode, IVAS_CPE_TD) && tdm_LRTD_flag ) ) ) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + + IF( !( ( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || EQ_16( st->core, HQ_CORE ) ) && EQ_16( st->last_core, ACELP_CORE ) ) && + ( NE_16( st->extl, st->last_extl ) || ( EQ_16( st->extl, st->last_extl ) && ( st->core ^ st->last_core ) == HQ_CORE ) ) && !( EQ_16( st->extl, SWB_CNG ) && EQ_16( st->last_extl, SWB_TBE ) ) && ( NE_16( st->element_mode, IVAS_CPE_TD ) || ( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && tdm_LRTD_flag ) ) ) { /* switching between BWE and TBE technologies */ - incr = idiv1616(L_FRAME * 2, add(shl(tmps, 1), 1)); + incr = idiv1616( L_FRAME * 2, add( shl( tmps, 1 ), 1 ) ); tmp16 = 0; move16(); - FOR ( i = 0; i < tmps; i++ ) + FOR( i = 0; i < tmps; i++ ) { - hb_synth_32_fx[n][i] = Mpy_32_16_1(hb_synth_32_fx[n][i], sin_table256_fx[tmp16]); + hb_synth_32_fx[n][i] = Mpy_32_16_1( hb_synth_32_fx[n][i], sin_table256_fx[tmp16] ); move16(); - tmp16 = add(tmp16, incr); + tmp16 = add( tmp16, incr ); } set16_fx( st->hb_prev_synth_buffer_fx, 0, tmps ); } - ELSE IF ( LT_16(tmps, st->old_bwe_delay )) + ELSE IF( LT_16( tmps, st->old_bwe_delay ) ) { /* the previous frame was TBE on top of ACELP@16kHz and the current frame is TBE on top of ACELP@12.8kHz */ - incr = idiv1616(L_FRAME * 2, add(shl(tmps, 1), 1)); + incr = idiv1616( L_FRAME * 2, add( shl( tmps, 1 ), 1 ) ); tmp16 = 0; move16(); - FOR(i = 0; i < tmps; i++) + FOR( i = 0; i < tmps; i++ ) { - tmp_buffer_fx[i] = round_fx(L_add(L_shr(L_mult(st->hb_prev_synth_buffer_fx[i], sin_table256_fx[255 - tmp16]), 1), L_shr(L_mult(st->hb_prev_synth_buffer_fx[st->old_bwe_delay - 1 - i], sin_table256_fx[tmp16]), 1))); - tmp_buffer_fx[i] = shl_sat(tmp_buffer_fx[i], 1); - tmp16 = add(tmp16, incr); + tmp_buffer_fx[i] = round_fx( L_add( L_shr( L_mult( st->hb_prev_synth_buffer_fx[i], sin_table256_fx[255 - tmp16] ), 1 ), L_shr( L_mult( st->hb_prev_synth_buffer_fx[st->old_bwe_delay - 1 - i], sin_table256_fx[tmp16] ), 1 ) ) ); + tmp_buffer_fx[i] = shl_sat( tmp_buffer_fx[i], 1 ); + tmp16 = add( tmp16, incr ); } - Copy(tmp_buffer_fx, st->hb_prev_synth_buffer_fx, tmps); - + Copy( tmp_buffer_fx, st->hb_prev_synth_buffer_fx, tmps ); } - ELSE IF ( GT_16(tmps, st->old_bwe_delay )) + ELSE IF( GT_16( tmps, st->old_bwe_delay ) ) { /* the previous frame was TBE on top of ACELP@12.8kHz and the current frame is TBE on top of ACELP@16kHz */ - incr = idiv1616(L_FRAME*2, add(shl(st->old_bwe_delay,1),1)); + incr = idiv1616( L_FRAME * 2, add( shl( st->old_bwe_delay, 1 ), 1 ) ); tmp16 = 0; move16(); - FOR (i=0; iold_bwe_delay; i++) + FOR( i = 0; i < st->old_bwe_delay; i++ ) { - tmp_buffer_fx[i] = mult_r(st->hb_prev_synth_buffer_fx[i], sin_table256_fx[255 - tmp16]); + tmp_buffer_fx[i] = mult_r( st->hb_prev_synth_buffer_fx[i], sin_table256_fx[255 - tmp16] ); move16(); - tmp16 = add(tmp16, incr); - + tmp16 = add( tmp16, incr ); } - FOR (; iold_bwe_delay; i++) + FOR( i = 0; i < st->old_bwe_delay; i++ ) { - tmp_buffer_fx[tmps - 1 - i] = round_fx(L_mac(L_mult(tmp_buffer_fx[tmps - 1 - i], 32767), st->hb_prev_synth_buffer_fx[st->old_bwe_delay - 1 - i], sin_table256_fx[tmp16/*i * incr*/])); - tmp16 = add(tmp16, incr); + tmp_buffer_fx[tmps - 1 - i] = round_fx( L_mac( L_mult( tmp_buffer_fx[tmps - 1 - i], 32767 ), st->hb_prev_synth_buffer_fx[st->old_bwe_delay - 1 - i], sin_table256_fx[tmp16 /*i * incr*/] ) ); + tmp16 = add( tmp16, incr ); } Copy( tmp_buffer_fx, st->hb_prev_synth_buffer_fx, tmps ); } - - test(); test(); test(); - IF ( ( NE_16(st->element_mode, IVAS_CPE_TD) && !use_cldfb_for_dft ) || ( EQ_16(hCPE->element_mode, IVAS_CPE_TD) && tdm_LRTD_flag ) ) + + test(); + test(); + test(); + IF( ( NE_16( st->element_mode, IVAS_CPE_TD ) && !use_cldfb_for_dft ) || ( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && tdm_LRTD_flag ) ) { /* Delay hb_synth */ Word32 hb_prev_synth_buffer_fx_32[111]; - Copy_Scale_sig_16_32(st->hb_prev_synth_buffer_fx, hb_prev_synth_buffer_fx_32, 111, 11); + Copy_Scale_sig_16_32( st->hb_prev_synth_buffer_fx, hb_prev_synth_buffer_fx_32, 111, 11 ); delay_signal_fx( hb_synth_32_fx[n], output_frame, hb_prev_synth_buffer_fx_32, tmps ); - Copy_Scale_sig_32_16(hb_prev_synth_buffer_fx_32, st->hb_prev_synth_buffer_fx, 111, -11); + Copy_Scale_sig_32_16( hb_prev_synth_buffer_fx_32, st->hb_prev_synth_buffer_fx, 111, -11 ); } ELSE { - Copy_Scale_sig_32_16(hb_synth_32_fx[n] + output_frame - tmps, st->hb_prev_synth_buffer_fx, tmps,negate(Q11)); + Copy_Scale_sig_32_16( hb_synth_32_fx[n] + output_frame - tmps, st->hb_prev_synth_buffer_fx, tmps, negate( Q11 ) ); } st->old_bwe_delay = tmps; /* SWB CNG/DTX - calculate SHB energy */ - test(); test(); test(); - IF ( GE_16(output_frame, L_FRAME32k) && GT_16(st->extl, SWB_CNG) && EQ_16(st->core, ACELP_CORE) && st->hTdCngDec != NULL ) + test(); + test(); + test(); + IF( GE_16( output_frame, L_FRAME32k ) && GT_16( st->extl, SWB_CNG ) && EQ_16( st->core, ACELP_CORE ) && st->hTdCngDec != NULL ) { Word16 exp, fra; - SWITCH(output_frame) + SWITCH( output_frame ) { - case L_FRAME8k: - tmp16 = 205; - BREAK; /*Q15*/ - case L_FRAME16k: - tmp16 = 102; - BREAK; /*Q15*/ - case L_FRAME32k: - tmp16 = 51; - BREAK; /*Q15*/ - case L_FRAME48k: - tmp16 = 34; - BREAK; /*Q15*/ + case L_FRAME8k: + tmp16 = 205; + BREAK; /*Q15*/ + case L_FRAME16k: + tmp16 = 102; + BREAK; /*Q15*/ + case L_FRAME32k: + tmp16 = 51; + BREAK; /*Q15*/ + case L_FRAME48k: + tmp16 = 34; + BREAK; /*Q15*/ } - L_tmp = L_deposit_l(2); /*0.001 in Q11*/ + L_tmp = L_deposit_l( 2 ); /*0.001 in Q11*/ - Word16 gb = find_guarded_bits_fx(output_frame); - L_tmp = L_add(L_tmp, sum2_f_32_fx(hb_synth_32_fx[n], output_frame, sub(11, gb))); - L_tmp = Mpy_32_16_1(L_tmp , tmp16); - exp = norm_l(L_tmp); - fra = Log2_norm_lc(L_shl(L_tmp, exp)); - exp = sub(sub(30, shl(sub(Q11, 0), 1)), exp); - L_tmp = Mpy_32_16(exp, fra, LG10); - st->last_shb_ener_fx = round_fx_sat(L_shl_sat(L_tmp, 10)); /*Q8*/ + Word16 gb = find_guarded_bits_fx( output_frame ); + L_tmp = L_add( L_tmp, sum2_f_32_fx( hb_synth_32_fx[n], output_frame, sub( 11, gb ) ) ); + L_tmp = Mpy_32_16_1( L_tmp, tmp16 ); + exp = norm_l( L_tmp ); + fra = Log2_norm_lc( L_shl( L_tmp, exp ) ); + exp = sub( sub( 30, shl( sub( Q11, 0 ), 1 ) ), exp ); + L_tmp = Mpy_32_16( exp, fra, LG10 ); + st->last_shb_ener_fx = round_fx_sat( L_shl_sat( L_tmp, 10 ) ); /*Q8*/ } } test(); - IF ( sba_dirac_stereo_flag && NE_16(st->element_mode, IVAS_CPE_MDCT )) + IF( sba_dirac_stereo_flag && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { /* for SBA DirAC stereo output DFT Stereo core switching and updates are done in ivas_sba_dirac_stereo_dec() as hCPE is not available at this point */ break; @@ -1188,19 +1218,19 @@ ivas_error ivas_core_dec( * - core switching in DFT stereo * - updates for potential TD->DFT stereo switching *----------------------------------------------------------------*/ - if (hCPE != NULL) + if ( hCPE != NULL ) { - FOR(int ch_ind = 0; ch_ind < n_channels; ch_ind++) - { - if (hCPE->hCoreCoder[ch_ind] != NULL) + FOR( int ch_ind = 0; ch_ind < n_channels; ch_ind++ ) { - if (hCPE->hCoreCoder[ch_ind]->hHQ_core != NULL) - { - Copy_Scale_sig_16_32(hCPE->hCoreCoder[ch_ind]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[ch_ind]->hHQ_core->old_outLB_fx, L_FRAME32k, Q11 - hCPE->hCoreCoder[ch_ind]->hHQ_core->Q_old_wtda_LB); - Copy_Scale_sig_16_32(hCPE->hCoreCoder[ch_ind]->hHQ_core->old_out_fx, hCPE->hCoreCoder[ch_ind]->hHQ_core->oldOut_fx, L_FRAME48k, Q11 - hCPE->hCoreCoder[ch_ind]->hHQ_core->Q_old_wtda); - } + if ( hCPE->hCoreCoder[ch_ind] != NULL ) + { + if ( hCPE->hCoreCoder[ch_ind]->hHQ_core != NULL ) + { + Copy_Scale_sig_16_32( hCPE->hCoreCoder[ch_ind]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[ch_ind]->hHQ_core->old_outLB_fx, L_FRAME32k, Q11 - hCPE->hCoreCoder[ch_ind]->hHQ_core->Q_old_wtda_LB ); + Copy_Scale_sig_16_32( hCPE->hCoreCoder[ch_ind]->hHQ_core->old_out_fx, hCPE->hCoreCoder[ch_ind]->hHQ_core->oldOut_fx, L_FRAME48k, Q11 - hCPE->hCoreCoder[ch_ind]->hHQ_core->Q_old_wtda ); + } + } } - } } if ( hSCE != NULL ) { @@ -1217,18 +1247,18 @@ ivas_error ivas_core_dec( Word16 exp_max = 0; Word32 output_fx_loc[L_FRAME48k]; - IF ( NE_16(st->element_mode, IVAS_CPE_DFT )) + IF( NE_16( st->element_mode, IVAS_CPE_DFT ) ) { - IF ( NE_16(st->element_mode, IVAS_CPE_MDCT) || sba_dirac_stereo_flag ) + IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) || sba_dirac_stereo_flag ) { ivas_post_proc_fx( hSCE, hCPE, n, synth_32_fx[n], NULL, output_frame, sba_dirac_stereo_flag ); } /* update OLA buffers - needed for switching to DFT stereo */ - IF ( !sba_dirac_stereo_flag ) + IF( !sba_dirac_stereo_flag ) { - IF ( hCPE != NULL ) + IF( hCPE != NULL ) { stereo_td2dft_update_fx( hCPE, n, output_32_fx[n], synth_32_fx[n], hb_synth_32_fx[n], output_frame ); } @@ -1237,7 +1267,7 @@ ivas_error ivas_core_dec( ELSE /* IVAS_CPE_DFT */ { Word16 q = 11; - IF ( EQ_16(hCPE->last_element_mode, IVAS_CPE_MDCT )) + IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) ) { stereo_mdct2dft_update_fx( hCPE, output_32_fx[0], synth_32_fx[0] ); } @@ -1249,8 +1279,8 @@ ivas_error ivas_core_dec( IF( DFT_fx != NULL ) { - Scale_sig32( DFT_fx[0], STEREO_DFT_BUF_MAX, sub(hCPE->hStereoDft->q_dft , q_DFT[0]) ); - Scale_sig32( DFT_fx[1], STEREO_DFT_BUF_MAX, sub(hCPE->hStereoDft->q_dft , q_DFT[1]) ); + Scale_sig32( DFT_fx[0], STEREO_DFT_BUF_MAX, sub( hCPE->hStereoDft->q_dft, q_DFT[0] ) ); + Scale_sig32( DFT_fx[1], STEREO_DFT_BUF_MAX, sub( hCPE->hStereoDft->q_dft, q_DFT[1] ) ); } IF( EQ_16( hCPE->nchan_out, 1 ) && EQ_16( hCPE->hStereoDft->hConfig->res_cod_mode, STEREO_DFT_RES_COD_OFF ) ) @@ -1265,41 +1295,54 @@ ivas_error ivas_core_dec( /*--------------------------------------------------------* * Common updates *--------------------------------------------------------*/ - + /*Scale Memories*/ - test(); test(); test(); test(); test(); - IF ((EQ_16(st->codec_mode, MODE1) && st->hTcxDec != NULL) && ((EQ_16(st->core, ACELP_CORE) && !(EQ_16(st->bfi, 1) && EQ_16(st->con_tcx, 1))) || EQ_16(st->core, HQ_CORE))) + test(); + test(); + test(); + test(); + test(); + IF( ( EQ_16( st->codec_mode, MODE1 ) && st->hTcxDec != NULL ) && ( ( EQ_16( st->core, ACELP_CORE ) && !( EQ_16( st->bfi, 1 ) && EQ_16( st->con_tcx, 1 ) ) ) || EQ_16( st->core, HQ_CORE ) ) ) { - Word16 exp_prev_synth_buffer = 0, exp_old_out = 0, exp_delay_buf_out = 0, exp_ouput = 0, exp_synth_history = 0/*, temp = 0*/; move16(); move16(); move16(); move16(); move16(); move16(); + Word16 exp_prev_synth_buffer = 0, exp_old_out = 0, exp_delay_buf_out = 0, exp_ouput = 0, exp_synth_history = 0 /*, temp = 0*/; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); - Copy_Scale_sig32_16( st->prev_synth_buffer32_fx, st->prev_synth_buffer_fx, NS2SA( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), -11 ); - st->q_prev_synth_buffer_fx = 0; + Copy_Scale_sig32_16( st->prev_synth_buffer32_fx, st->prev_synth_buffer_fx, NS2SA( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), -11 ); + st->q_prev_synth_buffer_fx = 0; - exp_ouput = Find_Max_Norm32(output_32_fx[n], output_frame); - exp_ouput += 11; - exp_prev_synth_buffer = Find_Max_Norm16(st->prev_synth_buffer_fx, NS2SA(48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS)); - exp_prev_synth_buffer += st->q_prev_synth_buffer_fx; - exp_old_out = Find_Max_Norm16(st->hHQ_core->old_out_fx + NS2SA(st->output_Fs, N_ZERO_MDCT_NS), NS2SA(st->output_Fs, N_ZERO_MDCT_NS) + NS2SA(st->output_Fs, PH_ECU_LOOKAHEAD_NS) - NS2SA(st->output_Fs, N_ZERO_MDCT_NS)); - exp_delay_buf_out = Find_Max_Norm16(st->delay_buf_out_fx, NS2SA(st->output_Fs, DELAY_CLDFB_NS)); - exp_synth_history = Find_Max_Norm16(st->hTcxDec->synth_history_fx + output_frame, 2 * output_frame - NS2SA(st->output_Fs, DELAY_CLDFB_NS) + NS2SA(st->output_Fs, PH_ECU_MEM_NS) - output_frame); + exp_ouput = Find_Max_Norm32( output_32_fx[n], output_frame ); + exp_ouput += 11; + exp_prev_synth_buffer = Find_Max_Norm16( st->prev_synth_buffer_fx, NS2SA( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) ); + exp_prev_synth_buffer += st->q_prev_synth_buffer_fx; + exp_old_out = Find_Max_Norm16( st->hHQ_core->old_out_fx + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), NS2SA( st->output_Fs, N_ZERO_MDCT_NS ) + NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) - NS2SA( st->output_Fs, N_ZERO_MDCT_NS ) ); + exp_delay_buf_out = Find_Max_Norm16( st->delay_buf_out_fx, NS2SA( st->output_Fs, DELAY_CLDFB_NS ) ); + exp_synth_history = Find_Max_Norm16( st->hTcxDec->synth_history_fx + output_frame, 2 * output_frame - NS2SA( st->output_Fs, DELAY_CLDFB_NS ) + NS2SA( st->output_Fs, PH_ECU_MEM_NS ) - output_frame ); #ifndef FIX_740_HQ_CORE_OVA - exp_synth_history += st->hTcxDec->q_synth_history_fx; + exp_synth_history += st->hTcxDec->q_synth_history_fx; #endif - exp_max = s_min(exp_synth_history, exp_ouput); - exp_max = s_min(exp_max, exp_prev_synth_buffer); move16(); - exp_max = s_min(exp_max, exp_old_out); move16(); - exp_max = s_min(exp_max, exp_delay_buf_out); move16(); + exp_max = s_min( exp_synth_history, exp_ouput ); + exp_max = s_min( exp_max, exp_prev_synth_buffer ); + move16(); + exp_max = s_min( exp_max, exp_old_out ); + move16(); + exp_max = s_min( exp_max, exp_delay_buf_out ); + move16(); - Copy32(output_32_fx[n], output_fx_loc, output_frame); + Copy32( output_32_fx[n], output_fx_loc, output_frame ); - Scale_sig32(output_fx_loc, output_frame, exp_max - 11); - Scale_sig(st->delay_buf_out_fx, NS2SA(st->output_Fs, DELAY_CLDFB_NS), exp_max - 0); - Scale_sig(st->hHQ_core->old_out_fx + NS2SA(st->output_Fs, N_ZERO_MDCT_NS), NS2SA(st->output_Fs, PH_ECU_LOOKAHEAD_NS) - NS2SA(st->output_Fs, N_ZERO_MDCT_NS), exp_max - 0); - Scale_sig(st->prev_synth_buffer_fx, NS2SA(48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS), exp_max - st->q_prev_synth_buffer_fx); - Scale_sig(st->hTcxDec->synth_history_fx + output_frame, 2 * output_frame - NS2SA(st->output_Fs, DELAY_CLDFB_NS) + NS2SA(st->output_Fs, PH_ECU_MEM_NS) - output_frame, exp_max - st->Q_syn); + Scale_sig32( output_fx_loc, output_frame, exp_max - 11 ); + Scale_sig( st->delay_buf_out_fx, NS2SA( st->output_Fs, DELAY_CLDFB_NS ), exp_max - 0 ); + Scale_sig( st->hHQ_core->old_out_fx + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) - NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), exp_max - 0 ); + Scale_sig( st->prev_synth_buffer_fx, NS2SA( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), exp_max - st->q_prev_synth_buffer_fx ); + Scale_sig( st->hTcxDec->synth_history_fx + output_frame, 2 * output_frame - NS2SA( st->output_Fs, DELAY_CLDFB_NS ) + NS2SA( st->output_Fs, PH_ECU_MEM_NS ) - output_frame, exp_max - st->Q_syn ); - st->q_prev_synth_buffer_fx = exp_max - st->q_prev_synth_buffer_fx; + st->q_prev_synth_buffer_fx = exp_max - st->q_prev_synth_buffer_fx; } /* Save synthesis for HQ FEC */ save_synthesis_hq_fec_fx( st, output_fx_loc, output_frame, hCPE ); @@ -1312,17 +1355,17 @@ ivas_error ivas_core_dec( } /* n_channels loop */ - FOR(n = 0; n < n_channels; n++) + FOR( n = 0; n < n_channels; n++ ) { st = sts[n]; - IF(st->cldfbAna) + IF( st->cldfbAna ) { - scale_sig32(st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, sub(Q11, Q10)); + scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, sub( Q11, Q10 ) ); st->cldfbAna->Q_cldfb_state = Q11; } - IF(st->cldfbSynHB) + IF( st->cldfbSynHB ) { - scale_sig32(st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->cldfb_size, sub(Q11, Q10)); + scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->cldfb_size, sub( Q11, Q10 ) ); st->cldfbSynHB->Q_cldfb_state = Q11; } } @@ -1508,7 +1551,7 @@ ivas_error ivas_core_dec( int16_t ovl, fade_len; if ( sts[0]->L_frame != sts[0]->last_L_frame ) { - lerp_flt( sts[0]->hHQ_core->old_outLB, sts[0]->hHQ_core->old_outLB, sts[0]->L_frame, sts[0]->last_L_frame ); + lerp_flt( sts[0]->hHQ_core->old_outLB, sts[0]->hHQ_core->old_outLB, sts[0]->L_frame, sts[0]->last_L_frame ); } if ( sts[0]->L_frame != L_FRAME16k ) { @@ -1687,7 +1730,7 @@ ivas_error ivas_core_dec( { if ( sts[n]->last_core_bfi != ACELP_CORE ) { - TonalMdctConceal_whiten_noise_shape_ivas( sts[n], L_FRAME16k, ON_FIRST_GOOD_FRAME ); + TonalMdctConceal_whiten_noise_shape_ivas( sts[n], L_FRAME16k, ON_FIRST_GOOD_FRAME ); } } } @@ -1926,7 +1969,7 @@ ivas_error ivas_core_dec( if ( ( st->element_mode != IVAS_CPE_TD && !use_cldfb_for_dft ) || ( hCPE->element_mode == IVAS_CPE_TD && tdm_LRTD_flag ) ) { /* Delay hb_synth */ - delay_signal_float( hb_synth[n], output_frame, st->hb_prev_synth_buffer, tmps ); + delay_signal_float( hb_synth[n], output_frame, st->hb_prev_synth_buffer, tmps ); } else { diff --git a/lib_dec/ivas_corecoder_dec_reconfig.c b/lib_dec/ivas_corecoder_dec_reconfig.c index 9a2b56c17..87c1c17b0 100644 --- a/lib_dec/ivas_corecoder_dec_reconfig.c +++ b/lib_dec/ivas_corecoder_dec_reconfig.c @@ -401,7 +401,7 @@ ivas_error ivas_corecoder_dec_reconfig_fx( } set32_fx( st_ivas->hSCE[0]->save_synth_fx, 0, output_frame ); st_ivas->hSCE[0]->q_save_synth_fx = 0; - //st_ivas->hSCE[0]->q_save_synth_fx = Q11; + // st_ivas->hSCE[0]->q_save_synth_fx = Q11; move16(); } @@ -769,7 +769,7 @@ ivas_error ivas_corecoder_dec_reconfig( #ifdef IVAS_FLOAT_FIXED ivas_error ivas_hp20_dec_reconfig_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const Word16 nchan_hp20_old /* i : number of HP20 filters in previous frame */ ) { @@ -785,54 +785,54 @@ ivas_error ivas_hp20_dec_reconfig_fx( nchan_hp20 = getNumChanSynthesis( st_ivas ); - IF ( GT_16(nchan_hp20 , nchan_hp20_old) ) + IF( GT_16( nchan_hp20, nchan_hp20_old ) ) { /* save old mem_hp_20 pointer */ old_mem_hp20_out_fx = st_ivas->mem_hp20_out_fx; st_ivas->mem_hp20_out_fx = NULL; - IF ( ( st_ivas->mem_hp20_out_fx = (Word32 **) malloc( nchan_hp20 * sizeof( Word32 * ) ) ) == NULL ) + IF( ( st_ivas->mem_hp20_out_fx = (Word32 **) malloc( nchan_hp20 * sizeof( Word32 * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); } - FOR ( i = 0; i < nchan_hp20_old; i++ ) + FOR( i = 0; i < nchan_hp20_old; i++ ) { st_ivas->mem_hp20_out_fx[i] = old_mem_hp20_out_fx[i]; old_mem_hp20_out_fx[i] = NULL; } /* create additional hp20 memories */ - FOR ( ; i < nchan_hp20; i++ ) + FOR( ; i < nchan_hp20; i++ ) { - IF ( ( st_ivas->mem_hp20_out_fx[i] = (Word32 *) malloc( (L_HP20_MEM + 2) * sizeof( Word32 ) ) ) == NULL ) + IF( ( st_ivas->mem_hp20_out_fx[i] = (Word32 *) malloc( ( L_HP20_MEM + 2 ) * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); } - set32_fx( st_ivas->mem_hp20_out_fx[i], 0, L_HP20_MEM + 2); + set32_fx( st_ivas->mem_hp20_out_fx[i], 0, L_HP20_MEM + 2 ); } free( old_mem_hp20_out_fx ); old_mem_hp20_out_fx = NULL; } - ELSE IF ( LT_16(nchan_hp20 , nchan_hp20_old) ) + ELSE IF( LT_16( nchan_hp20, nchan_hp20_old ) ) { /* save old mem_hp_20 pointer */ old_mem_hp20_out_fx = st_ivas->mem_hp20_out_fx; st_ivas->mem_hp20_out_fx = NULL; - IF ( ( st_ivas->mem_hp20_out_fx = (Word32 **) malloc( nchan_hp20 * sizeof(Word32 * ) ) ) == NULL ) + IF( ( st_ivas->mem_hp20_out_fx = (Word32 **) malloc( nchan_hp20 * sizeof( Word32 * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); } - FOR ( i = 0; i < nchan_hp20; i++ ) + FOR( i = 0; i < nchan_hp20; i++ ) { st_ivas->mem_hp20_out_fx[i] = old_mem_hp20_out_fx[i]; old_mem_hp20_out_fx[i] = NULL; } /* remove superfluous hp20 memories */ - FOR ( ; i < nchan_hp20_old; i++ ) + FOR( ; i < nchan_hp20_old; i++ ) { free( old_mem_hp20_out_fx[i] ); old_mem_hp20_out_fx[i] = NULL; @@ -930,7 +930,7 @@ ivas_error ivas_hp20_dec_reconfig( *-------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED ivas_error ivas_cldfb_dec_reconfig_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const Word16 nchan_transport_old, /* i : number of TCs in previous frame */ Word16 numCldfbAnalyses_old, /* i : number of CLDFB analysis instances in previous frame */ const Word16 numCldfbSyntheses_old /* i : number of CLDFB synthesis instances in previous frame */ @@ -946,7 +946,7 @@ ivas_error ivas_cldfb_dec_reconfig_fx( /* special case, if there was one transport channel in the previous frame and more than one in the current frame, remove the second CLDFB here, it was for CNA/CNG */ - IF ( EQ_16(st_ivas->ivas_format , SBA_FORMAT) && EQ_16(nchan_transport_old , 1) && EQ_16(numCldfbAnalyses_old , 2) && GT_16(st_ivas->nchan_transport , 1) ) + IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) && EQ_16( nchan_transport_old, 1 ) && EQ_16( numCldfbAnalyses_old, 2 ) && GT_16( st_ivas->nchan_transport, 1 ) ) { deleteCldfb_ivas( &( st_ivas->cldfbAnaDec[1] ) ); numCldfbAnalyses_old--; @@ -954,61 +954,61 @@ ivas_error ivas_cldfb_dec_reconfig_fx( /* resample CLDFB analysis instances */ FOR( i = 0; i < min( numCldfbAnalyses, numCldfbAnalyses_old ); i++ ) { - IF( NE_32( L_mult0( extract_l(L_mult0( st_ivas->cldfbAnaDec[i]->no_channels, st_ivas->cldfbAnaDec[i]->no_col )), FRAMES_PER_SEC ), hDecoderConfig->output_Fs ) ) + IF( NE_32( L_mult0( extract_l( L_mult0( st_ivas->cldfbAnaDec[i]->no_channels, st_ivas->cldfbAnaDec[i]->no_col ) ), FRAMES_PER_SEC ), hDecoderConfig->output_Fs ) ) { resampleCldfb_ivas_fx( st_ivas->cldfbAnaDec[i], hDecoderConfig->output_Fs ); } } /* Analysis*/ - IF ( GT_16(numCldfbAnalyses_old , numCldfbAnalyses) ) + IF( GT_16( numCldfbAnalyses_old, numCldfbAnalyses ) ) { /* delete superfluous CLDFB synthesis instances */ - FOR ( i = numCldfbAnalyses; i < numCldfbAnalyses_old; i++ ) + FOR( i = numCldfbAnalyses; i < numCldfbAnalyses_old; i++ ) { deleteCldfb_ivas( &( st_ivas->cldfbAnaDec[i] ) ); } } - ELSE IF ( LT_16(numCldfbAnalyses_old , numCldfbAnalyses) ) + ELSE IF( LT_16( numCldfbAnalyses_old, numCldfbAnalyses ) ) { /* create additional CLDFB synthesis instances */ - FOR ( i = numCldfbAnalyses_old; i < numCldfbAnalyses; i++ ) + FOR( i = numCldfbAnalyses_old; i < numCldfbAnalyses; i++ ) { - IF ( ( error = openCldfb_ivas_fx( &( st_ivas->cldfbAnaDec[i] ), CLDFB_ANALYSIS, hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) + IF( ( error = openCldfb_ivas_fx( &( st_ivas->cldfbAnaDec[i] ), CLDFB_ANALYSIS, hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) { return error; } } } /* Synthesis */ - IF ( GT_16(numCldfbSyntheses_old , numCldfbSyntheses) ) + IF( GT_16( numCldfbSyntheses_old, numCldfbSyntheses ) ) { /* delete superfluous CLDFB synthesis instances */ - FOR ( i = numCldfbSyntheses; i < numCldfbSyntheses_old; i++ ) + FOR( i = numCldfbSyntheses; i < numCldfbSyntheses_old; i++ ) { deleteCldfb_ivas( &( st_ivas->cldfbSynDec[i] ) ); } } - ELSE IF ( LT_16(numCldfbSyntheses_old , numCldfbSyntheses) ) + ELSE IF( LT_16( numCldfbSyntheses_old, numCldfbSyntheses ) ) { /* create additional CLDFB synthesis instances */ - FOR ( i = numCldfbSyntheses_old; i < numCldfbSyntheses; i++ ) + FOR( i = numCldfbSyntheses_old; i < numCldfbSyntheses; i++ ) { - IF ( ( error = openCldfb_ivas_fx( &( st_ivas->cldfbSynDec[i] ), CLDFB_SYNTHESIS, hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) + IF( ( error = openCldfb_ivas_fx( &( st_ivas->cldfbSynDec[i] ), CLDFB_SYNTHESIS, hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) { return error; } } } /* CLDFB Interpolation weights */ - IF ( EQ_16(st_ivas->ivas_format , SBA_FORMAT) && ( NE_16(numCldfbAnalyses_old , numCldfbAnalyses) || NE_16(numCldfbSyntheses_old , numCldfbSyntheses) || NE_16(nchan_transport_old , st_ivas->nchan_transport) ) && NE_16(numCldfbAnalyses , 0) && NE_16(numCldfbSyntheses , 0) ) + IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) && ( NE_16( numCldfbAnalyses_old, numCldfbAnalyses ) || NE_16( numCldfbSyntheses_old, numCldfbSyntheses ) || NE_16( nchan_transport_old, st_ivas->nchan_transport ) ) && NE_16( numCldfbAnalyses, 0 ) && NE_16( numCldfbSyntheses, 0 ) ) { ivas_spar_get_cldfb_gains_fx( st_ivas->hSpar, st_ivas->cldfbAnaDec[0], st_ivas->cldfbSynDec[0], hDecoderConfig ); FOR( i = 0; i < st_ivas->cldfbAnaDec[0]->cldfb_state_length; i++ ) - st_ivas->cldfbAnaDec[0]->cldfb_state_fx[i] = L_shr( st_ivas->cldfbAnaDec[0]->cldfb_state_fx[i], 16 ); // Scaling down from 27 to 11 + st_ivas->cldfbAnaDec[0]->cldfb_state_fx[i] = L_shr( st_ivas->cldfbAnaDec[0]->cldfb_state_fx[i], 16 ); // Scaling down from 27 to 11 st_ivas->cldfbAnaDec[0]->Q_cldfb_state = Q11; FOR( i = 0; i < st_ivas->cldfbSynDec[0]->cldfb_state_length; i++ ) - st_ivas->cldfbSynDec[0]->cldfb_state_fx[i] = L_shr( st_ivas->cldfbSynDec[0]->cldfb_state_fx[i], 21 - 11); // Scaling down from 21 to 11 + st_ivas->cldfbSynDec[0]->cldfb_state_fx[i] = L_shr( st_ivas->cldfbSynDec[0]->cldfb_state_fx[i], 21 - 11 ); // Scaling down from 21 to 11 st_ivas->cldfbSynDec[0]->Q_cldfb_state = Q11; } return IVAS_ERR_OK; diff --git a/lib_dec/ivas_cpe_dec.c b/lib_dec/ivas_cpe_dec.c index 0bcb595dc..4faab3eb7 100644 --- a/lib_dec/ivas_cpe_dec.c +++ b/lib_dec/ivas_cpe_dec.c @@ -684,7 +684,6 @@ ivas_error create_cpe_dec( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DFT stereo memory\n" ) ); } set_zero( hCPE->input_mem_BPF[0], STEREO_DFT32MS_OVL_16k ); - } if ( ( hCPE->output_mem[i] = (float *) malloc( sizeof( float ) * NS2SA( output_Fs, STEREO_DFT32MS_OVL_NS ) ) ) == NULL ) @@ -949,7 +948,6 @@ void destroy_cpe_dec( } free( hCPE->input_mem_BPF[0] ); hCPE->input_mem_BPF[0] = NULL; - } if ( hCPE->hStereoCng != NULL ) diff --git a/lib_dec/ivas_cpe_dec_fx.c b/lib_dec/ivas_cpe_dec_fx.c index 5ffceb2c1..4ff50cb31 100644 --- a/lib_dec/ivas_cpe_dec_fx.c +++ b/lib_dec/ivas_cpe_dec_fx.c @@ -120,11 +120,11 @@ ivas_error ivas_cpe_dec_fx( * dynamically allocate data structures depending on the actual stereo mode *----------------------------------------------------------------*/ -#if 1 // Float to fix conversions +#if 1 // Float to fix conversions Word16 q_old_out_LB = 31; - //q_output_mem = 11; - //q_buff_LBTCX_mem = 11; - //q_input_mem_LB = q_buff_LBTCX_mem; + // q_output_mem = 11; + // q_buff_LBTCX_mem = 11; + // q_input_mem_LB = q_buff_LBTCX_mem; FOR( Word16 ind1 = 0; ind1 < 2; ind1++ ) { IF( hCPE->hCoreCoder[ind1] && hCPE->hCoreCoder[ind1]->hHQ_core ) @@ -132,7 +132,7 @@ ivas_error ivas_cpe_dec_fx( Copy_Scale_sig_16_32( hCPE->hCoreCoder[ind1]->hHQ_core->old_out_fx, hCPE->hCoreCoder[ind1]->hHQ_core->oldOut_fx, L_FRAME48k, Q11 - hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_wtda ); } } - q_old_out_LB = Q11; + q_old_out_LB = Q11; FOR( Word16 ind1 = 0; ind1 < 1; ind1++ ) { IF( hCPE->hCoreCoder[ind1]->hHQ_core ) @@ -141,7 +141,7 @@ ivas_error ivas_cpe_dec_fx( hCPE->hCoreCoder[ind1]->hHQ_core->q_old_outLB_fx = q_old_out_LB; } } - //q_tcxltp_mem_in_float = 11; + // q_tcxltp_mem_in_float = 11; FOR( Word16 ind2 = 0; ind2 < 2; ind2++ ) { IF( hCPE->hCoreCoder[ind2] && hCPE->hCoreCoder[ind2]->cldfbSyn ) @@ -153,7 +153,7 @@ ivas_error ivas_cpe_dec_fx( { return error; } -#if 1 // Fix to float conversions +#if 1 // Fix to float conversions FOR( Word16 ind1 = 0; ind1 < 2; ind1++ ) { IF( hCPE->hCoreCoder[ind1] && hCPE->hCoreCoder[ind1]->hHQ_core ) @@ -602,7 +602,7 @@ ivas_error ivas_cpe_dec_fx( q_dft = hCPE->hStereoDft->q_dft; - //TODO : To check this + // TODO : To check this stereo_dtf_cng_fx( hCPE, ivas_total_brate, DFT_fx, output_frame, q_dft ); } @@ -614,7 +614,7 @@ ivas_error ivas_cpe_dec_fx( IF( EQ_16( hCPE->hStereoDft->first_frame, 1 ) ) { hCPE->hStereoDft->q_smoothed_nrg = hCPE->hStereoDft->q_dft; - FOR( int ii = 0; ii < (int) ( sizeof( hCPE->hStereoDft->q_DFT_past_DMX_fx ) / sizeof( hCPE->hStereoDft->q_DFT_past_DMX_fx[0] )); ii++ ) + FOR( int ii = 0; ii < (int) ( sizeof( hCPE->hStereoDft->q_DFT_past_DMX_fx ) / sizeof( hCPE->hStereoDft->q_DFT_past_DMX_fx[0] ) ); ii++ ) { hCPE->hStereoDft->q_DFT_past_DMX_fx[ii] = hCPE->hStereoDft->q_dft; } @@ -637,7 +637,7 @@ ivas_error ivas_cpe_dec_fx( IF( EQ_16( hCPE->hStereoDft->first_frame, 1 ) ) { hCPE->hStereoDft->q_smoothed_nrg = hCPE->hStereoDft->q_dft; - FOR( int ii = 0; ii < (int) (sizeof( hCPE->hStereoDft->q_DFT_past_DMX_fx ) / sizeof( hCPE->hStereoDft->q_DFT_past_DMX_fx[0] )); ii++ ) + FOR( int ii = 0; ii < (int) ( sizeof( hCPE->hStereoDft->q_DFT_past_DMX_fx ) / sizeof( hCPE->hStereoDft->q_DFT_past_DMX_fx[0] ) ); ii++ ) { hCPE->hStereoDft->q_DFT_past_DMX_fx[ii] = hCPE->hStereoDft->q_dft; } @@ -718,8 +718,8 @@ ivas_error ivas_cpe_dec_fx( // Delete below IF( hCPE->hStereoDft != NULL ) { - //Word16 q_td_gain = Q_factor_arr( hCPE->hStereoDft->td_gain, STEREO_DFT_CORE_HIST_MAX ); - //floatToFixed_arrL( hCPE->hStereoDft->td_gain, hCPE->hStereoDft->td_gain_fx, q_td_gain, STEREO_DFT_CORE_HIST_MAX ); // Checking this. + // Word16 q_td_gain = Q_factor_arr( hCPE->hStereoDft->td_gain, STEREO_DFT_CORE_HIST_MAX ); + // floatToFixed_arrL( hCPE->hStereoDft->td_gain, hCPE->hStereoDft->td_gain_fx, q_td_gain, STEREO_DFT_CORE_HIST_MAX ); // Checking this. } //////Till here @@ -761,8 +761,8 @@ ivas_error ivas_cpe_dec_fx( // delete below IF( hCPE->hStereoDft != NULL ) { - //Word16 q_td_gain = Q_factor_arr( hCPE->hStereoDft->td_gain, STEREO_DFT_CORE_HIST_MAX ); - //fixedToFloat_arrL( hCPE->hStereoDft->td_gain_fx, hCPE->hStereoDft->td_gain, q_td_gain, STEREO_DFT_CORE_HIST_MAX ); // Checking this. + // Word16 q_td_gain = Q_factor_arr( hCPE->hStereoDft->td_gain, STEREO_DFT_CORE_HIST_MAX ); + // fixedToFloat_arrL( hCPE->hStereoDft->td_gain_fx, hCPE->hStereoDft->td_gain, q_td_gain, STEREO_DFT_CORE_HIST_MAX ); // Checking this. } /*----------------------------------------------------------------* @@ -848,7 +848,7 @@ ivas_error create_cpe_dec( hCPE->stereo_switching_counter = 10; hCPE->NbFrameMod = 7; - //hCPE->lt_es_em = 0.0f; + // hCPE->lt_es_em = 0.0f; hCPE->lt_es_em_fx = 0; /* Note: nchan_out is considered to be related to the structure. This is nchan_out for CPE and for MASA_format is always 2. */ @@ -985,145 +985,141 @@ ivas_error create_cpe_dec( * DFT stereo initialization *-----------------------------------------------------------------*/ - IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) || ( st_ivas->sba_dirac_stereo_flag && EQ_16( hCPE->cpe_id, 0 ) ) ) - { + IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) || ( st_ivas->sba_dirac_stereo_flag && EQ_16( hCPE->cpe_id, 0 ) ) ){ #ifdef IVAS_FLOAT_FIXED - IF( ( error = stereo_dft_dec_create_fx( &( hCPE->hStereoDft ), hCPE->element_brate, output_Fs, st_ivas->sba_dirac_stereo_flag, st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) - { + IF( ( error = stereo_dft_dec_create_fx( &( hCPE->hStereoDft ), hCPE->element_brate, output_Fs, st_ivas->sba_dirac_stereo_flag, st_ivas->nchan_transport ) ) != IVAS_ERR_OK ){ return error; - } +} #else - IF( ( error = stereo_dft_dec_create( &( hCPE->hStereoDft ), hCPE->element_brate, output_Fs, st_ivas->sba_dirac_stereo_flag, st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) - { + IF( ( error = stereo_dft_dec_create( &( hCPE->hStereoDft ), hCPE->element_brate, output_Fs, st_ivas->sba_dirac_stereo_flag, st_ivas->nchan_transport ) ) != IVAS_ERR_OK ){ return error; - } +} #endif - } +} - /*-----------------------------------------------------------------* - * DFT stereo mono DMX initialization - *-----------------------------------------------------------------*/ +/*-----------------------------------------------------------------* + * DFT stereo mono DMX initialization + *-----------------------------------------------------------------*/ - IF( NE_16( hCPE->element_mode, IVAS_CPE_MDCT ) && EQ_16( hCPE->nchan_out, 1 ) ) +IF( NE_16( hCPE->element_mode, IVAS_CPE_MDCT ) && EQ_16( hCPE->nchan_out, 1 ) ) +{ + IF( ( hCPE->hStereoDftDmx = (STEREO_DFT_DMX_DATA_HANDLE) malloc( sizeof( STEREO_DFT_DMX_DATA ) ) ) == NULL ) { - IF( ( hCPE->hStereoDftDmx = (STEREO_DFT_DMX_DATA_HANDLE) malloc( sizeof( STEREO_DFT_DMX_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo DFT mono output\n" ) ); - } + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo DFT mono output\n" ) ); + } #ifdef IVAS_FLOAT_FIXED - stereo_dft_dmx_out_reset_fx(hCPE->hStereoDftDmx); + stereo_dft_dmx_out_reset_fx( hCPE->hStereoDftDmx ); #else - stereo_dft_dmx_out_reset( hCPE->hStereoDftDmx ); + stereo_dft_dmx_out_reset( hCPE->hStereoDftDmx ); #endif - } +} - /*-----------------------------------------------------------------* - * Temporal inter-channel alignment initialization - *-----------------------------------------------------------------*/ +/*-----------------------------------------------------------------* + * Temporal inter-channel alignment initialization + *-----------------------------------------------------------------*/ - IF( ( NE_16( hCPE->element_mode, IVAS_CPE_MDCT ) || ( EQ_16( (Word16) st_ivas->ivas_format, STEREO_FORMAT ) && LE_32( hCPE->element_brate, MAX_MDCT_ITD_BRATE ) ) ) && NE_16( hCPE->nchan_out, 1 ) ) +IF( ( NE_16( hCPE->element_mode, IVAS_CPE_MDCT ) || ( EQ_16( (Word16) st_ivas->ivas_format, STEREO_FORMAT ) && LE_32( hCPE->element_brate, MAX_MDCT_ITD_BRATE ) ) ) && NE_16( hCPE->nchan_out, 1 ) ) +{ + IF( ( hCPE->hStereoTCA = (STEREO_TCA_DEC_HANDLE) malloc( sizeof( STEREO_TCA_DEC_DATA ) ) ) == NULL ) { - IF( ( hCPE->hStereoTCA = (STEREO_TCA_DEC_HANDLE) malloc( sizeof( STEREO_TCA_DEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo TCA\n" ) ); - } + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo TCA\n" ) ); + } #ifdef IVAS_FLOAT_FIXED - stereo_tca_init_dec_fx(hCPE->hStereoTCA); + stereo_tca_init_dec_fx( hCPE->hStereoTCA ); #else - stereo_tca_init_dec(hCPE->hStereoTCA); + stereo_tca_init_dec( hCPE->hStereoTCA ); #endif - } +} - /*-----------------------------------------------------------------* - * Stereo IC BWE initialization - *-----------------------------------------------------------------*/ +/*-----------------------------------------------------------------* + * Stereo IC BWE initialization + *-----------------------------------------------------------------*/ - IF( NE_16( hCPE->element_mode, IVAS_CPE_MDCT ) && !( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && EQ_16( hCPE->nchan_out, 1 ) ) ) +IF( NE_16( hCPE->element_mode, IVAS_CPE_MDCT ) && !( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && EQ_16( hCPE->nchan_out, 1 ) ) ) +{ + IF( ( hCPE->hStereoICBWE = (STEREO_ICBWE_DEC_HANDLE) malloc( sizeof( STEREO_ICBWE_DEC_DATA ) ) ) == NULL ) { - IF( ( hCPE->hStereoICBWE = (STEREO_ICBWE_DEC_HANDLE) malloc( sizeof( STEREO_ICBWE_DEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo ICBWE\n" ) ); - } + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo ICBWE\n" ) ); + } #ifdef IVAS_FLOAT_FIXED - stereo_icBWE_init_dec_fx(hCPE->hStereoICBWE); + stereo_icBWE_init_dec_fx( hCPE->hStereoICBWE ); #else - stereo_icBWE_init_dec(hCPE->hStereoICBWE); + stereo_icBWE_init_dec( hCPE->hStereoICBWE ); #endif +} - } - - /*-----------------------------------------------------------------* - * TD stereo initialization - *-----------------------------------------------------------------*/ +/*-----------------------------------------------------------------* + * TD stereo initialization + *-----------------------------------------------------------------*/ - IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) ) +IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) ) +{ + IF( ( hCPE->hStereoTD = (STEREO_TD_DEC_DATA_HANDLE) malloc( sizeof( STEREO_TD_DEC_DATA ) ) ) == NULL ) { - IF( ( hCPE->hStereoTD = (STEREO_TD_DEC_DATA_HANDLE) malloc( sizeof( STEREO_TD_DEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD Stereo\n" ) ); - } - - stereo_td_init_dec_fx( hCPE->hStereoTD, hCPE->last_element_mode ); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD Stereo\n" ) ); } - /*-----------------------------------------------------------------* - * MDCT stereo initialization - *-----------------------------------------------------------------*/ + stereo_td_init_dec_fx( hCPE->hStereoTD, hCPE->last_element_mode ); +} + +/*-----------------------------------------------------------------* + * MDCT stereo initialization + *-----------------------------------------------------------------*/ - IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) && EQ_16( st_ivas->nCPE, 1 ) ) +IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) && EQ_16( st_ivas->nCPE, 1 ) ) +{ + IF( ( hCPE->hStereoMdct = (STEREO_MDCT_DEC_DATA_HANDLE) malloc( sizeof( STEREO_MDCT_DEC_DATA ) ) ) == NULL ) { - IF( ( hCPE->hStereoMdct = (STEREO_MDCT_DEC_DATA_HANDLE) malloc( sizeof( STEREO_MDCT_DEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo MDCT\n" ) ); - } + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo MDCT\n" ) ); + } - IF( EQ_16( (Word16) st_ivas->ivas_format, STEREO_FORMAT ) && LE_32( hCPE->element_brate, MAX_MDCT_ITD_BRATE ) ) - { - hCPE->hStereoMdct->use_itd = 1; - } - ELSE - { - hCPE->hStereoMdct->use_itd = 0; - } + IF( EQ_16( (Word16) st_ivas->ivas_format, STEREO_FORMAT ) && LE_32( hCPE->element_brate, MAX_MDCT_ITD_BRATE ) ) + { + hCPE->hStereoMdct->use_itd = 1; + } + ELSE + { + hCPE->hStereoMdct->use_itd = 0; + } - hCPE->hStereoMdct->reverse_dmx = 0; + hCPE->hStereoMdct->reverse_dmx = 0; #ifndef IVAS_FLOAT_FIXED - hCPE->hStereoMdct->smooth_ratio = 1.f; + hCPE->hStereoMdct->smooth_ratio = 1.f; #else - hCPE->hStereoMdct->smooth_ratio_fx = ONE_IN_Q26; + hCPE->hStereoMdct->smooth_ratio_fx = ONE_IN_Q26; #endif - set_s( hCPE->hStereoMdct->prev_ms_mask[0], 0, MAX_SFB ); - set_s( hCPE->hStereoMdct->prev_ms_mask[1], 0, MAX_SFB ); + set_s( hCPE->hStereoMdct->prev_ms_mask[0], 0, MAX_SFB ); + set_s( hCPE->hStereoMdct->prev_ms_mask[1], 0, MAX_SFB ); #ifndef IVAS_FLOAT_FIXED - hCPE->hStereoMdct->lastCoh = 1.f; + hCPE->hStereoMdct->lastCoh = 1.f; #else - hCPE->hStereoMdct->lastCoh_fx = ONE_IN_Q14; + hCPE->hStereoMdct->lastCoh_fx = ONE_IN_Q14; #endif - hCPE->hStereoMdct->mdct_stereo_mode[0] = SMDCT_DUAL_MONO; - hCPE->hStereoMdct->mdct_stereo_mode[1] = SMDCT_DUAL_MONO; - hCPE->hStereoMdct->IGFStereoMode[0] = -1; - hCPE->hStereoMdct->IGFStereoMode[1] = -1; - } + hCPE->hStereoMdct->mdct_stereo_mode[0] = SMDCT_DUAL_MONO; + hCPE->hStereoMdct->mdct_stereo_mode[1] = SMDCT_DUAL_MONO; + hCPE->hStereoMdct->IGFStereoMode[0] = -1; + hCPE->hStereoMdct->IGFStereoMode[1] = -1; +} - /*-----------------------------------------------------------------* - * Stereo CNG initialization - *-----------------------------------------------------------------*/ +/*-----------------------------------------------------------------* + * Stereo CNG initialization + *-----------------------------------------------------------------*/ - IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) || EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) +IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) || EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) +{ + IF( ( hCPE->hStereoCng = (STEREO_CNG_DEC_HANDLE) malloc( sizeof( STEREO_CNG_DEC ) ) ) == NULL ) { - IF( ( hCPE->hStereoCng = (STEREO_CNG_DEC_HANDLE) malloc( sizeof( STEREO_CNG_DEC ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo CNG\n" ) ); - } - stereo_cng_init_dec_fx( hCPE->hStereoCng, &hCPE->hCoreCoder[0]->hFdCngDec->hFdCngCom->frameSize ); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo CNG\n" ) ); } + stereo_cng_init_dec_fx( hCPE->hStereoCng, &hCPE->hCoreCoder[0]->hFdCngDec->hFdCngCom->frameSize ); +} - st_ivas->hCPE[cpe_id] = hCPE; +st_ivas->hCPE[cpe_id] = hCPE; - return error; +return error; } @@ -1198,7 +1194,7 @@ void destroy_cpe_dec( hCPE->input_mem_LB_fx[n] = NULL; free( hCPE->input_mem_fx[n] ); hCPE->input_mem_fx[n] = NULL; - free(hCPE->output_mem_fx[n]); + free( hCPE->output_mem_fx[n] ); hCPE->output_mem_fx[n] = NULL; #endif diff --git a/lib_dec/ivas_decision_matrix_dec.c b/lib_dec/ivas_decision_matrix_dec.c index 947767590..4e19ae179 100644 --- a/lib_dec/ivas_decision_matrix_dec.c +++ b/lib_dec/ivas_decision_matrix_dec.c @@ -48,8 +48,7 @@ * Set extension layers *-----------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -static Word16 get_next_index_4_by_15[16] = -{ +static Word16 get_next_index_4_by_15[16] = { 0, 2184, 4369, 6553, 8738, 10922, 13107, 15291, 17476, 19660, 21845, 24029, 26214, 28398, 30583, 32767 }; #endif @@ -474,7 +473,7 @@ void ivas_decision_matrix_dec( #endif #ifdef IVAS_FLOAT_FIXED void ivas_decision_matrix_dec_fx( - Decoder_State *st, /* i/o: decoder state structure */ + Decoder_State *st, /* i/o: decoder state structure */ Word16 *sharpFlag, /* o : formant sharpening flag */ Word16 *core_switching_flag, /* o : ACELP->HQ switching frame flag */ const Word32 element_brate, /* i : element bitrate */ @@ -508,27 +507,34 @@ void ivas_decision_matrix_dec_fx( * Read SID signaling bits from the bitstream *-----------------------------------------------------------------*/ - test(); test(); test(); test(); - IF ( ( EQ_16( st->idchan, 0 ) && ( EQ_32( st->total_brate, FRAME_NO_DATA ) || EQ_32( st->total_brate, SID_2k40 ) ) ) || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && LE_32( st->total_brate, SID_2k40 ) ) ) + test(); + test(); + test(); + test(); + IF( ( EQ_16( st->idchan, 0 ) && ( EQ_32( st->total_brate, FRAME_NO_DATA ) || EQ_32( st->total_brate, SID_2k40 ) ) ) || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && LE_32( st->total_brate, SID_2k40 ) ) ) { st->core = ACELP_CORE; move16(); st->core_brate = st->total_brate; move32(); - test(); test(); test(); test(); test(); - IF ( EQ_32( st->total_brate, SID_2k40 ) && !( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) ) + test(); + test(); + test(); + test(); + test(); + IF( EQ_32( st->total_brate, SID_2k40 ) && !( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) ) { - IF ( NE_16( st->element_mode, IVAS_CPE_DFT ) ) + IF( NE_16( st->element_mode, IVAS_CPE_DFT ) ) { st->cng_type = get_next_indice( st, 1 ); - IF ( EQ_16( st->cng_type, FD_CNG ) ) + IF( EQ_16( st->cng_type, FD_CNG ) ) { st->bwidth = get_next_indice( st, 2 ); } } - IF ( get_next_indice( st, 1 ) ) + IF( get_next_indice( st, 1 ) ) { st->L_frame = L_FRAME16k; move16(); @@ -539,7 +545,7 @@ void ivas_decision_matrix_dec_fx( move16(); } } - ELSE IF ( EQ_32( st->total_brate, SID_2k40 ) && EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( st->cng_sba_flag, 0 ) ) + ELSE IF( EQ_32( st->total_brate, SID_2k40 ) && EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( st->cng_sba_flag, 0 ) ) { /* read channel coherence */ Word16 index; @@ -547,21 +553,27 @@ void ivas_decision_matrix_dec_fx( st->hFdCngDec->hFdCngCom->coherence_fx = get_next_index_4_by_15[index]; ///* TODO: remove floating point dependency */ - //st->hFdCngDec->hFdCngCom->coherence_flt = ( (float) get_next_index_4_by_15[index] ) / ( ( 1 << 15 ) - 1 ); + // st->hFdCngDec->hFdCngCom->coherence_flt = ( (float) get_next_index_4_by_15[index] ) / ( ( 1 << 15 ) - 1 ); /* read flag for no side noise shape */ st->hFdCngDec->hFdCngCom->no_side_flag = get_next_indice( st, 1 ); } - test(); test(); test(); test(); test(); - IF ( ( GE_32( st->output_Fs, 32000 ) && GE_16( st->bwidth, SWB ) ) || ( EQ_16( st->element_mode, IVAS_CPE_DFT ) && GE_16( st->bwidth, SWB ) && EQ_16( nchan_out, 2 ) && LT_16( st->L_frame, L_FRAME16k ) ) ) + test(); + test(); + test(); + test(); + test(); + IF( ( GE_32( st->output_Fs, 32000 ) && GE_16( st->bwidth, SWB ) ) || ( EQ_16( st->element_mode, IVAS_CPE_DFT ) && GE_16( st->bwidth, SWB ) && EQ_16( nchan_out, 2 ) && LT_16( st->L_frame, L_FRAME16k ) ) ) { st->extl = SWB_CNG; move16(); } - test(); test(); test(); - IF ( EQ_32( st->total_brate, FRAME_NO_DATA ) && st->prev_bfi && !st->bfi && GT_16( st->L_frame, L_FRAME16k ) ) + test(); + test(); + test(); + IF( EQ_32( st->total_brate, FRAME_NO_DATA ) && st->prev_bfi && !st->bfi && GT_16( st->L_frame, L_FRAME16k ) ) { st->L_frame = st->last_CNG_L_frame; move16(); @@ -574,20 +586,21 @@ void ivas_decision_matrix_dec_fx( * ACELP/HQ core selection *---------------------------------------------------------------------*/ - test(); test(); - IF ( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 1 ) ) + test(); + test(); + IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 1 ) ) { /* minimal signaling for the secondary channel, most of the parameters are deduced from the primary channel */ st->core = ACELP_CORE; move16(); } - ELSE IF ( EQ_16( st->element_mode, IVAS_SCE ) && st->low_rate_mode ) + ELSE IF( EQ_16( st->element_mode, IVAS_SCE ) && st->low_rate_mode ) { /* ISM Low-rate mode -> always WB, ACELP core, IC coder_type */ st->core = ACELP_CORE; move16(); } - ELSE IF ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) + ELSE IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) { st->core = TCX_20_CORE; move16(); @@ -598,10 +611,10 @@ void ivas_decision_matrix_dec_fx( move16(); test(); - IF ( EQ_16( st->element_mode, IVAS_CPE_TD ) || GE_32( st->total_brate, STEREO_TCX_MIN_RATE ) ) + IF( EQ_16( st->element_mode, IVAS_CPE_TD ) || GE_32( st->total_brate, STEREO_TCX_MIN_RATE ) ) { /* ACELP/transform core selection bit */ - IF ( get_next_indice( st, 1 ) ) + IF( get_next_indice( st, 1 ) ) { st->core = HQ_CORE; move16(); @@ -618,10 +631,11 @@ void ivas_decision_matrix_dec_fx( * Read ACELP signaling bits from the bitstream *-----------------------------------------------------------------*/ - IF ( EQ_16( st->core, ACELP_CORE ) ) + IF( EQ_16( st->core, ACELP_CORE ) ) { - test(); test(); - IF ( EQ_16( st->element_mode, IVAS_SCE ) && st->low_rate_mode ) + test(); + test(); + IF( EQ_16( st->element_mode, IVAS_SCE ) && st->low_rate_mode ) { /* ISM Low-rate mode */ st->bwidth = WB; @@ -631,11 +645,11 @@ void ivas_decision_matrix_dec_fx( *sharpFlag = 0; move16(); } - ELSE IF ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) ) + ELSE IF( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) ) { *sharpFlag = 0; move16(); - IF ( EQ_16( st->coder_type, GENERIC ) || EQ_16( st->coder_type, VOICED ) ) + IF( EQ_16( st->coder_type, GENERIC ) || EQ_16( st->coder_type, VOICED ) ) { *sharpFlag = 1; move16(); @@ -646,8 +660,9 @@ void ivas_decision_matrix_dec_fx( st->codec_mode = MODE1; move16(); - test(); test(); - IF ( EQ_16( st->idchan, 1 ) && ( EQ_16( st->tdm_LRTD_flag, 0 ) || LT_16( st->bits_frame_channel, IVAS_16k4 / FRAMES_PER_SEC ) ) ) + test(); + test(); + IF( EQ_16( st->idchan, 1 ) && ( EQ_16( st->tdm_LRTD_flag, 0 ) || LT_16( st->bits_frame_channel, IVAS_16k4 / FRAMES_PER_SEC ) ) ) { st->bwidth = WB; /* only WB in the secondary channel */ move16(); @@ -655,14 +670,16 @@ void ivas_decision_matrix_dec_fx( } ELSE { - IF ( LT_32( element_brate, FRMT_SHP_MIN_BRATE_IVAS ) ) + IF( LT_32( element_brate, FRMT_SHP_MIN_BRATE_IVAS ) ) { st->coder_type = get_next_indice( st, 3 ); *sharpFlag = 0; move16(); - test(); test(); test(); - IF ( LT_32( element_brate, IVAS_24k4 ) && ( EQ_16( st->coder_type, VOICED ) || EQ_16( st->coder_type, GENERIC ) || EQ_16( st->coder_type, TRANSITION ) ) ) + test(); + test(); + test(); + IF( LT_32( element_brate, IVAS_24k4 ) && ( EQ_16( st->coder_type, VOICED ) || EQ_16( st->coder_type, GENERIC ) || EQ_16( st->coder_type, TRANSITION ) ) ) { *sharpFlag = 1; move16(); @@ -683,31 +700,37 @@ void ivas_decision_matrix_dec_fx( * Set extension layers *-----------------------------------------------------------------*/ - IF ( EQ_16( st->core, ACELP_CORE ) ) + IF( EQ_16( st->core, ACELP_CORE ) ) { - test(); test(); test(); test(); test(); test(); test(); - IF ( EQ_16( st->bwidth, WB ) && st->low_rate_mode ) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( EQ_16( st->bwidth, WB ) && st->low_rate_mode ) { st->extl = WB_BWE; move16(); - IF ( GE_32( st->total_brate, MIN_BRATE_WB_BWE ) ) + IF( GE_32( st->total_brate, MIN_BRATE_WB_BWE ) ) { st->extl_brate = WB_BWE_0k35; move32(); } } - ELSE IF ( EQ_16( st->bwidth, WB ) && ( LT_32( st->total_brate, MIN_BRATE_WB_BWE ) || ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) ) ) ) + ELSE IF( EQ_16( st->bwidth, WB ) && ( LT_32( st->total_brate, MIN_BRATE_WB_BWE ) || ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) ) ) ) { - IF ( EQ_16( st->vbr_hw_BWE_disable_dec, 0 ) ) + IF( EQ_16( st->vbr_hw_BWE_disable_dec, 0 ) ) { st->extl = WB_BWE; move16(); } } - ELSE IF ( EQ_16( st->bwidth, WB ) && GE_32( st->total_brate, MIN_BRATE_WB_BWE ) && !st->flag_ACELP16k ) + ELSE IF( EQ_16( st->bwidth, WB ) && GE_32( st->total_brate, MIN_BRATE_WB_BWE ) && !st->flag_ACELP16k ) { /* read the WB TBE/BWE selection bit */ - IF ( get_next_indice( st, 1 ) ) + IF( get_next_indice( st, 1 ) ) { st->extl = WB_BWE; move16(); @@ -718,8 +741,9 @@ void ivas_decision_matrix_dec_fx( { st->extl = WB_TBE; move16(); - test(); test(); - IF ( LT_32( st->total_brate, MIN_BRATE_WB_TBE_1k05 ) || ( EQ_16( st->element_mode, IVAS_CPE_TD ) && LT_32( st->total_brate, MIN_TDM_BRATE_WB_TBE_1k05 ) ) ) + test(); + test(); + IF( LT_32( st->total_brate, MIN_BRATE_WB_TBE_1k05 ) || ( EQ_16( st->element_mode, IVAS_CPE_TD ) && LT_32( st->total_brate, MIN_TDM_BRATE_WB_TBE_1k05 ) ) ) { st->extl_brate = WB_TBE_0k35; move32(); @@ -731,14 +755,14 @@ void ivas_decision_matrix_dec_fx( } } } - ELSE IF ( EQ_16( st->bwidth, SWB ) || EQ_16( st->bwidth, FB ) ) + ELSE IF( EQ_16( st->bwidth, SWB ) || EQ_16( st->bwidth, FB ) ) { - IF ( GE_32( st->total_brate, MIN_BRATE_SWB_BWE ) || ( GE_32( st->total_brate, MIN_MIN_BRATE_LRTD_SWB_BWE ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->bwidth, SWB ) && st->tdm_LRTD_flag ) || ( LT_32( element_brate, IVAS_16k4 ) && GE_32( st->total_brate, MIN_MIN_BRATE_LRTD_SWB_BWE ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->bwidth, SWB ) ) ) + IF( GE_32( st->total_brate, MIN_BRATE_SWB_BWE ) || ( GE_32( st->total_brate, MIN_MIN_BRATE_LRTD_SWB_BWE ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->bwidth, SWB ) && st->tdm_LRTD_flag ) || ( LT_32( element_brate, IVAS_16k4 ) && GE_32( st->total_brate, MIN_MIN_BRATE_LRTD_SWB_BWE ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->bwidth, SWB ) ) ) { /* read the SWB TBE/BWE selection bit */ tmp = get_next_indice( st, 1 ); - IF ( tmp ) + IF( tmp ) { st->extl = SWB_BWE; move16(); @@ -751,14 +775,14 @@ void ivas_decision_matrix_dec_fx( move32(); st->extl_brate = SWB_TBE_1k6; move32(); - IF ( GE_32( st->total_brate, MIN_BRATE_SWB_TBE_2k80 ) && st->flag_ACELP16k && EQ_16( st->element_mode, IVAS_SCE ) ) + IF( GE_32( st->total_brate, MIN_BRATE_SWB_TBE_2k80 ) && st->flag_ACELP16k && EQ_16( st->element_mode, IVAS_SCE ) ) { st->extl_brate = SWB_TBE_2k8; move32(); } - ELSE IF ( EQ_16( st->tdm_LRTD_flag, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) ) + ELSE IF( EQ_16( st->tdm_LRTD_flag, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) ) { - IF ( LT_32( st->element_brate, IVAS_24k4 ) ) + IF( LT_32( st->element_brate, IVAS_24k4 ) ) { st->extl_brate = SWB_TBE_1k10; move32(); @@ -769,7 +793,7 @@ void ivas_decision_matrix_dec_fx( move32(); } } - ELSE IF ( LT_32( st->total_brate, MIN_BRATE_SWB_TBE_1k60 ) ) + ELSE IF( LT_32( st->total_brate, MIN_BRATE_SWB_TBE_1k60 ) ) { st->extl_brate = SWB_TBE_0k95; move32(); @@ -785,22 +809,22 @@ void ivas_decision_matrix_dec_fx( } /* set FB TBE and FB BWE extension layers */ - IF ( EQ_16( st->bwidth, FB ) ) + IF( EQ_16( st->bwidth, FB ) ) { - IF ( EQ_16( st->extl, SWB_BWE ) ) + IF( EQ_16( st->extl, SWB_BWE ) ) { st->extl = FB_BWE; move16(); st->extl_brate = FB_BWE_1k8; move32(); } - ELSE IF ( EQ_16( st->extl, SWB_TBE ) ) + ELSE IF( EQ_16( st->extl, SWB_TBE ) ) { st->extl = FB_TBE; move16(); st->extl_brate = FB_TBE_1k8; move32(); - IF ( GE_32( st->total_brate, MIN_BRATE_SWB_TBE_2k80 ) && st->flag_ACELP16k && EQ_16( st->element_mode, IVAS_SCE ) ) + IF( GE_32( st->total_brate, MIN_BRATE_SWB_TBE_2k80 ) && st->flag_ACELP16k && EQ_16( st->element_mode, IVAS_SCE ) ) { st->extl_brate = FB_TBE_3k0; move32(); @@ -808,30 +832,36 @@ void ivas_decision_matrix_dec_fx( } } /* set IC-BWE bitrate */ - test(); test(); - IF ( EQ_16( st->element_mode, IVAS_CPE_TD ) && !( GE_16( st->bwidth, SWB ) && st->tdm_LRTD_flag ) ) + test(); + test(); + IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && !( GE_16( st->bwidth, SWB ) && st->tdm_LRTD_flag ) ) { icbwe_brate = STEREO_BITS_ICBWE * FRAMES_PER_SEC; move32(); - IF ( EQ_16( st->flag_ACELP16k, 0 ) ) + IF( EQ_16( st->flag_ACELP16k, 0 ) ) { icbwe_brate = ( STEREO_BITS_ICBWE - STEREO_ICBWE_SPBITS ) * FRAMES_PER_SEC; move32(); } } - ELSE IF ( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) + ELSE IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) { icbwe_brate = STEREO_BITS_ICBWE_DFT * FRAMES_PER_SEC; move32(); - IF ( EQ_16( st->flag_ACELP16k, 0 ) ) + IF( EQ_16( st->flag_ACELP16k, 0 ) ) { icbwe_brate = ( STEREO_BITS_ICBWE_DFT - STEREO_ICBWE_SPBITS ) * FRAMES_PER_SEC; move32(); } } - test(); test(); test(); test(); test(); test(); - IF ( GE_16( st->element_mode, IVAS_CPE_DFT ) && EQ_16( st->core, ACELP_CORE ) && ( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, FB_TBE ) ) && !( EQ_16( st->element_mode, IVAS_CPE_TD ) && st->tdm_LRTD_flag ) ) + test(); + test(); + test(); + test(); + test(); + test(); + IF( GE_16( st->element_mode, IVAS_CPE_DFT ) && EQ_16( st->core, ACELP_CORE ) && ( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, FB_TBE ) ) && !( EQ_16( st->element_mode, IVAS_CPE_TD ) && st->tdm_LRTD_flag ) ) { icbwe_brate = L_add( icbwe_brate, STEREO_ICBWE_MSFLAG_BITS * FRAMES_PER_SEC ); } @@ -845,10 +875,12 @@ void ivas_decision_matrix_dec_fx( * Read transform core (TCX vs. HQ) signaling bit from the bitstream *-----------------------------------------------------------------*/ - test(); test(); test(); - IF ( NE_16( st->element_mode, IVAS_CPE_MDCT ) && !( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) ) && EQ_16( st->core, HQ_CORE ) ) + test(); + test(); + test(); + IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) && !( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) ) && EQ_16( st->core, HQ_CORE ) ) { - IF ( get_next_indice( st, 1 ) ) + IF( get_next_indice( st, 1 ) ) { st->core = TCX_20_CORE; move16(); @@ -861,7 +893,7 @@ void ivas_decision_matrix_dec_fx( } test(); - IF ( NE_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( st->core, TCX_20_CORE ) ) + IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( st->core, TCX_20_CORE ) ) { st->extl = IGF_BWE; move16(); @@ -874,9 +906,9 @@ void ivas_decision_matrix_dec_fx( *-----------------------------------------------------------------*/ test(); - IF ( EQ_16( st->core, HQ_CORE ) || EQ_16( st->core, TCX_20_CORE ) ) + IF( EQ_16( st->core, HQ_CORE ) || EQ_16( st->core, TCX_20_CORE ) ) { - IF ( EQ_16( st->core, HQ_CORE ) ) + IF( EQ_16( st->core, HQ_CORE ) ) { /* read ACELP->HQ core switching flag */ *core_switching_flag = get_next_indice( st, 1 ); @@ -887,12 +919,12 @@ void ivas_decision_matrix_dec_fx( move16(); } - IF ( EQ_16( *core_switching_flag, 1 ) ) + IF( EQ_16( *core_switching_flag, 1 ) ) { st->last_core_from_bs = ACELP_CORE; move16(); - IF ( EQ_16( st->core, st->last_core ) ) + IF( EQ_16( st->core, st->last_core ) ) { /* A mismatch between the core_switching_flag and the st->core/st->last_core indicates a frame was lost. if prev_bfi is not set the frame loss @@ -915,20 +947,25 @@ void ivas_decision_matrix_dec_fx( * Set ACELP frame length *-----------------------------------------------------------------*/ - test(); test(); test(); test(); test(); test(); - IF ( EQ_32( st->core_brate, FRAME_NO_DATA ) ) + test(); + test(); + test(); + test(); + test(); + test(); + IF( EQ_32( st->core_brate, FRAME_NO_DATA ) ) { /* prevent "L_frame" changes in CNG segments */ st->L_frame = st->last_L_frame; move16(); } - ELSE IF ( EQ_32( st->core_brate, SID_2k40 ) && EQ_16( st->bwidth, WB ) && st->first_CNG && LT_16( st->hTdCngDec->act_cnt2, MIN_ACT_CNG_UPD ) ) + ELSE IF( EQ_32( st->core_brate, SID_2k40 ) && EQ_16( st->bwidth, WB ) && st->first_CNG && LT_16( st->hTdCngDec->act_cnt2, MIN_ACT_CNG_UPD ) ) { /* prevent "L_frame" changes in SID frame after short segment of active frames */ st->L_frame = st->last_CNG_L_frame; move16(); } - ELSE IF ( ( EQ_32( st->core_brate, SID_2k40 ) && GE_32( st->total_brate, ACELP_9k60 ) && EQ_16( st->bwidth, WB ) ) || st->flag_ACELP16k ) + ELSE IF( ( EQ_32( st->core_brate, SID_2k40 ) && GE_32( st->total_brate, ACELP_9k60 ) && EQ_16( st->bwidth, WB ) ) || st->flag_ACELP16k ) { st->L_frame = L_FRAME16k; move16(); @@ -939,7 +976,7 @@ void ivas_decision_matrix_dec_fx( move16(); } - IF ( EQ_16( st->L_frame, L_FRAME16k ) ) + IF( EQ_16( st->L_frame, L_FRAME16k ) ) { st->nb_subfr = NB_SUBFR16k; move16(); @@ -957,7 +994,7 @@ void ivas_decision_matrix_dec_fx( st->inactive_coder_type_flag = 0; /* AVQ by default */ move16(); - IF ( LE_32( st->total_brate, MAX_GSC_INACTIVE_BRATE ) ) + IF( LE_32( st->total_brate, MAX_GSC_INACTIVE_BRATE ) ) { st->inactive_coder_type_flag = 1; /* GSC */ move16(); @@ -973,8 +1010,9 @@ void ivas_decision_matrix_dec_fx( move32(); - test(); test(); - IF ( EQ_32( st->output_Fs, 16000 ) && EQ_16( st->L_frame, L_FRAME16k ) && NE_16( st->extl, IGF_BWE ) ) + test(); + test(); + IF( EQ_32( st->output_Fs, 16000 ) && EQ_16( st->L_frame, L_FRAME16k ) && NE_16( st->extl, IGF_BWE ) ) { st->extl = -1; move16(); @@ -982,7 +1020,7 @@ void ivas_decision_matrix_dec_fx( move32(); } - IF ( EQ_16( st->ini_frame, 0 ) ) + IF( EQ_16( st->ini_frame, 0 ) ) { /* avoid switching of internal ACELP Fs in the very first frame */ st->last_L_frame = st->L_frame; @@ -997,4 +1035,4 @@ void ivas_decision_matrix_dec_fx( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index 52a7ccf3c..aa9ebf964 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -65,29 +65,29 @@ static ivas_error ivas_dirac_dec_config_internal_fx( ivas_error error; DIRAC_CONFIG_FLAG flag_config; - flag_config = (flag_config_inp == DIRAC_RECONFIGURE_MODE) ? DIRAC_RECONFIGURE : flag_config_inp; + flag_config = ( flag_config_inp == DIRAC_RECONFIGURE_MODE ) ? DIRAC_RECONFIGURE : flag_config_inp; error = IVAS_ERR_OK; hDirAC = NULL; - IF (flag_config == DIRAC_RECONFIGURE) + IF( flag_config == DIRAC_RECONFIGURE ) { hDirAC = st_ivas->hDirAC; } - ELSE IF (flag_config == DIRAC_OPEN) + ELSE IF( flag_config == DIRAC_OPEN ) { /*-----------------------------------------------------------------* * prepare library opening *-----------------------------------------------------------------*/ - IF ((hDirAC = (DIRAC_DEC_HANDLE)malloc(sizeof(DIRAC_DEC_DATA))) == NULL) + IF( ( hDirAC = (DIRAC_DEC_HANDLE) malloc( sizeof( DIRAC_DEC_DATA ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } - IF ((hDirAC->hConfig = (DIRAC_CONFIG_DATA_HANDLE)malloc(sizeof(DIRAC_CONFIG_DATA))) == NULL) + IF( ( hDirAC->hConfig = (DIRAC_CONFIG_DATA_HANDLE) malloc( sizeof( DIRAC_CONFIG_DATA ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC Config\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC Config\n" ) ); } st_ivas->hDirAC = hDirAC; @@ -97,14 +97,14 @@ static ivas_error ivas_dirac_dec_config_internal_fx( * DirAC main configuration *-----------------------------------------------------------------*/ - IF ((error = ivas_dirac_config((void *)st_ivas, DEC)) != IVAS_ERR_OK) + IF( ( error = ivas_dirac_config( (void *) st_ivas, DEC ) ) != IVAS_ERR_OK ) { return error; } - IF (flag_config == DIRAC_OPEN) + IF( flag_config == DIRAC_OPEN ) { - hDirAC->spar_to_dirac_write_idx = (st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT) ? DELAY_DIRAC_PARAM_DEC_SFR : 0; + hDirAC->spar_to_dirac_write_idx = ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT ) ? DELAY_DIRAC_PARAM_DEC_SFR : 0; hDirAC->dithering_seed = DIRAC_DITH_SEED; st_ivas->hDirAC = hDirAC; } @@ -556,7 +556,6 @@ static ivas_error ivas_dirac_rend_config_fx( { initDiffuseResponses_fx( hDirACRend->diffuse_response_function_fx, nchan_out_woLFE, hDirACRend->hOutSetup.output_config, hDirACRend->hOutSetup, hDirACRend->hOutSetup.ambisonics_order, st_ivas->ivas_format, &hDirACRend->num_ele_spk_no_diffuse_rendering, st_ivas->transport_config ); - } ELSE { @@ -660,8 +659,29 @@ static ivas_error ivas_dirac_rend_config_fx( hDirACRend->proto_signal_decorr_on = 0; } - IF( ( EQ_16( flag_config, DIRAC_OPEN) && hDirACRend->proto_signal_decorr_on ) || ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( hDirACRend->proto_signal_decorr_on && !proto_signal_decorr_on_old ) ) ) + IF( ( EQ_16( flag_config, DIRAC_OPEN ) && hDirACRend->proto_signal_decorr_on ) || ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( hDirACRend->proto_signal_decorr_on && !proto_signal_decorr_on_old ) ) ){ +#ifdef IVAS_FLOAT_FIXED + IF( ( error = ivas_dirac_dec_decorr_open_fx( &( hDirACRend->h_freq_domain_decorr_ap_params ), &( hDirACRend->h_freq_domain_decorr_ap_state ), hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff, + hDirACRend->num_protos_diff, hDirACRend->synthesisConf, hDirACRend->frequency_axis_fx, nchan_transport > 2 ? 4 : nchan_transport, output_Fs ) ) != IVAS_ERR_OK ){ + return error; +} +#else + IF( ( error = ivas_dirac_dec_decorr_open( &( hDirACRend->h_freq_domain_decorr_ap_params ), &( hDirACRend->h_freq_domain_decorr_ap_state ), hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff, + hDirACRend->num_protos_diff, hDirACRend->synthesisConf, hDirACRend->frequency_axis, nchan_transport > 2 ? 4 : nchan_transport, output_Fs ) ) != IVAS_ERR_OK ){ + return error; +} +#endif +} +ELSE IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( !hDirACRend->proto_signal_decorr_on && proto_signal_decorr_on_old ) ) +{ + ivas_dirac_dec_decorr_close_fx( &hDirACRend->h_freq_domain_decorr_ap_params, &hDirACRend->h_freq_domain_decorr_ap_state ); +} +ELSE IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->proto_signal_decorr_on && proto_signal_decorr_on_old ) +{ + IF( NE_16( nchan_transport, nchan_transport_old ) || NE_16( hDirACRend->num_outputs_diff, num_outputs_diff_old ) || EQ_16( flag_config_inp, DIRAC_RECONFIGURE_MODE ) ) { + /* close and reopen the decorrelator */ + ivas_dirac_dec_decorr_close_fx( &hDirACRend->h_freq_domain_decorr_ap_params, &hDirACRend->h_freq_domain_decorr_ap_state ); #ifdef IVAS_FLOAT_FIXED IF( ( error = ivas_dirac_dec_decorr_open_fx( &( hDirACRend->h_freq_domain_decorr_ap_params ), &( hDirACRend->h_freq_domain_decorr_ap_state ), hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff, hDirACRend->num_protos_diff, hDirACRend->synthesisConf, hDirACRend->frequency_axis_fx, nchan_transport > 2 ? 4 : nchan_transport, output_Fs ) ) != IVAS_ERR_OK ) @@ -676,190 +696,166 @@ static ivas_error ivas_dirac_rend_config_fx( } #endif } - ELSE IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( !hDirACRend->proto_signal_decorr_on && proto_signal_decorr_on_old ) ) - { - ivas_dirac_dec_decorr_close_fx( &hDirACRend->h_freq_domain_decorr_ap_params, &hDirACRend->h_freq_domain_decorr_ap_state ); - } - ELSE IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->proto_signal_decorr_on && proto_signal_decorr_on_old ) - { - IF( NE_16( nchan_transport, nchan_transport_old ) || NE_16( hDirACRend->num_outputs_diff, num_outputs_diff_old ) || EQ_16( flag_config_inp, DIRAC_RECONFIGURE_MODE ) ) - { - /* close and reopen the decorrelator */ - ivas_dirac_dec_decorr_close_fx( &hDirACRend->h_freq_domain_decorr_ap_params, &hDirACRend->h_freq_domain_decorr_ap_state ); -#ifdef IVAS_FLOAT_FIXED - IF( ( error = ivas_dirac_dec_decorr_open_fx( &( hDirACRend->h_freq_domain_decorr_ap_params ), &( hDirACRend->h_freq_domain_decorr_ap_state ), hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff, - hDirACRend->num_protos_diff, hDirACRend->synthesisConf, hDirACRend->frequency_axis_fx, nchan_transport > 2 ? 4 : nchan_transport, output_Fs ) ) != IVAS_ERR_OK ) - { - return error; - } -#else - IF( ( error = ivas_dirac_dec_decorr_open( &( hDirACRend->h_freq_domain_decorr_ap_params ), &( hDirACRend->h_freq_domain_decorr_ap_state ), hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff, - hDirACRend->num_protos_diff, hDirACRend->synthesisConf, hDirACRend->frequency_axis, nchan_transport > 2 ? 4 : nchan_transport, output_Fs ) ) != IVAS_ERR_OK ) - { - return error; - } -#endif - } - } +} - /* output synthesis */ - IF( EQ_16( flag_config, DIRAC_OPEN ) ) - { - IF( ( ivas_dirac_dec_output_synthesis_open_fx( hSpatParamRendCom, hDirACRend, st_ivas->renderer_type, nchan_transport, output_Fs, hodirac_flag ) ) != IVAS_ERR_OK ) - { - return error; - } - hDirACRend->h_output_synthesis_psd_params.use_onset_filters = hDirACRend->proto_signal_decorr_on; - } - ELSE IF( ( EQ_16( flag_config, DIRAC_RECONFIGURE ) ) && ( ( NE_16( nchan_transport, nchan_transport_old ) ) || ( NE_16( hDirACRend->num_outputs_diff, num_outputs_diff_old ) ) ) ) +/* output synthesis */ +IF( EQ_16( flag_config, DIRAC_OPEN ) ) +{ + IF( ( ivas_dirac_dec_output_synthesis_open_fx( hSpatParamRendCom, hDirACRend, st_ivas->renderer_type, nchan_transport, output_Fs, hodirac_flag ) ) != IVAS_ERR_OK ) { - ivas_dirac_dec_output_synthesis_close_fx( hDirACRend ); - - IF( ( ivas_dirac_dec_output_synthesis_open_fx( hSpatParamRendCom, hDirACRend, st_ivas->renderer_type, nchan_transport, output_Fs, hodirac_flag ) ) != IVAS_ERR_OK ) - { - return error; - } - hDirACRend->h_output_synthesis_psd_params.use_onset_filters = hDirACRend->proto_signal_decorr_on; + return error; } + hDirACRend->h_output_synthesis_psd_params.use_onset_filters = hDirACRend->proto_signal_decorr_on; +} +ELSE IF( ( EQ_16( flag_config, DIRAC_RECONFIGURE ) ) && ( ( NE_16( nchan_transport, nchan_transport_old ) ) || ( NE_16( hDirACRend->num_outputs_diff, num_outputs_diff_old ) ) ) ) +{ + ivas_dirac_dec_output_synthesis_close_fx( hDirACRend ); - IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) || EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) + IF( ( ivas_dirac_dec_output_synthesis_open_fx( hSpatParamRendCom, hDirACRend, st_ivas->renderer_type, nchan_transport, output_Fs, hodirac_flag ) ) != IVAS_ERR_OK ) { - hDirACRend->h_output_synthesis_psd_params.use_onset_filters = 0; + return error; } + hDirACRend->h_output_synthesis_psd_params.use_onset_filters = hDirACRend->proto_signal_decorr_on; +} - /*-----------------------------------------------------------------* - * memory allocation - *-----------------------------------------------------------------*/ +IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) || EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) +{ + hDirACRend->h_output_synthesis_psd_params.use_onset_filters = 0; +} - IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) - { +/*-----------------------------------------------------------------* + * memory allocation + *-----------------------------------------------------------------*/ + +IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) +{ #if 1 /*TODO : remove float code*/ - IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->proto_frame_f ) - { - free( hDirACRend->proto_frame_f ); - } - hDirACRend->proto_frame_f = NULL; + IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->proto_frame_f ) + { + free( hDirACRend->proto_frame_f ); + } + hDirACRend->proto_frame_f = NULL; #endif - IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->proto_frame_f_fx ) - { - free( hDirACRend->proto_frame_f_fx ); - } - hDirACRend->proto_frame_f_fx = NULL; + IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->proto_frame_f_fx ) + { + free( hDirACRend->proto_frame_f_fx ); } - ELSE + hDirACRend->proto_frame_f_fx = NULL; +} +ELSE +{ + IF( EQ_16( flag_config, DIRAC_OPEN ) || ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->proto_frame_f_fx == NULL ) ) { - IF( EQ_16( flag_config, DIRAC_OPEN ) || ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->proto_frame_f_fx == NULL ) ) + IF( ( hDirACRend->proto_frame_f_fx = (Word32 *) malloc( sizeof( Word32 ) * 2 * hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands ) ) == NULL ) { - IF( ( hDirACRend->proto_frame_f_fx = (Word32 *) malloc( sizeof( Word32 ) * 2 * hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } - ELSE IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( NE_16( hDirACRend->num_protos_diff, num_protos_diff_old ) ) ) + } + ELSE IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( NE_16( hDirACRend->num_protos_diff, num_protos_diff_old ) ) ) + { + proto_frame_f_old_fx = hDirACRend->proto_frame_f_fx; + free( proto_frame_f_old_fx ); + IF( ( hDirACRend->proto_frame_f_fx = (Word32 *) malloc( sizeof( Word32 ) * 2 * hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands ) ) == NULL ) { - proto_frame_f_old_fx = hDirACRend->proto_frame_f_fx; - free( proto_frame_f_old_fx ); - IF( ( hDirACRend->proto_frame_f_fx = (Word32 *) malloc( sizeof( Word32 ) * 2 * hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } - hDirACRend->proto_frame_f_len = 2 * hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands; + } + hDirACRend->proto_frame_f_len = 2 * hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands; #ifdef TRUE - /*Todo : to remove float code*/ - if ( flag_config == DIRAC_OPEN || ( flag_config == DIRAC_RECONFIGURE && hDirACRend->proto_frame_f == NULL ) ) + /*Todo : to remove float code*/ + if ( flag_config == DIRAC_OPEN || ( flag_config == DIRAC_RECONFIGURE && hDirACRend->proto_frame_f == NULL ) ) + { + if ( ( hDirACRend->proto_frame_f = (float *) malloc( sizeof( float ) * 2 * hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands ) ) == NULL ) { - if ( ( hDirACRend->proto_frame_f = (float *) malloc( sizeof( float ) * 2 * hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } - else if ( flag_config == DIRAC_RECONFIGURE && ( hDirACRend->num_protos_diff != num_protos_diff_old ) ) + } + else if ( flag_config == DIRAC_RECONFIGURE && ( hDirACRend->num_protos_diff != num_protos_diff_old ) ) + { + proto_frame_f_old = hDirACRend->proto_frame_f; + free( proto_frame_f_old ); + if ( ( hDirACRend->proto_frame_f = (float *) malloc( sizeof( float ) * 2 * hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands ) ) == NULL ) { - proto_frame_f_old = hDirACRend->proto_frame_f; - free( proto_frame_f_old ); - if ( ( hDirACRend->proto_frame_f = (float *) malloc( sizeof( float ) * 2 * hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } -#endif } +#endif +} - IF( EQ_16( flag_config, DIRAC_OPEN ) ) - { - hDirACRend->buffer_energy_fx = NULL; - } +IF( EQ_16( flag_config, DIRAC_OPEN ) ) +{ + hDirACRend->buffer_energy_fx = NULL; +} - IF( ( EQ_16( flag_config, DIRAC_OPEN ) && hDirAC->hConfig->dec_param_estim == TRUE ) || ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( hDirAC->hConfig->dec_param_estim == TRUE && dec_param_estim_old == FALSE ) ) ) +IF( ( EQ_16( flag_config, DIRAC_OPEN ) && hDirAC->hConfig->dec_param_estim == TRUE ) || ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( hDirAC->hConfig->dec_param_estim == TRUE && dec_param_estim_old == FALSE ) ) ) +{ + hDirACRend->index_buffer_intensity = 0; + FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) { - hDirACRend->index_buffer_intensity = 0; - FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) + FOR( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) { - FOR( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) + IF( ( hDirACRend->buffer_intensity_real_fx[i][j] = (Word32 *) malloc( CLDFB_NO_CHANNELS_MAX * sizeof( Word32 ) ) ) == NULL ) { - IF( ( hDirACRend->buffer_intensity_real_fx[i][j] = (Word32 *) malloc( CLDFB_NO_CHANNELS_MAX * sizeof( Word32 ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } - set32_fx( hDirACRend->buffer_intensity_real_fx[i][j], 0, CLDFB_NO_CHANNELS_MAX ); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } + set32_fx( hDirACRend->buffer_intensity_real_fx[i][j], 0, CLDFB_NO_CHANNELS_MAX ); } - set16_fx( hDirACRend->q_buffer_intensity_real, Q31, DIRAC_NO_COL_AVG_DIFF ); - IF( hDirACRend->buffer_energy_fx == NULL ) + } + set16_fx( hDirACRend->q_buffer_intensity_real, Q31, DIRAC_NO_COL_AVG_DIFF ); + IF( hDirACRend->buffer_energy_fx == NULL ) + { + IF( ( hDirACRend->buffer_energy_fx = (Word32 *) malloc( DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX * sizeof( Word32 ) ) ) == NULL ) { - IF( ( hDirACRend->buffer_energy_fx = (Word32 *) malloc( DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX * sizeof( Word32 ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } - set32_fx( hDirACRend->buffer_energy_fx, 0, DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX ); - set16_fx( hDirACRend->q_buffer_energy, Q31, DIRAC_NO_COL_AVG_DIFF ); } - ELSE IF( ( EQ_16( flag_config, DIRAC_OPEN ) && hDirAC->hConfig->dec_param_estim == FALSE ) || ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( hDirAC->hConfig->dec_param_estim == FALSE && dec_param_estim_old == TRUE ) ) ) + set32_fx( hDirACRend->buffer_energy_fx, 0, DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX ); + set16_fx( hDirACRend->q_buffer_energy, Q31, DIRAC_NO_COL_AVG_DIFF ); +} +ELSE IF( ( EQ_16( flag_config, DIRAC_OPEN ) && hDirAC->hConfig->dec_param_estim == FALSE ) || ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( hDirAC->hConfig->dec_param_estim == FALSE && dec_param_estim_old == TRUE ) ) ) +{ + FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) { - FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) + FOR( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) { - FOR( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) + IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->buffer_intensity_real_fx[i][j] ) { - IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->buffer_intensity_real_fx[i][j] ) - { - free( hDirACRend->buffer_intensity_real_fx[i][j] ); - } - hDirACRend->buffer_intensity_real_fx[i][j] = NULL; + free( hDirACRend->buffer_intensity_real_fx[i][j] ); } - } - IF( hDirACRend->buffer_energy_fx != NULL ) - { - free( hDirACRend->buffer_energy_fx ); - hDirACRend->buffer_energy_fx = NULL; + hDirACRend->buffer_intensity_real_fx[i][j] = NULL; } } - /* output synthesis */ - ivas_dirac_dec_output_synthesis_init_fx( hSpatParamRendCom, hDirACRend, nchan_out_woLFE, hodirac_flag ); - - /* Allocate stack memory */ - IF( NE_16( flag_config, DIRAC_OPEN ) ) - { - ivas_dirac_free_mem_fx( &( hDirACRend->stack_mem ) ); - } - IF( ( error = ivas_dirac_alloc_mem( hDirACRend, st_ivas->renderer_type, hSpatParamRendCom->num_freq_bands, &( hDirACRend->stack_mem ), hodirac_flag ) ) != IVAS_ERR_OK ) + IF( hDirACRend->buffer_energy_fx != NULL ) { - return error; - } - - IF( EQ_16( flag_config, DIRAC_OPEN ) ) - { - st_ivas->hDirACRend = hDirACRend; + free( hDirACRend->buffer_energy_fx ); + hDirACRend->buffer_energy_fx = NULL; } +} +/* output synthesis */ +ivas_dirac_dec_output_synthesis_init_fx( hSpatParamRendCom, hDirACRend, nchan_out_woLFE, hodirac_flag ); +/* Allocate stack memory */ +IF( NE_16( flag_config, DIRAC_OPEN ) ) +{ + ivas_dirac_free_mem_fx( &( hDirACRend->stack_mem ) ); +} +IF( ( error = ivas_dirac_alloc_mem( hDirACRend, st_ivas->renderer_type, hSpatParamRendCom->num_freq_bands, &( hDirACRend->stack_mem ), hodirac_flag ) ) != IVAS_ERR_OK ) +{ return error; } + +IF( EQ_16( flag_config, DIRAC_OPEN ) ) +{ + st_ivas->hDirACRend = hDirACRend; +} + +return error; +} #else static ivas_error ivas_dirac_rend_config( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const DIRAC_CONFIG_FLAG flag_config_inp, /* i/ : Flag determining if we open or reconfigure the DirAC decoder */ - const int16_t dec_param_estim_old) + const int16_t dec_param_estim_old ) { DIRAC_DEC_HANDLE hDirAC; int16_t nchan_out_woLFE; @@ -881,30 +877,30 @@ static ivas_error ivas_dirac_rend_config( DIRAC_REND_HANDLE hDirACRend; SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; - flag_config = (flag_config_inp == DIRAC_RECONFIGURE_MODE) ? DIRAC_RECONFIGURE : flag_config_inp; + flag_config = ( flag_config_inp == DIRAC_RECONFIGURE_MODE ) ? DIRAC_RECONFIGURE : flag_config_inp; error = IVAS_ERR_OK; hDirACRend = NULL; output_Fs = st_ivas->hDecoderConfig->output_Fs; ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; - hodirac_flag = ivas_get_hodirac_flag(ivas_total_brate, st_ivas->sba_analysis_order); + hodirac_flag = ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ); hDirAC = st_ivas->hDirAC; hSpatParamRendCom = st_ivas->hSpatParamRendCom; - if (flag_config == DIRAC_RECONFIGURE) + if ( flag_config == DIRAC_RECONFIGURE ) { hDirACRend = st_ivas->hDirACRend; } - else if (flag_config == DIRAC_OPEN) + else if ( flag_config == DIRAC_OPEN ) { /*-----------------------------------------------------------------* * prepare library opening *-----------------------------------------------------------------*/ - if ((hDirACRend = (DIRAC_REND_HANDLE)malloc(sizeof(DIRAC_REND_DATA))) == NULL) + if ( ( hDirACRend = (DIRAC_REND_HANDLE) malloc( sizeof( DIRAC_REND_DATA ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC renderer\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC renderer\n" ) ); } nchan_transport_old = 0; @@ -916,20 +912,20 @@ static ivas_error ivas_dirac_rend_config( num_protos_diff_old = 0; nchan_transport_orig = st_ivas->nchan_transport; - if (st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT) + if ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT ) { - st_ivas->nchan_transport = ivas_sba_get_nchan_metadata(st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate); + st_ivas->nchan_transport = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); } nchan_transport = st_ivas->nchan_transport; - if (st_ivas->ivas_format == MASA_FORMAT && ivas_total_brate < MASA_STEREO_MIN_BITRATE && ivas_total_brate > IVAS_SID_5k2) + if ( st_ivas->ivas_format == MASA_FORMAT && ivas_total_brate < MASA_STEREO_MIN_BITRATE && ivas_total_brate > IVAS_SID_5k2 ) { nchan_transport = 1; } - if (flag_config == DIRAC_RECONFIGURE && (st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT)) + if ( flag_config == DIRAC_RECONFIGURE && ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT ) ) { int16_t tmp1, tmp2, tmp3; - ivas_sba_config(ivas_total_brate, st_ivas->sba_analysis_order, -1, &nchan_transport_old, st_ivas->sba_planar, &tmp1, &tmp2, &tmp3); + ivas_sba_config( ivas_total_brate, st_ivas->sba_analysis_order, -1, &nchan_transport_old, st_ivas->sba_planar, &tmp1, &tmp2, &tmp3 ); } /*-----------------------------------------------------------------* @@ -939,33 +935,33 @@ static ivas_error ivas_dirac_rend_config( hDirACRend->hOutSetup = st_ivas->hIntSetup; nchan_out_woLFE = hDirACRend->hOutSetup.nchan_out_woLFE; - if (hDirACRend->hOutSetup.ls_azimuth != NULL && hDirACRend->hOutSetup.ls_elevation != NULL) + if ( hDirACRend->hOutSetup.ls_azimuth != NULL && hDirACRend->hOutSetup.ls_elevation != NULL ) { - mvr2r(hDirACRend->hOutSetup.ls_azimuth, ls_azimuth, nchan_out_woLFE); - mvr2r(hDirACRend->hOutSetup.ls_elevation, ls_elevation, nchan_out_woLFE); + mvr2r( hDirACRend->hOutSetup.ls_azimuth, ls_azimuth, nchan_out_woLFE ); + mvr2r( hDirACRend->hOutSetup.ls_elevation, ls_elevation, nchan_out_woLFE ); } - if (hDirACRend->hOutSetup.ambisonics_order == -1) + if ( hDirACRend->hOutSetup.ambisonics_order == -1 ) { hDirACRend->hOutSetup.ambisonics_order = SBA_HOA3_ORDER; /* Order 3 is used by default in DirAC for SHD processing */ - if (hDirACRend->hOutSetup.output_config == IVAS_AUDIO_CONFIG_MONO || hDirACRend->hOutSetup.output_config == IVAS_AUDIO_CONFIG_STEREO) + if ( hDirACRend->hOutSetup.output_config == IVAS_AUDIO_CONFIG_MONO || hDirACRend->hOutSetup.output_config == IVAS_AUDIO_CONFIG_STEREO ) { hDirACRend->hOutSetup.ambisonics_order = SBA_FOA_ORDER; } } - else if (hDirACRend->hOutSetup.ambisonics_order >= SBA_FOA_ORDER) + else if ( hDirACRend->hOutSetup.ambisonics_order >= SBA_FOA_ORDER ) { - mvr2r(ls_azimuth_4d4, ls_azimuth, DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS); - mvr2r(ls_elevation_4d4, ls_elevation, DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS); + mvr2r( ls_azimuth_4d4, ls_azimuth, DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS ); + mvr2r( ls_elevation_4d4, ls_elevation, DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS ); } - if (hDirACRend->hOutSetup.separateChannelEnabled && (hDirACRend->hOutSetup.output_config == IVAS_AUDIO_CONFIG_5_1 || hDirACRend->hOutSetup.output_config == IVAS_AUDIO_CONFIG_7_1 || hDirACRend->hOutSetup.output_config == IVAS_AUDIO_CONFIG_5_1_2 || hDirACRend->hOutSetup.output_config == IVAS_AUDIO_CONFIG_5_1_4 || hDirACRend->hOutSetup.output_config == IVAS_AUDIO_CONFIG_7_1_4 || (hDirACRend->hOutSetup.output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM && st_ivas->hLsSetupCustom->separate_ch_found))) + if ( hDirACRend->hOutSetup.separateChannelEnabled && ( hDirACRend->hOutSetup.output_config == IVAS_AUDIO_CONFIG_5_1 || hDirACRend->hOutSetup.output_config == IVAS_AUDIO_CONFIG_7_1 || hDirACRend->hOutSetup.output_config == IVAS_AUDIO_CONFIG_5_1_2 || hDirACRend->hOutSetup.output_config == IVAS_AUDIO_CONFIG_5_1_4 || hDirACRend->hOutSetup.output_config == IVAS_AUDIO_CONFIG_7_1_4 || ( hDirACRend->hOutSetup.output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM && st_ivas->hLsSetupCustom->separate_ch_found ) ) ) { /* Remove the channel of the separated signal from the output setup of the spatial synthesis */ hDirACRend->hOutSetup.nchan_out_woLFE--; nchan_out_woLFE = hDirACRend->hOutSetup.nchan_out_woLFE; - mvr2r(&ls_azimuth[hDirACRend->hOutSetup.separateChannelIndex + 1], &ls_azimuth[hDirACRend->hOutSetup.separateChannelIndex], nchan_out_woLFE - hDirACRend->hOutSetup.separateChannelIndex); - mvr2r(&ls_elevation[hDirACRend->hOutSetup.separateChannelIndex + 1], &ls_elevation[hDirACRend->hOutSetup.separateChannelIndex], nchan_out_woLFE - hDirACRend->hOutSetup.separateChannelIndex); + mvr2r( &ls_azimuth[hDirACRend->hOutSetup.separateChannelIndex + 1], &ls_azimuth[hDirACRend->hOutSetup.separateChannelIndex], nchan_out_woLFE - hDirACRend->hOutSetup.separateChannelIndex ); + mvr2r( &ls_elevation[hDirACRend->hOutSetup.separateChannelIndex + 1], &ls_elevation[hDirACRend->hOutSetup.separateChannelIndex], nchan_out_woLFE - hDirACRend->hOutSetup.separateChannelIndex ); } /*-----------------------------------------------------------------* @@ -974,23 +970,23 @@ static ivas_error ivas_dirac_rend_config( st_ivas->nchan_transport = nchan_transport_orig; - if (nchan_transport_orig > 2 && hDirACRend->hOutSetup.is_loudspeaker_setup && st_ivas->renderer_type == RENDERER_DIRAC && !hodirac_flag) + if ( nchan_transport_orig > 2 && hDirACRend->hOutSetup.is_loudspeaker_setup && st_ivas->renderer_type == RENDERER_DIRAC && !hodirac_flag ) { hDirACRend->synthesisConf = DIRAC_SYNTHESIS_PSD_LS; hDirACRend->panningConf = DIRAC_PANNING_VBAP; } - else if ((st_ivas->ivas_format == MASA_FORMAT || st_ivas->mc_mode == MC_MODE_MCMASA) && hDirACRend->hOutSetup.output_config == IVAS_AUDIO_CONFIG_MONO) + else if ( ( st_ivas->ivas_format == MASA_FORMAT || st_ivas->mc_mode == MC_MODE_MCMASA ) && hDirACRend->hOutSetup.output_config == IVAS_AUDIO_CONFIG_MONO ) { hDirACRend->synthesisConf = DIRAC_SYNTHESIS_MONO; hDirACRend->panningConf = DIRAC_PANNING_HOA3; nchan_out_woLFE = 1; } - else if ((st_ivas->ivas_format == MASA_FORMAT || st_ivas->ivas_format == MASA_ISM_FORMAT || st_ivas->mc_mode == MC_MODE_MCMASA) && hDirACRend->hOutSetup.is_loudspeaker_setup) + else if ( ( st_ivas->ivas_format == MASA_FORMAT || st_ivas->ivas_format == MASA_ISM_FORMAT || st_ivas->mc_mode == MC_MODE_MCMASA ) && hDirACRend->hOutSetup.is_loudspeaker_setup ) { hDirACRend->synthesisConf = DIRAC_SYNTHESIS_PSD_LS; hDirACRend->panningConf = DIRAC_PANNING_VBAP; } - else if ((st_ivas->ivas_format == MASA_FORMAT || st_ivas->ivas_format == MASA_ISM_FORMAT) && !hDirACRend->hOutSetup.is_loudspeaker_setup && st_ivas->nchan_transport > 1) + else if ( ( st_ivas->ivas_format == MASA_FORMAT || st_ivas->ivas_format == MASA_ISM_FORMAT ) && !hDirACRend->hOutSetup.is_loudspeaker_setup && st_ivas->nchan_transport > 1 ) { hDirACRend->synthesisConf = DIRAC_SYNTHESIS_PSD_SHD; hDirACRend->panningConf = DIRAC_PANNING_HOA3; @@ -1001,32 +997,32 @@ static ivas_error ivas_dirac_rend_config( hDirACRend->panningConf = DIRAC_PANNING_HOA3; } - if (flag_config == DIRAC_OPEN) + if ( flag_config == DIRAC_OPEN ) { - if ((hDirACRend->frequency_axis = (float *)malloc(hSpatParamRendCom->num_freq_bands * sizeof(float))) == NULL) + if ( ( hDirACRend->frequency_axis = (float *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( float ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } - set_f(hDirACRend->frequency_axis, 0.0f, hSpatParamRendCom->num_freq_bands); - ivas_dirac_dec_get_frequency_axis(hDirACRend->frequency_axis, output_Fs, hSpatParamRendCom->num_freq_bands); + set_f( hDirACRend->frequency_axis, 0.0f, hSpatParamRendCom->num_freq_bands ); + ivas_dirac_dec_get_frequency_axis( hDirACRend->frequency_axis, output_Fs, hSpatParamRendCom->num_freq_bands ); } - if ((st_ivas->ivas_format == MASA_FORMAT || st_ivas->mc_mode == MC_MODE_MCMASA) && hDirACRend->panningConf == DIRAC_PANNING_HOA3 && nchan_transport == 2) + if ( ( st_ivas->ivas_format == MASA_FORMAT || st_ivas->mc_mode == MC_MODE_MCMASA ) && hDirACRend->panningConf == DIRAC_PANNING_HOA3 && nchan_transport == 2 ) { - if ((flag_config == DIRAC_RECONFIGURE && hDirACRend->masa_stereo_type_detect == NULL) || flag_config == DIRAC_OPEN) + if ( ( flag_config == DIRAC_RECONFIGURE && hDirACRend->masa_stereo_type_detect == NULL ) || flag_config == DIRAC_OPEN ) { - if ((hDirACRend->masa_stereo_type_detect = (MASA_STEREO_TYPE_DETECT *)malloc(sizeof(MASA_STEREO_TYPE_DETECT))) == NULL) + if ( ( hDirACRend->masa_stereo_type_detect = (MASA_STEREO_TYPE_DETECT *) malloc( sizeof( MASA_STEREO_TYPE_DETECT ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } } - ivas_masa_init_stereotype_detection(hDirACRend->masa_stereo_type_detect); + ivas_masa_init_stereotype_detection( hDirACRend->masa_stereo_type_detect ); } else { - if (flag_config == DIRAC_RECONFIGURE && hDirACRend->masa_stereo_type_detect != NULL) + if ( flag_config == DIRAC_RECONFIGURE && hDirACRend->masa_stereo_type_detect != NULL ) { - free(hDirACRend->masa_stereo_type_detect); + free( hDirACRend->masa_stereo_type_detect ); } hDirACRend->masa_stereo_type_detect = NULL; } @@ -1037,8 +1033,8 @@ static ivas_error ivas_dirac_rend_config( * (re)configure sub-modules *-----------------------------------------------------------------*/ - /* prototype signal computation */ - if (flag_config == DIRAC_RECONFIGURE) + /* prototype signal computation */ + if ( flag_config == DIRAC_RECONFIGURE ) { num_outputs_dir_old = hDirACRend->num_outputs_dir; num_outputs_diff_old = hDirACRend->num_outputs_diff; @@ -1046,94 +1042,94 @@ static ivas_error ivas_dirac_rend_config( } /* allocate output setup related arrays */ - if (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS) + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS ) { /* Directional and diffuses components in output LS format */ hDirACRend->num_outputs_diff = nchan_out_woLFE; hDirACRend->num_outputs_dir = nchan_out_woLFE; } - else if (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD) + else if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { /* Directional and diffuses components in SHD */ /* Diffuseness components up to 1st order */ - hDirACRend->num_outputs_diff = (min(hDirACRend->hOutSetup.ambisonics_order, 1) + 1) * (min(hDirACRend->hOutSetup.ambisonics_order, 1) + 1); - hDirACRend->num_outputs_dir = ivas_sba_get_nchan(hDirACRend->hOutSetup.ambisonics_order, 0); + hDirACRend->num_outputs_diff = ( min( hDirACRend->hOutSetup.ambisonics_order, 1 ) + 1 ) * ( min( hDirACRend->hOutSetup.ambisonics_order, 1 ) + 1 ); + hDirACRend->num_outputs_dir = ivas_sba_get_nchan( hDirACRend->hOutSetup.ambisonics_order, 0 ); } - else if (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD) + else if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) { hDirACRend->num_outputs_diff = DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS; hDirACRend->num_outputs_dir = nchan_out_woLFE; } - else if (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO) + else if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO ) { hDirACRend->num_outputs_diff = 1; /* There is one output channel in mono */ hDirACRend->num_outputs_dir = 2; /* Two channels are pre-rendered for stereo type detection */ } else { - assert(0 && "DirAC: not existing synthesis methods!"); + assert( 0 && "DirAC: not existing synthesis methods!" ); } - if (flag_config == DIRAC_OPEN) + if ( flag_config == DIRAC_OPEN ) { num_outputs_dir_old = hDirACRend->num_outputs_dir; - if ((hDirACRend->proto_index_dir = (int16_t *)malloc(sizeof(int16_t) * hDirACRend->num_outputs_dir)) == NULL) + if ( ( hDirACRend->proto_index_dir = (int16_t *) malloc( sizeof( int16_t ) * hDirACRend->num_outputs_dir ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } num_outputs_diff_old = hDirACRend->num_outputs_diff; - if ((hDirACRend->proto_index_diff = (int16_t *)malloc(sizeof(int16_t) * hDirACRend->num_outputs_diff)) == NULL) + if ( ( hDirACRend->proto_index_diff = (int16_t *) malloc( sizeof( int16_t ) * hDirACRend->num_outputs_diff ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } } - if (hDirACRend->num_outputs_dir != num_outputs_dir_old && flag_config == DIRAC_RECONFIGURE) + if ( hDirACRend->num_outputs_dir != num_outputs_dir_old && flag_config == DIRAC_RECONFIGURE ) { - free(hDirACRend->proto_index_dir); - if ((hDirACRend->proto_index_dir = (int16_t *)malloc(sizeof(int16_t) * hDirACRend->num_outputs_dir)) == NULL) + free( hDirACRend->proto_index_dir ); + if ( ( hDirACRend->proto_index_dir = (int16_t *) malloc( sizeof( int16_t ) * hDirACRend->num_outputs_dir ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } } - set_s(hDirACRend->proto_index_dir, 0, hDirACRend->num_outputs_dir); + set_s( hDirACRend->proto_index_dir, 0, hDirACRend->num_outputs_dir ); - if (hDirACRend->num_outputs_diff != num_outputs_diff_old && flag_config == DIRAC_RECONFIGURE) + if ( hDirACRend->num_outputs_diff != num_outputs_diff_old && flag_config == DIRAC_RECONFIGURE ) { - free(hDirACRend->proto_index_diff); - if ((hDirACRend->proto_index_diff = (int16_t *)malloc(sizeof(int16_t) * hDirACRend->num_outputs_diff)) == NULL) + free( hDirACRend->proto_index_diff ); + if ( ( hDirACRend->proto_index_diff = (int16_t *) malloc( sizeof( int16_t ) * hDirACRend->num_outputs_diff ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } } - set_s(hDirACRend->proto_index_diff, 0, hDirACRend->num_outputs_diff); + set_s( hDirACRend->proto_index_diff, 0, hDirACRend->num_outputs_diff ); hDirACRend->sba_map_tc = sba_map_tc; - if ((st_ivas->ivas_format == SBA_FORMAT) || (st_ivas->ivas_format == SBA_ISM_FORMAT)) + if ( ( st_ivas->ivas_format == SBA_FORMAT ) || ( st_ivas->ivas_format == SBA_ISM_FORMAT ) ) { - if (st_ivas->sba_order > SBA_FOA_ORDER && ivas_total_brate >= IVAS_512k) + if ( st_ivas->sba_order > SBA_FOA_ORDER && ivas_total_brate >= IVAS_512k ) { hDirACRend->sba_map_tc = sba_map_tc_512; } } - if (nchan_transport == 1) + if ( nchan_transport == 1 ) { hDirACRend->num_protos_ambi = 1; hDirACRend->num_protos_dir = 1; hDirACRend->num_protos_diff = 1; } - else if (nchan_transport == 2) + else if ( nchan_transport == 2 ) { - if (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD) + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { hDirACRend->num_protos_ambi = 2; hDirACRend->num_protos_diff = 1; hDirACRend->num_protos_dir = 2; hDirACRend->proto_index_dir[1] = 1; } - else if (hDirACRend->hOutSetup.output_config == IVAS_AUDIO_CONFIG_MONO) + else if ( hDirACRend->hOutSetup.output_config == IVAS_AUDIO_CONFIG_MONO ) { /* Following the foa rendering for code compatibility */ hDirACRend->num_protos_ambi = 2; @@ -1147,13 +1143,13 @@ static ivas_error ivas_dirac_rend_config( hDirACRend->num_protos_ambi = 2; hDirACRend->num_protos_diff = 3; - for (k = 0; k < hDirACRend->num_outputs_diff; k++) + for ( k = 0; k < hDirACRend->num_outputs_diff; k++ ) { - if (ls_azimuth[k] > 0.0f) + if ( ls_azimuth[k] > 0.0f ) { hDirACRend->proto_index_diff[k] = 1; } - else if (ls_azimuth[k] < 0.0f) + else if ( ls_azimuth[k] < 0.0f ) { hDirACRend->proto_index_diff[k] = 2; } @@ -1163,10 +1159,10 @@ static ivas_error ivas_dirac_rend_config( } } - if (hDirACRend->hOutSetup.is_loudspeaker_setup) + if ( hDirACRend->hOutSetup.is_loudspeaker_setup ) { hDirACRend->num_protos_dir = 3; - mvs2s(hDirACRend->proto_index_diff, hDirACRend->proto_index_dir, nchan_out_woLFE); + mvs2s( hDirACRend->proto_index_diff, hDirACRend->proto_index_dir, nchan_out_woLFE ); } else { @@ -1178,16 +1174,16 @@ static ivas_error ivas_dirac_rend_config( else /* nchan_transport > 2 */ { hDirACRend->num_protos_ambi = 4; - if (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS) + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS ) { hDirACRend->num_protos_diff = hDirACRend->num_outputs_diff; - for (k = 0; k < hDirACRend->num_outputs_diff; k++) + for ( k = 0; k < hDirACRend->num_outputs_diff; k++ ) { hDirACRend->proto_index_diff[k] = k; } hDirACRend->num_protos_dir = hDirACRend->num_outputs_dir; - for (k = 0; k < hDirACRend->num_outputs_dir; k++) + for ( k = 0; k < hDirACRend->num_outputs_dir; k++ ) { hDirACRend->proto_index_dir[k] = k; } @@ -1197,9 +1193,9 @@ static ivas_error ivas_dirac_rend_config( hDirACRend->num_protos_diff = 1; hDirACRend->num_protos_dir = nchan_transport; - for (k = 0; k < min(hDirACRend->num_outputs_dir, hDirACRend->num_protos_dir); k++) + for ( k = 0; k < min( hDirACRend->num_outputs_dir, hDirACRend->num_protos_dir ); k++ ) { - if (hDirACRend->sba_map_tc[k] < hDirACRend->num_outputs_dir) + if ( hDirACRend->sba_map_tc[k] < hDirACRend->num_outputs_dir ) { hDirACRend->proto_index_dir[hDirACRend->sba_map_tc[k]] = k; } @@ -1208,109 +1204,109 @@ static ivas_error ivas_dirac_rend_config( } /* direct/diffuse responses */ - if (flag_config == DIRAC_OPEN) + if ( flag_config == DIRAC_OPEN ) { - if ((hDirACRend->diffuse_response_function = (float *)malloc(sizeof(float) * hDirACRend->num_outputs_dir)) == NULL) + if ( ( hDirACRend->diffuse_response_function = (float *) malloc( sizeof( float ) * hDirACRend->num_outputs_dir ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } } /* reallocate static memory */ - else if (flag_config == DIRAC_RECONFIGURE && hDirACRend->num_outputs_dir != num_outputs_dir_old) + else if ( flag_config == DIRAC_RECONFIGURE && hDirACRend->num_outputs_dir != num_outputs_dir_old ) { - free(hDirACRend->diffuse_response_function); + free( hDirACRend->diffuse_response_function ); hDirACRend->diffuse_response_function = NULL; - if ((hDirACRend->diffuse_response_function = (float *)malloc(sizeof(float) * hDirACRend->num_outputs_dir)) == NULL) + if ( ( hDirACRend->diffuse_response_function = (float *) malloc( sizeof( float ) * hDirACRend->num_outputs_dir ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } } - if ((hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS) || (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD) || (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO)) + if ( ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS ) || ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) || ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO ) ) { - initDiffuseResponses(hDirACRend->diffuse_response_function, nchan_out_woLFE, hDirACRend->hOutSetup.output_config, - hDirACRend->hOutSetup, hDirACRend->hOutSetup.ambisonics_order, st_ivas->ivas_format, &hDirACRend->num_ele_spk_no_diffuse_rendering, st_ivas->transport_config); + initDiffuseResponses( hDirACRend->diffuse_response_function, nchan_out_woLFE, hDirACRend->hOutSetup.output_config, + hDirACRend->hOutSetup, hDirACRend->hOutSetup.ambisonics_order, st_ivas->ivas_format, &hDirACRend->num_ele_spk_no_diffuse_rendering, st_ivas->transport_config ); } else { - initDiffuseResponses(hDirACRend->diffuse_response_function, hDirACRend->num_outputs_dir, IVAS_AUDIO_CONFIG_FOA, - hDirACRend->hOutSetup, hDirACRend->hOutSetup.ambisonics_order, st_ivas->ivas_format, &hDirACRend->num_ele_spk_no_diffuse_rendering, IVAS_AUDIO_CONFIG_INVALID); + initDiffuseResponses( hDirACRend->diffuse_response_function, hDirACRend->num_outputs_dir, IVAS_AUDIO_CONFIG_FOA, + hDirACRend->hOutSetup, hDirACRend->hOutSetup.ambisonics_order, st_ivas->ivas_format, &hDirACRend->num_ele_spk_no_diffuse_rendering, IVAS_AUDIO_CONFIG_INVALID ); } - if (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD) + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) { - if (flag_config == DIRAC_OPEN) + if ( flag_config == DIRAC_OPEN ) { - if ((hDirACRend->hoa_encoder = (float *)malloc(nchan_out_woLFE * hDirACRend->num_outputs_diff * sizeof(float))) == NULL) + if ( ( hDirACRend->hoa_encoder = (float *) malloc( nchan_out_woLFE * hDirACRend->num_outputs_diff * sizeof( float ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } } - else if (flag_config == DIRAC_RECONFIGURE && hDirACRend->hoa_encoder && (hDirACRend->num_outputs_diff != num_outputs_diff_old)) + else if ( flag_config == DIRAC_RECONFIGURE && hDirACRend->hoa_encoder && ( hDirACRend->num_outputs_diff != num_outputs_diff_old ) ) { - free(hDirACRend->hoa_encoder); + free( hDirACRend->hoa_encoder ); hDirACRend->hoa_encoder = NULL; - if ((hDirACRend->hoa_encoder = (float *)malloc(nchan_out_woLFE * hDirACRend->num_outputs_diff * sizeof(float))) == NULL) + if ( ( hDirACRend->hoa_encoder = (float *) malloc( nchan_out_woLFE * hDirACRend->num_outputs_diff * sizeof( float ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } } - set_f(hDirACRend->hoa_encoder, 0.0f, nchan_out_woLFE * hDirACRend->num_outputs_diff); - compute_hoa_encoder_mtx(ls_azimuth, ls_elevation, hDirACRend->hoa_encoder, hDirACRend->num_outputs_diff, hDirACRend->hOutSetup.ambisonics_order); + set_f( hDirACRend->hoa_encoder, 0.0f, nchan_out_woLFE * hDirACRend->num_outputs_diff ); + compute_hoa_encoder_mtx( ls_azimuth, ls_elevation, hDirACRend->hoa_encoder, hDirACRend->num_outputs_diff, hDirACRend->hOutSetup.ambisonics_order ); } else { - if (flag_config == DIRAC_RECONFIGURE && hDirACRend->hoa_encoder) + if ( flag_config == DIRAC_RECONFIGURE && hDirACRend->hoa_encoder ) { - free(hDirACRend->hoa_encoder); + free( hDirACRend->hoa_encoder ); } hDirACRend->hoa_encoder = NULL; } /* VBAP */ - if (flag_config == DIRAC_OPEN) + if ( flag_config == DIRAC_OPEN ) { st_ivas->hVBAPdata = NULL; } - if (hDirACRend->panningConf == DIRAC_PANNING_VBAP) + if ( hDirACRend->panningConf == DIRAC_PANNING_VBAP ) { - if (flag_config == DIRAC_RECONFIGURE && st_ivas->hVBAPdata != NULL) + if ( flag_config == DIRAC_RECONFIGURE && st_ivas->hVBAPdata != NULL ) { - vbap_free_data(&(st_ivas->hVBAPdata)); + vbap_free_data( &( st_ivas->hVBAPdata ) ); } - if ((error = vbap_init_data(&(st_ivas->hVBAPdata), ls_azimuth, ls_elevation, nchan_out_woLFE, st_ivas->ivas_format)) != IVAS_ERR_OK) + if ( ( error = vbap_init_data( &( st_ivas->hVBAPdata ), ls_azimuth, ls_elevation, nchan_out_woLFE, st_ivas->ivas_format ) ) != IVAS_ERR_OK ) { return error; } } - else if (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO) + else if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO ) { - if (flag_config == DIRAC_RECONFIGURE && st_ivas->hVBAPdata != NULL) + if ( flag_config == DIRAC_RECONFIGURE && st_ivas->hVBAPdata != NULL ) { - vbap_free_data(&(st_ivas->hVBAPdata)); + vbap_free_data( &( st_ivas->hVBAPdata ) ); } hDirACRend->hoa_decoder = NULL; } - else if (flag_config == DIRAC_RECONFIGURE && st_ivas->hVBAPdata != NULL) + else if ( flag_config == DIRAC_RECONFIGURE && st_ivas->hVBAPdata != NULL ) { - vbap_free_data(&(st_ivas->hVBAPdata)); + vbap_free_data( &( st_ivas->hVBAPdata ) ); } /* HOA panning/dec */ - if (flag_config == DIRAC_OPEN) + if ( flag_config == DIRAC_OPEN ) { hDirACRend->hoa_decoder = NULL; - if ((hDirACRend->panningConf == DIRAC_PANNING_HOA3) || st_ivas->ivas_format == SBA_FORMAT || (nchan_transport > 2)) + if ( ( hDirACRend->panningConf == DIRAC_PANNING_HOA3 ) || st_ivas->ivas_format == SBA_FORMAT || ( nchan_transport > 2 ) ) { - if (hDirACRend->hOutSetup.is_loudspeaker_setup) + if ( hDirACRend->hOutSetup.is_loudspeaker_setup ) { - if (st_ivas->hoa_dec_mtx != NULL) + if ( st_ivas->hoa_dec_mtx != NULL ) { - free(st_ivas->hoa_dec_mtx); + free( st_ivas->hoa_dec_mtx ); st_ivas->hoa_dec_mtx = NULL; } - if ((error = ivas_sba_get_hoa_dec_matrix(hDirACRend->hOutSetup, &st_ivas->hoa_dec_mtx, hDirACRend->hOutSetup.ambisonics_order)) != IVAS_ERR_OK) + if ( ( error = ivas_sba_get_hoa_dec_matrix( hDirACRend->hOutSetup, &st_ivas->hoa_dec_mtx, hDirACRend->hOutSetup.ambisonics_order ) ) != IVAS_ERR_OK ) { return error; } @@ -1321,39 +1317,39 @@ static ivas_error ivas_dirac_rend_config( } /* decorrelation */ - proto_signal_decorr_on_old = (flag_config == DIRAC_RECONFIGURE) ? hDirACRend->proto_signal_decorr_on : 0; + proto_signal_decorr_on_old = ( flag_config == DIRAC_RECONFIGURE ) ? hDirACRend->proto_signal_decorr_on : 0; hDirACRend->proto_signal_decorr_on = 1; - if ((nchan_transport > 2) && (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS)) + if ( ( nchan_transport > 2 ) && ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS ) ) { /*switch off decorrelation for 4 transport channels*/ hDirACRend->proto_signal_decorr_on = 0; } - if (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO) + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO ) { hDirACRend->proto_signal_decorr_on = 0; } - if ((flag_config == DIRAC_OPEN && hDirACRend->proto_signal_decorr_on) || (flag_config == DIRAC_RECONFIGURE && (hDirACRend->proto_signal_decorr_on && !proto_signal_decorr_on_old))) + if ( ( flag_config == DIRAC_OPEN && hDirACRend->proto_signal_decorr_on ) || ( flag_config == DIRAC_RECONFIGURE && ( hDirACRend->proto_signal_decorr_on && !proto_signal_decorr_on_old ) ) ) { - if ((error = ivas_dirac_dec_decorr_open(&(hDirACRend->h_freq_domain_decorr_ap_params), &(hDirACRend->h_freq_domain_decorr_ap_state), hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff, - hDirACRend->num_protos_diff, hDirACRend->synthesisConf, hDirACRend->frequency_axis, nchan_transport > 2 ? 4 : nchan_transport, output_Fs)) != IVAS_ERR_OK) + if ( ( error = ivas_dirac_dec_decorr_open( &( hDirACRend->h_freq_domain_decorr_ap_params ), &( hDirACRend->h_freq_domain_decorr_ap_state ), hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff, + hDirACRend->num_protos_diff, hDirACRend->synthesisConf, hDirACRend->frequency_axis, nchan_transport > 2 ? 4 : nchan_transport, output_Fs ) ) != IVAS_ERR_OK ) { return error; } } - else if (flag_config == DIRAC_RECONFIGURE && (!hDirACRend->proto_signal_decorr_on && proto_signal_decorr_on_old)) + else if ( flag_config == DIRAC_RECONFIGURE && ( !hDirACRend->proto_signal_decorr_on && proto_signal_decorr_on_old ) ) { - ivas_dirac_dec_decorr_close(&hDirACRend->h_freq_domain_decorr_ap_params, &hDirACRend->h_freq_domain_decorr_ap_state); + ivas_dirac_dec_decorr_close( &hDirACRend->h_freq_domain_decorr_ap_params, &hDirACRend->h_freq_domain_decorr_ap_state ); } - else if (flag_config == DIRAC_RECONFIGURE && hDirACRend->proto_signal_decorr_on && proto_signal_decorr_on_old) + else if ( flag_config == DIRAC_RECONFIGURE && hDirACRend->proto_signal_decorr_on && proto_signal_decorr_on_old ) { - if (nchan_transport != nchan_transport_old || hDirACRend->num_outputs_diff != num_outputs_diff_old || flag_config_inp == DIRAC_RECONFIGURE_MODE) + if ( nchan_transport != nchan_transport_old || hDirACRend->num_outputs_diff != num_outputs_diff_old || flag_config_inp == DIRAC_RECONFIGURE_MODE ) { /* close and reopen the decorrelator */ - ivas_dirac_dec_decorr_close(&hDirACRend->h_freq_domain_decorr_ap_params, &hDirACRend->h_freq_domain_decorr_ap_state); + ivas_dirac_dec_decorr_close( &hDirACRend->h_freq_domain_decorr_ap_params, &hDirACRend->h_freq_domain_decorr_ap_state ); - if ((error = ivas_dirac_dec_decorr_open(&(hDirACRend->h_freq_domain_decorr_ap_params), &(hDirACRend->h_freq_domain_decorr_ap_state), hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff, - hDirACRend->num_protos_diff, hDirACRend->synthesisConf, hDirACRend->frequency_axis, nchan_transport > 2 ? 4 : nchan_transport, output_Fs)) != IVAS_ERR_OK) + if ( ( error = ivas_dirac_dec_decorr_open( &( hDirACRend->h_freq_domain_decorr_ap_params ), &( hDirACRend->h_freq_domain_decorr_ap_state ), hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff, + hDirACRend->num_protos_diff, hDirACRend->synthesisConf, hDirACRend->frequency_axis, nchan_transport > 2 ? 4 : nchan_transport, output_Fs ) ) != IVAS_ERR_OK ) { return error; } @@ -1361,26 +1357,26 @@ static ivas_error ivas_dirac_rend_config( } /* output synthesis */ - if (flag_config == DIRAC_OPEN) + if ( flag_config == DIRAC_OPEN ) { - if ((ivas_dirac_dec_output_synthesis_open(hSpatParamRendCom, hDirACRend, st_ivas->renderer_type, nchan_transport, output_Fs, hodirac_flag)) != IVAS_ERR_OK) + if ( ( ivas_dirac_dec_output_synthesis_open( hSpatParamRendCom, hDirACRend, st_ivas->renderer_type, nchan_transport, output_Fs, hodirac_flag ) ) != IVAS_ERR_OK ) { return error; } hDirACRend->h_output_synthesis_psd_params.use_onset_filters = hDirACRend->proto_signal_decorr_on; } - else if ((flag_config == DIRAC_RECONFIGURE) && ((nchan_transport != nchan_transport_old) || (hDirACRend->num_outputs_diff != num_outputs_diff_old))) + else if ( ( flag_config == DIRAC_RECONFIGURE ) && ( ( nchan_transport != nchan_transport_old ) || ( hDirACRend->num_outputs_diff != num_outputs_diff_old ) ) ) { - ivas_dirac_dec_output_synthesis_close(hDirACRend); + ivas_dirac_dec_output_synthesis_close( hDirACRend ); - if ((ivas_dirac_dec_output_synthesis_open(hSpatParamRendCom, hDirACRend, st_ivas->renderer_type, nchan_transport, output_Fs, hodirac_flag)) != IVAS_ERR_OK) + if ( ( ivas_dirac_dec_output_synthesis_open( hSpatParamRendCom, hDirACRend, st_ivas->renderer_type, nchan_transport, output_Fs, hodirac_flag ) ) != IVAS_ERR_OK ) { return error; } hDirACRend->h_output_synthesis_psd_params.use_onset_filters = hDirACRend->proto_signal_decorr_on; } - if (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD || hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD) + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD || hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { hDirACRend->h_output_synthesis_psd_params.use_onset_filters = 0; } @@ -1389,97 +1385,97 @@ static ivas_error ivas_dirac_rend_config( * memory allocation *-----------------------------------------------------------------*/ - if (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD) + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { - if (flag_config == DIRAC_RECONFIGURE && hDirACRend->proto_frame_f) + if ( flag_config == DIRAC_RECONFIGURE && hDirACRend->proto_frame_f ) { - free(hDirACRend->proto_frame_f); + free( hDirACRend->proto_frame_f ); } hDirACRend->proto_frame_f = NULL; } else { - if (flag_config == DIRAC_OPEN || (flag_config == DIRAC_RECONFIGURE && hDirACRend->proto_frame_f == NULL)) + if ( flag_config == DIRAC_OPEN || ( flag_config == DIRAC_RECONFIGURE && hDirACRend->proto_frame_f == NULL ) ) { - if ((hDirACRend->proto_frame_f = (float *)malloc(sizeof(float) * 2 * hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands)) == NULL) + if ( ( hDirACRend->proto_frame_f = (float *) malloc( sizeof( float ) * 2 * hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } } - else if (flag_config == DIRAC_RECONFIGURE && (hDirACRend->num_protos_diff != num_protos_diff_old)) + else if ( flag_config == DIRAC_RECONFIGURE && ( hDirACRend->num_protos_diff != num_protos_diff_old ) ) { proto_frame_f_old = hDirACRend->proto_frame_f; - free(proto_frame_f_old); - if ((hDirACRend->proto_frame_f = (float *)malloc(sizeof(float) * 2 * hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands)) == NULL) + free( proto_frame_f_old ); + if ( ( hDirACRend->proto_frame_f = (float *) malloc( sizeof( float ) * 2 * hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } } } - if (flag_config == DIRAC_OPEN) + if ( flag_config == DIRAC_OPEN ) { hDirACRend->buffer_energy = NULL; } - if ((flag_config == DIRAC_OPEN && hDirAC->hConfig->dec_param_estim == TRUE) || (flag_config == DIRAC_RECONFIGURE && (hDirAC->hConfig->dec_param_estim == TRUE && dec_param_estim_old == FALSE))) + if ( ( flag_config == DIRAC_OPEN && hDirAC->hConfig->dec_param_estim == TRUE ) || ( flag_config == DIRAC_RECONFIGURE && ( hDirAC->hConfig->dec_param_estim == TRUE && dec_param_estim_old == FALSE ) ) ) { hDirACRend->index_buffer_intensity = 0; - for (i = 0; i < DIRAC_NUM_DIMS; i++) + for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) { - for (j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++) + for ( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) { - if ((hDirACRend->buffer_intensity_real[i][j] = (float *)malloc(CLDFB_NO_CHANNELS_MAX * sizeof(float))) == NULL) + if ( ( hDirACRend->buffer_intensity_real[i][j] = (float *) malloc( CLDFB_NO_CHANNELS_MAX * sizeof( float ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } - set_f(hDirACRend->buffer_intensity_real[i][j], 0.0f, CLDFB_NO_CHANNELS_MAX); + set_f( hDirACRend->buffer_intensity_real[i][j], 0.0f, CLDFB_NO_CHANNELS_MAX ); } } - if (hDirACRend->buffer_energy == NULL) + if ( hDirACRend->buffer_energy == NULL ) { - if ((hDirACRend->buffer_energy = (float *)malloc(DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX * sizeof(float))) == NULL) + if ( ( hDirACRend->buffer_energy = (float *) malloc( DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX * sizeof( float ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } } - set_f(hDirACRend->buffer_energy, 0.0f, DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX); + set_f( hDirACRend->buffer_energy, 0.0f, DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX ); } - else if ((flag_config == DIRAC_OPEN && hDirAC->hConfig->dec_param_estim == FALSE) || (flag_config == DIRAC_RECONFIGURE && (hDirAC->hConfig->dec_param_estim == FALSE && dec_param_estim_old == TRUE))) + else if ( ( flag_config == DIRAC_OPEN && hDirAC->hConfig->dec_param_estim == FALSE ) || ( flag_config == DIRAC_RECONFIGURE && ( hDirAC->hConfig->dec_param_estim == FALSE && dec_param_estim_old == TRUE ) ) ) { - for (i = 0; i < DIRAC_NUM_DIMS; i++) + for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) { - for (j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++) + for ( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) { - if (flag_config == DIRAC_RECONFIGURE && hDirACRend->buffer_intensity_real[i][j]) + if ( flag_config == DIRAC_RECONFIGURE && hDirACRend->buffer_intensity_real[i][j] ) { - free(hDirACRend->buffer_intensity_real[i][j]); + free( hDirACRend->buffer_intensity_real[i][j] ); } hDirACRend->buffer_intensity_real[i][j] = NULL; } } - if (hDirACRend->buffer_energy != NULL) + if ( hDirACRend->buffer_energy != NULL ) { - free(hDirACRend->buffer_energy); + free( hDirACRend->buffer_energy ); hDirACRend->buffer_energy = NULL; } } /* output synthesis */ - ivas_dirac_dec_output_synthesis_init(hSpatParamRendCom, hDirACRend, nchan_out_woLFE, hodirac_flag); + ivas_dirac_dec_output_synthesis_init( hSpatParamRendCom, hDirACRend, nchan_out_woLFE, hodirac_flag ); /* Allocate stack memory */ - if (flag_config != DIRAC_OPEN) + if ( flag_config != DIRAC_OPEN ) { - ivas_dirac_free_mem(&(hDirACRend->stack_mem)); + ivas_dirac_free_mem( &( hDirACRend->stack_mem ) ); } - if ((error = ivas_dirac_alloc_mem(hDirACRend, st_ivas->renderer_type, hSpatParamRendCom->num_freq_bands, &(hDirACRend->stack_mem), hodirac_flag)) != IVAS_ERR_OK) + if ( ( error = ivas_dirac_alloc_mem( hDirACRend, st_ivas->renderer_type, hSpatParamRendCom->num_freq_bands, &( hDirACRend->stack_mem ), hodirac_flag ) ) != IVAS_ERR_OK ) { return error; } - if (flag_config == DIRAC_OPEN) + if ( flag_config == DIRAC_OPEN ) { st_ivas->hDirACRend = hDirACRend; } @@ -1515,14 +1511,17 @@ ivas_error ivas_dirac_dec_config_fx( /* Solve and setup flags for inits */ dec_config_flag = ( EQ_16( flag_config_inp, DIRAC_RECONFIGURE_MODE ) ) ? DIRAC_RECONFIGURE : flag_config_inp; - output_Fs = st_ivas->hDecoderConfig->output_Fs; move32(); + output_Fs = st_ivas->hDecoderConfig->output_Fs; + move32(); hodirac_flag = ivas_get_hodirac_flag_fx( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order ); dec_param_estim_old = ( dec_config_flag == DIRAC_RECONFIGURE ) ? st_ivas->hDirAC->hConfig->dec_param_estim : FALSE; - sparfoa_flag = 0; move16(); + sparfoa_flag = 0; + move16(); IF( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_FOA && st_ivas->ivas_format == SBA_FORMAT && !hodirac_flag ) { - sparfoa_flag = 1; move16(); + sparfoa_flag = 1; + move16(); } IF( ( error = ivas_dirac_dec_config_internal_fx( st_ivas, dec_config_flag ) ) != IVAS_ERR_OK ) @@ -1531,26 +1530,32 @@ ivas_error ivas_dirac_dec_config_fx( } /* This is required for parambin */ - test(); test(); - IF( EQ_16(st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC) || EQ_16(st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM) || EQ_16(st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC )) + test(); + test(); + IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_16( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) { - st_ivas->hDirAC->hConfig->dec_param_estim = FALSE; move16(); + st_ivas->hDirAC->hConfig->dec_param_estim = FALSE; + move16(); } - dec_param_estim_new = st_ivas->hDirAC->hConfig->dec_param_estim; move16(); + dec_param_estim_new = st_ivas->hDirAC->hConfig->dec_param_estim; + move16(); /* Setup renderers and meta */ /* First, free everything if in reconfig and not the active renderer */ - need_parambin = 0; move16(); + need_parambin = 0; + move16(); SWITCH( st_ivas->renderer_type ) { case RENDERER_BINAURAL_PARAMETRIC: case RENDERER_BINAURAL_PARAMETRIC_ROOM: case RENDERER_STEREO_PARAMETRIC: - need_parambin = 1; move16(); + need_parambin = 1; + move16(); BREAK; default: - need_parambin = 0; move16(); + need_parambin = 0; + move16(); } IF( !need_parambin ) @@ -1558,7 +1563,8 @@ ivas_error ivas_dirac_dec_config_fx( ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); } - need_dirac_rend = 0; move16(); + need_dirac_rend = 0; + move16(); SWITCH( st_ivas->renderer_type ) { case RENDERER_DIRAC: @@ -1568,10 +1574,12 @@ ivas_error ivas_dirac_dec_config_fx( case RENDERER_SBA_LINEAR_DEC: case RENDERER_OSBA_AMBI: case RENDERER_OSBA_LS: - need_dirac_rend = 1; move16(); + need_dirac_rend = 1; + move16(); BREAK; default: - need_dirac_rend = 0; move16(); + need_dirac_rend = 0; + move16(); } IF( !need_dirac_rend ) @@ -1598,7 +1606,7 @@ ivas_error ivas_dirac_dec_config_fx( IF( need_parambin ) { - IF( NE_16(st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC )) + IF( NE_16( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) { /*WIP*/ IF( ( error = ivas_dirac_dec_binaural_copy_hrtfs( &st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) @@ -1671,25 +1679,25 @@ ivas_error ivas_dirac_dec_config( error = IVAS_ERR_OK; /* Solve and setup flags for inits */ - dec_config_flag = (flag_config_inp == DIRAC_RECONFIGURE_MODE) ? DIRAC_RECONFIGURE : flag_config_inp; + dec_config_flag = ( flag_config_inp == DIRAC_RECONFIGURE_MODE ) ? DIRAC_RECONFIGURE : flag_config_inp; output_Fs = st_ivas->hDecoderConfig->output_Fs; - hodirac_flag = ivas_get_hodirac_flag(st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order); - dec_param_estim_old = (dec_config_flag == DIRAC_RECONFIGURE) ? st_ivas->hDirAC->hConfig->dec_param_estim : FALSE; + hodirac_flag = ivas_get_hodirac_flag( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order ); + dec_param_estim_old = ( dec_config_flag == DIRAC_RECONFIGURE ) ? st_ivas->hDirAC->hConfig->dec_param_estim : FALSE; sparfoa_flag = 0; - if (st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_FOA && st_ivas->ivas_format == SBA_FORMAT && !hodirac_flag) + if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_FOA && st_ivas->ivas_format == SBA_FORMAT && !hodirac_flag ) { sparfoa_flag = 1; } - if ((error = ivas_dirac_dec_config_internal(st_ivas, dec_config_flag)) != IVAS_ERR_OK) + if ( ( error = ivas_dirac_dec_config_internal( st_ivas, dec_config_flag ) ) != IVAS_ERR_OK ) { return error; } /* This is required for parambin */ - if (st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC) + if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) { st_ivas->hDirAC->hConfig->dec_param_estim = FALSE; } @@ -1699,74 +1707,74 @@ ivas_error ivas_dirac_dec_config( /* Setup renderers and meta */ /* First, free everything if in reconfig and not the active renderer */ need_parambin = 0; - switch (st_ivas->renderer_type) + switch ( st_ivas->renderer_type ) { - case RENDERER_BINAURAL_PARAMETRIC: - case RENDERER_BINAURAL_PARAMETRIC_ROOM: - case RENDERER_STEREO_PARAMETRIC: - need_parambin = 1; - break; - default: - need_parambin = 0; + case RENDERER_BINAURAL_PARAMETRIC: + case RENDERER_BINAURAL_PARAMETRIC_ROOM: + case RENDERER_STEREO_PARAMETRIC: + need_parambin = 1; + break; + default: + need_parambin = 0; } - if (!need_parambin) + if ( !need_parambin ) { - ivas_dirac_dec_close_binaural_data(&st_ivas->hDiracDecBin); + ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); } need_dirac_rend = 0; - switch (st_ivas->renderer_type) + switch ( st_ivas->renderer_type ) { - case RENDERER_DIRAC: - case RENDERER_BINAURAL_FASTCONV: - case RENDERER_BINAURAL_FASTCONV_ROOM: - case RENDERER_SBA_LINEAR_ENC: - case RENDERER_SBA_LINEAR_DEC: - case RENDERER_OSBA_AMBI: - case RENDERER_OSBA_LS: - need_dirac_rend = 1; - break; - default: - need_dirac_rend = 0; + case RENDERER_DIRAC: + case RENDERER_BINAURAL_FASTCONV: + case RENDERER_BINAURAL_FASTCONV_ROOM: + case RENDERER_SBA_LINEAR_ENC: + case RENDERER_SBA_LINEAR_DEC: + case RENDERER_OSBA_AMBI: + case RENDERER_OSBA_LS: + need_dirac_rend = 1; + break; + default: + need_dirac_rend = 0; } - if (!need_dirac_rend) + if ( !need_dirac_rend ) { - ivas_dirac_rend_close(&st_ivas->hDirACRend); + ivas_dirac_rend_close( &st_ivas->hDirACRend ); } - if (!sparfoa_flag) + if ( !sparfoa_flag ) { common_rend_config_flag = st_ivas->hSpatParamRendCom == NULL ? DIRAC_OPEN : flag_config_inp; - if ((error = ivas_spat_hSpatParamRendCom_config(&st_ivas->hSpatParamRendCom, common_rend_config_flag, dec_param_estim_new, - st_ivas->ivas_format, st_ivas->mc_mode, output_Fs, hodirac_flag, 0)) != IVAS_ERR_OK) + if ( ( error = ivas_spat_hSpatParamRendCom_config( &st_ivas->hSpatParamRendCom, common_rend_config_flag, dec_param_estim_new, + st_ivas->ivas_format, st_ivas->mc_mode, output_Fs, hodirac_flag, 0 ) ) != IVAS_ERR_OK ) { return error; } - if (need_dirac_rend) + if ( need_dirac_rend ) { rend_config_flag = st_ivas->hDirACRend == NULL ? DIRAC_OPEN : flag_config_inp; - if ((error = ivas_dirac_rend_config(st_ivas, rend_config_flag, dec_param_estim_old)) != IVAS_ERR_OK) + if ( ( error = ivas_dirac_rend_config( st_ivas, rend_config_flag, dec_param_estim_old ) ) != IVAS_ERR_OK ) { return error; } } - if (need_parambin) + if ( need_parambin ) { - if (st_ivas->renderer_type != RENDERER_STEREO_PARAMETRIC) + if ( st_ivas->renderer_type != RENDERER_STEREO_PARAMETRIC ) { - if ((error = ivas_dirac_dec_binaural_copy_hrtfs(&st_ivas->hHrtfParambin)) != IVAS_ERR_OK) + if ( ( error = ivas_dirac_dec_binaural_copy_hrtfs( &st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) { return error; } } - if (st_ivas->hDiracDecBin == NULL) + if ( st_ivas->hDiracDecBin == NULL ) { - if ((error = ivas_dirac_dec_init_binaural_data(st_ivas, st_ivas->hHrtfParambin)) != IVAS_ERR_OK) + if ( ( error = ivas_dirac_dec_init_binaural_data( st_ivas, st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) { return error; } @@ -1774,33 +1782,33 @@ ivas_error ivas_dirac_dec_config( else { /* This is required to keep BE in rate switching. This probably means that 1TC and 2TC MASA perform differently. */ - if (st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_params != NULL && !(st_ivas->ivas_format == MASA_FORMAT && st_ivas->nSCE > 0)) + if ( st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_params != NULL && !( st_ivas->ivas_format == MASA_FORMAT && st_ivas->nSCE > 0 ) ) { - ivas_dirac_dec_decorr_close(&st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_params, &st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_state); + ivas_dirac_dec_decorr_close( &st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_params, &st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_state ); } - if ((error = ivas_td_decorr_reconfig_dec(st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &(st_ivas->hDiracDecBin->hTdDecorr), &(st_ivas->hDiracDecBin->useTdDecorr))) != IVAS_ERR_OK) + if ( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( st_ivas->hDiracDecBin->hTdDecorr ), &( st_ivas->hDiracDecBin->useTdDecorr ) ) ) != IVAS_ERR_OK ) { return error; } - if (!st_ivas->hDiracDecBin->useTdDecorr) + if ( !st_ivas->hDiracDecBin->useTdDecorr ) { - if (st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_params == NULL) + if ( st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_params == NULL ) { float frequency_axis[CLDFB_NO_CHANNELS_MAX]; - ivas_dirac_dec_get_frequency_axis(frequency_axis, st_ivas->hDecoderConfig->output_Fs, st_ivas->hSpatParamRendCom->num_freq_bands); - if ((error = ivas_dirac_dec_decorr_open(&(st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_params), &(st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_state), st_ivas->hSpatParamRendCom->num_freq_bands, BINAURAL_CHANNELS, BINAURAL_CHANNELS, - DIRAC_SYNTHESIS_PSD_LS, frequency_axis, BINAURAL_CHANNELS, st_ivas->hDecoderConfig->output_Fs)) != IVAS_ERR_OK) + ivas_dirac_dec_get_frequency_axis( frequency_axis, st_ivas->hDecoderConfig->output_Fs, st_ivas->hSpatParamRendCom->num_freq_bands ); + if ( ( error = ivas_dirac_dec_decorr_open( &( st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_params ), &( st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_state ), st_ivas->hSpatParamRendCom->num_freq_bands, BINAURAL_CHANNELS, BINAURAL_CHANNELS, + DIRAC_SYNTHESIS_PSD_LS, frequency_axis, BINAURAL_CHANNELS, st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) { return error; } } } - st_ivas->hDiracDecBin->reqularizationFactor = configure_reqularization_factor(st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate); + st_ivas->hDiracDecBin->reqularizationFactor = configure_reqularization_factor( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate ); } } } @@ -1843,11 +1851,11 @@ void ivas_dirac_dec_close( #ifdef IVAS_FLOAT_FIXED void ivas_dirac_dec_close_fx( - DIRAC_DEC_HANDLE *hDirAC_out) + DIRAC_DEC_HANDLE *hDirAC_out ) { DIRAC_DEC_HANDLE hDirAC; - IF (hDirAC_out == NULL || *hDirAC_out == NULL) + IF( hDirAC_out == NULL || *hDirAC_out == NULL ) { return; } @@ -1855,13 +1863,13 @@ void ivas_dirac_dec_close_fx( hDirAC = *hDirAC_out; /* Config & CLDFB */ - IF (hDirAC->hConfig != NULL) + IF( hDirAC->hConfig != NULL ) { - free(hDirAC->hConfig); + free( hDirAC->hConfig ); hDirAC->hConfig = NULL; } - free(*hDirAC_out); + free( *hDirAC_out ); *hDirAC_out = NULL; return; @@ -2683,29 +2691,29 @@ void ivas_qmetadata_to_dirac( int16_t idx_sec = 0; int16_t no_secs = 1; - q_direction = &(hQMetaData->q_direction[0]); + q_direction = &( hQMetaData->q_direction[0] ); hSpatParamRendCom->numParametricDirections = hQMetaData->no_directions; hSpatParamRendCom->numSimultaneousDirections = hSpatParamRendCom->numParametricDirections + hSpatParamRendCom->numIsmDirections; - if (hMasa != NULL && ivas_total_brate > IVAS_SID_5k2) + if ( hMasa != NULL && ivas_total_brate > IVAS_SID_5k2 ) { int16_t meta_write_index; band_mapping = hMasa->data.band_mapping; - for (block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; ++block) + for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; ++block ) { - meta_write_index = (hSpatParamRendCom->dirac_bs_md_write_idx + block) % hSpatParamRendCom->dirac_md_buffer_length; + meta_write_index = ( hSpatParamRendCom->dirac_bs_md_write_idx + block ) % hSpatParamRendCom->dirac_md_buffer_length; - for (band = 0; band < hMasa->config.numCodingBands; ++band) + for ( band = 0; band < hMasa->config.numCodingBands; ++band ) { - for (b = MASA_band_grouping_24[band_mapping[band]]; b < MASA_band_grouping_24[band_mapping[band + 1]]; ++b) + for ( b = MASA_band_grouping_24[band_mapping[band]]; b < MASA_band_grouping_24[band_mapping[band + 1]]; ++b ) { - hSpatParamRendCom->azimuth[meta_write_index][b] = (int16_t)q_direction->band_data[band].azimuth[block]; - hSpatParamRendCom->elevation[meta_write_index][b] = (int16_t)q_direction->band_data[band].elevation[block]; + hSpatParamRendCom->azimuth[meta_write_index][b] = (int16_t) q_direction->band_data[band].azimuth[block]; + hSpatParamRendCom->elevation[meta_write_index][b] = (int16_t) q_direction->band_data[band].elevation[block]; hSpatParamRendCom->energy_ratio1[meta_write_index][b] = q_direction->band_data[band].energy_ratio[block]; hSpatParamRendCom->diffuseness_vector[meta_write_index][b] = 1.0f - q_direction->band_data[band].energy_ratio[block]; - if (q_direction->coherence_band_data != NULL) + if ( q_direction->coherence_band_data != NULL ) { hSpatParamRendCom->spreadCoherence[meta_write_index][b] = q_direction->coherence_band_data[band].spread_coherence[block] / 255.0f; } @@ -2714,7 +2722,7 @@ void ivas_qmetadata_to_dirac( hSpatParamRendCom->spreadCoherence[meta_write_index][b] = 0.0f; } - if (hQMetaData->surcoh_band_data != NULL) + if ( hQMetaData->surcoh_band_data != NULL ) { hSpatParamRendCom->surroundingCoherence[meta_write_index][b] = hQMetaData->surcoh_band_data[band].surround_coherence[block] / 255.0f; } @@ -2726,29 +2734,29 @@ void ivas_qmetadata_to_dirac( } } - if (hQMetaData->no_directions == 2) + if ( hQMetaData->no_directions == 2 ) { - q_direction = &(hQMetaData->q_direction[1]); - for (block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; ++block) + q_direction = &( hQMetaData->q_direction[1] ); + for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; ++block ) { - meta_write_index = (hSpatParamRendCom->dirac_bs_md_write_idx + block) % hSpatParamRendCom->dirac_md_buffer_length; + meta_write_index = ( hSpatParamRendCom->dirac_bs_md_write_idx + block ) % hSpatParamRendCom->dirac_md_buffer_length; - for (band = 0; band < hMasa->config.numCodingBands; ++band) + for ( band = 0; band < hMasa->config.numCodingBands; ++band ) { - for (b = MASA_band_grouping_24[band_mapping[band]]; b < MASA_band_grouping_24[band_mapping[band + 1]]; ++b) + for ( b = MASA_band_grouping_24[band_mapping[band]]; b < MASA_band_grouping_24[band_mapping[band + 1]]; ++b ) { - hSpatParamRendCom->azimuth2[meta_write_index][b] = (int16_t)q_direction->band_data[band].azimuth[block]; - hSpatParamRendCom->elevation2[meta_write_index][b] = (int16_t)q_direction->band_data[band].elevation[block]; + hSpatParamRendCom->azimuth2[meta_write_index][b] = (int16_t) q_direction->band_data[band].azimuth[block]; + hSpatParamRendCom->elevation2[meta_write_index][b] = (int16_t) q_direction->band_data[band].elevation[block]; hSpatParamRendCom->energy_ratio2[meta_write_index][b] = q_direction->band_data[band].energy_ratio[block]; hSpatParamRendCom->diffuseness_vector[meta_write_index][b] -= q_direction->band_data[band].energy_ratio[block]; /* Sanitize diffuseness for rare cases where floating point inaccuracy could result in negative diffuseness. */ - if (hSpatParamRendCom->diffuseness_vector[meta_write_index][b] < 0.0f) + if ( hSpatParamRendCom->diffuseness_vector[meta_write_index][b] < 0.0f ) { hSpatParamRendCom->diffuseness_vector[meta_write_index][b] = 0.0f; } - if (q_direction->coherence_band_data != NULL) + if ( q_direction->coherence_band_data != NULL ) { hSpatParamRendCom->spreadCoherence2[meta_write_index][b] = q_direction->coherence_band_data[band].spread_coherence[block] / 255.0f; } @@ -2760,16 +2768,16 @@ void ivas_qmetadata_to_dirac( } } } - else if (hSpatParamRendCom->azimuth2 != NULL && hSpatParamRendCom->elevation2 != NULL && hSpatParamRendCom->energy_ratio2 != NULL && hSpatParamRendCom->spreadCoherence2 != NULL) + else if ( hSpatParamRendCom->azimuth2 != NULL && hSpatParamRendCom->elevation2 != NULL && hSpatParamRendCom->energy_ratio2 != NULL && hSpatParamRendCom->spreadCoherence2 != NULL ) { /* zero out old dir2 data */ - for (block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; ++block) + for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; ++block ) { - meta_write_index = (hSpatParamRendCom->dirac_bs_md_write_idx + block) % hSpatParamRendCom->dirac_md_buffer_length; - set_s(hSpatParamRendCom->azimuth2[meta_write_index], 0, hSpatParamRendCom->num_freq_bands); - set_s(hSpatParamRendCom->elevation2[meta_write_index], 0, hSpatParamRendCom->num_freq_bands); - set_zero(hSpatParamRendCom->energy_ratio2[meta_write_index], hSpatParamRendCom->num_freq_bands); - set_zero(hSpatParamRendCom->spreadCoherence2[meta_write_index], hSpatParamRendCom->num_freq_bands); + meta_write_index = ( hSpatParamRendCom->dirac_bs_md_write_idx + block ) % hSpatParamRendCom->dirac_md_buffer_length; + set_s( hSpatParamRendCom->azimuth2[meta_write_index], 0, hSpatParamRendCom->num_freq_bands ); + set_s( hSpatParamRendCom->elevation2[meta_write_index], 0, hSpatParamRendCom->num_freq_bands ); + set_zero( hSpatParamRendCom->energy_ratio2[meta_write_index], hSpatParamRendCom->num_freq_bands ); + set_zero( hSpatParamRendCom->spreadCoherence2[meta_write_index], hSpatParamRendCom->num_freq_bands ); } } } @@ -2785,18 +2793,18 @@ void ivas_qmetadata_to_dirac( nbands = hDirAC->band_grouping[hDirAC->hConfig->nbands]; band_grouping = hDirAC->band_grouping; - if (ivas_total_brate <= IVAS_SID_5k2 && ivas_format != SBA_FORMAT) + if ( ivas_total_brate <= IVAS_SID_5k2 && ivas_format != SBA_FORMAT ) { /* SID/zero-frame: 1 direction, 5 bands, nblocks re-generated out of SID decoder*/ start_band = 0; hDirAC->hConfig->nbands = 5; - ivas_dirac_config_bands(hDirAC->band_grouping, hDirAC->hConfig->nbands, nbands, NULL, 0, 0, NULL); + ivas_dirac_config_bands( hDirAC->band_grouping, hDirAC->hConfig->nbands, nbands, NULL, 0, 0, NULL ); nbands = 5; } else { start_band = hDirAC->hConfig->enc_param_start_band; - if (ivas_format == SBA_FORMAT) + if ( ivas_format == SBA_FORMAT ) { hDirAC->hConfig->nbands = IVAS_MAX_NUM_BANDS; } @@ -2805,10 +2813,10 @@ void ivas_qmetadata_to_dirac( hDirAC->hConfig->nbands = q_direction->cfg.nbands; } - ivas_dirac_config_bands(hDirAC->band_grouping, hDirAC->hConfig->nbands, nbands, dirac_to_spar_md_bands, hQMetaData->useLowerBandRes, hDirAC->hConfig->enc_param_start_band, hDirAC->hFbMdft); + ivas_dirac_config_bands( hDirAC->band_grouping, hDirAC->hConfig->nbands, nbands, dirac_to_spar_md_bands, hQMetaData->useLowerBandRes, hDirAC->hConfig->enc_param_start_band, hDirAC->hFbMdft ); nbands = hDirAC->hConfig->nbands; - if (hQMetaData->q_direction[0].cfg.nblocks == 0) + if ( hQMetaData->q_direction[0].cfg.nblocks == 0 ) { /* No transmission -> no copy from qmetadata buffers*/ nbands = start_band; @@ -2816,15 +2824,15 @@ void ivas_qmetadata_to_dirac( } /* Low-Bands with no spatial data transmitted, analysis at decoder side */ - for (band = 0; band < start_band; band++) + for ( band = 0; band < start_band; band++ ) { band_start = band_grouping[band]; band_end = band_grouping[band + 1]; tmp_write_idx_param_band = hSpatParamRendCom->dirac_bs_md_write_idx; - for (block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++) + for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) { - for (b = band_start; b < band_end; b++) + for ( b = band_start; b < band_end; b++ ) { tmp_write_idx_band = tmp_write_idx_param_band; hSpatParamRendCom->spreadCoherence[block][b] = 0.0f; @@ -2837,26 +2845,26 @@ void ivas_qmetadata_to_dirac( hSpatParamRendCom->spreadCoherence[tmp_write_idx_band][b] = 0.0f; hSpatParamRendCom->surroundingCoherence[tmp_write_idx_band][b] = 0.0f; hSpatParamRendCom->energy_ratio1[tmp_write_idx_band][b] = 0; - tmp_write_idx_band = (tmp_write_idx_band + 1) % hSpatParamRendCom->dirac_md_buffer_length; + tmp_write_idx_band = ( tmp_write_idx_band + 1 ) % hSpatParamRendCom->dirac_md_buffer_length; } } } /* Bands with spatial data transmitted */ - if (hodirac_flag) + if ( hodirac_flag ) { no_secs = DIRAC_HO_NUMSECTORS; } - for (idx_sec = 0; idx_sec < no_secs; idx_sec++) + for ( idx_sec = 0; idx_sec < no_secs; idx_sec++ ) { - for (band = start_band; band < nbands; band++) + for ( band = start_band; band < nbands; band++ ) { band_start = band_grouping[band]; band_end = band_grouping[band + 1]; tmp_write_idx_param_band = hSpatParamRendCom->dirac_bs_md_write_idx; - if (ivas_format == SBA_FORMAT) + if ( ivas_format == SBA_FORMAT ) { qBand_idx = dirac_to_spar_md_bands[band] - start_band; } @@ -2867,25 +2875,25 @@ void ivas_qmetadata_to_dirac( diffuseness = 1.0f - q_direction->band_data[qBand_idx].energy_ratio[0]; diff_idx = q_direction->band_data[qBand_idx].energy_ratio_index[0]; - for (block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++) + for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) { int16_t block_qmetadata; - block_qmetadata = min(block, nblocks - 1); - block_qmetadata = max(block_qmetadata, 0); + block_qmetadata = min( block, nblocks - 1 ); + block_qmetadata = max( block_qmetadata, 0 ); - if (q_direction[idx_sec].band_data[qBand_idx].azimuth[block_qmetadata] < 0.f) + if ( q_direction[idx_sec].band_data[qBand_idx].azimuth[block_qmetadata] < 0.f ) { q_direction[idx_sec].band_data[qBand_idx].azimuth[block_qmetadata] += 360.f; } - if (hMasa == NULL && hodirac_flag) + if ( hMasa == NULL && hodirac_flag ) { azimuth = q_direction[idx_sec].band_data[qBand_idx].azimuth[block_qmetadata]; elevation = q_direction[idx_sec].band_data[qBand_idx].elevation[block_qmetadata]; diffuseness = 1.f - q_direction[0].band_data[qBand_idx].energy_ratio[block_qmetadata]; diffuseness_sec = q_direction[1].band_data[qBand_idx].energy_ratio[block_qmetadata]; - assert(diffuseness_sec < 1.0001f && diffuseness_sec > -0.0001f); + assert( diffuseness_sec < 1.0001f && diffuseness_sec > -0.0001f ); } else { @@ -2893,25 +2901,25 @@ void ivas_qmetadata_to_dirac( elevation = q_direction->band_data[qBand_idx].elevation[block_qmetadata]; } - for (b = band_start; b < band_end; b++) + for ( b = band_start; b < band_end; b++ ) { tmp_write_idx_band = tmp_write_idx_param_band; - if (hodirac_flag) + if ( hodirac_flag ) { - azi = (int16_t)(azimuth + 0.5f); - ele = (int16_t)(elevation + 0.5f); + azi = (int16_t) ( azimuth + 0.5f ); + ele = (int16_t) ( elevation + 0.5f ); } else { - azi = (int16_t)(azimuth + rand_triangular_signed(seed_ptr) * dirac_dithering_azi_scale[diff_idx] + 0.5f); - ele = (int16_t)(elevation + rand_triangular_signed(seed_ptr) * dirac_dithering_ele_scale[diff_idx] + 0.5f); + azi = (int16_t) ( azimuth + rand_triangular_signed( seed_ptr ) * dirac_dithering_azi_scale[diff_idx] + 0.5f ); + ele = (int16_t) ( elevation + rand_triangular_signed( seed_ptr ) * dirac_dithering_ele_scale[diff_idx] + 0.5f ); /* limit the elevation to [-90, 90] */ - ele = min(90, ele); - ele = max(-90, ele); + ele = min( 90, ele ); + ele = max( -90, ele ); } - if (ivas_total_brate > IVAS_SID_5k2 && q_direction->coherence_band_data != NULL) + if ( ivas_total_brate > IVAS_SID_5k2 && q_direction->coherence_band_data != NULL ) { hSpatParamRendCom->spreadCoherence[tmp_write_idx_band][b] = q_direction->coherence_band_data[qBand_idx].spread_coherence[block] / 255.0f; } @@ -2920,7 +2928,7 @@ void ivas_qmetadata_to_dirac( hSpatParamRendCom->spreadCoherence[tmp_write_idx_band][b] = 0.0f; } - if (ivas_total_brate > IVAS_SID_5k2 && q_direction->coherence_band_data != NULL) + if ( ivas_total_brate > IVAS_SID_5k2 && q_direction->coherence_band_data != NULL ) { hSpatParamRendCom->surroundingCoherence[tmp_write_idx_band][b] = hQMetaData->surcoh_band_data[qBand_idx].surround_coherence[0] / 255.0f; } @@ -2933,9 +2941,9 @@ void ivas_qmetadata_to_dirac( hSpatParamRendCom->diffuseness_vector[tmp_write_idx_band][b] = diffuseness; - if (hodirac_flag) + if ( hodirac_flag ) { - if (idx_sec == 0) + if ( idx_sec == 0 ) { hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele; hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi; @@ -2943,7 +2951,7 @@ void ivas_qmetadata_to_dirac( } else { - assert(idx_sec == 1); + assert( idx_sec == 1 ); hSpatParamRendCom->elevation2[tmp_write_idx_band][b] = ele; hSpatParamRendCom->azimuth2[tmp_write_idx_band][b] = azi; hSpatParamRendCom->energy_ratio2[tmp_write_idx_band][b] = 1.f - diffuseness_sec; @@ -2955,18 +2963,18 @@ void ivas_qmetadata_to_dirac( hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi; } } - tmp_write_idx_param_band = (tmp_write_idx_param_band + 1) % hSpatParamRendCom->dirac_md_buffer_length; + tmp_write_idx_param_band = ( tmp_write_idx_param_band + 1 ) % hSpatParamRendCom->dirac_md_buffer_length; } /* for ( block =...) */ } /* for ( band = ...) */ } /* for ( idx_sec = ...)*/ /* Bands not transmitted -> zeroed*/ - for (b = band_grouping[band]; b < hSpatParamRendCom->num_freq_bands; b++) + for ( b = band_grouping[band]; b < hSpatParamRendCom->num_freq_bands; b++ ) { tmp_write_idx_band = hSpatParamRendCom->dirac_bs_md_write_idx; - for (block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++) + for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) { hSpatParamRendCom->spreadCoherence[block][b] = 0.0f; @@ -2979,13 +2987,13 @@ void ivas_qmetadata_to_dirac( hSpatParamRendCom->spreadCoherence[tmp_write_idx_band][b] = 0.0f; hSpatParamRendCom->surroundingCoherence[tmp_write_idx_band][b] = 0.0f; hSpatParamRendCom->energy_ratio1[tmp_write_idx_band][b] = 0; - tmp_write_idx_band = (tmp_write_idx_band + 1) % hSpatParamRendCom->dirac_md_buffer_length; + tmp_write_idx_band = ( tmp_write_idx_band + 1 ) % hSpatParamRendCom->dirac_md_buffer_length; } } } /* update buffer write index */ - hSpatParamRendCom->dirac_bs_md_write_idx = (hSpatParamRendCom->dirac_bs_md_write_idx + MAX_PARAM_SPATIAL_SUBFRAMES) % hSpatParamRendCom->dirac_md_buffer_length; + hSpatParamRendCom->dirac_bs_md_write_idx = ( hSpatParamRendCom->dirac_bs_md_write_idx + MAX_PARAM_SPATIAL_SUBFRAMES ) % hSpatParamRendCom->dirac_md_buffer_length; return; } @@ -2999,7 +3007,7 @@ void ivas_qmetadata_to_dirac( #ifdef IVAS_FLOAT_FIXED void ivas_dirac_dec_set_md_map( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const Word16 nCldfbTs /* i : number of CLDFB time slots */ + const Word16 nCldfbTs /* i : number of CLDFB time slots */ ) { Word16 num_slots_in_subfr; @@ -3019,7 +3027,7 @@ void ivas_dirac_dec_set_md_map( /* copy also to tc buffer */ /* only for non-combined formats and combinded formats w/o discrete objects */ - IF ( ( st_ivas->ivas_format != MASA_ISM_FORMAT || st_ivas->ism_mode != ISM_MASA_MODE_DISC ) && !( st_ivas->ivas_format == SBA_ISM_FORMAT && st_ivas->ism_mode == ISM_SBA_MODE_DISC ) ) + IF( ( st_ivas->ivas_format != MASA_ISM_FORMAT || st_ivas->ism_mode != ISM_MASA_MODE_DISC ) && !( st_ivas->ivas_format == SBA_ISM_FORMAT && st_ivas->ism_mode == ISM_SBA_MODE_DISC ) ) { st_ivas->hTcBuffer->nb_subframes = hSpatParamRendCom->nb_subframes; mvs2s( hSpatParamRendCom->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, hSpatParamRendCom->nb_subframes ); @@ -3029,11 +3037,11 @@ void ivas_dirac_dec_set_md_map( set_s( hSpatParamRendCom->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME ); - IF ( st_ivas->ivas_format == MASA_FORMAT ) + IF( st_ivas->ivas_format == MASA_FORMAT ) { ivas_jbm_dec_get_md_map_even_spacing( nCldfbTs, num_slots_in_subfr, 0, hSpatParamRendCom->dirac_md_buffer_length, hSpatParamRendCom->render_to_md_map ); } - ELSE IF ( hDirAC == NULL || hDirAC->hConfig == NULL || hDirAC->hConfig->dec_param_estim == 0 ) + ELSE IF( hDirAC == NULL || hDirAC->hConfig == NULL || hDirAC->hConfig->dec_param_estim == 0 ) { ivas_jbm_dec_get_md_map( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbTs, num_slots_in_subfr, 0, hSpatParamRendCom->dirac_md_buffer_length, hSpatParamRendCom->render_to_md_map ); } @@ -3042,21 +3050,21 @@ void ivas_dirac_dec_set_md_map( ivas_jbm_dec_get_md_map( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbTs, num_slots_in_subfr, hSpatParamRendCom->dirac_read_idx, hSpatParamRendCom->dirac_md_buffer_length, hSpatParamRendCom->render_to_md_map ); } - IF ( hDirAC == NULL || hDirAC->hConfig == NULL || hDirAC->hConfig->dec_param_estim == 0 ) + IF( hDirAC == NULL || hDirAC->hConfig == NULL || hDirAC->hConfig->dec_param_estim == 0 ) { Word64 tmp_fx; Word16 sf_idx, slot_idx, slot_idx_abs; slot_idx_abs = 0; - FOR ( sf_idx = 0; sf_idx < hSpatParamRendCom->nb_subframes; sf_idx++ ) + FOR( sf_idx = 0; sf_idx < hSpatParamRendCom->nb_subframes; sf_idx++ ) { tmp_fx = 0; - FOR ( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[sf_idx]; slot_idx++ ) + FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[sf_idx]; slot_idx++ ) { tmp_fx += hSpatParamRendCom->render_to_md_map[slot_idx_abs]; slot_idx_abs++; } - hSpatParamRendCom->render_to_md_map[sf_idx] = (round_fx((Word32)(tmp_fx << 16) / hSpatParamRendCom->subframe_nbslots[sf_idx]) + hSpatParamRendCom->dirac_read_idx) % hSpatParamRendCom->dirac_md_buffer_length; + hSpatParamRendCom->render_to_md_map[sf_idx] = ( round_fx( (Word32) ( tmp_fx << 16 ) / hSpatParamRendCom->subframe_nbslots[sf_idx] ) + hSpatParamRendCom->dirac_read_idx ) % hSpatParamRendCom->dirac_md_buffer_length; } set_s( &hSpatParamRendCom->render_to_md_map[hSpatParamRendCom->nb_subframes], 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME - hSpatParamRendCom->nb_subframes ); @@ -3180,7 +3188,7 @@ void ivas_dirac_dec_set_md_map_fx( ivas_jbm_dec_get_md_map( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbTs, num_slots_in_subfr, hSpatParamRendCom->dirac_read_idx, hSpatParamRendCom->dirac_md_buffer_length, hSpatParamRendCom->render_to_md_map ); } - IF (hDirAC == NULL || hDirAC->hConfig == NULL || hDirAC->hConfig->dec_param_estim == 0) + IF( hDirAC == NULL || hDirAC->hConfig == NULL || hDirAC->hConfig->dec_param_estim == 0 ) { Word16 sf_idx, slot_idx, slot_idx_abs; Word32 tmp_fx; @@ -3190,34 +3198,35 @@ void ivas_dirac_dec_set_md_map_fx( Word16 ans_fix_16, exp_final; slot_idx_abs = 0; - FOR (sf_idx = 0; sf_idx < hSpatParamRendCom->nb_subframes; sf_idx++) + FOR( sf_idx = 0; sf_idx < hSpatParamRendCom->nb_subframes; sf_idx++ ) { tmp_fx = 0; - FOR (slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[sf_idx]; slot_idx++) + FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[sf_idx]; slot_idx++ ) { - tmp_fx = L_add(tmp_fx , L_deposit_h(hSpatParamRendCom->render_to_md_map[slot_idx_abs])); - slot_idx_abs = add(slot_idx_abs , 1); + tmp_fx = L_add( tmp_fx, L_deposit_h( hSpatParamRendCom->render_to_md_map[slot_idx_abs] ) ); + slot_idx_abs = add( slot_idx_abs, 1 ); } - + exp_denom = 15, exp_num = 31; - norm_num = norm_l(tmp_fx); - num = L_shl(tmp_fx, norm_num); + norm_num = norm_l( tmp_fx ); + num = L_shl( tmp_fx, norm_num ); exp_num = exp_num - norm_num; - - norm_denom = norm_s(hSpatParamRendCom->subframe_nbslots[sf_idx]); - denom = shl(hSpatParamRendCom->subframe_nbslots[sf_idx], norm_denom); + + norm_denom = norm_s( hSpatParamRendCom->subframe_nbslots[sf_idx] ); + denom = shl( hSpatParamRendCom->subframe_nbslots[sf_idx], norm_denom ); exp_denom = exp_denom - norm_denom; - exp = sub(exp_num, exp_denom); + exp = sub( exp_num, exp_denom ); - IF (num > denom) { - num = L_shr(num, 1); - exp = add(exp, 1); + IF( num > denom ) + { + num = L_shr( num, 1 ); + exp = add( exp, 1 ); } - - ans = div_l(num, denom); - ans_fix_32 = BASOP_Util_Add_Mant32Exp(ans, exp, L_deposit_h(hSpatParamRendCom->dirac_read_idx), 15/*31 - 16*/, &exp_final); - ans_fix_16 = round_fx(L_shr(ans_fix_32, 31 - exp_final - 16)); + + ans = div_l( num, denom ); + ans_fix_32 = BASOP_Util_Add_Mant32Exp( ans, exp, L_deposit_h( hSpatParamRendCom->dirac_read_idx ), 15 /*31 - 16*/, &exp_final ); + ans_fix_16 = round_fx( L_shr( ans_fix_32, 31 - exp_final - 16 ) ); hSpatParamRendCom->render_to_md_map[sf_idx] = ans_fix_16 % hSpatParamRendCom->dirac_md_buffer_length; } @@ -3318,24 +3327,22 @@ void ivas_dirac_dec_render_fx( } } - IF( EQ_16( hSpatParamRendCom->slots_rendered, hSpatParamRendCom->num_slots ) ) - { - IF( EQ_16( st_ivas->hDirAC->hConfig->dec_param_estim, 1 ) ) - { + IF( EQ_16( hSpatParamRendCom->slots_rendered, hSpatParamRendCom->num_slots ) ){ + IF( EQ_16( st_ivas->hDirAC->hConfig->dec_param_estim, 1 ) ){ temp = add( hSpatParamRendCom->dirac_read_idx, DEFAULT_JBM_CLDFB_TIMESLOTS ); - hSpatParamRendCom->dirac_read_idx = sub( temp, i_mult( idiv1616( temp, hSpatParamRendCom->dirac_md_buffer_length ), hSpatParamRendCom->dirac_md_buffer_length ) ); - } - ELSE - { - temp = add( hSpatParamRendCom->dirac_read_idx, DEFAULT_JBM_SUBFRAMES_5MS ); - hSpatParamRendCom->dirac_read_idx = sub( temp, i_mult( idiv1616( temp, hSpatParamRendCom->dirac_md_buffer_length ), hSpatParamRendCom->dirac_md_buffer_length ) ); - } - } + hSpatParamRendCom->dirac_read_idx = sub( temp, i_mult( idiv1616( temp, hSpatParamRendCom->dirac_md_buffer_length ), hSpatParamRendCom->dirac_md_buffer_length ) ); +} +ELSE +{ + temp = add( hSpatParamRendCom->dirac_read_idx, DEFAULT_JBM_SUBFRAMES_5MS ); + hSpatParamRendCom->dirac_read_idx = sub( temp, i_mult( idiv1616( temp, hSpatParamRendCom->dirac_md_buffer_length ), hSpatParamRendCom->dirac_md_buffer_length ) ); +} +} - *nSamplesAvailableNext = i_mult(sub(hSpatParamRendCom->num_slots, hSpatParamRendCom->slots_rendered), slot_size); - move16(); +*nSamplesAvailableNext = i_mult( sub( hSpatParamRendCom->num_slots, hSpatParamRendCom->slots_rendered ), slot_size ); +move16(); - return; +return; } #else /*------------------------------------------------------------------------- @@ -3428,11 +3435,11 @@ void ivas_dirac_dec_render( *------------------------------------------------------------------------*/ void ivas_dirac_dec_render_sf_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - float *output_f[], /* i/o: synthesized core-coder transport channels/DirAC output */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + float *output_f[], /* i/o: synthesized core-coder transport channels/DirAC output */ #ifdef MSAN_FIX - Word32 *output_buf_fx[], /* i/o: synthesized core-coder transport channels/DirAC output */ -#endif // MSAN_FIX + Word32 *output_buf_fx[], /* i/o: synthesized core-coder transport channels/DirAC output */ +#endif // MSAN_FIX const Word16 nchan_transport, /* i : number of transport channels */ Word32 *pppQMfFrame_ts_re_fx[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX], Word32 *pppQMfFrame_ts_im_fx[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX] ) @@ -3546,7 +3553,7 @@ void ivas_dirac_dec_render_sf_fx( state->proto_power_diff_smooth_q = 31 - state->proto_power_diff_smooth_q; } } - + h_dirac_output_synthesis_params = &( hDirACRend->h_output_synthesis_psd_params ); h_dirac_output_synthesis_state = &( hDirACRend->h_output_synthesis_psd_state ); num_channels_dir = hDirACRend->num_outputs_dir; @@ -3633,8 +3640,8 @@ void ivas_dirac_dec_render_sf_fx( } } } - - /////////////////////////////////////////////////////////////////////////////////////////////// + + /////////////////////////////////////////////////////////////////////////////////////////////// size = hDirACRend->num_outputs_dir * hSpatParamRendCom->num_freq_bands; size_ho = ( hodirac_flag ) ? size * DIRAC_HO_NUMSECTORS : size; hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q = Q26; @@ -3804,8 +3811,8 @@ void ivas_dirac_dec_render_sf_fx( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx, &max_exp_direct, &max_exp_diffusion ); - hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q = sub(Q31, max_exp_direct); - hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q = sub(Q31, max_exp_diffusion); + hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q = sub( Q31, max_exp_direct ); + hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q = sub( Q31, max_exp_diffusion ); IF( coherence_flag ) { @@ -4639,7 +4646,7 @@ void ivas_dirac_dec_render_sf_fx( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q = hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q; move16(); } - + ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hSpatParamRendCom, @@ -5002,7 +5009,7 @@ void ivas_dirac_dec_render_sf_fx( cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, p_out, samplesToProcess, st_ivas->cldfbSynDec[idx_in] ); // Scaling output from Q6-1 to Q11 - Scale_sig32(p_out, out_len, (Q11 - (Q6 - 1))); + Scale_sig32( p_out, out_len, ( Q11 - ( Q6 - 1 ) ) ); idx_in = add( idx_in, 1 ); } @@ -5222,7 +5229,7 @@ void ivas_dirac_dec_render_sf_fx( { for ( i = 0; i < st_ivas->hDecoderConfig->nchan_out; i++ ) { - scale_sig32( st_ivas->cldfbSynDec[i]->cldfb_state_fx, st_ivas->cldfbSynDec[i]->cldfb_size, sub(Q11, st_ivas->cldfbSynDec[i]->Q_cldfb_state) ); + scale_sig32( st_ivas->cldfbSynDec[i]->cldfb_state_fx, st_ivas->cldfbSynDec[i]->cldfb_size, sub( Q11, st_ivas->cldfbSynDec[i]->Q_cldfb_state ) ); st_ivas->cldfbSynDec[i]->Q_cldfb_state = Q11; fixedToFloat_arrL( output_buf_fx[i], output_f[i], Q11, index_slot * hSpatParamRendCom->num_freq_bands + hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->subframe_nbslots[subframe_idx] ); } @@ -5268,13 +5275,13 @@ void ivas_dirac_dec_render_sf_fx( IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && !hDirACRend->hOutSetup.separateChannelEnabled ) { Word16 cldfbSynIdx = add( hDirACRend->hOutSetup.nchan_out_woLFE, idx_lfe ); - scale_sig32( st_ivas->cldfbSynDec[cldfbSynIdx]->cldfb_state_fx, st_ivas->cldfbSynDec[cldfbSynIdx]->cldfb_size, sub(Q11, st_ivas->cldfbSynDec[cldfbSynIdx]->Q_cldfb_state) ); + scale_sig32( st_ivas->cldfbSynDec[cldfbSynIdx]->cldfb_state_fx, st_ivas->cldfbSynDec[cldfbSynIdx]->cldfb_size, sub( Q11, st_ivas->cldfbSynDec[cldfbSynIdx]->Q_cldfb_state ) ); st_ivas->cldfbSynDec[cldfbSynIdx]->Q_cldfb_state = Q11; } } ELSE IF( ( hDirACRend->hOutSetup.separateChannelEnabled == 0 ) || NE_16( hDirACRend->hOutSetup.separateChannelIndex, ch ) ) { - scale_sig32( st_ivas->cldfbSynDec[idx_in]->cldfb_state_fx, st_ivas->cldfbSynDec[idx_in]->cldfb_size, sub(Q11, st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state) ); + scale_sig32( st_ivas->cldfbSynDec[idx_in]->cldfb_state_fx, st_ivas->cldfbSynDec[idx_in]->cldfb_size, sub( Q11, st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state ) ); st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state = Q11; idx_in = add( idx_in, 1 ); } @@ -5315,7 +5322,7 @@ void ivas_dirac_dec_render_sf_fx( ELSE { // Fixed to float - fixedToFloat_arrL(output_buf_fx[ch], output_f[ch], Q11, hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->subframe_nbslots[subframe_idx] + index_slot * hSpatParamRendCom->num_freq_bands); + fixedToFloat_arrL( output_buf_fx[ch], output_f[ch], Q11, hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->subframe_nbslots[subframe_idx] + index_slot * hSpatParamRendCom->num_freq_bands ); } } } @@ -5545,10 +5552,10 @@ void ivas_dirac_dec_render_sf( for ( ch = 0; ch < nchan_transport; ch++ ) { cldfbAnalysis_ts_ivas( &( st_ivas->hTcBuffer->tc[hDirACRend->sba_map_tc[ch]][hSpatParamRendCom->num_freq_bands * index_slot] ), - Cldfb_RealBuffer_Temp[ch][slot_idx], - Cldfb_ImagBuffer_Temp[ch][slot_idx], - hSpatParamRendCom->num_freq_bands, - st_ivas->cldfbAnaDec[ch] ); + Cldfb_RealBuffer_Temp[ch][slot_idx], + Cldfb_ImagBuffer_Temp[ch][slot_idx], + hSpatParamRendCom->num_freq_bands, + st_ivas->cldfbAnaDec[ch] ); } } @@ -5591,10 +5598,10 @@ void ivas_dirac_dec_render_sf( for ( ch = 0; ch < nchan_transport; ch++ ) { cldfbAnalysis_ts_ivas( &( st_ivas->hTcBuffer->tc[hDirACRend->sba_map_tc[ch]][hSpatParamRendCom->num_freq_bands * index_slot] ), - Cldfb_RealBuffer[ch][0], - Cldfb_ImagBuffer[ch][0], - hSpatParamRendCom->num_freq_bands, - st_ivas->cldfbAnaDec[ch] ); + Cldfb_RealBuffer[ch][0], + Cldfb_ImagBuffer[ch][0], + hSpatParamRendCom->num_freq_bands, + st_ivas->cldfbAnaDec[ch] ); } } diff --git a/lib_dec/ivas_dirac_output_synthesis_cov.c b/lib_dec/ivas_dirac_output_synthesis_cov.c index b876dad48..34bed34af 100644 --- a/lib_dec/ivas_dirac_output_synthesis_cov.c +++ b/lib_dec/ivas_dirac_output_synthesis_cov.c @@ -67,13 +67,13 @@ ivas_error ivas_dirac_dec_output_synthesis_cov_open_fx( DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params, /* i/o: handle for the covariance synthesis parameters */ DIRAC_OUTPUT_SYNTHESIS_COV_STATE *h_dirac_output_synthesis_state, /* i/o: hanlde for the covariance synthesis state */ - const Word16 max_band_decorr, /* i : uppermost frequency band where decorrelation is applied */ - const Word16 interp_length, /* i : length for interpolating the mixing matrices in time slots */ - const Word16 num_param_bands, /* i : number of parameter bands */ - const Word16 num_param_bands_residual, /* i : number of parameter bands with a residual mixing matrix (i.e. decorrelation */ - const Word16 nchan_in, /* i : number of input (transport) channels */ - const Word16 nchan_out, /* i : number of output channels */ - const Word32 *proto_matrix /* i : the prototype (upmix) matrix (only used if mode == 1) */ + const Word16 max_band_decorr, /* i : uppermost frequency band where decorrelation is applied */ + const Word16 interp_length, /* i : length for interpolating the mixing matrices in time slots */ + const Word16 num_param_bands, /* i : number of parameter bands */ + const Word16 num_param_bands_residual, /* i : number of parameter bands with a residual mixing matrix (i.e. decorrelation */ + const Word16 nchan_in, /* i : number of input (transport) channels */ + const Word16 nchan_out, /* i : number of output channels */ + const Word32 *proto_matrix /* i : the prototype (upmix) matrix (only used if mode == 1) */ ) { Word16 idx; @@ -97,17 +97,17 @@ ivas_error ivas_dirac_dec_output_synthesis_cov_open_fx( for ( idx = 0; idx < num_param_bands; idx++ ) { - if ( ( h_dirac_output_synthesis_state->cx_old_fx[idx] = (Word32 *) malloc( nchan_in * nchan_in * sizeof(Word32) ) ) == NULL ) + if ( ( h_dirac_output_synthesis_state->cx_old_fx[idx] = (Word32 *) malloc( nchan_in * nchan_in * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis covariance\n" ) ); } h_dirac_output_synthesis_state->cx_old_len = nchan_in * nchan_in; move16(); - if ( ( h_dirac_output_synthesis_state->cy_old_fx[idx] = (Word32 *) malloc( nchan_out * nchan_out * sizeof(Word32) ) ) == NULL ) + if ( ( h_dirac_output_synthesis_state->cy_old_fx[idx] = (Word32 *) malloc( nchan_out * nchan_out * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis covariance\n" ) ); } - if ( ( h_dirac_output_synthesis_state->mixing_matrix_old_fx[idx] = (Word32 *) malloc( nchan_out * nchan_in * sizeof(Word32) ) ) == NULL ) + if ( ( h_dirac_output_synthesis_state->mixing_matrix_old_fx[idx] = (Word32 *) malloc( nchan_out * nchan_in * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis covariance\n" ) ); } @@ -115,7 +115,7 @@ ivas_error ivas_dirac_dec_output_synthesis_cov_open_fx( set_zero_fx( h_dirac_output_synthesis_state->cy_old_fx[idx], nchan_out * nchan_out ); set_zero_fx( h_dirac_output_synthesis_state->mixing_matrix_old_fx[idx], nchan_out * nchan_in ); - if ( ( h_dirac_output_synthesis_state->mixing_matrix_fx[idx] = (Word32 *) malloc( nchan_out * nchan_in * sizeof(Word32) ) ) == NULL ) + if ( ( h_dirac_output_synthesis_state->mixing_matrix_fx[idx] = (Word32 *) malloc( nchan_out * nchan_in * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis matrix\n" ) ); } @@ -131,17 +131,17 @@ ivas_error ivas_dirac_dec_output_synthesis_cov_open_fx( for ( idx = 0; idx < num_param_bands_residual; idx++ ) { - if ( ( h_dirac_output_synthesis_state->mixing_matrix_res_old_fx[idx] = (Word32 *) malloc( nchan_out * nchan_out * sizeof(Word32) ) ) == NULL ) + if ( ( h_dirac_output_synthesis_state->mixing_matrix_res_old_fx[idx] = (Word32 *) malloc( nchan_out * nchan_out * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis covariance\n" ) ); } - set_zero_fx( h_dirac_output_synthesis_state->mixing_matrix_res_old_fx[idx],nchan_out * nchan_out ); + set_zero_fx( h_dirac_output_synthesis_state->mixing_matrix_res_old_fx[idx], nchan_out * nchan_out ); - if ( ( h_dirac_output_synthesis_state->mixing_matrix_res_fx[idx] = (Word32 *) malloc( nchan_out * nchan_out * sizeof(Word32) ) ) == NULL ) + if ( ( h_dirac_output_synthesis_state->mixing_matrix_res_fx[idx] = (Word32 *) malloc( nchan_out * nchan_out * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis matrix\n" ) ); } - set_zero_fx( h_dirac_output_synthesis_state->mixing_matrix_res_fx[idx],nchan_out * nchan_out ); + set_zero_fx( h_dirac_output_synthesis_state->mixing_matrix_res_fx[idx], nchan_out * nchan_out ); } for ( ; idx < CLDFB_NO_CHANNELS_MAX; idx++ ) { @@ -149,41 +149,41 @@ ivas_error ivas_dirac_dec_output_synthesis_cov_open_fx( h_dirac_output_synthesis_state->mixing_matrix_res_fx[idx] = NULL; } - if ((h_dirac_output_synthesis_state->cx_old_e = (Word16 *)malloc(CLDFB_NO_CHANNELS_MAX * sizeof(Word16))) == NULL) + if ( ( h_dirac_output_synthesis_state->cx_old_e = (Word16 *) malloc( CLDFB_NO_CHANNELS_MAX * sizeof( Word16 ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis covariance\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis covariance\n" ) ); } - if ((h_dirac_output_synthesis_state->cy_old_e = (Word16 *)malloc(CLDFB_NO_CHANNELS_MAX * sizeof(Word16))) == NULL) + if ( ( h_dirac_output_synthesis_state->cy_old_e = (Word16 *) malloc( CLDFB_NO_CHANNELS_MAX * sizeof( Word16 ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis covariance\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis covariance\n" ) ); } - set16_fx(h_dirac_output_synthesis_state->cx_old_e, 0, CLDFB_NO_CHANNELS_MAX); - set16_fx(h_dirac_output_synthesis_state->cy_old_e, 0, CLDFB_NO_CHANNELS_MAX); + set16_fx( h_dirac_output_synthesis_state->cx_old_e, 0, CLDFB_NO_CHANNELS_MAX ); + set16_fx( h_dirac_output_synthesis_state->cy_old_e, 0, CLDFB_NO_CHANNELS_MAX ); - if ((h_dirac_output_synthesis_state->mixing_matrix_res_exp = (Word16 *)malloc(CLDFB_NO_CHANNELS_MAX * sizeof(Word16))) == NULL) + if ( ( h_dirac_output_synthesis_state->mixing_matrix_res_exp = (Word16 *) malloc( CLDFB_NO_CHANNELS_MAX * sizeof( Word16 ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis matrix\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis matrix\n" ) ); } - set16_fx(h_dirac_output_synthesis_state->mixing_matrix_res_exp, 0, CLDFB_NO_CHANNELS_MAX); + set16_fx( h_dirac_output_synthesis_state->mixing_matrix_res_exp, 0, CLDFB_NO_CHANNELS_MAX ); - if ((h_dirac_output_synthesis_state->mixing_matrix_res_old_exp = (Word16 *)malloc(CLDFB_NO_CHANNELS_MAX * sizeof(Word16))) == NULL) + if ( ( h_dirac_output_synthesis_state->mixing_matrix_res_old_exp = (Word16 *) malloc( CLDFB_NO_CHANNELS_MAX * sizeof( Word16 ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis matrix\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis matrix\n" ) ); } - set16_fx(h_dirac_output_synthesis_state->mixing_matrix_res_old_exp, 0, CLDFB_NO_CHANNELS_MAX); + set16_fx( h_dirac_output_synthesis_state->mixing_matrix_res_old_exp, 0, CLDFB_NO_CHANNELS_MAX ); - if ((h_dirac_output_synthesis_state->mixing_matrix_exp = (Word16 *)malloc(CLDFB_NO_CHANNELS_MAX * sizeof(Word16))) == NULL) + if ( ( h_dirac_output_synthesis_state->mixing_matrix_exp = (Word16 *) malloc( CLDFB_NO_CHANNELS_MAX * sizeof( Word16 ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis matrix\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis matrix\n" ) ); } - set16_fx(h_dirac_output_synthesis_state->mixing_matrix_exp, 0, CLDFB_NO_CHANNELS_MAX); + set16_fx( h_dirac_output_synthesis_state->mixing_matrix_exp, 0, CLDFB_NO_CHANNELS_MAX ); - if ((h_dirac_output_synthesis_state->mixing_matrix_old_exp = (Word16 *)malloc(CLDFB_NO_CHANNELS_MAX * sizeof(Word16))) == NULL) + if ( ( h_dirac_output_synthesis_state->mixing_matrix_old_exp = (Word16 *) malloc( CLDFB_NO_CHANNELS_MAX * sizeof( Word16 ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis matrix\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis matrix\n" ) ); } - set16_fx(h_dirac_output_synthesis_state->mixing_matrix_old_exp, 0, CLDFB_NO_CHANNELS_MAX); + set16_fx( h_dirac_output_synthesis_state->mixing_matrix_old_exp, 0, CLDFB_NO_CHANNELS_MAX ); /*-----------------------------------------------------------------* * prepare processing parameters @@ -271,11 +271,11 @@ ivas_error ivas_dirac_dec_output_synthesis_cov_open( for ( idx = 0; idx < num_param_bands; idx++ ) { - if ( ( h_dirac_output_synthesis_state->cx_old[idx] = (float *) malloc( nchan_in * nchan_in * sizeof(float) ) ) == NULL ) + if ( ( h_dirac_output_synthesis_state->cx_old[idx] = (float *) malloc( nchan_in * nchan_in * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis covariance\n" ) ); } - if ( ( h_dirac_output_synthesis_state->cy_old[idx] = (float *) malloc( nchan_out * nchan_out * sizeof(float) ) ) == NULL ) + if ( ( h_dirac_output_synthesis_state->cy_old[idx] = (float *) malloc( nchan_out * nchan_out * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis covariance\n" ) ); } @@ -327,13 +327,13 @@ ivas_error ivas_dirac_dec_output_synthesis_cov_open( /* compute interpolator */ #ifdef IVAS_FLOAT_FIXED - IF ( ( h_dirac_output_synthesis_params->interpolator_fx = (Word16 *) malloc( interp_length * sizeof(Word16) ) ) == NULL ) + IF( ( h_dirac_output_synthesis_params->interpolator_fx = (Word16 *) malloc( interp_length * sizeof( Word16 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis covariance\n" ) ); } for ( idx = 1; idx <= interp_length; ++idx ) { - h_dirac_output_synthesis_params->interpolator_fx[idx - 1] = div_s(idx,interp_length); + h_dirac_output_synthesis_params->interpolator_fx[idx - 1] = div_s( idx, interp_length ); } #endif if ( ( h_dirac_output_synthesis_params->interpolator = (float *) malloc( interp_length * sizeof( float ) ) ) == NULL ) @@ -410,10 +410,10 @@ void ivas_dirac_dec_output_synthesis_get_interpolator( #ifdef IVAS_FLOAT_FIXED void ivas_dirac_dec_output_synthesis_cov_init_fx( DIRAC_OUTPUT_SYNTHESIS_COV_STATE *h_dirac_output_synthesis_state, /* i/o: pointer to the state of the covariance synthesis */ - const Word16 nchan_in, /* i : number of input (tranport) channels */ - const Word16 nchan_out, /* i : number of output channels */ - const Word16 n_param_bands, /* i : number of total parameter bands */ - const Word16 n_param_bands_res /* i : number of parameter bands with a residual mixing matrix (i.e. decorrelation */ + const Word16 nchan_in, /* i : number of input (tranport) channels */ + const Word16 nchan_out, /* i : number of output channels */ + const Word16 n_param_bands, /* i : number of total parameter bands */ + const Word16 n_param_bands_res /* i : number of parameter bands with a residual mixing matrix (i.e. decorrelation */ ) { @@ -435,17 +435,17 @@ void ivas_dirac_dec_output_synthesis_cov_init_fx( } - set16_fx(h_dirac_output_synthesis_state->mixing_matrix_old_exp, 0, CLDFB_NO_CHANNELS_MAX); - set16_fx(h_dirac_output_synthesis_state->mixing_matrix_exp, 0, CLDFB_NO_CHANNELS_MAX); - set16_fx(h_dirac_output_synthesis_state->mixing_matrix_res_old_exp, 0, CLDFB_NO_CHANNELS_MAX); - set16_fx(h_dirac_output_synthesis_state->mixing_matrix_res_exp, 0, CLDFB_NO_CHANNELS_MAX); -#if 1/*TODO: To be removed :Floating point initializations*/ - FOR ( idx = 0; idx < n_param_bands; idx++ ) + set16_fx( h_dirac_output_synthesis_state->mixing_matrix_old_exp, 0, CLDFB_NO_CHANNELS_MAX ); + set16_fx( h_dirac_output_synthesis_state->mixing_matrix_exp, 0, CLDFB_NO_CHANNELS_MAX ); + set16_fx( h_dirac_output_synthesis_state->mixing_matrix_res_old_exp, 0, CLDFB_NO_CHANNELS_MAX ); + set16_fx( h_dirac_output_synthesis_state->mixing_matrix_res_exp, 0, CLDFB_NO_CHANNELS_MAX ); +#if 1 /*TODO: To be removed :Floating point initializations*/ + FOR( idx = 0; idx < n_param_bands; idx++ ) { set_zero( h_dirac_output_synthesis_state->mixing_matrix[idx], nchan_out * nchan_in ); } - FOR ( idx = 0; idx < n_param_bands_res; idx++ ) + FOR( idx = 0; idx < n_param_bands_res; idx++ ) { set_zero( h_dirac_output_synthesis_state->mixing_matrix_res[idx], nchan_out * nchan_out ); } @@ -511,112 +511,112 @@ void ivas_dirac_dec_output_synthesis_cov_close_fx( } /* free alpha */ - IF ( h_dirac_output_synthesis_params->alpha_synthesis_fx != NULL ) + IF( h_dirac_output_synthesis_params->alpha_synthesis_fx != NULL ) { free( h_dirac_output_synthesis_params->alpha_synthesis_fx ); h_dirac_output_synthesis_params->alpha_synthesis_fx = NULL; } /* free proto_matrix */ - IF ( h_dirac_output_synthesis_params->proto_matrix_fx != NULL ) + IF( h_dirac_output_synthesis_params->proto_matrix_fx != NULL ) { free( h_dirac_output_synthesis_params->proto_matrix_fx ); h_dirac_output_synthesis_params->proto_matrix_fx = NULL; } - - IF(h_dirac_output_synthesis_state->cx_old_e != NULL) + + IF( h_dirac_output_synthesis_state->cx_old_e != NULL ) { - free(h_dirac_output_synthesis_state->cx_old_e); + free( h_dirac_output_synthesis_state->cx_old_e ); h_dirac_output_synthesis_state->cx_old_e = NULL; } - IF(h_dirac_output_synthesis_state->cy_old_e != NULL) + IF( h_dirac_output_synthesis_state->cy_old_e != NULL ) { - free(h_dirac_output_synthesis_state->cy_old_e); + free( h_dirac_output_synthesis_state->cy_old_e ); h_dirac_output_synthesis_state->cy_old_e = NULL; } /* free cov buffers */ - FOR ( idx = 0; idx < CLDFB_NO_CHANNELS_MAX; idx++ ) + FOR( idx = 0; idx < CLDFB_NO_CHANNELS_MAX; idx++ ) { - IF ( h_dirac_output_synthesis_state->cx_old_fx[idx] != NULL ) + IF( h_dirac_output_synthesis_state->cx_old_fx[idx] != NULL ) { free( h_dirac_output_synthesis_state->cx_old_fx[idx] ); h_dirac_output_synthesis_state->cx_old_fx[idx] = NULL; } - IF ( h_dirac_output_synthesis_state->cy_old_fx[idx] != NULL ) + IF( h_dirac_output_synthesis_state->cy_old_fx[idx] != NULL ) { free( h_dirac_output_synthesis_state->cy_old_fx[idx] ); h_dirac_output_synthesis_state->cy_old_fx[idx] = NULL; } - IF ( h_dirac_output_synthesis_state->mixing_matrix_old_fx[idx] != NULL ) + IF( h_dirac_output_synthesis_state->mixing_matrix_old_fx[idx] != NULL ) { free( h_dirac_output_synthesis_state->mixing_matrix_old_fx[idx] ); h_dirac_output_synthesis_state->mixing_matrix_old_fx[idx] = NULL; } - IF ( h_dirac_output_synthesis_state->mixing_matrix_res_old_fx[idx] != NULL ) + IF( h_dirac_output_synthesis_state->mixing_matrix_res_old_fx[idx] != NULL ) { free( h_dirac_output_synthesis_state->mixing_matrix_res_old_fx[idx] ); h_dirac_output_synthesis_state->mixing_matrix_res_old_fx[idx] = NULL; } - IF ( h_dirac_output_synthesis_state->mixing_matrix_fx[idx] != NULL ) + IF( h_dirac_output_synthesis_state->mixing_matrix_fx[idx] != NULL ) { free( h_dirac_output_synthesis_state->mixing_matrix_fx[idx] ); h_dirac_output_synthesis_state->mixing_matrix_fx[idx] = NULL; } - IF ( h_dirac_output_synthesis_state->mixing_matrix_res_fx[idx] != NULL ) + IF( h_dirac_output_synthesis_state->mixing_matrix_res_fx[idx] != NULL ) { free( h_dirac_output_synthesis_state->mixing_matrix_res_fx[idx] ); h_dirac_output_synthesis_state->mixing_matrix_res_fx[idx] = NULL; } } - IF(h_dirac_output_synthesis_state->mixing_matrix_old_exp != NULL) + IF( h_dirac_output_synthesis_state->mixing_matrix_old_exp != NULL ) { - free(h_dirac_output_synthesis_state->mixing_matrix_old_exp); - h_dirac_output_synthesis_state->mixing_matrix_old_exp= NULL; + free( h_dirac_output_synthesis_state->mixing_matrix_old_exp ); + h_dirac_output_synthesis_state->mixing_matrix_old_exp = NULL; } - IF(h_dirac_output_synthesis_state->mixing_matrix_res_old_exp != NULL) + IF( h_dirac_output_synthesis_state->mixing_matrix_res_old_exp != NULL ) { - free(h_dirac_output_synthesis_state->mixing_matrix_res_old_exp ); + free( h_dirac_output_synthesis_state->mixing_matrix_res_old_exp ); h_dirac_output_synthesis_state->mixing_matrix_res_old_exp = NULL; } - IF(h_dirac_output_synthesis_state->mixing_matrix_exp != NULL) + IF( h_dirac_output_synthesis_state->mixing_matrix_exp != NULL ) { - free(h_dirac_output_synthesis_state->mixing_matrix_exp); + free( h_dirac_output_synthesis_state->mixing_matrix_exp ); h_dirac_output_synthesis_state->mixing_matrix_exp = NULL; } - IF(h_dirac_output_synthesis_state->mixing_matrix_res_exp != NULL) + IF( h_dirac_output_synthesis_state->mixing_matrix_res_exp != NULL ) { - free(h_dirac_output_synthesis_state->mixing_matrix_res_exp); + free( h_dirac_output_synthesis_state->mixing_matrix_res_exp ); h_dirac_output_synthesis_state->mixing_matrix_res_exp = NULL; } -#if 1/*TODO: To be removed later(floating point dealloc)*/ +#if 1 /*TODO: To be removed later(floating point dealloc)*/ /* free proto_matrix */ - IF ( h_dirac_output_synthesis_params->proto_matrix != NULL ) + IF( h_dirac_output_synthesis_params->proto_matrix != NULL ) { free( h_dirac_output_synthesis_params->proto_matrix ); h_dirac_output_synthesis_params->proto_matrix = NULL; } /* free cov buffers */ - FOR ( idx = 0; idx < CLDFB_NO_CHANNELS_MAX; idx++ ) + FOR( idx = 0; idx < CLDFB_NO_CHANNELS_MAX; idx++ ) { - IF ( h_dirac_output_synthesis_state->mixing_matrix[idx] != NULL ) + IF( h_dirac_output_synthesis_state->mixing_matrix[idx] != NULL ) { free( h_dirac_output_synthesis_state->mixing_matrix[idx] ); h_dirac_output_synthesis_state->mixing_matrix[idx] = NULL; } - IF ( h_dirac_output_synthesis_state->mixing_matrix_res[idx] != NULL ) + IF( h_dirac_output_synthesis_state->mixing_matrix_res[idx] != NULL ) { free( h_dirac_output_synthesis_state->mixing_matrix_res[idx] ); h_dirac_output_synthesis_state->mixing_matrix_res[idx] = NULL; @@ -1061,15 +1061,15 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx( Word32 *Cldfb_ImagBuffer_in_fx, Word32 Cldfb_RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : output channel filter bank samples (real part) */ Word32 Cldfb_ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : output channel filter bank samples (imaginary part) */ - Word32 *mixing_matrix_fx[], /* i : parameter band wise mixing matrices (direct part) */ - Word16 *mixing_matrix_e, /* i : parameter band wise mixing matrices (direct part) */ - Word32 *mixing_matrix_res_fx[], /* i : parameter band wise mixing matrices (residual part) */ - Word16 *mixing_matrix_res_e, /* i : parameter band wise mixing matrices (residual part) */ - const UWord16 slot_idx_sfr, /* i : time slot index for the current slot within the current subframe */ - const UWord16 slot_idx_tot, /* i : time slot index for the current slot within the frame */ - const Word16 nX, /* i : number of input channels */ - const Word16 nY, /* i : number of output channels */ - PARAM_MC_DEC_HANDLE hParamMC /* i : handle to the Parametric MC decoder state */ + Word32 *mixing_matrix_fx[], /* i : parameter band wise mixing matrices (direct part) */ + Word16 *mixing_matrix_e, /* i : parameter band wise mixing matrices (direct part) */ + Word32 *mixing_matrix_res_fx[], /* i : parameter band wise mixing matrices (residual part) */ + Word16 *mixing_matrix_res_e, /* i : parameter band wise mixing matrices (residual part) */ + const UWord16 slot_idx_sfr, /* i : time slot index for the current slot within the current subframe */ + const UWord16 slot_idx_tot, /* i : time slot index for the current slot within the frame */ + const Word16 nX, /* i : number of input channels */ + const Word16 nY, /* i : number of output channels */ + PARAM_MC_DEC_HANDLE hParamMC /* i : handle to the Parametric MC decoder state */ ) { Word16 param_band_idx, band, ch_idx; @@ -1099,7 +1099,7 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx( set_zero_fx( diff_f_real_fx, MAX_CICP_CHANNELS ); set_zero_fx( diff_f_imag_fx, MAX_CICP_CHANNELS ); - FOR ( param_band_idx = 0; param_band_idx < hParamMC->num_param_bands_synth; param_band_idx++ ) + FOR( param_band_idx = 0; param_band_idx < hParamMC->num_param_bands_synth; param_band_idx++ ) { /* final mixing */ have_residual = 0; @@ -1109,47 +1109,46 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx( brange[1] = hParamMC->band_grouping[param_band_idx + 1]; move16(); - IF ( brange[0] < hParamMC->h_output_synthesis_params.max_band_decorr ) + IF( brange[0] < hParamMC->h_output_synthesis_params.max_band_decorr ) { have_residual = 1; move16(); } - v_multc_fixed(mixing_matrix_fx[param_band_idx], L_deposit_h(hParamMC->h_output_synthesis_params.interpolator_fx[slot_idx_tot]), mixing_matrix_smooth_fx, nY * nX); + v_multc_fixed( mixing_matrix_fx[param_band_idx], L_deposit_h( hParamMC->h_output_synthesis_params.interpolator_fx[slot_idx_tot] ), mixing_matrix_smooth_fx, nY * nX ); mixing_matrix_smooth_e = mixing_matrix_e[param_band_idx]; // interpolator is W16 move16(); - v_multc_fixed(h_synthesis_state.mixing_matrix_old_fx[param_band_idx], L_sub( ONE_IN_Q31, L_deposit_h(hParamMC->h_output_synthesis_params.interpolator_fx[slot_idx_tot] ) ), mixing_matrix_buffer_fx, nY * nX); + v_multc_fixed( h_synthesis_state.mixing_matrix_old_fx[param_band_idx], L_sub( ONE_IN_Q31, L_deposit_h( hParamMC->h_output_synthesis_params.interpolator_fx[slot_idx_tot] ) ), mixing_matrix_buffer_fx, nY * nX ); mixing_matrix_buffer_e = h_synthesis_state.mixing_matrix_old_exp[param_band_idx]; // interpolator is W16 - v_add_fixed_me(mixing_matrix_smooth_fx, mixing_matrix_smooth_e, mixing_matrix_buffer_fx, mixing_matrix_buffer_e, mixing_matrix_smooth_fx, &mixing_matrix_smooth_e, nY * nX, 0); + v_add_fixed_me( mixing_matrix_smooth_fx, mixing_matrix_smooth_e, mixing_matrix_buffer_fx, mixing_matrix_buffer_e, mixing_matrix_smooth_fx, &mixing_matrix_smooth_e, nY * nX, 0 ); - IF ( have_residual ) + IF( have_residual ) { /* residual mixing matrix interpolation*/ - v_multc_fixed(mixing_matrix_res_fx[param_band_idx], L_deposit_h(hParamMC->h_output_synthesis_params.interpolator_fx[slot_idx_tot]), mixing_matrix_res_smooth_fx, nY * nY ); - mixing_matrix_res_smooth_e = mixing_matrix_res_e[param_band_idx] ; // interpolator is W16 + v_multc_fixed( mixing_matrix_res_fx[param_band_idx], L_deposit_h( hParamMC->h_output_synthesis_params.interpolator_fx[slot_idx_tot] ), mixing_matrix_res_smooth_fx, nY * nY ); + mixing_matrix_res_smooth_e = mixing_matrix_res_e[param_band_idx]; // interpolator is W16 - set_zero_fx(mixing_matrix_buffer_fx, nY * nY); - v_multc_fixed(h_synthesis_state.mixing_matrix_res_old_fx[param_band_idx], L_sub( ONE_IN_Q31, L_deposit_h( hParamMC->h_output_synthesis_params.interpolator_fx[slot_idx_tot]) ), mixing_matrix_buffer_fx, nY * nY); + set_zero_fx( mixing_matrix_buffer_fx, nY * nY ); + v_multc_fixed( h_synthesis_state.mixing_matrix_res_old_fx[param_band_idx], L_sub( ONE_IN_Q31, L_deposit_h( hParamMC->h_output_synthesis_params.interpolator_fx[slot_idx_tot] ) ), mixing_matrix_buffer_fx, nY * nY ); mixing_matrix_buffer_e = h_synthesis_state.mixing_matrix_res_old_exp[param_band_idx]; // interpolator is W16 - v_add_fixed_me(mixing_matrix_res_smooth_fx, mixing_matrix_res_smooth_e, mixing_matrix_buffer_fx, mixing_matrix_buffer_e, mixing_matrix_res_smooth_fx, &mixing_matrix_res_smooth_e, nY * nY, 0); + v_add_fixed_me( mixing_matrix_res_smooth_fx, mixing_matrix_res_smooth_e, mixing_matrix_buffer_fx, mixing_matrix_buffer_e, mixing_matrix_res_smooth_fx, &mixing_matrix_res_smooth_e, nY * nY, 0 ); } - - FOR ( band = brange[0]; band < brange[1]; band++ ) + FOR( band = brange[0]; band < brange[1]; band++ ) { assert( band >= 0 ); - IF ( have_residual ) + IF( have_residual ) { /* collect diffuse prototypes */ assert( band < hParamMC->h_output_synthesis_params.max_band_decorr ); - FOR ( ch_idx = 0; ch_idx < nY; ch_idx++ ) + FOR( ch_idx = 0; ch_idx < nY; ch_idx++ ) { diff_f_real_fx[ch_idx] = Cldfb_RealBuffer_fx[ch_idx][slot_idx_sfr][band]; // Q6 move32(); @@ -1161,14 +1160,14 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx( matrix_product_fx( mixing_matrix_res_smooth_fx, nY, nY, 0, diff_f_real_fx, nY, 1, 0, output_f_real_fx ); output_f_real_e = add( mixing_matrix_res_smooth_e, 25 ); - scale_sig32(output_f_real_fx, nY, 6 - (31 - output_f_real_e) ); + scale_sig32( output_f_real_fx, nY, 6 - ( 31 - output_f_real_e ) ); - matrix_product_fx(mixing_matrix_res_smooth_fx, nY, nY, 0, diff_f_imag_fx, nY, 1, 0, output_f_imag_fx); + matrix_product_fx( mixing_matrix_res_smooth_fx, nY, nY, 0, diff_f_imag_fx, nY, 1, 0, output_f_imag_fx ); output_f_imag_e = mixing_matrix_res_smooth_e + 25; - scale_sig32(output_f_imag_fx, nY, 6 - (31 - output_f_imag_e) ); + scale_sig32( output_f_imag_fx, nY, 6 - ( 31 - output_f_imag_e ) ); - FOR ( ch_idx = 0; ch_idx < nY; ch_idx++ ) + FOR( ch_idx = 0; ch_idx < nY; ch_idx++ ) { Cldfb_RealBuffer_fx[ch_idx][slot_idx_sfr][band] = output_f_real_fx[ch_idx]; // Q6 move32(); @@ -1178,7 +1177,7 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx( } ELSE { - FOR ( ch_idx = 0; ch_idx < nY; ch_idx++ ) + FOR( ch_idx = 0; ch_idx < nY; ch_idx++ ) { Cldfb_RealBuffer_fx[ch_idx][slot_idx_sfr][band] = 0; move32(); @@ -1188,33 +1187,31 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx( } /* collect input signals, still in cldfb buffers */ - FOR ( ch_idx = 0; ch_idx < nX; ch_idx++ ) + FOR( ch_idx = 0; ch_idx < nX; ch_idx++ ) { input_f_real_fx[ch_idx] = Cldfb_RealBuffer_in_fx[ch_idx * hParamMC->num_freq_bands + band]; // Q6 move32(); input_f_imag_fx[ch_idx] = Cldfb_ImagBuffer_in_fx[ch_idx * hParamMC->num_freq_bands + band]; move32(); - } /* apply mixing matrix */ - matrix_product_fx(mixing_matrix_smooth_fx, nY, nX, 0, input_f_real_fx, nX, 1, 0, output_f_real_fx); + matrix_product_fx( mixing_matrix_smooth_fx, nY, nX, 0, input_f_real_fx, nX, 1, 0, output_f_real_fx ); output_f_real_e = add( mixing_matrix_smooth_e, 25 ); - scale_sig32(output_f_real_fx, MAX_CICP_CHANNELS, sub( 6, sub(31, output_f_real_e) ) ); + scale_sig32( output_f_real_fx, MAX_CICP_CHANNELS, sub( 6, sub( 31, output_f_real_e ) ) ); - matrix_product_fx(mixing_matrix_smooth_fx, nY, nX, 0, input_f_imag_fx, nX, 1, 0, output_f_imag_fx); + matrix_product_fx( mixing_matrix_smooth_fx, nY, nX, 0, input_f_imag_fx, nX, 1, 0, output_f_imag_fx ); output_f_imag_e = add( mixing_matrix_smooth_e, 25 ); - scale_sig32(output_f_imag_fx, MAX_CICP_CHANNELS, sub( 6, sub( 31, output_f_imag_e ) ) ); + scale_sig32( output_f_imag_fx, MAX_CICP_CHANNELS, sub( 6, sub( 31, output_f_imag_e ) ) ); /* collect output */ - FOR ( ch_idx = 0; ch_idx < nY; ch_idx++ ) + FOR( ch_idx = 0; ch_idx < nY; ch_idx++ ) { - Cldfb_RealBuffer_fx[ch_idx][slot_idx_sfr][band] = L_add(Cldfb_RealBuffer_fx[ch_idx][slot_idx_sfr][band], output_f_real_fx[ch_idx] ); - Cldfb_ImagBuffer_fx[ch_idx][slot_idx_sfr][band] = L_add(Cldfb_ImagBuffer_fx[ch_idx][slot_idx_sfr][band], output_f_imag_fx[ch_idx] ); - + Cldfb_RealBuffer_fx[ch_idx][slot_idx_sfr][band] = L_add( Cldfb_RealBuffer_fx[ch_idx][slot_idx_sfr][band], output_f_real_fx[ch_idx] ); + Cldfb_ImagBuffer_fx[ch_idx][slot_idx_sfr][band] = L_add( Cldfb_ImagBuffer_fx[ch_idx][slot_idx_sfr][band], output_f_imag_fx[ch_idx] ); } } } @@ -1489,27 +1486,25 @@ int16_t computeMixingMatrices( } - #else Word16 computeMixingMatrices_fx( - const Word16 num_inputs, /* i : number of input channels */ - const Word16 num_outputs, /* i : number of output channels */ - const Word32 *Cx, /* i : input channel covariance matrix */ + const Word16 num_inputs, /* i : number of input channels */ + const Word16 num_outputs, /* i : number of output channels */ + const Word32 *Cx, /* i : input channel covariance matrix */ Word16 Cx_e, - const Word32 *Cy, /* i : target covariance matrix */ + const Word32 *Cy, /* i : target covariance matrix */ Word16 Cy_e, - const Word32 *Q, /* i : prototype matrix (usually a upmix matrix) */ + const Word32 *Q, /* i : prototype matrix (usually a upmix matrix) */ Word16 Q_fx_e, const Word16 energy_compensation_flag, /* i : flag indicating that the energy compensation should be performed (i.e. no residual mixing matrix will follow) */ - const Word32 reg_Sx_fx, /* i : regularization factor for the input channel singular values */ + const Word32 reg_Sx_fx, /* i : regularization factor for the input channel singular values */ Word16 reg_Sx_e, - const Word32 reg_ghat_fx, /* i : regularization factor for the normalization matrix */ + const Word32 reg_ghat_fx, /* i : regularization factor for the normalization matrix */ Word16 reg_ghat_e, - Word32 *mixing_matrix_fx, /* o : resulting mixing matrix */ + Word32 *mixing_matrix_fx, /* o : resulting mixing matrix */ Word16 *mixing_matrix_out_e, - Word32 *Cr_fx, /* o : residual covariance matrix */ - Word16 *Cr_e -) + Word32 *Cr_fx, /* o : residual covariance matrix */ + Word16 *Cr_e ) { Word16 i, j; Word16 out = EXIT_SUCCESS; @@ -1521,19 +1516,19 @@ Word16 computeMixingMatrices_fx( Word32 mat_mult_buffer2_fx[MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS]; Word32 Cx_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; Word32 Cy_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; - Word32 svd_u_buffer_fx[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS]; //Q31 out - Word32 svd_v_buffer_fx[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS]; //Q31 out + Word32 svd_u_buffer_fx[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS]; // Q31 out + Word32 svd_v_buffer_fx[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS]; // Q31 out - //Word16 mat_mult_buffer1_fx_e; + // Word16 mat_mult_buffer1_fx_e; Word16 Cx_fx_e; Word16 Cy_fx_e; - //Word16 svd_u_buffer_fx_e[MAX_OUTPUT_CHANNELS]; - //Word16 svd_v_buffer_fx_e[MAX_OUTPUT_CHANNELS]; + // Word16 svd_u_buffer_fx_e[MAX_OUTPUT_CHANNELS]; + // Word16 svd_v_buffer_fx_e[MAX_OUTPUT_CHANNELS]; Word32 svd_s_buffer_fx[MAX_OUTPUT_CHANNELS]; Word16 svd_s_buffer_e[MAX_OUTPUT_CHANNELS]; Word16 svd_s_buffer_fx_e; - + Word32 limit_fx; Word16 limit_e; @@ -1575,16 +1570,15 @@ Word16 computeMixingMatrices_fx( Word32 adj_fx[MAX_OUTPUT_CHANNELS]; Word16 adj_e[MAX_OUTPUT_CHANNELS]; Word32 *adj_fx_p; - //Word32 adj_buff_fx[MAX_OUTPUT_CHANNELS]; + // Word32 adj_buff_fx[MAX_OUTPUT_CHANNELS]; Word16 adj_fx_e; Word32 *Cr_p_fx, *Cy_tilde_p_fx, *Cy_p_fx; push_wmops( "dirac_cov_mix_mat" ); - set32_fx( svd_s_buffer_fx, 0, MAX_OUTPUT_CHANNELS ); - FOR ( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) + FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) { set32_fx( svd_in_buffer_fx[i], 0, MAX_OUTPUT_CHANNELS ); set32_fx( svd_u_buffer_fx[i], 0, MAX_OUTPUT_CHANNELS ); @@ -1592,9 +1586,9 @@ Word16 computeMixingMatrices_fx( } - Copy32(Q, Q_fx, lengthCy * lengthCx); - Copy32(Cx, Cx_fx, lengthCx * lengthCx); - Copy32(Cy, Cy_fx, lengthCy * lengthCy); + Copy32( Q, Q_fx, lengthCy * lengthCx ); + Copy32( Cx, Cx_fx, lengthCx * lengthCx ); + Copy32( Cy, Cy_fx, lengthCy * lengthCy ); Q_e = Q_fx_e; move16(); @@ -1612,33 +1606,33 @@ Word16 computeMixingMatrices_fx( mat2svdMat_fx( Cy_fx, svd_in_buffer_fx, lengthCy, lengthCy, 0 ); - svd_fx(svd_in_buffer_fx, Cy_fx_e, svd_u_buffer_fx, svd_s_buffer_fx, svd_v_buffer_fx, &svd_s_buffer_fx_e, lengthCy, lengthCy ); + svd_fx( svd_in_buffer_fx, Cy_fx_e, svd_u_buffer_fx, svd_s_buffer_fx, svd_v_buffer_fx, &svd_s_buffer_fx_e, lengthCy, lengthCy ); /* Computing Ky */ - /* Computing Ky */ - FOR ( i = 0; i < lengthCy; ++i ) + /* Computing Ky */ + FOR( i = 0; i < lengthCy; ++i ) { - FOR ( j = 0; j < lengthCy; ++j ) + FOR( j = 0; j < lengthCy; ++j ) { tmp_e = svd_s_buffer_fx_e; - L_tmp = Sqrt32(svd_s_buffer_fx[j], &tmp_e); + L_tmp = Sqrt32( svd_s_buffer_fx[j], &tmp_e ); Ky_fx[i + j * lengthCy] = Mpy_32_32( svd_u_buffer_fx[i][j], L_tmp ); - Ky_fx_e[i + j * lengthCy] = + tmp_e; + Ky_fx_e[i + j * lengthCy] = +tmp_e; } } exp = Ky_fx_e[0]; - FOR (i = 1; i < lengthCy * lengthCy; i++) + FOR( i = 1; i < lengthCy * lengthCy; i++ ) { - IF (exp < Ky_fx_e[i]) - exp = Ky_fx_e[i]; + IF( exp < Ky_fx_e[i] ) + exp = Ky_fx_e[i]; } - FOR (i = 0; i < lengthCy * lengthCy; i++) + FOR( i = 0; i < lengthCy * lengthCy; i++ ) { - Ky_fx[i] = L_shr(Ky_fx[i], exp - Ky_fx_e[i]); + Ky_fx[i] = L_shr( Ky_fx[i], exp - Ky_fx_e[i] ); Ky_fx_e[i] = exp; } @@ -1653,55 +1647,55 @@ Word16 computeMixingMatrices_fx( svd_fx( svd_in_buffer_fx, Cx_fx_e, svd_u_buffer_fx, svd_s_buffer_fx, svd_v_buffer_fx, &svd_s_buffer_fx_e, lengthCx, lengthCx ); - FOR ( i = 0; i < lengthCx; ++i ) + FOR( i = 0; i < lengthCx; ++i ) { - FOR ( j = 0; j < lengthCx; ++j ) + FOR( j = 0; j < lengthCx; ++j ) { tmp_e = svd_s_buffer_fx_e; - L_tmp = Sqrt32(svd_s_buffer_fx[j], &tmp_e); + L_tmp = Sqrt32( svd_s_buffer_fx[j], &tmp_e ); Kx_fx[i + j * lengthCx] = Mpy_32_32( svd_u_buffer_fx[i][j], L_tmp ); Kx_fx_e[i + j * lengthCx] = tmp_e; } } exp = Kx_fx_e[0]; - FOR (i = 1; i < lengthCx * lengthCx; i++) + FOR( i = 1; i < lengthCx * lengthCx; i++ ) { - IF (exp < Kx_fx_e[i]) - exp = Kx_fx_e[i]; + IF( exp < Kx_fx_e[i] ) + exp = Kx_fx_e[i]; } - FOR (i = 0; i < lengthCx * lengthCx; i++) + FOR( i = 0; i < lengthCx * lengthCx; i++ ) { - Kx_fx[i] = L_shr(Kx_fx[i], exp - Kx_fx_e[i]); + Kx_fx[i] = L_shr( Kx_fx[i], exp - Kx_fx_e[i] ); Kx_fx_e[i] = exp; move16(); } - FOR ( i = 0; i < lengthCx; ++i ) + FOR( i = 0; i < lengthCx; ++i ) { tmp_e = svd_s_buffer_fx_e; move16(); - svd_s_buffer_fx[i] = Sqrt32(svd_s_buffer_fx[i], &tmp_e); + svd_s_buffer_fx[i] = Sqrt32( svd_s_buffer_fx[i], &tmp_e ); svd_s_buffer_e[i] = tmp_e; move16(); } // making the Q common Word16 max = svd_s_buffer_e[0]; - FOR (i = 1; i < lengthCx; i++) + FOR( i = 1; i < lengthCx; i++ ) { - IF (max < svd_s_buffer_e[i]) + IF( max < svd_s_buffer_e[i] ) { max = svd_s_buffer_e[i]; move16(); } } - FOR (i = 0; i < lengthCx; i++) + FOR( i = 0; i < lengthCx; i++ ) { - svd_s_buffer_fx[i] = L_shr(svd_s_buffer_fx[i], (max - svd_s_buffer_e[i] )); + svd_s_buffer_fx[i] = L_shr( svd_s_buffer_fx[i], ( max - svd_s_buffer_e[i] ) ); } svd_s_buffer_fx_e = max; move16(); @@ -1715,14 +1709,14 @@ Word16 computeMixingMatrices_fx( limit_e = svd_s_buffer_fx_e; move16(); - L_tmp = Mpy_32_32(limit_fx, reg_Sx_fx); + L_tmp = Mpy_32_32( limit_fx, reg_Sx_fx ); limit_e = limit_e + reg_Sx_e; limit_fx = L_add( L_tmp, EPSILON_FX ); - FOR ( i = 0; i < lengthCx; ++i ) + FOR( i = 0; i < lengthCx; ++i ) { svd_s_buffer_e[i] = svd_s_buffer_fx_e; - IF (BASOP_Util_Cmp_Mant32Exp(svd_s_buffer_fx[i], svd_s_buffer_fx_e, limit_fx, limit_e) < 0) + IF( BASOP_Util_Cmp_Mant32Exp( svd_s_buffer_fx[i], svd_s_buffer_fx_e, limit_fx, limit_e ) < 0 ) { svd_s_buffer_fx[i] = limit_fx; svd_s_buffer_e[i] = limit_e; @@ -1730,7 +1724,6 @@ Word16 computeMixingMatrices_fx( } - limit_fx = 0; move32(); limit_e = 0; @@ -1741,30 +1734,30 @@ Word16 computeMixingMatrices_fx( * regularized Kx-1 *-----------------------------------------------------------------*/ - FOR ( i = 0; i < lengthCx; ++i ) + FOR( i = 0; i < lengthCx; ++i ) { Word16 scale, reg_fac_fx; - reg_fac_fx = BASOP_Util_Divide3232_Scale(1, svd_s_buffer_fx[i], &scale); - scale = scale + (31 - svd_s_buffer_e[i]); - FOR ( j = 0; j < lengthCx; ++j ) + reg_fac_fx = BASOP_Util_Divide3232_Scale( 1, svd_s_buffer_fx[i], &scale ); + scale = scale + ( 31 - svd_s_buffer_e[i] ); + FOR( j = 0; j < lengthCx; ++j ) { - Kx_reg_inv_fx[i + j * lengthCx] = Mpy_32_16_1(svd_u_buffer_fx[j][i], reg_fac_fx ); + Kx_reg_inv_fx[i + j * lengthCx] = Mpy_32_16_1( svd_u_buffer_fx[j][i], reg_fac_fx ); Kx_reg_inv_e[i + j * lengthCx] = scale; } } exp = Kx_reg_inv_e[0]; move16(); - FOR(i = 0; i < lengthCx * lengthCx; i++) + FOR( i = 0; i < lengthCx * lengthCx; i++ ) { - IF (exp < Kx_reg_inv_e[i]) - exp = Kx_reg_inv_e[i]; + IF( exp < Kx_reg_inv_e[i] ) + exp = Kx_reg_inv_e[i]; move16(); } - FOR(i = 0; i < lengthCx * lengthCx; i++) + FOR( i = 0; i < lengthCx * lengthCx; i++ ) { - Kx_reg_inv_fx[i] = L_shr(Kx_reg_inv_fx[i], exp - Kx_reg_inv_e[i]); + Kx_reg_inv_fx[i] = L_shr( Kx_reg_inv_fx[i], exp - Kx_reg_inv_e[i] ); Kx_reg_inv_e[i] = exp; move16(); } @@ -1781,9 +1774,9 @@ Word16 computeMixingMatrices_fx( Word16 guard_bits = find_guarded_bits_fx( lengthCx + 1 ); - FOR ( i = 0; i < lengthCy * lengthCx; ++i ) + FOR( i = 0; i < lengthCy * lengthCx; ++i ) { - IF ( Q_Cx_e > Q_e ) + IF( Q_Cx_e > Q_e ) { Q_fx[i] = L_shr( Q_fx[i], guard_bits ); } @@ -1793,7 +1786,7 @@ Word16 computeMixingMatrices_fx( } } - IF ( Q_Cx_e > Q_e ) + IF( Q_Cx_e > Q_e ) { Q_e += guard_bits; } @@ -1805,9 +1798,9 @@ Word16 computeMixingMatrices_fx( matrix_product_diag_fx( Q_Cx_fx, Q_Cx_e, lengthCy, lengthCx, 0, Q_fx, Q_e, lengthCy, lengthCx, 1, Cy_hat_diag_fx, &Cy_hat_diag_e ); - FOR ( i = 0; i < lengthCy; ++i ) + FOR( i = 0; i < lengthCy; ++i ) { - IF (BASOP_Util_Cmp_Mant32Exp(Cy_hat_diag_fx[i], Cy_hat_diag_e, limit_fx, limit_e) > 0) + IF( BASOP_Util_Cmp_Mant32Exp( Cy_hat_diag_fx[i], Cy_hat_diag_e, limit_fx, limit_e ) > 0 ) { limit_fx = Cy_hat_diag_fx[i]; move32(); @@ -1815,17 +1808,17 @@ Word16 computeMixingMatrices_fx( move16(); } - L_tmp = Mpy_32_32(limit_fx, reg_ghat_fx); - limit_fx = L_add(L_tmp, EPSILON_FX); + L_tmp = Mpy_32_32( limit_fx, reg_ghat_fx ); + limit_fx = L_add( L_tmp, EPSILON_FX ); limit_e = limit_e + reg_ghat_e; } - FOR ( i = 0; i < lengthCy; ++i ) + FOR( i = 0; i < lengthCy; ++i ) { - Cy_hat_diag_buff_e[i] = Cy_hat_diag_e; - move16(); - IF ( BASOP_Util_Cmp_Mant32Exp(limit_fx, limit_e, Cy_hat_diag_fx[i], Cy_hat_diag_buff_e[i] ) > 0 ) /* Computing Cy_hat_diag = max(Cy_hat_diag,limit) */ + Cy_hat_diag_buff_e[i] = Cy_hat_diag_e; + move16(); + IF( BASOP_Util_Cmp_Mant32Exp( limit_fx, limit_e, Cy_hat_diag_fx[i], Cy_hat_diag_buff_e[i] ) > 0 ) /* Computing Cy_hat_diag = max(Cy_hat_diag,limit) */ { Cy_hat_diag_fx[i] = limit_fx; move32(); @@ -1833,9 +1826,9 @@ Word16 computeMixingMatrices_fx( move16(); } - tmp = BASOP_Util_Divide3232_Scale(Cy_fx[i + i * lengthCy], Cy_hat_diag_fx[i], &exp); + tmp = BASOP_Util_Divide3232_Scale( Cy_fx[i + i * lengthCy], Cy_hat_diag_fx[i], &exp ); exp = exp + ( Cy_fx_e - Cy_hat_diag_buff_e[i] ); - L_tmp = Sqrt32(L_deposit_h(tmp), &exp); + L_tmp = Sqrt32( L_deposit_h( tmp ), &exp ); G_hat_fx[i] = L_tmp; move32(); G_hat_buff_e[i] = exp; @@ -1844,15 +1837,15 @@ Word16 computeMixingMatrices_fx( exp = G_hat_buff_e[0]; move16(); - FOR (i = 1; i < lengthCy; i++) + FOR( i = 1; i < lengthCy; i++ ) { - IF (exp < G_hat_buff_e[i]) - exp = G_hat_buff_e[i]; + IF( exp < G_hat_buff_e[i] ) + exp = G_hat_buff_e[i]; } - FOR (i = 0; i < lengthCy; i++) + FOR( i = 0; i < lengthCy; i++ ) { - G_hat_fx[i] = L_shr(G_hat_fx[i], exp - G_hat_buff_e[i]); + G_hat_fx[i] = L_shr( G_hat_fx[i], exp - G_hat_buff_e[i] ); } G_hat_e = exp; @@ -1864,7 +1857,7 @@ Word16 computeMixingMatrices_fx( /* Computing the input matrix Kx'*Q'*G_hat'*Ky */ - matrix_product_fx(Kx_fx, lengthCx, lengthCx, 1, Q_fx, lengthCy, lengthCx, 1, mat_mult_buffer1_fx); + matrix_product_fx( Kx_fx, lengthCx, lengthCx, 1, Q_fx, lengthCy, lengthCx, 1, mat_mult_buffer1_fx ); mat_mult_buffer1_e = Kx_fx_e[0] + Q_e; @@ -1874,7 +1867,7 @@ Word16 computeMixingMatrices_fx( mat_mult_buffer1_e = mat_mult_buffer2_e + Ky_fx_e[0]; - IF ( lengthCx < lengthCy ) + IF( lengthCx < lengthCy ) { mat2svdMat_fx( mat_mult_buffer1_fx, svd_in_buffer_fx, lengthCx, lengthCy, 1 ); @@ -1889,7 +1882,7 @@ Word16 computeMixingMatrices_fx( nC = lengthCx; move16(); - svd_fx(svd_in_buffer_fx, mat_mult_buffer1_e, svd_v_buffer_fx, svd_s_buffer_fx, svd_u_buffer_fx, &svd_s_buffer_fx_e, nL, nC ); + svd_fx( svd_in_buffer_fx, mat_mult_buffer1_e, svd_v_buffer_fx, svd_s_buffer_fx, svd_u_buffer_fx, &svd_s_buffer_fx_e, nL, nC ); #endif } ELSE @@ -1917,20 +1910,20 @@ Word16 computeMixingMatrices_fx( mat_mult_buffer1_e = 0; mat_mult_buffer2_e = 0; - guard_bits = find_guarded_bits_fx(lengthCx + 1); - FOR(i = 0; i < lengthCx * lengthCy; ++i) + guard_bits = find_guarded_bits_fx( lengthCx + 1 ); + FOR( i = 0; i < lengthCx * lengthCy; ++i ) { - IF(mat_mult_buffer1_e > mat_mult_buffer1_e) + IF( mat_mult_buffer1_e > mat_mult_buffer1_e ) { - mat_mult_buffer1_fx[i] = L_shr(mat_mult_buffer1_fx[i], guard_bits); + mat_mult_buffer1_fx[i] = L_shr( mat_mult_buffer1_fx[i], guard_bits ); } ELSE { - mat_mult_buffer2_fx[i] = L_shr(mat_mult_buffer2_fx[i], guard_bits); + mat_mult_buffer2_fx[i] = L_shr( mat_mult_buffer2_fx[i], guard_bits ); } } - IF(mat_mult_buffer1_e > mat_mult_buffer2_e ) + IF( mat_mult_buffer1_e > mat_mult_buffer2_e ) { mat_mult_buffer2_e += guard_bits; } @@ -1940,13 +1933,13 @@ Word16 computeMixingMatrices_fx( } matrix_product_fx( mat_mult_buffer1_fx, lengthCy, lengthCx, 0, - mat_mult_buffer2_fx, lengthCx, lengthCx, 1, - mat_mult_buffer3_fx ); - mat_mult_buffer3_e = mat_mult_buffer1_e + mat_mult_buffer2_e; + mat_mult_buffer2_fx, lengthCx, lengthCx, 1, + mat_mult_buffer3_fx ); + mat_mult_buffer3_e = mat_mult_buffer1_e + mat_mult_buffer2_e; /************************ Formulate M **********************/ - matrix_product_fx( Ky_fx, lengthCy, lengthCy, 0, mat_mult_buffer3_fx, lengthCy, lengthCx, 0, mat_mult_buffer1_fx); + matrix_product_fx( Ky_fx, lengthCy, lengthCy, 0, mat_mult_buffer3_fx, lengthCy, lengthCx, 0, mat_mult_buffer1_fx ); mat_mult_buffer1_e = Ky_fx_e[0] + mat_mult_buffer3_e; @@ -1970,26 +1963,26 @@ Word16 computeMixingMatrices_fx( Cr_p_fx = Cr_fx; Cy_p_fx = Cy_fx; Cy_tilde_p_fx = mat_mult_buffer2_fx; - exp = s_max(Cy_fx_e, mat_mult_buffer2_e); - FOR ( i = 0; i < lengthCy * lengthCy; i++) + exp = s_max( Cy_fx_e, mat_mult_buffer2_e ); + FOR( i = 0; i < lengthCy * lengthCy; i++ ) { - Cy_fx[i] = L_shr(Cy_p_fx[i], exp - Cy_fx_e); - Cy_tilde_p_fx[i] = L_shr(Cy_tilde_p_fx[i], exp - mat_mult_buffer2_e); + Cy_fx[i] = L_shr( Cy_p_fx[i], exp - Cy_fx_e ); + Cy_tilde_p_fx[i] = L_shr( Cy_tilde_p_fx[i], exp - mat_mult_buffer2_e ); } Cy_fx_e = exp; move16(); mat_mult_buffer2_e = exp; move16(); - FOR(i = 0; i < lengthCy; ++i) + FOR( i = 0; i < lengthCy; ++i ) { - FOR(j = 0; j < lengthCy; ++j) + FOR( j = 0; j < lengthCy; ++j ) { - *(Cr_p_fx++) = *(Cy_p_fx++) - *(Cy_tilde_p_fx++); + *( Cr_p_fx++ ) = *( Cy_p_fx++ ) - *( Cy_tilde_p_fx++ ); } /* Avoid Meaningless negative main diagonal elements */ - IF(BASOP_Util_Cmp_Mant32Exp(Cr_fx[i + i * lengthCy], exp, 0, 0) < 0) + IF( BASOP_Util_Cmp_Mant32Exp( Cr_fx[i + i * lengthCy], exp, 0, 0 ) < 0 ) { Cr_fx[i + i * lengthCy] = 0; move16(); @@ -2003,16 +1996,16 @@ Word16 computeMixingMatrices_fx( * Energy Compensation *-----------------------------------------------------------------*/ - IF ( energy_compensation_flag == 1 ) + IF( energy_compensation_flag == 1 ) { adj_fx_p = svd_s_buffer_fx; Cy_tilde_p_fx = mat_mult_buffer2_fx; - FOR ( i = 0; i < lengthCy; ++i ) + FOR( i = 0; i < lengthCy; ++i ) { /* Avoid correction for very small energies, main diagonal elements of Cy_tilde_p may be negative */ - IF (BASOP_Util_Cmp_Mant32Exp(Cy_tilde_p_fx[i + i * lengthCy], mat_mult_buffer2_e, 0, 0) < 0) + IF( BASOP_Util_Cmp_Mant32Exp( Cy_tilde_p_fx[i + i * lengthCy], mat_mult_buffer2_e, 0, 0 ) < 0 ) { adj_fx_p[i] = 1073741824; move32(); @@ -2021,17 +2014,17 @@ Word16 computeMixingMatrices_fx( } ELSE { - tmp = BASOP_Util_Divide3232_Scale(Cy_fx[i + lengthCy * i], L_add( Cy_tilde_p_fx[i + i * lengthCy], EPSILON_FX ), &exp); - exp = exp + (Cy_fx_e - mat_mult_buffer2_e); - L_tmp = L_deposit_h(tmp); - L_tmp = Sqrt32(L_tmp, &exp); + tmp = BASOP_Util_Divide3232_Scale( Cy_fx[i + lengthCy * i], L_add( Cy_tilde_p_fx[i + i * lengthCy], EPSILON_FX ), &exp ); + exp = exp + ( Cy_fx_e - mat_mult_buffer2_e ); + L_tmp = L_deposit_h( tmp ); + L_tmp = Sqrt32( L_tmp, &exp ); adj_fx_p[i] = L_tmp; move32(); adj_e[i] = exp; move16(); } - IF (BASOP_Util_Cmp_Mant32Exp(adj_fx_p[i], adj_e[i], 1073741824, 3) > 0) + IF( BASOP_Util_Cmp_Mant32Exp( adj_fx_p[i], adj_e[i], 1073741824, 3 ) > 0 ) { adj_fx_p[i] = 1073741824; move32(); @@ -2041,22 +2034,22 @@ Word16 computeMixingMatrices_fx( } exp = adj_e[0]; - FOR (i = 1; i < lengthCy; i++) + FOR( i = 1; i < lengthCy; i++ ) { - IF (exp < adj_e[i]) - exp = adj_e[i]; + IF( exp < adj_e[i] ) + exp = adj_e[i]; } - FOR (i = 0; i < lengthCy; i++) + FOR( i = 0; i < lengthCy; i++ ) { - adj_fx[i] = L_shr(adj_fx_p[i], exp - adj_e[i]); + adj_fx[i] = L_shr( adj_fx_p[i], exp - adj_e[i] ); } adj_fx_e = exp; move16(); diag_matrix_product_fx( adj_fx, adj_fx_e, lengthCy, mixing_matrix_fx, mixing_matrix_e, lengthCy, lengthCx, 0, mat_mult_buffer3_fx, &mat_mult_buffer3_e ); - Copy32(mat_mult_buffer3_fx, mixing_matrix_fx, lengthCx * lengthCy); + Copy32( mat_mult_buffer3_fx, mixing_matrix_fx, lengthCx * lengthCy ); mixing_matrix_e = mat_mult_buffer3_e; move16(); } @@ -2273,27 +2266,26 @@ int16_t computeMixingMatricesResidual( #else Word16 computeMixingMatricesResidual_fx( const Word32 num_outputs, /* i : number of output channels */ - const Word32 *Cx_fx, /* i : vector containing the diagonal diffuse prototype covariance */ + const Word32 *Cx_fx, /* i : vector containing the diagonal diffuse prototype covariance */ const Word16 Cx_e, - const Word32 *Cy_fx, /* i : matrix containing the missing cov (Cr from computeMixingMatrices()) */ + const Word32 *Cy_fx, /* i : matrix containing the missing cov (Cr from computeMixingMatrices()) */ const Word16 Cy_fx_e, - const Word32 reg_Sx_fx, /* i : regularization factor for the input channel singular values */ + const Word32 reg_Sx_fx, /* i : regularization factor for the input channel singular values */ const Word16 reg_Sx_e, - const Word32 reg_ghat_fx, /* i : regularization factor for the normalization matrix */ + const Word32 reg_ghat_fx, /* i : regularization factor for the normalization matrix */ const Word16 reg_ghat_e, - Word32 *mixing_matrix_fx, /* o : resulting residual mixing matrix */ - Word16 *mixing_matrix_ret_e -) + Word32 *mixing_matrix_fx, /* o : resulting residual mixing matrix */ + Word16 *mixing_matrix_ret_e ) { Word16 i, j; Word16 out = EXIT_SUCCESS; - Word16 lengthCx = extract_l(num_outputs); - Word16 lengthCy = extract_l(num_outputs); + Word16 lengthCx = extract_l( num_outputs ); + Word16 lengthCy = extract_l( num_outputs ); Word32 svd_in_buffer_fx[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS]; Word32 mat_mult_buffer2_fx[MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS]; - Word32 svd_u_buffer_fx[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS]; //Q31 out - Word32 svd_v_buffer_fx[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS]; //Q31 out + Word32 svd_u_buffer_fx[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS]; // Q31 out + Word32 svd_v_buffer_fx[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS]; // Q31 out Word16 mat_mult_buffer1_buff_e[MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS]; @@ -2305,7 +2297,7 @@ Word16 computeMixingMatricesResidual_fx( Word16 mixing_matrix_e = 0, mat_mult_buffer1_e, adj_e, mat_mult_buffer3_e, mat_mult_buffer2_e; #ifdef MSAN_FIX - Word32 svd_s_buffer_fx[MAX_OUTPUT_CHANNELS] = { 0 }; + Word32 svd_s_buffer_fx[MAX_OUTPUT_CHANNELS] = { 0 }; #else Word32 svd_s_buffer_fx[MAX_OUTPUT_CHANNELS]; #endif @@ -2352,27 +2344,27 @@ Word16 computeMixingMatricesResidual_fx( svd_fx( svd_in_buffer_fx, Cy_fx_e, svd_u_buffer_fx, svd_s_buffer_fx, svd_v_buffer_fx, &svd_s_buffer_fx_e, lengthCy, lengthCy ); /* Computing Ky */ - FOR ( i = 0; i < lengthCy; ++i ) + FOR( i = 0; i < lengthCy; ++i ) { - FOR ( j = 0; j < lengthCy; ++j ) + FOR( j = 0; j < lengthCy; ++j ) { tmp_e = svd_s_buffer_fx_e; - L_tmp = Sqrt32(svd_s_buffer_fx[j], &tmp_e); + L_tmp = Sqrt32( svd_s_buffer_fx[j], &tmp_e ); Ky_fx[i + j * lengthCy] = Mpy_32_32( svd_u_buffer_fx[i][j], L_tmp ); Ky_fx_e[i + j * lengthCy] = tmp_e; } } exp = Ky_fx_e[0]; - FOR (i = 1; i < lengthCy * lengthCy; i++) + FOR( i = 1; i < lengthCy * lengthCy; i++ ) { - IF (exp < Ky_fx_e[i]) - exp = Ky_fx_e[i]; + IF( exp < Ky_fx_e[i] ) + exp = Ky_fx_e[i]; } - FOR (i = 0; i < lengthCy * lengthCy; i++) + FOR( i = 0; i < lengthCy * lengthCy; i++ ) { - Ky_fx[i] = L_shr(Ky_fx[i], exp - Ky_fx_e[i]); + Ky_fx[i] = L_shr( Ky_fx[i], exp - Ky_fx_e[i] ); Ky_fx_e[i] = exp; move16(); } @@ -2388,25 +2380,25 @@ Word16 computeMixingMatricesResidual_fx( /* Computing Kx */ - FOR ( i = 0; i < lengthCx; ++i ) + FOR( i = 0; i < lengthCx; ++i ) { exp = Cx_e; move16(); - Kx_fx[i] = Sqrt32(Cx_fx[i], &exp); + Kx_fx[i] = Sqrt32( Cx_fx[i], &exp ); Kx_fx_e[i] = exp; move16(); } exp = Kx_fx_e[0]; - FOR (i = 1; i < lengthCx; i++) + FOR( i = 1; i < lengthCx; i++ ) { - IF (exp < Kx_fx_e[i]) - exp = Kx_fx_e[i]; + IF( exp < Kx_fx_e[i] ) + exp = Kx_fx_e[i]; } - FOR (i = 0; i < lengthCx; i++) + FOR( i = 0; i < lengthCx; i++ ) { - Kx_fx[i] = L_shr(Kx_fx[i], exp - Kx_fx_e[i]); + Kx_fx[i] = L_shr( Kx_fx[i], exp - Kx_fx_e[i] ); Kx_fx_e[i] = exp; move16(); } @@ -2420,15 +2412,15 @@ Word16 computeMixingMatricesResidual_fx( limit_e = Kx_fx_e[0]; move16(); - L_tmp = Mpy_32_32(limit_fx, reg_Sx_fx); - L_tmp = L_add(L_tmp, EPSILLON_FX); + L_tmp = Mpy_32_32( limit_fx, reg_Sx_fx ); + L_tmp = L_add( L_tmp, EPSILLON_FX ); limit_fx = L_tmp; move16(); limit_e = limit_e + reg_Sx_e; - FOR ( i = 0; i < lengthCx; ++i ) + FOR( i = 0; i < lengthCx; ++i ) { - IF (BASOP_Util_Cmp_Mant32Exp(Kx_fx[i], Kx_fx_e[0], limit_fx, limit_e) > 0) + IF( BASOP_Util_Cmp_Mant32Exp( Kx_fx[i], Kx_fx_e[0], limit_fx, limit_e ) > 0 ) { div_tmp = Kx_fx[i]; exp = Kx_fx_e[0]; @@ -2440,28 +2432,28 @@ Word16 computeMixingMatricesResidual_fx( exp = limit_e; move16(); } - tmp = BASOP_Util_Divide3232_Scale(1073741824, div_tmp, &scale); + tmp = BASOP_Util_Divide3232_Scale( 1073741824, div_tmp, &scale ); scale = scale + ( 1 - exp ); - - Kx_reg_inv_fx[i] = L_deposit_h( tmp); + + Kx_reg_inv_fx[i] = L_deposit_h( tmp ); Kx_reg_inv_e[i] = scale; move16(); } exp = Kx_reg_inv_e[0]; - FOR (i = 1; i < lengthCx; i++) + FOR( i = 1; i < lengthCx; i++ ) { - IF (exp < Kx_reg_inv_e[i]) - exp = Kx_reg_inv_e[i]; + IF( exp < Kx_reg_inv_e[i] ) + exp = Kx_reg_inv_e[i]; } - FOR (i = 0; i < lengthCx; i++) + FOR( i = 0; i < lengthCx; i++ ) { - Kx_reg_inv_fx[i] = L_shr(Kx_reg_inv_fx[i], exp - Kx_reg_inv_e[i]); + Kx_reg_inv_fx[i] = L_shr( Kx_reg_inv_fx[i], exp - Kx_reg_inv_e[i] ); } Kx_reg_inv_fx_e = exp; move16(); - + limit_fx = 0; move32(); @@ -2477,12 +2469,12 @@ Word16 computeMixingMatricesResidual_fx( *-----------------------------------------------------------------*/ /* Computing Cy_hat_diag */ - Copy32(Cx_fx, Cy_hat_diag_fx, extract_l(num_outputs)); + Copy32( Cx_fx, Cy_hat_diag_fx, extract_l( num_outputs ) ); Cy_hat_diag_e = Cx_e; - FOR ( i = 0; i < lengthCy; ++i ) + FOR( i = 0; i < lengthCy; ++i ) { - IF ( BASOP_Util_Cmp_Mant32Exp(Cy_hat_diag_fx[i], Cy_hat_diag_e, limit_fx, limit_e ) > 0 ) + IF( BASOP_Util_Cmp_Mant32Exp( Cy_hat_diag_fx[i], Cy_hat_diag_e, limit_fx, limit_e ) > 0 ) { limit_fx = Cy_hat_diag_fx[i]; move32(); @@ -2491,24 +2483,24 @@ Word16 computeMixingMatricesResidual_fx( } } - L_tmp = Mpy_32_32(limit_fx, reg_ghat_fx); - limit_fx = L_add(L_tmp, EPSILON_FX); + L_tmp = Mpy_32_32( limit_fx, reg_ghat_fx ); + limit_fx = L_add( L_tmp, EPSILON_FX ); limit_e = limit_e + reg_ghat_e; - + /* Computing G_hat */ - FOR ( i = 0; i < lengthCy; ++i ) + FOR( i = 0; i < lengthCy; ++i ) { Cy_hat_diag_fx_e[i] = Cy_hat_diag_e; - IF ( BASOP_Util_Cmp_Mant32Exp(limit_fx, limit_e, Cy_hat_diag_fx[i], Cy_hat_diag_e ) > 0 ) /* Computing Cy_hat_diag = max(Cy_hat_diag,limit) */ + IF( BASOP_Util_Cmp_Mant32Exp( limit_fx, limit_e, Cy_hat_diag_fx[i], Cy_hat_diag_e ) > 0 ) /* Computing Cy_hat_diag = max(Cy_hat_diag,limit) */ { Cy_hat_diag_fx[i] = limit_fx; move32(); Cy_hat_diag_fx_e[i] = limit_e; move16(); } - tmp = BASOP_Util_Divide3232_Scale(Cy_fx[i + i * lengthCy], Cy_hat_diag_fx[i], &scale ); - scale = scale + (Cy_fx_e - Cy_hat_diag_fx_e[i]); - L_tmp = Sqrt32(L_deposit_h(tmp), &scale); + tmp = BASOP_Util_Divide3232_Scale( Cy_fx[i + i * lengthCy], Cy_hat_diag_fx[i], &scale ); + scale = scale + ( Cy_fx_e - Cy_hat_diag_fx_e[i] ); + L_tmp = Sqrt32( L_deposit_h( tmp ), &scale ); G_hat_fx[i] = L_tmp; move32(); @@ -2520,36 +2512,36 @@ Word16 computeMixingMatricesResidual_fx( * Formulate optimal P *-----------------------------------------------------------------*/ - FOR ( i = 0; i < num_outputs; i++ ) + FOR( i = 0; i < num_outputs; i++ ) { L_tmp = Mpy_32_32( Kx_fx[i], G_hat_fx[i] ); Kx_fx[i] = L_tmp; Kx_fx_e[i] = Kx_fx_e[i] + G_hat_e[i]; } - FOR ( i = 0; i < num_outputs; i++ ) + FOR( i = 0; i < num_outputs; i++ ) { Word32 fac_fx = Kx_fx[i]; - FOR ( j = 0; j < num_outputs; j++ ) + FOR( j = 0; j < num_outputs; j++ ) { - L_tmp = Mpy_32_32(Ky_fx[i + j * num_outputs], fac_fx); + L_tmp = Mpy_32_32( Ky_fx[i + j * num_outputs], fac_fx ); mat_mult_buffer1_fx[i + j * num_outputs] = L_tmp; - mat_mult_buffer1_buff_e[i + j * num_outputs] = extract_l(L_add( Ky_fx_e[i + j * num_outputs], Kx_fx_e[i] )); + mat_mult_buffer1_buff_e[i + j * num_outputs] = extract_l( L_add( Ky_fx_e[i + j * num_outputs], Kx_fx_e[i] ) ); } } mat_mult_buffer1_e = mat_mult_buffer1_buff_e[0]; move16(); - FOR (i = 1; i < num_outputs * num_outputs; i++) + FOR( i = 1; i < num_outputs * num_outputs; i++ ) { - IF (mat_mult_buffer1_e < mat_mult_buffer1_buff_e[i]) - mat_mult_buffer1_e = mat_mult_buffer1_buff_e[i]; + IF( mat_mult_buffer1_e < mat_mult_buffer1_buff_e[i] ) + mat_mult_buffer1_e = mat_mult_buffer1_buff_e[i]; } - FOR (i = 0; i < num_outputs * num_outputs; i++) + FOR( i = 0; i < num_outputs * num_outputs; i++ ) { - mat_mult_buffer1_fx[i] = L_shr(mat_mult_buffer1_fx[i], mat_mult_buffer1_e - mat_mult_buffer1_buff_e[i]); + mat_mult_buffer1_fx[i] = L_shr( mat_mult_buffer1_fx[i], mat_mult_buffer1_e - mat_mult_buffer1_buff_e[i] ); } mat2svdMat_fx( mat_mult_buffer1_fx, svd_in_buffer_fx, lengthCx, lengthCy, 0 ); @@ -2572,19 +2564,19 @@ Word16 computeMixingMatricesResidual_fx( Word16 guard_bits = find_guarded_bits_fx( lengthCx + 1 ); - FOR ( i = 0; i < lengthCy * lengthCx; ++i ) + FOR( i = 0; i < lengthCy * lengthCx; ++i ) { - IF ( mat_mult_buffer1_e > mat_mult_buffer2_e ) + IF( mat_mult_buffer1_e > mat_mult_buffer2_e ) { - mat_mult_buffer2_fx[i] = L_shr(mat_mult_buffer2_fx[i], guard_bits ); + mat_mult_buffer2_fx[i] = L_shr( mat_mult_buffer2_fx[i], guard_bits ); } ELSE { - mat_mult_buffer1_fx[i] = L_shr(mat_mult_buffer1_fx[i], guard_bits ); + mat_mult_buffer1_fx[i] = L_shr( mat_mult_buffer1_fx[i], guard_bits ); } } - IF ( mat_mult_buffer1_e > mat_mult_buffer2_e ) + IF( mat_mult_buffer1_e > mat_mult_buffer2_e ) { mat_mult_buffer2_e += guard_bits; } @@ -2593,8 +2585,8 @@ Word16 computeMixingMatricesResidual_fx( mat_mult_buffer1_e += guard_bits; } matrix_product_fx( mat_mult_buffer1_fx, lengthCy, lengthCx, 0, - mat_mult_buffer2_fx, lengthCx, lengthCx, 1, - mat_mult_buffer3_fx ); + mat_mult_buffer2_fx, lengthCx, lengthCx, 1, + mat_mult_buffer3_fx ); mat_mult_buffer3_e = 0; /*-----------------------------------------------------------------* @@ -2604,11 +2596,11 @@ Word16 computeMixingMatricesResidual_fx( matrix_product_fx( Ky_fx, lengthCy, lengthCy, 0, mat_mult_buffer3_fx, lengthCy, lengthCx, 0, mat_mult_buffer1_fx ); mat_mult_buffer1_e = Ky_fx_e[0] + mat_mult_buffer3_e; - FOR ( i = 0; i < num_outputs; i++ ) + FOR( i = 0; i < num_outputs; i++ ) { Word32 fac_fx = Kx_reg_inv_fx[i]; - FOR ( j = 0; j < num_outputs; j++ ) + FOR( j = 0; j < num_outputs; j++ ) { L_tmp = Mpy_32_32( mat_mult_buffer1_fx[j + i * num_outputs], fac_fx ); mixing_matrix_fx[j + i * num_outputs] = L_tmp; @@ -2626,9 +2618,9 @@ Word16 computeMixingMatricesResidual_fx( guard_bits = find_guarded_bits_fx( lengthCx + 1 ); - FOR ( i = 0; i < lengthCy * lengthCx; ++i ) + FOR( i = 0; i < lengthCy * lengthCx; ++i ) { - IF ( mat_mult_buffer1_e > mixing_matrix_e ) + IF( mat_mult_buffer1_e > mixing_matrix_e ) { mixing_matrix_fx[i] = L_shr( mixing_matrix_fx[i], guard_bits ); } @@ -2638,7 +2630,7 @@ Word16 computeMixingMatricesResidual_fx( } } - IF ( mat_mult_buffer1_e > mixing_matrix_e ) + IF( mat_mult_buffer1_e > mixing_matrix_e ) { mixing_matrix_e += guard_bits; } @@ -2655,13 +2647,13 @@ Word16 computeMixingMatricesResidual_fx( adj_fx_p = svd_s_buffer_fx; - FOR ( i = 0; i < lengthCy; ++i ) + FOR( i = 0; i < lengthCy; ++i ) { - tmp = BASOP_Util_Divide3232_Scale(Cy_fx[i + lengthCy * i], L_add(Cy_tilde_fx[i], EPSILON_FX), &scale); + tmp = BASOP_Util_Divide3232_Scale( Cy_fx[i + lengthCy * i], L_add( Cy_tilde_fx[i], EPSILON_FX ), &scale ); scale = scale + ( Cy_fx_e - Cy_tilde_e ); - adj_fx_p[i] = Sqrt32(L_deposit_h(tmp), &scale ); + adj_fx_p[i] = Sqrt32( L_deposit_h( tmp ), &scale ); adj_buff_e[i] = scale; - IF ( BASOP_Util_Cmp_Mant32Exp( adj_fx_p[i], scale, 1073741824, 3 ) > 0 ) + IF( BASOP_Util_Cmp_Mant32Exp( adj_fx_p[i], scale, 1073741824, 3 ) > 0 ) { adj_fx_p[i] = 1073741824; move32(); @@ -2672,20 +2664,20 @@ Word16 computeMixingMatricesResidual_fx( adj_e = adj_buff_e[0]; - FOR (i = 1; i < lengthCy; i++) + FOR( i = 1; i < lengthCy; i++ ) { - IF (adj_e < adj_buff_e[i]) - adj_e = adj_buff_e[i]; + IF( adj_e < adj_buff_e[i] ) + adj_e = adj_buff_e[i]; } - FOR (i = 0; i < lengthCy; i++) + FOR( i = 0; i < lengthCy; i++ ) { - adj_fx[i] = L_shr(adj_fx_p[i], adj_e - adj_buff_e[i]); + adj_fx[i] = L_shr( adj_fx_p[i], adj_e - adj_buff_e[i] ); } diag_matrix_product_fx( adj_fx, adj_e, lengthCy, mixing_matrix_fx, mixing_matrix_e, lengthCy, lengthCx, 0, mat_mult_buffer3_fx, &mat_mult_buffer3_e ); - Copy32(mat_mult_buffer3_fx, mixing_matrix_fx, lengthCy * lengthCx); + Copy32( mat_mult_buffer3_fx, mixing_matrix_fx, lengthCy * lengthCx ); *mixing_matrix_ret_e = mat_mult_buffer3_e; move16(); @@ -2696,7 +2688,6 @@ Word16 computeMixingMatricesResidual_fx( #endif - /*-------------------------------------------------------------------* * computeMixingMatricesISM() * @@ -2788,9 +2779,9 @@ int16_t computeMixingMatricesISM( f2me_buf( responses, responses_fx, &responses_e, lengthCy * num_responses ); f2me_buf( ener, ener_fx, &ener_e, num_responses ); - matrix_diag_product_fx(responses_fx, responses_e, lengthCy, num_responses, 0, ener_fx, ener_e, num_responses, Ky_fx, &Ky_e ); + matrix_diag_product_fx( responses_fx, responses_e, lengthCy, num_responses, 0, ener_fx, ener_e, num_responses, Ky_fx, &Ky_e ); - me2f_buf(Ky_fx, Ky_e, Ky, lengthCy * num_responses ); + me2f_buf( Ky_fx, Ky_e, Ky, lengthCy * num_responses ); #else matrix_diag_product( responses, lengthCy, num_responses, 0, ener, num_responses, Ky ); #endif @@ -2915,14 +2906,16 @@ int16_t computeMixingMatricesISM( nC = lengthCx; svd_fx( svd_in_buffer_fx, mat_mult_buffer1_fx_e, svd_v_buffer_fx, svd_s_buffer_fx, svd_u_buffer_fx, &svd_s_buffer_fx_e, nL, nC ); - //local fix2float: to be removed - for ( i = 0; i < nL; i++) { - me2f_buf(svd_v_buffer_fx[i], 0, svd_v_buffer[i], nC); + // local fix2float: to be removed + for ( i = 0; i < nL; i++ ) + { + me2f_buf( svd_v_buffer_fx[i], 0, svd_v_buffer[i], nC ); } - for ( i = 0; i < nC; i++) { - me2f_buf(svd_u_buffer_fx[i], 0, svd_u_buffer[i], nC); + for ( i = 0; i < nC; i++ ) + { + me2f_buf( svd_u_buffer_fx[i], 0, svd_u_buffer[i], nC ); } - me2f_buf(svd_s_buffer_fx, svd_s_buffer_fx_e, svd_s_buffer, nC); + me2f_buf( svd_s_buffer_fx, svd_s_buffer_fx_e, svd_s_buffer, nC ); } else { @@ -2935,16 +2928,18 @@ int16_t computeMixingMatricesISM( nL = lengthCx; nC = num_responses; - svd_fx(svd_in_buffer_fx, mat_mult_buffer1_fx_e, svd_u_buffer_fx, svd_s_buffer_fx, svd_v_buffer_fx, &svd_s_buffer_fx_e, nL, nC ); + svd_fx( svd_in_buffer_fx, mat_mult_buffer1_fx_e, svd_u_buffer_fx, svd_s_buffer_fx, svd_v_buffer_fx, &svd_s_buffer_fx_e, nL, nC ); - //local fix2float: to be removed - for ( i = 0; i < nL; i++) { - me2f_buf(svd_u_buffer_fx[i], 0, svd_u_buffer[i], nC); + // local fix2float: to be removed + for ( i = 0; i < nL; i++ ) + { + me2f_buf( svd_u_buffer_fx[i], 0, svd_u_buffer[i], nC ); } - for ( i = 0; i < nC; i++) { - me2f_buf(svd_v_buffer_fx[i], 0, svd_v_buffer[i], nC); + for ( i = 0; i < nC; i++ ) + { + me2f_buf( svd_v_buffer_fx[i], 0, svd_v_buffer[i], nC ); } - me2f_buf(svd_s_buffer_fx, svd_s_buffer_fx_e, svd_s_buffer, nC); + me2f_buf( svd_s_buffer_fx, svd_s_buffer_fx_e, svd_s_buffer, nC ); } /* Actually Processing P */ @@ -2952,18 +2947,18 @@ int16_t computeMixingMatricesISM( /* can be skipped: lambda is always column-truncated identity matrix, so this operation just truncates V to num_input_channel columns */ #ifdef IVAS_FLOAT_FIXED Word16 min_q = -1; - FOR ( Word32 g = 0; g < num_responses; g++ ) + FOR( Word32 g = 0; g < num_responses; g++ ) { f2me_buf( svd_v_buffer[g], svd_v_buffer_fx[g], &svd_v_buffer_fx_e[g], lengthCx ); - IF ( svd_v_buffer_fx_e[g] > min_q ) + IF( svd_v_buffer_fx_e[g] > min_q ) { min_q = svd_v_buffer_fx_e[g]; } } - FOR ( Word32 g = 0; g < num_responses; g++ ) + FOR( Word32 g = 0; g < num_responses; g++ ) { - FOR ( Word32 h = 0; h < lengthCx; h++ ) + FOR( Word32 h = 0; h < lengthCx; h++ ) { svd_v_buffer_fx[g][h] = L_shr( svd_v_buffer_fx[g][h], min_q - svd_v_buffer_fx_e[g] ); } @@ -2971,18 +2966,18 @@ int16_t computeMixingMatricesISM( svd_v_buffer_fx_e[0] = min_q; min_q = -1; - FOR ( Word32 g = 0; g < lengthCx; g++ ) + FOR( Word32 g = 0; g < lengthCx; g++ ) { f2me_buf( svd_u_buffer[g], svd_u_buffer_fx[g], &svd_u_buffer_fx_e[g], lengthCx ); - IF ( svd_u_buffer_fx_e[g] > min_q ) + IF( svd_u_buffer_fx_e[g] > min_q ) { min_q = svd_u_buffer_fx_e[g]; } } - FOR ( Word32 g = 0; g < lengthCx; g++ ) + FOR( Word32 g = 0; g < lengthCx; g++ ) { - FOR ( Word32 h = 0; h < lengthCx; h++ ) + FOR( Word32 h = 0; h < lengthCx; h++ ) { svd_u_buffer_fx[g][h] = L_shr( svd_u_buffer_fx[g][h], min_q - svd_u_buffer_fx_e[g] ); } @@ -3245,4 +3240,4 @@ int16_t computeMixingMatricesISM( return out; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/ivas_entropy_decoder.c b/lib_dec/ivas_entropy_decoder.c index a8f02aa32..01922f9c3 100644 --- a/lib_dec/ivas_entropy_decoder.c +++ b/lib_dec/ivas_entropy_decoder.c @@ -161,7 +161,7 @@ static Word16 ivas_huffman_code_bits_present( Word16 i = 0; Word16 ind_t, code_t, bits_t; - WHILE ( LT_16( i, len ) ) + WHILE( LT_16( i, len ) ) { ind_t = codebook[0]; bits_t = codebook[1]; @@ -196,7 +196,7 @@ ivas_error ivas_huffman_decode( ind = ivas_huffman_code_bits_present( huff_cfg->codebook, code, num_bits_read, huff_cfg->sym_len ); - WHILE ( GT_16( ind, huff_cfg->sym_len ) ) + WHILE( GT_16( ind, huff_cfg->sym_len ) ) { bit = get_next_indice( st0, 1 ); num_bits_read = add( num_bits_read, 1 ); diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 99a88845d..f263e210f 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -63,7 +63,6 @@ static ivas_error ivas_read_format( Decoder_Struct *st_ivas, Word16 *num_bits_re static ivas_error doSanityChecks_IVAS( Decoder_Struct *st_ivas ); - /*-------------------------------------------------------------------* * ivas_dec_setup() * @@ -72,9 +71,9 @@ static ivas_error doSanityChecks_IVAS( Decoder_Struct *st_ivas ); #ifdef IVAS_FLOAT_FIXED ivas_error ivas_dec_setup( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ UWord16 *nSamplesRendered, /* o : number of samples flushed from the previous frame (JBM) */ - Word16 *data /* o : output synthesis signal */ + Word16 *data /* o : output synthesis signal */ ) { Word16 k, idx, num_bits_read; @@ -103,7 +102,7 @@ ivas_error ivas_dec_setup( * Read other signling (ISM/MC mode, number of channels, etc.) *-------------------------------------------------------------------*/ - IF ( EQ_16(is_DTXrate( ivas_total_brate ), 0 )) + IF( EQ_16( is_DTXrate( ivas_total_brate ), 0 ) ) { /*-------------------------------------------------------------------* * Read IVAS format related signaling: @@ -113,17 +112,17 @@ ivas_error ivas_dec_setup( * - in MC : read LS setup *-------------------------------------------------------------------*/ - IF ( st_ivas->ivas_format == STEREO_FORMAT ) + IF( st_ivas->ivas_format == STEREO_FORMAT ) { element_mode_flag = 1; } - ELSE IF ( st_ivas->ivas_format == ISM_FORMAT ) + ELSE IF( st_ivas->ivas_format == ISM_FORMAT ) { /* read the number of objects */ st_ivas->nchan_transport = 1; nchan_ism = 1; k = (Word16) ( ( ivas_total_brate / FRAMES_PER_SEC ) - 1 ); - WHILE ( st_ivas->bit_stream[k] && LT_16(nchan_ism , MAX_NUM_OBJECTS )) + WHILE( st_ivas->bit_stream[k] && LT_16( nchan_ism, MAX_NUM_OBJECTS ) ) { nchan_ism++; k--; @@ -131,27 +130,27 @@ ivas_error ivas_dec_setup( st_ivas->nchan_ism = nchan_ism; - IF ( ( error = ivas_ism_dec_config_fx( st_ivas, st_ivas->ism_mode, nSamplesRendered, data ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_ism_dec_config_fx( st_ivas, st_ivas->ism_mode, nSamplesRendered, data ) ) != IVAS_ERR_OK ) { return error; } } - ELSE IF ( st_ivas->ivas_format == SBA_FORMAT ) + ELSE IF( st_ivas->ivas_format == SBA_FORMAT ) { /* read Ambisonic (SBA) planar flag */ st_ivas->sba_planar = st_ivas->bit_stream[num_bits_read]; - num_bits_read = add(num_bits_read, SBA_PLANAR_BITS); + num_bits_read = add( num_bits_read, SBA_PLANAR_BITS ); /* read Ambisonic (SBA) order */ st_ivas->sba_order = st_ivas->bit_stream[num_bits_read + 1]; st_ivas->sba_order += 2 * st_ivas->bit_stream[num_bits_read]; - num_bits_read = add(num_bits_read, SBA_ORDER_BITS); - IF ( GT_16(st_ivas->ini_frame , 0) && NE_32(ivas_total_brate, st_ivas->last_active_ivas_total_brate) && GT_32(ivas_total_brate, IVAS_SID_5k2 )) + num_bits_read = add( num_bits_read, SBA_ORDER_BITS ); + IF( GT_16( st_ivas->ini_frame, 0 ) && NE_32( ivas_total_brate, st_ivas->last_active_ivas_total_brate ) && GT_32( ivas_total_brate, IVAS_SID_5k2 ) ) { - IF ( ( error = ivas_sba_dec_reconfigure_fx( st_ivas, nSamplesRendered, data ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_sba_dec_reconfigure_fx( st_ivas, nSamplesRendered, data ) ) != IVAS_ERR_OK ) { return error; } @@ -163,10 +162,10 @@ ivas_error ivas_dec_setup( ivas_sba_config_fx( ivas_total_brate, st_ivas->sba_analysis_order, -1, &( st_ivas->nchan_transport ), st_ivas->sba_planar, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init ); } } - ELSE IF ( st_ivas->ivas_format == MASA_FORMAT ) + ELSE IF( st_ivas->ivas_format == MASA_FORMAT ) { /* read number of MASA transport channels */ - IF ( st_ivas->bit_stream[( ivas_total_brate / FRAMES_PER_SEC ) - 1] ) + IF( st_ivas->bit_stream[( ivas_total_brate / FRAMES_PER_SEC ) - 1] ) { st_ivas->nchan_transport = 2; element_mode_flag = 1; @@ -176,20 +175,21 @@ ivas_error ivas_dec_setup( st_ivas->nchan_transport = 1; } - IF ( GT_16(st_ivas->ini_frame, 0 )) + IF( GT_16( st_ivas->ini_frame, 0 ) ) { /* reconfigure in case a change of operation mode is detected */ - IF ( ( GT_32(ivas_total_brate, IVAS_SID_5k2) && NE_32(ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate )) || EQ_16( st_ivas->ini_active_frame, 0 ) ) + IF( ( GT_32( ivas_total_brate, IVAS_SID_5k2 ) && NE_32( ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate ) ) || EQ_16( st_ivas->ini_active_frame, 0 ) ) { - IF ( st_ivas->last_ivas_format == MASA_FORMAT ) + IF( st_ivas->last_ivas_format == MASA_FORMAT ) { - IF ( EQ_16(st_ivas->ini_active_frame, 0) && NE_32(ivas_total_brate, FRAME_NO_DATA) && LT_32(ivas_total_brate, MASA_STEREO_MIN_BITRATE) && EQ_16(st_ivas->nCPE, 1 )) + IF( EQ_16( st_ivas->ini_active_frame, 0 ) && NE_32( ivas_total_brate, FRAME_NO_DATA ) && LT_32( ivas_total_brate, MASA_STEREO_MIN_BITRATE ) && EQ_16( st_ivas->nCPE, 1 ) ) { st_ivas->hCPE[0]->nchan_out = 1; } ELSE { - IF ( ( error = ivas_masa_dec_reconfigure_fx( st_ivas, nSamplesRendered, data ) ) != IVAS_ERR_OK ) { + IF( ( error = ivas_masa_dec_reconfigure_fx( st_ivas, nSamplesRendered, data ) ) != IVAS_ERR_OK ) + { return error; } } @@ -204,7 +204,7 @@ ivas_error ivas_dec_setup( } } } - ELSE IF ( st_ivas->ivas_format == MASA_ISM_FORMAT ) + ELSE IF( st_ivas->ivas_format == MASA_ISM_FORMAT ) { st_ivas->nchan_transport = 2; /* always 2 MASA transport channels */ @@ -212,10 +212,10 @@ ivas_error ivas_dec_setup( st_ivas->nchan_ism = 2 * st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 1] + st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 2] + 1; st_ivas->ism_mode = ivas_omasa_ism_mode_select( ivas_total_brate, st_ivas->nchan_ism ); - IF ( GT_16(st_ivas->ini_frame, 0 )) + IF( GT_16( st_ivas->ini_frame, 0 ) ) { /* reconfigure in case a change of operation mode is detected */ - IF ( ( GT_32(ivas_total_brate, IVAS_SID_5k2) && NE_32(ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate )) || EQ_16( st_ivas->ini_active_frame, 0 ) ) + IF( ( GT_32( ivas_total_brate, IVAS_SID_5k2 ) && NE_32( ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate ) ) || EQ_16( st_ivas->ini_active_frame, 0 ) ) { IF( ( error = ivas_omasa_dec_config_fx( st_ivas, nSamplesRendered, &num_src, SrcInd, data ) ) != IVAS_ERR_OK ) { @@ -224,31 +224,31 @@ ivas_error ivas_dec_setup( } } } - ELSE IF ( st_ivas->ivas_format == SBA_ISM_FORMAT ) + ELSE IF( st_ivas->ivas_format == SBA_ISM_FORMAT ) { /* the number of objects is written at the end of the bitstream, in the SBA metadata */ st_ivas->nchan_ism = 2 * st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 1] + st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 2] + 1; - IF ( LT_32(ivas_total_brate, IVAS_24k4) || GE_32(ivas_total_brate, IVAS_256k )) + IF( LT_32( ivas_total_brate, IVAS_24k4 ) || GE_32( ivas_total_brate, IVAS_256k ) ) { /* read Ambisonic (SBA) planar flag */ st_ivas->sba_planar = st_ivas->bit_stream[num_bits_read]; - num_bits_read = add(num_bits_read, SBA_PLANAR_BITS); + num_bits_read = add( num_bits_read, SBA_PLANAR_BITS ); } st_ivas->sba_order = st_ivas->bit_stream[num_bits_read + 1]; st_ivas->sba_order += 2 * st_ivas->bit_stream[num_bits_read]; - num_bits_read = add(num_bits_read, SBA_ORDER_BITS); + num_bits_read = add( num_bits_read, SBA_ORDER_BITS ); /* read Ambisonic (SBA) order */ - IF ( LT_32(ivas_total_brate, IVAS_256k )) + IF( LT_32( ivas_total_brate, IVAS_256k ) ) { st_ivas->sba_order = 3; } - IF ( GT_16(st_ivas->ini_frame, 0) && NE_32(ivas_total_brate, st_ivas->last_active_ivas_total_brate )) + IF( GT_16( st_ivas->ini_frame, 0 ) && NE_32( ivas_total_brate, st_ivas->last_active_ivas_total_brate ) ) { - IF ( ( error = ivas_sba_dec_reconfigure_fx( st_ivas, nSamplesRendered, data ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_sba_dec_reconfigure_fx( st_ivas, nSamplesRendered, data ) ) != IVAS_ERR_OK ) { return error; } @@ -261,13 +261,13 @@ ivas_error ivas_dec_setup( ivas_sba_config( ivas_total_brate, st_ivas->sba_analysis_order, -1, &( st_ivas->nchan_transport ), st_ivas->sba_planar, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init ); /*correct number of CPEs for discrete ISM coding*/ - IF ( GT_16(st_ivas->ini_frame, 0) && st_ivas->ism_mode == ISM_SBA_MODE_DISC ) + IF( GT_16( st_ivas->ini_frame, 0 ) && st_ivas->ism_mode == ISM_SBA_MODE_DISC ) { st_ivas->nCPE += add( st_ivas->nchan_ism, 1 ) >> 1; } } - IF ( GE_32(ivas_total_brate, IVAS_256k )) + IF( GE_32( ivas_total_brate, IVAS_256k ) ) { st_ivas->ism_mode = ISM_SBA_MODE_DISC; } @@ -276,21 +276,21 @@ ivas_error ivas_dec_setup( st_ivas->ism_mode = ISM_MODE_NONE; } } - ELSE IF ( st_ivas->ivas_format == MC_FORMAT ) + ELSE IF( st_ivas->ivas_format == MC_FORMAT ) { /* read MC configuration */ idx = 0; - FOR ( k = 0; k < MC_LS_SETUP_BITS; k++ ) + FOR( k = 0; k < MC_LS_SETUP_BITS; k++ ) { - IF ( st_ivas->bit_stream[num_bits_read + k] ) + IF( st_ivas->bit_stream[num_bits_read + k] ) { idx += 1 << ( MC_LS_SETUP_BITS - 1 - k ); } } - num_bits_read = add(num_bits_read, MC_LS_SETUP_BITS); + num_bits_read = add( num_bits_read, MC_LS_SETUP_BITS ); /* select MC format mode; reconfigure the MC format decoder */ - IF ( ( error = ivas_mc_dec_config_fx( st_ivas, idx, nSamplesRendered, data ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_mc_dec_config_fx( st_ivas, idx, nSamplesRendered, data ) ) != IVAS_ERR_OK ) { return error; } @@ -300,19 +300,19 @@ ivas_error ivas_dec_setup( * Read element mode *-------------------------------------------------------------------*/ - IF ( EQ_16(st_ivas->ini_frame, 0) && element_mode_flag ) + IF( EQ_16( st_ivas->ini_frame, 0 ) && element_mode_flag ) { /* read stereo technology info */ - IF ( LT_32(ivas_total_brate, MIN_BRATE_MDCT_STEREO )) + IF( LT_32( ivas_total_brate, MIN_BRATE_MDCT_STEREO ) ) { /* 1 bit */ - IF ( st_ivas->bit_stream[num_bits_read] ) + IF( st_ivas->bit_stream[num_bits_read] ) { - st_ivas->element_mode_init = add(1, IVAS_CPE_DFT); + st_ivas->element_mode_init = add( 1, IVAS_CPE_DFT ); } ELSE { - st_ivas->element_mode_init = add(0, IVAS_CPE_DFT); + st_ivas->element_mode_init = add( 0, IVAS_CPE_DFT ); } } ELSE @@ -321,9 +321,9 @@ ivas_error ivas_dec_setup( } } } - ELSE IF ( EQ_32(ivas_total_brate, IVAS_SID_5k2 )) + ELSE IF( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) ) { - SWITCH ( st_ivas->sid_format ) + SWITCH( st_ivas->sid_format ) { case SID_DFT_STEREO: st_ivas->element_mode_init = IVAS_CPE_DFT; @@ -339,7 +339,7 @@ ivas_error ivas_dec_setup( st_ivas->nchan_transport = 1; BREAK; case SID_MASA_2TC: - IF ( st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 1 - SID_FORMAT_NBITS] == 1 ) + IF( st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 1 - SID_FORMAT_NBITS] == 1 ) { st_ivas->element_mode_init = IVAS_CPE_MDCT; } @@ -357,16 +357,16 @@ ivas_error ivas_dec_setup( BREAK; } - IF ( GT_16(st_ivas->ini_frame, 0) && st_ivas->ivas_format == SBA_FORMAT ) + IF( GT_16( st_ivas->ini_frame, 0 ) && st_ivas->ivas_format == SBA_FORMAT ) { Word16 nchan_transport_old, nchan_transport; nchan_transport_old = st_ivas->nchan_transport; - nchan_transport = ( EQ_16(st_ivas->sid_format, SID_SBA_2TC )) ? 2 : 1; + nchan_transport = ( EQ_16( st_ivas->sid_format, SID_SBA_2TC ) ) ? 2 : 1; - IF ( ( nchan_transport_old != nchan_transport ) ) + IF( ( nchan_transport_old != nchan_transport ) ) { /*Setting the default bitrate for the reconfig function*/ - IF ( EQ_16(st_ivas->sid_format, SID_SBA_2TC )) + IF( EQ_16( st_ivas->sid_format, SID_SBA_2TC ) ) { st_ivas->hDecoderConfig->ivas_total_brate = IVAS_48k; } @@ -375,7 +375,7 @@ ivas_error ivas_dec_setup( st_ivas->hDecoderConfig->ivas_total_brate = IVAS_24k4; } - IF ( ( error = ivas_sba_dec_reconfigure_fx( st_ivas, nSamplesRendered, data ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_sba_dec_reconfigure_fx( st_ivas, nSamplesRendered, data ) ) != IVAS_ERR_OK ) { return error; } @@ -385,7 +385,7 @@ ivas_error ivas_dec_setup( } } - IF ( st_ivas->ivas_format == ISM_FORMAT ) + IF( st_ivas->ivas_format == ISM_FORMAT ) { ISM_MODE last_ism_mode = st_ivas->ism_mode; @@ -393,7 +393,7 @@ ivas_error ivas_dec_setup( st_ivas->nchan_transport = 1; nchan_ism = 1; k = (Word16) ( ( ivas_total_brate / FRAMES_PER_SEC ) - 1 ) - SID_FORMAT_NBITS; - WHILE ( st_ivas->bit_stream[k] && LT_16(nchan_ism, MAX_NUM_OBJECTS )) + WHILE( st_ivas->bit_stream[k] && LT_16( nchan_ism, MAX_NUM_OBJECTS ) ) { nchan_ism++; k--; @@ -409,19 +409,19 @@ ivas_error ivas_dec_setup( /* read ism_mode */ st_ivas->ism_mode = ISM_MODE_DISC; - IF ( GT_16(nchan_ism, 2 )) + IF( GT_16( nchan_ism, 2 ) ) { k -= nchan_ism; /* SID metadata flags */ idx = st_ivas->bit_stream[k]; - st_ivas->ism_mode = (ISM_MODE) add( idx , 1 ); + st_ivas->ism_mode = (ISM_MODE) add( idx, 1 ); } - IF ( st_ivas->ini_frame == 0 ) + IF( st_ivas->ini_frame == 0 ) { last_ism_mode = st_ivas->ism_mode; } - IF ( ( error = ivas_ism_dec_config_fx( st_ivas, last_ism_mode, nSamplesRendered, data ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_ism_dec_config_fx( st_ivas, last_ism_mode, nSamplesRendered, data ) ) != IVAS_ERR_OK ) { return error; } @@ -433,14 +433,14 @@ ivas_error ivas_dec_setup( * and number of transport channels *-------------------------------------------------------------------*/ - IF ( EQ_16(st_ivas->ini_frame, 0) && st_ivas->ivas_format != UNDEFINED_FORMAT ) + IF( EQ_16( st_ivas->ini_frame, 0 ) && st_ivas->ivas_format != UNDEFINED_FORMAT ) { - IF ( ( error = doSanityChecks_IVAS( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = doSanityChecks_IVAS( st_ivas ) ) != IVAS_ERR_OK ) { return IVAS_ERROR( error, "Sanity checks failed" ); } - IF ( ( error = ivas_init_decoder_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_init_decoder_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -456,7 +456,7 @@ ivas_error ivas_dec_setup( reset_elements( st_ivas ); /* update bitstream buffer pointer -> take into account already read bits */ - IF ( ( GT_16(st_ivas->nSCE, 0 )) || ( GT_16(st_ivas->nCPE, 0 )) ) + IF( ( GT_16( st_ivas->nSCE, 0 ) ) || ( GT_16( st_ivas->nCPE, 0 ) ) ) { st = GT_16( st_ivas->nSCE, 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0] : st_ivas->hCPE[0]->hCoreCoder[0]; st->next_bit_pos = num_bits_read; @@ -469,7 +469,7 @@ ivas_error ivas_dec_setup( ivas_error ivas_dec_setup( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ uint16_t *nSamplesRendered, /* o : number of samples flushed from the previous frame (JBM) */ - int16_t *data /* o : output synthesis signal */ + int16_t *data /* o : output synthesis signal */ ) { int16_t k, idx, num_bits_read; @@ -864,7 +864,6 @@ ivas_error ivas_dec_setup( #endif - // ivas_param_ism_dec /*-------------------------------------------------------------------* * ivas_read_format() @@ -875,7 +874,7 @@ ivas_error ivas_dec_setup( #ifdef IVAS_FLOAT_FIXED static ivas_error ivas_read_format( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - Word16 *num_bits_read /* o : number of IVAS signaling bits read from the bitstream */ + Word16 *num_bits_read /* o : number of IVAS signaling bits read from the bitstream */ ) { Word16 k, idx; @@ -890,24 +889,24 @@ static ivas_error ivas_read_format( *num_bits_read = 0; move16(); - IF ( !st_ivas->bfi && is_DTXrate( ivas_total_brate ) == 0 ) + IF( !st_ivas->bfi && is_DTXrate( ivas_total_brate ) == 0 ) { /* read IVAS format */ k = 0; - IF ( st_ivas->bit_stream[*num_bits_read] ) + IF( st_ivas->bit_stream[*num_bits_read] ) { k = 1; } k <<= 1; ( *num_bits_read )++; - IF ( st_ivas->bit_stream[*num_bits_read] ) + IF( st_ivas->bit_stream[*num_bits_read] ) { k += 1; } ( *num_bits_read )++; - SWITCH ( k ) + SWITCH( k ) { case 0: st_ivas->ivas_format = STEREO_FORMAT; @@ -918,12 +917,12 @@ static ivas_error ivas_read_format( case 2: st_ivas->ivas_format = ISM_FORMAT; - IF ( ivas_total_brate >= IVAS_24k4 ) + IF( ivas_total_brate >= IVAS_24k4 ) { - IF ( st_ivas->bit_stream[*num_bits_read] ) + IF( st_ivas->bit_stream[*num_bits_read] ) { ( *num_bits_read )++; - IF ( st_ivas->bit_stream[*num_bits_read] ) + IF( st_ivas->bit_stream[*num_bits_read] ) { st_ivas->ivas_format = SBA_ISM_FORMAT; } @@ -937,7 +936,7 @@ static ivas_error ivas_read_format( } BREAK; case 3: - IF ( st_ivas->bit_stream[*num_bits_read] ) + IF( st_ivas->bit_stream[*num_bits_read] ) { st_ivas->ivas_format = MASA_FORMAT; } @@ -950,7 +949,7 @@ static ivas_error ivas_read_format( /* read Ambisonic (SBA) order */ st_ivas->sba_order = st_ivas->bit_stream[( *num_bits_read ) + 2 + SBA_PLANAR_BITS]; st_ivas->sba_order += 2 * st_ivas->bit_stream[( *num_bits_read ) + 1 + SBA_PLANAR_BITS]; - IF ( st_ivas->sba_order == 0 ) + IF( st_ivas->sba_order == 0 ) { st_ivas->ivas_format = SBA_ISM_FORMAT; } @@ -960,19 +959,19 @@ static ivas_error ivas_read_format( BREAK; } } - ELSE IF ( EQ_16(st_ivas->bfi, 0) && ivas_total_brate == IVAS_SID_5k2 ) + ELSE IF( EQ_16( st_ivas->bfi, 0 ) && ivas_total_brate == IVAS_SID_5k2 ) { /* read IVAS format in SID frame */ idx = 0; - FOR ( k = 0; k < SID_FORMAT_NBITS; k++ ) + FOR( k = 0; k < SID_FORMAT_NBITS; k++ ) { idx += st_ivas->bit_stream[k] << ( SID_FORMAT_NBITS - 1 - k ); } - ( *num_bits_read ) = add(*num_bits_read, SID_FORMAT_NBITS); + ( *num_bits_read ) = add( *num_bits_read, SID_FORMAT_NBITS ); st_ivas->sid_format = idx; - SWITCH ( idx ) + SWITCH( idx ) { case SID_DFT_STEREO: case SID_MDCT_STEREO: @@ -999,7 +998,7 @@ static ivas_error ivas_read_format( BREAK; case SID_MASA_2TC: st_ivas->ivas_format = MASA_FORMAT; - IF ( st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 1] == 1 ) + IF( st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 1] == 1 ) { st_ivas->element_mode_init = IVAS_CPE_MDCT; } @@ -1013,9 +1012,9 @@ static ivas_error ivas_read_format( return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Invalid value %c found in SID format field.", st_ivas->sid_format ); } - IF ( st_ivas->ivas_format == SBA_FORMAT ) + IF( st_ivas->ivas_format == SBA_FORMAT ) { - IF ( st_ivas->sba_analysis_order == 0 ) + IF( st_ivas->sba_analysis_order == 0 ) { st_ivas->sba_analysis_order = SBA_FOA_ORDER; } @@ -1210,21 +1209,21 @@ Word16 getNumChanSynthesis( { Word16 n; - n = add(st_ivas->nSCE , imult1616(CPE_CHANNELS , st_ivas->nCPE)); + n = add( st_ivas->nSCE, imult1616( CPE_CHANNELS, st_ivas->nCPE ) ); - IF ( st_ivas->sba_dirac_stereo_flag ) + IF( st_ivas->sba_dirac_stereo_flag ) { n = CPE_CHANNELS; } - ELSE IF ( ( st_ivas->hMCT != NULL || EQ_16(st_ivas->ivas_format , SBA_FORMAT) ) && NE_16(st_ivas->ivas_format , SBA_ISM_FORMAT) ) + ELSE IF( ( st_ivas->hMCT != NULL || EQ_16( st_ivas->ivas_format, SBA_FORMAT ) ) && NE_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { n = st_ivas->nchan_transport; } - ELSE IF ( EQ_16(st_ivas->ivas_format , SBA_ISM_FORMAT) ) + ELSE IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { - IF ( EQ_16(st_ivas->ism_mode , ISM_SBA_MODE_DISC) ) + IF( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { - n = add(st_ivas->nchan_transport , st_ivas->nchan_ism); + n = add( st_ivas->nchan_transport, st_ivas->nchan_ism ); } ELSE { @@ -1362,18 +1361,18 @@ ivas_error ivas_init_decoder_front( * Allocate and initialize Custom loudspeaker layout handle *--------------------------------------------------------------------*/ - IF ( st_ivas->hDecoderConfig->Opt_LsCustom ) + IF( st_ivas->hDecoderConfig->Opt_LsCustom ) { - IF ( ( error = ivas_ls_custom_open_fx( &( st_ivas->hLsSetupCustom ) ) ) == IVAS_ERR_OK ) + IF( ( error = ivas_ls_custom_open_fx( &( st_ivas->hLsSetupCustom ) ) ) == IVAS_ERR_OK ) { #ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED - set_zero((st_ivas->hLsSetupCustom)->ls_azimuth, MAX_OUTPUT_CHANNELS ); - set_zero((st_ivas->hLsSetupCustom)->ls_elevation, MAX_OUTPUT_CHANNELS ); + set_zero( ( st_ivas->hLsSetupCustom )->ls_azimuth, MAX_OUTPUT_CHANNELS ); + set_zero( ( st_ivas->hLsSetupCustom )->ls_elevation, MAX_OUTPUT_CHANNELS ); #endif - set_zero_fx((st_ivas->hLsSetupCustom)->ls_azimuth_fx, MAX_OUTPUT_CHANNELS ); - set_zero_fx((st_ivas->hLsSetupCustom)->ls_elevation_fx, MAX_OUTPUT_CHANNELS ); + set_zero_fx( ( st_ivas->hLsSetupCustom )->ls_azimuth_fx, MAX_OUTPUT_CHANNELS ); + set_zero_fx( ( st_ivas->hLsSetupCustom )->ls_elevation_fx, MAX_OUTPUT_CHANNELS ); } - ELSE + ELSE { return error; } @@ -1399,14 +1398,14 @@ ivas_error ivas_init_decoder_front( * Allocate and initialize external orientation handle *--------------------------------------------------------------------*/ - IF ( st_ivas->hDecoderConfig->Opt_ExternalOrientation ) + IF( st_ivas->hDecoderConfig->Opt_ExternalOrientation ) { - IF ( ( error = ivas_external_orientation_open( &( st_ivas->hExtOrientationData ), st_ivas->hDecoderConfig->render_framesize ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_external_orientation_open( &( st_ivas->hExtOrientationData ), st_ivas->hDecoderConfig->render_framesize ) ) != IVAS_ERR_OK ) { return error; } #ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED - FOR ( Word16 i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + FOR( Word16 i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { st_ivas->hExtOrientationData->Quaternions[i].w = fixedToFloat_32( st_ivas->hExtOrientationData->Quaternions[i].w_fx, st_ivas->hExtOrientationData->Quaternions[i].q_fact ); st_ivas->hExtOrientationData->Quaternions[i].x = fixedToFloat_32( st_ivas->hExtOrientationData->Quaternions[i].x_fx, st_ivas->hExtOrientationData->Quaternions[i].q_fact ); @@ -1421,20 +1420,20 @@ ivas_error ivas_init_decoder_front( * Allocate and initialize combined orientation handle *--------------------------------------------------------------------*/ - IF ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) + IF( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) { - IF ( ( error = ivas_combined_orientation_open( &( st_ivas->hCombinedOrientationData ), st_ivas->hDecoderConfig->output_Fs, st_ivas->hDecoderConfig->render_framesize ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_combined_orientation_open( &( st_ivas->hCombinedOrientationData ), st_ivas->hDecoderConfig->output_Fs, st_ivas->hDecoderConfig->render_framesize ) ) != IVAS_ERR_OK ) { return error; } #ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED - FOR ( Word16 i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + FOR( Word16 i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { st_ivas->hCombinedOrientationData->Quaternions[i].w = fixedToFloat_32( st_ivas->hCombinedOrientationData->Quaternions[i].w_fx, st_ivas->hCombinedOrientationData->Quaternions[i].q_fact ); st_ivas->hCombinedOrientationData->Quaternions[i].x = fixedToFloat_32( st_ivas->hCombinedOrientationData->Quaternions[i].x_fx, st_ivas->hCombinedOrientationData->Quaternions[i].q_fact ); st_ivas->hCombinedOrientationData->Quaternions[i].y = fixedToFloat_32( st_ivas->hCombinedOrientationData->Quaternions[i].y_fx, st_ivas->hCombinedOrientationData->Quaternions[i].q_fact ); st_ivas->hCombinedOrientationData->Quaternions[i].z = fixedToFloat_32( st_ivas->hCombinedOrientationData->Quaternions[i].z_fx, st_ivas->hCombinedOrientationData->Quaternions[i].q_fact ); - + st_ivas->hCombinedOrientationData->listenerPos[i].x = fixedToFloat_32( st_ivas->hCombinedOrientationData->listenerPos[i].x_fx, st_ivas->hCombinedOrientationData->listenerPos[i].q_fact ); st_ivas->hCombinedOrientationData->listenerPos[i].y = fixedToFloat_32( st_ivas->hCombinedOrientationData->listenerPos[i].y_fx, st_ivas->hCombinedOrientationData->listenerPos[i].q_fact ); st_ivas->hCombinedOrientationData->listenerPos[i].z = fixedToFloat_32( st_ivas->hCombinedOrientationData->listenerPos[i].z_fx, st_ivas->hCombinedOrientationData->listenerPos[i].q_fact ); @@ -1446,7 +1445,7 @@ ivas_error ivas_init_decoder_front( * Allocate HRTF binary handle *--------------------------------------------------------------------*/ - IF ( st_ivas->hDecoderConfig->Opt_HRTF_binary ) + IF( st_ivas->hDecoderConfig->Opt_HRTF_binary ) { IF( ( error = ivas_HRTF_binary_open_fx( &( st_ivas->hHrtfTD ) ) ) != IVAS_ERR_OK ) { @@ -1458,7 +1457,7 @@ ivas_error ivas_init_decoder_front( return error; } - IF ( ( error = ivas_HRTF_fastconv_binary_open_fx( &st_ivas->hHrtfFastConv ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_HRTF_fastconv_binary_open_fx( &st_ivas->hHrtfFastConv ) ) != IVAS_ERR_OK ) { return error; } @@ -1473,22 +1472,21 @@ ivas_error ivas_init_decoder_front( * Allocate and initialize Binaural Renderer configuration handle *--------------------------------------------------------------------*/ - IF ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB - ) + IF( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) { - IF ( ( error = ivas_render_config_open( &( st_ivas->hRenderConfig ) ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_render_config_open( &( st_ivas->hRenderConfig ) ) ) != IVAS_ERR_OK ) { return error; } - IF((error = ivas_render_config_init_from_rom_fx(&st_ivas->hRenderConfig)) != IVAS_ERR_OK) + IF( ( error = ivas_render_config_init_from_rom_fx( &st_ivas->hRenderConfig ) ) != IVAS_ERR_OK ) { return error; } #ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED /*FLOAT CODE*/ - IF ( ( error = ivas_render_config_init_from_rom( &st_ivas->hRenderConfig ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_render_config_init_from_rom( &st_ivas->hRenderConfig ) ) != IVAS_ERR_OK ) { return error; } @@ -1604,8 +1602,7 @@ ivas_error ivas_init_decoder_front( * Allocate and initialize Binaural Renderer configuration handle *--------------------------------------------------------------------*/ - if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB - ) + if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) { if ( ( error = ivas_render_config_open( &( st_ivas->hRenderConfig ) ) ) != IVAS_ERR_OK ) { @@ -1624,7 +1621,6 @@ ivas_error ivas_init_decoder_front( #endif - /*-------------------------------------------------------------------* * ivas_init_decoder() * @@ -1660,18 +1656,18 @@ ivas_error ivas_init_decoder_fx( * Set number of output channels for EXTERNAL output config. *-----------------------------------------------------------------*/ - IF ( output_config == IVAS_AUDIO_CONFIG_EXTERNAL ) + IF( output_config == IVAS_AUDIO_CONFIG_EXTERNAL ) { - IF ( st_ivas->ivas_format == SBA_ISM_FORMAT ) + IF( st_ivas->ivas_format == SBA_ISM_FORMAT ) { hDecoderConfig->nchan_out = audioCfg2channels( IVAS_AUDIO_CONFIG_HOA3 ); hDecoderConfig->nchan_out += st_ivas->nchan_ism; } - ELSE IF ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + ELSE IF( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { hDecoderConfig->nchan_out = st_ivas->nchan_transport + st_ivas->nchan_ism; } - ELSE IF ( !( st_ivas->ism_mode == ISM_MODE_PARAM ) ) + ELSE IF( !( st_ivas->ism_mode == ISM_MODE_PARAM ) ) { hDecoderConfig->nchan_out = st_ivas->nchan_transport; } @@ -1687,7 +1683,7 @@ ivas_error ivas_init_decoder_fx( ivas_output_init( &( st_ivas->hOutSetup ), output_config ); - IF ( st_ivas->ivas_format == SBA_ISM_FORMAT && output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) + IF( st_ivas->ivas_format == SBA_ISM_FORMAT && output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) { st_ivas->hOutSetup.ambisonics_order = SBA_HOA3_ORDER; st_ivas->intern_config = IVAS_AUDIO_CONFIG_7_1_4; @@ -1695,7 +1691,7 @@ ivas_error ivas_init_decoder_fx( st_ivas->hOutSetup.nchan_out_woLFE = audioCfg2channels( st_ivas->intern_config ); } - IF ( st_ivas->ivas_format == SBA_ISM_FORMAT && output_config == IVAS_AUDIO_CONFIG_EXTERNAL ) + IF( st_ivas->ivas_format == SBA_ISM_FORMAT && output_config == IVAS_AUDIO_CONFIG_EXTERNAL ) { st_ivas->hOutSetup.ambisonics_order = SBA_HOA3_ORDER; st_ivas->intern_config = IVAS_AUDIO_CONFIG_HOA3; @@ -1704,12 +1700,12 @@ ivas_error ivas_init_decoder_fx( } /* Only initialize transport setup if it is used */ - IF ( st_ivas->transport_config != IVAS_AUDIO_CONFIG_INVALID ) + IF( st_ivas->transport_config != IVAS_AUDIO_CONFIG_INVALID ) { ivas_output_init( &( st_ivas->hTransSetup ), st_ivas->transport_config ); } - IF ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) + IF( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) { ivas_mcmasa_setNumTransportChannels_fx( &( st_ivas->nchan_transport ), &( st_ivas->element_mode_init ), ivas_total_brate ); @@ -1718,9 +1714,10 @@ ivas_error ivas_init_decoder_fx( ivas_renderer_select( st_ivas ); - IF ( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM ) + IF( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM ) { - IF ( ( error = ivas_ls_custom_output_init_fx( st_ivas ) ) == IVAS_ERR_OK ) { + IF( ( error = ivas_ls_custom_output_init_fx( st_ivas ) ) == IVAS_ERR_OK ) + { st_ivas->hOutSetup.ls_azimuth_fx = st_ivas->hLsSetupCustom->ls_azimuth_fx; st_ivas->hOutSetup.ls_elevation_fx = st_ivas->hLsSetupCustom->ls_elevation_fx; st_ivas->hIntSetup.ls_azimuth_fx = st_ivas->hLsSetupCustom->ls_azimuth_fx; @@ -1734,19 +1731,19 @@ ivas_error ivas_init_decoder_fx( ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config ); - IF ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) + IF( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) { ivas_mcmasa_set_separate_channel_mode_fx( &( st_ivas->hIntSetup.separateChannelEnabled ), &( st_ivas->hIntSetup.separateChannelIndex ), ivas_total_brate ); - IF ( st_ivas->hOutSetup.output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM && st_ivas->hOutSetup.separateChannelEnabled ) + IF( st_ivas->hOutSetup.output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM && st_ivas->hOutSetup.separateChannelEnabled ) { st_ivas->hLsSetupCustom->separate_ch_found = 0; - IF ( st_ivas->hOutSetup.nchan_out_woLFE >= MCMASA_MIN_SPEAKERS_SEPARATE_CENTER ) + IF( st_ivas->hOutSetup.nchan_out_woLFE >= MCMASA_MIN_SPEAKERS_SEPARATE_CENTER ) { /* check for a speaker at (0, 0) if minimum speaker count is available */ - FOR ( i = 0; i < st_ivas->hOutSetup.nchan_out_woLFE; i++ ) + FOR( i = 0; i < st_ivas->hOutSetup.nchan_out_woLFE; i++ ) { - IF ( L_shr(st_ivas->hOutSetup.ls_azimuth_fx[i], Q22) == 0 && L_shr(st_ivas->hOutSetup.ls_elevation_fx[i], Q22) == 0 ) + IF( L_shr( st_ivas->hOutSetup.ls_azimuth_fx[i], Q22 ) == 0 && L_shr( st_ivas->hOutSetup.ls_elevation_fx[i], Q22 ) == 0 ) { st_ivas->hIntSetup.separateChannelIndex = i; move16(); @@ -1764,22 +1761,25 @@ ivas_error ivas_init_decoder_fx( * Allocate and initialize SCE/CPE and other handles *-----------------------------------------------------------------*/ - IF ( EQ_32( st_ivas->ivas_format, MONO_FORMAT ) ) + IF( EQ_32( st_ivas->ivas_format, MONO_FORMAT ) ) { st_ivas->nSCE = 1; /* in mono, there is always only one SCE */ st_ivas->nCPE = 0; st_ivas->nchan_transport = 1; sce_id = 0; - move16(); move16(); move16(); move16(); + move16(); + move16(); + move16(); + move16(); - IF ( ( error = create_sce_dec( st_ivas, sce_id, ivas_total_brate ) ) != IVAS_ERR_OK ) + IF( ( error = create_sce_dec( st_ivas, sce_id, ivas_total_brate ) ) != IVAS_ERR_OK ) { return error; } reset_indices_dec( st_ivas->hSCE[sce_id]->hCoreCoder[0] ); } - ELSE IF ( st_ivas->ivas_format == STEREO_FORMAT ) + ELSE IF( st_ivas->ivas_format == STEREO_FORMAT ) { st_ivas->nchan_transport = CPE_CHANNELS; st_ivas->intern_config = IVAS_AUDIO_CONFIG_STEREO; @@ -1787,22 +1787,26 @@ ivas_error ivas_init_decoder_fx( st_ivas->nSCE = 0; st_ivas->nCPE = 1; /* in stereo, there is always only one CPE */ cpe_id = 0; - move16(); move16(); move16(); move16(); move16(); + move16(); + move16(); + move16(); + move16(); + move16(); - IF ( ( error = create_cpe_dec( st_ivas, cpe_id, ivas_total_brate ) ) != IVAS_ERR_OK ) + IF( ( error = create_cpe_dec( st_ivas, cpe_id, ivas_total_brate ) ) != IVAS_ERR_OK ) { return error; } - FOR ( n = 0; n < st_ivas->nchan_transport; n++ ) + FOR( n = 0; n < st_ivas->nchan_transport; n++ ) { reset_indices_dec( st_ivas->hCPE[cpe_id]->hCoreCoder[n] ); } /* init EFAP for custom LS output and set hTransSetup */ - IF ( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM ) + IF( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM ) { - IF ( ( error = efap_init_data_fx( &( st_ivas->hEFAPdata ), st_ivas->hOutSetup.ls_azimuth_fx, st_ivas->hOutSetup.ls_elevation_fx, st_ivas->hOutSetup.nchan_out_woLFE, EFAP_MODE_EFAP ) ) != IVAS_ERR_OK ) + IF( ( error = efap_init_data_fx( &( st_ivas->hEFAPdata ), st_ivas->hOutSetup.ls_azimuth_fx, st_ivas->hOutSetup.ls_elevation_fx, st_ivas->hOutSetup.nchan_out_woLFE, EFAP_MODE_EFAP ) ) != IVAS_ERR_OK ) { return error; } @@ -1810,7 +1814,7 @@ ivas_error ivas_init_decoder_fx( ivas_output_init( &( st_ivas->hTransSetup ), IVAS_AUDIO_CONFIG_STEREO ); } } - ELSE IF ( st_ivas->ivas_format == ISM_FORMAT ) + ELSE IF( st_ivas->ivas_format == ISM_FORMAT ) { Word32 element_brate_tmp[MAX_NUM_OBJECTS]; @@ -1819,28 +1823,31 @@ ivas_error ivas_init_decoder_fx( st_ivas->ism_extmeta_active = -1; st_ivas->ism_extmeta_cnt = 0; - move16(); move16(); move16(); move16(); - IF ( st_ivas->ism_mode == ISM_MODE_PARAM ) + move16(); + move16(); + move16(); + move16(); + IF( st_ivas->ism_mode == ISM_MODE_PARAM ) { st_ivas->nchan_transport = MAX_PARAM_ISM_WAVE; move16(); st_ivas->nSCE = MAX_PARAM_ISM_WAVE; move16(); - IF ( ( error = ivas_param_ism_dec_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_param_ism_dec_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } } - IF ( ( error = ivas_ism_metadata_dec_create_fx( st_ivas, st_ivas->nSCE, element_brate_tmp ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_ism_metadata_dec_create_fx( st_ivas, st_ivas->nSCE, element_brate_tmp ) ) != IVAS_ERR_OK ) { return error; } - FOR ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { - IF ( ( error = create_sce_dec( st_ivas, sce_id, element_brate_tmp[sce_id] ) ) != IVAS_ERR_OK ) + IF( ( error = create_sce_dec( st_ivas, sce_id, element_brate_tmp[sce_id] ) ) != IVAS_ERR_OK ) { return error; } @@ -1853,26 +1860,26 @@ ivas_error ivas_init_decoder_fx( st_ivas->hISMDTX.sce_id_dtx = 0; move16(); - IF ( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ) + IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ) { st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->seed2 = st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->seed3; } - ELSE IF ( EQ_32( st_ivas->ism_mode, ISM_MODE_DISC ) ) + ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MODE_DISC ) ) { - FOR ( sce_id = 0; sce_id < st_ivas->nSCE; ++sce_id ) + FOR( sce_id = 0; sce_id < st_ivas->nSCE; ++sce_id ) { st_ivas->hSCE[sce_id]->hCoreCoder[0]->hFdCngDec->hFdCngCom->seed2 = 2 + sce_id; } } } - ELSE IF ( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) ) + ELSE IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) ) { - IF ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) { return error; } - IF ( ( error = ivas_spar_dec_open_fx( st_ivas, 0 ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_spar_dec_open_fx( st_ivas, 0 ) ) != IVAS_ERR_OK ) { return error; } @@ -1881,22 +1888,22 @@ ivas_error ivas_init_decoder_fx( set_s( st_ivas->hSpar->hFbMixer->cldfb_cross_fade_fx, 0, CLDFB_NO_COL_MAX ); #endif - IF ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_DEC && st_ivas->hOutSetup.is_loudspeaker_setup ) + IF( st_ivas->renderer_type == RENDERER_SBA_LINEAR_DEC && st_ivas->hOutSetup.is_loudspeaker_setup ) { - IF ( ( error = ivas_sba_get_hoa_dec_matrix_fx( st_ivas->hOutSetup, &st_ivas->hoa_dec_mtx, st_ivas->hIntSetup.ambisonics_order ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_sba_get_hoa_dec_matrix_fx( st_ivas->hOutSetup, &st_ivas->hoa_dec_mtx, st_ivas->hIntSetup.ambisonics_order ) ) != IVAS_ERR_OK ) { return error; } } - IF ( ( error = ivas_dirac_sba_config_fx( st_ivas->hQMetaData, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) ? IVAS_MAX_NUM_BANDS : ( IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ),st_ivas->ivas_format ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_dirac_sba_config_fx( st_ivas->hQMetaData, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) ? IVAS_MAX_NUM_BANDS : ( IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ), st_ivas->ivas_format ) ) != IVAS_ERR_OK ) { return error; } - IF ( hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_FOA && st_ivas->hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_STEREO && st_ivas->hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_MONO ) + IF( hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_FOA && st_ivas->hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_STEREO && st_ivas->hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_MONO ) { - IF ( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK ) { return error; } @@ -1908,7 +1915,7 @@ ivas_error ivas_init_decoder_fx( Word16 band_grouping[IVAS_MAX_NUM_BANDS + 1]; st_ivas->hSpar->enc_param_start_band = min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND ); - IF ( ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) ) + IF( ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) ) { st_ivas->hSpar->enc_param_start_band = 0; @@ -1917,13 +1924,13 @@ ivas_error ivas_init_decoder_fx( } ivas_dirac_config_bands_fx( band_grouping, IVAS_MAX_NUM_BANDS, (Word16) ( st_ivas->hDecoderConfig->output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ), - st_ivas->hSpar->dirac_to_spar_md_bands, st_ivas->hQMetaData->useLowerBandRes, st_ivas->hSpar->enc_param_start_band, 0 ); + st_ivas->hSpar->dirac_to_spar_md_bands, st_ivas->hQMetaData->useLowerBandRes, st_ivas->hSpar->enc_param_start_band, 0 ); } st_ivas->sba_dirac_stereo_flag = ivas_get_sba_dirac_stereo_flag( st_ivas ); - FOR ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { - IF ( ( error = create_sce_dec( st_ivas, sce_id, ivas_total_brate / st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) + IF( ( error = create_sce_dec( st_ivas, sce_id, ivas_total_brate / st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) { return error; } @@ -1931,23 +1938,23 @@ ivas_error ivas_init_decoder_fx( reset_indices_dec( st_ivas->hSCE[sce_id]->hCoreCoder[0] ); } - FOR ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - IF ( ( error = create_cpe_dec( st_ivas, cpe_id, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) + IF( ( error = create_cpe_dec( st_ivas, cpe_id, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) { return error; } - FOR ( n = 0; n < CPE_CHANNELS; n++ ) + FOR( n = 0; n < CPE_CHANNELS; n++ ) { reset_indices_dec( st_ivas->hCPE[cpe_id]->hCoreCoder[n] ); } } /* create CPE element for DFT Stereo like upmix */ - IF ( st_ivas->sba_dirac_stereo_flag && st_ivas->nCPE == 0 ) + IF( st_ivas->sba_dirac_stereo_flag && st_ivas->nCPE == 0 ) { - IF ( ( error = create_cpe_dec( st_ivas, cpe_id, ivas_total_brate / ( st_ivas->nSCE + st_ivas->nCPE ) ) ) != IVAS_ERR_OK ) + IF( ( error = create_cpe_dec( st_ivas, cpe_id, ivas_total_brate / ( st_ivas->nSCE + st_ivas->nCPE ) ) ) != IVAS_ERR_OK ) { return error; } @@ -1956,9 +1963,9 @@ ivas_error ivas_init_decoder_fx( st_ivas->hCPE[0]->hCoreCoder[1] = NULL; } - IF ( st_ivas->nCPE > 1 ) + IF( st_ivas->nCPE > 1 ) { - IF ( ( error = create_mct_dec( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = create_mct_dec( st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -1967,33 +1974,34 @@ ivas_error ivas_init_decoder_fx( /* set CNA/CNG flags */ ivas_sba_set_cna_cng_flag( st_ivas ); } - ELSE IF ( st_ivas->ivas_format == MASA_FORMAT ) + ELSE IF( st_ivas->ivas_format == MASA_FORMAT ) { /* if we start in ISM_MODE_NONE in MASA_ISM, that appears as normal MASA, but we may change to a mode with ISMs */ st_ivas->ism_extmeta_active = -1; st_ivas->ism_extmeta_cnt = 0; - move16(); move16(); - IF ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) + move16(); + move16(); + IF( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) { return error; } - IF ( ( error = ivas_masa_dec_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_masa_dec_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } - IF ( st_ivas->renderer_type == RENDERER_DIRAC || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) + IF( st_ivas->renderer_type == RENDERER_DIRAC || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) { - IF ( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK ) { return error; } } - FOR ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { - IF ( ( error = create_sce_dec( st_ivas, sce_id, ivas_total_brate / st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) + IF( ( error = create_sce_dec( st_ivas, sce_id, ivas_total_brate / st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) { return error; } @@ -2001,14 +2009,14 @@ ivas_error ivas_init_decoder_fx( reset_indices_dec( st_ivas->hSCE[sce_id]->hCoreCoder[0] ); } - FOR ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - IF ( ( error = create_cpe_dec( st_ivas, cpe_id, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) + IF( ( error = create_cpe_dec( st_ivas, cpe_id, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) { return error; } - FOR ( n = 0; n < CPE_CHANNELS; n++ ) + FOR( n = 0; n < CPE_CHANNELS; n++ ) { reset_indices_dec( st_ivas->hCPE[cpe_id]->hCoreCoder[n] ); } @@ -2017,7 +2025,7 @@ ivas_error ivas_init_decoder_fx( /* set CNA/CNG flags */ ivas_sba_set_cna_cng_flag( st_ivas ); } - ELSE IF ( st_ivas->ivas_format == SBA_ISM_FORMAT ) + ELSE IF( st_ivas->ivas_format == SBA_ISM_FORMAT ) { Word32 temp_brate[MAX_SCE]; st_ivas->ism_extmeta_active = -1; @@ -2027,32 +2035,32 @@ ivas_error ivas_init_decoder_fx( st_ivas->sba_dirac_stereo_flag = ivas_get_sba_dirac_stereo_flag( st_ivas ); - IF ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) { return error; } - IF ( ( error = ivas_spar_dec_open_fx( st_ivas, 0 ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_spar_dec_open_fx( st_ivas, 0 ) ) != IVAS_ERR_OK ) { return error; } - IF ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_DEC && st_ivas->hOutSetup.is_loudspeaker_setup ) + IF( st_ivas->renderer_type == RENDERER_SBA_LINEAR_DEC && st_ivas->hOutSetup.is_loudspeaker_setup ) { - IF ( ( error = ivas_sba_get_hoa_dec_matrix_fx( st_ivas->hOutSetup, &st_ivas->hoa_dec_mtx, st_ivas->hIntSetup.ambisonics_order ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_sba_get_hoa_dec_matrix_fx( st_ivas->hOutSetup, &st_ivas->hoa_dec_mtx, st_ivas->hIntSetup.ambisonics_order ) ) != IVAS_ERR_OK ) { return error; } } - IF ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) ? IVAS_MAX_NUM_BANDS : ( IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ), st_ivas->ivas_format ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) ? IVAS_MAX_NUM_BANDS : ( IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ), st_ivas->ivas_format ) ) != IVAS_ERR_OK ) { return error; } - IF ( hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_FOA && st_ivas->hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_STEREO && st_ivas->hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_MONO ) + IF( hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_FOA && st_ivas->hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_STEREO && st_ivas->hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_MONO ) { - IF ( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK ) { return error; } @@ -2064,7 +2072,7 @@ ivas_error ivas_init_decoder_fx( Word16 band_grouping[IVAS_MAX_NUM_BANDS + 1]; st_ivas->hSpar->enc_param_start_band = min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND ); - IF ( ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) ) + IF( ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) ) { st_ivas->hSpar->enc_param_start_band = 0; @@ -2076,9 +2084,9 @@ ivas_error ivas_init_decoder_fx( st_ivas->hSpar->dirac_to_spar_md_bands, st_ivas->hQMetaData->useLowerBandRes, st_ivas->hSpar->enc_param_start_band, 0 ); } - FOR ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { - IF ( ( error = create_sce_dec( st_ivas, sce_id, ivas_total_brate / st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) + IF( ( error = create_sce_dec( st_ivas, sce_id, ivas_total_brate / st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) { return error; } @@ -2086,29 +2094,29 @@ ivas_error ivas_init_decoder_fx( reset_indices_dec( st_ivas->hSCE[sce_id]->hCoreCoder[0] ); } - IF ( st_ivas->ism_mode == ISM_SBA_MODE_DISC ) + IF( st_ivas->ism_mode == ISM_SBA_MODE_DISC ) { st_ivas->nCPE += ( st_ivas->nchan_ism + 1 ) >> 1; st_ivas->element_mode_init = IVAS_CPE_MDCT; } - FOR ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - IF ( ( error = create_cpe_dec( st_ivas, cpe_id, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) + IF( ( error = create_cpe_dec( st_ivas, cpe_id, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) { return error; } - FOR ( n = 0; n < CPE_CHANNELS; n++ ) + FOR( n = 0; n < CPE_CHANNELS; n++ ) { reset_indices_dec( st_ivas->hCPE[cpe_id]->hCoreCoder[n] ); } } /* create CPE element for DFT Stereo like upmix */ - IF ( st_ivas->sba_dirac_stereo_flag && st_ivas->nCPE == 0 ) + IF( st_ivas->sba_dirac_stereo_flag && st_ivas->nCPE == 0 ) { - IF ( ( error = create_cpe_dec( st_ivas, cpe_id, ivas_total_brate / ( st_ivas->nSCE + st_ivas->nCPE ) ) ) != IVAS_ERR_OK ) + IF( ( error = create_cpe_dec( st_ivas, cpe_id, ivas_total_brate / ( st_ivas->nSCE + st_ivas->nCPE ) ) ) != IVAS_ERR_OK ) { return error; } @@ -2117,22 +2125,22 @@ ivas_error ivas_init_decoder_fx( st_ivas->hCPE[0]->hCoreCoder[1] = NULL; } - IF ( st_ivas->nCPE > 1 ) + IF( st_ivas->nCPE > 1 ) { - IF ( ( error = create_mct_dec( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = create_mct_dec( st_ivas ) ) != IVAS_ERR_OK ) { return error; } } - IF ( st_ivas->ism_mode == ISM_SBA_MODE_DISC ) + IF( st_ivas->ism_mode == ISM_SBA_MODE_DISC ) { - IF ( ( error = ivas_ism_metadata_dec_create_fx( st_ivas, st_ivas->nchan_ism, temp_brate ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_ism_metadata_dec_create_fx( st_ivas, st_ivas->nchan_ism, temp_brate ) ) != IVAS_ERR_OK ) { return error; } - IF ( ( error = ivas_osba_data_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_osba_data_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -2141,52 +2149,52 @@ ivas_error ivas_init_decoder_fx( /* set CNA/CNG flags */ ivas_sba_set_cna_cng_flag( st_ivas ); } - ELSE IF ( st_ivas->ivas_format == MASA_ISM_FORMAT ) + ELSE IF( st_ivas->ivas_format == MASA_ISM_FORMAT ) { st_ivas->ism_extmeta_active = -1; st_ivas->ism_extmeta_cnt = 0; - IF ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) { return error; } k = 0; ism_total_brate = 0; - WHILE ( LT_16(k, SIZE_IVAS_BRATE_TBL) && NE_32(ivas_total_brate, ivas_brate_tbl[k] )) + WHILE( LT_16( k, SIZE_IVAS_BRATE_TBL ) && NE_32( ivas_total_brate, ivas_brate_tbl[k] ) ) { k++; } - IF ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) + IF( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) { /* one separated object */ st_ivas->nSCE = 1; ism_total_brate = sep_object_brate[k - 2][0]; - IF ( ( error = create_sce_dec( st_ivas, 0, ism_total_brate ) ) != IVAS_ERR_OK ) + IF( ( error = create_sce_dec( st_ivas, 0, ism_total_brate ) ) != IVAS_ERR_OK ) { return error; } reset_indices_dec( st_ivas->hSCE[0]->hCoreCoder[0] ); - IF ( ( error = ivas_ism_metadata_dec_create_fx( st_ivas, 1, NULL ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_ism_metadata_dec_create_fx( st_ivas, 1, NULL ) ) != IVAS_ERR_OK ) { return error; } } - ELSE IF ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + ELSE IF( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { Word32 temp_brate[MAX_SCE]; st_ivas->nSCE = st_ivas->nchan_ism; /* number of objects */ - FOR ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { temp_brate[sce_id] = sep_object_brate[k - 2][st_ivas->nSCE - 1]; ism_total_brate += temp_brate[sce_id]; - IF ( ( error = create_sce_dec( st_ivas, sce_id, temp_brate[sce_id] ) ) != IVAS_ERR_OK ) + IF( ( error = create_sce_dec( st_ivas, sce_id, temp_brate[sce_id] ) ) != IVAS_ERR_OK ) { return error; } @@ -2194,52 +2202,52 @@ ivas_error ivas_init_decoder_fx( reset_indices_dec( st_ivas->hSCE[sce_id]->hCoreCoder[0] ); } - IF ( ( error = ivas_ism_metadata_dec_create_fx( st_ivas, st_ivas->nchan_ism, temp_brate ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_ism_metadata_dec_create_fx( st_ivas, st_ivas->nchan_ism, temp_brate ) ) != IVAS_ERR_OK ) { return error; } } - IF ( ( error = ivas_masa_dec_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_masa_dec_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } - IF ( ( error = ivas_omasa_data_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_omasa_data_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } - IF ( st_ivas->renderer_type == RENDERER_DIRAC || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) + IF( st_ivas->renderer_type == RENDERER_DIRAC || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) { - IF ( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK ) { return error; } } - IF ( ( error = create_cpe_dec( st_ivas, 0, ivas_total_brate - ism_total_brate ) ) != IVAS_ERR_OK ) + IF( ( error = create_cpe_dec( st_ivas, 0, ivas_total_brate - ism_total_brate ) ) != IVAS_ERR_OK ) { return error; } - FOR ( n = 0; n < CPE_CHANNELS; n++ ) + FOR( n = 0; n < CPE_CHANNELS; n++ ) { reset_indices_dec( st_ivas->hCPE[0]->hCoreCoder[n] ); } } - ELSE IF ( st_ivas->ivas_format == MC_FORMAT ) + ELSE IF( st_ivas->ivas_format == MC_FORMAT ) { - IF ( st_ivas->mc_mode == MC_MODE_MCT ) + IF( st_ivas->mc_mode == MC_MODE_MCT ) { /* init EFAP for custom LS setup */ - IF ( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM ) + IF( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM ) { /*float2fix block: to be removed*/ - floatToFixed_arrL(st_ivas->hLsSetupCustom->ls_azimuth, st_ivas->hLsSetupCustom->ls_azimuth_fx, Q22, st_ivas->hLsSetupCustom->num_spk); - floatToFixed_arrL(st_ivas->hLsSetupCustom->ls_elevation, st_ivas->hLsSetupCustom->ls_elevation_fx, Q22, st_ivas->hLsSetupCustom->num_spk); + floatToFixed_arrL( st_ivas->hLsSetupCustom->ls_azimuth, st_ivas->hLsSetupCustom->ls_azimuth_fx, Q22, st_ivas->hLsSetupCustom->num_spk ); + floatToFixed_arrL( st_ivas->hLsSetupCustom->ls_elevation, st_ivas->hLsSetupCustom->ls_elevation_fx, Q22, st_ivas->hLsSetupCustom->num_spk ); /*float2fix block end*/ - IF ( ( error = efap_init_data_fx( &( st_ivas->hEFAPdata ), st_ivas->hLsSetupCustom->ls_azimuth_fx, st_ivas->hLsSetupCustom->ls_elevation_fx, st_ivas->hLsSetupCustom->num_spk, EFAP_MODE_EFAP ) ) != IVAS_ERR_OK ) + IF( ( error = efap_init_data_fx( &( st_ivas->hEFAPdata ), st_ivas->hLsSetupCustom->ls_azimuth_fx, st_ivas->hLsSetupCustom->ls_elevation_fx, st_ivas->hLsSetupCustom->num_spk, EFAP_MODE_EFAP ) ) != IVAS_ERR_OK ) { return error; } @@ -2251,34 +2259,34 @@ ivas_error ivas_init_decoder_fx( st_ivas->element_mode_init = IVAS_CPE_MDCT; - FOR ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - IF ( ( error = create_cpe_dec( st_ivas, cpe_id, ( ivas_total_brate / ( st_ivas->nchan_transport - 1 ) * CPE_CHANNELS ) ) ) != IVAS_ERR_OK ) + IF( ( error = create_cpe_dec( st_ivas, cpe_id, ( ivas_total_brate / ( st_ivas->nchan_transport - 1 ) * CPE_CHANNELS ) ) ) != IVAS_ERR_OK ) { return error; } - FOR ( n = 0; n < CPE_CHANNELS; n++ ) + FOR( n = 0; n < CPE_CHANNELS; n++ ) { reset_indices_dec( st_ivas->hCPE[cpe_id]->hCoreCoder[n] ); } } - IF ( ( error = create_mct_dec_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = create_mct_dec_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } } - ELSE IF ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) + ELSE IF( st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) { /* init EFAP for custom LS setup */ - IF ( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM ) + IF( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM ) { /*float2fix block: to be removed*/ - floatToFixed_arrL(st_ivas->hLsSetupCustom->ls_azimuth, st_ivas->hLsSetupCustom->ls_azimuth_fx, Q22, st_ivas->hLsSetupCustom->num_spk); - floatToFixed_arrL(st_ivas->hLsSetupCustom->ls_elevation, st_ivas->hLsSetupCustom->ls_elevation_fx, Q22, st_ivas->hLsSetupCustom->num_spk); + floatToFixed_arrL( st_ivas->hLsSetupCustom->ls_azimuth, st_ivas->hLsSetupCustom->ls_azimuth_fx, Q22, st_ivas->hLsSetupCustom->num_spk ); + floatToFixed_arrL( st_ivas->hLsSetupCustom->ls_elevation, st_ivas->hLsSetupCustom->ls_elevation_fx, Q22, st_ivas->hLsSetupCustom->num_spk ); /*float2fix block end*/ - IF ( ( error = efap_init_data_fx( &( st_ivas->hEFAPdata ), st_ivas->hLsSetupCustom->ls_azimuth_fx, st_ivas->hLsSetupCustom->ls_elevation_fx, st_ivas->hLsSetupCustom->num_spk, EFAP_MODE_EFAP ) ) != IVAS_ERR_OK ) + IF( ( error = efap_init_data_fx( &( st_ivas->hEFAPdata ), st_ivas->hLsSetupCustom->ls_azimuth_fx, st_ivas->hLsSetupCustom->ls_elevation_fx, st_ivas->hLsSetupCustom->num_spk, EFAP_MODE_EFAP ) ) != IVAS_ERR_OK ) { return error; } @@ -2287,38 +2295,40 @@ ivas_error ivas_init_decoder_fx( st_ivas->nSCE = 0; st_ivas->nCPE = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS / CPE_CHANNELS; st_ivas->nchan_transport = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS; - move16(); move16(); move16(); - IF ( ( error = ivas_mc_paramupmix_dec_open( st_ivas ) ) != IVAS_ERR_OK ) + move16(); + move16(); + move16(); + IF( ( error = ivas_mc_paramupmix_dec_open( st_ivas ) ) != IVAS_ERR_OK ) { return error; } st_ivas->element_mode_init = IVAS_CPE_MDCT; move16(); - FOR ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - IF ( ( error = create_cpe_dec( st_ivas, cpe_id, ( ivas_total_brate / ( st_ivas->nchan_transport - 1 ) * CPE_CHANNELS ) ) ) != IVAS_ERR_OK ) + IF( ( error = create_cpe_dec( st_ivas, cpe_id, ( ivas_total_brate / ( st_ivas->nchan_transport - 1 ) * CPE_CHANNELS ) ) ) != IVAS_ERR_OK ) { return error; } - FOR ( n = 0; n < CPE_CHANNELS; n++ ) + FOR( n = 0; n < CPE_CHANNELS; n++ ) { reset_indices_dec( st_ivas->hCPE[cpe_id]->hCoreCoder[n] ); } } - IF ( ( error = create_mct_dec_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = create_mct_dec_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } } - ELSE IF ( st_ivas->mc_mode == MC_MODE_PARAMMC ) + ELSE IF( st_ivas->mc_mode == MC_MODE_PARAMMC ) { /* init EFAP for custom LS setup */ - IF ( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM ) + IF( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM ) { - IF ( ( error = efap_init_data_fx( &( st_ivas->hEFAPdata ), st_ivas->hLsSetupCustom->ls_azimuth_fx, st_ivas->hLsSetupCustom->ls_elevation_fx, st_ivas->hLsSetupCustom->num_spk, EFAP_MODE_EFAP ) ) != IVAS_ERR_OK ) + IF( ( error = efap_init_data_fx( &( st_ivas->hEFAPdata ), st_ivas->hLsSetupCustom->ls_azimuth_fx, st_ivas->hLsSetupCustom->ls_elevation_fx, st_ivas->hLsSetupCustom->num_spk, EFAP_MODE_EFAP ) ) != IVAS_ERR_OK ) { return error; } @@ -2330,39 +2340,39 @@ ivas_error ivas_init_decoder_fx( st_ivas->hParamMC->proto_matrix_int_e = 0; move16(); - FOR ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - IF ( ( error = create_cpe_dec( st_ivas, cpe_id, ivas_total_brate / ( st_ivas->nSCE + st_ivas->nCPE ) ) ) != IVAS_ERR_OK ) + IF( ( error = create_cpe_dec( st_ivas, cpe_id, ivas_total_brate / ( st_ivas->nSCE + st_ivas->nCPE ) ) ) != IVAS_ERR_OK ) { return error; } - FOR ( n = 0; n < CPE_CHANNELS; n++ ) + FOR( n = 0; n < CPE_CHANNELS; n++ ) { reset_indices_dec( st_ivas->hCPE[cpe_id]->hCoreCoder[n] ); } } - IF ( GT_16(st_ivas->nCPE, 1 )) + IF( GT_16( st_ivas->nCPE, 1 ) ) { - IF ( ( error = create_mct_dec_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = create_mct_dec_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } } } - ELSE IF ( st_ivas->mc_mode == MC_MODE_MCMASA ) + ELSE IF( st_ivas->mc_mode == MC_MODE_MCMASA ) { Word32 brate_sce, brate_cpe; ivas_mcmasa_setNumTransportChannels_fx( &( st_ivas->nchan_transport ), &( st_ivas->element_mode_init ), ivas_total_brate ); - IF ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) { return error; } - IF ( ( error = ivas_masa_dec_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_masa_dec_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; @@ -2370,37 +2380,37 @@ ivas_error ivas_init_decoder_fx( st_ivas->sba_dirac_stereo_flag = ivas_get_sba_dirac_stereo_flag( st_ivas ); - IF ( st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_MCMASA_MONO_STEREO ) + IF( st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_MCMASA_MONO_STEREO ) { - IF ( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK ) { return error; } } - IF ( st_ivas->hOutSetup.output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM && st_ivas->hOutSetup.separateChannelEnabled && !st_ivas->hLsSetupCustom->separate_ch_found ) + IF( st_ivas->hOutSetup.output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM && st_ivas->hOutSetup.separateChannelEnabled && !st_ivas->hLsSetupCustom->separate_ch_found ) { /* If no speaker matching the separated channel, compute panning gains for the separated channel. */ - IF ( st_ivas->hVBAPdata == NULL ) + IF( st_ivas->hVBAPdata == NULL ) { /* Distribute signal to all channels if VBAP is not properly initialized. */ Word16 inv_sqr, sqr, exp = 15, exp_sqr; - IF(EQ_16(st_ivas->hLsSetupCustom->num_spk, 1)) + IF( EQ_16( st_ivas->hLsSetupCustom->num_spk, 1 ) ) { - inv_sqr = 32767; + inv_sqr = 32767; } ELSE { - sqr = Sqrt16(st_ivas->hLsSetupCustom->num_spk, &exp); - inv_sqr = BASOP_Util_Divide1616_Scale(32767, sqr, &exp_sqr); - exp_sqr = sub(exp_sqr, exp); - IF(LT_16(exp, 0)) + sqr = Sqrt16( st_ivas->hLsSetupCustom->num_spk, &exp ); + inv_sqr = BASOP_Util_Divide1616_Scale( 32767, sqr, &exp_sqr ); + exp_sqr = sub( exp_sqr, exp ); + IF( LT_16( exp, 0 ) ) { - inv_sqr = shr(inv_sqr, exp); + inv_sqr = shr( inv_sqr, exp ); } ELSE { - inv_sqr = shl(inv_sqr, exp); + inv_sqr = shl( inv_sqr, exp ); } } set16_fx( st_ivas->hLsSetupCustom->separate_ch_gains_fx, inv_sqr, st_ivas->hLsSetupCustom->num_spk ); @@ -2410,9 +2420,9 @@ ivas_error ivas_init_decoder_fx( ivas_mcmasa_split_brate_fx( st_ivas->hOutSetup.separateChannelEnabled, ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &brate_sce, &brate_cpe ); - FOR ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { - IF ( ( error = create_sce_dec( st_ivas, sce_id, brate_sce ) ) != IVAS_ERR_OK ) + IF( ( error = create_sce_dec( st_ivas, sce_id, brate_sce ) ) != IVAS_ERR_OK ) { return error; } @@ -2420,25 +2430,25 @@ ivas_error ivas_init_decoder_fx( reset_indices_dec( st_ivas->hSCE[sce_id]->hCoreCoder[0] ); } - FOR ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { st_ivas->element_mode_init = IVAS_CPE_MDCT; /* element_mode_init was IVAS_SCE for SCE initialization */ - IF ( ( error = create_cpe_dec( st_ivas, cpe_id, brate_cpe ) ) != IVAS_ERR_OK ) + IF( ( error = create_cpe_dec( st_ivas, cpe_id, brate_cpe ) ) != IVAS_ERR_OK ) { return error; } - FOR ( n = 0; n < CPE_CHANNELS; n++ ) + FOR( n = 0; n < CPE_CHANNELS; n++ ) { reset_indices_dec( st_ivas->hCPE[cpe_id]->hCoreCoder[n] ); } } /* create CPE element for DFT Stereo like upmix */ - IF ( st_ivas->sba_dirac_stereo_flag ) + IF( st_ivas->sba_dirac_stereo_flag ) { - IF ( ( error = create_cpe_dec( st_ivas, cpe_id, ivas_total_brate / ( st_ivas->nSCE + st_ivas->nCPE ) ) ) != IVAS_ERR_OK ) + IF( ( error = create_cpe_dec( st_ivas, cpe_id, ivas_total_brate / ( st_ivas->nSCE + st_ivas->nCPE ) ) ) != IVAS_ERR_OK ) { return error; } @@ -2448,7 +2458,7 @@ ivas_error ivas_init_decoder_fx( } /* set CNA/CNG flags */ - IF ( EQ_16(st_ivas->nchan_transport, 1) && ( ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) ) + IF( EQ_16( st_ivas->nchan_transport, 1 ) && ( ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) ) { st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag = 1; st_ivas->hSCE[0]->hCoreCoder[0]->cng_sba_flag = 1; @@ -2464,9 +2474,9 @@ ivas_error ivas_init_decoder_fx( /* set number of output channels used for synthesis/decoding */ n = getNumChanSynthesis( st_ivas ); - IF ( GT_16(n, 0 )) + IF( GT_16( n, 0 ) ) { - IF( ( st_ivas->mem_hp20_out_fx = (Word32 **) malloc( n * sizeof(Word32 * ) ) ) == NULL ) + IF( ( st_ivas->mem_hp20_out_fx = (Word32 **) malloc( n * sizeof( Word32 * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); } @@ -2476,84 +2486,84 @@ ivas_error ivas_init_decoder_fx( st_ivas->mem_hp20_out_fx = NULL; } - FOR ( i = 0; i < n; i++ ) + FOR( i = 0; i < n; i++ ) { - IF((st_ivas->mem_hp20_out_fx[i] = (Word32 *)malloc((L_HP20_MEM + 2) * sizeof(Word32))) == NULL) + IF( ( st_ivas->mem_hp20_out_fx[i] = (Word32 *) malloc( ( L_HP20_MEM + 2 ) * sizeof( Word32 ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); } - set32_fx(st_ivas->mem_hp20_out_fx[i], 0, L_HP20_MEM + 2); + set32_fx( st_ivas->mem_hp20_out_fx[i], 0, L_HP20_MEM + 2 ); } /*-------------------------------------------------------------------* * Allocate and initialize rendering handles *--------------------------------------------------------------------*/ - IF ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) + IF( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) { - IF ( ( error = ivas_binRenderer_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_binRenderer_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } } /* ParamISM is handled separately from other common config */ - ELSE IF ( st_ivas->ivas_format == ISM_FORMAT && st_ivas->ism_mode == ISM_MODE_PARAM && ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) ) + ELSE IF( st_ivas->ivas_format == ISM_FORMAT && st_ivas->ism_mode == ISM_MODE_PARAM && ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) ) { - IF ( st_ivas->renderer_type != RENDERER_STEREO_PARAMETRIC ) + IF( st_ivas->renderer_type != RENDERER_STEREO_PARAMETRIC ) { - IF ( ( error = ivas_dirac_dec_binaural_copy_hrtfs( &st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_dirac_dec_binaural_copy_hrtfs( &st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) { return error; } } - IF ( ( error = ivas_dirac_dec_init_binaural_data_fx( st_ivas, st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_dirac_dec_init_binaural_data_fx( st_ivas, st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) { return error; } } - ELSE IF ( st_ivas->renderer_type == RENDERER_BINAURAL_OBJECTS_TD ) + ELSE IF( st_ivas->renderer_type == RENDERER_BINAURAL_OBJECTS_TD ) { - Word16 SrcInd[MAX_NUM_TDREND_CHANNELS]; - Word16 num_src; - IF( ( error = ivas_td_binaural_open_fx( st_ivas, SrcInd, &num_src ) ) != IVAS_ERR_OK ) - { - return error; - } - Word16 nchan_rend = num_src; - IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) && NE_16( st_ivas->transport_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) - { - nchan_rend--; /* Skip LFE channel -- added to the others */ - } - FOR( Word16 nS = 0; nS < nchan_rend; nS++ ) - { - TDREND_SRC_t *Src_p = st_ivas->hBinRendererTd->Sources[SrcInd[nS]]; - IF( Src_p->SrcSpatial_p != NULL ) - { - Src_p->SrcSpatial_p->q_Pos_p = Q31; - } - TDREND_SRC_SPATIAL_t *SrcSpatial_p = st_ivas->hBinRendererTd->Sources[nS]->SrcSpatial_p; - SrcSpatial_p->q_Pos_p = Q31; - } + Word16 SrcInd[MAX_NUM_TDREND_CHANNELS]; + Word16 num_src; + IF( ( error = ivas_td_binaural_open_fx( st_ivas, SrcInd, &num_src ) ) != IVAS_ERR_OK ) + { + return error; + } + Word16 nchan_rend = num_src; + IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) && NE_16( st_ivas->transport_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) + { + nchan_rend--; /* Skip LFE channel -- added to the others */ + } + FOR( Word16 nS = 0; nS < nchan_rend; nS++ ) + { + TDREND_SRC_t *Src_p = st_ivas->hBinRendererTd->Sources[SrcInd[nS]]; + IF( Src_p->SrcSpatial_p != NULL ) + { + Src_p->SrcSpatial_p->q_Pos_p = Q31; + } + TDREND_SRC_SPATIAL_t *SrcSpatial_p = st_ivas->hBinRendererTd->Sources[nS]->SrcSpatial_p; + SrcSpatial_p->q_Pos_p = Q31; + } - IF ( EQ_32( st_ivas->hIntSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) + IF( EQ_32( st_ivas->hIntSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { - IF ( ( error = ivas_reverb_open_fx( &st_ivas->hReverb, st_ivas->hDecoderConfig->output_config, NULL, st_ivas->hBinRendererTd->HrFiltSet_p->lr_energy_and_iac_fx, st_ivas->hRenderConfig, st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_reverb_open_fx( &st_ivas->hReverb, st_ivas->hDecoderConfig->output_config, NULL, st_ivas->hBinRendererTd->HrFiltSet_p->lr_energy_and_iac_fx, st_ivas->hRenderConfig, st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) { return error; } } - granularity = NS2SA( st_ivas->hDecoderConfig->output_Fs, FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ); + granularity = NS2SA( st_ivas->hDecoderConfig->output_Fs, FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ); - n_channels_transport_jbm = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas ); + n_channels_transport_jbm = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas ); - IF ( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_RENDERER, n_channels_transport_jbm, n_channels_transport_jbm, n_channels_transport_jbm, granularity ) ) != IVAS_ERR_OK ) - { - return error; - } + IF( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_RENDERER, n_channels_transport_jbm, n_channels_transport_jbm, n_channels_transport_jbm, granularity ) ) != IVAS_ERR_OK ) + { + return error; + } } ELSE IF( st_ivas->renderer_type == RENDERER_MC ) { @@ -2562,76 +2572,76 @@ ivas_error ivas_init_decoder_fx( return error; } } - ELSE IF ( st_ivas->renderer_type == RENDERER_MONO_DOWNMIX ) + ELSE IF( st_ivas->renderer_type == RENDERER_MONO_DOWNMIX ) { - IF ( ( error = ivas_mono_dmx_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_mono_dmx_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) { return error; } } - ELSE IF ( st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV || st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM ) + ELSE IF( st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV || st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM ) { - IF ( st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM && st_ivas->ivas_format == MC_FORMAT && ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) ) + IF( st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM && st_ivas->ivas_format == MC_FORMAT && ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) ) { - IF ( ( error = efap_init_data_fx( &( st_ivas->hEFAPdata ), st_ivas->hIntSetup.ls_azimuth_fx, st_ivas->hIntSetup.ls_elevation_fx, st_ivas->hIntSetup.nchan_out_woLFE, EFAP_MODE_EFAP ) ) != IVAS_ERR_OK ) + IF( ( error = efap_init_data_fx( &( st_ivas->hEFAPdata ), st_ivas->hIntSetup.ls_azimuth_fx, st_ivas->hIntSetup.ls_elevation_fx, st_ivas->hIntSetup.nchan_out_woLFE, EFAP_MODE_EFAP ) ) != IVAS_ERR_OK ) { return error; } } - IF ( ( error = ivas_rend_openCrend( &( st_ivas->hCrendWrapper ), st_ivas->intern_config, st_ivas->hDecoderConfig->output_config, - st_ivas->hRenderConfig, st_ivas->hSetOfHRTF, st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_rend_openCrend( &( st_ivas->hCrendWrapper ), st_ivas->intern_config, st_ivas->hDecoderConfig->output_config, + st_ivas->hRenderConfig, st_ivas->hSetOfHRTF, st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) { return error; } st_ivas->binaural_latency_ns = st_ivas->hCrendWrapper->binaural_latency_ns; - IF ( ( st_ivas->ivas_format == MC_FORMAT ) && ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) ) - { - granularity = NS2SA( output_Fs, CLDFB_SLOT_NS ); + IF( ( st_ivas->ivas_format == MC_FORMAT ) && ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) ) + { + granularity = NS2SA( output_Fs, CLDFB_SLOT_NS ); - n_channels_transport_jbm = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas ); + n_channels_transport_jbm = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas ); - IF ( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_RENDERER, n_channels_transport_jbm, MC_PARAMUPMIX_MAX_INPUT_CHANS, MC_PARAMUPMIX_MAX_INPUT_CHANS, granularity ) ) != IVAS_ERR_OK ) - { - return error; - } - } - ELSE + IF( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_RENDERER, n_channels_transport_jbm, MC_PARAMUPMIX_MAX_INPUT_CHANS, MC_PARAMUPMIX_MAX_INPUT_CHANS, granularity ) ) != IVAS_ERR_OK ) { - granularity = NS2SA( st_ivas->hDecoderConfig->output_Fs, FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ); + return error; + } + } + ELSE + { + granularity = NS2SA( st_ivas->hDecoderConfig->output_Fs, FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ); - n_channels_transport_jbm = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas ); + n_channels_transport_jbm = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas ); - IF ( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_RENDERER, n_channels_transport_jbm, n_channels_transport_jbm, n_channels_transport_jbm, granularity ) ) != IVAS_ERR_OK ) - { - return error; - } + IF( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_RENDERER, n_channels_transport_jbm, n_channels_transport_jbm, n_channels_transport_jbm, granularity ) ) != IVAS_ERR_OK ) + { + return error; } + } } - IF ( st_ivas->ivas_format == MASA_ISM_FORMAT ) + IF( st_ivas->ivas_format == MASA_ISM_FORMAT ) { - IF ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC && st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + IF( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC && st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { /* Allocate TD renderer for the objects in DISC mode */ Word16 SrcInd[MAX_NUM_TDREND_CHANNELS]; Word16 num_src; - IF((error = ivas_td_binaural_open_fx(st_ivas, SrcInd, &num_src)) != IVAS_ERR_OK) + IF( ( error = ivas_td_binaural_open_fx( st_ivas, SrcInd, &num_src ) ) != IVAS_ERR_OK ) { return error; } Word16 nchan_rend = num_src; - IF(EQ_16(st_ivas->ivas_format, MC_FORMAT) && NE_16(st_ivas->transport_config, IVAS_AUDIO_CONFIG_LS_CUSTOM)) + IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) && NE_16( st_ivas->transport_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) { nchan_rend--; /* Skip LFE channel -- added to the others */ } - FOR(Word16 nS = 0; nS < nchan_rend; nS++) + FOR( Word16 nS = 0; nS < nchan_rend; nS++ ) { TDREND_SRC_t *Src_p = st_ivas->hBinRendererTd->Sources[SrcInd[nS]]; - IF(Src_p->SrcSpatial_p != NULL) + IF( Src_p->SrcSpatial_p != NULL ) { Src_p->SrcSpatial_p->q_Pos_p = Q31; } @@ -2640,60 +2650,60 @@ ivas_error ivas_init_decoder_fx( } /* Allocate 'hIsmRendererData' handle and memory for delay buffer within 'hMasaIsmData' */ - IF ( ( error = ivas_omasa_separate_object_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_omasa_separate_object_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) { return error; } } - IF ( st_ivas->renderer_type == RENDERER_DIRAC && ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) + IF( st_ivas->renderer_type == RENDERER_DIRAC && ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) { /* Allocate 'hIsmRendererData' handle and memory for delay buffer within 'hMasaIsmData' */ - IF ( ( error = ivas_omasa_separate_object_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_omasa_separate_object_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) { return error; } } } - IF ( ( st_ivas->ivas_format == ISM_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT ) && - ( st_ivas->ism_mode == ISM_MODE_DISC || st_ivas->ism_mode == ISM_SBA_MODE_DISC ) && - ( st_ivas->renderer_type == RENDERER_TD_PANNING || - st_ivas->renderer_type == RENDERER_NON_DIEGETIC_DOWNMIX || - st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC || - st_ivas->renderer_type == RENDERER_OSBA_STEREO || - st_ivas->renderer_type == RENDERER_OSBA_AMBI || - st_ivas->renderer_type == RENDERER_OSBA_LS || - st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || - st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM || - st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM ) ) + IF( ( st_ivas->ivas_format == ISM_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT ) && + ( st_ivas->ism_mode == ISM_MODE_DISC || st_ivas->ism_mode == ISM_SBA_MODE_DISC ) && + ( st_ivas->renderer_type == RENDERER_TD_PANNING || + st_ivas->renderer_type == RENDERER_NON_DIEGETIC_DOWNMIX || + st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC || + st_ivas->renderer_type == RENDERER_OSBA_STEREO || + st_ivas->renderer_type == RENDERER_OSBA_AMBI || + st_ivas->renderer_type == RENDERER_OSBA_LS || + st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || + st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM || + st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM ) ) { - IF ( ( error = ivas_ism_renderer_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_ism_renderer_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } } - IF ( st_ivas->ivas_format == SBA_ISM_FORMAT ) + IF( st_ivas->ivas_format == SBA_ISM_FORMAT ) { - IF ( ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV ) && st_ivas->ism_mode == ISM_SBA_MODE_DISC ) + IF( ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV ) && st_ivas->ism_mode == ISM_SBA_MODE_DISC ) { /* Allocate TD renderer for the objects in DISC mode */ Word16 SrcInd[MAX_NUM_TDREND_CHANNELS]; Word16 num_src; - IF((error = ivas_td_binaural_open_fx(st_ivas, SrcInd, &num_src)) != IVAS_ERR_OK) + IF( ( error = ivas_td_binaural_open_fx( st_ivas, SrcInd, &num_src ) ) != IVAS_ERR_OK ) { return error; } Word16 nchan_rend = num_src; - IF(EQ_16(st_ivas->ivas_format, MC_FORMAT) && NE_16(st_ivas->transport_config, IVAS_AUDIO_CONFIG_LS_CUSTOM)) + IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) && NE_16( st_ivas->transport_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) { nchan_rend--; /* Skip LFE channel -- added to the others */ } - FOR(Word16 nS = 0; nS < nchan_rend; nS++) + FOR( Word16 nS = 0; nS < nchan_rend; nS++ ) { TDREND_SRC_t *Src_p = st_ivas->hBinRendererTd->Sources[SrcInd[nS]]; - IF(Src_p->SrcSpatial_p != NULL) + IF( Src_p->SrcSpatial_p != NULL ) { Src_p->SrcSpatial_p->q_Pos_p = Q31; } @@ -2707,12 +2717,12 @@ ivas_error ivas_init_decoder_fx( * LFE handles for rendering after rendering to adjust LFE delay to binaural filter delay *-----------------------------------------------------------------*/ - IF ( st_ivas->mc_mode == MC_MODE_MCT || st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) + IF( st_ivas->mc_mode == MC_MODE_MCT || st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) { binauralization_delay_ns = st_ivas->binaural_latency_ns; - IF ( st_ivas->hBinRenderer != NULL ) + IF( st_ivas->hBinRenderer != NULL ) { - IF ( st_ivas->hBinRenderer->render_lfe ) + IF( st_ivas->hBinRenderer->render_lfe ) { { /* Account for filterbank delay */ @@ -2733,7 +2743,6 @@ ivas_error ivas_init_decoder_fx( set32_fx( st_ivas->hLFE->prevsynth_buf_fx, 0, LFE_PLC_BUFLEN ); set32_fx( st_ivas->hLFE->prior_out_buffer_fx, 0, L_FRAME48k ); - } /*-----------------------------------------------------------------* @@ -2742,32 +2751,32 @@ ivas_error ivas_init_decoder_fx( ivas_init_dec_get_num_cldfb_instances_ivas_fx( st_ivas, &numCldfbAnalyses, &numCldfbSyntheses ); - FOR ( i = 0; i < numCldfbAnalyses; i++ ) + FOR( i = 0; i < numCldfbAnalyses; i++ ) { - IF ( ( error = openCldfb_ivas( &( st_ivas->cldfbAnaDec[i] ), CLDFB_ANALYSIS, output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) + IF( ( error = openCldfb_ivas( &( st_ivas->cldfbAnaDec[i] ), CLDFB_ANALYSIS, output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) { return error; } } - FOR ( ; i < MAX_INTERN_CHANNELS; i++ ) + FOR( ; i < MAX_INTERN_CHANNELS; i++ ) { st_ivas->cldfbAnaDec[i] = NULL; } - FOR ( i = 0; i < numCldfbSyntheses; i++ ) + FOR( i = 0; i < numCldfbSyntheses; i++ ) { - IF ( ( error = openCldfb_ivas( &( st_ivas->cldfbSynDec[i] ), CLDFB_SYNTHESIS, output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) + IF( ( error = openCldfb_ivas( &( st_ivas->cldfbSynDec[i] ), CLDFB_SYNTHESIS, output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) { return error; } } - FOR ( ; i < MAX_OUTPUT_CHANNELS; i++ ) + FOR( ; i < MAX_OUTPUT_CHANNELS; i++ ) { st_ivas->cldfbSynDec[i] = NULL; } /* CLDFB Interpolation weights */ - IF ( ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT ) && !st_ivas->sba_dirac_stereo_flag && st_ivas->hDecoderConfig->nchan_out != 1 ) + IF( ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT ) && !st_ivas->sba_dirac_stereo_flag && st_ivas->hDecoderConfig->nchan_out != 1 ) { #ifdef IVAS_FLOAT_FIXED #if 1 @@ -2802,7 +2811,7 @@ ivas_error ivas_init_decoder_fx( * Allocate and initialize limiter struct *-----------------------------------------------------------------*/ - IF ( ( error = ivas_limiter_open( &st_ivas->hLimiter, hDecoderConfig->nchan_out, output_Fs ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_limiter_open( &st_ivas->hLimiter, hDecoderConfig->nchan_out, output_Fs ) ) != IVAS_ERR_OK ) { return error; } @@ -2811,32 +2820,32 @@ ivas_error ivas_init_decoder_fx( * Allocate and initialize JBM struct + buffer *-----------------------------------------------------------------*/ - IF ( st_ivas->hTcBuffer == NULL ) + IF( st_ivas->hTcBuffer == NULL ) { /* no module has yet open the TC buffer, open a default one */ n_channels_transport_jbm = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas ); - IF ( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, ivas_jbm_dec_get_tc_buffer_mode( st_ivas ), n_channels_transport_jbm, n_channels_transport_jbm, n_channels_transport_jbm, NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, ivas_jbm_dec_get_tc_buffer_mode( st_ivas ), n_channels_transport_jbm, n_channels_transport_jbm, n_channels_transport_jbm, NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ) != IVAS_ERR_OK ) { return error; } } - IF ( st_ivas->hTcBuffer == NULL ) + IF( st_ivas->hTcBuffer == NULL ) { /* we need the handle anyway, but without the buffer*/ - IF ( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_NONE, 0, 0, 0, 1 ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_NONE, 0, 0, 0, 1 ) ) != IVAS_ERR_OK ) { return error; } } - IF ( st_ivas->hJbmMetadata == NULL ) + IF( st_ivas->hJbmMetadata == NULL ) { - IF ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_EXTERNAL ) + IF( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_EXTERNAL ) { - IF ( ( error = ivas_jbm_dec_metadata_open( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_jbm_dec_metadata_open( st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -2846,26 +2855,24 @@ ivas_error ivas_init_decoder_fx( /*-----------------------------------------------------------------* * Allocate floating-point output audio buffers *-----------------------------------------------------------------*/ - st_ivas->p_out_len = ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); + st_ivas->p_out_len = ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); - FOR ( n = 0; n < ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); n++ ) + FOR( n = 0; n < ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); n++ ) + { + /* note: these are intra-frame heap memories */ + IF( ( st_ivas->p_output_f[n] = (float *) malloc( ( 48000 / FRAMES_PER_SEC ) * sizeof( float ) ) ) == NULL ) { - /* note: these are intra-frame heap memories */ - IF ( ( st_ivas->p_output_f[n] = (float *) malloc( ( 48000 / FRAMES_PER_SEC ) * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for floating-point output audio buffer!\n" ) ); - } - set_zero(st_ivas->p_output_f[n], 48000 / FRAMES_PER_SEC); - IF ( ( st_ivas->p_output_fx[n] = (Word32 *) malloc( ( 48000 / FRAMES_PER_SEC ) * sizeof( Word32 ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for floating-point output audio buffer!\n" ) ); - } - set32_fx(st_ivas->p_output_fx[n], 0, 48000 / FRAMES_PER_SEC); - - + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for floating-point output audio buffer!\n" ) ); + } + set_zero( st_ivas->p_output_f[n], 48000 / FRAMES_PER_SEC ); + IF( ( st_ivas->p_output_fx[n] = (Word32 *) malloc( ( 48000 / FRAMES_PER_SEC ) * sizeof( Word32 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for floating-point output audio buffer!\n" ) ); } + set32_fx( st_ivas->p_output_fx[n], 0, 48000 / FRAMES_PER_SEC ); + } - FOR ( ; n < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; n++ ) + FOR( ; n < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; n++ ) { st_ivas->p_output_f[n] = NULL; st_ivas->p_output_fx[n] = NULL; @@ -3113,10 +3120,8 @@ ivas_error ivas_init_decoder( } } - if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) ? IVAS_MAX_NUM_BANDS : ( IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ) - , - st_ivas->ivas_format - ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) ? IVAS_MAX_NUM_BANDS : ( IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ), + st_ivas->ivas_format ) ) != IVAS_ERR_OK ) { return error; } @@ -3269,10 +3274,8 @@ ivas_error ivas_init_decoder( } } - if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) ? IVAS_MAX_NUM_BANDS : ( IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ) - , - st_ivas->ivas_format - ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) ? IVAS_MAX_NUM_BANDS : ( IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ), + st_ivas->ivas_format ) ) != IVAS_ERR_OK ) { return error; } @@ -3731,13 +3734,13 @@ ivas_error ivas_init_decoder( } } - granularity = NS2SA( st_ivas->hDecoderConfig->output_Fs, FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ); - n_channels_transport_jbm = ivas_jbm_dec_get_num_tc_channels( st_ivas ); + granularity = NS2SA( st_ivas->hDecoderConfig->output_Fs, FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ); + n_channels_transport_jbm = ivas_jbm_dec_get_num_tc_channels( st_ivas ); - if ( ( error = ivas_jbm_dec_tc_buffer_open( st_ivas, TC_BUFFER_MODE_RENDERER, n_channels_transport_jbm, n_channels_transport_jbm, n_channels_transport_jbm, granularity ) ) != IVAS_ERR_OK ) - { - return error; - } + if ( ( error = ivas_jbm_dec_tc_buffer_open( st_ivas, TC_BUFFER_MODE_RENDERER, n_channels_transport_jbm, n_channels_transport_jbm, n_channels_transport_jbm, granularity ) ) != IVAS_ERR_OK ) + { + return error; + } } else if ( st_ivas->renderer_type == RENDERER_MC ) { @@ -3771,28 +3774,28 @@ ivas_error ivas_init_decoder( st_ivas->binaural_latency_ns = st_ivas->hCrendWrapper->binaural_latency_ns; - if ( ( st_ivas->ivas_format == MC_FORMAT ) && ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) ) - { - granularity = NS2SA( output_Fs, CLDFB_SLOT_NS ); + if ( ( st_ivas->ivas_format == MC_FORMAT ) && ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) ) + { + granularity = NS2SA( output_Fs, CLDFB_SLOT_NS ); - n_channels_transport_jbm = ivas_jbm_dec_get_num_tc_channels( st_ivas ); + n_channels_transport_jbm = ivas_jbm_dec_get_num_tc_channels( st_ivas ); - if ( ( error = ivas_jbm_dec_tc_buffer_open( st_ivas, TC_BUFFER_MODE_RENDERER, n_channels_transport_jbm, MC_PARAMUPMIX_MAX_INPUT_CHANS, MC_PARAMUPMIX_MAX_INPUT_CHANS, granularity ) ) != IVAS_ERR_OK ) - { - return error; - } - } - else + if ( ( error = ivas_jbm_dec_tc_buffer_open( st_ivas, TC_BUFFER_MODE_RENDERER, n_channels_transport_jbm, MC_PARAMUPMIX_MAX_INPUT_CHANS, MC_PARAMUPMIX_MAX_INPUT_CHANS, granularity ) ) != IVAS_ERR_OK ) { - granularity = NS2SA( st_ivas->hDecoderConfig->output_Fs, FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ); + return error; + } + } + else + { + granularity = NS2SA( st_ivas->hDecoderConfig->output_Fs, FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ); - n_channels_transport_jbm = ivas_jbm_dec_get_num_tc_channels( st_ivas ); + n_channels_transport_jbm = ivas_jbm_dec_get_num_tc_channels( st_ivas ); - if ( ( error = ivas_jbm_dec_tc_buffer_open( st_ivas, TC_BUFFER_MODE_RENDERER, n_channels_transport_jbm, n_channels_transport_jbm, n_channels_transport_jbm, granularity ) ) != IVAS_ERR_OK ) - { - return error; - } + if ( ( error = ivas_jbm_dec_tc_buffer_open( st_ivas, TC_BUFFER_MODE_RENDERER, n_channels_transport_jbm, n_channels_transport_jbm, n_channels_transport_jbm, granularity ) ) != IVAS_ERR_OK ) + { + return error; } + } } if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) @@ -3968,14 +3971,14 @@ ivas_error ivas_init_decoder( * Allocate floating-point output audio buffers *-----------------------------------------------------------------*/ - for ( n = 0; n < ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); n++ ) + for ( n = 0; n < ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); n++ ) + { + /* note: these are intra-frame heap memories */ + if ( ( st_ivas->p_output_f[n] = (float *) malloc( ( 48000 / FRAMES_PER_SEC ) * sizeof( float ) ) ) == NULL ) { - /* note: these are intra-frame heap memories */ - if ( ( st_ivas->p_output_f[n] = (float *) malloc( ( 48000 / FRAMES_PER_SEC ) * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for floating-point output audio buffer!\n" ) ); - } + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for floating-point output audio buffer!\n" ) ); } + } for ( ; n < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; n++ ) { @@ -4008,127 +4011,127 @@ void destroy_core_dec_fx( destroy_cldfb_decoder_ivas_fx( hCoreCoder ); } - IF ( hCoreCoder->hGSCDec != NULL ) + IF( hCoreCoder->hGSCDec != NULL ) { free( hCoreCoder->hGSCDec ); hCoreCoder->hGSCDec = NULL; } - IF ( hCoreCoder->hPFstat != NULL ) + IF( hCoreCoder->hPFstat != NULL ) { free( hCoreCoder->hPFstat ); hCoreCoder->hPFstat = NULL; } - IF ( hCoreCoder->hMusicPF != NULL ) + IF( hCoreCoder->hMusicPF != NULL ) { free( hCoreCoder->hMusicPF ); hCoreCoder->hMusicPF = NULL; } - IF ( hCoreCoder->hBPF != NULL ) + IF( hCoreCoder->hBPF != NULL ) { free( hCoreCoder->hBPF ); hCoreCoder->hBPF = NULL; } - IF ( hCoreCoder->hBWE_zero != NULL ) + IF( hCoreCoder->hBWE_zero != NULL ) { free( hCoreCoder->hBWE_zero ); hCoreCoder->hBWE_zero = NULL; } - IF ( hCoreCoder->hTdCngDec != NULL ) + IF( hCoreCoder->hTdCngDec != NULL ) { free( hCoreCoder->hTdCngDec ); hCoreCoder->hTdCngDec = NULL; } - IF ( hCoreCoder->hSC_VBR != NULL ) + IF( hCoreCoder->hSC_VBR != NULL ) { free( hCoreCoder->hSC_VBR ); hCoreCoder->hSC_VBR = NULL; } - IF ( hCoreCoder->hAmrwb_IO != NULL ) + IF( hCoreCoder->hAmrwb_IO != NULL ) { free( hCoreCoder->hAmrwb_IO ); hCoreCoder->hAmrwb_IO = NULL; } - IF ( hCoreCoder->hBWE_TD != NULL ) + IF( hCoreCoder->hBWE_TD != NULL ) { free( hCoreCoder->hBWE_TD ); hCoreCoder->hBWE_TD = NULL; } - IF ( hCoreCoder->hBWE_FD != NULL ) + IF( hCoreCoder->hBWE_FD != NULL ) { free( hCoreCoder->hBWE_FD ); hCoreCoder->hBWE_FD = NULL; } - IF ( hCoreCoder->hBWE_FD_HR != NULL ) + IF( hCoreCoder->hBWE_FD_HR != NULL ) { free( hCoreCoder->hBWE_FD_HR ); hCoreCoder->hBWE_FD_HR = NULL; } - IF ( hCoreCoder->hWIDec != NULL ) + IF( hCoreCoder->hWIDec != NULL ) { free( hCoreCoder->hWIDec ); hCoreCoder->hWIDec = NULL; } - IF ( hCoreCoder->hTECDec != NULL ) + IF( hCoreCoder->hTECDec != NULL ) { free( hCoreCoder->hTECDec ); hCoreCoder->hTECDec = NULL; } - IF ( hCoreCoder->hTcxLtpDec != NULL ) + IF( hCoreCoder->hTcxLtpDec != NULL ) { free( hCoreCoder->hTcxLtpDec ); hCoreCoder->hTcxLtpDec = NULL; } - IF ( hCoreCoder->hTcxDec != NULL ) + IF( hCoreCoder->hTcxDec != NULL ) { free( hCoreCoder->hTcxDec ); hCoreCoder->hTcxDec = NULL; } - IF ( hCoreCoder->hTcxCfg != NULL ) + IF( hCoreCoder->hTcxCfg != NULL ) { free( hCoreCoder->hTcxCfg ); hCoreCoder->hTcxCfg = NULL; } - IF ( hCoreCoder->hTonalMDCTConc != NULL ) + IF( hCoreCoder->hTonalMDCTConc != NULL ) { free( hCoreCoder->hTonalMDCTConc ); hCoreCoder->hTonalMDCTConc = NULL; } - IF ( hCoreCoder->hIGFDec != NULL ) + IF( hCoreCoder->hIGFDec != NULL ) { free( hCoreCoder->hIGFDec ); hCoreCoder->hIGFDec = NULL; } - IF ( hCoreCoder->hPlcInfo != NULL ) + IF( hCoreCoder->hPlcInfo != NULL ) { free( hCoreCoder->hPlcInfo ); hCoreCoder->hPlcInfo = NULL; } - IF ( hCoreCoder->hHQ_core != NULL ) + IF( hCoreCoder->hHQ_core != NULL ) { free( hCoreCoder->hHQ_core ); hCoreCoder->hHQ_core = NULL; } - IF ( hCoreCoder->hHQ_nbfec != NULL ) + IF( hCoreCoder->hHQ_nbfec != NULL ) { free( hCoreCoder->hHQ_nbfec ); hCoreCoder->hHQ_nbfec = NULL; @@ -4287,24 +4290,24 @@ void ivas_initialize_handles_dec( { Word16 i; - FOR ( i = 0; i < MAX_INTERN_CHANNELS; i++ ) + FOR( i = 0; i < MAX_INTERN_CHANNELS; i++ ) { st_ivas->cldfbAnaDec[i] = NULL; } - FOR ( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) + FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) { st_ivas->cldfbSynDec[i] = NULL; } /* SCE handles */ - FOR ( i = 0; i < MAX_SCE; i++ ) + FOR( i = 0; i < MAX_SCE; i++ ) { st_ivas->hSCE[i] = NULL; } /* CPE handles */ - FOR ( i = 0; i < MAX_CPE; i++ ) + FOR( i = 0; i < MAX_CPE; i++ ) { st_ivas->hCPE[i] = NULL; } @@ -4314,7 +4317,7 @@ void ivas_initialize_handles_dec( st_ivas->hLimiter = NULL; /* ISM metadata handles */ - FOR ( i = 0; i < MAX_NUM_OBJECTS; i++ ) + FOR( i = 0; i < MAX_NUM_OBJECTS; i++ ) { st_ivas->hIsmMetaData[i] = NULL; } @@ -4363,7 +4366,7 @@ void ivas_initialize_handles_dec( st_ivas->hJbmMetadata = NULL; /* floating-point output audio buffers */ - FOR ( i = 0; i < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; i++ ) + FOR( i = 0; i < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; i++ ) { #ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED st_ivas->p_output_f[i] = NULL; @@ -4414,13 +4417,13 @@ void ivas_initialize_handles_dec( ivas_ism_renderer_close( &( st_ivas->hIsmRendererData ) ); /* DirAC handle */ - if( st_ivas->ivas_format == ISM_FORMAT ) + if ( st_ivas->ivas_format == ISM_FORMAT ) { ivas_param_ism_dec_close( &( st_ivas->hParamIsmDec ), &( st_ivas->hSpatParamRendCom ), st_ivas->hDecoderConfig->output_config ); } ELSE - for ( i = 0; i < MAX_NUM_OBJECTS; i++ ) + for ( i = 0; i < MAX_NUM_OBJECTS; i++ ) { st_ivas->hIsmMetaData[i] = NULL; } @@ -4494,26 +4497,26 @@ void ivas_destroy_dec( Word16 i; /* CLDFB handles */ - FOR ( i = 0; i < MAX_INTERN_CHANNELS; i++ ) + FOR( i = 0; i < MAX_INTERN_CHANNELS; i++ ) { - IF ( st_ivas->cldfbAnaDec[i] != NULL ) + IF( st_ivas->cldfbAnaDec[i] != NULL ) { deleteCldfb_ivas( &( st_ivas->cldfbAnaDec[i] ) ); } } - FOR ( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) + FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) { - IF ( st_ivas->cldfbSynDec[i] != NULL ) + IF( st_ivas->cldfbSynDec[i] != NULL ) { deleteCldfb_ivas( &( st_ivas->cldfbSynDec[i] ) ); } } /* SCE handles */ - FOR ( i = 0; i < MAX_SCE; i++ ) + FOR( i = 0; i < MAX_SCE; i++ ) { - IF ( st_ivas->hSCE[i] != NULL ) + IF( st_ivas->hSCE[i] != NULL ) { destroy_sce_dec( st_ivas->hSCE[i] ); st_ivas->hSCE[i] = NULL; @@ -4521,12 +4524,12 @@ void ivas_destroy_dec( } /* CPE handles */ - FOR ( i = 0; i < MAX_CPE; i++ ) + FOR( i = 0; i < MAX_CPE; i++ ) { - IF ( st_ivas->hCPE[i] != NULL ) + IF( st_ivas->hCPE[i] != NULL ) { /* set pointer to NULL as core coder already deallocated in destroy_sce_dec() */ - IF ( st_ivas->sba_dirac_stereo_flag && st_ivas->nchan_transport == 1 ) + IF( st_ivas->sba_dirac_stereo_flag && st_ivas->nchan_transport == 1 ) { st_ivas->hCPE[i]->hCoreCoder[0] = NULL; st_ivas->hCPE[i]->hCoreCoder[1] = NULL; @@ -4555,13 +4558,13 @@ void ivas_destroy_dec( ivas_ism_renderer_close( &( st_ivas->hIsmRendererData ) ); /* DirAC handle */ - IF ( st_ivas->ivas_format == ISM_FORMAT ) + IF( st_ivas->ivas_format == ISM_FORMAT ) { ivas_param_ism_dec_close_fx( &( st_ivas->hParamIsmDec ), &( st_ivas->hSpatParamRendCom ), st_ivas->hDecoderConfig->output_config ); } ELSE { - ivas_dirac_rend_close_fx(&(st_ivas->hDirACRend)); + ivas_dirac_rend_close_fx( &( st_ivas->hDirACRend ) ); ivas_spat_hSpatParamRendCom_close_fx( &( st_ivas->hSpatParamRendCom ) ); ivas_dirac_dec_close_fx( &( st_ivas->hDirAC ) ); } @@ -4570,7 +4573,7 @@ void ivas_destroy_dec( ivas_spar_dec_close( &( st_ivas->hSpar ), st_ivas->hDecoderConfig->output_Fs, 0 ); /* HOA decoder matrix */ - IF ( st_ivas->hoa_dec_mtx != NULL ) + IF( st_ivas->hoa_dec_mtx != NULL ) { free( st_ivas->hoa_dec_mtx ); st_ivas->hoa_dec_mtx = NULL; @@ -4598,7 +4601,7 @@ void ivas_destroy_dec( efap_free_data( &st_ivas->hEFAPdata ); /* VBAP handle */ - vbap_free_data_fx(&(st_ivas->hVBAPdata)); + vbap_free_data_fx( &( st_ivas->hVBAPdata ) ); /* Fastconv binaural renderer handle */ ivas_binRenderer_close_fx( &st_ivas->hBinRenderer ); @@ -4616,7 +4619,7 @@ void ivas_destroy_dec( ivas_ls_setup_conversion_close_fx( &st_ivas->hLsSetUpConversion ); /* Custom LS configuration handle */ - IF ( st_ivas->hLsSetupCustom != NULL ) + IF( st_ivas->hLsSetupCustom != NULL ) { free( st_ivas->hLsSetupCustom ); st_ivas->hLsSetupCustom = NULL; @@ -4641,11 +4644,11 @@ void ivas_destroy_dec( ivas_combined_orientation_close( &st_ivas->hCombinedOrientationData ); /* Time Domain binaural renderer handle */ - IF ( st_ivas->hBinRendererTd != NULL ) + IF( st_ivas->hBinRendererTd != NULL ) { ivas_td_binaural_close_fx( &st_ivas->hBinRendererTd ); } - ELSE IF ( st_ivas->hHrtfTD != NULL ) + ELSE IF( st_ivas->hHrtfTD != NULL ) { #ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED BSplineModelEvalDealloc( &st_ivas->hHrtfTD->ModelParams, &st_ivas->hHrtfTD->ModelEval ); @@ -4672,7 +4675,7 @@ void ivas_destroy_dec( /* Limiter struct */ ivas_limiter_close( &( st_ivas->hLimiter ) ); - IF ( st_ivas->hDecoderConfig != NULL ) + IF( st_ivas->hDecoderConfig != NULL ) { free( st_ivas->hDecoderConfig ); st_ivas->hDecoderConfig = NULL; @@ -4680,27 +4683,27 @@ void ivas_destroy_dec( ivas_jbm_dec_tc_buffer_close( &st_ivas->hTcBuffer ); - IF ( st_ivas->hJbmMetadata != NULL ) + IF( st_ivas->hJbmMetadata != NULL ) { free( st_ivas->hJbmMetadata ); st_ivas->hJbmMetadata = NULL; } /* floating-point output audio buffers */ - FOR ( i = 0; i < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; i++ ) + FOR( i = 0; i < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; i++ ) { #ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED - IF ( st_ivas->p_output_f[i] != NULL ) + IF( st_ivas->p_output_f[i] != NULL ) { free( st_ivas->p_output_f[i] ); st_ivas->p_output_f[i] = NULL; } #endif - IF(st_ivas->p_output_fx[i] != NULL) + IF( st_ivas->p_output_fx[i] != NULL ) { - free(st_ivas->p_output_fx[i]); - st_ivas->p_output_fx[i] = NULL; + free( st_ivas->p_output_fx[i] ); + st_ivas->p_output_fx[i] = NULL; } } @@ -4937,7 +4940,7 @@ void ivas_destroy_dec( /*! r: number of cldfb instances */ #ifdef IVAS_FLOAT_FIXED void ivas_init_dec_get_num_cldfb_instances( - Decoder_Struct *st_ivas, /* i : IVAS decoder structure */ + Decoder_Struct *st_ivas, /* i : IVAS decoder structure */ Word16 *numCldfbAnalyses, /* o : number of needed CLDFB analysis instances */ Word16 *numCldfbSyntheses /* o : number of needed CLDFB synthesis instances */ ) @@ -4948,48 +4951,48 @@ void ivas_init_dec_get_num_cldfb_instances( ivas_format = ( st_ivas->ivas_format == SBA_ISM_FORMAT && st_ivas->ism_mode == ISM_MODE_NONE ) ? SBA_FORMAT : st_ivas->ivas_format; /* treat ISM_SBA_MODE_NONE just like SBA_FORMAT */ - SWITCH ( st_ivas->renderer_type ) + SWITCH( st_ivas->renderer_type ) { case RENDERER_BINAURAL_PARAMETRIC: case RENDERER_BINAURAL_PARAMETRIC_ROOM: case RENDERER_STEREO_PARAMETRIC: - IF ( st_ivas->nchan_transport == 1 ) + IF( st_ivas->nchan_transport == 1 ) { *numCldfbAnalyses = st_ivas->nchan_transport + 1; } - IF ( st_ivas->mc_mode == MC_MODE_MCMASA && st_ivas->hOutSetup.separateChannelEnabled ) + IF( st_ivas->mc_mode == MC_MODE_MCMASA && st_ivas->hOutSetup.separateChannelEnabled ) { *numCldfbAnalyses = st_ivas->nchan_transport + 1; } - IF ( ivas_format == SBA_ISM_FORMAT ) + IF( ivas_format == SBA_ISM_FORMAT ) { - IF ( st_ivas->ism_mode == ISM_SBA_MODE_DISC ) + IF( st_ivas->ism_mode == ISM_SBA_MODE_DISC ) { *numCldfbAnalyses += st_ivas->nchan_ism; } } - IF ( ivas_format == MASA_ISM_FORMAT ) + IF( ivas_format == MASA_ISM_FORMAT ) { - IF ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + IF( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { *numCldfbAnalyses += st_ivas->nchan_ism; } - ELSE IF ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) + ELSE IF( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) { *numCldfbAnalyses = st_ivas->nchan_transport + 1; } } - IF ( st_ivas->hDiracDecBin->useTdDecorr ) + IF( st_ivas->hDiracDecBin->useTdDecorr ) { *numCldfbAnalyses += 2; } BREAK; case RENDERER_NON_DIEGETIC_DOWNMIX: case RENDERER_MONO_DOWNMIX: - IF ( ivas_format == ISM_FORMAT || ivas_format == MASA_ISM_FORMAT || ivas_format == SBA_ISM_FORMAT ) + IF( ivas_format == ISM_FORMAT || ivas_format == MASA_ISM_FORMAT || ivas_format == SBA_ISM_FORMAT ) { /* CLDFB not used in rendering */ *numCldfbAnalyses = 0; @@ -4997,15 +5000,15 @@ void ivas_init_dec_get_num_cldfb_instances( } BREAK; case RENDERER_DIRAC: - IF ( ivas_format == SBA_FORMAT ) + IF( ivas_format == SBA_FORMAT ) { *numCldfbAnalyses = st_ivas->hSpar->hFbMixer->fb_cfg->num_in_chans; - IF ( st_ivas->hOutSetup.is_loudspeaker_setup && st_ivas->renderer_type == RENDERER_DIRAC ) + IF( st_ivas->hOutSetup.is_loudspeaker_setup && st_ivas->renderer_type == RENDERER_DIRAC ) { *numCldfbSyntheses = st_ivas->hOutSetup.nchan_out_woLFE; } - ELSE IF ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_FOA ) + ELSE IF( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_FOA ) { *numCldfbSyntheses = st_ivas->hSpar->hFbMixer->fb_cfg->num_out_chans; } @@ -5014,20 +5017,20 @@ void ivas_init_dec_get_num_cldfb_instances( *numCldfbSyntheses = MAX_OUTPUT_CHANNELS; } } - IF ( ivas_format != SBA_FORMAT ) + IF( ivas_format != SBA_FORMAT ) { - IF ( GT_16(st_ivas->nchan_transport, 2) && NE_16(st_ivas->sba_planar, 0) ) + IF( GT_16( st_ivas->nchan_transport, 2 ) && NE_16( st_ivas->sba_planar, 0 ) ) { - *numCldfbAnalyses = add(st_ivas->nchan_transport, 1); + *numCldfbAnalyses = add( st_ivas->nchan_transport, 1 ); } - ELSE IF ( EQ_16(st_ivas->nchan_transport, 1) && st_ivas->hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) + ELSE IF( EQ_16( st_ivas->nchan_transport, 1 ) && st_ivas->hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { - *numCldfbAnalyses = add(st_ivas->nchan_transport, 1); + *numCldfbAnalyses = add( st_ivas->nchan_transport, 1 ); } } BREAK; case RENDERER_MC_PARAMMC: - IF ( LE_16(st_ivas->hDecoderConfig->nchan_out, 2 )) + IF( LE_16( st_ivas->hDecoderConfig->nchan_out, 2 ) ) { /* CLDFB not used in rendering */ *numCldfbAnalyses = 0; @@ -5058,9 +5061,9 @@ void ivas_init_dec_get_num_cldfb_instances( case RENDERER_OSBA_STEREO: case RENDERER_OSBA_AMBI: case RENDERER_OSBA_LS: - IF ( ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT ) + IF( ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT ) { - IF ( NE_16(st_ivas->sba_dirac_stereo_flag, 0) ) + IF( NE_16( st_ivas->sba_dirac_stereo_flag, 0 ) ) { *numCldfbAnalyses = 0; *numCldfbSyntheses = 0; @@ -5069,11 +5072,11 @@ void ivas_init_dec_get_num_cldfb_instances( { *numCldfbAnalyses = st_ivas->hSpar->hFbMixer->fb_cfg->num_in_chans; - IF ( st_ivas->hOutSetup.is_loudspeaker_setup && st_ivas->renderer_type == RENDERER_DIRAC ) + IF( st_ivas->hOutSetup.is_loudspeaker_setup && st_ivas->renderer_type == RENDERER_DIRAC ) { *numCldfbSyntheses = st_ivas->hOutSetup.nchan_out_woLFE; } - ELSE IF ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_FOA ) + ELSE IF( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_FOA ) { *numCldfbSyntheses = st_ivas->hSpar->hFbMixer->fb_cfg->num_out_chans; } @@ -5082,13 +5085,13 @@ void ivas_init_dec_get_num_cldfb_instances( *numCldfbSyntheses = MAX_OUTPUT_CHANNELS; } - IF ( st_ivas->ivas_format == SBA_ISM_FORMAT && st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) + IF( st_ivas->ivas_format == SBA_ISM_FORMAT && st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) { *numCldfbAnalyses = st_ivas->nchan_ism + st_ivas->hSpar->hFbMixer->fb_cfg->num_in_chans; } } } - ELSE IF ( st_ivas->mc_mode == MC_MODE_PARAMMC ) + ELSE IF( st_ivas->mc_mode == MC_MODE_PARAMMC ) { /* do nothing for ParamMC */ } @@ -5100,15 +5103,15 @@ void ivas_init_dec_get_num_cldfb_instances( } BREAK; case RENDERER_SBA_LINEAR_ENC: - IF ( st_ivas->mc_mode == MC_MODE_PARAMMC ) + IF( st_ivas->mc_mode == MC_MODE_PARAMMC ) { *numCldfbSyntheses = param_mc_get_num_cldfb_syntheses_fx( st_ivas ); } - ELSE IF ( st_ivas->ism_mode == ISM_MODE_PARAM ) + ELSE IF( st_ivas->ism_mode == ISM_MODE_PARAM ) { *numCldfbSyntheses = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; } - ELSE IF ( st_ivas->mc_mode == MC_MODE_MCMASA ) + ELSE IF( st_ivas->mc_mode == MC_MODE_MCMASA ) { *numCldfbAnalyses = st_ivas->nchan_transport; *numCldfbSyntheses = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; @@ -5124,9 +5127,9 @@ void ivas_init_dec_get_num_cldfb_instances( assert( 0 && "Renderer not handled for CLDFB reservation." ); } - IF ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX && st_ivas->hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_MONO && st_ivas->hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_STEREO ) + IF( st_ivas->mc_mode == MC_MODE_PARAMUPMIX && st_ivas->hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_MONO && st_ivas->hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_STEREO ) { - IF ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) + IF( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) { *numCldfbAnalyses = max( MC_PARAMUPMIX_MAX_INPUT_CHANS, *numCldfbAnalyses ); } @@ -5370,7 +5373,7 @@ static ivas_error doSanityChecks_IVAS( * Sanity checks *-----------------------------------------------------------------*/ - IF ( output_Fs == 8000 ) + IF( output_Fs == 8000 ) { return IVAS_ERROR( IVAS_ERR_INVALID_SAMPLING_RATE, "8kHz output sampling rate is not supported in IVAS." ); } @@ -5379,88 +5382,87 @@ static ivas_error doSanityChecks_IVAS( assert( st_ivas->ivas_format != MONO_FORMAT && "\n Wrong IVAS format: MONO" ); /* Verify output configuration compatible with non-diegetic panning */ - IF ( st_ivas->hDecoderConfig->Opt_non_diegetic_pan && ( st_ivas->ivas_format != MONO_FORMAT ) && ( st_ivas->transport_config != IVAS_AUDIO_CONFIG_ISM1 ) ) + IF( st_ivas->hDecoderConfig->Opt_non_diegetic_pan && ( st_ivas->ivas_format != MONO_FORMAT ) && ( st_ivas->transport_config != IVAS_AUDIO_CONFIG_ISM1 ) ) { return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Error: Non-diegetic panning not supported in this IVAS format" ); } /* Verify stereo output configuration */ - IF ( st_ivas->ivas_format == STEREO_FORMAT ) + IF( st_ivas->ivas_format == STEREO_FORMAT ) { - IF ( output_config != IVAS_AUDIO_CONFIG_MONO && output_config != IVAS_AUDIO_CONFIG_STEREO && output_config != IVAS_AUDIO_CONFIG_5_1 && output_config != IVAS_AUDIO_CONFIG_7_1 && output_config != IVAS_AUDIO_CONFIG_5_1_2 && output_config != IVAS_AUDIO_CONFIG_5_1_4 && output_config != IVAS_AUDIO_CONFIG_7_1_4 && output_config != IVAS_AUDIO_CONFIG_LS_CUSTOM ) + IF( output_config != IVAS_AUDIO_CONFIG_MONO && output_config != IVAS_AUDIO_CONFIG_STEREO && output_config != IVAS_AUDIO_CONFIG_5_1 && output_config != IVAS_AUDIO_CONFIG_7_1 && output_config != IVAS_AUDIO_CONFIG_5_1_2 && output_config != IVAS_AUDIO_CONFIG_5_1_4 && output_config != IVAS_AUDIO_CONFIG_7_1_4 && output_config != IVAS_AUDIO_CONFIG_LS_CUSTOM ) { return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Wrong output configuration specified for Stereo!" ); } } - ELSE IF ( st_ivas->ivas_format == ISM_FORMAT ) + ELSE IF( st_ivas->ivas_format == ISM_FORMAT ) { /* Verify ISM output configuration */ - IF ( output_config == IVAS_AUDIO_CONFIG_INVALID ) + IF( output_config == IVAS_AUDIO_CONFIG_INVALID ) { return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Incorrect output configuration specified for ISM" ); } } - ELSE IF ( st_ivas->ivas_format == SBA_FORMAT ) + ELSE IF( st_ivas->ivas_format == SBA_FORMAT ) { /* Verify SBA output coniguration */ - IF ( output_config == IVAS_AUDIO_CONFIG_INVALID ) + IF( output_config == IVAS_AUDIO_CONFIG_INVALID ) { return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Incorrect output configuration specified for SBA" ); } } - ELSE IF ( st_ivas->ivas_format == MASA_FORMAT ) + ELSE IF( st_ivas->ivas_format == MASA_FORMAT ) { - IF ( output_config == IVAS_AUDIO_CONFIG_INVALID ) + IF( output_config == IVAS_AUDIO_CONFIG_INVALID ) { return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Incorrect output configuration specified for MASA!" ); } } - ELSE IF ( st_ivas->ivas_format == MC_FORMAT ) + ELSE IF( st_ivas->ivas_format == MC_FORMAT ) { /* Verify MC output configuration */ - IF ( output_config == IVAS_AUDIO_CONFIG_INVALID || output_config == IVAS_AUDIO_CONFIG_EXTERNAL ) + IF( output_config == IVAS_AUDIO_CONFIG_INVALID || output_config == IVAS_AUDIO_CONFIG_EXTERNAL ) { return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Incorrect output configuration specified for Multi-channel" ); } } - IF ( st_ivas->hDecoderConfig->Opt_Headrotation ) + IF( st_ivas->hDecoderConfig->Opt_Headrotation ) { - IF ( !( output_config == IVAS_AUDIO_CONFIG_BINAURAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB - ) ) + IF( !( output_config == IVAS_AUDIO_CONFIG_BINAURAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { return IVAS_ERROR( IVAS_ERR_HEAD_ROTATION_NOT_SUPPORTED, "Wrong set-up: Head-rotation not supported in this configuration" ); } } - IF ( st_ivas->hDecoderConfig->Opt_ExternalOrientation ) + IF( st_ivas->hDecoderConfig->Opt_ExternalOrientation ) { - IF ( !( output_config == IVAS_AUDIO_CONFIG_BINAURAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) + IF( !( output_config == IVAS_AUDIO_CONFIG_BINAURAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { return IVAS_ERROR( IVAS_ERR_EXT_ORIENTATION_NOT_SUPPORTED, "Wrong set-up: External orientation not supported in this configuration" ); } } - IF ( st_ivas->hDecoderConfig->Opt_dpid_on ) + IF( st_ivas->hDecoderConfig->Opt_dpid_on ) { - IF ( !( output_config == IVAS_AUDIO_CONFIG_BINAURAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) + IF( !( output_config == IVAS_AUDIO_CONFIG_BINAURAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { return IVAS_ERROR( IVAS_ERR_DIRECTIVITY_NOT_SUPPORTED, "Wrong set-up: Directivity is not supported in this output configuration." ); } } - IF ( st_ivas->hDecoderConfig->Opt_aeid_on ) + IF( st_ivas->hDecoderConfig->Opt_aeid_on ) { - IF ( output_config != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) + IF( output_config != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) { return IVAS_ERROR( IVAS_ERR_ACOUSTIC_ENVIRONMENT_NOT_SUPPORTED, "Wrong set-up: Acoustic environment is not supported in this output configuration." ); } } - IF ( st_ivas->ivas_format == MASA_ISM_FORMAT ) + IF( st_ivas->ivas_format == MASA_ISM_FORMAT ) { - IF ( st_ivas->ism_mode != ISM_MASA_MODE_DISC && output_config == IVAS_AUDIO_CONFIG_EXTERNAL ) + IF( st_ivas->ism_mode != ISM_MASA_MODE_DISC && output_config == IVAS_AUDIO_CONFIG_EXTERNAL ) { return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Incorrect output configuration specified for combined MASA and ISM format" ); } @@ -5541,8 +5543,7 @@ static ivas_error doSanityChecks_IVAS( if ( st_ivas->hDecoderConfig->Opt_Headrotation ) { - if ( !( output_config == IVAS_AUDIO_CONFIG_BINAURAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB - ) ) + if ( !( output_config == IVAS_AUDIO_CONFIG_BINAURAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { return IVAS_ERROR( IVAS_ERR_HEAD_ROTATION_NOT_SUPPORTED, "Wrong set-up: Head-rotation not supported in this configuration" ); } @@ -5584,4 +5585,4 @@ static ivas_error doSanityChecks_IVAS( return IVAS_ERR_OK; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/ivas_init_dec_fx.c b/lib_dec/ivas_init_dec_fx.c index 389d4212e..7d4820c14 100644 --- a/lib_dec/ivas_init_dec_fx.c +++ b/lib_dec/ivas_init_dec_fx.c @@ -207,4 +207,4 @@ void ivas_init_dec_get_num_cldfb_instances_ivas_fx( return; } -#endif // IVAS_FLOAT_FIXED \ No newline at end of file +#endif // IVAS_FLOAT_FIXED diff --git a/lib_dec/ivas_ism_dec.c b/lib_dec/ivas_ism_dec.c index f016a00e6..e15b3a421 100644 --- a/lib_dec/ivas_ism_dec.c +++ b/lib_dec/ivas_ism_dec.c @@ -51,11 +51,11 @@ #ifdef IVAS_FLOAT_FIXED static ivas_error ivas_ism_bitrate_switching_dec_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const Word16 nchan_transport_old, /* i : last number of transport channels */ - const ISM_MODE last_ism_mode, /* i : last ISM mode */ + const ISM_MODE last_ism_mode, /* i : last ISM mode */ UWord16 *nSamplesRendered, /* o : number of samples rendered */ - Word16 *data /* o : output synthesis signal */ + Word16 *data /* o : output synthesis signal */ ) { ivas_error error; @@ -85,7 +85,7 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( move16(); nchan_out_buff_old = ivas_get_nchan_buffers_dec_ivas_fx( st_ivas, -1, -1 ); - IF ( ( error = ivas_ism_config_fx( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->nchan_ism, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 0 ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_ism_config_fx( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->nchan_ism, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 0 ) ) != IVAS_ERR_OK ) { return error; } @@ -97,7 +97,7 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( * Allocate, initialize, and configure SCE/CPE/MCT handles *-----------------------------------------------------------------*/ - IF ( ( error = ivas_corecoder_dec_reconfig_fx( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, 0, st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport, ( st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_corecoder_dec_reconfig_fx( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, 0, st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport, ( st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) { return error; } @@ -105,7 +105,7 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( /*-----------------------------------------------------------------* * HP20 memories *-----------------------------------------------------------------*/ - IF ( ( error = ivas_hp20_dec_reconfig_fx( st_ivas, nchan_transport_old ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_hp20_dec_reconfig_fx( st_ivas, nchan_transport_old ) ) != IVAS_ERR_OK ) { return error; } @@ -126,15 +126,17 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config ); - IF ( ( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) && ( EQ_32( st_ivas->ism_mode, ISM_MODE_DISC ) ) ) + IF( ( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) && ( EQ_32( st_ivas->ism_mode, ISM_MODE_DISC ) ) ) { ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->hDecoderConfig->output_config ); } { - test(); test(); test(); + test(); + test(); + test(); /* transfer subframe info from DirAC or ParamMC to central tc buffer */ - IF ( EQ_32( last_ism_mode, ISM_MODE_PARAM ) && st_ivas->hSpatParamRendCom != NULL && ( NE_32( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) && NE_32( st_ivas->renderer_type, RENDERER_DISABLE ) ) ) + IF( EQ_32( last_ism_mode, ISM_MODE_PARAM ) && st_ivas->hSpatParamRendCom != NULL && ( NE_32( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) && NE_32( st_ivas->renderer_type, RENDERER_DISABLE ) ) ) { st_ivas->hTcBuffer->nb_subframes = st_ivas->hSpatParamRendCom->nb_subframes; move16(); @@ -151,9 +153,9 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( render what still fits in the new granularity */ tc_granularity_new = ivas_jbm_dec_get_render_granularity( st_ivas->renderer_type, st_ivas->ivas_format, st_ivas->mc_mode, st_ivas->hDecoderConfig->output_Fs ); - IF ( LT_16( tc_granularity_new, st_ivas->hTcBuffer->n_samples_granularity ) ) + IF( LT_16( tc_granularity_new, st_ivas->hTcBuffer->n_samples_granularity ) ) { - IF ( ( error = ivas_jbm_dec_flush_renderer_fx( st_ivas, tc_granularity_new, renderer_type_old, intern_config_old, &hIntSetupOld, MC_MODE_NONE, last_ism_mode, nSamplesRendered, data ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_jbm_dec_flush_renderer_fx( st_ivas, tc_granularity_new, renderer_type_old, intern_config_old, &hIntSetupOld, MC_MODE_NONE, last_ism_mode, nSamplesRendered, data ) ) != IVAS_ERR_OK ) { return error; } @@ -179,27 +181,27 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( *-----------------------------------------------------------------*/ /* switching from ParamISM to DiscISM */ - IF ( EQ_32( st_ivas->ism_mode, ISM_MODE_DISC ) && EQ_32( last_ism_mode, ISM_MODE_PARAM ) ) + IF( EQ_32( st_ivas->ism_mode, ISM_MODE_DISC ) && EQ_32( last_ism_mode, ISM_MODE_PARAM ) ) { /* Deallocate the ParamISM struct */ ivas_param_ism_dec_close_fx( &( st_ivas->hParamIsmDec ), &( st_ivas->hSpatParamRendCom ), st_ivas->hDecoderConfig->output_config ); - IF ( EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) + IF( EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { /* close the parametric binaural renderer */ ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); /* Open the TD Binaural renderer */ - IF ( st_ivas->hHrtfTD == NULL || st_ivas->hBinRendererTd == NULL ) + IF( st_ivas->hHrtfTD == NULL || st_ivas->hBinRendererTd == NULL ) { Word16 SrcInd[MAX_NUM_TDREND_CHANNELS]; Word16 num_src; - IF ( ( error = ivas_td_binaural_open_fx( st_ivas , SrcInd, &num_src ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_td_binaural_open_fx( st_ivas, SrcInd, &num_src ) ) != IVAS_ERR_OK ) { return error; } - IF ( st_ivas->hIntSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) + IF( st_ivas->hIntSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) { - IF ( ( error = ivas_reverb_open_fx( &st_ivas->hReverb, st_ivas->hDecoderConfig->output_config, NULL,st_ivas->hBinRendererTd->HrFiltSet_p->lr_energy_and_iac_fx, st_ivas->hRenderConfig, st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_reverb_open_fx( &st_ivas->hReverb, st_ivas->hDecoderConfig->output_config, NULL, st_ivas->hBinRendererTd->HrFiltSet_p->lr_energy_and_iac_fx, st_ivas->hRenderConfig, st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) { return error; } @@ -210,7 +212,7 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( { /* close the ISM renderer and reinitialize */ ivas_ism_renderer_close( &st_ivas->hIsmRendererData ); - IF ( ( error = ivas_ism_renderer_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_ism_renderer_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -244,18 +246,18 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( IF( EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { /* open the parametric binaural renderer */ - IF ( ( error = ivas_dirac_dec_binaural_copy_hrtfs_fx( &st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_dirac_dec_binaural_copy_hrtfs_fx( &st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) { return error; } - IF ( ( error = ivas_dirac_dec_init_binaural_data_fx( st_ivas, st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_dirac_dec_init_binaural_data_fx( st_ivas, st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) { return error; } /* Close the TD Binaural renderer */ - IF ( st_ivas->hBinRendererTd->HrFiltSet_p->ModelParams.modelROM == TRUE ) + IF( st_ivas->hBinRendererTd->HrFiltSet_p->ModelParams.modelROM == TRUE ) { ivas_td_binaural_close_fx( &st_ivas->hBinRendererTd ); st_ivas->hHrtfTD = NULL; @@ -272,15 +274,15 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( ivas_ism_renderer_close( &st_ivas->hIsmRendererData ); } - IF ( EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) ) + IF( EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) ) { /* open the parametric binaural renderer */ - IF ( ( error = ivas_dirac_dec_binaural_copy_hrtfs_fx( &st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_dirac_dec_binaural_copy_hrtfs_fx( &st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) { return error; } - IF ( ( error = ivas_dirac_dec_init_binaural_data_fx( st_ivas, st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_dirac_dec_init_binaural_data_fx( st_ivas, st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) { return error; } @@ -294,7 +296,7 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( * CLDFB instances *-----------------------------------------------------------------*/ - IF ( ( error = ivas_cldfb_dec_reconfig_fx( st_ivas, nchan_transport_old, numCldfbAnalyses_old, numCldfbSyntheses_old ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_cldfb_dec_reconfig_fx( st_ivas, nchan_transport_old, numCldfbAnalyses_old, numCldfbSyntheses_old ) ) != IVAS_ERR_OK ) { return error; } @@ -333,7 +335,7 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( tc_nchan_full_new = tc_nchan_tc_new; move16(); - IF ( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) { tc_nchan_allocate_new = 2 * BINAURAL_CHANNELS; move16(); @@ -341,24 +343,24 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( move16(); } - IF ( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) && ( NE_32( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) && NE_32( st_ivas->renderer_type, RENDERER_DISABLE ) && NE_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) && NE_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) ) + IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) && ( NE_32( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) && NE_32( st_ivas->renderer_type, RENDERER_DISABLE ) && NE_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) && NE_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) ) { tc_nchan_full_new = 0; move16(); } /* reconfigure buffer */ - IF ( NE_32( hTcBuffer->tc_buffer_mode, tc_buffer_mode_new ) || NE_16( hTcBuffer->nchan_transport_jbm, tc_nchan_tc_new ) || - NE_16( hTcBuffer->nchan_buffer_full, tc_nchan_full_new ) || NE_16( hTcBuffer->nchan_transport_internal, tc_nchan_allocate_new ) ) + IF( NE_32( hTcBuffer->tc_buffer_mode, tc_buffer_mode_new ) || NE_16( hTcBuffer->nchan_transport_jbm, tc_nchan_tc_new ) || + NE_16( hTcBuffer->nchan_buffer_full, tc_nchan_full_new ) || NE_16( hTcBuffer->nchan_transport_internal, tc_nchan_allocate_new ) ) { - IF ( ( error = ivas_jbm_dec_tc_buffer_reconfigure_fx( st_ivas, tc_buffer_mode_new, tc_nchan_tc_new, tc_nchan_allocate_new, tc_nchan_full_new, tc_granularity_new ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_jbm_dec_tc_buffer_reconfigure_fx( st_ivas, tc_buffer_mode_new, tc_nchan_tc_new, tc_nchan_allocate_new, tc_nchan_full_new, tc_granularity_new ) ) != IVAS_ERR_OK ) { return error; } } /* transfer subframe info from central tc buffer to ParamMC or McMASA (DirAC) */ - IF ( st_ivas->hSpatParamRendCom != NULL ) + IF( st_ivas->hSpatParamRendCom != NULL ) { st_ivas->hSpatParamRendCom->nb_subframes = st_ivas->hTcBuffer->nb_subframes; move16(); @@ -378,305 +380,303 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( #endif #ifndef IVAS_FLOAT_FIXED static ivas_error ivas_ism_bitrate_switching_dec( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const int16_t nchan_transport_old, /* i : last number of transport channels */ - const ISM_MODE last_ism_mode, /* i : last ISM mode */ - uint16_t *nSamplesRendered, /* o : number of samples rendered */ - int16_t *data /* o : output synthesis signal */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const int16_t nchan_transport_old, /* i : last number of transport channels */ + const ISM_MODE last_ism_mode, /* i : last ISM mode */ + uint16_t *nSamplesRendered, /* o : number of samples rendered */ + int16_t *data /* o : output synthesis signal */ ) { - ivas_error error; - int32_t element_brate_tmp[MAX_NUM_OBJECTS]; - int16_t nSCE_old, nCPE_old; - int16_t numCldfbAnalyses_old, numCldfbSyntheses_old, ism_mode; - TC_BUFFER_MODE tc_buffer_mode_new; - int16_t tc_nchan_tc_new; - int16_t tc_nchan_allocate_new; - int16_t tc_granularity_new; - int16_t nchan_out_buff, nchan_out_buff_old; - AUDIO_CONFIG intern_config_old; - IVAS_OUTPUT_SETUP hIntSetupOld; - RENDERER_TYPE renderer_type_old; - - error = IVAS_ERR_OK; - nCPE_old = st_ivas->nCPE; - nSCE_old = st_ivas->nSCE; - - /* temporarily set the ism mode back to the old one, otherwise this can give wrong results*/ - ism_mode = st_ivas->ism_mode; - st_ivas->ism_mode = last_ism_mode; - ivas_init_dec_get_num_cldfb_instances(st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old); - st_ivas->ism_mode = ism_mode; - nchan_out_buff_old = ivas_get_nchan_buffers_dec(st_ivas, -1, -1); - - if ((error = ivas_ism_config(st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->nchan_ism, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 0)) != IVAS_ERR_OK) - { - return error; - } - - st_ivas->nSCE = st_ivas->nchan_transport; - - /*-----------------------------------------------------------------* - * Allocate, initialize, and configure SCE/CPE/MCT handles - *-----------------------------------------------------------------*/ - - if ((error = ivas_corecoder_dec_reconfig(st_ivas, nSCE_old, nCPE_old, nchan_transport_old, 0, st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport, (st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport) * CPE_CHANNELS)) != IVAS_ERR_OK) - { - return error; - } - - /*-----------------------------------------------------------------* - * HP20 memories - *-----------------------------------------------------------------*/ - - if ((error = ivas_hp20_dec_reconfig(st_ivas, nchan_transport_old)) != IVAS_ERR_OK) - { - return error; - } + ivas_error error; + int32_t element_brate_tmp[MAX_NUM_OBJECTS]; + int16_t nSCE_old, nCPE_old; + int16_t numCldfbAnalyses_old, numCldfbSyntheses_old, ism_mode; + TC_BUFFER_MODE tc_buffer_mode_new; + int16_t tc_nchan_tc_new; + int16_t tc_nchan_allocate_new; + int16_t tc_granularity_new; + int16_t nchan_out_buff, nchan_out_buff_old; + AUDIO_CONFIG intern_config_old; + IVAS_OUTPUT_SETUP hIntSetupOld; + RENDERER_TYPE renderer_type_old; - /* save old IntSetup, might be needed for JBM flushing...*/ - intern_config_old = st_ivas->intern_config; - hIntSetupOld = st_ivas->hIntSetup; - tc_granularity_new = 1; - renderer_type_old = st_ivas->renderer_type; + error = IVAS_ERR_OK; + nCPE_old = st_ivas->nCPE; + nSCE_old = st_ivas->nSCE; - /*-----------------------------------------------------------------* - * Initialize the needed renderer struct and destroy the unnecessary renderer struct - *-----------------------------------------------------------------*/ + /* temporarily set the ism mode back to the old one, otherwise this can give wrong results*/ + ism_mode = st_ivas->ism_mode; + st_ivas->ism_mode = last_ism_mode; + ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old ); + st_ivas->ism_mode = ism_mode; + nchan_out_buff_old = ivas_get_nchan_buffers_dec( st_ivas, -1, -1 ); - /* select the renderer */ - ivas_renderer_select(st_ivas); + if ( ( error = ivas_ism_config( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->nchan_ism, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 0 ) ) != IVAS_ERR_OK ) + { + return error; + } - ivas_output_init(&(st_ivas->hIntSetup), st_ivas->intern_config); + st_ivas->nSCE = st_ivas->nchan_transport; - if ((st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC) && (st_ivas->ism_mode == ISM_MODE_DISC)) - { - ivas_output_init(&(st_ivas->hIntSetup), st_ivas->hDecoderConfig->output_config); - } + /*-----------------------------------------------------------------* + * Allocate, initialize, and configure SCE/CPE/MCT handles + *-----------------------------------------------------------------*/ - { - /* transfer subframe info from DirAC or ParamMC to central tc buffer */ - if (last_ism_mode == ISM_MODE_PARAM && st_ivas->hSpatParamRendCom != NULL && (st_ivas->renderer_type != RENDERER_MONO_DOWNMIX && st_ivas->renderer_type != RENDERER_DISABLE)) + if ( ( error = ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, 0, st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport, ( st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) { - st_ivas->hTcBuffer->nb_subframes = st_ivas->hSpatParamRendCom->nb_subframes; - st_ivas->hTcBuffer->subframes_rendered = st_ivas->hSpatParamRendCom->subframes_rendered; - st_ivas->hTcBuffer->num_slots = st_ivas->hSpatParamRendCom->num_slots; - st_ivas->hTcBuffer->slots_rendered = st_ivas->hSpatParamRendCom->slots_rendered; - mvs2s(st_ivas->hSpatParamRendCom->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS); + return error; } - /* JBM: when granularity goes down (e.g. Discrete ISM with TD Obj Renderer -> ParamISM with binaural fastconv - render what still fits in the new granularity */ - tc_granularity_new = ivas_jbm_dec_get_render_granularity_flt(st_ivas->renderer_type, st_ivas->ivas_format, st_ivas->mc_mode, st_ivas->hDecoderConfig->output_Fs); + /*-----------------------------------------------------------------* + * HP20 memories + *-----------------------------------------------------------------*/ - if (tc_granularity_new < st_ivas->hTcBuffer->n_samples_granularity) + if ( ( error = ivas_hp20_dec_reconfig( st_ivas, nchan_transport_old ) ) != IVAS_ERR_OK ) { - if ((error = ivas_jbm_dec_flush_renderer(st_ivas, tc_granularity_new, renderer_type_old, intern_config_old, &hIntSetupOld, MC_MODE_NONE, last_ism_mode, nSamplesRendered, data)) != IVAS_ERR_OK) - { return error; - } } - /* JBM: when granularity goes up set samples to discard at the beginning of the frame */ - else if (tc_granularity_new > st_ivas->hTcBuffer->n_samples_granularity) + + /* save old IntSetup, might be needed for JBM flushing...*/ + intern_config_old = st_ivas->intern_config; + hIntSetupOld = st_ivas->hIntSetup; + tc_granularity_new = 1; + renderer_type_old = st_ivas->renderer_type; + + /*-----------------------------------------------------------------* + * Initialize the needed renderer struct and destroy the unnecessary renderer struct + *-----------------------------------------------------------------*/ + + /* select the renderer */ + ivas_renderer_select( st_ivas ); + + ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config ); + + if ( ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC ) && ( st_ivas->ism_mode == ISM_MODE_DISC ) ) { - if ((error = ivas_jbm_dec_set_discard_samples(st_ivas)) != IVAS_ERR_OK) - { - return error; - } + ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->hDecoderConfig->output_config ); } - } - - if (st_ivas->ism_mode != last_ism_mode) - { - /* EFAP handle */ - efap_free_data(&st_ivas->hEFAPdata); - } - - /*-----------------------------------------------------------------* - * Switching between ParamISM and DiscISM - *-----------------------------------------------------------------*/ - - /* switching from ParamISM to DiscISM */ - if (st_ivas->ism_mode == ISM_MODE_DISC && last_ism_mode == ISM_MODE_PARAM) - { - /* Deallocate the ParamISM struct */ - ivas_param_ism_dec_close(&(st_ivas->hParamIsmDec), &(st_ivas->hSpatParamRendCom), st_ivas->hDecoderConfig->output_config); - - if (st_ivas->hOutSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL || st_ivas->hOutSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB - ) + { - /* close the parametric binaural renderer */ - ivas_dirac_dec_close_binaural_data(&st_ivas->hDiracDecBin); - /* Open the TD Binaural renderer */ - if (st_ivas->hHrtfTD == NULL || st_ivas->hBinRendererTd == NULL) - { - if ((error = ivas_td_binaural_open(st_ivas)) != IVAS_ERR_OK) + /* transfer subframe info from DirAC or ParamMC to central tc buffer */ + if ( last_ism_mode == ISM_MODE_PARAM && st_ivas->hSpatParamRendCom != NULL && ( st_ivas->renderer_type != RENDERER_MONO_DOWNMIX && st_ivas->renderer_type != RENDERER_DISABLE ) ) { - return error; + st_ivas->hTcBuffer->nb_subframes = st_ivas->hSpatParamRendCom->nb_subframes; + st_ivas->hTcBuffer->subframes_rendered = st_ivas->hSpatParamRendCom->subframes_rendered; + st_ivas->hTcBuffer->num_slots = st_ivas->hSpatParamRendCom->num_slots; + st_ivas->hTcBuffer->slots_rendered = st_ivas->hSpatParamRendCom->slots_rendered; + mvs2s( st_ivas->hSpatParamRendCom->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); } - if (st_ivas->hIntSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB) + + /* JBM: when granularity goes down (e.g. Discrete ISM with TD Obj Renderer -> ParamISM with binaural fastconv + render what still fits in the new granularity */ + tc_granularity_new = ivas_jbm_dec_get_render_granularity_flt( st_ivas->renderer_type, st_ivas->ivas_format, st_ivas->mc_mode, st_ivas->hDecoderConfig->output_Fs ); + + if ( tc_granularity_new < st_ivas->hTcBuffer->n_samples_granularity ) { - if ((error = ivas_reverb_open(&st_ivas->hReverb, st_ivas->hDecoderConfig->output_config, NULL, st_ivas->hBinRendererTd->HrFiltSet_p->lr_energy_and_iac, st_ivas->hRenderConfig, st_ivas->hDecoderConfig->output_Fs)) != IVAS_ERR_OK) - { - return error; - } + if ( ( error = ivas_jbm_dec_flush_renderer( st_ivas, tc_granularity_new, renderer_type_old, intern_config_old, &hIntSetupOld, MC_MODE_NONE, last_ism_mode, nSamplesRendered, data ) ) != IVAS_ERR_OK ) + { + return error; + } + } + /* JBM: when granularity goes up set samples to discard at the beginning of the frame */ + else if ( tc_granularity_new > st_ivas->hTcBuffer->n_samples_granularity ) + { + if ( ( error = ivas_jbm_dec_set_discard_samples( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } } - } - } - else - { - /* close the ISM renderer and reinitialize */ - ivas_ism_renderer_close(&st_ivas->hIsmRendererData); - - if ((error = ivas_ism_renderer_open(st_ivas)) != IVAS_ERR_OK) - { - return error; - } } - if (st_ivas->hOutSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR) + if ( st_ivas->ism_mode != last_ism_mode ) { - /* close the parametric binaural renderer */ - ivas_dirac_dec_close_binaural_data(&st_ivas->hDiracDecBin); - - /* Open Crend Binaural renderer */ - if ((error = ivas_rend_openCrend(&(st_ivas->hCrendWrapper), st_ivas->intern_config, st_ivas->hOutSetup.output_config, st_ivas->hRenderConfig, st_ivas->hSetOfHRTF, st_ivas->hDecoderConfig->output_Fs)) != IVAS_ERR_OK) - { - return error; - } - - st_ivas->binaural_latency_ns = st_ivas->hCrendWrapper->binaural_latency_ns; + /* EFAP handle */ + efap_free_data( &st_ivas->hEFAPdata ); } - } - /* switching from Discrete ISM to ParamISM */ - if (st_ivas->ism_mode == ISM_MODE_PARAM && last_ism_mode == ISM_MODE_DISC) - { - /* Allocate and initialize the ParamISM struct */ - if ((error = ivas_param_ism_dec_open(st_ivas)) != IVAS_ERR_OK) - { - return error; - } + /*-----------------------------------------------------------------* + * Switching between ParamISM and DiscISM + *-----------------------------------------------------------------*/ - if (st_ivas->hOutSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL || st_ivas->hOutSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB - ) + /* switching from ParamISM to DiscISM */ + if ( st_ivas->ism_mode == ISM_MODE_DISC && last_ism_mode == ISM_MODE_PARAM ) { - /* open the parametric binaural renderer */ - if ((error = ivas_dirac_dec_binaural_copy_hrtfs(&st_ivas->hHrtfParambin)) != IVAS_ERR_OK) - { - return error; - } + /* Deallocate the ParamISM struct */ + ivas_param_ism_dec_close( &( st_ivas->hParamIsmDec ), &( st_ivas->hSpatParamRendCom ), st_ivas->hDecoderConfig->output_config ); - if ((error = ivas_dirac_dec_init_binaural_data(st_ivas, st_ivas->hHrtfParambin)) != IVAS_ERR_OK) - { - return error; - } + if ( st_ivas->hOutSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL || st_ivas->hOutSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) + { + /* close the parametric binaural renderer */ + ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); + /* Open the TD Binaural renderer */ + if ( st_ivas->hHrtfTD == NULL || st_ivas->hBinRendererTd == NULL ) + { + if ( ( error = ivas_td_binaural_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + if ( st_ivas->hIntSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) + { + if ( ( error = ivas_reverb_open( &st_ivas->hReverb, st_ivas->hDecoderConfig->output_config, NULL, st_ivas->hBinRendererTd->HrFiltSet_p->lr_energy_and_iac, st_ivas->hRenderConfig, st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + } + else + { + /* close the ISM renderer and reinitialize */ + ivas_ism_renderer_close( &st_ivas->hIsmRendererData ); - /* Close the TD Binaural renderer */ - if (st_ivas->hBinRendererTd->HrFiltSet_p->ModelParams.modelROM == TRUE) - { - ivas_td_binaural_close(&st_ivas->hBinRendererTd); - st_ivas->hHrtfTD = NULL; + if ( ( error = ivas_ism_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } - if (st_ivas->hOutSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB) + if ( st_ivas->hOutSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) { - ivas_reverb_close(&st_ivas->hReverb); + /* close the parametric binaural renderer */ + ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); + + /* Open Crend Binaural renderer */ + if ( ( error = ivas_rend_openCrend( &( st_ivas->hCrendWrapper ), st_ivas->intern_config, st_ivas->hOutSetup.output_config, st_ivas->hRenderConfig, st_ivas->hSetOfHRTF, st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } + + st_ivas->binaural_latency_ns = st_ivas->hCrendWrapper->binaural_latency_ns; } - } - } - else - { - /* Close the ISM renderer */ - ivas_ism_renderer_close(&st_ivas->hIsmRendererData); } - if (st_ivas->hOutSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR) + /* switching from Discrete ISM to ParamISM */ + if ( st_ivas->ism_mode == ISM_MODE_PARAM && last_ism_mode == ISM_MODE_DISC ) { - /* open the parametric binaural renderer */ - if ((error = ivas_dirac_dec_binaural_copy_hrtfs(&st_ivas->hHrtfParambin)) != IVAS_ERR_OK) - { - return error; - } + /* Allocate and initialize the ParamISM struct */ + if ( ( error = ivas_param_ism_dec_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } - if ((error = ivas_dirac_dec_init_binaural_data(st_ivas, st_ivas->hHrtfParambin)) != IVAS_ERR_OK) - { - return error; - } + if ( st_ivas->hOutSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL || st_ivas->hOutSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) + { + /* open the parametric binaural renderer */ + if ( ( error = ivas_dirac_dec_binaural_copy_hrtfs( &st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) + { + return error; + } - /* close the crend binaural renderer */ - ivas_rend_closeCrend(&(st_ivas->hCrendWrapper)); - } - } + if ( ( error = ivas_dirac_dec_init_binaural_data( st_ivas, st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) + { + return error; + } - /*-----------------------------------------------------------------* - * CLDFB instances - *-----------------------------------------------------------------*/ + /* Close the TD Binaural renderer */ + if ( st_ivas->hBinRendererTd->HrFiltSet_p->ModelParams.modelROM == TRUE ) + { + ivas_td_binaural_close( &st_ivas->hBinRendererTd ); + st_ivas->hHrtfTD = NULL; - if ((error = ivas_cldfb_dec_reconfig(st_ivas, nchan_transport_old, numCldfbAnalyses_old, numCldfbSyntheses_old)) != IVAS_ERR_OK) - { - return error; - } + if ( st_ivas->hOutSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) + { + ivas_reverb_close( &st_ivas->hReverb ); + } + } + } + else + { + /* Close the ISM renderer */ + ivas_ism_renderer_close( &st_ivas->hIsmRendererData ); + } - /*-----------------------------------------------------------------* - * floating-point output audio buffers - *-----------------------------------------------------------------*/ + if ( st_ivas->hOutSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) + { + /* open the parametric binaural renderer */ + if ( ( error = ivas_dirac_dec_binaural_copy_hrtfs( &st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) + { + return error; + } - { - nchan_out_buff = ivas_get_nchan_buffers_dec(st_ivas, -1, -1); + if ( ( error = ivas_dirac_dec_init_binaural_data( st_ivas, st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) + { + return error; + } - if ((error = ivas_output_buff_dec(st_ivas->p_output_f, nchan_out_buff_old, nchan_out_buff)) != IVAS_ERR_OK) - { - return error; - } - } - - /*-----------------------------------------------------------------* - * JBM TC buffers - *-----------------------------------------------------------------*/ - { - int16_t tc_nchan_full_new; - DECODER_TC_BUFFER_HANDLE hTcBuffer; - - hTcBuffer = st_ivas->hTcBuffer; - tc_buffer_mode_new = ivas_jbm_dec_get_tc_buffer_mode(st_ivas); - tc_nchan_tc_new = ivas_jbm_dec_get_num_tc_channels(st_ivas); - tc_nchan_allocate_new = tc_nchan_tc_new; - tc_nchan_full_new = tc_nchan_tc_new; - - if (st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC) - { - tc_nchan_allocate_new = 2 * BINAURAL_CHANNELS; - tc_nchan_full_new = tc_nchan_allocate_new; + /* close the crend binaural renderer */ + ivas_rend_closeCrend( &( st_ivas->hCrendWrapper ) ); + } } - if (st_ivas->ism_mode == ISM_MODE_PARAM && (st_ivas->renderer_type != RENDERER_MONO_DOWNMIX && st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC && st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM)) + /*-----------------------------------------------------------------* + * CLDFB instances + *-----------------------------------------------------------------*/ + + if ( ( error = ivas_cldfb_dec_reconfig( st_ivas, nchan_transport_old, numCldfbAnalyses_old, numCldfbSyntheses_old ) ) != IVAS_ERR_OK ) { - tc_nchan_full_new = 0; + return error; } - /* reconfigure buffer */ - if (hTcBuffer->tc_buffer_mode != tc_buffer_mode_new || hTcBuffer->nchan_transport_jbm != tc_nchan_tc_new || - hTcBuffer->nchan_buffer_full != tc_nchan_full_new || hTcBuffer->nchan_transport_internal != tc_nchan_allocate_new) + /*-----------------------------------------------------------------* + * floating-point output audio buffers + *-----------------------------------------------------------------*/ + { - if ((error = ivas_jbm_dec_tc_buffer_reconfigure(st_ivas, tc_buffer_mode_new, tc_nchan_tc_new, tc_nchan_allocate_new, tc_nchan_full_new, tc_granularity_new)) != IVAS_ERR_OK) - { - return error; - } + nchan_out_buff = ivas_get_nchan_buffers_dec( st_ivas, -1, -1 ); + + if ( ( error = ivas_output_buff_dec( st_ivas->p_output_f, nchan_out_buff_old, nchan_out_buff ) ) != IVAS_ERR_OK ) + { + return error; + } } - /* transfer subframe info from central tc buffer to ParamMC or McMASA (DirAC) */ - if (st_ivas->hSpatParamRendCom != NULL) + /*-----------------------------------------------------------------* + * JBM TC buffers + *-----------------------------------------------------------------*/ { - st_ivas->hSpatParamRendCom->nb_subframes = st_ivas->hTcBuffer->nb_subframes; - st_ivas->hSpatParamRendCom->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered; - st_ivas->hSpatParamRendCom->num_slots = st_ivas->hTcBuffer->num_slots; - st_ivas->hSpatParamRendCom->slots_rendered = st_ivas->hTcBuffer->slots_rendered; + int16_t tc_nchan_full_new; + DECODER_TC_BUFFER_HANDLE hTcBuffer; - mvs2s(st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hSpatParamRendCom->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS); + hTcBuffer = st_ivas->hTcBuffer; + tc_buffer_mode_new = ivas_jbm_dec_get_tc_buffer_mode( st_ivas ); + tc_nchan_tc_new = ivas_jbm_dec_get_num_tc_channels( st_ivas ); + tc_nchan_allocate_new = tc_nchan_tc_new; + tc_nchan_full_new = tc_nchan_tc_new; + + if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) + { + tc_nchan_allocate_new = 2 * BINAURAL_CHANNELS; + tc_nchan_full_new = tc_nchan_allocate_new; + } + + if ( st_ivas->ism_mode == ISM_MODE_PARAM && ( st_ivas->renderer_type != RENDERER_MONO_DOWNMIX && st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC && st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) + { + tc_nchan_full_new = 0; + } + + /* reconfigure buffer */ + if ( hTcBuffer->tc_buffer_mode != tc_buffer_mode_new || hTcBuffer->nchan_transport_jbm != tc_nchan_tc_new || + hTcBuffer->nchan_buffer_full != tc_nchan_full_new || hTcBuffer->nchan_transport_internal != tc_nchan_allocate_new ) + { + if ( ( error = ivas_jbm_dec_tc_buffer_reconfigure( st_ivas, tc_buffer_mode_new, tc_nchan_tc_new, tc_nchan_allocate_new, tc_nchan_full_new, tc_granularity_new ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + /* transfer subframe info from central tc buffer to ParamMC or McMASA (DirAC) */ + if ( st_ivas->hSpatParamRendCom != NULL ) + { + st_ivas->hSpatParamRendCom->nb_subframes = st_ivas->hTcBuffer->nb_subframes; + st_ivas->hSpatParamRendCom->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered; + st_ivas->hSpatParamRendCom->num_slots = st_ivas->hTcBuffer->num_slots; + st_ivas->hSpatParamRendCom->slots_rendered = st_ivas->hTcBuffer->slots_rendered; + + mvs2s( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hSpatParamRendCom->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); + } } - } - return error; + return error; } #endif @@ -732,7 +732,7 @@ ivas_error ivas_ism_dec_config_fx( IF( ( NE_16( st_ivas->ism_mode, last_ism_mode ) ) || ( NE_32( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate ) ) ) { IF( NE_16( ( error = ivas_ism_bitrate_switching_dec_fx( st_ivas, nchan_transport_old, last_ism_mode, nSamplesRendered, - data ) ), + data ) ), IVAS_ERR_OK ) ) { return error; @@ -757,7 +757,7 @@ ivas_error ivas_ism_dec_config_fx( IF( NE_16( st_ivas->ism_mode, last_ism_mode ) ) { IF( NE_16( ( error = ivas_ism_bitrate_switching_dec_fx( st_ivas, nchan_transport_old, last_ism_mode, nSamplesRendered, - data ) ), + data ) ), IVAS_ERR_OK ) ) { return error; @@ -791,7 +791,7 @@ ivas_error ivas_ism_dec_config( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const ISM_MODE last_ism_mode, /* i/o: last ISM mode */ uint16_t *nSamplesRendered, /* o : number of samples flushed when the renderer granularity changes */ - int16_t *data /* o : output synthesis signal */ + int16_t *data /* o : output synthesis signal */ ) { int32_t ivas_total_brate; @@ -884,4 +884,4 @@ ivas_error ivas_ism_dec_config( return error; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/ivas_ism_dtx_dec.c b/lib_dec/ivas_ism_dtx_dec.c index 0e22492ac..2fd8bf77b 100644 --- a/lib_dec/ivas_ism_dtx_dec.c +++ b/lib_dec/ivas_ism_dtx_dec.c @@ -49,7 +49,7 @@ *-------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED void ivas_ism_dtx_dec_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ Word16 *nb_bits_metadata /* o : number of metadata bits */ ) { @@ -65,7 +65,7 @@ void ivas_ism_dtx_dec_fx( nchan_ism_prev = st_ivas->nchan_ism; move16(); - IF ( !st_ivas->bfi && EQ_32(ivas_total_brate , IVAS_SID_5k2) ) + IF( !st_ivas->bfi && EQ_32( ivas_total_brate, IVAS_SID_5k2 ) ) { /* 'nchan_ism' was read in ivas_dec_setup() */ nchan_ism = st_ivas->nchan_ism; @@ -82,9 +82,9 @@ void ivas_ism_dtx_dec_fx( ivas_ism_metadata_sid_dec_fx( st_ivas->hSCE, ivas_total_brate, st_ivas->bfi, nchan_ism, st_ivas->nchan_transport, st_ivas->ism_mode, &flag_noisy_speech, &sce_id_dtx, st_ivas->hIsmMetaData, nb_bits_metadata ); - IF ( EQ_32(ivas_total_brate , IVAS_SID_5k2) && !st_ivas->bfi ) + IF( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) && !st_ivas->bfi ) { - IF ( st_ivas->hParamIsmDec != NULL ) + IF( st_ivas->hParamIsmDec != NULL ) { st_ivas->hParamIsmDec->hParamIsm->flag_noisy_speech = flag_noisy_speech; move16(); @@ -96,9 +96,9 @@ void ivas_ism_dtx_dec_fx( set16_fx( md_diff_flag, 1, nchan_ism ); - IF ( EQ_16(st_ivas->ism_mode , ISM_MODE_PARAM) ) + IF( EQ_16( st_ivas->ism_mode, ISM_MODE_PARAM ) ) { - FOR ( ch = 0; ch < nchan_ism; ch++ ) + FOR( ch = 0; ch < nchan_ism; ch++ ) { st_ivas->hParamIsmDec->azimuth_values_fx[ch] = st_ivas->hIsmMetaData[ch]->azimuth_fx; st_ivas->hParamIsmDec->elevation_values_fx[ch] = st_ivas->hIsmMetaData[ch]->elevation_fx; @@ -107,9 +107,9 @@ void ivas_ism_dtx_dec_fx( } } /* synch common seed between SCEs */ - IF ( EQ_16(st_ivas->ism_mode , ISM_MODE_DISC) ) + IF( EQ_16( st_ivas->ism_mode, ISM_MODE_DISC ) ) { - FOR ( ch = 0; ch < nchan_ism; ++ch ) + FOR( ch = 0; ch < nchan_ism; ++ch ) { st_ivas->hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->seed = st_ivas->hSCE[st_ivas->hISMDTX.sce_id_dtx]->hCoreCoder[0]->hFdCngDec->hFdCngCom->seed; move16(); @@ -121,18 +121,18 @@ void ivas_ism_dtx_dec_fx( st_ivas->hISMDTX.ism_dtx_hangover_cnt = 0; move16(); - IF ( EQ_32(ivas_total_brate , IVAS_SID_5k2) && !st_ivas->bfi ) + IF( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) && !st_ivas->bfi ) { - FOR ( ch = 0; ch < st_ivas->nchan_transport; ch++ ) + FOR( ch = 0; ch < st_ivas->nchan_transport; ch++ ) { nb_bits_metadata[ch] = nb_bits_metadata[sce_id_dtx]; move16(); } } - IF ( !st_ivas->bfi ) + IF( !st_ivas->bfi ) { - FOR ( ch = 0; ch < st_ivas->nchan_transport; ch++ ) + FOR( ch = 0; ch < st_ivas->nchan_transport; ch++ ) { st = st_ivas->hSCE[ch]->hCoreCoder[0]; st->bit_stream = st_ivas->hSCE[0]->hCoreCoder[0]->bit_stream; @@ -256,34 +256,34 @@ void ivas_ism_dtx_limit_noise_energy_for_near_silence_fx( Word16 ch, cng_noise_level_len, Q_cng_noise_nrg_dominant, Q_fac; HANDLE_FD_CNG_COM hFdCngCom; hFdCngCom = hSCE[sce_id_dtx]->hCoreCoder[0]->hFdCngDec->hFdCngCom; - cng_noise_level_len = sub(hFdCngCom->stopFFTbin , hFdCngCom->startBand); - Q_cng_noise_nrg_dominant = add(Q_cngNoiseLevel[sce_id_dtx] , Q_cngNoiseLevel[sce_id_dtx]);/*stores Q for cng_noise_nrg_dominant_fx*/ - cng_noise_nrg_dominant_fx = dotp_fixed_o( hFdCngCom->cngNoiseLevel, hFdCngCom->cngNoiseLevel, cng_noise_level_len, 9 /*log2(len(hFdCngCom->cngNoiseLevel))*/, &Q_cng_noise_nrg_dominant );/*Resultant Q_cng_noise_nrg_dominant= (Q_cng_noise_nrg_dominant-x)<=31*/ - IF ( LT_32(cng_noise_nrg_dominant_fx , L_shl_sat(1, Q_cng_noise_nrg_dominant)))/*cng_noise_nrg_dominant<1.f*/ + cng_noise_level_len = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); + Q_cng_noise_nrg_dominant = add( Q_cngNoiseLevel[sce_id_dtx], Q_cngNoiseLevel[sce_id_dtx] ); /*stores Q for cng_noise_nrg_dominant_fx*/ + cng_noise_nrg_dominant_fx = dotp_fixed_o( hFdCngCom->cngNoiseLevel, hFdCngCom->cngNoiseLevel, cng_noise_level_len, 9 /*log2(len(hFdCngCom->cngNoiseLevel))*/, &Q_cng_noise_nrg_dominant ); /*Resultant Q_cng_noise_nrg_dominant= (Q_cng_noise_nrg_dominant-x)<=31*/ + IF( LT_32( cng_noise_nrg_dominant_fx, L_shl_sat( 1, Q_cng_noise_nrg_dominant ) ) ) /*cng_noise_nrg_dominant<1.f*/ { - FOR ( ch = 0; ch < nchan_transport; ch++ ) + FOR( ch = 0; ch < nchan_transport; ch++ ) { - IF ( EQ_16(ch , sce_id_dtx) ) + IF( EQ_16( ch, sce_id_dtx ) ) { continue; } hFdCngCom = hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom; - cng_noise_level_len = sub(hFdCngCom->stopFFTbin , hFdCngCom->startBand); - Word16 Q_cng_noise_nrg_obj = add(Q_cngNoiseLevel[ch] , Q_cngNoiseLevel[ch]);/*Stores Q-factor of cng_noise_nrg_obj*/ - cng_noise_nrg_obj_fx = dotp_fixed_o( hFdCngCom->cngNoiseLevel, hFdCngCom->cngNoiseLevel, cng_noise_level_len, 9, &Q_cng_noise_nrg_obj );/*Resultant Q_cng_noise_nrg_obj= (Q_cng_noise_nrg_obj-x)<=31*/ - IF( GT_32(cng_noise_nrg_obj_fx , cng_noise_nrg_dominant_fx) ) + cng_noise_level_len = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); + Word16 Q_cng_noise_nrg_obj = add( Q_cngNoiseLevel[ch], Q_cngNoiseLevel[ch] ); /*Stores Q-factor of cng_noise_nrg_obj*/ + cng_noise_nrg_obj_fx = dotp_fixed_o( hFdCngCom->cngNoiseLevel, hFdCngCom->cngNoiseLevel, cng_noise_level_len, 9, &Q_cng_noise_nrg_obj ); /*Resultant Q_cng_noise_nrg_obj= (Q_cng_noise_nrg_obj-x)<=31*/ + IF( GT_32( cng_noise_nrg_obj_fx, cng_noise_nrg_dominant_fx ) ) { - Word32 temp = divide3232( L_shr( cng_noise_nrg_dominant_fx, 1 ), cng_noise_nrg_obj_fx );/*Stores value of cng_noise_nrg_dominant_fx/cng_noise_nrg_obj_fx*/ - Word16 Q_temp = Q_cng_noise_nrg_dominant - 1 - Q_cng_noise_nrg_obj + 15;/*Stores resultant Q after divide3232 operation above*/ - IF (Q_temp % 2 == 1 )/*Making Q_temp even for sqrt function*/ + Word32 temp = divide3232( L_shr( cng_noise_nrg_dominant_fx, 1 ), cng_noise_nrg_obj_fx ); /*Stores value of cng_noise_nrg_dominant_fx/cng_noise_nrg_obj_fx*/ + Word16 Q_temp = Q_cng_noise_nrg_dominant - 1 - Q_cng_noise_nrg_obj + 15; /*Stores resultant Q after divide3232 operation above*/ + IF( Q_temp % 2 == 1 ) /*Making Q_temp even for sqrt function*/ { - Q_temp = sub(Q_temp , 1); + Q_temp = sub( Q_temp, 1 ); temp = L_shr( temp, 1 ); } - fac_fx = getSqrtWord32(temp);/*Resultant Q=Q_temp/2*/ + fac_fx = getSqrtWord32( temp ); /*Resultant Q=Q_temp/2*/ Q_fac = shr( Q_temp, 1 ); - v_multc_fixed( hFdCngCom->cngNoiseLevel, fac_fx, hFdCngCom->cngNoiseLevel, cng_noise_level_len );/*Resultant Q of cngNoiseLevel is Q_cngNoiseLevel for ch*/ - scale_sig32( hFdCngCom->cngNoiseLevel, cng_noise_level_len, negate(31 - Q_fac) );/*Restoring Q of hFdCngCom->cngNoiseLevel to Q_cngNoiseLevel */ + v_multc_fixed( hFdCngCom->cngNoiseLevel, fac_fx, hFdCngCom->cngNoiseLevel, cng_noise_level_len ); /*Resultant Q of cngNoiseLevel is Q_cngNoiseLevel for ch*/ + scale_sig32( hFdCngCom->cngNoiseLevel, cng_noise_level_len, negate( 31 - Q_fac ) ); /*Restoring Q of hFdCngCom->cngNoiseLevel to Q_cngNoiseLevel */ } } } diff --git a/lib_dec/ivas_ism_param_dec.c b/lib_dec/ivas_ism_param_dec.c index f733f38c5..6d540c937 100644 --- a/lib_dec/ivas_ism_param_dec.c +++ b/lib_dec/ivas_ism_param_dec.c @@ -726,7 +726,7 @@ static ivas_error ivas_param_ism_rendering_init_fx( /* memory allocation for proto matrix and interpolator */ #ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED - IF ( ( hParamIsmRendering->proto_matrix = (float *) malloc( hOutSetup.nchan_out_woLFE * nchan_transport * sizeof( float ) ) ) == NULL ) + IF( ( hParamIsmRendering->proto_matrix = (float *) malloc( hOutSetup.nchan_out_woLFE * nchan_transport * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for proto matrix\n" ) ); } @@ -750,7 +750,7 @@ static ivas_error ivas_param_ism_rendering_init_fx( ivas_ism_get_proto_matrix_fx( hOutSetup, nchan_transport, hParamIsmRendering->proto_matrix_fx ); #ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED - FOR ( Word16 idx = 0; idx < hOutSetup.nchan_out_woLFE; idx++ ) + FOR( Word16 idx = 0; idx < hOutSetup.nchan_out_woLFE; idx++ ) { hParamIsmRendering->proto_matrix[idx] = (float) hParamIsmRendering->proto_matrix_fx[idx] / ( 1 << 15 ); hParamIsmRendering->proto_matrix[idx + hOutSetup.nchan_out_woLFE] = (float) hParamIsmRendering->proto_matrix_fx[idx + hOutSetup.nchan_out_woLFE] / ( 1 << 15 ); @@ -896,23 +896,23 @@ ivas_error ivas_param_ism_dec_open_fx( * prepare library opening *-----------------------------------------------------------------*/ - IF ( ( hParamIsmDec = (PARAM_ISM_DEC_HANDLE) malloc( sizeof( PARAM_ISM_DEC_DATA ) ) ) == NULL ) + IF( ( hParamIsmDec = (PARAM_ISM_DEC_HANDLE) malloc( sizeof( PARAM_ISM_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ParamISM\n" ) ); } - IF ( ( hSpatParamRendCom = (SPAT_PARAM_REND_COMMON_DATA_HANDLE) malloc( sizeof( SPAT_PARAM_REND_COMMON_DATA ) ) ) == NULL ) + IF( ( hSpatParamRendCom = (SPAT_PARAM_REND_COMMON_DATA_HANDLE) malloc( sizeof( SPAT_PARAM_REND_COMMON_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } /* Assign memory to Param Object handle */ - IF ( ( hParamIsmDec->hParamIsm = (PARAM_ISM_CONFIG_HANDLE) malloc( sizeof( PARAM_ISM_CONFIG_DATA ) ) ) == NULL ) + IF( ( hParamIsmDec->hParamIsm = (PARAM_ISM_CONFIG_HANDLE) malloc( sizeof( PARAM_ISM_CONFIG_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ParamISM\n" ) ); } - IF ( ( hParamIsmDec->hParamIsmRendering = (PARAM_ISM_RENDERING_HANDLE) malloc( sizeof( PARAM_ISM_RENDERING_DATA ) ) ) == NULL ) + IF( ( hParamIsmDec->hParamIsmRendering = (PARAM_ISM_RENDERING_HANDLE) malloc( sizeof( PARAM_ISM_RENDERING_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ParamISM Rendering handle\n" ) ); } @@ -928,7 +928,7 @@ ivas_error ivas_param_ism_dec_open_fx( *-----------------------------------------------------------------*/ tmp = BASOP_Util_Divide3232_Scale( output_Fs, CLDFB_BANDWIDTH, &scale ); // FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX ); - hSpatParamRendCom->slot_size = shr(tmp, 15 - scale); + hSpatParamRendCom->slot_size = shr( tmp, 15 - scale ); set_s( hSpatParamRendCom->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS ); set_s( hSpatParamRendCom->subframe_nbslots, JBM_CLDFB_SLOTS_IN_SUBFRAME, DEFAULT_JBM_SUBFRAMES_5MS ); hSpatParamRendCom->nb_subframes = DEFAULT_JBM_SUBFRAMES_5MS; @@ -939,16 +939,16 @@ ivas_error ivas_param_ism_dec_open_fx( hSpatParamRendCom->num_slots = DEFAULT_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME; tmp = BASOP_Util_Divide3232_Scale( output_Fs, CLDFB_BANDWIDTH, &scale ); - hSpatParamRendCom->num_freq_bands = shr(tmp, 15 - scale ); + hSpatParamRendCom->num_freq_bands = shr( tmp, 15 - scale ); hParamIsmDec->hParamIsm->nbands = MAX_PARAM_ISM_NBANDS; - FOR ( i = 0; i < ( hParamIsmDec->hParamIsm->nbands + 1 ); i++ ) + FOR( i = 0; i < ( hParamIsmDec->hParamIsm->nbands + 1 ); i++ ) { hParamIsmDec->hParamIsm->band_grouping[i] = Param_ISM_band_grouping[i]; move16(); - IF ( GT_16( hParamIsmDec->hParamIsm->band_grouping[i], hSpatParamRendCom->num_freq_bands ) ) + IF( GT_16( hParamIsmDec->hParamIsm->band_grouping[i], hSpatParamRendCom->num_freq_bands ) ) { hParamIsmDec->hParamIsm->band_grouping[i] = hSpatParamRendCom->num_freq_bands; move16(); @@ -960,7 +960,7 @@ ivas_error ivas_param_ism_dec_open_fx( *-----------------------------------------------------------------*/ /* hIntSetup and hOutSetup differs only for Binaural rendering */ - IF ( EQ_16( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) + IF( EQ_16( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) { /* nchan_out is essential for memory initialization for CLDFB Synthesis */ st_ivas->hIntSetup.nchan_out_woLFE = st_ivas->nchan_ism; @@ -971,31 +971,35 @@ ivas_error ivas_param_ism_dec_open_fx( hOutSetup = st_ivas->hIntSetup; test(); - IF ( !( EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) ) + IF( !( EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) ) { /* Initialize Param ISM Rendering handle */ - IF ( st_ivas->hDecoderConfig->Opt_tsm ) + IF( st_ivas->hDecoderConfig->Opt_tsm ) { - IF ( ( error = ivas_param_ism_rendering_init_fx( hParamIsmDec->hParamIsmRendering, hOutSetup, st_ivas->nchan_transport, MAX_JBM_CLDFB_TIMESLOTS, output_config ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_param_ism_rendering_init_fx( hParamIsmDec->hParamIsmRendering, hOutSetup, st_ivas->nchan_transport, MAX_JBM_CLDFB_TIMESLOTS, output_config ) ) != IVAS_ERR_OK ) { return error; } } ELSE { - IF ( ( error = ivas_param_ism_rendering_init_fx( hParamIsmDec->hParamIsmRendering, hOutSetup, st_ivas->nchan_transport, CLDFB_NO_COL_MAX, output_config ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_param_ism_rendering_init_fx( hParamIsmDec->hParamIsmRendering, hOutSetup, st_ivas->nchan_transport, CLDFB_NO_COL_MAX, output_config ) ) != IVAS_ERR_OK ) { return error; } } } - test(); test(); test(); test(); test(); - IF ( !( output_config == IVAS_AUDIO_CONFIG_EXTERNAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB || - output_config == IVAS_AUDIO_CONFIG_MONO || output_config == IVAS_AUDIO_CONFIG_STEREO ) ) + test(); + test(); + test(); + test(); + test(); + IF( !( output_config == IVAS_AUDIO_CONFIG_EXTERNAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB || + output_config == IVAS_AUDIO_CONFIG_MONO || output_config == IVAS_AUDIO_CONFIG_STEREO ) ) { /* Initialize efap handle */ - IF ( ( error = efap_init_data_fx( &( st_ivas->hEFAPdata ), hOutSetup.ls_azimuth_fx, hOutSetup.ls_elevation_fx, hOutSetup.nchan_out_woLFE, EFAP_MODE_EFAP ) ) != IVAS_ERR_OK ) + IF( ( error = efap_init_data_fx( &( st_ivas->hEFAPdata ), hOutSetup.ls_azimuth_fx, hOutSetup.ls_elevation_fx, hOutSetup.nchan_out_woLFE, EFAP_MODE_EFAP ) ) != IVAS_ERR_OK ) { return error; } @@ -1013,15 +1017,16 @@ ivas_error ivas_param_ism_dec_open_fx( hSpatParamRendCom->dirac_read_idx = 0; move16(); - test(); test(); - IF ( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) + test(); + test(); + IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { - IF ( ( error = ivas_dirac_allocate_parameters_fx( hSpatParamRendCom, 1 ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_dirac_allocate_parameters_fx( hSpatParamRendCom, 1 ) ) != IVAS_ERR_OK ) { return error; } - IF ( ( error = ivas_dirac_allocate_parameters_fx( hSpatParamRendCom, 2 ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_dirac_allocate_parameters_fx( hSpatParamRendCom, 2 ) ) != IVAS_ERR_OK ) { return error; } @@ -1034,93 +1039,93 @@ ivas_error ivas_param_ism_dec_open_fx( st_ivas->hSpatParamRendCom = hSpatParamRendCom; + test(); + IF( NE_32( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) && NE_32( st_ivas->renderer_type, RENDERER_DISABLE ) ) + { + Word16 nchan_transport = st_ivas->nchan_transport; + move16(); + Word16 nchan_full = 0; + move16(); + test(); - IF ( NE_32( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) && NE_32( st_ivas->renderer_type, RENDERER_DISABLE ) ) + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) { - Word16 nchan_transport = st_ivas->nchan_transport; - move16(); - Word16 nchan_full = 0; - move16(); - - test(); - IF ( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) - { - nchan_full = nchan_transport; + nchan_full = nchan_transport; #ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED - hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc = NULL; - hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc = NULL; + hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc = NULL; + hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc = NULL; #endif - hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx = NULL; - hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx = NULL; + hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx = NULL; + hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx = NULL; + } + ELSE + { + Word16 n_slots_to_alloc; + IF( EQ_16( st_ivas->hDecoderConfig->Opt_tsm, 1 ) ) + { + n_slots_to_alloc = MAX_JBM_CLDFB_TIMESLOTS; + move16(); } ELSE { - Word16 n_slots_to_alloc; - IF ( EQ_16( st_ivas->hDecoderConfig->Opt_tsm, 1 ) ) - { - n_slots_to_alloc = MAX_JBM_CLDFB_TIMESLOTS; - move16(); - } - ELSE - { - n_slots_to_alloc = CLDFB_SLOTS_PER_SUBFRAME * MAX_PARAM_SPATIAL_SUBFRAMES; - move16(); - } + n_slots_to_alloc = CLDFB_SLOTS_PER_SUBFRAME * MAX_PARAM_SPATIAL_SUBFRAMES; + move16(); + } #ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED - IF ( ( hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc = (float *) malloc( n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands * sizeof( float ) ) ) == NULL ) + IF( ( hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc = (float *) malloc( n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param ISM JBM Rendering handle\n" ) ); - } - set_zero( hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc, n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands ); + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param ISM JBM Rendering handle\n" ) ); + } + set_zero( hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc, n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands ); - IF ( ( hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc = (float *) malloc( n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param ISM JBM Rendering handle\n" ) ); - } - set_zero( hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc, n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands ); + IF( ( hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc = (float *) malloc( n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param ISM JBM Rendering handle\n" ) ); + } + set_zero( hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc, n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands ); #endif - IF( ( hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx = (Word32 *) malloc( n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands * sizeof( Word32 ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param ISM JBM Rendering handle\n" ) ); - } - set32_fx( hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx, 0, n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands ); - - IF( ( hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx = (Word32 *) malloc( n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands * sizeof( Word32 ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param ISM JBM Rendering handle\n" ) ); - } - set32_fx( hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx, 0, n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands ); + IF( ( hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx = (Word32 *) malloc( n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands * sizeof( Word32 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param ISM JBM Rendering handle\n" ) ); } + set32_fx( hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx, 0, n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands ); - IF ( st_ivas->hTcBuffer == NULL ) + IF( ( hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx = (Word32 *) malloc( n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands * sizeof( Word32 ) ) ) == NULL ) { - IF ( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_RENDERER, nchan_transport, nchan_transport, nchan_full, NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ) != IVAS_ERR_OK ) - - { - return error; - } + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param ISM JBM Rendering handle\n" ) ); } + set32_fx( hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx, 0, n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands ); } - ELSE + + IF( st_ivas->hTcBuffer == NULL ) { + IF( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_RENDERER, nchan_transport, nchan_transport, nchan_full, NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ) != IVAS_ERR_OK ) + + { + return error; + } + } + } + ELSE + { #ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED - hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc = NULL; - hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc = NULL; + hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc = NULL; + hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc = NULL; #endif - hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx = NULL; - hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx = NULL; - IF ( st_ivas->hTcBuffer == NULL ) + hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx = NULL; + hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx = NULL; + IF( st_ivas->hTcBuffer == NULL ) + { + Word16 nchan_to_allocate = st_ivas->hDecoderConfig->nchan_out; + move16(); + IF( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_BUFFER, nchan_to_allocate, nchan_to_allocate, nchan_to_allocate, NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ) != IVAS_ERR_OK ) { - Word16 nchan_to_allocate = st_ivas->hDecoderConfig->nchan_out; - move16(); - IF ( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_BUFFER, nchan_to_allocate, nchan_to_allocate, nchan_to_allocate, NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ) != IVAS_ERR_OK ) - { - return error; - } + return error; } } + } pop_wmops(); return error; @@ -1267,63 +1272,63 @@ ivas_error ivas_param_ism_dec_open( st_ivas->hSpatParamRendCom = hSpatParamRendCom; - if ( st_ivas->renderer_type != RENDERER_MONO_DOWNMIX && st_ivas->renderer_type != RENDERER_DISABLE ) - { - int16_t nchan_transport = st_ivas->nchan_transport; - int16_t nchan_full = 0; + if ( st_ivas->renderer_type != RENDERER_MONO_DOWNMIX && st_ivas->renderer_type != RENDERER_DISABLE ) + { + int16_t nchan_transport = st_ivas->nchan_transport; + int16_t nchan_full = 0; - if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) + if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) + { + nchan_full = nchan_transport; + hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc = NULL; + hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc = NULL; + } + else + { + int16_t n_slots_to_alloc; + if ( st_ivas->hDecoderConfig->Opt_tsm == 1 ) { - nchan_full = nchan_transport; - hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc = NULL; - hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc = NULL; + n_slots_to_alloc = MAX_JBM_CLDFB_TIMESLOTS; } else { - int16_t n_slots_to_alloc; - if ( st_ivas->hDecoderConfig->Opt_tsm == 1 ) - { - n_slots_to_alloc = MAX_JBM_CLDFB_TIMESLOTS; - } - else - { - n_slots_to_alloc = CLDFB_SLOTS_PER_SUBFRAME * MAX_PARAM_SPATIAL_SUBFRAMES; - } - if ( ( hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc = (float *) malloc( n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands * sizeof( float ) ) ) == NULL ) + n_slots_to_alloc = CLDFB_SLOTS_PER_SUBFRAME * MAX_PARAM_SPATIAL_SUBFRAMES; + } + if ( ( hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc = (float *) malloc( n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param ISM JBM Rendering handle\n" ) ); - } - set_zero( hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc, n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands ); + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param ISM JBM Rendering handle\n" ) ); + } + set_zero( hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc, n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands ); - if ( ( hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc = (float *) malloc( n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param ISM JBM Rendering handle\n" ) ); - } - set_zero( hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc, n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands ); + if ( ( hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc = (float *) malloc( n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param ISM JBM Rendering handle\n" ) ); } + set_zero( hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc, n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands ); + } - if ( st_ivas->hTcBuffer == NULL ) + if ( st_ivas->hTcBuffer == NULL ) + { + if ( ( error = ivas_jbm_dec_tc_buffer_open( st_ivas, TC_BUFFER_MODE_RENDERER, nchan_transport, nchan_transport, nchan_full, NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ) != IVAS_ERR_OK ) { - if ( ( error = ivas_jbm_dec_tc_buffer_open( st_ivas, TC_BUFFER_MODE_RENDERER, nchan_transport, nchan_transport, nchan_full, NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ) != IVAS_ERR_OK ) - { - return error; - } + return error; } } - else + } + else + { + hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc = NULL; + hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc = NULL; + if ( st_ivas->hTcBuffer == NULL ) { - hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc = NULL; - hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc = NULL; - if ( st_ivas->hTcBuffer == NULL ) + int16_t nchan_to_allocate = st_ivas->hDecoderConfig->nchan_out; + if ( ( error = ivas_jbm_dec_tc_buffer_open( st_ivas, TC_BUFFER_MODE_BUFFER, nchan_to_allocate, nchan_to_allocate, nchan_to_allocate, NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ) != IVAS_ERR_OK ) { - int16_t nchan_to_allocate = st_ivas->hDecoderConfig->nchan_out; - if ( ( error = ivas_jbm_dec_tc_buffer_open( st_ivas, TC_BUFFER_MODE_BUFFER, nchan_to_allocate, nchan_to_allocate, nchan_to_allocate, NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ) != IVAS_ERR_OK ) - { - return error; - } + return error; } } + } pop_wmops(); return error; @@ -1710,7 +1715,7 @@ void ivas_param_ism_dec( } cldfbSynthesis_ivas( RealBuffer, ImagBuffer, &( output_f[ch][slot_idx_start * hSpatParamRendCom->num_freq_bands] ), - hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->subframe_nbslots[subframe_idx], st_ivas->cldfbSynDec[ch] ); + hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->subframe_nbslots[subframe_idx], st_ivas->cldfbSynDec[ch] ); idx_in++; } @@ -1820,7 +1825,7 @@ void ivas_ism_dec_digest_tc_fx( IF( st_ivas->intern_config == IVAS_AUDIO_CONFIG_STEREO ) { Word16 gains_fx[2]; - ivas_ism_get_stereo_gains_fx( (Word16) L_shr(st_ivas->hIsmMetaData[i]->azimuth_fx, 22), (Word16) L_shr(st_ivas->hIsmMetaData[i]->elevation_fx,22), &gains_fx[0], &gains_fx[1] ); + ivas_ism_get_stereo_gains_fx( (Word16) L_shr( st_ivas->hIsmMetaData[i]->azimuth_fx, 22 ), (Word16) L_shr( st_ivas->hIsmMetaData[i]->elevation_fx, 22 ), &gains_fx[0], &gains_fx[1] ); st_ivas->hIsmRendererData->gains_fx[i][0] = L_shr( L_deposit_h( gains_fx[0] ), 1 ); move32(); st_ivas->hIsmRendererData->gains_fx[i][1] = L_shr( L_deposit_h( gains_fx[1] ), 1 ); @@ -1906,9 +1911,9 @@ void ivas_ism_dec_digest_tc( } else { - for (i = 0; i < interpolator_length; i++) + for ( i = 0; i < interpolator_length; i++ ) { - st_ivas->hIsmRendererData->interpolator[i] = (float)i / ((float)interpolator_length - 1); + st_ivas->hIsmRendererData->interpolator[i] = (float) i / ( (float) interpolator_length - 1 ); } } } @@ -1946,7 +1951,7 @@ void ivas_ism_dec_digest_tc( if ( st_ivas->hEFAPdata != NULL ) { - efap_determine_gains(st_ivas->hEFAPdata, st_ivas->hIsmRendererData->gains[i], azimuth, elevation, EFAP_MODE_EFAP); + efap_determine_gains( st_ivas->hEFAPdata, st_ivas->hIsmRendererData->gains[i], azimuth, elevation, EFAP_MODE_EFAP ); } } else if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC || @@ -1954,7 +1959,7 @@ void ivas_ism_dec_digest_tc( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV ) { /*get HOA gets for direction (ACN/SN3D)*/ - ivas_dirac_dec_get_response(azimuth, elevation, st_ivas->hIsmRendererData->gains[i], st_ivas->hIntSetup.ambisonics_order); + ivas_dirac_dec_get_response( azimuth, elevation, st_ivas->hIsmRendererData->gains[i], st_ivas->hIntSetup.ambisonics_order ); } } } @@ -1971,7 +1976,7 @@ void ivas_ism_dec_digest_tc( *-------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED void ivas_param_ism_dec_digest_tc( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ const UWord16 nCldfbSlots, /* i : number of CLFBS slots in the transport channels */ Word32 *transport_channels[] /* i : synthesized core-coder transport channels/DirAC output */ ) @@ -1982,7 +1987,7 @@ void ivas_param_ism_dec_digest_tc( Word16 ref_power_e[CLDFB_NO_CHANNELS_MAX]; Word32 cx_diag_fx[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_DMX]; Word16 cx_diag_e[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_DMX]; - Word16 q_tc=13; + Word16 q_tc = 13; Word16 ch, nchan_transport, nchan_out, nchan_out_woLFE, i; Word16 slot_idx, bin_idx; Word32 ivas_total_brate; @@ -1999,15 +2004,15 @@ void ivas_param_ism_dec_digest_tc( assert( hParamIsmDec ); hSpatParamRendCom = st_ivas->hSpatParamRendCom; assert( hSpatParamRendCom ); - output_frame = imult1616(nCldfbSlots , hSpatParamRendCom->num_freq_bands); - fade_len = shr(output_frame , 2); + output_frame = imult1616( nCldfbSlots, hSpatParamRendCom->num_freq_bands ); + fade_len = shr( output_frame, 2 ); nchan_transport = st_ivas->nchan_transport; ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_exp = 23; hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_exp = 23; - IF ( EQ_16(st_ivas->hDecoderConfig->output_config , IVAS_AUDIO_CONFIG_EXTERNAL) ) + IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) { nchan_out = st_ivas->nchan_ism; nchan_out_woLFE = nchan_out; @@ -2027,17 +2032,17 @@ void ivas_param_ism_dec_digest_tc( ivas_dirac_dec_set_md_map_fx( st_ivas, nCldfbSlots ); /* set buffers to zero */ - FOR ( bin_idx = 0; bin_idx < CLDFB_NO_CHANNELS_MAX; bin_idx++ ) + FOR( bin_idx = 0; bin_idx < CLDFB_NO_CHANNELS_MAX; bin_idx++ ) { set_zero_fx( cx_diag_fx[bin_idx], PARAM_ISM_MAX_DMX ); - set16_fx(cx_diag_e[bin_idx], 31,PARAM_ISM_MAX_DMX ); + set16_fx( cx_diag_e[bin_idx], 31, PARAM_ISM_MAX_DMX ); } set_zero_fx( ref_power_fx, CLDFB_NO_CHANNELS_MAX ); - set16_fx(ref_power_e,31, CLDFB_NO_CHANNELS_MAX ); + set16_fx( ref_power_e, 31, CLDFB_NO_CHANNELS_MAX ); /* Frame-level Processing */ /* De-quantization */ - IF ( !( EQ_32(ivas_total_brate , IVAS_SID_5k2) || EQ_32(ivas_total_brate , FRAME_NO_DATA) ) ) + IF( !( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) || EQ_32( ivas_total_brate, FRAME_NO_DATA ) ) ) { ivas_param_ism_dec_dequant_DOA_fx( hParamIsmDec, st_ivas->nchan_ism ); ivas_param_ism_dec_dequant_powrat_fx( hParamIsmDec ); @@ -2049,7 +2054,7 @@ void ivas_param_ism_dec_digest_tc( } /* obtain the direct response using EFAP */ - IF ( !( EQ_16(st_ivas->hDecoderConfig->output_config , IVAS_AUDIO_CONFIG_EXTERNAL) ) ) + IF( !( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) ) { FOR( i = 0; i < st_ivas->nchan_ism; i++ ) { @@ -2060,11 +2065,11 @@ void ivas_param_ism_dec_digest_tc( { Word16 j; - FOR ( i = 0; i < st_ivas->nchan_ism; i++ ) + FOR( i = 0; i < st_ivas->nchan_ism; i++ ) { - FOR ( j = 0; j < nchan_out_woLFE; j++ ) + FOR( j = 0; j < nchan_out_woLFE; j++ ) { - IF ( EQ_16(i , j) ) + IF( EQ_16( i, j ) ) { direct_response_fx[i][j] = ONE_IN_Q30; } @@ -2075,7 +2080,7 @@ void ivas_param_ism_dec_digest_tc( } } - FOR ( j = 0; j < nchan_out_woLFE; j++ ) + FOR( j = 0; j < nchan_out_woLFE; j++ ) { IF( GT_32( hParamIsmDec->azimuth_values_fx[j], 0 ) ) { @@ -2102,30 +2107,30 @@ void ivas_param_ism_dec_digest_tc( } } - IF ( st_ivas->hDecoderConfig->Opt_tsm ) + IF( st_ivas->hDecoderConfig->Opt_tsm ) { /*TODO : FhG to check*/ - ivas_ism_param_dec_tc_gain_ajust_fx( st_ivas, output_frame, fade_len, transport_channels , &q_tc); - FOR ( i = 0; i < 2; i++ ) - scale_sig32( transport_channels[i], output_frame, sub(Q13 , q_tc) ); + ivas_ism_param_dec_tc_gain_ajust_fx( st_ivas, output_frame, fade_len, transport_channels, &q_tc ); + FOR( i = 0; i < 2; i++ ) + scale_sig32( transport_channels[i], output_frame, sub( Q13, q_tc ) ); q_tc = 13; } exp_ref_power = 31; max_exp_ref_power = 0; - FOR ( ch = 0; ch < nchan_transport; ch++ ) + FOR( ch = 0; ch < nchan_transport; ch++ ) { max_exp_cx_diag = 0; exp_cx_diag = 31; /* CLDFB Analysis */ - FOR ( slot_idx = 0; slot_idx < nCldfbSlots; slot_idx++ ) + FOR( slot_idx = 0; slot_idx < nCldfbSlots; slot_idx++ ) { - IF ( st_ivas->hDecoderConfig->Opt_tsm ) + IF( st_ivas->hDecoderConfig->Opt_tsm ) { Word32 RealBuffer_fx[CLDFB_NO_CHANNELS_MAX]; Word32 ImagBuffer_fx[CLDFB_NO_CHANNELS_MAX]; q_tc = 13; - cldfbAnalysis_ts_fx_fixed_q( &( transport_channels[ch][hSpatParamRendCom->num_freq_bands * slot_idx] ), RealBuffer_fx, ImagBuffer_fx, hSpatParamRendCom->num_freq_bands, st_ivas->cldfbAnaDec[ch] ,&q_tc); + cldfbAnalysis_ts_fx_fixed_q( &( transport_channels[ch][hSpatParamRendCom->num_freq_bands * slot_idx] ), RealBuffer_fx, ImagBuffer_fx, hSpatParamRendCom->num_freq_bands, st_ivas->cldfbAnaDec[ch], &q_tc ); Copy32( RealBuffer_fx, &hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx[slot_idx * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands], hSpatParamRendCom->num_freq_bands ); Copy32( ImagBuffer_fx, &hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx[slot_idx * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands], hSpatParamRendCom->num_freq_bands ); hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_exp = 23; @@ -2138,7 +2143,7 @@ void ivas_param_ism_dec_digest_tc( scale_factor_real = getScaleFactor32( &hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx[slot_idx * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands], hSpatParamRendCom->num_freq_bands ); scale_factor_imag = getScaleFactor32( &hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx[slot_idx * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands], hSpatParamRendCom->num_freq_bands ); scale_sig32( &hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx[slot_idx * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands], hSpatParamRendCom->num_freq_bands, scale_factor_real ); - scale_sig32(&hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx[slot_idx * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands], hSpatParamRendCom->num_freq_bands, scale_factor_imag); + scale_sig32( &hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx[slot_idx * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands], hSpatParamRendCom->num_freq_bands, scale_factor_imag ); exp_real_tmp -= scale_factor_real; exp_imag_tmp -= scale_factor_imag; ivas_param_ism_collect_slot_fx( hParamIsmDec, @@ -2177,24 +2182,24 @@ void ivas_param_ism_dec_digest_tc( } } /* Obtain Mixing Matrix on a frame-level */ -#if 1/*To avoid garbage values(garbage values giving wrong exponent in jbm_dec_render)*/ - FOR ( bin_idx = 0; bin_idx < CLDFB_NO_CHANNELS_MAX; bin_idx++ ) +#if 1 /*To avoid garbage values(garbage values giving wrong exponent in jbm_dec_render)*/ + FOR( bin_idx = 0; bin_idx < CLDFB_NO_CHANNELS_MAX; bin_idx++ ) { set32_fx( hParamIsmDec->hParamIsmRendering->mixing_matrix_lin_fx[bin_idx], 0, PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX ); } #else - FOR ( bin_idx = 0; bin_idx < hSpatParamRendCom->num_freq_bands; bin_idx++ ) + FOR( bin_idx = 0; bin_idx < hSpatParamRendCom->num_freq_bands; bin_idx++ ) { set32_fx( hParamIsmDec->hParamIsmRendering->mixing_matrix_lin_fx[bin_idx], 0, nchan_transport * nchan_out_woLFE ); } #endif -#if 1/*TODO : To be removed (Fixed to float) */ +#if 1 /*TODO : To be removed (Fixed to float) */ float ref_power[CLDFB_NO_CHANNELS_MAX]; float cx_diag[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_DMX]; float direct_response[MAX_NUM_OBJECTS][PARAM_ISM_MAX_CHAN]; FOR( ch = 0; ch < nchan_transport; ch++ ) { - scale_sig32( st_ivas->cldfbAnaDec[ch]->cldfb_state_fx, st_ivas->cldfbAnaDec[ch]->cldfb_size, sub(Q11, Q13) ); + scale_sig32( st_ivas->cldfbAnaDec[ch]->cldfb_state_fx, st_ivas->cldfbAnaDec[ch]->cldfb_size, sub( Q11, Q13 ) ); st_ivas->cldfbAnaDec[ch]->Q_cldfb_state = Q11; /* CLDFB Analysis */ FOR( slot_idx = 0; slot_idx < nCldfbSlots; slot_idx++ ) @@ -2203,9 +2208,9 @@ void ivas_param_ism_dec_digest_tc( fixedToFloat_arrL( &hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx[slot_idx * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands], &hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc[slot_idx * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands], Q8, hSpatParamRendCom->num_freq_bands ); } } - FOR ( bin_idx = 0; bin_idx < CLDFB_NO_CHANNELS_MAX; bin_idx++ ) + FOR( bin_idx = 0; bin_idx < CLDFB_NO_CHANNELS_MAX; bin_idx++ ) { - set_f( hParamIsmDec->hParamIsmRendering->mixing_matrix_lin[bin_idx], 0.0f, PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX );/*To be removed when dependency on mixing_matrix_lin is removed*/ + set_f( hParamIsmDec->hParamIsmRendering->mixing_matrix_lin[bin_idx], 0.0f, PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX ); /*To be removed when dependency on mixing_matrix_lin is removed*/ } FOR( Word16 band_idx = 0; band_idx < CLDFB_NO_CHANNELS_MAX; band_idx++ ) { @@ -2618,16 +2623,16 @@ static void ivas_ism_param_dec_render_sf_fx( Word16 idx_in; Word16 idx_lfe; Word16 subframe_idx; - Word16 samplesProcessed,no_col_cldfb, size_cldfb; + Word16 samplesProcessed, no_col_cldfb, size_cldfb; hParamIsmDec = st_ivas->hParamIsmDec; hSpatParamRendCom = st_ivas->hSpatParamRendCom; slot_idx_start = hSpatParamRendCom->slots_rendered; subframe_idx = hSpatParamRendCom->subframes_rendered; /* Set some memories to zero */ - FOR ( ch = 0; ch < nchan_out_woLFE; ch++ ) + FOR( ch = 0; ch < nchan_out_woLFE; ch++ ) { - FOR ( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) + FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) { set32_fx( Cldfb_RealBuffer_fx[ch][slot_idx], 0, hSpatParamRendCom->num_freq_bands ); set32_fx( Cldfb_ImagBuffer_fx[ch][slot_idx], 0, hSpatParamRendCom->num_freq_bands ); @@ -2637,11 +2642,11 @@ static void ivas_ism_param_dec_render_sf_fx( Word16 real_exp[JBM_CLDFB_SLOTS_IN_SUBFRAME]; Word16 imag_exp[JBM_CLDFB_SLOTS_IN_SUBFRAME]; - FOR ( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) + FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) { index_slot = slot_idx_start + slot_idx; - FOR ( ch = 0; ch < nchan_transport; ch++ ) + FOR( ch = 0; ch < nchan_transport; ch++ ) { Cldfb_RealBuffer_in_fx[ch] = &hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx[index_slot * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands]; // Q11 Cldfb_ImagBuffer_in_fx[ch] = &hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx[index_slot * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands]; // Q11 @@ -2659,19 +2664,19 @@ static void ivas_ism_param_dec_render_sf_fx( /* CLDFB Synthesis */ idx_in = 0; idx_lfe = 0; - //Word16 tmp_buff_Q[MAX_OUTPUT_CHANNELS]; + // Word16 tmp_buff_Q[MAX_OUTPUT_CHANNELS]; - FOR ( ch = 0; ch < nchan_out; ch++ ) + FOR( ch = 0; ch < nchan_out; ch++ ) { - IF ( ( hSetup.num_lfe > 0 ) && ( hSetup.index_lfe[idx_lfe] == ch ) ) + IF( ( hSetup.num_lfe > 0 ) && ( hSetup.index_lfe[idx_lfe] == ch ) ) { - set32_fx( output_f_fx[ch], 0, i_mult(hSpatParamRendCom->subframe_nbslots[subframe_idx] , hSpatParamRendCom->num_freq_bands) ); + set32_fx( output_f_fx[ch], 0, i_mult( hSpatParamRendCom->subframe_nbslots[subframe_idx], hSpatParamRendCom->num_freq_bands ) ); - IF ( idx_lfe < sub( hSetup.num_lfe , 1 ) ) + IF( idx_lfe < sub( hSetup.num_lfe, 1 ) ) { - idx_lfe = add(idx_lfe,1); + idx_lfe = add( idx_lfe, 1 ); } - //tmp_buff_Q[ch] = 0; + // tmp_buff_Q[ch] = 0; } ELSE { @@ -2681,47 +2686,47 @@ static void ivas_ism_param_dec_render_sf_fx( Word16 Q_real = 31; - FOR ( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ ) + FOR( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ ) { RealBuffer_fx[i] = Cldfb_RealBuffer_fx[idx_in][i]; ImagBuffer_fx[i] = Cldfb_ImagBuffer_fx[idx_in][i]; - Q_real = min( Q_real, sub(31 , imag_exp[i]) ); - Q_real = min( Q_real, sub(31 , real_exp[i]) ); + Q_real = min( Q_real, sub( 31, imag_exp[i] ) ); + Q_real = min( Q_real, sub( 31, real_exp[i] ) ); } - Q_real = sub(Q_real,3); // guarded bits + Q_real = sub( Q_real, 3 ); // guarded bits - FOR ( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ ) + FOR( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ ) { - Scale_sig32( RealBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, add(sub(Q_real , 31) , real_exp[i]) ); - Scale_sig32( ImagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, add(sub(Q_real , 31) , imag_exp[i]) ); + Scale_sig32( RealBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, add( sub( Q_real, 31 ), real_exp[i] ) ); + Scale_sig32( ImagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, add( sub( Q_real, 31 ), imag_exp[i] ) ); } - Scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->p_filter_length, sub(sub( Q_real , 1 ) , Q11) ); + Scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->p_filter_length, sub( sub( Q_real, 1 ), Q11 ) ); st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q_real - 1; cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, output_f_fx[ch], hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->subframe_nbslots[subframe_idx], st_ivas->cldfbSynDec[ch] ); - Scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->p_filter_length, sub(Q11 , sub( Q_real , 1 )) ); + Scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->p_filter_length, sub( Q11, sub( Q_real, 1 ) ) ); st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q11; - /*scaling the output_f buffer to have common Q accross the buffer*/ - samplesProcessed = hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->subframe_nbslots[subframe_idx]; - no_col_cldfb = st_ivas->cldfbSynDec[ch]->no_col; - IF(GT_16(samplesProcessed, -1)) - { - no_col_cldfb = min(no_col_cldfb, (samplesProcessed + st_ivas->cldfbSynDec[ch]->no_channels - 1) / st_ivas->cldfbSynDec[ch]->no_channels); - move16(); - } + /*scaling the output_f buffer to have common Q accross the buffer*/ + samplesProcessed = hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->subframe_nbslots[subframe_idx]; + no_col_cldfb = st_ivas->cldfbSynDec[ch]->no_col; + IF( GT_16( samplesProcessed, -1 ) ) + { + no_col_cldfb = min( no_col_cldfb, ( samplesProcessed + st_ivas->cldfbSynDec[ch]->no_channels - 1 ) / st_ivas->cldfbSynDec[ch]->no_channels ); + move16(); + } - size_cldfb = st_ivas->cldfbSynDec[ch]->no_channels*no_col_cldfb; - Scale_sig32(output_f_fx[ch], size_cldfb, sub(Q11 , sub(Q_real , 1))); + size_cldfb = st_ivas->cldfbSynDec[ch]->no_channels * no_col_cldfb; + Scale_sig32( output_f_fx[ch], size_cldfb, sub( Q11, sub( Q_real, 1 ) ) ); - Q_output[ch] = sub(Q_real , 1); - idx_in = add(idx_in,1); + Q_output[ch] = sub( Q_real, 1 ); + idx_in = add( idx_in, 1 ); } } - hSpatParamRendCom->slots_rendered = add(hSpatParamRendCom->slots_rendered,hSpatParamRendCom->subframe_nbslots[subframe_idx]); - hSpatParamRendCom->subframes_rendered = add(hSpatParamRendCom->subframes_rendered,1); + hSpatParamRendCom->slots_rendered = add( hSpatParamRendCom->slots_rendered, hSpatParamRendCom->subframe_nbslots[subframe_idx] ); + hSpatParamRendCom->subframes_rendered = add( hSpatParamRendCom->subframes_rendered, 1 ); return; } @@ -2824,12 +2829,11 @@ static void ivas_ism_param_dec_render_sf( *-------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED void ivas_param_ism_dec_render_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ UWord16 *nSamplesAvailableNext, /* o : number of CLDFB slots still to render */ - Word32 *output_f_fx[] -) + Word32 *output_f_fx[] ) { Word16 ch, slots_to_render, first_sf, last_sf, subframe_idx; @@ -2839,16 +2843,16 @@ void ivas_param_ism_dec_render_fx( IVAS_OUTPUT_SETUP hSetup; Word16 nchan_transport, nchan_out, nchan_out_woLFE; Word32 *output_f_local_fx[MAX_OUTPUT_CHANNELS]; - Word16 Q_output[MAX_OUTPUT_CHANNELS]; + Word16 Q_output[MAX_OUTPUT_CHANNELS]; - set16_fx(Q_output, 0, MAX_OUTPUT_CHANNELS); + set16_fx( Q_output, 0, MAX_OUTPUT_CHANNELS ); hParamIsmDec = st_ivas->hParamIsmDec; hSpatParamRendCom = st_ivas->hSpatParamRendCom; hSetup = st_ivas->hIntSetup; nchan_transport = st_ivas->nchan_transport; - - IF (st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_EXTERNAL) + + IF( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_EXTERNAL ) { nchan_out = st_ivas->nchan_ism; nchan_out_woLFE = nchan_out; @@ -2859,46 +2863,46 @@ void ivas_param_ism_dec_render_fx( nchan_out = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; nchan_out_woLFE = st_ivas->hIntSetup.nchan_out_woLFE; } - slot_size = NS2SA(st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS); + slot_size = NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */ - slots_to_render = min(hSpatParamRendCom->num_slots - hSpatParamRendCom->slots_rendered, nSamplesAsked / slot_size); + slots_to_render = min( hSpatParamRendCom->num_slots - hSpatParamRendCom->slots_rendered, nSamplesAsked / slot_size ); *nSamplesRendered = slots_to_render * slot_size; first_sf = hSpatParamRendCom->subframes_rendered; last_sf = first_sf; - WHILE (slots_to_render > 0) + WHILE( slots_to_render > 0 ) { - slots_to_render = sub(slots_to_render,hSpatParamRendCom->subframe_nbslots[last_sf]); - last_sf = add(last_sf,1); + slots_to_render = sub( slots_to_render, hSpatParamRendCom->subframe_nbslots[last_sf] ); + last_sf = add( last_sf, 1 ); } - FOR (ch = 0; ch < nchan_out; ch++) + FOR( ch = 0; ch < nchan_out; ch++ ) { output_f_local_fx[ch] = &output_f_fx[ch][0]; } - FOR (subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++) + FOR( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ ) { ivas_ism_param_dec_render_sf_fx( st_ivas, hSetup, nchan_transport, nchan_out, nchan_out_woLFE, output_f_local_fx, Q_output ); n_samples_sf = hSpatParamRendCom->subframe_nbslots[subframe_idx] * hSpatParamRendCom->slot_size; - FOR (ch = 0; ch < nchan_out; ch++) + FOR( ch = 0; ch < nchan_out; ch++ ) { output_f_local_fx[ch] += n_samples_sf; } } - IF (hSpatParamRendCom->slots_rendered == hSpatParamRendCom->num_slots) + IF( hSpatParamRendCom->slots_rendered == hSpatParamRendCom->num_slots ) { /* copy the memories */ /* store mixing matrix for next subframe */ - ivas_param_ism_update_mixing_matrix_fx(hParamIsmDec, hParamIsmDec->hParamIsmRendering->mixing_matrix_lin_fx, hParamIsmDec->hParamIsmRendering->exp_mixing_matrix_lin_fx, nchan_transport, nchan_out_woLFE); + ivas_param_ism_update_mixing_matrix_fx( hParamIsmDec, hParamIsmDec->hParamIsmRendering->mixing_matrix_lin_fx, hParamIsmDec->hParamIsmRendering->exp_mixing_matrix_lin_fx, nchan_transport, nchan_out_woLFE ); /* store MetaData parameters */ - FOR ( ch = 0; ch < st_ivas->nchan_ism; ch++ ) + FOR( ch = 0; ch < st_ivas->nchan_ism; ch++ ) { - IF ( st_ivas->hParamIsmDec->azimuth_values_fx[ch] > 754974720 /*180.f in Q22*/ ) + IF( st_ivas->hParamIsmDec->azimuth_values_fx[ch] > 754974720 /*180.f in Q22*/ ) { st_ivas->hIsmMetaData[ch]->azimuth_fx = L_sub( st_ivas->hParamIsmDec->azimuth_values_fx[ch], 1509949440 ) /*360.0F in Q22*/; } @@ -2911,7 +2915,7 @@ void ivas_param_ism_dec_render_fx( } } - *nSamplesAvailableNext = (hSpatParamRendCom->num_slots - hSpatParamRendCom->slots_rendered) * slot_size; + *nSamplesAvailableNext = ( hSpatParamRendCom->num_slots - hSpatParamRendCom->slots_rendered ) * slot_size; return; } @@ -3032,7 +3036,7 @@ void ivas_param_ism_params_to_masa_param_mapping_fx( ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; move32(); - IF ( !( EQ_32(ivas_total_brate , IVAS_SID_5k2) || EQ_32(ivas_total_brate , FRAME_NO_DATA) ) ) + IF( !( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) || EQ_32( ivas_total_brate, FRAME_NO_DATA ) ) ) { ivas_param_ism_dec_dequant_DOA_fx( hParamIsmDec, st_ivas->nchan_ism ); ivas_param_ism_dec_dequant_powrat_fx( hParamIsmDec ); @@ -3045,21 +3049,21 @@ void ivas_param_ism_params_to_masa_param_mapping_fx( move16(); } - IF ( GT_16(st_ivas->nchan_ism , 1) ) + IF( GT_16( st_ivas->nchan_ism, 1 ) ) { - IF ( st_ivas->hISMDTX.dtx_flag ) + IF( st_ivas->hISMDTX.dtx_flag ) { - Word32 energy_ratio_fx; /* Q30 */ + Word32 energy_ratio_fx; /* Q30 */ energy_ratio_fx = L_mult0( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_fx, st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_fx ); /* Q15 + Q15 -> Q30 */ hSpatParamRendCom->numSimultaneousDirections = 1; move16(); - azimuth[0] = (Word16) L_shr(( hParamIsmDec->azimuth_values_fx[0] +(1<<21)),22); - elevation[0] = (Word16) L_shr(( hParamIsmDec->elevation_values_fx[0] + (1 << 21)),22); + azimuth[0] = (Word16) L_shr( ( hParamIsmDec->azimuth_values_fx[0] + ( 1 << 21 ) ), 22 ); + elevation[0] = (Word16) L_shr( ( hParamIsmDec->elevation_values_fx[0] + ( 1 << 21 ) ), 22 ); - FOR ( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ ) + FOR( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ ) { - FOR ( bin_idx = 0; bin_idx < nBins; bin_idx++ ) + FOR( bin_idx = 0; bin_idx < nBins; bin_idx++ ) { hSpatParamRendCom->azimuth[sf_idx][bin_idx] = azimuth[0]; hSpatParamRendCom->elevation[sf_idx][bin_idx] = elevation[0]; @@ -3080,27 +3084,27 @@ void ivas_param_ism_params_to_masa_param_mapping_fx( { hSpatParamRendCom->numSimultaneousDirections = 2; move16(); - FOR ( band_idx = 0; band_idx < hParamIsmDec->hParamIsm->nbands; band_idx++ ) + FOR( band_idx = 0; band_idx < hParamIsmDec->hParamIsm->nbands; band_idx++ ) { brange[0] = hParamIsmDec->hParamIsm->band_grouping[band_idx]; brange[1] = hParamIsmDec->hParamIsm->band_grouping[band_idx + 1]; move16(); move16(); - azimuth[0] = (Word16) L_shr( hParamIsmDec->azimuth_values_fx[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][0]] + (1 << 21),22); - elevation[0] = (Word16)L_shr(hParamIsmDec->elevation_values_fx[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][0]] + (1 << 21),22); + azimuth[0] = (Word16) L_shr( hParamIsmDec->azimuth_values_fx[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][0]] + ( 1 << 21 ), 22 ); + elevation[0] = (Word16) L_shr( hParamIsmDec->elevation_values_fx[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][0]] + ( 1 << 21 ), 22 ); power_ratio_fx[0] = hParamIsmDec->power_ratios_fx[band_idx][0][0]; move16(); - azimuth[1] = (Word16)L_shr(hParamIsmDec->azimuth_values_fx[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][1]] + (1 << 21),22); - elevation[1] = (Word16)L_shr(hParamIsmDec->elevation_values_fx[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][1]]+ (1 << 21),22 ); + azimuth[1] = (Word16) L_shr( hParamIsmDec->azimuth_values_fx[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][1]] + ( 1 << 21 ), 22 ); + elevation[1] = (Word16) L_shr( hParamIsmDec->elevation_values_fx[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][1]] + ( 1 << 21 ), 22 ); power_ratio_fx[1] = hParamIsmDec->power_ratios_fx[band_idx][0][1]; move16(); - FOR ( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ ) + FOR( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ ) { - FOR ( bin_idx = brange[0]; bin_idx < brange[1]; bin_idx++ ) + FOR( bin_idx = brange[0]; bin_idx < brange[1]; bin_idx++ ) { hSpatParamRendCom->azimuth[sf_idx][bin_idx] = azimuth[0]; hSpatParamRendCom->elevation[sf_idx][bin_idx] = elevation[0]; @@ -3118,9 +3122,9 @@ void ivas_param_ism_params_to_masa_param_mapping_fx( } } - FOR ( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ ) + FOR( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ ) { - FOR ( bin_idx = 0; bin_idx < nBins; bin_idx++ ) + FOR( bin_idx = 0; bin_idx < nBins; bin_idx++ ) { hSpatParamRendCom->spreadCoherence_fx[sf_idx][bin_idx] = 0; hSpatParamRendCom->spreadCoherence2_fx[sf_idx][bin_idx] = 0; @@ -3136,12 +3140,12 @@ void ivas_param_ism_params_to_masa_param_mapping_fx( { hSpatParamRendCom->numSimultaneousDirections = 1; move16(); - azimuth[0] = (Word16) L_shr((hParamIsmDec->azimuth_values_fx[0] + (1 << 21)),22); - elevation[0] = (Word16)L_shr( hParamIsmDec->elevation_values_fx[0] + (1 << 21),22); + azimuth[0] = (Word16) L_shr( ( hParamIsmDec->azimuth_values_fx[0] + ( 1 << 21 ) ), 22 ); + elevation[0] = (Word16) L_shr( hParamIsmDec->elevation_values_fx[0] + ( 1 << 21 ), 22 ); - FOR ( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ ) + FOR( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ ) { - FOR ( bin_idx = 0; bin_idx < nBins; bin_idx++ ) + FOR( bin_idx = 0; bin_idx < nBins; bin_idx++ ) { hSpatParamRendCom->azimuth[sf_idx][bin_idx] = azimuth[0]; hSpatParamRendCom->elevation[sf_idx][bin_idx] = elevation[0]; diff --git a/lib_dec/ivas_ism_renderer.c b/lib_dec/ivas_ism_renderer.c index 7c6eeeaa4..663af323d 100644 --- a/lib_dec/ivas_ism_renderer.c +++ b/lib_dec/ivas_ism_renderer.c @@ -122,26 +122,26 @@ ivas_error ivas_ism_renderer_open_fx( UWord16 init_interpolator_length; ivas_error error; - IF ( ( st_ivas->hIsmRendererData = (ISM_RENDERER_HANDLE) malloc( sizeof( ISM_RENDERER_DATA ) ) ) == NULL ) + IF( ( st_ivas->hIsmRendererData = (ISM_RENDERER_HANDLE) malloc( sizeof( ISM_RENDERER_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ISM renderer\n" ) ); } - IF ( st_ivas->hIntSetup.is_loudspeaker_setup && st_ivas->hIntSetup.ls_azimuth_fx != NULL && st_ivas->hIntSetup.ls_elevation_fx != NULL && st_ivas->hEFAPdata == NULL ) + IF( st_ivas->hIntSetup.is_loudspeaker_setup && st_ivas->hIntSetup.ls_azimuth_fx != NULL && st_ivas->hIntSetup.ls_elevation_fx != NULL && st_ivas->hEFAPdata == NULL ) { - IF ( ( error = efap_init_data_fx( &( st_ivas->hEFAPdata ), st_ivas->hIntSetup.ls_azimuth_fx, st_ivas->hIntSetup.ls_elevation_fx, st_ivas->hIntSetup.nchan_out_woLFE, EFAP_MODE_EFAP ) ) != IVAS_ERR_OK ) + IF( ( error = efap_init_data_fx( &( st_ivas->hEFAPdata ), st_ivas->hIntSetup.ls_azimuth_fx, st_ivas->hIntSetup.ls_elevation_fx, st_ivas->hIntSetup.nchan_out_woLFE, EFAP_MODE_EFAP ) ) != IVAS_ERR_OK ) { return error; } } - FOR ( i = 0; i < MAX_NUM_OBJECTS; i++ ) + FOR( i = 0; i < MAX_NUM_OBJECTS; i++ ) { set32_fx( st_ivas->hIsmRendererData->prev_gains_fx[i], 0, MAX_OUTPUT_CHANNELS ); set32_fx( st_ivas->hIsmRendererData->gains_fx[i], 0, MAX_OUTPUT_CHANNELS ); } - IF ( st_ivas->hDecoderConfig->Opt_tsm ) + IF( st_ivas->hDecoderConfig->Opt_tsm ) { init_interpolator_length = NS2SA( st_ivas->hDecoderConfig->output_Fs, MAX_JBM_CLDFB_TIMESLOTS * CLDFB_SLOT_NS ); move16(); @@ -155,7 +155,7 @@ ivas_error ivas_ism_renderer_open_fx( interpolator_length = init_interpolator_length; move16(); } - IF ( ( st_ivas->hIsmRendererData->interpolator_fx = (Word16 *) malloc( sizeof( Word16 ) * init_interpolator_length ) ) == NULL ) + IF( ( st_ivas->hIsmRendererData->interpolator_fx = (Word16 *) malloc( sizeof( Word16 ) * init_interpolator_length ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ISM renderer interpolator\n" ) ); } @@ -163,7 +163,7 @@ ivas_error ivas_ism_renderer_open_fx( st_ivas->hIsmRendererData->interpolator_len = init_interpolator_length; move16(); - FOR ( i = 0; i < interpolator_length - 1; i++ ) + FOR( i = 0; i < interpolator_length - 1; i++ ) { st_ivas->hIsmRendererData->interpolator_fx[i] = div_s( i, sub( interpolator_length, 1 ) ); } @@ -184,12 +184,12 @@ void ivas_ism_renderer_close( ISM_RENDERER_HANDLE *hIsmRendererData /* i/o: ISM renderer handle */ ) { - IF ( hIsmRendererData == NULL || *hIsmRendererData == NULL ) + IF( hIsmRendererData == NULL || *hIsmRendererData == NULL ) { return; } - IF ( ( *hIsmRendererData )->interpolator != NULL ) + IF( ( *hIsmRendererData )->interpolator != NULL ) { free( ( *hIsmRendererData )->interpolator ); ( *hIsmRendererData )->interpolator = NULL; @@ -205,12 +205,12 @@ void ivas_ism_renderer_close( ISM_RENDERER_HANDLE *hIsmRendererData /* i/o: ISM renderer handle */ ) { - IF ( hIsmRendererData == NULL || *hIsmRendererData == NULL ) + IF( hIsmRendererData == NULL || *hIsmRendererData == NULL ) { return; } - IF ( ( *hIsmRendererData )->interpolator_fx != NULL ) + IF( ( *hIsmRendererData )->interpolator_fx != NULL ) { free( ( *hIsmRendererData )->interpolator_fx ); ( *hIsmRendererData )->interpolator_fx = NULL; @@ -236,7 +236,7 @@ void ivas_ism_render_sf( ) { int16_t i, j, k, j2; - float g2, *tc; + float g2, *tc; #ifndef IVAS_FLOAT_FIXED float *g1; #endif @@ -296,7 +296,7 @@ void ivas_ism_render_sf( { #ifdef IVAS_FLOAT_FIXED float gains[MAX_OUTPUT_CHANNELS]; - fixedToFloat_arrL(st_ivas->hIsmRendererData->gains_fx[i], gains, Q30, MAX_OUTPUT_CHANNELS); + fixedToFloat_arrL( st_ivas->hIsmRendererData->gains_fx[i], gains, Q30, MAX_OUTPUT_CHANNELS ); efap_determine_gains( st_ivas->hEFAPdata, gains, azimuth, elevation, EFAP_MODE_EFAP ); #else efap_determine_gains( st_ivas->hEFAPdata, st_ivas->hIsmRendererData->gains[i], azimuth, elevation, EFAP_MODE_EFAP ); @@ -313,8 +313,8 @@ void ivas_ism_render_sf( } #ifdef IVAS_FLOAT_FIXED - gain = fix_to_float(st_ivas->hIsmRendererData->gains_fx[i][j], Q30); - prev_gain = fix_to_float(st_ivas->hIsmRendererData->prev_gains_fx[i][j], Q30); + gain = fix_to_float( st_ivas->hIsmRendererData->gains_fx[i][j], Q30 ); + prev_gain = fix_to_float( st_ivas->hIsmRendererData->prev_gains_fx[i][j], Q30 ); #else gain = st_ivas->hIsmRendererData->gains[i][j]; prev_gain = st_ivas->hIsmRendererData->prev_gains[i][j]; @@ -331,8 +331,8 @@ void ivas_ism_render_sf( for ( k = 0; k < n_samples_to_render; k++ ) { #ifdef IVAS_FLOAT_FIXED - g2 = 1.0f - fix16_to_float(*g1_fx, Q15); - output_f[j2][k] += ( fix16_to_float(*g1_fx, Q15) * gain + g2 * prev_gain ) * *( tc++ ); + g2 = 1.0f - fix16_to_float( *g1_fx, Q15 ); + output_f[j2][k] += ( fix16_to_float( *g1_fx, Q15 ) * gain + g2 * prev_gain ) * *( tc++ ); g1_fx++; #else g2 = 1.0f - *g1; @@ -360,8 +360,8 @@ void ivas_ism_render_sf( } #else void ivas_ism_render_sf_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - Word32 *output_fx[], /* i/o: core-coder transport channels/object output */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Word32 *output_fx[], /* i/o: core-coder transport channels/object output */ const Word16 n_samples_to_render /* i : output frame length per channel */ ) { @@ -378,7 +378,7 @@ void ivas_ism_render_sf_fx( num_objects = st_ivas->nchan_transport; move16(); - IF ( st_ivas->ivas_format == SBA_ISM_FORMAT ) + IF( st_ivas->ivas_format == SBA_ISM_FORMAT ) { num_objects = st_ivas->nchan_ism; move16(); @@ -392,9 +392,9 @@ void ivas_ism_render_sf_fx( interp_offset = st_ivas->hTcBuffer->n_samples_rendered; move16(); - IF ( st_ivas->hDecoderConfig->Opt_tsm ) + IF( st_ivas->hDecoderConfig->Opt_tsm ) { - FOR ( i = 0; i < num_objects; i++ ) + FOR( i = 0; i < num_objects; i++ ) { p_tc_fx[i] = &st_ivas->hTcBuffer->tc_fx[i][tc_offset]; move16(); @@ -402,7 +402,7 @@ void ivas_ism_render_sf_fx( } ELSE { - FOR ( i = 0; i < num_objects; i++ ) + FOR( i = 0; i < num_objects; i++ ) { mvl2l( &output_fx[i][tc_offset], tc_local_fx[i], n_samples_to_render ); p_tc_fx[i] = tc_local_fx[i]; @@ -410,62 +410,61 @@ void ivas_ism_render_sf_fx( } } - FOR ( i = 0; i < nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; i++ ) + FOR( i = 0; i < nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; i++ ) { set32_fx( output_fx[i], 0, n_samples_to_render ); } - IF ( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx] == 1 ) + IF( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx] == 1 ) { ivas_jbm_dec_get_adapted_linear_interpolator_fx( n_samples_to_render, n_samples_to_render, st_ivas->hIsmRendererData->interpolator_fx ); interp_offset = 0; move16(); } - FOR ( i = 0; i < num_objects; i++ ) + FOR( i = 0; i < num_objects; i++ ) { /* Combined rotation: rotate the object positions depending the head and external orientations */ - IF ( st_ivas->hCombinedOrientationData != NULL && st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx] == 1 ) + IF( st_ivas->hCombinedOrientationData != NULL && st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx] == 1 ) { - rotateAziEle_fx( (Word16)L_shr(st_ivas->hIsmMetaData[i]->azimuth_fx, 22), (Word16)L_shr(st_ivas->hIsmMetaData[i]->elevation_fx, 22), &azimuth, &elevation, st_ivas->hCombinedOrientationData->Rmat_fx[0], st_ivas->hIntSetup.is_planar_setup ); + rotateAziEle_fx( (Word16) L_shr( st_ivas->hIsmMetaData[i]->azimuth_fx, 22 ), (Word16) L_shr( st_ivas->hIsmMetaData[i]->elevation_fx, 22 ), &azimuth, &elevation, st_ivas->hCombinedOrientationData->Rmat_fx[0], st_ivas->hIntSetup.is_planar_setup ); move32(); move32(); - IF ( st_ivas->hEFAPdata != NULL ) + IF( st_ivas->hEFAPdata != NULL ) { - efap_determine_gains_fx( st_ivas->hEFAPdata, st_ivas->hIsmRendererData->gains_fx[i], L_shl(azimuth, 22), L_shl(elevation, 22), EFAP_MODE_EFAP ); + efap_determine_gains_fx( st_ivas->hEFAPdata, st_ivas->hIsmRendererData->gains_fx[i], L_shl( azimuth, 22 ), L_shl( elevation, 22 ), EFAP_MODE_EFAP ); } } lfe_index = 0; move16(); - FOR ( (j = 0, j2 = 0); j < nchan_out_woLFE; (j++, j2++) ) + FOR( ( j = 0, j2 = 0 ); j < nchan_out_woLFE; ( j++, j2++ ) ) { - IF ( ( st_ivas->hIntSetup.num_lfe > 0 ) && ( st_ivas->hIntSetup.index_lfe[lfe_index] == j ) ) + IF( ( st_ivas->hIntSetup.num_lfe > 0 ) && ( st_ivas->hIntSetup.index_lfe[lfe_index] == j ) ) { ( lfe_index < ( st_ivas->hIntSetup.num_lfe - 1 ) ) ? ( lfe_index++, j2++ ) : j2++; move16(); move16(); - } gain_fx = st_ivas->hIsmRendererData->gains_fx[i][j]; move32(); prev_gain_fx = st_ivas->hIsmRendererData->prev_gains_fx[i][j]; move32(); - IF ( GT_32(L_abs( gain_fx ), 0) || GT_32(L_abs( prev_gain_fx ), 0) ) + IF( GT_32( L_abs( gain_fx ), 0 ) || GT_32( L_abs( prev_gain_fx ), 0 ) ) { g1_fx = &st_ivas->hIsmRendererData->interpolator_fx[interp_offset]; tc_fx = p_tc_fx[i]; - FOR ( k = 0; k < n_samples_to_render; k++ ) + FOR( k = 0; k < n_samples_to_render; k++ ) { - g2_fx = sub(32767, *g1_fx); - output_fx[j2][k] = L_add(output_fx[j2][k], L_shl(Mpy_32_32(L_add( Mpy_32_16_1(gain_fx, *( g1_fx++ )), Mpy_32_16_1(prev_gain_fx, g2_fx) ), *( tc_fx++ )), 1)); + g2_fx = sub( 32767, *g1_fx ); + output_fx[j2][k] = L_add( output_fx[j2][k], L_shl( Mpy_32_32( L_add( Mpy_32_16_1( gain_fx, *( g1_fx++ ) ), Mpy_32_16_1( prev_gain_fx, g2_fx ) ), *( tc_fx++ ) ), 1 ) ); } } /* update here only in case of head rotation */ - IF ( st_ivas->hCombinedOrientationData != NULL && st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx] == 1 ) + IF( st_ivas->hCombinedOrientationData != NULL && st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx] == 1 ) { st_ivas->hIsmRendererData->prev_gains_fx[i][j] = gain_fx; move32(); @@ -667,12 +666,12 @@ ivas_error ivas_omasa_separate_object_renderer_open( Word16 i; Word16 init_interpolator_length; - IF ( ( st_ivas->hIsmRendererData = (ISM_RENDERER_HANDLE) malloc( sizeof( ISM_RENDERER_DATA ) ) ) == NULL ) + IF( ( st_ivas->hIsmRendererData = (ISM_RENDERER_HANDLE) malloc( sizeof( ISM_RENDERER_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for MASA ISM renderer \n" ) ); } - FOR ( i = 0; i < MAX_NUM_OBJECTS; i++ ) + FOR( i = 0; i < MAX_NUM_OBJECTS; i++ ) { set32_fx( st_ivas->hIsmRendererData->prev_gains_fx[i], 0, MAX_OUTPUT_CHANNELS ); } @@ -687,9 +686,9 @@ ivas_error ivas_omasa_separate_object_renderer_open( #if 1 /*TODO: To be removed later: Stores length of interpolator_fx*/ st_ivas->hIsmRendererData->interpolator_len = init_interpolator_length; #endif - FOR ( i = 0; i < interpolator_length; i++ ) + FOR( i = 0; i < interpolator_length; i++ ) { - st_ivas->hIsmRendererData->interpolator_fx[i] = div_s(i, interpolator_length); + st_ivas->hIsmRendererData->interpolator_fx[i] = div_s( i, interpolator_length ); } st_ivas->hIsmRendererData->interpolator_len = interpolator_length; move16(); @@ -697,7 +696,7 @@ ivas_error ivas_omasa_separate_object_renderer_open( st_ivas->hMasaIsmData->delayBuffer_size = (Word16) ( ( st_ivas->hDecoderConfig->output_Fs / 50 ) / MAX_PARAM_SPATIAL_SUBFRAMES ); move16(); - IF ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) + IF( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) { st_ivas->hMasaIsmData->delayBuffer_nchan = 1; move16(); @@ -708,14 +707,14 @@ ivas_error ivas_omasa_separate_object_renderer_open( move16(); } - IF ( ( st_ivas->hMasaIsmData->delayBuffer_fx = (Word32 **) malloc( st_ivas->hMasaIsmData->delayBuffer_nchan * sizeof( Word32 * ) ) ) == NULL ) + IF( ( st_ivas->hMasaIsmData->delayBuffer_fx = (Word32 **) malloc( st_ivas->hMasaIsmData->delayBuffer_nchan * sizeof( Word32 * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for MASA ISM delay buffer \n" ) ); } - FOR ( i = 0; i < st_ivas->hMasaIsmData->delayBuffer_nchan; i++ ) + FOR( i = 0; i < st_ivas->hMasaIsmData->delayBuffer_nchan; i++ ) { - IF ( ( st_ivas->hMasaIsmData->delayBuffer_fx[i] = (Word32 *) malloc( st_ivas->hMasaIsmData->delayBuffer_size * sizeof( Word32 ) ) ) == NULL ) + IF( ( st_ivas->hMasaIsmData->delayBuffer_fx[i] = (Word32 *) malloc( st_ivas->hMasaIsmData->delayBuffer_size * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for MASA ISM delay buffer \n" ) ); } @@ -769,13 +768,13 @@ void ivas_omasa_separate_object_renderer_close( { Word16 i; - IF ( st_ivas->hMasaIsmData != NULL ) + IF( st_ivas->hMasaIsmData != NULL ) { - IF ( st_ivas->hMasaIsmData->delayBuffer_fx != NULL ) + IF( st_ivas->hMasaIsmData->delayBuffer_fx != NULL ) { - FOR ( i = 0; i < st_ivas->hMasaIsmData->delayBuffer_nchan; i++ ) + FOR( i = 0; i < st_ivas->hMasaIsmData->delayBuffer_nchan; i++ ) { - IF ( st_ivas->hMasaIsmData->delayBuffer_fx[i] != NULL ) + IF( st_ivas->hMasaIsmData->delayBuffer_fx[i] != NULL ) { free( st_ivas->hMasaIsmData->delayBuffer_fx[i] ); st_ivas->hMasaIsmData->delayBuffer_fx[i] = NULL; @@ -802,9 +801,9 @@ void ivas_omasa_separate_object_renderer_close( #ifndef IVAS_FLOAT_FIXED void ivas_omasa_separate_object_render_jbm( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const uint16_t nSamplesRendered, /* i : number of samples rendered */ - float input_f_in[][L_FRAME48k], /* i : separated object signal */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const uint16_t nSamplesRendered, /* i : number of samples rendered */ + float input_f_in[][L_FRAME48k], /* i : separated object signal */ float *output_f[], /* o : rendered time signal */ const int16_t subframes_rendered, /* i : number of subframes rendered */ const int16_t slots_rendered /* i : number of CLDFB slots rendered */ @@ -963,12 +962,12 @@ void ivas_omasa_separate_object_render_jbm( } #else void ivas_omasa_separate_object_render_jbm_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const UWord16 nSamplesRendered, /* i : number of samples rendered */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const UWord16 nSamplesRendered, /* i : number of samples rendered */ Word32 input_fx_in[][L_FRAME48k], /* i : separated object signal */ - Word32 *output_fx[], /* o : rendered time signal */ - const Word16 subframes_rendered, /* i : number of subframes rendered */ - const Word16 slots_rendered /* i : number of CLDFB slots rendered */ + Word32 *output_fx[], /* o : rendered time signal */ + const Word16 subframes_rendered, /* i : number of subframes rendered */ + const Word16 slots_rendered /* i : number of CLDFB slots rendered */ ) { VBAP_HANDLE hVBAPdata; @@ -1001,7 +1000,7 @@ void ivas_omasa_separate_object_render_jbm_fx( lfe_index = hDirACRend->hOutSetup.index_lfe[0]; move16(); - IF ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) + IF( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) { single_separated = 1; num_objects = 1; @@ -1014,23 +1013,23 @@ void ivas_omasa_separate_object_render_jbm_fx( move16(); } - offsetSamples = i_mult(slots_rendered, hSpatParamRendCom->slot_size); + offsetSamples = i_mult( slots_rendered, hSpatParamRendCom->slot_size ); - FOR ( j = 0; j < nchan_out_woLFE + num_lfe; j++ ) + FOR( j = 0; j < nchan_out_woLFE + num_lfe; j++ ) { output_fx_local[j] = output_fx[j]; } - IF ( st_ivas->hDecoderConfig->Opt_tsm ) + IF( st_ivas->hDecoderConfig->Opt_tsm ) { - FOR ( obj = 0; obj < num_objects; obj++ ) + FOR( obj = 0; obj < num_objects; obj++ ) { input_fx[obj] = &st_ivas->hTcBuffer->tc_fx[obj + 2][offsetSamples]; } } ELSE { - FOR ( obj = 0; obj < num_objects; obj++ ) + FOR( obj = 0; obj < num_objects; obj++ ) { input_fx[obj] = input_fx_in[obj]; } @@ -1043,30 +1042,30 @@ void ivas_omasa_separate_object_render_jbm_fx( last_sf = first_sf; move16(); - WHILE ( slots_to_render > 0 ) + WHILE( slots_to_render > 0 ) { - slots_to_render = sub(slots_to_render, hSpatParamRendCom->subframe_nbslots[last_sf]); - last_sf = add(last_sf, 1); + slots_to_render = sub( slots_to_render, hSpatParamRendCom->subframe_nbslots[last_sf] ); + last_sf = add( last_sf, 1 ); } - FOR ( obj = 0; obj < num_objects; obj++ ) + FOR( obj = 0; obj < num_objects; obj++ ) { /* Delay the signal to match CLDFB delay. Delay the whole buffer with the first rendering call of the stretched buffer. */ - IF ( slots_rendered == 0 ) + IF( slots_rendered == 0 ) { Word16 tcBufferSize; - tcBufferSize = i_mult(hSpatParamRendCom->num_slots, hSpatParamRendCom->slot_size); + tcBufferSize = i_mult( hSpatParamRendCom->num_slots, hSpatParamRendCom->slot_size ); delay_signal_fx( input_fx[obj], tcBufferSize, st_ivas->hMasaIsmData->delayBuffer_fx[obj], st_ivas->hMasaIsmData->delayBuffer_size ); } offsetSamples = 0; - FOR ( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ ) + FOR( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ ) { - n_samples_sf = i_mult(hSpatParamRendCom->subframe_nbslots[subframe_idx], hSpatParamRendCom->slot_size); - IF ( n_samples_sf != hRendererData->interpolator_len ) + n_samples_sf = i_mult( hSpatParamRendCom->subframe_nbslots[subframe_idx], hSpatParamRendCom->slot_size ); + IF( n_samples_sf != hRendererData->interpolator_len ) { - FOR ( k = 0; k < n_samples_sf; k++ ) + FOR( k = 0; k < n_samples_sf; k++ ) { hRendererData->interpolator_fx[k] = div_s( k, n_samples_sf ); } @@ -1077,7 +1076,7 @@ void ivas_omasa_separate_object_render_jbm_fx( md_idx = hSpatParamRendCom->render_to_md_map[subframe_idx]; move16(); - IF ( single_separated ) + IF( single_separated ) { azimuth = st_ivas->hMasaIsmData->azimuth_separated_ism[md_idx]; move16(); @@ -1092,14 +1091,14 @@ void ivas_omasa_separate_object_render_jbm_fx( move16(); } - IF ( st_ivas->hOutSetup.is_planar_setup ) + IF( st_ivas->hOutSetup.is_planar_setup ) { /* If no elevation support in output format, then rendering should be done with zero elevation */ elevation = 0; move16(); } - IF ( hVBAPdata != NULL ) + IF( hVBAPdata != NULL ) { vbap_determine_gains_fx( hVBAPdata, gains_fx, azimuth, elevation, 1 ); } @@ -1108,11 +1107,11 @@ void ivas_omasa_separate_object_render_jbm_fx( ivas_dirac_dec_get_response_fixed( azimuth, elevation, gains_fx, hDirACRend->hOutSetup.ambisonics_order ); } - FOR ( j = 0; j < nchan_out_woLFE; j++ ) + FOR( j = 0; j < nchan_out_woLFE; j++ ) { - IF ( GT_16(hDirACRend->hOutSetup.num_lfe, 0) ) + IF( GT_16( hDirACRend->hOutSetup.num_lfe, 0 ) ) { - j2 = add(j, (Word16)GE_16( j, lfe_index )); + j2 = add( j, (Word16) GE_16( j, lfe_index ) ); } ELSE { @@ -1120,22 +1119,22 @@ void ivas_omasa_separate_object_render_jbm_fx( move16(); } - IF ( GT_32(L_abs( gains_fx[j] ), 0) || GT_32(L_abs( hRendererData->prev_gains_fx[obj][j] ), 0) ) + IF( GT_32( L_abs( gains_fx[j] ), 0 ) || GT_32( L_abs( hRendererData->prev_gains_fx[obj][j] ), 0 ) ) { - FOR ( k = 0; k < n_samples_sf; k++ ) + FOR( k = 0; k < n_samples_sf; k++ ) { g1_fx = hRendererData->interpolator_fx[k]; move16(); - g2_fx = sub(32767, g1_fx); + g2_fx = sub( 32767, g1_fx ); move16(); - output_fx_local[j2][k + offsetSamples] = L_add(output_fx_local[j2][k + offsetSamples], L_add(L_shl(Mpy_32_32(Mpy_32_16_1(input_fx[obj][k + offsetSamples], g1_fx), gains_fx[j]), 2), L_shl(Mpy_32_32(Mpy_32_16_1(input_fx[obj][k + offsetSamples], g2_fx), hRendererData->prev_gains_fx[obj][j]), 2))); + output_fx_local[j2][k + offsetSamples] = L_add( output_fx_local[j2][k + offsetSamples], L_add( L_shl( Mpy_32_32( Mpy_32_16_1( input_fx[obj][k + offsetSamples], g1_fx ), gains_fx[j] ), 2 ), L_shl( Mpy_32_32( Mpy_32_16_1( input_fx[obj][k + offsetSamples], g2_fx ), hRendererData->prev_gains_fx[obj][j] ), 2 ) ) ); } } hRendererData->prev_gains_fx[obj][j] = gains_fx[j]; move32(); } - offsetSamples = add(offsetSamples, n_samples_sf); + offsetSamples = add( offsetSamples, n_samples_sf ); } } diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index 7e0267be1..d3021e92a 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -57,7 +57,7 @@ *-----------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -static void ivas_jbm_dec_copy_tc( Decoder_Struct *st_ivas, const Word16 nSamplesForRendering, Word16 *nSamplesResidual, Word32 *data, Word32 *tc_digest_f[], Word16 data_q); +static void ivas_jbm_dec_copy_tc( Decoder_Struct *st_ivas, const Word16 nSamplesForRendering, Word16 *nSamplesResidual, Word32 *data, Word32 *tc_digest_f[], Word16 data_q ); #else static void ivas_jbm_dec_copy_tc( Decoder_Struct *st_ivas, const int16_t nSamplesForRendering, int16_t *nSamplesResidual, float *data, float *tc_digest_f[] ); #endif @@ -100,11 +100,10 @@ static Word16 ceil_fx16( Word16 inp, Word16 Q ) #ifdef IVAS_FLOAT_FIXED ivas_error ivas_jbm_dec_tc_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - Word32 *data_fx -) + Word32 *data_fx ) { Word16 n, output_frame, nchan_out, i; - Decoder_State *st; /* used for bitstream handling */ + Decoder_State *st; /* used for bitstream handling */ Word32 *p_output_fx[MAX_TRANSPORT_CHANNELS]; /* 'float' buffer for output synthesis */ Word16 nchan_remapped; Word16 nb_bits_metadata[MAX_SCE + 1]; @@ -146,11 +145,11 @@ ivas_error ivas_jbm_dec_tc_fx( { FOR( n = 0; n < ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); n++ ) { - set_zero_fx(st_ivas->p_output_fx[n], L_FRAME48k); + set_zero_fx( st_ivas->p_output_fx[n], L_FRAME48k ); st_ivas->hTcBuffer->tc_fx[n] = st_ivas->p_output_fx[n]; } #ifdef MSAN_FIX - st_ivas->hTcBuffer->no_channels = ivas_get_nchan_buffers_dec(st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate); + st_ivas->hTcBuffer->no_channels = ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); #endif } @@ -172,7 +171,8 @@ ivas_error ivas_jbm_dec_tc_fx( ELSE IF( st_ivas->ivas_format == STEREO_FORMAT ) { st_ivas->hCPE[0]->element_brate = ivas_total_brate; - Word16 q_output = 11; move16(); + Word16 q_output = 11; + move16(); set32_fx( &p_output_fx[0][0], 0, L_FRAME48k ); set32_fx( &p_output_fx[1][0], 0, L_FRAME48k ); @@ -226,14 +226,14 @@ ivas_error ivas_jbm_dec_tc_fx( { IF( st_ivas->hSCE[ch] != NULL ) { - Word16 shift = getScaleFactor32(st_ivas->hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN); - IF(LT_16(sub(st_ivas->hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift), 4)) + Word16 shift = getScaleFactor32( st_ivas->hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN ); + IF( LT_16( sub( st_ivas->hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ), 4 ) ) { - shift = sub(st_ivas->hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4); + shift = sub( st_ivas->hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 ); } - scale_sig32(st_ivas->hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift); - st_ivas->hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub(st_ivas->hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift); - Q_cngNoiseLevel[ch] = sub(31, st_ivas->hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp); + scale_sig32( st_ivas->hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); + st_ivas->hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ); + Q_cngNoiseLevel[ch] = sub( 31, st_ivas->hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp ); } } ivas_ism_dtx_limit_noise_energy_for_near_silence_fx( st_ivas->hSCE, st_ivas->hISMDTX.sce_id_dtx, st_ivas->nchan_transport, Q_cngNoiseLevel ); @@ -352,7 +352,7 @@ ivas_error ivas_jbm_dec_tc_fx( } ELSE IF( GT_16( st_ivas->nCPE, 1 ) ) { - IF ( ( error = ivas_mct_dec_fx( st_ivas, p_output_fx, output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_mct_dec_fx( st_ivas, p_output_fx, output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { return error; } @@ -385,14 +385,15 @@ ivas_error ivas_jbm_dec_tc_fx( ivas_pca_dec_fx( st_ivas->hSpar->hPCA, output_frame, st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate, st_ivas->bfi, p_output_fx ); } - ivas_spar_dec_gen_umx_mat_fx( st_ivas->hSpar->hMdDec, st_ivas->nchan_transport, IVAS_MAX_NUM_BANDS, st_ivas->bfi, ivas_get_spar_dec_md_num_subframes(st_ivas->sba_order, ivas_total_brate, st_ivas->last_active_ivas_total_brate)); + ivas_spar_dec_gen_umx_mat_fx( st_ivas->hSpar->hMdDec, st_ivas->nchan_transport, IVAS_MAX_NUM_BANDS, st_ivas->bfi, ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, ivas_total_brate, st_ivas->last_active_ivas_total_brate ) ); } { Word16 q; hCPE = st_ivas->hCPE[0]; hSCE = st_ivas->hSCE[0]; - s = 0; move16(); + s = 0; + move16(); FOR( i = 0; i < 2; i++ ) { s = s_min( s, L_norm_arr( p_output_fx[i], L_FRAME48k ) - 11 ) /* Guard bits */; @@ -411,7 +412,7 @@ ivas_error ivas_jbm_dec_tc_fx( } q = hCPE->hStereoDft->q_dft; move16(); - scale_sig32(hCPE->input_mem_BPF_fx[0], STEREO_DFT32MS_OVL_16k, sub(hCPE->hStereoDft->q_dft, Q11)); + scale_sig32( hCPE->input_mem_BPF_fx[0], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) ); FOR( i = 0; i < CPE_CHANNELS; ++i ) { scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) ); @@ -419,8 +420,8 @@ ivas_error ivas_jbm_dec_tc_fx( } IF( hCPE->hCoreCoder[0] != NULL ) { - Copy_Scale_sig_16_32(hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx,L_FRAME32k,q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB); - Copy_Scale_sig_16_32(hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx,L_FRAME48k,q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda); + Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, L_FRAME32k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ); + Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, L_FRAME48k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda ); hCPE->hCoreCoder[0]->hHQ_core->q_old_outLB_fx = q; } IF( hCPE->hStereoDft != NULL ) @@ -498,7 +499,7 @@ ivas_error ivas_jbm_dec_tc_fx( Scale_sig32( &hCPE->prev_synth_fx[0][0], sizeof( hCPE->prev_synth_fx ) / sizeof( hCPE->prev_synth_fx[0][0] ), 11 - hCPE->q_prev_synth_fx ); #endif - scale_sig32(hCPE->input_mem_BPF_fx[0], STEREO_DFT32MS_OVL_16k, sub(Q11, hCPE->hStereoDft->q_dft)); + scale_sig32( hCPE->input_mem_BPF_fx[0], STEREO_DFT32MS_OVL_16k, sub( Q11, hCPE->hStereoDft->q_dft ) ); FOR( i = 0; i < CPE_CHANNELS; ++i ) { scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( Q11, hCPE->hStereoDft->q_dft ) ); @@ -548,7 +549,7 @@ ivas_error ivas_jbm_dec_tc_fx( hCPE->hStereoDft->q_ap_fade_mem_fx = Q11; } st_ivas->hSpar->hMdDec->Q_mixer_mat = 30; - FOR ( Word16 ii = 0; ii < CPE_CHANNELS; ii++ ) + FOR( Word16 ii = 0; ii < CPE_CHANNELS; ii++ ) { scale_sig32( hCPE->output_mem_fx[ii], NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); hCPE->q_output_mem_fx[ii] = Q11; @@ -597,11 +598,11 @@ ivas_error ivas_jbm_dec_tc_fx( Scale_sig32( p_output_fx[c], output_frame, 11 ); } } - ELSE IF ( st_ivas->renderer_type != RENDERER_DISABLE ) + ELSE IF( st_ivas->renderer_type != RENDERER_DISABLE ) { Word16 size = st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport; - IF ( st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport == 3 ) - size = add( size, 1 ); + IF( st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport == 3 ) + size = add( size, 1 ); FOR( i = 0; i < size; i++ ) { @@ -658,20 +659,22 @@ ivas_error ivas_jbm_dec_tc_fx( /* set ISM parameters and decode ISM metadata in OMASA format */ - Word16 q_output = 11; move16(); + Word16 q_output = 11; + move16(); // NOTE: the following is done to calculate the number of hIsmMetaData indices Word16 tmp_nchan_ism; - IF(st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ) + IF( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) { tmp_nchan_ism = 1; move16(); } - ELSE IF(st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ) + ELSE IF( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) { tmp_nchan_ism = 0; move16(); } - ELSE{ + ELSE + { tmp_nchan_ism = st_ivas->nchan_ism; move16(); } @@ -761,7 +764,6 @@ ivas_error ivas_jbm_dec_tc_fx( Scale_sig32( p_output_fx[n], output_frame, sub( Q11, output_q ) ); } } - } ELSE IF( st_ivas->ivas_format == SBA_ISM_FORMAT ) { @@ -772,7 +774,7 @@ ivas_error ivas_jbm_dec_tc_fx( IF( st_ivas->ism_mode == ISM_SBA_MODE_DISC ) { /* set ISM parameters and decode ISM metadata in OSBA format */ - IF((error = ivas_osba_ism_metadata_dec_fx(st_ivas, ivas_total_brate, &nchan_ism, &nb_bits_metadata[1])) != IVAS_ERR_OK) + IF( ( error = ivas_osba_ism_metadata_dec_fx( st_ivas, ivas_total_brate, &nchan_ism, &nb_bits_metadata[1] ) ) != IVAS_ERR_OK ) { return error; } @@ -796,7 +798,8 @@ ivas_error ivas_jbm_dec_tc_fx( } /* core-decoding of transport channels */ - Word16 q_output = 11; move16(); + Word16 q_output = 11; + move16(); IF( EQ_16( st_ivas->nSCE, 1 ) ) { @@ -823,13 +826,13 @@ ivas_error ivas_jbm_dec_tc_fx( } ELSE IF( GT_16( st_ivas->nCPE, 1 ) ) { - IF ( ( error = ivas_mct_dec_fx( st_ivas, p_output_fx, output_frame, nb_bits_metadata[0] + nb_bits_metadata[1] ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_mct_dec_fx( st_ivas, p_output_fx, output_frame, nb_bits_metadata[0] + nb_bits_metadata[1] ) ) != IVAS_ERR_OK ) { return error; } } - IF ( st_ivas->sba_dirac_stereo_flag ) + IF( st_ivas->sba_dirac_stereo_flag ) { FOR( i = 0; i < st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport; i++ ) { @@ -837,9 +840,12 @@ ivas_error ivas_jbm_dec_tc_fx( } SPAR_DEC_HANDLE hSpar = st_ivas->hSpar; Word16 nchan_transport; - nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; move16(); - nchan_out = nchan_transport; move16(); - hSpar->hMdDec->Q_mixer_mat = 31; move16(); + nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; + move16(); + nchan_out = nchan_transport; + move16(); + hSpar->hMdDec->Q_mixer_mat = 31; + move16(); ivas_agc_dec_process_fx( st_ivas->hSpar->hAgcDec, ( p_output_fx + sba_ch_idx ), ( p_output_fx + sba_ch_idx ), st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, output_frame ); IF( st_ivas->hSpar->hPCA != NULL ) @@ -851,7 +857,8 @@ ivas_error ivas_jbm_dec_tc_fx( Word16 q; hCPE = st_ivas->hCPE[0]; hSCE = st_ivas->hSCE[0]; - s = 0; move16(); + s = 0; + move16(); FOR( i = 0; i < 2; i++ ) { s = s_min( s, L_norm_arr( p_output_fx[sba_ch_idx + i], L_FRAME48k ) - 11 /* Guard bits */ ); @@ -867,7 +874,8 @@ ivas_error ivas_jbm_dec_tc_fx( hCPE->hStereoDft->q_ap_delay_mem_fx = hCPE->hStereoDft->q_dft; } - q = hCPE->hStereoDft->q_dft; move16(); + q = hCPE->hStereoDft->q_dft; + move16(); scale_sig32( hCPE->input_mem_BPF_fx[0], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) ); FOR( i = 0; i < CPE_CHANNELS; ++i ) { @@ -904,19 +912,19 @@ ivas_error ivas_jbm_dec_tc_fx( FOR( i = 0; i < CPE_CHANNELS; i++ ) Scale_sig32( hCPE->prev_synth_fx[i], NS2SA_fx2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), hCPE->q_prev_synth_fx - 11 ); #else - Scale_sig32( &hCPE->prev_synth_fx[0][0], sizeof( hCPE->prev_synth_fx) / sizeof(hCPE->prev_synth_fx[0][0]), hCPE->q_prev_synth_fx - 11); + Scale_sig32( &hCPE->prev_synth_fx[0][0], sizeof( hCPE->prev_synth_fx ) / sizeof( hCPE->prev_synth_fx[0][0] ), hCPE->q_prev_synth_fx - 11 ); #endif - ivas_sba_dirac_stereo_dec_fx(st_ivas, &p_output_fx[sba_ch_idx], output_frame, 0); - FOR(i = 0; i < 2; i++) + ivas_sba_dirac_stereo_dec_fx( st_ivas, &p_output_fx[sba_ch_idx], output_frame, 0 ); + FOR( i = 0; i < 2; i++ ) { - Scale_sig32(p_output_fx[sba_ch_idx + i], L_FRAME48k, negate(s)); + Scale_sig32( p_output_fx[sba_ch_idx + i], L_FRAME48k, negate( s ) ); } #ifdef MSAN_FIX FOR( i = 0; i < CPE_CHANNELS; i++ ) Scale_sig32( hCPE->prev_synth_fx[i], NS2SA_fx2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), 11 - hCPE->q_prev_synth_fx ); #else - Scale_sig32(&hCPE->prev_synth_fx[0][0], sizeof(hCPE->prev_synth_fx) / sizeof(hCPE->prev_synth_fx[0][0] ), 11 - hCPE->q_prev_synth_fx ); + Scale_sig32( &hCPE->prev_synth_fx[0][0], sizeof( hCPE->prev_synth_fx ) / sizeof( hCPE->prev_synth_fx[0][0] ), 11 - hCPE->q_prev_synth_fx ); #endif scale_sig32( hCPE->input_mem_BPF_fx[0], STEREO_DFT32MS_OVL_16k, sub( Q11, hCPE->hStereoDft->q_dft ) ); @@ -939,7 +947,7 @@ ivas_error ivas_jbm_dec_tc_fx( hCPE->hStereoDft->q_ap_fade_mem_fx = Q11; } st_ivas->hSpar->hMdDec->Q_mixer_mat = 30; - FOR (int ii = 0; ii < CPE_CHANNELS; ii++) + FOR( int ii = 0; ii < CPE_CHANNELS; ii++ ) { scale_sig32( hCPE->output_mem_fx[ii], NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); hCPE->q_output_mem_fx[ii] = Q11; @@ -961,7 +969,7 @@ ivas_error ivas_jbm_dec_tc_fx( SPAR_DEC_HANDLE hSpar = st_ivas->hSpar; Word16 Q_p_output = 14; Word16 nchan_transport; - //num_bands_out = hSpar->hFbMixer->pFb->filterbank_num_bands; + // num_bands_out = hSpar->hFbMixer->pFb->filterbank_num_bands; nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; nchan_out = nchan_transport; FOR( ch = 0; ch < nchan_transport; ch++ ) @@ -975,7 +983,6 @@ ivas_error ivas_jbm_dec_tc_fx( { Scale_sig32( p_output_fx[sba_ch_idx + c], output_frame, Q11 ); } - } ELSE IF( st_ivas->renderer_type != RENDERER_DISABLE && EQ_16( st_ivas->sba_dirac_stereo_flag, 0 ) ) { @@ -1076,7 +1083,7 @@ ivas_error ivas_jbm_dec_tc_fx( ivas_mc_paramupmix_dec_read_BS( st_ivas, st, st_ivas->hMCParamUpmix, &nb_bits_metadata[0] ); - IF ( ( error = ivas_mct_dec_fx( st_ivas, p_output_fx, output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_mct_dec_fx( st_ivas, p_output_fx, output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { return error; } @@ -1137,7 +1144,7 @@ ivas_error ivas_jbm_dec_tc_fx( } ELSE IF( st_ivas->nCPE > 1 ) { - IF ( ( error = ivas_mct_dec_fx( st_ivas, p_output_fx, output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_mct_dec_fx( st_ivas, p_output_fx, output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { return error; } @@ -1216,12 +1223,13 @@ ivas_error ivas_jbm_dec_tc_fx( ELSE IF( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM && EQ_16( st_ivas->hOutSetup.num_lfe, 0 ) ) { /* Delay the separated channel to sync with the DirAC rendering */ - delay_signal_fx(p_output_fx[n], output_frame, st_ivas->hMasa->hMasaLfeSynth->delayBuffer_syncDirAC_fx, st_ivas->hMasa->hMasaLfeSynth->delayBuffer_syncDirAC_size ); + delay_signal_fx( p_output_fx[n], output_frame, st_ivas->hMasa->hMasaLfeSynth->delayBuffer_syncDirAC_fx, st_ivas->hMasa->hMasaLfeSynth->delayBuffer_syncDirAC_size ); } } ELSE { - Word16 q_output = 11; move16(); + Word16 q_output = 11; + move16(); IF( EQ_16( st_ivas->nSCE, 1 ) ) { set32_fx( p_output_fx[0], 0, L_FRAME48k ); @@ -1251,7 +1259,8 @@ ivas_error ivas_jbm_dec_tc_fx( Word16 q; hCPE = st_ivas->hCPE[0]; hSCE = st_ivas->hSCE[0]; - s = 0; move16(); + s = 0; + move16(); FOR( i = 0; i < 2; i++ ) { s = s_min( s, L_norm_arr( p_output_fx[i], L_FRAME48k ) - 11 /* Guard bits */ ); @@ -1305,21 +1314,21 @@ ivas_error ivas_jbm_dec_tc_fx( hCPE->q_output_mem_fx[ii] = hCPE->hStereoDft->q_dft; } #ifdef MSAN_FIX - FOR ( i = 0; i < CPE_CHANNELS; i++ ) - Scale_sig32( hCPE->prev_synth_fx[i], NS2SA_fx2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), hCPE->q_prev_synth_fx - 11 ); + FOR( i = 0; i < CPE_CHANNELS; i++ ) + Scale_sig32( hCPE->prev_synth_fx[i], NS2SA_fx2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), hCPE->q_prev_synth_fx - 11 ); #else - Scale_sig32( &hCPE->prev_synth_fx[0][0], sizeof( hCPE->prev_synth_fx) / sizeof(hCPE->prev_synth_fx[0][0]), hCPE->q_prev_synth_fx - 11); + Scale_sig32( &hCPE->prev_synth_fx[0][0], sizeof( hCPE->prev_synth_fx ) / sizeof( hCPE->prev_synth_fx[0][0] ), hCPE->q_prev_synth_fx - 11 ); #endif - ivas_sba_dirac_stereo_dec_fx(st_ivas, p_output_fx, output_frame, 1); - FOR(i = 0; i < 2; i++) + ivas_sba_dirac_stereo_dec_fx( st_ivas, p_output_fx, output_frame, 1 ); + FOR( i = 0; i < 2; i++ ) { - Scale_sig32(p_output_fx[i], L_FRAME48k, negate(s)); + Scale_sig32( p_output_fx[i], L_FRAME48k, negate( s ) ); } #ifdef MSAN_FIX - FOR ( i = 0; i < CPE_CHANNELS; i++ ) - Scale_sig32( hCPE->prev_synth_fx[i], NS2SA_fx2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), 11 - hCPE->q_prev_synth_fx); + FOR( i = 0; i < CPE_CHANNELS; i++ ) + Scale_sig32( hCPE->prev_synth_fx[i], NS2SA_fx2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), 11 - hCPE->q_prev_synth_fx ); #else - Scale_sig32(&hCPE->prev_synth_fx[0][0], sizeof(hCPE->prev_synth_fx) / sizeof(hCPE->prev_synth_fx[0][0] ), 11 - hCPE->q_prev_synth_fx ); + Scale_sig32( &hCPE->prev_synth_fx[0][0], sizeof( hCPE->prev_synth_fx ) / sizeof( hCPE->prev_synth_fx[0][0] ), 11 - hCPE->q_prev_synth_fx ); #endif // MSAN_FIX scale_sig32( hCPE->input_mem_BPF_fx[0], STEREO_DFT32MS_OVL_16k, sub( Q11, hCPE->hStereoDft->q_dft ) ); @@ -1342,11 +1351,13 @@ ivas_error ivas_jbm_dec_tc_fx( } IF( st_ivas->hSpar != NULL ) { - st_ivas->hSpar->hMdDec->Q_mixer_mat = 31; move16(); + st_ivas->hSpar->hMdDec->Q_mixer_mat = 31; + move16(); FOR( Word16 ii = 0; ii < CPE_CHANNELS; ii++ ) { scale_sig32( hCPE->output_mem_fx[ii], NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); - hCPE->q_output_mem_fx[ii] = Q11; move16(); + hCPE->q_output_mem_fx[ii] = Q11; + move16(); } } } @@ -1368,34 +1379,34 @@ ivas_error ivas_jbm_dec_tc_fx( * Write IVAS transport channels *----------------------------------------------------------------*/ - IF ( EQ_16( st_ivas->hDecoderConfig->Opt_tsm, 1 ) ) + IF( EQ_16( st_ivas->hDecoderConfig->Opt_tsm, 1 ) ) { - ivas_syn_output_f_fx(p_output_fx, output_frame, st_ivas->hTcBuffer->nchan_transport_jbm, data_fx ); + ivas_syn_output_f_fx( p_output_fx, output_frame, st_ivas->hTcBuffer->nchan_transport_jbm, data_fx ); } ELSE { /* directly copy to tc buffers */ /*note : the q of cldfb buffers (imag/real) are needed to be Q_p_output - 5 here 6 is taken for that*/ ivas_jbm_dec_copy_tc_no_tsm_fx( st_ivas, p_output_fx, output_frame ); - } /*----------------------------------------------------------------* * Common updates *----------------------------------------------------------------*/ - IF ( !st_ivas->bfi ) /* do not update if first frame(s) are lost or NO_DATA */ + IF( !st_ivas->bfi ) /* do not update if first frame(s) are lost or NO_DATA */ { - st_ivas->hDecoderConfig->last_ivas_total_brate = ivas_total_brate; move32(); + st_ivas->hDecoderConfig->last_ivas_total_brate = ivas_total_brate; + move32(); st_ivas->last_active_ivas_total_brate = ( ivas_total_brate <= IVAS_SID_5k2 ) ? st_ivas->last_active_ivas_total_brate : ivas_total_brate; } - IF ( st_ivas->ini_frame < MAX_FRAME_COUNTER && !( st_ivas->bfi && st_ivas->ini_frame == 0 ) ) /* keep "st_ivas->ini_frame = 0" until first good received frame */ + IF( st_ivas->ini_frame < MAX_FRAME_COUNTER && !( st_ivas->bfi && st_ivas->ini_frame == 0 ) ) /* keep "st_ivas->ini_frame = 0" until first good received frame */ { st_ivas->ini_frame = add( st_ivas->ini_frame, 1 ); } - IF ( st_ivas->ini_active_frame < MAX_FRAME_COUNTER && !( st_ivas->bfi && st_ivas->ini_frame == 0 ) && ivas_total_brate > IVAS_SID_5k2 ) /* needed in MASA decoder in case the first active frame is BFI, and there were SID-frames decoded before */ + IF( st_ivas->ini_active_frame < MAX_FRAME_COUNTER && !( st_ivas->bfi && st_ivas->ini_frame == 0 ) && ivas_total_brate > IVAS_SID_5k2 ) /* needed in MASA decoder in case the first active frame is BFI, and there were SID-frames decoded before */ { st_ivas->ini_active_frame = add( st_ivas->ini_active_frame, 1 ); } @@ -1463,7 +1474,6 @@ ivas_error ivas_jbm_dec_tc( { set_f( p_output[n], 0.0f, output_frame ); } - } else if ( st_ivas->ivas_format == STEREO_FORMAT ) { @@ -1987,7 +1997,7 @@ ivas_error ivas_jbm_dec_tc( else if ( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM && st_ivas->hOutSetup.num_lfe == 0 ) { /* Delay the separated channel to sync with the DirAC rendering */ - delay_signal_float( p_output[n], output_frame, st_ivas->hMasa->hMasaLfeSynth->delayBuffer_syncDirAC, st_ivas->hMasa->hMasaLfeSynth->delayBuffer_syncDirAC_size ); + delay_signal_float( p_output[n], output_frame, st_ivas->hMasa->hMasaLfeSynth->delayBuffer_syncDirAC, st_ivas->hMasa->hMasaLfeSynth->delayBuffer_syncDirAC_size ); } } else @@ -2076,10 +2086,10 @@ ivas_error ivas_jbm_dec_tc( *--------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED void ivas_jbm_dec_feed_tc_to_renderer( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const int16_t nSamplesForRendering, /* i : number of TC samples available for rendering */ - int16_t *nSamplesResidual, /* o : number of samples not fitting into the renderer grid and buffer for the next call*/ - float *data /* i : transport channels */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const int16_t nSamplesForRendering, /* i : number of TC samples available for rendering */ + int16_t *nSamplesResidual, /* o : number of samples not fitting into the renderer grid and buffer for the next call*/ + float *data /* i : transport channels */ ) { float data_f[MAX_CLDFB_DIGEST_CHANNELS][MAX_JBM_L_FRAME48k] = { 0 }; /* 'float' buffer for transport channels that will be directly converted with the CLDFB */ @@ -2087,20 +2097,22 @@ void ivas_jbm_dec_feed_tc_to_renderer( #ifdef IVAS_FLOAT_FIXED Word32 data_f_fx[MAX_CLDFB_DIGEST_CHANNELS][MAX_JBM_L_FRAME48k] = { 0 }; /* 'float' buffer for transport channels that will be directly converted with the CLDFB */ Word32 *p_data_f_fx[MAX_CLDFB_DIGEST_CHANNELS]; - Word32* data_fx; - data_fx = (Word32*)malloc(8640 * sizeof(Word32)); + Word32 *data_fx; + data_fx = (Word32 *) malloc( 8640 * sizeof( Word32 ) ); - IF(st_ivas->hTcBuffer){ + IF( st_ivas->hTcBuffer ) + { st_ivas->hTcBuffer->q_tc_fx = 11; } - IF(st_ivas->hSpar){ + IF( st_ivas->hSpar ) + { st_ivas->hSpar->hMdDec->Q_mixer_mat = 31; } #endif Word16 n, n_render_timeslots, i; push_wmops( "ivas_jbm_dec_feed_tc_to_rendererer" ); - FOR ( n = 0; n < MAX_CLDFB_DIGEST_CHANNELS; n++ ) + FOR( n = 0; n < MAX_CLDFB_DIGEST_CHANNELS; n++ ) { p_data_f[n] = &data_f[n][0]; #ifdef IVAS_FLOAT_FIXED @@ -2108,71 +2120,74 @@ void ivas_jbm_dec_feed_tc_to_renderer( #endif } - IF ( st_ivas->hDecoderConfig->Opt_tsm ) + IF( st_ivas->hDecoderConfig->Opt_tsm ) { #ifdef IVAS_FLOAT_FIXED #if 1 - floatToFixed_arrL(data, data_fx, 11, s_min(3, st_ivas->hTcBuffer->nchan_transport_jbm)*2880); + floatToFixed_arrL( data, data_fx, 11, s_min( 3, st_ivas->hTcBuffer->nchan_transport_jbm ) * 2880 ); #endif - ivas_jbm_dec_copy_tc( st_ivas, nSamplesForRendering, nSamplesResidual, data_fx, p_data_f_fx, 11); + ivas_jbm_dec_copy_tc( st_ivas, nSamplesForRendering, nSamplesResidual, data_fx, p_data_f_fx, 11 ); -#if 1 //To-be-removed +#if 1 // To-be-removed Word16 ch; if ( st_ivas->hTcBuffer->nchan_transport_jbm - st_ivas->hTcBuffer->nchan_buffer_full > 0 ) { - for (ch = min( st_ivas->hTcBuffer->nchan_transport_jbm, st_ivas->hTcBuffer->nchan_buffer_full ) ; ch < st_ivas->hTcBuffer->nchan_transport_jbm; ch++ ) + for ( ch = min( st_ivas->hTcBuffer->nchan_transport_jbm, st_ivas->hTcBuffer->nchan_buffer_full ); ch < st_ivas->hTcBuffer->nchan_transport_jbm; ch++ ) { - fixedToFloat_arrL(p_data_f_fx[ch], p_data_f[ch], st_ivas->hTcBuffer->q_tc_fx, MAX_JBM_L_FRAME48k); + fixedToFloat_arrL( p_data_f_fx[ch], p_data_f[ch], st_ivas->hTcBuffer->q_tc_fx, MAX_JBM_L_FRAME48k ); } } #endif #else - ivas_jbm_dec_copy_tc( st_ivas, nSamplesForRendering, nSamplesResidual, data, p_data_f ); + ivas_jbm_dec_copy_tc( st_ivas, nSamplesForRendering, nSamplesResidual, data, p_data_f ); #endif } ELSE { - *nSamplesResidual = 0; move16(); + *nSamplesResidual = 0; + move16(); } - n_render_timeslots = idiv1616(st_ivas->hTcBuffer->n_samples_available, st_ivas->hTcBuffer->n_samples_granularity); + n_render_timeslots = idiv1616( st_ivas->hTcBuffer->n_samples_available, st_ivas->hTcBuffer->n_samples_granularity ); - IF ( EQ_16(st_ivas->hTcBuffer->tc_buffer_mode, TC_BUFFER_MODE_BUFFER )) + IF( EQ_16( st_ivas->hTcBuffer->tc_buffer_mode, TC_BUFFER_MODE_BUFFER ) ) { ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas ); - test(); test(); - IF ( ( EQ_16(st_ivas->ivas_format, MASA_FORMAT) || EQ_16(st_ivas->ivas_format, MASA_ISM_FORMAT) ) && EQ_16(st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL) ) + test(); + test(); + IF( ( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) || EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) && EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) { ivas_jbm_masa_sf_to_slot_map( st_ivas, n_render_timeslots ); } } - ELSE IF ( EQ_16(st_ivas->ivas_format, STEREO_FORMAT )) + ELSE IF( EQ_16( st_ivas->ivas_format, STEREO_FORMAT ) ) { ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas ); } - ELSE IF ( EQ_16(st_ivas->ivas_format, ISM_FORMAT )) + ELSE IF( EQ_16( st_ivas->ivas_format, ISM_FORMAT ) ) { /* Rendering */ - IF ( EQ_16(st_ivas->ism_mode, ISM_MODE_PARAM )) + IF( EQ_16( st_ivas->ism_mode, ISM_MODE_PARAM ) ) { - test(); test(); - IF ( EQ_16(st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC) || EQ_16(st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM) || EQ_16(st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC )) + test(); + test(); + IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_16( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) { ivas_dirac_dec_set_md_map_fx( st_ivas, n_render_timeslots ); ivas_param_ism_params_to_masa_param_mapping_fx( st_ivas ); } - ELSE IF ( EQ_16(st_ivas->renderer_type, RENDERER_PARAM_ISM) || EQ_16(st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC )) + ELSE IF( EQ_16( st_ivas->renderer_type, RENDERER_PARAM_ISM ) || EQ_16( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) { #ifdef IVAS_FLOAT_FIXED floatToFixed_arr32( p_data_f[0], p_data_f_fx[0], Q13, MAX_CLDFB_DIGEST_CHANNELS * MAX_JBM_L_FRAME48k ); -#if 1/*Float to fixed conversions*/ +#if 1 /*Float to fixed conversions*/ FOR( Word16 ch = 0; ch < MAX_INTERN_CHANNELS; ch++ ) { - IF(st_ivas->cldfbAnaDec[ch]) + IF( st_ivas->cldfbAnaDec[ch] ) { - scale_sig32(st_ivas->cldfbAnaDec[ch]->cldfb_state_fx, st_ivas->cldfbAnaDec[ch]->cldfb_size, sub(Q13, Q11)); + scale_sig32( st_ivas->cldfbAnaDec[ch]->cldfb_state_fx, st_ivas->cldfbAnaDec[ch]->cldfb_size, sub( Q13, Q11 ) ); st_ivas->cldfbAnaDec[ch]->Q_cldfb_state = Q13; } } @@ -2197,60 +2212,63 @@ void ivas_jbm_dec_feed_tc_to_renderer( ivas_ism_dec_digest_tc_fx( st_ivas ); } } - ELSE IF ( EQ_16(st_ivas->ivas_format, SBA_FORMAT) || EQ_16(st_ivas->ivas_format, MASA_FORMAT )) + ELSE IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, MASA_FORMAT ) ) { #if 1 - IF(st_ivas->hSCE[0]) + IF( st_ivas->hSCE[0] ) { - Word16 shift = getScaleFactor32(st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN); - IF(LT_16(sub(st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift), 4)) + Word16 shift = getScaleFactor32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN ); + IF( LT_16( sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ), 4 ) ) { - shift = sub(st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4); + shift = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 ); } - scale_sig32(st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift); - st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub(st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift); + scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); + st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ); } #endif ivas_sba_dec_digest_tc_fx( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available ); } - ELSE IF ( EQ_16(st_ivas->ivas_format, SBA_ISM_FORMAT )) + ELSE IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { - IF ( EQ_16(st_ivas->ism_mode, ISM_SBA_MODE_DISC )) + IF( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { ivas_ism_dec_digest_tc_fx( st_ivas ); - test();test();test();test(); + test(); + test(); + test(); + test(); /* delay the objects here for all renderers where it is needed */ - IF ( - EQ_16(st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV) || - EQ_16(st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM) || - EQ_16(st_ivas->renderer_type, RENDERER_OSBA_AMBI) || - EQ_16(st_ivas->renderer_type, RENDERER_OSBA_LS) || - EQ_16(st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL) ) + IF( + EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || + EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) || + EQ_16( st_ivas->renderer_type, RENDERER_OSBA_AMBI ) || + EQ_16( st_ivas->renderer_type, RENDERER_OSBA_LS ) || + EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) { - FOR ( n = 0; n < st_ivas->nchan_ism; n++ ) + FOR( n = 0; n < st_ivas->nchan_ism; n++ ) { delay_signal_fx( st_ivas->hTcBuffer->tc_fx[n], st_ivas->hTcBuffer->n_samples_available, st_ivas->hSbaIsmData->delayBuffer_fx[n], st_ivas->hSbaIsmData->delayBuffer_size ); } } - IF ( !st_ivas->sba_dirac_stereo_flag ) + IF( !st_ivas->sba_dirac_stereo_flag ) { - IF ( EQ_16(st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV) ) + IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) ) { n_render_timeslots *= ( st_ivas->hTcBuffer->n_samples_granularity / st_ivas->hSpatParamRendCom->slot_size ); } - IF(st_ivas->hSCE[0]) + IF( st_ivas->hSCE[0] ) { - Word16 shift = getScaleFactor32(st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN); - IF(LT_16(sub(st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift), 4)) + Word16 shift = getScaleFactor32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN ); + IF( LT_16( sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ), 4 ) ) { - shift = sub(st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4); + shift = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 ); } - scale_sig32(st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift); - st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub(st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift); + scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); + st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ); } ivas_sba_dec_digest_tc_fx( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available ); } @@ -2259,86 +2277,85 @@ void ivas_jbm_dec_feed_tc_to_renderer( { ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas ); - IF(st_ivas->hSCE[0]) + IF( st_ivas->hSCE[0] ) { - Word16 shift = getScaleFactor32(st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN); - IF(LT_16(sub(st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift), 4)) + Word16 shift = getScaleFactor32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN ); + IF( LT_16( sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ), 4 ) ) { - shift = sub(st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4); + shift = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 ); } - scale_sig32(st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift); - st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub(st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift); + scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); + st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ); } ivas_sba_dec_digest_tc_fx( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available ); } } - ELSE IF (EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT )) + ELSE IF( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) { - IF ( EQ_16(st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC) && EQ_16(st_ivas->ism_mode, ISM_MASA_MODE_DISC) ) + IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) && EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { - n_render_timeslots = i_mult(n_render_timeslots, idiv1616( st_ivas->hTcBuffer->n_samples_granularity, st_ivas->hSpatParamRendCom->slot_size )); + n_render_timeslots = i_mult( n_render_timeslots, idiv1616( st_ivas->hTcBuffer->n_samples_granularity, st_ivas->hSpatParamRendCom->slot_size ) ); } - IF(st_ivas->hSCE[0]) + IF( st_ivas->hSCE[0] ) { - Word16 shift = getScaleFactor32(st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN); - IF(LT_16(sub(st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift), 4)) + Word16 shift = getScaleFactor32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN ); + IF( LT_16( sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ), 4 ) ) { - shift = sub(st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4); + shift = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 ); } - scale_sig32(st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift); - st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub(st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift); + scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); + st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ); } ivas_sba_dec_digest_tc_fx( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available ); - IF ( EQ_16(st_ivas->ism_mode, ISM_MASA_MODE_DISC )) + IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { ivas_ism_dec_digest_tc_fx( st_ivas ); } } - ELSE IF ( EQ_16(st_ivas->ivas_format, MC_FORMAT )) + ELSE IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) ) { - IF ( EQ_16(st_ivas->mc_mode, MC_MODE_MCT )) + IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCT ) ) { ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas ); } - ELSE IF ( EQ_16(st_ivas->mc_mode, MC_MODE_PARAMUPMIX )) + ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) { ivas_mc_paramupmix_dec_digest_tc( st_ivas, (uint8_t) n_render_timeslots, st_ivas->hTcBuffer->n_samples_available ); } - ELSE IF ( EQ_16(st_ivas->mc_mode, MC_MODE_PARAMMC )) + ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_PARAMMC ) ) { #ifdef IVAS_FLOAT_FIXED Word16 cldfb_slots, j; cldfb_slots = DEFAULT_JBM_CLDFB_TIMESLOTS; - if (st_ivas->hDecoderConfig->Opt_tsm) + if ( st_ivas->hDecoderConfig->Opt_tsm ) { cldfb_slots = MAX_JBM_CLDFB_TIMESLOTS; } - f2me_buf(st_ivas->hParamMC->Cldfb_RealBuffer_tc, st_ivas->hParamMC->Cldfb_RealBuffer_tc_fx, &st_ivas->hParamMC->Cldfb_RealBuffer_tc_e, cldfb_slots * st_ivas->nchan_transport * st_ivas->hParamMC->num_freq_bands); - f2me_buf(st_ivas->hParamMC->Cldfb_ImagBuffer_tc, st_ivas->hParamMC->Cldfb_ImagBuffer_tc_fx, &st_ivas->hParamMC->Cldfb_ImagBuffer_tc_e, cldfb_slots * st_ivas->nchan_transport * st_ivas->hParamMC->num_freq_bands); - + f2me_buf( st_ivas->hParamMC->Cldfb_RealBuffer_tc, st_ivas->hParamMC->Cldfb_RealBuffer_tc_fx, &st_ivas->hParamMC->Cldfb_RealBuffer_tc_e, cldfb_slots * st_ivas->nchan_transport * st_ivas->hParamMC->num_freq_bands ); + f2me_buf( st_ivas->hParamMC->Cldfb_ImagBuffer_tc, st_ivas->hParamMC->Cldfb_ImagBuffer_tc_fx, &st_ivas->hParamMC->Cldfb_ImagBuffer_tc_e, cldfb_slots * st_ivas->nchan_transport * st_ivas->hParamMC->num_freq_bands ); Word16 max_e = 0, input_q[MAX_CLDFB_DIGEST_CHANNELS], in_q; - FOR(i = 0; i < MAX_CLDFB_DIGEST_CHANNELS; i++) + FOR( i = 0; i < MAX_CLDFB_DIGEST_CHANNELS; i++ ) { - f2me_buf(p_data_f[i], p_data_f_fx[i], &input_q[i], MAX_JBM_L_FRAME48k); + f2me_buf( p_data_f[i], p_data_f_fx[i], &input_q[i], MAX_JBM_L_FRAME48k ); } max_e = input_q[0]; - FOR(i = 0; i < MAX_CLDFB_DIGEST_CHANNELS; i++) + FOR( i = 0; i < MAX_CLDFB_DIGEST_CHANNELS; i++ ) { - IF(max_e < input_q[i]) - max_e = input_q[i]; + IF( max_e < input_q[i] ) + max_e = input_q[i]; } - FOR(i = 0; i < MAX_CLDFB_DIGEST_CHANNELS; i++) + FOR( i = 0; i < MAX_CLDFB_DIGEST_CHANNELS; i++ ) { - FOR(j = 0; j < MAX_JBM_L_FRAME48k; j++) - p_data_f_fx[i][j] = L_shr(p_data_f_fx[i][j], max_e - input_q[i]); + FOR( j = 0; j < MAX_JBM_L_FRAME48k; j++ ) + p_data_f_fx[i][j] = L_shr( p_data_f_fx[i][j], max_e - input_q[i] ); } in_q = max_e; @@ -2346,15 +2363,15 @@ void ivas_jbm_dec_feed_tc_to_renderer( Word16 nchan_transport = st_ivas->nchan_transport; Word16 nchan_out_transport = st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe; Word16 nchan_out_cov; - IF(st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM) + IF( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) { nchan_out_cov = st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe; } - ELSE IF(st_ivas->hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_CLDFB) + ELSE IF( st_ivas->hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_CLDFB ) { nchan_out_cov = nchan_out_transport; } - ELSE IF(st_ivas->hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_COV || st_ivas->hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO) + ELSE IF( st_ivas->hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_COV || st_ivas->hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) { nchan_out_cov = st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe; } @@ -2362,50 +2379,50 @@ void ivas_jbm_dec_feed_tc_to_renderer( { nchan_out_cov = nchan_out_transport; } - f2me_buf(st_ivas->hParamMC->h_output_synthesis_params.proto_matrix, st_ivas->hParamMC->h_output_synthesis_params.proto_matrix_fx, &st_ivas->hParamMC->h_output_synthesis_params.proto_matrix_e, nchan_out_cov * nchan_transport); + f2me_buf( st_ivas->hParamMC->h_output_synthesis_params.proto_matrix, st_ivas->hParamMC->h_output_synthesis_params.proto_matrix_fx, &st_ivas->hParamMC->h_output_synthesis_params.proto_matrix_e, nchan_out_cov * nchan_transport ); - scale_sig32(st_ivas->hParamMC->proto_matrix_int_fx, st_ivas->hParamMC->proto_matrix_int_len, -1); + scale_sig32( st_ivas->hParamMC->proto_matrix_int_fx, st_ivas->hParamMC->proto_matrix_int_len, -1 ); st_ivas->hParamMC->proto_matrix_int_e = 1; - ivas_param_mc_dec_digest_tc_fx( st_ivas, (uint8_t) n_render_timeslots, (Word32 **)p_data_f_fx, in_q ); + ivas_param_mc_dec_digest_tc_fx( st_ivas, (uint8_t) n_render_timeslots, (Word32 **) p_data_f_fx, in_q ); - scale_sig32(st_ivas->hParamMC->proto_matrix_int_fx, st_ivas->hParamMC->proto_matrix_int_len, 1); + scale_sig32( st_ivas->hParamMC->proto_matrix_int_fx, st_ivas->hParamMC->proto_matrix_int_len, 1 ); Word16 shift; - FOR(Word16 param_band_idx = 0; param_band_idx < st_ivas->hParamMC->num_param_bands_synth; param_band_idx++) + FOR( Word16 param_band_idx = 0; param_band_idx < st_ivas->hParamMC->num_param_bands_synth; param_band_idx++ ) { - shift = getScaleFactor32(st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_fx[param_band_idx], s_min(st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_len, nchan_transport * nchan_transport)); - scale_sig32(st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_fx[param_band_idx], s_min(st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_len, nchan_transport * nchan_transport), shift); - st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx] = sub(st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx], shift); + shift = getScaleFactor32( st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_fx[param_band_idx], s_min( st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_len, nchan_transport * nchan_transport ) ); + scale_sig32( st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_fx[param_band_idx], s_min( st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_len, nchan_transport * nchan_transport ), shift ); + st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx] = sub( st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx], shift ); - shift = getScaleFactor32(st_ivas->hParamMC->h_output_synthesis_cov_state.cy_old_fx[param_band_idx], nchan_out_cov * nchan_out_cov); - scale_sig32(st_ivas->hParamMC->h_output_synthesis_cov_state.cy_old_fx[param_band_idx], nchan_out_cov * nchan_out_cov, shift); - st_ivas->hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx] = sub(st_ivas->hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx], shift); + shift = getScaleFactor32( st_ivas->hParamMC->h_output_synthesis_cov_state.cy_old_fx[param_band_idx], nchan_out_cov * nchan_out_cov ); + scale_sig32( st_ivas->hParamMC->h_output_synthesis_cov_state.cy_old_fx[param_band_idx], nchan_out_cov * nchan_out_cov, shift ); + st_ivas->hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx] = sub( st_ivas->hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx], shift ); } - FOR(Word16 param_band_idx = 0; param_band_idx < st_ivas->hParamMC->num_param_bands_synth; param_band_idx++) + FOR( Word16 param_band_idx = 0; param_band_idx < st_ivas->hParamMC->num_param_bands_synth; param_band_idx++ ) { - me2f_buf(st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix[param_band_idx], nchan_out_cov * nchan_transport); - IF(st_ivas->hParamMC->band_grouping[param_band_idx] < st_ivas->hParamMC->h_output_synthesis_params.max_band_decorr) + me2f_buf( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix[param_band_idx], nchan_out_cov * nchan_transport ); + IF( st_ivas->hParamMC->band_grouping[param_band_idx] < st_ivas->hParamMC->h_output_synthesis_params.max_band_decorr ) { - me2f_buf(st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res[param_band_idx], nchan_out_cov * nchan_out_cov); + me2f_buf( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res[param_band_idx], nchan_out_cov * nchan_out_cov ); } } #else ivas_param_mc_dec_digest_tc( st_ivas, (uint8_t) n_render_timeslots, p_data_f ); #endif } - ELSE IF ( EQ_16(st_ivas->mc_mode, MC_MODE_MCMASA )) + ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) { - IF(st_ivas->hSCE[0]) + IF( st_ivas->hSCE[0] ) { - Word16 shift = getScaleFactor32(st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN); - IF(LT_16(sub(st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift), 4)) + Word16 shift = getScaleFactor32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN ); + IF( LT_16( sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ), 4 ) ) { - shift = sub(st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4); + shift = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 ); } - scale_sig32(st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift); - st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub(st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift); + scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); + st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ); } ivas_sba_dec_digest_tc_fx( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available ); } @@ -2491,16 +2508,15 @@ void ivas_jbm_dec_feed_tc_to_renderer( /* delay the objects here for all renderers where it is needed */ if ( - st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || - st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM || - st_ivas->renderer_type == RENDERER_OSBA_AMBI || - st_ivas->renderer_type == RENDERER_OSBA_LS || - st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_EXTERNAL - ) + st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || + st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM || + st_ivas->renderer_type == RENDERER_OSBA_AMBI || + st_ivas->renderer_type == RENDERER_OSBA_LS || + st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_EXTERNAL ) { for ( n = 0; n < st_ivas->nchan_ism; n++ ) { - delay_signal_float( st_ivas->hTcBuffer->tc[n], st_ivas->hTcBuffer->n_samples_available, st_ivas->hSbaIsmData->delayBuffer[n], st_ivas->hSbaIsmData->delayBuffer_size ); + delay_signal_float( st_ivas->hTcBuffer->tc[n], st_ivas->hTcBuffer->n_samples_available, st_ivas->hSbaIsmData->delayBuffer[n], st_ivas->hSbaIsmData->delayBuffer_size ); } } @@ -2582,7 +2598,7 @@ ivas_error ivas_jbm_dec_render( int16_t nSamplesAskedLocal; ivas_error error; float *p_output[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS] = { NULL }; - //float *p_tc[MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS] = { NULL }; + // float *p_tc[MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS] = { NULL }; Word32 *p_output_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS]; Word32 tmp_buffer_fx[MAX_OUTPUT_CHANNELS][L_FRAME48k] = { 0 }; Word32 *p_temp_fx[MAX_OUTPUT_CHANNELS]; @@ -2648,7 +2664,7 @@ ivas_error ivas_jbm_dec_render( } /*----------------------------------------------------------------* - * Rendering + * Rendering *----------------------------------------------------------------*/ if ( st_ivas->ivas_format == UNDEFINED_FORMAT ) @@ -2664,7 +2680,7 @@ ivas_error ivas_jbm_dec_render( /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */ tmp = BASOP_Util_Divide1616_Scale( nSamplesAsked, slot_size, &e ); tmp = shr( tmp, sub( 15, e ) ); - //slots_rendered = add( st_ivas->hTcBuffer->slots_rendered, slots_to_render ); + // slots_rendered = add( st_ivas->hTcBuffer->slots_rendered, slots_to_render ); FOR( Word16 ind = 0; ind < st_ivas->hTcBuffer->nchan_transport_jbm; ind++ ) { floatToFixed_arrL( p_output[ind], p_output_fx[ind], Q11, s_max( *nSamplesRendered, nSamplesAskedLocal ) ); @@ -2676,7 +2692,6 @@ ivas_error ivas_jbm_dec_render( { fixedToFloat_arrL( p_output_fx[ind], p_output[ind], Q11, s_max( *nSamplesRendered, nSamplesAskedLocal ) ); } - } else if ( st_ivas->ivas_format == STEREO_FORMAT ) { @@ -2686,7 +2701,7 @@ ivas_error ivas_jbm_dec_render( *nSamplesRendered = min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal ); Word16 q; q = 11; - + ivas_ls_setup_conversion_fx( st_ivas, st_ivas->nchan_transport, *nSamplesRendered, p_tc_fx, p_output_fx ); FOR( i = 0; i < st_ivas->hDecoderConfig->nchan_out; ++i ) { @@ -2962,11 +2977,11 @@ ivas_error ivas_jbm_dec_render( #endif } #ifdef IVAS_FLOAT_FIXED - IF ( ( error = ivas_sba_linear_renderer_fx( p_output_fx, *nSamplesRendered, nchan_remapped, 0, output_config, st_ivas->hOutSetup ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_sba_linear_renderer_fx( p_output_fx, *nSamplesRendered, nchan_remapped, 0, output_config, st_ivas->hOutSetup ) ) != IVAS_ERR_OK ) { return error; } -#if 1//To Be removed +#if 1 // To Be removed for ( n = 0; n < st_ivas->p_out_len; n++ ) { fixedToFloat_arrL( p_output_fx[n], p_output[n], 11, 960 ); @@ -2994,7 +3009,7 @@ ivas_error ivas_jbm_dec_render( nchan_internal = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); #endif - hSpar->hMdDec->Q_mixer_mat = 30; + hSpar->hMdDec->Q_mixer_mat = 30; #endif // if ( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx, 960 ) ) != IVAS_ERR_OK ) { @@ -3043,7 +3058,7 @@ ivas_error ivas_jbm_dec_render( #if 1 /*Float to fixed conversion*/ SPAR_DEC_HANDLE hSpar; hSpar = st_ivas->hSpar; - hSpar->hMdDec->Q_mixer_mat = 30; + hSpar->hMdDec->Q_mixer_mat = 30; #endif // IF( ( error = ivas_osba_dirac_td_binaural_jbm_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx, output_q_factor, 960 ) ) != IVAS_ERR_OK ) @@ -3106,7 +3121,7 @@ ivas_error ivas_jbm_dec_render( for ( n = 0; n < nchan_out; n++ ) { #ifdef IVAS_FLOAT_FIXED - v_add_fixed( p_output_fx[n], p_tc_fx[n + st_ivas->nchan_ism], p_output_fx[n], *nSamplesRendered, 0); + v_add_fixed( p_output_fx[n], p_tc_fx[n + st_ivas->nchan_ism], p_output_fx[n], *nSamplesRendered, 0 ); fixedToFloat_arrL( p_output_fx[n], p_output[n], 11, *nSamplesRendered ); #else @@ -3116,26 +3131,26 @@ ivas_error ivas_jbm_dec_render( } else if ( st_ivas->renderer_type == RENDERER_OSBA_AMBI || st_ivas->renderer_type == RENDERER_OSBA_LS || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) { - Word16 q = 11; - IF((error = ivas_osba_render_sf_fx(st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx)) != IVAS_ERR_OK) - { - return error; - } - q = Q11; - FOR(Word16 ind1 = 0; ind1 < s_max(st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe, s_max(st_ivas->nchan_transport, st_ivas->nchan_ism)); ind1++) - { - FOR(Word16 ind2 = 0; ind2 < L_FRAME48k; ind2++) + Word16 q = 11; + IF( ( error = ivas_osba_render_sf_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx ) ) != IVAS_ERR_OK ) { - p_output[ind1][ind2] = (float)(p_output_fx[ind1][ind2]) / (float)(1 << q); + return error; + } + q = Q11; + FOR( Word16 ind1 = 0; ind1 < s_max( st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe, s_max( st_ivas->nchan_transport, st_ivas->nchan_ism ) ); ind1++ ) + { + FOR( Word16 ind2 = 0; ind2 < L_FRAME48k; ind2++ ) + { + p_output[ind1][ind2] = (float) ( p_output_fx[ind1][ind2] ) / (float) ( 1 << q ); + } } - } } else if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_EXTERNAL ) /*EXT output = individual objects + HOA3*/ { #if 1 /*Float to fixed conversion*/ SPAR_DEC_HANDLE hSpar; hSpar = st_ivas->hSpar; - hSpar->hMdDec->Q_mixer_mat = 30; + hSpar->hMdDec->Q_mixer_mat = 30; #endif // if ( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, &p_output_fx[st_ivas->nchan_ism], 960 ) ) != IVAS_ERR_OK ) { @@ -3168,7 +3183,7 @@ ivas_error ivas_jbm_dec_render( #if 1 /*Float to fixed conversion*/ SPAR_DEC_HANDLE hSpar; hSpar = st_ivas->hSpar; - hSpar->hMdDec->Q_mixer_mat = 30; + hSpar->hMdDec->Q_mixer_mat = 30; #endif // if ( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx, 960 ) ) != IVAS_ERR_OK ) { @@ -3277,7 +3292,6 @@ ivas_error ivas_jbm_dec_render( p_output[i][j] = fixed_to_float( p_output_fx[i][j], *st_ivas->hCrendWrapper->p_io_qfactor ); } } - } else if ( st_ivas->renderer_type == RENDERER_MC ) { @@ -3288,7 +3302,6 @@ ivas_error ivas_jbm_dec_render( { fixedToFloat_arrL( p_output_fx[i], p_output[i], q, *nSamplesRendered ); } - } else if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC ) { @@ -3342,23 +3355,23 @@ ivas_error ivas_jbm_dec_render( } else if ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) { - FOR(i = 0; i < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; i++) + FOR( i = 0; i < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; i++ ) { - if (p_output[i] != NULL) - { - //fixedToFloat_arrL(p_output_fx[i], p_output[i], 11, 960); - floatToFixed_arrL(p_output[i], p_output_fx[i], 11, 960); - } + if ( p_output[i] != NULL ) + { + // fixedToFloat_arrL(p_output_fx[i], p_output[i], 11, 960); + floatToFixed_arrL( p_output[i], p_output_fx[i], 11, 960 ); + } } - ivas_mc_paramupmix_dec_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_tc_fx, p_output_fx); + ivas_mc_paramupmix_dec_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_tc_fx, p_output_fx ); - FOR(i = 0; i < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; i++) + FOR( i = 0; i < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; i++ ) { - if (p_output[i] != NULL) - { - fixedToFloat_arrL(p_output_fx[i], p_output[i], 11, 960); - } + if ( p_output[i] != NULL ) + { + fixedToFloat_arrL( p_output_fx[i], p_output[i], 11, 960 ); + } } /* Rendering */ @@ -3402,38 +3415,38 @@ ivas_error ivas_jbm_dec_render( else if ( st_ivas->renderer_type == RENDERER_BINAURAL_OBJECTS_TD ) { #ifdef IVAS_FLOAT_FIXED - //Word32 output_fx[MAX_OUTPUT_CHANNELS][L_FRAME48k]; - //Word32 *p_output_fx[MAX_OUTPUT_CHANNELS]; + // Word32 output_fx[MAX_OUTPUT_CHANNELS][L_FRAME48k]; + // Word32 *p_output_fx[MAX_OUTPUT_CHANNELS]; #ifndef IVAS_FLOAT_FIXED_TO_BE_REMOVED - FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++) + FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) { - floatToFixed_arrL(p_output[i], p_output_fx[i], Q11, L_FRAME48k); + floatToFixed_arrL( p_output[i], p_output_fx[i], Q11, L_FRAME48k ); p_output_fx[i] = p_output_fx[i]; } - Word16 num_subframes = (int16_t)((*nSamplesRendered * FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES) / output_Fs); - for (Word16 subframe_idx = 0; subframe_idx < num_subframes; subframe_idx++) + Word16 num_subframes = (int16_t) ( ( *nSamplesRendered * FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) / output_Fs ); + for ( Word16 subframe_idx = 0; subframe_idx < num_subframes; subframe_idx++ ) { Word16 idx = subframe_idx; Word16 pos_q = Q25; - IF(st_ivas->hCombinedOrientationData->listenerPos != NULL) + IF( st_ivas->hCombinedOrientationData->listenerPos != NULL ) { - st_ivas->hCombinedOrientationData->listenerPos[idx].x_fx = (Word32)float_to_fix(st_ivas->hCombinedOrientationData->listenerPos[idx].x, pos_q); - st_ivas->hCombinedOrientationData->listenerPos[idx].y_fx = (Word32)float_to_fix(st_ivas->hCombinedOrientationData->listenerPos[idx].y, pos_q); - st_ivas->hCombinedOrientationData->listenerPos[idx].z_fx = (Word32)float_to_fix(st_ivas->hCombinedOrientationData->listenerPos[idx].z, pos_q); + st_ivas->hCombinedOrientationData->listenerPos[idx].x_fx = (Word32) float_to_fix( st_ivas->hCombinedOrientationData->listenerPos[idx].x, pos_q ); + st_ivas->hCombinedOrientationData->listenerPos[idx].y_fx = (Word32) float_to_fix( st_ivas->hCombinedOrientationData->listenerPos[idx].y, pos_q ); + st_ivas->hCombinedOrientationData->listenerPos[idx].z_fx = (Word32) float_to_fix( st_ivas->hCombinedOrientationData->listenerPos[idx].z, pos_q ); st_ivas->hCombinedOrientationData->listenerPos[idx].q_fact = Q25; } } #endif - if ((error = ivas_td_binaural_renderer_fx(st_ivas, p_output_fx, *nSamplesRendered)) != IVAS_ERR_OK) + if ( ( error = ivas_td_binaural_renderer_fx( st_ivas, p_output_fx, *nSamplesRendered ) ) != IVAS_ERR_OK ) { return error; } #ifndef IVAS_FLOAT_FIXED_TO_BE_REMOVED - FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++) + FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) { - fixedToFloat_arrL(p_output_fx[i], p_output[i], Q11, L_FRAME48k); + fixedToFloat_arrL( p_output_fx[i], p_output[i], Q11, L_FRAME48k ); } #endif @@ -3457,141 +3470,147 @@ ivas_error ivas_jbm_dec_render( else if ( st_ivas->mc_mode == MC_MODE_PARAMMC ) { #ifdef IVAS_FLOAT_FIXED -#if 1//ftf changes +#if 1 // ftf changes int16_t channel_active_fx[MAX_OUTPUT_CHANNELS]; - //uint16_t nchan_out_init; + // uint16_t nchan_out_init; Word16 nchan_out_cov; Word16 nchan_out_cldfb = 0; - set_s(channel_active_fx, 0, MAX_CICP_CHANNELS ); + set_s( channel_active_fx, 0, MAX_CICP_CHANNELS ); Word16 nchan_transport_tmp = st_ivas->nchan_transport; output_Fs = st_ivas->hDecoderConfig->output_Fs; Word16 nchan_out_transport = st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe; - //nchan_out_init = nchan_out_transport; + // nchan_out_init = nchan_out_transport; - if (st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM) + if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) { nchan_out_cldfb = BINAURAL_CHANNELS; - set_s(channel_active_fx, 1, BINAURAL_CHANNELS); + set_s( channel_active_fx, 1, BINAURAL_CHANNELS ); nchan_out_cov = st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe; } - else if (st_ivas->hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_CLDFB) + else if ( st_ivas->hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_CLDFB ) { nchan_out_cov = nchan_out_transport; nchan_out_cldfb = st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe; } - else if (st_ivas->hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_COV || st_ivas->hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO) + else if ( st_ivas->hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_COV || st_ivas->hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) { nchan_out_cov = st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe; nchan_out_cldfb = nchan_out_cov; - set_s(channel_active_fx, 1, nchan_out_cov); + set_s( channel_active_fx, 1, nchan_out_cov ); } else { nchan_out_cov = nchan_out_transport; nchan_out_cldfb = nchan_out_transport; - set_s(channel_active_fx, 1, nchan_out_cov); + set_s( channel_active_fx, 1, nchan_out_cov ); } - //ftf for ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx - FOR( i = 0; i < 16 * nchan_transport_tmp * st_ivas->hParamMC->num_freq_bands; i++) + // ftf for ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx + FOR( i = 0; i < 16 * nchan_transport_tmp * st_ivas->hParamMC->num_freq_bands; i++ ) { - st_ivas->hParamMC->Cldfb_RealBuffer_tc_fx[i] = floatToFixed(st_ivas->hParamMC->Cldfb_RealBuffer_tc[i], Q6); - st_ivas->hParamMC->Cldfb_ImagBuffer_tc_fx[i] = floatToFixed(st_ivas->hParamMC->Cldfb_ImagBuffer_tc[i], Q6); + st_ivas->hParamMC->Cldfb_RealBuffer_tc_fx[i] = floatToFixed( st_ivas->hParamMC->Cldfb_RealBuffer_tc[i], Q6 ); + st_ivas->hParamMC->Cldfb_ImagBuffer_tc_fx[i] = floatToFixed( st_ivas->hParamMC->Cldfb_ImagBuffer_tc[i], Q6 ); } - //ftf changes - if (st_ivas->hParamMC->max_band_decorr > 0) + // ftf changes + if ( st_ivas->hParamMC->max_band_decorr > 0 ) { - //ftf for param_mc_protoSignalComputation_fx - FOR(Word16 x = 0; x < st_ivas->hParamMC->diff_proto_info->num_protos_diff; x++) + // ftf for param_mc_protoSignalComputation_fx + FOR( Word16 x = 0; x < st_ivas->hParamMC->diff_proto_info->num_protos_diff; x++ ) { Word16 num_source_ch = st_ivas->hParamMC->diff_proto_info->num_source_chan_diff[x]; move16(); - floatToFixed_arrL(st_ivas->hParamMC->diff_proto_info->proto_fac[x], st_ivas->hParamMC->diff_proto_info->proto_fac_fx[x], Q30, num_source_ch); + floatToFixed_arrL( st_ivas->hParamMC->diff_proto_info->proto_fac[x], st_ivas->hParamMC->diff_proto_info->proto_fac_fx[x], Q30, num_source_ch ); } - //ftf for ivas_dirac_dec_decorr_process_fx + // ftf for ivas_dirac_dec_decorr_process_fx Word16 tmp_e; - f2me_buf(st_ivas->hParamMC->h_freq_domain_decorr_ap_state->decorr_buffer, st_ivas->hParamMC->h_freq_domain_decorr_ap_state->decorr_buffer_fx, &tmp_e, st_ivas->hParamMC->h_freq_domain_decorr_ap_state->decorr_buffer_len); + f2me_buf( st_ivas->hParamMC->h_freq_domain_decorr_ap_state->decorr_buffer, st_ivas->hParamMC->h_freq_domain_decorr_ap_state->decorr_buffer_fx, &tmp_e, st_ivas->hParamMC->h_freq_domain_decorr_ap_state->decorr_buffer_len ); st_ivas->hParamMC->h_freq_domain_decorr_ap_state->q_decorr_buffer = 31 - tmp_e; } - FOR(Word16 param_band_idx = 0; param_band_idx < st_ivas->hParamMC->num_param_bands_synth; param_band_idx++) { + FOR( Word16 param_band_idx = 0; param_band_idx < st_ivas->hParamMC->num_param_bands_synth; param_band_idx++ ) + { - f2me_buf(st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx[param_band_idx], &st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp[param_band_idx], nchan_transport * nchan_out_cov); + f2me_buf( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx[param_band_idx], &st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp[param_band_idx], nchan_transport * nchan_out_cov ); - IF(st_ivas->hParamMC->band_grouping[param_band_idx] < st_ivas->hParamMC->h_output_synthesis_params.max_band_decorr) { - f2me_buf(st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx[param_band_idx], &st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp[param_band_idx], nchan_out_cov * nchan_out_cov); + IF( st_ivas->hParamMC->band_grouping[param_band_idx] < st_ivas->hParamMC->h_output_synthesis_params.max_band_decorr ) + { + f2me_buf( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx[param_band_idx], &st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp[param_band_idx], nchan_out_cov * nchan_out_cov ); } } - if ((st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM)) + if ( ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) ) { - if (st_ivas->hCombinedOrientationData && st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV) + if ( st_ivas->hCombinedOrientationData && st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV ) { Word16 Q_hoa_encoder = 31; - floatToFixed_arrL(st_ivas->hParamMC->hoa_encoder, st_ivas->hParamMC->hoa_encoder_fx, Q_hoa_encoder, st_ivas->hTransSetup.nchan_out_woLFE * MAX_INTERN_CHANNELS); + floatToFixed_arrL( st_ivas->hParamMC->hoa_encoder, st_ivas->hParamMC->hoa_encoder_fx, Q_hoa_encoder, st_ivas->hTransSetup.nchan_out_woLFE * MAX_INTERN_CHANNELS ); } } - //ftf for ivas_binRenderer_fx + // ftf for ivas_binRenderer_fx /* CLDFB synthesis */ - for (int ch = 0; ch < nchan_out_cldfb; ch++) + for ( int ch = 0; ch < nchan_out_cldfb; ch++ ) { - if (st_ivas->cldfbSynDec[ch]) + if ( st_ivas->cldfbSynDec[ch] ) { - scale_sig32(st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, sub(Q5, Q11)); + scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, sub( Q5, Q11 ) ); st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q5; } } - if (st_ivas->hParamMC->slots_rendered == st_ivas->hParamMC->num_slots) + if ( st_ivas->hParamMC->slots_rendered == st_ivas->hParamMC->num_slots ) { - FOR(Word16 param_band_idx = 0; param_band_idx < st_ivas->hParamMC->hMetadataPMC->nbands_coded; param_band_idx++) { - f2me_buf(st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx[param_band_idx], &st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp[param_band_idx], nchan_transport_tmp * nchan_out_cov); - IF(st_ivas->hParamMC->band_grouping[param_band_idx] < st_ivas->hParamMC->h_output_synthesis_params.max_band_decorr) { - f2me_buf(st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx[param_band_idx], &st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp[param_band_idx], nchan_transport_tmp * nchan_out_cov); + FOR( Word16 param_band_idx = 0; param_band_idx < st_ivas->hParamMC->hMetadataPMC->nbands_coded; param_band_idx++ ) + { + f2me_buf( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx[param_band_idx], &st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp[param_band_idx], nchan_transport_tmp * nchan_out_cov ); + IF( st_ivas->hParamMC->band_grouping[param_band_idx] < st_ivas->hParamMC->h_output_synthesis_params.max_band_decorr ) + { + f2me_buf( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx[param_band_idx], &st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp[param_band_idx], nchan_transport_tmp * nchan_out_cov ); } } } #endif - ivas_param_mc_dec_render_fx(st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx, channel_active_fx); -#if 1//ftf changes - for (int ch = 0; ch < nchan_out_cldfb; ch++) + ivas_param_mc_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx, channel_active_fx ); +#if 1 // ftf changes + for ( int ch = 0; ch < nchan_out_cldfb; ch++ ) { - if (st_ivas->cldfbSynDec[ch]) + if ( st_ivas->cldfbSynDec[ch] ) { - scale_sig32(st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, sub(Q11, Q5)); + scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, sub( Q11, Q5 ) ); st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q11; } - fixedToFloat_arrL(p_output_fx[ch], p_output[ch], Q11, *nSamplesRendered); + fixedToFloat_arrL( p_output_fx[ch], p_output[ch], Q11, *nSamplesRendered ); } - if (st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC) + if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC ) { - FOR(i = 0; i < MAX_OUTPUT_CHANNELS; i++) + FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) { - fixedToFloat_arrL(p_output_fx[i], p_output[i], Q11, *nSamplesRendered); + fixedToFloat_arrL( p_output_fx[i], p_output[i], Q11, *nSamplesRendered ); } } - if (st_ivas->hParamMC->slots_rendered == st_ivas->hParamMC->num_slots) + if ( st_ivas->hParamMC->slots_rendered == st_ivas->hParamMC->num_slots ) { - FOR(Word16 param_band_idx = 0; param_band_idx < st_ivas->hParamMC->hMetadataPMC->nbands_coded; param_band_idx++) { - IF(st_ivas->hParamMC->band_grouping[param_band_idx] < st_ivas->hParamMC->h_output_synthesis_params.max_band_decorr) { + FOR( Word16 param_band_idx = 0; param_band_idx < st_ivas->hParamMC->hMetadataPMC->nbands_coded; param_band_idx++ ) + { + IF( st_ivas->hParamMC->band_grouping[param_band_idx] < st_ivas->hParamMC->h_output_synthesis_params.max_band_decorr ) + { #ifdef IVAS_FLOAT_FIXED - mvl2l(st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_fx[param_band_idx], nchan_transport_tmp * nchan_out_cov); + mvl2l( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_fx[param_band_idx], nchan_transport_tmp * nchan_out_cov ); st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_exp[param_band_idx] = st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp[param_band_idx]; move16(); #else - mvr2r(st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old[param_band_idx], nchan_transport_tmp * nchan_out_cov); + mvr2r( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old[param_band_idx], nchan_transport_tmp * nchan_out_cov ); #endif } #ifdef IVAS_FLOAT_FIXED - mvl2l(st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_fx[param_band_idx], nchan_transport_tmp * nchan_out_cov); + mvl2l( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_fx[param_band_idx], nchan_transport_tmp * nchan_out_cov ); st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_exp[param_band_idx] = st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp[param_band_idx]; move16(); #else - mvr2r(st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_old[param_band_idx], nchan_transport_tmp * nchan_out_cov); + mvr2r( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_old[param_band_idx], nchan_transport_tmp * nchan_out_cov ); #endif } } @@ -3750,13 +3769,10 @@ ivas_error ivas_jbm_dec_render( ivas_syn_output_fx( p_output_fx, q_p_output, *nSamplesRendered, nchan_out, data ); - FOR( i = 0; i < nchan_out; i++ ) - { - } - + FOR( i = 0; i < nchan_out; i++ ){} - *nSamplesAvailableNext = st_ivas->hTcBuffer->n_samples_available; + *nSamplesAvailableNext = st_ivas->hTcBuffer->n_samples_available; pop_wmops(); return IVAS_ERR_OK; @@ -3767,7 +3783,7 @@ ivas_error ivas_jbm_dec_render( const uint16_t nSamplesAsked, /* i : number of samples wanted */ uint16_t *nSamplesRendered, /* o : number of samples rendered */ uint16_t *nSamplesAvailableNext, /* o : number of samples still available in the rendering pipeline */ - int16_t *data /* o : output synthesis signal */ + int16_t *data /* o : output synthesis signal */ ) { int16_t n, nchan_out; @@ -3899,10 +3915,10 @@ ivas_error ivas_jbm_dec_render( /* Binaural rendering */ if ( st_ivas->renderer_type == RENDERER_BINAURAL_OBJECTS_TD ) { - if ( ( error = ivas_td_binaural_renderer_sf( st_ivas, p_output, *nSamplesRendered ) ) != IVAS_ERR_OK ) - { - return error; - } + if ( ( error = ivas_td_binaural_renderer_sf( st_ivas, p_output, *nSamplesRendered ) ) != IVAS_ERR_OK ) + { + return error; + } } else if ( st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM ) { @@ -4083,11 +4099,11 @@ ivas_error ivas_jbm_dec_render( &st_ivas->hIntSetup, st_ivas->hEFAPdata, st_ivas->hTcBuffer, crendInPlaceRotation ? p_output : p_tc, p_output, *nSamplesRendered, output_Fs ) ) != IVAS_ERR_OK ) - { - return error; - } + { + return error; + } - ivas_binaural_add_LFE( st_ivas, *nSamplesRendered, p_tc, p_output ); + ivas_binaural_add_LFE( st_ivas, *nSamplesRendered, p_tc, p_output ); } else if ( st_ivas->renderer_type == RENDERER_MC ) { @@ -4100,12 +4116,12 @@ ivas_error ivas_jbm_dec_render( } else if ( st_ivas->renderer_type == RENDERER_BINAURAL_OBJECTS_TD ) { - if ( ( error = ivas_td_binaural_renderer_sf( st_ivas, p_output, *nSamplesRendered ) ) != IVAS_ERR_OK ) - { - return error; - } + if ( ( error = ivas_td_binaural_renderer_sf( st_ivas, p_output, *nSamplesRendered ) ) != IVAS_ERR_OK ) + { + return error; + } - ivas_binaural_add_LFE( st_ivas, *nSamplesRendered, p_tc, p_output ); + ivas_binaural_add_LFE( st_ivas, *nSamplesRendered, p_tc, p_output ); } } else if ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) @@ -4130,12 +4146,12 @@ ivas_error ivas_jbm_dec_render( } else if ( st_ivas->renderer_type == RENDERER_BINAURAL_OBJECTS_TD ) { - if ( ( error = ivas_td_binaural_renderer( st_ivas, p_output, *nSamplesRendered ) ) != IVAS_ERR_OK ) - { - return error; - } + if ( ( error = ivas_td_binaural_renderer( st_ivas, p_output, *nSamplesRendered ) ) != IVAS_ERR_OK ) + { + return error; + } - ivas_binaural_add_LFE( st_ivas, *nSamplesRendered, p_output, p_output ); + ivas_binaural_add_LFE( st_ivas, *nSamplesRendered, p_output, p_output ); } } else if ( st_ivas->mc_mode == MC_MODE_PARAMMC ) @@ -5694,13 +5710,12 @@ Word16 ivas_jbm_dec_get_num_tc_channels_fx( *--------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED static void ivas_jbm_dec_copy_tc( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const Word16 nSamplesForRendering, /* i : number of samples to digest */ Word16 *nSamplesResidual, /* o : number of samples that will be left for the next frame */ - Word32 *data, /* i : (interleaved) transport channel samples */ - Word32 *tc_digest_f[], /* o : samples that will be directly digested (e.g. by CLDFB) */ - Word16 data_q -) + Word32 *data, /* i : (interleaved) transport channel samples */ + Word32 *tc_digest_f[], /* o : samples that will be directly digested (e.g. by CLDFB) */ + Word16 data_q ) { Word16 ch; DECODER_TC_BUFFER_HANDLE hTcBuffer; @@ -5709,38 +5724,41 @@ static void ivas_jbm_dec_copy_tc( Word16 n_ch_res_copy; hTcBuffer = st_ivas->hTcBuffer; - n_samples_still_available = sub(hTcBuffer->n_samples_buffered, hTcBuffer->n_samples_rendered); - hTcBuffer->n_samples_buffered = add(add(n_samples_still_available, nSamplesForRendering), hTcBuffer->n_samples_discard); - hTcBuffer->n_samples_available = i_mult(hTcBuffer->n_samples_granularity, idiv1616( hTcBuffer->n_samples_buffered, hTcBuffer->n_samples_granularity )); - *nSamplesResidual = sub(hTcBuffer->n_samples_buffered, hTcBuffer->n_samples_available); + n_samples_still_available = sub( hTcBuffer->n_samples_buffered, hTcBuffer->n_samples_rendered ); + hTcBuffer->n_samples_buffered = add( add( n_samples_still_available, nSamplesForRendering ), hTcBuffer->n_samples_discard ); + hTcBuffer->n_samples_available = i_mult( hTcBuffer->n_samples_granularity, idiv1616( hTcBuffer->n_samples_buffered, hTcBuffer->n_samples_granularity ) ); + *nSamplesResidual = sub( hTcBuffer->n_samples_buffered, hTcBuffer->n_samples_available ); n_ch_full_copy = s_min( hTcBuffer->nchan_transport_jbm, hTcBuffer->nchan_buffer_full ); - n_ch_res_copy = sub(hTcBuffer->nchan_transport_jbm, hTcBuffer->nchan_buffer_full); + n_ch_res_copy = sub( hTcBuffer->nchan_transport_jbm, hTcBuffer->nchan_buffer_full ); - FOR ( ch = 0; ch < n_ch_full_copy; ch++ ) + FOR( ch = 0; ch < n_ch_full_copy; ch++ ) { set32_fx( hTcBuffer->tc_fx[ch], 0, hTcBuffer->n_samples_discard ); Copy32( hTcBuffer->tc_fx[ch] + hTcBuffer->n_samples_rendered, hTcBuffer->tc_fx[ch] + hTcBuffer->n_samples_discard, n_samples_still_available ); - FOR ( m = 0; m < nSamplesForRendering; m++ ) + FOR( m = 0; m < nSamplesForRendering; m++ ) { hTcBuffer->tc_fx[ch][n_samples_still_available + hTcBuffer->n_samples_discard + m] = data[m * st_ivas->hTcBuffer->nchan_transport_jbm + ch]; } } - IF ( GT_16(n_ch_res_copy, 0 )) + IF( GT_16( n_ch_res_copy, 0 ) ) { - FOR ( ; ch < hTcBuffer->nchan_transport_jbm; ch++ ) + FOR( ; ch < hTcBuffer->nchan_transport_jbm; ch++ ) { Copy32( hTcBuffer->tc_fx[ch], tc_digest_f[ch], n_samples_still_available ); - FOR ( m = 0; m < nSamplesForRendering; m++ ) + FOR( m = 0; m < nSamplesForRendering; m++ ) { - tc_digest_f[ch][add(n_samples_still_available, m)] = data[add(imult1616(m, st_ivas->hTcBuffer->nchan_transport_jbm), ch)]; + tc_digest_f[ch][add( n_samples_still_available, m )] = data[add( imult1616( m, st_ivas->hTcBuffer->nchan_transport_jbm ), ch )]; } Copy32( tc_digest_f[ch] + hTcBuffer->n_samples_available, hTcBuffer->tc_fx[ch], *nSamplesResidual ); } } - hTcBuffer->q_tc_fx = data_q; move16(); - hTcBuffer->n_samples_rendered = 0; move16(); - hTcBuffer->subframes_rendered = 0; move16(); + hTcBuffer->q_tc_fx = data_q; + move16(); + hTcBuffer->n_samples_rendered = 0; + move16(); + hTcBuffer->subframes_rendered = 0; + move16(); return; } @@ -5955,11 +5973,11 @@ ivas_error ivas_jbm_dec_tc_buffer_open( hTcBuffer->tc_fx[ch_idx] = NULL; } #endif - //hTcBuffer->tc_buffer = NULL; + // hTcBuffer->tc_buffer = NULL; for ( ch_idx = 0; ch_idx < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; ch_idx++ ) { - //hTcBuffer->tc[ch_idx] = NULL; + // hTcBuffer->tc[ch_idx] = NULL; } } else @@ -6277,7 +6295,7 @@ ivas_error ivas_jbm_dec_tc_buffer_reconfigure( } else { - //hTcBuffer->tc_buffer = NULL; + // hTcBuffer->tc_buffer = NULL; #ifdef IVAS_FLOAT_FIXED hTcBuffer->tc_buffer_fx = NULL; #endif @@ -6394,28 +6412,28 @@ ivas_error ivas_jbm_dec_tc_buffer_reconfigure_fx( } /* TODO: remove the floating point dependency */ - //IF( ( hTcBuffer->tc_buffer = (float *) malloc( nsamp_to_allocate * sizeof( float ) ) ) == NULL ) + // IF( ( hTcBuffer->tc_buffer = (float *) malloc( nsamp_to_allocate * sizeof( float ) ) ) == NULL ) { - //return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory FOR JBM TC Buffer\n" ) ); + // return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory FOR JBM TC Buffer\n" ) ); } hTcBuffer->tc_buff_len = nsamp_to_allocate; - //set_zero( hTcBuffer->tc_buffer, nsamp_to_allocate ); + // set_zero( hTcBuffer->tc_buffer, nsamp_to_allocate ); offset = 0; move16(); FOR( ch_idx = 0; ch_idx < hTcBuffer->nchan_buffer_full; ch_idx++ ) { - //hTcBuffer->tc[ch_idx] = &hTcBuffer->tc_buffer[offset]; + // hTcBuffer->tc[ch_idx] = &hTcBuffer->tc_buffer[offset]; offset = add( offset, n_samp_full ); } FOR( ; ch_idx < hTcBuffer->nchan_transport_internal; ch_idx++ ) { - //hTcBuffer->tc[ch_idx] = &hTcBuffer->tc_buffer[offset]; + // hTcBuffer->tc[ch_idx] = &hTcBuffer->tc_buffer[offset]; offset = add( offset, n_samp_residual ); } FOR( ; ch_idx < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; ch_idx++ ) { - //hTcBuffer->tc[ch_idx] = NULL; + // hTcBuffer->tc[ch_idx] = NULL; } } ELSE @@ -6423,7 +6441,7 @@ ivas_error ivas_jbm_dec_tc_buffer_reconfigure_fx( hTcBuffer->tc_buffer_fx = NULL; /* TODO: remove floating point dependency */ - // hTcBuffer->tc_buffer = NULL; + // hTcBuffer->tc_buffer = NULL; } } @@ -6529,9 +6547,9 @@ void ivas_jbm_dec_tc_buffer_close( //( *phTcBuffer )->tc[i] = NULL; } - //if ( ( *phTcBuffer )->tc_buffer != NULL ) + // if ( ( *phTcBuffer )->tc_buffer != NULL ) { - //free( ( *phTcBuffer )->tc_buffer ); + // free( ( *phTcBuffer )->tc_buffer ); //( *phTcBuffer )->tc_buffer = NULL; } @@ -6880,7 +6898,7 @@ void ivas_jbm_dec_copy_tc_no_tsm( { #ifdef IVAS_FLOAT_FIXED Word32 tc_fx[960]; - floatToFixed_arrL(tc[ch_idx], tc_fx, Q11, hTcBuffer->n_samples_buffered); + floatToFixed_arrL( tc[ch_idx], tc_fx, Q11, hTcBuffer->n_samples_buffered ); Copy32( tc_fx, st_ivas->hTcBuffer->tc_fx[ch_idx], hTcBuffer->n_samples_buffered ); #else mvr2r( tc[ch_idx], st_ivas->hTcBuffer->tc[ch_idx], hTcBuffer->n_samples_buffered ); @@ -6969,7 +6987,7 @@ void ivas_jbm_dec_copy_tc_no_tsm_fx( { Word32 *cldfb_real_buffer_fx; Word32 *cldfb_imag_buffer_fx; - //Word16 cldfb_real_e, cldfb_imag_e; + // Word16 cldfb_real_e, cldfb_imag_e; Word16 cldfb_ch, slot_idx, num_freq_bands; cldfb_real_buffer_fx = NULL; @@ -6980,9 +6998,9 @@ void ivas_jbm_dec_copy_tc_no_tsm_fx( IF( EQ_16( (Word16) st_ivas->ivas_format, (Word16) ISM_FORMAT ) ) { cldfb_real_buffer_fx = st_ivas->hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx; - //cldfb_real_e = st_ivas->hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_exp; + // cldfb_real_e = st_ivas->hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_exp; cldfb_imag_buffer_fx = st_ivas->hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx; - //cldfb_imag_e = st_ivas->hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_exp; + // cldfb_imag_e = st_ivas->hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_exp; num_freq_bands = st_ivas->hSpatParamRendCom->num_freq_bands; ivas_ism_param_dec_tc_gain_ajust_fx( st_ivas, output_frame, output_frame / 2, tc_fx, &Q_tc ); @@ -6992,9 +7010,9 @@ void ivas_jbm_dec_copy_tc_no_tsm_fx( ELSE IF( EQ_16( (Word16) st_ivas->ivas_format, (Word16) MC_FORMAT ) ) { cldfb_real_buffer_fx = st_ivas->hParamMC->Cldfb_RealBuffer_tc_fx; - //cldfb_real_e = st_ivas->hParamMC->Cldfb_RealBuffer_tc_e; + // cldfb_real_e = st_ivas->hParamMC->Cldfb_RealBuffer_tc_e; cldfb_imag_buffer_fx = st_ivas->hParamMC->Cldfb_ImagBuffer_tc_fx; - //cldfb_imag_e = st_ivas->hParamMC->Cldfb_ImagBuffer_tc_e; + // cldfb_imag_e = st_ivas->hParamMC->Cldfb_ImagBuffer_tc_e; num_freq_bands = st_ivas->hParamMC->num_freq_bands; } /* CLDFB Analysis*/ @@ -7163,7 +7181,7 @@ static void ivas_jbm_dec_copy_masa_meta_to_buffer( #ifdef IVAS_FLOAT_FIXED static void ivas_jbm_masa_sf_to_slot_map( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const Word16 nCldfbTs /* i : number of CLDFB time slots */ + const Word16 nCldfbTs /* i : number of CLDFB time slots */ ) { Word16 sf_to_slot_map[MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME]; @@ -7201,7 +7219,7 @@ static void ivas_jbm_masa_sf_to_slot_map( #else static void ivas_jbm_masa_sf_to_slot_map( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const int16_t nCldfbTs /* i : number of CLDFB time slots */ + const int16_t nCldfbTs /* i : number of CLDFB time slots */ ) { int16_t sf_to_slot_map[MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME]; diff --git a/lib_dec/ivas_lfe_dec.c b/lib_dec/ivas_lfe_dec.c index a7c0fe222..a6368a727 100644 --- a/lib_dec/ivas_lfe_dec.c +++ b/lib_dec/ivas_lfe_dec.c @@ -472,4 +472,4 @@ void ivas_lfe_dec_close( return; } #endif -#endif \ No newline at end of file +#endif diff --git a/lib_dec/ivas_lfe_plc.c b/lib_dec/ivas_lfe_plc.c index 6fe8d5939..fe25ad1ef 100644 --- a/lib_dec/ivas_lfe_plc.c +++ b/lib_dec/ivas_lfe_plc.c @@ -535,4 +535,4 @@ void ivas_lfe_tdplc( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/ivas_lfe_plc_fx.c b/lib_dec/ivas_lfe_plc_fx.c index 1fc1c04f4..325fc962e 100644 --- a/lib_dec/ivas_lfe_plc_fx.c +++ b/lib_dec/ivas_lfe_plc_fx.c @@ -713,7 +713,7 @@ static Word32 find_max_delta_fx( delta_fx = 0; move32(); - eps_fx = 21474836; // 0.01 in Q31 + eps_fx = 21474836; // 0.01 in Q31 move32(); fac_fx = 1073741824; // 2 in Q29 move32(); @@ -990,4 +990,4 @@ void ivas_lfe_tdplc_fx( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/ivas_ls_custom_dec.c b/lib_dec/ivas_ls_custom_dec.c index 58254892a..cfdce74bd 100644 --- a/lib_dec/ivas_ls_custom_dec.c +++ b/lib_dec/ivas_ls_custom_dec.c @@ -76,7 +76,7 @@ ivas_error ivas_ls_custom_open_fx( ) { /* Allocate handle */ - IF ( ( *hLsSetupCustom = (LSSETUP_CUSTOM_HANDLE) malloc( sizeof( LSSETUP_CUSTOM_STRUCT ) ) ) == NULL ) + IF( ( *hLsSetupCustom = (LSSETUP_CUSTOM_HANDLE) malloc( sizeof( LSSETUP_CUSTOM_STRUCT ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Custom LS layout memory\n" ) ); } @@ -105,7 +105,7 @@ ivas_error ivas_ls_custom_open_fx( #ifndef IVAS_FLOAT_FIXED void ivas_ls_custom_setup( - IVAS_OUTPUT_SETUP_HANDLE hOutSetup, /* o : IVAS output setup handle */ + IVAS_OUTPUT_SETUP_HANDLE hOutSetup, /* o : IVAS output setup handle */ #ifdef IVAS_FLOAT_FIXED LSSETUP_CUSTOM_STRUCT *hLsSetupCustom /* i : Custom loudspeaker setup handle */ // Removed const temporarily. Can be added later. #else @@ -181,7 +181,7 @@ ivas_error ivas_ls_custom_output_init_fx( Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ ) { - IF ( st_ivas->hLsSetupCustom == NULL ) + IF( st_ivas->hLsSetupCustom == NULL ) { return IVAS_ERR_WRONG_PARAMS; } diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 77a6bbb2a..61fe1caff 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -2661,7 +2661,7 @@ static Word16 decode_lfe_to_total_energy_ratio_fx( ivas_error ivas_masa_dec_reconfigure( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ uint16_t *nSamplesRendered, /* o : number of samples flushed from the previous frame (JBM) */ - int16_t *data /* o : output synthesis signal */ + int16_t *data /* o : output synthesis signal */ ) { int16_t n, tmp, num_bits; @@ -2678,12 +2678,12 @@ ivas_error ivas_masa_dec_reconfigure( ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; last_ivas_total_brate = st_ivas->hDecoderConfig->last_ivas_total_brate; - if ( st_ivas->hSpatParamRendCom != NULL && st_ivas->hSpatParamRendCom->slot_size == st_ivas->hTcBuffer->n_samples_granularity ) - { - mvs2s( st_ivas->hSpatParamRendCom->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); - st_ivas->hTcBuffer->nb_subframes = st_ivas->hSpatParamRendCom->nb_subframes; - st_ivas->hTcBuffer->subframes_rendered = st_ivas->hSpatParamRendCom->subframes_rendered; - } + if ( st_ivas->hSpatParamRendCom != NULL && st_ivas->hSpatParamRendCom->slot_size == st_ivas->hTcBuffer->n_samples_granularity ) + { + mvs2s( st_ivas->hSpatParamRendCom->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); + st_ivas->hTcBuffer->nb_subframes = st_ivas->hSpatParamRendCom->nb_subframes; + st_ivas->hTcBuffer->subframes_rendered = st_ivas->hSpatParamRendCom->subframes_rendered; + } ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old ); @@ -2778,7 +2778,7 @@ ivas_error ivas_masa_dec_reconfigure( if ( st_ivas->hDiracDecBin != NULL ) { - /* regularization factor is bitrate-dependent */ + /* regularization factor is bitrate-dependent */ st_ivas->hDiracDecBin->reqularizationFactor = configure_reqularization_factor( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate ); } @@ -3133,7 +3133,7 @@ ivas_error ivas_masa_dec_reconfigure_fx( } #else #if 1 - // Float to fix conversions for ivas_cldfb_dec_reconfig_fx + // Float to fix conversions for ivas_cldfb_dec_reconfig_fx IF( st_ivas->hSpar ) { st_ivas->hSpar->hFbMixer->cldfb_cross_fade_q = Q_factor_arr( st_ivas->hSpar->hFbMixer->cldfb_cross_fade, 16 ); @@ -5110,14 +5110,14 @@ static void decode_ism_ratios( } #else static void decode_ism_ratios_fx( - UWord16 *bit_stream, /* i : bitstream */ - Word16 *next_bit_pos, /* i/o: position in bitstream */ + UWord16 *bit_stream, /* i : bitstream */ + Word16 *next_bit_pos, /* i/o: position in bitstream */ Word32 masa_to_total_energy_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : masa_to_total energy ratios */ - Word32 ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], /* o : ISM ratios */ - const Word16 n_ism, /* i : number of objects */ - const Word16 nbands, /* i : number of subbands */ - const Word16 numSf, /* i : number of subframes */ - const Word16 idx_separated_object /* i : index of separated object */ + Word32 ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], /* o : ISM ratios */ + const Word16 n_ism, /* i : number of objects */ + const Word16 nbands, /* i : number of subbands */ + const Word16 numSf, /* i : number of subframes */ + const Word16 idx_separated_object /* i : index of separated object */ ) { Word16 sf, band; diff --git a/lib_dec/ivas_mc_param_dec.c b/lib_dec/ivas_mc_param_dec.c index 5d84f4512..1e03ab40d 100644 --- a/lib_dec/ivas_mc_param_dec.c +++ b/lib_dec/ivas_mc_param_dec.c @@ -70,8 +70,8 @@ typedef struct parameter_band_mapping_struct int16_t source_band_idx[20][4]; float source_band_factor[20][4]; #ifdef IVAS_FLOAT_FIXED - Word16 source_band_factor_fx[20][4];/*Q15*/ -#endif // IVAS_FLOAT_FIXED + Word16 source_band_factor_fx[20][4]; /*Q15*/ +#endif // IVAS_FLOAT_FIXED } PARAM_MC_PARAMETER_BAND_MAPPING; @@ -89,7 +89,7 @@ static void ivas_param_mc_dec_init_fx( PARAM_MC_DEC_HANDLE hParamMC, const Word1 static void param_mc_protoSignalComputation( float *RealBuffer, float *ImagBuffer, float *proto_frame_f, const PARAM_MC_DIFF_PROTO_INFO *diff_proto_info, const int16_t num_freq_bands ); #endif #ifdef IVAS_FLOAT_FIXED -static void ivas_param_mc_dec_copy_diffuse_proto(PARAM_MC_DEC_HANDLE hParamMC, Word32 Cldfb_buffer_real_fx[MAX_CICP_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], Word32 Cldfb_buffer_imag_fx[MAX_CICP_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], const Word16 nY, const Word16 slot_idx); +static void ivas_param_mc_dec_copy_diffuse_proto( PARAM_MC_DEC_HANDLE hParamMC, Word32 Cldfb_buffer_real_fx[MAX_CICP_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], Word32 Cldfb_buffer_imag_fx[MAX_CICP_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], const Word16 nY, const Word16 slot_idx ); #else static void ivas_param_mc_dec_copy_diffuse_proto( PARAM_MC_DEC_HANDLE hParamMC, float Cldfb_buffer_real[MAX_CICP_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float Cldfb_buffer_imag[MAX_CICP_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], const int16_t nY, const int16_t slot_idx ); #endif @@ -116,10 +116,10 @@ static void ivas_param_mc_get_mixing_matrices_fx( Word16 *mixing_matrix_e, Word32 *mixing_matrix_res_fx[], Word16 *mixing_matrix_res_e, - const Word16 nY_intern, /* i : number of channels in the transported format */ - const PARAM_MC_SYNTHESIS_CONF synth_config, /* i : Parametric MC synthesis config */ - const Word16 nX, /* i : number of transport channels */ - const Word16 nY_cov /* i : number of covariance synthesis output channels */ + const Word16 nY_intern, /* i : number of channels in the transported format */ + const PARAM_MC_SYNTHESIS_CONF synth_config, /* i : Parametric MC synthesis config */ + const Word16 nX, /* i : number of transport channels */ + const Word16 nY_cov /* i : number of covariance synthesis output channels */ ); #endif #ifndef IVAS_FLOAT_FIXED @@ -130,7 +130,7 @@ static void param_mc_update_mixing_matrices( PARAM_MC_DEC_HANDLE hParamMC, float #endif #ifdef IVAS_FLOAT_FIXED -static Word16 ivas_param_mc_uniform_decoder_fx(Word16 *seq, const Word16 sz_seq, const Word16 *alphabet, const Word16 N, UWord16 bit_buffer[PARAM_MC_MAX_BITS]); +static Word16 ivas_param_mc_uniform_decoder_fx( Word16 *seq, const Word16 sz_seq, const Word16 *alphabet, const Word16 N, UWord16 bit_buffer[PARAM_MC_MAX_BITS] ); static void ivas_param_mc_dec_compute_interpolator_fx( const UWord16 bAttackPresent, const UWord16 attackPos, const UWord16 interp_length, Word16 *interpolator ); #endif // IVAS_FLOAT_FIXED @@ -151,14 +151,14 @@ static void ivas_param_mc_bs_decode_parameter_values( uint16_t bit_buffer[], int #endif #ifdef IVAS_FLOAT_FIXED -static void ivas_param_mc_bs_decode_parameter_values_fx(UWord16 bit_buffer[], Word16 *bit_pos, const Word16 max_bits, Word16 *BER_detect, HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC, HANDLE_PARAM_MC_PARAMETER_CODING_INFO hParamCodingInfo, const Word16 map_size_wo_lfe, const Word16 map_size, const Word16 num_lfe_bands, const Word16 band_step, const Word16 num_param_bands, Word16 *value_buffer); -static void ivas_param_mc_dequantize_cov_fx(PARAM_MC_DEC_HANDLE hParamMC, Word16 *ild_q_fx, Word16 *icc_q_fx, const Word16 param_band_index, const Word16 nY_cov, const PARAM_MC_SYNTHESIS_CONF synth_conf, const Word16 nY_int, const Word16 nX, Word32 *Cx_state_fx, Word16 Cx_state_e, Word32 *Cproto_fx, Word16 Cproto_e, Word32 *Cy_state_fx, Word16 *Cy_state_e); -static ivas_error param_mc_get_diff_proto_info_fx(const Word32 *proto_mtx, const UWord16 nchan_transport, const UWord16 nchan_out_cov, PARAM_MC_DIFF_PROTO_INFO *p_diff_proto_info, Word16 Q_proto_mtx); +static void ivas_param_mc_bs_decode_parameter_values_fx( UWord16 bit_buffer[], Word16 *bit_pos, const Word16 max_bits, Word16 *BER_detect, HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC, HANDLE_PARAM_MC_PARAMETER_CODING_INFO hParamCodingInfo, const Word16 map_size_wo_lfe, const Word16 map_size, const Word16 num_lfe_bands, const Word16 band_step, const Word16 num_param_bands, Word16 *value_buffer ); +static void ivas_param_mc_dequantize_cov_fx( PARAM_MC_DEC_HANDLE hParamMC, Word16 *ild_q_fx, Word16 *icc_q_fx, const Word16 param_band_index, const Word16 nY_cov, const PARAM_MC_SYNTHESIS_CONF synth_conf, const Word16 nY_int, const Word16 nX, Word32 *Cx_state_fx, Word16 Cx_state_e, Word32 *Cproto_fx, Word16 Cproto_e, Word32 *Cy_state_fx, Word16 *Cy_state_e ); +static ivas_error param_mc_get_diff_proto_info_fx( const Word32 *proto_mtx, const UWord16 nchan_transport, const UWord16 nchan_out_cov, PARAM_MC_DIFF_PROTO_INFO *p_diff_proto_info, Word16 Q_proto_mtx ); static void param_mc_update_mixing_matrices_fx( PARAM_MC_DEC_HANDLE hParamMC, Word32 *mixing_matrix[], Word16 *mixing_matrix_fx, Word32 *mixing_matrix_res[], Word16 *mixing_matrix_res_exp, const UWord16 nX, const UWord16 nY ); -//static ivas_error param_mc_get_diff_proto_info_fx(const Word32 *proto_mtx, const UWord16 nchan_transport, const UWord16 nchan_out_cov, PARAM_MC_DIFF_PROTO_INFO *p_diff_proto_info); +// static ivas_error param_mc_get_diff_proto_info_fx(const Word32 *proto_mtx, const UWord16 nchan_transport, const UWord16 nchan_out_cov, PARAM_MC_DIFF_PROTO_INFO *p_diff_proto_info); -static void param_mc_protoSignalComputation_fx(Word32 *RealBuffer_fx, Word32 *ImagBuffer_fx, Word32 *proto_frame_f_fx, const PARAM_MC_DIFF_PROTO_INFO *diff_proto_info, const int16_t num_freq_bands/*, Word16 RealBuffer_fx_e, Word16 ImagBuffer_fx_e, Word16 *common_e*/); +static void param_mc_protoSignalComputation_fx( Word32 *RealBuffer_fx, Word32 *ImagBuffer_fx, Word32 *proto_frame_f_fx, const PARAM_MC_DIFF_PROTO_INFO *diff_proto_info, const int16_t num_freq_bands /*, Word16 RealBuffer_fx_e, Word16 ImagBuffer_fx_e, Word16 *common_e*/ ); #endif /*------------------------------------------------------------------------- @@ -214,7 +214,7 @@ ivas_error ivas_param_mc_dec_open_fx( mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup( st_ivas->transport_config ); nchan_out_transport = st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe; hParamMC->hoa_encoder_fx = NULL; -#if 1/*TODO: To be removed later(floating pointer initialization)*/ +#if 1 /*TODO: To be removed later(floating pointer initialization)*/ hParamMC->hoa_encoder = NULL; #endif @@ -238,7 +238,7 @@ ivas_error ivas_param_mc_dec_open_fx( if ( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM ) { st_ivas->hIntSetup.nchan_out_woLFE = st_ivas->hLsSetupCustom->num_spk; -#if 0/*TODO: To be removed later*/ +#if 0 /*TODO: To be removed later*/ st_ivas->hIntSetup.ls_azimuth = st_ivas->hLsSetupCustom->ls_azimuth; st_ivas->hIntSetup.ls_elevation = st_ivas->hLsSetupCustom->ls_elevation; #endif @@ -252,7 +252,7 @@ ivas_error ivas_param_mc_dec_open_fx( } } -#if 0/*TODO: To be removed later*/ +#if 0 /*TODO: To be removed later*/ hParamMC->ls_conv_dmx_matrix = NULL; #endif hParamMC->ls_conv_dmx_matrix_fx = NULL; @@ -359,7 +359,7 @@ ivas_error ivas_param_mc_dec_open_fx( /* convert the ls conv dmx matrix into column order matrix format (nchan_out_cldfb x nchan_out) */ if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_COV || hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) { -#if 0/*TODO: To be removed later (floating point malloc)*/ +#if 0 /*TODO: To be removed later (floating point malloc)*/ if ( ( hParamMC->ls_conv_dmx_matrix = (float *) malloc( nchan_out_transport * nchan_out_cov * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); @@ -372,7 +372,7 @@ ivas_error ivas_param_mc_dec_open_fx( for ( k = 0; k < nchan_out_transport; k++ ) { - Copy32( st_ivas->hLsSetUpConversion->dmxMtx_fx[k], &hParamMC->ls_conv_dmx_matrix_fx[k * nchan_out_cov], nchan_out_cov );/*Q30*/ + Copy32( st_ivas->hLsSetUpConversion->dmxMtx_fx[k], &hParamMC->ls_conv_dmx_matrix_fx[k * nchan_out_cov], nchan_out_cov ); /*Q30*/ } /* convert ParamMC parameter bands to SFB */ @@ -395,39 +395,39 @@ ivas_error ivas_param_mc_dec_open_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); } - Copy32( ivas_param_mc_conf[config_index].dmx_fac_fx, hParamMC->proto_matrix_int_fx, nchan_transport * nchan_out_transport );/*Q31*/ + Copy32( ivas_param_mc_conf[config_index].dmx_fac_fx, hParamMC->proto_matrix_int_fx, nchan_transport * nchan_out_transport ); /*Q31*/ hParamMC->proto_matrix_int_len = nchan_out_transport * nchan_transport; move16(); if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_COV || hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) { - Scale_sig32( hParamMC->ls_conv_dmx_matrix_fx, nchan_out_transport * nchan_out_cov, -4 ); /*Q.26*/ - matrix_product_fx( hParamMC->ls_conv_dmx_matrix_fx, nchan_out_cov, nchan_out_transport, 0, ivas_param_mc_conf[config_index].dmx_fac_fx, nchan_out_transport, nchan_transport, 0, proto_matrix_fx );/*Q.26*/ - Scale_sig32( hParamMC->ls_conv_dmx_matrix_fx, nchan_out_transport * nchan_out_cov, 4 ); /*Q.26*/ + Scale_sig32( hParamMC->ls_conv_dmx_matrix_fx, nchan_out_transport * nchan_out_cov, -4 ); /*Q.26*/ + matrix_product_fx( hParamMC->ls_conv_dmx_matrix_fx, nchan_out_cov, nchan_out_transport, 0, ivas_param_mc_conf[config_index].dmx_fac_fx, nchan_out_transport, nchan_transport, 0, proto_matrix_fx ); /*Q.26*/ + Scale_sig32( hParamMC->ls_conv_dmx_matrix_fx, nchan_out_transport * nchan_out_cov, 4 ); /*Q.26*/ if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) { - proto_mtx_norm_fx = ONE_IN_Q26;/*Q26*/ + proto_mtx_norm_fx = ONE_IN_Q26; /*Q26*/ for ( k = 0; k < nchan_transport * nchan_out_cov; k++ ) { - proto_mtx_norm_fx = L_max(L_abs(proto_mtx_norm_fx), L_abs( proto_matrix_fx[k] ) );/*Q.26*/ + proto_mtx_norm_fx = L_max( L_abs( proto_mtx_norm_fx ), L_abs( proto_matrix_fx[k] ) ); /*Q.26*/ } - proto_mtx_norm_fx = divide3232(ONE_IN_Q26 , proto_mtx_norm_fx);/*Q15*/ + proto_mtx_norm_fx = divide3232( ONE_IN_Q26, proto_mtx_norm_fx ); /*Q15*/ /* transfer flattened proto_matrix to 2D in hLsSetupConversion->dmxMtx */ for ( k = 0; k < nchan_transport; k++ ) { for ( int16_t i = 0; i < nchan_out_cov; i++ ) { - st_ivas->hLsSetUpConversion->dmxMtx_fx[k][i] = L_shl(Mult_32_16(proto_matrix_fx[k * nchan_out_cov + i] , extract_l(proto_mtx_norm_fx)),4);/*Q.30*/ + st_ivas->hLsSetUpConversion->dmxMtx_fx[k][i] = L_shl( Mult_32_16( proto_matrix_fx[k * nchan_out_cov + i], extract_l( proto_mtx_norm_fx ) ), 4 ); /*Q.30*/ } } } } else { - Copy32( ivas_param_mc_conf[config_index].dmx_fac_fx, proto_matrix_fx, nchan_out_transport * nchan_transport );/*Q.31*/ - Scale_sig32( proto_matrix_fx, nchan_out_transport * nchan_transport, -5);/*Scaling down to 26*/ + Copy32( ivas_param_mc_conf[config_index].dmx_fac_fx, proto_matrix_fx, nchan_out_transport * nchan_transport ); /*Q.31*/ + Scale_sig32( proto_matrix_fx, nchan_out_transport * nchan_transport, -5 ); /*Scaling down to 26*/ } if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) @@ -447,7 +447,7 @@ ivas_error ivas_param_mc_dec_open_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); } - if ( ( error = param_mc_get_diff_proto_info_fx( proto_matrix_fx, nchan_transport, nchan_out_cov, hParamMC->diff_proto_info ,Q26) ) != IVAS_ERR_OK ) + if ( ( error = param_mc_get_diff_proto_info_fx( proto_matrix_fx, nchan_transport, nchan_out_cov, hParamMC->diff_proto_info, Q26 ) ) != IVAS_ERR_OK ) { return error; } @@ -491,13 +491,13 @@ ivas_error ivas_param_mc_dec_open_fx( /* Head or external rotation */ if ( ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) && ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) ) { -#if 1/*TODO : To be removed later*/ - IF ( ( hParamMC->hoa_encoder = (float *) malloc( st_ivas->hTransSetup.nchan_out_woLFE * MAX_INTERN_CHANNELS * sizeof( float ) ) ) == NULL ) +#if 1 /*TODO : To be removed later*/ + IF( ( hParamMC->hoa_encoder = (float *) malloc( st_ivas->hTransSetup.nchan_out_woLFE * MAX_INTERN_CHANNELS * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); } #endif - IF ( ( hParamMC->hoa_encoder_fx = (Word32 *) malloc( st_ivas->hTransSetup.nchan_out_woLFE * MAX_INTERN_CHANNELS * sizeof(Word32) ) ) == NULL ) + IF( ( hParamMC->hoa_encoder_fx = (Word32 *) malloc( st_ivas->hTransSetup.nchan_out_woLFE * MAX_INTERN_CHANNELS * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); } @@ -508,13 +508,13 @@ ivas_error ivas_param_mc_dec_open_fx( * memory allocation *-----------------------------------------------------------------*/ - IF ( GT_16(hParamMC->max_band_decorr , 0) ) + IF( GT_16( hParamMC->max_band_decorr, 0 ) ) { - IF ( ( hParamMC->proto_frame_f_fx = (Word32 *) malloc( 2 * hParamMC->diff_proto_info->num_protos_diff * hParamMC->num_freq_bands * sizeof( Word32 ) ) ) == NULL ) + IF( ( hParamMC->proto_frame_f_fx = (Word32 *) malloc( 2 * hParamMC->diff_proto_info->num_protos_diff * hParamMC->num_freq_bands * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); } - IF ( ( hParamMC->proto_frame_dec_f_fx = (Word32 *) malloc( 2 * nchan_out_cov * hParamMC->num_freq_bands * sizeof( Word32 ) ) ) == NULL ) + IF( ( hParamMC->proto_frame_dec_f_fx = (Word32 *) malloc( 2 * nchan_out_cov * hParamMC->num_freq_bands * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); } @@ -527,12 +527,12 @@ ivas_error ivas_param_mc_dec_open_fx( ivas_param_mc_dec_init_fx( hParamMC, nchan_transport, nchan_out_cov ); - IF ( hParamMC->synthesis_conf != PARAM_MC_SYNTH_MONO_STEREO ) + IF( hParamMC->synthesis_conf != PARAM_MC_SYNTH_MONO_STEREO ) { Word16 n_cldfb_slots; n_cldfb_slots = DEFAULT_JBM_CLDFB_TIMESLOTS; - IF ( st_ivas->hDecoderConfig->Opt_tsm ) + IF( st_ivas->hDecoderConfig->Opt_tsm ) { n_cldfb_slots = MAX_JBM_CLDFB_TIMESLOTS; } @@ -550,7 +550,7 @@ ivas_error ivas_param_mc_dec_open_fx( hParamMC->sz = n_cldfb_slots * nchan_transport * hParamMC->num_freq_bands; -#if 1/*TODO: To be removed later(floating point malloc)*/ +#if 1 /*TODO: To be removed later(floating point malloc)*/ if ( ( hParamMC->Cldfb_RealBuffer_tc = (float *) malloc( n_cldfb_slots * nchan_transport * hParamMC->num_freq_bands * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC JBM\n" ) ); @@ -563,9 +563,9 @@ ivas_error ivas_param_mc_dec_open_fx( set_zero( hParamMC->Cldfb_ImagBuffer_tc, n_cldfb_slots * nchan_transport * hParamMC->num_freq_bands ); #endif - IF ( st_ivas->hTcBuffer == NULL ) + IF( st_ivas->hTcBuffer == NULL ) { - IF ( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_RENDERER, nchan_transport, nchan_transport, 0, NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_RENDERER, nchan_transport, nchan_transport, 0, NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ) != IVAS_ERR_OK ) { return error; } @@ -575,7 +575,7 @@ ivas_error ivas_param_mc_dec_open_fx( { hParamMC->Cldfb_RealBuffer_tc_fx = NULL; hParamMC->Cldfb_ImagBuffer_tc_fx = NULL; -#if 1/*TODO: To be removed later*/ +#if 1 /*TODO: To be removed later*/ hParamMC->Cldfb_RealBuffer_tc = NULL; hParamMC->Cldfb_ImagBuffer_tc = NULL; #endif @@ -986,40 +986,43 @@ static void ivas_param_mc_get_param_band_mapping( move16(); Word16 source_band_cnt_total; - FOR ( target_band_idx = 0; target_band_idx < n_target_bands; target_band_idx++ ) + FOR( target_band_idx = 0; target_band_idx < n_target_bands; target_band_idx++ ) { Word16 upper = target_band_grouping[target_band_idx + 1]; Word16 lower = target_band_grouping[target_band_idx]; Word16 source_band_in_target_band_cnt = 0; Word16 norm_fac_fx = 32767; source_band_cnt_total = 0; - move16();move16();move16(); + move16(); + move16(); + move16(); - FOR ( source_band_idx = 0; source_band_idx < n_source_bands; source_band_idx++ ) + FOR( source_band_idx = 0; source_band_idx < n_source_bands; source_band_idx++ ) { /* find lowest corresponding source band*/ - IF ( LE_16(source_band_grouping[source_band_idx] , lower) && GE_16(source_band_grouping[source_band_idx + 1] , lower) ) + IF( LE_16( source_band_grouping[source_band_idx], lower ) && GE_16( source_band_grouping[source_band_idx + 1], lower ) ) { DO { - Word16 source_bands_in_target_band = sub(s_min( source_band_grouping[source_band_idx + 1], upper ) , s_max( source_band_grouping[source_band_idx], lower )); - IF ( source_bands_in_target_band ) + Word16 source_bands_in_target_band = sub( s_min( source_band_grouping[source_band_idx + 1], upper ), s_max( source_band_grouping[source_band_idx], lower ) ); + IF( source_bands_in_target_band ) { - source_band_cnt_total = add(source_band_cnt_total,source_bands_in_target_band); + source_band_cnt_total = add( source_band_cnt_total, source_bands_in_target_band ); parameter_band_mapping->source_band_idx[target_band_idx][source_band_in_target_band_cnt] = source_band_idx; - parameter_band_mapping->source_band_factor_fx[target_band_idx][source_band_in_target_band_cnt++] = shl(source_bands_in_target_band,10); /*Q10*/ + parameter_band_mapping->source_band_factor_fx[target_band_idx][source_band_in_target_band_cnt++] = shl( source_bands_in_target_band, 10 ); /*Q10*/ move16(); move16(); } source_band_idx++; - } WHILE ( LE_16(source_band_grouping[source_band_idx] , upper) && LT_16(source_band_idx , n_source_bands) ); + } + WHILE( LE_16( source_band_grouping[source_band_idx], upper ) && LT_16( source_band_idx, n_source_bands ) ); BREAK; } } - norm_fac_fx = div_s(1, source_band_cnt_total );/*Q15*/ + norm_fac_fx = div_s( 1, source_band_cnt_total ); /*Q15*/ for ( source_band_idx = 0; source_band_idx < source_band_in_target_band_cnt; source_band_idx++ ) { - parameter_band_mapping->source_band_factor_fx[target_band_idx][source_band_idx] = shl_sat(mult(parameter_band_mapping->source_band_factor_fx[target_band_idx][source_band_idx],norm_fac_fx)/*Q10*/,5);/*Q15*/ + parameter_band_mapping->source_band_factor_fx[target_band_idx][source_band_idx] = shl_sat( mult( parameter_band_mapping->source_band_factor_fx[target_band_idx][source_band_idx], norm_fac_fx ) /*Q10*/, 5 ); /*Q15*/ } parameter_band_mapping->n_source_bands[target_band_idx] = source_band_in_target_band_cnt; move16(); @@ -1124,11 +1127,11 @@ ivas_error ivas_param_mc_dec_reconfig_fx( hTransportSetup = st_ivas->hTransSetup; #endif mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup( st_ivas->transport_config ); - nchan_out_transport = add(st_ivas->hTransSetup.nchan_out_woLFE , st_ivas->hTransSetup.num_lfe); + nchan_out_transport = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ); - IF ( EQ_16(hParamMC->synthesis_conf , PARAM_MC_SYNTH_LS_CONV_COV) || EQ_16(hParamMC->synthesis_conf , PARAM_MC_SYNTH_MONO_STEREO) ) + IF( EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) ) { - nchan_out_cov = add(st_ivas->hOutSetup.nchan_out_woLFE , st_ivas->hOutSetup.num_lfe); + nchan_out_cov = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ); } ELSE { @@ -1139,7 +1142,7 @@ ivas_error ivas_param_mc_dec_reconfig_fx( config_index = ivas_param_mc_get_configuration_index( mc_ls_setup, ivas_total_brate ); nchan_transport = st_ivas->nchan_transport; - SWITCH ( nchan_transport ) + SWITCH( nchan_transport ) { case 4: case 3: @@ -1164,31 +1167,31 @@ ivas_error ivas_param_mc_dec_reconfig_fx( #ifndef FIX_901_PARAMMC_DEAD_CODE /* deallocate the full icc map, gets newly allocated in the metadata open function */ - FOR ( k = 0; k < 2; k++ ) + FOR( k = 0; k < 2; k++ ) { - IF ( hParamMC->hMetadataPMC->icc_map_full[k] != NULL ) + IF( hParamMC->hMetadataPMC->icc_map_full[k] != NULL ) { free( hParamMC->hMetadataPMC->icc_map_full[k] ); hParamMC->hMetadataPMC->icc_map_full[k] = NULL; } } #endif - Copy( hParamMC->band_grouping, band_grouping_old, add(hParamMC->hMetadataPMC->num_parameter_bands , 1) ); + Copy( hParamMC->band_grouping, band_grouping_old, add( hParamMC->hMetadataPMC->num_parameter_bands, 1 ) ); #ifndef FIX_901_PARAMMC_DEAD_CODE ivas_param_mc_metadata_open( mc_ls_setup, hTransportSetup.index_lfe[0], ivas_total_brate, hParamMC->hMetadataPMC ); #else ivas_param_mc_metadata_open( mc_ls_setup, ivas_total_brate, hParamMC->hMetadataPMC ); #endif /* Band Grouping */ - IF ( EQ_16(hParamMC->hMetadataPMC->num_parameter_bands , 20) ) + IF( EQ_16( hParamMC->hMetadataPMC->num_parameter_bands, 20 ) ) { Copy( param_mc_band_grouping_20, hParamMC->band_grouping, 20 + 1 ); } - ELSE IF ( EQ_16(hParamMC->hMetadataPMC->num_parameter_bands , 14) ) + ELSE IF( EQ_16( hParamMC->hMetadataPMC->num_parameter_bands, 14 ) ) { Copy( param_mc_band_grouping_14, hParamMC->band_grouping, 14 + 1 ); } - ELSE IF ( EQ_16(hParamMC->hMetadataPMC->num_parameter_bands , 10) ) + ELSE IF( EQ_16( hParamMC->hMetadataPMC->num_parameter_bands, 10 ) ) { Copy( param_mc_band_grouping_10, hParamMC->band_grouping, 10 + 1 ); } @@ -1199,24 +1202,24 @@ ivas_error ivas_param_mc_dec_reconfig_fx( ivas_param_mc_get_param_band_mapping( hParamMC->hMetadataPMC->num_parameter_bands, hParamMC->band_grouping, num_param_bands_old, band_grouping_old, ¶meter_band_mapping ); - IF ( NE_16(nchan_transport_old , nchan_transport) || NE_16(num_param_bands_old , hParamMC->hMetadataPMC->num_parameter_bands) ) + IF( NE_16( nchan_transport_old, nchan_transport ) || NE_16( num_param_bands_old, hParamMC->hMetadataPMC->num_parameter_bands ) ) { Word16 *ild_q_old_fx = hParamMC->icld_q_fx; Word16 *icc_q_old_fx = hParamMC->icc_q_fx; - IF ( ( hParamMC->icc_q_fx = (Word16 *) malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe * sizeof(Word16) ) ) == NULL ) + IF( ( hParamMC->icc_q_fx = (Word16 *) malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe * sizeof( Word16 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); } - IF ( ( hParamMC->icld_q_fx = (Word16 *) malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe * sizeof( Word16 ) ) ) == NULL ) + IF( ( hParamMC->icld_q_fx = (Word16 *) malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe * sizeof( Word16 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); } - set16_fx( hParamMC->icld_q_fx, PARAM_MC_DEFAULT_MIN_ILD_FX, hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe );/*Q8*/ - set16_fx( hParamMC->icc_q_fx, 0, hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe );/*Q15*/ + set16_fx( hParamMC->icld_q_fx, PARAM_MC_DEFAULT_MIN_ILD_FX, hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe ); /*Q8*/ + set16_fx( hParamMC->icc_q_fx, 0, hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe ); /*Q15*/ /* map old to new parameter banding, only for same number of TCs, needs some more thought for a changing number of TCs */ - IF ( NE_16(num_param_bands_old , hParamMC->hMetadataPMC->num_parameter_bands) && EQ_16(nchan_transport_old , nchan_transport) ) + IF( NE_16( num_param_bands_old, hParamMC->hMetadataPMC->num_parameter_bands ) && EQ_16( nchan_transport_old, nchan_transport ) ) { Word16 new_param_band_idx, param_idx, source_param_idx; Word16 num_param_lfe; @@ -1227,14 +1230,14 @@ ivas_error ivas_param_mc_dec_reconfig_fx( /* ICC */ num_param_lfe = hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe; - FOR ( new_param_band_idx = 0; new_param_band_idx < hParamMC->hMetadataPMC->num_parameter_bands; new_param_band_idx++ ) + FOR( new_param_band_idx = 0; new_param_band_idx < hParamMC->hMetadataPMC->num_parameter_bands; new_param_band_idx++ ) { - FOR ( param_idx = 0; param_idx < num_param_lfe; param_idx++ ) + FOR( param_idx = 0; param_idx < num_param_lfe; param_idx++ ) { *p_icc_new_fx = 0; - FOR ( source_param_idx = 0; source_param_idx < parameter_band_mapping.n_source_bands[new_param_band_idx]; source_param_idx++ ) + FOR( source_param_idx = 0; source_param_idx < parameter_band_mapping.n_source_bands[new_param_band_idx]; source_param_idx++ ) { - *p_icc_new_fx = add( *p_icc_new_fx, mult( icc_q_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]* num_param_lfe + param_idx], parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx] ) ); /*Q15*/ + *p_icc_new_fx = add( *p_icc_new_fx, mult( icc_q_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx] * num_param_lfe + param_idx], parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx] ) ); /*Q15*/ } p_icc_new_fx++; } @@ -1242,17 +1245,17 @@ ivas_error ivas_param_mc_dec_reconfig_fx( /* ILD */ num_param_lfe = hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe; - FOR ( new_param_band_idx = 0; new_param_band_idx < hParamMC->hMetadataPMC->num_parameter_bands; new_param_band_idx++ ) + FOR( new_param_band_idx = 0; new_param_band_idx < hParamMC->hMetadataPMC->num_parameter_bands; new_param_band_idx++ ) { - FOR ( param_idx = 0; param_idx < num_param_lfe; param_idx++ ) + FOR( param_idx = 0; param_idx < num_param_lfe; param_idx++ ) { *p_ild_new_fx = 0; - FOR ( source_param_idx = 0; source_param_idx < parameter_band_mapping.n_source_bands[new_param_band_idx]; source_param_idx++ ) + FOR( source_param_idx = 0; source_param_idx < parameter_band_mapping.n_source_bands[new_param_band_idx]; source_param_idx++ ) { - p_ild_new_tmp = extract_h(BASOP_util_Pow2( L_mult0( 10885/*log2(10)/10*2^15*/, ild_q_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx] * num_param_lfe + param_idx] ), 8, &p_ild_new_e )); - *p_ild_new_fx = add(*p_ild_new_fx,mult(p_ild_new_tmp, parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx] )); + p_ild_new_tmp = extract_h( BASOP_util_Pow2( L_mult0( 10885 /*log2(10)/10*2^15*/, ild_q_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx] * num_param_lfe + param_idx] ), 8, &p_ild_new_e ) ); + *p_ild_new_fx = add( *p_ild_new_fx, mult( p_ild_new_tmp, parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx] ) ); } - *p_ild_new_fx = extract_l(L_shr(Mpy_32_16_1(L_add(BASOP_Util_Log2(*p_ild_new_fx),L_add(16<band_grouping[k] , PARAM_MC_MAX_BAND_ABS_COV_DEC) ) + WHILE( LE_16( hParamMC->band_grouping[k], PARAM_MC_MAX_BAND_ABS_COV_DEC ) ) { hParamMC->max_param_band_abs_cov = ( k++ ); } @@ -1276,22 +1279,22 @@ ivas_error ivas_param_mc_dec_reconfig_fx( /* prototype signal computation */ - IF ( EQ_16(hParamMC->synthesis_conf , PARAM_MC_SYNTH_MONO_STEREO) ) + IF( EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) ) { - IF ( NE_16(nchan_transport_old , nchan_transport) ) + IF( NE_16( nchan_transport_old, nchan_transport ) ) { - IF ( st_ivas->hLsSetUpConversion != NULL ) + IF( st_ivas->hLsSetUpConversion != NULL ) { ivas_ls_setup_conversion_close_fx( &st_ivas->hLsSetUpConversion ); } - IF ( ( error = ivas_ls_setup_conversion_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_ls_setup_conversion_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } /* convert the ls conv dmx matrix into column order matrix format (nchan_out_cldfb x nchan_out) */ -#if 0/*To be removed later*/ +#if 0 /*To be removed later*/ free( hParamMC->ls_conv_dmx_matrix ); #endif free( hParamMC->ls_conv_dmx_matrix_fx ); @@ -1301,11 +1304,11 @@ ivas_error ivas_param_mc_dec_reconfig_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); } #endif - IF ( ( hParamMC->ls_conv_dmx_matrix_fx = (Word32 *) malloc( nchan_out_transport * nchan_out_cov * sizeof(Word32) ) ) == NULL ) + IF( ( hParamMC->ls_conv_dmx_matrix_fx = (Word32 *) malloc( nchan_out_transport * nchan_out_cov * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); } - FOR ( k = 0; k < nchan_out_transport; k++ ) + FOR( k = 0; k < nchan_out_transport; k++ ) { Copy32( st_ivas->hLsSetUpConversion->dmxMtx_fx[k], &hParamMC->ls_conv_dmx_matrix_fx[k * nchan_out_cov], nchan_out_cov ); } @@ -1313,51 +1316,51 @@ ivas_error ivas_param_mc_dec_reconfig_fx( /* convert ParamMC parameter bands to SFB */ st_ivas->hLsSetUpConversion->sfbCnt = hParamMC->num_param_bands_synth; - FOR ( k = 0; k <= hParamMC->num_param_bands_synth; k++ ) + FOR( k = 0; k <= hParamMC->num_param_bands_synth; k++ ) { st_ivas->hLsSetUpConversion->sfbOffset[k] = PARAM_MC_BAND_TO_MDCT_BAND_RATIO * hParamMC->band_grouping[k]; } - FOR ( ; k < MAX_SFB + 2; k++ ) + FOR( ; k < MAX_SFB + 2; k++ ) { st_ivas->hLsSetUpConversion->sfbOffset[k] = 0; } } - IF ( NE_16(nchan_transport_old , nchan_transport) ) + IF( NE_16( nchan_transport_old, nchan_transport ) ) { free( hParamMC->proto_matrix_int_fx ); - IF ( ( hParamMC->proto_matrix_int_fx = (Word32 *) malloc( nchan_out_transport * nchan_transport * sizeof(Word32) ) ) == NULL ) + IF( ( hParamMC->proto_matrix_int_fx = (Word32 *) malloc( nchan_out_transport * nchan_transport * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); } hParamMC->proto_matrix_int_len = nchan_out_transport * nchan_transport; move16(); - Copy32( ivas_param_mc_conf[config_index].dmx_fac_fx, hParamMC->proto_matrix_int_fx, nchan_transport * nchan_out_transport );/*Q31*/ + Copy32( ivas_param_mc_conf[config_index].dmx_fac_fx, hParamMC->proto_matrix_int_fx, nchan_transport * nchan_out_transport ); /*Q31*/ } - IF ( EQ_16(hParamMC->synthesis_conf , PARAM_MC_SYNTH_LS_CONV_COV) || EQ_16(hParamMC->synthesis_conf , PARAM_MC_SYNTH_MONO_STEREO) ) + IF( EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) ) { Scale_sig32( hParamMC->ls_conv_dmx_matrix_fx, nchan_out_transport * nchan_out_cov, -4 ); matrix_product_fx( hParamMC->ls_conv_dmx_matrix_fx, nchan_out_cov, nchan_out_transport, 0, - ivas_param_mc_conf[config_index].dmx_fac_fx, nchan_out_transport, nchan_transport, 0, - proto_matrix_fx /*Q26*/); + ivas_param_mc_conf[config_index].dmx_fac_fx, nchan_out_transport, nchan_transport, 0, + proto_matrix_fx /*Q26*/ ); Scale_sig32( hParamMC->ls_conv_dmx_matrix_fx, nchan_out_transport * nchan_out_cov, 4 ); - IF ( EQ_16(hParamMC->synthesis_conf , PARAM_MC_SYNTH_MONO_STEREO) ) + IF( EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) ) { proto_mtx_norm_fx = ONE_IN_Q26; - FOR ( k = 0; k < nchan_transport * nchan_out_cov; k++ ) + FOR( k = 0; k < nchan_transport * nchan_out_cov; k++ ) { - proto_mtx_norm_fx = L_max(L_abs( proto_mtx_norm_fx ), L_abs( proto_matrix_fx[k] ) ); + proto_mtx_norm_fx = L_max( L_abs( proto_mtx_norm_fx ), L_abs( proto_matrix_fx[k] ) ); } - proto_mtx_norm_fx = divide3232(ONE_IN_Q26 , proto_mtx_norm_fx);/*Q15*/ + proto_mtx_norm_fx = divide3232( ONE_IN_Q26, proto_mtx_norm_fx ); /*Q15*/ /* transfer flattened proto_matrix to 2D in hLsSetupConversion->dmxMtx */ - FOR ( k = 0; k < nchan_transport; k++ ) + FOR( k = 0; k < nchan_transport; k++ ) { - FOR ( Word16 i = 0; i < nchan_out_cov; i++ ) + FOR( Word16 i = 0; i < nchan_out_cov; i++ ) { - st_ivas->hLsSetUpConversion->dmxMtx_fx[k][i] = L_shl(Mpy_32_16_1(proto_matrix_fx[k * nchan_out_cov + i] , (Word16)proto_mtx_norm_fx),4); + st_ivas->hLsSetUpConversion->dmxMtx_fx[k][i] = L_shl( Mpy_32_16_1( proto_matrix_fx[k * nchan_out_cov + i], (Word16) proto_mtx_norm_fx ), 4 ); } } } @@ -1368,7 +1371,7 @@ ivas_error ivas_param_mc_dec_reconfig_fx( Scale_sig32( proto_matrix_fx, nchan_out_transport * nchan_transport, -5 ); } - IF ( NE_16(nchan_transport_old , nchan_transport) && NE_16(hParamMC->synthesis_conf , PARAM_MC_SYNTH_MONO_STEREO) ) + IF( NE_16( nchan_transport_old, nchan_transport ) && NE_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) ) { Word16 i; Word16 len; @@ -1377,10 +1380,10 @@ ivas_error ivas_param_mc_dec_reconfig_fx( ivas_dirac_dec_decorr_close_fx( &hParamMC->h_freq_domain_decorr_ap_params, &hParamMC->h_freq_domain_decorr_ap_state ); /* deallocate diffuse prototype info */ - IF ( hParamMC->diff_proto_info ) + IF( hParamMC->diff_proto_info ) { -#if 1/*To be removed later*/ - FOR ( i = 0; i < hParamMC->diff_proto_info->num_protos_diff; i++ ) +#if 1 /*To be removed later*/ + FOR( i = 0; i < hParamMC->diff_proto_info->num_protos_diff; i++ ) { free( hParamMC->diff_proto_info->proto_fac[i] ); hParamMC->diff_proto_info->proto_fac[i] = NULL; @@ -1389,7 +1392,7 @@ ivas_error ivas_param_mc_dec_reconfig_fx( free( hParamMC->diff_proto_info->proto_fac ); hParamMC->diff_proto_info->proto_fac = NULL; #endif - FOR ( i = 0; i < hParamMC->diff_proto_info->num_protos_diff; i++ ) + FOR( i = 0; i < hParamMC->diff_proto_info->num_protos_diff; i++ ) { free( hParamMC->diff_proto_info->source_chan_idx[i] ); hParamMC->diff_proto_info->source_chan_idx[i] = NULL; @@ -1415,11 +1418,11 @@ ivas_error ivas_param_mc_dec_reconfig_fx( } hParamMC->num_outputs_diff = nchan_out_cov; - IF ( ( hParamMC->diff_proto_info = (PARAM_MC_DIFF_PROTO_INFO *) malloc( sizeof( PARAM_MC_DIFF_PROTO_INFO ) ) ) == NULL ) + IF( ( hParamMC->diff_proto_info = (PARAM_MC_DIFF_PROTO_INFO *) malloc( sizeof( PARAM_MC_DIFF_PROTO_INFO ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); } - IF ( ( param_mc_get_diff_proto_info_fx( proto_matrix_fx, nchan_transport, nchan_out_cov, hParamMC->diff_proto_info ,Q26) ) != IVAS_ERR_OK ) + IF( ( param_mc_get_diff_proto_info_fx( proto_matrix_fx, nchan_transport, nchan_out_cov, hParamMC->diff_proto_info, Q26 ) ) != IVAS_ERR_OK ) { return error; } @@ -1439,7 +1442,7 @@ ivas_error ivas_param_mc_dec_reconfig_fx( hParamMC->h_output_synthesis_params.use_onset_filters = 0; hParamMC->max_band_decorr = hParamMC->h_freq_domain_decorr_ap_params->max_band_decorr; /* init decorrelation */ - IF ( GT_16(hParamMC->max_band_decorr , 0) ) + IF( GT_16( hParamMC->max_band_decorr, 0 ) ) { len = hParamMC->diff_proto_info->num_protos_diff * hParamMC->h_freq_domain_decorr_ap_params->h_onset_detection_power_params.max_band_decorr; @@ -1453,9 +1456,9 @@ ivas_error ivas_param_mc_dec_reconfig_fx( hParamMC->max_band_energy_compensation = hParamMC->band_grouping[hParamMC->hMetadataPMC->nbands_coded]; max_param_band_residual = 0; - FOR ( k = hParamMC->hMetadataPMC->num_parameter_bands; k >= 0; k-- ) + FOR( k = hParamMC->hMetadataPMC->num_parameter_bands; k >= 0; k-- ) { - IF (LE_16( hParamMC->band_grouping[k] , hParamMC->max_band_decorr) ) + IF( LE_16( hParamMC->band_grouping[k], hParamMC->max_band_decorr ) ) { max_param_band_residual = k; assert( hParamMC->band_grouping[k] == hParamMC->max_band_decorr ); @@ -1463,18 +1466,18 @@ ivas_error ivas_param_mc_dec_reconfig_fx( } } - IF ( NE_16(nchan_transport_old , nchan_transport) || NE_16(num_param_bands_old , hParamMC->hMetadataPMC->num_parameter_bands) ) + IF( NE_16( nchan_transport_old, nchan_transport ) || NE_16( num_param_bands_old, hParamMC->hMetadataPMC->num_parameter_bands ) ) { DIRAC_OUTPUT_SYNTHESIS_COV_STATE cov_state_old = hParamMC->h_output_synthesis_cov_state; DIRAC_OUTPUT_SYNTHESIS_PARAMS params_old = hParamMC->h_output_synthesis_params; Word32 tmp_buf_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; - set_zero_fx( tmp_buf_fx,MAX_CICP_CHANNELS * MAX_CICP_CHANNELS ); + set_zero_fx( tmp_buf_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS ); /* output synthesis */ - IF ( ( error = ivas_dirac_dec_output_synthesis_cov_open_fx( &( hParamMC->h_output_synthesis_params ), &( hParamMC->h_output_synthesis_cov_state ), hParamMC->max_band_decorr, PARAM_MC_MAX_NSLOTS, - hParamMC->hMetadataPMC->num_parameter_bands, max_param_band_residual, nchan_transport, nchan_out_cov, proto_matrix_fx ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_dirac_dec_output_synthesis_cov_open_fx( &( hParamMC->h_output_synthesis_params ), &( hParamMC->h_output_synthesis_cov_state ), hParamMC->max_band_decorr, PARAM_MC_MAX_NSLOTS, + hParamMC->hMetadataPMC->num_parameter_bands, max_param_band_residual, nchan_transport, nchan_out_cov, proto_matrix_fx ) ) != IVAS_ERR_OK ) { return error; } @@ -1484,13 +1487,13 @@ ivas_error ivas_param_mc_dec_reconfig_fx( ivas_dirac_dec_output_synthesis_cov_init_fx( &( hParamMC->h_output_synthesis_cov_state ), nchan_transport, nchan_out_cov, hParamMC->hMetadataPMC->num_parameter_bands, max_param_band_residual ); /* map old to new parameter banding, only for same number of TCs, needs some more thought for changing number of TCs */ - IF ( NE_16(num_param_bands_old , hParamMC->hMetadataPMC->num_parameter_bands) && EQ_16(nchan_transport_old , nchan_transport) ) + IF( NE_16( num_param_bands_old, hParamMC->hMetadataPMC->num_parameter_bands ) && EQ_16( nchan_transport_old, nchan_transport ) ) { Word16 new_param_band_idx, source_param_idx; - FOR ( new_param_band_idx = 0; new_param_band_idx < hParamMC->hMetadataPMC->num_parameter_bands; new_param_band_idx++ ) + FOR( new_param_band_idx = 0; new_param_band_idx < hParamMC->hMetadataPMC->num_parameter_bands; new_param_band_idx++ ) { - FOR ( source_param_idx = 0; source_param_idx < parameter_band_mapping.n_source_bands[new_param_band_idx]; source_param_idx++ ) + FOR( source_param_idx = 0; source_param_idx < parameter_band_mapping.n_source_bands[new_param_band_idx]; source_param_idx++ ) { /* Cx */ v_multc_fixed_16( cov_state_old.cx_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx], tmp_buf_fx, nchan_transport_old * nchan_transport_old ); @@ -1503,9 +1506,9 @@ ivas_error ivas_param_mc_dec_reconfig_fx( v_add_fx( tmp_buf_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_fx[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_fx[new_param_band_idx], nchan_transport_old * nchan_out_cov ); } } - FOR ( new_param_band_idx = 0; new_param_band_idx < max_param_band_residual; new_param_band_idx++ ) + FOR( new_param_band_idx = 0; new_param_band_idx < max_param_band_residual; new_param_band_idx++ ) { - FOR ( source_param_idx = 0; source_param_idx < parameter_band_mapping.n_source_bands[new_param_band_idx]; source_param_idx++ ) + FOR( source_param_idx = 0; source_param_idx < parameter_band_mapping.n_source_bands[new_param_band_idx]; source_param_idx++ ) { /* residual mixing matrix*/ v_multc_fixed_16( cov_state_old.mixing_matrix_res_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx], tmp_buf_fx, nchan_out_cov * nchan_out_cov ); @@ -1520,10 +1523,10 @@ ivas_error ivas_param_mc_dec_reconfig_fx( * memory allocation *-----------------------------------------------------------------*/ - IF ( GT_16(hParamMC->max_band_decorr , 0) && NE_16(nchan_transport_old , nchan_transport) ) + IF( GT_16( hParamMC->max_band_decorr, 0 ) && NE_16( nchan_transport_old, nchan_transport ) ) { free( hParamMC->proto_frame_f_fx ); - IF ( ( hParamMC->proto_frame_f_fx = (Word32 *) malloc( 2 * hParamMC->diff_proto_info->num_protos_diff * hParamMC->num_freq_bands * sizeof(Word32) ) ) == NULL ) + IF( ( hParamMC->proto_frame_f_fx = (Word32 *) malloc( 2 * hParamMC->diff_proto_info->num_protos_diff * hParamMC->num_freq_bands * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); } @@ -1531,59 +1534,59 @@ ivas_error ivas_param_mc_dec_reconfig_fx( } - IF ( NE_16(nchan_transport_old , nchan_transport) ) + IF( NE_16( nchan_transport_old, nchan_transport ) ) { - IF ( NE_16(hParamMC->synthesis_conf , PARAM_MC_SYNTH_MONO_STEREO) ) + IF( NE_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) ) { Word16 n_cldfb_slots; #if 1 /*TODO: To be removed later*/ - IF ( hParamMC->Cldfb_RealBuffer_tc != NULL ) + IF( hParamMC->Cldfb_RealBuffer_tc != NULL ) { free( hParamMC->Cldfb_RealBuffer_tc ); hParamMC->Cldfb_RealBuffer_tc = NULL; } - IF ( hParamMC->Cldfb_ImagBuffer_tc != NULL ) + IF( hParamMC->Cldfb_ImagBuffer_tc != NULL ) { free( hParamMC->Cldfb_ImagBuffer_tc ); hParamMC->Cldfb_ImagBuffer_tc = NULL; } #endif - IF ( hParamMC->Cldfb_RealBuffer_tc_fx != NULL ) + IF( hParamMC->Cldfb_RealBuffer_tc_fx != NULL ) { free( hParamMC->Cldfb_RealBuffer_tc_fx ); hParamMC->Cldfb_RealBuffer_tc_fx = NULL; } - IF ( hParamMC->Cldfb_ImagBuffer_tc_fx != NULL ) + IF( hParamMC->Cldfb_ImagBuffer_tc_fx != NULL ) { free( hParamMC->Cldfb_ImagBuffer_tc_fx ); hParamMC->Cldfb_ImagBuffer_tc_fx = NULL; } n_cldfb_slots = DEFAULT_JBM_CLDFB_TIMESLOTS; - IF ( st_ivas->hDecoderConfig->Opt_tsm ) + IF( st_ivas->hDecoderConfig->Opt_tsm ) { n_cldfb_slots = MAX_JBM_CLDFB_TIMESLOTS; } -#if 1/*TODO: To be removed later*/ - IF ( ( hParamMC->Cldfb_RealBuffer_tc = (float *) malloc( n_cldfb_slots * nchan_transport * hParamMC->num_freq_bands * sizeof( float ) ) ) == NULL ) +#if 1 /*TODO: To be removed later*/ + IF( ( hParamMC->Cldfb_RealBuffer_tc = (float *) malloc( n_cldfb_slots * nchan_transport * hParamMC->num_freq_bands * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC JBM\n" ) ); } set_zero( hParamMC->Cldfb_RealBuffer_tc, n_cldfb_slots * nchan_transport * hParamMC->num_freq_bands ); - IF ( ( hParamMC->Cldfb_ImagBuffer_tc = (float *) malloc( n_cldfb_slots * nchan_transport * hParamMC->num_freq_bands * sizeof( float ) ) ) == NULL ) + IF( ( hParamMC->Cldfb_ImagBuffer_tc = (float *) malloc( n_cldfb_slots * nchan_transport * hParamMC->num_freq_bands * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC JBM\n" ) ); } set_zero( hParamMC->Cldfb_ImagBuffer_tc, n_cldfb_slots * nchan_transport * hParamMC->num_freq_bands ); #endif - IF ( ( hParamMC->Cldfb_RealBuffer_tc_fx = (Word32 *) malloc( n_cldfb_slots * nchan_transport * hParamMC->num_freq_bands * sizeof(Word32) ) ) == NULL ) + IF( ( hParamMC->Cldfb_RealBuffer_tc_fx = (Word32 *) malloc( n_cldfb_slots * nchan_transport * hParamMC->num_freq_bands * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC JBM\n" ) ); } set_zero_fx( hParamMC->Cldfb_RealBuffer_tc_fx, n_cldfb_slots * nchan_transport * hParamMC->num_freq_bands ); - IF ( ( hParamMC->Cldfb_ImagBuffer_tc_fx = (Word32 *) malloc( n_cldfb_slots * nchan_transport * hParamMC->num_freq_bands * sizeof(Word32) ) ) == NULL ) + IF( ( hParamMC->Cldfb_ImagBuffer_tc_fx = (Word32 *) malloc( n_cldfb_slots * nchan_transport * hParamMC->num_freq_bands * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC JBM\n" ) ); } @@ -1591,24 +1594,24 @@ ivas_error ivas_param_mc_dec_reconfig_fx( } ELSE { -#if 1/*TODO:To be removed later(floating point memory dealloc)*/ - IF ( hParamMC->Cldfb_RealBuffer_tc != NULL ) +#if 1 /*TODO:To be removed later(floating point memory dealloc)*/ + IF( hParamMC->Cldfb_RealBuffer_tc != NULL ) { free( hParamMC->Cldfb_RealBuffer_tc ); hParamMC->Cldfb_RealBuffer_tc = NULL; } - IF ( hParamMC->Cldfb_ImagBuffer_tc != NULL ) + IF( hParamMC->Cldfb_ImagBuffer_tc != NULL ) { free( hParamMC->Cldfb_ImagBuffer_tc ); hParamMC->Cldfb_ImagBuffer_tc = NULL; } #endif - IF ( hParamMC->Cldfb_RealBuffer_tc_fx != NULL ) + IF( hParamMC->Cldfb_RealBuffer_tc_fx != NULL ) { free( hParamMC->Cldfb_RealBuffer_tc_fx ); hParamMC->Cldfb_RealBuffer_tc_fx = NULL; } - IF ( hParamMC->Cldfb_ImagBuffer_tc_fx != NULL ) + IF( hParamMC->Cldfb_ImagBuffer_tc_fx != NULL ) { free( hParamMC->Cldfb_ImagBuffer_tc_fx ); hParamMC->Cldfb_ImagBuffer_tc_fx = NULL; @@ -2266,7 +2269,7 @@ void ivas_param_mc_dec_close_fx( IF( hParamMC->proto_frame_dec_f_fx != NULL ) { - free( hParamMC->proto_frame_dec_f_fx); + free( hParamMC->proto_frame_dec_f_fx ); hParamMC->proto_frame_dec_f_fx = NULL; } @@ -2889,11 +2892,10 @@ void ivas_param_mc_dec_read_BS( #ifdef IVAS_FLOAT_FIXED void ivas_param_mc_dec_digest_tc_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - const uint8_t nCldfbSlots, /* i : number of CLFBS slots in the transport channels */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const uint8_t nCldfbSlots, /* i : number of CLFBS slots in the transport channels */ Word32 *transport_channels_f_fx[], - Word16 transport_f_e -) + Word16 transport_f_e ) { PARAM_MC_DEC_HANDLE hParamMC; Word16 i, ch; @@ -2926,7 +2928,7 @@ void ivas_param_mc_dec_digest_tc_fx( nchan_transport = st_ivas->nchan_transport; nchan_out_transport = st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe; - IF ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) + IF( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) { nchan_out_cldfb = BINAURAL_CHANNELS; move16(); @@ -2934,14 +2936,14 @@ void ivas_param_mc_dec_digest_tc_fx( nchan_out_cov = st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe; hSynthesisOutputSetup = &st_ivas->hTransSetup; } - ELSE IF ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_CLDFB ) + ELSE IF( hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_CLDFB ) { nchan_out_cov = nchan_out_transport; move16(); nchan_out_cldfb = st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe; hSynthesisOutputSetup = &st_ivas->hTransSetup; } - ELSE IF ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_COV || hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) + ELSE IF( hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_COV || hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) { nchan_out_cov = st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe; nchan_out_cldfb = nchan_out_cov; @@ -2960,7 +2962,7 @@ void ivas_param_mc_dec_digest_tc_fx( } /* adapt transient position */ - IF ( hParamMC->hMetadataPMC->bAttackPresent ) + IF( hParamMC->hMetadataPMC->bAttackPresent ) { hParamMC->hMetadataPMC->attackIndex = (int16_t) max( 0, hParamMC->hMetadataPMC->attackIndex + ( ( nCldfbSlots - DEFAULT_JBM_CLDFB_TIMESLOTS ) / 2 ) ); } @@ -2975,36 +2977,36 @@ void ivas_param_mc_dec_digest_tc_fx( st_ivas->hTcBuffer->nb_subframes = hParamMC->nb_subframes; mvs2s( hParamMC->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, hParamMC->nb_subframes ); - ivas_param_mc_dec_compute_interpolator_fx(hParamMC->hMetadataPMC->bAttackPresent, hParamMC->hMetadataPMC->attackIndex, nCldfbSlots, hParamMC->h_output_synthesis_params.interpolator_fx); + ivas_param_mc_dec_compute_interpolator_fx( hParamMC->hMetadataPMC->bAttackPresent, hParamMC->hMetadataPMC->attackIndex, nCldfbSlots, hParamMC->h_output_synthesis_params.interpolator_fx ); - FOR (param_band_idx = 0; param_band_idx < PARAM_MC_MAX_PARAMETER_BANDS; param_band_idx++) + FOR( param_band_idx = 0; param_band_idx < PARAM_MC_MAX_PARAMETER_BANDS; param_band_idx++ ) { - set_zero_fx(cx_fx[param_band_idx], PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS); - set_zero_fx(cx_imag_fx[param_band_idx], PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS); + set_zero_fx( cx_fx[param_band_idx], PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS ); + set_zero_fx( cx_imag_fx[param_band_idx], PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS ); } cx_e = 0; move16(); cx_imag_e = 0; move16(); - //cldfb_slots = DEFAULT_JBM_CLDFB_TIMESLOTS; + // cldfb_slots = DEFAULT_JBM_CLDFB_TIMESLOTS; move16(); - //IF (st_ivas->hDecoderConfig->Opt_tsm) + // IF (st_ivas->hDecoderConfig->Opt_tsm) //{ - // cldfb_slots = MAX_JBM_CLDFB_TIMESLOTS; - // move16(); - //} + // cldfb_slots = MAX_JBM_CLDFB_TIMESLOTS; + // move16(); + // } /* slot loop for gathering the input data */ - FOR ( slot_idx = 0; slot_idx < nCldfbSlots; slot_idx++ ) + FOR( slot_idx = 0; slot_idx < nCldfbSlots; slot_idx++ ) { - IF ( st_ivas->hDecoderConfig->Opt_tsm ) + IF( st_ivas->hDecoderConfig->Opt_tsm ) { Word32 RealBuffer_fx[CLDFB_NO_CHANNELS_MAX]; Word32 ImagBuffer_fx[CLDFB_NO_CHANNELS_MAX]; /* CLDFB Analysis*/ - FOR ( ch = 0; ch < nchan_transport; ch++ ) + FOR( ch = 0; ch < nchan_transport; ch++ ) { qout = transport_f_e; move16(); @@ -3017,7 +3019,7 @@ void ivas_param_mc_dec_digest_tc_fx( hParamMC->Cldfb_ImagBuffer_tc_e = qout; move16(); } - IF ( slot_idx >= 2 * hParamMC->hMetadataPMC->attackIndex ) + IF( slot_idx >= 2 * hParamMC->hMetadataPMC->attackIndex ) { ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( &hParamMC->Cldfb_RealBuffer_tc_fx[slot_idx * hParamMC->num_freq_bands * nchan_transport], hParamMC->Cldfb_RealBuffer_tc_e, @@ -3034,10 +3036,10 @@ void ivas_param_mc_dec_digest_tc_fx( /* map from complex input covariance to real values */ - FOR(param_band_idx = 0; param_band_idx < hParamMC->num_param_bands_synth; param_band_idx++) + FOR( param_band_idx = 0; param_band_idx < hParamMC->num_param_bands_synth; param_band_idx++ ) { /* Cx for transport channels */ - FOR(i = 0; i < nchan_transport * nchan_transport; i++) + FOR( i = 0; i < nchan_transport * nchan_transport; i++ ) { real_part_fx = cx_fx[param_band_idx][i]; @@ -3046,12 +3048,12 @@ void ivas_param_mc_dec_digest_tc_fx( move16(); /* (a-ib)(c+id) = ac + bd + i(ad-bc) */ - IF(LT_16(param_band_idx, hParamMC->max_param_band_abs_cov)) + IF( LT_16( param_band_idx, hParamMC->max_param_band_abs_cov ) ) { - L_tmp1 = Mpy_32_32(real_part_fx, real_part_fx); - L_tmp2 = Mpy_32_32(imag_part_fx, imag_part_fx); - L_tmp1 = BASOP_Util_Add_Mant32Exp(L_tmp1, cx_e + cx_e, L_tmp2, cx_imag_e + cx_imag_e, &tmp_e); - cx_fx[param_band_idx][i] = Sqrt32(L_tmp1, &tmp_e); + L_tmp1 = Mpy_32_32( real_part_fx, real_part_fx ); + L_tmp2 = Mpy_32_32( imag_part_fx, imag_part_fx ); + L_tmp1 = BASOP_Util_Add_Mant32Exp( L_tmp1, cx_e + cx_e, L_tmp2, cx_imag_e + cx_imag_e, &tmp_e ); + cx_fx[param_band_idx][i] = Sqrt32( L_tmp1, &tmp_e ); cx_buff_e[param_band_idx][i] = tmp_e; move16(); } @@ -3068,24 +3070,24 @@ void ivas_param_mc_dec_digest_tc_fx( max_e = cx_buff_e[0][0]; move16(); - FOR(param_band_idx = 0; param_band_idx < hParamMC->num_param_bands_synth; param_band_idx++) + FOR( param_band_idx = 0; param_band_idx < hParamMC->num_param_bands_synth; param_band_idx++ ) { /* Cx for transport channels */ - FOR(i = 0; i < nchan_transport * nchan_transport; i++) + FOR( i = 0; i < nchan_transport * nchan_transport; i++ ) { - IF( max_e < cx_buff_e[param_band_idx][i] ) - max_e = cx_buff_e[param_band_idx][i]; + IF( max_e < cx_buff_e[param_band_idx][i] ) + max_e = cx_buff_e[param_band_idx][i]; } } - FOR(param_band_idx = 0; param_band_idx < hParamMC->num_param_bands_synth; param_band_idx++) + FOR( param_band_idx = 0; param_band_idx < hParamMC->num_param_bands_synth; param_band_idx++ ) { /* Cx for transport channels */ - FOR(i = 0; i < nchan_transport * nchan_transport; i++) + FOR( i = 0; i < nchan_transport * nchan_transport; i++ ) { - cx_fx[param_band_idx][i] = L_shr(cx_fx[param_band_idx][i], max_e - cx_buff_e[param_band_idx][i]); + cx_fx[param_band_idx][i] = L_shr( cx_fx[param_band_idx][i], max_e - cx_buff_e[param_band_idx][i] ); } } @@ -3095,25 +3097,25 @@ void ivas_param_mc_dec_digest_tc_fx( /* we have to do it similar to the encoder in case of attacks (i.e. accumulate two bands) to ensure correct DMX of the target covariance*/ - IF ( hParamMC->hMetadataPMC->bAttackPresent && ( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) ) ) + IF( hParamMC->hMetadataPMC->bAttackPresent && ( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) ) ) { - FOR ( param_band_idx = 0; param_band_idx < hParamMC->num_param_bands_synth; param_band_idx += 2 ) + FOR( param_band_idx = 0; param_band_idx < hParamMC->num_param_bands_synth; param_band_idx += 2 ) { v_add_fx( cx_fx[param_band_idx], cx_fx[param_band_idx + 1], cx_fx[param_band_idx], nchan_transport * nchan_transport ); Copy32( cx_fx[param_band_idx], cx_fx[param_band_idx + 1], nchan_transport * nchan_transport ); } } - IF ( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) ) + IF( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) ) { // streams not entering into this block - //ivas_param_mc_get_mono_stereo_mixing_matrices( hParamMC, cx, hParamMC->h_output_synthesis_cov_state.mixing_matrix, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res, nchan_out_transport, nchan_transport, nchan_out_cov ); + // ivas_param_mc_get_mono_stereo_mixing_matrices( hParamMC, cx, hParamMC->h_output_synthesis_cov_state.mixing_matrix, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res, nchan_out_transport, nchan_transport, nchan_out_cov ); } ELSE { /* generate mixing matrices */ - ivas_param_mc_get_mixing_matrices_fx( hParamMC, hSynthesisOutputSetup, cx_fx, cx_e, hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp, nchan_out_transport, hParamMC->synthesis_conf, nchan_transport, nchan_out_cov ); + ivas_param_mc_get_mixing_matrices_fx( hParamMC, hSynthesisOutputSetup, cx_fx, cx_e, hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp, nchan_out_transport, hParamMC->synthesis_conf, nchan_transport, nchan_out_cov ); } pop_wmops(); @@ -4020,7 +4022,7 @@ void ivas_param_mc_dec_render( * Parametric MC decoding process *------------------------------------------------------------------------*/ -#if 0 //NO Calling location +#if 0 // NO Calling location void ivas_param_mc_dec( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ float *output_f[] /* i/o: synthesized core-coder transport channels/DirAC output */ @@ -4062,7 +4064,7 @@ void ivas_param_mc_dec( #ifdef IVAS_FLOAT_FIXED static void ivas_param_mc_dec_init_fx( - PARAM_MC_DEC_HANDLE hParamMC, /* i/o: decoder DirAC handle */ + PARAM_MC_DEC_HANDLE hParamMC, /* i/o: decoder DirAC handle */ const Word16 nchan_transport, /* i : number of input (transport) channels */ const Word16 nchan_cov ) /* i : number of cov synthesis channels */ { @@ -4075,7 +4077,7 @@ static void ivas_param_mc_dec_init_fx( *-----------------------------------------------------------------*/ /* decorrelation */ - IF ( GT_16(hParamMC->max_band_decorr , 0) ) + IF( GT_16( hParamMC->max_band_decorr, 0 ) ) { len = hParamMC->diff_proto_info->num_protos_diff * hParamMC->h_freq_domain_decorr_ap_params->h_onset_detection_power_params.max_band_decorr; @@ -4088,9 +4090,9 @@ static void ivas_param_mc_dec_init_fx( max_param_band_residual = 0; /* output synthesis */ - FOR ( k = hParamMC->hMetadataPMC->num_parameter_bands; k >= 0; k-- ) + FOR( k = hParamMC->hMetadataPMC->num_parameter_bands; k >= 0; k-- ) { - IF ( LE_16(hParamMC->band_grouping[k] , hParamMC->max_band_decorr) ) + IF( LE_16( hParamMC->band_grouping[k], hParamMC->max_band_decorr ) ) { max_param_band_residual = k; break; @@ -4103,7 +4105,7 @@ static void ivas_param_mc_dec_init_fx( * init proto frames *-----------------------------------------------------------------*/ - IF ( GT_16(hParamMC->max_band_decorr , 0) ) + IF( GT_16( hParamMC->max_band_decorr, 0 ) ) { set_zero_fx( hParamMC->proto_frame_f_fx, 2 * hParamMC->diff_proto_info->num_protos_diff * hParamMC->num_freq_bands ); set32_fx( hParamMC->proto_frame_dec_f_fx, 0, 2 * nchan_cov * hParamMC->num_freq_bands ); @@ -4158,7 +4160,7 @@ static void ivas_param_mc_dec_init( set_zero( hParamMC->proto_frame_f, 2 * hParamMC->diff_proto_info->num_protos_diff * hParamMC->num_freq_bands ); set_zero( hParamMC->proto_frame_dec_f, 2 * nchan_cov * hParamMC->num_freq_bands ); #ifdef IVAS_FLOAT_FIXED - set32_fx(hParamMC->proto_frame_dec_f_fx, 0, 2 * nchan_cov * hParamMC->num_freq_bands); + set32_fx( hParamMC->proto_frame_dec_f_fx, 0, 2 * nchan_cov * hParamMC->num_freq_bands ); #endif } @@ -4220,61 +4222,60 @@ static void param_mc_protoSignalComputation( } #else static void param_mc_protoSignalComputation_fx( - Word32 *RealBuffer_fx, /* i : CLDFB samples of the transport channels (real part) */ - Word32 *ImagBuffer_fx, /* i : CLDFB samples of the transport channels (imaginary part) */ - Word32 *proto_frame_f_fx, /* o : interleaved complex prototype CLDFB samples */ - const PARAM_MC_DIFF_PROTO_INFO *diff_proto_info, /* i : prototype generation information */ - const int16_t num_freq_bands /* i : number of frequency bands for the prototypes */ + Word32 *RealBuffer_fx, /* i : CLDFB samples of the transport channels (real part) */ + Word32 *ImagBuffer_fx, /* i : CLDFB samples of the transport channels (imaginary part) */ + Word32 *proto_frame_f_fx, /* o : interleaved complex prototype CLDFB samples */ + const PARAM_MC_DIFF_PROTO_INFO *diff_proto_info, /* i : prototype generation information */ + const int16_t num_freq_bands /* i : number of frequency bands for the prototypes */ ) { - Word16 band; - Word16 proto_ch_idx, source_ch_cnt; + Word16 band; + Word16 proto_ch_idx, source_ch_cnt; - Word32 *p_proto_frame_fx; - Word32 *p_real_buffer_fx; // Q12 - Word32 *p_imag_buffer_fx; // Q12 + Word32 *p_proto_frame_fx; + Word32 *p_real_buffer_fx; // Q12 + Word32 *p_imag_buffer_fx; // Q12 - set32_fx(proto_frame_f_fx, 0, 2 * num_freq_bands * diff_proto_info->num_protos_diff); + set32_fx( proto_frame_f_fx, 0, 2 * num_freq_bands * diff_proto_info->num_protos_diff ); - FOR (proto_ch_idx = 0; proto_ch_idx < diff_proto_info->num_protos_diff; proto_ch_idx++) - { - Word16 num_source_ch = diff_proto_info->num_source_chan_diff[proto_ch_idx]; - move16(); - - FOR (source_ch_cnt = 0; source_ch_cnt < num_source_ch; source_ch_cnt++) + FOR( proto_ch_idx = 0; proto_ch_idx < diff_proto_info->num_protos_diff; proto_ch_idx++ ) { + Word16 num_source_ch = diff_proto_info->num_source_chan_diff[proto_ch_idx]; + move16(); - Word32 fac_fx = diff_proto_info->proto_fac_fx[proto_ch_idx][source_ch_cnt]; - move32(); - - Word16 source_ch_idx = diff_proto_info->source_chan_idx[proto_ch_idx][source_ch_cnt]; - move16(); + FOR( source_ch_cnt = 0; source_ch_cnt < num_source_ch; source_ch_cnt++ ) + { - p_proto_frame_fx = &proto_frame_f_fx[proto_ch_idx * num_freq_bands * 2]; - p_real_buffer_fx = &RealBuffer_fx[source_ch_idx * num_freq_bands]; - p_imag_buffer_fx = &ImagBuffer_fx[source_ch_idx * num_freq_bands]; + Word32 fac_fx = diff_proto_info->proto_fac_fx[proto_ch_idx][source_ch_cnt]; + move32(); - FOR (band = 0; band < num_freq_bands; band++) - { + Word16 source_ch_idx = diff_proto_info->source_chan_idx[proto_ch_idx][source_ch_cnt]; + move16(); - Word32 tmp_x = Mpy_32_32(fac_fx, (*(p_real_buffer_fx++))); // Q(30 + 6 - 31) :: Q5 + p_proto_frame_fx = &proto_frame_f_fx[proto_ch_idx * num_freq_bands * 2]; + p_real_buffer_fx = &RealBuffer_fx[source_ch_idx * num_freq_bands]; + p_imag_buffer_fx = &ImagBuffer_fx[source_ch_idx * num_freq_bands]; - *(p_proto_frame_fx) = L_add(*(p_proto_frame_fx), tmp_x); - move32(); - p_proto_frame_fx++; + FOR( band = 0; band < num_freq_bands; band++ ) + { - tmp_x = Mpy_32_32(fac_fx, (*(p_imag_buffer_fx++))); // Q(30 + 6 - 31) :: Q5 + Word32 tmp_x = Mpy_32_32( fac_fx, ( *( p_real_buffer_fx++ ) ) ); // Q(30 + 6 - 31) :: Q5 - *(p_proto_frame_fx) = L_add(*(p_proto_frame_fx), tmp_x); - move32(); - p_proto_frame_fx++; + *( p_proto_frame_fx ) = L_add( *( p_proto_frame_fx ), tmp_x ); + move32(); + p_proto_frame_fx++; + + tmp_x = Mpy_32_32( fac_fx, ( *( p_imag_buffer_fx++ ) ) ); // Q(30 + 6 - 31) :: Q5 - } + *( p_proto_frame_fx ) = L_add( *( p_proto_frame_fx ), tmp_x ); + move32(); + p_proto_frame_fx++; + } + } } - } - return; + return; } #endif @@ -4375,9 +4376,9 @@ static int16_t ivas_param_mc_bin2dec( *------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED static Word16 ivas_param_mc_uniform_decoder_fx( - Word16 *seq, /* o : decoded sequence of float values */ + Word16 *seq, /* o : decoded sequence of float values */ const Word16 sz_seq, /* i : number of values to decode */ - const Word16 *alphabet, /* i : codebook */ + const Word16 *alphabet, /* i : codebook */ const Word16 N, /* i : number of bits per coded index */ UWord16 bit_buffer[PARAM_MC_MAX_BITS] /* i : bit buffer to decode */ ) @@ -4389,13 +4390,13 @@ static Word16 ivas_param_mc_uniform_decoder_fx( n_bits = 0; assert( N * sz_seq < PARAM_MC_MAX_BITS ); - FOR ( i = 0; i < sz_seq; ++i ) + FOR( i = 0; i < sz_seq; ++i ) { idx = ivas_param_mc_bin2dec( &bit_buffer[i * N], N ); seq[i] = alphabet[idx]; } - n_bits = imult1616(N , sz_seq); + n_bits = imult1616( N, sz_seq ); return n_bits; } @@ -4457,15 +4458,15 @@ static Word16 ivas_param_mc_range_decoder_LC( #ifdef IVAS_FLOAT_FIXED rc_uni_dec_init_fx( &rc_st_dec, bit_buffer, nbbits - 32 ); /* (nbbits + 30) entries are read by the decoder */ #else - rc_uni_dec_init( &rc_st_dec, bit_buffer, nbbits - 32 ); /* (nbbits + 30) entries are read by the decoder */ + rc_uni_dec_init( &rc_st_dec, bit_buffer, nbbits - 32 ); /* (nbbits + 30) entries are read by the decoder */ #endif // IVAS_FLOAT_FIXED /* Main Loop through the indices */ - FOR ( k = 0; k < sz_seq; k++ ) + FOR( k = 0; k < sz_seq; k++ ) { #ifdef IVAS_FLOAT_FIXED r = rc_uni_dec_read_symbol_fastS_fx( &rc_st_dec, cft, sft, sz_alphabet, tot_shift ); /*Alphabet size = 17 (2^4 = 16 MSB symbols + 1 ESC symbol) */ - /* r is the symbol read, the possible values are {0,1,....alphabet_size - 1} */ + /* r is the symbol read, the possible values are {0,1,....alphabet_size - 1} */ #else r = rc_uni_dec_read_symbol_fastS( &rc_st_dec, cft, sft, sz_alphabet, tot_shift ); /*Alphabet size = 17 (2^4 = 16 MSB symbols + 1 ESC symbol) */ /* r is the symbol read, the possible values are {0,1,....alphabet_size - 1} */ @@ -4475,7 +4476,7 @@ static Word16 ivas_param_mc_range_decoder_LC( cur_bit_pos = rc_uni_dec_virtual_finish( &rc_st_dec ); /* Confirm that there is no overflow */ - IF ( cur_bit_pos > nbbits ) + IF( cur_bit_pos > nbbits ) { *BER_detect |= 1; } @@ -4487,7 +4488,7 @@ static Word16 ivas_param_mc_range_decoder_LC( /*st->next_bit_pos = rc_uni_dec_finish(&rc_st_dec);*/ /* Check for bitstream errors */ - IF ( rc_st_dec.bit_error_detected != 0 ) + IF( rc_st_dec.bit_error_detected != 0 ) { *BER_detect |= 1; } @@ -4609,7 +4610,7 @@ static void remove_lfe_from_cy_fx( const Word16 nY, /* i : dimension of the covariance matrix */ Word16 lfe_indices[PARAM_MC_LOCAL_SZ_LFE_MAP], /* i : LFE index */ Word16 num_lfe, /* i : number of LFEs */ - Word32 *cy, /* i : covariance matrix */ + Word32 *cy, /* i : covariance matrix */ Word32 *cy_woLFE /* o : covariance matrix with LFE removed */ ) { @@ -4621,13 +4622,13 @@ static void remove_lfe_from_cy_fx( ptrCy = cy; ptrCy_out = cy_woLFE; - FOR ( lfe_idx1 = 0; lfe_idx1 < num_lfe + 1; lfe_idx1++ ) + FOR( lfe_idx1 = 0; lfe_idx1 < num_lfe + 1; lfe_idx1++ ) { - FOR ( ch_idx1 = lfe_indices[lfe_idx1] + 1; ch_idx1 < lfe_indices[lfe_idx1 + 1]; ch_idx1++ ) + FOR( ch_idx1 = lfe_indices[lfe_idx1] + 1; ch_idx1 < lfe_indices[lfe_idx1 + 1]; ch_idx1++ ) { - FOR ( lfe_idx2 = 0; lfe_idx2 < num_lfe + 1; lfe_idx2++ ) + FOR( lfe_idx2 = 0; lfe_idx2 < num_lfe + 1; lfe_idx2++ ) { - FOR ( ch_idx2 = lfe_indices[lfe_idx2] + 1; ch_idx2 < lfe_indices[lfe_idx2 + 1]; ch_idx2++ ) + FOR( ch_idx2 = lfe_indices[lfe_idx2] + 1; ch_idx2 < lfe_indices[lfe_idx2 + 1]; ch_idx2++ ) { *( ptrCy_out++ ) = *( ptrCy++ ); move32(); @@ -4813,7 +4814,7 @@ static void ivas_param_mc_get_mixing_matrices( synth_config, nY_intern, nX, Cx_state, Cproto, Cy_state ); - //dbgwrite2_txt(Cy_state_fx,nY_intern*nY_intern,"../cy_state.txt"); + // dbgwrite2_txt(Cy_state_fx,nY_intern*nY_intern,"../cy_state.txt"); #endif /* Smoothing: Sum over two buffers */ @@ -4843,7 +4844,7 @@ static void ivas_param_mc_get_mixing_matrices( Word32 *Cy_fx = (Word32 *) malloc( MAX_CICP_CHANNELS * MAX_CICP_CHANNELS * sizeof( Word32 ) ); Word16 Cy_e; - f2me_buf( Cy_full, Cy_full_fx, &Cy_full_e, nY_cov*nY_cov ); + f2me_buf( Cy_full, Cy_full_fx, &Cy_full_e, nY_cov * nY_cov ); Cy_e = Cy_full_e; remove_lfe_from_cy_fx( nY_cov, lfe_indices, hSynthesisOutputSetup->num_lfe, Cy_full_fx, Cy_fx ); @@ -4895,9 +4896,9 @@ static void ivas_param_mc_get_mixing_matrices( mat_mult_buffer1_e += guard_bits; } - matrix_product_diag_fx(mat_mult_buffer1_fx, mat_mult_buffer1_e, nY_band, nX, 0, proto_matrix_ptr_fx, proto_matrix_ptr_e, nY_band, nX, 1, Cproto_diag_fx,&Cproto_diag_e); + matrix_product_diag_fx( mat_mult_buffer1_fx, mat_mult_buffer1_e, nY_band, nX, 0, proto_matrix_ptr_fx, proto_matrix_ptr_e, nY_band, nX, 1, Cproto_diag_fx, &Cproto_diag_e ); - me2f_buf(Cproto_diag_fx, Cproto_diag_e, Cproto_diag, nY_band); + me2f_buf( Cproto_diag_fx, Cproto_diag_e, Cproto_diag, nY_band ); #else matrix_product_diag( mat_mult_buffer1, nY_band, nX, 0, proto_matrix_ptr, nY_band, nX, 1, Cproto_diag ); #endif @@ -5015,10 +5016,10 @@ static void ivas_param_mc_get_mixing_matrices_fx( Word16 *mixing_matrix_e, Word32 *mixing_matrix_res_fx[], Word16 *mixing_matrix_res_e, - const Word16 nY_intern, /* i : number of channels in the transported format */ - const PARAM_MC_SYNTHESIS_CONF synth_config, /* i : Parametric MC synthesis config */ - const Word16 nX, /* i : number of transport channels */ - const Word16 nY_cov /* i : number of covariance synthesis output channels */ + const Word16 nY_intern, /* i : number of channels in the transported format */ + const PARAM_MC_SYNTHESIS_CONF synth_config, /* i : Parametric MC synthesis config */ + const Word16 nX, /* i : number of transport channels */ + const Word16 nY_cov /* i : number of covariance synthesis output channels */ ) { Word16 matSize = MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS; @@ -5074,28 +5075,28 @@ static void ivas_param_mc_get_mixing_matrices_fx( Word16 Cy_e, Cx_e; Word16 Cy_full_e; - set_zero_fx(Cproto_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS); - set_zero_fx(mat_mult_buffer1_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS); - set_zero_fx(proto_matrix_noLFE_fx, PARAM_MC_MAX_TRANSPORT_CHANS * MAX_CICP_CHANNELS); + set_zero_fx( Cproto_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS ); + set_zero_fx( mat_mult_buffer1_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS ); + set_zero_fx( proto_matrix_noLFE_fx, PARAM_MC_MAX_TRANSPORT_CHANS * MAX_CICP_CHANNELS ); Word16 proto_matrix_noLFE_e = 0; - Word16 guard_bit_cx = find_guarded_bits_fx(nY_intern + 1); - Word16 guard_bit_cy = find_guarded_bits_fx(nY_cov * nY_cov); + Word16 guard_bit_cx = find_guarded_bits_fx( nY_intern + 1 ); + Word16 guard_bit_cy = find_guarded_bits_fx( nY_cov * nY_cov ); Word32 Cx_in_fx[PARAM_MC_MAX_PARAMETER_BANDS][PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; - FOR (i = 0; i < PARAM_MC_MAX_PARAMETER_BANDS; i++) - Copy32(Cx_in_fixed[i], Cx_in_fx[i], PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS); + FOR( i = 0; i < PARAM_MC_MAX_PARAMETER_BANDS; i++ ) + Copy32( Cx_in_fixed[i], Cx_in_fx[i], PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS ); nY_band = nY_cov; num_lfe_bands = 0; remove_lfe = 0; set_s( lfe_indices, -1, PARAM_MC_LOCAL_SZ_LFE_MAP ); - IF ( hSynthesisOutputSetup->num_lfe ) + IF( hSynthesisOutputSetup->num_lfe ) { Word32 *proto_matrix_ptr_in_fx; - FOR ( lfe_idx1 = 0; lfe_idx1 < hSynthesisOutputSetup->num_lfe; lfe_idx1++ ) + FOR( lfe_idx1 = 0; lfe_idx1 < hSynthesisOutputSetup->num_lfe; lfe_idx1++ ) { lfe_indices[lfe_idx1 + 1] = hSynthesisOutputSetup->index_lfe[lfe_idx1]; } @@ -5105,15 +5106,15 @@ static void ivas_param_mc_get_mixing_matrices_fx( proto_matrix_noLFE_e = proto_matrix_e; move16(); - set_zero_fx(proto_matrix_noLFE_fx, PARAM_MC_MAX_TRANSPORT_CHANS * MAX_CICP_CHANNELS); + set_zero_fx( proto_matrix_noLFE_fx, PARAM_MC_MAX_TRANSPORT_CHANS * MAX_CICP_CHANNELS ); - FOR(ch_idx1 = 0; ch_idx1 < nX; ch_idx1++) + FOR( ch_idx1 = 0; ch_idx1 < nX; ch_idx1++ ) { - FOR(lfe_idx1 = 0; lfe_idx1 < hSynthesisOutputSetup->num_lfe + 1; lfe_idx1++) + FOR( lfe_idx1 = 0; lfe_idx1 < hSynthesisOutputSetup->num_lfe + 1; lfe_idx1++ ) { - FOR(ch_idx2 = lfe_indices[lfe_idx1] + 1; ch_idx2 < lfe_indices[lfe_idx1 + 1]; ch_idx2++) + FOR( ch_idx2 = lfe_indices[lfe_idx1] + 1; ch_idx2 < lfe_indices[lfe_idx1 + 1]; ch_idx2++ ) { - *(proto_matrix_ptr_fx++) = *(proto_matrix_ptr_in_fx++); + *( proto_matrix_ptr_fx++ ) = *( proto_matrix_ptr_in_fx++ ); } proto_matrix_ptr_in_fx++; } @@ -5124,14 +5125,14 @@ static void ivas_param_mc_get_mixing_matrices_fx( move16(); } - IF ( hParamMC->hMetadataPMC->lfe_on ) + IF( hParamMC->hMetadataPMC->lfe_on ) { num_lfe_bands = PARAM_MC_MAX_BAND_LFE; } - FOR ( param_band_idx = 0; param_band_idx < hParamMC->num_param_bands_synth; param_band_idx++ ) + FOR( param_band_idx = 0; param_band_idx < hParamMC->num_param_bands_synth; param_band_idx++ ) { - IF ( hSynthesisOutputSetup->num_lfe > 0 && param_band_idx >= num_lfe_bands ) + IF( hSynthesisOutputSetup->num_lfe > 0 && param_band_idx >= num_lfe_bands ) { remove_lfe = 1; move16(); @@ -5162,17 +5163,17 @@ static void ivas_param_mc_get_mixing_matrices_fx( Cx_state_e = Cx_in_e; move16(); - matrix_product_fx(hParamMC->proto_matrix_int_fx, nY_intern, nX, 0, Cx_state_fx, nX, nX, 0, mat_mult_buffer1_fx); + matrix_product_fx( hParamMC->proto_matrix_int_fx, nY_intern, nX, 0, Cx_state_fx, nX, nX, 0, mat_mult_buffer1_fx ); mat_mult_buffer1_e = hParamMC->proto_matrix_int_e + Cx_in_e; - matrix_product_fx(mat_mult_buffer1_fx, nY_intern, nX, 0, hParamMC->proto_matrix_int_fx, nY_intern, nX, 1, Cproto_fx); + matrix_product_fx( mat_mult_buffer1_fx, nY_intern, nX, 0, hParamMC->proto_matrix_int_fx, nY_intern, nX, 1, Cproto_fx ); Cproto_e = mat_mult_buffer1_e + hParamMC->proto_matrix_int_e; move16(); - FOR (ch_idx1 = 0; ch_idx1 < nY_intern; ch_idx1++) + FOR( ch_idx1 = 0; ch_idx1 < nY_intern; ch_idx1++ ) { - IF (BASOP_Util_Cmp_Mant32Exp( Cproto_fx[ch_idx1 + ch_idx1 * nY_intern], Cproto_e, 0, 0 ) < 0 ) + IF( BASOP_Util_Cmp_Mant32Exp( Cproto_fx[ch_idx1 + ch_idx1 * nY_intern], Cproto_e, 0, 0 ) < 0 ) { Cproto_fx[ch_idx1 + ch_idx1 * nY_intern] = 0; move32(); @@ -5194,11 +5195,11 @@ static void ivas_param_mc_get_mixing_matrices_fx( // dbgwrite2_txt(Cy_state_fx,nY_intern*nY_intern,"../cy_state_fx.txt"); /* Smoothing: Sum over two buffers */ - IF ( hParamMC->hMetadataPMC->bAttackPresent ) + IF( hParamMC->hMetadataPMC->bAttackPresent ) { /* no smoothing on attacks */ - Copy32(Cx_state_fx, Cx_fx, nX * nX); - Copy32(Cy_state_fx, Cy_full_fx, nY_cov * nY_cov); + Copy32( Cx_state_fx, Cx_fx, nX * nX ); + Copy32( Cy_state_fx, Cy_full_fx, nY_cov * nY_cov ); Cy_full_e = Cy_state_e; move16(); Cx_e = Cx_state_e; @@ -5207,42 +5208,41 @@ static void ivas_param_mc_get_mixing_matrices_fx( ELSE { /* smoothing gains are now identical to one, simply add up */ - //v_add( Cy_state, Cy_old_state, Cy_full, nY_cov * nY_cov ); + // v_add( Cy_state, Cy_old_state, Cy_full, nY_cov * nY_cov ); - tmp_e = max(hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx], Cx_state_e) + guard_bit_cx; - FOR(i = 0; i < nX * nX; i++) + tmp_e = max( hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx], Cx_state_e ) + guard_bit_cx; + FOR( i = 0; i < nX * nX; i++ ) { - Cx_old_state_fx[i] = L_shr(Cx_old_state_fx[i], tmp_e - hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx]); - Cx_state_fx[i] = L_shr(Cx_state_fx[i], tmp_e - Cx_state_e); + Cx_old_state_fx[i] = L_shr( Cx_old_state_fx[i], tmp_e - hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx] ); + Cx_state_fx[i] = L_shr( Cx_state_fx[i], tmp_e - Cx_state_e ); } hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx] = tmp_e; Cx_state_e = tmp_e; move16(); - tmp_e = max(hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx], Cy_state_e) + guard_bit_cy; - FOR(i = 0; i < nY_cov * nY_cov; i++) + tmp_e = max( hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx], Cy_state_e ) + guard_bit_cy; + FOR( i = 0; i < nY_cov * nY_cov; i++ ) { - Cy_old_state_fx[i] = L_shr(Cy_old_state_fx[i], tmp_e - hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx]); - Cy_state_fx[i] = L_shr(Cy_state_fx[i], tmp_e - Cy_state_e); + Cy_old_state_fx[i] = L_shr( Cy_old_state_fx[i], tmp_e - hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx] ); + Cy_state_fx[i] = L_shr( Cy_state_fx[i], tmp_e - Cy_state_e ); } hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx] = tmp_e; Cy_state_e = tmp_e; move16(); - v_add_32(Cx_state_fx, Cx_old_state_fx, Cx_fx, nX * nX); - v_add_32(Cy_state_fx, Cy_old_state_fx, Cy_full_fx, nY_cov * nY_cov); + v_add_32( Cx_state_fx, Cx_old_state_fx, Cx_fx, nX * nX ); + v_add_32( Cy_state_fx, Cy_old_state_fx, Cy_full_fx, nY_cov * nY_cov ); Cy_full_e = Cy_state_e; move16(); Cx_e = Cx_state_e; move16(); - } - Copy32(Cx_state_fx, Cx_old_state_fx, nX * nX); + Copy32( Cx_state_fx, Cx_old_state_fx, nX * nX ); - Copy32(Cy_state_fx, Cy_old_state_fx, nY_cov * nY_cov); + Copy32( Cy_state_fx, Cy_old_state_fx, nY_cov * nY_cov ); Word16 new_e = 0; @@ -5254,7 +5254,7 @@ static void ivas_param_mc_get_mixing_matrices_fx( FOR( i = 0; i < nX * nX; i++ ) { - IF(NE_32(Cx_old_state_fx[i], 0)) + IF( NE_32( Cx_old_state_fx[i], 0 ) ) { new_e = hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx]; move16(); @@ -5269,7 +5269,7 @@ static void ivas_param_mc_get_mixing_matrices_fx( FOR( i = 0; i < nY_cov * nY_cov; i++ ) { - IF(NE_32(Cy_old_state_fx[i], 0)) + IF( NE_32( Cy_old_state_fx[i], 0 ) ) { new_e = hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx]; move16(); @@ -5280,7 +5280,7 @@ static void ivas_param_mc_get_mixing_matrices_fx( move16(); /* remove LFE IF necessary */ - IF ( remove_lfe ) + IF( remove_lfe ) { Cy_e = Cy_full_e; @@ -5288,31 +5288,31 @@ static void ivas_param_mc_get_mixing_matrices_fx( } ELSE { - Copy32(Cy_full_fx, Cy_fx, nY_band * nY_band); + Copy32( Cy_full_fx, Cy_fx, nY_band * nY_band ); Cy_e = Cy_full_e; move16(); } - matrix_product_fx(proto_matrix_ptr_fx, nY_band, nX, 0, Cx_fx, nX, nX, 0, mat_mult_buffer1_fx); + matrix_product_fx( proto_matrix_ptr_fx, nY_band, nX, 0, Cx_fx, nX, nX, 0, mat_mult_buffer1_fx ); mat_mult_buffer1_e = proto_matrix_ptr_e + Cx_e; Word16 guard_bits = find_guarded_bits_fx( nY_band + 1 ); - FOR ( i = 0; i < nY_band * nX; ++i ) + FOR( i = 0; i < nY_band * nX; ++i ) { proto_matrix_ptr_fx[i] = L_shr( proto_matrix_ptr_fx[i], guard_bits ); - mat_mult_buffer1_fx[i] = L_shr(mat_mult_buffer1_fx[i], guard_bits); + mat_mult_buffer1_fx[i] = L_shr( mat_mult_buffer1_fx[i], guard_bits ); } - proto_matrix_ptr_e += guard_bits; - mat_mult_buffer1_e += guard_bits; + proto_matrix_ptr_e += guard_bits; + mat_mult_buffer1_e += guard_bits; - matrix_product_diag_fx(mat_mult_buffer1_fx, mat_mult_buffer1_e, nY_band, nX, 0, proto_matrix_ptr_fx, proto_matrix_ptr_e, nY_band, nX, 1, Cproto_diag_fx,&Cproto_diag_e); + matrix_product_diag_fx( mat_mult_buffer1_fx, mat_mult_buffer1_e, nY_band, nX, 0, proto_matrix_ptr_fx, proto_matrix_ptr_e, nY_band, nX, 1, Cproto_diag_fx, &Cproto_diag_e ); - FOR(i = 0; i < nY_band * nX; ++i) + FOR( i = 0; i < nY_band * nX; ++i ) { - proto_matrix_ptr_fx[i] = L_shl(proto_matrix_ptr_fx[i], guard_bits); - mat_mult_buffer1_fx[i] = L_shl(mat_mult_buffer1_fx[i], guard_bits); + proto_matrix_ptr_fx[i] = L_shl( proto_matrix_ptr_fx[i], guard_bits ); + mat_mult_buffer1_fx[i] = L_shl( mat_mult_buffer1_fx[i], guard_bits ); } proto_matrix_ptr_e -= guard_bits; @@ -5320,9 +5320,9 @@ static void ivas_param_mc_get_mixing_matrices_fx( /* make sure we have no negative entries in Cproto_diag due to rounding errors */ - FOR (ch_idx1 = 0; ch_idx1 < nY_band; ch_idx1++) + FOR( ch_idx1 = 0; ch_idx1 < nY_band; ch_idx1++ ) { - IF (BASOP_Util_Cmp_Mant32Exp( Cproto_diag_fx[ch_idx1], Cproto_diag_e, 0, 0 ) < 0 ) + IF( BASOP_Util_Cmp_Mant32Exp( Cproto_diag_fx[ch_idx1], Cproto_diag_e, 0, 0 ) < 0 ) { Cproto_diag_fx[ch_idx1] = 0; move16(); @@ -5333,25 +5333,25 @@ static void ivas_param_mc_get_mixing_matrices_fx( /* Computing the mixing matrices */ /* bands with decorr */ - IF ( brange[0] < hParamMC->h_output_synthesis_params.max_band_decorr ) + IF( brange[0] < hParamMC->h_output_synthesis_params.max_band_decorr ) { computeMixingMatrices_fx( nX, nY_band, Cx_fx, Cx_e, Cy_fx, Cy_e, proto_matrix_ptr_fx, proto_matrix_ptr_e, 0, PARAM_MC_REG_SX_FX, 0, PARAM_MC_REG_GHAT_FX, 0, mixing_matrix_local_fx, &mixing_matrix_local_e, Cr_fx, &Cr_e ); /* Compute mixing matrix FOR residual */ - computeMixingMatricesResidual_fx( nY_band, Cproto_diag_fx, Cproto_diag_e, Cr_fx, Cr_e, PARAM_MC_REG_SX_FX, 0, PARAM_MC_REG_GHAT_FX, 0, mixing_matrix_res_local_fx, &mixing_matrix_res_local_e); + computeMixingMatricesResidual_fx( nY_band, Cproto_diag_fx, Cproto_diag_e, Cr_fx, Cr_e, PARAM_MC_REG_SX_FX, 0, PARAM_MC_REG_GHAT_FX, 0, mixing_matrix_res_local_fx, &mixing_matrix_res_local_e ); - IF ( remove_lfe ) + IF( remove_lfe ) { set_zero_fx( mixing_matrix_res_fx[param_band_idx], nY_cov * nY_cov ); ptrMM_fx = mixing_matrix_res_local_fx; ptrMM_out_fx = mixing_matrix_res_fx[param_band_idx]; - FOR ( lfe_idx1 = 0; lfe_idx1 < hSynthesisOutputSetup->num_lfe + 1; lfe_idx1++ ) + FOR( lfe_idx1 = 0; lfe_idx1 < hSynthesisOutputSetup->num_lfe + 1; lfe_idx1++ ) { - FOR ( ch_idx1 = lfe_indices[lfe_idx1] + 1; ch_idx1 < lfe_indices[lfe_idx1 + 1]; ch_idx1++ ) + FOR( ch_idx1 = lfe_indices[lfe_idx1] + 1; ch_idx1 < lfe_indices[lfe_idx1 + 1]; ch_idx1++ ) { - FOR ( lfe_idx2 = 0; lfe_idx2 < hSynthesisOutputSetup->num_lfe + 1; lfe_idx2++ ) + FOR( lfe_idx2 = 0; lfe_idx2 < hSynthesisOutputSetup->num_lfe + 1; lfe_idx2++ ) { - FOR ( ch_idx2 = lfe_indices[lfe_idx2] + 1; ch_idx2 < lfe_indices[lfe_idx2 + 1]; ch_idx2++ ) + FOR( ch_idx2 = lfe_indices[lfe_idx2] + 1; ch_idx2 < lfe_indices[lfe_idx2 + 1]; ch_idx2++ ) { *( ptrMM_out_fx++ ) = *( ptrMM_fx++ ); } @@ -5366,60 +5366,60 @@ static void ivas_param_mc_get_mixing_matrices_fx( } ELSE { - Copy32(mixing_matrix_res_local_fx, mixing_matrix_res_fx[param_band_idx], nY_cov * nY_cov); + Copy32( mixing_matrix_res_local_fx, mixing_matrix_res_fx[param_band_idx], nY_cov * nY_cov ); mixing_matrix_res_e[param_band_idx] = mixing_matrix_res_local_e; move16(); } } - ELSE IF ( brange[0] < hParamMC->max_band_energy_compensation ) + ELSE IF( brange[0] < hParamMC->max_band_energy_compensation ) { /* Compute mixing matrices (energy compensation only) */ - computeMixingMatrices_fx( nX, nY_band, Cx_fx, Cx_e, Cy_fx, Cy_e, proto_matrix_ptr_fx, proto_matrix_ptr_e, 1, PARAM_MC_REG_SX_FX, 0, PARAM_MC_REG_GHAT_FX, 0, mixing_matrix_local_fx, &mixing_matrix_local_e, Cr_fx, &Cr_e ); + computeMixingMatrices_fx( nX, nY_band, Cx_fx, Cx_e, Cy_fx, Cy_e, proto_matrix_ptr_fx, proto_matrix_ptr_e, 1, PARAM_MC_REG_SX_FX, 0, PARAM_MC_REG_GHAT_FX, 0, mixing_matrix_local_fx, &mixing_matrix_local_e, Cr_fx, &Cr_e ); } ELSE { /*IF neither decorrelation nor energy compensation is applied*/ - FOR ( i = 0; i < nY_band; i++ ) + FOR( i = 0; i < nY_band; i++ ) { - tmp = BASOP_Util_Divide3232_Scale(Cy_fx[i], L_add(Cproto_diag_fx[i], EPSILON_FX) , &tmp_e); + tmp = BASOP_Util_Divide3232_Scale( Cy_fx[i], L_add( Cproto_diag_fx[i], EPSILON_FX ), &tmp_e ); tmp_e = Cy_diag_e + Cproto_diag_e; - L_tmp = Sqrt32(L_deposit_h(tmp), &tmp_e); + L_tmp = Sqrt32( L_deposit_h( tmp ), &tmp_e ); Cy_diag_fx[i] = L_tmp; move32(); Cy_diag_buff_e[i] = tmp_e; move16(); } - + Cy_diag_e = Cy_diag_buff_e[0]; move16(); - FOR (i = 1; i < nY_band; i++) + FOR( i = 1; i < nY_band; i++ ) { - IF (Cy_diag_e < Cy_diag_buff_e[i]) - Cy_diag_e = Cy_diag_buff_e[i]; + IF( Cy_diag_e < Cy_diag_buff_e[i] ) + Cy_diag_e = Cy_diag_buff_e[i]; } - FOR (i = 0; i < nY_band; i++) + FOR( i = 0; i < nY_band; i++ ) { - Cy_diag_fx[i] = L_shr(Cy_diag_fx[i], Cy_diag_e - Cy_diag_buff_e[i]); + Cy_diag_fx[i] = L_shr( Cy_diag_fx[i], Cy_diag_e - Cy_diag_buff_e[i] ); } diag_matrix_product_fx( Cy_diag_fx, Cy_diag_e, nY_band, proto_matrix_ptr_fx, proto_matrix_ptr_e, nY_band, nX, 0, mixing_matrix_local_fx, &mixing_matrix_local_e ); } - IF ( remove_lfe ) + IF( remove_lfe ) { - set_zero_fx(mixing_matrix_fx[param_band_idx], nX * nY_cov); + set_zero_fx( mixing_matrix_fx[param_band_idx], nX * nY_cov ); ptrMM_fx = mixing_matrix_local_fx; ptrMM_out_fx = mixing_matrix_fx[param_band_idx]; - FOR (ch_idx1 = 0; ch_idx1 < nX; ch_idx1++) + FOR( ch_idx1 = 0; ch_idx1 < nX; ch_idx1++ ) { - FOR (lfe_idx1 = 0; lfe_idx1 < hSynthesisOutputSetup->num_lfe + 1; lfe_idx1++) + FOR( lfe_idx1 = 0; lfe_idx1 < hSynthesisOutputSetup->num_lfe + 1; lfe_idx1++ ) { - FOR (ch_idx2 = lfe_indices[lfe_idx1] + 1; ch_idx2 < lfe_indices[lfe_idx1 + 1]; ch_idx2++) + FOR( ch_idx2 = lfe_indices[lfe_idx1] + 1; ch_idx2 < lfe_indices[lfe_idx1 + 1]; ch_idx2++ ) { - *(ptrMM_out_fx++) = *(ptrMM_fx++); + *( ptrMM_out_fx++ ) = *( ptrMM_fx++ ); } ptrMM_out_fx++; } @@ -5650,16 +5650,16 @@ static void param_mc_update_mixing_matrices( #else static void param_mc_update_mixing_matrices_fx( PARAM_MC_DEC_HANDLE hParamMC, /* i/o: Parametric MC handle */ - Word32 *mixing_matrix[], /* i : direct mixing matrices for the frame just processed */ + Word32 *mixing_matrix[], /* i : direct mixing matrices for the frame just processed */ Word16 *mixing_matrix_exp, - Word32 *mixing_matrix_res[], /* i : residual mixing matrices for the frame just processed */ + Word32 *mixing_matrix_res[], /* i : residual mixing matrices for the frame just processed */ Word16 *mixing_matrix_res_exp, - const UWord16 nX, /* i : number of transport channels */ - const UWord16 nY ) /* i : number of synthesis channels */ + const UWord16 nX, /* i : number of transport channels */ + const UWord16 nY ) /* i : number of synthesis channels */ { UWord16 param_band_idx; - FOR ( param_band_idx = 0; param_band_idx < hParamMC->hMetadataPMC->nbands_coded; param_band_idx++ ) + FOR( param_band_idx = 0; param_band_idx < hParamMC->hMetadataPMC->nbands_coded; param_band_idx++ ) { Word16 brange[2]; @@ -5669,7 +5669,7 @@ static void param_mc_update_mixing_matrices_fx( Copy32( mixing_matrix[param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_fx[param_band_idx], nX * nY ); hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_exp[param_band_idx] = mixing_matrix_exp[param_band_idx]; - IF ( brange[0] < hParamMC->h_output_synthesis_params.max_band_decorr ) + IF( brange[0] < hParamMC->h_output_synthesis_params.max_band_decorr ) { Copy32( mixing_matrix_res[param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_fx[param_band_idx], nY * nY ); hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_exp[param_band_idx] = mixing_matrix_res_exp[param_band_idx]; @@ -5734,7 +5734,7 @@ static void ivas_param_mc_dequantize_cov( } Nrqq[h_ild_mapping->ild_index[k]] = powf( 10.0f, ild_q[k] / 10.0f ) * hParamMC->hMetadataPMC->ild_factors[k] * ref_ener; } - //dbgwrite2_txt(Nrqq,size,"../nrqq.txt"); + // dbgwrite2_txt(Nrqq,size,"../nrqq.txt"); /* estimate ICCs from estimated Cproto */ for ( k = 0; k < nY_int; k++ ) @@ -5939,7 +5939,7 @@ static void ivas_param_mc_dequantize_cov_fx( tmp_e = Cp_buf_e[k + nY_int * k]; move16(); - IF( NE_32(Cproto_fx[k + nY_int * k] , 0) ) + IF( NE_32( Cproto_fx[k + nY_int * k], 0 ) ) { L_tmp = ISqrt32( Cproto_fx[k + nY_int * k], &tmp_e ); } @@ -6011,7 +6011,7 @@ static void ivas_param_mc_dequantize_cov_fx( test(); test(); - IF( GE_16(param_band_index , PARAM_MC_MAX_BAND_LFE) || EQ_16(hParamMC->hMetadataPMC->lfe_on,0) ) + IF( GE_16( param_band_index, PARAM_MC_MAX_BAND_LFE ) || EQ_16( hParamMC->hMetadataPMC->lfe_on, 0 ) ) { FOR( k = 0; k < nY_int; k++ ) { @@ -6290,8 +6290,8 @@ static void param_mc_set_num_synth_bands( #ifdef IVAS_FLOAT_FIXED static ivas_error param_mc_get_diff_proto_info_fx( const Word32 *proto_mtx, /* i : protoype matrix for the synthesis */ - const UWord16 nchan_transport, /* i : number of transport channels */ - const UWord16 nchan_out_cov, /* i : number if output channels of the covariance synthesis */ + const UWord16 nchan_transport, /* i : number of transport channels */ + const UWord16 nchan_out_cov, /* i : number if output channels of the covariance synthesis */ PARAM_MC_DIFF_PROTO_INFO *p_diff_proto_info, /* o : generated diffuse prototype info */ Word16 Q_proto_mtx ) { @@ -6340,7 +6340,7 @@ static ivas_error param_mc_get_diff_proto_info_fx( #if FLT_ENABLE float diff = 0; float *proto_fac_ptr = proto_fac + cur_diff_proto; - //const float *proto_mtx_ptr = proto_mtx + cur_out_ch; + // const float *proto_mtx_ptr = proto_mtx + cur_out_ch; #endif Word32 diff_fx = 0; Word32 *proto_fac_ptr_fx = proto_fac_fx + cur_diff_proto; @@ -6361,7 +6361,7 @@ static ivas_error param_mc_get_diff_proto_info_fx( #if FLT_ENABLE if ( diff < 0.1f ) #else - if ( LT_64( diff_fx * 10, L_shl_sat(1, Q_proto_mtx)) ) + if ( LT_64( diff_fx * 10, L_shl_sat( 1, Q_proto_mtx ) ) ) #endif { found = 1; @@ -6406,7 +6406,7 @@ static ivas_error param_mc_get_diff_proto_info_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); } -#if 1/*To be removed later*/ +#if 1 /*To be removed later*/ if ( ( p_diff_proto_info->proto_fac = (float **) malloc( p_diff_proto_info->num_protos_diff * sizeof( float * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); @@ -6427,7 +6427,7 @@ static ivas_error param_mc_get_diff_proto_info_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); } -#if 1/*To be removed later*/ +#if 1 /*To be removed later*/ if ( ( p_diff_proto_info->proto_fac[cur_diff_proto] = (float *) malloc( max_num_src_chan * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); @@ -6550,14 +6550,14 @@ static ivas_error param_mc_get_diff_proto_info( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); } #ifdef IVAS_FLOAT_FIXED - IF ((p_diff_proto_info->proto_fac_fx = (Word32 **)malloc(p_diff_proto_info->num_protos_diff * sizeof(Word32 *))) == NULL) + IF( ( p_diff_proto_info->proto_fac_fx = (Word32 **) malloc( p_diff_proto_info->num_protos_diff * sizeof( Word32 * ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); } #endif #ifdef IVAS_FLOAT_FIXED - if ( ( p_diff_proto_info->proto_fac_fx = (Word32 **) malloc( p_diff_proto_info->num_protos_diff * sizeof(Word32 * ) ) ) == NULL ) + if ( ( p_diff_proto_info->proto_fac_fx = (Word32 **) malloc( p_diff_proto_info->num_protos_diff * sizeof( Word32 * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); } @@ -6575,16 +6575,16 @@ static ivas_error param_mc_get_diff_proto_info( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); } #ifdef IVAS_FLOAT_FIXED - if ( ( p_diff_proto_info->proto_fac_fx[cur_diff_proto] = (Word32 *) malloc( max_num_src_chan * sizeof(Word32) ) ) == NULL ) + if ( ( p_diff_proto_info->proto_fac_fx[cur_diff_proto] = (Word32 *) malloc( max_num_src_chan * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); } #endif // IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED - IF ((p_diff_proto_info->proto_fac_fx[cur_diff_proto] = (Word32 *)malloc(max_num_src_chan * sizeof(Word32))) == NULL) + IF( ( p_diff_proto_info->proto_fac_fx[cur_diff_proto] = (Word32 *) malloc( max_num_src_chan * sizeof( Word32 ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); } #endif diff --git a/lib_dec/ivas_mc_param_dec_fx.c b/lib_dec/ivas_mc_param_dec_fx.c index 18c338bb7..f3faac41b 100644 --- a/lib_dec/ivas_mc_param_dec_fx.c +++ b/lib_dec/ivas_mc_param_dec_fx.c @@ -30,4 +30,4 @@ Word16 param_mc_get_num_cldfb_syntheses_ivas_fx( return num_cldfb_syntheses; } -#endif // IVAS_FLOAT_FIXED \ No newline at end of file +#endif // IVAS_FLOAT_FIXED diff --git a/lib_dec/ivas_mc_paramupmix_dec.c b/lib_dec/ivas_mc_paramupmix_dec.c index acd53db47..dec62f973 100644 --- a/lib_dec/ivas_mc_paramupmix_dec.c +++ b/lib_dec/ivas_mc_paramupmix_dec.c @@ -64,11 +64,9 @@ const int16_t MC_PARAMUPMIX_CHIDX2[MC_PARAMUPMIX_COMBINATIONS] = { 2, 3, 6, 7 }; * Local function prototypes *-----------------------------------------------------------------------*/ -static void ps_pred_process_sf( MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix, DECODER_TC_BUFFER_HANDLE hTcBuffer, - Word32 qmf_mod_re_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], Word32 qmf_mod_im_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], Word32 qmf_side_re_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], Word32 qmf_side_im_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], - Word16 *param_interpol_fx, const int16_t ch, const int16_t slots_rendered ); +static void ps_pred_process_sf( MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix, DECODER_TC_BUFFER_HANDLE hTcBuffer, Word32 qmf_mod_re_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], Word32 qmf_mod_im_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], Word32 qmf_side_re_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], Word32 qmf_side_im_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], Word16 *param_interpol_fx, const int16_t ch, const int16_t slots_rendered ); -static void ivas_mc_paramupmix_dec_sf( Decoder_Struct *st_ivas, Word32 *output_fx[MAX_OUTPUT_CHANNELS]); +static void ivas_mc_paramupmix_dec_sf( Decoder_Struct *st_ivas, Word32 *output_fx[MAX_OUTPUT_CHANNELS] ); static void ivas_param_upmix_dec_decorr_subframes( Decoder_Struct *st_ivas, const int16_t nSamplesForRendering ); @@ -76,11 +74,11 @@ static int16_t huff_read( Decoder_State *st, const int16_t ( *ht )[2] ); static void huffman_decode( Decoder_State *st, const PAR_TYPE parType, Word32 *vq ); -static void dequant_alpha(Word32 *vq, Word32 *v); +static void dequant_alpha( Word32 *vq, Word32 *v ); -static void dequant_beta(Word32 *aq, Word32 *bq, Word32 *beta); +static void dequant_beta( Word32 *aq, Word32 *bq, Word32 *beta ); -static void get_ec_data(Decoder_State *st, const PAR_TYPE parType, Word32 *parQ, Word32 *alphaQEnv, Word32 ab[IVAS_MAX_NUM_BANDS]); +static void get_ec_data( Decoder_State *st, const PAR_TYPE parType, Word32 *parQ, Word32 *alphaQEnv, Word32 ab[IVAS_MAX_NUM_BANDS] ); /*------------------------------------------------------------------------- @@ -90,74 +88,73 @@ static void get_ec_data(Decoder_State *st, const PAR_TYPE parType, Word32 *parQ, *------------------------------------------------------------------------*/ void ivas_mc_paramupmix_dec_read_BS( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - Decoder_State *st0, /* i/o: decoder state structure */ - MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix, /* i/o: decoder MC Param-Upmix handle */ - Word16 *nb_bits /* o : number of bits written */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Decoder_State *st0, /* i/o: decoder state structure */ + MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix, /* i/o: decoder MC Param-Upmix handle */ + Word16 *nb_bits /* o : number of bits written */ ) { - Word16 i, k; - Word32 alpha_quant[IVAS_MAX_NUM_BANDS]; - Word16 nb_bits_read_orig; - Word16 next_bit_pos_orig, last_bit_pos; - UWord16 bstr_meta[MAX_BITS_METADATA], *bit_stream_orig; + Word16 i, k; + Word32 alpha_quant[IVAS_MAX_NUM_BANDS]; + Word16 nb_bits_read_orig; + Word16 next_bit_pos_orig, last_bit_pos; + UWord16 bstr_meta[MAX_BITS_METADATA], *bit_stream_orig; - push_wmops("mc_paramupmix_read_bs"); - *nb_bits = 0; + push_wmops( "mc_paramupmix_read_bs" ); + *nb_bits = 0; - IF(st0->bfi) - { - FOR(i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++) + IF( st0->bfi ) { - FOR(k = 0; k < IVAS_MAX_NUM_BANDS; k++) - { - hMCParamUpmix->alphas_fx[i][k] = hMCParamUpmix->alpha_prev_fx[i][k]; - hMCParamUpmix->betas_fx[i][k] = hMCParamUpmix->beta_prev_fx[i][k]; - } + FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ ) + { + FOR( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) + { + hMCParamUpmix->alphas_fx[i][k] = hMCParamUpmix->alpha_prev_fx[i][k]; + hMCParamUpmix->betas_fx[i][k] = hMCParamUpmix->beta_prev_fx[i][k]; + } + } + hMCParamUpmix->first_frame = 1; + } + ELSE /* IF (!st->bfi) */ + { + bit_stream_orig = st0->bit_stream; + next_bit_pos_orig = st0->next_bit_pos; + last_bit_pos = (Word16) L_sub( ( st_ivas->hDecoderConfig->ivas_total_brate / FRAMES_PER_SEC ), 1 ); + nb_bits_read_orig = 0; + last_bit_pos = sub( last_bit_pos, nb_bits_read_orig ); /* reverse the bitstream for easier reading of indices */ + FOR( i = 0; i < s_min( MAX_BITS_METADATA, last_bit_pos ); i++ ) + { + bstr_meta[i] = st_ivas->bit_stream[sub( last_bit_pos, i )]; + } + st0->bit_stream = bstr_meta; + st0->next_bit_pos = 0; + st0->bits_frame = s_min( MAX_BITS_METADATA, add( last_bit_pos, 1 ) ); + st0->total_brate = st_ivas->hDecoderConfig->ivas_total_brate; /* to avoid BER detect */ + + FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ ) + { + get_ec_data( st0, ALPHA, hMCParamUpmix->alpha_quant[i], alpha_quant, hMCParamUpmix->alphas_fx[i] ); + + get_ec_data( st0, BETA, hMCParamUpmix->beta_quant[i], alpha_quant, hMCParamUpmix->betas_fx[i] ); + } + *nb_bits = add( *nb_bits, st0->next_bit_pos ); + st0->bit_stream = bit_stream_orig; + st0->next_bit_pos = next_bit_pos_orig; + + IF( hMCParamUpmix->first_frame ) + { + FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ ) + { + Copy32( hMCParamUpmix->alphas_fx[i], hMCParamUpmix->alpha_prev_fx[i], IVAS_MAX_NUM_BANDS ); + Copy32( hMCParamUpmix->betas_fx[i], hMCParamUpmix->beta_prev_fx[i], IVAS_MAX_NUM_BANDS ); + } + hMCParamUpmix->first_frame = 0; + } } - hMCParamUpmix->first_frame = 1; - } - ELSE /* IF (!st->bfi) */ - { - bit_stream_orig = st0->bit_stream; - next_bit_pos_orig = st0->next_bit_pos; - last_bit_pos = (Word16)L_sub((st_ivas->hDecoderConfig->ivas_total_brate / FRAMES_PER_SEC), 1); - nb_bits_read_orig = 0; - last_bit_pos = sub(last_bit_pos, nb_bits_read_orig); /* reverse the bitstream for easier reading of indices */ - FOR(i = 0; i < s_min(MAX_BITS_METADATA, last_bit_pos); i++) - { - bstr_meta[i] = st_ivas->bit_stream[sub(last_bit_pos, i)]; - } - st0->bit_stream = bstr_meta; - st0->next_bit_pos = 0; - st0->bits_frame = s_min(MAX_BITS_METADATA, add(last_bit_pos, 1)); - st0->total_brate = st_ivas->hDecoderConfig->ivas_total_brate; /* to avoid BER detect */ - - FOR(i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++) - { - get_ec_data(st0, ALPHA, hMCParamUpmix->alpha_quant[i], alpha_quant, hMCParamUpmix->alphas_fx[i]); - - get_ec_data(st0, BETA, hMCParamUpmix->beta_quant[i], alpha_quant, hMCParamUpmix->betas_fx[i]); - } - *nb_bits = add(*nb_bits, st0->next_bit_pos); - st0->bit_stream = bit_stream_orig; - st0->next_bit_pos = next_bit_pos_orig; - - IF(hMCParamUpmix->first_frame) - { - FOR(i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++) - { - Copy32(hMCParamUpmix->alphas_fx[i], hMCParamUpmix->alpha_prev_fx[i], IVAS_MAX_NUM_BANDS); - Copy32(hMCParamUpmix->betas_fx[i], hMCParamUpmix->beta_prev_fx[i], IVAS_MAX_NUM_BANDS); - } - hMCParamUpmix->first_frame = 0; - } - } - - pop_wmops(); - return; -} + pop_wmops(); + return; +} /*------------------------------------------------------------------------- @@ -167,7 +164,7 @@ void ivas_mc_paramupmix_dec_read_BS( *------------------------------------------------------------------------*/ void ivas_mc_paramupmix_dec_digest_tc( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ const UWord8 nCldfbSlots, /* i : number of CLFBS slots in the transport channels*/ const Word16 nSamplesForRendering /* i : number of samples provided */ ) @@ -200,8 +197,8 @@ void ivas_mc_paramupmix_dec_render( const uint16_t nSamplesAsked, /* i : number of CLDFB slots requested */ uint16_t *nSamplesRendered, /* o : number of CLDFB slots rendered */ uint16_t *nSamplesAvailable, /* o : number of CLDFB slots still to render */ - Word32 *input_fx[], /* i : core-coder transport channels */ - Word32 *output_fx[] /* i/o: synthesized core-coder transport channels */ + Word32 *input_fx[], /* i : core-coder transport channels */ + Word32 *output_fx[] /* i/o: synthesized core-coder transport channels */ ) { int16_t slots_to_render, first_sf, last_sf, subframe_idx; @@ -241,8 +238,8 @@ void ivas_mc_paramupmix_dec_render( for ( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS; ch++ ) { - Copy32(hMCParamUpmix->alpha_prev_fx[ch], hMCParamUpmix->alpha_sf_fx[ch], IVAS_MAX_NUM_BANDS); - Copy32(hMCParamUpmix->beta_prev_fx[ch], hMCParamUpmix->beta_sf_fx[ch], IVAS_MAX_NUM_BANDS); + Copy32( hMCParamUpmix->alpha_prev_fx[ch], hMCParamUpmix->alpha_sf_fx[ch], IVAS_MAX_NUM_BANDS ); + Copy32( hMCParamUpmix->beta_prev_fx[ch], hMCParamUpmix->beta_sf_fx[ch], IVAS_MAX_NUM_BANDS ); } for ( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ ) @@ -261,8 +258,8 @@ void ivas_mc_paramupmix_dec_render( } for ( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS; ch++ ) { - Copy32(hMCParamUpmix->alphas_fx[ch], hMCParamUpmix->alpha_prev_fx[ch], IVAS_MAX_NUM_BANDS); - Copy32(hMCParamUpmix->betas_fx[ch], hMCParamUpmix->beta_prev_fx[ch], IVAS_MAX_NUM_BANDS); + Copy32( hMCParamUpmix->alphas_fx[ch], hMCParamUpmix->alpha_prev_fx[ch], IVAS_MAX_NUM_BANDS ); + Copy32( hMCParamUpmix->betas_fx[ch], hMCParamUpmix->beta_prev_fx[ch], IVAS_MAX_NUM_BANDS ); } } @@ -346,18 +343,18 @@ ivas_error ivas_mc_paramupmix_dec_open( } compute_hoa_encoder_mtx_fx( st_ivas->hTransSetup.ls_azimuth_fx, st_ivas->hTransSetup.ls_elevation_fx, hMCParamUpmix->hoa_encoder_fx, st_ivas->hTransSetup.nchan_out_woLFE, HEAD_ROTATION_HOA_ORDER ); // compute_hoa_encoder_mtx( st_ivas->hTransSetup.ls_azimuth, st_ivas->hTransSetup.ls_elevation, hMCParamUpmix->hoa_encoder, st_ivas->hTransSetup.nchan_out_woLFE, HEAD_ROTATION_HOA_ORDER ); - Scale_sig32(hMCParamUpmix->hoa_encoder_fx, st_ivas->hTransSetup.nchan_out_woLFE*MAX_INTERN_CHANNELS, Q2);//Q29=>Q31 + Scale_sig32( hMCParamUpmix->hoa_encoder_fx, st_ivas->hTransSetup.nchan_out_woLFE * MAX_INTERN_CHANNELS, Q2 ); // Q29=>Q31 } /* allocate transport channels*/ hMCParamUpmix->free_param_interpolator = 0; - IF((hMCParamUpmix->param_interpolator_fx = (Word16 *)malloc(MAX_JBM_CLDFB_TIMESLOTS * sizeof(Word16))) == NULL) + IF( ( hMCParamUpmix->param_interpolator_fx = (Word16 *) malloc( MAX_JBM_CLDFB_TIMESLOTS * sizeof( Word16 ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for interpolator\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for interpolator\n" ) ); } hMCParamUpmix->free_param_interpolator = 1; - + ivas_jbm_dec_get_adapted_linear_interpolator_fx( DEFAULT_JBM_CLDFB_TIMESLOTS, DEFAULT_JBM_CLDFB_TIMESLOTS, hMCParamUpmix->param_interpolator_fx ); if ( st_ivas->hTcBuffer == NULL ) @@ -419,17 +416,17 @@ void ivas_mc_paramupmix_dec_close( free( ( *hMCParamUpmix )->pcm_delay_fx[i] ); } } - if ((*hMCParamUpmix)->param_interpolator_fx != NULL) + if ( ( *hMCParamUpmix )->param_interpolator_fx != NULL ) { - if ((*hMCParamUpmix)->free_param_interpolator == 1) - { - free((*hMCParamUpmix)->param_interpolator_fx); - } + if ( ( *hMCParamUpmix )->free_param_interpolator == 1 ) + { + free( ( *hMCParamUpmix )->param_interpolator_fx ); + } } - if ((*hMCParamUpmix)->hoa_encoder_fx != NULL) + if ( ( *hMCParamUpmix )->hoa_encoder_fx != NULL ) { - free((*hMCParamUpmix)->hoa_encoder_fx); - (*hMCParamUpmix)->hoa_encoder_fx = NULL; + free( ( *hMCParamUpmix )->hoa_encoder_fx ); + ( *hMCParamUpmix )->hoa_encoder_fx = NULL; } free( *hMCParamUpmix ); @@ -531,7 +528,7 @@ static void ivas_param_upmix_dec_decorr_subframes( int16_t nSamplesToDecorr = min( nSamplesLeftForTD, default_frame ); { - Word32 i, q_format[MC_PARAMUPMIX_COMBINATIONS]; + Word32 i, q_format[MC_PARAMUPMIX_COMBINATIONS]; FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ ) { @@ -542,7 +539,7 @@ static void ivas_param_upmix_dec_decorr_subframes( FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ ) { - Scale_sig32(pPcm_tmp_fx[i], nSamplesToDecorr, Q11- extract_l(q_format[i])); + Scale_sig32( pPcm_tmp_fx[i], nSamplesToDecorr, Q11 - extract_l( q_format[i] ) ); } } for ( ch = 0; ch < nchan_internal; ch++ ) @@ -569,7 +566,7 @@ static void ps_pred_process_sf( Word32 qmf_mod_im_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], Word32 qmf_side_re_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* in/out */ Word32 qmf_side_im_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], - Word16 *param_interpol_fx, + Word16 *param_interpol_fx, const int16_t ch, const int16_t slots_rendered ) { @@ -595,8 +592,8 @@ static void ps_pred_process_sf( 11, 11, 11, 11, 11, 11, 11, 11, 11, 11 }; - Copy32(alpha_sf_fx, alpha_start_fx, IVAS_MAX_NUM_BANDS); - Copy32(beta_sf_fx, beta_start_fx, IVAS_MAX_NUM_BANDS); + Copy32( alpha_sf_fx, alpha_start_fx, IVAS_MAX_NUM_BANDS ); + Copy32( beta_sf_fx, beta_start_fx, IVAS_MAX_NUM_BANDS ); for ( iqmf = 0; iqmf < CLDFB_NO_CHANNELS_MAX; iqmf++ ) { ipar = qmf_to_par_band[iqmf]; @@ -617,26 +614,26 @@ static void ps_pred_process_sf( } else { - ifac_fx = sub(param_interpol_fx[iismp], param_interpol_fx[iismp - 1]); + ifac_fx = sub( param_interpol_fx[iismp], param_interpol_fx[iismp - 1] ); } - dalpha_fx = Mpy_32_16_1(L_sub( alpha2_fx[ipar], alpha1_fx[ipar] ), ifac_fx); - dbeta_fx = Mpy_32_16_1(L_sub( beta2_fx[ipar], beta1_fx[ipar] ), ifac_fx); + dalpha_fx = Mpy_32_16_1( L_sub( alpha2_fx[ipar], alpha1_fx[ipar] ), ifac_fx ); + dbeta_fx = Mpy_32_16_1( L_sub( beta2_fx[ipar], beta1_fx[ipar] ), ifac_fx ); - alpha_smp_fx = L_add(alpha_smp_fx, dalpha_fx); - beta_smp_fx = L_add(dbeta_fx, beta_smp_fx); + alpha_smp_fx = L_add( alpha_smp_fx, dalpha_fx ); + beta_smp_fx = L_add( dbeta_fx, beta_smp_fx ); vmre_fx = qmf_mod_re_fx[ismp][iqmf]; vmim_fx = qmf_mod_im_fx[ismp][iqmf]; vsre_fx = qmf_side_re_fx[ismp][iqmf]; vsim_fx = qmf_side_im_fx[ismp][iqmf]; - res_a = L_shl_sat(Mpy_32_32(alpha_smp_fx, vmre_fx), Q31 - Q28); - res_b = L_shl_sat(Mpy_32_32(beta_smp_fx, vsre_fx), Q31 - Q28); - qmf_side_re_fx[ismp][iqmf] = L_add_sat(res_a, res_b); + res_a = L_shl_sat( Mpy_32_32( alpha_smp_fx, vmre_fx ), Q31 - Q28 ); + res_b = L_shl_sat( Mpy_32_32( beta_smp_fx, vsre_fx ), Q31 - Q28 ); + qmf_side_re_fx[ismp][iqmf] = L_add_sat( res_a, res_b ); - res_a = L_shl_sat(Mpy_32_32(alpha_smp_fx, vmim_fx), Q31 - Q28); - res_b = L_shl_sat(Mpy_32_32(beta_smp_fx, vsim_fx), Q31 - Q28); - qmf_side_re_fx[ismp][iqmf] = L_add_sat(res_a, res_b); + res_a = L_shl_sat( Mpy_32_32( alpha_smp_fx, vmim_fx ), Q31 - Q28 ); + res_b = L_shl_sat( Mpy_32_32( beta_smp_fx, vsim_fx ), Q31 - Q28 ); + qmf_side_re_fx[ismp][iqmf] = L_add_sat( res_a, res_b ); ismp++; } @@ -649,7 +646,7 @@ static void ps_pred_process_sf( static void ivas_mc_paramupmix_dec_sf( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ Word32 *output_fx[MAX_OUTPUT_CHANNELS] /* i/o: synthesized core-coder transport channels */ ) { @@ -689,7 +686,7 @@ static void ivas_mc_paramupmix_dec_sf( for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ ) { Word16 q_cldfb = 11; - cldfbAnalysis_ts_fx_fixed_q( &( pPcm_temp_fx[ch][hMCParamUpmix->num_freq_bands * slot_idx] ), Cldfb_RealBuffer_fx[ch][slot_idx], Cldfb_ImagBuffer_fx[ch][slot_idx], hMCParamUpmix->num_freq_bands, st_ivas->cldfbAnaDec[ch], &q_cldfb); + cldfbAnalysis_ts_fx_fixed_q( &( pPcm_temp_fx[ch][hMCParamUpmix->num_freq_bands * slot_idx] ), Cldfb_RealBuffer_fx[ch][slot_idx], Cldfb_ImagBuffer_fx[ch][slot_idx], hMCParamUpmix->num_freq_bands, st_ivas->cldfbAnaDec[ch], &q_cldfb ); } } @@ -715,10 +712,10 @@ static void ivas_mc_paramupmix_dec_sf( Word32 qrre_fx = Cldfb_RealBuffer_fx[2 * ch + 1][slot_idx][k]; Word32 qrim_fx = Cldfb_ImagBuffer_fx[2 * ch + 1][slot_idx][k]; - Cldfb_RealBuffer_fx[2 * ch][slot_idx][k] = L_add_sat(qlre_fx, qrre_fx); - Cldfb_ImagBuffer_fx[2 * ch][slot_idx][k] = L_add_sat(qlim_fx, qrim_fx); - Cldfb_RealBuffer_fx[2 * ch + 1][slot_idx][k] = L_sub_sat(qlre_fx, qrre_fx); - Cldfb_ImagBuffer_fx[2 * ch + 1][slot_idx][k] = L_sub_sat(qlim_fx, qrim_fx); + Cldfb_RealBuffer_fx[2 * ch][slot_idx][k] = L_add_sat( qlre_fx, qrre_fx ); + Cldfb_ImagBuffer_fx[2 * ch][slot_idx][k] = L_add_sat( qlim_fx, qrim_fx ); + Cldfb_RealBuffer_fx[2 * ch + 1][slot_idx][k] = L_sub_sat( qlre_fx, qrre_fx ); + Cldfb_ImagBuffer_fx[2 * ch + 1][slot_idx][k] = L_sub_sat( qlim_fx, qrim_fx ); } } } @@ -740,10 +737,10 @@ static void ivas_mc_paramupmix_dec_sf( { Word16 q_cldfb = 11; - cldfbAnalysis_ts_fx_fixed_q(&(pPcm_temp_fx[ch][hMCParamUpmix->num_freq_bands * slot_idx]), - Cldfb_RealBuffer_subfr_fx[idx_in][slot_idx], - Cldfb_ImagBuffer_subfr_fx[idx_in][slot_idx], - maxBand, st_ivas->cldfbAnaDec[2 * MC_PARAMUPMIX_COMBINATIONS + idx_in],&q_cldfb); + cldfbAnalysis_ts_fx_fixed_q( &( pPcm_temp_fx[ch][hMCParamUpmix->num_freq_bands * slot_idx] ), + Cldfb_RealBuffer_subfr_fx[idx_in][slot_idx], + Cldfb_ImagBuffer_subfr_fx[idx_in][slot_idx], + maxBand, st_ivas->cldfbAnaDec[2 * MC_PARAMUPMIX_COMBINATIONS + idx_in], &q_cldfb ); } idx_in++; } @@ -755,10 +752,10 @@ static void ivas_mc_paramupmix_dec_sf( { for ( slot_idx = 0; slot_idx < MAX_PARAM_SPATIAL_SUBFRAMES; slot_idx++ ) { - Copy32(Cldfb_RealBuffer_fx[MC_PARAMUPMIX_CHIDX1[ch]][slot_idx], Cldfb_RealBuffer_subfr_fx[idx_in][slot_idx], CLDFB_NO_CHANNELS_MAX); - Copy32(Cldfb_ImagBuffer_fx[MC_PARAMUPMIX_CHIDX1[ch]][slot_idx], Cldfb_ImagBuffer_subfr_fx[idx_in][slot_idx], CLDFB_NO_CHANNELS_MAX); - Copy32(Cldfb_RealBuffer_fx[MC_PARAMUPMIX_CHIDX2[ch]][slot_idx], Cldfb_RealBuffer_subfr_fx[idx_in + 1][slot_idx], CLDFB_NO_CHANNELS_MAX); - Copy32(Cldfb_ImagBuffer_fx[MC_PARAMUPMIX_CHIDX2[ch]][slot_idx], Cldfb_ImagBuffer_subfr_fx[idx_in + 1][slot_idx], CLDFB_NO_CHANNELS_MAX); + Copy32( Cldfb_RealBuffer_fx[MC_PARAMUPMIX_CHIDX1[ch]][slot_idx], Cldfb_RealBuffer_subfr_fx[idx_in][slot_idx], CLDFB_NO_CHANNELS_MAX ); + Copy32( Cldfb_ImagBuffer_fx[MC_PARAMUPMIX_CHIDX1[ch]][slot_idx], Cldfb_ImagBuffer_subfr_fx[idx_in][slot_idx], CLDFB_NO_CHANNELS_MAX ); + Copy32( Cldfb_RealBuffer_fx[MC_PARAMUPMIX_CHIDX2[ch]][slot_idx], Cldfb_RealBuffer_subfr_fx[idx_in + 1][slot_idx], CLDFB_NO_CHANNELS_MAX ); + Copy32( Cldfb_ImagBuffer_fx[MC_PARAMUPMIX_CHIDX2[ch]][slot_idx], Cldfb_ImagBuffer_subfr_fx[idx_in + 1][slot_idx], CLDFB_NO_CHANNELS_MAX ); } idx_in += 2; } @@ -767,7 +764,7 @@ static void ivas_mc_paramupmix_dec_sf( { for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ ) { - ivas_param_mc_mc2sba_cldfb_fx( st_ivas->hTransSetup, hMCParamUpmix->hoa_encoder_fx, slot_idx, Cldfb_RealBuffer_subfr_fx, Cldfb_ImagBuffer_subfr_fx, maxBand, GAIN_LFE_FX); + ivas_param_mc_mc2sba_cldfb_fx( st_ivas->hTransSetup, hMCParamUpmix->hoa_encoder_fx, slot_idx, Cldfb_RealBuffer_subfr_fx, Cldfb_ImagBuffer_subfr_fx, maxBand, GAIN_LFE_FX ); } } @@ -775,20 +772,20 @@ static void ivas_mc_paramupmix_dec_sf( Word16 input_q = 6; /* Implement binaural rendering */ - ivas_binRenderer_fx(st_ivas->hBinRenderer, - st_ivas->hCombinedOrientationData, - st_ivas->hTcBuffer->subframe_nbslots[subframeIdx], - Cldfb_RealBuffer_Binaural_fx, Cldfb_ImagBuffer_Binaural_fx, - Cldfb_RealBuffer_subfr_fx, - Cldfb_ImagBuffer_subfr_fx,&input_q); - - for (int idx1 = 0; idx1 < BINAURAL_CHANNELS; idx1++) + ivas_binRenderer_fx( st_ivas->hBinRenderer, + st_ivas->hCombinedOrientationData, + st_ivas->hTcBuffer->subframe_nbslots[subframeIdx], + Cldfb_RealBuffer_Binaural_fx, Cldfb_ImagBuffer_Binaural_fx, + Cldfb_RealBuffer_subfr_fx, + Cldfb_ImagBuffer_subfr_fx, &input_q ); + + for ( int idx1 = 0; idx1 < BINAURAL_CHANNELS; idx1++ ) { - for (int idx2 = 0; idx2 < MAX_PARAM_SPATIAL_SUBFRAMES; idx2++) - { - Scale_sig32(Cldfb_RealBuffer_Binaural_fx[idx1][idx2], CLDFB_NO_CHANNELS_MAX, 6- input_q); - Scale_sig32(Cldfb_ImagBuffer_Binaural_fx[idx1][idx2], CLDFB_NO_CHANNELS_MAX, 6- input_q); - } + for ( int idx2 = 0; idx2 < MAX_PARAM_SPATIAL_SUBFRAMES; idx2++ ) + { + Scale_sig32( Cldfb_RealBuffer_Binaural_fx[idx1][idx2], CLDFB_NO_CHANNELS_MAX, 6 - input_q ); + Scale_sig32( Cldfb_ImagBuffer_Binaural_fx[idx1][idx2], CLDFB_NO_CHANNELS_MAX, 6 - input_q ); + } } /* Implement CLDFB synthesis */ for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) @@ -801,15 +798,15 @@ static void ivas_mc_paramupmix_dec_sf( RealBuffer_fx[slot_idx] = Cldfb_RealBuffer_Binaural_fx[ch][slot_idx]; ImagBuffer_fx[slot_idx] = Cldfb_ImagBuffer_Binaural_fx[ch][slot_idx]; } - scale_sig32(st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, sub(Q5, Q11) ); + scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, sub( Q5, Q11 ) ); st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q5; cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, &( output_fx[ch][0] ), maxBand * st_ivas->hTcBuffer->subframe_nbslots[subframeIdx], st_ivas->cldfbSynDec[ch] ); - scale_sig32(st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, sub(Q11, Q5) ); + scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, sub( Q11, Q5 ) ); st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q11; } - for (ch = 0; ch < BINAURAL_CHANNELS; ch++) + for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { - Scale_sig32(output_fx[ch], maxBand * st_ivas->hTcBuffer->subframe_nbslots[subframeIdx], 6); + Scale_sig32( output_fx[ch], maxBand * st_ivas->hTcBuffer->subframe_nbslots[subframeIdx], 6 ); } } else @@ -827,7 +824,7 @@ static void ivas_mc_paramupmix_dec_sf( /* CLDFB synthesis */ for ( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS * 2; ch++ ) { - scale_sig32(st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, sub(Q5, st_ivas->cldfbSynDec[ch]->Q_cldfb_state) ); + scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, sub( Q5, st_ivas->cldfbSynDec[ch]->Q_cldfb_state ) ); st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q5; for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ ) { @@ -836,16 +833,16 @@ static void ivas_mc_paramupmix_dec_sf( ptr_re_fx[0] = Cldfb_RealBuffer_fx[ch][slot_idx]; ptr_im_fx[0] = Cldfb_ImagBuffer_fx[ch][slot_idx]; - cldfbSynthesis_ivas_fx(ptr_re_fx, ptr_im_fx, &(pPcm_temp_fx[ch][hMCParamUpmix->num_freq_bands * slot_idx]), - hMCParamUpmix->num_freq_bands, st_ivas->cldfbSynDec[ch]); + cldfbSynthesis_ivas_fx( ptr_re_fx, ptr_im_fx, &( pPcm_temp_fx[ch][hMCParamUpmix->num_freq_bands * slot_idx] ), + hMCParamUpmix->num_freq_bands, st_ivas->cldfbSynDec[ch] ); } - scale_sig32(st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, sub(Q11, st_ivas->cldfbSynDec[ch]->Q_cldfb_state) ); + scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, sub( Q11, st_ivas->cldfbSynDec[ch]->Q_cldfb_state ) ); st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q11; } - //Done to keep entire buffer in q11 - for (ch = 4; ch < 12; ch++) + // Done to keep entire buffer in q11 + for ( ch = 4; ch < 12; ch++ ) { - Scale_sig32(output_fx[ch], hMCParamUpmix->num_freq_bands * st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered], 6); + Scale_sig32( output_fx[ch], hMCParamUpmix->num_freq_bands * st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered], 6 ); } /* adjust delay of other channels */ noparamupmix_delay = NS2SA( st_ivas->hDecoderConfig->output_Fs, IVAS_FB_DEC_DELAY_NS ); @@ -855,10 +852,10 @@ static void ivas_mc_paramupmix_dec_sf( for ( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS; ch++ ) { Word32 tmp_buf_fx[L_SUBFRAME5MS_48k]; - Copy32(&output_fx[ch][n_samples_rendered - noparamupmix_delay], tmp_buf_fx, noparamupmix_delay); - Copy32(output_fx[ch], &output_fx[ch][noparamupmix_delay], n_samples_rendered - noparamupmix_delay); - Copy32(hMCParamUpmix->pcm_delay_fx[ch], output_fx[ch], noparamupmix_delay); - Copy32(tmp_buf_fx, hMCParamUpmix->pcm_delay_fx[ch], noparamupmix_delay); + Copy32( &output_fx[ch][n_samples_rendered - noparamupmix_delay], tmp_buf_fx, noparamupmix_delay ); + Copy32( output_fx[ch], &output_fx[ch][noparamupmix_delay], n_samples_rendered - noparamupmix_delay ); + Copy32( hMCParamUpmix->pcm_delay_fx[ch], output_fx[ch], noparamupmix_delay ); + Copy32( tmp_buf_fx, hMCParamUpmix->pcm_delay_fx[ch], noparamupmix_delay ); } } else @@ -866,13 +863,12 @@ static void ivas_mc_paramupmix_dec_sf( for ( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS; ch++ ) { Word32 tmp_buf_fx[L_SUBFRAME5MS_48k]; - Copy32(&output_fx[ch][0], tmp_buf_fx, n_samples_rendered); - Copy32(hMCParamUpmix->pcm_delay_fx[ch], output_fx[ch], n_samples_rendered); - Copy32(&hMCParamUpmix->pcm_delay_fx[ch][n_samples_rendered], &hMCParamUpmix->pcm_delay_fx[ch][0], noparamupmix_delay - n_samples_rendered); - Copy32(tmp_buf_fx, &hMCParamUpmix->pcm_delay_fx[ch][noparamupmix_delay - n_samples_rendered], n_samples_rendered); + Copy32( &output_fx[ch][0], tmp_buf_fx, n_samples_rendered ); + Copy32( hMCParamUpmix->pcm_delay_fx[ch], output_fx[ch], n_samples_rendered ); + Copy32( &hMCParamUpmix->pcm_delay_fx[ch][n_samples_rendered], &hMCParamUpmix->pcm_delay_fx[ch][0], noparamupmix_delay - n_samples_rendered ); + Copy32( tmp_buf_fx, &hMCParamUpmix->pcm_delay_fx[ch][noparamupmix_delay - n_samples_rendered], n_samples_rendered ); } } - } st_ivas->hTcBuffer->slots_rendered += st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; @@ -884,137 +880,137 @@ static void ivas_mc_paramupmix_dec_sf( static Word16 huff_read( - Decoder_State *st, - const Word16(*ht)[2]) + Decoder_State *st, + const Word16 ( *ht )[2] ) { - Word16 node = 0; - UWord16 next_bit = 0; - - DO - { - next_bit = st->bit_stream[st->next_bit_pos]; - st->next_bit_pos++; - node = ht[node][next_bit]; - } - WHILE(GT_16(node, 0)); - - return negate(add(node, 1)); + Word16 node = 0; + UWord16 next_bit = 0; + + DO + { + next_bit = st->bit_stream[st->next_bit_pos]; + st->next_bit_pos++; + node = ht[node][next_bit]; + } + WHILE( GT_16( node, 0 ) ); + + return negate( add( node, 1 ) ); } static void huffman_decode( - Decoder_State *st, - const PAR_TYPE parType, - Word32 *vq) + Decoder_State *st, + const PAR_TYPE parType, + Word32 *vq ) { - const Word16(*huff_node_table)[2]; - Word16 iv, nquant, offset; + const Word16( *huff_node_table )[2]; + Word16 iv, nquant, offset; - nquant = 0; - SWITCH(parType) - { + nquant = 0; + SWITCH( parType ) + { case ALPHA: - nquant = ivas_mc_paramupmix_alpha_quant_table_fx.nquant; - BREAK; + nquant = ivas_mc_paramupmix_alpha_quant_table_fx.nquant; + BREAK; case BETA: - nquant = ivas_mc_paramupmix_beta_quant_table_fx[0].nquant; - BREAK; + nquant = ivas_mc_paramupmix_beta_quant_table_fx[0].nquant; + BREAK; default: - assert(0); - } + assert( 0 ); + } - offset = sub(nquant, 1); /* range of df [-(nquant - 1), nquant - 1] */ + offset = sub( nquant, 1 ); /* range of df [-(nquant - 1), nquant - 1] */ - st->next_bit_pos++; - SWITCH(parType) - { + st->next_bit_pos++; + SWITCH( parType ) + { case ALPHA: - huff_node_table = ivas_mc_paramupmix_huff_nodes_df0.alpha; - BREAK; + huff_node_table = ivas_mc_paramupmix_huff_nodes_df0.alpha; + BREAK; case BETA: - huff_node_table = ivas_mc_paramupmix_huff_nodes_df0.beta; - BREAK; + huff_node_table = ivas_mc_paramupmix_huff_nodes_df0.beta; + BREAK; default: - huff_node_table = NULL; - assert(0); - } - vq[0] = huff_read(st, huff_node_table); + huff_node_table = NULL; + assert( 0 ); + } + vq[0] = huff_read( st, huff_node_table ); - SWITCH(parType) - { + SWITCH( parType ) + { case ALPHA: - huff_node_table = ivas_mc_paramupmix_huff_nodes_df.alpha; - BREAK; + huff_node_table = ivas_mc_paramupmix_huff_nodes_df.alpha; + BREAK; case BETA: - huff_node_table = ivas_mc_paramupmix_huff_nodes_df.beta; - BREAK; + huff_node_table = ivas_mc_paramupmix_huff_nodes_df.beta; + BREAK; default: - assert(0); - } + assert( 0 ); + } - FOR(iv = 1; iv < IVAS_MAX_NUM_BANDS; iv++) - { - vq[iv] = L_sub(L_add(huff_read(st, huff_node_table), vq[sub(iv, 1)]), offset); - } + FOR( iv = 1; iv < IVAS_MAX_NUM_BANDS; iv++ ) + { + vq[iv] = L_sub( L_add( huff_read( st, huff_node_table ), vq[sub( iv, 1 )] ), offset ); + } - return; + return; } static void dequant_alpha( - Word32 *vq, - Word32 *v) + Word32 *vq, + Word32 *v ) { - Word16 iv; - const ACPL_QUANT_TABLE_FX *quant_table = &ivas_mc_paramupmix_alpha_quant_table_fx; + Word16 iv; + const ACPL_QUANT_TABLE_FX *quant_table = &ivas_mc_paramupmix_alpha_quant_table_fx; - FOR(iv = 0; iv < IVAS_MAX_NUM_BANDS; iv++) - { - v[iv] = quant_table->data[vq[iv]]; - } + FOR( iv = 0; iv < IVAS_MAX_NUM_BANDS; iv++ ) + { + v[iv] = quant_table->data[vq[iv]]; + } - return; + return; } static void dequant_beta( - Word32 *aq, - Word32 *bq, - Word32 *beta) + Word32 *aq, + Word32 *bq, + Word32 *beta ) { - Word16 iv; - const ACPL_QUANT_TABLE_FX *quant_table; + Word16 iv; + const ACPL_QUANT_TABLE_FX *quant_table; - FOR(iv = 0; iv < IVAS_MAX_NUM_BANDS; iv++) - { - quant_table = &ivas_mc_paramupmix_beta_quant_table_fx[ivas_param_upmx_mx_qmap[aq[iv]]]; - beta[iv] = quant_table->data[bq[iv]]; - } + FOR( iv = 0; iv < IVAS_MAX_NUM_BANDS; iv++ ) + { + quant_table = &ivas_mc_paramupmix_beta_quant_table_fx[ivas_param_upmx_mx_qmap[aq[iv]]]; + beta[iv] = quant_table->data[bq[iv]]; + } - return; + return; } static void get_ec_data( - Decoder_State *st, - const PAR_TYPE parType, - Word32 *parQ, - Word32 *alphaQEnv, - Word32 ab[IVAS_MAX_NUM_BANDS]) + Decoder_State *st, + const PAR_TYPE parType, + Word32 *parQ, + Word32 *alphaQEnv, + Word32 ab[IVAS_MAX_NUM_BANDS] ) { - huffman_decode(st, parType, parQ); - - IF(EQ_32(parType, ALPHA)) - { - dequant_alpha(parQ, ab); - mvl2l(parQ, alphaQEnv, (Word16)IVAS_MAX_NUM_BANDS); - } - ELSE - { - dequant_beta(alphaQEnv, parQ, ab); - } - - return; + huffman_decode( st, parType, parQ ); + + IF( EQ_32( parType, ALPHA ) ) + { + dequant_alpha( parQ, ab ); + mvl2l( parQ, alphaQEnv, (Word16) IVAS_MAX_NUM_BANDS ); + } + ELSE + { + dequant_beta( alphaQEnv, parQ, ab ); + } + + return; } #else @@ -1023,7 +1019,7 @@ static void get_ec_data( * Local arrays *-----------------------------------------------------------------------*/ - /* boxes = { 0 1 2 3 [4 6] [5 7] [8 10] [9 11] }; */ +/* boxes = { 0 1 2 3 [4 6] [5 7] [8 10] [9 11] }; */ const int16_t MC_PARAMUPMIX_CHIDX1[MC_PARAMUPMIX_COMBINATIONS] = { 0, 1, 4, 5 }; const int16_t MC_PARAMUPMIX_CHIDX2[MC_PARAMUPMIX_COMBINATIONS] = { 2, 3, 6, 7 }; @@ -1032,21 +1028,21 @@ const int16_t MC_PARAMUPMIX_CHIDX2[MC_PARAMUPMIX_COMBINATIONS] = { 2, 3, 6, 7 }; * Local function prototypes *-----------------------------------------------------------------------*/ -static void ps_pred_process_sf(MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix, DECODER_TC_BUFFER_HANDLE hTcBuffer, float qmf_mod_re[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float qmf_mod_im[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float qmf_side_re[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float qmf_side_im[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float *param_interpol, const int16_t ch, const int16_t slots_rendered); +static void ps_pred_process_sf( MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix, DECODER_TC_BUFFER_HANDLE hTcBuffer, float qmf_mod_re[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float qmf_mod_im[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float qmf_side_re[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float qmf_side_im[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float *param_interpol, const int16_t ch, const int16_t slots_rendered ); -static void ivas_mc_paramupmix_dec_sf(Decoder_Struct *st_ivas, float *output_f[MAX_OUTPUT_CHANNELS]); +static void ivas_mc_paramupmix_dec_sf( Decoder_Struct *st_ivas, float *output_f[MAX_OUTPUT_CHANNELS] ); -static void ivas_param_upmix_dec_decorr_subframes(Decoder_Struct *st_ivas, const int16_t nSamplesForRendering); +static void ivas_param_upmix_dec_decorr_subframes( Decoder_Struct *st_ivas, const int16_t nSamplesForRendering ); -static int16_t huff_read(Decoder_State *st, const int16_t(*ht)[2]); +static int16_t huff_read( Decoder_State *st, const int16_t ( *ht )[2] ); -static void huffman_decode(Decoder_State *st, const PAR_TYPE parType, int32_t *vq); +static void huffman_decode( Decoder_State *st, const PAR_TYPE parType, int32_t *vq ); -static void dequant_alpha(int32_t *vq, float *v); +static void dequant_alpha( int32_t *vq, float *v ); -static void dequant_beta(int32_t *aq, int32_t *bq, float *beta); +static void dequant_beta( int32_t *aq, int32_t *bq, float *beta ); -static void get_ec_data(Decoder_State *st, const PAR_TYPE parType, int32_t *parQ, int32_t *alphaQEnv, float ab[IVAS_MAX_NUM_BANDS]); +static void get_ec_data( Decoder_State *st, const PAR_TYPE parType, int32_t *parQ, int32_t *alphaQEnv, float ab[IVAS_MAX_NUM_BANDS] ); /*------------------------------------------------------------------------- @@ -1056,72 +1052,72 @@ static void get_ec_data(Decoder_State *st, const PAR_TYPE parType, int32_t *parQ *------------------------------------------------------------------------*/ void ivas_mc_paramupmix_dec_read_BS( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - Decoder_State *st0, /* i/o: decoder state structure */ - MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix, /* i/o: decoder MC Param-Upmix handle */ - int16_t *nb_bits /* o : number of bits written */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Decoder_State *st0, /* i/o: decoder state structure */ + MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix, /* i/o: decoder MC Param-Upmix handle */ + int16_t *nb_bits /* o : number of bits written */ ) { - int16_t i, k; - int32_t alpha_quant[IVAS_MAX_NUM_BANDS]; - int16_t nb_bits_read_orig; - int16_t next_bit_pos_orig, last_bit_pos; - uint16_t bstr_meta[MAX_BITS_METADATA], *bit_stream_orig; + int16_t i, k; + int32_t alpha_quant[IVAS_MAX_NUM_BANDS]; + int16_t nb_bits_read_orig; + int16_t next_bit_pos_orig, last_bit_pos; + uint16_t bstr_meta[MAX_BITS_METADATA], *bit_stream_orig; - push_wmops("mc_paramupmix_read_bs"); - *nb_bits = 0; + push_wmops( "mc_paramupmix_read_bs" ); + *nb_bits = 0; - if (st0->bfi) - { - for (i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++) + if ( st0->bfi ) { - for (k = 0; k < IVAS_MAX_NUM_BANDS; k++) - { - hMCParamUpmix->alphas[i][k] = hMCParamUpmix->alpha_prev[i][k]; - hMCParamUpmix->betas[i][k] = hMCParamUpmix->beta_prev[i][k]; - } + for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ ) + { + for ( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) + { + hMCParamUpmix->alphas[i][k] = hMCParamUpmix->alpha_prev[i][k]; + hMCParamUpmix->betas[i][k] = hMCParamUpmix->beta_prev[i][k]; + } + } + hMCParamUpmix->first_frame = 1; } - hMCParamUpmix->first_frame = 1; - } - else /* if (!st->bfi) */ - { - bit_stream_orig = st0->bit_stream; - next_bit_pos_orig = st0->next_bit_pos; - last_bit_pos = (int16_t)((st_ivas->hDecoderConfig->ivas_total_brate / FRAMES_PER_SEC) - 1); - nb_bits_read_orig = 0; - last_bit_pos -= nb_bits_read_orig; /* reverse the bitstream for easier reading of indices */ - for (i = 0; i < min(MAX_BITS_METADATA, last_bit_pos); i++) + else /* if (!st->bfi) */ { - bstr_meta[i] = st_ivas->bit_stream[last_bit_pos - i]; - } - st0->bit_stream = bstr_meta; - st0->next_bit_pos = 0; - st0->bits_frame = min(MAX_BITS_METADATA, last_bit_pos + 1); - st0->total_brate = st_ivas->hDecoderConfig->ivas_total_brate; /* to avoid BER detect */ + bit_stream_orig = st0->bit_stream; + next_bit_pos_orig = st0->next_bit_pos; + last_bit_pos = (int16_t) ( ( st_ivas->hDecoderConfig->ivas_total_brate / FRAMES_PER_SEC ) - 1 ); + nb_bits_read_orig = 0; + last_bit_pos -= nb_bits_read_orig; /* reverse the bitstream for easier reading of indices */ + for ( i = 0; i < min( MAX_BITS_METADATA, last_bit_pos ); i++ ) + { + bstr_meta[i] = st_ivas->bit_stream[last_bit_pos - i]; + } + st0->bit_stream = bstr_meta; + st0->next_bit_pos = 0; + st0->bits_frame = min( MAX_BITS_METADATA, last_bit_pos + 1 ); + st0->total_brate = st_ivas->hDecoderConfig->ivas_total_brate; /* to avoid BER detect */ - for (i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++) - { - get_ec_data(st0, ALPHA, hMCParamUpmix->alpha_quant[i], alpha_quant, hMCParamUpmix->alphas[i]); + for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ ) + { + get_ec_data( st0, ALPHA, hMCParamUpmix->alpha_quant[i], alpha_quant, hMCParamUpmix->alphas[i] ); - get_ec_data(st0, BETA, hMCParamUpmix->beta_quant[i], alpha_quant, hMCParamUpmix->betas[i]); - } - *nb_bits += st0->next_bit_pos; - st0->bit_stream = bit_stream_orig; - st0->next_bit_pos = next_bit_pos_orig; + get_ec_data( st0, BETA, hMCParamUpmix->beta_quant[i], alpha_quant, hMCParamUpmix->betas[i] ); + } + *nb_bits += st0->next_bit_pos; + st0->bit_stream = bit_stream_orig; + st0->next_bit_pos = next_bit_pos_orig; - if (hMCParamUpmix->first_frame) - { - for (i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++) - { - mvr2r(hMCParamUpmix->alphas[i], hMCParamUpmix->alpha_prev[i], IVAS_MAX_NUM_BANDS); - mvr2r(hMCParamUpmix->betas[i], hMCParamUpmix->beta_prev[i], IVAS_MAX_NUM_BANDS); - } - hMCParamUpmix->first_frame = 0; + if ( hMCParamUpmix->first_frame ) + { + for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ ) + { + mvr2r( hMCParamUpmix->alphas[i], hMCParamUpmix->alpha_prev[i], IVAS_MAX_NUM_BANDS ); + mvr2r( hMCParamUpmix->betas[i], hMCParamUpmix->beta_prev[i], IVAS_MAX_NUM_BANDS ); + } + hMCParamUpmix->first_frame = 0; + } } - } - pop_wmops(); - return; + pop_wmops(); + return; } @@ -1132,25 +1128,25 @@ void ivas_mc_paramupmix_dec_read_BS( *------------------------------------------------------------------------*/ void ivas_mc_paramupmix_dec_digest_tc( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - const uint8_t nCldfbSlots, /* i : number of CLFBS slots in the transport channels*/ - const int16_t nSamplesForRendering /* i : number of samples provided */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const uint8_t nCldfbSlots, /* i : number of CLFBS slots in the transport channels*/ + const int16_t nSamplesForRendering /* i : number of samples provided */ ) { - MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix; - hMCParamUpmix = st_ivas->hMCParamUpmix; - assert(hMCParamUpmix); - push_wmops("ivas_mc_paramupmix_dec_digest_tc"); + MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix; + hMCParamUpmix = st_ivas->hMCParamUpmix; + assert( hMCParamUpmix ); + push_wmops( "ivas_mc_paramupmix_dec_digest_tc" ); - ivas_param_upmix_dec_decorr_subframes(st_ivas, nSamplesForRendering); + ivas_param_upmix_dec_decorr_subframes( st_ivas, nSamplesForRendering ); - /* adapt subframes */ - ivas_jbm_dec_td_renderers_adapt_subframes(st_ivas); + /* adapt subframes */ + ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas ); - ivas_jbm_dec_get_adapted_linear_interpolator(DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbSlots, hMCParamUpmix->param_interpolator); + ivas_jbm_dec_get_adapted_linear_interpolator( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbSlots, hMCParamUpmix->param_interpolator ); - pop_wmops(); - return; + pop_wmops(); + return; } @@ -1161,81 +1157,81 @@ void ivas_mc_paramupmix_dec_digest_tc( *------------------------------------------------------------------------*/ void ivas_mc_paramupmix_dec_render( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - const uint16_t nSamplesAsked, /* i : number of CLDFB slots requested */ - uint16_t *nSamplesRendered, /* o : number of CLDFB slots rendered */ - uint16_t *nSamplesAvailable, /* o : number of CLDFB slots still to render */ - float *input_f[], /* i : core-coder transport channels */ - float *output_f[] /* i/o: synthesized core-coder transport channels */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const uint16_t nSamplesAsked, /* i : number of CLDFB slots requested */ + uint16_t *nSamplesRendered, /* o : number of CLDFB slots rendered */ + uint16_t *nSamplesAvailable, /* o : number of CLDFB slots still to render */ + float *input_f[], /* i : core-coder transport channels */ + float *output_f[] /* i/o: synthesized core-coder transport channels */ ) { - int16_t slots_to_render, first_sf, last_sf, subframe_idx; - uint16_t slot_size, ch; - float *output_f_local[MAX_OUTPUT_CHANNELS]; - MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix; - - hMCParamUpmix = st_ivas->hMCParamUpmix; - assert(hMCParamUpmix); - - push_wmops("ivas_mc_paramupmix_dec_render"); + int16_t slots_to_render, first_sf, last_sf, subframe_idx; + uint16_t slot_size, ch; + float *output_f_local[MAX_OUTPUT_CHANNELS]; + MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix; - for (ch = 0; ch < MAX_OUTPUT_CHANNELS; ch++) - { - output_f_local[ch] = output_f[ch]; - } + hMCParamUpmix = st_ivas->hMCParamUpmix; + assert( hMCParamUpmix ); - slot_size = st_ivas->hTcBuffer->n_samples_granularity; + push_wmops( "ivas_mc_paramupmix_dec_render" ); - /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */ - slots_to_render = min(st_ivas->hTcBuffer->num_slots - st_ivas->hTcBuffer->slots_rendered, nSamplesAsked / slot_size); - *nSamplesRendered = slots_to_render * slot_size; - first_sf = st_ivas->hTcBuffer->subframes_rendered; - last_sf = first_sf; + for ( ch = 0; ch < MAX_OUTPUT_CHANNELS; ch++ ) + { + output_f_local[ch] = output_f[ch]; + } - for (ch = 0; ch < MAX_TRANSPORT_CHANNELS; ch++) - { - mvr2r(input_f[ch], output_f_local[ch], *nSamplesRendered); - } + slot_size = st_ivas->hTcBuffer->n_samples_granularity; - while (slots_to_render > 0) - { - slots_to_render -= st_ivas->hTcBuffer->subframe_nbslots[last_sf]; - last_sf++; - } - { + /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */ + slots_to_render = min( st_ivas->hTcBuffer->num_slots - st_ivas->hTcBuffer->slots_rendered, nSamplesAsked / slot_size ); + *nSamplesRendered = slots_to_render * slot_size; + first_sf = st_ivas->hTcBuffer->subframes_rendered; + last_sf = first_sf; - for (ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS; ch++) + for ( ch = 0; ch < MAX_TRANSPORT_CHANNELS; ch++ ) { - mvr2r(hMCParamUpmix->alpha_prev[ch], hMCParamUpmix->alpha_sf[ch], IVAS_MAX_NUM_BANDS); - mvr2r(hMCParamUpmix->beta_prev[ch], hMCParamUpmix->beta_sf[ch], IVAS_MAX_NUM_BANDS); + mvr2r( input_f[ch], output_f_local[ch], *nSamplesRendered ); } - for (subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++) + while ( slots_to_render > 0 ) + { + slots_to_render -= st_ivas->hTcBuffer->subframe_nbslots[last_sf]; + last_sf++; + } { - int16_t n_samples_sf = slot_size * st_ivas->hTcBuffer->subframe_nbslots[subframe_idx]; - ivas_mc_paramupmix_dec_sf(st_ivas, output_f_local); + for ( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS; ch++ ) + { + mvr2r( hMCParamUpmix->alpha_prev[ch], hMCParamUpmix->alpha_sf[ch], IVAS_MAX_NUM_BANDS ); + mvr2r( hMCParamUpmix->beta_prev[ch], hMCParamUpmix->beta_sf[ch], IVAS_MAX_NUM_BANDS ); + } - for (ch = 0; ch < min(MAX_OUTPUT_CHANNELS, ivas_get_nchan_buffers_dec(st_ivas, -1, -1)); ch++) - { - output_f_local[ch] += n_samples_sf; - } + for ( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ ) + { + int16_t n_samples_sf = slot_size * st_ivas->hTcBuffer->subframe_nbslots[subframe_idx]; - /* update combined orientation access index */ - ivas_combined_orientation_update_index(st_ivas->hCombinedOrientationData, n_samples_sf); - } + ivas_mc_paramupmix_dec_sf( st_ivas, output_f_local ); - for (ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS; ch++) - { - mvr2r(hMCParamUpmix->alphas[ch], hMCParamUpmix->alpha_prev[ch], IVAS_MAX_NUM_BANDS); - mvr2r(hMCParamUpmix->betas[ch], hMCParamUpmix->beta_prev[ch], IVAS_MAX_NUM_BANDS); + for ( ch = 0; ch < min( MAX_OUTPUT_CHANNELS, ivas_get_nchan_buffers_dec( st_ivas, -1, -1 ) ); ch++ ) + { + output_f_local[ch] += n_samples_sf; + } + + /* update combined orientation access index */ + ivas_combined_orientation_update_index( st_ivas->hCombinedOrientationData, n_samples_sf ); + } + + for ( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS; ch++ ) + { + mvr2r( hMCParamUpmix->alphas[ch], hMCParamUpmix->alpha_prev[ch], IVAS_MAX_NUM_BANDS ); + mvr2r( hMCParamUpmix->betas[ch], hMCParamUpmix->beta_prev[ch], IVAS_MAX_NUM_BANDS ); + } } - } - *nSamplesAvailable = (st_ivas->hTcBuffer->num_slots - st_ivas->hTcBuffer->slots_rendered) * slot_size; + *nSamplesAvailable = ( st_ivas->hTcBuffer->num_slots - st_ivas->hTcBuffer->slots_rendered ) * slot_size; - pop_wmops(); - return; + pop_wmops(); + return; } @@ -1246,112 +1242,112 @@ void ivas_mc_paramupmix_dec_render( *-------------------------------------------------------------------------*/ ivas_error ivas_mc_paramupmix_dec_open( - Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ) { - MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix; - int32_t output_Fs; - int16_t nchan_transport; - uint16_t i; - ivas_error error; + MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix; + int32_t output_Fs; + int16_t nchan_transport; + uint16_t i; + ivas_error error; - error = IVAS_ERR_OK; + error = IVAS_ERR_OK; - /*-----------------------------------------------------------------* - * prepare library opening - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * prepare library opening + *-----------------------------------------------------------------*/ - if ((hMCParamUpmix = (MC_PARAMUPMIX_DEC_HANDLE)malloc(sizeof(MC_PARAMUPMIX_DEC_DATA))) == NULL) - { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param-Upmix MC\n")); - } - output_Fs = st_ivas->hDecoderConfig->output_Fs; - hMCParamUpmix->first_frame = 1; - st_ivas->nchan_transport = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS; - nchan_transport = st_ivas->nchan_transport; + if ( ( hMCParamUpmix = (MC_PARAMUPMIX_DEC_HANDLE) malloc( sizeof( MC_PARAMUPMIX_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param-Upmix MC\n" ) ); + } + output_Fs = st_ivas->hDecoderConfig->output_Fs; + hMCParamUpmix->first_frame = 1; + st_ivas->nchan_transport = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS; + nchan_transport = st_ivas->nchan_transport; - switch (nchan_transport) - { - case 8: - st_ivas->nCPE = 4; - st_ivas->nSCE = 0; - st_ivas->element_mode_init = IVAS_CPE_MDCT; - break; - } + switch ( nchan_transport ) + { + case 8: + st_ivas->nCPE = 4; + st_ivas->nSCE = 0; + st_ivas->element_mode_init = IVAS_CPE_MDCT; + break; + } - hMCParamUpmix->hoa_encoder = NULL; + hMCParamUpmix->hoa_encoder = NULL; - /*-----------------------------------------------------------------* - * set input parameters - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * set input parameters + *-----------------------------------------------------------------*/ - hMCParamUpmix->num_freq_bands = (int16_t)(output_Fs * INV_CLDFB_BANDWIDTH + 0.5f); + hMCParamUpmix->num_freq_bands = (int16_t) ( output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ); - for (i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++) - { - ivas_td_decorr_dec_open(&(hMCParamUpmix->hTdDecorr[i]), output_Fs, 2, 1); - } + for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ ) + { + ivas_td_decorr_dec_open( &( hMCParamUpmix->hTdDecorr[i] ), output_Fs, 2, 1 ); + } - for (i = 0; i < MC_PARAMUPMIX_MAX_TRANSPORT_CHANS; i++) - { - if ((hMCParamUpmix->pcm_delay[i] = (float *)malloc(NS2SA(output_Fs, IVAS_FB_DEC_DELAY_NS) * sizeof(float))) == NULL) + for ( i = 0; i < MC_PARAMUPMIX_MAX_TRANSPORT_CHANS; i++ ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for delay buffer\n")); + if ( ( hMCParamUpmix->pcm_delay[i] = (float *) malloc( NS2SA( output_Fs, IVAS_FB_DEC_DELAY_NS ) * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for delay buffer\n" ) ); + } + set_zero( hMCParamUpmix->pcm_delay[i], NS2SA( output_Fs, IVAS_FB_DEC_DELAY_NS ) ); } - set_zero(hMCParamUpmix->pcm_delay[i], NS2SA(output_Fs, IVAS_FB_DEC_DELAY_NS)); - } - /* Head or external rotation */ - if ((st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM) && (st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation)) - { - if ((hMCParamUpmix->hoa_encoder = (float *)malloc(st_ivas->hTransSetup.nchan_out_woLFE * MAX_INTERN_CHANNELS * sizeof(float))) == NULL) + /* Head or external rotation */ + if ( ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) && ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n")); + if ( ( hMCParamUpmix->hoa_encoder = (float *) malloc( st_ivas->hTransSetup.nchan_out_woLFE * MAX_INTERN_CHANNELS * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } + compute_hoa_encoder_mtx( st_ivas->hTransSetup.ls_azimuth, st_ivas->hTransSetup.ls_elevation, hMCParamUpmix->hoa_encoder, st_ivas->hTransSetup.nchan_out_woLFE, HEAD_ROTATION_HOA_ORDER ); } - compute_hoa_encoder_mtx(st_ivas->hTransSetup.ls_azimuth, st_ivas->hTransSetup.ls_elevation, hMCParamUpmix->hoa_encoder, st_ivas->hTransSetup.nchan_out_woLFE, HEAD_ROTATION_HOA_ORDER); - } - /* allocate transport channels*/ - hMCParamUpmix->free_param_interpolator = 0; - hMCParamUpmix->param_interpolator = NULL; + /* allocate transport channels*/ + hMCParamUpmix->free_param_interpolator = 0; + hMCParamUpmix->param_interpolator = NULL; - if ((hMCParamUpmix->param_interpolator = (float *)malloc(MAX_JBM_CLDFB_TIMESLOTS * sizeof(float))) == NULL) - { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for interpolator\n")); - } - hMCParamUpmix->free_param_interpolator = 1; + if ( ( hMCParamUpmix->param_interpolator = (float *) malloc( MAX_JBM_CLDFB_TIMESLOTS * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for interpolator\n" ) ); + } + hMCParamUpmix->free_param_interpolator = 1; - ivas_jbm_dec_get_adapted_linear_interpolator(DEFAULT_JBM_CLDFB_TIMESLOTS, DEFAULT_JBM_CLDFB_TIMESLOTS, hMCParamUpmix->param_interpolator); + ivas_jbm_dec_get_adapted_linear_interpolator( DEFAULT_JBM_CLDFB_TIMESLOTS, DEFAULT_JBM_CLDFB_TIMESLOTS, hMCParamUpmix->param_interpolator ); - if (st_ivas->hTcBuffer == NULL) - { - int16_t nchan_to_allocate; - int16_t nchan_tc; - TC_BUFFER_MODE buffer_mode; + if ( st_ivas->hTcBuffer == NULL ) + { + int16_t nchan_to_allocate; + int16_t nchan_tc; + TC_BUFFER_MODE buffer_mode; - buffer_mode = TC_BUFFER_MODE_RENDERER; - nchan_tc = ivas_jbm_dec_get_num_tc_channels(st_ivas); - nchan_to_allocate = MC_PARAMUPMIX_MAX_INPUT_CHANS; + buffer_mode = TC_BUFFER_MODE_RENDERER; + nchan_tc = ivas_jbm_dec_get_num_tc_channels( st_ivas ); + nchan_to_allocate = MC_PARAMUPMIX_MAX_INPUT_CHANS; - if (st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_STEREO || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_MONO) - { - buffer_mode = TC_BUFFER_MODE_BUFFER; - nchan_tc = st_ivas->hDecoderConfig->nchan_out; - nchan_to_allocate = nchan_tc; - } - else if (st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC) - { - nchan_to_allocate = MC_PARAMUPMIX_MAX_INPUT_CHANS; - } + if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_STEREO || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_MONO ) + { + buffer_mode = TC_BUFFER_MODE_BUFFER; + nchan_tc = st_ivas->hDecoderConfig->nchan_out; + nchan_to_allocate = nchan_tc; + } + else if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) + { + nchan_to_allocate = MC_PARAMUPMIX_MAX_INPUT_CHANS; + } - if ((error = ivas_jbm_dec_tc_buffer_open(st_ivas, buffer_mode, nchan_tc, nchan_to_allocate, nchan_to_allocate, NS2SA(st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS))) != IVAS_ERR_OK) - { - return error; + if ( ( error = ivas_jbm_dec_tc_buffer_open( st_ivas, buffer_mode, nchan_tc, nchan_to_allocate, nchan_to_allocate, NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ) != IVAS_ERR_OK ) + { + return error; + } } - } - st_ivas->hMCParamUpmix = hMCParamUpmix; + st_ivas->hMCParamUpmix = hMCParamUpmix; - return error; + return error; } @@ -1362,43 +1358,43 @@ ivas_error ivas_mc_paramupmix_dec_open( *------------------------------------------------------------------------*/ void ivas_mc_paramupmix_dec_close( - MC_PARAMUPMIX_DEC_HANDLE *hMCParamUpmix /* i/o: Parametric MC decoder handle */ + MC_PARAMUPMIX_DEC_HANDLE *hMCParamUpmix /* i/o: Parametric MC decoder handle */ ) { - int16_t i; + int16_t i; + + if ( hMCParamUpmix == NULL || *hMCParamUpmix == NULL ) + { + return; + } + for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ ) + { + ivas_td_decorr_dec_close( &( ( *hMCParamUpmix )->hTdDecorr[i] ) ); + } + for ( i = 0; i < MC_PARAMUPMIX_MAX_TRANSPORT_CHANS; i++ ) + { + if ( ( *hMCParamUpmix )->pcm_delay[i] != NULL ) + { + free( ( *hMCParamUpmix )->pcm_delay[i] ); + } + } + if ( ( *hMCParamUpmix )->param_interpolator != NULL ) + { + if ( ( *hMCParamUpmix )->free_param_interpolator == 1 ) + { + free( ( *hMCParamUpmix )->param_interpolator ); + } + } + if ( ( *hMCParamUpmix )->hoa_encoder != NULL ) + { + free( ( *hMCParamUpmix )->hoa_encoder ); + ( *hMCParamUpmix )->hoa_encoder = NULL; + } + free( *hMCParamUpmix ); + + *hMCParamUpmix = NULL; - if (hMCParamUpmix == NULL || *hMCParamUpmix == NULL) - { return; - } - for (i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++) - { - ivas_td_decorr_dec_close(&((*hMCParamUpmix)->hTdDecorr[i])); - } - for (i = 0; i < MC_PARAMUPMIX_MAX_TRANSPORT_CHANS; i++) - { - if ((*hMCParamUpmix)->pcm_delay[i] != NULL) - { - free((*hMCParamUpmix)->pcm_delay[i]); - } - } - if ((*hMCParamUpmix)->param_interpolator != NULL) - { - if ((*hMCParamUpmix)->free_param_interpolator == 1) - { - free((*hMCParamUpmix)->param_interpolator); - } - } - if ((*hMCParamUpmix)->hoa_encoder != NULL) - { - free((*hMCParamUpmix)->hoa_encoder); - (*hMCParamUpmix)->hoa_encoder = NULL; - } - free(*hMCParamUpmix); - - *hMCParamUpmix = NULL; - - return; } @@ -1409,49 +1405,49 @@ void ivas_mc_paramupmix_dec_close( *------------------------------------------------------------------------*/ static void paramupmix_td_decorr_process_jbm( - ivas_td_decorr_state_t *hTdDecorr[], /* i/o: SPAR Covar. decoder handle */ - float *pcm_in[], /* i : input audio channels */ - float **pp_out_pcm, /* o : output audio channels */ - const int16_t output_frame /* i : output frame length */ + ivas_td_decorr_state_t *hTdDecorr[], /* i/o: SPAR Covar. decoder handle */ + float *pcm_in[], /* i : input audio channels */ + float **pp_out_pcm, /* o : output audio channels */ + const int16_t output_frame /* i : output frame length */ ) { - int16_t j, k; - int16_t offset; - float in_duck_gain[L_FRAME48k], out_duck_gain[L_FRAME48k]; - - offset = (int16_t)(output_frame * FRAMES_PER_SEC * IVAS_DECORR_PARM_LOOKAHEAD_TAU); + int16_t j, k; + int16_t offset; + float in_duck_gain[L_FRAME48k], out_duck_gain[L_FRAME48k]; - /* Look-ahead delay */ - for (k = 0; k < MC_PARAMUPMIX_COMBINATIONS; k++) - { - mvr2r(pcm_in[k], pp_out_pcm[k], output_frame); - delay_signal_float(pp_out_pcm[k], output_frame, hTdDecorr[k]->look_ahead_buf, offset); + offset = (int16_t) ( output_frame * FRAMES_PER_SEC * IVAS_DECORR_PARM_LOOKAHEAD_TAU ); - /* In ducking gains */ - if (hTdDecorr[k]->ducking_flag) + /* Look-ahead delay */ + for ( k = 0; k < MC_PARAMUPMIX_COMBINATIONS; k++ ) { - ivas_td_decorr_get_ducking_gains(hTdDecorr[k]->pTrans_det, pcm_in[k], in_duck_gain, out_duck_gain, output_frame, 0); + mvr2r( pcm_in[k], pp_out_pcm[k], output_frame ); + delay_signal_float( pp_out_pcm[k], output_frame, hTdDecorr[k]->look_ahead_buf, offset ); - for (j = 0; j < output_frame; j++) - { - pp_out_pcm[k][j] = pp_out_pcm[k][j] * in_duck_gain[j]; - } - } + /* In ducking gains */ + if ( hTdDecorr[k]->ducking_flag ) + { + ivas_td_decorr_get_ducking_gains( hTdDecorr[k]->pTrans_det, pcm_in[k], in_duck_gain, out_duck_gain, output_frame, 0 ); - /* All pass delay section */ - ivas_td_decorr_APD_iir_filter(&hTdDecorr[k]->APD_filt_state[0], pp_out_pcm[k], hTdDecorr[k]->num_apd_sections, output_frame); + for ( j = 0; j < output_frame; j++ ) + { + pp_out_pcm[k][j] = pp_out_pcm[k][j] * in_duck_gain[j]; + } + } - /* Out ducking gains */ - if (hTdDecorr[k]->ducking_flag) - { - for (j = 0; j < output_frame; j++) - { - pp_out_pcm[k][j] = pp_out_pcm[k][j] * out_duck_gain[j]; - } + /* All pass delay section */ + ivas_td_decorr_APD_iir_filter( &hTdDecorr[k]->APD_filt_state[0], pp_out_pcm[k], hTdDecorr[k]->num_apd_sections, output_frame ); + + /* Out ducking gains */ + if ( hTdDecorr[k]->ducking_flag ) + { + for ( j = 0; j < output_frame; j++ ) + { + pp_out_pcm[k][j] = pp_out_pcm[k][j] * out_duck_gain[j]; + } + } } - } - return; + return; } @@ -1462,47 +1458,47 @@ static void paramupmix_td_decorr_process_jbm( *------------------------------------------------------------------------*/ static void ivas_param_upmix_dec_decorr_subframes( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - const int16_t nSamplesForRendering) + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const int16_t nSamplesForRendering ) { - MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix; - float *pPcm_tmp[MC_PARAMUPMIX_COMBINATIONS]; - float *p_tc[MC_PARAMUPMIX_COMBINATIONS]; - int16_t nchan_internal, ch; - int16_t nSamplesLeftForTD, default_frame; + MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix; + float *pPcm_tmp[MC_PARAMUPMIX_COMBINATIONS]; + float *p_tc[MC_PARAMUPMIX_COMBINATIONS]; + int16_t nchan_internal, ch; + int16_t nSamplesLeftForTD, default_frame; - hMCParamUpmix = st_ivas->hMCParamUpmix; - assert(hMCParamUpmix); + hMCParamUpmix = st_ivas->hMCParamUpmix; + assert( hMCParamUpmix ); + + push_wmops( "ivas_param_upmix_dec_decorr_subframes" ); - push_wmops("ivas_param_upmix_dec_decorr_subframes"); + /* TD decorrelator */ + default_frame = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ); + nSamplesLeftForTD = nSamplesForRendering; + nchan_internal = MC_PARAMUPMIX_COMBINATIONS; - /* TD decorrelator */ - default_frame = (int16_t)(st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC); - nSamplesLeftForTD = nSamplesForRendering; - nchan_internal = MC_PARAMUPMIX_COMBINATIONS; + for ( ch = 0; ch < nchan_internal; ch++ ) + { + pPcm_tmp[ch] = st_ivas->hTcBuffer->tc[ch + 8]; + p_tc[ch] = st_ivas->hTcBuffer->tc[ch + 4]; + } - for (ch = 0; ch < nchan_internal; ch++) - { - pPcm_tmp[ch] = st_ivas->hTcBuffer->tc[ch + 8]; - p_tc[ch] = st_ivas->hTcBuffer->tc[ch + 4]; - } + while ( nSamplesLeftForTD ) + { + int16_t nSamplesToDecorr = min( nSamplesLeftForTD, default_frame ); - while (nSamplesLeftForTD) - { - int16_t nSamplesToDecorr = min(nSamplesLeftForTD, default_frame); + paramupmix_td_decorr_process_jbm( hMCParamUpmix->hTdDecorr, p_tc, pPcm_tmp, nSamplesToDecorr ); - paramupmix_td_decorr_process_jbm(hMCParamUpmix->hTdDecorr, p_tc, pPcm_tmp, nSamplesToDecorr); + for ( ch = 0; ch < nchan_internal; ch++ ) + { + p_tc[ch] += nSamplesToDecorr; + } - for (ch = 0; ch < nchan_internal; ch++) - { - p_tc[ch] += nSamplesToDecorr; + nSamplesLeftForTD -= nSamplesToDecorr; } - nSamplesLeftForTD -= nSamplesToDecorr; - } - - pop_wmops(); - return; + pop_wmops(); + return; } @@ -1511,414 +1507,414 @@ static void ivas_param_upmix_dec_decorr_subframes( /*****************************************************************************************/ static void ps_pred_process_sf( - MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix, - DECODER_TC_BUFFER_HANDLE hTcBuffer, - float qmf_mod_re[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* in/out */ - float qmf_mod_im[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], - float qmf_side_re[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* in/out */ - float qmf_side_im[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], - float *param_interpol, - const int16_t ch, - const int16_t slots_rendered) + MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix, + DECODER_TC_BUFFER_HANDLE hTcBuffer, + float qmf_mod_re[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* in/out */ + float qmf_mod_im[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], + float qmf_side_re[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* in/out */ + float qmf_side_im[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], + float *param_interpol, + const int16_t ch, + const int16_t slots_rendered ) { - float vmre, vmim, vsre, vsim; - int16_t iqmf, ipar, ismp, iismp; - float alpha_smp, beta_smp; - float *alpha1, *alpha2; - float *beta1, *beta2; - float *alpha_prev = hMCParamUpmix->alpha_prev[ch]; - float *beta_prev = hMCParamUpmix->beta_prev[ch]; - float *alpha_sf = hMCParamUpmix->alpha_sf[ch]; - float *beta_sf = hMCParamUpmix->beta_sf[ch]; - float dalpha, dbeta, ifac; - float alpha_start[IVAS_MAX_NUM_BANDS], beta_start[IVAS_MAX_NUM_BANDS]; - - const int16_t qmf_to_par_band[] = { - 0, 1, 2, 3, 4, 5, 5, 6, 6, 7, - 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, - 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, - 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, - 11, 11, 11, 11, 11, 11, 11, 11, 11, 11 - }; - - mvr2r(alpha_sf, alpha_start, IVAS_MAX_NUM_BANDS); - mvr2r(beta_sf, beta_start, IVAS_MAX_NUM_BANDS); - for (iqmf = 0; iqmf < CLDFB_NO_CHANNELS_MAX; iqmf++) - { - ipar = qmf_to_par_band[iqmf]; - alpha1 = alpha_prev; - beta1 = beta_prev; - - ismp = 0; - alpha2 = hMCParamUpmix->alphas[ch]; - beta2 = hMCParamUpmix->betas[ch]; - alpha_smp = alpha_start[ipar]; - beta_smp = beta_start[ipar]; - - for (iismp = 0; iismp < hTcBuffer->subframe_nbslots[hTcBuffer->subframes_rendered]; iismp++) - { - if ((slots_rendered == 0) && (iismp == 0)) - { - ifac = param_interpol[iismp]; - } - else - { - ifac = param_interpol[iismp] - param_interpol[iismp - 1]; - } - dalpha = (alpha2[ipar] - alpha1[ipar]) * ifac; - dbeta = (beta2[ipar] - beta1[ipar]) * ifac; - - alpha_smp += dalpha; - beta_smp += dbeta; - - vmre = qmf_mod_re[ismp][iqmf]; - vmim = qmf_mod_im[ismp][iqmf]; - vsre = qmf_side_re[ismp][iqmf]; - vsim = qmf_side_im[ismp][iqmf]; - - qmf_side_re[ismp][iqmf] = alpha_smp * vmre + beta_smp * vsre; - qmf_side_im[ismp][iqmf] = alpha_smp * vmim + beta_smp * vsim; - - ismp++; - } - alpha_sf[ipar] = alpha_smp; - beta_sf[ipar] = beta_smp; - } - - return; + float vmre, vmim, vsre, vsim; + int16_t iqmf, ipar, ismp, iismp; + float alpha_smp, beta_smp; + float *alpha1, *alpha2; + float *beta1, *beta2; + float *alpha_prev = hMCParamUpmix->alpha_prev[ch]; + float *beta_prev = hMCParamUpmix->beta_prev[ch]; + float *alpha_sf = hMCParamUpmix->alpha_sf[ch]; + float *beta_sf = hMCParamUpmix->beta_sf[ch]; + float dalpha, dbeta, ifac; + float alpha_start[IVAS_MAX_NUM_BANDS], beta_start[IVAS_MAX_NUM_BANDS]; + + const int16_t qmf_to_par_band[] = { + 0, 1, 2, 3, 4, 5, 5, 6, 6, 7, + 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, + 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, + 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, + 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, + 11, 11, 11, 11, 11, 11, 11, 11, 11, 11 + }; + + mvr2r( alpha_sf, alpha_start, IVAS_MAX_NUM_BANDS ); + mvr2r( beta_sf, beta_start, IVAS_MAX_NUM_BANDS ); + for ( iqmf = 0; iqmf < CLDFB_NO_CHANNELS_MAX; iqmf++ ) + { + ipar = qmf_to_par_band[iqmf]; + alpha1 = alpha_prev; + beta1 = beta_prev; + + ismp = 0; + alpha2 = hMCParamUpmix->alphas[ch]; + beta2 = hMCParamUpmix->betas[ch]; + alpha_smp = alpha_start[ipar]; + beta_smp = beta_start[ipar]; + + for ( iismp = 0; iismp < hTcBuffer->subframe_nbslots[hTcBuffer->subframes_rendered]; iismp++ ) + { + if ( ( slots_rendered == 0 ) && ( iismp == 0 ) ) + { + ifac = param_interpol[iismp]; + } + else + { + ifac = param_interpol[iismp] - param_interpol[iismp - 1]; + } + dalpha = ( alpha2[ipar] - alpha1[ipar] ) * ifac; + dbeta = ( beta2[ipar] - beta1[ipar] ) * ifac; + + alpha_smp += dalpha; + beta_smp += dbeta; + + vmre = qmf_mod_re[ismp][iqmf]; + vmim = qmf_mod_im[ismp][iqmf]; + vsre = qmf_side_re[ismp][iqmf]; + vsim = qmf_side_im[ismp][iqmf]; + + qmf_side_re[ismp][iqmf] = alpha_smp * vmre + beta_smp * vsre; + qmf_side_im[ismp][iqmf] = alpha_smp * vmim + beta_smp * vsim; + + ismp++; + } + alpha_sf[ipar] = alpha_smp; + beta_sf[ipar] = beta_smp; + } + + return; } static void ivas_mc_paramupmix_dec_sf( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - float *output_f[MAX_OUTPUT_CHANNELS] /* i/o: synthesized core-coder transport channels */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + float *output_f[MAX_OUTPUT_CHANNELS] /* i/o: synthesized core-coder transport channels */ ) { - int16_t i, ch, slot_idx, k; - float *pPcm_temp[MC_PARAMUPMIX_COMBINATIONS * 2]; /* decorrelated and undecorrelated*/ - /*CLDFB*/ - float Cldfb_RealBuffer[MC_PARAMUPMIX_MAX_TRANSPORT_CHANS][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; - float Cldfb_ImagBuffer[MC_PARAMUPMIX_MAX_TRANSPORT_CHANS][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; - int16_t noparamupmix_delay, n_samples_rendered; - MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix; - int16_t subframeIdx, idx_in, maxBand; - float Cldfb_RealBuffer_subfr[MAX_INTERN_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; - float Cldfb_ImagBuffer_subfr[MAX_INTERN_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; - float Cldfb_RealBuffer_Binaural[BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; - float Cldfb_ImagBuffer_Binaural[BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; - - hMCParamUpmix = st_ivas->hMCParamUpmix; - assert(hMCParamUpmix); - push_wmops("ivas_mc_paramupmix_dec_sf"); - - for (i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++) - { - pPcm_temp[2 * i] = output_f[i + 4]; /* un-decorrelated */ - pPcm_temp[2 * i + 1] = output_f[i + 8]; /* decorrelated */ - } - - /* CLDFB Analysis*/ - for (ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS * 2; ch++) - { - /* slot loop for gathering the input data */ - for (slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++) - { - cldfbAnalysis_ts_ivas(&(pPcm_temp[ch][hMCParamUpmix->num_freq_bands * slot_idx]), Cldfb_RealBuffer[ch][slot_idx], Cldfb_ImagBuffer[ch][slot_idx], hMCParamUpmix->num_freq_bands, st_ivas->cldfbAnaDec[ch]); - } - } - for (ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS; ch++) - { - ps_pred_process_sf(hMCParamUpmix, - st_ivas->hTcBuffer, - Cldfb_RealBuffer[2 * ch], /* in/out */ - Cldfb_ImagBuffer[2 * ch], - Cldfb_RealBuffer[2 * ch + 1], /* in/out decorr */ - Cldfb_ImagBuffer[2 * ch + 1], - &hMCParamUpmix->param_interpolator[st_ivas->hTcBuffer->slots_rendered], - ch, - st_ivas->hTcBuffer->slots_rendered); - - /*-- m, s -> l, r ----------------------------*/ - for (slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++) - { - for (k = 0; k < CLDFB_NO_CHANNELS_MAX; k++) - { - float qlre = Cldfb_RealBuffer[2 * ch][slot_idx][k]; - float qlim = Cldfb_ImagBuffer[2 * ch][slot_idx][k]; - float qrre = Cldfb_RealBuffer[2 * ch + 1][slot_idx][k]; - float qrim = Cldfb_ImagBuffer[2 * ch + 1][slot_idx][k]; - - Cldfb_RealBuffer[2 * ch][slot_idx][k] = qlre + qrre; - Cldfb_ImagBuffer[2 * ch][slot_idx][k] = qlim + qrim; - Cldfb_RealBuffer[2 * ch + 1][slot_idx][k] = qlre - qrre; - Cldfb_ImagBuffer[2 * ch + 1][slot_idx][k] = qlim - qrim; - } - } - } - - if (st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM) - { - maxBand = (int16_t)((CLDFB_NO_CHANNELS_MAX * st_ivas->hDecoderConfig->output_Fs) / 48000); - subframeIdx = st_ivas->hTcBuffer->subframes_rendered; - /* fastconv binaural rendering and CLDFB synthesis */ - /* cldfb analysis of non-coupled, non-LFE channels */ - idx_in = 0; - for (ch = 0; ch < MC_PARAMUPMIX_MAX_INPUT_CHANS - 2 * MC_PARAMUPMIX_COMBINATIONS; ch++) - { - if (st_ivas->hIntSetup.index_lfe[0] != ch) - { - pPcm_temp[ch] = output_f[ch]; + int16_t i, ch, slot_idx, k; + float *pPcm_temp[MC_PARAMUPMIX_COMBINATIONS * 2]; /* decorrelated and undecorrelated*/ + /*CLDFB*/ + float Cldfb_RealBuffer[MC_PARAMUPMIX_MAX_TRANSPORT_CHANS][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; + float Cldfb_ImagBuffer[MC_PARAMUPMIX_MAX_TRANSPORT_CHANS][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; + int16_t noparamupmix_delay, n_samples_rendered; + MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix; + int16_t subframeIdx, idx_in, maxBand; + float Cldfb_RealBuffer_subfr[MAX_INTERN_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; + float Cldfb_ImagBuffer_subfr[MAX_INTERN_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; + float Cldfb_RealBuffer_Binaural[BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; + float Cldfb_ImagBuffer_Binaural[BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; + + hMCParamUpmix = st_ivas->hMCParamUpmix; + assert( hMCParamUpmix ); + push_wmops( "ivas_mc_paramupmix_dec_sf" ); + + for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ ) + { + pPcm_temp[2 * i] = output_f[i + 4]; /* un-decorrelated */ + pPcm_temp[2 * i + 1] = output_f[i + 8]; /* decorrelated */ + } + + /* CLDFB Analysis*/ + for ( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS * 2; ch++ ) + { /* slot loop for gathering the input data */ - for (slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++) + for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ ) { - cldfbAnalysis_ts_ivas(&(pPcm_temp[ch][hMCParamUpmix->num_freq_bands * slot_idx]), - Cldfb_RealBuffer_subfr[idx_in][slot_idx], - Cldfb_ImagBuffer_subfr[idx_in][slot_idx], - maxBand, st_ivas->cldfbAnaDec[2 * MC_PARAMUPMIX_COMBINATIONS + idx_in]); + cldfbAnalysis_ts_ivas( &( pPcm_temp[ch][hMCParamUpmix->num_freq_bands * slot_idx] ), Cldfb_RealBuffer[ch][slot_idx], Cldfb_ImagBuffer[ch][slot_idx], hMCParamUpmix->num_freq_bands, st_ivas->cldfbAnaDec[ch] ); + } + } + for ( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS; ch++ ) + { + ps_pred_process_sf( hMCParamUpmix, + st_ivas->hTcBuffer, + Cldfb_RealBuffer[2 * ch], /* in/out */ + Cldfb_ImagBuffer[2 * ch], + Cldfb_RealBuffer[2 * ch + 1], /* in/out decorr */ + Cldfb_ImagBuffer[2 * ch + 1], + &hMCParamUpmix->param_interpolator[st_ivas->hTcBuffer->slots_rendered], + ch, + st_ivas->hTcBuffer->slots_rendered ); + + /*-- m, s -> l, r ----------------------------*/ + for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ ) + { + for ( k = 0; k < CLDFB_NO_CHANNELS_MAX; k++ ) + { + float qlre = Cldfb_RealBuffer[2 * ch][slot_idx][k]; + float qlim = Cldfb_ImagBuffer[2 * ch][slot_idx][k]; + float qrre = Cldfb_RealBuffer[2 * ch + 1][slot_idx][k]; + float qrim = Cldfb_ImagBuffer[2 * ch + 1][slot_idx][k]; + + Cldfb_RealBuffer[2 * ch][slot_idx][k] = qlre + qrre; + Cldfb_ImagBuffer[2 * ch][slot_idx][k] = qlim + qrim; + Cldfb_RealBuffer[2 * ch + 1][slot_idx][k] = qlre - qrre; + Cldfb_ImagBuffer[2 * ch + 1][slot_idx][k] = qlim - qrim; + } + } + } + + if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) + { + maxBand = (int16_t) ( ( CLDFB_NO_CHANNELS_MAX * st_ivas->hDecoderConfig->output_Fs ) / 48000 ); + subframeIdx = st_ivas->hTcBuffer->subframes_rendered; + /* fastconv binaural rendering and CLDFB synthesis */ + /* cldfb analysis of non-coupled, non-LFE channels */ + idx_in = 0; + for ( ch = 0; ch < MC_PARAMUPMIX_MAX_INPUT_CHANS - 2 * MC_PARAMUPMIX_COMBINATIONS; ch++ ) + { + if ( st_ivas->hIntSetup.index_lfe[0] != ch ) + { + pPcm_temp[ch] = output_f[ch]; + /* slot loop for gathering the input data */ + for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ ) + { + cldfbAnalysis_ts_ivas( &( pPcm_temp[ch][hMCParamUpmix->num_freq_bands * slot_idx] ), + Cldfb_RealBuffer_subfr[idx_in][slot_idx], + Cldfb_ImagBuffer_subfr[idx_in][slot_idx], + maxBand, st_ivas->cldfbAnaDec[2 * MC_PARAMUPMIX_COMBINATIONS + idx_in] ); + } + idx_in++; + } + } + + /* copy and reorder cldfb analysis of coupled channels */ + for ( ch = 0; ch < MAX_PARAM_SPATIAL_SUBFRAMES; ch++ ) + { + for ( slot_idx = 0; slot_idx < MAX_PARAM_SPATIAL_SUBFRAMES; slot_idx++ ) + { + mvr2r( Cldfb_RealBuffer[MC_PARAMUPMIX_CHIDX1[ch]][slot_idx], Cldfb_RealBuffer_subfr[idx_in][slot_idx], CLDFB_NO_CHANNELS_MAX ); + mvr2r( Cldfb_ImagBuffer[MC_PARAMUPMIX_CHIDX1[ch]][slot_idx], Cldfb_ImagBuffer_subfr[idx_in][slot_idx], CLDFB_NO_CHANNELS_MAX ); + mvr2r( Cldfb_RealBuffer[MC_PARAMUPMIX_CHIDX2[ch]][slot_idx], Cldfb_RealBuffer_subfr[idx_in + 1][slot_idx], CLDFB_NO_CHANNELS_MAX ); + mvr2r( Cldfb_ImagBuffer[MC_PARAMUPMIX_CHIDX2[ch]][slot_idx], Cldfb_ImagBuffer_subfr[idx_in + 1][slot_idx], CLDFB_NO_CHANNELS_MAX ); + } + idx_in += 2; + } + + if ( st_ivas->hCombinedOrientationData && st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV ) + { + for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ ) + { + ivas_param_mc_mc2sba_cldfb( st_ivas->hTransSetup, hMCParamUpmix->hoa_encoder, slot_idx, Cldfb_RealBuffer_subfr, Cldfb_ImagBuffer_subfr, maxBand, GAIN_LFE ); + } + } + + + /* Implement binaural rendering */ + ivas_binRenderer( st_ivas->hBinRenderer, + st_ivas->hCombinedOrientationData, + st_ivas->hTcBuffer->subframe_nbslots[subframeIdx], + Cldfb_RealBuffer_Binaural, Cldfb_ImagBuffer_Binaural, + Cldfb_RealBuffer_subfr, + Cldfb_ImagBuffer_subfr ); + + + /* Implement CLDFB synthesis */ + for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) + { + float *RealBuffer[MAX_PARAM_SPATIAL_SUBFRAMES]; + float *ImagBuffer[MAX_PARAM_SPATIAL_SUBFRAMES]; + + for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[subframeIdx]; slot_idx++ ) + { + RealBuffer[slot_idx] = Cldfb_RealBuffer_Binaural[ch][slot_idx]; + ImagBuffer[slot_idx] = Cldfb_ImagBuffer_Binaural[ch][slot_idx]; + } + + cldfbSynthesis_ivas( RealBuffer, ImagBuffer, &( output_f[ch][0] ), maxBand * st_ivas->hTcBuffer->subframe_nbslots[subframeIdx], st_ivas->cldfbSynDec[ch] ); } - idx_in++; - } - } - - /* copy and reorder cldfb analysis of coupled channels */ - for (ch = 0; ch < MAX_PARAM_SPATIAL_SUBFRAMES; ch++) - { - for (slot_idx = 0; slot_idx < MAX_PARAM_SPATIAL_SUBFRAMES; slot_idx++) - { - mvr2r(Cldfb_RealBuffer[MC_PARAMUPMIX_CHIDX1[ch]][slot_idx], Cldfb_RealBuffer_subfr[idx_in][slot_idx], CLDFB_NO_CHANNELS_MAX); - mvr2r(Cldfb_ImagBuffer[MC_PARAMUPMIX_CHIDX1[ch]][slot_idx], Cldfb_ImagBuffer_subfr[idx_in][slot_idx], CLDFB_NO_CHANNELS_MAX); - mvr2r(Cldfb_RealBuffer[MC_PARAMUPMIX_CHIDX2[ch]][slot_idx], Cldfb_RealBuffer_subfr[idx_in + 1][slot_idx], CLDFB_NO_CHANNELS_MAX); - mvr2r(Cldfb_ImagBuffer[MC_PARAMUPMIX_CHIDX2[ch]][slot_idx], Cldfb_ImagBuffer_subfr[idx_in + 1][slot_idx], CLDFB_NO_CHANNELS_MAX); - } - idx_in += 2; - } - - if (st_ivas->hCombinedOrientationData && st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV) - { - for (slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++) - { - ivas_param_mc_mc2sba_cldfb(st_ivas->hTransSetup, hMCParamUpmix->hoa_encoder, slot_idx, Cldfb_RealBuffer_subfr, Cldfb_ImagBuffer_subfr, maxBand, GAIN_LFE); - } - } - - - /* Implement binaural rendering */ - ivas_binRenderer(st_ivas->hBinRenderer, - st_ivas->hCombinedOrientationData, - st_ivas->hTcBuffer->subframe_nbslots[subframeIdx], - Cldfb_RealBuffer_Binaural, Cldfb_ImagBuffer_Binaural, - Cldfb_RealBuffer_subfr, - Cldfb_ImagBuffer_subfr); - - - /* Implement CLDFB synthesis */ - for (ch = 0; ch < BINAURAL_CHANNELS; ch++) - { - float *RealBuffer[MAX_PARAM_SPATIAL_SUBFRAMES]; - float *ImagBuffer[MAX_PARAM_SPATIAL_SUBFRAMES]; - - for (slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[subframeIdx]; slot_idx++) - { - RealBuffer[slot_idx] = Cldfb_RealBuffer_Binaural[ch][slot_idx]; - ImagBuffer[slot_idx] = Cldfb_ImagBuffer_Binaural[ch][slot_idx]; - } - - cldfbSynthesis_ivas(RealBuffer, ImagBuffer, &(output_f[ch][0]), maxBand * st_ivas->hTcBuffer->subframe_nbslots[subframeIdx], st_ivas->cldfbSynDec[ch]); - } - } - else - { - /* boxes = { 0 1 2 3 [4 6] [5 7] [8 10] [9 11] }; */ - pPcm_temp[0] = output_f[4]; - pPcm_temp[1] = output_f[6]; - pPcm_temp[2] = output_f[5]; - pPcm_temp[3] = output_f[7]; - pPcm_temp[4] = output_f[8]; - pPcm_temp[5] = output_f[10]; - pPcm_temp[6] = output_f[9]; - pPcm_temp[7] = output_f[11]; - - /* CLDFB synthesis */ - for (ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS * 2; ch++) - { - for (slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++) - { - float *ptr_im[1], *ptr_re[1]; - ptr_re[0] = Cldfb_RealBuffer[ch][slot_idx]; - ptr_im[0] = Cldfb_ImagBuffer[ch][slot_idx]; - - cldfbSynthesis_ivas(ptr_re, ptr_im, &(pPcm_temp[ch][hMCParamUpmix->num_freq_bands * slot_idx]), - hMCParamUpmix->num_freq_bands, st_ivas->cldfbSynDec[ch]); - } - } - /* adjust delay of other channels */ - noparamupmix_delay = NS2SA(st_ivas->hDecoderConfig->output_Fs, IVAS_FB_DEC_DELAY_NS); - n_samples_rendered = st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered] * hMCParamUpmix->num_freq_bands; - if (n_samples_rendered > noparamupmix_delay) - { - for (ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS; ch++) - { - float tmp_buf[L_SUBFRAME5MS_48k]; - mvr2r(&output_f[ch][n_samples_rendered - noparamupmix_delay], tmp_buf, noparamupmix_delay); - mvr2r(output_f[ch], &output_f[ch][noparamupmix_delay], n_samples_rendered - noparamupmix_delay); - mvr2r(hMCParamUpmix->pcm_delay[ch], output_f[ch], noparamupmix_delay); - mvr2r(tmp_buf, hMCParamUpmix->pcm_delay[ch], noparamupmix_delay); - } } else { - for (ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS; ch++) - { - float tmp_buf[L_SUBFRAME5MS_48k]; - mvr2r(&output_f[ch][0], tmp_buf, n_samples_rendered); - mvr2r(hMCParamUpmix->pcm_delay[ch], output_f[ch], n_samples_rendered); - mvr2r(&hMCParamUpmix->pcm_delay[ch][n_samples_rendered], &hMCParamUpmix->pcm_delay[ch][0], noparamupmix_delay - n_samples_rendered); - mvr2r(tmp_buf, &hMCParamUpmix->pcm_delay[ch][noparamupmix_delay - n_samples_rendered], n_samples_rendered); - } + /* boxes = { 0 1 2 3 [4 6] [5 7] [8 10] [9 11] }; */ + pPcm_temp[0] = output_f[4]; + pPcm_temp[1] = output_f[6]; + pPcm_temp[2] = output_f[5]; + pPcm_temp[3] = output_f[7]; + pPcm_temp[4] = output_f[8]; + pPcm_temp[5] = output_f[10]; + pPcm_temp[6] = output_f[9]; + pPcm_temp[7] = output_f[11]; + + /* CLDFB synthesis */ + for ( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS * 2; ch++ ) + { + for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ ) + { + float *ptr_im[1], *ptr_re[1]; + ptr_re[0] = Cldfb_RealBuffer[ch][slot_idx]; + ptr_im[0] = Cldfb_ImagBuffer[ch][slot_idx]; + + cldfbSynthesis_ivas( ptr_re, ptr_im, &( pPcm_temp[ch][hMCParamUpmix->num_freq_bands * slot_idx] ), + hMCParamUpmix->num_freq_bands, st_ivas->cldfbSynDec[ch] ); + } + } + /* adjust delay of other channels */ + noparamupmix_delay = NS2SA( st_ivas->hDecoderConfig->output_Fs, IVAS_FB_DEC_DELAY_NS ); + n_samples_rendered = st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered] * hMCParamUpmix->num_freq_bands; + if ( n_samples_rendered > noparamupmix_delay ) + { + for ( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS; ch++ ) + { + float tmp_buf[L_SUBFRAME5MS_48k]; + mvr2r( &output_f[ch][n_samples_rendered - noparamupmix_delay], tmp_buf, noparamupmix_delay ); + mvr2r( output_f[ch], &output_f[ch][noparamupmix_delay], n_samples_rendered - noparamupmix_delay ); + mvr2r( hMCParamUpmix->pcm_delay[ch], output_f[ch], noparamupmix_delay ); + mvr2r( tmp_buf, hMCParamUpmix->pcm_delay[ch], noparamupmix_delay ); + } + } + else + { + for ( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS; ch++ ) + { + float tmp_buf[L_SUBFRAME5MS_48k]; + mvr2r( &output_f[ch][0], tmp_buf, n_samples_rendered ); + mvr2r( hMCParamUpmix->pcm_delay[ch], output_f[ch], n_samples_rendered ); + mvr2r( &hMCParamUpmix->pcm_delay[ch][n_samples_rendered], &hMCParamUpmix->pcm_delay[ch][0], noparamupmix_delay - n_samples_rendered ); + mvr2r( tmp_buf, &hMCParamUpmix->pcm_delay[ch][noparamupmix_delay - n_samples_rendered], n_samples_rendered ); + } + } } - } - st_ivas->hTcBuffer->slots_rendered += st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; - st_ivas->hTcBuffer->subframes_rendered++; + st_ivas->hTcBuffer->slots_rendered += st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; + st_ivas->hTcBuffer->subframes_rendered++; - pop_wmops(); - return; + pop_wmops(); + return; } static int16_t huff_read( - Decoder_State *st, - const int16_t(*ht)[2]) + Decoder_State *st, + const int16_t ( *ht )[2] ) { - int16_t node = 0; - uint16_t next_bit = 0; + int16_t node = 0; + uint16_t next_bit = 0; - do - { - next_bit = st->bit_stream[st->next_bit_pos]; - st->next_bit_pos++; - node = ht[node][next_bit]; - } while (node > 0); + do + { + next_bit = st->bit_stream[st->next_bit_pos]; + st->next_bit_pos++; + node = ht[node][next_bit]; + } while ( node > 0 ); - return -(node + 1); + return -( node + 1 ); } static void huffman_decode( - Decoder_State *st, - const PAR_TYPE parType, - int32_t *vq) + Decoder_State *st, + const PAR_TYPE parType, + int32_t *vq ) { - const int16_t(*huff_node_table)[2]; - int16_t iv, nquant, offset; - - nquant = 0; - switch (parType) - { - case ALPHA: - nquant = ivas_mc_paramupmix_alpha_quant_table.nquant; - break; - case BETA: - nquant = ivas_mc_paramupmix_beta_quant_table[0].nquant; - break; - default: - assert(0); - } - - offset = nquant - 1; /* range of df [-(nquant - 1), nquant - 1] */ - - st->next_bit_pos++; - switch (parType) - { - case ALPHA: - huff_node_table = ivas_mc_paramupmix_huff_nodes_df0.alpha; - break; - case BETA: - huff_node_table = ivas_mc_paramupmix_huff_nodes_df0.beta; - break; - default: - huff_node_table = NULL; - assert(0); - } - vq[0] = huff_read(st, huff_node_table); - - switch (parType) - { - case ALPHA: - huff_node_table = ivas_mc_paramupmix_huff_nodes_df.alpha; - break; - case BETA: - huff_node_table = ivas_mc_paramupmix_huff_nodes_df.beta; - break; - default: - assert(0); - } - - for (iv = 1; iv < IVAS_MAX_NUM_BANDS; iv++) - { - vq[iv] = huff_read(st, huff_node_table) + vq[iv - 1] - offset; - } - - return; + const int16_t( *huff_node_table )[2]; + int16_t iv, nquant, offset; + + nquant = 0; + switch ( parType ) + { + case ALPHA: + nquant = ivas_mc_paramupmix_alpha_quant_table.nquant; + break; + case BETA: + nquant = ivas_mc_paramupmix_beta_quant_table[0].nquant; + break; + default: + assert( 0 ); + } + + offset = nquant - 1; /* range of df [-(nquant - 1), nquant - 1] */ + + st->next_bit_pos++; + switch ( parType ) + { + case ALPHA: + huff_node_table = ivas_mc_paramupmix_huff_nodes_df0.alpha; + break; + case BETA: + huff_node_table = ivas_mc_paramupmix_huff_nodes_df0.beta; + break; + default: + huff_node_table = NULL; + assert( 0 ); + } + vq[0] = huff_read( st, huff_node_table ); + + switch ( parType ) + { + case ALPHA: + huff_node_table = ivas_mc_paramupmix_huff_nodes_df.alpha; + break; + case BETA: + huff_node_table = ivas_mc_paramupmix_huff_nodes_df.beta; + break; + default: + assert( 0 ); + } + + for ( iv = 1; iv < IVAS_MAX_NUM_BANDS; iv++ ) + { + vq[iv] = huff_read( st, huff_node_table ) + vq[iv - 1] - offset; + } + + return; } static void dequant_alpha( - int32_t *vq, - float *v) + int32_t *vq, + float *v ) { - int16_t iv; - const ACPL_QUANT_TABLE *quant_table = &ivas_mc_paramupmix_alpha_quant_table; + int16_t iv; + const ACPL_QUANT_TABLE *quant_table = &ivas_mc_paramupmix_alpha_quant_table; - for (iv = 0; iv < IVAS_MAX_NUM_BANDS; iv++) - { - v[iv] = quant_table->data[vq[iv]]; - } + for ( iv = 0; iv < IVAS_MAX_NUM_BANDS; iv++ ) + { + v[iv] = quant_table->data[vq[iv]]; + } - return; + return; } static void dequant_beta( - int32_t *aq, - int32_t *bq, - float *beta) + int32_t *aq, + int32_t *bq, + float *beta ) { - int16_t iv; - const ACPL_QUANT_TABLE *quant_table; + int16_t iv; + const ACPL_QUANT_TABLE *quant_table; - for (iv = 0; iv < IVAS_MAX_NUM_BANDS; iv++) - { - quant_table = &ivas_mc_paramupmix_beta_quant_table[ivas_param_upmx_mx_qmap[aq[iv]]]; - beta[iv] = quant_table->data[bq[iv]]; - } + for ( iv = 0; iv < IVAS_MAX_NUM_BANDS; iv++ ) + { + quant_table = &ivas_mc_paramupmix_beta_quant_table[ivas_param_upmx_mx_qmap[aq[iv]]]; + beta[iv] = quant_table->data[bq[iv]]; + } - return; + return; } static void get_ec_data( - Decoder_State *st, - const PAR_TYPE parType, - int32_t *parQ, - int32_t *alphaQEnv, - float ab[IVAS_MAX_NUM_BANDS]) + Decoder_State *st, + const PAR_TYPE parType, + int32_t *parQ, + int32_t *alphaQEnv, + float ab[IVAS_MAX_NUM_BANDS] ) { - huffman_decode(st, parType, parQ); - - if (parType == ALPHA) - { - dequant_alpha(parQ, ab); - mvl2l(parQ, alphaQEnv, (int16_t)IVAS_MAX_NUM_BANDS); - } - else - { - dequant_beta(alphaQEnv, parQ, ab); - } - - return; + huffman_decode( st, parType, parQ ); + + if ( parType == ALPHA ) + { + dequant_alpha( parQ, ab ); + mvl2l( parQ, alphaQEnv, (int16_t) IVAS_MAX_NUM_BANDS ); + } + else + { + dequant_beta( alphaQEnv, parQ, ab ); + } + + return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/ivas_mcmasa_dec.c b/lib_dec/ivas_mcmasa_dec.c index f169d7e55..c010fb175 100644 --- a/lib_dec/ivas_mcmasa_dec.c +++ b/lib_dec/ivas_mcmasa_dec.c @@ -69,25 +69,25 @@ ivas_error ivas_mcmasa_dec_reconfig( ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config ); ivas_mcmasa_set_separate_channel_mode_fx( &( st_ivas->hIntSetup.separateChannelEnabled ), &( st_ivas->hIntSetup.separateChannelIndex ), ivas_total_brate ); - IF ( ( error = ivas_masa_dec_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_masa_dec_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } st_ivas->sba_dirac_stereo_flag = ivas_get_sba_dirac_stereo_flag( st_ivas ); - IF ( NE_16(st_ivas->renderer_type , RENDERER_DISABLE) && NE_16(st_ivas->renderer_type , RENDERER_MCMASA_MONO_STEREO) ) + IF( NE_16( st_ivas->renderer_type, RENDERER_DISABLE ) && NE_16( st_ivas->renderer_type, RENDERER_MCMASA_MONO_STEREO ) ) { - IF ( st_ivas->hDirAC == NULL ) + IF( st_ivas->hDirAC == NULL ) { - IF ( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK ) { return error; } } ELSE { - IF ( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_RECONFIGURE ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_RECONFIGURE ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_dec/ivas_mct_core_dec.c b/lib_dec/ivas_mct_core_dec.c index cc2281d50..b703aaaef 100644 --- a/lib_dec/ivas_mct_core_dec.c +++ b/lib_dec/ivas_mct_core_dec.c @@ -157,12 +157,12 @@ void ivas_mct_side_bits( void ivas_mct_side_bits_fx( MCT_DEC_HANDLE hMCT, /* i/o: MCT decoder structure */ CPE_DEC_HANDLE hCPE[MCT_MAX_BLOCKS], /* i/o: CPE decoder structure */ - const Word16 nCPE, /* i : number of CPEs */ + const Word16 nCPE, /* i : number of CPEs */ Decoder_State *st0, /* i : decoder handle for Bstr */ - const Word16 bfi, /* i : BFI flag */ - UWord16 *bitstream, /* o : bitstream indices */ - const Word32 ivas_total_brate, /* i : IVAS total bitrate */ - const Word16 nb_bits_metadata /* i : number of metadata bits */ + const Word16 bfi, /* i : BFI flag */ + UWord16 *bitstream, /* o : bitstream indices */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + const Word16 nb_bits_metadata /* i : number of metadata bits */ ) { Word16 ch, cpe_id, nChannels, i, k, nSubframes; @@ -174,23 +174,23 @@ void ivas_mct_side_bits_fx( nChannels = hMCT->nchan_out_woLFE; /*initializations */ - FOR ( (cpe_id = 0, i = 0); cpe_id < nCPE; cpe_id++ ) + FOR( ( cpe_id = 0, i = 0 ); cpe_id < nCPE; cpe_id++ ) { - FOR ( ch = 0; ch < CPE_CHANNELS; ch++ ) + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { sts[i] = hCPE[cpe_id]->hCoreCoder[ch]; - i = add(i, 1); + i = add( i, 1 ); move16(); } } /*first read IFG bits */ - IF ( !bfi && st0->igf ) + IF( !bfi && st0->igf ) { - FOR ( ch = 0; ch < nChannels; ch++ ) + FOR( ch = 0; ch < nChannels; ch++ ) { st = sts[ch]; - IF ( st->mct_chan_mode == MCT_CHAN_MODE_IGNORE ) + IF( st->mct_chan_mode == MCT_CHAN_MODE_IGNORE ) { continue; } @@ -200,23 +200,23 @@ void ivas_mct_side_bits_fx( } /*read MCT data and calculate frame bits per channel */ - FOR ( ch = 0; ch < (Word16) ( hMCT->nchan_out_woLFE * 0.5 ); ch++ ) + FOR( ch = 0; ch < (Word16) ( hMCT->nchan_out_woLFE * 0.5 ); ch++ ) { initMdctStereoDecData_fx( hMCT->hBlockData[ch]->hStereoMdct, st0->igf, st0->hIGFDec->igfData.igfInfo.grid, hCPE[0]->element_brate, st0->bwidth ); } - IF ( !bfi ) + IF( !bfi ) { availableBits = 0; ivas_mct_dec_mct_fx( hMCT, sts, nChannels ); /*read channel bitrate ratios from bitstream*/ - FOR ( ch = 0; ch < nChannels; ch++ ) + FOR( ch = 0; ch < nChannels; ch++ ) { st = sts[ch]; - IF ( st->mct_chan_mode == MCT_CHAN_MODE_IGNORE ) + IF( st->mct_chan_mode == MCT_CHAN_MODE_IGNORE ) { chBitRatios[ch] = 0; st->bits_frame_channel = 0; @@ -226,7 +226,7 @@ void ivas_mct_side_bits_fx( nSubframes = ( st->core == TCX_10_CORE ) ? NB_DIV : 1; - FOR ( k = 0; k < nSubframes; k++ ) + FOR( k = 0; k < nSubframes; k++ ) { nf_side_bits += ( NBITS_TCX_GAIN + NOISE_FILL_RANGES * NBITS_NOISE_FILL_LEVEL ); } @@ -238,11 +238,11 @@ void ivas_mct_side_bits_fx( splitAvailableBitsMCT( (void **) sts, availableBits, chBitRatios, DEC, nChannels ); next_bit_pos = sts[0]->next_bit_pos; - FOR ( ch = 1; ch < nChannels; ch++ ) + FOR( ch = 1; ch < nChannels; ch++ ) { nf_bits = ( sts[ch - 1]->core == TCX_20_CORE ? 1 : NB_DIV ) * ( NBITS_TCX_GAIN + NOISE_FILL_RANGES * NBITS_NOISE_FILL_LEVEL ); - IF ( chBitRatios[ch - 1] == 0 ) /* indicates LFE with no content */ + IF( chBitRatios[ch - 1] == 0 ) /* indicates LFE with no content */ { nf_bits = 0; } @@ -501,4 +501,4 @@ void ivas_mct_core_dec( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index eac88cf6d..31976aae0 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -68,233 +68,232 @@ static ivas_error ivas_mc_dec_reconfig( Decoder_Struct *st_ivas, uint16_t *nSamp #ifndef IVAS_FLOAT_FIXED ivas_error ivas_mct_dec( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - float *output[], /* o : output synthesis signal */ - const int16_t output_frame, /* i : output frame length per channel */ - const int16_t nb_bits_metadata /* i : number of metadata bits */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + float *output[], /* o : output synthesis signal */ + const int16_t output_frame, /* i : output frame length per channel */ + const int16_t nb_bits_metadata /* i : number of metadata bits */ ) { - int16_t n, nCPE, cpe_id; - MCT_DEC_HANDLE hMCT; - CPE_DEC_HANDLE hCPE; - float *x[CPE_CHANNELS][NB_DIV]; - int16_t param[MCT_MAX_BLOCKS][CPE_CHANNELS][DEC_NPRM_DIV * NB_DIV]; - int16_t param_lpc[MCT_MAX_BLOCKS][CPE_CHANNELS][NPRM_LPC_NEW]; - int16_t p_param[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; - int16_t nTnsBitsTCX10[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; - float Aq[MCT_MAX_BLOCKS][CPE_CHANNELS][(NB_SUBFR16k + 1) * (M + 1)]; - int16_t fUseTns[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; - STnsData tnsData[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; - Decoder_State **sts; - float synth[CPE_CHANNELS][L_FRAME_PLUS]; - float output_lfe_ch[L_FRAME48k]; - int32_t ivas_total_brate; - ivas_error error; - - push_wmops("ivas_mct_dec"); - - error = IVAS_ERR_OK; - nCPE = st_ivas->nCPE; - hMCT = st_ivas->hMCT; - - ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; + int16_t n, nCPE, cpe_id; + MCT_DEC_HANDLE hMCT; + CPE_DEC_HANDLE hCPE; + float *x[CPE_CHANNELS][NB_DIV]; + int16_t param[MCT_MAX_BLOCKS][CPE_CHANNELS][DEC_NPRM_DIV * NB_DIV]; + int16_t param_lpc[MCT_MAX_BLOCKS][CPE_CHANNELS][NPRM_LPC_NEW]; + int16_t p_param[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; + int16_t nTnsBitsTCX10[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; + float Aq[MCT_MAX_BLOCKS][CPE_CHANNELS][( NB_SUBFR16k + 1 ) * ( M + 1 )]; + int16_t fUseTns[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; + STnsData tnsData[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; + Decoder_State **sts; + float synth[CPE_CHANNELS][L_FRAME_PLUS]; + float output_lfe_ch[L_FRAME48k]; + int32_t ivas_total_brate; + ivas_error error; - if (st_ivas->ivas_format == MC_FORMAT && (st_ivas->mc_mode == MC_MODE_MCT || st_ivas->mc_mode == MC_MODE_PARAMUPMIX)) - { - /* save LFE channel */ - mvr2r(output[LFE_CHANNEL], output_lfe_ch, output_frame); - } + push_wmops( "ivas_mct_dec" ); - if (st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCT && !st_ivas->bfi) - { - /* get the number of channels from the signalled MC LS setup */ - n = ivas_mc_ls_setup_get_num_channels(ivas_mc_map_output_config_to_mc_ls_setup(st_ivas->transport_config)); + error = IVAS_ERR_OK; + nCPE = st_ivas->nCPE; + hMCT = st_ivas->hMCT; - if (n != st_ivas->nchan_transport) - { - /* IVAS_fmToDo: more work needed for switching the number of transport channels */ - return IVAS_ERROR(IVAS_ERR_INTERNAL_FATAL, "Error: wrong number of transport channels signalled in MC format!"); - } - } + ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; - for (cpe_id = 0; cpe_id < nCPE; cpe_id++) - { - /*initialize param_lpc buffer*/ - for (n = 0; n < CPE_CHANNELS; n++) + if ( st_ivas->ivas_format == MC_FORMAT && ( st_ivas->mc_mode == MC_MODE_MCT || st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) ) { - set_s(param_lpc[cpe_id][n], 0, NPRM_LPC_NEW); + /* save LFE channel */ + mvr2r( output[LFE_CHANNEL], output_lfe_ch, output_frame ); } - if ((error = ivas_cpe_dec(st_ivas, cpe_id, output, output_frame, 0)) != IVAS_ERR_OK) + if ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCT && !st_ivas->bfi ) { - return error; - } + /* get the number of channels from the signalled MC LS setup */ + n = ivas_mc_ls_setup_get_num_channels( ivas_mc_map_output_config_to_mc_ls_setup( st_ivas->transport_config ) ); - if (cpe_id == 0) - { - st_ivas->hCPE[0]->hCoreCoder[0]->total_brate = ivas_total_brate; /* set high enough to read the whole side-info; total_brate is rewritten later in ivas_mdct_core_invQ() */ + if ( n != st_ivas->nchan_transport ) + { + /* IVAS_fmToDo: more work needed for switching the number of transport channels */ + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error: wrong number of transport channels signalled in MC format!" ); + } } - if (!st_ivas->bfi) + for ( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) { - ivas_mdct_dec_side_bits_frame_channel(st_ivas->hCPE[cpe_id], param_lpc[cpe_id], p_param[cpe_id], st_ivas->hCPE[0]->hCoreCoder[0], nTnsBitsTCX10[cpe_id], param[cpe_id], 1, - ((cpe_id + 1) * CPE_CHANNELS > hMCT->nchan_out_woLFE)); + /*initialize param_lpc buffer*/ + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + set_s( param_lpc[cpe_id][n], 0, NPRM_LPC_NEW ); + } - st_ivas->BER_detect |= st_ivas->hCPE[cpe_id]->hCoreCoder[0]->BER_detect; - st_ivas->BER_detect |= st_ivas->hCPE[cpe_id]->hCoreCoder[1]->BER_detect; - } - } + if ( ( error = ivas_cpe_dec( st_ivas, cpe_id, output, output_frame, 0 ) ) != IVAS_ERR_OK ) + { + return error; + } - /* MCT side bits decoder */ - ivas_mct_side_bits(hMCT, st_ivas->hCPE, nCPE, st_ivas->hCPE[0]->hCoreCoder[0], st_ivas->bfi, st_ivas->hCPE[0]->hCoreCoder[0]->bit_stream, ivas_total_brate, nb_bits_metadata); + if ( cpe_id == 0 ) + { + st_ivas->hCPE[0]->hCoreCoder[0]->total_brate = ivas_total_brate; /* set high enough to read the whole side-info; total_brate is rewritten later in ivas_mdct_core_invQ() */ + } - for (cpe_id = 0; cpe_id < nCPE; cpe_id++) - { - st_ivas->hCPE[cpe_id]->hCoreCoder[0]->BER_detect |= st_ivas->BER_detect; - st_ivas->hCPE[cpe_id]->hCoreCoder[1]->BER_detect |= st_ivas->BER_detect; + if ( !st_ivas->bfi ) + { + ivas_mdct_dec_side_bits_frame_channel( st_ivas->hCPE[cpe_id], param_lpc[cpe_id], p_param[cpe_id], st_ivas->hCPE[0]->hCoreCoder[0], nTnsBitsTCX10[cpe_id], param[cpe_id], 1, + ( ( cpe_id + 1 ) * CPE_CHANNELS > hMCT->nchan_out_woLFE ) ); - for (n = 0; n < CPE_CHANNELS; n++) - { - x[n][0] = output[n + cpe_id * CPE_CHANNELS]; - x[n][1] = output[n + cpe_id * CPE_CHANNELS] + (L_FRAME48k / 2); - set_zero(x[n][0], L_FRAME48k / 2); - set_zero(x[n][1], L_FRAME48k / 2); + st_ivas->BER_detect |= st_ivas->hCPE[cpe_id]->hCoreCoder[0]->BER_detect; + st_ivas->BER_detect |= st_ivas->hCPE[cpe_id]->hCoreCoder[1]->BER_detect; + } } - ivas_mdct_core_invQ(st_ivas->hCPE[cpe_id], nTnsBitsTCX10[cpe_id], p_param[cpe_id], param_lpc[cpe_id], param[cpe_id], - fUseTns[cpe_id], tnsData[cpe_id], x, x, Aq[cpe_id], NULL, 1); + /* MCT side bits decoder */ + ivas_mct_side_bits( hMCT, st_ivas->hCPE, nCPE, st_ivas->hCPE[0]->hCoreCoder[0], st_ivas->bfi, st_ivas->hCPE[0]->hCoreCoder[0]->bit_stream, ivas_total_brate, nb_bits_metadata ); + + for ( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) + { + st_ivas->hCPE[cpe_id]->hCoreCoder[0]->BER_detect |= st_ivas->BER_detect; + st_ivas->hCPE[cpe_id]->hCoreCoder[1]->BER_detect |= st_ivas->BER_detect; - st_ivas->BER_detect |= st_ivas->hCPE[cpe_id]->hCoreCoder[0]->BER_detect; - st_ivas->BER_detect |= st_ivas->hCPE[cpe_id]->hCoreCoder[1]->BER_detect; - } + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + x[n][0] = output[n + cpe_id * CPE_CHANNELS]; + x[n][1] = output[n + cpe_id * CPE_CHANNELS] + ( L_FRAME48k / 2 ); + set_zero( x[n][0], L_FRAME48k / 2 ); + set_zero( x[n][1], L_FRAME48k / 2 ); + } - /* MCT core decoder */ - ivas_mct_core_dec(hMCT, st_ivas->hCPE, nCPE, output); + ivas_mdct_core_invQ( st_ivas->hCPE[cpe_id], nTnsBitsTCX10[cpe_id], p_param[cpe_id], param_lpc[cpe_id], param[cpe_id], + fUseTns[cpe_id], tnsData[cpe_id], x, x, Aq[cpe_id], NULL, 1 ); - /* for sba to stereo output disable any further processing for TCs > 2 as it is not needed*/ - if (st_ivas->sba_dirac_stereo_flag && st_ivas->ivas_format != SBA_ISM_FORMAT) - { - for (cpe_id = 1; cpe_id < nCPE; cpe_id++) - { - for (n = 0; n < CPE_CHANNELS; n++) - { - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_IGNORE; - } + st_ivas->BER_detect |= st_ivas->hCPE[cpe_id]->hCoreCoder[0]->BER_detect; + st_ivas->BER_detect |= st_ivas->hCPE[cpe_id]->hCoreCoder[1]->BER_detect; } - } - /* MCT reconstruction and CoreCoder updates */ - for (cpe_id = 0; cpe_id < nCPE; cpe_id++) - { - hCPE = st_ivas->hCPE[cpe_id]; + /* MCT core decoder */ + ivas_mct_core_dec( hMCT, st_ivas->hCPE, nCPE, output ); - for (n = 0; n < CPE_CHANNELS; n++) + /* for sba to stereo output disable any further processing for TCs > 2 as it is not needed*/ + if ( st_ivas->sba_dirac_stereo_flag && st_ivas->ivas_format != SBA_ISM_FORMAT ) { - x[n][0] = output[n + cpe_id * CPE_CHANNELS]; - x[n][1] = output[n + cpe_id * CPE_CHANNELS] + (L_FRAME48k / 2); + for ( cpe_id = 1; cpe_id < nCPE; cpe_id++ ) + { + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_IGNORE; + } + } } - ivas_mdct_core_tns_ns(hCPE, fUseTns[cpe_id], tnsData[cpe_id], x, Aq[cpe_id], 1); - } + /* MCT reconstruction and CoreCoder updates */ + for ( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) + { + hCPE = st_ivas->hCPE[cpe_id]; - if (st_ivas->renderer_type == RENDERER_MC) - { - /* Equalization in MDCT Domain */ - ivas_ls_setup_conversion_process_mdct(st_ivas, output); - } + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + x[n][0] = output[n + cpe_id * CPE_CHANNELS]; + x[n][1] = output[n + cpe_id * CPE_CHANNELS] + ( L_FRAME48k / 2 ); + } - else if (st_ivas->renderer_type == RENDERER_MC_PARAMMC && (st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_MONO || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_STEREO)) - { - float *x_all[MAX_CICP_CHANNELS][NB_DIV]; + ivas_mdct_core_tns_ns( hCPE, fUseTns[cpe_id], tnsData[cpe_id], x, Aq[cpe_id], 1 ); + } - for (cpe_id = 0; cpe_id < nCPE; cpe_id++) + if ( st_ivas->renderer_type == RENDERER_MC ) { - for (n = 0; n < CPE_CHANNELS; n++) - { - x_all[n + cpe_id * CPE_CHANNELS][0] = output[n + cpe_id * CPE_CHANNELS]; - x_all[n + cpe_id * CPE_CHANNELS][1] = output[n + cpe_id * CPE_CHANNELS] + (L_FRAME48k / 2); - } + /* Equalization in MDCT Domain */ + ivas_ls_setup_conversion_process_mdct( st_ivas, output ); } - ivas_ls_setup_conversion_process_mdct_param_mc(st_ivas, x_all); - } + else if ( st_ivas->renderer_type == RENDERER_MC_PARAMMC && ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_MONO || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_STEREO ) ) + { + float *x_all[MAX_CICP_CHANNELS][NB_DIV]; - for (cpe_id = 0; cpe_id < nCPE; cpe_id++) - { - hCPE = st_ivas->hCPE[cpe_id]; - sts = hCPE->hCoreCoder; + for ( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) + { + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + x_all[n + cpe_id * CPE_CHANNELS][0] = output[n + cpe_id * CPE_CHANNELS]; + x_all[n + cpe_id * CPE_CHANNELS][1] = output[n + cpe_id * CPE_CHANNELS] + ( L_FRAME48k / 2 ); + } + } - for (n = 0; n < CPE_CHANNELS; n++) - { - x[n][0] = output[n + cpe_id * CPE_CHANNELS]; - x[n][1] = output[n + cpe_id * CPE_CHANNELS] + (L_FRAME48k / 2); + ivas_ls_setup_conversion_process_mdct_param_mc( st_ivas, x_all ); } - ivas_mdct_core_reconstruct(hCPE, x, synth, fUseTns[cpe_id], 1); + for ( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) + { + hCPE = st_ivas->hCPE[cpe_id]; + sts = hCPE->hCoreCoder; - /*----------------------------------------------------------------* - * CoreCoder Post-processing and updates - *----------------------------------------------------------------*/ + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + x[n][0] = output[n + cpe_id * CPE_CHANNELS]; + x[n][1] = output[n + cpe_id * CPE_CHANNELS] + ( L_FRAME48k / 2 ); + } - for (n = 0; n < CPE_CHANNELS; n++) - { - if (st_ivas->sba_dirac_stereo_flag && (st_ivas->ivas_format != SBA_ISM_FORMAT || cpe_id >= nCPE - 2)) - { - ivas_post_proc(NULL, hCPE, n, synth[n], NULL, output_frame, 1); - } + ivas_mdct_core_reconstruct( hCPE, x, synth, fUseTns[cpe_id], 1 ); - /* Postprocessing for ACELP/MDCT core switching and synchronization */ - if ((error = core_switching_post_dec(sts[n], synth[n], output[cpe_id * CPE_CHANNELS + n], hCPE->output_mem[1], st_ivas->ivas_format, 0, output_frame, 0 /*core_switching_flag*/, (st_ivas->ivas_format != SBA_ISM_FORMAT || cpe_id >= nCPE - 2) ? st_ivas->sba_dirac_stereo_flag : 0, -1, hCPE->last_element_mode)) != IVAS_ERR_OK) - { - return error; - } + /*----------------------------------------------------------------* + * CoreCoder Post-processing and updates + *----------------------------------------------------------------*/ + + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + if ( st_ivas->sba_dirac_stereo_flag && ( st_ivas->ivas_format != SBA_ISM_FORMAT || cpe_id >= nCPE - 2 ) ) + { + ivas_post_proc( NULL, hCPE, n, synth[n], NULL, output_frame, 1 ); + } + + /* Postprocessing for ACELP/MDCT core switching and synchronization */ + if ( ( error = core_switching_post_dec( sts[n], synth[n], output[cpe_id * CPE_CHANNELS + n], hCPE->output_mem[1], st_ivas->ivas_format, 0, output_frame, 0 /*core_switching_flag*/, ( st_ivas->ivas_format != SBA_ISM_FORMAT || cpe_id >= nCPE - 2 ) ? st_ivas->sba_dirac_stereo_flag : 0, -1, hCPE->last_element_mode ) ) != IVAS_ERR_OK ) + { + return error; + } - /* final output of synthesis signal */ - mvr2r(synth[n], output[cpe_id * CPE_CHANNELS + n], output_frame); + /* final output of synthesis signal */ + mvr2r( synth[n], output[cpe_id * CPE_CHANNELS + n], output_frame ); - /* Save synthesis for HQ FEC */ - save_synthesis_hq_fec(sts[n], output[cpe_id * CPE_CHANNELS + n], output_frame, hCPE); + /* Save synthesis for HQ FEC */ + save_synthesis_hq_fec( sts[n], output[cpe_id * CPE_CHANNELS + n], output_frame, hCPE ); - /* CoreCoder common updates */ - updt_dec_common(sts[n], NORMAL_HQ_CORE, -1, output[cpe_id * CPE_CHANNELS + n]); + /* CoreCoder common updates */ + updt_dec_common( sts[n], NORMAL_HQ_CORE, -1, output[cpe_id * CPE_CHANNELS + n] ); - } /* n_channels loop */ + } /* n_channels loop */ - /* synthesis synchronization between stereo modes */ - if (!st_ivas->sba_dirac_stereo_flag || (st_ivas->ivas_format == SBA_ISM_FORMAT && cpe_id < nCPE - 2)) - { - synchro_synthesis(ivas_total_brate, hCPE, output + cpe_id * CPE_CHANNELS, output_frame, 0); + /* synthesis synchronization between stereo modes */ + if ( !st_ivas->sba_dirac_stereo_flag || ( st_ivas->ivas_format == SBA_ISM_FORMAT && cpe_id < nCPE - 2 ) ) + { + synchro_synthesis( ivas_total_brate, hCPE, output + cpe_id * CPE_CHANNELS, output_frame, 0 ); + } } - } + /* move channels after LFE to correct output for multi-channel MCT */ + if ( st_ivas->ivas_format == MC_FORMAT && ( st_ivas->mc_mode == MC_MODE_MCT || st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) ) + { + float tmp[L_FRAME48k]; - /* move channels after LFE to correct output for multi-channel MCT */ - if (st_ivas->ivas_format == MC_FORMAT && (st_ivas->mc_mode == MC_MODE_MCT || st_ivas->mc_mode == MC_MODE_PARAMUPMIX)) - { - float tmp[L_FRAME48k]; + /*save center channel output*/ + mvr2r( output[hMCT->nchan_out_woLFE - 1], tmp, output_frame ); - /*save center channel output*/ - mvr2r(output[hMCT->nchan_out_woLFE - 1], tmp, output_frame); + for ( n = hMCT->nchan_out_woLFE - 1; n >= LFE_CHANNEL; n-- ) + { + mvr2r( output[n - 1], output[n + 1], output_frame ); + } + mvr2r( tmp, output[LFE_CHANNEL - 1], output_frame ); - for (n = hMCT->nchan_out_woLFE - 1; n >= LFE_CHANNEL; n--) - { - mvr2r(output[n - 1], output[n + 1], output_frame); + /* save LFE channel */ + mvr2r( output_lfe_ch, output[LFE_CHANNEL], output_frame ); } - mvr2r(tmp, output[LFE_CHANNEL - 1], output_frame); - - /* save LFE channel */ - mvr2r(output_lfe_ch, output[LFE_CHANNEL], output_frame); - } - pop_wmops(); - return error; + pop_wmops(); + return error; } #else ivas_error ivas_mct_dec_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - Word32 *output_fx[], /* o : output synthesis signal */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Word32 *output_fx[], /* o : output synthesis signal */ const Word16 output_frame, /* i : output frame length per channel */ const Word16 nb_bits_metadata /* i : number of metadata bits */ ) @@ -331,28 +330,28 @@ ivas_error ivas_mct_dec_fx( ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; move32(); - IF ( EQ_16(st_ivas->ivas_format, MC_FORMAT) && ( EQ_16(st_ivas->mc_mode, MC_MODE_MCT) || EQ_16(st_ivas->mc_mode, MC_MODE_PARAMUPMIX) ) ) + IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) && ( EQ_16( st_ivas->mc_mode, MC_MODE_MCT ) || EQ_16( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) ) { /* save LFE channel */ mvl2l( output_fx[LFE_CHANNEL], output_lfe_ch_fx, output_frame ); } - IF ( EQ_16(st_ivas->ivas_format, MC_FORMAT) && EQ_16(st_ivas->mc_mode, MC_MODE_MCT) && EQ_16(st_ivas->bfi, 0) ) + IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) && EQ_16( st_ivas->mc_mode, MC_MODE_MCT ) && EQ_16( st_ivas->bfi, 0 ) ) { /* get the number of channels from the signalled MC LS setup */ n = ivas_mc_ls_setup_get_num_channels( ivas_mc_map_output_config_to_mc_ls_setup( st_ivas->transport_config ) ); - IF ( NE_16(n, st_ivas->nchan_transport) ) + IF( NE_16( n, st_ivas->nchan_transport ) ) { /* IVAS_fmToDo: more work needed for switching the number of transport channels */ return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error: wrong number of transport channels signalled in MC format!" ); } } - FOR ( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) + FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) { /*initialize param_lpc buffer*/ - FOR ( n = 0; n < CPE_CHANNELS; n++ ) + FOR( n = 0; n < CPE_CHANNELS; n++ ) { set_s( param_lpc[cpe_id][n], 0, NPRM_LPC_NEW ); } @@ -365,20 +364,20 @@ ivas_error ivas_mct_dec_fx( return error; } - IF ( EQ_16(cpe_id, 0) ) + IF( EQ_16( cpe_id, 0 ) ) { st_ivas->hCPE[0]->hCoreCoder[0]->total_brate = ivas_total_brate; /* set high enough to read the whole side-info; total_brate is rewritten later in ivas_mdct_core_invQ() */ move32(); } - IF ( EQ_16(st_ivas->bfi, 0) ) + IF( EQ_16( st_ivas->bfi, 0 ) ) { ivas_mdct_dec_side_bits_frame_channel_fx( st_ivas->hCPE[cpe_id], param_lpc[cpe_id], p_param[cpe_id], st_ivas->hCPE[0]->hCoreCoder[0], nTnsBitsTCX10[cpe_id], param[cpe_id], 1, - (Word16) GT_16( i_mult(add( cpe_id, 1 ), CPE_CHANNELS ), hMCT->nchan_out_woLFE ) ); + (Word16) GT_16( i_mult( add( cpe_id, 1 ), CPE_CHANNELS ), hMCT->nchan_out_woLFE ) ); - st_ivas->BER_detect = s_or(st_ivas->BER_detect, st_ivas->hCPE[cpe_id]->hCoreCoder[0]->BER_detect); + st_ivas->BER_detect = s_or( st_ivas->BER_detect, st_ivas->hCPE[cpe_id]->hCoreCoder[0]->BER_detect ); test(); - st_ivas->BER_detect = s_or(st_ivas->BER_detect, st_ivas->hCPE[cpe_id]->hCoreCoder[1]->BER_detect); + st_ivas->BER_detect = s_or( st_ivas->BER_detect, st_ivas->hCPE[cpe_id]->hCoreCoder[1]->BER_detect ); test(); } } @@ -386,14 +385,14 @@ ivas_error ivas_mct_dec_fx( /* MCT side bits decoder */ ivas_mct_side_bits_fx( hMCT, st_ivas->hCPE, nCPE, st_ivas->hCPE[0]->hCoreCoder[0], st_ivas->bfi, st_ivas->hCPE[0]->hCoreCoder[0]->bit_stream, ivas_total_brate, nb_bits_metadata ); - FOR ( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) + FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) { - st_ivas->hCPE[cpe_id]->hCoreCoder[0]->BER_detect = s_or(st_ivas->hCPE[cpe_id]->hCoreCoder[0]->BER_detect, st_ivas->BER_detect); + st_ivas->hCPE[cpe_id]->hCoreCoder[0]->BER_detect = s_or( st_ivas->hCPE[cpe_id]->hCoreCoder[0]->BER_detect, st_ivas->BER_detect ); test(); - st_ivas->hCPE[cpe_id]->hCoreCoder[1]->BER_detect = s_or(st_ivas->hCPE[cpe_id]->hCoreCoder[1]->BER_detect, st_ivas->BER_detect); + st_ivas->hCPE[cpe_id]->hCoreCoder[1]->BER_detect = s_or( st_ivas->hCPE[cpe_id]->hCoreCoder[1]->BER_detect, st_ivas->BER_detect ); test(); - FOR ( n = 0; n < CPE_CHANNELS; n++ ) + FOR( n = 0; n < CPE_CHANNELS; n++ ) { x_fx[n][0] = output_fx[n + cpe_id * CPE_CHANNELS]; x_e[n][0] = 20; @@ -401,52 +400,52 @@ ivas_error ivas_mct_dec_fx( x_e[n][1] = 20; move16(); move16(); - - set32_fx( x_fx[n][0], 0, shr(L_FRAME48k, 1) ); - set32_fx( x_fx[n][1], 0, shr(L_FRAME48k, 1) ); + + set32_fx( x_fx[n][0], 0, shr( L_FRAME48k, 1 ) ); + set32_fx( x_fx[n][1], 0, shr( L_FRAME48k, 1 ) ); } ivas_mdct_core_invQ_fx( st_ivas->hCPE[cpe_id], nTnsBitsTCX10[cpe_id], p_param[cpe_id], param_lpc[cpe_id], param[cpe_id], fUseTns[cpe_id], tnsData[cpe_id], x_fx, x_e, x_fx, x_e, x_len, Aq_fx[cpe_id], NULL, 1 ); - FOR(ch = 0; ch < CPE_CHANNELS; ch++) + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { - Word16 subFrames = (st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->core == TCX_10_CORE) ? NB_DIV : 1; - FOR(k = 0; k < subFrames; ++k) + Word16 subFrames = ( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->core == TCX_10_CORE ) ? NB_DIV : 1; + FOR( k = 0; k < subFrames; ++k ) { - Scale_sig32(x_fx[ch][k], shr(L_FRAME48k, subFrames - 1), sub(x_e[ch][k], 20)); + Scale_sig32( x_fx[ch][k], shr( L_FRAME48k, subFrames - 1 ), sub( x_e[ch][k], 20 ) ); } } - - st_ivas->BER_detect = s_or(st_ivas->BER_detect, st_ivas->hCPE[cpe_id]->hCoreCoder[0]->BER_detect); + + st_ivas->BER_detect = s_or( st_ivas->BER_detect, st_ivas->hCPE[cpe_id]->hCoreCoder[0]->BER_detect ); test(); - st_ivas->BER_detect = s_or(st_ivas->BER_detect, st_ivas->hCPE[cpe_id]->hCoreCoder[1]->BER_detect); + st_ivas->BER_detect = s_or( st_ivas->BER_detect, st_ivas->hCPE[cpe_id]->hCoreCoder[1]->BER_detect ); test(); } /* MCT core decoder */ Word16 q_x[MAX_TRANSPORT_CHANNELS]; - set16_fx(q_x, Q12, MAX_TRANSPORT_CHANNELS); + set16_fx( q_x, Q12, MAX_TRANSPORT_CHANNELS ); // Scaling output buffer to q_x - FOR ( i = 0; i < hMCT->nchan_out_woLFE; ++i) + FOR( i = 0; i < hMCT->nchan_out_woLFE; ++i ) { - Scale_sig32(output_fx[i], L_FRAME48k, sub(q_x[i], Q11) ); + Scale_sig32( output_fx[i], L_FRAME48k, sub( q_x[i], Q11 ) ); } - ivas_mct_core_dec(hMCT, st_ivas->hCPE, nCPE, output_fx, q_x); + ivas_mct_core_dec( hMCT, st_ivas->hCPE, nCPE, output_fx, q_x ); // Scaling output buffer back to Q11 - FOR ( i = 0; i < hMCT->nchan_out_woLFE; ++i) + FOR( i = 0; i < hMCT->nchan_out_woLFE; ++i ) { - Scale_sig32(output_fx[i], L_FRAME48k, sub(Q11, q_x[i]) ); + Scale_sig32( output_fx[i], L_FRAME48k, sub( Q11, q_x[i] ) ); } - + /* for sba to stereo output disable any further processing for TCs > 2 as it is not needed*/ - IF ( NE_16(st_ivas->sba_dirac_stereo_flag, 0) && NE_16(st_ivas->ivas_format, SBA_ISM_FORMAT) ) + IF( NE_16( st_ivas->sba_dirac_stereo_flag, 0 ) && NE_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { - FOR ( cpe_id = 1; cpe_id < nCPE; cpe_id++ ) + FOR( cpe_id = 1; cpe_id < nCPE; cpe_id++ ) { - FOR ( n = 0; n < CPE_CHANNELS; n++ ) + FOR( n = 0; n < CPE_CHANNELS; n++ ) { st_ivas->hCPE[cpe_id]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_IGNORE; } @@ -455,49 +454,50 @@ ivas_error ivas_mct_dec_fx( Word32 Aq_fx_32[6][2][102]; /* MCT reconstruction and CoreCoder updates */ - FOR(cpe_id = 0; cpe_id < nCPE; cpe_id++) + FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) { hCPE = st_ivas->hCPE[cpe_id]; - FOR(n = 0; n < CPE_CHANNELS; n++) + FOR( n = 0; n < CPE_CHANNELS; n++ ) { - Copy_Scale_sig_16_32(Aq_fx[cpe_id][n], Aq_fx_32[cpe_id][n], 102, sub(Q16, Q12)); + Copy_Scale_sig_16_32( Aq_fx[cpe_id][n], Aq_fx_32[cpe_id][n], 102, sub( Q16, Q12 ) ); x_fx[n][0] = output_fx[n + cpe_id * CPE_CHANNELS]; - x_fx[n][1] = output_fx[n + cpe_id * CPE_CHANNELS] + (L_FRAME48k / 2); + x_fx[n][1] = output_fx[n + cpe_id * CPE_CHANNELS] + ( L_FRAME48k / 2 ); x_e[n][0] = 20; move16(); x_e[n][1] = 20; move16(); } - ivas_mdct_core_tns_ns_fx(hCPE, fUseTns[cpe_id], tnsData[cpe_id], x_fx, Aq_fx_32[cpe_id], 1, x_e); + ivas_mdct_core_tns_ns_fx( hCPE, fUseTns[cpe_id], tnsData[cpe_id], x_fx, Aq_fx_32[cpe_id], 1, x_e ); - FOR(Word16 ind = 0; ind < 2; ind++) + FOR( Word16 ind = 0; ind < 2; ind++ ) { - Word16 nSubFrames = EQ_16(hCPE->hCoreCoder[ind]->core, TCX_20_CORE) ? 1 : NB_DIV; - Scale_sig32(x_fx[ind][0], shr(L_FRAME48k, sub(nSubFrames, 1)), sub(x_e[ind][0], 20)); - IF(nSubFrames == 2) { - Scale_sig32(x_fx[ind][1], shr(L_FRAME48k, 1), sub(x_e[ind][1], 20)); + Word16 nSubFrames = EQ_16( hCPE->hCoreCoder[ind]->core, TCX_20_CORE ) ? 1 : NB_DIV; + Scale_sig32( x_fx[ind][0], shr( L_FRAME48k, sub( nSubFrames, 1 ) ), sub( x_e[ind][0], 20 ) ); + IF( nSubFrames == 2 ) + { + Scale_sig32( x_fx[ind][1], shr( L_FRAME48k, 1 ), sub( x_e[ind][1], 20 ) ); } } } - IF ( EQ_16(st_ivas->renderer_type, RENDERER_MC) ) + IF( EQ_16( st_ivas->renderer_type, RENDERER_MC ) ) { /* Equalization in MDCT Domain */ - ivas_ls_setup_conversion_process_mdct_fx( st_ivas, output_fx); + ivas_ls_setup_conversion_process_mdct_fx( st_ivas, output_fx ); } - ELSE IF(EQ_16(st_ivas->renderer_type, RENDERER_MC_PARAMMC) && (EQ_16(st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO) || EQ_16(st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO))) + ELSE IF( EQ_16( st_ivas->renderer_type, RENDERER_MC_PARAMMC ) && ( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) ) ) { Word16 x_all_e[MAX_CICP_CHANNELS][NB_DIV] = { 0 }; Word32 *x_all_fx[MAX_CICP_CHANNELS][NB_DIV]; - FOR(cpe_id = 0; cpe_id < nCPE; cpe_id++) + FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) { - FOR(n = 0; n < CPE_CHANNELS; n++) + FOR( n = 0; n < CPE_CHANNELS; n++ ) { x_all_fx[n + cpe_id * CPE_CHANNELS][0] = output_fx[n + cpe_id * CPE_CHANNELS]; - x_all_fx[n + cpe_id * CPE_CHANNELS][1] = output_fx[n + cpe_id * CPE_CHANNELS] + (L_FRAME48k / 2); + x_all_fx[n + cpe_id * CPE_CHANNELS][1] = output_fx[n + cpe_id * CPE_CHANNELS] + ( L_FRAME48k / 2 ); x_all_e[n + cpe_id * CPE_CHANNELS][1] = 20; move16(); x_all_e[n + cpe_id * CPE_CHANNELS][0] = 20; @@ -505,146 +505,144 @@ ivas_error ivas_mct_dec_fx( } } - ivas_ls_setup_conversion_process_mdct_param_mc_fx(st_ivas, x_all_fx, x_all_e); + ivas_ls_setup_conversion_process_mdct_param_mc_fx( st_ivas, x_all_fx, x_all_e ); - FOR(cpe_id = 0; cpe_id < nCPE; cpe_id++) + FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) { - FOR(n = 0; n < CPE_CHANNELS; n++) + FOR( n = 0; n < CPE_CHANNELS; n++ ) { - Scale_sig32(x_all_fx[n + cpe_id * CPE_CHANNELS][0], shr(L_FRAME48k, 1), sub(x_all_e[n + cpe_id * CPE_CHANNELS][0], 20)); - Scale_sig32(x_all_fx[n + cpe_id * CPE_CHANNELS][1], shr(L_FRAME48k, 1), sub(x_all_e[n + cpe_id * CPE_CHANNELS][1], 20)); + Scale_sig32( x_all_fx[n + cpe_id * CPE_CHANNELS][0], shr( L_FRAME48k, 1 ), sub( x_all_e[n + cpe_id * CPE_CHANNELS][0], 20 ) ); + Scale_sig32( x_all_fx[n + cpe_id * CPE_CHANNELS][1], shr( L_FRAME48k, 1 ), sub( x_all_e[n + cpe_id * CPE_CHANNELS][1], 20 ) ); } } - } - FOR ( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) + FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) { hCPE = st_ivas->hCPE[cpe_id]; sts = hCPE->hCoreCoder; - FOR ( n = 0; n < CPE_CHANNELS; n++ ) + FOR( n = 0; n < CPE_CHANNELS; n++ ) { x_fx[n][0] = output_fx[n + cpe_id * CPE_CHANNELS]; x_fx[n][1] = output_fx[n + cpe_id * CPE_CHANNELS] + ( L_FRAME48k / 2 ); } - FOR(n = 0; n < CPE_CHANNELS; n++) + FOR( n = 0; n < CPE_CHANNELS; n++ ) { - IF(NE_16(hCPE->hCoreCoder[n]->Q_syn, 0)) + IF( NE_16( hCPE->hCoreCoder[n]->Q_syn, 0 ) ) { - Scale_sig(hCPE->hCoreCoder[n]->hHQ_core->old_out_fx, L_FRAME48k, hCPE->hCoreCoder[n]->Q_syn); + Scale_sig( hCPE->hCoreCoder[n]->hHQ_core->old_out_fx, L_FRAME48k, hCPE->hCoreCoder[n]->Q_syn ); } if ( sts[n]->hTcxDec && sts[n]->hTcxDec->conCngLevelBackgroundTrace_e < 0 ) { sts[n]->hTcxDec->conCngLevelBackgroundTrace_e = 0; } } - - Copy_Scale_sig_16_32(hCPE->hCoreCoder[0]->old_Aq_12_8_fx, hCPE->hCoreCoder[0]->old_Aq_12_8_fx_32, M + 1, (28 - norm_s(hCPE->hCoreCoder[0]->old_Aq_12_8_fx[0] - 1))); - Copy_Scale_sig_16_32(hCPE->hCoreCoder[1]->old_Aq_12_8_fx, hCPE->hCoreCoder[1]->old_Aq_12_8_fx_32, M + 1, (28 - norm_s(hCPE->hCoreCoder[1]->old_Aq_12_8_fx[0] - 1))); + + Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->old_Aq_12_8_fx, hCPE->hCoreCoder[0]->old_Aq_12_8_fx_32, M + 1, ( 28 - norm_s( hCPE->hCoreCoder[0]->old_Aq_12_8_fx[0] - 1 ) ) ); + Copy_Scale_sig_16_32( hCPE->hCoreCoder[1]->old_Aq_12_8_fx, hCPE->hCoreCoder[1]->old_Aq_12_8_fx_32, M + 1, ( 28 - norm_s( hCPE->hCoreCoder[1]->old_Aq_12_8_fx[0] - 1 ) ) ); ivas_mdct_core_reconstruct_fx( hCPE, x_fx, synth_fx, fUseTns[cpe_id], 1, q_output, 15 ); - FOR(n = 0; n < CPE_CHANNELS; n++) + FOR( n = 0; n < CPE_CHANNELS; n++ ) { - IF(NE_16(hCPE->hCoreCoder[n]->Q_syn, 0)) + IF( NE_16( hCPE->hCoreCoder[n]->Q_syn, 0 ) ) { - Scale_sig(hCPE->hCoreCoder[n]->hHQ_core->old_out_fx, L_FRAME48k, negate(hCPE->hCoreCoder[n]->Q_syn)); + Scale_sig( hCPE->hCoreCoder[n]->hHQ_core->old_out_fx, L_FRAME48k, negate( hCPE->hCoreCoder[n]->Q_syn ) ); } - IF(hCPE->hCoreCoder[n]->hBPF) + IF( hCPE->hCoreCoder[n]->hBPF ) { - hCPE->hCoreCoder[n]->hBPF->pst_mem_deemp_err_fx = extract_l( L_shr( hCPE->hCoreCoder[n]->mem_error, sub(Q16, hCPE->hCoreCoder[n]->Q_syn2 - 1) ) ); - Scale_sig(hCPE->hCoreCoder[n]->hBPF->pst_old_syn_fx, NBPSF_PIT_MAX, hCPE->hCoreCoder[n]->Q_syn2 - 1); + hCPE->hCoreCoder[n]->hBPF->pst_mem_deemp_err_fx = extract_l( L_shr( hCPE->hCoreCoder[n]->mem_error, sub( Q16, hCPE->hCoreCoder[n]->Q_syn2 - 1 ) ) ); + Scale_sig( hCPE->hCoreCoder[n]->hBPF->pst_old_syn_fx, NBPSF_PIT_MAX, hCPE->hCoreCoder[n]->Q_syn2 - 1 ); } - IF(hCPE->hCoreCoder[n]->hTcxDec) + IF( hCPE->hCoreCoder[n]->hTcxDec ) { - //Scale_sig(hCPE->hCoreCoder[n]->hTcxDec->synth_history_fx, NS2SA(hCPE->hCoreCoder[n]->output_Fs, PH_ECU_MEM_NS), negate(hCPE->hCoreCoder[n]->Q_syn)); + // Scale_sig(hCPE->hCoreCoder[n]->hTcxDec->synth_history_fx, NS2SA(hCPE->hCoreCoder[n]->output_Fs, PH_ECU_MEM_NS), negate(hCPE->hCoreCoder[n]->Q_syn)); } - IF(hCPE->hCoreCoder[n]->hHQ_core) + IF( hCPE->hCoreCoder[n]->hHQ_core ) { - Scale_sig(hCPE->hCoreCoder[n]->hHQ_core->old_out_fx, L_FRAME48k, negate(hCPE->hCoreCoder[n]->Q_syn)); + Scale_sig( hCPE->hCoreCoder[n]->hHQ_core->old_out_fx, L_FRAME48k, negate( hCPE->hCoreCoder[n]->Q_syn ) ); } - } - + /*----------------------------------------------------------------* * CoreCoder Post-processing and updates *----------------------------------------------------------------*/ Word32 synth_fx_32[CPE_CHANNELS][L_FRAME48k]; - FOR ( n = 0; n < CPE_CHANNELS; n++ ) + FOR( n = 0; n < CPE_CHANNELS; n++ ) { - IF ( NE_16(st_ivas->sba_dirac_stereo_flag, 0) && ( NE_16(st_ivas->ivas_format, SBA_ISM_FORMAT) || GE_16(cpe_id, sub(nCPE, 2)) ) ) + IF( NE_16( st_ivas->sba_dirac_stereo_flag, 0 ) && ( NE_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) || GE_16( cpe_id, sub( nCPE, 2 ) ) ) ) { - Copy_Scale_sig_16_32(synth_fx[n], synth_fx_32[n], L_FRAME48k, sub(Q11, 0)); - Copy_Scale_sig_16_32(hCPE->hCoreCoder[n]->hHQ_core->old_out_fx, hCPE->hCoreCoder[n]->hHQ_core->oldOut_fx, output_frame, Q11); + Copy_Scale_sig_16_32( synth_fx[n], synth_fx_32[n], L_FRAME48k, sub( Q11, 0 ) ); + Copy_Scale_sig_16_32( hCPE->hCoreCoder[n]->hHQ_core->old_out_fx, hCPE->hCoreCoder[n]->hHQ_core->oldOut_fx, output_frame, Q11 ); ivas_post_proc_fx( NULL, hCPE, n, synth_fx_32[n], NULL, output_frame, 1 ); #ifdef MSAN_FIX - Copy_Scale_sig_32_16(synth_fx_32[n], synth_fx[n], output_frame, sub(0, Q11)); + Copy_Scale_sig_32_16( synth_fx_32[n], synth_fx[n], output_frame, sub( 0, Q11 ) ); #else - Copy_Scale_sig_32_16(synth_fx_32[n], synth_fx[n], L_FRAME48k, sub(0, Q11)); + Copy_Scale_sig_32_16( synth_fx_32[n], synth_fx[n], L_FRAME48k, sub( 0, Q11 ) ); #endif - } /* Postprocessing for ACELP/MDCT core switching and synchronization */ Word16 output_mem_fx[L_FRAME48k]; IF( hCPE->output_mem_fx[1] != NULL ) { - Copy_Scale_sig_32_16( hCPE->output_mem_fx[1], output_mem_fx, NS2SA( sts[n]->output_Fs, 3125000 ), sub(0, Q11) ); + Copy_Scale_sig_32_16( hCPE->output_mem_fx[1], output_mem_fx, NS2SA( sts[n]->output_Fs, 3125000 ), sub( 0, Q11 ) ); } ELSE { set16_fx( output_mem_fx, 0, NS2SA( sts[n]->output_Fs, 3125000 ) ); } - + Word16 Q_synth = 0; - IF ( ( error = core_switching_post_dec_ivas_fx( sts[n], synth_fx[n], output_fx[cpe_id * CPE_CHANNELS + n], output_mem_fx, st_ivas->ivas_format, 0, output_frame, 0 /*core_switching_flag*/, ( st_ivas->ivas_format != SBA_ISM_FORMAT || cpe_id >= nCPE - 2 ) ? st_ivas->sba_dirac_stereo_flag : 0, -1, hCPE->last_element_mode, &Q_synth ) ) != IVAS_ERR_OK ) + IF( ( error = core_switching_post_dec_ivas_fx( sts[n], synth_fx[n], output_fx[cpe_id * CPE_CHANNELS + n], output_mem_fx, st_ivas->ivas_format, 0, output_frame, 0 /*core_switching_flag*/, ( st_ivas->ivas_format != SBA_ISM_FORMAT || cpe_id >= nCPE - 2 ) ? st_ivas->sba_dirac_stereo_flag : 0, -1, hCPE->last_element_mode, &Q_synth ) ) != IVAS_ERR_OK ) { return error; } - Copy_Scale_sig_16_32(synth_fx[n], output_fx[cpe_id * CPE_CHANNELS + n], output_frame, sub(Q11, Q_synth)); + Copy_Scale_sig_16_32( synth_fx[n], output_fx[cpe_id * CPE_CHANNELS + n], output_frame, sub( Q11, Q_synth ) ); /* Save synthesis for HQ FEC */ Word32 output_fx_[L_FRAME48k]; - mvl2l(output_fx[cpe_id * CPE_CHANNELS + n], output_fx_, L_FRAME48k); - Scale_sig32(output_fx_, L_FRAME48k, sub(Q16, Q11)); - Copy_Scale_sig32_16(sts[n]->prev_synth_buffer32_fx, sts[n]->prev_synth_buffer_fx, NS2SA(48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS), -11); + mvl2l( output_fx[cpe_id * CPE_CHANNELS + n], output_fx_, L_FRAME48k ); + Scale_sig32( output_fx_, L_FRAME48k, sub( Q16, Q11 ) ); + Copy_Scale_sig32_16( sts[n]->prev_synth_buffer32_fx, sts[n]->prev_synth_buffer_fx, NS2SA( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), -11 ); sts[n]->q_prev_synth_buffer_fx = 0; save_synthesis_hq_fec_fx( sts[n], output_fx_, output_frame, hCPE ); - + /* CoreCoder common updates */ ivas_updt_dec_common_fx( hCPE->hCoreCoder[n], NORMAL_HQ_CORE, -1, output_fx[cpe_id * CPE_CHANNELS + n], 11 ); } /* n_channels loop */ - FOR(n = 0; n < 2; n++) { - IF(hCPE->hCoreCoder[n]) + FOR( n = 0; n < 2; n++ ) + { + IF( hCPE->hCoreCoder[n] ) { - Copy_Scale_sig_16_32(hCPE->hCoreCoder[n]->delay_buf_out_fx, hCPE->hCoreCoder[n]->delay_buf_out32_fx, HQ_DELTA_MAX * HQ_DELAY_COMP, Q11); + Copy_Scale_sig_16_32( hCPE->hCoreCoder[n]->delay_buf_out_fx, hCPE->hCoreCoder[n]->delay_buf_out32_fx, HQ_DELTA_MAX * HQ_DELAY_COMP, Q11 ); } } /* synthesis synchronization between stereo modes */ - IF ( EQ_16(st_ivas->sba_dirac_stereo_flag, 0) || ( EQ_16(st_ivas->ivas_format, SBA_ISM_FORMAT) && LE_16(cpe_id, sub(nCPE, 2)) ) ) + IF( EQ_16( st_ivas->sba_dirac_stereo_flag, 0 ) || ( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) && LE_16( cpe_id, sub( nCPE, 2 ) ) ) ) { - synchro_synthesis_fx( ivas_total_brate, hCPE, output_fx + cpe_id * CPE_CHANNELS, output_frame, 0 ); + synchro_synthesis_fx( ivas_total_brate, hCPE, output_fx + cpe_id * CPE_CHANNELS, output_frame, 0 ); } } /* move channels after LFE to correct output for multi-channel MCT */ - IF ( EQ_16(st_ivas->ivas_format, MC_FORMAT) && ( EQ_16(st_ivas->mc_mode, MC_MODE_MCT) || EQ_16(st_ivas->mc_mode, MC_MODE_PARAMUPMIX) ) ) + IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) && ( EQ_16( st_ivas->mc_mode, MC_MODE_MCT ) || EQ_16( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) ) { Word32 tmp[L_FRAME48k]; /*save center channel output*/ mvl2l( output_fx[hMCT->nchan_out_woLFE - 1], tmp, output_frame ); - FOR ( n = hMCT->nchan_out_woLFE - 1; n >= LFE_CHANNEL; n-- ) + FOR( n = hMCT->nchan_out_woLFE - 1; n >= LFE_CHANNEL; n-- ) { mvl2l( output_fx[n - 1], output_fx[n + 1], output_frame ); } @@ -656,7 +654,6 @@ ivas_error ivas_mct_dec_fx( pop_wmops(); return error; - } #endif @@ -678,8 +675,8 @@ ivas_error create_mct_dec_fx( Word16 cpe_id; /*--------------------------------------------------------- --------* - * Allocate MCT handle - *-----------------------------------------------------------------*/ + * Allocate MCT handle + *-----------------------------------------------------------------*/ IF( ( hMCT = (MCT_DEC_HANDLE) malloc( sizeof( MCT_DEC_DATA ) ) ) == NULL ) { @@ -687,25 +684,25 @@ ivas_error create_mct_dec_fx( } /*-----------------------------------------------------------------* - * Allocate MCT BlockData handles - *-----------------------------------------------------------------*/ + * Allocate MCT BlockData handles + *-----------------------------------------------------------------*/ /* Determine active channels */ - IF( ( EQ_16(st_ivas->ivas_format , MC_FORMAT) && EQ_16(st_ivas->mc_mode , MC_MODE_PARAMMC) ) || EQ_16(st_ivas->ivas_format , SBA_FORMAT) || EQ_16(st_ivas->ivas_format , SBA_ISM_FORMAT) ) + IF( ( EQ_16( st_ivas->ivas_format, MC_FORMAT ) && EQ_16( st_ivas->mc_mode, MC_MODE_PARAMMC ) ) || EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { hMCT->nchan_out_woLFE = st_ivas->nchan_transport; - IF( EQ_16(st_ivas->ism_mode , ISM_SBA_MODE_DISC) ) + IF( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { - hMCT->nchan_out_woLFE = add(hMCT->nchan_out_woLFE,st_ivas->nchan_ism); + hMCT->nchan_out_woLFE = add( hMCT->nchan_out_woLFE, st_ivas->nchan_ism ); } } - ELSE IF( EQ_16(st_ivas->mc_mode , MC_MODE_MCT) ) + ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCT ) ) { - hMCT->nchan_out_woLFE = sub(st_ivas->nchan_transport , st_ivas->hTransSetup.num_lfe); + hMCT->nchan_out_woLFE = sub( st_ivas->nchan_transport, st_ivas->hTransSetup.num_lfe ); } - ELSE IF( EQ_16(st_ivas->ivas_format , MC_FORMAT) && EQ_16(st_ivas->mc_mode , MC_MODE_PARAMUPMIX) ) + ELSE IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) && EQ_16( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) { - hMCT->nchan_out_woLFE = sub(st_ivas->nchan_transport , st_ivas->hTransSetup.num_lfe); + hMCT->nchan_out_woLFE = sub( st_ivas->nchan_transport, st_ivas->hTransSetup.num_lfe ); } ELSE { @@ -714,7 +711,7 @@ ivas_error create_mct_dec_fx( cp_bitrate = L_shl( Mult_32_16( st_ivas->hDecoderConfig->ivas_total_brate, div_s( 1, hMCT->nchan_out_woLFE ) ), 1 ); - IF( EQ_16(st_ivas->ism_mode , ISM_SBA_MODE_DISC) ) + IF( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { cp_bitrate = L_shl( Mult_32_16( st_ivas->hDecoderConfig->ivas_total_brate, div_s( 1, st_ivas->nchan_transport ) ), 1 ); } @@ -735,7 +732,7 @@ ivas_error create_mct_dec_fx( } /*Initialize MCT block data */ - max_blocks = shr(hMCT->nchan_out_woLFE , 1); + max_blocks = shr( hMCT->nchan_out_woLFE, 1 ); FOR( n = 0; n < max_blocks; n++ ) { @@ -749,8 +746,8 @@ ivas_error create_mct_dec_fx( hMCT->hBlockData[n]->ch2 = 0; /*-----------------------------------------------------------------* - * MDCT stereo initialization - *-----------------------------------------------------------------*/ + * MDCT stereo initialization + *-----------------------------------------------------------------*/ IF( ( hMCT->hBlockData[n]->hStereoMdct = (STEREO_MDCT_DEC_DATA_HANDLE) malloc( sizeof( STEREO_MDCT_DEC_DATA ) ) ) == NULL ) { @@ -768,14 +765,14 @@ ivas_error create_mct_dec_fx( } /*-----------------------------------------------------------------* - * Initializations - *-----------------------------------------------------------------*/ + * Initializations + *-----------------------------------------------------------------*/ hMCT->currBlockDataCnt = 0; /*Initialize bits required to signal channel-pair index*/ // hMCT->bitsChannelPairIndex = max( 1, (Word16) ( floorf( ( logf( (float) hMCT->nchan_out_woLFE * ( hMCT->nchan_out_woLFE - 1 ) / 2 - 1 ) * INV_LOG_2 ) ) + 1 ) ); - hMCT->bitsChannelPairIndex = s_max( 1, floor_log_2( (Word32) hMCT->nchan_out_woLFE * ( (Word32) hMCT->nchan_out_woLFE - 1 ) / 2 - 1 )+ 1 ); + hMCT->bitsChannelPairIndex = s_max( 1, floor_log_2( (Word32) hMCT->nchan_out_woLFE * ( (Word32) hMCT->nchan_out_woLFE - 1 ) / 2 - 1 ) + 1 ); set16_fx( hMCT->chBitRatios, 0, MCT_MAX_CHANNELS ); set16_fx( hMCT->lowE_ch, 0, MCT_MAX_CHANNELS ); @@ -920,7 +917,7 @@ ivas_error create_mct_dec( #ifdef IVAS_FLOAT_FIXED ivas_error mct_dec_reconfigure_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const UWord16 b_nchan_change /* i : flag indicating different channel count */ ) { @@ -935,24 +932,27 @@ ivas_error mct_dec_reconfigure_fx( /*-----------------------------------------------------------------* * Allocate and initialize MCT BlockData handles *-----------------------------------------------------------------*/ - IF ( b_nchan_change ) + IF( b_nchan_change ) { /* Determine active channels */ - test(); test(); test(); test(); - IF ( ( EQ_32( st_ivas->ivas_format, MC_FORMAT ) && EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) ) || EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) + test(); + test(); + test(); + test(); + IF( ( EQ_32( st_ivas->ivas_format, MC_FORMAT ) && EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) ) || EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { hMCT->nchan_out_woLFE = st_ivas->nchan_transport; move16(); - IF ( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) + IF( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { hMCT->nchan_out_woLFE = add( hMCT->nchan_out_woLFE, st_ivas->nchan_ism ); } } - ELSE IF ( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) ) + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) ) { hMCT->nchan_out_woLFE = sub( st_ivas->nchan_transport, st_ivas->hTransSetup.num_lfe ); } - ELSE IF ( EQ_32( st_ivas->ivas_format, MC_FORMAT ) && EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) + ELSE IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) && EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) { hMCT->nchan_out_woLFE = sub( st_ivas->nchan_transport, st_ivas->hTransSetup.num_lfe ); } @@ -963,67 +963,67 @@ ivas_error mct_dec_reconfigure_fx( } /* indicate LFE for appropriate core-coder channel */ - FOR ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - FOR ( n = 0; n < CPE_CHANNELS; n++ ) + FOR( n = 0; n < CPE_CHANNELS; n++ ) { st_ivas->hCPE[cpe_id]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_REGULAR; } } /* in case we have an uneven number of transport channels, indicate last channel ID as inactive */ - IF ( hMCT->nchan_out_woLFE % 2 ) + IF( hMCT->nchan_out_woLFE % 2 ) { st_ivas->hCPE[st_ivas->nCPE - 1]->hCoreCoder[1]->mct_chan_mode = MCT_CHAN_MODE_IGNORE; } - tmp = BASOP_Util_Divide3216_Scale(st_ivas->hDecoderConfig->ivas_total_brate, hMCT->nchan_out_woLFE, &tmp_exp ); + tmp = BASOP_Util_Divide3216_Scale( st_ivas->hDecoderConfig->ivas_total_brate, hMCT->nchan_out_woLFE, &tmp_exp ); cp_bitrate = L_shl( tmp, tmp_exp + 2 ); - IF ( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) + IF( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { - tmp = BASOP_Util_Divide3216_Scale(st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, &tmp_exp); - cp_bitrate = L_shl(tmp, tmp_exp + 2); + tmp = BASOP_Util_Divide3216_Scale( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, &tmp_exp ); + cp_bitrate = L_shl( tmp, tmp_exp + 2 ); } /* set correct nominal bitrates and igf config already here, otherwise we * run into a number of problems */ - FOR ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { st_ivas->hCPE[cpe_id]->element_brate = cp_bitrate; move32(); - FOR ( n = 0; n < CPE_CHANNELS; n++ ) + FOR( n = 0; n < CPE_CHANNELS; n++ ) { st = st_ivas->hCPE[cpe_id]->hCoreCoder[n]; st->total_brate = st_ivas->hCPE[cpe_id]->element_brate; move32(); - IF ( NE_32( st->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) ) + IF( NE_32( st->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) ) { tmp = BASOP_Util_Divide3232_Scale( st_ivas->hCPE[cpe_id]->element_brate, FRAMES_PER_SEC, &tmp_exp ); st->bits_frame_nominal = shr( tmp, 15 - tmp_exp ); - st->igf = getIgfPresent_fx(st->element_mode, st->bits_frame_nominal * FRAMES_PER_SEC, st->bwidth, st->rf_flag); // no floating point so directly pluggable + st->igf = getIgfPresent_fx( st->element_mode, st->bits_frame_nominal * FRAMES_PER_SEC, st->bwidth, st->rf_flag ); // no floating point so directly pluggable - IF(st->igf) + IF( st->igf ) { - IGFDecSetMode_ivas_fx(st->hIGFDec, st_ivas->hCPE[cpe_id]->element_brate, st->bwidth, st->element_mode, -1, -1, st->rf_flag); + IGFDecSetMode_ivas_fx( st->hIGFDec, st_ivas->hCPE[cpe_id]->element_brate, st->bwidth, st->element_mode, -1, -1, st->rf_flag ); } } } } /*Initialize MCT block data */ - tmp = BASOP_Util_Divide1616_Scale(hMCT->nchan_out_woLFE, CPE_CHANNELS, &tmp_exp); + tmp = BASOP_Util_Divide1616_Scale( hMCT->nchan_out_woLFE, CPE_CHANNELS, &tmp_exp ); max_blocks = shr( tmp, 15 - tmp_exp ); - FOR ( n = 0; n < max_blocks; n++ ) + FOR( n = 0; n < max_blocks; n++ ) { - IF ( b_nchan_change ) + IF( b_nchan_change ) { - IF ( hMCT->hBlockData[n] == NULL ) + IF( hMCT->hBlockData[n] == NULL ) { - IF ( ( hMCT->hBlockData[n] = (MCT_DEC_BLOCK_DATA_HANDLE) malloc( sizeof( MCT_BLOCK_DATA ) ) ) == NULL ) + IF( ( hMCT->hBlockData[n] = (MCT_DEC_BLOCK_DATA_HANDLE) malloc( sizeof( MCT_BLOCK_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MCT block data structure\n" ) ); } @@ -1035,7 +1035,7 @@ ivas_error mct_dec_reconfigure_fx( move16(); /* MDCT stereo initialization */ - IF ( ( hMCT->hBlockData[n]->hStereoMdct = (STEREO_MDCT_DEC_DATA_HANDLE) malloc( sizeof( STEREO_MDCT_ENC_DATA ) ) ) == NULL ) + IF( ( hMCT->hBlockData[n]->hStereoMdct = (STEREO_MDCT_DEC_DATA_HANDLE) malloc( sizeof( STEREO_MDCT_ENC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n" ) ); } @@ -1048,12 +1048,12 @@ ivas_error mct_dec_reconfigure_fx( move16(); } - FOR ( ; n < MCT_MAX_BLOCKS; n++ ) + FOR( ; n < MCT_MAX_BLOCKS; n++ ) { /* deallocate no longer needed blocks */ - IF ( hMCT->hBlockData[n] != NULL ) + IF( hMCT->hBlockData[n] != NULL ) { - IF ( hMCT->hBlockData[n]->hStereoMdct != NULL ) + IF( hMCT->hBlockData[n]->hStereoMdct != NULL ) { free( hMCT->hBlockData[n]->hStereoMdct ); hMCT->hBlockData[n]->hStereoMdct = NULL; @@ -1068,7 +1068,7 @@ ivas_error mct_dec_reconfigure_fx( * Initializations *-----------------------------------------------------------------*/ - IF ( b_nchan_change ) + IF( b_nchan_change ) { hMCT->currBlockDataCnt = 0; move16(); @@ -1076,16 +1076,16 @@ ivas_error mct_dec_reconfigure_fx( /*Initialize bits required to signal channel-pair index*/ Word32 log_tmp; - L_tmp = L_sub( L_shr( L_mult0( hMCT->nchan_out_woLFE, sub(hMCT->nchan_out_woLFE, 1) ), 1 ), 1 ); - tmp_exp = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, tmp_exp); - log_tmp = BASOP_Util_Log2(L_tmp); // ( 31 - tmp_exp ) - log_tmp = L_add(log_tmp, L_shl((Q31 - tmp_exp), Q25)); // Q25 + L_tmp = L_sub( L_shr( L_mult0( hMCT->nchan_out_woLFE, sub( hMCT->nchan_out_woLFE, 1 ) ), 1 ), 1 ); + tmp_exp = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, tmp_exp ); + log_tmp = BASOP_Util_Log2( L_tmp ); // ( 31 - tmp_exp ) + log_tmp = L_add( log_tmp, L_shl( ( Q31 - tmp_exp ), Q25 ) ); // Q25 // scale down from Q25 to Q0 - tmp = extract_l(L_shr(log_tmp, Q25)); - tmp = add(tmp, 1); - hMCT->bitsChannelPairIndex = s_max(1, tmp); + tmp = extract_l( L_shr( log_tmp, Q25 ) ); + tmp = add( tmp, 1 ); + hMCT->bitsChannelPairIndex = s_max( 1, tmp ); set_s( hMCT->chBitRatios, 0, MCT_MAX_CHANNELS ); set_s( hMCT->lowE_ch, 0, MCT_MAX_CHANNELS ); @@ -1258,18 +1258,18 @@ void ivas_mct_dec_close( { Word16 n, maxBlocks; - IF ( hMCT == NULL || *hMCT == NULL ) + IF( hMCT == NULL || *hMCT == NULL ) { return; } maxBlocks = shr( ( *hMCT )->nchan_out_woLFE, 1 ); - FOR ( n = 0; n < maxBlocks; n++ ) + FOR( n = 0; n < maxBlocks; n++ ) { - IF ( ( *hMCT )->hBlockData[n] != NULL ) + IF( ( *hMCT )->hBlockData[n] != NULL ) { - IF ( ( *hMCT )->hBlockData[n]->hStereoMdct != NULL ) + IF( ( *hMCT )->hBlockData[n]->hStereoMdct != NULL ) { free( ( *hMCT )->hBlockData[n]->hStereoMdct ); ( *hMCT )->hBlockData[n]->hStereoMdct = NULL; @@ -1289,18 +1289,18 @@ void ivas_mct_dec_close( { Word16 n, maxBlocks; - IF ( hMCT == NULL || *hMCT == NULL ) + IF( hMCT == NULL || *hMCT == NULL ) { return; } maxBlocks = ( *hMCT )->nchan_out_woLFE / 2; - FOR ( n = 0; n < maxBlocks; n++ ) + FOR( n = 0; n < maxBlocks; n++ ) { - IF ( ( *hMCT )->hBlockData[n] != NULL ) + IF( ( *hMCT )->hBlockData[n] != NULL ) { - IF ( ( *hMCT )->hBlockData[n]->hStereoMdct != NULL ) + IF( ( *hMCT )->hBlockData[n]->hStereoMdct != NULL ) { free( ( *hMCT )->hBlockData[n]->hStereoMdct ); ( *hMCT )->hBlockData[n]->hStereoMdct = NULL; @@ -1330,10 +1330,10 @@ void ivas_mct_dec_close( /*! r : MC format mode */ #ifdef IVAS_FLOAT_FIXED ivas_error ivas_mc_dec_config_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const Word16 idx, /* i : LS config. index */ UWord16 *nSamplesRendered, /* o : samples flushed from last frame (JBM) */ - Word16 *data /* o : output synthesis signal */ + Word16 *data /* o : output synthesis signal */ ) { AUDIO_CONFIG signaled_config; @@ -1343,12 +1343,12 @@ ivas_error ivas_mc_dec_config_fx( /* store last frame MC mode */ last_mc_mode = st_ivas->mc_mode; - IF ( EQ_16(st_ivas->bfi, 0) ) + IF( EQ_16( st_ivas->bfi, 0 ) ) { /* set transported MC LS setup */ signaled_config = ivas_mc_map_ls_setup_to_output_config( idx ); - IF ( EQ_16(st_ivas->ini_frame, 0) ) + IF( EQ_16( st_ivas->ini_frame, 0 ) ) { st_ivas->transport_config = signaled_config; } @@ -1357,22 +1357,22 @@ ivas_error ivas_mc_dec_config_fx( st_ivas->mc_mode = ivas_mc_mode_select( ivas_mc_map_output_config_to_mc_ls_setup( signaled_config ), st_ivas->hDecoderConfig->ivas_total_brate ); /* MC format switching */ - IF ( st_ivas->ini_frame != 0 ) + IF( st_ivas->ini_frame != 0 ) { - IF ( NE_32(st_ivas->hDecoderConfig->last_ivas_total_brate, st_ivas->hDecoderConfig->ivas_total_brate) || st_ivas->transport_config != signaled_config || last_mc_mode != st_ivas->mc_mode ) + IF( NE_32( st_ivas->hDecoderConfig->last_ivas_total_brate, st_ivas->hDecoderConfig->ivas_total_brate ) || st_ivas->transport_config != signaled_config || last_mc_mode != st_ivas->mc_mode ) { - IF ( st_ivas->hRenderConfig ) + IF( st_ivas->hRenderConfig ) { FOR( Word16 i = 0; i < 4; i++ ) { st_ivas->hRenderConfig->directivity_fx[i * 3 + 2] = shl_sat( st_ivas->hRenderConfig->directivity_fx[i * 3 + 2], 9 ); } } - IF ( ( error = ivas_mc_dec_reconfig_fx( st_ivas, nSamplesRendered, data ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_mc_dec_reconfig_fx( st_ivas, nSamplesRendered, data ) ) != IVAS_ERR_OK ) { return error; } - IF ( st_ivas->hRenderConfig ) + IF( st_ivas->hRenderConfig ) { FOR( Word16 i = 0; i < 4; i++ ) { @@ -1392,7 +1392,7 @@ ivas_error ivas_mc_dec_config( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const int16_t idx, /* i : LS config. index */ uint16_t *nSamplesRendered, /* o : samples flushed from last frame (JBM) */ - int16_t *data /* o : output synthesis signal */ + int16_t *data /* o : output synthesis signal */ ) { AUDIO_CONFIG signaled_config; @@ -1444,7 +1444,7 @@ ivas_error ivas_mc_dec_config( #ifdef IVAS_FLOAT_FIXED static ivas_error ivas_mc_dec_reconfig_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ UWord16 *nSamplesRendered, /* o : number of samples flushed from the last frame (JBM) */ Word16 *data /* o : output synthesis signal */ ) @@ -1483,7 +1483,7 @@ static ivas_error ivas_mc_dec_reconfig_fx( sba_dirac_stereo_flag_old = st_ivas->sba_dirac_stereo_flag; /* special handling needed for the hp20 buffers for McMASA */ - IF ( EQ_16(last_mc_mode , MC_MODE_MCMASA) ) + IF( EQ_16( last_mc_mode, MC_MODE_MCMASA ) ) { nchan_hp20_old = getNumChanSynthesis( st_ivas ); } @@ -1506,7 +1506,7 @@ static ivas_error ivas_mc_dec_reconfig_fx( ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config ); /* transfer subframe info from DirAC or ParamMC to central tc buffer */ - IF ( EQ_16(last_mc_mode , MC_MODE_PARAMMC) ) + IF( EQ_16( last_mc_mode, MC_MODE_PARAMMC ) ) { st_ivas->hTcBuffer->nb_subframes = st_ivas->hParamMC->nb_subframes; st_ivas->hTcBuffer->subframes_rendered = st_ivas->hParamMC->subframes_rendered; @@ -1514,7 +1514,7 @@ static ivas_error ivas_mc_dec_reconfig_fx( st_ivas->hTcBuffer->slots_rendered = st_ivas->hParamMC->slots_rendered; Copy( st_ivas->hParamMC->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); } - ELSE IF ( EQ_16(last_mc_mode , MC_MODE_MCMASA) && st_ivas->hSpatParamRendCom != NULL ) + ELSE IF( EQ_16( last_mc_mode, MC_MODE_MCMASA ) && st_ivas->hSpatParamRendCom != NULL ) { st_ivas->hTcBuffer->nb_subframes = st_ivas->hSpatParamRendCom->nb_subframes; st_ivas->hTcBuffer->subframes_rendered = st_ivas->hSpatParamRendCom->subframes_rendered; @@ -1526,31 +1526,31 @@ static ivas_error ivas_mc_dec_reconfig_fx( /* JBM: when granularity goes down (e.g. MCT with CREND -> ParamMC with binaural fastconv render what still fits in the new granularity */ tc_granularity_new = ivas_jbm_dec_get_render_granularity( st_ivas->renderer_type, st_ivas->ivas_format, st_ivas->mc_mode, st_ivas->hDecoderConfig->output_Fs ); - IF ( LT_16(tc_granularity_new , st_ivas->hTcBuffer->n_samples_granularity) ) + IF( LT_16( tc_granularity_new, st_ivas->hTcBuffer->n_samples_granularity ) ) { - IF ( ( error = ivas_jbm_dec_flush_renderer_fx( st_ivas, tc_granularity_new, renderer_type_old, intern_config_old, &hIntSetupOld, last_mc_mode, ISM_MODE_NONE, nSamplesRendered, data ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_jbm_dec_flush_renderer_fx( st_ivas, tc_granularity_new, renderer_type_old, intern_config_old, &hIntSetupOld, last_mc_mode, ISM_MODE_NONE, nSamplesRendered, data ) ) != IVAS_ERR_OK ) { return error; } } /* JBM: when granularity goes up set samples to discard at the beginning of the frame */ - ELSE IF ( GT_16(tc_granularity_new , st_ivas->hTcBuffer->n_samples_granularity) ) + ELSE IF( GT_16( tc_granularity_new, st_ivas->hTcBuffer->n_samples_granularity ) ) { - IF ( ( error = ivas_jbm_dec_set_discard_samples( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_jbm_dec_set_discard_samples( st_ivas ) ) != IVAS_ERR_OK ) { return error; } } - IF ( EQ_16(st_ivas->mc_mode , MC_MODE_MCT) ) + IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCT ) ) { st_ivas->nchan_transport = ivas_mc_ls_setup_get_num_channels( ivas_mc_map_output_config_to_mc_ls_setup( st_ivas->transport_config ) ); st_ivas->nSCE = 0; st_ivas->nCPE = st_ivas->nchan_transport / 2; - IF ( NE_16(last_mc_mode , MC_MODE_MCT) ) + IF( NE_16( last_mc_mode, MC_MODE_MCT ) ) { /*De-allocate handles for other MC modes*/ - IF ( st_ivas->hParamMC != NULL ) + IF( st_ivas->hParamMC != NULL ) { ivas_param_mc_dec_close_fx( &st_ivas->hParamMC ); @@ -1558,7 +1558,7 @@ static ivas_error ivas_mc_dec_reconfig_fx( ivas_ls_setup_conversion_close_fx( &st_ivas->hLsSetUpConversion ); } - IF ( EQ_16(last_mc_mode , MC_MODE_PARAMUPMIX) ) + IF( EQ_16( last_mc_mode, MC_MODE_PARAMUPMIX ) ) { ivas_mc_paramupmix_dec_close( &( st_ivas->hMCParamUpmix ) ); ivas_ls_setup_conversion_close_fx( &( st_ivas->hLsSetUpConversion ) ); @@ -1568,7 +1568,7 @@ static ivas_error ivas_mc_dec_reconfig_fx( ivas_masa_dec_close_fx( &( st_ivas->hMasa ) ); ivas_qmetadata_close( &st_ivas->hQMetaData ); - IF ( st_ivas->hDirAC != NULL ) + IF( st_ivas->hDirAC != NULL ) { ivas_dirac_rend_close_fx( &( st_ivas->hDirACRend ) ); ivas_spat_hSpatParamRendCom_close_fx( &( st_ivas->hSpatParamRendCom ) ); @@ -1577,7 +1577,7 @@ static ivas_error ivas_mc_dec_reconfig_fx( } /* init LS conversion if the renderer type asks for it */ - IF ( EQ_16(st_ivas->renderer_type , RENDERER_MC) && st_ivas->hLsSetUpConversion == NULL ) + IF( EQ_16( st_ivas->renderer_type, RENDERER_MC ) && st_ivas->hLsSetUpConversion == NULL ) { if ( ( error = ivas_ls_setup_conversion_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { @@ -1586,16 +1586,16 @@ static ivas_error ivas_mc_dec_reconfig_fx( } } } - ELSE IF ( EQ_16(st_ivas->mc_mode , MC_MODE_PARAMUPMIX) ) + ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) { st_ivas->nSCE = 0; st_ivas->nCPE = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS / 2; st_ivas->nchan_transport = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS; - IF ( NE_16(last_mc_mode , MC_MODE_PARAMUPMIX) ) + IF( NE_16( last_mc_mode, MC_MODE_PARAMUPMIX ) ) { /*De-allocate handles for other MC modes*/ - IF ( st_ivas->hParamMC != NULL ) + IF( st_ivas->hParamMC != NULL ) { ivas_param_mc_dec_close_fx( &st_ivas->hParamMC ); @@ -1607,39 +1607,38 @@ static ivas_error ivas_mc_dec_reconfig_fx( ivas_qmetadata_close( &st_ivas->hQMetaData ); /* init LS conversion if the renderer type asks for it */ - IF ( ( EQ_16(st_ivas->renderer_type , RENDERER_MC) ) && st_ivas->hLsSetUpConversion == NULL ) + IF( ( EQ_16( st_ivas->renderer_type, RENDERER_MC ) ) && st_ivas->hLsSetUpConversion == NULL ) { - IF ( ( error = ivas_ls_setup_conversion_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_ls_setup_conversion_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } } - IF ( ( error = ivas_mc_paramupmix_dec_open( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_mc_paramupmix_dec_open( st_ivas ) ) != IVAS_ERR_OK ) { return error; } } } - ELSE IF ( EQ_16(st_ivas->mc_mode , MC_MODE_PARAMMC) ) + ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_PARAMMC ) ) { - IF ( NE_16(last_mc_mode , MC_MODE_PARAMMC) ) + IF( NE_16( last_mc_mode, MC_MODE_PARAMMC ) ) { /* remove old ls conversion for MCT if open, gets reopened correctly within ivas_param_mc_dec_open when needed */ - IF ( EQ_16(renderer_type_old , RENDERER_MC) && st_ivas->hLsSetUpConversion != NULL ) + IF( EQ_16( renderer_type_old, RENDERER_MC ) && st_ivas->hLsSetUpConversion != NULL ) { ivas_ls_setup_conversion_close_fx( &st_ivas->hLsSetUpConversion ); } - IF ( ( error = ivas_param_mc_dec_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_param_mc_dec_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } - } ELSE { - IF ( ( error = ivas_param_mc_dec_reconfig_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_param_mc_dec_reconfig_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -1649,7 +1648,7 @@ static ivas_error ivas_mc_dec_reconfig_fx( ivas_masa_dec_close_fx( &( st_ivas->hMasa ) ); ivas_qmetadata_close( &st_ivas->hQMetaData ); - IF ( st_ivas->hDirAC != NULL ) + IF( st_ivas->hDirAC != NULL ) { ivas_dirac_rend_close_fx( &( st_ivas->hDirACRend ) ); ivas_spat_hSpatParamRendCom_close_fx( &( st_ivas->hSpatParamRendCom ) ); @@ -1657,14 +1656,14 @@ static ivas_error ivas_mc_dec_reconfig_fx( vbap_free_data_fx( &( st_ivas->hVBAPdata ) ); } - IF ( EQ_16(last_mc_mode , MC_MODE_MCT) ) + IF( EQ_16( last_mc_mode, MC_MODE_MCT ) ) { - IF ( st_ivas->hMCT != NULL && LE_16(st_ivas->nchan_transport , CPE_CHANNELS) ) + IF( st_ivas->hMCT != NULL && LE_16( st_ivas->nchan_transport, CPE_CHANNELS ) ) { ivas_mct_dec_close( &st_ivas->hMCT ); } } - ELSE IF ( EQ_16(last_mc_mode , MC_MODE_PARAMUPMIX) ) + ELSE IF( EQ_16( last_mc_mode, MC_MODE_PARAMUPMIX ) ) { ivas_mc_paramupmix_dec_close( &( st_ivas->hMCParamUpmix ) ); } @@ -1672,38 +1671,38 @@ static ivas_error ivas_mc_dec_reconfig_fx( /* LFE handle */ ivas_lfe_dec_close_fx( &( st_ivas->hLFE ) ); } - ELSE IF ( EQ_16(st_ivas->mc_mode , MC_MODE_MCMASA) ) + ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) { ivas_mcmasa_setNumTransportChannels_fx( &( st_ivas->nchan_transport ), &( st_ivas->element_mode_init ), ivas_total_brate ); - IF ( NE_16(last_mc_mode , MC_MODE_MCMASA) ) + IF( NE_16( last_mc_mode, MC_MODE_MCMASA ) ) { - IF ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) { return error; } } - IF ( ( error = ivas_mcmasa_dec_reconfig( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_mcmasa_dec_reconfig( st_ivas ) ) != IVAS_ERR_OK ) { return error; } /* LS conversion */ - IF ( st_ivas->hLsSetUpConversion != NULL ) + IF( st_ivas->hLsSetUpConversion != NULL ) { ivas_ls_setup_conversion_close_fx( &st_ivas->hLsSetUpConversion ); } ivas_mc_paramupmix_dec_close( &( st_ivas->hMCParamUpmix ) ); - IF ( st_ivas->hParamMC != NULL ) + IF( st_ivas->hParamMC != NULL ) { ivas_param_mc_dec_close_fx( &st_ivas->hParamMC ); st_ivas->hParamMC = NULL; } - IF ( EQ_16(last_mc_mode , MC_MODE_MCT) ) + IF( EQ_16( last_mc_mode, MC_MODE_MCT ) ) { ivas_mct_dec_close( &st_ivas->hMCT ); } @@ -1712,9 +1711,9 @@ static ivas_error ivas_mc_dec_reconfig_fx( ivas_lfe_dec_close_fx( &( st_ivas->hLFE ) ); } - IF ( NE_16(st_ivas->mc_mode , MC_MODE_MCMASA) ) + IF( NE_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) { - IF ( EQ_16(st_ivas->nchan_transport , 1) ) + IF( EQ_16( st_ivas->nchan_transport, 1 ) ) { st_ivas->element_mode_init = IVAS_SCE; } @@ -1731,11 +1730,11 @@ static ivas_error ivas_mc_dec_reconfig_fx( /* special case: MCT->ParamMC with more than 2 TC, CPE 1 stays, but has the wrong mct_chan_mode in channel 1 and might have IGF static memory not allocated and the bit stream index list not set, set correct mct_chan_mode and init missing static mem (IGF, HQ) and some config (TNS) do it here since it is _very_ MC specific */ - IF ( EQ_16(last_mc_mode , MC_MODE_MCT) && EQ_16(st_ivas->mc_mode , MC_MODE_PARAMMC) && GT_16(st_ivas->nchan_transport , CPE_CHANNELS) ) + IF( EQ_16( last_mc_mode, MC_MODE_MCT ) && EQ_16( st_ivas->mc_mode, MC_MODE_PARAMMC ) && GT_16( st_ivas->nchan_transport, CPE_CHANNELS ) ) { st = st_ivas->hCPE[1]->hCoreCoder[1]; - IF ( st_ivas->nchan_transport == 3 ) + IF( st_ivas->nchan_transport == 3 ) { st->mct_chan_mode = MCT_CHAN_MODE_IGNORE; } @@ -1744,9 +1743,9 @@ static ivas_error ivas_mc_dec_reconfig_fx( st->mct_chan_mode = MCT_CHAN_MODE_REGULAR; } - IF ( st->hIGFDec == NULL ) + IF( st->hIGFDec == NULL ) { - IF ( ( st->hIGFDec = (IGF_DEC_INSTANCE_HANDLE) malloc( sizeof( IGFDEC_INSTANCE ) ) ) == NULL ) + IF( ( st->hIGFDec = (IGF_DEC_INSTANCE_HANDLE) malloc( sizeof( IGFDEC_INSTANCE ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for IGF\n" ) ); } @@ -1764,9 +1763,9 @@ static ivas_error ivas_mc_dec_reconfig_fx( #endif } - IF ( st->hHQ_core == NULL ) + IF( st->hHQ_core == NULL ) { - IF ( ( st->hHQ_core = (HQ_DEC_HANDLE) malloc( sizeof( HQ_DEC_DATA ) ) ) == NULL ) + IF( ( st->hHQ_core = (HQ_DEC_HANDLE) malloc( sizeof( HQ_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HQ core\n" ) ); } @@ -1776,9 +1775,9 @@ static ivas_error ivas_mc_dec_reconfig_fx( } /* check if we have a doubly used hTxcCfg, if so, allocate a distint one for the old MCT LFE channel */ - IF ( st->hTcxCfg == st_ivas->hCPE[1]->hCoreCoder[0]->hTcxCfg ) + IF( st->hTcxCfg == st_ivas->hCPE[1]->hCoreCoder[0]->hTcxCfg ) { - IF ( ( st->hTcxCfg = (TCX_CONFIG_HANDLE) malloc( sizeof( TCX_config ) ) ) == NULL ) + IF( ( st->hTcxCfg = (TCX_CONFIG_HANDLE) malloc( sizeof( TCX_config ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxCfg\n" ) ); } @@ -1786,19 +1785,19 @@ static ivas_error ivas_mc_dec_reconfig_fx( st->hTcxCfg->fIsTNSAllowed = getTnsAllowed( ivas_total_brate, st->igf, st->element_mode ); } - IF ( EQ_16(st_ivas->mc_mode , MC_MODE_MCMASA) ) + IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) { uint8_t separateChannelEnabled; int16_t separateChannelIndex; ivas_mcmasa_set_separate_channel_mode_fx( &separateChannelEnabled, &separateChannelIndex, ivas_total_brate ); ivas_mcmasa_split_brate_fx( separateChannelEnabled, ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &new_brate_SCE, &new_brate_CPE ); } - ELSE IF ( EQ_16(st_ivas->mc_mode , MC_MODE_MCT) ) + ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCT ) ) { new_brate_SCE = 0; new_brate_CPE = ( ivas_total_brate / ( st_ivas->nchan_transport - 1 ) ) * CPE_CHANNELS; } - ELSE IF ( EQ_16(st_ivas->mc_mode , MC_MODE_PARAMUPMIX) ) + ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) { new_brate_SCE = 0; new_brate_CPE = ( ivas_total_brate / ( st_ivas->nchan_transport - 1 ) ) * CPE_CHANNELS; @@ -1813,14 +1812,14 @@ static ivas_error ivas_mc_dec_reconfig_fx( { return error; } - IF ( EQ_16(last_mc_mode , MC_MODE_MCT) && EQ_16(st_ivas->mc_mode , MC_MODE_PARAMMC) && GT_16(st_ivas->nchan_transport , CPE_CHANNELS) ) + IF( EQ_16( last_mc_mode, MC_MODE_MCT ) && EQ_16( st_ivas->mc_mode, MC_MODE_PARAMMC ) && GT_16( st_ivas->nchan_transport, CPE_CHANNELS ) ) { st = st_ivas->hCPE[1]->hCoreCoder[1]; /* TCX-LTP */ - IF ( st->hTcxLtpDec == NULL ) + IF( st->hTcxLtpDec == NULL ) { - IF ( ( st->hTcxLtpDec = (TCX_LTP_DEC_HANDLE) malloc( sizeof( TCX_LTP_DEC_DATA ) ) ) == NULL ) + IF( ( st->hTcxLtpDec = (TCX_LTP_DEC_HANDLE) malloc( sizeof( TCX_LTP_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TCX-LTP handle\n" ) ); } @@ -1831,7 +1830,7 @@ static ivas_error ivas_mc_dec_reconfig_fx( /*-----------------------------------------------------------------* * re-configure HP20 memories *-----------------------------------------------------------------*/ - IF ( ( error = ivas_hp20_dec_reconfig_fx( st_ivas, nchan_hp20_old ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_hp20_dec_reconfig_fx( st_ivas, nchan_hp20_old ) ) != IVAS_ERR_OK ) { return error; } @@ -1839,12 +1838,12 @@ static ivas_error ivas_mc_dec_reconfig_fx( * Allocate the LFE handle that is coded separately after the allocation of the core coders *-----------------------------------------------------------------*/ - IF ( ( EQ_16(st_ivas->mc_mode , MC_MODE_MCT) || EQ_16(st_ivas->mc_mode , MC_MODE_PARAMUPMIX) ) && st_ivas->hLFE == NULL ) + IF( ( EQ_16( st_ivas->mc_mode, MC_MODE_MCT ) || EQ_16( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) && st_ivas->hLFE == NULL ) { Word32 binauralization_delay_ns = st_ivas->binaural_latency_ns; - IF ( st_ivas->hBinRenderer != NULL ) + IF( st_ivas->hBinRenderer != NULL ) { - IF ( st_ivas->hBinRenderer->render_lfe ) + IF( st_ivas->hBinRenderer->render_lfe ) { /* Account for filterbank delay */ binauralization_delay_ns += IVAS_FB_DEC_DELAY_NS; @@ -1868,14 +1867,14 @@ static ivas_error ivas_mc_dec_reconfig_fx( * Reconfigure renderers *-----------------------------------------------------------------*/ - IF ( EQ_16(st_ivas->mc_mode , MC_MODE_MCMASA) ) + IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) { - IF ( ( NE_16(st_ivas->renderer_type , RENDERER_DISABLE) ) && ( NE_16(st_ivas->renderer_type , RENDERER_MCMASA_MONO_STEREO) ) ) + IF( ( NE_16( st_ivas->renderer_type, RENDERER_DISABLE ) ) && ( NE_16( st_ivas->renderer_type, RENDERER_MCMASA_MONO_STEREO ) ) ) { - IF ( st_ivas->hDirAC != NULL ) + IF( st_ivas->hDirAC != NULL ) { /* reconfigure existing DirAC dec */ - IF ( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_RECONFIGURE ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_RECONFIGURE ) ) != IVAS_ERR_OK ) { return error; } @@ -1883,13 +1882,13 @@ static ivas_error ivas_mc_dec_reconfig_fx( ELSE { /* init a new DirAC dec */ - IF ( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK ) { return error; } } } - ELSE IF ( EQ_16(st_ivas->renderer_type , RENDERER_DISABLE) && st_ivas->hDirAC != NULL ) + ELSE IF( EQ_16( st_ivas->renderer_type, RENDERER_DISABLE ) && st_ivas->hDirAC != NULL ) { ivas_dirac_rend_close_fx( &( st_ivas->hDirACRend ) ); ivas_spat_hSpatParamRendCom_close_fx( &( st_ivas->hSpatParamRendCom ) ); @@ -1898,73 +1897,73 @@ static ivas_error ivas_mc_dec_reconfig_fx( } } - IF ( NE_16(renderer_type_old , st_ivas->renderer_type) ) + IF( NE_16( renderer_type_old, st_ivas->renderer_type ) ) { AUDIO_CONFIG output_config; output_config = st_ivas->hDecoderConfig->output_config; /* binaural renderers*/ - IF ( EQ_16(output_config , IVAS_AUDIO_CONFIG_BINAURAL) || EQ_16(output_config , IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR) || EQ_16(output_config , IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB) ) + IF( EQ_16( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { /* remove unneeded binaural renderers */ - IF ( st_ivas->hBinRenderer != NULL && ( NE_16(st_ivas->renderer_type , RENDERER_BINAURAL_FASTCONV) && NE_16(st_ivas->renderer_type , RENDERER_BINAURAL_FASTCONV_ROOM) ) ) + IF( st_ivas->hBinRenderer != NULL && ( NE_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) && NE_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) ) { ivas_binRenderer_close_fx( &st_ivas->hBinRenderer ); } - IF ( ( st_ivas->hCrendWrapper != NULL ) && ( st_ivas->hCrendWrapper->hCrend != NULL ) && ( NE_16(st_ivas->renderer_type , RENDERER_BINAURAL_MIXER_CONV) && NE_16(st_ivas->renderer_type , RENDERER_BINAURAL_MIXER_CONV_ROOM) && ( NE_16(st_ivas->renderer_type , RENDERER_BINAURAL_OBJECTS_TD) || NE_16(st_ivas->hIntSetup.output_config , IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB) ) ) ) + IF( ( st_ivas->hCrendWrapper != NULL ) && ( st_ivas->hCrendWrapper->hCrend != NULL ) && ( NE_16( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV ) && NE_16( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) && ( NE_16( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) || NE_16( st_ivas->hIntSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) ) ) { ivas_rend_closeCrend( &( st_ivas->hCrendWrapper ) ); } - IF ( st_ivas->hBinRendererTd != NULL && ( NE_16(st_ivas->renderer_type , RENDERER_BINAURAL_OBJECTS_TD) ) ) + IF( st_ivas->hBinRendererTd != NULL && ( NE_16( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) ) ) { ivas_td_binaural_close_fx( &st_ivas->hBinRendererTd ); st_ivas->hHrtfTD = NULL; } - IF ( st_ivas->hDiracDecBin != NULL ) + IF( st_ivas->hDiracDecBin != NULL ) { - IF ( NE_16(st_ivas->renderer_type , RENDERER_BINAURAL_PARAMETRIC) && NE_16(st_ivas->renderer_type , RENDERER_BINAURAL_PARAMETRIC_ROOM) && NE_16(st_ivas->renderer_type , RENDERER_STEREO_PARAMETRIC) ) + IF( NE_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) && NE_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) && NE_16( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) { ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); } } /* init necessary new renderers */ - IF ( st_ivas->hBinRenderer == NULL && ( EQ_16(st_ivas->renderer_type , RENDERER_BINAURAL_FASTCONV) || EQ_16(st_ivas->renderer_type , RENDERER_BINAURAL_FASTCONV_ROOM) ) ) + IF( st_ivas->hBinRenderer == NULL && ( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) ) { - IF ( ( error = ivas_binRenderer_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_binRenderer_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } } - ELSE IF ( st_ivas->hBinRendererTd == NULL && EQ_16(st_ivas->renderer_type , RENDERER_BINAURAL_OBJECTS_TD) ) + ELSE IF( st_ivas->hBinRendererTd == NULL && EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) ) { IF( ( error = ivas_td_binaural_open_fx( st_ivas, &st_ivas->SrcInd[0], &st_ivas->num_src ) ) != IVAS_ERR_OK ) { return error; } - IF ( EQ_16(st_ivas->hIntSetup.output_config , IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB) ) + IF( EQ_16( st_ivas->hIntSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { - IF ( ( error = ivas_rend_initCrendWrapper( &st_ivas->hCrendWrapper ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_rend_initCrendWrapper( &st_ivas->hCrendWrapper ) ) != IVAS_ERR_OK ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend Wrapper\n" ); } st_ivas->hCrendWrapper->hCrend = NULL; st_ivas->hCrendWrapper->hHrtfCrend = NULL; - IF ( ( st_ivas->hCrendWrapper->hCrend = (CREND_HANDLE) malloc( sizeof( CREND_DATA ) ) ) == NULL ) + IF( ( st_ivas->hCrendWrapper->hCrend = (CREND_HANDLE) malloc( sizeof( CREND_DATA ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend\n" ); } } } - ELSE IF ( st_ivas->hCrendWrapper == NULL && ( EQ_16(st_ivas->renderer_type , RENDERER_BINAURAL_MIXER_CONV) || EQ_16(st_ivas->renderer_type , RENDERER_BINAURAL_MIXER_CONV_ROOM) ) ) + ELSE IF( st_ivas->hCrendWrapper == NULL && ( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) ) ) { - IF ( ( error = ivas_rend_openCrend( &( st_ivas->hCrendWrapper ), st_ivas->intern_config, st_ivas->hDecoderConfig->output_config, st_ivas->hRenderConfig, st_ivas->hSetOfHRTF, st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_rend_openCrend( &( st_ivas->hCrendWrapper ), st_ivas->intern_config, st_ivas->hDecoderConfig->output_config, st_ivas->hRenderConfig, st_ivas->hSetOfHRTF, st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) { return error; } @@ -1972,12 +1971,12 @@ static ivas_error ivas_mc_dec_reconfig_fx( } } /* mono/stereo */ - ELSE IF ( EQ_16(output_config , IVAS_AUDIO_CONFIG_MONO) || EQ_16(output_config , IVAS_AUDIO_CONFIG_STEREO) ) + ELSE IF( EQ_16( output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) { /* nothing should happen here... */ } /* LS */ - ELSE IF ( EQ_16(output_config , IVAS_AUDIO_CONFIG_5_1) || EQ_16(output_config , IVAS_AUDIO_CONFIG_5_1_2) || EQ_16(output_config , IVAS_AUDIO_CONFIG_5_1_4) || EQ_16(output_config , IVAS_AUDIO_CONFIG_7_1) || EQ_16(output_config , IVAS_AUDIO_CONFIG_7_1_4) || EQ_16(output_config , IVAS_AUDIO_CONFIG_LS_CUSTOM) ) + ELSE IF( EQ_16( output_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_5_1_2 ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_7_1 ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_7_1_4 ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) { } } @@ -1985,7 +1984,7 @@ static ivas_error ivas_mc_dec_reconfig_fx( * CLDFB instances *-----------------------------------------------------------------*/ - IF ( ( error = ivas_cldfb_dec_reconfig_fx( st_ivas, nchan_transport_old, numCldfbAnalyses_old, numCldfbSyntheses_old ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_cldfb_dec_reconfig_fx( st_ivas, nchan_transport_old, numCldfbAnalyses_old, numCldfbSyntheses_old ) ) != IVAS_ERR_OK ) { return error; } @@ -2004,21 +2003,21 @@ static ivas_error ivas_mc_dec_reconfig_fx( tc_nchan_allocate_new = tc_nchan_tc_new; tc_nchan_full_new = tc_nchan_tc_new; - IF ( EQ_16(st_ivas->renderer_type , RENDERER_BINAURAL_PARAMETRIC) || EQ_16(st_ivas->renderer_type , RENDERER_BINAURAL_PARAMETRIC_ROOM) || EQ_16(st_ivas->renderer_type , RENDERER_STEREO_PARAMETRIC) ) + IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_16( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) { tc_nchan_allocate_new = 2 * BINAURAL_CHANNELS; tc_nchan_full_new = tc_nchan_allocate_new; } - IF ( EQ_16(st_ivas->mc_mode , MC_MODE_PARAMMC) && NE_16(st_ivas->hDecoderConfig->output_config , IVAS_AUDIO_CONFIG_MONO) && NE_16(st_ivas->hDecoderConfig->output_config , IVAS_AUDIO_CONFIG_STEREO) ) + IF( EQ_16( st_ivas->mc_mode, MC_MODE_PARAMMC ) && NE_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) && NE_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) ) { tc_nchan_full_new = 0; } - ELSE IF ( EQ_16(st_ivas->mc_mode , MC_MODE_PARAMUPMIX) ) + ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) { tc_nchan_allocate_new = MC_PARAMUPMIX_MAX_INPUT_CHANS; tc_buffer_mode_new = TC_BUFFER_MODE_RENDERER; - IF ( EQ_16(st_ivas->hDecoderConfig->output_config , IVAS_AUDIO_CONFIG_STEREO) || EQ_16(st_ivas->hDecoderConfig->output_config , IVAS_AUDIO_CONFIG_MONO) ) + IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) ) { tc_buffer_mode_new = TC_BUFFER_MODE_BUFFER; tc_nchan_tc_new = st_ivas->hDecoderConfig->nchan_out; @@ -2028,17 +2027,17 @@ static ivas_error ivas_mc_dec_reconfig_fx( } /* reconfigure buffer */ - IF ( NE_16(hTcBuffer->tc_buffer_mode , tc_buffer_mode_new) || NE_16(hTcBuffer->nchan_transport_jbm , tc_nchan_tc_new) || - NE_16(hTcBuffer->nchan_buffer_full , tc_nchan_full_new) || NE_16(hTcBuffer->nchan_transport_internal , tc_nchan_allocate_new) || - NE_16(tc_granularity_new , hTcBuffer->n_samples_granularity) ) + IF( NE_16( hTcBuffer->tc_buffer_mode, tc_buffer_mode_new ) || NE_16( hTcBuffer->nchan_transport_jbm, tc_nchan_tc_new ) || + NE_16( hTcBuffer->nchan_buffer_full, tc_nchan_full_new ) || NE_16( hTcBuffer->nchan_transport_internal, tc_nchan_allocate_new ) || + NE_16( tc_granularity_new, hTcBuffer->n_samples_granularity ) ) { - IF ( ( error = ivas_jbm_dec_tc_buffer_reconfigure_fx( st_ivas, tc_buffer_mode_new, tc_nchan_tc_new, tc_nchan_allocate_new, tc_nchan_full_new, tc_granularity_new ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_jbm_dec_tc_buffer_reconfigure_fx( st_ivas, tc_buffer_mode_new, tc_nchan_tc_new, tc_nchan_allocate_new, tc_nchan_full_new, tc_granularity_new ) ) != IVAS_ERR_OK ) { return error; } } /* transfer subframe info from central tc buffer to ParamMC or McMASA (DirAC) */ - IF ( st_ivas->hSpatParamRendCom != NULL ) + IF( st_ivas->hSpatParamRendCom != NULL ) { st_ivas->hSpatParamRendCom->nb_subframes = st_ivas->hTcBuffer->nb_subframes; st_ivas->hSpatParamRendCom->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered; @@ -2046,7 +2045,7 @@ static ivas_error ivas_mc_dec_reconfig_fx( st_ivas->hSpatParamRendCom->slots_rendered = st_ivas->hTcBuffer->slots_rendered; Copy( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hSpatParamRendCom->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); } - ELSE IF ( st_ivas->hParamMC != NULL ) + ELSE IF( st_ivas->hParamMC != NULL ) { st_ivas->hParamMC->nb_subframes = st_ivas->hTcBuffer->nb_subframes; st_ivas->hParamMC->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered; @@ -2067,7 +2066,7 @@ static ivas_error ivas_mc_dec_reconfig_fx( { return error; } -#if 1/*TODO: To be removed later*/ +#if 1 /*TODO: To be removed later*/ if ( ( error = ivas_output_buff_dec( st_ivas->p_output_f, nchan_out_buff_old, nchan_out_buff ) ) != IVAS_ERR_OK ) { return error; diff --git a/lib_dec/ivas_mct_dec_mct.c b/lib_dec/ivas_mct_dec_mct.c index 6d071cedb..5c56eb533 100644 --- a/lib_dec/ivas_mct_dec_mct.c +++ b/lib_dec/ivas_mct_dec_mct.c @@ -229,7 +229,6 @@ void apply_MCT_dec( } - /*----------------------------------------------------------* * mctStereoIGF_dec() * diff --git a/lib_dec/ivas_mct_dec_mct_fx.c b/lib_dec/ivas_mct_dec_mct_fx.c index 4a3577cd1..25774ec40 100644 --- a/lib_dec/ivas_mct_dec_mct_fx.c +++ b/lib_dec/ivas_mct_dec_mct_fx.c @@ -372,11 +372,11 @@ void mctStereoIGF_dec_fx( move32(); } - //IF( st->igf ) + // IF( st->igf ) //{ - // // TODO: remove this float to fixed conversion later. - // me2f_buf( st->hIGFDec->virtualSpec, st->hIGFDec->virtualSpec_e, st->hIGFDec->virtualSpec_float, ( N_MAX_TCX - IGF_START_MN ) ); - //} + // // TODO: remove this float to fixed conversion later. + // me2f_buf( st->hIGFDec->virtualSpec, st->hIGFDec->virtualSpec_e, st->hIGFDec->virtualSpec_float, ( N_MAX_TCX - IGF_START_MN ) ); + // } } } // TODO: Converting 16bit noise info to u8bit. can remove this later. @@ -437,7 +437,7 @@ void mctStereoIGF_dec_fx( IF( st->igf ) { // TODO: Fixed to float. Remove this later. - //me2f_buf( st->hIGFDec->virtualSpec, st->hIGFDec->virtualSpec_e, st->hIGFDec->virtualSpec_float, ( N_MAX_TCX - IGF_START_MN ) ); + // me2f_buf( st->hIGFDec->virtualSpec, st->hIGFDec->virtualSpec_e, st->hIGFDec->virtualSpec_float, ( N_MAX_TCX - IGF_START_MN ) ); // TODO: 16bit to u8bit. Remove this later. FOR( Word16 l = 0; l < IGF_START_MX; l++ ) { diff --git a/lib_dec/ivas_mdct_core_dec.c b/lib_dec/ivas_mdct_core_dec.c index 4d6248f45..0b3973293 100644 --- a/lib_dec/ivas_mdct_core_dec.c +++ b/lib_dec/ivas_mdct_core_dec.c @@ -1600,7 +1600,7 @@ void ivas_mdct_core_invQ( } nf_seed = 0; - decoder_tcx_invQ(st, prm[ch], Aq[ch], Aind[ch], L_spec[ch], L_frame[ch], L_frameTCX[ch], x[ch][k], NULL, xn_buf, &fUseTns[ch][k], &tnsData[ch][k], &gain_tcx, &prm_sqQ, &nf_seed, bfi, k); + decoder_tcx_invQ( st, prm[ch], Aq[ch], Aind[ch], L_spec[ch], L_frame[ch], L_frameTCX[ch], x[ch][k], NULL, xn_buf, &fUseTns[ch][k], &tnsData[ch][k], &gain_tcx, &prm_sqQ, &nf_seed, bfi, k ); mvr2r( x[ch][k], x_0[ch][k], L_frameTCX[ch] ); @@ -1809,14 +1809,15 @@ void ivas_mdct_core_reconstruct( } #else void ivas_mdct_core_reconstruct_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *x_fx[][NB_DIV], /* i/o: synthesis @internal_FS */ // Q(q_x) - Word16 signal_outFB_fx[CPE_CHANNELS][L_FRAME_PLUS], /* o : synthesis @output_FS */ // e_sig + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 *x_fx[][NB_DIV], + /* i/o: synthesis @internal_FS */ // Q(q_x) + Word16 signal_outFB_fx[CPE_CHANNELS][L_FRAME_PLUS], + /* o : synthesis @output_FS */ // e_sig Word16 fUseTns[CPE_CHANNELS][NB_DIV], /* i : flage TNS enabled */ - const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0)*/ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0)*/ Word16 q_x, - Word16 e_sig -) + Word16 e_sig ) { Word16 ch, k, bfi; Decoder_State **sts, *st; @@ -1840,7 +1841,7 @@ void ivas_mdct_core_reconstruct_fx( Word16 pitch[CPE_CHANNELS][NB_SUBFR16k]; Word16 pit_gain_fx[CPE_CHANNELS][NB_SUBFR16k]; Word16 skip_decoding; - + set16_fx( xn_buf_fx, 0, L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX ); /* Initializations */ @@ -1848,12 +1849,12 @@ void ivas_mdct_core_reconstruct_fx( bfi = sts[0]->bfi; /* TNS, ITF, IMDCT and updates */ - FOR ( ch = 0; ch < CPE_CHANNELS; ch++ ) + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { st = sts[ch]; skip_decoding = 0; - IF ( st->mct_chan_mode == MCT_CHAN_MODE_IGNORE ) + IF( st->mct_chan_mode == MCT_CHAN_MODE_IGNORE ) { skip_decoding = 1; } @@ -1863,26 +1864,26 @@ void ivas_mdct_core_reconstruct_fx( synthFB_fx = synth_bufFB_fx + st->hTcxDec->old_synth_lenFB; Copy_Scale_sig( st->hTcxDec->old_synth, synth_buf_fx, st->hTcxDec->old_synth_len, 0 ); - Copy_Scale_sig( st->hTcxDec->old_synthFB_fx, synth_bufFB_fx, st->hTcxDec->old_synth_lenFB, sub(q_syn, st->Q_syn) ); + Copy_Scale_sig( st->hTcxDec->old_synthFB_fx, synth_bufFB_fx, st->hTcxDec->old_synth_lenFB, sub( q_syn, st->Q_syn ) ); set16_fx( synth_fx, 0, L_FRAME_PLUS + M ); set16_fx( synthFB_fx, 0, L_FRAME_PLUS + M ); - IF ( NE_16(st->core, ACELP_CORE) ) - { - Scale_sig(st->hTcxDec->syn_Overl_TDACFB, shr(L_FRAME_MAX, 1), sub(q_win, -1 - st->Q_syn)); - Scale_sig(st->hTcxDec->syn_Overl_TDAC, shr(L_FRAME32k, 1), sub(q_win, -1 - st->Q_syn)); - Scale_sig(st->hTcxDec->old_syn_Overl, shr(L_FRAME32k, 1), sub(q_win, -1 - st->Q_syn)); - Scale_sig(st->hTcxDec->syn_Overl, L_FRAME32k / 2, sub(q_win, st->Q_syn)); - Scale_sig(st->hTcxDec->syn_OverlFB, L_FRAME_MAX / 2, sub(q_win, st->Q_syn)); - Scale_sig(st->hHQ_core->old_out_LB_fx, L_FRAME32k, sub(q_win, st->Q_syn)); - Scale_sig(st->hHQ_core->old_out_fx, L_FRAME48k, sub(q_win, st->Q_syn)); + IF( NE_16( st->core, ACELP_CORE ) ) + { + Scale_sig( st->hTcxDec->syn_Overl_TDACFB, shr( L_FRAME_MAX, 1 ), sub( q_win, -1 - st->Q_syn ) ); + Scale_sig( st->hTcxDec->syn_Overl_TDAC, shr( L_FRAME32k, 1 ), sub( q_win, -1 - st->Q_syn ) ); + Scale_sig( st->hTcxDec->old_syn_Overl, shr( L_FRAME32k, 1 ), sub( q_win, -1 - st->Q_syn ) ); + Scale_sig( st->hTcxDec->syn_Overl, L_FRAME32k / 2, sub( q_win, st->Q_syn ) ); + Scale_sig( st->hTcxDec->syn_OverlFB, L_FRAME_MAX / 2, sub( q_win, st->Q_syn ) ); + Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( q_win, st->Q_syn ) ); + Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, sub( q_win, st->Q_syn ) ); #ifdef MSAN_FIX Scale_sig( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ), sub( q_win, q_syn ) ); Scale_sig( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ), sub( q_win, q_syn ) ); #else - Scale_sig(synth_buf_fx, 3136, sub(q_win, q_syn)); - Scale_sig(synth_bufFB_fx, 3136, sub(q_win, q_syn)); + Scale_sig( synth_buf_fx, 3136, sub( q_win, q_syn ) ); + Scale_sig( synth_bufFB_fx, 3136, sub( q_win, q_syn ) ); #endif - Scale_sig(st->syn, M + 1, q_win - st->Q_syn); + Scale_sig( st->syn, M + 1, q_win - st->Q_syn ); FOR( k = 0; k < nSubframes[ch]; k++ ) { L_spec[ch] = st->hTcxCfg->tcx_coded_lines / nSubframes[ch]; @@ -1890,14 +1891,13 @@ void ivas_mdct_core_reconstruct_fx( L_frame_globalTCX[ch] = st->hTcxDec->L_frameTCX / nSubframes[ch]; init_tcx_info_fx( st, L_frame_global[ch], L_frame_globalTCX[ch], k, bfi, &tcx_offset[ch], - &tcx_offsetFB[ch], &L_frame[ch], &L_frameTCX[ch], &left_rect[ch], &L_spec[ch] ); + &tcx_offsetFB[ch], &L_frame[ch], &L_frameTCX[ch], &left_rect[ch], &L_spec[ch] ); - IF ( !skip_decoding ) + IF( !skip_decoding ) { decoder_tcx_imdct_fx( st, L_frame_global[ch], L_frame_globalTCX[ch], L_spec[ch], tcx_offset[ch], tcx_offsetFB[ch], L_frame[ch], L_frameTCX[ch], left_rect[ch], x_fx[ch][k], q_x, xn_buf_fx, q_win, - ( ( hCPE->nchan_out == 1 && st->hTcxDec->kernel_type[k] == MDST_IV ) || st->hTcxCfg->tcx_last_overlap_mode == TRANSITION_OVERLAP ) ? MDCT_IV : st->hTcxDec->kernel_type[k], - fUseTns[ch][k], &synth_fx[k * L_frame[ch]], &synthFB_fx[k * L_frameTCX[ch]], bfi, k, 0 ); - + ( ( hCPE->nchan_out == 1 && st->hTcxDec->kernel_type[k] == MDST_IV ) || st->hTcxCfg->tcx_last_overlap_mode == TRANSITION_OVERLAP ) ? MDCT_IV : st->hTcxDec->kernel_type[k], + fUseTns[ch][k], &synth_fx[k * L_frame[ch]], &synthFB_fx[k * L_frameTCX[ch]], bfi, k, 0 ); } ELSE { @@ -1905,36 +1905,36 @@ void ivas_mdct_core_reconstruct_fx( set16_fx( &synthFB_fx[k * L_frame[ch]], 0, L_frameTCX[ch] ); } } - - IF ( EQ_16(bfi, 0) && st->hTonalMDCTConc != NULL ) + + IF( EQ_16( bfi, 0 ) && st->hTonalMDCTConc != NULL ) { Word16 synth_tmp[L_FRAME48k]; - Copy_Scale_sig(synthFB_fx, synth_tmp, st->hTonalMDCTConc->nSamples, 2); + Copy_Scale_sig( synthFB_fx, synth_tmp, st->hTonalMDCTConc->nSamples, 2 ); TonalMDCTConceal_SaveTimeSignal( st->hTonalMDCTConc, synth_tmp, L_frameTCX[ch] ); } decoder_tcx_post_ivas_fx( st, synth_fx, synthFB_fx, NULL, bfi, MCT_flag ); - - Scale_sig(st->hTcxDec->syn_Overl_TDACFB, shr(L_FRAME_MAX, 1), sub(-1 - st->Q_syn, q_win)); - Scale_sig(st->hTcxDec->syn_Overl_TDAC, shr(L_FRAME32k, 1), sub(-1 - st->Q_syn, q_win)); - Scale_sig(st->hTcxDec->old_syn_Overl, shr(L_FRAME32k, 1), sub(-1 - st->Q_syn, q_win)); + + Scale_sig( st->hTcxDec->syn_Overl_TDACFB, shr( L_FRAME_MAX, 1 ), sub( -1 - st->Q_syn, q_win ) ); + Scale_sig( st->hTcxDec->syn_Overl_TDAC, shr( L_FRAME32k, 1 ), sub( -1 - st->Q_syn, q_win ) ); + Scale_sig( st->hTcxDec->old_syn_Overl, shr( L_FRAME32k, 1 ), sub( -1 - st->Q_syn, q_win ) ); #ifdef MSAN_FIX - Scale_sig( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ), sub(q_syn, q_win) ); - Scale_sig( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ), sub(q_syn, q_win) ); + Scale_sig( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ), sub( q_syn, q_win ) ); + Scale_sig( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ), sub( q_syn, q_win ) ); #else - Scale_sig(synth_buf_fx, 3136, sub(q_syn, q_win)); - Scale_sig(synth_bufFB_fx, 3136, sub(q_syn, q_win)); + Scale_sig( synth_buf_fx, 3136, sub( q_syn, q_win ) ); + Scale_sig( synth_bufFB_fx, 3136, sub( q_syn, q_win ) ); #endif - Scale_sig(st->syn, M + 1, st->Q_syn + 2); - Scale_sig(st->hTcxDec->syn_OverlFB, shr(L_FRAME_MAX, 1), sub(st->Q_syn, q_win)); - Scale_sig(st->hTcxDec->syn_Overl, shr(L_FRAME32k, 1), sub(st->Q_syn, q_win)); - Scale_sig(st->hHQ_core->old_out_LB_fx, L_FRAME32k, sub(st->Q_syn, q_win)); - Scale_sig(st->hHQ_core->old_out_fx, L_FRAME48k, sub(st->Q_syn, q_win)); + Scale_sig( st->syn, M + 1, st->Q_syn + 2 ); + Scale_sig( st->hTcxDec->syn_OverlFB, shr( L_FRAME_MAX, 1 ), sub( st->Q_syn, q_win ) ); + Scale_sig( st->hTcxDec->syn_Overl, shr( L_FRAME32k, 1 ), sub( st->Q_syn, q_win ) ); + Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( st->Q_syn, q_win ) ); + Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, sub( st->Q_syn, q_win ) ); } ELSE /*ACELP core for ACELP-PLC */ { - assert( EQ_16(st->bfi, 1) ); + assert( EQ_16( st->bfi, 1 ) ); /* PLC: [TCX: TD PLC] */ - IF ( NE_16(MCT_flag , 0) ) + IF( NE_16( MCT_flag, 0 ) ) { con_tcx_fx( st, &synthFB_fx[0] /*, -1.f, NULL, 0, NULL */ ); } @@ -1944,15 +1944,14 @@ void ivas_mdct_core_reconstruct_fx( con_tcx_ivas_fx( st, &synthFB_fx[0], hCPE->hStereoMdct->lastCoh_fx, &sts[0]->seed_acelp, ( sts[1]->core != ACELP_CORE ) ? 1 : 0, &st->hFdCngDec->hFdCngCom->A_cng[0] ); } - Scale_sig(synthFB_fx, st->hTcxDec->L_frameTCX, q_syn); - IF( ( EQ_16( st->nbLostCmpt, 1 ) ) || NE_16(st->hTcxDec->tcxConceal_recalc_exc, 0) ) + Scale_sig( synthFB_fx, st->hTcxDec->L_frameTCX, q_syn ); + IF( ( EQ_16( st->nbLostCmpt, 1 ) ) || NE_16( st->hTcxDec->tcxConceal_recalc_exc, 0 ) ) { - Scale_sig(synthFB_fx - (st->hTcxDec->L_frameTCX / 2 + st->hTcxDec->pit_max_TCX + 2 * M), sub(q_syn, st->Q_exc - 1), st->hTcxDec->L_frameTCX / 2 + st->hTcxDec->pit_max_TCX + 2 * M); + Scale_sig( synthFB_fx - ( st->hTcxDec->L_frameTCX / 2 + st->hTcxDec->pit_max_TCX + 2 * M ), sub( q_syn, st->Q_exc - 1 ), st->hTcxDec->L_frameTCX / 2 + st->hTcxDec->pit_max_TCX + 2 * M ); } ELSE { - Scale_sig(synthFB_fx - st->hTcxDec->L_frameTCX, sub(q_syn, st->Q_exc - 1), st->hTcxDec->L_frameTCX); - + Scale_sig( synthFB_fx - st->hTcxDec->L_frameTCX, sub( q_syn, st->Q_exc - 1 ), st->hTcxDec->L_frameTCX ); } lerp( synthFB_fx, synth_fx, st->L_frame, st->hTcxDec->L_frameTCX ); @@ -1961,12 +1960,12 @@ void ivas_mdct_core_reconstruct_fx( /* PLC: [TCX: Tonal Concealment] */ /* Signal that this frame is not TCX */ - IF ( st->hTonalMDCTConc != NULL ) + IF( st->hTonalMDCTConc != NULL ) { TonalMDCTConceal_UpdateState( st->hTonalMDCTConc, 0, 0, 0, 0 ); } - Scale_sig(st->mem_syn2_fx, M, st->Q_syn); - Scale_sig(st->mem_syn_r, M, st->Q_syn); + Scale_sig( st->mem_syn2_fx, M, st->Q_syn ); + Scale_sig( st->mem_syn_r, M, st->Q_syn ); } /*--------------------------------------------------------------------------------* @@ -1975,16 +1974,16 @@ void ivas_mdct_core_reconstruct_fx( st = sts[ch]; - IF ( NE_16(bfi, 0) && NE_16(st->last_core, ACELP_CORE) && EQ_16(st->core, ACELP_CORE) ) + IF( NE_16( bfi, 0 ) && NE_16( st->last_core, ACELP_CORE ) && EQ_16( st->core, ACELP_CORE ) ) { /* Update FEC_scale_syn parameters */ - IF ( EQ_16(st->hTcxLtpDec->tcxltp_gain, 0) ) + IF( EQ_16( st->hTcxLtpDec->tcxltp_gain, 0 ) ) { - frame_ener_fx( st->L_frame, UNVOICED, synth_fx, shr(st->L_frame, 1), &st->enr_old_fx, st->L_frame, 0, 0, 0 ); + frame_ener_fx( st->L_frame, UNVOICED, synth_fx, shr( st->L_frame, 1 ), &st->enr_old_fx, st->L_frame, 0, 0, 0 ); } ELSE { - frame_ener_fx( st->L_frame, st->clas_dec, synth_fx, extract_l( L_shr(st->old_fpitch, 16)), &st->enr_old_fx, st->L_frame, 0, 0, 0 ); + frame_ener_fx( st->L_frame, st->clas_dec, synth_fx, extract_l( L_shr( st->old_fpitch, 16 ) ), &st->enr_old_fx, st->L_frame, 0, 0, 0 ); } } @@ -1992,8 +1991,8 @@ void ivas_mdct_core_reconstruct_fx( Copy( synth_buf_fx + st->L_frame, st->hTcxDec->old_synth, st->hTcxDec->old_synth_len ); Copy( st->hTcxDec->old_synthFB_fx + st->hTcxDec->L_frameTCX - NS2SA( st->output_Fs, PH_ECU_MEM_NS ), st->hTcxDec->synth_history_fx, NS2SA( st->output_Fs, PH_ECU_MEM_NS ) ); mvs2s( synth_bufFB_fx + st->hTcxDec->L_frameTCX, st->hTcxDec->old_synthFB_fx, st->hTcxDec->old_synth_lenFB ); - Scale_sig(st->hTcxDec->old_synthFB_fx, st->hTcxDec->old_synth_lenFB, sub(st->Q_syn, q_syn)); - IF ( st->hHQ_core != NULL ) + Scale_sig( st->hTcxDec->old_synthFB_fx, st->hTcxDec->old_synth_lenFB, sub( st->Q_syn, q_syn ) ); + IF( st->hHQ_core != NULL ) { mvs2s( st->hHQ_core->old_out_fx + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), st->hTcxDec->old_synthFB_fx + st->hTcxDec->old_synth_lenFB, NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ); } @@ -2004,7 +2003,7 @@ void ivas_mdct_core_reconstruct_fx( /* Postfiltering */ Word16 x_fx_16[1200]; - Copy_Scale_sig_32_16(x_fx[ch][0], x_fx_16, st->L_frame, sub(0, q_x)); + Copy_Scale_sig_32_16( x_fx[ch][0], x_fx_16, st->L_frame, sub( 0, q_x ) ); IF( st->p_bpf_noise_buf_32 ) { Copy_Scale_sig_32_16( st->p_bpf_noise_buf_32, st->p_bpf_noise_buf, st->L_frame, negate( Q11 ) ); @@ -2016,22 +2015,21 @@ void ivas_mdct_core_reconstruct_fx( { Copy_Scale_sig_16_32_no_sat( st->p_bpf_noise_buf, st->p_bpf_noise_buf_32, st->L_frame, Q11 ); } - IF ( signal_outFB_fx[ch] != NULL ) + IF( signal_outFB_fx[ch] != NULL ) { - Copy_Scale_sig( synthFB_fx, signal_outFB_fx[ch], st->hTcxDec->L_frameTCX, sub(sub(15, e_sig), q_syn) ); - //Scale_sig(signal_outFB_fx[ch], st->hTcxDec->L_frameTCX, sub(sub(15, e_sig), q_syn)); + Copy_Scale_sig( synthFB_fx, signal_outFB_fx[ch], st->hTcxDec->L_frameTCX, sub( sub( 15, e_sig ), q_syn ) ); + // Scale_sig(signal_outFB_fx[ch], st->hTcxDec->L_frameTCX, sub(sub(15, e_sig), q_syn)); } /* updates */ st->last_voice_factor_fx = 0; st->last_coder_type = st->coder_type; - Copy_Scale_sig_16_32( x_fx_16, x_fx[ch][0], st->L_frame, sub(q_x, 0) ); - + Copy_Scale_sig_16_32( x_fx_16, x_fx[ch][0], st->L_frame, sub( q_x, 0 ) ); } /* calculate coherence of signal needed when next frame is lost */ - IF ( EQ_16(bfi, 0) && EQ_16(MCT_flag, 0) && EQ_16(hCPE->element_mode, IVAS_CPE_MDCT) ) + IF( EQ_16( bfi, 0 ) && EQ_16( MCT_flag, 0 ) && EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) ) { Word16 i; Word64 nrgL_fx, nrgR_fx, xcorr_fx; @@ -2042,32 +2040,34 @@ void ivas_mdct_core_reconstruct_fx( nrgR_fx = EPSILON_FX; xcorr_fx = EPSILON_FX; - move32(); move32(); move32(); + move32(); + move32(); + move32(); - FOR ( i = 0; i < sts[0]->hTcxDec->L_frameTCX; i++ ) + FOR( i = 0; i < sts[0]->hTcxDec->L_frameTCX; i++ ) { - nrgL_fx = W_add(nrgL_fx, L_mult0(signal_outFB_fx[0][i], signal_outFB_fx[0][i])); - nrgR_fx = W_add(nrgR_fx, L_mult0(signal_outFB_fx[1][i], signal_outFB_fx[1][i])); - xcorr_fx = W_add(xcorr_fx, L_mult0(signal_outFB_fx[0][i], signal_outFB_fx[1][i])); + nrgL_fx = W_add( nrgL_fx, L_mult0( signal_outFB_fx[0][i], signal_outFB_fx[0][i] ) ); + nrgR_fx = W_add( nrgR_fx, L_mult0( signal_outFB_fx[1][i], signal_outFB_fx[1][i] ) ); + xcorr_fx = W_add( xcorr_fx, L_mult0( signal_outFB_fx[0][i], signal_outFB_fx[1][i] ) ); } - e_nrgL = add(33, shl(e_sig, 1)); + e_nrgL = add( 33, shl( e_sig, 1 ) ); e_nrgR = e_nrgL; move16(); e_xcorr = e_nrgL; move16(); - tmp = W_norm(nrgL_fx); - nrgL_fx = W_shl(nrgL_fx, tmp); - e_nrgL = sub(e_nrgL, tmp); - tmp = W_norm(nrgR_fx); - nrgR_fx = W_shl(nrgR_fx, tmp); - e_nrgR = sub(e_nrgR, tmp); - tmp = W_norm(xcorr_fx); - xcorr_fx = W_shl(xcorr_fx, tmp); - e_xcorr = sub(e_xcorr, tmp); - L_tmp = Mpy_32_32(W_extract_h(nrgL_fx), W_extract_h(nrgR_fx)); - e_tmp = add(e_nrgL, e_nrgR); - L_tmp = ISqrt32(L_tmp, &e_tmp); - hCPE->hStereoMdct->lastCoh_fx = extract_l(L_shr(Mpy_32_32(L_abs(W_extract_h(xcorr_fx)), L_tmp), sub(17, add(e_xcorr, e_tmp)))); + tmp = W_norm( nrgL_fx ); + nrgL_fx = W_shl( nrgL_fx, tmp ); + e_nrgL = sub( e_nrgL, tmp ); + tmp = W_norm( nrgR_fx ); + nrgR_fx = W_shl( nrgR_fx, tmp ); + e_nrgR = sub( e_nrgR, tmp ); + tmp = W_norm( xcorr_fx ); + xcorr_fx = W_shl( xcorr_fx, tmp ); + e_xcorr = sub( e_xcorr, tmp ); + L_tmp = Mpy_32_32( W_extract_h( nrgL_fx ), W_extract_h( nrgR_fx ) ); + e_tmp = add( e_nrgL, e_nrgR ); + L_tmp = ISqrt32( L_tmp, &e_tmp ); + hCPE->hStereoMdct->lastCoh_fx = extract_l( L_shr( Mpy_32_32( L_abs( W_extract_h( xcorr_fx ) ), L_tmp ), sub( 17, add( e_xcorr, e_tmp ) ) ) ); hCPE->hStereoMdct->lastCoh_fx = s_min( hCPE->hStereoMdct->lastCoh_fx, 16384 ); } @@ -2168,9 +2168,10 @@ void ivas_mdct_core_tns_ns( f2me_16( sns_int_scf[j], &scf_fx[j], &scf_e[j] ); }*/ Word16 q_shift; - FOR(Word16 ind = 0; ind < st->hTonalMDCTConc->nScaleFactors; ind++) { - q_shift = norm_l(sns_int_scf_fx[ind]); - scf_fx[ind] = extract_h(L_shl(sns_int_scf_fx[ind], q_shift)); + FOR( Word16 ind = 0; ind < st->hTonalMDCTConc->nScaleFactors; ind++ ) + { + q_shift = norm_l( sns_int_scf_fx[ind] ); + scf_fx[ind] = extract_h( L_shl( sns_int_scf_fx[ind], q_shift ) ); scf_e[ind] = 15 - q_shift; } /*float maxim = 0; @@ -2184,7 +2185,7 @@ void ivas_mdct_core_tns_ns( x_e = 31 - q_x;*/ TonalMDCTConceal_SaveFreqSignal_ivas_fx( st->hTonalMDCTConc, x_fx, x_e, L_frameTCX[ch], L_frame[ch], &scf_fx[0], scf_e, 0, get_igf_startline( st, L_frame[ch], L_frameTCX[ch] ) ); - //st->hTonalMDCTConc->last_block_nrg_flt = me2f( st->hTonalMDCTConc->last_block_nrg, st->hTonalMDCTConc->last_block_nrg_exp ); + // st->hTonalMDCTConc->last_block_nrg_flt = me2f( st->hTonalMDCTConc->last_block_nrg, st->hTonalMDCTConc->last_block_nrg_exp ); #else TonalMDCTConceal_SaveFreqSignal_ivas( st->hTonalMDCTConc, x[ch][k], L_frameTCX[ch], L_frame[ch], &sns_int_scf[0], get_igf_startline_flt( st, L_frame[ch], L_frameTCX[ch] ) ); #endif @@ -2195,7 +2196,7 @@ void ivas_mdct_core_tns_ns( if ( st->hTonalMDCTConc != NULL ) { if ( !MCT_flag && st->hTcxDec->cummulative_damping_tcx_float < 0.99f ) - //if ( !MCT_flag && st->hTcxDec->cummulative_damping_tcx_float != 1.f ) + // if ( !MCT_flag && st->hTcxDec->cummulative_damping_tcx_float != 1.f ) { float *scf_last, *scf_bg; float fade_in, fade_out; @@ -2225,11 +2226,15 @@ void ivas_mdct_core_tns_ns( Word32 x_fx_[1200]; Word16 q = 26; float maximum = 0; - FOR(Word16 ind = 0; ind < st->hTcxCfg->pCurrentTnsConfig->iFilterBorders[0]; ind++) maximum = fmaxf(maximum, fabsf(x[ch][k][ind])); - if(maximum>=1.f) q = norm_l((Word32)maximum) - 5; - FOR(Word16 ind = 0; ind < s_max(s_max(L_frameTCX[ch], L_spec[ch]), st->hTcxCfg->pCurrentTnsConfig->iFilterBorders[0]); ind++) x_fx_[ind] = (Word32)(x[ch][k][ind] * (1 << q)); + FOR( Word16 ind = 0; ind < st->hTcxCfg->pCurrentTnsConfig->iFilterBorders[0]; ind++ ) + maximum = fmaxf( maximum, fabsf( x[ch][k][ind] ) ); + if ( maximum >= 1.f ) + q = norm_l( (Word32) maximum ) - 5; + FOR( Word16 ind = 0; ind < s_max( s_max( L_frameTCX[ch], L_spec[ch] ), st->hTcxCfg->pCurrentTnsConfig->iFilterBorders[0] ); ind++ ) + x_fx_[ind] = (Word32) ( x[ch][k][ind] * ( 1 << q ) ); decoder_tcx_tns_fx( st, L_frame_global[ch], L_spec[ch], L_frame[ch], L_frameTCX[ch], x_fx_, fUseTns[ch][k], &tnsData[ch][k], bfi, k, 1 ); - FOR(Word16 ind = 0; ind < s_max(s_max(L_frameTCX[ch], L_spec[ch]), st->hTcxCfg->pCurrentTnsConfig->iFilterBorders[0]); ind++) x[ch][k][ind] = (float)(x_fx_[ind]) / (float)(1 << q); + FOR( Word16 ind = 0; ind < s_max( s_max( L_frameTCX[ch], L_spec[ch] ), st->hTcxCfg->pCurrentTnsConfig->iFilterBorders[0] ); ind++ ) + x[ch][k][ind] = (float) ( x_fx_[ind] ) / (float) ( 1 << q ); #else decoder_tcx_tns( st, L_frame_global[ch], L_spec[ch], L_frame[ch], L_frameTCX[ch], &x[ch][k][0], fUseTns[ch][k], &tnsData[ch][k], bfi, k, 1 ); #endif @@ -2240,12 +2245,12 @@ void ivas_mdct_core_tns_ns( FOR( Word16 c = 0; c < L_FRAME16k; c++ ) { if ( abs( (Word32) x[ch][k][c] ) != 0 ) - q_x = s_min( q_x, norm_l( (Word32)x[ch][k][c] ) ); + q_x = s_min( q_x, norm_l( (Word32) x[ch][k][c] ) ); } FOR( Word16 c = 0; c < FDNS_NPTS; c++ ) { if ( abs( (Word32) sns_int_scf[c] ) != 0 ) - q_sns_int_scf = s_min( q_sns_int_scf, norm_l( (Word32)sns_int_scf[c] ) ); + q_sns_int_scf = s_min( q_sns_int_scf, norm_l( (Word32) sns_int_scf[c] ) ); } q_x -= 1; q_sns_int_scf -= 1; @@ -2260,7 +2265,7 @@ void ivas_mdct_core_tns_ns( sns_shape_spectrum_fx( x_fx, &q_x, st->hTcxCfg->psychParamsCurrent, sns_int_scf_fx, q_sns_int_scf, st->hTcxCfg->psychParamsCurrent->nBins ); - IF ( q_x + 1 < 31 ) + IF( q_x + 1 < 31 ) { FOR( Word16 c = 0; c < st->hTcxCfg->psychParamsCurrent->nBins; c++ ) { @@ -2299,14 +2304,13 @@ void ivas_mdct_core_tns_ns( #ifdef IVAS_FLOAT_FIXED /* Has a missing dependency: TonalMDCTConceal_Apply. Currently not used anywhere and untested.*/ void ivas_mdct_core_tns_ns_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word16 fUseTns[CPE_CHANNELS][NB_DIV], /* i : two entries for each channel in TCX10 */ - STnsData tnsData[CPE_CHANNELS][NB_DIV], /* o : TNS parameter */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word16 fUseTns[CPE_CHANNELS][NB_DIV], /* i : two entries for each channel in TCX10 */ + STnsData tnsData[CPE_CHANNELS][NB_DIV], /* o : TNS parameter */ Word32 *x_fx[CPE_CHANNELS][NB_DIV], /* o : synthesis @internal_FS */ Word32 Aq_fx[CPE_CHANNELS][( NB_SUBFR16k + 1 ) * ( M + 1 )], /* o : LP coefficients */ - const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ - Word16 x_e[CPE_CHANNELS][NB_DIV] -) + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ + Word16 x_e[CPE_CHANNELS][NB_DIV] ) { Word16 ch, k, bfi; Decoder_State **sts, *st; @@ -2332,24 +2336,24 @@ void ivas_mdct_core_tns_ns_fx( /* TNS, ITF, IMDCT and updates */ - FOR ( ch = 0; ch < CPE_CHANNELS; ch++ ) + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { st = sts[ch]; nSubframes[ch] = EQ_16( st->core, TCX_20_CORE ) ? 1 : NB_DIV; move16(); - L_frame_global[ch] = BASOP_Util_Divide3216_Scale( st->L_frame, nSubframes[ch], &exp); + L_frame_global[ch] = BASOP_Util_Divide3216_Scale( st->L_frame, nSubframes[ch], &exp ); L_frame_global[ch] = shl( L_frame_global[ch], exp + 1 ); - L_frameTCX_glob[ch] = BASOP_Util_Divide3216_Scale(st->hTcxDec->L_frameTCX, nSubframes[ch], &exp); - L_frameTCX_glob[ch] = shl(L_frameTCX_glob[ch], exp + 1); + L_frameTCX_glob[ch] = BASOP_Util_Divide3216_Scale( st->hTcxDec->L_frameTCX, nSubframes[ch], &exp ); + L_frameTCX_glob[ch] = shl( L_frameTCX_glob[ch], exp + 1 ); - L_spec[ch] = BASOP_Util_Divide3216_Scale(st->hTcxCfg->tcx_coded_lines, nSubframes[ch], &exp); - L_spec[ch] = shl(L_spec[ch], exp + 1); + L_spec[ch] = BASOP_Util_Divide3216_Scale( st->hTcxCfg->tcx_coded_lines, nSubframes[ch], &exp ); + L_spec[ch] = shl( L_spec[ch], exp + 1 ); - IF ( ( st->mct_chan_mode == MCT_CHAN_MODE_IGNORE ) || ( NE_16(st->bfi, 0) && EQ_16(st->core, ACELP_CORE) ) ) /* indicates LFE with no content, or odd number of channels */ + IF( ( st->mct_chan_mode == MCT_CHAN_MODE_IGNORE ) || ( NE_16( st->bfi, 0 ) && EQ_16( st->core, ACELP_CORE ) ) ) /* indicates LFE with no content, or odd number of channels */ { - IF ( st->hTonalMDCTConc != NULL ) + IF( st->hTonalMDCTConc != NULL ) { TonalMDCTConceal_UpdateState( st->hTonalMDCTConc, st->hTcxDec->L_frameTCX, 0, bfi, 0 ); } @@ -2358,34 +2362,35 @@ void ivas_mdct_core_tns_ns_fx( continue; } - FOR ( k = 0; k < nSubframes[ch]; k++ ) + FOR( k = 0; k < nSubframes[ch]; k++ ) { init_tcx_info_fx( st, L_frame_global[ch], L_frameTCX_glob[ch], k, bfi, &tcx_offset[ch], - &tcx_offsetFB[ch], &L_frame[ch], &L_frameTCX[ch], &left_rect[ch], &L_spec[ch] ); + &tcx_offsetFB[ch], &L_frame[ch], &L_frameTCX[ch], &left_rect[ch], &L_spec[ch] ); Word16 q_x; - q_x = sub(31 , x_e[ch][k]); - IF ( EQ_16(bfi, 0) ) + q_x = sub( 31, x_e[ch][k] ); + IF( EQ_16( bfi, 0 ) ) { sns_interpolate_scalefactors_fx( sns_int_scf_fx, &Aq_fx[ch][k * M], DEC ); - IF ( NE_16(MCT_flag, 0) && st->hTonalMDCTConc != NULL && EQ_16( add( k, 1 ), nSubframes[ch] ) ) + IF( NE_16( MCT_flag, 0 ) && st->hTonalMDCTConc != NULL && EQ_16( add( k, 1 ), nSubframes[ch] ) ) { Word16 scf_fx[FDNS_NPTS], scf_e[FDNS_NPTS]; Word16 q_shift; - FOR(Word16 ind = 0; ind < st->hTonalMDCTConc->nScaleFactors; ind++) { - q_shift = norm_l(sns_int_scf_fx[ind]); - scf_fx[ind] = extract_h(L_shl(sns_int_scf_fx[ind], q_shift)); - scf_e[ind] = sub(15 , q_shift); + FOR( Word16 ind = 0; ind < st->hTonalMDCTConc->nScaleFactors; ind++ ) + { + q_shift = norm_l( sns_int_scf_fx[ind] ); + scf_fx[ind] = extract_h( L_shl( sns_int_scf_fx[ind], q_shift ) ); + scf_e[ind] = sub( 15, q_shift ); } TonalMDCTConceal_SaveFreqSignal_ivas_fx( st->hTonalMDCTConc, x_fx[ch][k], x_e[ch][k], L_frameTCX[ch], L_frame[ch], &scf_fx[0], scf_e, 0, get_igf_startline( st, L_frame[ch], L_frameTCX[ch] ) ); } } ELSE { - IF ( st->hTonalMDCTConc != NULL ) + IF( st->hTonalMDCTConc != NULL ) { - IF ( EQ_16(MCT_flag, 0) && LT_16(st->hTcxDec->cummulative_damping_tcx, 32440) ) + IF( EQ_16( MCT_flag, 0 ) && LT_16( st->hTcxDec->cummulative_damping_tcx, 32440 ) ) { Word16 *scf_last_m, *scf_last_e; Word32 *scf_bg; @@ -2395,38 +2400,38 @@ void ivas_mdct_core_tns_ns_fx( scf_last_e = &st->hTonalMDCTConc->lastBlockData.scaleFactors_exp[0]; scf_bg = &st->hTonalMDCTConc->scaleFactorsBackground_fx[0]; - st->hTonalMDCTConc->scf_fadeout = mult(st->hTonalMDCTConc->scf_fadeout, 31130); // 0.95 in Q15 = 31130 + st->hTonalMDCTConc->scf_fadeout = mult( st->hTonalMDCTConc->scf_fadeout, 31130 ); // 0.95 in Q15 = 31130 fade_out = st->hTonalMDCTConc->scf_fadeout; - fade_in = sub(32767 , fade_out); + fade_in = sub( 32767, fade_out ); - FOR ( Word16 i = 0; i < st->hTonalMDCTConc->nScaleFactors; i++ ) + FOR( Word16 i = 0; i < st->hTonalMDCTConc->nScaleFactors; i++ ) { - sns_int_scf_fx[i] = L_add(Mpy_32_16_1(L_shl(scf_last_m[i], 1 + scf_last_e[i]), fade_out), Mpy_32_16_1( L_shl(scf_bg[i], 1), fade_in)); + sns_int_scf_fx[i] = L_add( Mpy_32_16_1( L_shl( scf_last_m[i], 1 + scf_last_e[i] ), fade_out ), Mpy_32_16_1( L_shl( scf_bg[i], 1 ), fade_in ) ); } } ELSE { st->hTonalMDCTConc->scf_fadeout = 32767; - FOR(Word16 i = 0; i < st->hTonalMDCTConc->nScaleFactors; i++) + FOR( Word16 i = 0; i < st->hTonalMDCTConc->nScaleFactors; i++ ) { - sns_int_scf_fx[i] = L_shl(st->hTonalMDCTConc->lastBlockData.scaleFactors[i], 1 + st->hTonalMDCTConc->lastBlockData.scaleFactors_exp[i]); + sns_int_scf_fx[i] = L_shl( st->hTonalMDCTConc->lastBlockData.scaleFactors[i], 1 + st->hTonalMDCTConc->lastBlockData.scaleFactors_exp[i] ); } } } } Word16 norm_x; - q_x = sub(q_x,5); + q_x = sub( q_x, 5 ); Scale_sig32( &x_fx[ch][k][0], L_spec[ch], -5 ); decoder_tcx_tns_fx( st, L_frame_global[ch], L_spec[ch], L_frame[ch], L_frameTCX[ch], x_fx[ch][k], fUseTns[ch][k], &tnsData[ch][k], bfi, k, 1 ); norm_x = getScaleFactor32( &x_fx[ch][k][0], L_spec[ch] ); Scale_sig32( &x_fx[ch][k][0], L_spec[ch], norm_x ); - q_x = add(q_x,norm_x); - x_e[ch][k] = sub(31 , q_x); + q_x = add( q_x, norm_x ); + x_e[ch][k] = sub( 31, q_x ); Word16 q_sns_int_scf; Word16 q_2; - q_sns_int_scf = add(16 - 1 , getScaleFactor32( sns_int_scf_fx, FDNS_NPTS )); + q_sns_int_scf = add( 16 - 1, getScaleFactor32( sns_int_scf_fx, FDNS_NPTS ) ); // q_sns_int_scf -= 1; FOR( Word16 c = 0; c < FDNS_NPTS; c++ ) { @@ -2434,48 +2439,48 @@ void ivas_mdct_core_tns_ns_fx( } q_2 = q_x; sns_shape_spectrum_fx( x_fx[ch][k], &q_x, st->hTcxCfg->psychParamsCurrent, sns_int_scf_fx, q_sns_int_scf, st->hTcxCfg->psychParamsCurrent->nBins ); - IF ( LT_16(q_2 , add( q_x , 1 )) ) /*scaling to q_2*/ + IF( LT_16( q_2, add( q_x, 1 ) ) ) /*scaling to q_2*/ { - Scale_sig32( &x_fx[ch][k][0],st->hTcxCfg->psychParamsCurrent->nBins, q_2 - q_x - 1 ); + Scale_sig32( &x_fx[ch][k][0], st->hTcxCfg->psychParamsCurrent->nBins, q_2 - q_x - 1 ); q_x = q_2; } ELSE /*scaling to q_x+1*/ { Scale_sig32( &x_fx[ch][k][0] + st->hTcxCfg->psychParamsCurrent->nBins, L_spec[ch] - st->hTcxCfg->psychParamsCurrent->nBins, q_x + 1 - q_2 ); - q_x = add(q_x , 1); + q_x = add( q_x, 1 ); } - x_e[ch][k] = sub(31 , q_x); + x_e[ch][k] = sub( 31, q_x ); v_multc_fixed( x_fx[ch][k] + st->hTcxCfg->psychParamsCurrent->nBins, sns_int_scf_fx[FDNS_NPTS - 1], x_fx[ch][k] + st->hTcxCfg->psychParamsCurrent->nBins, L_spec[ch] - st->hTcxCfg->psychParamsCurrent->nBins ); - q_2 = sub(add(q_x , q_sns_int_scf) , 31); + q_2 = sub( add( q_x, q_sns_int_scf ), 31 ); Scale_sig32( &x_fx[ch][k][0], st->hTcxCfg->psychParamsCurrent->nBins, q_2 - q_x ); q_x = q_2; - x_e[ch][k] = sub(31 , q_x); + x_e[ch][k] = sub( 31, q_x ); - q_x = sub(q_x,5); + q_x = sub( q_x, 5 ); Scale_sig32( &x_fx[ch][k][0], L_spec[ch], -5 ); decoder_tcx_tns_fx( st, L_frame_global[ch], L_spec[ch], L_frame[ch], L_frameTCX[ch], &x_fx[ch][k][0], fUseTns[ch][k], &tnsData[ch][k], bfi, k, 0 ); norm_x = getScaleFactor32( &x_fx[ch][k][0], L_spec[ch] ); Scale_sig32( &x_fx[ch][k][0], L_spec[ch], norm_x ); - q_x = add(q_x,norm_x); - x_e[ch][k] = sub(31 , q_x); + q_x = add( q_x, norm_x ); + x_e[ch][k] = sub( 31, q_x ); } - IF ( NE_16(bfi, 0) && NE_16(st->tonal_mdct_plc_active, 0) ) + IF( NE_16( bfi, 0 ) && NE_16( st->tonal_mdct_plc_active, 0 ) ) { Word16 q_x, q_x_old; FOR( Word16 i = 0; i < FDNS_NPTS; i++ ) { st->hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e = s_max( st->hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e, st->hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[i] ); } - q_x_old = sub(31 , x_e[ch][0]); + q_x_old = sub( 31, x_e[ch][0] ); TonalMDCTConceal_Apply_ivas_fx( st->hTonalMDCTConc, x_fx[ch][0], &x_e[ch][0], st->hTcxCfg->psychParamsCurrent ); - q_x = sub(31 , x_e[ch][0]); + q_x = sub( 31, x_e[ch][0] ); // Fix to float - IF( LT_16(q_x_old , q_x) ) + IF( LT_16( q_x_old, q_x ) ) { - x_e[ch][0] = sub(31 , q_x_old); + x_e[ch][0] = sub( 31, q_x_old ); FOR( Word16 i = 0; i < st->hTonalMDCTConc->pTCI->numIndexes; i++ ) { FOR( Word16 l = st->hTonalMDCTConc->pTCI->lowerIndex[i]; l <= st->hTonalMDCTConc->pTCI->upperIndex[i]; l++ ) @@ -2486,28 +2491,27 @@ void ivas_mdct_core_tns_ns_fx( } ELSE { - x_e[ch][0] = sub(31 , q_x); + x_e[ch][0] = sub( 31, q_x ); FOR( Word16 i = 0; i < st->hTonalMDCTConc->pTCI->numIndexes; i++ ) { FOR( Word16 l = 0; l < st->hTonalMDCTConc->pTCI->lowerIndex[i]; l++ ) { - x_fx[ch][0][l] = L_shr( x_fx[ch][0][l], sub(q_x_old , q_x) ); + x_fx[ch][0][l] = L_shr( x_fx[ch][0][l], sub( q_x_old, q_x ) ); } FOR( Word16 l = st->hTonalMDCTConc->pTCI->upperIndex[i] + 1; l < L_spec[ch]; l++ ) { - x_fx[ch][0][l] = L_shr( x_fx[ch][0][l], sub(q_x_old , q_x) ); + x_fx[ch][0][l] = L_shr( x_fx[ch][0][l], sub( q_x_old, q_x ) ); } } } } - IF ( ( bfi || MCT_flag ) && st->hTonalMDCTConc != NULL ) + IF( ( bfi || MCT_flag ) && st->hTonalMDCTConc != NULL ) { TonalMDCTConceal_UpdateState( st->hTonalMDCTConc, L_frameTCX[ch], ( st->hTcxDec->tcxltp_last_gain_unmodified > 0 ) ? st->old_fpitch : 0, bfi, bfi && st->tonal_mdct_plc_active ); } } return; - } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/ivas_objectRenderer_internal.c b/lib_dec/ivas_objectRenderer_internal.c index 3186bead6..aeb119af8 100644 --- a/lib_dec/ivas_objectRenderer_internal.c +++ b/lib_dec/ivas_objectRenderer_internal.c @@ -56,13 +56,12 @@ #ifdef IVAS_FLOAT_FIXED ivas_error ivas_td_binaural_open_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - Word16 * SrcInd, /*Temporarily used to store the updated value of SrcInd*/ - Word16 *num_src -) + Word16 *SrcInd, /*Temporarily used to store the updated value of SrcInd*/ + Word16 *num_src ) { *num_src = st_ivas->nchan_transport; move16(); - IF ( EQ_16( st_ivas->ism_mode , ISM_MASA_MODE_DISC ) || EQ_16( st_ivas->ism_mode , ISM_SBA_MODE_DISC ) ) + IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { *num_src = st_ivas->nchan_ism; move16(); @@ -97,17 +96,17 @@ ivas_error ivas_td_binaural_open( #ifdef IVAS_FLOAT_FIXED ivas_error ivas_td_binaural_renderer_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - Word32 *output[], /* i/o: SCE channels / Binaural synthesis */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Word32 *output[], /* i/o: SCE channels / Binaural synthesis */ const Word16 output_frame /* i : output frame length */ ) { Word16 ism_md_subframe_update; Word16 nchan_transport; test(); - nchan_transport = (EQ_16(st_ivas->ism_mode , ISM_MASA_MODE_DISC) || EQ_16(st_ivas->ism_mode , ISM_SBA_MODE_DISC)) ? st_ivas->nchan_ism : st_ivas->nchan_transport; + nchan_transport = ( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) ? st_ivas->nchan_ism : st_ivas->nchan_transport; - IF (st_ivas->hDecoderConfig->Opt_delay_comp) + IF( st_ivas->hDecoderConfig->Opt_delay_comp ) { ism_md_subframe_update = 1; } @@ -116,12 +115,12 @@ ivas_error ivas_td_binaural_renderer_fx( ism_md_subframe_update = 2; } - IF (EQ_16(st_ivas->ivas_format , MASA_ISM_FORMAT)) + IF( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) { ism_md_subframe_update = 2; } - return ivas_td_binaural_renderer_unwrap_fx(st_ivas->hReverb, st_ivas->transport_config, st_ivas->hBinRendererTd, nchan_transport, LFE_CHANNEL, st_ivas->ivas_format, st_ivas->hIsmMetaData, st_ivas->hCombinedOrientationData, ism_md_subframe_update, output, output_frame, MAX_PARAM_SPATIAL_SUBFRAMES); + return ivas_td_binaural_renderer_unwrap_fx( st_ivas->hReverb, st_ivas->transport_config, st_ivas->hBinRendererTd, nchan_transport, LFE_CHANNEL, st_ivas->ivas_format, st_ivas->hIsmMetaData, st_ivas->hCombinedOrientationData, ism_md_subframe_update, output, output_frame, MAX_PARAM_SPATIAL_SUBFRAMES ); } #else ivas_error ivas_td_binaural_renderer( @@ -303,10 +302,10 @@ ivas_error ivas_td_binaural_renderer_sf_fx( /* Shifting x_fx, y_fx, z_fx to the same Q-factor as Listener_p->Pos_q (usually Q25) */ Word16 pos_q = st_ivas->hBinRendererTd->Listener_p->Pos_q; move16(); - tmp_vector_fx->x_fx = L_shr( tmp_vector_fx->x_fx, sub( tmp_vector_fx->q_fact, pos_q ) ); - tmp_vector_fx->y_fx = L_shr( tmp_vector_fx->y_fx, sub( tmp_vector_fx->q_fact, pos_q ) ); - tmp_vector_fx->z_fx = L_shr( tmp_vector_fx->z_fx, sub( tmp_vector_fx->q_fact, pos_q ) ); - tmp_vector_fx->q_fact = pos_q; + tmp_vector_fx->x_fx = L_shr( tmp_vector_fx->x_fx, sub( tmp_vector_fx->q_fact, pos_q ) ); + tmp_vector_fx->y_fx = L_shr( tmp_vector_fx->y_fx, sub( tmp_vector_fx->q_fact, pos_q ) ); + tmp_vector_fx->z_fx = L_shr( tmp_vector_fx->z_fx, sub( tmp_vector_fx->q_fact, pos_q ) ); + tmp_vector_fx->q_fact = pos_q; } ELSE { diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index da4195bf3..fb302068d 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -51,7 +51,7 @@ * Local constants *------------------------------------------------------------------------*/ -#define OMASA_TDREND_MATCHING_GAIN 0.7943f +#define OMASA_TDREND_MATCHING_GAIN 0.7943f #define OMASA_TDREND_MATCHING_GAIN_FX 26026 /*-------------------------------------------------------------------* @@ -251,9 +251,9 @@ void ivas_omasa_data_close_fx( ivas_error ivas_omasa_dec_config_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ UWord16 *nSamplesRendered, /* o : number of samples flushed from the previous frame (JBM) */ - Word16 *num_src, - Word16 SrcInd[MAX_NUM_TDREND_CHANNELS], - Word16 *data /* o : output synthesis signal */ + Word16 *num_src, + Word16 SrcInd[MAX_NUM_TDREND_CHANNELS], + Word16 *data /* o : output synthesis signal */ ) { Word16 k, sce_id, nSCE_old, nchan_hp20_old, numCldfbAnalyses_old, numCldfbSyntheses_old, n_MD; @@ -306,14 +306,17 @@ ivas_error ivas_omasa_dec_config_fx( /* MASA reconfig. */ cpe_brate = calculate_cpe_brate_MASA_ISM_fx( st_ivas->ism_mode, ivas_total_brate, st_ivas->nchan_ism ); move32(); - test(); test(); test(); - IF ( st_ivas->ini_active_frame == 0 && NE_32(ivas_total_brate, FRAME_NO_DATA ) && LT_32( cpe_brate, MASA_STEREO_MIN_BITRATE ) && EQ_16( st_ivas->nCPE, 1 ) ) + test(); + test(); + test(); + IF( st_ivas->ini_active_frame == 0 && NE_32( ivas_total_brate, FRAME_NO_DATA ) && LT_32( cpe_brate, MASA_STEREO_MIN_BITRATE ) && EQ_16( st_ivas->nCPE, 1 ) ) { st_ivas->hCPE[0]->nchan_out = 1; move16(); } - ELSE{ - IF((error = ivas_masa_dec_reconfigure_fx(st_ivas, nSamplesRendered, data)) != IVAS_ERR_OK) + ELSE + { + IF( ( error = ivas_masa_dec_reconfigure_fx( st_ivas, nSamplesRendered, data ) ) != IVAS_ERR_OK ) { return error; } @@ -351,19 +354,19 @@ ivas_error ivas_omasa_dec_config_fx( /* reconfigure core-coders for ISMs */ k = 0; move16(); - WHILE( LT_16(k, SIZE_IVAS_BRATE_TBL) && NE_32( ivas_total_brate, ivas_brate_tbl[k] ) ) + WHILE( LT_16( k, SIZE_IVAS_BRATE_TBL ) && NE_32( ivas_total_brate, ivas_brate_tbl[k] ) ) { - k = add(k, 1); + k = add( k, 1 ); } FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { - ism_total_brate = L_add(ism_total_brate, sep_object_brate[k - 2][st_ivas->nSCE - 1]); + ism_total_brate = L_add( ism_total_brate, sep_object_brate[k - 2][st_ivas->nSCE - 1] ); } brate_SCE = 0; move32(); - IF( GT_16( st_ivas->nSCE, 0 )) + IF( GT_16( st_ivas->nSCE, 0 ) ) { brate_SCE = sep_object_brate[k - 2][st_ivas->nSCE - 1]; move32(); @@ -381,7 +384,7 @@ ivas_error ivas_omasa_dec_config_fx( } #endif - IF ( NE_16(ism_mode_old, st_ivas->ism_mode) ) + IF( NE_16( ism_mode_old, st_ivas->ism_mode ) ) { /* ISM MD reconfig. */ n_MD = 0; @@ -416,7 +419,7 @@ ivas_error ivas_omasa_dec_config_fx( ivas_ism_metadata_close( st_ivas->hIsmMetaData, n_MD ); - st_ivas->hCPE[0]->element_brate = L_sub( ivas_total_brate, ism_total_brate); + st_ivas->hCPE[0]->element_brate = L_sub( ivas_total_brate, ism_total_brate ); /*-----------------------------------------------------------------* * Renderer selection @@ -454,7 +457,7 @@ ivas_error ivas_omasa_dec_config_fx( IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { /* Allocate TD renderer for the objects in DISC mode */ - IF ( ( error = ivas_td_binaural_open_fx( st_ivas, SrcInd, num_src ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_td_binaural_open_fx( st_ivas, SrcInd, num_src ) ) != IVAS_ERR_OK ) { return error; } @@ -516,7 +519,7 @@ ivas_error ivas_omasa_dec_config_fx( * CLDFB instances *-----------------------------------------------------------------*/ - IF ( ( error = ivas_cldfb_dec_reconfig_fx( st_ivas, 2, numCldfbAnalyses_old, numCldfbSyntheses_old) ) != IVAS_ERR_OK ) + IF( ( error = ivas_cldfb_dec_reconfig_fx( st_ivas, 2, numCldfbAnalyses_old, numCldfbSyntheses_old ) ) != IVAS_ERR_OK ) { return error; } @@ -544,7 +547,7 @@ ivas_error ivas_omasa_dec_config_fx( ivas_error ivas_omasa_dec_config( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ uint16_t *nSamplesRendered, /* o : number of samples flushed from the previous frame (JBM) */ - int16_t *data /* o : output synthesis signal */ + int16_t *data /* o : output synthesis signal */ ) { int16_t k, sce_id, nSCE_old, nchan_hp20_old, numCldfbAnalyses_old, numCldfbSyntheses_old, n_MD; @@ -872,7 +875,7 @@ void ivas_set_surplus_brate_dec( #else void ivas_set_surplus_brate_dec( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - Word32 *ism_total_brate /* i/o: ISM total bitrate */ + Word32 *ism_total_brate /* i/o: ISM total bitrate */ ) { Word16 n, bits_ism, bits_element[MAX_NUM_OBJECTS]; @@ -882,11 +885,11 @@ void ivas_set_surplus_brate_dec( move32(); test(); - IF ( EQ_32(st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ) || EQ_32(st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ) ) + IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) { *ism_total_brate = ivas_interformat_brate( st_ivas->ism_mode, 1, st_ivas->hSCE[0]->element_brate, st_ivas->hIsmMetaData[0]->ism_imp, 0 ); - st_ivas->hCPE[0]->brate_surplus = L_sub(st_ivas->hSCE[0]->element_brate, *ism_total_brate); + st_ivas->hCPE[0]->brate_surplus = L_sub( st_ivas->hSCE[0]->element_brate, *ism_total_brate ); /* set 'st->total_brate'; there are no meta-data in ISM_MASA_MODE_PARAM_ONE_OBJ mode */ st_ivas->hSCE[0]->hCoreCoder[0]->total_brate = *ism_total_brate; @@ -894,17 +897,17 @@ void ivas_set_surplus_brate_dec( st_ivas->hSCE[0]->hCoreCoder[0]->low_rate_mode = 0; move16(); - IF ( EQ_16( st_ivas->hIsmMetaData[0]->ism_imp, ISM_NO_META ) ) + IF( EQ_16( st_ivas->hIsmMetaData[0]->ism_imp, ISM_NO_META ) ) { st_ivas->hSCE[0]->hCoreCoder[0]->low_rate_mode = 1; move16(); } } - ELSE IF ( EQ_32(st_ivas->ism_mode, ISM_MASA_MODE_DISC) ) + ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { Word16 brate_limit_flag, ism_imp[MAX_NUM_OBJECTS], tmp; - FOR ( n = 0; n < st_ivas->nchan_ism; n++ ) + FOR( n = 0; n < st_ivas->nchan_ism; n++ ) { ism_imp[n] = st_ivas->hIsmMetaData[n]->ism_imp; move16(); @@ -915,44 +918,46 @@ void ivas_set_surplus_brate_dec( ism_total_brate_ref = 0; move32(); - FOR ( n = 0; n < st_ivas->nchan_ism; n++ ) + FOR( n = 0; n < st_ivas->nchan_ism; n++ ) { - ism_total_brate_ref = L_add(ism_total_brate_ref, st_ivas->hSCE[n]->element_brate); + ism_total_brate_ref = L_add( ism_total_brate_ref, st_ivas->hSCE[n]->element_brate ); } bits_ism = BASOP_Util_Divide3216_Scale( ism_total_brate_ref, FRAMES_PER_SEC, &tmp ); - bits_ism = shr(bits_ism, negate(add(tmp,1))); // bring down to Q0. + bits_ism = shr( bits_ism, negate( add( tmp, 1 ) ) ); // bring down to Q0. tmp = 0; move16(); - IF(bits_ism != 0) + IF( bits_ism != 0 ) { - tmp = idiv1616(bits_ism, st_ivas->nchan_ism); + tmp = idiv1616( bits_ism, st_ivas->nchan_ism ); } set16_fx( bits_element, tmp, st_ivas->nchan_ism ); - bits_element[st_ivas->nchan_ism - 1] = add(bits_element[st_ivas->nchan_ism - 1], bits_ism % st_ivas->nchan_ism); + bits_element[st_ivas->nchan_ism - 1] = add( bits_element[st_ivas->nchan_ism - 1], bits_ism % st_ivas->nchan_ism ); move16(); bitbudget_to_brate( bits_element, element_brate, st_ivas->nchan_ism ); *ism_total_brate = 0; move32(); - FOR ( n = 0; n < st_ivas->nchan_ism; n++ ) + FOR( n = 0; n < st_ivas->nchan_ism; n++ ) { st_ivas->hSCE[n]->element_brate = element_brate[n]; move32(); - *ism_total_brate = L_add(*ism_total_brate, ivas_interformat_brate( ISM_MASA_MODE_DISC, st_ivas->nchan_ism, st_ivas->hSCE[n]->element_brate, st_ivas->hIsmMetaData[n]->ism_imp, brate_limit_flag ) ); + *ism_total_brate = L_add( *ism_total_brate, ivas_interformat_brate( ISM_MASA_MODE_DISC, st_ivas->nchan_ism, st_ivas->hSCE[n]->element_brate, st_ivas->hIsmMetaData[n]->ism_imp, brate_limit_flag ) ); - test(); test(); - IF ( GT_16( ism_imp[n], 1 ) && EQ_16( st_ivas->flag_omasa_brate, 1 ) && brate_limit_flag >= 0 ) + test(); + test(); + IF( GT_16( ism_imp[n], 1 ) && EQ_16( st_ivas->flag_omasa_brate, 1 ) && brate_limit_flag >= 0 ) { - *ism_total_brate = L_sub(*ism_total_brate, ADJUST_ISM_BRATE_NEG); + *ism_total_brate = L_sub( *ism_total_brate, ADJUST_ISM_BRATE_NEG ); } - test(); test(); - IF ( EQ_16( brate_limit_flag, -1 ) && GE_16( ism_imp[n], 1 ) && GE_16( st_ivas->nchan_ism, 3 ) && GT_32( L_sub( ism_total_brate_ref, *ism_total_brate ), IVAS_48k ) ) + test(); + test(); + IF( EQ_16( brate_limit_flag, -1 ) && GE_16( ism_imp[n], 1 ) && GE_16( st_ivas->nchan_ism, 3 ) && GT_32( L_sub( ism_total_brate_ref, *ism_total_brate ), IVAS_48k ) ) { - *ism_total_brate = L_add(*ism_total_brate, ADJUST_ISM_BRATE_POS); + *ism_total_brate = L_add( *ism_total_brate, ADJUST_ISM_BRATE_POS ); } } st_ivas->hCPE[0]->brate_surplus = L_sub( ism_total_brate_ref, *ism_total_brate ); @@ -1071,14 +1076,14 @@ ivas_error ivas_omasa_ism_metadata_dec_fx( move16(); *nchan_transport_ism = st_ivas->nchan_ism; move16(); - IF ( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) + IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) { *nchan_ism = 1; move16(); *nchan_transport_ism = 1; move16(); } - ELSE IF ( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) + ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) { *nchan_ism = 0; move16(); @@ -1087,7 +1092,7 @@ ivas_error ivas_omasa_ism_metadata_dec_fx( } test(); - IF ( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) + IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) { /* decode ISM metadata */ IF( ( error = ivas_ism_metadata_dec_fx( ism_total_brate, *nchan_ism, nchan_transport_ism, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->bfi, @@ -1096,18 +1101,18 @@ ivas_error ivas_omasa_ism_metadata_dec_fx( return error; } - IF ( st_ivas->hDirAC != NULL ) + IF( st_ivas->hDirAC != NULL ) { - IF ( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) + IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { - FOR ( n = 0; n < st_ivas->nchan_ism; n++ ) + FOR( n = 0; n < st_ivas->nchan_ism; n++ ) { - //azimuth_ism = (int16_t) ( st_ivas->hIsmMetaData[n]->azimuth + 0.5f ); - //elevation_ism = (int16_t) ( st_ivas->hIsmMetaData[n]->elevation + 0.5f ); - azimuth_ism = extract_l(L_shr(L_add(st_ivas->hIsmMetaData[n]->azimuth_fx, ONE_IN_Q21), 21) / 2); // using "/ 2" here because it rounds towards 0, whereas L_shr rounds towards -inf - elevation_ism = extract_l(L_shr(L_add(st_ivas->hIsmMetaData[n]->elevation_fx, ONE_IN_Q21), 21)/ 2); + // azimuth_ism = (int16_t) ( st_ivas->hIsmMetaData[n]->azimuth + 0.5f ); + // elevation_ism = (int16_t) ( st_ivas->hIsmMetaData[n]->elevation + 0.5f ); + azimuth_ism = extract_l( L_shr( L_add( st_ivas->hIsmMetaData[n]->azimuth_fx, ONE_IN_Q21 ), 21 ) / 2 ); // using "/ 2" here because it rounds towards 0, whereas L_shr rounds towards -inf + elevation_ism = extract_l( L_shr( L_add( st_ivas->hIsmMetaData[n]->elevation_fx, ONE_IN_Q21 ), 21 ) / 2 ); - FOR ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) + FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) { meta_write_index = ( add( dirac_bs_md_write_idx, block ) ) % st_ivas->hSpatParamRendCom->dirac_md_buffer_length; move16(); @@ -1120,10 +1125,10 @@ ivas_error ivas_omasa_ism_metadata_dec_fx( } ELSE /* ISM_MASA_MODE_MASA_ONE_OBJ */ { - azimuth_ism = extract_l(L_shr(L_add(st_ivas->hIsmMetaData[0]->azimuth_fx, ONE_IN_Q21), 21) / 2); // using "/ 2" here because it rounds towards 0, whereas L_shr rounds towards -inf - elevation_ism = extract_l(L_shr(L_add(st_ivas->hIsmMetaData[0]->elevation_fx, ONE_IN_Q21), 21) / 2); + azimuth_ism = extract_l( L_shr( L_add( st_ivas->hIsmMetaData[0]->azimuth_fx, ONE_IN_Q21 ), 21 ) / 2 ); // using "/ 2" here because it rounds towards 0, whereas L_shr rounds towards -inf + elevation_ism = extract_l( L_shr( L_add( st_ivas->hIsmMetaData[0]->elevation_fx, ONE_IN_Q21 ), 21 ) / 2 ); - FOR ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) + FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) { meta_write_index = ( add( dirac_bs_md_write_idx, block ) ) % st_ivas->hSpatParamRendCom->dirac_md_buffer_length; move16(); @@ -1185,9 +1190,9 @@ void ivas_omasa_dirac_rend_jbm( Word16 q_output = 31; Word32 **output_fx, data_separated_objects_fx[4][960]; q_output = Q11; -#ifdef MSAN_FIX/*Can be removed when dependency on data_separated_objects is removed*/ +#ifdef MSAN_FIX /*Can be removed when dependency on data_separated_objects is removed*/ Word16 no_channels; - IF ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) + IF( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) { no_channels = 1; } @@ -1198,60 +1203,60 @@ void ivas_omasa_dirac_rend_jbm( FOR( Word16 ind = 0; ind < no_channels; ind++ ) { #else - FOR(Word16 ind = 0; ind < MAX_NUM_OBJECTS; ind++) + FOR( Word16 ind = 0; ind < MAX_NUM_OBJECTS; ind++ ) { #endif // MSAN_FIX - FOR(Word16 ind2 = 0; ind2 < nSamplesAsked; ind2++) + FOR( Word16 ind2 = 0; ind2 < nSamplesAsked; ind2++ ) { - //data_separated_objects_fx[ind][ind2] = (Word32)(data_separated_objects[ind][ind2] * (1<hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe)); - FOR(Word16 ind = 0; ind < st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; ind++) + output_fx = (Word32 **) malloc( sizeof( Word32 * ) * ( st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe ) ); + FOR( Word16 ind = 0; ind < st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; ind++ ) { - output_fx[ind] = (Word32*)malloc(sizeof(Word32) * 960); - FOR(Word16 ind2 = 0; ind2 < 960; ind2++) + output_fx[ind] = (Word32 *) malloc( sizeof( Word32 ) * 960 ); + FOR( Word16 ind2 = 0; ind2 < 960; ind2++ ) { - //output_fx[ind][ind2] =(Word32)(output_f[ind][ind2] * (1<hIsmRendererData->prev_gains_fx[ind1][ind2] = L_shr(st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2], 1); // Q30 -> Q29 + st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2] = L_shr( st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2], 1 ); // Q30 -> Q29 } } ivas_omasa_separate_object_render_jbm_fx( st_ivas, *nSamplesRendered, data_separated_objects_fx, output_fx, subframes_rendered, slots_rendered ); - FOR(Word16 ind = 0; ind < st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; ind++) + FOR( Word16 ind = 0; ind < st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; ind++ ) { - FOR(Word16 ind2 = 0; ind2 < 960; ind2++) + FOR( Word16 ind2 = 0; ind2 < 960; ind2++ ) { - output_f[ind][ind2] =fixedToFloat(output_fx[ind][ind2], q_output); + output_f[ind][ind2] = fixedToFloat( output_fx[ind][ind2], q_output ); } - free(output_fx[ind]); + free( output_fx[ind] ); } - free(output_fx); + free( output_fx ); #ifdef MSAN_FIX FOR( Word16 ind1 = 0; ind1 < MAX_NUM_OBJECTS; ind1++ ) #else - FOR(Word16 ind1 = 0; ind1 < MAX_CICP_CHANNELS - 1; ind1++) + FOR( Word16 ind1 = 0; ind1 < MAX_CICP_CHANNELS - 1; ind1++ ) #endif // MSAN_FIX { - FOR(Word16 ind2 = 0; ind2 < MAX_OUTPUT_CHANNELS; ind2++) + FOR( Word16 ind2 = 0; ind2 < MAX_OUTPUT_CHANNELS; ind2++ ) { - st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2] = L_shl(st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2], 1); // Q29 -> Q30 + st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2] = L_shl( st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2], 1 ); // Q29 -> Q30 } } - //dbgwrite2_txt(output_f[1],960,"../omasa_soutput_f.txt"); + // dbgwrite2_txt(output_f[1],960,"../omasa_soutput_f.txt"); #else ivas_omasa_separate_object_render_jbm( st_ivas, *nSamplesRendered, data_separated_objects, output_f, subframes_rendered, slots_rendered ); #endif @@ -1334,12 +1339,12 @@ ivas_error ivas_omasa_dirac_td_binaural_jbm( #ifndef MSAN_FIX Word32 rend_output_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS][L_FRAME48k]; Word32 *p_rend_output_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS]; - for (int i = 0; i < st_ivas->hDecoderConfig->nchan_out; i++) + for ( int i = 0; i < st_ivas->hDecoderConfig->nchan_out; i++ ) { p_rend_output_fx[i] = rend_output_fx[i]; - for (int j = 0; j < L_FRAME48k; j++) + for ( int j = 0; j < L_FRAME48k; j++ ) { - p_rend_output_fx[i][j] = floatToFixed(p_sepobj[i][j], Q11); + p_rend_output_fx[i][j] = floatToFixed( p_sepobj[i][j], Q11 ); } } #endif @@ -1350,20 +1355,20 @@ ivas_error ivas_omasa_dirac_td_binaural_jbm( return error; } #else - IF ( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_rend_output_fx, q_factor, *nSamplesRendered ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_rend_output_fx, q_factor, *nSamplesRendered ) ) != IVAS_ERR_OK ) { return error; } #endif #if 1 /* TODO: remove fixed to float conversions */ - for (int i = 0; i < st_ivas->hDecoderConfig->nchan_out; i++) + for ( int i = 0; i < st_ivas->hDecoderConfig->nchan_out; i++ ) { - for (int j = 0; j < L_FRAME48k; j++) + for ( int j = 0; j < L_FRAME48k; j++ ) { #ifdef MSAN_FIX - p_sepobj[i][j] = fixedToFloat(p_sepobj_fx[i][j], Q11); + p_sepobj[i][j] = fixedToFloat( p_sepobj_fx[i][j], Q11 ); #else - p_sepobj[i][j] = fixedToFloat(p_rend_output_fx[i][j], Q11); + p_sepobj[i][j] = fixedToFloat( p_rend_output_fx[i][j], Q11 ); #endif } } @@ -1413,9 +1418,9 @@ void ivas_omasa_rearrange_channels( #ifdef IVAS_FLOAT_FIXED void ivas_omasa_rearrange_channels_fx( - Word32 *output[], /* o : output synthesis signal */ - const Word16 nchan_transport_ism, /* o : number of ISM TCs */ - const Word16 output_frame /* i : output frame length per channel */ + Word32 *output[], /* o : output synthesis signal */ + const Word16 nchan_transport_ism, /* o : number of ISM TCs */ + const Word16 output_frame /* i : output frame length per channel */ ) { Word16 n; @@ -1424,7 +1429,7 @@ void ivas_omasa_rearrange_channels_fx( Copy32( output[0], tmp_buff[0], output_frame ); Copy32( output[1], tmp_buff[1], output_frame ); - FOR ( n = 0; n < nchan_transport_ism; n++ ) + FOR( n = 0; n < nchan_transport_ism; n++ ) { Copy32( output[CPE_CHANNELS + n], output[n], output_frame ); } @@ -1433,4 +1438,4 @@ void ivas_omasa_rearrange_channels_fx( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/ivas_osba_dec.c b/lib_dec/ivas_osba_dec.c index 9431b8f08..fff163ccd 100644 --- a/lib_dec/ivas_osba_dec.c +++ b/lib_dec/ivas_osba_dec.c @@ -42,7 +42,7 @@ #ifdef IVAS_FLOAT_FIXED #include "prot_fx1.h" #include "prot_fx2.h" -#include "math.h" // temporary (for fabs) +#include "math.h" // temporary (for fabs) #define IVAS_FLOAT_FIXED_TO_BE_REMOVED #endif // IVAS_FLOAT_FIXED @@ -103,14 +103,14 @@ ivas_error ivas_osba_data_open_fx( hSbaIsmData->delayBuffer_nchan = st_ivas->nchan_ism; hSbaIsmData->delayBuffer_size = (int16_t) ( ( st_ivas->hDecoderConfig->output_Fs / 50 ) / MAX_PARAM_SPATIAL_SUBFRAMES ); - if ( ( hSbaIsmData->delayBuffer_fx = (Word32 **) malloc( hSbaIsmData->delayBuffer_nchan * sizeof(Word32 * ) ) ) == NULL ) + if ( ( hSbaIsmData->delayBuffer_fx = (Word32 **) malloc( hSbaIsmData->delayBuffer_nchan * sizeof( Word32 * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for OSBA delay buffer \n" ) ); } for ( i = 0; i < hSbaIsmData->delayBuffer_nchan; i++ ) { - if ( ( hSbaIsmData->delayBuffer_fx[i] = (Word32 *) malloc( hSbaIsmData->delayBuffer_size * sizeof(Word32) ) ) == NULL ) + if ( ( hSbaIsmData->delayBuffer_fx[i] = (Word32 *) malloc( hSbaIsmData->delayBuffer_size * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for OSBA delay buffer \n" ) ); } @@ -305,8 +305,8 @@ ivas_error ivas_osba_ism_metadata_dec_fx( *nchan_ism = st_ivas->nchan_ism; /* decode ISM metadata */ - IF((error = ivas_ism_metadata_dec_fx(ism_total_brate, *nchan_ism, &nchan_transport_ism, st_ivas->hIsmMetaData, NULL, st_ivas->bfi, - nb_bits_metadata, st_ivas->ism_mode, st_ivas->hISMDTX, NULL, &st_ivas->ism_extmeta_active, &st_ivas->ism_extmeta_cnt, st_ivas->hCPE[0]->hCoreCoder[0])) != IVAS_ERR_OK) + IF( ( error = ivas_ism_metadata_dec_fx( ism_total_brate, *nchan_ism, &nchan_transport_ism, st_ivas->hIsmMetaData, NULL, st_ivas->bfi, + nb_bits_metadata, st_ivas->ism_mode, st_ivas->hISMDTX, NULL, &st_ivas->ism_extmeta_active, &st_ivas->ism_extmeta_cnt, st_ivas->hCPE[0]->hCoreCoder[0] ) ) != IVAS_ERR_OK ) { return error; } @@ -348,11 +348,11 @@ ivas_error ivas_osba_ism_metadata_dec( #ifdef IVAS_FLOAT_FIXED ivas_error ivas_osba_render_sf_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ UWord16 *nSamplesAvailableNext, /* o : number of CLDFB slots still to render */ - Word32 *p_output[] /* o : rendered time signal */ + Word32 *p_output[] /* o : rendered time signal */ ) { Word16 n; @@ -360,36 +360,37 @@ ivas_error ivas_osba_render_sf_fx( Word32 *p_output_ism[MAX_OUTPUT_CHANNELS]; ivas_error error; - FOR(n = 0; n < MAX_OUTPUT_CHANNELS; n++) + FOR( n = 0; n < MAX_OUTPUT_CHANNELS; n++ ) { p_output_ism[n] = &output_ism[n][0]; } - FOR(n = 0; n < st_ivas->nchan_ism; n++) + FOR( n = 0; n < st_ivas->nchan_ism; n++ ) { - v_shr(p_output[n], sub(Q11, Q11), output_ism[n], nSamplesAsked); + v_shr( p_output[n], sub( Q11, Q11 ), output_ism[n], nSamplesAsked ); } - IF((error = ivas_sba_dec_render_fx(st_ivas, nSamplesAsked, nSamplesRendered, nSamplesAvailableNext, p_output, 960)) != IVAS_ERR_OK) + IF( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAsked, nSamplesRendered, nSamplesAvailableNext, p_output, 960 ) ) != IVAS_ERR_OK ) { return error; } - IF(st_ivas->renderer_type != RENDERER_BINAURAL_FASTCONV_ROOM) + IF( st_ivas->renderer_type != RENDERER_BINAURAL_FASTCONV_ROOM ) { - ivas_ism_render_sf_fx(st_ivas, p_output_ism, *nSamplesRendered); + ivas_ism_render_sf_fx( st_ivas, p_output_ism, *nSamplesRendered ); } - FOR(n = 0; n < st_ivas->hDecoderConfig->nchan_out; n++) + FOR( n = 0; n < st_ivas->hDecoderConfig->nchan_out; n++ ) { - IF(st_ivas->renderer_type != RENDERER_BINAURAL_FASTCONV_ROOM) + IF( st_ivas->renderer_type != RENDERER_BINAURAL_FASTCONV_ROOM ) { - v_add_fixed(p_output[n], p_output_ism[n], p_output[n], *nSamplesRendered, 1); //takes care of downscaling by 0.5f + v_add_fixed( p_output[n], p_output_ism[n], p_output[n], *nSamplesRendered, 1 ); // takes care of downscaling by 0.5f } - ELSE{ - scale_sig32(p_output[n], *nSamplesRendered, -1); + ELSE + { + scale_sig32( p_output[n], *nSamplesRendered, -1 ); } - //v_multc_fixed(p_output[n], 1073741824 /* 0.5f in Q31 */, p_output[n], *nSamplesRendered); + // v_multc_fixed(p_output[n], 1073741824 /* 0.5f in Q31 */, p_output[n], *nSamplesRendered); } return IVAS_ERR_OK; diff --git a/lib_dec/ivas_out_setup_conversion.c b/lib_dec/ivas_out_setup_conversion.c index 0510723e9..ad6f0f9c1 100644 --- a/lib_dec/ivas_out_setup_conversion.c +++ b/lib_dec/ivas_out_setup_conversion.c @@ -668,24 +668,24 @@ ivas_error ivas_ls_setup_conversion_open_fx( set32_fx( hLsSetUpConversion->dmxEnergyPrev_fx[chIdx], 0, hLsSetUpConversion->sfbCnt ); hLsSetUpConversion->dmx_prev_exp = 0; /* TODO: remove the floating point dependency */ - //IF( ( hLsSetUpConversion->targetEnergyPrev[chIdx] = (float *) malloc( ( hLsSetUpConversion->sfbCnt ) * sizeof( float ) ) ) == NULL ) + // IF( ( hLsSetUpConversion->targetEnergyPrev[chIdx] = (float *) malloc( ( hLsSetUpConversion->sfbCnt ) * sizeof( float ) ) ) == NULL ) //{ - // return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LS configuration Conversion Handle \n" ) ); - //} - //IF( ( hLsSetUpConversion->dmxEnergyPrev[chIdx] = (float *) malloc( ( hLsSetUpConversion->sfbCnt ) * sizeof( float ) ) ) == NULL ) + // return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LS configuration Conversion Handle \n" ) ); + // } + // IF( ( hLsSetUpConversion->dmxEnergyPrev[chIdx] = (float *) malloc( ( hLsSetUpConversion->sfbCnt ) * sizeof( float ) ) ) == NULL ) //{ - // return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LS configuration Conversion Handle \n" ) ); - //} - //set_f( hLsSetUpConversion->targetEnergyPrev[chIdx], 0.0f, hLsSetUpConversion->sfbCnt ); - //set_f( hLsSetUpConversion->dmxEnergyPrev[chIdx], 0.0f, hLsSetUpConversion->sfbCnt ); + // return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LS configuration Conversion Handle \n" ) ); + // } + // set_f( hLsSetUpConversion->targetEnergyPrev[chIdx], 0.0f, hLsSetUpConversion->sfbCnt ); + // set_f( hLsSetUpConversion->dmxEnergyPrev[chIdx], 0.0f, hLsSetUpConversion->sfbCnt ); } FOR( ; chIdx < MAX_CICP_CHANNELS; chIdx++ ) { hLsSetUpConversion->targetEnergyPrev_fx[chIdx] = NULL; hLsSetUpConversion->dmxEnergyPrev_fx[chIdx] = NULL; /* TODO: remove the floating point dependency */ - //hLsSetUpConversion->targetEnergyPrev[chIdx] = NULL; - //hLsSetUpConversion->dmxEnergyPrev[chIdx] = NULL; + // hLsSetUpConversion->targetEnergyPrev[chIdx] = NULL; + // hLsSetUpConversion->dmxEnergyPrev[chIdx] = NULL; } } ELSE @@ -719,28 +719,28 @@ ivas_error ivas_ls_setup_conversion_open_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LS configuration Conversion Handle \n" ) ); } /* TODO: remove the floating point dependency */ - //IF( ( hLsSetUpConversion->targetEnergyPrev[0] = (float *) malloc( ( MAX_SFB + 2 ) * sizeof( float ) ) ) == NULL ) + // IF( ( hLsSetUpConversion->targetEnergyPrev[0] = (float *) malloc( ( MAX_SFB + 2 ) * sizeof( float ) ) ) == NULL ) //{ - // return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LS configuration Conversion Handle \n" ) ); - //} - //IF( ( hLsSetUpConversion->dmxEnergyPrev[0] = (float *) malloc( ( MAX_SFB + 2 ) * sizeof( float ) ) ) == NULL ) + // return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LS configuration Conversion Handle \n" ) ); + // } + // IF( ( hLsSetUpConversion->dmxEnergyPrev[0] = (float *) malloc( ( MAX_SFB + 2 ) * sizeof( float ) ) ) == NULL ) //{ - // return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LS configuration Conversion Handle \n" ) ); - //} + // return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LS configuration Conversion Handle \n" ) ); + // } FOR( chIdx = 1; chIdx < MAX_CICP_CHANNELS; chIdx++ ) { hLsSetUpConversion->targetEnergyPrev_fx[chIdx] = NULL; hLsSetUpConversion->dmxEnergyPrev_fx[chIdx] = NULL; /* TODO: remove the floating point dependency */ - //hLsSetUpConversion->targetEnergyPrev[chIdx] = NULL; - //hLsSetUpConversion->dmxEnergyPrev[chIdx] = NULL; + // hLsSetUpConversion->targetEnergyPrev[chIdx] = NULL; + // hLsSetUpConversion->dmxEnergyPrev[chIdx] = NULL; } set32_fx( hLsSetUpConversion->targetEnergyPrev_fx[0], 0, MAX_SFB + 2 ); set32_fx( hLsSetUpConversion->dmxEnergyPrev_fx[0], 0, MAX_SFB + 2 ); /* TODO: remove the floating point dependency */ - //set_f( hLsSetUpConversion->targetEnergyPrev[0], 0.0f, MAX_SFB + 2 ); - //set_f( hLsSetUpConversion->dmxEnergyPrev[0], 0.0f, MAX_SFB + 2 ); + // set_f( hLsSetUpConversion->targetEnergyPrev[0], 0.0f, MAX_SFB + 2 ); + // set_f( hLsSetUpConversion->dmxEnergyPrev[0], 0.0f, MAX_SFB + 2 ); } /* Initialize the DMX conversion matrix */ @@ -755,18 +755,18 @@ ivas_error ivas_ls_setup_conversion_open_fx( /* TODO: remove the floating point dependency */ /* Allocate memory depending on the number of output channels */ - //IF( ( hLsSetUpConversion->dmxMtx[chIdx] = (float *) malloc( outChannels * sizeof( float ) ) ) == NULL ) + // IF( ( hLsSetUpConversion->dmxMtx[chIdx] = (float *) malloc( outChannels * sizeof( float ) ) ) == NULL ) //{ - // return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory FOR temp dmx matrix \n" ) ); - //} - //set_zero( hLsSetUpConversion->dmxMtx[chIdx], outChannels ); + // return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory FOR temp dmx matrix \n" ) ); + // } + // set_zero( hLsSetUpConversion->dmxMtx[chIdx], outChannels ); } FOR( ; chIdx < MAX_CICP_CHANNELS; chIdx++ ) { hLsSetUpConversion->dmxMtx_fx[chIdx] = NULL; /* TODO: remove the floating point dependency */ - //hLsSetUpConversion->dmxMtx[chIdx] = NULL; + // hLsSetUpConversion->dmxMtx[chIdx] = NULL; } IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) @@ -797,7 +797,7 @@ ivas_error ivas_ls_setup_conversion_open_fx( { FOR( Word16 j = 0; j < outChannels; ++j ) { - //hLsSetUpConversion->dmxMtx[i][j] = fix_to_float( hLsSetUpConversion->dmxMtx_fx[i][j], Q30 ); + // hLsSetUpConversion->dmxMtx[i][j] = fix_to_float( hLsSetUpConversion->dmxMtx_fx[i][j], Q30 ); } } @@ -985,23 +985,23 @@ void ivas_ls_setup_conversion_close_fx( } /* TODO: remove the floating point dependency */ - //IF( ( *hLsSetUpConversion )->dmxMtx[idx] != NULL ) + // IF( ( *hLsSetUpConversion )->dmxMtx[idx] != NULL ) //{ - // free( ( *hLsSetUpConversion )->dmxMtx[idx] ); - // ( *hLsSetUpConversion )->dmxMtx[idx] = NULL; - //} + // free( ( *hLsSetUpConversion )->dmxMtx[idx] ); + // ( *hLsSetUpConversion )->dmxMtx[idx] = NULL; + // } - //IF( ( *hLsSetUpConversion )->targetEnergyPrev[idx] != NULL ) + // IF( ( *hLsSetUpConversion )->targetEnergyPrev[idx] != NULL ) //{ - // free( ( *hLsSetUpConversion )->targetEnergyPrev[idx] ); - // ( *hLsSetUpConversion )->targetEnergyPrev[idx] = NULL; - //} + // free( ( *hLsSetUpConversion )->targetEnergyPrev[idx] ); + // ( *hLsSetUpConversion )->targetEnergyPrev[idx] = NULL; + // } - //IF( ( *hLsSetUpConversion )->dmxEnergyPrev[idx] != NULL ) + // IF( ( *hLsSetUpConversion )->dmxEnergyPrev[idx] != NULL ) //{ - // free( ( *hLsSetUpConversion )->dmxEnergyPrev[idx] ); - // ( *hLsSetUpConversion )->dmxEnergyPrev[idx] = NULL; - //} + // free( ( *hLsSetUpConversion )->dmxEnergyPrev[idx] ); + // ( *hLsSetUpConversion )->dmxEnergyPrev[idx] = NULL; + // } } free( *hLsSetUpConversion ); @@ -1782,7 +1782,7 @@ void ivas_ls_setup_conversion_process_mdct_param_mc_fx( nchan_transport = st_ivas->nchan_transport; nchan_out = st_ivas->hDecoderConfig->nchan_out; num_CPE = st_ivas->nCPE; - nchan_transport_format = add(st_ivas->hTransSetup.nchan_out_woLFE , st_ivas->hTransSetup.num_lfe); + nchan_transport_format = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ); hLsSetUpConversion = st_ivas->hLsSetUpConversion; /* Assign all the declared handles*/ FOR( cpe_idx = 0; cpe_idx < num_CPE; cpe_idx++ ) @@ -1797,7 +1797,7 @@ void ivas_ls_setup_conversion_process_mdct_param_mc_fx( FOR( idx = 0; idx < CPE_CHANNELS; idx++ ) { /* get the channel index */ - chInIdx = add(imult1616(cpe_idx , CPE_CHANNELS) , idx); + chInIdx = add( imult1616( cpe_idx, CPE_CHANNELS ), idx ); assert( chInIdx <= nchan_transport ); transform_type[chInIdx][0] = hCPE[cpe_idx]->hCoreCoder[idx]->transform_type[0]; transform_type[chInIdx][1] = hCPE[cpe_idx]->hCoreCoder[idx]->transform_type[1]; @@ -1810,19 +1810,19 @@ void ivas_ls_setup_conversion_process_mdct_param_mc_fx( set_zero_fx( targetEnergy_fx, MAX_SFB + 2 ); set_zero_fx( dmxEnergy_fx, MAX_SFB + 2 ); - FOR ( chInIdx = 0; chInIdx < nchan_transport; chInIdx++ ) + FOR( chInIdx = 0; chInIdx < nchan_transport; chInIdx++ ) { - IF ( NE_16(mct_chan_mode[chInIdx] , MCT_CHAN_MODE_IGNORE) ) + IF( NE_16( mct_chan_mode[chInIdx], MCT_CHAN_MODE_IGNORE ) ) { /* initially, set pointers to input; if conversion occurs in (sub)frame, set to convertRes */ sig_fx[chInIdx][0] = pTmp_fx[0] = x_fx[chInIdx][0]; /*Q=31-x_e[chInIdx][0]*/ sig_fx[chInIdx][1] = pTmp_fx[1] = x_fx[chInIdx][1]; /*Q=31-x_e[chInIdx][1]*/ /* convert (sub)frames to higher frequency resolution */ - IF ( NE_16(transform_type[chInIdx][0] , TCX_20) ) + IF( NE_16( transform_type[chInIdx][0], TCX_20 ) ) { - FOR ( subFrameIdx = 0; subFrameIdx < NB_DIV; subFrameIdx++ ) + FOR( subFrameIdx = 0; subFrameIdx < NB_DIV; subFrameIdx++ ) { - IF ( EQ_16(transform_type[chInIdx][subFrameIdx] , TCX_5) ) + IF( EQ_16( transform_type[chInIdx][subFrameIdx], TCX_5 ) ) { /* subframe is TCX5, but TCX10 or TCX20 in other channel -> convert channel with TCX5 to TCX10 resolution */ pTmp_fx[subFrameIdx] = sig_fx[chInIdx][subFrameIdx] = convertRes_fx[chInIdx] + subFrameIdx * frameSize / 2; @@ -1838,15 +1838,15 @@ void ivas_ls_setup_conversion_process_mdct_param_mc_fx( } } } - Word16 input_exp, output_exp=0; + Word16 input_exp, output_exp = 0; /* precalculate MDST estimate */ - FOR ( chInIdx = 0; chInIdx < nchan_transport; chInIdx++ ) + FOR( chInIdx = 0; chInIdx < nchan_transport; chInIdx++ ) { - IF ( NE_16(mct_chan_mode[chInIdx] , MCT_CHAN_MODE_IGNORE) ) + IF( NE_16( mct_chan_mode[chInIdx], MCT_CHAN_MODE_IGNORE ) ) { mdst_fx[chInIdx][0] = mdst_fx[chInIdx][frameSize - 1] = 0; - FOR ( i = 1; i < frameSize - 1; i++ ) + FOR( i = 1; i < frameSize - 1; i++ ) { mdst_fx[chInIdx][i] = L_sub( sig_fx[chInIdx][0][i + 1], sig_fx[chInIdx][0][i - 1] ); /*Q=31-x_e[chInIdx][0]*/ } @@ -1854,7 +1854,7 @@ void ivas_ls_setup_conversion_process_mdct_param_mc_fx( } /* Step 1.1, calculate Cx from MDST estimate */ - FOR ( bandIdx = 0; bandIdx < PARAM_MC_MAX_PARAMETER_BANDS; bandIdx++ ) + FOR( bandIdx = 0; bandIdx < PARAM_MC_MAX_PARAMETER_BANDS; bandIdx++ ) { set_zero_fx( cx_fx[bandIdx], PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS ); set_zero_fx( cx_imag_fx[bandIdx], PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS ); @@ -1862,14 +1862,14 @@ void ivas_ls_setup_conversion_process_mdct_param_mc_fx( set_zero_fx( Nrqq_fx, MAX_OUTPUT_CHANNELS ); set_zero_fx( target_ch_ener_fx, MAX_OUTPUT_CHANNELS ); Word16 max_e = 0; - FOR ( idx = 0; idx < nchan_transport; idx++ ) + FOR( idx = 0; idx < nchan_transport; idx++ ) { - IF ( NE_16(mct_chan_mode[idx] , MCT_CHAN_MODE_IGNORE) ) + IF( NE_16( mct_chan_mode[idx], MCT_CHAN_MODE_IGNORE ) ) { max_e = s_max( max_e, x_e[idx][0] ); } } - FOR ( bandIdx = 0; bandIdx < hLsSetUpConversion->sfbCnt; bandIdx++ ) + FOR( bandIdx = 0; bandIdx < hLsSetUpConversion->sfbCnt; bandIdx++ ) { set_zero_fx( real_in_buffer_fx, PARAM_MC_MAX_BANDS_IN_PARAMETER_BAND * PARAM_MC_BAND_TO_MDCT_BAND_RATIO * MAX_TRANSPORT_CHANNELS ); set_zero_fx( imag_in_buffer_fx, PARAM_MC_MAX_BANDS_IN_PARAMETER_BAND * PARAM_MC_BAND_TO_MDCT_BAND_RATIO * MAX_TRANSPORT_CHANNELS ); @@ -1878,14 +1878,14 @@ void ivas_ls_setup_conversion_process_mdct_param_mc_fx( start = hLsSetUpConversion->sfbOffset[bandIdx]; stop = hLsSetUpConversion->sfbOffset[bandIdx + 1]; - num_bands = sub(stop , start); + num_bands = sub( stop, start ); - FOR ( i = 0; i < num_bands; i++ ) + FOR( i = 0; i < num_bands; i++ ) { band = start + i; - FOR ( idx = 0; idx < nchan_transport; idx++ ) + FOR( idx = 0; idx < nchan_transport; idx++ ) { - IF ( mct_chan_mode[idx] != MCT_CHAN_MODE_IGNORE ) + IF( mct_chan_mode[idx] != MCT_CHAN_MODE_IGNORE ) { real_in_buffer_fx[i + num_bands * idx] = L_shr( sig_fx[idx][0][band], max_e - x_e[idx][0] ); /*Setting the exponent to max_e*/ imag_in_buffer_fx[i + num_bands * idx] = L_shr( mdst_fx[idx][band], max_e - x_e[idx][0] ); /*Setting the exponent to max_e*/ @@ -1899,13 +1899,13 @@ void ivas_ls_setup_conversion_process_mdct_param_mc_fx( imag_in_buffer_fx[i] = L_shr( imag_in_buffer_fx[i], shift ); } input_exp = max_e; - input_exp = add(input_exp,shift); + input_exp = add( input_exp, shift ); cmplx_matrix_square_fx( real_in_buffer_fx, imag_in_buffer_fx, num_bands, nchan_transport, real_buffer_fx, imag_buffer_fx, input_exp, &output_exp ); - v_add_32( cx_fx[bandIdx], real_buffer_fx, cx_fx[bandIdx], nchan_transport * nchan_transport ); /*Q=Q_real_buffer=Q_imag_buffer=output_exp*/ + v_add_32( cx_fx[bandIdx], real_buffer_fx, cx_fx[bandIdx], nchan_transport * nchan_transport ); /*Q=Q_real_buffer=Q_imag_buffer=output_exp*/ v_add_32( cx_imag_fx[bandIdx], imag_buffer_fx, cx_imag_fx[bandIdx], nchan_transport * nchan_transport ); /*Q=Q_real_buffer=Q_imag_buffer=output_exp*/ } Word16 exp_in = 10, exp_out = 0; - FOR ( bandIdx = 0; bandIdx < hLsSetUpConversion->sfbCnt; bandIdx++ ) + FOR( bandIdx = 0; bandIdx < hLsSetUpConversion->sfbCnt; bandIdx++ ) { DMXEne_fx = 0; set_zero_fx( cy_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS ); @@ -1913,13 +1913,13 @@ void ivas_ls_setup_conversion_process_mdct_param_mc_fx( set_zero_fx( target_ch_ener_fx, MAX_OUTPUT_CHANNELS ); /* Step 1.2, get target channel energies for the transported format as in ivas_param_mc_get_mono_stereo_mixing_matrices(), Nrqq calculation */ ild_q_fx = hParamMC->icld_q_fx + imult1616( bandIdx, hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe ); - FOR ( chInIdx = 0; chInIdx < nchan_transport_format; chInIdx++ ) + FOR( chInIdx = 0; chInIdx < nchan_transport_format; chInIdx++ ) { Word32 ref_ener_fx = 0; Word16 ref_channel_cnt; Word16 ref_channel_idx; - FOR ( ref_channel_cnt = 0; ref_channel_cnt < hParamMC->hMetadataPMC->ild_mapping_conf->num_ref_channels[chInIdx]; ref_channel_cnt++ ) + FOR( ref_channel_cnt = 0; ref_channel_cnt < hParamMC->hMetadataPMC->ild_mapping_conf->num_ref_channels[chInIdx]; ref_channel_cnt++ ) { ref_channel_idx = hParamMC->hMetadataPMC->ild_mapping_conf->ref_channel_idx[chInIdx][ref_channel_cnt]; ref_ener_fx = L_add( ref_ener_fx, cx_fx[bandIdx][ref_channel_idx + ref_channel_idx * nchan_transport] ); /*Exponent=output_exp*/ @@ -1930,19 +1930,19 @@ void ivas_ls_setup_conversion_process_mdct_param_mc_fx( } /* Step 1.3 get target Cy like in ivas_param_mc_get_mono_stereo_mixing_matrices() (with dmx matrix from CICPX to MONO/STEREO saved in hParamMC) */ - FOR ( chOutIdx = 0; chOutIdx < nchan_out; chOutIdx++ ) + FOR( chOutIdx = 0; chOutIdx < nchan_out; chOutIdx++ ) { - FOR ( i = 0; i < nchan_transport_format; i++ ) + FOR( i = 0; i < nchan_transport_format; i++ ) { - IF ( EQ_32(hParamMC->ls_conv_dmx_matrix_fx[chOutIdx + i * nchan_out] , 32768) ) - hParamMC->ls_conv_dmx_matrix_fx[chOutIdx + i * nchan_out] = 32767; + IF( EQ_32( hParamMC->ls_conv_dmx_matrix_fx[chOutIdx + i * nchan_out], 32768 ) ) + hParamMC->ls_conv_dmx_matrix_fx[chOutIdx + i * nchan_out] = 32767; target_ch_ener_fx[chOutIdx] = L_add( target_ch_ener_fx[chOutIdx], Mpy_32_16_1( Nrqq_fx[i], (Word16) hParamMC->ls_conv_dmx_matrix_fx[chOutIdx + i * nchan_out] ) ); /*output_exp + 2*/ } cy_fx[chOutIdx + nchan_out * chOutIdx] = target_ch_ener_fx[chOutIdx]; } /* Step 1.4 final target energy for the band would then be the sum over the diagonal of Cy*/ - FOR ( chOutIdx = 0; chOutIdx < nchan_out; chOutIdx++ ) + FOR( chOutIdx = 0; chOutIdx < nchan_out; chOutIdx++ ) { targetEnergy_fx[bandIdx] = L_add( targetEnergy_fx[bandIdx], cy_fx[chOutIdx + nchan_out * chOutIdx] ); /*exp=output_exp+2*/ } @@ -1951,19 +1951,19 @@ void ivas_ls_setup_conversion_process_mdct_param_mc_fx( start = hLsSetUpConversion->sfbOffset[bandIdx]; stop = hLsSetUpConversion->sfbOffset[bandIdx + 1]; - FOR ( chOutIdx = 0; chOutIdx < nchan_out; chOutIdx++ ) + FOR( chOutIdx = 0; chOutIdx < nchan_out; chOutIdx++ ) { - FOR ( chInIdx = 0; chInIdx < nchan_transport; chInIdx++ ) + FOR( chInIdx = 0; chInIdx < nchan_transport; chInIdx++ ) { - IF ( mct_chan_mode[chInIdx] != MCT_CHAN_MODE_IGNORE ) + IF( mct_chan_mode[chInIdx] != MCT_CHAN_MODE_IGNORE ) { dmxCoeff_fx = hLsSetUpConversion->dmxMtx_fx[chInIdx][chOutIdx]; /* Step 1: Compute the target energy and DMX signal (possible since we have all signals in TCX20 resolution) */ - IF ( dmxCoeff_fx ) + IF( dmxCoeff_fx ) { /* Loop over all the bins in the band */ - FOR ( binIdx = start; binIdx < stop; binIdx++ ) + FOR( binIdx = start; binIdx < stop; binIdx++ ) { tmpDMXSig_fx = Mult_32_32( dmxCoeff_fx, L_shr( sig_fx[chInIdx][0][binIdx], max_e - x_e[chInIdx][0] ) ); /*max_e+1*/ dmxSignalReal_fx[binIdx] = L_add( dmxSignalReal_fx[binIdx], tmpDMXSig_fx ); @@ -1976,7 +1976,7 @@ void ivas_ls_setup_conversion_process_mdct_param_mc_fx( } /* Loop over all the bins in the band */ DMXEne_fx = 0; - FOR ( binIdx = start; binIdx < stop; binIdx++ ) + FOR( binIdx = start; binIdx < stop; binIdx++ ) { tmpReal_fx = L_shr( dmxSignalReal_fx[binIdx], 1 ); tmpImag_fx = L_shr( dmxSignalImag_fx[binIdx], 1 ); @@ -1989,7 +1989,7 @@ void ivas_ls_setup_conversion_process_mdct_param_mc_fx( } /* Step 3: Peform energy smoothing */ - FOR ( bandIdx = 0; bandIdx < hLsSetUpConversion->sfbCnt; bandIdx++ ) + FOR( bandIdx = 0; bandIdx < hLsSetUpConversion->sfbCnt; bandIdx++ ) { targetEnergy_fx[bandIdx] = L_add( Mult_32_32( LS_OUT_CONV_SMOOTHING_FACTOR_Q31, targetEnergy_fx[bandIdx] ), Mult_32_32( L_sub( MAX_32, LS_OUT_CONV_SMOOTHING_FACTOR_Q31 ), L_shr( hLsSetUpConversion->targetEnergyPrev_fx[0][bandIdx], output_exp + 2 - hLsSetUpConversion->te_prev_exp ) ) ); /*output_exp + 2*/ dmxEnergy_fx[bandIdx] = L_add( Mult_32_32( LS_OUT_CONV_SMOOTHING_FACTOR_Q31, dmxEnergy_fx[bandIdx] ), Mult_32_32( L_sub( MAX_32, LS_OUT_CONV_SMOOTHING_FACTOR_Q31 ), L_shr( hLsSetUpConversion->dmxEnergyPrev_fx[0][bandIdx], 2 * ( max_e + 2 ) - hLsSetUpConversion->dmx_prev_exp ) ) ); /*2 * (max_e + 2)*/ @@ -1999,14 +1999,14 @@ void ivas_ls_setup_conversion_process_mdct_param_mc_fx( hLsSetUpConversion->te_prev_exp = output_exp + 2; hLsSetUpConversion->dmx_prev_exp = 2 * ( max_e + 2 ); /* Step 4: Perform equalization */ - FOR ( chInIdx = 0; chInIdx < nchan_transport; chInIdx++ ) + FOR( chInIdx = 0; chInIdx < nchan_transport; chInIdx++ ) { - IF ( NE_16(mct_chan_mode[chInIdx] , MCT_CHAN_MODE_IGNORE) ) + IF( NE_16( mct_chan_mode[chInIdx], MCT_CHAN_MODE_IGNORE ) ) { - IF ( EQ_16(transform_type[chInIdx][0] , TCX_20) ) + IF( EQ_16( transform_type[chInIdx][0], TCX_20 ) ) { /*TCX20*/ - FOR ( bandIdx = 0; bandIdx < hLsSetUpConversion->sfbCnt; bandIdx++ ) + FOR( bandIdx = 0; bandIdx < hLsSetUpConversion->sfbCnt; bandIdx++ ) { start = hLsSetUpConversion->sfbOffset[bandIdx]; stop = hLsSetUpConversion->sfbOffset[bandIdx + 1]; @@ -2014,7 +2014,7 @@ void ivas_ls_setup_conversion_process_mdct_param_mc_fx( /*Compute Eq gains */ ivas_lssetupconversion_computeEQFactor_fx( &targetEnergy_fx[bandIdx], &dmxEnergy_fx[bandIdx], &eqGain_fx ); - FOR ( binIdx = start; binIdx < stop; binIdx++ ) + FOR( binIdx = start; binIdx < stop; binIdx++ ) { x_fx[chInIdx][0][binIdx] = L_shl( Mult_32_32( x_fx[chInIdx][0][binIdx], eqGain_fx ), 1 ); } @@ -2023,7 +2023,7 @@ void ivas_ls_setup_conversion_process_mdct_param_mc_fx( ELSE { stop_tcx5 = 0; - FOR ( bandIdx = 0; bandIdx < hLsSetUpConversion->sfbCnt; bandIdx++ ) + FOR( bandIdx = 0; bandIdx < hLsSetUpConversion->sfbCnt; bandIdx++ ) { start = hLsSetUpConversion->sfbOffset[bandIdx] / 2; stop = hLsSetUpConversion->sfbOffset[bandIdx + 1] / 2; @@ -2032,12 +2032,12 @@ void ivas_ls_setup_conversion_process_mdct_param_mc_fx( ivas_lssetupconversion_computeEQFactor_fx( &targetEnergy_fx[bandIdx], &dmxEnergy_fx[bandIdx], &eqGain_fx ); - FOR ( subFrameIdx = 0; subFrameIdx < NB_DIV; subFrameIdx++ ) + FOR( subFrameIdx = 0; subFrameIdx < NB_DIV; subFrameIdx++ ) { - IF ( EQ_16(transform_type[chInIdx][subFrameIdx] , TCX_10) ) + IF( EQ_16( transform_type[chInIdx][subFrameIdx], TCX_10 ) ) { /*TCX10*/ - FOR ( binIdx = start; binIdx < stop; binIdx++ ) + FOR( binIdx = start; binIdx < stop; binIdx++ ) { x_fx[chInIdx][subFrameIdx][binIdx] = L_shl( Mult_32_32( x_fx[chInIdx][subFrameIdx][binIdx], eqGain_fx ), 1 ); } @@ -2047,12 +2047,12 @@ void ivas_ls_setup_conversion_process_mdct_param_mc_fx( /* TCX5*/ start_tcx5 = stop_tcx5; stop_tcx5 = ( stop + 1 ) / 2; - FOR ( binIdx = start_tcx5; binIdx < stop_tcx5; binIdx++ ) + FOR( binIdx = start_tcx5; binIdx < stop_tcx5; binIdx++ ) { x_fx[chInIdx][subFrameIdx][binIdx] = L_shl( Mult_32_32( x_fx[chInIdx][subFrameIdx][binIdx], eqGain_fx ), 1 ); } - FOR ( binIdx = start_tcx5; binIdx < stop_tcx5; binIdx++ ) + FOR( binIdx = start_tcx5; binIdx < stop_tcx5; binIdx++ ) { x_fx[chInIdx][subFrameIdx][binIdx + ( frameSize >> 2 )] = L_shl( Mult_32_32( x_fx[chInIdx][subFrameIdx][binIdx + ( frameSize >> 2 )], eqGain_fx ), 1 ); } @@ -2738,4 +2738,4 @@ void ivas_lssetupconversion_process_param_mc( pop_wmops(); return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/ivas_output_config.c b/lib_dec/ivas_output_config.c index 965a58c3a..18d7b0c50 100644 --- a/lib_dec/ivas_output_config.c +++ b/lib_dec/ivas_output_config.c @@ -71,22 +71,28 @@ void ivas_renderer_select( *-----------------------------------------------------------------*/ test(); - IF ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) + IF( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) { st_ivas->hCombinedOrientationData->shd_rot_max_order = -1; move16(); } - test(); test(); test(); test(); - IF ( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) - ) + test(); + test(); + test(); + test(); + IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { - test(); test(); test(); test(); test(); - IF ( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) ) + test(); + test(); + test(); + test(); + test(); + IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) ) { - IF ( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ) + IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ) { - IF ( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) ) + IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) ) { *renderer_type = RENDERER_BINAURAL_PARAMETRIC; move16(); @@ -100,8 +106,7 @@ void ivas_renderer_select( ELSE /* ISM_MODE_DISC */ { test(); - IF ( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) - ) + IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { *renderer_type = RENDERER_BINAURAL_OBJECTS_TD; move16(); @@ -117,12 +122,12 @@ void ivas_renderer_select( } } } - ELSE IF ( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) || EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) || ( ( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) && LE_16( st_ivas->nchan_transport, 2 ) ) ) + ELSE IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) || EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) || ( ( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) && LE_16( st_ivas->nchan_transport, 2 ) ) ) { *internal_config = output_config; move16(); - IF ( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) ) + IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) ) { *renderer_type = RENDERER_BINAURAL_PARAMETRIC; move16(); @@ -133,14 +138,13 @@ void ivas_renderer_select( move16(); } } - ELSE IF ( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) + ELSE IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { *internal_config = IVAS_AUDIO_CONFIG_HOA3; move16(); test(); - IF ( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) - ) + IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { *renderer_type = RENDERER_BINAURAL_FASTCONV; move16(); @@ -152,44 +156,46 @@ void ivas_renderer_select( } test(); - IF ( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( *renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) + IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( *renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) { *internal_config = IVAS_AUDIO_CONFIG_7_1_4; move16(); } test(); - IF ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) + IF( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) { nchan_internal = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); - test(); test(); test(); - IF ( EQ_16( nchan_internal, 2 ) ) + test(); + test(); + test(); + IF( EQ_16( nchan_internal, 2 ) ) { st_ivas->hCombinedOrientationData->shd_rot_max_order = 1; } - ELSE IF ( EQ_16( nchan_internal, 4 ) || EQ_16( nchan_internal, 3 ) ) + ELSE IF( EQ_16( nchan_internal, 4 ) || EQ_16( nchan_internal, 3 ) ) { st_ivas->hCombinedOrientationData->shd_rot_max_order = 0; } - ELSE IF ( EQ_16( nchan_internal, 6 ) || EQ_16( nchan_internal, 5 ) ) + ELSE IF( EQ_16( nchan_internal, 6 ) || EQ_16( nchan_internal, 5 ) ) { st_ivas->hCombinedOrientationData->shd_rot_max_order = 2; } - ELSE IF ( EQ_16( nchan_internal, 8 ) || EQ_16( nchan_internal, 7 ) ) + ELSE IF( EQ_16( nchan_internal, 8 ) || EQ_16( nchan_internal, 7 ) ) { st_ivas->hCombinedOrientationData->shd_rot_max_order = 3; } } } - ELSE IF ( EQ_32( st_ivas->ivas_format, MC_FORMAT ) ) + ELSE IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) ) { - IF ( EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) ) + IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) ) { *internal_config = output_config; move16(); - IF ( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) ) + IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) ) { *renderer_type = RENDERER_BINAURAL_PARAMETRIC; move16(); @@ -205,17 +211,21 @@ void ivas_renderer_select( *internal_config = transport_config; move16(); test(); - IF ( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) - { - test(); test(); test(); test(); test(); - IF ( ( EQ_32( st_ivas->transport_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_32( st_ivas->transport_config, IVAS_AUDIO_CONFIG_7_1 ) ) && ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) && ( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) || EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) ) + IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) + { + test(); + test(); + test(); + test(); + test(); + IF( ( EQ_32( st_ivas->transport_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_32( st_ivas->transport_config, IVAS_AUDIO_CONFIG_7_1 ) ) && ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) && ( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) || EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) ) { *renderer_type = RENDERER_BINAURAL_OBJECTS_TD; move16(); } ELSE { - IF ( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) ) + IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) ) { *renderer_type = RENDERER_BINAURAL_MIXER_CONV; move16(); @@ -237,7 +247,7 @@ void ivas_renderer_select( } #endif test(); - IF ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) + IF( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) { /* force HOA3 domain for rotation*/ *internal_config = IVAS_AUDIO_CONFIG_HOA3; @@ -247,7 +257,7 @@ void ivas_renderer_select( } ELSE { - IF ( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) ) + IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) ) { *renderer_type = RENDERER_BINAURAL_MIXER_CONV_ROOM; move16(); @@ -266,48 +276,49 @@ void ivas_renderer_select( * Non-binaural rendering configurations *-----------------------------------------------------------------*/ - ELSE IF ( EQ_32( st_ivas->ivas_format, MONO_FORMAT ) ) + ELSE IF( EQ_32( st_ivas->ivas_format, MONO_FORMAT ) ) { - IF ( EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) + IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) { *renderer_type = RENDERER_NON_DIEGETIC_DOWNMIX; move16(); } } - ELSE IF ( EQ_32( st_ivas->ivas_format, STEREO_FORMAT ) ) + ELSE IF( EQ_32( st_ivas->ivas_format, STEREO_FORMAT ) ) { test(); - IF ( NE_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) && NE_32( output_config, IVAS_AUDIO_CONFIG_MONO ) ) + IF( NE_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) && NE_32( output_config, IVAS_AUDIO_CONFIG_MONO ) ) { *renderer_type = RENDERER_MC; move16(); } } - ELSE IF ( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) ) + ELSE IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) ) { test(); - IF ( ( EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) && ( st_ivas->hDecoderConfig->Opt_non_diegetic_pan ) ) + IF( ( EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) && ( st_ivas->hDecoderConfig->Opt_non_diegetic_pan ) ) { *renderer_type = RENDERER_NON_DIEGETIC_DOWNMIX; move16(); } ELSE { - IF ( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ) + IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ) { *renderer_type = RENDERER_PARAM_ISM; - test(); test(); - IF ( EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) ) + test(); + test(); + IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) ) { *renderer_type = RENDERER_MONO_DOWNMIX; move16(); } - ELSE IF ( EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) + ELSE IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) { *renderer_type = RENDERER_DISABLE; move16(); } - ELSE IF ( EQ_32( output_config, IVAS_AUDIO_CONFIG_FOA ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_HOA2 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_HOA3 ) ) + ELSE IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_FOA ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_HOA2 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_HOA3 ) ) { *renderer_type = RENDERER_SBA_LINEAR_ENC; move16(); @@ -318,18 +329,19 @@ void ivas_renderer_select( ELSE /* ISM_MODE_DISC */ { *renderer_type = RENDERER_TD_PANNING; - test(); test(); - IF ( EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) ) + test(); + test(); + IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) ) { *renderer_type = RENDERER_MONO_DOWNMIX; move16(); } - ELSE IF ( EQ_32( output_config, IVAS_AUDIO_CONFIG_FOA ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_HOA2 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_HOA3 ) ) + ELSE IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_FOA ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_HOA2 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_HOA3 ) ) { *renderer_type = RENDERER_SBA_LINEAR_ENC; move16(); } - ELSE IF ( EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) + ELSE IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) { *renderer_type = RENDERER_DISABLE; move16(); @@ -337,27 +349,54 @@ void ivas_renderer_select( } } } - ELSE IF ( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) + ELSE IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { IVAS_FORMAT ivas_format; *renderer_type = RENDERER_DIRAC; move16(); ivas_format = ( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_MODE_NONE ) ) ? SBA_FORMAT : st_ivas->ivas_format; /* treat ISM_SBA_MODE_NONE just like SBA_FORMAT */ - test(); test(); test(); test(); test(); test(); test(); - test(); test(); test(); test(); test(); test(); test(); - test(); test(); test(); test(); test(); test(); test(); - test(); test(); test(); test(); test(); test(); test(); - test(); test(); test(); - IF ( EQ_32( ivas_format, SBA_FORMAT ) && ( NE_32( output_config, IVAS_AUDIO_CONFIG_5_1 ) && NE_32( output_config, IVAS_AUDIO_CONFIG_5_1_2 ) && NE_32( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) && NE_32( output_config, IVAS_AUDIO_CONFIG_7_1 ) && NE_32( output_config, IVAS_AUDIO_CONFIG_7_1_4 ) && NE_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && NE_32( output_config, IVAS_AUDIO_CONFIG_MONO ) && NE_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) ) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( EQ_32( ivas_format, SBA_FORMAT ) && ( NE_32( output_config, IVAS_AUDIO_CONFIG_5_1 ) && NE_32( output_config, IVAS_AUDIO_CONFIG_5_1_2 ) && NE_32( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) && NE_32( output_config, IVAS_AUDIO_CONFIG_7_1 ) && NE_32( output_config, IVAS_AUDIO_CONFIG_7_1_4 ) && NE_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && NE_32( output_config, IVAS_AUDIO_CONFIG_MONO ) && NE_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) ) { - test(); test(); - IF ( EQ_32( output_config, IVAS_AUDIO_CONFIG_HOA2 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_FOA ) ) + test(); + test(); + IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_HOA2 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_FOA ) ) { *internal_config = output_config; move16(); } - ELSE IF ( EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) + ELSE IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) { *internal_config = IVAS_AUDIO_CONFIG_FOA; move16(); @@ -369,87 +408,88 @@ void ivas_renderer_select( } st_ivas->renderer_type = RENDERER_SBA_LINEAR_DEC; } - ELSE IF ( ( EQ_32( ivas_format, MASA_FORMAT ) && EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) && EQ_16( st_ivas->nchan_transport, 1 ) ) || - ( EQ_32( ivas_format, SBA_FORMAT ) && ( EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) ) ) ) + ELSE IF( ( EQ_32( ivas_format, MASA_FORMAT ) && EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) && EQ_16( st_ivas->nchan_transport, 1 ) ) || + ( EQ_32( ivas_format, SBA_FORMAT ) && ( EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) ) ) ) { *renderer_type = RENDERER_DISABLE; move16(); } - ELSE IF ( ( EQ_32( ivas_format, MASA_FORMAT ) && EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) && LT_32( st_ivas->hDecoderConfig->ivas_total_brate, MASA_STEREO_MIN_BITRATE ) && GT_32( st_ivas->hDecoderConfig->ivas_total_brate, IVAS_SID_5k2 ) ) ) + ELSE IF( ( EQ_32( ivas_format, MASA_FORMAT ) && EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) && LT_32( st_ivas->hDecoderConfig->ivas_total_brate, MASA_STEREO_MIN_BITRATE ) && GT_32( st_ivas->hDecoderConfig->ivas_total_brate, IVAS_SID_5k2 ) ) ) { *renderer_type = RENDERER_DISABLE; move16(); } - ELSE IF ( EQ_32( ivas_format, MASA_FORMAT ) && EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) + ELSE IF( EQ_32( ivas_format, MASA_FORMAT ) && EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) { *renderer_type = RENDERER_STEREO_PARAMETRIC; move16(); } - ELSE IF ( EQ_32( ivas_format, MASA_FORMAT ) && EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) + ELSE IF( EQ_32( ivas_format, MASA_FORMAT ) && EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) { *renderer_type = RENDERER_DISABLE; move16(); } - ELSE IF ( EQ_32( ivas_format, SBA_FORMAT ) && EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) ) + ELSE IF( EQ_32( ivas_format, SBA_FORMAT ) && EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) ) { *renderer_type = RENDERER_SBA_LINEAR_DEC; move16(); } - ELSE IF ( EQ_32( ivas_format, SBA_ISM_FORMAT ) && EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) + ELSE IF( EQ_32( ivas_format, SBA_ISM_FORMAT ) && EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) { *renderer_type = RENDERER_OSBA_STEREO; move16(); } - ELSE IF ( EQ_32( ivas_format, SBA_ISM_FORMAT ) && EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) ) + ELSE IF( EQ_32( ivas_format, SBA_ISM_FORMAT ) && EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) ) { *renderer_type = RENDERER_MONO_DOWNMIX; move16(); } - ELSE IF ( EQ_32( ivas_format, SBA_ISM_FORMAT ) && ( EQ_32( output_config, IVAS_AUDIO_CONFIG_FOA ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_HOA2 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_HOA3 ) ) ) + ELSE IF( EQ_32( ivas_format, SBA_ISM_FORMAT ) && ( EQ_32( output_config, IVAS_AUDIO_CONFIG_FOA ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_HOA2 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_HOA3 ) ) ) { *renderer_type = RENDERER_OSBA_AMBI; move16(); } - ELSE IF ( EQ_32( ivas_format, SBA_ISM_FORMAT ) && ( EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_2 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_7_1 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_7_1_4 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) ) + ELSE IF( EQ_32( ivas_format, SBA_ISM_FORMAT ) && ( EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_2 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_7_1 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_7_1_4 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) ) { *renderer_type = RENDERER_OSBA_LS; move16(); } - ELSE IF ( EQ_32( ivas_format, SBA_ISM_FORMAT ) && EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) + ELSE IF( EQ_32( ivas_format, SBA_ISM_FORMAT ) && EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) { *renderer_type = RENDERER_SBA_LINEAR_DEC; move16(); } } - ELSE IF ( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) + ELSE IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) { *renderer_type = RENDERER_DIRAC; move16(); - IF ( EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) ) + IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) ) { *renderer_type = RENDERER_MONO_DOWNMIX; move16(); } - ELSE IF ( EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) + ELSE IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) { *renderer_type = RENDERER_STEREO_PARAMETRIC; move16(); } - ELSE IF ( EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) + ELSE IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) { *renderer_type = RENDERER_DISABLE; move16(); } } - ELSE IF ( EQ_32( st_ivas->ivas_format, MC_FORMAT ) ) + ELSE IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) ) { *internal_config = transport_config; test(); - IF ( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) && NE_32( *internal_config, output_config ) ) + IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) && NE_32( *internal_config, output_config ) ) { - test(); test(); - IF ( NE_32( output_config, IVAS_AUDIO_CONFIG_FOA ) && NE_32( output_config, IVAS_AUDIO_CONFIG_HOA2 ) && NE_32( output_config, IVAS_AUDIO_CONFIG_HOA3 ) ) + test(); + test(); + IF( NE_32( output_config, IVAS_AUDIO_CONFIG_FOA ) && NE_32( output_config, IVAS_AUDIO_CONFIG_HOA2 ) && NE_32( output_config, IVAS_AUDIO_CONFIG_HOA3 ) ) { *renderer_type = RENDERER_MC; move16(); @@ -460,13 +500,14 @@ void ivas_renderer_select( move16(); } } - ELSE IF ( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) { *internal_config = transport_config; - IF ( NE_32( *internal_config, output_config ) ) + IF( NE_32( *internal_config, output_config ) ) { - test(); test(); - IF ( NE_32( output_config, IVAS_AUDIO_CONFIG_FOA ) && NE_32( output_config, IVAS_AUDIO_CONFIG_HOA2 ) && NE_32( output_config, IVAS_AUDIO_CONFIG_HOA3 ) ) + test(); + test(); + IF( NE_32( output_config, IVAS_AUDIO_CONFIG_FOA ) && NE_32( output_config, IVAS_AUDIO_CONFIG_HOA2 ) && NE_32( output_config, IVAS_AUDIO_CONFIG_HOA3 ) ) { *renderer_type = RENDERER_MC; move16(); @@ -478,10 +519,11 @@ void ivas_renderer_select( } } } - ELSE IF ( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) ) + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) ) { - test(); test(); - IF ( EQ_32( output_config, IVAS_AUDIO_CONFIG_FOA ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_HOA2 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_HOA3 ) ) + test(); + test(); + IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_FOA ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_HOA2 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_HOA3 ) ) { *renderer_type = RENDERER_SBA_LINEAR_ENC; move16(); @@ -491,22 +533,23 @@ void ivas_renderer_select( *renderer_type = RENDERER_MC_PARAMMC; } } - ELSE IF ( EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) ) + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) ) { *internal_config = output_config; move16(); /* No rendering for 1TC to Mono or Stereo and 2TC to Stereo */ test(); - IF ( EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) + IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) { - test(); test(); - IF ( EQ_16( st_ivas->nchan_transport, 1 ) ) + test(); + test(); + IF( EQ_16( st_ivas->nchan_transport, 1 ) ) { *renderer_type = RENDERER_DISABLE; move16(); } - ELSE IF ( EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) && EQ_16( st_ivas->nchan_transport, 2 ) && !st_ivas->hOutSetup.separateChannelEnabled ) + ELSE IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) && EQ_16( st_ivas->nchan_transport, 2 ) && !st_ivas->hOutSetup.separateChannelEnabled ) { *renderer_type = RENDERER_DISABLE; move16(); @@ -520,14 +563,17 @@ void ivas_renderer_select( ELSE { *renderer_type = RENDERER_DIRAC; - test(); test(); test(); test(); - IF ( EQ_32( output_config, IVAS_AUDIO_CONFIG_FOA ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_HOA2 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_HOA3 ) ) + test(); + test(); + test(); + test(); + IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_FOA ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_HOA2 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_HOA3 ) ) { *renderer_type = RENDERER_SBA_LINEAR_ENC; *internal_config = transport_config; move16(); } - ELSE IF ( EQ_32( transport_config, IVAS_AUDIO_CONFIG_5_1 ) && ( EQ_32( output_config, IVAS_AUDIO_CONFIG_7_1 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) ) ) + ELSE IF( EQ_32( transport_config, IVAS_AUDIO_CONFIG_5_1 ) && ( EQ_32( output_config, IVAS_AUDIO_CONFIG_7_1 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) ) ) { *internal_config = transport_config; move16(); @@ -564,8 +610,7 @@ void ivas_renderer_select( st_ivas->hCombinedOrientationData->shd_rot_max_order = -1; } - if ( output_config == IVAS_AUDIO_CONFIG_BINAURAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB - ) + if ( output_config == IVAS_AUDIO_CONFIG_BINAURAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) { if ( st_ivas->ivas_format == ISM_FORMAT ) { @@ -582,8 +627,7 @@ void ivas_renderer_select( } else /* ISM_MODE_DISC */ { - if ( output_config == IVAS_AUDIO_CONFIG_BINAURAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB - ) + if ( output_config == IVAS_AUDIO_CONFIG_BINAURAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) { *renderer_type = RENDERER_BINAURAL_OBJECTS_TD; *internal_config = output_config; @@ -612,8 +656,7 @@ void ivas_renderer_select( { *internal_config = IVAS_AUDIO_CONFIG_HOA3; - if ( output_config == IVAS_AUDIO_CONFIG_BINAURAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB - ) + if ( output_config == IVAS_AUDIO_CONFIG_BINAURAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) { *renderer_type = RENDERER_BINAURAL_FASTCONV; } diff --git a/lib_dec/ivas_pca_dec.c b/lib_dec/ivas_pca_dec.c index ffb10f8eb..dd9bf96e4 100644 --- a/lib_dec/ivas_pca_dec.c +++ b/lib_dec/ivas_pca_dec.c @@ -309,4 +309,4 @@ void ivas_pca_dec( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/ivas_pca_dec_fx.c b/lib_dec/ivas_pca_dec_fx.c index ef53d89b3..58aa5d04d 100644 --- a/lib_dec/ivas_pca_dec_fx.c +++ b/lib_dec/ivas_pca_dec_fx.c @@ -112,7 +112,7 @@ static void pca_inv_transform_sub_fx( temp = 0; FOR( i = 0; i < n_channels; i++ ) { - temp2 = Mpy_32_16_1(buffer_data[i], eigVec[k * IVAS_PCA_INTERP + i]); + temp2 = Mpy_32_16_1( buffer_data[i], eigVec[k * IVAS_PCA_INTERP + i] ); temp = L_add( temp, temp2 ); } transformed_data[k][j + start] = temp; @@ -235,12 +235,12 @@ void ivas_pca_dec_fx( /* @@@TODO: check how ivas_total_brate is set if bfi == 1 */ // ToDo: and what happens in DTX where "ivas_total_brate" can be close to zero? /* handle bit rate switching */ - IF( NE_32(ivas_total_brate, PCA_BRATE) || ( EQ_32(ivas_total_brate, PCA_BRATE) && GT_16( n_channels, FOA_CHANNELS) ) ) + IF( NE_32( ivas_total_brate, PCA_BRATE ) || ( EQ_32( ivas_total_brate, PCA_BRATE ) && GT_16( n_channels, FOA_CHANNELS ) ) ) { /* set PCA by-pass mode in current frame and interpolate transform as previous frame used PCA */ pca_dec_reset_dquat_fx( ql_fx, qr_fx ); - IF( ( NE_32(last_ivas_total_brate, PCA_BRATE) ) || ( EQ_32(last_ivas_total_brate, PCA_BRATE) && GT_16(hPCA->prev_pca_bypass, 1) ) ) + IF( ( NE_32( last_ivas_total_brate, PCA_BRATE ) ) || ( EQ_32( last_ivas_total_brate, PCA_BRATE ) && GT_16( hPCA->prev_pca_bypass, 1 ) ) ) { pca_dec_reset_mem_eigvec_fx( hPCA ); } @@ -250,10 +250,10 @@ void ivas_pca_dec_fx( } pca_dec_update_dquat_fx( hPCA, ql_fx, qr_fx ); - hPCA->prev_pca_bypass = add(hPCA->prev_pca_bypass, 1); + hPCA->prev_pca_bypass = add( hPCA->prev_pca_bypass, 1 ); move16(); - IF( GT_16(hPCA->prev_pca_bypass, 2 )) + IF( GT_16( hPCA->prev_pca_bypass, 2 ) ) { hPCA->prev_pca_bypass = 2; move16(); @@ -274,11 +274,11 @@ void ivas_pca_dec_fx( move16(); } - IF( EQ_16(pca_bypass, PCA_MODE_INACTIVE )) + IF( EQ_16( pca_bypass, PCA_MODE_INACTIVE ) ) { pca_dec_reset_dquat_fx( ql_fx, qr_fx ); - IF( GT_16(hPCA->prev_pca_bypass, 1 )) //&& (hPCA->pca_off_hangover == 0)) + IF( GT_16( hPCA->prev_pca_bypass, 1 ) ) //&& (hPCA->pca_off_hangover == 0)) { /* copy input data into output directly as previous frame was already in by-pass mode */ pca_dec_reset_mem_eigvec_fx( hPCA ); @@ -290,7 +290,7 @@ void ivas_pca_dec_fx( pca_dec_update_dquat_fx( hPCA, ql_fx, qr_fx ); - hPCA->prev_pca_bypass = add(hPCA->prev_pca_bypass , 1); + hPCA->prev_pca_bypass = add( hPCA->prev_pca_bypass, 1 ); hPCA->prev_pca_bypass = min( hPCA->prev_pca_bypass, 2 ); move16(); return; // exit happens here @@ -317,4 +317,4 @@ void ivas_pca_dec_fx( move16(); return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/ivas_post_proc.c b/lib_dec/ivas_post_proc.c index f058777e0..297708375 100644 --- a/lib_dec/ivas_post_proc.c +++ b/lib_dec/ivas_post_proc.c @@ -259,17 +259,16 @@ void ivas_post_proc_fx( #ifdef IVAS_FLOAT_FIXED void stereo_dft_dec_core_switching_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ Word32 output_fx[], /* i/o: synthesis @internal Fs */ Word32 synth_fx[], /* i/o: synthesis @output Fs */ Word32 hb_synth_fx[], /* i/o: hb synthesis */ Word32 DFT_fx[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* o : DFT buffers */ - const Word16 output_frame, /* i : output frame length */ - const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB FOR DFT Stereo */ - const Word16 sba_dirac_stereo_dtx_flag, /* i : DTX indicator FOR SBA DirAC stereo */ + const Word16 output_frame, /* i : output frame length */ + const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB FOR DFT Stereo */ + const Word16 sba_dirac_stereo_dtx_flag, /* i : DTX indicator FOR SBA DirAC stereo */ Word16 *q, - Word16 *q_DFT -) + Word16 *q_DFT ) { Word32 output_Fs; Decoder_State *st; @@ -284,7 +283,7 @@ void stereo_dft_dec_core_switching_fx( Word64 calc_inv; Word32 synth_tmp_fx[L_FRAME48k]; - + st = hCPE->hCoreCoder[0]; /* in DFT stereo, only M channel is decoded by the CoreCoder */ output_Fs = st->output_Fs; L_frameTCX = st->hTcxDec->L_frameTCX; @@ -385,7 +384,7 @@ void stereo_dft_dec_core_switching_fx( Copy32( synth_fx, synth_tmp_fx, output_frame ); Word16 qtmps = norm_l( tmps ); Word32 tmps_fx = L_shl( tmps, qtmps ); - Word32 tmps_inv = (Word32)(calc_inv / tmps); + Word32 tmps_inv = (Word32) ( calc_inv / tmps ); FOR( i = 0; i < tmps; i++ ) { synth_tmp_fx[i] = L_add( Mpy_32_32( hb_synth_fx[i + delay_tdbwe], tmps_fx - i * ( 1 << qtmps ) ), Mpy_32_32( synth_fx[i], i * ( 1 << qtmps ) ) ); @@ -466,7 +465,7 @@ void stereo_dft_dec_core_switching_fx( Word16 qmem_len = norm_l( mem_len ); Word32 mem_len_fx = L_shl( mem_len, qmem_len ); - Word32 mem_len_inv = (Word32)(calc_inv / tmps); + Word32 mem_len_inv = (Word32) ( calc_inv / tmps ); FOR( i = 0; i < mem_len; i++ ) { hCPE->input_mem_LB_fx[0][i] = Mpy_32_32( hCPE->input_mem_LB_fx[0][i], mem_len_fx - ( i * ( 1 << qmem_len ) ) ); @@ -494,7 +493,7 @@ void stereo_dft_dec_core_switching_fx( } /* ACELP fading-in*/ Word16 qdelay_dft_dec_lb = norm_l( delay_dft_dec_lb ); - Word32 delay_dft_dec_lb_inv = (Word32)(calc_inv / delay_dft_dec_lb); + Word32 delay_dft_dec_lb_inv = (Word32) ( calc_inv / delay_dft_dec_lb ); FOR( i = 0; i < delay_dft_dec_lb; i++ ) { hCPE->input_mem_LB_fx[0][NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) - delay_dft_dec_lb + i] = @@ -518,7 +517,7 @@ void stereo_dft_dec_core_switching_fx( IF( hCPE->last_element_mode != IVAS_CPE_MDCT ) { Word16 qdelay_dft_dec = norm_l( delay_dft_dec ); - Word32 delay_dft_dec_inv = (Word32)(calc_inv / delay_dft_dec); + Word32 delay_dft_dec_inv = (Word32) ( calc_inv / delay_dft_dec ); Word32 delay_dft_dec_fx = L_shl( delay_dft_dec, qdelay_dft_dec ); FOR( i = 0; i < delay_dft_dec; i++ ) /* 1.25 ms of hb_synth fade-in and TCX fade-out */ { @@ -646,12 +645,12 @@ void stereo_dft_dec_core_switching_fx( Copy32( output_fx, pAp_input_fx, st->L_frame ); IF( st->last_core != ACELP_CORE ) /* TCX/HQ-Core -> ACELP */ { - Word16 shift = sub(hCPE->hStereoDft->q_ap_fade_mem_fx, q_DFT[0]); + Word16 shift = sub( hCPE->hStereoDft->q_ap_fade_mem_fx, q_DFT[0] ); FOR( i = 0; i < ap_fade_len; i++ ) { pAp_input_fx[i] = L_add( Mpy_32_32( pAp_input_fx[i], i * ( 1 << qap_fade_len ) ), - Mpy_32_32( L_shr(hCPE->hStereoDft->ap_fade_mem_fx[i], shift), ap_fade_len_fx - i * ( 1 << qap_fade_len ) ) ); + Mpy_32_32( L_shr( hCPE->hStereoDft->ap_fade_mem_fx[i], shift ), ap_fade_len_fx - i * ( 1 << qap_fade_len ) ) ); pAp_input_fx[i] = L_shl( Mpy_32_32( pAp_input_fx[i], ap_fade_len_inv ), 31 - qap_fade_len ); } } @@ -660,7 +659,7 @@ void stereo_dft_dec_core_switching_fx( /* apply predelay to have same overall filter delay FOR all cases */ - delay_signal_q_adj_fx( pAp_input_fx, st->L_frame, hCPE->hStereoDft->ap_delay_mem_fx, predelay, *q, hCPE->hStereoDft->q_ap_delay_mem_fx); + delay_signal_q_adj_fx( pAp_input_fx, st->L_frame, hCPE->hStereoDft->ap_delay_mem_fx, predelay, *q, hCPE->hStereoDft->q_ap_delay_mem_fx ); /* input zeroes FOR transient frames */ IF( hCPE->hStereoDft->attackPresent ) @@ -854,7 +853,7 @@ void stereo_dft_dec_core_switching( stereo_dft_dec_analyze( hCPE, output, DFT, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_LB_ADD, 1, 0 ); /* BPF */ - if ( st->p_bpf_noise_buf_float) + if ( st->p_bpf_noise_buf_float ) { set_zero( hCPE->input_mem_BPF[0], NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) ); } @@ -901,7 +900,7 @@ void stereo_dft_dec_core_switching( stereo_dft_dec_analyze( hCPE, output, DFT, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_LB, 0, 0 ); /* BPF */ - if ( st->p_bpf_noise_buf_float) + if ( st->p_bpf_noise_buf_float ) { stereo_dft_dec_analyze( hCPE, st->p_bpf_noise_buf_float, DFT, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_BPF, 0, 0 ); } @@ -922,7 +921,7 @@ void stereo_dft_dec_core_switching( stereo_dft_dec_analyze( hCPE, output, DFT, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_LB, 0, 0 ); /* BPF */ - if ( st->p_bpf_noise_buf_float) + if ( st->p_bpf_noise_buf_float ) { stereo_dft_dec_analyze( hCPE, st->p_bpf_noise_buf_float, DFT, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_BPF, 0, 0 ); } @@ -976,7 +975,7 @@ void stereo_dft_dec_core_switching( stereo_dft_dec_analyze( hCPE, output, DFT, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_LB, 0, 0 ); /* BPF */ - if ( st->p_bpf_noise_buf_float) + if ( st->p_bpf_noise_buf_float ) { stereo_dft_dec_analyze( hCPE, st->p_bpf_noise_buf_float, DFT, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_BPF, 0, 0 ); } diff --git a/lib_dec/ivas_qmetadata_dec.c b/lib_dec/ivas_qmetadata_dec.c index f97c89461..c830e1b78 100644 --- a/lib_dec/ivas_qmetadata_dec.c +++ b/lib_dec/ivas_qmetadata_dec.c @@ -6603,19 +6603,17 @@ static Word16 read_GR_min_removed_data( } } - FOR( j = 0; j < no_data; j++ ) - { - IF( GT_16( no_cv_vec[j], 1 ) ) - { + FOR( j = 0; j < no_data; j++ ){ + IF( GT_16( no_cv_vec[j], 1 ) ){ decoded_idx[j] = add( decoded_idx[j], min_index ); - move16(); - } - } - - *p_bit_pos = bit_pos; move16(); +} +} - return nbits; +*p_bit_pos = bit_pos; +move16(); + +return nbits; } #else static int16_t read_GR_min_removed_data( @@ -7981,8 +7979,8 @@ static int16_t read_surround_coherence_hr( } #ifdef NON_BE_FIX_1048_THRESHOLD_COH_BASOP - int_error_ratio_surr = (int32_t)(MASA_SUR_COH_PRECISION * error_ratio_surr); - error_ratio_surr = (float)(int_error_ratio_surr * MASA_SUR_COH_THRESHOLD); + int_error_ratio_surr = (int32_t) ( MASA_SUR_COH_PRECISION * error_ratio_surr ); + error_ratio_surr = (float) ( int_error_ratio_surr * MASA_SUR_COH_THRESHOLD ); #endif if ( error_ratio_surr <= 0 ) @@ -8115,11 +8113,11 @@ static Word16 read_surround_coherence_hr_fx( Word16 j, k, sf; UWord16 byteBuffer; UWord16 idx_sur_coh[MASA_MAXIMUM_CODING_SUBBANDS]; - //IVAS_QDIRECTION *q_direction; + // IVAS_QDIRECTION *q_direction; Word16 min_index; Word16 d, idx; coding_subbands = hQMetaData->q_direction[0].cfg.nbands; - //q_direction = hQMetaData->q_direction; + // q_direction = hQMetaData->q_direction; bits_sur_coherence = 0; bit_pos = *p_bit_pos; diff --git a/lib_dec/ivas_qspherical_dec.c b/lib_dec/ivas_qspherical_dec.c index 9436d6d96..332f4952f 100644 --- a/lib_dec/ivas_qspherical_dec.c +++ b/lib_dec/ivas_qspherical_dec.c @@ -150,4 +150,4 @@ Word32 deindex_elevation_fx( return theta_hat_fx; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/ivas_range_uni_dec.c b/lib_dec/ivas_range_uni_dec.c index 1e426869a..395a0654c 100644 --- a/lib_dec/ivas_range_uni_dec.c +++ b/lib_dec/ivas_range_uni_dec.c @@ -113,10 +113,10 @@ void rc_uni_dec_init_fx( rc_st_dec->bit_error_detected = 0; - FOR ( i = 0; i < 4; i++ ) + FOR( i = 0; i < 4; i++ ) { // Not adding basops becuase the resultant value greater than Word32 - rc_st_dec->rc_low = (rc_st_dec->rc_low << 8) + rc_uni_dec_read_fx(rc_st_dec); + rc_st_dec->rc_low = ( rc_st_dec->rc_low << 8 ) + rc_uni_dec_read_fx( rc_st_dec ); } return; @@ -228,7 +228,7 @@ UWord16 rc_uni_dec_read_symbol_fastS_fx( /* the condition val >= level is equivalent with low >= range * level */ /* in case of bitstream errors it is possible that val >= (1 << tot_shift) */ - IF ( low >= ( range << tot_shift ) ) + IF( low >= ( range << tot_shift ) ) { rc_st_dec->bit_error_detected = 1; @@ -247,16 +247,16 @@ UWord16 rc_uni_dec_read_symbol_fastS_fx( /* ceil(log2(x)) = 1 + floor(log2(x - 1)), for any x >= 2 */ /* floor(log2(y)) = 31 - norm_ul_float(y) = 30 - norm_l(y), for any 1 <= y <= 2 ^ 31 - 1 */ - ceil_log2_alphabet_size = sub(31 , norm_l( alphabet_size - 1 )); + ceil_log2_alphabet_size = sub( 31, norm_l( alphabet_size - 1 ) ); /* completely equivalent with 32 - norm_ul_float(alphabet_size - 1), but norm_l is faster */ reversed_low = ( range << tot_shift ) - low; /* at most ceil_log2_alphabet_size steps are needed so that sym_end - sym_begin == 1 */ - FOR ( step = 0; step < ceil_log2_alphabet_size; step++ ) + FOR( step = 0; step < ceil_log2_alphabet_size; step++ ) { - sym_middle = shr(add( sym_begin , sym_end ) , 1); + sym_middle = shr( add( sym_begin, sym_end ), 1 ); /* completely equvalent with low >= range * ((1 << tot_shift) - table[sym_middle]) */ - IF ( range * L_sub( L_shl( 1 , tot_shift ) , cum_freq_table[sym_middle] ) >= reversed_low ) + IF( range * L_sub( L_shl( 1, tot_shift ), cum_freq_table[sym_middle] ) >= reversed_low ) { sym_begin = sym_middle; } @@ -318,11 +318,11 @@ static void rc_uni_dec_update_fx( rc_st_dec->rc_range *= sym_freq; /* rc_range was shifted right by up to 16, so at most two renormalizations are needed */ - IF ( rc_st_dec->rc_range < 0x01000000 ) + IF( rc_st_dec->rc_range < 0x01000000 ) { rc_st_dec->rc_low = ( rc_st_dec->rc_low << 8 ) + rc_uni_dec_read_fx( rc_st_dec ); rc_st_dec->rc_range <<= 8; - IF ( rc_st_dec->rc_range < 0x01000000 ) + IF( rc_st_dec->rc_range < 0x01000000 ) { rc_st_dec->rc_low = ( rc_st_dec->rc_low << 8 ) + rc_uni_dec_read_fx( rc_st_dec ); rc_st_dec->rc_range <<= 8; @@ -561,7 +561,7 @@ Word16 rc_uni_dec_virtual_finish_fx( { /* the function is completely equivalent with rc_uni_dec_finish */ // Not adding basop because value of rc_st_dec->rc_range exceeds Word32 - return add( rc_st_dec->bit_count , sub( norm_l( rc_st_dec->rc_range >> 24 ), 53 ) ); + return add( rc_st_dec->bit_count, sub( norm_l( rc_st_dec->rc_range >> 24 ), 53 ) ); } @@ -638,10 +638,10 @@ static Word16 rc_uni_dec_read_fx( /* pack the first 8 bits from shifted_bit_buffer, first bit is most significant */ - byte_read = s_or( shl( shifted_bit_buffer[0], 7 ), s_or( shl( shifted_bit_buffer[1], 6 ), - s_or( shl( shifted_bit_buffer[2], 5 ), s_or( shl( shifted_bit_buffer[3], 4 ), - s_or( shl( shifted_bit_buffer[4], 3 ), s_or( shl( shifted_bit_buffer[5], 2 ), - s_or( shl( shifted_bit_buffer[6], 1 ), shifted_bit_buffer[7] ) ) ) ) ) ) ) ; + byte_read = s_or( shl( shifted_bit_buffer[0], 7 ), s_or( shl( shifted_bit_buffer[1], 6 ), + s_or( shl( shifted_bit_buffer[2], 5 ), s_or( shl( shifted_bit_buffer[3], 4 ), + s_or( shl( shifted_bit_buffer[4], 3 ), s_or( shl( shifted_bit_buffer[5], 2 ), + s_or( shl( shifted_bit_buffer[6], 1 ), shifted_bit_buffer[7] ) ) ) ) ) ) ); return byte_read; } diff --git a/lib_dec/ivas_rom_dec.h b/lib_dec/ivas_rom_dec.h index 165b7f3ee..f03bc53cc 100644 --- a/lib_dec/ivas_rom_dec.h +++ b/lib_dec/ivas_rom_dec.h @@ -133,7 +133,6 @@ extern const float dmxmtx_table[BINAURAL_CHANNELS][11]; extern const Word32 dmxmtx_table_fx[BINAURAL_CHANNELS][11]; - /*----------------------------------------------------------------------* * MC ParamUpmix ROM tables *-----------------------------------------------------------------------*/ diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 7c63005b7..13186b6e5 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -56,20 +56,20 @@ void ivas_sba_set_cna_cng_flag( { Word16 n, cpe_id; - IF ( st_ivas->ivas_format == SBA_FORMAT && st_ivas->nchan_transport == 1 ) + IF( st_ivas->ivas_format == SBA_FORMAT && st_ivas->nchan_transport == 1 ) { /* skip as done in init function */ /* st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag = 0; */ /* st_ivas->hSCE[0]->hCoreCoder[0]->cng_sba_flag = 0; */ } - ELSE IF ( st_ivas->nchan_transport == 1 && ( ( st_ivas->renderer_type == RENDERER_DIRAC && st_ivas->hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) || ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) ) ) + ELSE IF( st_ivas->nchan_transport == 1 && ( ( st_ivas->renderer_type == RENDERER_DIRAC && st_ivas->hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) || ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) ) ) { st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag = 1; st_ivas->hSCE[0]->hCoreCoder[0]->cng_sba_flag = 1; } - ELSE IF ( st_ivas->nchan_transport == 2 ) + ELSE IF( st_ivas->nchan_transport == 2 ) { - FOR ( n = 0; n < CPE_CHANNELS; n++ ) + FOR( n = 0; n < CPE_CHANNELS; n++ ) { st_ivas->hCPE[0]->hCoreCoder[n]->cna_dirac_flag = 0; st_ivas->hCPE[0]->hCoreCoder[n]->cng_sba_flag = 1; @@ -77,9 +77,9 @@ void ivas_sba_set_cna_cng_flag( } ELSE { - FOR ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - FOR ( n = 0; n < CPE_CHANNELS; n++ ) + FOR( n = 0; n < CPE_CHANNELS; n++ ) { st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cna_dirac_flag = 0; st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cng_sba_flag = 0; @@ -131,7 +131,7 @@ void ivas_sba_set_cna_cng_flag( } #endif -#ifndef IVAS_FLOAT_FIXED +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * ivas_sba_dec_reconfigure() * @@ -141,7 +141,7 @@ void ivas_sba_set_cna_cng_flag( ivas_error ivas_sba_dec_reconfigure( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ uint16_t *nSamplesFlushed, /* o : number of samples flushed */ - int16_t *data /* o : output synthesis signal */ + int16_t *data /* o : output synthesis signal */ ) { int16_t nchan_transport_old, nSCE_old, nCPE_old, nchan_hp20_old; @@ -223,8 +223,7 @@ ivas_error ivas_sba_dec_reconfigure( } else { - if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB - ) + if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) { renderer_type_new = RENDERER_BINAURAL_FASTCONV; } @@ -348,9 +347,8 @@ ivas_error ivas_sba_dec_reconfigure( ivas_pca_dec_init( hSpar->hPCA ); #ifdef IVAS_FLOAT_FIXED - ivas_pca_dec_init_fx(hSpar->hPCA); + ivas_pca_dec_init_fx( hSpar->hPCA ); #endif - } ivas_spar_config( ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &hSpar->core_nominal_brate, st_ivas->sid_format ); @@ -423,10 +421,8 @@ ivas_error ivas_sba_dec_reconfigure( ivas_mono_dmx_renderer_close( &st_ivas->hMonoDmxRenderer ); } - if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) ? IVAS_MAX_NUM_BANDS : ( IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ) - , - st_ivas->ivas_format - ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) ? IVAS_MAX_NUM_BANDS : ( IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ), + st_ivas->ivas_format ) ) != IVAS_ERR_OK ) { return error; } @@ -475,14 +471,14 @@ ivas_error ivas_sba_dec_reconfigure( if ( st_ivas->renderer_type == RENDERER_DISABLE ) { #ifdef IVAS_FLOAT_FIXED - ivas_dirac_rend_close_fx(&(st_ivas->hDirACRend)); - ivas_spat_hSpatParamRendCom_close_fx(&(st_ivas->hSpatParamRendCom)); - ivas_dirac_dec_close_fx(&(st_ivas->hDirAC)); - vbap_free_data_fx(&(st_ivas->hVBAPdata)); + ivas_dirac_rend_close_fx( &( st_ivas->hDirACRend ) ); + ivas_spat_hSpatParamRendCom_close_fx( &( st_ivas->hSpatParamRendCom ) ); + ivas_dirac_dec_close_fx( &( st_ivas->hDirAC ) ); + vbap_free_data_fx( &( st_ivas->hVBAPdata ) ); #else ivas_dirac_rend_close( &( st_ivas->hDirACRend ) ); - ivas_spat_hSpatParamRendCom_close(&(st_ivas->hSpatParamRendCom)); - ivas_dirac_dec_close(&(st_ivas->hDirAC)); + ivas_spat_hSpatParamRendCom_close( &( st_ivas->hSpatParamRendCom ) ); + ivas_dirac_dec_close( &( st_ivas->hDirAC ) ); vbap_free_data( &( st_ivas->hVBAPdata ) ); #endif } @@ -504,7 +500,7 @@ ivas_error ivas_sba_dec_reconfigure( st_ivas->ism_mode = ISM_SBA_MODE_DISC; #ifdef IVAS_FLOAT_FIXED - IF ( ( error = ivas_ism_metadata_dec_create_fx( st_ivas, st_ivas->nchan_ism, temp_brate ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_ism_metadata_dec_create_fx( st_ivas, st_ivas->nchan_ism, temp_brate ) ) != IVAS_ERR_OK ) #else if ( ( error = ivas_ism_metadata_dec_create( st_ivas, st_ivas->nchan_ism, temp_brate ) ) != IVAS_ERR_OK ) #endif @@ -523,7 +519,7 @@ ivas_error ivas_sba_dec_reconfigure( st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM ) ) { #ifdef IVAS_FLOAT_FIXED - IF ( ( error = ivas_ism_renderer_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_ism_renderer_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -599,7 +595,7 @@ ivas_error ivas_sba_dec_reconfigure( } #ifdef IVAS_FLOAT_FIXED - IF ( ( error = ivas_corecoder_dec_reconfig_fx( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old, st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport, ( st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_corecoder_dec_reconfig_fx( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old, st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport, ( st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) { return error; } @@ -614,10 +610,10 @@ ivas_error ivas_sba_dec_reconfigure( * HP20 memories *-----------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED - if ((error = ivas_hp20_dec_reconfig_fx(st_ivas, nchan_hp20_old)) != IVAS_ERR_OK) - { - return error; - } + if ( ( error = ivas_hp20_dec_reconfig_fx( st_ivas, nchan_hp20_old ) ) != IVAS_ERR_OK ) + { + return error; + } #else if ( ( error = ivas_hp20_dec_reconfig( st_ivas, nchan_hp20_old ) ) != IVAS_ERR_OK ) { @@ -727,17 +723,17 @@ ivas_error ivas_sba_dec_reconfigure( * floating-point output audio buffers *-----------------------------------------------------------------*/ - nchan_out_buff = ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); + nchan_out_buff = ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); - if ( ( error = ivas_output_buff_dec( st_ivas->p_output_f, nchan_out_buff_old, nchan_out_buff ) ) != IVAS_ERR_OK ) - { - return error; - } + if ( ( error = ivas_output_buff_dec( st_ivas->p_output_f, nchan_out_buff_old, nchan_out_buff ) ) != IVAS_ERR_OK ) + { + return error; + } #ifdef IVAS_FLOAT_FIXED - if ( ( error = ivas_output_buff_dec_fx( st_ivas->p_output_fx, nchan_out_buff_old, nchan_out_buff ) ) != IVAS_ERR_OK ) - { - return error; - } + if ( ( error = ivas_output_buff_dec_fx( st_ivas->p_output_fx, nchan_out_buff_old, nchan_out_buff ) ) != IVAS_ERR_OK ) + { + return error; + } #endif // IVAS_FLOAT_FIXED return error; @@ -752,7 +748,7 @@ ivas_error ivas_sba_dec_reconfigure( ivas_error ivas_sba_dec_reconfigure_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ uint16_t *nSamplesFlushed, /* o : number of samples flushed */ - int16_t *data /* o : output synthesis signal */ + int16_t *data /* o : output synthesis signal */ ) { int16_t nchan_transport_old, nSCE_old, nCPE_old, nchan_hp20_old; @@ -834,8 +830,7 @@ ivas_error ivas_sba_dec_reconfigure_fx( } else { - if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB - ) + if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) { renderer_type_new = RENDERER_BINAURAL_FASTCONV; } @@ -987,11 +982,10 @@ ivas_error ivas_sba_dec_reconfigure_fx( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for PCA decoder" ); } - //ivas_pca_dec_init( hSpar->hPCA ); + // ivas_pca_dec_init( hSpar->hPCA ); #ifdef IVAS_FLOAT_FIXED - ivas_pca_dec_init_fx(hSpar->hPCA); + ivas_pca_dec_init_fx( hSpar->hPCA ); #endif - } ivas_spar_config( ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &hSpar->core_nominal_brate, st_ivas->sid_format ); @@ -1037,12 +1031,12 @@ ivas_error ivas_sba_dec_reconfigure_fx( if ( st_ivas->hBinRenderer == NULL && ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) ) { /*float2fix block: to be removed*/ - /* if (st_ivas->hIntSetup.ls_azimuth && st_ivas->hIntSetup.ls_azimuth_fx) { - floatToFixed_arrL((float *)st_ivas->hIntSetup.ls_azimuth, (Word32 *)st_ivas->hIntSetup.ls_azimuth_fx, Q22, st_ivas->hIntSetup.nchan_out_woLFE); - } - if (st_ivas->hIntSetup.ls_elevation && st_ivas->hIntSetup.ls_elevation_fx) { - floatToFixed_arrL((float *)st_ivas->hIntSetup.ls_elevation, (Word32 *)st_ivas->hIntSetup.ls_elevation_fx, Q22, st_ivas->hIntSetup.nchan_out_woLFE); - }*/ + /* if (st_ivas->hIntSetup.ls_azimuth && st_ivas->hIntSetup.ls_azimuth_fx) { + floatToFixed_arrL((float *)st_ivas->hIntSetup.ls_azimuth, (Word32 *)st_ivas->hIntSetup.ls_azimuth_fx, Q22, st_ivas->hIntSetup.nchan_out_woLFE); + } + if (st_ivas->hIntSetup.ls_elevation && st_ivas->hIntSetup.ls_elevation_fx) { + floatToFixed_arrL((float *)st_ivas->hIntSetup.ls_elevation, (Word32 *)st_ivas->hIntSetup.ls_elevation_fx, Q22, st_ivas->hIntSetup.nchan_out_woLFE); + }*/ /*float2fix block end*/ /* open fastconv binaural renderer */ if ( ( error = ivas_binRenderer_open_fx( st_ivas ) ) != IVAS_ERR_OK ) @@ -1068,10 +1062,8 @@ ivas_error ivas_sba_dec_reconfigure_fx( ivas_mono_dmx_renderer_close( &st_ivas->hMonoDmxRenderer ); } - if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) ? IVAS_MAX_NUM_BANDS : ( IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ) - , - st_ivas->ivas_format - ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) ? IVAS_MAX_NUM_BANDS : ( IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ), + st_ivas->ivas_format ) ) != IVAS_ERR_OK ) { return error; } @@ -1120,14 +1112,14 @@ ivas_error ivas_sba_dec_reconfigure_fx( if ( st_ivas->renderer_type == RENDERER_DISABLE ) { #ifdef IVAS_FLOAT_FIXED - ivas_dirac_rend_close_fx(&(st_ivas->hDirACRend)); - ivas_spat_hSpatParamRendCom_close_fx(&(st_ivas->hSpatParamRendCom)); - ivas_dirac_dec_close_fx(&(st_ivas->hDirAC)); - vbap_free_data_fx(&(st_ivas->hVBAPdata)); + ivas_dirac_rend_close_fx( &( st_ivas->hDirACRend ) ); + ivas_spat_hSpatParamRendCom_close_fx( &( st_ivas->hSpatParamRendCom ) ); + ivas_dirac_dec_close_fx( &( st_ivas->hDirAC ) ); + vbap_free_data_fx( &( st_ivas->hVBAPdata ) ); #else ivas_dirac_rend_close( &( st_ivas->hDirACRend ) ); - ivas_spat_hSpatParamRendCom_close(&(st_ivas->hSpatParamRendCom)); - ivas_dirac_dec_close(&(st_ivas->hDirAC)); + ivas_spat_hSpatParamRendCom_close( &( st_ivas->hSpatParamRendCom ) ); + ivas_dirac_dec_close( &( st_ivas->hDirAC ) ); vbap_free_data( &( st_ivas->hVBAPdata ) ); #endif } @@ -1149,7 +1141,7 @@ ivas_error ivas_sba_dec_reconfigure_fx( st_ivas->ism_mode = ISM_SBA_MODE_DISC; #ifdef IVAS_FLOAT_FIXED - IF ( ( error = ivas_ism_metadata_dec_create_fx( st_ivas, st_ivas->nchan_ism, temp_brate ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_ism_metadata_dec_create_fx( st_ivas, st_ivas->nchan_ism, temp_brate ) ) != IVAS_ERR_OK ) #else if ( ( error = ivas_ism_metadata_dec_create( st_ivas, st_ivas->nchan_ism, temp_brate ) ) != IVAS_ERR_OK ) #endif @@ -1168,7 +1160,7 @@ ivas_error ivas_sba_dec_reconfigure_fx( st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM ) ) { #ifdef IVAS_FLOAT_FIXED - IF ( ( error = ivas_ism_renderer_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_ism_renderer_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -1203,20 +1195,20 @@ ivas_error ivas_sba_dec_reconfigure_fx( #ifdef IVAS_FLOAT_FIXED Word16 SrcInd[MAX_NUM_TDREND_CHANNELS]; Word16 num_src; - IF((error = ivas_td_binaural_open_fx(st_ivas, SrcInd, &num_src)) != IVAS_ERR_OK) + IF( ( error = ivas_td_binaural_open_fx( st_ivas, SrcInd, &num_src ) ) != IVAS_ERR_OK ) { return error; } #if 1 // Cleanup changes for ivas_td_binaural_open: fixed to float Word16 nchan_rend = num_src; - IF(EQ_16(st_ivas->ivas_format, MC_FORMAT) && NE_16(st_ivas->transport_config, IVAS_AUDIO_CONFIG_LS_CUSTOM)) + IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) && NE_16( st_ivas->transport_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) { nchan_rend--; /* Skip LFE channel -- added to the others */ } - FOR(Word16 nS = 0; nS < nchan_rend; nS++) + FOR( Word16 nS = 0; nS < nchan_rend; nS++ ) { TDREND_SRC_t *Src_p = st_ivas->hBinRendererTd->Sources[SrcInd[nS]]; - IF(Src_p->SrcSpatial_p != NULL) + IF( Src_p->SrcSpatial_p != NULL ) { Src_p->SrcSpatial_p->q_Pos_p = Q31; } @@ -1270,7 +1262,7 @@ ivas_error ivas_sba_dec_reconfigure_fx( } #ifdef IVAS_FLOAT_FIXED - IF ( ( error = ivas_corecoder_dec_reconfig_fx( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old, st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport, ( st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_corecoder_dec_reconfig_fx( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old, st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport, ( st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) { return error; } @@ -1285,10 +1277,10 @@ ivas_error ivas_sba_dec_reconfigure_fx( * HP20 memories *-----------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED - if ((error = ivas_hp20_dec_reconfig_fx(st_ivas, nchan_hp20_old)) != IVAS_ERR_OK) - { - return error; - } + if ( ( error = ivas_hp20_dec_reconfig_fx( st_ivas, nchan_hp20_old ) ) != IVAS_ERR_OK ) + { + return error; + } #else if ( ( error = ivas_hp20_dec_reconfig( st_ivas, nchan_hp20_old ) ) != IVAS_ERR_OK ) { @@ -1312,7 +1304,7 @@ ivas_error ivas_sba_dec_reconfigure_fx( *-----------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED #if 1 - // Float to fix conversions for ivas_cldfb_dec_reconfig_fx + // Float to fix conversions for ivas_cldfb_dec_reconfig_fx #ifndef MSAN_FIX IF( st_ivas->hSpar ) { @@ -1414,17 +1406,17 @@ ivas_error ivas_sba_dec_reconfigure_fx( * floating-point output audio buffers *-----------------------------------------------------------------*/ - nchan_out_buff = ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); + nchan_out_buff = ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); - if ( ( error = ivas_output_buff_dec( st_ivas->p_output_f, nchan_out_buff_old, nchan_out_buff ) ) != IVAS_ERR_OK ) - { - return error; - } + if ( ( error = ivas_output_buff_dec( st_ivas->p_output_f, nchan_out_buff_old, nchan_out_buff ) ) != IVAS_ERR_OK ) + { + return error; + } #ifdef IVAS_FLOAT_FIXED - if ( ( error = ivas_output_buff_dec_fx( st_ivas->p_output_fx, nchan_out_buff_old, nchan_out_buff ) ) != IVAS_ERR_OK ) - { - return error; - } + if ( ( error = ivas_output_buff_dec_fx( st_ivas->p_output_fx, nchan_out_buff_old, nchan_out_buff ) ) != IVAS_ERR_OK ) + { + return error; + } #endif // IVAS_FLOAT_FIXED return error; @@ -1730,7 +1722,7 @@ void ivas_sba_dec_digest_tc( #endif #ifdef IVAS_FLOAT_FIXED void ivas_sba_dec_digest_tc_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ const Word16 nCldfbSlots, /* i : number of CLDFB slots */ const Word16 nSamplesForRendering /* i : number of samples provided */ ) @@ -1738,64 +1730,83 @@ void ivas_sba_dec_digest_tc_fx( Word16 ch_idx, nchan_transport; /* set the md map */ - IF ( st_ivas->hDirAC ) + IF( st_ivas->hDirAC ) { ivas_dirac_dec_set_md_map_fx( st_ivas, nCldfbSlots ); } test(); - IF ( EQ_16(st_ivas->ivas_format, SBA_FORMAT) || EQ_16(st_ivas->ivas_format, SBA_ISM_FORMAT )) + IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { - ivas_spar_dec_digest_tc_fx(st_ivas, st_ivas->nchan_transport, nCldfbSlots, nSamplesForRendering); + ivas_spar_dec_digest_tc_fx( st_ivas, st_ivas->nchan_transport, nCldfbSlots, nSamplesForRendering ); } test(); - IF ( st_ivas->hDiracDecBin != NULL && ( st_ivas->hDiracDecBin->useTdDecorr ) ) + IF( st_ivas->hDiracDecBin != NULL && ( st_ivas->hDiracDecBin->useTdDecorr ) ) { Word16 nSamplesLeftForTD, default_frame; Word32 *decorr_signal[BINAURAL_CHANNELS]; Word32 *p_tc[2 * BINAURAL_CHANNELS]; Word16 q_format = 14; - default_frame = (Word16)(st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ); - nSamplesLeftForTD = nSamplesForRendering; move16(); + default_frame = (Word16) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ); + nSamplesLeftForTD = nSamplesForRendering; + move16(); - FOR ( ch_idx = 0; ch_idx < BINAURAL_CHANNELS; ch_idx++ ) + FOR( ch_idx = 0; ch_idx < BINAURAL_CHANNELS; ch_idx++ ) { - decorr_signal[ch_idx] = st_ivas->hTcBuffer->tc_fx[ch_idx + BINAURAL_CHANNELS]; move32(); - p_tc[ch_idx] = st_ivas->hTcBuffer->tc_fx[ch_idx]; move32(); + decorr_signal[ch_idx] = st_ivas->hTcBuffer->tc_fx[ch_idx + BINAURAL_CHANNELS]; + move32(); + p_tc[ch_idx] = st_ivas->hTcBuffer->tc_fx[ch_idx]; + move32(); } - WHILE ( nSamplesLeftForTD ) + WHILE( nSamplesLeftForTD ) { Word16 nSamplesToDecorr = s_min( nSamplesLeftForTD, default_frame ); - IF ( st_ivas->hDiracDecBin->hTdDecorr ) + IF( st_ivas->hDiracDecBin->hTdDecorr ) { ivas_td_decorr_process_fx( st_ivas->hDiracDecBin->hTdDecorr, p_tc, decorr_signal, nSamplesToDecorr, &q_format ); } - FOR ( ch_idx = 0; ch_idx < BINAURAL_CHANNELS; ch_idx++ ) + FOR( ch_idx = 0; ch_idx < BINAURAL_CHANNELS; ch_idx++ ) { decorr_signal[ch_idx] += nSamplesToDecorr; p_tc[ch_idx] += nSamplesToDecorr; } - nSamplesLeftForTD = sub(nSamplesLeftForTD, nSamplesToDecorr); + nSamplesLeftForTD = sub( nSamplesLeftForTD, nSamplesToDecorr ); } } /* if we have a late CNG generation, do it here */ - nchan_transport = st_ivas->nchan_transport; move16(); + nchan_transport = st_ivas->nchan_transport; + move16(); - test(); test(); test(); test(); test(); - IF ( EQ_16(st_ivas->ivas_format, MASA_FORMAT) && LT_32(st_ivas->hDecoderConfig->ivas_total_brate, MASA_STEREO_MIN_BITRATE) && ( GT_32(st_ivas->hDecoderConfig->ivas_total_brate, IVAS_SID_5k2) || ( LE_32(st_ivas->hDecoderConfig->ivas_total_brate, IVAS_SID_5k2) && GT_16(st_ivas->nCPE, 0) && EQ_16(st_ivas->hCPE[0]->nchan_out, 1) ) ) ) + test(); + test(); + test(); + test(); + test(); + IF( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) && LT_32( st_ivas->hDecoderConfig->ivas_total_brate, MASA_STEREO_MIN_BITRATE ) && ( GT_32( st_ivas->hDecoderConfig->ivas_total_brate, IVAS_SID_5k2 ) || ( LE_32( st_ivas->hDecoderConfig->ivas_total_brate, IVAS_SID_5k2 ) && GT_16( st_ivas->nCPE, 0 ) && EQ_16( st_ivas->hCPE[0]->nchan_out, 1 ) ) ) ) { - nchan_transport = 1; move16();/* Only one channel transported */ + nchan_transport = 1; + move16(); /* Only one channel transported */ } - test(); test(); test(); test(); test(); test(); test(); test(); test(); test(); test(); - IF ( ( ( NE_16(st_ivas->ivas_format, SBA_FORMAT) && NE_16(st_ivas->ivas_format, SBA_ISM_FORMAT) ) && EQ_16(st_ivas->nchan_transport, 1) && st_ivas->hSCE[0]->hCoreCoder[0] != NULL && st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag ) || - ( (EQ_16(st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC) || EQ_16(st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM) || EQ_16(st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC) ) && (EQ_16(nchan_transport, 1) && NE_16(st_ivas->nchan_transport, 2) && st_ivas->hSCE[0]->hCoreCoder[0] != NULL && st_ivas->hSCE[0]->hCoreCoder[0]->cng_sba_flag ) ) ) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( ( NE_16( st_ivas->ivas_format, SBA_FORMAT ) && NE_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) && EQ_16( st_ivas->nchan_transport, 1 ) && st_ivas->hSCE[0]->hCoreCoder[0] != NULL && st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag ) || + ( ( EQ_16( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) ) && ( EQ_16( nchan_transport, 1 ) && NE_16( st_ivas->nchan_transport, 2 ) && st_ivas->hSCE[0]->hCoreCoder[0] != NULL && st_ivas->hSCE[0]->hCoreCoder[0]->cng_sba_flag ) ) ) { Decoder_State *st = st_ivas->hSCE[0]->hCoreCoder[0]; - Scale_sig(st->hFdCngDec->hFdCngCom->A_cng, M + 1, norm_s(st->hFdCngDec->hFdCngCom->A_cng[0] - 1) - 2); + Scale_sig( st->hFdCngDec->hFdCngCom->A_cng, M + 1, norm_s( st->hFdCngDec->hFdCngCom->A_cng[0] - 1 ) - 2 ); generate_masking_noise_lb_dirac_fx( st->hFdCngDec->hFdCngCom, st_ivas->hTcBuffer->tc_fx[1], nCldfbSlots, st->cna_dirac_flag && st->flag_cna ); } @@ -1811,12 +1822,12 @@ void ivas_sba_dec_digest_tc_fx( *-------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED ivas_error ivas_sba_dec_render_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ UWord16 *nSamplesAvailableNext, /* o : number of CLDFB slots still to render */ Word32 *output_fx[], /* o : rendered time signal */ - Word16 out_len /*Store the length of values in each channel*/ + Word16 out_len /*Store the length of values in each channel*/ ) { Word16 slots_to_render, first_sf, last_sf, subframe_idx; @@ -1833,9 +1844,9 @@ ivas_error ivas_sba_dec_render_fx( hSpar = st_ivas->hSpar; hSpatParamRendCom = st_ivas->hSpatParamRendCom; nchan_internal = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); - nchan_out = add(st_ivas->hIntSetup.nchan_out_woLFE , st_ivas->hIntSetup.num_lfe); + nchan_out = add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe ); - FOR ( ch = 0; ch < nchan_out; ch++ ) + FOR( ch = 0; ch < nchan_out; ch++ ) { output_f_local_fx[ch] = output_fx[ch]; } @@ -1843,55 +1854,55 @@ ivas_error ivas_sba_dec_render_fx( slot_size = NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */ - slots_to_render = s_min( sub(hSpar->num_slots , hSpar->slots_rendered), nSamplesAsked / slot_size ); - *nSamplesRendered = imult1616(slots_to_render , slot_size); + slots_to_render = s_min( sub( hSpar->num_slots, hSpar->slots_rendered ), nSamplesAsked / slot_size ); + *nSamplesRendered = imult1616( slots_to_render, slot_size ); first_sf = hSpar->subframes_rendered; last_sf = first_sf; move16(); move16(); - WHILE ( GT_16(slots_to_render , 0) ) + WHILE( GT_16( slots_to_render, 0 ) ) { - slots_to_render = sub(slots_to_render,hSpar->subframe_nbslots[last_sf]); + slots_to_render = sub( slots_to_render, hSpar->subframe_nbslots[last_sf] ); last_sf++; } - FOR ( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ ) + FOR( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ ) { - Word16 n_samples_sf = imult1616(slot_size , hSpar->subframe_nbslots[subframe_idx]); + Word16 n_samples_sf = imult1616( slot_size, hSpar->subframe_nbslots[subframe_idx] ); - ivas_spar_dec_upmixer_sf_fx( st_ivas, output_f_local_fx, nchan_internal,output_f_local_len ); - FOR ( ch = 0; ch < nchan_out; ch++ ) + ivas_spar_dec_upmixer_sf_fx( st_ivas, output_f_local_fx, nchan_internal, output_f_local_len ); + FOR( ch = 0; ch < nchan_out; ch++ ) { - output_f_local_fx[ch] = output_f_local_fx[ch]+n_samples_sf; + output_f_local_fx[ch] = output_f_local_fx[ch] + n_samples_sf; } - output_f_local_len = sub(output_f_local_len,n_samples_sf); + output_f_local_len = sub( output_f_local_len, n_samples_sf ); /* update combined orientation access index */ ivas_combined_orientation_update_index( st_ivas->hCombinedOrientationData, n_samples_sf ); } - IF ( EQ_16(st_ivas->renderer_type , RENDERER_SBA_LINEAR_DEC) ) + IF( EQ_16( st_ivas->renderer_type, RENDERER_SBA_LINEAR_DEC ) ) { - IF ( ( error = ivas_sba_linear_renderer_fx( output_fx, *nSamplesRendered, st_ivas->hIntSetup.nchan_out_woLFE, 0, st_ivas->hDecoderConfig->output_config, st_ivas->hOutSetup ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_sba_linear_renderer_fx( output_fx, *nSamplesRendered, st_ivas->hIntSetup.nchan_out_woLFE, 0, st_ivas->hDecoderConfig->output_config, st_ivas->hOutSetup ) ) != IVAS_ERR_OK ) { return error; } } - IF ( st_ivas->hDirAC != NULL && EQ_16(hSpar->slots_rendered , hSpar->num_slots) ) + IF( st_ivas->hDirAC != NULL && EQ_16( hSpar->slots_rendered, hSpar->num_slots ) ) { - IF ( EQ_16(st_ivas->hDirAC->hConfig->dec_param_estim , 1) ) + IF( EQ_16( st_ivas->hDirAC->hConfig->dec_param_estim, 1 ) ) { - hSpatParamRendCom->dirac_read_idx = add( hSpatParamRendCom->dirac_read_idx , DEFAULT_JBM_CLDFB_TIMESLOTS ) % hSpatParamRendCom->dirac_md_buffer_length; + hSpatParamRendCom->dirac_read_idx = add( hSpatParamRendCom->dirac_read_idx, DEFAULT_JBM_CLDFB_TIMESLOTS ) % hSpatParamRendCom->dirac_md_buffer_length; } ELSE { - hSpatParamRendCom->dirac_read_idx = add( hSpatParamRendCom->dirac_read_idx , DEFAULT_JBM_SUBFRAMES_5MS ) % hSpatParamRendCom->dirac_md_buffer_length; + hSpatParamRendCom->dirac_read_idx = add( hSpatParamRendCom->dirac_read_idx, DEFAULT_JBM_SUBFRAMES_5MS ) % hSpatParamRendCom->dirac_md_buffer_length; } move16(); } - *nSamplesAvailableNext = imult1616(sub( hSpar->num_slots , hSpar->slots_rendered ) , slot_size); + *nSamplesAvailableNext = imult1616( sub( hSpar->num_slots, hSpar->slots_rendered ), slot_size ); return IVAS_ERR_OK; } @@ -1977,4 +1988,3 @@ ivas_error ivas_sba_dec_render( return IVAS_ERR_OK; } #endif // IVAS_FLOAT_FIXED - diff --git a/lib_dec/ivas_sba_dirac_stereo_dec.c b/lib_dec/ivas_sba_dirac_stereo_dec.c index af1f06f2b..c869afb08 100644 --- a/lib_dec/ivas_sba_dirac_stereo_dec.c +++ b/lib_dec/ivas_sba_dirac_stereo_dec.c @@ -890,9 +890,9 @@ void ivas_sba_dirac_stereo_dec( } synchro_synthesis( st_ivas->hDecoderConfig->ivas_total_brate, hCPE, output, output_frame, 1 /*st_ivas->sba_dirac_stereo_flag*/ ); - - //Todo use below once input is fixed not done due to complication in pointer - //synchro_synthesis_fixed_clean( st_ivas->hDecoderConfig->ivas_total_brate, hCPE, output, output_frame, 1 /*st_ivas->sba_dirac_stereo_flag*/ ); + + // Todo use below once input is fixed not done due to complication in pointer + // synchro_synthesis_fixed_clean( st_ivas->hDecoderConfig->ivas_total_brate, hCPE, output, output_frame, 1 /*st_ivas->sba_dirac_stereo_flag*/ ); /* output scaling */ if ( !sba_mono_flag ) @@ -937,4 +937,4 @@ void ivas_sba_dirac_stereo_dec( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/ivas_sba_dirac_stereo_dec_fx.c b/lib_dec/ivas_sba_dirac_stereo_dec_fx.c index 09343b736..aaa838a2c 100644 --- a/lib_dec/ivas_sba_dirac_stereo_dec_fx.c +++ b/lib_dec/ivas_sba_dirac_stereo_dec_fx.c @@ -44,8 +44,8 @@ #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED -#define SIN_NEG_30_DEGREES_Q15 ((Word16)0xC000) -#define SIN_30_DEGREES_Q15 ((Word16)0x4000) +#define SIN_NEG_30_DEGREES_Q15 ( (Word16) 0xC000 ) +#define SIN_30_DEGREES_Q15 ( (Word16) 0x4000 ) /*-------------------------------------------------------------------* * ivas_get_sba_dirac_stereo_flag() @@ -65,11 +65,11 @@ Word16 ivas_get_sba_dirac_stereo_flag( output_config = st_ivas->hDecoderConfig->output_config; move16(); - IF ( EQ_16(st_ivas->ivas_format, SBA_FORMAT) || (EQ_16( st_ivas->ivas_format, MC_FORMAT) && EQ_16(st_ivas->mc_mode, MC_MODE_MCMASA )) ) + IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || ( EQ_16( st_ivas->ivas_format, MC_FORMAT ) && EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) ) { - IF ( EQ_16(st_ivas->ivas_format, SBA_FORMAT )) + IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) ) { - IF ( EQ_16(output_config, IVAS_AUDIO_CONFIG_STEREO) || ( EQ_16(output_config, IVAS_AUDIO_CONFIG_MONO) && EQ_16(st_ivas->nchan_transport, 1) ) ) + IF( EQ_16( output_config, IVAS_AUDIO_CONFIG_STEREO ) || ( EQ_16( output_config, IVAS_AUDIO_CONFIG_MONO ) && EQ_16( st_ivas->nchan_transport, 1 ) ) ) { sba_dirac_stereo_flag = 1; move16(); @@ -77,16 +77,16 @@ Word16 ivas_get_sba_dirac_stereo_flag( } ELSE { - IF ( EQ_16(st_ivas->nchan_transport, 1) && EQ_16(output_config, IVAS_AUDIO_CONFIG_STEREO) ) + IF( EQ_16( st_ivas->nchan_transport, 1 ) && EQ_16( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) { sba_dirac_stereo_flag = 1; move16(); } } } - ELSE IF ( EQ_16(st_ivas->ivas_format, SBA_ISM_FORMAT) ) + ELSE IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { - IF ( EQ_16(output_config, IVAS_AUDIO_CONFIG_STEREO) ) + IF( EQ_16( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) { sba_dirac_stereo_flag = 1; move16(); @@ -107,7 +107,7 @@ void ivas_sba_dirac_stereo_config( STEREO_DFT_CONFIG_DATA_HANDLE hConfig /* o : DFT stereo configuration */ ) { - IF ( hConfig != NULL ) + IF( hConfig != NULL ) { hConfig->dmx_active = STEREO_DFT_DMX_ACTIVE; move16(); @@ -152,7 +152,7 @@ static Word16 ivas_sba_dirac_stereo_band_config( nbands = SBA_DIRAC_STEREO_NUM_BANDS; move16(); - IF ( spar_flag ) + IF( spar_flag ) { nbands = IVAS_MAX_NUM_BANDS; move16(); @@ -163,94 +163,96 @@ static Word16 ivas_sba_dirac_stereo_band_config( move16(); } - SWITCH (output_Fs) + SWITCH( output_Fs ) { - case 8000: - num_cldfb_bands = 10; - move16(); - BREAK; - case 16000: - num_cldfb_bands = 20; - move16(); - BREAK; - case 32000: - num_cldfb_bands = 40; - move16(); - BREAK; - case 48000: - num_cldfb_bands = 60; - move16(); - BREAK; - default: - num_cldfb_bands = 60; - move16(); - assert(0); + case 8000: + num_cldfb_bands = 10; + move16(); + BREAK; + case 16000: + num_cldfb_bands = 20; + move16(); + BREAK; + case 32000: + num_cldfb_bands = 40; + move16(); + BREAK; + case 48000: + num_cldfb_bands = 60; + move16(); + BREAK; + default: + num_cldfb_bands = 60; + move16(); + assert( 0 ); } - bins_per_cldfb_band = idiv1616(NFFT , shl( num_cldfb_bands, 1 )); + bins_per_cldfb_band = idiv1616( NFFT, shl( num_cldfb_bands, 1 ) ); move16(); band_limits[0] = 1; move16(); - FOR ( i = 1; i < nbands; i++ ) + FOR( i = 1; i < nbands; i++ ) { - IF ( spar_flag ) + IF( spar_flag ) { - band_limits[i] = i_mult(DirAC_band_grouping_12[i], bins_per_cldfb_band); + band_limits[i] = i_mult( DirAC_band_grouping_12[i], bins_per_cldfb_band ); move16(); } ELSE { - band_limits[i] = i_mult(DirAC_band_grouping_5[i], bins_per_cldfb_band); + band_limits[i] = i_mult( DirAC_band_grouping_5[i], bins_per_cldfb_band ); move16(); } - IF ( GE_16(band_limits[i], shr(NFFT, 1) ) ) + IF( GE_16( band_limits[i], shr( NFFT, 1 ) ) ) { nbands = i; move16(); BREAK; } } - band_limits[nbands] = shr(NFFT, 1); + band_limits[nbands] = shr( NFFT, 1 ); move16(); return nbands; } static Word16 get_panning_tangent_gain( - const Word16 sinAngleMapped) + const Word16 sinAngleMapped ) { - Word16 tbl_len = sizeof(ivas_sine_panning_tbl_fx) / sizeof(ivas_sine_panning_tbl_fx[0]); move16(); - Word16 idx = shr(tbl_len, 1); move16(); + Word16 tbl_len = sizeof( ivas_sine_panning_tbl_fx ) / sizeof( ivas_sine_panning_tbl_fx[0] ); + move16(); + Word16 idx = shr( tbl_len, 1 ); + move16(); const Word16 *ptr_sin = &ivas_sine_panning_tbl_fx[0]; const Word16 *ptr_tan = &ivas_tan_panning_gain_dirac_tbl_fx[0]; Word16 lim_l = 0; move16(); Word16 lim_r = tbl_len; move16(); - WHILE (1) + WHILE( 1 ) { idx = shr( add( lim_l, lim_r ), 1 ); - IF (GE_16(idx, tbl_len)) + IF( GE_16( idx, tbl_len ) ) { return ptr_tan[tbl_len - 1]; } - ELSE IF (LE_16(idx, 0)) + ELSE IF( LE_16( idx, 0 ) ) { return ptr_tan[0]; } - ELSE IF ( LE_16(sinAngleMapped, ptr_sin[idx + 1]) && GE_16(sinAngleMapped, ptr_sin[idx])) + ELSE IF( LE_16( sinAngleMapped, ptr_sin[idx + 1] ) && GE_16( sinAngleMapped, ptr_sin[idx] ) ) { - IF (EQ_16(sinAngleMapped, ptr_sin[idx + 1])) + IF( EQ_16( sinAngleMapped, ptr_sin[idx + 1] ) ) { return ptr_tan[idx + 1]; } - ELSE IF(EQ_16(sinAngleMapped, ptr_sin[idx])) + ELSE IF( EQ_16( sinAngleMapped, ptr_sin[idx] ) ) { return ptr_tan[idx]; } ELSE { - Word16 mid = add(shr( ptr_sin[idx], 1 ), shr(ptr_sin[idx + 1], 1)); + Word16 mid = add( shr( ptr_sin[idx], 1 ), shr( ptr_sin[idx + 1], 1 ) ); move16(); IF( LE_16( sinAngleMapped, mid ) ) { @@ -262,12 +264,12 @@ static Word16 get_panning_tangent_gain( } } } - ELSE IF (GT_16( sinAngleMapped, ptr_sin[idx] )) + ELSE IF( GT_16( sinAngleMapped, ptr_sin[idx] ) ) { lim_l = add( idx, 1 ); move16(); } - ELSE IF (LT_16(sinAngleMapped, ptr_sin[idx])) + ELSE IF( LT_16( sinAngleMapped, ptr_sin[idx] ) ) { lim_r = sub( idx, 1 ); move16(); @@ -279,46 +281,49 @@ static Word16 get_panning( const Word16 aziDeg, const Word16 eleDeg ) { - Word16 panning = 0; move16(); - Word16 azAddEl = aziDeg + eleDeg; move16(); - Word16 azSubEl = aziDeg - eleDeg; move16(); + Word16 panning = 0; + move16(); + Word16 azAddEl = aziDeg + eleDeg; + move16(); + Word16 azSubEl = aziDeg - eleDeg; + move16(); const Word16 *ptr_sin_az = &ivas_sin_az_fx[180]; - while (azAddEl > 180) + while ( azAddEl > 180 ) { azAddEl = azAddEl - 360; move16(); } - while (azAddEl < -180) + while ( azAddEl < -180 ) { azAddEl = azAddEl + 360; move16(); } - while (azSubEl > 180) + while ( azSubEl > 180 ) { azSubEl = azSubEl - 360; move16(); } - while (azSubEl < -180) + while ( azSubEl < -180 ) { azSubEl = azSubEl + 360; move16(); } /*sin(az)cos(el) = 0.5 * (sin(az + el) + sin(az - el)) */ - Word16 sin_az_cos_el = add(shr(ptr_sin_az[azAddEl], 1), shr(ptr_sin_az[azSubEl], 1)); + Word16 sin_az_cos_el = add( shr( ptr_sin_az[azAddEl], 1 ), shr( ptr_sin_az[azSubEl], 1 ) ); move16(); - IF (GE_32(sin_az_cos_el, SIN_30_DEGREES_Q15)) + IF( GE_32( sin_az_cos_el, SIN_30_DEGREES_Q15 ) ) { /* Left side */ - panning = (Word16)0x7fff; + panning = (Word16) 0x7fff; move16(); } - ELSE IF (LE_32(sin_az_cos_el, SIN_NEG_30_DEGREES_Q15)) + ELSE IF( LE_32( sin_az_cos_el, SIN_NEG_30_DEGREES_Q15 ) ) { /* Right side */ - panning = (Word16)0x8000; + panning = (Word16) 0x8000; move16(); } ELSE - { /* Tangent panning law */ - panning = get_panning_tangent_gain(sin_az_cos_el); + { /* Tangent panning law */ + panning = get_panning_tangent_gain( sin_az_cos_el ); } return panning; } @@ -333,13 +338,12 @@ static Word16 get_panning( static void map_params_dirac_to_stereo( STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ const IVAS_QMETADATA_HANDLE hQMetaData, /* i : frame of MASA q_metadata */ - Word32 synth[], /* i : decoded downmix signal */ - Word32 DFT[STEREO_DFT_BUF_MAX], /* i/o: DFT buffer */ - const UWord8 b_wide_panning, /* i : flag indicating wider panning */ + Word32 synth[], /* i : decoded downmix signal */ + Word32 DFT[STEREO_DFT_BUF_MAX], /* i/o: DFT buffer */ + const UWord8 b_wide_panning, /* i : flag indicating wider panning */ const Word16 L_frame, /* i : core signal length */ - const Word16 mcmasa, /* i : McMASA flag */ - const Word16 q_synth -) + const Word16 mcmasa, /* i : McMASA flag */ + const Word16 q_synth ) { Word16 i, b, k; Word16 k_offset; @@ -370,35 +374,35 @@ static void map_params_dirac_to_stereo( move16(); k_offset = STEREO_DFT_OFFSET; move16(); - side_gain = hStereoDft->side_gain_fx + i_mult(k_offset, STEREO_DFT_BAND_MAX); - res_pred_gain = hStereoDft->res_pred_gain_fx + i_mult(k_offset, STEREO_DFT_BAND_MAX); + side_gain = hStereoDft->side_gain_fx + i_mult( k_offset, STEREO_DFT_BAND_MAX ); + res_pred_gain = hStereoDft->res_pred_gain_fx + i_mult( k_offset, STEREO_DFT_BAND_MAX ); q_direction = &( hQMetaData->q_direction[0] ); /* gain smoothing factor */ pDFT = DFT; q_nrg = hStereoDft->q_dft; move16(); - FOR ( k = 0; k < NB_DIV; k++ ) + FOR( k = 0; k < NB_DIV; k++ ) { - FOR ( b = 0; b < hStereoDft->nbands; b++ ) + FOR( b = 0; b < hStereoDft->nbands; b++ ) { Word64 tmp64 = 0; /* calculate band-wise subframe energies */ subframe_band_nrg[k][b] = 0; move32(); - FOR ( i = hStereoDft->band_limits[b]; i < hStereoDft->band_limits[b + 1]; i++ ) + FOR( i = hStereoDft->band_limits[b]; i < hStereoDft->band_limits[b + 1]; i++ ) { - tmp64 = W_add(tmp64, W_add(W_mult0_32_32(pDFT[2 * i], pDFT[2 * i]), - W_mult0_32_32(pDFT[2 * i + 1], pDFT[2 * i + 1]))); + tmp64 = W_add( tmp64, W_add( W_mult0_32_32( pDFT[2 * i], pDFT[2 * i] ), + W_mult0_32_32( pDFT[2 * i + 1], pDFT[2 * i + 1] ) ) ); move32(); } - subframe_band_nrg[k][b] = W_extract_h(W_shl(tmp64, 1)); - q_nrg = sub(Q31, sub(shl(hStereoDft->q_dft, 1) , Q31)); + subframe_band_nrg[k][b] = W_extract_h( W_shl( tmp64, 1 ) ); + q_nrg = sub( Q31, sub( shl( hStereoDft->q_dft, 1 ), Q31 ) ); subframe_band_nrg[k][b] = Sqrt32( subframe_band_nrg[k][b], &q_nrg ); move32(); - IF (NE_16(sub(Q31, q_nrg) , hStereoDft->q_smooth_buf_fx)) + IF( NE_16( sub( Q31, q_nrg ), hStereoDft->q_smooth_buf_fx ) ) { - subframe_band_nrg[k][b] = L_shl(subframe_band_nrg[k][b], sub(hStereoDft->q_smooth_buf_fx, sub(Q31, q_nrg))); + subframe_band_nrg[k][b] = L_shl( subframe_band_nrg[k][b], sub( hStereoDft->q_smooth_buf_fx, sub( Q31, q_nrg ) ) ); } hStereoDft->smooth_buf_fx[b][NB_DIV - 1 - k] = subframe_band_nrg[k][b]; move32(); @@ -409,34 +413,34 @@ static void map_params_dirac_to_stereo( smooth_long_avg[k][b] = 0; move32(); /* Multiplying and adding avoids overflow */ - FOR ( i = sub(NB_DIV - 1, k); i < add(SBA_DIRAC_NRG_SMOOTH_SHORT + NB_DIV - 1, k); i++ ) + FOR( i = sub( NB_DIV - 1, k ); i < add( SBA_DIRAC_NRG_SMOOTH_SHORT + NB_DIV - 1, k ); i++ ) { - smooth_short_avg[k][b] = Madd_32_16(smooth_short_avg[k][b], hStereoDft->smooth_buf_fx[b][i], (Word16)0x2AAB); /* 1/ 3 in Q15*/ + smooth_short_avg[k][b] = Madd_32_16( smooth_short_avg[k][b], hStereoDft->smooth_buf_fx[b][i], (Word16) 0x2AAB ); /* 1/ 3 in Q15*/ move32(); - smooth_long_avg[k][b] = Madd_32_16(smooth_long_avg[k][b], hStereoDft->smooth_buf_fx[b][i], (Word16)0x0CCD); /* 1/ 10 in Q15*/ + smooth_long_avg[k][b] = Madd_32_16( smooth_long_avg[k][b], hStereoDft->smooth_buf_fx[b][i], (Word16) 0x0CCD ); /* 1/ 10 in Q15*/ move32(); } - FOR ( i = sub(NB_DIV - 1 + SBA_DIRAC_NRG_SMOOTH_SHORT, k) ; i < sub(SBA_DIRAC_NRG_SMOOTH_LONG + NB_DIV - 1, k); i++ ) + FOR( i = sub( NB_DIV - 1 + SBA_DIRAC_NRG_SMOOTH_SHORT, k ); i < sub( SBA_DIRAC_NRG_SMOOTH_LONG + NB_DIV - 1, k ); i++ ) { - smooth_long_avg[k][b] = Madd_32_16(smooth_long_avg[k][b], hStereoDft->smooth_buf_fx[b][i], (Word16)0x0CCD); + smooth_long_avg[k][b] = Madd_32_16( smooth_long_avg[k][b], hStereoDft->smooth_buf_fx[b][i], (Word16) 0x0CCD ); move32(); } /* calculate smoothing factor based on energy averages */ /* reduce factor for higher short-term energy */ - IF (NE_32(smooth_long_avg[k][b], 0)) + IF( NE_32( smooth_long_avg[k][b], 0 ) ) { - hStereoDft->smooth_fac_fx[k][b] = extract_l(s_min( MAX_16, BASOP_Util_Divide3232_Scale(smooth_long_avg[k][b] , smooth_short_avg[k][b], &q_div) )); + hStereoDft->smooth_fac_fx[k][b] = extract_l( s_min( MAX_16, BASOP_Util_Divide3232_Scale( smooth_long_avg[k][b], smooth_short_avg[k][b], &q_div ) ) ); move32(); - IF (GT_16(q_div , norm_s(hStereoDft->smooth_fac_fx[k][b]))) + IF( GT_16( q_div, norm_s( hStereoDft->smooth_fac_fx[k][b] ) ) ) { hStereoDft->smooth_fac_fx[k][b] = MAX_16; move32(); } ELSE { - hStereoDft->smooth_fac_fx[k][b] = shl(hStereoDft->smooth_fac_fx[k][b], q_div); + hStereoDft->smooth_fac_fx[k][b] = shl( hStereoDft->smooth_fac_fx[k][b], q_div ); move32(); q_div = 0; move16(); @@ -449,15 +453,15 @@ static void map_params_dirac_to_stereo( } /* map factor to range [0;1] */ - hStereoDft->smooth_fac_fx[k][b] = s_max( 0, extract_l(L_shr(Mpy_32_16_1(SBA_DIRAC_NRG_SMOOTH_LONG_BY_LONG_SHORT_FX, sub(hStereoDft->smooth_fac_fx[k][b] , SBA_DIRAC_NRG_SMOOTH_SHORT_BY_LONG_FX)), Q15))); + hStereoDft->smooth_fac_fx[k][b] = s_max( 0, extract_l( L_shr( Mpy_32_16_1( SBA_DIRAC_NRG_SMOOTH_LONG_BY_LONG_SHORT_FX, sub( hStereoDft->smooth_fac_fx[k][b], SBA_DIRAC_NRG_SMOOTH_SHORT_BY_LONG_FX ) ), Q15 ) ) ); move16(); /* compress factor (higher compression in lowest bands) */ q_sqrt = 0; move16(); - IF ( LT_16(b, 2) ) + IF( LT_16( b, 2 ) ) { - Word16 tmp_val = Sqrt16( hStereoDft->smooth_fac_fx[k][b], &q_sqrt); - hStereoDft->smooth_fac_fx[k][b] = Sqrt16(tmp_val, &q_sqrt); + Word16 tmp_val = Sqrt16( hStereoDft->smooth_fac_fx[k][b], &q_sqrt ); + hStereoDft->smooth_fac_fx[k][b] = Sqrt16( tmp_val, &q_sqrt ); move16(); } ELSE @@ -465,7 +469,7 @@ static void map_params_dirac_to_stereo( hStereoDft->smooth_fac_fx[k][b] = Sqrt16( hStereoDft->smooth_fac_fx[k][b], &q_sqrt ); move16(); } - hStereoDft->smooth_fac_fx[k][b] = shl(hStereoDft->smooth_fac_fx[k][b], q_sqrt); + hStereoDft->smooth_fac_fx[k][b] = shl( hStereoDft->smooth_fac_fx[k][b], q_sqrt ); move16(); /* apply upper bounds depending on band */ @@ -477,27 +481,27 @@ static void map_params_dirac_to_stereo( pDFT += STEREO_DFT32MS_N_MAX; } - IF ( mcmasa ) + IF( mcmasa ) { Word16 q_div1; /* calculate block energies for side gain weighting (combine angles of 2 DirAC blocks to side gain for 1 DFT Stereo subframe; 4 blocks and 2 subframes overall) */ pSynth = synth; - block_len = idiv1616(L_frame , nBlocks); - FOR ( block = 0; block < nBlocks; block++ ) + block_len = idiv1616( L_frame, nBlocks ); + FOR( block = 0; block < nBlocks; block++ ) { block_nrg[block] = 0; move32(); - FOR ( i = 0; i < block_len; i++ ) + FOR( i = 0; i < block_len; i++ ) { - block_nrg[block] = Madd_32_32(block_nrg[block], pSynth[i] , pSynth[i]); + block_nrg[block] = Madd_32_32( block_nrg[block], pSynth[i], pSynth[i] ); move32(); } - q_nrg = sub(Q31, sub(shl(q_synth, 1) , Q31)); - block_nrg[block] = Sqrt32( block_nrg[block], &q_nrg); + q_nrg = sub( Q31, sub( shl( q_synth, 1 ), Q31 ) ); + block_nrg[block] = Sqrt32( block_nrg[block], &q_nrg ); move32(); - IF (NE_16(sub(Q31, q_nrg) , q_synth)) + IF( NE_16( sub( Q31, q_nrg ), q_synth ) ) { - block_nrg[block] = L_shl(block_nrg[block], sub(q_synth, sub(Q31, q_nrg))); + block_nrg[block] = L_shl( block_nrg[block], sub( q_synth, sub( Q31, q_nrg ) ) ); move32(); } pSynth += block_len; @@ -529,18 +533,18 @@ static void map_params_dirac_to_stereo( q_div2 = 0; } #else - nrg_norm1 = L_add(block_nrg[0] , L_add(block_nrg[1] , EPSILON_FIX)); - nrg_norm2 = L_add(block_nrg[2] , L_add(block_nrg[3] , EPSILON_FIX)); + nrg_norm1 = L_add( block_nrg[0], L_add( block_nrg[1], EPSILON_FIX ) ); + nrg_norm2 = L_add( block_nrg[2], L_add( block_nrg[3], EPSILON_FIX ) ); #endif /* extract DirAC parameters from metadata */ - FOR ( b = 0; b < nbands; b++ ) + FOR( b = 0; b < nbands; b++ ) { - diffuseness[b] = L_shl(L_sub(ONE_IN_Q30 , q_direction->band_data[b].energy_ratio_fx[0]), 1); + diffuseness[b] = L_shl( L_sub( ONE_IN_Q30, q_direction->band_data[b].energy_ratio_fx[0] ), 1 ); move32(); - IF ( hQMetaData->surcoh_band_data != NULL ) + IF( hQMetaData->surcoh_band_data != NULL ) { - surrCoh[b] = extract_h(imult3216((Word32)0x00808080, hQMetaData->surcoh_band_data[b].surround_coherence[0])); + surrCoh[b] = extract_h( imult3216( (Word32) 0x00808080, hQMetaData->surcoh_band_data[b].surround_coherence[0] ) ); move32(); } ELSE @@ -549,11 +553,11 @@ static void map_params_dirac_to_stereo( move32(); } - FOR ( block = 0; block < nBlocks; block++ ) + FOR( block = 0; block < nBlocks; block++ ) { Word16 block_metadata; - IF ( hQMetaData->useLowerRes ) + IF( hQMetaData->useLowerRes ) { block_metadata = 0; move16(); @@ -563,9 +567,9 @@ static void map_params_dirac_to_stereo( block_metadata = block; move16(); } - IF ( LT_32(q_direction->band_data[b].azimuth_fx[block_metadata], 0) ) + IF( LT_32( q_direction->band_data[b].azimuth_fx[block_metadata], 0 ) ) { - q_direction->band_data[b].azimuth_fx[block_metadata] = L_add((Word32)0x5A000000, q_direction->band_data[b].azimuth_fx[block_metadata]); + q_direction->band_data[b].azimuth_fx[block_metadata] = L_add( (Word32) 0x5A000000, q_direction->band_data[b].azimuth_fx[block_metadata] ); move16(); } /* @@ -573,20 +577,20 @@ static void map_params_dirac_to_stereo( * Before converting rounding is done. */ - azimuth[block][b] = extract_l(L_shr(L_add(q_direction->band_data[b].azimuth_fx[block_metadata], ONE_IN_Q21), Q22)); + azimuth[block][b] = extract_l( L_shr( L_add( q_direction->band_data[b].azimuth_fx[block_metadata], ONE_IN_Q21 ), Q22 ) ); move16(); - elevation[block][b] = extract_l(L_shr(L_add(q_direction->band_data[b].elevation_fx[block_metadata], ONE_IN_Q21), Q22)); + elevation[block][b] = extract_l( L_shr( L_add( q_direction->band_data[b].elevation_fx[block_metadata], ONE_IN_Q21 ), Q22 ) ); move16(); } } /* map angles (azi, ele), surround coherence, and diffuseness to DFT Stereo side and prediction gains */ - FOR ( b = 0; b < hStereoDft->nbands; b++ ) + FOR( b = 0; b < hStereoDft->nbands; b++ ) { /* combine angles of first 2 blocks to side gain of first subframe */ side_gain[b] = 0; move32(); - FOR ( block = 0; block < shr(nBlocks , 1); block++ ) + FOR( block = 0; block < shr( nBlocks, 1 ); block++ ) { #if 0 IF ( EQ_16(b_wide_panning, 1) ) @@ -602,29 +606,29 @@ static void map_params_dirac_to_stereo( } #else /* - * The floating point version of the code computes + * The floating point version of the code computes * nrg_norm1 = 1 / (block_nrg[0] + block_nrg[1]); and then computes * block_nrg[0] * nrg_norm1; which effectively is block_nrg[0] / (block_nrg[0] + block_nrg[1]); */ - IF ( EQ_16(b_wide_panning, 1) ) + IF( EQ_16( b_wide_panning, 1 ) ) { - Word32 temp = L_mult(BASOP_Util_Divide3232_Scale(block_nrg[block], nrg_norm1, &q_div1) , get_panning( azimuth[block][b], elevation[block][b])); - IF (NE_16(q_div1, 0)) + Word32 temp = L_mult( BASOP_Util_Divide3232_Scale( block_nrg[block], nrg_norm1, &q_div1 ), get_panning( azimuth[block][b], elevation[block][b] ) ); + IF( NE_16( q_div1, 0 ) ) { - temp = L_shl_sat(temp, q_div1); + temp = L_shl_sat( temp, q_div1 ); } /* panning between left and ride, saturate at the stereo ls positions (+/- 30deg azi) */ - side_gain[b] = L_add_sat(side_gain[b], temp); + side_gain[b] = L_add_sat( side_gain[b], temp ); move32(); } ELSE { - Word32 temp = L_mult(BASOP_Util_Divide3232_Scale(block_nrg[block], nrg_norm1, &q_div1) , mult(ptr_sin_az[azimuth[block][b]] , ptr_cos_el[elevation[block][b]])); - IF (NE_16(q_div1, 0)) + Word32 temp = L_mult( BASOP_Util_Divide3232_Scale( block_nrg[block], nrg_norm1, &q_div1 ), mult( ptr_sin_az[azimuth[block][b]], ptr_cos_el[elevation[block][b]] ) ); + IF( NE_16( q_div1, 0 ) ) { - temp = L_shl_sat(temp, q_div1); + temp = L_shl_sat( temp, q_div1 ); } - side_gain[b] = L_add_sat(side_gain[b], temp); + side_gain[b] = L_add_sat( side_gain[b], temp ); move32(); } #endif @@ -633,7 +637,7 @@ static void map_params_dirac_to_stereo( /* combine angles of last 2 blocks to side gain of second subframe */ side_gain[b + STEREO_DFT_BAND_MAX] = 0; move32(); - FOR ( block = shr(nBlocks , 1); block < nBlocks; block++ ) + FOR( block = shr( nBlocks, 1 ); block < nBlocks; block++ ) { #if 0 IF ( EQ_16(b_wide_panning, 1) ) @@ -648,47 +652,47 @@ static void map_params_dirac_to_stereo( move32(); } #else - IF ( EQ_16(b_wide_panning, 1) ) + IF( EQ_16( b_wide_panning, 1 ) ) { - Word32 temp = L_mult(BASOP_Util_Divide3232_Scale(block_nrg[block], nrg_norm2, &q_div1) , get_panning( azimuth[block][b], elevation[block][b])); - IF (NE_16(q_div1, 0)) + Word32 temp = L_mult( BASOP_Util_Divide3232_Scale( block_nrg[block], nrg_norm2, &q_div1 ), get_panning( azimuth[block][b], elevation[block][b] ) ); + IF( NE_16( q_div1, 0 ) ) { - temp = L_shl_sat(temp, q_div1); + temp = L_shl_sat( temp, q_div1 ); } /* panning between left and ride, saturate at the stereo ls positions (+/- 30deg azi) */ - side_gain[b + STEREO_DFT_BAND_MAX] = L_add_sat(side_gain[b + STEREO_DFT_BAND_MAX], temp); + side_gain[b + STEREO_DFT_BAND_MAX] = L_add_sat( side_gain[b + STEREO_DFT_BAND_MAX], temp ); move32(); } ELSE { - Word32 temp = L_mult(BASOP_Util_Divide3232_Scale(block_nrg[block], nrg_norm2, &q_div1) , mult(ptr_sin_az[azimuth[block][b]] , ptr_cos_el[elevation[block][b]])); - IF (NE_16(q_div1, 0)) + Word32 temp = L_mult( BASOP_Util_Divide3232_Scale( block_nrg[block], nrg_norm2, &q_div1 ), mult( ptr_sin_az[azimuth[block][b]], ptr_cos_el[elevation[block][b]] ) ); + IF( NE_16( q_div1, 0 ) ) { - temp = L_shl_sat(temp, q_div1); + temp = L_shl_sat( temp, q_div1 ); } - side_gain[b + STEREO_DFT_BAND_MAX] = L_add_sat(side_gain[b + STEREO_DFT_BAND_MAX], temp); + side_gain[b + STEREO_DFT_BAND_MAX] = L_add_sat( side_gain[b + STEREO_DFT_BAND_MAX], temp ); move32(); } #endif } q_sqrt = 0; - side_gain[b] = Mpy_32_32(side_gain[b], Sqrt32(L_sub(MAX_32, diffuseness[b]), &q_sqrt)); + side_gain[b] = Mpy_32_32( side_gain[b], Sqrt32( L_sub( MAX_32, diffuseness[b] ), &q_sqrt ) ); move32(); - IF (NE_16(q_sqrt, 0)) + IF( NE_16( q_sqrt, 0 ) ) { - side_gain[b] = L_shl(side_gain[b], q_sqrt); + side_gain[b] = L_shl( side_gain[b], q_sqrt ); q_sqrt = 0; } - side_gain[b + STEREO_DFT_BAND_MAX] = Mpy_32_32(side_gain[b + STEREO_DFT_BAND_MAX], Sqrt32(L_sub(MAX_32, diffuseness[b]), &q_sqrt)); + side_gain[b + STEREO_DFT_BAND_MAX] = Mpy_32_32( side_gain[b + STEREO_DFT_BAND_MAX], Sqrt32( L_sub( MAX_32, diffuseness[b] ), &q_sqrt ) ); move32(); - IF (NE_16(q_sqrt, 0)) + IF( NE_16( q_sqrt, 0 ) ) { - side_gain[b + STEREO_DFT_BAND_MAX] = L_shl(side_gain[b], q_sqrt); + side_gain[b + STEREO_DFT_BAND_MAX] = L_shl( side_gain[b], q_sqrt ); q_sqrt = 0; } - res_pred_gain[b] = Mpy_32_16_1(diffuseness[b], sub(MAX_16, surrCoh[b] )); + res_pred_gain[b] = Mpy_32_16_1( diffuseness[b], sub( MAX_16, surrCoh[b] ) ); move32(); - res_pred_gain[b + STEREO_DFT_BAND_MAX] = Mpy_32_16_1(diffuseness[b], sub(MAX_16, surrCoh[b]) ); + res_pred_gain[b + STEREO_DFT_BAND_MAX] = Mpy_32_16_1( diffuseness[b], sub( MAX_16, surrCoh[b] ) ); move32(); } } @@ -712,70 +716,70 @@ static void map_params_dirac_to_stereo( static void ivas_sba_dirac_stereo_compute_td_stefi_nrgs( STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ - const Word32 hb_synth[L_FRAME48k], /* i : HB signal */ - const Word16 core, /* i : core decision */ - const Word16 output_frame, /* i : output frame length per channel */ + const Word32 hb_synth[L_FRAME48k], /* i : HB signal */ + const Word16 core, /* i : core decision */ + const Word16 output_frame, /* i : output frame length per channel */ const Word16 fd_cng_flag, /* i : FD-CNG indicator */ - const Word16 q_hb_synth -) + const Word16 q_hb_synth ) { Word16 i; - Word32 hb_nrg = EPSILON_FIX; move32(); - Word32 hb_nrg2 = EPSILON_FIX; move32(); + Word32 hb_nrg = EPSILON_FIX; + move32(); + Word32 hb_nrg2 = EPSILON_FIX; + move32(); - IF ( ( EQ_16(core, ACELP_CORE) && EQ_16(fd_cng_flag, 0) ) || EQ_16(hStereoDft->core_hist[1], ACELP_CORE) ) + IF( ( EQ_16( core, ACELP_CORE ) && EQ_16( fd_cng_flag, 0 ) ) || EQ_16( hStereoDft->core_hist[1], ACELP_CORE ) ) { - FOR ( i = 0; i < shr(output_frame, 2); i++ ) + FOR( i = 0; i < shr( output_frame, 2 ); i++ ) { - hb_nrg2 = Madd_32_32(hb_nrg2, hb_synth[i], hb_synth[i]); + hb_nrg2 = Madd_32_32( hb_nrg2, hb_synth[i], hb_synth[i] ); } hStereoDft->hb_nrg_subr_fx[0] = hb_nrg2; - hStereoDft->q_hb_nrg_subr = sub(shl(q_hb_synth, 1), 31); + hStereoDft->q_hb_nrg_subr = sub( shl( q_hb_synth, 1 ), 31 ); move32(); - hb_nrg = L_add(hb_nrg, hb_nrg2); + hb_nrg = L_add( hb_nrg, hb_nrg2 ); hb_nrg2 = EPSILON_FIX; move32(); - FOR ( ; i < output_frame; i++ ) + FOR( ; i < output_frame; i++ ) { - hb_nrg2 = Madd_32_32(hb_nrg2, hb_synth[i], hb_synth[i]); + hb_nrg2 = Madd_32_32( hb_nrg2, hb_synth[i], hb_synth[i] ); } hStereoDft->hb_nrg_subr_fx[1] = hb_nrg2; move32(); - hb_nrg = L_add(hb_nrg, hb_nrg2); + hb_nrg = L_add( hb_nrg, hb_nrg2 ); - IF (EQ_16(hStereoDft->q_hb_stefi_sig_fx, q_hb_synth)) + IF( EQ_16( hStereoDft->q_hb_stefi_sig_fx, q_hb_synth ) ) { Copy32( hb_synth, hStereoDft->hb_stefi_sig_fx + hStereoDft->hb_stefi_delay, output_frame ); } ELSE { - IF (GT_16(hStereoDft->q_hb_stefi_sig_fx, q_hb_synth)) + IF( GT_16( hStereoDft->q_hb_stefi_sig_fx, q_hb_synth ) ) { - v_shr(hStereoDft->hb_stefi_sig_fx, sub(hStereoDft->q_hb_stefi_sig_fx, q_hb_synth), hStereoDft->hb_stefi_sig_fx, sizeof(hStereoDft->hb_stefi_sig_fx) / sizeof(hStereoDft->hb_stefi_sig_fx[0])); + v_shr( hStereoDft->hb_stefi_sig_fx, sub( hStereoDft->q_hb_stefi_sig_fx, q_hb_synth ), hStereoDft->hb_stefi_sig_fx, sizeof( hStereoDft->hb_stefi_sig_fx ) / sizeof( hStereoDft->hb_stefi_sig_fx[0] ) ); hStereoDft->q_hb_stefi_sig_fx = q_hb_synth; Copy32( hb_synth, hStereoDft->hb_stefi_sig_fx + hStereoDft->hb_stefi_delay, output_frame ); } ELSE { - v_shr(hb_synth, sub(q_hb_synth, hStereoDft->q_hb_stefi_sig_fx), hStereoDft->hb_stefi_sig_fx + hStereoDft->hb_stefi_delay, output_frame); + v_shr( hb_synth, sub( q_hb_synth, hStereoDft->q_hb_stefi_sig_fx ), hStereoDft->hb_stefi_sig_fx + hStereoDft->hb_stefi_delay, output_frame ); } - } } ELSE { - set_val_Word32( hStereoDft->hb_stefi_sig_fx + hStereoDft->hb_stefi_delay, 0, output_frame); + set_val_Word32( hStereoDft->hb_stefi_sig_fx + hStereoDft->hb_stefi_delay, 0, output_frame ); #ifdef MSAN_FIX hStereoDft->hb_nrg_subr_fx[0] = 0; hStereoDft->hb_nrg_subr_fx[1] = 0; #endif // MSAN_FIX } - hStereoDft->hb_nrg_subr_fx[0] = hStereoDft->hb_nrg_subr_fx[0]; //imult3216(hStereoDft->hb_nrg_subr_fx[0] , shr(hStereoDft->NFFT, 1)); + hStereoDft->hb_nrg_subr_fx[0] = hStereoDft->hb_nrg_subr_fx[0]; // imult3216(hStereoDft->hb_nrg_subr_fx[0] , shr(hStereoDft->NFFT, 1)); move32(); - hStereoDft->hb_nrg_subr_fx[1] = hStereoDft->hb_nrg_subr_fx[1]; //imult3216(hStereoDft->hb_nrg_subr_fx[1] , shr(hStereoDft->NFFT, 1)); + hStereoDft->hb_nrg_subr_fx[1] = hStereoDft->hb_nrg_subr_fx[1]; // imult3216(hStereoDft->hb_nrg_subr_fx[1] , shr(hStereoDft->NFFT, 1)); move32(); hStereoDft->hb_nrg_fx[0] = hb_nrg; move32(); @@ -795,7 +799,7 @@ static void ivas_sba_dirac_stereo_compute_td_stefi_nrgs( static void ivas_sba_dirac_stereo_compute_hb_gain( STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ - Word32 hb_gain[NB_DIV] /* o : side gains for HB signal */ + Word32 hb_gain[NB_DIV] /* o : side gains for HB signal */ ) { Word16 k_offset; @@ -823,127 +827,127 @@ static void ivas_sba_dirac_stereo_upmix_hb( Word32 hb_stereo_synth[CPE_CHANNELS][L_FRAME48k], /* i/o: stereo HB synthesis signal */ Word32 hb_synth[L_FRAME48k], /* i : HB signal */ Word32 hb_gain[NB_DIV], /* i : side gains for HB signal */ - const Word16 output_frame, /* i : output frame length per channel */ - const Word16 mcmasa, /* i : McMASA flag */ - const Word16 sba_mono_flag, /* i : flag for mono output */ - const Word16 bwidth, /* i : bandwidth of signal */ - const STEREO_DFT_DEC_DATA_HANDLE hStereoDft /* i : Stereo DFT handle for mixing matrix */ + const Word16 output_frame, /* i : output frame length per channel */ + const Word16 mcmasa, /* i : McMASA flag */ + const Word16 sba_mono_flag, /* i : flag for mono output */ + const Word16 bwidth, /* i : bandwidth of signal */ + const STEREO_DFT_DEC_DATA_HANDLE hStereoDft /* i : Stereo DFT handle for mixing matrix */ ) { Word16 i; Word32 gp, gm; Word16 gain_fac; - IF ( EQ_16(mcmasa, 0) ) + IF( EQ_16( mcmasa, 0 ) ) { - gain_fac = ( bwidth == FB ) ? (Word32)0x2000 : (Word32)0x2A3D; /* last matrix element not used for SWB, divide by 3 instead of 4*/ + gain_fac = ( bwidth == FB ) ? (Word32) 0x2000 : (Word32) 0x2A3D; /* last matrix element not used for SWB, divide by 3 instead of 4*/ move16(); - IF ( sba_mono_flag ) + IF( sba_mono_flag ) { - gp = L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][0][8], gain_fac), - Madd_32_16(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][0][9], gain_fac), - hStereoDft->mixer_mat_smooth_fx[0][0][10], gain_fac)); - IF ( EQ_16(bwidth, FB) ) + gp = L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][0][8], gain_fac ), + Madd_32_16( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][0][9], gain_fac ), + hStereoDft->mixer_mat_smooth_fx[0][0][10], gain_fac ) ); + IF( EQ_16( bwidth, FB ) ) { - gp = Madd_32_16(gp, hStereoDft->mixer_mat_smooth_fx[0][0][11], gain_fac); + gp = Madd_32_16( gp, hStereoDft->mixer_mat_smooth_fx[0][0][11], gain_fac ); } - FOR ( i = 0; i < shr(output_frame, 1); i++ ) + FOR( i = 0; i < shr( output_frame, 1 ); i++ ) { - hb_stereo_synth[0][i] = Mpy_32_32(hb_synth[i] , gp); + hb_stereo_synth[0][i] = Mpy_32_32( hb_synth[i], gp ); move32(); } - gp = L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][0][8 + IVAS_MAX_NUM_BANDS], gain_fac), - Madd_32_16(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][0][9 + IVAS_MAX_NUM_BANDS], gain_fac), - hStereoDft->mixer_mat_smooth_fx[0][0][10 + IVAS_MAX_NUM_BANDS], gain_fac)); - IF ( EQ_16(bwidth, FB) ) + gp = L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][0][8 + IVAS_MAX_NUM_BANDS], gain_fac ), + Madd_32_16( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][0][9 + IVAS_MAX_NUM_BANDS], gain_fac ), + hStereoDft->mixer_mat_smooth_fx[0][0][10 + IVAS_MAX_NUM_BANDS], gain_fac ) ); + IF( EQ_16( bwidth, FB ) ) { - gp = Madd_32_16(gp, hStereoDft->mixer_mat_smooth_fx[0][0][11 + IVAS_MAX_NUM_BANDS], gain_fac); + gp = Madd_32_16( gp, hStereoDft->mixer_mat_smooth_fx[0][0][11 + IVAS_MAX_NUM_BANDS], gain_fac ); } - FOR ( i = shr(output_frame , 1); i < output_frame; i++ ) + FOR( i = shr( output_frame, 1 ); i < output_frame; i++ ) { - hb_stereo_synth[0][i] = Mpy_32_32(hb_synth[i], gp); + hb_stereo_synth[0][i] = Mpy_32_32( hb_synth[i], gp ); move32(); } } ELSE { /* Accounting for the 0.5 multiplication */ - gain_fac = shr(gain_fac, 1); - gp = L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][0][8], gain_fac) , - L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[1][0][8], gain_fac) , - L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][0][9], gain_fac) , - L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[1][0][9], gain_fac) , - L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][0][10], gain_fac) , - Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[1][0][10], gain_fac)))))); - IF ( EQ_32(bwidth , FB) ) + gain_fac = shr( gain_fac, 1 ); + gp = L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][0][8], gain_fac ), + L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[1][0][8], gain_fac ), + L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][0][9], gain_fac ), + L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[1][0][9], gain_fac ), + L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][0][10], gain_fac ), + Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[1][0][10], gain_fac ) ) ) ) ) ); + IF( EQ_32( bwidth, FB ) ) { - gp = L_add(gp, Madd_32_16(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][0][11] , gain_fac), - hStereoDft->mixer_mat_smooth_fx[1][0][11], gain_fac)); + gp = L_add( gp, Madd_32_16( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][0][11], gain_fac ), + hStereoDft->mixer_mat_smooth_fx[1][0][11], gain_fac ) ); } - gm = L_add(Msub_32_16(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][0][8], gain_fac) , - hStereoDft->mixer_mat_smooth_fx[1][0][8], gain_fac) , - L_add(Msub_32_16(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][0][9], gain_fac) , - hStereoDft->mixer_mat_smooth_fx[1][0][9], gain_fac) , - Msub_32_16(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][0][10], gain_fac) , - hStereoDft->mixer_mat_smooth_fx[1][0][10], gain_fac))); - IF ( EQ_32(bwidth , FB) ) + gm = L_add( Msub_32_16( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][0][8], gain_fac ), + hStereoDft->mixer_mat_smooth_fx[1][0][8], gain_fac ), + L_add( Msub_32_16( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][0][9], gain_fac ), + hStereoDft->mixer_mat_smooth_fx[1][0][9], gain_fac ), + Msub_32_16( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][0][10], gain_fac ), + hStereoDft->mixer_mat_smooth_fx[1][0][10], gain_fac ) ) ); + IF( EQ_32( bwidth, FB ) ) { - gm = L_add(gm, Msub_32_16(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][0][11], gain_fac) , - hStereoDft->mixer_mat_smooth_fx[1][0][11], gain_fac)); + gm = L_add( gm, Msub_32_16( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][0][11], gain_fac ), + hStereoDft->mixer_mat_smooth_fx[1][0][11], gain_fac ) ); } - FOR ( i = 0; i < shr(output_frame , 1); i++ ) + FOR( i = 0; i < shr( output_frame, 1 ); i++ ) { - hb_stereo_synth[0][i] = Mpy_32_32(hb_synth[i] , gp); + hb_stereo_synth[0][i] = Mpy_32_32( hb_synth[i], gp ); move32(); - hb_stereo_synth[1][i] = Mpy_32_32(hb_synth[i] , gm); + hb_stereo_synth[1][i] = Mpy_32_32( hb_synth[i], gm ); move32(); } - gp = L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][0][8 + IVAS_MAX_NUM_BANDS], gain_fac), - L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[1][0][8 + IVAS_MAX_NUM_BANDS], gain_fac), - L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][0][9 + IVAS_MAX_NUM_BANDS], gain_fac), - L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[1][0][9 + IVAS_MAX_NUM_BANDS], gain_fac), - Madd_32_16(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][0][10 + IVAS_MAX_NUM_BANDS], gain_fac), - hStereoDft->mixer_mat_smooth_fx[1][0][10 + IVAS_MAX_NUM_BANDS], gain_fac))))); - IF ( EQ_32(bwidth , FB) ) + gp = L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][0][8 + IVAS_MAX_NUM_BANDS], gain_fac ), + L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[1][0][8 + IVAS_MAX_NUM_BANDS], gain_fac ), + L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][0][9 + IVAS_MAX_NUM_BANDS], gain_fac ), + L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[1][0][9 + IVAS_MAX_NUM_BANDS], gain_fac ), + Madd_32_16( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][0][10 + IVAS_MAX_NUM_BANDS], gain_fac ), + hStereoDft->mixer_mat_smooth_fx[1][0][10 + IVAS_MAX_NUM_BANDS], gain_fac ) ) ) ) ); + IF( EQ_32( bwidth, FB ) ) { - gp = L_add(gp, Madd_32_16(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][0][11 + IVAS_MAX_NUM_BANDS], gain_fac) , hStereoDft->mixer_mat_smooth_fx[1][0][11 + IVAS_MAX_NUM_BANDS], gain_fac)); + gp = L_add( gp, Madd_32_16( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][0][11 + IVAS_MAX_NUM_BANDS], gain_fac ), hStereoDft->mixer_mat_smooth_fx[1][0][11 + IVAS_MAX_NUM_BANDS], gain_fac ) ); } - gm = L_add(Msub_32_16(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][0][8 + IVAS_MAX_NUM_BANDS], gain_fac) , hStereoDft->mixer_mat_smooth_fx[1][0][8 + IVAS_MAX_NUM_BANDS], gain_fac), - L_add(Msub_32_16(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][0][9 + IVAS_MAX_NUM_BANDS], gain_fac) , hStereoDft->mixer_mat_smooth_fx[1][0][9 + IVAS_MAX_NUM_BANDS], gain_fac), - Msub_32_16(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][0][10 + IVAS_MAX_NUM_BANDS], gain_fac) , hStereoDft->mixer_mat_smooth_fx[1][0][10 + IVAS_MAX_NUM_BANDS], gain_fac))); - IF ( EQ_32(bwidth , FB) ) + gm = L_add( Msub_32_16( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][0][8 + IVAS_MAX_NUM_BANDS], gain_fac ), hStereoDft->mixer_mat_smooth_fx[1][0][8 + IVAS_MAX_NUM_BANDS], gain_fac ), + L_add( Msub_32_16( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][0][9 + IVAS_MAX_NUM_BANDS], gain_fac ), hStereoDft->mixer_mat_smooth_fx[1][0][9 + IVAS_MAX_NUM_BANDS], gain_fac ), + Msub_32_16( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][0][10 + IVAS_MAX_NUM_BANDS], gain_fac ), hStereoDft->mixer_mat_smooth_fx[1][0][10 + IVAS_MAX_NUM_BANDS], gain_fac ) ) ); + IF( EQ_32( bwidth, FB ) ) { - gm = L_add(gm, Msub_32_16(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][0][11 + IVAS_MAX_NUM_BANDS], gain_fac) , hStereoDft->mixer_mat_smooth_fx[1][0][11 + IVAS_MAX_NUM_BANDS], gain_fac)); + gm = L_add( gm, Msub_32_16( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][0][11 + IVAS_MAX_NUM_BANDS], gain_fac ), hStereoDft->mixer_mat_smooth_fx[1][0][11 + IVAS_MAX_NUM_BANDS], gain_fac ) ); } - FOR ( i = shr(output_frame , 1); i < output_frame; i++ ) + FOR( i = shr( output_frame, 1 ); i < output_frame; i++ ) { - hb_stereo_synth[0][i] = Mpy_32_32(hb_synth[i] , gp); + hb_stereo_synth[0][i] = Mpy_32_32( hb_synth[i], gp ); move32(); - hb_stereo_synth[1][i] = Mpy_32_32(hb_synth[i] , gm); + hb_stereo_synth[1][i] = Mpy_32_32( hb_synth[i], gm ); move32(); } } } ELSE { - FOR ( i = 0; i < L_shr(output_frame , 1); i++ ) + FOR( i = 0; i < L_shr( output_frame, 1 ); i++ ) { - hb_stereo_synth[0][i] = L_add(L_shr(hb_synth[i], 1) , L_shr(Mpy_32_32(hb_gain[0] , hb_synth[i]), 1)); + hb_stereo_synth[0][i] = L_add( L_shr( hb_synth[i], 1 ), L_shr( Mpy_32_32( hb_gain[0], hb_synth[i] ), 1 ) ); move32(); - hb_stereo_synth[1][i] = L_sub(L_shr(hb_synth[i], 1) , L_shr(Mpy_32_32(hb_gain[0] , hb_synth[i]), 1)); + hb_stereo_synth[1][i] = L_sub( L_shr( hb_synth[i], 1 ), L_shr( Mpy_32_32( hb_gain[0], hb_synth[i] ), 1 ) ); move32(); } - FOR ( i = shr(output_frame, 1); i < output_frame; i++ ) + FOR( i = shr( output_frame, 1 ); i < output_frame; i++ ) { - hb_stereo_synth[0][i] = L_add(L_shr(hb_synth[i], 1) , L_shr(Mpy_32_32(hb_gain[1] , hb_synth[i]), 1)); + hb_stereo_synth[0][i] = L_add( L_shr( hb_synth[i], 1 ), L_shr( Mpy_32_32( hb_gain[1], hb_synth[i] ), 1 ) ); move32(); - hb_stereo_synth[1][i] = L_sub(L_shr(hb_synth[i], 1) , L_shr(Mpy_32_32(hb_gain[1] , hb_synth[i]), 1)); + hb_stereo_synth[1][i] = L_sub( L_shr( hb_synth[i], 1 ), L_shr( Mpy_32_32( hb_gain[1], hb_synth[i] ), 1 ) ); move32(); } } @@ -960,9 +964,9 @@ static void ivas_sba_dirac_stereo_upmix_hb( static void ivas_sba_dirac_stereo_apply_td_stefi( STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ - Word32 *output[CPE_CHANNELS], /* i/o: output synthesis signal */ - const Word16 output_frame, /* i : output frame length per channel */ - const Word16 spar_flag /* i : SPAR flag */ + Word32 *output[CPE_CHANNELS], /* i/o: output synthesis signal */ + const Word16 output_frame, /* i : output frame length per channel */ + const Word16 spar_flag /* i : SPAR flag */ ) { Word16 i; @@ -971,7 +975,7 @@ static void ivas_sba_dirac_stereo_apply_td_stefi( Word32 tmp; const Word16 *win_dft; - IF ( spar_flag ) + IF( spar_flag ) { win_dft = hStereoDft->win32ms_fx; dftOvlLen = hStereoDft->dft32ms_ovl; @@ -981,74 +985,70 @@ static void ivas_sba_dirac_stereo_apply_td_stefi( Word32 g_L, g_R; Word32 stefi_L, stefi_R; - g_W_1 = L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][1][8], 0x147B), - L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][2][8], 0x147B) , - L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][3][8], 0x147B) , - L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][1][9], 0x147B) , - L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][2][9], 0x147B), - L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][3][9], 0x147B), - L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][1][10], 0x147B), - L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][2][10], 0x147B), - Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][3][10], 0x147B)) - ))))))); - - g_Y_1 = L_add( Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[1][1][8], 0x147B), - L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[1][2][8], 0x147B), - L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[1][3][8], 0x147B), - L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[1][1][9], 0x147B), - L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[1][2][9], 0x147B), - L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[1][3][9], 0x147B), - L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[1][1][10], 0x147B), - L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[1][2][10], 0x147B), - Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[1][3][10], 0x147B)) - ))))))); - - g_W_2 = L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][1][8 + IVAS_MAX_NUM_BANDS], 0x147B), - L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][2][8 + IVAS_MAX_NUM_BANDS], 0x147B), - L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][3][8 + IVAS_MAX_NUM_BANDS], 0x147B), - L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][1][9 + IVAS_MAX_NUM_BANDS], 0x147B), - L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][2][9 + IVAS_MAX_NUM_BANDS], 0x147B), - L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][3][9 + IVAS_MAX_NUM_BANDS], 0x147B), - L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][1][10 + IVAS_MAX_NUM_BANDS], 0x147B), - L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][2][10 + IVAS_MAX_NUM_BANDS], 0x147B), - Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][3][10 + IVAS_MAX_NUM_BANDS], 0x147B)) - ))))))); - - g_Y_2 = L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[1][1][8 + IVAS_MAX_NUM_BANDS], 0x147B), - L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[1][2][8 + IVAS_MAX_NUM_BANDS], 0x147B), - L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[1][3][8 + IVAS_MAX_NUM_BANDS], 0x147B), - L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[1][1][9 + IVAS_MAX_NUM_BANDS], 0x147B), - L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[1][2][9 + IVAS_MAX_NUM_BANDS], 0x147B), - L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[1][3][9 + IVAS_MAX_NUM_BANDS], 0x147B), - L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[1][1][10 + IVAS_MAX_NUM_BANDS], 0x147B), - L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[1][2][10 + IVAS_MAX_NUM_BANDS], 0x147B), - Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[1][3][10 + IVAS_MAX_NUM_BANDS], 0x147B)) - ))))))); - - g_L = L_sub( L_add(g_W_1 , g_W_2) , L_add(g_Y_1 , g_Y_2) ); /* 0x147B = 0.16 in Q15 */ - g_R = L_add( L_add(g_W_1 , g_W_2) , L_add(g_Y_1 , g_Y_2) ); /* 0x147B = 0.16 in Q15 */ - FOR ( i = 0; i < dftOvlLen; i++ ) + g_W_1 = L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][1][8], 0x147B ), + L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][2][8], 0x147B ), + L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][3][8], 0x147B ), + L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][1][9], 0x147B ), + L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][2][9], 0x147B ), + L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][3][9], 0x147B ), + L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][1][10], 0x147B ), + L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][2][10], 0x147B ), + Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][3][10], 0x147B ) ) ) ) ) ) ) ) ); + + g_Y_1 = L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[1][1][8], 0x147B ), + L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[1][2][8], 0x147B ), + L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[1][3][8], 0x147B ), + L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[1][1][9], 0x147B ), + L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[1][2][9], 0x147B ), + L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[1][3][9], 0x147B ), + L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[1][1][10], 0x147B ), + L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[1][2][10], 0x147B ), + Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[1][3][10], 0x147B ) ) ) ) ) ) ) ) ); + + g_W_2 = L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][1][8 + IVAS_MAX_NUM_BANDS], 0x147B ), + L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][2][8 + IVAS_MAX_NUM_BANDS], 0x147B ), + L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][3][8 + IVAS_MAX_NUM_BANDS], 0x147B ), + L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][1][9 + IVAS_MAX_NUM_BANDS], 0x147B ), + L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][2][9 + IVAS_MAX_NUM_BANDS], 0x147B ), + L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][3][9 + IVAS_MAX_NUM_BANDS], 0x147B ), + L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][1][10 + IVAS_MAX_NUM_BANDS], 0x147B ), + L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][2][10 + IVAS_MAX_NUM_BANDS], 0x147B ), + Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][3][10 + IVAS_MAX_NUM_BANDS], 0x147B ) ) ) ) ) ) ) ) ); + + g_Y_2 = L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[1][1][8 + IVAS_MAX_NUM_BANDS], 0x147B ), + L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[1][2][8 + IVAS_MAX_NUM_BANDS], 0x147B ), + L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[1][3][8 + IVAS_MAX_NUM_BANDS], 0x147B ), + L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[1][1][9 + IVAS_MAX_NUM_BANDS], 0x147B ), + L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[1][2][9 + IVAS_MAX_NUM_BANDS], 0x147B ), + L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[1][3][9 + IVAS_MAX_NUM_BANDS], 0x147B ), + L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[1][1][10 + IVAS_MAX_NUM_BANDS], 0x147B ), + L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[1][2][10 + IVAS_MAX_NUM_BANDS], 0x147B ), + Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[1][3][10 + IVAS_MAX_NUM_BANDS], 0x147B ) ) ) ) ) ) ) ) ); + + g_L = L_sub( L_add( g_W_1, g_W_2 ), L_add( g_Y_1, g_Y_2 ) ); /* 0x147B = 0.16 in Q15 */ + g_R = L_add( L_add( g_W_1, g_W_2 ), L_add( g_Y_1, g_Y_2 ) ); /* 0x147B = 0.16 in Q15 */ + FOR( i = 0; i < dftOvlLen; i++ ) { - win_in = mult_r(win_dft[STEREO_DFT32MS_STEP * i], win_dft[STEREO_DFT32MS_STEP * i]); - win_out = sub(MAX_16, win_in); + win_in = mult_r( win_dft[STEREO_DFT32MS_STEP * i], win_dft[STEREO_DFT32MS_STEP * i] ); + win_out = sub( MAX_16, win_in ); - stefi_L = L_shr(Mpy_32_32( Madd_32_16(Mpy_32_32(win_out , hStereoDft->g_L_prev_fx) , g_L , win_in ) , hStereoDft->hb_stefi_sig_fx[i]), 1); - stefi_R = L_shr(Mpy_32_32( Madd_32_16(Mpy_32_32(win_out , hStereoDft->g_R_prev_fx) , g_R , win_in ) , hStereoDft->hb_stefi_sig_fx[i]), 1); + stefi_L = L_shr( Mpy_32_32( Madd_32_16( Mpy_32_32( win_out, hStereoDft->g_L_prev_fx ), g_L, win_in ), hStereoDft->hb_stefi_sig_fx[i] ), 1 ); + stefi_R = L_shr( Mpy_32_32( Madd_32_16( Mpy_32_32( win_out, hStereoDft->g_R_prev_fx ), g_R, win_in ), hStereoDft->hb_stefi_sig_fx[i] ), 1 ); - output[0][i] = L_add(output[0][i], L_shr(stefi_L, sub(hStereoDft->q_hb_stefi_sig_fx, hStereoDft->q_dft))); + output[0][i] = L_add( output[0][i], L_shr( stefi_L, sub( hStereoDft->q_hb_stefi_sig_fx, hStereoDft->q_dft ) ) ); move32(); - output[1][i] = L_add(output[1][i], L_shr(stefi_R, sub(hStereoDft->q_hb_stefi_sig_fx, hStereoDft->q_dft))); + output[1][i] = L_add( output[1][i], L_shr( stefi_R, sub( hStereoDft->q_hb_stefi_sig_fx, hStereoDft->q_dft ) ) ); move32(); } - FOR ( i = dftOvlLen; i < output_frame; i++ ) + FOR( i = dftOvlLen; i < output_frame; i++ ) { - stefi_L = L_shr(Mpy_32_32(g_L , hStereoDft->hb_stefi_sig_fx[i]), 1); - stefi_R = L_shr(Mpy_32_32(g_R , hStereoDft->hb_stefi_sig_fx[i]), 1); + stefi_L = L_shr( Mpy_32_32( g_L, hStereoDft->hb_stefi_sig_fx[i] ), 1 ); + stefi_R = L_shr( Mpy_32_32( g_R, hStereoDft->hb_stefi_sig_fx[i] ), 1 ); - output[0][i] = L_add(output[0][i], L_shr(stefi_L, sub(hStereoDft->q_hb_stefi_sig_fx, hStereoDft->q_dft))); + output[0][i] = L_add( output[0][i], L_shr( stefi_L, sub( hStereoDft->q_hb_stefi_sig_fx, hStereoDft->q_dft ) ) ); move32(); - output[1][i] = L_add(output[1][i], L_shr(stefi_R, sub(hStereoDft->q_hb_stefi_sig_fx, hStereoDft->q_dft))); + output[1][i] = L_add( output[1][i], L_shr( stefi_R, sub( hStereoDft->q_hb_stefi_sig_fx, hStereoDft->q_dft ) ) ); move32(); } hStereoDft->g_L_prev_fx = g_L; @@ -1056,28 +1056,28 @@ static void ivas_sba_dirac_stereo_apply_td_stefi( hStereoDft->g_R_prev_fx = g_R; move32(); } - ELSE IF ( L_max( hStereoDft->td_gain_fx[0], hStereoDft->td_gain_fx[1] ) > 0 ) + ELSE IF( L_max( hStereoDft->td_gain_fx[0], hStereoDft->td_gain_fx[1] ) > 0 ) { win_dft = hStereoDft->win32ms_fx; dftOvlLen = hStereoDft->dft32ms_ovl; - FOR ( i = 0; i < dftOvlLen; i++ ) + FOR( i = 0; i < dftOvlLen; i++ ) { - win_in = mult(win_dft[STEREO_DFT32MS_STEP * i] , win_dft[STEREO_DFT32MS_STEP * i]); - win_out = sub(MAX_16 , win_in); - tmp = L_shr(Mpy_32_32(Madd_32_16(Mpy_32_16_1(hStereoDft->td_gain_fx[0], win_in) , hStereoDft->td_gain_fx[1] , win_out) , hStereoDft->hb_stefi_sig_fx[i]), 1); + win_in = mult( win_dft[STEREO_DFT32MS_STEP * i], win_dft[STEREO_DFT32MS_STEP * i] ); + win_out = sub( MAX_16, win_in ); + tmp = L_shr( Mpy_32_32( Madd_32_16( Mpy_32_16_1( hStereoDft->td_gain_fx[0], win_in ), hStereoDft->td_gain_fx[1], win_out ), hStereoDft->hb_stefi_sig_fx[i] ), 1 ); - output[0][i] = L_add(output[0][i], L_shr(tmp, sub(hStereoDft->q_hb_stefi_sig_fx, hStereoDft->q_dft))); + output[0][i] = L_add( output[0][i], L_shr( tmp, sub( hStereoDft->q_hb_stefi_sig_fx, hStereoDft->q_dft ) ) ); move32(); - output[1][i] = L_sub(output[1][i], L_shr(tmp, sub(hStereoDft->q_hb_stefi_sig_fx, hStereoDft->q_dft))); + output[1][i] = L_sub( output[1][i], L_shr( tmp, sub( hStereoDft->q_hb_stefi_sig_fx, hStereoDft->q_dft ) ) ); move32(); } - FOR ( i = dftOvlLen; i < output_frame; i++ ) + FOR( i = dftOvlLen; i < output_frame; i++ ) { - tmp = L_shr(Mpy_32_32(hStereoDft->hb_stefi_sig_fx[i], hStereoDft->td_gain_fx[0]), 1); - output[0][i] = L_add(output[0][i], L_shr(tmp, sub(hStereoDft->q_hb_stefi_sig_fx, hStereoDft->q_dft))); + tmp = L_shr( Mpy_32_32( hStereoDft->hb_stefi_sig_fx[i], hStereoDft->td_gain_fx[0] ), 1 ); + output[0][i] = L_add( output[0][i], L_shr( tmp, sub( hStereoDft->q_hb_stefi_sig_fx, hStereoDft->q_dft ) ) ); move32(); - output[1][i] = L_sub(output[1][i], L_shr(tmp, sub(hStereoDft->q_hb_stefi_sig_fx, hStereoDft->q_dft))); + output[1][i] = L_sub( output[1][i], L_shr( tmp, sub( hStereoDft->q_hb_stefi_sig_fx, hStereoDft->q_dft ) ) ); move32(); } } @@ -1095,9 +1095,9 @@ static void ivas_sba_dirac_stereo_apply_td_stefi( void ivas_sba_dirac_stereo_smooth_parameters_fx( STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD handle for upmixing */ - const Word16 cross_fade_start_offset, /* i : SPAR mixer delay compensation */ - const Word32 output_Fs, /* i : Fs for delay calculation */ - const Word16 num_md_sub_frames /* i : number of subframes in mixing matrix */ + const Word16 cross_fade_start_offset, /* i : SPAR mixer delay compensation */ + const Word32 output_Fs, /* i : Fs for delay calculation */ + const Word16 num_md_sub_frames /* i : number of subframes in mixing matrix */ ) { Word16 i, j, k, i_sf; @@ -1113,73 +1113,73 @@ void ivas_sba_dirac_stereo_smooth_parameters_fx( prev_res_pred_gain = hStereoDft->res_pred_gain_fx; res_pred_gain = hStereoDft->res_pred_gain_fx + k_offset * STEREO_DFT_BAND_MAX; - IF ( !hMdDec ) + IF( !hMdDec ) { /* Smoothing of side and prediction gains between ftrames */ - FOR ( b = hStereoDft->res_pred_band_min; b < hStereoDft->nbands; b++ ) + FOR( b = hStereoDft->res_pred_band_min; b < hStereoDft->nbands; b++ ) { - IF ( hStereoDft->attackPresent ) + IF( hStereoDft->attackPresent ) { - res_pred_gain[b] = Mpy_32_16_1(res_pred_gain[b], (Word16)0x6666); + res_pred_gain[b] = Mpy_32_16_1( res_pred_gain[b], (Word16) 0x6666 ); move32(); - res_pred_gain[b + STEREO_DFT_BAND_MAX] = Mpy_32_16_1(res_pred_gain[b + STEREO_DFT_BAND_MAX], (Word16)0x6666); + res_pred_gain[b + STEREO_DFT_BAND_MAX] = Mpy_32_16_1( res_pred_gain[b + STEREO_DFT_BAND_MAX], (Word16) 0x6666 ); move32(); } ELSE { - side_gain[b] = Madd_32_16(Mpy_32_16_1(prev_side_gain[b], hStereoDft->smooth_fac_fx[0][b]), - side_gain[b], sub((Word16)0x7FFF, hStereoDft->smooth_fac_fx[0][b])); + side_gain[b] = Madd_32_16( Mpy_32_16_1( prev_side_gain[b], hStereoDft->smooth_fac_fx[0][b] ), + side_gain[b], sub( (Word16) 0x7FFF, hStereoDft->smooth_fac_fx[0][b] ) ); move32(); - side_gain[b + STEREO_DFT_BAND_MAX] = Madd_32_16(Mpy_32_16_1(side_gain[b], hStereoDft->smooth_fac_fx[1][b]), - side_gain[b + STEREO_DFT_BAND_MAX], - sub((Word16)0x7FFF, hStereoDft->smooth_fac_fx[1][b])); + side_gain[b + STEREO_DFT_BAND_MAX] = Madd_32_16( Mpy_32_16_1( side_gain[b], hStereoDft->smooth_fac_fx[1][b] ), + side_gain[b + STEREO_DFT_BAND_MAX], + sub( (Word16) 0x7FFF, hStereoDft->smooth_fac_fx[1][b] ) ); move32(); - res_pred_gain[b] = Madd_32_16(Mpy_32_16_1(prev_res_pred_gain[b], hStereoDft->smooth_fac_fx[0][b]), - res_pred_gain[b], - sub((Word16)0x7FFF, hStereoDft->smooth_fac_fx[0][b])); + res_pred_gain[b] = Madd_32_16( Mpy_32_16_1( prev_res_pred_gain[b], hStereoDft->smooth_fac_fx[0][b] ), + res_pred_gain[b], + sub( (Word16) 0x7FFF, hStereoDft->smooth_fac_fx[0][b] ) ); move32(); - res_pred_gain[b + STEREO_DFT_BAND_MAX] = Madd_32_16(Mpy_32_16_1(res_pred_gain[b], hStereoDft->smooth_fac_fx[1][b]), - res_pred_gain[b + STEREO_DFT_BAND_MAX], - sub((Word16)0x7FFF, hStereoDft->smooth_fac_fx[1][b] )); + res_pred_gain[b + STEREO_DFT_BAND_MAX] = Madd_32_16( Mpy_32_16_1( res_pred_gain[b], hStereoDft->smooth_fac_fx[1][b] ), + res_pred_gain[b + STEREO_DFT_BAND_MAX], + sub( (Word16) 0x7FFF, hStereoDft->smooth_fac_fx[1][b] ) ); move32(); } } } - IF ( hMdDec != 0 ) + IF( hMdDec != 0 ) { Word64 xfade_start_ns; Word16 xfade_delay_subframes; Word16 i_hist; Word16 md_sf; - xfade_start_ns = W_sub(W_mult_32_32((Word32)cross_fade_start_offset, 1000000000), W_mult_32_32(IVAS_FB_ENC_DELAY_NS, output_Fs)); + xfade_start_ns = W_sub( W_mult_32_32( (Word32) cross_fade_start_offset, 1000000000 ), W_mult_32_32( IVAS_FB_ENC_DELAY_NS, output_Fs ) ); /* 64-bit container is needed for storing the result in the previous step. ToDo: Replace the 64-bit division below with appropriate BASOP */ - xfade_delay_subframes = (Word16)( xfade_start_ns / W_mult_32_32(( FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ), output_Fs)); + xfade_delay_subframes = (Word16) ( xfade_start_ns / W_mult_32_32( ( FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ), output_Fs ) ); move16(); - i_hist = sub((Word16)4 , xfade_delay_subframes); + i_hist = sub( (Word16) 4, xfade_delay_subframes ); move16(); - FOR ( k = 0; k < 2; k++ ) + FOR( k = 0; k < 2; k++ ) { - FOR ( i_sf = k * 2; i_sf < ( k + 1 ) * 2; i_sf++ ) + FOR( i_sf = k * 2; i_sf < ( k + 1 ) * 2; i_sf++ ) { - md_sf = (Word16)(EQ_16( num_md_sub_frames, MAX_PARAM_SPATIAL_SUBFRAMES ) ? i_sf : 0); - IF ( hStereoDft->first_frame ) + md_sf = (Word16) ( EQ_16( num_md_sub_frames, MAX_PARAM_SPATIAL_SUBFRAMES ) ? i_sf : 0 ); + IF( hStereoDft->first_frame ) { - FOR ( i = 0; i < 2; i++ ) + FOR( i = 0; i < 2; i++ ) { - FOR ( j = 0; j < 4; j++ ) + FOR( j = 0; j < 4; j++ ) { - FOR ( b = 0; b < hStereoDft->nbands; b++ ) + FOR( b = 0; b < hStereoDft->nbands; b++ ) { // The Q format of mixer_mat_fx is Q30 so applying the left shift. - hStereoDft->mixer_mat_smooth_fx[i][j][b + k * IVAS_MAX_NUM_BANDS] = L_shl_sat(hMdDec->mixer_mat_fx[i][j][b], 1); + hStereoDft->mixer_mat_smooth_fx[i][j][b + k * IVAS_MAX_NUM_BANDS] = L_shl_sat( hMdDec->mixer_mat_fx[i][j][b], 1 ); move32(); } - FOR ( ; b < IVAS_MAX_NUM_BANDS; b++ ) + FOR( ; b < IVAS_MAX_NUM_BANDS; b++ ) { hStereoDft->mixer_mat_smooth_fx[i][j][b + k * IVAS_MAX_NUM_BANDS] = 0; move32(); @@ -1189,18 +1189,18 @@ void ivas_sba_dirac_stereo_smooth_parameters_fx( } ELSE { - FOR ( i = 0; i < 2; i++ ) + FOR( i = 0; i < 2; i++ ) { - FOR ( j = 0; j < 4; j++ ) + FOR( j = 0; j < 4; j++ ) { - FOR ( b = 0; b < hStereoDft->nbands; b++ ) + FOR( b = 0; b < hStereoDft->nbands; b++ ) { Word16 beta = hStereoDft->smooth_fac_fx[k][b]; move16(); // The Q format of mixer_mat_prev_fx is Q30 so applying the left shift. hStereoDft->mixer_mat_smooth_fx[i][j][b + k * IVAS_MAX_NUM_BANDS] = - L_add_sat(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[i][j][b + k * IVAS_MAX_NUM_BANDS], beta), - L_shl_sat(Mpy_32_16_1(hMdDec->mixer_mat_prev_fx[i_hist][i][j][b], sub((Word16)0x7FFF, beta)), Q1)); + L_add_sat( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[i][j][b + k * IVAS_MAX_NUM_BANDS], beta ), + L_shl_sat( Mpy_32_16_1( hMdDec->mixer_mat_prev_fx[i_hist][i][j][b], sub( (Word16) 0x7FFF, beta ) ), Q1 ) ); move32(); } } @@ -1212,11 +1212,11 @@ void ivas_sba_dirac_stereo_smooth_parameters_fx( Copy32( hMdDec->mixer_mat_prev_fx[3][0][0], hMdDec->mixer_mat_prev_fx[2][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_SPAR_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); Copy32( hMdDec->mixer_mat_prev_fx[4][0][0], hMdDec->mixer_mat_prev_fx[3][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_SPAR_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); - FOR ( i = 0; i < 2; i++ ) + FOR( i = 0; i < 2; i++ ) { - FOR ( j = 0; j < 4; j++ ) + FOR( j = 0; j < 4; j++ ) { - FOR ( b = 0; b < hStereoDft->nbands; b++ ) + FOR( b = 0; b < hStereoDft->nbands; b++ ) { hMdDec->mixer_mat_prev_fx[4][i][j][b] = hMdDec->mixer_mat_fx[i][j][b + md_sf * IVAS_MAX_NUM_BANDS]; move32(); @@ -1241,10 +1241,10 @@ void ivas_sba_dirac_stereo_smooth_parameters_fx( *-------------------------------------------------------------------*/ void ivas_sba_dirac_stereo_dec_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ Word32 *output[CPE_CHANNELS], /* i/o: output synthesis signal */ - const Word16 output_frame, /* i : output frame length per channel */ - const Word16 mcmasa /* i : McMASA flag */ + const Word16 output_frame, /* i : output frame length per channel */ + const Word16 mcmasa /* i : McMASA flag */ ) { Word16 dtx_flag, fd_cng_flag; @@ -1255,7 +1255,7 @@ void ivas_sba_dirac_stereo_dec_fx( Word32 hb_gain[NB_DIV]; Word32 hb_synth_stereo[CPE_CHANNELS][L_FRAME48k]; Word32 DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX]; - Word16 q_dft[2] = {0, 0}; + Word16 q_dft[2] = { 0, 0 }; Word16 q = 0; SCE_DEC_HANDLE hSCE; CPE_DEC_HANDLE hCPE; @@ -1276,14 +1276,14 @@ void ivas_sba_dirac_stereo_dec_fx( IF( hSCE != NULL ) { #ifdef MSAN_FIX - Scale_sig32( hSCE->prev_hb_synth_fx, NS2SA_fx2(st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS),-( Q11 - hCPE->hStereoDft->q_dft ) ); + Scale_sig32( hSCE->prev_hb_synth_fx, NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), -( Q11 - hCPE->hStereoDft->q_dft ) ); #else Scale_sig32( hSCE->prev_hb_synth_fx, NS2SA_fx2( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), -( Q11 - hCPE->hStereoDft->q_dft ) ); #endif // MSAN_FIX hSCE->q_prev_hb_synth_fx = hCPE->hStereoDft->q_dft; } - IF ( GT_16(st_ivas->nchan_transport, 1) && EQ_16(mcmasa, 0) ) + IF( GT_16( st_ivas->nchan_transport, 1 ) && EQ_16( mcmasa, 0 ) ) { dtx_flag = 0; move16(); @@ -1292,17 +1292,17 @@ void ivas_sba_dirac_stereo_dec_fx( } ELSE { - dtx_flag = (Word16)LE_32(hSCE->hCoreCoder[0]->core_brate, SID_2k40); - fd_cng_flag = ( dtx_flag && EQ_16(hSCE->hCoreCoder[0]->cng_type, FD_CNG) ); + dtx_flag = (Word16) LE_32( hSCE->hCoreCoder[0]->core_brate, SID_2k40 ); + fd_cng_flag = ( dtx_flag && EQ_16( hSCE->hCoreCoder[0]->cng_type, FD_CNG ) ); } - sba_mono_flag = (Word16)EQ_16(st_ivas->hDecoderConfig->nchan_out, 1); + sba_mono_flag = (Word16) EQ_16( st_ivas->hDecoderConfig->nchan_out, 1 ); - memOffset = NS2SA( L_mult0(output_frame, FRAMES_PER_SEC), L_sub(IVAS_DEC_DELAY_NS, DELAY_BWE_TOTAL_NS) ); + memOffset = NS2SA( L_mult0( output_frame, FRAMES_PER_SEC ), L_sub( IVAS_DEC_DELAY_NS, DELAY_BWE_TOTAL_NS ) ); ivas_sba_dirac_stereo_config( hStereoDft->hConfig ); hStereoDft->nbands = ivas_sba_dirac_stereo_band_config( hStereoDft->band_limits, st_ivas->hDecoderConfig->output_Fs, hStereoDft->NFFT, ( ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT ) && !mcmasa ) ); stereo_dft_dec_update_fx( hStereoDft, output_frame, 1 /*st_ivas->sba_dirac_stereo_flag*/ ); - IF ( GT_16(st_ivas->nchan_transport, 1) ) + IF( GT_16( st_ivas->nchan_transport, 1 ) ) { stereo_dft_dec_analyze_fx( hCPE, output[0], DFT, 0, output_frame, output_frame, DFT_STEREO_DEC_ANA_FB, 0, 0, &q, &q_dft[0] ); stereo_dft_dec_analyze_fx( hCPE, output[1], DFT, 1, output_frame, output_frame, DFT_STEREO_DEC_ANA_FB, 0, 0, &q, &q_dft[0] ); @@ -1319,26 +1319,26 @@ void ivas_sba_dirac_stereo_dec_fx( stereo_dft_dec_core_switching_fx( hCPE, output[0] /*hSCE->save_output*/, hSCE->save_synth_fx, hSCE->save_hb_synth_fx, DFT, output_frame, 0, dtx_flag, &q, &q_dft[0] ); /* do updates here after skipping this in SCE decoder (needs to be done after core switching) */ - ivas_updt_dec_common_fx( hSCE->hCoreCoder[0], NORMAL_HQ_CORE, -1, hSCE->save_synth_fx, q); + ivas_updt_dec_common_fx( hSCE->hCoreCoder[0], NORMAL_HQ_CORE, -1, hSCE->save_synth_fx, q ); } /* mapping of DirAC parameters (azimuth, elevation, diffuseness) to DFT Stereo parameters (side gain, prediction gain) */ map_params_dirac_to_stereo( hStereoDft, st_ivas->hQMetaData, tmp_synth, DFT[0], st_ivas->ivas_format == MC_FORMAT, ( ( st_ivas->ivas_format != SBA_FORMAT && st_ivas->ivas_format != SBA_ISM_FORMAT ) || mcmasa ) ? hSCE->hCoreCoder[0]->L_frame : output_frame, - ( ( st_ivas->ivas_format != SBA_FORMAT && st_ivas->ivas_format != SBA_ISM_FORMAT ) || mcmasa ), hSCE != NULL ? hSCE->q_save_synth_fx:0); + ( ( st_ivas->ivas_format != SBA_FORMAT && st_ivas->ivas_format != SBA_ISM_FORMAT ) || mcmasa ), hSCE != NULL ? hSCE->q_save_synth_fx : 0 ); - IF ( (EQ_32( st_ivas->ivas_format , SBA_FORMAT) || EQ_32(st_ivas->ivas_format , SBA_ISM_FORMAT) ) && !mcmasa ) + IF( ( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) && !mcmasa ) { set_val_Word32( hStereoDft->res_pred_gain_fx, MAX_32, 3 * STEREO_DFT_BAND_MAX ); } /* DFT Stereo upmix */ stereo_dft_dec_fx( hStereoDft, hCPE->hCoreCoder[0], DFT, NULL, NULL, 1 /*st_ivas->sba_dirac_stereo_flag*/, sba_mono_flag, ( st_ivas->hSpar != NULL && !mcmasa ) ? st_ivas->hSpar->hMdDec : NULL, ( st_ivas->hSpar != NULL && !mcmasa ) ? st_ivas->hSpar->hFbMixer->cross_fade_start_offset : 0, - st_ivas->hDecoderConfig->output_Fs, st_ivas->nchan_transport, ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ) ); + st_ivas->hDecoderConfig->output_Fs, st_ivas->nchan_transport, ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ) ); /* DFT synthesis */ stereo_dft_dec_synthesize_fx( hCPE, DFT, 0, output[0], output_frame ); - IF ( EQ_16(sba_mono_flag, 0) ) + IF( EQ_16( sba_mono_flag, 0 ) ) { stereo_dft_dec_synthesize_fx( hCPE, DFT, 1, output[1], output_frame ); } @@ -1346,22 +1346,22 @@ void ivas_sba_dirac_stereo_dec_fx( synchro_synthesis_fx( st_ivas->hDecoderConfig->ivas_total_brate, hCPE, output, output_frame, 1 /*st_ivas->sba_dirac_stereo_flag*/ ); /* output scaling */ - IF ( EQ_16(sba_mono_flag, 0) ) + IF( EQ_16( sba_mono_flag, 0 ) ) { v_shr( output[0], 1, output[0], output_frame ); v_shr( output[1], 1, output[1], output_frame ); } /* delay HB synth */ - IF ( EQ_16(st_ivas->nchan_transport, 1) ) + IF( EQ_16( st_ivas->nchan_transport, 1 ) ) { Copy32( hSCE->save_hb_synth_fx + output_frame - memOffset, tmp_buf, memOffset ); Copy32( hSCE->save_hb_synth_fx, hSCE->save_hb_synth_fx + memOffset, output_frame - memOffset ); Copy32( hSCE->prev_hb_synth_fx, hSCE->save_hb_synth_fx, memOffset ); - v_shr( tmp_buf, sub(hSCE->q_prev_hb_synth_fx, hSCE->q_save_hb_synth_fx) ,hSCE->prev_hb_synth_fx, memOffset ); + v_shr( tmp_buf, sub( hSCE->q_prev_hb_synth_fx, hSCE->q_save_hb_synth_fx ), hSCE->prev_hb_synth_fx, memOffset ); } - IF ( (EQ_16( hCPE->hCoreCoder[0]->core, ACELP_CORE) || EQ_16(hCPE->hCoreCoder[0]->last_core, ACELP_CORE)) && EQ_16(fd_cng_flag, 0) && EQ_16(st_ivas->nchan_transport, 1) ) + IF( ( EQ_16( hCPE->hCoreCoder[0]->core, ACELP_CORE ) || EQ_16( hCPE->hCoreCoder[0]->last_core, ACELP_CORE ) ) && EQ_16( fd_cng_flag, 0 ) && EQ_16( st_ivas->nchan_transport, 1 ) ) { /* upmix ACELP BWE */ ivas_sba_dirac_stereo_compute_hb_gain( hStereoDft, hb_gain ); @@ -1370,7 +1370,7 @@ void ivas_sba_dirac_stereo_dec_fx( /* add HB to ACELP core */ v_add_fx( output[0], hb_synth_stereo[0], output[0], output_frame ); - IF ( EQ_16(sba_mono_flag, 0) ) + IF( EQ_16( sba_mono_flag, 0 ) ) { v_add_fx( output[1], hb_synth_stereo[1], output[1], output_frame ); @@ -1380,7 +1380,7 @@ void ivas_sba_dirac_stereo_dec_fx( } /* reset the other channels to 0 (they are not used since here) */ - FOR ( Word16 ch = CPE_CHANNELS; ch < st_ivas->nchan_transport; ch++ ) + FOR( Word16 ch = CPE_CHANNELS; ch < st_ivas->nchan_transport; ch++ ) { set_val_Word32( output[ch], 0, output_frame ); } @@ -1393,7 +1393,7 @@ void ivas_sba_dirac_stereo_dec_fx( IF( hSCE != NULL ) { #ifdef MSAN_FIX - Scale_sig32( hSCE->prev_hb_synth_fx, NS2SA_fx2(st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), ( Q11 - hCPE->hStereoDft->q_dft ) ); + Scale_sig32( hSCE->prev_hb_synth_fx, NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), ( Q11 - hCPE->hStereoDft->q_dft ) ); #else Scale_sig32( hSCE->prev_hb_synth_fx, NS2SA_fx2( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), ( Q11 - hCPE->hStereoDft->q_dft ) ); #endif // MSAN_FIX diff --git a/lib_dec/ivas_sba_rendering_internal.c b/lib_dec/ivas_sba_rendering_internal.c index 52db40217..a8be63373 100644 --- a/lib_dec/ivas_sba_rendering_internal.c +++ b/lib_dec/ivas_sba_rendering_internal.c @@ -149,7 +149,7 @@ void ivas_sba2mc_cldfb_fixed( FOR( m = 0; m < nb_channels_in; m++ ) { - g_fx = hoa_dec_mtx[SBA_NHARM_HOA3 * n + m]; //Q29 + g_fx = hoa_dec_mtx[SBA_NHARM_HOA3 * n + m]; // Q29 p_realOut_fx = realOut_fx[n]; p_imagOut_fx = imagOut_fx[n]; @@ -198,11 +198,12 @@ void ivas_sba2mc_cldfb_fixed( #ifdef IVAS_FLOAT_FIXED void ivas_mc2sba_fx( IVAS_OUTPUT_SETUP hIntSetup, /* i : Format of decoder output */ - Word32 *in_buffer_td_fx[], /* i : MC signals (on input) and the HOA3 (on output) *//*Q*/ - Word32 *buffer_td_fx[], /* i/o: MC signals (on input) and the HOA3 (on output) */ - const Word16 output_frame, /* i : output frame length per channel */ - const Word16 sba_order, /* i : Ambisonic (SBA) order */ - const Word16 gain_lfe_fx /* i : gain for LFE, 0 = ignore LFE */ + Word32 *in_buffer_td_fx[], + /* i : MC signals (on input) and the HOA3 (on output) */ /*Q*/ + Word32 *buffer_td_fx[], /* i/o: MC signals (on input) and the HOA3 (on output) */ + const Word16 output_frame, /* i : output frame length per channel */ + const Word16 sba_order, /* i : Ambisonic (SBA) order */ + const Word16 gain_lfe_fx /* i : gain for LFE, 0 = ignore LFE */ ) { Word16 i, j, k; @@ -212,7 +213,7 @@ void ivas_mc2sba_fx( Word16 azimuth, elevation; Word16 sba_num_chans; - assert( ( LE_16(sba_order , 3) ) && "Only order up to 3 is supported!" ); + assert( ( LE_16( sba_order, 3 ) ) && "Only order up to 3 is supported!" ); /* Init*/ sba_num_chans = imult1616( add( sba_order, 1 ), add( sba_order, 1 ) ); FOR( j = 0; j < sba_num_chans; j++ ) @@ -359,12 +360,12 @@ void ivas_mc2sba( *-------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED void ivas_param_mc_mc2sba_cldfb_fx( - IVAS_OUTPUT_SETUP hTransSetup, /* i : transported MC Format */ + IVAS_OUTPUT_SETUP hTransSetup, /* i : transported MC Format */ Word32 *hoa_encoder_fx, /* i : HOA3 encoder for the transported MC format */ - const Word16 slot_idx, /* i : current slot in the subframe */ + const Word16 slot_idx, /* i : current slot in the subframe */ Word32 Cldfb_RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i/o: Contains the MC signals (on input) and the HOA3 (on output) */ Word32 Cldfb_ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i/o: Contains the MC signals (on input) and the HOA3 (on output) */ - const Word16 nBands, /* i : number of synth CLDFB bands */ + const Word16 nBands, /* i : number of synth CLDFB bands */ const Word16 gain_lfe_fx /* i : gain applied to LFE */ ) { @@ -389,9 +390,9 @@ void ivas_param_mc_mc2sba_cldfb_fx( move16(); move16(); - FOR ( idx_ch = 0; idx_ch < add(hTransSetup.nchan_out_woLFE , hTransSetup.num_lfe); idx_ch++ ) + FOR( idx_ch = 0; idx_ch < add( hTransSetup.nchan_out_woLFE, hTransSetup.num_lfe ); idx_ch++ ) { - IF ( GT_16( hTransSetup.num_lfe , 0 ) && EQ_16( idx_ch , hTransSetup.index_lfe[idx_lfe] ) ) + IF( GT_16( hTransSetup.num_lfe, 0 ) && EQ_16( idx_ch, hTransSetup.index_lfe[idx_lfe] ) ) { IF( GT_32( gain_lfe_fx, 0 ) ) { @@ -400,14 +401,14 @@ void ivas_param_mc_mc2sba_cldfb_fx( Cldfb_ImagBuffer_tmp_fx[0][0] = L_add_sat( Cldfb_ImagBuffer_tmp_fx[0][0], Mult_32_16( L_shl( Cldfb_ImagBuffer_fx[idx_ch][slot_idx][0], 1 ), gain_lfe_fx ) ); } - IF ( LT_16(idx_lfe , sub( hTransSetup.num_lfe , 1 )) ) + IF( LT_16( idx_lfe, sub( hTransSetup.num_lfe, 1 ) ) ) { idx_lfe++; } } ELSE { - gains_fx = hoa_encoder_fx + imult1616( idx_in, sba_num_chans );/*Pointer addition*/ + gains_fx = hoa_encoder_fx + imult1616( idx_in, sba_num_chans ); /*Pointer addition*/ FOR( idx_out = 0; idx_out < sba_num_chans; idx_out++ ) { FOR( idx_band = 0; idx_band < nBands; idx_band++ ) @@ -420,7 +421,7 @@ void ivas_param_mc_mc2sba_cldfb_fx( idx_in++; } } - FOR ( idx_ch = 0; idx_ch < sba_num_chans; idx_ch++ ) + FOR( idx_ch = 0; idx_ch < sba_num_chans; idx_ch++ ) { Copy32( Cldfb_RealBuffer_tmp_fx[idx_ch], Cldfb_RealBuffer_fx[idx_ch][slot_idx], nBands ); Copy32( Cldfb_ImagBuffer_tmp_fx[idx_ch], Cldfb_ImagBuffer_fx[idx_ch][slot_idx], nBands ); @@ -509,30 +510,30 @@ void ivas_param_mc_mc2sba_cldfb( /*! r: SBA DirAC stereo flag */ #ifdef IVAS_FLOAT_FIXED Word16 ivas_sba_remapTCs_fx( - Word32 *sba_data_fx[], /* i/o: SBA signals */ - Decoder_Struct *st_ivas, /* i/o: decoder struct */ + Word32 *sba_data_fx[], /* i/o: SBA signals */ + Decoder_Struct *st_ivas, /* i/o: decoder struct */ const Word16 output_frame /* i : frame length */ ) { Word16 nchan_remapped; nchan_remapped = st_ivas->nchan_transport; move16(); - IF ( EQ_16(nchan_remapped , 3) ) + IF( EQ_16( nchan_remapped, 3 ) ) { nchan_remapped++; - IF (EQ_16(nchan_remapped , 4) ) + IF( EQ_16( nchan_remapped, 4 ) ) { Copy32( sba_data_fx[2], sba_data_fx[3], output_frame ); } } - IF ( GT_16(st_ivas->nchan_transport , 3) ) + IF( GT_16( st_ivas->nchan_transport, 3 ) ) { Word16 i = 0; move16(); Word32 temp_fx; /*convert WYXZ downmix to WYZX*/ - FOR ( i = 0; i < output_frame; i++ ) + FOR( i = 0; i < output_frame; i++ ) { temp_fx = sba_data_fx[2][i]; move32(); @@ -540,7 +541,7 @@ Word16 ivas_sba_remapTCs_fx( move32(); sba_data_fx[3][i] = temp_fx; move32(); - IF ( EQ_16(st_ivas->nchan_transport , 3) ) + IF( EQ_16( st_ivas->nchan_transport, 3 ) ) { sba_data_fx[2][i] = 0; move32(); @@ -594,7 +595,6 @@ int16_t ivas_sba_remapTCs( } - /*-------------------------------------------------------------------------* * ivas_ism2sba_sf() * @@ -602,13 +602,14 @@ int16_t ivas_sba_remapTCs( *-------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED void ivas_ism2sba_sf_fx( - Word32 *buffer_in_fx[], /* i : TC buffer *//*Q_buffer_in*/ - Word32 *buffer_out_fx[], /* o : TD signal buffers */ - ISM_RENDERER_HANDLE hIsmRendererData, /* i/o: renderer data */ - const Word16 num_objects, /* i : number of objects */ - const Word16 n_samples_to_render, /* i : output frame length per channel */ - const Word16 offset, /* i : offset for the interpolatr */ - const Word16 sba_order /* i : Ambisonic (SBA) order */ + Word32 *buffer_in_fx[], + /* i : TC buffer */ /*Q_buffer_in*/ + Word32 *buffer_out_fx[], /* o : TD signal buffers */ + ISM_RENDERER_HANDLE hIsmRendererData, /* i/o: renderer data */ + const Word16 num_objects, /* i : number of objects */ + const Word16 n_samples_to_render, /* i : output frame length per channel */ + const Word16 offset, /* i : offset for the interpolatr */ + const Word16 sba_order /* i : Ambisonic (SBA) order */ ) { Word16 i, j, k; @@ -620,17 +621,17 @@ void ivas_ism2sba_sf_fx( assert( ( sba_order <= 3 ) && "Only order up to 3 is supported!" ); assert( hIsmRendererData != NULL && "hIsmRendererData not allocated!" ); /* Init*/ - sba_num_chans = imult1616(add( sba_order , 1 ) , add( sba_order , 1 )); - FOR ( j = 0; j < sba_num_chans; j++ ) + sba_num_chans = imult1616( add( sba_order, 1 ), add( sba_order, 1 ) ); + FOR( j = 0; j < sba_num_chans; j++ ) { set32_fx( buffer_tmp_fx[j], 0, n_samples_to_render ); } - FOR ( i = 0; i < num_objects; i++ ) + FOR( i = 0; i < num_objects; i++ ) { - FOR ( j = 0; j < sba_num_chans; j++ ) + FOR( j = 0; j < sba_num_chans; j++ ) { - g2_fx = hIsmRendererData->interpolator_fx + offset;/*Pointer addition*/ - tc_fx = buffer_in_fx[i] + offset;/*Pointer addition*/ + g2_fx = hIsmRendererData->interpolator_fx + offset; /*Pointer addition*/ + tc_fx = buffer_in_fx[i] + offset; /*Pointer addition*/ out_fx = buffer_tmp_fx[j]; gain_fx = hIsmRendererData->gains_fx[i][j]; move32(); @@ -638,22 +639,22 @@ void ivas_ism2sba_sf_fx( move32(); FOR( k = 0; k < n_samples_to_render; k++ ) { - g1_fx = sub(32767 , *g2_fx); - *( out_fx ) += Mult_32_32( ( Mult_32_16( gain_fx, ( *( g2_fx ) ) ) + Mult_32_16( prev_gain_fx, g1_fx ) ), ( *( tc_fx ) ) );/*Q_buffer_in + 29 - 31*/ + g1_fx = sub( 32767, *g2_fx ); + *( out_fx ) += Mult_32_32( ( Mult_32_16( gain_fx, ( *( g2_fx ) ) ) + Mult_32_16( prev_gain_fx, g1_fx ) ), ( *( tc_fx ) ) ); /*Q_buffer_in + 29 - 31*/ g2_fx++; tc_fx++; out_fx++; } } } - FOR ( j = 0; j < sba_num_chans; j++ ) + FOR( j = 0; j < sba_num_chans; j++ ) { Copy32( buffer_tmp_fx[j], buffer_out_fx[j], n_samples_to_render ); } return; } #else // IVAS_FLOAT_FIXED - + void ivas_ism2sba_sf( float *buffer_in[], /* i : TC buffer */ float *buffer_out[], /* o : TD signal buffers */ @@ -716,10 +717,10 @@ void ivas_ism2sba_sf( Float to fixed conversion required for:output_f *************************/ ivas_error ivas_sba_linear_renderer_fx( - Word32 *output_f[], /* i/o: synthesized core-coder transport channels/DirAC output */ - const Word16 output_frame, /* i : output frame length per channel */ - const Word16 nchan_in, /* i : number of input ambisonics channels */ - const Word16 nchan_ism, /* i : number of objects */ + Word32 *output_f[], /* i/o: synthesized core-coder transport channels/DirAC output */ + const Word16 output_frame, /* i : output frame length per channel */ + const Word16 nchan_in, /* i : number of input ambisonics channels */ + const Word16 nchan_ism, /* i : number of objects */ const AUDIO_CONFIG output_config, /* i : output audio configuration */ const IVAS_OUTPUT_SETUP output_setup /* i : output format setup */ ) @@ -734,33 +735,33 @@ ivas_error ivas_sba_linear_renderer_fx( nchan_hoa = nchan_in; move16(); - IF ( EQ_16(nchan_in , 6) ) /*2H1V*/ + IF( EQ_16( nchan_in, 6 ) ) /*2H1V*/ { nchan_hoa = 9; move16(); } - ELSE IF ( EQ_16(nchan_in , 8) ) /*3H1V*/ + ELSE IF( EQ_16( nchan_in, 8 ) ) /*3H1V*/ { nchan_hoa = 16; move16(); } - SWITCH ( output_config ) + SWITCH( output_config ) { case IVAS_AUDIO_CONFIG_FOA: /* Ambisonics output, order: 1 */ case IVAS_AUDIO_CONFIG_HOA2: /* Ambisonics output, order: 2 */ case IVAS_AUDIO_CONFIG_HOA3: /* Ambisonics output, order: 3 */ - FOR ( i = nchan_hoa; i < output_setup.nchan_out_woLFE; i++ ) + FOR( i = nchan_hoa; i < output_setup.nchan_out_woLFE; i++ ) { set_zero_fx( output_f[i], output_frame ); } BREAK; case IVAS_AUDIO_CONFIG_EXTERNAL: - FOR ( i = output_setup.nchan_out_woLFE - 1; i >= nchan_ism; i-- ) + FOR( i = output_setup.nchan_out_woLFE - 1; i >= nchan_ism; i-- ) { Copy32( output_f[i - nchan_ism], output_f[i], output_frame ); } - FOR ( ; i >= 0; i-- ) + FOR( ; i >= 0; i-- ) { set_zero_fx( output_f[i], output_frame ); } @@ -836,12 +837,12 @@ ivas_error ivas_sba_linear_renderer( #ifdef IVAS_FLOAT_FIXED void ivas_sba_mix_matrix_determiner_fx( SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ - Word32 *output_fx[], /* i/o: transport/output audio channels */ + Word32 *output_fx[], /* i/o: transport/output audio channels */ const Word16 bfi, /* i : BFI flag */ const Word16 nchan_remapped, /* i : num channels after remapping of TCs */ const Word16 output_frame, /* i : output frame length */ const Word16 num_md_sub_frames /* i : number of subframes in mixing matrix*/ - ) +) { Word16 i, ch; Word16 num_bands_out, nchan_transport, nchan_out; @@ -892,8 +893,9 @@ void ivas_sba_mix_matrix_determiner_fx( } /* Mixing matrix determiner */ - num_bands_out = hSpar->hFbMixer->pFb->filterbank_num_bands; move16(); - ivas_spar_dec_gen_umx_mat_fx( hSpar->hMdDec, nchan_transport, num_bands_out, bfi, num_md_sub_frames); + num_bands_out = hSpar->hFbMixer->pFb->filterbank_num_bands; + move16(); + ivas_spar_dec_gen_umx_mat_fx( hSpar->hMdDec, nchan_transport, num_bands_out, bfi, num_md_sub_frames ); return; } #endif // IVAS_FLOAT_FIXED @@ -986,13 +988,13 @@ void ivas_sba_mix_matrix_determiner( num_bands_out = hSpar->hFbMixer->pFb->filterbank_num_bands; #ifdef IVAS_FLOAT_FIXED #if 1 /*Float to fixed changes */ - //Word16 num_out_ch; - //num_out_ch = hSpar->hMdDec->spar_md_cfg.num_umx_chs; + // Word16 num_out_ch; + // num_out_ch = hSpar->hMdDec->spar_md_cfg.num_umx_chs; hSpar->hMdDec->Q_mixer_mat = 31; - //Word16 num_in_ch; - //num_in_ch = hSpar->hMdDec->spar_md_cfg.num_umx_chs; + // Word16 num_in_ch; + // num_in_ch = hSpar->hMdDec->spar_md_cfg.num_umx_chs; #endif - ivas_spar_dec_gen_umx_mat_fx( hSpar->hMdDec, nchan_transport, num_bands_out, bfi, num_md_sub_frames); + ivas_spar_dec_gen_umx_mat_fx( hSpar->hMdDec, nchan_transport, num_bands_out, bfi, num_md_sub_frames ); #else ivas_spar_dec_gen_umx_mat( hSpar->hMdDec, nchan_transport, num_bands_out, bfi, num_md_sub_frames ); #endif // IVAS_FLOAT_FIXED @@ -1003,57 +1005,57 @@ void ivas_sba_mix_matrix_determiner( #else void ivas_sba_mix_matrix_determiner( - SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ - float *output[], /* i/o: transport/output audio channels */ - const int16_t bfi, /* i : BFI flag */ - const int16_t nchan_remapped, /* i : num channels after remapping of TCs */ - const int16_t output_frame, /* i : output frame length */ - const int16_t num_md_sub_frames /* i : number of subframes in mixing matrix*/ + SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ + float *output[], /* i/o: transport/output audio channels */ + const int16_t bfi, /* i : BFI flag */ + const int16_t nchan_remapped, /* i : num channels after remapping of TCs */ + const int16_t output_frame, /* i : output frame length */ + const int16_t num_md_sub_frames /* i : number of subframes in mixing matrix*/ ) { - int16_t i, ch; - float temp; - int16_t num_bands_out, nchan_transport, nchan_out; - - /* Convert numeric range */ - for (ch = 0; ch < nchan_remapped; ch++) - { - for (i = 0; i < output_frame; i++) + int16_t i, ch; + float temp; + int16_t num_bands_out, nchan_transport, nchan_out; + + /* Convert numeric range */ + for ( ch = 0; ch < nchan_remapped; ch++ ) { - temp = output[ch][i]; - temp = floorf(temp + 0.5f); - - if (temp > MAX16B_FLT) - { - temp = MAX16B_FLT; - } - else if (temp < (-1.0f * PCM16_TO_FLT_FAC)) - { - temp = (-1.0f * PCM16_TO_FLT_FAC); - } - temp *= (1.0f / PCM16_TO_FLT_FAC); - output[ch][i] = temp; + for ( i = 0; i < output_frame; i++ ) + { + temp = output[ch][i]; + temp = floorf( temp + 0.5f ); + + if ( temp > MAX16B_FLT ) + { + temp = MAX16B_FLT; + } + else if ( temp < ( -1.0f * PCM16_TO_FLT_FAC ) ) + { + temp = ( -1.0f * PCM16_TO_FLT_FAC ); + } + temp *= ( 1.0f / PCM16_TO_FLT_FAC ); + output[ch][i] = temp; + } } - } - /* AGC */ - nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; - nchan_out = nchan_transport; - ivas_agc_dec_process(hSpar->hAgcDec, output, output, nchan_transport, output_frame); + /* AGC */ + nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; + nchan_out = nchan_transport; + ivas_agc_dec_process( hSpar->hAgcDec, output, output, nchan_transport, output_frame ); - /* Convert numeric range back */ - for (ch = 0; ch < nchan_out; ch++) - { - for (i = 0; i < output_frame; i++) + /* Convert numeric range back */ + for ( ch = 0; ch < nchan_out; ch++ ) { - output[ch][i] = output[ch][i] * PCM16_TO_FLT_FAC; + for ( i = 0; i < output_frame; i++ ) + { + output[ch][i] = output[ch][i] * PCM16_TO_FLT_FAC; + } } - } - /* Mixing matrix determiner */ - num_bands_out = hSpar->hFbMixer->pFb->filterbank_num_bands; - ivas_spar_dec_gen_umx_mat(hSpar->hMdDec, nchan_transport, num_bands_out, bfi, num_md_sub_frames); + /* Mixing matrix determiner */ + num_bands_out = hSpar->hFbMixer->pFb->filterbank_num_bands; + ivas_spar_dec_gen_umx_mat( hSpar->hMdDec, nchan_transport, num_bands_out, bfi, num_md_sub_frames ); - return; + return; } #endif diff --git a/lib_dec/ivas_sce_dec.c b/lib_dec/ivas_sce_dec.c index 781a2504a..7c30d3032 100644 --- a/lib_dec/ivas_sce_dec.c +++ b/lib_dec/ivas_sce_dec.c @@ -283,7 +283,6 @@ ivas_error ivas_sce_dec( st_ivas->BER_detect |= st->BER_detect; - pop_wmops(); return error; } @@ -296,7 +295,7 @@ ivas_error ivas_sce_dec( *-------------------------------------------------------------------------*/ ivas_error create_sce_dec( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const Word16 sce_id, /* i : SCE # identifier */ const Word32 element_brate /* i : element bitrate */ ) @@ -313,7 +312,7 @@ ivas_error create_sce_dec( * Allocate SCE handle *-----------------------------------------------------------------*/ - IF ( ( hSCE = (SCE_DEC_HANDLE) malloc( sizeof( SCE_DEC_DATA ) ) ) == NULL ) + IF( ( hSCE = (SCE_DEC_HANDLE) malloc( sizeof( SCE_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SCE\n" ) ); } @@ -330,9 +329,9 @@ ivas_error create_sce_dec( /*-----------------------------------------------------------------* * Core Coder, 1 instance: allocate and initialize *-----------------------------------------------------------------*/ - - //if ( ( st = (DEC_CORE_HANDLE) calloc( sizeof( Decoder_State ) ) ) == NULL ) - IF ( ( st = (Decoder_State *)calloc(1, sizeof(Decoder_State))) == NULL ) + + // if ( ( st = (DEC_CORE_HANDLE) calloc( sizeof( Decoder_State ) ) ) == NULL ) + IF( ( st = (Decoder_State *) calloc( 1, sizeof( Decoder_State ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CoreCoder structure\n" ) ); } @@ -342,22 +341,22 @@ ivas_error create_sce_dec( st->total_brate = hSCE->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ st->mct_chan_mode = MCT_CHAN_MODE_REGULAR; st->is_ism_format = 0; - IF ( st_ivas->ivas_format == ISM_FORMAT || st_ivas->ivas_format == MASA_ISM_FORMAT ) + IF( st_ivas->ivas_format == ISM_FORMAT || st_ivas->ivas_format == MASA_ISM_FORMAT ) { st->is_ism_format = 1; } #ifndef IVAS_FLOAT_FIXED - IF ( ( error = init_decoder( st, 0, st_ivas->mc_mode ) ) != IVAS_ERR_OK ) + IF( ( error = init_decoder( st, 0, st_ivas->mc_mode ) ) != IVAS_ERR_OK ) #else - if ( ( error = init_decoder_fx(st, EVS_MONO) ) != IVAS_ERR_OK ) + if ( ( error = init_decoder_fx( st, EVS_MONO ) ) != IVAS_ERR_OK ) #endif { return error; } - IF ( st_ivas->ivas_format == SBA_FORMAT && ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_STEREO || ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_MONO && st_ivas->nchan_transport == 1 ) ) ) + IF( st_ivas->ivas_format == SBA_FORMAT && ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_STEREO || ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_MONO && st_ivas->nchan_transport == 1 ) ) ) { - IF ( ( error = openCldfb_ivas( &st->cldfbSynHB, CLDFB_SYNTHESIS, st->output_Fs, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) + IF( ( error = openCldfb_ivas( &st->cldfbSynHB, CLDFB_SYNTHESIS, st->output_Fs, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) { return error; } @@ -368,9 +367,9 @@ ivas_error create_sce_dec( } /* allocate and initialize "hTdCngDec" - needed in DTX */ - IF ( sce_id == 0 && st->hTdCngDec == NULL ) + IF( sce_id == 0 && st->hTdCngDec == NULL ) { - IF ( ( st->hTdCngDec = (TD_CNG_DEC_HANDLE) malloc( sizeof( TD_CNG_DEC_DATA ) ) ) == NULL ) + IF( ( st->hTdCngDec = (TD_CNG_DEC_HANDLE) malloc( sizeof( TD_CNG_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX/TD CNG\n" ) ); } @@ -382,15 +381,15 @@ ivas_error create_sce_dec( * Synthesis buffers: allocate and initialize *-----------------------------------------------------------------*/ - IF ( st_ivas->sba_dirac_stereo_flag ) + IF( st_ivas->sba_dirac_stereo_flag ) { - IF ( ( hSCE->save_synth = (float *) malloc( sizeof( float ) * output_frame ) ) == NULL ) + IF( ( hSCE->save_synth = (float *) malloc( sizeof( float ) * output_frame ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for stereo output\n" ) ); } set_zero( hSCE->save_synth, output_frame ); - IF ( ( hSCE->save_hb_synth = (float *) malloc( sizeof( float ) * output_frame ) ) == NULL ) + IF( ( hSCE->save_hb_synth = (float *) malloc( sizeof( float ) * output_frame ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate HB memory for stereo output\n" ) ); } @@ -423,7 +422,7 @@ void destroy_sce_dec( st = hSCE->hCoreCoder[0]; - IF ( st != NULL ) + IF( st != NULL ) { destroy_core_dec( st ); @@ -431,12 +430,12 @@ void destroy_sce_dec( st = NULL; } - IF ( hSCE->save_synth != NULL ) + IF( hSCE->save_synth != NULL ) { free( hSCE->save_synth ); hSCE->save_synth = NULL; } - IF ( hSCE->save_hb_synth != NULL ) + IF( hSCE->save_hb_synth != NULL ) { free( hSCE->save_hb_synth ); hSCE->save_hb_synth = NULL; diff --git a/lib_dec/ivas_sce_dec_fx.c b/lib_dec/ivas_sce_dec_fx.c index 9974fcc2a..6c183fc07 100644 --- a/lib_dec/ivas_sce_dec_fx.c +++ b/lib_dec/ivas_sce_dec_fx.c @@ -348,27 +348,26 @@ ivas_error create_sce_dec( st->is_ism_format = 1; } - //if (st_ivas->mode == IVAS_DEC_MODE_EVS) - if (st->element_mode == EVS_MONO) + // if (st_ivas->mode == IVAS_DEC_MODE_EVS) + if ( st->element_mode == EVS_MONO ) { - error = init_decoder_fx(st, EVS_MONO); - if (error) - { + error = init_decoder_fx( st, EVS_MONO ); + if ( error ) { - return error; + { + return error; + } } - } } else { - error = init_decoder_ivas_fx(st, 0, st_ivas->mc_mode); - if (error) - { + error = init_decoder_ivas_fx( st, 0, st_ivas->mc_mode ); + if ( error ) { - return error; + { + return error; + } } - } - } IF( EQ_16( (Word16) st_ivas->ivas_format, SBA_FORMAT ) && ( EQ_16( (Word16) st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) || ( EQ_16( (Word16) st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) && EQ_16( st_ivas->nchan_transport, 1 ) ) ) ) @@ -400,14 +399,14 @@ ivas_error create_sce_dec( IF( st_ivas->sba_dirac_stereo_flag ) { - IF( ( hSCE->save_synth_fx = (Word32 *) malloc( sizeof( *(hSCE->save_synth_fx) ) * output_frame ) ) == NULL ) + IF( ( hSCE->save_synth_fx = (Word32 *) malloc( sizeof( *( hSCE->save_synth_fx ) ) * output_frame ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for stereo output\n" ) ); } set_zero_fx( hSCE->save_synth_fx, output_frame ); hSCE->q_save_synth_fx = 0; - IF( ( hSCE->save_hb_synth_fx = (Word32 *) malloc( sizeof( *(hSCE->save_hb_synth_fx) ) * output_frame ) ) == NULL ) + IF( ( hSCE->save_hb_synth_fx = (Word32 *) malloc( sizeof( *( hSCE->save_hb_synth_fx ) ) * output_frame ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate HB memory for stereo output\n" ) ); } diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index aa7694ad3..52a12a737 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -388,11 +388,10 @@ ivas_error ivas_spar_dec_open_fx( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for PCA decoder" ); } - //ivas_pca_dec_init( hSpar->hPCA ); + // ivas_pca_dec_init( hSpar->hPCA ); #ifdef IVAS_FLOAT_FIXED - ivas_pca_dec_init_fx(hSpar->hPCA); + ivas_pca_dec_init_fx( hSpar->hPCA ); #endif - } /* mixer_mat intitialization */ @@ -1116,11 +1115,11 @@ void ivas_spar_get_cldfb_gains_fx( /* optimization*/ /* compute time-domain cross-fade for considered time slots*/ tmp_idx = sub( cf_start, imult1616( cf_cldfb_start, stride ) ); - //Word32 pFilterbank_cross_fade_fx[192];// Temporarily added to stored fixed value of hSpar->hFbMixer->pFilterbank_cross_fade_fx - //floatToFixed_arrL( (float *)hSpar->hFbMixer->pFilterbank_cross_fade, pFilterbank_cross_fade_fx, Q31, cf_len ); + // Word32 pFilterbank_cross_fade_fx[192];// Temporarily added to stored fixed value of hSpar->hFbMixer->pFilterbank_cross_fade_fx + // floatToFixed_arrL( (float *)hSpar->hFbMixer->pFilterbank_cross_fade, pFilterbank_cross_fade_fx, Q31, cf_len ); FOR( sample = 0; sample < cf_len; sample++ ) { - tgt_fx[tmp_idx++] = L_deposit_h(hSpar->hFbMixer->pFilterbank_cross_fade_fx[sample]); + tgt_fx[tmp_idx++] = L_deposit_h( hSpar->hFbMixer->pFilterbank_cross_fade_fx[sample] ); /* increasing window function */ } FOR( ; tmp_idx < num_samples; tmp_idx++ ) @@ -1138,7 +1137,7 @@ void ivas_spar_get_cldfb_gains_fx( { /* fill internal CLDFB analysis time buffer with data*/ Word16 x_fx = get_random_number_fx( &seed ); - cldfbAnaDec0->cldfb_state_fx[sample] = L_shl(x_fx,12); + cldfbAnaDec0->cldfb_state_fx[sample] = L_shl( x_fx, 12 ); } Word16 q_cldfb = 27; cldfbAnaDec0->Q_cldfb_state = q_cldfb; @@ -1147,7 +1146,7 @@ void ivas_spar_get_cldfb_gains_fx( FOR( sample = 0; sample < stride; sample++ ) { Word16 x_fx = get_random_number_fx( &seed ); - ts_inout_fx[sample] = L_shl( x_fx, 12 );/*Q-27*/ + ts_inout_fx[sample] = L_shl( x_fx, 12 ); /*Q-27*/ } cldfbAnalysis_ts_fx_fixed_q( ts_inout_fx, ts_re_fx, ts_im_fx, num_cldfb_bands, cldfbAnaDec0, &q_cldfb ); @@ -1168,17 +1167,17 @@ void ivas_spar_get_cldfb_gains_fx( /* target is synthesis output times the cross-fade window*/ FOR( sample = 0; sample < num_samples; sample++ ) { - tgt_fx[sample] = L_shl(Mult_32_32( tgt_fx[sample], L_add( T_fx[sample][0], L_add( T_fx[sample][1], T_fx[sample][2] ) ) ),10);/*Q31*/ + tgt_fx[sample] = L_shl( Mult_32_32( tgt_fx[sample], L_add( T_fx[sample][0], L_add( T_fx[sample][1], T_fx[sample][2] ) ) ), 10 ); /*Q31*/ } /* compute matrices */ - FOR ( slot_row = 0; slot_row < num_cf_slots; slot_row++ ) + FOR( slot_row = 0; slot_row < num_cf_slots; slot_row++ ) { - FOR ( slot_col = slot_row; slot_col < num_cf_slots; slot_col++ ) + FOR( slot_col = slot_row; slot_col < num_cf_slots; slot_col++ ) { Tt_T_fx[slot_row][slot_col] = 0; - FOR ( sample = 0; sample < num_samples; sample++ ) + FOR( sample = 0; sample < num_samples; sample++ ) { - Tt_T_fx[slot_row][slot_col] =L_add( Tt_T_fx[slot_row][slot_col], Mult_32_32(L_shl(T_fx[sample][slot_row],8), L_shl(T_fx[sample][slot_col],8) ) );/*Q58-Q31*/ + Tt_T_fx[slot_row][slot_col] = L_add( Tt_T_fx[slot_row][slot_col], Mult_32_32( L_shl( T_fx[sample][slot_row], 8 ), L_shl( T_fx[sample][slot_col], 8 ) ) ); /*Q58-Q31*/ } } } @@ -1186,25 +1185,25 @@ void ivas_spar_get_cldfb_gains_fx( Tt_T_fx[1][0] = Tt_T_fx[0][1]; Tt_T_fx[2][0] = Tt_T_fx[0][2]; Tt_T_fx[2][1] = Tt_T_fx[1][2]; - FOR ( slot_row = 0; slot_row < num_cf_slots; slot_row++ ) + FOR( slot_row = 0; slot_row < num_cf_slots; slot_row++ ) { Tt_tgt_fx[slot_row] = 0; - FOR ( sample = 0; sample < num_samples; sample++ ) + FOR( sample = 0; sample < num_samples; sample++ ) { - Tt_tgt_fx[slot_row] = L_add(Tt_tgt_fx[slot_row],Mult_32_32(T_fx[sample][slot_row] , tgt_fx[sample])); + Tt_tgt_fx[slot_row] = L_add( Tt_tgt_fx[slot_row], Mult_32_32( T_fx[sample][slot_row], tgt_fx[sample] ) ); } } Word16 output_q = 27; matrix_inverse_fx( Tt_T_fx, Tt_T_inv_fx, num_cf_slots, &output_q ); /* compute the optimal coefficients */ - FOR ( slot_row = 0; slot_row < num_cf_slots; slot_row++ ) + FOR( slot_row = 0; slot_row < num_cf_slots; slot_row++ ) { Word32 tmp = 0; - FOR ( slot_col = 0; slot_col < num_cf_slots; slot_col++ ) + FOR( slot_col = 0; slot_col < num_cf_slots; slot_col++ ) { - tmp = L_add(tmp,Mult_32_32(Tt_T_inv_fx[slot_row][slot_col] , Tt_tgt_fx[slot_col])); + tmp = L_add( tmp, Mult_32_32( Tt_T_inv_fx[slot_row][slot_col], Tt_tgt_fx[slot_col] ) ); } - weights_fx[add(cf_cldfb_start , slot_row)] = extract_l(L_shr(L_max( L_min( tmp, L_shl(1, (output_q-10)) ), 0 ), output_q - 10- Q_weights));/*Q_weights*/ + weights_fx[add( cf_cldfb_start, slot_row )] = extract_l( L_shr( L_max( L_min( tmp, L_shl( 1, ( output_q - 10 ) ) ), 0 ), output_q - 10 - Q_weights ) ); /*Q_weights*/ } hSpar->hFbMixer->cldfb_cross_fade_q = Q_weights; @@ -1684,8 +1683,7 @@ static Word16 ivas_spar_get_cldfb_slot_gain_fx( const int16_t time_slot_idx, int16_t *time_slot_idx0, int16_t *time_slot_idx1, - Word16 *weight_lowfreq_fx -) + Word16 *weight_lowfreq_fx ) { Word16 weight_fx; Word32 encfb_delay_fx, decfb_delay_fx; @@ -1698,26 +1696,26 @@ static Word16 ivas_spar_get_cldfb_slot_gain_fx( encfb_delay_fx = IVAS_FB_ENC_DELAY_NS; decfb_delay_fx = IVAS_FB_DEC_DELAY_NS; - Word32 one_by_outfs = 0;//q15 - switch (hDecoderConfig->output_Fs) - { - case 16000: - one_by_outfs = 2048000000; - break; - case 32000: - one_by_outfs = 1024000000; - break; - case 48000: - one_by_outfs = 682666688; - break; - default: - assert(0); - } - - Word64 fade_start = (Word64)one_by_outfs * hSpar->hFbMixer->cross_fade_start_offset; - fade_start = W_shr(fade_start, 15); - xfade_start_ns_fx = ((Word32)fade_start - encfb_delay_fx + L_shr(decfb_delay_fx,1)); - xfade_delay_subframes = (int16_t) (xfade_start_ns_fx / ( FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ) ); + Word32 one_by_outfs = 0; // q15 + switch ( hDecoderConfig->output_Fs ) + { + case 16000: + one_by_outfs = 2048000000; + break; + case 32000: + one_by_outfs = 1024000000; + break; + case 48000: + one_by_outfs = 682666688; + break; + default: + assert( 0 ); + } + + Word64 fade_start = (Word64) one_by_outfs * hSpar->hFbMixer->cross_fade_start_offset; + fade_start = W_shr( fade_start, 15 ); + xfade_start_ns_fx = ( (Word32) fade_start - encfb_delay_fx + L_shr( decfb_delay_fx, 1 ) ); + xfade_delay_subframes = (int16_t) ( xfade_start_ns_fx / ( FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ) ); i_hist = 4 - xfade_delay_subframes; split_band = SPAR_DIRAC_SPLIT_START_BAND; @@ -1727,24 +1725,23 @@ static Word16 ivas_spar_get_cldfb_slot_gain_fx( if ( hSpar->i_subframe > 3 ) { Word16 mod_res = time_slot_idx % MAX_PARAM_SPATIAL_SUBFRAMES; - switch (mod_res) + switch ( mod_res ) { - case 0: - weight_fx = 0; - break; - case 1: - weight_fx = 8191; - break; - case 2: - weight_fx = 16383; - break; - case 3: - weight_fx = 24575; - break; - default: - weight_fx = 0; - break; - + case 0: + weight_fx = 0; + break; + case 1: + weight_fx = 8191; + break; + case 2: + weight_fx = 16383; + break; + case 3: + weight_fx = 24575; + break; + default: + weight_fx = 0; + break; } } else @@ -1767,12 +1764,12 @@ static Word16 ivas_spar_get_cldfb_slot_gain_fx( #else static float ivas_spar_get_cldfb_slot_gain( - SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ - const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ - const int16_t time_slot_idx, - int16_t *time_slot_idx0, - int16_t *time_slot_idx1, - float *weight_lowfreq) + SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ + const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ + const int16_t time_slot_idx, + int16_t *time_slot_idx0, + int16_t *time_slot_idx1, + float *weight_lowfreq ) { float weight; float output_Fs, encfb_delay, decfb_delay; @@ -1831,15 +1828,14 @@ void ivas_spar_get_parameters_fx( const int16_t num_ch_out, const int16_t num_ch_in, const int16_t num_spar_bands, - Word32 par_mat_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS] -) + Word32 par_mat_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS] ) { int16_t spar_band, out_ch, in_ch; Word16 weight_fx, weight_20ms_fx; int16_t ts0, ts1, split_band; - //weight = ivas_spar_get_cldfb_slot_gain(hSpar, hDecoderConfig, ts, &ts0, &ts1, &weight_20ms); - weight_fx = ivas_spar_get_cldfb_slot_gain_fx( hSpar, hDecoderConfig, ts, &ts0, &ts1, &weight_20ms_fx); + // weight = ivas_spar_get_cldfb_slot_gain(hSpar, hDecoderConfig, ts, &ts0, &ts1, &weight_20ms); + weight_fx = ivas_spar_get_cldfb_slot_gain_fx( hSpar, hDecoderConfig, ts, &ts0, &ts1, &weight_20ms_fx ); split_band = SPAR_DIRAC_SPLIT_START_BAND; for ( spar_band = 0; spar_band < num_spar_bands; spar_band++ ) @@ -1856,14 +1852,13 @@ void ivas_spar_get_parameters_fx( if ( hSpar->i_subframe > 3 ) { - par_mat_fx[out_ch][in_ch][spar_band] = L_add_sat(Mpy_32_16_1(hSpar->hMdDec->mixer_mat_prev_fx[ts0][out_ch][in_ch][spar_band], sub(MAX_WORD16, weight_fx)), - Mpy_32_16_1(hSpar->hMdDec->mixer_mat_prev_fx[ts1][out_ch][in_ch][spar_band], weight_fx)); + par_mat_fx[out_ch][in_ch][spar_band] = L_add_sat( Mpy_32_16_1( hSpar->hMdDec->mixer_mat_prev_fx[ts0][out_ch][in_ch][spar_band], sub( MAX_WORD16, weight_fx ) ), + Mpy_32_16_1( hSpar->hMdDec->mixer_mat_prev_fx[ts1][out_ch][in_ch][spar_band], weight_fx ) ); } else { par_mat_fx[out_ch][in_ch][spar_band] = hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][spar_band]; } - } } else @@ -1872,9 +1867,7 @@ void ivas_spar_get_parameters_fx( { /* 20ms Transport channel reconstruction with matching encoder/decoder processing */ int16_t prev_idx = SPAR_DIRAC_SPLIT_START_BAND < IVAS_MAX_NUM_BANDS ? 1 : 0; /* if SPAR_DIRAC_SPLIT_START_BAND == IVAS_MAX_NUM_BANDS, then the sub-frame mixer_mat delay line is not active */ - par_mat_fx[out_ch][in_ch][spar_band] = L_add_sat(Mpy_32_16_1(hSpar->hMdDec->mixer_mat_prev_fx[prev_idx][out_ch][in_ch][spar_band], sub(MAX_WORD16, weight_20ms_fx)) - ,Mpy_32_16_1(hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][spar_band], weight_20ms_fx)); - + par_mat_fx[out_ch][in_ch][spar_band] = L_add_sat( Mpy_32_16_1( hSpar->hMdDec->mixer_mat_prev_fx[prev_idx][out_ch][in_ch][spar_band], sub( MAX_WORD16, weight_20ms_fx ) ), Mpy_32_16_1( hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][spar_band], weight_20ms_fx ) ); } } } @@ -1885,13 +1878,13 @@ void ivas_spar_get_parameters_fx( #else void ivas_spar_get_parameters( - SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ - const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ - const int16_t ts, - const int16_t num_ch_out, - const int16_t num_ch_in, - const int16_t num_spar_bands, - float par_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]) + SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ + const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ + const int16_t ts, + const int16_t num_ch_out, + const int16_t num_ch_in, + const int16_t num_spar_bands, + float par_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS] ) { int16_t spar_band, out_ch, in_ch; float weight, weight_20ms; @@ -2018,44 +2011,44 @@ static void ivas_spar_get_skip_mat_fx( Word16 spar_band, out_ch, in_ch; Word16 i_ts, skip_flag; - FOR ( out_ch = 0; out_ch < num_ch_out; out_ch++ ) + FOR( out_ch = 0; out_ch < num_ch_out; out_ch++ ) { - FOR ( in_ch = 0; in_ch < num_ch_in; in_ch++ ) + FOR( in_ch = 0; in_ch < num_ch_in; in_ch++ ) { skip_mat[out_ch][in_ch] = 1; skip_flag = 1; - FOR ( i_ts = 0; i_ts < MAX_PARAM_SPATIAL_SUBFRAMES; i_ts++ ) + FOR( i_ts = 0; i_ts < MAX_PARAM_SPATIAL_SUBFRAMES; i_ts++ ) { - FOR ( spar_band = 0; spar_band < num_spar_bands; spar_band++ ) + FOR( spar_band = 0; spar_band < num_spar_bands; spar_band++ ) { - IF ( hSpar->hMdDec->mixer_mat_prev_fx[1 + i_ts][out_ch][in_ch][spar_band] != 0 ) + IF( hSpar->hMdDec->mixer_mat_prev_fx[1 + i_ts][out_ch][in_ch][spar_band] != 0 ) { skip_flag = 0; BREAK; } } - IF ( skip_flag == 0 ) + IF( skip_flag == 0 ) { skip_mat[out_ch][in_ch] = 0; BREAK; } } - IF ( skip_mat[out_ch][in_ch] == 1 ) + IF( skip_mat[out_ch][in_ch] == 1 ) { - FOR ( i_ts = 0; i_ts < num_md_sub_frames; i_ts++ ) + FOR( i_ts = 0; i_ts < num_md_sub_frames; i_ts++ ) { - FOR ( spar_band = 0; spar_band < num_spar_bands; spar_band++ ) + FOR( spar_band = 0; spar_band < num_spar_bands; spar_band++ ) { - IF ( hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][spar_band + i_ts * IVAS_MAX_NUM_BANDS] != 0 ) + IF( hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][spar_band + i_ts * IVAS_MAX_NUM_BANDS] != 0 ) { skip_flag = 0; BREAK; } } - IF ( skip_flag == 0 ) + IF( skip_flag == 0 ) { skip_mat[out_ch][in_ch] = 0; BREAK; @@ -2341,8 +2334,8 @@ void ivas_spar_dec_agc_pca( #else void ivas_spar_dec_agc_pca_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - Word32 *output[], /* i/o: input/output audio channels */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + Word32 *output[], /* i/o: input/output audio channels */ const Word16 output_frame /* i : output frame length */ ) { @@ -2355,22 +2348,26 @@ void ivas_spar_dec_agc_pca_fx( hSpar = st_ivas->hSpar; hDecoderConfig = st_ivas->hDecoderConfig; - nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; move16(); + nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; + move16(); - IF ( GE_16(st_ivas->nchan_transport, 3 )) + IF( GE_16( st_ivas->nchan_transport, 3 ) ) { Word32 temp; Word16 i; /*convert WYZX downmix to WYXZ*/ - FOR ( i = 0; i < output_frame; i++ ) + FOR( i = 0; i < output_frame; i++ ) { - temp = output[2][i]; move32(); - output[2][i] = output[3][i]; move32(); - output[3][i] = temp; move32(); + temp = output[2][i]; + move32(); + output[2][i] = output[3][i]; + move32(); + output[3][i] = temp; + move32(); } } - IF ( hSpar->hMdDec->td_decorr_flag ) + IF( hSpar->hMdDec->td_decorr_flag ) { num_in_ingest = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); move16(); @@ -2387,7 +2384,7 @@ void ivas_spar_dec_agc_pca_fx( ivas_agc_dec_process_fx( hSpar->hAgcDec, ( output ), ( output ), nchan_transport, output_frame ); - IF ( hSpar->hPCA != NULL ) + IF( hSpar->hPCA != NULL ) { ivas_pca_dec_fx( hSpar->hPCA, output_frame, num_in_ingest, hDecoderConfig->ivas_total_brate, hDecoderConfig->last_ivas_total_brate, st_ivas->bfi, output ); } @@ -2435,7 +2432,7 @@ void ivas_spar_dec_set_render_map( #else void ivas_spar_dec_set_render_map_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const Word16 nCldfbTs /* i : number of CLDFB time slots */ + const Word16 nCldfbTs /* i : number of CLDFB time slots */ ) { SPAR_DEC_HANDLE hSpar; @@ -2443,18 +2440,22 @@ void ivas_spar_dec_set_render_map_fx( hSpar = st_ivas->hSpar; /* adapt subframes */ - hSpar->num_slots = nCldfbTs; move16(); - hSpar->slots_rendered = 0; move16(); - hSpar->subframes_rendered = 0; move16(); + hSpar->num_slots = nCldfbTs; + move16(); + hSpar->slots_rendered = 0; + move16(); + hSpar->subframes_rendered = 0; + move16(); set16_fx( hSpar->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME ); ivas_jbm_dec_get_adapted_subframes( nCldfbTs, hSpar->subframe_nbslots, &hSpar->nb_subframes ); /* copy also to tc buffer */ /* only for non-combined formats and combinded formats w/o discrete objects */ - IF ( !( EQ_16(st_ivas->ivas_format, SBA_ISM_FORMAT) && EQ_16(st_ivas->ism_mode, ISM_SBA_MODE_DISC) ) ) + IF( !( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) ) { - st_ivas->hTcBuffer->nb_subframes = hSpar->nb_subframes; move16(); + st_ivas->hTcBuffer->nb_subframes = hSpar->nb_subframes; + move16(); Copy( hSpar->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, hSpar->nb_subframes ); } @@ -2491,7 +2492,7 @@ void ivas_spar_dec_set_render_params( } #else void ivas_spar_dec_set_render_params_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ const Word16 n_cldfb_slots /* i : number of cldfb slots in this frame */ ) { @@ -2502,7 +2503,7 @@ void ivas_spar_dec_set_render_params_fx( hSpar = st_ivas->hSpar; nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; num_bands_out = hSpar->hFbMixer->pFb->filterbank_num_bands; - ivas_spar_dec_gen_umx_mat_fx( hSpar->hMdDec, nchan_transport, num_bands_out, st_ivas->bfi, ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate )); + ivas_spar_dec_gen_umx_mat_fx( hSpar->hMdDec, nchan_transport, num_bands_out, st_ivas->bfi, ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ) ); ivas_spar_dec_set_render_map_fx( st_ivas, n_cldfb_slots ); @@ -2596,7 +2597,7 @@ void ivas_spar_dec_digest_tc( } #else void ivas_spar_dec_digest_tc_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ const Word16 nchan_transport, /* i : number of transport channels */ const Word16 nCldfbSlots, /* i : number of CLDFB slots */ const Word16 nSamplesForRendering /* i : number of samples provided */ @@ -2605,8 +2606,9 @@ void ivas_spar_dec_digest_tc_fx( SPAR_DEC_HANDLE hSpar; hSpar = st_ivas->hSpar; - test(); test(); - IF ( hSpar->hMdDec->td_decorr_flag && !( EQ_16(st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC) || EQ_16(st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM) ) ) + test(); + test(); + IF( hSpar->hMdDec->td_decorr_flag && !( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) ) { Word16 nchan_internal, ch; Word16 ch_sba_idx; @@ -2616,12 +2618,14 @@ void ivas_spar_dec_digest_tc_fx( Word32 Pcm_tmp[MAX_SPAR_INTERNAL_CHANNELS][L_FRAME48k]; Word16 q_format = Q11; - ch_sba_idx = 0; move16(); - IF ( EQ_16(st_ivas->ivas_format, SBA_ISM_FORMAT )) + ch_sba_idx = 0; + move16(); + IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { - IF ( EQ_16(st_ivas->ism_mode, ISM_SBA_MODE_DISC )) + IF( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { - ch_sba_idx = st_ivas->nchan_ism; move16(); + ch_sba_idx = st_ivas->nchan_ism; + move16(); } } @@ -2630,50 +2634,51 @@ void ivas_spar_dec_digest_tc_fx( nSamplesLeftForTD = nSamplesForRendering; nchan_internal = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); - FOR ( ch = 0; ch < nchan_internal; ch++ ) + FOR( ch = 0; ch < nchan_internal; ch++ ) { pPcm_tmp[ch] = Pcm_tmp[ch]; - p_tc[ch] = st_ivas->hTcBuffer->tc_fx[ch + ch_sba_idx]; move32(); + p_tc[ch] = st_ivas->hTcBuffer->tc_fx[ch + ch_sba_idx]; + move32(); } - WHILE ( nSamplesLeftForTD ) + WHILE( nSamplesLeftForTD ) { Word16 nSamplesToDecorr = s_min( nSamplesLeftForTD, default_frame ); - IF ( hSpar->hTdDecorr ) + IF( hSpar->hTdDecorr ) { ivas_td_decorr_process_fx( hSpar->hTdDecorr, p_tc, pPcm_tmp, nSamplesToDecorr, &q_format ); - st_ivas->hTcBuffer->q_tc_fx = s_min(st_ivas->hTcBuffer->q_tc_fx, q_format); - IF ( GE_16(hSpar->hTdDecorr->num_apd_outputs, sub( nchan_internal, nchan_transport )) ) + st_ivas->hTcBuffer->q_tc_fx = s_min( st_ivas->hTcBuffer->q_tc_fx, q_format ); + IF( GE_16( hSpar->hTdDecorr->num_apd_outputs, sub( nchan_internal, nchan_transport ) ) ) { - FOR ( ch = 0; ch < sub(nchan_internal, nchan_transport); ch++ ) + FOR( ch = 0; ch < sub( nchan_internal, nchan_transport ); ch++ ) { Copy32( pPcm_tmp[hSpar->hTdDecorr->num_apd_outputs - 1 - ch], p_tc[nchan_internal - 1 - ch], nSamplesToDecorr ); } } ELSE { - FOR ( ch = 0; ch < sub(nchan_internal, nchan_transport); ch++ ) + FOR( ch = 0; ch < sub( nchan_internal, nchan_transport ); ch++ ) { set32_fx( p_tc[nchan_internal - 1 - ch], 0, nSamplesToDecorr ); } - FOR ( ch = 0; ch < hSpar->hTdDecorr->num_apd_outputs; ch++ ) + FOR( ch = 0; ch < hSpar->hTdDecorr->num_apd_outputs; ch++ ) { Copy32( pPcm_tmp[hSpar->hTdDecorr->num_apd_outputs - 1 - ch], p_tc[nchan_internal - 1 - ch], nSamplesToDecorr ); } } } - FOR ( ch = 0; ch < nchan_internal; ch++ ) + FOR( ch = 0; ch < nchan_internal; ch++ ) { p_tc[ch] = p_tc[ch] + nSamplesToDecorr; } - nSamplesLeftForTD = sub(nSamplesLeftForTD, nSamplesToDecorr); + nSamplesLeftForTD = sub( nSamplesLeftForTD, nSamplesToDecorr ); } } - ivas_spar_dec_set_render_params_fx(st_ivas, nCldfbSlots); + ivas_spar_dec_set_render_params_fx( st_ivas, nCldfbSlots ); return; } @@ -2808,10 +2813,9 @@ void ivas_spar_dec_upmixer( #ifdef IVAS_FLOAT_FIXED void ivas_spar_dec_upmixer_sf_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - Word32 *output_fx[], /* o : output audio channels */ + Word32 *output_fx[], /* o : output audio channels */ const Word16 nchan_internal, /* i : number of internal channels */ - Word16 out_len -) + Word16 out_len ) { /*TODO: To be removed later--------------------------------------------------------*/ float output[MAX_OUTPUT_CHANNELS][L_FRAME48k]; @@ -2820,7 +2824,7 @@ void ivas_spar_dec_upmixer_sf_fx( Word16 cldfb_band, num_cldfb_bands, numch_in, numch_out; Word32 *cldfb_in_ts_re_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS][CLDFB_NO_COL_MAX]; Word32 *cldfb_in_ts_im_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS][CLDFB_NO_COL_MAX]; - //Word32 output_fx[16][960]; + // Word32 output_fx[16][960]; Word16 i, b, ts, out_ch, in_ch; Word16 num_spar_bands, spar_band, nchan_transport; Word16 num_in_ingest, split_band; @@ -2847,20 +2851,20 @@ void ivas_spar_dec_upmixer_sf_fx( slot_size = NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); slot_idx_start = hSpar->slots_rendered; - IF ( EQ_16(st_ivas->ivas_format , SBA_ISM_FORMAT) && EQ_16(st_ivas->ism_mode , ISM_SBA_MODE_DISC) ) + IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { Word16 nchan_ism; nchan_ism = st_ivas->nchan_ism; - FOR ( i = 0; i < nchan_internal; i++ ) + FOR( i = 0; i < nchan_internal; i++ ) { p_tc_fx[i] = st_ivas->hTcBuffer->tc_fx[i + nchan_ism] + slot_idx_start * slot_size; } - IF ( EQ_16(st_ivas->ivas_format , SBA_ISM_FORMAT) && EQ_16(st_ivas->ism_mode , ISM_SBA_MODE_DISC) && EQ_16(st_ivas->renderer_type , RENDERER_BINAURAL_FASTCONV_ROOM) ) + IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) && EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) { - FOR ( i = 0; i < nchan_ism; i++ ) + FOR( i = 0; i < nchan_ism; i++ ) { p_tc_fx[i + nchan_internal] = st_ivas->hTcBuffer->tc_fx[i] + slot_idx_start * slot_size; } @@ -2868,7 +2872,7 @@ void ivas_spar_dec_upmixer_sf_fx( } ELSE { - FOR ( i = 0; i < nchan_internal; i++ ) + FOR( i = 0; i < nchan_internal; i++ ) { p_tc_fx[i] = st_ivas->hTcBuffer->tc_fx[i] + slot_idx_start * slot_size; } @@ -2879,7 +2883,7 @@ void ivas_spar_dec_upmixer_sf_fx( * TD Decorr and pcm ingest *---------------------------------------------------------------------*/ - IF ( hSpar->hMdDec->td_decorr_flag ) + IF( hSpar->hMdDec->td_decorr_flag ) { num_in_ingest = nchan_internal; } @@ -2900,12 +2904,12 @@ void ivas_spar_dec_upmixer_sf_fx( *---------------------------------------------------------------------*/ /* set-up pointers */ - IF ( NE_16(hDecoderConfig->output_config , IVAS_AUDIO_CONFIG_FOA) ) + IF( NE_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_FOA ) ) { /* at this point, output channels are used as intermediate procesing buffers */ - FOR ( in_ch = 0; in_ch < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; in_ch++ ) + FOR( in_ch = 0; in_ch < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; in_ch++ ) { - FOR ( ts = 0; ts < MAX_PARAM_SPATIAL_SUBFRAMES; ts++ ) + FOR( ts = 0; ts < MAX_PARAM_SPATIAL_SUBFRAMES; ts++ ) { cldfb_in_ts_re_fx[in_ch][ts] = &Pcm_tmp_fx[in_ch][ts * num_cldfb_bands]; cldfb_in_ts_im_fx[in_ch][ts] = &Pcm_tmp_fx[in_ch][ts * num_cldfb_bands + 4 * num_cldfb_bands]; @@ -2914,9 +2918,9 @@ void ivas_spar_dec_upmixer_sf_fx( } ELSE { - FOR ( in_ch = 0; in_ch < numch_in; in_ch++ ) + FOR( in_ch = 0; in_ch < numch_in; in_ch++ ) { - FOR ( ts = 0; ts < MAX_PARAM_SPATIAL_SUBFRAMES; ts++ ) + FOR( ts = 0; ts < MAX_PARAM_SPATIAL_SUBFRAMES; ts++ ) { cldfb_in_ts_re_fx[in_ch][ts] = &Pcm_tmp_fx[in_ch][ts * num_cldfb_bands]; cldfb_in_ts_im_fx[in_ch][ts] = &Pcm_tmp_fx[in_ch][ts * num_cldfb_bands + 4 * num_cldfb_bands]; @@ -2938,20 +2942,20 @@ void ivas_spar_dec_upmixer_sf_fx( /* CLDFB analysis of incoming frame */ - FOR ( in_ch = 0; in_ch < numch_in; in_ch++ ) + FOR( in_ch = 0; in_ch < numch_in; in_ch++ ) { - FOR ( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ ) + FOR( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ ) { Word16 q_cldfb = 11; cldfbAnalysis_ts_fx_fixed_q( &p_tc_fx[in_ch][ts * num_cldfb_bands], cldfb_in_ts_re_fx[in_ch][ts], cldfb_in_ts_im_fx[in_ch][ts], num_cldfb_bands, st_ivas->cldfbAnaDec[in_ch], &q_cldfb ); } } - IF ( EQ_16(st_ivas->ivas_format , SBA_ISM_FORMAT) && EQ_16(st_ivas->ism_mode , ISM_SBA_MODE_DISC) && EQ_16(st_ivas->renderer_type , RENDERER_BINAURAL_FASTCONV_ROOM) ) + IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) && EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) { - FOR ( ; in_ch < st_ivas->nchan_ism + numch_in; in_ch++ ) + FOR( ; in_ch < st_ivas->nchan_ism + numch_in; in_ch++ ) { - FOR ( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ ) + FOR( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ ) { Word16 q_cldfb = 11; cldfbAnalysis_ts_fx_fixed_q( &p_tc_fx[in_ch][ts * num_cldfb_bands], cldfb_in_ts_re_fx[in_ch][ts], cldfb_in_ts_im_fx[in_ch][ts], num_cldfb_bands, st_ivas->cldfbAnaDec[in_ch], &q_cldfb ); @@ -2959,49 +2963,49 @@ void ivas_spar_dec_upmixer_sf_fx( } } - IF ( ( LT_32(hDecoderConfig->ivas_total_brate , IVAS_24k4) ) && ( ( EQ_16(hDecoderConfig->output_config , IVAS_AUDIO_CONFIG_HOA2) ) || ( EQ_16(hDecoderConfig->output_config , IVAS_AUDIO_CONFIG_HOA3) ) ) ) + IF( ( LT_32( hDecoderConfig->ivas_total_brate, IVAS_24k4 ) ) && ( ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA2 ) ) || ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA3 ) ) ) ) { Word16 q_cldfb = 6; ivas_spar_calc_smooth_facs_fx( cldfb_in_ts_re_fx[0], cldfb_in_ts_im_fx[0], q_cldfb, num_spar_bands, hSpar->subframe_nbslots[hSpar->subframes_rendered], hSpar->subframes_rendered == 0, &hSpar->hFbMixer->pFb->fb_bin_to_band, hSpar->hMdDec->smooth_fac_fx, hSpar->hMdDec->smooth_buf_fx ); } - FOR ( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ ) + FOR( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ ) { md_idx = hSpar->render_to_md_map[ts + slot_idx_start]; floatToFixed_arr( hSpar->hFbMixer->cldfb_cross_fade, hSpar->hFbMixer->cldfb_cross_fade_fx, Q15, CLDFB_NO_COL_MAX ); ivas_spar_get_parameters_fx( hSpar, hDecoderConfig, md_idx, numch_out, numch_in, num_spar_bands, mixer_mat_fx ); - IF ( ( LT_32(hDecoderConfig->ivas_total_brate , IVAS_24k4) ) && ( ( EQ_16(hDecoderConfig->output_config , IVAS_AUDIO_CONFIG_HOA2) ) || ( EQ_16(hDecoderConfig->output_config , IVAS_AUDIO_CONFIG_HOA3) ) ) ) + IF( ( LT_32( hDecoderConfig->ivas_total_brate, IVAS_24k4 ) ) && ( ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA2 ) ) || ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA3 ) ) ) ) { - FOR ( spar_band = 0; spar_band < num_spar_bands; spar_band++ ) + FOR( spar_band = 0; spar_band < num_spar_bands; spar_band++ ) { - FOR ( out_ch = 0; out_ch < numch_out; out_ch++ ) + FOR( out_ch = 0; out_ch < numch_out; out_ch++ ) { - FOR ( in_ch = 0; in_ch < numch_in; in_ch++ ) + FOR( in_ch = 0; in_ch < numch_in; in_ch++ ) { - mixer_mat_fx[out_ch][in_ch][spar_band] = L_add(Mult_32_16( mixer_mat_fx[out_ch][in_ch][spar_band], sub( 32767, hSpar->hMdDec->smooth_fac_fx[spar_band] ) ) , Mult_32_16( hSpar->hMdDec->mixer_mat_prev2_fx[out_ch][in_ch][spar_band], hSpar->hMdDec->smooth_fac_fx[spar_band] )); /*q1*/ + mixer_mat_fx[out_ch][in_ch][spar_band] = L_add( Mult_32_16( mixer_mat_fx[out_ch][in_ch][spar_band], sub( 32767, hSpar->hMdDec->smooth_fac_fx[spar_band] ) ), Mult_32_16( hSpar->hMdDec->mixer_mat_prev2_fx[out_ch][in_ch][spar_band], hSpar->hMdDec->smooth_fac_fx[spar_band] ) ); /*q1*/ hSpar->hMdDec->mixer_mat_prev2_fx[out_ch][in_ch][spar_band] = mixer_mat_fx[out_ch][in_ch][spar_band]; } } } } - FOR ( cldfb_band = 0; cldfb_band < num_cldfb_bands; cldfb_band++ ) + FOR( cldfb_band = 0; cldfb_band < num_cldfb_bands; cldfb_band++ ) { Word32 out_re_fx[IVAS_SPAR_MAX_CH]; Word32 out_im_fx[IVAS_SPAR_MAX_CH]; - Word32 cldfb_par_fx;/*q1*/ + Word32 cldfb_par_fx; /*q1*/ ivas_fb_bin_to_band_data_t *bin2band = &hSpar->hFbMixer->pFb->fb_bin_to_band; - FOR ( out_ch = 0; out_ch < numch_out; out_ch++ ) + FOR( out_ch = 0; out_ch < numch_out; out_ch++ ) { out_re_fx[out_ch] = 0; out_im_fx[out_ch] = 0; - FOR ( in_ch = 0; in_ch < numch_in; in_ch++ ) + FOR( in_ch = 0; in_ch < numch_in; in_ch++ ) { - IF ( EQ_16(b_skip_mat[out_ch][in_ch] , 0) ) + IF( EQ_16( b_skip_mat[out_ch][in_ch], 0 ) ) { - IF ( LT_16(cldfb_band , CLDFB_PAR_WEIGHT_START_BAND) ) /* tuning parameter, depends on how much SPAR Filters overlap for the CLDFB bands */ + IF( LT_16( cldfb_band, CLDFB_PAR_WEIGHT_START_BAND ) ) /* tuning parameter, depends on how much SPAR Filters overlap for the CLDFB bands */ { spar_band = bin2band->p_cldfb_map_to_spar_band[cldfb_band]; cldfb_par_fx = mixer_mat_fx[out_ch][in_ch][spar_band]; @@ -3012,42 +3016,42 @@ void ivas_spar_dec_upmixer_sf_fx( FOR( spar_band = bin2band->p_spar_start_bands[cldfb_band]; spar_band < num_spar_bands; spar_band++ ) { /* accumulate contributions from all SPAR bands */ - Word16 tmp = extract_l(L_shr( bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band], 7 )); + Word16 tmp = extract_l( L_shr( bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band], 7 ) ); cldfb_par_fx = L_add_sat( cldfb_par_fx, Mult_32_16( mixer_mat_fx[out_ch][in_ch][spar_band], tmp ) ); /*q1*/ } } - out_re_fx[out_ch] = L_add(out_re_fx[out_ch],Mult_32_32(cldfb_in_ts_re_fx[in_ch][ts][cldfb_band] , cldfb_par_fx));/*q1-25*/ - out_im_fx[out_ch] = L_add(out_im_fx[out_ch],Mult_32_32(cldfb_in_ts_im_fx[in_ch][ts][cldfb_band] , cldfb_par_fx));/*q1-25*/ + out_re_fx[out_ch] = L_add( out_re_fx[out_ch], Mult_32_32( cldfb_in_ts_re_fx[in_ch][ts][cldfb_band], cldfb_par_fx ) ); /*q1-25*/ + out_im_fx[out_ch] = L_add( out_im_fx[out_ch], Mult_32_32( cldfb_in_ts_im_fx[in_ch][ts][cldfb_band], cldfb_par_fx ) ); /*q1-25*/ } } } /*update CLDFB data with the parameter-modified data*/ - FOR ( out_ch = 0; out_ch < numch_out; out_ch++ ) + FOR( out_ch = 0; out_ch < numch_out; out_ch++ ) { - cldfb_in_ts_re_fx[out_ch][ts][cldfb_band] = L_shl(out_re_fx[out_ch],31-q1);/*Q=6*/ - cldfb_in_ts_im_fx[out_ch][ts][cldfb_band] = L_shl(out_im_fx[out_ch], 31 - q1);/*Q=6*/ + cldfb_in_ts_re_fx[out_ch][ts][cldfb_band] = L_shl( out_re_fx[out_ch], 31 - q1 ); /*Q=6*/ + cldfb_in_ts_im_fx[out_ch][ts][cldfb_band] = L_shl( out_im_fx[out_ch], 31 - q1 ); /*Q=6*/ } } - IF ( ( EQ_16(( add(add(slot_idx_start , ts) , 1) ) , hSpar->num_slots) ) || ( NE_16(( md_idx / JBM_CLDFB_SLOTS_IN_SUBFRAME ) , ( hSpar->render_to_md_map[ts + slot_idx_start + 1] / JBM_CLDFB_SLOTS_IN_SUBFRAME )) ) ) + IF( ( EQ_16( ( add( add( slot_idx_start, ts ), 1 ) ), hSpar->num_slots ) ) || ( NE_16( ( md_idx / JBM_CLDFB_SLOTS_IN_SUBFRAME ), ( hSpar->render_to_md_map[ts + slot_idx_start + 1] / JBM_CLDFB_SLOTS_IN_SUBFRAME ) ) ) ) { /* we have crossed an unadapted parameter sf border, update previous mixing matrices */ Word16 md_sf = md_idx / JBM_CLDFB_SLOTS_IN_SUBFRAME; split_band = SPAR_DIRAC_SPLIT_START_BAND; md_sf = ( num_md_sub_frames == MAX_PARAM_SPATIAL_SUBFRAMES ) ? md_sf : 0; - IF ( LT_16(split_band , IVAS_MAX_NUM_BANDS) ) + IF( LT_16( split_band, IVAS_MAX_NUM_BANDS ) ) { Copy32( hSpar->hMdDec->mixer_mat_prev_fx[1][0][0], hSpar->hMdDec->mixer_mat_prev_fx[0][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_SPAR_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); Copy32( hSpar->hMdDec->mixer_mat_prev_fx[2][0][0], hSpar->hMdDec->mixer_mat_prev_fx[1][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_SPAR_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); Copy32( hSpar->hMdDec->mixer_mat_prev_fx[3][0][0], hSpar->hMdDec->mixer_mat_prev_fx[2][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_SPAR_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); Copy32( hSpar->hMdDec->mixer_mat_prev_fx[4][0][0], hSpar->hMdDec->mixer_mat_prev_fx[3][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_SPAR_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); - FOR ( out_ch = 0; out_ch < numch_out; out_ch++ ) + FOR( out_ch = 0; out_ch < numch_out; out_ch++ ) { - FOR ( in_ch = 0; in_ch < numch_in; in_ch++ ) + FOR( in_ch = 0; in_ch < numch_in; in_ch++ ) { - FOR ( b = 0; b < num_spar_bands; b++ ) + FOR( b = 0; b < num_spar_bands; b++ ) { hSpar->hMdDec->mixer_mat_prev_fx[4][out_ch][in_ch][b] = hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][b + md_sf * IVAS_MAX_NUM_BANDS]; } @@ -3059,7 +3063,7 @@ void ivas_spar_dec_upmixer_sf_fx( } } - IF ( NE_16(hDecoderConfig->output_config , IVAS_AUDIO_CONFIG_FOA) && NE_16(hDecoderConfig->output_config , IVAS_AUDIO_CONFIG_STEREO) && NE_16(hDecoderConfig->output_config , IVAS_AUDIO_CONFIG_MONO) ) + IF( NE_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_FOA ) && NE_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) && NE_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) ) { FOR( Word16 ch = 0; ch < add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ); ch++ ) { @@ -3073,39 +3077,39 @@ void ivas_spar_dec_upmixer_sf_fx( #endif // MSAN_FIX } /*------------------------------------------------------------------ends*/ - IF ( st_ivas->hDirAC != NULL ) + IF( st_ivas->hDirAC != NULL ) { Word16 outchannels, idx_in, idx_lfe, ch; idx_in = 0; idx_lfe = 0; - outchannels = add(st_ivas->hOutSetup.nchan_out_woLFE , st_ivas->hOutSetup.num_lfe); + outchannels = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ); - FOR ( ch = 0; ch < outchannels; ch++ ) + FOR( ch = 0; ch < outchannels; ch++ ) { - IF ( ( GT_16(st_ivas->hOutSetup.num_lfe , 0) ) && ( EQ_16(st_ivas->hOutSetup.index_lfe[idx_lfe] , ch) ) ) + IF( ( GT_16( st_ivas->hOutSetup.num_lfe, 0 ) ) && ( EQ_16( st_ivas->hOutSetup.index_lfe[idx_lfe], ch ) ) ) { set_zero_fx( output_fx[ch], hSpar->subframe_nbslots[hSpar->subframes_rendered] * num_cldfb_bands ); - IF ( LT_16(idx_lfe , ( sub(st_ivas->hDirACRend->hOutSetup.num_lfe , 1) ) )) + IF( LT_16( idx_lfe, ( sub( st_ivas->hDirACRend->hOutSetup.num_lfe, 1 ) ) ) ) { idx_lfe++; } } ELSE { - IF ( ( EQ_16(hDecoderConfig->output_config , IVAS_AUDIO_CONFIG_FOA) || !( EQ_16(st_ivas->hOutSetup.output_config , IVAS_AUDIO_CONFIG_BINAURAL) || EQ_16(st_ivas->hOutSetup.output_config , IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR) || EQ_16(st_ivas->hOutSetup.output_config , IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB) ) ) && - !( EQ_16(st_ivas->ivas_format , SBA_ISM_FORMAT) && EQ_16(st_ivas->ism_mode , ISM_SBA_MODE_DISC) && EQ_16(st_ivas->renderer_type , RENDERER_BINAURAL_FASTCONV_ROOM) ) ) + IF( ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_FOA ) || !( EQ_16( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_16( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_16( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) ) && + !( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) && EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) ) { - Scale_sig32(st_ivas->cldfbSynDec[idx_in]->cldfb_state_fx, st_ivas->cldfbSynDec[idx_in]->p_filter_length, -6 ); - st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state = sub(st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state, 6); + Scale_sig32( st_ivas->cldfbSynDec[idx_in]->cldfb_state_fx, st_ivas->cldfbSynDec[idx_in]->p_filter_length, -6 ); + st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state = sub( st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state, 6 ); Scale_sig32( output_fx[ch], out_len, -6 ); - FOR ( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ ) + FOR( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ ) { cldfbSynthesis_ivas_fx( &cldfb_in_ts_re_fx[idx_in][ts], &cldfb_in_ts_im_fx[idx_in][ts], &output_fx[ch][ts * num_cldfb_bands], num_cldfb_bands, st_ivas->cldfbSynDec[idx_in] ); } Scale_sig32( output_fx[ch], out_len, 6 ); - Scale_sig32(st_ivas->cldfbSynDec[idx_in]->cldfb_state_fx, st_ivas->cldfbSynDec[idx_in]->p_filter_length, 6 ); - st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state = add(st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state, 6); + Scale_sig32( st_ivas->cldfbSynDec[idx_in]->cldfb_state_fx, st_ivas->cldfbSynDec[idx_in]->p_filter_length, 6 ); + st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state = add( st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state, 6 ); } idx_in++; @@ -3115,22 +3119,22 @@ void ivas_spar_dec_upmixer_sf_fx( ELSE { /* CLDFB to time synthesis (overwrite mixer output) */ - FOR ( out_ch = 0; out_ch < numch_out_dirac; out_ch++ ) + FOR( out_ch = 0; out_ch < numch_out_dirac; out_ch++ ) { Scale_sig32( st_ivas->cldfbSynDec[out_ch]->cldfb_state_fx, st_ivas->cldfbSynDec[out_ch]->p_filter_length, -6 ); - st_ivas->cldfbSynDec[out_ch]->Q_cldfb_state = sub(st_ivas->cldfbSynDec[out_ch]->Q_cldfb_state, 6); + st_ivas->cldfbSynDec[out_ch]->Q_cldfb_state = sub( st_ivas->cldfbSynDec[out_ch]->Q_cldfb_state, 6 ); Scale_sig32( output_fx[out_ch], out_len, -6 ); - FOR ( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ ) + FOR( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ ) { cldfbSynthesis_ivas_fx( &cldfb_in_ts_re_fx[out_ch][ts], &cldfb_in_ts_im_fx[out_ch][ts], &output_fx[out_ch][ts * num_cldfb_bands], num_cldfb_bands, st_ivas->cldfbSynDec[out_ch] ); } Scale_sig32( output_fx[out_ch], out_len, 6 ); Scale_sig32( st_ivas->cldfbSynDec[out_ch]->cldfb_state_fx, st_ivas->cldfbSynDec[out_ch]->p_filter_length, 6 ); - st_ivas->cldfbSynDec[out_ch]->Q_cldfb_state = add(st_ivas->cldfbSynDec[out_ch]->Q_cldfb_state, 6); + st_ivas->cldfbSynDec[out_ch]->Q_cldfb_state = add( st_ivas->cldfbSynDec[out_ch]->Q_cldfb_state, 6 ); } } - hSpar->slots_rendered = add(hSpar->slots_rendered,hSpar->subframe_nbslots[hSpar->subframes_rendered]); + hSpar->slots_rendered = add( hSpar->slots_rendered, hSpar->subframe_nbslots[hSpar->subframes_rendered] ); hSpar->subframes_rendered++; pop_wmops(); @@ -3175,7 +3179,7 @@ void ivas_spar_dec_upmixer_sf( slot_idx_start = hSpar->slots_rendered; #ifdef IVAS_FLOAT_FIXED - for ( i = 0; i < s_max(st_ivas->nchan_ism,0)+ nchan_internal; i++ ) + for ( i = 0; i < s_max( st_ivas->nchan_ism, 0 ) + nchan_internal; i++ ) { floatToFixed_arr32( st_ivas->hTcBuffer->tc[i], st_ivas->hTcBuffer->tc_fx[i], Q11, st_ivas->hTcBuffer->n_samples_available ); } @@ -3418,8 +3422,7 @@ void ivas_spar_dec_upmixer_sf( } else { - if ( ( hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_FOA || !( st_ivas->hOutSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL || st_ivas->hOutSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || st_ivas->hOutSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB - ) ) && + if ( ( hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_FOA || !( st_ivas->hOutSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL || st_ivas->hOutSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || st_ivas->hOutSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) && !( st_ivas->ivas_format == SBA_ISM_FORMAT && st_ivas->ism_mode == ISM_SBA_MODE_DISC && st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) ) { for ( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ ) diff --git a/lib_dec/ivas_spar_md_dec.c b/lib_dec/ivas_spar_md_dec.c index 097ff9bb3..dbfa58e17 100644 --- a/lib_dec/ivas_spar_md_dec.c +++ b/lib_dec/ivas_spar_md_dec.c @@ -88,11 +88,11 @@ static void ivas_spar_dec_compute_ramp_down_post_matrix( ivas_spar_md_dec_state_ #endif #ifdef IVAS_FLOAT_FIXED -static void ivas_spar_dec_compute_ramp_down_post_matrix_fx(ivas_spar_md_dec_state_t *hMdDec, const Word16 num_bands, const Word16 bfi, const Word16 num_md_sub_frames); +static void ivas_spar_dec_compute_ramp_down_post_matrix_fx( ivas_spar_md_dec_state_t *hMdDec, const Word16 num_bands, const Word16 bfi, const Word16 num_md_sub_frames ); #endif // IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED -static void ivas_spar_md_fill_invalid_bands_fx(ivas_spar_dec_matrices_t *pSpar_coeffs, ivas_spar_dec_matrices_t *pSpar_coeffs_prev, const Word16 *valid_bands, Word16 *base_band_age, const Word16 num_bands, const Word16 num_channels, const Word16 num_md_sub_frames); +static void ivas_spar_md_fill_invalid_bands_fx( ivas_spar_dec_matrices_t *pSpar_coeffs, ivas_spar_dec_matrices_t *pSpar_coeffs_prev, const Word16 *valid_bands, Word16 *base_band_age, const Word16 num_bands, const Word16 num_channels, const Word16 num_md_sub_frames ); #endif #ifndef IVAS_FLOAT_FIXED static void ivas_spar_md_fill_invalid_bands( ivas_spar_dec_matrices_t *pSpar_coeffs, ivas_spar_dec_matrices_t *pSpar_coeffs_prev, const int16_t *valid_bands, int16_t *base_band_age, const int16_t num_bands, const int16_t numch_out, const int16_t num_md_sub_frames ); @@ -115,11 +115,9 @@ static ivas_error ivas_deindex_real_index_fx( const int16_t *index, const int16_ #endif #ifdef IVAS_FLOAT_FIXED -static void ivas_spar_dec_parse_md_bs_fx( ivas_spar_md_dec_state_t *hMdDec, Decoder_State *st, int16_t *nB, int16_t *bands_bw, int16_t *dtx_vad, const int32_t ivas_total_brate, const int16_t sba_inactive_mode -); +static void ivas_spar_dec_parse_md_bs_fx( ivas_spar_md_dec_state_t *hMdDec, Decoder_State *st, int16_t *nB, int16_t *bands_bw, int16_t *dtx_vad, const int32_t ivas_total_brate, const int16_t sba_inactive_mode ); #else -static void ivas_spar_dec_parse_md_bs( ivas_spar_md_dec_state_t *hMdDec, Decoder_State *st, int16_t *nB, int16_t *bands_bw, int16_t *dtx_vad, const int32_t ivas_total_brate, const int16_t sba_inactive_mode -); +static void ivas_spar_dec_parse_md_bs( ivas_spar_md_dec_state_t *hMdDec, Decoder_State *st, int16_t *nB, int16_t *bands_bw, int16_t *dtx_vad, const int32_t ivas_total_brate, const int16_t sba_inactive_mode ); #endif @@ -243,21 +241,21 @@ ivas_error ivas_spar_md_dec_matrix_open( if ( ( hMdDec->spar_coeffs_tar.C_re = (float ***) malloc( num_channels * sizeof( float ** ) ) ) == NULL ) { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix"); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for (i = 0; i < num_channels; i++) + for ( i = 0; i < num_channels; i++ ) { if ( ( hMdDec->spar_coeffs_tar.C_re[i] = (float **) malloc( num_channels * sizeof( float * ) ) ) == NULL ) - { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix"); - } - for (j = 0; j < num_channels; j++) - { - if ( ( hMdDec->spar_coeffs_tar.C_re[i][j] = (float *) malloc( IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix"); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); + } + for ( j = 0; j < num_channels; j++ ) + { + if ( ( hMdDec->spar_coeffs_tar.C_re[i][j] = (float *) malloc( IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); + } } - } } if ( ( hMdDec->spar_coeffs_tar.P_re = (float ***) malloc( num_channels * sizeof( float ** ) ) ) == NULL ) @@ -278,22 +276,22 @@ ivas_error ivas_spar_md_dec_matrix_open( } } } - for (i = 0; i < num_channels; i++) + for ( i = 0; i < num_channels; i++ ) { - for (j = 0; j < num_channels; j++) - { - for ( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) + for ( j = 0; j < num_channels; j++ ) { + for ( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) + { hMdDec->spar_coeffs_prev.C_re[i][j][k] = 0.0f; hMdDec->spar_coeffs_prev.P_re[i][j][k] = 0.0f; hMdDec->spar_coeffs_tar.C_re[i][j][k] = 0.0f; hMdDec->spar_coeffs_tar.P_re[i][j][k] = 0.0f; } } - } + } return IVAS_ERR_OK; - } +} #else ivas_error ivas_spar_md_dec_matrix_open_fx( @@ -301,149 +299,149 @@ ivas_error ivas_spar_md_dec_matrix_open_fx( const int16_t num_channels, /* i : number of internal channels */ const int16_t num_md_sub_frames /* i : number of MD subframes */ ) - { +{ int16_t i, j; int16_t k; if ( ( hMdDec->spar_md.band_coeffs = (ivas_band_coeffs_t *) malloc( IVAS_MAX_NUM_BANDS * num_md_sub_frames * sizeof( ivas_band_coeffs_t ) ) ) == NULL ) - { + { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for band_coeffs in SPAR MD" ); - } + } if ( ( hMdDec->band_coeffs_prev = (ivas_band_coeffs_t *) malloc( IVAS_MAX_NUM_BANDS * sizeof( ivas_band_coeffs_t ) ) ) == NULL ) - { + { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for band_coeffs in SPAR MD" ); } if ( ( hMdDec->mixer_mat_fx = (Word32 ***) malloc( num_channels * sizeof( Word32 ** ) ) ) == NULL ) { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix"); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for (i = 0; i < num_channels; i++) + for ( i = 0; i < num_channels; i++ ) { if ( ( hMdDec->mixer_mat_fx[i] = (Word32 **) malloc( num_channels * sizeof( Word32 * ) ) ) == NULL ) - { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix"); - } - for (j = 0; j < num_channels; j++) - { - if ( ( hMdDec->mixer_mat_fx[i][j] = (Word32 *) malloc( num_md_sub_frames * IVAS_MAX_NUM_BANDS * sizeof( Word32 ) ) ) == NULL ) { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix"); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); + } + for ( j = 0; j < num_channels; j++ ) + { + if ( ( hMdDec->mixer_mat_fx[i][j] = (Word32 *) malloc( num_md_sub_frames * IVAS_MAX_NUM_BANDS * sizeof( Word32 ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); + } } - } } - if ( ( hMdDec->spar_coeffs.C_re_fx = (Word32 ***) malloc( num_channels * sizeof(Word32 ** ) ) ) == NULL ) + if ( ( hMdDec->spar_coeffs.C_re_fx = (Word32 ***) malloc( num_channels * sizeof( Word32 ** ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } for ( i = 0; i < num_channels; i++ ) { - if ( ( hMdDec->spar_coeffs.C_re_fx[i] = (Word32 **) malloc( num_channels * sizeof(Word32 * ) ) ) == NULL ) + if ( ( hMdDec->spar_coeffs.C_re_fx[i] = (Word32 **) malloc( num_channels * sizeof( Word32 * ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } for ( j = 0; j < num_channels; j++ ) { - if ( ( hMdDec->spar_coeffs.C_re_fx[i][j] = (Word32 *) malloc( num_md_sub_frames * IVAS_MAX_NUM_BANDS * sizeof(Word32) ) ) == NULL ) + if ( ( hMdDec->spar_coeffs.C_re_fx[i][j] = (Word32 *) malloc( num_md_sub_frames * IVAS_MAX_NUM_BANDS * sizeof( Word32 ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } } } - if ( ( hMdDec->spar_coeffs.P_re_fx = (Word32 ***) malloc( num_channels * sizeof(Word32 ** ) ) ) == NULL ) + if ( ( hMdDec->spar_coeffs.P_re_fx = (Word32 ***) malloc( num_channels * sizeof( Word32 ** ) ) ) == NULL ) { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix"); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for (i = 0; i < num_channels; i++) + for ( i = 0; i < num_channels; i++ ) { - if ( ( hMdDec->spar_coeffs.P_re_fx[i] = (Word32 **) malloc( num_channels * sizeof(Word32 * ) ) ) == NULL ) - { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix"); - } - for (j = 0; j < num_channels; j++) - { - if ( ( hMdDec->spar_coeffs.P_re_fx[i][j] = (Word32 *) malloc( num_md_sub_frames * IVAS_MAX_NUM_BANDS * sizeof(Word32) ) ) == NULL ) + if ( ( hMdDec->spar_coeffs.P_re_fx[i] = (Word32 **) malloc( num_channels * sizeof( Word32 * ) ) ) == NULL ) { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix"); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); + } + for ( j = 0; j < num_channels; j++ ) + { + if ( ( hMdDec->spar_coeffs.P_re_fx[i][j] = (Word32 *) malloc( num_md_sub_frames * IVAS_MAX_NUM_BANDS * sizeof( Word32 ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); + } } - } } - if ((hMdDec->spar_coeffs_prev.C_re_fx = (Word32 ***)malloc(num_channels * sizeof(Word32 **))) == NULL) + if ( ( hMdDec->spar_coeffs_prev.C_re_fx = (Word32 ***) malloc( num_channels * sizeof( Word32 ** ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } for ( i = 0; i < num_channels; i++ ) { - if ((hMdDec->spar_coeffs_prev.C_re_fx[i] = (Word32 **)malloc(num_channels * sizeof(Word32 *))) == NULL) + if ( ( hMdDec->spar_coeffs_prev.C_re_fx[i] = (Word32 **) malloc( num_channels * sizeof( Word32 * ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } for ( j = 0; j < num_channels; j++ ) { - if ((hMdDec->spar_coeffs_prev.C_re_fx[i][j] = (Word32 *)malloc(IVAS_MAX_NUM_BANDS * sizeof(Word32))) == NULL) + if ( ( hMdDec->spar_coeffs_prev.C_re_fx[i][j] = (Word32 *) malloc( IVAS_MAX_NUM_BANDS * sizeof( Word32 ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } } } - //Fix Memory - if ((hMdDec->spar_coeffs_prev.P_re_fx = (Word32 ***)malloc(num_channels * sizeof(Word32 **))) == NULL) + // Fix Memory + if ( ( hMdDec->spar_coeffs_prev.P_re_fx = (Word32 ***) malloc( num_channels * sizeof( Word32 ** ) ) ) == NULL ) { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix"); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for (i = 0; i < num_channels; i++) + for ( i = 0; i < num_channels; i++ ) { - if ((hMdDec->spar_coeffs_prev.P_re_fx[i] = (Word32 **)malloc(num_channels * sizeof(Word32 *))) == NULL) - { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix"); - } - for (j = 0; j < num_channels; j++) - { - if ((hMdDec->spar_coeffs_prev.P_re_fx[i][j] = (Word32 *)malloc(IVAS_MAX_NUM_BANDS * sizeof(Word32))) == NULL) + if ( ( hMdDec->spar_coeffs_prev.P_re_fx[i] = (Word32 **) malloc( num_channels * sizeof( Word32 * ) ) ) == NULL ) { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix"); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); + } + for ( j = 0; j < num_channels; j++ ) + { + if ( ( hMdDec->spar_coeffs_prev.P_re_fx[i][j] = (Word32 *) malloc( IVAS_MAX_NUM_BANDS * sizeof( Word32 ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); + } } - } } - //Fix Memory - if ((hMdDec->spar_coeffs_tar.C_re_fx = (Word32 ***)malloc(num_channels * sizeof(Word32 **))) == NULL) + // Fix Memory + if ( ( hMdDec->spar_coeffs_tar.C_re_fx = (Word32 ***) malloc( num_channels * sizeof( Word32 ** ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } for ( i = 0; i < num_channels; i++ ) { - if ((hMdDec->spar_coeffs_tar.C_re_fx[i] = (Word32 **)malloc(num_channels * sizeof(Word32 *))) == NULL) + if ( ( hMdDec->spar_coeffs_tar.C_re_fx[i] = (Word32 **) malloc( num_channels * sizeof( Word32 * ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } for ( j = 0; j < num_channels; j++ ) { - if ((hMdDec->spar_coeffs_tar.C_re_fx[i][j] = (Word32 *)malloc(IVAS_MAX_NUM_BANDS * sizeof(Word32))) == NULL) + if ( ( hMdDec->spar_coeffs_tar.C_re_fx[i][j] = (Word32 *) malloc( IVAS_MAX_NUM_BANDS * sizeof( Word32 ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } } } - //Fix Memory - if ((hMdDec->spar_coeffs_tar.P_re_fx = (Word32 ***)malloc(num_channels * sizeof(Word32 **))) == NULL) + // Fix Memory + if ( ( hMdDec->spar_coeffs_tar.P_re_fx = (Word32 ***) malloc( num_channels * sizeof( Word32 ** ) ) ) == NULL ) { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix"); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for (i = 0; i < num_channels; i++) + for ( i = 0; i < num_channels; i++ ) { - if ((hMdDec->spar_coeffs_tar.P_re_fx[i] = (Word32 **)malloc(num_channels * sizeof(Word32 *))) == NULL) - { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix"); - } - for (j = 0; j < num_channels; j++) - { - if ((hMdDec->spar_coeffs_tar.P_re_fx[i][j] = (Word32 *)malloc(IVAS_MAX_NUM_BANDS * sizeof(Word32))) == NULL) + if ( ( hMdDec->spar_coeffs_tar.P_re_fx[i] = (Word32 **) malloc( num_channels * sizeof( Word32 * ) ) ) == NULL ) { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix"); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); + } + for ( j = 0; j < num_channels; j++ ) + { + if ( ( hMdDec->spar_coeffs_tar.P_re_fx[i][j] = (Word32 *) malloc( IVAS_MAX_NUM_BANDS * sizeof( Word32 ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); + } } - } } for ( i = 0; i < num_channels; i++ ) @@ -687,16 +685,16 @@ void ivas_spar_md_dec_matrix_close( if ( hMdDecoder->spar_coeffs_tar.C_re != NULL ) { - for (i = 0; i < num_channels; i++) - { - for (j = 0; j < num_channels; j++) + for ( i = 0; i < num_channels; i++ ) { + for ( j = 0; j < num_channels; j++ ) + { free( hMdDecoder->spar_coeffs_tar.C_re[i][j] ); - } + } free( hMdDecoder->spar_coeffs_tar.C_re[i] ); } free( hMdDecoder->spar_coeffs_tar.C_re ); - } + } if ( hMdDecoder->spar_coeffs_tar.P_re != NULL ) { @@ -719,19 +717,19 @@ void ivas_spar_md_dec_matrix_close_fx( ivas_spar_md_dec_state_t *hMdDecoder, /* i/o: SPAR MD decoder handle */ const int16_t num_channels /* i : number of internal channels */ ) - { +{ int16_t i, j; if ( hMdDecoder->spar_md.band_coeffs != NULL ) - { + { free( hMdDecoder->spar_md.band_coeffs ); hMdDecoder->spar_md.band_coeffs = NULL; - } + } if ( hMdDecoder->band_coeffs_prev != NULL ) { free( hMdDecoder->band_coeffs_prev ); hMdDecoder->band_coeffs_prev = NULL; - } + } if ( hMdDecoder->mixer_mat_fx != NULL ) { @@ -747,14 +745,14 @@ void ivas_spar_md_dec_matrix_close_fx( } if ( hMdDecoder->spar_coeffs.C_re_fx != NULL ) { - for (i = 0; i < num_channels; i++) - { - for (j = 0; j < num_channels; j++) + for ( i = 0; i < num_channels; i++ ) { + for ( j = 0; j < num_channels; j++ ) + { free( hMdDecoder->spar_coeffs.C_re_fx[i][j] ); - } + } free( hMdDecoder->spar_coeffs.C_re_fx[i] ); - } + } free( hMdDecoder->spar_coeffs.C_re_fx ); } if ( hMdDecoder->spar_coeffs.P_re_fx != NULL ) @@ -770,55 +768,55 @@ void ivas_spar_md_dec_matrix_close_fx( free( hMdDecoder->spar_coeffs.P_re_fx ); } - if (hMdDecoder->spar_coeffs_prev.C_re_fx != NULL) + if ( hMdDecoder->spar_coeffs_prev.C_re_fx != NULL ) { - for (i = 0; i < num_channels; i++) - { - for (j = 0; j < num_channels; j++) + for ( i = 0; i < num_channels; i++ ) { - free(hMdDecoder->spar_coeffs_prev.C_re_fx[i][j]); + for ( j = 0; j < num_channels; j++ ) + { + free( hMdDecoder->spar_coeffs_prev.C_re_fx[i][j] ); + } + free( hMdDecoder->spar_coeffs_prev.C_re_fx[i] ); } - free(hMdDecoder->spar_coeffs_prev.C_re_fx[i]); - } - free(hMdDecoder->spar_coeffs_prev.C_re_fx); + free( hMdDecoder->spar_coeffs_prev.C_re_fx ); } - if (hMdDecoder->spar_coeffs_prev.P_re_fx != NULL) + if ( hMdDecoder->spar_coeffs_prev.P_re_fx != NULL ) { for ( i = 0; i < num_channels; i++ ) { for ( j = 0; j < num_channels; j++ ) { - free(hMdDecoder->spar_coeffs_prev.P_re_fx[i][j]); + free( hMdDecoder->spar_coeffs_prev.P_re_fx[i][j] ); } - free(hMdDecoder->spar_coeffs_prev.P_re_fx[i]); + free( hMdDecoder->spar_coeffs_prev.P_re_fx[i] ); } - free(hMdDecoder->spar_coeffs_prev.P_re_fx); + free( hMdDecoder->spar_coeffs_prev.P_re_fx ); } - if (hMdDecoder->spar_coeffs_tar.C_re_fx != NULL) + if ( hMdDecoder->spar_coeffs_tar.C_re_fx != NULL ) { - for (i = 0; i < num_channels; i++) - { - for (j = 0; j < num_channels; j++) + for ( i = 0; i < num_channels; i++ ) { - free(hMdDecoder->spar_coeffs_tar.C_re_fx[i][j]); + for ( j = 0; j < num_channels; j++ ) + { + free( hMdDecoder->spar_coeffs_tar.C_re_fx[i][j] ); + } + free( hMdDecoder->spar_coeffs_tar.C_re_fx[i] ); } - free(hMdDecoder->spar_coeffs_tar.C_re_fx[i]); - } - free(hMdDecoder->spar_coeffs_tar.C_re_fx); + free( hMdDecoder->spar_coeffs_tar.C_re_fx ); } - if (hMdDecoder->spar_coeffs_tar.P_re_fx != NULL) + if ( hMdDecoder->spar_coeffs_tar.P_re_fx != NULL ) { - for (i = 0; i < num_channels; i++) - { - for (j = 0; j < num_channels; j++) + for ( i = 0; i < num_channels; i++ ) { - free(hMdDecoder->spar_coeffs_tar.P_re_fx[i][j]); + for ( j = 0; j < num_channels; j++ ) + { + free( hMdDecoder->spar_coeffs_tar.P_re_fx[i][j] ); + } + free( hMdDecoder->spar_coeffs_tar.P_re_fx[i] ); } - free(hMdDecoder->spar_coeffs_tar.P_re_fx[i]); - } - free(hMdDecoder->spar_coeffs_tar.P_re_fx); + free( hMdDecoder->spar_coeffs_tar.P_re_fx ); } return; @@ -893,7 +891,7 @@ ivas_error ivas_spar_md_dec_init( { pFC[i] = ivas_fb_fcs_12band_1ms[i] * hDecoderConfig->output_Fs * 0.5f; } - + if ( ( error = ivas_spar_set_dec_config( hMdDec, nchan_transport, pFC ) ) != IVAS_ERR_OK ) { return error; @@ -953,71 +951,71 @@ ivas_error ivas_spar_md_dec_init( } #else /*-----------------------------------------------------------------------------------------* -* Function ivas_spar_md_dec_init() -* -* SPAR MD decoder initialization -*-----------------------------------------------------------------------------------------*/ + * Function ivas_spar_md_dec_init() + * + * SPAR MD decoder initialization + *-----------------------------------------------------------------------------------------*/ ivas_error ivas_spar_md_dec_init( - ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ - const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ - const int16_t num_channels, /* i : number of internal channels */ - const int16_t sba_order /* i : SBA order */ + ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ + const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ + const int16_t num_channels, /* i : number of internal channels */ + const int16_t sba_order /* i : SBA order */ ) { - int16_t i, j; - int16_t nchan_transport; + int16_t i, j; + int16_t nchan_transport; #ifndef IVAS_FLOAT_FIXED - Word32 pFC[IVAS_MAX_NUM_BANDS]; + Word32 pFC[IVAS_MAX_NUM_BANDS]; #endif - Word32 *pFC_fx=NULL, PR_minmax_fx[2]; - ivas_error error; + Word32 *pFC_fx = NULL, PR_minmax_fx[2]; + ivas_error error; - ivas_sba_get_spar_hoa_md_flag( sba_order, hDecoderConfig->ivas_total_brate, &hMdDec->spar_hoa_md_flag, &hMdDec->spar_hoa_dirac2spar_md_flag ); + ivas_sba_get_spar_hoa_md_flag( sba_order, hDecoderConfig->ivas_total_brate, &hMdDec->spar_hoa_md_flag, &hMdDec->spar_hoa_dirac2spar_md_flag ); - ivas_sba_get_spar_hoa_ch_ind( num_channels, hDecoderConfig->ivas_total_brate, hMdDec->HOA_md_ind ); + ivas_sba_get_spar_hoa_ch_ind( num_channels, hDecoderConfig->ivas_total_brate, hMdDec->HOA_md_ind ); - hMdDec->spar_md.num_bands = ( hMdDec->spar_hoa_md_flag ) ? IVAS_MAX_NUM_BANDS : min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND ); - - ivas_spar_set_bitrate_config_fx(&hMdDec->spar_md_cfg, hMdDec->table_idx, hMdDec->spar_md.num_bands, hMdDec->spar_hoa_dirac2spar_md_flag, 0, 0, 0 ); - - nchan_transport = hMdDec->spar_md_cfg.nchan_transport; + hMdDec->spar_md.num_bands = ( hMdDec->spar_hoa_md_flag ) ? IVAS_MAX_NUM_BANDS : min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND ); + + ivas_spar_set_bitrate_config_fx( &hMdDec->spar_md_cfg, hMdDec->table_idx, hMdDec->spar_md.num_bands, hMdDec->spar_hoa_dirac2spar_md_flag, 0, 0, 0 ); + + nchan_transport = hMdDec->spar_md_cfg.nchan_transport; #ifndef IVAS_FLOAT_FIXED - /* get FB coefficients */ - FOR (i = 0; i < IVAS_MAX_NUM_BANDS; i++) - { - pFC[i] = L_shr(Mpy_32_32(ivas_fb_fcs_12band_1ms_fx[i], hDecoderConfig->output_Fs), 1); //Q0 - } + /* get FB coefficients */ + FOR( i = 0; i < IVAS_MAX_NUM_BANDS; i++ ) + { + pFC[i] = L_shr( Mpy_32_32( ivas_fb_fcs_12band_1ms_fx[i], hDecoderConfig->output_Fs ), 1 ); // Q0 + } #endif - - IF (EQ_32 (hDecoderConfig->output_Fs, 8000)) + + IF( EQ_32( hDecoderConfig->output_Fs, 8000 ) ) { pFC_fx = pFC_8k; } - ELSE IF(EQ_32(hDecoderConfig->output_Fs, 12800)) + ELSE IF( EQ_32( hDecoderConfig->output_Fs, 12800 ) ) { - pFC_fx = pFC_12k; + pFC_fx = pFC_12k; } - ELSE IF (EQ_32(hDecoderConfig->output_Fs, 16000)) + ELSE IF( EQ_32( hDecoderConfig->output_Fs, 16000 ) ) { - pFC_fx = pFC_16k; + pFC_fx = pFC_16k; } - ELSE IF (EQ_32(hDecoderConfig->output_Fs, 32000)) + ELSE IF( EQ_32( hDecoderConfig->output_Fs, 32000 ) ) { - pFC_fx = pFC_32k; + pFC_fx = pFC_32k; } - ELSE IF (EQ_32(hDecoderConfig->output_Fs, 48000)) + ELSE IF( EQ_32( hDecoderConfig->output_Fs, 48000 ) ) { - pFC_fx = pFC_48k; + pFC_fx = pFC_48k; } else { - assert(0);//update sample rate + assert( 0 ); // update sample rate } #ifdef IVAS_FLOAT_FIXED - if ( ( error = ivas_spar_set_dec_config( hMdDec, nchan_transport, pFC_fx) ) != IVAS_ERR_OK ) + if ( ( error = ivas_spar_set_dec_config( hMdDec, nchan_transport, pFC_fx ) ) != IVAS_ERR_OK ) #else if ( ( error = ivas_spar_set_dec_config( hMdDec, nchan_transport, pFC ) ) != IVAS_ERR_OK ) #endif @@ -1052,8 +1050,8 @@ ivas_error ivas_spar_md_dec_init( ivas_clear_band_coeffs( hMdDec->spar_md.band_coeffs, IVAS_MAX_NUM_BANDS ); ivas_clear_band_coeffs( hMdDec->band_coeffs_prev, IVAS_MAX_NUM_BANDS ); #else - ivas_clear_band_coeffs_fx( hMdDec->spar_md.band_coeffs, IVAS_MAX_NUM_BANDS ); - ivas_clear_band_coeffs_fx( hMdDec->band_coeffs_prev, IVAS_MAX_NUM_BANDS ); + ivas_clear_band_coeffs_fx( hMdDec->spar_md.band_coeffs, IVAS_MAX_NUM_BANDS ); + ivas_clear_band_coeffs_fx( hMdDec->band_coeffs_prev, IVAS_MAX_NUM_BANDS ); #endif ivas_clear_band_coeff_idx( hMdDec->spar_md.band_coeffs_idx, IVAS_MAX_NUM_BANDS ); ivas_clear_band_coeff_idx( hMdDec->spar_md_prev.band_coeffs_idx, IVAS_MAX_NUM_BANDS ); @@ -1062,21 +1060,21 @@ ivas_error ivas_spar_md_dec_init( hMdDec->spar_md.dtx_vad = 0; hMdDec->td_decorr_flag = 1; - + set32_fx( hMdDec->spar_md.en_ratio_slow_fx, 0, IVAS_MAX_NUM_BANDS ); set32_fx( hMdDec->spar_md.ref_pow_slow_fx, 0, IVAS_MAX_NUM_BANDS ); - set16_fx( hMdDec->smooth_fac_fx,0, IVAS_MAX_NUM_BANDS ); + set16_fx( hMdDec->smooth_fac_fx, 0, IVAS_MAX_NUM_BANDS ); #ifndef IVAS_FLOAT_FIXED - set_f( hMdDec->spar_md.en_ratio_slow, 0.0f, IVAS_MAX_NUM_BANDS ); - set_f( hMdDec->spar_md.ref_pow_slow, 0.0f, IVAS_MAX_NUM_BANDS ); + set_f( hMdDec->spar_md.en_ratio_slow, 0.0f, IVAS_MAX_NUM_BANDS ); + set_f( hMdDec->spar_md.ref_pow_slow, 0.0f, IVAS_MAX_NUM_BANDS ); set_zero( hMdDec->smooth_fac, IVAS_MAX_NUM_BANDS ); #endif for ( i = 0; i < IVAS_MAX_NUM_BANDS; i++ ) { - set32_fx(hMdDec->smooth_buf_fx[i], 0, 2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1); + set32_fx( hMdDec->smooth_buf_fx[i], 0, 2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1 ); #ifndef IVAS_FLOAT_FIXED - set_zero( hMdDec->smooth_buf[i], 2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1 ); + set_zero( hMdDec->smooth_buf[i], 2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1 ); #endif } @@ -1084,9 +1082,9 @@ ivas_error ivas_spar_md_dec_init( { for ( j = 0; j < IVAS_SPAR_MAX_CH; j++ ) { - set32_fx(hMdDec->mixer_mat_prev2_fx[i][j], 0, IVAS_MAX_NUM_BANDS); -#ifndef IVAS_FLOAT_FIXED - set_zero( hMdDec->mixer_mat_prev2[i][j], IVAS_MAX_NUM_BANDS ); + set32_fx( hMdDec->mixer_mat_prev2_fx[i][j], 0, IVAS_MAX_NUM_BANDS ); +#ifndef IVAS_FLOAT_FIXED + set_zero( hMdDec->mixer_mat_prev2[i][j], IVAS_MAX_NUM_BANDS ); #endif } } @@ -1095,7 +1093,7 @@ ivas_error ivas_spar_md_dec_init( return IVAS_ERR_OK; } -#endif +#endif /*-----------------------------------------------------------------------------------------* @@ -1107,7 +1105,7 @@ ivas_error ivas_spar_md_dec_init( static ivas_error ivas_spar_set_dec_config( ivas_spar_md_dec_state_t *hMdDec, const int16_t nchan_transport, - Word32 *pFC ) + Word32 *pFC ) { int16_t i, j, nchan, dmx_ch; @@ -1227,7 +1225,7 @@ static void ivas_dec_mono_sba_handling( mono_flag = 1; - FOR ( b = 0; b < st_ivas->hQMetaData->q_direction[0].cfg.nbands; b++ ) + FOR( b = 0; b < st_ivas->hQMetaData->q_direction[0].cfg.nbands; b++ ) { FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; ++block ) { @@ -1272,7 +1270,7 @@ static void ivas_dec_mono_sba_handling( return; } -#else +#else static void ivas_dec_mono_sba_handling_fx( Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ ) @@ -1345,8 +1343,8 @@ static void ivas_dec_mono_sba_handling_fx( *-----------------------------------------------------------------------------------------*/ void ivas_spar_md_dec_process_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling */ const Word16 num_bands_out, /* i : number of output bands */ const Word16 sba_order /* i : Ambisonic (SBA) order */ ) @@ -1367,20 +1365,21 @@ void ivas_spar_md_dec_process_fx( num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( sba_order, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ); test(); - IF ( GT_16(hMdDec->spar_md_cfg.nchan_transport , 1) && LE_16(hMdDec->spar_md_cfg.nchan_transport , 3) ) + IF( GT_16( hMdDec->spar_md_cfg.nchan_transport, 1 ) && LE_16( hMdDec->spar_md_cfg.nchan_transport, 3 ) ) { - hMdDec->spar_md.res_ind = 0; move16(); + hMdDec->spar_md.res_ind = 0; + move16(); dyn_active_w_flag = get_next_indice_fx( st0, 1 ); - IF ( EQ_16(dyn_active_w_flag , 1) ) + IF( EQ_16( dyn_active_w_flag, 1 ) ) { - IF ( EQ_16(hMdDec->spar_md_cfg.nchan_transport , 2) ) + IF( EQ_16( hMdDec->spar_md_cfg.nchan_transport, 2 ) ) { hMdDec->spar_md.res_ind = get_next_indice_fx( st0, 1 ); move16(); - hMdDec->spar_md.res_ind = add(hMdDec->spar_md_cfg.nchan_transport, hMdDec->spar_md.res_ind); + hMdDec->spar_md.res_ind = add( hMdDec->spar_md_cfg.nchan_transport, hMdDec->spar_md.res_ind ); move16(); } - ELSE IF ( EQ_16(hMdDec->spar_md_cfg.nchan_transport , 3) ) + ELSE IF( EQ_16( hMdDec->spar_md_cfg.nchan_transport, 3 ) ) { hMdDec->spar_md.res_ind = remix_order_set[hMdDec->spar_md_cfg.remix_unmix_order][hMdDec->spar_md_cfg.nchan_transport]; move16(); @@ -1391,13 +1390,13 @@ void ivas_spar_md_dec_process_fx( { dyn_active_w_flag = 0; move16(); - IF ( EQ_16(hMdDec->spar_md_cfg.nchan_transport , FOA_CHANNELS) ) + IF( EQ_16( hMdDec->spar_md_cfg.nchan_transport, FOA_CHANNELS ) ) { get_next_indice_fx( st0, 1 ); } } -#if 0 //ndef IVAS_FLOAT_FIXED_TO_BE_REMOVED +#if 0 // ndef IVAS_FLOAT_FIXED_TO_BE_REMOVED FOR (Word16 i = 0; i < IVAS_MAX_NUM_BANDS; i++) { FOR (Word16 ii = 0; ii < IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS; ii++) @@ -1415,8 +1414,7 @@ void ivas_spar_md_dec_process_fx( } #endif ivas_spar_dec_parse_md_bs_fx( hMdDec, st0, &nB, &bw, &dtx_vad, st_ivas->hDecoderConfig->ivas_total_brate, - st_ivas->hQMetaData->sba_inactive_mode - ); + st_ivas->hQMetaData->sba_inactive_mode ); assert( nB == hMdDec->spar_md.num_bands ); assert( bw == 1 ); @@ -1427,7 +1425,7 @@ void ivas_spar_md_dec_process_fx( &hMdDec->base_band_coeffs_age[0], &hMdDec->first_valid_frame, nB ); -#if 0 //ndef IVAS_FLOAT_FIXED_TO_BE_REMOVED +#if 0 // ndef IVAS_FLOAT_FIXED_TO_BE_REMOVED for (int i = 0; i < IVAS_MAX_NUM_BANDS; i++) { for (int ii = 0; ii < IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS; ii++) @@ -1447,7 +1445,7 @@ void ivas_spar_md_dec_process_fx( ivas_dec_mono_sba_handling_fx( st_ivas ); /* SPAR to DirAC conversion */ - IF ( EQ_16(hMdDec->spar_hoa_dirac2spar_md_flag , 1) ) + IF( EQ_16( hMdDec->spar_hoa_dirac2spar_md_flag, 1 ) ) { ivas_spar_to_dirac_fx( st_ivas, hMdDec, dtx_vad, num_bands_out, bw, dyn_active_w_flag ); } @@ -1463,7 +1461,7 @@ void ivas_spar_md_dec_process_fx( { for ( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) { -#if 0 //ndef IVAS_FLOAT_FIXED_TO_BE_REMOVED +#if 0 // ndef IVAS_FLOAT_FIXED_TO_BE_REMOVED hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re[j] = hMdDec->spar_md.band_coeffs[b].pred_re[j]; #endif hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re_fx[j] = hMdDec->spar_md.band_coeffs[b].pred_re_fx[j]; @@ -1474,7 +1472,7 @@ void ivas_spar_md_dec_process_fx( { for ( k = 0; k < IVAS_SPAR_MAX_DMX_CHS - 1; k++ ) { -#if 0 //ndef IVAS_FLOAT_FIXED_TO_BE_REMOVED +#if 0 // ndef IVAS_FLOAT_FIXED_TO_BE_REMOVED hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].C_re[j][k] = hMdDec->spar_md.band_coeffs[b].C_re[j][k]; #endif hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].C_re_fx[j][k] = hMdDec->spar_md.band_coeffs[b].C_re_fx[j][k]; @@ -1484,7 +1482,7 @@ void ivas_spar_md_dec_process_fx( for ( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) { -#if 0 //ndef IVAS_FLOAT_FIXED_TO_BE_REMOVED +#if 0 // ndef IVAS_FLOAT_FIXED_TO_BE_REMOVED hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].P_re[j] = hMdDec->spar_md.band_coeffs[b].P_re[j]; #endif hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].P_re_fx[j] = hMdDec->spar_md.band_coeffs[b].P_re_fx[j]; @@ -1521,122 +1519,121 @@ void ivas_spar_md_dec_process_fx( *-----------------------------------------------------------------------------------------*/ void ivas_spar_md_dec_process( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling */ - const int16_t num_bands_out, /* i : number of output bands */ - const int16_t sba_order /* i : Ambisonic (SBA) order */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling */ + const int16_t num_bands_out, /* i : number of output bands */ + const int16_t sba_order /* i : Ambisonic (SBA) order */ ) { - int16_t j, k, b, bw, dtx_vad, nB, i_ts; - ivas_spar_md_dec_state_t *hMdDec; - int16_t num_md_chs; - int16_t num_md_sub_frames; - int16_t dyn_active_w_flag; - int16_t active_w_vlbr; + int16_t j, k, b, bw, dtx_vad, nB, i_ts; + ivas_spar_md_dec_state_t *hMdDec; + int16_t num_md_chs; + int16_t num_md_sub_frames; + int16_t dyn_active_w_flag; + int16_t active_w_vlbr; - hMdDec = st_ivas->hSpar->hMdDec; + hMdDec = st_ivas->hSpar->hMdDec; - active_w_vlbr = (st_ivas->hDecoderConfig->ivas_total_brate < IVAS_24k4) ? 1 : 0; + active_w_vlbr = ( st_ivas->hDecoderConfig->ivas_total_brate < IVAS_24k4 ) ? 1 : 0; - num_md_chs = ivas_sba_get_nchan_metadata(sba_order, st_ivas->hDecoderConfig->ivas_total_brate); + num_md_chs = ivas_sba_get_nchan_metadata( sba_order, st_ivas->hDecoderConfig->ivas_total_brate ); - num_md_sub_frames = ivas_get_spar_dec_md_num_subframes(sba_order, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate); + num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( sba_order, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ); - if (hMdDec->spar_md_cfg.nchan_transport > 1 && hMdDec->spar_md_cfg.nchan_transport <= 3) - { - hMdDec->spar_md.res_ind = 0; - dyn_active_w_flag = get_next_indice(st0, 1); - if (dyn_active_w_flag == 1) + if ( hMdDec->spar_md_cfg.nchan_transport > 1 && hMdDec->spar_md_cfg.nchan_transport <= 3 ) { - if (hMdDec->spar_md_cfg.nchan_transport == 2) - { - hMdDec->spar_md.res_ind = get_next_indice(st0, 1); - hMdDec->spar_md.res_ind += hMdDec->spar_md_cfg.nchan_transport; - } - else if (hMdDec->spar_md_cfg.nchan_transport == 3) - { - hMdDec->spar_md.res_ind = remix_order_set[hMdDec->spar_md_cfg.remix_unmix_order][hMdDec->spar_md_cfg.nchan_transport]; - } + hMdDec->spar_md.res_ind = 0; + dyn_active_w_flag = get_next_indice( st0, 1 ); + if ( dyn_active_w_flag == 1 ) + { + if ( hMdDec->spar_md_cfg.nchan_transport == 2 ) + { + hMdDec->spar_md.res_ind = get_next_indice( st0, 1 ); + hMdDec->spar_md.res_ind += hMdDec->spar_md_cfg.nchan_transport; + } + else if ( hMdDec->spar_md_cfg.nchan_transport == 3 ) + { + hMdDec->spar_md.res_ind = remix_order_set[hMdDec->spar_md_cfg.remix_unmix_order][hMdDec->spar_md_cfg.nchan_transport]; + } + } } - } - else - { - dyn_active_w_flag = 0; - if (hMdDec->spar_md_cfg.nchan_transport == FOA_CHANNELS) + else { - get_next_indice(st0, 1); + dyn_active_w_flag = 0; + if ( hMdDec->spar_md_cfg.nchan_transport == FOA_CHANNELS ) + { + get_next_indice( st0, 1 ); + } } - } - ivas_spar_dec_parse_md_bs(hMdDec, st0, &nB, &bw, &dtx_vad, st_ivas->hDecoderConfig->ivas_total_brate, - st_ivas->hQMetaData->sba_inactive_mode - ); + ivas_spar_dec_parse_md_bs( hMdDec, st0, &nB, &bw, &dtx_vad, st_ivas->hDecoderConfig->ivas_total_brate, + st_ivas->hQMetaData->sba_inactive_mode ); - assert(nB == hMdDec->spar_md.num_bands); - assert(bw == 1); - ivas_spar_md_fill_invalid_bandcoeffs( - hMdDec->spar_md.band_coeffs, - hMdDec->band_coeffs_prev, - &hMdDec->valid_bands[0], - &hMdDec->base_band_coeffs_age[0], - &hMdDec->first_valid_frame, - nB); + assert( nB == hMdDec->spar_md.num_bands ); + assert( bw == 1 ); + ivas_spar_md_fill_invalid_bandcoeffs( + hMdDec->spar_md.band_coeffs, + hMdDec->band_coeffs_prev, + &hMdDec->valid_bands[0], + &hMdDec->base_band_coeffs_age[0], + &hMdDec->first_valid_frame, + nB ); - ivas_dec_mono_sba_handling(st_ivas); + ivas_dec_mono_sba_handling( st_ivas ); - /* SPAR to DirAC conversion */ - if (hMdDec->spar_hoa_dirac2spar_md_flag == 1) - { - ivas_spar_to_dirac(st_ivas, hMdDec, dtx_vad, num_bands_out, bw, dyn_active_w_flag); - } + /* SPAR to DirAC conversion */ + if ( hMdDec->spar_hoa_dirac2spar_md_flag == 1 ) + { + ivas_spar_to_dirac( st_ivas, hMdDec, dtx_vad, num_bands_out, bw, dyn_active_w_flag ); + } - /* set correct number of bands*/ - nB = IVAS_MAX_NUM_BANDS; + /* set correct number of bands*/ + nB = IVAS_MAX_NUM_BANDS; - /* expand DirAC MD to all time slots */ - for (i_ts = 1; i_ts < num_md_sub_frames; i_ts++) - { - for (b = 0; b < hMdDec->spar_md.num_bands; b++) + /* expand DirAC MD to all time slots */ + for ( i_ts = 1; i_ts < num_md_sub_frames; i_ts++ ) { - for (j = 0; j < IVAS_SPAR_MAX_CH - 1; j++) - { - hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re[j] = hMdDec->spar_md.band_coeffs[b].pred_re[j]; - } - - for (j = 0; j < IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS; j++) - { - for (k = 0; k < IVAS_SPAR_MAX_DMX_CHS - 1; k++) + for ( b = 0; b < hMdDec->spar_md.num_bands; b++ ) { - hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].C_re[j][k] = hMdDec->spar_md.band_coeffs[b].C_re[j][k]; - } - } + for ( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) + { + hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re[j] = hMdDec->spar_md.band_coeffs[b].pred_re[j]; + } - for (j = 0; j < IVAS_SPAR_MAX_CH - 1; j++) - { - hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].P_re[j] = hMdDec->spar_md.band_coeffs[b].P_re[j]; - } + for ( j = 0; j < IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS; j++ ) + { + for ( k = 0; k < IVAS_SPAR_MAX_DMX_CHS - 1; k++ ) + { + hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].C_re[j][k] = hMdDec->spar_md.band_coeffs[b].C_re[j][k]; + } + } + + for ( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) + { + hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].P_re[j] = hMdDec->spar_md.band_coeffs[b].P_re[j]; + } + } } - } - ivas_get_spar_matrices(hMdDec, num_bands_out, num_md_sub_frames, bw, dtx_vad, nB, num_md_chs, active_w_vlbr, dyn_active_w_flag); + ivas_get_spar_matrices( hMdDec, num_bands_out, num_md_sub_frames, bw, dtx_vad, nB, num_md_chs, active_w_vlbr, dyn_active_w_flag ); #ifdef DEBUG_SPAR_DIRAC_WRITE_OUT_PRED_PARS - { - static FILE *fid = 0; - int16_t band = 9; - if (!fid) { - fid = fopen("pred_coeffs_dec.txt", "wt"); + static FILE *fid = 0; + int16_t band = 9; + if ( !fid ) + { + fid = fopen( "pred_coeffs_dec.txt", "wt" ); + } + fprintf( fid, "%.6f\n", hMdDec->mixer_mat[1][0][band] ); } - fprintf(fid, "%.6f\n", hMdDec->mixer_mat[1][0][band]); - } #endif - ivas_spar_md_fill_invalid_bands(&hMdDec->spar_coeffs, &hMdDec->spar_coeffs_prev, &hMdDec->valid_bands[0], &hMdDec->base_band_age[0], num_bands_out, num_md_chs, num_md_sub_frames); + ivas_spar_md_fill_invalid_bands( &hMdDec->spar_coeffs, &hMdDec->spar_coeffs_prev, &hMdDec->valid_bands[0], &hMdDec->base_band_age[0], num_bands_out, num_md_chs, num_md_sub_frames ); - hMdDec->dtx_md_smoothing_cntr = 1; + hMdDec->dtx_md_smoothing_cntr = 1; - return; + return; } #endif @@ -1774,7 +1771,7 @@ void ivas_spar_smooth_md_dtx_fx( tar_fx = hMdDec->spar_coeffs_tar.P_re_fx[j][k][b]; /* Q22 */ move32(); new_val_fx = L_add( prev_fx, Mpy_32_16_1( L_sub( tar_fx, prev_fx ), ramp_fx ) ); /* Q22 + Q15 - Q15 = Q22*/ - hMdDec->spar_coeffs.P_re_fx[j][k][b] = new_val_fx; /* Q22 */ + hMdDec->spar_coeffs.P_re_fx[j][k][b] = new_val_fx; /* Q22 */ move32(); } } @@ -1788,7 +1785,7 @@ void ivas_spar_smooth_md_dtx_fx( tar_fx = hMdDec->spar_coeffs_tar.C_re_fx[j][k][b]; /* Q22 */ move32(); new_val_fx = L_add( prev_fx, Mpy_32_16_1( L_sub( tar_fx, prev_fx ), ramp_fx ) ); /* Q22 + Q15 - Q15 = Q22*/ - hMdDec->spar_coeffs.C_re_fx[j][k][b] = new_val_fx; /* Q22 */ + hMdDec->spar_coeffs.C_re_fx[j][k][b] = new_val_fx; /* Q22 */ move32(); } } @@ -2390,258 +2387,258 @@ static void ivas_get_spar_matrices( #else static void ivas_get_spar_matrices_fx( - ivas_spar_md_dec_state_t *hMdDec, - const int16_t num_bands_out, - const int16_t n_ts, - const int16_t bw, - const int16_t dtx_vad, - const int16_t nB, - const int16_t numch_out, - const int16_t active_w_vlbr, - const int16_t dyn_active_w_flag ) + ivas_spar_md_dec_state_t *hMdDec, + const int16_t num_bands_out, + const int16_t n_ts, + const int16_t bw, + const int16_t dtx_vad, + const int16_t nB, + const int16_t numch_out, + const int16_t active_w_vlbr, + const int16_t dyn_active_w_flag ) { - Word16 num_bands, dmx_ch, split_band; - Word16 i, j, k, m, b, i_ts, active_w; - const Word16 *order; - Word32 active_w_dm_fac_fx, re_fx,re_fx1; - - num_bands = num_bands_out; - order = remix_order_set[hMdDec->spar_md_cfg.remix_unmix_order]; - - split_band = SPAR_DIRAC_SPLIT_START_BAND; - - //Dead code as SPAR_DIRAC_SPLIT_START_BAND = 8 and IVAS_MAX_NUM_BANDS = 12 - IF( GE_16( split_band, IVAS_MAX_NUM_BANDS ) ) - { - /*store previous 4x4 parameters for linear interpolation to current*/ - - FOR( i = 0; i < numch_out; i++ ) - { - FOR( j = 0; j < numch_out; j++ ) - { - FOR( b = 0; b < num_bands; b++ ) - { - hMdDec->mixer_mat_prev_fx[0][i][j][b] = hMdDec->mixer_mat_fx[i][j][b]; - move32(); - } - } - } - } - - IF( bw == IVAS_RED_BAND_FACT ) - { - num_bands = shl( num_bands, 1 ); - } - - active_w = EQ_16( dyn_active_w_flag, 1 ) || EQ_16( hMdDec->spar_md_cfg.active_w, 1 ); - active_w_dm_fac_fx = EQ_16( dtx_vad, 0 ) ? IVAS_ACTIVEW_DM_F_SCALE_DTX_FX : ( EQ_16( active_w_vlbr, 1 ) ? IVAS_ACTIVEW_DM_F_SCALE_VLBR_FX : IVAS_ACTIVEW_DM_F_SCALE_FX ); - - move16(); - FOR( i_ts = 0; i_ts < n_ts; i_ts++ ) - { - FOR( i = 0; i < numch_out; i++ ) - { - FOR( j = 0; j < numch_out; j++ ) - { - - set32_fx( &hMdDec->spar_coeffs.C_re_fx[i][j][i_ts * IVAS_MAX_NUM_BANDS], 0, IVAS_MAX_NUM_BANDS ); - set32_fx( &hMdDec->spar_coeffs.P_re_fx[i][j][i_ts * IVAS_MAX_NUM_BANDS], 0, IVAS_MAX_NUM_BANDS ); - } - } - num_bands = min( num_bands, nB ); - - FOR( b = 0; b < num_bands; b++ ) - { - Word32 tmp_C1_re_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; - Word32 tmp_C2_re_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; - Word32 tmp_dm_re_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; - dmx_ch = hMdDec->spar_md_cfg.num_dmx_chans_per_band[bw * b]; - - FOR( j = 0; j < numch_out; j++ ) - { - set_zero_fx( tmp_C1_re_fx[j], numch_out ); - set_zero_fx( tmp_C2_re_fx[j], numch_out ); - set_zero_fx( tmp_dm_re_fx[j], numch_out ); - - tmp_C1_re_fx[j][j] = ONE_IN_Q22; - tmp_C2_re_fx[j][j] = ONE_IN_Q22; - tmp_dm_re_fx[j][j] = ONE_IN_Q22; - move32(); - move32(); - move32(); - } - - FOR( j = 1; j < numch_out; j++ ) - { - tmp_C1_re_fx[j][0] = hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re_fx[j - 1]; // Q.22 - move32(); - } - - IF( EQ_16( active_w, 1 ) ) - { - FOR( j = 1; j < numch_out; j++ ) - { - - tmp_C2_re_fx[0][j] = Mpy_32_32( active_w_dm_fac_fx, -hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re_fx[j - 1] ); // Q31 *Q22=Q22 - move32(); - } - re_fx = Mpy_32_32( tmp_C2_re_fx[0][1], tmp_C1_re_fx[1][0] ); // Q22 *Q22 =Q13 - re_fx1 = L_add( ONE_IN_Q13, re_fx ); // Q13+Q13 - - re_fx = Mpy_32_32( tmp_C2_re_fx[0][2], tmp_C1_re_fx[2][0] ); // Q22 *Q22 =Q13 - re_fx1 = L_add( re_fx1, re_fx ); // Q13+Q13 - - re_fx = Mpy_32_32( tmp_C2_re_fx[0][3], tmp_C1_re_fx[3][0] ); // Q22 *Q22 =Q13 - tmp_dm_re_fx[0][0] = L_shl(L_add( re_fx1, re_fx ), Q9); // (Q13+Q13) << Q9 = Q22; - move32(); - - if ( EQ_16( dyn_active_w_flag, 1 ) ) - { - tmp_dm_re_fx[0][0] =L_shl(Mpy_32_32( tmp_dm_re_fx[0][0], IVAS_SPAR_DYN_ACTIVEW_THRESH_FX ),Q9); // Q13 *Q31 =Q13 << Q9=Q.22 - move32(); - } - - tmp_dm_re_fx[0][1] = tmp_C2_re_fx[0][1]; - - tmp_dm_re_fx[0][2] = tmp_C2_re_fx[0][2]; - - tmp_dm_re_fx[0][3] = tmp_C2_re_fx[0][3]; - - tmp_dm_re_fx[1][0] = tmp_C1_re_fx[1][0]; - - tmp_dm_re_fx[2][0] = tmp_C1_re_fx[2][0]; - - tmp_dm_re_fx[3][0] = tmp_C1_re_fx[3][0]; - - IF( NE_16( hMdDec->spar_md_cfg.remix_unmix_order, 3 ) ) - { - ivas_mat_col_rearrange_fx( tmp_dm_re_fx, order, i_ts, hMdDec->mixer_mat_fx, b, numch_out ); - } - } - ELSE - { - IF( NE_16( hMdDec->spar_md_cfg.remix_unmix_order, 3 ) ) - { - - ivas_mat_col_rearrange_fx( tmp_C1_re_fx, order, i_ts, hMdDec->mixer_mat_fx, b, numch_out ); - } - } - - IF( GT_16( dmx_ch, 0 ) ) - { - Word32 tmpC_re_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; - Word32 tmpP_re_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; - - FOR( j = 0; j < numch_out; j++ ) - { - set32_fx( tmpC_re_fx[j], 0, numch_out ); - set32_fx( tmpP_re_fx[j], 0, numch_out ); - } - - FOR( j = 0; j < numch_out; j++ ) - { - set32_fx( tmpC_re_fx[j], 0, numch_out ); - } - - FOR( k = 0; k < dmx_ch; k++ ) - { - tmpC_re_fx[k][k] = ONE_IN_Q22; - move32(); - } - - FOR( j = dmx_ch; j < numch_out; j++ ) - { - FOR( k = 1; k < dmx_ch; k++ ) - { - tmpC_re_fx[j][k] = hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].C_re_fx[j - dmx_ch][k - 1]; // Q22 - move32(); - } - } - - FOR( j = dmx_ch; j < numch_out; j++ ) - { - FOR( k = dmx_ch; k < numch_out; k++ ) - { - IF( EQ_16( sub( j, dmx_ch ), sub( k, dmx_ch ) ) ) - { - tmpP_re_fx[j][k] = hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].P_re_fx[k - dmx_ch]; // Q22 - move32(); - } - ELSE - { - tmpP_re_fx[j][k] = 0; - move32(); - } - } - } - - - FOR( j = 1; j < numch_out; j++ ) - { - FOR( k = dmx_ch; k < numch_out; k++ ) - { - FOR( m = 0; m < numch_out; m++ ) - { - re_fx = Mpy_32_32( hMdDec->mixer_mat_fx[j][m][b + i_ts * IVAS_MAX_NUM_BANDS], tmpP_re_fx[m][k] ); // Q30*Q22 - re_fx = L_shl( re_fx, 1 ); - hMdDec->spar_coeffs.P_re_fx[j][k][( b * bw ) + i_ts * IVAS_MAX_NUM_BANDS] = L_add( hMdDec->spar_coeffs.P_re_fx[j][k][( b * bw ) + i_ts * IVAS_MAX_NUM_BANDS], re_fx ); - move32(); - } - } - } - - - FOR( j = 0; j < numch_out; j++ ) - { - FOR( k = 0; k < dmx_ch; k++ ) - { - FOR( m = 0; m < numch_out; m++ ) - { - re_fx = Mpy_32_32( hMdDec->mixer_mat_fx[j][m][b + i_ts * IVAS_MAX_NUM_BANDS], tmpC_re_fx[m][k] ); // Q30* Q22 - re_fx = L_shl( re_fx, 1 ); - hMdDec->spar_coeffs.C_re_fx[j][k][( b * bw ) + i_ts * IVAS_MAX_NUM_BANDS] = L_add( hMdDec->spar_coeffs.C_re_fx[j][k][( b * bw ) + i_ts * IVAS_MAX_NUM_BANDS], re_fx ); - move32(); - } - } - } - - hMdDec->spar_coeffs.C_re_fx[0][0][( b * bw ) + i_ts * IVAS_MAX_NUM_BANDS] = - max( 0, hMdDec->spar_coeffs.C_re_fx[0][0][( b * bw ) + i_ts * IVAS_MAX_NUM_BANDS] ); - } - } - - /* band mixing */ - IF( EQ_16( bw, IVAS_RED_BAND_FACT ) ) - { - FOR( b = 0; b < num_bands_out; b = b + bw ) - { - dmx_ch = hMdDec->spar_md_cfg.num_dmx_chans_per_band[b]; - move16(); - FOR( j = 0; j < numch_out; j++ ) - { - FOR( k = dmx_ch; k < numch_out; k++ ) - { - - hMdDec->spar_coeffs.P_re_fx[j][k][( b + 1 ) + i_ts * IVAS_MAX_NUM_BANDS] = hMdDec->spar_coeffs.P_re_fx[j][k][b + i_ts * IVAS_MAX_NUM_BANDS]; - move32(); - } - } - - FOR( j = 0; j < numch_out; j++ ) - { - FOR( k = 0; k < dmx_ch; k++ ) - { - - hMdDec->spar_coeffs.C_re_fx[j][k][( b + 1 ) + i_ts * IVAS_MAX_NUM_BANDS] = hMdDec->spar_coeffs.C_re_fx[j][k][b + i_ts * IVAS_MAX_NUM_BANDS]; - - move32(); - } - } - } - } - } - - return; + Word16 num_bands, dmx_ch, split_band; + Word16 i, j, k, m, b, i_ts, active_w; + const Word16 *order; + Word32 active_w_dm_fac_fx, re_fx, re_fx1; + + num_bands = num_bands_out; + order = remix_order_set[hMdDec->spar_md_cfg.remix_unmix_order]; + + split_band = SPAR_DIRAC_SPLIT_START_BAND; + + // Dead code as SPAR_DIRAC_SPLIT_START_BAND = 8 and IVAS_MAX_NUM_BANDS = 12 + IF( GE_16( split_band, IVAS_MAX_NUM_BANDS ) ) + { + /*store previous 4x4 parameters for linear interpolation to current*/ + + FOR( i = 0; i < numch_out; i++ ) + { + FOR( j = 0; j < numch_out; j++ ) + { + FOR( b = 0; b < num_bands; b++ ) + { + hMdDec->mixer_mat_prev_fx[0][i][j][b] = hMdDec->mixer_mat_fx[i][j][b]; + move32(); + } + } + } + } + + IF( bw == IVAS_RED_BAND_FACT ) + { + num_bands = shl( num_bands, 1 ); + } + + active_w = EQ_16( dyn_active_w_flag, 1 ) || EQ_16( hMdDec->spar_md_cfg.active_w, 1 ); + active_w_dm_fac_fx = EQ_16( dtx_vad, 0 ) ? IVAS_ACTIVEW_DM_F_SCALE_DTX_FX : ( EQ_16( active_w_vlbr, 1 ) ? IVAS_ACTIVEW_DM_F_SCALE_VLBR_FX : IVAS_ACTIVEW_DM_F_SCALE_FX ); + + move16(); + FOR( i_ts = 0; i_ts < n_ts; i_ts++ ) + { + FOR( i = 0; i < numch_out; i++ ) + { + FOR( j = 0; j < numch_out; j++ ) + { + + set32_fx( &hMdDec->spar_coeffs.C_re_fx[i][j][i_ts * IVAS_MAX_NUM_BANDS], 0, IVAS_MAX_NUM_BANDS ); + set32_fx( &hMdDec->spar_coeffs.P_re_fx[i][j][i_ts * IVAS_MAX_NUM_BANDS], 0, IVAS_MAX_NUM_BANDS ); + } + } + num_bands = min( num_bands, nB ); + + FOR( b = 0; b < num_bands; b++ ) + { + Word32 tmp_C1_re_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; + Word32 tmp_C2_re_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; + Word32 tmp_dm_re_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; + dmx_ch = hMdDec->spar_md_cfg.num_dmx_chans_per_band[bw * b]; + + FOR( j = 0; j < numch_out; j++ ) + { + set_zero_fx( tmp_C1_re_fx[j], numch_out ); + set_zero_fx( tmp_C2_re_fx[j], numch_out ); + set_zero_fx( tmp_dm_re_fx[j], numch_out ); + + tmp_C1_re_fx[j][j] = ONE_IN_Q22; + tmp_C2_re_fx[j][j] = ONE_IN_Q22; + tmp_dm_re_fx[j][j] = ONE_IN_Q22; + move32(); + move32(); + move32(); + } + + FOR( j = 1; j < numch_out; j++ ) + { + tmp_C1_re_fx[j][0] = hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re_fx[j - 1]; // Q.22 + move32(); + } + + IF( EQ_16( active_w, 1 ) ) + { + FOR( j = 1; j < numch_out; j++ ) + { + + tmp_C2_re_fx[0][j] = Mpy_32_32( active_w_dm_fac_fx, -hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re_fx[j - 1] ); // Q31 *Q22=Q22 + move32(); + } + re_fx = Mpy_32_32( tmp_C2_re_fx[0][1], tmp_C1_re_fx[1][0] ); // Q22 *Q22 =Q13 + re_fx1 = L_add( ONE_IN_Q13, re_fx ); // Q13+Q13 + + re_fx = Mpy_32_32( tmp_C2_re_fx[0][2], tmp_C1_re_fx[2][0] ); // Q22 *Q22 =Q13 + re_fx1 = L_add( re_fx1, re_fx ); // Q13+Q13 + + re_fx = Mpy_32_32( tmp_C2_re_fx[0][3], tmp_C1_re_fx[3][0] ); // Q22 *Q22 =Q13 + tmp_dm_re_fx[0][0] = L_shl( L_add( re_fx1, re_fx ), Q9 ); // (Q13+Q13) << Q9 = Q22; + move32(); + + if ( EQ_16( dyn_active_w_flag, 1 ) ) + { + tmp_dm_re_fx[0][0] = L_shl( Mpy_32_32( tmp_dm_re_fx[0][0], IVAS_SPAR_DYN_ACTIVEW_THRESH_FX ), Q9 ); // Q13 *Q31 =Q13 << Q9=Q.22 + move32(); + } + + tmp_dm_re_fx[0][1] = tmp_C2_re_fx[0][1]; + + tmp_dm_re_fx[0][2] = tmp_C2_re_fx[0][2]; + + tmp_dm_re_fx[0][3] = tmp_C2_re_fx[0][3]; + + tmp_dm_re_fx[1][0] = tmp_C1_re_fx[1][0]; + + tmp_dm_re_fx[2][0] = tmp_C1_re_fx[2][0]; + + tmp_dm_re_fx[3][0] = tmp_C1_re_fx[3][0]; + + IF( NE_16( hMdDec->spar_md_cfg.remix_unmix_order, 3 ) ) + { + ivas_mat_col_rearrange_fx( tmp_dm_re_fx, order, i_ts, hMdDec->mixer_mat_fx, b, numch_out ); + } + } + ELSE + { + IF( NE_16( hMdDec->spar_md_cfg.remix_unmix_order, 3 ) ) + { + + ivas_mat_col_rearrange_fx( tmp_C1_re_fx, order, i_ts, hMdDec->mixer_mat_fx, b, numch_out ); + } + } + + IF( GT_16( dmx_ch, 0 ) ) + { + Word32 tmpC_re_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; + Word32 tmpP_re_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; + + FOR( j = 0; j < numch_out; j++ ) + { + set32_fx( tmpC_re_fx[j], 0, numch_out ); + set32_fx( tmpP_re_fx[j], 0, numch_out ); + } + + FOR( j = 0; j < numch_out; j++ ) + { + set32_fx( tmpC_re_fx[j], 0, numch_out ); + } + + FOR( k = 0; k < dmx_ch; k++ ) + { + tmpC_re_fx[k][k] = ONE_IN_Q22; + move32(); + } + + FOR( j = dmx_ch; j < numch_out; j++ ) + { + FOR( k = 1; k < dmx_ch; k++ ) + { + tmpC_re_fx[j][k] = hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].C_re_fx[j - dmx_ch][k - 1]; // Q22 + move32(); + } + } + + FOR( j = dmx_ch; j < numch_out; j++ ) + { + FOR( k = dmx_ch; k < numch_out; k++ ) + { + IF( EQ_16( sub( j, dmx_ch ), sub( k, dmx_ch ) ) ) + { + tmpP_re_fx[j][k] = hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].P_re_fx[k - dmx_ch]; // Q22 + move32(); + } + ELSE + { + tmpP_re_fx[j][k] = 0; + move32(); + } + } + } + + + FOR( j = 1; j < numch_out; j++ ) + { + FOR( k = dmx_ch; k < numch_out; k++ ) + { + FOR( m = 0; m < numch_out; m++ ) + { + re_fx = Mpy_32_32( hMdDec->mixer_mat_fx[j][m][b + i_ts * IVAS_MAX_NUM_BANDS], tmpP_re_fx[m][k] ); // Q30*Q22 + re_fx = L_shl( re_fx, 1 ); + hMdDec->spar_coeffs.P_re_fx[j][k][( b * bw ) + i_ts * IVAS_MAX_NUM_BANDS] = L_add( hMdDec->spar_coeffs.P_re_fx[j][k][( b * bw ) + i_ts * IVAS_MAX_NUM_BANDS], re_fx ); + move32(); + } + } + } + + + FOR( j = 0; j < numch_out; j++ ) + { + FOR( k = 0; k < dmx_ch; k++ ) + { + FOR( m = 0; m < numch_out; m++ ) + { + re_fx = Mpy_32_32( hMdDec->mixer_mat_fx[j][m][b + i_ts * IVAS_MAX_NUM_BANDS], tmpC_re_fx[m][k] ); // Q30* Q22 + re_fx = L_shl( re_fx, 1 ); + hMdDec->spar_coeffs.C_re_fx[j][k][( b * bw ) + i_ts * IVAS_MAX_NUM_BANDS] = L_add( hMdDec->spar_coeffs.C_re_fx[j][k][( b * bw ) + i_ts * IVAS_MAX_NUM_BANDS], re_fx ); + move32(); + } + } + } + + hMdDec->spar_coeffs.C_re_fx[0][0][( b * bw ) + i_ts * IVAS_MAX_NUM_BANDS] = + max( 0, hMdDec->spar_coeffs.C_re_fx[0][0][( b * bw ) + i_ts * IVAS_MAX_NUM_BANDS] ); + } + } + + /* band mixing */ + IF( EQ_16( bw, IVAS_RED_BAND_FACT ) ) + { + FOR( b = 0; b < num_bands_out; b = b + bw ) + { + dmx_ch = hMdDec->spar_md_cfg.num_dmx_chans_per_band[b]; + move16(); + FOR( j = 0; j < numch_out; j++ ) + { + FOR( k = dmx_ch; k < numch_out; k++ ) + { + + hMdDec->spar_coeffs.P_re_fx[j][k][( b + 1 ) + i_ts * IVAS_MAX_NUM_BANDS] = hMdDec->spar_coeffs.P_re_fx[j][k][b + i_ts * IVAS_MAX_NUM_BANDS]; + move32(); + } + } + + FOR( j = 0; j < numch_out; j++ ) + { + FOR( k = 0; k < dmx_ch; k++ ) + { + + hMdDec->spar_coeffs.C_re_fx[j][k][( b + 1 ) + i_ts * IVAS_MAX_NUM_BANDS] = hMdDec->spar_coeffs.C_re_fx[j][k][b + i_ts * IVAS_MAX_NUM_BANDS]; + + move32(); + } + } + } + } + } + + return; } #endif @@ -2676,35 +2673,34 @@ static void ivas_mat_col_rearrange( } #else /*-----------------------------------------------------------------------------------------* -* Function ivas_mat_col_rearrange() -* -* reorders the input matrix based on order -*-----------------------------------------------------------------------------------------*/ + * Function ivas_mat_col_rearrange() + * + * reorders the input matrix based on order + *-----------------------------------------------------------------------------------------*/ static void ivas_mat_col_rearrange_fx( - Word32 in_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - const Word16 order[IVAS_SPAR_MAX_CH], - const Word16 i_ts, - Word32 ***mixer_mat, - const Word16 bands, - const Word16 num_ch -) + Word32 in_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + const Word16 order[IVAS_SPAR_MAX_CH], + const Word16 i_ts, + Word32 ***mixer_mat, + const Word16 bands, + const Word16 num_ch ) { - Word16 i, j, idx; + Word16 i, j, idx; - FOR( i = 0; i < num_ch; i++ ) - { - idx = order[i]; - move16(); + FOR( i = 0; i < num_ch; i++ ) + { + idx = order[i]; + move16(); - FOR( j = 0; j < num_ch; j++ ) - { - mixer_mat[j][i][bands + i_ts * IVAS_MAX_NUM_BANDS] = L_shl_sat(in_re[j][idx], Q8); - move32(); - } - } + FOR( j = 0; j < num_ch; j++ ) + { + mixer_mat[j][i][bands + i_ts * IVAS_MAX_NUM_BANDS] = L_shl_sat( in_re[j][idx], Q8 ); + move32(); + } + } - return; + return; } #endif @@ -2721,31 +2717,31 @@ void ivas_spar_dec_gen_umx_mat_fx( const Word16 bfi, /* i : bad frame indicator */ const Word16 num_md_sub_frames ) { - Word16 i, j, b, i_ts, num_out_ch; - num_out_ch = hMdDec->spar_md_cfg.num_umx_chs; - move16(); - FOR ( i_ts = 0; i_ts < num_md_sub_frames; i_ts++ ) + Word16 i, j, b, i_ts, num_out_ch; + num_out_ch = hMdDec->spar_md_cfg.num_umx_chs; + move16(); + FOR( i_ts = 0; i_ts < num_md_sub_frames; i_ts++ ) { - IF ( EQ_16(hMdDec->td_decorr_flag , 1) ) + IF( EQ_16( hMdDec->td_decorr_flag, 1 ) ) { - FOR ( i = 0; i < num_out_ch; i++ ) + FOR( i = 0; i < num_out_ch; i++ ) { - FOR ( j = 0; j < nchan_transport; j++ ) + FOR( j = 0; j < nchan_transport; j++ ) { - FOR ( b = 0; b < num_bands_out; b++ ) + FOR( b = 0; b < num_bands_out; b++ ) { - hMdDec->mixer_mat_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = L_shl_sat(hMdDec->spar_coeffs.C_re_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS], Q8); + hMdDec->mixer_mat_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = L_shl_sat( hMdDec->spar_coeffs.C_re_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS], Q8 ); move32(); } } } - FOR ( i = 0; i < num_out_ch; i++ ) + FOR( i = 0; i < num_out_ch; i++ ) { - FOR ( j = nchan_transport; j < num_out_ch; j++ ) + FOR( j = nchan_transport; j < num_out_ch; j++ ) { - FOR ( b = 0; b < num_bands_out; b++ ) + FOR( b = 0; b < num_bands_out; b++ ) { - hMdDec->mixer_mat_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = L_shl_sat(hMdDec->spar_coeffs.P_re_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS], Q8); + hMdDec->mixer_mat_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = L_shl_sat( hMdDec->spar_coeffs.P_re_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS], Q8 ); move32(); } } @@ -2753,20 +2749,20 @@ void ivas_spar_dec_gen_umx_mat_fx( } ELSE { - FOR ( i = 0; i < num_out_ch; i++ ) + FOR( i = 0; i < num_out_ch; i++ ) { - FOR ( j = 0; j < nchan_transport; j++ ) + FOR( j = 0; j < nchan_transport; j++ ) { - FOR ( b = 0; b < num_bands_out; b++ ) + FOR( b = 0; b < num_bands_out; b++ ) { - hMdDec->mixer_mat_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = L_shl_sat(hMdDec->spar_coeffs.C_re_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS], Q8); + hMdDec->mixer_mat_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = L_shl_sat( hMdDec->spar_coeffs.C_re_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS], Q8 ); move32(); } } } } } - ivas_spar_dec_compute_ramp_down_post_matrix_fx( hMdDec, num_bands_out, bfi, num_md_sub_frames); + ivas_spar_dec_compute_ramp_down_post_matrix_fx( hMdDec, num_bands_out, bfi, num_md_sub_frames ); return; } #else // IVAS_FLOAT_FIXED @@ -2821,7 +2817,6 @@ void ivas_spar_dec_gen_umx_mat( } } } - } ivas_spar_dec_compute_ramp_down_post_matrix( hMdDec, num_bands_out, bfi, num_md_sub_frames ); @@ -2850,26 +2845,26 @@ static void ivas_spar_md_band_upmix( idx = i * bw_fact + b; for ( ii = 0; ii < ndec + ndm - 1; ii++ ) { -#if 0 //ndef IVAS_FLOAT_FIXED_TO_BE_REMOVED +#if 0 // ndef IVAS_FLOAT_FIXED_TO_BE_REMOVED band_coeffs[idx].pred_re[ii] = band_coeffs[i].pred_re[ii]; -#endif +#endif band_coeffs[idx].pred_re_fx[ii] = band_coeffs[i].pred_re_fx[ii]; } for ( ii = 0; ii < ndec; ii++ ) { for ( jj = 0; jj < ndm - 1; jj++ ) { -#if 0 //ndef IVAS_FLOAT_FIXED_TO_BE_REMOVED +#if 0 // ndef IVAS_FLOAT_FIXED_TO_BE_REMOVED band_coeffs[idx].C_re[ii][jj] = band_coeffs[i].C_re[ii][jj]; -#endif +#endif band_coeffs[idx].C_re_fx[ii][jj] = band_coeffs[i].C_re_fx[ii][jj]; } } for ( jj = 0; jj < ndec; jj++ ) { -#if 0 //ndef IVAS_FLOAT_FIXED_TO_BE_REMOVED +#if 0 // ndef IVAS_FLOAT_FIXED_TO_BE_REMOVED band_coeffs[idx].P_re[jj] = band_coeffs[i].P_re[jj]; -#endif +#endif band_coeffs[idx].P_re_fx[jj] = band_coeffs[i].P_re_fx[jj]; } valid_bands[idx] = valid_bands[i]; @@ -2895,8 +2890,7 @@ static void ivas_spar_dec_parse_md_bs( int16_t *bands_bw, int16_t *dtx_vad, const int32_t ivas_total_brate, - const int16_t sba_inactive_mode -) + const int16_t sba_inactive_mode ) { int16_t i, j, k, num_bands; int16_t ii, jj, ndec, ndm; @@ -3130,7 +3124,7 @@ static void ivas_spar_dec_parse_md_bs_fx( int16_t *bands_bw, int16_t *dtx_vad, const int32_t ivas_total_brate, - const int16_t sba_inactive_mode) + const int16_t sba_inactive_mode ) { int16_t i, j, k, num_bands; int16_t ii, jj, ndec, ndm; @@ -3138,7 +3132,7 @@ static void ivas_spar_dec_parse_md_bs_fx( ivas_quant_strat_t qs; int16_t strat, no_ec; int16_t do_diff[IVAS_MAX_NUM_BANDS]; - //float quant[IVAS_SPAR_MAX_C_COEFF]; + // float quant[IVAS_SPAR_MAX_C_COEFF]; Word32 quant_fx[IVAS_SPAR_MAX_C_COEFF]; int16_t do_repeat[IVAS_MAX_NUM_BANDS]; *dtx_vad = 1; @@ -3193,9 +3187,9 @@ static void ivas_spar_dec_parse_md_bs_fx( { for ( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) { - //hMdDec->spar_md.band_coeffs[i].pred_re[j] = 0; + // hMdDec->spar_md.band_coeffs[i].pred_re[j] = 0; hMdDec->spar_md.band_coeffs[i].pred_re_fx[j] = 0; - //hMdDec->spar_md.band_coeffs[i].P_re[j] = 0; + // hMdDec->spar_md.band_coeffs[i].P_re[j] = 0; hMdDec->spar_md.band_coeffs[i].P_re_fx[j] = 0; } hMdDec->valid_bands[i] = 1; @@ -3207,7 +3201,7 @@ static void ivas_spar_dec_parse_md_bs_fx( { for ( k = 0; k < ( IVAS_SPAR_MAX_DMX_CHS - 1 ); k++ ) { - //hMdDec->spar_md.band_coeffs[i].C_re[j][k] = 0; + // hMdDec->spar_md.band_coeffs[i].C_re[j][k] = 0; hMdDec->spar_md.band_coeffs[i].C_re_fx[j][k] = 0; } } @@ -3301,7 +3295,7 @@ static void ivas_spar_dec_parse_md_bs_fx( ndec = hMdDec->spar_md_cfg.num_decorr_per_band[( *bands_bw ) * i]; ndm = hMdDec->spar_md_cfg.num_dmx_chans_per_band[( *bands_bw ) * i]; - //ivas_deindex_real_index( hMdDec->spar_md.band_coeffs_idx[i].pred_index_re, qs.PR.q_levels[0], qs.PR.min, qs.PR.max, hMdDec->spar_md.band_coeffs[i].pred_re, ndm + ndec - 1 ); + // ivas_deindex_real_index( hMdDec->spar_md.band_coeffs_idx[i].pred_index_re, qs.PR.q_levels[0], qs.PR.min, qs.PR.max, hMdDec->spar_md.band_coeffs[i].pred_re, ndm + ndec - 1 ); ivas_deindex_real_index_fx( hMdDec->spar_md.band_coeffs_idx[i].pred_index_re, qs.PR.q_levels[0], qs.PR.min_fx, qs.PR.max_fx, hMdDec->spar_md.band_coeffs[i].pred_re_fx, ndm + ndec - 1 ); j = 0; @@ -3309,13 +3303,13 @@ static void ivas_spar_dec_parse_md_bs_fx( { for ( jj = 0; jj < ndm - 1; jj++ ) { - //quant[j] = hMdDec->spar_md.band_coeffs[i].C_re[ii][jj]; + // quant[j] = hMdDec->spar_md.band_coeffs[i].C_re[ii][jj]; quant_fx[j] = hMdDec->spar_md.band_coeffs[i].C_re_fx[ii][jj]; j++; } } - //ivas_deindex_real_index( hMdDec->spar_md.band_coeffs_idx[i].drct_index_re, qs.C.q_levels[0], qs.C.min, qs.C.max, quant, ndec * ( ndm - 1 ) ); + // ivas_deindex_real_index( hMdDec->spar_md.band_coeffs_idx[i].drct_index_re, qs.C.q_levels[0], qs.C.min, qs.C.max, quant, ndec * ( ndm - 1 ) ); ivas_deindex_real_index_fx( hMdDec->spar_md.band_coeffs_idx[i].drct_index_re, qs.C.q_levels[0], qs.C.min_fx, qs.C.max_fx, quant_fx, ndec * ( ndm - 1 ) ); j = 0; @@ -3323,13 +3317,13 @@ static void ivas_spar_dec_parse_md_bs_fx( { for ( jj = 0; jj < ndm - 1; jj++ ) { - //hMdDec->spar_md.band_coeffs[i].C_re[ii][jj] = quant[j]; + // hMdDec->spar_md.band_coeffs[i].C_re[ii][jj] = quant[j]; hMdDec->spar_md.band_coeffs[i].C_re_fx[ii][jj] = quant_fx[j]; j++; } } - //ivas_deindex_real_index( hMdDec->spar_md.band_coeffs_idx[i].decd_index_re, qs.P_r.q_levels[0], qs.P_r.min, qs.P_r.max, hMdDec->spar_md.band_coeffs[i].P_re, ndm + ndec - 1 ); + // ivas_deindex_real_index( hMdDec->spar_md.band_coeffs_idx[i].decd_index_re, qs.P_r.q_levels[0], qs.P_r.min, qs.P_r.max, hMdDec->spar_md.band_coeffs[i].P_re, ndm + ndec - 1 ); ivas_deindex_real_index_fx( hMdDec->spar_md.band_coeffs_idx[i].decd_index_re, qs.P_r.q_levels[0], qs.P_r.min_fx, qs.P_r.max_fx, hMdDec->spar_md.band_coeffs[i].P_re_fx, ndm + ndec - 1 ); /* Store prior coefficient indices */ @@ -3706,40 +3700,40 @@ static void ivas_spar_get_plc_interp_weights( #endif static void ivas_spar_get_plc_interp_weights_fx( - int16_t valid_band_idx[IVAS_MAX_NUM_BANDS], - int16_t last_valid_band_idx, - int16_t idx, - int16_t b, - Word16 *w, - int16_t *id0, - int16_t *id1) + int16_t valid_band_idx[IVAS_MAX_NUM_BANDS], + int16_t last_valid_band_idx, + int16_t idx, + int16_t b, + Word16 *w, + int16_t *id0, + int16_t *id1 ) { - if (last_valid_band_idx < 0) /* Extrapolation */ - { - *id1 = valid_band_idx[0]; - *id0 = 0; - *w = MAX_WORD16; - } - else if (last_valid_band_idx == idx) /* Extrapolation */ - { - *id1 = valid_band_idx[last_valid_band_idx]; - *id0 = valid_band_idx[last_valid_band_idx]; - *w = 0; - } - else /* Interpolation */ - { - *id0 = valid_band_idx[last_valid_band_idx]; - *id1 = valid_band_idx[last_valid_band_idx + 1]; - if ((b - *id0) == 0) - { - *w = 0; + if ( last_valid_band_idx < 0 ) /* Extrapolation */ + { + *id1 = valid_band_idx[0]; + *id0 = 0; + *w = MAX_WORD16; } - else + else if ( last_valid_band_idx == idx ) /* Extrapolation */ { - *w = divide3232((b - *id0), (*id1 - *id0)); + *id1 = valid_band_idx[last_valid_band_idx]; + *id0 = valid_band_idx[last_valid_band_idx]; + *w = 0; } - } - return; + else /* Interpolation */ + { + *id0 = valid_band_idx[last_valid_band_idx]; + *id1 = valid_band_idx[last_valid_band_idx + 1]; + if ( ( b - *id0 ) == 0 ) + { + *w = 0; + } + else + { + *w = divide3232( ( b - *id0 ), ( *id1 - *id0 ) ); + } + } + return; } #ifdef IVAS_FLOAT_FIXED @@ -3766,35 +3760,35 @@ static void ivas_spar_md_fill_invalid_bands_fx( last_valid_band_idx, valid_band_idx, &all_valid, &idx ); assert( idx > 0 ); /* some bands should be valid */ - IF ( EQ_16(all_valid , 0) ) + IF( EQ_16( all_valid, 0 ) ) { - FOR ( b = 0; b < num_bands; b++ ) + FOR( b = 0; b < num_bands; b++ ) { /* check against non zero in if and else if */ - IF ( GT_16(base_band_age[b] , 3) ) /* old invalid bands */ + IF( GT_16( base_band_age[b], 3 ) ) /* old invalid bands */ { Word16 id0, id1; ivas_spar_get_plc_interp_weights_fx( valid_band_idx, last_valid_band_idx[b], - idx, b, &w_fx, &id0, &id1); - FOR ( i = 0; i < num_channels; i++ ) + idx, b, &w_fx, &id0, &id1 ); + FOR( i = 0; i < num_channels; i++ ) { - FOR ( j = 0; j < num_channels; j++ ) + FOR( j = 0; j < num_channels; j++ ) { - pSpar_coeffs->C_re_fx[i][j][b] = L_add(Mpy_32_16_1(pSpar_coeffs->C_re_fx[i][j][id0], sub(MAX_WORD16, w_fx)), Mpy_32_16_1(pSpar_coeffs->C_re_fx[i][j][id1], w_fx)); + pSpar_coeffs->C_re_fx[i][j][b] = L_add( Mpy_32_16_1( pSpar_coeffs->C_re_fx[i][j][id0], sub( MAX_WORD16, w_fx ) ), Mpy_32_16_1( pSpar_coeffs->C_re_fx[i][j][id1], w_fx ) ); move32(); - pSpar_coeffs->P_re_fx[i][j][b] = L_add(Mpy_32_16_1(pSpar_coeffs->P_re_fx[i][j][id0], sub(MAX_WORD16, w_fx)), Mpy_32_16_1(pSpar_coeffs->P_re_fx[i][j][id1], w_fx)); + pSpar_coeffs->P_re_fx[i][j][b] = L_add( Mpy_32_16_1( pSpar_coeffs->P_re_fx[i][j][id0], sub( MAX_WORD16, w_fx ) ), Mpy_32_16_1( pSpar_coeffs->P_re_fx[i][j][id1], w_fx ) ); move32(); } } } ELSE /* young invalid bands */ { - IF ( EQ_16(valid_bands[b] , 0) ) + IF( EQ_16( valid_bands[b], 0 ) ) { - FOR ( i = 0; i < num_channels; i++ ) + FOR( i = 0; i < num_channels; i++ ) { - FOR ( j = 0; j < num_channels; j++ ) + FOR( j = 0; j < num_channels; j++ ) { pSpar_coeffs->C_re_fx[i][j][b] = pSpar_coeffs_prev->C_re_fx[i][j][b]; move32(); @@ -3805,18 +3799,18 @@ static void ivas_spar_md_fill_invalid_bands_fx( } } - IF ( EQ_16(valid_bands[b] , 0) ) + IF( EQ_16( valid_bands[b], 0 ) ) { Word16 i_ts; - FOR ( i = 0; i < num_channels; i++ ) + FOR( i = 0; i < num_channels; i++ ) { - FOR ( j = 0; j < num_channels; j++ ) + FOR( j = 0; j < num_channels; j++ ) { - FOR ( i_ts = 1; i_ts < num_md_sub_frames; i_ts++ ) + FOR( i_ts = 1; i_ts < num_md_sub_frames; i_ts++ ) { - pSpar_coeffs->C_re_fx[i][j][add(b , i_ts * IVAS_MAX_NUM_BANDS)] = pSpar_coeffs->C_re_fx[i][j][b]; + pSpar_coeffs->C_re_fx[i][j][add( b, i_ts * IVAS_MAX_NUM_BANDS )] = pSpar_coeffs->C_re_fx[i][j][b]; move32(); - pSpar_coeffs->P_re_fx[i][j][add(b , i_ts * IVAS_MAX_NUM_BANDS)] = pSpar_coeffs->P_re_fx[i][j][b]; + pSpar_coeffs->P_re_fx[i][j][add( b, i_ts * IVAS_MAX_NUM_BANDS )] = pSpar_coeffs->P_re_fx[i][j][b]; move32(); } } @@ -3919,7 +3913,7 @@ static void ivas_spar_md_fill_invalid_bandcoeffs( int16_t j, k, b, all_valid; int16_t valid_band_idx[IVAS_MAX_NUM_BANDS], idx = -1; int16_t last_valid_band_idx[IVAS_MAX_NUM_BANDS]; - //float w = 0; + // float w = 0; Word16 w_fx = 0; ivas_spar_plc_get_band_age( valid_bands, base_band_age, num_bands, @@ -3935,30 +3929,30 @@ static void ivas_spar_md_fill_invalid_bandcoeffs( if ( ( base_band_age[b] > 3 ) || ( *first_valid_frame == 0 ) ) /* old invalid bands */ { int16_t id0, id1; - //ivas_spar_get_plc_interp_weights( valid_band_idx, last_valid_band_idx[b], - // idx, b, &w, &id0, &id1 ); - ivas_spar_get_plc_interp_weights_fx(valid_band_idx, last_valid_band_idx[b], - idx, b, &w_fx, &id0, &id1); + // ivas_spar_get_plc_interp_weights( valid_band_idx, last_valid_band_idx[b], + // idx, b, &w, &id0, &id1 ); + ivas_spar_get_plc_interp_weights_fx( valid_band_idx, last_valid_band_idx[b], + idx, b, &w_fx, &id0, &id1 ); for ( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) { - //pBand_coeffs[b].pred_re[j] = ( 1 - w ) * pBand_coeffs[id0].pred_re[j] + w * pBand_coeffs[id1].pred_re[j]; - pBand_coeffs[b].pred_re_fx[j] = L_add(Mpy_32_16_1(pBand_coeffs[id0].pred_re_fx[j], sub(MAX_WORD16, w_fx)), Mpy_32_16_1(pBand_coeffs[id1].pred_re_fx[j],w_fx)); + // pBand_coeffs[b].pred_re[j] = ( 1 - w ) * pBand_coeffs[id0].pred_re[j] + w * pBand_coeffs[id1].pred_re[j]; + pBand_coeffs[b].pred_re_fx[j] = L_add( Mpy_32_16_1( pBand_coeffs[id0].pred_re_fx[j], sub( MAX_WORD16, w_fx ) ), Mpy_32_16_1( pBand_coeffs[id1].pred_re_fx[j], w_fx ) ); } for ( j = 0; j < IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS; j++ ) { for ( k = 0; k < IVAS_SPAR_MAX_DMX_CHS - 1; k++ ) { - // pBand_coeffs[b].C_re[j][k] = ( 1 - w ) * pBand_coeffs[id0].C_re[j][k] + w * pBand_coeffs[id1].C_re[j][k]; - pBand_coeffs[b].C_re_fx[j][k] = L_add(Mpy_32_16_1(pBand_coeffs[id0].C_re_fx[j][k], sub(MAX_WORD16, w_fx)), Mpy_32_16_1(pBand_coeffs[id1].C_re_fx[j][k],w_fx)); + // pBand_coeffs[b].C_re[j][k] = ( 1 - w ) * pBand_coeffs[id0].C_re[j][k] + w * pBand_coeffs[id1].C_re[j][k]; + pBand_coeffs[b].C_re_fx[j][k] = L_add( Mpy_32_16_1( pBand_coeffs[id0].C_re_fx[j][k], sub( MAX_WORD16, w_fx ) ), Mpy_32_16_1( pBand_coeffs[id1].C_re_fx[j][k], w_fx ) ); } } for ( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) { - //pBand_coeffs[b].P_re[j] = ( 1 - w ) * pBand_coeffs[id0].P_re[j] + w * pBand_coeffs[id1].P_re[j]; - pBand_coeffs[b].P_re_fx[j] = L_add(Mpy_32_16_1(pBand_coeffs[id0].P_re_fx[j], sub(MAX_WORD16, w_fx)), Mpy_32_16_1(pBand_coeffs[id1].P_re_fx[j], w_fx)); + // pBand_coeffs[b].P_re[j] = ( 1 - w ) * pBand_coeffs[id0].P_re[j] + w * pBand_coeffs[id1].P_re[j]; + pBand_coeffs[b].P_re_fx[j] = L_add( Mpy_32_16_1( pBand_coeffs[id0].P_re_fx[j], sub( MAX_WORD16, w_fx ) ), Mpy_32_16_1( pBand_coeffs[id1].P_re_fx[j], w_fx ) ); } } else /* young invalid bands */ @@ -3967,7 +3961,7 @@ static void ivas_spar_md_fill_invalid_bandcoeffs( { for ( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) { - //pBand_coeffs[b].pred_re[j] = pBand_coeffs_prev[b].pred_re[j]; + // pBand_coeffs[b].pred_re[j] = pBand_coeffs_prev[b].pred_re[j]; pBand_coeffs[b].pred_re_fx[j] = pBand_coeffs_prev[b].pred_re_fx[j]; } @@ -3975,14 +3969,14 @@ static void ivas_spar_md_fill_invalid_bandcoeffs( { for ( k = 0; k < IVAS_SPAR_MAX_DMX_CHS - 1; k++ ) { - //pBand_coeffs[b].C_re[j][k] = pBand_coeffs_prev[b].C_re[j][k]; + // pBand_coeffs[b].C_re[j][k] = pBand_coeffs_prev[b].C_re[j][k]; pBand_coeffs[b].C_re_fx[j][k] = pBand_coeffs_prev[b].C_re_fx[j][k]; } } for ( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) { - //pBand_coeffs[b].P_re[j] = pBand_coeffs_prev[b].P_re[j]; + // pBand_coeffs[b].P_re[j] = pBand_coeffs_prev[b].P_re[j]; pBand_coeffs[b].P_re_fx[j] = pBand_coeffs_prev[b].P_re_fx[j]; } } @@ -4088,29 +4082,29 @@ static void ivas_spar_dec_compute_ramp_down_post_matrix_fx( ivas_spar_md_dec_state_t *hMdDec, const Word16 num_bands_out, const Word16 bfi, - const Word16 num_md_sub_frames) + const Word16 num_md_sub_frames ) { Word16 num_in_ch, num_out_ch, i, j, b; num_in_ch = hMdDec->spar_md_cfg.num_umx_chs; num_out_ch = hMdDec->spar_md_cfg.num_umx_chs; move16(); move16(); - IF ( EQ_16(bfi , 0 )) + IF( EQ_16( bfi, 0 ) ) { hMdDec->spar_plc_num_lost_frames = 0; move16(); } ELSE { - IF (EQ_16(hMdDec->td_decorr_flag , 0) ) + IF( EQ_16( hMdDec->td_decorr_flag, 0 ) ) { assert( 0 ); } - hMdDec->spar_plc_num_lost_frames =add(hMdDec->spar_plc_num_lost_frames, 1); + hMdDec->spar_plc_num_lost_frames = add( hMdDec->spar_plc_num_lost_frames, 1 ); hMdDec->spar_plc_num_lost_frames = s_min( hMdDec->spar_plc_num_lost_frames, 100 ); /*hMdDec->spar_plc_num_lost_frames is always <=100*/ - IF ( GT_16(hMdDec->spar_plc_num_lost_frames , ivas_spar_dec_plc_num_frames_keep) ) /*if control enters then ivas_spar_dec_plc_num_frames_keep<100 */ + IF( GT_16( hMdDec->spar_plc_num_lost_frames, ivas_spar_dec_plc_num_frames_keep ) ) /*if control enters then ivas_spar_dec_plc_num_frames_keep<100 */ { Word16 num_fade_frames; Word16 gain_dB; @@ -4119,33 +4113,33 @@ static void ivas_spar_dec_compute_ramp_down_post_matrix_fx( Word16 Q_post_matrix; Word16 Q_gain; Word16 norm_nff; /*norm of num_fade_frames*/ - num_fade_frames = s_max( sub(hMdDec->spar_plc_num_lost_frames , ivas_spar_dec_plc_num_frames_keep), 0 ); + num_fade_frames = s_max( sub( hMdDec->spar_plc_num_lost_frames, ivas_spar_dec_plc_num_frames_keep ), 0 ); norm_nff = norm_s( num_fade_frames ); - gain_dB = -imult1616(s_min( num_fade_frames, ivas_spar_dec_plc_max_num_frames_ramp_down ) , ivas_spar_dec_plc_per_frame_ramp_down_gain_dB); /*abs(gain_dB)<99*/ /*Q(gain_dB)=7Q24*/ - Word16 exp_gain = 0; /*stores exponent for gain_fx*/ - gain_fx = BASOP_util_Pow2( Mult_32_16( imult3216(13421773/*=2^28/20*/, gain_dB ), 27213/*=log2(10)*2^13*/ ), 5, &exp_gain ); - Q_gain = sub(31, exp_gain); - FOR ( i = 0; i < IVAS_SPAR_MAX_CH; i++ ) + gain_dB = -imult1616( s_min( num_fade_frames, ivas_spar_dec_plc_max_num_frames_ramp_down ), ivas_spar_dec_plc_per_frame_ramp_down_gain_dB ); /*abs(gain_dB)<99*/ /*Q(gain_dB)=7Q24*/ + Word16 exp_gain = 0; /*stores exponent for gain_fx*/ + gain_fx = BASOP_util_Pow2( Mult_32_16( imult3216( 13421773 /*=2^28/20*/, gain_dB ), 27213 /*=log2(10)*2^13*/ ), 5, &exp_gain ); + Q_gain = sub( 31, exp_gain ); + FOR( i = 0; i < IVAS_SPAR_MAX_CH; i++ ) { post_matrix_fx[i] = add( shl( 1, norm_nff ), mult( s_min( mult( shl( num_fade_frames, norm_nff ), div_s( 1, ivas_spar_dec_plc_num_frames_fade_out ) ), shl( 1, norm_nff ) ), shl( sub( ivas_spar_dec_plc_spatial_target[i], 1 ), 15 ) ) ); /*Q=norm_nff*/ - post_matrix_fx[i] = Mult_32_16( gain_fx, (Word16)post_matrix_fx[i] ); /*Q_gain+norm_nff-15*/ + post_matrix_fx[i] = Mult_32_16( gain_fx, (Word16) post_matrix_fx[i] ); /*Q_gain+norm_nff-15*/ } - Q_post_matrix = sub(add(Q_gain, norm_nff), 15); + Q_post_matrix = sub( add( Q_gain, norm_nff ), 15 ); /* apply the post matrix */ - FOR ( Word16 i_ts = 0; i_ts < num_md_sub_frames; i_ts++ ) + FOR( Word16 i_ts = 0; i_ts < num_md_sub_frames; i_ts++ ) { - FOR ( i = 0; i < num_out_ch; i++ ) + FOR( i = 0; i < num_out_ch; i++ ) { - FOR ( j = 0; j < num_in_ch; j++ ) + FOR( j = 0; j < num_in_ch; j++ ) { - FOR ( b = 0; b < num_bands_out; b++ ) + FOR( b = 0; b < num_bands_out; b++ ) { hMdDec->mixer_mat_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = Mult_32_32( hMdDec->mixer_mat_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS], post_matrix_fx[i] ); } } } } - hMdDec->Q_mixer_mat = sub(add(Q_post_matrix, hMdDec->Q_mixer_mat), 31); + hMdDec->Q_mixer_mat = sub( add( Q_post_matrix, hMdDec->Q_mixer_mat ), 31 ); } } @@ -4217,7 +4211,6 @@ static void ivas_spar_dec_compute_ramp_down_post_matrix( #endif // IVAS_FLOAT_FIXED - /*-----------------------------------------------------------------------------------------* * Function ivas_spar_unquant_dtx_indicies() * @@ -4232,14 +4225,14 @@ static void ivas_spar_unquant_dtx_indicies( { int16_t i, b; int16_t q_lvl; - //float val; + // float val; Word32 val_fx; int16_t idx; - //float pr_min_max[2]; + // float pr_min_max[2]; Word32 pr_min_max_fx[2]; - //pr_min_max[0] = pSpar_md->min_max[0]; - //pr_min_max[1] = pSpar_md->min_max[1]; + // pr_min_max[0] = pSpar_md->min_max[0]; + // pr_min_max[1] = pSpar_md->min_max[1]; pr_min_max_fx[0] = pSpar_md->min_max_fx[0]; pr_min_max_fx[1] = pSpar_md->min_max_fx[1]; @@ -4249,33 +4242,33 @@ static void ivas_spar_unquant_dtx_indicies( for ( i = 0; i < FOA_CHANNELS - 1; i++ ) { q_lvl = dtx_pr_real_q_levels[ndm_per_band[bw * b] - 1][i]; - //idx = pSpar_md->band_coeffs_idx[b].pred_index_re[i]; - //ivas_deindex_real_index( &idx, q_lvl, pr_min_max[0], pr_min_max[1], &val, 1 ); - //pSpar_md->band_coeffs[b].pred_re[i] = val; - //pSpar_md->band_coeffs[b].pred_re_fx[i] = val * (1 << 22); + // idx = pSpar_md->band_coeffs_idx[b].pred_index_re[i]; + // ivas_deindex_real_index( &idx, q_lvl, pr_min_max[0], pr_min_max[1], &val, 1 ); + // pSpar_md->band_coeffs[b].pred_re[i] = val; + // pSpar_md->band_coeffs[b].pred_re_fx[i] = val * (1 << 22); idx = pSpar_md->band_coeffs_idx[b].pred_index_re[i]; - ivas_deindex_real_index_fx(&idx, q_lvl, pr_min_max_fx[0], pr_min_max_fx[1], &val_fx, 1); + ivas_deindex_real_index_fx( &idx, q_lvl, pr_min_max_fx[0], pr_min_max_fx[1], &val_fx, 1 ); pSpar_md->band_coeffs[b].pred_re_fx[i] = val_fx; -#if 0 //ndef IVAS_FLOAT_FIXED_TO_BE_REMOVED +#if 0 // ndef IVAS_FLOAT_FIXED_TO_BE_REMOVED pSpar_md->band_coeffs[b].pred_re[i] = (float)val_fx / (1 << 22); -#endif +#endif } for ( i = 0; i < FOA_CHANNELS - ndm_per_band[bw * b]; i++ ) { q_lvl = dtx_pd_real_q_levels[ndm_per_band[bw * b] - 1][i]; - //idx = pSpar_md->band_coeffs_idx[b].decd_index_re[i]; - //ivas_deindex_real_index( &idx, q_lvl, dtx_pd_real_min_max[0], dtx_pd_real_min_max[1], &val, 1 ); - //pSpar_md->band_coeffs[b].P_re[i] = val; - //pSpar_md->band_coeffs[b].P_re_fx[i] = val*(1<<22); + // idx = pSpar_md->band_coeffs_idx[b].decd_index_re[i]; + // ivas_deindex_real_index( &idx, q_lvl, dtx_pd_real_min_max[0], dtx_pd_real_min_max[1], &val, 1 ); + // pSpar_md->band_coeffs[b].P_re[i] = val; + // pSpar_md->band_coeffs[b].P_re_fx[i] = val*(1<<22); idx = pSpar_md->band_coeffs_idx[b].decd_index_re[i]; - ivas_deindex_real_index_fx(&idx, q_lvl, dtx_pd_real_min_max_fx[0], dtx_pd_real_min_max_fx[1], &val_fx, 1); + ivas_deindex_real_index_fx( &idx, q_lvl, dtx_pd_real_min_max_fx[0], dtx_pd_real_min_max_fx[1], &val_fx, 1 ); pSpar_md->band_coeffs[b].P_re_fx[i] = val_fx; -#if 0 //ndef IVAS_FLOAT_FIXED_TO_BE_REMOVED +#if 0 // ndef IVAS_FLOAT_FIXED_TO_BE_REMOVED pSpar_md->band_coeffs[b].P_re[i] = (float)val_fx / (1 << 22); -#endif +#endif } } @@ -4286,7 +4279,7 @@ static void ivas_spar_unquant_dtx_indicies( ivas_spar_md_t *pSpar_md, const int16_t nB, const int16_t bw, - int16_t *ndm_per_band) + int16_t *ndm_per_band ) { int16_t i, b; int16_t q_lvl; @@ -4297,21 +4290,21 @@ static void ivas_spar_unquant_dtx_indicies( pr_min_max[0] = pSpar_md->min_max[0]; pr_min_max[1] = pSpar_md->min_max[1]; - for (b = 0; b < nB; b++) + for ( b = 0; b < nB; b++ ) { - for (i = 0; i < FOA_CHANNELS - 1; i++) + for ( i = 0; i < FOA_CHANNELS - 1; i++ ) { q_lvl = dtx_pr_real_q_levels[ndm_per_band[bw * b] - 1][i]; idx = pSpar_md->band_coeffs_idx[b].pred_index_re[i]; - ivas_deindex_real_index(&idx, q_lvl, pr_min_max[0], pr_min_max[1], &val, 1); + ivas_deindex_real_index( &idx, q_lvl, pr_min_max[0], pr_min_max[1], &val, 1 ); pSpar_md->band_coeffs[b].pred_re[i] = val; } - for (i = 0; i < FOA_CHANNELS - ndm_per_band[bw * b]; i++) + for ( i = 0; i < FOA_CHANNELS - ndm_per_band[bw * b]; i++ ) { q_lvl = dtx_pd_real_q_levels[ndm_per_band[bw * b] - 1][i]; idx = pSpar_md->band_coeffs_idx[b].decd_index_re[i]; - ivas_deindex_real_index(&idx, q_lvl, dtx_pd_real_min_max[0], dtx_pd_real_min_max[1], &val, 1); + ivas_deindex_real_index( &idx, q_lvl, dtx_pd_real_min_max[0], dtx_pd_real_min_max[1], &val, 1 ); pSpar_md->band_coeffs[b].P_re[i] = val; } } @@ -4335,18 +4328,18 @@ static void ivas_parse_parameter_bitstream_dtx( int16_t *num_dec_per_band ) { int16_t i, j, ndec, ndm; - //float val; + // float val; Word32 val_fx; int16_t idx; - //float pr_min_max[2]; + // float pr_min_max[2]; Word32 pr_min_max_fx[2]; int16_t pr_q_lvls, pr, pd, pd_q_lvls, pr_pd_bits; int16_t zero_pad_bits, sid_bits_len; sid_bits_len = st0->next_bit_pos; - //pr_min_max[0] = pSpar_md->min_max[0]; + // pr_min_max[0] = pSpar_md->min_max[0]; pr_min_max_fx[0] = pSpar_md->min_max_fx[0]; - //pr_min_max[1] = pSpar_md->min_max[1]; + // pr_min_max[1] = pSpar_md->min_max[1]; pr_min_max_fx[1] = pSpar_md->min_max_fx[1]; for ( i = 0; i < num_bands; i++ ) @@ -4383,15 +4376,15 @@ static void ivas_parse_parameter_bitstream_dtx( pr = (int16_t) floor( value / pd_q_lvls ); pd = value - pr * pd_q_lvls; - //val = dtx_pd_real_min_max[0]; + // val = dtx_pd_real_min_max[0]; val_fx = dtx_pd_real_min_max_fx[0]; - //ivas_quantise_real_values( &val, pd_q_lvls, dtx_pd_real_min_max[0], dtx_pd_real_min_max[1], &idx, &val, 1 ); + // ivas_quantise_real_values( &val, pd_q_lvls, dtx_pd_real_min_max[0], dtx_pd_real_min_max[1], &idx, &val, 1 ); ivas_quantise_real_values_fx( &val_fx, pd_q_lvls, dtx_pd_real_min_max_fx[0], dtx_pd_real_min_max_fx[1], &idx, &val_fx, 1 ); pd = pd + idx; - //val = pr_min_max[0]; + // val = pr_min_max[0]; val_fx = pr_min_max_fx[0]; - //ivas_quantise_real_values( &val, pr_q_lvls, pr_min_max[0], pr_min_max[1], &idx, &val, 1 ); + // ivas_quantise_real_values( &val, pr_q_lvls, pr_min_max[0], pr_min_max[1], &idx, &val, 1 ); ivas_quantise_real_values_fx( &val_fx, pr_q_lvls, pr_min_max_fx[0], pr_min_max_fx[1], &idx, &val_fx, 1 ); pr = pr + idx; @@ -4557,38 +4550,38 @@ static ivas_error ivas_deindex_real_index( #else static ivas_error ivas_deindex_real_index_fx( - const int16_t *index, - const int16_t q_levels, - const Word32 min_value, - const Word32 max_value, - Word32 *quant, - const int16_t dim) + const int16_t *index, + const int16_t q_levels, + const Word32 min_value, + const Word32 max_value, + Word32 *quant, + const int16_t dim ) { - int16_t i; - Word32 q_step_fx; - if (q_levels == 0) - { - return IVAS_ERR_INTERNAL; - } + int16_t i; + Word32 q_step_fx; + if ( q_levels == 0 ) + { + return IVAS_ERR_INTERNAL; + } - if (q_levels == 1) - { - for (i = 0; i < dim; i++) + if ( q_levels == 1 ) { - quant[i] = 0; + for ( i = 0; i < dim; i++ ) + { + quant[i] = 0; + } } - } - else - { - q_step_fx = L_sub(max_value, min_value); - q_step_fx = Mpy_32_32(q_step_fx, one_by_q_level[(q_levels - 1)]); - for (i = 0; i < dim; i++) + else { - quant[i] = Mpy_32_32(L_shl(index[i], 31 - 6), q_step_fx);//(25+28)-31 = 22 + q_step_fx = L_sub( max_value, min_value ); + q_step_fx = Mpy_32_32( q_step_fx, one_by_q_level[( q_levels - 1 )] ); + for ( i = 0; i < dim; i++ ) + { + quant[i] = Mpy_32_32( L_shl( index[i], 31 - 6 ), q_step_fx ); //(25+28)-31 = 22 + } } - } - return IVAS_ERR_OK; + return IVAS_ERR_OK; } #endif @@ -4671,11 +4664,11 @@ void ivas_spar_to_dirac( dvx[band] = PR[0] * dvnorm; dvy[band] = PR[1] * dvnorm; dvz[band] = PR[2] * dvnorm; - } + } radius = sqrtf( dvx[band] * dvx[band] + dvy[band] * dvy[band] ); - azi[band] = (int16_t)(max(-180.0f, min(180.0f, atan2f(dvy[band], dvx[band]) / EVS_PI * 180.0f)) + 0.5f); - ele[band] = (int16_t)(max(-90.0f, min(180.0f, atan2f(dvz[band], radius) / EVS_PI * 180.0f)) + 0.5f); + azi[band] = (int16_t) ( max( -180.0f, min( 180.0f, atan2f( dvy[band], dvx[band] ) / EVS_PI * 180.0f ) ) + 0.5f ); + ele[band] = (int16_t) ( max( -90.0f, min( 180.0f, atan2f( dvz[band], radius ) / EVS_PI * 180.0f ) ) + 0.5f ); if ( st_ivas->nchan_transport == 1 ) { @@ -4870,447 +4863,443 @@ void ivas_spar_to_dirac( #else void ivas_spar_to_dirac_fx( - Decoder_Struct *st_ivas, - ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ - const int16_t dtx_vad, /* i : DTX frame flag */ - const int16_t num_bands_out, /* i : number of output bands */ - const int16_t bw, /* i : band joining factor */ - const int16_t dyn_active_w_flag) + Decoder_Struct *st_ivas, + ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ + const int16_t dtx_vad, /* i : DTX frame flag */ + const int16_t num_bands_out, /* i : number of output bands */ + const int16_t bw, /* i : band joining factor */ + const int16_t dyn_active_w_flag ) { - DIRAC_DEC_HANDLE hDirAC; - int16_t start_band, end_band, band, qmf_band_start, qmf_band_end; - int16_t block, b; - int16_t *band_grouping; - //float diffuseness[IVAS_MAX_NUM_BANDS]; - Word32 diffuseness_fx[IVAS_MAX_NUM_BANDS]; - int16_t sba_order_internal; - //float azi_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; - Word32 azi_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; - //float ele_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; - Word32 ele_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; - int16_t azi[IVAS_MAX_NUM_BANDS]; - int16_t ele[IVAS_MAX_NUM_BANDS]; - //float dvx[IVAS_MAX_NUM_BANDS], dvy[IVAS_MAX_NUM_BANDS], dvz[IVAS_MAX_NUM_BANDS]; - Word32 dvx_fx[IVAS_MAX_NUM_BANDS], dvy_fx[IVAS_MAX_NUM_BANDS], dvz_fx[IVAS_MAX_NUM_BANDS]; - //float radius; + DIRAC_DEC_HANDLE hDirAC; + int16_t start_band, end_band, band, qmf_band_start, qmf_band_end; + int16_t block, b; + int16_t *band_grouping; + // float diffuseness[IVAS_MAX_NUM_BANDS]; + Word32 diffuseness_fx[IVAS_MAX_NUM_BANDS]; + int16_t sba_order_internal; + // float azi_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; + Word32 azi_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; + // float ele_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; + Word32 ele_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; + int16_t azi[IVAS_MAX_NUM_BANDS]; + int16_t ele[IVAS_MAX_NUM_BANDS]; + // float dvx[IVAS_MAX_NUM_BANDS], dvy[IVAS_MAX_NUM_BANDS], dvz[IVAS_MAX_NUM_BANDS]; + Word32 dvx_fx[IVAS_MAX_NUM_BANDS], dvy_fx[IVAS_MAX_NUM_BANDS], dvz_fx[IVAS_MAX_NUM_BANDS]; + // float radius; Word32 radius_fx; - //float en_ratio, res_pow; - Word32 en_ratio_fx, res_pow_fx; - Word16 en_ratio_q; - int16_t num_slots_in_subfr; - int16_t tmp_write_idx_param_band; - int16_t tmp_write_idx_band; - //float pred_re_20ms[IVAS_MAX_NUM_BANDS][IVAS_SPAR_MAX_CH - 1]; - Word32 pred_re_20ms_fx[IVAS_MAX_NUM_BANDS][IVAS_SPAR_MAX_CH - 1]; - int16_t pred_idx; - int16_t *dirac_to_spar_md_bands; - int16_t enc_param_start_band; - int16_t active_w_vlbr; - int16_t i, num_subframes; - int16_t active_w; - SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; - - active_w = (dyn_active_w_flag == 1) || (hMdDec->spar_md_cfg.active_w == 1); - sba_order_internal = min(st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER); - start_band = 0; - end_band = min(num_bands_out, SPAR_DIRAC_SPLIT_START_BAND) / bw; - - hDirAC = st_ivas->hDirAC; - hSpatParamRendCom = st_ivas->hSpatParamRendCom; - - dirac_to_spar_md_bands = st_ivas->hSpar->dirac_to_spar_md_bands; - enc_param_start_band = st_ivas->hSpar->enc_param_start_band / bw; - active_w_vlbr = (st_ivas->hDecoderConfig->ivas_total_brate < IVAS_24k4) ? 1 : 0; - - if (hDirAC != NULL && ivas_get_hodirac_flag(st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order) == 0) - { - band_grouping = hDirAC->band_grouping; - num_slots_in_subfr = st_ivas->hDirAC->hConfig->dec_param_estim ? CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES : 1; - - for (band = start_band; band < end_band; band++) - { - //float PR[3], Pd[3], dvnorm, g_pred; - Word32 PR_fx[3], Pd_fx[3], dvnorm_fx, g_pred_fx; - Word16 q_g_pred; - Word16 q_dvnorm; - //PR[0] = hMdDec->spar_md.band_coeffs[band].pred_re[2]; - PR_fx[0] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[2]; - //PR[1] = hMdDec->spar_md.band_coeffs[band].pred_re[0]; - PR_fx[1] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[0]; - //PR[2] = hMdDec->spar_md.band_coeffs[band].pred_re[1]; - PR_fx[2] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[1]; - //g_pred = PR[0] * PR[0] + PR[1] * PR[1] + PR[2] * PR[2]; - g_pred_fx = Mpy_32_32(PR_fx[0], PR_fx[0]) + Mpy_32_32(PR_fx[1], PR_fx[1]) + Mpy_32_32(PR_fx[2], PR_fx[2]); - q_g_pred = Q22 + Q22 - Q31; - q_dvnorm = Q31 - q_g_pred; - q_g_pred = q_dvnorm; - IF ( LE_32 (g_pred_fx, EPSILON_FIX ) ) - { - dvx_fx[band] = ONE_IN_Q22; - dvy_fx[band] = 0; - dvz_fx[band] = 0; - - azi[band] = 0; - ele[band] = 0; - q_g_pred = Q22; - q_dvnorm = Q22; - } - else - { - //g_pred = Sqrt32( g_pred, ); - //dvnorm = 1.0f / g_pred; - dvnorm_fx = ISqrt32(g_pred_fx, &q_dvnorm); - g_pred_fx = Sqrt32(g_pred_fx, &q_g_pred); - if (q_g_pred < 0) - { - g_pred_fx = L_shr(g_pred_fx, (-1 * q_g_pred)); - q_g_pred = 0; - } - - /*dvx[band] = PR[0] * dvnorm; - dvy[band] = PR[1] * dvnorm; - dvz[band] = PR[2] * dvnorm;*/ - - dvx_fx[band] = Mpy_32_32(PR_fx[0], dvnorm_fx); - dvy_fx[band] = Mpy_32_32(PR_fx[1], dvnorm_fx); - dvz_fx[band] = Mpy_32_32(PR_fx[2], dvnorm_fx); - Word16 q_1 = (22) + (31 - q_dvnorm) - 31; - - Word32 temp = Mpy_32_32(dvx_fx[band], dvx_fx[band]) + Mpy_32_32(dvy_fx[band], dvy_fx[band] ); - Word16 q2 = q_1 + q_1 - 31; - Word16 q_temp = 31 - q2; - radius_fx = Sqrt32(temp, &q_temp); - //radius = sqrtf(dvx[band] * dvx[band] + dvy[band] * dvy[band]); - - - //float check_qzi = atan2f(dvy[band], dvx[band]); - Word16 check_azi_fx = BASOP_util_atan2(dvy_fx[band], dvx_fx[band],0); - Word32 check_azi_fx_32 = L_shl(check_azi_fx,16); - Word16 check_azi_fx_res; - IF (LT_32(check_azi_fx_32 ,0)) - { - check_azi_fx_res = negate(divide3232(L_negate(check_azi_fx_32), 1686629760)); - } - ELSE - { - check_azi_fx_res = divide3232(check_azi_fx_32, 1686629760); - } - Word32 azi_intermediate = Mpy_32_16_1(DEGREE_180_Q_22, check_azi_fx_res); - azi_intermediate = azi_intermediate + ONE_IN_Q21; - //Word16 azi_res = L_shr_r(azi_intermediate, 22); - Word16 azi_res = extract_l(azi_intermediate / (1 << 22)); - - Word16 check_ele_fx = BASOP_util_atan2(dvz_fx[band], radius_fx, (9+ q_dvnorm)-q_temp); - Word32 check_ele_fx_32 = L_shl(check_ele_fx, 16); - Word16 check_ele_fx_res; - IF (LT_32(check_azi_fx_32 ,0)) - { - check_ele_fx_res = negate(divide3232(L_negate(check_ele_fx_32), 1686629760)); - } - else - { - check_ele_fx_res = divide3232(check_ele_fx_32, 1686629760); - } - Word32 ele_intermediate = Mpy_32_16_1(DEGREE_180_Q_22, check_ele_fx_res); - ele_intermediate = ele_intermediate + ONE_IN_Q21; - //Word16 ele_res = L_shr_r(ele_intermediate, 22); - Word16 ele_res = extract_l(ele_intermediate/(1<<22)); - - - - //azi[band] = (int16_t)(max(-180.0f, min(180.0f, atan2f(dvy[band], dvx[band]) / EVS_PI * 180.0f)) + 0.5f); - azi[band] = max(-180, min(180, azi_res)); - //ele[band] = (int16_t)(max(-90.0f, min(180.0f, atan2f(dvz[band], radius) / EVS_PI * 180.0f)) + 0.5f); - ele[band] = max(-90, min(180, ele_res)); - } - - if (st_ivas->nchan_transport == 1) - { - //float w_en_norm, f_scale; - Word32 w_en_norm_fx, f_scale_fx; - Word16 q_w_en_norm_fx; - if (active_w) - { - if (dtx_vad == 0) - { - //f_scale = IVAS_ACTIVEW_DM_F_SCALE_DTX; - f_scale_fx = IVAS_ACTIVEW_DM_F_SCALE_DTX_FX; - } - else - { - //f_scale = ( active_w_vlbr ) ? IVAS_ACTIVEW_DM_F_SCALE_VLBR : IVAS_ACTIVEW_DM_F_SCALE; - f_scale_fx = ( active_w_vlbr ) ? IVAS_ACTIVEW_DM_F_SCALE_VLBR_FX : IVAS_ACTIVEW_DM_F_SCALE_FX; - } - } - else - { - //f_scale = 0.0f; - f_scale_fx = 0; - } - - //w_en_norm = ( 1.0f - ( f_scale * g_pred * g_pred ) ); - Word32 temp_result = Mpy_32_32(Mpy_32_32(f_scale_fx, g_pred_fx), g_pred_fx); - temp_result = L_sub(L_shr(ONE_IN_Q31, q_g_pred), temp_result); - //w_en_norm *= w_en_norm; - w_en_norm_fx = Mpy_32_32(temp_result, temp_result); - q_w_en_norm_fx = q_g_pred + q_g_pred; - //Pd[0] = hMdDec->spar_md.band_coeffs[band].P_re[1]; - //Pd[1] = hMdDec->spar_md.band_coeffs[band].P_re[0]; - //Pd[2] = hMdDec->spar_md.band_coeffs[band].P_re[2]; - Pd_fx[0] = hMdDec->spar_md.band_coeffs[band].P_re_fx[1]; - Pd_fx[1] = hMdDec->spar_md.band_coeffs[band].P_re_fx[0]; - Pd_fx[2] = hMdDec->spar_md.band_coeffs[band].P_re_fx[2]; - //en_ratio = PR[0] * PR[0] + PR[1] * PR[1] + PR[2] * PR[2]; - en_ratio_fx = Mpy_32_32(PR_fx[0], PR_fx[0]) + Mpy_32_32(PR_fx[1], PR_fx[1]) + Mpy_32_32(PR_fx[2], PR_fx[2]); //22+22-31 = 13 - Word32 Pd_temp_res = Mpy_32_32(Pd_fx[0], Pd_fx[0]) + Mpy_32_32(Pd_fx[1], Pd_fx[1]) + Mpy_32_32(Pd_fx[2], Pd_fx[2]);//q = 22+22-31 = 13 - //res_pow = w_en_norm + en_ratio + ( Pd[0] * Pd[0] + Pd[1] * Pd[1] + Pd[2] * Pd[2] ); - res_pow_fx = L_shr(w_en_norm_fx, (31- q_w_en_norm_fx)-13) + en_ratio_fx + Pd_temp_res; - //res_pow_q = 13; - res_pow_fx = L_shr(res_pow_fx, 1); - //res_pow *= 0.5f; - //hMdDec->spar_md.en_ratio_slow[band] = 0.75f * hMdDec->spar_md.en_ratio_slow[band] + 0.25f * en_ratio; - hMdDec->spar_md.en_ratio_slow_fx[band] = Mpy_32_32(1610612736, hMdDec->spar_md.en_ratio_slow_fx[band]) + Mpy_32_32(536870912, en_ratio_fx); - //hMdDec->spar_md.ref_pow_slow[band] = 0.75f * hMdDec->spar_md.ref_pow_slow[band] + 0.25f * res_pow; - hMdDec->spar_md.ref_pow_slow_fx[band] = Mpy_32_32(1610612736, hMdDec->spar_md.ref_pow_slow_fx[band]) + Mpy_32_32(536870912, res_pow_fx); - //en_ratio = sqrtf( hMdDec->spar_md.en_ratio_slow[band] ) / ( hMdDec->spar_md.ref_pow_slow[band] + EPSILON ); - en_ratio_q = 31 - 13; - en_ratio_fx = Sqrt32(hMdDec->spar_md.en_ratio_slow_fx[band], &en_ratio_q); - if (en_ratio_q < 0) - { - en_ratio_fx = L_shr(en_ratio_fx, -1 * (en_ratio_q)); - en_ratio_q = 0; - } - Word32 en_ratio_fx_scaled = L_shr(en_ratio_fx, (31 - en_ratio_q - 13)); - if (en_ratio_fx_scaled > hMdDec->spar_md.ref_pow_slow_fx[band]) - { - diffuseness_fx[band] = 0; - } - else if(en_ratio_fx_scaled == 0) - { - diffuseness_fx[band] = ONE_IN_Q30; - } - else if (en_ratio_fx_scaled == hMdDec->spar_md.ref_pow_slow_fx[band]) - { - diffuseness_fx[band] = ONE_IN_Q30; - } - else - { - en_ratio_fx = divide3232(en_ratio_fx_scaled, (hMdDec->spar_md.ref_pow_slow_fx[band] + EPSILON_FX)); - en_ratio_fx = L_shl(en_ratio_fx, 15); - diffuseness_fx[band] = ONE_IN_Q30 - en_ratio_fx; - } + // float en_ratio, res_pow; + Word32 en_ratio_fx, res_pow_fx; + Word16 en_ratio_q; + int16_t num_slots_in_subfr; + int16_t tmp_write_idx_param_band; + int16_t tmp_write_idx_band; + // float pred_re_20ms[IVAS_MAX_NUM_BANDS][IVAS_SPAR_MAX_CH - 1]; + Word32 pred_re_20ms_fx[IVAS_MAX_NUM_BANDS][IVAS_SPAR_MAX_CH - 1]; + int16_t pred_idx; + int16_t *dirac_to_spar_md_bands; + int16_t enc_param_start_band; + int16_t active_w_vlbr; + int16_t i, num_subframes; + int16_t active_w; + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; - } - else - { - //en_ratio = PR[0] * PR[0] + PR[1] * PR[1] + PR[2] * PR[2]; - en_ratio_fx = Mpy_32_32(PR_fx[0] , PR_fx[0]) + Mpy_32_32(PR_fx[1] , PR_fx[1])+ Mpy_32_32(PR_fx[2] , PR_fx[2]); - //hMdDec->spar_md.en_ratio_slow[band] = 0.75f * hMdDec->spar_md.en_ratio_slow[band] + 0.25f * en_ratio; - hMdDec->spar_md.en_ratio_slow_fx[band] = Mpy_32_32(1610612736, hMdDec->spar_md.en_ratio_slow_fx[band]) + Mpy_32_32(536870912, en_ratio_fx); - //en_ratio = sqrtf( hMdDec->spar_md.en_ratio_slow[band] ); - en_ratio_q = 31 - 13; - en_ratio_fx = Sqrt32( hMdDec->spar_md.en_ratio_slow_fx[band], &en_ratio_q); - if (en_ratio_q < 0) - { - en_ratio_fx = L_shr(en_ratio_fx, -1 * (en_ratio_q)); - en_ratio_q = 0; - } - Word32 en_ratio_fx_scaled = L_shr(en_ratio_fx, 1); - if (en_ratio_fx_scaled > ONE_IN_Q30) - { - diffuseness_fx[band] = 0; - } - else - { - diffuseness_fx[band] = ONE_IN_Q30 - en_ratio_fx_scaled; - } - - } - //diffuseness[band] = 1.0f - en_ratio; /*compute diffuseness*/ - // diffuseness[band] = ( ( diffuseness[band] < 1.0f ) ? ( ( diffuseness[band] < 0.0f ) ? 0.f : diffuseness[band] ) : 1.0f ); - //diffuseness[band] = (float)diffuseness_fx[band] / (1 << 30); - } - - for (band = start_band; band < end_band; band++) - { - int16_t azi_dith, ele_dith; - tmp_write_idx_param_band = hDirAC->spar_to_dirac_write_idx; - - //en_ratio = 1.0f - diffuseness[band]; - en_ratio_fx = ONE_IN_Q30 - diffuseness_fx[band]; - //en_ratio = (float)en_ratio_fx / (1 << 30); - //cam delete the below function call - //masa_sq( 1.0f - en_ratio, diffuseness_thresholds, DIRAC_DIFFUSE_LEVELS ); -//#ifdef IVAS_FLOAT_FIXED - masa_sq_fx(ONE_IN_Q30 - en_ratio_fx, diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); -//#endif - - qmf_band_start = band_grouping[band]; - qmf_band_end = band_grouping[band + 1]; - - for (block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++) - { - int16_t ts_start, ts_end, ts; + active_w = ( dyn_active_w_flag == 1 ) || ( hMdDec->spar_md_cfg.active_w == 1 ); + sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); + start_band = 0; + end_band = min( num_bands_out, SPAR_DIRAC_SPLIT_START_BAND ) / bw; + + hDirAC = st_ivas->hDirAC; + hSpatParamRendCom = st_ivas->hSpatParamRendCom; + + dirac_to_spar_md_bands = st_ivas->hSpar->dirac_to_spar_md_bands; + enc_param_start_band = st_ivas->hSpar->enc_param_start_band / bw; + active_w_vlbr = ( st_ivas->hDecoderConfig->ivas_total_brate < IVAS_24k4 ) ? 1 : 0; + + if ( hDirAC != NULL && ivas_get_hodirac_flag( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order ) == 0 ) + { + band_grouping = hDirAC->band_grouping; + num_slots_in_subfr = st_ivas->hDirAC->hConfig->dec_param_estim ? CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES : 1; - ts_start = DirAC_block_grouping[block]; - ts_end = DirAC_block_grouping[block + 1]; - for (b = qmf_band_start; b < qmf_band_end; b++) + for ( band = start_band; band < end_band; band++ ) { + // float PR[3], Pd[3], dvnorm, g_pred; + Word32 PR_fx[3], Pd_fx[3], dvnorm_fx, g_pred_fx; + Word16 q_g_pred; + Word16 q_dvnorm; + // PR[0] = hMdDec->spar_md.band_coeffs[band].pred_re[2]; + PR_fx[0] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[2]; + // PR[1] = hMdDec->spar_md.band_coeffs[band].pred_re[0]; + PR_fx[1] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[0]; + // PR[2] = hMdDec->spar_md.band_coeffs[band].pred_re[1]; + PR_fx[2] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[1]; + // g_pred = PR[0] * PR[0] + PR[1] * PR[1] + PR[2] * PR[2]; + g_pred_fx = Mpy_32_32( PR_fx[0], PR_fx[0] ) + Mpy_32_32( PR_fx[1], PR_fx[1] ) + Mpy_32_32( PR_fx[2], PR_fx[2] ); + q_g_pred = Q22 + Q22 - Q31; + q_dvnorm = Q31 - q_g_pred; + q_g_pred = q_dvnorm; + IF( LE_32( g_pred_fx, EPSILON_FIX ) ) + { + dvx_fx[band] = ONE_IN_Q22; + dvy_fx[band] = 0; + dvz_fx[band] = 0; + + azi[band] = 0; + ele[band] = 0; + q_g_pred = Q22; + q_dvnorm = Q22; + } + else + { + // g_pred = Sqrt32( g_pred, ); + // dvnorm = 1.0f / g_pred; + dvnorm_fx = ISqrt32( g_pred_fx, &q_dvnorm ); + g_pred_fx = Sqrt32( g_pred_fx, &q_g_pred ); + if ( q_g_pred < 0 ) + { + g_pred_fx = L_shr( g_pred_fx, ( -1 * q_g_pred ) ); + q_g_pred = 0; + } + + /*dvx[band] = PR[0] * dvnorm; +dvy[band] = PR[1] * dvnorm; + dvz[band] = PR[2] * dvnorm;*/ - azi_dith = azi[band]; - ele_dith = ele[band]; + dvx_fx[band] = Mpy_32_32( PR_fx[0], dvnorm_fx ); + dvy_fx[band] = Mpy_32_32( PR_fx[1], dvnorm_fx ); + dvz_fx[band] = Mpy_32_32( PR_fx[2], dvnorm_fx ); + Word16 q_1 = ( 22 ) + ( 31 - q_dvnorm ) - 31; + Word32 temp = Mpy_32_32( dvx_fx[band], dvx_fx[band] ) + Mpy_32_32( dvy_fx[band], dvy_fx[band] ); + Word16 q2 = q_1 + q_1 - 31; + Word16 q_temp = 31 - q2; + radius_fx = Sqrt32( temp, &q_temp ); + // radius = sqrtf(dvx[band] * dvx[band] + dvy[band] * dvy[band]); - hSpatParamRendCom->energy_ratio1_fx[block][b] = en_ratio_fx; - tmp_write_idx_band = tmp_write_idx_param_band; - if (hDirAC->hConfig->dec_param_estim == FALSE) - { - hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele_dith; - hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi_dith; + // float check_qzi = atan2f(dvy[band], dvx[band]); + Word16 check_azi_fx = BASOP_util_atan2( dvy_fx[band], dvx_fx[band], 0 ); + Word32 check_azi_fx_32 = L_shl( check_azi_fx, 16 ); + Word16 check_azi_fx_res; + IF( LT_32( check_azi_fx_32, 0 ) ) + { + check_azi_fx_res = negate( divide3232( L_negate( check_azi_fx_32 ), 1686629760 ) ); + } + ELSE + { + check_azi_fx_res = divide3232( check_azi_fx_32, 1686629760 ); + } + Word32 azi_intermediate = Mpy_32_16_1( DEGREE_180_Q_22, check_azi_fx_res ); + azi_intermediate = azi_intermediate + ONE_IN_Q21; + // Word16 azi_res = L_shr_r(azi_intermediate, 22); + Word16 azi_res = extract_l( azi_intermediate / ( 1 << 22 ) ); + + Word16 check_ele_fx = BASOP_util_atan2( dvz_fx[band], radius_fx, ( 9 + q_dvnorm ) - q_temp ); + Word32 check_ele_fx_32 = L_shl( check_ele_fx, 16 ); + Word16 check_ele_fx_res; + IF( LT_32( check_azi_fx_32, 0 ) ) + { + check_ele_fx_res = negate( divide3232( L_negate( check_ele_fx_32 ), 1686629760 ) ); + } + else + { + check_ele_fx_res = divide3232( check_ele_fx_32, 1686629760 ); + } + Word32 ele_intermediate = Mpy_32_16_1( DEGREE_180_Q_22, check_ele_fx_res ); + ele_intermediate = ele_intermediate + ONE_IN_Q21; + // Word16 ele_res = L_shr_r(ele_intermediate, 22); + Word16 ele_res = extract_l( ele_intermediate / ( 1 << 22 ) ); + - hSpatParamRendCom->diffuseness_vector_fx[tmp_write_idx_band][b] = diffuseness_fx[band]; + // azi[band] = (int16_t)(max(-180.0f, min(180.0f, atan2f(dvy[band], dvx[band]) / EVS_PI * 180.0f)) + 0.5f); + azi[band] = max( -180, min( 180, azi_res ) ); + // ele[band] = (int16_t)(max(-90.0f, min(180.0f, atan2f(dvz[band], radius) / EVS_PI * 180.0f)) + 0.5f); + ele[band] = max( -90, min( 180, ele_res ) ); + } - } - else - { - for (ts = ts_start; ts < ts_end; ts++) + if ( st_ivas->nchan_transport == 1 ) { - hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele_dith; - hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi_dith; + // float w_en_norm, f_scale; + Word32 w_en_norm_fx, f_scale_fx; + Word16 q_w_en_norm_fx; + if ( active_w ) + { + if ( dtx_vad == 0 ) + { + // f_scale = IVAS_ACTIVEW_DM_F_SCALE_DTX; + f_scale_fx = IVAS_ACTIVEW_DM_F_SCALE_DTX_FX; + } + else + { + // f_scale = ( active_w_vlbr ) ? IVAS_ACTIVEW_DM_F_SCALE_VLBR : IVAS_ACTIVEW_DM_F_SCALE; + f_scale_fx = ( active_w_vlbr ) ? IVAS_ACTIVEW_DM_F_SCALE_VLBR_FX : IVAS_ACTIVEW_DM_F_SCALE_FX; + } + } + else + { + // f_scale = 0.0f; + f_scale_fx = 0; + } - hSpatParamRendCom->diffuseness_vector_fx[tmp_write_idx_band][b] = diffuseness_fx[band]; - tmp_write_idx_band = (tmp_write_idx_band + 1) % hSpatParamRendCom->dirac_md_buffer_length; + // w_en_norm = ( 1.0f - ( f_scale * g_pred * g_pred ) ); + Word32 temp_result = Mpy_32_32( Mpy_32_32( f_scale_fx, g_pred_fx ), g_pred_fx ); + temp_result = L_sub( L_shr( ONE_IN_Q31, q_g_pred ), temp_result ); + // w_en_norm *= w_en_norm; + w_en_norm_fx = Mpy_32_32( temp_result, temp_result ); + q_w_en_norm_fx = q_g_pred + q_g_pred; + // Pd[0] = hMdDec->spar_md.band_coeffs[band].P_re[1]; + // Pd[1] = hMdDec->spar_md.band_coeffs[band].P_re[0]; + // Pd[2] = hMdDec->spar_md.band_coeffs[band].P_re[2]; + Pd_fx[0] = hMdDec->spar_md.band_coeffs[band].P_re_fx[1]; + Pd_fx[1] = hMdDec->spar_md.band_coeffs[band].P_re_fx[0]; + Pd_fx[2] = hMdDec->spar_md.band_coeffs[band].P_re_fx[2]; + // en_ratio = PR[0] * PR[0] + PR[1] * PR[1] + PR[2] * PR[2]; + en_ratio_fx = Mpy_32_32( PR_fx[0], PR_fx[0] ) + Mpy_32_32( PR_fx[1], PR_fx[1] ) + Mpy_32_32( PR_fx[2], PR_fx[2] ); // 22+22-31 = 13 + Word32 Pd_temp_res = Mpy_32_32( Pd_fx[0], Pd_fx[0] ) + Mpy_32_32( Pd_fx[1], Pd_fx[1] ) + Mpy_32_32( Pd_fx[2], Pd_fx[2] ); // q = 22+22-31 = 13 + // res_pow = w_en_norm + en_ratio + ( Pd[0] * Pd[0] + Pd[1] * Pd[1] + Pd[2] * Pd[2] ); + res_pow_fx = L_shr( w_en_norm_fx, ( 31 - q_w_en_norm_fx ) - 13 ) + en_ratio_fx + Pd_temp_res; + // res_pow_q = 13; + res_pow_fx = L_shr( res_pow_fx, 1 ); + // res_pow *= 0.5f; + // hMdDec->spar_md.en_ratio_slow[band] = 0.75f * hMdDec->spar_md.en_ratio_slow[band] + 0.25f * en_ratio; + hMdDec->spar_md.en_ratio_slow_fx[band] = Mpy_32_32( 1610612736, hMdDec->spar_md.en_ratio_slow_fx[band] ) + Mpy_32_32( 536870912, en_ratio_fx ); + // hMdDec->spar_md.ref_pow_slow[band] = 0.75f * hMdDec->spar_md.ref_pow_slow[band] + 0.25f * res_pow; + hMdDec->spar_md.ref_pow_slow_fx[band] = Mpy_32_32( 1610612736, hMdDec->spar_md.ref_pow_slow_fx[band] ) + Mpy_32_32( 536870912, res_pow_fx ); + // en_ratio = sqrtf( hMdDec->spar_md.en_ratio_slow[band] ) / ( hMdDec->spar_md.ref_pow_slow[band] + EPSILON ); + en_ratio_q = 31 - 13; + en_ratio_fx = Sqrt32( hMdDec->spar_md.en_ratio_slow_fx[band], &en_ratio_q ); + if ( en_ratio_q < 0 ) + { + en_ratio_fx = L_shr( en_ratio_fx, -1 * ( en_ratio_q ) ); + en_ratio_q = 0; + } + Word32 en_ratio_fx_scaled = L_shr( en_ratio_fx, ( 31 - en_ratio_q - 13 ) ); + if ( en_ratio_fx_scaled > hMdDec->spar_md.ref_pow_slow_fx[band] ) + { + diffuseness_fx[band] = 0; + } + else if ( en_ratio_fx_scaled == 0 ) + { + diffuseness_fx[band] = ONE_IN_Q30; + } + else if ( en_ratio_fx_scaled == hMdDec->spar_md.ref_pow_slow_fx[band] ) + { + diffuseness_fx[band] = ONE_IN_Q30; + } + else + { + en_ratio_fx = divide3232( en_ratio_fx_scaled, ( hMdDec->spar_md.ref_pow_slow_fx[band] + EPSILON_FX ) ); + en_ratio_fx = L_shl( en_ratio_fx, 15 ); + diffuseness_fx[band] = ONE_IN_Q30 - en_ratio_fx; + } + } + else + { + // en_ratio = PR[0] * PR[0] + PR[1] * PR[1] + PR[2] * PR[2]; + en_ratio_fx = Mpy_32_32( PR_fx[0], PR_fx[0] ) + Mpy_32_32( PR_fx[1], PR_fx[1] ) + Mpy_32_32( PR_fx[2], PR_fx[2] ); + // hMdDec->spar_md.en_ratio_slow[band] = 0.75f * hMdDec->spar_md.en_ratio_slow[band] + 0.25f * en_ratio; + hMdDec->spar_md.en_ratio_slow_fx[band] = Mpy_32_32( 1610612736, hMdDec->spar_md.en_ratio_slow_fx[band] ) + Mpy_32_32( 536870912, en_ratio_fx ); + // en_ratio = sqrtf( hMdDec->spar_md.en_ratio_slow[band] ); + en_ratio_q = 31 - 13; + en_ratio_fx = Sqrt32( hMdDec->spar_md.en_ratio_slow_fx[band], &en_ratio_q ); + if ( en_ratio_q < 0 ) + { + en_ratio_fx = L_shr( en_ratio_fx, -1 * ( en_ratio_q ) ); + en_ratio_q = 0; + } + Word32 en_ratio_fx_scaled = L_shr( en_ratio_fx, 1 ); + if ( en_ratio_fx_scaled > ONE_IN_Q30 ) + { + diffuseness_fx[band] = 0; + } + else + { + diffuseness_fx[band] = ONE_IN_Q30 - en_ratio_fx_scaled; + } } - } + // diffuseness[band] = 1.0f - en_ratio; /*compute diffuseness*/ + // diffuseness[band] = ( ( diffuseness[band] < 1.0f ) ? ( ( diffuseness[band] < 0.0f ) ? 0.f : diffuseness[band] ) : 1.0f ); + // diffuseness[band] = (float)diffuseness_fx[band] / (1 << 30); } - tmp_write_idx_param_band = (tmp_write_idx_param_band + num_slots_in_subfr) % hSpatParamRendCom->dirac_md_buffer_length; - } - } - /* update buffer write index */ - if (hDirAC->hConfig->dec_param_estim == FALSE) - { - hDirAC->spar_to_dirac_write_idx = (hDirAC->spar_to_dirac_write_idx + MAX_PARAM_SPATIAL_SUBFRAMES) % hSpatParamRendCom->dirac_md_buffer_length; + for ( band = start_band; band < end_band; band++ ) + { + int16_t azi_dith, ele_dith; + tmp_write_idx_param_band = hDirAC->spar_to_dirac_write_idx; + + // en_ratio = 1.0f - diffuseness[band]; + en_ratio_fx = ONE_IN_Q30 - diffuseness_fx[band]; + // en_ratio = (float)en_ratio_fx / (1 << 30); + // cam delete the below function call + // masa_sq( 1.0f - en_ratio, diffuseness_thresholds, DIRAC_DIFFUSE_LEVELS ); + //#ifdef IVAS_FLOAT_FIXED + masa_sq_fx( ONE_IN_Q30 - en_ratio_fx, diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); + //#endif + + qmf_band_start = band_grouping[band]; + qmf_band_end = band_grouping[band + 1]; + + for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) + { + int16_t ts_start, ts_end, ts; + + ts_start = DirAC_block_grouping[block]; + ts_end = DirAC_block_grouping[block + 1]; + for ( b = qmf_band_start; b < qmf_band_end; b++ ) + { + + azi_dith = azi[band]; + ele_dith = ele[band]; + + + hSpatParamRendCom->energy_ratio1_fx[block][b] = en_ratio_fx; + tmp_write_idx_band = tmp_write_idx_param_band; + + if ( hDirAC->hConfig->dec_param_estim == FALSE ) + { + hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele_dith; + hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi_dith; + + hSpatParamRendCom->diffuseness_vector_fx[tmp_write_idx_band][b] = diffuseness_fx[band]; + } + else + { + for ( ts = ts_start; ts < ts_end; ts++ ) + { + hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele_dith; + hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi_dith; + + hSpatParamRendCom->diffuseness_vector_fx[tmp_write_idx_band][b] = diffuseness_fx[band]; + tmp_write_idx_band = ( tmp_write_idx_band + 1 ) % hSpatParamRendCom->dirac_md_buffer_length; + } + } + } + tmp_write_idx_param_band = ( tmp_write_idx_param_band + num_slots_in_subfr ) % hSpatParamRendCom->dirac_md_buffer_length; + } + } + + /* update buffer write index */ + if ( hDirAC->hConfig->dec_param_estim == FALSE ) + { + hDirAC->spar_to_dirac_write_idx = ( hDirAC->spar_to_dirac_write_idx + MAX_PARAM_SPATIAL_SUBFRAMES ) % hSpatParamRendCom->dirac_md_buffer_length; + } + else + { + hDirAC->spar_to_dirac_write_idx = ( hDirAC->spar_to_dirac_write_idx + CLDFB_NO_COL_MAX ) % hSpatParamRendCom->dirac_md_buffer_length; + } } else { - hDirAC->spar_to_dirac_write_idx = (hDirAC->spar_to_dirac_write_idx + CLDFB_NO_COL_MAX) % hSpatParamRendCom->dirac_md_buffer_length; + band = end_band; } - } - else - { - band = end_band; - } - /*read DirAC metadata, convert DirAC to SPAR*/ - for (; band < num_bands_out / bw; band++) - { - int16_t dirac_band_idx; + /*read DirAC metadata, convert DirAC to SPAR*/ + for ( ; band < num_bands_out / bw; band++ ) + { + int16_t dirac_band_idx; - dirac_band_idx = dirac_to_spar_md_bands[band] - enc_param_start_band; + dirac_band_idx = dirac_to_spar_md_bands[band] - enc_param_start_band; - num_subframes = MAX_PARAM_SPATIAL_SUBFRAMES; - if (st_ivas->hQMetaData->useLowerRes) - { - num_subframes = 1; - } - - for (block = 0; block < num_subframes; block++) - { - //if ( st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth[block] < 0.f ) - //{ - // st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth[block] += 360.f; - //} - if ( st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth_fx[block] < 0 ) - { - st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth_fx[block] = - L_add(L_shl(360, 22), st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth_fx[block]); - } - //azi_dirac[band][block] = st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth[block]; - //ele_dirac[band][block] = st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].elevation[block]; -//#ifdef IVAS_FLOAT_FIXED - azi_dirac_fx[band][block] = st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth_fx[block]; - ele_dirac_fx[band][block] = st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].elevation_fx[block]; -//#endif - } - - //diffuseness[band] = 1.0f - st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].energy_ratio[0]; -//#ifdef IVAS_FLOAT_FIXED - diffuseness_fx[band] = ONE_IN_Q30 - st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].energy_ratio_fx[0]; -//#endif - } - - /* DirAC MD averaged over 4 subframes and converted to SPAR format similar to encoder processing */ - if (hMdDec->spar_md_cfg.nchan_transport > 1) - { + num_subframes = MAX_PARAM_SPATIAL_SUBFRAMES; + if ( st_ivas->hQMetaData->useLowerRes ) + { + num_subframes = 1; + } + + for ( block = 0; block < num_subframes; block++ ) + { + // if ( st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth[block] < 0.f ) + //{ + // st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth[block] += 360.f; + // } + if ( st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth_fx[block] < 0 ) + { + st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth_fx[block] = + L_add( L_shl( 360, 22 ), st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth_fx[block] ); + } + // azi_dirac[band][block] = st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth[block]; + // ele_dirac[band][block] = st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].elevation[block]; + //#ifdef IVAS_FLOAT_FIXED + azi_dirac_fx[band][block] = st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth_fx[block]; + ele_dirac_fx[band][block] = st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].elevation_fx[block]; + //#endif + } + + // diffuseness[band] = 1.0f - st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].energy_ratio[0]; + //#ifdef IVAS_FLOAT_FIXED + diffuseness_fx[band] = ONE_IN_Q30 - st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].energy_ratio_fx[0]; + //#endif + } + + /* DirAC MD averaged over 4 subframes and converted to SPAR format similar to encoder processing */ + if ( hMdDec->spar_md_cfg.nchan_transport > 1 ) + { #ifdef IVAS_FLOAT_FIXED - ivas_get_spar_md_from_dirac_fx( azi_dirac_fx, ele_dirac_fx, diffuseness_fx, 1, NULL, &hMdDec->spar_md, &hMdDec->spar_md_cfg, end_band, num_bands_out, ( hMdDec->spar_hoa_md_flag ) ? 1 : sba_order_internal, dtx_vad, NULL, st_ivas->hQMetaData->useLowerRes, active_w_vlbr, dyn_active_w_flag ); + ivas_get_spar_md_from_dirac_fx( azi_dirac_fx, ele_dirac_fx, diffuseness_fx, 1, NULL, &hMdDec->spar_md, &hMdDec->spar_md_cfg, end_band, num_bands_out, ( hMdDec->spar_hoa_md_flag ) ? 1 : sba_order_internal, dtx_vad, NULL, st_ivas->hQMetaData->useLowerRes, active_w_vlbr, dyn_active_w_flag ); #else - ivas_get_spar_md_from_dirac(azi_dirac, ele_dirac, diffuseness, 1, NULL, &hMdDec->spar_md, &hMdDec->spar_md_cfg, end_band, num_bands_out, (hMdDec->spar_hoa_md_flag) ? 1 : sba_order_internal, dtx_vad, NULL, st_ivas->hQMetaData->useLowerRes, active_w_vlbr, dyn_active_w_flag); + ivas_get_spar_md_from_dirac( azi_dirac, ele_dirac, diffuseness, 1, NULL, &hMdDec->spar_md, &hMdDec->spar_md_cfg, end_band, num_bands_out, ( hMdDec->spar_hoa_md_flag ) ? 1 : sba_order_internal, dtx_vad, NULL, st_ivas->hQMetaData->useLowerRes, active_w_vlbr, dyn_active_w_flag ); #endif - /* temporarily copy frame-wise prediction coefficients in DirAC bands*/ - for (pred_idx = 0; pred_idx < FOA_CHANNELS - 1; pred_idx++) - { - for (band = SPAR_DIRAC_SPLIT_START_BAND; band < IVAS_MAX_NUM_BANDS; band++) - { - //pred_re_20ms[band][pred_idx] = hMdDec->spar_md.band_coeffs[band].pred_re[pred_idx]; - pred_re_20ms_fx[band][pred_idx] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[pred_idx]; - } + /* temporarily copy frame-wise prediction coefficients in DirAC bands*/ + for ( pred_idx = 0; pred_idx < FOA_CHANNELS - 1; pred_idx++ ) + { + for ( band = SPAR_DIRAC_SPLIT_START_BAND; band < IVAS_MAX_NUM_BANDS; band++ ) + { + // pred_re_20ms[band][pred_idx] = hMdDec->spar_md.band_coeffs[band].pred_re[pred_idx]; + pred_re_20ms_fx[band][pred_idx] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[pred_idx]; + } + } } - } - int16_t num_md_sub_frames; - num_md_sub_frames = ivas_get_spar_dec_md_num_subframes(sba_order_internal, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate); -//#ifdef IVAS_FLOAT_FIXED - ivas_get_spar_md_from_dirac_fx( azi_dirac_fx, ele_dirac_fx, diffuseness_fx, num_md_sub_frames, NULL, &hMdDec->spar_md, &hMdDec->spar_md_cfg, end_band, num_bands_out / bw, ( hMdDec->spar_hoa_md_flag ) ? 1 : sba_order_internal, dtx_vad, NULL, st_ivas->hQMetaData->useLowerRes, active_w_vlbr, dyn_active_w_flag ); -//#else -// ivas_get_spar_md_from_dirac( azi_dirac, ele_dirac, diffuseness, num_md_sub_frames, NULL, &hMdDec->spar_md, &hMdDec->spar_md_cfg, end_band, num_bands_out / bw, ( hMdDec->spar_hoa_md_flag ) ? 1 : sba_order_internal, dtx_vad, NULL, st_ivas->hQMetaData->useLowerRes, active_w_vlbr, dyn_active_w_flag ); -//#endif - if (st_ivas->hQMetaData->useLowerRes && dtx_vad) - { - for (band = SPAR_DIRAC_SPLIT_START_BAND; band < IVAS_MAX_NUM_BANDS; band++) + int16_t num_md_sub_frames; + num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( sba_order_internal, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ); + //#ifdef IVAS_FLOAT_FIXED + ivas_get_spar_md_from_dirac_fx( azi_dirac_fx, ele_dirac_fx, diffuseness_fx, num_md_sub_frames, NULL, &hMdDec->spar_md, &hMdDec->spar_md_cfg, end_band, num_bands_out / bw, ( hMdDec->spar_hoa_md_flag ) ? 1 : sba_order_internal, dtx_vad, NULL, st_ivas->hQMetaData->useLowerRes, active_w_vlbr, dyn_active_w_flag ); + //#else + // ivas_get_spar_md_from_dirac( azi_dirac, ele_dirac, diffuseness, num_md_sub_frames, NULL, &hMdDec->spar_md, &hMdDec->spar_md_cfg, end_band, num_bands_out / bw, ( hMdDec->spar_hoa_md_flag ) ? 1 : sba_order_internal, dtx_vad, NULL, st_ivas->hQMetaData->useLowerRes, active_w_vlbr, dyn_active_w_flag ); + //#endif + if ( st_ivas->hQMetaData->useLowerRes && dtx_vad ) { - for (block = 1; block < num_md_sub_frames; block++) - { - for (i = 0; i < FOA_CHANNELS - 1; i++) /* pred coefficient index (index 0, 1, 2 predicts Y, Z, X respectively) */ - { - //hMdDec->spar_md.band_coeffs[band + block * IVAS_MAX_NUM_BANDS].pred_re[i] = hMdDec->spar_md.band_coeffs[band].pred_re[i]; - hMdDec->spar_md.band_coeffs[band + block * IVAS_MAX_NUM_BANDS].pred_re_fx[i] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[i]; - } - for (i = 0; i < FOA_CHANNELS - 1; i++) /* pred coefficient index (index 0, 1, 2 predicts Y, Z, X respectively) */ + for ( band = SPAR_DIRAC_SPLIT_START_BAND; band < IVAS_MAX_NUM_BANDS; band++ ) { - //hMdDec->spar_md.band_coeffs[band + block * IVAS_MAX_NUM_BANDS].P_re[i] = hMdDec->spar_md.band_coeffs[band].P_re[i]; - hMdDec->spar_md.band_coeffs[band + block * IVAS_MAX_NUM_BANDS].P_re_fx[i] = hMdDec->spar_md.band_coeffs[band].P_re_fx[i]; + for ( block = 1; block < num_md_sub_frames; block++ ) + { + for ( i = 0; i < FOA_CHANNELS - 1; i++ ) /* pred coefficient index (index 0, 1, 2 predicts Y, Z, X respectively) */ + { + // hMdDec->spar_md.band_coeffs[band + block * IVAS_MAX_NUM_BANDS].pred_re[i] = hMdDec->spar_md.band_coeffs[band].pred_re[i]; + hMdDec->spar_md.band_coeffs[band + block * IVAS_MAX_NUM_BANDS].pred_re_fx[i] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[i]; + } + for ( i = 0; i < FOA_CHANNELS - 1; i++ ) /* pred coefficient index (index 0, 1, 2 predicts Y, Z, X respectively) */ + { + // hMdDec->spar_md.band_coeffs[band + block * IVAS_MAX_NUM_BANDS].P_re[i] = hMdDec->spar_md.band_coeffs[band].P_re[i]; + hMdDec->spar_md.band_coeffs[band + block * IVAS_MAX_NUM_BANDS].P_re_fx[i] = hMdDec->spar_md.band_coeffs[band].P_re_fx[i]; + } + } } - } } - } - /* expand DirAC TC 20ms MD for residual channels to all subframes*/ - for (block = 0; block < num_md_sub_frames; block++) - { - for (band = SPAR_DIRAC_SPLIT_START_BAND; band < IVAS_MAX_NUM_BANDS; band++) + /* expand DirAC TC 20ms MD for residual channels to all subframes*/ + for ( block = 0; block < num_md_sub_frames; block++ ) { - for (pred_idx = 0; pred_idx < FOA_CHANNELS - 1; pred_idx++) /* pred coefficient index (index 0, 1, 2 predicts Y, Z, X respectively) */ - { - if (ivas_is_res_channel(pred_idx + 1, hMdDec->spar_md_cfg.nchan_transport)) + for ( band = SPAR_DIRAC_SPLIT_START_BAND; band < IVAS_MAX_NUM_BANDS; band++ ) { - /* use 20ms coefficients only for residual channels */ - //hMdDec->spar_md.band_coeffs[band + block * IVAS_MAX_NUM_BANDS].pred_re[pred_idx] = pred_re_20ms[band][pred_idx]; - hMdDec->spar_md.band_coeffs[band + block * IVAS_MAX_NUM_BANDS].pred_re_fx[pred_idx] = pred_re_20ms_fx[band][pred_idx]; + for ( pred_idx = 0; pred_idx < FOA_CHANNELS - 1; pred_idx++ ) /* pred coefficient index (index 0, 1, 2 predicts Y, Z, X respectively) */ + { + if ( ivas_is_res_channel( pred_idx + 1, hMdDec->spar_md_cfg.nchan_transport ) ) + { + /* use 20ms coefficients only for residual channels */ + // hMdDec->spar_md.band_coeffs[band + block * IVAS_MAX_NUM_BANDS].pred_re[pred_idx] = pred_re_20ms[band][pred_idx]; + hMdDec->spar_md.band_coeffs[band + block * IVAS_MAX_NUM_BANDS].pred_re_fx[pred_idx] = pred_re_20ms_fx[band][pred_idx]; + } + } } - } } - } - for (b = end_band * bw; b < num_bands_out; b++) - { - hMdDec->valid_bands[b] = 1; - } + for ( b = end_band * bw; b < num_bands_out; b++ ) + { + hMdDec->valid_bands[b] = 1; + } - return; + return; } #endif @@ -5355,8 +5344,7 @@ static void ivas_parse_parameter_bitstream_dtx( ivas_spar_md_t *pSpar_md, Decode static ivas_error ivas_deindex_real_index( const int16_t *index, const int16_t q_levels, const float min_value, const float max_value, float *quant, const int16_t num_ch_dim2 ); -static void ivas_spar_dec_parse_md_bs( ivas_spar_md_dec_state_t *hMdDec, Decoder_State *st, int16_t *nB, int16_t *bands_bw, int16_t *dtx_vad, const int32_t ivas_total_brate, const int16_t sba_inactive_mode -); +static void ivas_spar_dec_parse_md_bs( ivas_spar_md_dec_state_t *hMdDec, Decoder_State *st, int16_t *nB, int16_t *bands_bw, int16_t *dtx_vad, const int32_t ivas_total_brate, const int16_t sba_inactive_mode ); /*------------------------------------------------------------------------- @@ -6038,8 +6026,7 @@ void ivas_spar_md_dec_process( } ivas_spar_dec_parse_md_bs( hMdDec, st0, &nB, &bw, &dtx_vad, st_ivas->hDecoderConfig->ivas_total_brate, - st_ivas->hQMetaData->sba_inactive_mode - ); + st_ivas->hQMetaData->sba_inactive_mode ); assert( nB == hMdDec->spar_md.num_bands ); assert( bw == 1 ); @@ -6685,7 +6672,6 @@ void ivas_spar_dec_gen_umx_mat( } } } - } ivas_spar_dec_compute_ramp_down_post_matrix( hMdDec, num_bands_out, bfi, num_md_sub_frames ); @@ -6748,8 +6734,7 @@ static void ivas_spar_dec_parse_md_bs( int16_t *bands_bw, int16_t *dtx_vad, const int32_t ivas_total_brate, - const int16_t sba_inactive_mode -) + const int16_t sba_inactive_mode ) { int16_t i, j, k, num_bands; int16_t ii, jj, ndec, ndm; @@ -7996,4 +7981,4 @@ void ivas_spar_to_dirac( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index e12b810fa..c6c307fda 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -106,31 +106,31 @@ typedef struct stereo_dft_dec_data_struct #endif - int16_t dft32ms_ovl; /* Overlap size */ + int16_t dft32ms_ovl; /* Overlap size */ #ifndef IVAS_FLOAT_FIXED const float *win32ms; /* DFT window */ const float *win32ms_12k8; /* DFT window */ const float *win32ms_16k; /* DFT window */ const float *win32ms_8k; /* DFT window */ #else - const Word16 *win32ms_fx; /* DFT window */ /* Q15 */ - const Word16 *win32ms_12k8_fx; /* DFT window */ /* Q15 */ - const Word16 *win32ms_16k_fx; /* DFT window */ /* Q15 */ - const Word16 *win32ms_8k_fx; /* DFT window */ /* Q15 */ + const Word16 *win32ms_fx; /* DFT window */ /* Q15 */ + const Word16 *win32ms_12k8_fx; /* DFT window */ /* Q15 */ + const Word16 *win32ms_16k_fx; /* DFT window */ /* Q15 */ + const Word16 *win32ms_8k_fx; /* DFT window */ /* Q15 */ #endif - int16_t dft32ms_ovl2; /* Overlap2 size */ + int16_t dft32ms_ovl2; /* Overlap2 size */ #ifndef IVAS_FLOAT_FIXED const float *win232ms; /* DFT window */ const float *win232ms_12k8; /* DFT window */ const float *win232ms_16k; /* DFT window */ const float *win232ms_8k; /* DFT window */ #else - const Word16 *win232ms_fx; /* DFT window */ /* Q15 */ - const Word16 *win232ms_12k8_fx; /* DFT window */ /* Q15 */ - const Word16 *win232ms_16k_fx; /* DFT window */ /* Q15 */ - const Word16 *win232ms_8k_fx; /* DFT window */ /* Q15 */ - const Word16 *win_8k_fx; /* DFT window residual */ /* Q15 */ + const Word16 *win232ms_fx; /* DFT window */ /* Q15 */ + const Word16 *win232ms_12k8_fx; /* DFT window */ /* Q15 */ + const Word16 *win232ms_16k_fx; /* DFT window */ /* Q15 */ + const Word16 *win232ms_8k_fx; /* DFT window */ /* Q15 */ + const Word16 *win_8k_fx; /* DFT window residual */ /* Q15 */ #endif #ifndef IVAS_FLOAT_FIXED @@ -149,7 +149,7 @@ typedef struct stereo_dft_dec_data_struct #ifndef IVAS_FLOAT_FIXED float side_gain[STEREO_DFT_DEC_DFT_NB * STEREO_DFT_BAND_MAX]; #else - Word32 side_gain_fx[STEREO_DFT_DEC_DFT_NB * STEREO_DFT_BAND_MAX]; /* Q31 */ + Word32 side_gain_fx[STEREO_DFT_DEC_DFT_NB * STEREO_DFT_BAND_MAX]; /* Q31 */ #endif int16_t side_gain_flag_1; int16_t side_gain_flag_2; @@ -159,7 +159,7 @@ typedef struct stereo_dft_dec_data_struct #ifndef IVAS_FLOAT_FIXED float gipd[STEREO_DFT_DEC_DFT_NB]; #else - Word32 gipd_fx[STEREO_DFT_DEC_DFT_NB]; /* Q13 */ + Word32 gipd_fx[STEREO_DFT_DEC_DFT_NB]; /* Q13 */ #endif int16_t no_ipd_flag; /* flag to indicate when no IPD gets used */ @@ -186,7 +186,7 @@ typedef struct stereo_dft_dec_data_struct #endif /*residual prediction*/ - int16_t res_pred_mode[STEREO_DFT_DEC_DFT_NB]; /* residual prediction mode: 0(off), 1(stereo filling only), 2(enhanced stereo filling) */ + int16_t res_pred_mode[STEREO_DFT_DEC_DFT_NB]; /* residual prediction mode: 0(off), 1(stereo filling only), 2(enhanced stereo filling) */ #ifndef IVAS_FLOAT_FIXED float res_pred_gain[STEREO_DFT_DEC_DFT_NB * STEREO_DFT_BAND_MAX]; /* prediction gain for the residual HFs */ #endif @@ -202,9 +202,9 @@ typedef struct stereo_dft_dec_data_struct Word32 ipd_xfade_prev_fx; /* Q13 */ Word32 res_pred_gain_fx[STEREO_DFT_DEC_DFT_NB * STEREO_DFT_BAND_MAX]; /* prediction gain for the residual HFs */ /* Q31 */ #endif - int16_t res_pred_band_min; /* Band min for prediction of residual */ + int16_t res_pred_band_min; /* Band min for prediction of residual */ #ifndef IVAS_FLOAT_FIXED - float DFT_past_DMX[STEREO_DFT_PAST_MAX][STEREO_DFT32MS_N_32k]; /* Past DMX for residual prediction */ + float DFT_past_DMX[STEREO_DFT_PAST_MAX][STEREO_DFT32MS_N_32k]; /* Past DMX for residual prediction */ #endif int16_t past_DMX_pos; int16_t res_pred_flag_0; @@ -243,7 +243,7 @@ typedef struct stereo_dft_dec_data_struct Word16 q_smoothed_nrg; Word16 q_DFT_past_DMX_fx[STEREO_DFT_PAST_MAX]; Word32 res_global_gain_fx; /* Q15 */ -#endif // IVAS_FLOAT_FIXED +#endif // IVAS_FLOAT_FIXED #ifndef IVAS_FLOAT_FIXED float res_cod_mem[STEREO_DFT_OVL_8k]; float buff_LBTCX_mem[NS2SA( 16000, STEREO_DFT32MS_OVL_NS )]; @@ -330,7 +330,7 @@ typedef struct stereo_dft_dec_data_struct #ifndef IVAS_FLOAT_FIXED float g_state[STEREO_DFT_BAND_MAX]; #else - Word16 g_state_fx[STEREO_DFT_BAND_MAX]; /* Q15 */ + Word16 g_state_fx[STEREO_DFT_BAND_MAX]; /* Q15 */ #endif int16_t frame_sid_nodata; int16_t frame_nodata; @@ -339,7 +339,7 @@ typedef struct stereo_dft_dec_data_struct #ifndef IVAS_FLOAT_FIXED float scale; #else - Word16 scale_fx; /* Q15 */ + Word16 scale_fx; /* Q15 */ #endif /* PLC on residual signal */ @@ -378,10 +378,10 @@ typedef struct stereo_dft_dec_data_struct float g_R_prev; const float *max_smooth_gains, *min_smooth_gains; #else - Word32 mixer_mat_smooth_fx[2][4][2 * IVAS_MAX_NUM_BANDS]; /* Q31 */ - Word32 g_L_prev_fx; /* Q31 */ - Word32 g_R_prev_fx; /* Q31 */ - const Word16 *max_smooth_gains_fx, *min_smooth_gains_fx; /* Q15 */ + Word32 mixer_mat_smooth_fx[2][4][2 * IVAS_MAX_NUM_BANDS]; /* Q31 */ + Word32 g_L_prev_fx; /* Q31 */ + Word32 g_R_prev_fx; /* Q31 */ + const Word16 *max_smooth_gains_fx, *min_smooth_gains_fx; /* Q15 */ #endif } STEREO_DFT_DEC_DATA, *STEREO_DFT_DEC_DATA_HANDLE; @@ -394,16 +394,16 @@ typedef struct stereo_dft_dmx_out_data_structure float targetGain; /* TCA gain norm applied on target (or right) channel in current frame */ float prevTargetGain; /* TCA gain norm applied on target (or right) channel in previous frame */ #else - Word32 targetGain_fx; /* Q29 */ - Word32 prevTargetGain_fx; /* Q29 */ + Word32 targetGain_fx; /* Q29 */ + Word32 prevTargetGain_fx; /* Q29 */ #endif #ifndef IVAS_FLOAT_FIXED float memOutHB[NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS )]; float memTransitionHB[NS2SA( 48000, STEREO_DFT32MS_OVL_NS )]; #else - Word32 memOutHB_fx[NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS )]; /* Q11 */ - Word32 memTransitionHB_fx[NS2SA( 48000, STEREO_DFT32MS_OVL_NS )]; /* Q11 */ + Word32 memOutHB_fx[NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS )]; /* Q11 */ + Word32 memTransitionHB_fx[NS2SA( 48000, STEREO_DFT32MS_OVL_NS )]; /* Q11 */ #endif } STEREO_DFT_DMX_DATA, *STEREO_DFT_DMX_DATA_HANDLE; @@ -483,14 +483,14 @@ typedef struct stereo_td_dec_data_structure #ifndef IVAS_FLOAT_FIXED float TCX_old_syn_Overl[L_FRAME16k / 2]; /* past ovrl buffer for possible switching from TD stereo ACELP to MDCT stereo TCX frame */ - float prevSP_ratio; /* previous SP ratio */ - float SP_ratio_LT; /* longterm SP ratio */ - float c_LR_LT; /* left-right cross-correlation */ + float prevSP_ratio; /* previous SP ratio */ + float SP_ratio_LT; /* longterm SP ratio */ + float c_LR_LT; /* left-right cross-correlation */ #else Word32 TCX_old_syn_Overl_fx[L_FRAME16k / 2]; /* past ovrl buffer for possible switching from TD stereo ACELP to MDCT stereo TCX frame */ /* Q11 */ - Word16 prevSP_ratio_fx; /* previous SP ratio */ - Word32 SP_ratio_LT_fx; /* longterm SP ratio */ - Word32 c_LR_LT_fx; /* left-right cross-correlation */ + Word16 prevSP_ratio_fx; /* previous SP ratio */ + Word32 SP_ratio_LT_fx; /* longterm SP ratio */ + Word32 c_LR_LT_fx; /* left-right cross-correlation */ #endif } STEREO_TD_DEC_DATA, *STEREO_TD_DEC_DATA_HANDLE; @@ -519,21 +519,21 @@ typedef struct stereo_mdct_dec_data_structure #ifndef IVAS_FLOAT_FIXED float itd; #else - Word32 itd_fx; /* Q15 */ + Word32 itd_fx; /* Q15 */ #endif int16_t reverse_dmx; #ifndef IVAS_FLOAT_FIXED float smooth_ratio; #else - Word32 smooth_ratio_fx; /* Q26 */ + Word32 smooth_ratio_fx; /* Q26 */ #endif int16_t prev_ms_mask[NB_DIV][MAX_SFB]; #ifndef IVAS_FLOAT_FIXED float lastCoh; #else - Word16 lastCoh_fx; /* Q14 */ + Word16 lastCoh_fx; /* Q14 */ #endif int16_t noise_seeds_channels[CPE_CHANNELS]; int16_t noise_seed_common; @@ -556,8 +556,8 @@ typedef struct stereo_tca_dec_data_structure float targetGain; /* gain norm applied on target (or right) channel in current frame */ float prevTargetGain; /* gain norm applied on target (or right) channel in previous frame */ #else - Word32 targetGain_fx; /* gain norm applied on target (or right) channel in current frame */ // Q29 - Word32 prevTargetGain_fx; /* gain norm applied on target (or right) channel in previous frame */ // Q29 + Word32 targetGain_fx; /* gain norm applied on target (or right) channel in current frame */ // Q29 + Word32 prevTargetGain_fx; /* gain norm applied on target (or right) channel in previous frame */ // Q29 #endif int16_t corrLagStats; /* corr lag stats in current frame */ @@ -571,8 +571,8 @@ typedef struct stereo_tca_dec_data_structure Word32 memChanL_fx[L_DEC_MEM_LEN_ICA]; /* left channel input to correct at the cross-over for Fixed */ Word32 memChanR_fx[L_DEC_MEM_LEN_ICA]; /* right channel input to correct at the cross-over for Fixed */ #else - float memChanL[L_DEC_MEM_LEN_ICA]; /* left channel input to correct at the cross-over */ - float memChanR[L_DEC_MEM_LEN_ICA]; /* right channel input to correct at the cross-over */ + float memChanL[L_DEC_MEM_LEN_ICA]; /* left channel input to correct at the cross-over */ + float memChanR[L_DEC_MEM_LEN_ICA]; /* right channel input to correct at the cross-over */ #endif } STEREO_TCA_DEC_DATA, *STEREO_TCA_DEC_HANDLE; @@ -594,9 +594,9 @@ typedef struct stereo_icbwe_dec_data_structure float memTransitionHB[CPE_CHANNELS][NS2SA( 48000, STEREO_DFT32MS_OVL_NS )]; #else - Word32 memOutHB_fx[CPE_CHANNELS][NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS )]; /* Q11 */ + Word32 memOutHB_fx[CPE_CHANNELS][NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS )]; /* Q11 */ - Word32 memTransitionHB_fx[CPE_CHANNELS][NS2SA( 48000, STEREO_DFT32MS_OVL_NS )]; /* Q11 */ + Word32 memTransitionHB_fx[CPE_CHANNELS][NS2SA( 48000, STEREO_DFT32MS_OVL_NS )]; /* Q11 */ #endif /* unscaled & scaled SHB synthesis memory */ @@ -605,9 +605,9 @@ typedef struct stereo_icbwe_dec_data_structure float mem_lpc_shbsynth_nonref[LPC_SHB_ORDER]; float mem_syn_shb_ola_nonref[L_SHB_LAHEAD]; #else - Word32 mem_syn_shb_nonref_fx[L_SHB_LAHEAD]; /* Q(prev_Q_syn_shb_nonref) */ - Word32 mem_lpc_shbsynth_nonref_fx[LPC_SHB_ORDER]; /* Q(prev_Q_lpc_shbsynth_nonref) */ - Word32 mem_syn_shb_ola_nonref_fx[L_SHB_LAHEAD]; /* Q(prev_Q_syn_shb_ola_nonref) */ + Word32 mem_syn_shb_nonref_fx[L_SHB_LAHEAD]; /* Q(prev_Q_syn_shb_nonref) */ + Word32 mem_lpc_shbsynth_nonref_fx[LPC_SHB_ORDER]; /* Q(prev_Q_lpc_shbsynth_nonref) */ + Word32 mem_syn_shb_ola_nonref_fx[L_SHB_LAHEAD]; /* Q(prev_Q_syn_shb_ola_nonref) */ Word16 prev_Q_syn_shb_nonref; Word16 prev_Q_lpc_shbsynth_nonref; @@ -646,7 +646,7 @@ typedef struct stereo_icbwe_dec_data_structure #ifndef IVAS_FLOAT_FIXED float icbweM2Ref_prev; #else - Word16 icbweM2Ref_prev_fx; /* Q14 */ + Word16 icbweM2Ref_prev_fx; /* Q14 */ #endif #ifndef IVAS_FLOAT_FIXED @@ -797,8 +797,8 @@ typedef struct dirac_output_synthesis_cov_state_structure Word32 *mixing_matrix_res_old_fx[CLDFB_NO_CHANNELS_MAX]; Word32 *mixing_matrix_res_fx[CLDFB_NO_CHANNELS_MAX]; - Word16 * cx_old_e; - Word16 *cy_old_e; + Word16 *cx_old_e; + Word16 *cy_old_e; Word16 *mixing_matrix_old_exp; Word16 *mixing_matrix_res_old_exp; Word16 *mixing_matrix_exp; @@ -832,9 +832,9 @@ typedef struct ivas_param_mc_dec_data_structure float *Cldfb_RealBuffer_tc; float *Cldfb_ImagBuffer_tc; #ifdef IVAS_FLOAT_FIXED - Word32 *Cldfb_RealBuffer_tc_fx; // Q12 + Word32 *Cldfb_RealBuffer_tc_fx; // Q12 Word16 Cldfb_RealBuffer_tc_e; - Word32 *Cldfb_ImagBuffer_tc_fx; // Q12 + Word32 *Cldfb_ImagBuffer_tc_fx; // Q12 Word16 Cldfb_ImagBuffer_tc_e; Word16 sz; #endif @@ -874,8 +874,8 @@ typedef struct ivas_param_mc_dec_data_structure float *icc_q; /* ICC parameters*/ float *icld_q; #else - Word16 *icc_q_fx; /* ICC parameters*/ /* Q15 */ - Word16 *icld_q_fx; /* Q8 */ + Word16 *icc_q_fx; /* ICC parameters*/ /* Q15 */ + Word16 *icld_q_fx; /* Q8 */ #endif int16_t max_param_band_abs_cov; #ifndef IVAS_FLOAT_FIXED @@ -917,14 +917,14 @@ typedef struct ivas_mc_paramupmix_dec_data_structure #ifdef IVAS_FLOAT_FIXED - Word32 alphas_fx[MC_PARAMUPMIX_COMBINATIONS][IVAS_MAX_NUM_BANDS]; // Q28 - Word32 betas_fx[MC_PARAMUPMIX_COMBINATIONS][IVAS_MAX_NUM_BANDS]; // Q28 + Word32 alphas_fx[MC_PARAMUPMIX_COMBINATIONS][IVAS_MAX_NUM_BANDS]; // Q28 + Word32 betas_fx[MC_PARAMUPMIX_COMBINATIONS][IVAS_MAX_NUM_BANDS]; // Q28 Word32 alpha_prev_fx[MC_PARAMUPMIX_COMBINATIONS][IVAS_MAX_NUM_BANDS]; // Q28 - Word32 beta_prev_fx[MC_PARAMUPMIX_COMBINATIONS][IVAS_MAX_NUM_BANDS]; // Q28 + Word32 beta_prev_fx[MC_PARAMUPMIX_COMBINATIONS][IVAS_MAX_NUM_BANDS]; // Q28 Word32 *pcm_delay_fx[MC_PARAMUPMIX_MAX_TRANSPORT_CHANS]; - Word16 *param_interpolator_fx; // Q15 - Word32 alpha_sf_fx[MC_PARAMUPMIX_COMBINATIONS][IVAS_MAX_NUM_BANDS];//Q28 - Word32 beta_sf_fx[MC_PARAMUPMIX_COMBINATIONS][IVAS_MAX_NUM_BANDS];//Q28 + Word16 *param_interpolator_fx; // Q15 + Word32 alpha_sf_fx[MC_PARAMUPMIX_COMBINATIONS][IVAS_MAX_NUM_BANDS]; // Q28 + Word32 beta_sf_fx[MC_PARAMUPMIX_COMBINATIONS][IVAS_MAX_NUM_BANDS]; // Q28 Word32 *hoa_encoder_fx; #else float alphas[MC_PARAMUPMIX_COMBINATIONS][IVAS_MAX_NUM_BANDS]; @@ -1008,7 +1008,7 @@ typedef struct ivas_agc_dec_chan_state_t #ifndef IVAS_FLOAT_FIXED float lastGain; #else - Word16 lastGain_fx; /* Q15 */ + Word16 lastGain_fx; /* Q15 */ #endif // IVAS_FLOAT_FIXED Word16 gainExpVal; @@ -1159,7 +1159,7 @@ typedef struct cpe_dec_data_structure #endif #ifdef IVAS_FLOAT_FIXED - Word32 lt_es_em_fx;//24 + Word32 lt_es_em_fx; // 24 Word32 prev_hb_synth_fx[CPE_CHANNELS][NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS )]; Word32 prev_synth_fx[CPE_CHANNELS][NS2SA( 48000, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS )]; @@ -1229,7 +1229,7 @@ typedef struct ivas_lfe_dec_data_structure #ifndef IVAS_FLOAT_FIXED float lfe_block_delay_s; #else - Word16 lfe_block_delay_s_fx; /* Q15 */ + Word16 lfe_block_delay_s_fx; /* Q15 */ #endif Word16 lfe_prior_buf_len; #ifndef IVAS_FLOAT_FIXED @@ -1278,17 +1278,17 @@ typedef struct ivas_binaural_rendering_struct IVAS_OUTPUT_SETUP_HANDLE hInputSetup; /* pointer to input spatial format for binaural renderer*/ EFAP_HANDLE hEFAPdata; /* EFAP structure*/ #ifndef IVAS_FLOAT_FIXED - float *hoa_dec_mtx; /* pointer to HOA decoder mtx */ + float *hoa_dec_mtx; /* pointer to HOA decoder mtx */ #else - Word32 *hoa_dec_mtx; /* pointer to HOA decoder mtx */ + Word32 *hoa_dec_mtx; /* pointer to HOA decoder mtx */ #endif - int8_t rotInCldfb; /* Flag to enable rotation within bin Renderer in CLDFB*/ - int16_t max_band; /* band upto which rendering is performed */ - int16_t conv_band; /* band upto which convolution in cldfb domain is performed */ - int16_t timeSlots; /* number of time slots of binaural renderer */ - int16_t nInChannels; /* number input channels */ - int8_t render_lfe; /* Flag to render LFE in binaural rendering*/ - IVAS_FORMAT ivas_format; /* format; corresponds to st_ivas->ivas_format, unless the signal gets transormed to a different domain for rendering */ + int8_t rotInCldfb; /* Flag to enable rotation within bin Renderer in CLDFB*/ + int16_t max_band; /* band upto which rendering is performed */ + int16_t conv_band; /* band upto which convolution in cldfb domain is performed */ + int16_t timeSlots; /* number of time slots of binaural renderer */ + int16_t nInChannels; /* number input channels */ + int8_t render_lfe; /* Flag to render LFE in binaural rendering*/ + IVAS_FORMAT ivas_format; /* format; corresponds to st_ivas->ivas_format, unless the signal gets transormed to a different domain for rendering */ /* Convolution module structure */ #ifndef IVAS_FLOAT_FIXED @@ -1334,7 +1334,7 @@ typedef struct ivas_masa_decoder_data_struct #ifndef IVAS_FLOAT_FIXED float dir_decode_quality; #else - Word16 dir_decode_quality_fx; /* Q15 */ + Word16 dir_decode_quality_fx; /* Q15 */ #endif } MASA_DECODER_DATA; @@ -1397,7 +1397,7 @@ typedef struct ivas_masa_ism_data_structure #ifndef IVAS_FLOAT_FIXED float **delayBuffer; #else - Word32 **delayBuffer_fx; /* Q11 */ + Word32 **delayBuffer_fx; /* Q11 */ #endif int16_t delayBuffer_size; int16_t delayBuffer_nchan; @@ -1415,22 +1415,22 @@ typedef struct decoder_tc_buffer_structure float *tc_buffer; /* the buffer itself */ float *tc[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS]; /* pointers into the buffer to the beginning of each tc */ // VE2SB: TBV #else - Word32 *tc_buffer_fx; /* the buffer itself */ - Word16 tc_buff_len;/*stores memory length of tc buffer*/ + Word32 *tc_buffer_fx; /* the buffer itself */ + Word16 tc_buff_len; /*stores memory length of tc buffer*/ Word32 *tc_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS]; /* pointers into the buffer to the beginning of each tc Q11 for ivas */ // VE2SB: TBV #ifdef MSAN_FIX Word16 no_channels; /*Stores no of channels in tc_fx with values*/ #endif Word16 q_tc_fx; #endif - TC_BUFFER_MODE tc_buffer_mode; /* mode of the buffer (no buffering, render buffering, out buffering) */ - int16_t nchan_transport_jbm; /* number of TCs after TC decoding */ - int16_t nchan_transport_internal; /* total number of TC buffer channels, can include e.g. TD decorr data */ - int16_t nchan_buffer_full; /* number of channels to be fully buffered */ - int16_t n_samples_available; /* samples still available for rendering in the current frame */ - int16_t n_samples_buffered; /* full number of samples in the buffer (including spill to next frame) */ - int16_t n_samples_rendered; /* samples already rendered in the current frame */ - int16_t n_samples_granularity; /* render granularity */ + TC_BUFFER_MODE tc_buffer_mode; /* mode of the buffer (no buffering, render buffering, out buffering) */ + int16_t nchan_transport_jbm; /* number of TCs after TC decoding */ + int16_t nchan_transport_internal; /* total number of TC buffer channels, can include e.g. TD decorr data */ + int16_t nchan_buffer_full; /* number of channels to be fully buffered */ + int16_t n_samples_available; /* samples still available for rendering in the current frame */ + int16_t n_samples_buffered; /* full number of samples in the buffer (including spill to next frame) */ + int16_t n_samples_rendered; /* samples already rendered in the current frame */ + int16_t n_samples_granularity; /* render granularity */ int16_t n_samples_flushed; int16_t subframe_nbslots[MAX_JBM_SUBFRAMES_5MS]; int16_t nb_subframes; diff --git a/lib_dec/ivas_stereo_adapt_GR_dec.c b/lib_dec/ivas_stereo_adapt_GR_dec.c index 675a16b46..79b9d272f 100644 --- a/lib_dec/ivas_stereo_adapt_GR_dec.c +++ b/lib_dec/ivas_stereo_adapt_GR_dec.c @@ -956,4 +956,4 @@ int16_t read_flag_EC_DFT( } } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/ivas_stereo_cng_dec.c b/lib_dec/ivas_stereo_cng_dec.c index 93817a5b1..418d04fbf 100644 --- a/lib_dec/ivas_stereo_cng_dec.c +++ b/lib_dec/ivas_stereo_cng_dec.c @@ -48,33 +48,33 @@ * Local constants *-------------------------------------------------------------------*/ -#define A_GFILT 0.8f /* LP-filter coefficient for coherence and sidegain */ +#define A_GFILT 0.8f /* LP-filter coefficient for coherence and sidegain */ #ifdef IVAS_FLOAT_FIXED -#define A_GFILT_FX (Word16)(0x6666) /* LP-filter coefficient for coherence and sidegain */ -#define ONE_MINUS_A_GFILT_FX (Word16)(0x199A) /* LP-filter coefficient for coherence and sidegain */ +#define A_GFILT_FX ( Word16 )( 0x6666 ) /* LP-filter coefficient for coherence and sidegain */ +#define ONE_MINUS_A_GFILT_FX ( Word16 )( 0x199A ) /* LP-filter coefficient for coherence and sidegain */ #endif #define SKIP_XFADE_FRAMES 2 /* DTX/CNG */ -#define MAX_K 50.0f -#define ONE_BY_MAX_K (Word16)(0x028F) -#define STEREO_TD_PS_CORR_FILT 0.8f -#define STEREO_TD_PS_CORR_FILT_FX 1717986918 -#define STEREO_TD_PS_CORR_FILT_Q31 1717986944 +#define MAX_K 50.0f +#define ONE_BY_MAX_K ( Word16 )( 0x028F ) +#define STEREO_TD_PS_CORR_FILT 0.8f +#define STEREO_TD_PS_CORR_FILT_FX 1717986918 +#define STEREO_TD_PS_CORR_FILT_Q31 1717986944 #define ONE_MINUS_STEREO_TD_PS_CORR_FILT_Q31 429496704 -#define MAX_XFADE 50.0f +#define MAX_XFADE 50.0f #ifdef IVAS_FLOAT_FIXED -#define MAX_XFADE_FX 50 +#define MAX_XFADE_FX 50 #endif -#define CM_INIT 50 -#define CORR_INIT 8 -#define SID_INIT 6 -#define STEREO_CNA_LR_CORR_LT_FILT 0.95f /* long-term averaging factor for L/R correlation estimation in stereo CNA */ +#define CM_INIT 50 +#define CORR_INIT 8 +#define SID_INIT 6 +#define STEREO_CNA_LR_CORR_LT_FILT 0.95f /* long-term averaging factor for L/R correlation estimation in stereo CNA */ #define STEREO_CNA_LR_CORR_LT_FILT_FX 2040109440 /* long-term averaging factor for L/R correlation estimation in stereo CNA */ -#define STEREO_CNA_ILD_LT_FILT 0.9f /* long-term averaging factor for ILD estimation in stereo CNA */ -#define STEREO_CNA_ILD_LT_FILT_FX 1932735283 /* long-term averaging factor for ILD estimation in stereo CNA */ -#define STEREO_CNA_SOFT_VAD_UP 0.7f /* long-term averaging factor for upward soft VAD update in stereo CNA */ -#define STEREO_CNA_SOFT_VAD_DN 0.95f /* long-term averaging factor for downward soft VAD update in stereo CNA */ +#define STEREO_CNA_ILD_LT_FILT 0.9f /* long-term averaging factor for ILD estimation in stereo CNA */ +#define STEREO_CNA_ILD_LT_FILT_FX 1932735283 /* long-term averaging factor for ILD estimation in stereo CNA */ +#define STEREO_CNA_SOFT_VAD_UP 0.7f /* long-term averaging factor for upward soft VAD update in stereo CNA */ +#define STEREO_CNA_SOFT_VAD_DN 0.95f /* long-term averaging factor for downward soft VAD update in stereo CNA */ /*------------------------------------------------------------------- @@ -645,7 +645,7 @@ static void stereo_dft_generate_comfort_noise( } /* update msNoiseEst in SID and NO_DATA frames */ - bandcombinepow_flt( &st->hFdCngDec->smoothed_psd[hFdCngCom->startBand], hFdCngCom->stopFFTbin - hFdCngCom->startBand, st->hFdCngDec->part_shaping, st->hFdCngDec->nFFTpart_shaping, st->hFdCngDec->psize_inv_shaping_float, st->hFdCngDec->msNoiseEst_float); + bandcombinepow_flt( &st->hFdCngDec->smoothed_psd[hFdCngCom->startBand], hFdCngCom->stopFFTbin - hFdCngCom->startBand, st->hFdCngDec->part_shaping, st->hFdCngDec->nFFTpart_shaping, st->hFdCngDec->psize_inv_shaping_float, st->hFdCngDec->msNoiseEst_float ); st->hFdCngDec->first_cna_noise_updated = 1; mvr2r( st->hFdCngDec->msNoiseEst_float, st->hFdCngDec->msPeriodog_ST, st->hFdCngDec->nFFTpart_shaping ); @@ -713,7 +713,7 @@ static void stereo_dft_generate_comfort_noise_fx( * -12dB in Q11 is (Word32)0xFFFFA000. * The guard bits are calculated by converting the power of 10 exponent to power of 2 exponent. */ - addl_guard_bits = s_max(1, shr(extract_l(L_shr(Mpy_32_16_1(L_sub((Word32)0xFFFFA000, st->hTdCngDec->shb_cng_gain_fx_32), (Word16)0x2A85), Q11)), 1)); + addl_guard_bits = s_max( 1, shr( extract_l( L_shr( Mpy_32_16_1( L_sub( (Word32) 0xFFFFA000, st->hTdCngDec->shb_cng_gain_fx_32 ), (Word16) 0x2A85 ), Q11 ) ), 1 ) ); move16(); @@ -793,8 +793,9 @@ static void stereo_dft_generate_comfort_noise_fx( IF( hStereoCng->first_SID_after_TD ) { Word16 q_div, q_sqrt, q_sqrt2; - scaleAvg = 0; move16(); - FOR ( b = 0; b < hStereoDft->nbands; b++ ) + scaleAvg = 0; + move16(); + FOR( b = 0; b < hStereoDft->nbands; b++ ) { Word32 tmp_n, tmp_d, tmp_32, tmp_32_2; Word16 sqrt_res; @@ -802,13 +803,13 @@ static void stereo_dft_generate_comfort_noise_fx( { gamma = hStereoCng->cm_fx[b]; move16(); - gamma = BASOP_Util_Divide1616_Scale(gamma , sub( MAX_16 , gamma ), &q_div); - q_sqrt2 = q_div+16; - tmp_32_2 = Sqrt32(gamma, &q_sqrt2); - tmp_32 = BASOP_Util_Add_Mant32Exp(gamma, 16+q_div, sub(MAX_16, mult(hStereoDft->g_state_fx[b], hStereoDft->g_state_fx[b])), 16, &q_sqrt); - tmp_32 = Sqrt32( tmp_32, &q_sqrt); - tmp_32 = BASOP_Util_Add_Mant32Exp(tmp_32, q_sqrt, L_negate(tmp_32_2), q_sqrt2, &q_sqrt); - gamma = extract_h(L_shl(tmp_32, q_sqrt)); + gamma = BASOP_Util_Divide1616_Scale( gamma, sub( MAX_16, gamma ), &q_div ); + q_sqrt2 = q_div + 16; + tmp_32_2 = Sqrt32( gamma, &q_sqrt2 ); + tmp_32 = BASOP_Util_Add_Mant32Exp( gamma, 16 + q_div, sub( MAX_16, mult( hStereoDft->g_state_fx[b], hStereoDft->g_state_fx[b] ) ), 16, &q_sqrt ); + tmp_32 = Sqrt32( tmp_32, &q_sqrt ); + tmp_32 = BASOP_Util_Add_Mant32Exp( tmp_32, q_sqrt, L_negate( tmp_32_2 ), q_sqrt2, &q_sqrt ); + gamma = extract_h( L_shl( tmp_32, q_sqrt ) ); } ELSE { @@ -887,15 +888,15 @@ static void stereo_dft_generate_comfort_noise_fx( trigo_dec[shr( st->L_frame, 2 )] = pTrigo[shr( st->L_frame, 2 ) * trigo_step]; move16(); - rshift_cng = getScaleFactor32(cngNoiseLevel_upd, st->L_frame); - rshift_cng = sub(find_guarded_bits_fx(st->L_frame), rshift_cng); + rshift_cng = getScaleFactor32( cngNoiseLevel_upd, st->L_frame ); + rshift_cng = sub( find_guarded_bits_fx( st->L_frame ), rshift_cng ); /* * The guardbits calculated here are not sufficient for all cases. * Due to the gain values like shb_cng_gain and other things in the ensuing code blocks, * additional guard bits have to be added. The choice based on existing test vector set is Q2 */ - rshift_cng = add(rshift_cng, addl_guard_bits); - v_shr_32(cngNoiseLevel_upd, cngNoiseLevel_upd, st->L_frame, rshift_cng); + rshift_cng = add( rshift_cng, addl_guard_bits ); + v_shr_32( cngNoiseLevel_upd, cngNoiseLevel_upd, st->L_frame, rshift_cng ); // Input Q to fft will be Q30 - rshift. rfft_fx( cngNoiseLevel_upd, trigo_dec, st->L_frame, -1 ); // v_shr_32(cngNoiseLevel_upd, cngNoiseLevel_upd, st->L_frame, negate(rshift)); @@ -916,31 +917,32 @@ static void stereo_dft_generate_comfort_noise_fx( // The left shift of q_div and 1 (because of multiplication factor 2.0) is handled below. // by adjusting q_inv_sqrt. minimum_abs32_fx( ptr0, st->L_frame, &min_val ); - //q_inv_sqrt = sub( sub( Q31, norm_l( L_abs( min_val ) ) ), add( q_div, 1 ) ); + // q_inv_sqrt = sub( sub( Q31, norm_l( L_abs( min_val ) ) ), add( q_div, 1 ) ); /* cngNoiseLevel_upd buffer has Q of ( Q30 - rshift_cng )*/ FOR( i = 0; i < shr( st->L_frame, 1 ) - 1; i++ ) { - //if ((*ptr1 == 0) && (*ptr2 == 0)) - // assert(0); - //assert( (*ptr1 != 0) || (*ptr2 != 0)); - IF (norm_l(*ptr1) > rshift_cng && norm_l(*ptr2) > rshift_cng) + // if ((*ptr1 == 0) && (*ptr2 == 0)) + // assert(0); + // assert( (*ptr1 != 0) || (*ptr2 != 0)); + IF( norm_l( *ptr1 ) > rshift_cng && norm_l( *ptr2 ) > rshift_cng ) { - ftmp = Madd_32_32(Mpy_32_32(L_shl(*ptr1, rshift_cng) , L_shl(*ptr1, rshift_cng)) , L_shl(*ptr2, rshift_cng) , L_shl(*ptr2, rshift_cng)); + ftmp = Madd_32_32( Mpy_32_32( L_shl( *ptr1, rshift_cng ), L_shl( *ptr1, rshift_cng ) ), L_shl( *ptr2, rshift_cng ), L_shl( *ptr2, rshift_cng ) ); q_sqrt = Q2; } ELSE { - ftmp = Madd_32_32(Mpy_32_32(*ptr1 , *ptr1) , *ptr2, *ptr2); - q_sqrt = sub(Q31, sub(shl(sub(Q30, rshift_cng), 1) , Q31)); + ftmp = Madd_32_32( Mpy_32_32( *ptr1, *ptr1 ), *ptr2, *ptr2 ); + q_sqrt = sub( Q31, sub( shl( sub( Q30, rshift_cng ), 1 ), Q31 ) ); } - IF (EQ_32(ftmp , 0)) + IF( EQ_32( ftmp, 0 ) ) { - ftmp = EPSILON_FX; move32(); - q_sqrt = s_max(0, q_sqrt); + ftmp = EPSILON_FX; + move32(); + q_sqrt = s_max( 0, q_sqrt ); } - tmp = ISqrt32(ftmp, &q_sqrt); - tmp = Mpy_32_16_1(tmp, factor); + tmp = ISqrt32( ftmp, &q_sqrt ); + tmp = Mpy_32_16_1( tmp, factor ); q_cng_temp[i] = sub( add( sub( Q31, q_sqrt ), sub( Q15, add( q_div, 1 ) ) ), Q15 ); *ptr0++ = tmp; move32(); @@ -1006,26 +1008,27 @@ static void stereo_dft_generate_comfort_noise_fx( move16(); } - rshift_shb = getScaleFactor32(shb_shape, L_FRAME16k); - rshift_shb = sub(find_guarded_bits_fx(L_FRAME16k), rshift_shb); + rshift_shb = getScaleFactor32( shb_shape, L_FRAME16k ); + rshift_shb = sub( find_guarded_bits_fx( L_FRAME16k ), rshift_shb ); /* * The guardbits calculated here are not sufficient for all cases. * Due to the gain values like shb_cng_gain and other things in the ensuing code blocks, * additional guard bits have to be added. The choice based on existing test vector set is Q2 */ - rshift_shb = add(rshift_shb, addl_guard_bits); - v_shr_32(shb_shape, shb_shape, L_FRAME16k, rshift_shb); + rshift_shb = add( rshift_shb, addl_guard_bits ); + v_shr_32( shb_shape, shb_shape, L_FRAME16k, rshift_shb ); rfft_fx( shb_shape, trigo_dec, L_FRAME16k, -1 ); // v_shr_32(shb_shape, shb_shape, L_FRAME16k, negate(rshift)); /* Compute 1/|A| */ - enr = Madd_32_32(Mpy_32_32(L_shl(shb_shape[0], addl_guard_bits), L_shl(shb_shape[0], addl_guard_bits)), - L_shl(shb_shape[1], addl_guard_bits) , L_shl(shb_shape[1], addl_guard_bits)); - q_enr = add(sub(shl(sub(Q30, rshift_shb), 1), Q31), shl(addl_guard_bits, 1)); - IF (EQ_32(enr , 0)) + enr = Madd_32_32( Mpy_32_32( L_shl( shb_shape[0], addl_guard_bits ), L_shl( shb_shape[0], addl_guard_bits ) ), + L_shl( shb_shape[1], addl_guard_bits ), L_shl( shb_shape[1], addl_guard_bits ) ); + q_enr = add( sub( shl( sub( Q30, rshift_shb ), 1 ), Q31 ), shl( addl_guard_bits, 1 ) ); + IF( EQ_32( enr, 0 ) ) { - enr = EPSILON_FX; move32(); - q_enr = s_max(0, q_enr); + enr = EPSILON_FX; + move32(); + q_enr = s_max( 0, q_enr ); } ptr0 = shb_shape; ptr1 = ptr0 + 2; @@ -1033,15 +1036,16 @@ static void stereo_dft_generate_comfort_noise_fx( FOR( i = 0; i < L_FRAME16k / 2 - 1; i++ ) { - Word16 q_shift = sub(shl(sub(Q30, rshift_shb), 1), Q31); - //assert((*ptr1 != 0) || (*ptr2 != 0)); - ftmp = Madd_32_32( Mpy_32_32(L_shl(*ptr1, addl_guard_bits) , L_shl(*ptr1, addl_guard_bits)) , - L_shl(*ptr2, addl_guard_bits) , L_shl(*ptr2, addl_guard_bits)); - q_shift = add(q_shift, shl(addl_guard_bits, 1)) ; - IF(EQ_32(ftmp, 0)) + Word16 q_shift = sub( shl( sub( Q30, rshift_shb ), 1 ), Q31 ); + // assert((*ptr1 != 0) || (*ptr2 != 0)); + ftmp = Madd_32_32( Mpy_32_32( L_shl( *ptr1, addl_guard_bits ), L_shl( *ptr1, addl_guard_bits ) ), + L_shl( *ptr2, addl_guard_bits ), L_shl( *ptr2, addl_guard_bits ) ); + q_shift = add( q_shift, shl( addl_guard_bits, 1 ) ); + IF( EQ_32( ftmp, 0 ) ) { - ftmp = EPSILON_FX; move32(); - q_shift = s_max(0, q_shift); + ftmp = EPSILON_FX; + move32(); + q_shift = s_max( 0, q_shift ); } ftmp = L_deposit_l( BASOP_Util_Divide3232_Scale( L_sub( L_shl( Q1, q_shift ), 1 ), ftmp, &q_div ) ); ftmp = L_shl( ftmp, sub( q_div, sub( Q15, q_shift ) ) ); @@ -1055,8 +1059,9 @@ static void stereo_dft_generate_comfort_noise_fx( q_div = sub( Q31, q_shift ); ftmp = Sqrt32( ftmp, &q_div ); // Reduce the Q of shb_shape back to its original Q i.e., Q30 - rshift - ftmp = L_shr(ftmp, sub(sub(Q31, q_div), sub(Q30, rshift_shb))); - *ptr0++ = ftmp; move32(); + ftmp = L_shr( ftmp, sub( sub( Q31, q_div ), sub( Q30, rshift_shb ) ) ); + *ptr0++ = ftmp; + move32(); ptr1 += 2; ptr2 += 2; } @@ -1134,26 +1139,29 @@ static void stereo_dft_generate_comfort_noise_fx( // To ensure the result of the multiplication is with optimal precision // apply left shift on the input data and use it for multiplication // result of multiplication will be in same Q as ptr_r buffer - tmp = imult3216(( *ptr_r ), scale); - IF (GE_16(norm_l(tmp), shift_val)) + tmp = imult3216( ( *ptr_r ), scale ); + IF( GE_16( norm_l( tmp ), shift_val ) ) { - ( *ptr_r ) = Mpy_32_32(L_shl(tmp, shift_val), *ptr_level); move32(); + ( *ptr_r ) = Mpy_32_32( L_shl( tmp, shift_val ), *ptr_level ); + move32(); } ELSE { - ( *ptr_r ) = L_shl(Mpy_32_32(tmp, *ptr_level), shift_val); move32(); + ( *ptr_r ) = L_shl( Mpy_32_32( tmp, *ptr_level ), shift_val ); + move32(); } ptr_r += 2; /* Imaginary part in FFT bins */ rand_gauss_fx( ptr_i, &st->hTdCngDec->cng_seed, q_dft ); - tmp = imult3216(( *ptr_i ) , scale); move32(); - IF (GE_16(norm_l(tmp), shift_val)) + tmp = imult3216( ( *ptr_i ), scale ); + move32(); + IF( GE_16( norm_l( tmp ), shift_val ) ) { - ( *ptr_i ) = Mpy_32_32(L_shl(tmp, shift_val), *ptr_level); + ( *ptr_i ) = Mpy_32_32( L_shl( tmp, shift_val ), *ptr_level ); } ELSE { - ( *ptr_i ) = L_shl(Mpy_32_32(tmp, *ptr_level), shift_val); + ( *ptr_i ) = L_shl( Mpy_32_32( tmp, *ptr_level ), shift_val ); } ptr_i += 2; ptr_level++; @@ -1169,25 +1177,27 @@ static void stereo_dft_generate_comfort_noise_fx( // Above expression equivalent to 2 ^ (3.321928094 * 0.1 * st->hTdCngDec->shb_cng_gain) // 3.321928094 * 0.1 = 0.3321928094 // st->hTdCngDec->shb_cng_gain_fx_32 Q is 11 - scale_32 = BASOP_util_Pow2( Mpy_32_16_1(st->hTdCngDec->shb_cng_gain_fx_32, (Word16)0x2A85), Q31 - Q11, &q_res); - //Q of scale_32 is Q31 - q_res, Q of enr is - //scale_32 = L_shl(scale_32, sub( q_enr, sub(Q31, q_res))); - q_div = 0; move16(); - scale = BASOP_Util_Divide3232_Scale( scale_32, enr, &q_div); - //q_res = add(q_div, sub( q_enr, sub(Q31, q_res))); move16(); - q_res = sub(Q15, add(sub(Q15, q_div), sub(sub(Q31, q_res), q_enr))); move16(); - //q_div = sub(Q15, q_res); move16(); + scale_32 = BASOP_util_Pow2( Mpy_32_16_1( st->hTdCngDec->shb_cng_gain_fx_32, (Word16) 0x2A85 ), Q31 - Q11, &q_res ); + // Q of scale_32 is Q31 - q_res, Q of enr is + // scale_32 = L_shl(scale_32, sub( q_enr, sub(Q31, q_res))); + q_div = 0; + move16(); + scale = BASOP_Util_Divide3232_Scale( scale_32, enr, &q_div ); + // q_res = add(q_div, sub( q_enr, sub(Q31, q_res))); move16(); + q_res = sub( Q15, add( sub( Q15, q_div ), sub( sub( Q31, q_res ), q_enr ) ) ); + move16(); + // q_div = sub(Q15, q_res); move16(); q_div = q_res; - inv_scale = ISqrt16( scale, &q_res); - scale = Sqrt16(scale, &q_div); + inv_scale = ISqrt16( scale, &q_res ); + scale = Sqrt16( scale, &q_div ); ptr_shb = shb_shape + L_FRAME16k / 2 - 1; ptr_q_shb = q_shb_shape + L_FRAME16k / 2 - 1; /* Averaging for Nyquist frequency */ tmp = Mpy_32_16_1( cngNoiseLevel_upd[sub( shr( sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ), 1 ), 1 )], inv_scale ); // q of cngNoiseLevel_upd is Q16. // ptr_shb will be in Q30 - rshift. tmp is in Q16(Q15 + 1 (for the 0.5 in multiplication)) - q_res, Applying appropriate shift on tmp - q_res = sub(sub(Q30, rshift_cng), sub(Q16, q_res)); - IF (LT_16(q_res, norm_l(tmp))) + q_res = sub( sub( Q30, rshift_cng ), sub( Q16, q_res ) ); + IF( LT_16( q_res, norm_l( tmp ) ) ) { tmp = L_shl( tmp, q_res ); q_res = 0; @@ -1205,13 +1215,15 @@ static void stereo_dft_generate_comfort_noise_fx( FOR( i = 0; i < ( min( output_frame, hFdCngCom->regularStopBand * 16 ) - hFdCngCom->stopFFTbin ) / 2; i++ ) { /* Real part in FFT bins */ - rand_gauss_fx( ptr_r, &st->hTdCngDec->cng_seed, q_dft); - //ptr_shb will be in Q30 - rshift at this point. So apply left shift by 1 to compensate Mpy_32_32 right shift.. - ( *ptr_r ) = W_extract_l(W_shl(W_mult0_32_32(*ptr_r, *ptr_shb), sub(add(rshift_shb, add(1, *ptr_q_shb)), 31))); move32(); + rand_gauss_fx( ptr_r, &st->hTdCngDec->cng_seed, q_dft ); + // ptr_shb will be in Q30 - rshift at this point. So apply left shift by 1 to compensate Mpy_32_32 right shift.. + ( *ptr_r ) = W_extract_l( W_shl( W_mult0_32_32( *ptr_r, *ptr_shb ), sub( add( rshift_shb, add( 1, *ptr_q_shb ) ), 31 ) ) ); + move32(); ptr_r += 2; /* Imaginary part in FFT bins */ - rand_gauss_fx( ptr_i, &st->hTdCngDec->cng_seed, q_dft); - ( *ptr_i ) = W_extract_l(W_shl(W_mult0_32_32(*ptr_i, *ptr_shb), sub(add(rshift_shb, add(1, *ptr_q_shb)), 31))); move32(); + rand_gauss_fx( ptr_i, &st->hTdCngDec->cng_seed, q_dft ); + ( *ptr_i ) = W_extract_l( W_shl( W_mult0_32_32( *ptr_i, *ptr_shb ), sub( add( rshift_shb, add( 1, *ptr_q_shb ) ), 31 ) ) ); + move32(); ptr_i += 2; ptr_shb--; } @@ -1223,9 +1235,11 @@ static void stereo_dft_generate_comfort_noise_fx( ptr_i = ptr_r + 1; FOR( i = 0; i < shr( sub( s_min( output_frame, shl( hFdCngCom->regularStopBand, 4 ) ), hFdCngCom->stopFFTbin ), 1 ); i++ ) { - ( *ptr_r ) = W_extract_l(W_shl(W_mult0_32_32(Mpy_32_16_1(*ptr_r, scale), shr(output_frame, 1)), q_div)); move32(); + ( *ptr_r ) = W_extract_l( W_shl( W_mult0_32_32( Mpy_32_16_1( *ptr_r, scale ), shr( output_frame, 1 ) ), q_div ) ); + move32(); + move32(); + ( *ptr_i ) = W_extract_l( W_shl( W_mult0_32_32( Mpy_32_16_1( *ptr_i, scale ), shr( output_frame, 1 ) ), q_div ) ); move32(); - ( *ptr_i ) = W_extract_l(W_shl(W_mult0_32_32(Mpy_32_16_1(*ptr_i, scale), shr(output_frame, 1)), q_div)); move32(); move32(); ptr_r += 2; ptr_i += 2; @@ -1234,20 +1248,21 @@ static void stereo_dft_generate_comfort_noise_fx( } /* Expand cngNoiseLevel_flt from 0-159 to 0-318, compute noise level */ - lp_noise = 0; move32(); - ptr_level = hFdCngCom->cngNoiseLevel + sub(sub(hFdCngCom->stopFFTbin , hFdCngCom->startBand) , 1); - ptr_tmp = cngNoiseLevel_upd + sub(shr(sub( hFdCngCom->stopFFTbin , hFdCngCom->startBand ) , 1) , 1); - rshift_cng = sub(sub(31, hFdCngCom->cngNoiseLevelExp), sub(shl(q_cngNoiseLevel_upd, 1), Q31)); - FOR ( i = 0; i < shr(sub( hFdCngCom->stopFFTbin , hFdCngCom->startBand ) , 1); i++ ) + lp_noise = 0; + move32(); + ptr_level = hFdCngCom->cngNoiseLevel + sub( sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ), 1 ); + ptr_tmp = cngNoiseLevel_upd + sub( shr( sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ), 1 ), 1 ); + rshift_cng = sub( sub( 31, hFdCngCom->cngNoiseLevelExp ), sub( shl( q_cngNoiseLevel_upd, 1 ), Q31 ) ); + FOR( i = 0; i < shr( sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ), 1 ); i++ ) { - IF (norm_l(*ptr_tmp) >= rshift_cng) + IF( norm_l( *ptr_tmp ) >= rshift_cng ) { - *ptr_level-- = Mpy_32_32(L_shl(*ptr_tmp, rshift_cng) , *ptr_tmp); + *ptr_level-- = Mpy_32_32( L_shl( *ptr_tmp, rshift_cng ), *ptr_tmp ); move32(); } ELSE { - *ptr_level-- = L_shl(Mpy_32_32(*ptr_tmp, *ptr_tmp), rshift_cng); + *ptr_level-- = L_shl( Mpy_32_32( *ptr_tmp, *ptr_tmp ), rshift_cng ); move32(); } @@ -1289,7 +1304,7 @@ static void stereo_dft_generate_comfort_noise_fx( ptr_level = hFdCngCom->cngNoiseLevel; ptr_r = DFT[chan] + hFdCngCom->startBand + k * STEREO_DFT32MS_N_MAX; ptr_i = ptr_r + 1; - q_cngNoiseLevel = sub(Q31, hFdCngCom->cngNoiseLevelExp); + q_cngNoiseLevel = sub( Q31, hFdCngCom->cngNoiseLevelExp ); FOR( i = 0; i < shr( sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ), 1 ); i++ ) { Word16 q_sqrt; @@ -1385,14 +1400,15 @@ static void stereo_dft_generate_comfort_noise_fx( IF( EQ_16( chan, 0 ) && LE_32( st->core_brate, SID_2k40 ) ) { - Word32 max_smoothed_psd = 0; move32(); - (void)maximum_32_fx(&st->hFdCngDec->smoothed_psd_fx[hFdCngCom->startBand], sub(hFdCngCom->stopFFTbin, hFdCngCom->startBand), &max_smoothed_psd); + Word32 max_smoothed_psd = 0; + move32(); + (void) maximum_32_fx( &st->hFdCngDec->smoothed_psd_fx[hFdCngCom->startBand], sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ), &max_smoothed_psd ); /* update smoothed periodogram used by stereo CNA in SID and NO_DATA frames from cngNoiseLevel_flt */ FOR( i = hFdCngCom->startBand; i < hFdCngCom->stopFFTbin; i++ ) { - Word16 l_shift_val = sub(st->hFdCngDec->q_smoothed_psd, sub(Q31, hFdCngCom->cngNoiseLevelExp)); + Word16 l_shift_val = sub( st->hFdCngDec->q_smoothed_psd, sub( Q31, hFdCngCom->cngNoiseLevelExp ) ); move16(); - l_shift_val = max_smoothed_psd == 0 ? 0 :l_shift_val; + l_shift_val = max_smoothed_psd == 0 ? 0 : l_shift_val; ftmp = hFdCngCom->cngNoiseLevel[i - hFdCngCom->startBand]; move32(); IF( !st->hFdCngDec->first_cna_noise_updated ) @@ -1405,13 +1421,14 @@ static void stereo_dft_generate_comfort_noise_fx( { alpha = (Word16) ( 0x799A ); move16(); - IF( GT_32( st->hFdCngDec->smoothed_psd_fx[i], 0 ) && GT_32( Mpy_32_16_1( ftmp, (Word16) 0x3333 ), L_shr(st->hFdCngDec->smoothed_psd_fx[i], l_shift_val) ) ) + IF( GT_32( st->hFdCngDec->smoothed_psd_fx[i], 0 ) && GT_32( Mpy_32_16_1( ftmp, (Word16) 0x3333 ), L_shr( st->hFdCngDec->smoothed_psd_fx[i], l_shift_val ) ) ) { /* prevent abrupt upward update steps */ - ftmp = L_add(L_shl(st->hFdCngDec->smoothed_psd_fx[i], 2), L_shr(st->hFdCngDec->smoothed_psd_fx[i], 1)); - l_shift_val = 0; move16(); + ftmp = L_add( L_shl( st->hFdCngDec->smoothed_psd_fx[i], 2 ), L_shr( st->hFdCngDec->smoothed_psd_fx[i], 1 ) ); + l_shift_val = 0; + move16(); } - ELSE IF ( LT_32(ftmp , L_shr(st->hFdCngDec->smoothed_psd_fx[i], l_shift_val)) ) + ELSE IF( LT_32( ftmp, L_shr( st->hFdCngDec->smoothed_psd_fx[i], l_shift_val ) ) ) { /* faster downward updates */ alpha = (Word16) ( 0x599A ); @@ -1420,15 +1437,16 @@ static void stereo_dft_generate_comfort_noise_fx( } /* smoothing */ - st->hFdCngDec->smoothed_psd_fx[i] = L_add(Mpy_32_16_1(st->hFdCngDec->smoothed_psd_fx[i], alpha) , L_shl(Mpy_32_16_1(ftmp, sub( MAX_16 , alpha )), l_shift_val)); + st->hFdCngDec->smoothed_psd_fx[i] = L_add( Mpy_32_16_1( st->hFdCngDec->smoothed_psd_fx[i], alpha ), L_shl( Mpy_32_16_1( ftmp, sub( MAX_16, alpha ) ), l_shift_val ) ); move32(); } /* update msNoiseEst in SID and NO_DATA frames */ - bandcombinepow( &st->hFdCngDec->smoothed_psd_fx[hFdCngCom->startBand], (Q31 - st->hFdCngDec->q_smoothed_psd), hFdCngCom->stopFFTbin - hFdCngCom->startBand, st->hFdCngDec->part_shaping, st->hFdCngDec->nFFTpart_shaping, st->hFdCngDec->psize_inv_shaping, st->hFdCngDec->msNoiseEst, &st->hFdCngDec->msNoiseEst_exp); - Scale_sig32(st->hFdCngDec->msNoiseEst, NPART_SHAPING, sub( st->hFdCngDec->msNoiseEst_exp, 27 ) ); + bandcombinepow( &st->hFdCngDec->smoothed_psd_fx[hFdCngCom->startBand], ( Q31 - st->hFdCngDec->q_smoothed_psd ), hFdCngCom->stopFFTbin - hFdCngCom->startBand, st->hFdCngDec->part_shaping, st->hFdCngDec->nFFTpart_shaping, st->hFdCngDec->psize_inv_shaping, st->hFdCngDec->msNoiseEst, &st->hFdCngDec->msNoiseEst_exp ); + Scale_sig32( st->hFdCngDec->msNoiseEst, NPART_SHAPING, sub( st->hFdCngDec->msNoiseEst_exp, 27 ) ); st->hFdCngDec->msNoiseEst_exp = 27; - st->hFdCngDec->first_cna_noise_updated = 1; move16(); + st->hFdCngDec->first_cna_noise_updated = 1; + move16(); Copy32( st->hFdCngDec->msNoiseEst, st->hFdCngDec->msPeriodog_ST_fx, st->hFdCngDec->nFFTpart_shaping ); st->hFdCngDec->ms_last_inactive_bwidth = st->bwidth; move16(); @@ -1485,8 +1503,8 @@ void stereo_dtf_cng_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ const Word32 ivas_total_brate, /* i : IVAS total bitrate */ Word32 DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i/o: DFT buffers */ - const Word16 output_frame, /* i : output frame size */ - Word16 q_dft /* i : Q factor of the DFT data */ + const Word16 output_frame, /* i : output frame size */ + Word16 q_dft /* i : Q factor of the DFT data */ ) { Decoder_State **sts; @@ -1511,7 +1529,7 @@ void stereo_dtf_cng_fx( FOR( n = 0; n < CPE_CHANNELS; n++ ) { - stereo_dft_generate_comfort_noise_fx( hCPE->hStereoDft, hCPE->hStereoCng, hCPE->last_element_mode, sts[0], DFT, sts[1], extract_h(hCPE->hStereoTCA->targetGain_fx), n, output_frame, q_dft); + stereo_dft_generate_comfort_noise_fx( hCPE->hStereoDft, hCPE->hStereoCng, hCPE->last_element_mode, sts[0], DFT, sts[1], extract_h( hCPE->hStereoTCA->targetGain_fx ), n, output_frame, q_dft ); } } } @@ -1652,8 +1670,8 @@ void stereo_cng_compute_PScorr_fx( } Word32 Var2, Var3; - Var2 = ISqrt32(Var1, &exp); - Var3 = L_add( dotPS_fx, 1 ); /*adding one in order to make temp non-zero. q = Q_outputSptr + Q_outputPptr - guard_bits*/ + Var2 = ISqrt32( Var1, &exp ); + Var3 = L_add( dotPS_fx, 1 ); /*adding one in order to make temp non-zero. q = Q_outputSptr + Q_outputPptr - guard_bits*/ c_PS_fx = Mpy_32_32( Var3, Var2 ); /* outputSptr_Q + outputPptr_Q - guard_bits - exp */ Word16 c_PS_fx_Q = outputSptr_Q + outputPptr_Q - guard_bits - exp - 31; @@ -1665,13 +1683,13 @@ void stereo_cng_compute_PScorr_fx( b = Mpy_32_32( STEREO_TD_PS_CORR_FILT_Q31, *c_PS_LT_fx ); // Q(Q_c_PS_LT_fx) b_q = Q_c_PS_LT_fx; - IF (GT_16( a_q , b_q) ) + IF( GT_16( a_q, b_q ) ) { ab_q = a_q - b_q; *c_PS_LT_fx = L_add( L_shr( a, (Word16) ab_q ), b ); Q_c_PS_LT_fx = b_q; } - ELSE IF ( LT_16(b_q , a_q )) + ELSE IF( LT_16( b_q, a_q ) ) { ab_q = b_q - a_q; *c_PS_LT_fx = L_add( a, L_shr( b, (Word16) ab_q ) ); @@ -2170,10 +2188,10 @@ void stereo_cna_update_params( } #else void stereo_cna_update_params_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ Word32 *output_fx[CPE_CHANNELS], /* i : Output signal */ - const int16_t output_frame, /* i : Output frame length */ - const int16_t tdm_ratio_idx /* i : TDM ratio index */ + const int16_t output_frame, /* i : Output frame length */ + const int16_t tdm_ratio_idx /* i : TDM ratio index */ ) { int16_t i; @@ -2192,10 +2210,10 @@ void stereo_cna_update_params_fx( hFdCngDec = sts[0]->hFdCngDec; - //delete below - //hFdCngDec->cna_act_fact_fx = (Word16)(hFdCngDec->cna_act_fact * (1 << 15)); - // hFdCngDec->cna_LR_LT_fx = (Word16)(hFdCngDec->cna_LR_LT * (1 << 15)); - // hFdCngDec->cna_ILD_LT_fx = (Word16)(hFdCngDec->cna_ILD_LT * (1 << 15)); + // delete below + // hFdCngDec->cna_act_fact_fx = (Word16)(hFdCngDec->cna_act_fact * (1 << 15)); + // hFdCngDec->cna_LR_LT_fx = (Word16)(hFdCngDec->cna_LR_LT * (1 << 15)); + // hFdCngDec->cna_ILD_LT_fx = (Word16)(hFdCngDec->cna_ILD_LT * (1 << 15)); ///// @@ -2203,7 +2221,7 @@ void stereo_cna_update_params_fx( { if ( hCPE->nchan_out > 1 ) { - FindEmEs_fx(output_fx[0], output_fx[1], output_frame,&hCPE->lt_es_em_fx); + FindEmEs_fx( output_fx[0], output_fx[1], output_frame, &hCPE->lt_es_em_fx ); } else { @@ -2212,7 +2230,7 @@ void stereo_cna_update_params_fx( } else if ( hCPE->element_mode == IVAS_CPE_TD ) { - FindEmEs_fx(output_fx[0], output_fx[1], output_frame, &hCPE->lt_es_em_fx); + FindEmEs_fx( output_fx[0], output_fx[1], output_frame, &hCPE->lt_es_em_fx ); hCPE->hStereoCng->first_SID_after_TD = 1; @@ -2240,101 +2258,101 @@ void stereo_cna_update_params_fx( FOR( i = 0; i < output_frame; i++ ) { - enrL_fx += ((Word64)output_fx[0][i] ) * ( output_fx[0][i] ); - enrR_fx += ((Word64)output_fx[1][i] ) * ( output_fx[1][i] ); - dotLR_fx += ( ((Word64)output_fx[0][i] ) * ( output_fx[1][i] ) ); + enrL_fx += ( (Word64) output_fx[0][i] ) * ( output_fx[0][i] ); + enrR_fx += ( (Word64) output_fx[1][i] ) * ( output_fx[1][i] ); + dotLR_fx += ( ( (Word64) output_fx[0][i] ) * ( output_fx[1][i] ) ); } dotLR_fx = dotLR_fx + EPSILON_FX_SMALL; - if (dotLR_fx < 0) + if ( dotLR_fx < 0 ) { - dotLR_fx = W_neg(dotLR_fx); + dotLR_fx = W_neg( dotLR_fx ); } enrL_fx = enrL_fx + EPSILON_FX_SMALL; enrR_fx = enrR_fx + EPSILON_FX_SMALL; - headroom_left_x = W_norm(enrL_fx); - headroom_left_y = W_norm(enrR_fx); + headroom_left_x = W_norm( enrL_fx ); + headroom_left_y = W_norm( enrR_fx ); - IF(headroom_left_x < 32) + IF( headroom_left_x < 32 ) { - enrL_fx = W_shr(enrL_fx, (32 - headroom_left_x)); - x_q = (31 - ((2 * OUTPUT_Q) - (32 - headroom_left_x))); + enrL_fx = W_shr( enrL_fx, ( 32 - headroom_left_x ) ); + x_q = ( 31 - ( ( 2 * OUTPUT_Q ) - ( 32 - headroom_left_x ) ) ); } ELSE { - x_q = 31 - (2 * OUTPUT_Q); + x_q = 31 - ( 2 * OUTPUT_Q ); } - IF(headroom_left_y < 32) + IF( headroom_left_y < 32 ) { - enrR_fx = W_shr(enrR_fx, (32 - headroom_left_y)); - y_q = (31 - ((2 * OUTPUT_Q) - (32 - headroom_left_y))); + enrR_fx = W_shr( enrR_fx, ( 32 - headroom_left_y ) ); + y_q = ( 31 - ( ( 2 * OUTPUT_Q ) - ( 32 - headroom_left_y ) ) ); } ELSE { - y_q = 31 - (2 * OUTPUT_Q); + y_q = 31 - ( 2 * OUTPUT_Q ); } x_inv_q = x_q; y_inv_q = y_q; - temp_x_inv = ISqrt32((Word32)enrL_fx, &x_inv_q); - temp_y_inv = ISqrt32((Word32)enrR_fx, &y_inv_q); - energy_xy_fx = Mpy_32_32(temp_x_inv, temp_y_inv); + temp_x_inv = ISqrt32( (Word32) enrL_fx, &x_inv_q ); + temp_y_inv = ISqrt32( (Word32) enrR_fx, &y_inv_q ); + energy_xy_fx = Mpy_32_32( temp_x_inv, temp_y_inv ); temp_res_q = x_inv_q + y_inv_q; - headroom_left_dotLR_fx = W_norm(dotLR_fx); + headroom_left_dotLR_fx = W_norm( dotLR_fx ); dotLR_fx_q = OUTPUT_Q * 2; - IF(headroom_left_dotLR_fx < 32) + IF( headroom_left_dotLR_fx < 32 ) { - dotLR_fx = W_shr(dotLR_fx, 32 - headroom_left_dotLR_fx); - dotLR_fx_q = dotLR_fx_q - (32 - headroom_left_dotLR_fx); + dotLR_fx = W_shr( dotLR_fx, 32 - headroom_left_dotLR_fx ); + dotLR_fx_q = dotLR_fx_q - ( 32 - headroom_left_dotLR_fx ); } - dotLR_fx = Mpy_32_32((Word32)dotLR_fx, energy_xy_fx); - dotLR_fx_q = dotLR_fx_q + (31 - temp_res_q) - 31; - dotLR_fx = (Word64)L_shl_sat((Word32)dotLR_fx, 31 - dotLR_fx_q); + dotLR_fx = Mpy_32_32( (Word32) dotLR_fx, energy_xy_fx ); + dotLR_fx_q = dotLR_fx_q + ( 31 - temp_res_q ) - 31; + dotLR_fx = (Word64) L_shl_sat( (Word32) dotLR_fx, 31 - dotLR_fx_q ); /* estimate L/R correlation factor and ILD in time domain */ - c_LR_fx = extract_h((Word32)dotLR_fx); + c_LR_fx = extract_h( (Word32) dotLR_fx ); temp_res_q = 0; - c_fx = BASOP_Util_Divide3232_Scale((Word32)enrL_fx, (Word32)enrR_fx, &temp_res_q); - c_q = 15 - temp_res_q + (y_q - x_q); - - Word32 one_in_c_q ; - IF (GT_16( c_q, 31 ) ) + c_fx = BASOP_Util_Divide3232_Scale( (Word32) enrL_fx, (Word32) enrR_fx, &temp_res_q ); + c_q = 15 - temp_res_q + ( y_q - x_q ); + + Word32 one_in_c_q; + IF( GT_16( c_q, 31 ) ) { - c_q = 31; - c_fx = L_shr_sat(c_fx, c_q - 31); - one_in_c_q = ONE_IN_Q31; + c_q = 31; + c_fx = L_shr_sat( c_fx, c_q - 31 ); + one_in_c_q = ONE_IN_Q31; } ELSE { - one_in_c_q = L_shl_sat(1, c_q); + one_in_c_q = L_shl_sat( 1, c_q ); } - Word32 num_c_fx = L_sub_sat(c_fx, one_in_c_q); - Word32 denom_c_fx = L_add_sat(c_fx, one_in_c_q); - Word16 num_c_headroom = norm_l(L_sub_sat(c_fx, one_in_c_q)); - Word16 denom_c_headroom = norm_l(L_add_sat(c_fx, one_in_c_q)); + Word32 num_c_fx = L_sub_sat( c_fx, one_in_c_q ); + Word32 denom_c_fx = L_add_sat( c_fx, one_in_c_q ); + Word16 num_c_headroom = norm_l( L_sub_sat( c_fx, one_in_c_q ) ); + Word16 denom_c_headroom = norm_l( L_add_sat( c_fx, one_in_c_q ) ); Word16 min_headroom_left = num_c_headroom < denom_c_headroom ? num_c_headroom : denom_c_headroom; temp_res_q = 0; - c_ILD_fx = BASOP_Util_Divide3232_Scale(L_shl_sat(num_c_fx, min_headroom_left), L_shl_sat(denom_c_fx, min_headroom_left), &temp_res_q); - if (temp_res_q < 0) + c_ILD_fx = BASOP_Util_Divide3232_Scale( L_shl_sat( num_c_fx, min_headroom_left ), L_shl_sat( denom_c_fx, min_headroom_left ), &temp_res_q ); + if ( temp_res_q < 0 ) { - c_ILD_fx = L_shr(c_ILD_fx, -1 * temp_res_q); + c_ILD_fx = L_shr( c_ILD_fx, -1 * temp_res_q ); } } /* update of long-term ILD and LR correlation factors for stereo CNA */ if ( !hFdCngDec->first_cna_noise_updated ) { - hFdCngDec->cna_LR_LT_fx = (Word16)c_LR_fx; - hFdCngDec->cna_ILD_LT_fx = (Word16)c_ILD_fx; + hFdCngDec->cna_LR_LT_fx = (Word16) c_LR_fx; + hFdCngDec->cna_ILD_LT_fx = (Word16) c_ILD_fx; } else { - hFdCngDec->cna_LR_LT_fx = extract_h(L_add_sat(Mpy_32_16_1(STEREO_CNA_LR_CORR_LT_FILT_FX, hFdCngDec->cna_LR_LT_fx), - Mpy_32_16_1(L_sub( ONE_IN_Q31, STEREO_CNA_LR_CORR_LT_FILT_FX ), (Word16)c_LR_fx))); + hFdCngDec->cna_LR_LT_fx = extract_h( L_add_sat( Mpy_32_16_1( STEREO_CNA_LR_CORR_LT_FILT_FX, hFdCngDec->cna_LR_LT_fx ), + Mpy_32_16_1( L_sub( ONE_IN_Q31, STEREO_CNA_LR_CORR_LT_FILT_FX ), (Word16) c_LR_fx ) ) ); - hFdCngDec->cna_ILD_LT_fx = extract_h(L_add_sat(Mpy_32_16_1(STEREO_CNA_ILD_LT_FILT_FX, hFdCngDec->cna_ILD_LT_fx), - Mpy_32_16_1(L_sub(ONE_IN_Q31, STEREO_CNA_ILD_LT_FILT_FX ), (Word16)c_ILD_fx))); + hFdCngDec->cna_ILD_LT_fx = extract_h( L_add_sat( Mpy_32_16_1( STEREO_CNA_ILD_LT_FILT_FX, hFdCngDec->cna_ILD_LT_fx ), + Mpy_32_16_1( L_sub( ONE_IN_Q31, STEREO_CNA_ILD_LT_FILT_FX ), (Word16) c_ILD_fx ) ) ); } set16_fx( hFdCngDec->cna_g_state_fx, hFdCngDec->cna_ILD_LT_fx, hFdCngDec->cna_nbands ); @@ -2356,7 +2374,7 @@ void stereo_cna_update_params_fx( /* quickly decrease in TD stereo mode */ hFdCngDec->cna_act_fact_fx = extract_h( Mpy_32_16_1( 1503238553, hFdCngDec->cna_act_fact_fx ) ); } - else if ( (sts[0]->VAD*MAX_WORD16) > hFdCngDec->cna_act_fact_fx )//VAD is one bit + else if ( ( sts[0]->VAD * MAX_WORD16 ) > hFdCngDec->cna_act_fact_fx ) // VAD is one bit { /* quickly increase during active frames in DFT stereo mode */ hFdCngDec->cna_act_fact_fx = extract_h( Mpy_32_16_1( 1503238553, hFdCngDec->cna_act_fact_fx ) + ( 644245094 * sts[0]->VAD ) ); @@ -2411,7 +2429,7 @@ void stereo_cng_init_dec( #else void stereo_cng_init_dec_fx( STEREO_CNG_DEC_HANDLE hStereoCng, /* i/o: stereo CNG decoder structure */ - const Word16 *frameSize /* i : pointer to frameSize of channel 0 to be used for channel 1 */ + const Word16 *frameSize /* i : pointer to frameSize of channel 0 to be used for channel 1 */ ) { hStereoCng->prev_sid_nodata = 0; diff --git a/lib_dec/ivas_stereo_dft_dec.c b/lib_dec/ivas_stereo_dft_dec.c index f1e909c95..0ed260376 100644 --- a/lib_dec/ivas_stereo_dft_dec.c +++ b/lib_dec/ivas_stereo_dft_dec.c @@ -55,9 +55,9 @@ #define STEFI_DELAY_IND( d, buf_ind ) ( ( buf_ind ) + STEREO_DFT_PAST_MAX - ( d ) + 1 ) % STEREO_DFT_PAST_MAX -#define STEREO_DFT_RES_RATIO_LIMIT 0.18f +#define STEREO_DFT_RES_RATIO_LIMIT 0.18f #ifdef IVAS_FLOAT_FIXED -#define STEREO_DFT_RES_RATIO_LIMIT_FX (Word32)(0x170A3D71) +#define STEREO_DFT_RES_RATIO_LIMIT_FX ( Word32 )( 0x170A3D71 ) #endif #define STEREO_DFT_LT_PREDGAIN_UPD 0.1f #define STEREO_DFT_VR_PREDGAIN_UPD 0.1f @@ -547,19 +547,19 @@ void stereo_dft_dec_update( k_offset = STEREO_DFT_OFFSET; /*Add an offset*/ /* Update parameters */ - for (i = 0; i < k_offset * STEREO_DFT_BAND_MAX; i++) + for ( i = 0; i < k_offset * STEREO_DFT_BAND_MAX; i++ ) { hStereoDft->side_gain[i] = hStereoDft->side_gain[STEREO_DFT_NBDIV * STEREO_DFT_BAND_MAX + i]; hStereoDft->res_pred_gain[i] = hStereoDft->res_pred_gain[STEREO_DFT_NBDIV * STEREO_DFT_BAND_MAX + i]; } - for (i = 0; i < k_offset; i++) + for ( i = 0; i < k_offset; i++ ) { hStereoDft->gipd[i] = hStereoDft->gipd[STEREO_DFT_NBDIV + i]; } /* Update configuration memories */ - for (i = 0; i < k_offset; i++) + for ( i = 0; i < k_offset; i++ ) { hStereoDft->band_res[i] = hStereoDft->band_res[i + STEREO_DFT_NBDIV]; hStereoDft->prm_res[i] = hStereoDft->prm_res[i + STEREO_DFT_NBDIV]; @@ -569,36 +569,36 @@ void stereo_dft_dec_update( } /* Load new configurations */ - set_s(hStereoDft->band_res + k_offset, hStereoDft->hConfig->band_res, STEREO_DFT_NBDIV); - set_s(hStereoDft->prm_res + k_offset, hStereoDft->hConfig->prm_res, STEREO_DFT_NBDIV); - set_s(hStereoDft->res_pred_mode + k_offset, hStereoDft->hConfig->res_pred_mode, STEREO_DFT_NBDIV); - set_s(hStereoDft->res_cod_mode + k_offset, hStereoDft->hConfig->res_cod_mode, STEREO_DFT_NBDIV); + set_s( hStereoDft->band_res + k_offset, hStereoDft->hConfig->band_res, STEREO_DFT_NBDIV ); + set_s( hStereoDft->prm_res + k_offset, hStereoDft->hConfig->prm_res, STEREO_DFT_NBDIV ); + set_s( hStereoDft->res_pred_mode + k_offset, hStereoDft->hConfig->res_pred_mode, STEREO_DFT_NBDIV ); + set_s( hStereoDft->res_cod_mode + k_offset, hStereoDft->hConfig->res_cod_mode, STEREO_DFT_NBDIV ); /*Update attack info*/ - if (hStereoDft->attackPresent) + if ( hStereoDft->attackPresent ) { hStereoDft->wasTransient = 1; } - else if (hStereoDft->wasTransient) + else if ( hStereoDft->wasTransient ) { hStereoDft->wasTransient = 0; } - for (i = STEREO_DFT_CORE_HIST_MAX - 1; i > 0; i--) + for ( i = STEREO_DFT_CORE_HIST_MAX - 1; i > 0; i-- ) { hStereoDft->core_hist[i] = hStereoDft->core_hist[i - 1]; } - mvr2r(hStereoDft->hb_stefi_sig + output_frame, hStereoDft->hb_stefi_sig, hStereoDft->hb_stefi_delay); - mvr2r(hStereoDft->hb_nrg, hStereoDft->hb_nrg + 1, STEREO_DFT_CORE_HIST_MAX - 1); - mvr2r(hStereoDft->td_gain, hStereoDft->td_gain + 1, STEREO_DFT_CORE_HIST_MAX - 1); + mvr2r( hStereoDft->hb_stefi_sig + output_frame, hStereoDft->hb_stefi_sig, hStereoDft->hb_stefi_delay ); + mvr2r( hStereoDft->hb_nrg, hStereoDft->hb_nrg + 1, STEREO_DFT_CORE_HIST_MAX - 1 ); + mvr2r( hStereoDft->td_gain, hStereoDft->td_gain + 1, STEREO_DFT_CORE_HIST_MAX - 1 ); - if (sba_dirac_stereo_flag) + if ( sba_dirac_stereo_flag ) { /* buffer update, push back by 2 because of 2 subframes */ - for (b = 0; b < hStereoDft->nbands; b++) + for ( b = 0; b < hStereoDft->nbands; b++ ) { - for (i = SBA_DIRAC_NRG_SMOOTH_LONG; i > 1; i--) + for ( i = SBA_DIRAC_NRG_SMOOTH_LONG; i > 1; i-- ) { hStereoDft->smooth_buf[b][i] = hStereoDft->smooth_buf[b][i - 2]; } @@ -623,19 +623,19 @@ void stereo_dft_dec_destroy( hStereoDft = *hStereoDft_glob; - IF ( hStereoDft->hConfig != NULL ) + IF( hStereoDft->hConfig != NULL ) { free( hStereoDft->hConfig ); hStereoDft->hConfig = NULL; } - IF ( hStereoDft->hBpf != NULL ) + IF( hStereoDft->hBpf != NULL ) { free( hStereoDft->hBpf ); hStereoDft->hBpf = NULL; } - IF ( hStereoDft->hTcxLtpDec != NULL ) + IF( hStereoDft->hTcxLtpDec != NULL ) { free( hStereoDft->hTcxLtpDec ); hStereoDft->hTcxLtpDec = NULL; @@ -1779,7 +1779,6 @@ void stereo_dft_dec( DFT_L[2 * i + 1] = pDFT_DMX[2 * i + 1] + tmp; DFT_R[2 * i + 1] = pDFT_DMX[2 * i + 1] - tmp; - } for ( ; i < hStereoDft->band_limits[b + 1]; i++ ) @@ -1793,7 +1792,6 @@ void stereo_dft_dec( DFT_L[2 * i + 1] = pDFT_DMX[2 * i + 1] + tmp; DFT_R[2 * i + 1] = pDFT_DMX[2 * i + 1] - tmp; - } /* Active Upmix */ @@ -2468,7 +2466,6 @@ void stereo_dft_dec_read_BS( } } } - } if ( !( ivas_format == MASA_FORMAT && ivas_total_brate <= IVAS_SID_5k2 ) ) @@ -2528,7 +2525,6 @@ void stereo_dft_dec_read_BS( #ifdef DUMPS_ENABLED dbgwrite_txt( res_buf, hStereoDft->res_cod_line_max, "float_res_buf.txt", NULL ); #endif // DUMPS_ENABLED - } else { @@ -2540,7 +2536,6 @@ void stereo_dft_dec_read_BS( ( *nb_bits ) += n_bits; pop_wmops(); - } if ( hStereoDft->frame_sid && !( ivas_format == MASA_FORMAT && ivas_total_brate <= IVAS_SID_5k2 ) ) @@ -3414,4 +3409,4 @@ static void stereo_dft_adapt_sf_delay( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/ivas_stereo_dft_dec_dmx.c b/lib_dec/ivas_stereo_dft_dec_dmx.c index 439753295..27ee4f817 100644 --- a/lib_dec/ivas_stereo_dft_dec_dmx.c +++ b/lib_dec/ivas_stereo_dft_dec_dmx.c @@ -645,118 +645,118 @@ void add_HB_to_mono_dmx( } #else void add_HB_to_mono_dmx_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 output[L_FRAME48k], /* i/o: output synthesis */ - Word32 outputHB[L_FRAME48k], /* i : HB synthesis */ - const int16_t last_core, /* i : last core, primary channel */ - const int16_t output_frame /* i : frame length */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 output[L_FRAME48k], /* i/o: output synthesis */ + Word32 outputHB[L_FRAME48k], /* i : HB synthesis */ + const int16_t last_core, /* i : last core, primary channel */ + const int16_t output_frame /* i : frame length */ ) { - int16_t i, j, decoderDelay, icbweOLASize, dftOvlLen, memOffset; - Word32 temp_fx[L_FRAME48k + NS2SA(48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS)]; + int16_t i, j, decoderDelay, icbweOLASize, dftOvlLen, memOffset; + Word32 temp_fx[L_FRAME48k + NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS )]; - Word32 winSlope_fx = 0; - Word32 alpha_fx; - const Word16 *win_dft_fx; - int32_t output_Fs; - Word32 *memOutHB_fx, *memTransitionHB_fx; + Word32 winSlope_fx = 0; + Word32 alpha_fx; + const Word16 *win_dft_fx; + int32_t output_Fs; + Word32 *memOutHB_fx, *memTransitionHB_fx; - output_Fs = hCPE->hCoreCoder[0]->output_Fs; + output_Fs = hCPE->hCoreCoder[0]->output_Fs; #if 0 Word16 q_memOutHB = Q_factor_arr(hCPE->hStereoDftDmx->memOutHB, NS2SA(48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS)); floatToFixed_arrL(hCPE->hStereoDftDmx->memOutHB, hCPE->hStereoDftDmx->memOutHB_fx, q_memOutHB, NS2SA(48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS)); #endif - memOutHB_fx = hCPE->hStereoDftDmx->memOutHB_fx; + memOutHB_fx = hCPE->hStereoDftDmx->memOutHB_fx; #if 0 Word16 q_memTransitionHB = Q_factor_arr(hCPE->hStereoDftDmx->memTransitionHB, NS2SA(48000, STEREO_DFT32MS_OVL_NS)); floatToFixed_arrL(hCPE->hStereoDftDmx->memTransitionHB, hCPE->hStereoDftDmx->memTransitionHB_fx, q_memTransitionHB, NS2SA(48000, STEREO_DFT32MS_OVL_NS)); #endif - memTransitionHB_fx = hCPE->hStereoDftDmx->memTransitionHB_fx; + memTransitionHB_fx = hCPE->hStereoDftDmx->memTransitionHB_fx; - memOffset = NS2SA(output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS); + memOffset = NS2SA( output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ); - IF (EQ_16(hCPE->hCoreCoder[0]->core, ACELP_CORE) && GT_32(hCPE->hCoreCoder[0]->extl_brate, 0)) - { - /* Resampled LB and HB offset */ - Copy32(outputHB, temp_fx + memOffset, output_frame - memOffset); + IF( EQ_16( hCPE->hCoreCoder[0]->core, ACELP_CORE ) && GT_32( hCPE->hCoreCoder[0]->extl_brate, 0 ) ) + { + /* Resampled LB and HB offset */ + Copy32( outputHB, temp_fx + memOffset, output_frame - memOffset ); - decoderDelay = NS2SA(output_Fs, IVAS_DEC_DELAY_NS); + decoderDelay = NS2SA( output_Fs, IVAS_DEC_DELAY_NS ); - IF (NE_16(last_core, ACELP_CORE)) - { - /* hb_synth of mid band is faded out in the 1.25 ms prior to DFT analysis and the icbwe is faded in time domain */ - icbweOLASize = NS2SA(output_Fs, STEREO_DFT_DELAY_DEC_BWE_NS); - - FOR (i = 0; i < decoderDelay; i++) - { - temp_fx[i] = 0; - } - - assert(icbweOLASize > 0); - switch (output_Fs) - { - case 48000: - winSlope_fx = 17895698; //Q30 - break; - case 32000: - winSlope_fx = 26843546; - break; - case 16000: - winSlope_fx = 53687092; - break; - } - alpha_fx = winSlope_fx; // Q30 - FOR (; i < decoderDelay + icbweOLASize; i++) - { - temp_fx[i] = L_shl(Mpy_32_32(temp_fx[i], alpha_fx), 1); - alpha_fx = L_add_sat(alpha_fx, winSlope_fx); - } - } - ELSE - { - Copy32(memOutHB_fx, temp_fx, memOffset); - } + IF( NE_16( last_core, ACELP_CORE ) ) + { + /* hb_synth of mid band is faded out in the 1.25 ms prior to DFT analysis and the icbwe is faded in time domain */ + icbweOLASize = NS2SA( output_Fs, STEREO_DFT_DELAY_DEC_BWE_NS ); - v_add_32(temp_fx, output, output, output_frame); - - Copy32(outputHB + output_frame - memOffset, memOutHB_fx, memOffset); + FOR( i = 0; i < decoderDelay; i++ ) + { + temp_fx[i] = 0; + } - win_dft_fx = hCPE->hStereoDft->win32ms_fx; - dftOvlLen = hCPE->hStereoDft->dft32ms_ovl; + assert( icbweOLASize > 0 ); + switch ( output_Fs ) + { + case 48000: + winSlope_fx = 17895698; // Q30 + break; + case 32000: + winSlope_fx = 26843546; + break; + case 16000: + winSlope_fx = 53687092; + break; + } + alpha_fx = winSlope_fx; // Q30 + FOR( ; i < decoderDelay + icbweOLASize; i++ ) + { + temp_fx[i] = L_shl( Mpy_32_32( temp_fx[i], alpha_fx ), 1 ); + alpha_fx = L_add_sat( alpha_fx, winSlope_fx ); + } + } + ELSE + { + Copy32( memOutHB_fx, temp_fx, memOffset ); + } - /* Preparing buffers in anticipation of an ACELP to TCX switch */ - j = 0; - FOR (i = 0; i < memOffset; i++) - { - memTransitionHB_fx[i] = Mpy_32_16_1(memOutHB_fx[i], win_dft_fx[STEREO_DFT32MS_STEP * (dftOvlLen - 1 - j)]); - j++; - } + v_add_32( temp_fx, output, output, output_frame ); - FOR (i = 0; j < dftOvlLen; i++) - { - memTransitionHB_fx[memOffset + i] = Mpy_32_16_1(outputHB[output_frame - i - 1], win_dft_fx[STEREO_DFT32MS_STEP * (dftOvlLen - 1 - j)]); - j++; + Copy32( outputHB + output_frame - memOffset, memOutHB_fx, memOffset ); + + win_dft_fx = hCPE->hStereoDft->win32ms_fx; + dftOvlLen = hCPE->hStereoDft->dft32ms_ovl; + + /* Preparing buffers in anticipation of an ACELP to TCX switch */ + j = 0; + FOR( i = 0; i < memOffset; i++ ) + { + memTransitionHB_fx[i] = Mpy_32_16_1( memOutHB_fx[i], win_dft_fx[STEREO_DFT32MS_STEP * ( dftOvlLen - 1 - j )] ); + j++; + } + + FOR( i = 0; j < dftOvlLen; i++ ) + { + memTransitionHB_fx[memOffset + i] = Mpy_32_16_1( outputHB[output_frame - i - 1], win_dft_fx[STEREO_DFT32MS_STEP * ( dftOvlLen - 1 - j )] ); + j++; + } } - } - ELSE - { - IF (EQ_16(last_core, ACELP_CORE)) + ELSE { - /* This is generated in the ACELP frame and windowed. This process is akin to GenTransition for IC-BWE */ - IF (EQ_16(hCPE->element_mode, IVAS_CPE_DFT) && EQ_16(hCPE->nchan_out, 1) && EQ_16(hCPE->hStereoDft->hConfig->res_cod_mode, STEREO_DFT_RES_COD_OFF)) - { - v_add_32(output, outputHB, output, NS2SA(output_Fs, STEREO_DFT32MS_OVL_NS)); - } - ELSE - { - v_add_32(output, memTransitionHB_fx, output, NS2SA(output_Fs, STEREO_DFT32MS_OVL_NS)); - } - - set32_fx(memOutHB_fx, 0, memOffset); - set32_fx(memTransitionHB_fx, 0, NS2SA(output_Fs, STEREO_DFT32MS_OVL_NS)); + IF( EQ_16( last_core, ACELP_CORE ) ) + { + /* This is generated in the ACELP frame and windowed. This process is akin to GenTransition for IC-BWE */ + IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && EQ_16( hCPE->nchan_out, 1 ) && EQ_16( hCPE->hStereoDft->hConfig->res_cod_mode, STEREO_DFT_RES_COD_OFF ) ) + { + v_add_32( output, outputHB, output, NS2SA( output_Fs, STEREO_DFT32MS_OVL_NS ) ); + } + ELSE + { + v_add_32( output, memTransitionHB_fx, output, NS2SA( output_Fs, STEREO_DFT32MS_OVL_NS ) ); + } + + set32_fx( memOutHB_fx, 0, memOffset ); + set32_fx( memTransitionHB_fx, 0, NS2SA( output_Fs, STEREO_DFT32MS_OVL_NS ) ); + } } - } - return; + return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/ivas_stereo_dft_dec_fx.c b/lib_dec/ivas_stereo_dft_dec_fx.c index 0aa7f0f61..1c973dd5d 100644 --- a/lib_dec/ivas_stereo_dft_dec_fx.c +++ b/lib_dec/ivas_stereo_dft_dec_fx.c @@ -57,21 +57,21 @@ #define STEFI_DELAY_IND( d, buf_ind ) ( ( buf_ind ) + STEREO_DFT_PAST_MAX - ( d ) + 1 ) % STEREO_DFT_PAST_MAX -#define STEREO_DFT_RES_RATIO_LIMIT_FX (Word32)(0x170A3D71) -#define STEREO_DFT_RES_RATIO_LIMIT_FX_3_BY_2 (Word32)(0x228F5C28) -#define ONE_STEREO_DFT_RES_RATIO_LIMIT_Q12 (Word16)(0x58E4) -#define STEREO_DFT_LT_PREDGAIN_UPD_FX (Word16)(0x0CCD) -#define STEREO_DFT_VR_PREDGAIN_UPD_FX (Word16)(0x0CCD) -#define STEREO_DFT_STEFFI_PG_THRESHOLD_FX (Word32)(0x4CCCCCCD) -#define STEREO_DFT_STEFFI_RATIO_UP_HIGH_FX (Word32)(0x03D70A3D) -#define STEREO_DFT_STEFFI_RATIO_DOWN_HIGH_FX (Word32)(0x06666666) -#define STEREO_DFT_STEFFI_RATIO_UP_LOW_FX (Word32)(0x0CCCCCCC) -#define STEREO_DFT_STEFFI_RATIO_DOWN_LOW_FX (Word32)(0x0020C49C) -#define STEREO_DFT_STEFFI_DELAY_SHORT 2 -#define STEREO_DFT_STEFFI_DELAY_LONG 4 -#define STEREO_DFT_STEFFI_DELAY_OFFSET 2 -#define STEREO_DFT_STEFFI_GAIN_REST_AMT_FX (Word16)(0x4CCD) -#define STEREO_DFT_STEFFI_GAIN_AMP_FX (Word16)(0x7FFF) +#define STEREO_DFT_RES_RATIO_LIMIT_FX ( Word32 )( 0x170A3D71 ) +#define STEREO_DFT_RES_RATIO_LIMIT_FX_3_BY_2 ( Word32 )( 0x228F5C28 ) +#define ONE_STEREO_DFT_RES_RATIO_LIMIT_Q12 ( Word16 )( 0x58E4 ) +#define STEREO_DFT_LT_PREDGAIN_UPD_FX ( Word16 )( 0x0CCD ) +#define STEREO_DFT_VR_PREDGAIN_UPD_FX ( Word16 )( 0x0CCD ) +#define STEREO_DFT_STEFFI_PG_THRESHOLD_FX ( Word32 )( 0x4CCCCCCD ) +#define STEREO_DFT_STEFFI_RATIO_UP_HIGH_FX ( Word32 )( 0x03D70A3D ) +#define STEREO_DFT_STEFFI_RATIO_DOWN_HIGH_FX ( Word32 )( 0x06666666 ) +#define STEREO_DFT_STEFFI_RATIO_UP_LOW_FX ( Word32 )( 0x0CCCCCCC ) +#define STEREO_DFT_STEFFI_RATIO_DOWN_LOW_FX ( Word32 )( 0x0020C49C ) +#define STEREO_DFT_STEFFI_DELAY_SHORT 2 +#define STEREO_DFT_STEFFI_DELAY_LONG 4 +#define STEREO_DFT_STEFFI_DELAY_OFFSET 2 +#define STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ( Word16 )( 0x4CCD ) +#define STEREO_DFT_STEFFI_GAIN_AMP_FX ( Word16 )( 0x7FFF ) #define STEREO_DFT_BPF_SIZE 40 /* BPF: Number of weights for BPF in DFT: 40*40Hz=1.6kHz*/ @@ -400,8 +400,8 @@ ivas_error stereo_dft_dec_create_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TCX-LTP handle\n" ) ); } #ifdef MSAN_FIX - set_zero_fx( hStereoDft_loc->hb_nrg_subr_fx, STEREO_DFT_NBDIV );/*Setting hb_nrg_subr_fx to zero*/ -#endif // MSAN_FIX + set_zero_fx( hStereoDft_loc->hb_nrg_subr_fx, STEREO_DFT_NBDIV ); /*Setting hb_nrg_subr_fx to zero*/ +#endif // MSAN_FIX hStereoDft_loc->hConfig->force_mono_transmission = 0; move16(); @@ -438,16 +438,16 @@ static void stereo_dft_dequantize_res_gains_fx( { Word16 i, index; - FOR ( i = 0; i < N; i++ ) + FOR( i = 0; i < N; i++ ) { /* Ensure the indices are within range -- may go out of range due to frame loss */ ind1[i] = check_bounds_s( ind1[i], 0, 30 ); move16(); ind2[i] = check_bounds_s( ind2[i], 0, 7 ); move16(); - index = add(shl( LE_16(ind1[i], 15) ? sub(15, ind1[i]) : sub(ind1[i], 15), 3 ), ind2[i]); + index = add( shl( LE_16( ind1[i], 15 ) ? sub( 15, ind1[i] ) : sub( ind1[i], 15 ), 3 ), ind2[i] ); move16(); - gout[i] = LE_16(ind1[i], 15) ? L_negate(dft_res_gains_q_fx[index][0]) : dft_res_gains_q_fx[index][0]; + gout[i] = LE_16( ind1[i], 15 ) ? L_negate( dft_res_gains_q_fx[index][0] ) : dft_res_gains_q_fx[index][0]; move16(); rout[i] = dft_res_gains_q_fx[index][1]; move16(); @@ -472,36 +472,36 @@ static void stereo_dft_dequantize_res_gains_f_fx( Word16 i, i1, j1, sign, ji, ij; Word32 fi, fj; - FOR ( i = 0; i < N; i++ ) + FOR( i = 0; i < N; i++ ) { /* Ensure the indices are within range -- may go out of range due to frame loss */ - ind1[i] = check_bounds_l( ind1[i], 0, L_shl(31, Q26)); + ind1[i] = check_bounds_l( ind1[i], 0, L_shl( 31, Q26 ) ); move32(); - ind2[i] = check_bounds_l( ind2[i], 0, L_shl(7, Q26)); + ind2[i] = check_bounds_l( ind2[i], 0, L_shl( 7, Q26 ) ); move32(); /* compensate for the offset and extract/remove sign of first index */ - sign = LT_32(ind1[i], L_shl(15, Q26)) ? -1 : 1; + sign = LT_32( ind1[i], L_shl( 15, Q26 ) ) ? -1 : 1; move16(); - i1 = (Word16)L_shr(( LT_32(ind1[i], L_shl(15, Q26)) ? L_sub(L_shl(15, Q26), ind1[i]) : L_sub(ind1[i], L_shl(15, Q26)) ), Q26); - fi = (LT_32( ind1[i], L_shl(15, Q26)) ? L_sub(L_shl(15, Q26), ind1[i]) : L_sub(ind1[i], L_shl(15, Q26))) - L_shl(i1, Q26); + i1 = (Word16) L_shr( ( LT_32( ind1[i], L_shl( 15, Q26 ) ) ? L_sub( L_shl( 15, Q26 ), ind1[i] ) : L_sub( ind1[i], L_shl( 15, Q26 ) ) ), Q26 ); + fi = ( LT_32( ind1[i], L_shl( 15, Q26 ) ) ? L_sub( L_shl( 15, Q26 ), ind1[i] ) : L_sub( ind1[i], L_shl( 15, Q26 ) ) ) - L_shl( i1, Q26 ); move16(); j1 = (Word16) L_shr( ind2[i], Q26 ); - fj = L_sub(ind2[i], L_shl(j1, Q26)); + fj = L_sub( ind2[i], L_shl( j1, Q26 ) ); /* choose base indices for interpolation */ - ji = (Word16)L_min( fj < ONE_IN_Q25 ? j1 : j1 + 1, 7 ); - ij = (Word16)L_min( fi < ONE_IN_Q25 ? i1 : i1 + 1, 15 ); + ji = (Word16) L_min( fj < ONE_IN_Q25 ? j1 : j1 + 1, 7 ); + ij = (Word16) L_min( fi < ONE_IN_Q25 ? i1 : i1 + 1, 15 ); /* interpolate values from table */ // IF ( LT_32(i1, L_shl(15, Q26)) ) - IF ( LT_16(i1, 15) ) + IF( LT_16( i1, 15 ) ) { - gout[i] = Madd_32_32( Mpy_32_32(L_sub(MAX_32, L_shl(fi , Q5)), dft_res_gains_q_fx[( i1 << 3 ) + ji][0]), dft_res_gains_q_fx[( ( i1 + 1 ) << 3 ) + ji][0], L_shl(fi, Q5) ); + gout[i] = Madd_32_32( Mpy_32_32( L_sub( MAX_32, L_shl( fi, Q5 ) ), dft_res_gains_q_fx[( i1 << 3 ) + ji][0] ), dft_res_gains_q_fx[( ( i1 + 1 ) << 3 ) + ji][0], L_shl( fi, Q5 ) ); move32(); - IF (EQ_16(sign , -1)) + IF( EQ_16( sign, -1 ) ) { - gout[i] = L_negate(gout[i]); + gout[i] = L_negate( gout[i] ); move32(); } } @@ -509,16 +509,16 @@ static void stereo_dft_dequantize_res_gains_f_fx( { gout[i] = sign * dft_res_gains_q_fx[120 + ji][0]; move32(); - IF (EQ_16(sign , -1)) + IF( EQ_16( sign, -1 ) ) { - gout[i] = L_negate(gout[i]); + gout[i] = L_negate( gout[i] ); move32(); } } - IF ( LT_32(j1, L_shl(7, Q26)) ) + IF( LT_32( j1, L_shl( 7, Q26 ) ) ) { - rout[i] = Madd_32_32(Mpy_32_32(L_sub(MAX_32, L_shl(fj , Q5)), dft_res_gains_q_fx[( ij << 3 ) + j1][1]), L_shl(fj, Q5) , dft_res_gains_q_fx[( ij << 3 ) + j1 + 1][1]); + rout[i] = Madd_32_32( Mpy_32_32( L_sub( MAX_32, L_shl( fj, Q5 ) ), dft_res_gains_q_fx[( ij << 3 ) + j1][1] ), L_shl( fj, Q5 ), dft_res_gains_q_fx[( ij << 3 ) + j1 + 1][1] ); move32(); } ELSE @@ -629,11 +629,11 @@ void stereo_dft_dec_update_fx( *-------------------------------------------------------------------------*/ void stereo_dft_dec_synthesize_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ Word32 DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i : DFT buffers */ - const Word16 chan, /* i : channel number */ + const Word16 chan, /* i : channel number */ Word32 output[L_FRAME48k], /* o : output synthesis signal */ - const Word16 output_frame /* i : output frame length */ + const Word16 output_frame /* i : output frame length */ ) { Word16 i, k; @@ -641,7 +641,7 @@ void stereo_dft_dec_synthesize_fx( STEREO_DFT_DEC_DATA_HANDLE hStereoDft; Word32 *p_DFT; const Word16 *win, *win2; - Word16 trigo_dec[((STEREO_DFT32MS_N_MAX) >> 1) + 1]; + Word16 trigo_dec[( ( STEREO_DFT32MS_N_MAX ) >> 1 ) + 1]; Word16 trigo_step; Word16 ovl, zp, NFFT; Word32 outputFs; @@ -657,9 +657,9 @@ void stereo_dft_dec_synthesize_fx( hStereoDft = hCPE->hStereoDft; - hCPE->lt_es_em_fx = L_shr(hCPE->lt_es_em_fx, 9); // Q24 -> Q15 + hCPE->lt_es_em_fx = L_shr( hCPE->lt_es_em_fx, 9 ); // Q24 -> Q15 - outputFs = L_mult0(output_frame, FRAMES_PER_SEC); + outputFs = L_mult0( output_frame, FRAMES_PER_SEC ); zp = NS2SA( outputFs, STEREO_DFT32MS_ZP_NS ); move16(); @@ -670,7 +670,7 @@ void stereo_dft_dec_synthesize_fx( move16(); ovl2 = NS2SA( outputFs, STEREO_DFT32MS_OVL2_NS ); move16(); - flat_portion_end = NS2SA( outputFs, L_sub(STEREO_DFT32MS_WIN_CENTER_NS , L_shr(STEREO_DFT32MS_OVL2_NS, 1)) ); + flat_portion_end = NS2SA( outputFs, L_sub( STEREO_DFT32MS_WIN_CENTER_NS, L_shr( STEREO_DFT32MS_OVL2_NS, 1 ) ) ); move16(); win2 = hStereoDft->win232ms_fx; @@ -678,17 +678,17 @@ void stereo_dft_dec_synthesize_fx( set_val_Word32( output, 0, NS2SA( outputFs, FRAME_SIZE_NS ) ); /* deactivating the spectrum scrambling on active speech */ - IF ( ( EQ_16(chan, 0) && GT_16(hCPE->hCoreCoder[0]->last_coder_type, UNVOICED) ) || EQ_16(hCPE->last_element_mode, IVAS_CPE_MDCT) || LT_16(hCPE->last_element_mode, IVAS_CPE_DFT) ) + IF( ( EQ_16( chan, 0 ) && GT_16( hCPE->hCoreCoder[0]->last_coder_type, UNVOICED ) ) || EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) || LT_16( hCPE->last_element_mode, IVAS_CPE_DFT ) ) { hCPE->stereo_switching_counter = 10; move16(); } - IF ( EQ_16(hCPE->stereo_switching_counter, 0) ) + IF( EQ_16( hCPE->stereo_switching_counter, 0 ) ) { /* Set the level of dispersion */ - Word16 tmp = extract_l(L_max( (Word16)0xF333, L_min( (Word16)0x3333, hCPE->lt_es_em_fx ) )); - hCPE->NbFrameMod = extract_h(L_add( L_mult0(12, tmp) , 0x0000D99A )); /* -0.1: -0.4 ; -0.1 -> 0, 0.4 -> 6*/ + Word16 tmp = extract_l( L_max( (Word16) 0xF333, L_min( (Word16) 0x3333, hCPE->lt_es_em_fx ) ) ); + hCPE->NbFrameMod = extract_h( L_add( L_mult0( 12, tmp ), 0x0000D99A ) ); /* -0.1: -0.4 ; -0.1 -> 0, 0.4 -> 6*/ } moffset = max( 0, 6 - hCPE->NbFrameMod ); @@ -696,65 +696,65 @@ void stereo_dft_dec_synthesize_fx( * Synthesis *-----------------------------------------------------------------*/ - trigo_step = i_mult(hStereoDft->dft_trigo_step, STEREO_DFT_TRIGO_DEC_STEP); - FOR ( i = 0; i < shr(NFFT, 2); i++ ) + trigo_step = i_mult( hStereoDft->dft_trigo_step, STEREO_DFT_TRIGO_DEC_STEP ); + FOR( i = 0; i < shr( NFFT, 2 ); i++ ) { trigo_dec[i] = hStereoDft->dft_trigo_fx[i * trigo_step]; move16(); - trigo_dec[sub(shr(NFFT , 1) , i)] = hStereoDft->dft_trigo_fx[i * trigo_step]; + trigo_dec[sub( shr( NFFT, 1 ), i )] = hStereoDft->dft_trigo_fx[i * trigo_step]; move16(); } - trigo_dec[shr(NFFT , 2)] = hStereoDft->dft_trigo_fx[shr(NFFT , 2) * trigo_step]; + trigo_dec[shr( NFFT, 2 )] = hStereoDft->dft_trigo_fx[shr( NFFT, 2 ) * trigo_step]; move16(); - FOR ( k = 0; k < STEREO_DFT_NBDIV; k++ ) + FOR( k = 0; k < STEREO_DFT_NBDIV; k++ ) { /* scrambling the spectrum */ - IF ( LE_16(hCPE->stereo_switching_counter , 6) && EQ_16(chan, 1) && ( GT_32(hCPE->lt_es_em_fx , (Word16)0xCCCD) || GT_16(hCPE->NbFrameMod, 4) ) ) + IF( LE_16( hCPE->stereo_switching_counter, 6 ) && EQ_16( chan, 1 ) && ( GT_32( hCPE->lt_es_em_fx, (Word16) 0xCCCD ) || GT_16( hCPE->NbFrameMod, 4 ) ) ) { - FOR ( i = 3; i < NFFT - moffset - 1; i++ ) + FOR( i = 3; i < NFFT - moffset - 1; i++ ) { - p_DFT[i] = L_negate(p_DFT[i + moffset + 1]); + p_DFT[i] = L_negate( p_DFT[i + moffset + 1] ); move32(); } } - ELSE IF ( LT_16(hCPE->stereo_switching_counter, 7) && ( GT_32(hCPE->lt_es_em_fx , (Word16)0x199A) || GT_16(hCPE->NbFrameMod , 4) ) ) + ELSE IF( LT_16( hCPE->stereo_switching_counter, 7 ) && ( GT_32( hCPE->lt_es_em_fx, (Word16) 0x199A ) || GT_16( hCPE->NbFrameMod, 4 ) ) ) { - FOR ( i = sub(16 , hCPE->NbFrameMod); i < sub(NFFT, add(moffset, 1)); i++ ) + FOR( i = sub( 16, hCPE->NbFrameMod ); i < sub( NFFT, add( moffset, 1 ) ); i++ ) { - p_DFT[i - 2] = L_negate(p_DFT[i + moffset + 1]); + p_DFT[i - 2] = L_negate( p_DFT[i + moffset + 1] ); move32(); } } /*IFFT*/ - scale_dft = getScaleFactor32(p_DFT, NFFT); - scale_dft = find_guarded_bits_fx(NFFT) - scale_dft; - v_shr(p_DFT, scale_dft, p_DFT, NFFT); + scale_dft = getScaleFactor32( p_DFT, NFFT ); + scale_dft = find_guarded_bits_fx( NFFT ) - scale_dft; + v_shr( p_DFT, scale_dft, p_DFT, NFFT ); rfft_fx( p_DFT, trigo_dec, NFFT, +1 ); - v_shr(p_DFT, negate(scale_dft), p_DFT, NFFT); + v_shr( p_DFT, negate( scale_dft ), p_DFT, NFFT ); - IF ( EQ_16(k , 0) ) + IF( EQ_16( k, 0 ) ) { offset = 0; move16(); /* Left OLA - 3.125ms */ - FOR ( i = 0; i < ovl; i++ ) + FOR( i = 0; i < ovl; i++ ) { - output[offset + i] = Madd_32_16(L_shr(hCPE->output_mem_fx[chan][i], sub(hCPE->q_output_mem_fx[chan], hCPE->hStereoDft->q_dft)), p_DFT[zp + i], win[STEREO_DFT32MS_STEP * i]); + output[offset + i] = Madd_32_16( L_shr( hCPE->output_mem_fx[chan][i], sub( hCPE->q_output_mem_fx[chan], hCPE->hStereoDft->q_dft ) ), p_DFT[zp + i], win[STEREO_DFT32MS_STEP * i] ); move32(); } /* Flat Portion */ - FOR ( i = ovl; i < flat_portion_end; i++ ) + FOR( i = ovl; i < flat_portion_end; i++ ) { output[offset + i] = p_DFT[zp + i]; move32(); } /* Right OLA */ - FOR ( i = 0; i < ovl2; i++ ) + FOR( i = 0; i < ovl2; i++ ) { - ola_buff[i] = Mpy_32_16_1( p_DFT[NFFT - zp - ovl2 + i], win2[ovl2 - 1 - i]); + ola_buff[i] = Mpy_32_16_1( p_DFT[NFFT - zp - ovl2 + i], win2[ovl2 - 1 - i] ); move32(); } } @@ -764,21 +764,21 @@ void stereo_dft_dec_synthesize_fx( offset = flat_portion_end; move16(); /* Left OLA */ - FOR ( i = 0; i < ovl2; i++ ) + FOR( i = 0; i < ovl2; i++ ) { - output[offset + i] = Madd_32_16(ola_buff[i], p_DFT[zp + i], win2[i]); + output[offset + i] = Madd_32_16( ola_buff[i], p_DFT[zp + i], win2[i] ); move32(); } /* Flat Portion */ - FOR ( i = ovl2; i < NFFT - 2 * zp - ovl; i++ ) + FOR( i = ovl2; i < NFFT - 2 * zp - ovl; i++ ) { output[offset + i] = p_DFT[zp + i]; move32(); } /* Right OLA - 3.125ms */ - FOR ( i = 0; i < ovl; i++ ) + FOR( i = 0; i < ovl; i++ ) { - hCPE->output_mem_fx[chan][i] = Mpy_32_16_1(p_DFT[NFFT - zp - ovl + i], win[STEREO_DFT32MS_STEP * ( ovl - 1 - i )]); + hCPE->output_mem_fx[chan][i] = Mpy_32_16_1( p_DFT[NFFT - zp - ovl + i], win[STEREO_DFT32MS_STEP * ( ovl - 1 - i )] ); move32(); } hCPE->q_output_mem_fx[chan] = hCPE->hStereoDft->q_dft; @@ -786,7 +786,7 @@ void stereo_dft_dec_synthesize_fx( p_DFT += STEREO_DFT32MS_N_MAX; } - hCPE->lt_es_em_fx = L_shl(hCPE->lt_es_em_fx, 9); // Q15 -> Q24 + hCPE->lt_es_em_fx = L_shl( hCPE->lt_es_em_fx, 9 ); // Q15 -> Q24 pop_wmops(); return; @@ -800,9 +800,9 @@ void stereo_dft_dec_synthesize_fx( void stereo_dft_dec_smooth_parameters_fx( STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ - const Word16 prev_sid_nodata, /* i : Previous SID/No data indicator */ - const Word16 active_frame_counter, /* i : Active frame counter */ - const Word32 element_brate /* i : Element bitrate */ + const Word16 prev_sid_nodata, /* i : Previous SID/No data indicator */ + const Word16 active_frame_counter, /* i : Active frame counter */ + const Word32 element_brate /* i : Element bitrate */ ) { Word16 k_offset, k, k2, b, N_div; @@ -818,81 +818,81 @@ void stereo_dft_dec_smooth_parameters_fx( k_offset = STEREO_DFT_OFFSET; move16(); - IF ( hStereoDft->frame_sid_nodata || prev_sid_nodata ) + IF( hStereoDft->frame_sid_nodata || prev_sid_nodata ) { k = 1; - FOR ( b = 0; b < hStereoDft->nbands; b++ ) + FOR( b = 0; b < hStereoDft->nbands; b++ ) { - *( hStereoDft->side_gain_fx + ( ( add( k , k_offset ) ) - 1 ) * STEREO_DFT_BAND_MAX + b ) = *( hStereoDft->side_gain_fx + ( add( k , k_offset ) ) * STEREO_DFT_BAND_MAX + b ); + *( hStereoDft->side_gain_fx + ( ( add( k, k_offset ) ) - 1 ) * STEREO_DFT_BAND_MAX + b ) = *( hStereoDft->side_gain_fx + ( add( k, k_offset ) ) * STEREO_DFT_BAND_MAX + b ); move32(); } - IF ( hStereoDft->frame_sid_nodata ) + IF( hStereoDft->frame_sid_nodata ) { /* set new xfade target if new itd received */ #ifdef NONBE_FIX_1010_STEREO_CNG_DIV_BY_ZERO - IF ( LT_16(hStereoDft->ipd_xfade_counter, STEREO_DFT_ITD_CNG_XFADE) ) + IF( LT_16( hStereoDft->ipd_xfade_counter, STEREO_DFT_ITD_CNG_XFADE ) ) #else - IF ( NE_32(hStereoDft->gipd_fx[add( k , k_offset )], hStereoDft->ipd_xfade_target_fx) ) + IF( NE_32( hStereoDft->gipd_fx[add( k, k_offset )], hStereoDft->ipd_xfade_target_fx ) ) #endif { Word16 q_val; - IF ( GT_32(L_sub( hStereoDft->gipd_fx[add( k , k_offset )], hStereoDft->ipd_xfade_prev_fx ), EVS_PI_FX) ) + IF( GT_32( L_sub( hStereoDft->gipd_fx[add( k, k_offset )], hStereoDft->ipd_xfade_prev_fx ), EVS_PI_FX ) ) { - hStereoDft->ipd_xfade_target_fx = L_sub(hStereoDft->gipd_fx[add( k , k_offset )], EVS_PI_FX); + hStereoDft->ipd_xfade_target_fx = L_sub( hStereoDft->gipd_fx[add( k, k_offset )], EVS_PI_FX ); move32(); - hStereoDft->ipd_xfade_step_fx = BASOP_Util_Divide3232_Scale(L_sub( hStereoDft->ipd_xfade_target_fx, hStereoDft->ipd_xfade_prev_fx ) , L_shl(L_sub( STEREO_DFT_ITD_CNG_XFADE, hStereoDft->ipd_xfade_counter ), Q13), &q_val); - q_val = sub(q_val, Q2); + hStereoDft->ipd_xfade_step_fx = BASOP_Util_Divide3232_Scale( L_sub( hStereoDft->ipd_xfade_target_fx, hStereoDft->ipd_xfade_prev_fx ), L_shl( L_sub( STEREO_DFT_ITD_CNG_XFADE, hStereoDft->ipd_xfade_counter ), Q13 ), &q_val ); + q_val = sub( q_val, Q2 ); move32(); - IF (GT_16(q_val, 16)) + IF( GT_16( q_val, 16 ) ) { - assert(0); + assert( 0 ); } ELSE { - hStereoDft->ipd_xfade_step_fx = L_shl(hStereoDft->ipd_xfade_step_fx, q_val); + hStereoDft->ipd_xfade_step_fx = L_shl( hStereoDft->ipd_xfade_step_fx, q_val ); } } - ELSE IF ( GT_32(L_sub( hStereoDft->ipd_xfade_prev_fx, hStereoDft->gipd_fx[add( k , k_offset )] ), EVS_PI_FX) ) + ELSE IF( GT_32( L_sub( hStereoDft->ipd_xfade_prev_fx, hStereoDft->gipd_fx[add( k, k_offset )] ), EVS_PI_FX ) ) { - hStereoDft->ipd_xfade_target_fx = L_add(hStereoDft->gipd_fx[add( k , k_offset )], L_shl(EVS_PI_FX, 1)); + hStereoDft->ipd_xfade_target_fx = L_add( hStereoDft->gipd_fx[add( k, k_offset )], L_shl( EVS_PI_FX, 1 ) ); move32(); - hStereoDft->ipd_xfade_step_fx = BASOP_Util_Divide3232_Scale(L_sub( hStereoDft->ipd_xfade_target_fx, hStereoDft->ipd_xfade_prev_fx ) , L_shl(L_sub( STEREO_DFT_ITD_CNG_XFADE, hStereoDft->ipd_xfade_counter ), Q13), &q_val); - q_val = sub(q_val, Q2); + hStereoDft->ipd_xfade_step_fx = BASOP_Util_Divide3232_Scale( L_sub( hStereoDft->ipd_xfade_target_fx, hStereoDft->ipd_xfade_prev_fx ), L_shl( L_sub( STEREO_DFT_ITD_CNG_XFADE, hStereoDft->ipd_xfade_counter ), Q13 ), &q_val ); + q_val = sub( q_val, Q2 ); move32(); - IF (GT_16(q_val, 16)) + IF( GT_16( q_val, 16 ) ) { - assert(0); + assert( 0 ); } ELSE { - hStereoDft->ipd_xfade_step_fx = L_shl(hStereoDft->ipd_xfade_step_fx, q_val); + hStereoDft->ipd_xfade_step_fx = L_shl( hStereoDft->ipd_xfade_step_fx, q_val ); } } ELSE { - hStereoDft->ipd_xfade_target_fx = hStereoDft->gipd_fx[add( k , k_offset )]; + hStereoDft->ipd_xfade_target_fx = hStereoDft->gipd_fx[add( k, k_offset )]; move32(); - hStereoDft->ipd_xfade_step_fx = BASOP_Util_Divide3232_Scale(L_sub( hStereoDft->ipd_xfade_target_fx, hStereoDft->ipd_xfade_prev_fx ) , L_shl(L_sub( STEREO_DFT_ITD_CNG_XFADE, hStereoDft->ipd_xfade_counter ), Q13), &q_val); - q_val = sub(q_val, Q2); + hStereoDft->ipd_xfade_step_fx = BASOP_Util_Divide3232_Scale( L_sub( hStereoDft->ipd_xfade_target_fx, hStereoDft->ipd_xfade_prev_fx ), L_shl( L_sub( STEREO_DFT_ITD_CNG_XFADE, hStereoDft->ipd_xfade_counter ), Q13 ), &q_val ); + q_val = sub( q_val, Q2 ); move32(); - IF (GT_16(q_val, 16)) + IF( GT_16( q_val, 16 ) ) { - assert(0); + assert( 0 ); } ELSE { - hStereoDft->ipd_xfade_step_fx = L_shl(hStereoDft->ipd_xfade_step_fx, q_val); + hStereoDft->ipd_xfade_step_fx = L_shl( hStereoDft->ipd_xfade_step_fx, q_val ); } } } /* xfade */ - IF ( NE_32(hStereoDft->ipd_xfade_prev_fx, hStereoDft->ipd_xfade_target_fx) && LT_16(hStereoDft->ipd_xfade_counter, STEREO_DFT_ITD_CNG_XFADE) && LE_32(hStereoDft->last_active_element_brate, 24400) ) + IF( NE_32( hStereoDft->ipd_xfade_prev_fx, hStereoDft->ipd_xfade_target_fx ) && LT_16( hStereoDft->ipd_xfade_counter, STEREO_DFT_ITD_CNG_XFADE ) && LE_32( hStereoDft->last_active_element_brate, 24400 ) ) { - hStereoDft->gipd_fx[add( k , k_offset )] = L_add(hStereoDft->ipd_xfade_prev_fx, hStereoDft->ipd_xfade_step_fx); + hStereoDft->gipd_fx[add( k, k_offset )] = L_add( hStereoDft->ipd_xfade_prev_fx, hStereoDft->ipd_xfade_step_fx ); move32(); - hStereoDft->ipd_xfade_prev_fx = hStereoDft->gipd_fx[add( k , k_offset )]; + hStereoDft->ipd_xfade_prev_fx = hStereoDft->gipd_fx[add( k, k_offset )]; move32(); hStereoDft->ipd_xfade_counter++; } @@ -900,53 +900,53 @@ void stereo_dft_dec_smooth_parameters_fx( ELSE { /* First active frame, "reset" everything if long enough active encoding, only triggered if STEREO_DFT_ITD_CNG_XFADE_RESET = -1 */ - IF ( GT_16(active_frame_counter, STEREO_DFT_ITD_CNG_XFADE_RESET) ) + IF( GT_16( active_frame_counter, STEREO_DFT_ITD_CNG_XFADE_RESET ) ) { - hStereoDft->ipd_xfade_target_fx = hStereoDft->gipd_fx[add( k , k_offset )]; + hStereoDft->ipd_xfade_target_fx = hStereoDft->gipd_fx[add( k, k_offset )]; move32(); - hStereoDft->ipd_xfade_prev_fx = hStereoDft->gipd_fx[add( k , k_offset )]; + hStereoDft->ipd_xfade_prev_fx = hStereoDft->gipd_fx[add( k, k_offset )]; move32(); hStereoDft->ipd_xfade_counter = 0; move16(); } } - FOR ( k2 = 1; k2 < hStereoDft->prm_res[add( k , k_offset )]; k2++ ) + FOR( k2 = 1; k2 < hStereoDft->prm_res[add( k, k_offset )]; k2++ ) { - hStereoDft->gipd_fx[( add( k , k_offset ) ) - k2] = hStereoDft->gipd_fx[add( k , k_offset )]; + hStereoDft->gipd_fx[( add( k, k_offset ) ) - k2] = hStereoDft->gipd_fx[add( k, k_offset )]; move32(); } - IF ( hStereoDft->frame_sid_nodata ) + IF( hStereoDft->frame_sid_nodata ) { /* set new xfade target if new itd received */ #ifdef NONBE_FIX_1010_STEREO_CNG_DIV_BY_ZERO - IF ( LT_16(hStereoDft->itd_xfade_counter , STEREO_DFT_ITD_CNG_XFADE) ) + IF( LT_16( hStereoDft->itd_xfade_counter, STEREO_DFT_ITD_CNG_XFADE ) ) #else - IF ( NE_32(hStereoDft->itd_fx[add( k , k_offset )], hStereoDft->itd_xfade_target_fx) ) + IF( NE_32( hStereoDft->itd_fx[add( k, k_offset )], hStereoDft->itd_xfade_target_fx ) ) #endif { Word16 q_val; - hStereoDft->itd_xfade_target_fx = hStereoDft->itd_fx[add( k , k_offset )]; + hStereoDft->itd_xfade_target_fx = hStereoDft->itd_fx[add( k, k_offset )]; move32(); - hStereoDft->itd_xfade_step_fx = BASOP_Util_Divide3232_Scale(L_sub( hStereoDft->itd_xfade_target_fx, hStereoDft->itd_xfade_prev_fx) , L_shl(sub( STEREO_DFT_ITD_CNG_XFADE, hStereoDft->itd_xfade_counter ), Q15), &q_val); - IF (GT_16(q_val, 16)) + hStereoDft->itd_xfade_step_fx = BASOP_Util_Divide3232_Scale( L_sub( hStereoDft->itd_xfade_target_fx, hStereoDft->itd_xfade_prev_fx ), L_shl( sub( STEREO_DFT_ITD_CNG_XFADE, hStereoDft->itd_xfade_counter ), Q15 ), &q_val ); + IF( GT_16( q_val, 16 ) ) { - assert(0); + assert( 0 ); } ELSE { - hStereoDft->itd_xfade_step_fx = L_shl(hStereoDft->itd_xfade_step_fx, q_val); + hStereoDft->itd_xfade_step_fx = L_shl( hStereoDft->itd_xfade_step_fx, q_val ); } move32(); } /* xfade */ - IF ( NE_32(hStereoDft->itd_xfade_prev_fx, hStereoDft->itd_xfade_target_fx) && LT_16(hStereoDft->itd_xfade_counter, STEREO_DFT_ITD_CNG_XFADE) && LE_32(hStereoDft->last_active_element_brate, 24400) ) + IF( NE_32( hStereoDft->itd_xfade_prev_fx, hStereoDft->itd_xfade_target_fx ) && LT_16( hStereoDft->itd_xfade_counter, STEREO_DFT_ITD_CNG_XFADE ) && LE_32( hStereoDft->last_active_element_brate, 24400 ) ) { - hStereoDft->itd_fx[add( k , k_offset )] = L_add(hStereoDft->itd_xfade_prev_fx , hStereoDft->itd_xfade_step_fx); + hStereoDft->itd_fx[add( k, k_offset )] = L_add( hStereoDft->itd_xfade_prev_fx, hStereoDft->itd_xfade_step_fx ); move32(); - hStereoDft->itd_xfade_prev_fx = hStereoDft->itd_fx[add( k , k_offset )]; + hStereoDft->itd_xfade_prev_fx = hStereoDft->itd_fx[add( k, k_offset )]; move32(); hStereoDft->itd_xfade_counter++; } @@ -954,11 +954,11 @@ void stereo_dft_dec_smooth_parameters_fx( ELSE { /* First active frame, "reset" everything if long enough active encoding, only triggered if STEREO_DFT_ITD_CNG_XFADE_RESET = -1 */ - IF ( GT_16(active_frame_counter, STEREO_DFT_ITD_CNG_XFADE_RESET) ) + IF( GT_16( active_frame_counter, STEREO_DFT_ITD_CNG_XFADE_RESET ) ) { - hStereoDft->itd_xfade_target_fx = hStereoDft->itd_fx[add( k , k_offset )]; + hStereoDft->itd_xfade_target_fx = hStereoDft->itd_fx[add( k, k_offset )]; move32(); - hStereoDft->itd_xfade_prev_fx = hStereoDft->itd_fx[add( k , k_offset )]; + hStereoDft->itd_xfade_prev_fx = hStereoDft->itd_fx[add( k, k_offset )]; move32(); hStereoDft->itd_xfade_counter = 0; move32(); @@ -967,9 +967,9 @@ void stereo_dft_dec_smooth_parameters_fx( hStereoDft->last_active_element_brate = element_brate; move32(); } - FOR ( k2 = 1; k2 < hStereoDft->prm_res[add( k , k_offset )]; k2++ ) + FOR( k2 = 1; k2 < hStereoDft->prm_res[add( k, k_offset )]; k2++ ) { - hStereoDft->itd_fx[( add( k , k_offset ) ) - k2] = hStereoDft->itd_fx[add( k , k_offset )]; + hStereoDft->itd_fx[( add( k, k_offset ) ) - k2] = hStereoDft->itd_fx[add( k, k_offset )]; move32(); } @@ -977,7 +977,7 @@ void stereo_dft_dec_smooth_parameters_fx( } /* Active frame, "reset" everything "reset" everything if long enough active encoding */ - IF ( GT_16(active_frame_counter, STEREO_DFT_ITD_CNG_XFADE_RESET )) + IF( GT_16( active_frame_counter, STEREO_DFT_ITD_CNG_XFADE_RESET ) ) { hStereoDft->itd_xfade_counter = 0; move16(); @@ -996,18 +996,18 @@ void stereo_dft_dec_smooth_parameters_fx( hStereoDft->last_active_element_brate = element_brate; move32(); - FOR ( k = hStereoDft->prm_res[k_offset] - 1; k < N_div; k += hStereoDft->prm_res[add( k , k_offset )] ) + FOR( k = hStereoDft->prm_res[k_offset] - 1; k < N_div; k += hStereoDft->prm_res[add( k, k_offset )] ) { max_res_pred_ind = 0; move32(); - IF ( EQ_16(hStereoDft->reverb_flag, 1) ) + IF( EQ_16( hStereoDft->reverb_flag, 1 ) ) { nbands = min( 10, hStereoDft->nbands_respred ); move16(); /*Shift 2 last bands residual prediction gains for SWB/FB*/ - IF ( EQ_16(hStereoDft->band_res[k_offset], STEREO_DFT_BAND_RES_HIGH) ) + IF( EQ_16( hStereoDft->band_res[k_offset], STEREO_DFT_BAND_RES_HIGH ) ) { - FOR ( b = hStereoDft->nbands_respred - 1; b >= nbands; b-- ) + FOR( b = hStereoDft->nbands_respred - 1; b >= nbands; b-- ) { hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX] = hStereoDft->res_gains_ind_fx[1][b - STEREO_DFT_RES_PRED_BAND_MIN_RED + hStereoDft->res_pred_band_min + STEREO_DFT_BAND_MAX]; @@ -1018,9 +1018,9 @@ void stereo_dft_dec_smooth_parameters_fx( } /* Get maximal index */ - FOR ( b = hStereoDft->res_pred_band_min; b < ( nbands - STEREO_DFT_RES_PRED_BAND_MIN_CONST ); b++ ) + FOR( b = hStereoDft->res_pred_band_min; b < ( nbands - STEREO_DFT_RES_PRED_BAND_MIN_CONST ); b++ ) { - IF ( LT_32(max_res_pred_ind, hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX]) ) + IF( LT_32( max_res_pred_ind, hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX] ) ) { max_res_pred_ind = hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX]; move32(); @@ -1028,7 +1028,7 @@ void stereo_dft_dec_smooth_parameters_fx( } /* predictive values */ - FOR ( ; b < nbands; b++ ) + FOR( ; b < nbands; b++ ) { assert( hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX] == 0 ); hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX] = max_res_pred_ind; @@ -1036,7 +1036,7 @@ void stereo_dft_dec_smooth_parameters_fx( } } - FOR ( b = hStereoDft->res_pred_band_min; b < hStereoDft->res_cod_band_max; b++ ) + FOR( b = hStereoDft->res_pred_band_min; b < hStereoDft->res_cod_band_max; b++ ) { Word32 tmp; Word16 tmps1, tmps2; @@ -1048,161 +1048,161 @@ void stereo_dft_dec_smooth_parameters_fx( move16(); tmps2 = (Word16) L_shr( hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX], Q26 ); move16(); - stereo_dft_dequantize_res_gains_fx( &tmps1, &tmps2, hStereoDft->side_gain_fx + ( add( k , k_offset ) ) * STEREO_DFT_BAND_MAX + b, hStereoDft->res_pred_gain_fx + ( add( k , k_offset ) ) * STEREO_DFT_BAND_MAX + b, 1 ); + stereo_dft_dequantize_res_gains_fx( &tmps1, &tmps2, hStereoDft->side_gain_fx + ( add( k, k_offset ) ) * STEREO_DFT_BAND_MAX + b, hStereoDft->res_pred_gain_fx + ( add( k, k_offset ) ) * STEREO_DFT_BAND_MAX + b, 1 ); - IF ( hStereoDft->attackPresent ) + IF( hStereoDft->attackPresent ) { - hStereoDft->res_gains_ind_fx[1][b] = Mpy_32_16_1(hStereoDft->res_gains_ind_fx[1][b], (Word16)0x6666); + hStereoDft->res_gains_ind_fx[1][b] = Mpy_32_16_1( hStereoDft->res_gains_ind_fx[1][b], (Word16) 0x6666 ); move32(); } - ELSE IF ( hStereoDft->trans || ( hStereoDft->res_pred_mode[k] && ( hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX] < ONE_IN_Q27 ) ) ) /* Assuming Maximum Q of res_gains_ind_fx is Q26 */ + ELSE IF( hStereoDft->trans || ( hStereoDft->res_pred_mode[k] && ( hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX] < ONE_IN_Q27 ) ) ) /* Assuming Maximum Q of res_gains_ind_fx is Q26 */ { - hStereoDft->res_gains_ind_fx[1][b] = Madd_32_16(Mpy_32_16_1(hStereoDft->res_gains_ind_fx[1][b], (Word16)0x4CCD), - hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX], (Word16)0x3333); + hStereoDft->res_gains_ind_fx[1][b] = Madd_32_16( Mpy_32_16_1( hStereoDft->res_gains_ind_fx[1][b], (Word16) 0x4CCD ), + hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX], (Word16) 0x3333 ); move32(); } ELSE { - hStereoDft->res_gains_ind_fx[1][b] = Madd_32_16( Mpy_32_16_1(hStereoDft->res_gains_ind_fx[1][b], dft_alpha_s2_fx[b]), + hStereoDft->res_gains_ind_fx[1][b] = Madd_32_16( Mpy_32_16_1( hStereoDft->res_gains_ind_fx[1][b], dft_alpha_s2_fx[b] ), hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX], - sub( (Word16)0x7FFF, dft_alpha_s2_fx[b] )); + sub( (Word16) 0x7FFF, dft_alpha_s2_fx[b] ) ); move32(); } - stereo_dft_dequantize_res_gains_f_fx( &hStereoDft->res_gains_ind_fx[0][b], &hStereoDft->res_gains_ind_fx[1][b], &tmp, hStereoDft->res_pred_gain_fx + ( add( k , k_offset ) ) * STEREO_DFT_BAND_MAX + b, 1 ); + stereo_dft_dequantize_res_gains_f_fx( &hStereoDft->res_gains_ind_fx[0][b], &hStereoDft->res_gains_ind_fx[1][b], &tmp, hStereoDft->res_pred_gain_fx + ( add( k, k_offset ) ) * STEREO_DFT_BAND_MAX + b, 1 ); } /* Smoothing of prediction gains between ftrames */ - FOR ( ; b < hStereoDft->nbands; b++ ) + FOR( ; b < hStereoDft->nbands; b++ ) { - IF ( hStereoDft->attackPresent ) + IF( hStereoDft->attackPresent ) { hStereoDft->res_gains_ind_fx[0][b] = hStereoDft->res_gains_ind_fx[0][b + STEREO_DFT_BAND_MAX]; move32(); - hStereoDft->res_gains_ind_fx[1][b] = Mpy_32_16_1(hStereoDft->res_gains_ind_fx[1][b], (Word16)0x6666); + hStereoDft->res_gains_ind_fx[1][b] = Mpy_32_16_1( hStereoDft->res_gains_ind_fx[1][b], (Word16) 0x6666 ); move32(); } - ELSE IF ( hStereoDft->trans || ( hStereoDft->res_pred_mode[k] && LT_32( hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX], ONE_IN_Q27 ) ) ) + ELSE IF( hStereoDft->trans || ( hStereoDft->res_pred_mode[k] && LT_32( hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX], ONE_IN_Q27 ) ) ) { hStereoDft->res_gains_ind_fx[0][b] = hStereoDft->res_gains_ind_fx[0][b + STEREO_DFT_BAND_MAX]; move32(); - IF ( EQ_16(hStereoDft->hConfig->band_res, STEREO_DFT_BAND_RES_LOW) ) + IF( EQ_16( hStereoDft->hConfig->band_res, STEREO_DFT_BAND_RES_LOW ) ) { - hStereoDft->res_gains_ind_fx[1][b] = Madd_32_16(Mpy_32_16_1(hStereoDft->res_gains_ind_fx[1][b], dft_alpha_w_b2_fx[b]), - hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX], sub((Word16)0x7FFF, dft_alpha_w_b2_fx[b])); + hStereoDft->res_gains_ind_fx[1][b] = Madd_32_16( Mpy_32_16_1( hStereoDft->res_gains_ind_fx[1][b], dft_alpha_w_b2_fx[b] ), + hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX], sub( (Word16) 0x7FFF, dft_alpha_w_b2_fx[b] ) ); move32(); } ELSE { - hStereoDft->res_gains_ind_fx[1][b] = Madd_32_16(Mpy_32_16_1(hStereoDft->res_gains_ind_fx[1][b], dft_alpha_w_fx[b]), - hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX], sub((Word16)0x7FFF, dft_alpha_w_fx[b] )); + hStereoDft->res_gains_ind_fx[1][b] = Madd_32_16( Mpy_32_16_1( hStereoDft->res_gains_ind_fx[1][b], dft_alpha_w_fx[b] ), + hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX], sub( (Word16) 0x7FFF, dft_alpha_w_fx[b] ) ); move32(); } } ELSE { - IF ( EQ_16(hStereoDft->hConfig->band_res, STEREO_DFT_BAND_RES_LOW) ) + IF( EQ_16( hStereoDft->hConfig->band_res, STEREO_DFT_BAND_RES_LOW ) ) { - hStereoDft->res_gains_ind_fx[0][b] = Madd_32_16(Mpy_32_16_1(hStereoDft->res_gains_ind_fx[0][b], dft_alpha_s_b2_fx[b]), - hStereoDft->res_gains_ind_fx[0][b + STEREO_DFT_BAND_MAX], - sub( (Word16)0x7FFF, dft_alpha_s_b2_fx[b] ) ); + hStereoDft->res_gains_ind_fx[0][b] = Madd_32_16( Mpy_32_16_1( hStereoDft->res_gains_ind_fx[0][b], dft_alpha_s_b2_fx[b] ), + hStereoDft->res_gains_ind_fx[0][b + STEREO_DFT_BAND_MAX], + sub( (Word16) 0x7FFF, dft_alpha_s_b2_fx[b] ) ); move32(); - hStereoDft->res_gains_ind_fx[1][b] = Madd_32_16(Mpy_32_16_1(hStereoDft->res_gains_ind_fx[1][b], dft_alpha_s2_b2_fx[b]), - hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX], - sub( (Word16)0x7FFF, dft_alpha_s2_b2_fx[b] ) ); + hStereoDft->res_gains_ind_fx[1][b] = Madd_32_16( Mpy_32_16_1( hStereoDft->res_gains_ind_fx[1][b], dft_alpha_s2_b2_fx[b] ), + hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX], + sub( (Word16) 0x7FFF, dft_alpha_s2_b2_fx[b] ) ); move32(); } ELSE { - hStereoDft->res_gains_ind_fx[0][b] = Madd_32_16(Mpy_32_16_1(hStereoDft->res_gains_ind_fx[0][b], dft_alpha_s_fx[b]), - hStereoDft->res_gains_ind_fx[0][b + STEREO_DFT_BAND_MAX], - sub((Word16)(0x7FFF), dft_alpha_s_fx[b] )); + hStereoDft->res_gains_ind_fx[0][b] = Madd_32_16( Mpy_32_16_1( hStereoDft->res_gains_ind_fx[0][b], dft_alpha_s_fx[b] ), + hStereoDft->res_gains_ind_fx[0][b + STEREO_DFT_BAND_MAX], + sub( (Word16) ( 0x7FFF ), dft_alpha_s_fx[b] ) ); move32(); - hStereoDft->res_gains_ind_fx[1][b] = Madd_32_16(Mpy_32_16_1(hStereoDft->res_gains_ind_fx[1][b], dft_alpha_s2_fx[b]), - hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX], - sub((Word16)(0x7FFF), dft_alpha_s2_fx[b] ) ); + hStereoDft->res_gains_ind_fx[1][b] = Madd_32_16( Mpy_32_16_1( hStereoDft->res_gains_ind_fx[1][b], dft_alpha_s2_fx[b] ), + hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX], + sub( (Word16) ( 0x7FFF ), dft_alpha_s2_fx[b] ) ); move32(); } } - IF ( !hStereoDft->recovery_flg ) + IF( !hStereoDft->recovery_flg ) { - stereo_dft_dequantize_res_gains_f_fx( &hStereoDft->res_gains_ind_fx[0][b], &hStereoDft->res_gains_ind_fx[1][b], hStereoDft->side_gain_fx + ( add( k , k_offset ) ) * STEREO_DFT_BAND_MAX + b, hStereoDft->res_pred_gain_fx + ( add( k , k_offset ) ) * STEREO_DFT_BAND_MAX + b, 1 ); + stereo_dft_dequantize_res_gains_f_fx( &hStereoDft->res_gains_ind_fx[0][b], &hStereoDft->res_gains_ind_fx[1][b], hStereoDft->side_gain_fx + ( add( k, k_offset ) ) * STEREO_DFT_BAND_MAX + b, hStereoDft->res_pred_gain_fx + ( add( k, k_offset ) ) * STEREO_DFT_BAND_MAX + b, 1 ); } } /* Smoothing of IPDs*/ - pgIpd = hStereoDft->gipd_fx + ( add( k , k_offset ) ); - diff_ipd = L_sub(pgIpd[0] , pgIpd[-hStereoDft->prm_res[add( k , k_offset )]]); - IF ( LT_32(diff_ipd, -EVS_PI_FX) ) + pgIpd = hStereoDft->gipd_fx + ( add( k, k_offset ) ); + diff_ipd = L_sub( pgIpd[0], pgIpd[-hStereoDft->prm_res[add( k, k_offset )]] ); + IF( LT_32( diff_ipd, -EVS_PI_FX ) ) { - pgIpd[0] = L_add(L_add(pgIpd[0], EVS_PI_FX), EVS_PI_FX); + pgIpd[0] = L_add( L_add( pgIpd[0], EVS_PI_FX ), EVS_PI_FX ); } - ELSE IF ( GT_32(diff_ipd, EVS_PI_FX) ) + ELSE IF( GT_32( diff_ipd, EVS_PI_FX ) ) { - pgIpd[0] = L_sub(L_sub(pgIpd[0], EVS_PI_FX), EVS_PI_FX); + pgIpd[0] = L_sub( L_sub( pgIpd[0], EVS_PI_FX ), EVS_PI_FX ); } - IF ( !hStereoDft->attackPresent ) + IF( !hStereoDft->attackPresent ) { - IF ( hStereoDft->wasTransient ) + IF( hStereoDft->wasTransient ) { - pgIpd[0] = L_add(Mpy_32_16_1(pgIpd[0], (Word16)0x6666), Mpy_32_16_1(pgIpd[-hStereoDft->prm_res[add( k , k_offset )]], (Word16)(0x199A))); + pgIpd[0] = L_add( Mpy_32_16_1( pgIpd[0], (Word16) 0x6666 ), Mpy_32_16_1( pgIpd[-hStereoDft->prm_res[add( k, k_offset )]], (Word16) ( 0x199A ) ) ); move16(); } ELSE { - pgIpd[0] = L_add(L_shr(pgIpd[0], 1), L_shr(pgIpd[-hStereoDft->prm_res[add( k , k_offset )]], 1)); + pgIpd[0] = L_add( L_shr( pgIpd[0], 1 ), L_shr( pgIpd[-hStereoDft->prm_res[add( k, k_offset )]], 1 ) ); move16(); } } - IF ( !hStereoDft->attackPresent ) + IF( !hStereoDft->attackPresent ) { - pSideGain = hStereoDft->side_gain_fx + ( add( k , k_offset ) ) * STEREO_DFT_BAND_MAX; - FOR ( b = 0; b < hStereoDft->res_cod_band_max; b++ ) + pSideGain = hStereoDft->side_gain_fx + ( add( k, k_offset ) ) * STEREO_DFT_BAND_MAX; + FOR( b = 0; b < hStereoDft->res_cod_band_max; b++ ) { - pSideGain[b] = Madd_32_16(Mpy_32_16_1(pSideGain[b], dft_res_cod_alpha_fx[b]), - pSideGain[b - hStereoDft->prm_res[add( k , k_offset )] * STEREO_DFT_BAND_MAX], - sub( (Word16)0x7FFF, dft_res_cod_alpha_fx[b] ) ); + pSideGain[b] = Madd_32_16( Mpy_32_16_1( pSideGain[b], dft_res_cod_alpha_fx[b] ), + pSideGain[b - hStereoDft->prm_res[add( k, k_offset )] * STEREO_DFT_BAND_MAX], + sub( (Word16) 0x7FFF, dft_res_cod_alpha_fx[b] ) ); move32(); } } /*Interpolation between DFT slots*/ - FOR ( k2 = 1; k2 < hStereoDft->prm_res[add( k , k_offset )]; k2++ ) + FOR( k2 = 1; k2 < hStereoDft->prm_res[add( k, k_offset )]; k2++ ) { - pInterpol = hStereoDft->gipd_fx + sub( add( k , k_offset ) , k2 ); - pIpd = hStereoDft->gipd_fx + add( k , k_offset ); - IF ( hStereoDft->attackPresent ) + pInterpol = hStereoDft->gipd_fx + sub( add( k, k_offset ), k2 ); + pIpd = hStereoDft->gipd_fx + add( k, k_offset ); + IF( hStereoDft->attackPresent ) { *( pInterpol ) = *( pIpd ); move32(); } ELSE { - *( pInterpol ) = *( hStereoDft->gipd_fx + ( add( k , k_offset ) - hStereoDft->prm_res[add( k , k_offset )] ) ); + *( pInterpol ) = *( hStereoDft->gipd_fx + ( add( k, k_offset ) - hStereoDft->prm_res[add( k, k_offset )] ) ); move32(); } - FOR ( b = 0; b < hStereoDft->nbands; b++ ) + FOR( b = 0; b < hStereoDft->nbands; b++ ) { - *( hStereoDft->res_pred_gain_fx + sub( add( k , k_offset ) , k2 ) * STEREO_DFT_BAND_MAX + b ) = *( hStereoDft->res_pred_gain_fx + ( add( k , k_offset ) - hStereoDft->prm_res[add( k , k_offset )] ) * STEREO_DFT_BAND_MAX + b ); + *( hStereoDft->res_pred_gain_fx + sub( add( k, k_offset ), k2 ) * STEREO_DFT_BAND_MAX + b ) = *( hStereoDft->res_pred_gain_fx + ( add( k, k_offset ) - hStereoDft->prm_res[add( k, k_offset )] ) * STEREO_DFT_BAND_MAX + b ); move32(); - IF ( b < hStereoDft->res_cod_band_max || hStereoDft->attackPresent || hStereoDft->trans || ( hStereoDft->res_pred_mode[k] && LT_32( hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX], ONE_IN_Q27 ) ) ) + IF( b < hStereoDft->res_cod_band_max || hStereoDft->attackPresent || hStereoDft->trans || ( hStereoDft->res_pred_mode[k] && LT_32( hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX], ONE_IN_Q27 ) ) ) { - *( hStereoDft->side_gain_fx + sub( add( k , k_offset ) , k2 ) * STEREO_DFT_BAND_MAX + b ) = *( hStereoDft->side_gain_fx + ( add( k , k_offset ) ) * STEREO_DFT_BAND_MAX + b ); + *( hStereoDft->side_gain_fx + sub( add( k, k_offset ), k2 ) * STEREO_DFT_BAND_MAX + b ) = *( hStereoDft->side_gain_fx + ( add( k, k_offset ) ) * STEREO_DFT_BAND_MAX + b ); move32(); } ELSE { - *( hStereoDft->side_gain_fx + sub( add( k , k_offset ) , k2 ) * STEREO_DFT_BAND_MAX + b ) = *( hStereoDft->side_gain_fx + ( add( k , k_offset ) - hStereoDft->prm_res[add( k , k_offset )] ) * STEREO_DFT_BAND_MAX + b ); + *( hStereoDft->side_gain_fx + sub( add( k, k_offset ), k2 ) * STEREO_DFT_BAND_MAX + b ) = *( hStereoDft->side_gain_fx + ( add( k, k_offset ) - hStereoDft->prm_res[add( k, k_offset )] ) * STEREO_DFT_BAND_MAX + b ); move32(); } } - hStereoDft->itd_fx[( add( k , k_offset ) ) - k2] = hStereoDft->itd_fx[add( k , k_offset )]; + hStereoDft->itd_fx[( add( k, k_offset ) ) - k2] = hStereoDft->itd_fx[add( k, k_offset )]; move32(); } /*end of interpolation*/ } @@ -1217,9 +1217,9 @@ void stereo_dft_dec_smooth_parameters_fx( *-------------------------------------------------------------------------*/ void stereo_dft_dec_res_fx( - CPE_DEC_HANDLE hCPE, /* i/o: decoder CPE handle */ + CPE_DEC_HANDLE hCPE, /* i/o: decoder CPE handle */ Word32 res_buf[STEREO_DFT_N_8k], /* i : residual buffer */ - Word16 q_res, /* i : q fact of residural buffer */ + Word16 q_res, /* i : q fact of residural buffer */ Word32 *output /* o : output */ ) { @@ -1237,7 +1237,7 @@ void stereo_dft_dec_res_fx( move16(); /* flush memories when switching residual coding on */ - IF ( EQ_16(hCPE->hStereoDft->res_cod_mode[STEREO_DFT_OFFSET - 1], STEREO_DFT_RES_COD_OFF) ) + IF( EQ_16( hCPE->hStereoDft->res_cod_mode[STEREO_DFT_OFFSET - 1], STEREO_DFT_RES_COD_OFF ) ) { set_val_Word32( hCPE->hStereoDft->res_cod_mem_fx, 0, STEREO_DFT_OVL_8k ); hCPE->hStereoDft->q_res_cod_mem_fx = Q16; @@ -1250,7 +1250,7 @@ void stereo_dft_dec_res_fx( /*Inverse MDCT*/ TCX_MDCT_Inverse( res_buf, q_res, win, STEREO_DFT_OVL_8k, L_FRAME8k - STEREO_DFT_OVL_8k, STEREO_DFT_OVL_8k, IVAS_CPE_DFT ); - IF ( !prev_bfi ) + IF( !prev_bfi ) { /*OLA*/ /*overlapping parts*/ @@ -1274,65 +1274,65 @@ void stereo_dft_dec_res_fx( { Word16 q_div; /* For first good frame, ola memory contains extended ECU buffer -- need to crossfade instead of OLA */ - step = BASOP_Util_Divide3232_Scale( 1, STEREO_DFT_OVL_8k, &q_div); - IF (NE_16(q_div, 0)) + step = BASOP_Util_Divide3232_Scale( 1, STEREO_DFT_OVL_8k, &q_div ); + IF( NE_16( q_div, 0 ) ) { - step = shl(step, q_div); + step = shl( step, q_div ); } fac = 0; move16(); - FOR ( i = 0; i < STEREO_DFT_OVL_8k; i++ ) + FOR( i = 0; i < STEREO_DFT_OVL_8k; i++ ) { - win[i] = extract_h(Madd_32_16(Mpy_32_16_1(hCPE->hStereoDft->res_cod_mem_fx[i], sub(MAX_16, mult(fac, fac))), - L_mult(hCPE->hStereoDft->win_8k_fx[i], win[i]), - sub(MAX_16, mult(sub(MAX_16, fac), sub(MAX_16 , fac))))); + win[i] = extract_h( Madd_32_16( Mpy_32_16_1( hCPE->hStereoDft->res_cod_mem_fx[i], sub( MAX_16, mult( fac, fac ) ) ), + L_mult( hCPE->hStereoDft->win_8k_fx[i], win[i] ), + sub( MAX_16, mult( sub( MAX_16, fac ), sub( MAX_16, fac ) ) ) ) ); move16(); - hCPE->hStereoDft->res_cod_mem_fx[i] = L_mult(win[L_FRAME8k + i], hCPE->hStereoDft->win_8k_fx[STEREO_DFT_OVL_8k - 1 - i]); + hCPE->hStereoDft->res_cod_mem_fx[i] = L_mult( win[L_FRAME8k + i], hCPE->hStereoDft->win_8k_fx[STEREO_DFT_OVL_8k - 1 - i] ); move32(); - fac = add(fac, step); + fac = add( fac, step ); } } Copy( win, out_16, L_FRAME8k ); - IF ( EQ_16(hCPE->hCoreCoder[0]->core , ACELP_CORE) ) + IF( EQ_16( hCPE->hCoreCoder[0]->core, ACELP_CORE ) ) { /* bass post-filter */ bass_psfilter_fx( hCPE->hStereoDft->hBpf, hCPE->hCoreCoder[0]->Opt_AMR_WB, out_16, L_FRAME8k, hCPE->hCoreCoder[0]->old_pitch_buf_16_fx + ( L_FRAME8k / STEREO_DFT_L_SUBFR_8k ), hCPE->hCoreCoder[0]->bpf_off, - hCPE->hCoreCoder[0]->stab_fac_fx, &hCPE->hStereoDft->stab_fac_smooth_res_fx, hCPE->hCoreCoder[0]->last_coder_type, 0, bpf_error_signal_8k_16 ); - Copy_Scale_sig_16_32(bpf_error_signal_8k_16, bpf_error_signal_8k, L_FRAME8k, Q15); + hCPE->hCoreCoder[0]->stab_fac_fx, &hCPE->hStereoDft->stab_fac_smooth_res_fx, hCPE->hCoreCoder[0]->last_coder_type, 0, bpf_error_signal_8k_16 ); + Copy_Scale_sig_16_32( bpf_error_signal_8k_16, bpf_error_signal_8k, L_FRAME8k, Q15 ); res_bpf_flag = res_bpf_adapt_ivas_fx( hCPE->hStereoDft, bpf_error_signal_8k, res_buf ); - IF ( prev_bfi ) + IF( prev_bfi ) { /* Ramp up BPF contribution for the first good frame */ - step = (Word16)(0x00CD) ; // ( 1.0f / L_FRAME8k ); + step = (Word16) ( 0x00CD ); // ( 1.0f / L_FRAME8k ); move16(); - fac = negate(step); - FOR ( i = 0; i < L_FRAME8k; i++ ) + fac = negate( step ); + FOR( i = 0; i < L_FRAME8k; i++ ) { - fac = add(fac, step); - bpf_error_signal_8k[i] = Mpy_32_16_1(bpf_error_signal_8k[i], fac); + fac = add( fac, step ); + bpf_error_signal_8k[i] = Mpy_32_16_1( bpf_error_signal_8k[i], fac ); move32(); } } - Copy_Scale_sig_16_32(out_16, output, L_FRAME8k, 16); - IF ( res_bpf_flag ) + Copy_Scale_sig_16_32( out_16, output, L_FRAME8k, 16 ); + IF( res_bpf_flag ) { v_sub_32( output, bpf_error_signal_8k, output, L_FRAME8k ); } } - ELSE IF ( EQ_16(hCPE->hCoreCoder[0]->last_core, ACELP_CORE) ) + ELSE IF( EQ_16( hCPE->hCoreCoder[0]->last_core, ACELP_CORE ) ) { set_val_Word16( hCPE->hStereoDft->hBpf->pst_old_syn_fx, 0, STEREO_DFT_NBPSF_PIT_MAX_8k ); hCPE->hStereoDft->hBpf->pst_mem_deemp_err_fx = 0; move16(); - Copy_Scale_sig_16_32(out_16, output, L_FRAME8k, 16); + Copy_Scale_sig_16_32( out_16, output, L_FRAME8k, 16 ); } ELSE { /* This step is needed to ensure output is properly populated with scaled values in all cases*/ - Copy_Scale_sig_16_32(out_16, output, L_FRAME8k, 16); + Copy_Scale_sig_16_32( out_16, output, L_FRAME8k, 16 ); } return; @@ -1346,18 +1346,18 @@ void stereo_dft_dec_res_fx( *-------------------------------------------------------------------------*/ void stereo_dft_dec_fx( - STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ - Decoder_State *st0, /* i/o: decoder state structure */ + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ + Decoder_State *st0, /* i/o: decoder state structure */ Word32 DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i/o: DFT buffers */ Word32 *input_mem, /* i/o: mem of buffer DFT analysis */ - STEREO_CNG_DEC_HANDLE hStereoCng, /* i/o: Stereo CNG data structure */ - const Word16 sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC */ - const Word16 sba_mono_flag, /* i : signal mono output for SBA DirAC */ - ivas_spar_md_dec_state_t *hMdDec, /* i : SPAR MD handle for upmixing */ - const Word16 cross_fade_start_offset, /* i : SPAR mixer delay compensation */ - const Word32 output_Fs, /* i : Fs for delay calculation */ - const Word16 nchan_transport, /* i : number of transpor channels */ - const Word16 num_md_sub_frames /* i : number of MD subframes */ + STEREO_CNG_DEC_HANDLE hStereoCng, /* i/o: Stereo CNG data structure */ + const Word16 sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC */ + const Word16 sba_mono_flag, /* i : signal mono output for SBA DirAC */ + ivas_spar_md_dec_state_t *hMdDec, /* i : SPAR MD handle for upmixing */ + const Word16 cross_fade_start_offset, /* i : SPAR mixer delay compensation */ + const Word32 output_Fs, /* i : Fs for delay calculation */ + const Word16 nchan_transport, /* i : number of transpor channels */ + const Word16 num_md_sub_frames /* i : number of MD subframes */ ) { Word16 i, k, b, N_div, stop; @@ -1391,25 +1391,25 @@ void stereo_dft_dec_fx( Word16 q_cna_level; HANDLE_FD_CNG_DEC hFdCngDec = st0->hFdCngDec; HANDLE_FD_CNG_COM hFdCngCom = hFdCngDec->hFdCngCom; - Word16 *cna_seed = &( hFdCngCom->seed); + Word16 *cna_seed = &( hFdCngCom->seed ); Word32 DFT_W, DFT_Y; Word16 q_samp_ratio = Q15; - output_frame = (Word16) Mpy_32_32( L_add(st0->output_Fs , FRAMES_PER_SEC_BY_2), ONE_BY_FRAMES_PER_SEC); + output_frame = (Word16) Mpy_32_32( L_add( st0->output_Fs, FRAMES_PER_SEC_BY_2 ), ONE_BY_FRAMES_PER_SEC ); /*------------------------------------------------------------------* * Initialization *-----------------------------------------------------------------*/ - samp_ratio = (Word16)BASOP_Util_Divide3232_Scale(st0->sr_core, st0->output_Fs, &q_samp_ratio); - samp_ratio = shr(samp_ratio , sub(Q15 - Q12, q_samp_ratio)); + samp_ratio = (Word16) BASOP_Util_Divide3232_Scale( st0->sr_core, st0->output_Fs, &q_samp_ratio ); + samp_ratio = shr( samp_ratio, sub( Q15 - Q12, q_samp_ratio ) ); - stop = shr(STEREO_DFT32MS_N_32k , 1); + stop = shr( STEREO_DFT32MS_N_32k, 1 ); /* Analyze nature of current frame */ - hStereoDft->trans = (Word16)( ( EQ_16( st0->clas_dec, ONSET ) || EQ_16( st0->clas_dec, SIN_ONSET ) || EQ_16( st0->clas_dec, UNVOICED_CLAS ) || EQ_16( st0->clas_dec, UNVOICED_TRANSITION ) ) || LE_16( st0->stab_fac_fx, (Word16)0x2000 ) ) || - ( (EQ_16(st0->core, TCX_20_CORE) && ( EQ_16( st0->hTcxCfg->tcx_last_overlap_mode, MIN_OVERLAP ) || EQ_16( st0->hTcxCfg->tcx_last_overlap_mode, HALF_OVERLAP ) ) ) || EQ_16( st0->core, TCX_10_CORE )); + hStereoDft->trans = (Word16) ( ( EQ_16( st0->clas_dec, ONSET ) || EQ_16( st0->clas_dec, SIN_ONSET ) || EQ_16( st0->clas_dec, UNVOICED_CLAS ) || EQ_16( st0->clas_dec, UNVOICED_TRANSITION ) ) || LE_16( st0->stab_fac_fx, (Word16) 0x2000 ) ) || + ( ( EQ_16( st0->core, TCX_20_CORE ) && ( EQ_16( st0->hTcxCfg->tcx_last_overlap_mode, MIN_OVERLAP ) || EQ_16( st0->hTcxCfg->tcx_last_overlap_mode, HALF_OVERLAP ) ) ) || EQ_16( st0->core, TCX_10_CORE ) ); move16(); /* Initialization */ @@ -1421,15 +1421,15 @@ void stereo_dft_dec_fx( The prev_old_bfi still holds the prev_bfi for the current frame. */ /* make sure number of bands corresponds to output bwidth in case it is lower than parameter bwidth */ move16(); - IF ( LT_16(output_frame, inner_frame_tbl[st0->bwidth]) && EQ_16(sba_dirac_stereo_flag, 0) ) + IF( LT_16( output_frame, inner_frame_tbl[st0->bwidth] ) && EQ_16( sba_dirac_stereo_flag, 0 ) ) { hStereoDft->nbands = stereo_dft_band_config_fx( hStereoDft->band_limits, hStereoDft->band_res[k_offset], hStereoDft->NFFT, DEC ); } - IF ( EQ_16(st0->bfi, 0) ) + IF( EQ_16( st0->bfi, 0 ) ) { /* Smoothing for the current frame */ - IF ( sba_dirac_stereo_flag ) + IF( sba_dirac_stereo_flag ) { ivas_sba_dirac_stereo_smooth_parameters_fx( hStereoDft, hMdDec, cross_fade_start_offset, output_Fs, num_md_sub_frames ); } @@ -1441,7 +1441,7 @@ void stereo_dft_dec_fx( dmx_nrg = 0; move32(); - IF ( prev_bfi ) + IF( prev_bfi ) { dmx_nrg = stereo_dft_dmx_swb_nrg_fx( DFT[0], DFT[0] + STEREO_DFT32MS_N_MAX, min( hStereoDft->NFFT, STEREO_DFT32MS_N_32k ), 0, 0 ); } @@ -1450,18 +1450,18 @@ void stereo_dft_dec_fx( #ifdef DEBUG_PRINT printf( "\nframe: %d\n", frame ); #endif - FOR ( k = 0; k < N_div; k++ ) + FOR( k = 0; k < N_div; k++ ) { - pDFT_DMX = DFT[0] + i_mult(k , STEREO_DFT32MS_N_MAX); - pDFT_RES = DFT[1] + i_mult(k , STEREO_DFT32MS_N_MAX); + pDFT_DMX = DFT[0] + i_mult( k, STEREO_DFT32MS_N_MAX ); + pDFT_RES = DFT[1] + i_mult( k, STEREO_DFT32MS_N_MAX ); pDFT_DMX1 = 0; - IF ( GT_16(nchan_transport, 1) ) + IF( GT_16( nchan_transport, 1 ) ) { - pDFT_DMX1 = DFT[1] + i_mult(k , STEREO_DFT32MS_N_MAX); + pDFT_DMX1 = DFT[1] + i_mult( k, STEREO_DFT32MS_N_MAX ); } /*Apply Stereo*/ - IF ( hStereoDft->hConfig->dmx_active ) + IF( hStereoDft->hConfig->dmx_active ) { g = MAX_16; move16(); @@ -1471,9 +1471,9 @@ void stereo_dft_dec_fx( move16(); /* since delay is just 3.125ms, the parameters received are used for the second window */ - pSideGain = hStereoDft->side_gain_fx + i_mult(add( k , k_offset ) , STEREO_DFT_BAND_MAX); - pgIpd = hStereoDft->gipd_fx + add( k , k_offset ); - pPredGain = hStereoDft->res_pred_gain_fx + i_mult(add( k , k_offset ) , STEREO_DFT_BAND_MAX); + pSideGain = hStereoDft->side_gain_fx + i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ); + pgIpd = hStereoDft->gipd_fx + add( k, k_offset ); + pPredGain = hStereoDft->res_pred_gain_fx + i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ); #ifdef DEBUG_PRINT if ( k == 0 ) @@ -1493,28 +1493,28 @@ void stereo_dft_dec_fx( #endif /* Use coarse band partition in inactive frames */ - IF ( hStereoDft->frame_sid_nodata && !sba_dirac_stereo_flag ) + IF( hStereoDft->frame_sid_nodata && !sba_dirac_stereo_flag ) { - NFFT_inner = i_mult((STEREO_DFT32MS_N_MAX / L_FRAME48k), inner_frame_tbl[st0->bwidth]); + NFFT_inner = i_mult( ( STEREO_DFT32MS_N_MAX / L_FRAME48k ), inner_frame_tbl[st0->bwidth] ); hStereoDft->nbands = stereo_dft_band_config_fx( hStereoDft->band_limits, 2, NFFT_inner, DEC ); } - IF ( st0->bfi ) + IF( st0->bfi ) { hStereoDft->past_DMX_pos = ( hStereoDft->past_DMX_pos + STEREO_DFT_PAST_MAX - 1 ) % STEREO_DFT_PAST_MAX; } - IF ( !( sba_dirac_stereo_flag && GE_16(nchan_transport, 2) ) ) + IF( !( sba_dirac_stereo_flag && GE_16( nchan_transport, 2 ) ) ) { stereo_dft_generate_res_pred_fx( hStereoDft, samp_ratio, pDFT_DMX, DFT_PRED_RES, pPredGain, k, DFT[1] + k * STEREO_DFT32MS_N_MAX, &stop, st0->bfi ); } - IF ( GT_16(hStereoDft->res_cod_band_max, 0) ) + IF( GT_16( hStereoDft->res_cod_band_max, 0 ) ) { - IF ( !st0->bfi ) + IF( !st0->bfi ) { - IF ( EQ_16(k, 1) ) + IF( EQ_16( k, 1 ) ) { Copy32( pDFT_RES, hStereoDft->res_mem_fx, 2 * hStereoDft->band_limits[hStereoDft->res_cod_band_max] ); hStereoDft->time_offs = 0; @@ -1529,7 +1529,7 @@ void stereo_dft_dec_fx( /* Apply active DMX */ /* pDFT_RES is used for the second channel in inactive frames */ - IF ( hStereoDft->frame_sid_nodata && !sba_dirac_stereo_flag ) + IF( hStereoDft->frame_sid_nodata && !sba_dirac_stereo_flag ) { DFT_L[0] = pDFT_DMX[0]; move32(); @@ -1544,26 +1544,26 @@ void stereo_dft_dec_fx( move32(); } - IF ( hStereoDft->frame_sid_nodata || EQ_16(st0->VAD, 0) ) + IF( hStereoDft->frame_sid_nodata || EQ_16( st0->VAD, 0 ) ) { hFdCngDec->cna_nbands = 0; move16(); } - FOR ( b = 0; b < hStereoDft->nbands; b++ ) + FOR( b = 0; b < hStereoDft->nbands; b++ ) { - g = extract_h(pSideGain[b]); + g = extract_h( pSideGain[b] ); move16(); - IF ( hStereoDft->frame_sid_nodata && !sba_dirac_stereo_flag ) + IF( hStereoDft->frame_sid_nodata && !sba_dirac_stereo_flag ) { g = hStereoDft->g_state_fx[b]; move16(); } /* store side gains from inactive frames for later use by the stereo CNA */ - IF ( LT_16(hStereoDft->band_limits[b], L_FRAME16k) && ( hStereoDft->frame_sid_nodata || EQ_16(st0->VAD, 0) ) ) + IF( LT_16( hStereoDft->band_limits[b], L_FRAME16k ) && ( hStereoDft->frame_sid_nodata || EQ_16( st0->VAD, 0 ) ) ) { - hFdCngDec->cna_nbands = add(b , 1); + hFdCngDec->cna_nbands = add( b, 1 ); move16(); hFdCngDec->cna_band_limits[b] = hStereoDft->band_limits[b]; move16(); @@ -1572,10 +1572,10 @@ void stereo_dft_dec_fx( } /* No residual coding in inactive frames, instead pDFT_RES is used for the second channel */ - IF ( GE_16(b, hStereoDft->res_cod_band_max) && !hStereoDft->frame_sid_nodata && !( sba_dirac_stereo_flag && hMdDec ) ) + IF( GE_16( b, hStereoDft->res_cod_band_max ) && !hStereoDft->frame_sid_nodata && !( sba_dirac_stereo_flag && hMdDec ) ) { /*filter non-coded frequencies. It removes some MDCT frequency aliasing*/ - FOR ( i = hStereoDft->band_limits[b]; i < hStereoDft->band_limits[b + 1]; i++ ) + FOR( i = hStereoDft->band_limits[b]; i < hStereoDft->band_limits[b + 1]; i++ ) { pDFT_RES[2 * i] = 0; move32(); @@ -1584,7 +1584,7 @@ void stereo_dft_dec_fx( } } - IF ( hStereoDft->frame_sid_nodata && !sba_dirac_stereo_flag ) + IF( hStereoDft->frame_sid_nodata && !sba_dirac_stereo_flag ) { /* Low pass filter coherence */ /* store coherence from inactive frames for later use by the stereo CNA */ @@ -1592,26 +1592,26 @@ void stereo_dft_dec_fx( move16(); /* Calculate gamma */ - IF ( LT_16(hStereoCng->cm_fx[b], (Word16)0x7333) ) + IF( LT_16( hStereoCng->cm_fx[b], (Word16) 0x7333 ) ) { Word32 op1, op2, l_gamma; Word16 q_loc1, q_loc2; gamma = hStereoCng->cm_fx[b]; move16(); - gamma = BASOP_Util_Divide3232_Scale(gamma , sub( MAX_16, gamma), &q_loc1); - l_gamma = L_deposit_l(gamma); - op1 = L_add(l_gamma, L_shr(L_deposit_l(sub(MAX_16 , mult(g, g))), q_loc1)); + gamma = BASOP_Util_Divide3232_Scale( gamma, sub( MAX_16, gamma ), &q_loc1 ); + l_gamma = L_deposit_l( gamma ); + op1 = L_add( l_gamma, L_shr( L_deposit_l( sub( MAX_16, mult( g, g ) ) ), q_loc1 ) ); q_loc1 = Q16 + q_loc1; q_loc2 = q_loc1; - op1 = Sqrt32(op1, &q_loc1); - op2 = Sqrt32(l_gamma, &q_loc2); - IF (NE_16(q_loc1, q_loc2)) + op1 = Sqrt32( op1, &q_loc1 ); + op2 = Sqrt32( l_gamma, &q_loc2 ); + IF( NE_16( q_loc1, q_loc2 ) ) { - op2 = L_shl(op2, sub(q_loc2, q_loc1)); + op2 = L_shl( op2, sub( q_loc2, q_loc1 ) ); q_loc2 = q_loc1; } - gamma = extract_h(L_sub( op1, op2)); - gamma = shl(gamma, q_loc2); + gamma = extract_h( L_sub( op1, op2 ) ); + gamma = shl( gamma, q_loc2 ); } ELSE { @@ -1619,115 +1619,115 @@ void stereo_dft_dec_fx( move16(); } - FOR ( i = hStereoDft->band_limits[b]; i < hStereoDft->band_limits[b + 1]; i++ ) + FOR( i = hStereoDft->band_limits[b]; i < hStereoDft->band_limits[b + 1]; i++ ) { /* Create L and R signals with the correct coherence by mixing channel 0 (pDFT_DMX) and channel 1 (pDFT_RES) */ - DFT_L[2 * i] = Madd_32_16(Madd_32_16(pDFT_DMX[2 * i], pDFT_DMX[2 * i], g ) , pDFT_RES[2 * i], gamma); + DFT_L[2 * i] = Madd_32_16( Madd_32_16( pDFT_DMX[2 * i], pDFT_DMX[2 * i], g ), pDFT_RES[2 * i], gamma ); move32(); - DFT_R[2 * i] = Msub_32_16(Msub_32_16(pDFT_DMX[2 * i], pDFT_DMX[2 * i], g ) , pDFT_RES[2 * i], gamma); + DFT_R[2 * i] = Msub_32_16( Msub_32_16( pDFT_DMX[2 * i], pDFT_DMX[2 * i], g ), pDFT_RES[2 * i], gamma ); move32(); - DFT_L[2 * i + 1] = Madd_32_16(Madd_32_16(pDFT_DMX[2 * i + 1], pDFT_DMX[2 * i + 1], g) , pDFT_RES[2 * i + 1], gamma); + DFT_L[2 * i + 1] = Madd_32_16( Madd_32_16( pDFT_DMX[2 * i + 1], pDFT_DMX[2 * i + 1], g ), pDFT_RES[2 * i + 1], gamma ); move32(); - DFT_R[2 * i + 1] = Msub_32_16(Msub_32_16(pDFT_DMX[2 * i + 1], pDFT_DMX[2 * i + 1], g) , pDFT_RES[2 * i + 1], gamma); + DFT_R[2 * i + 1] = Msub_32_16( Msub_32_16( pDFT_DMX[2 * i + 1], pDFT_DMX[2 * i + 1], g ), pDFT_RES[2 * i + 1], gamma ); move32(); } - IF ( NE_32(pgIpd[0] , 0) ) + IF( NE_32( pgIpd[0], 0 ) ) { Word32 theta = pgIpd[0]; - WHILE(GT_32(theta , EVS_2PI_FX)) + WHILE( GT_32( theta, EVS_2PI_FX ) ) { - theta = L_sub(theta, EVS_2PI_FX); + theta = L_sub( theta, EVS_2PI_FX ); } - WHILE(LT_32(theta , -EVS_2PI_FX)) + WHILE( LT_32( theta, -EVS_2PI_FX ) ) { - theta = L_add(theta, EVS_2PI_FX); + theta = L_add( theta, EVS_2PI_FX ); } - IF (GT_32(theta, EVS_PI_FX)) + IF( GT_32( theta, EVS_PI_FX ) ) { - theta = L_sub(theta, EVS_2PI_FX); + theta = L_sub( theta, EVS_2PI_FX ); } - ELSE IF(LT_32(theta, -EVS_PI_FX)) + ELSE IF( LT_32( theta, -EVS_PI_FX ) ) { - theta = L_add(theta, EVS_2PI_FX); + theta = L_add( theta, EVS_2PI_FX ); } - c0 = getCosWord16( extract_l(theta)); - IF (EQ_16(c0, ONE_IN_Q14)) + c0 = getCosWord16( extract_l( theta ) ); + IF( EQ_16( c0, ONE_IN_Q14 ) ) { c0 = MAX_16; } ELSE { - c0 = shl(c0, 1); + c0 = shl( c0, 1 ); } - s0 = getSinWord16( extract_l(theta)); - FOR ( i = hStereoDft->band_limits[b]; i < hStereoDft->band_limits[b + 1]; i++ ) + s0 = getSinWord16( extract_l( theta ) ); + FOR( i = hStereoDft->band_limits[b]; i < hStereoDft->band_limits[b + 1]; i++ ) { /*rotate L*/ - tmp = Msub_32_16(Mpy_32_16_1(DFT_L[2 * i], c0), DFT_L[2 * i + 1], s0); - DFT_L[2 * i + 1] = Madd_32_16(Mpy_32_16_1(DFT_L[2 * i], s0), DFT_L[2 * i + 1], c0); + tmp = Msub_32_16( Mpy_32_16_1( DFT_L[2 * i], c0 ), DFT_L[2 * i + 1], s0 ); + DFT_L[2 * i + 1] = Madd_32_16( Mpy_32_16_1( DFT_L[2 * i], s0 ), DFT_L[2 * i + 1], c0 ); move32(); DFT_L[2 * i] = tmp; move32(); } } } - ELSE IF ( sba_dirac_stereo_flag && hMdDec ) + ELSE IF( sba_dirac_stereo_flag && hMdDec ) { - IF ( EQ_16(nchan_transport , 1) ) + IF( EQ_16( nchan_transport, 1 ) ) { - IF ( sba_mono_flag ) + IF( sba_mono_flag ) { - IF ( EQ_16(b , 0) ) + IF( EQ_16( b, 0 ) ) { i = 0; move16(); - DFT_W = Mpy_32_32(hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i]); + DFT_W = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i] ); move32(); DFT_L[2 * i] = DFT_W; move32(); DFT_R[2 * i] = 0; move32(); - DFT_W = Mpy_32_32(hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i + 1]); + DFT_W = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i + 1] ); move32(); DFT_L[2 * i + 1] = DFT_W; move32(); DFT_R[2 * i + 1] = 0; move32(); } - FOR ( i = hStereoDft->band_limits[b]; i < min( stop, hStereoDft->band_limits[b + 1] ); i++ ) + FOR( i = hStereoDft->band_limits[b]; i < min( stop, hStereoDft->band_limits[b + 1] ); i++ ) { - DFT_W = Madd_32_32(Mpy_32_32(hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS] , pDFT_DMX[2 * i]), - L_add( hStereoDft->mixer_mat_smooth_fx[0][1][b + k * IVAS_MAX_NUM_BANDS] , - L_add( hStereoDft->mixer_mat_smooth_fx[0][2][b + k * IVAS_MAX_NUM_BANDS] , - hStereoDft->mixer_mat_smooth_fx[0][3][b + k * IVAS_MAX_NUM_BANDS])), - DFT_PRED_RES[2 * i]); + DFT_W = Madd_32_32( Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i] ), + L_add( hStereoDft->mixer_mat_smooth_fx[0][1][b + k * IVAS_MAX_NUM_BANDS], + L_add( hStereoDft->mixer_mat_smooth_fx[0][2][b + k * IVAS_MAX_NUM_BANDS], + hStereoDft->mixer_mat_smooth_fx[0][3][b + k * IVAS_MAX_NUM_BANDS] ) ), + DFT_PRED_RES[2 * i] ); DFT_L[2 * i] = DFT_W; move32(); DFT_R[2 * i] = 0; move32(); - DFT_W = Madd_32_32(Mpy_32_32(hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS] , pDFT_DMX[2 * i + 1]), - L_add( hStereoDft->mixer_mat_smooth_fx[0][1][b + k * IVAS_MAX_NUM_BANDS] , - L_add(hStereoDft->mixer_mat_smooth_fx[0][2][b + k * IVAS_MAX_NUM_BANDS] , - hStereoDft->mixer_mat_smooth_fx[0][3][b + k * IVAS_MAX_NUM_BANDS])), - DFT_PRED_RES[2 * i + 1]); + DFT_W = Madd_32_32( Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i + 1] ), + L_add( hStereoDft->mixer_mat_smooth_fx[0][1][b + k * IVAS_MAX_NUM_BANDS], + L_add( hStereoDft->mixer_mat_smooth_fx[0][2][b + k * IVAS_MAX_NUM_BANDS], + hStereoDft->mixer_mat_smooth_fx[0][3][b + k * IVAS_MAX_NUM_BANDS] ) ), + DFT_PRED_RES[2 * i + 1] ); DFT_L[2 * i + 1] = DFT_W; move32(); DFT_R[2 * i + 1] = 0; move32(); } - FOR ( ; i < hStereoDft->band_limits[b + 1]; i++ ) + FOR( ; i < hStereoDft->band_limits[b + 1]; i++ ) { - DFT_W = Mpy_32_32(hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS] , pDFT_DMX[2 * i]); + DFT_W = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i] ); DFT_L[2 * i] = DFT_W; move32(); DFT_R[2 * i] = 0; move32(); - DFT_W = Mpy_32_32(hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS] , pDFT_DMX[2 * i + 1]); + DFT_W = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i + 1] ); DFT_L[2 * i + 1] = DFT_W; move32(); DFT_R[2 * i + 1] = 0; @@ -1736,123 +1736,123 @@ void stereo_dft_dec_fx( } ELSE { - IF ( EQ_16(b , 0) ) + IF( EQ_16( b, 0 ) ) { i = 0; move16(); - DFT_W = Mpy_32_32(hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS] , pDFT_DMX[2 * i]); - DFT_Y = Mpy_32_32(hStereoDft->mixer_mat_smooth_fx[1][0][b + k * IVAS_MAX_NUM_BANDS] , pDFT_DMX[2 * i]); + DFT_W = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i] ); + DFT_Y = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[1][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i] ); - DFT_L[2 * i] = L_add(DFT_W , DFT_Y); + DFT_L[2 * i] = L_add( DFT_W, DFT_Y ); move32(); - DFT_R[2 * i] = L_sub(DFT_W , DFT_Y); + DFT_R[2 * i] = L_sub( DFT_W, DFT_Y ); move32(); - DFT_W = Mpy_32_32(hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS] , pDFT_DMX[2 * i + 1]); - DFT_Y = Mpy_32_32(hStereoDft->mixer_mat_smooth_fx[1][0][b + k * IVAS_MAX_NUM_BANDS] , pDFT_DMX[2 * i + 1]); + DFT_W = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i + 1] ); + DFT_Y = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[1][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i + 1] ); - DFT_L[2 * i + 1] = L_add(DFT_W , DFT_Y); + DFT_L[2 * i + 1] = L_add( DFT_W, DFT_Y ); move32(); - DFT_R[2 * i + 1] = L_sub(DFT_W , DFT_Y); + DFT_R[2 * i + 1] = L_sub( DFT_W, DFT_Y ); move32(); } - FOR ( i = hStereoDft->band_limits[b]; i < min( stop, hStereoDft->band_limits[b + 1] ); i++ ) + FOR( i = hStereoDft->band_limits[b]; i < min( stop, hStereoDft->band_limits[b + 1] ); i++ ) { - DFT_W = Madd_32_32(Mpy_32_32(hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS] , pDFT_DMX[2 * i]) , - L_add( hStereoDft->mixer_mat_smooth_fx[0][1][b + k * IVAS_MAX_NUM_BANDS] , - L_add(hStereoDft->mixer_mat_smooth_fx[0][2][b + k * IVAS_MAX_NUM_BANDS] , - hStereoDft->mixer_mat_smooth_fx[0][3][b + k * IVAS_MAX_NUM_BANDS])), - DFT_PRED_RES[2 * i]); - DFT_Y = Madd_32_32(Mpy_32_32(hStereoDft->mixer_mat_smooth_fx[1][0][b + k * IVAS_MAX_NUM_BANDS] , pDFT_DMX[2 * i]) , - L_add( hStereoDft->mixer_mat_smooth_fx[1][1][b + k * IVAS_MAX_NUM_BANDS] , - L_add(hStereoDft->mixer_mat_smooth_fx[1][2][b + k * IVAS_MAX_NUM_BANDS] , - hStereoDft->mixer_mat_smooth_fx[1][3][b + k * IVAS_MAX_NUM_BANDS])), - DFT_PRED_RES[2 * i]); - - DFT_L[2 * i] = L_add(DFT_W, DFT_Y); + DFT_W = Madd_32_32( Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i] ), + L_add( hStereoDft->mixer_mat_smooth_fx[0][1][b + k * IVAS_MAX_NUM_BANDS], + L_add( hStereoDft->mixer_mat_smooth_fx[0][2][b + k * IVAS_MAX_NUM_BANDS], + hStereoDft->mixer_mat_smooth_fx[0][3][b + k * IVAS_MAX_NUM_BANDS] ) ), + DFT_PRED_RES[2 * i] ); + DFT_Y = Madd_32_32( Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[1][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i] ), + L_add( hStereoDft->mixer_mat_smooth_fx[1][1][b + k * IVAS_MAX_NUM_BANDS], + L_add( hStereoDft->mixer_mat_smooth_fx[1][2][b + k * IVAS_MAX_NUM_BANDS], + hStereoDft->mixer_mat_smooth_fx[1][3][b + k * IVAS_MAX_NUM_BANDS] ) ), + DFT_PRED_RES[2 * i] ); + + DFT_L[2 * i] = L_add( DFT_W, DFT_Y ); move32(); - DFT_R[2 * i] = L_sub(DFT_W, DFT_Y); + DFT_R[2 * i] = L_sub( DFT_W, DFT_Y ); move32(); - DFT_W = Madd_32_32(Mpy_32_32(hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS] , pDFT_DMX[2 * i + 1]) , - L_add( hStereoDft->mixer_mat_smooth_fx[0][1][b + k * IVAS_MAX_NUM_BANDS] , - L_add(hStereoDft->mixer_mat_smooth_fx[0][2][b + k * IVAS_MAX_NUM_BANDS] , - hStereoDft->mixer_mat_smooth_fx[0][3][b + k * IVAS_MAX_NUM_BANDS])), - DFT_PRED_RES[2 * i + 1]); - DFT_Y = Madd_32_32(Mpy_32_32(hStereoDft->mixer_mat_smooth_fx[1][0][b + k * IVAS_MAX_NUM_BANDS] , pDFT_DMX[2 * i + 1]) , - L_add( hStereoDft->mixer_mat_smooth_fx[1][1][b + k * IVAS_MAX_NUM_BANDS] , - L_add(hStereoDft->mixer_mat_smooth_fx[1][2][b + k * IVAS_MAX_NUM_BANDS] , - hStereoDft->mixer_mat_smooth_fx[1][3][b + k * IVAS_MAX_NUM_BANDS])), - DFT_PRED_RES[2 * i + 1]); - - DFT_L[2 * i + 1] = L_add(DFT_W , DFT_Y); + DFT_W = Madd_32_32( Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i + 1] ), + L_add( hStereoDft->mixer_mat_smooth_fx[0][1][b + k * IVAS_MAX_NUM_BANDS], + L_add( hStereoDft->mixer_mat_smooth_fx[0][2][b + k * IVAS_MAX_NUM_BANDS], + hStereoDft->mixer_mat_smooth_fx[0][3][b + k * IVAS_MAX_NUM_BANDS] ) ), + DFT_PRED_RES[2 * i + 1] ); + DFT_Y = Madd_32_32( Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[1][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i + 1] ), + L_add( hStereoDft->mixer_mat_smooth_fx[1][1][b + k * IVAS_MAX_NUM_BANDS], + L_add( hStereoDft->mixer_mat_smooth_fx[1][2][b + k * IVAS_MAX_NUM_BANDS], + hStereoDft->mixer_mat_smooth_fx[1][3][b + k * IVAS_MAX_NUM_BANDS] ) ), + DFT_PRED_RES[2 * i + 1] ); + + DFT_L[2 * i + 1] = L_add( DFT_W, DFT_Y ); move32(); - DFT_R[2 * i + 1] = L_sub(DFT_W , DFT_Y); + DFT_R[2 * i + 1] = L_sub( DFT_W, DFT_Y ); move32(); } - FOR ( ; i < hStereoDft->band_limits[b + 1]; i++ ) + FOR( ; i < hStereoDft->band_limits[b + 1]; i++ ) { - DFT_W = Mpy_32_32(hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS] , pDFT_DMX[2 * i]); - DFT_Y = Mpy_32_32(hStereoDft->mixer_mat_smooth_fx[1][0][b + k * IVAS_MAX_NUM_BANDS] , pDFT_DMX[2 * i]); + DFT_W = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i] ); + DFT_Y = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[1][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i] ); - DFT_L[2 * i] = L_add(DFT_W , DFT_Y); + DFT_L[2 * i] = L_add( DFT_W, DFT_Y ); move32(); - DFT_R[2 * i] = L_sub(DFT_W , DFT_Y); + DFT_R[2 * i] = L_sub( DFT_W, DFT_Y ); move32(); - DFT_W = Mpy_32_32(hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS] , pDFT_DMX[2 * i + 1]); - DFT_Y = Mpy_32_32(hStereoDft->mixer_mat_smooth_fx[1][0][b + k * IVAS_MAX_NUM_BANDS] , pDFT_DMX[2 * i + 1]); + DFT_W = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i + 1] ); + DFT_Y = Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[1][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i + 1] ); - DFT_L[2 * i + 1] = L_add(DFT_W , DFT_Y); + DFT_L[2 * i + 1] = L_add( DFT_W, DFT_Y ); move32(); - DFT_R[2 * i + 1] = L_sub(DFT_W , DFT_Y); + DFT_R[2 * i + 1] = L_sub( DFT_W, DFT_Y ); move32(); } } } - ELSE IF ( GE_16(nchan_transport , 2) ) + ELSE IF( GE_16( nchan_transport, 2 ) ) { - IF ( EQ_16(b , 0) ) + IF( EQ_16( b, 0 ) ) { i = 0; move32(); DFT_W = pDFT_DMX[2 * i]; move32(); - DFT_Y = Madd_32_32(pDFT_DMX1[2 * i], hStereoDft->mixer_mat_smooth_fx[1][0][b + k * IVAS_MAX_NUM_BANDS] , pDFT_DMX[2 * i]); + DFT_Y = Madd_32_32( pDFT_DMX1[2 * i], hStereoDft->mixer_mat_smooth_fx[1][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i] ); - DFT_L[2 * i] = L_add(DFT_W , DFT_Y); + DFT_L[2 * i] = L_add( DFT_W, DFT_Y ); move32(); - DFT_R[2 * i] = L_sub(DFT_W , DFT_Y); + DFT_R[2 * i] = L_sub( DFT_W, DFT_Y ); move32(); DFT_W = pDFT_DMX[2 * i + 1]; move32(); - DFT_Y = Madd_32_32(pDFT_DMX1[2 * i + 1], hStereoDft->mixer_mat_smooth_fx[1][0][b + k * IVAS_MAX_NUM_BANDS] , pDFT_DMX[2 * i + 1]); + DFT_Y = Madd_32_32( pDFT_DMX1[2 * i + 1], hStereoDft->mixer_mat_smooth_fx[1][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i + 1] ); - DFT_L[2 * i + 1] = L_add(DFT_W , DFT_Y); + DFT_L[2 * i + 1] = L_add( DFT_W, DFT_Y ); move32(); - DFT_R[2 * i + 1] = L_sub(DFT_W , DFT_Y); + DFT_R[2 * i + 1] = L_sub( DFT_W, DFT_Y ); move32(); } - FOR ( i = hStereoDft->band_limits[b]; i < hStereoDft->band_limits[b + 1]; i++ ) + FOR( i = hStereoDft->band_limits[b]; i < hStereoDft->band_limits[b + 1]; i++ ) { DFT_W = pDFT_DMX[2 * i]; move32(); - DFT_Y = Madd_32_32(pDFT_DMX1[2 * i], hStereoDft->mixer_mat_smooth_fx[1][0][b + k * IVAS_MAX_NUM_BANDS] , pDFT_DMX[2 * i]); + DFT_Y = Madd_32_32( pDFT_DMX1[2 * i], hStereoDft->mixer_mat_smooth_fx[1][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i] ); - DFT_L[2 * i] = L_add(DFT_W , DFT_Y); + DFT_L[2 * i] = L_add( DFT_W, DFT_Y ); move32(); - DFT_R[2 * i] = L_sub(DFT_W , DFT_Y); + DFT_R[2 * i] = L_sub( DFT_W, DFT_Y ); move32(); DFT_W = pDFT_DMX[2 * i + 1]; move32(); - DFT_Y = Madd_32_32(pDFT_DMX1[2 * i + 1], hStereoDft->mixer_mat_smooth_fx[1][0][b + k * IVAS_MAX_NUM_BANDS] , pDFT_DMX[2 * i + 1]); + DFT_Y = Madd_32_32( pDFT_DMX1[2 * i + 1], hStereoDft->mixer_mat_smooth_fx[1][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i + 1] ); - DFT_L[2 * i + 1] = L_add(DFT_W , DFT_Y); + DFT_L[2 * i + 1] = L_add( DFT_W, DFT_Y ); move32(); - DFT_R[2 * i + 1] = L_sub(DFT_W , DFT_Y); + DFT_R[2 * i + 1] = L_sub( DFT_W, DFT_Y ); move32(); } } @@ -1863,77 +1863,75 @@ void stereo_dft_dec_fx( } ELSE { - FOR ( i = hStereoDft->band_limits[b]; i < min( stop, hStereoDft->band_limits[b + 1] ); i++ ) + FOR( i = hStereoDft->band_limits[b]; i < min( stop, hStereoDft->band_limits[b + 1] ); i++ ) { - tmp = L_add(Madd_32_16(pDFT_RES[2 * i], pDFT_DMX[2 * i], g) , DFT_PRED_RES[2 * i]); + tmp = L_add( Madd_32_16( pDFT_RES[2 * i], pDFT_DMX[2 * i], g ), DFT_PRED_RES[2 * i] ); - DFT_L[2 * i] = L_add(pDFT_DMX[2 * i] , tmp); + DFT_L[2 * i] = L_add( pDFT_DMX[2 * i], tmp ); move32(); - DFT_R[2 * i] = L_sub(pDFT_DMX[2 * i] , tmp); + DFT_R[2 * i] = L_sub( pDFT_DMX[2 * i], tmp ); move32(); - tmp = L_add(Madd_32_16(pDFT_RES[2 * i + 1], pDFT_DMX[2 * i + 1], g) , DFT_PRED_RES[2 * i + 1]); + tmp = L_add( Madd_32_16( pDFT_RES[2 * i + 1], pDFT_DMX[2 * i + 1], g ), DFT_PRED_RES[2 * i + 1] ); - DFT_L[2 * i + 1] = L_add(pDFT_DMX[2 * i + 1] , tmp); + DFT_L[2 * i + 1] = L_add( pDFT_DMX[2 * i + 1], tmp ); move32(); - DFT_R[2 * i + 1] = L_sub(pDFT_DMX[2 * i + 1] , tmp); + DFT_R[2 * i + 1] = L_sub( pDFT_DMX[2 * i + 1], tmp ); move32(); - } - FOR ( ; i < hStereoDft->band_limits[b + 1]; i++ ) + FOR( ; i < hStereoDft->band_limits[b + 1]; i++ ) { - tmp = Madd_32_16(pDFT_RES[2 * i], pDFT_DMX[2 * i], g); + tmp = Madd_32_16( pDFT_RES[2 * i], pDFT_DMX[2 * i], g ); - DFT_L[2 * i] = L_add(pDFT_DMX[2 * i] , tmp); + DFT_L[2 * i] = L_add( pDFT_DMX[2 * i], tmp ); move32(); - DFT_R[2 * i] = L_sub(pDFT_DMX[2 * i] , tmp); + DFT_R[2 * i] = L_sub( pDFT_DMX[2 * i], tmp ); move32(); - tmp = Madd_32_16(pDFT_RES[2 * i + 1], pDFT_DMX[2 * i + 1], g); + tmp = Madd_32_16( pDFT_RES[2 * i + 1], pDFT_DMX[2 * i + 1], g ); - DFT_L[2 * i + 1] = L_add(pDFT_DMX[2 * i + 1] , tmp); + DFT_L[2 * i + 1] = L_add( pDFT_DMX[2 * i + 1], tmp ); move32(); - DFT_R[2 * i + 1] = L_sub(pDFT_DMX[2 * i + 1] , tmp); + DFT_R[2 * i + 1] = L_sub( pDFT_DMX[2 * i + 1], tmp ); move32(); - } /* Active Upmix */ - IF ( NE_32(pgIpd[0] , 0) ) + IF( NE_32( pgIpd[0], 0 ) ) { Word32 theta = pgIpd[0]; - WHILE(GT_32(theta , EVS_2PI_FX)) + WHILE( GT_32( theta, EVS_2PI_FX ) ) { - theta = L_sub(theta, EVS_2PI_FX); + theta = L_sub( theta, EVS_2PI_FX ); } - WHILE(LT_32(theta , -EVS_2PI_FX)) + WHILE( LT_32( theta, -EVS_2PI_FX ) ) { - theta = L_add(theta, EVS_2PI_FX); + theta = L_add( theta, EVS_2PI_FX ); } - IF (GT_32(theta, EVS_PI_FX)) + IF( GT_32( theta, EVS_PI_FX ) ) { - theta = L_sub(theta, EVS_2PI_FX); + theta = L_sub( theta, EVS_2PI_FX ); } - ELSE IF(LT_32(theta, -EVS_PI_FX)) + ELSE IF( LT_32( theta, -EVS_PI_FX ) ) { - theta = L_add(theta, EVS_2PI_FX); + theta = L_add( theta, EVS_2PI_FX ); } - c0 = getCosWord16( extract_l(theta) ); - IF (EQ_16(c0, ONE_IN_Q14)) + c0 = getCosWord16( extract_l( theta ) ); + IF( EQ_16( c0, ONE_IN_Q14 ) ) { c0 = MAX_16; } ELSE { - c0 = shl(c0, 1); + c0 = shl( c0, 1 ); } - s0 = getSinWord16( extract_l(theta) ); - FOR ( i = hStereoDft->band_limits[b]; i < hStereoDft->band_limits[b + 1]; i++ ) + s0 = getSinWord16( extract_l( theta ) ); + FOR( i = hStereoDft->band_limits[b]; i < hStereoDft->band_limits[b + 1]; i++ ) { /*rotate L*/ - tmp = Msub_32_16(Mpy_32_16_1(DFT_L[2 * i], c0), DFT_L[2 * i + 1], s0); - DFT_L[2 * i + 1] = Madd_32_16(Mpy_32_16_1(DFT_L[2 * i], s0), DFT_L[2 * i + 1], c0); + tmp = Msub_32_16( Mpy_32_16_1( DFT_L[2 * i], c0 ), DFT_L[2 * i + 1], s0 ); + DFT_L[2 * i + 1] = Madd_32_16( Mpy_32_16_1( DFT_L[2 * i], s0 ), DFT_L[2 * i + 1], c0 ); move32(); DFT_L[2 * i] = tmp; move32(); @@ -1942,13 +1940,13 @@ void stereo_dft_dec_fx( } } - IF ( hStereoDft->frame_sid_nodata || EQ_16(st0->VAD , 0) ) + IF( hStereoDft->frame_sid_nodata || EQ_16( st0->VAD, 0 ) ) { hFdCngDec->cna_band_limits[hFdCngDec->cna_nbands] = hStereoDft->band_limits[hFdCngDec->cna_nbands]; move16(); } - IF ( hStereoDft->frame_sid_nodata && !sba_dirac_stereo_flag ) + IF( hStereoDft->frame_sid_nodata && !sba_dirac_stereo_flag ) { hStereoCng->first_SID = 0; move16(); @@ -1956,7 +1954,7 @@ void stereo_dft_dec_fx( move16(); } - FOR ( i = hStereoDft->band_limits[b]; i < shr(hStereoDft->NFFT , 1); i++ ) + FOR( i = hStereoDft->band_limits[b]; i < shr( hStereoDft->NFFT, 1 ); i++ ) { DFT_L[2 * i] = 0; move32(); @@ -1969,15 +1967,15 @@ void stereo_dft_dec_fx( } /*Nyquist Freq.*/ - IF ( EQ_16(hStereoDft->band_limits[b] , shr(hStereoDft->NFFT , 1 ))) + IF( EQ_16( hStereoDft->band_limits[b], shr( hStereoDft->NFFT, 1 ) ) ) { - DFT_L[1] = L_add(pDFT_DMX[1] , Mpy_32_16_1(pDFT_DMX[1], g)); + DFT_L[1] = L_add( pDFT_DMX[1], Mpy_32_16_1( pDFT_DMX[1], g ) ); move32(); - DFT_R[1] = L_sub(pDFT_DMX[1] , Mpy_32_16_1(pDFT_DMX[1], g)); + DFT_R[1] = L_sub( pDFT_DMX[1], Mpy_32_16_1( pDFT_DMX[1], g ) ); move32(); - DFT_L[1] = Mpy_32_16_1(DFT_L[1], INV_SQRT2_FX_Q15); + DFT_L[1] = Mpy_32_16_1( DFT_L[1], INV_SQRT2_FX_Q15 ); move32(); - DFT_R[1] = Mpy_32_16_1(DFT_R[1], INV_SQRT2_FX_Q15); + DFT_R[1] = Mpy_32_16_1( DFT_R[1], INV_SQRT2_FX_Q15 ); move32(); } ELSE @@ -1994,75 +1992,75 @@ void stereo_dft_dec_fx( pSideGain = NULL; /* Dummy upmix-> mono binauralization */ - FOR ( i = 0; i < hStereoDft->NFFT; i++ ) + FOR( i = 0; i < hStereoDft->NFFT; i++ ) { - DFT_L[i] = L_add( pDFT_DMX[i] , pDFT_RES[i] ); + DFT_L[i] = L_add( pDFT_DMX[i], pDFT_RES[i] ); move32(); - DFT_R[i] = L_sub( pDFT_DMX[i] , pDFT_RES[i] ); + DFT_R[i] = L_sub( pDFT_DMX[i], pDFT_RES[i] ); move32(); } } /* Comfort Noise Addition */ - IF ( st0->flag_cna ) + IF( st0->flag_cna ) { ptr_per = &hFdCngDec->smoothed_psd_fx[hFdCngCom->startBand]; scale_fact0 = 0; move16(); - IF ( GT_16(hFdCngDec->cna_rescale_fact_fx , 0) ) + IF( GT_16( hFdCngDec->cna_rescale_fact_fx, 0 ) ) { Word16 q_scale_fact0 = 0; - Word16 op = Sqrt16( shr(hFdCngDec->cna_rescale_fact_fx, 1), &q_scale_fact0); + Word16 op = Sqrt16( shr( hFdCngDec->cna_rescale_fact_fx, 1 ), &q_scale_fact0 ); move16(); - scale_fact0 = L_mult0(shr(output_frame , 1) , op); - IF (GT_16(q_scale_fact0, 0)) + scale_fact0 = L_mult0( shr( output_frame, 1 ), op ); + IF( GT_16( q_scale_fact0, 0 ) ) { - assert(0); + assert( 0 ); } ELSE { - scale_fact0 = L_shl(scale_fact0, q_scale_fact0); + scale_fact0 = L_shl( scale_fact0, q_scale_fact0 ); } } - FOR ( b = 0; b < hFdCngDec->cna_nbands; b++ ) + FOR( b = 0; b < hFdCngDec->cna_nbands; b++ ) { /* calculate gamma factor reflecting inter-channel correlation and side gain (ILD) */ coh = hFdCngDec->cna_cm_fx[b]; move16(); g = hFdCngDec->cna_g_state_fx[b]; move16(); - IF ( LT_16(coh , (Word16)(0x7333)) ) + IF( LT_16( coh, (Word16) ( 0x7333 ) ) ) { Word32 op1, op2, l_gamma; Word16 q_loc1, q_loc2, q_gamma; gamma = coh; move16(); - gamma = BASOP_Util_Divide3232_Scale(gamma , sub( (Word16)0x7FFF, gamma), &q_gamma); - IF (EQ_16(gamma, 0)) + gamma = BASOP_Util_Divide3232_Scale( gamma, sub( (Word16) 0x7FFF, gamma ), &q_gamma ); + IF( EQ_16( gamma, 0 ) ) { q_gamma = 0; } - l_gamma = L_deposit_l(gamma); - op1 = L_add(l_gamma, L_shr(L_deposit_l(sub(MAX_16 , mult(g, g))), q_gamma)); + l_gamma = L_deposit_l( gamma ); + op1 = L_add( l_gamma, L_shr( L_deposit_l( sub( MAX_16, mult( g, g ) ) ), q_gamma ) ); q_loc2 = Q16 + q_gamma; q_loc1 = q_loc2; - op1 = Sqrt32(op1, &q_loc1); - op2 = Sqrt32(l_gamma, &q_loc2); - IF (NE_32(op2, 0)) + op1 = Sqrt32( op1, &q_loc1 ); + op2 = Sqrt32( l_gamma, &q_loc2 ); + IF( NE_32( op2, 0 ) ) { - IF (NE_16(q_loc1, q_loc2)) + IF( NE_16( q_loc1, q_loc2 ) ) { - op2 = L_shl(op2, sub(q_loc2, q_loc1)); + op2 = L_shl( op2, sub( q_loc2, q_loc1 ) ); q_loc2 = q_loc1; } - gamma = extract_h(L_sub( op1, op2)); - gamma = shl(gamma, q_loc2); + gamma = extract_h( L_sub( op1, op2 ) ); + gamma = shl( gamma, q_loc2 ); } ELSE { - gamma = extract_h(L_shl(op1, q_loc1)); + gamma = extract_h( L_shl( op1, q_loc1 ) ); } } ELSE @@ -2070,7 +2068,7 @@ void stereo_dft_dec_fx( gamma = 0; } - FOR ( i = s_max( hFdCngDec->cna_band_limits[b], shr(hFdCngCom->startBand , 1) ); i < s_min( hFdCngDec->cna_band_limits[b + 1], (L_FRAME16k) >> 1 ); i++ ) + FOR( i = s_max( hFdCngDec->cna_band_limits[b], shr( hFdCngCom->startBand, 1 ) ); i < s_min( hFdCngDec->cna_band_limits[b + 1], ( L_FRAME16k ) >> 1 ); i++ ) { Word32 l_tmp; lev1 = *ptr_per++; @@ -2078,7 +2076,7 @@ void stereo_dft_dec_fx( lev2 = *ptr_per++; move32(); - IF ( GT_32(lev1 , 0) && GT_32(lev2 , 0) && GT_32( Mpy_32_16_1(L_max( lev1, lev2 ), (Word16)0x6AAB) , L_min( lev1, lev2 ))) + IF( GT_32( lev1, 0 ) && GT_32( lev2, 0 ) && GT_32( Mpy_32_16_1( L_max( lev1, lev2 ), (Word16) 0x6AAB ), L_min( lev1, lev2 ) ) ) { /* take the minimum of two adjacent frequency bins */ cna_level = L_min( lev1, lev2 ); @@ -2086,46 +2084,46 @@ void stereo_dft_dec_fx( ELSE { /* take the average of two adjacent frequency bins */ - cna_level = L_add(L_shr( lev1, 1) , L_shr(lev2 , 1)); + cna_level = L_add( L_shr( lev1, 1 ), L_shr( lev2, 1 ) ); } - q_cna_level = sub(Q31 , hFdCngDec->q_smoothed_psd); + q_cna_level = sub( Q31, hFdCngDec->q_smoothed_psd ); move16(); - l_tmp = Sqrt32( cna_level, &q_cna_level); - scale_fact = Mpy_32_32(l_tmp, scale_fact0); + l_tmp = Sqrt32( cna_level, &q_cna_level ); + scale_fact = Mpy_32_32( l_tmp, scale_fact0 ); /* scale_fact0 will be in Q15 by the time the above operation is performed so the q of scale_fact represented now by q_cna_level has to be updated */ - q_cna_level = sub(Q31, add(q_cna_level, Q16)); + q_cna_level = sub( Q31, add( q_cna_level, Q16 ) ); /* generate comfort noise from gaussian noise and add to the decoded DFT spectrum */ - N1 = L_shl(Mpy_32_16_1(scale_fact , rand_gauss_fix( &ftmp, cna_seed )), Q2); - N2 = L_shl(Mpy_32_16_1(scale_fact , rand_gauss_fix( &ftmp, cna_seed )), Q2); - l_tmp = L_add(Madd_32_16(N1, N1, g) , Mpy_32_16_1(N2, gamma)); - l_tmp = L_shr(l_tmp, sub(q_cna_level, hStereoDft->q_dft)); - DFT_L[2 * i] = L_add(DFT_L[2 * i], l_tmp); + N1 = L_shl( Mpy_32_16_1( scale_fact, rand_gauss_fix( &ftmp, cna_seed ) ), Q2 ); + N2 = L_shl( Mpy_32_16_1( scale_fact, rand_gauss_fix( &ftmp, cna_seed ) ), Q2 ); + l_tmp = L_add( Madd_32_16( N1, N1, g ), Mpy_32_16_1( N2, gamma ) ); + l_tmp = L_shr( l_tmp, sub( q_cna_level, hStereoDft->q_dft ) ); + DFT_L[2 * i] = L_add( DFT_L[2 * i], l_tmp ); move32(); - l_tmp = L_sub(Msub_32_16(N1, N1, g) , Mpy_32_16_1(N2, gamma)); - l_tmp = L_shr(l_tmp, sub(q_cna_level, hStereoDft->q_dft)); - DFT_R[2 * i] = L_add(DFT_R[2 * i], l_tmp); + l_tmp = L_sub( Msub_32_16( N1, N1, g ), Mpy_32_16_1( N2, gamma ) ); + l_tmp = L_shr( l_tmp, sub( q_cna_level, hStereoDft->q_dft ) ); + DFT_R[2 * i] = L_add( DFT_R[2 * i], l_tmp ); move32(); - N1 = L_shl(Mpy_32_16_1(scale_fact , rand_gauss_fix( &ftmp, cna_seed )), Q2); - N2 = L_shl(Mpy_32_16_1(scale_fact , rand_gauss_fix( &ftmp, cna_seed )), Q2); - l_tmp = L_add(Madd_32_16(N1, N1, g) , Mpy_32_16_1(N2, gamma)); - l_tmp = L_shr(l_tmp, sub(q_cna_level, hStereoDft->q_dft)); - DFT_L[2 * i + 1] = L_add(DFT_L[2 * i + 1] , l_tmp); + N1 = L_shl( Mpy_32_16_1( scale_fact, rand_gauss_fix( &ftmp, cna_seed ) ), Q2 ); + N2 = L_shl( Mpy_32_16_1( scale_fact, rand_gauss_fix( &ftmp, cna_seed ) ), Q2 ); + l_tmp = L_add( Madd_32_16( N1, N1, g ), Mpy_32_16_1( N2, gamma ) ); + l_tmp = L_shr( l_tmp, sub( q_cna_level, hStereoDft->q_dft ) ); + DFT_L[2 * i + 1] = L_add( DFT_L[2 * i + 1], l_tmp ); move32(); - l_tmp = L_sub(Msub_32_16(N1, N1, g) , Mpy_32_16_1(N2, gamma)); - l_tmp = L_shr(l_tmp, sub(q_cna_level, hStereoDft->q_dft)); - DFT_R[2 * i + 1] = L_add(DFT_R[2 * i + 1] , l_tmp); + l_tmp = L_sub( Msub_32_16( N1, N1, g ), Mpy_32_16_1( N2, gamma ) ); + l_tmp = L_shr( l_tmp, sub( q_cna_level, hStereoDft->q_dft ) ); + DFT_R[2 * i + 1] = L_add( DFT_R[2 * i + 1], l_tmp ); move32(); } } /* update CNA re-scaling factor */ - hFdCngDec->cna_rescale_fact_fx = extract_l(L_shr(L_mult0((Word16)0x6666, hFdCngDec->cna_act_fact_fx), Q15)); - IF ( !hFdCngDec->first_cna_noise_updated ) + hFdCngDec->cna_rescale_fact_fx = extract_l( L_shr( L_mult0( (Word16) 0x6666, hFdCngDec->cna_act_fact_fx ), Q15 ) ); + IF( !hFdCngDec->first_cna_noise_updated ) { hFdCngDec->cna_rescale_fact_fx = 0; move16(); @@ -2133,10 +2131,10 @@ void stereo_dft_dec_fx( } /* Update memories */ - hStereoDft->past_DMX_pos = ( hStereoDft->past_DMX_pos + 1 ) & (STEREO_DFT_PAST_MAX - 1); + hStereoDft->past_DMX_pos = ( hStereoDft->past_DMX_pos + 1 ) & ( STEREO_DFT_PAST_MAX - 1 ); Copy32( pDFT_DMX, hStereoDft->DFT_past_DMX_fx[hStereoDft->past_DMX_pos], s_min( hStereoDft->NFFT, STEREO_DFT32MS_N_32k ) ); hStereoDft->q_DFT_past_DMX_fx[hStereoDft->past_DMX_pos] = hStereoDft->q_dft; - IF ( pPredGain ) + IF( pPredGain ) { stereo_dft_adapt_sf_delay_fx( hStereoDft, pPredGain ); } @@ -2145,14 +2143,14 @@ void stereo_dft_dec_fx( Copy32( DFT_R, DFT[1] + k * STEREO_DFT32MS_N_MAX, hStereoDft->NFFT ); } - IF ( st0->bfi && !prev_bfi ) + IF( st0->bfi && !prev_bfi ) { Word16 q_shift0; Word16 q_shift1; - idx_k0 = add( hStereoDft->past_DMX_pos , STEREO_DFT_PAST_MAX - 1 ) & (STEREO_DFT_PAST_MAX - 1); - idx_k1 = add( idx_k0 , 1 ) & (STEREO_DFT_PAST_MAX - 1); - q_shift0 = sub(hStereoDft->q_dft, hStereoDft->q_DFT_past_DMX_fx[idx_k0]); - q_shift1 = sub(hStereoDft->q_dft, hStereoDft->q_DFT_past_DMX_fx[idx_k1]); + idx_k0 = add( hStereoDft->past_DMX_pos, STEREO_DFT_PAST_MAX - 1 ) & ( STEREO_DFT_PAST_MAX - 1 ); + idx_k1 = add( idx_k0, 1 ) & ( STEREO_DFT_PAST_MAX - 1 ); + q_shift0 = sub( hStereoDft->q_dft, hStereoDft->q_DFT_past_DMX_fx[idx_k0] ); + q_shift1 = sub( hStereoDft->q_dft, hStereoDft->q_DFT_past_DMX_fx[idx_k1] ); /*dmx energy memory*/ hStereoDft->past_dmx_nrg_fx = stereo_dft_dmx_swb_nrg_fx( hStereoDft->DFT_past_DMX_fx[idx_k0], hStereoDft->DFT_past_DMX_fx[idx_k1], s_min( hStereoDft->NFFT, STEREO_DFT32MS_N_32k ), q_shift0, q_shift1 ); } @@ -2170,7 +2168,7 @@ void stereo_dft_dec_fx( static void stereo_dft_compute_td_stefi_params_fx( STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ - const Word16 samp_ratio /* i : sampling ratio */ + const Word16 samp_ratio /* i : sampling ratio */ ) { Word16 pdmx_ind; @@ -2193,7 +2191,7 @@ static void stereo_dft_compute_td_stefi_params_fx( bres = hStereoDft->band_res[1]; move16(); - IF ( NE_16(hStereoDft->core_hist[1], ACELP_CORE) || hStereoDft->wasTransient ) + IF( NE_16( hStereoDft->core_hist[1], ACELP_CORE ) || hStereoDft->wasTransient ) { hStereoDft->td_gain_fx[0] = 0; move32(); @@ -2202,12 +2200,12 @@ static void stereo_dft_compute_td_stefi_params_fx( return; } - bin0 = extract_l( L_shr_r(Mpy_32_16_1((Word32)hStereoDft->NFFT, samp_ratio), 1) ); - bin0 = shl(bin0, Q3); + bin0 = extract_l( L_shr_r( Mpy_32_16_1( (Word32) hStereoDft->NFFT, samp_ratio ), 1 ) ); + bin0 = shl( bin0, Q3 ); bin0 = s_min( bin0, hStereoDft->band_limits[hStereoDft->nbands] ); b = hStereoDft->nbands; move16(); - WHILE ( GT_16(hStereoDft->band_limits[b], bin0) ) + WHILE( GT_16( hStereoDft->band_limits[b], bin0 ) ) { b--; } @@ -2215,15 +2213,16 @@ static void stereo_dft_compute_td_stefi_params_fx( /* calculate averages over high bands */ pred_g = pred_gain_avg = 0; - move32(); move32(); + move32(); + move32(); nbands = 0; move16(); wsum = 0; move32(); - shift_g = Q15 - norm_s(sub(hStereoDft->nbands, band0)); - FOR ( b = band0; b < hStereoDft->nbands; b++ ) + shift_g = Q15 - norm_s( sub( hStereoDft->nbands, band0 ) ); + FOR( b = band0; b < hStereoDft->nbands; b++ ) { - IF ( LT_32(L_min( hStereoDft->past_res_pred_gain_fx[STEFI_DELAY_IND( STEREO_DFT_TD_STEFI_SUBFR_DELAY + 1, pdmx_ind )][b], hStereoDft->past_res_pred_gain_fx[STEFI_DELAY_IND( STEREO_DFT_TD_STEFI_SUBFR_DELAY + 2, pdmx_ind )][b] ), 0) ) + IF( LT_32( L_min( hStereoDft->past_res_pred_gain_fx[STEFI_DELAY_IND( STEREO_DFT_TD_STEFI_SUBFR_DELAY + 1, pdmx_ind )][b], hStereoDft->past_res_pred_gain_fx[STEFI_DELAY_IND( STEREO_DFT_TD_STEFI_SUBFR_DELAY + 2, pdmx_ind )][b] ), 0 ) ) { hStereoDft->td_gain_fx[0] = 0; move32(); @@ -2231,21 +2230,23 @@ static void stereo_dft_compute_td_stefi_params_fx( move16(); return; } - pred_g = L_add(pred_g, L_shr(Mpy_32_16_1(L_add( L_shr(hStereoDft->res_pred_gain_fx[b + STEREO_DFT_BAND_MAX], 1) , - L_shr(hStereoDft->res_pred_gain_fx[b + 2 * STEREO_DFT_BAND_MAX], 1) ), - dft_res_pred_weights_fx[bres][b - band0]), shift_g)); - pred_gain_avg = L_add(pred_gain_avg, L_shr(Mpy_32_16_1( L_add(L_shr(hStereoDft->past_res_pred_gain_fx[STEFI_DELAY_IND( STEREO_DFT_TD_STEFI_SUBFR_DELAY + 2, pdmx_ind )][b] , 1), - L_shr(hStereoDft->past_res_pred_gain_fx[STEFI_DELAY_IND( STEREO_DFT_TD_STEFI_SUBFR_DELAY + 1, pdmx_ind )][b] , 1 )), - dft_res_pred_weights_fx[bres][b - band0]), shift_g)); + pred_g = L_add( pred_g, L_shr( Mpy_32_16_1( L_add( L_shr( hStereoDft->res_pred_gain_fx[b + STEREO_DFT_BAND_MAX], 1 ), + L_shr( hStereoDft->res_pred_gain_fx[b + 2 * STEREO_DFT_BAND_MAX], 1 ) ), + dft_res_pred_weights_fx[bres][b - band0] ), + shift_g ) ); + pred_gain_avg = L_add( pred_gain_avg, L_shr( Mpy_32_16_1( L_add( L_shr( hStereoDft->past_res_pred_gain_fx[STEFI_DELAY_IND( STEREO_DFT_TD_STEFI_SUBFR_DELAY + 2, pdmx_ind )][b], 1 ), + L_shr( hStereoDft->past_res_pred_gain_fx[STEFI_DELAY_IND( STEREO_DFT_TD_STEFI_SUBFR_DELAY + 1, pdmx_ind )][b], 1 ) ), + dft_res_pred_weights_fx[bres][b - band0] ), + shift_g ) ); nbands++; - wsum = L_add(wsum, dft_res_pred_weights_fx[bres][b - band0]); + wsum = L_add( wsum, dft_res_pred_weights_fx[bres][b - band0] ); #ifdef DBG_TD_STEFI printf( "frame: %d\tband: %-2d\tpred_gain1: %f\tpred_gain2: %f\tppg1: %f\tppg2: %f\n", frame, b, hStereoDft->res_pred_gain[b + STEREO_DFT_BAND_MAX], hStereoDft->res_pred_gain[b + 2 * STEREO_DFT_BAND_MAX], hStereoDft->past_res_pred_gain[STEREO_DFT_TD_STEFI_SUBFR_DELAY - 2][b], hStereoDft->past_res_pred_gain[d_short - 1][b] ); #endif } - IF ( EQ_16(nbands, 0) ) + IF( EQ_16( nbands, 0 ) ) { /* apparently, there is nothing to do here */ hStereoDft->td_gain_fx[0] = 0; @@ -2254,62 +2255,63 @@ static void stereo_dft_compute_td_stefi_params_fx( move16(); return; } - wsum = L_shl(wsum, sub(Q16 , shift_g)); - pred_g = BASOP_Util_Divide3232_Scale(pred_g, wsum, &q_div); - IF (GT_16(sub(15, q_div), 15)) + wsum = L_shl( wsum, sub( Q16, shift_g ) ); + pred_g = BASOP_Util_Divide3232_Scale( pred_g, wsum, &q_div ); + IF( GT_16( sub( 15, q_div ), 15 ) ) { - pred_g = L_shl(pred_g, q_div); - //q_pred_g = 15; + pred_g = L_shl( pred_g, q_div ); + // q_pred_g = 15; } - //ELSE + // ELSE //{ - // q_pred_g = sub(15, q_div); - //} - pred_gain_avg = BASOP_Util_Divide3232_Scale(pred_gain_avg, wsum, &q_div); - IF (GT_16(sub(15, q_div), 15)) + // q_pred_g = sub(15, q_div); + // } + pred_gain_avg = BASOP_Util_Divide3232_Scale( pred_gain_avg, wsum, &q_div ); + IF( GT_16( sub( 15, q_div ), 15 ) ) { - pred_gain_avg = L_shl(pred_gain_avg, q_div); + pred_gain_avg = L_shl( pred_gain_avg, q_div ); q_pred_gain_avg = 15; } ELSE { - q_pred_gain_avg = sub(15, q_div);; + q_pred_gain_avg = sub( 15, q_div ); + ; } nrg_DMX = hStereoDft->hb_nrg_fx[0]; nrg_pred_DMX = hStereoDft->hb_nrg_fx[1]; - op1 = BASOP_Util_Divide3232_Scale(L_add( EPSILON_FIX , nrg_DMX ) , L_add( EPSILON_FIX , nrg_pred_DMX ), &q_div); + op1 = BASOP_Util_Divide3232_Scale( L_add( EPSILON_FIX, nrg_DMX ), L_add( EPSILON_FIX, nrg_pred_DMX ), &q_div ); q_sqrt = Q16 + q_div; - op1 = Sqrt32(op1, &q_sqrt); - g2 = Mpy_32_32(pred_g , op1); - IF (LT_16(q_sqrt, 0)) + op1 = Sqrt32( op1, &q_sqrt ); + g2 = Mpy_32_32( pred_g, op1 ); + IF( LT_16( q_sqrt, 0 ) ) { - g2 = L_shl(g2, q_sqrt); + g2 = L_shl( g2, q_sqrt ); q_sqrt = 0; } - ELSE IF ( NE_16(q_sqrt, 0)) + ELSE IF( NE_16( q_sqrt, 0 ) ) { - IF (LT_32(L_shr(pred_gain_avg, q_sqrt), g2)) + IF( LT_32( L_shr( pred_gain_avg, q_sqrt ), g2 ) ) { g2 = pred_gain_avg; } ELSE { - g2 = L_min( Mpy_32_16_1(L_shr(pred_gain_avg, q_sqrt) , STEREO_DFT_STEFFI_GAIN_AMP_FX), - Madd_32_16(Mpy_32_16_1(L_shr(pred_gain_avg, q_sqrt) , sub( (Word16)0x7FFF , STEREO_DFT_STEFFI_GAIN_REST_AMT_FX )), - g2, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX )); - g2 = L_shl(g2, q_sqrt); + g2 = L_min( Mpy_32_16_1( L_shr( pred_gain_avg, q_sqrt ), STEREO_DFT_STEFFI_GAIN_AMP_FX ), + Madd_32_16( Mpy_32_16_1( L_shr( pred_gain_avg, q_sqrt ), sub( (Word16) 0x7FFF, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ), + g2, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ); + g2 = L_shl( g2, q_sqrt ); } } ELSE { - g2 = L_min( Mpy_32_16_1(pred_gain_avg , STEREO_DFT_STEFFI_GAIN_AMP_FX), - Madd_32_16(Mpy_32_16_1(pred_gain_avg , sub( (Word16)0x7FFF , STEREO_DFT_STEFFI_GAIN_REST_AMT_FX )), - g2, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX )); + g2 = L_min( Mpy_32_16_1( pred_gain_avg, STEREO_DFT_STEFFI_GAIN_AMP_FX ), + Madd_32_16( Mpy_32_16_1( pred_gain_avg, sub( (Word16) 0x7FFF, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ), + g2, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ); } - hStereoDft->td_gain_fx[0] = L_deposit_h((Word16)g2); - hStereoDft->q_td_gain[0] = add(16, q_pred_gain_avg); + hStereoDft->td_gain_fx[0] = L_deposit_h( (Word16) g2 ); + hStereoDft->q_td_gain[0] = add( 16, q_pred_gain_avg ); move32(); move16(); @@ -2364,14 +2366,14 @@ static void stereo_dft_dequantize_ipd_fx( *-------------------------------------------------------------------------*/ void stereo_dft_generate_res_pred_fx( STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ - const Word16 samp_ratio, /* i : sampling ratio */ - Word32 *pDFT_DMX, /* i : downmix signal */ - Word32 *DFT_PRED_RES, /* o : residual prediction signal */ - Word32 *pPredGain, /* i : residual prediction gains */ - const Word16 k, /* i : subframe index */ - Word32 *ap_filt_DMX, /* i : enhanced stereo filling signal */ - Word16 *stop, /* o : last FD stereo filling bin */ - const Word16 bfi /* i : BFI flag */ + const Word16 samp_ratio, /* i : sampling ratio */ + Word32 *pDFT_DMX, /* i : downmix signal */ + Word32 *DFT_PRED_RES, /* o : residual prediction signal */ + Word32 *pPredGain, /* i : residual prediction gains */ + const Word16 k, /* i : subframe index */ + Word32 *ap_filt_DMX, /* i : enhanced stereo filling signal */ + Word16 *stop, /* o : last FD stereo filling bin */ + const Word16 bfi /* i : BFI flag */ ) { /* general variables */ @@ -2383,7 +2385,7 @@ void stereo_dft_generate_res_pred_fx( /* variables for enhanced stereo filling */ Word16 norm_fac, q_norm_fac = 0, lim_norm_fac; Word16 q_sqrt; - Word16 alpha; //gain_limit; + Word16 alpha; // gain_limit; /* variables for stereo filling */ Word16 d_long, d_short, d_long_ind, d_short_ind; @@ -2397,8 +2399,8 @@ void stereo_dft_generate_res_pred_fx( push_wmops( "gen_respred" ); /* smoothing and limiting parameters */ - alpha = hStereoDft->wasTransient ? 0 : (Word16)(0x199A); /* no smoothing after transients */ - //gain_limit = 0x7FFF; // 2.0 in Q14 + alpha = hStereoDft->wasTransient ? 0 : (Word16) ( 0x199A ); /* no smoothing after transients */ + // gain_limit = 0x7FFF; // 2.0 in Q14 move16(); /* residual prediction only used up to 16 kHz (SWB) */ @@ -2406,19 +2408,19 @@ void stereo_dft_generate_res_pred_fx( /* In ACELP mode the downmix signal is not available in bandwidth extension area. * * Therefore, the downmix energy in the corresponding subbands is estimated. */ - bin0 = (Word16) (L_shr(L_add(L_mult0(hStereoDft->NFFT, samp_ratio), ONE_IN_Q12), Q12 + 1)); + bin0 = (Word16) ( L_shr( L_add( L_mult0( hStereoDft->NFFT, samp_ratio ), ONE_IN_Q12 ), Q12 + 1 ) ); move16(); bin0 = s_min( bin0, hStereoDft->band_limits[hStereoDft->nbands] ); b = hStereoDft->nbands; move16(); - WHILE ( GE_16(hStereoDft->band_limits[b], bin0) ) + WHILE( GE_16( hStereoDft->band_limits[b], bin0 ) ) { b--; } band0 = b; move16(); - IF ( LT_16(hStereoDft->res_pred_mode[k + STEREO_DFT_OFFSET], STEREO_DFT_RESPRED_ESF) ) + IF( LT_16( hStereoDft->res_pred_mode[k + STEREO_DFT_OFFSET], STEREO_DFT_RESPRED_ESF ) ) { /* no ESF signal available, use stereo filling over whole spectrum */ lb_stefi_start_band = s_max( hStereoDft->res_pred_band_min, hStereoDft->res_cod_band_max ); @@ -2429,18 +2431,18 @@ void stereo_dft_generate_res_pred_fx( lb_stefi_start_band = s_max( band0, hStereoDft->res_cod_band_max ); } - IF ( bfi ) + IF( bfi ) { lb_stefi_start_band = 0; move16(); } /* lowband: use ESF if available, else use stereo filling */ - IF ( EQ_16(hStereoDft->res_pred_mode[k + STEREO_DFT_OFFSET], STEREO_DFT_RESPRED_ESF) ) + IF( EQ_16( hStereoDft->res_pred_mode[k + STEREO_DFT_OFFSET], STEREO_DFT_RESPRED_ESF ) ) { /* ESF in lowband */ /* main loop over core region*/ - FOR ( b = hStereoDft->res_cod_band_max; b <= band0; b++ ) + FOR( b = hStereoDft->res_cod_band_max; b <= band0; b++ ) { dmx_nrg = EPSILON_FIX; move32(); @@ -2448,69 +2450,69 @@ void stereo_dft_generate_res_pred_fx( move32(); /* calculate band energies (low band only in case of ACELP) */ - FOR ( i = hStereoDft->band_limits[b]; i < s_min( hStereoDft->band_limits[b + 1], bin0 ); i++ ) + FOR( i = hStereoDft->band_limits[b]; i < s_min( hStereoDft->band_limits[b + 1], bin0 ); i++ ) { /* Saturating below calculations (to be rechecked?) */ - dmx_nrg = L_add_sat(dmx_nrg, - Madd_32_32(Mpy_32_32(pDFT_DMX[2 * i], pDFT_DMX[2 * i]), - pDFT_DMX[2 * i + 1], pDFT_DMX[2 * i + 1])); - rev_nrg = L_add_sat(rev_nrg, - Madd_32_32(Mpy_32_32(ap_filt_DMX[2 * i], ap_filt_DMX[2 * i]), - ap_filt_DMX[2 * i + 1], ap_filt_DMX[2 * i + 1])); + dmx_nrg = L_add_sat( dmx_nrg, + Madd_32_32( Mpy_32_32( pDFT_DMX[2 * i], pDFT_DMX[2 * i] ), + pDFT_DMX[2 * i + 1], pDFT_DMX[2 * i + 1] ) ); + rev_nrg = L_add_sat( rev_nrg, + Madd_32_32( Mpy_32_32( ap_filt_DMX[2 * i], ap_filt_DMX[2 * i] ), + ap_filt_DMX[2 * i + 1], ap_filt_DMX[2 * i + 1] ) ); } - IF (LT_16(hStereoDft->q_smoothed_nrg , hStereoDft->q_dft)) + IF( LT_16( hStereoDft->q_smoothed_nrg, hStereoDft->q_dft ) ) { - rev_nrg = L_shr(rev_nrg, shl(sub(hStereoDft->q_dft, hStereoDft->q_smoothed_nrg), 1)); - dmx_nrg = L_shr(dmx_nrg, shl(sub(hStereoDft->q_dft, hStereoDft->q_smoothed_nrg), 1)); + rev_nrg = L_shr( rev_nrg, shl( sub( hStereoDft->q_dft, hStereoDft->q_smoothed_nrg ), 1 ) ); + dmx_nrg = L_shr( dmx_nrg, shl( sub( hStereoDft->q_dft, hStereoDft->q_smoothed_nrg ), 1 ) ); } #if 1 - ELSE IF (GT_16(hStereoDft->q_smoothed_nrg , hStereoDft->q_dft)) + ELSE IF( GT_16( hStereoDft->q_smoothed_nrg, hStereoDft->q_dft ) ) { - hStereoDft->smooth_res_nrg_fx[b] = L_shr(hStereoDft->smooth_res_nrg_fx[b], shl(sub(hStereoDft->q_smoothed_nrg, hStereoDft->q_dft), 1)); - hStereoDft->smooth_dmx_nrg_fx[b] = L_shr(hStereoDft->smooth_dmx_nrg_fx[b], shl(sub(hStereoDft->q_smoothed_nrg, hStereoDft->q_dft), 1)); + hStereoDft->smooth_res_nrg_fx[b] = L_shr( hStereoDft->smooth_res_nrg_fx[b], shl( sub( hStereoDft->q_smoothed_nrg, hStereoDft->q_dft ), 1 ) ); + hStereoDft->smooth_dmx_nrg_fx[b] = L_shr( hStereoDft->smooth_dmx_nrg_fx[b], shl( sub( hStereoDft->q_smoothed_nrg, hStereoDft->q_dft ), 1 ) ); } #endif /* smoothing */ - hStereoDft->smooth_res_nrg_fx[b] = Madd_32_16(Mpy_32_16_1(hStereoDft->smooth_res_nrg_fx[b], alpha), rev_nrg, sub( (Word16)(0x7FFF), alpha )) ; + hStereoDft->smooth_res_nrg_fx[b] = Madd_32_16( Mpy_32_16_1( hStereoDft->smooth_res_nrg_fx[b], alpha ), rev_nrg, sub( (Word16) ( 0x7FFF ), alpha ) ); move32(); - hStereoDft->smooth_dmx_nrg_fx[b] = Madd_32_16(Mpy_32_16_1(hStereoDft->smooth_dmx_nrg_fx[b], alpha), dmx_nrg, sub( (Word16)(0x7FFF), alpha )) ; + hStereoDft->smooth_dmx_nrg_fx[b] = Madd_32_16( Mpy_32_16_1( hStereoDft->smooth_dmx_nrg_fx[b], alpha ), dmx_nrg, sub( (Word16) ( 0x7FFF ), alpha ) ); move32(); /* normalization factor */ - IF (NE_32(hStereoDft->smooth_res_nrg_fx[b], 0)) + IF( NE_32( hStereoDft->smooth_res_nrg_fx[b], 0 ) ) { - norm_fac = BASOP_Util_Divide3232_Scale(hStereoDft->smooth_dmx_nrg_fx[b], hStereoDft->smooth_res_nrg_fx[b], &q_norm_fac); - norm_fac = Sqrt16(norm_fac, &q_norm_fac); - IF (NE_16(norm_fac, 0)) + norm_fac = BASOP_Util_Divide3232_Scale( hStereoDft->smooth_dmx_nrg_fx[b], hStereoDft->smooth_res_nrg_fx[b], &q_norm_fac ); + norm_fac = Sqrt16( norm_fac, &q_norm_fac ); + IF( NE_16( norm_fac, 0 ) ) { /* gain compressor */ - IF (LE_16(q_norm_fac, -Q1) || (EQ_16(q_norm_fac, Q1) && GT_16((Word16)0x3333, norm_fac)) || (EQ_16(q_norm_fac, 0) && GT_16((Word16)0x6666, norm_fac))) + IF( LE_16( q_norm_fac, -Q1 ) || ( EQ_16( q_norm_fac, Q1 ) && GT_16( (Word16) 0x3333, norm_fac ) ) || ( EQ_16( q_norm_fac, 0 ) && GT_16( (Word16) 0x6666, norm_fac ) ) ) { - lim_norm_fac = (Word16)0x5000; + lim_norm_fac = (Word16) 0x5000; } - ELSE IF (GT_16(q_norm_fac, Q1) || (EQ_16(q_norm_fac, Q1) && LT_16((Word16)0x5000, norm_fac)) || (EQ_16(q_norm_fac, 0) && GT_16((Word16)0x6666, norm_fac))) + ELSE IF( GT_16( q_norm_fac, Q1 ) || ( EQ_16( q_norm_fac, Q1 ) && LT_16( (Word16) 0x5000, norm_fac ) ) || ( EQ_16( q_norm_fac, 0 ) && GT_16( (Word16) 0x6666, norm_fac ) ) ) { - lim_norm_fac = (Word16)0x3333; + lim_norm_fac = (Word16) 0x3333; } ELSE { lim_norm_fac = norm_fac; } - IF (EQ_16(lim_norm_fac, norm_fac)) + IF( EQ_16( lim_norm_fac, norm_fac ) ) { norm_fac = ONE_IN_Q14; q_norm_fac = Q1; } ELSE { - norm_fac = extract_l(L_shr(L_mult0(norm_fac, lim_norm_fac), Q15)); - q_norm_fac = add(q_norm_fac, 1); - IF (LT_16(q_norm_fac, 0 )) + norm_fac = extract_l( L_shr( L_mult0( norm_fac, lim_norm_fac ), Q15 ) ); + q_norm_fac = add( q_norm_fac, 1 ); + IF( LT_16( q_norm_fac, 0 ) ) { - norm_fac = shl(norm_fac, q_norm_fac); + norm_fac = shl( norm_fac, q_norm_fac ); q_norm_fac = 0; } - ELSE IF (GT_16(q_norm_fac, 2) && LT_16(norm_s(norm_fac) , sub(q_norm_fac, Q1))) + ELSE IF( GT_16( q_norm_fac, 2 ) && LT_16( norm_s( norm_fac ), sub( q_norm_fac, Q1 ) ) ) { norm_fac = MAX_16; q_norm_fac = Q1; @@ -2524,29 +2526,29 @@ void stereo_dft_generate_res_pred_fx( q_norm_fac = Q1; } - FOR ( i = hStereoDft->band_limits[b]; i < s_min( hStereoDft->band_limits[b + 1], bin0 ); i++ ) + FOR( i = hStereoDft->band_limits[b]; i < s_min( hStereoDft->band_limits[b + 1], bin0 ); i++ ) { - DFT_PRED_RES[2 * i] = L_shl(Mpy_32_32(Mpy_32_16_1(pPredGain[b], norm_fac), ap_filt_DMX[2 * i]), q_norm_fac); + DFT_PRED_RES[2 * i] = L_shl( Mpy_32_32( Mpy_32_16_1( pPredGain[b], norm_fac ), ap_filt_DMX[2 * i] ), q_norm_fac ); move32(); - DFT_PRED_RES[2 * i + 1] = L_shl(Mpy_32_32(Mpy_32_16_1(pPredGain[b], norm_fac), ap_filt_DMX[2 * i + 1]), q_norm_fac); + DFT_PRED_RES[2 * i + 1] = L_shl( Mpy_32_32( Mpy_32_16_1( pPredGain[b], norm_fac ), ap_filt_DMX[2 * i + 1] ), q_norm_fac ); move32(); } } #if 1 - IF (GT_16(hStereoDft->q_smoothed_nrg , hStereoDft->q_dft)) + IF( GT_16( hStereoDft->q_smoothed_nrg, hStereoDft->q_dft ) ) { hStereoDft->q_smoothed_nrg = hStereoDft->q_dft; } #endif } - ELSE IF ( EQ_16(hStereoDft->res_pred_mode[k + STEREO_DFT_OFFSET], STEREO_DFT_RESPRED_STEFI) ) + ELSE IF( EQ_16( hStereoDft->res_pred_mode[k + STEREO_DFT_OFFSET], STEREO_DFT_RESPRED_STEFI ) ) { /* stefi in lowband */ set_l( DFT_PRED_RES, 0, 2 * hStereoDft->band_limits[lb_stefi_start_band] ); - FOR ( b = lb_stefi_start_band; b <= band0; b++ ) + FOR( b = lb_stefi_start_band; b <= band0; b++ ) { - d_short_ind = add(sub(STEREO_DFT_PAST_MAX, STEREO_DFT_STEFFI_DELAY_SHORT), b & 1); + d_short_ind = add( sub( STEREO_DFT_PAST_MAX, STEREO_DFT_STEFFI_DELAY_SHORT ), b & 1 ); /* ToDo:Change the float operation here */ d_long_ind = max( 4, (int16_t) ( ( STEREO_DFT_PAST_MAX + 4 - 1 ) * ( (float) b / ( hStereoDft->nbands - 1 ) ) + 0.5f ) ) - 4; move16(); @@ -2556,14 +2558,14 @@ void stereo_dft_generate_res_pred_fx( move16(); /* Even number of window sliding (assymmetric OLA) */ - d_short_ind = shl( shr(d_short_ind, 1), 1 ); - d_long_ind = shl(shr( d_long_ind, 1), 1 ); + d_short_ind = shl( shr( d_short_ind, 1 ), 1 ); + d_long_ind = shl( shr( d_long_ind, 1 ), 1 ); - d_short = sub(STEREO_DFT_PAST_MAX, d_short_ind); - d_long = sub(STEREO_DFT_PAST_MAX, d_long_ind); + d_short = sub( STEREO_DFT_PAST_MAX, d_short_ind ); + d_long = sub( STEREO_DFT_PAST_MAX, d_long_ind ); - d_short_ind = add(add(d_short_ind, hStereoDft->past_DMX_pos), 1 ) % STEREO_DFT_PAST_MAX; - d_long_ind = add(add(d_long_ind, hStereoDft->past_DMX_pos), 1) % STEREO_DFT_PAST_MAX; + d_short_ind = add( add( d_short_ind, hStereoDft->past_DMX_pos ), 1 ) % STEREO_DFT_PAST_MAX; + d_long_ind = add( add( d_long_ind, hStereoDft->past_DMX_pos ), 1 ) % STEREO_DFT_PAST_MAX; g_short = hStereoDft->stefi_short_gain_fx; move16(); @@ -2571,7 +2573,7 @@ void stereo_dft_generate_res_pred_fx( move16(); /* change mixing ratio if long and short delay are the same */ - IF ( EQ_16(d_short, d_long) ) + IF( EQ_16( d_short, d_long ) ) { g_short = MAX_16; move16(); @@ -2580,21 +2582,21 @@ void stereo_dft_generate_res_pred_fx( } /* Avoid transient components */ - IF ( EQ_32(hStereoDft->past_res_pred_gain_fx[d_short_ind][b], EVS_LW_MIN) && EQ_32(hStereoDft->past_res_pred_gain_fx[d_long_ind][b], EVS_LW_MIN) ) + IF( EQ_32( hStereoDft->past_res_pred_gain_fx[d_short_ind][b], EVS_LW_MIN ) && EQ_32( hStereoDft->past_res_pred_gain_fx[d_long_ind][b], EVS_LW_MIN ) ) { g_long = 0; move16(); g_short = 0; move16(); } - ELSE IF ( EQ_32(hStereoDft->past_res_pred_gain_fx[d_short_ind][b], EVS_LW_MIN) ) + ELSE IF( EQ_32( hStereoDft->past_res_pred_gain_fx[d_short_ind][b], EVS_LW_MIN ) ) { g_long = MAX_16; move16(); g_short = 0; move16(); } - ELSE IF ( EQ_32(hStereoDft->past_res_pred_gain_fx[d_long_ind][b], EVS_LW_MIN) ) + ELSE IF( EQ_32( hStereoDft->past_res_pred_gain_fx[d_long_ind][b], EVS_LW_MIN ) ) { g_long = 0; move16(); @@ -2602,158 +2604,158 @@ void stereo_dft_generate_res_pred_fx( move16(); } - IF ( GT_16(s_max( g_short, g_long ), 0) ) + IF( GT_16( s_max( g_short, g_long ), 0 ) ) { - Word16 q_shift0 = sub(hStereoDft->q_dft, hStereoDft->q_DFT_past_DMX_fx[d_short_ind]); - Word16 q_shift1 = sub(hStereoDft->q_dft, hStereoDft->q_DFT_past_DMX_fx[d_long_ind]); + Word16 q_shift0 = sub( hStereoDft->q_dft, hStereoDft->q_DFT_past_DMX_fx[d_short_ind] ); + Word16 q_shift1 = sub( hStereoDft->q_dft, hStereoDft->q_DFT_past_DMX_fx[d_long_ind] ); past_dmx_nrg = EPSILON_FIX; move32(); dmx_nrg = EPSILON_FIX; move32(); - FOR ( i = hStereoDft->band_limits[b]; i < min( bin0, hStereoDft->band_limits[b + 1] ); i++ ) + FOR( i = hStereoDft->band_limits[b]; i < min( bin0, hStereoDft->band_limits[b + 1] ); i++ ) { - dmx_nrg = Madd_32_32(Madd_32_32(dmx_nrg, pDFT_DMX[2 * i], pDFT_DMX[2 * i]), pDFT_DMX[2 * i + 1], pDFT_DMX[2 * i + 1]); + dmx_nrg = Madd_32_32( Madd_32_32( dmx_nrg, pDFT_DMX[2 * i], pDFT_DMX[2 * i] ), pDFT_DMX[2 * i + 1], pDFT_DMX[2 * i + 1] ); - DFT_PRED_RES[2 * i] = L_add(L_shl(Mpy_32_16_1(hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i] , g_short), q_shift0), L_shl(Mpy_32_16_1(hStereoDft->DFT_past_DMX_fx[d_long_ind][2 * i], g_long ), q_shift1)); + DFT_PRED_RES[2 * i] = L_add( L_shl( Mpy_32_16_1( hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i], g_short ), q_shift0 ), L_shl( Mpy_32_16_1( hStereoDft->DFT_past_DMX_fx[d_long_ind][2 * i], g_long ), q_shift1 ) ); move32(); - DFT_PRED_RES[2 * i + 1] = L_add(L_shl(Mpy_32_16_1(hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i + 1] , g_short), q_shift0), L_shl(Mpy_32_16_1(hStereoDft->DFT_past_DMX_fx[d_long_ind][2 * i + 1], g_long ), q_shift1)); + DFT_PRED_RES[2 * i + 1] = L_add( L_shl( Mpy_32_16_1( hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i + 1], g_short ), q_shift0 ), L_shl( Mpy_32_16_1( hStereoDft->DFT_past_DMX_fx[d_long_ind][2 * i + 1], g_long ), q_shift1 ) ); move32(); - past_dmx_nrg = Madd_32_32(Madd_32_32(past_dmx_nrg, DFT_PRED_RES[2 * i], DFT_PRED_RES[2 * i]), DFT_PRED_RES[2 * i + 1], DFT_PRED_RES[2 * i + 1]); + past_dmx_nrg = Madd_32_32( Madd_32_32( past_dmx_nrg, DFT_PRED_RES[2 * i], DFT_PRED_RES[2 * i] ), DFT_PRED_RES[2 * i + 1], DFT_PRED_RES[2 * i + 1] ); } - IF ( !bfi || GE_16(b, hStereoDft->res_cod_band_max) ) + IF( !bfi || GE_16( b, hStereoDft->res_cod_band_max ) ) { Word16 q_div; Word16 op; - op = BASOP_Util_Divide3232_Scale(( 1 + dmx_nrg ), ( 1 + past_dmx_nrg ), &q_div); + op = BASOP_Util_Divide3232_Scale( ( 1 + dmx_nrg ), ( 1 + past_dmx_nrg ), &q_div ); q_sqrt = q_div; - norm_fac = Sqrt16( op, &q_sqrt); - g2 = Mpy_32_16_1(pPredGain[b], norm_fac); - IF (LE_32(q_sqrt, norm_l(g2))) + norm_fac = Sqrt16( op, &q_sqrt ); + g2 = Mpy_32_16_1( pPredGain[b], norm_fac ); + IF( LE_32( q_sqrt, norm_l( g2 ) ) ) { - g2 = L_shl(g2, q_sqrt); - pred_gain_avg = Madd_32_16(Mpy_32_16_1(hStereoDft->past_res_pred_gain_fx[d_short_ind][b], g_short), - hStereoDft->past_res_pred_gain_fx[d_long_ind][b], g_long); - - g2 = min( Mpy_32_16_1(pred_gain_avg, STEREO_DFT_STEFFI_GAIN_AMP_FX), - Madd_32_16(Mpy_32_16_1(pred_gain_avg, sub( MAX_16, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX )), - g2, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX )); + g2 = L_shl( g2, q_sqrt ); + pred_gain_avg = Madd_32_16( Mpy_32_16_1( hStereoDft->past_res_pred_gain_fx[d_short_ind][b], g_short ), + hStereoDft->past_res_pred_gain_fx[d_long_ind][b], g_long ); + + g2 = min( Mpy_32_16_1( pred_gain_avg, STEREO_DFT_STEFFI_GAIN_AMP_FX ), + Madd_32_16( Mpy_32_16_1( pred_gain_avg, sub( MAX_16, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ), + g2, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ); q_sqrt = 0; } ELSE { /* Multiplication with STEREO_DFT_STEFFI_GAIN_AMP_FX is avodided since the float value of this constant is 1.0f */ - g2 = Madd_32_16(Mpy_32_16_1(hStereoDft->past_res_pred_gain_fx[d_short_ind][b], g_short), - hStereoDft->past_res_pred_gain_fx[d_long_ind][b], g_long); + g2 = Madd_32_16( Mpy_32_16_1( hStereoDft->past_res_pred_gain_fx[d_short_ind][b], g_short ), + hStereoDft->past_res_pred_gain_fx[d_long_ind][b], g_long ); q_sqrt = 0; } - FOR ( i = hStereoDft->band_limits[b]; i < min( bin0, hStereoDft->band_limits[b + 1] ); i++ ) + FOR( i = hStereoDft->band_limits[b]; i < min( bin0, hStereoDft->band_limits[b + 1] ); i++ ) { - DFT_PRED_RES[2 * i] = L_shl(Mpy_32_32(g2, DFT_PRED_RES[2 * i]), q_sqrt); + DFT_PRED_RES[2 * i] = L_shl( Mpy_32_32( g2, DFT_PRED_RES[2 * i] ), q_sqrt ); move32(); - DFT_PRED_RES[2 * i + 1] = L_shl(Mpy_32_32(g2, DFT_PRED_RES[2 * i + 1]), q_sqrt); + DFT_PRED_RES[2 * i + 1] = L_shl( Mpy_32_32( g2, DFT_PRED_RES[2 * i + 1] ), q_sqrt ); move32(); } } } ELSE { - set32_fx( DFT_PRED_RES + shl(hStereoDft->band_limits[b], 1), 0, shl( sub(min( bin0, hStereoDft->band_limits[b + 1] ), hStereoDft->band_limits[b]), 1) ); + set32_fx( DFT_PRED_RES + shl( hStereoDft->band_limits[b], 1 ), 0, shl( sub( min( bin0, hStereoDft->band_limits[b + 1] ), hStereoDft->band_limits[b] ), 1 ) ); } } } - IF ( GT_16(hStereoDft->band_limits[nbands_respred], bin0) ) + IF( GT_16( hStereoDft->band_limits[nbands_respred], bin0 ) ) { /* apply stereo filling in ACELP BWE region */ - IF ( EQ_16(hStereoDft->core_hist[0], ACELP_CORE) && EQ_16(hStereoDft->core_hist[STEREO_DFT_STEFFI_DELAY_SHORT / 2], ACELP_CORE) ) + IF( EQ_16( hStereoDft->core_hist[0], ACELP_CORE ) && EQ_16( hStereoDft->core_hist[STEREO_DFT_STEFFI_DELAY_SHORT / 2], ACELP_CORE ) ) { /* ACELP -> ACELP: nothing to do */ *stop = bin0; move16(); } - ELSE IF ( EQ_16(hStereoDft->core_hist[STEREO_DFT_STEFFI_DELAY_SHORT / 2], ACELP_CORE) ) + ELSE IF( EQ_16( hStereoDft->core_hist[STEREO_DFT_STEFFI_DELAY_SHORT / 2], ACELP_CORE ) ) { /* ACELP -> TCX/HQ core transition */ /* calculate high band energy only */ dmx_nrg = EPSILON_FIX; move32(); - FOR ( i = bin0; i < shr(hStereoDft->NFFT, 1); i++ ) + FOR( i = bin0; i < shr( hStereoDft->NFFT, 1 ); i++ ) { - dmx_nrg = L_add(dmx_nrg, Madd_32_32(Mpy_32_32(pDFT_DMX[2 * i], pDFT_DMX[2 * i]), pDFT_DMX[2 * i + 1], pDFT_DMX[2 * i + 1])); + dmx_nrg = L_add( dmx_nrg, Madd_32_32( Mpy_32_32( pDFT_DMX[2 * i], pDFT_DMX[2 * i] ), pDFT_DMX[2 * i + 1], pDFT_DMX[2 * i + 1] ) ); } - hStereoDft->hb_nrg_fx[0] = dmx_nrg , L_shr(hStereoDft->NFFT, 1); + hStereoDft->hb_nrg_fx[0] = dmx_nrg, L_shr( hStereoDft->NFFT, 1 ); *stop = bin0; move16(); } - ELSE IF ( EQ_16(hStereoDft->core_hist[0], ACELP_CORE) ) + ELSE IF( EQ_16( hStereoDft->core_hist[0], ACELP_CORE ) ) { /* TCX/HQ core -> ACELP transition */ /* apply short delay only and blend to long/short gain */ dmx_nrg = hStereoDft->hb_nrg_subr_fx[k]; d_short_ind = STEREO_DFT_PAST_MAX - STEREO_DFT_TD_STEFI_SUBFR_DELAY; - d_short_ind = add( d_short_ind , add(hStereoDft->past_DMX_pos , 1) ) & (STEREO_DFT_PAST_MAX - 1); + d_short_ind = add( d_short_ind, add( hStereoDft->past_DMX_pos, 1 ) ) & ( STEREO_DFT_PAST_MAX - 1 ); /* calculate high band energy of past dmx */ - //past_dmx_nrg = EPSILON_FIX; + // past_dmx_nrg = EPSILON_FIX; past_dmx_nrg = 0; - FOR ( i = bin0; i < s_min( shr(hStereoDft->NFFT , 1), STEREO_DFT32MS_N_32k / 2 ); i++ ) + FOR( i = bin0; i < s_min( shr( hStereoDft->NFFT, 1 ), STEREO_DFT32MS_N_32k / 2 ); i++ ) { - past_dmx_nrg = L_add(past_dmx_nrg, Madd_32_32(Mpy_32_32(hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i] , hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i]) , hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i + 1] , hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i + 1])); + past_dmx_nrg = L_add( past_dmx_nrg, Madd_32_32( Mpy_32_32( hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i], hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i] ), hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i + 1], hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i + 1] ) ); } - past_dmx_nrg = L_shl(past_dmx_nrg, shl(sub(hStereoDft->q_dft, hStereoDft->q_DFT_past_DMX_fx[d_short_ind]), 1)); - IF (EQ_32(past_dmx_nrg, 0)) + past_dmx_nrg = L_shl( past_dmx_nrg, shl( sub( hStereoDft->q_dft, hStereoDft->q_DFT_past_DMX_fx[d_short_ind] ), 1 ) ); + IF( EQ_32( past_dmx_nrg, 0 ) ) { past_dmx_nrg = EPSILON_FX; } - FOR ( b = band0; b < nbands_respred; b++ ) + FOR( b = band0; b < nbands_respred; b++ ) { - g_short = LT_32(hStereoDft->past_res_pred_gain_fx[d_short_ind][b], 0) ? 0 : add( ONE_IN_Q14, shr(hStereoDft->stefi_short_gain_fx, 1)); + g_short = LT_32( hStereoDft->past_res_pred_gain_fx[d_short_ind][b], 0 ) ? 0 : add( ONE_IN_Q14, shr( hStereoDft->stefi_short_gain_fx, 1 ) ); - IF ( GT_16(g_short , 0) ) + IF( GT_16( g_short, 0 ) ) { Word16 q_divide, q_shift; - Word32 op = BASOP_Util_Divide3232_Scale( (EPSILON_FIX + dmx_nrg ) , ( EPSILON_FIX + past_dmx_nrg ) , &q_divide); + Word32 op = BASOP_Util_Divide3232_Scale( ( EPSILON_FIX + dmx_nrg ), ( EPSILON_FIX + past_dmx_nrg ), &q_divide ); q_norm_fac = Q16 + q_divide + hStereoDft->q_hb_nrg_subr; - op = Sqrt32( op, &q_norm_fac); - g2 = Mpy_32_32(pPredGain[b], op); - pred_gain_avg = Mpy_32_16_1(hStereoDft->past_res_pred_gain_fx[d_short_ind][b], g_short); - IF (LT_16(q_norm_fac, 0)) + op = Sqrt32( op, &q_norm_fac ); + g2 = Mpy_32_32( pPredGain[b], op ); + pred_gain_avg = Mpy_32_16_1( hStereoDft->past_res_pred_gain_fx[d_short_ind][b], g_short ); + IF( LT_16( q_norm_fac, 0 ) ) { - g2 = L_shl(g2, q_norm_fac); + g2 = L_shl( g2, q_norm_fac ); q_norm_fac = 0; } - ELSE IF ( NE_16(q_norm_fac, 0)) + ELSE IF( NE_16( q_norm_fac, 0 ) ) { - IF (LT_32(L_shr(pred_gain_avg, q_norm_fac), g2)) + IF( LT_32( L_shr( pred_gain_avg, q_norm_fac ), g2 ) ) { g2 = pred_gain_avg; } ELSE { - g2 = L_min( Mpy_32_16_1(L_shr(pred_gain_avg, q_norm_fac) , STEREO_DFT_STEFFI_GAIN_AMP_FX), - Madd_32_16(Mpy_32_16_1(L_shr(pred_gain_avg, q_norm_fac) , sub( (Word16)0x7FFF , STEREO_DFT_STEFFI_GAIN_REST_AMT_FX )), - g2, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX )); - g2 = L_shl(g2, q_norm_fac); + g2 = L_min( Mpy_32_16_1( L_shr( pred_gain_avg, q_norm_fac ), STEREO_DFT_STEFFI_GAIN_AMP_FX ), + Madd_32_16( Mpy_32_16_1( L_shr( pred_gain_avg, q_norm_fac ), sub( (Word16) 0x7FFF, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ), + g2, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ); + g2 = L_shl( g2, q_norm_fac ); } } ELSE { - g2 = L_min( Mpy_32_16_1(pred_gain_avg , STEREO_DFT_STEFFI_GAIN_AMP_FX), - Madd_32_16(Mpy_32_16_1(pred_gain_avg , sub( (Word16)0x7FFF , STEREO_DFT_STEFFI_GAIN_REST_AMT_FX )), - g2, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX )); + g2 = L_min( Mpy_32_16_1( pred_gain_avg, STEREO_DFT_STEFFI_GAIN_AMP_FX ), + Madd_32_16( Mpy_32_16_1( pred_gain_avg, sub( (Word16) 0x7FFF, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ), + g2, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ); } - q_shift = sub(hStereoDft->q_dft, hStereoDft->q_DFT_past_DMX_fx[d_short_ind]); + q_shift = sub( hStereoDft->q_dft, hStereoDft->q_DFT_past_DMX_fx[d_short_ind] ); move16(); - FOR ( i = max( hStereoDft->band_limits[b], bin0 ); i < min( hStereoDft->band_limits[b + 1], STEREO_DFT32MS_N_32k / 2 ); i++ ) + FOR( i = max( hStereoDft->band_limits[b], bin0 ); i < min( hStereoDft->band_limits[b + 1], STEREO_DFT32MS_N_32k / 2 ); i++ ) { - DFT_PRED_RES[2 * i] = L_shl(Mpy_32_32(g2 , hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i]), q_shift); + DFT_PRED_RES[2 * i] = L_shl( Mpy_32_32( g2, hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i] ), q_shift ); move32(); - DFT_PRED_RES[2 * i + 1] = L_shl(Mpy_32_32(g2 , hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i + 1]), q_shift); + DFT_PRED_RES[2 * i + 1] = L_shl( Mpy_32_32( g2, hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i + 1] ), q_shift ); move32(); } } @@ -2769,10 +2771,10 @@ void stereo_dft_generate_res_pred_fx( } ELSE { - FOR ( b = band0; b < nbands_respred; b++ ) + FOR( b = band0; b < nbands_respred; b++ ) { /* TCX/HQ core -> TCX/HQ core: business as usual */ - d_short_ind = add(sub(STEREO_DFT_PAST_MAX, STEREO_DFT_STEFFI_DELAY_SHORT), b & 1); + d_short_ind = add( sub( STEREO_DFT_PAST_MAX, STEREO_DFT_STEFFI_DELAY_SHORT ), b & 1 ); move16(); d_long_ind = max( 4, (int16_t) ( ( STEREO_DFT_PAST_MAX + 4 - 1 ) * ( (float) b / ( hStereoDft->nbands - 1 ) ) + 0.5f ) ) - 4; move16(); @@ -2781,20 +2783,20 @@ void stereo_dft_generate_res_pred_fx( d_short_ind = s_max( d_short_ind, d_long_ind ); /* Even number of window sliding (assymmetric OLA) */ - d_short_ind = d_short_ind & (Word16)(0xFFFE); + d_short_ind = d_short_ind & (Word16) ( 0xFFFE ); move16(); - d_long_ind = d_long_ind & (Word16)(0xFFFE); + d_long_ind = d_long_ind & (Word16) ( 0xFFFE ); move16(); - d_short = sub(STEREO_DFT_PAST_MAX , d_short_ind); + d_short = sub( STEREO_DFT_PAST_MAX, d_short_ind ); move16(); - d_long = sub(STEREO_DFT_PAST_MAX , d_long_ind); + d_long = sub( STEREO_DFT_PAST_MAX, d_long_ind ); move16(); /* Works as long as STEREO_DFT_PAST_MAX is a power of 2*/ - d_short_ind = ( add(d_short_ind, add(hStereoDft->past_DMX_pos, 1)) ) & (STEREO_DFT_PAST_MAX - 1); + d_short_ind = ( add( d_short_ind, add( hStereoDft->past_DMX_pos, 1 ) ) ) & ( STEREO_DFT_PAST_MAX - 1 ); move16(); - d_long_ind = ( add(d_long_ind, add(hStereoDft->past_DMX_pos, 1)) ) & (STEREO_DFT_PAST_MAX - 1); + d_long_ind = ( add( d_long_ind, add( hStereoDft->past_DMX_pos, 1 ) ) ) & ( STEREO_DFT_PAST_MAX - 1 ); move16(); g_short = hStereoDft->stefi_short_gain_fx; @@ -2803,7 +2805,7 @@ void stereo_dft_generate_res_pred_fx( move16(); /* change mixing ratio if long and short delay are the same */ - IF ( EQ_16(d_short , d_long) ) + IF( EQ_16( d_short, d_long ) ) { g_short = MAX_16; move16(); @@ -2812,80 +2814,80 @@ void stereo_dft_generate_res_pred_fx( } /* Avoid transient components */ - IF ( EQ_32(hStereoDft->past_res_pred_gain_fx[d_short_ind][b], MIN_32) && - EQ_32(hStereoDft->past_res_pred_gain_fx[d_long_ind][b], MIN_32)) + IF( EQ_32( hStereoDft->past_res_pred_gain_fx[d_short_ind][b], MIN_32 ) && + EQ_32( hStereoDft->past_res_pred_gain_fx[d_long_ind][b], MIN_32 ) ) { g_long = 0; move16(); g_short = 0; move16(); } - ELSE IF( EQ_32(hStereoDft->past_res_pred_gain_fx[d_short_ind][b], MIN_32) ) + ELSE IF( EQ_32( hStereoDft->past_res_pred_gain_fx[d_short_ind][b], MIN_32 ) ) { g_long = MAX_16; move16(); g_short = 0; move16(); } - ELSE IF ( EQ_32(hStereoDft->past_res_pred_gain_fx[d_long_ind][b], MIN_32) ) + ELSE IF( EQ_32( hStereoDft->past_res_pred_gain_fx[d_long_ind][b], MIN_32 ) ) { g_long = 0; move16(); g_short = MAX_16; move16(); } - IF ( EQ_32(hStereoDft->core_hist[d_short / 2], ACELP_CORE) ) + IF( EQ_32( hStereoDft->core_hist[d_short / 2], ACELP_CORE ) ) { g_short = 0; move16(); } - IF ( EQ_32(hStereoDft->core_hist[d_long / 2] , ACELP_CORE) ) + IF( EQ_32( hStereoDft->core_hist[d_long / 2], ACELP_CORE ) ) { g_long = 0; move16(); } - IF ( GT_16(s_max( g_short, g_long ) , 0) ) + IF( GT_16( s_max( g_short, g_long ), 0 ) ) { Word16 q_div; Word32 op1; - Word16 q_shift0 = sub(hStereoDft->q_dft, hStereoDft->q_DFT_past_DMX_fx[d_short_ind]); - Word16 q_shift1 = sub(hStereoDft->q_dft, hStereoDft->q_DFT_past_DMX_fx[d_long_ind]); + Word16 q_shift0 = sub( hStereoDft->q_dft, hStereoDft->q_DFT_past_DMX_fx[d_short_ind] ); + Word16 q_shift1 = sub( hStereoDft->q_dft, hStereoDft->q_DFT_past_DMX_fx[d_long_ind] ); past_dmx_nrg = EPSILON_FIX; move32(); dmx_nrg = EPSILON_FIX; move32(); - FOR ( i = max( hStereoDft->band_limits[b], bin0 ); i < min( hStereoDft->band_limits[b + 1], STEREO_DFT32MS_N_32k / 2 ); i++ ) + FOR( i = max( hStereoDft->band_limits[b], bin0 ); i < min( hStereoDft->band_limits[b + 1], STEREO_DFT32MS_N_32k / 2 ); i++ ) { - dmx_nrg = L_add(dmx_nrg, Madd_32_32(Mpy_32_32(pDFT_DMX[2 * i] , pDFT_DMX[2 * i]) , pDFT_DMX[2 * i + 1] , pDFT_DMX[2 * i + 1])); + dmx_nrg = L_add( dmx_nrg, Madd_32_32( Mpy_32_32( pDFT_DMX[2 * i], pDFT_DMX[2 * i] ), pDFT_DMX[2 * i + 1], pDFT_DMX[2 * i + 1] ) ); - DFT_PRED_RES[2 * i] = L_add(L_shl(Mpy_32_16_1(hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i], g_short), q_shift0) , L_shl(Mpy_32_16_1(hStereoDft->DFT_past_DMX_fx[d_long_ind][2 * i], g_long ), q_shift1)); + DFT_PRED_RES[2 * i] = L_add( L_shl( Mpy_32_16_1( hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i], g_short ), q_shift0 ), L_shl( Mpy_32_16_1( hStereoDft->DFT_past_DMX_fx[d_long_ind][2 * i], g_long ), q_shift1 ) ); move32(); - DFT_PRED_RES[2 * i + 1] = L_add(L_shl(Mpy_32_16_1(hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i + 1], g_short), q_shift0) , L_shl(Mpy_32_16_1(hStereoDft->DFT_past_DMX_fx[d_long_ind][2 * i + 1] , g_long ), q_shift1)); + DFT_PRED_RES[2 * i + 1] = L_add( L_shl( Mpy_32_16_1( hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i + 1], g_short ), q_shift0 ), L_shl( Mpy_32_16_1( hStereoDft->DFT_past_DMX_fx[d_long_ind][2 * i + 1], g_long ), q_shift1 ) ); move32(); - past_dmx_nrg = L_add(past_dmx_nrg, Madd_32_32(Mpy_32_32(DFT_PRED_RES[2 * i] , DFT_PRED_RES[2 * i]) , DFT_PRED_RES[2 * i + 1] , DFT_PRED_RES[2 * i + 1])); + past_dmx_nrg = L_add( past_dmx_nrg, Madd_32_32( Mpy_32_32( DFT_PRED_RES[2 * i], DFT_PRED_RES[2 * i] ), DFT_PRED_RES[2 * i + 1], DFT_PRED_RES[2 * i + 1] ) ); } - op1 = L_deposit_h(BASOP_Util_Divide3232_Scale( (EPSILON_FIX + dmx_nrg ) , ( EPSILON_FIX + past_dmx_nrg ), &q_div)); + op1 = L_deposit_h( BASOP_Util_Divide3232_Scale( ( EPSILON_FIX + dmx_nrg ), ( EPSILON_FIX + past_dmx_nrg ), &q_div ) ); q_norm_fac = q_div; - op1 = Sqrt32( op1, &q_norm_fac); - IF (GT_16(q_norm_fac , 16)) + op1 = Sqrt32( op1, &q_norm_fac ); + IF( GT_16( q_norm_fac, 16 ) ) { - assert(0); + assert( 0 ); } - norm_fac = extract_h(op1); - q_norm_fac = sub(q_norm_fac, Q16); - g2 = Mpy_32_16_1(pPredGain[b], norm_fac); - pred_gain_avg = Madd_32_16(Mpy_32_16_1(hStereoDft->past_res_pred_gain_fx[d_short_ind][b], g_short) , hStereoDft->past_res_pred_gain_fx[d_long_ind][b] , g_long); + norm_fac = extract_h( op1 ); + q_norm_fac = sub( q_norm_fac, Q16 ); + g2 = Mpy_32_16_1( pPredGain[b], norm_fac ); + pred_gain_avg = Madd_32_16( Mpy_32_16_1( hStereoDft->past_res_pred_gain_fx[d_short_ind][b], g_short ), hStereoDft->past_res_pred_gain_fx[d_long_ind][b], g_long ); - g2 = L_min( Mpy_32_16_1(pred_gain_avg , STEREO_DFT_STEFFI_GAIN_AMP_FX), - Madd_32_16(Mpy_32_16_1(pred_gain_avg , sub( (Word16)(0x7FFF) , STEREO_DFT_STEFFI_GAIN_REST_AMT_FX )) , g2 , STEREO_DFT_STEFFI_GAIN_REST_AMT_FX )); + g2 = L_min( Mpy_32_16_1( pred_gain_avg, STEREO_DFT_STEFFI_GAIN_AMP_FX ), + Madd_32_16( Mpy_32_16_1( pred_gain_avg, sub( (Word16) ( 0x7FFF ), STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ), g2, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ); - FOR ( i = max( hStereoDft->band_limits[b], bin0 ); i < min( hStereoDft->band_limits[b + 1], STEREO_DFT32MS_N_32k / 2 ); i++ ) + FOR( i = max( hStereoDft->band_limits[b], bin0 ); i < min( hStereoDft->band_limits[b + 1], STEREO_DFT32MS_N_32k / 2 ); i++ ) { - DFT_PRED_RES[2 * i] = Mpy_32_32(g2, DFT_PRED_RES[2 * i]); + DFT_PRED_RES[2 * i] = Mpy_32_32( g2, DFT_PRED_RES[2 * i] ); move32(); - DFT_PRED_RES[2 * i + 1] = Mpy_32_32(g2, DFT_PRED_RES[2 * i + 1]); + DFT_PRED_RES[2 * i + 1] = Mpy_32_32( g2, DFT_PRED_RES[2 * i + 1] ); move32(); } } @@ -2900,16 +2902,16 @@ void stereo_dft_generate_res_pred_fx( } /* update buffers */ - FOR ( b = hStereoDft->res_pred_band_min; b < hStereoDft->nbands; b++ ) + FOR( b = hStereoDft->res_pred_band_min; b < hStereoDft->nbands; b++ ) { - IF ( hStereoDft->attackPresent || hStereoDft->wasTransient ) + IF( hStereoDft->attackPresent || hStereoDft->wasTransient ) { - hStereoDft->past_res_pred_gain_fx[( hStereoDft->past_DMX_pos + 1 ) & (STEREO_DFT_PAST_MAX - 1)][b] = MIN_32; + hStereoDft->past_res_pred_gain_fx[( hStereoDft->past_DMX_pos + 1 ) & ( STEREO_DFT_PAST_MAX - 1 )][b] = MIN_32; move32(); } ELSE { - hStereoDft->past_res_pred_gain_fx[( hStereoDft->past_DMX_pos + 1 ) & (STEREO_DFT_PAST_MAX - 1)][b] = pPredGain[b]; + hStereoDft->past_res_pred_gain_fx[( hStereoDft->past_DMX_pos + 1 ) & ( STEREO_DFT_PAST_MAX - 1 )][b] = pPredGain[b]; move32(); } } @@ -2945,62 +2947,62 @@ static void stereo_dft_adapt_sf_delay_fx( move32(); q_sqrt = 0; move32(); - q_guard = sub(15 , norm_s(hStereoDft->nbands)); + q_guard = sub( 15, norm_s( hStereoDft->nbands ) ); /* find sum and maximum of prediction gains */ - FOR ( b = hStereoDft->res_pred_band_min; b < hStereoDft->nbands; b++ ) + FOR( b = hStereoDft->res_pred_band_min; b < hStereoDft->nbands; b++ ) { - IF ( GT_32(pPredGain[b], max_pg) ) + IF( GT_32( pPredGain[b], max_pg ) ) { max_pg = pPredGain[b]; move16(); } - sum_pg = L_add(sum_pg, L_shr(pPredGain[b], q_guard)); + sum_pg = L_add( sum_pg, L_shr( pPredGain[b], q_guard ) ); } - IF (GT_16(q_guard, hStereoDft->q_lt_pred_gain)) + IF( GT_16( q_guard, hStereoDft->q_lt_pred_gain ) ) { - hStereoDft->lt_pred_gain_fx = L_shr(hStereoDft->lt_pred_gain_fx, sub(q_guard, hStereoDft->q_lt_pred_gain)); + hStereoDft->lt_pred_gain_fx = L_shr( hStereoDft->lt_pred_gain_fx, sub( q_guard, hStereoDft->q_lt_pred_gain ) ); hStereoDft->q_lt_pred_gain = q_guard; } ELSE { - sum_pg = L_shr(sum_pg, sub(hStereoDft->q_lt_pred_gain, q_guard)); + sum_pg = L_shr( sum_pg, sub( hStereoDft->q_lt_pred_gain, q_guard ) ); q_guard = hStereoDft->q_lt_pred_gain; } - IF ( GT_32(sum_pg, 0) ) + IF( GT_32( sum_pg, 0 ) ) { /* Calculate mean of the prediction gain */ - hStereoDft->lt_pred_gain_fx = Madd_32_16(Mpy_32_16_1( sum_pg, STEREO_DFT_LT_PREDGAIN_UPD_FX), hStereoDft->lt_pred_gain_fx, sub( MAX_16, STEREO_DFT_LT_PREDGAIN_UPD_FX )); + hStereoDft->lt_pred_gain_fx = Madd_32_16( Mpy_32_16_1( sum_pg, STEREO_DFT_LT_PREDGAIN_UPD_FX ), hStereoDft->lt_pred_gain_fx, sub( MAX_16, STEREO_DFT_LT_PREDGAIN_UPD_FX ) ); /* Calculate the variation of the prediction gain */ - new_variation = L_abs( L_sub(sum_pg , hStereoDft->lt_pred_gain_fx) ); - hStereoDft->lt_pred_gain_variation_fx = Madd_32_16(Mpy_32_16_1(new_variation , STEREO_DFT_VR_PREDGAIN_UPD_FX) , hStereoDft->lt_pred_gain_variation_fx, sub( MAX_16 , STEREO_DFT_VR_PREDGAIN_UPD_FX )); + new_variation = L_abs( L_sub( sum_pg, hStereoDft->lt_pred_gain_fx ) ); + hStereoDft->lt_pred_gain_variation_fx = Madd_32_16( Mpy_32_16_1( new_variation, STEREO_DFT_VR_PREDGAIN_UPD_FX ), hStereoDft->lt_pred_gain_variation_fx, sub( MAX_16, STEREO_DFT_VR_PREDGAIN_UPD_FX ) ); } /* Calculate ratio of variation and mean of prediction gain */ var_mean_ratio = STEREO_DFT_RES_RATIO_LIMIT_FX; move16(); - IF ( GT_32(hStereoDft->lt_pred_gain_fx, 0) ) + IF( GT_32( hStereoDft->lt_pred_gain_fx, 0 ) ) { - Word32 opr2 = L_deposit_h(BASOP_Util_Divide3232_Scale(hStereoDft->lt_pred_gain_variation_fx , hStereoDft->lt_pred_gain_fx, &q_div)); - IF ( LT_16(q_div, 0) ) + Word32 opr2 = L_deposit_h( BASOP_Util_Divide3232_Scale( hStereoDft->lt_pred_gain_variation_fx, hStereoDft->lt_pred_gain_fx, &q_div ) ); + IF( LT_16( q_div, 0 ) ) { - opr2 = L_shl(opr2, q_div); + opr2 = L_shl( opr2, q_div ); q_div = 0; move16(); } - IF ( LT_32(L_shr(STEREO_DFT_RES_RATIO_LIMIT_FX_3_BY_2, q_div), opr2)) + IF( LT_32( L_shr( STEREO_DFT_RES_RATIO_LIMIT_FX_3_BY_2, q_div ), opr2 ) ) { var_mean_ratio = STEREO_DFT_RES_RATIO_LIMIT_FX_3_BY_2; } ELSE { - var_mean_ratio = L_shl(opr2, q_div); + var_mean_ratio = L_shl( opr2, q_div ); } } - IF ( GT_32(max_pg , STEREO_DFT_STEFFI_PG_THRESHOLD_FX) ) + IF( GT_32( max_pg, STEREO_DFT_STEFFI_PG_THRESHOLD_FX ) ) { /* slow upwards */ alpha_up = STEREO_DFT_STEFFI_RATIO_UP_HIGH_FX; @@ -3017,37 +3019,34 @@ static void stereo_dft_adapt_sf_delay_fx( move16(); } - IF ( GT_16(extract_h(var_mean_ratio) , extract_h(hStereoDft->lt_var_mean_ratio_fx)) ) + IF( GT_16( extract_h( var_mean_ratio ), extract_h( hStereoDft->lt_var_mean_ratio_fx ) ) ) { - hStereoDft->lt_var_mean_ratio_fx = Madd_32_32(Mpy_32_32(var_mean_ratio, alpha_up) , hStereoDft->lt_var_mean_ratio_fx, L_sub( MAX_32 , alpha_up )); + hStereoDft->lt_var_mean_ratio_fx = Madd_32_32( Mpy_32_32( var_mean_ratio, alpha_up ), hStereoDft->lt_var_mean_ratio_fx, L_sub( MAX_32, alpha_up ) ); } ELSE { - hStereoDft->lt_var_mean_ratio_fx = Madd_32_32(Mpy_32_32(var_mean_ratio, alpha_down) , hStereoDft->lt_var_mean_ratio_fx, L_sub( MAX_32 , alpha_down )); + hStereoDft->lt_var_mean_ratio_fx = Madd_32_32( Mpy_32_32( var_mean_ratio, alpha_down ), hStereoDft->lt_var_mean_ratio_fx, L_sub( MAX_32, alpha_down ) ); } /* Calculate a target delay for the stereo filling. Set the stereo filling delay lower when the prediction gain variation is relatively high compared to the mean */ - IF ( GE_16(extract_h(hStereoDft->lt_var_mean_ratio_fx) , extract_h(STEREO_DFT_RES_RATIO_LIMIT_FX)) ) + IF( GE_16( extract_h( hStereoDft->lt_var_mean_ratio_fx ), extract_h( STEREO_DFT_RES_RATIO_LIMIT_FX ) ) ) { - target_delay = L_shl(STEREO_DFT_STEFFI_DELAY_SHORT, Q15); + target_delay = L_shl( STEREO_DFT_STEFFI_DELAY_SHORT, Q15 ); move32(); } ELSE { - target_delay = L_min( L_shl(STEREO_DFT_STEFFI_DELAY_LONG, Q15), - L_add(L_shl(STEREO_DFT_STEFFI_DELAY_SHORT, Q15) , - L_mult0(( STEREO_DFT_STEFFI_DELAY_OFFSET + STEREO_DFT_STEFFI_DELAY_LONG - STEREO_DFT_STEFFI_DELAY_SHORT ) , - sub( MAX_16 , extract_h(L_shl(Mpy_32_16_1(hStereoDft->lt_var_mean_ratio_fx , ONE_STEREO_DFT_RES_RATIO_LIMIT_Q12), Q3))) - ) - ) - ); + target_delay = L_min( L_shl( STEREO_DFT_STEFFI_DELAY_LONG, Q15 ), + L_add( L_shl( STEREO_DFT_STEFFI_DELAY_SHORT, Q15 ), + L_mult0( ( STEREO_DFT_STEFFI_DELAY_OFFSET + STEREO_DFT_STEFFI_DELAY_LONG - STEREO_DFT_STEFFI_DELAY_SHORT ), + sub( MAX_16, extract_h( L_shl( Mpy_32_16_1( hStereoDft->lt_var_mean_ratio_fx, ONE_STEREO_DFT_RES_RATIO_LIMIT_Q12 ), Q3 ) ) ) ) ) ); } /* Adapt the stereo filling delay by interpolating between two delay taps, one at the shortest delay and one at the longest delay */ - hStereoDft->stefi_short_gain_fx = extract_l(L_shr(L_sub(L_shl(STEREO_DFT_STEFFI_DELAY_LONG, Q15), target_delay), 1)); + hStereoDft->stefi_short_gain_fx = extract_l( L_shr( L_sub( L_shl( STEREO_DFT_STEFFI_DELAY_LONG, Q15 ), target_delay ), 1 ) ); q_sqrt = 0; - IF (hStereoDft->stefi_short_gain_fx == MIN_16) + IF( hStereoDft->stefi_short_gain_fx == MIN_16 ) { hStereoDft->stefi_short_gain_fx = MAX_16; hStereoDft->stefi_long_gain_fx = 0; @@ -3055,10 +3054,10 @@ static void stereo_dft_adapt_sf_delay_fx( ELSE { op = hStereoDft->stefi_short_gain_fx; - hStereoDft->stefi_long_gain_fx = Sqrt16( sub(MAX_16 , mult(op, op)), &q_sqrt); - IF (NE_16(q_sqrt, 0)) + hStereoDft->stefi_long_gain_fx = Sqrt16( sub( MAX_16, mult( op, op ) ), &q_sqrt ); + IF( NE_16( q_sqrt, 0 ) ) { - hStereoDft->stefi_long_gain_fx = shl(hStereoDft->stefi_long_gain_fx, q_sqrt); + hStereoDft->stefi_long_gain_fx = shl( hStereoDft->stefi_long_gain_fx, q_sqrt ); } } @@ -3207,17 +3206,17 @@ void stereo_dft_dequantize_itd_fx( *-------------------------------------------------------------------------*/ void stereo_dft_dec_read_BS_fx( - const Word32 ivas_total_brate, /* i : IVAS total bitrate */ - const Word32 element_brate, /* i : element bitrate */ - Word32 *total_brate, /* o : total bitrate */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + const Word32 element_brate, /* i : element bitrate */ + Word32 *total_brate, /* o : total bitrate */ Decoder_State *st, /* i/o: decoder state structure */ STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder stereo handle */ - const Word16 bwidth, /* i : bandwidth */ - const Word16 output_frame, /* i : output frame length */ - Word32 res_buf_fx[STEREO_DFT_N_8k], /* o : residual buffer */ - Word16 *nb_bits, /* o : number of bits read */ - Word16 *coh_fx, /* i/o: Coherence */ - const Word16 ivas_format /* i : ivas format */ + const Word16 bwidth, /* i : bandwidth */ + const Word16 output_frame, /* i : output frame length */ + Word32 res_buf_fx[STEREO_DFT_N_8k], /* o : residual buffer */ + Word16 *nb_bits, /* o : number of bits read */ + Word16 *coh_fx, /* i/o: Coherence */ + const Word16 ivas_format /* i : ivas format */ ) { Word32 sg_tmp_fx[STEREO_DFT_BAND_MAX]; @@ -3294,7 +3293,7 @@ void stereo_dft_dec_read_BS_fx( move16(); move16(); - st->total_brate = L_mult0( *nb_bits, FRAMES_PER_SEC); + st->total_brate = L_mult0( *nb_bits, FRAMES_PER_SEC ); } hStereoDft->reverb_flag = 0; @@ -3383,8 +3382,8 @@ void stereo_dft_dec_read_BS_fx( hStereoDft->res_cod_band_max = dft_band_res_cod[hStereoDft->band_res[k_offset]][hStereoDft->res_cod_mode[k_offset]]; move16(); - hStereoDft->res_cod_line_max = (Word16) L_shr( ( ( 1 << Q13 )/*0.5f Q-14*/ + L_shl( L_mult0( sub( hStereoDft->band_limits[hStereoDft->res_cod_band_max], 1 ), divide1616( shr( output_frame, 1 ), ( hStereoDft->NFFT ) ) ) /*Q-14*/, 1 ) ), Q14 ); - hStereoDft->res_cod_line_max = shl(shr( hStereoDft->res_cod_line_max , 3 ),3); + hStereoDft->res_cod_line_max = (Word16) L_shr( ( ( 1 << Q13 ) /*0.5f Q-14*/ + L_shl( L_mult0( sub( hStereoDft->band_limits[hStereoDft->res_cod_band_max], 1 ), divide1616( shr( output_frame, 1 ), ( hStereoDft->NFFT ) ) ) /*Q-14*/, 1 ) ), Q14 ); + hStereoDft->res_cod_line_max = shl( shr( hStereoDft->res_cod_line_max, 3 ), 3 ); hStereoDft->res_pred_band_min = s_max( STEREO_DFT_RES_PRED_BAND_MIN, hStereoDft->res_cod_band_max ); @@ -3688,7 +3687,7 @@ void stereo_dft_dec_read_BS_fx( IF( GT_32( ivas_total_brate, IVAS_SID_5k2 ) ) { - //hStereoDft->recovery_flg = stereo_dft_sg_recovery( hStereoDft ); + // hStereoDft->recovery_flg = stereo_dft_sg_recovery( hStereoDft ); hStereoDft->recovery_flg = stereo_dft_sg_recovery_fx( hStereoDft ); IF( hStereoDft->recovery_flg ) diff --git a/lib_dec/ivas_stereo_dft_plc_fx.c b/lib_dec/ivas_stereo_dft_plc_fx.c index 255066ea3..3023b40e9 100644 --- a/lib_dec/ivas_stereo_dft_plc_fx.c +++ b/lib_dec/ivas_stereo_dft_plc_fx.c @@ -47,10 +47,10 @@ * Local constants * ---------------------------------------------------------------*/ -#define ZP8k 15 /* zero padding in 8kHz DFT analysis */ -#define OFFSET8k 55 /* offset in 8 kHz */ -#define STEREO_DFT_PLC_STEP21 ( L_FRAME8k - OFFSET8k ) /* Step from subframe 2 in frame n to subframe 1 in frame n+1 */ -#define STEREO_DFT_PLC_PH_C_FX (Word16)( 0x0A8D ) /* Phase estimation constant, for estimating phase of fractional frequency */ +#define ZP8k 15 /* zero padding in 8kHz DFT analysis */ +#define OFFSET8k 55 /* offset in 8 kHz */ +#define STEREO_DFT_PLC_STEP21 ( L_FRAME8k - OFFSET8k ) /* Step from subframe 2 in frame n to subframe 1 in frame n+1 */ +#define STEREO_DFT_PLC_PH_C_FX ( Word16 )( 0x0A8D ) /* Phase estimation constant, for estimating phase of fractional frequency */ #ifdef IVAS_FLOAT_FIXED @@ -516,7 +516,7 @@ void stereo_dft_res_subst_spec_fx( ) { Word16 i, idx; - //Word16 fac; + // Word16 fac; Word32 s1, s2, abs1, abs2, abs3, abs4; Word32 abs_res[( STEREO_DFT_RES_BW_MAX ) / 2]; Word32 Xmax, Xmin; @@ -588,7 +588,7 @@ void stereo_dft_res_subst_spec_fx( abs3 = L_abs( p_mem[2 * i] ); abs4 = L_abs( p_mem[2 * i + 1] ); - //fac = MAX_16; + // fac = MAX_16; move16(); /* Low-complex phase matching that brings the angle within pi/4 of the target angle */ test(); @@ -802,4 +802,4 @@ Word16 stereo_dft_sg_recovery_fx( return 0; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/ivas_stereo_ica_dec.c b/lib_dec/ivas_stereo_ica_dec.c index fb98f4a51..804a5a68f 100644 --- a/lib_dec/ivas_stereo_ica_dec.c +++ b/lib_dec/ivas_stereo_ica_dec.c @@ -297,201 +297,201 @@ void stereo_tca_dec_fx( } #else void stereo_tca_dec( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - float *synth[CPE_CHANNELS], /* i/o: output synth */ - const int16_t output_frame /* i : length of a frame per channel */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + float *synth[CPE_CHANNELS], /* i/o: output synth */ + const int16_t output_frame /* i : length of a frame per channel */ ) { - /* Buffers, input Left and right channels @ input_Fs*/ - float bufChanL[L_DEC_MEM_LEN_ICA + L_FRAME48k]; - float bufChanR[L_DEC_MEM_LEN_ICA + L_FRAME48k]; - float *ptrChanL, *ptrChanR; - float *target; - int16_t target_idx, prevNCShift, currentNCShift, l_shift_adapt; - int16_t dsFactor, tempMax; - float *ref; - int16_t bothChannelShift; - int32_t output_Fs; - STEREO_TCA_DEC_HANDLE hStereoTCA; + /* Buffers, input Left and right channels @ input_Fs*/ + float bufChanL[L_DEC_MEM_LEN_ICA + L_FRAME48k]; + float bufChanR[L_DEC_MEM_LEN_ICA + L_FRAME48k]; + float *ptrChanL, *ptrChanR; + float *target; + int16_t target_idx, prevNCShift, currentNCShift, l_shift_adapt; + int16_t dsFactor, tempMax; + float *ref; + int16_t bothChannelShift; + int32_t output_Fs; + STEREO_TCA_DEC_HANDLE hStereoTCA; - hStereoTCA = hCPE->hStereoTCA; + hStereoTCA = hCPE->hStereoTCA; - output_Fs = hCPE->hCoreCoder[0]->output_Fs; + output_Fs = hCPE->hCoreCoder[0]->output_Fs; - if (hCPE->nchan_out == 1) - { - if (hCPE->hStereoDftDmx) + if ( hCPE->nchan_out == 1 ) { - if (hCPE->element_mode == IVAS_CPE_DFT) - { - hCPE->hStereoDftDmx->targetGain = 1.0f; - } + if ( hCPE->hStereoDftDmx ) + { + if ( hCPE->element_mode == IVAS_CPE_DFT ) + { + hCPE->hStereoDftDmx->targetGain = 1.0f; + } - /* save the target gain for next frame */ - hCPE->hStereoDftDmx->prevTargetGain = hCPE->hStereoDftDmx->targetGain; + /* save the target gain for next frame */ + hCPE->hStereoDftDmx->prevTargetGain = hCPE->hStereoDftDmx->targetGain; + } + + return; + } + else if ( hCPE->element_mode == IVAS_CPE_MDCT && !hCPE->hStereoMdct->use_itd ) + { + return; } - return; - } - else if (hCPE->element_mode == IVAS_CPE_MDCT && !hCPE->hStereoMdct->use_itd) - { - return; - } + /* populate L/R memories into current buffers */ + mvr2r( hStereoTCA->memChanL, bufChanL, L_DEC_MEM_LEN_ICA ); + mvr2r( hStereoTCA->memChanR, bufChanR, L_DEC_MEM_LEN_ICA ); - /* populate L/R memories into current buffers */ - mvr2r(hStereoTCA->memChanL, bufChanL, L_DEC_MEM_LEN_ICA); - mvr2r(hStereoTCA->memChanR, bufChanR, L_DEC_MEM_LEN_ICA); + /* pointers to the current frame */ + ptrChanL = bufChanL + L_DEC_MEM_LEN_ICA; + ptrChanR = bufChanR + L_DEC_MEM_LEN_ICA; - /* pointers to the current frame */ - ptrChanL = bufChanL + L_DEC_MEM_LEN_ICA; - ptrChanR = bufChanR + L_DEC_MEM_LEN_ICA; + /* copy interleaved stereo data to two channels, e.g., L, R */ + mvr2r( synth[0], ptrChanL, output_frame ); + mvr2r( synth[1], ptrChanR, output_frame ); - /* copy interleaved stereo data to two channels, e.g., L, R */ - mvr2r(synth[0], ptrChanL, output_frame); - mvr2r(synth[1], ptrChanR, output_frame); + /* back up the L/R target synth for next frame */ + mvr2r( bufChanL + output_frame, hStereoTCA->memChanL, L_DEC_MEM_LEN_ICA ); + mvr2r( bufChanR + output_frame, hStereoTCA->memChanR, L_DEC_MEM_LEN_ICA ); - /* back up the L/R target synth for next frame */ - mvr2r(bufChanL + output_frame, hStereoTCA->memChanL, L_DEC_MEM_LEN_ICA); - mvr2r(bufChanR + output_frame, hStereoTCA->memChanR, L_DEC_MEM_LEN_ICA); + /* TCA parameter de-quantize */ + dsFactor = (int16_t) ( output_Fs / 8000 ); + tempMax = NS2SA( output_Fs, L_NCSHIFT_NS ); + hStereoTCA->corrLagStats = min( hStereoTCA->indx_ica_NCShift * dsFactor, tempMax ); - /* TCA parameter de-quantize */ - dsFactor = (int16_t)(output_Fs / 8000); - tempMax = NS2SA(output_Fs, L_NCSHIFT_NS); - hStereoTCA->corrLagStats = min(hStereoTCA->indx_ica_NCShift * dsFactor, tempMax); + bothChannelShift = 0; + if ( hCPE->element_mode == IVAS_CPE_DFT || hCPE->element_mode == IVAS_CPE_MDCT ) + { + hStereoTCA->corrLagStats = 0; + hStereoTCA->refChanIndx = L_CH_INDX; + hStereoTCA->targetGain = 1.0f; - bothChannelShift = 0; - if (hCPE->element_mode == IVAS_CPE_DFT || hCPE->element_mode == IVAS_CPE_MDCT) - { - hStereoTCA->corrLagStats = 0; - hStereoTCA->refChanIndx = L_CH_INDX; - hStereoTCA->targetGain = 1.0f; + if ( hCPE->element_mode == IVAS_CPE_DFT ) + { + hStereoTCA->corrLagStats = (int16_t) fabsf( hCPE->hStereoDft->itd[1] ); + hStereoTCA->refChanIndx = ( hCPE->hStereoDft->itd[1] >= 0 ) ? ( L_CH_INDX ) : ( R_CH_INDX ); + } + else if ( hCPE->element_mode == IVAS_CPE_MDCT ) + { + float itd; - if (hCPE->element_mode == IVAS_CPE_DFT) - { - hStereoTCA->corrLagStats = (int16_t)fabsf(hCPE->hStereoDft->itd[1]); - hStereoTCA->refChanIndx = (hCPE->hStereoDft->itd[1] >= 0) ? (L_CH_INDX) : (R_CH_INDX); - } - else if (hCPE->element_mode == IVAS_CPE_MDCT) - { - float itd; + itd = hCPE->hStereoMdct->itd; + hStereoTCA->corrLagStats = (int16_t) fabsf( itd ); + hStereoTCA->refChanIndx = ( itd >= 0 ) ? ( L_CH_INDX ) : ( R_CH_INDX ); + } - itd = hCPE->hStereoMdct->itd; - hStereoTCA->corrLagStats = (int16_t)fabsf(itd); - hStereoTCA->refChanIndx = (itd >= 0) ? (L_CH_INDX) : (R_CH_INDX); + if ( hStereoTCA->refChanIndx != hStereoTCA->prevRefChanIndx && hStereoTCA->corrLagStats != 0 ) + { + bothChannelShift = 1; + } } - if (hStereoTCA->refChanIndx != hStereoTCA->prevRefChanIndx && hStereoTCA->corrLagStats != 0) + prevNCShift = (int16_t) abs( hStereoTCA->prevCorrLagStats ); + currentNCShift = (int16_t) abs( hStereoTCA->corrLagStats ); + + if ( hCPE->element_mode == IVAS_CPE_TD && hCPE->last_element_mode == IVAS_CPE_TD ) { - bothChannelShift = 1; - } - } + if ( hStereoTCA->corrLagStats == hStereoTCA->prevCorrLagStats && hStereoTCA->interp_dec_switch_to_zero_diff == 0 ) + { + hStereoTCA->interp_dec_switch_to_zero_diff = 1; + } + else + { + hStereoTCA->interp_dec_switch_to_zero_diff = 0; + } - prevNCShift = (int16_t)abs(hStereoTCA->prevCorrLagStats); - currentNCShift = (int16_t)abs(hStereoTCA->corrLagStats); + if ( currentNCShift != 0 ) + { + currentNCShift = TRUNC( 0.6 * prevNCShift + 0.4 * currentNCShift ); + } - if (hCPE->element_mode == IVAS_CPE_TD && hCPE->last_element_mode == IVAS_CPE_TD) - { - if (hStereoTCA->corrLagStats == hStereoTCA->prevCorrLagStats && hStereoTCA->interp_dec_switch_to_zero_diff == 0) - { - hStereoTCA->interp_dec_switch_to_zero_diff = 1; + prevNCShift = hStereoTCA->interp_dec_prevNCShift; + hStereoTCA->interp_dec_prevNCShift = currentNCShift; } else { - hStereoTCA->interp_dec_switch_to_zero_diff = 0; - } - - if (currentNCShift != 0) - { - currentNCShift = TRUNC(0.6 * prevNCShift + 0.4 * currentNCShift); + hStereoTCA->interp_dec_prevNCShift = currentNCShift; + hStereoTCA->interp_dec_switch_to_zero_diff = 0; } - prevNCShift = hStereoTCA->interp_dec_prevNCShift; - hStereoTCA->interp_dec_prevNCShift = currentNCShift; - } - else - { - hStereoTCA->interp_dec_prevNCShift = currentNCShift; - hStereoTCA->interp_dec_switch_to_zero_diff = 0; - } - - ref = ptrChanL; - target = ptrChanR; - target_idx = R_CH_INDX; - /* identify target signal to adjust for shift variations */ - if ((prevNCShift == 0 && hStereoTCA->refChanIndx == R_CH_INDX) || (hStereoTCA->prevRefChanIndx == R_CH_INDX)) - { - ref = ptrChanR; - target = ptrChanL; - target_idx = L_CH_INDX; - } - - if (bothChannelShift == 1) - { ref = ptrChanL; target = ptrChanR; target_idx = R_CH_INDX; - if (hStereoTCA->refChanIndx == R_CH_INDX) + /* identify target signal to adjust for shift variations */ + if ( ( prevNCShift == 0 && hStereoTCA->refChanIndx == R_CH_INDX ) || ( hStereoTCA->prevRefChanIndx == R_CH_INDX ) ) { - ref = ptrChanR; - target = ptrChanL; - target_idx = L_CH_INDX; + ref = ptrChanR; + target = ptrChanL; + target_idx = L_CH_INDX; } - } - /* target signal adjustment for temporal shift variations */ - if (hStereoTCA->prevCorrLagStats != hStereoTCA->corrLagStats || bothChannelShift || (hStereoTCA->interp_dec_switch_to_zero_diff == 1 && hCPE->element_mode == IVAS_CPE_TD)) - { - l_shift_adapt = L_SHIFT_ADAPT_16k; - if (output_Fs > 16000) + if ( bothChannelShift == 1 ) { - l_shift_adapt = L_SHIFT_ADAPT_MAX; + ref = ptrChanL; + target = ptrChanR; + target_idx = R_CH_INDX; + if ( hStereoTCA->refChanIndx == R_CH_INDX ) + { + ref = ptrChanR; + target = ptrChanL; + target_idx = L_CH_INDX; + } } - if (hCPE->element_mode == IVAS_CPE_TD && hCPE->last_element_mode == IVAS_CPE_DFT) + /* target signal adjustment for temporal shift variations */ + if ( hStereoTCA->prevCorrLagStats != hStereoTCA->corrLagStats || bothChannelShift || ( hStereoTCA->interp_dec_switch_to_zero_diff == 1 && hCPE->element_mode == IVAS_CPE_TD ) ) { - l_shift_adapt = l_shift_adapt >> 1; - } + l_shift_adapt = L_SHIFT_ADAPT_16k; + if ( output_Fs > 16000 ) + { + l_shift_adapt = L_SHIFT_ADAPT_MAX; + } - if (abs(currentNCShift - prevNCShift) <= N_MAX_SHIFT_CHANGE && bothChannelShift == 0) - { - adjustTargetSignal(target - currentNCShift, currentNCShift, prevNCShift, l_shift_adapt, 0); - } - else - { - if (bothChannelShift == 1) - { - adjustTargetSignal(ref, 0, prevNCShift, l_shift_adapt, 1); - adjustTargetSignal(target - currentNCShift, currentNCShift, 0, l_shift_adapt, 1); - } - else - { - adjustTargetSignal(target - currentNCShift, currentNCShift, prevNCShift, l_shift_adapt, 1); - } + if ( hCPE->element_mode == IVAS_CPE_TD && hCPE->last_element_mode == IVAS_CPE_DFT ) + { + l_shift_adapt = l_shift_adapt >> 1; + } + + if ( abs( currentNCShift - prevNCShift ) <= N_MAX_SHIFT_CHANGE && bothChannelShift == 0 ) + { + adjustTargetSignal( target - currentNCShift, currentNCShift, prevNCShift, l_shift_adapt, 0 ); + } + else + { + if ( bothChannelShift == 1 ) + { + adjustTargetSignal( ref, 0, prevNCShift, l_shift_adapt, 1 ); + adjustTargetSignal( target - currentNCShift, currentNCShift, 0, l_shift_adapt, 1 ); + } + else + { + adjustTargetSignal( target - currentNCShift, currentNCShift, prevNCShift, l_shift_adapt, 1 ); + } + } } - } - /* temporal channel adjustment */ - mvr2r(target - currentNCShift, synth[target_idx], output_frame); + /* temporal channel adjustment */ + mvr2r( target - currentNCShift, synth[target_idx], output_frame ); - mvr2r(ref, synth[!target_idx], output_frame); + mvr2r( ref, synth[!target_idx], output_frame ); - /* Scale the Right channel with the gain */ - stereo_tca_scale_R_channel(hCPE, synth[1], output_frame); + /* Scale the Right channel with the gain */ + stereo_tca_scale_R_channel( hCPE, synth[1], output_frame ); - /*-----------------------------------------------------------------* - * updates and memory backups - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * updates and memory backups + *-----------------------------------------------------------------*/ - /* save the reference channel index for next frame */ - hStereoTCA->prevRefChanIndx = hStereoTCA->refChanIndx; + /* save the reference channel index for next frame */ + hStereoTCA->prevRefChanIndx = hStereoTCA->refChanIndx; - /* save the corr lag stats for next frame */ - hStereoTCA->prevCorrLagStats = hStereoTCA->corrLagStats; + /* save the corr lag stats for next frame */ + hStereoTCA->prevCorrLagStats = hStereoTCA->corrLagStats; - /* save the target gain for next frame */ - hStereoTCA->prevTargetGain = hStereoTCA->targetGain; + /* save the target gain for next frame */ + hStereoTCA->prevTargetGain = hStereoTCA->targetGain; - return; + return; } #endif /*-------------------------------------------------------------------* @@ -779,7 +779,6 @@ void stereo_tca_scale_R_channel_fx( *-------------------------------------------------------------------*/ - #ifdef IVAS_FLOAT_FIXED void stereo_tca_init_dec_fx( STEREO_TCA_DEC_HANDLE hStereoTCA /* i/o: Stereo TCA handle */ @@ -815,25 +814,25 @@ void stereo_tca_init_dec_fx( } #else void stereo_tca_init_dec( - STEREO_TCA_DEC_HANDLE hStereoTCA /* i/o: Stereo TCA handle */ + STEREO_TCA_DEC_HANDLE hStereoTCA /* i/o: Stereo TCA handle */ ) { - hStereoTCA->refChanIndx = L_CH_INDX; - hStereoTCA->prevRefChanIndx = L_CH_INDX; - hStereoTCA->indx_ica_NCShift = 0; - hStereoTCA->indx_ica_gD = 0; - hStereoTCA->targetGain = 1.0f; - hStereoTCA->prevTargetGain = 1.0f; + hStereoTCA->refChanIndx = L_CH_INDX; + hStereoTCA->prevRefChanIndx = L_CH_INDX; + hStereoTCA->indx_ica_NCShift = 0; + hStereoTCA->indx_ica_gD = 0; + hStereoTCA->targetGain = 1.0f; + hStereoTCA->prevTargetGain = 1.0f; - hStereoTCA->corrLagStats = 0; - hStereoTCA->prevCorrLagStats = 0; + hStereoTCA->corrLagStats = 0; + hStereoTCA->prevCorrLagStats = 0; - hStereoTCA->interp_dec_prevNCShift = 0; - hStereoTCA->interp_dec_switch_to_zero_diff = 0; + hStereoTCA->interp_dec_prevNCShift = 0; + hStereoTCA->interp_dec_switch_to_zero_diff = 0; - set_f(hStereoTCA->memChanL, 0.0f, L_DEC_MEM_LEN_ICA); - set_f(hStereoTCA->memChanR, 0.0f, L_DEC_MEM_LEN_ICA); + set_f( hStereoTCA->memChanL, 0.0f, L_DEC_MEM_LEN_ICA ); + set_f( hStereoTCA->memChanR, 0.0f, L_DEC_MEM_LEN_ICA ); - return; + return; } #endif diff --git a/lib_dec/ivas_stereo_icbwe_dec.c b/lib_dec/ivas_stereo_icbwe_dec.c index 39ae1386f..199647063 100644 --- a/lib_dec/ivas_stereo_icbwe_dec.c +++ b/lib_dec/ivas_stereo_icbwe_dec.c @@ -646,7 +646,7 @@ void stereo_icBWE_dec_fx( hCPE->hStereoDft->hb_nrg_subr_fx[0] = hb_nrg2_fx; move32(); - hStereoDft->q_hb_nrg_subr = sub(add(*Q_syn, synthRef_shift), 31); + hStereoDft->q_hb_nrg_subr = sub( add( *Q_syn, synthRef_shift ), 31 ); hb_nrg_fx = L_add( hb_nrg_fx, hb_nrg2_fx ); hb_nrg2_fx = 0; move32(); @@ -663,7 +663,7 @@ void stereo_icBWE_dec_fx( Copy32( synthRef_fx, hCPE->hStereoDft->hb_stefi_sig_fx + hCPE->hStereoDft->hb_stefi_delay, output_frame ); - Scale_sig32(hCPE->hStereoDft->hb_stefi_sig_fx + hCPE->hStereoDft->hb_stefi_delay, output_frame, -5); + Scale_sig32( hCPE->hStereoDft->hb_stefi_sig_fx + hCPE->hStereoDft->hb_stefi_delay, output_frame, -5 ); } ELSE { @@ -924,7 +924,7 @@ void stereo_icBWE_dec_fx( #ifndef FIX_736_BWE_SECT_C L_mixExc16k = L_shl( L_mixExc16k, Q_icBWE - st->Q_exc ); // Q_icBWE #else - L_mixExc16k = L_shl( L_mixExc16k, Q_icBWE - ( st->prev_Q_bwe_exc - 25 ) ); // Q_icBWE + L_mixExc16k = L_shl( L_mixExc16k, Q_icBWE - ( st->prev_Q_bwe_exc - 25 ) ); // Q_icBWE #endif excSHB_nonref_fx[k] = L_add( Mpy_32_16_1( L_nlExc16k, temp1_fx ), Mpy_32_16_1( L_mixExc16k, temp2_fx ) ); // Q_icBWE move32(); @@ -1159,7 +1159,7 @@ void stereo_icBWE_dec_fx( #ifdef FIX_TMP_714 tmp = mult_r( ratio_L_fx, ratio_L_fx ); // Q15 #else - tmp = mult_r( sub( 32767, ratio_L_fx ), sub( 32767, ratio_L_fx ) ); // Q15 + tmp = mult_r( sub( 32767, ratio_L_fx ), sub( 32767, ratio_L_fx ) ); // Q15 #endif tmp = mult_r( tmp, gsMapping_fx ); // Q14 tmp = mult_r( tmp, gsMapping_fx ); // Q13 @@ -1322,7 +1322,7 @@ void stereo_icBWE_dec_fx( #ifdef FIX_TMP_714 tmp = mult_r( ratio_L_fx, ratio_L_fx ); // Q15 #else - tmp = mult_r( sub( 32767, ratio_L_fx ), sub( 32767, ratio_L_fx ) ); // Q15 + tmp = mult_r( sub( 32767, ratio_L_fx ), sub( 32767, ratio_L_fx ) ); // Q15 #endif tmp = mult_r( tmp, gsMapping_fx ); // Q14 tmp = mult_r( tmp, gsMapping_fx ); // Q13 @@ -2032,24 +2032,24 @@ void stereo_icBWE_decproc_fx( dftOvlLen = hCPE->hStereoDft->dft32ms_ovl; move16(); - //Scale_sig32(hCPE->hStereoDft->td_gain_fx, STEREO_DFT_CORE_HIST_MAX, -12); + // Scale_sig32(hCPE->hStereoDft->td_gain_fx, STEREO_DFT_CORE_HIST_MAX, -12); FOR( i = 0; i < dftOvlLen; i++ ) { win_in_fx = L_mult( win_dft_fx[mult0( STEREO_DFT32MS_STEP, i )], win_dft_fx[mult0( STEREO_DFT32MS_STEP, i )] ); /* Q31 */ win_out_fx = L_sub( ONE_IN_Q31, win_in_fx ); /* Q31 */ - gain0_fx = Mpy_32_32( win_in_fx, hCPE->hStereoDft->td_gain_fx[0] ); /* Q --> q_td_gain[0] */ + gain0_fx = Mpy_32_32( win_in_fx, hCPE->hStereoDft->td_gain_fx[0] ); /* Q --> q_td_gain[0] */ #ifdef FIX_736_BWE_SECT_C gain0_fx = (Word32) W_shr( ( (Word64) gain0_fx * hCPE->hStereoDft->hb_stefi_sig_fx[i] ), sub( add( (Word16) hCPE->hStereoDft->q_td_gain[0], hCPE->hStereoDft->q_hb_stefi_sig_fx ), 2 * q_output + 14 ) ); /* Q --> q_output */ - gain1_fx = Mpy_32_32( win_out_fx, hCPE->hStereoDft->td_gain_fx[1] ); /* Q --> q_td_gain[1] */ + gain1_fx = Mpy_32_32( win_out_fx, hCPE->hStereoDft->td_gain_fx[1] ); /* Q --> q_td_gain[1] */ gain1_fx = (Word32) W_shr( ( (Word64) gain1_fx * hCPE->hStereoDft->hb_stefi_sig_fx[i] ), sub( add( (Word16) hCPE->hStereoDft->q_td_gain[1], hCPE->hStereoDft->q_hb_stefi_sig_fx ), 2 * q_output + 14 ) ); /* Q --> q_output */ #else - gain0_fx = (Word32) W_shr( ( (Word64) gain0_fx * hCPE->hStereoDft->hb_stefi_sig_fx[i] ), sub( add( (Word16) hCPE->hStereoDft->q_td_gain[0], hCPE->hStereoDft->q_hb_stefi_sig_fx ), q_output ) ); /* Q --> q_output */ - gain1_fx = Mpy_32_32( win_out_fx, hCPE->hStereoDft->td_gain_fx[1] ); /* Q --> q_td_gain[1] */ - gain1_fx = (Word32) W_shr( ( (Word64) gain1_fx * hCPE->hStereoDft->hb_stefi_sig_fx[i] ), sub( add( (Word16) hCPE->hStereoDft->q_td_gain[1], hCPE->hStereoDft->q_hb_stefi_sig_fx ), q_output ) ); /* Q --> q_output */ + gain0_fx = (Word32) W_shr( ( (Word64) gain0_fx * hCPE->hStereoDft->hb_stefi_sig_fx[i] ), sub( add( (Word16) hCPE->hStereoDft->q_td_gain[0], hCPE->hStereoDft->q_hb_stefi_sig_fx ), q_output ) ); /* Q --> q_output */ + gain1_fx = Mpy_32_32( win_out_fx, hCPE->hStereoDft->td_gain_fx[1] ); /* Q --> q_td_gain[1] */ + gain1_fx = (Word32) W_shr( ( (Word64) gain1_fx * hCPE->hStereoDft->hb_stefi_sig_fx[i] ), sub( add( (Word16) hCPE->hStereoDft->q_td_gain[1], hCPE->hStereoDft->q_hb_stefi_sig_fx ), q_output ) ); /* Q --> q_output */ #endif - tmp_fx = L_add_sat( gain0_fx, gain1_fx ); /* Q --> q_output */ + tmp_fx = L_add_sat( gain0_fx, gain1_fx ); /* Q --> q_output */ output[0][i] = L_add_sat( output[0][i], tmp_fx ); move32(); @@ -2147,4 +2147,4 @@ void stereo_icBWE_init_dec_fx( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/ivas_stereo_mdct_core_dec.c b/lib_dec/ivas_stereo_mdct_core_dec.c index dbe9f4f95..3248c9323 100644 --- a/lib_dec/ivas_stereo_mdct_core_dec.c +++ b/lib_dec/ivas_stereo_mdct_core_dec.c @@ -417,7 +417,7 @@ void stereo_mdct_core_dec( f2me_16( sns_int_scf[j], &scf_fx[j], &scf_e[j] ); } TonalMDCTConceal_SaveFreqSignal_ivas_fx( st->hTonalMDCTConc, x_fx_, x_e, L_frameTCX[ch], L_frame[ch], &scf_fx[0], scf_e, 0, get_igf_startline( st, L_frame[ch], L_frameTCX[ch] ) ); - //st->hTonalMDCTConc->last_block_nrg_flt = me2f( st->hTonalMDCTConc->last_block_nrg, st->hTonalMDCTConc->last_block_nrg_exp ); + // st->hTonalMDCTConc->last_block_nrg_flt = me2f( st->hTonalMDCTConc->last_block_nrg, st->hTonalMDCTConc->last_block_nrg_exp ); #else TonalMDCTConceal_SaveFreqSignal_ivas( st->hTonalMDCTConc, x[ch][k], L_frameTCX[ch], L_frame[ch], &sns_int_scf[0], get_igf_startline_flt( st, L_frame[ch], L_frameTCX[ch] ) ); #endif @@ -439,30 +439,35 @@ void stereo_mdct_core_dec( #ifdef IVAS_FLOAT_FIXED1 Word32 Aq_fx[2][102]; Word16 x_e[2][2]; - FOR(Word16 ind = 0; ind < 2; ind++) { - FOR(Word16 ind2 = 0; ind2 < 102; ind2++) { - Aq_fx[ind][ind2] = (Word32)(Aq[ind][ind2] * (ONE_IN_Q16)); + FOR( Word16 ind = 0; ind < 2; ind++ ) + { + FOR( Word16 ind2 = 0; ind2 < 102; ind2++ ) + { + Aq_fx[ind][ind2] = (Word32) ( Aq[ind][ind2] * ( ONE_IN_Q16 ) ); } - FOR(Word16 ind2 = 0; ind2 < 2; ind2++) { + FOR( Word16 ind2 = 0; ind2 < 2; ind2++ ) + { f2me_buf( x[ind][ind2], x_fx[ind][ind2], &x_e[ind][ind2], L_frameTCX[ind] ); } } - st->hTcxDec->cummulative_damping_tcx = (Word16)(st->hTcxDec->cummulative_damping_tcx * (ONE_IN_Q15)); - FOR(Word16 ind = 0; ind < st->hTonalMDCTConc->nScaleFactors; ind++) { + st->hTcxDec->cummulative_damping_tcx = (Word16) ( st->hTcxDec->cummulative_damping_tcx * ( ONE_IN_Q15 ) ); + FOR( Word16 ind = 0; ind < st->hTonalMDCTConc->nScaleFactors; ind++ ) + { f2me_16( st->hTonalMDCTConc->lastBlockData.scaleFactors_float[ind], &st->hTonalMDCTConc->lastBlockData.scaleFactors[ind], &st->hTonalMDCTConc->lastBlockData.scaleFactors_exp[ind] ); } - FOR(Word16 ind = 0; ind < st->hTonalMDCTConc->nScaleFactors; ind++) { + FOR( Word16 ind = 0; ind < st->hTonalMDCTConc->nScaleFactors; ind++ ) + { f2me_16( st->hTonalMDCTConc->lastBlockData.scaleFactors_float[ind], &st->hTonalMDCTConc->lastBlockData.scaleFactors[ind], &st->hTonalMDCTConc->lastBlockData.scaleFactors_exp[ind] ); } FOR( Word16 i = 0; i < st->hTonalMDCTConc->nScaleFactors; i++ ) { st->hTonalMDCTConc->scaleFactorsBackground[i] = float_to_fix16( st->hTonalMDCTConc->scaleFactorsBackground_flt[i], 15 ); } - st->hTonalMDCTConc->scf_fadeout = float_to_fix16(st->hTonalMDCTConc->scf_fadeout_flt, 15); - st->old_fpitch = float_to_fix(st->old_fpitch_float, 16); - st->hTcxDec->tcxltp_last_gain_unmodified = float_to_fix16(st->hTcxDec->tcxltp_last_gain_unmodified_float, 15); + st->hTonalMDCTConc->scf_fadeout = float_to_fix16( st->hTonalMDCTConc->scf_fadeout_flt, 15 ); + st->old_fpitch = float_to_fix( st->old_fpitch_float, 16 ); + st->hTcxDec->tcxltp_last_gain_unmodified = float_to_fix16( st->hTcxDec->tcxltp_last_gain_unmodified_float, 15 ); - ivas_mdct_core_tns_ns_fx( hCPE, fUseTns, tnsData, x_fx, Aq_fx, 0 , x_e); + ivas_mdct_core_tns_ns_fx( hCPE, fUseTns, tnsData, x_fx, Aq_fx, 0, x_e ); #else ivas_mdct_core_tns_ns( hCPE, fUseTns, tnsData, x, Aq, 0 ); #endif @@ -760,7 +765,7 @@ static void run_min_stats( st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_flt = 0.99f * st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_flt + 0.01f * (float) st->hFdCngDec->hFdCngCom->flag_noisy_speech; #ifdef IVAS_FLOAT_FIXED st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx = L_add( Mpy_32_32( Q31_0_99, st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ), - st->hFdCngDec->hFdCngCom->flag_noisy_speech * Q31_0_01); + st->hFdCngDec->hFdCngCom->flag_noisy_speech * Q31_0_01 ); #endif st->lp_noise_float = st->hFdCngDec->lp_noise_float; } @@ -777,4 +782,3 @@ static void run_min_stats( return; } #endif - diff --git a/lib_dec/ivas_stereo_mdct_core_dec_fx.c b/lib_dec/ivas_stereo_mdct_core_dec_fx.c index 99534d9b9..f1b88a8df 100644 --- a/lib_dec/ivas_stereo_mdct_core_dec_fx.c +++ b/lib_dec/ivas_stereo_mdct_core_dec_fx.c @@ -54,7 +54,7 @@ static void apply_dmx_weights_fx( CPE_DEC_HANDLE hCPE, Word32 *x[CPE_CHANNELS][N static void apply_dmx_weights( CPE_DEC_HANDLE hCPE, float *x[CPE_CHANNELS][NB_DIV], int16_t transform_type_left[NB_DIV], int16_t transform_type_right[NB_DIV] ); #endif -static void run_min_stats_fx( Decoder_State **sts, Word32 *x[CPE_CHANNELS][NB_DIV], Word16 x_e[CPE_CHANNELS][NB_DIV]); +static void run_min_stats_fx( Decoder_State **sts, Word32 *x[CPE_CHANNELS][NB_DIV], Word16 x_e[CPE_CHANNELS][NB_DIV] ); /*-------------------------------------------------------------------* * stereo_mdct_dec_stereo() @@ -95,8 +95,8 @@ static void stereo_mdct_dec_stereo_fx( *--------------------------------------------------------------------*/ void stereo_mdct_core_dec_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ Word32 *signal_out_fx[CPE_CHANNELS], /* o : synthesis @internal_FS */ Word16 signal_outFB_fx[CPE_CHANNELS][L_FRAME48k] /* o : synthesis @output_FS */ ) @@ -164,7 +164,7 @@ void stereo_mdct_core_dec_fx( move16(); sts[ch]->enablePlcWaveadjust = 0; move16(); - set32_fx( signal_out_tmp_fx[ch], 0,L_FRAME_PLUS ); + set32_fx( signal_out_tmp_fx[ch], 0, L_FRAME_PLUS ); x_fx[ch][0] = &signal_out_tmp_fx[ch][0]; x_fx[ch][1] = &signal_out_tmp_fx[ch][0] + L_FRAME_PLUS / 2; @@ -183,16 +183,16 @@ void stereo_mdct_core_dec_fx( set_s( ms_mask[1], 0, MAX_SFB ); initMdctStereoDecData_fx( hCPE->hStereoMdct, sts[0]->igf, sts[0]->hIGFDec->igfData.igfInfo.grid, hCPE->element_brate, sts[0]->bwidth ); - hCPE->hStereoMdct->isSBAStereoMode = ( ( EQ_16(st_ivas->ivas_format, SBA_FORMAT) || EQ_16(st_ivas->ivas_format, SBA_ISM_FORMAT) ) && EQ_16( st_ivas->nchan_transport, 2 ) ); + hCPE->hStereoMdct->isSBAStereoMode = ( ( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) && EQ_16( st_ivas->nchan_transport, 2 ) ); move16(); - IF( EQ_16(bfi, 0) ) + IF( EQ_16( bfi, 0 ) ) { ivas_mdct_dec_side_bits_frame_channel_fx( hCPE, param_lpc, p_param, hCPE->hCoreCoder[0], nTnsBitsTCX10, param, 0, 0 ); - IF( NE_16(sts[0]->igf, 0) ) + IF( NE_16( sts[0]->igf, 0 ) ) { - FOR ( ch = 0; ch < nChannels; ch++ ) + FOR( ch = 0; ch < nChannels; ch++ ) { st = sts[ch]; mdct_read_IGF_bits_fx( st, sts[0] ); @@ -206,14 +206,14 @@ void stereo_mdct_core_dec_fx( mvs2s( hCPE->hStereoMdct->prev_ms_mask[0], ms_mask[0], MAX_SFB ); mvs2s( hCPE->hStereoMdct->prev_ms_mask[1], ms_mask[1], MAX_SFB ); - IF ( NE_16(sts[0]->core, TCX_10_CORE) && NE_16(sts[1]->core, TCX_10_CORE) ) + IF( NE_16( sts[0]->core, TCX_10_CORE ) && NE_16( sts[1]->core, TCX_10_CORE ) ) { hCPE->hStereoMdct->mdct_stereo_mode[1] = SMDCT_DUAL_MONO; move16(); hCPE->hStereoMdct->IGFStereoMode[1] = SMDCT_DUAL_MONO; move16(); } - ELSE IF ( EQ_16(sts[0]->core, TCX_10_CORE) && EQ_16(sts[1]->core, TCX_10_CORE) ) + ELSE IF( EQ_16( sts[0]->core, TCX_10_CORE ) && EQ_16( sts[1]->core, TCX_10_CORE ) ) { hCPE->hStereoMdct->global_ild[0] = hCPE->hStereoMdct->global_ild[1]; move16(); @@ -250,29 +250,28 @@ void stereo_mdct_core_dec_fx( } ivas_mdct_core_invQ_fx( hCPE, nTnsBitsTCX10, p_param, param_lpc, param, fUseTns, tnsData, x_0_fx, x_0_e, x_fx, x_e, x_len, Aq_fx, ms_mask, 0 ); - - FOR(ch = 0; ch < CPE_CHANNELS; ch++) + + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { - IF(sts[ch]->mct_chan_mode != MCT_CHAN_MODE_IGNORE) + IF( sts[ch]->mct_chan_mode != MCT_CHAN_MODE_IGNORE ) { // 16bit to u8bit - FOR(l = 0; l < IGF_START_MX; l++) + FOR( l = 0; l < IGF_START_MX; l++ ) { - sts[ch]->hIGFDec->infoTCXNoise[l] = (UWord8)sts[ch]->hIGFDec->infoTCXNoise_evs[l]; + sts[ch]->hIGFDec->infoTCXNoise[l] = (UWord8) sts[ch]->hIGFDec->infoTCXNoise_evs[l]; } - } } - FOR(ch = 0; ch < CPE_CHANNELS; ch++) + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { - Word16 subFrames = (hCPE->hCoreCoder[ch]->core == TCX_10_CORE) ? NB_DIV : 1; - FOR(k = 0; k < subFrames; ++k) + Word16 subFrames = ( hCPE->hCoreCoder[ch]->core == TCX_10_CORE ) ? NB_DIV : 1; + FOR( k = 0; k < subFrames; ++k ) { - Scale_sig32(x_fx[ch][k], x_len[ch][k], sub(x_e[ch][k], 20)); + Scale_sig32( x_fx[ch][k], x_len[ch][k], sub( x_e[ch][k], 20 ) ); x_e[ch][k] = 20; move16(); - Scale_sig32(x_0_fx[ch][k], x_len[ch][k], sub(x_0_e[ch][k], 20)); + Scale_sig32( x_0_fx[ch][k], x_len[ch][k], sub( x_0_e[ch][k], 20 ) ); x_0_e[ch][k] = 20; move16(); } @@ -285,81 +284,82 @@ void stereo_mdct_core_dec_fx( FOR( k = 0; k < nSubframes[ch]; k++ ) { - L_spec[ch] = idiv1616(sts[ch]->hTcxCfg->tcx_coded_lines, nSubframes[ch]); + L_spec[ch] = idiv1616( sts[ch]->hTcxCfg->tcx_coded_lines, nSubframes[ch] ); init_tcx_info_fx( sts[ch], sts[ch]->L_frame / nSubframes[ch], sts[ch]->hTcxDec->L_frameTCX / nSubframes[ch], k, bfi, &tcx_offset[ch], &tcx_offsetFB[ch], &L_frame[ch], &L_frameTCX[ch], &left_rect[ch], &L_spec[ch] ); } } /* IGF decoding */ - IF ( NE_16(sts[0]->igf, 0) || NE_16(sts[1]->igf, 0) ) + IF( NE_16( sts[0]->igf, 0 ) || NE_16( sts[1]->igf, 0 ) ) { - IF ( NE_16(sts[0]->core, sts[1]->core) ) + IF( NE_16( sts[0]->core, sts[1]->core ) ) { - FOR ( ch = 0; ch < nChannels; ch++ ) + FOR( ch = 0; ch < nChannels; ch++ ) { st = sts[ch]; - IF ( !EQ_16(bfi, 0) || ( NE_16(bfi, 0) && NE_16(st->core, ACELP_CORE) ) ) + IF( !EQ_16( bfi, 0 ) || ( NE_16( bfi, 0 ) && NE_16( st->core, ACELP_CORE ) ) ) { - FOR ( k = 0; k < nSubframes[ch]; k++ ) + FOR( k = 0; k < nSubframes[ch]; k++ ) { /* mono or dual mono IGF decoding */ decoder_tcx_IGF_mono_fx( st, x_fx[ch][k], &x_e[ch][k], &x_len[ch][k], L_frame[ch], left_rect[ch], bfi, k ); - Scale_sig32(x_fx[ch][k], x_len[ch][k], sub(x_e[ch][k], 20)); + Scale_sig32( x_fx[ch][k], x_len[ch][k], sub( x_e[ch][k], 20 ) ); x_e[ch][k] = 20; move16(); - IF(st->igf) + IF( st->igf ) { // 16bit to u8bit - FOR( l = 0; l < IGF_START_MX; l++) + FOR( l = 0; l < IGF_START_MX; l++ ) { - st->hIGFDec->infoTCXNoise[l] = (UWord8)st->hIGFDec->infoTCXNoise_evs[l]; + st->hIGFDec->infoTCXNoise[l] = (UWord8) st->hIGFDec->infoTCXNoise_evs[l]; } } } } } } - ELSE IF ( NE_16(sts[0]->core, ACELP_CORE) ) + ELSE IF( NE_16( sts[0]->core, ACELP_CORE ) ) { - assert( EQ_16(nSubframes[0], nSubframes[1]) ); + assert( EQ_16( nSubframes[0], nSubframes[1] ) ); - FOR ( k = 0; k < nSubframes[0]; k++ ) + FOR( k = 0; k < nSubframes[0]; k++ ) { - IF ( ( NE_16(hCPE->hStereoMdct->IGFStereoMode[k], SMDCT_DUAL_MONO) || NE_16(hCPE->hStereoMdct->mdct_stereo_mode[k], SMDCT_DUAL_MONO) ) && EQ_16(hCPE->hStereoMdct->isSBAStereoMode, 0) ) + IF( ( NE_16( hCPE->hStereoMdct->IGFStereoMode[k], SMDCT_DUAL_MONO ) || NE_16( hCPE->hStereoMdct->mdct_stereo_mode[k], SMDCT_DUAL_MONO ) ) && EQ_16( hCPE->hStereoMdct->isSBAStereoMode, 0 ) ) { - assert( ( EQ_16(sts[0]->core, sts[1]->core) ) || ( EQ_16(hCPE->hStereoMdct->mdct_stereo_mode[0], SMDCT_DUAL_MONO) ) ); + assert( ( EQ_16( sts[0]->core, sts[1]->core ) ) || ( EQ_16( hCPE->hStereoMdct->mdct_stereo_mode[0], SMDCT_DUAL_MONO ) ) ); /* stereo IGF decoding */ decoder_tcx_IGF_stereo_fx( sts, hCPE->hStereoMdct, ms_mask, x_fx, x_e, x_len, L_frame[0], left_rect[0], k, bfi, 0 /* MCT_flag */ ); - Scale_sig32(x_fx[0][k], x_len[0][k], sub(x_e[0][k], 20)); - Scale_sig32(x_fx[1][k], x_len[1][k], sub(x_e[1][k], 20)); + Scale_sig32( x_fx[0][k], x_len[0][k], sub( x_e[0][k], 20 ) ); + Scale_sig32( x_fx[1][k], x_len[1][k], sub( x_e[1][k], 20 ) ); x_e[0][k] = 20; x_e[1][k] = 20; - move16(); move16(); + move16(); + move16(); - FOR( i = 0; i < IGF_START_MX; i++) + FOR( i = 0; i < IGF_START_MX; i++ ) { - sts[0]->hIGFDec->infoTCXNoise[i] = (UWord8)sts[0]->hIGFDec->infoTCXNoise_evs[i]; - sts[1]->hIGFDec->infoTCXNoise[i] = (UWord8)sts[1]->hIGFDec->infoTCXNoise_evs[i]; + sts[0]->hIGFDec->infoTCXNoise[i] = (UWord8) sts[0]->hIGFDec->infoTCXNoise_evs[i]; + sts[1]->hIGFDec->infoTCXNoise[i] = (UWord8) sts[1]->hIGFDec->infoTCXNoise_evs[i]; } } ELSE { - FOR ( ch = 0; ch < nChannels; ch++ ) + FOR( ch = 0; ch < nChannels; ch++ ) { st = sts[ch]; /* mono or dual mono IGF decoding */ decoder_tcx_IGF_mono_fx( st, x_fx[ch][k], &x_e[ch][k], &x_len[ch][k], L_frame[ch], left_rect[ch], bfi, k ); - Scale_sig32(x_fx[ch][k], x_len[ch][k], sub(x_e[ch][k], 20)); + Scale_sig32( x_fx[ch][k], x_len[ch][k], sub( x_e[ch][k], 20 ) ); x_e[ch][k] = 20; move16(); - IF(st->igf) + IF( st->igf ) { // 16bit to u8bit - FOR( l = 0; l < IGF_START_MX; l++) + FOR( l = 0; l < IGF_START_MX; l++ ) { - st->hIGFDec->infoTCXNoise[l] = (UWord8)st->hIGFDec->infoTCXNoise_evs[l]; + st->hIGFDec->infoTCXNoise[l] = (UWord8) st->hIGFDec->infoTCXNoise_evs[l]; } } } @@ -368,42 +368,42 @@ void stereo_mdct_core_dec_fx( } } - FOR(ch = 0; ch < CPE_CHANNELS; ch++) + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { - Copy_Scale_sig_16_32(Aq_fx[ch], Aq_fx_32[ch], (NB_SUBFR16k + 1) * (M + 1), sub(Q16, Q12)); + Copy_Scale_sig_16_32( Aq_fx[ch], Aq_fx_32[ch], ( NB_SUBFR16k + 1 ) * ( M + 1 ), sub( Q16, Q12 ) ); } /*--------------------------------------------------------------------------------* * Stereo processing *--------------------------------------------------------------------------------*/ - IF ( EQ_16(bfi, 0) ) + IF( EQ_16( bfi, 0 ) ) { - FOR ( ch = 0; ch < CPE_CHANNELS; ch++ ) + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { Word32 sns_int_scf_fx[FDNS_NPTS]; Word16 scf_fx[FDNS_NPTS], scf_e[FDNS_NPTS]; Word16 norm; st = sts[ch]; - FOR ( k = 0; k < nSubframes[ch]; k++ ) + FOR( k = 0; k < nSubframes[ch]; k++ ) { sns_interpolate_scalefactors_fx( sns_int_scf_fx, Aq_fx_32[ch], DEC ); - - IF ( st->hTonalMDCTConc != NULL && EQ_16( add( k, 1 ), nSubframes[ch] ) ) + + IF( st->hTonalMDCTConc != NULL && EQ_16( add( k, 1 ), nSubframes[ch] ) ) { x_e[ch][k] = 20; move16(); - FOR ( j = 0; j < st->hTonalMDCTConc->nScaleFactors; j++ ) + FOR( j = 0; j < st->hTonalMDCTConc->nScaleFactors; j++ ) { - norm = norm_l(sns_int_scf_fx[j]); - scf_e[j] = sub(15, norm); - scf_fx[j] = extract_h(L_shl(sns_int_scf_fx[j], norm)); + norm = norm_l( sns_int_scf_fx[j] ); + scf_e[j] = sub( 15, norm ); + scf_fx[j] = extract_h( L_shl( sns_int_scf_fx[j], norm ) ); } - Word16 s = getScaleFactor32(x_fx[ch][k], L_frameTCX[ch]); - Scale_sig32(x_fx[ch][k], L_frameTCX[ch], s); - TonalMDCTConceal_SaveFreqSignal_ivas_fx( st->hTonalMDCTConc, x_fx[ch][k], sub(x_e[ch][k], s), L_frameTCX[ch], L_frame[ch], &scf_fx[0], scf_e, 0, get_igf_startline( st, L_frame[ch], L_frameTCX[ch] ) ); - Scale_sig32(x_fx[ch][k], L_frameTCX[ch], negate(s)); + Word16 s = getScaleFactor32( x_fx[ch][k], L_frameTCX[ch] ); + Scale_sig32( x_fx[ch][k], L_frameTCX[ch], s ); + TonalMDCTConceal_SaveFreqSignal_ivas_fx( st->hTonalMDCTConc, x_fx[ch][k], sub( x_e[ch][k], s ), L_frameTCX[ch], L_frame[ch], &scf_fx[0], scf_e, 0, get_igf_startline( st, L_frame[ch], L_frameTCX[ch] ) ); + Scale_sig32( x_fx[ch][k], L_frameTCX[ch], negate( s ) ); } } @@ -414,12 +414,11 @@ void stereo_mdct_core_dec_fx( mvs2s( ms_mask[1], hCPE->hStereoMdct->prev_ms_mask[1], MAX_SFB ); } - IF ( ( EQ_16(bfi, 0) || ( NE_16(sts[0]->core, ACELP_CORE) || NE_16(sts[1]->core, ACELP_CORE) ) ) && EQ_16(hCPE->hStereoMdct->isSBAStereoMode, 0) ) + IF( ( EQ_16( bfi, 0 ) || ( NE_16( sts[0]->core, ACELP_CORE ) || NE_16( sts[1]->core, ACELP_CORE ) ) ) && EQ_16( hCPE->hStereoMdct->isSBAStereoMode, 0 ) ) { Word16 q_x_1 = 11, q_x_0 = 11; stereo_decoder_tcx_fx( hCPE->hStereoMdct, ms_mask, x_0_fx[1], x_fx[0], x_fx[1], &hCPE->hStereoMdct->mdct_stereo_mode[0], sts[0]->core, sts[1]->core, sts[0]->igf, L_frameTCX[0], L_frameTCX[1], 0, sts[0]->last_core, sts[1]->last_core, 0, &q_x_1, &q_x_0 ); - } ivas_mdct_core_tns_ns_fx( hCPE, fUseTns, tnsData, x_fx, Aq_fx_32, 0, x_e ); @@ -451,21 +450,22 @@ void stereo_mdct_core_dec_fx( } Word16 s; - FOR(ch = 0; ch < CPE_CHANNELS; ch++) + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { - IF(sts[ch]->hFdCngDec && sts[ch]->hFdCngDec->hFdCngCom) + IF( sts[ch]->hFdCngDec && sts[ch]->hFdCngDec->hFdCngCom ) { - s = getScaleFactor32(sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN); - IF(GT_16(s, sub(sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4))) + s = getScaleFactor32( sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN ); + IF( GT_16( s, sub( sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 ) ) ) { - s = sub(sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4); + s = sub( sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 ); move16(); } - scale_sig32(sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, s); - sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub(sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, s); + scale_sig32( sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, s ); + sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, s ); } - IF(sts[ch]->hFdCngDec && sts[ch]->hFdCngDec->hFdCngCom) { - sts[ch]->hFdCngDec->hFdCngCom->likelihood_noisy_speech = extract_h(sts[ch]->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx); + IF( sts[ch]->hFdCngDec && sts[ch]->hFdCngDec->hFdCngCom ) + { + sts[ch]->hFdCngDec->hFdCngCom->likelihood_noisy_speech = extract_h( sts[ch]->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ); } } @@ -962,8 +962,7 @@ static void apply_dmx_weights_fx( static void run_min_stats_fx( Decoder_State **sts, Word32 *x[CPE_CHANNELS][NB_DIV], /* i/o: MDCT Spectrum */ - Word16 x_e[CPE_CHANNELS][NB_DIV] -) + Word16 x_e[CPE_CHANNELS][NB_DIV] ) { int16_t ch, will_estimate_noise_on_channel[CPE_CHANNELS], save_VAD[CPE_CHANNELS]; Word32 power_spec[L_FRAME16k]; @@ -982,16 +981,16 @@ static void run_min_stats_fx( for the two different channels. If they would only run on one of the channels, the VAD of the other one is patched so that the MS will still run. This other channel then uses the power spectrum of the other channel to run the MS. This is done to keep continuity and synchronicity between the two noise levels and silently assumes that the background noise is somehow diffuse and at leas partly shared between the channels */ - FOR ( ch = 0; ch < CPE_CHANNELS; ch++ ) + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { Decoder_State *st; st = sts[ch]; - IF ( !sts[0]->bfi && ( will_estimate_noise_on_channel[0] || will_estimate_noise_on_channel[1] ) ) + IF( !sts[0]->bfi && ( will_estimate_noise_on_channel[0] || will_estimate_noise_on_channel[1] ) ) { /* if noise estimation is expected to run on this channel, compute power spectrum from it, otherwise, use other channel's signal */ - IF ( will_estimate_noise_on_channel[ch] ) + IF( will_estimate_noise_on_channel[ch] ) { spec_in = &x[ch][0][0]; spec_e = x_e[ch][0]; @@ -999,7 +998,7 @@ static void run_min_stats_fx( ELSE { spec_in = &x[( ch + 1 ) % 2][0][0]; - spec_e = x_e[(ch + 1) % 2][0]; + spec_e = x_e[( ch + 1 ) % 2][0]; /* patch VAD to zero so that estimation runs, will later be restored */ st->VAD = 0; } @@ -1021,30 +1020,30 @@ static void run_min_stats_fx( power_spec_e = add( 4, shl( spec_e, 1 ) ) - tmp16; } - Copy_Scale_sig32_16(power_spec, power_spec_16, L_FRAME16k, 0); - - noisy_speech_detection_fx( st->hFdCngDec, st->VAD && st->m_frame_type == ACTIVE_FRAME, power_spec_16, sub(15, power_spec_e)); + Copy_Scale_sig32_16( power_spec, power_spec_16, L_FRAME16k, 0 ); - st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx = L_add(Mpy_32_32(Q31_0_99, st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx), Mpy_32_32(st->hFdCngDec->hFdCngCom->flag_noisy_speech, Q31_0_01)); + noisy_speech_detection_fx( st->hFdCngDec, st->VAD && st->m_frame_type == ACTIVE_FRAME, power_spec_16, sub( 15, power_spec_e ) ); + + st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx = L_add( Mpy_32_32( Q31_0_99, st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ), Mpy_32_32( st->hFdCngDec->hFdCngCom->flag_noisy_speech, Q31_0_01 ) ); st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = extract_h( st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ); st->lp_noise = st->hFdCngDec->lp_noise; } - IF ( will_estimate_noise_on_channel[0] || will_estimate_noise_on_channel[1] || st->bfi ) - { - //for ( int p = 0; p < FFTCLDFBLEN; p++ ) + IF( will_estimate_noise_on_channel[0] || will_estimate_noise_on_channel[1] || st->bfi ) + { + // for ( int p = 0; p < FFTCLDFBLEN; p++ ) { - //st->hFdCngDec->hFdCngCom->cngNoiseLevel[p] = L_shr ( st->hFdCngDec->hFdCngCom->cngNoiseLevel[p], sub( 28, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ) ); + // st->hFdCngDec->hFdCngCom->cngNoiseLevel[p] = L_shr ( st->hFdCngDec->hFdCngCom->cngNoiseLevel[p], sub( 28, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ) ); } - Scale_sig32(st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, sub(st->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 28) ); + Scale_sig32( st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, sub( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 28 ) ); st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 31 - Q3; // Q3 - Scale_sig32(st->hFdCngDec->msNoiseEst, NPART_SHAPING, sub(st->hFdCngDec->msNoiseEst_exp, 27) ); + Scale_sig32( st->hFdCngDec->msNoiseEst, NPART_SHAPING, sub( st->hFdCngDec->msNoiseEst_exp, 27 ) ); st->hFdCngDec->msNoiseEst_exp = 27; - //Scale_sig32(power_spec, L_FRAME16k, sub(power_spec_e, 31)); - //power_spec_e = 31; + // Scale_sig32(power_spec, L_FRAME16k, sub(power_spec_e, 31)); + // power_spec_e = 31; /*=================================================*/ - ApplyFdCng_ivas_fx( NULL, 0, st->bfi ? NULL : power_spec, sub(31, power_spec_e), NULL, NULL, NULL, st, st->bfi, 0 ); + ApplyFdCng_ivas_fx( NULL, 0, st->bfi ? NULL : power_spec, sub( 31, power_spec_e ), NULL, NULL, NULL, st, st->bfi, 0 ); /*=================================================*/ } diff --git a/lib_dec/ivas_stereo_mdct_stereo_dec.c b/lib_dec/ivas_stereo_mdct_stereo_dec.c index 256b3efeb..b6a424093 100644 --- a/lib_dec/ivas_stereo_mdct_stereo_dec.c +++ b/lib_dec/ivas_stereo_mdct_stereo_dec.c @@ -897,7 +897,7 @@ ivas_error initMdctStereoDtxData_fx( } /* Init FD-CNG */ -#if 1/*TODO: To be removed later*/ +#if 1 /*TODO: To be removed later*/ initFdCngDec( st ); #endif initFdCngDec_ivas_fx( st, st->cldfbSyn->scale ); @@ -943,14 +943,14 @@ ivas_error initMdctStereoDtxData( error = IVAS_ERR_OK; move16(); - FOR ( ch = 0; ch < CPE_CHANNELS; ch++ ) + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { DEC_CORE_HANDLE st = hCPE->hCoreCoder[ch]; - IF ( st->hFdCngDec == NULL ) + IF( st->hFdCngDec == NULL ) { /* Create FD_CNG instance */ - IF ( ( error = createFdCngDec( &st->hFdCngDec ) ) != IVAS_ERR_OK ) + IF( ( error = createFdCngDec( &st->hFdCngDec ) ) != IVAS_ERR_OK ) { return error; } @@ -963,27 +963,27 @@ ivas_error initMdctStereoDtxData( #endif } - IF ( EQ_16( st->first_CNG, 0 ) ) + IF( EQ_16( st->first_CNG, 0 ) ) { - IF ( EQ_16( ch, 1 ) && st->cng_sba_flag ) + IF( EQ_16( ch, 1 ) && st->cng_sba_flag ) { st->hFdCngDec->hFdCngCom->seed = add( st->hFdCngDec->hFdCngCom->seed, 3 ); } } - IF ( st->cldfbAna == NULL ) + IF( st->cldfbAna == NULL ) { /* open analysis for max. sampling rate 48kHz */ - IF ( ( error = openCldfb_ivas( &st->cldfbAna, CLDFB_ANALYSIS, 48000, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) + IF( ( error = openCldfb_ivas( &st->cldfbAna, CLDFB_ANALYSIS, 48000, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) { return error; } } - IF ( st->cldfbBPF == NULL ) + IF( st->cldfbBPF == NULL ) { /* open analysis BPF for max. internal sampling rate 16kHz */ - IF ( ( error = openCldfb_ivas( &st->cldfbBPF, CLDFB_ANALYSIS, 16000, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) + IF( ( error = openCldfb_ivas( &st->cldfbBPF, CLDFB_ANALYSIS, 16000, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) { return error; } @@ -1094,7 +1094,7 @@ void synchonize_channels_mdct_sid( *-------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -//helper function +// helper function static void update_exp( Word16 *a_exp, Word16 *b_exp, Word16 *buff_a, Word16 *buff_b, Word16 legth ); static void update_exp( Word16 *a_exp, Word16 *b_exp, Word16 *buff_a, Word16 *buff_b, Word16 legth ) @@ -1121,18 +1121,18 @@ static void update_exp( Word16 *a_exp, Word16 *b_exp, Word16 *buff_a, Word16 *bu } return; } -static Word16 norm_arr(Word16 *arr, int size) +static Word16 norm_arr( Word16 *arr, int size ) { - Word16 q = 15; - for (int i = 0; i < size; i++) - if (arr[i] != 0) - { - q = min(q, norm_s(arr[i])); - } - return q; + Word16 q = 15; + for ( int i = 0; i < size; i++ ) + if ( arr[i] != 0 ) + { + q = min( q, norm_s( arr[i] ) ); + } + return q; } void updateBuffersForDmxMdctStereo_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE handle */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE handle */ const Word16 output_frame, /* i : output frame length */ Word32 output0_fx[], Word32 output1_fx[], @@ -1182,7 +1182,7 @@ void updateBuffersForDmxMdctStereo_fx( FOR( int16_t p = 0; p < sts[0]->hFdCngDec->hFdCngCom->npart; p++ ) { Var1 = L_add( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] >> 1, sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst[p] >> 1 ); // exp_sidNoiseEst0 - 1 - sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] = Mpy_32_32( float_to_fix( 0.5f, 31 ), Var1 ); // 31 - exp_sidNoiseEst0 - 1 + 31 - 31 + sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] = Mpy_32_32( float_to_fix( 0.5f, 31 ), Var1 ); // 31 - exp_sidNoiseEst0 - 1 + 31 - 31 } } @@ -1210,25 +1210,24 @@ void updateBuffersForDmxMdctStereo_fx( Word16 sum_tcx_ltp = 0, sum_delay_buf = 0, sum_tcx_ltp_out = 0, sum_old_out = 0; - Copy_Scale_sig_32_16(&sts[0]->hTcxLtpDec->tcxltp_mem_in_32[0], &sts[0]->hTcxLtpDec->tcxltp_mem_in[0], TCXLTP_MAX_DELAY, -11); - Copy_Scale_sig_32_16(&sts[1]->hTcxLtpDec->tcxltp_mem_in_32[0], &sts[1]->hTcxLtpDec->tcxltp_mem_in[0], TCXLTP_MAX_DELAY, -11); + Copy_Scale_sig_32_16( &sts[0]->hTcxLtpDec->tcxltp_mem_in_32[0], &sts[0]->hTcxLtpDec->tcxltp_mem_in[0], TCXLTP_MAX_DELAY, -11 ); + Copy_Scale_sig_32_16( &sts[1]->hTcxLtpDec->tcxltp_mem_in_32[0], &sts[1]->hTcxLtpDec->tcxltp_mem_in[0], TCXLTP_MAX_DELAY, -11 ); + + Copy_Scale_sig_32_16( &sts[0]->hTcxLtpDec->tcxltp_mem_out_32[0], &sts[0]->hTcxLtpDec->tcxltp_mem_out[0], L_FRAME48k, -11 ); + Copy_Scale_sig_32_16( &sts[1]->hTcxLtpDec->tcxltp_mem_out_32[0], &sts[1]->hTcxLtpDec->tcxltp_mem_out[0], L_FRAME48k, -11 ); - Copy_Scale_sig_32_16(&sts[0]->hTcxLtpDec->tcxltp_mem_out_32[0], &sts[0]->hTcxLtpDec->tcxltp_mem_out[0], L_FRAME48k, -11); - Copy_Scale_sig_32_16(&sts[1]->hTcxLtpDec->tcxltp_mem_out_32[0], &sts[1]->hTcxLtpDec->tcxltp_mem_out[0], L_FRAME48k, -11); + sts[0]->hTcxLtpDec->exp_tcxltp_mem_in = 15 - norm_arr( sts[0]->hTcxLtpDec->tcxltp_mem_in, TCXLTP_MAX_DELAY ); + sts[1]->hTcxLtpDec->exp_tcxltp_mem_in = 15 - norm_arr( sts[1]->hTcxLtpDec->tcxltp_mem_in, TCXLTP_MAX_DELAY ); - sts[0]->hTcxLtpDec->exp_tcxltp_mem_in = 15 - norm_arr(sts[0]->hTcxLtpDec->tcxltp_mem_in, TCXLTP_MAX_DELAY); - sts[1]->hTcxLtpDec->exp_tcxltp_mem_in = 15 - norm_arr(sts[1]->hTcxLtpDec->tcxltp_mem_in, TCXLTP_MAX_DELAY); - - sts[0]->hTcxLtpDec->exp_tcxltp_mem_out = 15 - norm_arr(sts[0]->hTcxLtpDec->tcxltp_mem_out, L_FRAME48k); - sts[1]->hTcxLtpDec->exp_tcxltp_mem_out = 15 - norm_arr(sts[1]->hTcxLtpDec->tcxltp_mem_out, L_FRAME48k); + sts[0]->hTcxLtpDec->exp_tcxltp_mem_out = 15 - norm_arr( sts[0]->hTcxLtpDec->tcxltp_mem_out, L_FRAME48k ); + sts[1]->hTcxLtpDec->exp_tcxltp_mem_out = 15 - norm_arr( sts[1]->hTcxLtpDec->tcxltp_mem_out, L_FRAME48k ); + Scale_sig( &sts[0]->hTcxLtpDec->tcxltp_mem_in[0], TCXLTP_MAX_DELAY, sub( 15, sts[0]->hTcxLtpDec->exp_tcxltp_mem_in ) ); + Scale_sig( &sts[1]->hTcxLtpDec->tcxltp_mem_in[0], TCXLTP_MAX_DELAY, sub( 15, sts[1]->hTcxLtpDec->exp_tcxltp_mem_in ) ); - Scale_sig(&sts[0]->hTcxLtpDec->tcxltp_mem_in[0], TCXLTP_MAX_DELAY, sub(15, sts[0]->hTcxLtpDec->exp_tcxltp_mem_in)); - Scale_sig(&sts[1]->hTcxLtpDec->tcxltp_mem_in[0], TCXLTP_MAX_DELAY, sub(15, sts[1]->hTcxLtpDec->exp_tcxltp_mem_in)); - - Scale_sig(&sts[0]->hTcxLtpDec->tcxltp_mem_out[0], TCXLTP_MAX_DELAY, sub(15, sts[0]->hTcxLtpDec->exp_tcxltp_mem_out)); - Scale_sig(&sts[1]->hTcxLtpDec->tcxltp_mem_out[0], TCXLTP_MAX_DELAY, sub(15, sts[1]->hTcxLtpDec->exp_tcxltp_mem_out)); + Scale_sig( &sts[0]->hTcxLtpDec->tcxltp_mem_out[0], TCXLTP_MAX_DELAY, sub( 15, sts[0]->hTcxLtpDec->exp_tcxltp_mem_out ) ); + Scale_sig( &sts[1]->hTcxLtpDec->tcxltp_mem_out[0], TCXLTP_MAX_DELAY, sub( 15, sts[1]->hTcxLtpDec->exp_tcxltp_mem_out ) ); update_exp( &sts[0]->hTcxLtpDec->exp_tcxltp_mem_in, &sts[1]->hTcxLtpDec->exp_tcxltp_mem_in, @@ -1280,8 +1279,8 @@ void updateBuffersForDmxMdctStereo_fx( sts[0]->hHQ_core->exp_old_out = add( sts[0]->hHQ_core->exp_old_out, 1 ); sts[0]->hTcxLtpDec->exp_tcxltp_mem_out = add( sts[0]->hTcxLtpDec->exp_tcxltp_mem_out, 1 ); - Copy_Scale_sig_16_32(&sts[0]->hTcxLtpDec->tcxltp_mem_in[0], &sts[0]->hTcxLtpDec->tcxltp_mem_in_32[0], TCXLTP_MAX_DELAY, sub(11, sub(15, sts[0]->hTcxLtpDec->exp_tcxltp_mem_in))); - Copy_Scale_sig_16_32(&sts[0]->hTcxLtpDec->tcxltp_mem_out[0], &sts[0]->hTcxLtpDec->tcxltp_mem_out_32[0], TCXLTP_MAX_DELAY, sub(11, sub(15, sts[0]->hTcxLtpDec->exp_tcxltp_mem_out))); + Copy_Scale_sig_16_32( &sts[0]->hTcxLtpDec->tcxltp_mem_in[0], &sts[0]->hTcxLtpDec->tcxltp_mem_in_32[0], TCXLTP_MAX_DELAY, sub( 11, sub( 15, sts[0]->hTcxLtpDec->exp_tcxltp_mem_in ) ) ); + Copy_Scale_sig_16_32( &sts[0]->hTcxLtpDec->tcxltp_mem_out[0], &sts[0]->hTcxLtpDec->tcxltp_mem_out_32[0], TCXLTP_MAX_DELAY, sub( 11, sub( 15, sts[0]->hTcxLtpDec->exp_tcxltp_mem_out ) ) ); } return; diff --git a/lib_dec/ivas_stereo_switching_dec.c b/lib_dec/ivas_stereo_switching_dec.c index b8a5cc5c0..b4df02cab 100644 --- a/lib_dec/ivas_stereo_switching_dec.c +++ b/lib_dec/ivas_stereo_switching_dec.c @@ -50,7 +50,7 @@ * Local constants *-------------------------------------------------------------------*/ -#define DFT2TD_CORR_THRESH 0.9f +#define DFT2TD_CORR_THRESH 0.9f #define DFT2TD_CORR_THRESH_FX 1932735283 /*-------------------------------------------------------------------* @@ -138,39 +138,39 @@ static ivas_error allocate_CoreCoder_TCX_fx( DEC_CORE_HANDLE st /* i/o: Core decoder state structure */ ) { - IF ( st->hTcxDec == NULL ) + IF( st->hTcxDec == NULL ) { - IF ( ( st->hTcxDec = (TCX_DEC_HANDLE) malloc( sizeof( TCX_DEC_DATA ) ) ) == NULL ) + IF( ( st->hTcxDec = (TCX_DEC_HANDLE) malloc( sizeof( TCX_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for hTcxDec" ) ); } reset_tcx_overl_buf_fx( st->hTcxDec ); - //st->hTcxDec->CngLevelBackgroundTrace_bfi = 0; //initializing to avoid garbage overflow; + // st->hTcxDec->CngLevelBackgroundTrace_bfi = 0; //initializing to avoid garbage overflow; set16_fx( st->hTcxDec->syn_OverlFB, 0, L_FRAME48k / 2 ); set16_fx( st->hTcxDec->old_synth, 0, OLD_SYNTH_INTERNAL_DEC ); set16_fx( st->hTcxDec->synth_history_fx, 0, L_PROT48k + L_FRAME48k ); #if 1 // TODO: TO be removed later - //reset_tcx_overl_buf( st->hTcxDec ); - //set_zero( st->hTcxDec->syn_OverlFB_float, L_FRAME48k / 2 ); - //set_zero( st->hTcxDec->old_synth_float, OLD_SYNTH_INTERNAL_DEC ); - //set_zero( st->hTcxDec->synth_history, L_PROT48k + L_FRAME48k ); + // reset_tcx_overl_buf( st->hTcxDec ); + // set_zero( st->hTcxDec->syn_OverlFB_float, L_FRAME48k / 2 ); + // set_zero( st->hTcxDec->old_synth_float, OLD_SYNTH_INTERNAL_DEC ); + // set_zero( st->hTcxDec->synth_history, L_PROT48k + L_FRAME48k ); #endif } - IF ( st->hTcxCfg == NULL ) + IF( st->hTcxCfg == NULL ) { - IF ( ( st->hTcxCfg = (TCX_CONFIG_HANDLE) malloc( sizeof( TCX_config ) ) ) == NULL ) + IF( ( st->hTcxCfg = (TCX_CONFIG_HANDLE) malloc( sizeof( TCX_config ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for hTcxCfg" ) ); } } /* allocated TCX-LTP structure for second channel */ - IF ( st->hTcxLtpDec == NULL ) + IF( st->hTcxLtpDec == NULL ) { - IF ( ( st->hTcxLtpDec = (TCX_LTP_DEC_HANDLE) malloc( sizeof( TCX_LTP_DEC_DATA ) ) ) == NULL ) + IF( ( st->hTcxLtpDec = (TCX_LTP_DEC_HANDLE) malloc( sizeof( TCX_LTP_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for TCX-LTP handle\n" ) ); } @@ -179,9 +179,9 @@ static ivas_error allocate_CoreCoder_TCX_fx( } /* allocate HQ structure */ - IF ( st->hHQ_core == NULL ) + IF( st->hHQ_core == NULL ) { - IF ( ( st->hHQ_core = (HQ_DEC_HANDLE) malloc( sizeof( HQ_DEC_DATA ) ) ) == NULL ) + IF( ( st->hHQ_core = (HQ_DEC_HANDLE) malloc( sizeof( HQ_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for HQ core\n" ) ); } @@ -189,9 +189,9 @@ static ivas_error allocate_CoreCoder_TCX_fx( HQ_core_dec_init_fx( st->hHQ_core ); } - IF ( st->hIGFDec == NULL ) + IF( st->hIGFDec == NULL ) { - IF ( ( st->hIGFDec = (IGF_DEC_INSTANCE_HANDLE) malloc( sizeof( IGFDEC_INSTANCE ) ) ) == NULL ) + IF( ( st->hIGFDec = (IGF_DEC_INSTANCE_HANDLE) malloc( sizeof( IGFDEC_INSTANCE ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for IGF\n" ) ); } @@ -201,9 +201,9 @@ static ivas_error allocate_CoreCoder_TCX_fx( init_igf_dec( st->hIGFDec ); } - IF ( st->hTonalMDCTConc == NULL ) + IF( st->hTonalMDCTConc == NULL ) { - IF ( ( st->hTonalMDCTConc = (TonalMDCTConcealPtr) malloc( sizeof( TonalMDCTConceal_INSTANCE ) ) ) == NULL ) + IF( ( st->hTonalMDCTConc = (TonalMDCTConcealPtr) malloc( sizeof( TonalMDCTConceal_INSTANCE ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for TonalMDCTConcealment\n" ) ); } @@ -253,7 +253,7 @@ static ivas_error allocate_CoreCoder( Init_post_filter_ivas( st->hPFstat ); #ifdef IVAS_FLOAT_FIXED - Init_post_filter_fx(st->hPFstat); + Init_post_filter_fx( st->hPFstat ); #endif // IVAS_FLOAT_FIXED st->psf_lp_noise = 0.0f; } @@ -317,9 +317,9 @@ static ivas_error allocate_CoreCoder_fx( error = IVAS_ERR_OK; - IF ( st->hGSCDec == NULL ) + IF( st->hGSCDec == NULL ) { - IF ( ( st->hGSCDec = (GSC_DEC_HANDLE) malloc( sizeof( GSC_DEC_DATA ) ) ) == NULL ) + IF( ( st->hGSCDec = (GSC_DEC_HANDLE) malloc( sizeof( GSC_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for GSC\n" ) ); } @@ -327,9 +327,9 @@ static ivas_error allocate_CoreCoder_fx( GSC_dec_init_ivas_fx( st->hGSCDec ); } - IF ( st->hPFstat == NULL ) + IF( st->hPFstat == NULL ) { - IF ( ( st->hPFstat = (PFSTAT_HANDLE) malloc( sizeof( PFSTAT ) ) ) == NULL ) + IF( ( st->hPFstat = (PFSTAT_HANDLE) malloc( sizeof( PFSTAT ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for NB/formant postflter\n" ) ); } @@ -344,9 +344,9 @@ static ivas_error allocate_CoreCoder_fx( #endif } - IF ( st->hMusicPF == NULL ) + IF( st->hMusicPF == NULL ) { - IF ( ( st->hMusicPF = (MUSIC_POSTFILT_HANDLE) malloc( sizeof( MUSIC_POSTFILT_DATA ) ) ) == NULL ) + IF( ( st->hMusicPF = (MUSIC_POSTFILT_HANDLE) malloc( sizeof( MUSIC_POSTFILT_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LD music postflter\n" ) ); } @@ -358,9 +358,9 @@ static ivas_error allocate_CoreCoder_fx( #endif } - IF ( st->hBPF == NULL ) + IF( st->hBPF == NULL ) { - IF ( ( st->hBPF = (BPF_DEC_HANDLE) malloc( sizeof( BPF_DEC_DATA ) ) ) == NULL ) + IF( ( st->hBPF = (BPF_DEC_HANDLE) malloc( sizeof( BPF_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for BPF\n" ) ); } @@ -368,9 +368,9 @@ static ivas_error allocate_CoreCoder_fx( bass_psfilter_init_fx( st->hBPF ); } - IF ( st->hBWE_zero == NULL ) + IF( st->hBWE_zero == NULL ) { - IF ( ( st->hBWE_zero = (ZERO_BWE_DEC_HANDLE) malloc( sizeof( ZERO_BWE_DEC_DATA ) ) ) == NULL ) + IF( ( st->hBWE_zero = (ZERO_BWE_DEC_HANDLE) malloc( sizeof( ZERO_BWE_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for zero BWE\n" ) ); } @@ -381,19 +381,19 @@ static ivas_error allocate_CoreCoder_fx( #endif } - IF ( st->cldfbAna == NULL ) + IF( st->cldfbAna == NULL ) { /* open analysis for max. sampling rate 48kHz */ - IF ( ( error = openCldfb_ivas_fx( &st->cldfbAna, CLDFB_ANALYSIS, 48000, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) + IF( ( error = openCldfb_ivas_fx( &st->cldfbAna, CLDFB_ANALYSIS, 48000, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) { return error; } } - IF ( st->cldfbBPF == NULL ) + IF( st->cldfbBPF == NULL ) { /* open analysis BPF for max. internal sampling rate 16kHz */ - IF ( ( error = openCldfb_ivas_fx( &st->cldfbBPF, CLDFB_ANALYSIS, 16000, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) + IF( ( error = openCldfb_ivas_fx( &st->cldfbBPF, CLDFB_ANALYSIS, 16000, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) { return error; } @@ -414,25 +414,25 @@ static void deallocate_CoreCoder_TCX( DEC_CORE_HANDLE st /* i/o: Core decoder state structure */ ) { - IF ( st->hTcxDec != NULL ) + IF( st->hTcxDec != NULL ) { free( st->hTcxDec ); st->hTcxDec = NULL; } - IF ( st->hTcxCfg != NULL ) + IF( st->hTcxCfg != NULL ) { free( st->hTcxCfg ); st->hTcxCfg = NULL; } - IF ( st->hIGFDec != NULL ) + IF( st->hIGFDec != NULL ) { free( st->hIGFDec ); st->hIGFDec = NULL; } - IF ( st->hTonalMDCTConc != NULL ) + IF( st->hTonalMDCTConc != NULL ) { free( st->hTonalMDCTConc ); st->hTonalMDCTConc = NULL; @@ -502,44 +502,44 @@ static void deallocate_CoreCoder_fx( DEC_CORE_HANDLE st /* i/o: Core decoder state structure */ ) { - IF ( st->hGSCDec != NULL ) + IF( st->hGSCDec != NULL ) { free( st->hGSCDec ); st->hGSCDec = NULL; } - IF ( st->hPFstat != NULL ) + IF( st->hPFstat != NULL ) { free( st->hPFstat ); st->hPFstat = NULL; } - IF ( st->hMusicPF != NULL ) + IF( st->hMusicPF != NULL ) { free( st->hMusicPF ); st->hMusicPF = NULL; } - IF ( st->hBPF != NULL ) + IF( st->hBPF != NULL ) { free( st->hBPF ); st->hBPF = NULL; } - IF ( st->hBWE_zero != NULL ) + IF( st->hBWE_zero != NULL ) { free( st->hBWE_zero ); st->hBWE_zero = NULL; } /* CLDFB BPF & resampling tools */ - IF ( NE_16(st->element_mode, IVAS_CPE_MDCT) ) + IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { deleteCldfb_ivas_fx( &st->cldfbAna ); /* delete analysis at max. sampling rate 48kHz */ deleteCldfb_ivas_fx( &st->cldfbBPF ); /* delete analysis BPF at max. internal sampling rate 16kHz */ } - IF ( NE_16(st->element_mode, IVAS_CPE_MDCT) ) + IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { deallocate_CoreCoder_TCX( st ); } @@ -588,13 +588,13 @@ static void cpy_tcx_ltp_data_fx( move16(); hTcxLtpDecNew->tcxltp_filt_idx_prev = hTcxLtpDecOld->tcxltp_filt_idx_prev; move16(); - sz = BASOP_Util_Divide3232_Scale(TCXLTP_MAX_DELAY * output_Fs, 48000, &e); - sz = shr(sz, sub(15, e)); - mvs2s( hTcxLtpDecOld->tcxltp_mem_in, hTcxLtpDecNew->tcxltp_mem_in, sz ); // TODO: One of these will be removed later + sz = BASOP_Util_Divide3232_Scale( TCXLTP_MAX_DELAY * output_Fs, 48000, &e ); + sz = shr( sz, sub( 15, e ) ); + mvs2s( hTcxLtpDecOld->tcxltp_mem_in, hTcxLtpDecNew->tcxltp_mem_in, sz ); // TODO: One of these will be removed later mvl2l( hTcxLtpDecOld->tcxltp_mem_in_32, hTcxLtpDecNew->tcxltp_mem_in_32, sz ); - sz = BASOP_Util_Divide3232_Scale(( L_FRAME48k * output_Fs ), 48000, &e); - sz = shr(sz, sub(15, e)); - mvs2s( hTcxLtpDecOld->tcxltp_mem_out, hTcxLtpDecNew->tcxltp_mem_out, sz ); // TODO: One of these will be removed later + sz = BASOP_Util_Divide3232_Scale( ( L_FRAME48k * output_Fs ), 48000, &e ); + sz = shr( sz, sub( 15, e ) ); + mvs2s( hTcxLtpDecOld->tcxltp_mem_out, hTcxLtpDecNew->tcxltp_mem_out, sz ); // TODO: One of these will be removed later mvl2l( hTcxLtpDecOld->tcxltp_mem_out_32, hTcxLtpDecNew->tcxltp_mem_out_32, sz ); return; @@ -714,7 +714,7 @@ ivas_error stereo_memory_dec( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo ICBWE \n" ) ); } - stereo_icBWE_init_dec(hCPE->hStereoICBWE); + stereo_icBWE_init_dec( hCPE->hStereoICBWE ); } /* allocate HQ core */ @@ -823,7 +823,7 @@ ivas_error stereo_memory_dec( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo DFT mono output\n" ) ); } - stereo_dft_dmx_out_reset(hCPE->hStereoDftDmx); + stereo_dft_dmx_out_reset( hCPE->hStereoDftDmx ); } /* allocate TCA data structure */ @@ -1090,7 +1090,7 @@ ivas_error stereo_memory_dec( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo ICBWE \n" ) ); } - stereo_icBWE_init_dec(hCPE->hStereoICBWE); + stereo_icBWE_init_dec( hCPE->hStereoICBWE ); } } } @@ -1153,7 +1153,7 @@ ivas_error stereo_memory_dec( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo DFT mono output\n" ) ); } - stereo_dft_dmx_out_reset(hCPE->hStereoDftDmx); + stereo_dft_dmx_out_reset( hCPE->hStereoDftDmx ); } if ( hCPE->prev_synth_chs[1] != NULL ) @@ -1193,7 +1193,7 @@ ivas_error stereo_memory_dec( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo ICBWE \n" ) ); } - stereo_icBWE_init_dec(hCPE->hStereoICBWE); + stereo_icBWE_init_dec( hCPE->hStereoICBWE ); } if ( hCPE->hStereoTCA == NULL && ( hCPE->element_mode == IVAS_CPE_DFT || hCPE->element_mode == IVAS_CPE_TD ) ) @@ -1268,11 +1268,11 @@ ivas_error stereo_memory_dec( #else ivas_error stereo_memory_dec_fx( const Word32 ivas_total_brate, /* i : IVAS total bitrate */ - CPE_DEC_HANDLE hCPE, /* i : CPE decoder structure */ + CPE_DEC_HANDLE hCPE, /* i : CPE decoder structure */ const Word16 nb_bits_metadata, /* i : number of metadata bits */ const Word32 output_Fs, /* i : output sampling rate */ - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const MC_MODE mc_mode, /* i : MC mode */ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const MC_MODE mc_mode, /* i : MC mode */ const Word16 nchan_transport /* i : number of transport channels*/ ) { @@ -1283,7 +1283,7 @@ ivas_error stereo_memory_dec_fx( error = IVAS_ERR_OK; - assert( GE_16(hCPE->last_element_mode, IVAS_CPE_DFT) && "Switching from SCE to CPE is not a valid configuration!" ); + assert( GE_16( hCPE->last_element_mode, IVAS_CPE_DFT ) && "Switching from SCE to CPE is not a valid configuration!" ); hCPE->hCoreCoder[0]->element_mode = hCPE->element_mode; @@ -1296,57 +1296,57 @@ ivas_error stereo_memory_dec_fx( *---------------------------------------------------------------*/ /* handling of DFT->TD switching */ - IF ( EQ_16(hCPE->last_element_mode, IVAS_CPE_DFT) && ( EQ_16(hCPE->element_mode, IVAS_CPE_TD) || EQ_16(hCPE->element_mode, IVAS_CPE_MDCT) ) ) + IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) && ( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) || EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) ) ) { delay_comp_DFT = NS2SA( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ); move16(); /* redressing of the DFT OLA part */ - FOR ( n = 0; n < CPE_CHANNELS; n++ ) + FOR( n = 0; n < CPE_CHANNELS; n++ ) { - FOR ( i = delay_comp_DFT; i < hCPE->hStereoDft->dft32ms_ovl; i++ ) + FOR( i = delay_comp_DFT; i < hCPE->hStereoDft->dft32ms_ovl; i++ ) { - div_m = BASOP_Util_Divide3216_Scale(hCPE->output_mem_fx[n][sub(i, delay_comp_DFT)], hCPE->hStereoDft->win32ms_fx[i_mult(STEREO_DFT32MS_STEP, (sub(add(sub(hCPE->hStereoDft->dft32ms_ovl, 1), delay_comp_DFT), i)))], &div_e); - hCPE->output_mem_fx[n][sub(i, delay_comp_DFT)] = L_shl(div_m, add(div_e, 16)); + div_m = BASOP_Util_Divide3216_Scale( hCPE->output_mem_fx[n][sub( i, delay_comp_DFT )], hCPE->hStereoDft->win32ms_fx[i_mult( STEREO_DFT32MS_STEP, ( sub( add( sub( hCPE->hStereoDft->dft32ms_ovl, 1 ), delay_comp_DFT ), i ) ) )], &div_e ); + hCPE->output_mem_fx[n][sub( i, delay_comp_DFT )] = L_shl( div_m, add( div_e, 16 ) ); // hCPE->output_mem_fx[n][sub(i, delay_comp_DFT)] = hCPE->hStereoDft->win32ms_fx[i_mult(STEREO_DFT32MS_STEP, ( sub(add(sub(hCPE->hStereoDft->dft32ms_ovl, 1), delay_comp_DFT), i) ))]; } } - IF ( NE_16(hCPE->hCoreCoder[0]->last_core, ACELP_CORE) ) + IF( NE_16( hCPE->hCoreCoder[0]->last_core, ACELP_CORE ) ) { - mvl2l( hCPE->hStereoDft->buff_LBTCX_mem_fx, hCPE->input_mem_LB_fx[0], NS2SA( i_mult(hCPE->hCoreCoder[0]->last_L_frame, FRAMES_PER_SEC), STEREO_DFT32MS_OVL_NS ) ); + mvl2l( hCPE->hStereoDft->buff_LBTCX_mem_fx, hCPE->input_mem_LB_fx[0], NS2SA( i_mult( hCPE->hCoreCoder[0]->last_L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) ); } } - IF ( EQ_16(hCPE->last_element_mode, IVAS_CPE_MDCT) && EQ_16(hCPE->element_mode, IVAS_CPE_DFT) ) + IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) && EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { v_add_32( hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, hCPE->hCoreCoder[1]->hHQ_core->oldOut_fx, hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, (int16_t) ( output_Fs / FRAMES_PER_SEC ) ); - v_multc_fixed_16( hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, 16384 /* 0.5 in Q15 */ , hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, (int16_t) ( output_Fs / FRAMES_PER_SEC ) ); + v_multc_fixed_16( hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, 16384 /* 0.5 in Q15 */, hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, (int16_t) ( output_Fs / FRAMES_PER_SEC ) ); v_add_32( hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, hCPE->hCoreCoder[1]->hHQ_core->old_outLB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, L_FRAME32k ); v_multc_fixed_16( hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, 16384, hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, L_FRAME32k ); } - + /*--------------------------------------------------------------* * allocate/deallocate data structures *---------------------------------------------------------------*/ - IF ( NE_16(hCPE->element_mode, hCPE->last_element_mode) ) + IF( NE_16( hCPE->element_mode, hCPE->last_element_mode ) ) { /*--------------------------------------------------------------* * switching CPE mode to DFT stereo *---------------------------------------------------------------*/ - IF ( EQ_16(hCPE->element_mode, IVAS_CPE_DFT) ) + IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { /* deallocate data structure of the previous CPE mode */ - IF ( hCPE->hStereoTD != NULL ) + IF( hCPE->hStereoTD != NULL ) { free( hCPE->hStereoTD ); hCPE->hStereoTD = NULL; } - IF ( hCPE->hStereoMdct != NULL ) + IF( hCPE->hStereoMdct != NULL ) { free( hCPE->hStereoMdct ); hCPE->hStereoMdct = NULL; @@ -1354,39 +1354,38 @@ ivas_error stereo_memory_dec_fx( /* deallocate secondary channel */ deallocate_CoreCoder_fx( hCPE->hCoreCoder[1] ); - + /* allocate DFT stereo data structure */ - IF ( NE_16( ( error = stereo_dft_dec_create_fx( &( hCPE->hStereoDft ), hCPE->element_brate, output_Fs, 0, nchan_transport ) ), IVAS_ERR_OK ) ) + IF( NE_16( ( error = stereo_dft_dec_create_fx( &( hCPE->hStereoDft ), hCPE->element_brate, output_Fs, 0, nchan_transport ) ), IVAS_ERR_OK ) ) { return error; } - IF ( EQ_16(hCPE->last_element_mode, IVAS_CPE_MDCT) ) + IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) ) { cpy_tcx_ltp_data_fx( hCPE->hCoreCoder[1]->hTcxLtpDec, hCPE->hStereoDft->hTcxLtpDec, output_Fs ); deleteFdCngDec_fx( &hCPE->hCoreCoder[1]->hFdCngDec ); } - + /* memory update - needed in TD stereo, TCX/HQ frame -> DFT stereo, ACELP frame switching */ mvl2l( hCPE->input_mem_LB_fx[0], hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA( s_min( hCPE->hCoreCoder[0]->last_L_frame * FRAMES_PER_SEC, 16000 ), STEREO_DFT32MS_OVL_NS ) ); /* allocate ICBWE structure */ - IF ( hCPE->hStereoICBWE == NULL ) + IF( hCPE->hStereoICBWE == NULL ) { - IF ( ( hCPE->hStereoICBWE = (STEREO_ICBWE_DEC_HANDLE) malloc( sizeof( STEREO_ICBWE_DEC_DATA ) ) ) == NULL ) + IF( ( hCPE->hStereoICBWE = (STEREO_ICBWE_DEC_HANDLE) malloc( sizeof( STEREO_ICBWE_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo ICBWE \n" ) ); } - stereo_icBWE_init_dec_fx(hCPE->hStereoICBWE); - + stereo_icBWE_init_dec_fx( hCPE->hStereoICBWE ); } /* allocate HQ core */ st = hCPE->hCoreCoder[0]; - IF ( st->hHQ_core == NULL ) + IF( st->hHQ_core == NULL ) { - IF ( ( st->hHQ_core = (HQ_DEC_HANDLE) malloc( sizeof( HQ_DEC_DATA ) ) ) == NULL ) + IF( ( st->hHQ_core = (HQ_DEC_HANDLE) malloc( sizeof( HQ_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HQ core\n" ) ); } @@ -1395,34 +1394,34 @@ ivas_error stereo_memory_dec_fx( } /* allocate TD CNG handle */ - IF ( EQ_16(st->idchan, 0) && st->hTdCngDec == NULL ) + IF( EQ_16( st->idchan, 0 ) && st->hTdCngDec == NULL ) { - IF ( ( st->hTdCngDec = (TD_CNG_DEC_HANDLE) malloc( sizeof( TD_CNG_DEC_DATA ) ) ) == NULL ) + IF( ( st->hTdCngDec = (TD_CNG_DEC_HANDLE) malloc( sizeof( TD_CNG_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX/TD CNG\n" ) ); } td_cng_dec_init_fx( st ); #if 1 // TODO: To be removed later - //td_cng_dec_init( st ); + // td_cng_dec_init( st ); #endif } } - + /*--------------------------------------------------------------* * switching CPE mode to TD stereo *---------------------------------------------------------------*/ - IF ( EQ_16(hCPE->element_mode, IVAS_CPE_TD) ) + IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) ) { /* deallocate data structure of the previous CPE mode */ - IF ( hCPE->hStereoDft != NULL ) + IF( hCPE->hStereoDft != NULL ) { stereo_dft_dec_destroy( &( hCPE->hStereoDft ) ); hCPE->hStereoDft = NULL; } - IF ( hCPE->hStereoMdct != NULL ) + IF( hCPE->hStereoMdct != NULL ) { free( hCPE->hStereoMdct ); hCPE->hStereoMdct = NULL; @@ -1431,18 +1430,18 @@ ivas_error stereo_memory_dec_fx( /* deallocated TCX/IGF structures for second channel */ deallocate_CoreCoder_TCX( hCPE->hCoreCoder[1] ); - IF ( EQ_16(hCPE->last_element_mode, IVAS_CPE_MDCT) ) + IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) ) { deleteFdCngDec_fx( &hCPE->hCoreCoder[1]->hFdCngDec ); } /* allocate TD stereo data structure */ - IF ( hCPE->hStereoTD != NULL ) + IF( hCPE->hStereoTD != NULL ) { return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error: TD Stereo memory already allocated\n" ); } - IF ( ( hCPE->hStereoTD = (STEREO_TD_DEC_DATA_HANDLE) malloc( sizeof( STEREO_TD_DEC_DATA ) ) ) == NULL ) + IF( ( hCPE->hStereoTD = (STEREO_TD_DEC_DATA_HANDLE) malloc( sizeof( STEREO_TD_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD Stereo\n" ) ); } @@ -1450,7 +1449,7 @@ ivas_error stereo_memory_dec_fx( stereo_td_init_dec_fx( hCPE->hStereoTD, hCPE->last_element_mode ); /* allocate CoreCoder secondary channel */ - IF ( NE_16(( error = allocate_CoreCoder_fx( hCPE->hCoreCoder[1] ) ), IVAS_ERR_OK) ) + IF( NE_16( ( error = allocate_CoreCoder_fx( hCPE->hCoreCoder[1] ) ), IVAS_ERR_OK ) ) { return error; } @@ -1460,17 +1459,17 @@ ivas_error stereo_memory_dec_fx( * allocate DFT/TD stereo structures after MDCT stereo frame *---------------------------------------------------------------*/ - IF ( EQ_16(hCPE->last_element_mode, IVAS_CPE_MDCT) && ( EQ_16(hCPE->element_mode, IVAS_CPE_DFT) || EQ_16(hCPE->element_mode, IVAS_CPE_TD) ) ) + IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) && ( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) || EQ_16( hCPE->element_mode, IVAS_CPE_TD ) ) ) { /* deallocated TCX-LTP for second channel */ st = hCPE->hCoreCoder[1]; - IF ( st->hTcxLtpDec != NULL ) + IF( st->hTcxLtpDec != NULL ) { free( st->hTcxLtpDec ); st->hTcxLtpDec = NULL; } - IF ( EQ_16(st->element_mode, IVAS_CPE_TD) ) + IF( EQ_16( st->element_mode, IVAS_CPE_TD ) ) { /* re-use an existing buffer for MDCT->TD stereo switching */ Word16 nZeros, len; @@ -1482,48 +1481,46 @@ ivas_error stereo_memory_dec_fx( } /* deallocated HQ-core for second channel */ - IF ( st->hHQ_core != NULL ) + IF( st->hHQ_core != NULL ) { free( st->hHQ_core ); st->hHQ_core = NULL; } /* allocate DFT stereo mono DMX data structure */ - IF ( EQ_16(hCPE->nchan_out, 1) && hCPE->hStereoDftDmx == NULL ) + IF( EQ_16( hCPE->nchan_out, 1 ) && hCPE->hStereoDftDmx == NULL ) { - IF ( ( hCPE->hStereoDftDmx = (STEREO_DFT_DMX_DATA_HANDLE) malloc( sizeof( STEREO_DFT_DMX_DATA ) ) ) == NULL ) + IF( ( hCPE->hStereoDftDmx = (STEREO_DFT_DMX_DATA_HANDLE) malloc( sizeof( STEREO_DFT_DMX_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo DFT mono output\n" ) ); } - stereo_dft_dmx_out_reset_fx(hCPE->hStereoDftDmx); - + stereo_dft_dmx_out_reset_fx( hCPE->hStereoDftDmx ); } /* allocate TCA data structure */ - IF ( NE_16(hCPE->nchan_out, 1) && hCPE->hStereoTCA == NULL ) + IF( NE_16( hCPE->nchan_out, 1 ) && hCPE->hStereoTCA == NULL ) { - IF ( ( hCPE->hStereoTCA = (STEREO_TCA_DEC_HANDLE) malloc( sizeof( STEREO_TCA_DEC_DATA ) ) ) == NULL ) + IF( ( hCPE->hStereoTCA = (STEREO_TCA_DEC_HANDLE) malloc( sizeof( STEREO_TCA_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo TCA\n" ) ); } stereo_tca_init_dec_fx( hCPE->hStereoTCA ); - } st = hCPE->hCoreCoder[0]; /* allocate primary channel substructures */ - IF ( NE_16(( error = allocate_CoreCoder_fx( st ) ), IVAS_ERR_OK) ) + IF( NE_16( ( error = allocate_CoreCoder_fx( st ) ), IVAS_ERR_OK ) ) { return error; } /* allocate BWEs for primary channel */ - IF ( st->hBWE_TD == NULL ) + IF( st->hBWE_TD == NULL ) { - IF ( ( st->hBWE_TD = (TD_BWE_DEC_HANDLE) malloc( sizeof( TD_BWE_DEC_DATA ) ) ) == NULL ) + IF( ( st->hBWE_TD = (TD_BWE_DEC_HANDLE) malloc( sizeof( TD_BWE_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD BWE\n" ) ); } @@ -1535,7 +1532,7 @@ ivas_error stereo_memory_dec_fx( st->prev_ener_fx_Q = 31; st->prev_frame_pow_exp = 0; - IF ( ( st->hBWE_FD = (FD_BWE_DEC_HANDLE) malloc( sizeof( FD_BWE_DEC_DATA ) ) ) == NULL ) + IF( ( st->hBWE_FD = (FD_BWE_DEC_HANDLE) malloc( sizeof( FD_BWE_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FD BWE\n" ) ); } @@ -1548,19 +1545,19 @@ ivas_error stereo_memory_dec_fx( move16(); #if 1 // TODO: To be removed later - //fd_bwe_dec_init_flt( st->hBWE_FD ); + // fd_bwe_dec_init_flt( st->hBWE_FD ); #endif - fd_bwe_dec_init(st, st->hBWE_FD); + fd_bwe_dec_init( st, st->hBWE_FD ); st->hBWE_FD->old_wtda_swb_fx_exp = 0; st->hBWE_FD->mem_imdct_exp_fx = 0; st->prev_Q_synth = 0; } /* Allocated FD_CNG instance for primary channel*/ - IF ( st->hFdCngDec == NULL ) + IF( st->hFdCngDec == NULL ) { /* Create FD_CNG instance */ - IF ( ( error = createFdCngDec_fx( &st->hFdCngDec ) ) != IVAS_ERR_OK ) + IF( ( error = createFdCngDec_fx( &st->hFdCngDec ) ) != IVAS_ERR_OK ) { return error; } @@ -1571,9 +1568,9 @@ ivas_error stereo_memory_dec_fx( } /* allocate stereo CNG structure */ - IF ( hCPE->hStereoCng == NULL ) + IF( hCPE->hStereoCng == NULL ) { - IF ( ( hCPE->hStereoCng = (STEREO_CNG_DEC_HANDLE) malloc( sizeof( STEREO_CNG_DEC ) ) ) == NULL ) + IF( ( hCPE->hStereoCng = (STEREO_CNG_DEC_HANDLE) malloc( sizeof( STEREO_CNG_DEC ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo CNG\n" ) ); } @@ -1585,54 +1582,54 @@ ivas_error stereo_memory_dec_fx( * switching CPE mode to MDCT stereo *---------------------------------------------------------------*/ - IF ( EQ_16(hCPE->element_mode, IVAS_CPE_MDCT) ) + IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) ) { Word32 tmpF_buff[L_FRAME16k / 2]; TCX_LTP_DEC_DATA tcxLtpTmp; - IF ( EQ_16(hCPE->last_element_mode, IVAS_CPE_TD) ) + IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_TD ) ) { mvl2l( hCPE->hStereoTD->TCX_old_syn_Overl_fx, tmpF_buff, L_FRAME16k / 2 ); } - IF ( EQ_16(hCPE->last_element_mode, IVAS_CPE_DFT) ) + IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) ) { cpy_tcx_ltp_data_fx( hCPE->hStereoDft->hTcxLtpDec, &tcxLtpTmp, output_Fs ); } /* deallocate data structure of the previous CPE mode */ - IF ( hCPE->hStereoDft != NULL ) + IF( hCPE->hStereoDft != NULL ) { stereo_dft_dec_destroy( &( hCPE->hStereoDft ) ); hCPE->hStereoDft = NULL; } - IF ( hCPE->hStereoTD != NULL ) + IF( hCPE->hStereoTD != NULL ) { free( hCPE->hStereoTD ); hCPE->hStereoTD = NULL; } - IF ( hCPE->hStereoDftDmx != NULL ) + IF( hCPE->hStereoDftDmx != NULL ) { free( hCPE->hStereoDftDmx ); hCPE->hStereoDftDmx = NULL; } - IF ( hCPE->hStereoICBWE != NULL ) + IF( hCPE->hStereoICBWE != NULL ) { free( hCPE->hStereoICBWE ); hCPE->hStereoICBWE = NULL; } /* de-allocate stereo CNG structure */ - IF ( hCPE->hStereoCng != NULL ) + IF( hCPE->hStereoCng != NULL ) { free( hCPE->hStereoCng ); hCPE->hStereoCng = NULL; } - FOR ( i = 0; i < CPE_CHANNELS; i++ ) + FOR( i = 0; i < CPE_CHANNELS; i++ ) { st = hCPE->hCoreCoder[i]; st->element_mode = hCPE->element_mode; @@ -1648,49 +1645,49 @@ ivas_error stereo_memory_dec_fx( /* allocate CLDFB structures for second channel */ st = hCPE->hCoreCoder[1]; - IF ( st->cldfbAna == NULL ) + IF( st->cldfbAna == NULL ) { - IF ( NE_16(( error = openCldfb_ivas_fx( &st->cldfbAna, CLDFB_ANALYSIS, 48000, CLDFB_PROTOTYPE_1_25MS ) ), IVAS_ERR_OK) ) + IF( NE_16( ( error = openCldfb_ivas_fx( &st->cldfbAna, CLDFB_ANALYSIS, 48000, CLDFB_PROTOTYPE_1_25MS ) ), IVAS_ERR_OK ) ) { return error; } } - IF ( st->cldfbBPF == NULL ) + IF( st->cldfbBPF == NULL ) { /* open analysis BPF for max. internal sampling rate 16kHz */ - IF ( NE_16(( error = openCldfb_ivas_fx( &st->cldfbBPF, CLDFB_ANALYSIS, 16000, CLDFB_PROTOTYPE_1_25MS ) ), IVAS_ERR_OK) ) + IF( NE_16( ( error = openCldfb_ivas_fx( &st->cldfbBPF, CLDFB_ANALYSIS, 16000, CLDFB_PROTOTYPE_1_25MS ) ), IVAS_ERR_OK ) ) { return error; } } /* allocate Fd-Cng structure for second channel */ - IF ( NE_16(( error = createFdCngDec_fx( &st->hFdCngDec ) ), IVAS_ERR_OK) ) + IF( NE_16( ( error = createFdCngDec_fx( &st->hFdCngDec ) ), IVAS_ERR_OK ) ) { return error; } /* Init FD-CNG */ - initFdCngDec_ivas_fx( st, st->cldfbSyn->scale); + initFdCngDec_ivas_fx( st, st->cldfbSyn->scale ); #if 1 // TODO: To be removed later initFdCngDec( st ); #endif - IF ( EQ_16(hCPE->last_element_mode, IVAS_CPE_DFT) ) + IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) ) { st->last_core = ACELP_CORE; /* needed to set-up TCX core in SetTCXModeInfo() */ } /*Allocate CoreCoder TCX modules for second channel */ - IF ( NE_16(( error = allocate_CoreCoder_TCX_fx( hCPE->hCoreCoder[1] ) ), IVAS_ERR_OK) ) + IF( NE_16( ( error = allocate_CoreCoder_TCX_fx( hCPE->hCoreCoder[1] ) ), IVAS_ERR_OK ) ) { return error; } - IF ( EQ_16(hCPE->last_element_mode, IVAS_CPE_DFT) ) + IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) ) { - IF ( EQ_16(hCPE->nchan_out, 1) ) + IF( EQ_16( hCPE->nchan_out, 1 ) ) { cpy_tcx_ltp_data_fx( hCPE->hCoreCoder[0]->hTcxLtpDec, hCPE->hCoreCoder[1]->hTcxLtpDec, output_Fs ); } @@ -1700,28 +1697,28 @@ ivas_error stereo_memory_dec_fx( } } - IF ( EQ_16(hCPE->last_element_mode, IVAS_CPE_TD) ) + IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_TD ) ) { mvl2l( tmpF_buff, st->hTcxDec->old_syn_Overl_32, L_FRAME16k / 2 ); } - set16_fx(st->hTcxDec->FBTCXdelayBuf, 0, 111); - set32_fx(st->hTcxDec->FBTCXdelayBuf_32, 0, 111); - st->hTcxDec->old_synthFB_fx = st->hTcxDec->synth_history_fx + NS2SA(st->output_Fs, PH_ECU_MEM_NS); - st->hTcxDec->prev_good_synth_fx = st->hTcxDec->old_synthFB_fx + NS2SA(st->output_Fs, PH_ECU_LOOKAHEAD_NS); + set16_fx( st->hTcxDec->FBTCXdelayBuf, 0, 111 ); + set32_fx( st->hTcxDec->FBTCXdelayBuf_32, 0, 111 ); + st->hTcxDec->old_synthFB_fx = st->hTcxDec->synth_history_fx + NS2SA( st->output_Fs, PH_ECU_MEM_NS ); + st->hTcxDec->prev_good_synth_fx = st->hTcxDec->old_synthFB_fx + NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ); #if 1 // To be removed later - //set_f( st->hTcxDec->FBTCXdelayBuf_float, 0.0f, 111 ); - //st->hTcxDec->old_synthFB = st->hTcxDec->synth_history + NS2SA( st->output_Fs, PH_ECU_MEM_NS ); - //st->hTcxDec->prev_good_synth = st->hTcxDec->old_synthFB + NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ); + // set_f( st->hTcxDec->FBTCXdelayBuf_float, 0.0f, 111 ); + // st->hTcxDec->old_synthFB = st->hTcxDec->synth_history + NS2SA( st->output_Fs, PH_ECU_MEM_NS ); + // st->hTcxDec->prev_good_synth = st->hTcxDec->old_synthFB + NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ); #endif /* allocate and initialize MDCT stereo structure */ - IF ( ( hCPE->hStereoMdct = (STEREO_MDCT_DEC_DATA_HANDLE) malloc( sizeof( STEREO_MDCT_DEC_DATA ) ) ) == NULL ) + IF( ( hCPE->hStereoMdct = (STEREO_MDCT_DEC_DATA_HANDLE) malloc( sizeof( STEREO_MDCT_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n" ) ); } - IF ( EQ_16(ivas_format, STEREO_FORMAT) && hCPE->element_brate <= MAX_MDCT_ITD_BRATE ) + IF( EQ_16( ivas_format, STEREO_FORMAT ) && hCPE->element_brate <= MAX_MDCT_ITD_BRATE ) { hCPE->hStereoMdct->use_itd = 1; move16(); @@ -1735,7 +1732,6 @@ ivas_error stereo_memory_dec_fx( move16(); hCPE->hStereoMdct->smooth_ratio_fx = ONE_IN_Q26; move32(); - } } @@ -1743,26 +1739,26 @@ ivas_error stereo_memory_dec_fx( * normal TD / LRTD switching *---------------------------------------------------------------*/ - IF ( EQ_16(hCPE->element_mode, IVAS_CPE_TD) ) + IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) ) { - IF ( EQ_16(hCPE->hCoreCoder[0]->bfi, 0) ) + IF( EQ_16( hCPE->hCoreCoder[0]->bfi, 0 ) ) { st = hCPE->hCoreCoder[1]; hCPE->hStereoTD->tdm_LRTD_flag = get_indice_st( hCPE->hCoreCoder[0], hCPE->element_brate + hCPE->brate_surplus, (int16_t) ( ( hCPE->element_brate / FRAMES_PER_SEC ) - nb_bits_metadata + ( hCPE->brate_surplus / FRAMES_PER_SEC ) - TDM_SECONDARY_SIGNALLING - TDM_RATIO_BITS - TDM_LP_REUSE_BITS - TDM_LR_CONTENT_BITS ), TDM_LR_CONTENT_BITS ); - IF ( NE_16(hCPE->hStereoTD->tdm_LRTD_flag, 0) ) + IF( NE_16( hCPE->hStereoTD->tdm_LRTD_flag, 0 ) ) { /* deallocate ICBWE structure */ - IF ( hCPE->hStereoICBWE != NULL ) + IF( hCPE->hStereoICBWE != NULL ) { free( hCPE->hStereoICBWE ); hCPE->hStereoICBWE = NULL; } /* allocate BWEs for secondary channel */ - IF ( st->hBWE_TD == NULL ) + IF( st->hBWE_TD == NULL ) { - IF ( ( st->hBWE_TD = (TD_BWE_DEC_HANDLE) malloc( sizeof( TD_BWE_DEC_DATA ) ) ) == NULL ) + IF( ( st->hBWE_TD = (TD_BWE_DEC_HANDLE) malloc( sizeof( TD_BWE_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD BWE\n" ) ); } @@ -1774,7 +1770,7 @@ ivas_error stereo_memory_dec_fx( st->prev_ener_fx_Q = 31; st->prev_frame_pow_exp = 0; - IF ( ( st->hBWE_FD = (FD_BWE_DEC_HANDLE) malloc( sizeof( FD_BWE_DEC_DATA ) ) ) == NULL ) + IF( ( st->hBWE_FD = (FD_BWE_DEC_HANDLE) malloc( sizeof( FD_BWE_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FD BWE\n" ) ); } @@ -1787,9 +1783,9 @@ ivas_error stereo_memory_dec_fx( move16(); #if 1 // TODO: To be removed later - //fd_bwe_dec_init_flt( st->hBWE_FD ); + // fd_bwe_dec_init_flt( st->hBWE_FD ); #endif - fd_bwe_dec_init(st, st->hBWE_FD); + fd_bwe_dec_init( st, st->hBWE_FD ); st->hBWE_FD->old_wtda_swb_fx_exp = 0; st->hBWE_FD->mem_imdct_exp_fx = 0; st->prev_Q_synth = 0; @@ -1798,15 +1794,15 @@ ivas_error stereo_memory_dec_fx( ELSE /* tdm_LRTD_flag == 0 */ { /* deallocate BWEs for secondary channel */ - IF ( st->hBWE_TD != NULL ) + IF( st->hBWE_TD != NULL ) { - IF ( st->hBWE_TD != NULL ) + IF( st->hBWE_TD != NULL ) { free( st->hBWE_TD ); st->hBWE_TD = NULL; } - IF ( st->hBWE_FD != NULL ) + IF( st->hBWE_FD != NULL ) { free( st->hBWE_FD ); st->hBWE_FD = NULL; @@ -1814,14 +1810,14 @@ ivas_error stereo_memory_dec_fx( } /* allocate ICBWE structure */ - IF ( hCPE->hStereoICBWE == NULL ) + IF( hCPE->hStereoICBWE == NULL ) { - IF ( ( hCPE->hStereoICBWE = (STEREO_ICBWE_DEC_HANDLE) malloc( sizeof( STEREO_ICBWE_DEC_DATA ) ) ) == NULL ) + IF( ( hCPE->hStereoICBWE = (STEREO_ICBWE_DEC_HANDLE) malloc( sizeof( STEREO_ICBWE_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo ICBWE \n" ) ); } - stereo_icBWE_init_dec_fx(hCPE->hStereoICBWE); + stereo_icBWE_init_dec_fx( hCPE->hStereoICBWE ); } } } @@ -1831,16 +1827,16 @@ ivas_error stereo_memory_dec_fx( * MDCT stereo bitrate switching *---------------------------------------------------------------*/ - IF ( EQ_16(ivas_format, STEREO_FORMAT) && EQ_16(hCPE->element_mode, IVAS_CPE_MDCT) ) + IF( EQ_16( ivas_format, STEREO_FORMAT ) && EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) ) { - IF ( LE_32(hCPE->element_brate, MAX_MDCT_ITD_BRATE) && GT_32(ivas_total_brate, IVAS_SID_5k2) ) + IF( LE_32( hCPE->element_brate, MAX_MDCT_ITD_BRATE ) && GT_32( ivas_total_brate, IVAS_SID_5k2 ) ) { - IF ( EQ_16(hCPE->hStereoMdct->use_itd, 0) ) + IF( EQ_16( hCPE->hStereoMdct->use_itd, 0 ) ) { - IF ( hCPE->hStereoTCA == NULL ) + IF( hCPE->hStereoTCA == NULL ) { /* allocate TCA data structure */ - IF ( ( hCPE->hStereoTCA = (STEREO_TCA_DEC_HANDLE) malloc( sizeof( STEREO_TCA_DEC_DATA ) ) ) == NULL ) + IF( ( hCPE->hStereoTCA = (STEREO_TCA_DEC_HANDLE) malloc( sizeof( STEREO_TCA_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo TCA\n" ) ); } @@ -1855,14 +1851,14 @@ ivas_error stereo_memory_dec_fx( ELSE { /* de-allocate TCA data structure */ - IF ( hCPE->hStereoMdct->use_itd == 1 && ivas_total_brate > IVAS_SID_5k2 && hCPE->hStereoTCA != NULL ) + IF( hCPE->hStereoMdct->use_itd == 1 && ivas_total_brate > IVAS_SID_5k2 && hCPE->hStereoTCA != NULL ) { free( hCPE->hStereoTCA ); hCPE->hStereoTCA = NULL; hCPE->hStereoMdct->use_itd = 0; move16(); } - ELSE IF ( hCPE->hStereoMdct->use_itd == 1 && ivas_total_brate <= IVAS_SID_5k2 ) + ELSE IF( hCPE->hStereoMdct->use_itd == 1 && ivas_total_brate <= IVAS_SID_5k2 ) { hCPE->hStereoMdct->itd_fx = 0; move32(); @@ -1879,27 +1875,27 @@ ivas_error stereo_memory_dec_fx( * Bitrate switching in MASA format *---------------------------------------------------------------*/ - IF ( ( EQ_16(ivas_format, MASA_FORMAT) || EQ_16(ivas_format, MASA_ISM_FORMAT) ) && EQ_16(nchan_transport, 2) ) + IF( ( EQ_16( ivas_format, MASA_FORMAT ) || EQ_16( ivas_format, MASA_ISM_FORMAT ) ) && EQ_16( nchan_transport, 2 ) ) { - IF ( EQ_16(hCPE->nchan_out, 1) ) + IF( EQ_16( hCPE->nchan_out, 1 ) ) { - IF ( hCPE->hStereoDftDmx == NULL ) + IF( hCPE->hStereoDftDmx == NULL ) { - IF ( ( hCPE->hStereoDftDmx = (STEREO_DFT_DMX_DATA_HANDLE) malloc( sizeof( STEREO_DFT_DMX_DATA ) ) ) == NULL ) + IF( ( hCPE->hStereoDftDmx = (STEREO_DFT_DMX_DATA_HANDLE) malloc( sizeof( STEREO_DFT_DMX_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo DFT mono output\n" ) ); } - stereo_dft_dmx_out_reset_fx(hCPE->hStereoDftDmx); + stereo_dft_dmx_out_reset_fx( hCPE->hStereoDftDmx ); } - IF (hCPE->prev_synth_chs_fx[1] != NULL) + IF( hCPE->prev_synth_chs_fx[1] != NULL ) { - free(hCPE->prev_synth_chs_fx[1]); - hCPE->prev_synth_chs_fx[1] = NULL; + free( hCPE->prev_synth_chs_fx[1] ); + hCPE->prev_synth_chs_fx[1] = NULL; } - IF ( hCPE->hStereoTCA != NULL ) + IF( hCPE->hStereoTCA != NULL ) { free( hCPE->hStereoTCA ); hCPE->hStereoTCA = NULL; @@ -1907,35 +1903,35 @@ ivas_error stereo_memory_dec_fx( } ELSE /* nchan_out == 2 */ { - IF ( hCPE->hStereoDftDmx != NULL ) + IF( hCPE->hStereoDftDmx != NULL ) { free( hCPE->hStereoDftDmx ); hCPE->hStereoDftDmx = NULL; } - IF (hCPE->prev_synth_chs_fx[1] == NULL) + IF( hCPE->prev_synth_chs_fx[1] == NULL ) { - st = hCPE->hCoreCoder[1]; - IF ((hCPE->prev_synth_chs_fx[1] = (Word32 *)malloc(sizeof(Word32) * NS2SA(st->output_Fs, FRAME_SIZE_NS))) == NULL) - { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DFT stereo memory\n")); - } - set32_fx(hCPE->prev_synth_chs_fx[1],0, NS2SA(st->output_Fs, FRAME_SIZE_NS)); + st = hCPE->hCoreCoder[1]; + IF( ( hCPE->prev_synth_chs_fx[1] = (Word32 *) malloc( sizeof( Word32 ) * NS2SA( st->output_Fs, FRAME_SIZE_NS ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DFT stereo memory\n" ) ); + } + set32_fx( hCPE->prev_synth_chs_fx[1], 0, NS2SA( st->output_Fs, FRAME_SIZE_NS ) ); } - IF ( hCPE->hStereoICBWE == NULL && EQ_16(hCPE->element_mode, IVAS_CPE_DFT) ) + IF( hCPE->hStereoICBWE == NULL && EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { - IF ( ( hCPE->hStereoICBWE = (STEREO_ICBWE_DEC_HANDLE) malloc( sizeof( STEREO_ICBWE_DEC_DATA ) ) ) == NULL ) + IF( ( hCPE->hStereoICBWE = (STEREO_ICBWE_DEC_HANDLE) malloc( sizeof( STEREO_ICBWE_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo ICBWE \n" ) ); } - stereo_icBWE_init_dec_fx(hCPE->hStereoICBWE); + stereo_icBWE_init_dec_fx( hCPE->hStereoICBWE ); } - IF ( hCPE->hStereoTCA == NULL && ( EQ_16(hCPE->element_mode, IVAS_CPE_DFT) || EQ_16(hCPE->element_mode, IVAS_CPE_TD) ) ) + IF( hCPE->hStereoTCA == NULL && ( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) || EQ_16( hCPE->element_mode, IVAS_CPE_TD ) ) ) { - IF ( ( hCPE->hStereoTCA = (STEREO_TCA_DEC_HANDLE) malloc( sizeof( STEREO_TCA_DEC_DATA ) ) ) == NULL ) + IF( ( hCPE->hStereoTCA = (STEREO_TCA_DEC_HANDLE) malloc( sizeof( STEREO_TCA_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo TCA\n" ) ); } @@ -1943,16 +1939,16 @@ ivas_error stereo_memory_dec_fx( stereo_tca_init_dec_fx( hCPE->hStereoTCA ); } - IF ( EQ_16(hCPE->element_mode, IVAS_CPE_MDCT) ) + IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) ) { - IF ( hCPE->hStereoTCA != NULL ) + IF( hCPE->hStereoTCA != NULL ) { /* note: in MASA, hCPE->hStereoMdct->itd = 0 */ free( hCPE->hStereoTCA ); hCPE->hStereoTCA = NULL; } - IF ( hCPE->hStereoICBWE != NULL ) + IF( hCPE->hStereoICBWE != NULL ) { free( hCPE->hStereoICBWE ); hCPE->hStereoICBWE = NULL; @@ -1965,12 +1961,12 @@ ivas_error stereo_memory_dec_fx( * Bitrate switching in MASA format *---------------------------------------------------------------*/ - IF ( EQ_16(ivas_format, MC_FORMAT) && EQ_16(hCPE->element_mode, IVAS_CPE_MDCT) ) + IF( EQ_16( ivas_format, MC_FORMAT ) && EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) ) { - IF ( EQ_16(mc_mode, MC_MODE_MCT) || EQ_16(mc_mode, MC_MODE_PARAMUPMIX) ) + IF( EQ_16( mc_mode, MC_MODE_MCT ) || EQ_16( mc_mode, MC_MODE_PARAMUPMIX ) ) { /* deallocate the FdCNG handle */ - FOR ( i = 0; i < CPE_CHANNELS; ++i ) + FOR( i = 0; i < CPE_CHANNELS; ++i ) { deleteFdCngDec_fx( &hCPE->hCoreCoder[i]->hFdCngDec ); } @@ -1978,19 +1974,19 @@ ivas_error stereo_memory_dec_fx( ELSE { /* allocate the FdCNG handle (for noise estimation for TCX PLC fadeout)*/ - FOR ( i = 0; i < CPE_CHANNELS; ++i ) + FOR( i = 0; i < CPE_CHANNELS; ++i ) { - IF ( hCPE->hCoreCoder[i]->cldfbSyn == NULL ) /* could be NULL when we had the MCT LFE channel */ + IF( hCPE->hCoreCoder[i]->cldfbSyn == NULL ) /* could be NULL when we had the MCT LFE channel */ { - IF ( NE_16(( error = openCldfb_ivas_fx( &hCPE->hCoreCoder[i]->cldfbSyn, CLDFB_SYNTHESIS, hCPE->hCoreCoder[i]->output_Fs, CLDFB_PROTOTYPE_1_25MS ) ), IVAS_ERR_OK) ) + IF( NE_16( ( error = openCldfb_ivas_fx( &hCPE->hCoreCoder[i]->cldfbSyn, CLDFB_SYNTHESIS, hCPE->hCoreCoder[i]->output_Fs, CLDFB_PROTOTYPE_1_25MS ) ), IVAS_ERR_OK ) ) { return error; } } - IF ( hCPE->hCoreCoder[i]->hFdCngDec == NULL ) + IF( hCPE->hCoreCoder[i]->hFdCngDec == NULL ) { - IF ( NE_16(( error = createFdCngDec_fx( &hCPE->hCoreCoder[i]->hFdCngDec ) ), IVAS_ERR_OK) ) + IF( NE_16( ( error = createFdCngDec_fx( &hCPE->hCoreCoder[i]->hFdCngDec ) ), IVAS_ERR_OK ) ) { return error; } @@ -2946,7 +2942,7 @@ void stereo_switching_dec( { FOR( i = 0; i < dft32ms_ovl; i++ ) { - hCPE->output_mem_fx[n][i] = Mpy_32_16_1(hCPE->output_mem_fx[n][i], hCPE->hStereoDft->win32ms_fx[STEREO_DFT32MS_STEP * (dft32ms_ovl - 1 - i)]); + hCPE->output_mem_fx[n][i] = Mpy_32_16_1( hCPE->output_mem_fx[n][i], hCPE->hStereoDft->win32ms_fx[STEREO_DFT32MS_STEP * ( dft32ms_ovl - 1 - i )] ); } } ELSE @@ -2964,15 +2960,15 @@ void stereo_switching_dec( } FOR( i = 0; i < dft32ms_ovl; i++ ) { - Word32 temp_result = Mpy_32_16_1(tmpF_fx, hCPE->hStereoDft->win32ms_fx[STEREO_DFT32MS_STEP * (dft32ms_ovl - 1 - i)]); + Word32 temp_result = Mpy_32_16_1( tmpF_fx, hCPE->hStereoDft->win32ms_fx[STEREO_DFT32MS_STEP * ( dft32ms_ovl - 1 - i )] ); hCPE->output_mem_fx[n][i] = L_shl_sat( Mpy_32_32( hCPE->output_mem_fx[n][i], temp_result ), 4 ); } FOR( i = 0; i < delay_comp_TD; i++ ) { Word64 temp_result; // 16bit buffer - //temp_result = (Word64) hCPE->hCoreCoder[1]->prev_synth_buffer_fx[i] * tmpF_fx; - //hCPE->hCoreCoder[1]->prev_synth_buffer_fx[i] = saturate( W_extract_l(W_shr( temp_result, 27 )) ); + // temp_result = (Word64) hCPE->hCoreCoder[1]->prev_synth_buffer_fx[i] * tmpF_fx; + // hCPE->hCoreCoder[1]->prev_synth_buffer_fx[i] = saturate( W_extract_l(W_shr( temp_result, 27 )) ); // 32bit buffer temp_result = (Word64) hCPE->hCoreCoder[1]->prev_synth_buffer32_fx[i] * tmpF_fx; hCPE->hCoreCoder[1]->prev_synth_buffer32_fx[i] = W_sat_l( W_shr( temp_result, 27 ) ); @@ -3056,22 +3052,22 @@ void stereo_switching_dec( cldfb_reset_memory_fx( sts[0]->cldfbBPF ); cldfb_reset_memory_fx( sts[0]->cldfbSyn ); - //sts[0]->mem_deemph = 0; + // sts[0]->mem_deemph = 0; sts[0]->mem_deemph_fx = 0; #ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED - //sts[0]->tilt_code = 0.0f; - //sts[0]->gc_threshold = 0.0f; + // sts[0]->tilt_code = 0.0f; + // sts[0]->gc_threshold = 0.0f; #endif sts[0]->tilt_code_fx = 0; sts[0]->gc_threshold_fx = 0; #ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED - //set_f( sts[0]->mem_syn1, 0, M ); - //set_f( sts[0]->mem_syn2, 0, M ); - //set_f( sts[0]->mem_syn3, 0, M ); - //set_f( sts[0]->mem_syn_r_float, 0.0f, L_SYN_MEM ); + // set_f( sts[0]->mem_syn1, 0, M ); + // set_f( sts[0]->mem_syn2, 0, M ); + // set_f( sts[0]->mem_syn3, 0, M ); + // set_f( sts[0]->mem_syn_r_float, 0.0f, L_SYN_MEM ); #endif set16_fx( sts[0]->mem_syn1_fx, 0, M ); @@ -3083,9 +3079,9 @@ void stereo_switching_dec( #ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED /* reset PCh memories */ - //set_f( sts[0]->old_exc, 0, L_EXC_MEM_DEC ); - //set_f( sts[0]->lsf_old, 0, M ); - //set_f( sts[0]->lsp_old, 0, M ); + // set_f( sts[0]->old_exc, 0, L_EXC_MEM_DEC ); + // set_f( sts[0]->lsf_old, 0, M ); + // set_f( sts[0]->lsp_old, 0, M ); #endif set16_fx( sts[0]->old_exc_fx, 0, L_EXC_MEM_DEC ); @@ -3097,7 +3093,7 @@ void stereo_switching_dec( sts[1]->prev_bfi = sts[0]->prev_bfi; #ifndef IVAS_FLOAT_FIXED - set_f(sts[1]->old_pitch_buf, (float)L_SUBFR, 2 * NB_SUBFR16k); + set_f( sts[1]->old_pitch_buf, (float) L_SUBFR, 2 * NB_SUBFR16k ); sts[1]->old_fpitchFB_float = 2 * (float) L_SUBFR; #endif // #ifndef IVAS_FLOAT_FIXED @@ -3116,21 +3112,21 @@ void stereo_switching_dec( cldfb_reset_memory_fx( sts[1]->cldfbBPF ); cldfb_reset_memory_fx( sts[1]->cldfbSyn ); - //sts[1]->mem_deemph = 0; + // sts[1]->mem_deemph = 0; sts[1]->mem_deemph_fx = 0; #ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED - //sts[1]->tilt_code = 0.0f; - //sts[1]->gc_threshold = 0.0f; + // sts[1]->tilt_code = 0.0f; + // sts[1]->gc_threshold = 0.0f; #endif sts[1]->tilt_code_fx = 0; sts[1]->gc_threshold_fx = 0; #ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED - //set_f( sts[1]->mem_syn1, 0, M ); - //set_f( sts[1]->mem_syn2, 0, M ); - //set_f( sts[1]->mem_syn3, 0, M ); - //set_f( sts[1]->mem_syn_r_float, 0.0f, L_SYN_MEM ); + // set_f( sts[1]->mem_syn1, 0, M ); + // set_f( sts[1]->mem_syn2, 0, M ); + // set_f( sts[1]->mem_syn3, 0, M ); + // set_f( sts[1]->mem_syn_r_float, 0.0f, L_SYN_MEM ); #endif set16_fx( sts[1]->mem_syn1_fx, 0, M ); @@ -3149,11 +3145,11 @@ void stereo_switching_dec( sts[1]->last_coder_type = sts[0]->last_coder_type; #ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED - //mvr2r( sts[0]->hHQ_core->old_out, sts[1]->hHQ_core->old_out, L_FRAME48k ); - //mvr2r( sts[0]->hTcxDec->old_syn_Overl_float, sts[1]->hTcxDec->old_syn_Overl_float, 256 ); + // mvr2r( sts[0]->hHQ_core->old_out, sts[1]->hHQ_core->old_out, L_FRAME48k ); + // mvr2r( sts[0]->hTcxDec->old_syn_Overl_float, sts[1]->hTcxDec->old_syn_Overl_float, 256 ); #endif #ifndef IVAS_FLOAT_FIXED - mvr2r(sts[0]->delay_buf_out, sts[1]->delay_buf_out, HQ_DELTA_MAX * HQ_DELAY_COMP); + mvr2r( sts[0]->delay_buf_out, sts[1]->delay_buf_out, HQ_DELTA_MAX * HQ_DELAY_COMP ); #endif // #ifndef IVAS_FLOAT_FIXED // 32bit buffer @@ -3169,8 +3165,8 @@ void stereo_switching_dec( ELSE IF( hCPE->element_mode == IVAS_CPE_TD && hCPE->last_element_mode == IVAS_CPE_MDCT ) { #ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED - //set_f( sts[0]->old_exc, 0.0f, L_EXC_MEM_DEC ); - //set_f( sts[1]->old_exc, 0.0f, L_EXC_MEM_DEC ); + // set_f( sts[0]->old_exc, 0.0f, L_EXC_MEM_DEC ); + // set_f( sts[1]->old_exc, 0.0f, L_EXC_MEM_DEC ); #endif set16_fx( sts[0]->old_exc_fx, 0, L_EXC_MEM_DEC ); set16_fx( sts[1]->old_exc_fx, 0, L_EXC_MEM_DEC ); @@ -3196,213 +3192,213 @@ void stereo_switching_dec( } #else void stereo_switching_dec( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - const int32_t ivas_total_brate /* i : IVAS total bitrate */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + const int32_t ivas_total_brate /* i : IVAS total bitrate */ ) { - int16_t i, n; - int16_t dft32ms_ovl; - Decoder_State **sts; - float tmpF; - int16_t delay_comp_TD; - - sts = hCPE->hCoreCoder; - - delay_comp_TD = NS2SA(sts[0]->output_Fs, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS); - - /* prevent CPE mode switching in the first received frame */ - if (sts[0]->ini_frame == 0) - { - hCPE->last_element_mode = hCPE->element_mode; - hCPE->stereo_switching_counter = 10; - hCPE->NbFrameMod = 7; - hCPE->lt_es_em = 0.0f; - } - - if (hCPE->element_mode == hCPE->last_element_mode) - { - hCPE->stereo_switching_counter++; - hCPE->stereo_switching_counter = min(10, hCPE->stereo_switching_counter); - } - else - { - hCPE->stereo_switching_counter = 0; - } - - if (hCPE->element_mode == IVAS_CPE_DFT && hCPE->nchan_out == 1 && hCPE->element_brate >= IVAS_32k && hCPE->last_element_brate <= IVAS_24k4) - { - dft32ms_ovl = (int16_t)((STEREO_DFT32MS_OVL_MAX * sts[0]->output_Fs) / 48000); - set_zero(hCPE->output_mem[0], dft32ms_ovl); - } - - if (hCPE->element_mode == IVAS_CPE_DFT && hCPE->last_element_mode != IVAS_CPE_DFT && hCPE->hCoreCoder[0]->ini_frame > 0) - { - /* windowing the OLA memory */ - dft32ms_ovl = (int16_t)((STEREO_DFT32MS_OVL_MAX * sts[0]->output_Fs) / 48000); - for (n = 0; n < CPE_CHANNELS; n++) + int16_t i, n; + int16_t dft32ms_ovl; + Decoder_State **sts; + float tmpF; + int16_t delay_comp_TD; + + sts = hCPE->hCoreCoder; + + delay_comp_TD = NS2SA( sts[0]->output_Fs, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ); + + /* prevent CPE mode switching in the first received frame */ + if ( sts[0]->ini_frame == 0 ) { - if (hCPE->last_element_mode == IVAS_CPE_MDCT) - { - /* copy memories from previous MDCT Stereo frame to output_mem */ - mvr2r(hCPE->input_mem[n], hCPE->output_mem[n], dft32ms_ovl); - } - - if (ivas_total_brate > IVAS_SID_5k2 || n == 0 || hCPE->last_element_mode != IVAS_CPE_TD || hCPE->nchan_out == 1) - { - for (i = 0; i < dft32ms_ovl; i++) - { - hCPE->output_mem[n][i] *= hCPE->hStereoDft->win32ms[STEREO_DFT32MS_STEP * (dft32ms_ovl - 1 - i)]; - } - } - else - { - tmpF = 1.0f / hCPE->hStereoTCA->prevTargetGain; - for (i = 0; i < dft32ms_ovl; i++) + hCPE->last_element_mode = hCPE->element_mode; + hCPE->stereo_switching_counter = 10; + hCPE->NbFrameMod = 7; + hCPE->lt_es_em = 0.0f; + } + + if ( hCPE->element_mode == hCPE->last_element_mode ) + { + hCPE->stereo_switching_counter++; + hCPE->stereo_switching_counter = min( 10, hCPE->stereo_switching_counter ); + } + else + { + hCPE->stereo_switching_counter = 0; + } + + if ( hCPE->element_mode == IVAS_CPE_DFT && hCPE->nchan_out == 1 && hCPE->element_brate >= IVAS_32k && hCPE->last_element_brate <= IVAS_24k4 ) + { + dft32ms_ovl = (int16_t) ( ( STEREO_DFT32MS_OVL_MAX * sts[0]->output_Fs ) / 48000 ); + set_zero( hCPE->output_mem[0], dft32ms_ovl ); + } + + if ( hCPE->element_mode == IVAS_CPE_DFT && hCPE->last_element_mode != IVAS_CPE_DFT && hCPE->hCoreCoder[0]->ini_frame > 0 ) + { + /* windowing the OLA memory */ + dft32ms_ovl = (int16_t) ( ( STEREO_DFT32MS_OVL_MAX * sts[0]->output_Fs ) / 48000 ); + for ( n = 0; n < CPE_CHANNELS; n++ ) { - hCPE->output_mem[n][i] *= tmpF * hCPE->hStereoDft->win32ms[STEREO_DFT32MS_STEP * (dft32ms_ovl - 1 - i)]; + if ( hCPE->last_element_mode == IVAS_CPE_MDCT ) + { + /* copy memories from previous MDCT Stereo frame to output_mem */ + mvr2r( hCPE->input_mem[n], hCPE->output_mem[n], dft32ms_ovl ); + } + + if ( ivas_total_brate > IVAS_SID_5k2 || n == 0 || hCPE->last_element_mode != IVAS_CPE_TD || hCPE->nchan_out == 1 ) + { + for ( i = 0; i < dft32ms_ovl; i++ ) + { + hCPE->output_mem[n][i] *= hCPE->hStereoDft->win32ms[STEREO_DFT32MS_STEP * ( dft32ms_ovl - 1 - i )]; + } + } + else + { + tmpF = 1.0f / hCPE->hStereoTCA->prevTargetGain; + for ( i = 0; i < dft32ms_ovl; i++ ) + { + hCPE->output_mem[n][i] *= tmpF * hCPE->hStereoDft->win32ms[STEREO_DFT32MS_STEP * ( dft32ms_ovl - 1 - i )]; + } + for ( i = 0; i < delay_comp_TD; i++ ) + { + hCPE->hCoreCoder[1]->prev_synth_buffer[i] *= tmpF; + } + for ( i = 0; i < L_DEC_MEM_LEN_ICA; i++ ) + { + hCPE->hStereoTCA->memChanR[i] *= tmpF; + } + } } - for (i = 0; i < delay_comp_TD; i++) + + if ( hCPE->last_element_mode == IVAS_CPE_MDCT ) { - hCPE->hCoreCoder[1]->prev_synth_buffer[i] *= tmpF; + /* create passive downmix of MDCT Stereo memories for DFT input memory */ + v_add( hCPE->input_mem_LB[0], hCPE->input_mem_LB[1], hCPE->input_mem_LB[0], STEREO_DFT32MS_OVL_16k ); + v_multc( hCPE->input_mem_LB[0], 0.5f, hCPE->input_mem_LB[0], STEREO_DFT32MS_OVL_16k ); + + v_add( hCPE->input_mem[0], hCPE->input_mem[1], hCPE->input_mem[0], dft32ms_ovl ); + v_multc( hCPE->input_mem[0], 0.5f, hCPE->input_mem[0], dft32ms_ovl ); + + if ( hCPE->nchan_out == 1 ) + { + v_add( hCPE->output_mem[0], hCPE->output_mem[1], hCPE->output_mem[0], dft32ms_ovl ); + v_multc( hCPE->output_mem[0], INV_SQRT_2, hCPE->output_mem[0], dft32ms_ovl ); + } } - for (i = 0; i < L_DEC_MEM_LEN_ICA; i++) + + /* Update the side_gain[] parameters */ + if ( hCPE->last_element_mode != IVAS_CPE_MDCT ) { - hCPE->hStereoTCA->memChanR[i] *= tmpF; + tmpF = 0; + if ( hCPE->hStereoTCA != NULL ) + { + tmpF = usdequant( hCPE->hStereoTCA->indx_ica_gD, STEREO_TCA_GDMIN, STEREO_TCA_GDSTEP ); + } + + set_f( hCPE->hStereoDft->side_gain + STEREO_DFT_NBDIV * STEREO_DFT_BAND_MAX, tmpF, STEREO_DFT_BAND_MAX ); } - } - } - if (hCPE->last_element_mode == IVAS_CPE_MDCT) - { - /* create passive downmix of MDCT Stereo memories for DFT input memory */ - v_add(hCPE->input_mem_LB[0], hCPE->input_mem_LB[1], hCPE->input_mem_LB[0], STEREO_DFT32MS_OVL_16k); - v_multc(hCPE->input_mem_LB[0], 0.5f, hCPE->input_mem_LB[0], STEREO_DFT32MS_OVL_16k); - - v_add(hCPE->input_mem[0], hCPE->input_mem[1], hCPE->input_mem[0], dft32ms_ovl); - v_multc(hCPE->input_mem[0], 0.5f, hCPE->input_mem[0], dft32ms_ovl); - - if (hCPE->nchan_out == 1) - { - v_add(hCPE->output_mem[0], hCPE->output_mem[1], hCPE->output_mem[0], dft32ms_ovl); - v_multc(hCPE->output_mem[0], INV_SQRT_2, hCPE->output_mem[0], dft32ms_ovl); - } + /* reset residual coding / ESF (secondary channel) */ + set_zero( hCPE->hStereoDft->res_cod_mem, STEREO_DFT_OVL_8k ); + set_zero( hCPE->input_mem[1], NS2SA( sts[0]->output_Fs, STEREO_DFT32MS_OVL_NS ) ); } - /* Update the side_gain[] parameters */ - if (hCPE->last_element_mode != IVAS_CPE_MDCT) + if ( hCPE->element_mode == IVAS_CPE_TD && hCPE->last_element_mode != IVAS_CPE_TD && hCPE->hCoreCoder[0]->ini_frame > 0 ) { - tmpF = 0; - if (hCPE->hStereoTCA != NULL) - { - tmpF = usdequant(hCPE->hStereoTCA->indx_ica_gD, STEREO_TCA_GDMIN, STEREO_TCA_GDSTEP); - } + hCPE->hStereoTD->tdm_last_ratio_idx = LRTD_STEREO_MID_IS_PRIM; + hCPE->hStereoTD->tdm_last_SM_flag = 0; + hCPE->hStereoTD->tdm_prev_last_SM_flag = 0; - set_f(hCPE->hStereoDft->side_gain + STEREO_DFT_NBDIV * STEREO_DFT_BAND_MAX, tmpF, STEREO_DFT_BAND_MAX); + /* First frame after DFT frame AND the content is uncorrelated or xtalk -> the primary channel is forced to left */ + if ( hCPE->hStereoTD->tdm_LRTD_flag == 1 ) + { + hCPE->hStereoTD->tdm_last_ratio_idx = LRTD_STEREO_LEFT_IS_PRIM; + } } - /* reset residual coding / ESF (secondary channel) */ - set_zero(hCPE->hStereoDft->res_cod_mem, STEREO_DFT_OVL_8k); - set_zero(hCPE->input_mem[1], NS2SA(sts[0]->output_Fs, STEREO_DFT32MS_OVL_NS)); - } - - if (hCPE->element_mode == IVAS_CPE_TD && hCPE->last_element_mode != IVAS_CPE_TD && hCPE->hCoreCoder[0]->ini_frame > 0) - { - hCPE->hStereoTD->tdm_last_ratio_idx = LRTD_STEREO_MID_IS_PRIM; - hCPE->hStereoTD->tdm_last_SM_flag = 0; - hCPE->hStereoTD->tdm_prev_last_SM_flag = 0; - - /* First frame after DFT frame AND the content is uncorrelated or xtalk -> the primary channel is forced to left */ - if (hCPE->hStereoTD->tdm_LRTD_flag == 1) + /* no secondary channel in the previous frame -> memory resets */ + if ( hCPE->element_mode > IVAS_CPE_DFT && hCPE->last_element_mode == IVAS_CPE_DFT ) { - hCPE->hStereoTD->tdm_last_ratio_idx = LRTD_STEREO_LEFT_IS_PRIM; - } - } + if ( hCPE->last_element_brate <= IVAS_SID_5k2 && hCPE->nchan_out == 2 ) + { + /* reset CLDFB memories */ + cldfb_reset_memory_ivas( sts[0]->cldfbAna ); + cldfb_reset_memory_ivas( sts[0]->cldfbBPF ); + cldfb_reset_memory_ivas( sts[0]->cldfbSyn ); - /* no secondary channel in the previous frame -> memory resets */ - if (hCPE->element_mode > IVAS_CPE_DFT && hCPE->last_element_mode == IVAS_CPE_DFT) - { - if (hCPE->last_element_brate <= IVAS_SID_5k2 && hCPE->nchan_out == 2) - { - /* reset CLDFB memories */ - cldfb_reset_memory_ivas(sts[0]->cldfbAna); - cldfb_reset_memory_ivas(sts[0]->cldfbBPF); - cldfb_reset_memory_ivas(sts[0]->cldfbSyn); + sts[0]->mem_deemph = 0; - sts[0]->mem_deemph = 0; + sts[0]->tilt_code = 0.0f; + sts[0]->gc_threshold = 0.0f; - sts[0]->tilt_code = 0.0f; - sts[0]->gc_threshold = 0.0f; + set_f( sts[0]->mem_syn1, 0, M ); + set_f( sts[0]->mem_syn2, 0, M ); + set_f( sts[0]->mem_syn3, 0, M ); + set_f( sts[0]->mem_syn_r_float, 0.0f, L_SYN_MEM ); - set_f(sts[0]->mem_syn1, 0, M); - set_f(sts[0]->mem_syn2, 0, M); - set_f(sts[0]->mem_syn3, 0, M); - set_f(sts[0]->mem_syn_r_float, 0.0f, L_SYN_MEM); + sts[1]->last_L_frame = sts[0]->last_L_frame; - sts[1]->last_L_frame = sts[0]->last_L_frame; + /* reset PCh memories */ + set_f( sts[0]->old_exc, 0, L_EXC_MEM_DEC ); + set_f( sts[0]->lsf_old, 0, M ); + set_f( sts[0]->lsp_old, 0, M ); + } + sts[1]->last_extl = -1; - /* reset PCh memories */ - set_f(sts[0]->old_exc, 0, L_EXC_MEM_DEC); - set_f(sts[0]->lsf_old, 0, M); - set_f(sts[0]->lsp_old, 0, M); - } - sts[1]->last_extl = -1; + sts[1]->prev_bfi = sts[0]->prev_bfi; - sts[1]->prev_bfi = sts[0]->prev_bfi; + set_f( sts[1]->old_pitch_buf, (float) L_SUBFR, 2 * NB_SUBFR16k ); + sts[1]->old_fpitchFB_float = 2 * (float) L_SUBFR; - set_f(sts[1]->old_pitch_buf, (float)L_SUBFR, 2 * NB_SUBFR16k); - sts[1]->old_fpitchFB_float = 2 * (float)L_SUBFR; + /* reset CLDFB memories */ + cldfb_reset_memory_ivas( sts[1]->cldfbAna ); + cldfb_reset_memory_ivas( sts[1]->cldfbBPF ); + cldfb_reset_memory_ivas( sts[1]->cldfbSyn ); - /* reset CLDFB memories */ - cldfb_reset_memory_ivas(sts[1]->cldfbAna); - cldfb_reset_memory_ivas(sts[1]->cldfbBPF); - cldfb_reset_memory_ivas(sts[1]->cldfbSyn); + sts[1]->mem_deemph = 0; - sts[1]->mem_deemph = 0; + sts[1]->tilt_code = 0.0f; + sts[1]->gc_threshold = 0.0f; - sts[1]->tilt_code = 0.0f; - sts[1]->gc_threshold = 0.0f; + set_f( sts[1]->mem_syn1, 0, M ); + set_f( sts[1]->mem_syn2, 0, M ); + set_f( sts[1]->mem_syn3, 0, M ); + set_f( sts[1]->mem_syn_r_float, 0.0f, L_SYN_MEM ); - set_f(sts[1]->mem_syn1, 0, M); - set_f(sts[1]->mem_syn2, 0, M); - set_f(sts[1]->mem_syn3, 0, M); - set_f(sts[1]->mem_syn_r_float, 0.0f, L_SYN_MEM); + sts[1]->last_L_frame = sts[0]->last_L_frame; - sts[1]->last_L_frame = sts[0]->last_L_frame; + /* populate PCh memories into the SCh */ + mvr2r( sts[0]->old_exc, sts[1]->old_exc, L_EXC_MEM_DEC ); + mvr2r( sts[0]->lsf_old, sts[1]->lsf_old, M ); + mvr2r( sts[0]->lsp_old, sts[1]->lsp_old, M ); + if ( hCPE->element_mode == IVAS_CPE_MDCT ) + { + sts[1]->last_core = sts[0]->last_core; + sts[1]->last_coder_type = sts[0]->last_coder_type; - /* populate PCh memories into the SCh */ - mvr2r(sts[0]->old_exc, sts[1]->old_exc, L_EXC_MEM_DEC); - mvr2r(sts[0]->lsf_old, sts[1]->lsf_old, M); - mvr2r(sts[0]->lsp_old, sts[1]->lsp_old, M); - if (hCPE->element_mode == IVAS_CPE_MDCT) + mvr2r( sts[0]->hHQ_core->old_out, sts[1]->hHQ_core->old_out, L_FRAME48k ); + mvr2r( sts[0]->delay_buf_out, sts[1]->delay_buf_out, HQ_DELTA_MAX * HQ_DELAY_COMP ); + mvr2r( sts[0]->hTcxDec->old_syn_Overl_float, sts[1]->hTcxDec->old_syn_Overl_float, 256 ); + } + } + else if ( hCPE->element_mode == IVAS_CPE_TD && hCPE->last_element_mode == IVAS_CPE_MDCT ) { - sts[1]->last_core = sts[0]->last_core; - sts[1]->last_coder_type = sts[0]->last_coder_type; + set_f( sts[0]->old_exc, 0.0f, L_EXC_MEM_DEC ); + set_f( sts[1]->old_exc, 0.0f, L_EXC_MEM_DEC ); + } - mvr2r(sts[0]->hHQ_core->old_out, sts[1]->hHQ_core->old_out, L_FRAME48k); - mvr2r(sts[0]->delay_buf_out, sts[1]->delay_buf_out, HQ_DELTA_MAX * HQ_DELAY_COMP); - mvr2r(sts[0]->hTcxDec->old_syn_Overl_float, sts[1]->hTcxDec->old_syn_Overl_float, 256); + /* TD/DFT -> MDCT stereo switching (there is no TCX in the TD stereo secondary channel, or DFT stereo) */ + if ( hCPE->element_mode == IVAS_CPE_MDCT && hCPE->last_element_mode != IVAS_CPE_MDCT ) + { + sts[1]->hTcxCfg->last_aldo = sts[0]->hTcxCfg->last_aldo; + sts[1]->hTcxCfg->tcx_curr_overlap_mode = sts[0]->hTcxCfg->tcx_curr_overlap_mode; + sts[1]->fscale = sts[0]->fscale; + sts[1]->hTcxCfg->tcx_mdct_window_length = sts[0]->hTcxCfg->tcx_mdct_window_length; + sts[1]->pit_res_max = sts[0]->pit_res_max; + sts[1]->pit_res_max_past = sts[0]->pit_res_max_past; + sts[1]->hTcxDec->L_frameTCX = sts[0]->hTcxDec->L_frameTCX; + sts[1]->hTcxDec->conceal_eof_gain_float = sts[0]->hTcxDec->conceal_eof_gain_float; } - } - else if (hCPE->element_mode == IVAS_CPE_TD && hCPE->last_element_mode == IVAS_CPE_MDCT) - { - set_f(sts[0]->old_exc, 0.0f, L_EXC_MEM_DEC); - set_f(sts[1]->old_exc, 0.0f, L_EXC_MEM_DEC); - } - - /* TD/DFT -> MDCT stereo switching (there is no TCX in the TD stereo secondary channel, or DFT stereo) */ - if (hCPE->element_mode == IVAS_CPE_MDCT && hCPE->last_element_mode != IVAS_CPE_MDCT) - { - sts[1]->hTcxCfg->last_aldo = sts[0]->hTcxCfg->last_aldo; - sts[1]->hTcxCfg->tcx_curr_overlap_mode = sts[0]->hTcxCfg->tcx_curr_overlap_mode; - sts[1]->fscale = sts[0]->fscale; - sts[1]->hTcxCfg->tcx_mdct_window_length = sts[0]->hTcxCfg->tcx_mdct_window_length; - sts[1]->pit_res_max = sts[0]->pit_res_max; - sts[1]->pit_res_max_past = sts[0]->pit_res_max_past; - sts[1]->hTcxDec->L_frameTCX = sts[0]->hTcxDec->L_frameTCX; - sts[1]->hTcxDec->conceal_eof_gain_float = sts[0]->hTcxDec->conceal_eof_gain_float; - } - - return; + + return; } #endif /*-------------------------------------------------------------------* @@ -4288,4 +4284,4 @@ void smooth_dft2td_transition_fx( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/ivas_stereo_td_dec.c b/lib_dec/ivas_stereo_td_dec.c index 25e578a58..ffb63c5ce 100644 --- a/lib_dec/ivas_stereo_td_dec.c +++ b/lib_dec/ivas_stereo_td_dec.c @@ -89,11 +89,11 @@ void stereo_td_init_dec_fx( hStereoTD->tdm_last_ratio_idx = LRTD_STEREO_MID_IS_PRIM; hStereoTD->tdm_prev_last_SM_flag = 0; hStereoTD->tdm_LRTD_flag = 0; - //hStereoTD->prevSP_ratio = 0.5f; + // hStereoTD->prevSP_ratio = 0.5f; hStereoTD->prevSP_ratio_fx = ONE_IN_Q14; //.5 - //hStereoTD->SP_ratio_LT = 0.0f; + // hStereoTD->SP_ratio_LT = 0.0f; hStereoTD->SP_ratio_LT_fx = 0; - //hStereoTD->c_LR_LT = 0.5f; + // hStereoTD->c_LR_LT = 0.5f; hStereoTD->c_LR_LT_fx = ONE_IN_Q30; //.5 hStereoTD->flag_skip_DMX = 0; @@ -1238,4 +1238,4 @@ void stereo_tdm_combine_fx( } return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/ivas_svd_dec.c b/lib_dec/ivas_svd_dec.c index a107a4614..98d876cad 100644 --- a/lib_dec/ivas_svd_dec.c +++ b/lib_dec/ivas_svd_dec.c @@ -47,7 +47,7 @@ *-----------------------------------------------------------------------*/ /* The SVD is sensitive to changes to the following constants, so please be careful when trying to tune things */ -#define SVD_MAX_NUM_ITERATION 75 /* maximum number of interations before exiting the SVD */ +#define SVD_MAX_NUM_ITERATION 75 /* maximum number of interations before exiting the SVD */ #ifndef IVAS_FLOAT_FIXED #ifdef NONBE_FIX_1069_SVD_TUNING #define SVD_MINIMUM_VALUE 1e-32f /* minimum value */ @@ -59,7 +59,7 @@ #define SVD_ZERO_FLUSH_THRESHOLD 1.0e-20f #endif #else -#define SVD_MINIMUM_VALUE_FX ( 2 ) /* minimum value */ +#define SVD_MINIMUM_VALUE_FX ( 2 ) /* minimum value */ #define SVD_ZERO_FLUSH_THRESHOLD_FX ( 0 ) #define CONVERGENCE_FACTOR_FX 214748 /* factor for SVD convergence (as per latest float code: 1.0e-04f) */ #endif @@ -103,7 +103,7 @@ static void HouseholderReduction_fx( const int16_t nChannelsL, const int16_t nChannelsC, Word32 *eps_x_fx, - Word16 *eps_x_fx_e); + Word16 *eps_x_fx_e ); static void biDiagonalReductionLeft_fx( Word32 singularVectors[][MAX_OUTPUT_CHANNELS], @@ -117,7 +117,7 @@ static void biDiagonalReductionLeft_fx( const Word16 currChannel, Word32 *sig_x, Word16 *sig_x_e, - Word32 *g); // Q31 + Word32 *g ); // Q31 static void biDiagonalReductionRight_fx( Word32 singularVectors[][MAX_OUTPUT_CHANNELS], @@ -129,26 +129,26 @@ static void biDiagonalReductionRight_fx( const Word16 currChannel, Word32 *sig_x, Word16 *sig_x_e, - Word32 *g); //Q31 + Word32 *g ); // Q31 static void singularVectorsAccumulationLeft_fx( - Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], //Q31 output + Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], // Q31 output Word32 singularValues[MAX_OUTPUT_CHANNELS], Word16 singularVectors_e, Word16 singularValues_e, const Word16 nChannelsL, - const Word16 nChannelsC); + const Word16 nChannelsC ); static void singularVectorsAccumulationRight_fx( Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], - Word32 singularVectors_Right[][MAX_OUTPUT_CHANNELS], //Q31 output + Word32 singularVectors_Right[][MAX_OUTPUT_CHANNELS], // Q31 output Word32 secDiag[MAX_OUTPUT_CHANNELS], Word16 singularVectors_e, Word16 secDiag_e, - const Word16 nChannelsC); + const Word16 nChannelsC ); static Word32 maxWithSign_fx( - const Word32 a); + const Word32 a ); #if 0 static void flushToZeroArray_fx( @@ -166,12 +166,12 @@ static Word16 BidagonalDiagonalisation_fx( Word32 singularValues_fx[MAX_OUTPUT_CHANNELS], /* i/o: singular values vector (S) */ Word32 singularVectors_Right_fx[][MAX_OUTPUT_CHANNELS], /* i/o: right singular vectors (V) Q31 */ Word32 secDiag_fx[MAX_OUTPUT_CHANNELS], /* i/o: */ - Word16 *singularValues_fx_e, /* i/o: singular values vector (S) */ - Word16 *secDiag_fx_e, /* i/o: */ - const Word16 nChannelsL, /* i : number of rows in the matrix to be decomposed */ - const Word16 nChannelsC, /* i : number of columns in the matrix to be decomposed */ - const Word32 eps_x, /* i : */ - const Word16 eps_x_e /* i : */ + Word16 *singularValues_fx_e, /* i/o: singular values vector (S) */ + Word16 *secDiag_fx_e, /* i/o: */ + const Word16 nChannelsL, /* i : number of rows in the matrix to be decomposed */ + const Word16 nChannelsC, /* i : number of columns in the matrix to be decomposed */ + const Word32 eps_x, /* i : */ + const Word16 eps_x_e /* i : */ ); static void ApplyRotation_fx( @@ -190,14 +190,14 @@ static void ApplyRotation_fx( Word16 *g_e, const Word16 currentIndex1, const Word16 currentIndex2, - const Word16 nChannels); + const Word16 nChannels ); static Word32 GivensRotation_fx( const Word32 x, const Word16 x_e, const Word32 z, const Word16 z_e, - Word16 *out_e); + Word16 *out_e ); static void ApplyQRTransform_fx( Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], /* i/o: left singular vectors (U) Q31 */ @@ -206,10 +206,10 @@ static void ApplyQRTransform_fx( Word32 secDiag[MAX_OUTPUT_CHANNELS], /* i/o: */ Word16 singularValues_e[MAX_OUTPUT_CHANNELS], Word16 secDiag_e[MAX_OUTPUT_CHANNELS], - const Word16 startIndex, /* i : */ - const Word16 currentIndex, /* i : */ - const Word16 nChannelsL, /* i : number of rows in the matrix to be decomposed */ - const Word16 nChannelsC /* i : number of columns in the matrix to be decomposed */ + const Word16 startIndex, /* i : */ + const Word16 currentIndex, /* i : */ + const Word16 nChannelsL, /* i : number of rows in the matrix to be decomposed */ + const Word16 nChannelsC /* i : number of columns in the matrix to be decomposed */ ); #endif @@ -230,11 +230,11 @@ void mat2svdMat_fx( { Word16 i, j; - IF ( transpose ) + IF( transpose ) { - FOR ( i = 0; i < mCols; i++ ) + FOR( i = 0; i < mCols; i++ ) { - FOR ( j = 0; j < nRows; j++ ) + FOR( j = 0; j < nRows; j++ ) { svdMat[i][j] = mat[j + nRows * i]; } @@ -242,16 +242,16 @@ void mat2svdMat_fx( set_zero_fx( &svdMat[i][mCols], MAX_OUTPUT_CHANNELS - nRows ); } - FOR ( ; i < MAX_OUTPUT_CHANNELS; i++ ) + FOR( ; i < MAX_OUTPUT_CHANNELS; i++ ) { set_zero_fx( svdMat[i], MAX_OUTPUT_CHANNELS ); } } ELSE { - FOR ( i = 0; i < nRows; i++ ) + FOR( i = 0; i < nRows; i++ ) { - FOR ( j = 0; j < mCols; j++ ) + FOR( j = 0; j < mCols; j++ ) { svdMat[i][j] = mat[i + nRows * j]; } @@ -259,7 +259,7 @@ void mat2svdMat_fx( set_zero_fx( &svdMat[i][mCols], MAX_OUTPUT_CHANNELS - mCols ); } - FOR ( ; i < MAX_OUTPUT_CHANNELS; i++ ) + FOR( ; i < MAX_OUTPUT_CHANNELS; i++ ) { set_zero_fx( svdMat[i], MAX_OUTPUT_CHANNELS ); } @@ -284,9 +284,9 @@ void svdMat2mat_fx( { Word16 i, j; - FOR ( i = 0; i < nRows; i++ ) + FOR( i = 0; i < nRows; i++ ) { - FOR ( j = 0; j < mCols; j++ ) + FOR( j = 0; j < mCols; j++ ) { mat[i + nRows * j] = svdMat[i][j]; } @@ -387,34 +387,34 @@ void svdMat2mat( *-------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED - /*! r: error or success */ +/*! r: error or success */ Word16 svd_fx( - Word32 InputMatrix[][MAX_OUTPUT_CHANNELS], /* i : matrix to be decomposed (M) */ + Word32 InputMatrix[][MAX_OUTPUT_CHANNELS], /* i : matrix to be decomposed (M) */ Word16 InputMatrix_e, Word32 singularVectors_Left_fx[][MAX_OUTPUT_CHANNELS], /* o : left singular vectors (U) (Q31) */ Word32 singularValues_fx[MAX_OUTPUT_CHANNELS], /* o : singular values vector (S) */ Word32 singularVectors_Right_fx[][MAX_OUTPUT_CHANNELS], /* o : right singular vectors (V) (Q31) */ Word16 *singularValues_fx_e, - const Word16 nChannelsL, /* i : number of rows in the matrix to be decomposed */ - const Word16 nChannelsC /* i : number of columns in the matrix to be decomposed */ + const Word16 nChannelsL, /* i : number of rows in the matrix to be decomposed */ + const Word16 nChannelsC /* i : number of columns in the matrix to be decomposed */ ) { Word16 iCh, jCh; Word16 lengthSingularValues; Word16 errorMessage, condition; - //int16_t max_length = ((nChannelsL > nChannelsC) ? nChannelsL : nChannelsC); + // int16_t max_length = ((nChannelsL > nChannelsC) ? nChannelsL : nChannelsC); Word32 secDiag_fx[MAX_OUTPUT_CHANNELS]; Word16 secDiag_fx_e = 0; Word32 eps_x_fx = 0, temp_fx; Word16 eps_x_fx_e = 0; - push_wmops("svd_fx"); + push_wmops( "svd_fx" ); - set32_fx(secDiag_fx, 0, MAX_OUTPUT_CHANNELS); + set32_fx( secDiag_fx, 0, MAX_OUTPUT_CHANNELS ); /* Collecting Values */ - FOR(iCh = 0; iCh < nChannelsL; iCh++) + FOR( iCh = 0; iCh < nChannelsL; iCh++ ) { - FOR(jCh = 0; jCh < nChannelsC; jCh++) + FOR( jCh = 0; jCh < nChannelsC; jCh++ ) { singularVectors_Left_fx[iCh][jCh] = InputMatrix[iCh][jCh]; } @@ -423,18 +423,18 @@ Word16 svd_fx( *singularValues_fx_e = 0; /* Householder reduction */ - HouseholderReduction_fx(singularVectors_Left_fx, singularValues_fx, singularVectors_Right_fx, secDiag_fx, InputMatrix_e, singularValues_fx_e, &secDiag_fx_e, nChannelsL, nChannelsC, &eps_x_fx, &eps_x_fx_e); + HouseholderReduction_fx( singularVectors_Left_fx, singularValues_fx, singularVectors_Right_fx, secDiag_fx, InputMatrix_e, singularValues_fx_e, &secDiag_fx_e, nChannelsL, nChannelsC, &eps_x_fx, &eps_x_fx_e ); /* Set extremely small values to zero if needed */ - //flushToZeroArray(singularValues, max_length); - //flushToZeroMat(singularVectors_Left, nChannelsL, nChannelsL); - //flushToZeroMat(singularVectors_Right, nChannelsC, nChannelsC); + // flushToZeroArray(singularValues, max_length); + // flushToZeroMat(singularVectors_Left, nChannelsL, nChannelsL); + // flushToZeroMat(singularVectors_Right, nChannelsC, nChannelsC); /* BidagonalDiagonalisation */ - errorMessage = BidagonalDiagonalisation_fx( singularVectors_Left_fx, singularValues_fx, singularVectors_Right_fx, secDiag_fx, singularValues_fx_e, &secDiag_fx_e, nChannelsL, nChannelsC, eps_x_fx, eps_x_fx_e); + errorMessage = BidagonalDiagonalisation_fx( singularVectors_Left_fx, singularValues_fx, singularVectors_Right_fx, secDiag_fx, singularValues_fx_e, &secDiag_fx_e, nChannelsL, nChannelsC, eps_x_fx, eps_x_fx_e ); /* Sort the singular values descending order */ - lengthSingularValues = min(nChannelsL, nChannelsC); + lengthSingularValues = min( nChannelsL, nChannelsC ); DO { @@ -448,14 +448,14 @@ Word16 svd_fx( singularValues_fx[iCh] = singularValues_fx[iCh + 1]; singularValues_fx[iCh + 1] = temp_fx; - FOR(jCh = 0; jCh < nChannelsL; ++jCh) + FOR( jCh = 0; jCh < nChannelsL; ++jCh ) { temp_fx = singularVectors_Left_fx[jCh][iCh]; singularVectors_Left_fx[jCh][iCh] = singularVectors_Left_fx[jCh][iCh + 1]; singularVectors_Left_fx[jCh][iCh + 1] = temp_fx; } - FOR(jCh = 0; jCh < nChannelsC; ++jCh) + FOR( jCh = 0; jCh < nChannelsC; ++jCh ) { temp_fx = singularVectors_Right_fx[jCh][iCh]; singularVectors_Right_fx[jCh][iCh] = singularVectors_Right_fx[jCh][iCh + 1]; @@ -463,10 +463,11 @@ Word16 svd_fx( } } } - } WHILE (EQ_16(condition, 1)); + } + WHILE( EQ_16( condition, 1 ) ); pop_wmops(); - return (errorMessage); + return ( errorMessage ); } #else @@ -564,12 +565,12 @@ static Word16 BidagonalDiagonalisation_fx( Word32 singularValues_fx[MAX_OUTPUT_CHANNELS], /* i/o: singular values vector (S) */ Word32 singularVectors_Right_fx[][MAX_OUTPUT_CHANNELS], /* i/o: right singular vectors (V) Q31 */ Word32 secDiag_fx[MAX_OUTPUT_CHANNELS], /* i/o: */ - Word16 *singularValues_fx_e, /* i/o: singular values vector (S) */ - Word16 *secDiag_fx_e, /* i/o: */ - const Word16 nChannelsL, /* i : number of rows in the matrix to be decomposed */ - const Word16 nChannelsC, /* i : number of columns in the matrix to be decomposed */ - const Word32 eps_x, /* i : */ - const Word16 eps_x_e /* i : */ + Word16 *singularValues_fx_e, /* i/o: singular values vector (S) */ + Word16 *secDiag_fx_e, /* i/o: */ + const Word16 nChannelsL, /* i : number of rows in the matrix to be decomposed */ + const Word16 nChannelsC, /* i : number of columns in the matrix to be decomposed */ + const Word32 eps_x, /* i : */ + const Word16 eps_x_e /* i : */ ) { Word16 kCh, nCh, iCh, jCh, split; @@ -591,7 +592,7 @@ static Word16 BidagonalDiagonalisation_fx( iteration = 0; split = iCh - 1; - WHILE ( EQ_16(convergence, 0) ) + WHILE( EQ_16( convergence, 0 ) ) { iteration++; found_split = 1; @@ -612,19 +613,19 @@ static Word16 BidagonalDiagonalisation_fx( convergence = ( jCh == iCh ) ? 1 : 0; - IF ( found_split ) + IF( found_split ) { s = MAX_32; s_e = 0; c = 0; c_e = 0; - FOR ( kCh = jCh; kCh <= iCh; kCh++ ) + FOR( kCh = jCh; kCh <= iCh; kCh++ ) { g = Mpy_32_32( s, secDiag_fx[kCh] ); - g_e = add(s_e, secDiag_new_e[kCh]); + g_e = add( s_e, secDiag_new_e[kCh] ); secDiag_fx[kCh] = Mpy_32_32( c, secDiag_fx[kCh] ); - secDiag_new_e[kCh] = add(c_e, secDiag_new_e[kCh]); + secDiag_new_e[kCh] = add( c_e, secDiag_new_e[kCh] ); IF( LE_16( BASOP_Util_Cmp_Mant32Exp( L_abs( g ), g_e, Mpy_32_32( CONVERGENCE_FACTOR_FX, eps_x ), eps_x_e ), 0 ) ) /* is singularValues[split] vanishing compared to eps_x */ { BREAK; @@ -633,34 +634,34 @@ static Word16 BidagonalDiagonalisation_fx( c = singularValues_fx[kCh]; c_e = singularValues_new_e[kCh]; singularValues_fx[kCh] = GivensRotation_fx( g, g_e, singularValues_fx[kCh], singularValues_new_e[kCh], &singularValues_new_e[kCh] ); - c = BASOP_Util_Divide3232_Scale_cadence( c, maxWithSign_fx(singularValues_fx[kCh] ), &temp_exp ); + c = BASOP_Util_Divide3232_Scale_cadence( c, maxWithSign_fx( singularValues_fx[kCh] ), &temp_exp ); c_e = add( temp_exp, sub( c_e, singularValues_new_e[kCh] ) ); IF( GT_16( c_e, 0 ) ) { - c = L_shl_sat(c, c_e); // Q31 + c = L_shl_sat( c, c_e ); // Q31 c_e = 0; } - s = BASOP_Util_Divide3232_Scale_cadence( -g, maxWithSign_fx(singularValues_fx[kCh] ), &temp_exp ); + s = BASOP_Util_Divide3232_Scale_cadence( -g, maxWithSign_fx( singularValues_fx[kCh] ), &temp_exp ); s_e = add( temp_exp, sub( g_e, singularValues_new_e[kCh] ) ); IF( GT_16( s_e, 0 ) ) { - s = L_shl_sat(s, s_e); // Q31 + s = L_shl_sat( s, s_e ); // Q31 s_e = 0; } - ApplyRotation_fx(singularVectors_Left_fx, c, c_e, s, s_e, 0, x11_e, 0, x12_e, &f1, &f1_e, &f2, &f2_e, kCh, split, nChannelsL ); /* nChannelsL */ + ApplyRotation_fx( singularVectors_Left_fx, c, c_e, s, s_e, 0, x11_e, 0, x12_e, &f1, &f1_e, &f2, &f2_e, kCh, split, nChannelsL ); /* nChannelsL */ } } - IF ( convergence ) + IF( convergence ) { singularValues_fx[iCh] = (Word32) singularValues_fx[iCh]; IF( LT_32( singularValues_fx[iCh], 0 ) ) { - singularValues_fx[iCh] = L_negate(singularValues_fx[iCh]); + singularValues_fx[iCh] = L_negate( singularValues_fx[iCh] ); FOR( nCh = 0; nCh < nChannelsC; nCh++ ) /* nChannelsC */ { - singularVectors_Right_fx[nCh][iCh] = L_negate(singularVectors_Right_fx[nCh][iCh]); + singularVectors_Right_fx[nCh][iCh] = L_negate( singularVectors_Right_fx[nCh][iCh] ); } } } @@ -670,11 +671,11 @@ static Word16 BidagonalDiagonalisation_fx( { IF( LT_32( singularValues_fx[iCh], 0 ) ) { - singularValues_fx[iCh] = L_negate(singularValues_fx[iCh]); + singularValues_fx[iCh] = L_negate( singularValues_fx[iCh] ); FOR( nCh = 0; nCh < nChannelsC; nCh++ ) /* nChannelsC */ { - singularVectors_Right_fx[nCh][iCh] = L_negate(singularVectors_Right_fx[nCh][iCh]); + singularVectors_Right_fx[nCh][iCh] = L_negate( singularVectors_Right_fx[nCh][iCh] ); } } error = 1; @@ -688,30 +689,32 @@ static Word16 BidagonalDiagonalisation_fx( } } - //rescaling block + // rescaling block Word16 max_exp = -31; - FOR (iCh = 0; iCh < nChannelsC; iCh++) { - IF(singularValues_fx[iCh]) { - max_exp = s_max(max_exp,singularValues_new_e[iCh]); - } - } - *singularValues_fx_e = max_exp; - FOR(iCh = 0; iCh < nChannelsC; iCh++) { - singularValues_fx[iCh] = L_shr_r(singularValues_fx[iCh], sub(*singularValues_fx_e, singularValues_new_e[iCh])); - } + FOR( iCh = 0; iCh < nChannelsC; iCh++ ){ + IF( singularValues_fx[iCh] ){ + max_exp = s_max( max_exp, singularValues_new_e[iCh] ); +} +} +*singularValues_fx_e = max_exp; +FOR( iCh = 0; iCh < nChannelsC; iCh++ ) +{ + singularValues_fx[iCh] = L_shr_r( singularValues_fx[iCh], sub( *singularValues_fx_e, singularValues_new_e[iCh] ) ); +} - max_exp = -31; - FOR(iCh = 0; iCh < nChannelsC; iCh++) { - IF(secDiag_fx[iCh]) { - max_exp = s_max(max_exp, secDiag_new_e[iCh]); - } - } - *secDiag_fx_e = max_exp; - FOR(iCh = 0; iCh < nChannelsC; iCh++) { - secDiag_fx[iCh] = L_shr_r(secDiag_fx[iCh], sub(*secDiag_fx_e, secDiag_new_e[iCh])); - } +max_exp = -31; +FOR( iCh = 0; iCh < nChannelsC; iCh++ ){ + IF( secDiag_fx[iCh] ){ + max_exp = s_max( max_exp, secDiag_new_e[iCh] ); +} +} +*secDiag_fx_e = max_exp; +FOR( iCh = 0; iCh < nChannelsC; iCh++ ) +{ + secDiag_fx[iCh] = L_shr_r( secDiag_fx[iCh], sub( *secDiag_fx_e, secDiag_new_e[iCh] ) ); +} - return ( error ); +return ( error ); } #else static int16_t BidagonalDiagonalisation( @@ -834,10 +837,10 @@ static void ApplyQRTransform_fx( Word32 secDiag[MAX_OUTPUT_CHANNELS], /* i/o: */ Word16 singularValues_e[MAX_OUTPUT_CHANNELS], Word16 secDiag_e[MAX_OUTPUT_CHANNELS], - const Word16 startIndex, /* i : */ - const Word16 currentIndex, /* i : */ - const Word16 nChannelsL, /* i : number of rows in the matrix to be decomposed */ - const Word16 nChannelsC /* i : number of columns in the matrix to be decomposed */ + const Word16 startIndex, /* i : */ + const Word16 currentIndex, /* i : */ + const Word16 nChannelsL, /* i : number of rows in the matrix to be decomposed */ + const Word16 nChannelsC /* i : number of columns in the matrix to be decomposed */ ) { Word16 ch, split; @@ -863,23 +866,23 @@ static void ApplyQRTransform_fx( r = secDiag[currentIndex]; r_e = secDiag_e[currentIndex]; - //d = (x_split + x_kk) * (x_split - x_kk) + (g + r) * (g - r); + // d = (x_split + x_kk) * (x_split - x_kk) + (g + r) * (g - r); L_temp1 = BASOP_Util_Add_Mant32Exp( x_split, x_split_e, x_kk, x_kk_e, &L_temp1_e ); L_temp2 = BASOP_Util_Add_Mant32Exp( x_split, x_split_e, -x_kk, x_kk_e, &L_temp2_e ); L_temp3 = BASOP_Util_Add_Mant32Exp( g, g_e, r, r_e, &L_temp3_e ); L_temp4 = BASOP_Util_Add_Mant32Exp( g, g_e, -r, r_e, &L_temp4_e ); d = BASOP_Util_Add_Mant32Exp( Mpy_32_32( L_temp1, L_temp2 ), add( L_temp1_e, L_temp2_e ), Mpy_32_32( L_temp3, L_temp4 ), add( L_temp3_e, L_temp4_e ), &d_e ); - //d /= maxWithSign((r + r) * x_split); + // d /= maxWithSign((r + r) * x_split); L_temp1 = BASOP_Util_Add_Mant32Exp( r, r_e, r, r_e, &L_temp1_e ); L_temp1 = maxWithSign_fx( Mpy_32_32( L_temp1, x_split ) ); L_temp1_e = add( L_temp1_e, x_split_e ); d = BASOP_Util_Divide3232_Scale_cadence( d, L_temp1, &temp_exp ); d_e = add( temp_exp, sub( d_e, L_temp1_e ) ); - g = GivensRotation_fx(MAX_32, 0, d, d_e, &g_e); + g = GivensRotation_fx( MAX_32, 0, d, d_e, &g_e ); - //mu = x_split / maxWithSign(d + (d >= 0.0f ? 1 : (-1)) * fabsf(g)) - r; + // mu = x_split / maxWithSign(d + (d >= 0.0f ? 1 : (-1)) * fabsf(g)) - r; L_temp1 = d >= 0 ? L_abs( g ) : -L_abs( g ); L_temp1_e = g_e; L_temp2 = maxWithSign_fx( BASOP_Util_Add_Mant32Exp( d, d_e, L_temp1, L_temp1_e, &L_temp2_e ) ); @@ -887,7 +890,7 @@ static void ApplyQRTransform_fx( mu_e = add( mu_e, sub( x_split_e, L_temp2_e ) ); mu = BASOP_Util_Add_Mant32Exp( mu, mu_e, -r, r_e, &mu_e ); - //d = ((x_ii + x_kk) * (x_ii - x_kk) + r * mu) / maxWithSign(x_ii); + // d = ((x_ii + x_kk) * (x_ii - x_kk) + r * mu) / maxWithSign(x_ii); L_temp1 = BASOP_Util_Add_Mant32Exp( x_ii, x_ii_e, x_kk, x_kk_e, &L_temp1_e ); L_temp2 = BASOP_Util_Add_Mant32Exp( x_ii, x_ii_e, -x_kk, x_kk_e, &L_temp2_e ); d = BASOP_Util_Add_Mant32Exp( Mpy_32_32( L_temp1, L_temp2 ), add( L_temp1_e, L_temp2_e ), Mpy_32_32( r, mu ), add( r_e, mu_e ), &d_e ); @@ -895,38 +898,38 @@ static void ApplyQRTransform_fx( d_e = add( temp_exp, sub( d_e, x_ii_e ) ); /*QR transformation*/ - FOR(ch = startIndex; ch <= split; ch++) + FOR( ch = startIndex; ch <= split; ch++ ) { - r = Mpy_32_32(s, secDiag[ch + 1]); - r_e = add(s_e,secDiag_e[ch + 1]); - g = Mpy_32_32(c, secDiag[ch + 1]); - g_e = add(c_e,secDiag_e[ch + 1]); + r = Mpy_32_32( s, secDiag[ch + 1] ); + r_e = add( s_e, secDiag_e[ch + 1] ); + g = Mpy_32_32( c, secDiag[ch + 1] ); + g_e = add( c_e, secDiag_e[ch + 1] ); secDiag[ch] = GivensRotation_fx( d, d_e, r, r_e, &secDiag_e[ch] ); c = BASOP_Util_Divide3232_Scale_cadence( d, maxWithSign_fx( secDiag[ch] ), &c_e ); - c_e = add(c_e, sub( d_e, secDiag_e[ch] ) ); + c_e = add( c_e, sub( d_e, secDiag_e[ch] ) ); IF( GT_16( c_e, 0 ) ) { - c = L_shl_sat(c, c_e); // Q31 + c = L_shl_sat( c, c_e ); // Q31 c_e = 0; } s = BASOP_Util_Divide3232_Scale_cadence( r, maxWithSign_fx( secDiag[ch] ), &s_e ); - s_e = add(s_e, sub( r_e, secDiag_e[ch] ) ); + s_e = add( s_e, sub( r_e, secDiag_e[ch] ) ); IF( GT_16( s_e, 0 ) ) { - s = L_shl_sat(s, s_e); // Q31 + s = L_shl_sat( s, s_e ); // Q31 s_e = 0; } - r = Mpy_32_32(s, singularValues[ch + 1]); - r_e = add(s_e,singularValues_e[ch + 1]); - x_split = Mpy_32_32(c, singularValues[ch + 1]); - x_split_e = add(c_e,singularValues_e[ch + 1]); + r = Mpy_32_32( s, singularValues[ch + 1] ); + r_e = add( s_e, singularValues_e[ch + 1] ); + x_split = Mpy_32_32( c, singularValues[ch + 1] ); + x_split_e = add( c_e, singularValues_e[ch + 1] ); aux = g; aux_e = g_e; - //ApplyRotation(singularVectors_Right, c, s, x_ii, aux, &d, &g, ch + 1, ch, nChannelsC); + // ApplyRotation(singularVectors_Right, c, s, x_ii, aux, &d, &g, ch + 1, ch, nChannelsC); ApplyRotation_fx( singularVectors_Right, c, c_e, s, s_e, x_ii, x_ii_e, aux, aux_e, &d, &d_e, &g, &g_e, ch + 1, ch, nChannelsC ); singularValues[ch] = GivensRotation_fx( d, d_e, r, r_e, &singularValues_e[ch] ); @@ -939,7 +942,7 @@ static void ApplyQRTransform_fx( c_e = add( d_e, aux_e ); IF( GT_16( c_e, 0 ) ) { - c = L_shl_sat(c, c_e); // Q31 + c = L_shl_sat( c, c_e ); // Q31 c_e = 0; } @@ -947,13 +950,13 @@ static void ApplyQRTransform_fx( s_e = add( r_e, aux_e ); IF( GT_16( s_e, 0 ) ) { - s = L_shl_sat(s, s_e); // Q31 + s = L_shl_sat( s, s_e ); // Q31 s_e = 0; } } - //ApplyRotation(singularVectors_Left, c, s, g, x_split, &d, &x_ii, ch + 1, ch, nChannelsL); - ApplyRotation_fx(singularVectors_Left, c, c_e, s, s_e, g, g_e, x_split, x_split_e, &d, &d_e, &x_ii, &x_ii_e, ch + 1, ch, nChannelsL); + // ApplyRotation(singularVectors_Left, c, s, g, x_split, &d, &x_ii, ch + 1, ch, nChannelsL); + ApplyRotation_fx( singularVectors_Left, c, c_e, s, s_e, g, g_e, x_split, x_split_e, &d, &d_e, &x_ii, &x_ii_e, ch + 1, ch, nChannelsL ); } secDiag[startIndex] = 0; @@ -1058,17 +1061,17 @@ static void ApplyRotation_fx( Word16 ch; Word16 temp_exp; - *d = BASOP_Util_Add_Mant32Exp( Mpy_32_32( c, x11 ), add(c_e,x11_e), Mpy_32_32( s, x12 ), add(s_e,x12_e), d_e ); - *g = BASOP_Util_Add_Mant32Exp( Mpy_32_32( c, x12 ), add(c_e,x12_e), Mpy_32_32( -s, x11 ), add(s_e,x11_e), g_e ); + *d = BASOP_Util_Add_Mant32Exp( Mpy_32_32( c, x11 ), add( c_e, x11_e ), Mpy_32_32( s, x12 ), add( s_e, x12_e ), d_e ); + *g = BASOP_Util_Add_Mant32Exp( Mpy_32_32( c, x12 ), add( c_e, x12_e ), Mpy_32_32( -s, x11 ), add( s_e, x11_e ), g_e ); FOR( ch = 0; ch < nChannels; ch++ ) { x11 = singularVector[ch][currentIndex2]; x12 = singularVector[ch][currentIndex1]; singularVector[ch][currentIndex2] = BASOP_Util_Add_Mant32Exp( Mpy_32_32( c, x11 ), c_e, Mpy_32_32( s, x12 ), s_e, &temp_exp ); - singularVector[ch][currentIndex2] = L_shl_sat(singularVector[ch][currentIndex2], temp_exp); - singularVector[ch][currentIndex1] = BASOP_Util_Add_Mant32Exp( Mpy_32_32( c, x12 ), c_e, Mpy_32_32( -s, x11 ), s_e, &temp_exp); - singularVector[ch][currentIndex1] = L_shl_sat(singularVector[ch][currentIndex1], temp_exp); + singularVector[ch][currentIndex2] = L_shl_sat( singularVector[ch][currentIndex2], temp_exp ); + singularVector[ch][currentIndex1] = BASOP_Util_Add_Mant32Exp( Mpy_32_32( c, x12 ), c_e, Mpy_32_32( -s, x11 ), s_e, &temp_exp ); + singularVector[ch][currentIndex1] = L_shl_sat( singularVector[ch][currentIndex1], temp_exp ); } return; @@ -1121,21 +1124,21 @@ static void HouseholderReduction_fx( const int16_t nChannelsL, const int16_t nChannelsC, Word32 *eps_x_fx, - Word16 *eps_x_fx_e) + Word16 *eps_x_fx_e ) { int16_t nCh; - //float g = 0.0f, sig_x = 0.0f;// to be removed + // float g = 0.0f, sig_x = 0.0f;// to be removed Word32 g_fx = 0, sig_x_fx = 0; Word16 sig_x_fx_e = 0; /* Bidiagonal Reduction for every channel */ - FOR(nCh = 0; nCh < nChannelsC; nCh++) /* nChannelsC */ + FOR( nCh = 0; nCh < nChannelsC; nCh++ ) /* nChannelsC */ { - biDiagonalReductionLeft_fx(singularVectors_Left_fx, singularValues_fx, secDiag_fx, &singularVectors_Left_e, singularValues_fx_e, secDiag_fx_e, nChannelsL, nChannelsC, nCh, &sig_x_fx, &sig_x_fx_e, &g_fx); - biDiagonalReductionRight_fx(singularVectors_Left_fx, secDiag_fx, &singularVectors_Left_e, secDiag_fx_e, nChannelsL, nChannelsC, nCh, &sig_x_fx, &sig_x_fx_e, &g_fx); + biDiagonalReductionLeft_fx( singularVectors_Left_fx, singularValues_fx, secDiag_fx, &singularVectors_Left_e, singularValues_fx_e, secDiag_fx_e, nChannelsL, nChannelsC, nCh, &sig_x_fx, &sig_x_fx_e, &g_fx ); + biDiagonalReductionRight_fx( singularVectors_Left_fx, secDiag_fx, &singularVectors_Left_e, secDiag_fx_e, nChannelsL, nChannelsC, nCh, &sig_x_fx, &sig_x_fx_e, &g_fx ); Word16 L_temp_e; - Word32 L_temp = BASOP_Util_Add_Mant32Exp( L_abs( singularValues_fx[nCh] ), *singularValues_fx_e, L_abs( secDiag_fx[nCh] ), *secDiag_fx_e, &L_temp_e); + Word32 L_temp = BASOP_Util_Add_Mant32Exp( L_abs( singularValues_fx[nCh] ), *singularValues_fx_e, L_abs( secDiag_fx[nCh] ), *secDiag_fx_e, &L_temp_e ); IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( L_temp, L_temp_e, *eps_x_fx, *eps_x_fx_e ), 1 ) ) { *eps_x_fx = L_temp; @@ -1146,7 +1149,7 @@ static void HouseholderReduction_fx( /* SingularVecotr Accumulation */ singularVectorsAccumulationRight_fx( singularVectors_Left_fx, singularVectors_Right_fx, secDiag_fx, singularVectors_Left_e, *secDiag_fx_e, nChannelsC ); - singularVectorsAccumulationLeft_fx(singularVectors_Left_fx, singularValues_fx, singularVectors_Left_e, *singularValues_fx_e, nChannelsL, nChannelsC); + singularVectorsAccumulationLeft_fx( singularVectors_Left_fx, singularValues_fx, singularVectors_Left_e, *singularValues_fx_e, nChannelsL, nChannelsC ); return; } @@ -1207,129 +1210,126 @@ static void biDiagonalReductionLeft_fx( Word16 sing_exp2[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS] = { 0 }; Word32 L_temp; Word16 L_temp_e; - FOR (jCh = 0; jCh < MAX_OUTPUT_CHANNELS; jCh++) { - set_s( sing_exp2[jCh], *singularVectors_e, MAX_OUTPUT_CHANNELS); + FOR( jCh = 0; jCh < MAX_OUTPUT_CHANNELS; jCh++ ) + { + set_s( sing_exp2[jCh], *singularVectors_e, MAX_OUTPUT_CHANNELS ); } secDiag[currChannel] = Mpy_32_32( *sig_x, *g ); - //rescaling block + // rescaling block IF( GT_16( *sig_x_e, *secDiag_e ) ) { - FOR ( Word16 i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) - { - IF( NE_16( i, currChannel ) ) - { + FOR( Word16 i = 0; i < MAX_OUTPUT_CHANNELS; i++ ){ + IF( NE_16( i, currChannel ) ){ secDiag[i] = L_shl( secDiag[i], sub( *secDiag_e, *sig_x_e ) ); - } - } - *secDiag_e = *sig_x_e; - } - ELSE IF ( LT_16( *sig_x_e, *secDiag_e ) ) - { - secDiag[currChannel] = L_shr_r( secDiag[currChannel], sub( *secDiag_e, *sig_x_e ) ); } +} +*secDiag_e = *sig_x_e; +} +ELSE IF( LT_16( *sig_x_e, *secDiag_e ) ) +{ + secDiag[currChannel] = L_shr_r( secDiag[currChannel], sub( *secDiag_e, *sig_x_e ) ); +} - /* Setting values to 0 */ - ( *sig_x ) = 0; - ( *g ) = 0; +/* Setting values to 0 */ +( *sig_x ) = 0; +( *g ) = 0; - IF( LT_16( currChannel, nChannelsL ) ) /* i <= m */ +IF( LT_16( currChannel, nChannelsL ) ) /* i <= m */ +{ + idx = currChannel; + + FOR( jCh = idx; jCh < nChannelsL; jCh++ ) /* nChannelsL */ { - idx = currChannel; + ( *sig_x ) = BASOP_Util_Add_Mant32Exp( *sig_x, *sig_x_e, L_abs( singularVectors[jCh][currChannel] ), *singularVectors_e, sig_x_e ); + } - FOR ( jCh = idx; jCh < nChannelsL; jCh++ ) /* nChannelsL */ + IF( ( *sig_x ) ) /*(fabsf(*sig_x) > EPSILON * fabsf(*sig_x)) { */ + { + norm_x = 0; + norm_x_e = 0; + FOR( jCh = idx; jCh < nChannelsL; jCh++ ) /* nChannelsL */ { - ( *sig_x ) = BASOP_Util_Add_Mant32Exp( *sig_x, *sig_x_e, L_abs( singularVectors[jCh][currChannel] ), *singularVectors_e, sig_x_e ); + singularVectors[jCh][currChannel] = BASOP_Util_Divide3232_Scale_cadence( singularVectors[jCh][currChannel], maxWithSign_fx( *sig_x ), &sing_exp[jCh] ); + sing_exp[jCh] = add( sing_exp[jCh], sub( *singularVectors_e, *sig_x_e ) ); + norm_x = BASOP_Util_Add_Mant32Exp( norm_x, norm_x_e, Mpy_32_32( singularVectors[jCh][currChannel], singularVectors[jCh][currChannel] ), shl( sing_exp[jCh], 1 ), &norm_x_e ); } - - IF ( ( *sig_x ) ) /*(fabsf(*sig_x) > EPSILON * fabsf(*sig_x)) { */ + IF( GT_16( norm_x_e, 0 ) ) { - norm_x = 0; + norm_x = MAX_32; norm_x_e = 0; - FOR ( jCh = idx; jCh < nChannelsL; jCh++ ) /* nChannelsL */ - { - singularVectors[jCh][currChannel] = BASOP_Util_Divide3232_Scale_cadence( singularVectors[jCh][currChannel], maxWithSign_fx( *sig_x ), &sing_exp[jCh] ); - sing_exp[jCh] = add( sing_exp[jCh], sub( *singularVectors_e, *sig_x_e ) ); - norm_x = BASOP_Util_Add_Mant32Exp( norm_x, norm_x_e, Mpy_32_32( singularVectors[jCh][currChannel], singularVectors[jCh][currChannel] ), shl( sing_exp[jCh], 1 ), &norm_x_e ); - } - IF( GT_16( norm_x_e, 0 ) ) - { - norm_x = MAX_32; - norm_x_e = 0; - } - L_temp_e = norm_x_e; - L_temp = Sqrt32( norm_x, &L_temp_e ); - L_temp = L_shl_r( L_temp, L_temp_e ); // Q31 - ( *g ) = L_negate( GE_32( singularVectors[currChannel][idx], 0 ) ? L_temp : L_negate( L_temp ) ); + } + L_temp_e = norm_x_e; + L_temp = Sqrt32( norm_x, &L_temp_e ); + L_temp = L_shl_r( L_temp, L_temp_e ); // Q31 + ( *g ) = L_negate( GE_32( singularVectors[currChannel][idx], 0 ) ? L_temp : L_negate( L_temp ) ); - r = BASOP_Util_Add_Mant32Exp( Mpy_32_32( ( *g ), singularVectors[currChannel][idx] ), sing_exp[currChannel], -norm_x, norm_x_e, &r_e ); - singularVectors[currChannel][idx] = BASOP_Util_Add_Mant32Exp( singularVectors[currChannel][idx], sing_exp[idx], -( *g ), 0, &sing_exp[currChannel] ); + r = BASOP_Util_Add_Mant32Exp( Mpy_32_32( ( *g ), singularVectors[currChannel][idx] ), sing_exp[currChannel], -norm_x, norm_x_e, &r_e ); + singularVectors[currChannel][idx] = BASOP_Util_Add_Mant32Exp( singularVectors[currChannel][idx], sing_exp[idx], -( *g ), 0, &sing_exp[currChannel] ); - FOR ( iCh = currChannel + 1; iCh < nChannelsC; iCh++ ) /* nChannelsC */ + FOR( iCh = currChannel + 1; iCh < nChannelsC; iCh++ ) /* nChannelsC */ + { + norm_x = 0; + norm_x_e = 0; + FOR( jCh = idx; jCh < nChannelsL; jCh++ ) /* nChannelsL */ { - norm_x = 0; - norm_x_e = 0; - FOR ( jCh = idx; jCh < nChannelsL; jCh++ ) /* nChannelsL */ - { - norm_x = BASOP_Util_Add_Mant32Exp( norm_x, norm_x_e, Mpy_32_32( singularVectors[jCh][currChannel], singularVectors[jCh][iCh] ), add( sing_exp[jCh], *singularVectors_e ), &norm_x_e ); - } - - f = BASOP_Util_Divide3232_Scale_cadence( norm_x, maxWithSign_fx( r ), &f_e ); - f_e = add( f_e, sub( norm_x_e, r_e ) ); - - FOR( jCh = idx; jCh < nChannelsL; jCh++ ) /* nChannelsL */ - { - singularVectors[jCh][iCh] = BASOP_Util_Add_Mant32Exp( singularVectors[jCh][iCh], *singularVectors_e, Mpy_32_32( f, singularVectors[jCh][currChannel] ), add( f_e, sing_exp[jCh] ), &sing_exp2[jCh][iCh] ); - } + norm_x = BASOP_Util_Add_Mant32Exp( norm_x, norm_x_e, Mpy_32_32( singularVectors[jCh][currChannel], singularVectors[jCh][iCh] ), add( sing_exp[jCh], *singularVectors_e ), &norm_x_e ); } + f = BASOP_Util_Divide3232_Scale_cadence( norm_x, maxWithSign_fx( r ), &f_e ); + f_e = add( f_e, sub( norm_x_e, r_e ) ); FOR( jCh = idx; jCh < nChannelsL; jCh++ ) /* nChannelsL */ { - singularVectors[jCh][currChannel] = Mpy_32_32( singularVectors[jCh][currChannel], ( *sig_x ) ); - sing_exp2[jCh][currChannel] = add( sing_exp[jCh], *sig_x_e ); + singularVectors[jCh][iCh] = BASOP_Util_Add_Mant32Exp( singularVectors[jCh][iCh], *singularVectors_e, Mpy_32_32( f, singularVectors[jCh][currChannel] ), add( f_e, sing_exp[jCh] ), &sing_exp2[jCh][iCh] ); } + } - //rescaling block - Word16 exp_max = *singularVectors_e; - FOR(iCh = 0; iCh < nChannelsC; iCh++) - { - FOR(jCh = 0; jCh < nChannelsL; jCh++) - { - exp_max = s_max(exp_max, sing_exp2[jCh][iCh]); - } - } - FOR(iCh = 0; iCh < nChannelsC; iCh++) - { - FOR(jCh = 0; jCh < nChannelsL; jCh++) - { - singularVectors[jCh][iCh] = L_shr_r(singularVectors[jCh][iCh], sub(exp_max, sing_exp2[jCh][iCh])); - } - } - *singularVectors_e = exp_max; + FOR( jCh = idx; jCh < nChannelsL; jCh++ ) /* nChannelsL */ + { + singularVectors[jCh][currChannel] = Mpy_32_32( singularVectors[jCh][currChannel], ( *sig_x ) ); + sing_exp2[jCh][currChannel] = add( sing_exp[jCh], *sig_x_e ); } - //rescaling block - singularValues[currChannel] = Mpy_32_32( ( *sig_x ), ( *g ) ); - IF( GT_16( *sig_x_e, *singularValues_e ) ) + // rescaling block + Word16 exp_max = *singularVectors_e; + FOR( iCh = 0; iCh < nChannelsC; iCh++ ) { - FOR( Word16 i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) + FOR( jCh = 0; jCh < nChannelsL; jCh++ ) { - IF( NE_16( i, currChannel ) ) - { - singularValues[i] = L_shl( singularValues[i], sub( *singularValues_e, *sig_x_e ) ); - } + exp_max = s_max( exp_max, sing_exp2[jCh][iCh] ); } - *singularValues_e = *sig_x_e; } - ELSE IF ( LT_16( *sig_x_e, *singularValues_e ) ) + + FOR( iCh = 0; iCh < nChannelsC; iCh++ ) { - singularValues[currChannel] = L_shr_r( singularValues[currChannel], sub( *singularValues_e, *sig_x_e ) ); + FOR( jCh = 0; jCh < nChannelsL; jCh++ ) + { + singularVectors[jCh][iCh] = L_shr_r( singularVectors[jCh][iCh], sub( exp_max, sing_exp2[jCh][iCh] ) ); + } } + *singularVectors_e = exp_max; } - return; + // rescaling block + singularValues[currChannel] = Mpy_32_32( ( *sig_x ), ( *g ) ); + IF( GT_16( *sig_x_e, *singularValues_e ) ) + { + FOR( Word16 i = 0; i < MAX_OUTPUT_CHANNELS; i++ ){ + IF( NE_16( i, currChannel ) ){ + singularValues[i] = L_shl( singularValues[i], sub( *singularValues_e, *sig_x_e ) ); + } +} +*singularValues_e = *sig_x_e; +} +ELSE IF( LT_16( *sig_x_e, *singularValues_e ) ) +{ + singularValues[currChannel] = L_shr_r( singularValues[currChannel], sub( *singularValues_e, *sig_x_e ) ); +} +} + +return; } #else static void biDiagonalReductionLeft( @@ -1431,10 +1431,11 @@ static void biDiagonalReductionRight_fx( Word16 sing_exp2[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS] = { 0 }; Word32 L_temp; Word16 L_temp_e; - FOR (jCh = 0; jCh < MAX_OUTPUT_CHANNELS; jCh++) { - set_s(sing_exp2[jCh], *singularVectors_e, MAX_OUTPUT_CHANNELS); + FOR( jCh = 0; jCh < MAX_OUTPUT_CHANNELS; jCh++ ) + { + set_s( sing_exp2[jCh], *singularVectors_e, MAX_OUTPUT_CHANNELS ); } - set_s(secDiag_exp, *secDiag_e, MAX_OUTPUT_CHANNELS); + set_s( secDiag_exp, *secDiag_e, MAX_OUTPUT_CHANNELS ); /* Setting values to 0 */ ( *sig_x ) = 0; @@ -1442,23 +1443,23 @@ static void biDiagonalReductionRight_fx( IF( LT_16( currChannel, nChannelsL ) && NE_16( currChannel, sub( nChannelsC, 1 ) ) ) /* i <=m && i !=n */ { - idx = add(currChannel, 1); + idx = add( currChannel, 1 ); - FOR ( jCh = idx; jCh < nChannelsC; jCh++ ) /* nChannelsC */ + FOR( jCh = idx; jCh < nChannelsC; jCh++ ) /* nChannelsC */ { - ( *sig_x ) = BASOP_Util_Add_Mant32Exp( *sig_x, *sig_x_e, L_abs( singularVectors[currChannel][jCh]), *singularVectors_e, sig_x_e ); + ( *sig_x ) = BASOP_Util_Add_Mant32Exp( *sig_x, *sig_x_e, L_abs( singularVectors[currChannel][jCh] ), *singularVectors_e, sig_x_e ); } - IF ( ( *sig_x ) ) /*(fabsf(*sig_x) > EPSILON * fabsf(*sig_x)) { */ + IF( ( *sig_x ) ) /*(fabsf(*sig_x) > EPSILON * fabsf(*sig_x)) { */ { norm_x = 0; norm_x_e = 0; FOR( jCh = idx; jCh < nChannelsC; jCh++ ) /*nChannelsC */ { - singularVectors[currChannel][jCh] = BASOP_Util_Divide3232_Scale_cadence(singularVectors[currChannel][jCh], maxWithSign_fx(*sig_x), &sing_exp[jCh]); - sing_exp[jCh] = add(sing_exp[jCh], sub(*singularVectors_e, *sig_x_e)); - norm_x = BASOP_Util_Add_Mant32Exp(norm_x, norm_x_e, Mpy_32_32(singularVectors[currChannel][jCh], singularVectors[currChannel][jCh]), shl(sing_exp[jCh], 1), &norm_x_e); + singularVectors[currChannel][jCh] = BASOP_Util_Divide3232_Scale_cadence( singularVectors[currChannel][jCh], maxWithSign_fx( *sig_x ), &sing_exp[jCh] ); + sing_exp[jCh] = add( sing_exp[jCh], sub( *singularVectors_e, *sig_x_e ) ); + norm_x = BASOP_Util_Add_Mant32Exp( norm_x, norm_x_e, Mpy_32_32( singularVectors[currChannel][jCh], singularVectors[currChannel][jCh] ), shl( sing_exp[jCh], 1 ), &norm_x_e ); } IF( GT_16( norm_x_e, 0 ) ) { @@ -1466,17 +1467,17 @@ static void biDiagonalReductionRight_fx( norm_x_e = 0; } L_temp_e = norm_x_e; - L_temp = Sqrt32(norm_x, &L_temp_e); - L_temp = L_shl_r(L_temp, L_temp_e); // Q31 + L_temp = Sqrt32( norm_x, &L_temp_e ); + L_temp = L_shl_r( L_temp, L_temp_e ); // Q31 ( *g ) = L_negate( GE_32( singularVectors[currChannel][idx], 0 ) ? L_temp : L_negate( L_temp ) ); - r = BASOP_Util_Add_Mant32Exp(Mpy_32_32((*g), singularVectors[currChannel][idx]), sing_exp[idx], -norm_x, norm_x_e, &r_e); - singularVectors[currChannel][idx] = BASOP_Util_Add_Mant32Exp(singularVectors[currChannel][idx], sing_exp[idx], -(*g), 0, &sing_exp[idx]); + r = BASOP_Util_Add_Mant32Exp( Mpy_32_32( ( *g ), singularVectors[currChannel][idx] ), sing_exp[idx], -norm_x, norm_x_e, &r_e ); + singularVectors[currChannel][idx] = BASOP_Util_Add_Mant32Exp( singularVectors[currChannel][idx], sing_exp[idx], -( *g ), 0, &sing_exp[idx] ); FOR( jCh = idx; jCh < nChannelsC; jCh++ ) /* nChannelsC */ { - secDiag[jCh] = BASOP_Util_Divide3232_Scale_cadence(singularVectors[currChannel][jCh], maxWithSign_fx(r), &secDiag_exp[jCh]); - secDiag_exp[jCh] = add( secDiag_exp[jCh], sub( sing_exp[jCh], r_e) ); + secDiag[jCh] = BASOP_Util_Divide3232_Scale_cadence( singularVectors[currChannel][jCh], maxWithSign_fx( r ), &secDiag_exp[jCh] ); + secDiag_exp[jCh] = add( secDiag_exp[jCh], sub( sing_exp[jCh], r_e ) ); } FOR( iCh = currChannel + 1; iCh < nChannelsL; iCh++ ) /* nChannelsL */ @@ -1485,12 +1486,12 @@ static void biDiagonalReductionRight_fx( norm_x_e = 0; FOR( jCh = idx; jCh < nChannelsC; jCh++ ) /* nChannelsC */ { - norm_x = BASOP_Util_Add_Mant32Exp(norm_x, norm_x_e, Mpy_32_32(singularVectors[iCh][jCh], singularVectors[currChannel][jCh]), add( *singularVectors_e, sing_exp[jCh] ), &norm_x_e); + norm_x = BASOP_Util_Add_Mant32Exp( norm_x, norm_x_e, Mpy_32_32( singularVectors[iCh][jCh], singularVectors[currChannel][jCh] ), add( *singularVectors_e, sing_exp[jCh] ), &norm_x_e ); } FOR( jCh = idx; jCh < nChannelsC; jCh++ ) /* nChannelsC */ { - singularVectors[iCh][jCh] = BASOP_Util_Add_Mant32Exp(singularVectors[iCh][jCh], *singularVectors_e, Mpy_32_32(norm_x, secDiag[jCh]), add(norm_x_e, secDiag_exp[jCh]), &sing_exp2[iCh][jCh]); + singularVectors[iCh][jCh] = BASOP_Util_Add_Mant32Exp( singularVectors[iCh][jCh], *singularVectors_e, Mpy_32_32( norm_x, secDiag[jCh] ), add( norm_x_e, secDiag_exp[jCh] ), &sing_exp2[iCh][jCh] ); } } @@ -1502,28 +1503,30 @@ static void biDiagonalReductionRight_fx( /*rescaling block*/ Word16 exp_max = *secDiag_e; - FOR(jCh = 0; jCh < nChannelsC; jCh++) { - exp_max = s_max(exp_max, secDiag_exp[jCh]); + FOR( jCh = 0; jCh < nChannelsC; jCh++ ) + { + exp_max = s_max( exp_max, secDiag_exp[jCh] ); } - FOR(jCh = 0; jCh < nChannelsC; jCh++) { + FOR( jCh = 0; jCh < nChannelsC; jCh++ ) + { secDiag[jCh] = L_shr_r( secDiag[jCh], sub( exp_max, secDiag_exp[jCh] ) ); } exp_max = *singularVectors_e; - FOR(iCh = 0; iCh < nChannelsL; iCh++) + FOR( iCh = 0; iCh < nChannelsL; iCh++ ) { - FOR(jCh = 0; jCh < nChannelsC; jCh++) + FOR( jCh = 0; jCh < nChannelsC; jCh++ ) { - exp_max = s_max(exp_max, sing_exp2[iCh][jCh]); + exp_max = s_max( exp_max, sing_exp2[iCh][jCh] ); } } - FOR(iCh = 0; iCh < nChannelsL ; iCh++) + FOR( iCh = 0; iCh < nChannelsL; iCh++ ) { - FOR(jCh = 0; jCh < nChannelsC; jCh++) + FOR( jCh = 0; jCh < nChannelsC; jCh++ ) { - singularVectors[iCh][jCh] = L_shr_r(singularVectors[iCh][jCh], sub(exp_max, sing_exp2[iCh][jCh])); + singularVectors[iCh][jCh] = L_shr_r( singularVectors[iCh][jCh], sub( exp_max, sing_exp2[iCh][jCh] ) ); } } *singularVectors_e = exp_max; @@ -1609,58 +1612,59 @@ static void biDiagonalReductionRight( #ifdef IVAS_FLOAT_FIXED static void singularVectorsAccumulationLeft_fx( - Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], //Q31 output + Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], // Q31 output Word32 singularValues[MAX_OUTPUT_CHANNELS], Word16 singularVectors_e, Word16 singularValues_e, const Word16 nChannelsL, - const Word16 nChannelsC) + const Word16 nChannelsC ) { Word16 nCh, iCh, k; Word16 nChannels; Word32 norm_y, t_jj, t_ii; Word16 norm_y_e, t_jj_e, t_ii_e, temp_exp; Word16 sing_exp2[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS] = { 0 }; - FOR(nCh = 0; nCh < MAX_OUTPUT_CHANNELS; nCh++) { - set_s(sing_exp2[nCh], singularVectors_e, MAX_OUTPUT_CHANNELS); + FOR( nCh = 0; nCh < MAX_OUTPUT_CHANNELS; nCh++ ) + { + set_s( sing_exp2[nCh], singularVectors_e, MAX_OUTPUT_CHANNELS ); } /* Processing */ - nChannels = min(nChannelsL, nChannelsC); /* min(nChannelsL,ChannelsC) */ - //FILE *fp = fopen("t_ii_out.txt","a"); - FOR(nCh = nChannels - 1; nCh >= 0; nCh--) /* min(nChannelsL,ChannelsC) */ + nChannels = min( nChannelsL, nChannelsC ); /* min(nChannelsL,ChannelsC) */ + // FILE *fp = fopen("t_ii_out.txt","a"); + FOR( nCh = nChannels - 1; nCh >= 0; nCh-- ) /* min(nChannelsL,ChannelsC) */ { t_ii = singularValues[nCh]; t_ii_e = singularValues_e; - FOR(iCh = nCh + 1; iCh < nChannelsC; iCh++) /* nChannelsC */ + FOR( iCh = nCh + 1; iCh < nChannelsC; iCh++ ) /* nChannelsC */ { singularVectors_Left[nCh][iCh] = 0; } - IF(t_ii) /*if (fabsf(t_ii) > EPSILON *fabsf(t_ii)) {*/ + IF( t_ii ) /*if (fabsf(t_ii) > EPSILON *fabsf(t_ii)) {*/ { - t_ii = BASOP_Util_Divide3232_Scale_cadence(ONE_IN_Q30, maxWithSign_fx(t_ii), &temp_exp); + t_ii = BASOP_Util_Divide3232_Scale_cadence( ONE_IN_Q30, maxWithSign_fx( t_ii ), &temp_exp ); t_ii_e = add( 1, sub( temp_exp, t_ii_e ) ); - //fprintf( fp, "%e\n", me2f( t_ii, t_ii_e ) ); - FOR(iCh = nCh + 1; iCh < nChannelsC; iCh++) /* nChannelsC */ + // fprintf( fp, "%e\n", me2f( t_ii, t_ii_e ) ); + FOR( iCh = nCh + 1; iCh < nChannelsC; iCh++ ) /* nChannelsC */ { norm_y = 0; norm_y_e = 0; - FOR(k = nCh + 1; k < nChannelsL; k++) /* nChannelsL */ + FOR( k = nCh + 1; k < nChannelsL; k++ ) /* nChannelsL */ { norm_y = BASOP_Util_Add_Mant32Exp( norm_y, norm_y_e, Mpy_32_32( singularVectors_Left[k][nCh], singularVectors_Left[k][iCh] ), add( sing_exp2[k][nCh], sing_exp2[k][iCh] ), &norm_y_e ); } - t_jj = BASOP_Util_Divide3232_Scale_cadence( Mpy_32_32( t_ii, norm_y ), maxWithSign_fx( singularVectors_Left[nCh][nCh] ), &temp_exp ); //t_ii_e+norm_y_e-*singularVectors_e, + t_jj = BASOP_Util_Divide3232_Scale_cadence( Mpy_32_32( t_ii, norm_y ), maxWithSign_fx( singularVectors_Left[nCh][nCh] ), &temp_exp ); // t_ii_e+norm_y_e-*singularVectors_e, t_jj_e = add( temp_exp, sub( add( t_ii_e, norm_y_e ), sing_exp2[nCh][nCh] ) ); - FOR(k = nCh; k < nChannelsL; k++) /* nChannelsL */ + FOR( k = nCh; k < nChannelsL; k++ ) /* nChannelsL */ { singularVectors_Left[k][iCh] = BASOP_Util_Add_Mant32Exp( singularVectors_Left[k][iCh], sing_exp2[k][iCh], Mpy_32_32( t_jj, singularVectors_Left[k][nCh] ), add( t_jj_e, sing_exp2[k][nCh] ), &sing_exp2[k][iCh] ); } } - FOR(iCh = nCh; iCh < nChannelsL; iCh++) /* nChannelsL */ + FOR( iCh = nCh; iCh < nChannelsL; iCh++ ) /* nChannelsL */ { singularVectors_Left[iCh][nCh] = Mpy_32_32( singularVectors_Left[iCh][nCh], t_ii ); sing_exp2[iCh][nCh] = add( sing_exp2[iCh][nCh], t_ii_e ); @@ -1668,7 +1672,7 @@ static void singularVectorsAccumulationLeft_fx( } ELSE { - FOR(iCh = nCh; iCh < nChannelsL; iCh++) /* nChannelsL */ + FOR( iCh = nCh; iCh < nChannelsL; iCh++ ) /* nChannelsL */ { singularVectors_Left[iCh][nCh] = 0; } @@ -1676,9 +1680,11 @@ static void singularVectorsAccumulationLeft_fx( singularVectors_Left[nCh][nCh] = BASOP_Util_Add_Mant32Exp( singularVectors_Left[nCh][nCh], sing_exp2[nCh][nCh], ONE_IN_Q30, 1, &sing_exp2[nCh][nCh] ); } - //fclose(fp); - FOR(nCh = 0; nCh < nChannelsL; nCh++) { - FOR(iCh = 0; iCh < nChannelsC; iCh++) { + // fclose(fp); + FOR( nCh = 0; nCh < nChannelsL; nCh++ ) + { + FOR( iCh = 0; iCh < nChannelsC; iCh++ ) + { singularVectors_Left[nCh][iCh] = L_shl_sat( singularVectors_Left[nCh][iCh], sing_exp2[nCh][iCh] ); } } @@ -1757,7 +1763,7 @@ static void singularVectorsAccumulationLeft( #ifdef IVAS_FLOAT_FIXED static void singularVectorsAccumulationRight_fx( Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], - Word32 singularVectors_Right[][MAX_OUTPUT_CHANNELS], //Q31 + Word32 singularVectors_Right[][MAX_OUTPUT_CHANNELS], // Q31 Word32 secDiag[MAX_OUTPUT_CHANNELS], Word16 singularVectors_e, Word16 secDiag_e, @@ -1784,10 +1790,10 @@ static void singularVectorsAccumulationRight_fx( FOR( iCh = nCh + 1; iCh < nChannelsC; iCh++ ) /* nChannelsC*/ { - ratio_float = BASOP_Util_Divide3232_Scale_cadence( singularVectors_Left[nCh][iCh], maxWithSign_fx( singularVectors_Left[nCh][nCh + 1]), &temp_exp1); - singularVectors_Right[iCh][nCh] = BASOP_Util_Divide3232_Scale_cadence( ratio_float, maxWithSign_fx( t_ii ), &sing_right_exp[iCh][nCh]); - sing_right_exp[iCh][nCh] = add(sing_right_exp[iCh][nCh], sub( temp_exp1, secDiag_e ) ); - //singularVectors_Right[iCh][nCh] = L_shl_sat( singularVectors_Right[iCh][nCh], temp_exp2 ); + ratio_float = BASOP_Util_Divide3232_Scale_cadence( singularVectors_Left[nCh][iCh], maxWithSign_fx( singularVectors_Left[nCh][nCh + 1] ), &temp_exp1 ); + singularVectors_Right[iCh][nCh] = BASOP_Util_Divide3232_Scale_cadence( ratio_float, maxWithSign_fx( t_ii ), &sing_right_exp[iCh][nCh] ); + sing_right_exp[iCh][nCh] = add( sing_right_exp[iCh][nCh], sub( temp_exp1, secDiag_e ) ); + // singularVectors_Right[iCh][nCh] = L_shl_sat( singularVectors_Right[iCh][nCh], temp_exp2 ); } FOR( iCh = nCh + 1; iCh < nChannelsC; iCh++ ) /* nChannelsC */ @@ -1891,7 +1897,7 @@ static Word32 GivensRotation_fx( const Word16 x_e, const Word32 z, const Word16 z_e, - Word16 *out_e) + Word16 *out_e ) { Word32 x_abs, z_abs; Word32 cotan, tan, r; @@ -1913,7 +1919,7 @@ static Word32 GivensRotation_fx( { cotan = BASOP_Util_Divide3232_Scale_cadence( z_abs, x_abs, &temp_exp ); temp_exp = add( temp_exp, sub( z_e, x_e ) ); - L_temp = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, 1, Mpy_32_32( cotan, cotan ), 2*temp_exp, &temp_exp ); + L_temp = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, 1, Mpy_32_32( cotan, cotan ), 2 * temp_exp, &temp_exp ); L_temp = Sqrt32( L_temp, &temp_exp ); r = Mpy_32_32( x_abs, L_temp ); *out_e = add( x_e, temp_exp ); @@ -1929,7 +1935,7 @@ static Word32 GivensRotation_fx( { tan = BASOP_Util_Divide3232_Scale_cadence( x_abs, z_abs, &temp_exp ); temp_exp = add( temp_exp, sub( x_e, z_e ) ); - L_temp = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, 1, Mpy_32_32( tan, tan ), 2*temp_exp, &temp_exp ); + L_temp = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, 1, Mpy_32_32( tan, tan ), 2 * temp_exp, &temp_exp ); L_temp = Sqrt32( L_temp, &temp_exp ); r = Mpy_32_32( z_abs, L_temp ); *out_e = add( z_e, temp_exp ); diff --git a/lib_dec/ivas_tcx_core_dec.c b/lib_dec/ivas_tcx_core_dec.c index 761c7c94b..1703bbead 100644 --- a/lib_dec/ivas_tcx_core_dec.c +++ b/lib_dec/ivas_tcx_core_dec.c @@ -58,7 +58,7 @@ static void stereo_tcx_dec_mode_switch_reconf( Decoder_State *st, const int16_t #ifdef IVAS_FLOAT_FIXED -static void dec_prm_tcx_ivas_fx(Decoder_State *st, Word16 param[], Word16 param_lpc[], Word16 *total_nbbits, const Word16 last_element_mode, Word16 *bitsRead); +static void dec_prm_tcx_ivas_fx( Decoder_State *st, Word16 param[], Word16 param_lpc[], Word16 *total_nbbits, const Word16 last_element_mode, Word16 *bitsRead ); static void stereo_tcx_dec_mode_switch_reconf_ivas_fx( Decoder_State *st, const Word16 MCT_flag, const Word16 last_element_mode, Word16 *Q_syn_Overl_TDAC, Word16 *Q_fer_samples, Word16 *Q_syn_Overl, Word16 *Q_syn_Overl_TDACFB, Word16 *Q_syn_OverlFB, Word16 *Q_old_out, Word16 *Q_old_outLB, Word16 *Q_old_Aq_12_8 ); #endif // IVAS_FLOAT_FIXED /*-------------------------------------------------------------* @@ -325,13 +325,13 @@ void stereo_tcx_core_dec_fx( bitsRead = 0; LSF_Q_prediction = -1; /* to avoid compilation warnings */ - IF( EQ_32(frameMode, FRAMEMODE_NORMAL) ) + IF( EQ_32( frameMode, FRAMEMODE_NORMAL ) ) { st->m_decodeMode = DEC_NO_FRAM_LOSS; bfi = 0; } - IF( EQ_32(frameMode, FRAMEMODE_MISSING) ) + IF( EQ_32( frameMode, FRAMEMODE_MISSING ) ) { st->m_decodeMode = DEC_CONCEALMENT_EXT; bfi = 1; @@ -352,7 +352,7 @@ void stereo_tcx_core_dec_fx( /* Initialize pointers */ synth_fx = synth_buf_fx + hTcxDec->old_synth_len; synthFB_fx = synth_bufFB_fx + hTcxDec->old_synth_lenFB; - Copy_Scale_sig( hTcxDec->old_synth, synth_buf_fx, hTcxDec->old_synth_len, -st->Q_syn); + Copy_Scale_sig( hTcxDec->old_synth, synth_buf_fx, hTcxDec->old_synth_len, -st->Q_syn ); Copy( hTcxDec->old_synthFB_fx, synth_bufFB_fx, hTcxDec->old_synth_lenFB ); set16_fx( synth_fx, 0, L_FRAME_PLUS + M ); set16_fx( synthFB_fx, 0, L_FRAME_PLUS + M ); @@ -464,7 +464,7 @@ void stereo_tcx_core_dec_fx( lsfBase = PlcGetLsfBase( st->lpcQuantization, st->narrowBand, st->sr_core ); - dlpc_bfi( st->L_frame, lsfnew_uw_fx, st->lsfold_uw, st->last_good, st->nbLostCmpt, st->mem_MA_fx, st->mem_AR_fx, &( st->stab_fac_fx ), st->lsf_adaptive_mean_fx, st->numlpc, st->lsf_cng, (Word8)st->plcBackgroundNoiseUpdated, st->lsf_q_cng, st->old_lsf_q_cng, lsfBase, (Word8) st->tcxonly ); + dlpc_bfi( st->L_frame, lsfnew_uw_fx, st->lsfold_uw, st->last_good, st->nbLostCmpt, st->mem_MA_fx, st->mem_AR_fx, &( st->stab_fac_fx ), st->lsf_adaptive_mean_fx, st->numlpc, st->lsf_cng, (Word8) st->plcBackgroundNoiseUpdated, st->lsf_q_cng, st->old_lsf_q_cng, lsfBase, (Word8) st->tcxonly ); hTcxDec->envWeighted = 0; @@ -619,7 +619,7 @@ void stereo_tcx_core_dec_fx( E_LPC_f_lsp_a_conversion( &lsp_fx[( k + 1 ) * M], Aq_fx, M ); { - //IGFDecRestoreTCX10SubFrameData_flt( st->hIGFDec, k ); /*float call to be removed*/ + // IGFDecRestoreTCX10SubFrameData_flt( st->hIGFDec, k ); /*float call to be removed*/ IGFDecRestoreTCX10SubFrameData_fx( st->hIGFDec, k ); } @@ -715,7 +715,7 @@ void stereo_tcx_core_dec_fx( } /* Update past buffers */ - Copy_Scale_sig( synth_buf_fx + st->L_frame, hTcxDec->old_synth, hTcxDec->old_synth_len, 0); + Copy_Scale_sig( synth_buf_fx + st->L_frame, hTcxDec->old_synth, hTcxDec->old_synth_len, 0 ); Copy( hTcxDec->old_synthFB_fx + hTcxDec->L_frameTCX - NS2SA_fx2( st->output_Fs, PH_ECU_MEM_NS ), hTcxDec->synth_history_fx, NS2SA_fx2( st->output_Fs, PH_ECU_MEM_NS ) ); Copy( synth_bufFB_fx + hTcxDec->L_frameTCX, hTcxDec->old_synthFB_fx, hTcxDec->old_synth_lenFB ); Copy( st->hHQ_core->old_out_fx + NS2SA_fx2( st->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->old_synthFB_fx + hTcxDec->old_synth_lenFB, NS2SA_fx2( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ); @@ -780,7 +780,7 @@ void stereo_tcx_core_dec_fx( post_decoder( st, synth_buf_fx, pit_gain_fx, pitch, signal_out_fx, st->p_bpf_noise_buf ); #ifdef MSAN_FIX - IF( st->p_bpf_noise_buf_32 && st->tcxonly == 0) + IF( st->p_bpf_noise_buf_32 && st->tcxonly == 0 ) #else IF( st->p_bpf_noise_buf_32 ) #endif // MSAN_FIX @@ -1633,8 +1633,8 @@ static void stereo_tcx_dec_mode_switch_reconf( #endif #ifdef IVAS_FLOAT_FIXED static void stereo_tcx_dec_mode_switch_reconf_ivas_fx( - Decoder_State *st, /* i/o: decoder state structure */ - const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0)*/ + Decoder_State *st, /* i/o: decoder state structure */ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0)*/ const Word16 last_element_mode, /* i : element mode of previous frame */ Word16 *Q_syn_Overl_TDAC, Word16 *Q_fer_samples, @@ -1643,8 +1643,7 @@ static void stereo_tcx_dec_mode_switch_reconf_ivas_fx( Word16 *Q_syn_OverlFB, Word16 *Q_old_out, Word16 *Q_old_outLB, - Word16 *Q_old_Aq_12_8 -) + Word16 *Q_old_Aq_12_8 ) { Word16 frame_size_index; @@ -1670,7 +1669,7 @@ static void stereo_tcx_dec_mode_switch_reconf_ivas_fx( } /* Reconfigure Core */ - mode_switch_decoder_LPD_ivas_fx( st, st->bwidth, st->bits_frame_nominal * FRAMES_PER_SEC, st->last_bits_frame_nominal * FRAMES_PER_SEC, frame_size_index, MCT_flag, last_element_mode,Q_syn_Overl_TDAC, Q_fer_samples, Q_syn_Overl, Q_syn_Overl_TDACFB, Q_syn_OverlFB, Q_old_out, Q_old_outLB, Q_old_Aq_12_8); + mode_switch_decoder_LPD_ivas_fx( st, st->bwidth, st->bits_frame_nominal * FRAMES_PER_SEC, st->last_bits_frame_nominal * FRAMES_PER_SEC, frame_size_index, MCT_flag, last_element_mode, Q_syn_Overl_TDAC, Q_fer_samples, Q_syn_Overl, Q_syn_Overl_TDACFB, Q_syn_OverlFB, Q_old_out, Q_old_outLB, Q_old_Aq_12_8 ); return; } @@ -1697,7 +1696,7 @@ static void dec_prm_tcx_ivas_fx( IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { // The value of 1/ FRAMES_PER_SEC shifted left by 19 because taking Q as 15 led to precision loss - st->bits_frame_core = (Word16) L_sub(L_shr(Mpy_32_16_1( st->total_brate , 10486 ),4) , st->next_bit_pos ); + st->bits_frame_core = (Word16) L_sub( L_shr( Mpy_32_16_1( st->total_brate, 10486 ), 4 ), st->next_bit_pos ); } start_bit_pos = st->next_bit_pos; @@ -1791,8 +1790,8 @@ static void dec_prm_tcx_ivas_fx( } #if 1 /*Fixed to float changes*/ - //st->hTcxLtpDec->tcxltp_gain_float = fixedToFloat( st->hTcxLtpDec->tcxltp_gain, 15 ); - //st->hTcxDec->tcxltp_last_gain_unmodified_float = fixedToFloat( st->hTcxDec->tcxltp_last_gain_unmodified, 15 ); + // st->hTcxLtpDec->tcxltp_gain_float = fixedToFloat( st->hTcxLtpDec->tcxltp_gain, 15 ); + // st->hTcxDec->tcxltp_last_gain_unmodified_float = fixedToFloat( st->hTcxDec->tcxltp_last_gain_unmodified, 15 ); #endif // Ends here return; } diff --git a/lib_dec/ivas_td_low_rate_dec.c b/lib_dec/ivas_td_low_rate_dec.c index 2282cc30f..9f1c7b167 100644 --- a/lib_dec/ivas_td_low_rate_dec.c +++ b/lib_dec/ivas_td_low_rate_dec.c @@ -173,43 +173,45 @@ void tdm_low_rate_dec( /*hGSCDec float2fix*/ st->GSC_noisy_speech = st->GSC_noisy_speech; - //st->lp_gainc_fx = float_to_fix16(st->lp_gainc, Q3); + // st->lp_gainc_fx = float_to_fix16(st->lp_gainc, Q3); st->last_good = st->last_good; st->Last_GSC_noisy_speech_flag = st->Last_GSC_noisy_speech_flag; st->last_coder_type = st->last_coder_type; /*hGSCDec end*/ Word16 dct_epit_fx[L_FRAME]; - //Word16 tmp_noise_fx; + // Word16 tmp_noise_fx; Word16 pitch_buf_fx[NB_SUBFR16k]; Word16 voice_factors_fx[5]; Word16 exc_fx[L_FRAME]; Word16 exc2_fx[L_FRAME]; Word16 bwe_exc_fx[L_FRAME32k]; Word16 lsf_new_fx[M]; - //floatToFixed_arr(exc, exc_fx, 0, L_FRAME); - //floatToFixed_arr(exc2, exc2_fx, 0, L_FRAME); - set_s(dct_epit_fx, 0, L_FRAME); - set_s(exc_fx, 0, L_FRAME); - set_s(exc2_fx, 0, L_FRAME); - set_s(bwe_exc_fx, 0, L_FRAME32k); - for (int i = 0; i < M; i++) { - lsf_new_fx[i] = (Word16)(lsf_new[i] * 2.56f); + // floatToFixed_arr(exc, exc_fx, 0, L_FRAME); + // floatToFixed_arr(exc2, exc2_fx, 0, L_FRAME); + set_s( dct_epit_fx, 0, L_FRAME ); + set_s( exc_fx, 0, L_FRAME ); + set_s( exc2_fx, 0, L_FRAME ); + set_s( bwe_exc_fx, 0, L_FRAME32k ); + for ( int i = 0; i < M; i++ ) + { + lsf_new_fx[i] = (Word16) ( lsf_new[i] * 2.56f ); } - tdm_low_rate_dec_fx(st, dct_epit_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, lsf_new_fx); - fixedToFloat_arr(dct_epit_fx, dct_epit, st->Q_exc, L_FRAME); + tdm_low_rate_dec_fx( st, dct_epit_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, lsf_new_fx ); + fixedToFloat_arr( dct_epit_fx, dct_epit, st->Q_exc, L_FRAME ); //*tmp_noise = fixedToFloat(tmp_noise_fx, Q3); - fixedToFloat_arr(pitch_buf_fx, pitch_buf, Q6, NB_SUBFR16k); - fixedToFloat_arr(voice_factors_fx, voice_factors, Q15, 5); - fixedToFloat_arr(exc_fx, exc, st->Q_exc, L_FRAME); - fixedToFloat_arr(exc2_fx, exc2 , st->Q_exc, L_FRAME); - if (bwe_exc) { - fixedToFloat_arr(bwe_exc_fx, bwe_exc, st->Q_exc, L_FRAME32k); + fixedToFloat_arr( pitch_buf_fx, pitch_buf, Q6, NB_SUBFR16k ); + fixedToFloat_arr( voice_factors_fx, voice_factors, Q15, 5 ); + fixedToFloat_arr( exc_fx, exc, st->Q_exc, L_FRAME ); + fixedToFloat_arr( exc2_fx, exc2, st->Q_exc, L_FRAME ); + if ( bwe_exc ) + { + fixedToFloat_arr( bwe_exc_fx, bwe_exc, st->Q_exc, L_FRAME32k ); } - + /*hGSCDec fix2float*/ st->GSC_noisy_speech = st->GSC_noisy_speech; - //st->lp_gainc = fixedToFloat(st->lp_gainc_fx, Q3); + // st->lp_gainc = fixedToFloat(st->lp_gainc_fx, Q3); /*hGSCDec end*/ *tmp_noise = st->lp_gainc; @@ -218,9 +220,9 @@ void tdm_low_rate_dec( #endif #ifdef IVAS_FLOAT_FIXED void tdm_low_rate_dec_fx( - Decoder_State *st, /* i/o: decoder static memory */ - Word16 dct_epit[], /* o : GSC excitation in DCT domain Q_exc */ - //Word16 *tmp_noise, /* o : long term temporary noise energy Q3 */ + Decoder_State *st, /* i/o: decoder static memory */ + Word16 dct_epit[], /* o : GSC excitation in DCT domain Q_exc */ + // Word16 *tmp_noise, /* o : long term temporary noise energy Q3 */ Word16 *pitch_buf, /* o : floating pitch values for each subframe Q6 */ Word16 *voice_factors, /* o : voicing factors Q15 */ Word16 *exc, /* i/o: adapt. excitation exc Q_exc */ @@ -234,7 +236,7 @@ void tdm_low_rate_dec_fx( Word16 Diff_len, nb_subfr; Word16 attack_flag; Word16 last_bin; - //float exc_wo_nf[L_FRAME]; + // float exc_wo_nf[L_FRAME]; Word16 exc_wo_nf_fx[L_FRAME]; hGSCDec = st->hGSCDec; @@ -252,17 +254,17 @@ void tdm_low_rate_dec_fx( pit_band_idx = 10 + BAND1k2; hGSCDec->Last_GSC_pit_band_idx = pit_band_idx; - //st->tilt_code = 0.0f; + // st->tilt_code = 0.0f; st->tilt_code_fx = 0; - //set_f(exc, 0, L_FRAME); - //set_f(dct_epit, 0, L_FRAME); - //set_f(pitch_buf, L_SUBFR, NB_SUBFR); - set_s(exc, 0, L_FRAME); - set_s(dct_epit, 0, L_FRAME); - set_s(pitch_buf, shl(L_SUBFR, Q6), NB_SUBFR); + // set_f(exc, 0, L_FRAME); + // set_f(dct_epit, 0, L_FRAME); + // set_f(pitch_buf, L_SUBFR, NB_SUBFR); + set_s( exc, 0, L_FRAME ); + set_s( dct_epit, 0, L_FRAME ); + set_s( pitch_buf, shl( L_SUBFR, Q6 ), NB_SUBFR ); st->bpf_off = 1; - st->bfi_pitch_fx = mean_fx(pitch_buf, 4); + st->bfi_pitch_fx = mean_fx( pitch_buf, 4 ); st->bfi_pitch_frame = L_FRAME; Diff_len = L_FRAME / 2; st->bpf_off = 0; @@ -272,64 +274,64 @@ void tdm_low_rate_dec_fx( * GSC decoder *--------------------------------------------------------------------------------------*/ - /* find the current total number of bits used */ + /* find the current total number of bits used */ tmp_nb_bits_tot = st->next_bit_pos; - IF(st->element_mode == IVAS_CPE_TD) + IF( st->element_mode == IVAS_CPE_TD ) { tmp_nb_bits_tot += TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS; } - IF(st->tdm_LRTD_flag == 1) + IF( st->tdm_LRTD_flag == 1 ) { tmp_nb_bits_tot -= STEREO_BITS_TCA; } - IF(st->extl_brate_orig > 0) + IF( st->extl_brate_orig > 0 ) { /* subtract 1 bit for TBE/BWE BWE flag (bit counted in extl_brate) */ tmp_nb_bits_tot--; } - //gsc_dec(st, dct_epit, pit_band_idx, Diff_len, tmp_nb_bits_tot, nb_subfr, st->coder_type, &last_bin, lsf_new, exc_wo_nf, tmp_noise); - gsc_dec_ivas_fx(st, dct_epit, pit_band_idx, Diff_len, tmp_nb_bits_tot, nb_subfr, st->coder_type, &last_bin, lsf_new, exc_wo_nf_fx, st->Q_exc); + // gsc_dec(st, dct_epit, pit_band_idx, Diff_len, tmp_nb_bits_tot, nb_subfr, st->coder_type, &last_bin, lsf_new, exc_wo_nf, tmp_noise); + gsc_dec_ivas_fx( st, dct_epit, pit_band_idx, Diff_len, tmp_nb_bits_tot, nb_subfr, st->coder_type, &last_bin, lsf_new, exc_wo_nf_fx, st->Q_exc ); /*--------------------------------------------------------------------------------------* * iDCT transform *--------------------------------------------------------------------------------------*/ - //edct(dct_epit, exc, L_FRAME, IVAS_CPE_TD); - edct_16fx(dct_epit, exc, L_FRAME, find_guarded_bits_fx(L_FRAME), IVAS_CPE_TD); + // edct(dct_epit, exc, L_FRAME, IVAS_CPE_TD); + edct_16fx( dct_epit, exc, L_FRAME, find_guarded_bits_fx( L_FRAME ), IVAS_CPE_TD ); - //edct(exc_wo_nf, exc_wo_nf, L_FRAME, IVAS_CPE_TD); - edct_16fx(exc_wo_nf_fx, exc_wo_nf_fx, L_FRAME, find_guarded_bits_fx(L_FRAME), IVAS_CPE_TD); + // edct(exc_wo_nf, exc_wo_nf, L_FRAME, IVAS_CPE_TD); + edct_16fx( exc_wo_nf_fx, exc_wo_nf_fx, L_FRAME, find_guarded_bits_fx( L_FRAME ), IVAS_CPE_TD ); /*----------------------------------------------------------------------* * Remove potential pre-echo in case an onset has been detected *----------------------------------------------------------------------*/ - //pre_echo_att(&hGSCDec->Last_frame_ener, exc, attack_flag, st->last_coder_type, st->L_frame); - pre_echo_att_fx(&hGSCDec->Last_frame_ener_fx, exc, attack_flag, st->Q_exc, st->last_coder_type, st->L_frame); + // pre_echo_att(&hGSCDec->Last_frame_ener, exc, attack_flag, st->last_coder_type, st->L_frame); + pre_echo_att_fx( &hGSCDec->Last_frame_ener_fx, exc, attack_flag, st->Q_exc, st->last_coder_type, st->L_frame ); /*--------------------------------------------------------------------------------------* * Update BWE excitation *--------------------------------------------------------------------------------------*/ - //set_f(voice_factors, 0.0f, NB_SUBFR16k); - set_s(voice_factors, 0, NB_SUBFR16k); + // set_f(voice_factors, 0.0f, NB_SUBFR16k); + set_s( voice_factors, 0, NB_SUBFR16k ); - IF(st->hBWE_TD != NULL) + IF( st->hBWE_TD != NULL ) { - IF(st->tdm_LRTD_flag) + IF( st->tdm_LRTD_flag ) { - //interp_code_5over2(exc, bwe_exc, L_FRAME); - interp_code_5over2_fx(exc, bwe_exc, L_FRAME); + // interp_code_5over2(exc, bwe_exc, L_FRAME); + interp_code_5over2_fx( exc, bwe_exc, L_FRAME ); } ELSE { - //set_f(bwe_exc, 0, L_FRAME32k); - set_s(bwe_exc, 0, L_FRAME32k); + // set_f(bwe_exc, 0, L_FRAME32k); + set_s( bwe_exc, 0, L_FRAME32k ); } } @@ -337,16 +339,16 @@ void tdm_low_rate_dec_fx( * Updates *--------------------------------------------------------------------------------------*/ - //mvr2r(exc, exc2, L_FRAME); - Copy(exc, exc2, L_FRAME); - //mvr2r(exc_wo_nf, exc, L_FRAME); - Copy(exc_wo_nf_fx, exc, L_FRAME); + // mvr2r(exc, exc2, L_FRAME); + Copy( exc, exc2, L_FRAME ); + // mvr2r(exc_wo_nf, exc, L_FRAME); + Copy( exc_wo_nf_fx, exc, L_FRAME ); /*--------------------------------------------------------------------------------------* * Channel aware mode parameters *--------------------------------------------------------------------------------------*/ - set_s(st->tilt_code_dec_fx, 0, NB_SUBFR16k); + set_s( st->tilt_code_dec_fx, 0, NB_SUBFR16k ); return; } @@ -507,8 +509,8 @@ void decod_gen_2sbfr_ivas_fx( Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc */ Word16 *gain_buf, /* o : floating pitch gain for each subframe Q14 */ const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ - const Word16 tdm_Pri_pitch_buf[] /* i : pitch values for primary channel Q6 */ - ) + const Word16 tdm_Pri_pitch_buf[] /* i : pitch values for primary channel Q6 */ +) { Word16 T0, T0_frac, T0_min, T0_max; /* integer pitch variables */ // float gain_pit = 0.0f; /* pitch gain */ @@ -531,7 +533,7 @@ void decod_gen_2sbfr_ivas_fx( Word16 code[2 * L_SUBFR]; /* algebraic codevector */ const Word16 *p_Aq; /* Pointer to frame LP coefficient */ Word16 *pt_pitch; /* pointer to floating pitch */ - Word16 i_subfr; /* tmp variables */ + Word16 i_subfr; /* tmp variables */ Word16 L_frame; Word16 pitch_limit_flag; // float error; @@ -615,24 +617,24 @@ void decod_gen_2sbfr_ivas_fx( Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, &exc[i_subfr], ( bwe_exc != NULL ) ? &bwe_exc[i_subfr * HIBND_ACB_L_FAC] : NULL, st->hGSCDec->last_exc_dct_in_fx, 2 * L_SUBFR, 2 * L_SUBFR * HIBND_ACB_L_FAC, gain_code, &( st->Q_exc ), st->Q_subfr, exc2, i_subfr, st->coder_type ); -#else - - IF(EQ_16(st->L_frame, L_FRAME)) +#else + + IF( EQ_16( st->L_frame, L_FRAME ) ) { - Rescale_exc(st->hMusicPF->dct_post_old_exc_fx, &exc[i_subfr], (bwe_exc != NULL) ? &bwe_exc[i_subfr * HIBND_ACB_L_FAC] : NULL, st->hGSCDec->last_exc_dct_in_fx, - L_SUBFR, L_SUBFR* HIBND_ACB_L_FAC, gain_code, &(st->Q_exc), st->Q_subfr, exc2, i_subfr, st->coder_type); + Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, &exc[i_subfr], ( bwe_exc != NULL ) ? &bwe_exc[i_subfr * HIBND_ACB_L_FAC] : NULL, st->hGSCDec->last_exc_dct_in_fx, + L_SUBFR, L_SUBFR * HIBND_ACB_L_FAC, gain_code, &( st->Q_exc ), st->Q_subfr, exc2, i_subfr, st->coder_type ); } ELSE { - Rescale_exc(st->hMusicPF->dct_post_old_exc_fx, &exc[i_subfr], (bwe_exc != NULL) ? &bwe_exc[i_subfr * 2] : NULL, st->hGSCDec->last_exc_dct_in_fx, - L_SUBFR, L_SUBFR * 2, gain_code, &(st->Q_exc), st->Q_subfr, exc2, i_subfr, st->coder_type); + Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, &exc[i_subfr], ( bwe_exc != NULL ) ? &bwe_exc[i_subfr * 2] : NULL, st->hGSCDec->last_exc_dct_in_fx, + L_SUBFR, L_SUBFR * 2, gain_code, &( st->Q_exc ), st->Q_subfr, exc2, i_subfr, st->coder_type ); } #endif - Word16 gain_code16 = round_fx(L_shl(gain_code, st->Q_exc)); /*Q_exc*/ + Word16 gain_code16 = round_fx( L_shl( gain_code, st->Q_exc ) ); /*Q_exc*/ #ifdef FIX_734_MISSING_SUBFR_LOW_RATE_ACELP Acelp_dec_total_exc( exc, exc2, gain_code16, gain_pit, i_subfr, code, 2 * L_SUBFR ); -#else - Acelp_dec_total_exc(exc, exc2, gain_code16, gain_pit, i_subfr, code, L_SUBFR); +#else + Acelp_dec_total_exc( exc, exc2, gain_code16, gain_pit, i_subfr, code, L_SUBFR ); #endif /*-----------------------------------------------------------------* * Prepare TBE excitation @@ -650,18 +652,18 @@ void decod_gen_2sbfr_ivas_fx( * Excitation enhancements (update of total excitation signal) * called twice because adapting it to double the subfr length would need lot of modifications *----------------------------------------------------------------*/ -#if 1//def FIX_734_MISSING_SUBFR_LOW_RATE_ACELP - enhancer_fx( st->core_brate, 0, GENERIC, i_subfr, L_frame, voice_fac, st->stab_fac_fx, norm_gain_code, gain_inov, &st->gc_threshold_fx, code, exc2 , gain_pit, &st->dm_fx, st->Q_exc ); +#if 1 // def FIX_734_MISSING_SUBFR_LOW_RATE_ACELP + enhancer_fx( st->core_brate, 0, GENERIC, i_subfr, L_frame, voice_fac, st->stab_fac_fx, norm_gain_code, gain_inov, &st->gc_threshold_fx, code, exc2, gain_pit, &st->dm_fx, st->Q_exc ); enhancer_fx( st->core_brate, 0, GENERIC, i_subfr, L_frame, voice_fac, st->stab_fac_fx, norm_gain_code, gain_inov, &st->gc_threshold_fx, code + L_SUBFR, exc2 + L_SUBFR, gain_pit, &st->dm_fx, st->Q_exc ); #else // enhancer(MODE1, st->core_brate, -1, 0, GENERIC, L_frame, voice_fac, st->stab_fac, norm_gain_code, gain_inov, &st->gc_threshold, code, exc2 + i_subfr, gain_pit, st->dispMem); // enhancer_fx(MODE1, st->core_brate, -1, 0, GENERIC, L_frame, voice_fac, st->stab_fac, norm_gain_code, gain_inov, &st->gc_threshold, code, exc2 + i_subfr, gain_pit, st->dispMem); - enhancer_fx( st->core_brate, 0, GENERIC, i_subfr, L_frame, voice_fac, st->stab_fac_fx, norm_gain_code, gain_inov, &st->gc_threshold_fx, code, exc2, gain_pit, &st->dm_fx, st->Q_exc); + enhancer_fx( st->core_brate, 0, GENERIC, i_subfr, L_frame, voice_fac, st->stab_fac_fx, norm_gain_code, gain_inov, &st->gc_threshold_fx, code, exc2, gain_pit, &st->dm_fx, st->Q_exc ); // enhancer(MODE1, st->core_brate, -1, 0, GENERIC, L_frame, voice_fac, st->stab_fac, norm_gain_code, gain_inov, &st->gc_threshold, code + L_SUBFR, exc2 + i_subfr + L_SUBFR, gain_pit, st->dispMem); // enhancer_fx(MODE1, st->core_brate, -1, 0, GENERIC, L_frame, voice_fac, st->stab_fac, norm_gain_code, gain_inov, &st->gc_threshold, code + L_SUBFR, exc2 + i_subfr + L_SUBFR, gain_pit, st->dispMem); - enhancer_fx( st->core_brate, 0, GENERIC, i_subfr, L_frame, voice_fac, st->stab_fac_fx, norm_gain_code, gain_inov, &st->gc_threshold_fx, code + L_SUBFR, exc2 + L_SUBFR, gain_pit, &st->dm_fx, st->Q_exc); + enhancer_fx( st->core_brate, 0, GENERIC, i_subfr, L_frame, voice_fac, st->stab_fac_fx, norm_gain_code, gain_inov, &st->gc_threshold_fx, code + L_SUBFR, exc2 + L_SUBFR, gain_pit, &st->dm_fx, st->Q_exc ); #endif p_Aq += 2 * ( M + 1 ); @@ -673,12 +675,12 @@ void decod_gen_2sbfr_ivas_fx( gain_buf[( i_subfr + L_SUBFR ) / L_SUBFR] = gain_pit; st->tilt_code_dec_fx[i_subfr / L_SUBFR] = st->tilt_code_fx; st->tilt_code_dec_fx[( i_subfr + L_SUBFR ) / L_SUBFR] = st->tilt_code_fx; - //st->tilt_code_dec[i_subfr / L_SUBFR] = st->tilt_code; - //st->tilt_code_dec[( i_subfr + L_SUBFR ) / L_SUBFR] = st->tilt_code; + // st->tilt_code_dec[i_subfr / L_SUBFR] = st->tilt_code; + // st->tilt_code_dec[( i_subfr + L_SUBFR ) / L_SUBFR] = st->tilt_code; } /* SC-VBR */ - //st->prev_gain_pit_dec = gain_pit; + // st->prev_gain_pit_dec = gain_pit; st->prev_gain_pit_dec_fx = gain_pit; return; diff --git a/lib_dec/jbm_jb4_circularbuffer.c b/lib_dec/jbm_jb4_circularbuffer.c index b44dfd368..af539f930 100644 --- a/lib_dec/jbm_jb4_circularbuffer.c +++ b/lib_dec/jbm_jb4_circularbuffer.c @@ -73,7 +73,7 @@ ivas_error JB4_CIRCULARBUFFER_Create( { JB4_CIRCULARBUFFER_HANDLE h; - IF ( ( h = malloc( sizeof( struct JB4_CIRCULARBUFFER ) ) ) == NULL ) + IF( ( h = malloc( sizeof( struct JB4_CIRCULARBUFFER ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for JBM\n" ) ); } @@ -98,17 +98,17 @@ void JB4_CIRCULARBUFFER_Destroy( { JB4_CIRCULARBUFFER_HANDLE h; - IF ( !ph ) + IF( !ph ) { return; } h = *ph; - IF ( !h ) + IF( !h ) { return; } - IF ( h->data ) + IF( h->data ) { free( h->data ); } @@ -127,7 +127,7 @@ Word16 JB4_CIRCULARBUFFER_Init( /* keep one element free to be able to decide between full/empty buffer */ ++capacity; - IF ( ( h->data = malloc( capacity * sizeof( JB4_CIRCULARBUFFER_ELEMENT ) ) ) == NULL ) + IF( ( h->data = malloc( capacity * sizeof( JB4_CIRCULARBUFFER_ELEMENT ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for JBM\n" ) ); } @@ -147,14 +147,14 @@ Word16 JB4_CIRCULARBUFFER_Enque( JB4_CIRCULARBUFFER_HANDLE h, JB4_CIRCULARBUFFER_ELEMENT element ) { - IF ( JB4_CIRCULARBUFFER_IsFull( h ) ) + IF( JB4_CIRCULARBUFFER_IsFull( h ) ) { return -1; } h->data[h->writePos] = element; ++h->writePos; - IF ( h->writePos == h->capacity ) + IF( h->writePos == h->capacity ) { h->writePos = 0; move16(); @@ -168,14 +168,14 @@ Word16 JB4_CIRCULARBUFFER_Deque( JB4_CIRCULARBUFFER_HANDLE h, JB4_CIRCULARBUFFER_ELEMENT *pElement ) { - IF ( JB4_CIRCULARBUFFER_IsEmpty( h ) ) + IF( JB4_CIRCULARBUFFER_IsEmpty( h ) ) { return -1; } *pElement = h->data[h->readPos]; ++h->readPos; - IF ( h->readPos == h->capacity ) + IF( h->readPos == h->capacity ) { h->readPos = 0; move16(); @@ -192,7 +192,7 @@ JB4_CIRCULARBUFFER_ELEMENT JB4_CIRCULARBUFFER_Front( JB4_CIRCULARBUFFER_ELEMENT ret; ret = h->data[h->readPos]; - move32(); + move32(); return ret; } @@ -203,15 +203,15 @@ JB4_CIRCULARBUFFER_ELEMENT JB4_CIRCULARBUFFER_Back( { JB4_CIRCULARBUFFER_ELEMENT ret; - IF ( h->writePos != 0U ) + IF( h->writePos != 0U ) { ret = h->data[h->writePos - 1]; - move32(); + move32(); } ELSE { ret = h->data[h->capacity - 1]; - move32(); + move32(); } @@ -224,7 +224,7 @@ Word16 JB4_CIRCULARBUFFER_IsEmpty( { Word16 ret; - IF ( h->readPos == h->writePos ) + IF( h->readPos == h->writePos ) { ret = 1; move16(); @@ -244,7 +244,7 @@ Word16 JB4_CIRCULARBUFFER_IsFull( { Word16 ret; - IF ( ( ( h->writePos + 1 ) % h->capacity ) == h->readPos ) + IF( ( ( h->writePos + 1 ) % h->capacity ) == h->readPos ) { ret = 1; move16(); @@ -264,7 +264,7 @@ UWord16 JB4_CIRCULARBUFFER_Size( { UWord16 ret; - IF ( h->readPos <= h->writePos ) + IF( h->readPos <= h->writePos ) { ret = h->writePos - h->readPos; } @@ -291,13 +291,13 @@ void JB4_CIRCULARBUFFER_Min( minEle = h->data[h->readPos]; move32(); - IF ( h->readPos <= h->writePos ) + IF( h->readPos <= h->writePos ) { /* no wrap around */ /* calc statistics for [readPos;writePos[ */ - FOR ( i = h->readPos; i != h->writePos; ++i ) + FOR( i = h->readPos; i != h->writePos; ++i ) { - IF ( LT_32( h->data[i], minEle ) ) + IF( LT_32( h->data[i], minEle ) ) { minEle = h->data[i]; move32(); @@ -308,18 +308,18 @@ void JB4_CIRCULARBUFFER_Min( { /* wrap around */ /* calc statistics for [readPos;capacity[ */ - FOR ( i = h->readPos; i != h->capacity; ++i ) + FOR( i = h->readPos; i != h->capacity; ++i ) { - IF ( LT_32( h->data[i], minEle ) ) + IF( LT_32( h->data[i], minEle ) ) { minEle = h->data[i]; move32(); } } /* calc statistics for [0;writePos[ */ - FOR ( i = 0; i != h->writePos; ++i ) + FOR( i = 0; i != h->writePos; ++i ) { - IF ( LT_32( h->data[i], minEle ) ) + IF( LT_32( h->data[i], minEle ) ) { minEle = h->data[i]; move32(); @@ -343,13 +343,13 @@ void JB4_CIRCULARBUFFER_Max( /* init output variable */ maxEle = h->data[h->readPos]; move32(); - IF ( h->readPos <= h->writePos ) + IF( h->readPos <= h->writePos ) { /* no wrap around */ /* calc statistics for [readPos;writePos[ */ - FOR ( i = h->readPos; i != h->writePos; ++i ) + FOR( i = h->readPos; i != h->writePos; ++i ) { - IF ( GT_32( h->data[i], maxEle ) ) + IF( GT_32( h->data[i], maxEle ) ) { maxEle = h->data[i]; move32(); @@ -360,18 +360,18 @@ void JB4_CIRCULARBUFFER_Max( { /* wrap around */ /* calc statistics for [readPos;capacity[ */ - FOR ( i = h->readPos; i != h->capacity; ++i ) + FOR( i = h->readPos; i != h->capacity; ++i ) { - IF ( GT_32( h->data[i], maxEle ) ) + IF( GT_32( h->data[i], maxEle ) ) { maxEle = h->data[i]; move32(); } } /* calc statistics for [0;writePos[ */ - FOR ( i = 0; i != h->writePos; ++i ) + FOR( i = 0; i != h->writePos; ++i ) { - IF ( GT_32( h->data[i], maxEle ) ) + IF( GT_32( h->data[i], maxEle ) ) { maxEle = h->data[i]; move32(); @@ -412,13 +412,13 @@ void JB4_CIRCULARBUFFER_MinAndPercentile( maxElementsCapacity = nElementsToIgnore + 1; move16(); assert( maxElementsCapacity <= JBM_MAX_CIRCULAR_ELEMENTS ); - IF ( h->readPos <= h->writePos ) + IF( h->readPos <= h->writePos ) { /* no wrap around */ /* calc statistics for [readPos;writePos[ */ - FOR ( i = h->readPos; i != h->writePos; ++i ) + FOR( i = h->readPos; i != h->writePos; ++i ) { - IF ( LT_32( h->data[i], minEle ) ) + IF( LT_32( h->data[i], minEle ) ) { minEle = h->data[i]; move32(); @@ -430,9 +430,9 @@ void JB4_CIRCULARBUFFER_MinAndPercentile( { /* wrap around */ /* calc statistics for [readPos;capacity[ */ - FOR ( i = h->readPos; i != h->capacity; ++i ) + FOR( i = h->readPos; i != h->capacity; ++i ) { - IF ( LT_32( h->data[i], minEle ) ) + IF( LT_32( h->data[i], minEle ) ) { minEle = h->data[i]; move32(); @@ -440,9 +440,9 @@ void JB4_CIRCULARBUFFER_MinAndPercentile( JB4_CIRCULARBUFFER_calcPercentile( maxElements, &maxElementsSize, maxElementsCapacity, h->data[i] ); } /* calc statistics for [0;writePos[ */ - FOR ( i = 0; i != h->writePos; ++i ) + FOR( i = 0; i != h->writePos; ++i ) { - IF ( LT_32( h->data[i], minEle ) ) + IF( LT_32( h->data[i], minEle ) ) { minEle = h->data[i]; move32(); @@ -470,14 +470,14 @@ static void JB4_CIRCULARBUFFER_calcPercentile( UWord16 i, j; /* insert newElement IF elements buffer is not yet full */ - IF ( *size < capacity ) + IF( *size < capacity ) { - FOR ( i = 0; i != *size; ++i ) + FOR( i = 0; i != *size; ++i ) { - IF ( LE_32( newElement, elements[i] ) ) + IF( LE_32( newElement, elements[i] ) ) { /* insert newElement at index i */ - FOR ( j = *size; j > i; --j ) + FOR( j = *size; j > i; --j ) { elements[j] = elements[j - 1]; move32(); @@ -495,18 +495,18 @@ static void JB4_CIRCULARBUFFER_calcPercentile( } /* check IF newElement is too small to be inserted in elements buffer */ - IF ( LE_32( newElement, elements[0] ) ) + IF( LE_32( newElement, elements[0] ) ) { return; } /* select position to insert newElement to elements */ - FOR ( i = *size - 1; i != 0; --i ) + FOR( i = *size - 1; i != 0; --i ) { - IF ( GE_32( newElement, elements[i] ) ) + IF( GE_32( newElement, elements[i] ) ) { /* insert newElement at index i */ - FOR ( j = 0; j < i; j++ ) + FOR( j = 0; j < i; j++ ) { elements[j] = elements[1 + j]; move32(); diff --git a/lib_dec/jbm_jb4_circularbuffer.h b/lib_dec/jbm_jb4_circularbuffer.h index 3c5a9f3a0..f39bfa2ab 100644 --- a/lib_dec/jbm_jb4_circularbuffer.h +++ b/lib_dec/jbm_jb4_circularbuffer.h @@ -110,4 +110,3 @@ void JB4_CIRCULARBUFFER_MinAndPercentile( const JB4_CIRCULARBUFFER_HANDLE h, uin #endif /* IVAS_FLOAT_FIXED*/ #endif /* JBM_JB4_CIRCULARBUFFER_H */ - diff --git a/lib_dec/jbm_jb4_inputbuffer.c b/lib_dec/jbm_jb4_inputbuffer.c index e10ab6e82..92f488f1b 100644 --- a/lib_dec/jbm_jb4_inputbuffer.c +++ b/lib_dec/jbm_jb4_inputbuffer.c @@ -70,7 +70,7 @@ ivas_error JB4_INPUTBUFFER_Create( { JB4_INPUTBUFFER_HANDLE h; - IF ( ( h = malloc( sizeof( struct JB4_INPUTBUFFER ) ) ) == NULL ) + IF( ( h = malloc( sizeof( struct JB4_INPUTBUFFER ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for JBM\n" ) ); } @@ -96,17 +96,17 @@ void JB4_INPUTBUFFER_Destroy( { JB4_INPUTBUFFER_HANDLE h; - IF ( !ph ) + IF( !ph ) { return; } h = *ph; - IF ( !h ) + IF( !h ) { return; } - IF ( h->data ) + IF( h->data ) { free( h->data ); } @@ -127,7 +127,7 @@ ivas_error JB4_INPUTBUFFER_Init( /* keep one element free to be able to decide between full/empty buffer */ ++capacity; - IF ( ( h->data = malloc( capacity * sizeof( JB4_INPUTBUFFER_ELEMENT ) ) ) == NULL ) + IF( ( h->data = malloc( capacity * sizeof( JB4_INPUTBUFFER_ELEMENT ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for JBM\n" ) ); } @@ -160,17 +160,17 @@ Word16 JB4_INPUTBUFFER_Enque( *replacedElement = NULL; size = JB4_INPUTBUFFER_Size( h ); - IF ( size >= h->capacity - 1 ) + IF( size >= h->capacity - 1 ) { return -1; } /* appending the first element is straight forward */ - IF ( size == 0U ) + IF( size == 0U ) { h->data[h->writePos] = element; ++h->writePos; - IF ( h->writePos == h->capacity ) + IF( h->writePos == h->capacity ) { h->writePos = 0; move16(); @@ -179,11 +179,11 @@ Word16 JB4_INPUTBUFFER_Enque( } /* there's a high probability that the new element can be appended at the back */ - IF ( GT_32( h->compareFunction( element, JB4_INPUTBUFFER_Back( h ), &replace ), 0 ) ) + IF( GT_32( h->compareFunction( element, JB4_INPUTBUFFER_Back( h ), &replace ), 0 ) ) { h->data[h->writePos] = element; ++h->writePos; - IF ( h->writePos == h->capacity ) + IF( h->writePos == h->capacity ) { h->writePos = 0; move16(); @@ -195,21 +195,21 @@ Word16 JB4_INPUTBUFFER_Enque( low = 0; move16(); high = size - 1; - WHILE ( LE_16( low, high ) ) + WHILE( LE_16( low, high ) ) { middle = add( low, shr( sub( high, low ), 1 ) ); diff = h->compareFunction( element, JB4_INPUTBUFFER_Element( h, middle ), &replace ); - IF ( LT_16( diff, 0 ) ) + IF( LT_16( diff, 0 ) ) { high = sub( middle, 1 ); } - ELSE IF ( GT_16( diff, 0 ) ) + ELSE IF( GT_16( diff, 0 ) ) { low = add( middle, 1 ); } ELSE /* an element with same index is already stored */ { - IF ( replace != 0 ) + IF( replace != 0 ) { *replacedElement = h->data[( h->readPos + middle ) % h->capacity]; h->data[( h->readPos + middle ) % h->capacity] = element; @@ -221,7 +221,7 @@ Word16 JB4_INPUTBUFFER_Enque( insertPos = ( h->readPos + low ) % h->capacity; - IF ( h->readPos < h->writePos ) + IF( h->readPos < h->writePos ) { canMoveRight = 1; move16(); @@ -238,17 +238,17 @@ Word16 JB4_INPUTBUFFER_Enque( assert( canMoveRight != 0 || canMoveLeft != 0 ); - IF ( canMoveRight ) + IF( canMoveRight ) { /* move higher elements to the right and insert at insertPos */ - FOR ( j = h->writePos; j > insertPos; --j ) + FOR( j = h->writePos; j > insertPos; --j ) { h->data[j] = h->data[j - 1]; } h->data[insertPos] = element; ++h->writePos; - IF ( h->writePos == h->capacity ) + IF( h->writePos == h->capacity ) { h->writePos = 0; move16(); @@ -257,7 +257,7 @@ Word16 JB4_INPUTBUFFER_Enque( ELSE { /* move lower elements to the left and insert before insertPos */ - FOR ( j = 0; j < low; j++ ) + FOR( j = 0; j < low; j++ ) { h->data[h->readPos - 1 + j] = h->data[h->readPos + j]; } @@ -275,14 +275,14 @@ Word16 JB4_INPUTBUFFER_Deque( JB4_INPUTBUFFER_HANDLE h, JB4_INPUTBUFFER_ELEMENT *pElement ) { - IF ( JB4_INPUTBUFFER_IsEmpty( h ) ) + IF( JB4_INPUTBUFFER_IsEmpty( h ) ) { return -1; } *pElement = h->data[h->readPos]; ++h->readPos; - IF ( h->readPos == h->capacity ) + IF( h->readPos == h->capacity ) { h->readPos = 0; move16(); @@ -311,7 +311,7 @@ JB4_INPUTBUFFER_ELEMENT JB4_INPUTBUFFER_Back( { JB4_INPUTBUFFER_ELEMENT ret; - IF ( h->writePos != 0U ) + IF( h->writePos != 0U ) { ret = h->data[h->writePos - 1]; } @@ -332,7 +332,7 @@ JB4_INPUTBUFFER_ELEMENT JB4_INPUTBUFFER_Element( JB4_INPUTBUFFER_ELEMENT ret; /* return h->data[(h->readPos + index) % h->capacity] without error handling */ - IF ( h->readPos + index < h->capacity ) + IF( h->readPos + index < h->capacity ) { ret = h->data[h->readPos + index]; } @@ -365,7 +365,7 @@ Word16 JB4_INPUTBUFFER_IsFull( ret = 0; move16(); - IF ( JB4_INPUTBUFFER_Size( h ) == h->capacity - 1 ) + IF( JB4_INPUTBUFFER_Size( h ) == h->capacity - 1 ) { ret = 1; move16(); @@ -380,7 +380,7 @@ UWord16 JB4_INPUTBUFFER_Size( { UWord16 ret; - IF ( h->readPos <= h->writePos ) + IF( h->readPos <= h->writePos ) { ret = h->writePos - h->readPos; move16(); diff --git a/lib_dec/jbm_jb4_jmf.c b/lib_dec/jbm_jb4_jmf.c index 596e0118d..8af4a8286 100644 --- a/lib_dec/jbm_jb4_jmf.c +++ b/lib_dec/jbm_jb4_jmf.c @@ -94,20 +94,20 @@ ivas_error JB4_JMF_Create( JB4_JMF_HANDLE h; ivas_error error; - IF ( ( h = malloc( sizeof( struct JB4_JMF ) ) ) == NULL ) + IF( ( h = malloc( sizeof( struct JB4_JMF ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for JBM\n" ) ); } - IF ( NE_32( ( error = JB4_CIRCULARBUFFER_Create( &h->fifo ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = JB4_CIRCULARBUFFER_Create( &h->fifo ) ), IVAS_ERR_OK ) ) { return error; } - IF ( NE_32( ( JB4_CIRCULARBUFFER_Create( &h->offsetFifo ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( JB4_CIRCULARBUFFER_Create( &h->offsetFifo ) ), IVAS_ERR_OK ) ) { return error; } - IF ( NE_32( ( JB4_CIRCULARBUFFER_Create( &h->timeStampFifo ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( JB4_CIRCULARBUFFER_Create( &h->timeStampFifo ) ), IVAS_ERR_OK ) ) { return error; } @@ -138,12 +138,12 @@ void JB4_JMF_Destroy( { JB4_JMF_HANDLE h; - IF ( !ph ) + IF( !ph ) { return; } h = *ph; - IF ( !h ) + IF( !h ) { return; } @@ -169,11 +169,11 @@ Word16 JB4_JMF_Init( { /* check parameters */ - IF ( windowSize != 0U && consideredFraction * windowSize / 1000 < 2 ) + IF( windowSize != 0U && consideredFraction * windowSize / 1000 < 2 ) { return -1; } - IF ( consideredFraction > 1000 ) + IF( consideredFraction > 1000 ) { return -1; } @@ -206,7 +206,7 @@ Word16 JB4_JMF_PushPacket( Word32 offset, delay; /* check if this is the first entry */ - IF ( EQ_16( h->firstPacketPushed, 0 ) ) + IF( EQ_16( h->firstPacketPushed, 0 ) ) { h->firstPacketPushed = 1; move16(); @@ -235,7 +235,7 @@ Word16 JB4_JMF_PushPacket( move32(); /* reset delay if absolute value is greater than 60s * to avoid overflow caused by clockdrift */ - IF ( delay > 60 * h->timeScale || delay < -60 * h->timeScale ) + IF( delay > 60 * h->timeScale || delay < -60 * h->timeScale ) { h->lastDelay = 0; move32(); @@ -260,7 +260,7 @@ Word16 JB4_JMF_Jitter( JB4_CIRCULARBUFFER_ELEMENT min_ele, percentile; /* sanity check (must not be empty) and return invalid result if there is only one entry */ - IF ( JB4_CIRCULARBUFFER_Size( h->fifo ) < 2U ) + IF( JB4_CIRCULARBUFFER_Size( h->fifo ) < 2U ) { return -1; } @@ -282,7 +282,7 @@ Word16 JB4_JMF_MinOffset( { JB4_CIRCULARBUFFER_ELEMENT min_ele; - IF ( JB4_CIRCULARBUFFER_IsEmpty( h->offsetFifo ) ) + IF( JB4_CIRCULARBUFFER_IsEmpty( h->offsetFifo ) ) { return -1; } @@ -311,7 +311,7 @@ static void JB4_JMF_pushBack( UWord32 duration; /* check for size and discard first entry if too big */ - IF ( JB4_CIRCULARBUFFER_IsFull( h->fifo ) ) + IF( JB4_CIRCULARBUFFER_IsFull( h->fifo ) ) { JB4_JMF_popFront( h ); } @@ -324,15 +324,15 @@ static void JB4_JMF_pushBack( /* check for duration and discard first entries if too long */ minTime = JB4_CIRCULARBUFFER_Front( h->timeStampFifo ); maxTime = JB4_CIRCULARBUFFER_Back( h->timeStampFifo ); - IF ( maxTime > minTime ) + IF( maxTime > minTime ) { duration = maxTime - minTime; move32(); - WHILE ( duration > h->maxWindowDuration ) + WHILE( duration > h->maxWindowDuration ) { JB4_JMF_popFront( h ); minTime = JB4_CIRCULARBUFFER_Front( h->timeStampFifo ); - IF ( maxTime <= minTime ) + IF( maxTime <= minTime ) { BREAK; } @@ -352,7 +352,7 @@ static void JB4_JMF_popFront( JB4_CIRCULARBUFFER_ELEMENT tmpElement; /* try to remove one element - fails if empty */ - IF ( JB4_CIRCULARBUFFER_Deque( h->fifo, &tmpElement ) != 0 ) + IF( JB4_CIRCULARBUFFER_Deque( h->fifo, &tmpElement ) != 0 ) { return; } diff --git a/lib_dec/jbm_jb4sb.c b/lib_dec/jbm_jb4sb.c index f0a01be30..a0245e908 100644 --- a/lib_dec/jbm_jb4sb.c +++ b/lib_dec/jbm_jb4sb.c @@ -208,7 +208,7 @@ ivas_error JB4_Create( JB4_HANDLE h; ivas_error error; - IF ( ( h = malloc( sizeof( struct JB4 ) ) ) == NULL ) + IF( ( h = malloc( sizeof( struct JB4 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for JB4 structure\n" ) ); } @@ -244,15 +244,15 @@ ivas_error JB4_Create( /* jitter buffer configuration values: done in JB4_Init() */ /* short term jitter evaluation */ - IF ( NE_32( ( error = JB4_JMF_Create( &h->stJmf ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = JB4_JMF_Create( &h->stJmf ) ), IVAS_ERR_OK ) ) { return error; } - IF ( NE_32( ( error = JB4_CIRCULARBUFFER_Create( &h->stJitterFifo ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = JB4_CIRCULARBUFFER_Create( &h->stJitterFifo ) ), IVAS_ERR_OK ) ) { return error; } - IF ( NE_32( ( error = JB4_CIRCULARBUFFER_Create( &h->stTimeStampFifo ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = JB4_CIRCULARBUFFER_Create( &h->stTimeStampFifo ) ), IVAS_ERR_OK ) ) { return error; } @@ -284,7 +284,7 @@ ivas_error JB4_Create( h->pre_partial_frame = 0; h->FecOffWinLen = 0; - FOR ( iter = 0; iter < 10; iter++ ) + FOR( iter = 0; iter < 10; iter++ ) { h->FecOffWin[iter] = 0; move32(); @@ -304,15 +304,15 @@ ivas_error JB4_Create( move32(); /* members to store the data units */ - IF ( ( error = JB4_INPUTBUFFER_Create( &h->inputBuffer ) ) != IVAS_ERR_OK ) + IF( ( error = JB4_INPUTBUFFER_Create( &h->inputBuffer ) ) != IVAS_ERR_OK ) { return error; } /* allocate memory for data units */ - FOR ( iter = 0; iter < MAX_JBM_SLOTS; ++iter ) + FOR( iter = 0; iter < MAX_JBM_SLOTS; ++iter ) { - IF ( ( h->memorySlots[iter].data = malloc( MAX_AU_SIZE ) ) == NULL ) + IF( ( h->memorySlots[iter].data = malloc( MAX_AU_SIZE ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for JB4 structure\n" ) ); } @@ -332,12 +332,12 @@ void JB4_Destroy( JB4_HANDLE h; UWord16 i; - IF ( !ph ) + IF( !ph ) { return; } h = *ph; - IF ( !h ) + IF( !h ) { return; } @@ -348,7 +348,7 @@ void JB4_Destroy( JB4_JMF_Destroy( &h->ltJmf ); JB4_INPUTBUFFER_Destroy( &h->inputBuffer ); - FOR ( i = 0; i < MAX_JBM_SLOTS; ++i ) + FOR( i = 0; i < MAX_JBM_SLOTS; ++i ) { free( h->memorySlots[i].data ); } @@ -369,7 +369,7 @@ ivas_error JB4_Init( ivas_error error; /* internal timescale is 1000, frame duration is 20ms */ - h->timeScale = 1000; /* ms */ + h->timeScale = 1000; /* ms */ move16(); h->frameDuration = 20; /* ms */ move32(); @@ -396,7 +396,7 @@ ivas_error JB4_Init( inputBufferCapacity = MAX_JBM_SLOTS - 2; move16(); - IF ( ( error = JB4_INPUTBUFFER_Init( h->inputBuffer, inputBufferCapacity, JB4_inputBufferCompareFunction ) ) != IVAS_ERR_OK ) + IF( ( error = JB4_INPUTBUFFER_Init( h->inputBuffer, inputBufferCapacity, JB4_inputBufferCompareFunction ) ) != IVAS_ERR_OK ) { return error; } @@ -450,15 +450,15 @@ Word16 JB4_PushDataUnit( assert( dataUnit->timeScale == (UWord16) h->timeScale ); /* ignore frames from too far in future (3 seconds) */ - IF ( h->firstDataUnitPopped && JB4_rtpTimeStampDiff( h->lastReturnedTs, dataUnit->timeStamp ) >= - (Word32) ( 50 * 3 * dataUnit->duration ) ) + IF( h->firstDataUnitPopped && JB4_rtpTimeStampDiff( h->lastReturnedTs, dataUnit->timeStamp ) >= + (Word32) ( 50 * 3 * dataUnit->duration ) ) { JB4_FreeDataUnit( h, dataUnit ); return 0; } /* reserve space for one element to add: drop oldest if buffer is full */ - WHILE ( JB4_INPUTBUFFER_IsFull( h->inputBuffer ) ) + WHILE( JB4_INPUTBUFFER_IsFull( h->inputBuffer ) ) { JB4_dropFromBuffer( h ); } @@ -466,20 +466,20 @@ Word16 JB4_PushDataUnit( /* do statistics on partial copy offset using active primary copies to * avoid unexpected resets because RF_NO_DATA partial copies are dropped before JBM */ - IF ( dataUnit->silenceIndicator == 0 && dataUnit->partial_frame == 0 ) + IF( dataUnit->silenceIndicator == 0 && dataUnit->partial_frame == 0 ) { - IF ( EQ_16( dataUnit->partialCopyOffset, 0 ) ) + IF( EQ_16( dataUnit->partialCopyOffset, 0 ) ) { - IF ( GT_16( h->rfOffset2Active, 0 ) ) - --h->rfOffset2Active; - IF ( GT_16( h->rfOffset3Active, 0 ) ) - --h->rfOffset3Active; - IF ( GT_16( h->rfOffset5Active, 0 ) ) - --h->rfOffset5Active; - IF ( GT_16( h->rfOffset7Active, 0 ) ) - --h->rfOffset7Active; + IF( GT_16( h->rfOffset2Active, 0 ) ) + --h->rfOffset2Active; + IF( GT_16( h->rfOffset3Active, 0 ) ) + --h->rfOffset3Active; + IF( GT_16( h->rfOffset5Active, 0 ) ) + --h->rfOffset5Active; + IF( GT_16( h->rfOffset7Active, 0 ) ) + --h->rfOffset7Active; } - ELSE IF ( EQ_16( dataUnit->partialCopyOffset, 2 ) ) + ELSE IF( EQ_16( dataUnit->partialCopyOffset, 2 ) ) { h->rfOffset2Active = 100; move16(); @@ -490,7 +490,7 @@ Word16 JB4_PushDataUnit( h->rfOffset7Active = 0; move16(); } - ELSE IF ( EQ_16( dataUnit->partialCopyOffset, 3 ) ) + ELSE IF( EQ_16( dataUnit->partialCopyOffset, 3 ) ) { h->rfOffset2Active = 0; move16(); @@ -501,7 +501,7 @@ Word16 JB4_PushDataUnit( h->rfOffset7Active = 0; move16(); } - ELSE IF ( EQ_16( dataUnit->partialCopyOffset, 5 ) ) + ELSE IF( EQ_16( dataUnit->partialCopyOffset, 5 ) ) { h->rfOffset2Active = 0; move16(); @@ -512,7 +512,7 @@ Word16 JB4_PushDataUnit( h->rfOffset7Active = 0; move16(); } - ELSE IF ( EQ_16( dataUnit->partialCopyOffset, 7 ) ) + ELSE IF( EQ_16( dataUnit->partialCopyOffset, 7 ) ) { h->rfOffset2Active = 0; move16(); @@ -525,29 +525,29 @@ Word16 JB4_PushDataUnit( } } - IF ( dataUnit->partial_frame != 0 ) + IF( dataUnit->partial_frame != 0 ) { /* check for "real" late loss: a frame with higher/same timestamp was already returned to be fed into decoder */ - IF ( h->firstDataUnitPopped && LE_32( JB4_rtpTimeStampDiff( h->lastReturnedTs, dataUnit->timeStamp ), 0 ) ) + IF( h->firstDataUnitPopped && LE_32( JB4_rtpTimeStampDiff( h->lastReturnedTs, dataUnit->timeStamp ), 0 ) ) { JB4_FreeDataUnit( h, dataUnit ); return 0; } /* drop partial copy if the missing frame was already concealed */ - IF ( h->firstDataUnitPopped ) + IF( h->firstDataUnitPopped ) { - IF ( LE_16( dataUnit->partialCopyOffset, 3 ) && LT_32( JB4_rtpTimeStampDiff( h->nextExpectedTs, dataUnit->timeStamp ), 0 ) ) + IF( LE_16( dataUnit->partialCopyOffset, 3 ) && LT_32( JB4_rtpTimeStampDiff( h->nextExpectedTs, dataUnit->timeStamp ), 0 ) ) { JB4_FreeDataUnit( h, dataUnit ); return 0; } - ELSE IF ( EQ_16( dataUnit->partialCopyOffset, 5 ) && LT_32( JB4_rtpTimeStampDiff( h->nextExpectedTs, dataUnit->timeStamp ), -40 ) ) + ELSE IF( EQ_16( dataUnit->partialCopyOffset, 5 ) && LT_32( JB4_rtpTimeStampDiff( h->nextExpectedTs, dataUnit->timeStamp ), -40 ) ) { JB4_FreeDataUnit( h, dataUnit ); return 0; } - ELSE IF ( EQ_16( dataUnit->partialCopyOffset, 7 ) && LT_32( JB4_rtpTimeStampDiff( h->nextExpectedTs, dataUnit->timeStamp ), -80 ) ) + ELSE IF( EQ_16( dataUnit->partialCopyOffset, 7 ) && LT_32( JB4_rtpTimeStampDiff( h->nextExpectedTs, dataUnit->timeStamp ), -80 ) ) { JB4_FreeDataUnit( h, dataUnit ); return 0; @@ -555,10 +555,10 @@ Word16 JB4_PushDataUnit( } /* try to store partial copy - will be dropped if primary copy already available */ - IF ( EQ_16( JB4_INPUTBUFFER_Enque( h->inputBuffer, dataUnit, (void **) &droppedDataUnit ), 0 ) ) + IF( EQ_16( JB4_INPUTBUFFER_Enque( h->inputBuffer, dataUnit, (void **) &droppedDataUnit ), 0 ) ) { /* partial copy is useful, consider it in long-term jitter estimation */ - IF ( LE_16( dataUnit->partialCopyOffset, 3 ) ) + IF( LE_16( dataUnit->partialCopyOffset, 3 ) ) { JB4_JMF_PushPacket( h->ltJmf, rcvTime, dataUnit->timeStamp ); } @@ -567,7 +567,7 @@ Word16 JB4_PushDataUnit( { JB4_FreeDataUnit( h, dataUnit ); } - IF ( droppedDataUnit != NULL ) + IF( droppedDataUnit != NULL ) { JB4_FreeDataUnit( h, droppedDataUnit ); } @@ -578,9 +578,9 @@ Word16 JB4_PushDataUnit( JB4_JMF_PushPacket( h->ltJmf, rcvTime, dataUnit->timeStamp ); JB4_estimateShortTermJitter( h, rcvTime, dataUnit->timeStamp ); /* check for "real" late loss: a frame with higher/same timestamp was already returned to be fed into decoder */ - IF ( h->firstDataUnitPopped && JB4_rtpTimeStampDiff( h->lastReturnedTs, dataUnit->timeStamp ) <= 0 ) + IF( h->firstDataUnitPopped && JB4_rtpTimeStampDiff( h->lastReturnedTs, dataUnit->timeStamp ) <= 0 ) { - IF ( !dataUnit->silenceIndicator ) + IF( !dataUnit->silenceIndicator ) { ++h->nLateLost; /* deletion of a speech frame because it arrived at the JBM too late */ @@ -590,11 +590,11 @@ Word16 JB4_PushDataUnit( return 0; } /* store data unit */ - IF ( JB4_INPUTBUFFER_Enque( h->inputBuffer, dataUnit, (void **) &droppedDataUnit ) != 0 ) + IF( JB4_INPUTBUFFER_Enque( h->inputBuffer, dataUnit, (void **) &droppedDataUnit ) != 0 ) { JB4_FreeDataUnit( h, dataUnit ); } - IF ( droppedDataUnit != NULL ) + IF( droppedDataUnit != NULL ) { JB4_FreeDataUnit( h, droppedDataUnit ); } @@ -613,7 +613,7 @@ Word16 JB4_getFECoffset( Word16 JB4_FECoffset( JB4_HANDLE h ) { - IF ( h->netLossRate < 0.05 ) + IF( h->netLossRate < 0.05 ) { return 0; } @@ -635,7 +635,7 @@ Word16 JB4_PopDataUnit( Word16 ret; assert( sysTime >= h->prevPopSysTime ); - IF ( sysTime > h->prevPopSysTime + 20 ) + IF( sysTime > h->prevPopSysTime + 20 ) { h->lastPlayoutOffset += 20; } @@ -690,17 +690,17 @@ static void JB4_targetPlayoutDelay( move32(); h->rfDelay = 0; move32(); - IF ( h->rfOffset7Active != 0 ) + IF( h->rfOffset7Active != 0 ) { h->rfDelay = 140; move32(); } - ELSE IF ( h->rfOffset5Active != 0 ) + ELSE IF( h->rfOffset5Active != 0 ) { h->rfDelay = 100; move32(); } - ELSE IF ( h->rfOffset2Active == 0 && h->rfOffset3Active == 0 ) + ELSE IF( h->rfOffset2Active == 0 && h->rfOffset3Active == 0 ) { /* keep some delay reserve for RF-off */ extraDelayReserve = 15; @@ -708,7 +708,7 @@ static void JB4_targetPlayoutDelay( } /* get estimated long term jitter */ - IF ( JB4_JMF_Jitter( h->ltJmf, <Jitter ) == 0 ) + IF( JB4_JMF_Jitter( h->ltJmf, <Jitter ) == 0 ) { /* combine long term and short term jitter to calculate target delay values */ *targetMax = h->stJitter + h->safetyMargin + h->rfDelay; @@ -730,7 +730,7 @@ static void JB4_targetPlayoutDelay( *targetStartUp = ( *targetMin + *targetMax ) / 2; } - IF ( *targetStartUp < 60 ) + IF( *targetStartUp < 60 ) { *targetStartUp = 60; move32(); @@ -752,7 +752,7 @@ static Word16 JB4_adaptPlayout( bool stretchTime; /* reset scale */ - IF ( scale == NULL || maxScaling == NULL ) + IF( scale == NULL || maxScaling == NULL ) { return -1; } @@ -763,11 +763,11 @@ static Word16 JB4_adaptPlayout( stretchTime = false; /* switch type of current playout (first one, active, DTX) */ - IF ( !h->firstDataUnitPopped ) + IF( !h->firstDataUnitPopped ) { JB4_adaptFirstPlayout( h, sysTime, &stretchTime ); } - ELSE IF ( h->lastPoppedWasSilence ) + ELSE IF( h->lastPoppedWasSilence ) { JB4_adaptDtxPlayout( h, sysTime, &stretchTime ); } @@ -777,14 +777,14 @@ static Word16 JB4_adaptPlayout( } /* time shrinking done IF needed, now do time stretching or pop data unit to play */ - IF ( stretchTime ) + IF( stretchTime ) { /* return empty data unit */ *pDataUnit = NULL; - IF ( h->firstDataUnitPopped ) + IF( h->firstDataUnitPopped ) { ++h->nUnavailablePopped; - IF ( !h->lastPoppedWasSilence ) + IF( !h->lastPoppedWasSilence ) { ++h->nStretched; /* jitter-induced insertion (e.g. buffer underflow) */ @@ -819,7 +819,7 @@ static void JB4_adaptActivePlayout( Word32 minOffTicks, tsDiffToNextDataUnit; JB4_targetPlayoutDelay( h, &targetMin, &targetMax, &targetDtx, &targetStartUp ); - IF ( JB4_JMF_MinOffset( h->ltJmf, &minOffTicks ) != 0 ) + IF( JB4_JMF_MinOffset( h->ltJmf, &minOffTicks ) != 0 ) { return; } @@ -836,11 +836,11 @@ static void JB4_adaptActivePlayout( /* calculate current playout delay */ currPlayoutDelay = h->lastPlayoutOffset - minOffTicks + extBufferedTime; - IF ( !JB4_INPUTBUFFER_IsEmpty( h->inputBuffer ) ) + IF( !JB4_INPUTBUFFER_IsEmpty( h->inputBuffer ) ) { nextDataUnit = (JB4_DATAUNIT_HANDLE) JB4_INPUTBUFFER_Front( h->inputBuffer ); tsDiffToNextDataUnit = JB4_rtpTimeStampDiff( h->nextExpectedTs, nextDataUnit->timeStamp ); - IF ( tsDiffToNextDataUnit < 0 ) + IF( tsDiffToNextDataUnit < 0 ) { convertToLateLoss = true; /* time stretching is expected -> increase playout delay to allow dropping the late frame */ @@ -850,17 +850,17 @@ static void JB4_adaptActivePlayout( } /* decided between shrinking/stretching */ - IF ( currPlayoutDelay > targetMax ) /* time shrinking */ + IF( currPlayoutDelay > targetMax ) /* time shrinking */ { gap = currPlayoutDelay - h->targetPlayoutDelay; /* check if gap is positive and dropping is allowed * and buffer contains enough time (ignoring one frame) */ - IF ( gap > 0 && - JB4_inspectBufferForDropping( h, &dropEarly, &buffered ) == 0 && - ( convertToLateLoss || - ( buffered + h->frameDuration + extBufferedTime ) > targetMax ) ) + IF( gap > 0 && + JB4_inspectBufferForDropping( h, &dropEarly, &buffered ) == 0 && + ( convertToLateLoss || + ( buffered + h->frameDuration + extBufferedTime ) > targetMax ) ) { - IF ( convertToLateLoss ) + IF( convertToLateLoss ) { #ifndef IVAS_FLOAT_FIXED JB4_dropFromBuffer( h ); @@ -869,7 +869,7 @@ static void JB4_adaptActivePlayout( h->nLostOrStretched = L_add( h->nLostOrStretched, 1 ); #endif } - ELSE IF ( dropEarly ) + ELSE IF( dropEarly ) { #ifndef IVAS_FLOAT_FIXED JB4_dropFromBuffer( h ); @@ -897,8 +897,8 @@ static void JB4_adaptActivePlayout( * Also make sure that the delay doesn't increase too much. */ delayWithClearedExternalBuffer = currPlayoutDelay - extBufferedTime + h->frameDuration; targetMaxStretch = targetMax - h->frameDuration; - IF ( delayWithClearedExternalBuffer + h->frameDuration <= targetMaxStretch && - currPlayoutDelay < targetMaxStretch && currPlayoutDelay < (UWord32) ( 110 + h->rfDelay / 4 ) ) + IF( delayWithClearedExternalBuffer + h->frameDuration <= targetMaxStretch && + currPlayoutDelay < targetMaxStretch && currPlayoutDelay < (UWord32) ( 110 + h->rfDelay / 4 ) ) { *scale = 120; move32(); @@ -923,7 +923,7 @@ static void JB4_adaptDtxPlayout( Word32 minOffTicks, tsDiffToNextDataUnit; JB4_targetPlayoutDelay( h, &targetMin, &targetMax, &targetDtx, &targetStartUp ); - IF ( JB4_JMF_MinOffset( h->ltJmf, &minOffTicks ) != 0 ) + IF( JB4_JMF_MinOffset( h->ltJmf, &minOffTicks ) != 0 ) { return; } @@ -932,7 +932,7 @@ static void JB4_adaptDtxPlayout( currPlayoutDelay = h->lastPlayoutOffset - minOffTicks; /* check for startup after DTX */ - IF ( !JB4_INPUTBUFFER_IsEmpty( h->inputBuffer ) ) + IF( !JB4_INPUTBUFFER_IsEmpty( h->inputBuffer ) ) { firstDu = (JB4_DATAUNIT_HANDLE) JB4_INPUTBUFFER_Front( h->inputBuffer ); firstTs = firstDu->timeStamp; @@ -940,17 +940,17 @@ static void JB4_adaptDtxPlayout( tsDiffToNextDataUnit = JB4_rtpTimeStampDiff( h->nextExpectedTs, firstTs ); /* check if the next available data unit should already be used (time stamp order) */ - IF ( GT_32( tsDiffToNextDataUnit, 0 ) ) + IF( GT_32( tsDiffToNextDataUnit, 0 ) ) { /* time stretching is expected -> increase playout delay */ currPlayoutDelay += tsDiffToNextDataUnit; } - IF ( !firstDu->silenceIndicator ) + IF( !firstDu->silenceIndicator ) { /* recalculate playout delay based on first buffered data unit */ JB4_playoutDelay( h, sysTime, firstTs, &currPlayoutDelay ); /* check if the next available data unit should already be used (time stamp order) */ - IF ( GT_32( tsDiffToNextDataUnit, 0 ) ) + IF( GT_32( tsDiffToNextDataUnit, 0 ) ) { /* time stretching is expected -> increase playout delay */ currPlayoutDelay += tsDiffToNextDataUnit; @@ -959,14 +959,14 @@ static void JB4_adaptDtxPlayout( move32(); headRoom = 600 * h->frameDuration / 1000; /* decided between shrinking/stretching */ - IF ( currPlayoutDelay > targetStartUp + headRoom ) /* time shrinking */ + IF( currPlayoutDelay > targetStartUp + headRoom ) /* time shrinking */ { - IF ( JB4_checkDtxDropping( h ) ) + IF( JB4_checkDtxDropping( h ) ) { JB4_dropFromBuffer( h ); } } - ELSE IF ( currPlayoutDelay + headRoom < targetStartUp ) /* time stretching */ + ELSE IF( currPlayoutDelay + headRoom < targetStartUp ) /* time stretching */ { *stretchTime = true; } @@ -978,14 +978,14 @@ static void JB4_adaptDtxPlayout( h->targetPlayoutDelay = targetDtx; /* decided between shrinking/stretching */ - IF ( currPlayoutDelay >= targetDtx + h->frameDuration ) /* time shrinking */ + IF( currPlayoutDelay >= targetDtx + h->frameDuration ) /* time shrinking */ { - IF ( JB4_checkDtxDropping( h ) ) + IF( JB4_checkDtxDropping( h ) ) { JB4_dropFromBuffer( h ); } } - ELSE IF ( currPlayoutDelay + 500 * h->frameDuration / 1000 < targetDtx ) /* time stretching */ + ELSE IF( currPlayoutDelay + 500 * h->frameDuration / 1000 < targetDtx ) /* time stretching */ { *stretchTime = true; } @@ -1003,24 +1003,24 @@ static void JB4_adaptFirstPlayout( UWord32 currPlayoutDelay; JB4_DATAUNIT_HANDLE firstDu; UWord32 targetMin, targetMax, targetDtx, targetStartUp; - IF ( JB4_INPUTBUFFER_IsEmpty( h->inputBuffer ) ) + IF( JB4_INPUTBUFFER_IsEmpty( h->inputBuffer ) ) { *prebuffer = true; return; } JB4_targetPlayoutDelay( h, &targetMin, &targetMax, &targetDtx, &targetStartUp ); - IF ( targetStartUp < h->frameDuration ) + IF( targetStartUp < h->frameDuration ) { return; } /* calculate delay if first data unit would be played now */ firstDu = (JB4_DATAUNIT_HANDLE) JB4_INPUTBUFFER_Front( h->inputBuffer ); - IF ( JB4_playoutDelay( h, sysTime, firstDu->timeStamp, &currPlayoutDelay ) != 0 ) + IF( JB4_playoutDelay( h, sysTime, firstDu->timeStamp, &currPlayoutDelay ) != 0 ) { *prebuffer = true; return; } - IF ( currPlayoutDelay + h->frameDuration / 2 < targetStartUp ) /* time stretching */ + IF( currPlayoutDelay + h->frameDuration / 2 < targetStartUp ) /* time stretching */ { *prebuffer = true; } @@ -1051,7 +1051,7 @@ static Word16 JB4_inspectBufferForDropping( *buffered = 0; move16(); inputBufferSize = JB4_INPUTBUFFER_Size( h->inputBuffer ); - IF ( inputBufferSize == 0U ) + IF( inputBufferSize == 0U ) { return -1; } @@ -1059,7 +1059,7 @@ static Word16 JB4_inspectBufferForDropping( firstDu = (JB4_DATAUNIT_HANDLE) JB4_INPUTBUFFER_Front( h->inputBuffer ); firstTs = firstDu->timeStamp; /* check for loss: sequence number diff is exactly 0 in the valid case */ - IF ( h->firstDataUnitPopped ) + IF( h->firstDataUnitPopped ) { seqNrDiff = JB4_rtpTimeStampDiff( h->nextExpectedTs, firstTs ) / (Word32) ( h->frameDuration ); @@ -1069,16 +1069,16 @@ static Word16 JB4_inspectBufferForDropping( seqNrDiff = 0; move32(); } - IF ( LE_32( seqNrDiff, 0 ) ) + IF( LE_32( seqNrDiff, 0 ) ) { /* preview data unit to play after dropping */ - IF ( inputBufferSize <= 1U ) + IF( inputBufferSize <= 1U ) { /* data unit to play missing, avoid drop followed by concealment */ return -1; } secondDu = JB4_INPUTBUFFER_Element( h->inputBuffer, 1 ); - IF ( firstTs + h->frameDuration != secondDu->timeStamp ) + IF( firstTs + h->frameDuration != secondDu->timeStamp ) { /* data unit to play is not available, avoid drop followed by concealment */ return -1; @@ -1087,7 +1087,7 @@ static Word16 JB4_inspectBufferForDropping( bufferedTs = 0; move32(); } - ELSE IF ( EQ_32( seqNrDiff, 2 ) ) + ELSE IF( EQ_32( seqNrDiff, 2 ) ) { /* data unit to play is not available, avoid dropping followed by concealment */ return -1; @@ -1104,7 +1104,7 @@ static Word16 JB4_inspectBufferForDropping( } /* add time stamp difference of last and first actually buffered data unit */ - IF ( inputBufferSize == 1U ) + IF( inputBufferSize == 1U ) { bufferedTs += h->frameDuration; } @@ -1114,7 +1114,7 @@ static Word16 JB4_inspectBufferForDropping( beginTs = firstTs; endTs = lastDu->timeStamp + h->frameDuration; /* check for RTP time stamp wrap around */ - IF ( endTs < beginTs ) + IF( endTs < beginTs ) { endTs = endTs + 0xFFFFFFFF; } @@ -1122,7 +1122,7 @@ static Word16 JB4_inspectBufferForDropping( } /* the result should not be negative */ - IF ( LT_32( bufferedTs, 0 ) ) + IF( LT_32( bufferedTs, 0 ) ) { return -1; } @@ -1148,13 +1148,13 @@ static Word16 JB4_checkDtxDropping( droppingAllowed = 1; move16(); inputBufferSize = JB4_INPUTBUFFER_Size( h->inputBuffer ); - IF ( inputBufferSize > 0U ) + IF( inputBufferSize > 0U ) { firstDu = (JB4_DATAUNIT_HANDLE) JB4_INPUTBUFFER_Front( h->inputBuffer ); /* check for loss: sequence number diff is exactly 0 in the valid case */ seqNrDiff = JB4_rtpTimeStampDiff( h->nextExpectedTs, firstDu->timeStamp ) / (Word32) ( h->frameDuration ); - IF ( LE_32( seqNrDiff, 0 ) ) + IF( LE_32( seqNrDiff, 0 ) ) { /* no not drop first active frame */ droppingAllowed = 0; @@ -1180,7 +1180,7 @@ static void JB4_estimateShortTermJitter( jitter = 0; JB4_JMF_PushPacket( h->stJmf, rcvTime, rtpTimeStamp ); /* save delta delay */ - IF ( EQ_16( JB4_JMF_Jitter( h->stJmf, &jitter ), 0 ) ) + IF( EQ_16( JB4_JMF_Jitter( h->stJmf, &jitter ), 0 ) ) { /* compensate difference between both offsets */ Word32 stOffset, ltOffset; @@ -1188,7 +1188,7 @@ static void JB4_estimateShortTermJitter( JB4_JMF_MinOffset( h->ltJmf, <Offset ); jitter += stOffset - ltOffset; assert( (Word16) jitter >= 0 ); - IF ( JB4_CIRCULARBUFFER_IsFull( h->stJitterFifo ) ) + IF( JB4_CIRCULARBUFFER_IsFull( h->stJitterFifo ) ) { JB4_CIRCULARBUFFER_Deque( h->stJitterFifo, &dequedElement ); JB4_CIRCULARBUFFER_Deque( h->stTimeStampFifo, &dequedElement ); @@ -1199,16 +1199,16 @@ static void JB4_estimateShortTermJitter( /* check for duration and discard first entries if too long */ minTime = JB4_CIRCULARBUFFER_Front( h->stTimeStampFifo ); maxTime = JB4_CIRCULARBUFFER_Back( h->stTimeStampFifo ); - IF ( maxTime > minTime ) + IF( maxTime > minTime ) { duration = maxTime - minTime; maxDuration = 4 * h->timeScale; - WHILE ( duration > maxDuration ) + WHILE( duration > maxDuration ) { JB4_CIRCULARBUFFER_Deque( h->stJitterFifo, &dequedElement ); JB4_CIRCULARBUFFER_Deque( h->stTimeStampFifo, &dequedElement ); minTime = JB4_CIRCULARBUFFER_Front( h->stTimeStampFifo ); - IF ( LE_32( maxTime, minTime ) ) + IF( LE_32( maxTime, minTime ) ) { BREAK; } @@ -1218,7 +1218,7 @@ static void JB4_estimateShortTermJitter( } /* update h->stJitter */ - IF ( !JB4_CIRCULARBUFFER_IsEmpty( h->stJitterFifo ) ) + IF( !JB4_CIRCULARBUFFER_IsEmpty( h->stJitterFifo ) ) { JB4_CIRCULARBUFFER_Max( h->stJitterFifo, &maxElement ); /* round up to full frame duration */ @@ -1249,12 +1249,12 @@ static void JB4_popFromBuffer( UWord16 searchpos, endpos; /* check if a data unit is available */ - IF ( JB4_INPUTBUFFER_IsEmpty( h->inputBuffer ) ) + IF( JB4_INPUTBUFFER_IsEmpty( h->inputBuffer ) ) { /* no data unit available */ *pDataUnit = NULL; h->nextExpectedTs += h->frameDuration; - IF ( h->lastPoppedWasSilence ) + IF( h->lastPoppedWasSilence ) { ++h->nComfortNoice; } @@ -1271,7 +1271,7 @@ static void JB4_popFromBuffer( nextDataUnit = (JB4_DATAUNIT_HANDLE) JB4_INPUTBUFFER_Front( h->inputBuffer ); /* check if this is the first data unit */ - IF ( !h->firstDataUnitPopped ) + IF( !h->firstDataUnitPopped ) { h->firstDataUnitPopped = true; /* adjust sequence numbers to avoid handling first packet as loss */ @@ -1283,15 +1283,15 @@ static void JB4_popFromBuffer( tsDiff = JB4_rtpTimeStampDiff( nextDataUnit->timeStamp, h->nextExpectedTs ); h->totWin += 1; - IF ( ( h->totWin > 3000 ) || ( h->FecOffWinLen > 100 ) ) + IF( ( h->totWin > 3000 ) || ( h->FecOffWinLen > 100 ) ) { maxval = h->FecOffWin[1]; move16(); h->optimum_offset = 1; move16(); - FOR ( i = 2; i < MAXOFFSET; i++ ) + FOR( i = 2; i < MAXOFFSET; i++ ) { - IF ( h->FecOffWin[i] > maxval ) + IF( h->FecOffWin[i] > maxval ) { maxval = h->FecOffWin[i]; move16(); @@ -1314,7 +1314,7 @@ static void JB4_popFromBuffer( lost = h->nLost + h->nPartialCopiesUsed - h->last_nLost; total_rec = h->nAvailablePopped + h->nUnavailablePopped - h->last_ntot; - IF ( lost != 0 && total_rec != 0 ) + IF( lost != 0 && total_rec != 0 ) { h->netLossRate_fx = (Word32) ( lost / (float) total_rec ); h->netLossRate = (float) lost / (float) total_rec; @@ -1328,17 +1328,17 @@ static void JB4_popFromBuffer( h->last_ntot = L_add( h->nAvailablePopped, h->nUnavailablePopped ); } - IF ( LT_32( tsDiff, 0 ) ) + IF( LT_32( tsDiff, 0 ) ) { readlen = JB4_INPUTBUFFER_Size( h->inputBuffer ); - FOR ( i = 0; i < readlen; i++ ) + FOR( i = 0; i < readlen; i++ ) { tempDataUnit = (JB4_DATAUNIT_HANDLE) JB4_INPUTBUFFER_Element( h->inputBuffer, i ); - IF ( !tempDataUnit->partial_frame && !h->lastPoppedWasSilence ) + IF( !tempDataUnit->partial_frame && !h->lastPoppedWasSilence ) { frameoffset = (Word16) ( JB4_rtpTimeStampDiff( h->nextExpectedTs, tempDataUnit->timeStamp ) / 20 ); - IF ( GT_16( frameoffset, 0 ) && LT_16( frameoffset, MAXOFFSET ) ) + IF( GT_16( frameoffset, 0 ) && LT_16( frameoffset, MAXOFFSET ) ) { h->FecOffWin[frameoffset] += 1; } @@ -1352,7 +1352,7 @@ static void JB4_popFromBuffer( /* update statistics */ h->nextExpectedTs += h->frameDuration; - IF ( h->lastPoppedWasSilence ) + IF( h->lastPoppedWasSilence ) { ++h->nComfortNoice; } @@ -1367,22 +1367,22 @@ static void JB4_popFromBuffer( /* fetch the next data unit from buffer */ *pDataUnit = nextDataUnit; nextDataUnit->nextCoderType = INACTIVE; - IF ( h->pre_partial_frame || nextDataUnit->partial_frame ) + IF( h->pre_partial_frame || nextDataUnit->partial_frame ) { - IF ( nextDataUnit->partial_frame ) + IF( nextDataUnit->partial_frame ) { h->pre_partial_frame = 1; } - ELSE IF ( h->pre_partial_frame ) + ELSE IF( h->pre_partial_frame ) { h->pre_partial_frame = 0; } endpos = JB4_INPUTBUFFER_Size( h->inputBuffer ); - FOR ( searchpos = 0; searchpos < endpos; searchpos++ ) + FOR( searchpos = 0; searchpos < endpos; searchpos++ ) { partialCopyDu = (JB4_DATAUNIT_HANDLE) JB4_INPUTBUFFER_Element( h->inputBuffer, searchpos ); - IF ( partialCopyDu->timeStamp == nextDataUnit->timeStamp + partialCopyDu->duration ) + IF( partialCopyDu->timeStamp == nextDataUnit->timeStamp + partialCopyDu->duration ) { get_NextCoderType( partialCopyDu->data, &nextDataUnit->nextCoderType ); BREAK; @@ -1391,19 +1391,19 @@ static void JB4_popFromBuffer( } JB4_INPUTBUFFER_Deque( h->inputBuffer, (void **) pDataUnit ); - IF ( nextDataUnit->partial_frame ) + IF( nextDataUnit->partial_frame ) { h->nPartialCopiesUsed += 1; readlen = JB4_INPUTBUFFER_Size( h->inputBuffer ); - FOR ( i = 0; i < readlen; i++ ) + FOR( i = 0; i < readlen; i++ ) { tempDataUnit = (JB4_DATAUNIT_HANDLE) JB4_INPUTBUFFER_Element( h->inputBuffer, i ); - IF ( !tempDataUnit->partial_frame && !h->lastPoppedWasSilence ) + IF( !tempDataUnit->partial_frame && !h->lastPoppedWasSilence ) { frameoffset = (Word16) ( JB4_rtpTimeStampDiff( h->nextExpectedTs, tempDataUnit->timeStamp ) / 20 ); - IF ( frameoffset > 0 && frameoffset < MAXOFFSET ) + IF( frameoffset > 0 && frameoffset < MAXOFFSET ) { h->FecOffWin[frameoffset] += 1; } @@ -1413,7 +1413,7 @@ static void JB4_popFromBuffer( } /* update statistics */ - IF ( h->nLostOrStretched != 0U ) + IF( h->nLostOrStretched != 0U ) { assert( h->lastPoppedWasSilence == false ); /* separate concealments since last available pop in lost and stretched */ @@ -1428,7 +1428,7 @@ static void JB4_popFromBuffer( h->lastReturnedTs = nextDataUnit->timeStamp; JB4_updateLastTimingMembers( h, sysTime, nextDataUnit->timeStamp ); h->nextExpectedTs = nextDataUnit->timeStamp + h->frameDuration; - IF ( nextDataUnit->silenceIndicator ) + IF( nextDataUnit->silenceIndicator ) { h->lastPoppedWasSilence = true; ++h->nComfortNoice; @@ -1451,7 +1451,7 @@ static void JB4_dropFromBuffer( UWord32 nStretched; /* check if a data unit is available */ - IF ( JB4_INPUTBUFFER_IsEmpty( h->inputBuffer ) ) + IF( JB4_INPUTBUFFER_IsEmpty( h->inputBuffer ) ) { return; } @@ -1459,7 +1459,7 @@ static void JB4_dropFromBuffer( nextDataUnit = (JB4_DATAUNIT_HANDLE) JB4_INPUTBUFFER_Front( h->inputBuffer ); /* check if this is the first data unit */ - IF ( !h->firstDataUnitPopped ) + IF( !h->firstDataUnitPopped ) { h->firstDataUnitPopped = true; /* adjust sequence numbers to avoid handling first packet as loss */ @@ -1469,21 +1469,21 @@ static void JB4_dropFromBuffer( /* check if the next available data unit should already be used (time stamp order) */ tsDiff = JB4_rtpTimeStampDiff( nextDataUnit->timeStamp, h->nextExpectedTs ); - IF ( LT_32( tsDiff, 0 ) ) + IF( LT_32( tsDiff, 0 ) ) { /* next expected data unit is missing, remember this data unit as popped, * but do not count it as lost, because it will not be concealed */ h->nextExpectedTs += h->frameDuration; /* substract one frame from last playout delay */ h->lastPlayoutOffset -= h->frameDuration; - IF ( !h->lastPoppedWasSilence ) + IF( !h->lastPoppedWasSilence ) { ++h->nShrinked; /* modification of the output timeline due to link loss */ ++h->nUnavailablePopped; ++h->nLostOrStretched; } - IF ( h->lastTargetTime != 0U ) + IF( h->lastTargetTime != 0U ) { h->lastTargetTime += h->frameDuration; } @@ -1493,7 +1493,7 @@ static void JB4_dropFromBuffer( /* fetch the next data unit from buffer */ JB4_INPUTBUFFER_Deque( h->inputBuffer, (void *) &dataUnit ); /* update statistics */ - IF ( h->nLostOrStretched != 0U ) + IF( h->nLostOrStretched != 0U ) { assert( h->lastPoppedWasSilence == false ); /* separate concealments since last available pop in lost and stretched */ @@ -1501,14 +1501,14 @@ static void JB4_dropFromBuffer( assert( h->nLostOrStretched >= nStretched ); /* convert stretching followed by shrinking to late-loss */ - IF ( nStretched > 0U ) + IF( nStretched > 0U ) { --nStretched; ++h->nLateLost; h->nLost += h->nLostOrStretched - nStretched; /* jitter-induced insertion (e.g. buffer underflow) */ h->jitterInducedConcealments += nStretched; - IF ( !dataUnit->silenceIndicator ) + IF( !dataUnit->silenceIndicator ) { /* JBM induced removal of a speech frame (intentional frame dropping) */ ++h->jitterInducedConcealments; @@ -1519,7 +1519,7 @@ static void JB4_dropFromBuffer( { h->nLost += h->nLostOrStretched; ++h->nShrinked; - IF ( !dataUnit->silenceIndicator ) + IF( !dataUnit->silenceIndicator ) { /* JBM induced removal of a speech frame (intentional frame dropping) */ ++h->jitterInducedConcealments; @@ -1530,7 +1530,7 @@ static void JB4_dropFromBuffer( } ELSE { - IF ( !dataUnit->silenceIndicator ) + IF( !dataUnit->silenceIndicator ) { ++h->nShrinked; /* JBM induced removal of a speech frame (intentional frame dropping) */ @@ -1546,8 +1546,8 @@ static void JB4_dropFromBuffer( /* substract one frame from last playout delay */ h->lastPlayoutOffset -= h->frameDuration; - IF ( h->lastTargetTime != 0U ) - h->lastTargetTime += h->frameDuration; + IF( h->lastTargetTime != 0U ) + h->lastTargetTime += h->frameDuration; JB4_FreeDataUnit( h, dataUnit ); @@ -1564,7 +1564,7 @@ static Word16 JB4_playoutDelay( { Word32 minOffTicks; - IF ( NE_16( JB4_JMF_MinOffset( h->ltJmf, &minOffTicks ), 0 ) ) + IF( NE_16( JB4_JMF_MinOffset( h->ltJmf, &minOffTicks ), 0 ) ) { return -1; } @@ -1583,7 +1583,7 @@ static void JB4_updateLastTimingMembers( { Word32 minOffTicks; - IF ( JB4_JMF_MinOffset( h->ltJmf, &minOffTicks ) != 0 ) + IF( JB4_JMF_MinOffset( h->ltJmf, &minOffTicks ) != 0 ) { return; } @@ -1611,12 +1611,12 @@ static Word16 JB4_inputBufferCompareFunction( newDataUnit = (JB4_DATAUNIT_HANDLE) newElement; arrayDataUnit = (JB4_DATAUNIT_HANDLE) arrayElement; diff = JB4_rtpTimeStampDiff( arrayDataUnit->timeStamp, newDataUnit->timeStamp ); - IF ( diff > 0 ) + IF( diff > 0 ) { result = 1; move16(); } - ELSE IF ( LT_32( diff, 0 ) ) + ELSE IF( LT_32( diff, 0 ) ) { result = -1; move16(); @@ -1625,12 +1625,12 @@ static Word16 JB4_inputBufferCompareFunction( { result = 0; move16(); - IF ( newDataUnit->partial_frame == 0 && arrayDataUnit->partial_frame == 1 ) + IF( newDataUnit->partial_frame == 0 && arrayDataUnit->partial_frame == 1 ) { /* replace partial copy with primary copy */ *replaceWithNewElementIfEqual = 1; } - ELSE IF ( newDataUnit->partial_frame == arrayDataUnit->partial_frame && newDataUnit->dataSize > arrayDataUnit->dataSize ) + ELSE IF( newDataUnit->partial_frame == arrayDataUnit->partial_frame && newDataUnit->dataSize > arrayDataUnit->dataSize ) { /* if both are primary or partial: take the one with higher size (e.g. higher bitrate) */ *replaceWithNewElementIfEqual = 1; diff --git a/lib_dec/jbm_pcmdsp_apa.c b/lib_dec/jbm_pcmdsp_apa.c index f91c4c310..e2596d3f6 100644 --- a/lib_dec/jbm_pcmdsp_apa.c +++ b/lib_dec/jbm_pcmdsp_apa.c @@ -70,7 +70,7 @@ struct apa_state_t { Word16 signalScaleForCorrelation; - Word16 frmInScaled[6 * 2 * 48000 / 50 * 2 ]; + Word16 frmInScaled[6 * 2 * 48000 / 50 * 2]; /* output buffer */ bool evs_compat_mode; @@ -83,7 +83,7 @@ struct apa_state_t /* Hann window */ float win[APA_BUF_PER_CHANNEL]; const Word16 *win_fx; - //const Word16 *win_fx; + // const Word16 *win_fx; UWord16 l_halfwin; Word16 win_incrementor; @@ -136,7 +136,6 @@ struct apa_state_t }; - /*---------------------------------------------------------------------* * Local function prototypes *---------------------------------------------------------------------*/ @@ -144,8 +143,8 @@ struct apa_state_t #ifndef IVAS_FLOAT_FIXED static float apa_corrEnergy2dB( float energy, uint16_t corr_len ); #endif -Word16 apa_corrEnergy2dB_fx(Word32 energy, Word16 energyExp, Word16 corr_len); -Word16 apa_getQualityIncreaseForLowEnergy_fx(Word16 energydB); +Word16 apa_corrEnergy2dB_fx( Word32 energy, Word16 energyExp, Word16 corr_len ); +Word16 apa_getQualityIncreaseForLowEnergy_fx( Word16 energydB ); #ifndef IVAS_FLOAT_FIXED static float apa_getQualityIncreaseForLowEnergy( float energydB ); @@ -153,15 +152,15 @@ static float apa_getQualityIncreaseForLowEnergy( float energydB ); #ifdef IVAS_FLOAT_FIXED static Word8 logarithmic_search_fx( const apa_state_t *ps, - const Word16 *signal, - Word16 s_start, - Word16 inlen, - Word16 offset, - Word16 fixed_pos, - Word16 corr_len, - Word16 wss, - Word16 css, - Word16 *synchpos ); + const Word16 *signal, + Word16 s_start, + Word16 inlen, + Word16 offset, + Word16 fixed_pos, + Word16 corr_len, + Word16 wss, + Word16 css, + Word16 *synchpos ); #else static bool logarithmic_search( const apa_state_t *ps, const float *signal, int16_t s_start, uint16_t inlen, uint16_t offset, uint16_t fixed_pos, uint16_t corr_len, uint16_t wss, uint16_t css, int16_t *synchpos ); @@ -179,16 +178,16 @@ static bool extend_frm( apa_state_t *ps, const float frm_in[], float frm_out[], #ifdef IVAS_FLOAT_FIXED static Word16 find_synch_fx( apa_state_t *ps, - const Word16 *in, - Word16 l_in, - Word16 s_start, - Word16 s_len, - Word16 fixed_pos, - Word16 corr_len, - Word16 offset, - Word16 *energydBQ8, - Word32 *qualityQ16, - Word16 *synch_pos ); + const Word16 *in, + Word16 l_in, + Word16 s_start, + Word16 s_len, + Word16 fixed_pos, + Word16 corr_len, + Word16 offset, + Word16 *energydBQ8, + Word32 *qualityQ16, + Word16 *synch_pos ); #endif // IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* @@ -204,13 +203,13 @@ ivas_error apa_init( apa_state_t *ps = NULL; /* make sure pointer is valid */ - IF ( !pps ) + IF( !pps ) { return 1; } /* allocate state struct */ - IF ( ( ps = (apa_state_t *) malloc( sizeof( apa_state_t ) ) ) == NULL ) + IF( ( ps = (apa_state_t *) malloc( sizeof( apa_state_t ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for JBM\n" ) ); } @@ -220,13 +219,13 @@ ivas_error apa_init( ps->buf_out_capacity = (UWord16) ( APA_BUF_PER_CHANNEL * num_channels ); #ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED - IF ( ( ps->buf_out = malloc( sizeof( float ) * ps->buf_out_capacity ) ) == NULL ) + IF( ( ps->buf_out = malloc( sizeof( float ) * ps->buf_out_capacity ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for JBM\n" ) ); } #endif - IF ( ( ps->buf_out_fx = malloc( sizeof( Word16 ) * ps->buf_out_capacity ) ) == NULL ) + IF( ( ps->buf_out_fx = malloc( sizeof( Word16 ) * ps->buf_out_capacity ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for JBM\n" ) ); } @@ -378,15 +377,15 @@ uint8_t apa_reconfigure( #ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED free( ps->buf_out ); ps->buf_out = (float *) malloc( sizeof( float ) * ps->buf_out_capacity ); - IF ( !ps->buf_out ) + IF( !ps->buf_out ) { return 2; } #endif free( ps->buf_out_fx ); - ps->buf_out_fx = (Word16 *)malloc(sizeof(float) * ps->buf_out_capacity); - IF ( !ps->buf_out_fx ) + ps->buf_out_fx = (Word16 *) malloc( sizeof( float ) * ps->buf_out_capacity ); + IF( !ps->buf_out_fx ) { return 2; } @@ -551,7 +550,7 @@ bool apa_set_rate( move16(); } /* sample rates 8k, 16k & 32k use a Hann window of length of 640, - * where 8k and 16k subsample */ + * where 8k and 16k subsample */ if ( EQ_32( ps->rate, 16000 ) ) ps->win_incrementor = 2; move16(); @@ -563,7 +562,7 @@ bool apa_set_rate( /* set to 40 samples at 16 kHz */ /* (defines min change in number of samples, i.e., abs(l_in-l_out) >= p_min) */ /* before basop port was originally: ps->p_min = (ps->rate * ps->num_channels) / 400; - * but for simplicity can be taken as l_seg / 4 */ + * but for simplicity can be taken as l_seg / 4 */ ps->signalScaleForCorrelation = getSignalScaleForCorrelation( ps->rate ); #endif return 0; @@ -577,20 +576,20 @@ bool apa_set_scale( UWord16 scale ) { /* make sure pointer is valid */ - IF ( ps == NULL ) + IF( ps == NULL ) { return 1; } /* check range */ - IF ( ( LT_32( (Word32) scale, APA_MIN_SCALE ) ) || GT_32( (Word32) scale, APA_MAX_SCALE ) ) + IF( ( LT_32( (Word32) scale, APA_MIN_SCALE ) ) || GT_32( (Word32) scale, APA_MAX_SCALE ) ) { return 1; } /* do nothing if same scale is set multiple times */ /* (otherwise scale control is confused) */ - IF ( EQ_32( (Word32 ) ps->scale, ( Word32 ) scale ) ) + IF( EQ_32( (Word32) ps->scale, (Word32) scale ) ) { return 0; } @@ -648,7 +647,7 @@ bool apa_set_renderer_granularity( UWord16 l_ts ) { /* make sure pointer is valid */ - IF ( ps == NULL ) + IF( ps == NULL ) { return 1; } @@ -682,7 +681,7 @@ bool apa_set_renderer_residual_samples( UWord16 l_r_buf ) { /* make sure pointer is valid */ - IF ( ps == NULL ) + IF( ps == NULL ) { return 1; } @@ -716,7 +715,7 @@ bool apa_set_evs_compat_mode( bool mode ) { /* make sure pointer is valid */ - IF ( ps == NULL ) + IF( ps == NULL ) { return 1; } @@ -808,17 +807,17 @@ bool apa_set_complexity_options( UWord16 css ) { /* make sure pointer is valid */ - IF ( ps == NULL ) + IF( ps == NULL ) { return 1; } - IF ( wss == 0 || wss > 1000 ) + IF( wss == 0 || wss > 1000 ) { return 1; } - IF ( css == 0 || css > 1000 ) + IF( css == 0 || css > 1000 ) { return 1; } @@ -1252,17 +1251,17 @@ static void get_scaling_quality( #else -static void get_scaling_quality_fx(const apa_state_t * ps, - const Word16 * signal, - Word16 s_len, - Word16 offset, - Word16 corr_len, - Word16 pitch, - Word16 * energydBQ8, - Word32 * qualityQ16) +static void get_scaling_quality_fx( const apa_state_t *ps, + const Word16 *signal, + Word16 s_len, + Word16 offset, + Word16 corr_len, + Word16 pitch, + Word16 *energydBQ8, + Word32 *qualityQ16 ) { Word32 energy, maxEnergy; - Word32 qualityOfMaxEnergy; /* we measure the quality for all channels and select the one with highest energy */ + Word32 qualityOfMaxEnergy; /* we measure the quality for all channels and select the one with highest energy */ Word16 half_pitch_cn; Word16 pitch_cn; Word16 three_halves_pitch_cn; @@ -1274,73 +1273,73 @@ static void get_scaling_quality_fx(const apa_state_t * ps, Word16 i; - maxEnergy = L_deposit_l(0); - qualityOfMaxEnergy = L_deposit_l(0); + maxEnergy = L_deposit_l( 0 ); + qualityOfMaxEnergy = L_deposit_l( 0 ); - FOR(i = 0; i < ps->num_channels; i++) + FOR( i = 0; i < ps->num_channels; i++ ) { offset = 0; move16(); - pitch_cn = normalized_cross_correlation_self_fx(signal, add(pitch, offset), offset, corr_len, - shl(ps->num_channels, 1), &pitch_energy); - IF(pitch_cn > 0) + pitch_cn = normalized_cross_correlation_self_fx( signal, add( pitch, offset ), offset, corr_len, + shl( ps->num_channels, 1 ), &pitch_energy ); + IF( pitch_cn > 0 ) { /* calculate correlation for double pitch */ - IF(LE_16(add(add(shl(pitch, 1), offset), corr_len), s_len)) + IF( LE_16( add( add( shl( pitch, 1 ), offset ), corr_len ), s_len ) ) { - double_pitch_cn = normalized_cross_correlation_self_fx(signal, add(shl(pitch, 1), offset), - offset, corr_len, shl(ps->num_channels, 1), &double_pitch_energy); + double_pitch_cn = normalized_cross_correlation_self_fx( signal, add( shl( pitch, 1 ), offset ), + offset, corr_len, shl( ps->num_channels, 1 ), &double_pitch_energy ); } ELSE { double_pitch_cn = pitch_cn; move16(); - double_pitch_energy = L_add(pitch_energy, 0); + double_pitch_energy = L_add( pitch_energy, 0 ); } - /* calculate correlation for three/half pitch */ - IF(LE_16(add(add(shr(i_mult2(pitch, 3), 1), offset), corr_len), s_len)) + /* calculate correlation for three/half pitch */ + IF( LE_16( add( add( shr( i_mult2( pitch, 3 ), 1 ), offset ), corr_len ), s_len ) ) { - three_halves_pitch_cn = normalized_cross_correlation_self_fx(signal, add(shr(i_mult2(pitch, 3), 1), - offset), offset, corr_len, shl(ps->num_channels, 1), &three_halves_pitch_energy); + three_halves_pitch_cn = normalized_cross_correlation_self_fx( signal, add( shr( i_mult2( pitch, 3 ), 1 ), offset ), offset, corr_len, shl( ps->num_channels, 1 ), &three_halves_pitch_energy ); } ELSE { three_halves_pitch_cn = pitch_cn; move16(); - three_halves_pitch_energy = L_add(pitch_energy, 0); + three_halves_pitch_energy = L_add( pitch_energy, 0 ); } - /* calculate correlation for half pitch */ - IF(LE_16(add(add(shr(pitch, 1), offset), corr_len), s_len)) + /* calculate correlation for half pitch */ + IF( LE_16( add( add( shr( pitch, 1 ), offset ), corr_len ), s_len ) ) { - half_pitch_cn = normalized_cross_correlation_self_fx(signal, add(shr(pitch, 1), offset), - offset, corr_len, shl(ps->num_channels, 1), &half_pitch_energy); + half_pitch_cn = normalized_cross_correlation_self_fx( signal, add( shr( pitch, 1 ), offset ), + offset, corr_len, shl( ps->num_channels, 1 ), &half_pitch_energy ); } ELSE { half_pitch_cn = pitch_cn; move16(); - half_pitch_energy = L_add(pitch_energy, 0); + half_pitch_energy = L_add( pitch_energy, 0 ); } - /* combine correlation results: Q15.16 */ - *qualityQ16 = L_shr(L_mac0(L_mult0(half_pitch_cn, three_halves_pitch_cn), - pitch_cn, double_pitch_cn), 14); + /* combine correlation results: Q15.16 */ + *qualityQ16 = L_shr( L_mac0( L_mult0( half_pitch_cn, three_halves_pitch_cn ), + pitch_cn, double_pitch_cn ), + 14 ); BASOP_SATURATE_WARNING_OFF_EVS - energy = L_add(L_add(L_add(pitch_energy, half_pitch_energy), three_halves_pitch_energy), double_pitch_energy); + energy = L_add( L_add( L_add( pitch_energy, half_pitch_energy ), three_halves_pitch_energy ), double_pitch_energy ); BASOP_SATURATE_WARNING_ON_EVS } ELSE { - *qualityQ16 = L_shl(L_deposit_l(pitch_cn), 1); /* value is negative, thus pass it */ - energy = L_add(pitch_energy, 0); + *qualityQ16 = L_shl( L_deposit_l( pitch_cn ), 1 ); /* value is negative, thus pass it */ + energy = L_add( pitch_energy, 0 ); } - /* update the quality by the quality of the signal with the highest energy */ - IF(GT_32(energy, maxEnergy)) + /* update the quality by the quality of the signal with the highest energy */ + IF( GT_32( energy, maxEnergy ) ) { - qualityOfMaxEnergy = L_add(*qualityQ16, 0); - maxEnergy = L_add(energy, 0); + qualityOfMaxEnergy = L_add( *qualityQ16, 0 ); + maxEnergy = L_add( energy, 0 ); } /* go to next channel */ @@ -1350,26 +1349,26 @@ static void get_scaling_quality_fx(const apa_state_t * ps, move32(); /* increase calculated quality of signals with low energy */ - *energydBQ8 = apa_corrEnergy2dB_fx(maxEnergy, shl(ps->signalScaleForCorrelation, 1), corr_len); - *qualityQ16 = L_add(*qualityQ16, L_shl(L_deposit_l(apa_getQualityIncreaseForLowEnergy_fx(*energydBQ8)), 8)); + *energydBQ8 = apa_corrEnergy2dB_fx( maxEnergy, shl( ps->signalScaleForCorrelation, 1 ), corr_len ); + *qualityQ16 = L_add( *qualityQ16, L_shl( L_deposit_l( apa_getQualityIncreaseForLowEnergy_fx( *energydBQ8 ) ), 8 ) ); } #endif -Word16 apa_corrEnergy2dB_fx(Word32 energy, Word16 energyExp, Word16 corr_len) +Word16 apa_corrEnergy2dB_fx( Word32 energy, Word16 energyExp, Word16 corr_len ) { Word16 result, tmpScale; /* normalise before dividing */ - tmpScale = norm_l(energy); - energy = L_shl(energy, tmpScale); - energyExp = sub(energyExp, tmpScale); + tmpScale = norm_l( energy ); + energy = L_shl( energy, tmpScale ); + energyExp = sub( energyExp, tmpScale ); /* divide energy by corr_len */ - result = BASOP_Util_Divide3216_Scale(energy, corr_len, &tmpScale); - energyExp = add(energyExp, tmpScale); + result = BASOP_Util_Divide3216_Scale( energy, corr_len, &tmpScale ); + energyExp = add( energyExp, tmpScale ); - result = BASOP_Util_lin2dB(L_deposit_l(result), energyExp, 1); + result = BASOP_Util_lin2dB( L_deposit_l( result ), energyExp, 1 ); return result; } @@ -1415,43 +1414,43 @@ static float apa_getQualityIncreaseForLowEnergy( } #endif -Word16 apa_getQualityIncreaseForLowEnergy_fx(Word16 energydBQ8) +Word16 apa_getQualityIncreaseForLowEnergy_fx( Word16 energydBQ8 ) { - Word16 qualIncreaseMinEnergy, qualIncreaseMaxEnergy, qualIncForLowEnergy; /* Q8 */ - - qualIncreaseMinEnergy = -65 * (1 << 8); - move16(); - qualIncreaseMaxEnergy = -40 * (1 << 8); - move16(); - qualIncForLowEnergy = 0; - move16(); - - /* increase calculated quality of signals with low energy */ - IF(LT_16(energydBQ8, qualIncreaseMaxEnergy)) - { - qualIncForLowEnergy = energydBQ8; - move16(); - if (LT_16(qualIncForLowEnergy, qualIncreaseMinEnergy)) - { - qualIncForLowEnergy = qualIncreaseMinEnergy; - move16(); - } - if (GT_16(qualIncForLowEnergy, qualIncreaseMaxEnergy)) - { - qualIncForLowEnergy = qualIncreaseMaxEnergy; - move16(); - } - /* -50: (-50 - -40) / (-65 - -40) * 20 - * = -10 / -25 * 20 - */ - qualIncForLowEnergy = divide1616(sub(qualIncForLowEnergy, qualIncreaseMaxEnergy), - sub(qualIncreaseMinEnergy, qualIncreaseMaxEnergy)); - /* apply factor 2 and scale back to Q8 */ - assert(qualIncForLowEnergy >= 0); - qualIncForLowEnergy = shr(qualIncForLowEnergy, 7 - 1); - assert(qualIncForLowEnergy >= 0 && qualIncForLowEnergy <= (2 << 8)); - } - return qualIncForLowEnergy; + Word16 qualIncreaseMinEnergy, qualIncreaseMaxEnergy, qualIncForLowEnergy; /* Q8 */ + + qualIncreaseMinEnergy = -65 * ( 1 << 8 ); + move16(); + qualIncreaseMaxEnergy = -40 * ( 1 << 8 ); + move16(); + qualIncForLowEnergy = 0; + move16(); + + /* increase calculated quality of signals with low energy */ + IF( LT_16( energydBQ8, qualIncreaseMaxEnergy ) ) + { + qualIncForLowEnergy = energydBQ8; + move16(); + if ( LT_16( qualIncForLowEnergy, qualIncreaseMinEnergy ) ) + { + qualIncForLowEnergy = qualIncreaseMinEnergy; + move16(); + } + if ( GT_16( qualIncForLowEnergy, qualIncreaseMaxEnergy ) ) + { + qualIncForLowEnergy = qualIncreaseMaxEnergy; + move16(); + } + /* -50: (-50 - -40) / (-65 - -40) * 20 + * = -10 / -25 * 20 + */ + qualIncForLowEnergy = divide1616( sub( qualIncForLowEnergy, qualIncreaseMaxEnergy ), + sub( qualIncreaseMinEnergy, qualIncreaseMaxEnergy ) ); + /* apply factor 2 and scale back to Q8 */ + assert( qualIncForLowEnergy >= 0 ); + qualIncForLowEnergy = shr( qualIncForLowEnergy, 7 - 1 ); + assert( qualIncForLowEnergy >= 0 && qualIncForLowEnergy <= ( 2 << 8 ) ); + } + return qualIncForLowEnergy; } /* @@ -1549,89 +1548,89 @@ static bool logarithmic_search( #else -static Word8 logarithmic_search_fx(const apa_state_t * ps, - const Word16 * signal, - Word16 s_start, - Word16 inlen, - Word16 offset, - Word16 fixed_pos, - Word16 corr_len, - Word16 wss, - Word16 css, - Word16 * synchpos) +static Word8 logarithmic_search_fx( const apa_state_t *ps, + const Word16 *signal, + Word16 s_start, + Word16 inlen, + Word16 offset, + Word16 fixed_pos, + Word16 corr_len, + Word16 wss, + Word16 css, + Word16 *synchpos ) +{ + Word16 i; + Word32 coeff; + Word32 coeff_max; + Word16 s_start_old, s_len_old; + + DO + { + coeff_max = 0x80000000; /* will always be overwritten with result of first correlation */ + move32(); + + FOR( i = s_start; i < s_start + inlen; i += css * ps->num_channels ) + { + test(); + IF( EQ_16( wss, 1 ) && EQ_16( ps->num_channels, 1 ) ) + { + coeff = cross_correlation_self_fx( signal, add( i, offset ), add( fixed_pos, offset ), corr_len ); + } + ELSE + { + coeff = cross_correlation_subsampled_self_fx( signal, add( i, offset ), add( fixed_pos, offset ), + corr_len, i_mult2( wss, ps->num_channels ) ); + } + + /* update max corr */ + IF( LT_16( ps->scale, 100 ) ){ + /* shrinking: prefer greater synchpos for equal coeff */ + BASOP_SATURATE_WARNING_OFF_EVS + IF( GE_32( coeff, coeff_max ) ){ + coeff_max = L_add( coeff, 0 ); + *synchpos = i; + move16(); + } + BASOP_SATURATE_WARNING_ON_EVS + } + ELSE + { + /* extending: prefer smaller synchpos for equal coeff */ + BASOP_SATURATE_WARNING_OFF_EVS + IF( GT_32( coeff, coeff_max ) ) + { + coeff_max = L_add( coeff, 0 ); + *synchpos = i; + move16(); + } + BASOP_SATURATE_WARNING_ON_EVS + } +} +/* backup old search range */ +s_start_old = s_start; +move16(); +s_len_old = inlen; +move16(); + +css = shr( css, 1 ); +inlen = shr( inlen, 1 ); +s_start_old = s_start; +move16(); +s_start = sub( *synchpos, shr( inlen, 1 ) ); + +if ( LT_16( s_start, s_start_old ) ) +{ + s_start = s_start_old; + move16(); +} + +IF( GT_16( add( s_start, inlen ), add( s_start_old, s_len_old ) ) ) { - Word16 i; - Word32 coeff; - Word32 coeff_max; - Word16 s_start_old, s_len_old; - - DO - { - coeff_max = 0x80000000; /* will always be overwritten with result of first correlation */ move32(); - - FOR(i = s_start; i < s_start + inlen; i += css * ps->num_channels ) - { - test(); - IF(EQ_16(wss,1) && EQ_16(ps->num_channels,1)) - { - coeff = cross_correlation_self_fx(signal, add(i, offset), add(fixed_pos, offset), corr_len); - } - ELSE - { - coeff = cross_correlation_subsampled_self_fx(signal, add(i, offset), add(fixed_pos, offset), - corr_len, i_mult2(wss, ps->num_channels)); - } - - /* update max corr */ - IF(LT_16(ps->scale, 100)) - { - /* shrinking: prefer greater synchpos for equal coeff */ - BASOP_SATURATE_WARNING_OFF_EVS - IF(GE_32(coeff, coeff_max)) - { - coeff_max = L_add(coeff, 0); - *synchpos = i; - move16(); - } - BASOP_SATURATE_WARNING_ON_EVS - } - ELSE - { - /* extending: prefer smaller synchpos for equal coeff */ - BASOP_SATURATE_WARNING_OFF_EVS - IF(GT_32(coeff, coeff_max)) - { - coeff_max = L_add(coeff, 0); - *synchpos = i; - move16(); - } - BASOP_SATURATE_WARNING_ON_EVS - } - } - /* backup old search range */ - s_start_old = s_start; - move16(); - s_len_old = inlen; - move16(); - - css = shr(css, 1); - inlen = shr(inlen, 1); - s_start_old = s_start; - move16(); - s_start = sub(*synchpos, shr(inlen, 1)); - - if (LT_16(s_start,s_start_old)) - { - s_start = s_start_old; - move16(); - } - - IF(GT_16(add(s_start,inlen), add(s_start_old,s_len_old))) - { - inlen = add(sub(s_start_old, s_start), s_len_old); - } - } WHILE(GT_16(css, 2)); - return 0; + inlen = add( sub( s_start_old, s_start ), s_len_old ); +} +} +WHILE( GT_16( css, 2 ) ); +return 0; } #endif /* @@ -1709,16 +1708,16 @@ static bool find_synch( #else static Word16 find_synch_fx( apa_state_t *ps, - const Word16 *in, - Word16 l_in, - Word16 s_start, - Word16 s_len, - Word16 fixed_pos, - Word16 corr_len, - Word16 offset, - Word16 *energydBQ8, - Word32 *qualityQ16, - Word16 *synch_pos ) + const Word16 *in, + Word16 l_in, + Word16 s_start, + Word16 s_len, + Word16 fixed_pos, + Word16 corr_len, + Word16 offset, + Word16 *energydBQ8, + Word32 *qualityQ16, + Word16 *synch_pos ) { assert( ( corr_len - 1 + s_start + s_len - 1 + offset ) < l_in ); assert( ( corr_len - 1 + fixed_pos + offset ) < l_in ); @@ -1727,22 +1726,22 @@ static Word16 find_synch_fx( apa_state_t *ps, *synch_pos = ps->last_pitch; move16(); logarithmic_search_fx( ps, - in, - s_start, - s_len, - offset, - fixed_pos, - corr_len, - ps->wss, - //i_mult2( ps->css, ps->num_channels ), - ps->css, - synch_pos ); + in, + s_start, + s_len, + offset, + fixed_pos, + corr_len, + ps->wss, + // i_mult2( ps->css, ps->num_channels ), + ps->css, + synch_pos ); /* assert synch_pos is cleanly divisible by number of channels */ assert( *synch_pos % ps->num_channels == 0 ); *qualityQ16 = L_deposit_l( 0 ); get_scaling_quality_fx( ps, in, l_in, offset, corr_len, - abs_s( sub( *synch_pos, fixed_pos ) ), energydBQ8, qualityQ16 ); + abs_s( sub( *synch_pos, fixed_pos ) ), energydBQ8, qualityQ16 ); ps->last_pitch = *synch_pos; move16(); return 0; @@ -1843,7 +1842,7 @@ static bool shrink_frm( #ifdef IVAS_FLOAT_FIXED Word16 frm_in_fx[APA_BUF]; - for ( i = 0; i < l_frm/*960*ps->num_channels*/; i++ ) + for ( i = 0; i < l_frm /*960*ps->num_channels*/; i++ ) { frm_in_fx[i] = (Word16) frm_in[i]; } @@ -1864,7 +1863,7 @@ static bool shrink_frm( #endif // !IVAS_FLOAT_FIXED { /* maximum scaling */ - //energy = -65; + // energy = -65; quality = 5; if ( ps->evs_compat_mode == false ) { @@ -1899,15 +1898,15 @@ static bool shrink_frm( /* find synch */ #ifdef IVAS_FLOAT_FIXED Word16 energyQ8; - Word32 qualityQ16=0; - IF(ps->evs_compat_mode == false) - ps->signalScaleForCorrelation += 1; + Word32 qualityQ16 = 0; + IF( ps->evs_compat_mode == false ) + ps->signalScaleForCorrelation += 1; scaleSignal16( frm_in_fx, ps->frmInScaled, l_frm, ps->signalScaleForCorrelation ); findSynchResult = find_synch_fx( ps, ps->frmInScaled, l_frm, s_start, (uint16_t) ( s_end - s_start ), 0, l_seg, 0, &energyQ8, &qualityQ16, &xtract ); - //energy = fixedToFloat( energyQ8, 8 ); + // energy = fixedToFloat( energyQ8, 8 ); quality = fixedToFloat( qualityQ16, 16 ); - IF(ps->evs_compat_mode == false) - ps->signalScaleForCorrelation -= 1; + IF( ps->evs_compat_mode == false ) + ps->signalScaleForCorrelation -= 1; #else findSynchResult = find_synch( ps, frm_in, l_frm, s_start, (uint16_t) ( s_end - s_start ), 0, l_seg, 0, &energy, &quality, &xtract ); #endif @@ -1953,18 +1952,18 @@ static bool shrink_frm( { return 1; } - Word16 frm_out_fx[960*8]; - IF ( ps->evs_compat_mode == true ) + Word16 frm_out_fx[960 * 8]; + IF( ps->evs_compat_mode == true ) { - //overlapAddEvs_fx( frm_in_fx, frm_in_fx + xtract, frm_out_fx, l_seg, ps->num_channels, ps->win_fx + ps->l_halfwin_fx, ps->win_fx ); - overlapAdd( frm_in_fx, frm_in_fx + xtract, frm_out_fx, l_seg, ps->num_channels, ps->win_fx + ps->l_halfwin, ps->win_fx , ps->win_incrementor); + // overlapAddEvs_fx( frm_in_fx, frm_in_fx + xtract, frm_out_fx, l_seg, ps->num_channels, ps->win_fx + ps->l_halfwin_fx, ps->win_fx ); + overlapAdd( frm_in_fx, frm_in_fx + xtract, frm_out_fx, l_seg, ps->num_channels, ps->win_fx + ps->l_halfwin, ps->win_fx, ps->win_incrementor ); } ELSE { - overlapAdd( frm_in_fx, frm_in_fx + xtract, frm_out_fx, l_seg, ps->num_channels, ps->win_fx + ps->l_halfwin, ps->win_fx , ps->win_incrementor); + overlapAdd( frm_in_fx, frm_in_fx + xtract, frm_out_fx, l_seg, ps->num_channels, ps->win_fx + ps->l_halfwin, ps->win_fx, ps->win_incrementor ); } for ( i = 0; i < l_seg; i++ ) - frm_out[i] = (float)frm_out_fx[i]; + frm_out[i] = (float) frm_out_fx[i]; } else { @@ -2249,23 +2248,23 @@ static bool extend_frm( } } #ifdef IVAS_FLOAT_FIXED - Word16 frm_in_fx[1920*2*2*2]; + Word16 frm_in_fx[1920 * 2 * 2 * 2]; Word16 max_flag = 0; - for ( i = 0; i < 2*l_frm; i++ ) + for ( i = 0; i < 2 * l_frm; i++ ) { - if(frm_in[i] > 32767) + if ( frm_in[i] > 32767 ) { - max_flag = 1; - frm_in_fx[i] = 32767; + max_flag = 1; + frm_in_fx[i] = 32767; } - else if( frm_in[i] < -32767 ) + else if ( frm_in[i] < -32767 ) { - max_flag = 1; - frm_in_fx[i] = -32767; + max_flag = 1; + frm_in_fx[i] = -32767; } else { - frm_in_fx[i] = (Word16) frm_in[i]; + frm_in_fx[i] = (Word16) frm_in[i]; } } #endif @@ -2280,7 +2279,7 @@ static bool extend_frm( #endif { /* maximum scaling */ - //energy = -65; + // energy = -65; quality = 5; xtract[n] = s_start + ps->num_channels; if ( ps->evs_compat_mode == false ) @@ -2294,21 +2293,21 @@ static bool extend_frm( else { #ifdef IVAS_FLOAT_FIXED - Word16 energyQ8=0,*frmInScaled; - Word32 qualityQ16=0; + Word16 energyQ8 = 0, *frmInScaled; + Word32 qualityQ16 = 0; frmInScaled = ps->frmInScaled; - if(max_flag) + if ( max_flag ) { - ps->signalScaleForCorrelation += 1; + ps->signalScaleForCorrelation += 1; } assert( sizeof( ps->frmInScaled ) / sizeof( ps->frmInScaled[0] ) >= 2 * (size_t) l_frm ); - scaleSignal16( frm_in_fx, frmInScaled, shl(l_frm, 1), ps->signalScaleForCorrelation ); - findSynchResult = find_synch_fx( ps, frmInScaled, 2 * l_frm, s_start, s_end - s_start, sync_start, l_seg, l_frm, &energyQ8, &qualityQ16, &xtract[n] ); - //energy = fixedToFloat( energyQ8, 8 ); + scaleSignal16( frm_in_fx, frmInScaled, shl( l_frm, 1 ), ps->signalScaleForCorrelation ); + findSynchResult = find_synch_fx( ps, frmInScaled, 2 * l_frm, s_start, s_end - s_start, sync_start, l_seg, l_frm, &energyQ8, &qualityQ16, &xtract[n] ); + // energy = fixedToFloat( energyQ8, 8 ); quality = fixedToFloat( qualityQ16, 16 ); - if(max_flag) + if ( max_flag ) { - ps->signalScaleForCorrelation -= 1; + ps->signalScaleForCorrelation -= 1; } #else /* find synch */ @@ -2365,20 +2364,20 @@ static bool extend_frm( fadeOut = frm_in + l_frm + xtract[n - 1] + l_seg; fadeIn = frm_in + l_frm + xtract[n]; out = frm_out + ( n - 2 ) * l_seg; - Word16 fadeOut_fx[960*8], fadeIn_fx[960*8], out_fx[960*8]; + Word16 fadeOut_fx[960 * 8], fadeIn_fx[960 * 8], out_fx[960 * 8]; for ( i = 0; i < l_seg; i++ ) { fadeOut_fx[i] = (Word16) fadeOut[i]; fadeIn_fx[i] = (Word16) fadeIn[i]; } - IF ( ps->evs_compat_mode == true ) + IF( ps->evs_compat_mode == true ) { - //overlapAddEvs_fx( fadeOut_fx, fadeIn_fx, out_fx, l_seg, ps->num_channels, ps->win_fx + ps->l_halfwin_fx, ps->win_fx ); - overlapAdd( fadeOut_fx, fadeIn_fx, out_fx, l_seg, ps->num_channels, ps->win_fx + ps->l_halfwin, ps->win_fx ,ps->win_incrementor); + // overlapAddEvs_fx( fadeOut_fx, fadeIn_fx, out_fx, l_seg, ps->num_channels, ps->win_fx + ps->l_halfwin_fx, ps->win_fx ); + overlapAdd( fadeOut_fx, fadeIn_fx, out_fx, l_seg, ps->num_channels, ps->win_fx + ps->l_halfwin, ps->win_fx, ps->win_incrementor ); } ELSE { - overlapAdd( fadeOut_fx, fadeIn_fx, out_fx, l_seg, ps->num_channels, ps->win_fx + ps->l_halfwin, ps->win_fx ,ps->win_incrementor); + overlapAdd( fadeOut_fx, fadeIn_fx, out_fx, l_seg, ps->num_channels, ps->win_fx + ps->l_halfwin, ps->win_fx, ps->win_incrementor ); } for ( i = 0; i < l_seg; i++ ) out[i] = (float) out_fx[i]; @@ -2619,4 +2618,4 @@ static bool extend_frm( return 0; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/jbm_pcmdsp_similarityestimation.c b/lib_dec/jbm_pcmdsp_similarityestimation.c index 3863c0c7c..23f61a2d4 100644 --- a/lib_dec/jbm_pcmdsp_similarityestimation.c +++ b/lib_dec/jbm_pcmdsp_similarityestimation.c @@ -80,10 +80,10 @@ void scaleSignal16( const Word16 *src, Word16 *dst, Word16 n, Word16 rightShift #endif /* Calculates cross correlation coefficient for template segment. */ Word32 cross_correlation_subsampled_self_fx( const Word16 *signal, - Word16 x, - Word16 y, - Word16 corr_len, - Word16 subsampling ) + Word16 x, + Word16 y, + Word16 corr_len, + Word16 subsampling ) { Word32 sum; Word16 i; @@ -185,9 +185,12 @@ bool isSilence( return true; } -Word16 normalized_cross_correlation_self_fx(const Word16 * signal, - Word16 x, Word16 y, Word16 corr_len, - Word16 subsampling, Word32 *energy) +Word16 normalized_cross_correlation_self_fx( const Word16 *signal, + Word16 x, + Word16 y, + Word16 corr_len, + Word16 subsampling, + Word32 *energy ) { const Word16 *signalX, *signalY; Word32 sumXY, sumXX, sumYY, product; @@ -196,66 +199,66 @@ Word16 normalized_cross_correlation_self_fx(const Word16 * signal, signalX = &signal[x]; signalY = &signal[y]; - sumXY = L_deposit_l(0); - sumXX = L_deposit_l(0); - sumYY = L_deposit_l(0); + sumXY = L_deposit_l( 0 ); + sumXX = L_deposit_l( 0 ); + sumYY = L_deposit_l( 0 ); - FOR(i = 0; i < corr_len; i += subsampling) + FOR( i = 0; i < corr_len; i += subsampling ) { - sumXY = L_mac0(sumXY, signalX[i], signalY[i]); - sumXX = L_mac0(sumXX, signalX[i], signalX[i]); - sumYY = L_mac0(sumYY, signalY[i], signalY[i]); + sumXY = L_mac0( sumXY, signalX[i], signalY[i] ); + sumXX = L_mac0( sumXX, signalX[i], signalX[i] ); + sumYY = L_mac0( sumYY, signalY[i], signalY[i] ); } - normX = norm_l(sumXX); - sumXX = L_shl(sumXX, normX); - normY = norm_l(sumYY); - sumYY = L_shl(sumYY, normY); - product = L_mult0(extract_h(sumXX), extract_h(sumYY)); - normXY = add(normX, normY); - normXY = sub(normXY, 32); + normX = norm_l( sumXX ); + sumXX = L_shl( sumXX, normX ); + normY = norm_l( sumYY ); + sumYY = L_shl( sumYY, normY ); + product = L_mult0( extract_h( sumXX ), extract_h( sumYY ) ); + normXY = add( normX, normY ); + normXY = sub( normXY, 32 ); /* change norm to factor of 2 */ - IF( s_and(normXY, 0x1) != 0 ) + IF( s_and( normXY, 0x1 ) != 0 ) { - product = L_shr(product, 1); - normXY = sub(normXY, 1); + product = L_shr( product, 1 ); + normXY = sub( normXY, 1 ); } - sqrtXY = getSqrtWord32(product); - normXY = shr(normXY, 1); + sqrtXY = getSqrtWord32( product ); + normXY = shr( normXY, 1 ); - IF(sqrtXY != 0) + IF( sqrtXY != 0 ) { normCC = 0; move16(); - cc = BASOP_Util_Divide3216_Scale(sumXY, sqrtXY, &normCC); - normCC = add(normCC, 16); + cc = BASOP_Util_Divide3216_Scale( sumXY, sqrtXY, &normCC ); + normCC = add( normCC, 16 ); /* scale to Q15 with saturation */ BASOP_SATURATE_WARNING_OFF - cc = shl_r(cc, add(normXY, normCC)); + cc = shl_r( cc, add( normXY, normCC ) ); BASOP_SATURATE_WARNING_ON - *energy = L_shr_r(L_deposit_l(sqrtXY), normXY); + *energy = L_shr_r( L_deposit_l( sqrtXY ), normXY ); } - ELSE /* conceal silent frames */ + ELSE /* conceal silent frames */ { cc = 0; move16(); - *energy = L_deposit_l(1); + *energy = L_deposit_l( 1 ); } return cc; /* Q15 */ } -Word16 getSignalScaleForCorrelation(Word32 sampleRate) +Word16 getSignalScaleForCorrelation( Word32 sampleRate ) { Word16 ret; - IF( LT_32(sampleRate, 16000)) + IF( LT_32( sampleRate, 16000 ) ) { ret = 2; move16(); } - ELSE IF( GE_32(sampleRate, 32000)) + ELSE IF( GE_32( sampleRate, 32000 ) ) { ret = 4; move16(); @@ -269,30 +272,32 @@ Word16 getSignalScaleForCorrelation(Word32 sampleRate) return ret; } -Word32 cross_correlation_self_fx(const Word16 * signal, - Word16 x, Word16 y, Word16 corr_len) +Word32 cross_correlation_self_fx( const Word16 *signal, + Word16 x, + Word16 y, + Word16 corr_len ) { Word32 sum; Word16 i; - sum = L_deposit_l(0); - FOR(i = 0; i < corr_len; i++) + sum = L_deposit_l( 0 ); + FOR( i = 0; i < corr_len; i++ ) { - sum = L_mac0(sum, signal[x + i], signal[y + i]); + sum = L_mac0( sum, signal[x + i], signal[y + i] ); } return sum; } #ifdef IVAS_FLOAT_FIXED -Word8 isSilence_fx(const Word16 * signal, Word16 len, Word16 segments) +Word8 isSilence_fx( const Word16 *signal, Word16 len, Word16 segments ) { Word16 i, j, samplesPerSegment; Word32 energy, maxEnergy; Word8 ret; - assert(len > 0); - assert(segments > 0); + assert( len > 0 ); + assert( segments > 0 ); /* Every segment is checked using the following formula: * 10 * log10(sum_i(signal[i]*signal[i]))) > -65 @@ -302,35 +307,35 @@ Word8 isSilence_fx(const Word16 * signal, Word16 len, Word16 segments) ret = 1; move16(); - energy = L_deposit_l(0); - samplesPerSegment = idiv1616U(len, segments); + energy = L_deposit_l( 0 ); + samplesPerSegment = idiv1616U( len, segments ); /* calculate maxEnergy with factor 2 to reduce rounding error */ - maxEnergy = L_mult0(samplesPerSegment, 37); /* 37 = 2 * exp10(-65.0 / 20) * 32768 */ - maxEnergy = L_shr(maxEnergy, 1); + maxEnergy = L_mult0( samplesPerSegment, 37 ); /* 37 = 2 * exp10(-65.0 / 20) * 32768 */ + maxEnergy = L_shr( maxEnergy, 1 ); j = samplesPerSegment; move16(); /* check all but last segment */ - FOR(i = 0; i < len; i++) + FOR( i = 0; i < len; i++ ) { /* division by 32768 is done later */ - energy = L_add(energy, L_abs(L_deposit_l(signal[i]))); - IF( EQ_16(i, j)) + energy = L_add( energy, L_abs( L_deposit_l( signal[i] ) ) ); + IF( EQ_16( i, j ) ) { /* check energy of current segment */ /* 20 * log10(energy / 32768 / samplesPerSegment) > -65 * => energy > samplesPerSegment * 10 ^ (-65 / 20) * 32768 */ - IF( GT_32(energy, maxEnergy)) + IF( GT_32( energy, maxEnergy ) ) { ret = 0; move16(); BREAK; } - energy = L_deposit_l(0); - j = add(j, samplesPerSegment); + energy = L_deposit_l( 0 ); + j = add( j, samplesPerSegment ); } } /* check last segment */ - if( GT_32(energy, maxEnergy)) + if ( GT_32( energy, maxEnergy ) ) { ret = 0; move16(); diff --git a/lib_dec/jbm_pcmdsp_similarityestimation.h b/lib_dec/jbm_pcmdsp_similarityestimation.h index 44936fa7a..c681dbb1f 100644 --- a/lib_dec/jbm_pcmdsp_similarityestimation.h +++ b/lib_dec/jbm_pcmdsp_similarityestimation.h @@ -155,27 +155,31 @@ bool isSilence( uint32_t len, uint32_t segments ); -Word32 cross_correlation_subsampled_self_fx(const Word16 * signal, - Word16 x, Word16 y, Word16 corr_len, Word16 subsampling); +Word32 cross_correlation_subsampled_self_fx( const Word16 *signal, + Word16 x, + Word16 y, + Word16 corr_len, + Word16 subsampling ); -Word16 getSignalScaleForCorrelation(Word32 sampleRate); +Word16 getSignalScaleForCorrelation( Word32 sampleRate ); #ifdef IVAS_FLOAT_FIXED -void scaleSignal16(const Word16 *src, Word16 *dst, Word16 n, Word16 rightShift); +void scaleSignal16( const Word16 *src, Word16 *dst, Word16 n, Word16 rightShift ); #endif /* IVAS_FLOAT_FIXED */ -Word16 normalized_cross_correlation_self_fx(const Word16 * signal, - Word16 x, - Word16 y, - Word16 corr_len, - Word16 subsampling, - Word32 * energy - ); +Word16 normalized_cross_correlation_self_fx( const Word16 *signal, + Word16 x, + Word16 y, + Word16 corr_len, + Word16 subsampling, + Word32 *energy ); -Word32 cross_correlation_self_fx(const Word16 * signal, - Word16 x, Word16 y, Word16 corr_len); +Word32 cross_correlation_self_fx( const Word16 *signal, + Word16 x, + Word16 y, + Word16 corr_len ); -Word8 isSilence_fx(const Word16 * signal, Word16 len, Word16 segments); +Word8 isSilence_fx( const Word16 *signal, Word16 len, Word16 segments ); #endif /* JBM_PCMDSP_SIMILARITYESTIMATION_H */ diff --git a/lib_dec/jbm_pcmdsp_window.c b/lib_dec/jbm_pcmdsp_window.c index 3b38ba115..938d763ed 100644 --- a/lib_dec/jbm_pcmdsp_window.c +++ b/lib_dec/jbm_pcmdsp_window.c @@ -104,97 +104,95 @@ void overlapAdd( const Word16 *fadeOut, const Word16 *fadeIn, Word16 *out, Word1 #else void overlapAdd( - const float *fadeOut, - const float *fadeIn, - float *out, - uint16_t n, - uint16_t nChannels, - const float *fadeOutWin, - const float *fadeInWin) + const float *fadeOut, + const float *fadeIn, + float *out, + uint16_t n, + uint16_t nChannels, + const float *fadeOutWin, + const float *fadeInWin ) { - float fdOutVal, fdInVal; - int16_t i, j, hannIter; - float combinedVal; - - for (j = 0; j < nChannels; j++) - { - /* reset Hann window iterator to beginning (both channels use same window) */ - hannIter = 0; - for (i = j; i < n; i += nChannels) + float fdOutVal, fdInVal; + int16_t i, j, hannIter; + float combinedVal; + + for ( j = 0; j < nChannels; j++ ) { - fdOutVal = fadeOut[i] * fadeOutWin[hannIter]; - fdInVal = fadeIn[i] * fadeInWin[hannIter]; - /* round combinedVal value (taking care of sign) */ - combinedVal = fdInVal + fdOutVal; - out[i] = combinedVal; - hannIter++; + /* reset Hann window iterator to beginning (both channels use same window) */ + hannIter = 0; + for ( i = j; i < n; i += nChannels ) + { + fdOutVal = fadeOut[i] * fadeOutWin[hannIter]; + fdInVal = fadeIn[i] * fadeInWin[hannIter]; + /* round combinedVal value (taking care of sign) */ + combinedVal = fdInVal + fdOutVal; + out[i] = combinedVal; + hannIter++; + } } - } - return; + return; } void overlapAddEvs( - const float *fadeOut, - const float *fadeIn, - float *out, - uint16_t n, - uint16_t nChannels, - const float *fadeOutWin, - const float *fadeInWin) + const float *fadeOut, + const float *fadeIn, + float *out, + uint16_t n, + uint16_t nChannels, + const float *fadeOutWin, + const float *fadeInWin ) { - float fdOutVal, fdInVal; - int16_t i, j, hannIter; - float combinedVal; - - for (j = 0; j < nChannels; j++) - { - /* reset Hann window iterator to beginning (both channels use same window) */ - hannIter = 0; - for (i = j; i < n; i += nChannels) + float fdOutVal, fdInVal; + int16_t i, j, hannIter; + float combinedVal; + + for ( j = 0; j < nChannels; j++ ) { - fdOutVal = fadeOut[i] * fadeOutWin[hannIter]; - fdInVal = fadeIn[i] * fadeInWin[hannIter]; - /* round combinedVal value (taking care of sign) */ - - combinedVal = floorf((fdInVal + fdOutVal) + 0.5f); - if (fdInVal + fdOutVal < 0.0) - { - combinedVal = ceilf((fdInVal + fdOutVal) - 0.5f); - } - - /* saturate value */ - if (combinedVal > MAX16B_FLT) - { - combinedVal = MAX16B_FLT; - } - else if (combinedVal < MIN16B_FLT) - { - combinedVal = MIN16B_FLT; - } - - out[i] = combinedVal; - - hannIter++; + /* reset Hann window iterator to beginning (both channels use same window) */ + hannIter = 0; + for ( i = j; i < n; i += nChannels ) + { + fdOutVal = fadeOut[i] * fadeOutWin[hannIter]; + fdInVal = fadeIn[i] * fadeInWin[hannIter]; + /* round combinedVal value (taking care of sign) */ + + combinedVal = floorf( ( fdInVal + fdOutVal ) + 0.5f ); + if ( fdInVal + fdOutVal < 0.0 ) + { + combinedVal = ceilf( ( fdInVal + fdOutVal ) - 0.5f ); + } + + /* saturate value */ + if ( combinedVal > MAX16B_FLT ) + { + combinedVal = MAX16B_FLT; + } + else if ( combinedVal < MIN16B_FLT ) + { + combinedVal = MIN16B_FLT; + } + + out[i] = combinedVal; + + hannIter++; + } } - } - return; + return; } #endif - #ifdef IVAS_FLOAT_FIXED -void overlapAdd_fx(const Word16 *fadeOut, const Word16 *fadeIn, Word16 *out, - Word16 n, Word16 nChannels, const Word16 *fadeOutWin, const Word16 *fadeInWin ) +void overlapAdd_fx( const Word16 *fadeOut, const Word16 *fadeIn, Word16 *out, Word16 n, Word16 nChannels, const Word16 *fadeOutWin, const Word16 *fadeInWin ) { Word32 fdOutVal, fdInVal; Word16 i, j, hannIter, combinedVal; - FOR(j = 0; j < nChannels; j++) + FOR( j = 0; j < nChannels; j++ ) { /* reset Hann window iterator to beginning (both channels use same window) */ hannIter = 0; @@ -202,7 +200,7 @@ void overlapAdd_fx(const Word16 *fadeOut, const Word16 *fadeIn, Word16 *out, FOR( i = j; i < n; i += nChannels ) { fdOutVal = L_mult( fadeOut[i], fadeOutWin[hannIter] ); - fdInVal = L_mult( fadeIn[i], fadeInWin[hannIter] ); + fdInVal = L_mult( fadeIn[i], fadeInWin[hannIter] ); /* round to 16bit value and saturate (L_add already applies saturation) */ combinedVal = round_fx( L_add( fdOutVal, fdInVal ) ); @@ -226,20 +224,20 @@ void overlapAddEvs_fx( Word32 fdOutVal, fdInVal; Word16 i, j, hannIter, combinedVal; - FOR ( j = 0; j < nChannels; j++ ) + FOR( j = 0; j < nChannels; j++ ) { /* reset Hann window iterator to beginning (both channels use same window) */ hannIter = 0; - FOR ( i = j; i < n; i += nChannels ) + FOR( i = j; i < n; i += nChannels ) { fdOutVal = L_mult( fadeOut[i], fadeOutWin[hannIter] ); - fdInVal = L_mult( fadeIn[i], fadeInWin[hannIter] ); + fdInVal = L_mult( fadeIn[i], fadeInWin[hannIter] ); /* round combinedVal value (taking care of sign) */ - combinedVal = round_fx(L_add(fdOutVal, fdInVal)); - IF ( L_add( fdInVal, fdOutVal ) < 0 ) + combinedVal = round_fx( L_add( fdOutVal, fdInVal ) ); + IF( L_add( fdInVal, fdOutVal ) < 0 ) { - combinedVal = round_fx(L_add(fdOutVal, fdInVal)); + combinedVal = round_fx( L_add( fdOutVal, fdInVal ) ); } out[i] = combinedVal; @@ -249,4 +247,4 @@ void overlapAddEvs_fx( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/jbm_pcmdsp_window.h b/lib_dec/jbm_pcmdsp_window.h index 4b604b70f..1abf57f33 100644 --- a/lib_dec/jbm_pcmdsp_window.h +++ b/lib_dec/jbm_pcmdsp_window.h @@ -62,18 +62,15 @@ void hannWindow( uint16_t n, float *w ); * @param[in] fadeOutWin window for fade out * @param[in] fadeInWin window for fade in */ #ifndef IVAS_FLOAT_FIXED -void overlapAdd(const float *fadeOut, const float *fadeIn, float *out, uint16_t n, uint16_t nChannels, const float *fadeOutWin, const float *fadeInWin); -void overlapAddEvs(const float *fadeOut, const float *fadeIn, float *out, uint16_t n, uint16_t nChannels, const float *fadeOutWin, const float *fadeInWin); +void overlapAdd( const float *fadeOut, const float *fadeIn, float *out, uint16_t n, uint16_t nChannels, const float *fadeOutWin, const float *fadeInWin ); +void overlapAddEvs( const float *fadeOut, const float *fadeIn, float *out, uint16_t n, uint16_t nChannels, const float *fadeOutWin, const float *fadeInWin ); #else -void overlapAdd(const Word16 *fadeOut, const Word16 *fadeIn, Word16 *out, - Word16 n, Word16 nChannels, const Word16 *fadeOutWin, const Word16 *fadeInWin, Word16 hannIncrementor); +void overlapAdd( const Word16 *fadeOut, const Word16 *fadeIn, Word16 *out, Word16 n, Word16 nChannels, const Word16 *fadeOutWin, const Word16 *fadeInWin, Word16 hannIncrementor ); -void overlapAdd_fx(const Word16 *fadeOut, const Word16 *fadeIn, Word16 *out, - Word16 n, Word16 nChannels, const Word16 *fadeOutWin, const Word16 *fadeInWin ); +void overlapAdd_fx( const Word16 *fadeOut, const Word16 *fadeIn, Word16 *out, Word16 n, Word16 nChannels, const Word16 *fadeOutWin, const Word16 *fadeInWin ); -void overlapAdd_fx(const Word16 *fadeOut, const Word16 *fadeIn, Word16 *out, - Word16 n, Word16 nChannels, const Word16 *fadeOutWin, const Word16 *fadeInWin ); +void overlapAdd_fx( const Word16 *fadeOut, const Word16 *fadeIn, Word16 *out, Word16 n, Word16 nChannels, const Word16 *fadeOutWin, const Word16 *fadeInWin ); void overlapAddEvs_fx( const Word16 *fadeOut, const Word16 *fadeIn, Word16 *out, UWord16 n, UWord16 nChannels, const Word16 *fadeOutWin, const Word16 *fadeInWin ); #endif /* IVAS_FLOAT_FIXED */ diff --git a/lib_dec/lead_deindexing_fx.c b/lib_dec/lead_deindexing_fx.c index 195442ac9..090ec84a4 100644 --- a/lib_dec/lead_deindexing_fx.c +++ b/lib_dec/lead_deindexing_fx.c @@ -3,7 +3,7 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ +#include "options.h" /* Compilation switches */ #include "cnst.h" #include "rom_com.h" #include "rom_dec.h" @@ -13,7 +13,7 @@ /*-------------------------------------------------------------------* * Local function prototype *-------------------------------------------------------------------*/ -static void fcb_decode_pos_fx(const Word16 index, Word16 pos_vector[], const Word16 pulse_num, const Word16 pos_num); +static void fcb_decode_pos_fx( const Word16 index, Word16 pos_vector[], const Word16 pulse_num, const Word16 pos_num ); /*-------------------------------------------------------------------* * re8_decode_base_index_fx @@ -22,15 +22,15 @@ static void fcb_decode_pos_fx(const Word16 index, Word16 pos_vector[], const Wor *-------------------------------------------------------------------*/ void re8_decode_base_index_fx( const Word16 n, /* i : codebook number (*n is an integer defined in {0,2,3,4,..,n_max}) */ - UWord16 I, /* i : index of c (pointer to unsigned 16-bit word) */ - Word16 *x /* o : point in RE8 (8-dimensional integer vector) */ + UWord16 I, /* i : index of c (pointer to unsigned 16-bit word) */ + Word16 *x /* o : point in RE8 (8-dimensional integer vector) */ ) { - Word16 i,j,k1,l,m,m1,m2; - Word16 setor_8p_temp[8],setor_8p_temp_1[8],setor_8p_temp_2[8]; + Word16 i, j, k1, l, m, m1, m2; + Word16 setor_8p_temp[8], setor_8p_temp_1[8], setor_8p_temp_2[8]; Word16 sign_8p; Word16 code_level; - const Word16 *a1,*a2; + const Word16 *a1, *a2; Word16 ka; UWord16 offset; @@ -41,19 +41,19 @@ void re8_decode_base_index_fx( move16(); element_a11 = 0; element_a12 = 0; - set16_fx(setor_8p_temp_2, 0, 8); + set16_fx( setor_8p_temp_2, 0, 8 ); - IF (LT_16( n, 2 )) + IF( LT_16( n, 2 ) ) { - FOR (i=0; i<8; i++) + FOR( i = 0; i < 8; i++ ) { - x[i]=0; + x[i] = 0; move16(); } } ELSE { - if ( GT_32( I, 65519 )) + if ( GT_32( I, 65519 ) ) { I = 0; move16(); @@ -63,28 +63,28 @@ void re8_decode_base_index_fx( * search for the identifier ka of the absolute leader (table-lookup) * Q2 is a subset of Q3 - the two cases are considered in the same branch *-------------------------------------------------------------------*/ - IF (LE_16(n,3)) + IF( LE_16( n, 3 ) ) { - FOR (i = 1; i < NB_LDQ3; i++) + FOR( i = 1; i < NB_LDQ3; i++ ) { - IF (LT_32(I, II3[i])) + IF( LT_32( I, II3[i] ) ) { BREAK; } } - ka = AA3[sub(i,1)]; + ka = AA3[sub( i, 1 )]; move16(); } ELSE { - FOR (i = 1; i < NB_LDQ4; i++) + FOR( i = 1; i < NB_LDQ4; i++ ) { - IF (LT_32(I, II4[i])) + IF( LT_32( I, II4[i] ) ) { BREAK; } } - ka = AA4[sub(i,1)]; + ka = AA4[sub( i, 1 )]; move16(); } @@ -104,9 +104,9 @@ void re8_decode_base_index_fx( move16(); code_index = extract_l( L_sub( I, offset ) ); - sign_8p = s_and(code_index, sub( shl(1,k1), 1 )); + sign_8p = s_and( code_index, sub( shl( 1, k1 ), 1 ) ); - code_index = shr(code_index, k1); + code_index = shr( code_index, k1 ); m = 0; move16(); @@ -118,71 +118,71 @@ void re8_decode_base_index_fx( element_a10 = a1[0]; move16(); - SWITCH (code_level) + SWITCH( code_level ) { - case 4: + case 4: - m2 = 1; - move16(); - i = s_and(code_index, 1); - setor_8p_temp_2[0] = 0; - move16(); - - if ( i ) - { - setor_8p_temp_2[0] = 1; + m2 = 1; + move16(); + i = s_and( code_index, 1 ); + setor_8p_temp_2[0] = 0; move16(); - } - code_index = shr(code_index, 1); - /* FALLTHRU */ - case 3: + if ( i ) + { + setor_8p_temp_2[0] = 1; + move16(); + } + code_index = shr( code_index, 1 ); + /* FALLTHRU */ - m = a2[2]; - move16(); - m1 = a2[3]; - move16(); + case 3: - l = select_table22[m1][m]; - move16(); - j = extract_l(L_shr(L_mult0(code_index, mult_avq_tab[l]), shift_avq_tab[l])); - code_index = sub(code_index, extract_l(L_mult0(j, l))); - fcb_decode_pos_fx(code_index,setor_8p_temp_1, m, m1); + m = a2[2]; + move16(); + m1 = a2[3]; + move16(); - code_index = j; - move16(); - element_a12 = a1[2]; - move16(); - /* FALLTHRU */ + l = select_table22[m1][m]; + move16(); + j = extract_l( L_shr( L_mult0( code_index, mult_avq_tab[l] ), shift_avq_tab[l] ) ); + code_index = sub( code_index, extract_l( L_mult0( j, l ) ) ); + fcb_decode_pos_fx( code_index, setor_8p_temp_1, m, m1 ); + + code_index = j; + move16(); + element_a12 = a1[2]; + move16(); + /* FALLTHRU */ - case 2: + case 2: - m = a2[2]; - move16(); - fcb_decode_pos_fx(code_index,setor_8p_temp,8,m); - element_a11 = a1[1]; - move16(); + m = a2[2]; + move16(); + fcb_decode_pos_fx( code_index, setor_8p_temp, 8, m ); + element_a11 = a1[1]; + move16(); } - FOR (i=0; i<8; i++) + FOR( i = 0; i < 8; i++ ) { x[i] = element_a10; move16(); } - FOR (i=0; i 0)) + IF( ( k1 == 7 ) && ( l > 0 ) ) #else - IF(k1 == 7) + IF( k1 == 7 ) #endif { m2 = 7; move16(); } - FOR(i = 0; i < m2; i++) + FOR( i = 0; i < m2; i++ ) { - IF(x[i] != 0) + IF( x[i] != 0 ) { - IF(s_and(shr(sign_8p, m1), 1) != 0) + IF( s_and( shr( sign_8p, m1 ), 1 ) != 0 ) { - x[i] = sub(0, x[i]); + x[i] = sub( 0, x[i] ); move16(); } - m1 = sub(m1, 1); + m1 = sub( m1, 1 ); } } /*--------------------------------------------------------------------* * recover the sign of last element if needed *--------------------------------------------------------------------*/ - IF (EQ_16( k1, 7 )) + IF( EQ_16( k1, 7 ) ) { m1 = 0; move16(); - FOR (i=0; i<8; i++) + FOR( i = 0; i < 8; i++ ) { - m1 = add(m1, x[i]); + m1 = add( m1, x[i] ); } - IF ( s_and(m1, 3) ) + IF( s_and( m1, 3 ) ) { - x[7] = sub(0, x[7]); + x[7] = sub( 0, x[7] ); move16(); } } @@ -255,14 +255,14 @@ void re8_decode_base_index_fx( * base function for decoding position index *-------------------------------------------------------------------*/ static void fcb_decode_pos_fx( - const Word16 index, /* i : Index to decoder */ - Word16 pos_vector[], /* o : Position vector */ - const Word16 pulse_num, /* i : Number of pulses */ - const Word16 pos_num /* i : Number of positions */ + const Word16 index, /* i : Index to decoder */ + Word16 pos_vector[], /* o : Position vector */ + const Word16 pulse_num, /* i : Number of pulses */ + const Word16 pos_num /* i : Number of positions */ ) { - Word16 i,k,l; - Word16 temp1,temp2,tmp_loop; + Word16 i, k, l; + Word16 temp1, temp2, tmp_loop; const Word16 *select_table23, *select_table24; k = index; @@ -273,26 +273,26 @@ static void fcb_decode_pos_fx( move16(); temp2 = add( pulse_num, 1 ); - tmp_loop = sub(pos_num,1); - FOR (i=0; ihSCE[0]->hCoreCoder; hCoreCoder[0]->total_brate = st_ivas->hDecoderConfig->ivas_total_brate; hCoreCoder[0]->total_num_bits = st_ivas->num_bits; - hCoreCoder[0]->output_frame_fx = extract_l(Mult_32_16(hCoreCoder[0]->output_Fs, 0x0290)); + hCoreCoder[0]->output_frame_fx = extract_l( Mult_32_16( hCoreCoder[0]->output_Fs, 0x0290 ) ); mdct_switching_dec( hCoreCoder[0] ); for ( ch = 0; ch < MAX_OUTPUT_CHANNELS_IN_DIEGETIC_PAN; ch++ ) @@ -2758,8 +2752,8 @@ static ivas_error evs_dec_main( p_output[ch] = st_ivas->p_output_f[ch]; } #ifdef IVAS_FLOAT_FIXED - Word16 output_16[L_FRAME48k]; -#endif + Word16 output_16[L_FRAME48k]; +#endif /* run the main EVS decoding routine */ if ( hCoreCoder[0]->codec_mode == MODE1 ) @@ -2769,7 +2763,7 @@ static ivas_error evs_dec_main( #ifndef IVAS_FLOAT_FIXED if ( ( error = amr_wb_dec( hCoreCoder[0], st_ivas->mem_hp20_out[0], p_output[0] ) ) != IVAS_ERR_OK ) #else - if ( ( error = amr_wb_dec_fx(output_16, hCoreCoder[0]) ) != IVAS_ERR_OK ) + if ( ( error = amr_wb_dec_fx( output_16, hCoreCoder[0] ) ) != IVAS_ERR_OK ) #endif { return error; @@ -2780,7 +2774,7 @@ static ivas_error evs_dec_main( #ifndef IVAS_FLOAT_FIXED if ( ( error = evs_dec( hCoreCoder[0], st_ivas->mem_hp20_out[0], p_output[0], FRAMEMODE_NORMAL ) ) != IVAS_ERR_OK ) #else - if ( ( error = evs_dec_fx(hCoreCoder[0], output_16, FRAMEMODE_NORMAL) ) != IVAS_ERR_OK ) + if ( ( error = evs_dec_fx( hCoreCoder[0], output_16, FRAMEMODE_NORMAL ) ) != IVAS_ERR_OK ) #endif { return error; @@ -2794,7 +2788,7 @@ static ivas_error evs_dec_main( #ifndef IVAS_FLOAT_FIXED if ( ( error = evs_dec( hCoreCoder[0], st_ivas->mem_hp20_out[0], p_output[0], FRAMEMODE_NORMAL ) ) != IVAS_ERR_OK ) #else - if ( ( error = evs_dec_fx(hCoreCoder[0], output_16, FRAMEMODE_NORMAL)) != IVAS_ERR_OK ) + if ( ( error = evs_dec_fx( hCoreCoder[0], output_16, FRAMEMODE_NORMAL ) ) != IVAS_ERR_OK ) #endif { return error; @@ -2805,7 +2799,7 @@ static ivas_error evs_dec_main( #ifndef IVAS_FLOAT_FIXED if ( ( error = evs_dec( hCoreCoder[0], st_ivas->mem_hp20_out[0], p_output[0], FRAMEMODE_FUTURE ) ) != IVAS_ERR_OK ) #else - if ( ( error = evs_dec_fx(hCoreCoder[0], output_16, FRAMEMODE_FUTURE)) != IVAS_ERR_OK ) + if ( ( error = evs_dec_fx( hCoreCoder[0], output_16, FRAMEMODE_FUTURE ) ) != IVAS_ERR_OK ) #endif { return error; @@ -2816,7 +2810,7 @@ static ivas_error evs_dec_main( #ifndef IVAS_FLOAT_FIXED if ( ( error = evs_dec( hCoreCoder[0], st_ivas->mem_hp20_out[0], p_output[0], FRAMEMODE_MISSING ) ) != IVAS_ERR_OK ) #else - if ( ( error = evs_dec_fx(hCoreCoder[0], output_16, FRAMEMODE_MISSING)) != IVAS_ERR_OK ) + if ( ( error = evs_dec_fx( hCoreCoder[0], output_16, FRAMEMODE_MISSING ) ) != IVAS_ERR_OK ) #endif { return error; @@ -2833,9 +2827,9 @@ static ivas_error evs_dec_main( v_multc( p_output[0], mixer_left, p_output[0], nOutSamples ); } #ifdef IVAS_FLOAT_FIXED - for (int i = 0; i < nOutSamples; i++) + for ( int i = 0; i < nOutSamples; i++ ) { - p_output[0][i] = output_16[i]; + p_output[0][i] = output_16[i]; } #endif if ( !st_ivas->hDecoderConfig->Opt_tsm ) @@ -2848,21 +2842,18 @@ static ivas_error evs_dec_main( int16_t pcm_buf_local[L_FRAME48k * MAX_OUTPUT_CHANNELS_IN_DIEGETIC_PAN]; /* convert 'float' output data to 'short' */ - ivas_syn_output( p_output, nOutSamples, st_ivas->hDecoderConfig->nchan_out, pcm_buf_local ); + ivas_syn_output( p_output, nOutSamples, st_ivas->hDecoderConfig->nchan_out, pcm_buf_local ); mvs2r( pcm_buf_local, floatBuf, nOutSamples * st_ivas->hDecoderConfig->nchan_out ); } else { - ivas_syn_output( p_output, nOutSamples, st_ivas->hDecoderConfig->nchan_out, pcmBuf ); - + ivas_syn_output( p_output, nOutSamples, st_ivas->hDecoderConfig->nchan_out, pcmBuf ); } return IVAS_ERR_OK; } - - /*---------------------------------------------------------------------* * input_format_API_to_internal() * @@ -3008,6 +2999,3 @@ static ivas_error IVAS_DEC_VoIP_reconfigure( return IVAS_ERR_OK; } #endif // !IVAS_FLOAT_FIXED - - - diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index 02aedd958..f6d7f1b0a 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -65,9 +65,6 @@ typedef enum _IVAS_DEC_COMPLEXITY_LEVEL } IVAS_DEC_COMPLEXITY_LEVEL; - - - /* bitstream formats that can be consumed */ typedef enum _IVAS_DEC_BS_FORMAT { diff --git a/lib_dec/lib_dec_fx.c b/lib_dec/lib_dec_fx.c index 06ee28758..78b694122 100644 --- a/lib_dec/lib_dec_fx.c +++ b/lib_dec/lib_dec_fx.c @@ -751,22 +751,22 @@ ivas_error IVAS_DEC_FeedFrame_Serial( DECODER_CONFIG_HANDLE hDecoderConfig = hIvasDec->st_ivas->hDecoderConfig; AUDIO_CONFIG output_config = hDecoderConfig->output_config; - IF((hIvasDec->st_ivas->ivas_format == MC_FORMAT) && (hIvasDec->st_ivas->mc_mode == MC_MODE_PARAMMC)) + IF( ( hIvasDec->st_ivas->ivas_format == MC_FORMAT ) && ( hIvasDec->st_ivas->mc_mode == MC_MODE_PARAMMC ) ) { - IF(output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM) + IF( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM ) { /*float2fix block: to be removed*/ - floatToFixed_arrL(hIvasDec->st_ivas->hLsSetupCustom->ls_azimuth, hIvasDec->st_ivas->hLsSetupCustom->ls_azimuth_fx, Q22, hIvasDec->st_ivas->hLsSetupCustom->num_spk); - floatToFixed_arrL(hIvasDec->st_ivas->hLsSetupCustom->ls_elevation, hIvasDec->st_ivas->hLsSetupCustom->ls_elevation_fx, Q22, hIvasDec->st_ivas->hLsSetupCustom->num_spk); + floatToFixed_arrL( hIvasDec->st_ivas->hLsSetupCustom->ls_azimuth, hIvasDec->st_ivas->hLsSetupCustom->ls_azimuth_fx, Q22, hIvasDec->st_ivas->hLsSetupCustom->num_spk ); + floatToFixed_arrL( hIvasDec->st_ivas->hLsSetupCustom->ls_elevation, hIvasDec->st_ivas->hLsSetupCustom->ls_elevation_fx, Q22, hIvasDec->st_ivas->hLsSetupCustom->num_spk ); } } - IF(output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM) + IF( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM ) { - FOR(Word16 ind = 0; ind < MAX_OUTPUT_CHANNELS; ind++) + FOR( Word16 ind = 0; ind < MAX_OUTPUT_CHANNELS; ind++ ) { - hIvasDec->st_ivas->hLsSetupCustom->ls_azimuth_fx[ind] = (Word32)(hIvasDec->st_ivas->hLsSetupCustom->ls_azimuth[ind] * (1 << 22)); - hIvasDec->st_ivas->hLsSetupCustom->ls_elevation_fx[ind] = (Word32)(hIvasDec->st_ivas->hLsSetupCustom->ls_elevation[ind] * (1 << 22)); + hIvasDec->st_ivas->hLsSetupCustom->ls_azimuth_fx[ind] = (Word32) ( hIvasDec->st_ivas->hLsSetupCustom->ls_azimuth[ind] * ( 1 << 22 ) ); + hIvasDec->st_ivas->hLsSetupCustom->ls_elevation_fx[ind] = (Word32) ( hIvasDec->st_ivas->hLsSetupCustom->ls_elevation[ind] * ( 1 << 22 ) ); } } IF( ( error = ivas_init_decoder_fx( hIvasDec->st_ivas ) ) != IVAS_ERR_OK ) @@ -778,17 +778,18 @@ ivas_error IVAS_DEC_FeedFrame_Serial( } #ifdef IVAS_FLOAT_FIXED Word32 ivas_total_brate = hIvasDec->st_ivas->hDecoderConfig->ivas_total_brate; - IF((hIvasDec->st_ivas->ivas_format == MC_FORMAT) && (hIvasDec->st_ivas->mc_mode == MC_MODE_PARAMMC)) { + IF( ( hIvasDec->st_ivas->ivas_format == MC_FORMAT ) && ( hIvasDec->st_ivas->mc_mode == MC_MODE_PARAMMC ) ) + { PARAM_MC_DEC_HANDLE hParamMC; hParamMC = hIvasDec->st_ivas->hParamMC; Word16 nchan_out_transport, nchan_out_cov; MC_LS_SETUP mc_ls_setup; Word16 nchan_transport, i; - mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup(hIvasDec->st_ivas->transport_config); - hIvasDec->st_ivas->nchan_transport = ivas_param_mc_getNumTransportChannels(ivas_total_brate, mc_ls_setup); + mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup( hIvasDec->st_ivas->transport_config ); + hIvasDec->st_ivas->nchan_transport = ivas_param_mc_getNumTransportChannels( ivas_total_brate, mc_ls_setup ); nchan_transport = hIvasDec->st_ivas->nchan_transport; nchan_out_transport = hIvasDec->st_ivas->hTransSetup.nchan_out_woLFE + hIvasDec->st_ivas->hTransSetup.num_lfe; - IF (hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_COV || hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO) + IF( hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_COV || hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) { nchan_out_cov = hIvasDec->st_ivas->hOutSetup.nchan_out_woLFE + hIvasDec->st_ivas->hOutSetup.num_lfe; move16(); @@ -797,15 +798,15 @@ ivas_error IVAS_DEC_FeedFrame_Serial( { nchan_out_cov = nchan_out_transport; } - IF (hParamMC) + IF( hParamMC ) { - fixedToFloat_arrL(hParamMC->h_output_synthesis_params.proto_matrix_fx, hParamMC->h_output_synthesis_params.proto_matrix, 26, nchan_transport * nchan_out_cov); - FOR(i = 0; i < hParamMC->diff_proto_info->num_protos_diff; i++) + fixedToFloat_arrL( hParamMC->h_output_synthesis_params.proto_matrix_fx, hParamMC->h_output_synthesis_params.proto_matrix, 26, nchan_transport * nchan_out_cov ); + FOR( i = 0; i < hParamMC->diff_proto_info->num_protos_diff; i++ ) { - fixedToFloat_arrL(hParamMC->diff_proto_info->proto_fac_fx[i], hParamMC->diff_proto_info->proto_fac[i], 26, hParamMC->diff_proto_info->num_source_chan_diff[i]); + fixedToFloat_arrL( hParamMC->diff_proto_info->proto_fac_fx[i], hParamMC->diff_proto_info->proto_fac[i], 26, hParamMC->diff_proto_info->num_source_chan_diff[i] ); } - IF (hParamMC->hoa_encoder_fx) - fixedToFloat_arrL(hParamMC->hoa_encoder_fx, hParamMC->hoa_encoder, Q29, hIvasDec->st_ivas->hTransSetup.nchan_out_woLFE * MAX_INTERN_CHANNELS); + IF( hParamMC->hoa_encoder_fx ) + fixedToFloat_arrL( hParamMC->hoa_encoder_fx, hParamMC->hoa_encoder, Q29, hIvasDec->st_ivas->hTransSetup.nchan_out_woLFE * MAX_INTERN_CHANNELS ); } } #endif @@ -950,100 +951,97 @@ ivas_error IVAS_DEC_GetSamples( *needNewFrame = true; } } - ELSE - { + ELSE{ /* check if we need to run the setup function */ - IF( !hIvasDec->isInitialized || hIvasDec->hasBeenFedFrame ) - { + IF( !hIvasDec->isInitialized || hIvasDec->hasBeenFedFrame ){ /* setup */ - IF( ( error = IVAS_DEC_Setup( hIvasDec, &l_ts, &nTransportChannels, &nOutChannels, &nSamplesRendered_loop, pcmBuf + nSamplesRendered * nOutChannels ) ) != IVAS_ERR_OK ) + IF( ( error = IVAS_DEC_Setup( hIvasDec, &l_ts, &nTransportChannels, &nOutChannels, &nSamplesRendered_loop, pcmBuf + nSamplesRendered * nOutChannels ) ) != IVAS_ERR_OK ){ + return error; +} +} +{ + /* check if we need to run the setup function, tc decoding and feeding the renderer */ + IF( !hIvasDec->isInitialized || hIvasDec->hasBeenFedFrame ) + { + Word16 nResidualSamples, nSamplesTcsScaled; + nSamplesRendered = add( nSamplesRendered, nSamplesRendered_loop ); + + IF( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm && NE_16( (Word16) nTransportChannels, hIvasDec->nTransportChannelsOld ) ) + { + IF( ( error = IVAS_DEC_VoIP_reconfigure( hIvasDec, nTransportChannels, l_ts ) ) != IVAS_ERR_OK ) { return error; } } + + /* IVAS decoder */ + IF( ( error = IVAS_DEC_GetTcSamples( hIvasDec, hIvasDec->apaExecBuffer, hIvasDec->apaExecBuffer_fx, &nOutSamplesElse ) ) != IVAS_ERR_OK ) + { + return error; + } + /* JBM */ + IF( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm ) { - /* check if we need to run the setup function, tc decoding and feeding the renderer */ - IF( !hIvasDec->isInitialized || hIvasDec->hasBeenFedFrame ) + IF( NE_16( (Word16) apa_set_scale( hIvasDec->hTimeScaler, hIvasDec->tsm_scale ), 0 ) ) { - Word16 nResidualSamples, nSamplesTcsScaled; - nSamplesRendered = add( nSamplesRendered, nSamplesRendered_loop ); - - IF( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm && NE_16( (Word16) nTransportChannels, hIvasDec->nTransportChannelsOld ) ) - { - IF( ( error = IVAS_DEC_VoIP_reconfigure( hIvasDec, nTransportChannels, l_ts ) ) != IVAS_ERR_OK ) - { - return error; - } - } - - /* IVAS decoder */ - IF( ( error = IVAS_DEC_GetTcSamples( hIvasDec, hIvasDec->apaExecBuffer, hIvasDec->apaExecBuffer_fx, &nOutSamplesElse ) ) != IVAS_ERR_OK ) - { - return error; - } - /* JBM */ - IF( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm ) - { - IF( NE_16( (Word16) apa_set_scale( hIvasDec->hTimeScaler, hIvasDec->tsm_scale ), 0 ) ) - { - return IVAS_ERR_UNKNOWN; - } - - IF( NE_16( (Word16) apa_exec( hIvasDec->hTimeScaler, hIvasDec->apaExecBuffer, hIvasDec->nSamplesFrame * nTransportChannels, (UWord16) hIvasDec->tsm_max_scaling, hIvasDec->apaExecBuffer, &nTimeScalerOutSamples ), 0 ) ) - { - return IVAS_ERR_UNKNOWN; - } - - assert( LE_32( (Word32) nTimeScalerOutSamples, APA_BUF ) ); - nSamplesTcsScaled = nTimeScalerOutSamples / nTransportChannels; - } - ELSE - { - nSamplesTcsScaled = hIvasDec->nSamplesFrame; - } - - /* Feed decoded transport channels samples to the renderer */ - IF( ( error = IVAS_DEC_RendererFeedTcSamples( hIvasDec, nSamplesTcsScaled, &nResidualSamples, hIvasDec->apaExecBuffer ) ) != IVAS_ERR_OK ) - { - return error; - } - - IF( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm ) - { - /* feed residual samples to TSM for the next call */ - IF( NE_16( (Word16) apa_set_renderer_residual_samples( hIvasDec->hTimeScaler, (UWord16) nResidualSamples ), 0 ) ) - { - return IVAS_ERR_UNKNOWN; - } - } - hIvasDec->hasBeenFedFrame = false; + return IVAS_ERR_UNKNOWN; } - /* render IVAS frames directly to the output buffer */ - nSamplesToRender = sub( nSamplesAsked, nSamplesRendered ); - IF( ( error = IVAS_DEC_GetRenderedSamples( hIvasDec, nSamplesToRender, &nSamplesRendered_loop, &hIvasDec->nSamplesAvailableNext, pcmBuf + nSamplesRendered * nOutChannels ) ) != IVAS_ERR_OK ) + IF( NE_16( (Word16) apa_exec( hIvasDec->hTimeScaler, hIvasDec->apaExecBuffer, hIvasDec->nSamplesFrame * nTransportChannels, (UWord16) hIvasDec->tsm_max_scaling, hIvasDec->apaExecBuffer, &nTimeScalerOutSamples ), 0 ) ) { - return error; + return IVAS_ERR_UNKNOWN; } - nSamplesRendered = add( nSamplesRendered, nSamplesRendered_loop ); - nSamplesToRender = sub( nSamplesToRender, nSamplesRendered_loop ); - IF( EQ_16( hIvasDec->nSamplesAvailableNext, 0 ) ) - { - *needNewFrame = true; - hIvasDec->needNewFrame = true; - } - ELSE + assert( LE_32( (Word32) nTimeScalerOutSamples, APA_BUF ) ); + nSamplesTcsScaled = nTimeScalerOutSamples / nTransportChannels; + } + ELSE + { + nSamplesTcsScaled = hIvasDec->nSamplesFrame; + } + + /* Feed decoded transport channels samples to the renderer */ + IF( ( error = IVAS_DEC_RendererFeedTcSamples( hIvasDec, nSamplesTcsScaled, &nResidualSamples, hIvasDec->apaExecBuffer ) ) != IVAS_ERR_OK ) + { + return error; + } + + IF( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm ) + { + /* feed residual samples to TSM for the next call */ + IF( NE_16( (Word16) apa_set_renderer_residual_samples( hIvasDec->hTimeScaler, (UWord16) nResidualSamples ), 0 ) ) { - *needNewFrame = false; + return IVAS_ERR_UNKNOWN; } } + hIvasDec->hasBeenFedFrame = false; } - *nOutSamples = nSamplesRendered; + /* render IVAS frames directly to the output buffer */ + nSamplesToRender = sub( nSamplesAsked, nSamplesRendered ); + IF( ( error = IVAS_DEC_GetRenderedSamples( hIvasDec, nSamplesToRender, &nSamplesRendered_loop, &hIvasDec->nSamplesAvailableNext, pcmBuf + nSamplesRendered * nOutChannels ) ) != IVAS_ERR_OK ) + { + return error; + } - return IVAS_ERR_OK; + nSamplesRendered = add( nSamplesRendered, nSamplesRendered_loop ); + nSamplesToRender = sub( nSamplesToRender, nSamplesRendered_loop ); + IF( EQ_16( hIvasDec->nSamplesAvailableNext, 0 ) ) + { + *needNewFrame = true; + hIvasDec->needNewFrame = true; + } + ELSE + { + *needNewFrame = false; + } +} +} + +*nOutSamples = nSamplesRendered; + +return IVAS_ERR_OK; } @@ -1099,89 +1097,92 @@ static ivas_error IVAS_DEC_Setup( #if 1 // flt to fix Word16 n_samples_granularity; - n_samples_granularity = NS2SA(st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS); + n_samples_granularity = NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); DECODER_CONFIG_HANDLE hDecoderConfig = NULL; Word32 ivas_total_brate; ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; Word16 SrcInd[MAX_NUM_TDREND_CHANNELS]; Word16 num_src = 0; Word16 i; - IF(EQ_16(is_DTXrate(ivas_total_brate), 0) && (!(EQ_16(st_ivas->ini_active_frame, 0) && NE_32(ivas_total_brate, FRAME_NO_DATA) && LT_32(ivas_total_brate, MASA_STEREO_MIN_BITRATE) && EQ_16(st_ivas->nCPE, 1))) && st_ivas->bit_stream[(ivas_total_brate / FRAMES_PER_SEC) - 1] && st_ivas->ivas_format == MASA_FORMAT && st_ivas->last_ivas_format == MASA_FORMAT && ((GT_32(ivas_total_brate, IVAS_SID_5k2) && NE_32(ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate)) || EQ_16(st_ivas->ini_active_frame, 0))) + IF( EQ_16( is_DTXrate( ivas_total_brate ), 0 ) && ( !( EQ_16( st_ivas->ini_active_frame, 0 ) && NE_32( ivas_total_brate, FRAME_NO_DATA ) && LT_32( ivas_total_brate, MASA_STEREO_MIN_BITRATE ) && EQ_16( st_ivas->nCPE, 1 ) ) ) && st_ivas->bit_stream[( ivas_total_brate / FRAMES_PER_SEC ) - 1] && st_ivas->ivas_format == MASA_FORMAT && st_ivas->last_ivas_format == MASA_FORMAT && ( ( GT_32( ivas_total_brate, IVAS_SID_5k2 ) && NE_32( ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate ) ) || EQ_16( st_ivas->ini_active_frame, 0 ) ) ) { - IF(EQ_16(st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC) || EQ_16(st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM) || EQ_16(st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC)) + IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_16( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) { - IF(EQ_16(st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC) && NE_16(st_ivas->ism_mode, ISM_MASA_MODE_DISC)) + IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) && NE_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { - IF(LT_16(n_samples_granularity, st_ivas->hTcBuffer->n_samples_granularity)) + IF( LT_16( n_samples_granularity, st_ivas->hTcBuffer->n_samples_granularity ) ) { - IF(st_ivas->hSbaIsmData) + IF( st_ivas->hSbaIsmData ) { - FOR(Word16 ch_idx = 0; ch_idx < st_ivas->hSbaIsmData->delayBuffer_nchan; ch_idx++) + FOR( Word16 ch_idx = 0; ch_idx < st_ivas->hSbaIsmData->delayBuffer_nchan; ch_idx++ ) { - //floatToFixed_arr32(st_ivas->hSbaIsmData->delayBuffer[ch_idx], st_ivas->hSbaIsmData->delayBuffer_fx[ch_idx], Q11, st_ivas->hSbaIsmData->delayBuffer_size); + // floatToFixed_arr32(st_ivas->hSbaIsmData->delayBuffer[ch_idx], st_ivas->hSbaIsmData->delayBuffer_fx[ch_idx], Q11, st_ivas->hSbaIsmData->delayBuffer_size); } } Word16 n_tc; - IF (st_ivas->ivas_format == MASA_ISM_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT) - n_tc = st_ivas->nchan_ism; + IF( st_ivas->ivas_format == MASA_ISM_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT ) + n_tc = st_ivas->nchan_ism; ELSE n_tc = st_ivas->hTcBuffer->nchan_transport_internal; - FOR (Word16 ch = 0; ch < n_tc; ch++) + FOR( Word16 ch = 0; ch < n_tc; ch++ ) { - //floatToFixed_arrL(st_ivas->hTcBuffer->tc[ch], st_ivas->hTcBuffer->tc_fx[ch], Q11, L_FRAME48k); + // floatToFixed_arrL(st_ivas->hTcBuffer->tc[ch], st_ivas->hTcBuffer->tc_fx[ch], Q11, L_FRAME48k); } } } } } - IF(EQ_16(is_DTXrate(ivas_total_brate), 0) && (!(EQ_16(st_ivas->ini_active_frame, 0) && NE_32(ivas_total_brate, FRAME_NO_DATA) && LT_32(ivas_total_brate, MASA_STEREO_MIN_BITRATE) && EQ_16(st_ivas->nCPE, 1))) && st_ivas->bit_stream[(ivas_total_brate / FRAMES_PER_SEC) - 1] && st_ivas->ivas_format == MASA_FORMAT && st_ivas->last_ivas_format != MASA_FORMAT && ((GT_32(ivas_total_brate, IVAS_SID_5k2) && NE_32(ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate)) && EQ_16(st_ivas->ini_active_frame, 0))) + IF( EQ_16( is_DTXrate( ivas_total_brate ), 0 ) && ( !( EQ_16( st_ivas->ini_active_frame, 0 ) && NE_32( ivas_total_brate, FRAME_NO_DATA ) && LT_32( ivas_total_brate, MASA_STEREO_MIN_BITRATE ) && EQ_16( st_ivas->nCPE, 1 ) ) ) && st_ivas->bit_stream[( ivas_total_brate / FRAMES_PER_SEC ) - 1] && st_ivas->ivas_format == MASA_FORMAT && st_ivas->last_ivas_format != MASA_FORMAT && ( ( GT_32( ivas_total_brate, IVAS_SID_5k2 ) && NE_32( ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate ) ) && EQ_16( st_ivas->ini_active_frame, 0 ) ) ) { - // Float to fix conversions for ivas_td_binaural_open_fx - IF (st_ivas->ism_mode == ISM_MASA_MODE_DISC) - { - FOR(i = 0; i < 4; i++) - { - st_ivas->hRenderConfig->directivity_fx[i * 3] = (Word16)floatToFixed(st_ivas->hRenderConfig->directivity[i * 3], 6); - st_ivas->hRenderConfig->directivity_fx[i * 3 + 1] = (Word16)floatToFixed(st_ivas->hRenderConfig->directivity[i * 3 + 1], 6); - st_ivas->hRenderConfig->directivity_fx[i * 3 + 2] = (Word16)floatToFixed(st_ivas->hRenderConfig->directivity[i * 3 + 2], 15); - } - } - // Float to fix conversions for ivas_cldfb_dec_reconfig_fx - IF(st_ivas->hSpar) + // Float to fix conversions for ivas_td_binaural_open_fx + IF( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + FOR( i = 0; i < 4; i++ ) { - st_ivas->hSpar->hFbMixer->cldfb_cross_fade_q = Q_factor_arr(st_ivas->hSpar->hFbMixer->cldfb_cross_fade, 16); - floatToFixed_arr(st_ivas->hSpar->hFbMixer->cldfb_cross_fade, st_ivas->hSpar->hFbMixer->cldfb_cross_fade_fx, st_ivas->hSpar->hFbMixer->cldfb_cross_fade_q, 16); + st_ivas->hRenderConfig->directivity_fx[i * 3] = (Word16) floatToFixed( st_ivas->hRenderConfig->directivity[i * 3], 6 ); + st_ivas->hRenderConfig->directivity_fx[i * 3 + 1] = (Word16) floatToFixed( st_ivas->hRenderConfig->directivity[i * 3 + 1], 6 ); + st_ivas->hRenderConfig->directivity_fx[i * 3 + 2] = (Word16) floatToFixed( st_ivas->hRenderConfig->directivity[i * 3 + 2], 15 ); } } + // Float to fix conversions for ivas_cldfb_dec_reconfig_fx + IF( st_ivas->hSpar ) + { + st_ivas->hSpar->hFbMixer->cldfb_cross_fade_q = Q_factor_arr( st_ivas->hSpar->hFbMixer->cldfb_cross_fade, 16 ); + floatToFixed_arr( st_ivas->hSpar->hFbMixer->cldfb_cross_fade, st_ivas->hSpar->hFbMixer->cldfb_cross_fade_fx, st_ivas->hSpar->hFbMixer->cldfb_cross_fade_q, 16 ); + } + } - IF(EQ_16(is_DTXrate(ivas_total_brate), 0) && st_ivas->ivas_format == MASA_ISM_FORMAT && GT_16(st_ivas->ini_frame, 0) && (GT_32(ivas_total_brate, IVAS_SID_5k2) && NE_32(ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate)) && EQ_16(st_ivas->ini_active_frame, 0)) { - IF(st_ivas->ism_mode == ISM_MASA_MODE_DISC) - { - FOR(i = 0; i < 4; i++) - { - st_ivas->hRenderConfig->directivity_fx[i * 3] = (Word16)floatToFixed(st_ivas->hRenderConfig->directivity[i * 3], 6); - st_ivas->hRenderConfig->directivity_fx[i * 3 + 1] = (Word16)floatToFixed(st_ivas->hRenderConfig->directivity[i * 3 + 1], 6); - st_ivas->hRenderConfig->directivity_fx[i * 3 + 2] = (Word16)floatToFixed(st_ivas->hRenderConfig->directivity[i * 3 + 2], 15); - } - } - // Float to fix conversions for ivas_cldfb_dec_reconfig_fx - IF(st_ivas->hSpar) + IF( EQ_16( is_DTXrate( ivas_total_brate ), 0 ) && st_ivas->ivas_format == MASA_ISM_FORMAT && GT_16( st_ivas->ini_frame, 0 ) && ( GT_32( ivas_total_brate, IVAS_SID_5k2 ) && NE_32( ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate ) ) && EQ_16( st_ivas->ini_active_frame, 0 ) ) + { + IF( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + FOR( i = 0; i < 4; i++ ) { - st_ivas->hSpar->hFbMixer->cldfb_cross_fade_q = Q_factor_arr(st_ivas->hSpar->hFbMixer->cldfb_cross_fade, 16); - floatToFixed_arr(st_ivas->hSpar->hFbMixer->cldfb_cross_fade, st_ivas->hSpar->hFbMixer->cldfb_cross_fade_fx, st_ivas->hSpar->hFbMixer->cldfb_cross_fade_q, 16); + st_ivas->hRenderConfig->directivity_fx[i * 3] = (Word16) floatToFixed( st_ivas->hRenderConfig->directivity[i * 3], 6 ); + st_ivas->hRenderConfig->directivity_fx[i * 3 + 1] = (Word16) floatToFixed( st_ivas->hRenderConfig->directivity[i * 3 + 1], 6 ); + st_ivas->hRenderConfig->directivity_fx[i * 3 + 2] = (Word16) floatToFixed( st_ivas->hRenderConfig->directivity[i * 3 + 2], 15 ); } } + // Float to fix conversions for ivas_cldfb_dec_reconfig_fx + IF( st_ivas->hSpar ) + { + st_ivas->hSpar->hFbMixer->cldfb_cross_fade_q = Q_factor_arr( st_ivas->hSpar->hFbMixer->cldfb_cross_fade, 16 ); + floatToFixed_arr( st_ivas->hSpar->hFbMixer->cldfb_cross_fade, st_ivas->hSpar->hFbMixer->cldfb_cross_fade_fx, st_ivas->hSpar->hFbMixer->cldfb_cross_fade_q, 16 ); + } + } - IF(EQ_16(is_DTXrate(ivas_total_brate), 0) && (st_ivas->ivas_format == MC_FORMAT)) { - IF (st_ivas->mc_mode == MC_MODE_PARAMMC) + IF( EQ_16( is_DTXrate( ivas_total_brate ), 0 ) && ( st_ivas->ivas_format == MC_FORMAT ) ) + { + IF( st_ivas->mc_mode == MC_MODE_PARAMMC ) { - IF (st_ivas->hParamMC) + IF( st_ivas->hParamMC ) { - IF (st_ivas->hParamMC->diff_proto_info) { - FOR(i = 0; i < st_ivas->hParamMC->diff_proto_info->num_protos_diff; i++) + IF( st_ivas->hParamMC->diff_proto_info ) + { + FOR( i = 0; i < st_ivas->hParamMC->diff_proto_info->num_protos_diff; i++ ) { - floatToFixed_arrL(st_ivas->hParamMC->diff_proto_info->proto_fac[i], st_ivas->hParamMC->diff_proto_info->proto_fac_fx[i], Q26, st_ivas->hParamMC->diff_proto_info->num_source_chan_diff[i]); + floatToFixed_arrL( st_ivas->hParamMC->diff_proto_info->proto_fac[i], st_ivas->hParamMC->diff_proto_info->proto_fac_fx[i], Q26, st_ivas->hParamMC->diff_proto_info->num_source_chan_diff[i] ); } } } @@ -1190,22 +1191,22 @@ static ivas_error IVAS_DEC_Setup( hDecoderConfig = st_ivas->hDecoderConfig; AUDIO_CONFIG output_config = hDecoderConfig->output_config; - IF((st_ivas->ivas_format == MC_FORMAT) && (st_ivas->mc_mode == MC_MODE_PARAMMC)) + IF( ( st_ivas->ivas_format == MC_FORMAT ) && ( st_ivas->mc_mode == MC_MODE_PARAMMC ) ) { - IF(output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM) + IF( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM ) { /*float2fix block: to be removed*/ - floatToFixed_arrL(st_ivas->hLsSetupCustom->ls_azimuth, st_ivas->hLsSetupCustom->ls_azimuth_fx, Q22, st_ivas->hLsSetupCustom->num_spk); - floatToFixed_arrL(st_ivas->hLsSetupCustom->ls_elevation, st_ivas->hLsSetupCustom->ls_elevation_fx, Q22, st_ivas->hLsSetupCustom->num_spk); + floatToFixed_arrL( st_ivas->hLsSetupCustom->ls_azimuth, st_ivas->hLsSetupCustom->ls_azimuth_fx, Q22, st_ivas->hLsSetupCustom->num_spk ); + floatToFixed_arrL( st_ivas->hLsSetupCustom->ls_elevation, st_ivas->hLsSetupCustom->ls_elevation_fx, Q22, st_ivas->hLsSetupCustom->num_spk ); } } - IF(output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM) + IF( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM ) { - FOR(Word16 ind = 0; ind < MAX_OUTPUT_CHANNELS; ind++) + FOR( Word16 ind = 0; ind < MAX_OUTPUT_CHANNELS; ind++ ) { - st_ivas->hLsSetupCustom->ls_azimuth_fx[ind] = (Word32)(st_ivas->hLsSetupCustom->ls_azimuth[ind] * (1 << 22)); - st_ivas->hLsSetupCustom->ls_elevation_fx[ind] = (Word32)(st_ivas->hLsSetupCustom->ls_elevation[ind] * (1 << 22)); + st_ivas->hLsSetupCustom->ls_azimuth_fx[ind] = (Word32) ( st_ivas->hLsSetupCustom->ls_azimuth[ind] * ( 1 << 22 ) ); + st_ivas->hLsSetupCustom->ls_elevation_fx[ind] = (Word32) ( st_ivas->hLsSetupCustom->ls_elevation[ind] * ( 1 << 22 ) ); } } #endif @@ -1214,17 +1215,18 @@ static ivas_error IVAS_DEC_Setup( return error; } #if 1 // fix to float - IF((st_ivas->ivas_format == MC_FORMAT) && (st_ivas->mc_mode == MC_MODE_PARAMMC)) { + IF( ( st_ivas->ivas_format == MC_FORMAT ) && ( st_ivas->mc_mode == MC_MODE_PARAMMC ) ) + { PARAM_MC_DEC_HANDLE hParamMC; hParamMC = st_ivas->hParamMC; Word16 nchan_out_transport, nchan_out_cov; MC_LS_SETUP mc_ls_setup; Word16 nchan_transport; - mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup(st_ivas->transport_config); - st_ivas->nchan_transport = ivas_param_mc_getNumTransportChannels(ivas_total_brate, mc_ls_setup); + mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup( st_ivas->transport_config ); + st_ivas->nchan_transport = ivas_param_mc_getNumTransportChannels( ivas_total_brate, mc_ls_setup ); nchan_transport = st_ivas->nchan_transport; nchan_out_transport = st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe; - IF(hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_COV || hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO) + IF( hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_COV || hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) { nchan_out_cov = st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe; move16(); @@ -1233,81 +1235,84 @@ static ivas_error IVAS_DEC_Setup( { nchan_out_cov = nchan_out_transport; } - IF(hParamMC) + IF( hParamMC ) { - fixedToFloat_arrL(hParamMC->h_output_synthesis_params.proto_matrix_fx, hParamMC->h_output_synthesis_params.proto_matrix, 26, nchan_transport * nchan_out_cov); - IF (st_ivas->hParamMC->diff_proto_info) { - FOR(i = 0; i < hParamMC->diff_proto_info->num_protos_diff; i++) + fixedToFloat_arrL( hParamMC->h_output_synthesis_params.proto_matrix_fx, hParamMC->h_output_synthesis_params.proto_matrix, 26, nchan_transport * nchan_out_cov ); + IF( st_ivas->hParamMC->diff_proto_info ) + { + FOR( i = 0; i < hParamMC->diff_proto_info->num_protos_diff; i++ ) { - fixedToFloat_arrL(hParamMC->diff_proto_info->proto_fac_fx[i], hParamMC->diff_proto_info->proto_fac[i], 26, hParamMC->diff_proto_info->num_source_chan_diff[i]); + fixedToFloat_arrL( hParamMC->diff_proto_info->proto_fac_fx[i], hParamMC->diff_proto_info->proto_fac[i], 26, hParamMC->diff_proto_info->num_source_chan_diff[i] ); } } - IF(hParamMC->hoa_encoder_fx) - fixedToFloat_arrL(hParamMC->hoa_encoder_fx, hParamMC->hoa_encoder, Q29, st_ivas->hTransSetup.nchan_out_woLFE * MAX_INTERN_CHANNELS); + IF( hParamMC->hoa_encoder_fx ) + fixedToFloat_arrL( hParamMC->hoa_encoder_fx, hParamMC->hoa_encoder, Q29, st_ivas->hTransSetup.nchan_out_woLFE * MAX_INTERN_CHANNELS ); } } - IF(EQ_16(is_DTXrate(ivas_total_brate), 0) && (!(EQ_16(st_ivas->ini_active_frame, 0) && NE_32(ivas_total_brate, FRAME_NO_DATA) && LT_32(ivas_total_brate, MASA_STEREO_MIN_BITRATE) && EQ_16(st_ivas->nCPE, 1))) && st_ivas->bit_stream[(ivas_total_brate / FRAMES_PER_SEC) - 1] && st_ivas->ivas_format == MASA_FORMAT && ((GT_32(ivas_total_brate, IVAS_SID_5k2) && NE_32(ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate)) || EQ_16(st_ivas->ini_active_frame, 0))) { - IF(EQ_16(st_ivas->ism_mode, ISM_MASA_MODE_DISC)) + IF( EQ_16( is_DTXrate( ivas_total_brate ), 0 ) && ( !( EQ_16( st_ivas->ini_active_frame, 0 ) && NE_32( ivas_total_brate, FRAME_NO_DATA ) && LT_32( ivas_total_brate, MASA_STEREO_MIN_BITRATE ) && EQ_16( st_ivas->nCPE, 1 ) ) ) && st_ivas->bit_stream[( ivas_total_brate / FRAMES_PER_SEC ) - 1] && st_ivas->ivas_format == MASA_FORMAT && ( ( GT_32( ivas_total_brate, IVAS_SID_5k2 ) && NE_32( ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate ) ) || EQ_16( st_ivas->ini_active_frame, 0 ) ) ) + { + IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) + { + Word16 nchan_rend = num_src; + IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) && NE_16( st_ivas->transport_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) { - Word16 nchan_rend = num_src; - IF(EQ_16(st_ivas->ivas_format, MC_FORMAT) && NE_16(st_ivas->transport_config, IVAS_AUDIO_CONFIG_LS_CUSTOM)) - { - nchan_rend--; /* Skip LFE channel -- added to the others */ - } - FOR(Word16 nS = 0; nS < nchan_rend; nS++) + nchan_rend--; /* Skip LFE channel -- added to the others */ + } + FOR( Word16 nS = 0; nS < nchan_rend; nS++ ) + { + TDREND_SRC_t *Src_p = st_ivas->hBinRendererTd->Sources[SrcInd[nS]]; + IF( Src_p->SrcSpatial_p != NULL ) { - TDREND_SRC_t *Src_p = st_ivas->hBinRendererTd->Sources[SrcInd[nS]]; - IF(Src_p->SrcSpatial_p != NULL) - { - Src_p->SrcSpatial_p->q_Pos_p = Q31; - } - TDREND_SRC_SPATIAL_t *SrcSpatial_p = st_ivas->hBinRendererTd->Sources[nS]->SrcSpatial_p; - SrcSpatial_p->q_Pos_p = Q31; + Src_p->SrcSpatial_p->q_Pos_p = Q31; } + TDREND_SRC_SPATIAL_t *SrcSpatial_p = st_ivas->hBinRendererTd->Sources[nS]->SrcSpatial_p; + SrcSpatial_p->q_Pos_p = Q31; } } + } - IF(EQ_16(is_DTXrate(ivas_total_brate), 0) && st_ivas->ivas_format == MASA_ISM_FORMAT && GT_16(st_ivas->ini_frame, 0) && (GT_32(ivas_total_brate, IVAS_SID_5k2) && NE_32(ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate)) && EQ_16(st_ivas->ini_active_frame, 0)) { - IF(EQ_16(st_ivas->ism_mode, ISM_MASA_MODE_DISC)) + IF( EQ_16( is_DTXrate( ivas_total_brate ), 0 ) && st_ivas->ivas_format == MASA_ISM_FORMAT && GT_16( st_ivas->ini_frame, 0 ) && ( GT_32( ivas_total_brate, IVAS_SID_5k2 ) && NE_32( ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate ) ) && EQ_16( st_ivas->ini_active_frame, 0 ) ) + { + IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) + { + Word16 nchan_rend = num_src; + IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) && NE_16( st_ivas->transport_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) + { + nchan_rend--; /* Skip LFE channel -- added to the others */ + } + FOR( Word16 nS = 0; nS < nchan_rend; nS++ ) { - Word16 nchan_rend = num_src; - IF(EQ_16(st_ivas->ivas_format, MC_FORMAT) && NE_16(st_ivas->transport_config, IVAS_AUDIO_CONFIG_LS_CUSTOM)) + TDREND_SRC_t *Src_p = st_ivas->hBinRendererTd->Sources[SrcInd[nS]]; + IF( Src_p->SrcSpatial_p != NULL ) { - nchan_rend--; /* Skip LFE channel -- added to the others */ - } - FOR(Word16 nS = 0; nS < nchan_rend; nS++) - { - TDREND_SRC_t *Src_p = st_ivas->hBinRendererTd->Sources[SrcInd[nS]]; - IF(Src_p->SrcSpatial_p != NULL) - { - Src_p->SrcSpatial_p->q_Pos_p = Q31; - } - TDREND_SRC_SPATIAL_t *SrcSpatial_p = st_ivas->hBinRendererTd->Sources[nS]->SrcSpatial_p; - SrcSpatial_p->q_Pos_p = Q31; + Src_p->SrcSpatial_p->q_Pos_p = Q31; } + TDREND_SRC_SPATIAL_t *SrcSpatial_p = st_ivas->hBinRendererTd->Sources[nS]->SrcSpatial_p; + SrcSpatial_p->q_Pos_p = Q31; } } + } - IF(EQ_16(is_DTXrate(ivas_total_brate), 0) && (st_ivas->ivas_format == MC_FORMAT)) { - IF (st_ivas->mc_mode == MC_MODE_PARAMMC) + IF( EQ_16( is_DTXrate( ivas_total_brate ), 0 ) && ( st_ivas->ivas_format == MC_FORMAT ) ) + { + IF( st_ivas->mc_mode == MC_MODE_PARAMMC ) { - IF (st_ivas->hParamMC) + IF( st_ivas->hParamMC ) { - fixedToFloat_arrL(st_ivas->hParamMC->h_output_synthesis_params.proto_matrix_fx, st_ivas->hParamMC->h_output_synthesis_params.proto_matrix, 26, st_ivas->hParamMC->h_output_synthesis_params.proto_matrix_len); - IF(st_ivas->hParamMC->diff_proto_info) - FOR(i = 0; i < st_ivas->hParamMC->diff_proto_info->num_protos_diff; i++) + fixedToFloat_arrL( st_ivas->hParamMC->h_output_synthesis_params.proto_matrix_fx, st_ivas->hParamMC->h_output_synthesis_params.proto_matrix, 26, st_ivas->hParamMC->h_output_synthesis_params.proto_matrix_len ); + IF( st_ivas->hParamMC->diff_proto_info ) + FOR( i = 0; i < st_ivas->hParamMC->diff_proto_info->num_protos_diff; i++ ) { - fixedToFloat_arrL(st_ivas->hParamMC->diff_proto_info->proto_fac_fx[i], st_ivas->hParamMC->diff_proto_info->proto_fac[i], 26, st_ivas->hParamMC->diff_proto_info->num_source_chan_diff[i]); + fixedToFloat_arrL( st_ivas->hParamMC->diff_proto_info->proto_fac_fx[i], st_ivas->hParamMC->diff_proto_info->proto_fac[i], 26, st_ivas->hParamMC->diff_proto_info->num_source_chan_diff[i] ); } - IF (st_ivas->hParamMC->hoa_encoder_fx) - fixedToFloat_arrL(st_ivas->hParamMC->hoa_encoder_fx, st_ivas->hParamMC->hoa_encoder, Q29, st_ivas->hTransSetup.nchan_out_woLFE * MAX_INTERN_CHANNELS); + IF( st_ivas->hParamMC->hoa_encoder_fx ) + fixedToFloat_arrL( st_ivas->hParamMC->hoa_encoder_fx, st_ivas->hParamMC->hoa_encoder, Q29, st_ivas->hTransSetup.nchan_out_woLFE * MAX_INTERN_CHANNELS ); } } } #endif - } *nTransportChannels = (UWord8) st_ivas->hTcBuffer->nchan_transport_jbm; @@ -1328,7 +1333,7 @@ static ivas_error IVAS_DEC_Setup( static ivas_error IVAS_DEC_GetTcSamples( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ float *pcmBuf, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels */ - Word32 *pcmBuf_fx, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels */ + Word32 *pcmBuf_fx, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels */ Word16 *nOutSamples /* o : number of samples per channel written to output buffer */ ) { @@ -1351,12 +1356,12 @@ static ivas_error IVAS_DEC_GetTcSamples( return error; } } - ELSE IF(EQ_16((Word16)hIvasDec->mode, IVAS_DEC_MODE_IVAS)) + ELSE IF( EQ_16( (Word16) hIvasDec->mode, IVAS_DEC_MODE_IVAS ) ) { /* run the main IVAS decoding routine */ /*------------------------flt 2 fix----------------------*/ Word16 l, n; - Decoder_State *st, **sts; /* used for bitstream handling */ + Decoder_State *st, **sts; /* used for bitstream handling */ MCT_DEC_HANDLE hMCT; Word16 ch, nCPE, cpe_id; nCPE = st_ivas->nCPE; @@ -1365,16 +1370,17 @@ static ivas_error IVAS_DEC_GetTcSamples( hMCT = st_ivas->hMCT; Word16 num_freq_bands = 0; /* Float to Fixed */ - IF(pcmBuf != NULL) + IF( pcmBuf != NULL ) { - floatToFixed_arrL(pcmBuf, pcmBuf_fx, 11, (Word16)(st_ivas->hTcBuffer->nchan_transport_jbm * st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC)); + floatToFixed_arrL( pcmBuf, pcmBuf_fx, 11, (Word16) ( st_ivas->hTcBuffer->nchan_transport_jbm * st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ) ); } - IF(EQ_16(st_ivas->hDecoderConfig->Opt_tsm, 0)) { - FOR( n = 0; n < ivas_get_nchan_buffers_dec_ivas_fx(st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate); n++) + IF( EQ_16( st_ivas->hDecoderConfig->Opt_tsm, 0 ) ) + { + FOR( n = 0; n < ivas_get_nchan_buffers_dec_ivas_fx( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); n++ ) { - set_zero(st_ivas->p_output_f[n], L_FRAME48k); - set32_fx(st_ivas->p_output_fx[n], 0, L_FRAME48k); + set_zero( st_ivas->p_output_f[n], L_FRAME48k ); + set32_fx( st_ivas->p_output_fx[n], 0, L_FRAME48k ); st_ivas->hTcBuffer->tc_fx[n] = st_ivas->p_output_fx[n]; } } @@ -1382,38 +1388,39 @@ static ivas_error IVAS_DEC_GetTcSamples( #if 1 CPE_DEC_HANDLE hCPE; - IF(((st_ivas->mc_mode == MC_MODE_PARAMUPMIX) || (st_ivas->mc_mode == MC_MODE_MCT) || st_ivas->ivas_format == SBA_ISM_FORMAT || (st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == MASA_FORMAT) || st_ivas->mc_mode == MC_MODE_PARAMMC) && (GT_16(st_ivas->nCPE, 1))) { + IF( ( ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) || ( st_ivas->mc_mode == MC_MODE_MCT ) || st_ivas->ivas_format == SBA_ISM_FORMAT || ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == MASA_FORMAT ) || st_ivas->mc_mode == MC_MODE_PARAMMC ) && ( GT_16( st_ivas->nCPE, 1 ) ) ) + { nCPE = st_ivas->nCPE; move16(); hMCT = st_ivas->hMCT; - FOR(cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++) + FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { hCPE = st_ivas->hCPE[cpe_id]; sts = hCPE->hCoreCoder; - FOR(n = 0; n < CPE_CHANNELS; n++) + FOR( n = 0; n < CPE_CHANNELS; n++ ) { st = hCPE->hCoreCoder[n]; - IF(sts[n]->mct_chan_mode != MCT_CHAN_MODE_IGNORE) + IF( sts[n]->mct_chan_mode != MCT_CHAN_MODE_IGNORE ) { // u8bit to 16bit - FOR(l = 0; l < IGF_START_MX; l++) + FOR( l = 0; l < IGF_START_MX; l++ ) { - sts[n]->hIGFDec->infoTCXNoise_evs[l] = (Word16)sts[n]->hIGFDec->infoTCXNoise[l]; + sts[n]->hIGFDec->infoTCXNoise_evs[l] = (Word16) sts[n]->hIGFDec->infoTCXNoise[l]; } } - IF(st->hTcxDec) - st->hTcxDec->conNoiseLevelIndex = st->hTcxDec->NoiseLevelIndex_bfi; - IF(st->hTcxDec) - st->hTcxDec->conCurrLevelIndex = st->hTcxDec->CurrLevelIndex_bfi; + IF( st->hTcxDec ) + st->hTcxDec->conNoiseLevelIndex = st->hTcxDec->NoiseLevelIndex_bfi; + IF( st->hTcxDec ) + st->hTcxDec->conCurrLevelIndex = st->hTcxDec->CurrLevelIndex_bfi; /*cldfb struct*/ /*------------------fix-to-fix-start---------------------*/ /*core_switching_post_dec*/ - IF(hCPE->hCoreCoder[n]->hHQ_core != NULL) + IF( hCPE->hCoreCoder[n]->hHQ_core != NULL ) { hCPE->hCoreCoder[n]->hHQ_core->Q_old_postdec = 0; hCPE->hCoreCoder[n]->hHQ_core->Q_old_wtda = 0; @@ -1422,41 +1429,42 @@ static ivas_error IVAS_DEC_GetTcSamples( } } - IF( NE_16( st_ivas->hDecoderConfig->Opt_tsm, 1) ) { + IF( NE_16( st_ivas->hDecoderConfig->Opt_tsm, 1 ) ) + { - IF (st_ivas->ivas_format == ISM_FORMAT) + IF( st_ivas->ivas_format == ISM_FORMAT ) { - IF (st_ivas->hSpatParamRendCom != NULL) + IF( st_ivas->hSpatParamRendCom != NULL ) { num_freq_bands = st_ivas->hSpatParamRendCom->num_freq_bands; } - FOR (Word16 lp = 0; lp < n_ch_cldfb_tmp; lp++) + FOR( Word16 lp = 0; lp < n_ch_cldfb_tmp; lp++ ) { - Word16 length = 15 * num_freq_bands * n_ch_cldfb_tmp + num_freq_bands * (n_ch_cldfb_tmp - 1) + st_ivas->cldfbAnaDec[lp]->no_channels; - FOR (Word16 i = 0; i < length; i++) + Word16 length = 15 * num_freq_bands * n_ch_cldfb_tmp + num_freq_bands * ( n_ch_cldfb_tmp - 1 ) + st_ivas->cldfbAnaDec[lp]->no_channels; + FOR( Word16 i = 0; i < length; i++ ) { st_ivas->hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx[i] = - floatToFixed(st_ivas->hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc[i], 6); + floatToFixed( st_ivas->hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc[i], 6 ); st_ivas->hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx[i] = - floatToFixed(st_ivas->hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc[i], 6); + floatToFixed( st_ivas->hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc[i], 6 ); } } } - ELSE IF(st_ivas->ivas_format == MC_FORMAT) + ELSE IF( st_ivas->ivas_format == MC_FORMAT ) { - IF(st_ivas->hParamMC != NULL) + IF( st_ivas->hParamMC != NULL ) { num_freq_bands = st_ivas->hParamMC->num_freq_bands; } - FOR(Word16 lp = 0; lp < n_ch_cldfb_tmp; lp++) + FOR( Word16 lp = 0; lp < n_ch_cldfb_tmp; lp++ ) { - Word16 length = 15 * num_freq_bands * n_ch_cldfb_tmp + num_freq_bands * (n_ch_cldfb_tmp - 1) + st_ivas->cldfbAnaDec[lp]->no_channels; - FOR(Word16 lp2 = 0; lp2 < length; lp2++) + Word16 length = 15 * num_freq_bands * n_ch_cldfb_tmp + num_freq_bands * ( n_ch_cldfb_tmp - 1 ) + st_ivas->cldfbAnaDec[lp]->no_channels; + FOR( Word16 lp2 = 0; lp2 < length; lp2++ ) { st_ivas->hParamMC->Cldfb_RealBuffer_tc_fx[lp2] = - floatToFixed(st_ivas->hParamMC->Cldfb_RealBuffer_tc[lp2], 6); + floatToFixed( st_ivas->hParamMC->Cldfb_RealBuffer_tc[lp2], 6 ); st_ivas->hParamMC->Cldfb_ImagBuffer_tc_fx[lp2] = - floatToFixed(st_ivas->hParamMC->Cldfb_ImagBuffer_tc[lp2], 6); + floatToFixed( st_ivas->hParamMC->Cldfb_ImagBuffer_tc[lp2], 6 ); } } } @@ -1464,60 +1472,61 @@ static ivas_error IVAS_DEC_GetTcSamples( #endif /* Function call: ivas_jbm_dec_tc function */ - IF((error = ivas_jbm_dec_tc_fx(st_ivas, pcmBuf_fx)) != IVAS_ERR_OK) + IF( ( error = ivas_jbm_dec_tc_fx( st_ivas, pcmBuf_fx ) ) != IVAS_ERR_OK ) { return error; } #if 1 /* Fixed to Float */ - IF(pcmBuf != NULL) + IF( pcmBuf != NULL ) { - fixedToFloat_arrL(pcmBuf_fx, pcmBuf, 11, (Word16)(st_ivas->hTcBuffer->nchan_transport_jbm * st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC)); + fixedToFloat_arrL( pcmBuf_fx, pcmBuf, 11, (Word16) ( st_ivas->hTcBuffer->nchan_transport_jbm * st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ) ); } - FOR(n = 0; n < MAX_TRANSPORT_CHANNELS; n++) { - IF(st_ivas->p_output_f[n] != NULL) + FOR( n = 0; n < MAX_TRANSPORT_CHANNELS; n++ ) + { + IF( st_ivas->p_output_f[n] != NULL ) { - fixedToFloat_arrL(st_ivas->p_output_fx[n], st_ivas->p_output_f[n], 11, L_FRAME48k); + fixedToFloat_arrL( st_ivas->p_output_fx[n], st_ivas->p_output_f[n], 11, L_FRAME48k ); } } IF( NE_16( st_ivas->hDecoderConfig->Opt_tsm, 1 ) ) { - IF(st_ivas->ivas_format == ISM_FORMAT) + IF( st_ivas->ivas_format == ISM_FORMAT ) { - IF(st_ivas->hSpatParamRendCom != NULL) + IF( st_ivas->hSpatParamRendCom != NULL ) { num_freq_bands = st_ivas->hSpatParamRendCom->num_freq_bands; } - FOR(Word16 lp = 0; lp < n_ch_cldfb_tmp; lp++) + FOR( Word16 lp = 0; lp < n_ch_cldfb_tmp; lp++ ) { - Word16 length = 15 * num_freq_bands * n_ch_cldfb_tmp + num_freq_bands * (n_ch_cldfb_tmp - 1) + st_ivas->cldfbAnaDec[lp]->no_channels; - FOR(Word16 lp2 = 0; lp2 < length; lp2++) + Word16 length = 15 * num_freq_bands * n_ch_cldfb_tmp + num_freq_bands * ( n_ch_cldfb_tmp - 1 ) + st_ivas->cldfbAnaDec[lp]->no_channels; + FOR( Word16 lp2 = 0; lp2 < length; lp2++ ) { st_ivas->hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc[lp2] = - fixedToFloat(st_ivas->hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx[lp2], 6); + fixedToFloat( st_ivas->hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx[lp2], 6 ); st_ivas->hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc[lp2] = - fixedToFloat(st_ivas->hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx[lp2], 6); + fixedToFloat( st_ivas->hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx[lp2], 6 ); } } } - ELSE IF(st_ivas->ivas_format == MC_FORMAT) + ELSE IF( st_ivas->ivas_format == MC_FORMAT ) { - IF(st_ivas->hParamMC != NULL) + IF( st_ivas->hParamMC != NULL ) { num_freq_bands = st_ivas->hParamMC->num_freq_bands; } - FOR(Word16 lp = 0; lp < n_ch_cldfb_tmp; lp++) + FOR( Word16 lp = 0; lp < n_ch_cldfb_tmp; lp++ ) { - Word16 length = 15 * num_freq_bands * n_ch_cldfb_tmp + num_freq_bands * (n_ch_cldfb_tmp - 1) + st_ivas->cldfbAnaDec[lp]->no_channels; - FOR(Word16 lp2 = 0; lp2 < length; lp2++) + Word16 length = 15 * num_freq_bands * n_ch_cldfb_tmp + num_freq_bands * ( n_ch_cldfb_tmp - 1 ) + st_ivas->cldfbAnaDec[lp]->no_channels; + FOR( Word16 lp2 = 0; lp2 < length; lp2++ ) { st_ivas->hParamMC->Cldfb_RealBuffer_tc[lp2] = - fixedToFloat(st_ivas->hParamMC->Cldfb_RealBuffer_tc_fx[lp2], 6); + fixedToFloat( st_ivas->hParamMC->Cldfb_RealBuffer_tc_fx[lp2], 6 ); st_ivas->hParamMC->Cldfb_ImagBuffer_tc[lp2] = - fixedToFloat(st_ivas->hParamMC->Cldfb_ImagBuffer_tc_fx[lp2], 6); + fixedToFloat( st_ivas->hParamMC->Cldfb_ImagBuffer_tc_fx[lp2], 6 ); } } } @@ -1526,49 +1535,50 @@ static ivas_error IVAS_DEC_GetTcSamples( hIvasDec->isInitialized = true; /* Initialization done in ivas_dec() */ - IF(((st_ivas->mc_mode == MC_MODE_PARAMUPMIX) || (st_ivas->mc_mode == MC_MODE_MCT) || st_ivas->ivas_format == SBA_ISM_FORMAT || (st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == MASA_FORMAT) || st_ivas->mc_mode == MC_MODE_PARAMMC) && (GT_16(st_ivas->nCPE, 1))) { - FOR(cpe_id = 0; cpe_id < nCPE; cpe_id++) + IF( ( ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) || ( st_ivas->mc_mode == MC_MODE_MCT ) || st_ivas->ivas_format == SBA_ISM_FORMAT || ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == MASA_FORMAT ) || st_ivas->mc_mode == MC_MODE_PARAMMC ) && ( GT_16( st_ivas->nCPE, 1 ) ) ) + { + FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) { hCPE = st_ivas->hCPE[cpe_id]; sts = hCPE->hCoreCoder; - FOR(ch = 0; ch < CPE_CHANNELS; ch++) + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { st = hCPE->hCoreCoder[ch]; - IF(sts[ch]->mct_chan_mode != MCT_CHAN_MODE_IGNORE) + IF( sts[ch]->mct_chan_mode != MCT_CHAN_MODE_IGNORE ) { // 16bit to u8bit - FOR(l = 0; l < IGF_START_MX; l++) + FOR( l = 0; l < IGF_START_MX; l++ ) { sts[ch]->hIGFDec->infoTCXNoise[l] = (UWord8) sts[ch]->hIGFDec->infoTCXNoise_evs[l]; } } } - FOR(n = 0; n < 2; n++) + FOR( n = 0; n < 2; n++ ) { st = hCPE->hCoreCoder[n]; sts = hCPE->hCoreCoder; /*-------------------cldfb-start-------------------------*/ /*note : cldfb_size here signifies the original size which was assigned to cldfb_state_fx buffer not its current size*/ - IF (sts[n]->cldfbAna != NULL) + IF( sts[n]->cldfbAna != NULL ) { - scale_sig32(sts[n]->cldfbAna->cldfb_state_fx, sts[n]->cldfbAna->cldfb_size, sub(Q11, Q10) ); + scale_sig32( sts[n]->cldfbAna->cldfb_state_fx, sts[n]->cldfbAna->cldfb_size, sub( Q11, Q10 ) ); sts[n]->cldfbAna->Q_cldfb_state = Q11; } - IF (sts[n]->cldfbSyn != NULL) + IF( sts[n]->cldfbSyn != NULL ) { - scale_sig32(sts[n]->cldfbSyn->cldfb_state_fx, sts[n]->cldfbSyn->cldfb_size, sub(Q11, Q4) ); + scale_sig32( sts[n]->cldfbSyn->cldfb_state_fx, sts[n]->cldfbSyn->cldfb_size, sub( Q11, Q4 ) ); sts[n]->cldfbSyn->Q_cldfb_state = Q11; } /*-------------------cldfb-end---------------------------*/ /* reset WB BWE buffers */ - IF(NE_16(sts[n]->last_extl, WB_BWE) && EQ_16(sts[n]->extl, WB_BWE) && sts[n]->hBWE_FD != NULL) + IF( NE_16( sts[n]->last_extl, WB_BWE ) && EQ_16( sts[n]->extl, WB_BWE ) && sts[n]->hBWE_FD != NULL ) { - IF(NE_16(sts[n]->last_extl, SWB_BWE) && NE_16(sts[n]->last_extl, FB_BWE)) + IF( NE_16( sts[n]->last_extl, SWB_BWE ) && NE_16( sts[n]->last_extl, FB_BWE ) ) { sts[n]->hBWE_FD->prev_mode = sts[n]->hBWE_FD->prev_mode; } @@ -1579,19 +1589,19 @@ static ivas_error IVAS_DEC_GetTcSamples( } - IF(st_ivas->hCPE[0]->hCoreCoder[0]->igf) + IF( st_ivas->hCPE[0]->hCoreCoder[0]->igf ) { - IF(!hMCT->currBlockDataCnt) + IF( !hMCT->currBlockDataCnt ) { - FOR(cpe_id = 0; cpe_id < nCPE; cpe_id++) + FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) { - FOR(ch = 0; ch < CPE_CHANNELS; ch++) + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { - IF(st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->igf) + IF( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->igf ) { - FOR(l = 0; l < IGF_START_MX; l++) + FOR( l = 0; l < IGF_START_MX; l++ ) { - st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hIGFDec->infoTCXNoise[l] = (UWord8)st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hIGFDec->infoTCXNoise_evs[l]; + st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hIGFDec->infoTCXNoise[l] = (UWord8) st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hIGFDec->infoTCXNoise_evs[l]; } } } @@ -1600,7 +1610,6 @@ static ivas_error IVAS_DEC_GetTcSamples( } } #endif // fixed to float - } IF( hIvasDec->hasBeenFedFirstGoodFrame ) { @@ -1854,25 +1863,25 @@ ivas_error IVAS_DEC_GetObjectMetadata( Decoder_Struct *st_ivas; ISM_METADATA_HANDLE hIsmMeta; - IF(hIvasDec == NULL || hIvasDec->st_ivas == NULL) + IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } st_ivas = hIvasDec->st_ivas; - IF(NE_16((Word16)st_ivas->ivas_format, ISM_FORMAT) && NE_16((Word16)st_ivas->ivas_format, MASA_ISM_FORMAT) && NE_16((Word16)st_ivas->ivas_format, SBA_ISM_FORMAT)) + IF( NE_16( (Word16) st_ivas->ivas_format, ISM_FORMAT ) && NE_16( (Word16) st_ivas->ivas_format, MASA_ISM_FORMAT ) && NE_16( (Word16) st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { return IVAS_ERR_WRONG_MODE; } - IF(GE_16(objectIdx, st_ivas->nchan_ism)) + IF( GE_16( objectIdx, st_ivas->nchan_ism ) ) { return IVAS_ERR_INVALID_INDEX; } hIsmMeta = st_ivas->hIsmMetaData[objectIdx]; - IF(hIsmMeta == NULL || zero_flag) + IF( hIsmMeta == NULL || zero_flag ) { metadata->azimuth_fx = 0; metadata->elevation_fx = 0; @@ -1940,11 +1949,11 @@ ivas_error IVAS_DEC_GetObjectMetadata( ELSE { #ifdef IVAS_FLOAT_FIXED - metadata->azimuth = fixedToFloat(hIsmMeta->azimuth_fx, Q22); - metadata->elevation = fixedToFloat(hIsmMeta->elevation_fx, Q22); - metadata->radius = fixedToFloat(hIsmMeta->radius_fx, Q9); - metadata->yaw = fixedToFloat(hIsmMeta->yaw_fx, Q22); - metadata->pitch = fixedToFloat(hIsmMeta->pitch_fx, Q22); + metadata->azimuth = fixedToFloat( hIsmMeta->azimuth_fx, Q22 ); + metadata->elevation = fixedToFloat( hIsmMeta->elevation_fx, Q22 ); + metadata->radius = fixedToFloat( hIsmMeta->radius_fx, Q9 ); + metadata->yaw = fixedToFloat( hIsmMeta->yaw_fx, Q22 ); + metadata->pitch = fixedToFloat( hIsmMeta->pitch_fx, Q22 ); #else metadata->azimuth = hIsmMeta->azimuth; metadata->elevation = hIsmMeta->elevation; @@ -1958,8 +1967,8 @@ ivas_error IVAS_DEC_GetObjectMetadata( } #ifdef IVAS_FLOAT_FIXED - metadata->azimuth_fx = floatToFixed(metadata->azimuth,Q22); - metadata->elevation_fx = floatToFixed(metadata->elevation,Q22); + metadata->azimuth_fx = floatToFixed( metadata->azimuth, Q22 ); + metadata->elevation_fx = floatToFixed( metadata->elevation, Q22 ); #endif return IVAS_ERR_OK; } @@ -2061,7 +2070,7 @@ ivas_error IVAS_DEC_FeedHeadTrackData( { return error; } -#endif +#endif hHeadTrackData->Pos[subframe_idx].x = Pos.x; hHeadTrackData->Pos[subframe_idx].y = Pos.y; @@ -2194,20 +2203,20 @@ ivas_error IVAS_DEC_FeedExternalOrientationData( #ifdef IVAS_FLOAT_FIXED IVAS_QUATERNION orientation_fx = { 0 }; orientation_fx.q_fact = Q29; - orientation_fx.w_fx = float_to_fix(orientation.w, orientation_fx.q_fact); - orientation_fx.x_fx = float_to_fix(orientation.x, orientation_fx.q_fact); - orientation_fx.y_fx = float_to_fix(orientation.y, orientation_fx.q_fact); - orientation_fx.z_fx = float_to_fix(orientation.z, orientation_fx.q_fact); + orientation_fx.w_fx = float_to_fix( orientation.w, orientation_fx.q_fact ); + orientation_fx.x_fx = float_to_fix( orientation.x, orientation_fx.q_fact ); + orientation_fx.y_fx = float_to_fix( orientation.y, orientation_fx.q_fact ); + orientation_fx.z_fx = float_to_fix( orientation.z, orientation_fx.q_fact ); /* Move external orientation data to the decoder handle (invert orientations) */ - QuaternionInverse_fx(orientation_fx, &hExternalOrientationData->Quaternions[subframe_idx]); - hExternalOrientationData->Quaternions[subframe_idx].w = me2f(hExternalOrientationData->Quaternions[subframe_idx].w_fx, - 31 - hExternalOrientationData->Quaternions[subframe_idx].q_fact); - hExternalOrientationData->Quaternions[subframe_idx].x = me2f(hExternalOrientationData->Quaternions[subframe_idx].x_fx, - 31 - hExternalOrientationData->Quaternions[subframe_idx].q_fact); - hExternalOrientationData->Quaternions[subframe_idx].y = me2f(hExternalOrientationData->Quaternions[subframe_idx].y_fx, - 31 - hExternalOrientationData->Quaternions[subframe_idx].q_fact); - hExternalOrientationData->Quaternions[subframe_idx].z = me2f(hExternalOrientationData->Quaternions[subframe_idx].z_fx, - 31 - hExternalOrientationData->Quaternions[subframe_idx].q_fact); + QuaternionInverse_fx( orientation_fx, &hExternalOrientationData->Quaternions[subframe_idx] ); + hExternalOrientationData->Quaternions[subframe_idx].w = me2f( hExternalOrientationData->Quaternions[subframe_idx].w_fx, + 31 - hExternalOrientationData->Quaternions[subframe_idx].q_fact ); + hExternalOrientationData->Quaternions[subframe_idx].x = me2f( hExternalOrientationData->Quaternions[subframe_idx].x_fx, + 31 - hExternalOrientationData->Quaternions[subframe_idx].q_fact ); + hExternalOrientationData->Quaternions[subframe_idx].y = me2f( hExternalOrientationData->Quaternions[subframe_idx].y_fx, + 31 - hExternalOrientationData->Quaternions[subframe_idx].q_fact ); + hExternalOrientationData->Quaternions[subframe_idx].z = me2f( hExternalOrientationData->Quaternions[subframe_idx].z_fx, + 31 - hExternalOrientationData->Quaternions[subframe_idx].q_fact ); #else /* Move external orientation data to the decoder handle (invert orientations) */ QuaternionInverse( orientation, &hExternalOrientationData->Quaternions[subframe_idx] ); @@ -2385,14 +2394,14 @@ static ivas_error copyRendererConfigStruct( hRCout->roomAcoustics.acousticPreDelay_fx = hRCin->roomAcoustics.acousticPreDelay_fx; hRCout->roomAcoustics.inputPreDelay_fx = hRCin->roomAcoustics.inputPreDelay_fx; - Copy32( hRCin->roomAcoustics.pFc_input_fx, hRCout->roomAcoustics.pFc_input_fx, CLDFB_NO_CHANNELS_MAX); - Copy32(hRCin->roomAcoustics.pAcoustic_rt60_fx, hRCout->roomAcoustics.pAcoustic_rt60_fx, CLDFB_NO_CHANNELS_MAX); - Copy32(hRCin->roomAcoustics.pAcoustic_dsr_fx, hRCout->roomAcoustics.pAcoustic_dsr_fx, CLDFB_NO_CHANNELS_MAX); - Copy(hRCin->directivity_fx, hRCout->directivity_fx, 3 * MAX_NUM_OBJECTS ); + Copy32( hRCin->roomAcoustics.pFc_input_fx, hRCout->roomAcoustics.pFc_input_fx, CLDFB_NO_CHANNELS_MAX ); + Copy32( hRCin->roomAcoustics.pAcoustic_rt60_fx, hRCout->roomAcoustics.pAcoustic_rt60_fx, CLDFB_NO_CHANNELS_MAX ); + Copy32( hRCin->roomAcoustics.pAcoustic_dsr_fx, hRCout->roomAcoustics.pAcoustic_dsr_fx, CLDFB_NO_CHANNELS_MAX ); + Copy( hRCin->directivity_fx, hRCout->directivity_fx, 3 * MAX_NUM_OBJECTS ); hRCout->roomAcoustics.use_er = hRCin->roomAcoustics.use_er; hRCout->roomAcoustics.lowComplexity = hRCin->roomAcoustics.lowComplexity; #if 1 // To be removed - mvr2r(hRCin->directivity, hRCout->directivity, 3 * MAX_NUM_OBJECTS); + mvr2r( hRCin->directivity, hRCout->directivity, 3 * MAX_NUM_OBJECTS ); #endif return IVAS_ERR_OK; @@ -2427,7 +2436,7 @@ ivas_error IVAS_DEC_GetDefaultRenderConfig( RENDER_CONFIG_HANDLE hRCin = &RCin; ivas_error error; #ifdef IVAS_FLOAT_FIXED - IF((error = ivas_render_config_init_from_rom_fx(&hRCin)) != IVAS_ERR_OK) + IF( ( error = ivas_render_config_init_from_rom_fx( &hRCin ) ) != IVAS_ERR_OK ) { return error; } @@ -2485,7 +2494,7 @@ ivas_error IVAS_DEC_FeedRenderConfig( Copy( renderConfig.directivity_fx, hRenderConfig->directivity_fx, 3 * MAX_NUM_OBJECTS ); #if 1 // To be removed - mvr2r(renderConfig.directivity, hRenderConfig->directivity, 3 * MAX_NUM_OBJECTS); + mvr2r( renderConfig.directivity, hRenderConfig->directivity, 3 * MAX_NUM_OBJECTS ); #endif return IVAS_ERR_OK; @@ -2851,7 +2860,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples( } #ifdef IVAS_FLOAT_FIXED - IF ( GT_32( maxScaling, 20 ) ) + IF( GT_32( maxScaling, 20 ) ) { maxScaling = 20; move16(); @@ -3567,9 +3576,9 @@ static ivas_error evs_dec_main( IF( !st_ivas->hDecoderConfig->Opt_tsm ) { #ifdef IVAS_FLOAT_FIXED - for(int i = 0; i < st_ivas->hDecoderConfig->nchan_out; i++) + for ( int i = 0; i < st_ivas->hDecoderConfig->nchan_out; i++ ) { - floatToFixed_arrL(p_output[i], p_output_fx[i], Q11, nOutSamples); + floatToFixed_arrL( p_output[i], p_output_fx[i], Q11, nOutSamples ); } ivas_jbm_dec_copy_tc_no_tsm_fx( st_ivas, p_output_fx, nOutSamples ); #else diff --git a/lib_dec/lp_exc_d_fx.c b/lib_dec/lp_exc_d_fx.c index bc708244b..0eb99d413 100644 --- a/lib_dec/lp_exc_d_fx.c +++ b/lib_dec/lp_exc_d_fx.c @@ -3,10 +3,10 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ /*======================================================================*/ /* FUNCTION : lp_filt_exc_dec_fx() */ @@ -34,14 +34,13 @@ /*=======================================================================*/ void lp_filt_exc_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 codec_mode, /* i : coder mode */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 L_subfr, /* i : subframe size */ - const Word16 L_frame, /* i : frame size */ - Word16 lp_flag, /* i : operation mode signaling */ - Word16 *exc -) + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 codec_mode, /* i : coder mode */ + const Word16 i_subfr, /* i : subframe index */ + const Word16 L_subfr, /* i : subframe size */ + const Word16 L_frame, /* i : frame size */ + Word16 lp_flag, /* i : operation mode signaling */ + Word16 *exc ) { Word16 i, fac_n, fac_m; @@ -51,37 +50,37 @@ void lp_filt_exc_dec_fx( /*-----------------------------------------------------------------* * Select LP filtering of the adaptive excitation *-----------------------------------------------------------------*/ - IF(EQ_16(codec_mode, MODE1)) + IF( EQ_16( codec_mode, MODE1 ) ) { - IF(EQ_16(lp_flag, NORMAL_OPERATION)) + IF( EQ_16( lp_flag, NORMAL_OPERATION ) ) { - lp_flag = (Word16)get_next_indice(st_fx, 1); + lp_flag = (Word16) get_next_indice( st_fx, 1 ); } } - IF ( EQ_16(lp_flag, LOW_PASS)) + IF( EQ_16( lp_flag, LOW_PASS ) ) { /* pointer positioning to avoid doing it inside the loop */ test(); - IF(codec_mode ==MODE2 && L_frame==L_FRAME16k) + IF( codec_mode == MODE2 && L_frame == L_FRAME16k ) { - fac_n = 6881/*0.21f Q15*/; - fac_m = 19005/*0.58f Q15*/; + fac_n = 6881 /*0.21f Q15*/; + fac_m = 19005 /*0.58f Q15*/; } ELSE { - fac_n = 5898/*0.18f Q15*/; - fac_m = 20972/*0.64f Q15*/; + fac_n = 5898 /*0.18f Q15*/; + fac_m = 20972 /*0.64f Q15*/; } - FOR (i=0; itdm_LRTD_flag == 0 && st->idchan == 1 && tdm_lsfQ_PCh != NULL ) { #ifdef IVAS_FLOAT_FIXED - Word16 tdm_lsfQ_PCh_fx[M]; - Word16 pred3_fx[M]; - for ( i = 0; i < M; i++) - { - tdm_lsfQ_PCh_fx[i] = (Word16)((tdm_lsfQ_PCh[i]) * 2.56f); - pred3_fx[i] = (Word16)((pred3[i]) * 2.56f); - } - - tdm_SCh_LSF_intra_pred_fx(st->element_brate, tdm_lsfQ_PCh_fx, pred3_fx); - - for (i = 0; i < M; i++) - { - pred3[i] = (pred3_fx[i]) / 2.56f; - } + Word16 tdm_lsfQ_PCh_fx[M]; + Word16 pred3_fx[M]; + for ( i = 0; i < M; i++ ) + { + tdm_lsfQ_PCh_fx[i] = (Word16) ( ( tdm_lsfQ_PCh[i] ) * 2.56f ); + pred3_fx[i] = (Word16) ( ( pred3[i] ) * 2.56f ); + } + + tdm_SCh_LSF_intra_pred_fx( st->element_brate, tdm_lsfQ_PCh_fx, pred3_fx ); + + for ( i = 0; i < M; i++ ) + { + pred3[i] = ( pred3_fx[i] ) / 2.56f; + } #else tdm_SCh_LSF_intra_pred( st->element_brate, tdm_lsfQ_PCh, pred3 ); #endif diff --git a/lib_dec/lsf_dec_fx.c b/lib_dec/lsf_dec_fx.c index 9fa9484c0..407ea463f 100644 --- a/lib_dec/lsf_dec_fx.c +++ b/lib_dec/lsf_dec_fx.c @@ -3,11 +3,11 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ #ifdef LSF_RE_USE_SECONDARY_CHANNEL #include "ivas_prot.h" #include "ivas_rom_com.h" @@ -15,7 +15,7 @@ /*-------------------------------------------------------------------* * Local functions *-------------------------------------------------------------------*/ -static void dqlsf_CNG_fx(Decoder_State* st_fx, Word16* lsf_q); +static void dqlsf_CNG_fx( Decoder_State *st_fx, Word16 *lsf_q ); /*--------------------------------------------------------------------------------------* * dqlsf_CNG_fx() @@ -30,40 +30,42 @@ static void dqlsf_CNG_fx(Decoder_State* st_fx, Word16* lsf_q); ----------------------------------------------------------------------------------------*/ static void dqlsf_CNG_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *lsf_q /* o : decoded LSFs */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *lsf_q /* o : decoded LSFs */ ) { Word16 indice[4]; Word16 ber_flag; - indice[0] = (Word16)get_next_indice( st_fx, 4 ); + indice[0] = (Word16) get_next_indice( st_fx, 4 ); move16(); - indice[1] = (Word16)get_next_indice( st_fx, LEN_INDICE ); + indice[1] = (Word16) get_next_indice( st_fx, LEN_INDICE ); move16(); - indice[2] = (Word16)get_next_indice( st_fx, LSF_BITS_CNG - 4 - LEN_INDICE ); + indice[2] = (Word16) get_next_indice( st_fx, LSF_BITS_CNG - 4 - LEN_INDICE ); move16(); /* deindex_lvq_cng decoder does not need to know the sampling rate, the sampling rate data is embedded inside the LSF coefficients */ - IF (EQ_16(st_fx->element_mode, EVS_MONO)) { + IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) + { ber_flag = - deindex_lvq_cng_fx(&indice[1], lsf_q, indice[0], LSF_BITS_CNG - 4, &st_fx->offset_scale1_fx[0][0], &st_fx->offset_scale2_fx[0][0], &st_fx->no_scales_fx[0][0]); + deindex_lvq_cng_fx( &indice[1], lsf_q, indice[0], LSF_BITS_CNG - 4, &st_fx->offset_scale1_fx[0][0], &st_fx->offset_scale2_fx[0][0], &st_fx->no_scales_fx[0][0] ); } - ELSE { + ELSE + { ber_flag = - deindex_lvq_cng_ivas_fx(&indice[1], lsf_q, indice[0], LSF_BITS_CNG - 4); + deindex_lvq_cng_ivas_fx( &indice[1], lsf_q, indice[0], LSF_BITS_CNG - 4 ); } - st_fx->BER_detect = s_or(ber_flag, st_fx->BER_detect); + st_fx->BER_detect = s_or( ber_flag, st_fx->BER_detect ); /* The sampling frequency of the LP-CNG frame can be determined by checking the value of the highest order LSF coefficient (last coefficient). If the last decoded LSF coefficient is larger than 6350 the decoded frame is WB2 with sampling rate of 16 kHz otherwise it is sampled at 12.8kHz and contains either NB or WB LSF data. */ - Vr_add(lsf_q, &CNG_SN1_fx[indice[0] * M], lsf_q, M); + Vr_add( lsf_q, &CNG_SN1_fx[indice[0] * M], lsf_q, M ); test(); test(); test(); - IF ( ((EQ_16(st_fx->L_frame, L_FRAME16k))&&(LE_16(lsf_q[M-1],WB_LIMIT_LSF_FX)))||((LT_16(st_fx->L_frame,L_FRAME16k))&&(GT_16(lsf_q[M-1],WB_LIMIT_LSF_FX)))) + IF( ( ( EQ_16( st_fx->L_frame, L_FRAME16k ) ) && ( LE_16( lsf_q[M - 1], WB_LIMIT_LSF_FX ) ) ) || ( ( LT_16( st_fx->L_frame, L_FRAME16k ) ) && ( GT_16( lsf_q[M - 1], WB_LIMIT_LSF_FX ) ) ) ) { st_fx->BER_detect = 1; move16(); @@ -100,16 +102,17 @@ static void dqlsf_CNG_fx( /* _ None */ /*===========================================================================*/ void lsf_dec_fx( - Decoder_State *st_fx, /* i/o: State structure */ - const Word16 tc_subfr, /* i : TC subframe index */ - Word16 *Aq, /* o : quantized A(z) for 4 subframes */ - Word16 *LSF_Q_prediction, /* o : LSF prediction mode */ - Word16 *lsf_new, /* o : de-quantized LSF vector */ - Word16 *lsp_new, /* o : de-quantized LSP vector */ - Word16 *lsp_mid, /* o : de-quantized mid-frame LSP vector */ + Decoder_State *st_fx, /* i/o: State structure */ + const Word16 tc_subfr, /* i : TC subframe index */ + Word16 *Aq, /* o : quantized A(z) for 4 subframes */ + Word16 *LSF_Q_prediction, /* o : LSF prediction mode */ + Word16 *lsf_new, /* o : de-quantized LSF vector */ + Word16 *lsp_new, /* o : de-quantized LSP vector */ + Word16 *lsp_mid, /* o : de-quantized mid-frame LSP vector */ const Word16 tdm_low_rate_mode /* i : secondary channel low rate mode flag */ #ifdef LSF_RE_USE_SECONDARY_CHANNEL - ,const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ + , + const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ #endif ) { @@ -118,31 +121,32 @@ void lsf_dec_fx( Word16 param_lpc[NPRM_LPC_NEW]; Word32 L_tmp; Word16 nBits = 0; - Word16 tmp_old[M+1], tmp_new[M+1]; + Word16 tmp_old[M + 1], tmp_new[M + 1]; Word16 enr_old = 0, enr_new = 0; Word16 lsf_diff, coder_type; #ifdef REMOVE_IVAS_UNUSED_PARAMETERS_WARNING - (void)(tdm_low_rate_mode); + (void) ( tdm_low_rate_mode ); #endif /* initialize */ coder_type = st_fx->coder_type; - if ( EQ_32(st_fx->core_brate, SID_2k40) ) + if ( EQ_32( st_fx->core_brate, SID_2k40 ) ) { coder_type = INACTIVE; move16(); } test(); - if ( EQ_16(coder_type, AUDIO) && GT_16( st_fx->GSC_IVAS_mode, 0) ) + if ( EQ_16( coder_type, AUDIO ) && GT_16( st_fx->GSC_IVAS_mode, 0 ) ) { coder_type = GENERIC; move16(); } no_param_lpc = 0; nBits = 0; - move16();move16(); + move16(); + move16(); /* Find the number of bits for LSF quantization */ - IF ( EQ_32(st_fx->core_brate,SID_2k40)) + IF( EQ_32( st_fx->core_brate, SID_2k40 ) ) { nBits = LSF_BITS_CNG; move16(); @@ -150,25 +154,25 @@ void lsf_dec_fx( ELSE { test(); - IF ( st_fx->nelp_mode_dec == 0 && st_fx->ppp_mode_dec == 0 ) + IF( st_fx->nelp_mode_dec == 0 && st_fx->ppp_mode_dec == 0 ) { nBits = st_fx->acelp_cfg.lsf_bits; move16(); } - ELSE IF ( EQ_16(st_fx->nelp_mode_dec,1)) + ELSE IF( EQ_16( st_fx->nelp_mode_dec, 1 ) ) { - IF ( EQ_16(coder_type,UNVOICED)) + IF( EQ_16( coder_type, UNVOICED ) ) { nBits = 30; move16(); - if ( EQ_16(st_fx->bwidth,NB)) + if ( EQ_16( st_fx->bwidth, NB ) ) { nBits = 32; move16(); } } } - ELSE IF ( EQ_16(st_fx->ppp_mode_dec,1)) + ELSE IF( EQ_16( st_fx->ppp_mode_dec, 1 ) ) { nBits = 26; move16(); @@ -176,25 +180,25 @@ void lsf_dec_fx( } /* LSF de-quantization */ - lsf_end_dec_fx( st_fx, 0, coder_type, st_fx->bwidth, nBits, lsf_new, param_lpc, LSF_Q_prediction, &no_param_lpc); + lsf_end_dec_fx( st_fx, 0, coder_type, st_fx->bwidth, nBits, lsf_new, param_lpc, LSF_Q_prediction, &no_param_lpc ); /* convert quantized LSFs to LSPs */ - lsf2lsp_fx(lsf_new, lsp_new, M ,st_fx->sr_core); + lsf2lsp_fx( lsf_new, lsp_new, M, st_fx->sr_core ); /* set seed_acelp used in UC mode */ test(); - IF (EQ_16(coder_type, UNVOICED) && GT_16(st_fx->element_mode, EVS_MONO)) + IF( EQ_16( coder_type, UNVOICED ) && GT_16( st_fx->element_mode, EVS_MONO ) ) { st_fx->seed_acelp = 0; move16(); - FOR (i = no_param_lpc - 1; i >= 0; i--) + FOR( i = no_param_lpc - 1; i >= 0; i-- ) { /* rightshift before *seed_acelp+param_lpc[i] to avoid overflows*/ - st_fx->seed_acelp = (int16_t)((((st_fx->seed_acelp) >> 1) + param_lpc[i]) * 31821L + 13849L); - //PMTE() /*IVAS_CODE to be completed */ + st_fx->seed_acelp = (int16_t) ( ( ( ( st_fx->seed_acelp ) >> 1 ) + param_lpc[i] ) * 31821L + 13849L ); + // PMTE() /*IVAS_CODE to be completed */ } } - IF ( EQ_32(st_fx->core_brate,SID_2k40)) + IF( EQ_32( st_fx->core_brate, SID_2k40 ) ) { /* return if SID frame (conversion to A(z) done in the calling function) */ return; @@ -204,31 +208,31 @@ void lsf_dec_fx( * FEC - update adaptive LSF mean vector *-------------------------------------------------------------------------------------*/ - FOR (i=0; ilsfoldbfi1_fx[i], 10922); /*Q(x2.56+16)*/ - L_tmp = L_mac(L_tmp, st_fx->lsfoldbfi0_fx[i], 10922); /*Q(x2.56+16)*/ - st_fx->lsf_adaptive_mean_fx[i] = round_fx(L_tmp); /*Q(x2.56)*/ + L_tmp = L_mult( lsf_new[i], 10922 ); /*Q(x2.56+16)*/ + L_tmp = L_mac( L_tmp, st_fx->lsfoldbfi1_fx[i], 10922 ); /*Q(x2.56+16)*/ + L_tmp = L_mac( L_tmp, st_fx->lsfoldbfi0_fx[i], 10922 ); /*Q(x2.56+16)*/ + st_fx->lsf_adaptive_mean_fx[i] = round_fx( L_tmp ); /*Q(x2.56)*/ } test(); test(); - IF ( ( st_fx->prev_bfi && (EQ_16(coder_type,TRANSITION))&&(EQ_16(tc_subfr,sub(st_fx->L_frame,L_SUBFR))))) + IF( ( st_fx->prev_bfi && ( EQ_16( coder_type, TRANSITION ) ) && ( EQ_16( tc_subfr, sub( st_fx->L_frame, L_SUBFR ) ) ) ) ) { lsf_diff = 1205; - move16(); /*int_fs / (float)(2*(M+1)); = 470.588 -> 1205 in Q2.56 */ - if( EQ_16(st_fx->L_frame,L_FRAME)) + move16(); /*int_fs / (float)(2*(M+1)); = 470.588 -> 1205 in Q2.56 */ + if ( EQ_16( st_fx->L_frame, L_FRAME ) ) { lsf_diff = 964; - move16(); /*int_fs / (float)(2*(M+1)); = 376.47 -> 964 in Q2.56 */ + move16(); /*int_fs / (float)(2*(M+1)); = 376.47 -> 964 in Q2.56 */ } st_fx->lsf_old_fx[0] = lsf_diff; move16(); - FOR ( i=1; ilsf_old_fx[i] = add(st_fx->lsf_old_fx[i-1], lsf_diff); + st_fx->lsf_old_fx[i] = add( st_fx->lsf_old_fx[i - 1], lsf_diff ); move16(); } lsf2lsp_fx( st_fx->lsf_old_fx, st_fx->lsp_old_fx, M, st_fx->sr_core ); @@ -237,30 +241,30 @@ void lsf_dec_fx( * Mid-frame LSF decoding * LSP interpolation and conversion of LSPs to A(z) *-------------------------------------------------------------------------------------*/ - if(st_fx->rate_switching_reset) + if ( st_fx->rate_switching_reset ) { /*extrapolation in case of unstable LSF convert*/ - Copy(lsp_new,st_fx->lsp_old_fx,M); - Copy(lsf_new,st_fx->lsf_old_fx,M); + Copy( lsp_new, st_fx->lsp_old_fx, M ); + Copy( lsf_new, st_fx->lsf_old_fx, M ); } { /* Mid-frame LSF decoding */ - lsf_mid_dec_fx( st_fx, lsp_new, coder_type, lsp_mid); + lsf_mid_dec_fx( st_fx, lsp_new, coder_type, lsp_mid ); } test(); test(); - IF ( !( st_fx->prev_bfi && (EQ_16(coder_type,TRANSITION))&&(EQ_16(tc_subfr,sub(st_fx->L_frame,L_SUBFR))))) + IF( !( st_fx->prev_bfi && ( EQ_16( coder_type, TRANSITION ) ) && ( EQ_16( tc_subfr, sub( st_fx->L_frame, L_SUBFR ) ) ) ) ) { - IF ( st_fx->prev_bfi) + IF( st_fx->prev_bfi ) { /* check, if LSP interpolation can be relaxed */ - E_LPC_f_lsp_a_conversion( st_fx->lsp_old_fx, tmp_old, M); - enr_old = Enr_1_Az_fx( tmp_old, 2*L_SUBFR ); + E_LPC_f_lsp_a_conversion( st_fx->lsp_old_fx, tmp_old, M ); + enr_old = Enr_1_Az_fx( tmp_old, 2 * L_SUBFR ); - E_LPC_f_lsp_a_conversion( lsp_new, tmp_new, M); - enr_new = Enr_1_Az_fx( tmp_new, 2*L_SUBFR ); + E_LPC_f_lsp_a_conversion( lsp_new, tmp_new, M ); + enr_new = Enr_1_Az_fx( tmp_new, 2 * L_SUBFR ); - IF( LT_16(enr_new, mult_r(9830/*0.3 Q15*/,enr_old))) + IF( LT_16( enr_new, mult_r( 9830 /*0.3 Q15*/, enr_old ) ) ) { /* OLD CODE : if( st->safety_net == 1), replaced with a decision similar to MODE2 */ st_fx->relax_prev_lsf_interp = -1; @@ -269,7 +273,7 @@ void lsf_dec_fx( test(); test(); test(); - if ( EQ_16(st_fx->clas_dec, UNVOICED_CLAS)||EQ_16(st_fx->clas_dec,SIN_ONSET)||EQ_16(st_fx->clas_dec,INACTIVE_CLAS)||EQ_16(coder_type,GENERIC)||EQ_16(coder_type,TRANSITION)) + if ( EQ_16( st_fx->clas_dec, UNVOICED_CLAS ) || EQ_16( st_fx->clas_dec, SIN_ONSET ) || EQ_16( st_fx->clas_dec, INACTIVE_CLAS ) || EQ_16( coder_type, GENERIC ) || EQ_16( coder_type, TRANSITION ) ) { st_fx->relax_prev_lsf_interp = 1; move16(); @@ -278,41 +282,41 @@ void lsf_dec_fx( } } test(); - IF( EQ_16(st_fx->last_core, HQ_CORE)&&EQ_16(st_fx->core,ACELP_CORE)) + IF( EQ_16( st_fx->last_core, HQ_CORE ) && EQ_16( st_fx->core, ACELP_CORE ) ) { /* update old LSPs/LSFs in case of HQ->ACELP core switching */ Copy( lsp_mid, st_fx->lsp_old_fx, M ); - lsp2lsf_fx( lsp_mid, st_fx->lsf_old_fx, M, st_fx->sr_core); + lsp2lsf_fx( lsp_mid, st_fx->lsf_old_fx, M, st_fx->sr_core ); } - IF (EQ_16(tdm_low_rate_mode, 1) && GT_16(coder_type, UNVOICED)) + IF( EQ_16( tdm_low_rate_mode, 1 ) && GT_16( coder_type, UNVOICED ) ) { - //PMT("To be verified") - IF (EQ_16(st_fx->active_cnt, 1) ) + // PMT("To be verified") + IF( EQ_16( st_fx->active_cnt, 1 ) ) { - Copy(lsp_mid, st_fx->lsp_old_fx, M); - lsp2lsf_fx(lsp_mid, st_fx->lsf_old_fx, M, st_fx->sr_core); - Copy(lsp_new, lsp_mid, M); + Copy( lsp_mid, st_fx->lsp_old_fx, M ); + lsp2lsf_fx( lsp_mid, st_fx->lsf_old_fx, M, st_fx->sr_core ); + Copy( lsp_new, lsp_mid, M ); } /* LSP interpolation and conversion of LSPs to A(z) - two-subframe mode */ - int_lsp4_fx(st_fx->L_frame, st_fx->lsp_old_fx, lsp_mid, lsp_new, Aq, M, -2); + int_lsp4_fx( st_fx->L_frame, st_fx->lsp_old_fx, lsp_mid, lsp_new, Aq, M, -2 ); } ELSE { /* LSP interpolation and conversion of LSPs to A(z) */ - int_lsp4_fx(st_fx->L_frame, st_fx->lsp_old_fx, lsp_mid, lsp_new, Aq, M, st_fx->relax_prev_lsf_interp); + int_lsp4_fx( st_fx->L_frame, st_fx->lsp_old_fx, lsp_mid, lsp_new, Aq, M, st_fx->relax_prev_lsf_interp ); } /*------------------------------------------------------------------* * Check LSF stability (distance between old LSFs and current LSFs) *------------------------------------------------------------------*/ - IF( EQ_16(st_fx->element_mode, EVS_MONO ) ) + IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) { st_fx->stab_fac_fx = lsf_stab_fx( lsf_new, st_fx->lsf_old_fx, 0, st_fx->L_frame ); /*Q15*/ } else { - st_fx->stab_fac_fx = lsf_stab_ivas_fx(lsf_new, st_fx->lsf_old_fx, 0, st_fx->L_frame ); + st_fx->stab_fac_fx = lsf_stab_ivas_fx( lsf_new, st_fx->lsf_old_fx, 0, st_fx->L_frame ); } return; @@ -354,17 +358,18 @@ void lsf_dec_fx( /*========================================================================*/ void lsf_end_dec_fx( - Decoder_State * st, /* i/o: decoder state structure */ + Decoder_State *st, /* i/o: decoder state structure */ Word16 mode2_flag, - const Word16 coder_type_org, /* i : coding type */ - const Word16 bwidth, /* i : input signal bandwidth */ - const Word16 nBits_in, /* i : number of bits used for ISF quantization*/ - Word16 *qlsf, /* o : quantized LSFs in the cosine domain */ - Word16 *lpc_param, /* i : LPC parameters */ - Word16 *LSF_Q_prediction, /* o : LSF prediction mode */ - Word16 * nb_indices /* o : number of indices */ + const Word16 coder_type_org, /* i : coding type */ + const Word16 bwidth, /* i : input signal bandwidth */ + const Word16 nBits_in, /* i : number of bits used for ISF quantization*/ + Word16 *qlsf, /* o : quantized LSFs in the cosine domain */ + Word16 *lpc_param, /* i : LPC parameters */ + Word16 *LSF_Q_prediction, /* o : LSF prediction mode */ + Word16 *nb_indices /* o : number of indices */ #ifdef LSF_RE_USE_SECONDARY_CHANNEL - ,const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ + , + const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ #endif ) { @@ -375,15 +380,15 @@ void lsf_end_dec_fx( Word16 levels0[MAX_VQ_STAGES]; /* Sizes of different codebook stages for safety-net quantizer*/ Word16 levels1[MAX_VQ_STAGES]; /* Sizes of different codebook stages for predictive quantizer*/ Word16 i; - Word16 TCQIdx[M/2+4]; + Word16 TCQIdx[M / 2 + 4]; Word16 bits0[MAX_VQ_STAGES], bits1[MAX_VQ_STAGES]; - Word16 cumleft; - Word16 lindice[MAX_VQ_STAGES+3]; /* Predictor selector needs 1 bit and the LVQ indice uses 3 shorts */ + Word16 cumleft; + Word16 lindice[MAX_VQ_STAGES + 3]; /* Predictor selector needs 1 bit and the LVQ indice uses 3 shorts */ Word16 mode_lvq, mode_lvq_p; Word16 safety_net, predmode, stages, *levels; const Word16 *Bit_alloc1 = NULL, *bits; Word16 num_bits; - Word16 * p_lpc_param; + Word16 *p_lpc_param; Word16 nBits; @@ -393,27 +398,30 @@ void lsf_end_dec_fx( #ifdef LSF_RE_USE_SECONDARY_CHANNEL Word16 pred3[M]; #endif - flag_1bit_gran = (Word16)GT_16(st->element_mode, EVS_MONO); + flag_1bit_gran = (Word16) GT_16( st->element_mode, EVS_MONO ); nBits = nBits_in; *nb_indices = 0; - move16();move16();move16(); + move16(); + move16(); + move16(); test(); test(); #ifdef LSF_RE_USE_SECONDARY_CHANNEL - IF((EQ_16(coder_type_org, GENERIC)) && (EQ_32(st->sr_core,INT_FS_16k)) && (mode2_flag==0) && (st->idchan == 0)) + IF( ( EQ_16( coder_type_org, GENERIC ) ) && ( EQ_32( st->sr_core, INT_FS_16k ) ) && ( mode2_flag == 0 ) && ( st->idchan == 0 ) ) #else - IF((EQ_16(coder_type_org, GENERIC)) && (EQ_32(st->sr_core,INT_FS_16k)) && (mode2_flag==0)) + IF( ( EQ_16( coder_type_org, GENERIC ) ) && ( EQ_32( st->sr_core, INT_FS_16k ) ) && ( mode2_flag == 0 ) ) #endif { /* this bit is used only for primary channel or mono */ - coder_type = (Word16)get_next_indice( st, 1 ); - coder_type = add(coder_type,2); - test(); test(); - if (EQ_16(coder_type, GENERIC) || (EQ_16(coder_type, VOICED) && EQ_16(flag_1bit_gran, 1))) + coder_type = (Word16) get_next_indice( st, 1 ); + coder_type = add( coder_type, 2 ); + test(); + test(); + if ( EQ_16( coder_type, GENERIC ) || ( EQ_16( coder_type, VOICED ) && EQ_16( flag_1bit_gran, 1 ) ) ) { - nBits = sub(nBits,1); + nBits = sub( nBits, 1 ); } } ELSE @@ -426,63 +434,63 @@ void lsf_end_dec_fx( * LSF de-quantization of SID frames *--------------------------------------------------------------------------------*/ - IF ( st->core_brate == SID_2k40 ) + IF( st->core_brate == SID_2k40 ) { - dqlsf_CNG_fx( st, qlsf); - sort_fx( qlsf, 0, M-1); + dqlsf_CNG_fx( st, qlsf ); + sort_fx( qlsf, 0, M - 1 ); reorder_lsf_fx( qlsf, MODE1_LSF_GAP_FX, M, st->sr_core ); return; } - find_pred_mode(&predmode, coder_type, bwidth, st->sr_core, &mode_lvq, &mode_lvq_p, st->total_brate); + find_pred_mode( &predmode, coder_type, bwidth, st->sr_core, &mode_lvq, &mode_lvq_p, st->total_brate ); /*----------------------------------------------------------------* * Calculate number of stages and levels for each stage based on the allowed bit allocation * (subtract one bit for LSF predictor selection) *----------------------------------------------------------------*/ - lsf_allocate_fx( sub(nBits,shr(predmode,1)), mode_lvq, mode_lvq_p, &stages0, &stages1, levels0, levels1, - bits0, bits1); + lsf_allocate_fx( sub( nBits, shr( predmode, 1 ) ), mode_lvq, mode_lvq_p, &stages0, &stages1, levels0, levels1, + bits0, bits1 ); /*--------------------------------------------------------------------------* * Select safety_net or predictive mode *--------------------------------------------------------------------------*/ #ifdef LSF_RE_USE_SECONDARY_CHANNEL - IF (st->tdm_LRTD_flag == 0 && EQ_16(st->idchan, 1) && tdm_lsfQ_PCh != NULL) + IF( st->tdm_LRTD_flag == 0 && EQ_16( st->idchan, 1 ) && tdm_lsfQ_PCh != NULL ) { /* if secondary channel predmode is set to be > 2 */ /*predmode += 3;*/ - predmode =add(predmode , 3); + predmode = add( predmode, 3 ); } #endif p_lpc_param = lpc_param; - + move16(); - IF ( predmode == 0 ) + IF( predmode == 0 ) { safety_net = 1; move16(); } - ELSE IF ( predmode == 1 ) + ELSE IF( predmode == 1 ) { safety_net = 0; move16(); } ELSE { - IF (EQ_16(mode2_flag, 1) || EQ_16(st->core, TCX_20_CORE) || EQ_16(st->core, TCX_10_CORE)) + IF( EQ_16( mode2_flag, 1 ) || EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) ) { /* read from param_lpc */ safety_net = p_lpc_param[0]; move16(); p_lpc_param++; - *nb_indices = add(*nb_indices, 1); + *nb_indices = add( *nb_indices, 1 ); } ELSE { - safety_net = (Word16)get_next_indice( st, 1 ); + safety_net = (Word16) get_next_indice( st, 1 ); } } @@ -493,30 +501,32 @@ void lsf_end_dec_fx( * Read indices from array *--------------------------------------------------------------------------*/ #ifdef LSF_RE_USE_SECONDARY_CHANNEL - /* Make sure there are the correct bit allocations */ - IF (st->idchan == 1 && predmode > 2) + /* Make sure there are the correct bit allocations */ + IF( st->idchan == 1 && predmode > 2 ) { PMTE() /* use same AR prediction bit allocation for intra and inter modes*/ - lsf_allocate(nBits - 1, mode_lvq, 9, &stages0, &stages1, levels0, levels1, bits0, bits1); + lsf_allocate( nBits - 1, mode_lvq, 9, &stages0, &stages1, levels0, levels1, bits0, bits1 ); stages0 = stages1; - mvs2s(levels1, levels0, stages0); - mvs2s(bits1, bits0, stages0); + mvs2s( levels1, levels0, stages0 ); + mvs2s( bits1, bits0, stages0 ); } #endif - test(); test(); - IF (EQ_32(st->sr_core , INT_FS_16k) && EQ_16(coder_type, VOICED) && flag_1bit_gran == 0) + test(); + test(); + IF( EQ_32( st->sr_core, INT_FS_16k ) && EQ_16( coder_type, VOICED ) && flag_1bit_gran == 0 ) { /* BC-TCVQ - only in VOICED_WB@16kHz */ - test(); test(); - IF (EQ_16(st->codec_mode, MODE2) || EQ_16(st->core, TCX_20_CORE) || EQ_16(st->core, TCX_10_CORE)) + test(); + test(); + IF( EQ_16( st->codec_mode, MODE2 ) || EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) ) { *nb_indices = 10; move16(); move16(); TCQIdx[0] = safety_net; - FOR (i = 1; i < *nb_indices; i++) + FOR( i = 1; i < *nb_indices; i++ ) { TCQIdx[i] = *p_lpc_param++; move16(); @@ -527,16 +537,16 @@ void lsf_end_dec_fx( Bit_alloc1 = &BC_TCVQ_BIT_ALLOC_40B[1]; TCQIdx[0] = safety_net; move16(); - FOR (i = 0; i < M / 2 + 3; i++) + FOR( i = 0; i < M / 2 + 3; i++ ) { - TCQIdx[i + 1] = get_next_indice(st, Bit_alloc1[i]); + TCQIdx[i + 1] = get_next_indice( st, Bit_alloc1[i] ); move16(); } } } ELSE { - IF(safety_net) + IF( safety_net ) { stages = stages0; move16(); @@ -554,10 +564,11 @@ void lsf_end_dec_fx( bits = bits1; move16(); } - test(); test(); - IF(EQ_16(mode2_flag, 1) || EQ_16(st->core, TCX_20_CORE) || EQ_16(st->core, TCX_10_CORE)) + test(); + test(); + IF( EQ_16( mode2_flag, 1 ) || EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) ) { - FOR(i = 0; i < stages - 1; i++) + FOR( i = 0; i < stages - 1; i++ ) { num_bits = bits[i]; move16(); @@ -567,11 +578,11 @@ void lsf_end_dec_fx( cumleft = levels[stages - 1]; move16(); - WHILE(cumleft > 0) + WHILE( cumleft > 0 ) { - IF(GT_16(cumleft, LEN_INDICE)) + IF( GT_16( cumleft, LEN_INDICE ) ) { - cumleft = sub(cumleft, LEN_INDICE); + cumleft = sub( cumleft, LEN_INDICE ); } ELSE { @@ -581,45 +592,45 @@ void lsf_end_dec_fx( lindice[i + 1] = *p_lpc_param++; move16(); - i = add(i,1); + i = add( i, 1 ); } - *nb_indices = add(*nb_indices , i); + *nb_indices = add( *nb_indices, i ); move16(); } ELSE { - FOR(i = 0; i < stages - 1; i++) + FOR( i = 0; i < stages - 1; i++ ) { num_bits = bits[i]; move16(); - lindice[i + 1] = (Word16)get_next_indice(st, num_bits); + lindice[i + 1] = (Word16) get_next_indice( st, num_bits ); } - cumleft = levels[sub(stages,1)]; - WHILE(cumleft > 0) + cumleft = levels[sub( stages, 1 )]; + WHILE( cumleft > 0 ) { - IF(GT_16(cumleft, LEN_INDICE)) + IF( GT_16( cumleft, LEN_INDICE ) ) { - cumleft = sub(cumleft, LEN_INDICE); + cumleft = sub( cumleft, LEN_INDICE ); num_bits = LEN_INDICE; move16(); } ELSE { - num_bits = (Word16)cumleft; + num_bits = (Word16) cumleft; move16(); cumleft = 0; move16(); } - lindice[i + 1] = (Word16)get_next_indice(st, num_bits); - i = add(i,1); + lindice[i + 1] = (Word16) get_next_indice( st, num_bits ); + i = add( i, 1 ); } } } - IF(EQ_16(st->reset_mem_AR,1)) + IF( EQ_16( st->reset_mem_AR, 1 ) ) { - FOR( i=0; imem_AR_fx[i] = ModeMeans_fx[mode_lvq][i]; move16(); @@ -634,24 +645,25 @@ void lsf_end_dec_fx( *LSF_Q_prediction = SAFETY_NET; move16(); /* VOICED_WB@16kHz */ - test(); test(); - IF ( EQ_32(st->sr_core, INT_FS_16k) && EQ_16(coder_type,VOICED) && flag_1bit_gran == 0) + test(); + test(); + IF( EQ_32( st->sr_core, INT_FS_16k ) && EQ_16( coder_type, VOICED ) && flag_1bit_gran == 0 ) { /* BC-TCVQ decoder */ - safety_net = qlsf_ARSN_tcvq_Dec_16k_fx ( qlsf, TCQIdx, nBits-1 ); + safety_net = qlsf_ARSN_tcvq_Dec_16k_fx( qlsf, TCQIdx, nBits - 1 ); /* Update mem_MA */ Copy( qlsf, st->mem_MA_fx, M ); - IF (safety_net) + IF( safety_net ) { - Copy(ModeMeans_fx[mode_lvq], pred0, M); + Copy( ModeMeans_fx[mode_lvq], pred0, M ); } ELSE { - FOR(i = 0; i < M; i++) + FOR( i = 0; i < M; i++ ) { - pred0[i] = add(ModeMeans_fx[mode_lvq][i], mult(Predictors_fx[mode_lvq_p][i],(sub(st->mem_AR_fx[i], ModeMeans_fx[mode_lvq][i])))); /* Q(x2.56)*/ + pred0[i] = add( ModeMeans_fx[mode_lvq][i], mult( Predictors_fx[mode_lvq_p][i], ( sub( st->mem_AR_fx[i], ModeMeans_fx[mode_lvq][i] ) ) ) ); /* Q(x2.56)*/ } *LSF_Q_prediction = AUTO_REGRESSIVE; move16(); @@ -664,30 +676,30 @@ void lsf_end_dec_fx( /* Safety-net */ Copy( ModeMeans_fx[mode_lvq], pred0, M ); /* for mem_MA update */ - FOR (i=0; imem_MA_fx[i])); + pred1[i] = add( pred0[i], mult_r( MU_MA_FX, st->mem_MA_fx[i] ) ); } #ifdef LSF_RE_USE_SECONDARY_CHANNEL /* TD stereo SCh: perform intra-frame prediction with pulling-to-mean */ - if (st->tdm_LRTD_flag == 0 && st->idchan == 1 && tdm_lsfQ_PCh != NULL) + if ( st->tdm_LRTD_flag == 0 && st->idchan == 1 && tdm_lsfQ_PCh != NULL ) { - tdm_SCh_LSF_intra_pred(st->element_brate, tdm_lsfQ_PCh, pred3); + tdm_SCh_LSF_intra_pred( st->element_brate, tdm_lsfQ_PCh, pred3 ); } #endif - IF ( safety_net ) + IF( safety_net ) { /* LVQ */ #ifdef LSF_RE_USE_SECONDARY_CHANNEL - if (st->tdm_LRTD_flag == 0 && st->idchan == 1 && tdm_lsfQ_PCh != NULL) + if ( st->tdm_LRTD_flag == 0 && st->idchan == 1 && tdm_lsfQ_PCh != NULL ) { /* intra mode*/ st->BER_detect = st->BER_detect | - vq_dec_lvq(0, qlsf, &lindice[1], stages0, M, 9, /*mode_lvq_p,*/ levels0[stages0 - 1]); + vq_dec_lvq( 0, qlsf, &lindice[1], stages0, M, 9, /*mode_lvq_p,*/ levels0[stages0 - 1] ); - v_add(qlsf, pred3, qlsf, M); - v_sub(qlsf, pred1, st->mem_MA, M); + v_add( qlsf, pred3, qlsf, M ); + v_sub( qlsf, pred1, st->mem_MA, M ); } else #endif @@ -702,19 +714,20 @@ void lsf_end_dec_fx( &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->offset_scale1_p_fx[0][0], &st->offset_scale2_p_fx[0][0], &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0] ); } - st->BER_detect = s_or(st->BER_detect, ber_flag); - Vr_add(qlsf, pred0, qlsf, M); - Vr_subt(qlsf, pred1, st->mem_MA_fx, M); + st->BER_detect = s_or( st->BER_detect, ber_flag ); + Vr_add( qlsf, pred0, qlsf, M ); + Vr_subt( qlsf, pred1, st->mem_MA_fx, M ); } } ELSE { #ifdef LSF_RE_USE_SECONDARY_CHANNEL - IF (EQ_16(predmode, 4)) + IF( EQ_16( predmode, 4 ) ) { mode_lvq_p = 9; predmode = 2; - move16(); move16(); + move16(); + move16(); } #endif if ( st->element_mode != EVS_MONO ) @@ -727,15 +740,15 @@ void lsf_end_dec_fx( &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->offset_scale1_p_fx[0][0], &st->offset_scale2_p_fx[0][0], &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0] ); } - st->BER_detect = s_or(st->BER_detect, ber_flag); + st->BER_detect = s_or( st->BER_detect, ber_flag ); #ifdef LSF_RE_USE_SECONDARY_CHANNEL test(); - IF (EQ_16(predmode, 1) || EQ_16(predmode, 4)) /* MA only */ + IF( EQ_16( predmode, 1 ) || EQ_16( predmode, 4 ) ) /* MA only */ #else - IF (EQ_16(predmode, 1)) /* MA only */ + IF( EQ_16( predmode, 1 ) ) /* MA only */ #endif { - Copy(qlsf, st->mem_MA_fx, M); + Copy( qlsf, st->mem_MA_fx, M ); Vr_add( qlsf, pred1, qlsf, M ); *LSF_Q_prediction = MOVING_AVERAGE; move16(); @@ -743,9 +756,9 @@ void lsf_end_dec_fx( ELSE { /* AR */ - FOR ( i=0; imem_AR_fx[i], pred0[i]))); + pred2[i] = add( pred0[i], mult( Predictors_fx[mode_lvq_p][i], sub( st->mem_AR_fx[i], pred0[i] ) ) ); } Vr_add( qlsf, pred2, qlsf, M ); Vr_subt( qlsf, pred1, st->mem_MA_fx, M ); @@ -762,7 +775,7 @@ void lsf_end_dec_fx( *--------------------------------------------------------------------------*/ /* Sort the quantized vector */ - sort_fx( qlsf, 0, M-1 ); + sort_fx( qlsf, 0, M - 1 ); /* Verify stability */ reorder_lsf_fx( qlsf, MODE1_LSF_GAP_FX, M, st->sr_core ); @@ -799,10 +812,10 @@ void lsf_end_dec_fx( /* _ None */ /*========================================================================*/ void lsf_mid_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 lsp_new[], /* i : quantized LSPs from frame endSQ15*/ - Word16 coder_type, /* i : Coder type */ - Word16 lsp_mid[] /* o : quantized LSPs Q15*/ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 lsp_new[], /* i : quantized LSPs from frame endSQ15*/ + Word16 coder_type, /* i : Coder type */ + Word16 lsp_mid[] /* o : quantized LSPs Q15*/ ) { Word16 j, idx; @@ -816,17 +829,17 @@ void lsf_mid_dec_fx( /* Convert LSPs to LSFs */ - lsp2lsf_fx(st_fx->lsp_old_fx, qlsf0, M, st_fx->sr_core); - lsp2lsf_fx( lsp_new, qlsf1, M, st_fx->sr_core); + lsp2lsf_fx( st_fx->lsp_old_fx, qlsf0, M, st_fx->sr_core ); + lsp2lsf_fx( lsp_new, qlsf1, M, st_fx->sr_core ); /* Codebook selection */ - IF ( EQ_16(st_fx->ppp_mode_dec,1)) + IF( EQ_16( st_fx->ppp_mode_dec, 1 ) ) { nb_bits = 1; move16(); ratio = &tbl_mid_voi_wb_1b_fx[0]; } - ELSE IF ( EQ_16(st_fx->nelp_mode_dec,1)) + ELSE IF( EQ_16( st_fx->nelp_mode_dec, 1 ) ) { nb_bits = 4; move16(); @@ -839,47 +852,47 @@ void lsf_mid_dec_fx( /* codebook selection */ - IF ( EQ_16(coder_type,VOICED)) + IF( EQ_16( coder_type, VOICED ) ) { - SWITCH ( nb_bits ) + SWITCH( nb_bits ) { - case 5: + case 5: { ratio = tbl_mid_voi_wb_5b_fx; BREAK; } - case 4: + case 4: { ratio = tbl_mid_voi_wb_4b_fx; BREAK; } - case 1: + case 1: { ratio = tbl_mid_voi_wb_1b_fx; break; } } } - ELSE IF ( coder_type == UNVOICED ) + ELSE IF( coder_type == UNVOICED ) { ratio = tbl_mid_unv_wb_5b_fx; } ELSE { /* GENERIC, TRANSITION, AUDIO and INACTIVE */ - SWITCH ( nb_bits ) + SWITCH( nb_bits ) { - case 5: + case 5: { ratio = tbl_mid_gen_wb_5b_fx; BREAK; } - case 4: + case 4: { ratio = tbl_mid_gen_wb_4b_fx; break; } - case 2: + case 2: { ratio = tbl_mid_gen_wb_2b_fx; BREAK; @@ -889,22 +902,22 @@ void lsf_mid_dec_fx( } /* Retrieve mid-frame LSF index */ - idx = (Word16)get_next_indice( st_fx, nb_bits ); + idx = (Word16) get_next_indice( st_fx, nb_bits ); /* Calculation of mid-LSF vector */ - FOR (j=0; jQ(x2.56+14)*/ - L_tmp = L_mac(L_tmp, ratio[idx*M+j], qlsf1[j]); /*Q(x2.56+14)*/ - qlsf[j] = round_fx(L_shl(L_tmp,2)); /*Q(x2.56)*/ + L_tmp = L_mult( sub( 0x2000, ratio[idx * M + j] ), qlsf0[j] ); /*Q(x2.56+13+1)->Q(x2.56+14)*/ + L_tmp = L_mac( L_tmp, ratio[idx * M + j], qlsf1[j] ); /*Q(x2.56+14)*/ + qlsf[j] = round_fx( L_shl( L_tmp, 2 ) ); /*Q(x2.56)*/ } /* check for incorrect LSF ordering */ - IF ( EQ_16(st_fx->mid_lsf_int, 1)) + IF( EQ_16( st_fx->mid_lsf_int, 1 ) ) { - FOR (j=1; jprev_bfi || ( EQ_16(st_fx->mid_lsf_int, 1) && bad_spacing)) + IF( st_fx->prev_bfi || ( EQ_16( st_fx->mid_lsf_int, 1 ) && bad_spacing ) ) { - FOR (j=0; j 0 && LT_16(j, M)&<_16(qlsf[j],add(qlsf[j-1],LSF_GAP_MID_FX))) + IF( j > 0 && LT_16( j, M ) && LT_16( qlsf[j], add( qlsf[j - 1], LSF_GAP_MID_FX ) ) ) { - qlsf[j] = add(qlsf[j-1], LSF_GAP_MID_FX); + qlsf[j] = add( qlsf[j - 1], LSF_GAP_MID_FX ); move16(); } } @@ -936,13 +950,13 @@ void lsf_mid_dec_fx( ELSE { /* otherwise, use regular LSF spacing and ordering as in the encoder */ - FOR (j=0; j 0 && LT_16(j, M)&<_16(qlsf[j],add(qlsf[j-1],LSF_GAP_MID_FX))) + IF( j > 0 && LT_16( j, M ) && LT_16( qlsf[j], add( qlsf[j - 1], LSF_GAP_MID_FX ) ) ) { - qlsf[j] = add(qlsf[j-1], LSF_GAP_MID_FX); + qlsf[j] = add( qlsf[j - 1], LSF_GAP_MID_FX ); move16(); } } @@ -955,17 +969,17 @@ void lsf_mid_dec_fx( move16(); } - if (st_fx->safety_net ) + if ( st_fx->safety_net ) { /* safety-net encountered -> stop redoing mid-LSF interpolation with 0.4 */ st_fx->mid_lsf_int = 0; move16(); } - reorder_lsf_fx( qlsf, LSF_GAP_MID_FX, M, st_fx->sr_core); + reorder_lsf_fx( qlsf, LSF_GAP_MID_FX, M, st_fx->sr_core ); /* convert back to LSPs */ - lsf2lsp_fx( qlsf, lsp_mid, M, st_fx->sr_core); + lsf2lsp_fx( qlsf, lsp_mid, M, st_fx->sr_core ); return; } diff --git a/lib_dec/lsf_msvq_ma_dec.c b/lib_dec/lsf_msvq_ma_dec.c index 7e9fadb1c..d18d49fff 100644 --- a/lib_dec/lsf_msvq_ma_dec.c +++ b/lib_dec/lsf_msvq_ma_dec.c @@ -184,7 +184,7 @@ int16_t D_lsf_tcxlpc_ivas( NumIndices = 1; - msvq_dec_float(lsf_codebook_flt[narrowband][cdk], lsf_dims_ivas, lsf_offs_ivas, TCXLPC_NUMSTAGES, M, M, indices + NumIndices, 0, NULL, lsf_q, lsf_q_ind ); + msvq_dec_float( lsf_codebook_flt[narrowband][cdk], lsf_dims_ivas, lsf_offs_ivas, TCXLPC_NUMSTAGES, M, M, indices + NumIndices, 0, NULL, lsf_q, lsf_q_ind ); NumIndices += TCXLPC_NUMSTAGES; @@ -193,7 +193,7 @@ int16_t D_lsf_tcxlpc_ivas( /* Only add contribution if flag is enabled */ - msvq_dec_float(lsf_ind_codebook_flt[narrowband][cdk], lsf_ind_dims_ivas, lsf_ind_offs, TCXLPC_IND_NUMSTAGES, M, M, indices + NumIndices, 0, NULL, lsf_rem_q, lsf_rem_q_ind ); + msvq_dec_float( lsf_ind_codebook_flt[narrowband][cdk], lsf_ind_dims_ivas, lsf_ind_offs, TCXLPC_IND_NUMSTAGES, M, M, indices + NumIndices, 0, NULL, lsf_rem_q, lsf_rem_q_ind ); NumIndices += TCXLPC_IND_NUMSTAGES; /* Add to MA-removed vector */ @@ -219,7 +219,7 @@ int16_t D_lsf_tcxlpc_ivas( } reorder_lsf( lsf_q, TCXLPC_LSF_GAP_FLT, M, INT_FS_12k8 ); - basop_reorder_lsf( lsf_q_ind, LSF_GAP_VAL(TCXLPC_LSF_GAP_FLT), M, INT_FS_FX ); + basop_reorder_lsf( lsf_q_ind, LSF_GAP_VAL( TCXLPC_LSF_GAP_FLT ), M, INT_FS_FX ); if ( lsp_q_ind ) { @@ -262,7 +262,7 @@ int16_t dec_lsf_tcxlpc_ivas( } /* Decode independent lsf */ - msvq_dec_float(lsf_codebook_flt[narrowband][cdk], lsf_dims_ivas, lsf_offs_ivas, TCXLPC_NUMSTAGES, M, M, flag + 1, 0, NULL, lsf_q_ignored, lsf_q_ind ); + msvq_dec_float( lsf_codebook_flt[narrowband][cdk], lsf_dims_ivas, lsf_offs_ivas, TCXLPC_NUMSTAGES, M, M, flag + 1, 0, NULL, lsf_q_ignored, lsf_q_ind ); /* Update flag */ *flag = lsf_ind_is_active_flt( lsf_q_ind, lsf_means_float[narrowband], narrowband, cdk ); diff --git a/lib_dec/lsf_msvq_ma_dec_fx.c b/lib_dec/lsf_msvq_ma_dec_fx.c index 66db651e4..13e41a8d2 100644 --- a/lib_dec/lsf_msvq_ma_dec_fx.c +++ b/lib_dec/lsf_msvq_ma_dec_fx.c @@ -12,7 +12,13 @@ #include "rom_com.h" #ifndef swap - #define swap(x,y,type) {type u__p; u__p=x; x=y; y=u__p;} +#define swap( x, y, type ) \ + { \ + type u__p; \ + u__p = x; \ + x = y; \ + y = u__p; \ + } #endif /*---------------------------------------------------------------------* * lsf_msvq_ma_decprm() @@ -20,49 +26,49 @@ * *---------------------------------------------------------------------*/ -Word16 lsf_msvq_ma_decprm( Decoder_State * st, Word16 *param_lpc) +Word16 lsf_msvq_ma_decprm( Decoder_State *st, Word16 *param_lpc ) { Word16 i, nbits_lpc, tmp; - Word16 bits_midlpc; + Word16 bits_midlpc; Word16 bits0[MAX_VQ_STAGES], bits1[MAX_VQ_STAGES], stages0, stages1, stages, - levels0[MAX_VQ_STAGES], levels1[MAX_VQ_STAGES], * bits; - Word16 predmode, mode_lvq, mode_lvq_p, safety_net; + levels0[MAX_VQ_STAGES], levels1[MAX_VQ_STAGES], *bits; + Word16 predmode, mode_lvq, mode_lvq_p, safety_net; - bits_midlpc=5; + bits_midlpc = 5; move16(); test(); - IF ((EQ_32(st->sr_core, INT_FS_16k))&&(EQ_16(st->coder_type,UNVOICED))) + IF( ( EQ_32( st->sr_core, INT_FS_16k ) ) && ( EQ_16( st->coder_type, UNVOICED ) ) ) { - find_pred_mode(&predmode, GENERIC, sub(1, st->narrowBand) /*st->bwidth*/, st->sr_core, - &mode_lvq, &mode_lvq_p, st->total_brate); + find_pred_mode( &predmode, GENERIC, sub( 1, st->narrowBand ) /*st->bwidth*/, st->sr_core, + &mode_lvq, &mode_lvq_p, st->total_brate ); move16(); } ELSE { - IF (EQ_16(st->core, TCX_20_CORE)) + IF( EQ_16( st->core, TCX_20_CORE ) ) { - find_pred_mode(&predmode, AUDIO, sub(1,st->narrowBand)/*st->bwidth*/, st->sr_core, &mode_lvq, &mode_lvq_p, st->total_brate ); + find_pred_mode( &predmode, AUDIO, sub( 1, st->narrowBand ) /*st->bwidth*/, st->sr_core, &mode_lvq, &mode_lvq_p, st->total_brate ); move16(); } ELSE { - find_pred_mode(&predmode, st->coder_type, sub(1, st->narrowBand)/*st->bwidth*/, st->sr_core, &mode_lvq, &mode_lvq_p, st->total_brate ); + find_pred_mode( &predmode, st->coder_type, sub( 1, st->narrowBand ) /*st->bwidth*/, st->sr_core, &mode_lvq, &mode_lvq_p, st->total_brate ); move16(); } } - lsf_allocate_fx( sub(ENDLSF_NBITS, shr(predmode,1)), mode_lvq, mode_lvq_p, &stages0, &stages1, levels0, levels1, bits0, bits1); + lsf_allocate_fx( sub( ENDLSF_NBITS, shr( predmode, 1 ) ), mode_lvq, mode_lvq_p, &stages0, &stages1, levels0, levels1, bits0, bits1 ); nbits_lpc = 0; move16(); - IF (EQ_16(predmode, 2)) + IF( EQ_16( predmode, 2 ) ) { /* there is choice between SN and AR prediction */ - safety_net = get_next_indice_fx(st, 1); + safety_net = get_next_indice_fx( st, 1 ); - IF (EQ_16(safety_net,1)) + IF( EQ_16( safety_net, 1 ) ) { stages = stages0; move16(); @@ -80,7 +86,6 @@ Word16 lsf_msvq_ma_decprm( Decoder_State * st, Word16 *param_lpc) move16(); param_lpc++; nbits_lpc++; - } ELSE { @@ -91,42 +96,39 @@ Word16 lsf_msvq_ma_decprm( Decoder_State * st, Word16 *param_lpc) } - tmp = sub(stages,1); - FOR (i=0; icoder_type, VOICED) && st->core==0 && st->acelp_cfg.midLpc) + IF( NE_16( st->coder_type, VOICED ) && st->core == 0 && st->acelp_cfg.midLpc ) { - *param_lpc = get_next_indice_fx(st, bits_midlpc); - nbits_lpc = add(nbits_lpc, bits_midlpc); + *param_lpc = get_next_indice_fx( st, bits_midlpc ); + nbits_lpc = add( nbits_lpc, bits_midlpc ); } return nbits_lpc; } - Word16 lsf_bctcvq_decprm( - Decoder_State * st, - Word16 *param_lpc -) + Decoder_State *st, + Word16 *param_lpc ) { Word16 i, nbits_lpc; Word16 num_par; @@ -138,11 +140,11 @@ Word16 lsf_bctcvq_decprm( nbits_lpc = 0; - FOR (i=0; inext_bit_pos; move16(); - FOR (i=0; inext_bit_pos, start_bit_pos); + return sub( st->next_bit_pos, start_bit_pos ); } diff --git a/lib_dec/nelp_dec.c b/lib_dec/nelp_dec.c index 4f0c346f1..9537ff858 100644 --- a/lib_dec/nelp_dec.c +++ b/lib_dec/nelp_dec.c @@ -217,4 +217,4 @@ void nelp_decoder( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/nelp_dec_fx.c b/lib_dec/nelp_dec_fx.c index 8330ef1a9..dfafc8d09 100644 --- a/lib_dec/nelp_dec_fx.c +++ b/lib_dec/nelp_dec_fx.c @@ -3,9 +3,9 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ #include "rom_com.h" /*===================================================================*/ @@ -28,29 +28,29 @@ /* RETURN ARGUMENTS : */ /* _ None */ /*===================================================================*/ -static void normalize_arr(Word16 *arr, Word16 *qf, Word16 size, Word16 hdr) +static void normalize_arr( Word16 *arr, Word16 *qf, Word16 size, Word16 hdr ) { Word16 i; Word16 max_s = 0; - FOR(i = 0; i < size; i++) + FOR( i = 0; i < size; i++ ) { - max_s=s_max(max_s, abs_s(arr[i])); + max_s = s_max( max_s, abs_s( arr[i] ) ); } - *qf=norm_s((Word16)max_s); + *qf = norm_s( (Word16) max_s ); test(); - IF((*qf == 0)&&(((Word16)max_s)==0)) + IF( ( *qf == 0 ) && ( ( (Word16) max_s ) == 0 ) ) { *qf = 15; move16(); } - *qf = *qf-hdr; + *qf = *qf - hdr; - FOR (i = 0; i < size; i++) + FOR( i = 0; i < size; i++ ) { - arr[i] = shl(arr[i], *qf); + arr[i] = shl( arr[i], *qf ); move16(); /* saturation can occur here */ } @@ -72,7 +72,7 @@ static void normalize_arr(Word16 *arr, Word16 *qf, Word16 size, Word16 hdr) /*-------------------------------------------------------------------*/ /* OUTPUT ARGUMENTS : */ /* _ (Word16[]) exc_nelp : adapt. excitation/total exc (Q0) */ -/* (Word16[]) gain_buf : floating pitch gain for each subframe */ +/* (Word16[]) gain_buf : floating pitch gain for each subframe */ /*-------------------------------------------------------------------*/ /* _ (Word16[]) shape1_filt_mem_dec : filter memory (Q0) */ @@ -85,16 +85,14 @@ static void normalize_arr(Word16 *arr, Word16 *qf, Word16 size, Word16 hdr) /* _ None */ /*===================================================================*/ -void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word16 *Q_exc, Word16 bfi, const Word16 coder_type - , Word16 *gain_buf - ) +void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word16 *Q_exc, Word16 bfi, const Word16 coder_type, Word16 *gain_buf ) { Word16 i, fid = 0; Word16 ptr[L_FRAME], filtRes[L_FRAME], gain_fac; /*ptr, filtRes - Q0, gain_fac - Q14 */ - Word16 Gains[10]; /* Q0 */ + Word16 Gains[10]; /* Q0 */ Word32 Gain, E3, E2; Word16 BP1_ORDER = 4; - Word16 ptr_tmp[L_FRAME]; /* Q0 */ + Word16 ptr_tmp[L_FRAME]; /* Q0 */ Word16 iG1, iG2[2]; Word16 exp_E2, exp_E3, frac_E2, frac_E3; Word16 tmp, scale, exp, frac; @@ -103,12 +101,12 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 Word32 max_exc_sqr; Word16 n; Word16 max_val = 0, norm_val = 0; - Word16 qGain=0; + Word16 qGain = 0; SC_VBR_DEC_HANDLE hSC_VBR; hSC_VBR = st_fx->hSC_VBR; - if (EQ_16(st_fx->last_nelp_mode_dec,1)&&NE_16(st_fx->bwidth,st_fx->last_bwidth)) + if ( EQ_16( st_fx->last_nelp_mode_dec, 1 ) && NE_16( st_fx->bwidth, st_fx->last_bwidth ) ) { st_fx->last_nelp_mode_dec = 0; } @@ -116,37 +114,37 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 test(); test(); test(); - IF ( EQ_16(coder_type,UNVOICED)&&EQ_16(st_fx->bwidth,NB)) + IF( EQ_16( coder_type, UNVOICED ) && EQ_16( st_fx->bwidth, NB ) ) { - IF (NE_16(st_fx->last_nelp_mode_dec,1)) + IF( NE_16( st_fx->last_nelp_mode_dec, 1 ) ) { BP1_ORDER = 7; move16(); - set32_fx(hSC_VBR->bp1_filt_mem_nb_dec_fx, 0, BP1_ORDER*2); + set32_fx( hSC_VBR->bp1_filt_mem_nb_dec_fx, 0, BP1_ORDER * 2 ); } } - ELSE IF ( EQ_16(coder_type,UNVOICED)&&(EQ_16(st_fx->bwidth,WB)||EQ_16(st_fx->bwidth,SWB))) + ELSE IF( EQ_16( coder_type, UNVOICED ) && ( EQ_16( st_fx->bwidth, WB ) || EQ_16( st_fx->bwidth, SWB ) ) ) { - BP1_ORDER =4; + BP1_ORDER = 4; move16(); - IF (NE_16(st_fx->last_nelp_mode_dec,1)) + IF( NE_16( st_fx->last_nelp_mode_dec, 1 ) ) { - set16_fx(hSC_VBR->bp1_filt_mem_wb_dec_fx, 0 , BP1_ORDER*2); + set16_fx( hSC_VBR->bp1_filt_mem_wb_dec_fx, 0, BP1_ORDER * 2 ); } } - IF (NE_16(st_fx->last_nelp_mode_dec,1)) + IF( NE_16( st_fx->last_nelp_mode_dec, 1 ) ) { - set16_fx(hSC_VBR->shape1_filt_mem_dec_fx, 0, 10); - set16_fx(hSC_VBR->shape2_filt_mem_dec_fx, 0, 10); - set16_fx(hSC_VBR->shape3_filt_mem_dec_fx, 0, 10); + set16_fx( hSC_VBR->shape1_filt_mem_dec_fx, 0, 10 ); + set16_fx( hSC_VBR->shape2_filt_mem_dec_fx, 0, 10 ); + set16_fx( hSC_VBR->shape3_filt_mem_dec_fx, 0, 10 ); } - IF (bfi == 0) + IF( bfi == 0 ) { test(); - IF(EQ_16(st_fx->rf_frame_type,RF_NELP)&&EQ_16(st_fx->use_partial_copy,1)) + IF( EQ_16( st_fx->rf_frame_type, RF_NELP ) && EQ_16( st_fx->use_partial_copy, 1 ) ) { iG1 = st_fx->rf_indx_nelp_iG1; iG2[0] = st_fx->rf_indx_nelp_iG2[0]; @@ -155,75 +153,75 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 ELSE { /* Do Unvoiced/NELP Decoding */ - iG1 =(Word16) get_next_indice( st_fx, 5 ); + iG1 = (Word16) get_next_indice( st_fx, 5 ); move16(); - iG2[0] =(Word16) get_next_indice( st_fx, 6 ); + iG2[0] = (Word16) get_next_indice( st_fx, 6 ); move16(); - iG2[1] =(Word16) get_next_indice( st_fx, 6 ); + iG2[1] = (Word16) get_next_indice( st_fx, 6 ); move16(); } test(); test(); - IF ( EQ_16(coder_type,UNVOICED)&&(EQ_16(st_fx->bwidth,WB)||EQ_16(st_fx->bwidth,SWB))) + IF( EQ_16( coder_type, UNVOICED ) && ( EQ_16( st_fx->bwidth, WB ) || EQ_16( st_fx->bwidth, SWB ) ) ) { test(); - IF(EQ_16(st_fx->rf_frame_type,RF_NELP)&&EQ_16(st_fx->use_partial_copy,1)) + IF( EQ_16( st_fx->rf_frame_type, RF_NELP ) && EQ_16( st_fx->use_partial_copy, 1 ) ) { fid = st_fx->rf_indx_nelp_fid; } ELSE { - fid = (Word16)get_next_indice( st_fx, 2 ); + fid = (Word16) get_next_indice( st_fx, 2 ); move16(); } } - *Q_exc = dequantize_uvg_fx(iG1, iG2, Gains, st_fx->bwidth ,1 ); - move16();/* Gains - Q0/Q3 */ + *Q_exc = dequantize_uvg_fx( iG1, iG2, Gains, st_fx->bwidth, 1 ); + move16(); /* Gains - Q0/Q3 */ } ELSE { - FOR (i=1; i<=L_SUBFR; i++) + FOR( i = 1; i <= L_SUBFR; i++ ) { - exc_sqr[i-1] = L_mult0(exc[-i],exc[-i]); - move32();/*2*Q_exc */ + exc_sqr[i - 1] = L_mult0( exc[-i], exc[-i] ); + move32(); /*2*Q_exc */ } - max_exc_sqr = L_deposit_l(0); - FOR (i=0; ibwidth,WB)||EQ_16(st_fx->bwidth,SWB))) + if ( EQ_16( coder_type, UNVOICED ) && ( EQ_16( st_fx->bwidth, WB ) || EQ_16( st_fx->bwidth, SWB ) ) ) { gain_fac = 19005; move16(); /* 1.16f - Q14 */ } - IF (EQ_16(st_fx->bwidth,WB)||EQ_16(st_fx->bwidth,SWB)) + IF( EQ_16( st_fx->bwidth, WB ) || EQ_16( st_fx->bwidth, SWB ) ) { /* Normalize Gains[10] with headroom 4, qGain is the new Q value os Gains, not Q0*/ /* This is done to avoid internal overflow observed in the wb bp filter below, similar to encoder */ - normalize_arr(Gains, &qGain, 10, 4); + normalize_arr( Gains, &qGain, 10, 4 ); } - generate_nelp_excitation_fx(&(hSC_VBR->nelp_dec_seed), Gains, ptr, gain_fac); + generate_nelp_excitation_fx( &( hSC_VBR->nelp_dec_seed ), Gains, ptr, gain_fac ); /* o: ptr = nelp_exc in Q=qGain, qGain = 0 always for NB */ test(); test(); - IF ( EQ_16(coder_type,UNVOICED )&&(EQ_16(st_fx->bwidth,WB)||EQ_16(st_fx->bwidth,SWB))) + IF( EQ_16( coder_type, UNVOICED ) && ( EQ_16( st_fx->bwidth, WB ) || EQ_16( st_fx->bwidth, SWB ) ) ) { - BP1_ORDER =4; + BP1_ORDER = 4; move16(); - Scale_sig(hSC_VBR->bp1_filt_mem_wb_dec_fx, 2*BP1_ORDER, qGain); /* bring filter prev memory from Q0 to qGain */ - pz_filter_sp_fx(bp1_num_coef_wb_fx, bp1_den_coef_wb_fx, ptr, ptr_tmp, hSC_VBR->bp1_filt_mem_wb_dec_fx, - BP1_ORDER, BP1_ORDER, L_FRAME, (sub(16,BP1_COEF_WB_QF))); + Scale_sig( hSC_VBR->bp1_filt_mem_wb_dec_fx, 2 * BP1_ORDER, qGain ); /* bring filter prev memory from Q0 to qGain */ + pz_filter_sp_fx( bp1_num_coef_wb_fx, bp1_den_coef_wb_fx, ptr, ptr_tmp, hSC_VBR->bp1_filt_mem_wb_dec_fx, + BP1_ORDER, BP1_ORDER, L_FRAME, ( sub( 16, BP1_COEF_WB_QF ) ) ); - Scale_sig(hSC_VBR->bp1_filt_mem_wb_dec_fx, 2*BP1_ORDER, -qGain); /* bring filter prev memory from qGain to Q0 */ - Scale_sig(ptr_tmp, L_FRAME, -qGain); /* bring nelp_exc to Q0 */ - Copy(ptr_tmp,ptr,L_FRAME); + Scale_sig( hSC_VBR->bp1_filt_mem_wb_dec_fx, 2 * BP1_ORDER, -qGain ); /* bring filter prev memory from qGain to Q0 */ + Scale_sig( ptr_tmp, L_FRAME, -qGain ); /* bring nelp_exc to Q0 */ + Copy( ptr_tmp, ptr, L_FRAME ); } test(); - IF ( EQ_16(coder_type,UNVOICED )&&(EQ_16(st_fx->bwidth,NB))) + IF( EQ_16( coder_type, UNVOICED ) && ( EQ_16( st_fx->bwidth, NB ) ) ) { BP1_ORDER = 7; move16(); - FOR (i=0; i < L_FRAME; i++ ) + FOR( i = 0; i < L_FRAME; i++ ) { max_val = s_max( ptr[i], max_val ); } - tmp = shl(BP1_ORDER,1); - FOR (i=0; i < tmp; i++ ) + tmp = shl( BP1_ORDER, 1 ); + FOR( i = 0; i < tmp; i++ ) { - max_val = s_max( round_fx( L_shr(hSC_VBR->bp1_filt_mem_nb_dec_fx[i], 16)), max_val ); + max_val = s_max( round_fx( L_shr( hSC_VBR->bp1_filt_mem_nb_dec_fx[i], 16 ) ), max_val ); } - norm_val = norm_s(max_val); + norm_val = norm_s( max_val ); - norm_val = s_max (0, sub(norm_val, 4)); /* 4 bit head room */ + norm_val = s_max( 0, sub( norm_val, 4 ) ); /* 4 bit head room */ - norm_val = s_min ( norm_val,8); /* scale only for very low level signals */ + norm_val = s_min( norm_val, 8 ); /* scale only for very low level signals */ - IF ( norm_val > 0 ) + IF( norm_val > 0 ) { - Scale_sig32(hSC_VBR->bp1_filt_mem_nb_dec_fx, shl(BP1_ORDER,1), norm_val) ; - Scale_sig(ptr, L_FRAME, norm_val); + Scale_sig32( hSC_VBR->bp1_filt_mem_nb_dec_fx, shl( BP1_ORDER, 1 ), norm_val ); + Scale_sig( ptr, L_FRAME, norm_val ); *Q_exc = add( norm_val, *Q_exc ); } BP1_ORDER = 7; move16(); - pz_filter_dp_fx(bp1_num_coef_nb_fx_order7, bp1_den_coef_nb_fx_order7, ptr, ptr_tmp, hSC_VBR->bp1_filt_mem_nb_dec_fx, - BP1_ORDER, BP1_ORDER, L_FRAME, (sub(16,BP1_COEF_NB_QF_ORDER7))); + pz_filter_dp_fx( bp1_num_coef_nb_fx_order7, bp1_den_coef_nb_fx_order7, ptr, ptr_tmp, hSC_VBR->bp1_filt_mem_nb_dec_fx, + BP1_ORDER, BP1_ORDER, L_FRAME, ( sub( 16, BP1_COEF_NB_QF_ORDER7 ) ) ); - IF ( norm_val > 0 ) + IF( norm_val > 0 ) { - Scale_sig32(hSC_VBR->bp1_filt_mem_nb_dec_fx, shl(BP1_ORDER,1), -norm_val) ; - + Scale_sig32( hSC_VBR->bp1_filt_mem_nb_dec_fx, shl( BP1_ORDER, 1 ), -norm_val ); } - Copy(ptr_tmp,ptr,L_FRAME); /*Q_exc */ + Copy( ptr_tmp, ptr, L_FRAME ); /*Q_exc */ } - E3 = L_deposit_l(1); - FOR (i=0 ; ibwidth,WB)||EQ_16(st_fx->bwidth,SWB))) + IF( EQ_16( coder_type, UNVOICED ) && ( EQ_16( st_fx->bwidth, WB ) || EQ_16( st_fx->bwidth, SWB ) ) ) { - pz_filter_sp_fx(shape1_num_coef_fx, shape1_den_coef_fx, ptr, ptr_tmp, hSC_VBR->shape1_filt_mem_dec_fx, - 10, 10, L_FRAME, (sub(16,SHAPE1_COEF_QF))); - Copy(ptr_tmp,ptr,L_FRAME); /*Q_exc */ + pz_filter_sp_fx( shape1_num_coef_fx, shape1_den_coef_fx, ptr, ptr_tmp, hSC_VBR->shape1_filt_mem_dec_fx, + 10, 10, L_FRAME, ( sub( 16, SHAPE1_COEF_QF ) ) ); + Copy( ptr_tmp, ptr, L_FRAME ); /*Q_exc */ - SWITCH(fid) + SWITCH( fid ) { - case 1: - /* Update other filter memory */ - pz_filter_sp_fx(shape3_num_coef_fx, shape3_den_coef_fx, ptr, filtRes, hSC_VBR->shape3_filt_mem_dec_fx, - 10, 10, L_FRAME, (sub(16,SHAPE3_COEF_QF))); - - /* filter the residual to desired shape */ - pz_filter_sp_fx(shape2_num_coef_fx, shape2_den_coef_fx, ptr, ptr_tmp, hSC_VBR->shape2_filt_mem_dec_fx, - 10, 10, L_FRAME, (sub(16,SHAPE2_COEF_QF))); - - Copy(ptr_tmp,ptr,L_FRAME); /*Q_exc */ - - BREAK; - case 2: - /* Update other filter memory */ - pz_filter_sp_fx(shape2_num_coef_fx, shape2_den_coef_fx, ptr, filtRes, hSC_VBR->shape2_filt_mem_dec_fx, - 10, 10, L_FRAME, (sub(16,SHAPE2_COEF_QF))); - - /* filter the residual to desired shape */ - pz_filter_sp_fx(shape3_num_coef_fx, shape3_den_coef_fx, ptr, ptr_tmp, hSC_VBR->shape3_filt_mem_dec_fx, - 10, 10, L_FRAME, (sub(16,SHAPE3_COEF_QF))); - - Copy(ptr_tmp,ptr,L_FRAME); /*Q_exc */ - - BREAK; - default: - /* Update other filter memory */ - pz_filter_sp_fx(shape2_num_coef_fx, shape2_den_coef_fx, ptr, filtRes, hSC_VBR->shape2_filt_mem_dec_fx, - 10, 10, L_FRAME, (sub(16,SHAPE2_COEF_QF))); - pz_filter_sp_fx(shape3_num_coef_fx, shape3_den_coef_fx, ptr, filtRes, hSC_VBR->shape3_filt_mem_dec_fx, - 10, 10, L_FRAME, (sub(16,SHAPE3_COEF_QF))); - - BREAK; + case 1: + /* Update other filter memory */ + pz_filter_sp_fx( shape3_num_coef_fx, shape3_den_coef_fx, ptr, filtRes, hSC_VBR->shape3_filt_mem_dec_fx, + 10, 10, L_FRAME, ( sub( 16, SHAPE3_COEF_QF ) ) ); + + /* filter the residual to desired shape */ + pz_filter_sp_fx( shape2_num_coef_fx, shape2_den_coef_fx, ptr, ptr_tmp, hSC_VBR->shape2_filt_mem_dec_fx, + 10, 10, L_FRAME, ( sub( 16, SHAPE2_COEF_QF ) ) ); + + Copy( ptr_tmp, ptr, L_FRAME ); /*Q_exc */ + + BREAK; + case 2: + /* Update other filter memory */ + pz_filter_sp_fx( shape2_num_coef_fx, shape2_den_coef_fx, ptr, filtRes, hSC_VBR->shape2_filt_mem_dec_fx, + 10, 10, L_FRAME, ( sub( 16, SHAPE2_COEF_QF ) ) ); + + /* filter the residual to desired shape */ + pz_filter_sp_fx( shape3_num_coef_fx, shape3_den_coef_fx, ptr, ptr_tmp, hSC_VBR->shape3_filt_mem_dec_fx, + 10, 10, L_FRAME, ( sub( 16, SHAPE3_COEF_QF ) ) ); + + Copy( ptr_tmp, ptr, L_FRAME ); /*Q_exc */ + + BREAK; + default: + /* Update other filter memory */ + pz_filter_sp_fx( shape2_num_coef_fx, shape2_den_coef_fx, ptr, filtRes, hSC_VBR->shape2_filt_mem_dec_fx, + 10, 10, L_FRAME, ( sub( 16, SHAPE2_COEF_QF ) ) ); + pz_filter_sp_fx( shape3_num_coef_fx, shape3_den_coef_fx, ptr, filtRes, hSC_VBR->shape3_filt_mem_dec_fx, + 10, 10, L_FRAME, ( sub( 16, SHAPE3_COEF_QF ) ) ); + + BREAK; } - E2 = L_deposit_l(1); - FOR (i=0 ; i -#include "options.h" /* Compilation switches */ +#include "options.h" /* Compilation switches */ #include "prot_fx1.h" #include "prot_fx2.h" #include "rom_com.h" #include "enh64.h" -#define PK_VQ_NOISE_DELTA ((Word16)3277) /* 0.1 in Q15 */ +#define PK_VQ_NOISE_DELTA ( (Word16) 3277 ) /* 0.1 in Q15 */ /*------------------------------------------------------------------------* * Local function prototypes *------------------------------------------------------------------------*/ -static void dequant_peaks_fx( Decoder_State *st_fx, Word32 *vect_out, const Word32 *peak_gain); -static Word16 hvq_dec_pos_fx(Decoder_State *st_fx, Word16 *pos_vec, const Word16 length, const Word16 num_peaks ); -static Word16 sparse_dec_pos_fx(Decoder_State *st_fx, Word16 *out, const Word16 length ); -static void peak_vq_dec_fx(Decoder_State* st_fx, Word32* coefs_out, const Word32 brate, const Word16 num_bits, const Word16* ynrm, - Word16* R, Word16* vq_peak_idx, Word16* Npeaks, const Word16 core); +static void dequant_peaks_fx( Decoder_State *st_fx, Word32 *vect_out, const Word32 *peak_gain ); +static Word16 hvq_dec_pos_fx( Decoder_State *st_fx, Word16 *pos_vec, const Word16 length, const Word16 num_peaks ); +static Word16 sparse_dec_pos_fx( Decoder_State *st_fx, Word16 *out, const Word16 length ); +static void peak_vq_dec_fx( Decoder_State *st_fx, Word32 *coefs_out, const Word32 brate, const Word16 num_bits, const Word16 *ynrm, Word16 *R, Word16 *vq_peak_idx, Word16 *Npeaks, const Word16 core ); /*-------------------------------------------------------------------------- * hvq_dec_fx() * @@ -27,16 +26,16 @@ static void peak_vq_dec_fx(Decoder_State* st_fx, Word32* coefs_out, const Word32 *--------------------------------------------------------------------------*/ void hvq_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 num_bits, /* i : Number of available bits */ - const Word32 core_brate, /* i : Core bit-rate */ - const Word16 *ynrm, /* i : Envelope coefficients */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 num_bits, /* i : Number of available bits */ + const Word32 core_brate, /* i : Core bit-rate */ + const Word16 *ynrm, /* i : Envelope coefficients */ Word16 *R, /* i/o: Bit allocation/updated bit allocation */ Word16 *noise_level, /* o : Noise level in Q15 */ Word16 *peak_idx, /* o : Peak position vector */ Word16 *Npeaks, /* o : Total number of peaks */ Word32 *coefsq_norm, /* o : Output vector in Q12 */ - const Word16 core /* i : Core */ + const Word16 core /* i : Core */ ) { Word16 i; @@ -48,10 +47,10 @@ void hvq_dec_fx( FOR( i = 0; i < HVQ_BWE_NOISE_BANDS; i++ ) { noise_level_idx = get_next_indice( st_fx, 2 ); /* 2-bits => max noise_level-idx = 3 */ - noise_level[i] = i_mult(noise_level_idx, PK_VQ_NOISE_DELTA); - move16();/* max noise_level=3*0.1 => Q15 is good enough */ + noise_level[i] = i_mult( noise_level_idx, PK_VQ_NOISE_DELTA ); + move16(); /* max noise_level=3*0.1 => Q15 is good enough */ - bits = sub(bits, 2); + bits = sub( bits, 2 ); } peak_vq_dec_fx( st_fx, coefsq_norm, core_brate, bits, ynrm, R, peak_idx, @@ -65,16 +64,15 @@ void hvq_dec_fx( *--------------------------------------------------------------------------*/ static void peak_vq_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word32 *coefs_out, /* o : Output coefficient vector Q12 */ - const Word32 core_brate, /* i : Core bitrate */ - const Word16 num_bits, /* i : Number of bits for HVQ */ - const Word16 *ynrm, /* i : Envelope coefficients */ - Word16 *R, /* i/o: Bit allocation/updated bit allocation */ - Word16 *vq_peak_idx, /* o : Peak position vector */ - Word16 *Npeaks, /* o : Number of peaks */ - const Word16 core -) + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word32 *coefs_out, /* o : Output coefficient vector Q12 */ + const Word32 core_brate, /* i : Core bitrate */ + const Word16 num_bits, /* i : Number of bits for HVQ */ + const Word16 *ynrm, /* i : Envelope coefficients */ + Word16 *R, /* i/o: Bit allocation/updated bit allocation */ + Word16 *vq_peak_idx, /* o : Peak position vector */ + Word16 *Npeaks, /* o : Number of peaks */ + const Word16 core ) { Word16 vq_peaks, i, j, k, FlagN, hcode_l, diff; Word16 bin_th, bin_th2, max_peaks, pvq_bands; @@ -95,7 +93,7 @@ static void peak_vq_dec_fx( UWord16 dontCare; Word32 acc; Word16 *pPvqVector; - Word32 manE_peak, manPeakGains, manPkEnrg; /* Due to very wide dynamic range, use floating point format, i.e., (man, exp) */ + Word32 manE_peak, manPeakGains, manPkEnrg; /* Due to very wide dynamic range, use floating point format, i.e., (man, exp) */ Word16 expE_peak, expPeakGains, expPkEnrg; Word16 *pSelBnds; Word16 sel_bnds[HVQ_NUM_SFM_24k]; @@ -114,38 +112,38 @@ static void peak_vq_dec_fx( set16_fx( npulses, 0, MAX_PVQ_BANDS ); set16_fx( pvq_inp_vector, 0, HVQ_PVQ_BUF_LEN ); - assert((core_brate > HQ_16k40 && core_brate <= HQ_48k) && "HVQ rate not supported"); - //PMT("max_peaks equation needs to be converted") - max_peaks = (Word16)((core_brate * HVQ_PEAKS_PER_DELTA + HVQ_PEAKS_PER_DELTA_OFFS) / HVQ_PEAKS_BPS_DELTA); + assert( ( core_brate > HQ_16k40 && core_brate <= HQ_48k ) && "HVQ rate not supported" ); + // PMT("max_peaks equation needs to be converted") + max_peaks = (Word16) ( ( core_brate * HVQ_PEAKS_PER_DELTA + HVQ_PEAKS_PER_DELTA_OFFS ) / HVQ_PEAKS_BPS_DELTA ); /*max_peaks = ((core_brate * HVQ_PEAKS_PER_DELTA / HVQ_PEAKS_BPS_DELTA + HVQ_PEAKS_PER_DELTA_OFFS / HVQ_PEAKS_BPS_DELTA) );*/ #if 0 { - #define INV_HVQ_PEAKS_BPS_DELTA_Q31 (Word32)((1.0f/HVQ_PEAKS_BPS_DELTA)*(1<<31)) - #define DELTAINV_HVQ_PEAKS_BPS_DELTA_Q31 (Word32)(((float)HVQ_PEAKS_PER_DELTA/HVQ_PEAKS_BPS_DELTA)*(1<<31)) +#define INV_HVQ_PEAKS_BPS_DELTA_Q31 ( Word32 )( ( 1.0f / HVQ_PEAKS_BPS_DELTA ) * ( 1 << 31 ) ) +#define DELTAINV_HVQ_PEAKS_BPS_DELTA_Q31 ( Word32 )( ( (float) HVQ_PEAKS_PER_DELTA / HVQ_PEAKS_BPS_DELTA ) * ( 1 << 31 ) ) max_peaks = W_round32_s(W_add(W_mult_32_32(HVQ_PEAKS_PER_DELTA_OFFS, INV_HVQ_PEAKS_BPS_DELTA_Q31), W_mult_32_32(core_brate, DELTAINV_HVQ_PEAKS_BPS_DELTA_Q31))); printf("Fixed point code needed to be completed"); } #endif bin_th = HVQ_THRES_BIN_24k; - bin_th2 = HVQ_THRES_BIN_24k/HVQ_NF_GROUPS; - IF (GE_32(core_brate, HQ_BWE_CROSSOVER_BRATE)) + bin_th2 = HVQ_THRES_BIN_24k / HVQ_NF_GROUPS; + IF( GE_32( core_brate, HQ_BWE_CROSSOVER_BRATE ) ) { bin_th = HVQ_THRES_BIN_32k; - bin_th2 = HVQ_THRES_BIN_32k/HVQ_NF_GROUPS; + bin_th2 = HVQ_THRES_BIN_32k / HVQ_NF_GROUPS; move16(); } /* Get number of peaks */ vq_peaks = get_next_indice( st_fx, 5 ); - vq_peaks = sub(max_peaks, vq_peaks); + vq_peaks = sub( max_peaks, vq_peaks ); *Npeaks = vq_peaks; move16(); diff = 5; move16(); /* safety check in case of bit errors */ - IF( LT_16(*Npeaks, HVQ_MIN_PEAKS)) + IF( LT_16( *Npeaks, HVQ_MIN_PEAKS ) ) { st_fx->BER_detect = 1; move16(); @@ -156,22 +154,22 @@ static void peak_vq_dec_fx( } /* De-quantize peak positions */ - FOR (i = 0; i < bin_th; i++) + FOR( i = 0; i < bin_th; i++ ) { res_vec[i] = 0; move16(); } /* Unpack PVQ codewords */ - pos_bits = hvq_dec_pos_fx(st_fx, res_vec, bin_th, vq_peaks); - diff = add(diff, pos_bits); + pos_bits = hvq_dec_pos_fx( st_fx, res_vec, bin_th, vq_peaks ); + diff = add( diff, pos_bits ); j = 0; move16(); test(); - FOR (i = 0; i < bin_th && j < vq_peaks; i++) /* safety check in case of bit errors */ + FOR( i = 0; i < bin_th && j < vq_peaks; i++ ) /* safety check in case of bit errors */ { - IF ( res_vec[i] != 0) + IF( res_vec[i] != 0 ) { vq_peak_idx[j++] = i; move16(); @@ -179,12 +177,12 @@ static void peak_vq_dec_fx( } /* safety check in case of bit errors */ - IF( LT_16(j, vq_peaks)) + IF( LT_16( j, vq_peaks ) ) { st_fx->BER_detect = 1; move16(); - vq_peaks = sub(j, 1); - *Npeaks = sub(j, 1); + vq_peaks = sub( j, 1 ); + *Npeaks = sub( j, 1 ); } /* Huffman or differential coding */ @@ -194,50 +192,51 @@ static void peak_vq_dec_fx( pgain_difidx[0] = get_next_indice( st_fx, GAIN0_BITS ); /* safety check in case of bit errors */ - IF( GT_16(pgain_difidx[0], 44)) + IF( GT_16( pgain_difidx[0], 44 ) ) { st_fx->BER_detect = 1; move16(); pgain_difidx[0] = 44; move16(); } - peak_gains_fx[0] = dicn_pg_fx[pgain_difidx[0]]; /* Q12 */ move32(); - if (res_vec[vq_peak_idx[0]] < 0) + peak_gains_fx[0] = dicn_pg_fx[pgain_difidx[0]]; /* Q12 */ + move32(); + if ( res_vec[vq_peak_idx[0]] < 0 ) { - peak_gains_fx[0] = L_negate(peak_gains_fx[0]); + peak_gains_fx[0] = L_negate( peak_gains_fx[0] ); move16(); } hcode_l = 0; move16(); - IF (FlagN) + IF( FlagN ) { - huff_dec_fx( st_fx, vq_peaks-1, MAX_PG_HUFFLEN, NUM_PG_HUFFLEN, hvq_pg_huff_thres, hvq_pg_huff_offset, hvq_pg_huff_tab, &pgain_difidx[1] ); + huff_dec_fx( st_fx, vq_peaks - 1, MAX_PG_HUFFLEN, NUM_PG_HUFFLEN, hvq_pg_huff_thres, hvq_pg_huff_offset, hvq_pg_huff_tab, &pgain_difidx[1] ); - FOR (i = 1; i < vq_peaks; i++) + FOR( i = 1; i < vq_peaks; i++ ) { - hcode_l = add(hcode_l, pgain_huffsizn[pgain_difidx[i]]); - move16();/* indirect addressing*/ + hcode_l = add( hcode_l, pgain_huffsizn[pgain_difidx[i]] ); + move16(); /* indirect addressing*/ } } ELSE { - FOR (i = 1; i < vq_peaks; i++) + FOR( i = 1; i < vq_peaks; i++ ) { - pgain_difidx[i] = get_next_indice(st_fx, GAINI_BITS ); + pgain_difidx[i] = get_next_indice( st_fx, GAINI_BITS ); move16(); - hcode_l = add(hcode_l, GAINI_BITS); + hcode_l = add( hcode_l, GAINI_BITS ); } } - FOR (i = 1; i < vq_peaks; i++) + FOR( i = 1; i < vq_peaks; i++ ) { - pgain_difidx[i] = add(pgain_difidx[i], sub(pgain_difidx[i - 1],15)); + pgain_difidx[i] = add( pgain_difidx[i], sub( pgain_difidx[i - 1], 15 ) ); move16(); /* safety check in case of bit errors */ test(); - IF( GT_16(pgain_difidx[i], 44)||pgain_difidx[i]<0) + IF( GT_16( pgain_difidx[i], 44 ) || pgain_difidx[i] < 0 ) { st_fx->BER_detect = 1; move16(); @@ -246,115 +245,116 @@ static void peak_vq_dec_fx( } peak_gains_fx[i] = dicn_pg_fx[pgain_difidx[i]]; - move32();/* Q12 move16(); */ - if (res_vec[vq_peak_idx[i]] < 0) + move32(); /* Q12 move16(); */ + if ( res_vec[vq_peak_idx[i]] < 0 ) { - peak_gains_fx[i] = L_negate(peak_gains_fx[i]); + peak_gains_fx[i] = L_negate( peak_gains_fx[i] ); move32(); } } /* Scale up peak gains and accumulate peak energy */ - manE_peak = L_deposit_l(0); + manE_peak = L_deposit_l( 0 ); expE_peak = 32; move16(); - FOR (i = 0; i < vq_peaks; i++) + FOR( i = 0; i < vq_peaks; i++ ) { - peak_gains_fx[i] = L_shl(peak_gains_fx[i], 2); + peak_gains_fx[i] = L_shl( peak_gains_fx[i], 2 ); move32(); /* Q12 */ /* Use floating point operation to deal with wide dynamic range. * 32-bit mantissa is used here. It should be even more accurate than * the floating-point reference code with 24-bit mantissa! */ - tmp = L_shl(dicn_pg_fx[pgain_difidx[i]], 2); - expPeakGains = norm_l(tmp); - manPeakGains = L_shl(tmp, expPeakGains); - Mpy_32_32_ss(manPeakGains, manPeakGains, &manPkEnrg, &lsb); /* peak_gains square */ - expPkEnrg = shl(expPeakGains, 1); /* Multiply by 2 due to squaring. */ + tmp = L_shl( dicn_pg_fx[pgain_difidx[i]], 2 ); + expPeakGains = norm_l( tmp ); + manPeakGains = L_shl( tmp, expPeakGains ); + Mpy_32_32_ss( manPeakGains, manPeakGains, &manPkEnrg, &lsb ); /* peak_gains square */ + expPkEnrg = shl( expPeakGains, 1 ); /* Multiply by 2 due to squaring. */ - floating_point_add(&manE_peak, &expE_peak, manPkEnrg, expPkEnrg); + floating_point_add( &manE_peak, &expE_peak, manPkEnrg, expPkEnrg ); } /* Number of bits used for peak gain quantization */ - diff = add(diff, add(FLAGN_BITS + GAIN0_BITS, hcode_l)); + diff = add( diff, add( FLAGN_BITS + GAIN0_BITS, hcode_l ) ); /* De-quantize peaks */ - FOR (i = 0; i < vq_peaks; i++) + FOR( i = 0; i < vq_peaks; i++ ) { - dequant_peaks_fx( st_fx, &coefs_out[vq_peak_idx[i]-2], &peak_gains_fx[i]); /* coefs_out in Q12, peak_gains_fx in Q14 */ - diff = add(diff, 9); + dequant_peaks_fx( st_fx, &coefs_out[vq_peak_idx[i] - 2], &peak_gains_fx[i] ); /* coefs_out in Q12, peak_gains_fx in Q14 */ + diff = add( diff, 9 ); } - FOR (i = 0; i < HVQ_NF_GROUPS; i++) + FOR( i = 0; i < HVQ_NF_GROUPS; i++ ) { nf_gains_idx[i] = get_next_indice( st_fx, 5 ); move16(); - nf_gains_fx[i] = L_shr(dicn_fx[nf_gains_idx[i]],1); + nf_gains_fx[i] = L_shr( dicn_fx[nf_gains_idx[i]], 1 ); move32(); /* nf_gains in Q14 */ - diff = add(diff, 5); + diff = add( diff, 5 ); } - pvq_bits = sub(num_bits, diff); + pvq_bits = sub( num_bits, diff ); /* Calculate number of PVQ bands to code and assign bits */ - pvq_bands = hvq_pvq_bitalloc_fx(pvq_bits, core_brate, st_fx->bwidth, ynrm, manE_peak, expE_peak, Rk, R, sel_bnds, - &n_sel_bnds); + pvq_bands = hvq_pvq_bitalloc_fx( pvq_bits, core_brate, st_fx->bwidth, ynrm, manE_peak, expE_peak, Rk, R, sel_bnds, + &n_sel_bnds ); /* safety check in case of bit errors */ test(); - if (pvq_bands == 0 && EQ_16(st_fx->element_mode, EVS_MONO)) /* PVQ bands may be zero for IVAS */ + if ( pvq_bands == 0 && EQ_16( st_fx->element_mode, EVS_MONO ) ) /* PVQ bands may be zero for IVAS */ { st_fx->BER_detect = 1; move16(); } - pvq_bits = sub(pvq_bits, i_mult2(HVQ_PVQ_GAIN_BITS, pvq_bands)); + pvq_bits = sub( pvq_bits, i_mult2( HVQ_PVQ_GAIN_BITS, pvq_bands ) ); /* Get band limits for concatenated PVQ target */ - hvq_concat_bands_fx(pvq_bands, sel_bnds, n_sel_bnds, hvq_band_start, - hvq_band_width, hvq_band_end); + hvq_concat_bands_fx( pvq_bands, sel_bnds, n_sel_bnds, hvq_band_start, + hvq_band_width, hvq_band_end ); - FOR (k = 0; k < pvq_bands; k++) + FOR( k = 0; k < pvq_bands; k++ ) { k_sort[k] = k; move16(); } - pvq_decode_frame_fx(st_fx, pvq_vector, npulses, pvq_inp_vector, hvq_band_start, hvq_band_end, hvq_band_width, pvq_bands, Rk, pvq_bits, core ); + pvq_decode_frame_fx( st_fx, pvq_vector, npulses, pvq_inp_vector, hvq_band_start, hvq_band_end, hvq_band_width, pvq_bands, Rk, pvq_bits, core ); fine_gain_pred_fx( hvq_band_start, hvq_band_end, hvq_band_width, k_sort, npulses, pvq_maxpulse, NULL, pvq_bands, pvq_vector, pvq_inp_vector, fg_pred, core ); - fine_gain_dec_fx( st_fx, k_sort, pvq_bands, gain_bits_array, fg_pred); + fine_gain_dec_fx( st_fx, k_sort, pvq_bands, gain_bits_array, fg_pred ); - apply_gain_fx(k_sort, hvq_band_start, hvq_band_end, pvq_bands, fg_pred, pvq_vector); + apply_gain_fx( k_sort, hvq_band_start, hvq_band_end, pvq_bands, fg_pred, pvq_vector ); pPvqVector = pvq_vector; pCoefsOut = coefs_out; pSelBnds = sel_bnds; move16(); - FOR (k = 0; k < pvq_bands; k++) + FOR( k = 0; k < pvq_bands; k++ ) { pvq_norm[k] = get_next_indice( st_fx, HVQ_PVQ_GAIN_BITS ); - pvq_norm[k] = add(pvq_norm[k], 8); + pvq_norm[k] = add( pvq_norm[k], 8 ); move16(); - diff = add(diff, HVQ_PVQ_GAIN_BITS); + diff = add( diff, HVQ_PVQ_GAIN_BITS ); j = 0; move16(); - IF (GE_16(k, sub(pvq_bands, n_sel_bnds))) + IF( GE_16( k, sub( pvq_bands, n_sel_bnds ) ) ) { i = band_start_harm[*pSelBnds++]; move16(); move16(); pCoefsOut = coefs_out + i; } - normq = L_add(dicn_fx[pvq_norm[k]], 0); - WHILE (LT_16(j, hvq_band_width[k])) + normq = L_add( dicn_fx[pvq_norm[k]], 0 ); + WHILE( LT_16( j, hvq_band_width[k] ) ) { - IF (EQ_32(*pCoefsOut, 0)) + IF( EQ_32( *pCoefsOut, 0 ) ) { - Mpy_32_16_ss(normq, *pPvqVector++, &acc, &dontCare); /* acc(Q11), normq(Q14), pvq_vector(Q12) */ - *pCoefsOut = L_shl(acc, 12 - 11); /* Q12 */ move32(); - j = add(j, 1); + Mpy_32_16_ss( normq, *pPvqVector++, &acc, &dontCare ); /* acc(Q11), normq(Q14), pvq_vector(Q12) */ + *pCoefsOut = L_shl( acc, 12 - 11 ); /* Q12 */ + move32(); + j = add( j, 1 ); } pCoefsOut++; } @@ -362,15 +362,16 @@ static void peak_vq_dec_fx( /* Noise fill unqantized coeffs with one gain per group */ pCoefsOut = &coefs_out[-1]; - FOR (i = 0; i < HVQ_NF_GROUPS; i++) + FOR( i = 0; i < HVQ_NF_GROUPS; i++ ) { - FOR (j = 0; j < bin_th2; j++) + FOR( j = 0; j < bin_th2; j++ ) { - IF (*(++pCoefsOut) == 0) + IF( *( ++pCoefsOut ) == 0 ) { - whiteNoise = Random(&nf_seed); /* Q15 */ - Mpy_32_16_ss(nf_gains_fx[i], whiteNoise, &acc, &dontCare); /* nf_gains_fx[] in Q14 */ - *pCoefsOut = L_shr(acc, 14-12); /* Q12 */ move32(); + whiteNoise = Random( &nf_seed ); /* Q15 */ + Mpy_32_16_ss( nf_gains_fx[i], whiteNoise, &acc, &dontCare ); /* nf_gains_fx[] in Q14 */ + *pCoefsOut = L_shr( acc, 14 - 12 ); /* Q12 */ + move32(); } } } @@ -385,9 +386,9 @@ static void peak_vq_dec_fx( *--------------------------------------------------------------------------*/ static void dequant_peaks_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word32 *vect_out, /* o : Quantized vector in Q12 */ - const Word32 *peak_gain /* i : Peak gain in Q12 */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word32 *vect_out, /* o : Quantized vector in Q12 */ + const Word32 *peak_gain /* i : Peak gain in Q12 */ ) { Word16 xq[4]; @@ -400,51 +401,53 @@ static void dequant_peaks_fx( hvq_cb_rev = get_next_indice( st_fx, 1 ); cb_idx = get_next_indice( st_fx, 8 ); - indx = shl(cb_idx,2); - IF ( hvq_cb_rev ) + indx = shl( cb_idx, 2 ); + IF( hvq_cb_rev ) { - indx = add(indx,3); + indx = add( indx, 3 ); tmp = &hvq_peak_cb_fx[indx]; - FOR (i = 0; i < 4; i++) + FOR( i = 0; i < 4; i++ ) { - xq[i] = *tmp--; /* Q15 */ move16(); + xq[i] = *tmp--; /* Q15 */ + move16(); } } ELSE { tmp = &hvq_peak_cb_fx[indx]; - FOR (i = 0; i < 4; i++) + FOR( i = 0; i < 4; i++ ) { - xq[i] = *tmp++; /* Q15 */ move16(); + xq[i] = *tmp++; /* Q15 */ + move16(); } } - absPeakGain = L_abs(peak_gain[0]); + absPeakGain = L_abs( peak_gain[0] ); - IF(vect_out[0] == 0) + IF( vect_out[0] == 0 ) { - Mpy_32_16_ss(*peak_gain, xq[0], &vect_out[0], &dontCare); /* vect_out in Q12 */ - Mpy_32_16_ss(*peak_gain, xq[1], &vect_out[1], &dontCare); /* Q12 */ + Mpy_32_16_ss( *peak_gain, xq[0], &vect_out[0], &dontCare ); /* vect_out in Q12 */ + Mpy_32_16_ss( *peak_gain, xq[1], &vect_out[1], &dontCare ); /* Q12 */ } ELSE { - absPeakGain1 = L_abs(peak_gain[-1]); - IF(LE_32(absPeakGain1, absPeakGain)) + absPeakGain1 = L_abs( peak_gain[-1] ); + IF( LE_32( absPeakGain1, absPeakGain ) ) { - Mpy_32_16_ss(*peak_gain, xq[0], &vect_out[0], &dontCare); /* vect_out in Q12 */ - Mpy_32_16_ss(*peak_gain, xq[1], &vect_out[1], &dontCare); /* Q12 */ + Mpy_32_16_ss( *peak_gain, xq[0], &vect_out[0], &dontCare ); /* vect_out in Q12 */ + Mpy_32_16_ss( *peak_gain, xq[1], &vect_out[1], &dontCare ); /* Q12 */ } ELSE { - IF(vect_out[1] == 0 || (LE_32(absPeakGain1, absPeakGain))) + IF( vect_out[1] == 0 || ( LE_32( absPeakGain1, absPeakGain ) ) ) { - Mpy_32_16_ss(*peak_gain, xq[1], &vect_out[1], &dontCare); + Mpy_32_16_ss( *peak_gain, xq[1], &vect_out[1], &dontCare ); } } } vect_out[2] = *peak_gain; /* vect_out in Q12 */ - Mpy_32_16_ss(*peak_gain, xq[2], &vect_out[3], &dontCare); - Mpy_32_16_ss(*peak_gain, xq[3], &vect_out[4], &dontCare); + Mpy_32_16_ss( *peak_gain, xq[2], &vect_out[3], &dontCare ); + Mpy_32_16_ss( *peak_gain, xq[3], &vect_out[4], &dontCare ); return; } @@ -457,10 +460,10 @@ static void dequant_peaks_fx( *--------------------------------------------------------------------------*/ static Word16 hvq_dec_pos_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *pos_vec, /* o : decoded peak positions */ - const Word16 length, /* i : length */ - const Word16 num_peaks /* i : number of peaks */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *pos_vec, /* o : decoded peak positions */ + const Word16 length, /* i : length */ + const Word16 num_peaks /* i : number of peaks */ ) { Word16 peak_idx[HVQ_MAX_PEAKS]; @@ -473,35 +476,35 @@ static Word16 hvq_dec_pos_fx( num_bits = 0; move16(); - set16_fx(pos_vec, 0, length); + set16_fx( pos_vec, 0, length ); - mode = get_next_indice(st_fx, 1); - num_bits = add(num_bits, 1); + mode = get_next_indice( st_fx, 1 ); + num_bits = add( num_bits, 1 ); - IF (mode == HVQ_CP_DELTA) + IF( mode == HVQ_CP_DELTA ) { - huff_dec_fx(st_fx, num_peaks, HVQ_CP_HUFF_MAX_CODE, HVQ_CP_HUFF_NUM_LEN, hvq_cp_huff_thres, hvq_cp_huff_offset, hvq_cp_huff_tab, delta); + huff_dec_fx( st_fx, num_peaks, HVQ_CP_HUFF_MAX_CODE, HVQ_CP_HUFF_NUM_LEN, hvq_cp_huff_thres, hvq_cp_huff_offset, hvq_cp_huff_tab, delta ); - FOR (i = 0; i < num_peaks; i++) + FOR( i = 0; i < num_peaks; i++ ) { - num_bits = add(num_bits, hvq_cp_huff_len[delta[i]]); + num_bits = add( num_bits, hvq_cp_huff_len[delta[i]] ); } - peak_idx[0] = sub(delta[0], HVQ_CP_HUFF_OFFSET); + peak_idx[0] = sub( delta[0], HVQ_CP_HUFF_OFFSET ); /* safety check in case of bit errors */ - IF (peak_idx[0] < 2) + IF( peak_idx[0] < 2 ) { peak_idx[0] = 2; move16(); st_fx->BER_detect = 1; move16(); } - FOR (i = 1; i < num_peaks; i++) + FOR( i = 1; i < num_peaks; i++ ) { - peak_idx[i] = add(add(delta[i], peak_idx[i-1]), HVQ_CP_HUFF_OFFSET); + peak_idx[i] = add( add( delta[i], peak_idx[i - 1] ), HVQ_CP_HUFF_OFFSET ); move16(); /* safety check in case of bit errors */ - IF (GE_16(peak_idx[i], HVQ_THRES_BIN_32k)) + IF( GE_16( peak_idx[i], HVQ_THRES_BIN_32k ) ) { peak_idx[i] = HVQ_THRES_BIN_32k - 1; move16(); @@ -510,7 +513,7 @@ static Word16 hvq_dec_pos_fx( } } - FOR (i = 0; i < num_peaks; i++) + FOR( i = 0; i < num_peaks; i++ ) { pos_vec[peak_idx[i]] = 1; move16(); @@ -518,13 +521,13 @@ static Word16 hvq_dec_pos_fx( } ELSE { - tmp = sparse_dec_pos_fx(st_fx, pos_vec, length); - num_bits = add(num_bits, tmp); + tmp = sparse_dec_pos_fx( st_fx, pos_vec, length ); + num_bits = add( num_bits, tmp ); } - FOR (i = 0; i < num_peaks; i++) + FOR( i = 0; i < num_peaks; i++ ) { - IF (get_next_indice_1(st_fx) == 0) + IF( get_next_indice_1( st_fx ) == 0 ) { sign_vec[i] = -1; move16(); @@ -535,17 +538,17 @@ static Word16 hvq_dec_pos_fx( move16(); } } - num_bits = add(num_bits, num_peaks); + num_bits = add( num_bits, num_peaks ); j = 0; move16(); /* safety check in case of bit errors */ test(); - FOR (i = 0; i < length && j < num_peaks; i++) + FOR( i = 0; i < length && j < num_peaks; i++ ) { - if (EQ_16(pos_vec[i], 1)) + if ( EQ_16( pos_vec[i], 1 ) ) { - pos_vec[i] = i_mult2(pos_vec[i], sign_vec[j++]); + pos_vec[i] = i_mult2( pos_vec[i], sign_vec[j++] ); move16(); } } @@ -560,9 +563,9 @@ static Word16 hvq_dec_pos_fx( *--------------------------------------------------------------------------*/ static Word16 sparse_dec_pos_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16* out, /* o : decoded peak positions */ - const Word16 length /* i : length */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *out, /* o : decoded peak positions */ + const Word16 length /* i : length */ ) { Word16 layer2[HVQ_CP_L2_MAX]; @@ -571,44 +574,44 @@ static Word16 sparse_dec_pos_fx( Word16 bits; Word16 idx, val; - set16_fx(layer2, 0, HVQ_CP_L2_MAX); - set16_fx(out, 0, length); + set16_fx( layer2, 0, HVQ_CP_L2_MAX ); + set16_fx( out, 0, length ); bits = 0; move16(); /*layer_length = (short)((float)length/HVQ_CP_L1_LEN + 0.5); */ - layer_length = round_fx(L_mult0(length, 13107)); /* 0+16-16, 13107 is 1/5 in Q16 */ + layer_length = round_fx( L_mult0( length, 13107 ) ); /* 0+16-16, 13107 is 1/5 in Q16 */ - FOR (i = 0; i < layer_length; i++) + FOR( i = 0; i < layer_length; i++ ) { - layer2[i] = get_next_indice_1(st_fx); + layer2[i] = get_next_indice_1( st_fx ); move16(); } - bits = add(bits, layer_length); + bits = add( bits, layer_length ); - FOR (j = 0; j < layer_length; j++) + FOR( j = 0; j < layer_length; j++ ) { - IF (EQ_16(layer2[j], 1)) + IF( EQ_16( layer2[j], 1 ) ) { - idx = get_next_indice(st_fx, HVQ_CP_MAP_IDX_LEN); - bits = add(bits, HVQ_CP_MAP_IDX_LEN); + idx = get_next_indice( st_fx, HVQ_CP_MAP_IDX_LEN ); + bits = add( bits, HVQ_CP_MAP_IDX_LEN ); val = hvq_cp_layer1_map5[idx]; move16(); - test(); /* safety check in case of bit errors */ - IF ( j == 0 && GT_16(val, 4)) /* out[0] and out[1] are invalid positions */ + test(); /* safety check in case of bit errors */ + IF( j == 0 && GT_16( val, 4 ) ) /* out[0] and out[1] are invalid positions */ { st_fx->BER_detect = 1; move16(); val = 4; move16(); } - tmp = i_mult2(j, HVQ_CP_L1_LEN); - FOR (i = sub(s_min(i_mult2(add(j,1), HVQ_CP_L1_LEN), length), 1); i >= tmp; i--) + tmp = i_mult2( j, HVQ_CP_L1_LEN ); + FOR( i = sub( s_min( i_mult2( add( j, 1 ), HVQ_CP_L1_LEN ), length ), 1 ); i >= tmp; i-- ) { - out[i] = s_and(val, 1); + out[i] = s_and( val, 1 ); move16(); - val = lshr(val, 1); + val = lshr( val, 1 ); } } } diff --git a/lib_dec/pit_dec_fx.c b/lib_dec/pit_dec_fx.c index b19b389df..e4e6f4806 100644 --- a/lib_dec/pit_dec_fx.c +++ b/lib_dec/pit_dec_fx.c @@ -18,29 +18,28 @@ * Decode pitch lag *----------------------------------------------------------*/ -Word32 Mode2_pit_decode( /* o: floating pitch value */ - const Word16 coder_type, /* i: coding model */ - Word16 i_subfr, /* i: subframe index */ - Word16 L_subfr, - Word16 **pt_indice, /* i/o: quantization indices pointer */ - Word16 *T0, /* i/o: close loop integer pitch */ - Word16 *T0_frac, /* o: close loop fractional part of the pitch */ - Word16 *T0_res, /* i/o: pitch resolution */ - Word16 *T0_min, /* i/o: lower limit for close-loop search */ - Word16 *T0_min_frac, /* i/o: lower limit for close-loop search */ - Word16 *T0_max, /* i/o: higher limit for close-loop search */ - Word16 *T0_max_frac, /* i/o: higher limit for close-loop search */ - Word16 pit_min, - Word16 pit_fr1, - Word16 pit_fr1b, - Word16 pit_fr2, - Word16 pit_max, - Word16 pit_res_max -) +Word32 Mode2_pit_decode( /* o: floating pitch value */ + const Word16 coder_type, /* i: coding model */ + Word16 i_subfr, /* i: subframe index */ + Word16 L_subfr, + Word16 **pt_indice, /* i/o: quantization indices pointer */ + Word16 *T0, /* i/o: close loop integer pitch */ + Word16 *T0_frac, /* o: close loop fractional part of the pitch */ + Word16 *T0_res, /* i/o: pitch resolution */ + Word16 *T0_min, /* i/o: lower limit for close-loop search */ + Word16 *T0_min_frac, /* i/o: lower limit for close-loop search */ + Word16 *T0_max, /* i/o: higher limit for close-loop search */ + Word16 *T0_max_frac, /* i/o: higher limit for close-loop search */ + Word16 pit_min, + Word16 pit_fr1, + Word16 pit_fr1b, + Word16 pit_fr2, + Word16 pit_max, + Word16 pit_res_max ) { Word32 pitch; - IF(coder_type == 0) + IF( coder_type == 0 ) { *T0 = L_subfr; move16(); @@ -49,120 +48,119 @@ Word32 Mode2_pit_decode( /* o: floating pitch value *T0_res = 1; move16(); } - ELSE IF(EQ_16(coder_type,1)) /* 8/4/4/4 (EVS) */ + ELSE IF( EQ_16( coder_type, 1 ) ) /* 8/4/4/4 (EVS) */ { - IF (i_subfr == 0) + IF( i_subfr == 0 ) { - Mode2_abs_pit_dec( T0, T0_frac, T0_res, pt_indice, pit_min, pit_fr1b, pit_min, pit_res_max); + Mode2_abs_pit_dec( T0, T0_frac, T0_res, pt_indice, pit_min, pit_fr1b, pit_min, pit_res_max ); } ELSE { - limit_T0_voiced( 4, shr(pit_res_max,1), *T0, *T0_frac, *T0_res, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); - *T0_res = shr(pit_res_max,1); + limit_T0_voiced( 4, shr( pit_res_max, 1 ), *T0, *T0_frac, *T0_res, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); + *T0_res = shr( pit_res_max, 1 ); move16(); - Mode2_delta_pit_dec( T0, T0_frac, *T0_res, T0_min, T0_min_frac, pt_indice); + Mode2_delta_pit_dec( T0, T0_frac, *T0_res, T0_min, T0_min_frac, pt_indice ); } } - ELSE IF(EQ_16(coder_type,2)) /* 8/5/8/5 (EVS) */ + ELSE IF( EQ_16( coder_type, 2 ) ) /* 8/5/8/5 (EVS) */ { test(); - IF ( ( i_subfr == 0 ) || ( EQ_16(i_subfr,shl(L_subfr,1)))) + IF( ( i_subfr == 0 ) || ( EQ_16( i_subfr, shl( L_subfr, 1 ) ) ) ) { - Mode2_abs_pit_dec( T0, T0_frac, T0_res, pt_indice, pit_min, pit_fr1b, pit_min, pit_res_max); + Mode2_abs_pit_dec( T0, T0_frac, T0_res, pt_indice, pit_min, pit_fr1b, pit_min, pit_res_max ); } ELSE { - limit_T0_voiced( 5, shr(pit_res_max,1), *T0, *T0_frac, *T0_res, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); - *T0_res = shr(pit_res_max,1); + limit_T0_voiced( 5, shr( pit_res_max, 1 ), *T0, *T0_frac, *T0_res, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); + *T0_res = shr( pit_res_max, 1 ); move16(); - Mode2_delta_pit_dec( T0, T0_frac, *T0_res, T0_min, T0_min_frac, pt_indice); + Mode2_delta_pit_dec( T0, T0_frac, *T0_res, T0_min, T0_min_frac, pt_indice ); } } - ELSE IF(EQ_16(coder_type,3)) /* 9/6/6/6 (HRs- VC) */ + ELSE IF( EQ_16( coder_type, 3 ) ) /* 9/6/6/6 (HRs- VC) */ { Word16 pit_res_max2 = pit_res_max; - if ( EQ_16(pit_min,PIT_MIN_16k)) + if ( EQ_16( pit_min, PIT_MIN_16k ) ) { - pit_res_max2 = shr(pit_res_max,1); + pit_res_max2 = shr( pit_res_max, 1 ); } - IF ( ( i_subfr == 0 ) ) + IF( ( i_subfr == 0 ) ) { - Mode2_abs_pit_dec( T0, T0_frac, T0_res, pt_indice, pit_min, pit_fr1, pit_fr2, pit_res_max); + Mode2_abs_pit_dec( T0, T0_frac, T0_res, pt_indice, pit_min, pit_fr1, pit_fr2, pit_res_max ); } ELSE { limit_T0_voiced( 6, pit_res_max2, *T0, 0, 1, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); *T0_res = pit_res_max2; move16(); - Mode2_delta_pit_dec( T0, T0_frac, *T0_res, T0_min, T0_min_frac, pt_indice); + Mode2_delta_pit_dec( T0, T0_frac, *T0_res, T0_min, T0_min_frac, pt_indice ); } } - ELSE IF(EQ_16(coder_type,4)) /* 9/6/9/6 (AMRWB) */ + ELSE IF( EQ_16( coder_type, 4 ) ) /* 9/6/9/6 (AMRWB) */ { Word16 pit_res_max2 = pit_res_max; - if ( EQ_16(pit_min,PIT_MIN_16k)) + if ( EQ_16( pit_min, PIT_MIN_16k ) ) { - pit_res_max2 = shr(pit_res_max,1); + pit_res_max2 = shr( pit_res_max, 1 ); } test(); - IF ( ( i_subfr == 0 ) || ( EQ_16(i_subfr,shl(L_subfr,1)))) + IF( ( i_subfr == 0 ) || ( EQ_16( i_subfr, shl( L_subfr, 1 ) ) ) ) { - Mode2_abs_pit_dec( T0, T0_frac, T0_res, pt_indice, pit_min, pit_fr1, pit_fr2, pit_res_max); + Mode2_abs_pit_dec( T0, T0_frac, T0_res, pt_indice, pit_min, pit_fr1, pit_fr2, pit_res_max ); } ELSE { limit_T0_voiced( 6, pit_res_max2, *T0, 0, 1, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); *T0_res = pit_res_max2; move16(); - Mode2_delta_pit_dec( T0, T0_frac, *T0_res, T0_min, T0_min_frac, pt_indice); + Mode2_delta_pit_dec( T0, T0_frac, *T0_res, T0_min, T0_min_frac, pt_indice ); } } - ELSE IF(EQ_16(coder_type,8)) /* 8/5/5/5 (RF all pred mode) */ + ELSE IF( EQ_16( coder_type, 8 ) ) /* 8/5/5/5 (RF all pred mode) */ { - IF (i_subfr == 0) + IF( i_subfr == 0 ) { - Mode2_abs_pit_dec( T0, T0_frac, T0_res, pt_indice, pit_min, pit_fr1b, pit_min, pit_res_max); + Mode2_abs_pit_dec( T0, T0_frac, T0_res, pt_indice, pit_min, pit_fr1b, pit_min, pit_res_max ); } ELSE { - limit_T0_voiced( 5, shr(pit_res_max,1), *T0, *T0_frac, *T0_res, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); - *T0_res = shr(pit_res_max,1); - Mode2_delta_pit_dec( T0, T0_frac, *T0_res, T0_min, T0_min_frac, pt_indice); + limit_T0_voiced( 5, shr( pit_res_max, 1 ), *T0, *T0_frac, *T0_res, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); + *T0_res = shr( pit_res_max, 1 ); + Mode2_delta_pit_dec( T0, T0_frac, *T0_res, T0_min, T0_min_frac, pt_indice ); } } - ELSE IF(EQ_16(coder_type,9)) /* 8/0/8/0 (RF gen pred mode) */ + ELSE IF( EQ_16( coder_type, 9 ) ) /* 8/0/8/0 (RF gen pred mode) */ { - IF (i_subfr == 0) + IF( i_subfr == 0 ) { - Mode2_abs_pit_dec( T0, T0_frac, T0_res, pt_indice, pit_min, pit_fr1b, pit_min, pit_res_max); + Mode2_abs_pit_dec( T0, T0_frac, T0_res, pt_indice, pit_min, pit_fr1b, pit_min, pit_res_max ); } ELSE { - limit_T0_voiced( 4, shr(pit_res_max,1), *T0, *T0_frac, *T0_res, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); - *T0_res = shr(pit_res_max,1); - Mode2_delta_pit_dec( T0, T0_frac, *T0_res, T0_min, T0_min_frac, pt_indice); + limit_T0_voiced( 4, shr( pit_res_max, 1 ), *T0, *T0_frac, *T0_res, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); + *T0_res = shr( pit_res_max, 1 ); + Mode2_delta_pit_dec( T0, T0_frac, *T0_res, T0_min, T0_min_frac, pt_indice ); } } ELSE { - assert(0 && "LTP mode not supported"); + assert( 0 && "LTP mode not supported" ); } /*-------------------------------------------------------* * Compute floating pitch output *-------------------------------------------------------*/ - assert(*T0_res > 0 || *T0_res <= 6); + assert( *T0_res > 0 || *T0_res <= 6 ); - /*pitch = (float)(*T0) + (float)(*T0_frac)/(float)(*T0_res);*/ /* save subframe pitch values */ - pitch = L_mac(L_deposit_h(*T0), *T0_frac,inv_T0_res[*T0_res]); + /*pitch = (float)(*T0) + (float)(*T0_frac)/(float)(*T0_res);*/ /* save subframe pitch values */ + pitch = L_mac( L_deposit_h( *T0 ), *T0_frac, inv_T0_res[*T0_res] ); return pitch; } - /*---------------------------------------------------------------------* * Mode2_abs_pit_dec() * @@ -177,59 +175,58 @@ void Mode2_abs_pit_dec( Word16 pit_min, Word16 pit_fr1, Word16 pit_fr2, - Word16 pit_res_max -) + Word16 pit_res_max ) { Word16 index; Word16 pit_res_max_half, tmp1, tmp2, res; index = **pt_indice; move16(); - (*pt_indice)++; - pit_res_max_half = shr(pit_res_max,1); + ( *pt_indice )++; + pit_res_max_half = shr( pit_res_max, 1 ); - tmp1 = i_mult(sub(pit_fr2,pit_min),pit_res_max); - tmp2 = i_mult(sub(pit_fr1,pit_fr2),pit_res_max_half); - IF (LT_16(index,tmp1)) + tmp1 = i_mult( sub( pit_fr2, pit_min ), pit_res_max ); + tmp2 = i_mult( sub( pit_fr1, pit_fr2 ), pit_res_max_half ); + IF( LT_16( index, tmp1 ) ) { - assert(pit_res_max > 1 && pit_res_max<=6); + assert( pit_res_max > 1 && pit_res_max <= 6 ); res = pit_res_max; move16(); - if(EQ_16(pit_res_max,6)) + if ( EQ_16( pit_res_max, 6 ) ) { - res =shr(res,1); + res = shr( res, 1 ); } - *T0 = mult(index,inv_T0_res[res]); - if(EQ_16(pit_res_max,6)) + *T0 = mult( index, inv_T0_res[res] ); + if ( EQ_16( pit_res_max, 6 ) ) { - *T0 =shr(*T0,1); + *T0 = shr( *T0, 1 ); } - *T0 = add(pit_min,*T0); + *T0 = add( pit_min, *T0 ); move16(); - *T0_frac = sub(index,i_mult(sub(*T0,pit_min),pit_res_max)); + *T0_frac = sub( index, i_mult( sub( *T0, pit_min ), pit_res_max ) ); move16(); *T0_res = pit_res_max; move16(); } - ELSE IF (index < add(tmp1,tmp2) ) + ELSE IF( index < add( tmp1, tmp2 ) ) { - assert(pit_res_max > 1); + assert( pit_res_max > 1 ); - index = sub(index,tmp1); - *T0 = add(pit_fr2,mult(index,inv_T0_res[pit_res_max_half])); + index = sub( index, tmp1 ); + *T0 = add( pit_fr2, mult( index, inv_T0_res[pit_res_max_half] ) ); move16(); - *T0_frac = sub(index, i_mult(sub(*T0,pit_fr2),pit_res_max_half)); + *T0_frac = sub( index, i_mult( sub( *T0, pit_fr2 ), pit_res_max_half ) ); move16(); *T0_res = pit_res_max_half; move16(); } ELSE { - *T0 = add(index,sub(pit_fr1,add(tmp1,tmp2))); + *T0 = add( index, sub( pit_fr1, add( tmp1, tmp2 ) ) ); move16(); *T0_frac = 0; move16(); @@ -247,40 +244,40 @@ void Mode2_abs_pit_dec( * Decode delta pitch *---------------------------------------------------------------------*/ void Mode2_delta_pit_dec( - Word16 *T0, /* o: integer pitch lag */ - Word16 *T0_frac, /* o: pitch fraction */ - Word16 T0_res, /* i: pitch resolution */ - Word16 *T0_min, /* i/o: delta search min */ - Word16 *T0_min_frac, /* i: delta search min */ - Word16 **pt_indice /* i/o: pointer to Vector of Q indexes */ + Word16 *T0, /* o: integer pitch lag */ + Word16 *T0_frac, /* o: pitch fraction */ + Word16 T0_res, /* i: pitch resolution */ + Word16 *T0_min, /* i/o: delta search min */ + Word16 *T0_min_frac, /* i: delta search min */ + Word16 **pt_indice /* i/o: pointer to Vector of Q indexes */ ) { Word16 index, res; - assert(T0_res > 1 && T0_res<=6); + assert( T0_res > 1 && T0_res <= 6 ); res = T0_res; move16(); - if(EQ_16(T0_res,6)) + if ( EQ_16( T0_res, 6 ) ) { - res =shr(res,1); + res = shr( res, 1 ); } index = **pt_indice; move16(); - (*pt_indice)++; + ( *pt_indice )++; - *T0 = mult(add(index,*T0_min_frac),inv_T0_res[res]); - if(EQ_16(T0_res,6)) + *T0 = mult( add( index, *T0_min_frac ), inv_T0_res[res] ); + if ( EQ_16( T0_res, 6 ) ) { - *T0 =shr(*T0,1); + *T0 = shr( *T0, 1 ); } - *T0 = add(*T0_min,*T0); + *T0 = add( *T0_min, *T0 ); move16(); - *T0_frac = add(index, sub(*T0_min_frac, i_mult(sub(*T0,*T0_min),T0_res))); + *T0_frac = add( index, sub( *T0_min_frac, i_mult( sub( *T0, *T0_min ), T0_res ) ) ); return; } @@ -314,26 +311,27 @@ void Mode2_delta_pit_dec( /*=======================================================================*/ -Word16 pit_decode_fx( /* o : floating pitch value */ - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - Word16 i_subfr, /* i : subframe index */ - const Word16 coder_type, /* i : coding type */ - Word16 *limit_flag, /* i/o: restrained(0) or extended(1) Q limits */ - Word16 *T0, /* o : close loop integer pitch */ - Word16 *T0_frac, /* o : close loop fractional part of the pitch */ - Word16 *T0_min, /* i/o: delta search min for sf 2 & 4 */ - Word16 *T0_max, /* i/o: delta search max for sf 2 & 4 */ - const Word16 L_subfr /* i : subframe length */ +Word16 pit_decode_fx( /* o : floating pitch value */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const Word16 L_frame, /* i : length of the frame */ + Word16 i_subfr, /* i : subframe index */ + const Word16 coder_type, /* i : coding type */ + Word16 *limit_flag, /* i/o: restrained(0) or extended(1) Q limits */ + Word16 *T0, /* o : close loop integer pitch */ + Word16 *T0_frac, /* o : close loop fractional part of the pitch */ + Word16 *T0_min, /* i/o: delta search min for sf 2 & 4 */ + Word16 *T0_max, /* i/o: delta search max for sf 2 & 4 */ + const Word16 L_subfr /* i : subframe length */ #ifdef ADD_LRTD - , const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ - const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ + , + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ #endif ) { - Word16 pitch; /*Q2*/ + Word16 pitch; /*Q2*/ Word16 pitch_index, nBits, pit_flag; pitch_index = 0; @@ -344,7 +342,7 @@ Word16 pit_decode_fx( /* o : floating pitch value pit_flag = i_subfr; move16(); - if (EQ_16(i_subfr,PIT_DECODE_2XL_SUBFR)) + if ( EQ_16( i_subfr, PIT_DECODE_2XL_SUBFR ) ) { pit_flag = 0; move16(); @@ -365,21 +363,21 @@ Word16 pit_decode_fx( /* o : floating pitch value *limit_flag = 1; move16(); - if( EQ_16(coder_type,VOICED)) + if ( EQ_16( coder_type, VOICED ) ) { *limit_flag = 2; move16(); /* double-extended limits */ } test(); - if( EQ_16(coder_type,GENERIC )&&EQ_32(core_brate,ACELP_7k20)) + if ( EQ_16( coder_type, GENERIC ) && EQ_32( core_brate, ACELP_7k20 ) ) { *limit_flag = 0; move16(); } } - ELSE IF( EQ_16(i_subfr,2*L_SUBFR)&&EQ_32(coder_type,GENERIC)&&LE_32(core_brate,ACELP_13k20)) + ELSE IF( EQ_16( i_subfr, 2 * L_SUBFR ) && EQ_32( coder_type, GENERIC ) && LE_32( core_brate, ACELP_13k20 ) ) { - if( GT_16(*T0,shr(add(PIT_FR1_EXTEND_8b, PIT_MIN),1) )) + if ( GT_16( *T0, shr( add( PIT_FR1_EXTEND_8b, PIT_MIN ), 1 ) ) ) { *limit_flag = 0; move16(); @@ -392,12 +390,12 @@ Word16 pit_decode_fx( /* o : floating pitch value nBits = 0; move16(); - IF( NE_16(coder_type, AUDIO)) + IF( NE_16( coder_type, AUDIO ) ) { /* find the number of bits */ - nBits = st_fx->acelp_cfg.pitch_bits[shr(i_subfr,6)]; + nBits = st_fx->acelp_cfg.pitch_bits[shr( i_subfr, 6 )]; move16(); - pitch_index = (Word16)get_next_indice( st_fx, nBits ); + pitch_index = (Word16) get_next_indice( st_fx, nBits ); move16(); } @@ -405,33 +403,33 @@ Word16 pit_decode_fx( /* o : floating pitch value * Pitch decoding in AUDIO mode * (both ACELP@12k8 and ACELP@16k cores) *-------------------------------------------------------*/ - IF( EQ_16(coder_type, AUDIO)) + IF( EQ_16( coder_type, AUDIO ) ) { test(); - if( EQ_16(L_subfr,L_FRAME/2)&&i_subfr!=0) + if ( EQ_16( L_subfr, L_FRAME / 2 ) && i_subfr != 0 ) { pit_flag = L_SUBFR; move16(); } - if( pit_flag == 0 ) + if ( pit_flag == 0 ) { nBits = 10; move16(); } - if( pit_flag != 0 ) + if ( pit_flag != 0 ) { nBits = 6; move16(); } - pitch_index = (Word16)get_next_indice( st_fx, nBits ); + pitch_index = (Word16) get_next_indice( st_fx, nBits ); move16(); test(); test(); - IF( EQ_16(L_subfr,L_FRAME/2)&&i_subfr!=0&&GE_16(pitch_index,32)) /* safety check in case of bit errors */ + IF( EQ_16( L_subfr, L_FRAME / 2 ) && i_subfr != 0 && GE_16( pitch_index, 32 ) ) /* safety check in case of bit errors */ { - pitch_index = shr(pitch_index,1); + pitch_index = shr( pitch_index, 1 ); move16(); st_fx->BER_detect = 1; move16(); @@ -439,13 +437,13 @@ Word16 pit_decode_fx( /* o : floating pitch value pit_Q_dec_fx( 0, pitch_index, nBits, 4, pit_flag, *limit_flag, T0, T0_frac, T0_min, T0_max, &st_fx->BER_detect ); } - ELSE IF( EQ_16(coder_type,VOICED)) + ELSE IF( EQ_16( coder_type, VOICED ) ) { /*-------------------------------------------------------* * Pitch decoding in VOICED mode * (ACELP@12k8 core only) *-------------------------------------------------------*/ - if( EQ_16(i_subfr,2*L_SUBFR)) + if ( EQ_16( i_subfr, 2 * L_SUBFR ) ) { pit_flag = i_subfr; move16(); @@ -454,9 +452,10 @@ Word16 pit_decode_fx( /* o : floating pitch value pit_Q_dec_fx( 0, pitch_index, nBits, 4, pit_flag, *limit_flag, T0, T0_frac, T0_min, T0_max, &st_fx->BER_detect ); } #ifdef ADD_LRTD - ELSE IF ( EQ_16(st_fx->idchan, 1) && (EQ_16(tdm_Pitch_reuse_flag, 1) || EQ_16(nBits,4) ) ) + ELSE IF( EQ_16( st_fx->idchan, 1 ) && ( EQ_16( tdm_Pitch_reuse_flag, 1 ) || EQ_16( nBits, 4 ) ) ) { - test(); test(); + test(); + test(); /*-------------------------------------------------------* * Pitch decoding with reusing of primary channel information *-------------------------------------------------------*/ @@ -464,32 +463,34 @@ Word16 pit_decode_fx( /* o : floating pitch value delta = 4; pit_flag = L_SUBFR; - move16(); move16(); - isubfridx = shr(i_subfr, 6); - IF ( EQ_16(L_subfr, 2 * L_SUBFR ) ) + move16(); + move16(); + isubfridx = shr( i_subfr, 6 ); + IF( EQ_16( L_subfr, 2 * L_SUBFR ) ) { - move16(); move16(); - pit_tmp1 = tdm_Pri_pitch_buf[isubfridx]; /*tdm_Pri_pitch_buf in Q6 ->pit_tmp1 and 2 in Q6 too */ - pit_tmp2 = tdm_Pri_pitch_buf[shr(add(i_subfr, 1), 6)]; + move16(); + move16(); + pit_tmp1 = tdm_Pri_pitch_buf[isubfridx]; /*tdm_Pri_pitch_buf in Q6 ->pit_tmp1 and 2 in Q6 too */ + pit_tmp2 = tdm_Pri_pitch_buf[shr( add( i_subfr, 1 ), 6 )]; /*loc_T0 = (int16_t)(0.5f * tdm_Pri_pitch_buf[i_subfr / L_SUBFR] + 0.5f * tdm_Pri_pitch_buf[(i_subfr + L_SUBFR) / L_SUBFR]);*/ - loc_T0 = mac_r( L_mult(16384, pit_tmp1, 16384, pit_tmp2) ); + loc_T0 = mac_r( L_mult( 16384, pit_tmp1, 16384, pit_tmp2 ) ); /*loc_frac = (int16_t)(((0.5f * tdm_Pri_pitch_buf[i_subfr / L_SUBFR] + 0.5f * tdm_Pri_pitch_buf[(i_subfr + L_SUBFR) / L_SUBFR]) - loc_T0) * 4.0f);*/ } ELSE { /*loc_T0 = (int16_t)tdm_Pri_pitch_buf[i_subfr / L_SUBFR];*/ - loc_T0 = tdm_Pri_pitch_buf[isubfridx]; /*Q6*/ + loc_T0 = tdm_Pri_pitch_buf[isubfridx]; /*Q6*/ /*loc_frac = (int16_t)((tdm_Pri_pitch_buf[i_subfr / L_SUBFR] - loc_T0) * 4.0f);*/ } loc_frac = shr(sub(loc_T0, shl(shr(loc_T0, 6), 6)), 4)); /* Final result in Q 2*/ - loc_T0 = shr (loc_T0, 6); /*Q6 -> Q0*/ + loc_T0 = shr( loc_T0, 6 ); /*Q6 -> Q0*/ - limit_T0_fx(L_FRAME, delta, pit_flag, *limit_flag, loc_T0, loc_frac, T0_min, T0_max); + limit_T0_fx( L_FRAME, delta, pit_flag, *limit_flag, loc_T0, loc_frac, T0_min, T0_max ); - IF (nBits > 0) + IF( nBits > 0 ) { - pit_Q_dec_fx(0, pitch_index, nBits, delta, pit_flag, *limit_flag, T0, T0_frac, T0_min, T0_max, &st_fx->BER_detect); + pit_Q_dec_fx( 0, pitch_index, nBits, delta, pit_flag, *limit_flag, T0, T0_frac, T0_min, T0_max, &st_fx->BER_detect ); } ELSE { @@ -498,7 +499,7 @@ Word16 pit_decode_fx( /* o : floating pitch value move16(); move16(); } -printf("function not tested yet\n"); + printf( "function not tested yet\n" ); } #endif ELSE @@ -507,7 +508,7 @@ printf("function not tested yet\n"); * Pitch decoding in GENERIC mode * (both ACELP@12k8 and ACELP@16k cores) *-------------------------------------------------------*/ - IF( EQ_16(L_frame,L_FRAME)) + IF( EQ_16( L_frame, L_FRAME ) ) { pit_Q_dec_fx( 0, pitch_index, nBits, 8, pit_flag, *limit_flag, T0, T0_frac, T0_min, T0_max, &st_fx->BER_detect ); } @@ -528,7 +529,7 @@ printf("function not tested yet\n"); move16(); test(); test(); - IF( i_subfr == 0 || ( EQ_16(i_subfr, 2*L_SUBFR)&&EQ_32(core_brate,ACELP_8k85))) + IF( i_subfr == 0 || ( EQ_16( i_subfr, 2 * L_SUBFR ) && EQ_32( core_brate, ACELP_8k85 ) ) ) { nBits = 8; move16(); @@ -538,19 +539,19 @@ printf("function not tested yet\n"); nBits = 5; move16(); } - IF( GT_32(core_brate, ACELP_8k85)) + IF( GT_32( core_brate, ACELP_8k85 ) ) { nBits = 6; move16(); test(); - if( i_subfr == 0 || EQ_16(i_subfr, 2*L_SUBFR)) + if ( i_subfr == 0 || EQ_16( i_subfr, 2 * L_SUBFR ) ) { nBits = 9; move16(); } } - pitch_index = (Word16)get_next_indice( st_fx, nBits ); + pitch_index = (Word16) get_next_indice( st_fx, nBits ); pit_Q_dec_fx( 1, pitch_index, nBits, 8, pit_flag, *limit_flag, T0, T0_frac, T0_min, T0_max, &st_fx->BER_detect ); } @@ -559,7 +560,7 @@ printf("function not tested yet\n"); * Compute floating pitch output *-------------------------------------------------------*/ - pitch = shl(add(shl(*T0,2),*T0_frac),4); /* save subframe pitch values Q6 */ + pitch = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); /* save subframe pitch values Q6 */ return pitch; } @@ -592,22 +593,23 @@ printf("function not tested yet\n"); /*=======================================================================*/ -Word16 pit_decode_ivas_fx( /* o : floating pitch value */ - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - Word16 i_subfr, /* i : subframe index */ - const Word16 coder_type, /* i : coding type */ - Word16 *limit_flag, /* i/o: restrained(0) or extended(1) Q limits */ - Word16 *T0, /* o : close loop integer pitch */ - Word16 *T0_frac, /* o : close loop fractional part of the pitch */ - Word16 *T0_min, /* i/o: delta search min for sf 2 & 4 */ - Word16 *T0_max, /* i/o: delta search max for sf 2 & 4 */ - const Word16 L_subfr /* i : subframe length */ -#if 1//def ADD_LRTD - , const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ - const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ +Word16 pit_decode_ivas_fx( /* o : floating pitch value */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const Word16 L_frame, /* i : length of the frame */ + Word16 i_subfr, /* i : subframe index */ + const Word16 coder_type, /* i : coding type */ + Word16 *limit_flag, /* i/o: restrained(0) or extended(1) Q limits */ + Word16 *T0, /* o : close loop integer pitch */ + Word16 *T0_frac, /* o : close loop fractional part of the pitch */ + Word16 *T0_min, /* i/o: delta search min for sf 2 & 4 */ + Word16 *T0_max, /* i/o: delta search max for sf 2 & 4 */ + const Word16 L_subfr /* i : subframe length */ +#if 1 // def ADD_LRTD + , + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ #endif ) { @@ -851,79 +853,80 @@ Word16 pit_decode_ivas_fx( /* o : floating pitch value *----------------------------------------------------------*/ void pit_Q_dec_fx( - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 pitch_index, /* i : pitch index */ - const Word16 nBits, /* i : # of Q bits */ - const Word16 delta, /* i : Half the CL searched interval */ - const Word16 pit_flag, /* i : absolute(0) or delta(1) pitch Q */ - const Word16 limit_flag, /* i : restrained(0) or extended(1) Q limits */ - Word16 *T0, /* o : integer pitch lag */ - Word16 *T0_frac, /* o : pitch fraction */ - Word16 *T0_min, /* i/o: delta search min */ - Word16 *T0_max /* i/o: delta search max */ - ,Word16 *BER_detect /* o : BER detect flag */ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const Word16 pitch_index, /* i : pitch index */ + const Word16 nBits, /* i : # of Q bits */ + const Word16 delta, /* i : Half the CL searched interval */ + const Word16 pit_flag, /* i : absolute(0) or delta(1) pitch Q */ + const Word16 limit_flag, /* i : restrained(0) or extended(1) Q limits */ + Word16 *T0, /* o : integer pitch lag */ + Word16 *T0_frac, /* o : pitch fraction */ + Word16 *T0_min, /* i/o: delta search min */ + Word16 *T0_max /* i/o: delta search max */ + , + Word16 *BER_detect /* o : BER detect flag */ ) { - IF( EQ_16(nBits, 10)) /* absolute decoding with 10 bits */ + IF( EQ_16( nBits, 10 ) ) /* absolute decoding with 10 bits */ { IF( limit_flag == 0 ) { - *T0 = add(PIT_MIN,shr(pitch_index,2)); - *T0_frac = sub(pitch_index,shl(sub(*T0,PIT_MIN),2)); + *T0 = add( PIT_MIN, shr( pitch_index, 2 ) ); + *T0_frac = sub( pitch_index, shl( sub( *T0, PIT_MIN ), 2 ) ); } - ELSE IF( EQ_16(limit_flag,1)) + ELSE IF( EQ_16( limit_flag, 1 ) ) { - *T0 = add(PIT_MIN_EXTEND,shr(pitch_index,2)); - *T0_frac = sub(pitch_index ,shl(sub(*T0,PIT_MIN_EXTEND),2)); + *T0 = add( PIT_MIN_EXTEND, shr( pitch_index, 2 ) ); + *T0_frac = sub( pitch_index, shl( sub( *T0, PIT_MIN_EXTEND ), 2 ) ); } - ELSE /* limit_flag == 2 */ + ELSE /* limit_flag == 2 */ { - *T0 = add(PIT_MIN_DOUBLEEXTEND,shr(pitch_index,2)); - *T0_frac = sub(pitch_index ,shl(sub(*T0,PIT_MIN_DOUBLEEXTEND),2)); + *T0 = add( PIT_MIN_DOUBLEEXTEND, shr( pitch_index, 2 ) ); + *T0_frac = sub( pitch_index, shl( sub( *T0, PIT_MIN_DOUBLEEXTEND ), 2 ) ); } } - ELSE IF( EQ_16(nBits, 9)) /* absolute decoding with 9 bits */ + ELSE IF( EQ_16( nBits, 9 ) ) /* absolute decoding with 9 bits */ { abs_pit_dec_fx( 4, pitch_index, limit_flag, T0, T0_frac ); /* find T0_min and T0_max for delta search */ IF( Opt_AMR_WB ) { - limit_T0_fx( L_FRAME, delta, pit_flag, 0, *T0, 0, T0_min, T0_max ); /* T0_frac==0 to keep IO with AMR-WB */ + limit_T0_fx( L_FRAME, delta, pit_flag, 0, *T0, 0, T0_min, T0_max ); /* T0_frac==0 to keep IO with AMR-WB */ } } - ELSE IF( EQ_16(nBits, 8)) /* absolute decoding with 8 bits */ + ELSE IF( EQ_16( nBits, 8 ) ) /* absolute decoding with 8 bits */ { abs_pit_dec_fx( 2, pitch_index, limit_flag, T0, T0_frac ); /* find T0_min and T0_max for delta search */ IF( Opt_AMR_WB ) { - limit_T0_fx( L_FRAME, delta, pit_flag, 0, *T0, 0, T0_min, T0_max ); /* T0_frac==0 to keep IO with AMR-WB */ + limit_T0_fx( L_FRAME, delta, pit_flag, 0, *T0, 0, T0_min, T0_max ); /* T0_frac==0 to keep IO with AMR-WB */ } } - ELSE IF( EQ_16(nBits, 6)) /* relative decoding with 6 bits */ + ELSE IF( EQ_16( nBits, 6 ) ) /* relative decoding with 6 bits */ { delta_pit_dec_fx( 4, pitch_index, T0, T0_frac, *T0_min ); } - ELSE IF( EQ_16(nBits, 5)) /* relative decoding with 5 bits */ + ELSE IF( EQ_16( nBits, 5 ) ) /* relative decoding with 5 bits */ { - IF( EQ_16(delta,8)) + IF( EQ_16( delta, 8 ) ) { delta_pit_dec_fx( 2, pitch_index, T0, T0_frac, *T0_min ); } - ELSE /* delta == 4 */ + ELSE /* delta == 4 */ { delta_pit_dec_fx( 4, pitch_index, T0, T0_frac, *T0_min ); } } - ELSE /* nBits == 4 */ /* relative decoding with 4 bits */ + ELSE /* nBits == 4 */ /* relative decoding with 4 bits */ { - IF( EQ_16(delta,8)) + IF( EQ_16( delta, 8 ) ) { delta_pit_dec_fx( 0, pitch_index, T0, T0_frac, *T0_min ); } - ELSE /* delta == 4 */ + ELSE /* delta == 4 */ { delta_pit_dec_fx( 2, pitch_index, T0, T0_frac, *T0_min ); } @@ -932,7 +935,7 @@ void pit_Q_dec_fx( /* biterror detection mechanism */ test(); test(); - IF( GT_16(add((*T0<<2),*T0_frac),add((PIT_MAX<<2),2))&&pit_flag==0&&!Opt_AMR_WB) + IF( GT_16( add( ( *T0 << 2 ), *T0_frac ), add( ( PIT_MAX << 2 ), 2 ) ) && pit_flag == 0 && !Opt_AMR_WB ) { *T0 = L_SUBFR; move16(); @@ -952,82 +955,81 @@ void pit_Q_dec_fx( } /*-------------------------------------------------* - * pit16k_Q_dec() - * - * pitch decoding @16kHz core - *-------------------------------------------------*/ + * pit16k_Q_dec() + * + * pitch decoding @16kHz core + *-------------------------------------------------*/ void pit16k_Q_dec_fx( - const Word16 pitch_index, /* i : pitch index */ - const Word16 nBits, /* i : # of Q bits */ - const Word16 limit_flag, /* i : restrained(0) or extended(1) limits */ - Word16 *T0, /* o : integer pitch lag */ - Word16 *T0_frac, /* o : pitch fraction */ - Word16 *T0_min, /* i/o: delta search min */ - Word16 *T0_max /* i/o: delta search max */ - ,Word16 *BER_detect /* o : BER detect flag */ + const Word16 pitch_index, /* i : pitch index */ + const Word16 nBits, /* i : # of Q bits */ + const Word16 limit_flag, /* i : restrained(0) or extended(1) limits */ + Word16 *T0, /* o : integer pitch lag */ + Word16 *T0_frac, /* o : pitch fraction */ + Word16 *T0_min, /* i/o: delta search min */ + Word16 *T0_max /* i/o: delta search max */ + , + Word16 *BER_detect /* o : BER detect flag */ ) { - Word16 index; + Word16 index; - IF( EQ_16(nBits,10)) /* absolute decoding with 10 bits */ + IF( EQ_16( nBits, 10 ) ) /* absolute decoding with 10 bits */ { { - IF( LT_16(pitch_index,shl((PIT16k_FR2_EXTEND_10b-PIT16k_MIN_EXTEND),2))) + IF( LT_16( pitch_index, shl( ( PIT16k_FR2_EXTEND_10b - PIT16k_MIN_EXTEND ), 2 ) ) ) { - *T0 = add(PIT16k_MIN_EXTEND, shr(pitch_index,2)); + *T0 = add( PIT16k_MIN_EXTEND, shr( pitch_index, 2 ) ); move16(); - *T0_frac = sub(pitch_index, shl(sub(*T0, PIT16k_MIN_EXTEND),2)); + *T0_frac = sub( pitch_index, shl( sub( *T0, PIT16k_MIN_EXTEND ), 2 ) ); move16(); } ELSE { - index = sub(pitch_index, shl((PIT16k_FR2_EXTEND_10b-PIT16k_MIN_EXTEND),2)); - *T0 = add(PIT16k_FR2_EXTEND_10b, shr(index,1)); - *T0_frac = sub(index, shl(sub(*T0, PIT16k_FR2_EXTEND_10b),1)); + index = sub( pitch_index, shl( ( PIT16k_FR2_EXTEND_10b - PIT16k_MIN_EXTEND ), 2 ) ); + *T0 = add( PIT16k_FR2_EXTEND_10b, shr( index, 1 ) ); + *T0_frac = sub( index, shl( sub( *T0, PIT16k_FR2_EXTEND_10b ), 1 ) ); /*(*T0_frac) *= 2;*/ - (*T0_frac) = shl(*T0_frac,1); - + ( *T0_frac ) = shl( *T0_frac, 1 ); } } - } - ELSE IF ( EQ_16(nBits,9)) /* absolute decoding with 9 bits */ + ELSE IF( EQ_16( nBits, 9 ) ) /* absolute decoding with 9 bits */ { { - IF (LT_16(pitch_index,(PIT16k_FR2_EXTEND_9b-PIT16k_MIN_EXTEND)*4)) + IF( LT_16( pitch_index, ( PIT16k_FR2_EXTEND_9b - PIT16k_MIN_EXTEND ) * 4 ) ) { - *T0 = add(PIT16k_MIN_EXTEND, shr(pitch_index,2)); + *T0 = add( PIT16k_MIN_EXTEND, shr( pitch_index, 2 ) ); move16(); - *T0_frac = sub(pitch_index, shl(sub(*T0, PIT16k_MIN_EXTEND),2)); + *T0_frac = sub( pitch_index, shl( sub( *T0, PIT16k_MIN_EXTEND ), 2 ) ); move16(); } - ELSE IF (LT_16(pitch_index,( (PIT16k_FR2_EXTEND_9b-PIT16k_MIN_EXTEND)*4 + (PIT16k_FR1_EXTEND_9b-PIT16k_FR2_EXTEND_9b)*2))) + ELSE IF( LT_16( pitch_index, ( ( PIT16k_FR2_EXTEND_9b - PIT16k_MIN_EXTEND ) * 4 + ( PIT16k_FR1_EXTEND_9b - PIT16k_FR2_EXTEND_9b ) * 2 ) ) ) { - index = sub(pitch_index, (PIT16k_FR2_EXTEND_9b-PIT16k_MIN_EXTEND)*4); - *T0 = add(PIT16k_FR2_EXTEND_9b, shr(index,1)); + index = sub( pitch_index, ( PIT16k_FR2_EXTEND_9b - PIT16k_MIN_EXTEND ) * 4 ); + *T0 = add( PIT16k_FR2_EXTEND_9b, shr( index, 1 ) ); move16(); - *T0_frac = sub(index, shl(sub(*T0, PIT16k_FR2_EXTEND_9b),1)); + *T0_frac = sub( index, shl( sub( *T0, PIT16k_FR2_EXTEND_9b ), 1 ) ); move16(); - (*T0_frac) *= shl((*T0_frac),1); + ( *T0_frac ) *= shl( ( *T0_frac ), 1 ); } ELSE { - *T0 = add(pitch_index, PIT16k_FR1_EXTEND_9b - ((PIT16k_FR2_EXTEND_9b-PIT16k_MIN_EXTEND)*4) - ((PIT16k_FR1_EXTEND_9b-PIT16k_FR2_EXTEND_9b)*2)); + *T0 = add( pitch_index, PIT16k_FR1_EXTEND_9b - ( ( PIT16k_FR2_EXTEND_9b - PIT16k_MIN_EXTEND ) * 4 ) - ( ( PIT16k_FR1_EXTEND_9b - PIT16k_FR2_EXTEND_9b ) * 2 ) ); move16(); *T0_frac = 0; move16(); } } } - ELSE /* nBits == 6 */ /* relative decoding with 6 bits */ + ELSE /* nBits == 6 */ /* relative decoding with 6 bits */ { delta_pit_dec_fx( 4, pitch_index, T0, T0_frac, *T0_min ); } /* biterror detection mechanism */ test(); - IF( GT_16(add((*T0<<2),*T0_frac),(PIT16k_MAX<<2))&&GE_16(nBits,9)) + IF( GT_16( add( ( *T0 << 2 ), *T0_frac ), ( PIT16k_MAX << 2 ) ) && GE_16( nBits, 9 ) ) { *T0 = L_SUBFR; move16(); @@ -1050,173 +1052,173 @@ void pit16k_Q_dec_fx( *----------------------------------------------------------*/ void abs_pit_dec_fx( - const Word16 fr_steps, /* i: fractional resolution steps (0, 2, 4) */ - Word16 pitch_index, /* i: pitch index */ - const Word16 limit_flag, /* i : restrained(0) or extended(1) limits */ - Word16 *T0, /* o: integer pitch lag */ - Word16 *T0_frac /* o: pitch fraction */ + const Word16 fr_steps, /* i: fractional resolution steps (0, 2, 4) */ + Word16 pitch_index, /* i: pitch index */ + const Word16 limit_flag, /* i : restrained(0) or extended(1) limits */ + Word16 *T0, /* o: integer pitch lag */ + Word16 *T0_frac /* o: pitch fraction */ ) { Word16 temp; IF( limit_flag == 0 ) { - IF(EQ_16(fr_steps,2)) + IF( EQ_16( fr_steps, 2 ) ) { - IF(LT_16(pitch_index,PIT_FR1_8b_MINUS_PIT_MIN_X2)) + IF( LT_16( pitch_index, PIT_FR1_8b_MINUS_PIT_MIN_X2 ) ) { - *T0= add(PIT_MIN,shr(pitch_index,1)); + *T0 = add( PIT_MIN, shr( pitch_index, 1 ) ); move16(); - temp = shl(sub(*T0,PIT_MIN),1); - *T0_frac = shl(sub(pitch_index,temp),1); + temp = shl( sub( *T0, PIT_MIN ), 1 ); + *T0_frac = shl( sub( pitch_index, temp ), 1 ); move16(); } ELSE { - *T0 = add(pitch_index,PIT_FR1_8b_MINUS_PIT_FR1_8b_MINUS_PIT_MIN_X2); + *T0 = add( pitch_index, PIT_FR1_8b_MINUS_PIT_FR1_8b_MINUS_PIT_MIN_X2 ); move16(); *T0_frac = 0; move16(); } } - ELSE IF( EQ_16(fr_steps,4)) + ELSE IF( EQ_16( fr_steps, 4 ) ) { - IF(LT_16(pitch_index,PIT_FR2_9b_MINUS_PIT_MIN_X4)) + IF( LT_16( pitch_index, PIT_FR2_9b_MINUS_PIT_MIN_X4 ) ) { - *T0= add(PIT_MIN,shr(pitch_index,2)); + *T0 = add( PIT_MIN, shr( pitch_index, 2 ) ); move16(); - temp = shl(sub(*T0,PIT_MIN),2); - *T0_frac = sub(pitch_index,temp); + temp = shl( sub( *T0, PIT_MIN ), 2 ); + *T0_frac = sub( pitch_index, temp ); move16(); } - ELSE IF (LT_16(pitch_index,PIT_DECODE_1)) /*( (PIT_FR2_9b-PIT_MIN)*4 + (PIT_FR1_9b-PIT_FR2_9b)*2) = 440*/ + ELSE IF( LT_16( pitch_index, PIT_DECODE_1 ) ) /*( (PIT_FR2_9b-PIT_MIN)*4 + (PIT_FR1_9b-PIT_FR2_9b)*2) = 440*/ { - pitch_index = sub(pitch_index,PIT_DECODE_2); /*pitch_index -= (PIT_FR2_9b-PIT_MIN)*4(=376);*/ - *T0 = add(PIT_FR2_9b,shr(pitch_index,1)); + pitch_index = sub( pitch_index, PIT_DECODE_2 ); /*pitch_index -= (PIT_FR2_9b-PIT_MIN)*4(=376);*/ + *T0 = add( PIT_FR2_9b, shr( pitch_index, 1 ) ); move16(); - temp = shl(sub(*T0,PIT_FR2_9b),1); - *T0_frac = shl(sub(pitch_index,temp),1); + temp = shl( sub( *T0, PIT_FR2_9b ), 1 ); + *T0_frac = shl( sub( pitch_index, temp ), 1 ); move16(); } ELSE { - *T0 = add(pitch_index,PIT_DECODE_3); + *T0 = add( pitch_index, PIT_DECODE_3 ); move16(); *T0_frac = 0; move16(); } } - ELSE /* fr_steps == 0 */ + ELSE /* fr_steps == 0 */ { /* not used in the codec */ } } - ELSE IF( EQ_16(limit_flag, 1)) /* extended Q range */ + ELSE IF( EQ_16( limit_flag, 1 ) ) /* extended Q range */ { - IF( EQ_16(fr_steps,2)) + IF( EQ_16( fr_steps, 2 ) ) { - IF( LT_16(pitch_index, PIT_FR1_EXT8b_MINUS_PIT_MIN_EXT_X2)) + IF( LT_16( pitch_index, PIT_FR1_EXT8b_MINUS_PIT_MIN_EXT_X2 ) ) { - *T0 = add(PIT_MIN_EXTEND, shr(pitch_index,1)); + *T0 = add( PIT_MIN_EXTEND, shr( pitch_index, 1 ) ); move16(); - *T0_frac = sub(pitch_index, shl(sub(*T0, PIT_MIN_EXTEND),1)); - *T0_frac = shl(*T0_frac, 1); + *T0_frac = sub( pitch_index, shl( sub( *T0, PIT_MIN_EXTEND ), 1 ) ); + *T0_frac = shl( *T0_frac, 1 ); move16(); } ELSE { - *T0 = add(pitch_index, sub(PIT_FR1_EXTEND_8b, PIT_FR1_EXT8b_MINUS_PIT_MIN_EXT_X2)); + *T0 = add( pitch_index, sub( PIT_FR1_EXTEND_8b, PIT_FR1_EXT8b_MINUS_PIT_MIN_EXT_X2 ) ); move16(); *T0_frac = 0; move16(); } } - ELSE IF( EQ_16(fr_steps,4)) + ELSE IF( EQ_16( fr_steps, 4 ) ) { - IF( LT_16(pitch_index, PIT_FR2_EXT9b_MINUS_PIT_MIN_EXT_X4)) + IF( LT_16( pitch_index, PIT_FR2_EXT9b_MINUS_PIT_MIN_EXT_X4 ) ) { /**T0 = PIT_MIN_EXTEND + (pitch_index/4);*/ - *T0 = add(PIT_MIN_EXTEND, shr(pitch_index,2)); + *T0 = add( PIT_MIN_EXTEND, shr( pitch_index, 2 ) ); move16(); /**T0_frac = pitch_index - (*T0 - PIT_MIN_EXTEND)*4;*/ - *T0_frac = sub(pitch_index, shl(sub(*T0, PIT_MIN_EXTEND),2)); + *T0_frac = sub( pitch_index, shl( sub( *T0, PIT_MIN_EXTEND ), 2 ) ); move16(); } - ELSE IF( LT_16(pitch_index,add(PIT_FR2_EXT9b_MINUS_PIT_MIN_EXT_X4, PIT_FR1_EXT9b_MINUS_PIT_FR2_EXT9b_X2))) + ELSE IF( LT_16( pitch_index, add( PIT_FR2_EXT9b_MINUS_PIT_MIN_EXT_X4, PIT_FR1_EXT9b_MINUS_PIT_FR2_EXT9b_X2 ) ) ) { /*pitch_index -= (PIT_FR2_EXTEND_9b-PIT_MIN_EXTEND)*4;*/ - pitch_index = sub(pitch_index, PIT_FR2_EXT9b_MINUS_PIT_MIN_EXT_X4); - *T0 = add(PIT_FR2_EXTEND_9b, shr(pitch_index,1)); - *T0_frac = sub(pitch_index, shl(sub(*T0, PIT_FR2_EXTEND_9b),1)); - (*T0_frac) = shl(*T0_frac,1); + pitch_index = sub( pitch_index, PIT_FR2_EXT9b_MINUS_PIT_MIN_EXT_X4 ); + *T0 = add( PIT_FR2_EXTEND_9b, shr( pitch_index, 1 ) ); + *T0_frac = sub( pitch_index, shl( sub( *T0, PIT_FR2_EXTEND_9b ), 1 ) ); + ( *T0_frac ) = shl( *T0_frac, 1 ); move16(); } ELSE { /**T0 = pitch_index + PIT_FR1_EXTEND_9b - ((PIT_FR2_EXTEND_9b-PIT_MIN_EXTEND)*4) - ((PIT_FR1_EXTEND_9b-PIT_FR2_EXTEND_9b)*2);move16();*/ - *T0 = add(pitch_index, PIT_DECODE_7); + *T0 = add( pitch_index, PIT_DECODE_7 ); move16(); *T0_frac = 0; move16(); } } - ELSE /* fr_steps == 0 */ + ELSE /* fr_steps == 0 */ { /* not used in the codec */ } } - ELSE /* limit_flag == 2 */ + ELSE /* limit_flag == 2 */ { - IF( EQ_16(fr_steps,2)) + IF( EQ_16( fr_steps, 2 ) ) { - IF( LT_16(pitch_index,PIT_FR1_DEXT8b_MINUS_PIT_MIN_DEXT_X2)) + IF( LT_16( pitch_index, PIT_FR1_DEXT8b_MINUS_PIT_MIN_DEXT_X2 ) ) { - *T0 = add(PIT_MIN_DOUBLEEXTEND, shr(pitch_index,1)); + *T0 = add( PIT_MIN_DOUBLEEXTEND, shr( pitch_index, 1 ) ); move16(); - *T0_frac = sub(pitch_index, shl(sub(*T0, PIT_MIN_DOUBLEEXTEND),1)); + *T0_frac = sub( pitch_index, shl( sub( *T0, PIT_MIN_DOUBLEEXTEND ), 1 ) ); move16(); - *T0_frac = shl(*T0_frac,1); + *T0_frac = shl( *T0_frac, 1 ); move16(); } ELSE { /**T0 = pitch_index + PIT_FR1_DOUBLEEXTEND_8b - ((PIT_FR1_DOUBLEEXTEND_8b-PIT_MIN_DOUBLEEXTEND)*2);move16();*/ - *T0 = add(pitch_index, PIT_DECODE_8); + *T0 = add( pitch_index, PIT_DECODE_8 ); move16(); *T0_frac = 0; move16(); } } - ELSE IF( EQ_16(fr_steps,4)) + ELSE IF( EQ_16( fr_steps, 4 ) ) { - IF( LT_16(pitch_index, PIT_FR2_DEXT9b_MINUS_PIT_MIN_DEXT_X4)) + IF( LT_16( pitch_index, PIT_FR2_DEXT9b_MINUS_PIT_MIN_DEXT_X4 ) ) { - *T0 = add(PIT_MIN_DOUBLEEXTEND, shr(pitch_index,2)); + *T0 = add( PIT_MIN_DOUBLEEXTEND, shr( pitch_index, 2 ) ); move16(); - *T0_frac = sub(pitch_index, shl(sub(*T0, PIT_MIN_DOUBLEEXTEND),2)); + *T0_frac = sub( pitch_index, shl( sub( *T0, PIT_MIN_DOUBLEEXTEND ), 2 ) ); move16(); } - ELSE IF( LT_16(pitch_index,PIT_DECODE_9)) + ELSE IF( LT_16( pitch_index, PIT_DECODE_9 ) ) { /*pitch_index -= (PIT_FR2_DOUBLEEXTEND_9b-PIT_MIN_DOUBLEEXTEND)*4;move16();*/ - pitch_index = sub(pitch_index , PIT_FR2_DEXT9b_MINUS_PIT_MIN_DEXT_X4); + pitch_index = sub( pitch_index, PIT_FR2_DEXT9b_MINUS_PIT_MIN_DEXT_X4 ); move16(); - *T0 = add(PIT_FR2_DOUBLEEXTEND_9b, shr(pitch_index,1)); + *T0 = add( PIT_FR2_DOUBLEEXTEND_9b, shr( pitch_index, 1 ) ); move16(); - *T0_frac = sub(pitch_index, shl(sub(*T0, PIT_FR2_DOUBLEEXTEND_9b),1)); + *T0_frac = sub( pitch_index, shl( sub( *T0, PIT_FR2_DOUBLEEXTEND_9b ), 1 ) ); move16(); - (*T0_frac) = shl(*T0_frac,1); + ( *T0_frac ) = shl( *T0_frac, 1 ); move16(); } ELSE { - *T0 = add(pitch_index, PIT_DECODE_10); + *T0 = add( pitch_index, PIT_DECODE_10 ); move16(); *T0_frac = 0; move16(); } } - ELSE /* fr_steps == 0 */ + ELSE /* fr_steps == 0 */ { /* not used in the codec */ } @@ -1232,36 +1234,36 @@ void abs_pit_dec_fx( *----------------------------------------------------------*/ void delta_pit_dec_fx( - const Word16 fr_steps, /* i : fractional resolution steps (0, 2, 4) */ - const Word16 pitch_index, /* i : pitch index */ - Word16 *T0, /* o : integer pitch lag */ - Word16 *T0_frac, /* o : pitch fraction */ - const Word16 T0_min /* i : delta search min */ + const Word16 fr_steps, /* i : fractional resolution steps (0, 2, 4) */ + const Word16 pitch_index, /* i : pitch index */ + Word16 *T0, /* o : integer pitch lag */ + Word16 *T0_frac, /* o : pitch fraction */ + const Word16 T0_min /* i : delta search min */ ) { Word16 temp; IF( fr_steps == 0 ) { - *T0 = add(T0_min,pitch_index); + *T0 = add( T0_min, pitch_index ); move16(); *T0_frac = 0; move16(); } - ELSE IF( EQ_16(fr_steps,2)) + ELSE IF( EQ_16( fr_steps, 2 ) ) { - *T0 = add(T0_min,shr(pitch_index,1)); + *T0 = add( T0_min, shr( pitch_index, 1 ) ); move16(); - temp = shl(sub(*T0,T0_min),1); - *T0_frac = shl(sub(pitch_index,temp),1); + temp = shl( sub( *T0, T0_min ), 1 ); + *T0_frac = shl( sub( pitch_index, temp ), 1 ); move16(); } - ELSE IF ( EQ_16(fr_steps,4)) + ELSE IF( EQ_16( fr_steps, 4 ) ) { - *T0 = add(T0_min,shr(pitch_index,2)); + *T0 = add( T0_min, shr( pitch_index, 2 ) ); move16(); - temp = shl(sub(*T0,T0_min),2); - *T0_frac = sub(pitch_index,temp); + temp = shl( sub( *T0, T0_min ), 2 ); + *T0_frac = sub( pitch_index, temp ); move16(); } diff --git a/lib_dec/pitch_extr_fx.c b/lib_dec/pitch_extr_fx.c index 7e46acdc4..78d0fc1f0 100644 --- a/lib_dec/pitch_extr_fx.c +++ b/lib_dec/pitch_extr_fx.c @@ -12,16 +12,15 @@ #include "basop_util.h" - /*-------------------------------------------------------------------* * - num x 32768 * ------------------- Q15 * PIT_MAX x Fact *-------------------------------------------------------------------*/ -#define PIT_MAX_DIV_8k(num, fact) ( -(num * 32768) / (PIT_MAX_12k8 * fact) ) -#define PIT_MAX_DIV_12k8(num, fact) ( -(num * 32768) / (PIT_MAX_12k8 * fact) ) -#define PIT_MAX_DIV_16k(num, fact) ( -(num * 32768) / (PIT_MAX_16k * fact) ) +#define PIT_MAX_DIV_8k( num, fact ) ( -( num * 32768 ) / ( PIT_MAX_12k8 * fact ) ) +#define PIT_MAX_DIV_12k8( num, fact ) ( -( num * 32768 ) / ( PIT_MAX_12k8 * fact ) ) +#define PIT_MAX_DIV_16k( num, fact ) ( -( num * 32768 ) / ( PIT_MAX_16k * fact ) ) /*-----------------------------------------------------------------* @@ -29,18 +28,28 @@ *-----------------------------------------------------------------*/ /*port is up to date with trunk 38840*/ void pitch_pred_linear_fit( - const Word16 /*short*/ bfi_cnt, /* i: bfi counter */ /*Q0 */ - const Word16 /*short*/ last_good, /* i: last classification type */ /*Q0 */ - Word32 /*float*/ *old_pitch_buf, /* i: pitch lag buffer */ /*Q16*/ - Word32 /*float*/ *old_fpitch, /* i: */ /*Q16*/ - Word32 /*float*/ *T0_out, /* o: estimated close loop pitch */ /*Q16*/ - Word16 /* int*/ pit_min, /* i: Minimum pitch lag */ /*Q0 */ - Word16 /* int*/ pit_max, /* i: Maximum pitch lag */ /*Q0 */ - Word16 /*float*/ *mem_pitch_gain, /* i: pitch gain [0] is the most recent subfr gain */ /*Q14*/ + const Word16 /*short*/ bfi_cnt, + /* i: bfi counter */ /*Q0 */ + const Word16 /*short*/ last_good, + /* i: last classification type */ /*Q0 */ + Word32 /*float*/ *old_pitch_buf, + /* i: pitch lag buffer */ /*Q16*/ + Word32 /*float*/ *old_fpitch, + /* i: */ /*Q16*/ + Word32 /*float*/ *T0_out, + /* o: estimated close loop pitch */ /*Q16*/ + Word16 /* int*/ pit_min, + /* i: Minimum pitch lag */ /*Q0 */ + Word16 /* int*/ pit_max, + /* i: Maximum pitch lag */ /*Q0 */ + Word16 /*float*/ *mem_pitch_gain, + /* i: pitch gain [0] is the most recent subfr gain */ /*Q14*/ Word16 /* int*/ limitation, - Word16 /*short*/ plc_use_future_lag, /* i: */ /*Q0 */ - Word16 /*short*/ *extrapolationFailed,/* o: flag if extrap decides not to change the pitch */ /*Q0 */ - Word16 nb_subfr /* i: number of ACELP subframes*/ + Word16 /*short*/ plc_use_future_lag, + /* i: */ /*Q0 */ + Word16 /*short*/ *extrapolationFailed, + /* o: flag if extrap decides not to change the pitch */ /*Q0 */ + Word16 nb_subfr /* i: number of ACELP subframes*/ ) { Word32 pit, a, b, pita, pitb; @@ -49,29 +58,29 @@ void pitch_pred_linear_fit( Word32 mdy, dy[5]; Word16 lcor; Word16 imax, i; - Word16 pg[8]; /* local buffer for pitch gain*/ - Word32 ml[8]; /* local buffer for mem_lag*/ - Word16 const timeWeight[5] = {20480/*1.25f Q14*/, 18432/*1.125f Q14*/, 16384/*1.f Q14*/, 14336/*0.875f Q14*/, 12288/*.75f Q14*/}; /*Q14*/ + Word16 pg[8]; /* local buffer for pitch gain*/ + Word32 ml[8]; /* local buffer for mem_lag*/ + Word16 const timeWeight[5] = { 20480 /*1.25f Q14*/, 18432 /*1.125f Q14*/, 16384 /*1.f Q14*/, 14336 /*0.875f Q14*/, 12288 /*.75f Q14*/ }; /*Q14*/ Word16 no_subfr_pred; Word16 a1, a2, a3, a4, a5, tmpa, tmpb, b1, b2, b3, b4, b5; Word16 a_e, b_e, sum0_q; - Word32 mem_lag[2*NB_SUBFR16k+2]; + Word32 mem_lag[2 * NB_SUBFR16k + 2]; /* Inverse the order the pitch lag memory */ - IF ( EQ_16(nb_subfr, 4)) + IF( EQ_16( nb_subfr, 4 ) ) { - FOR (i = 0; i < 2*NB_SUBFR+2; i++) + FOR( i = 0; i < 2 * NB_SUBFR + 2; i++ ) { - mem_lag[i] = old_pitch_buf[2*NB_SUBFR+1 - i]; + mem_lag[i] = old_pitch_buf[2 * NB_SUBFR + 1 - i]; move32(); } } - ELSE /* L_frame == L_FRAME16k */ + ELSE /* L_frame == L_FRAME16k */ { - FOR (i = 0; i < 2*NB_SUBFR16k+2; i++) + FOR( i = 0; i < 2 * NB_SUBFR16k + 2; i++ ) { - mem_lag[i] = old_pitch_buf[2*NB_SUBFR16k+1 - i]; + mem_lag[i] = old_pitch_buf[2 * NB_SUBFR16k + 1 - i]; move32(); } } @@ -81,7 +90,7 @@ void pitch_pred_linear_fit( move16(); move16(); /*timeweight*/ - IF (LT_16(pit_max,extract_h(*old_fpitch)) ) + IF( LT_16( pit_max, extract_h( *old_fpitch ) ) ) { *extrapolationFailed = 1; *T0_out = pit_max; @@ -90,31 +99,31 @@ void pitch_pred_linear_fit( move16(); lcor = 5; - T0 = L_deposit_l(0); + T0 = L_deposit_l( 0 ); test(); test(); - IF (EQ_16(bfi_cnt , 1)&&GE_16(last_good,UNVOICED_TRANSITION)&<_16(last_good,ONSET)) + IF( EQ_16( bfi_cnt, 1 ) && GE_16( last_good, UNVOICED_TRANSITION ) && LT_16( last_good, ONSET ) ) { move16(); no_subfr_pred = 4; - if (plc_use_future_lag!=0) + if ( plc_use_future_lag != 0 ) { move16(); no_subfr_pred = 2; } /* copy to local buffers, depending on availability of info about future subframes */ - Copy(mem_pitch_gain+no_subfr_pred-2,pg,8); - Copy32(mem_lag+no_subfr_pred-2,ml,8); + Copy( mem_pitch_gain + no_subfr_pred - 2, pg, 8 ); + Copy32( mem_lag + no_subfr_pred - 2, ml, 8 ); - mdy = L_deposit_l(0); + mdy = L_deposit_l( 0 ); - FOR (i = (sub(lcor,1)); i >= 0; i--) + FOR( i = ( sub( lcor, 1 ) ); i >= 0; i-- ) { move32(); - dy[i] = L_sub(ml[i] , ml[i+1]); - mdy = L_add(mdy , dy[i]); + dy[i] = L_sub( ml[i], ml[i + 1] ); + mdy = L_add( mdy, dy[i] ); } /*---------------------------------------------------* @@ -122,25 +131,26 @@ void pitch_pred_linear_fit( *---------------------------------------------------*/ move16(); imax = 0; - pita = L_abs(dy[0]); - FOR (i = 1; i Q9*/),mult_r(pg[3],16384/*Q12->Q11*/))/*Q5*/; - a4 = mac_r(L_mac(L_mult( mult_r(-12*2048,pg[0])/*Q8*/,pg[3] /*Q12*/)/*Q5+16*/,mult_r(-6*2048,pg[1])/*Q8*/,pg[3]/*Q12*/)/*Q5+16*/,mult_r(-2*2048,pg[2])/*Q8*/,pg[3]/*Q12*/)/*Q5*/; - a3 = mac_r(L_mac(L_mult( mult_r(-8*2048,pg[0]) /*Q8*/,pg[2]),mult_r(-3*2048,pg[1])/*Q8*/,pg[2]),mult_r(pg[2],4096/*Q12->Q9*/),mult_r(pg[3],16384/*12->Q11*/));/*Q5*/ - a2 = mac_r(L_mac(L_mult( mult_r(2*2048,pg[1]) /*Q8*/,pg[2])/*Q5+16*/,mult_r(2*2048,pg[1])/*Q8*/,pg[3])/*Q5+16*/,mult_r(-4*2048,pg[0])/*Q8*/,pg[1]/*Q12*/)/*Q5*/; - a1 = mac_r(L_mac(L_mult( mult_r(3*2048,pg[0]) /*Q8*/,pg[1])/*Q5+16*/,mult_r(4*2048,pg[0])/*Q8*/,pg[2]/*Q12*/)/*Q5+16*/,mult_r(3*2048,pg[0])/*Q8*/,pg[3]/*Q12*/)/*Q5*/; - - a = L_mac(L_mac(L_mac(L_mac(L_mult(a1 - , round_fx(L_shl(ml[0],4)))/*Q4*/ - , round_fx(L_shl(ml[1],4)) /*Q4*/, a2) - , round_fx(L_shl(ml[2],4)) /*Q4*/, a3) - , round_fx(L_shl(ml[3],4)) /*Q4*/, a4) - , round_fx(L_shl(ml[4],4)) /*Q4*/, a5); /*Q-6+16 = Q10*/ - - a_e = norm_l(a); - a = L_shl(a, a_e); - - a1 = BASOP_Util_Divide3216_Scale(L_negate(a), /* Numerator */ /*scalefactor 21*/ - sum0, /* Denominator*/ /*scalefactor 10*/ - &tmpa); /* scalefactor for result */ + a5 = mac_r( L_mac( L_mac( L_mult( mult_r( -32768, pg[0] ) /*Q8*/, pg[4] ) /*Q5+16*/, mult_r( -9 * 2048, pg[1] ) /*Q8*/, pg[4] /*Q12*/ ) /*Q5+16*/, mult_r( -4 * 2048, pg[2] ) /*Q8*/, pg[4] /*Q12*/ ) /*Q5+16*/, mult_r( pg[4], -4096 /*Q12->Q9*/ ), mult_r( pg[3], 16384 /*Q12->Q11*/ ) ) /*Q5*/; + a4 = mac_r( L_mac( L_mult( mult_r( -12 * 2048, pg[0] ) /*Q8*/, pg[3] /*Q12*/ ) /*Q5+16*/, mult_r( -6 * 2048, pg[1] ) /*Q8*/, pg[3] /*Q12*/ ) /*Q5+16*/, mult_r( -2 * 2048, pg[2] ) /*Q8*/, pg[3] /*Q12*/ ) /*Q5*/; + a3 = mac_r( L_mac( L_mult( mult_r( -8 * 2048, pg[0] ) /*Q8*/, pg[2] ), mult_r( -3 * 2048, pg[1] ) /*Q8*/, pg[2] ), mult_r( pg[2], 4096 /*Q12->Q9*/ ), mult_r( pg[3], 16384 /*12->Q11*/ ) ); /*Q5*/ + a2 = mac_r( L_mac( L_mult( mult_r( 2 * 2048, pg[1] ) /*Q8*/, pg[2] ) /*Q5+16*/, mult_r( 2 * 2048, pg[1] ) /*Q8*/, pg[3] ) /*Q5+16*/, mult_r( -4 * 2048, pg[0] ) /*Q8*/, pg[1] /*Q12*/ ) /*Q5*/; + a1 = mac_r( L_mac( L_mult( mult_r( 3 * 2048, pg[0] ) /*Q8*/, pg[1] ) /*Q5+16*/, mult_r( 4 * 2048, pg[0] ) /*Q8*/, pg[2] /*Q12*/ ) /*Q5+16*/, mult_r( 3 * 2048, pg[0] ) /*Q8*/, pg[3] /*Q12*/ ) /*Q5*/; + + a = L_mac( L_mac( L_mac( L_mac( L_mult( a1, round_fx( L_shl( ml[0], 4 ) ) ) /*Q4*/ + , + round_fx( L_shl( ml[1], 4 ) ) /*Q4*/, a2 ), + round_fx( L_shl( ml[2], 4 ) ) /*Q4*/, a3 ), + round_fx( L_shl( ml[3], 4 ) ) /*Q4*/, a4 ), + round_fx( L_shl( ml[4], 4 ) ) /*Q4*/, a5 ); /*Q-6+16 = Q10*/ + + a_e = norm_l( a ); + a = L_shl( a, a_e ); + + a1 = BASOP_Util_Divide3216_Scale( L_negate( a ), /* Numerator */ /*scalefactor 21*/ + sum0, /* Denominator*/ /*scalefactor 10*/ + &tmpa ); /* scalefactor for result */ /* Float: - b=(( pg[1]+2*pg[2]+3*pg[3]+4*pg[4])*pg[0] *//*b1*//* - *ml[0] + - (( pg[2]+2*pg[3]+3*pg[4])*pg[1]-pg[1]*pg[0]) *//*b2*//* - *ml[1] + - ( -2*pg[2]*pg[0]-pg[2]*pg[1]+(pg[3]+2*pg[4])*pg[2]) *//*b3*//* - *ml[2] + - ( -3*pg[3]*pg[0]-2*pg[3]*pg[1]-pg[3]*pg[2]+pg[4]*pg[3]) *//*b4*//* - *ml[3] + - ( -4*pg[4]*pg[0]-3*pg[4]*pg[1]-2*pg[4]*pg[2]-pg[4]*pg[3]) *//*b5*//* - *ml[4] )/sum0; MAC(22);MULT(9);DIV(1);*/ + b=(( pg[1]+2*pg[2]+3*pg[3]+4*pg[4])*pg[0] */ + /*b1*/ /* +*ml[0] + +(( pg[2]+2*pg[3]+3*pg[4])*pg[1]-pg[1]*pg[0]) */ + /*b2*/ /* +*ml[1] + +( -2*pg[2]*pg[0]-pg[2]*pg[1]+(pg[3]+2*pg[4])*pg[2]) */ + /*b3*/ /* +*ml[2] + +( -3*pg[3]*pg[0]-2*pg[3]*pg[1]-pg[3]*pg[2]+pg[4]*pg[3]) */ + /*b4*/ /* +*ml[3] + +( -4*pg[4]*pg[0]-3*pg[4]*pg[1]-2*pg[4]*pg[2]-pg[4]*pg[3]) */ + /*b5*/ /* + *ml[4] )/sum0; MAC(22);MULT(9);DIV(1);*/ /*magic numbers in Q13 if not DIRECTLY marked otherwise*/ - b1 = mac_r(L_mac(L_mac(L_mult(mult_r(pg[1],pg[0]),32768/4)/*Q7+16*/,mult_r(2*8192,pg[0])/*Q10*/,pg[2]/*Q12*/)/*Q7+16*/,mult_r(3*8192,pg[0])/*Q10*/,pg[3]/*Q12*/)/*Q7+16*/, /*mult_r(4*8192,pg[0])*/ pg[0]/*Q10*/,pg[4]/*Q12*/)/*Q7*/; - b2 = mac_r(L_mac(L_mac(L_mult(mult_r(pg[2],pg[1]),32768/4)/*Q7+16*/,mult_r(2*8192,pg[1]),pg[3]),mult_r(3*8192,pg[1]),pg[4])/*Q7+16*/,mult_r(pg[1],-32768/2/*Q12->Q12*/),mult_r(pg[0],32768/2/*Q12->Q10*/))/*Q7*/; - b3 = mac_r(L_mac(L_mac(L_mult(mult_r(-2*8192,pg[0]),pg[2])/*Q7+16*/,mult_r(pg[2],-32768/2),mult_r(pg[1],32768/2)),mult_r(pg[3],32768/2),mult_r(pg[2],32768/2))/*Q5+16*/,mult_r(2*8192,pg[2]),pg[4])/*Q7*/; - b4 = mac_r(L_mac(L_mac(L_mult(mult_r(-3*8192,pg[0]),pg[3]),mult_r(-2*8192,pg[1]),pg[3]),mult_r(-32768/2,pg[3]),mult_r(32768/2,pg[2])),mult_r(32768/2,pg[4]),mult_r(32768/2,pg[3]));/*Q7*/ - b5 = mac_r(L_mac(L_mac(L_mult(mult_r(-32768/*(-4*8192)*/,pg[0]),pg[4]),mult_r(-3*8192,pg[1]),pg[4]),mult_r(-2*8192,pg[2]),pg[4]),mult_r(-32768/2,pg[4]),mult_r(32768/2,pg[3]))/*Q7*/; - - b = L_mac(L_mac(L_mac(L_mac(L_mult(b1 - , round_fx(L_shl(ml[0],4)))/*Q4*/ - , round_fx(L_shl(ml[1],4)) /*Q4*/, b2) - , round_fx(L_shl(ml[2],4)) /*Q4*/, b3) - , round_fx(L_shl(ml[3],4)) /*Q4*/, b4) - , round_fx(L_shl(ml[4],4)) /*Q4*/, b5); /*Q-4+16 = Q12*/ + b1 = mac_r( L_mac( L_mac( L_mult( mult_r( pg[1], pg[0] ), 32768 / 4 ) /*Q7+16*/, mult_r( 2 * 8192, pg[0] ) /*Q10*/, pg[2] /*Q12*/ ) /*Q7+16*/, mult_r( 3 * 8192, pg[0] ) /*Q10*/, pg[3] /*Q12*/ ) /*Q7+16*/, /*mult_r(4*8192,pg[0])*/ pg[0] /*Q10*/, pg[4] /*Q12*/ ) /*Q7*/; + b2 = mac_r( L_mac( L_mac( L_mult( mult_r( pg[2], pg[1] ), 32768 / 4 ) /*Q7+16*/, mult_r( 2 * 8192, pg[1] ), pg[3] ), mult_r( 3 * 8192, pg[1] ), pg[4] ) /*Q7+16*/, mult_r( pg[1], -32768 / 2 /*Q12->Q12*/ ), mult_r( pg[0], 32768 / 2 /*Q12->Q10*/ ) ) /*Q7*/; + b3 = mac_r( L_mac( L_mac( L_mult( mult_r( -2 * 8192, pg[0] ), pg[2] ) /*Q7+16*/, mult_r( pg[2], -32768 / 2 ), mult_r( pg[1], 32768 / 2 ) ), mult_r( pg[3], 32768 / 2 ), mult_r( pg[2], 32768 / 2 ) ) /*Q5+16*/, mult_r( 2 * 8192, pg[2] ), pg[4] ) /*Q7*/; + b4 = mac_r( L_mac( L_mac( L_mult( mult_r( -3 * 8192, pg[0] ), pg[3] ), mult_r( -2 * 8192, pg[1] ), pg[3] ), mult_r( -32768 / 2, pg[3] ), mult_r( 32768 / 2, pg[2] ) ), mult_r( 32768 / 2, pg[4] ), mult_r( 32768 / 2, pg[3] ) ); /*Q7*/ + b5 = mac_r( L_mac( L_mac( L_mult( mult_r( -32768 /*(-4*8192)*/, pg[0] ), pg[4] ), mult_r( -3 * 8192, pg[1] ), pg[4] ), mult_r( -2 * 8192, pg[2] ), pg[4] ), mult_r( -32768 / 2, pg[4] ), mult_r( 32768 / 2, pg[3] ) ) /*Q7*/; + + b = L_mac( L_mac( L_mac( L_mac( L_mult( b1, round_fx( L_shl( ml[0], 4 ) ) ) /*Q4*/ + , + round_fx( L_shl( ml[1], 4 ) ) /*Q4*/, b2 ), + round_fx( L_shl( ml[2], 4 ) ) /*Q4*/, b3 ), + round_fx( L_shl( ml[3], 4 ) ) /*Q4*/, b4 ), + round_fx( L_shl( ml[4], 4 ) ) /*Q4*/, b5 ); /*Q-4+16 = Q12*/ /*predict pitch for 4th future subframe*/ - b_e = norm_l(b); - b = L_shl(b, b_e); + b_e = norm_l( b ); + b = L_shl( b, b_e ); - b1 = BASOP_Util_Divide3216_Scale(b, /* Numerator */ /*scalefactor 19*/ - sum0, /* Denominator*/ /*scalefactor 10*/ - &tmpb); /* scalefactor for result*/ + b1 = BASOP_Util_Divide3216_Scale( b, /* Numerator */ /*scalefactor 19*/ + sum0, /* Denominator*/ /*scalefactor 10*/ + &tmpb ); /* scalefactor for result*/ /*pit = a + b * ((float)no_subfr_pred + (float)nb_subfr);*/ - pita = L_shl( L_deposit_l(a1),add(add(sum0_q, 16-10+1),sub(tmpa, a_e)))/*Q16*/; - pitb = L_shl_r(L_mult(b1/*Q15*/,add(no_subfr_pred,nb_subfr)/*Q0*/ ),add(add(sum0_q, 16-12),sub(tmpb, b_e))); - pit = L_add( pita , pitb ); /*Q16*/ + pita = L_shl( L_deposit_l( a1 ), add( add( sum0_q, 16 - 10 + 1 ), sub( tmpa, a_e ) ) ) /*Q16*/; + pitb = L_shl_r( L_mult( b1 /*Q15*/, add( no_subfr_pred, nb_subfr ) /*Q0*/ ), add( add( sum0_q, 16 - 12 ), sub( tmpb, b_e ) ) ); + pit = L_add( pita, pitb ); /*Q16*/ - T0 = L_add(pit, 0); + T0 = L_add( pit, 0 ); /*limit pitch to allowed range*/ - T0 = L_min(L_deposit_h(pit_max),T0); - T0 = L_max(L_deposit_h(pit_min),T0); + T0 = L_min( L_deposit_h( pit_max ), T0 ); + T0 = L_max( L_deposit_h( pit_min ), T0 ); move16(); *extrapolationFailed = 0; } ELSE { - T0 = L_deposit_l(0); + T0 = L_deposit_l( 0 ); *extrapolationFailed = 1; move16(); } @@ -282,14 +302,14 @@ void pitch_pred_linear_fit( ELSE { - T0 = L_deposit_l(0); + T0 = L_deposit_l( 0 ); move16(); *extrapolationFailed = 1; } } ELSE { - T0 = L_add(*old_fpitch, 0); + T0 = L_add( *old_fpitch, 0 ); move16(); *extrapolationFailed = 1; } @@ -301,25 +321,27 @@ void pitch_pred_linear_fit( /* up to date with rev 8158*/ void get_subframe_pitch( - Word16 nSubframes, /* i: number of subframes */ /* Q0 */ - Word32 pitchStart, /* i: starting pitch lag (in subframe -1) */ /*15Q16*/ - Word32 pitchEnd, /* i: ending pitch lag (in subframe nSubframes-1) */ /*15Q16*/ - Word32 *pitchBuf /* o: interpolated pitch lag per subframe */ /*15Q16*/ + Word16 nSubframes, + /* i: number of subframes */ /* Q0 */ + Word32 pitchStart, + /* i: starting pitch lag (in subframe -1) */ /*15Q16*/ + Word32 pitchEnd, + /* i: ending pitch lag (in subframe nSubframes-1) */ /*15Q16*/ + Word32 *pitchBuf /* o: interpolated pitch lag per subframe */ /*15Q16*/ ) { - Word16 i,s; + Word16 i, s; Word32 pitchDelta; - assert((nSubframes > 0) && (pitchBuf != NULL) && (pitchStart >= 0) && (pitchEnd > 0)); + assert( ( nSubframes > 0 ) && ( pitchBuf != NULL ) && ( pitchStart >= 0 ) && ( pitchEnd > 0 ) ); /*pitchDelta = (pitchEnd - pitchStart)/nSubframes;*/ - pitchDelta = L_deposit_l(BASOP_Util_Divide3216_Scale(L_sub(pitchEnd,pitchStart),nSubframes, &s));/*Q15*/ - pitchDelta = L_shl(pitchDelta,add(s,1));/*Q16*/ - pitchBuf[0] = L_add(pitchStart,pitchDelta); - FOR (i = 1; i < nSubframes; i++) + pitchDelta = L_deposit_l( BASOP_Util_Divide3216_Scale( L_sub( pitchEnd, pitchStart ), nSubframes, &s ) ); /*Q15*/ + pitchDelta = L_shl( pitchDelta, add( s, 1 ) ); /*Q16*/ + pitchBuf[0] = L_add( pitchStart, pitchDelta ); + FOR( i = 1; i < nSubframes; i++ ) { - pitchBuf[i] = L_add(pitchBuf[i-1] , pitchDelta); + pitchBuf[i] = L_add( pitchBuf[i - 1], pitchDelta ); move32(); } } - diff --git a/lib_dec/post_dec_fx.c b/lib_dec/post_dec_fx.c index ddc727b09..1071b2389 100644 --- a/lib_dec/post_dec_fx.c +++ b/lib_dec/post_dec_fx.c @@ -14,9 +14,7 @@ * Function prototypes *---------------------------------------------------------------------*/ -static void bass_pf_1sf_delay( Word16 *syn, Word16 *T_sf, Word16 *gainT_sf, Word16 l_frame, - Word16 l_subfr, Word16 *bpf_noise_buf, Word16 *gain_factor_param, - Word8 disable_bpf, Word32 *lp_error_ener, Word32 *mem_error ); +static void bass_pf_1sf_delay( Word16 *syn, Word16 *T_sf, Word16 *gainT_sf, Word16 l_frame, Word16 l_subfr, Word16 *bpf_noise_buf, Word16 *gain_factor_param, Word8 disable_bpf, Word32 *lp_error_ener, Word32 *mem_error ); /*---------------------------------------------------------------------* * post_decoder() @@ -30,8 +28,7 @@ void post_decoder( Word16 pit_gain[], Word16 pitch[], Word16 signal_out[], - Word16 *bpf_noise_buf -) + Word16 *bpf_noise_buf ) { Word16 L_frame, nb_subfr; Word16 *synth, *synth2; @@ -39,20 +36,20 @@ void post_decoder( Word16 pitch_gain_adjust[NB_SUBFR16k]; Word16 tmp, tmp_noise; Word16 synth2_pe[L_FRAME_MAX]; - Word16 synth_buf2[PIT_MAX_16k+1+L_FRAME_MAX+M]; + Word16 synth_buf2[PIT_MAX_16k + 1 + L_FRAME_MAX + M]; Word32 bitrate; - Word8 tmp8; + Word8 tmp8; BPF_DEC_HANDLE hBPF; Word16 coder_type = st->coder_type; move16(); -// if (st->hPFstat != NULL || st->hBPF == NULL) -// { -//#ifdef DEBUGGING -// IVAS_ERROR(IVAS_ERR_INTERNAL, "ERROR::: In function post_decoder, at least one post filter handle is not initialized, at frame %d\n", frame); -//#endif -// return; -// } + // if (st->hPFstat != NULL || st->hBPF == NULL) + // { + //#ifdef DEBUGGING + // IVAS_ERROR(IVAS_ERR_INTERNAL, "ERROR::: In function post_decoder, at least one post filter handle is not initialized, at frame %d\n", frame); + //#endif + // return; + // } hBPF = st->hBPF; L_frame = st->L_frame; move16(); @@ -63,61 +60,61 @@ void post_decoder( st->hPFstat->on = 0; move16(); - bitrate = L_add(st->total_brate, 0); - if(st->core_brate <= SID_2k40) + bitrate = L_add( st->total_brate, 0 ); + if ( st->core_brate <= SID_2k40 ) { - bitrate = L_add(st->last_active_brate, 0); + bitrate = L_add( st->last_active_brate, 0 ); } /*Adapt Bpf: copy old and current adapt bpf parameters*/ - set16_fx(pitch_gain_adjust, st->bpf_gain_param, nb_subfr); + set16_fx( pitch_gain_adjust, st->bpf_gain_param, nb_subfr ); synth = synth_buf + st->hTcxDec->old_synth_len; synth2 = synth_buf2 + NBPSF_PIT_MAX; - Copy(hBPF->pst_old_syn_fx, synth_buf2, NBPSF_PIT_MAX ); + Copy( hBPF->pst_old_syn_fx, synth_buf2, NBPSF_PIT_MAX ); - IF ( st->tcxonly != 0 ) + IF( st->tcxonly != 0 ) { Copy( synth, synth2, L_frame ); - IF ( pfstat_on_previous ) + IF( pfstat_on_previous ) { - Copy( st->hPFstat->mem_pf_in+L_SYN_MEM-M, synth-M, M ); - Residu3_fx ( st->old_Aq_12_8_fx, synth, synth_buf, L_SUBFR, 1 ); - E_UTIL_synthesis ( 1, st->old_Aq_12_8_fx, synth_buf, synth2, L_SUBFR, st->hPFstat->mem_stp+L_SYN_MEM-M, 0, M ); - scale_st_fx ( synth, synth2, &st->hPFstat->gain_prec, L_SUBFR ); - blend_subfr2_fx(synth2+L_SUBFR/2, synth+L_SUBFR/2, synth2+L_SUBFR/2); + Copy( st->hPFstat->mem_pf_in + L_SYN_MEM - M, synth - M, M ); + Residu3_fx( st->old_Aq_12_8_fx, synth, synth_buf, L_SUBFR, 1 ); + E_UTIL_synthesis( 1, st->old_Aq_12_8_fx, synth_buf, synth2, L_SUBFR, st->hPFstat->mem_stp + L_SYN_MEM - M, 0, M ); + scale_st_fx( synth, synth2, &st->hPFstat->gain_prec, L_SUBFR ); + blend_subfr2_fx( synth2 + L_SUBFR / 2, synth + L_SUBFR / 2, synth2 + L_SUBFR / 2 ); } } ELSE { /*Formant enhancement*/ - IF ( EQ_16(st->last_bwidth,NB)) + IF( EQ_16( st->last_bwidth, NB ) ) { Copy( synth, synth2_pe, L_frame ); tmp = synth[-1]; move16(); - preemph_copy_fx( synth2_pe, synth2_pe, st->preemph_fac, L_frame, &tmp); + preemph_copy_fx( synth2_pe, synth2_pe, st->preemph_fac, L_frame, &tmp ); tmp = 0; move16(); test(); test(); - if ((GT_32(st->lp_noise, LP_NOISE_THRESH))|| - (st->core != ACELP_CORE) || - (EQ_16(coder_type, UNVOICED))) + if ( ( GT_32( st->lp_noise, LP_NOISE_THRESH ) ) || + ( st->core != ACELP_CORE ) || + ( EQ_16( coder_type, UNVOICED ) ) ) { tmp = 1; move16(); } - if(pfstat_on_previous==0) + if ( pfstat_on_previous == 0 ) { st->hPFstat->reset = 1; move16(); } - IF ( EQ_16(st->bwidth,NB)) + IF( EQ_16( st->bwidth, NB ) ) { st->hPFstat->on = 1; move16(); @@ -131,7 +128,7 @@ void post_decoder( tmp_noise = 0; nb_post_filt_fx( L_frame, st->hPFstat, &tmp_noise, 0, synth2_pe, st->mem_Aq, pitch, AUDIO, st->BER_detect, tmp ); } - Copy(synth2_pe, synth2, L_frame); + Copy( synth2_pe, synth2, L_frame ); tmp = synth2[-1]; move16(); @@ -139,12 +136,12 @@ void post_decoder( } ELSE { - if(pfstat_on_previous==0) + if ( pfstat_on_previous == 0 ) { st->hPFstat->reset = 1; move16(); } - IF ( GE_16(st->last_bwidth,WB)) + IF( GE_16( st->last_bwidth, WB ) ) { st->hPFstat->on = 1; move16(); @@ -162,13 +159,13 @@ void post_decoder( tmp8 = 0; move16(); test(); - if( GT_32(st->lp_noise,LP_NOISE_THRESH)&&st->narrowBand) + if ( GT_32( st->lp_noise, LP_NOISE_THRESH ) && st->narrowBand ) { tmp8 = 1; move16(); } bass_pf_1sf_delay( synth2, pitch, pit_gain, L_frame, L_SUBFR, bpf_noise_buf, pitch_gain_adjust, - tmp8, &(st->lp_error_ener), &(st->mem_error) ); + tmp8, &( st->lp_error_ener ), &( st->mem_error ) ); } /* Output */ @@ -188,8 +185,7 @@ void post_decoder_ivas_fx( Word16 pit_gain[], Word16 pitch[], Word16 signal_out[], - Word16 *bpf_noise_buf -) + Word16 *bpf_noise_buf ) { Word16 L_frame, nb_subfr; Word16 *synth, *synth2; @@ -197,9 +193,9 @@ void post_decoder_ivas_fx( Word16 pitch_gain_adjust[NB_SUBFR16k]; Word16 tmp, tmp_noise; Word16 synth2_pe[L_FRAME_MAX]; - Word16 synth_buf2[PIT_MAX_16k+1+L_FRAME_MAX+M]; + Word16 synth_buf2[PIT_MAX_16k + 1 + L_FRAME_MAX + M]; Word32 bitrate; - Word8 tmp8; + Word8 tmp8; BPF_DEC_HANDLE hBPF; Word16 coder_type = st->coder_type; @@ -212,7 +208,7 @@ void post_decoder_ivas_fx( pfstat_on_previous = 0; move16(); - IF(st->hPFstat != NULL) + IF( st->hPFstat != NULL ) { pfstat_on_previous = st->hPFstat->on; move16(); @@ -220,66 +216,66 @@ void post_decoder_ivas_fx( move16(); } - bitrate = L_add(st->total_brate, 0); - IF(LE_32(st->core_brate, SID_2k40)) + bitrate = L_add( st->total_brate, 0 ); + IF( LE_32( st->core_brate, SID_2k40 ) ) { - bitrate = L_add(st->last_active_brate, 0); + bitrate = L_add( st->last_active_brate, 0 ); } /*Adapt Bpf: copy old and current adapt bpf parameters*/ - set16_fx(pitch_gain_adjust, st->bpf_gain_param, nb_subfr); + set16_fx( pitch_gain_adjust, st->bpf_gain_param, nb_subfr ); synth = synth_buf + st->hTcxDec->old_synth_len; synth2 = synth_buf2 + NBPSF_PIT_MAX; - IF(st->hBPF != NULL) + IF( st->hBPF != NULL ) { - Copy(hBPF->pst_old_syn_fx, synth_buf2, NBPSF_PIT_MAX); + Copy( hBPF->pst_old_syn_fx, synth_buf2, NBPSF_PIT_MAX ); } - IF ( st->tcxonly != 0 ) + IF( st->tcxonly != 0 ) { Copy( synth, synth2, L_frame ); - IF ( pfstat_on_previous ) + IF( pfstat_on_previous ) { - Copy( st->hPFstat->mem_pf_in+L_SYN_MEM-M, synth-M, M ); + Copy( st->hPFstat->mem_pf_in + L_SYN_MEM - M, synth - M, M ); Word16 L_subfr = st->L_frame / st->nb_subfr; - Residu3_fx ( st->old_Aq_12_8_fx, synth, synth_buf, L_subfr, 1 ); - E_UTIL_synthesis ( 1, st->old_Aq_12_8_fx, synth_buf, synth2, L_subfr, st->hPFstat->mem_stp+L_SYN_MEM-M, 0, M ); - scale_st_fx ( synth, synth2, &st->hPFstat->gain_prec, L_subfr ); - blend_subfr2_fx(synth2+L_subfr/2, synth+L_subfr/2, synth2+L_subfr/2); + Residu3_fx( st->old_Aq_12_8_fx, synth, synth_buf, L_subfr, 1 ); + E_UTIL_synthesis( 1, st->old_Aq_12_8_fx, synth_buf, synth2, L_subfr, st->hPFstat->mem_stp + L_SYN_MEM - M, 0, M ); + scale_st_fx( synth, synth2, &st->hPFstat->gain_prec, L_subfr ); + blend_subfr2_fx( synth2 + L_subfr / 2, synth + L_subfr / 2, synth2 + L_subfr / 2 ); } } ELSE { /*Formant enhancement*/ - IF ( EQ_16(st->last_bwidth,NB)) + IF( EQ_16( st->last_bwidth, NB ) ) { Copy( synth, synth2_pe, L_frame ); tmp = synth[-1]; move16(); - preemph_copy_fx( synth2_pe, synth2_pe, st->preemph_fac, L_frame, &tmp); + preemph_copy_fx( synth2_pe, synth2_pe, st->preemph_fac, L_frame, &tmp ); tmp = 0; move16(); test(); test(); - if ((GT_32(st->lp_noise, LP_NOISE_THRESH))|| - (st->core != ACELP_CORE) || - (EQ_16(coder_type, UNVOICED))) + if ( ( GT_32( st->lp_noise, LP_NOISE_THRESH ) ) || + ( st->core != ACELP_CORE ) || + ( EQ_16( coder_type, UNVOICED ) ) ) { tmp = 1; move16(); } - IF(EQ_16(pfstat_on_previous, 0)) + IF( EQ_16( pfstat_on_previous, 0 ) ) { st->hPFstat->reset = 1; move16(); } - IF ( EQ_16(st->bwidth,NB)) + IF( EQ_16( st->bwidth, NB ) ) { st->hPFstat->on = 1; move16(); @@ -293,7 +289,7 @@ void post_decoder_ivas_fx( tmp_noise = 0; nb_post_filt_fx( L_frame, st->hPFstat, &tmp_noise, 0, synth2_pe, st->mem_Aq, pitch, AUDIO, st->BER_detect, tmp ); } - Copy(synth2_pe, synth2, L_frame); + Copy( synth2_pe, synth2, L_frame ); tmp = synth2[-1]; move16(); @@ -301,12 +297,12 @@ void post_decoder_ivas_fx( } ELSE { - IF(EQ_16(pfstat_on_previous, 0)) + IF( EQ_16( pfstat_on_previous, 0 ) ) { st->hPFstat->reset = 1; move16(); } - IF ( GE_16(st->last_bwidth,WB)) + IF( GE_16( st->last_bwidth, WB ) ) { st->hPFstat->on = 1; move16(); @@ -324,22 +320,22 @@ void post_decoder_ivas_fx( tmp8 = 0; move16(); test(); - if( GT_32(st->lp_noise,LP_NOISE_THRESH)&&st->narrowBand) + if ( GT_32( st->lp_noise, LP_NOISE_THRESH ) && st->narrowBand ) { tmp8 = 1; move16(); } bass_pf_1sf_delay( synth2, pitch, pit_gain, L_frame, L_SUBFR, bpf_noise_buf, pitch_gain_adjust, - tmp8, &(st->lp_error_ener), &(st->mem_error) ); + tmp8, &( st->lp_error_ener ), &( st->mem_error ) ); } /* Output */ Copy( synth2, signal_out, L_frame ); /* Update synth2 memory */ - IF(st->hBPF != NULL) + IF( st->hBPF != NULL ) { - Copy(synth_buf2 + L_frame, hBPF->pst_old_syn_fx, NBPSF_PIT_MAX); + Copy( synth_buf2 + L_frame, hBPF->pst_old_syn_fx, NBPSF_PIT_MAX ); } @@ -354,230 +350,226 @@ void post_decoder_ivas_fx( *---------------------------------------------------------------------*/ static void bass_pf_1sf_delay( - Word16 *syn, /* (i) : 12.8kHz synthesis to postfilter Q0 */ - Word16 *T_sf, /* (i) : Pitch period for all subframes (T_sf[16]) Q0 */ - Word16 *gainT_sf, /* (i) : Pitch gain for all subframes (gainT_sf[16]) Q14 */ - Word16 l_frame, /* (i) : frame length (should be multiple of l_subfr) Q0 */ - Word16 l_subfr, /* (i) : sub-frame length (60/64) Q0 */ - Word16 *bpf_noise_buf, /* (i) : harmoninc filtered signal Q0 */ - Word16 *gain_factor_param, /* (i) : gain factor param 0-> no BPF, 3-> full BPF */ + Word16 *syn, /* (i) : 12.8kHz synthesis to postfilter Q0 */ + Word16 *T_sf, /* (i) : Pitch period for all subframes (T_sf[16]) Q0 */ + Word16 *gainT_sf, /* (i) : Pitch gain for all subframes (gainT_sf[16]) Q14 */ + Word16 l_frame, /* (i) : frame length (should be multiple of l_subfr) Q0 */ + Word16 l_subfr, /* (i) : sub-frame length (60/64) Q0 */ + Word16 *bpf_noise_buf, /* (i) : harmoninc filtered signal Q0 */ + Word16 *gain_factor_param, /* (i) : gain factor param 0-> no BPF, 3-> full BPF */ Word8 disable_bpf, Word32 *lp_error_ener, - Word32 *mem_error -) + Word32 *mem_error ) { Word16 i, sf, i_subfr, T, lg, s1, st, tmp16; Word16 gain; Word32 tmp, nrg, lp_error, tmp32; Word32 ener2; - assert(bpf_noise_buf != NULL); + assert( bpf_noise_buf != NULL ); sf = 0; move16(); - lp_error = L_shl(*mem_error, 0); + lp_error = L_shl( *mem_error, 0 ); - FOR (i_subfr = 0; i_subfr < l_frame; i_subfr += l_subfr) + FOR( i_subfr = 0; i_subfr < l_frame; i_subfr += l_subfr ) { T = T_sf[sf]; move16(); - lg = sub(sub(l_frame, T), i_subfr); - if (lg < 0) + lg = sub( sub( l_frame, T ), i_subfr ); + if ( lg < 0 ) { lg = 0; move16(); } - if (lg > l_subfr) + if ( lg > l_subfr ) { lg = l_subfr; move16(); } test(); - IF (disable_bpf == 0 && gainT_sf[sf] > 0) + IF( disable_bpf == 0 && gainT_sf[sf] > 0 ) { /* get headroom for used part of syn */ - tmp16 = add(l_subfr, T); - if (lg>0) + tmp16 = add( l_subfr, T ); + if ( lg > 0 ) { - tmp16 = add(lg, shl(T, 1)); + tmp16 = add( lg, shl( T, 1 ) ); } - s1 = getScaleFactor16(syn + sub(i_subfr, T), tmp16); - s1 = sub(s1, 3); + s1 = getScaleFactor16( syn + sub( i_subfr, T ), tmp16 ); + s1 = sub( s1, 3 ); - tmp = L_deposit_l(1); - nrg = L_deposit_l(1); + tmp = L_deposit_l( 1 ); + nrg = L_deposit_l( 1 ); - IF (lg > 0) + IF( lg > 0 ) { { Word64 tmp64 = W_deposit32_l( tmp ); Word64 nrg64 = W_deposit32_l( nrg ); - FOR (i = 0; i < lg; i++) + FOR( i = 0; i < lg; i++ ) { - tmp32 = L_mult(syn[i+i_subfr-T], 0x4000); - tmp32 = L_mac(tmp32, syn[i+i_subfr+T], 0x4000); - tmp16 = round_fx(L_shl(tmp32, s1)); /* Q0+s1 */ + tmp32 = L_mult( syn[i + i_subfr - T], 0x4000 ); + tmp32 = L_mac( tmp32, syn[i + i_subfr + T], 0x4000 ); + tmp16 = round_fx( L_shl( tmp32, s1 ) ); /* Q0+s1 */ - tmp64 = W_mac0_16_16(tmp64, shl(syn[i+i_subfr], s1), tmp16); /* Q0+2*s1 */ - nrg64 = W_mac0_16_16(nrg64, tmp16, tmp16); /* Q0+2*s1 */ + tmp64 = W_mac0_16_16( tmp64, shl( syn[i + i_subfr], s1 ), tmp16 ); /* Q0+2*s1 */ + nrg64 = W_mac0_16_16( nrg64, tmp16, tmp16 ); /* Q0+2*s1 */ } - tmp = W_sat_l(tmp64); - nrg = W_sat_l(nrg64); + tmp = W_sat_l( tmp64 ); + nrg = W_sat_l( nrg64 ); } - } - IF (LT_16(lg, l_subfr)) + IF( LT_16( lg, l_subfr ) ) { { Word64 tmp64 = W_deposit32_l( tmp ); Word64 nrg64 = W_deposit32_l( nrg ); - FOR (i = lg; i < l_subfr; i++) + FOR( i = lg; i < l_subfr; i++ ) { - tmp16 = shl(syn[i+i_subfr-T], s1); /* Q0+s1 */ - tmp64 = W_mac0_16_16(tmp64, shl(syn[i+i_subfr], s1), tmp16); /* Q0+2*s1 */ - nrg64 = W_mac0_16_16(nrg64, tmp16, tmp16); /* Q0+2*s1 */ + tmp16 = shl( syn[i + i_subfr - T], s1 ); /* Q0+s1 */ + tmp64 = W_mac0_16_16( tmp64, shl( syn[i + i_subfr], s1 ), tmp16 ); /* Q0+2*s1 */ + nrg64 = W_mac0_16_16( nrg64, tmp16, tmp16 ); /* Q0+2*s1 */ } - tmp = W_sat_l(tmp64); - nrg = W_sat_l(nrg64); + tmp = W_sat_l( tmp64 ); + nrg = W_sat_l( nrg64 ); } - } /* gain = tmp/nrg; */ - gain = BASOP_Util_Divide3232_Scale(tmp, nrg, &tmp16); + gain = BASOP_Util_Divide3232_Scale( tmp, nrg, &tmp16 ); BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB - gain = shl_sat(gain, tmp16); /* Q15 */ + gain = shl_sat( gain, tmp16 ); /* Q15 */ #else - gain = shl(gain, tmp16); /* Q15 */ + gain = shl( gain, tmp16 ); /* Q15 */ #endif BASOP_SATURATE_WARNING_ON_EVS; - if (gain < 0) + if ( gain < 0 ) { gain = 0; move16(); } - st = sub(norm_l(lp_error), 3); + st = sub( norm_l( lp_error ), 3 ); test(); - if ((LT_16(st, s1))&&(lp_error!=0)) + if ( ( LT_16( st, s1 ) ) && ( lp_error != 0 ) ) { s1 = st; move16(); } - ener2 = L_deposit_l(0); + ener2 = L_deposit_l( 0 ); - IF (lg > 0) + IF( lg > 0 ) { { Word64 ener2_64 = W_deposit32_l( ener2 ); - FOR (i = 0; i < lg; i++) + FOR( i = 0; i < lg; i++ ) { - tmp32 = L_msu0(0, gain, syn[i+i_subfr-T]); - tmp32 = L_msu0(tmp32, gain, syn[i+i_subfr+T]); + tmp32 = L_msu0( 0, gain, syn[i + i_subfr - T] ); + tmp32 = L_msu0( tmp32, gain, syn[i + i_subfr + T] ); #ifdef BASOP_NOGLOB - tmp16 = mac_r_sat(tmp32, gain, syn[i+i_subfr]); /* Q0 */ + tmp16 = mac_r_sat( tmp32, gain, syn[i + i_subfr] ); /* Q0 */ #else - tmp16 = mac_r(tmp32, gain, syn[i+i_subfr]); /* Q0 */ + tmp16 = mac_r( tmp32, gain, syn[i + i_subfr] ); /* Q0 */ #endif - lp_error = Mpy_32_16_1(lp_error, 29491/*0.9f Q15*/); + lp_error = Mpy_32_16_1( lp_error, 29491 /*0.9f Q15*/ ); #ifdef BASOP_NOGLOB - lp_error = L_mac_sat( lp_error, tmp16, 0x1000 ); /* Q13 */ - tmp16 = round_fx_sat( L_shl_sat( lp_error, s1 ) ); /* Q0+s1-3 */ + lp_error = L_mac_sat( lp_error, tmp16, 0x1000 ); /* Q13 */ + tmp16 = round_fx_sat( L_shl_sat( lp_error, s1 ) ); /* Q0+s1-3 */ #else - lp_error = L_mac(lp_error, tmp16, 0x1000); /* Q13 */ + lp_error = L_mac( lp_error, tmp16, 0x1000 ); /* Q13 */ - tmp16 = round_fx(L_shl(lp_error, s1)); /* Q0+s1-3 */ + tmp16 = round_fx( L_shl( lp_error, s1 ) ); /* Q0+s1-3 */ #endif - ener2_64 = W_mac0_16_16(ener2_64, tmp16, tmp16); /* Q0+(s1-3)*2 */ + ener2_64 = W_mac0_16_16( ener2_64, tmp16, tmp16 ); /* Q0+(s1-3)*2 */ } - ener2 = W_sat_l(ener2_64); + ener2 = W_sat_l( ener2_64 ); } - } - IF (LT_16(lg, l_subfr)) + IF( LT_16( lg, l_subfr ) ) { { Word64 ener2_64 = W_deposit32_l( ener2 ); - FOR (i = lg; i < l_subfr; i++) + FOR( i = lg; i < l_subfr; i++ ) { #ifdef BASOP_NOGLOB tmp32 = L_mult0( gain, syn[i + i_subfr] ); - tmp32 = L_msu0_sat(tmp32, gain, syn[i+i_subfr-T]); /* Q0 */ - tmp16 = round_fx_sat(tmp32); + tmp32 = L_msu0_sat( tmp32, gain, syn[i + i_subfr - T] ); /* Q0 */ + tmp16 = round_fx_sat( tmp32 ); - lp_error = Mpy_32_16_1(lp_error, 29491/*0.9f Q15*/); - lp_error = L_mac_sat(lp_error, tmp16, 0x1000); /* Q13 */ + lp_error = Mpy_32_16_1( lp_error, 29491 /*0.9f Q15*/ ); + lp_error = L_mac_sat( lp_error, tmp16, 0x1000 ); /* Q13 */ - tmp16 = round_fx_sat(L_shl_sat(lp_error, s1)); /* Q0+s1-3 */ + tmp16 = round_fx_sat( L_shl_sat( lp_error, s1 ) ); /* Q0+s1-3 */ #else - tmp32 = L_mult0(gain, syn[i+i_subfr]); - tmp32 = L_msu0(tmp32, gain, syn[i+i_subfr-T]); /* Q0 */ - tmp16 = round_fx(tmp32); + tmp32 = L_mult0( gain, syn[i + i_subfr] ); + tmp32 = L_msu0( tmp32, gain, syn[i + i_subfr - T] ); /* Q0 */ + tmp16 = round_fx( tmp32 ); - lp_error = Mpy_32_16_1(lp_error, 29491/*0.9f Q15*/); - lp_error = L_mac(lp_error, tmp16, 0x1000); /* Q13 */ + lp_error = Mpy_32_16_1( lp_error, 29491 /*0.9f Q15*/ ); + lp_error = L_mac( lp_error, tmp16, 0x1000 ); /* Q13 */ - tmp16 = round_fx(L_shl(lp_error, s1)); /* Q0+s1-3 */ + tmp16 = round_fx( L_shl( lp_error, s1 ) ); /* Q0+s1-3 */ #endif - ener2_64 = W_mac0_16_16(ener2_64, tmp16, tmp16); /* Q0+(s1-3)*2 */ + ener2_64 = W_mac0_16_16( ener2_64, tmp16, tmp16 ); /* Q0+(s1-3)*2 */ } - ener2 = W_sat_l(ener2_64); + ener2 = W_sat_l( ener2_64 ); } - } - st = shl(sub(s1, 3), 1); + st = shl( sub( s1, 3 ), 1 ); - IF (ener2 > 0) + IF( ener2 > 0 ) { - ener2 = L_shr(BASOP_Util_Log2(ener2), 9); /* 15Q16 */ - ener2 = L_add(ener2, L_deposit_h(sub(31, st))); + ener2 = L_shr( BASOP_Util_Log2( ener2 ), 9 ); /* 15Q16 */ + ener2 = L_add( ener2, L_deposit_h( sub( 31, st ) ) ); } ELSE { - ener2 = L_add(0xFFF95B2C, 0); /* log2(0.01) (15Q16) */ + ener2 = L_add( 0xFFF95B2C, 0 ); /* log2(0.01) (15Q16) */ } - *lp_error_ener = L_add(Mpy_32_16_1(L_sub(*lp_error_ener, ener2), 32440/*0.99f Q15*/), ener2); /* 15Q16 */ + *lp_error_ener = L_add( Mpy_32_16_1( L_sub( *lp_error_ener, ener2 ), 32440 /*0.99f Q15*/ ), ener2 ); /* 15Q16 */ - st = add(st, 6); - ener2 = L_sub(*lp_error_ener, L_deposit_h(sub(31, st))); - IF (ener2 >= 0) + st = add( st, 6 ); + ener2 = L_sub( *lp_error_ener, L_deposit_h( sub( 31, st ) ) ); + IF( ener2 >= 0 ) { - tmp16 = add(extract_h(ener2), 1); - ener2 = L_sub(ener2, L_deposit_h(tmp16)); - tmp = L_shr(tmp, tmp16); - nrg = L_shr(nrg, tmp16); + tmp16 = add( extract_h( ener2 ), 1 ); + ener2 = L_sub( ener2, L_deposit_h( tmp16 ) ); + tmp = L_shr( tmp, tmp16 ); + nrg = L_shr( nrg, tmp16 ); } - ener2 = BASOP_Util_InvLog2(L_shl(ener2, 9)); /* Q0+2*s1 */ + ener2 = BASOP_Util_InvLog2( L_shl( ener2, 9 ) ); /* Q0+2*s1 */ - tmp32 = L_add(L_shr(nrg, 1), L_shr(ener2, 1)); - if (tmp32 == 0) tmp32 = L_deposit_l(1); - tmp16 = BASOP_Util_Divide3232_Scale(tmp, tmp32, &st); + tmp32 = L_add( L_shr( nrg, 1 ), L_shr( ener2, 1 ) ); + if ( tmp32 == 0 ) + tmp32 = L_deposit_l( 1 ); + tmp16 = BASOP_Util_Divide3232_Scale( tmp, tmp32, &st ); BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB - tmp16 = shl_sat(tmp16, sub(st, 2)); /* Q15 */ + tmp16 = shl_sat( tmp16, sub( st, 2 ) ); /* Q15 */ #else - tmp16 = shl(tmp16, sub(st, 2)); /* Q15 */ + tmp16 = shl( tmp16, sub( st, 2 ) ); /* Q15 */ #endif - if (GT_16(tmp16, 16384/*0.5f Q15*/)) + if ( GT_16( tmp16, 16384 /*0.5f Q15*/ ) ) { - tmp16 = 16384/*0.5f Q15*/; + tmp16 = 16384 /*0.5f Q15*/; move16(); } - if (tmp16 < 0) + if ( tmp16 < 0 ) { tmp16 = 0; move16(); @@ -587,48 +579,48 @@ static void bass_pf_1sf_delay( /*Adjust gain*/ /* full gain = gainLTP*0.5*/ /* adaptive gain = gainLTP*0.5*max(0.5f*gain_factor_param[sf],0.125f)*/ - tmp16 = round_fx(L_shl(L_mult0(tmp16, s_max(shl(gain_factor_param[sf],2),1)),13)); + tmp16 = round_fx( L_shl( L_mult0( tmp16, s_max( shl( gain_factor_param[sf], 2 ), 1 ) ), 13 ) ); /* calculate noise based on voiced pitch */ - IF (lg > 0) + IF( lg > 0 ) { - FOR (i = 0; i < lg; i++) + FOR( i = 0; i < lg; i++ ) { - tmp32 = L_msu0(0, tmp16, syn[i+i_subfr-T]); + tmp32 = L_msu0( 0, tmp16, syn[i + i_subfr - T] ); #ifdef BASOP_NOGLOB tmp32 = L_msu0_sat( tmp32, tmp16, syn[i + i_subfr + T] ); - tmp32 = L_mac_sat(tmp32, tmp16, syn[i+i_subfr]); - bpf_noise_buf[i+i_subfr] = round_fx_sat(tmp32); /* Q0 */ + tmp32 = L_mac_sat( tmp32, tmp16, syn[i + i_subfr] ); + bpf_noise_buf[i + i_subfr] = round_fx_sat( tmp32 ); /* Q0 */ #else - tmp32 = L_msu0(tmp32, tmp16, syn[i+i_subfr+T]); - tmp32 = L_mac(tmp32, tmp16, syn[i+i_subfr]); - bpf_noise_buf[i+i_subfr] = round_fx(tmp32); /* Q0 */ + tmp32 = L_msu0( tmp32, tmp16, syn[i + i_subfr + T] ); + tmp32 = L_mac( tmp32, tmp16, syn[i + i_subfr] ); + bpf_noise_buf[i + i_subfr] = round_fx( tmp32 ); /* Q0 */ #endif } } - IF (LT_16(lg, l_subfr)) + IF( LT_16( lg, l_subfr ) ) { - FOR (i = lg; i < l_subfr; i++) + FOR( i = lg; i < l_subfr; i++ ) { - tmp32 = L_mult0(tmp16, syn[i+i_subfr]); + tmp32 = L_mult0( tmp16, syn[i + i_subfr] ); #ifdef BASOP_NOGLOB tmp32 = L_msu0_sat( tmp32, tmp16, syn[i + i_subfr - T] ); - bpf_noise_buf[i+i_subfr] = round_fx_sat(tmp32); /* Q0 */ + bpf_noise_buf[i + i_subfr] = round_fx_sat( tmp32 ); /* Q0 */ #else - tmp32 = L_msu0(tmp32, tmp16, syn[i+i_subfr-T]); - bpf_noise_buf[i+i_subfr] = round_fx(tmp32); /* Q0 */ + tmp32 = L_msu0( tmp32, tmp16, syn[i + i_subfr - T] ); + bpf_noise_buf[i + i_subfr] = round_fx( tmp32 ); /* Q0 */ #endif } } } ELSE { - set16_fx(bpf_noise_buf+i_subfr, 0, l_subfr); + set16_fx( bpf_noise_buf + i_subfr, 0, l_subfr ); } - sf = add(sf, 1); + sf = add( sf, 1 ); } *mem_error = lp_error; @@ -649,8 +641,7 @@ void cldfb_synth_set_bandsToZero( Word32 **rAnalysis, Word32 **iAnalysis, const Word16 nTimeSlots, - const CLDFB_SCALE_FACTOR scaleFactor -) + const CLDFB_SCALE_FACTOR scaleFactor ) { Word32 nrgQ31; Word32 nrg_band[CLDFB_NO_CHANNELS_MAX], tempQ31, max_nrg; @@ -672,51 +663,51 @@ void cldfb_synth_set_bandsToZero( offset = 250; WBcnt = 20; - perc_miss = 13107; /*0.80 in Q14*/ + perc_miss = 13107; /*0.80 in Q14*/ perc_detect = 14746; /*0.90 in Q14*/ - IF(EQ_16(st->VAD,1)) + IF( EQ_16( st->VAD, 1 ) ) { - st->active_frame_cnt_bwddec = add(st->active_frame_cnt_bwddec,1); - st->total_frame_cnt_bwddec = add(st->total_frame_cnt_bwddec,1); - if(GT_16(st->active_frame_cnt_bwddec, 99)) + st->active_frame_cnt_bwddec = add( st->active_frame_cnt_bwddec, 1 ); + st->total_frame_cnt_bwddec = add( st->total_frame_cnt_bwddec, 1 ); + if ( GT_16( st->active_frame_cnt_bwddec, 99 ) ) { st->active_frame_cnt_bwddec = 100; move16(); } - if(GT_16(st->total_frame_cnt_bwddec, 500)) + if ( GT_16( st->total_frame_cnt_bwddec, 500 ) ) { st->total_frame_cnt_bwddec = 500; move16(); } - FOR (i = 0; i < (st->cldfbSyn->no_channels - st->cldfbSyn->bandsToZero); i++) + FOR( i = 0; i < ( st->cldfbSyn->no_channels - st->cldfbSyn->bandsToZero ); i++ ) { nrgQ31 = 0; move32(); - FOR (k = 0; k < nTimeSlots; k++) + FOR( k = 0; k < nTimeSlots; k++ ) { /* use 16-bit precision of real and imag buffers */ - realQ1 = extract_l(L_shr(rAnalysis[k][i], 31-(15+scaleFactor.lb_scale)+3)); - imagQ1 = extract_l(L_shr(iAnalysis[k][i], 31-(15+scaleFactor.lb_scale)+3)); /* Q(-3), headroom */ + realQ1 = extract_l( L_shr( rAnalysis[k][i], 31 - ( 15 + scaleFactor.lb_scale ) + 3 ) ); + imagQ1 = extract_l( L_shr( iAnalysis[k][i], 31 - ( 15 + scaleFactor.lb_scale ) + 3 ) ); /* Q(-3), headroom */ #ifdef BASOP_NOGLOB - nrgQ31 = L_mac0_o(nrgQ31, realQ1, realQ1, &Overflow); - nrgQ31 = L_mac0_o(nrgQ31, imagQ1, imagQ1, &Overflow); /* keep in Q(-6) */ + nrgQ31 = L_mac0_o( nrgQ31, realQ1, realQ1, &Overflow ); + nrgQ31 = L_mac0_o( nrgQ31, imagQ1, imagQ1, &Overflow ); /* keep in Q(-6) */ #else - nrgQ31 = L_mac0(nrgQ31, realQ1, realQ1); - nrgQ31 = L_mac0(nrgQ31, imagQ1, imagQ1); /* keep in Q(-6) */ + nrgQ31 = L_mac0( nrgQ31, realQ1, realQ1 ); + nrgQ31 = L_mac0( nrgQ31, imagQ1, imagQ1 ); /* keep in Q(-6) */ #endif } - nrg_band[i] = (nrgQ31); + nrg_band[i] = ( nrgQ31 ); move16(); test(); - if(GT_32(nrg_band[i], max_nrg)&&GE_16(i,11)) + if ( GT_32( nrg_band[i], max_nrg ) && GE_16( i, 11 ) ) { max_nrg = nrg_band[i]; move16(); } } - FOR(; i < st->cldfbSyn->no_channels; i++) + FOR( ; i < st->cldfbSyn->no_channels; i++ ) { nrg_band[i] = 0; move16(); @@ -724,17 +715,17 @@ void cldfb_synth_set_bandsToZero( nrgQ31 = 0; move16(); - FOR(i = 2; i < 9; i++) + FOR( i = 2; i < 9; i++ ) { - nrgQ31 = L_add(nrgQ31, Mult_32_16(nrg_band[i], 4681)); + nrgQ31 = L_add( nrgQ31, Mult_32_16( nrg_band[i], 4681 ) ); } - tempQ31 = L_shr(nrgQ31,9); + tempQ31 = L_shr( nrgQ31, 9 ); - st->avg_nrg_LT = L_add(Mult_32_16(st->avg_nrg_LT, 32440), Mult_32_16(tempQ31, 327)); /*0.99*avg_nrg_LT + 0.01*tempQ31*/ + st->avg_nrg_LT = L_add( Mult_32_16( st->avg_nrg_LT, 32440 ), Mult_32_16( tempQ31, 327 ) ); /*0.99*avg_nrg_LT + 0.01*tempQ31*/ update_perc = 1; move16(); - if(st->ini_frame >= 25 && tempQ31 < Mult_32_16(st->avg_nrg_LT, 164)) + if ( st->ini_frame >= 25 && tempQ31 < Mult_32_16( st->avg_nrg_LT, 164 ) ) { update_perc = 0; move16(); @@ -742,50 +733,50 @@ void cldfb_synth_set_bandsToZero( flag = 1; move16(); - if(max_nrg >= tempQ31) + if ( max_nrg >= tempQ31 ) { flag = 0; move16(); } - FOR(i = 0; i < WBcnt-1; i++) + FOR( i = 0; i < WBcnt - 1; i++ ) { - st->flag_buffer[i] = st->flag_buffer[i+1]; + st->flag_buffer[i] = st->flag_buffer[i + 1]; move16(); } - st->flag_buffer[WBcnt-1] = flag; + st->flag_buffer[WBcnt - 1] = flag; move16(); /*long term percentage*/ - IF(EQ_16(update_perc, 1)) + IF( EQ_16( update_perc, 1 ) ) { - IF(flag != 0) + IF( flag != 0 ) { - tmp1 = sub(16384, st->perc_bwddec); /*Q14*/ + tmp1 = sub( 16384, st->perc_bwddec ); /*Q14*/ - tmp = norm_s(st->active_frame_cnt_bwddec); - tmp3 = shl(st->active_frame_cnt_bwddec, tmp); /*Qtmp*/ + tmp = norm_s( st->active_frame_cnt_bwddec ); + tmp3 = shl( st->active_frame_cnt_bwddec, tmp ); /*Qtmp*/ - tmp2 = div_s(16384,tmp3); /* 1/active_frames in Q15 + Q14 - Qtmp = Q29 - Qtmp */ - tmp2 = mult_r(tmp2, tmp1); /*(1-perc)*(1/active_frames) in Q14 + Q29 - Qtmp - Q15 = Q28 - Qtmp*/ - st->perc_bwddec = add(st->perc_bwddec, shl(tmp2, sub(tmp, 14))); /* Q14 */ + tmp2 = div_s( 16384, tmp3 ); /* 1/active_frames in Q15 + Q14 - Qtmp = Q29 - Qtmp */ + tmp2 = mult_r( tmp2, tmp1 ); /*(1-perc)*(1/active_frames) in Q14 + Q29 - Qtmp - Q15 = Q28 - Qtmp*/ + st->perc_bwddec = add( st->perc_bwddec, shl( tmp2, sub( tmp, 14 ) ) ); /* Q14 */ } ELSE { - tmp1 = (st->perc_bwddec); /*Q14*/ + tmp1 = ( st->perc_bwddec ); /*Q14*/ - tmp = norm_s(st->active_frame_cnt_bwddec); - tmp3 = shl(st->active_frame_cnt_bwddec, tmp); /*Qtmp*/ + tmp = norm_s( st->active_frame_cnt_bwddec ); + tmp3 = shl( st->active_frame_cnt_bwddec, tmp ); /*Qtmp*/ - tmp2 = div_s(16384,tmp3); /* 1/active_frames in Q15 + Q14 - Qtmp = Q29 - Qtmp */ - tmp2 = mult_r(tmp2, tmp1); /*(perc)*(1/active_frames) in Q14 + Q29 - Qtmp - Q15 = Q28 - Qtmp*/ - st->perc_bwddec = sub(st->perc_bwddec, shl(tmp2, sub(tmp, 14))); /* Q14 */ + tmp2 = div_s( 16384, tmp3 ); /* 1/active_frames in Q15 + Q14 - Qtmp = Q29 - Qtmp */ + tmp2 = mult_r( tmp2, tmp1 ); /*(perc)*(1/active_frames) in Q14 + Q29 - Qtmp - Q15 = Q28 - Qtmp*/ + st->perc_bwddec = sub( st->perc_bwddec, shl( tmp2, sub( tmp, 14 ) ) ); /* Q14 */ } } test(); - IF(GT_16(st->total_frame_cnt_bwddec, offset)&>_16(st->active_frame_cnt_bwddec,50)) + IF( GT_16( st->total_frame_cnt_bwddec, offset ) && GT_16( st->active_frame_cnt_bwddec, 50 ) ) { - IF( (st->perc_bwddec >= perc_detect || (st->perc_bwddec >= perc_miss && st->last_flag_filter_NB)) && (sum16_fx(st->flag_buffer, WBcnt) != 0)) /*decision hysterysis*/ + IF( ( st->perc_bwddec >= perc_detect || ( st->perc_bwddec >= perc_miss && st->last_flag_filter_NB ) ) && ( sum16_fx( st->flag_buffer, WBcnt ) != 0 ) ) /*decision hysterysis*/ { st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, 10 ); move16(); @@ -803,7 +794,7 @@ void cldfb_synth_set_bandsToZero( st->last_flag_filter_NB = 0; move16(); } - IF(sum16_fx(st->flag_buffer, WBcnt) == 0) + IF( sum16_fx( st->flag_buffer, WBcnt ) == 0 ) { st->perc_bwddec = 0; st->active_frame_cnt_bwddec = 0; @@ -816,13 +807,13 @@ void cldfb_synth_set_bandsToZero( } ELSE { - IF(st->last_flag_filter_NB == 1) + IF( st->last_flag_filter_NB == 1 ) { st->cldfbSyn->bandsToZero = st->last_active_bandsToZero_bwdec; move16(); } - st->total_frame_cnt_bwddec = add(st->total_frame_cnt_bwddec, 1); - if(GT_16(st->total_frame_cnt_bwddec, 500)) + st->total_frame_cnt_bwddec = add( st->total_frame_cnt_bwddec, 1 ); + if ( GT_16( st->total_frame_cnt_bwddec, 500 ) ) { st->total_frame_cnt_bwddec = 500; move16(); @@ -833,4 +824,4 @@ void cldfb_synth_set_bandsToZero( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/ppp_dec_fx.c b/lib_dec/ppp_dec_fx.c index f9a4faef7..24461a7fb 100644 --- a/lib_dec/ppp_dec_fx.c +++ b/lib_dec/ppp_dec_fx.c @@ -8,50 +8,49 @@ #include "prot_fx2.h" #include "rom_com.h" - /*===================================================================*/ - /* FUNCTION : struct DTFS_fx::dequant_cw_fx () */ - /*-------------------------------------------------------------------*/ - /* PURPOSE : Dequantize QPPP prototype */ - /*-------------------------------------------------------------------*/ - /* INPUT ARGUMENTS : */ - /* _ (Word16) pl: previous lag */ - /* _ (Word16) p_idx: Power index */ - /* _ (Word16[]) a_idx: Amplitude indices, 2 words */ - /* _ (struct DTFS_fx) X : prototype in polar domain */ - /* (Word16) lag: length of prototype */ - /*-------------------------------------------------------------------*/ - /* OUTPUT ARGUMENTS : */ - /* _ (struct DTFS_fx) X : prototype in polar domain */ - /* (Word16) lag: length of prototype in time domain */ - /* (Word16 []) a: amplitude of harmonics, normalized */ - /* (Word16) Q: norm factor of a */ - /* _ (Word16[]) curr_erb: Quantized current ERB, Q13 */ - /*-------------------------------------------------------------------*/ - /* INPUT/OUTPUT ARGUMENTS : */ - /* _ (Word16[]) lasterb: ERB history for differential */ - /* quantization, Q13 */ - /* _ (Word16) Lgain: low band power history, log domain, Q11 */ - /* _ (Word16) Hgain: high band power history, log domain, Q11 */ - /*-------------------------------------------------------------------*/ - /* RETURN ARGUMENTS : _ None. */ - /*-------------------------------------------------------------------*/ - /* CALLED FROM : TX/RX */ - /*===================================================================*/ +/*===================================================================*/ +/* FUNCTION : struct DTFS_fx::dequant_cw_fx () */ +/*-------------------------------------------------------------------*/ +/* PURPOSE : Dequantize QPPP prototype */ +/*-------------------------------------------------------------------*/ +/* INPUT ARGUMENTS : */ +/* _ (Word16) pl: previous lag */ +/* _ (Word16) p_idx: Power index */ +/* _ (Word16[]) a_idx: Amplitude indices, 2 words */ +/* _ (struct DTFS_fx) X : prototype in polar domain */ +/* (Word16) lag: length of prototype */ +/*-------------------------------------------------------------------*/ +/* OUTPUT ARGUMENTS : */ +/* _ (struct DTFS_fx) X : prototype in polar domain */ +/* (Word16) lag: length of prototype in time domain */ +/* (Word16 []) a: amplitude of harmonics, normalized */ +/* (Word16) Q: norm factor of a */ +/* _ (Word16[]) curr_erb: Quantized current ERB, Q13 */ +/*-------------------------------------------------------------------*/ +/* INPUT/OUTPUT ARGUMENTS : */ +/* _ (Word16[]) lasterb: ERB history for differential */ +/* quantization, Q13 */ +/* _ (Word16) Lgain: low band power history, log domain, Q11 */ +/* _ (Word16) Hgain: high band power history, log domain, Q11 */ +/*-------------------------------------------------------------------*/ +/* RETURN ARGUMENTS : _ None. */ +/*-------------------------------------------------------------------*/ +/* CALLED FROM : TX/RX */ +/*===================================================================*/ static void DTFS_dequant_cw_fx( - Word16 pl_fx, /* i : Previous lag */ - Word16 POWER_IDX_fx, /* i : POWER index */ - const Word16* AMP_IDX_fx, /* i : Amp Shape index */ - Word16* lastLgainD_fx, /* i/o: low band last gain */ - Word16* lastHgainD_fx, /* i/o: high band last gain */ - Word16* lasterbD_fx, /* i/o: last frame ERB vector */ - DTFS_STRUCTURE* X_fx, /* o : DTFS structure dequantized */ - Word16 num_erb_fx -) + Word16 pl_fx, /* i : Previous lag */ + Word16 POWER_IDX_fx, /* i : POWER index */ + const Word16 *AMP_IDX_fx, /* i : Amp Shape index */ + Word16 *lastLgainD_fx, /* i/o: low band last gain */ + Word16 *lastHgainD_fx, /* i/o: high band last gain */ + Word16 *lasterbD_fx, /* i/o: last frame ERB vector */ + DTFS_STRUCTURE *X_fx, /* o : DTFS structure dequantized */ + Word16 num_erb_fx ) { Word16 tmp_fx, mfreq_fx[NUM_ERB_WB], curr_erb_fx[NUM_ERB_WB]; - const Word16* PowerCB_fx = NULL; + const Word16 *PowerCB_fx = NULL; Word16 slot_fx[NUM_ERB_WB]; Word16 Ql, Qh, n; Word32 Ltemp_fx, logLag_fx; @@ -59,12 +58,12 @@ static void DTFS_dequant_cw_fx( Word32 L_tmp, L_temp; Word32 L_tmp2; - IF(num_erb_fx == NUM_ERB_NB) + IF( num_erb_fx == NUM_ERB_NB ) { PowerCB_fx = PowerCB_NB_fx; move16(); } - ELSE IF(num_erb_fx == NUM_ERB_WB) + ELSE IF( num_erb_fx == NUM_ERB_WB ) { PowerCB_fx = PowerCB_WB_fx; move16(); @@ -72,137 +71,134 @@ static void DTFS_dequant_cw_fx( /* Amplitude Dequantization */ - erb_add_fx(curr_erb_fx, X_fx->lag_fx, lasterbD_fx, pl_fx, AMP_IDX_fx, num_erb_fx); + erb_add_fx( curr_erb_fx, X_fx->lag_fx, lasterbD_fx, pl_fx, AMP_IDX_fx, num_erb_fx ); - curr_erb_fx[0] = mult_r(curr_erb_fx[1], 9830);/* 0.3 inQ15 leaves curr_erb in Q13 */ - curr_erb_fx[sub(num_erb_fx, 2)] = mult_r(curr_erb_fx[sub(num_erb_fx, 3)], 9830);/* Q13 */ + curr_erb_fx[0] = mult_r( curr_erb_fx[1], 9830 ); /* 0.3 inQ15 leaves curr_erb in Q13 */ + curr_erb_fx[sub( num_erb_fx, 2 )] = mult_r( curr_erb_fx[sub( num_erb_fx, 3 )], 9830 ); /* Q13 */ move16(); - curr_erb_fx[sub(num_erb_fx, 1)] = 0; + curr_erb_fx[sub( num_erb_fx, 1 )] = 0; - erb_slot_fx(X_fx->lag_fx, slot_fx, mfreq_fx, num_erb_fx); + erb_slot_fx( X_fx->lag_fx, slot_fx, mfreq_fx, num_erb_fx ); /* mfreq normalized (2.56) in Q15 */ - DTFS_erb_inv_fx(curr_erb_fx, slot_fx, mfreq_fx, X_fx, num_erb_fx); + DTFS_erb_inv_fx( curr_erb_fx, slot_fx, mfreq_fx, X_fx, num_erb_fx ); /* Back up the lasterbD memory after power normalization */ - DTFS_setEngyHarm_fx(236, 2828, 0, 2828, 1, 0, &Ql, X_fx); - DTFS_setEngyHarm_fx(2828, X_fx->upper_cut_off_freq_of_interest_fx, 2828, X_fx->upper_cut_off_freq_fx, 1, 0, &Qh, X_fx); + DTFS_setEngyHarm_fx( 236, 2828, 0, 2828, 1, 0, &Ql, X_fx ); + DTFS_setEngyHarm_fx( 2828, X_fx->upper_cut_off_freq_of_interest_fx, 2828, X_fx->upper_cut_off_freq_fx, 1, 0, &Qh, X_fx ); /* Need to unify the Q factors of both bands */ - X_fx->Q = s_min(Ql, Qh); /* set Q factor to be the smaller one */ - n = sub(Ql, Qh); /* compare band Q factors */ - - + X_fx->Q = s_min( Ql, Qh ); /* set Q factor to be the smaller one */ + n = sub( Ql, Qh ); /* compare band Q factors */ /* This logic adjusts difference between Q formats of both bands */ - IF(n < 0) - rshiftHarmBand_fx(X_fx, 2828, X_fx->upper_cut_off_freq_fx, n); - ELSE IF(n > 0) - rshiftHarmBand_fx(X_fx, 0, 2828, sub(Qh, Ql)); + IF( n < 0 ) + rshiftHarmBand_fx( X_fx, 2828, X_fx->upper_cut_off_freq_fx, n ); + ELSE IF( n > 0 ) + rshiftHarmBand_fx( X_fx, 0, 2828, sub( Qh, Ql ) ); - DTFS_to_erb_fx(*X_fx, lasterbD_fx); + DTFS_to_erb_fx( *X_fx, lasterbD_fx ); /* Power Dequantization */ - tmp_fx = shl(POWER_IDX_fx, 1); /* tmp=2*POWER_IDX */ + tmp_fx = shl( POWER_IDX_fx, 1 ); /* tmp=2*POWER_IDX */ #ifdef BASOP_NOGLOB - *lastLgainD_fx = add_sat(*lastLgainD_fx, PowerCB_fx[tmp_fx]); /* Q11 */ - *lastHgainD_fx = add_sat(*lastHgainD_fx, PowerCB_fx[tmp_fx + 1]); /* Q11 */ + *lastLgainD_fx = add_sat( *lastLgainD_fx, PowerCB_fx[tmp_fx] ); /* Q11 */ + *lastHgainD_fx = add_sat( *lastHgainD_fx, PowerCB_fx[tmp_fx + 1] ); /* Q11 */ #else - *lastLgainD_fx = add(*lastLgainD_fx, PowerCB_fx[tmp_fx]); /* Q11 */ - *lastHgainD_fx = add(*lastHgainD_fx, PowerCB_fx[tmp_fx + 1]); /* Q11 */ + *lastLgainD_fx = add( *lastLgainD_fx, PowerCB_fx[tmp_fx] ); /* Q11 */ + *lastHgainD_fx = add( *lastHgainD_fx, PowerCB_fx[tmp_fx + 1] ); /* Q11 */ #endif - L_tmp = L_deposit_h(X_fx->lag_fx); /* Q16 */ - exp = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, exp); - frac = Log2_norm_lc(L_tmp); - exp = sub(30, add(exp, 16)); - L_tmp = Mpy_32_16(exp, frac, 12330);/* Q13 */ /* 10*log10(2) in Q12*/ - Ltemp_fx = L_shl(L_tmp, 10);/* Q23 */ + L_tmp = L_deposit_h( X_fx->lag_fx ); /* Q16 */ + exp = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, exp ); + frac = Log2_norm_lc( L_tmp ); + exp = sub( 30, add( exp, 16 ) ); + L_tmp = Mpy_32_16( exp, frac, 12330 ); /* Q13 */ /* 10*log10(2) in Q12*/ + Ltemp_fx = L_shl( L_tmp, 10 ); /* Q23 */ - logLag_fx = Mult_32_16(Ltemp_fx, 0x6666); /* logLag=log10(lag), Q26 */ + logLag_fx = Mult_32_16( Ltemp_fx, 0x6666 ); /* logLag=log10(lag), Q26 */ - Ltemp_fx = L_sub(L_shr(L_deposit_h(*lastLgainD_fx), 1), logLag_fx); /* Ltemp=Lgain-log10(lag), Q26 */ + Ltemp_fx = L_sub( L_shr( L_deposit_h( *lastLgainD_fx ), 1 ), logLag_fx ); /* Ltemp=Lgain-log10(lag), Q26 */ /* Lacc_fx=dsp_pow10(Ltemp_fx); : Lacc=10^Lgain/lag, Q15 */ - L_tmp = Mult_32_16(Ltemp_fx, 27213); /* 3.321928 in Q13 */ - L_tmp = L_shr(L_tmp, 8); /* Q16 */ - frac = L_Extract_lc(L_tmp, &exp1); /* Extract exponent */ - L_tmp = Pow2(14, frac); - exp1 = sub(exp1, 14); + L_tmp = Mult_32_16( Ltemp_fx, 27213 ); /* 3.321928 in Q13 */ + L_tmp = L_shr( L_tmp, 8 ); /* Q16 */ + frac = L_Extract_lc( L_tmp, &exp1 ); /* Extract exponent */ + L_tmp = Pow2( 14, frac ); + exp1 = sub( exp1, 14 ); #ifdef BASOP_NOGLOB - L_temp = L_shl_sat(L_tmp, add(exp1, 15) ); /* Q15 */ + L_temp = L_shl_sat( L_tmp, add( exp1, 15 ) ); /* Q15 */ #else - L_temp = L_shl(L_tmp, add(exp1, 15)); /* Q15 */ + L_temp = L_shl( L_tmp, add( exp1, 15 ) ); /* Q15 */ #endif L_tmp2 = L_temp; - if (GE_32(L_temp, 2147483647)) + if ( GE_32( L_temp, 2147483647 ) ) { - L_temp = L_shl(L_tmp, 15); /*Q(15-exp1) */ + L_temp = L_shl( L_tmp, 15 ); /*Q(15-exp1) */ } - n = norm_l(L_temp); - Ltemp_fx = L_shl(L_temp, n); /* Ltemp in Q(15+n) or Q(15 - exp1 +n) */ + n = norm_l( L_temp ); + Ltemp_fx = L_shl( L_temp, n ); /* Ltemp in Q(15+n) or Q(15 - exp1 +n) */ - IF(GE_32(L_tmp2, 2147483647)) + IF( GE_32( L_tmp2, 2147483647 ) ) { - DTFS_setEngyHarm_fx(236, 2828, 0, 2828, Ltemp_fx, add(15, sub(n, exp1)), &Ql, X_fx); + DTFS_setEngyHarm_fx( 236, 2828, 0, 2828, Ltemp_fx, add( 15, sub( n, exp1 ) ), &Ql, X_fx ); } ELSE { - DTFS_setEngyHarm_fx(236, 2828, 0, 2828, Ltemp_fx, add(15,n), &Ql, X_fx); + DTFS_setEngyHarm_fx( 236, 2828, 0, 2828, Ltemp_fx, add( 15, n ), &Ql, X_fx ); } - Ltemp_fx = L_sub(L_shr(L_deposit_h(*lastHgainD_fx), 1), logLag_fx); /* Ltemp=Hgain-log10(lag), Q26 */ + Ltemp_fx = L_sub( L_shr( L_deposit_h( *lastHgainD_fx ), 1 ), logLag_fx ); /* Ltemp=Hgain-log10(lag), Q26 */ /* Lacc_fx=dsp_pow10(Ltemp_fx); : Lacc=10^Hgain/lag, Q15 */ - L_tmp = Mult_32_16(Ltemp_fx, 27213); /* 3.321928 in Q13 */ /* Q24 */ - L_tmp = L_shr(L_tmp, 8); /* Q16 */ - frac = L_Extract_lc(L_tmp, &exp1); /* Extract exponent */ - L_tmp = Pow2(14, frac); - exp1 = sub(exp1, 14); + L_tmp = Mult_32_16( Ltemp_fx, 27213 ); /* 3.321928 in Q13 */ /* Q24 */ + L_tmp = L_shr( L_tmp, 8 ); /* Q16 */ + frac = L_Extract_lc( L_tmp, &exp1 ); /* Extract exponent */ + L_tmp = Pow2( 14, frac ); + exp1 = sub( exp1, 14 ); #ifdef BASOP_NOGLOB L_temp = L_shl_sat( L_tmp, exp1 + 15 ); /* Q15 */ #else - L_temp = L_shl( L_tmp, exp1 + 15 ); /* Q15 */ + L_temp = L_shl( L_tmp, exp1 + 15 ); /* Q15 */ #endif L_tmp2 = L_temp; - if (GE_32(L_temp, 2147483647)) + if ( GE_32( L_temp, 2147483647 ) ) { - L_temp = L_shl(L_tmp, 15); /*Q(15-exp1) */ + L_temp = L_shl( L_tmp, 15 ); /*Q(15-exp1) */ } - n = norm_l(L_temp); - Ltemp_fx = L_shl(L_temp, n); /* Ltemp in Q(15+n) or Q(15 - exp1 +n) */ + n = norm_l( L_temp ); + Ltemp_fx = L_shl( L_temp, n ); /* Ltemp in Q(15+n) or Q(15 - exp1 +n) */ - IF(GE_32(L_tmp2, 2147483647)) + IF( GE_32( L_tmp2, 2147483647 ) ) { - DTFS_setEngyHarm_fx(2828, X_fx->upper_cut_off_freq_of_interest_fx, 2828, X_fx->upper_cut_off_freq_fx, Ltemp_fx, add(15, sub(n, exp1)), &Qh, X_fx); + DTFS_setEngyHarm_fx( 2828, X_fx->upper_cut_off_freq_of_interest_fx, 2828, X_fx->upper_cut_off_freq_fx, Ltemp_fx, add( 15, sub( n, exp1 ) ), &Qh, X_fx ); } ELSE { - DTFS_setEngyHarm_fx(2828, X_fx->upper_cut_off_freq_of_interest_fx,2828, X_fx->upper_cut_off_freq_fx, Ltemp_fx, add(15, n), &Qh, X_fx); + DTFS_setEngyHarm_fx( 2828, X_fx->upper_cut_off_freq_of_interest_fx, 2828, X_fx->upper_cut_off_freq_fx, Ltemp_fx, add( 15, n ), &Qh, X_fx ); } - /* Need to unify the Q factors of both bands */ - X_fx->Q = s_min(Ql, Qh); /* set Q factor to be the smaller one */ - n = sub(Ql, Qh); /* compare band Q factors */ - + /* Need to unify the Q factors of both bands */ + X_fx->Q = s_min( Ql, Qh ); /* set Q factor to be the smaller one */ + n = sub( Ql, Qh ); /* compare band Q factors */ - IF(n < 0) - rshiftHarmBand_fx(X_fx, 2828, X_fx->upper_cut_off_freq_fx, n); - ELSE IF(n > 0) - rshiftHarmBand_fx(X_fx, 0, 2828, sub(Qh, Ql)); + IF( n < 0 ) + rshiftHarmBand_fx( X_fx, 2828, X_fx->upper_cut_off_freq_fx, n ); + ELSE IF( n > 0 ) + rshiftHarmBand_fx( X_fx, 0, 2828, sub( Qh, Ql ) ); } /*===================================================================*/ /* FUNCTION : void ppp_quarter_decoder_fx () */ @@ -245,57 +241,56 @@ static void DTFS_dequant_cw_fx( /* CALLED FROM : RX */ /*===================================================================*/ ivas_error ppp_quarter_decoder_fx( - DTFS_STRUCTURE *CURRCW_Q_DTFS_FX, /* i/o: Current CW DTFS */ - Word16 prevCW_lag_fx, /* i : Previous lag */ - Word16 *lastLgainD_fx, /* i/o: Last gain lowband Q11 */ - Word16 *lastHgainD_fx, /* i/o: Last gain highwband Q11 */ - Word16 *lasterbD_fx, /* i/o: Last ERB vector Q13 */ - Word16 bfi, /* i : FER flag */ - Word16 *S_fx, /* i : sine table, Q15 */ - Word16 *C_fx, /* i : cosine table, Q15 */ - DTFS_STRUCTURE PREV_CW_D_FX, /* i : Previous DTFS */ - Decoder_State *st_fx -) + DTFS_STRUCTURE *CURRCW_Q_DTFS_FX, /* i/o: Current CW DTFS */ + Word16 prevCW_lag_fx, /* i : Previous lag */ + Word16 *lastLgainD_fx, /* i/o: Last gain lowband Q11 */ + Word16 *lastHgainD_fx, /* i/o: Last gain highwband Q11 */ + Word16 *lasterbD_fx, /* i/o: Last ERB vector Q13 */ + Word16 bfi, /* i : FER flag */ + Word16 *S_fx, /* i : sine table, Q15 */ + Word16 *C_fx, /* i : cosine table, Q15 */ + DTFS_STRUCTURE PREV_CW_D_FX, /* i : Previous DTFS */ + Decoder_State *st_fx ) { DTFS_STRUCTURE *PREVDTFS_FX; Word16 AMP_IDX_fx[2]; - Word16 temp_pl_fx = prevCW_lag_fx, temp_l_fx = CURRCW_Q_DTFS_FX->lag_fx; + Word16 temp_pl_fx = prevCW_lag_fx, temp_l_fx = CURRCW_Q_DTFS_FX->lag_fx; Word16 temp_fx; Word16 l_fx = CURRCW_Q_DTFS_FX->lag_fx; Word16 POWER_IDX_fx; Word16 Erot_fx = 0; Word16 num_erb_fx = 24; - Word32 temp32d_fx,temp32n_fx; + Word32 temp32d_fx, temp32n_fx; Word32 L_tmp, L_tmp1; Word16 tmp, exp; ivas_error error; error = IVAS_ERR_OK; move16(); - IF ((error = DTFS_new_fx(&PREVDTFS_FX)) != IVAS_ERR_OK) + IF( ( error = DTFS_new_fx( &PREVDTFS_FX ) ) != IVAS_ERR_OK ) { return error; } - IF ( EQ_16(CURRCW_Q_DTFS_FX->upper_cut_off_freq_fx,4000 )) + IF( EQ_16( CURRCW_Q_DTFS_FX->upper_cut_off_freq_fx, 4000 ) ) { num_erb_fx = 22; move16(); } - ELSE IF ( EQ_16(CURRCW_Q_DTFS_FX->upper_cut_off_freq_fx,6400)) + ELSE IF( EQ_16( CURRCW_Q_DTFS_FX->upper_cut_off_freq_fx, 6400 ) ) { num_erb_fx = 24; move16(); } - DTFS_copy_fx(PREVDTFS_FX, PREV_CW_D_FX); - IF (bfi == 0) + DTFS_copy_fx( PREVDTFS_FX, PREV_CW_D_FX ); + IF( bfi == 0 ) { - POWER_IDX_fx =(Word16) get_next_indice( st_fx, 6); + POWER_IDX_fx = (Word16) get_next_indice( st_fx, 6 ); move16(); - AMP_IDX_fx[0] =(Word16) get_next_indice( st_fx, 6); + AMP_IDX_fx[0] = (Word16) get_next_indice( st_fx, 6 ); move16(); - AMP_IDX_fx[1] =(Word16) get_next_indice( st_fx, 6); + AMP_IDX_fx[1] = (Word16) get_next_indice( st_fx, 6 ); move16(); /* Amplitude Dequantization */ @@ -303,60 +298,59 @@ ivas_error ppp_quarter_decoder_fx( dequant_cw. So upper cut-off frequencies need to be multiplied by a factor2.56. This logic of normalisation is not employed in adjustlag, hence denormalisation is necessury.*/ /*As the upper cut of freqencies are normalized to 12800, we have to multiply upper cut off freq by - 2.56(1/12800 in Q15) */ - temp32n_fx = L_mult(CURRCW_Q_DTFS_FX->upper_cut_off_freq_fx,10486);/* Q0+Q27 = Q28 */ - CURRCW_Q_DTFS_FX->upper_cut_off_freq_fx = (Word16)L_shr(temp32n_fx,13);/*Q15 */ - temp32n_fx = L_mult(CURRCW_Q_DTFS_FX->upper_cut_off_freq_of_interest_fx,10486);/* Q0+Q27 = Q28 */ - CURRCW_Q_DTFS_FX->upper_cut_off_freq_of_interest_fx = (Word16)L_shr(temp32n_fx,13);/*Q15 */ + 2.56(1/12800 in Q15) */ + temp32n_fx = L_mult( CURRCW_Q_DTFS_FX->upper_cut_off_freq_fx, 10486 ); /* Q0+Q27 = Q28 */ + CURRCW_Q_DTFS_FX->upper_cut_off_freq_fx = (Word16) L_shr( temp32n_fx, 13 ); /*Q15 */ + temp32n_fx = L_mult( CURRCW_Q_DTFS_FX->upper_cut_off_freq_of_interest_fx, 10486 ); /* Q0+Q27 = Q28 */ + CURRCW_Q_DTFS_FX->upper_cut_off_freq_of_interest_fx = (Word16) L_shr( temp32n_fx, 13 ); /*Q15 */ - DTFS_dequant_cw_fx(prevCW_lag_fx,POWER_IDX_fx,AMP_IDX_fx,lastLgainD_fx,lastHgainD_fx,lasterbD_fx,CURRCW_Q_DTFS_FX,num_erb_fx); + DTFS_dequant_cw_fx( prevCW_lag_fx, POWER_IDX_fx, AMP_IDX_fx, lastLgainD_fx, lastHgainD_fx, lasterbD_fx, CURRCW_Q_DTFS_FX, num_erb_fx ); /*De-normalize cut off frequencies */ - temp32n_fx = L_shl((Word32)CURRCW_Q_DTFS_FX->upper_cut_off_freq_fx,13);/*Q28 */ - CURRCW_Q_DTFS_FX->upper_cut_off_freq_fx = (Word16)find_remd(temp32n_fx, 20971,&temp32d_fx); - temp32n_fx = L_shl((Word32)CURRCW_Q_DTFS_FX->upper_cut_off_freq_of_interest_fx,13);/*Q28 */ - CURRCW_Q_DTFS_FX->upper_cut_off_freq_of_interest_fx = (Word16)find_remd(temp32n_fx, 20971,&temp32d_fx); + temp32n_fx = L_shl( (Word32) CURRCW_Q_DTFS_FX->upper_cut_off_freq_fx, 13 ); /*Q28 */ + CURRCW_Q_DTFS_FX->upper_cut_off_freq_fx = (Word16) find_remd( temp32n_fx, 20971, &temp32d_fx ); + temp32n_fx = L_shl( (Word32) CURRCW_Q_DTFS_FX->upper_cut_off_freq_of_interest_fx, 13 ); /*Q28 */ + CURRCW_Q_DTFS_FX->upper_cut_off_freq_of_interest_fx = (Word16) find_remd( temp32n_fx, 20971, &temp32d_fx ); } /* Copying phase spectrum over */ - DTFS_adjustLag_fx(PREVDTFS_FX,l_fx); + DTFS_adjustLag_fx( PREVDTFS_FX, l_fx ); - temp_fx = sub(L_FRAME,temp_l_fx); /*Q0 */ + temp_fx = sub( L_FRAME, temp_l_fx ); /*Q0 */ - exp = norm_s(temp_pl_fx); - tmp = div_s(shl(1,sub(14,exp)),temp_pl_fx); /*Q(29-exp) */ - L_tmp = L_mult(temp_fx,tmp); /*Q(31-exp); +1 due to /2 */ - L_tmp = L_shl(L_tmp,sub(exp,15)); /*Q16 */ + exp = norm_s( temp_pl_fx ); + tmp = div_s( shl( 1, sub( 14, exp ) ), temp_pl_fx ); /*Q(29-exp) */ + L_tmp = L_mult( temp_fx, tmp ); /*Q(31-exp); +1 due to /2 */ + L_tmp = L_shl( L_tmp, sub( exp, 15 ) ); /*Q16 */ - exp = norm_s(temp_l_fx); - tmp = div_s(shl(1,sub(14,exp)),temp_l_fx); /*Q(29-exp) */ - L_tmp1 = L_mult(temp_fx,tmp); /*Q(31-exp); +1 due to /2 */ - L_tmp1 = L_shl(L_tmp1,sub(exp,15)); /*Q16 */ + exp = norm_s( temp_l_fx ); + tmp = div_s( shl( 1, sub( 14, exp ) ), temp_l_fx ); /*Q(29-exp) */ + L_tmp1 = L_mult( temp_fx, tmp ); /*Q(31-exp); +1 due to /2 */ + L_tmp1 = L_shl( L_tmp1, sub( exp, 15 ) ); /*Q16 */ - L_tmp = L_add(L_tmp,L_tmp1); /*Q16 */ + L_tmp = L_add( L_tmp, L_tmp1 ); /*Q16 */ - tmp = lshr(extract_l(L_tmp),1); /*Q15 */ - L_tmp = L_mult(temp_l_fx,tmp); /*Q16 */ - temp_fx = rint_new_fx(L_tmp); - Erot_fx = sub(temp_l_fx,temp_fx); /*Q0 */ + tmp = lshr( extract_l( L_tmp ), 1 ); /*Q15 */ + L_tmp = L_mult( temp_l_fx, tmp ); /*Q16 */ + temp_fx = rint_new_fx( L_tmp ); + Erot_fx = sub( temp_l_fx, temp_fx ); /*Q0 */ - Q2phaseShift_fx(PREVDTFS_FX,shl(Erot_fx,2),CURRCW_Q_DTFS_FX->lag_fx,S_fx,C_fx); - IF ( EQ_16(bfi,1)) + Q2phaseShift_fx( PREVDTFS_FX, shl( Erot_fx, 2 ), CURRCW_Q_DTFS_FX->lag_fx, S_fx, C_fx ); + IF( EQ_16( bfi, 1 ) ) { - DTFS_car2pol_fx(CURRCW_Q_DTFS_FX); + DTFS_car2pol_fx( CURRCW_Q_DTFS_FX ); } /*Phase copying is done through copy_phase instead of car2pol and pol2car */ - copy_phase_fx(PREVDTFS_FX,*CURRCW_Q_DTFS_FX,CURRCW_Q_DTFS_FX); + copy_phase_fx( PREVDTFS_FX, *CURRCW_Q_DTFS_FX, CURRCW_Q_DTFS_FX ); { temp_fx = (Word16) get_next_indice( st_fx, 3 ); - temp_fx = sub(temp_fx,3); - temp_fx = shl(temp_fx,2);/*Q2 */ - Q2phaseShift_fx(CURRCW_Q_DTFS_FX,temp_fx,CURRCW_Q_DTFS_FX->lag_fx,S_fx,C_fx); + temp_fx = sub( temp_fx, 3 ); + temp_fx = shl( temp_fx, 2 ); /*Q2 */ + Q2phaseShift_fx( CURRCW_Q_DTFS_FX, temp_fx, CURRCW_Q_DTFS_FX->lag_fx, S_fx, C_fx ); } - count_free(PREVDTFS_FX); + count_free( PREVDTFS_FX ); return error; } - diff --git a/lib_dec/pvq_core_dec_fx.c b/lib_dec/pvq_core_dec_fx.c index 333576db2..65f94c317 100644 --- a/lib_dec/pvq_core_dec_fx.c +++ b/lib_dec/pvq_core_dec_fx.c @@ -3,11 +3,11 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "rom_com.h" /* Static table prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "rom_com.h" /* Static table prototypes */ #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" #endif @@ -16,55 +16,55 @@ * Local prototypes * *-------------------------------------------------------------------*/ -static Word16 get_pvq_splits_fx(Decoder_State* st_fx, PVQ_DEC_HANDLE hPVQ, const Word16 band_bits, const Word16 sfmsize, Word16* bits); -static void densitySymbolIndexDecode_fx(Decoder_State* st_fx, PVQ_DEC_HANDLE hPVQ, const Word16 density, const Word16 opp_sz, const Word16 near_sz, Word16* index_phi); +static Word16 get_pvq_splits_fx( Decoder_State *st_fx, PVQ_DEC_HANDLE hPVQ, const Word16 band_bits, const Word16 sfmsize, Word16 *bits ); +static void densitySymbolIndexDecode_fx( Decoder_State *st_fx, PVQ_DEC_HANDLE hPVQ, const Word16 density, const Word16 opp_sz, const Word16 near_sz, Word16 *index_phi ); /*-------------------------------------------------------------------* * pvq_decode_band() * *-------------------------------------------------------------------*/ static void pvq_decode_band_fx( - Decoder_State *st_fx, /* i/o: Decoder state */ - PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ - Word16* pulse_vector, /* i/o: decoded integer shape vector */ - Word16* npulses, /* i/o: number of pulses */ - Word16* coefs_quant, /* i/o: decoded coefficients buffer */ - const Word16 sfmsize, /* i : band length */ - const Word16 band_bits, /* i : assigned bit budget */ - Word16* bits_left, /* i/o: number of bits / bits remaining */ - const Word16 strict_bits /* i : Conservative rounding flag */ -) + Decoder_State *st_fx, /* i/o: Decoder state */ + PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ + Word16 *pulse_vector, /* i/o: decoded integer shape vector */ + Word16 *npulses, /* i/o: number of pulses */ + Word16 *coefs_quant, /* i/o: decoded coefficients buffer */ + const Word16 sfmsize, /* i : band length */ + const Word16 band_bits, /* i : assigned bit budget */ + Word16 *bits_left, /* i/o: number of bits / bits remaining */ + const Word16 strict_bits /* i : Conservative rounding flag */ +) { Word16 K_val; Word16 j, Np; - Word16 part_start[MAX_SPLITS+1], dim_part[MAX_SPLITS+1], bits_part[MAX_SPLITS+1]; + Word16 part_start[MAX_SPLITS + 1], dim_part[MAX_SPLITS + 1], bits_part[MAX_SPLITS + 1]; Word16 pool_tot, pool_part, dim_parts; Word16 g_part[MAX_SPLITS]; Word16 g_part_neg[MAX_SPLITS]; - Word16 sg_part[MAX_SPLITS+1]; - Word16 idx_sort[MAX_SPLITS+1]; + Word16 sg_part[MAX_SPLITS + 1]; + Word16 idx_sort[MAX_SPLITS + 1]; Word16 js, band_bits_tot, split_bit; - Np = get_pvq_splits_fx(st_fx, hPVQ, band_bits, sfmsize, &split_bit); - band_bits_tot = sub(band_bits, split_bit); + Np = get_pvq_splits_fx( st_fx, hPVQ, band_bits, sfmsize, &split_bit ); + band_bits_tot = sub( band_bits, split_bit ); - dim_parts = extract_h(L_mult(negate(sfmsize),lim_neg_inv_tbl_fx[Np])); - set16_fx(dim_part, dim_parts, sub(Np, 1)); - dim_part[Np-1] = sub(sfmsize, i_mult2(dim_parts, sub(Np, 1))); + dim_parts = extract_h( L_mult( negate( sfmsize ), lim_neg_inv_tbl_fx[Np] ) ); + set16_fx( dim_part, dim_parts, sub( Np, 1 ) ); + dim_part[Np - 1] = sub( sfmsize, i_mult2( dim_parts, sub( Np, 1 ) ) ); move16(); part_start[0] = 0; move16(); - FOR (j = 1; j < Np; j++) + FOR( j = 1; j < Np; j++ ) { - part_start[j] = add(part_start[j-1], dim_part[j-1]); + part_start[j] = add( part_start[j - 1], dim_part[j - 1] ); move16(); } /* Encode energies */ set16_fx( g_part_neg, -32768, Np ); - IF( GT_16(Np, 1)) + IF( GT_16( Np, 1 ) ) { decode_energies_fx( st_fx, hPVQ, Np, dim_part, bits_part, g_part_neg, band_bits_tot, bits_left, sfmsize, strict_bits ); } @@ -79,32 +79,32 @@ static void pvq_decode_band_fx( pool_part = 0; move16(); BASOP_SATURATE_WARNING_OFF_EVS - FOR (j = 0; j < Np; j++) + FOR( j = 0; j < Np; j++ ) { - g_part[j] = negate(g_part_neg[j]); + g_part[j] = negate( g_part_neg[j] ); } BASOP_SATURATE_WARNING_ON_EVS - srt_vec_ind16_fx(g_part, sg_part, idx_sort, Np); - FOR(j = 0; j < Np; j++) + srt_vec_ind16_fx( g_part, sg_part, idx_sort, Np ); + FOR( j = 0; j < Np; j++ ) { - js = idx_sort[Np-1-j]; - pool_part = shrtCDivSignedApprox(pool_tot, sub(Np, j) ); - bits_part[js] = s_max(0, s_min(add(bits_part[js], pool_part), 256)); + js = idx_sort[Np - 1 - j]; + pool_part = shrtCDivSignedApprox( pool_tot, sub( Np, j ) ); + bits_part[js] = s_max( 0, s_min( add( bits_part[js], pool_part ), 256 ) ); move16(); - conservativeL1Norm_fx(dim_part[js],bits_part[js], strict_bits, *bits_left, pool_tot , *npulses, /* inputs */ - &K_val, bits_left, &pool_tot, npulses); /* outputs */ + conservativeL1Norm_fx( dim_part[js], bits_part[js], strict_bits, *bits_left, pool_tot, *npulses, /* inputs */ + &K_val, bits_left, &pool_tot, npulses ); /* outputs */ - IF( K_val > 0 ) + IF( K_val > 0 ) { - pvq_decode_fx(st_fx, hPVQ, coefs_quant + part_start[js], pulse_vector + part_start[js], - K_val, dim_part[js], g_part_neg[js]); + pvq_decode_fx( st_fx, hPVQ, coefs_quant + part_start[js], pulse_vector + part_start[js], + K_val, dim_part[js], g_part_neg[js] ); } ELSE { - set16_fx(coefs_quant + part_start[js], 0, dim_part[js]); - set16_fx(pulse_vector + part_start[js], 0, dim_part[js]); + set16_fx( coefs_quant + part_start[js], 0, dim_part[js] ); + set16_fx( pulse_vector + part_start[js], 0, dim_part[js] ); } } @@ -113,16 +113,16 @@ static void pvq_decode_band_fx( void pvq_decode_frame_fx( Decoder_State *st_fx, - Word16 *coefs_quant, /* o : quantized coefficients */ - Word16 *npulses, /* o : number of pulses per band */ - Word16 *pulse_vector, /* o : non-normalized pulse shapes */ - const Word16 *sfm_start, /* i : indices of first coefficients in the bands */ - const Word16 *sfm_end, /* i : indices of last coefficients in the bands */ - const Word16 *sfmsize, /* i : band sizes */ - const Word16 nb_sfm, /* i : total number of bands */ - const Word16 *R, /* i : bitallocation per band */ - const Word16 pvq_bits, /* i : number of bits avaiable */ - const Word16 core /* i : core */ + Word16 *coefs_quant, /* o : quantized coefficients */ + Word16 *npulses, /* o : number of pulses per band */ + Word16 *pulse_vector, /* o : non-normalized pulse shapes */ + const Word16 *sfm_start, /* i : indices of first coefficients in the bands */ + const Word16 *sfm_end, /* i : indices of last coefficients in the bands */ + const Word16 *sfmsize, /* i : band sizes */ + const Word16 nb_sfm, /* i : total number of bands */ + const Word16 *R, /* i : bitallocation per band */ + const Word16 pvq_bits, /* i : number of bits avaiable */ + const Word16 core /* i : core */ ) { Word16 i, j; @@ -136,31 +136,31 @@ void pvq_decode_frame_fx( PVQ_DEC_DATA pvq_dec; PVQ_DEC_HANDLE hPVQ = &pvq_dec; - rc_dec_init_fx(st_fx, hPVQ, pvq_bits); + rc_dec_init_fx( st_fx, hPVQ, pvq_bits ); - bits = shl(sub(pvq_bits, RC_BITS_RESERVED), 3); + bits = shl( sub( pvq_bits, RC_BITS_RESERVED ), 3 ); bands_to_code = 0; move16(); - FOR (i = 0; i < nb_sfm; i++) + FOR( i = 0; i < nb_sfm; i++ ) { - if (R[i] > 0) + if ( R[i] > 0 ) { - bands_to_code = add(bands_to_code, 1); + bands_to_code = add( bands_to_code, 1 ); } } - IF (core == ACELP_CORE) + IF( core == ACELP_CORE ) { strict_bits = PVQ_CONS; move16(); - srt_vec_ind16_fx (R, R_sort, i_sort, nb_sfm); + srt_vec_ind16_fx( R, R_sort, i_sort, nb_sfm ); } ELSE { strict_bits = PVQ_NEAREST; move16(); - FOR (i = 0; i < nb_sfm; i++) + FOR( i = 0; i < nb_sfm; i++ ) { i_sort[i] = i; move16(); @@ -169,25 +169,25 @@ void pvq_decode_frame_fx( coded_bands = 0; move16(); - FOR (i = 0; i < nb_sfm; i++) + FOR( i = 0; i < nb_sfm; i++ ) { is = i_sort[i]; move16(); - IF(R[is] > 0) + IF( R[is] > 0 ) { - bandBitsAdjustment_fx(hPVQ->rc_num_bits, hPVQ->rc_range, bits, bands_to_code, bands_to_code-coded_bands, sfmsize[is] ,R[is], bit_pool, /* inputs */ - &band_bits, &bits_left, &bit_pool); /* outputs */ + bandBitsAdjustment_fx( hPVQ->rc_num_bits, hPVQ->rc_range, bits, bands_to_code, bands_to_code - coded_bands, sfmsize[is], R[is], bit_pool, /* inputs */ + &band_bits, &bits_left, &bit_pool ); /* outputs */ - pvq_decode_band_fx( st_fx, hPVQ, &pulse_vector[sfm_start[is]], &npulses[is], + pvq_decode_band_fx( st_fx, hPVQ, &pulse_vector[sfm_start[is]], &npulses[is], &coefs_quant[sfm_start[is]], sfmsize[is], band_bits, - &bits_left, strict_bits); + &bits_left, strict_bits ); /* Updates */ - coded_bands = add(coded_bands, 1); + coded_bands = add( coded_bands, 1 ); } ELSE { - FOR (j = sfm_start[is]; j < sfm_end[is]; j++) + FOR( j = sfm_start[is]; j < sfm_end[is]; j++ ) { coefs_quant[j] = 0; move16(); @@ -197,7 +197,7 @@ void pvq_decode_frame_fx( } } - rc_dec_finish_fx(st_fx, hPVQ); + rc_dec_finish_fx( st_fx, hPVQ ); } /*-------------------------------------------------------------------* @@ -291,16 +291,15 @@ Word16 pvq_core_dec_fx( const Word16 *sfm_start, const Word16 *sfm_end, const Word16 *sfmsize, - Word16 coefs_quant[], /* o : output MDCT */ + Word16 coefs_quant[], /* o : output MDCT */ Word16 *Q_coefs, Word16 bits_tot, Word16 nb_sfm, - Word16 *R, /* Q3 */ + Word16 *R, /* Q3 */ Word16 *Rs, Word16 *npulses, Word16 *maxpulse, - const Word16 core -) + const Word16 core ) { Word16 i; Word16 R_upd; @@ -310,25 +309,25 @@ Word16 pvq_core_dec_fx( Word16 gain_bits_array[NB_SFM]; Word16 fg_pred[NB_SFM_MAX]; - IF (st_fx->hHQ_core != NULL) + IF( st_fx->hHQ_core != NULL ) { st_fx->hHQ_core->ber_occured_in_pvq = 0; move16(); } - R_upd = shl(bits_tot, 3); + R_upd = shl( bits_tot, 3 ); assign_gain_bits_fx( core, nb_sfm, sfmsize, R, gain_bits_array, &R_upd ); - pvq_bits = shr(R_upd, 3); + pvq_bits = shr( R_upd, 3 ); - pvq_decode_frame_fx(st_fx, coefs_quant, npulses, pulse_vector, sfm_start, - sfm_end, sfmsize, nb_sfm, R, pvq_bits, core ); + pvq_decode_frame_fx( st_fx, coefs_quant, npulses, pulse_vector, sfm_start, + sfm_end, sfmsize, nb_sfm, R, pvq_bits, core ); IF( Rs != NULL ) { - FOR(i = 0; i < nb_sfm; i++) + FOR( i = 0; i < nb_sfm; i++ ) { - if (npulses[i] <= 0) + if ( npulses[i] <= 0 ) { Rs[i] = 0; move16(); /* Update Rs in case no pulses were assigned */ @@ -336,11 +335,11 @@ Word16 pvq_core_dec_fx( } } - FOR (i=0; i < nb_sfm; i++) + FOR( i = 0; i < nb_sfm; i++ ) { ord[i] = i; move16(); - if (npulses[i] <= 0) + if ( npulses[i] <= 0 ) { R[i] = 0; move16(); /* Update in case no pulses were assigned */ @@ -352,15 +351,15 @@ Word16 pvq_core_dec_fx( fine_gain_pred_fx( sfm_start, sfm_end, sfmsize, ord, npulses, maxpulse, R, nb_sfm, coefs_quant, pulse_vector, fg_pred, core ); - fine_gain_dec_fx( st_fx, ord, nb_sfm, gain_bits_array, fg_pred); - IF(st_fx->hHQ_core != NULL) + fine_gain_dec_fx( st_fx, ord, nb_sfm, gain_bits_array, fg_pred ); + IF( st_fx->hHQ_core != NULL ) { - IF(st_fx->hHQ_core->ber_occured_in_pvq != 0) + IF( st_fx->hHQ_core->ber_occured_in_pvq != 0 ) { - set16_fx(fg_pred, 1, nb_sfm); /* low complex ECU action in case of detetected BER in PVQ decoding */ + set16_fx( fg_pred, 1, nb_sfm ); /* low complex ECU action in case of detetected BER in PVQ decoding */ } } - apply_gain_fx(ord, sfm_start, sfm_end, nb_sfm, fg_pred, coefs_quant); + apply_gain_fx( ord, sfm_start, sfm_end, nb_sfm, fg_pred, coefs_quant ); *Q_coefs = 12; return bits_tot; @@ -372,69 +371,68 @@ Word16 pvq_core_dec_fx( *-------------------------------------------------------------------*/ void decode_energies_fx( Decoder_State *st_fx, - PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ + PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ Word16 Np, Word16 *dim_part, Word16 *bits_part, - Word16 *g_part, /* Q15 */ + Word16 *g_part, /* Q15 */ short qband, Word16 *bits_left, Word16 dim, - const Word16 strict_bits -) + const Word16 strict_bits ) { Word16 density; - Word16 i, l_Np, r_Np; + Word16 i, l_Np, r_Np; Word16 l_bits, r_bits, l_dim, r_dim; Word16 il, ir; Word16 oppRQ3, qzero; Word16 l_gain, r_gain; - Word16 index_phi=-1; + Word16 index_phi = -1; - l_Np = shr(Np, 1); - r_Np = sub(Np, l_Np); + l_Np = shr( Np, 1 ); + r_Np = sub( Np, l_Np ); l_bits = 0; move16(); l_dim = 0; move16(); - FOR (i = 0; i < l_Np; i++) + FOR( i = 0; i < l_Np; i++ ) { - l_dim = add(l_dim, dim_part[i]); + l_dim = add( l_dim, dim_part[i] ); } - r_dim = sub(dim, l_dim); - - obtainEnergyQuantizerDensity_fx(dim, qband, &density); - rangeCoderFinalizationFBits_fx(hPVQ->rc_num_bits, hPVQ->rc_range, &qzero); + r_dim = sub( dim, l_dim ); - densitySymbolIndexDecode_fx( st_fx, hPVQ, density, r_dim, l_dim, &index_phi); - densityAngle2RmsProjDec_fx(density, index_phi, &ir, &il, &oppRQ3); + obtainEnergyQuantizerDensity_fx( dim, qband, &density ); + rangeCoderFinalizationFBits_fx( hPVQ->rc_num_bits, hPVQ->rc_range, &qzero ); + densitySymbolIndexDecode_fx( st_fx, hPVQ, density, r_dim, l_dim, &index_phi ); + densityAngle2RmsProjDec_fx( density, index_phi, &ir, &il, &oppRQ3 ); + l_gain = il; /* Q15 */ + move16(); + r_gain = ir; /* Q15 */ + move16(); - l_gain = il; /* Q15 */ move16(); - r_gain = ir; /* Q15 */ move16(); - - FOR (i = 0; i < l_Np; i++) + FOR( i = 0; i < l_Np; i++ ) { - g_part[i] = mult_r(l_gain, g_part[i]); + g_part[i] = mult_r( l_gain, g_part[i] ); move16(); } - FOR (i = l_Np; i < Np; i++) + FOR( i = l_Np; i < Np; i++ ) { - g_part[i] = mult_r(r_gain, g_part[i]); + g_part[i] = mult_r( r_gain, g_part[i] ); move16(); } - NearOppSplitAdjustment_fx( qband, qzero, hPVQ->rc_num_bits, hPVQ->rc_range, *bits_left, - strict_bits, Np, dim_part[0], dim_part[Np-1], + NearOppSplitAdjustment_fx( qband, qzero, hPVQ->rc_num_bits, hPVQ->rc_range, *bits_left, + strict_bits, Np, dim_part[0], dim_part[Np - 1], l_dim, r_dim, oppRQ3, - &l_bits, &r_bits, bits_left); + &l_bits, &r_bits, bits_left ); - IF (GT_16(l_Np, 1)) + IF( GT_16( l_Np, 1 ) ) { decode_energies_fx( st_fx, hPVQ, l_Np, dim_part, bits_part, g_part, l_bits, bits_left, l_dim, strict_bits ); } @@ -444,7 +442,7 @@ void decode_energies_fx( move16(); } - IF (GT_16(r_Np, 1)) + IF( GT_16( r_Np, 1 ) ) { decode_energies_fx( st_fx, hPVQ, r_Np, &dim_part[l_Np], &bits_part[l_Np], &g_part[l_Np], r_bits, bits_left, r_dim, strict_bits ); } @@ -461,14 +459,13 @@ void decode_energies_fx( * densitySymbolIndexDecode() * *-------------------------------------------------------------------*/ -static void densitySymbolIndexDecode_fx( +static void densitySymbolIndexDecode_fx( Decoder_State *st_fx, - PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ - const Word16 density, - const Word16 opp_sz, - const Word16 near_sz, - Word16 *index_phi -) + PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ + const Word16 density, + const Word16 opp_sz, + const Word16 near_sz, + Word16 *index_phi ) { Word16 density1, density2; Word32 tmp1; @@ -478,130 +475,130 @@ static void densitySymbolIndexDecode_fx( Word16 angle, expo, r; UWord16 lsb; Word32 acc; - Word16 alpha=0; + Word16 alpha = 0; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - IF( s_and((Word16)0xFFFE, density) == 0 ) + IF( s_and( (Word16) 0xFFFE, density ) == 0 ) { /* odd density exit */ *index_phi = -1; return; } - sym_freq = L_deposit_l(1); + sym_freq = L_deposit_l( 1 ); - angle = atan2_fx(SQRT_DIM_fx[opp_sz], SQRT_DIM_fx[near_sz]); + angle = atan2_fx( SQRT_DIM_fx[opp_sz], SQRT_DIM_fx[near_sz] ); #ifdef BASOP_NOGLOB - angle = shl_o(angle, 1, &Overflow); + angle = shl_o( angle, 1, &Overflow ); #else - angle = shl(angle, 1); + angle = shl( angle, 1 ); #endif - angle = mult_r(angle, 20861); - c = mult_r(density, angle); - density_c = sub(density, c); + angle = mult_r( angle, 20861 ); + c = mult_r( density, angle ); + density_c = sub( density, c ); - tot = L_mac0(1L, density, add(density, 1)); - IF (c == 0) + tot = L_mac0( 1L, density, add( density, 1 ) ); + IF( c == 0 ) { - dec_freq = rc_decode_fx(&st_fx->BER_detect, hPVQ, tot); + dec_freq = rc_decode_fx( &st_fx->BER_detect, hPVQ, tot ); - density1 = add(density, 1); - acc = L_mult0(density1, density1); - acc = L_sub(acc, dec_freq); - alpha = add(getSqrtWord32(acc), density1); - sym_freq = L_mac(1L, sub(density, alpha), 1); - cum_freq = L_mac0(L_mult(alpha, density), alpha, 1); + density1 = add( density, 1 ); + acc = L_mult0( density1, density1 ); + acc = L_sub( acc, dec_freq ); + alpha = add( getSqrtWord32( acc ), density1 ); + sym_freq = L_mac( 1L, sub( density, alpha ), 1 ); + cum_freq = L_mac0( L_mult( alpha, density ), alpha, 1 ); } - ELSE IF (EQ_16(c, density)) + ELSE IF( EQ_16( c, density ) ) { - dec_freq = rc_decode_fx(&st_fx->BER_detect, hPVQ, tot); + dec_freq = rc_decode_fx( &st_fx->BER_detect, hPVQ, tot ); - alpha = getSqrtWord32(dec_freq); - sym_freq = L_add(L_shl(alpha, 1), 1); - cum_freq = L_mult0(alpha, alpha); + alpha = getSqrtWord32( dec_freq ); + sym_freq = L_add( L_shl( alpha, 1 ), 1 ); + cum_freq = L_mult0( alpha, alpha ); } ELSE { - acc = L_mult0(density, c); - Mpy_32_16_ss(acc, density_c, &acc, &lsb); - acc = L_or(L_shl(acc, 16), L_and(lsb, 0xffffL)); /* Concatenate acc and lsb forming 48 bits; upshift 16 bits; keep 32 MSB. */ - acc = L_shr(acc, 1); /* Compensate fractional mode multiply (Mpy_32_16_ss) */ - tot = L_add(L_add(acc, (Word32)density), 1L); - - dec_freq = rc_decode_fx(&st_fx->BER_detect, hPVQ, tot); - - acc = L_mult0(sub(density_c, 1), density_c); - Mpy_32_16_ss(acc, c, &acc, &lsb); - acc = L_or(L_shl(acc, 16), L_and(lsb, 0xffffL)); /* Concatenate acc and lsb forming 48 bits; upshift 16 bits; keep 32 MSB. */ - acc = L_shr(acc, 1); /* Compensate fractional mode multiply (Mpy_32_16_ss) */ - acc = L_add(acc, L_add(density, 1)); - acc = L_sub(acc, L_add(c, 1)); - acc = L_sub(tot, acc); - IF (LT_32(dec_freq, acc )) + acc = L_mult0( density, c ); + Mpy_32_16_ss( acc, density_c, &acc, &lsb ); + acc = L_or( L_shl( acc, 16 ), L_and( lsb, 0xffffL ) ); /* Concatenate acc and lsb forming 48 bits; upshift 16 bits; keep 32 MSB. */ + acc = L_shr( acc, 1 ); /* Compensate fractional mode multiply (Mpy_32_16_ss) */ + tot = L_add( L_add( acc, (Word32) density ), 1L ); + + dec_freq = rc_decode_fx( &st_fx->BER_detect, hPVQ, tot ); + + acc = L_mult0( sub( density_c, 1 ), density_c ); + Mpy_32_16_ss( acc, c, &acc, &lsb ); + acc = L_or( L_shl( acc, 16 ), L_and( lsb, 0xffffL ) ); /* Concatenate acc and lsb forming 48 bits; upshift 16 bits; keep 32 MSB. */ + acc = L_shr( acc, 1 ); /* Compensate fractional mode multiply (Mpy_32_16_ss) */ + acc = L_add( acc, L_add( density, 1 ) ); + acc = L_sub( acc, L_add( c, 1 ) ); + acc = L_sub( tot, acc ); + IF( LT_32( dec_freq, acc ) ) { - acc = L_add((Word32)density_c, L_shl(dec_freq, 2)); - acc = L_sub(acc, 2); - Mpy_32_16_ss(acc, density_c, &acc, &lsb); - acc = L_or(L_shl(acc, 16), L_and(lsb, 0xffffL)); /* Concatenate acc and lsb forming 48 bits; upshift 16 bits; keep 32 MSB. */ - acc = L_shr(acc, 1); /* Compensate fractional mode multiply (Mpy_32_16_ss) */ - acc = L_add(acc, 1); - tmp2 = getSqrtWord32(acc); - acc = L_add(density_c, tmp2); - acc = L_sub(acc, 1); - r = ratio(acc, L_shl(density_c,1), &expo); - alpha = shr(r, add(14, expo)); - - acc = L_mult(alpha, density_c); - sym_freq = L_add(acc, 1); - acc = L_mult0(sub(alpha, 1), density_c); - acc = L_add(acc, 1); - cum_freq = L_mult0(alpha, extract_l(acc)); + acc = L_add( (Word32) density_c, L_shl( dec_freq, 2 ) ); + acc = L_sub( acc, 2 ); + Mpy_32_16_ss( acc, density_c, &acc, &lsb ); + acc = L_or( L_shl( acc, 16 ), L_and( lsb, 0xffffL ) ); /* Concatenate acc and lsb forming 48 bits; upshift 16 bits; keep 32 MSB. */ + acc = L_shr( acc, 1 ); /* Compensate fractional mode multiply (Mpy_32_16_ss) */ + acc = L_add( acc, 1 ); + tmp2 = getSqrtWord32( acc ); + acc = L_add( density_c, tmp2 ); + acc = L_sub( acc, 1 ); + r = ratio( acc, L_shl( density_c, 1 ), &expo ); + alpha = shr( r, add( 14, expo ) ); + + acc = L_mult( alpha, density_c ); + sym_freq = L_add( acc, 1 ); + acc = L_mult0( sub( alpha, 1 ), density_c ); + acc = L_add( acc, 1 ); + cum_freq = L_mult0( alpha, extract_l( acc ) ); } ELSE { - density1 = add(density, 1); - density2 = add(shl(density, 1), 1); - - acc = L_mult0(density, density1); - Mpy_32_16_ss(acc, c, &acc, &lsb); - acc = L_or(L_shl(acc, 16), L_and(lsb, 0xffffL)); /* Concatenate acc and lsb forming 48-bit; upshift 16 bits; keep 32 MSB. */ - acc = L_shr(acc, 1); /* Compensate fractional mode multiply (Mpy_32_16_ss) */ - acc = L_add(density1, acc); - acc = L_add(dec_freq, acc); - acc = L_sub(tot, acc); - Mpy_32_16_ss(acc, c, &acc, &lsb); - acc = L_or(L_shl(acc, 16), L_and(lsb, 0xffffL)); - acc = L_shr(acc, 1 - 2); - - tmp2 = extract_l(L_mac0(1L, c, density2)); - tmp1 = L_mult0(tmp2, tmp2); - tmp1 = L_add(tmp1, acc); - tmp2 = getSqrtWord32(tmp1); /* floor */ - if (L_msu0(tmp1, tmp2, tmp2) != 0) + density1 = add( density, 1 ); + density2 = add( shl( density, 1 ), 1 ); + + acc = L_mult0( density, density1 ); + Mpy_32_16_ss( acc, c, &acc, &lsb ); + acc = L_or( L_shl( acc, 16 ), L_and( lsb, 0xffffL ) ); /* Concatenate acc and lsb forming 48-bit; upshift 16 bits; keep 32 MSB. */ + acc = L_shr( acc, 1 ); /* Compensate fractional mode multiply (Mpy_32_16_ss) */ + acc = L_add( density1, acc ); + acc = L_add( dec_freq, acc ); + acc = L_sub( tot, acc ); + Mpy_32_16_ss( acc, c, &acc, &lsb ); + acc = L_or( L_shl( acc, 16 ), L_and( lsb, 0xffffL ) ); + acc = L_shr( acc, 1 - 2 ); + + tmp2 = extract_l( L_mac0( 1L, c, density2 ) ); + tmp1 = L_mult0( tmp2, tmp2 ); + tmp1 = L_add( tmp1, acc ); + tmp2 = getSqrtWord32( tmp1 ); /* floor */ + if ( L_msu0( tmp1, tmp2, tmp2 ) != 0 ) { - tmp2 = add(tmp2, 1); /* convert to ceil */ + tmp2 = add( tmp2, 1 ); /* convert to ceil */ } - acc = L_mult0(c, density2); - acc = L_add(acc, 1); - acc = L_sub(acc, tmp2); - r = ratio(acc, L_shl(c, 1), &expo); - alpha = shr(r, add(14, expo)); - - density_alpha = sub(density, alpha); - sym_freq = L_mac(1L, density_alpha, c); - acc = L_mult0(density_alpha, add(density_alpha, 1)); - Mpy_32_16_ss(acc, c, &acc, &lsb); - acc = L_or(L_shl(acc, 16), L_and(lsb, 0xffffL)); /* Concatenate acc and lsb forming 48-bit; upshift 16 bits; keep 32 MSB. */ - acc = L_shr(acc, 1); /* Compensate fractional mode multiply (Mpy_32_16_ss) */ - acc = L_sub(acc, alpha); - acc = L_add(acc, density1); - cum_freq = L_sub(tot, acc); + acc = L_mult0( c, density2 ); + acc = L_add( acc, 1 ); + acc = L_sub( acc, tmp2 ); + r = ratio( acc, L_shl( c, 1 ), &expo ); + alpha = shr( r, add( 14, expo ) ); + + density_alpha = sub( density, alpha ); + sym_freq = L_mac( 1L, density_alpha, c ); + acc = L_mult0( density_alpha, add( density_alpha, 1 ) ); + Mpy_32_16_ss( acc, c, &acc, &lsb ); + acc = L_or( L_shl( acc, 16 ), L_and( lsb, 0xffffL ) ); /* Concatenate acc and lsb forming 48-bit; upshift 16 bits; keep 32 MSB. */ + acc = L_shr( acc, 1 ); /* Compensate fractional mode multiply (Mpy_32_16_ss) */ + acc = L_sub( acc, alpha ); + acc = L_add( acc, density1 ); + cum_freq = L_sub( tot, acc ); } } - rc_dec_update_fx(st_fx, hPVQ, cum_freq, sym_freq); + rc_dec_update_fx( st_fx, hPVQ, cum_freq, sym_freq ); *index_phi = alpha; return; } @@ -613,59 +610,57 @@ static void densitySymbolIndexDecode_fx( * Retrieve the number of segments *--------------------------------------------------------------------------*/ -static Word16 get_pvq_splits_fx( /* o : Number of segments */ - Decoder_State *st_fx, /* i/o: Decoder state */ - PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ - const Word16 band_bits, /* i : Band bit budget */ - const Word16 sfmsize, /* i : Band width */ - Word16 *bits /* o : Used bits */ +static Word16 get_pvq_splits_fx( /* o : Number of segments */ + Decoder_State *st_fx, /* i/o: Decoder state */ + PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ + const Word16 band_bits, /* i : Band bit budget */ + const Word16 sfmsize, /* i : Band width */ + Word16 *bits /* o : Used bits */ ) { Word16 Np, i; Word32 acc, flag; - IF (band_bits == 0) + IF( band_bits == 0 ) { Np = 1; move16(); } ELSE { - acc = L_mult0(band_bits, 0x7a44); - Np = extract_l(L_shr(acc, 23)); /* Get integer part. */ - if (L_and(acc, 0x7fffffL) != 0) /* If fractional part != 0, add 1. */ + acc = L_mult0( band_bits, 0x7a44 ); + Np = extract_l( L_shr( acc, 23 ) ); /* Get integer part. */ + if ( L_and( acc, 0x7fffffL ) != 0 ) /* If fractional part != 0, add 1. */ { - Np = add(Np, 1); /* ceiling operation */ + Np = add( Np, 1 ); /* ceiling operation */ } } *bits = 0; move16(); - IF (LT_16(Np, MAX_SPLITS)) + IF( LT_16( Np, MAX_SPLITS ) ) { - acc = L_mult0(8*THR_ADD_SPLIT, sfmsize); - IF (GT_32(band_bits, acc)) + acc = L_mult0( 8 * THR_ADD_SPLIT, sfmsize ); + IF( GT_32( band_bits, acc ) ) { - flag = rc_dec_bits_fx(st_fx, hPVQ, 1); + flag = rc_dec_bits_fx( st_fx, hPVQ, 1 ); *bits = 8; move16(); - if (flag != 0) + if ( flag != 0 ) { - Np = add(Np, 1); + Np = add( Np, 1 ); } } } /* Check constraints for number of splits */ /* The following code assumes that PVQ_MAX_BAND_SIZE is 64 */ - i = shr(sfmsize, 6); /* 6 = log2(64) = log2(PVQ_MAX_BAND_SIZE) */ - if (s_and(sfmsize, 0x3f) != 0) + i = shr( sfmsize, 6 ); /* 6 = log2(64) = log2(PVQ_MAX_BAND_SIZE) */ + if ( s_and( sfmsize, 0x3f ) != 0 ) { - i = add(i, 1); /* ceiling operation */ + i = add( i, 1 ); /* ceiling operation */ } - Np = s_max(i, Np); - Np = s_min(MAX_SPLITS, Np); - Np = s_min(sfmsize, Np); /* The code line assumes that MIN_BAND_SIZE is 1 */ + Np = s_max( i, Np ); + Np = s_min( MAX_SPLITS, Np ); + Np = s_min( sfmsize, Np ); /* The code line assumes that MIN_BAND_SIZE is 1 */ return Np; } - - diff --git a/lib_dec/pvq_decode_fx.c b/lib_dec/pvq_decode_fx.c index 520370005..1ae7b0988 100644 --- a/lib_dec/pvq_decode_fx.c +++ b/lib_dec/pvq_decode_fx.c @@ -3,54 +3,54 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ +#include "options.h" /* Compilation switches */ #include "prot_fx1.h" #include "prot_fx2.h" #include "rom_com.h" /*-------------------------------------------------------------------* -* Function pvq_decode_fx() * -* * -* PVQ subvector decoding algorithm * -*-------------------------------------------------------------------*/ + * Function pvq_decode_fx() * + * * + * PVQ subvector decoding algorithm * + *-------------------------------------------------------------------*/ void pvq_decode_fx( Decoder_State *st_fx, - PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ - Word16 *xq, /* o: decoded vector (Q15) */ - Word16 *y, /* o: decoded vector (non-scaled int) */ - const Word16 k_val, /* i: number of allocated pulses */ - const Word16 dim, /* i: Length of vector */ - const Word16 neg_gain /* i: Gain (negated to fit 1.0 in Q15 as -1.0) */ + PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ + Word16 *xq, /* o: decoded vector (Q15) */ + Word16 *y, /* o: decoded vector (non-scaled int) */ + const Word16 k_val, /* i: number of allocated pulses */ + const Word16 dim, /* i: Length of vector */ + const Word16 neg_gain /* i: Gain (negated to fit 1.0 in Q15 as -1.0) */ ) { Word16 i; - UWord32 h_mem[1+KMAX_NON_DIRECT_FX+1]; /* allocate max offset memory for dim 6 */ + UWord32 h_mem[1 + KMAX_NON_DIRECT_FX + 1]; /* allocate max offset memory for dim 6 */ PvqEntry entry; - Word16 neg_gain_norm, shift_num,shift_den,shift_tot; - Word32 L_yy,L_isqrt,L_tmp; + Word16 neg_gain_norm, shift_num, shift_den, shift_tot; + Word32 L_yy, L_isqrt, L_tmp; UWord16 u16_tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - entry = get_size_mpvq_calc_offset_fx(dim, k_val, h_mem); /* get size & prepare H(adaptive table for entry.size=N_MPVQ(dim,k_val) */ + entry = get_size_mpvq_calc_offset_fx( dim, k_val, h_mem ); /* get size & prepare H(adaptive table for entry.size=N_MPVQ(dim,k_val) */ - IF( NE_16(dim, 1)) + IF( NE_16( dim, 1 ) ) { - entry.lead_sign_ind = (short)rc_dec_bits_fx(st_fx, hPVQ, 1); - entry.index = rc_dec_uniform_fx(st_fx, hPVQ, entry.size); + entry.lead_sign_ind = (short) rc_dec_bits_fx( st_fx, hPVQ, 1 ); + entry.index = rc_dec_uniform_fx( st_fx, hPVQ, entry.size ); - IF(st_fx->hHQ_core != NULL) + IF( st_fx->hHQ_core != NULL ) { /* safety check in case of bit errors */ test(); - IF(GE_32(entry.index, entry.size) || st_fx->hHQ_core->ber_occured_in_pvq != 0) + IF( GE_32( entry.index, entry.size ) || st_fx->hHQ_core->ber_occured_in_pvq != 0 ) { st_fx->hHQ_core->ber_occured_in_pvq = 1; move16(); @@ -63,54 +63,52 @@ void pvq_decode_fx( } ELSE { - entry.lead_sign_ind = (short)rc_dec_bits_fx(st_fx, hPVQ, 1); /* always a single sign bit */ - entry.index = L_deposit_l(0); + entry.lead_sign_ind = (short) rc_dec_bits_fx( st_fx, hPVQ, 1 ); /* always a single sign bit */ + entry.index = L_deposit_l( 0 ); } - mpvq_decode_vec_fx(&entry, h_mem, y); + mpvq_decode_vec_fx( &entry, h_mem, y ); - IF( neg_gain == 0 ) + IF( neg_gain == 0 ) { - FOR(i=0; i -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ - +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ /*-------------------------------------------------------------------* * Local prototypes *-------------------------------------------------------------------*/ -static Word16 rc_dec_read_fx(Decoder_State *st_fx, PVQ_DEC_HANDLE hPVQ); +static Word16 rc_dec_read_fx( Decoder_State *st_fx, PVQ_DEC_HANDLE hPVQ ); /*-------------------------------------------------------------------* * rc_dec_init() * @@ -22,25 +21,25 @@ static Word16 rc_dec_read_fx(Decoder_State *st_fx, PVQ_DEC_HANDLE hPVQ); *-------------------------------------------------------------------*/ void rc_dec_init_fx( - Decoder_State *st_fx, /* i/o: Decoder State */ - PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ - Word16 tot_bits /* i : Total bit budget */ + Decoder_State *st_fx, /* i/o: Decoder State */ + PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ + Word16 tot_bits /* i : Total bit budget */ ) { Word16 i; - hPVQ->rc_low = L_deposit_l(0); + hPVQ->rc_low = L_deposit_l( 0 ); hPVQ->rc_range = 0xffffffff; move32(); hPVQ->rc_num_bits = 0; move16(); - hPVQ->rc_offset = add(tot_bits, st_fx->next_bit_pos); + hPVQ->rc_offset = add( tot_bits, st_fx->next_bit_pos ); hPVQ->rc_end = hPVQ->rc_offset; move16(); - FOR (i = 0; i < 4; i++) + FOR( i = 0; i < 4; i++ ) { - hPVQ->rc_low = UL_addNsD(UL_lshl(hPVQ->rc_low, 8), UL_deposit_l(rc_dec_read_fx(st_fx, hPVQ))); + hPVQ->rc_low = UL_addNsD( UL_lshl( hPVQ->rc_low, 8 ), UL_deposit_l( rc_dec_read_fx( st_fx, hPVQ ) ) ); } } @@ -50,41 +49,41 @@ void rc_dec_init_fx( * Decode symbol *-------------------------------------------------------------------*/ -UWord32 rc_decode_fx( /* o : Decoded cumulative frequency */ - Word16* BER_detect, /* o : Bit error detection flag */ - PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ - UWord32 tot /* i : Total cumulative frequency */ +UWord32 rc_decode_fx( /* o : Decoded cumulative frequency */ + Word16 *BER_detect, /* o : Bit error detection flag */ + PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ + UWord32 tot /* i : Total cumulative frequency */ ) { UWord32 inv, lsb, val, UL_tmp1, UL_tmp2; Word16 exp_num, exp_den, exp; UWord16 sgn; - inv = UL_inverse(tot, &exp); - Mpy_32_32_uu(hPVQ->rc_range, inv, &(hPVQ->rc_help), &lsb);/*0+exp-32*/ - hPVQ->rc_help = UL_lshr(hPVQ->rc_help, sub(exp, 32)); + inv = UL_inverse( tot, &exp ); + Mpy_32_32_uu( hPVQ->rc_range, inv, &( hPVQ->rc_help ), &lsb ); /*0+exp-32*/ + hPVQ->rc_help = UL_lshr( hPVQ->rc_help, sub( exp, 32 ) ); - exp_den = norm_ul(hPVQ->rc_help); - UL_tmp2 = UL_lshl(hPVQ->rc_help, exp_den); - exp_num = sub(norm_ul(hPVQ->rc_low), 1); - UL_tmp1 = UL_lshl(hPVQ->rc_low, exp_num); - exp = add(32, sub(exp_num, exp_den)); + exp_den = norm_ul( hPVQ->rc_help ); + UL_tmp2 = UL_lshl( hPVQ->rc_help, exp_den ); + exp_num = sub( norm_ul( hPVQ->rc_low ), 1 ); + UL_tmp1 = UL_lshl( hPVQ->rc_low, exp_num ); + exp = add( 32, sub( exp_num, exp_den ) ); - val = UL_div(UL_tmp1, UL_tmp2); - val = UL_lshr(val, exp); + val = UL_div( UL_tmp1, UL_tmp2 ); + val = UL_lshr( val, exp ); - UL_tmp1 = UL_Mpy_32_32(val, hPVQ->rc_help); - UL_tmp2 = UL_Mpy_32_32(UL_addNsD(val, 1), hPVQ->rc_help); - UL_tmp1 = UL_subNsD(hPVQ->rc_low, UL_tmp1); - UL_tmp2 = UL_subNsD(hPVQ->rc_low, UL_tmp2); - if (UL_tmp2 < UL_tmp1) + UL_tmp1 = UL_Mpy_32_32( val, hPVQ->rc_help ); + UL_tmp2 = UL_Mpy_32_32( UL_addNsD( val, 1 ), hPVQ->rc_help ); + UL_tmp1 = UL_subNsD( hPVQ->rc_low, UL_tmp1 ); + UL_tmp2 = UL_subNsD( hPVQ->rc_low, UL_tmp2 ); + if ( UL_tmp2 < UL_tmp1 ) { - val = UL_addNsD(val, 1); + val = UL_addNsD( val, 1 ); } /* safety check in case of bit errors */ - UL_tmp1 = UL_subNs(tot,val,&sgn); - IF ( sgn != 0) + UL_tmp1 = UL_subNs( tot, val, &sgn ); + IF( sgn != 0 ) { *BER_detect = 1; move16(); @@ -101,21 +100,21 @@ UWord32 rc_decode_fx( /* o : Decoded cumulative frequency */ *-------------------------------------------------------------------*/ void rc_dec_update_fx( - Decoder_State *st_fx, /* i/o: Decoder State */ - PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ - UWord32 cum_freq, /* i : Cumulative frequency */ - UWord32 sym_freq /* i : Symbol frequency */ + Decoder_State *st_fx, /* i/o: Decoder State */ + PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ + UWord32 cum_freq, /* i : Cumulative frequency */ + UWord32 sym_freq /* i : Symbol frequency */ ) { - hPVQ->rc_low = UL_subNsD(hPVQ->rc_low, UL_Mpy_32_32(cum_freq, hPVQ->rc_help)); /*0+0*/ - hPVQ->rc_range = UL_Mpy_32_32(hPVQ->rc_help, sym_freq); + hPVQ->rc_low = UL_subNsD( hPVQ->rc_low, UL_Mpy_32_32( cum_freq, hPVQ->rc_help ) ); /*0+0*/ + hPVQ->rc_range = UL_Mpy_32_32( hPVQ->rc_help, sym_freq ); - WHILE (hPVQ->rc_range < 1<<24) + WHILE( hPVQ->rc_range < 1 << 24 ) { - L_sub(0, 0); /* For comparision in while*/ - hPVQ->rc_num_bits = add(hPVQ->rc_num_bits, 8); - hPVQ->rc_low = UL_addNsD(UL_lshl(hPVQ->rc_low, 8), UL_deposit_l(rc_dec_read_fx(st_fx, hPVQ))); - hPVQ->rc_range = UL_lshl(hPVQ->rc_range, 8); + L_sub( 0, 0 ); /* For comparision in while*/ + hPVQ->rc_num_bits = add( hPVQ->rc_num_bits, 8 ); + hPVQ->rc_low = UL_addNsD( UL_lshl( hPVQ->rc_low, 8 ), UL_deposit_l( rc_dec_read_fx( st_fx, hPVQ ) ) ); + hPVQ->rc_range = UL_lshl( hPVQ->rc_range, 8 ); } } @@ -125,27 +124,27 @@ void rc_dec_update_fx( * Encode bits *-------------------------------------------------------------------*/ -Word32 rc_dec_bits_fx( /* i : Decoded value */ - Decoder_State *st_fx, /* i/o: Decoder State */ - PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ - Word16 bits /* i : Number of bits */ +Word32 rc_dec_bits_fx( /* i : Decoded value */ + Decoder_State *st_fx, /* i/o: Decoder State */ + PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ + Word16 bits /* i : Number of bits */ ) { Word32 value; - hPVQ->rc_num_bits = add(hPVQ->rc_num_bits, bits); + hPVQ->rc_num_bits = add( hPVQ->rc_num_bits, bits ); - IF (GT_16(bits, 16)) + IF( GT_16( bits, 16 ) ) { - hPVQ->rc_offset = sub(hPVQ->rc_offset, sub(bits, 16)); - value = UL_lshl(UL_deposit_l(get_indice(st_fx, hPVQ->rc_offset, sub(bits, 16))), 16); - hPVQ->rc_offset = sub(hPVQ->rc_offset, 16); - value = UL_or(value, UL_deposit_l(get_indice(st_fx, hPVQ->rc_offset, 16))); + hPVQ->rc_offset = sub( hPVQ->rc_offset, sub( bits, 16 ) ); + value = UL_lshl( UL_deposit_l( get_indice( st_fx, hPVQ->rc_offset, sub( bits, 16 ) ) ), 16 ); + hPVQ->rc_offset = sub( hPVQ->rc_offset, 16 ); + value = UL_or( value, UL_deposit_l( get_indice( st_fx, hPVQ->rc_offset, 16 ) ) ); } ELSE { - hPVQ->rc_offset = sub(hPVQ->rc_offset, bits); - value = UL_deposit_l(get_indice(st_fx, hPVQ->rc_offset, bits)); + hPVQ->rc_offset = sub( hPVQ->rc_offset, bits ); + value = UL_deposit_l( get_indice( st_fx, hPVQ->rc_offset, bits ) ); } return value; @@ -157,28 +156,28 @@ Word32 rc_dec_bits_fx( /* i : Decoded value */ * Encode with uniform distribution *-------------------------------------------------------------------*/ -UWord32 rc_dec_uniform_fx( /* i : Decoded value */ - Decoder_State *st_fx, /* i/o: Decoder State */ - PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ - UWord32 tot /* i : Maximum value */ +UWord32 rc_dec_uniform_fx( /* i : Decoded value */ + Decoder_State *st_fx, /* i/o: Decoder State */ + PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ + UWord32 tot /* i : Maximum value */ ) { UWord32 value; Word16 n; - n = sub(32, norm_ul(tot - 1)); + n = sub( 32, norm_ul( tot - 1 ) ); - IF (LE_16(n, 8)) + IF( LE_16( n, 8 ) ) { - value = rc_decode_fx(&st_fx->BER_detect, hPVQ, tot); - rc_dec_update_fx(st_fx, hPVQ, value, 1); + value = rc_decode_fx( &st_fx->BER_detect, hPVQ, tot ); + rc_dec_update_fx( st_fx, hPVQ, value, 1 ); } ELSE { - n = sub(n, 8); - value = rc_decode_fx(&st_fx->BER_detect, hPVQ, UL_addNsD(UL_lshr(tot, n), 1)); - rc_dec_update_fx(st_fx, hPVQ, value, 1); - value = UL_lshl(value, n); - value = UL_or(value, rc_dec_bits_fx(st_fx, hPVQ, n)); + n = sub( n, 8 ); + value = rc_decode_fx( &st_fx->BER_detect, hPVQ, UL_addNsD( UL_lshr( tot, n ), 1 ) ); + rc_dec_update_fx( st_fx, hPVQ, value, 1 ); + value = UL_lshl( value, n ); + value = UL_or( value, rc_dec_bits_fx( st_fx, hPVQ, n ) ); } return value; @@ -191,8 +190,8 @@ UWord32 rc_dec_uniform_fx( /* i : Decoded value */ *-------------------------------------------------------------------*/ void rc_dec_finish_fx( - Decoder_State *st_fx, /* i/o: Decoder state */ - PVQ_DEC_HANDLE hPVQ /* i/o: PVQ decoder handle */ + Decoder_State *st_fx, /* i/o: Decoder state */ + PVQ_DEC_HANDLE hPVQ /* i/o: PVQ decoder handle */ ) { st_fx->next_bit_pos = hPVQ->rc_end; @@ -206,22 +205,21 @@ void rc_dec_finish_fx( static Word16 rc_dec_read_fx( - Decoder_State* st_fx, /* i/o: Decoder state */ - PVQ_DEC_HANDLE hPVQ /* i/o: PVQ decoder handle */ + Decoder_State *st_fx, /* i/o: Decoder state */ + PVQ_DEC_HANDLE hPVQ /* i/o: PVQ decoder handle */ ) { Word16 bits; - bits = sub(hPVQ->rc_end, st_fx->next_bit_pos ); + bits = sub( hPVQ->rc_end, st_fx->next_bit_pos ); /* If the end of the buffer has been reached, pad the last byte with zeros */ - IF(sub(bits, 8) < 0) + IF( sub( bits, 8 ) < 0 ) { - return shl(get_next_indice(st_fx, bits), sub(8, bits)); + return shl( get_next_indice( st_fx, bits ), sub( 8, bits ) ); } ELSE { - return get_next_indice(st_fx, 8); + return get_next_indice( st_fx, 8 ); } } - diff --git a/lib_dec/re8_dec_fx.c b/lib_dec/re8_dec_fx.c index 3fabbede3..e1177d1ec 100644 --- a/lib_dec/re8_dec_fx.c +++ b/lib_dec/re8_dec_fx.c @@ -3,23 +3,23 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ /*-------------------------------------------------------------------------- -* re8_dec_fx() -* -* MULTI-RATE INDEXING OF A POINT y in THE LATTICE RE8 (INDEX DECODING) -* note: the index I is defined as a 32-bit word, but only -* 16 bits are required (long can be replaced by unsigned integer) -*--------------------------------------------------------------------------*/ + * re8_dec_fx() + * + * MULTI-RATE INDEXING OF A POINT y in THE LATTICE RE8 (INDEX DECODING) + * note: the index I is defined as a 32-bit word, but only + * 16 bits are required (long can be replaced by unsigned integer) + *--------------------------------------------------------------------------*/ void re8_dec_fx( - Word16 n, /* i : codebook number (*n is an integer defined in {0,2,3,4,..,n_max}) */ - const UWord16 I, /* i : index of c (pointer to unsigned 16-bit word) */ - const Word16 k[], /* i : index of v (8-dimensional vector of binary indices) = Voronoi index */ - Word16 y[] /* o : point in RE8 (8-dimensional integer vector) */ + Word16 n, /* i : codebook number (*n is an integer defined in {0,2,3,4,..,n_max}) */ + const UWord16 I, /* i : index of c (pointer to unsigned 16-bit word) */ + const Word16 k[], /* i : index of v (8-dimensional vector of binary indices) = Voronoi index */ + Word16 y[] /* o : point in RE8 (8-dimensional integer vector) */ ) { Word16 i, m, v[8]; @@ -29,7 +29,7 @@ void re8_dec_fx( * if n=0,2,3,4, decode I (no Voronoi extension) * if n>4, Voronoi extension is used, decode I and kv[] *------------------------------------------------------------------------*/ - IF( LE_16(n, 4)) + IF( LE_16( n, 4 ) ) { re8_decode_base_index_fx( n, I, y ); } @@ -41,9 +41,9 @@ void re8_dec_fx( m = 0; move16(); - FOR (; n > 4; n -= 2) + FOR( ; n > 4; n -= 2 ) { - m = add(m, 1); + m = add( m, 1 ); } /*--------------------------------------------------------------------* @@ -61,10 +61,10 @@ void re8_dec_fx( /*--------------------------------------------------------------------* * reconstruct y as y = m c + v (with m=2^r, r integer >=1) *--------------------------------------------------------------------*/ - FOR( i=0; i<8; i++ ) + FOR( i = 0; i < 8; i++ ) { /* y[i] = m*y[i] + v[i] */ - y[i] = add(shl(y[i], m), v[i]); + y[i] = add( shl( y[i], m ), v[i] ); move16(); } } diff --git a/lib_dec/rom_dec.c b/lib_dec/rom_dec.c index d5261988d..062f4df35 100644 --- a/lib_dec/rom_dec.c +++ b/lib_dec/rom_dec.c @@ -482,12 +482,11 @@ const Word16 T_256DIV_L_Frame[] = /* Word16 (Q15) Hann window ranging from 0 to 32767/32768 (~0.999969) */ -const Word16 pcmdsp_window_hann_960[960] = -{ - 0, 0, 1, 3, 6, 9, 13, 17, 22, 28, 35, 42, 51, 59, 69, - 79, 90, 101, 114, 127, 140, 155, 170, 185, 202, 219, 237, 255, 274, 294, - 315, 336, 358, 381, 404, 428, 453, 478, 504, 531, 558, 586, 615, 645, 675, - 705, 737, 769, 802, 835, 869, 904, 940, 976, 1013, 1050, 1088, 1127, 1166, 1206, +const Word16 pcmdsp_window_hann_960[960] = { + 0, 0, 1, 3, 6, 9, 13, 17, 22, 28, 35, 42, 51, 59, 69, + 79, 90, 101, 114, 127, 140, 155, 170, 185, 202, 219, 237, 255, 274, 294, + 315, 336, 358, 381, 404, 428, 453, 478, 504, 531, 558, 586, 615, 645, 675, + 705, 737, 769, 802, 835, 869, 904, 940, 976, 1013, 1050, 1088, 1127, 1166, 1206, 1247, 1289, 1331, 1373, 1416, 1460, 1505, 1550, 1596, 1643, 1690, 1737, 1786, 1835, 1884, 1935, 1985, 2037, 2089, 2142, 2195, 2249, 2303, 2359, 2414, 2471, 2528, 2585, 2643, 2702, 2761, 2821, 2882, 2943, 3004, 3066, 3129, 3192, 3256, 3321, 3386, 3451, 3517, 3584, 3651, @@ -495,48 +494,48 @@ const Word16 pcmdsp_window_hann_960[960] = 4799, 4875, 4951, 5028, 5106, 5184, 5263, 5342, 5421, 5501, 5581, 5662, 5743, 5825, 5907, 5990, 6073, 6157, 6241, 6325, 6410, 6495, 6581, 6667, 6754, 6841, 6928, 7016, 7104, 7193, 7282, 7371, 7461, 7551, 7641, 7732, 7823, 7915, 8007, 8099, 8192, 8285, 8378, 8472, 8566, - 8661, 8755, 8850, 8946, 9042, 9138, 9234, 9331, 9427, 9525, 9622, 9720, 9818, 9917,10015, - 10114,10213,10313,10413,10512,10613,10713,10814,10915,11016,11118,11219,11321,11423,11525, - 11628,11731,11834,11937,12040,12144,12247,12351,12455,12559,12664,12768,12873,12978,13083, - 13188,13293,13398,13504,13609,13715,13821,13927,14033,14139,14245,14352,14458,14565,14671, - 14778,14885,14992,15099,15205,15312,15419,15527,15634,15741,15848,15955,16062,16170,16277, - 16384,16491,16598,16706,16813,16920,17027,17134,17241,17349,17456,17563,17669,17776,17883, - 17990,18097,18203,18310,18416,18523,18629,18735,18841,18947,19053,19159,19264,19370,19475, - 19580,19685,19790,19895,20000,20104,20209,20313,20417,20521,20624,20728,20831,20934,21037, - 21140,21243,21345,21447,21549,21650,21752,21853,21954,22055,22155,22256,22355,22455,22555, - 22654,22753,22851,22950,23048,23146,23243,23341,23437,23534,23630,23726,23822,23918,24013, - 24107,24202,24296,24390,24483,24576,24669,24761,24853,24945,25036,25127,25217,25307,25397, - 25486,25575,25664,25752,25840,25927,26014,26101,26187,26273,26358,26443,26527,26611,26695, - 26778,26861,26943,27025,27106,27187,27267,27347,27426,27505,27584,27662,27740,27817,27893, - 27969,28045,28120,28194,28269,28342,28415,28488,28560,28631,28702,28773,28842,28912,28981, - 29049,29117,29184,29251,29317,29382,29447,29512,29576,29639,29702,29764,29825,29886,29947, - 30007,30066,30125,30183,30240,30297,30354,30409,30465,30519,30573,30626,30679,30731,30783, - 30833,30884,30933,30982,31031,31078,31125,31172,31218,31263,31308,31352,31395,31437,31479, - 31521,31562,31602,31641,31680,31718,31755,31792,31828,31864,31899,31933,31966,31999,32031, - 32063,32093,32123,32153,32182,32210,32237,32264,32290,32315,32340,32364,32387,32410,32432, - 32453,32474,32494,32513,32531,32549,32566,32583,32598,32613,32628,32641,32654,32667,32678, - 32689,32699,32709,32717,32726,32733,32740,32746,32751,32755,32759,32762,32765,32767,32767, - 32767,32767,32766,32764,32761,32758,32754,32750,32745,32739,32732,32725,32716,32708,32698, - 32688,32677,32666,32653,32640,32627,32612,32597,32582,32565,32548,32530,32512,32493,32473, - 32452,32431,32409,32386,32363,32339,32314,32289,32263,32236,32209,32181,32152,32122,32092, - 32062,32030,31998,31965,31932,31898,31863,31827,31791,31754,31717,31679,31640,31601,31561, - 31520,31478,31436,31394,31351,31307,31262,31217,31171,31124,31077,31030,30981,30932,30883, - 30832,30782,30730,30678,30625,30572,30518,30464,30408,30353,30296,30239,30182,30124,30065, - 30006,29946,29885,29824,29763,29701,29638,29575,29511,29446,29381,29316,29250,29183,29116, - 29048,28980,28911,28841,28772,28701,28630,28559,28487,28414,28341,28268,28193,28119,28044, - 27968,27892,27816,27739,27661,27583,27504,27425,27346,27266,27186,27105,27024,26942,26860, - 26777,26694,26610,26526,26442,26357,26272,26186,26100,26013,25926,25839,25751,25663,25574, - 25485,25396,25306,25216,25126,25035,24944,24852,24760,24668,24575,24482,24389,24295,24201, - 24106,24012,23917,23821,23725,23629,23533,23436,23340,23242,23145,23047,22949,22850,22752, - 22653,22554,22454,22354,22255,22154,22054,21953,21852,21751,21649,21548,21446,21344,21242, - 21139,21036,20933,20830,20727,20623,20520,20416,20312,20208,20103,19999,19894,19789,19684, - 19579,19474,19369,19263,19158,19052,18946,18840,18734,18628,18522,18415,18309,18202,18096, - 17989,17882,17775,17668,17562,17455,17348,17240,17133,17026,16919,16812,16705,16597,16490, - 16383,16276,16169,16061,15954,15847,15740,15633,15526,15418,15311,15204,15098,14991,14884, - 14777,14670,14564,14457,14351,14244,14138,14032,13926,13820,13714,13608,13503,13397,13292, - 13187,13082,12977,12872,12767,12663,12558,12454,12350,12246,12143,12039,11936,11833,11730, - 11627,11524,11422,11320,11218,11117,11015,10914,10813,10712,10612,10511,10412,10312,10212, - 10113,10014,9916, 9817, 9719, 9621, 9524, 9426, 9330, 9233, 9137, 9041, 8945, 8849, 8754, + 8661, 8755, 8850, 8946, 9042, 9138, 9234, 9331, 9427, 9525, 9622, 9720, 9818, 9917, 10015, + 10114, 10213, 10313, 10413, 10512, 10613, 10713, 10814, 10915, 11016, 11118, 11219, 11321, 11423, 11525, + 11628, 11731, 11834, 11937, 12040, 12144, 12247, 12351, 12455, 12559, 12664, 12768, 12873, 12978, 13083, + 13188, 13293, 13398, 13504, 13609, 13715, 13821, 13927, 14033, 14139, 14245, 14352, 14458, 14565, 14671, + 14778, 14885, 14992, 15099, 15205, 15312, 15419, 15527, 15634, 15741, 15848, 15955, 16062, 16170, 16277, + 16384, 16491, 16598, 16706, 16813, 16920, 17027, 17134, 17241, 17349, 17456, 17563, 17669, 17776, 17883, + 17990, 18097, 18203, 18310, 18416, 18523, 18629, 18735, 18841, 18947, 19053, 19159, 19264, 19370, 19475, + 19580, 19685, 19790, 19895, 20000, 20104, 20209, 20313, 20417, 20521, 20624, 20728, 20831, 20934, 21037, + 21140, 21243, 21345, 21447, 21549, 21650, 21752, 21853, 21954, 22055, 22155, 22256, 22355, 22455, 22555, + 22654, 22753, 22851, 22950, 23048, 23146, 23243, 23341, 23437, 23534, 23630, 23726, 23822, 23918, 24013, + 24107, 24202, 24296, 24390, 24483, 24576, 24669, 24761, 24853, 24945, 25036, 25127, 25217, 25307, 25397, + 25486, 25575, 25664, 25752, 25840, 25927, 26014, 26101, 26187, 26273, 26358, 26443, 26527, 26611, 26695, + 26778, 26861, 26943, 27025, 27106, 27187, 27267, 27347, 27426, 27505, 27584, 27662, 27740, 27817, 27893, + 27969, 28045, 28120, 28194, 28269, 28342, 28415, 28488, 28560, 28631, 28702, 28773, 28842, 28912, 28981, + 29049, 29117, 29184, 29251, 29317, 29382, 29447, 29512, 29576, 29639, 29702, 29764, 29825, 29886, 29947, + 30007, 30066, 30125, 30183, 30240, 30297, 30354, 30409, 30465, 30519, 30573, 30626, 30679, 30731, 30783, + 30833, 30884, 30933, 30982, 31031, 31078, 31125, 31172, 31218, 31263, 31308, 31352, 31395, 31437, 31479, + 31521, 31562, 31602, 31641, 31680, 31718, 31755, 31792, 31828, 31864, 31899, 31933, 31966, 31999, 32031, + 32063, 32093, 32123, 32153, 32182, 32210, 32237, 32264, 32290, 32315, 32340, 32364, 32387, 32410, 32432, + 32453, 32474, 32494, 32513, 32531, 32549, 32566, 32583, 32598, 32613, 32628, 32641, 32654, 32667, 32678, + 32689, 32699, 32709, 32717, 32726, 32733, 32740, 32746, 32751, 32755, 32759, 32762, 32765, 32767, 32767, + 32767, 32767, 32766, 32764, 32761, 32758, 32754, 32750, 32745, 32739, 32732, 32725, 32716, 32708, 32698, + 32688, 32677, 32666, 32653, 32640, 32627, 32612, 32597, 32582, 32565, 32548, 32530, 32512, 32493, 32473, + 32452, 32431, 32409, 32386, 32363, 32339, 32314, 32289, 32263, 32236, 32209, 32181, 32152, 32122, 32092, + 32062, 32030, 31998, 31965, 31932, 31898, 31863, 31827, 31791, 31754, 31717, 31679, 31640, 31601, 31561, + 31520, 31478, 31436, 31394, 31351, 31307, 31262, 31217, 31171, 31124, 31077, 31030, 30981, 30932, 30883, + 30832, 30782, 30730, 30678, 30625, 30572, 30518, 30464, 30408, 30353, 30296, 30239, 30182, 30124, 30065, + 30006, 29946, 29885, 29824, 29763, 29701, 29638, 29575, 29511, 29446, 29381, 29316, 29250, 29183, 29116, + 29048, 28980, 28911, 28841, 28772, 28701, 28630, 28559, 28487, 28414, 28341, 28268, 28193, 28119, 28044, + 27968, 27892, 27816, 27739, 27661, 27583, 27504, 27425, 27346, 27266, 27186, 27105, 27024, 26942, 26860, + 26777, 26694, 26610, 26526, 26442, 26357, 26272, 26186, 26100, 26013, 25926, 25839, 25751, 25663, 25574, + 25485, 25396, 25306, 25216, 25126, 25035, 24944, 24852, 24760, 24668, 24575, 24482, 24389, 24295, 24201, + 24106, 24012, 23917, 23821, 23725, 23629, 23533, 23436, 23340, 23242, 23145, 23047, 22949, 22850, 22752, + 22653, 22554, 22454, 22354, 22255, 22154, 22054, 21953, 21852, 21751, 21649, 21548, 21446, 21344, 21242, + 21139, 21036, 20933, 20830, 20727, 20623, 20520, 20416, 20312, 20208, 20103, 19999, 19894, 19789, 19684, + 19579, 19474, 19369, 19263, 19158, 19052, 18946, 18840, 18734, 18628, 18522, 18415, 18309, 18202, 18096, + 17989, 17882, 17775, 17668, 17562, 17455, 17348, 17240, 17133, 17026, 16919, 16812, 16705, 16597, 16490, + 16383, 16276, 16169, 16061, 15954, 15847, 15740, 15633, 15526, 15418, 15311, 15204, 15098, 14991, 14884, + 14777, 14670, 14564, 14457, 14351, 14244, 14138, 14032, 13926, 13820, 13714, 13608, 13503, 13397, 13292, + 13187, 13082, 12977, 12872, 12767, 12663, 12558, 12454, 12350, 12246, 12143, 12039, 11936, 11833, 11730, + 11627, 11524, 11422, 11320, 11218, 11117, 11015, 10914, 10813, 10712, 10612, 10511, 10412, 10312, 10212, + 10113, 10014, 9916, 9817, 9719, 9621, 9524, 9426, 9330, 9233, 9137, 9041, 8945, 8849, 8754, 8660, 8565, 8471, 8377, 8284, 8191, 8098, 8006, 7914, 7822, 7731, 7640, 7550, 7460, 7370, 7281, 7192, 7103, 7015, 6927, 6840, 6753, 6666, 6580, 6494, 6409, 6324, 6240, 6156, 6072, 5989, 5906, 5824, 5742, 5661, 5580, 5500, 5420, 5341, 5262, 5183, 5105, 5027, 4950, 4874, @@ -544,56 +543,55 @@ const Word16 pcmdsp_window_hann_960[960] = 3718, 3650, 3583, 3516, 3450, 3385, 3320, 3255, 3191, 3128, 3065, 3003, 2942, 2881, 2820, 2760, 2701, 2642, 2584, 2527, 2470, 2413, 2358, 2302, 2248, 2194, 2141, 2088, 2036, 1984, 1934, 1883, 1834, 1785, 1736, 1689, 1642, 1595, 1549, 1504, 1459, 1415, 1372, 1330, 1288, - 1246, 1205, 1165, 1126, 1087, 1049, 1012, 975, 939, 903, 868, 834, 801, 768, 736, - 704, 674, 644, 614, 585, 557, 530, 503, 477, 452, 427, 403, 380, 357, 335, - 314, 293, 273, 254, 236, 218, 201, 184, 169, 154, 139, 126, 113, 100, 89, - 78, 68, 58, 50, 41, 34, 27, 21, 16, 12, 8, 5, 2, 0, 0 + 1246, 1205, 1165, 1126, 1087, 1049, 1012, 975, 939, 903, 868, 834, 801, 768, 736, + 704, 674, 644, 614, 585, 557, 530, 503, 477, 452, 427, 403, 380, 357, 335, + 314, 293, 273, 254, 236, 218, 201, 184, 169, 154, 139, 126, 113, 100, 89, + 78, 68, 58, 50, 41, 34, 27, 21, 16, 12, 8, 5, 2, 0, 0 }; /* Word16 (Q15) Hann window ranging from 0 to 32767/32768 (~0.999969) */ -const Word16 pcmdsp_window_hann_640[640] = -{ - 0, 1, 3, 7, 13, 20, 28, 39, 51, 64, 79, 95, 114, 133, 155, - 177, 202, 228, 255, 284, 315, 347, 381, 416, 453, 491, 531, 572, 615, 660, - 705, 753, 802, 852, 904, 958, 1013, 1069, 1127, 1186, 1247, 1309, 1373, 1438, 1505, +const Word16 pcmdsp_window_hann_640[640] = { + 0, 1, 3, 7, 13, 20, 28, 39, 51, 64, 79, 95, 114, 133, 155, + 177, 202, 228, 255, 284, 315, 347, 381, 416, 453, 491, 531, 572, 615, 660, + 705, 753, 802, 852, 904, 958, 1013, 1069, 1127, 1186, 1247, 1309, 1373, 1438, 1505, 1573, 1643, 1713, 1786, 1859, 1935, 2011, 2089, 2168, 2249, 2331, 2414, 2499, 2585, 2672, 2761, 2851, 2943, 3035, 3129, 3224, 3321, 3418, 3517, 3618, 3719, 3822, 3926, 4031, 4137, 4244, 4353, 4463, 4574, 4686, 4799, 4913, 5028, 5145, 5263, 5381, 5501, 5622, 5743, 5866, 5990, 6115, 6241, 6368, 6495, 6624, 6754, 6884, 7016, 7148, 7282, 7416, 7551, 7687, 7823, 7961, 8099, 8238, 8378, 8519, 8661, 8803, 8946, 9089, 9234, 9379, 9525, 9671, 9818, 9966, - 10114,10263,10413,10563,10713,10864,11016,11168,11321,11474,11628,11782,11937,12092,12247, - 12403,12559,12716,12873,13030,13188,13346,13504,13662,13821,13980,14139,14299,14458,14618, - 14778,14938,15099,15259,15419,15580,15741,15902,16062,16223,16384,16545,16706,16866,17027, - 17188,17349,17509,17669,17830,17990,18150,18310,18469,18629,18788,18947,19106,19264,19422, - 19580,19738,19895,20052,20209,20365,20521,20676,20831,20986,21140,21294,21447,21600,21752, - 21904,22055,22205,22355,22505,22654,22802,22950,23097,23243,23389,23534,23679,23822,23965, - 24107,24249,24390,24530,24669,24807,24945,25081,25217,25352,25486,25620,25752,25884,26014, - 26144,26273,26400,26527,26653,26778,26902,27025,27146,27267,27387,27505,27623,27740,27855, - 27969,28082,28194,28305,28415,28524,28631,28737,28842,28946,29049,29150,29251,29350,29447, - 29544,29639,29733,29825,29917,30007,30096,30183,30269,30354,30437,30519,30600,30679,30757, - 30833,30909,30982,31055,31125,31195,31263,31330,31395,31459,31521,31582,31641,31699,31755, - 31810,31864,31916,31966,32015,32063,32108,32153,32196,32237,32277,32315,32352,32387,32421, - 32453,32484,32513,32540,32566,32591,32613,32635,32654,32673,32689,32704,32717,32729,32740, - 32748,32755,32761,32765,32767,32767,32766,32764,32760,32754,32747,32739,32728,32716,32703, - 32688,32672,32653,32634,32612,32590,32565,32539,32512,32483,32452,32420,32386,32351,32314, - 32276,32236,32195,32152,32107,32062,32014,31965,31915,31863,31809,31754,31698,31640,31581, - 31520,31458,31394,31329,31262,31194,31124,31054,30981,30908,30832,30756,30678,30599,30518, - 30436,30353,30268,30182,30095,30006,29916,29824,29732,29638,29543,29446,29349,29250,29149, - 29048,28945,28841,28736,28630,28523,28414,28304,28193,28081,27968,27854,27739,27622,27504, - 27386,27266,27145,27024,26901,26777,26652,26526,26399,26272,26143,26013,25883,25751,25619, - 25485,25351,25216,25080,24944,24806,24668,24529,24389,24248,24106,23964,23821,23678,23533, - 23388,23242,23096,22949,22801,22653,22504,22354,22204,22054,21903,21751,21599,21446,21293, - 21139,20985,20830,20675,20520,20364,20208,20051,19894,19737,19579,19421,19263,19105,18946, - 18787,18628,18468,18309,18149,17989,17829,17668,17508,17348,17187,17026,16865,16705,16544, - 16383,16222,16061,15901,15740,15579,15418,15258,15098,14937,14777,14617,14457,14298,14138, - 13979,13820,13661,13503,13345,13187,13029,12872,12715,12558,12402,12246,12091,11936,11781, - 11627,11473,11320,11167,11015,10863,10712,10562,10412,10262,10113, 9965, 9817, 9670, 9524, + 10114, 10263, 10413, 10563, 10713, 10864, 11016, 11168, 11321, 11474, 11628, 11782, 11937, 12092, 12247, + 12403, 12559, 12716, 12873, 13030, 13188, 13346, 13504, 13662, 13821, 13980, 14139, 14299, 14458, 14618, + 14778, 14938, 15099, 15259, 15419, 15580, 15741, 15902, 16062, 16223, 16384, 16545, 16706, 16866, 17027, + 17188, 17349, 17509, 17669, 17830, 17990, 18150, 18310, 18469, 18629, 18788, 18947, 19106, 19264, 19422, + 19580, 19738, 19895, 20052, 20209, 20365, 20521, 20676, 20831, 20986, 21140, 21294, 21447, 21600, 21752, + 21904, 22055, 22205, 22355, 22505, 22654, 22802, 22950, 23097, 23243, 23389, 23534, 23679, 23822, 23965, + 24107, 24249, 24390, 24530, 24669, 24807, 24945, 25081, 25217, 25352, 25486, 25620, 25752, 25884, 26014, + 26144, 26273, 26400, 26527, 26653, 26778, 26902, 27025, 27146, 27267, 27387, 27505, 27623, 27740, 27855, + 27969, 28082, 28194, 28305, 28415, 28524, 28631, 28737, 28842, 28946, 29049, 29150, 29251, 29350, 29447, + 29544, 29639, 29733, 29825, 29917, 30007, 30096, 30183, 30269, 30354, 30437, 30519, 30600, 30679, 30757, + 30833, 30909, 30982, 31055, 31125, 31195, 31263, 31330, 31395, 31459, 31521, 31582, 31641, 31699, 31755, + 31810, 31864, 31916, 31966, 32015, 32063, 32108, 32153, 32196, 32237, 32277, 32315, 32352, 32387, 32421, + 32453, 32484, 32513, 32540, 32566, 32591, 32613, 32635, 32654, 32673, 32689, 32704, 32717, 32729, 32740, + 32748, 32755, 32761, 32765, 32767, 32767, 32766, 32764, 32760, 32754, 32747, 32739, 32728, 32716, 32703, + 32688, 32672, 32653, 32634, 32612, 32590, 32565, 32539, 32512, 32483, 32452, 32420, 32386, 32351, 32314, + 32276, 32236, 32195, 32152, 32107, 32062, 32014, 31965, 31915, 31863, 31809, 31754, 31698, 31640, 31581, + 31520, 31458, 31394, 31329, 31262, 31194, 31124, 31054, 30981, 30908, 30832, 30756, 30678, 30599, 30518, + 30436, 30353, 30268, 30182, 30095, 30006, 29916, 29824, 29732, 29638, 29543, 29446, 29349, 29250, 29149, + 29048, 28945, 28841, 28736, 28630, 28523, 28414, 28304, 28193, 28081, 27968, 27854, 27739, 27622, 27504, + 27386, 27266, 27145, 27024, 26901, 26777, 26652, 26526, 26399, 26272, 26143, 26013, 25883, 25751, 25619, + 25485, 25351, 25216, 25080, 24944, 24806, 24668, 24529, 24389, 24248, 24106, 23964, 23821, 23678, 23533, + 23388, 23242, 23096, 22949, 22801, 22653, 22504, 22354, 22204, 22054, 21903, 21751, 21599, 21446, 21293, + 21139, 20985, 20830, 20675, 20520, 20364, 20208, 20051, 19894, 19737, 19579, 19421, 19263, 19105, 18946, + 18787, 18628, 18468, 18309, 18149, 17989, 17829, 17668, 17508, 17348, 17187, 17026, 16865, 16705, 16544, + 16383, 16222, 16061, 15901, 15740, 15579, 15418, 15258, 15098, 14937, 14777, 14617, 14457, 14298, 14138, + 13979, 13820, 13661, 13503, 13345, 13187, 13029, 12872, 12715, 12558, 12402, 12246, 12091, 11936, 11781, + 11627, 11473, 11320, 11167, 11015, 10863, 10712, 10562, 10412, 10262, 10113, 9965, 9817, 9670, 9524, 9378, 9233, 9088, 8945, 8802, 8660, 8518, 8377, 8237, 8098, 7960, 7822, 7686, 7550, 7415, 7281, 7147, 7015, 6883, 6753, 6623, 6494, 6367, 6240, 6114, 5989, 5865, 5742, 5621, 5500, 5380, 5262, 5144, 5027, 4912, 4798, 4685, 4573, 4462, 4352, 4243, 4136, 4030, 3925, 3821, 3718, 3617, 3516, 3417, 3320, 3223, 3128, 3034, 2942, 2850, 2760, 2671, 2584, 2498, 2413, 2330, 2248, 2167, 2088, 2010, 1934, 1858, 1785, 1712, 1642, 1572, 1504, 1437, 1372, 1308, - 1246, 1185, 1126, 1068, 1012, 957, 903, 851, 801, 752, 704, 659, 614, 571, 530, - 490, 452, 415, 380, 346, 314, 283, 254, 227, 201, 176, 154, 132, 113, 94, - 78, 63, 50, 38, 27, 19, 12, 6, 2, 0 + 1246, 1185, 1126, 1068, 1012, 957, 903, 851, 801, 752, 704, 659, 614, 571, 530, + 490, 452, 415, 380, 346, 314, 283, 254, 227, 201, 176, 154, 132, 113, 94, + 78, 63, 50, 38, 27, 19, 12, 6, 2, 0 }; diff --git a/lib_dec/rst_dec_fx.c b/lib_dec/rst_dec_fx.c index 93163f06e..ad750273b 100644 --- a/lib_dec/rst_dec_fx.c +++ b/lib_dec/rst_dec_fx.c @@ -2,12 +2,12 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include "options.h" /* Compilation switches */ +#include "options.h" /* Compilation switches */ #include "stl.h" -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ /*----------------------------------------------------------------------------------* * CNG_reset_dec() @@ -16,9 +16,9 @@ *----------------------------------------------------------------------------------*/ void CNG_reset_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *pitch_buf, /* o : floating pitch for each subframe */ - Word16 *voice_factors /* o : voicing factors */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *pitch_buf, /* o : floating pitch for each subframe */ + Word16 *voice_factors /* o : voicing factors */ ) { Word16 tmp, exp; @@ -26,8 +26,8 @@ void CNG_reset_dec_fx( Copy( UVWB_Ave_fx, st_fx->mem_AR_fx, M ); set16_fx( st_fx->mem_MA_fx, 0, M ); /*set16_fx( st_fx->dispMem_fx, 0, 8 );*/ - set16_fx( st_fx->dm_fx.prev_gain_pit , 0, 6 ); - st_fx->dm_fx.prev_gain_code = L_deposit_l(0); + set16_fx( st_fx->dm_fx.prev_gain_pit, 0, 6 ); + st_fx->dm_fx.prev_gain_code = L_deposit_l( 0 ); st_fx->dm_fx.prev_state = 0; move16(); @@ -51,30 +51,30 @@ void CNG_reset_dec_fx( st_fx->lp_gainc_fx = 0; move16(); - IF (st_fx->lp_ener_fx != 0) + IF( st_fx->lp_ener_fx != 0 ) { - exp = norm_l(st_fx->lp_ener_fx); /* In Q6 */ - tmp = extract_h(L_shl(st_fx->lp_ener_fx, exp)); - exp = sub(exp, 30-6); + exp = norm_l( st_fx->lp_ener_fx ); /* In Q6 */ + tmp = extract_h( L_shl( st_fx->lp_ener_fx, exp ) ); + exp = sub( exp, 30 - 6 ); - tmp = div_s(16384, tmp); - L_tmp = L_deposit_h(tmp); - L_tmp = Isqrt_lc(L_tmp, &exp); + tmp = div_s( 16384, tmp ); + L_tmp = L_deposit_h( tmp ); + L_tmp = Isqrt_lc( L_tmp, &exp ); #ifdef BASOP_NOGLOB st_fx->lp_gainc_fx = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 12 ) ) ); /* In Q3 */ #else - st_fx->lp_gainc_fx = round_fx(L_shl(L_tmp, sub(exp, 12))); /* In Q3 */ + st_fx->lp_gainc_fx = round_fx( L_shl( L_tmp, sub( exp, 12 ) ) ); /* In Q3 */ #endif } /* reset the pitch buffer in case of FRAME_NO_DATA or SID frames */ - IF( EQ_16(st_fx->L_frame,L_FRAME)) + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { - set16_fx( pitch_buf, L_SUBFR<<6, NB_SUBFR ); + set16_fx( pitch_buf, L_SUBFR << 6, NB_SUBFR ); } - ELSE /* st->L_frame == L_FRAME16k */ + ELSE /* st->L_frame == L_FRAME16k */ { - set16_fx( pitch_buf, L_SUBFR16k<<6, NB_SUBFR16k ); + set16_fx( pitch_buf, L_SUBFR16k << 6, NB_SUBFR16k ); } set16_fx( voice_factors, 32767, NB_SUBFR16k ); @@ -83,7 +83,7 @@ void CNG_reset_dec_fx( st_fx->bpf_off = 1; move16(); /* Reset active frame counter */ - if (st_fx->hTdCngDec != NULL) + if ( st_fx->hTdCngDec != NULL ) { st_fx->hTdCngDec->act_cnt2 = 0; } diff --git a/lib_dec/stat_dec.h b/lib_dec/stat_dec.h index eb4aeca2f..301014d92 100644 --- a/lib_dec/stat_dec.h +++ b/lib_dec/stat_dec.h @@ -58,19 +58,20 @@ typedef enum FRAMEMODE_NORMAL = 0x0, /* frame available */ FRAMEMODE_MISSING = 0x1, /* frame missing => conceal */ FRAMEMODE_FUTURE = 0x2 -} FRAME_MODE,frameMode_fx; +} FRAME_MODE, + frameMode_fx; typedef enum { - TONALMDCTCONCEAL_OK = 0, + TONALMDCTCONCEAL_OK = 0, - __error_codes_start = -100, + __error_codes_start = -100, - TONALMDCTCONCEAL_NSAMPLES_LARGER_THAN_MAXBLOCKSIZE, - TONALMDCTCONCEAL_INVALIDPOINTER, - TONALMDCTCONCEAL_UNEXPECTED_ERROR, + TONALMDCTCONCEAL_NSAMPLES_LARGER_THAN_MAXBLOCKSIZE, + TONALMDCTCONCEAL_INVALIDPOINTER, + TONALMDCTCONCEAL_UNEXPECTED_ERROR, - __error_codes_end + __error_codes_end } TONALMDCTCONCEAL_ERROR; @@ -82,169 +83,169 @@ typedef struct { HANDLE_FD_CNG_COM hFdCngCom; - Word16 olapBufferAna[FFTLEN]; - Word16 olapBufferSynth2[FFTLEN]; + Word16 olapBufferAna[FFTLEN]; + Word16 olapBufferSynth2[FFTLEN]; #ifndef IVAS_FLOAT_FIXED float msPeriodog_float[NPART_SHAPING]; /* Periodogram */ -#endif - Word32 msPeriodog[NPART_SHAPING]; /* Periodogram */ - - Word16 msPeriodog_exp; /* Common exponent for fft and cldfb energies */ - Word16 msPeriodog_exp_fft; - Word16 msPeriodog_exp_cldfb; -#ifndef IVAS_FLOAT_FIXED - float msBminWin_float[NPART_SHAPING]; -#endif - Word32 msBminWin[NPART_SHAPING]; -#ifndef IVAS_FLOAT_FIXED - float msBminSubWin_float[NPART_SHAPING]; -#endif - Word32 msBminSubWin[NPART_SHAPING]; -#ifndef IVAS_FLOAT_FIXED - float msPsd_float[NPART_SHAPING]; /* Power Spectral Density estimate (i.e., smoothed periodogram) */ -#endif - Word16 msPsd[NPART_SHAPING]; /* Power Spectral Density estimate (i.e., smoothed periodogram) */ - Word32 msPsd_fx[NPART_SHAPING]; /* Power Spectral Density estimate (i.e., smoothed periodogram) */ - - Word16 msPsd_exp_fft; -#ifndef IVAS_FLOAT_FIXED - float msAlpha_float[NPART_SHAPING]; /* Optimal smoothing parameter */ -#endif - Word32 msAlpha[NPART_SHAPING]; /* Optimal smoothing parameter */ -#ifndef IVAS_FLOAT_FIXED - float msMinBuf_float[MSNUMSUBFR * NPART_SHAPING]; /* Buffer of minima */ -#endif - Word32 msMinBuf[MSNUMSUBFR*NPART_SHAPING]; /* Buffer of minima */ - -#ifndef IVAS_FLOAT_FIXED - float msCurrentMinOut_float[NPART_SHAPING]; -#endif - Word32 msCurrentMinOut[NPART_SHAPING]; -#ifndef IVAS_FLOAT_FIXED - float msCurrentMin_float[NPART_SHAPING]; -#endif - Word32 msCurrentMin[NPART_SHAPING]; -#ifndef IVAS_FLOAT_FIXED - float msCurrentMinSubWindow_float[NPART_SHAPING]; -#endif - Word32 msCurrentMinSubWindow[NPART_SHAPING]; +#endif + Word32 msPeriodog[NPART_SHAPING]; /* Periodogram */ + + Word16 msPeriodog_exp; /* Common exponent for fft and cldfb energies */ + Word16 msPeriodog_exp_fft; + Word16 msPeriodog_exp_cldfb; +#ifndef IVAS_FLOAT_FIXED + float msBminWin_float[NPART_SHAPING]; +#endif + Word32 msBminWin[NPART_SHAPING]; +#ifndef IVAS_FLOAT_FIXED + float msBminSubWin_float[NPART_SHAPING]; +#endif + Word32 msBminSubWin[NPART_SHAPING]; +#ifndef IVAS_FLOAT_FIXED + float msPsd_float[NPART_SHAPING]; /* Power Spectral Density estimate (i.e., smoothed periodogram) */ +#endif + Word16 msPsd[NPART_SHAPING]; /* Power Spectral Density estimate (i.e., smoothed periodogram) */ + Word32 msPsd_fx[NPART_SHAPING]; /* Power Spectral Density estimate (i.e., smoothed periodogram) */ + + Word16 msPsd_exp_fft; +#ifndef IVAS_FLOAT_FIXED + float msAlpha_float[NPART_SHAPING]; /* Optimal smoothing parameter */ +#endif + Word32 msAlpha[NPART_SHAPING]; /* Optimal smoothing parameter */ +#ifndef IVAS_FLOAT_FIXED + float msMinBuf_float[MSNUMSUBFR * NPART_SHAPING]; /* Buffer of minima */ +#endif + Word32 msMinBuf[MSNUMSUBFR * NPART_SHAPING]; /* Buffer of minima */ + +#ifndef IVAS_FLOAT_FIXED + float msCurrentMinOut_float[NPART_SHAPING]; +#endif + Word32 msCurrentMinOut[NPART_SHAPING]; +#ifndef IVAS_FLOAT_FIXED + float msCurrentMin_float[NPART_SHAPING]; +#endif + Word32 msCurrentMin[NPART_SHAPING]; +#ifndef IVAS_FLOAT_FIXED + float msCurrentMinSubWindow_float[NPART_SHAPING]; +#endif + Word32 msCurrentMinSubWindow[NPART_SHAPING]; int16_t msLocalMinFlag[NPART_SHAPING]; int16_t msNewMinFlag[NPART_SHAPING]; -#ifndef IVAS_FLOAT_FIXED +#ifndef IVAS_FLOAT_FIXED float msPsdFirstMoment_float[NPART_SHAPING]; -#endif - Word16 msPsdFirstMoment[NPART_SHAPING]; -#ifndef IVAS_FLOAT_FIXED - float msPsdSecondMoment_float[NPART_SHAPING]; -#endif - Word32 msPsdSecondMoment[NPART_SHAPING]; - -#ifndef IVAS_FLOAT_FIXED - float msNoiseFloor_float[NPART_SHAPING]; /* Estimated noise floor */ -#endif - Word16 msNoiseFloor[NPART_SHAPING]; /* Estimated noise floor */ -#ifndef IVAS_FLOAT_FIXED - float msNoiseEst_float[NPART_SHAPING]; /* Estimated noise level */ -#endif - Word32 msNoiseEst[NPART_SHAPING]; /* Estimated noise level */ - Word16 msNoiseEst_exp; -#ifndef IVAS_FLOAT_FIXED - float msLogPeriodog_float[NPART_SHAPING]; /* Periodogram */ -#endif - Word16 msLogPeriodog[NPART_SHAPING]; -#ifndef IVAS_FLOAT_FIXED - float msLogNoiseEst_float[NPART_SHAPING]; /* Estimated noise level */ -#endif - Word16 msLogNoiseEst[NPART_SHAPING]; - - int16_t npart_shaping; /* Number of partitions */ +#endif + Word16 msPsdFirstMoment[NPART_SHAPING]; +#ifndef IVAS_FLOAT_FIXED + float msPsdSecondMoment_float[NPART_SHAPING]; +#endif + Word32 msPsdSecondMoment[NPART_SHAPING]; + +#ifndef IVAS_FLOAT_FIXED + float msNoiseFloor_float[NPART_SHAPING]; /* Estimated noise floor */ +#endif + Word16 msNoiseFloor[NPART_SHAPING]; /* Estimated noise floor */ +#ifndef IVAS_FLOAT_FIXED + float msNoiseEst_float[NPART_SHAPING]; /* Estimated noise level */ +#endif + Word32 msNoiseEst[NPART_SHAPING]; /* Estimated noise level */ + Word16 msNoiseEst_exp; +#ifndef IVAS_FLOAT_FIXED + float msLogPeriodog_float[NPART_SHAPING]; /* Periodogram */ +#endif + Word16 msLogPeriodog[NPART_SHAPING]; +#ifndef IVAS_FLOAT_FIXED + float msLogNoiseEst_float[NPART_SHAPING]; /* Estimated noise level */ +#endif + Word16 msLogNoiseEst[NPART_SHAPING]; + + int16_t npart_shaping; /* Number of partitions */ int16_t nFFTpart_shaping; /* Number of hybrid spectral partitions */ int16_t part_shaping[NPART_SHAPING]; /* Partition upper boundaries (band indices starting from 0) */ int16_t midband_shaping[NPART_SHAPING]; /* Central band of each partition */ - - Word16 psize_shaping[NPART_SHAPING]; /* Partition sizes */ - - Word16 psize_shaping_norm[NPART_SHAPING]; /* Partition sizes, fractional variable */ - Word16 psize_shaping_norm_exp; /* Partition sizes exponent for fractional variable */ - - Word16 psize_inv_shaping[NPART_SHAPING]; /* Inverse of partition sizes */ - - -#ifndef IVAS_FLOAT_FIXED - float psize_shaping_float[NPART_SHAPING]; /* Partition sizes */ - float psize_inv_shaping_float[NPART_SHAPING]; /* Inverse of partition sizes */ - float bandNoiseShape_float[FFTLEN2]; /* CNG spectral shape computed at the decoder */ -#endif - - Word32 bandNoiseShape[FFTLEN2]; /* CNG spectral shape computed at the decoder */ - - Word16 bandNoiseShape_exp; /* exponent of bandNoiseShape */ -#ifndef IVAS_FLOAT_FIXED - float partNoiseShape_float[NPART]; /* CNG spectral shape computed at the decoder */ -#endif - Word32 partNoiseShape[NPART]; /* CNG spectral shape computed at the decoder */ - - Word16 partNoiseShape_exp; /* exponent of partNoiseShape */ - -#ifndef IVAS_FLOAT_FIXED - float smoothed_psd[L_FRAME16k]; /* stereo CNA - periodogram smoothed with IIR filter */ - float msPeriodog_ST[NPART_SHAPING]; /* stereo CNA - short-term periodogram */ -#endif - Word32 msPeriodog_ST_fx[NPART_SHAPING]; /* stereo CNA - short-term periodogram */ - Word16 msPeriodog_ST_exp; /* exponent of stereo CNA - short-term periodogram */ + + Word16 psize_shaping[NPART_SHAPING]; /* Partition sizes */ + + Word16 psize_shaping_norm[NPART_SHAPING]; /* Partition sizes, fractional variable */ + Word16 psize_shaping_norm_exp; /* Partition sizes exponent for fractional variable */ + + Word16 psize_inv_shaping[NPART_SHAPING]; /* Inverse of partition sizes */ + + +#ifndef IVAS_FLOAT_FIXED + float psize_shaping_float[NPART_SHAPING]; /* Partition sizes */ + float psize_inv_shaping_float[NPART_SHAPING]; /* Inverse of partition sizes */ + float bandNoiseShape_float[FFTLEN2]; /* CNG spectral shape computed at the decoder */ +#endif + + Word32 bandNoiseShape[FFTLEN2]; /* CNG spectral shape computed at the decoder */ + + Word16 bandNoiseShape_exp; /* exponent of bandNoiseShape */ +#ifndef IVAS_FLOAT_FIXED + float partNoiseShape_float[NPART]; /* CNG spectral shape computed at the decoder */ +#endif + Word32 partNoiseShape[NPART]; /* CNG spectral shape computed at the decoder */ + + Word16 partNoiseShape_exp; /* exponent of partNoiseShape */ + +#ifndef IVAS_FLOAT_FIXED + float smoothed_psd[L_FRAME16k]; /* stereo CNA - periodogram smoothed with IIR filter */ + float msPeriodog_ST[NPART_SHAPING]; /* stereo CNA - short-term periodogram */ +#endif + Word32 msPeriodog_ST_fx[NPART_SHAPING]; /* stereo CNA - short-term periodogram */ + Word16 msPeriodog_ST_exp; /* exponent of stereo CNA - short-term periodogram */ int16_t ms_last_inactive_bwidth; /* stereo CNA - bandwidth from the last inactive frame */ int16_t ms_cnt_bw_up; /* stereo CNA - downward counter of frames since the last NB->WB switch */ #ifndef IVAS_FLOAT_FIXED - float cna_LR_LT; /* stereo CNA - long-term L/R correlation factor calculated on stereo upmix */ -#endif - Word16 cna_LR_LT_fx; /* stereo CNA - long-term L/R correlation factor calculated on stereo upmix */ + float cna_LR_LT; /* stereo CNA - long-term L/R correlation factor calculated on stereo upmix */ +#endif + Word16 cna_LR_LT_fx; /* stereo CNA - long-term L/R correlation factor calculated on stereo upmix */ #ifndef IVAS_FLOAT_FIXED - float cna_ILD_LT; /* stereo CNA - long-term ILD factor calculated on stereo upmix */ -#endif - Word16 cna_ILD_LT_fx; /* stereo CNA - long-term ILD factor calculated on stereo upmix */ + float cna_ILD_LT; /* stereo CNA - long-term ILD factor calculated on stereo upmix */ +#endif + Word16 cna_ILD_LT_fx; /* stereo CNA - long-term ILD factor calculated on stereo upmix */ #ifndef IVAS_FLOAT_FIXED float cna_g_state[STEREO_DFT_BAND_MAX]; /* stereo CNA - side gains from the last inactive frame */ float cna_cm[STEREO_DFT_BAND_MAX]; /* stereo CNA - coherence from the last inactive frame */ -#endif - int16_t first_cna_noise_updated; /* stereo CNA - flag indicating that comfort noise has been properly initialized during warmup */ - int16_t first_cna_noise_update_cnt; /* stereo CNA - counter of CN initialization frames */ - int16_t cna_nbands; /* stereo CNA - number of frequency bands used by the CNA in DFT stereo mode */ +#endif + int16_t first_cna_noise_updated; /* stereo CNA - flag indicating that comfort noise has been properly initialized during warmup */ + int16_t first_cna_noise_update_cnt; /* stereo CNA - counter of CN initialization frames */ + int16_t cna_nbands; /* stereo CNA - number of frequency bands used by the CNA in DFT stereo mode */ int16_t cna_band_limits[STEREO_DFT_BAND_MAX + 1]; /* stereo CNA - band limits used by the CNA in DFT stereo mode */ #ifndef IVAS_FLOAT_FIXED - float cna_act_fact; /* stereo CNA - long-term signal activity factor (0-1) */ + float cna_act_fact; /* stereo CNA - long-term signal activity factor (0-1) */ #endif #ifndef IVAS_FLOAT_FIXED - float cna_rescale_fact; /* stereo CNA - CN energy re-scaling factor to maintain decoded energy */ -#endif - int16_t cna_seed; /* stereo CNA - seed for random CN generator */ + float cna_rescale_fact; /* stereo CNA - CN energy re-scaling factor to maintain decoded energy */ +#endif + int16_t cna_seed; /* stereo CNA - seed for random CN generator */ int16_t flag_dtx_mode; #ifndef IVAS_FLOAT_FIXED - float lp_speech_float; -#endif - Word32 lp_speech; /* format: Q9.23 */ + float lp_speech_float; +#endif + Word32 lp_speech; /* format: Q9.23 */ Word16 q_lp_speech; - + #ifndef IVAS_FLOAT_FIXED - float lp_noise_float; -#endif - Word32 lp_noise; /* format: Q9.23 */ + float lp_noise_float; +#endif + Word32 lp_noise; /* format: Q9.23 */ Word16 q_lp_noise; #ifndef IVAS_FLOAT_FIXED float msPeriodogBuf_float[MSBUFLEN * NPART_SHAPING]; -#endif - Word16 msPeriodogBuf[MSBUFLEN*NPART_SHAPING]; - - int16_t msPeriodogBufPtr; +#endif + Word16 msPeriodogBuf[MSBUFLEN * NPART_SHAPING]; - Word32 smoothed_psd_fx[L_FRAME16k]; /* stereo CNA - periodogram smoothed with IIR filter */ + int16_t msPeriodogBufPtr; + + Word32 smoothed_psd_fx[L_FRAME16k]; /* stereo CNA - periodogram smoothed with IIR filter */ #ifdef IVAS_FLOAT_FIXED Word16 cna_g_state_fx[STEREO_DFT_BAND_MAX]; /* stereo CNA - side gains from the last inactive frame */ Word16 cna_cm_fx[STEREO_DFT_BAND_MAX]; /* stereo CNA - coherence from the last inactive frame */ - Word16 cna_act_fact_fx; /* stereo CNA - long-term signal activity factor (0-1) */ + Word16 cna_act_fact_fx; /* stereo CNA - long-term signal activity factor (0-1) */ Word16 cna_rescale_fact_fx; Word16 q_smoothed_psd; #endif @@ -258,64 +259,64 @@ typedef struct typedef struct { int16_t L_frameTCX; - Word16 FrameSize; + Word16 FrameSize; int16_t Pitch; - Word16 Pitch_fx; - - int16_t T_bfi; - Word8 T_bfi_fx; + Word16 Pitch_fx; + + int16_t T_bfi; + Word8 T_bfi_fx; int16_t Transient[MAX_POST_LEN]; int16_t TCX_Tonality[DEC_STATE_LEN]; #ifndef IVAS_FLOAT_FIXED float outx_new_n1; #endif - Word16 outx_new_n1_fx; + Word16 outx_new_n1_fx; #ifndef IVAS_FLOAT_FIXED float nsapp_gain; #endif - Word16 nsapp_gain_fx; + Word16 nsapp_gain_fx; #ifndef IVAS_FLOAT_FIXED - float nsapp_gain_n; + float nsapp_gain_n; #endif - Word16 nsapp_gain_n_fx; + Word16 nsapp_gain_n_fx; #ifndef IVAS_FLOAT_FIXED - float data_reci2[L_FRAME_MAX]; + float data_reci2[L_FRAME_MAX]; #endif - Word32 data_reci2_fx[L_FRAME_MAX]; + Word32 data_reci2_fx[L_FRAME_MAX]; - Word16 data_reci2_scale; + Word16 data_reci2_scale; #ifndef IVAS_FLOAT_FIXED float data_noise_float[L_FRAME_MAX]; #endif - Word16 data_noise[L_FRAME_MAX]; + Word16 data_noise[L_FRAME_MAX]; #ifndef IVAS_FLOAT_FIXED float ener_mean; #endif - Word32 ener_mean_fx; + Word32 ener_mean_fx; #ifndef IVAS_FLOAT_FIXED - float ener; + float ener; #endif - Word32 ener_fx; - - int16_t zp; - Word16 zp_fx; + Word32 ener_fx; + + int16_t zp; + Word16 zp_fx; #ifndef IVAS_FLOAT_FIXED float recovery_gain_float; #endif - Word16 recovery_gain; /*outside waveformadjustment: Q14 - insinde waveformadjustment: Q15*/ + Word16 recovery_gain; /*outside waveformadjustment: Q14 - insinde waveformadjustment: Q15*/ #ifndef IVAS_FLOAT_FIXED - float step_concealgain; + float step_concealgain; #endif - Word16 step_concealgain_fx; + Word16 step_concealgain_fx; int16_t concealment_method; - - int16_t subframe; - Word16 subframe_fx; - - int16_t nbLostCmpt; + + int16_t subframe; + Word16 subframe_fx; + + int16_t nbLostCmpt; int16_t seed; @@ -330,21 +331,21 @@ typedef struct { uint16_t nSamples; uint16_t nSamplesCore; - - Float32 *spectralData_float; - Word16 * spectralData; - - Word16 spectralData_exp; + + Float32 *spectralData_float; + Word16 *spectralData; + + Word16 spectralData_exp; #ifndef IVAS_FLOAT_FIXED - float *scaleFactors_float; + float *scaleFactors_float; #endif - Word16 * scaleFactors; + Word16 *scaleFactors; - Word16 * scaleFactors_exp; - Word16 scaleFactors_max_e; - Word16 gain_tcx_exp; + Word16 *scaleFactors_exp; + Word16 scaleFactors_max_e; + Word16 gain_tcx_exp; - int16_t blockIsValid; + int16_t blockIsValid; int16_t blockIsConcealed; int16_t tonalConcealmentActive; } blockData; @@ -355,29 +356,29 @@ typedef struct uint16_t indexOfTonalPeak[MAX_NUMBER_OF_IDX]; uint16_t lowerIndex[MAX_NUMBER_OF_IDX]; uint16_t upperIndex[MAX_NUMBER_OF_IDX]; - + Word16 phaseDiff[MAX_NUMBER_OF_IDX]; // Q12 /* This one can be stored with 16 bits in range 0..2*PI */ - Word16 phase_currentFramePredicted[MAX_NUMBER_OF_IDX*GROUP_LENGTH]; // Q13 /* This one can be stored with 16 bits in range [-pi;pi] 2Q13, but the code has to be adapted to use moduo(2*PI) after adding */ + Word16 phase_currentFramePredicted[MAX_NUMBER_OF_IDX * GROUP_LENGTH]; // Q13 /* This one can be stored with 16 bits in range [-pi;pi] 2Q13, but the code has to be adapted to use moduo(2*PI) after adding */ #ifndef IVAS_FLOAT_FIXED - Float32 phaseDiff_float[MAX_NUMBER_OF_IDX]; /* This one can be stored with 16 bits in range 0..2*PI */ - - Float32 phase_currentFramePredicted_float[MAX_NUMBER_OF_IDX * GROUP_LENGTH]; /* This one can be stored with 16 bits in range 0..2*PI, but the code has to be adapted to use moduo(2*PI) after adding */ + Float32 phaseDiff_float[MAX_NUMBER_OF_IDX]; /* This one can be stored with 16 bits in range 0..2*PI */ + + Float32 phase_currentFramePredicted_float[MAX_NUMBER_OF_IDX * GROUP_LENGTH]; /* This one can be stored with 16 bits in range 0..2*PI, but the code has to be adapted to use moduo(2*PI) after adding */ #endif } TonalComponentsInfo; -//typedef struct +// typedef struct //{ -// Word16 numIndexes; -// Word16 indexOfTonalPeak[MAX_NUMBER_OF_IDX]; -// Word16 lowerIndex[MAX_NUMBER_OF_IDX]; -// Word16 upperIndex[MAX_NUMBER_OF_IDX]; +// Word16 numIndexes; +// Word16 indexOfTonalPeak[MAX_NUMBER_OF_IDX]; +// Word16 lowerIndex[MAX_NUMBER_OF_IDX]; +// Word16 upperIndex[MAX_NUMBER_OF_IDX]; // -// Word16 phaseDiff[MAX_NUMBER_OF_IDX]; // Q12 /* This one can be stored with 16 bits in range 0..2*PI */ +// Word16 phaseDiff[MAX_NUMBER_OF_IDX]; // Q12 /* This one can be stored with 16 bits in range 0..2*PI */ // -// Word16 phase_currentFramePredicted[MAX_NUMBER_OF_IDX*GROUP_LENGTH]; // Q13 /* This one can be stored with 16 bits in range [-pi;pi] 2Q13, but the code has to be adapted to use moduo(2*PI) after adding */ +// Word16 phase_currentFramePredicted[MAX_NUMBER_OF_IDX*GROUP_LENGTH]; // Q13 /* This one can be stored with 16 bits in range [-pi;pi] 2Q13, but the code has to be adapted to use moduo(2*PI) after adding */ // -//} TonalComponentsInfo_fix; +// } TonalComponentsInfo_fix; typedef struct tonalmdctconceal { @@ -391,38 +392,38 @@ typedef struct tonalmdctconceal #ifndef IVAS_FLOAT_FIXED float lastPitchLag_float; #endif // #ifndef IVAS_FLOAT_FIXED - Word32 lastPitchLag; + Word32 lastPitchLag; blockData lastBlockData; blockData secondLastBlockData; - Word16 scaleFactorsBuffers[2][FDNS_NPTS]; /* Contains also global gain. */ - - Word16 scaleFactorsBuffers_exp[2][FDNS_NPTS]; - - Word16 spectralDataBuffers[2][L_FRAME_MAX]; /* 16 bits is enough, because it is stored before applying scale factors. Take care that power spectrum is also stored here. */ - - Word16 timeDataBuffer[(3 * L_FRAME_MAX) / 2]; /* 16 bits are enough for the TD signal */ + Word16 scaleFactorsBuffers[2][FDNS_NPTS]; /* Contains also global gain. */ + + Word16 scaleFactorsBuffers_exp[2][FDNS_NPTS]; + + Word16 spectralDataBuffers[2][L_FRAME_MAX]; /* 16 bits is enough, because it is stored before applying scale factors. Take care that power spectrum is also stored here. */ + + Word16 timeDataBuffer[( 3 * L_FRAME_MAX ) / 2]; /* 16 bits are enough for the TD signal */ #ifndef IVAS_FLOAT_FIXED Float32 scaleFactorsBuffers_float[2][FDNS_NPTS]; /* Contains also global gain. If it can not be stored in 16 bits with global gain included, then store global gain separately. */ - Float32 spectralDataBuffers_float[2][L_FRAME_MAX]; /* 16 bits is enough, because it is stored before applying scale factors. Take care that power spectrum is also stored here. */ - Float32 timeDataBuffer_float[( 3 * L_FRAME_MAX ) / 2]; - Float32 *lastPcmOut_float; - Float32 *secondLastPcmOut_float; + Float32 spectralDataBuffers_float[2][L_FRAME_MAX]; /* 16 bits is enough, because it is stored before applying scale factors. Take care that power spectrum is also stored here. */ + Float32 timeDataBuffer_float[( 3 * L_FRAME_MAX ) / 2]; + Float32 *lastPcmOut_float; + Float32 *secondLastPcmOut_float; #endif - Word16 * lastPcmOut; - - Word16 * secondLastPcmOut; - - Word16 * secondLastPowerSpectrum; + Word16 *lastPcmOut; + + Word16 *secondLastPcmOut; - Word16 secondLastPowerSpectrum_exp; + Word16 *secondLastPowerSpectrum; - //Word16 scaleFactorsBackground[FDNS_NPTS]; + Word16 secondLastPowerSpectrum_exp; + + // Word16 scaleFactorsBackground[FDNS_NPTS]; Word32 scaleFactorsBackground_fx[FDNS_NPTS]; #ifndef IVAS_FLOAT_FIXED - float *secondLastPowerSpectrum_float; + float *secondLastPowerSpectrum_float; float scaleFactorsBackground_flt[FDNS_NPTS]; float scf_fadeout_flt; #endif @@ -448,7 +449,7 @@ typedef struct tonalmdctconceal #ifndef IVAS_FLOAT_FIXED float nFramesLost_float; #endif - Word16 nFramesLost; + Word16 nFramesLost; #if 0 //Memory ovelap issue #endif @@ -459,7 +460,6 @@ typedef struct tonalmdctconceal } TonalMDCTConceal_INSTANCE, *TonalMDCTConcealPtr; - /*---------------------------------------------------------------* * Structures for IGF decoder * *---------------------------------------------------------------*/ @@ -490,19 +490,19 @@ typedef struct igfdec_private_data_struct IGF_INFO igfInfo; /* envelope reconstruction: */ #ifndef IVAS_FLOAT_FIXED - float igf_sN_float[IGF_MAX_SFB]; /* only with short blocks as static needed */ + float igf_sN_float[IGF_MAX_SFB]; /* only with short blocks as static needed */ #endif - Word32 igf_sN[IGF_MAX_SFB]; /* Q31 | only with short blocks as static needed */ - - Word16 igf_sN_e[IGF_MAX_SFB]; /* | exponent for igf_sN */ + Word32 igf_sN[IGF_MAX_SFB]; /* Q31 | only with short blocks as static needed */ + + Word16 igf_sN_e[IGF_MAX_SFB]; /* | exponent for igf_sN */ #ifndef IVAS_FLOAT_FIXED - float igf_pN_float[IGF_MAX_SFB]; /* only with short blocks as static needed */ + float igf_pN_float[IGF_MAX_SFB]; /* only with short blocks as static needed */ #endif - Word32 igf_pN[IGF_MAX_SFB]; /* Q31 | only with short blocks as static needed */ - - Word16 igf_pN_e[IGF_MAX_SFB]; - - int16_t igf_curr[IGF_MAX_SFB]; /* current igf energies */ + Word32 igf_pN[IGF_MAX_SFB]; /* Q31 | only with short blocks as static needed */ + + Word16 igf_pN_e[IGF_MAX_SFB]; + + int16_t igf_curr[IGF_MAX_SFB]; /* current igf energies */ int16_t igf_prev[IGF_MAX_SFB]; /* needed for concealment or indepflag==0 */ int16_t igf_curr_subframe[IGF_MAX_SUBFRAMES][IGF_TRANS_FAK][IGF_MAX_SFB]; /* current igf energies per subframe*/ int16_t igf_prev_subframe[IGF_MAX_SUBFRAMES][IGF_MAX_SFB]; /* needed for concealment or indepflag==0 */ @@ -514,8 +514,8 @@ typedef struct igfdec_private_data_struct float pSpecFlatBuf[IGF_START_MX]; #endif Word32 *pSpecFlat; - Word32 pSpecFlatBuf_fx[IGF_START_MX]; /* Q31 | MDCT spectrum before LPC shaping */ - Word16 pSpecFlat_exp; + Word32 pSpecFlatBuf_fx[IGF_START_MX]; /* Q31 | MDCT spectrum before LPC shaping */ + Word16 pSpecFlat_exp; int16_t restrict_hopsize; @@ -526,17 +526,17 @@ typedef struct igfdec_private_data_struct #ifndef IVAS_FLOAT_FIXED float totalNoiseNrg_float; #endif - Word32 totalNoiseNrg; + Word32 totalNoiseNrg; Word16 totalNoiseNrg_exp; - - int16_t n_noise_bands; - - Word16 headroom_TCX_noise_white; - Word16 headroom_TCX_noise; + + int16_t n_noise_bands; + + Word16 headroom_TCX_noise_white; + Word16 headroom_TCX_noise; #ifndef IVAS_FLOAT_FIXED float totalNoiseNrg_off_float; #endif - Word32 totalNoiseNrg_off; + Word32 totalNoiseNrg_off; Word16 totalNoiseNrg_off_exp; int16_t n_noise_bands_off; @@ -567,8 +567,8 @@ typedef struct igfdec_instance_struct float virtualSpecBuf[N_MAX_TCX - IGF_START_MN]; #endif Word32 *virtualSpec_fx; - Word32 virtualSpec[N_MAX_TCX - IGF_START_MN]; /* Q31 | buffer for temp flattening */ - Word16 virtualSpec_e; /* | exponent of virtualSpec */ + Word32 virtualSpec[N_MAX_TCX - IGF_START_MN]; /* Q31 | buffer for temp flattening */ + Word16 virtualSpec_e; /* | exponent of virtualSpec */ int16_t flatteningTrigger; IGFDEC_PRIVATE_DATA igfData; @@ -587,7 +587,7 @@ typedef struct tec_dec_structure float loBuffer_flt[CLDFB_NO_COL_MAX + MAX_TEC_SMOOTHING_DEG]; #endif - //fixed variable + // fixed variable Word16 pGainTemp_m[CLDFB_NO_COL_MAX]; Word16 pGainTemp_e[CLDFB_NO_COL_MAX]; Word16 loBuffer[CLDFB_NO_COL_MAX + MAX_TEC_SMOOTHING_DEG]; @@ -608,25 +608,25 @@ typedef struct tcx_ltp_dec_structure #ifndef IVAS_FLOAT_FIXED float tcxltp_gain_float; #endif - Word16 tcxltp_gain; + Word16 tcxltp_gain; - int16_t tcxltp_pitch_int; + int16_t tcxltp_pitch_int; int16_t tcxltp_pitch_fr; #ifndef IVAS_FLOAT_FIXED float tcxltp_mem_in_float[TCXLTP_MAX_DELAY]; #endif - Word16 tcxltp_mem_in[TCXLTP_MAX_DELAY]; - Word32 tcxltp_mem_in_32[TCXLTP_MAX_DELAY]; + Word16 tcxltp_mem_in[TCXLTP_MAX_DELAY]; + Word32 tcxltp_mem_in_32[TCXLTP_MAX_DELAY]; #ifdef IVAS_FLOAT_FIXED - Word16 exp_tcxltp_mem_in; + Word16 exp_tcxltp_mem_in; #endif #ifndef IVAS_FLOAT_FIXED - float tcxltp_mem_out_float[L_FRAME48k]; + float tcxltp_mem_out_float[L_FRAME48k]; #endif - Word16 tcxltp_mem_out[L_FRAME48k]; - Word32 tcxltp_mem_out_32[L_FRAME48k]; + Word16 tcxltp_mem_out[L_FRAME48k]; + Word32 tcxltp_mem_out_32[L_FRAME48k]; #ifdef IVAS_FLOAT_FIXED - Word16 exp_tcxltp_mem_out; + Word16 exp_tcxltp_mem_out; #endif @@ -636,9 +636,9 @@ typedef struct tcx_ltp_dec_structure #ifndef IVAS_FLOAT_FIXED float tcxltp_gain_post_prev_float; #endif // #ifndef IVAS_FLOAT_FIXED - Word16 tcxltp_gain_post_prev; - - int16_t tcxltp_filt_idx_prev; + Word16 tcxltp_gain_post_prev; + + int16_t tcxltp_filt_idx_prev; } TCX_LTP_DEC_DATA, *TCX_LTP_DEC_HANDLE; @@ -655,15 +655,15 @@ typedef struct tcx_dec_structure /* tonal PLC */ #ifndef IVAS_FLOAT_FIXED float tcxltp_second_last_pitch_float; - float tcxltp_third_last_pitch_float; + float tcxltp_third_last_pitch_float; #endif // #ifndef IVAS_FLOAT_FIXED - Word32 tcxltp_second_last_pitch; - - Word32 tcxltp_third_last_pitch; + Word32 tcxltp_second_last_pitch; + + Word32 tcxltp_third_last_pitch; #ifndef IVAS_FLOAT_FIXED - float tcxltp_last_gain_unmodified_float; + float tcxltp_last_gain_unmodified_float; #endif - Word16 tcxltp_last_gain_unmodified; + Word16 tcxltp_last_gain_unmodified; int16_t tcx_hm_LtpPitchLag; int16_t tcx_lpc_shaped_ari; @@ -675,58 +675,58 @@ typedef struct tcx_dec_structure #ifndef IVAS_FLOAT_FIXED float old_excFB[L_FRAME48k]; /* old excitation FB */ #endif - Word16 old_excFB_fx[L_FRAME48k]; /* old excitation FB */ + Word16 old_excFB_fx[L_FRAME48k]; /* old excitation FB */ int16_t old_synth_len; int16_t old_synth_lenFB; #ifndef IVAS_FLOAT_FIXED - float old_synth_float[OLD_SYNTH_INTERNAL_DEC]; /* synthesis memory */ + float old_synth_float[OLD_SYNTH_INTERNAL_DEC]; /* synthesis memory */ #endif - Word16 old_synth[OLD_SYNTH_INTERNAL_DEC]; /* synthesis memory */ + Word16 old_synth[OLD_SYNTH_INTERNAL_DEC]; /* synthesis memory */ #ifndef IVAS_FLOAT_FIXED - float synth_history[L_PROT48k + L_FRAME_MAX]; /* unified synthesis memory */ + float synth_history[L_PROT48k + L_FRAME_MAX]; /* unified synthesis memory */ #endif - Word16 synth_history_fx[L_PROT48k + L_FRAME_MAX]; /*TCX unified synthesis memory */ - Word16 q_synth_history_fx; + Word16 synth_history_fx[L_PROT48k + L_FRAME_MAX]; /*TCX unified synthesis memory */ + Word16 q_synth_history_fx; #ifndef IVAS_FLOAT_FIXED float *old_synthFB; #endif - Word16* old_synthFB_fx; + Word16 *old_synthFB_fx; #ifndef IVAS_FLOAT_FIXED float *prev_good_synth; #endif - Word16* prev_good_synth_fx; + Word16 *prev_good_synth_fx; #ifndef IVAS_FLOAT_FIXED float old_syn_Overl_float[L_FRAME32k / 2]; #endif - Word16 old_syn_Overl[L_FRAME32k / 2]; - Word32 old_syn_Overl_32[L_FRAME32k / 2]; + Word16 old_syn_Overl[L_FRAME32k / 2]; + Word32 old_syn_Overl_32[L_FRAME32k / 2]; Word16 Q_old_syn_Overl; #ifndef IVAS_FLOAT_FIXED float syn_Overl_TDAC_float[L_FRAME32k / 2]; #endif - Word16 syn_Overl_TDAC[L_FRAME32k / 2]; + Word16 syn_Overl_TDAC[L_FRAME32k / 2]; Word16 Q_syn_Overl_TDAC; #ifndef IVAS_FLOAT_FIXED - float syn_Overl_TDACFB_float[L_FRAME_MAX / 2]; + float syn_Overl_TDACFB_float[L_FRAME_MAX / 2]; #endif - Word16 syn_Overl_TDACFB[L_FRAME_MAX / 2]; + Word16 syn_Overl_TDACFB[L_FRAME_MAX / 2]; Word16 Q_syn_Overl_TDACFB; #ifndef IVAS_FLOAT_FIXED float syn_Overl_float[L_FRAME32k / 2]; #endif - Word16 syn_Overl[L_FRAME32k / 2]; + Word16 syn_Overl[L_FRAME32k / 2]; Word16 Q_syn_Overl; #ifndef IVAS_FLOAT_FIXED - float syn_OverlFB_float[L_FRAME_MAX / 2]; + float syn_OverlFB_float[L_FRAME_MAX / 2]; #endif - Word16 syn_OverlFB[L_FRAME_MAX / 2]; + Word16 syn_OverlFB[L_FRAME_MAX / 2]; Word16 Q_syn_OverlFB; #ifndef IVAS_FLOAT_FIXED float FBTCXdelayBuf_float[111]; /* 2.3125ms at 48kHz -> 111 samples */ #endif - Word16 FBTCXdelayBuf[111]; /* 2.3125ms at 48kHz -> 111 samples */ - Word32 FBTCXdelayBuf_32[111]; /* 2.3125ms at 48kHz -> 111 samples */ + Word16 FBTCXdelayBuf[111]; /* 2.3125ms at 48kHz -> 111 samples */ + Word32 FBTCXdelayBuf_32[111]; /* 2.3125ms at 48kHz -> 111 samples */ /*TCX resisual Q*/ @@ -739,64 +739,64 @@ typedef struct tcx_dec_structure float ltpGainMemory[N_LTP_GAIN_MEMS]; /* for smoothing noiseTransWidth */ #endif Word16 ltpGainMemory_fx[N_LTP_GAIN_MEMS]; /* Q15 */ - uint16_t kernel_type[2]; /* transform kernel type in each subframe (MDCT or MDST) */ + uint16_t kernel_type[2]; /* transform kernel type in each subframe (MDCT or MDST) */ int16_t prev_widow_left_rect; - //Word32 CngLevelBackgroundTrace_bfi_fx; /* PLC - long term gain estimate for background level, used for PLC fade out */ - //Word16 CngLevelBackgroundTrace_bfi_exp; + // Word32 CngLevelBackgroundTrace_bfi_fx; /* PLC - long term gain estimate for background level, used for PLC fade out */ + // Word16 CngLevelBackgroundTrace_bfi_exp; /* state variables for the minimum statistics used for PLC */ #ifndef IVAS_FLOAT_FIXED float CngLevelBackgroundTrace_bfi; /* PLC - long term gain estimate for background level, used for PLC fade out */ float NoiseLevelMemory_bfi[PLC_MIN_STAT_BUFF_SIZE]; #endif #ifdef IVAS_FLOAT_FIXED - //Word16 NoiseLevelMemory_bfi_fx[PLC_MIN_STAT_BUFF_SIZE]; + // Word16 NoiseLevelMemory_bfi_fx[PLC_MIN_STAT_BUFF_SIZE]; #endif // IVAS_FLOAT_FIXED int16_t NoiseLevelIndex_bfi; int16_t CurrLevelIndex_bfi; - - Word16 conCngLevelBackgroundTrace; /* Q15 long term gain estimate for background level, used for PLC fade out */ - Word16 conCngLevelBackgroundTrace_e; + + Word16 conCngLevelBackgroundTrace; /* Q15 long term gain estimate for background level, used for PLC fade out */ + Word16 conCngLevelBackgroundTrace_e; #ifndef IVAS_FLOAT_FIXED - float LastFrameLevel_bfi; + float LastFrameLevel_bfi; #endif #ifdef IVAS_FLOAT_FIXED Word16 LastFrameLevel_bfi_fx; #endif // IVAS_FLOAT_FIXED - - Word16 conNoiseLevelMemory[PLC_MIN_STAT_BUFF_SIZE], conNoiseLevelMemory_e[PLC_MIN_STAT_BUFF_SIZE];/*Q15*/ - Word16 conNoiseLevelIndex; /*Q0*/ - Word16 conCurrLevelIndex; /*Q0*/ - Word16 conLastFrameLevel, conLastFrameLevel_e;/*Q15*/ -#ifndef IVAS_FLOAT_FIXED - float old_gaintcx_bfi_float; - float conceal_eof_gain_float; -#endif - Word16 old_gaintcx_bfi, old_gaintcx_bfi_e; - - Word16 conceal_eof_gain; /*Q14*/ + + Word16 conNoiseLevelMemory[PLC_MIN_STAT_BUFF_SIZE], conNoiseLevelMemory_e[PLC_MIN_STAT_BUFF_SIZE]; /*Q15*/ + Word16 conNoiseLevelIndex; /*Q0*/ + Word16 conCurrLevelIndex; /*Q0*/ + Word16 conLastFrameLevel, conLastFrameLevel_e; /*Q15*/ +#ifndef IVAS_FLOAT_FIXED + float old_gaintcx_bfi_float; + float conceal_eof_gain_float; +#endif + Word16 old_gaintcx_bfi, old_gaintcx_bfi_e; + + Word16 conceal_eof_gain; /*Q14*/ #ifdef IVAS_FLOAT_FIXED - //Word32 conceal_eof_gain32; /*have been created for further calculation */ + // Word32 conceal_eof_gain32; /*have been created for further calculation */ #endif #ifndef IVAS_FLOAT_FIXED - float damping_float; + float damping_float; #endif - Word16 damping; /* 1Q14 */ - + Word16 damping; /* 1Q14 */ + #ifndef IVAS_FLOAT_FIXED - float gainHelper_float; + float gainHelper_float; #endif - Word16 gainHelper, gainHelper_e; /*can be >1*/ + Word16 gainHelper, gainHelper_e; /*can be >1*/ #ifndef IVAS_FLOAT_FIXED - float stepCompensate_float; + float stepCompensate_float; #endif - Word16 stepCompensate, stepCompensate_e; - - int16_t tcxConceal_recalc_exc; + Word16 stepCompensate, stepCompensate_e; + + int16_t tcxConceal_recalc_exc; #ifndef IVAS_FLOAT_FIXED - float cummulative_damping_tcx_float; + float cummulative_damping_tcx_float; #endif - Word16 cummulative_damping_tcx; + Word16 cummulative_damping_tcx; } TCX_DEC_DATA, *TCX_DEC_HANDLE; @@ -808,50 +808,50 @@ typedef struct tcx_dec_structure typedef struct gsc_dec_structure { - int16_t seed_tcx; /* AC mode (GSC) - seed for noise fill */ - //Word16 seed_tcx; /* AC mode (GSC) - seed for noise fill Q0*/ - - int16_t cor_strong_limit; /* AC mode (GSC) - Indicator about high spectral correlation per band */ - //Word16 cor_strong_limit; /* AC mode (GSC) - Indicator about high spectral correlation per band */ - + int16_t seed_tcx; /* AC mode (GSC) - seed for noise fill */ + // Word16 seed_tcx; /* AC mode (GSC) - seed for noise fill Q0*/ + + int16_t cor_strong_limit; /* AC mode (GSC) - Indicator about high spectral correlation per band */ + // Word16 cor_strong_limit; /* AC mode (GSC) - Indicator about high spectral correlation per band */ + #ifndef IVAS_FLOAT_FIXED - float old_y_gain[MBANDS_GN16k]; /* AC mode (GSC) - AR mem for low rate gain quantization */ + float old_y_gain[MBANDS_GN16k]; /* AC mode (GSC) - AR mem for low rate gain quantization */ #endif - Word16 old_y_gain_fx[MBANDS_GN16k]; /* AC mode (GSC) - AR mem for low rate gain quantization */ - - int16_t noise_lev; /* AC mode (GSC) - noise level */ - //Word16 noise_lev; /* AC mode (GSC) - noise level Q0*/ - + Word16 old_y_gain_fx[MBANDS_GN16k]; /* AC mode (GSC) - AR mem for low rate gain quantization */ + + int16_t noise_lev; /* AC mode (GSC) - noise level */ + // Word16 noise_lev; /* AC mode (GSC) - noise level Q0*/ + #ifndef IVAS_FLOAT_FIXED - float lt_ener_per_band[MBANDS_GN16k]; + float lt_ener_per_band[MBANDS_GN16k]; #endif - Word16 lt_ener_per_band_fx[MBANDS_GN16k]; /* Q12 */ - + Word16 lt_ener_per_band_fx[MBANDS_GN16k]; /* Q12 */ + #ifndef IVAS_FLOAT_FIXED - float Last_frame_ener; /* AC mode (GSC) - last frame energy */ + float Last_frame_ener; /* AC mode (GSC) - last frame energy */ #endif - Word32 Last_frame_ener_fx; /* AC mode (GSC) - last frame energy */ - + Word32 Last_frame_ener_fx; /* AC mode (GSC) - last frame energy */ + #ifndef IVAS_FLOAT_FIXED - float Last_GSC_spectrum[L_FRAME16k]; /* AC mode (GSC) - Last good GSC spectrum */ + float Last_GSC_spectrum[L_FRAME16k]; /* AC mode (GSC) - Last good GSC spectrum */ #endif - Word16 Last_GSC_spectrum_fx[L_FRAME16k]; /* AC mode (GSC) - Last good GSC spectrum */ - - int16_t Last_GSC_pit_band_idx; /* AC mode (GSC) - Last pitch band index */ - //Word16 Last_GSC_pit_band_idx; /* AC mode (GSC) - Last pitch band index Q0*/ - + Word16 Last_GSC_spectrum_fx[L_FRAME16k]; /* AC mode (GSC) - Last good GSC spectrum */ + + int16_t Last_GSC_pit_band_idx; /* AC mode (GSC) - Last pitch band index */ + // Word16 Last_GSC_pit_band_idx; /* AC mode (GSC) - Last pitch band index Q0*/ + #ifndef IVAS_FLOAT_FIXED - float last_exc_dct_in[L_FRAME16k]; /* AC mode (GSC) - previous excitation */ + float last_exc_dct_in[L_FRAME16k]; /* AC mode (GSC) - previous excitation */ #endif - Word16 last_exc_dct_in_fx[L_FRAME16k]; /* AC mode (GSC) - previous excitation */ - + Word16 last_exc_dct_in_fx[L_FRAME16k]; /* AC mode (GSC) - previous excitation */ + #ifndef IVAS_FLOAT_FIXED - float last_ener; /* AC mode (GSC) - previous energy */ + float last_ener; /* AC mode (GSC) - previous energy */ #endif - Word16 last_ener_fx; /* AC mode (GSC) - previous energy */ - - int16_t last_bitallocation_band[6]; /* AC mode (GSC) - previous bit allocation of each band */ - //Word16 last_bitallocation_band[6]; /* AC mode (GSC) - previous bit allocation of each band */ + Word16 last_ener_fx; /* AC mode (GSC) - previous energy */ + + int16_t last_bitallocation_band[6]; /* AC mode (GSC) - previous bit allocation of each band */ + // Word16 last_bitallocation_band[6]; /* AC mode (GSC) - previous bit allocation of each band */ } GSC_DEC_DATA, *GSC_DEC_HANDLE; @@ -866,20 +866,17 @@ typedef struct WI_dec_structure #ifndef IVAS_FLOAT_FIXED float old_exc2[L_EXC_MEM]; /* FEC - old excitation2 used in fast recovery */ #endif - Word16 old_exc2_fx[L_EXC_MEM]; /* FEC - old excitation2 used in fast recovery */ - + Word16 old_exc2_fx[L_EXC_MEM]; /* FEC - old excitation2 used in fast recovery */ + #ifndef IVAS_FLOAT_FIXED - float old_syn2[L_EXC_MEM]; /* FEC - old syn speech used in fast recovery */ + float old_syn2[L_EXC_MEM]; /* FEC - old syn speech used in fast recovery */ #endif - Word16 old_syn2_fx[L_EXC_MEM]; /* FEC - old syn speech used in fast recovery */ - - + Word16 old_syn2_fx[L_EXC_MEM]; /* FEC - old syn speech used in fast recovery */ } WI_DEC_DATA, *WI_DEC_HANDLE; - /*----------------------------------------------------------------------------------* * LD music post-filter *----------------------------------------------------------------------------------*/ @@ -887,62 +884,62 @@ typedef struct WI_dec_structure typedef struct ld_music_postfilt_structure { #ifndef IVAS_FLOAT_FIXED - float LDm_mem_etot; /* LD music post-filter - total energy memory */ + float LDm_mem_etot; /* LD music post-filter - total energy memory */ #endif - Word16 LDm_mem_etot_fx; /* LD music post-filter - total energy memory */ - - int16_t LDm_last_music_flag; /* LD music post-filter - last music flag */ - //Word16 LDm_last_music_flag; /* LD music post-filter - last music flag */ - - int16_t LDm_nb_thr_1; /* LD music post-filter - number of consecutive frames of level 1 */ - //Word16 LDm_nb_thr_1; /* LD music post-filter - number of consecutives frames of level 1 */ - - int16_t LDm_nb_thr_3; - //Word16 LDm_nb_thr_3; - + Word16 LDm_mem_etot_fx; /* LD music post-filter - total energy memory */ + + int16_t LDm_last_music_flag; /* LD music post-filter - last music flag */ + // Word16 LDm_last_music_flag; /* LD music post-filter - last music flag */ + + int16_t LDm_nb_thr_1; /* LD music post-filter - number of consecutive frames of level 1 */ + // Word16 LDm_nb_thr_1; /* LD music post-filter - number of consecutives frames of level 1 */ + + int16_t LDm_nb_thr_3; + // Word16 LDm_nb_thr_3; + #ifndef IVAS_FLOAT_FIXED - float dct_post_old_exc[DCT_L_POST - OFFSET2]; + float dct_post_old_exc[DCT_L_POST - OFFSET2]; #endif - Word16 dct_post_old_exc_fx[DCT_L_POST - OFFSET2]; - + Word16 dct_post_old_exc_fx[DCT_L_POST - OFFSET2]; + #ifndef IVAS_FLOAT_FIXED - float LDm_thres[4]; /* LD music post-filter - Classification threshold */ + float LDm_thres[4]; /* LD music post-filter - Classification threshold */ #endif - Word16 LDm_thres_fx[4]; /* LD music post-filter - Classification threshold */ - + Word16 LDm_thres_fx[4]; /* LD music post-filter - Classification threshold */ + #ifndef IVAS_FLOAT_FIXED - float LDm_lt_diff_etot[MAX_LT]; /* LD music post-filter - long-term total energy variation */ + float LDm_lt_diff_etot[MAX_LT]; /* LD music post-filter - long-term total energy variation */ #endif - Word16 LDm_lt_diff_etot_fx[MAX_LT]; /* LD music post-filter - long-term total energy variation */ - + Word16 LDm_lt_diff_etot_fx[MAX_LT]; /* LD music post-filter - long-term total energy variation */ + #ifndef IVAS_FLOAT_FIXED - float LDm_enh_lp_gbin[VOIC_BINS_HR]; /* LD music post-filter - smoothed suppression gain, per bin FFT */ + float LDm_enh_lp_gbin[VOIC_BINS_HR]; /* LD music post-filter - smoothed suppression gain, per bin FFT */ #endif - Word16 LDm_enh_lp_gbin_fx[VOIC_BINS_HR]; /* LD music post-filter - smoothed suppression gain, per bin FFT */ - + Word16 LDm_enh_lp_gbin_fx[VOIC_BINS_HR]; /* LD music post-filter - smoothed suppression gain, per bin FFT */ + #ifndef IVAS_FLOAT_FIXED - float LDm_enh_lf_EO[VOIC_BINS_HR]; /* LD music post-filter - old per bin E for previous half frame */ + float LDm_enh_lf_EO[VOIC_BINS_HR]; /* LD music post-filter - old per bin E for previous half frame */ #endif - Word32 LDm_enh_lf_EO_fx[VOIC_BINS_HR]; /* LD music post-filter - old per bin E for previous half frame */ - + Word32 LDm_enh_lf_EO_fx[VOIC_BINS_HR]; /* LD music post-filter - old per bin E for previous half frame */ + #ifndef IVAS_FLOAT_FIXED - float LDm_enh_min_ns_gain; /* LD music post-filter - minimum suppression gain */ + float LDm_enh_min_ns_gain; /* LD music post-filter - minimum suppression gain */ #endif - Word16 LDm_enh_min_ns_gain_fx; /* LD music post-filter - minimum suppression gain */ - + Word16 LDm_enh_min_ns_gain_fx; /* LD music post-filter - minimum suppression gain */ + #ifndef IVAS_FLOAT_FIXED - float LDm_bckr_noise[MBANDS_GN_LD]; /* LD music post-filter - background noise estimation per critical band */ + float LDm_bckr_noise[MBANDS_GN_LD]; /* LD music post-filter - background noise estimation per critical band */ #endif - Word32 LDm_bckr_noise_fx[MBANDS_GN_LD]; /* LD music post-filter - background noise estimation per critical band */ + Word32 LDm_bckr_noise_fx[MBANDS_GN_LD]; /* LD music post-filter - background noise estimation per critical band */ #ifndef IVAS_FLOAT_FIXED - float filt_lfE[DCT_L_POST]; + float filt_lfE[DCT_L_POST]; #endif - Word16 filt_lfE_fx[DCT_L_POST]; - - int16_t last_nonfull_music; - //Word16 last_nonfull_music; + Word16 filt_lfE_fx[DCT_L_POST]; - Word16 Old_ener_Q; /* Old energy scaling factor */ + int16_t last_nonfull_music; + // Word16 last_nonfull_music; + + Word16 Old_ener_Q; /* Old energy scaling factor */ } MUSIC_POSTFILT_DATA, *MUSIC_POSTFILT_HANDLE; @@ -954,35 +951,33 @@ typedef struct ld_music_postfilt_structure typedef struct bass_postfilt_structure { #ifndef IVAS_FLOAT_FIXED - float pst_old_syn[NBPSF_PIT_MAX]; /* Bass post-filter - old synthesis buffer 1 */ + float pst_old_syn[NBPSF_PIT_MAX]; /* Bass post-filter - old synthesis buffer 1 */ #endif - Word16 pst_old_syn_fx[NBPSF_PIT_MAX]; /* Bass post-filter - old synthesis buffer 1 Q_syn2-1*/ + Word16 pst_old_syn_fx[NBPSF_PIT_MAX]; /* Bass post-filter - old synthesis buffer 1 Q_syn2-1*/ Word16 q_pst_old_syn; #ifndef IVAS_FLOAT_FIXED - float pst_mem_deemp_err; /* Bass post-filter - filter memory of noise LP filter */ + float pst_mem_deemp_err; /* Bass post-filter - filter memory of noise LP filter */ #endif - Word16 pst_mem_deemp_err_fx; /* Bass post-filter - filter memory of noise LP filter Q_syn2-1*/ + Word16 pst_mem_deemp_err_fx; /* Bass post-filter - filter memory of noise LP filter Q_syn2-1*/ #ifndef IVAS_FLOAT_FIXED - float pst_lp_ener; /* Bass post-filter - long-term energy */ + float pst_lp_ener; /* Bass post-filter - long-term energy */ #endif - Word16 pst_lp_ener_fx; /* Bass post-filter - long-term energy Q8*/ - - int16_t Track_on_hist[L_TRACK_HIST]; /* Bass post-filter - History of half frame usage */ - //Word16 Track_on_hist[L_TRACK_HIST]; /* Bass post-filter - History of half frame usage */ - - int16_t vibrato_hist[L_TRACK_HIST]; /* Bass post-filter - History of frames declared as vibrato */ - //Word16 vibrato_hist[L_TRACK_HIST]; /* Bass post-filter - History of frames declared as vibrato */ + Word16 pst_lp_ener_fx; /* Bass post-filter - long-term energy Q8*/ + + int16_t Track_on_hist[L_TRACK_HIST]; /* Bass post-filter - History of half frame usage */ + // Word16 Track_on_hist[L_TRACK_HIST]; /* Bass post-filter - History of half frame usage */ + + int16_t vibrato_hist[L_TRACK_HIST]; /* Bass post-filter - History of frames declared as vibrato */ + // Word16 vibrato_hist[L_TRACK_HIST]; /* Bass post-filter - History of frames declared as vibrato */ #ifndef IVAS_FLOAT_FIXED - float psf_att; /* Bass post-filter - post filter attenuation factor */ + float psf_att; /* Bass post-filter - post filter attenuation factor */ #endif - Word16 psf_att_fx; /* Bass post-filter - post filter attenuation factor */ + Word16 psf_att_fx; /* Bass post-filter - post filter attenuation factor */ #ifndef IVAS_FLOAT_FIXED - float mem_mean_pit[L_TRACK_HIST]; /* Bass post-filter - average pitch memory */ + float mem_mean_pit[L_TRACK_HIST]; /* Bass post-filter - average pitch memory */ #endif - Word16 mem_mean_pit_fx[L_TRACK_HIST]; /* Bass post-filter - average pitch memory */ - - + Word16 mem_mean_pit_fx[L_TRACK_HIST]; /* Bass post-filter - average pitch memory */ } BPF_DEC_DATA, *BPF_DEC_HANDLE; @@ -993,95 +988,95 @@ typedef struct bass_postfilt_structure typedef struct td_cng_dec_structure { - int16_t cng_seed; /* DTX/CNG - seed for white noise random generator */ - // Word16 cng_seed; /*CNG and DTX - seed for white noise random generator*/ -#ifndef IVAS_FLOAT_FIXED - float Enew; /* DTX/CNG - decoded residual energy */ -#endif - Word32 Enew_fx; /* CNG and DTX - decoded residual energy Q6*/ - - int16_t old_enr_index; /* DTX/CNG - index of last encoded CNG energy */ - //Word16 old_enr_index; /* CNG and DTX - index of last encoded CNG energy Q0*/ - - int16_t cng_ener_seed; /* DTX/CNG - seed for random generator for variation of excitation energy */ - //Word16 cng_ener_seed; /*CNG and DTX - seed for random generator for variation of excitation energyQ0*/ - - int16_t cng_ener_seed1; - //Word16 cng_ener_seed1; - - int16_t last_allow_cn_step; - //Word16 last_allow_cn_step; /*Q0*/ - - int16_t ho_hist_size; /* DTX/CNG - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ - // Word16 ho_hist_size; /* CNG and DTX - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ - - int16_t ho_hist_ptr; /* DTX/CNG - pointer for averaging buffers */ - //Word16 ho_hist_ptr; /* CNG and DTX - pointer for averaging buffers */ - - int32_t ho_sid_bw; /* DTX/CNG - SID bandwidth flags */ - //Word32 ho_sid_bw; /* CNG and DTX - SID bandwidth flags */ + int16_t cng_seed; /* DTX/CNG - seed for white noise random generator */ + // Word16 cng_seed; /*CNG and DTX - seed for white noise random generator*/ +#ifndef IVAS_FLOAT_FIXED + float Enew; /* DTX/CNG - decoded residual energy */ +#endif + Word32 Enew_fx; /* CNG and DTX - decoded residual energy Q6*/ + + int16_t old_enr_index; /* DTX/CNG - index of last encoded CNG energy */ + // Word16 old_enr_index; /* CNG and DTX - index of last encoded CNG energy Q0*/ + + int16_t cng_ener_seed; /* DTX/CNG - seed for random generator for variation of excitation energy */ + // Word16 cng_ener_seed; /*CNG and DTX - seed for random generator for variation of excitation energyQ0*/ + + int16_t cng_ener_seed1; + // Word16 cng_ener_seed1; + + int16_t last_allow_cn_step; + // Word16 last_allow_cn_step; /*Q0*/ + + int16_t ho_hist_size; /* DTX/CNG - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ + // Word16 ho_hist_size; /* CNG and DTX - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ + + int16_t ho_hist_ptr; /* DTX/CNG - pointer for averaging buffers */ + // Word16 ho_hist_ptr; /* CNG and DTX - pointer for averaging buffers */ + + int32_t ho_sid_bw; /* DTX/CNG - SID bandwidth flags */ + // Word32 ho_sid_bw; /* CNG and DTX - SID bandwidth flags */ #ifndef IVAS_FLOAT_FIXED float ho_lsp_hist[HO_HIST_SIZE * M]; /* DTX/CNG - old LSP buffer for averaging */ #endif - Word16 ho_lsp_hist_fx[HO_HIST_SIZE * M]; /* CNG and DTX - old LSP buffer for averaging */ + Word16 ho_lsp_hist_fx[HO_HIST_SIZE * M]; /* CNG and DTX - old LSP buffer for averaging */ #ifndef IVAS_FLOAT_FIXED - float ho_ener_hist[HO_HIST_SIZE]; /* DTX/CNG - energy buffer for averaging */ + float ho_ener_hist[HO_HIST_SIZE]; /* DTX/CNG - energy buffer for averaging */ #endif - Word32 ho_ener_hist_fx[HO_HIST_SIZE]; /* CNG and DTX - energy buffer for averaging */ /*Q6 */ + Word32 ho_ener_hist_fx[HO_HIST_SIZE]; /* CNG and DTX - energy buffer for averaging */ /*Q6 */ #ifndef IVAS_FLOAT_FIXED - float ho_env_hist[HO_HIST_SIZE * NUM_ENV_CNG]; + float ho_env_hist[HO_HIST_SIZE * NUM_ENV_CNG]; #endif - Word32 ho_env_hist_fx[HO_HIST_SIZE * NUM_ENV_CNG]; + Word32 ho_env_hist_fx[HO_HIST_SIZE * NUM_ENV_CNG]; + + int16_t act_cnt; /* DTX/CNG - counter of active frames */ + // Word16 act_cnt; /* CNG and DTX - counter of active frames */ - int16_t act_cnt; /* DTX/CNG - counter of active frames */ - // Word16 act_cnt; /* CNG and DTX - counter of active frames */ - - int16_t ho_circ_size; /* DTX/CNG - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ - //Word16 ho_circ_size; /* CNG and DTX - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ - - int16_t ho_circ_ptr; /* DTX/CNG - pointer for averaging buffers */ - //Word16 ho_circ_ptr; /* CNG and DTX - pointer for averaging buffers */ + int16_t ho_circ_size; /* DTX/CNG - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ + // Word16 ho_circ_size; /* CNG and DTX - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ + + int16_t ho_circ_ptr; /* DTX/CNG - pointer for averaging buffers */ + // Word16 ho_circ_ptr; /* CNG and DTX - pointer for averaging buffers */ #ifndef IVAS_FLOAT_FIXED - float ho_lsp_circ[HO_HIST_SIZE * M]; /* DTX/CNG - old LSP buffer for averaging */ + float ho_lsp_circ[HO_HIST_SIZE * M]; /* DTX/CNG - old LSP buffer for averaging */ #endif - Word16 ho_lsp_circ_fx[HO_HIST_SIZE * M]; /* CNG and DTX - old LSP buffer for averaging */ + Word16 ho_lsp_circ_fx[HO_HIST_SIZE * M]; /* CNG and DTX - old LSP buffer for averaging */ #ifndef IVAS_FLOAT_FIXED - float ho_ener_circ[HO_HIST_SIZE]; /* DTX/CNG - energy buffer for averaging */ + float ho_ener_circ[HO_HIST_SIZE]; /* DTX/CNG - energy buffer for averaging */ #endif - Word32 ho_ener_circ_fx[HO_HIST_SIZE]; /* CNG and DTX - energy buffer for averaging */ /* Q6 */ + Word32 ho_ener_circ_fx[HO_HIST_SIZE]; /* CNG and DTX - energy buffer for averaging */ /* Q6 */ #ifndef IVAS_FLOAT_FIXED - float ho_env_circ[HO_HIST_SIZE * NUM_ENV_CNG]; + float ho_env_circ[HO_HIST_SIZE * NUM_ENV_CNG]; #endif - Word32 ho_env_circ_fx[HO_HIST_SIZE * NUM_ENV_CNG]; - - - int16_t num_ho; /* DTX/CNG - number of selected hangover frames */ - //Word16 num_ho; /* DTX/CNG - number of selected hangover frames */ - - int16_t ho_16k_lsp[HO_HIST_SIZE]; /* DTX/CNG - 16k LSPs flags */ - //Word16 ho_16k_lsp[HO_HIST_SIZE]; /* DTX/CNG - 16k LSPs flags */ + Word32 ho_env_circ_fx[HO_HIST_SIZE * NUM_ENV_CNG]; + + + int16_t num_ho; /* DTX/CNG - number of selected hangover frames */ + // Word16 num_ho; /* DTX/CNG - number of selected hangover frames */ + + int16_t ho_16k_lsp[HO_HIST_SIZE]; /* DTX/CNG - 16k LSPs flags */ + // Word16 ho_16k_lsp[HO_HIST_SIZE]; /* DTX/CNG - 16k LSPs flags */ - int16_t act_cnt2; /* DTX/CNG - counter of active frames for CNG_mode switching */ - // Word16 act_cnt2; /* DTX/CNG - counter of active frames for CNG_mode switching */ + int16_t act_cnt2; /* DTX/CNG - counter of active frames for CNG_mode switching */ + // Word16 act_cnt2; /* DTX/CNG - counter of active frames for CNG_mode switching */ #ifndef IVAS_FLOAT_FIXED - float old_env[20]; + float old_env[20]; #endif - Word32 old_env_fx[20]; + Word32 old_env_fx[20]; #ifndef IVAS_FLOAT_FIXED - float lp_env[20]; + float lp_env[20]; #endif - Word32 lp_env_fx[20]; + Word32 lp_env_fx[20]; #ifndef IVAS_FLOAT_FIXED - float exc_mem[24]; + float exc_mem[24]; #endif - Word16 exc_mem_fx[24]; + Word16 exc_mem_fx[24]; #ifndef IVAS_FLOAT_FIXED - float exc_mem1[30]; + float exc_mem1[30]; #endif - Word16 exc_mem1_fx[30]; + Word16 exc_mem1_fx[30]; #ifndef IVAS_FLOAT_FIXED float interpol_3_2_cng_dec[INTERP_3_2_MEM_LEN]; @@ -1108,31 +1103,29 @@ typedef struct td_cng_dec_structure #endif int16_t shb_dtx_count; int16_t trans_cnt; - + #ifdef IVAS_FLOAT_FIXED Word16 interpol_3_2_cng_dec_fx[INTERP_3_2_MEM_LEN]; - Word32 shb_cng_ener_fx_32; // Q(11) - Word32 shb_cng_gain_fx_32; //Q(11) - Word32 wb_cng_ener_fx_32; // Q(11) - Word32 last_wb_cng_ener_fx_32; // Q(11) - Word32 last_shb_cng_ener_fx_32; // Q(11) - Word16 lsp_shb_prev_fx[LPC_SHB_ORDER]; //Q(14) - Word16 lsp_shb_prev_prev_fx[LPC_SHB_ORDER]; //Q(14) + Word32 shb_cng_ener_fx_32; // Q(11) + Word32 shb_cng_gain_fx_32; // Q(11) + Word32 wb_cng_ener_fx_32; // Q(11) + Word32 last_wb_cng_ener_fx_32; // Q(11) + Word32 last_shb_cng_ener_fx_32; // Q(11) + Word16 lsp_shb_prev_fx[LPC_SHB_ORDER]; // Q(14) + Word16 lsp_shb_prev_prev_fx[LPC_SHB_ORDER]; // Q(14) #endif - int16_t burst_cnt; - //Word16 burst_cnt; + int16_t burst_cnt; + // Word16 burst_cnt; #ifndef IVAS_FLOAT_FIXED - float last_shb_ener; + float last_shb_ener; #endif #ifdef IVAS_FLOAT_FIXED - Word32 last_shb_ener_fx; //Q(11) + Word32 last_shb_ener_fx; // Q(11) #endif - Word16 last_cng_type_fx; /* DTX/CNG - flag indicating last frame LP or CLDFB based SID/CNG */ - - + Word16 last_cng_type_fx; /* DTX/CNG - flag indicating last frame LP or CLDFB based SID/CNG */ } TD_CNG_DEC_DATA, *TD_CNG_DEC_HANDLE; @@ -1145,83 +1138,82 @@ typedef struct td_cng_dec_structure typedef struct sc_vbr_dec_structure { int16_t firstTime_voiceddec; - //Word16 firstTime_voiceddec; /*Q0*/ + // Word16 firstTime_voiceddec; /*Q0*/ /* DTFS variables */ #ifndef IVAS_FLOAT_FIXED float dtfs_dec_a[MAXLAG_WI]; #endif - Word16 dtfs_dec_a_fx[MAXLAG_WI]; /*Variable Q format in dtfs_dec_Q*/ + Word16 dtfs_dec_a_fx[MAXLAG_WI]; /*Variable Q format in dtfs_dec_Q*/ #ifndef IVAS_FLOAT_FIXED - float dtfs_dec_b[MAXLAG_WI]; + float dtfs_dec_b[MAXLAG_WI]; #endif - Word16 dtfs_dec_b_fx[MAXLAG_WI]; /*Variable Q format in dtfs_dec_Q*/ + Word16 dtfs_dec_b_fx[MAXLAG_WI]; /*Variable Q format in dtfs_dec_Q*/ int16_t dtfs_dec_lag; - //Word16 dtfs_dec_lag; - - int16_t dtfs_dec_nH; - //Word16 dtfs_dec_nH; - - int16_t dtfs_dec_nH_4kHz; - //Word16 dtfs_dec_nH_4kHz; /*Q0*/ + // Word16 dtfs_dec_lag; + + int16_t dtfs_dec_nH; + // Word16 dtfs_dec_nH; + + int16_t dtfs_dec_nH_4kHz; + // Word16 dtfs_dec_nH_4kHz; /*Q0*/ #ifndef IVAS_FLOAT_FIXED float dtfs_dec_upper_cut_off_freq_of_interest; #endif - Word16 dtfs_dec_upper_cut_off_freq_of_interest_fx; /*Q0*/ + Word16 dtfs_dec_upper_cut_off_freq_of_interest_fx; /*Q0*/ #ifndef IVAS_FLOAT_FIXED float dtfs_dec_upper_cut_off_freq; #endif - Word16 dtfs_dec_upper_cut_off_freq_fx; /*Q0*/ + Word16 dtfs_dec_upper_cut_off_freq_fx; /*Q0*/ #ifndef IVAS_FLOAT_FIXED - float ph_offset_D; + float ph_offset_D; #endif - Word16 ph_offset_D_fx; /* normalized by 2Pi Q15*/ + Word16 ph_offset_D_fx; /* normalized by 2Pi Q15*/ #ifndef IVAS_FLOAT_FIXED - float lastLgainD; /* previous gain value for the low band */ + float lastLgainD; /* previous gain value for the low band */ #endif - Word16 lastLgainD_fx; /* previous gain value for the low band Q11*/ + Word16 lastLgainD_fx; /* previous gain value for the low band Q11*/ #ifndef IVAS_FLOAT_FIXED - float lastHgainD; /* previous gain value for the high band */ + float lastHgainD; /* previous gain value for the high band */ #endif - Word16 lastHgainD_fx; /* previous gain value for the high band Q11 */ + Word16 lastHgainD_fx; /* previous gain value for the high band Q11 */ #ifndef IVAS_FLOAT_FIXED - float lasterbD[NUM_ERB_WB]; /* previous amplitude spectrum (ERB) */ + float lasterbD[NUM_ERB_WB]; /* previous amplitude spectrum (ERB) */ #endif - Word16 lasterbD_fx[NUM_ERB_WB]; /* previous amplitude spectrum (ERB) Q13*/ + Word16 lasterbD_fx[NUM_ERB_WB]; /* previous amplitude spectrum (ERB) Q13*/ - Word16 dtfs_dec_Q; /*Q0*/ + Word16 dtfs_dec_Q; /*Q0*/ /* NELP decoder variables */ #ifndef IVAS_FLOAT_FIXED float bp1_filt_mem_nb_dec[14]; #endif - Word32 bp1_filt_mem_nb_dec_fx[14]; /* qfm currently Q0*/ + Word32 bp1_filt_mem_nb_dec_fx[14]; /* qfm currently Q0*/ #ifndef IVAS_FLOAT_FIXED - float bp1_filt_mem_wb_dec[8]; + float bp1_filt_mem_wb_dec[8]; #endif - Word16 bp1_filt_mem_wb_dec_fx[8]; /* qfm currently Q0*/ + Word16 bp1_filt_mem_wb_dec_fx[8]; /* qfm currently Q0*/ #ifndef IVAS_FLOAT_FIXED float shape1_filt_mem_dec[20]; #endif - Word16 shape1_filt_mem_dec_fx[10]; /* qfm currently Q0*/ + Word16 shape1_filt_mem_dec_fx[10]; /* qfm currently Q0*/ #ifndef IVAS_FLOAT_FIXED float shape2_filt_mem_dec[20]; #endif - Word16 shape2_filt_mem_dec_fx[10]; /* qfm currently Q0*/ - + Word16 shape2_filt_mem_dec_fx[10]; /* qfm currently Q0*/ + #ifndef IVAS_FLOAT_FIXED float shape3_filt_mem_dec[20]; #endif - Word16 shape3_filt_mem_dec_fx[10]; /* qfm currently Q0*/ + Word16 shape3_filt_mem_dec_fx[10]; /* qfm currently Q0*/ int16_t nelp_dec_seed; - //Word16 nelp_dec_seed; /* Q0*/ + // Word16 nelp_dec_seed; /* Q0*/ - Word16 FadeScale_fx; /*Q15*/ - + Word16 FadeScale_fx; /*Q15*/ } SC_VBR_DEC_DATA, *SC_VBR_DEC_HANDLE; @@ -1233,86 +1225,85 @@ typedef struct sc_vbr_dec_structure typedef struct hq_nbfec_structure { int16_t prev_last_core; /* !!! note: the parameter is identical to last_core in IVAS */ - //Word16 prev_last_core; /* !!! note: the parameter is identical to last_core in IVAS */ + // Word16 prev_last_core; /* !!! note: the parameter is identical to last_core in IVAS */ #ifndef IVAS_FLOAT_FIXED float diff_energy; #endif - Word16 diff_energy_fx; + Word16 diff_energy_fx; int16_t stat_mode_out; - //Word16 stat_mode_out; + // Word16 stat_mode_out; int16_t stat_mode_old; - //Word16 stat_mode_old; + // Word16 stat_mode_old; int16_t phase_mat_flag; - //Word16 phase_mat_flag; - - int16_t phase_mat_next; - //Word16 phase_mat_next; + // Word16 phase_mat_flag; + + int16_t phase_mat_next; + // Word16 phase_mat_next; int16_t old_Min_ind; - //Word16 old_Min_ind; - + // Word16 old_Min_ind; + #ifndef IVAS_FLOAT_FIXED - float old_auOut_2fr[L_FRAME8k * 2]; + float old_auOut_2fr[L_FRAME8k * 2]; #endif - Word16 old_auOut_2fr_fx[L_FRAME8k * 2]; - + Word16 old_auOut_2fr_fx[L_FRAME8k * 2]; + #ifndef IVAS_FLOAT_FIXED - float old_out_pha[2][N_LEAD_NB]; /* FEC for HQ Core, 0-phase matching old_out, 1-overlapping original old_out and phase matching old_out*/ + float old_out_pha[2][N_LEAD_NB]; /* FEC for HQ Core, 0-phase matching old_out, 1-overlapping original old_out and phase matching old_out*/ #endif - Word16 old_out_pha_fx[2][N_LEAD_NB]; /* FEC for HQ Core, 0-phase matching old_out, 1-overlapping original old_out and phase matching old_out*/ - + Word16 old_out_pha_fx[2][N_LEAD_NB]; /* FEC for HQ Core, 0-phase matching old_out, 1-overlapping original old_out and phase matching old_out*/ + #ifndef IVAS_FLOAT_FIXED - float ynrm_values[MAX_SB_NB][MAX_PGF]; + float ynrm_values[MAX_SB_NB][MAX_PGF]; #endif - Word32 ynrm_values_fx[MAX_SB_NB][MAX_PGF]; - + Word32 ynrm_values_fx[MAX_SB_NB][MAX_PGF]; + #ifndef IVAS_FLOAT_FIXED - float r_p_values[MAX_SB_NB][MAX_ROW]; + float r_p_values[MAX_SB_NB][MAX_ROW]; #endif - Word32 r_p_values_fx[MAX_SB_NB][MAX_ROW]; + Word32 r_p_values_fx[MAX_SB_NB][MAX_ROW]; #ifndef IVAS_FLOAT_FIXED float Norm_gain[SFM_N_NB]; #endif - Word16 Norm_gain_fx[SFM_N_NB]; - - /*Word16 old_hqswb_clas;*/ /* only used in inactive code, where it might probably be replaced by old_hqswb_clas_fx */ + Word16 Norm_gain_fx[SFM_N_NB]; + /*Word16 old_hqswb_clas;*/ /* only used in inactive code, where it might probably be replaced by old_hqswb_clas_fx */ int16_t HQ_FEC_seed; - //Word16 HQ_FEC_seed; + // Word16 HQ_FEC_seed; #ifndef IVAS_FLOAT_FIXED float energy_MA_Curr[2]; #endif - Word16 energy_MA_Curr_fx[2]; - - int16_t prev_sign_switch[HQ_FEC_SIGN_SFM]; - //Word16 prev_sign_switch[HQ_FEC_SIGN_SFM]; - - int16_t prev_sign_switch_2[HQ_FEC_SIGN_SFM]; - //Word16 prev_sign_switch_2[HQ_FEC_SIGN_SFM]; - + Word16 energy_MA_Curr_fx[2]; + + int16_t prev_sign_switch[HQ_FEC_SIGN_SFM]; + // Word16 prev_sign_switch[HQ_FEC_SIGN_SFM]; + + int16_t prev_sign_switch_2[HQ_FEC_SIGN_SFM]; + // Word16 prev_sign_switch_2[HQ_FEC_SIGN_SFM]; + #ifndef IVAS_FLOAT_FIXED - float old_coeffs[L_FRAME8k]; /* HQ core - old coefficients (for FEC) */ + float old_coeffs[L_FRAME8k]; /* HQ core - old coefficients (for FEC) */ #endif - Word32 old_coeffs_fx[L_FRAME8k]; /* HQ core - old coefficients (for FEC) */ - + Word32 old_coeffs_fx[L_FRAME8k]; /* HQ core - old coefficients (for FEC) */ + #ifndef IVAS_FLOAT_FIXED - float oldIMDCTout[L_FRAME8k / 2]; + float oldIMDCTout[L_FRAME8k / 2]; #endif - Word32 oldIMDCTout_fx[L_FRAME8k / 2]; - + Word32 oldIMDCTout_fx[L_FRAME8k / 2]; + #ifndef IVAS_FLOAT_FIXED - float prev_oldauOut[L_FRAME8k]; + float prev_oldauOut[L_FRAME8k]; #endif - Word16 prev_oldauOut_fx[L_FRAME8k]; + Word16 prev_oldauOut_fx[L_FRAME8k]; } HQ_NBFEC_DATA, *HQ_NBFEC_HANDLE; @@ -1327,240 +1318,239 @@ typedef struct hq_dec_structure #ifndef IVAS_FLOAT_FIXED float old_out[L_FRAME48k]; /* HQ core - previous synthesis for OLA */ #endif - Word32 oldOut_fx[L_FRAME48k]; /* HQ core - previous synthesis for OLA */ - Word16 old_out_fx[L_FRAME48k]; /* HQ core - previous synthesis for OLA */ - Word16 Q_old_out; + Word32 oldOut_fx[L_FRAME48k]; /* HQ core - previous synthesis for OLA */ + Word16 old_out_fx[L_FRAME48k]; /* HQ core - previous synthesis for OLA */ + Word16 Q_old_out; #ifdef IVAS_FLOAT_FIXED - Word16 exp_old_out; + Word16 exp_old_out; #endif #ifndef IVAS_FLOAT_FIXED - float old_outLB[L_FRAME32k]; + float old_outLB[L_FRAME32k]; #endif - Word16 old_out_LB_fx[L_FRAME32k]; /* HQ core - previous synthesis for OLA for Low Band */ + Word16 old_out_LB_fx[L_FRAME32k]; /* HQ core - previous synthesis for OLA for Low Band */ Word16 Q_old_outLB; Word32 old_outLB_fx[L_FRAME32k]; Word16 q_old_outLB_fx; - Word16 Q_old_wtda_LB; - Word16 Q_old_wtda; - Word16 Q_old_postdec; /*scaling of the output of core_switching_post_dec_fx() */ + Word16 Q_old_wtda_LB; + Word16 Q_old_wtda; + Word16 Q_old_postdec; /*scaling of the output of core_switching_post_dec_fx() */ - int16_t last_hq_core_type; - //Word16 last_hq_core_type; /*Q0*/ + int16_t last_hq_core_type; + // Word16 last_hq_core_type; /*Q0*/ - //int16_t old_is_transient[3]; /* HQ core - previous transient flag (for FEC and BWE/NF) */ - Word16 old_is_transient[3]; /* HQ core - previous transient flag (for FEC) */ + // int16_t old_is_transient[3]; /* HQ core - previous transient flag (for FEC and BWE/NF) */ + Word16 old_is_transient[3]; /* HQ core - previous transient flag (for FEC) */ - //int16_t mem_norm[SFM_N_ENV_STAB]; - Word16 mem_norm[SFM_N_ENV_STAB]; /* Q0 */ + // int16_t mem_norm[SFM_N_ENV_STAB]; + Word16 mem_norm[SFM_N_ENV_STAB]; /* Q0 */ - //int16_t mem_env_delta; - Word16 mem_env_delta; /* Q11 */ - - //int16_t no_att_hangover; - Word16 no_att_hangover; /* Q0 */ + // int16_t mem_env_delta; + Word16 mem_env_delta; /* Q11 */ + + // int16_t no_att_hangover; + Word16 no_att_hangover; /* Q0 */ -#ifndef IVAS_FLOAT_FIXED - float energy_lt; -#endif - Word32 energy_lt_fx; /* Q13 */ - - //int16_t hq_generic_seed; - Word16 hq_generic_seed; - #ifndef IVAS_FLOAT_FIXED - float prev_noise_level[2]; + float energy_lt; #endif - Word16 prev_noise_level_fx[2]; /* Q15 */ - - //int16_t prev_hqswb_clas; - Word16 prev_hqswb_clas; - - //int16_t prev_R; /* the table of bit allocation of last frame */ - Word16 prev_R; /* the table of bit allocation of last frame */ + Word32 energy_lt_fx; /* Q13 */ + + // int16_t hq_generic_seed; + Word16 hq_generic_seed; #ifndef IVAS_FLOAT_FIXED - float prev_coeff_out[L_HQ_WB_BWE]; /* the highest coefficients of last frame */ -#endif - int16_t prev_SWB_peak_pos[SPT_SHORTEN_SBNUM]; - - Word32 prev_coeff_out_fx[L_HQ_WB_BWE]; /* Q12 */ /* the coefficients of last frame */ - Word16 prev_SWB_peak_pos_fx[SPT_SHORTEN_SBNUM]; + float prev_noise_level[2]; +#endif + Word16 prev_noise_level_fx[2]; /* Q15 */ + + // int16_t prev_hqswb_clas; + Word16 prev_hqswb_clas; + // int16_t prev_R; /* the table of bit allocation of last frame */ + Word16 prev_R; /* the table of bit allocation of last frame */ - //int16_t HqVoicing; - Word16 HqVoicing; -#ifndef IVAS_FLOAT_FIXED - float fer_samples[L_FRAME48k]; +#ifndef IVAS_FLOAT_FIXED + float prev_coeff_out[L_HQ_WB_BWE]; /* the highest coefficients of last frame */ #endif - Word16 fer_samples_fx[L_FRAME48k]; - Word16 Q_fer_samples; -#ifndef IVAS_FLOAT_FIXED - float prev_normq[SFM_N_WB]; /* previous norms */ -#endif - Word32 prev_normq_fx[SFM_N_WB]; /* Q14 */ /* previous norms */ - + int16_t prev_SWB_peak_pos[SPT_SHORTEN_SBNUM]; + + Word32 prev_coeff_out_fx[L_HQ_WB_BWE]; /* Q12 */ /* the coefficients of last frame */ + Word16 prev_SWB_peak_pos_fx[SPT_SHORTEN_SBNUM]; -#ifndef IVAS_FLOAT_FIXED - float prev_env[SFM_N_WB]; /* previous noise envelopes */ -#endif - Word32 prev_env_fx[SFM_N_WB]; /* previous noise envelopes */ - Word16 prev_env_Q[SFM_N_WB]; + // int16_t HqVoicing; + Word16 HqVoicing; +#ifndef IVAS_FLOAT_FIXED + float fer_samples[L_FRAME48k]; +#endif + Word16 fer_samples_fx[L_FRAME48k]; + Word16 Q_fer_samples; +#ifndef IVAS_FLOAT_FIXED + float prev_normq[SFM_N_WB]; /* previous norms */ +#endif + Word32 prev_normq_fx[SFM_N_WB]; /* Q14 */ /* previous norms */ -#ifndef IVAS_FLOAT_FIXED - float last_ni_gain[BANDS_MAX]; +#ifndef IVAS_FLOAT_FIXED + float prev_env[SFM_N_WB]; /* previous noise envelopes */ #endif - Word32 last_ni_gain_fx[BANDS_MAX]; - -#ifndef IVAS_FLOAT_FIXED - float last_env[BANDS_MAX]; + Word32 prev_env_fx[SFM_N_WB]; /* previous noise envelopes */ + + Word16 prev_env_Q[SFM_N_WB]; + + +#ifndef IVAS_FLOAT_FIXED + float last_ni_gain[BANDS_MAX]; +#endif + Word32 last_ni_gain_fx[BANDS_MAX]; + +#ifndef IVAS_FLOAT_FIXED + float last_env[BANDS_MAX]; #endif - Word16 last_env_fx[BANDS_MAX]; + Word16 last_env_fx[BANDS_MAX]; - //int16_t last_max_pos_pulse; - Word16 last_max_pos_pulse; + // int16_t last_max_pos_pulse; + Word16 last_max_pos_pulse; /* pre-echo reduction */ -#ifndef IVAS_FLOAT_FIXED +#ifndef IVAS_FLOAT_FIXED float memfilt_lb; #endif - Word16 memfilt_lb_fx; /* Q0 */ - -#ifndef IVAS_FLOAT_FIXED - float mean_prev_hb; -#endif - Word32 mean_prev_hb_fx; /* Q0 */ - -#ifndef IVAS_FLOAT_FIXED - float smoothmem; -#endif - Word16 smoothmem_fx; /* Q15 */ - -#ifndef IVAS_FLOAT_FIXED - float mean_prev; -#endif - Word32 mean_prev_fx; /* Q0 */ - -#ifndef IVAS_FLOAT_FIXED - float mean_prev_nc; -#endif - Word32 mean_prev_nc_fx; /* Q0 */ - -#ifndef IVAS_FLOAT_FIXED - float wmold_hb; -#endif - Word16 wmold_hb_fx; /* Q15 */ - - int16_t prevflag; - - int16_t pastpre; - - - //int16_t prev_frm_hfe2; - Word16 prev_frm_hfe2; - - //int16_t prev_stab_hfe2; - Word16 prev_stab_hfe2; - -#ifndef IVAS_FLOAT_FIXED - float prev_ni_ratio; -#endif - Word16 prev_ni_ratio_fx; /* 15 */ - -#ifndef IVAS_FLOAT_FIXED - float prev_En_sb[NB_SWB_SUBBANDS]; -#endif - Word16 prev_En_sb_fx[NB_SWB_SUBBANDS]; /* QsEn(4) */ + Word16 memfilt_lb_fx; /* Q0 */ + +#ifndef IVAS_FLOAT_FIXED + float mean_prev_hb; +#endif + Word32 mean_prev_hb_fx; /* Q0 */ + +#ifndef IVAS_FLOAT_FIXED + float smoothmem; +#endif + Word16 smoothmem_fx; /* Q15 */ + +#ifndef IVAS_FLOAT_FIXED + float mean_prev; +#endif + Word32 mean_prev_fx; /* Q0 */ + +#ifndef IVAS_FLOAT_FIXED + float mean_prev_nc; +#endif + Word32 mean_prev_nc_fx; /* Q0 */ + +#ifndef IVAS_FLOAT_FIXED + float wmold_hb; +#endif + Word16 wmold_hb_fx; /* Q15 */ + + int16_t prevflag; + + int16_t pastpre; + + + // int16_t prev_frm_hfe2; + Word16 prev_frm_hfe2; + + // int16_t prev_stab_hfe2; + Word16 prev_stab_hfe2; + +#ifndef IVAS_FLOAT_FIXED + float prev_ni_ratio; +#endif + Word16 prev_ni_ratio_fx; /* 15 */ + +#ifndef IVAS_FLOAT_FIXED + float prev_En_sb[NB_SWB_SUBBANDS]; +#endif + Word16 prev_En_sb_fx[NB_SWB_SUBBANDS]; /* QsEn(4) */ /*----------------------------------------------------------------------------------* * HQ FEC *----------------------------------------------------------------------------------*/ /* HQ PHASE ECU internal state */ - //int16_t time_offs; - Word16 time_offs; - -#ifndef IVAS_FLOAT_FIXED - float X_sav[PH_ECU_SPEC_SIZE]; -#endif - Word16 X_sav_fx[PH_ECU_SPEC_SIZE]; - - Word16 Q_X_sav; - - //int16_t num_p; - Word16 num_p; - - //int16_t plocs[MAX_PLOCS]; - Word16 plocs[MAX_PLOCS]; - -#ifndef IVAS_FLOAT_FIXED - float plocsi[MAX_PLOCS]; -#endif - Word32 plocsi_fx[MAX_PLOCS]; - -#ifndef IVAS_FLOAT_FIXED - float env_stab; -#endif - Word16 env_stab_fx; - - //int16_t mem_norm_hqfec[SFM_N_ENV_STAB]; - Word16 mem_norm_hqfec[SFM_N_ENV_STAB]; - - //int16_t mem_env_delta_hqfec; - Word16 mem_env_delta_hqfec; - -#ifndef IVAS_FLOAT_FIXED - float env_stab_plc; -#endif - Word16 env_stab_plc_fx; - -#ifndef IVAS_FLOAT_FIXED - float env_stab_state_p[NUM_ENV_STAB_PLC_STATES]; -#endif - Word16 env_stab_state_p_fx[NUM_ENV_STAB_PLC_STATES]; - - //int16_t envstabplc_hocnt; - Word16 envstabplc_hocnt; - -#ifndef IVAS_FLOAT_FIXED + // int16_t time_offs; + Word16 time_offs; + +#ifndef IVAS_FLOAT_FIXED + float X_sav[PH_ECU_SPEC_SIZE]; +#endif + Word16 X_sav_fx[PH_ECU_SPEC_SIZE]; + + Word16 Q_X_sav; + + // int16_t num_p; + Word16 num_p; + + // int16_t plocs[MAX_PLOCS]; + Word16 plocs[MAX_PLOCS]; + +#ifndef IVAS_FLOAT_FIXED + float plocsi[MAX_PLOCS]; +#endif + Word32 plocsi_fx[MAX_PLOCS]; + +#ifndef IVAS_FLOAT_FIXED + float env_stab; +#endif + Word16 env_stab_fx; + + // int16_t mem_norm_hqfec[SFM_N_ENV_STAB]; + Word16 mem_norm_hqfec[SFM_N_ENV_STAB]; + + // int16_t mem_env_delta_hqfec; + Word16 mem_env_delta_hqfec; + +#ifndef IVAS_FLOAT_FIXED + float env_stab_plc; +#endif + Word16 env_stab_plc_fx; + +#ifndef IVAS_FLOAT_FIXED + float env_stab_state_p[NUM_ENV_STAB_PLC_STATES]; +#endif + Word16 env_stab_state_p_fx[NUM_ENV_STAB_PLC_STATES]; + + // int16_t envstabplc_hocnt; + Word16 envstabplc_hocnt; + +#ifndef IVAS_FLOAT_FIXED float mag_chg_1st[LGW_MAX]; /* i/o: per band magnitude modifier for transients*/ -#endif - Word16 mag_chg_1st_fx[LGW_MAX]; /* i/o: per band magnitude modifier for transients*/ - -#ifndef IVAS_FLOAT_FIXED - float Xavg[LGW_MAX]; /* Frequency group average gain to fade to */ -#endif - Word16 Xavg_fx[LGW_MAX]; /* Frequency group average gain to fade to */ - -#ifndef IVAS_FLOAT_FIXED - float beta_mute; /* Factor for long-term mute */ -#endif - Word16 beta_mute_fx; /* Factor for long-term mute */ - - //int16_t last_fec; - Word16 last_fec; - - //int16_t ph_ecu_HqVoicing; - Word16 ph_ecu_HqVoicing; - - //int16_t oldHqVoicing; - Word16 oldHqVoicing; - -#ifndef IVAS_FLOAT_FIXED - float oldgapsynth[L_FRAME48k]; -#endif - Word16 oldgapsynth_fx[L_FRAME48k]; - - //int16_t ph_ecu_active; /* Set to 1 if Phase ECU was used in last bad frame; Set to 2 if TCX TD PLC was used */ - Word16 ph_ecu_active; /* Set if Phase ECU was used in last bad frame */ - - int16_t ni_seed_forfec; - - int16_t ber_occured_in_pvq; /* flag for BER detection from PVQ routines */ +#endif + Word16 mag_chg_1st_fx[LGW_MAX]; /* i/o: per band magnitude modifier for transients*/ + +#ifndef IVAS_FLOAT_FIXED + float Xavg[LGW_MAX]; /* Frequency group average gain to fade to */ +#endif + Word16 Xavg_fx[LGW_MAX]; /* Frequency group average gain to fade to */ + +#ifndef IVAS_FLOAT_FIXED + float beta_mute; /* Factor for long-term mute */ +#endif + Word16 beta_mute_fx; /* Factor for long-term mute */ + + // int16_t last_fec; + Word16 last_fec; + + // int16_t ph_ecu_HqVoicing; + Word16 ph_ecu_HqVoicing; + + // int16_t oldHqVoicing; + Word16 oldHqVoicing; + +#ifndef IVAS_FLOAT_FIXED + float oldgapsynth[L_FRAME48k]; +#endif + Word16 oldgapsynth_fx[L_FRAME48k]; + + // int16_t ph_ecu_active; /* Set to 1 if Phase ECU was used in last bad frame; Set to 2 if TCX TD PLC was used */ + Word16 ph_ecu_active; /* Set if Phase ECU was used in last bad frame */ + int16_t ni_seed_forfec; + + int16_t ber_occured_in_pvq; /* flag for BER detection from PVQ routines */ } HQ_DEC_DATA, *HQ_DEC_HANDLE; @@ -1572,30 +1562,30 @@ typedef struct hq_dec_structure typedef struct zero_bwe_dec_structure { - int16_t seed2; /* HF (6-7kHz) BWE - seed for random signal generator */ - -#ifndef IVAS_FLOAT_FIXED - float mem_hp400[4]; /* HF (6-7kHz) BWE - hp400 filter memory */ - - float mem_hf[( L_FIR - 1 )]; /* HF (6-7kHz) BWE - band-pass filter memory */ - - float mem_syn_hf[M]; /* HF (6-7kHz) BWE - synthesis filter memory */ - - float delay_syn_hf[NS2SA( 16000, DELAY_CLDFB_NS )]; /* HF (6-7kHz) BWE - To synchronise BWE content with postfiltered synthesis */ - - float mem_hp_interp[INTERP_3_1_MEM_LEN]; /* HF (6-7 kHz) BWE - interp. memory */ -#endif - - Word16 mem_hp400_fx[6]; /* HF (6-7kHz) BWE - hp400 filter memory */ - Word16 q_mem_hp400_fx; - - Word16 mem_hf_fx[2 * L_FILT16k]; /* HF (6-7kHz) BWE - band-pass filter memory Q(-2-memExp1)*/ - - Word16 mem_syn_hf_fx[M]; /* HF (6-7kHz) BWE - synthesis filter memory Q0*/ - - Word16 delay_syn_hf_fx[NS2SA(16000, DELAY_CLDFB_NS)]; /* HF (6-7kHz) BWE - To synchronise BWE content with postfiltered synthesis Q0*/ - - Word16 mem_hp_interp_fx[INTERP_3_1_MEM_LEN]; /* HF (6-7 kHz) BWE - interp. memory */ + int16_t seed2; /* HF (6-7kHz) BWE - seed for random signal generator */ + +#ifndef IVAS_FLOAT_FIXED + float mem_hp400[4]; /* HF (6-7kHz) BWE - hp400 filter memory */ + + float mem_hf[( L_FIR - 1 )]; /* HF (6-7kHz) BWE - band-pass filter memory */ + + float mem_syn_hf[M]; /* HF (6-7kHz) BWE - synthesis filter memory */ + + float delay_syn_hf[NS2SA( 16000, DELAY_CLDFB_NS )]; /* HF (6-7kHz) BWE - To synchronise BWE content with postfiltered synthesis */ + + float mem_hp_interp[INTERP_3_1_MEM_LEN]; /* HF (6-7 kHz) BWE - interp. memory */ +#endif + + Word16 mem_hp400_fx[6]; /* HF (6-7kHz) BWE - hp400 filter memory */ + Word16 q_mem_hp400_fx; + + Word16 mem_hf_fx[2 * L_FILT16k]; /* HF (6-7kHz) BWE - band-pass filter memory Q(-2-memExp1)*/ + + Word16 mem_syn_hf_fx[M]; /* HF (6-7kHz) BWE - synthesis filter memory Q0*/ + + Word16 delay_syn_hf_fx[NS2SA( 16000, DELAY_CLDFB_NS )]; /* HF (6-7kHz) BWE - To synchronise BWE content with postfiltered synthesis Q0*/ + + Word16 mem_hp_interp_fx[INTERP_3_1_MEM_LEN]; /* HF (6-7 kHz) BWE - interp. memory */ } ZERO_BWE_DEC_DATA, *ZERO_BWE_DEC_HANDLE; @@ -1610,303 +1600,302 @@ typedef struct td_bwe_dec_structure #ifndef IVAS_FLOAT_FIXED float state_lpc_syn[LPC_SHB_ORDER]; #endif - Word16 state_lpc_syn_fx[LPC_SHB_ORDER]; + Word16 state_lpc_syn_fx[LPC_SHB_ORDER]; #ifndef IVAS_FLOAT_FIXED float mem_csfilt[2]; #endif - Word32 mem_csfilt_fx[2]; + Word32 mem_csfilt_fx[2]; /* states for the filters used in generating SHB signal from SHB excitation*/ #ifndef IVAS_FLOAT_FIXED float state_syn_shbexc[L_SHB_LAHEAD]; - float syn_overlap[L_SHB_LAHEAD]; /* overlap buffer used to Adjust SHB Frame Gain*/ + float syn_overlap[L_SHB_LAHEAD]; /* overlap buffer used to Adjust SHB Frame Gain*/ #endif - Word16 state_syn_shbexc_fx[L_SHB_LAHEAD]; - - Word16 syn_overlap_fx[L_SHB_LAHEAD]; /* overlap buffer used to Adjust SHB Frame Gain*/ - Word32 syn_overlap_fx_32[L_SHB_LAHEAD]; /* overlap buffer used to Adjust SHB Frame Gain*/ + Word16 state_syn_shbexc_fx[L_SHB_LAHEAD]; + + Word16 syn_overlap_fx[L_SHB_LAHEAD]; /* overlap buffer used to Adjust SHB Frame Gain*/ + Word32 syn_overlap_fx_32[L_SHB_LAHEAD]; /* overlap buffer used to Adjust SHB Frame Gain*/ /* previous frame parameters for frame error concealment */ #ifndef IVAS_FLOAT_FIXED float lsp_prevfrm[LPC_SHB_ORDER]; #endif - Word16 lsp_prevfrm_fx[LPC_SHB_ORDER]; - + Word16 lsp_prevfrm_fx[LPC_SHB_ORDER]; + #ifndef IVAS_FLOAT_FIXED - float GainFrame_prevfrm; + float GainFrame_prevfrm; #endif - Word32 GainFrame_prevfrm_fx; - + Word32 GainFrame_prevfrm_fx; + #ifndef IVAS_FLOAT_FIXED - float GainShape_Delay[NUM_SHB_SUBFR / 2]; + float GainShape_Delay[NUM_SHB_SUBFR / 2]; #endif Word16 GainShape_Delay_fx[NUM_SHB_SUBFR / 2]; - + #ifndef IVAS_FLOAT_FIXED - float GainAttn; + float GainAttn; #endif - Word16 GainAttn_fx; + Word16 GainAttn_fx; #ifndef IVAS_FLOAT_FIXED float old_bwe_exc[PIT16k_MAX * 2]; /* old excitation */ #endif - Word16 old_bwe_exc_fx[PIT16k_MAX * 2]; /*Q_exc*/ + Word16 old_bwe_exc_fx[PIT16k_MAX * 2]; /*Q_exc*/ + + int16_t bwe_seed[2]; + // Word16 bwe_seed[2]; /*Q0*/ - int16_t bwe_seed[2]; - //Word16 bwe_seed[2]; /*Q0*/ - #ifndef IVAS_FLOAT_FIXED - float bwe_non_lin_prev_scale; + float bwe_non_lin_prev_scale; #endif - Word32 bwe_non_lin_prev_scale_fx; - + Word32 bwe_non_lin_prev_scale_fx; + #ifndef IVAS_FLOAT_FIXED - float old_bwe_exc_extended[NL_BUFF_OFFSET]; + float old_bwe_exc_extended[NL_BUFF_OFFSET]; #endif - Word16 old_bwe_exc_extended_fx[NL_BUFF_OFFSET]; - + Word16 old_bwe_exc_extended_fx[NL_BUFF_OFFSET]; #ifndef IVAS_FLOAT_FIXED float genSHBsynth_Hilbert_Mem[HILBERT_MEM_SIZE]; #endif - Word32 genSHBsynth_Hilbert_Mem_fx[HILBERT_MEM_SIZE]; + Word32 genSHBsynth_Hilbert_Mem_fx[HILBERT_MEM_SIZE]; #ifndef IVAS_FLOAT_FIXED float mem_genSHBexc_filt_down_shb[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; #endif - Word16 mem_genSHBexc_filt_down_shb_fx[2 * ALLPASSSECTIONS_STEEP + 1]; + Word16 mem_genSHBexc_filt_down_shb_fx[2 * ALLPASSSECTIONS_STEEP + 1]; #ifndef IVAS_FLOAT_FIXED - float mem_genSHBexc_filt_down_wb2[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; + float mem_genSHBexc_filt_down_wb2[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; #endif - Word16 mem_genSHBexc_filt_down_wb2_fx[2 * ALLPASSSECTIONS_STEEP + 1]; - + Word16 mem_genSHBexc_filt_down_wb2_fx[2 * ALLPASSSECTIONS_STEEP + 1]; + #ifndef IVAS_FLOAT_FIXED - float mem_genSHBexc_filt_down_wb3[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; + float mem_genSHBexc_filt_down_wb3[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; #endif - Word16 mem_genSHBexc_filt_down_wb3_fx[2 * ALLPASSSECTIONS_STEEP + 1]; - + Word16 mem_genSHBexc_filt_down_wb3_fx[2 * ALLPASSSECTIONS_STEEP + 1]; + #ifndef IVAS_FLOAT_FIXED - float genSHBsynth_state_lsyn_filt_shb_local[2 * ALLPASSSECTIONS_STEEP]; + float genSHBsynth_state_lsyn_filt_shb_local[2 * ALLPASSSECTIONS_STEEP]; #endif - Word16 genSHBsynth_state_lsyn_filt_shb_local_fx[2 * ALLPASSSECTIONS_STEEP]; - Word32 genSHBsynth_state_lsyn_filt_shb_local_fx_32[2 * ALLPASSSECTIONS_STEEP]; - + Word16 genSHBsynth_state_lsyn_filt_shb_local_fx[2 * ALLPASSSECTIONS_STEEP]; + Word32 genSHBsynth_state_lsyn_filt_shb_local_fx_32[2 * ALLPASSSECTIONS_STEEP]; + #ifndef IVAS_FLOAT_FIXED - float state_lsyn_filt_shb[2 * ALLPASSSECTIONS_STEEP]; + float state_lsyn_filt_shb[2 * ALLPASSSECTIONS_STEEP]; #endif - Word16 state_lsyn_filt_shb_fx[2 * ALLPASSSECTIONS_STEEP]; + Word16 state_lsyn_filt_shb_fx[2 * ALLPASSSECTIONS_STEEP]; Word32 state_lsyn_filt_shb_fx_32[2 * ALLPASSSECTIONS_STEEP]; - + #ifndef IVAS_FLOAT_FIXED - float state_lsyn_filt_dwn_shb[2 * ALLPASSSECTIONS_STEEP]; + float state_lsyn_filt_dwn_shb[2 * ALLPASSSECTIONS_STEEP]; #endif - Word16 state_lsyn_filt_dwn_shb_fx[2 * ALLPASSSECTIONS_STEEP]; + Word16 state_lsyn_filt_dwn_shb_fx[2 * ALLPASSSECTIONS_STEEP]; Word32 state_lsyn_filt_dwn_shb_fx_32[2 * ALLPASSSECTIONS_STEEP]; - + #ifndef IVAS_FLOAT_FIXED - float mem_resamp_HB[INTERP_3_1_MEM_LEN]; + float mem_resamp_HB[INTERP_3_1_MEM_LEN]; #endif - Word16 mem_resamp_HB_fx[INTERP_3_1_MEM_LEN]; - Word32 mem_resamp_HB_fx_32[INTERP_3_1_MEM_LEN]; - + Word16 mem_resamp_HB_fx[INTERP_3_1_MEM_LEN]; + Word32 mem_resamp_HB_fx_32[INTERP_3_1_MEM_LEN]; + #ifndef IVAS_FLOAT_FIXED - float mem_resamp_HB_32k[2 * ALLPASSSECTIONS_STEEP + 1]; + float mem_resamp_HB_32k[2 * ALLPASSSECTIONS_STEEP + 1]; #endif - Word16 mem_resamp_HB_32k_fx[2 * ALLPASSSECTIONS_STEEP + 1]; - Word32 mem_resamp_HB_32k_fx_32[2 * ALLPASSSECTIONS_STEEP + 1]; - - Word16 state_32and48k_WB_upsample_fx[2 * ALLPASSSECTIONS_STEEP]; /* !!! this memory in FLP is called mem_resamp_HB */ - + Word16 mem_resamp_HB_32k_fx[2 * ALLPASSSECTIONS_STEEP + 1]; + Word32 mem_resamp_HB_32k_fx_32[2 * ALLPASSSECTIONS_STEEP + 1]; + + Word16 state_32and48k_WB_upsample_fx[2 * ALLPASSSECTIONS_STEEP]; /* !!! this memory in FLP is called mem_resamp_HB */ + #ifndef IVAS_FLOAT_FIXED - float prev_pow_exc16kWhtnd; /* power of the LB excitation signal in the previous frame */ + float prev_pow_exc16kWhtnd; /* power of the LB excitation signal in the previous frame */ #endif - //Word16 prev_pow_exc16kWhtnd_fx; /* power of the LB excitation signal in the previous frame */ - Don't use this + // Word16 prev_pow_exc16kWhtnd_fx; /* power of the LB excitation signal in the previous frame */ - Don't use this Word32 prev_pow_exc16kWhtnd_fx32; /* power of the LB excitation signal in the previous frame */ #ifndef IVAS_FLOAT_FIXED - float prev_mix_factor; /* mixing factor in the previous frame */ + float prev_mix_factor; /* mixing factor in the previous frame */ #endif - Word16 prev_mix_factor_fx; /* mixing factor in the previous frame */ + Word16 prev_mix_factor_fx; /* mixing factor in the previous frame */ int16_t syn_dm_phase; - //Word16 syn_dm_phase; + // Word16 syn_dm_phase; #ifndef IVAS_FLOAT_FIXED float fbbwe_hpf_mem[4][4]; #endif - Word32 fbbwe_hpf_mem_fx[4][4]; - - Word16 fbbwe_hpf_mem_fx_Q[4]; - + Word32 fbbwe_hpf_mem_fx[4][4]; + + Word16 fbbwe_hpf_mem_fx_Q[4]; + #ifndef IVAS_FLOAT_FIXED - float prev_wb_bwe_frame_pow; + float prev_wb_bwe_frame_pow; #endif - Word32 prev_wb_bwe_frame_pow_fx; - + Word32 prev_wb_bwe_frame_pow_fx; + #ifndef IVAS_FLOAT_FIXED - float prev_swb_bwe_frame_pow; + float prev_swb_bwe_frame_pow; #endif - Word32 prev_swb_bwe_frame_pow_fx; - + Word32 prev_swb_bwe_frame_pow_fx; + #ifndef IVAS_FLOAT_FIXED - float prev_ener; + float prev_ener; #endif - Word32 prev_ener_fx; - + Word32 prev_ener_fx; + #ifndef IVAS_FLOAT_FIXED - float prev_GainShape; + float prev_GainShape; #endif - Word16 prev_GainShape_fx; - + Word16 prev_GainShape_fx; + #ifndef IVAS_FLOAT_FIXED - float fb_state_lpc_syn[LPC_SHB_ORDER]; + float fb_state_lpc_syn[LPC_SHB_ORDER]; #endif - Word16 fb_state_lpc_syn_fx[LPC_SHB_ORDER]; - - //Word16 prev_Q_bwe_exc_fb; - //Word16 prev_Qx; - //Word16 prev_Q_bwe_exc; - //Word16 prev_Q_synth; + Word16 fb_state_lpc_syn_fx[LPC_SHB_ORDER]; + + // Word16 prev_Q_bwe_exc_fb; + // Word16 prev_Qx; + // Word16 prev_Q_bwe_exc; + // Word16 prev_Q_synth; #ifndef IVAS_FLOAT_FIXED - float fb_tbe_demph; + float fb_tbe_demph; #endif - Word16 fb_tbe_demph_fx; - + Word16 fb_tbe_demph_fx; + #ifndef IVAS_FLOAT_FIXED - float prev_fbbwe_ratio; + float prev_fbbwe_ratio; #endif - Word16 prev_fbbwe_ratio_fx; + Word16 prev_fbbwe_ratio_fx; #ifndef IVAS_FLOAT_FIXED float tbe_demph; #endif - Word16 tbe_demph_fx; + Word16 tbe_demph_fx; #ifndef IVAS_FLOAT_FIXED float tbe_premph; #endif - Word16 tbe_premph_fx; - + Word16 tbe_premph_fx; + #ifndef IVAS_FLOAT_FIXED - float mem_stp_swb[LPC_SHB_ORDER]; + float mem_stp_swb[LPC_SHB_ORDER]; #endif - Word16 mem_stp_swb_fx[LPC_SHB_ORDER]; - + Word16 mem_stp_swb_fx[LPC_SHB_ORDER]; + #ifndef IVAS_FLOAT_FIXED - float *ptr_mem_stp_swb; + float *ptr_mem_stp_swb; #endif - Word16* ptr_mem_stp_swb_fx; - + Word16 *ptr_mem_stp_swb_fx; + #ifndef IVAS_FLOAT_FIXED - float gain_prec_swb; + float gain_prec_swb; #endif - Word16 gain_prec_swb_fx; - + Word16 gain_prec_swb_fx; + #ifndef IVAS_FLOAT_FIXED - float mem_zero_swb[LPC_SHB_ORDER]; + float mem_zero_swb[LPC_SHB_ORDER]; #endif - Word16 mem_zero_swb_fx[LPC_SHB_ORDER]; + Word16 mem_zero_swb_fx[LPC_SHB_ORDER]; #ifndef IVAS_FLOAT_FIXED float swb_lsp_prev_interp[LPC_SHB_ORDER]; #endif - Word16 swb_lsp_prev_interp_fx[LPC_SHB_ORDER]; - + Word16 swb_lsp_prev_interp_fx[LPC_SHB_ORDER]; + #ifndef IVAS_FLOAT_FIXED - float prev1_shb_ener_sf, prev2_shb_ener_sf, prev3_shb_ener_sf, prev_res_shb_gshape, prev_mixFactors; + float prev1_shb_ener_sf, prev2_shb_ener_sf, prev3_shb_ener_sf, prev_res_shb_gshape, prev_mixFactors; #endif - Word32 prev1_shb_ener_sf_fx, prev2_shb_ener_sf_fx, prev3_shb_ener_sf_fx; - - Word16 prev_res_shb_gshape_fx, prev_mixFactors_fx; - + Word32 prev1_shb_ener_sf_fx, prev2_shb_ener_sf_fx, prev3_shb_ener_sf_fx; + + Word16 prev_res_shb_gshape_fx, prev_mixFactors_fx; + #ifndef IVAS_FLOAT_FIXED - float tilt_mem; /* Formant factor adaptation tilt smoothing memory */ + float tilt_mem; /* Formant factor adaptation tilt smoothing memory */ #endif - Word16 tilt_mem_fx; - + Word16 tilt_mem_fx; + #ifndef IVAS_FLOAT_FIXED - float prev_lsf_diff[LPC_SHB_ORDER - 2]; + float prev_lsf_diff[LPC_SHB_ORDER - 2]; #endif - Word16 prev_lsf_diff_fx[LPC_SHB_ORDER - 2]; - + Word16 prev_lsf_diff_fx[LPC_SHB_ORDER - 2]; + #ifndef IVAS_FLOAT_FIXED - float prev_tilt_para; + float prev_tilt_para; #endif - Word16 prev_tilt_para_fx; - + Word16 prev_tilt_para_fx; + #ifndef IVAS_FLOAT_FIXED - float cur_sub_Aq[M + 1]; + float cur_sub_Aq[M + 1]; #endif - Word16 cur_sub_Aq_fx[M + 1]; + Word16 cur_sub_Aq_fx[M + 1]; /* quantized data */ int16_t lsf_idx[NUM_Q_LSF]; - //Word16 lsf_idx[NUM_Q_LSF]; - - int16_t m_idx; - //Word16 m_idx; - - int16_t grid_idx; - //Word16 grid_idx; - - int16_t idxSubGains; - //Word16 idxSubGains; - - int16_t idxFrameGain; - //Word16 idxFrameGain; - - int16_t idx_shb_fr_gain; - //Word16 idx_shb_fr_gain; - - int16_t idx_res_gs[NB_SUBFR16k]; - //Word16 idx_res_gs[NB_SUBFR16k]; - - int16_t idx_mixFac; - //Word16 idx_mixFac; + // Word16 lsf_idx[NUM_Q_LSF]; + + int16_t m_idx; + // Word16 m_idx; + + int16_t grid_idx; + // Word16 grid_idx; + + int16_t idxSubGains; + // Word16 idxSubGains; + + int16_t idxFrameGain; + // Word16 idxFrameGain; + + int16_t idx_shb_fr_gain; + // Word16 idx_shb_fr_gain; + + int16_t idx_res_gs[NB_SUBFR16k]; + // Word16 idx_res_gs[NB_SUBFR16k]; + + int16_t idx_mixFac; + // Word16 idx_mixFac; int16_t lsf_WB; - //Word16 lsf_WB; + // Word16 lsf_WB; - int16_t gFrame_WB; - //Word16 gFrame_WB; + int16_t gFrame_WB; + // Word16 gFrame_WB; int16_t idxGain; - //Word16 idxGain; - + // Word16 idxGain; + #ifndef IVAS_FLOAT_FIXED - float old_core_synth[L_FRAME16k]; + float old_core_synth[L_FRAME16k]; #endif - Word16 old_core_synth_fx[L_FRAME16k]; - + Word16 old_core_synth_fx[L_FRAME16k]; + #ifndef IVAS_FLOAT_FIXED - float old_tbe_synth[L_SHB_TRANSITION_LENGTH]; + float old_tbe_synth[L_SHB_TRANSITION_LENGTH]; #endif - Word16 old_tbe_synth_fx[L_SHB_TRANSITION_LENGTH]; - Word32 old_tbe_synth_fx_32[L_SHB_TRANSITION_LENGTH]; + Word16 old_tbe_synth_fx[L_SHB_TRANSITION_LENGTH]; + Word32 old_tbe_synth_fx_32[L_SHB_TRANSITION_LENGTH]; #ifndef IVAS_FLOAT_FIXED float int_3_over_2_tbemem_dec[INTERP_3_2_MEM_LEN]; #endif - Word16 int_3_over_2_tbemem_dec_fx[INTERP_3_2_MEM_LEN]; - Word32 int_3_over_2_tbemem_dec_fx_32[INTERP_3_2_MEM_LEN]; + Word16 int_3_over_2_tbemem_dec_fx[INTERP_3_2_MEM_LEN]; + Word32 int_3_over_2_tbemem_dec_fx_32[INTERP_3_2_MEM_LEN]; #ifndef IVAS_FLOAT_FIXED float old_hb_synth[L_FRAME48k]; #endif - Word16 old_hb_synth_fx[L_FRAME48k]; + Word16 old_hb_synth_fx[L_FRAME48k]; #ifndef IVAS_FLOAT_FIXED float tilt_swb_fec; /* FEC - SWB TBE TILT */ #endif - Word16 tilt_swb_fec_fx; /* FEC - SWB TBE TILT */ + Word16 tilt_swb_fec_fx; /* FEC - SWB TBE TILT */ - Word16 prev_hb_synth_fx_exp; + Word16 prev_hb_synth_fx_exp; } TD_BWE_DEC_DATA, *TD_BWE_DEC_HANDLE; @@ -1917,89 +1906,89 @@ typedef struct td_bwe_dec_structure typedef struct fd_bwe_dec_structure { - Word16 old_wtda_wb_fx_exp; - + Word16 old_wtda_wb_fx_exp; + #ifndef IVAS_FLOAT_FIXED - float old_wtda_swb[L_FRAME48k]; + float old_wtda_swb[L_FRAME48k]; #endif - Word16 L_old_wtda_swb_fx[L_FRAME48k]; - Word32 L_old_wtda_swb_fx32[L_FRAME48k]; - - Word16 old_wtda_swb_fx_exp; - + Word16 L_old_wtda_swb_fx[L_FRAME48k]; + Word32 L_old_wtda_swb_fx32[L_FRAME48k]; + + Word16 old_wtda_swb_fx_exp; + #ifndef IVAS_FLOAT_FIXED - float old_syn_12k8_16k[NS2SA( 16000, DELAY_FD_BWE_ENC_NS )]; + float old_syn_12k8_16k[NS2SA( 16000, DELAY_FD_BWE_ENC_NS )]; #endif - Word16 old_syn_12k8_16k_fx[NS2SA(16000, DELAY_FD_BWE_ENC_NS)]; /*Q_syn2-1*/ - + Word16 old_syn_12k8_16k_fx[NS2SA( 16000, DELAY_FD_BWE_ENC_NS )]; /*Q_syn2-1*/ + #ifndef IVAS_FLOAT_FIXED - float mem_deemph_old_syn; + float mem_deemph_old_syn; #endif - Word16 mem_deemph_old_syn_fx; - - int16_t prev_mode; - //Word16 prev_mode; - + Word16 mem_deemph_old_syn_fx; + + int16_t prev_mode; + // Word16 prev_mode; + #ifndef IVAS_FLOAT_FIXED - float prev_SWB_fenv[SWB_FENV]; + float prev_SWB_fenv[SWB_FENV]; #endif - //Word16 prev_SWB_fenv_fx[SWB_FENV]; // Don't use this. Use prev_SWB_fenv_fx present in Decoder_State - + // Word16 prev_SWB_fenv_fx[SWB_FENV]; // Don't use this. Use prev_SWB_fenv_fx present in Decoder_State + #ifndef IVAS_FLOAT_FIXED - float prev_Energy; + float prev_Energy; #endif - Word16 prev_Energy_fx; - + Word16 prev_Energy_fx; + #ifndef IVAS_FLOAT_FIXED - float prev_Energy_wb; + float prev_Energy_wb; #endif - Word32 prev_Energy_wb_fx; - - int16_t prev_L_swb_norm; - //Word16 prev_L_swb_norm; - - int16_t Seed; - //Word16 Seed; - - Word16 memExp1; - - int16_t prev_frica_flag; - //Word16 prev_frica_flag; - + Word32 prev_Energy_wb_fx; + + int16_t prev_L_swb_norm; + // Word16 prev_L_swb_norm; + + int16_t Seed; + // Word16 Seed; + + Word16 memExp1; + + int16_t prev_frica_flag; + // Word16 prev_frica_flag; + #ifndef IVAS_FLOAT_FIXED - float mem_imdct[L_FRAME48k]; + float mem_imdct[L_FRAME48k]; #endif - Word16 mem_imdct_fx[L_FRAME48k]; - - Word16 mem_imdct_exp_fx; - + Word16 mem_imdct_fx[L_FRAME48k]; + + Word16 mem_imdct_exp_fx; + #ifndef IVAS_FLOAT_FIXED - float prev_td_energy; + float prev_td_energy; #endif - Word16 prev_td_energy_fx; - + Word16 prev_td_energy_fx; + #ifndef IVAS_FLOAT_FIXED - float prev_weight; + float prev_weight; #endif - Word16 prev_weight_fx; - - int16_t prev_flag; - //Word16 prev_flag; - + Word16 prev_weight_fx; + + int16_t prev_flag; + // Word16 prev_flag; + #ifndef IVAS_FLOAT_FIXED - float last_wb_bwe_ener; + float last_wb_bwe_ener; #endif - //Word16 last_wb_bwe_ener_fx; // Don't use this. Use last_wb_bwe_ener_fx present in Decoder_State - + // Word16 last_wb_bwe_ener_fx; // Don't use this. Use last_wb_bwe_ener_fx present in Decoder_State + #ifndef IVAS_FLOAT_FIXED - float prev_fb_ener_adjust; + float prev_fb_ener_adjust; #endif - //Word16 prev_fb_ener_adjust_fx; // Don't use this. Use prev_fb_ener_adjust_fx present in Decoder_State + // Word16 prev_fb_ener_adjust_fx; // Don't use this. Use prev_fb_ener_adjust_fx present in Decoder_State - //Word16 prev_frame_pow_exp; - //Word16 prev_Qx; - //Word16 prev_Q_bwe_exc; - //Word16 prev_Q_synth; + // Word16 prev_frame_pow_exp; + // Word16 prev_Qx; + // Word16 prev_Q_bwe_exc; + // Word16 prev_Q_synth; } FD_BWE_DEC_DATA, *FD_BWE_DEC_HANDLE; @@ -2013,26 +2002,24 @@ typedef struct hr_swb_bwe_dec_structure { int16_t bwe_highrate_seed; - Word16 bwe_highrate_seed_fx; + Word16 bwe_highrate_seed_fx; #ifndef IVAS_FLOAT_FIXED - float t_audio_prev[2 * END_FREQ_BWE_FULL_FB / FRAMES_PER_SEC - NUM_NONTRANS_START_FREQ_COEF]; -#endif - Word16 t_audio_prev_fx[2 * END_FREQ_BWE_FULL_FB / 50 - NUM_NONTRANS_START_FREQ_COEF]; - - Word16 t_audio_prev_fx_exp[NUM_TIME_SWITCHING_BLOCKS]; - - int16_t old_is_transient_hr_bwe; - Word16 old_is_transient_hr_bwe_fx; - -#ifndef IVAS_FLOAT_FIXED - float mem_EnergyLT; + float t_audio_prev[2 * END_FREQ_BWE_FULL_FB / FRAMES_PER_SEC - NUM_NONTRANS_START_FREQ_COEF]; #endif - Word32 L_mem_EnergyLT_fx; + Word16 t_audio_prev_fx[2 * END_FREQ_BWE_FULL_FB / 50 - NUM_NONTRANS_START_FREQ_COEF]; + + Word16 t_audio_prev_fx_exp[NUM_TIME_SWITCHING_BLOCKS]; - Word16 mem_EnergyLT_fx_exp; + int16_t old_is_transient_hr_bwe; + Word16 old_is_transient_hr_bwe_fx; +#ifndef IVAS_FLOAT_FIXED + float mem_EnergyLT; +#endif + Word32 L_mem_EnergyLT_fx; + Word16 mem_EnergyLT_fx_exp; } HR_BWE_DEC_DATA, *HR_BWE_DEC_HANDLE; @@ -2063,94 +2050,94 @@ typedef struct amrwb_io_dec_structure #ifndef IVAS_FLOAT_FIXED float past_qua_en[GAIN_PRED_ORDER]; /* gain quantization memory (used also in AMR-WB IO mode) */ #endif - Word16 past_qua_en_fx[GAIN_PRED_ORDER]; /* gain quantization memory (used also in AMR-WB IO mode) */ + Word16 past_qua_en_fx[GAIN_PRED_ORDER]; /* gain quantization memory (used also in AMR-WB IO mode) */ #ifndef IVAS_FLOAT_FIXED - float prev_r; /* HF BWE - previous sub-frame gain */ + float prev_r; /* HF BWE - previous sub-frame gain */ #endif - Word16 prev_r_fx; /* HF BWE - previous sub-frame gain */ + Word16 prev_r_fx; /* HF BWE - previous sub-frame gain */ #ifndef IVAS_FLOAT_FIXED - float fmerit_w_sm; /* HF BWE - fmerit parameter memory */ + float fmerit_w_sm; /* HF BWE - fmerit parameter memory */ #endif - Word16 fmerit_w_sm_fx; /* HF BWE - fmerit parameter memory */ - - int16_t frame_count; /* HF BWE - frame count */ - Word16 frame_count_fx; /* HF BWE - frame count */ -#ifndef IVAS_FLOAT_FIXED - float ne_min; /* HF BWE - minimum Noise gate - short-term energy */ -#endif - Word16 ne_min_fx; /* HF BWE - minimum Noise gate - short-term energy */ + Word16 fmerit_w_sm_fx; /* HF BWE - fmerit parameter memory */ + int16_t frame_count; /* HF BWE - frame count */ + Word16 frame_count_fx; /* HF BWE - frame count */ #ifndef IVAS_FLOAT_FIXED - float fmerit_m_sm; /* HF BWE - memory of fmerit_m param */ -#endif - Word16 fmerit_m_sm_fx; /* HF BWE - memory of fmerit_m param */ + float ne_min; /* HF BWE - minimum Noise gate - short-term energy */ +#endif + Word16 ne_min_fx; /* HF BWE - minimum Noise gate - short-term energy */ #ifndef IVAS_FLOAT_FIXED - float voice_fac_amr_wb_hf_float; /* HF BWE - voice factor */ + float fmerit_m_sm; /* HF BWE - memory of fmerit_m param */ #endif - Word16 voice_fac_amr_wb_hf; /* HF BWE - voice factor */ + Word16 fmerit_m_sm_fx; /* HF BWE - memory of fmerit_m param */ #ifndef IVAS_FLOAT_FIXED - float unvoicing; /* HF BWE - unvoiced parameter */ -#endif - Word16 unvoicing_fx; /* HF BWE - unvoiced parameter */ + float voice_fac_amr_wb_hf_float; /* HF BWE - voice factor */ +#endif + Word16 voice_fac_amr_wb_hf; /* HF BWE - voice factor */ #ifndef IVAS_FLOAT_FIXED - float unvoicing_sm; /* HF BWE - smoothed unvoiced parameter */ -#endif - Word16 unvoicing_sm_fx; /* HF BWE - smoothed unvoiced parameter */ + float unvoicing; /* HF BWE - unvoiced parameter */ +#endif + Word16 unvoicing_fx; /* HF BWE - unvoiced parameter */ + +#ifndef IVAS_FLOAT_FIXED + float unvoicing_sm; /* HF BWE - smoothed unvoiced parameter */ +#endif + Word16 unvoicing_sm_fx; /* HF BWE - smoothed unvoiced parameter */ + + int16_t unvoicing_flag; /* HF BWE - unvoiced flag */ + Word16 unvoicing_flag_fx; /* HF BWE - unvoiced flag */ - int16_t unvoicing_flag; /* HF BWE - unvoiced flag */ - Word16 unvoicing_flag_fx; /* HF BWE - unvoiced flag */ - - int16_t voicing_flag; /* HF BWE - voiced flag */ - Word16 voicing_flag_fx; /* HF BWE - voiced flag */ - - int16_t start_band_old; /* HF BWE - previous start point for copying frequency band */ - Word16 start_band_old_fx; /* HF BWE - previous start point for copying frequency band */ + int16_t voicing_flag; /* HF BWE - voiced flag */ + Word16 voicing_flag_fx; /* HF BWE - voiced flag */ + + int16_t start_band_old; /* HF BWE - previous start point for copying frequency band */ + Word16 start_band_old_fx; /* HF BWE - previous start point for copying frequency band */ #ifndef IVAS_FLOAT_FIXED - float OptCrit_old; /* HF BWE - previous criterion value for deciding the start point */ -#endif - Word32 OptCrit_old_fx; /* HF BWE - previous criterion value for deciding the start point */ + float OptCrit_old; /* HF BWE - previous criterion value for deciding the start point */ +#endif + Word32 OptCrit_old_fx; /* HF BWE - previous criterion value for deciding the start point */ /* Improvement of unvoiced and audio signals in AMR-WB IO mode */ - int16_t UV_cnt; /* number of consecutives frames classified as UV */ - Word16 UV_cnt_fx; /* number of consecutives frames classified as UV */ + int16_t UV_cnt; /* number of consecutives frames classified as UV */ + Word16 UV_cnt_fx; /* number of consecutives frames classified as UV */ #ifndef IVAS_FLOAT_FIXED - float LT_UV_cnt; /* long-term consecutives frames classified as UV */ + float LT_UV_cnt; /* long-term consecutives frames classified as UV */ #endif - Word16 LT_UV_cnt_fx; /* long-term consecutives frames classified as UV */ + Word16 LT_UV_cnt_fx; /* long-term consecutives frames classified as UV */ #ifndef IVAS_FLOAT_FIXED - float Last_ener; /* last_energy frame */ -#endif - Word16 Last_ener_fx; /* last_energy frame */ + float Last_ener; /* last_energy frame */ +#endif + Word16 Last_ener_fx; /* last_energy frame */ #ifndef IVAS_FLOAT_FIXED - float lt_diff_etot[MAX_LT]; /* stability estimation - long-term total energy variation */ -#endif - Word16 lt_diff_etot_fx[MAX_LT]; /* stability estimation - long-term total energy variation */ + float lt_diff_etot[MAX_LT]; /* stability estimation - long-term total energy variation */ +#endif + Word16 lt_diff_etot_fx[MAX_LT]; /* stability estimation - long-term total energy variation */ #ifndef IVAS_FLOAT_FIXED - float old_Aq[NB_SUBFR * ( M + 1 )]; /* old LPC filter coefficient */ -#endif - Word16 old_Aq_fx[68]; /* old LPC filter coefficient */ + float old_Aq[NB_SUBFR * ( M + 1 )]; /* old LPC filter coefficient */ +#endif + Word16 old_Aq_fx[68]; /* old LPC filter coefficient */ #ifndef IVAS_FLOAT_FIXED - float lt_voice_fac; /* average voice factor over 4 sub-frames */ + float lt_voice_fac; /* average voice factor over 4 sub-frames */ #endif - Word16 lt_voice_fac_fx; /* average voice factor over 4 sub-frames */ + Word16 lt_voice_fac_fx; /* average voice factor over 4 sub-frames */ } AMRWB_IO_DEC_DATA, *AMRWB_IO_DEC_HANDLE; struct dispMem_fx { - Word16 prev_state; /*Q0 */ - Word32 prev_gain_code; /*Q16 */ - Word16 prev_gain_pit[6]; /*Q14 */ + Word16 prev_state; /*Q0 */ + Word32 prev_gain_code; /*Q16 */ + Word16 prev_gain_pit[6]; /*Q14 */ }; /*----------------------------------------------------------------------------------* @@ -2166,371 +2153,370 @@ typedef struct Decoder_State * Common parameters *----------------------------------------------------------------------------------*/ - int16_t idchan; /* channel ID (audio channel number) */ - int16_t element_mode; /* element mode */ + int16_t idchan; /* channel ID (audio channel number) */ + int16_t element_mode; /* element mode */ int32_t element_brate; /* element bitrate */ int16_t codec_mode; /* Mode 1 or 2 */ int16_t mdct_sw_enable; /* MDCT switching enable flag */ int16_t mdct_sw; /* MDCT switching indicator */ int16_t last_codec_mode; /* last used codec mode */ - uint16_t *bit_stream; /* pointer to bitstream buffer */ - //UWord16 *bit_stream_fx; - - int16_t next_bit_pos; /* position of the next bit to be read from the bitstream */ - //Word16 next_bit_pos; /* position of the next bit to be read from the bitstream */ - - Word16 bitstreamformat; /* Bitstream format flag (G.192/MIME/VOIP_G192_RTP/VOIP_RTPDUMP) */ - Word16 sdp_hf_only; /* RTP payload format parameter: only Header-Full format without zero padding for size collision avoidance */ - Word16 amrwb_rfc4867_flag; /* MIME from rfc4867 is used */ - Word16 total_num_bits; /* == st->total_brate / 50 */ - - int16_t BER_detect; /* flag to signal detected bit error in the bitstream */ - - int32_t output_Fs; /* output sampling rate */ - //Word32 output_Fs_fx; /* output sampling rate Q0*/ - - Word16 output_frame_fx; /* Output frame length Q0*/ - - int32_t total_brate; /* total bitrate in kbps of the codec */ - //Word32 total_brate_fx; /* total bitrate in kbps of the codec Q0*/ - - int32_t last_total_brate; /* last total bitrate in kbps of the codec */ - //Word32 last_total_brate_fx; /* last total bitrate in kbps of the codec Q0*/ - - int32_t last_total_brate_ber; /* last total bitrate in kbps of the codec - used only when first frame is lost and BER is detected afterwards */ - //Word32 last_total_brate_ber_fx; /* last total bitrate in kbps of the codec - used only when first frame is lost and BER is detected afterwards */ - - int16_t bits_frame_nominal; /* avg bits per frame on active frame */ - int32_t last_bits_frame_nominal; /* last avg bits per frame on active frame */ - int16_t flag_ACELP16k; /* flag indicating use of ACELP core at 16kHz internal sampling rate */ - int16_t bits_frame_channel; /* bits frame channel */ - int16_t side_bits_frame_channel; /* bits frame channel */ - - int16_t core; /* core (ACELP_CORE, TCX_20_CORE, TCX_10_CORE, HQ_CORE, AMR_WB_CORE) */ - //Word16 core_fx; /* core (ACELP_CORE, TCX_20_CORE, TCX_10_CORE, HQ_CORE, AMR_WB_CORE) */ - - int16_t coder_type; /* coder type */ - int16_t transform_type[2]; /* TCX20/10/5 mode in each subframe */ - - int32_t core_brate; /* core bitrate */ - //Word32 core_brate_fx; /* core bitrate */ - - int32_t last_core_brate; /* previous frame core bitrate */ - //Word32 last_core_brate_fx; /* previous frame core bitrate Q0*/ - - int16_t extl; /* extension layer */ - //Word16 extl_fx; /* extension layer Q0*/ - - int16_t extl_orig; /* extension layer */ - - int16_t last_extl; /* previous extension layer */ - //Word16 last_extl_fx; /* previous extension layer Q0*/ - - int32_t extl_brate; /* extension layer bitrate */ - //Word32 extl_brate_fx; /* extension layer bitrate */ - - int32_t extl_brate_orig; /* extension layer bitrate */ - - int16_t L_frame; /* ACELP core internal frame length */ - //Word16 L_frame_fx; /* ACELP core internal frame length */ - - int16_t bwidth; /* encoded signal bandwidth */ - //Word16 bwidth_fx; /* encoded signal bandwidth */ - - int16_t Opt_AMR_WB; /* flag indicating AMR-WB IO mode */ - //Word16 Opt_AMR_WB_fx; /* flag indicating AMR-WB IO mode Q0*/ - - Word16 Opt_VOIP_fx; /* flag indicating VOIP mode with JBM */ - - int16_t ini_frame; /* initialization frames counter */ - //Word16 ini_frame_fx; /* initialization frames counter */ - - int16_t prev_coder_type; /* coding type of last frame */ + uint16_t *bit_stream; /* pointer to bitstream buffer */ + // UWord16 *bit_stream_fx; + + int16_t next_bit_pos; /* position of the next bit to be read from the bitstream */ + // Word16 next_bit_pos; /* position of the next bit to be read from the bitstream */ + + Word16 bitstreamformat; /* Bitstream format flag (G.192/MIME/VOIP_G192_RTP/VOIP_RTPDUMP) */ + Word16 sdp_hf_only; /* RTP payload format parameter: only Header-Full format without zero padding for size collision avoidance */ + Word16 amrwb_rfc4867_flag; /* MIME from rfc4867 is used */ + Word16 total_num_bits; /* == st->total_brate / 50 */ + + int16_t BER_detect; /* flag to signal detected bit error in the bitstream */ + + int32_t output_Fs; /* output sampling rate */ + // Word32 output_Fs_fx; /* output sampling rate Q0*/ + + Word16 output_frame_fx; /* Output frame length Q0*/ + + int32_t total_brate; /* total bitrate in kbps of the codec */ + // Word32 total_brate_fx; /* total bitrate in kbps of the codec Q0*/ + + int32_t last_total_brate; /* last total bitrate in kbps of the codec */ + // Word32 last_total_brate_fx; /* last total bitrate in kbps of the codec Q0*/ + + int32_t last_total_brate_ber; /* last total bitrate in kbps of the codec - used only when first frame is lost and BER is detected afterwards */ + // Word32 last_total_brate_ber_fx; /* last total bitrate in kbps of the codec - used only when first frame is lost and BER is detected afterwards */ + + int16_t bits_frame_nominal; /* avg bits per frame on active frame */ + int32_t last_bits_frame_nominal; /* last avg bits per frame on active frame */ + int16_t flag_ACELP16k; /* flag indicating use of ACELP core at 16kHz internal sampling rate */ + int16_t bits_frame_channel; /* bits frame channel */ + int16_t side_bits_frame_channel; /* bits frame channel */ + + int16_t core; /* core (ACELP_CORE, TCX_20_CORE, TCX_10_CORE, HQ_CORE, AMR_WB_CORE) */ + // Word16 core_fx; /* core (ACELP_CORE, TCX_20_CORE, TCX_10_CORE, HQ_CORE, AMR_WB_CORE) */ + + int16_t coder_type; /* coder type */ + int16_t transform_type[2]; /* TCX20/10/5 mode in each subframe */ + + int32_t core_brate; /* core bitrate */ + // Word32 core_brate_fx; /* core bitrate */ + + int32_t last_core_brate; /* previous frame core bitrate */ + // Word32 last_core_brate_fx; /* previous frame core bitrate Q0*/ + + int16_t extl; /* extension layer */ + // Word16 extl_fx; /* extension layer Q0*/ + + int16_t extl_orig; /* extension layer */ + + int16_t last_extl; /* previous extension layer */ + // Word16 last_extl_fx; /* previous extension layer Q0*/ + + int32_t extl_brate; /* extension layer bitrate */ + // Word32 extl_brate_fx; /* extension layer bitrate */ + + int32_t extl_brate_orig; /* extension layer bitrate */ + + int16_t L_frame; /* ACELP core internal frame length */ + // Word16 L_frame_fx; /* ACELP core internal frame length */ + + int16_t bwidth; /* encoded signal bandwidth */ + // Word16 bwidth_fx; /* encoded signal bandwidth */ + + int16_t Opt_AMR_WB; /* flag indicating AMR-WB IO mode */ + // Word16 Opt_AMR_WB_fx; /* flag indicating AMR-WB IO mode Q0*/ + + Word16 Opt_VOIP_fx; /* flag indicating VOIP mode with JBM */ + + int16_t ini_frame; /* initialization frames counter */ + // Word16 ini_frame_fx; /* initialization frames counter */ + + int16_t prev_coder_type; /* coding type of last frame */ int16_t low_rate_mode; /* low-rate mode flag */ int16_t last_low_rate_mode; /* previous frame low-rate mode flag */ int16_t inactive_coder_type_flag; /* inactive coder type flag (0 = AVQ / 1 = GSC) */ - Word16 CNG_fx; /* RXDTX handler: CNG=1, nonCNG=0 */ - Word16 prev_ft_speech_fx; /* RXDTX handler: previous frametype flag for G.192 format AMRWB SID_FIRST detection */ + Word16 CNG_fx; /* RXDTX handler: CNG=1, nonCNG=0 */ + Word16 prev_ft_speech_fx; /* RXDTX handler: previous frametype flag for G.192 format AMRWB SID_FIRST detection */ - //note_ : produces failures if added below their float parts - Word16 old_exc_fx[L_EXC_MEM_DEC]; /* old excitation Q_exc*/ - Word16 lsf_old_fx[M]; /* old LSF vector at the end of the frame Q2.56*/ - Word16 lsp_old_fx[M]; /* old LSP vector at the end of the frame Q15*/ + // note_ : produces failures if added below their float parts + Word16 old_exc_fx[L_EXC_MEM_DEC]; /* old excitation Q_exc*/ + Word16 lsf_old_fx[M]; /* old LSF vector at the end of the frame Q2.56*/ + Word16 lsp_old_fx[M]; /* old LSP vector at the end of the frame Q15*/ /*----------------------------------------------------------------------------------* * ACELP core parameters *----------------------------------------------------------------------------------*/ - - - Word16 tilt_code_fx; /* tilt of code Q15*/ - + + Word16 tilt_code_fx; /* tilt of code Q15*/ + #ifndef IVAS_FLOAT_FIXED float old_exc[L_EXC_MEM_DEC]; /* old excitation */ - float lsp_old[M]; /* old LSP vector at the end of the frame */ - float lsf_old[M]; /* old LSF vector at the end of the frame */ - - float tilt_code; /* tilt of code */ - - float mem_syn1[M]; /* synthesis filter memory (for core switching and FD BWE) */ - float mem_syn2[M]; /* synthesis filter memory */ - float mem_syn3[M]; - - float mem_AR[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean) */ - float mem_MA[M]; /* MA memory of LSF quantizer (past quantized residual) */ - float mem_deemph; /* deemphasis filter memory */ -#endif // 0 - - Word16 mem_syn1_fx[M]; /* synthesis filter memory (for core switching and FD BWE) */ - Word16 mem_syn2_fx[M]; /* synthesis filter memory Q_syn*/ - Word16 mem_syn3_fx[M]; - - Word16 mem_deemph_fx; /* deemphasis filter memory Q_syn*/ - - Word16 mem_AR_fx[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean)(Qx2.56) */ - - Word16 mem_MA_fx[M]; /* MA memory of LSF quantizer (past quantized residual)(Qx2.56)*/ - - Word16 stab_fac_fx; /* LSF stability factor Q15*/ - - Word16 stab_fac_smooth_fx; /* low-pass filtered stability factor Q15*/ - - int16_t last_coder_type; /* previous coder type */ - //Word16 last_coder_type; /* previous coder type Q0*/ - - Word16 agc_mem_fx[2]; /* memory of AGC for saturation control Q0*/ - - int16_t mid_lsf_int; - //Word16 mid_lsf_int; - - int16_t safety_net; - //Word16 safety_net; - -#ifndef IVAS_FLOAT_FIXED - float stab_fac; /* LSF stability factor */ - float stab_fac_smooth; /* low-pass filtered stability factor */ - float agc_mem2[2]; /* memory of AGC for saturation control */ - float stab_fac_smooth_lt; + float lsp_old[M]; /* old LSP vector at the end of the frame */ + float lsf_old[M]; /* old LSF vector at the end of the frame */ + + float tilt_code; /* tilt of code */ + + float mem_syn1[M]; /* synthesis filter memory (for core switching and FD BWE) */ + float mem_syn2[M]; /* synthesis filter memory */ + float mem_syn3[M]; + + float mem_AR[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean) */ + float mem_MA[M]; /* MA memory of LSF quantizer (past quantized residual) */ + float mem_deemph; /* deemphasis filter memory */ +#endif // 0 + + Word16 mem_syn1_fx[M]; /* synthesis filter memory (for core switching and FD BWE) */ + Word16 mem_syn2_fx[M]; /* synthesis filter memory Q_syn*/ + Word16 mem_syn3_fx[M]; + + Word16 mem_deemph_fx; /* deemphasis filter memory Q_syn*/ + + Word16 mem_AR_fx[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean)(Qx2.56) */ + + Word16 mem_MA_fx[M]; /* MA memory of LSF quantizer (past quantized residual)(Qx2.56)*/ + + Word16 stab_fac_fx; /* LSF stability factor Q15*/ + + Word16 stab_fac_smooth_fx; /* low-pass filtered stability factor Q15*/ + + int16_t last_coder_type; /* previous coder type */ + // Word16 last_coder_type; /* previous coder type Q0*/ + + Word16 agc_mem_fx[2]; /* memory of AGC for saturation control Q0*/ + + int16_t mid_lsf_int; + // Word16 mid_lsf_int; + + int16_t safety_net; + // Word16 safety_net; + +#ifndef IVAS_FLOAT_FIXED + float stab_fac; /* LSF stability factor */ + float stab_fac_smooth; /* low-pass filtered stability factor */ + float agc_mem2[2]; /* memory of AGC for saturation control */ + float stab_fac_smooth_lt; float log_energy_old; float log_energy_diff_lt; #endif #ifdef IVAS_FLOAT_FIXED - Word32 log_energy_diff_lt_fx;/*In range of word16*//*Q-15*/ - Word16 stab_fac_smooth_lt_fx;/*In range of word16*//*Q-15*/ + Word32 log_energy_diff_lt_fx; /*In range of word16*/ /*Q-15*/ + Word16 stab_fac_smooth_lt_fx; /*In range of word16*/ /*Q-15*/ Word32 log_energy_old_fx; #endif - Word32 offset_scale1_fx[MAX_NO_MODES + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure 1st 8-dim subvector*/ - Word32 offset_scale2_fx[MAX_NO_MODES + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure 2nd 8-dim subvector*/ - Word32 offset_scale1_p_fx[MAX_NO_MODES_p + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure, pred. case, 1st 8-dim subvector*/ - Word32 offset_scale2_p_fx[MAX_NO_MODES_p + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure, pred. case, 2nd 8-dim subvector*/ - Word16 no_scales_fx[MAX_NO_MODES][2]; /* LSF LVQ structure Q0*/ - Word16 no_scales_p_fx[MAX_NO_MODES_p][2]; /* LSF LVQ structure Q0*/ - Word32 L_mem_hp_out_fx[5]; /* hp filter memory for synthesis */ + Word32 offset_scale1_fx[MAX_NO_MODES + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure 1st 8-dim subvector*/ + Word32 offset_scale2_fx[MAX_NO_MODES + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure 2nd 8-dim subvector*/ + Word32 offset_scale1_p_fx[MAX_NO_MODES_p + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure, pred. case, 1st 8-dim subvector*/ + Word32 offset_scale2_p_fx[MAX_NO_MODES_p + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure, pred. case, 2nd 8-dim subvector*/ + Word16 no_scales_fx[MAX_NO_MODES][2]; /* LSF LVQ structure Q0*/ + Word16 no_scales_p_fx[MAX_NO_MODES_p][2]; /* LSF LVQ structure Q0*/ + Word32 L_mem_hp_out_fx[5]; /* hp filter memory for synthesis */ + + + int16_t GSC_noisy_speech; /* AC mode (GSC) - flag to indicate GSC on SWB noisy speech */ + // Word16 GSC_noisy_speech; /* AC mode (GSC) - flag to indicate GSC osn SWB noisy speech */ + int16_t GSC_IVAS_mode; /* AC mode (GSC) - GSC IVAS mode */ - int16_t GSC_noisy_speech; /* AC mode (GSC) - flag to indicate GSC on SWB noisy speech */ - //Word16 GSC_noisy_speech; /* AC mode (GSC) - flag to indicate GSC osn SWB noisy speech */ - - int16_t GSC_IVAS_mode; /* AC mode (GSC) - GSC IVAS mode */ - - int16_t Last_GSC_noisy_speech_flag; /* AC mode (GSC) - mem of the past flag to indicate GSC osn SWB noisy speech */ - //Word16 Last_GSC_noisy_speech_flag; /* AC mode (GSC) - mem of the past flag to indicate GSC osn SWB noisy speech */ - - GSC_DEC_HANDLE hGSCDec; + int16_t Last_GSC_noisy_speech_flag; /* AC mode (GSC) - mem of the past flag to indicate GSC osn SWB noisy speech */ + // Word16 Last_GSC_noisy_speech_flag; /* AC mode (GSC) - mem of the past flag to indicate GSC osn SWB noisy speech */ + + GSC_DEC_HANDLE hGSCDec; + + + Word32 gc_threshold_fx; /* Noise enhancer - threshold for gain_code Q16*/ - - Word32 gc_threshold_fx; /* Noise enhancer - threshold for gain_code Q16*/ - #ifndef IVAS_FLOAT_FIXED - float gc_threshold; /* Noise enhancer - threshold for gain_code */ - float dispMem[8]; /* Noise enhancer - phase dispersion algorithm memory */ + float gc_threshold; /* Noise enhancer - threshold for gain_code */ + float dispMem[8]; /* Noise enhancer - phase dispersion algorithm memory */ #endif - struct dispMem_fx dm_fx; /* Noise enhancer - phase dispersion algorithm memory */ + struct dispMem_fx dm_fx; /* Noise enhancer - phase dispersion algorithm memory */ ZERO_BWE_DEC_HANDLE hBWE_zero; /* HF (6-7kHz) BWE */ - int16_t unv_cnt; /* Stationary noise UV modification - unvoiced frame counter */ - //Word16 unv_cnt; /* Stationary noise UV modification - unvoiced frame counter Q0*/ - - int16_t uv_count; /* Stationary noise UV modification - unvoiced counter */ - //Word16 uv_count; /* Stationary noise UV modification - unvoiced counter Q0*/ - - int16_t act_count; /* Stationary noise UV modification - activation counter */ - //Word16 act_count; /* Stationary noise UV modification - activation counter Q0*/ - - Word32 ge_sm_fx; /* Stationary noise UV modification - smoothed excitation gain Q(GE_SHIFT)*/ - - Word16 lspold_s_fx[M]; /* Stationary noise UV modification - old LSP vector Q15*/ - - int16_t noimix_seed; /* Stationary noise UV modification - mixture seed */ - //Word16 noimix_seed; /* Stationary noise UV modification - mixture seed Q0*/ - - Word16 min_alpha_fx; /* Stationary noise UV modification - minimum alpha Q15*/ - - Word16 Q_stat_noise; /* Q of Exc_pe */ - -#ifndef IVAS_FLOAT_FIXED - float min_alpha; /* Stationary noise UV modification - minimum alpha */ - float lspold_s[M]; /* Stationary noise UV modification - old LSP vector */ - float ge_sm; /* Stationary noise UV modification - smoothed excitation gain */ - float exc_pe; /* Stationary noise UV modification - memory of the preemphasis filter */ -#endif // 0 - Word16 exc_pe_fx; /* Stationary noise UV modification - scale (Q_stat_noise) */ - - Word16 Q_stat_noise_ge; /* Q of ge_sm_fx */ - - - int16_t bfi; /* FEC - bad frame indicator */ - //Word16 bfi_fx; /* FEC - bad frame indicator */ - - int16_t prev_bfi; /* FEC - previous bad frame indicator */ - //Word16 prev_bfi_fx; /* FEC - previous bad frame indicator Q0*/ - - int16_t prev_old_bfi; /* FEC - previous old bad frame indicator */ - - int16_t seed; /* FEC - seed for random generator for excitation */ - //Word16 seed_fx; /* FEC - seed for random generator for excitation Q0*/ - -#ifndef IVAS_FLOAT_FIXED - float lp_ener_bfi; /* FEC - long-term active-signal average energy */ - float lp_ener; /* FEC - low-pass filtered energy */ -#endif - - int16_t last_good; /* FEC - clas of last good received */ - - Word16 lp_gainp_fx; /* FEC - low-pass filtered pitch gain Q14 */ - - Word16 lp_gainc_fx; /* FEC - low-pass filtered code gain Q3*/ - - Word32 lp_ener_fx; /* FEC - low-pass filtered energy Q6*/ - - Word32 enr_old_fx; /* FEC - energy of the concealed frame Q0*/ - -#ifndef IVAS_FLOAT_FIXED - float lp_gainp; /* FEC - low-pass filtered pitch gain */ - float lp_gainc; /* FEC - low-pass filtered code gain */ - float enr_old; /* FEC - energy of the concealed frame */ - float bfi_pitch; /* FEC - pitch for FEC */ - float old_pitch_buf[2 * NB_SUBFR16k + 2]; /* FEC - buffer of old subframe pitch values */ -#endif // #ifndef IVAS_FLOAT_FIXED - Word16 bfi_pitch_fx; /* FEC - pitch for FEC */ - - int16_t bfi_pitch_frame; /* FEC - frame length when pitch for FEC is saved */ - //Word16 bfi_pitch_frame_fx; /*FEC - frame length when pitch for FEC is saved Q0*/ - - Word16 old_pitch_buf_16_fx[2 * NB_SUBFR16k + 2]; /* FEC - buffer of old subframe pitch values 15Q16 */ - Word32 old_pitch_buf_fx[2 * NB_SUBFR16k + 2]; /* FEC - buffer of old subframe pitch values 15Q16 */ - - int16_t upd_cnt; /* FEC - counter of frames since last update */ - //Word16 upd_cnt_fx; /* FEC - counter of frames since last update Q0*/ - - int16_t scaling_flag; /* FEC - flag to indicate energy control of syn */ - - Word32 lp_ener_FEC_av; /* FEC - averaged voiced signal energy Q0 */ - - Word32 lp_ener_FEC_max; /* FEC - averaged voiced signal energy Q0 */ - - Word16 old_enr_LP; /* FEC - LP filter gain Q5*/ - - int16_t prev_nbLostCmpt; /* FEC - compt for number of consecutive lost frame at the previous frame*/ - int16_t mode_lvq; /* FEC - index for LSF mean vector*/ - -#ifndef IVAS_FLOAT_FIXED - float old_enr_LP_float; /* FEC - LP filter gain */ - float lp_ener_FEC_av_float; /* FEC - averaged voiced signal energy */ - float lp_ener_FEC_max_float; /* FEC - averaged voiced signal energy */ - float lsfoldbfi0[M]; /* FEC - LSF vector of the previous frame */ - float lsfoldbfi1[M]; /* FEC - LSF vector of the past previous frame */ - float lsf_adaptive_mean[M]; /* FEC - adaptive mean LSF vector for FEC */ -#endif - - Word16 lsfoldbfi0_fx[M]; /* FEC - LSF vector of the previous frame (Qx2.56)*/ - - Word16 lsfoldbfi1_fx[M]; /* FEC - LSF vector of the past previous frame (Qx2.56) */ - - Word16 lsf_adaptive_mean_fx[M]; /* FEC - adaptive mean LSF vector for FEC (Qx2.56)*/ - - int16_t decision_hyst; /* FEC - hysteresis of the music/speech decision */ - //Word16 decision_hyst_fx; /* FEC - hysteresis of the music/speech decision Q0*/ - - //Word16 last_good; /* FEC - clas of last good received Q0*/ - Word16 lp_ener_FER_fx; /* FEC - long-term active-signal average energy Q8*/ - - - WI_DEC_HANDLE hWIDec; - - int16_t relax_prev_lsf_interp; - //Word16 relax_prev_lsf_interp; - -#ifndef IVAS_FLOAT_FIXED - float mem_syn_clas_estim[L_SYN_MEM_CLAS_ESTIM]; /* FEC - memory of the synthesis signal for frame class estimation */ -#endif // #ifndef IVAS_FLOAT_FIXED - Word16 mem_syn_clas_estim_fx[L_SYN_MEM_CLAS_ESTIM]; /* FEC - memory of the synthesis signal for frame class estimation */ + int16_t unv_cnt; /* Stationary noise UV modification - unvoiced frame counter */ + // Word16 unv_cnt; /* Stationary noise UV modification - unvoiced frame counter Q0*/ + + int16_t uv_count; /* Stationary noise UV modification - unvoiced counter */ + // Word16 uv_count; /* Stationary noise UV modification - unvoiced counter Q0*/ + + int16_t act_count; /* Stationary noise UV modification - activation counter */ + // Word16 act_count; /* Stationary noise UV modification - activation counter Q0*/ + + Word32 ge_sm_fx; /* Stationary noise UV modification - smoothed excitation gain Q(GE_SHIFT)*/ + + Word16 lspold_s_fx[M]; /* Stationary noise UV modification - old LSP vector Q15*/ + + int16_t noimix_seed; /* Stationary noise UV modification - mixture seed */ + // Word16 noimix_seed; /* Stationary noise UV modification - mixture seed Q0*/ + + Word16 min_alpha_fx; /* Stationary noise UV modification - minimum alpha Q15*/ + + Word16 Q_stat_noise; /* Q of Exc_pe */ + +#ifndef IVAS_FLOAT_FIXED + float min_alpha; /* Stationary noise UV modification - minimum alpha */ + float lspold_s[M]; /* Stationary noise UV modification - old LSP vector */ + float ge_sm; /* Stationary noise UV modification - smoothed excitation gain */ + float exc_pe; /* Stationary noise UV modification - memory of the preemphasis filter */ +#endif // 0 + Word16 exc_pe_fx; /* Stationary noise UV modification - scale (Q_stat_noise) */ + + Word16 Q_stat_noise_ge; /* Q of ge_sm_fx */ - int16_t bpf_off; /* Bass post-filter - do not use BPF when this flag is set to 1 */ - //Word16 bpf_off_fx; /* Bass post-filter - do not use BPF when this flag is set to 1 Q0*/ - - BPF_DEC_HANDLE hBPF; /* Bass post-filter handle */ - HANDLE_CLDFB_FILTER_BANK cldfbAna; /* main analysis filter bank handle */ - //HANDLE_CLDFB_FILTER_BANK cldfbAna_fx; /* main analysis filter bank handle */ - - HANDLE_CLDFB_FILTER_BANK cldfbBPF; /* BPF analysis filter bank handle */ - //HANDLE_CLDFB_FILTER_BANK cldfbBPF_fx; /* BPF analysis filter bank handle */ - - HANDLE_CLDFB_FILTER_BANK cldfbSyn; /* main synthesis filter bank handle */ - //HANDLE_CLDFB_FILTER_BANK cldfbSyn_fx; /* main synthesis filter bank handle */ - - HANDLE_CLDFB_FILTER_BANK cldfbSynHB; /* high band synthesis filter bank needed in SBA2Stereo DTX handling */ + int16_t bfi; /* FEC - bad frame indicator */ + // Word16 bfi_fx; /* FEC - bad frame indicator */ + + int16_t prev_bfi; /* FEC - previous bad frame indicator */ + // Word16 prev_bfi_fx; /* FEC - previous bad frame indicator Q0*/ + + int16_t prev_old_bfi; /* FEC - previous old bad frame indicator */ + + int16_t seed; /* FEC - seed for random generator for excitation */ + // Word16 seed_fx; /* FEC - seed for random generator for excitation Q0*/ + +#ifndef IVAS_FLOAT_FIXED + float lp_ener_bfi; /* FEC - long-term active-signal average energy */ + float lp_ener; /* FEC - low-pass filtered energy */ +#endif + + int16_t last_good; /* FEC - clas of last good received */ + + Word16 lp_gainp_fx; /* FEC - low-pass filtered pitch gain Q14 */ + + Word16 lp_gainc_fx; /* FEC - low-pass filtered code gain Q3*/ + + Word32 lp_ener_fx; /* FEC - low-pass filtered energy Q6*/ + + Word32 enr_old_fx; /* FEC - energy of the concealed frame Q0*/ + +#ifndef IVAS_FLOAT_FIXED + float lp_gainp; /* FEC - low-pass filtered pitch gain */ + float lp_gainc; /* FEC - low-pass filtered code gain */ + float enr_old; /* FEC - energy of the concealed frame */ + float bfi_pitch; /* FEC - pitch for FEC */ + float old_pitch_buf[2 * NB_SUBFR16k + 2]; /* FEC - buffer of old subframe pitch values */ +#endif // #ifndef IVAS_FLOAT_FIXED + Word16 bfi_pitch_fx; /* FEC - pitch for FEC */ + + int16_t bfi_pitch_frame; /* FEC - frame length when pitch for FEC is saved */ + // Word16 bfi_pitch_frame_fx; /*FEC - frame length when pitch for FEC is saved Q0*/ + + Word16 old_pitch_buf_16_fx[2 * NB_SUBFR16k + 2]; /* FEC - buffer of old subframe pitch values 15Q16 */ + Word32 old_pitch_buf_fx[2 * NB_SUBFR16k + 2]; /* FEC - buffer of old subframe pitch values 15Q16 */ + + int16_t upd_cnt; /* FEC - counter of frames since last update */ + // Word16 upd_cnt_fx; /* FEC - counter of frames since last update Q0*/ + + int16_t scaling_flag; /* FEC - flag to indicate energy control of syn */ + + Word32 lp_ener_FEC_av; /* FEC - averaged voiced signal energy Q0 */ + + Word32 lp_ener_FEC_max; /* FEC - averaged voiced signal energy Q0 */ + + Word16 old_enr_LP; /* FEC - LP filter gain Q5*/ + + int16_t prev_nbLostCmpt; /* FEC - compt for number of consecutive lost frame at the previous frame*/ + int16_t mode_lvq; /* FEC - index for LSF mean vector*/ + +#ifndef IVAS_FLOAT_FIXED + float old_enr_LP_float; /* FEC - LP filter gain */ + float lp_ener_FEC_av_float; /* FEC - averaged voiced signal energy */ + float lp_ener_FEC_max_float; /* FEC - averaged voiced signal energy */ + float lsfoldbfi0[M]; /* FEC - LSF vector of the previous frame */ + float lsfoldbfi1[M]; /* FEC - LSF vector of the past previous frame */ + float lsf_adaptive_mean[M]; /* FEC - adaptive mean LSF vector for FEC */ +#endif + + Word16 lsfoldbfi0_fx[M]; /* FEC - LSF vector of the previous frame (Qx2.56)*/ + + Word16 lsfoldbfi1_fx[M]; /* FEC - LSF vector of the past previous frame (Qx2.56) */ + + Word16 lsf_adaptive_mean_fx[M]; /* FEC - adaptive mean LSF vector for FEC (Qx2.56)*/ + + int16_t decision_hyst; /* FEC - hysteresis of the music/speech decision */ + // Word16 decision_hyst_fx; /* FEC - hysteresis of the music/speech decision Q0*/ + + // Word16 last_good; /* FEC - clas of last good received Q0*/ + Word16 lp_ener_FER_fx; /* FEC - long-term active-signal average energy Q8*/ + + + WI_DEC_HANDLE hWIDec; + + int16_t relax_prev_lsf_interp; + // Word16 relax_prev_lsf_interp; + +#ifndef IVAS_FLOAT_FIXED + float mem_syn_clas_estim[L_SYN_MEM_CLAS_ESTIM]; /* FEC - memory of the synthesis signal for frame class estimation */ +#endif // #ifndef IVAS_FLOAT_FIXED + Word16 mem_syn_clas_estim_fx[L_SYN_MEM_CLAS_ESTIM]; /* FEC - memory of the synthesis signal for frame class estimation */ + + int16_t bpf_off; /* Bass post-filter - do not use BPF when this flag is set to 1 */ + // Word16 bpf_off_fx; /* Bass post-filter - do not use BPF when this flag is set to 1 Q0*/ + + BPF_DEC_HANDLE hBPF; /* Bass post-filter handle */ + + HANDLE_CLDFB_FILTER_BANK cldfbAna; /* main analysis filter bank handle */ + // HANDLE_CLDFB_FILTER_BANK cldfbAna_fx; /* main analysis filter bank handle */ + + HANDLE_CLDFB_FILTER_BANK cldfbBPF; /* BPF analysis filter bank handle */ + // HANDLE_CLDFB_FILTER_BANK cldfbBPF_fx; /* BPF analysis filter bank handle */ + + HANDLE_CLDFB_FILTER_BANK cldfbSyn; /* main synthesis filter bank handle */ + // HANDLE_CLDFB_FILTER_BANK cldfbSyn_fx; /* main synthesis filter bank handle */ + + HANDLE_CLDFB_FILTER_BANK cldfbSynHB; /* high band synthesis filter bank needed in SBA2Stereo DTX handling */ int16_t last_active_bandsToZero_bwdec; int16_t last_flag_filter_NB; - + #ifndef IVAS_FLOAT_FIXED float perc_bwddec_float; - float avg_nrg_LT_float; - float ng_ener_ST; /* Noise gate - short-term energy */ -#endif // 0 - Word16 perc_bwddec; /*Q14*/ - - int16_t active_frame_cnt_bwddec; + float avg_nrg_LT_float; + float ng_ener_ST; /* Noise gate - short-term energy */ +#endif // 0 + Word16 perc_bwddec; /*Q14*/ + + int16_t active_frame_cnt_bwddec; int16_t flag_buffer[20]; int16_t total_frame_cnt_bwddec; - - Word32 avg_nrg_LT; - - Word16 Ng_ener_ST_fx; /* Noise gate - short-term energy Q8*/ - - int16_t last_L_frame; /* ACELP@16kHz - last value of st->L_frame */ - //Word16 last_L_frame_fx; /* ACELP@16kHz - last value of st->L_frame */ - - Word16 mem_preemp_preQ_fx; /* ACELP@16kHz - prequantizer preemhasis memory */ - - int16_t last_nq_preQ; /* ACELP@16kHz - AVQ subquantizer number of the last sub-band of the last subframe */ - //Word16 last_nq_preQ; /* ACELP@16kHz - AVQ subquantizer number of the last sub-band of the last subframe */ - - int16_t last_code_preq; /* ACELP@16kHz - last coefficient of the pre-quantizer contribution */ - - int16_t use_acelp_preq; /* ACELP@16kHz - flag of prequantizer usage */ + + Word32 avg_nrg_LT; + + Word16 Ng_ener_ST_fx; /* Noise gate - short-term energy Q8*/ + + int16_t last_L_frame; /* ACELP@16kHz - last value of st->L_frame */ + // Word16 last_L_frame_fx; /* ACELP@16kHz - last value of st->L_frame */ + + Word16 mem_preemp_preQ_fx; /* ACELP@16kHz - prequantizer preemhasis memory */ + + int16_t last_nq_preQ; /* ACELP@16kHz - AVQ subquantizer number of the last sub-band of the last subframe */ + // Word16 last_nq_preQ; /* ACELP@16kHz - AVQ subquantizer number of the last sub-band of the last subframe */ + + int16_t last_code_preq; /* ACELP@16kHz - last coefficient of the pre-quantizer contribution */ + + int16_t use_acelp_preq; /* ACELP@16kHz - flag of prequantizer usage */ /* NB and formant post-filter */ PFSTAT_HANDLE hPFstat; /* NB and formant post-filter states */ - - Word16 psf_lp_noise_fx; + + Word16 psf_lp_noise_fx; #ifndef IVAS_FLOAT_FIXED - float mem_preemp_preQ; /* ACELP@16kHz - prequantizer preemhasis memory */ - float psf_lp_noise; /* NB post-filter - long-term noise */ - float last_voice_factor; - float prev_synth_buffer[NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS )]; -#endif // #ifndef IVAS_FLOAT_FIXED - Word16 last_voice_factor_fx; /* Q6*/ + float mem_preemp_preQ; /* ACELP@16kHz - prequantizer preemhasis memory */ + float psf_lp_noise; /* NB post-filter - long-term noise */ + float last_voice_factor; + float prev_synth_buffer[NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS )]; +#endif // #ifndef IVAS_FLOAT_FIXED + Word16 last_voice_factor_fx; /* Q6*/ int16_t old_bfi_cnt; /* HQ core - # of bfi until previous frame(for FEC) */ @@ -2540,28 +2526,28 @@ typedef struct Decoder_State *----------------------------------------------------------------------------------*/ int16_t first_CNG; /* DTX/CNG - first CNG frame flag */ - //Word16 first_CNG_fx; /* CNG and DTX - first CNG frame flag Q0*/ - - int16_t cng_type; /* DTX/CNG - flag indicating LP or CLDFB based SID/CNG */ - //Word16 cng_type_fx; /* DTX/CNG - flag indicating LP or CLDFB based SID/CNG */ - - int16_t last_vad; - - int32_t last_active_brate; /* DTX/CNG - last active frame bitrate used for CNG_mode control */ - //Word32 last_active_brate_fx; /* DTX/CNG - last active frame bitrate used for CNG_mode control */ - - int16_t last_CNG_L_frame; /* DTX/CNG - last CNG frame length */ - //Word16 last_CNG_L_frame_fx; /* DTX/CNG - last CNG frame length */ + // Word16 first_CNG_fx; /* CNG and DTX - first CNG frame flag Q0*/ + + int16_t cng_type; /* DTX/CNG - flag indicating LP or CLDFB based SID/CNG */ + // Word16 cng_type_fx; /* DTX/CNG - flag indicating LP or CLDFB based SID/CNG */ + + int16_t last_vad; + + int32_t last_active_brate; /* DTX/CNG - last active frame bitrate used for CNG_mode control */ + // Word32 last_active_brate_fx; /* DTX/CNG - last active frame bitrate used for CNG_mode control */ + + int16_t last_CNG_L_frame; /* DTX/CNG - last CNG frame length */ + // Word16 last_CNG_L_frame_fx; /* DTX/CNG - last CNG frame length */ int16_t CNG_mode; /* DTX/CNG - mode for DTX configuration */ - //Word16 CNG_mode_fx; /* DTX/CNG - mode for DTX configuration */ + // Word16 CNG_mode_fx; /* DTX/CNG - mode for DTX configuration */ #ifndef IVAS_FLOAT_FIXED - float lspCNG[M]; /* DTX/CNG - LP filtered ISPs */ -#endif // #ifndef IVAS_FLOAT_FIXED - Word16 lspCNG_fx[M]; /* CNG and DTX - LP filtered ISPs Q15*/ - - int16_t active_cnt; + float lspCNG[M]; /* DTX/CNG - LP filtered ISPs */ +#endif // #ifndef IVAS_FLOAT_FIXED + Word16 lspCNG_fx[M]; /* CNG and DTX - LP filtered ISPs Q15*/ + + int16_t active_cnt; TD_CNG_DEC_HANDLE hTdCngDec; int16_t masa_sid_format; @@ -2579,38 +2565,38 @@ typedef struct Decoder_State SC_VBR_DEC_HANDLE hSC_VBR; int16_t last_ppp_mode_dec; - //Word16 last_ppp_mode_dec; /*Q0*/ - - int16_t ppp_mode_dec; - //Word16 ppp_mode_dec; /*Q0*/ - - int16_t last_nelp_mode_dec; - // Word16 last_nelp_mode_dec; - - int16_t nelp_mode_dec; - //Word16 nelp_mode_dec; /* Q0 */ - - Word16 prev_gain_pit_dec_fx; /*Q14*/ - -#ifndef IVAS_FLOAT_FIXED - float prev_gain_pit_dec; - float prev_tilt_code_dec; + // Word16 last_ppp_mode_dec; /*Q0*/ + + int16_t ppp_mode_dec; + // Word16 ppp_mode_dec; /*Q0*/ + + int16_t last_nelp_mode_dec; + // Word16 last_nelp_mode_dec; + + int16_t nelp_mode_dec; + // Word16 nelp_mode_dec; /* Q0 */ + + Word16 prev_gain_pit_dec_fx; /*Q14*/ + +#ifndef IVAS_FLOAT_FIXED + float prev_gain_pit_dec; + float prev_tilt_code_dec; float tilt_code_dec[NB_SUBFR16k]; #endif - Word16 prev_tilt_code_dec_fx; /*Q15*/ - - int16_t vbr_hw_BWE_disable_dec; - //Word16 vbr_hw_BWE_disable_dec; - - int16_t last_vbr_hw_BWE_disable_dec; - //Word16 last_vbr_hw_BWE_disable_dec; + Word16 prev_tilt_code_dec_fx; /*Q15*/ + + int16_t vbr_hw_BWE_disable_dec; + // Word16 vbr_hw_BWE_disable_dec; + + int16_t last_vbr_hw_BWE_disable_dec; + // Word16 last_vbr_hw_BWE_disable_dec; /*----------------------------------------------------------------------------------* * channel-aware mode *----------------------------------------------------------------------------------*/ - Word16 tilt_code_dec_fx[NB_SUBFR16k]; + Word16 tilt_code_dec_fx[NB_SUBFR16k]; int16_t rf_frame_type; int16_t use_partial_copy; @@ -2633,7 +2619,7 @@ typedef struct Decoder_State *----------------------------------------------------------------------------------*/ HR_BWE_DEC_HANDLE hBWE_FD_HR; - Word16 Qprev_synth_buffer_fx; + Word16 Qprev_synth_buffer_fx; /*----------------------------------------------------------------------------------* * HQ core parameters @@ -2642,42 +2628,42 @@ typedef struct Decoder_State HQ_DEC_HANDLE hHQ_core; int16_t last_core; - //Word16 last_core_fx; /*Q0*/ + // Word16 last_core_fx; /*Q0*/ - int16_t last_core_from_bs; /* last frame core as coded in TCX bitstream */ - //Word16 last_core_bs_fx; + int16_t last_core_from_bs; /* last frame core as coded in TCX bitstream */ + // Word16 last_core_bs_fx; int16_t last_L_frame_ori; - //Word16 last_L_frame_ori_fx; - - Word16 previoussynth_fx[L_FRAME48k]; - Word32 previoussynth_fx_32[L_FRAME48k]; - + // Word16 last_L_frame_ori_fx; + + Word16 previoussynth_fx[L_FRAME48k]; + Word32 previoussynth_fx_32[L_FRAME48k]; + #ifndef IVAS_FLOAT_FIXED - float previoussynth[L_FRAME48k]; /* note: only 60+111 out of 960 samples are needed in IVAS (for ACELP->TCX switching */ - float old_synth_sw[NS2SA(48000, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS)]; /* note: buffer used only in EVS mono */ -#endif // 0 - Word16 old_synth_sw_fx[NS2SA(48000, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS)]; - - Word16 delay_buf_out_fx[HQ_DELTA_MAX * HQ_DELAY_COMP]; /*Q0*/ - Word32 delay_buf_out32_fx[HQ_DELTA_MAX * HQ_DELAY_COMP]; /*Q11*/ + float previoussynth[L_FRAME48k]; /* note: only 60+111 out of 960 samples are needed in IVAS (for ACELP->TCX switching */ + float old_synth_sw[NS2SA( 48000, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS )]; /* note: buffer used only in EVS mono */ +#endif // 0 + Word16 old_synth_sw_fx[NS2SA( 48000, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS )]; + Word16 delay_buf_out_fx[HQ_DELTA_MAX * HQ_DELAY_COMP]; /*Q0*/ + Word32 delay_buf_out32_fx[HQ_DELTA_MAX * HQ_DELAY_COMP]; /*Q11*/ + + + Word16 old_Aq_12_8_fx[M + 1]; /* Q12 old Aq[] for core switching */ + Word32 old_Aq_12_8_fx_32[M + 1]; /* Q28 old Aq[] for core switching */ - Word16 old_Aq_12_8_fx[M + 1]; /* Q12 old Aq[] for core switching */ - Word32 old_Aq_12_8_fx_32[M + 1]; /* Q28 old Aq[] for core switching */ - #ifndef IVAS_FLOAT_FIXED - float delay_buf_out[HQ_DELTA_MAX * HQ_DELAY_COMP]; + float delay_buf_out[HQ_DELTA_MAX * HQ_DELAY_COMP]; float old_Aq_12_8[M + 1]; /* old Aq[] for core switching */ - float old_Es_pred; /* old Es_pred for core switching */ + float old_Es_pred; /* old Es_pred for core switching */ #endif - Word16 old_Es_pred_fx; /* old Es_pred for core switching */ + Word16 old_Es_pred_fx; /* old Es_pred for core switching */ - // Word16 old_bfi_cnt; /* HQ core - # of bfi until previous frame(for FEC) */ - //Word16 prev_old_bfi; - - HQ_NBFEC_HANDLE hHQ_nbfec; + // Word16 old_bfi_cnt; /* HQ core - # of bfi until previous frame(for FEC) */ + // Word16 prev_old_bfi; + + HQ_NBFEC_HANDLE hHQ_nbfec; /*----------------------------------------------------------------------------------* * TBE parameters @@ -2686,125 +2672,125 @@ typedef struct Decoder_State TD_BWE_DEC_HANDLE hBWE_TD; int16_t old_bwe_delay; - //Word16 old_bwe_delay; /*Q0*/ - - Word16 hb_prev_synth_buffer_fx[NS2SA(48000, DELAY_BWE_TOTAL_NS)]; + // Word16 old_bwe_delay; /*Q0*/ + + Word16 hb_prev_synth_buffer_fx[NS2SA( 48000, DELAY_BWE_TOTAL_NS )]; /* WB/SWB bandwidth switching */ - Word16 tilt_wb_fx; - - Word16 tilt_swb_fx; - + Word16 tilt_wb_fx; + + Word16 tilt_swb_fx; + #ifndef IVAS_FLOAT_FIXED - float hb_prev_synth_buffer[NS2SA( 48000, DELAY_BWE_TOTAL_NS )]; + float hb_prev_synth_buffer[NS2SA( 48000, DELAY_BWE_TOTAL_NS )]; float tilt_wb; - float tilt_swb; - float prev_ener_shb; - float prev_enerLH; - float prev_enerLL; + float tilt_swb; + float prev_ener_shb; + float prev_enerLH; + float prev_enerLL; - float enerLH; + float enerLH; float enerLL; #endif - Word16 prev_ener_shb_fx; - - Word32 enerLH_fx; - Word16 enerLH_fx_Q; - - Word32 prev_enerLH_fx; - - Word32 enerLL_fx; - Word16 enerLL_fx_Q; - - Word32 prev_enerLL_fx; - - int16_t prev_fractive; - //Word16 prev_fractive; - - int16_t prev_bws_cnt; - // Word16 prev_bws_cnt; - - int16_t bws_cnt; - // Word16 bws_cnt; - - int16_t bws_cnt1; - // Word16 bws_cnt1; - -#ifndef IVAS_FLOAT_FIXED - float attenu1; - float t_audio_q[L_FRAME]; + Word16 prev_ener_shb_fx; + + Word32 enerLH_fx; + Word16 enerLH_fx_Q; + + Word32 prev_enerLH_fx; + + Word32 enerLL_fx; + Word16 enerLL_fx_Q; + + Word32 prev_enerLL_fx; + + int16_t prev_fractive; + // Word16 prev_fractive; + + int16_t prev_bws_cnt; + // Word16 prev_bws_cnt; + + int16_t bws_cnt; + // Word16 bws_cnt; + + int16_t bws_cnt1; + // Word16 bws_cnt1; + +#ifndef IVAS_FLOAT_FIXED + float attenu1; + float t_audio_q[L_FRAME]; #endif // #ifndef IVAS_FLOAT_FIXED - Word16 attenu_fx; - - int16_t last_inner_frame; - //Word16 last_inner_frame_fx; /* (HQ_CORE) DCT length */ - - int16_t last_bwidth; - //Word16 last_bwidth_fx; - - Word16 t_audio_q_fx[L_FRAME]; - - Word16 interpol_3_2_cng_dec_fx[INTERP_3_2_MEM_LEN]; - - /*----------------------------------------------------------------------------------* - * Fixed point only - *----------------------------------------------------------------------------------*/ - Word16 Q_exc; - Word16 Q_exc_cng; - Word16 prev_Q_exc; - Word16 Q_subfr[L_Q_MEM]; + Word16 attenu_fx; + + int16_t last_inner_frame; + // Word16 last_inner_frame_fx; /* (HQ_CORE) DCT length */ - Word16 prev_Q_bwe_syn; - Word16 prev_Q_bwe_syn2; + int16_t last_bwidth; + // Word16 last_bwidth_fx; - Word16 prev_Q_bwe_exc_fb; - Word16 prev_Qx; - Word16 prev_Q_bwe_exc; - Word16 prev_Q_synth; - Word16 prev_SWB_fenv_fx[SWB_FENV]; + Word16 t_audio_q_fx[L_FRAME]; + + Word16 interpol_3_2_cng_dec_fx[INTERP_3_2_MEM_LEN]; + + /*----------------------------------------------------------------------------------* + * Fixed point only + *----------------------------------------------------------------------------------*/ + Word16 Q_exc; + Word16 Q_exc_cng; + Word16 prev_Q_exc; + Word16 Q_subfr[L_Q_MEM]; + + Word16 prev_Q_bwe_syn; + Word16 prev_Q_bwe_syn2; + + Word16 prev_Q_bwe_exc_fb; + Word16 prev_Qx; + Word16 prev_Q_bwe_exc; + Word16 prev_Q_synth; + Word16 prev_SWB_fenv_fx[SWB_FENV]; Word16 Q_syn; Word16 Q_syn2; - Word16 Q_syn_cng; - Word16 prev_Q_syn; - Word16 prev_frame_pow_exp; - Word16 prev_ener_fx_Q; - Word16 last_wb_bwe_ener_fx; - Word16 prev_fb_ener_adjust_fx; + Word16 Q_syn_cng; + Word16 prev_Q_syn; + Word16 prev_frame_pow_exp; + Word16 prev_ener_fx_Q; + Word16 last_wb_bwe_ener_fx; + Word16 prev_fb_ener_adjust_fx; #ifdef IVAS_FLOAT_FIXED - Word16 prev_synth_buffer_fx[NS2SA(48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS)];/*Updated IVAS size is 96*/ - Word16 q_prev_synth_buffer_fx; + Word16 prev_synth_buffer_fx[NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS )]; /*Updated IVAS size is 96*/ + Word16 q_prev_synth_buffer_fx; #else - Word16 prev_synth_buffer_fx[NS2SA(48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS)]; - /*Old EVS size is 51*/ + Word16 prev_synth_buffer_fx[NS2SA( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS )]; + /*Old EVS size is 51*/ #endif - Word16 GainShape_Delay[NUM_SHB_SUBFR / 2]; - Word16 prev_lpc_wb_fx[LPC_SHB_ORDER_WB]; + Word16 GainShape_Delay[NUM_SHB_SUBFR / 2]; + Word16 prev_lpc_wb_fx[LPC_SHB_ORDER_WB]; /*----------------------------------------------------------------------------------* * SWB BWE structure *----------------------------------------------------------------------------------*/ FD_BWE_DEC_HANDLE hBWE_FD; - // Word16 prev_coder_type; + // Word16 prev_coder_type; - /*----------------------------------------------------------------------------------* - * SWB DTX/CNG parameters - *----------------------------------------------------------------------------------*/ + /*----------------------------------------------------------------------------------* + * SWB DTX/CNG parameters + *----------------------------------------------------------------------------------*/ - Word16 shb_cng_ener_fx; - Word16 wb_cng_ener_fx; - Word16 last_wb_cng_ener_fx; - Word16 last_shb_cng_ener_fx; - Word16 swb_cng_seed; - Word16 lsp_shb_prev_prev_fx[LPC_SHB_ORDER]; - Word16 lsp_shb_prev_fx[LPC_SHB_ORDER]; - Word16 shb_dtx_count_fx; - Word16 last_vad_fx; - Word16 trans_cnt_fx; - //Word16 burst_cnt; - Word16 last_shb_ener_fx; + Word16 shb_cng_ener_fx; + Word16 wb_cng_ener_fx; + Word16 last_wb_cng_ener_fx; + Word16 last_shb_cng_ener_fx; + Word16 swb_cng_seed; + Word16 lsp_shb_prev_prev_fx[LPC_SHB_ORDER]; + Word16 lsp_shb_prev_fx[LPC_SHB_ORDER]; + Word16 shb_dtx_count_fx; + Word16 last_vad_fx; + Word16 trans_cnt_fx; + // Word16 burst_cnt; + Word16 last_shb_ener_fx; /*----------------------------------------------------------------------------------* * LD music post-filter @@ -2823,8 +2809,8 @@ typedef struct Decoder_State TCX_DEC_HANDLE hTcxDec; - Word32 lp_error_ener; - Word32 mem_error; + Word32 lp_error_ener; + Word32 mem_error; /*----------------------------------------------------------------------------------* * Mode 2 @@ -2840,7 +2826,7 @@ typedef struct Decoder_State int16_t bits_frame_core; /* bit per frame for the core */ int16_t narrowBand; - Word16 bits_common; /* read bits from header and LPC*/ + Word16 bits_common; /* read bits from header and LPC*/ int16_t last_is_cng; @@ -2848,68 +2834,68 @@ typedef struct Decoder_State float *acelp_zir; #endif // !IVAS_FLOAT_FIXED #ifndef IVAS_FLOAT_FIXED - float syn_float[M + 1]; + float syn_float[M + 1]; #endif - Word16 syn[M + 1]; + Word16 syn[M + 1]; int16_t bpf_gain_param; /* bass post-filter gain factor parameter (0->noBpf)*/ int16_t L_frame_past; int16_t L_frameTCX_past; - Word16 lsfold_uw[M]; /* old lsf (unweighted) */ - - Word16 lspold_uw[M]; /* old lsp (unweighted) */ - - int16_t seed_tcx_plc; /* seed memory (for random function in TCX PLC) */ - + Word16 lsfold_uw[M]; /* old lsf (unweighted) */ + + Word16 lspold_uw[M]; /* old lsp (unweighted) */ + + int16_t seed_tcx_plc; /* seed memory (for random function in TCX PLC) */ + #ifndef IVAS_FLOAT_FIXED float lsfold_uw_float[M]; /* old lsf (unweighted) */ - float lspold_uw_float[M]; /* old lsp (unweighted) */ - float past_gpit_float; /* past gain of pitch (for frame recovery) */ - float past_gcode_float; /* past energy (!) of code (for frame recovery) */ - float lsf_cng_float[M]; /* lsf coefficients used for CNG generation (long term) */ - float lspold_cng_float[M]; /* lsp coefficients used for CNG generation (long term) */ - float lsp_q_cng_float[M]; /* lsp coefficients used for CNG generation (short term interpolated) */ - float old_lsp_q_cng_float[M]; /* lsp coefficients used for CNG generation (short term interpolated) */ - float lsf_q_cng_float[M]; /* lsf coefficients used for CNG generation (short term interpolated) */ - float old_lsf_q_cng_float[M]; /* lsf: old quantized lsfs for background noise */ - float Aq_cng_float[( NB_SUBFR16k + 1 ) * ( M + 1 )]; /* LPC coefficients derived from CNG estimate */ -#endif // 0 - - Word16 past_gpit; /* past gain of pitch (for frame recovery) */ - Word32 past_gcode; /* past energy (!) of code (for frame recovery) */ /*15Q16*/ - - Word16 lsf_cng[M]; /* xSF coefficients used for CNG generation (long term) */ - - Word16 lspold_cng[M]; /* xSP coefficients used for CNG generation (long term) */ - - Word16 lsp_q_cng[M]; /* xSP coefficients used for CNG generation (short term interpolated) */ - - Word16 old_lsp_q_cng[M]; /* xSP coefficients used for CNG generation (short term interpolated) */ - - Word16 lsf_q_cng[M]; /* xSF coefficients used for CNG generation (short term interpolated) */ - - Word16 old_lsf_q_cng[M]; /* xSF: old quantized lsfs for background noise */ - - Word16 Aq_cng[(NB_SUBFR16k + 1)*(M + 1)]; /* LPC coefficients derived from CNG estimate */ - - Word16 mem_syn_unv_back[M]; /* filter memory for unvoiced synth */ - - int16_t plcBackgroundNoiseUpdated; /* flag: Is background noise estimate updated? */ - -#ifndef IVAS_FLOAT_FIXED - float mem_syn_unv_back_float[M]; /* filter memory for unvoiced synth */ - float last_gain_syn_deemph_float; - float last_concealed_gain_syn_deemph_float; -#endif - Word16 last_gain_syn_deemph; /*Q15*/ - - Word16 last_gain_syn_deemph_e; - - Word16 last_concealed_gain_syn_deemph; /*Q15*/ - - Word16 last_concealed_gain_syn_deemph_e; + float lspold_uw_float[M]; /* old lsp (unweighted) */ + float past_gpit_float; /* past gain of pitch (for frame recovery) */ + float past_gcode_float; /* past energy (!) of code (for frame recovery) */ + float lsf_cng_float[M]; /* lsf coefficients used for CNG generation (long term) */ + float lspold_cng_float[M]; /* lsp coefficients used for CNG generation (long term) */ + float lsp_q_cng_float[M]; /* lsp coefficients used for CNG generation (short term interpolated) */ + float old_lsp_q_cng_float[M]; /* lsp coefficients used for CNG generation (short term interpolated) */ + float lsf_q_cng_float[M]; /* lsf coefficients used for CNG generation (short term interpolated) */ + float old_lsf_q_cng_float[M]; /* lsf: old quantized lsfs for background noise */ + float Aq_cng_float[( NB_SUBFR16k + 1 ) * ( M + 1 )]; /* LPC coefficients derived from CNG estimate */ +#endif // 0 + + Word16 past_gpit; /* past gain of pitch (for frame recovery) */ + Word32 past_gcode; /* past energy (!) of code (for frame recovery) */ /*15Q16*/ + + Word16 lsf_cng[M]; /* xSF coefficients used for CNG generation (long term) */ + + Word16 lspold_cng[M]; /* xSP coefficients used for CNG generation (long term) */ + + Word16 lsp_q_cng[M]; /* xSP coefficients used for CNG generation (short term interpolated) */ + + Word16 old_lsp_q_cng[M]; /* xSP coefficients used for CNG generation (short term interpolated) */ + + Word16 lsf_q_cng[M]; /* xSF coefficients used for CNG generation (short term interpolated) */ + + Word16 old_lsf_q_cng[M]; /* xSF: old quantized lsfs for background noise */ + + Word16 Aq_cng[( NB_SUBFR16k + 1 ) * ( M + 1 )]; /* LPC coefficients derived from CNG estimate */ + + Word16 mem_syn_unv_back[M]; /* filter memory for unvoiced synth */ + + int16_t plcBackgroundNoiseUpdated; /* flag: Is background noise estimate updated? */ + +#ifndef IVAS_FLOAT_FIXED + float mem_syn_unv_back_float[M]; /* filter memory for unvoiced synth */ + float last_gain_syn_deemph_float; + float last_concealed_gain_syn_deemph_float; +#endif + Word16 last_gain_syn_deemph; /*Q15*/ + + Word16 last_gain_syn_deemph_e; + + Word16 last_concealed_gain_syn_deemph; /*Q15*/ + + Word16 last_concealed_gain_syn_deemph_e; /* variables for framing */ @@ -2928,60 +2914,60 @@ typedef struct Decoder_State int16_t pit_res_max_past; /*Preemphasis factor*/ - Word16 preemph_fac; /*0Q15*/ - + Word16 preemph_fac; /*0Q15*/ + #ifndef IVAS_FLOAT_FIXED /*Preemphasis factor*/ float preemph_fac_float; - float gamma_float; + float gamma_float; /*for AMR-WB like 6.4 to 7 kHz upsampling and noise filling*/ float mem_Aq_float[NB_SUBFR16k * ( M + 1 )]; #endif // #ifndef IVAS_FLOAT_FIXED - Word16 gamma; + Word16 gamma; - Word16 inv_gamma; + Word16 inv_gamma; /*for AMR-WB like 6.4 to 7 kHz upsampling and noise filling*/ - Word16 mem_Aq[(NB_SUBFR16k)*(M + 1)]; /* Q12 */ + Word16 mem_Aq[( NB_SUBFR16k ) * ( M + 1 )]; /* Q12 */ /* Error concealment */ int16_t last_core_bfi; /* PLC - mode in previous frame */ int16_t nbLostCmpt; /* PLC - compt for number of consecutive lost frame */ - Word32 old_fpitch; /* last pitch of previous frame */ /*15Q16*/ - - Word32 old_fpitchFB; /* PLC - last pitch of previous FB frame (depends on output sr) */ /*15Q16*/ - - int16_t clas_dec; /* PLC - frame class at the decoder */ - + Word32 old_fpitch; /* last pitch of previous frame */ /*15Q16*/ + + Word32 old_fpitchFB; /* PLC - last pitch of previous FB frame (depends on output sr) */ /*15Q16*/ + + int16_t clas_dec; /* PLC - frame class at the decoder */ + #ifndef IVAS_FLOAT_FIXED float old_fpitch_float; /* PLC - last pitch of previous frame (as transmitted) */ - float old_fpitchFB_float; /* PLC - last pitch of previous FB frame (depends on output sr) */ - float mem_pitch_gain_float[2 * NB_SUBFR16k + 2]; /* PLC - Pitch gain memory */ + float old_fpitchFB_float; /* PLC - last pitch of previous FB frame (depends on output sr) */ + float mem_pitch_gain_float[2 * NB_SUBFR16k + 2]; /* PLC - Pitch gain memory */ float cummulative_damping_float; - float cngTDLevel_float; -#endif // #ifndef IVAS_FLOAT_FIXED - Word16 mem_pitch_gain[2 * NB_SUBFR16k + 2]; /* Pitch gain memory Q14 */ - - int16_t plc_use_future_lag; /* PLC - flag indicating if info (pitch lag / pitch gain) about future frame is usable */ + float cngTDLevel_float; +#endif // #ifndef IVAS_FLOAT_FIXED + Word16 mem_pitch_gain[2 * NB_SUBFR16k + 2]; /* Pitch gain memory Q14 */ + + int16_t plc_use_future_lag; /* PLC - flag indicating if info (pitch lag / pitch gain) about future frame is usable */ - Word32 Mode2_lp_gainc; /* 15Q16 low passed code gain used for concealment*/ - Word32 Mode2_lp_gainp; /* 15Q16 low passed pitch gain used for concealment*/ + Word32 Mode2_lp_gainc; /* 15Q16 low passed code gain used for concealment*/ + Word32 Mode2_lp_gainp; /* 15Q16 low passed pitch gain used for concealment*/ - Word16 cummulative_damping; /*Q15*/ + Word16 cummulative_damping; /*Q15*/ - Word16 cngTDLevel; - Word16 cngTDLevel_e; - - Word16 prev_widow_left_rect; + Word16 cngTDLevel; + Word16 cngTDLevel_e; - int16_t reset_mem_AR; + Word16 prev_widow_left_rect; - Word16 classifier_Q_mem_syn; /*scalingfactor of mem_syn_clas_estim_fx in MODE2 */ + int16_t reset_mem_AR; + + Word16 classifier_Q_mem_syn; /*scalingfactor of mem_syn_clas_estim_fx in MODE2 */ int16_t rate_switching_init; @@ -2994,18 +2980,18 @@ typedef struct Decoder_State #ifndef IVAS_FLOAT_FIXED float TcxBandwidth_float; #endif - Word16 TcxBandwidth; + Word16 TcxBandwidth; #ifndef IVAS_FLOAT_FIXED - float voice_fac_float; + float voice_fac_float; #endif // #ifndef IVAS_FLOAT_FIXED - Word16 voice_fac; + Word16 voice_fac; int16_t tcxonly; int16_t last_ctx_hm_enabled; - struct tonalmdctconceal tonalMDCTconceal; + struct tonalmdctconceal tonalMDCTconceal; TonalMDCTConcealPtr hTonalMDCTConc; int16_t tonal_mdct_plc_active; @@ -3016,19 +3002,19 @@ typedef struct Decoder_State /* parameters for switching */ #ifndef IVAS_FLOAT_FIXED float mem_syn_r_float[L_SYN_MEM]; /*LPC synthesis memory needed for rate switching*/ -#endif // #ifndef IVAS_FLOAT_FIXED - Word16 mem_syn_r[L_SYN_MEM]; /*LPC synthesis memory needed for rate switching*/ - - int16_t rate_switching_reset; +#endif // #ifndef IVAS_FLOAT_FIXED + Word16 mem_syn_r[L_SYN_MEM]; /*LPC synthesis memory needed for rate switching*/ - Word16 bpf_noise_buf[L_FRAME_16k]; - Word32 bpf_noise_buf_32[L_FRAME_16k]; + int16_t rate_switching_reset; + + Word16 bpf_noise_buf[L_FRAME_16k]; + Word32 bpf_noise_buf_32[L_FRAME_16k]; #ifndef IVAS_FLOAT_FIXED float bpf_noise_buf_float[L_FRAME16k]; float *p_bpf_noise_buf_float; #endif - Word16 *p_bpf_noise_buf; - Word32 *p_bpf_noise_buf_32; + Word16 *p_bpf_noise_buf; + Word32 *p_bpf_noise_buf_32; int16_t enableGplc; int16_t flagGuidedAcelp; @@ -3038,7 +3024,7 @@ typedef struct Decoder_State int16_t enablePlcWaveadjust; int16_t tonality_flag; T_PLCInfo_HANDLE hPlcInfo; - T_PLCInfo plcInfo; + T_PLCInfo plcInfo; int16_t VAD; int16_t flag_cna; @@ -3047,9 +3033,9 @@ typedef struct Decoder_State #ifndef IVAS_FLOAT_FIXED float lp_noise_float; #endif // #ifndef IVAS_FLOAT_FIXED - Word32 lp_noise; - - int16_t seed_acelp; + Word32 lp_noise; + + int16_t seed_acelp; int16_t core_ext_mode; /*GC,VC,UC,TC: core extended mode used for PLC or Acelp-external modules.*/ int16_t dec_glr; @@ -3060,13 +3046,13 @@ typedef struct Decoder_State uint8_t m_old_frame_type; /*ZERO_FRAME/SID_FRAME/ACTIVE_FRAME*/ int16_t old_ppp_mode; - //Word16 old_ppp_mode; + // Word16 old_ppp_mode; int16_t con_tcx; int16_t last_con_tcx; - Word16 prev_Q_exc_fr; - Word16 prev_Q_syn_fr; + Word16 prev_Q_exc_fr; + Word16 prev_Q_syn_fr; int16_t writeFECoffset; @@ -3082,9 +3068,9 @@ typedef struct Decoder_State IGF_DEC_INSTANCE_HANDLE hIGFDec; int16_t igf; - CLDFB_SCALE_FACTOR scaleFactor; + CLDFB_SCALE_FACTOR scaleFactor; + - /*----------------------------------------------------------------------------------* * TEC *----------------------------------------------------------------------------------*/ @@ -3106,18 +3092,18 @@ typedef struct Decoder_State int16_t cng_sba_flag; /* CNG in SBA flag */ /* MCT Channel mode indication: LFE, ignore channel? */ - //note_ : one extra value in evs ivas macro code + // note_ : one extra value in evs ivas macro code MCT_CHAN_MODE mct_chan_mode; int16_t cng_ism_flag; /* CNG in ISM format flag */ int16_t is_ism_format; /* Indication whether the codec operates in ISM format */ - Word16 last_element_mode; /* element mode */ - // Word16 coder_type; /* low-rate mode flag */ - Word32 prev_synth_buffer32_fx[NS2SA(48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS)]; + Word16 last_element_mode; /* element mode */ + // Word16 coder_type; /* low-rate mode flag */ + Word32 prev_synth_buffer32_fx[NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS )]; #ifdef DEBUGGING - Word16 id_element; /* element ID */ + Word16 id_element; /* element ID */ #endif IVAS_FORMAT ivas_format; /* format; corresponds to st_ivas->ivas_format, unless the signal gets transormed to a different domain for rendering */ diff --git a/lib_dec/stat_noise_uv_dec_fx.c b/lib_dec/stat_noise_uv_dec_fx.c index a090fdfc7..39b56fa7f 100644 --- a/lib_dec/stat_noise_uv_dec_fx.c +++ b/lib_dec/stat_noise_uv_dec_fx.c @@ -3,9 +3,9 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ /*---------------------------------------------------------* @@ -14,12 +14,13 @@ * Modifies excitation signal in UC mode when the noise is stationary *---------------------------------------------------------*/ void stat_noise_uv_dec_fx( - Decoder_State *st_fx, /* i/o: Decoder static memory */ - Word16 *lsp_new, /* i : end-frame LSP vector */ - Word16 *lsp_mid, /* i : mid-frame LSP vector */ - Word16 *Aq, /* o : A(z) quantized for the 4 subframes */ - Word16 *exc2 /* i/o: excitation buffer */ - , const Word16 uc_two_stage_flag /* i : flag indicating two-stage UC */ + Decoder_State *st_fx, /* i/o: Decoder static memory */ + Word16 *lsp_new, /* i : end-frame LSP vector */ + Word16 *lsp_mid, /* i : mid-frame LSP vector */ + Word16 *Aq, /* o : A(z) quantized for the 4 subframes */ + Word16 *exc2 /* i/o: excitation buffer */ + , + const Word16 uc_two_stage_flag /* i : flag indicating two-stage UC */ ) { Word16 noisiness = 0, i; @@ -32,10 +33,10 @@ void stat_noise_uv_dec_fx( *-----------------------------------------------------------------*/ test(); test(); - IF( (EQ_16(coder_type,UNVOICED ) && !uc_two_stage_flag) ||(EQ_16(coder_type,INACTIVE)&&LE_32(st_fx->core_brate,ACELP_9k60))) + IF( ( EQ_16( coder_type, UNVOICED ) && !uc_two_stage_flag ) || ( EQ_16( coder_type, INACTIVE ) && LE_32( st_fx->core_brate, ACELP_9k60 ) ) ) { /* read the noisiness parameter */ - noisiness = (Word16)get_next_indice( st_fx, 5 ); + noisiness = (Word16) get_next_indice( st_fx, 5 ); move16(); } @@ -43,28 +44,28 @@ void stat_noise_uv_dec_fx( * Update long-term energies for FEC * Update LSP vector for CNG *-----------------------------------------------------------------*/ - IF (EQ_16(coder_type,INACTIVE)) + IF( EQ_16( coder_type, INACTIVE ) ) { - IF (GT_16(st_fx->unv_cnt,20)) + IF( GT_16( st_fx->unv_cnt, 20 ) ) { /*ftmp = st->lp_gainc * st->lp_gainc;*/ - L_tmp = L_mult0(st_fx->lp_gainc_fx, st_fx->lp_gainc_fx); /*Q3 * Q3 ->Q6*/ + L_tmp = L_mult0( st_fx->lp_gainc_fx, st_fx->lp_gainc_fx ); /*Q3 * Q3 ->Q6*/ /*st->lp_ener = 0.7f * st->lp_ener + 0.3f * ftmp;*/ - L_tmp = Mult_32_16(L_tmp, 9830); - st_fx->lp_ener_fx = L_add(Mult_32_16(st_fx->lp_ener_fx, 22938), L_tmp); - move16(); /*Q6 + Q6*/ + L_tmp = Mult_32_16( L_tmp, 9830 ); + st_fx->lp_ener_fx = L_add( Mult_32_16( st_fx->lp_ener_fx, 22938 ), L_tmp ); + move16(); /*Q6 + Q6*/ - FOR( i=0 ; ilspCNG[i] = (float)(0.9f * st->lspCNG[i] + 0.1f * lspnew[i]);*/ - L_tmp = L_mult(lsp_new[i], 3277); - st_fx->lspCNG_fx[i] = mac_r(L_tmp, st_fx->lspCNG_fx[i], 29491); - move16();/*Q15*/ + L_tmp = L_mult( lsp_new[i], 3277 ); + st_fx->lspCNG_fx[i] = mac_r( L_tmp, st_fx->lspCNG_fx[i], 29491 ); + move16(); /*Q15*/ } } ELSE { - st_fx->unv_cnt = add(st_fx->unv_cnt,1); + st_fx->unv_cnt = add( st_fx->unv_cnt, 1 ); } } ELSE @@ -73,15 +74,14 @@ void stat_noise_uv_dec_fx( move16(); } - IF (!st_fx->Opt_AMR_WB) + IF( !st_fx->Opt_AMR_WB ) { - stat_noise_uv_mod_fx( coder_type, noisiness, st_fx->lsp_old_fx, lsp_new, lsp_mid, Aq - ,exc2, st_fx->Q_exc, 0, &st_fx->ge_sm_fx, &st_fx->uv_count, &st_fx->act_count, + stat_noise_uv_mod_fx( coder_type, noisiness, st_fx->lsp_old_fx, lsp_new, lsp_mid, Aq, exc2, st_fx->Q_exc, 0, &st_fx->ge_sm_fx, &st_fx->uv_count, &st_fx->act_count, st_fx->lspold_s_fx, &st_fx->noimix_seed, &st_fx->min_alpha_fx, &st_fx->exc_pe_fx, st_fx->core_brate, st_fx->bwidth, &st_fx->Q_stat_noise, &st_fx->Q_stat_noise_ge ); } - return ; + return; } diff --git a/lib_dec/swb_bwe_dec.c b/lib_dec/swb_bwe_dec.c index 7d4427f70..bcee86982 100644 --- a/lib_dec/swb_bwe_dec.c +++ b/lib_dec/swb_bwe_dec.c @@ -221,289 +221,287 @@ static int16_t para_pred_bws( #endif #ifdef IVAS_FLOAT_FIXED -static -Word16 para_pred_bws_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *signal_wb_fx, /* i : wideband frequency signal */ - Word16 *SWB_fenv_fx, /* o : frequency-domain BWE envelope */ - Word16 Q_syn -) +static Word16 para_pred_bws_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *signal_wb_fx, /* i : wideband frequency signal */ + Word16 *SWB_fenv_fx, /* o : frequency-domain BWE envelope */ + Word16 Q_syn ) { - Word16 i, j, k; - Word16 mode; - Word16 tmp, tmp_den, tmp_num; - Word32 L_tmp, L_tmp_max; - Word16 exp; - Word16 *input_hi_fx; - Word32 *mea; - Word16 peak_fx, mag_fx; - Word32 mean_fx[7], peak_32_fx; - Word32 avrg1_fx, avrg2_fx, min_fx; - Word16 att_fx; - Word16 coder_type = st_fx->coder_type; - - mode = NORMAL; - move16(); - - k = 0; - move16(); - input_hi_fx = &signal_wb_fx[SHARP_WIDTH]; - move16(); - FOR(i = 0; i < 7; i++) - { - peak_fx = 0; - move16(); - mean_fx[i] = 0; - move16(); - FOR(j = 0; j < SHARP_WIDTH; j++) - { - mag_fx = abs_s(*input_hi_fx); - peak_fx = s_max(peak_fx, mag_fx); - /*IF (sub(mag_fx, peak_fx) > 0) */ - /*{ */ - /* peak_fx = mag_fx; */ - /*} */ - mean_fx[i] = L_add(mean_fx[i], L_deposit_l(mag_fx)); - move32(); - input_hi_fx++; - } - - IF(Q_syn < 11) - { - tmp = 1; - move16(); - } - ELSE - { - tmp = 0; - move16(); - if (GT_16(shr(peak_fx, 3), shl(1, Q_syn))) - { - tmp = 1; - move16(); - } - } - IF(tmp > 0) - { - L_tmp = L_msu0(Mult_32_16(L_shl(mean_fx[i], 10), 18432), peak_fx, 4544); - if (L_tmp < 0) - { - k = add(k, 1); - } - } - } - - avrg1_fx = L_deposit_l(0); - avrg2_fx = L_deposit_l(0); - FOR(i = 1; i < 4; i++) - { - avrg1_fx = L_add(avrg1_fx, mean_fx[i]); - avrg2_fx = L_add(avrg2_fx, mean_fx[i + 3]); - } - avrg1_fx = Mult_32_16(avrg1_fx, 10923); - avrg2_fx = Mult_32_16(avrg2_fx, 10923); /* 1/3 -> Q15 -> 10923 */ - - min_fx = L_add(2147483647, 0); /*2^31 */ - peak_32_fx = L_deposit_l(0); - FOR(i = 4; i < 7; i++) - { - IF(GT_32(mean_fx[i], L_shl(avrg2_fx, 1))) - { - exp = norm_l(mean_fx[i]); - IF(LT_16(exp, 16)) - { - tmp_den = extract_l(L_shr(mean_fx[i], sub(16, exp))); /*Qsyn - 16 + exp */ - tmp_num = extract_l(L_shr(avrg2_fx, sub(15, exp))); /*//Qsyn - 16 + exp */ - } - ELSE - { - tmp_den = extract_l(mean_fx[i]); - tmp_num = extract_l(L_shl(avrg2_fx, 1)); - } - - tmp_den = div_s(1, tmp_den); - - tmp = i_mult(tmp_num, tmp_den); /*Q15 */ - - mean_fx[i] = Mult_32_16(mean_fx[i], tmp); - move32(); - } - min_fx = L_min(min_fx, mean_fx[i]); - peak_32_fx = L_max(peak_32_fx, mean_fx[i]); - /*IF(L_sub(mean_fx[i], min_fx) < 0) */ - /*{ */ - /* min_fx = mean_fx[i]; */ - /*} */ - /*IF(L_sub(mean_fx[i], peak_32_fx) > 0) */ - /*{ */ - /* peak_32_fx = mean_fx[i]; */ - /*} */ - } - - IF(GT_16(st_fx->tilt_wb_fx, 16384)) - { - IF(GT_16(st_fx->tilt_wb_fx, 30720)) - { - min_fx = peak_32_fx; - } - ELSE - { - tmp = extract_l(L_shr(L_mult0(st_fx->tilt_wb_fx, 17476), 14)); /*Q15 */ - min_fx = Mult_32_16(peak_32_fx, tmp); - } - } - - test(); - IF(peak_32_fx == 0 || min_fx == 0) - { - set16_fx(SWB_fenv_fx, 0, SWB_FENV); - } - ELSE - { - exp = norm_l(peak_32_fx); - IF(LT_16(exp, 16)) - { - tmp_den = extract_l(L_shr(peak_32_fx, sub(16, exp))); /*Qsyn - 16 + exp */ - tmp = div_s(16384, tmp_den); /*Q15+14 - (Qsyn - 16 + exp) */ - tmp_num = extract_l(L_shr(min_fx, sub(16, exp))); /*Qsyn - 16 + exp */ - - tmp = extract_l(L_shr(L_mult0(tmp_num, tmp), 14)); /*Q15 */ - } - ELSE - { - tmp_den = extract_l(peak_32_fx); /*Qsyn */ - exp = norm_s(tmp_den); - tmp = div_s(shl(1, sub(14,exp)), tmp_den); /*Q 29-exp - Qsyn */ - tmp_num = extract_l(min_fx); /*Qsyn */ - - tmp = extract_l(L_shr(L_mult0(tmp_num, tmp), sub(14, exp))); /*Q15 */ - } - - j = 0; - move16(); - mea = &mean_fx[4]; - move16(); - L_tmp_max = L_shl(32767, add(Q_syn, 5)); - FOR(i = 0; i < SWB_FENV; i++) - { - IF(j == 5) - { - mea++; - move16(); - j = 0; - move16(); - } - j++; - move16(); - L_tmp = L_min(Mult_32_16(*mea, tmp), L_tmp_max); - SWB_fenv_fx[i] = extract_l(L_shr(L_tmp, add(Q_syn, 5))); - } - } - - j = 0; - move16(); - FOR(i = shr(SWB_FENV, 1); i < SWB_FENV; i++) - { - tmp = sub(32767, i_mult(j, 2341)); - move16(); - SWB_fenv_fx[i] = mult_r(SWB_fenv_fx[i], tmp); - move16(); - j++; - move16(); - } - - IF(GT_32(avrg1_fx, L_shl(avrg2_fx, 3))) - { - FOR(i = 0; i < SWB_FENV; i++) - { - SWB_fenv_fx[i] = shr(SWB_fenv_fx[i], 1); - move16(); - } - } - - test(); - test(); - test(); - test(); - test(); - IF(NE_16(st_fx->last_core, HQ_CORE) && EQ_16(st_fx->last_codec_mode, MODE1) && - (GT_32(st_fx->enerLH_fx, L_shr(st_fx->prev_enerLH_fx, 1)) && LT_32(L_shr(st_fx->enerLH_fx, 1), st_fx->prev_enerLH_fx)) && - (GT_32(st_fx->enerLL_fx, L_shr(st_fx->prev_enerLL_fx, 1)) && LT_32(L_shr(st_fx->enerLL_fx, 1), st_fx->prev_enerLL_fx))) - { - FOR(i = 0; i < SWB_FENV; i++) - { - test(); - IF(NE_16(st_fx->prev_coder_type, coder_type) && GT_16(mult_r(SWB_fenv_fx[i], 16384), st_fx->prev_SWB_fenv_fx[i])) - { - /*SWB_fenv_fx[i] = add(mult_r(SWB_fenv_fx[i], 3277), mult_r(st_fx->prev_SWB_fenv_fx[i], 29491)); */ - SWB_fenv_fx[i] = round_fx(L_mac(L_mult(SWB_fenv_fx[i], 3277), st_fx->prev_SWB_fenv_fx[i], 29491)); - } - ELSE - { - /*SWB_fenv_fx[i] = add(mult_r(SWB_fenv_fx[i], st_fx->attenu_fx), mult_r(st_fx->prev_SWB_fenv_fx[i], sub(32767, st_fx->attenu_fx))); */ - SWB_fenv_fx[i] = round_fx(L_mac(L_mult(SWB_fenv_fx[i], st_fx->attenu_fx), st_fx->prev_SWB_fenv_fx[i], sub(32767, st_fx->attenu_fx))); - } - } - - IF(LT_16(st_fx->attenu_fx, 29491)) - { - st_fx->attenu_fx = add(st_fx->attenu_fx, 1638); - move16(); - } - } - ELSE - { - test(); - test(); - test(); - test(); - IF(NE_32(st_fx->core_brate, st_fx->last_core_brate) || (GT_32(st_fx->enerLH_fx,L_shr(st_fx->prev_enerLH_fx,1)) && LT_32(L_shr(st_fx->enerLH_fx,1),st_fx->prev_enerLH_fx)) || - (GT_32(st_fx->enerLL_fx, L_shr(st_fx->prev_enerLL_fx, 1)) && LT_32(L_shr(st_fx->enerLL_fx, 1), st_fx->prev_enerLL_fx))) - { - FOR(i = 0; i < SWB_FENV; i++) - { - if (GT_16(mult_r(SWB_fenv_fx[i], 16384), st_fx->prev_SWB_fenv_fx[i])) - { - SWB_fenv_fx[i] = st_fx->prev_SWB_fenv_fx[i]; - move16(); - } - } - } - - FOR(i = 0; i < SWB_FENV; i++) - { - /*SWB_fenv_fx[i] = add(mult_r(SWB_fenv_fx[i], 29491), mult_r(st_fx->prev_SWB_fenv_fx[i], 3277)); */ - SWB_fenv_fx[i] = round_fx(L_mac(L_mult(SWB_fenv_fx[i], 29491), st_fx->prev_SWB_fenv_fx[i], 3277)); - } - st_fx->attenu_fx = 3277; - move16(); - } - - if (GT_16(k, 3)) - { - mode = HARMONIC; - move16(); - } - - - att_fx = i_mult(sub(N_WS2N_FRAMES, st_fx->bws_cnt), 819); - move16();/*15 */ - IF(EQ_16(st_fx->L_frame, L_FRAME16k)) - { - FOR(i = 0; i < 4; i++) - { - SWB_fenv_fx[i] = mult_r(SWB_fenv_fx[i], att_fx); - move16(); /*Q1 */ - } - } - - FOR(i = 4; i < SWB_FENV; i++) - { - SWB_fenv_fx[i] = mult_r(SWB_fenv_fx[i], att_fx); - move16(); /*Q1 */ - } - - return mode; + Word16 i, j, k; + Word16 mode; + Word16 tmp, tmp_den, tmp_num; + Word32 L_tmp, L_tmp_max; + Word16 exp; + Word16 *input_hi_fx; + Word32 *mea; + Word16 peak_fx, mag_fx; + Word32 mean_fx[7], peak_32_fx; + Word32 avrg1_fx, avrg2_fx, min_fx; + Word16 att_fx; + Word16 coder_type = st_fx->coder_type; + + mode = NORMAL; + move16(); + + k = 0; + move16(); + input_hi_fx = &signal_wb_fx[SHARP_WIDTH]; + move16(); + FOR( i = 0; i < 7; i++ ) + { + peak_fx = 0; + move16(); + mean_fx[i] = 0; + move16(); + FOR( j = 0; j < SHARP_WIDTH; j++ ) + { + mag_fx = abs_s( *input_hi_fx ); + peak_fx = s_max( peak_fx, mag_fx ); + /*IF (sub(mag_fx, peak_fx) > 0) */ + /*{ */ + /* peak_fx = mag_fx; */ + /*} */ + mean_fx[i] = L_add( mean_fx[i], L_deposit_l( mag_fx ) ); + move32(); + input_hi_fx++; + } + + IF( Q_syn < 11 ) + { + tmp = 1; + move16(); + } + ELSE + { + tmp = 0; + move16(); + if ( GT_16( shr( peak_fx, 3 ), shl( 1, Q_syn ) ) ) + { + tmp = 1; + move16(); + } + } + IF( tmp > 0 ) + { + L_tmp = L_msu0( Mult_32_16( L_shl( mean_fx[i], 10 ), 18432 ), peak_fx, 4544 ); + if ( L_tmp < 0 ) + { + k = add( k, 1 ); + } + } + } + + avrg1_fx = L_deposit_l( 0 ); + avrg2_fx = L_deposit_l( 0 ); + FOR( i = 1; i < 4; i++ ) + { + avrg1_fx = L_add( avrg1_fx, mean_fx[i] ); + avrg2_fx = L_add( avrg2_fx, mean_fx[i + 3] ); + } + avrg1_fx = Mult_32_16( avrg1_fx, 10923 ); + avrg2_fx = Mult_32_16( avrg2_fx, 10923 ); /* 1/3 -> Q15 -> 10923 */ + + min_fx = L_add( 2147483647, 0 ); /*2^31 */ + peak_32_fx = L_deposit_l( 0 ); + FOR( i = 4; i < 7; i++ ) + { + IF( GT_32( mean_fx[i], L_shl( avrg2_fx, 1 ) ) ) + { + exp = norm_l( mean_fx[i] ); + IF( LT_16( exp, 16 ) ) + { + tmp_den = extract_l( L_shr( mean_fx[i], sub( 16, exp ) ) ); /*Qsyn - 16 + exp */ + tmp_num = extract_l( L_shr( avrg2_fx, sub( 15, exp ) ) ); /*//Qsyn - 16 + exp */ + } + ELSE + { + tmp_den = extract_l( mean_fx[i] ); + tmp_num = extract_l( L_shl( avrg2_fx, 1 ) ); + } + + tmp_den = div_s( 1, tmp_den ); + + tmp = i_mult( tmp_num, tmp_den ); /*Q15 */ + + mean_fx[i] = Mult_32_16( mean_fx[i], tmp ); + move32(); + } + min_fx = L_min( min_fx, mean_fx[i] ); + peak_32_fx = L_max( peak_32_fx, mean_fx[i] ); + /*IF(L_sub(mean_fx[i], min_fx) < 0) */ + /*{ */ + /* min_fx = mean_fx[i]; */ + /*} */ + /*IF(L_sub(mean_fx[i], peak_32_fx) > 0) */ + /*{ */ + /* peak_32_fx = mean_fx[i]; */ + /*} */ + } + + IF( GT_16( st_fx->tilt_wb_fx, 16384 ) ) + { + IF( GT_16( st_fx->tilt_wb_fx, 30720 ) ) + { + min_fx = peak_32_fx; + } + ELSE + { + tmp = extract_l( L_shr( L_mult0( st_fx->tilt_wb_fx, 17476 ), 14 ) ); /*Q15 */ + min_fx = Mult_32_16( peak_32_fx, tmp ); + } + } + + test(); + IF( peak_32_fx == 0 || min_fx == 0 ) + { + set16_fx( SWB_fenv_fx, 0, SWB_FENV ); + } + ELSE + { + exp = norm_l( peak_32_fx ); + IF( LT_16( exp, 16 ) ) + { + tmp_den = extract_l( L_shr( peak_32_fx, sub( 16, exp ) ) ); /*Qsyn - 16 + exp */ + tmp = div_s( 16384, tmp_den ); /*Q15+14 - (Qsyn - 16 + exp) */ + tmp_num = extract_l( L_shr( min_fx, sub( 16, exp ) ) ); /*Qsyn - 16 + exp */ + + tmp = extract_l( L_shr( L_mult0( tmp_num, tmp ), 14 ) ); /*Q15 */ + } + ELSE + { + tmp_den = extract_l( peak_32_fx ); /*Qsyn */ + exp = norm_s( tmp_den ); + tmp = div_s( shl( 1, sub( 14, exp ) ), tmp_den ); /*Q 29-exp - Qsyn */ + tmp_num = extract_l( min_fx ); /*Qsyn */ + + tmp = extract_l( L_shr( L_mult0( tmp_num, tmp ), sub( 14, exp ) ) ); /*Q15 */ + } + + j = 0; + move16(); + mea = &mean_fx[4]; + move16(); + L_tmp_max = L_shl( 32767, add( Q_syn, 5 ) ); + FOR( i = 0; i < SWB_FENV; i++ ) + { + IF( j == 5 ) + { + mea++; + move16(); + j = 0; + move16(); + } + j++; + move16(); + L_tmp = L_min( Mult_32_16( *mea, tmp ), L_tmp_max ); + SWB_fenv_fx[i] = extract_l( L_shr( L_tmp, add( Q_syn, 5 ) ) ); + } + } + + j = 0; + move16(); + FOR( i = shr( SWB_FENV, 1 ); i < SWB_FENV; i++ ) + { + tmp = sub( 32767, i_mult( j, 2341 ) ); + move16(); + SWB_fenv_fx[i] = mult_r( SWB_fenv_fx[i], tmp ); + move16(); + j++; + move16(); + } + + IF( GT_32( avrg1_fx, L_shl( avrg2_fx, 3 ) ) ) + { + FOR( i = 0; i < SWB_FENV; i++ ) + { + SWB_fenv_fx[i] = shr( SWB_fenv_fx[i], 1 ); + move16(); + } + } + + test(); + test(); + test(); + test(); + test(); + IF( NE_16( st_fx->last_core, HQ_CORE ) && EQ_16( st_fx->last_codec_mode, MODE1 ) && + ( GT_32( st_fx->enerLH_fx, L_shr( st_fx->prev_enerLH_fx, 1 ) ) && LT_32( L_shr( st_fx->enerLH_fx, 1 ), st_fx->prev_enerLH_fx ) ) && + ( GT_32( st_fx->enerLL_fx, L_shr( st_fx->prev_enerLL_fx, 1 ) ) && LT_32( L_shr( st_fx->enerLL_fx, 1 ), st_fx->prev_enerLL_fx ) ) ) + { + FOR( i = 0; i < SWB_FENV; i++ ) + { + test(); + IF( NE_16( st_fx->prev_coder_type, coder_type ) && GT_16( mult_r( SWB_fenv_fx[i], 16384 ), st_fx->prev_SWB_fenv_fx[i] ) ) + { + /*SWB_fenv_fx[i] = add(mult_r(SWB_fenv_fx[i], 3277), mult_r(st_fx->prev_SWB_fenv_fx[i], 29491)); */ + SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], 3277 ), st_fx->prev_SWB_fenv_fx[i], 29491 ) ); + } + ELSE + { + /*SWB_fenv_fx[i] = add(mult_r(SWB_fenv_fx[i], st_fx->attenu_fx), mult_r(st_fx->prev_SWB_fenv_fx[i], sub(32767, st_fx->attenu_fx))); */ + SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], st_fx->attenu_fx ), st_fx->prev_SWB_fenv_fx[i], sub( 32767, st_fx->attenu_fx ) ) ); + } + } + + IF( LT_16( st_fx->attenu_fx, 29491 ) ) + { + st_fx->attenu_fx = add( st_fx->attenu_fx, 1638 ); + move16(); + } + } + ELSE + { + test(); + test(); + test(); + test(); + IF( NE_32( st_fx->core_brate, st_fx->last_core_brate ) || ( GT_32( st_fx->enerLH_fx, L_shr( st_fx->prev_enerLH_fx, 1 ) ) && LT_32( L_shr( st_fx->enerLH_fx, 1 ), st_fx->prev_enerLH_fx ) ) || + ( GT_32( st_fx->enerLL_fx, L_shr( st_fx->prev_enerLL_fx, 1 ) ) && LT_32( L_shr( st_fx->enerLL_fx, 1 ), st_fx->prev_enerLL_fx ) ) ) + { + FOR( i = 0; i < SWB_FENV; i++ ) + { + if ( GT_16( mult_r( SWB_fenv_fx[i], 16384 ), st_fx->prev_SWB_fenv_fx[i] ) ) + { + SWB_fenv_fx[i] = st_fx->prev_SWB_fenv_fx[i]; + move16(); + } + } + } + + FOR( i = 0; i < SWB_FENV; i++ ) + { + /*SWB_fenv_fx[i] = add(mult_r(SWB_fenv_fx[i], 29491), mult_r(st_fx->prev_SWB_fenv_fx[i], 3277)); */ + SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], 29491 ), st_fx->prev_SWB_fenv_fx[i], 3277 ) ); + } + st_fx->attenu_fx = 3277; + move16(); + } + + if ( GT_16( k, 3 ) ) + { + mode = HARMONIC; + move16(); + } + + + att_fx = i_mult( sub( N_WS2N_FRAMES, st_fx->bws_cnt ), 819 ); + move16(); /*15 */ + IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) + { + FOR( i = 0; i < 4; i++ ) + { + SWB_fenv_fx[i] = mult_r( SWB_fenv_fx[i], att_fx ); + move16(); /*Q1 */ + } + } + + FOR( i = 4; i < SWB_FENV; i++ ) + { + SWB_fenv_fx[i] = mult_r( SWB_fenv_fx[i], att_fx ); + move16(); /*Q1 */ + } + + return mode; } #endif // IVAS_FLOAT_FIXED @@ -1060,297 +1058,300 @@ void swb_bwe_dec_flt( #ifdef IVAS_FLOAT_FIXED Word16 swb_bwe_dec_fx32( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word32 output_fx[], /* i : synthesis @internal Fs Q11 */ - Word32 *synth_fx, /* i : ACELP core synthesis/final synthesis Q11 */ - Word32 *hb_synth_fx, /* o : SHB synthesis/final synthesis */ - Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ - Word16 output_frame /* i : frame length */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word32 output_fx[], /* i : synthesis @internal Fs Q11 */ + Word32 *synth_fx, /* i : ACELP core synthesis/final synthesis Q11 */ + Word32 *hb_synth_fx, /* o : SHB synthesis/final synthesis */ + Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ + Word16 output_frame /* i : frame length */ ) { - Word16 L; - Word16 mode; - Word16 idxGain; - Word16 i, j, l_subfr; - Word16 fb_band_begin; - Word16 frica_flag = 0; - Word16 ener_adjust_quan_fx; - Word16 fb_ener_adjust_fx = 0; - Word16 scl, new_input_fx_exp, ysynth_frame_size; - Word16 Q_syn, Q_syn_hb, tmp, tmp2, q_tmp, Qsynth_fx16; - - Word16 ysynth_fx[L_FRAME48k]; - Word16 SWB_fenv_fx[SWB_FENV]; - Word16 SWB_tenv_fx[SWB_TENV]; - Word16 synth_fx16[L_FRAME48k]; - Word16 hb_synth_fx16[L_FRAME48k]; - - Word32 L_tmp; - Word32 yerror_fx[L_FRAME48k]; - Word32 ysynth_fx32[L_FRAME48k]; - Word32 SWB_tenv_tmp_fx[SWB_TENV]; - Word32 wtda_synth_fx[2 * L_FRAME48k]; - - FD_BWE_DEC_HANDLE hBWE_FD; - hBWE_FD = st_fx->hBWE_FD; - - /*---------------------------------------------------------------------* - * SWB BWE decoding - *---------------------------------------------------------------------*/ - - IF (EQ_16(st_fx->element_mode, IVAS_CPE_DFT) && !use_cldfb_for_dft) - { - /* todo - wtda() does not support L_FRAME length; thus temporarily resample the signal */ - /* todo - delay output[] by 1.25ms ? */ - L_lerp_fx_q11(output_fx, ysynth_fx32, L_FRAME16k, st_fx->L_frame); - - /* windowing of the ACELP core synthesis */ - wtda_fx32(ysynth_fx32, wtda_synth_fx, hBWE_FD->L_old_wtda_swb_fx32, ALDO_WINDOW, ALDO_WINDOW, /*st_fx->L_frame*/ L_FRAME16k); - - /* DCT of the ACELP core synthesis */ - new_input_fx_exp = 11; - direct_transform_fx(wtda_synth_fx, ysynth_fx32, 0, /*st_fx->L_frame*/ L_FRAME16k, &new_input_fx_exp,st_fx->element_mode); - ysynth_frame_size = L_FRAME16k; - } - ELSE - { - /* windowing of the ACELP core synthesis */ - //wtda(synth, wtda_synth, hBWE_FD->old_wtda_swb, ALDO_WINDOW, ALDO_WINDOW, output_frame); - wtda_fx32(synth_fx, wtda_synth_fx, hBWE_FD->L_old_wtda_swb_fx32, ALDO_WINDOW, ALDO_WINDOW, output_frame); - - /* DCT of the ACELP core synthesis */ - //direct_transform(wtda_synth, ysynth, 0, output_frame, st_fx->element_mode); - new_input_fx_exp = 11; - direct_transform_fx(wtda_synth_fx, ysynth_fx32, 0, output_frame, &new_input_fx_exp,st_fx->element_mode); - ysynth_frame_size = output_frame; - } - - /* Convert to 16 Bits (Calc Shift Required to Stay within MAX_Q_NEW_INPUT) */ - scl = sub(16 + 11, new_input_fx_exp); - /* Possible to Upscale? */ - IF(GT_16(scl, 0)) - { - /* Yes */ - /* Calc Room to Upscale */ - Q_syn = Find_Max_Norm32(ysynth_fx32, ysynth_frame_size)-3; - /* Stay within MAX_Q_NEW_INPUT */ - scl = s_min(Q_syn, scl); - } - /*Don't upscale if already in 15 bits*/ - IF(GT_16(scl, 15)) { - FOR(i = 0; i < ysynth_frame_size; i++) { - ysynth_fx[i] = extract_l(ysynth_fx32[i]); - } - Q_syn = new_input_fx_exp; - } - ELSE{ - Copy_Scale_sig32_16(ysynth_fx32, ysynth_fx, ysynth_frame_size, scl); - Q_syn = add(sub(new_input_fx_exp, 16), scl); - } - - IF (!st_fx->bfi) - { - IF (GT_16( st_fx->bws_cnt, 0)) - { - /* estimate parameters */ - mode = para_pred_bws_fx(st_fx, ysynth_fx, SWB_fenv_fx, Q_syn); - } - ELSE - { - /* de-quantization */ - mode = swb_bwe_gain_deq_fx(st_fx, ACELP_CORE, SWB_tenv_fx, SWB_fenv_fx, 0, -1); - } - - L = SWB_FENV; - IF (EQ_16(mode, TRANSIENT)) - { - L = SWB_FENV_TRANS; - } - - L_tmp = 0; - FOR (i = 0; i < L; i++) - { - L_tmp = L_add(L_tmp, L_deposit_l(SWB_fenv_fx[i])); - } - q_tmp = norm_s(L); - tmp = div_s(shl(1, sub(14, q_tmp)), L);/*Q(29-q_tmp) */ - L_tmp = Mpy_32_16_1(L_tmp, tmp); /*Q(1+29-q_tmp+1-16)->Q(15-q_tmp) */ - st_fx->prev_ener_shb_fx = round_fx(L_shl(L_tmp, add(q_tmp, 2)));/*Q1 */ - } - ELSE - { - /* SHB FEC */ - - IF(NE_16(hBWE_FD->prev_mode, TRANSIENT)) - { - mode = hBWE_FD->prev_mode; - } - ELSE - { - mode = NORMAL; - } - - Copy(st_fx->prev_SWB_fenv_fx, SWB_fenv_fx, SWB_FENV); - } - - /* reconstruction of MDCT spectrum of the error signal */ - set32_fx(yerror_fx, 0, output_frame); - - IF(EQ_16(st_fx->L_frame, L_FRAME16k)) - { - SWB_BWE_decoding_fx(ysynth_fx, SWB_fenv_fx, yerror_fx, L_FRAME32k - 80, mode, &frica_flag, &hBWE_FD->prev_Energy_fx, st_fx->prev_SWB_fenv_fx, &hBWE_FD->prev_L_swb_norm, st_fx->tilt_wb_fx, &hBWE_FD->Seed, 80, &hBWE_FD->prev_weight_fx, st_fx->extl, Q_syn, st_fx->last_extl, st_fx->element_mode); - } - ELSE - { - SWB_BWE_decoding_fx(ysynth_fx, SWB_fenv_fx, yerror_fx, L_FRAME32k - 80, mode, &frica_flag, &hBWE_FD->prev_Energy_fx, st_fx->prev_SWB_fenv_fx, &hBWE_FD->prev_L_swb_norm, st_fx->tilt_wb_fx, &hBWE_FD->Seed, 6, &hBWE_FD->prev_weight_fx, st_fx->extl, Q_syn, st_fx->last_extl, st_fx->element_mode); - } - - - IF(EQ_16(hBWE_FD->prev_frica_flag, 1) && frica_flag == 0) - { - FOR (i = 0; i < L_SUBFR; i++) - { - tmp = sub(32767, extract_l(L_mult0(i, 512))); /*Q15 */ - hBWE_FD->mem_imdct_fx[i] = mult_r(hBWE_FD->mem_imdct_fx[i], tmp); - } - - FOR (; i < output_frame; i++) - { - hBWE_FD->mem_imdct_fx[i] = 0; - } - } - - /* decode information */ - IF(EQ_16(st_fx->extl, FB_BWE)) - { - IF (!st_fx->bfi) - { - idxGain = (Word16)get_next_indice(st_fx, NUM_BITS_FB_FRAMEGAIN); - fb_ener_adjust_fx = usdequant_fx(idxGain, FB_GAIN_QLOW_FX, FB_GAIN_QDELTA_FX); /*Q15 */ - } - ELSE IF (st_fx->bfi) - { - fb_ener_adjust_fx = st_fx->prev_fb_ener_adjust_fx; - } - - st_fx->prev_fb_ener_adjust_fx = fb_ener_adjust_fx; - IF(EQ_16(mode, TRANSIENT)) - { - ener_adjust_quan_fx = shr(fb_ener_adjust_fx, 2); - } - ELSE - { - IF (SWB_fenv_fx[7] != 0) - { - tmp = div_s(1, SWB_fenv_fx[7]); - ener_adjust_quan_fx = s_min(shr(i_mult_sat(SWB_fenv_fx[13], tmp), 2), 32767); - } - ELSE - { - ener_adjust_quan_fx = 0; - } - } - - fb_band_begin = FB_BAND_BEGIN; - IF (EQ_16(st_fx->L_frame, L_FRAME)) - { - fb_band_begin = FB_BAND_BEGIN_12k8; - } - - j = 0; - FOR (i = fb_band_begin; i < fb_band_begin + DE_OFFSET1; i++) - { - tmp = sub(32767, i_mult(j, 1024)); - tmp = mult_r(tmp, ener_adjust_quan_fx); /*Q13*/ - - tmp2 = i_mult(j, 256); /*Q13*/ - tmp2 = mult_r(tmp2, fb_ener_adjust_fx); /*Q13*/ - - tmp = add(tmp, tmp2); /*Q13*/ - yerror_fx[i] = L_shl(Mpy_32_16_1(yerror_fx[i - FB_BAND_WIDTH], tmp), 2);/*15+Q_syn */ - j = add(j, 1); - } - FOR (; i < FB_BAND_END; i++) - { - yerror_fx[i] = Mpy_32_16_1(yerror_fx[i - FB_BAND_WIDTH], fb_ener_adjust_fx);/*15+Q_syn */ - } - } - - /* iDCT of the error signal */ - Q_syn_hb = add(Q_syn, 15); - Inverse_Transform(yerror_fx, &Q_syn_hb, wtda_synth_fx, 0, output_frame, -1, st_fx->element_mode); - - /* inverse windowing of the error signal */ - window_ola_fx(wtda_synth_fx, hb_synth_fx16, &Q_syn_hb, hBWE_FD->mem_imdct_fx, &hBWE_FD->mem_imdct_exp_fx, output_frame, ALDO_WINDOW, ALDO_WINDOW, 0, 0, 0); - l_subfr = mult( output_frame , 8192); - - IF(EQ_16(mode, TRANSIENT)) - { - FOR (i = 0; i < SWB_TENV; i++) - { - SWB_tenv_tmp_fx[i] = L_mult0(SWB_tenv_fx[i], 26214); - } - - /* time envelope shaping when the current frame is TRANSIENT frame */ - time_envelop_shaping_fx(hb_synth_fx16, SWB_tenv_tmp_fx, output_frame, &Q_syn_hb); - Q_syn_hb = sub(Q_syn_hb, 3); - - hBWE_FD->prev_td_energy_fx = SWB_tenv_fx[3]; - } - ELSE IF (EQ_16(frica_flag, 1) && EQ_16(hBWE_FD->prev_frica_flag, 0)) - { - Qsynth_fx16 = Find_Max_Norm32(synth_fx, output_frame); - Qsynth_fx16 = sub(Qsynth_fx16, shr(add(sub(15, norm_s(l_subfr)),1),1)); - Copy_Scale_sig32_16(synth_fx, synth_fx16, output_frame, Qsynth_fx16); - Qsynth_fx16 = add(sub(11, 16), Qsynth_fx16); - - /* IVAS_fmToDo: synth[] is @internal_Fs!!! */ - time_reduce_pre_echo_fx(synth_fx16, hb_synth_fx16, hBWE_FD->prev_td_energy_fx, l_subfr, Qsynth_fx16, Q_syn_hb); - } - ELSE - { - tmp = i_mult2(3, l_subfr); - L_tmp = L_deposit_l(0); - - FOR (i = 0; i < l_subfr; i++) - { - L_tmp = L_mac0_sat(L_tmp, hb_synth_fx16[tmp + i], hb_synth_fx16[tmp + i]); /*(2*Q_syn_hb) */ - } - - L_tmp = Mult_32_16(L_tmp, div_s(1, l_subfr)); /*(2*Q_syn_hb) */ - hBWE_FD->prev_td_energy_fx = 0; - - IF (NE_32(L_tmp, 0)) - { - q_tmp = norm_l(L_tmp); - tmp = extract_h(L_shl(L_tmp, q_tmp)); - q_tmp = sub(q_tmp, sub(30, shl(Q_syn_hb, 1))); - - tmp = div_s(16384, tmp); - L_tmp = L_deposit_h(tmp); - L_tmp = Isqrt_lc(L_tmp, &q_tmp); /*Q(31-exp) */ - hBWE_FD->prev_td_energy_fx = round_fx(L_shl(L_tmp, sub(q_tmp, 15))); /*Q0 */ - } - - } - - IF (EQ_16(st_fx->element_mode, IVAS_CPE_DFT) && !use_cldfb_for_dft) - { - Qsynth_fx16 = add(sub(16, 11), Q_syn_hb); - Copy_Scale_sig32_16(synth_fx, synth_fx16, output_frame, Qsynth_fx16); - - /* add HB synth from hf_synth() */ - v_add_16(hb_synth_fx16, synth_fx16, hb_synth_fx16, output_frame); - } - - hBWE_FD->prev_mode = mode; - hBWE_FD->prev_frica_flag = frica_flag; - - FOR(i = 0; i < output_frame; i++) { - hb_synth_fx[i] = L_deposit_l(hb_synth_fx16[i]); - } - - return Q_syn_hb; + Word16 L; + Word16 mode; + Word16 idxGain; + Word16 i, j, l_subfr; + Word16 fb_band_begin; + Word16 frica_flag = 0; + Word16 ener_adjust_quan_fx; + Word16 fb_ener_adjust_fx = 0; + Word16 scl, new_input_fx_exp, ysynth_frame_size; + Word16 Q_syn, Q_syn_hb, tmp, tmp2, q_tmp, Qsynth_fx16; + + Word16 ysynth_fx[L_FRAME48k]; + Word16 SWB_fenv_fx[SWB_FENV]; + Word16 SWB_tenv_fx[SWB_TENV]; + Word16 synth_fx16[L_FRAME48k]; + Word16 hb_synth_fx16[L_FRAME48k]; + + Word32 L_tmp; + Word32 yerror_fx[L_FRAME48k]; + Word32 ysynth_fx32[L_FRAME48k]; + Word32 SWB_tenv_tmp_fx[SWB_TENV]; + Word32 wtda_synth_fx[2 * L_FRAME48k]; + + FD_BWE_DEC_HANDLE hBWE_FD; + hBWE_FD = st_fx->hBWE_FD; + + /*---------------------------------------------------------------------* + * SWB BWE decoding + *---------------------------------------------------------------------*/ + + IF( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) && !use_cldfb_for_dft ) + { + /* todo - wtda() does not support L_FRAME length; thus temporarily resample the signal */ + /* todo - delay output[] by 1.25ms ? */ + L_lerp_fx_q11( output_fx, ysynth_fx32, L_FRAME16k, st_fx->L_frame ); + + /* windowing of the ACELP core synthesis */ + wtda_fx32( ysynth_fx32, wtda_synth_fx, hBWE_FD->L_old_wtda_swb_fx32, ALDO_WINDOW, ALDO_WINDOW, /*st_fx->L_frame*/ L_FRAME16k ); + + /* DCT of the ACELP core synthesis */ + new_input_fx_exp = 11; + direct_transform_fx( wtda_synth_fx, ysynth_fx32, 0, /*st_fx->L_frame*/ L_FRAME16k, &new_input_fx_exp, st_fx->element_mode ); + ysynth_frame_size = L_FRAME16k; + } + ELSE + { + /* windowing of the ACELP core synthesis */ + // wtda(synth, wtda_synth, hBWE_FD->old_wtda_swb, ALDO_WINDOW, ALDO_WINDOW, output_frame); + wtda_fx32( synth_fx, wtda_synth_fx, hBWE_FD->L_old_wtda_swb_fx32, ALDO_WINDOW, ALDO_WINDOW, output_frame ); + + /* DCT of the ACELP core synthesis */ + // direct_transform(wtda_synth, ysynth, 0, output_frame, st_fx->element_mode); + new_input_fx_exp = 11; + direct_transform_fx( wtda_synth_fx, ysynth_fx32, 0, output_frame, &new_input_fx_exp, st_fx->element_mode ); + ysynth_frame_size = output_frame; + } + + /* Convert to 16 Bits (Calc Shift Required to Stay within MAX_Q_NEW_INPUT) */ + scl = sub( 16 + 11, new_input_fx_exp ); + /* Possible to Upscale? */ + IF( GT_16( scl, 0 ) ) + { + /* Yes */ + /* Calc Room to Upscale */ + Q_syn = Find_Max_Norm32( ysynth_fx32, ysynth_frame_size ) - 3; + /* Stay within MAX_Q_NEW_INPUT */ + scl = s_min( Q_syn, scl ); + } + /*Don't upscale if already in 15 bits*/ + IF( GT_16( scl, 15 ) ) + { + FOR( i = 0; i < ysynth_frame_size; i++ ) + { + ysynth_fx[i] = extract_l( ysynth_fx32[i] ); + } + Q_syn = new_input_fx_exp; + } + ELSE + { + Copy_Scale_sig32_16( ysynth_fx32, ysynth_fx, ysynth_frame_size, scl ); + Q_syn = add( sub( new_input_fx_exp, 16 ), scl ); + } + + IF( !st_fx->bfi ) + { + IF( GT_16( st_fx->bws_cnt, 0 ) ) + { + /* estimate parameters */ + mode = para_pred_bws_fx( st_fx, ysynth_fx, SWB_fenv_fx, Q_syn ); + } + ELSE + { + /* de-quantization */ + mode = swb_bwe_gain_deq_fx( st_fx, ACELP_CORE, SWB_tenv_fx, SWB_fenv_fx, 0, -1 ); + } + + L = SWB_FENV; + IF( EQ_16( mode, TRANSIENT ) ) + { + L = SWB_FENV_TRANS; + } + + L_tmp = 0; + FOR( i = 0; i < L; i++ ) + { + L_tmp = L_add( L_tmp, L_deposit_l( SWB_fenv_fx[i] ) ); + } + q_tmp = norm_s( L ); + tmp = div_s( shl( 1, sub( 14, q_tmp ) ), L ); /*Q(29-q_tmp) */ + L_tmp = Mpy_32_16_1( L_tmp, tmp ); /*Q(1+29-q_tmp+1-16)->Q(15-q_tmp) */ + st_fx->prev_ener_shb_fx = round_fx( L_shl( L_tmp, add( q_tmp, 2 ) ) ); /*Q1 */ + } + ELSE + { + /* SHB FEC */ + + IF( NE_16( hBWE_FD->prev_mode, TRANSIENT ) ) + { + mode = hBWE_FD->prev_mode; + } + ELSE + { + mode = NORMAL; + } + + Copy( st_fx->prev_SWB_fenv_fx, SWB_fenv_fx, SWB_FENV ); + } + + /* reconstruction of MDCT spectrum of the error signal */ + set32_fx( yerror_fx, 0, output_frame ); + + IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) + { + SWB_BWE_decoding_fx( ysynth_fx, SWB_fenv_fx, yerror_fx, L_FRAME32k - 80, mode, &frica_flag, &hBWE_FD->prev_Energy_fx, st_fx->prev_SWB_fenv_fx, &hBWE_FD->prev_L_swb_norm, st_fx->tilt_wb_fx, &hBWE_FD->Seed, 80, &hBWE_FD->prev_weight_fx, st_fx->extl, Q_syn, st_fx->last_extl, st_fx->element_mode ); + } + ELSE + { + SWB_BWE_decoding_fx( ysynth_fx, SWB_fenv_fx, yerror_fx, L_FRAME32k - 80, mode, &frica_flag, &hBWE_FD->prev_Energy_fx, st_fx->prev_SWB_fenv_fx, &hBWE_FD->prev_L_swb_norm, st_fx->tilt_wb_fx, &hBWE_FD->Seed, 6, &hBWE_FD->prev_weight_fx, st_fx->extl, Q_syn, st_fx->last_extl, st_fx->element_mode ); + } + + + IF( EQ_16( hBWE_FD->prev_frica_flag, 1 ) && frica_flag == 0 ) + { + FOR( i = 0; i < L_SUBFR; i++ ) + { + tmp = sub( 32767, extract_l( L_mult0( i, 512 ) ) ); /*Q15 */ + hBWE_FD->mem_imdct_fx[i] = mult_r( hBWE_FD->mem_imdct_fx[i], tmp ); + } + + FOR( ; i < output_frame; i++ ) + { + hBWE_FD->mem_imdct_fx[i] = 0; + } + } + + /* decode information */ + IF( EQ_16( st_fx->extl, FB_BWE ) ) + { + IF( !st_fx->bfi ) + { + idxGain = (Word16) get_next_indice( st_fx, NUM_BITS_FB_FRAMEGAIN ); + fb_ener_adjust_fx = usdequant_fx( idxGain, FB_GAIN_QLOW_FX, FB_GAIN_QDELTA_FX ); /*Q15 */ + } + ELSE IF( st_fx->bfi ) + { + fb_ener_adjust_fx = st_fx->prev_fb_ener_adjust_fx; + } + + st_fx->prev_fb_ener_adjust_fx = fb_ener_adjust_fx; + IF( EQ_16( mode, TRANSIENT ) ) + { + ener_adjust_quan_fx = shr( fb_ener_adjust_fx, 2 ); + } + ELSE + { + IF( SWB_fenv_fx[7] != 0 ) + { + tmp = div_s( 1, SWB_fenv_fx[7] ); + ener_adjust_quan_fx = s_min( shr( i_mult_sat( SWB_fenv_fx[13], tmp ), 2 ), 32767 ); + } + ELSE + { + ener_adjust_quan_fx = 0; + } + } + + fb_band_begin = FB_BAND_BEGIN; + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) + { + fb_band_begin = FB_BAND_BEGIN_12k8; + } + + j = 0; + FOR( i = fb_band_begin; i < fb_band_begin + DE_OFFSET1; i++ ) + { + tmp = sub( 32767, i_mult( j, 1024 ) ); + tmp = mult_r( tmp, ener_adjust_quan_fx ); /*Q13*/ + + tmp2 = i_mult( j, 256 ); /*Q13*/ + tmp2 = mult_r( tmp2, fb_ener_adjust_fx ); /*Q13*/ + + tmp = add( tmp, tmp2 ); /*Q13*/ + yerror_fx[i] = L_shl( Mpy_32_16_1( yerror_fx[i - FB_BAND_WIDTH], tmp ), 2 ); /*15+Q_syn */ + j = add( j, 1 ); + } + FOR( ; i < FB_BAND_END; i++ ) + { + yerror_fx[i] = Mpy_32_16_1( yerror_fx[i - FB_BAND_WIDTH], fb_ener_adjust_fx ); /*15+Q_syn */ + } + } + + /* iDCT of the error signal */ + Q_syn_hb = add( Q_syn, 15 ); + Inverse_Transform( yerror_fx, &Q_syn_hb, wtda_synth_fx, 0, output_frame, -1, st_fx->element_mode ); + + /* inverse windowing of the error signal */ + window_ola_fx( wtda_synth_fx, hb_synth_fx16, &Q_syn_hb, hBWE_FD->mem_imdct_fx, &hBWE_FD->mem_imdct_exp_fx, output_frame, ALDO_WINDOW, ALDO_WINDOW, 0, 0, 0 ); + l_subfr = mult( output_frame, 8192 ); + + IF( EQ_16( mode, TRANSIENT ) ) + { + FOR( i = 0; i < SWB_TENV; i++ ) + { + SWB_tenv_tmp_fx[i] = L_mult0( SWB_tenv_fx[i], 26214 ); + } + + /* time envelope shaping when the current frame is TRANSIENT frame */ + time_envelop_shaping_fx( hb_synth_fx16, SWB_tenv_tmp_fx, output_frame, &Q_syn_hb ); + Q_syn_hb = sub( Q_syn_hb, 3 ); + + hBWE_FD->prev_td_energy_fx = SWB_tenv_fx[3]; + } + ELSE IF( EQ_16( frica_flag, 1 ) && EQ_16( hBWE_FD->prev_frica_flag, 0 ) ) + { + Qsynth_fx16 = Find_Max_Norm32( synth_fx, output_frame ); + Qsynth_fx16 = sub( Qsynth_fx16, shr( add( sub( 15, norm_s( l_subfr ) ), 1 ), 1 ) ); + Copy_Scale_sig32_16( synth_fx, synth_fx16, output_frame, Qsynth_fx16 ); + Qsynth_fx16 = add( sub( 11, 16 ), Qsynth_fx16 ); + + /* IVAS_fmToDo: synth[] is @internal_Fs!!! */ + time_reduce_pre_echo_fx( synth_fx16, hb_synth_fx16, hBWE_FD->prev_td_energy_fx, l_subfr, Qsynth_fx16, Q_syn_hb ); + } + ELSE + { + tmp = i_mult2( 3, l_subfr ); + L_tmp = L_deposit_l( 0 ); + + FOR( i = 0; i < l_subfr; i++ ) + { + L_tmp = L_mac0_sat( L_tmp, hb_synth_fx16[tmp + i], hb_synth_fx16[tmp + i] ); /*(2*Q_syn_hb) */ + } + + L_tmp = Mult_32_16( L_tmp, div_s( 1, l_subfr ) ); /*(2*Q_syn_hb) */ + hBWE_FD->prev_td_energy_fx = 0; + + IF( NE_32( L_tmp, 0 ) ) + { + q_tmp = norm_l( L_tmp ); + tmp = extract_h( L_shl( L_tmp, q_tmp ) ); + q_tmp = sub( q_tmp, sub( 30, shl( Q_syn_hb, 1 ) ) ); + + tmp = div_s( 16384, tmp ); + L_tmp = L_deposit_h( tmp ); + L_tmp = Isqrt_lc( L_tmp, &q_tmp ); /*Q(31-exp) */ + hBWE_FD->prev_td_energy_fx = round_fx( L_shl( L_tmp, sub( q_tmp, 15 ) ) ); /*Q0 */ + } + } + + IF( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) && !use_cldfb_for_dft ) + { + Qsynth_fx16 = add( sub( 16, 11 ), Q_syn_hb ); + Copy_Scale_sig32_16( synth_fx, synth_fx16, output_frame, Qsynth_fx16 ); + + /* add HB synth from hf_synth() */ + v_add_16( hb_synth_fx16, synth_fx16, hb_synth_fx16, output_frame ); + } + + hBWE_FD->prev_mode = mode; + hBWE_FD->prev_frica_flag = frica_flag; + + FOR( i = 0; i < output_frame; i++ ) + { + hb_synth_fx[i] = L_deposit_l( hb_synth_fx16[i] ); + } + + return Q_syn_hb; } #endif // IVAS_FLOAT_FIXED diff --git a/lib_dec/swb_bwe_dec_fx.c b/lib_dec/swb_bwe_dec_fx.c index 306643818..34167dc29 100644 --- a/lib_dec/swb_bwe_dec_fx.c +++ b/lib_dec/swb_bwe_dec_fx.c @@ -11,22 +11,20 @@ #include "rom_enc.h" #include "ivas_prot_fx.h" -#define MAX_Q_NEW_INPUT 8 -#define Q_WTDA_FX 13 -#define Q_32_BITS 15 +#define MAX_Q_NEW_INPUT 8 +#define Q_WTDA_FX 13 +#define Q_32_BITS 15 /*-------------------------------------------------------------------* * para_pred_bws() * * predict SWB parameters for bandwidth switching *-------------------------------------------------------------------*/ -static -Word16 para_pred_bws_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *signal_wb_fx, /* i : wideband frequency signal */ - Word16 *SWB_fenv_fx, /* o : frequency-domain BWE envelope */ - Word16 Q_syn -) +static Word16 para_pred_bws_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *signal_wb_fx, /* i : wideband frequency signal */ + Word16 *SWB_fenv_fx, /* o : frequency-domain BWE envelope */ + Word16 Q_syn ) { Word16 i, j, k; Word16 mode; @@ -48,26 +46,26 @@ Word16 para_pred_bws_fx( move16(); input_hi_fx = &signal_wb_fx[SHARP_WIDTH]; move16(); - FOR(i = 0; i < 7; i ++) + FOR( i = 0; i < 7; i++ ) { peak_fx = 0; move16(); mean_fx[i] = 0; move16(); - FOR(j = 0; j < SHARP_WIDTH; j ++) + FOR( j = 0; j < SHARP_WIDTH; j++ ) { - mag_fx = abs_s(*input_hi_fx); - peak_fx = s_max(peak_fx ,mag_fx); + mag_fx = abs_s( *input_hi_fx ); + peak_fx = s_max( peak_fx, mag_fx ); /*IF (sub(mag_fx, peak_fx) > 0) */ /*{ */ /* peak_fx = mag_fx; */ /*} */ - mean_fx[i] = L_add(mean_fx[i], L_deposit_l(mag_fx)); + mean_fx[i] = L_add( mean_fx[i], L_deposit_l( mag_fx ) ); move32(); - input_hi_fx ++; + input_hi_fx++; } - IF(Q_syn < 11) + IF( Q_syn < 11 ) { tmp = 1; move16(); @@ -76,59 +74,59 @@ Word16 para_pred_bws_fx( { tmp = 0; move16(); - if(GT_16(shr(peak_fx, 3), shl(1, Q_syn))) + if ( GT_16( shr( peak_fx, 3 ), shl( 1, Q_syn ) ) ) { tmp = 1; move16(); } } - IF( tmp > 0) + IF( tmp > 0 ) { - L_tmp = L_msu0(Mult_32_16(L_shl(mean_fx[i], 10), 18432), peak_fx, 4544); - if (L_tmp < 0) + L_tmp = L_msu0( Mult_32_16( L_shl( mean_fx[i], 10 ), 18432 ), peak_fx, 4544 ); + if ( L_tmp < 0 ) { - k = add(k, 1); + k = add( k, 1 ); } } } - avrg1_fx = L_deposit_l(0); - avrg2_fx = L_deposit_l(0); - FOR(i=1; i<4; i++) + avrg1_fx = L_deposit_l( 0 ); + avrg2_fx = L_deposit_l( 0 ); + FOR( i = 1; i < 4; i++ ) { - avrg1_fx = L_add(avrg1_fx, mean_fx[i]); - avrg2_fx = L_add(avrg2_fx, mean_fx[i+3]); + avrg1_fx = L_add( avrg1_fx, mean_fx[i] ); + avrg2_fx = L_add( avrg2_fx, mean_fx[i + 3] ); } - avrg1_fx = Mult_32_16(avrg1_fx, 10923); - avrg2_fx = Mult_32_16(avrg2_fx, 10923); /* 1/3 -> Q15 -> 10923 */ + avrg1_fx = Mult_32_16( avrg1_fx, 10923 ); + avrg2_fx = Mult_32_16( avrg2_fx, 10923 ); /* 1/3 -> Q15 -> 10923 */ - min_fx = L_add(2147483647, 0); /*2^31 */ - peak_32_fx = L_deposit_l(0); - FOR(i = 4; i < 7; i ++) + min_fx = L_add( 2147483647, 0 ); /*2^31 */ + peak_32_fx = L_deposit_l( 0 ); + FOR( i = 4; i < 7; i++ ) { - IF(GT_32(mean_fx[i], L_shl(avrg2_fx, 1))) + IF( GT_32( mean_fx[i], L_shl( avrg2_fx, 1 ) ) ) { - exp = norm_l(mean_fx[i]); - IF(LT_16(exp, 16)) + exp = norm_l( mean_fx[i] ); + IF( LT_16( exp, 16 ) ) { - tmp_den = extract_l(L_shr(mean_fx[i], sub(16, exp))); /*Qsyn - 16 + exp */ - tmp_num = extract_l(L_shr(avrg2_fx, sub(15, exp))); /*//Qsyn - 16 + exp */ + tmp_den = extract_l( L_shr( mean_fx[i], sub( 16, exp ) ) ); /*Qsyn - 16 + exp */ + tmp_num = extract_l( L_shr( avrg2_fx, sub( 15, exp ) ) ); /*//Qsyn - 16 + exp */ } ELSE { - tmp_den = extract_l(mean_fx[i]); - tmp_num = extract_l(L_shl(avrg2_fx, 1)); + tmp_den = extract_l( mean_fx[i] ); + tmp_num = extract_l( L_shl( avrg2_fx, 1 ) ); } - tmp_den = div_s(1, tmp_den); + tmp_den = div_s( 1, tmp_den ); - tmp = i_mult(tmp_num, tmp_den); /*Q15 */ + tmp = i_mult( tmp_num, tmp_den ); /*Q15 */ - mean_fx[i] = Mult_32_16(mean_fx[i], tmp); + mean_fx[i] = Mult_32_16( mean_fx[i], tmp ); move32(); } - min_fx = L_min(min_fx, mean_fx[i]); - peak_32_fx = L_max(peak_32_fx, mean_fx[i]); + min_fx = L_min( min_fx, mean_fx[i] ); + peak_32_fx = L_max( peak_32_fx, mean_fx[i] ); /*IF(L_sub(mean_fx[i], min_fx) < 0) */ /*{ */ /* min_fx = mean_fx[i]; */ @@ -139,53 +137,53 @@ Word16 para_pred_bws_fx( /*} */ } - IF(GT_16(st_fx->tilt_wb_fx, 16384)) + IF( GT_16( st_fx->tilt_wb_fx, 16384 ) ) { - IF(GT_16(st_fx->tilt_wb_fx, 30720)) + IF( GT_16( st_fx->tilt_wb_fx, 30720 ) ) { min_fx = peak_32_fx; } ELSE { - tmp = extract_l(L_shr(L_mult0(st_fx->tilt_wb_fx, 17476), 14)); /*Q15 */ - min_fx = Mult_32_16(peak_32_fx, tmp); + tmp = extract_l( L_shr( L_mult0( st_fx->tilt_wb_fx, 17476 ), 14 ) ); /*Q15 */ + min_fx = Mult_32_16( peak_32_fx, tmp ); } } test(); - IF(peak_32_fx == 0 || min_fx == 0) + IF( peak_32_fx == 0 || min_fx == 0 ) { - set16_fx(SWB_fenv_fx, 0, SWB_FENV); + set16_fx( SWB_fenv_fx, 0, SWB_FENV ); } ELSE { - exp = norm_l(peak_32_fx); - IF(LT_16(exp, 16)) + exp = norm_l( peak_32_fx ); + IF( LT_16( exp, 16 ) ) { - tmp_den = extract_l(L_shr(peak_32_fx, sub(16, exp))); /*Qsyn - 16 + exp */ - tmp = div_s(16384, tmp_den); /*Q15+14 - (Qsyn - 16 + exp) */ - tmp_num = extract_l(L_shr(min_fx, sub(16, exp))); /*Qsyn - 16 + exp */ + tmp_den = extract_l( L_shr( peak_32_fx, sub( 16, exp ) ) ); /*Qsyn - 16 + exp */ + tmp = div_s( 16384, tmp_den ); /*Q15+14 - (Qsyn - 16 + exp) */ + tmp_num = extract_l( L_shr( min_fx, sub( 16, exp ) ) ); /*Qsyn - 16 + exp */ - tmp = extract_l(L_shr(L_mult0(tmp_num, tmp), 14)); /*Q15 */ + tmp = extract_l( L_shr( L_mult0( tmp_num, tmp ), 14 ) ); /*Q15 */ } ELSE { - tmp_den = extract_l(peak_32_fx); /*Qsyn */ - exp = norm_s(tmp_den); - tmp = div_s(shl(1, sub(14,exp)), tmp_den); /*Q 29-exp - Qsyn */ - tmp_num = extract_l(min_fx); /*Qsyn */ + tmp_den = extract_l( peak_32_fx ); /*Qsyn */ + exp = norm_s( tmp_den ); + tmp = div_s( shl( 1, sub( 14, exp ) ), tmp_den ); /*Q 29-exp - Qsyn */ + tmp_num = extract_l( min_fx ); /*Qsyn */ - tmp = extract_l(L_shr(L_mult0(tmp_num, tmp), sub(14, exp))); /*Q15 */ + tmp = extract_l( L_shr( L_mult0( tmp_num, tmp ), sub( 14, exp ) ) ); /*Q15 */ } j = 0; move16(); mea = &mean_fx[4]; move16(); - L_tmp_max = L_shl(32767, add(Q_syn, 5)); - FOR(i = 0; i < SWB_FENV; i++) + L_tmp_max = L_shl( 32767, add( Q_syn, 5 ) ); + FOR( i = 0; i < SWB_FENV; i++ ) { - IF(j == 5) + IF( j == 5 ) { mea++; move16(); @@ -194,28 +192,28 @@ Word16 para_pred_bws_fx( } j++; move16(); - L_tmp = L_min(Mult_32_16(*mea, tmp), L_tmp_max); - SWB_fenv_fx[i] = extract_l(L_shr(L_tmp, add(Q_syn, 5))); + L_tmp = L_min( Mult_32_16( *mea, tmp ), L_tmp_max ); + SWB_fenv_fx[i] = extract_l( L_shr( L_tmp, add( Q_syn, 5 ) ) ); } } j = 0; move16(); - FOR(i = shr(SWB_FENV, 1); i < SWB_FENV; i++) + FOR( i = shr( SWB_FENV, 1 ); i < SWB_FENV; i++ ) { - tmp = sub(32767, i_mult(j, 2341)); + tmp = sub( 32767, i_mult( j, 2341 ) ); move16(); - SWB_fenv_fx[i] = mult_r(SWB_fenv_fx[i], tmp); + SWB_fenv_fx[i] = mult_r( SWB_fenv_fx[i], tmp ); move16(); j++; move16(); } - IF(GT_32(avrg1_fx, L_shl(avrg2_fx, 3))) + IF( GT_32( avrg1_fx, L_shl( avrg2_fx, 3 ) ) ) { - FOR(i = 0; i < SWB_FENV; i ++) + FOR( i = 0; i < SWB_FENV; i++ ) { - SWB_fenv_fx[i] = shr(SWB_fenv_fx[i], 1); + SWB_fenv_fx[i] = shr( SWB_fenv_fx[i], 1 ); move16(); } } @@ -225,28 +223,28 @@ Word16 para_pred_bws_fx( test(); test(); test(); - IF( NE_16(st_fx->last_core, HQ_CORE)&&EQ_16(st_fx->last_codec_mode,MODE1)&& - (GT_32(st_fx->enerLH_fx, L_shr(st_fx->prev_enerLH_fx, 1)) && LT_32(L_shr(st_fx->enerLH_fx, 1), st_fx->prev_enerLH_fx) ) && - (GT_32(st_fx->enerLL_fx, L_shr(st_fx->prev_enerLL_fx, 1)) && LT_32(L_shr(st_fx->enerLL_fx, 1), st_fx->prev_enerLL_fx) ) ) + IF( NE_16( st_fx->last_core, HQ_CORE ) && EQ_16( st_fx->last_codec_mode, MODE1 ) && + ( GT_32( st_fx->enerLH_fx, L_shr( st_fx->prev_enerLH_fx, 1 ) ) && LT_32( L_shr( st_fx->enerLH_fx, 1 ), st_fx->prev_enerLH_fx ) ) && + ( GT_32( st_fx->enerLL_fx, L_shr( st_fx->prev_enerLL_fx, 1 ) ) && LT_32( L_shr( st_fx->enerLL_fx, 1 ), st_fx->prev_enerLL_fx ) ) ) { - FOR(i=0; iprev_coder_type, coder_type)&>_16(mult_r(SWB_fenv_fx[i],16384), st_fx->prev_SWB_fenv_fx[i])) + IF( NE_16( st_fx->prev_coder_type, coder_type ) && GT_16( mult_r( SWB_fenv_fx[i], 16384 ), st_fx->prev_SWB_fenv_fx[i] ) ) { /*SWB_fenv_fx[i] = add(mult_r(SWB_fenv_fx[i], 3277), mult_r(st_fx->prev_SWB_fenv_fx[i], 29491)); */ - SWB_fenv_fx[i] = round_fx(L_mac(L_mult(SWB_fenv_fx[i], 3277), st_fx->prev_SWB_fenv_fx[i], 29491)); + SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], 3277 ), st_fx->prev_SWB_fenv_fx[i], 29491 ) ); } ELSE { /*SWB_fenv_fx[i] = add(mult_r(SWB_fenv_fx[i], st_fx->attenu_fx), mult_r(st_fx->prev_SWB_fenv_fx[i], sub(32767, st_fx->attenu_fx))); */ - SWB_fenv_fx[i] = round_fx(L_mac(L_mult(SWB_fenv_fx[i], st_fx->attenu_fx), st_fx->prev_SWB_fenv_fx[i], sub(32767, st_fx->attenu_fx))); + SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], st_fx->attenu_fx ), st_fx->prev_SWB_fenv_fx[i], sub( 32767, st_fx->attenu_fx ) ) ); } } - IF(LT_16(st_fx->attenu_fx, 29491)) + IF( LT_16( st_fx->attenu_fx, 29491 ) ) { - st_fx->attenu_fx = add(st_fx->attenu_fx, 1638); + st_fx->attenu_fx = add( st_fx->attenu_fx, 1638 ); move16(); } } @@ -256,12 +254,12 @@ Word16 para_pred_bws_fx( test(); test(); test(); - IF( NE_32(st_fx->core_brate, st_fx->last_core_brate)||(GT_32(st_fx->enerLH_fx,L_shr(st_fx->prev_enerLH_fx,1))&<_32(L_shr(st_fx->enerLH_fx,1),st_fx->prev_enerLH_fx))|| - (GT_32(st_fx->enerLL_fx, L_shr(st_fx->prev_enerLL_fx, 1)) && LT_32(L_shr(st_fx->enerLL_fx, 1), st_fx->prev_enerLL_fx) ) ) + IF( NE_32( st_fx->core_brate, st_fx->last_core_brate ) || ( GT_32( st_fx->enerLH_fx, L_shr( st_fx->prev_enerLH_fx, 1 ) ) && LT_32( L_shr( st_fx->enerLH_fx, 1 ), st_fx->prev_enerLH_fx ) ) || + ( GT_32( st_fx->enerLL_fx, L_shr( st_fx->prev_enerLL_fx, 1 ) ) && LT_32( L_shr( st_fx->enerLL_fx, 1 ), st_fx->prev_enerLL_fx ) ) ) { - FOR(i=0; iprev_SWB_fenv_fx[i])) + if ( GT_16( mult_r( SWB_fenv_fx[i], 16384 ), st_fx->prev_SWB_fenv_fx[i] ) ) { SWB_fenv_fx[i] = st_fx->prev_SWB_fenv_fx[i]; move16(); @@ -269,37 +267,37 @@ Word16 para_pred_bws_fx( } } - FOR(i=0; iprev_SWB_fenv_fx[i], 3277)); */ - SWB_fenv_fx[i] = round_fx(L_mac(L_mult(SWB_fenv_fx[i], 29491), st_fx->prev_SWB_fenv_fx[i], 3277)); + SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], 29491 ), st_fx->prev_SWB_fenv_fx[i], 3277 ) ); } st_fx->attenu_fx = 3277; move16(); } - if(GT_16(k, 3)) + if ( GT_16( k, 3 ) ) { mode = HARMONIC; move16(); } - att_fx = i_mult(sub(N_WS2N_FRAMES, st_fx->bws_cnt), 819); - move16();/*15 */ - IF( EQ_16(st_fx->L_frame, L_FRAME16k)) + att_fx = i_mult( sub( N_WS2N_FRAMES, st_fx->bws_cnt ), 819 ); + move16(); /*15 */ + IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { FOR( i = 0; i < 4; i++ ) { - SWB_fenv_fx[i] = mult_r(SWB_fenv_fx[i], att_fx); - move16(); /*Q1 */ + SWB_fenv_fx[i] = mult_r( SWB_fenv_fx[i], att_fx ); + move16(); /*Q1 */ } } - FOR( i=4; ielement_mode == IVAS_CPE_DFT && !use_cldfb_for_dft) + if ( st->element_mode == IVAS_CPE_DFT && !use_cldfb_for_dft ) { /* IVAS_fmToDo: wtda() does not support L_FRAME length; thus temporarily resample the signal */ /* IVAS_fmToDo: delay output[] by 1.25ms ? */ - lerp(output, ysynth, L_FRAME16k, st->L_frame); + lerp( output, ysynth, L_FRAME16k, st->L_frame ); - wtda(ysynth, wtda_synth, hBWE_FD->old_wtda_swb, ALDO_WINDOW, ALDO_WINDOW, /*st->L_frame*/ L_FRAME16k); - direct_transform(wtda_synth, ysynth, 0, /*st->L_frame*/ L_FRAME16k, st->element_mode); + wtda( ysynth, wtda_synth, hBWE_FD->old_wtda_swb, ALDO_WINDOW, ALDO_WINDOW, /*st->L_frame*/ L_FRAME16k ); + direct_transform( wtda_synth, ysynth, 0, /*st->L_frame*/ L_FRAME16k, st->element_mode ); } else #endif { - wtda_fx(synth_fx, &new_input_fx_exp, L_wtda_synth_fx, hBWE_FD->L_old_wtda_swb_fx, - &hBWE_FD->old_wtda_swb_fx_exp, ALDO_WINDOW, ALDO_WINDOW, /* window overlap of current frame (0: full, 2: none, or 3: half) */ - output_frame); - *Qpost = sub(new_input_fx_exp, 15); + wtda_fx( synth_fx, &new_input_fx_exp, L_wtda_synth_fx, hBWE_FD->L_old_wtda_swb_fx, + &hBWE_FD->old_wtda_swb_fx_exp, ALDO_WINDOW, ALDO_WINDOW, /* window overlap of current frame (0: full, 2: none, or 3: half) */ + output_frame ); + *Qpost = sub( new_input_fx_exp, 15 ); /* DCT of the ACELP core synthesis */ - direct_transform_fx(L_wtda_synth_fx, ysynth_32, 0, output_frame, &new_input_fx_exp, st_fx->element_mode); + direct_transform_fx( L_wtda_synth_fx, ysynth_32, 0, output_frame, &new_input_fx_exp, st_fx->element_mode ); } /* Convert to 16 Bits (Calc Shift Required to Stay within MAX_Q_NEW_INPUT) */ - scl = sub(16+MAX_Q_NEW_INPUT, new_input_fx_exp); + scl = sub( 16 + MAX_Q_NEW_INPUT, new_input_fx_exp ); /* Possible to Upscale? */ - IF (scl > 0) + IF( scl > 0 ) { /* Yes */ /* Calc Room to Upscale */ - Q_syn = Find_Max_Norm32(ysynth_32, output_frame); + Q_syn = Find_Max_Norm32( ysynth_32, output_frame ); /* Stay within MAX_Q_NEW_INPUT */ - scl = s_min(Q_syn, scl); + scl = s_min( Q_syn, scl ); } - Copy_Scale_sig32_16(ysynth_32, ysynth_fx, output_frame, scl); - Q_syn = add(sub(new_input_fx_exp, 16), scl); + Copy_Scale_sig32_16( ysynth_32, ysynth_fx, output_frame, scl ); + Q_syn = add( sub( new_input_fx_exp, 16 ), scl ); IF( !st_fx->bfi ) { #ifdef ADD_IVAS_BWE - IF( st_fx->extl_brate > 0) + IF( st_fx->extl_brate > 0 ) #else - IF( EQ_32(st_fx->total_brate, ACELP_13k20)) + IF( EQ_32( st_fx->total_brate, ACELP_13k20 ) ) #endif { /* de-quantization */ - mode = WB_BWE_gain_deq_fx(st_fx, WB_fenv_fx ); + mode = WB_BWE_gain_deq_fx( st_fx, WB_fenv_fx ); #ifdef BASOP_NOGLOB - st_fx->last_wb_bwe_ener_fx = mult_r(add_sat(WB_fenv_fx[0], WB_fenv_fx[1]), 16384); // this would not saturate if written like : rounf_fx(L_mac(L_mult(WB_fenv_fx[0], 16384), WB_fenv_fx[1], 16384)) + st_fx->last_wb_bwe_ener_fx = mult_r( add_sat( WB_fenv_fx[0], WB_fenv_fx[1] ), 16384 ); // this would not saturate if written like : rounf_fx(L_mac(L_mult(WB_fenv_fx[0], 16384), WB_fenv_fx[1], 16384)) #else - st_fx->last_wb_bwe_ener_fx = mult_r(add(WB_fenv_fx[0], WB_fenv_fx[1]), 16384); + st_fx->last_wb_bwe_ener_fx = mult_r( add( WB_fenv_fx[0], WB_fenv_fx[1] ), 16384 ); #endif } ELSE @@ -597,23 +594,22 @@ Word16 wb_bwe_dec_fx( int32_t tmp_brate; tmp_brate = st_fx->last_core_brate; -#if 1//def ADD_IVAS_BWE +#if 1 // def ADD_IVAS_BWE test(); - IF (EQ_32(st_fx->last_total_brate, ACELP_9k60) && EQ_16(st_fx->last_extl, SWB_TBE ) ) + IF( EQ_32( st_fx->last_total_brate, ACELP_9k60 ) && EQ_16( st_fx->last_extl, SWB_TBE ) ) { tmp_brate = ACELP_8k00; /* this is needed in order to stay BE wrt. EVS mono */ move16(); } #endif - if( NE_16(st_fx->last_extl, WB_BWE)) + if ( NE_16( st_fx->last_extl, WB_BWE ) ) { st_fx->prev_SWB_fenv_fx[0] = 0; move16(); } mode = WB_BWE_gain_pred_fx( WB_fenv_fx, ysynth_fx, coder_type, st_fx->prev_coder_type, st_fx->prev_SWB_fenv_fx[0], - voice_factors_fx, pitch_buf_fx, tmp_brate, st_fx->last_wb_bwe_ener_fx, Q_syn - ,st_fx->last_extl, st_fx->tilt_wb_fx); + voice_factors_fx, pitch_buf_fx, tmp_brate, st_fx->last_wb_bwe_ener_fx, Q_syn, st_fx->last_extl, st_fx->tilt_wb_fx ); move16(); } } @@ -622,49 +618,49 @@ Word16 wb_bwe_dec_fx( /* FEC */ mode = NORMAL; move16(); - FOR(i=0; i<2; i++) + FOR( i = 0; i < 2; i++ ) { - WB_fenv_fx[i] = mult_r(st_fx->prev_SWB_fenv_fx[i], 24576); + WB_fenv_fx[i] = mult_r( st_fx->prev_SWB_fenv_fx[i], 24576 ); } } test(); - IF( NE_16(st_fx->last_extl, WB_BWE)||st_fx->bfi) + IF( NE_16( st_fx->last_extl, WB_BWE ) || st_fx->bfi ) { Copy( WB_fenv_fx, st_fx->prev_SWB_fenv_fx, 2 ); } - exp = norm_l(hBWE_FD->prev_Energy_wb_fx); - IF(GT_16(add(st_fx->prev_Q_synth, exp),Q_syn)) + exp = norm_l( hBWE_FD->prev_Energy_wb_fx ); + IF( GT_16( add( st_fx->prev_Q_synth, exp ), Q_syn ) ) { - hBWE_FD->prev_Energy_wb_fx = L_shr(hBWE_FD->prev_Energy_wb_fx, sub(st_fx->prev_Q_synth, Q_syn)); + hBWE_FD->prev_Energy_wb_fx = L_shr( hBWE_FD->prev_Energy_wb_fx, sub( st_fx->prev_Q_synth, Q_syn ) ); } ELSE { - Q_syn = add(st_fx->prev_Q_synth, exp); - hBWE_FD->prev_Energy_wb_fx = L_shl(hBWE_FD->prev_Energy_wb_fx, exp); + Q_syn = add( st_fx->prev_Q_synth, exp ); + hBWE_FD->prev_Energy_wb_fx = L_shl( hBWE_FD->prev_Energy_wb_fx, exp ); } WB_BWE_decoding_fx( ysynth_fx, WB_fenv_fx, ysynth_32, L_FRAME16k, mode, st_fx->last_extl, &hBWE_FD->prev_Energy_wb_fx, st_fx->prev_SWB_fenv_fx, &hBWE_FD->prev_L_swb_norm, st_fx->extl, coder_type, st_fx->total_brate, &hBWE_FD->Seed, &hBWE_FD->prev_flag, st_fx->prev_coder_type, Q_syn, &Q_syn_hb ); - IF ( EQ_32(st_fx->output_Fs, 32000)) + IF( EQ_32( st_fx->output_Fs, 32000 ) ) { set32_fx( &ysynth_32[L_FRAME16k], 0, L_FRAME16k ); } - ELSE IF ( EQ_32(st_fx->output_Fs, 48000)) + ELSE IF( EQ_32( st_fx->output_Fs, 48000 ) ) { set32_fx( &ysynth_32[L_FRAME16k], 0, L_FRAME32k ); } Inverse_Transform( ysynth_32, &Q_syn_hb, t_audio32_tmp, 0, output_frame, output_frame, st_fx->element_mode ); window_ola_fx( t_audio32_tmp, hb_synth_fx, &Q_syn_hb, hBWE_FD->mem_imdct_fx, &hBWE_FD->mem_imdct_exp_fx, output_frame, - ALDO_WINDOW,ALDO_WINDOW, 0,0,0); + ALDO_WINDOW, ALDO_WINDOW, 0, 0, 0 ); #ifdef ADD_IVAS_BWE test(); - IF (EQ_16(st_fx->element_mode, IVAS_CPE_DFT) && !use_cldfb_for_dft) + IF( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) && !use_cldfb_for_dft ) { /* add HB synth from hf_synth() */ - v_add(hb_synth, synth, hb_synth, output_frame); + v_add( hb_synth, synth, hb_synth, output_frame ); } #endif hBWE_FD->prev_mode = mode; @@ -676,29 +672,29 @@ Word16 wb_bwe_dec_fx( * * Decoding of SWB parameters *-------------------------------------------------------------------*/ -Word16 swb_bwe_gain_deq_fx( /* o : BWE class */ - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 core, /* i : core */ - Word16 *SWB_tenv, /* o : Q0, time-domain BWE envelope */ - Word16 *SWB_fenv, /* o : Q1, frequency-domain BWE envelope */ - const Word16 hr_flag, /* i : high rate flag */ - const Word16 hqswb_clas /* i : HQ BWE class */ +Word16 swb_bwe_gain_deq_fx( /* o : BWE class */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 core, /* i : core */ + Word16 *SWB_tenv, /* o : Q0, time-domain BWE envelope */ + Word16 *SWB_fenv, /* o : Q1, frequency-domain BWE envelope */ + const Word16 hr_flag, /* i : high rate flag */ + const Word16 hqswb_clas /* i : HQ BWE class */ ) { Word16 index, mode, n_band; Word16 indice[6]; - Word16 quant_tmp[SWB_FENV/2], quant_tmp2[SWB_FENV/2]; + Word16 quant_tmp[SWB_FENV / 2], quant_tmp2[SWB_FENV / 2]; Word16 nb_bits[6]; Word16 nenv; - Word16 tmp,exp,frac; + Word16 tmp, exp, frac; Word32 L_tmp; - IF ( hqswb_clas > 0) + IF( hqswb_clas > 0 ) { - mode = (Word16)get_next_indice( st_fx, 1 ); - IF (mode == 0) + mode = (Word16) get_next_indice( st_fx, 1 ); + IF( mode == 0 ) { - mode = (Word16)get_next_indice( st_fx, 1 ); + mode = (Word16) get_next_indice( st_fx, 1 ); } ELSE { @@ -708,74 +704,75 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class */ } ELSE { - mode = (Word16)get_next_indice( st_fx, 2 ); + mode = (Word16) get_next_indice( st_fx, 2 ); } test(); - IF( EQ_16(mode,1)&&EQ_16(core,ACELP_CORE)) + IF( EQ_16( mode, 1 ) && EQ_16( core, ACELP_CORE ) ) { FOR( n_band = 0; n_band < SWB_TENV; n_band++ ) { - index = (Word16)get_next_indice(st_fx, 4 ); - SWB_tenv[n_band] = shl_sat(1, index); + index = (Word16) get_next_indice( st_fx, 4 ); + SWB_tenv[n_band] = shl_sat( 1, index ); move16(); } - indice[0] = (Word16)get_next_indice(st_fx, 7 ); + indice[0] = (Word16) get_next_indice( st_fx, 7 ); move16(); - indice[1] = (Word16)get_next_indice(st_fx, 6 ); + indice[1] = (Word16) get_next_indice( st_fx, 6 ); move16(); - tmp = shl(indice[0],1); - FOR(n_band = 0; n_band < DIM_TR1; n_band++) + tmp = shl( indice[0], 1 ); + FOR( n_band = 0; n_band < DIM_TR1; n_band++ ) { /*Env_TR_Cdbk1_fx[ indice[0]*DIM_TR1+n_band]*/ - quant_tmp[2*n_band] = Env_TR_Cdbk1_fx[add(tmp,n_band)];/*Q8 */ move16(); + quant_tmp[2 * n_band] = Env_TR_Cdbk1_fx[add( tmp, n_band )]; /*Q8 */ + move16(); } /*tmp = indice[1]*DIM_TR2*/ - tmp = shl(indice[1],1); + tmp = shl( indice[1], 1 ); #ifdef BASOP_NOGLOB quant_tmp[1] = add_sat( shr( add_sat( quant_tmp[0], quant_tmp[2] ), 1 ), Env_TR_Cdbk2_fx[tmp] ); /* To prevent an unnecessary saturation, it would be better to write the code as below, but might have an impact on EVS bit exactness */ /* quant_tmp[1] = add( extract_h( L_mac( L_mult( quant_tmp[0], 16384 ), quant_tmp[2], 16384 ) ), Env_TR_Cdbk2_fx[tmp] ); */ #else - quant_tmp[1] = add(shr(add(quant_tmp[0], quant_tmp[2]),1), Env_TR_Cdbk2_fx[tmp]); + quant_tmp[1] = add( shr( add( quant_tmp[0], quant_tmp[2] ), 1 ), Env_TR_Cdbk2_fx[tmp] ); #endif - move16();/*Q8 */ - quant_tmp[3] = add(quant_tmp[2],Env_TR_Cdbk2_fx[add(tmp,1)]); - move16();/*Q8 */ + move16(); /*Q8 */ + quant_tmp[3] = add( quant_tmp[2], Env_TR_Cdbk2_fx[add( tmp, 1 )] ); + move16(); /*Q8 */ - FOR(n_band = 0; n_band < SWB_FENV_TRANS; n_band++) + FOR( n_band = 0; n_band < SWB_FENV_TRANS; n_band++ ) { - tmp = add(quant_tmp[n_band], Mean_env_tr_fx[n_band]); /*Q8 */ + tmp = add( quant_tmp[n_band], Mean_env_tr_fx[n_band] ); /*Q8 */ /*-----------------------------------------------------------------* * SWB_fenv[n_band] = pow(10.0, tmp/40) * = pow(2, 3.321928*tmp/40) * = pow(2, 0.0830482*tmp) *-----------------------------------------------------------------*/ - L_tmp = L_mult(tmp, 21771); /* 0.0830482 in Q18 -> Q27 */ - L_tmp = L_shr(L_tmp, 11); /* From Q27 to Q16 */ - frac = L_Extract_lc(L_tmp, &exp); /* Extract exponent of L_tmp */ - tmp = extract_l(Pow2(13, frac)); - exp = sub(exp, 13); - SWB_fenv[n_band] = shl(tmp, add(exp, 1)); - move16();/*Q1 */ + L_tmp = L_mult( tmp, 21771 ); /* 0.0830482 in Q18 -> Q27 */ + L_tmp = L_shr( L_tmp, 11 ); /* From Q27 to Q16 */ + frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent of L_tmp */ + tmp = extract_l( Pow2( 13, frac ) ); + exp = sub( exp, 13 ); + SWB_fenv[n_band] = shl( tmp, add( exp, 1 ) ); + move16(); /*Q1 */ } /* in case of band-width switching, attenuate frame gain */ IF( st_fx->bws_cnt1 > 0 ) { - tmp = i_mult(st_fx->bws_cnt1, 1638); - FOR(n_band = 0; n_band < SWB_TENV; n_band++) + tmp = i_mult( st_fx->bws_cnt1, 1638 ); + FOR( n_band = 0; n_band < SWB_TENV; n_band++ ) { - SWB_tenv[n_band] = mult_r(SWB_tenv[n_band], tmp); + SWB_tenv[n_band] = mult_r( SWB_tenv[n_band], tmp ); move16(); } - FOR (n_band = 0; n_band < SWB_FENV_TRANS; n_band++) + FOR( n_band = 0; n_band < SWB_FENV_TRANS; n_band++ ) { - SWB_fenv[n_band] = mult_r(SWB_fenv[n_band], tmp); + SWB_fenv[n_band] = mult_r( SWB_fenv[n_band], tmp ); move16(); } } @@ -791,7 +788,7 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class */ nb_bits[3] = 5; move16(); - IF ( EQ_16(hr_flag,1)) + IF( EQ_16( hr_flag, 1 ) ) { nb_bits[4] = 5; move16(); @@ -806,113 +803,113 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class */ move16(); } - FOR (n_band = 0; n_band < 5; n_band++) + FOR( n_band = 0; n_band < 5; n_band++ ) { - indice[n_band] = (Word16) get_next_indice(st_fx, nb_bits[n_band] ); + indice[n_band] = (Word16) get_next_indice( st_fx, nb_bits[n_band] ); move16(); } - IF ( EQ_16(hqswb_clas,HQ_GEN_FB)) + IF( EQ_16( hqswb_clas, HQ_GEN_FB ) ) { - indice[n_band] = (Word16) get_next_indice(st_fx, 5 ); + indice[n_band] = (Word16) get_next_indice( st_fx, 5 ); move16(); } - Copy( &EnvCdbk11_fx[i_mult2(indice[0], DIM11)], quant_tmp, DIM11 ); - Copy( &EnvCdbk1st_fx[i_mult2(indice[1], DIM1ST)], quant_tmp2, DIM1ST ); - Copy( &EnvCdbk2nd_fx[i_mult2(indice[2], DIM2ND)], quant_tmp2+DIM1ST, DIM2ND ); + Copy( &EnvCdbk11_fx[i_mult2( indice[0], DIM11 )], quant_tmp, DIM11 ); + Copy( &EnvCdbk1st_fx[i_mult2( indice[1], DIM1ST )], quant_tmp2, DIM1ST ); + Copy( &EnvCdbk2nd_fx[i_mult2( indice[2], DIM2ND )], quant_tmp2 + DIM1ST, DIM2ND ); - FOR( n_band = 0; n_band < DIM11-1; n_band++ ) + FOR( n_band = 0; n_band < DIM11 - 1; n_band++ ) { - quant_tmp[n_band] = add(quant_tmp[n_band], quant_tmp2[n_band]); - move16();/*Q8 */ - SWB_fenv[n_band*2] = quant_tmp[n_band]; + quant_tmp[n_band] = add( quant_tmp[n_band], quant_tmp2[n_band] ); + move16(); /*Q8 */ + SWB_fenv[n_band * 2] = quant_tmp[n_band]; move16(); /*Q8 */ } - IF ( EQ_16(hr_flag,1)) + IF( EQ_16( hr_flag, 1 ) ) { - quant_tmp[6] = add(quant_tmp[6],quant_tmp2[6]); - move16();/*Q8 */ + quant_tmp[6] = add( quant_tmp[6], quant_tmp2[6] ); + move16(); /*Q8 */ SWB_fenv[11] = quant_tmp[6]; move16(); Copy( &EnvCdbk3rd_fx[indice[3] * DIM3RD], quant_tmp2, DIM3RD ); - Copy( &EnvCdbk3rd_fx[indice[4] * DIM3RD], quant_tmp2+DIM3RD, DIM3RD ); + Copy( &EnvCdbk3rd_fx[indice[4] * DIM3RD], quant_tmp2 + DIM3RD, DIM3RD ); - FOR(n_band = 0; n_band < 5; n_band++) + FOR( n_band = 0; n_band < 5; n_band++ ) { #ifdef BASOP_NOGLOB - SWB_fenv[add(shl(n_band,1),1)] = add_sat(shr(add_sat(quant_tmp[n_band], quant_tmp[n_band+1]),1), quant_tmp2[n_band+1]); + SWB_fenv[add( shl( n_band, 1 ), 1 )] = add_sat( shr( add_sat( quant_tmp[n_band], quant_tmp[n_band + 1] ), 1 ), quant_tmp2[n_band + 1] ); #else - SWB_fenv[add(shl(n_band,1),1)] = add(shr(add(quant_tmp[n_band], quant_tmp[n_band+1]),1), quant_tmp2[n_band+1]); + SWB_fenv[add( shl( n_band, 1 ), 1 )] = add( shr( add( quant_tmp[n_band], quant_tmp[n_band + 1] ), 1 ), quant_tmp2[n_band + 1] ); #endif - move16();/*Q8 */ + move16(); /*Q8 */ } - SWB_fenv[0] = add(SWB_fenv[0], quant_tmp2[0]); - move16();/*Q8 */ + SWB_fenv[0] = add( SWB_fenv[0], quant_tmp2[0] ); + move16(); /*Q8 */ } ELSE { - quant_tmp[DIM11-1]=add(quant_tmp[DIM11-1],quant_tmp2[DIM11-1]); - move16();/*Q8 */ - SWB_fenv[(DIM11-1)*2] = quant_tmp[DIM11-1]; + quant_tmp[DIM11 - 1] = add( quant_tmp[DIM11 - 1], quant_tmp2[DIM11 - 1] ); + move16(); /*Q8 */ + SWB_fenv[( DIM11 - 1 ) * 2] = quant_tmp[DIM11 - 1]; move16(); - Copy( &EnvCdbk3rd_fx[i_mult2(indice[3], DIM3RD)], quant_tmp2, DIM3RD ); - Copy( &EnvCdbk4th_fx[i_mult2(indice[4], DIM4TH)], quant_tmp2+DIM3RD, DIM4TH ); + Copy( &EnvCdbk3rd_fx[i_mult2( indice[3], DIM3RD )], quant_tmp2, DIM3RD ); + Copy( &EnvCdbk4th_fx[i_mult2( indice[4], DIM4TH )], quant_tmp2 + DIM3RD, DIM4TH ); - FOR( n_band = 0; n_band < DIM12-1; n_band++ ) + FOR( n_band = 0; n_band < DIM12 - 1; n_band++ ) { #ifdef BASOP_NOGLOB - SWB_fenv[add(shl(n_band,1),1)] = add_sat(shr(add_sat(quant_tmp[n_band],quant_tmp[n_band+1]),1),quant_tmp2[n_band]); + SWB_fenv[add( shl( n_band, 1 ), 1 )] = add_sat( shr( add_sat( quant_tmp[n_band], quant_tmp[n_band + 1] ), 1 ), quant_tmp2[n_band] ); #else - SWB_fenv[add(shl(n_band,1),1)] = add(shr(add(quant_tmp[n_band],quant_tmp[n_band+1]),1),quant_tmp2[n_band]); + SWB_fenv[add( shl( n_band, 1 ), 1 )] = add( shr( add( quant_tmp[n_band], quant_tmp[n_band + 1] ), 1 ), quant_tmp2[n_band] ); #endif - move16();/*Q8 */ + move16(); /*Q8 */ } - SWB_fenv[n_band*2+1] = add(quant_tmp[n_band],quant_tmp2[n_band]); - move16();/*Q8 */ + SWB_fenv[n_band * 2 + 1] = add( quant_tmp[n_band], quant_tmp2[n_band] ); + move16(); /*Q8 */ } FOR( n_band = 0; n_band < nenv; n_band++ ) { - tmp = add(SWB_fenv[n_band],Mean_env_fx[n_band]); /*Q8 */ + tmp = add( SWB_fenv[n_band], Mean_env_fx[n_band] ); /*Q8 */ - L_tmp = L_mult(tmp, 21771); /* 0.166096 in Q17 -> Q26 */ - L_tmp = L_shr(L_tmp, 10); /* From Q26 to Q16 */ - frac = L_Extract_lc(L_tmp, &exp); /* Extract exponent of L_tmp */ + L_tmp = L_mult( tmp, 21771 ); /* 0.166096 in Q17 -> Q26 */ + L_tmp = L_shr( L_tmp, 10 ); /* From Q26 to Q16 */ + frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent of L_tmp */ - tmp = extract_l(Pow2(13, frac));/* Put 13 as exponent so that */ + tmp = extract_l( Pow2( 13, frac ) ); /* Put 13 as exponent so that */ /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ - exp = sub(exp, 13); + exp = sub( exp, 13 ); #ifdef BASOP_NOGLOB SWB_fenv[n_band] = shl_sat( tmp, add( exp, 1 ) ); #else - SWB_fenv[n_band] = shl(tmp, add(exp,1)); + SWB_fenv[n_band] = shl( tmp, add( exp, 1 ) ); #endif - move16();/*Q1 */ + move16(); /*Q1 */ } - IF ( EQ_16(hqswb_clas,HQ_GEN_FB)) + IF( EQ_16( hqswb_clas, HQ_GEN_FB ) ) { - Copy( &EnvCdbkFB_fx[i_mult2(indice[5], DIM_FB)], &SWB_fenv[nenv], DIM_FB ); /*Q7 */ + Copy( &EnvCdbkFB_fx[i_mult2( indice[5], DIM_FB )], &SWB_fenv[nenv], DIM_FB ); /*Q7 */ FOR( n_band = 0; n_band < DIM_FB; n_band++ ) { - tmp = add(SWB_fenv[add(n_band,nenv)], Mean_env_fb_fx[n_band]); - L_tmp = L_mult(tmp, 21771); /* 0.166096 in Q17 -> Q25 */ - L_tmp = L_shr(L_tmp, 9); /* From Q25 to Q16 */ - frac = L_Extract_lc(L_tmp, &exp); /* Extract exponent of L_tmp */ + tmp = add( SWB_fenv[add( n_band, nenv )], Mean_env_fb_fx[n_band] ); + L_tmp = L_mult( tmp, 21771 ); /* 0.166096 in Q17 -> Q25 */ + L_tmp = L_shr( L_tmp, 9 ); /* From Q25 to Q16 */ + frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent of L_tmp */ - tmp = extract_l(Pow2(13, frac));/* Put 13 as exponent so that */ + tmp = extract_l( Pow2( 13, frac ) ); /* Put 13 as exponent so that */ /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ - exp = sub(exp, 13); - SWB_fenv[add(n_band,nenv)] = shl(tmp, add(exp,1)); + exp = sub( exp, 13 ); + SWB_fenv[add( n_band, nenv )] = shl( tmp, add( exp, 1 ) ); move16(); } } @@ -926,21 +923,21 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class */ /*-------------------------------------------------------------------* * swb_bwe_dec() * - * SWB BWE decoder + * SWB BWE decoder *-------------------------------------------------------------------*/ Word16 swb_bwe_dec_fx( #ifdef ADD_IVAS_BWE - const Word16 output[], /* i : suntehsis @ internal Fs */ + const Word16 output[], /* i : suntehsis @ internal Fs */ #endif - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis (might be rescaled inside wtda() ) */ - Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis (might be rescaled inside wtda() ) */ + Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis */ #ifdef ADD_IVAS_BWE const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ #endif - const Word16 output_frame /* i : frame length */ - ,Word16 * Qpost -) + const Word16 output_frame /* i : frame length */ + , + Word16 *Qpost ) { Word16 i, l_subfr; Word16 mode; @@ -950,7 +947,7 @@ Word16 swb_bwe_dec_fx( Word16 ysynth_fx[L_FRAME48k]; Word16 tmp; Word16 SWB_tenv_fx[SWB_TENV]; - Word32 L_wtda_synth_fx[2*L_FRAME48k], ysynth_32[L_FRAME48k]; + Word32 L_wtda_synth_fx[2 * L_FRAME48k], ysynth_32[L_FRAME48k]; Word16 scl, new_input_fx_exp; Word32 t_audio32_tmp[L_FRAME48k]; Word32 SWB_tenv_tmp_fx[SWB_TENV]; @@ -972,81 +969,81 @@ Word16 swb_bwe_dec_fx( /* windowing of the ACELP core synthesis */ new_input_fx_exp = *Qpost; #ifdef ADD_IVAS_BWE - if (st->element_mode == IVAS_CPE_DFT && !use_cldfb_for_dft) + if ( st->element_mode == IVAS_CPE_DFT && !use_cldfb_for_dft ) { /* IVAS_fmToDo: wtda() does not support L_FRAME length; thus temporarily resample the signal */ /* IVAS_fmToDo: delay output[] by 1.25ms ? */ - lerp(output, ysynthIfx, L_FRAME16k, st_fx->L_frame); + lerp( output, ysynthIfx, L_FRAME16k, st_fx->L_frame ); - wtda_fx(ysynth_fx, &new_input_fx_exp, L_wtda_synth_fx, hBWE_FD->L_old_wtda_swb_fx, - &hBWE_FD->old_wtda_swb_fx_exp, ALDO_WINDOW, ALDO_WINDOW, /*st->L_frame*/ L_FRAME16k); - direct_transform_fx(L_wtda_synth_fx, ysynth_32, 0, /*st->L_frame*/ L_FRAME16k, &new_input_fx_exp, st_fx->element_mode); + wtda_fx( ysynth_fx, &new_input_fx_exp, L_wtda_synth_fx, hBWE_FD->L_old_wtda_swb_fx, + &hBWE_FD->old_wtda_swb_fx_exp, ALDO_WINDOW, ALDO_WINDOW, /*st->L_frame*/ L_FRAME16k ); + direct_transform_fx( L_wtda_synth_fx, ysynth_32, 0, /*st->L_frame*/ L_FRAME16k, &new_input_fx_exp, st_fx->element_mode ); } else #endif { - wtda_fx(synth_fx, &new_input_fx_exp, L_wtda_synth_fx, hBWE_FD->L_old_wtda_swb_fx, - &hBWE_FD->old_wtda_swb_fx_exp, - ALDO_WINDOW, - ALDO_WINDOW, /* window overlap of current frame (0: full, 2: none, or 3: half) */ - output_frame); - *Qpost = sub(new_input_fx_exp, 15); + wtda_fx( synth_fx, &new_input_fx_exp, L_wtda_synth_fx, hBWE_FD->L_old_wtda_swb_fx, + &hBWE_FD->old_wtda_swb_fx_exp, + ALDO_WINDOW, + ALDO_WINDOW, /* window overlap of current frame (0: full, 2: none, or 3: half) */ + output_frame ); + *Qpost = sub( new_input_fx_exp, 15 ); /* DCT of the ACELP core synthesis */ - direct_transform_fx(L_wtda_synth_fx, ysynth_32, 0, output_frame, &new_input_fx_exp, st_fx->element_mode); + direct_transform_fx( L_wtda_synth_fx, ysynth_32, 0, output_frame, &new_input_fx_exp, st_fx->element_mode ); } /* Convert to 16 Bits (Calc Shift Required to Stay within MAX_Q_NEW_INPUT) */ - scl = sub(16+MAX_Q_NEW_INPUT, new_input_fx_exp); + scl = sub( 16 + MAX_Q_NEW_INPUT, new_input_fx_exp ); /* Possible to Upscale? */ - IF (scl > 0) + IF( scl > 0 ) { /* Yes */ /* Calc Room to Upscale */ - Q_syn = Find_Max_Norm32(ysynth_32, output_frame); + Q_syn = Find_Max_Norm32( ysynth_32, output_frame ); /* Stay within MAX_Q_NEW_INPUT */ - scl = s_min(Q_syn, scl); + scl = s_min( Q_syn, scl ); } - Copy_Scale_sig32_16(ysynth_32, ysynth_fx, output_frame, scl); - Q_syn = add(sub(new_input_fx_exp, 16), scl); + Copy_Scale_sig32_16( ysynth_32, ysynth_fx, output_frame, scl ); + Q_syn = add( sub( new_input_fx_exp, 16 ), scl ); IF( !st_fx->bfi ) { IF( st_fx->bws_cnt > 0 ) { /* estimate parameters */ - mode = para_pred_bws_fx( st_fx, ysynth_fx, SWB_fenv_fx, Q_syn); + mode = para_pred_bws_fx( st_fx, ysynth_fx, SWB_fenv_fx, Q_syn ); move16(); } ELSE { /* de-quantization */ - mode = swb_bwe_gain_deq_fx(st_fx, ACELP_CORE, SWB_tenv_fx, SWB_fenv_fx, 0, -1 ); + mode = swb_bwe_gain_deq_fx( st_fx, ACELP_CORE, SWB_tenv_fx, SWB_fenv_fx, 0, -1 ); move16(); } L = SWB_FENV; move16(); - if(EQ_16(mode, TRANSIENT)) + if ( EQ_16( mode, TRANSIENT ) ) { L = SWB_FENV_TRANS; move16(); } L_tmp = 0; move16(); - FOR(i=0; iQ(15-exp) */ - st_fx->prev_ener_shb_fx = round_fx(L_shl(L_tmp, add(exp,2))); /*Q1 */ + L_tmp = Mult_32_16( L_tmp, tmp ); /*Q(1+29-exp+1-16)->Q(15-exp) */ + st_fx->prev_ener_shb_fx = round_fx( L_shl( L_tmp, add( exp, 2 ) ) ); /*Q1 */ } ELSE { /* SHB FEC */ - IF( NE_16(hBWE_FD->prev_mode, TRANSIENT)) + IF( NE_16( hBWE_FD->prev_mode, TRANSIENT ) ) { mode = hBWE_FD->prev_mode; move16(); @@ -1057,31 +1054,30 @@ Word16 swb_bwe_dec_fx( move16(); } - Copy(st_fx->prev_SWB_fenv_fx, SWB_fenv_fx, SWB_FENV ); + Copy( st_fx->prev_SWB_fenv_fx, SWB_fenv_fx, SWB_FENV ); } /* reconstruction of MDCT spectrum of the error signal */ set32_fx( ysynth_32, 0, output_frame ); - IF ( EQ_16(st_fx->L_frame, L_FRAME16k)) + IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { - SWB_BWE_decoding_fx( ysynth_fx, SWB_fenv_fx, ysynth_32, L_FRAME32k-80, mode, &frica_flag, &hBWE_FD->prev_Energy_fx, st_fx->prev_SWB_fenv_fx, - &hBWE_FD->prev_L_swb_norm, st_fx->tilt_wb_fx, &hBWE_FD->Seed, 80, &hBWE_FD->prev_weight_fx, st_fx->extl, Q_syn - ,st_fx->last_extl, st_fx->element_mode); + SWB_BWE_decoding_fx( ysynth_fx, SWB_fenv_fx, ysynth_32, L_FRAME32k - 80, mode, &frica_flag, &hBWE_FD->prev_Energy_fx, st_fx->prev_SWB_fenv_fx, + &hBWE_FD->prev_L_swb_norm, st_fx->tilt_wb_fx, &hBWE_FD->Seed, 80, &hBWE_FD->prev_weight_fx, st_fx->extl, Q_syn, st_fx->last_extl, st_fx->element_mode ); } ELSE { - SWB_BWE_decoding_fx( ysynth_fx, SWB_fenv_fx, ysynth_32, L_FRAME32k-80, mode, &frica_flag, &hBWE_FD->prev_Energy_fx, st_fx->prev_SWB_fenv_fx, - &hBWE_FD->prev_L_swb_norm, st_fx->tilt_wb_fx, &hBWE_FD->Seed, 6, &hBWE_FD->prev_weight_fx, st_fx->extl, Q_syn, - st_fx->last_extl, st_fx->element_mode); + SWB_BWE_decoding_fx( ysynth_fx, SWB_fenv_fx, ysynth_32, L_FRAME32k - 80, mode, &frica_flag, &hBWE_FD->prev_Energy_fx, st_fx->prev_SWB_fenv_fx, + &hBWE_FD->prev_L_swb_norm, st_fx->tilt_wb_fx, &hBWE_FD->Seed, 6, &hBWE_FD->prev_weight_fx, st_fx->extl, Q_syn, + st_fx->last_extl, st_fx->element_mode ); } test(); - IF ( EQ_16(hBWE_FD->prev_frica_flag, 1) && frica_flag==0) + IF( EQ_16( hBWE_FD->prev_frica_flag, 1 ) && frica_flag == 0 ) { FOR( i = 0; i < L_SUBFR; i++ ) { - tmp = sub(32767, extract_l(L_mult0(i, 512))); /*Q15 */ - hBWE_FD->mem_imdct_fx[i] = mult_r(hBWE_FD->mem_imdct_fx[i], tmp); + tmp = sub( 32767, extract_l( L_mult0( i, 512 ) ) ); /*Q15 */ + hBWE_FD->mem_imdct_fx[i] = mult_r( hBWE_FD->mem_imdct_fx[i], tmp ); move16(); /*Q_synth */ } @@ -1093,14 +1089,14 @@ Word16 swb_bwe_dec_fx( } /* decode information */ - IF ( EQ_16(st_fx->extl, FB_BWE)) + IF( EQ_16( st_fx->extl, FB_BWE ) ) { IF( !st_fx->bfi ) { - idxGain = (Word16)get_next_indice(st_fx, NUM_BITS_FB_FRAMEGAIN ); - fb_ener_adjust_fx = usdequant_fx(idxGain, FB_GAIN_QLOW_FX, FB_GAIN_QDELTA_FX); /*Q15 */ + idxGain = (Word16) get_next_indice( st_fx, NUM_BITS_FB_FRAMEGAIN ); + fb_ener_adjust_fx = usdequant_fx( idxGain, FB_GAIN_QLOW_FX, FB_GAIN_QDELTA_FX ); /*Q15 */ } - ELSE if( st_fx->bfi ) + ELSE if ( st_fx->bfi ) { fb_ener_adjust_fx = st_fx->prev_fb_ener_adjust_fx; move16(); @@ -1108,21 +1104,21 @@ Word16 swb_bwe_dec_fx( st_fx->prev_fb_ener_adjust_fx = fb_ener_adjust_fx; move16(); - IF(EQ_16(mode, TRANSIENT)) + IF( EQ_16( mode, TRANSIENT ) ) { - ener_adjust_quan_fx = shr(fb_ener_adjust_fx, 2); + ener_adjust_quan_fx = shr( fb_ener_adjust_fx, 2 ); move16(); /*Q13*/ } ELSE { - IF(SWB_fenv_fx[7] != 0) + IF( SWB_fenv_fx[7] != 0 ) { - tmp = div_s(1, SWB_fenv_fx[7]); + tmp = div_s( 1, SWB_fenv_fx[7] ); move16(); /*Q14*/ #ifdef BASOP_NOGLOB - ener_adjust_quan_fx = s_min(shr(i_mult_sat(SWB_fenv_fx[13], tmp), 2), 32767); + ener_adjust_quan_fx = s_min( shr( i_mult_sat( SWB_fenv_fx[13], tmp ), 2 ), 32767 ); #else - ener_adjust_quan_fx = s_min(shr(i_mult(SWB_fenv_fx[13], tmp), 2), 32767); + ener_adjust_quan_fx = s_min( shr( i_mult( SWB_fenv_fx[13], tmp ), 2 ), 32767 ); #endif move16(); /*Q13*/ } @@ -1134,95 +1130,95 @@ Word16 swb_bwe_dec_fx( } fb_band_begin = FB_BAND_BEGIN; #ifdef ADD_IVAS_BWE - IF (st_fx->L_frame == L_FRAME) + IF( st_fx->L_frame == L_FRAME ) { fb_band_begin = FB_BAND_BEGIN_12k8; } #endif - FOR( i = fb_band_begin; i < fb_band_begin +DE_OFFSET1; i++ ) + FOR( i = fb_band_begin; i < fb_band_begin + DE_OFFSET1; i++ ) { - tmp = sub(32767, i_mult(j, 1024)); - tmp = mult_r(tmp, ener_adjust_quan_fx); /*Q13*/ + tmp = sub( 32767, i_mult( j, 1024 ) ); + tmp = mult_r( tmp, ener_adjust_quan_fx ); /*Q13*/ - tmp2 = i_mult(j, 256); /*Q13*/ - tmp2 = mult_r(tmp2, fb_ener_adjust_fx); /*Q13*/ + tmp2 = i_mult( j, 256 ); /*Q13*/ + tmp2 = mult_r( tmp2, fb_ener_adjust_fx ); /*Q13*/ - tmp = add(tmp, tmp2); /*Q13*/ - ysynth_32[i] = ysynth_32[i-FB_BAND_WIDTH]; + tmp = add( tmp, tmp2 ); /*Q13*/ + ysynth_32[i] = ysynth_32[i - FB_BAND_WIDTH]; move16(); - ysynth_32[i] = L_shl(Mult_32_16(ysynth_32[i], tmp), 2); - move32();/*15+Q_syn */ - j = add(j, 1); + ysynth_32[i] = L_shl( Mult_32_16( ysynth_32[i], tmp ), 2 ); + move32(); /*15+Q_syn */ + j = add( j, 1 ); } - FOR( ; ielement_mode ); - window_ola_fx( t_audio32_tmp, hb_synth_fx, &Q_syn_hb, hBWE_FD->mem_imdct_fx, &hBWE_FD->mem_imdct_exp_fx, output_frame, ALDO_WINDOW, ALDO_WINDOW, 0,0,0); - l_subfr = mult(output_frame, 8192); + window_ola_fx( t_audio32_tmp, hb_synth_fx, &Q_syn_hb, hBWE_FD->mem_imdct_fx, &hBWE_FD->mem_imdct_exp_fx, output_frame, ALDO_WINDOW, ALDO_WINDOW, 0, 0, 0 ); + l_subfr = mult( output_frame, 8192 ); test(); - IF( EQ_16(mode,TRANSIENT)) + IF( EQ_16( mode, TRANSIENT ) ) { - FOR(i = 0; i < SWB_TENV; i++) + FOR( i = 0; i < SWB_TENV; i++ ) { - SWB_tenv_tmp_fx[i] = L_mult0(SWB_tenv_fx[i], 26214); - move32();/*Q15 */ + SWB_tenv_tmp_fx[i] = L_mult0( SWB_tenv_fx[i], 26214 ); + move32(); /*Q15 */ } /* time envelope shaping when the current frame is TRANSIENT frame */ time_envelop_shaping_fx( hb_synth_fx, SWB_tenv_tmp_fx, output_frame, &Q_syn_hb ); - Q_syn_hb = sub(Q_syn_hb, 3); + Q_syn_hb = sub( Q_syn_hb, 3 ); hBWE_FD->prev_td_energy_fx = SWB_tenv_fx[3]; move16(); } - ELSE IF( EQ_16(frica_flag, 1) && hBWE_FD->prev_frica_flag==0) + ELSE IF( EQ_16( frica_flag, 1 ) && hBWE_FD->prev_frica_flag == 0 ) { time_reduce_pre_echo_fx( synth_fx, hb_synth_fx, hBWE_FD->prev_td_energy_fx, l_subfr, *Qpost, Q_syn_hb ); } ELSE { - tmp = i_mult2(3, l_subfr); - L_tmp = L_deposit_l(0); - FOR(i=0; iprev_td_energy_fx = 0; move16(); - IF(L_tmp != 0) + IF( L_tmp != 0 ) { - exp = norm_l(L_tmp); - frac = extract_h(L_shl(L_tmp, exp)); - exp = sub(exp, sub(30,shl(Q_syn_hb,1))); - - tmp = div_s(16384, frac); - L_tmp = L_deposit_h(tmp); - L_tmp = Isqrt_lc(L_tmp, &exp); /*Q(31-exp) */ - hBWE_FD->prev_td_energy_fx = round_fx(L_shl(L_tmp, sub(exp,15))); /*Q0 */ + exp = norm_l( L_tmp ); + frac = extract_h( L_shl( L_tmp, exp ) ); + exp = sub( exp, sub( 30, shl( Q_syn_hb, 1 ) ) ); + + tmp = div_s( 16384, frac ); + L_tmp = L_deposit_h( tmp ); + L_tmp = Isqrt_lc( L_tmp, &exp ); /*Q(31-exp) */ + hBWE_FD->prev_td_energy_fx = round_fx( L_shl( L_tmp, sub( exp, 15 ) ) ); /*Q0 */ } } #ifdef ADD_IVAS_BWE test(); - IF (EQ_16(st_fx->element_mode, IVAS_CPE_DFT) && !use_cldfb_for_dft) + IF( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) && !use_cldfb_for_dft ) { /* add HB synth from hf_synth() */ - v_add(hb_synth, synth, hb_synth, output_frame); + v_add( hb_synth, synth, hb_synth, output_frame ); } #endif hBWE_FD->prev_frica_flag = frica_flag; @@ -1235,20 +1231,20 @@ Word16 swb_bwe_dec_fx( /*-------------------------------------------------------------------* -* fd_bwe_dec_init() -* -* Initialize FD BWE state structure at the decoder -*-------------------------------------------------------------------*/ + * fd_bwe_dec_init() + * + * Initialize FD BWE state structure at the decoder + *-------------------------------------------------------------------*/ void fd_bwe_dec_init( - Decoder_State* st_fx, /* i/o: decoder state structure */ + Decoder_State *st_fx, /* i/o: decoder state structure */ FD_BWE_DEC_HANDLE hBWE_FD /* i/o: FD BWE data handle */ ) { hBWE_FD->old_wtda_wb_fx_exp = 0; move16(); - set16_fx(hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA(16000, DELAY_FD_BWE_ENC_NS)); - set16_fx(hBWE_FD->L_old_wtda_swb_fx, 0, L_FRAME48k); + set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); + set16_fx( hBWE_FD->L_old_wtda_swb_fx, 0, L_FRAME48k ); hBWE_FD->old_wtda_swb_fx_exp = 0; move16(); hBWE_FD->mem_imdct_exp_fx = 0; @@ -1256,7 +1252,7 @@ void fd_bwe_dec_init( hBWE_FD->prev_mode = NORMAL; move16(); - set16_fx(st_fx->prev_SWB_fenv_fx, 0, SWB_FENV); + set16_fx( st_fx->prev_SWB_fenv_fx, 0, SWB_FENV ); hBWE_FD->prev_Energy_fx = 0; move16(); hBWE_FD->prev_L_swb_norm = 8; @@ -1265,15 +1261,16 @@ void fd_bwe_dec_init( move16(); hBWE_FD->prev_frica_flag = 0; move16(); - set16_fx(hBWE_FD->mem_imdct_fx, 0, L_FRAME48k); + set16_fx( hBWE_FD->mem_imdct_fx, 0, L_FRAME48k ); hBWE_FD->prev_td_energy_fx = 0; move16(); - hBWE_FD->prev_weight_fx = 6554; /*0.2 in Q15*/ move16(); + hBWE_FD->prev_weight_fx = 6554; /*0.2 in Q15*/ + move16(); hBWE_FD->prev_flag = 0; move16(); st_fx->last_wb_bwe_ener_fx = 0; move16(); - hBWE_FD->prev_Energy_wb_fx = L_deposit_l(0); + hBWE_FD->prev_Energy_wb_fx = L_deposit_l( 0 ); hBWE_FD->memExp1 = 0; move16(); @@ -1285,4 +1282,4 @@ void fd_bwe_dec_init( st_fx->prev_fb_ener_adjust_fx = 0; return; -} \ No newline at end of file +} diff --git a/lib_dec/swb_bwe_dec_hr_fx.c b/lib_dec/swb_bwe_dec_hr_fx.c index 63ac2236c..3276cf990 100644 --- a/lib_dec/swb_bwe_dec_hr_fx.c +++ b/lib_dec/swb_bwe_dec_hr_fx.c @@ -2,16 +2,16 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "rom_com.h" /* Static table prototypes */ -#include "rom_dec.h" /* Static table prototypes */ -#include "cnst.h" /* Static table prototypes */ - -#define Q_GUARD 1 -#define Q_32_BITS 14 /* scaling of 't_audio32' */ -#define MAKE_PSEUDO_FLT(v,e) ((((Word32)(v))<<16) + (e)) +#include "options.h" /* Compilation switches */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "rom_com.h" /* Static table prototypes */ +#include "rom_dec.h" /* Static table prototypes */ +#include "cnst.h" /* Static table prototypes */ + +#define Q_GUARD 1 +#define Q_32_BITS 14 /* scaling of 't_audio32' */ +#define MAKE_PSEUDO_FLT( v, e ) ( ( ( (Word32) ( v ) ) << 16 ) + ( e ) ) #define AVQ_DEMUX /*-----------------------------------------------------------* * Gain_Dequant_HR() @@ -27,78 +27,78 @@ two functions would be less efficient (Performance Wise) since the function here doesn't use 'Log2_norm_lc' at all versus gain_dequant_fx() which does. */ -static Word16 Gain_Dequant_HR( /* o: decoded gain (Q13) */ - Word16 index, /* i: quantization index */ - const Word16 min, /* i: value of lower limit (Q13) */ - const Word16 bits, /* i: number of bits to dequantize */ - Word16 *exp /* o: exponent of Decoded Gain */ +static Word16 Gain_Dequant_HR( /* o: decoded gain (Q13) */ + Word16 index, /* i: quantization index */ + const Word16 min, /* i: value of lower limit (Q13) */ + const Word16 bits, /* i: number of bits to dequantize */ + Word16 *exp /* o: exponent of Decoded Gain */ ) { Word32 L_mini, L_fact; Word16 gain; Word32 L_temp; - Word16 exp1,exp2, p2_frac,p2_int; + Word16 exp1, exp2, p2_frac, p2_int; - L_mini=0; /* no complexity counted, just to remove warning */ - L_fact=0; /* no complexity counted, just to remove warning */ + L_mini = 0; /* no complexity counted, just to remove warning */ + L_fact = 0; /* no complexity counted, just to remove warning */ move32(); move32(); - IF (EQ_16(min, G_AVQ_MIN_FX)) + IF( EQ_16( min, G_AVQ_MIN_FX ) ) { - L_mini = MAKE_PSEUDO_FLT(26214, 15); /* 0.8 in Q15 */ - L_fact = MAKE_PSEUDO_FLT(14145, 11); /* Log2(96) - Log2(0.8) in Q11 */ + L_mini = MAKE_PSEUDO_FLT( 26214, 15 ); /* 0.8 in Q15 */ + L_fact = MAKE_PSEUDO_FLT( 14145, 11 ); /* Log2(96) - Log2(0.8) in Q11 */ } - ELSE IF (EQ_16(min, G_AVQ_MIN_DIV10_FX)) + ELSE IF( EQ_16( min, G_AVQ_MIN_DIV10_FX ) ) { - L_mini = MAKE_PSEUDO_FLT(20972, 18); /* 0.8*0.1 in Q18 */ - L_fact = MAKE_PSEUDO_FLT(20949, 11); /* Log2(96) - Log2(0.8*0.1) in Q11 */ + L_mini = MAKE_PSEUDO_FLT( 20972, 18 ); /* 0.8*0.1 in Q18 */ + L_fact = MAKE_PSEUDO_FLT( 20949, 11 ); /* Log2(96) - Log2(0.8*0.1) in Q11 */ } - ELSE IF (EQ_16(min, G_CODE_MIN_FX)) + ELSE IF( EQ_16( min, G_CODE_MIN_FX ) ) { - L_mini = MAKE_PSEUDO_FLT(20972, 20); /* 0.02 in Q20 */ - L_fact = MAKE_PSEUDO_FLT(32628, 12); /* Log2(5) - Log2(0.02) in Q12 */ + L_mini = MAKE_PSEUDO_FLT( 20972, 20 ); /* 0.02 in Q20 */ + L_fact = MAKE_PSEUDO_FLT( 32628, 12 ); /* Log2(5) - Log2(0.02) in Q12 */ } - ELSE IF (EQ_16(min, G_CODE_MIN_TC192_FX)) + ELSE IF( EQ_16( min, G_CODE_MIN_TC192_FX ) ) { - L_mini = MAKE_PSEUDO_FLT(19661, 15); /* 0.6 in Q15 */ - L_fact = MAKE_PSEUDO_FLT(24963, 12); /* Log2(41) - Log2(0.6) in Q12 */ + L_mini = MAKE_PSEUDO_FLT( 19661, 15 ); /* 0.6 in Q15 */ + L_fact = MAKE_PSEUDO_FLT( 24963, 12 ); /* Log2(41) - Log2(0.6) in Q12 */ } - ELSE IF (EQ_16(min, MIN_GLOB_GAIN_BWE_HR_FX)) + ELSE IF( EQ_16( min, MIN_GLOB_GAIN_BWE_HR_FX ) ) { - L_mini = MAKE_PSEUDO_FLT(24576, 13); /* 3.0 in Q13 */ - L_fact = MAKE_PSEUDO_FLT(30232, 12); /* Log2(500) - Log2(3) in Q12 */ + L_mini = MAKE_PSEUDO_FLT( 24576, 13 ); /* 3.0 in Q13 */ + L_fact = MAKE_PSEUDO_FLT( 30232, 12 ); /* Log2(500) - Log2(3) in Q12 */ } /* levels = 1< 0.5f) ? 1.0f : 0.5f;*/ /* beta_flt = (alpha_flt - gain_flt)/sub(input_frame, ind2);*/ - temp2 = sub(16384, temp); - if (temp2 < 0) - temp2 = add(temp2, 16384); - temp3 = sub(input_frame, ind2); + temp2 = sub( 16384, temp ); + if ( temp2 < 0 ) + temp2 = add( temp2, 16384 ); + temp3 = sub( input_frame, ind2 ); /* Inverse 'temp3' */ - temp1 = norm_s(temp3); - temp3 = shl(temp3, temp1); - temp3 = div_s(16384, temp3); - L_Energy2 = L_mult0(temp2, temp3); - temp1 = add(temp1, 1); /* because we used 0.5 (16384) to inverse and not 1.0 (32768) */ + temp1 = norm_s( temp3 ); + temp3 = shl( temp3, temp1 ); + temp3 = div_s( 16384, temp3 ); + L_Energy2 = L_mult0( temp2, temp3 ); + temp1 = add( temp1, 1 ); /* because we used 0.5 (16384) to inverse and not 1.0 (32768) */ /* Back to Q31 */ - L_Energy2 = L_shr(L_Energy2, temp1); + L_Energy2 = L_shr( L_Energy2, temp1 ); FOR( i = ind2; i < input_frame; i++ ) { #ifdef BASOP_NOGLOB - hb_synth_fx[i] = mult_r_sat(round_fx_sat(L_Energy), hb_synth_fx[i]); + hb_synth_fx[i] = mult_r_sat( round_fx_sat( L_Energy ), hb_synth_fx[i] ); move16(); - L_Energy = L_add_sat(L_Energy, L_Energy2); + L_Energy = L_add_sat( L_Energy, L_Energy2 ); #else - hb_synth_fx[i] = mult_r(round_fx(L_Energy), hb_synth_fx[i]); + hb_synth_fx[i] = mult_r( round_fx( L_Energy ), hb_synth_fx[i] ); move16(); - L_Energy = L_add(L_Energy, L_Energy2); + L_Energy = L_add( L_Energy, L_Energy2 ); #endif } } @@ -242,19 +242,19 @@ static Word16 TD_Postprocess( /* o : gain in Q15 */ * HR SWB BWE decoder *-------------------------------------------------------------------*/ -Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 *syn_12k8_16k_fx,/* i : ACELP core synthesis @16kHz */ - const Word16 exp, /* i : Exponent of core synthesis */ - Word16 *hb_synth_fx, /* o : SHB synthesis */ - const Word16 output_frame, /* i : frame length */ - const Word16 unbits, /* i : number of core unused bits */ - const Word16 pitch_buf[] /* i : pitch buffer */ +Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 *syn_12k8_16k_fx, /* i : ACELP core synthesis @16kHz */ + const Word16 exp, /* i : Exponent of core synthesis */ + Word16 *hb_synth_fx, /* o : SHB synthesis */ + const Word16 output_frame, /* i : frame length */ + const Word16 unbits, /* i : number of core unused bits */ + const Word16 pitch_buf[] /* i : pitch buffer */ ) { Word16 i, j, k, nBits, nBits_total, nBits_block, Nsv, Nsv2, width_noncoded; Word16 is_transient, tmpS, incr, IsTransient, pos; - Word16 x_norm[NSV_MAX*(WIDTH_BAND+1)], x_norm1[NSV_MAX*(WIDTH_BAND+1)]; + Word16 x_norm[NSV_MAX * ( WIDTH_BAND + 1 )], x_norm1[NSV_MAX * ( WIDTH_BAND + 1 )]; Word32 t_audio32_tmp[L_FRAME48k]; Word32 t_audio32[L_FRAME48k]; Word16 t_audio_exp; @@ -286,18 +286,18 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ /* Use 't_audio32_tmp' Word32 Buffer as two Word16 Buffers to save local Stack. */ /* There is no possible overlap so it is ok */ - t_audio = (Word16 *)&t_audio32_tmp[0]; - t_audio_tmp = (Word16 *)&t_audio32_tmp[L_FRAME48k/2]; + t_audio = (Word16 *) &t_audio32_tmp[0]; + t_audio_tmp = (Word16 *) &t_audio32_tmp[L_FRAME48k / 2]; - hBWE_FD_HR->bwe_highrate_seed_fx = extract_l(L_mult0(pitch_buf[0],pitch_buf[3])); + hBWE_FD_HR->bwe_highrate_seed_fx = extract_l( L_mult0( pitch_buf[0], pitch_buf[3] ) ); /*---------------------------------------------------------------------* * initializations *---------------------------------------------------------------------*/ - set16_fx(t_audio, 0, output_frame); - set32_fx(t_audio32, 0, output_frame); + set16_fx( t_audio, 0, output_frame ); + set32_fx( t_audio32, 0, output_frame ); exp2 = 0; move16(); Nsv2 = 0; @@ -314,16 +314,16 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ /* reset memories in case that last frame was a different technology */ test(); - IF( EQ_16(st_fx->last_core, HQ_CORE)||NE_16(st_fx->last_extl,st_fx->extl)) + IF( EQ_16( st_fx->last_core, HQ_CORE ) || NE_16( st_fx->last_extl, st_fx->extl ) ) { - set16_fx(hBWE_FD->L_old_wtda_swb_fx, 0, L_FRAME48k ); + set16_fx( hBWE_FD->L_old_wtda_swb_fx, 0, L_FRAME48k ); st_fx->hHQ_core->Q_old_wtda = 14; move16(); } /* calculate SWB BWE bit-budget */ /* nBits = st->extl_brate/50 + unbits */ - nBits = add(320,unbits); /* st->extl_brate_fx is always 16kbps */ + nBits = add( 320, unbits ); /* st->extl_brate_fx is always 16kbps */ nBits_total = nBits; move16(); @@ -331,12 +331,12 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ * calculate tilt of the core synthesis *---------------------------------------------------------------------*/ L_tilt_wb = calc_tilt_bwe_fx( syn_12k8_16k_fx, exp, L_FRAME16k ); - L_temp = L_mac(1L, 8192, pitch_buf[0]); - FOR (i = 1; i < NB_SUBFR16k-1; i++) + L_temp = L_mac( 1L, 8192, pitch_buf[0] ); + FOR( i = 1; i < NB_SUBFR16k - 1; i++ ) { - L_temp = L_mac(L_temp, 8192, pitch_buf[i]); + L_temp = L_mac( L_temp, 8192, pitch_buf[i] ); } - pitch = mac_r(L_temp, 8192, pitch_buf[i]); + pitch = mac_r( L_temp, 8192, pitch_buf[i] ); /* pitch now in Q4 (Q6 div by 4) */ /*---------------------------------------------------------------------* @@ -351,13 +351,14 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ /* Replication of the last spectrum, with an attenuation */ test(); test(); - IF( (EQ_16(st_fx->clas_dec, VOICED_CLAS)||EQ_16(st_fx->clas_dec,INACTIVE_CLAS))&&LE_16(st_fx->nbLostCmpt,3)) + IF( ( EQ_16( st_fx->clas_dec, VOICED_CLAS ) || EQ_16( st_fx->clas_dec, INACTIVE_CLAS ) ) && LE_16( st_fx->nbLostCmpt, 3 ) ) { - alpha = 26214; /* 0.80 */ move16(); + alpha = 26214; /* 0.80 */ + move16(); t_audio_exp = 0; move16(); } - ELSE IF ( is_transient ) + ELSE IF( is_transient ) { alpha = 19661 /* 0.15 */; move16(); @@ -375,16 +376,16 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ IF( is_transient ) { /* output_frame == L_FRAME48k */ - tmpS = (2*END_FREQ_BWE_FULL_FB/50)/NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_START_FREQ_COEF; + tmpS = ( 2 * END_FREQ_BWE_FULL_FB / 50 ) / NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_START_FREQ_COEF; move16(); /* set BWE spectrum length */ - if( EQ_16(output_frame, L_FRAME32k)) + if ( EQ_16( output_frame, L_FRAME32k ) ) { - tmpS = L_FRAME32k/NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_START_FREQ_COEF; + tmpS = L_FRAME32k / NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_START_FREQ_COEF; move16(); } - temp = shr(output_frame, 2); + temp = shr( output_frame, 2 ); pos = NUM_TRANS_START_FREQ_COEF; move16(); ind1 = 0; @@ -394,38 +395,38 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ move16(); /* Here t_audio was initialy filled with zeros */ /* So, after the loop, the Q will be 'Q_32_Bits' */ - FOR( k=0; kt_audio_prev_fx_exp[k], Q_32_BITS); - temp4 = add(temp4, t_audio_exp); - FOR( i=0; it_audio_prev_fx_exp[k], Q_32_BITS ); + temp4 = add( temp4, t_audio_exp ); + FOR( i = 0; i < tmpS; i++ ) { - L_temp = L_mult(alpha, hBWE_FD_HR->t_audio_prev_fx[i + ind1]); - L_temp = L_shr(L_temp, temp4); + L_temp = L_mult( alpha, hBWE_FD_HR->t_audio_prev_fx[i + ind1] ); + L_temp = L_shr( L_temp, temp4 ); t_audio32[pos + i] = L_temp; move32(); } - ind1 = add(ind1, tmpS); - pos = add(pos, temp); + ind1 = add( ind1, tmpS ); + pos = add( pos, temp ); } /* Save transform coefficients for the next frame (needed in case of frame erasures) */ - FOR( k=0; kt_audio_prev_fx + i_mult2(k, tmpS), tmpS, temp4); - hBWE_FD_HR->t_audio_prev_fx_exp[k] = add(Q_32_BITS, temp4); + temp = add( NUM_TRANS_START_FREQ_COEF, len ); + temp4 = Find_Max_Norm32( t_audio32 + temp, tmpS ); + Copy_Scale_sig32_16( t_audio32 + temp, hBWE_FD_HR->t_audio_prev_fx + i_mult2( k, tmpS ), tmpS, temp4 ); + hBWE_FD_HR->t_audio_prev_fx_exp[k] = add( Q_32_BITS, temp4 ); move16(); - len = add(len, shr(output_frame, 2)); + len = add( len, shr( output_frame, 2 ) ); } } ELSE { /* output_frame == L_FRAME48k */ - tmpS = 2*END_FREQ_BWE_FULL_FB/50 - NUM_NONTRANS_START_FREQ_COEF; + tmpS = 2 * END_FREQ_BWE_FULL_FB / 50 - NUM_NONTRANS_START_FREQ_COEF; move16(); /* set BWE spectrum length */ - if( EQ_16(output_frame, L_FRAME32k)) + if ( EQ_16( output_frame, L_FRAME32k ) ) { tmpS = L_FRAME32k - NUM_NONTRANS_START_FREQ_COEF; move16(); @@ -434,51 +435,51 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ /* reconstruct */ /* Here t_audio was initialy filled with zeros */ /* So, after the loop, the Q will be 'Q_32_Bits' */ - temp4 = sub(hBWE_FD_HR->t_audio_prev_fx_exp[0], Q_32_BITS); - temp4 = add(temp4, t_audio_exp); + temp4 = sub( hBWE_FD_HR->t_audio_prev_fx_exp[0], Q_32_BITS ); + temp4 = add( temp4, t_audio_exp ); ptr32 = &t_audio32[NUM_NONTRANS_START_FREQ_COEF]; - FOR( i=0; it_audio_prev_fx[i]); - L_temp = L_shr(L_temp, temp4); + L_temp = L_mult( alpha, hBWE_FD_HR->t_audio_prev_fx[i] ); + L_temp = L_shr( L_temp, temp4 ); *ptr32++ = L_temp; move32(); } /* Save transform coefficients for the next frame (needed in case of frame erasures) */ temp = NUM_NONTRANS_START_FREQ_COEF; move16(); /* not necessary but improves readability and allows a larger common code path */ - temp4 = Find_Max_Norm32(t_audio32 + temp, tmpS); - Copy_Scale_sig32_16(t_audio32 + temp, hBWE_FD_HR->t_audio_prev_fx, tmpS, temp4); - hBWE_FD_HR->t_audio_prev_fx_exp[0] = add(Q_32_BITS, temp4); + temp4 = Find_Max_Norm32( t_audio32 + temp, tmpS ); + Copy_Scale_sig32_16( t_audio32 + temp, hBWE_FD_HR->t_audio_prev_fx, tmpS, temp4 ); + hBWE_FD_HR->t_audio_prev_fx_exp[0] = add( Q_32_BITS, temp4 ); move16(); } - hBWE_FD_HR->L_mem_EnergyLT_fx = Mul_flt32_Q15(hBWE_FD_HR->L_mem_EnergyLT_fx, &hBWE_FD_HR->mem_EnergyLT_fx_exp, alpha); + hBWE_FD_HR->L_mem_EnergyLT_fx = Mul_flt32_Q15( hBWE_FD_HR->L_mem_EnergyLT_fx, &hBWE_FD_HR->mem_EnergyLT_fx_exp, alpha ); move32(); - hBWE_FD_HR->mem_EnergyLT_fx_exp = add(hBWE_FD_HR->mem_EnergyLT_fx_exp, t_audio_exp); + hBWE_FD_HR->mem_EnergyLT_fx_exp = add( hBWE_FD_HR->mem_EnergyLT_fx_exp, t_audio_exp ); /* Set Exponent */ t_audio_exp = Q_32_BITS; move16(); - exp_L = norm_s(output_frame); - inv_L = div_s(shl(1,sub(14,exp_L)), output_frame); /*Q(29-exp_L)*/ + exp_L = norm_s( output_frame ); + inv_L = div_s( shl( 1, sub( 14, exp_L ) ), output_frame ); /*Q(29-exp_L)*/ /*Q(st_fx->mem_EnergyLT_fx_exp+29-exp_L-15) -> Q(st_fx->mem_EnergyLT_fx_exp-exp_L+14)*/ - hBWE_FD_HR->L_mem_EnergyLT_fx = Mul_flt32_Q15(hBWE_FD_HR->L_mem_EnergyLT_fx, &hBWE_FD_HR->mem_EnergyLT_fx_exp, inv_L); + hBWE_FD_HR->L_mem_EnergyLT_fx = Mul_flt32_Q15( hBWE_FD_HR->L_mem_EnergyLT_fx, &hBWE_FD_HR->mem_EnergyLT_fx_exp, inv_L ); move32(); - IF(hBWE_FD_HR->L_mem_EnergyLT_fx != 0) + IF( hBWE_FD_HR->L_mem_EnergyLT_fx != 0 ) { - exp1 = norm_l(hBWE_FD_HR->L_mem_EnergyLT_fx); - frac = extract_h(L_shl(hBWE_FD_HR->L_mem_EnergyLT_fx, exp1)); - exp1 = sub(exp1,sub(16,sub(hBWE_FD_HR->mem_EnergyLT_fx_exp,exp_L))); + exp1 = norm_l( hBWE_FD_HR->L_mem_EnergyLT_fx ); + frac = extract_h( L_shl( hBWE_FD_HR->L_mem_EnergyLT_fx, exp1 ) ); + exp1 = sub( exp1, sub( 16, sub( hBWE_FD_HR->mem_EnergyLT_fx_exp, exp_L ) ) ); - temp = div_s(16384, frac); - L_temp = L_deposit_h(temp); - L_temp = Isqrt_lc(L_temp, &exp1); + temp = div_s( 16384, frac ); + L_temp = L_deposit_h( temp ); + L_temp = Isqrt_lc( L_temp, &exp1 ); #ifdef BASOP_NOGLOB - gain_fx = extract_l(L_shl_sat(L_temp, sub(exp1, 2))); /*Q(31-exp + (exp-3)) -> Q13*/ + gain_fx = extract_l( L_shl_sat( L_temp, sub( exp1, 2 ) ) ); /*Q(31-exp + (exp-3)) -> Q13*/ #else - gain_fx = extract_l(L_shl(L_temp, sub(exp1, 2))); /*Q(31-exp + (exp-3)) -> Q13*/ + gain_fx = extract_l( L_shl( L_temp, sub( exp1, 2 ) ) ); /*Q(31-exp + (exp-3)) -> Q13*/ #endif } @@ -497,23 +498,23 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ { nBits = -1; move16(); /* is_transient flag */ - nBits_block = shr(nBits_total, 2); - nBits = add(nBits, s_and(nBits_total, 3)); + nBits_block = shr( nBits_total, 2 ); + nBits = add( nBits, s_and( nBits_total, 3 ) ); /* set width of noncoded (blind estimated) spectrum */ test(); - IF( EQ_16(st_fx->extl, SWB_BWE_HIGHRATE)||EQ_16(output_frame,L_FRAME32k)) + IF( EQ_16( st_fx->extl, SWB_BWE_HIGHRATE ) || EQ_16( output_frame, L_FRAME32k ) ) { - width_noncoded = L_FRAME32k/NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_END_FREQ_COEF; + width_noncoded = L_FRAME32k / NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_END_FREQ_COEF; move16(); - tmpS = L_FRAME32k/NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_END_FREQ_COEF_EFF; + tmpS = L_FRAME32k / NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_END_FREQ_COEF_EFF; move16(); } - ELSE /* st->extl == FB_BWE_HIGHRATE */ + ELSE /* st->extl == FB_BWE_HIGHRATE */ { - width_noncoded = (2*END_FREQ_BWE_FULL_FB/50)/NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_END_FREQ_COEF; + width_noncoded = ( 2 * END_FREQ_BWE_FULL_FB / 50 ) / NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_END_FREQ_COEF; move16(); - tmpS = (2*END_FREQ_BWE_FULL_FB/50)/NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_END_FREQ_COEF_EFF; + tmpS = ( 2 * END_FREQ_BWE_FULL_FB / 50 ) / NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_END_FREQ_COEF_EFF; move16(); } @@ -524,7 +525,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ move16(); FOR( k = 0; k < NUM_TIME_SWITCHING_BLOCKS; k++ ) { - nBits = add(nBits, nBits_block); + nBits = add( nBits, nBits_block ); /*---------------------------------------------------------------------* * global gain and envelope decoding @@ -533,60 +534,60 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ /* get global gain */ ind1 = (Word16) get_next_indice( st_fx, NBITS_GLOB_GAIN_BWE_HR ); gain_fx = Gain_Dequant_HR( ind1, MIN_GLOB_GAIN_BWE_HR_FX, NBITS_GLOB_GAIN_BWE_HR, &exp1 ); - nBits = sub(nBits, NBITS_GLOB_GAIN_BWE_HR); + nBits = sub( nBits, NBITS_GLOB_GAIN_BWE_HR ); /* get energy per band */ IF( k == 0 ) { - ind1 = (Word16)get_next_indice( st_fx, NBITS_ENVELOPE_BWE_HR_TR ); + ind1 = (Word16) get_next_indice( st_fx, NBITS_ENVELOPE_BWE_HR_TR ); ind2 = ind1; move16(); - nBits = sub(nBits, NBITS_ENVELOPE_BWE_HR_TR); + nBits = sub( nBits, NBITS_ENVELOPE_BWE_HR_TR ); } ELSE { - ind1 = (Word16)get_next_indice( st_fx, NBITS_ENVELOPE_BWE_HR_TR - 1 ); - if( GE_16(ind2, 8)) + ind1 = (Word16) get_next_indice( st_fx, NBITS_ENVELOPE_BWE_HR_TR - 1 ); + if ( GE_16( ind2, 8 ) ) { - ind1 = add(ind1, NUM_ENVLOPE_CODE_HR_TR2); + ind1 = add( ind1, NUM_ENVLOPE_CODE_HR_TR2 ); } - nBits = sub(nBits, NBITS_ENVELOPE_BWE_HR_TR - 1); + nBits = sub( nBits, NBITS_ENVELOPE_BWE_HR_TR - 1 ); } - temp = shl(ind1, 1); + temp = shl( ind1, 1 ); en_band[0] = swb_hr_env_code3_fx[temp]; move16(); - en_band[1] = swb_hr_env_code3_fx[add(temp, 1)]; + en_band[1] = swb_hr_env_code3_fx[add( temp, 1 )]; move16(); /*env = add(shr(en_band[0], 1), shr(en_band[1], 1));*/ - env = mac_r(L_mult(en_band[0], 16384), en_band[1], 16384); + env = mac_r( L_mult( en_band[0], 16384 ), en_band[1], 16384 ); /*---------------------------------------------------------------------* * estimate energy of noncoded spectrum (14.4-20kHz) *---------------------------------------------------------------------*/ - en_noncoded = en_band[N_BANDS_TRANS_BWE_HR-1]; + en_noncoded = en_band[N_BANDS_TRANS_BWE_HR - 1]; move16(); - IF( EQ_16(st_fx->extl, FB_BWE_HIGHRATE)) + IF( EQ_16( st_fx->extl, FB_BWE_HIGHRATE ) ) { - ind1 = (Word16)get_next_indice( st_fx, NBITS_HF_GAIN_BWE_HR ); - nBits = sub(nBits, NBITS_HF_GAIN_BWE_HR); + ind1 = (Word16) get_next_indice( st_fx, NBITS_HF_GAIN_BWE_HR ); + nBits = sub( nBits, NBITS_HF_GAIN_BWE_HR ); - IF (EQ_16(ind1, 1)) + IF( EQ_16( ind1, 1 ) ) { - en_noncoded = round_fx(L_mult0(en_noncoded, BWE_HR_TRANS_EN_LIMIT1_FX_Q16)); + en_noncoded = round_fx( L_mult0( en_noncoded, BWE_HR_TRANS_EN_LIMIT1_FX_Q16 ) ); } - IF( EQ_16(ind1, 2)) + IF( EQ_16( ind1, 2 ) ) { - en_noncoded = round_fx(L_mult0(en_noncoded, BWE_HR_TRANS_EN_LIMIT2_FX_Q16)); + en_noncoded = round_fx( L_mult0( en_noncoded, BWE_HR_TRANS_EN_LIMIT2_FX_Q16 ) ); } - IF( EQ_16(ind1, 3)) + IF( EQ_16( ind1, 3 ) ) { - en_noncoded = round_fx(L_mult0(en_noncoded, BWE_HR_TRANS_EN_LIMIT3_FX_Q16)); + en_noncoded = round_fx( L_mult0( en_noncoded, BWE_HR_TRANS_EN_LIMIT3_FX_Q16 ) ); } } @@ -594,41 +595,41 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ * AVQ decoding (dequantize normalized spectrum) *---------------------------------------------------------------------*/ - Nsv = (NUM_TRANS_END_FREQ_COEF - NUM_TRANS_START_FREQ_COEF) / WIDTH_BAND; + Nsv = ( NUM_TRANS_END_FREQ_COEF - NUM_TRANS_START_FREQ_COEF ) / WIDTH_BAND; move16(); #ifdef AVQ_DEMUX - AVQ_demuxdec_fx(st_fx, x_norm, &nBits, Nsv, nq, 0, sub(Nsv,1)); + AVQ_demuxdec_fx( st_fx, x_norm, &nBits, Nsv, nq, 0, sub( Nsv, 1 ) ); #else AVQ_demuxdec_fx( st_fx, x_norm, &nBits, Nsv, nq ); #endif - temp = add(len, NUM_TRANS_START_FREQ_COEF); + temp = add( len, NUM_TRANS_START_FREQ_COEF ); /* 't_audio' in Q8 */ t_audio_exp = 8; move16(); - FOR( i=0; i < Nsv*WIDTH_BAND; i++ ) + FOR( i = 0; i < Nsv * WIDTH_BAND; i++ ) { - t_audio[temp + i] = shl(x_norm[i], t_audio_exp); + t_audio[temp + i] = shl( x_norm[i], t_audio_exp ); move16(); } /* apply noise-fill */ #ifdef BASOP_NOGLOB - swb_hr_noise_fill_fx( is_transient, NUM_TRANS_START_FREQ_COEF, NUM_TRANS_END_FREQ_COEF, round_fx_sat(L_shl_sat(L_tilt_wb, 3)), /* Q(24+3-16) -> Q11 */ - pitch, nq, Nsv, &hBWE_FD_HR->bwe_highrate_seed_fx, t_audio+temp, t_audio_exp ); + swb_hr_noise_fill_fx( is_transient, NUM_TRANS_START_FREQ_COEF, NUM_TRANS_END_FREQ_COEF, round_fx_sat( L_shl_sat( L_tilt_wb, 3 ) ), /* Q(24+3-16) -> Q11 */ + pitch, nq, Nsv, &hBWE_FD_HR->bwe_highrate_seed_fx, t_audio + temp, t_audio_exp ); #else - swb_hr_noise_fill_fx( is_transient, NUM_TRANS_START_FREQ_COEF, NUM_TRANS_END_FREQ_COEF, round_fx(L_shl(L_tilt_wb, 3)), /* Q(24+3-16) -> Q11 */ - pitch, nq, Nsv, &hBWE_FD_HR->bwe_highrate_seed_fx, t_audio+temp, t_audio_exp ); + swb_hr_noise_fill_fx( is_transient, NUM_TRANS_START_FREQ_COEF, NUM_TRANS_END_FREQ_COEF, round_fx( L_shl( L_tilt_wb, 3 ) ), /* Q(24+3-16) -> Q11 */ + pitch, nq, Nsv, &hBWE_FD_HR->bwe_highrate_seed_fx, t_audio + temp, t_audio_exp ); #endif /* Go from Q't_audio_exp' on 16 Bits to 'Q_32_BITS' on 32 bits */ - temp2 = i_mult2(WIDTH_BAND, Nsv); + temp2 = i_mult2( WIDTH_BAND, Nsv ); ptr16 = &t_audio[temp]; move16(); ptr32 = &t_audio32[temp]; - j = shl(1, sub(Q_32_BITS, t_audio_exp)); - FOR (i = 0; i< temp2; i++) + j = shl( 1, sub( Q_32_BITS, t_audio_exp ) ); + FOR( i = 0; i < temp2; i++ ) { /* put in 'Q_32_BITS' in a 32 Bits */ - L_temp = L_mult0(*ptr16++, j); + L_temp = L_mult0( *ptr16++, j ); *ptr32++ = L_temp; move32(); } @@ -637,131 +638,131 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ * reconstruction *---------------------------------------------------------------------*/ - temp = add(temp, NUM_TRANS_END_FREQ_COEF_EFF-NUM_TRANS_START_FREQ_COEF); - pos = sub(temp, tmpS); + temp = add( temp, NUM_TRANS_END_FREQ_COEF_EFF - NUM_TRANS_START_FREQ_COEF ); + pos = sub( temp, tmpS ); ptr32 = &t_audio32[temp]; /* reconstruct 14-16(20) kHz spectrum */ FOR( j = 0; j < tmpS; j++ ) { - *ptr32++ = L_shr(t_audio32[pos + j], 1); + *ptr32++ = L_shr( t_audio32[pos + j], 1 ); move32(); } - temp = i_mult2(shr(output_frame, 2), k); + temp = i_mult2( shr( output_frame, 2 ), k ); - temp2 = add(NUM_TRANS_START_FREQ_COEF, temp); + temp2 = add( NUM_TRANS_START_FREQ_COEF, temp ); ptr32 = &t_audio32[temp2]; /* envelope denormalization */ - FOR( i=0; it_audio_prev_fx + i_mult2(k, pos), pos, temp4); - hBWE_FD_HR->t_audio_prev_fx_exp[k] = add(Q_32_BITS, temp4); + temp4 = Find_Max_Norm32( t_audio32 + temp, pos ); + Copy_Scale_sig32_16( t_audio32 + temp, hBWE_FD_HR->t_audio_prev_fx + i_mult2( k, pos ), pos, temp4 ); + hBWE_FD_HR->t_audio_prev_fx_exp[k] = add( Q_32_BITS, temp4 ); move16(); - len = add(len, shr(output_frame, 2)); + len = add( len, shr( output_frame, 2 ) ); /* attenuate HFs in case of band-width switching */ IF( st_fx->bws_cnt1 > 0 ) { - temp = shr(output_frame, 2); - temp = i_mult(k, temp); - temp = add(NUM_TRANS_START_FREQ_COEF, temp); - temp2 = i_mult(st_fx->bws_cnt1, 1638); /*Q15*/ + temp = shr( output_frame, 2 ); + temp = i_mult( k, temp ); + temp = add( NUM_TRANS_START_FREQ_COEF, temp ); + temp2 = i_mult( st_fx->bws_cnt1, 1638 ); /*Q15*/ - j = (2*END_FREQ_BWE_FULL_FB/50)/NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_START_FREQ_COEF; + j = ( 2 * END_FREQ_BWE_FULL_FB / 50 ) / NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_START_FREQ_COEF; move16(); - if( output_frame == L_FRAME32k ) + if ( output_frame == L_FRAME32k ) { - j = L_FRAME32k/NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_START_FREQ_COEF; + j = L_FRAME32k / NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_START_FREQ_COEF; move16(); } - FOR( i=0; iextl, FB_BWE_HIGHRATE)) + IF( EQ_16( st_fx->extl, FB_BWE_HIGHRATE ) ) { ind1 = (Word16) get_next_indice( st_fx, NBITS_HF_GAIN_BWE_HR ); - nBits = sub(nBits, NBITS_HF_GAIN_BWE_HR); + nBits = sub( nBits, NBITS_HF_GAIN_BWE_HR ); - if (EQ_16(ind1, 1)) + if ( EQ_16( ind1, 1 ) ) { /* en_noncoded = BWE_HR_NONTRANS_EN_LIMIT1*(0.5*min_env) ==> 0.25*min_env */ - en_noncoded = mult_r(min_env, BWE_HR_NONTRANS_EN_LIMIT2_FX_Q15/2); + en_noncoded = mult_r( min_env, BWE_HR_NONTRANS_EN_LIMIT2_FX_Q15 / 2 ); } - IF (EQ_16(ind1, 2)) + IF( EQ_16( ind1, 2 ) ) { /* en_noncoded = 2.0*BWE_HR_NONTRANS_EN_LIMIT2*(0.5*min_env) ==> 1.2*min_env */ - en_noncoded = round_fx(L_shl(L_mult(BWE_HR_NONTRANS_EN_LIMIT2_FX_Q14, min_env), 1)); + en_noncoded = round_fx( L_shl( L_mult( BWE_HR_NONTRANS_EN_LIMIT2_FX_Q14, min_env ), 1 ) ); } - if (EQ_16(ind1, 3)) + if ( EQ_16( ind1, 3 ) ) { /* en_noncoded = 2.0*BWE_HR_NONTRANS_EN_LIMIT3*(0.5*min_env) ==> 0.8*min_env */ - en_noncoded = mult_r(BWE_HR_NONTRANS_EN_LIMIT3_FX_Q15, min_env); + en_noncoded = mult_r( BWE_HR_NONTRANS_EN_LIMIT3_FX_Q15, min_env ); } } @@ -856,9 +857,9 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ *---------------------------------------------------------------------*/ /* Nsv = i / WIDTH_BAND */ - Nsv = shr(i, 3); + Nsv = shr( i, 3 ); #ifdef AVQ_DEMUX - AVQ_demuxdec_fx( st_fx, x_norm, &nBits, Nsv, nq, 0, sub(Nsv,1) ); + AVQ_demuxdec_fx( st_fx, x_norm, &nBits, Nsv, nq, 0, sub( Nsv, 1 ) ); #else AVQ_demuxdec_fx( st_fx, x_norm, &nBits, Nsv, nq ); #endif @@ -867,15 +868,15 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ *---------------------------------------------------------------------*/ test(); - IF( GE_16(nBits, 9 + NBITS_GLOB_GAIN_BWE_HR)&&sum16_fx(nq,Nsv)>0) + IF( GE_16( nBits, 9 + NBITS_GLOB_GAIN_BWE_HR ) && sum16_fx( nq, Nsv ) > 0 ) { ind1 = (Word16) get_next_indice( st_fx, NBITS_GLOB_GAIN_BWE_HR ); gain2_fx = Gain_Dequant_HR( ind1, MIN_GLOB_GAIN_BWE_HR_FX, NBITS_GLOB_GAIN_BWE_HR, &exp2 ); /* gain2_flt *= 0.0625f */ - exp2 = add(exp2, 4); + exp2 = add( exp2, 4 ); /* calculate the number of subbands according to the rest bits */ - IF( GT_16(nBits, 396)) + IF( GT_16( nBits, 396 ) ) { Nsv2 = 33; move16(); @@ -884,22 +885,22 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ { /* Here what is acheived is an integer divide by 12 with truncation. */ /* nBits/12 */ - Nsv2 = mult(nBits, 2731); + Nsv2 = mult( nBits, 2731 ); /* But, we have imprecision of the fraction so correction is necessary. */ /* We crosscheck if 'Nsv2' is either too high or too low. */ /* Finally, the result must satisfy: */ /* Nsv2 * 12 <= nBits (Nsv2 is not too high) AND */ /* nBits - Nsv2 * 12 < 12 (Nsv2 is the highest divisor) */ - L_temp = L_msu0(L_deposit_l(nBits), 12, Nsv2); - if (GE_32(L_temp, 12L)) - Nsv2 = add(Nsv2, 1); - if (L_temp < 0) - Nsv2 = sub(Nsv2, 1); + L_temp = L_msu0( L_deposit_l( nBits ), 12, Nsv2 ); + if ( GE_32( L_temp, 12L ) ) + Nsv2 = add( Nsv2, 1 ); + if ( L_temp < 0 ) + Nsv2 = sub( Nsv2, 1 ); } - nBits = sub(nBits, NBITS_GLOB_GAIN_BWE_HR); + nBits = sub( nBits, NBITS_GLOB_GAIN_BWE_HR ); #ifdef AVQ_DEMUX - AVQ_demuxdec_fx( st_fx, x_norm1, &nBits, Nsv2, nq2, 0, sub(Nsv2,1) ); + AVQ_demuxdec_fx( st_fx, x_norm1, &nBits, Nsv2, nq2, 0, sub( Nsv2, 1 ) ); #else AVQ_demuxdec_fx( st_fx, x_norm1, &nBits, Nsv2, nq2 ); #endif @@ -912,68 +913,68 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ /* set 't_audio' exp */ t_audio_exp = 10; move16(); - FOR( i = 0; i < Nsv*WIDTH_BAND; i++ ) + FOR( i = 0; i < Nsv * WIDTH_BAND; i++ ) { #ifdef BASOP_NOGLOB t_audio_tmp[i] = shl_sat( x_norm[i], t_audio_exp ); #else - t_audio_tmp[i] = shl(x_norm[i], t_audio_exp); + t_audio_tmp[i] = shl( x_norm[i], t_audio_exp ); #endif move16(); } Copy( nq, nq_tmp, Nsv ); - IF( GT_16(Nsv2, Nsv)) + IF( GT_16( Nsv2, Nsv ) ) { /* Safety check, happens rarely */ - set16_fx( nq_tmp + Nsv, 0, sub(Nsv2, Nsv) ); + set16_fx( nq_tmp + Nsv, 0, sub( Nsv2, Nsv ) ); } incr = 0; move16(); ptr16 = x_norm1; - temp2 = sub(sub(exp2, 15), t_audio_exp); /* go to Q't_audio' */ - FOR( i=0; i=ind1; i-- ) + FOR( i = sub( Nsv, 1 ); i >= ind1; i-- ) { nq[j] = nq[i]; move16(); - j = sub(j, 1); + j = sub( j, 1 ); } - Copy( nq + ind2, nq + ind1, add(WIDTH_BAND, pos) ); + Copy( nq + ind2, nq + ind1, add( WIDTH_BAND, pos ) ); } } /* apply noise-fill */ - IF( LT_16(nBits, 200)) + IF( LT_16( nBits, 200 ) ) { - swb_hr_noise_fill_fx(is_transient, NUM_NONTRANS_START_FREQ_COEF, NUM_NONTRANS_END_FREQ_COEF, + swb_hr_noise_fill_fx( is_transient, NUM_NONTRANS_START_FREQ_COEF, NUM_NONTRANS_END_FREQ_COEF, #ifdef BASOP_NOGLOB - round_fx_sat(L_shl_sat(L_tilt_wb, 3)), /* Q(24+3-16) -> Q11 */ + round_fx_sat( L_shl_sat( L_tilt_wb, 3 ) ), /* Q(24+3-16) -> Q11 */ #else - round_fx(L_shl(L_tilt_wb, 3)), /* Q(24+3-16) -> Q11 */ + round_fx( L_shl( L_tilt_wb, 3 ) ), /* Q(24+3-16) -> Q11 */ #endif - pitch, nq, Nsv, &hBWE_FD_HR->bwe_highrate_seed_fx, t_audio + NUM_NONTRANS_START_FREQ_COEF, t_audio_exp ); + pitch, nq, Nsv, &hBWE_FD_HR->bwe_highrate_seed_fx, t_audio + NUM_NONTRANS_START_FREQ_COEF, t_audio_exp ); } /* Go from Q't_audio_exp' on 16 Bits to Q16 on 32 bits */ ptr32 = &t_audio32[NUM_NONTRANS_START_FREQ_COEF]; - j = shl(1, sub(Q_32_BITS, t_audio_exp)); - FOR (i = 0; i < temp4; i++) + j = shl( 1, sub( Q_32_BITS, t_audio_exp ) ); + FOR( i = 0; i < temp4; i++ ) { /* put in 'Q_32_BITS' in a 32 Bits */ - L_temp = L_mult0(*ptr16++, j); + L_temp = L_mult0( *ptr16++, j ); *ptr32++ = L_temp; move32(); } @@ -1065,106 +1066,106 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ /* smoothing 12.6-12.8kHz */ test(); - IF( EQ_16(pos, 3)&&LE_16(nBits_total,400)) + IF( EQ_16( pos, 3 ) && LE_16( nBits_total, 400 ) ) { ptr16 = &t_audio[NUM_NONTRANS_START_FREQ_COEF + 200 - WIDTH_BAND]; - L_temp = L_mac0(1L/* EPSILON */, *ptr16, *ptr16); - FOR (i = 1; i < WIDTH_BAND; i++) + L_temp = L_mac0( 1L /* EPSILON */, *ptr16, *ptr16 ); + FOR( i = 1; i < WIDTH_BAND; i++ ) { ptr16++; - L_temp = L_mac0(L_temp, *ptr16, *ptr16); + L_temp = L_mac0( L_temp, *ptr16, *ptr16 ); } ptr16++; - L_temp2 = L_mac0(1L/* EPSILON */, *ptr16, *ptr16); - FOR (i = 1; i < WIDTH_BAND; i++) + L_temp2 = L_mac0( 1L /* EPSILON */, *ptr16, *ptr16 ); + FOR( i = 1; i < WIDTH_BAND; i++ ) { ptr16++; - L_temp2 = L_mac0(L_temp2, *ptr16, *ptr16); + L_temp2 = L_mac0( L_temp2, *ptr16, *ptr16 ); } - L_temp = Sqrt_Ratio32(L_temp, 0, L_temp2, 0, &temp); + L_temp = Sqrt_Ratio32( L_temp, 0, L_temp2, 0, &temp ); /* if 'temp' is < 0 then it is req to shift right before substracting 1.0 */ - temp2 = s_min(0, temp); - L_temp = L_shl(L_temp, temp2); + temp2 = s_min( 0, temp ); + L_temp = L_shl( L_temp, temp2 ); /* Energy_flt - i*(Energy_flt-1.0)/8.0 */ - L_temp2 = L_add(L_temp, L_shr(-2147483647L-1L, s_max(0, temp))); /* 1.0 in same Q as Sqrt minus the Guard */ + L_temp2 = L_add( L_temp, L_shr( -2147483647L - 1L, s_max( 0, temp ) ) ); /* 1.0 in same Q as Sqrt minus the Guard */ /* / 8.0 */ - L_temp2 = L_shr(L_temp2, 3+Q_GUARD); + L_temp2 = L_shr( L_temp2, 3 + Q_GUARD ); /* Add Guard */ - L_temp = L_shr(L_temp, Q_GUARD); + L_temp = L_shr( L_temp, Q_GUARD ); /* Set Index */ ptr16 = &t_audio[NUM_NONTRANS_START_FREQ_COEF + 200]; ptr32 = &t_audio32[NUM_NONTRANS_START_FREQ_COEF + 200]; /* Set Exponent (relative to t_audio_exp (from 16 bits vector) */ - temp2 = add(sub(temp, temp2), sub(Q_GUARD-(16-Q_32_BITS), t_audio_exp)); + temp2 = add( sub( temp, temp2 ), sub( Q_GUARD - ( 16 - Q_32_BITS ), t_audio_exp ) ); - FOR( i=0; iextl == FB_BWE_HIGHRATE */ test(); - if( EQ_16(st_fx->extl, SWB_BWE_HIGHRATE)||EQ_16(output_frame,L_FRAME32k)) + if ( EQ_16( st_fx->extl, SWB_BWE_HIGHRATE ) || EQ_16( output_frame, L_FRAME32k ) ) { width_noncoded = L_FRAME32k - NUM_NONTRANS_END_FREQ_COEF; move16(); } ptr16 = &t_audio[NUM_NONTRANS_END_FREQ_COEF - WIDTH_BAND]; - L_temp = L_mac0(1L/* EPSILON */, *ptr16, *ptr16); - FOR (i = 1; i < WIDTH_BAND; i++) + L_temp = L_mac0( 1L /* EPSILON */, *ptr16, *ptr16 ); + FOR( i = 1; i < WIDTH_BAND; i++ ) { ptr16++; - L_temp = L_mac0(L_temp, *ptr16, *ptr16); + L_temp = L_mac0( L_temp, *ptr16, *ptr16 ); } - ptr16 = &t_audio[sub(NUM_NONTRANS_END_FREQ_COEF, width_noncoded)]; - L_temp2 = L_mac0(1L/* EPSILON */, *ptr16, *ptr16); - FOR (i = 1; i < WIDTH_BAND; i++) + ptr16 = &t_audio[sub( NUM_NONTRANS_END_FREQ_COEF, width_noncoded )]; + L_temp2 = L_mac0( 1L /* EPSILON */, *ptr16, *ptr16 ); + FOR( i = 1; i < WIDTH_BAND; i++ ) { ptr16++; - L_temp2 = L_mac0(L_temp2, *ptr16, *ptr16); + L_temp2 = L_mac0( L_temp2, *ptr16, *ptr16 ); } - L_temp = Sqrt_Ratio32(L_temp, 0, L_temp2, 0, &temp); + L_temp = Sqrt_Ratio32( L_temp, 0, L_temp2, 0, &temp ); /* So part of the copy can be skipped because the loop that follows */ /* will take the values from t_audio (16 bits) */ /* Since 'width_noncoded' is always > WIDTH_BAND, we can substract it from the length */ /* and adjust the offset accordingly */ - Copy32( t_audio32 + sub(NUM_NONTRANS_END_FREQ_COEF+WIDTH_BAND, width_noncoded), - t_audio32 + NUM_NONTRANS_END_FREQ_COEF+WIDTH_BAND, sub(width_noncoded, WIDTH_BAND) ); + Copy32( t_audio32 + sub( NUM_NONTRANS_END_FREQ_COEF + WIDTH_BAND, width_noncoded ), + t_audio32 + NUM_NONTRANS_END_FREQ_COEF + WIDTH_BAND, sub( width_noncoded, WIDTH_BAND ) ); /* smoothing 14.4-14.8kHz */ - ptr16 = &t_audio[sub(NUM_NONTRANS_END_FREQ_COEF, width_noncoded)]; + ptr16 = &t_audio[sub( NUM_NONTRANS_END_FREQ_COEF, width_noncoded )]; ptr32 = &t_audio32[NUM_NONTRANS_END_FREQ_COEF]; - temp = sub(temp, add(t_audio_exp, 16-Q_32_BITS)); - FOR( i=0; iextl,SWB_BWE_HIGHRATE)||LT_16(temp,shl_sat(18022,sub(15-13,temp2)))) /* 2.2 in Q13 == 18022 */ + IF( EQ_16( st_fx->extl, SWB_BWE_HIGHRATE ) || LT_16( temp, shl_sat( 18022, sub( 15 - 13, temp2 ) ) ) ) /* 2.2 in Q13 == 18022 */ #else - IF( EQ_16(st_fx->extl,SWB_BWE_HIGHRATE)||LT_16(temp,shl(18022,sub(15-13,temp2)))) /* 2.2 in Q13 == 18022 */ + IF( EQ_16( st_fx->extl, SWB_BWE_HIGHRATE ) || LT_16( temp, shl( 18022, sub( 15 - 13, temp2 ) ) ) ) /* 2.2 in Q13 == 18022 */ #endif { /* (en_band_flt[3] - j*(en_band_flt[3]/WIDTH_BAND - en_noncoded_flt/WIDTH_BAND)) */ - L_temp = L_deposit_h(en_band[3]); - L_temp2 = L_mult(sub(en_band[3], en_noncoded), 32768/WIDTH_BAND); + L_temp = L_deposit_h( en_band[3] ); + L_temp2 = L_mult( sub( en_band[3], en_noncoded ), 32768 / WIDTH_BAND ); ptr32 = &t_audio32[NUM_NONTRANS_END_FREQ_COEF]; /* in L_temp/L_temp2, value in Q16+9 */ - FOR( j=0; j Q23 */ - L_temp2 = Mult_32_16(L_temp,32768/160); /* step */ - FOR( j=0; j Q23 */ + L_temp2 = Mult_32_16( L_temp, 32768 / 160 ); /* step */ + FOR( j = 0; j < tmpS; j++ ) { /* t_audio[NUM_NONTRANS_END_FREQ_COEF + j] *= 2.2f * en_noncoded * (1-(float)k/(float)160); */ - *ptr32 = L_shl(Mult_32_16(*ptr32, round_fx(L_temp)), 31-23); + *ptr32 = L_shl( Mult_32_16( *ptr32, round_fx( L_temp ) ), 31 - 23 ); move32(); ptr32++; - L_temp = L_sub(L_temp, L_temp2); + L_temp = L_sub( L_temp, L_temp2 ); } - L_temp = L_mult(21299 /* 0.65 in Q15*/,en_noncoded); /* Q15 * Q9 -> Q25 */ - L_temp2 = Mult_32_16(L_temp,32768/320); /* step */ - FOR( ; j Q25 */ + L_temp2 = Mult_32_16( L_temp, 32768 / 320 ); /* step */ + FOR( ; j < width_noncoded; j++ ) { /* t_audio[NUM_NONTRANS_END_FREQ_COEF + j] *= 0.65f * en_noncoded * (1-(float)k/(float)320); */ - *ptr32 = L_shl(Mult_32_16(*ptr32, round_fx(L_temp)), 31-25); + *ptr32 = L_shl( Mult_32_16( *ptr32, round_fx( L_temp ) ), 31 - 25 ); move32(); ptr32++; - L_temp = L_sub(L_temp, L_temp2); + L_temp = L_sub( L_temp, L_temp2 ); } } /* Overlap region */ ptr32 = &t_audio32[NUM_NONTRANS_START_FREQ_COEF]; - IF( EQ_16(output_frame, L_FRAME48k)) + IF( EQ_16( output_frame, L_FRAME48k ) ) { - FOR( i=0; it_audio_prev_fx, pos, temp4); - hBWE_FD_HR->t_audio_prev_fx_exp[0] = add(Q_32_BITS, temp4); + temp4 = Find_Max_Norm32( t_audio32 + temp, pos ); + Copy_Scale_sig32_16( t_audio32 + temp, hBWE_FD_HR->t_audio_prev_fx, pos, temp4 ); + hBWE_FD_HR->t_audio_prev_fx_exp[0] = add( Q_32_BITS, temp4 ); move16(); /* attenuate HFs in case of band-width switching */ IF( st_fx->bws_cnt1 > 0 ) { - temp = i_mult(st_fx->bws_cnt1, 1638); /*Q15*/ + temp = i_mult( st_fx->bws_cnt1, 1638 ); /*Q15*/ - j = 2*END_FREQ_BWE_FULL_FB/50 - NUM_NONTRANS_START_FREQ_COEF; + j = 2 * END_FREQ_BWE_FULL_FB / 50 - NUM_NONTRANS_START_FREQ_COEF; move16(); - if( output_frame == L_FRAME32k ) + if ( output_frame == L_FRAME32k ) { j = L_FRAME32k - NUM_NONTRANS_START_FREQ_COEF; move16(); } - FOR( i=0; iprev_ener_shb_fx = extract_h(L_shr(L_mult0(32767, env), 7)); + st_fx->prev_ener_shb_fx = extract_h( L_shr( L_mult0( 32767, env ), 7 ) ); } ELSE { - st_fx->prev_ener_shb_fx = extract_h(L_shr(L_mult0(gain_fx, env), 7)); + st_fx->prev_ener_shb_fx = extract_h( L_shr( L_mult0( gain_fx, env ), 7 ) ); } - FOR(i=0; iprev_SWB_fenv_fx[i] = st_fx->prev_ener_shb_fx; move16(); @@ -1332,9 +1333,9 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ *---------------------------------------------------------------------*/ t_audio_exp = Q_32_BITS; - - Inverse_Transform( t_audio32, &t_audio_exp, t_audio32_tmp, is_transient, output_frame, output_frame, st_fx->element_mode); - window_ola_fx( t_audio32_tmp, hb_synth_fx, &t_audio_exp, hBWE_FD->L_old_wtda_swb_fx, &st_fx->hHQ_core->Q_old_wtda, output_frame,ALDO_WINDOW, ALDO_WINDOW, 0,0,0); + + Inverse_Transform( t_audio32, &t_audio_exp, t_audio32_tmp, is_transient, output_frame, output_frame, st_fx->element_mode ); + window_ola_fx( t_audio32_tmp, hb_synth_fx, &t_audio_exp, hBWE_FD->L_old_wtda_swb_fx, &st_fx->hHQ_core->Q_old_wtda, output_frame, ALDO_WINDOW, ALDO_WINDOW, 0, 0, 0 ); hb_synth_fx_exp = t_audio_exp; move16(); @@ -1346,7 +1347,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ { IsTransient = 0; move16(); - L_EnergyLT = L_add(hBWE_FD_HR->L_mem_EnergyLT_fx, 0); + L_EnergyLT = L_add( hBWE_FD_HR->L_mem_EnergyLT_fx, 0 ); temp4 = hBWE_FD_HR->mem_EnergyLT_fx_exp; move16(); pos = 0; @@ -1355,78 +1356,78 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ ptr16 = hb_synth_fx; move16(); - len = shr(output_frame, 2); /* Divide Frame Len by 4, all (160, 320, 640, 960) are divisible by 4 */ - L_ener_all = L_deposit_l(0); + len = shr( output_frame, 2 ); /* Divide Frame Len by 4, all (160, 320, 640, 960) are divisible by 4 */ + L_ener_all = L_deposit_l( 0 ); ener_all_exp = 40; move16(); /* set to a high exponent */ - FOR( j=0; j<4; j++ ) + FOR( j = 0; j < 4; j++ ) { - L_Energy = Calc_Energy_Autoscaled(ptr16, hb_synth_fx_exp, len, &temp2); + L_Energy = Calc_Energy_Autoscaled( ptr16, hb_synth_fx_exp, len, &temp2 ); ptr16 += len; move16(); /* Normalize Energy */ - temp = norm_l(L_Energy); - L_Energy = L_shl(L_Energy, temp); + temp = norm_l( L_Energy ); + L_Energy = L_shl( L_Energy, temp ); /* Update Exponent of 'L_Energy' */ - temp2 = add(temp2, temp); + temp2 = add( temp2, temp ); /* Normalize Long Term Energy */ - temp = norm_l(L_EnergyLT); - L_EnergyLT = L_shl(L_EnergyLT, temp); + temp = norm_l( L_EnergyLT ); + L_EnergyLT = L_shl( L_EnergyLT, temp ); /* Calculate Exponent of Long Term Energy */ - temp = add(temp, temp4); + temp = add( temp, temp4 ); /* Divide by 12.5 */ - L_temp = Mult_32_16(L_Energy, 20972); /* 20972 = 1/12.5*32768*8 (*8 to boost precision) */ - temp3 = norm_l(L_temp); - L_temp = L_shl(L_temp, temp3); - temp3 = add(add(temp2, temp3), 3); + L_temp = Mult_32_16( L_Energy, 20972 ); /* 20972 = 1/12.5*32768*8 (*8 to boost precision) */ + temp3 = norm_l( L_temp ); + L_temp = L_shl( L_temp, temp3 ); + temp3 = add( add( temp2, temp3 ), 3 ); /* Energies are Strictly Positive Values and Normalized (compare exponent and value only if exponent is same) */ /* Replaces: 'if (Energy_flt > 12.5f * EnergyLT_flt )' */ - temp3 = sub(temp3, temp); + temp3 = sub( temp3, temp ); test(); test(); - IF (temp3 < 0 || (GT_32(L_temp, L_EnergyLT)&&temp3==0)) + IF( temp3 < 0 || ( GT_32( L_temp, L_EnergyLT ) && temp3 == 0 ) ) { IsTransient = 1; move16(); pos = j; move16(); - L_ener_saved = L_add(L_ener_all, 0); + L_ener_saved = L_add( L_ener_all, 0 ); ener_saved_exp = ener_all_exp; move16(); } - L_ener_all = Add_flt32_flt32(L_Energy, temp2, L_ener_all, ener_all_exp, &ener_all_exp); + L_ener_all = Add_flt32_flt32( L_Energy, temp2, L_ener_all, ener_all_exp, &ener_all_exp ); /* 0.25f*Energy_flt */ - temp2 = add(temp2, 2); + temp2 = add( temp2, 2 ); /* 0.75f*EnergyLT_flt */ - L_EnergyLT = L_sub(L_EnergyLT, L_shr(L_EnergyLT, 2)); + L_EnergyLT = L_sub( L_EnergyLT, L_shr( L_EnergyLT, 2 ) ); /* Exponent of 'L_EnergyLT' is 'temp' */ /* Exponent of 'L_Energy' is 'temp2' */ /* EnergyLT = 0.75f*EnergyLT + 0.25f*Energy */ - L_EnergyLT = Add_flt32_flt32(L_Energy, temp2, L_EnergyLT, temp, &temp4); + L_EnergyLT = Add_flt32_flt32( L_Energy, temp2, L_EnergyLT, temp, &temp4 ); } test(); test(); test(); - IF( IsTransient != 0 && pos > 0 && LT_32(L_tilt_wb, 16777216L*3/*tilt_wb in Q24*/)&>_16(pitch,500*16/*Q4*/)) + IF( IsTransient != 0 && pos > 0 && LT_32( L_tilt_wb, 16777216L * 3 /*tilt_wb in Q24*/ ) && GT_16( pitch, 500 * 16 /*Q4*/ ) ) { - Nsv = i_mult2(pos, shr(output_frame, 2)); + Nsv = i_mult2( pos, shr( output_frame, 2 ) ); gain_fx = 16384; /* sqrt(1.0) in Q14 */ /* pos is 1,2 or 3 */ - temp3 = sub(pos, 2); - if (temp3 == 0) + temp3 = sub( pos, 2 ); + if ( temp3 == 0 ) { gain_fx = 23170; move16(); /* sqrt(2.0) in Q14 */ } - if (temp3 > 0) + if ( temp3 > 0 ) { gain_fx = 28378; move16(); /* sqrt(3.0) in Q14 */ @@ -1434,62 +1435,62 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ exp1 = 14; move16(); - IF( EQ_16(st_fx->last_extl, st_fx->extl)) + IF( EQ_16( st_fx->last_extl, st_fx->extl ) ) { L_temp = Div_flt32_flt32( L_ener_saved, ener_saved_exp, hBWE_FD_HR->L_mem_EnergyLT_fx, hBWE_FD_HR->mem_EnergyLT_fx_exp, &temp2 ); - temp3 = sub(temp2, 1); - L_temp2 = Isqrt_lc(L_temp, &temp3); - temp3 = sub(sub(30+31-15+1, temp2), temp3); - - L_temp = Mult_32_16(L_temp2, gain_fx); - temp = norm_l(L_temp); - L_temp2 = L_shl(L_temp, temp); - gain_fx = round_fx(L_temp2); - exp1 = sub(add(temp3, temp), sub(31, exp1)); /* gain_fx is in Q14 */ + temp3 = sub( temp2, 1 ); + L_temp2 = Isqrt_lc( L_temp, &temp3 ); + temp3 = sub( sub( 30 + 31 - 15 + 1, temp2 ), temp3 ); + + L_temp = Mult_32_16( L_temp2, gain_fx ); + temp = norm_l( L_temp ); + L_temp2 = L_shl( L_temp, temp ); + gain_fx = round_fx( L_temp2 ); + exp1 = sub( add( temp3, temp ), sub( 31, exp1 ) ); /* gain_fx is in Q14 */ } - L_temp = L_mult0(26214, gain_fx); + L_temp = L_mult0( 26214, gain_fx ); /* +16: Because 26214 is 0.2 in Q16 * -16: Because of round_fx * -15: To get exponent with ref to Q15 * +1: Because of L_mult'0' * and the normalization */ - exp2 = add(exp1, +16-16-15+1); - temp = norm_l(L_temp); - L_temp = L_shl(L_temp, temp); - exp2 = add(exp2, temp); - temp = round_fx(L_temp); /* Gain is in Q15+x */ - FOR( i=0; i>(19-15+1)); /* 19-15+1 to Bring to Q30 */ - FOR ( i = 0; i < len; i++ ) + L_temp2 = L_msu( L_temp2, swb_hr_inv_frm_len[temp], 32768L >> ( 19 - 15 + 1 ) ); /* 19-15+1 to Bring to Q30 */ + FOR( i = 0; i < len; i++ ) { /* hb_synth[i+Nsv] *= (gain_flt - i*8.0f*(1.0f/output_frame*gain_flt - 1.0f/output_frame)) */ - *ptr16 = round_fx(L_shl(Mult_32_16(L_temp, *ptr16), 1)); + *ptr16 = round_fx( L_shl( Mult_32_16( L_temp, *ptr16 ), 1 ) ); ptr16++; - L_temp = L_sub(L_temp, L_temp2); + L_temp = L_sub( L_temp, L_temp2 ); } } @@ -1503,29 +1504,29 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ /* post-processing in case of TD/FD switching */ test(); - IF( EQ_16(st_fx->last_core, HQ_CORE)||NE_16(st_fx->last_extl,st_fx->extl)) + IF( EQ_16( st_fx->last_core, HQ_CORE ) || NE_16( st_fx->last_extl, st_fx->extl ) ) { - IF( LT_32(L_tilt_wb, 16777216L*3/*tilt_wb in Q24*/)) + IF( LT_32( L_tilt_wb, 16777216L * 3 /*tilt_wb in Q24*/ ) ) { temp = TD_Postprocess( hb_synth_fx, hb_synth_fx_exp, output_frame, st_fx->last_extl ); - FOR( i=0; iL_old_wtda_swb_fx[i] = mult_r(hBWE_FD->L_old_wtda_swb_fx[i], temp); + hBWE_FD->L_old_wtda_swb_fx[i] = mult_r( hBWE_FD->L_old_wtda_swb_fx[i], temp ); move16(); } tmpS = L_FRAME32k - NUM_NONTRANS_START_FREQ_COEF; move16(); - if( EQ_16(output_frame,L_FRAME48k)) + if ( EQ_16( output_frame, L_FRAME48k ) ) { - tmpS = 2*END_FREQ_BWE_FULL_FB/50 - NUM_NONTRANS_START_FREQ_COEF; + tmpS = 2 * END_FREQ_BWE_FULL_FB / 50 - NUM_NONTRANS_START_FREQ_COEF; move16(); } - FOR( i=0; it_audio_prev_fx[i] = mult_r(hBWE_FD_HR->t_audio_prev_fx[i], temp); + hBWE_FD_HR->t_audio_prev_fx[i] = mult_r( hBWE_FD_HR->t_audio_prev_fx[i], temp ); move16(); } } @@ -1562,14 +1563,14 @@ void hr_bwe_dec_init( HR_BWE_DEC_HANDLE hBWE_FD_HR /* i/o: HR BWE data handle */ ) { - set16_fx(hBWE_FD_HR->t_audio_prev_fx, 0, 2 * END_FREQ_BWE_FULL_FB / 50 - NUM_NONTRANS_START_FREQ_COEF); - set16_fx(hBWE_FD_HR->t_audio_prev_fx_exp, 0, NUM_TIME_SWITCHING_BLOCKS); /* one exp per switching block */ + set16_fx( hBWE_FD_HR->t_audio_prev_fx, 0, 2 * END_FREQ_BWE_FULL_FB / 50 - NUM_NONTRANS_START_FREQ_COEF ); + set16_fx( hBWE_FD_HR->t_audio_prev_fx_exp, 0, NUM_TIME_SWITCHING_BLOCKS ); /* one exp per switching block */ hBWE_FD_HR->old_is_transient_hr_bwe_fx = 0; move16(); hBWE_FD_HR->bwe_highrate_seed_fx = 12345; move16(); - hBWE_FD_HR->L_mem_EnergyLT_fx = L_deposit_h(16384); + hBWE_FD_HR->L_mem_EnergyLT_fx = L_deposit_h( 16384 ); hBWE_FD_HR->mem_EnergyLT_fx_exp = 40; move16(); /* set to a high exponent */ diff --git a/lib_dec/swb_bwe_dec_lr.c b/lib_dec/swb_bwe_dec_lr.c index fe580269a..ff664e20b 100644 --- a/lib_dec/swb_bwe_dec_lr.c +++ b/lib_dec/swb_bwe_dec_lr.c @@ -86,7 +86,7 @@ static void DecodeSWBGenericParameters( } #endif -#ifndef IVAS_FLOAT_FIXED +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * DecodeSWBSubbands() * @@ -238,7 +238,7 @@ static void DecodeSWBSubbands( } #endif -#ifndef IVAS_FLOAT_FIXED +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * swb_bwe_dec_lr() * @@ -307,4 +307,4 @@ void swb_bwe_dec_lr( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/swb_bwe_dec_lr_fx.c b/lib_dec/swb_bwe_dec_lr_fx.c index 56ff265a6..689029be4 100644 --- a/lib_dec/swb_bwe_dec_lr_fx.c +++ b/lib_dec/swb_bwe_dec_lr_fx.c @@ -15,29 +15,29 @@ *-------------------------------------------------------------------*/ static void DecodeSWBGenericParameters_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *lagIndices_fx, /* o : lowband index for each subband */ - const Word16 nBands_search_fx, /* i : number of subbnads for SSearch */ - const Word16 BANDS_fx, /* i : total number of subbands per frame */ - const Word16 *p2a_flags_fx, /* i : HF tonal flag */ - const Word16 hq_swb_clas_fx /* i : mode of operation HQ_NORMAL or HQ_HARMONIC */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *lagIndices_fx, /* o : lowband index for each subband */ + const Word16 nBands_search_fx, /* i : number of subbnads for SSearch */ + const Word16 BANDS_fx, /* i : total number of subbands per frame */ + const Word16 *p2a_flags_fx, /* i : HF tonal flag */ + const Word16 hq_swb_clas_fx /* i : mode of operation HQ_NORMAL or HQ_HARMONIC */ ) { Word16 sb; /* lag index for each subband (except last two) */ - FOR (sb = 0; sb < nBands_search_fx; sb++) + FOR( sb = 0; sb < nBands_search_fx; sb++ ) { - IF( EQ_16(hq_swb_clas_fx, HQ_HARMONIC)) + IF( EQ_16( hq_swb_clas_fx, HQ_HARMONIC ) ) { - lagIndices_fx[sb] = get_next_indice(st_fx, bits_lagIndices_mode0_Har[sb]); + lagIndices_fx[sb] = get_next_indice( st_fx, bits_lagIndices_mode0_Har[sb] ); move16(); } ELSE { - IF( p2a_flags_fx[BANDS_fx-NB_SWB_SUBBANDS+sb] == 0 ) + IF( p2a_flags_fx[BANDS_fx - NB_SWB_SUBBANDS + sb] == 0 ) { - lagIndices_fx[sb] = get_next_indice(st_fx, bits_lagIndices_modeNormal[sb]); + lagIndices_fx[sb] = get_next_indice( st_fx, bits_lagIndices_modeNormal[sb] ); move16(); } ELSE @@ -61,35 +61,35 @@ static void DecodeSWBGenericParameters_fx( *-------------------------------------------------------------------*/ static void DecodeSWBSubbands_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - HQ_DEC_HANDLE hHQ_core, /* i/o: HQ decoder handle */ - Word32 *L_spectra, /* i/o: MDCT domain spectrum */ - Word16 QsL, /* i : Q value of spectra */ - const Word16 fLenLow_fx, /* i : lowband length */ - const Word16 fLenHigh_fx, /* i : highband length */ - const Word16 nBands_fx, /* i : number of subbands */ - const Word16 *sbWidth_fx, /* i : subband lengths */ - const Word16 *subband_offsets_fx, /* i : subband offsets */ - Word16 *lagIndices_fx, /* i : lowband index for each subband */ - Word16 *lagGains_fx, /* i : first gain for each subband */ - Word16 *QlagGains, /* i : Q value of lagGains */ - Word16 BANDS_fx, /* i : number subbands per frame */ - Word16 *band_start_fx, /* i : band start of each SB */ - Word16 *band_end_fx, /* i : band end of each SB */ - Word32 *L_band_energy, /* i : band energy of each SB */ - Word16 Qbe, /* i : Q value of band energy */ - Word16 *p2a_flags_fx, /* i : HF tonal indicator */ - const Word16 hqswb_clas_fx, /* i : class information */ - const Word16 har_bands_fx, /* i : number of LF harmonic bands */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + HQ_DEC_HANDLE hHQ_core, /* i/o: HQ decoder handle */ + Word32 *L_spectra, /* i/o: MDCT domain spectrum */ + Word16 QsL, /* i : Q value of spectra */ + const Word16 fLenLow_fx, /* i : lowband length */ + const Word16 fLenHigh_fx, /* i : highband length */ + const Word16 nBands_fx, /* i : number of subbands */ + const Word16 *sbWidth_fx, /* i : subband lengths */ + const Word16 *subband_offsets_fx, /* i : subband offsets */ + Word16 *lagIndices_fx, /* i : lowband index for each subband */ + Word16 *lagGains_fx, /* i : first gain for each subband */ + Word16 *QlagGains, /* i : Q value of lagGains */ + Word16 BANDS_fx, /* i : number subbands per frame */ + Word16 *band_start_fx, /* i : band start of each SB */ + Word16 *band_end_fx, /* i : band end of each SB */ + Word32 *L_band_energy, /* i : band energy of each SB */ + Word16 Qbe, /* i : Q value of band energy */ + Word16 *p2a_flags_fx, /* i : HF tonal indicator */ + const Word16 hqswb_clas_fx, /* i : class information */ + const Word16 har_bands_fx, /* i : number of LF harmonic bands */ const Word16 *subband_search_offset_fx, /* i : Number of harmonic LF bands */ - Word16 *prev_frm_hfe2, /* i/o: */ - Word16 *prev_stab_hfe2, /* i/o: */ - Word16 band_width_fx[], /* i : subband band widths */ - const Word32 L_spectra_ni[], /* i/o: core coder with sparseness filled */ - Word16 *ni_seed_fx /* i/o: random seed for search buffer NI */ + Word16 *prev_frm_hfe2, /* i/o: */ + Word16 *prev_stab_hfe2, /* i/o: */ + Word16 band_width_fx[], /* i : subband band widths */ + const Word32 L_spectra_ni[], /* i/o: core coder with sparseness filled */ + Word16 *ni_seed_fx /* i/o: random seed for search buffer NI */ ) { - Word16 i,k; + Word16 i, k; Word16 sspectra_fx[L_FRAME32k]; Word16 Qss; @@ -101,7 +101,7 @@ static void DecodeSWBSubbands_fx( Word16 QbeL; GainItem_fx pk_sf_fx[N_NBIGGEST_SEARCH_LRG_B]; Word16 pul_res_fx[NB_SWB_SUBBANDS]; - Word16 g_fx; /* Q11 */ + Word16 g_fx; /* Q11 */ Word16 imin_fx; Word16 Qg; @@ -126,45 +126,44 @@ static void DecodeSWBSubbands_fx( pos_max_hfe2 = 0; move16(); - set16_fx(pul_res_fx,0,NB_SWB_SUBBANDS); + set16_fx( pul_res_fx, 0, NB_SWB_SUBBANDS ); - IF( EQ_16(hqswb_clas_fx, HQ_HARMONIC)) + IF( EQ_16( hqswb_clas_fx, HQ_HARMONIC ) ) { pos_max_hfe2 = har_est_fx( L_spectra, fLenLow_fx, &har_freq_est1, &har_freq_est2, &flag_dis, prev_frm_hfe2, subband_search_offset_fx, sbWidth_fx, prev_stab_hfe2 ); - noise_extr_corcod_fx(L_spectra, L_spectra_ni, sspectra_fx, sspectra_diff_fx, sspectra_ni_fx, fLenLow_fx, hHQ_core->prev_hqswb_clas, &(hHQ_core->prev_ni_ratio_fx), &Qss); + noise_extr_corcod_fx( L_spectra, L_spectra_ni, sspectra_fx, sspectra_diff_fx, sspectra_ni_fx, fLenLow_fx, hHQ_core->prev_hqswb_clas, &( hHQ_core->prev_ni_ratio_fx ), &Qss ); IF( flag_dis == 0 ) { test(); - if( NE_16(har_freq_est2, SWB_HAR_RAN1)||NE_16(har_freq_est2,*prev_frm_hfe2)) + if ( NE_16( har_freq_est2, SWB_HAR_RAN1 ) || NE_16( har_freq_est2, *prev_frm_hfe2 ) ) { - har_freq_est2 = add(har_freq_est2, lagIndices_fx[0]); + har_freq_est2 = add( har_freq_est2, lagIndices_fx[0] ); } } /* Generate HF noise */ - genhf_noise_fx(sspectra_diff_fx, Qss, L_xSynth_har, QsL, sspectra_fx, BANDS_fx, har_bands_fx, har_freq_est2, pos_max_hfe2, pul_res_fx, pk_sf_fx, fLenLow_fx, fLenHigh_fx, sbWidth_fx, lagIndices_fx, subband_offsets_fx, subband_search_offset_fx); + genhf_noise_fx( sspectra_diff_fx, Qss, L_xSynth_har, QsL, sspectra_fx, BANDS_fx, har_bands_fx, har_freq_est2, pos_max_hfe2, pul_res_fx, pk_sf_fx, fLenLow_fx, fLenHigh_fx, sbWidth_fx, lagIndices_fx, subband_offsets_fx, subband_search_offset_fx ); - imin_fx = get_next_indice(st_fx, 2); + imin_fx = get_next_indice( st_fx, 2 ); move16(); /* g= pow(10.0f, gain_table_SWB_BWE[imin]) */ - L_temp = L_mult(gain_table_SWB_BWE_fx[imin_fx], 27213); /* Q14+Q13+1=Q28 log(10)/log(2)=3.3219 27213.23(Q13) */ - L_temp = L_shr(L_temp, 12); /* Q28-Q12 -> Q16 */ - temp_lo_fx = L_Extract_lc(L_temp, &temp_hi_fx); - Qg = sub(14, temp_hi_fx); - g_fx = extract_l(Pow2(14, temp_lo_fx)); - g_fx = shl(g_fx, sub(11, Qg)); + L_temp = L_mult( gain_table_SWB_BWE_fx[imin_fx], 27213 ); /* Q14+Q13+1=Q28 log(10)/log(2)=3.3219 27213.23(Q13) */ + L_temp = L_shr( L_temp, 12 ); /* Q28-Q12 -> Q16 */ + temp_lo_fx = L_Extract_lc( L_temp, &temp_hi_fx ); + Qg = sub( 14, temp_hi_fx ); + g_fx = extract_l( Pow2( 14, temp_lo_fx ) ); + g_fx = shl( g_fx, sub( 11, Qg ) ); /* tonal energy estimation */ ton_ene_est_fx( L_xSynth_har, QsL, L_be_tonal, &QbeL, L_band_energy, Qbe, band_start_fx, band_end_fx, band_width_fx, fLenLow_fx, fLenHigh_fx, - BANDS_fx, har_bands_fx, g_fx, pk_sf_fx, Qss, pul_res_fx - ); + BANDS_fx, har_bands_fx, g_fx, pk_sf_fx, Qss, pul_res_fx ); /*HF Spectrum Generation*/ Gettonl_scalfact_fx( L_xSynth_har, QsL, L_spectra_ni, fLenLow_fx, fLenHigh_fx, har_bands_fx, BANDS_fx, L_band_energy, Qbe, band_start_fx, band_end_fx, - p2a_flags_fx, L_be_tonal, QbeL, pk_sf_fx ,Qss, pul_res_fx); + p2a_flags_fx, L_be_tonal, QbeL, pk_sf_fx, Qss, pul_res_fx ); IF( flag_dis == 0 ) { @@ -181,20 +180,20 @@ static void DecodeSWBSubbands_fx( { FOR( i = band_start_fx[k]; i <= band_end_fx[k]; i++ ) { - L_spectra[i] = L_xSynth_har[i-fLenLow_fx]; + L_spectra[i] = L_xSynth_har[i - fLenLow_fx]; move32(); /* QsL */ } } } - ELSE IF ( EQ_16(hqswb_clas_fx, HQ_NORMAL)) + ELSE IF( EQ_16( hqswb_clas_fx, HQ_NORMAL ) ) { ss_min_fx = spectrumsmooth_noiseton_fx( - L_spectra, /*QsL,*/ L_spectra_ni, sspectra_fx, sspectra_diff_fx, sspectra_ni_fx, &Qss, fLenLow_fx, ni_seed_fx); + L_spectra, /*QsL,*/ L_spectra_ni, sspectra_fx, sspectra_diff_fx, sspectra_ni_fx, &Qss, fLenLow_fx, ni_seed_fx ); convert_lagIndices_pls2smp_fx( lagIndices_fx, nBands_fx, lagIndices_real_fx, sspectra_fx, sbWidth_fx, fLenLow_fx ); - FOR (k = 0; k < nBands_fx; k++) + FOR( k = 0; k < nBands_fx; k++ ) { - if ( EQ_16(p2a_flags_fx[BANDS_fx-NB_SWB_SUBBANDS+k], 1)) + if ( EQ_16( p2a_flags_fx[BANDS_fx - NB_SWB_SUBBANDS + k], 1 ) ) { lagIndices_real_fx[k] = 0; move16(); @@ -202,12 +201,12 @@ static void DecodeSWBSubbands_fx( } GetlagGains_fx( sspectra_ni_fx, Qss, - &L_band_energy[BANDS_fx-NB_SWB_SUBBANDS], Qbe, + &L_band_energy[BANDS_fx - NB_SWB_SUBBANDS], Qbe, nBands_fx, sbWidth_fx, lagIndices_real_fx, fLenLow_fx, lagGains_fx, QlagGains ); - FOR(k=0; k Qs */ + L_th_g[k] = L_shl( L_mult( lagGains_fx[k], ss_min_fx ), sub( QsL, add( add( QlagGains[k], Qss ), 1 ) ) ); /* QlagGain+Qss -> Qs */ } } /* Construct spectrum */ GetSynthesizedSpecThinOut_fx( sspectra_ni_fx, Qss, L_xSynth_har, QsL, nBands_fx, sbWidth_fx, - lagIndices_real_fx, lagGains_fx, QlagGains, fLenLow_fx - ); + lagIndices_real_fx, lagGains_fx, QlagGains, fLenLow_fx ); /* Level adjustment for the missing bands */ noiseinj_hf_fx( L_xSynth_har, QsL, L_th_g, L_band_energy, Qbe, hHQ_core->prev_En_sb_fx, - p2a_flags_fx, BANDS_fx, band_start_fx, band_end_fx, fLenLow_fx, fLenHigh_fx); - FOR( k = sub(BANDS_fx, NB_SWB_SUBBANDS); k < BANDS_fx; k++ ) + p2a_flags_fx, BANDS_fx, band_start_fx, band_end_fx, fLenLow_fx, fLenHigh_fx ); + FOR( k = sub( BANDS_fx, NB_SWB_SUBBANDS ); k < BANDS_fx; k++ ) { IF( p2a_flags_fx[k] == 0 ) { FOR( i = band_start_fx[k]; i <= band_end_fx[k]; i++ ) { - L_spectra[i] = L_xSynth_har[i-fLenLow_fx]; + L_spectra[i] = L_xSynth_har[i - fLenLow_fx]; move32(); /* QsL */ } } @@ -269,25 +267,25 @@ static void DecodeSWBSubbands_fx( *-------------------------------------------------------------------*/ void swb_bwe_dec_lr_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word32 L_m_core[], /* i : lowband synthesis */ - const Word16 QsL, /* i : Q value of m_core */ - Word32 L_m[], /* o : highband synthesis with lowband zeroed */ - const Word32 L_total_brate, /* i : total bitrate for selecting subband pattern */ - Word16 BANDS_fx, /* i : Number subbands/Frame */ - Word16 *band_start_fx, /* i : Band Start of each SB */ - Word16 *band_end_fx, /* i : Band end of each SB */ - Word32 *L_band_energy, /* i : Band energy of each SB : Qbe */ - Word16 Qbe, /* i : Q value of band energy */ - Word16 *p2a_flags_fx, /* i : HF tonal Indicator */ - const Word16 hqswb_clas_fx, /* i : class information */ - Word16 lowlength_fx, /* i : Lowband Length */ - Word16 highlength_fx, /* i : Highband Length */ - const Word16 har_bands_fx, /* i : Number of LF harmonic bands */ + const Word32 L_m_core[], /* i : lowband synthesis */ + const Word16 QsL, /* i : Q value of m_core */ + Word32 L_m[], /* o : highband synthesis with lowband zeroed */ + const Word32 L_total_brate, /* i : total bitrate for selecting subband pattern */ + Word16 BANDS_fx, /* i : Number subbands/Frame */ + Word16 *band_start_fx, /* i : Band Start of each SB */ + Word16 *band_end_fx, /* i : Band end of each SB */ + Word32 *L_band_energy, /* i : Band energy of each SB : Qbe */ + Word16 Qbe, /* i : Q value of band energy */ + Word16 *p2a_flags_fx, /* i : HF tonal Indicator */ + const Word16 hqswb_clas_fx, /* i : class information */ + Word16 lowlength_fx, /* i : Lowband Length */ + Word16 highlength_fx, /* i : Highband Length */ + const Word16 har_bands_fx, /* i : Number of LF harmonic bands */ Word16 *prev_frm_hfe2, /* i/o: */ Word16 *prev_stab_hfe2, /* i/o: */ - Word16 band_width_fx[], /* i : subband bandwidth */ - const Word32 L_y2_ni[], /* i/o: Sparse filled corecoder */ - Word16 *ni_seed_fx /* i/o: random seed */ + Word16 band_width_fx[], /* i : subband bandwidth */ + const Word32 L_y2_ni[], /* i/o: Sparse filled corecoder */ + Word16 *ni_seed_fx /* i/o: random seed */ ) { Word16 k; @@ -307,8 +305,8 @@ void swb_bwe_dec_lr_fx( subband_search_offset_fx = subband_search_offsets_13p2kbps_Har; subband_offsets_fx = subband_offsets_sub5_13p2kbps_Har; - hf_parinitiz_fx(L_total_brate,hqswb_clas_fx,lowlength_fx,highlength_fx,wBands_fx,&subband_search_offset_fx,&subband_offsets_fx,&nBands_fx,&nBands_search_fx,&swb_lowband_fx,&swb_highband_fx); - allband_fx = add(swb_lowband_fx, swb_highband_fx); + hf_parinitiz_fx( L_total_brate, hqswb_clas_fx, lowlength_fx, highlength_fx, wBands_fx, &subband_search_offset_fx, &subband_offsets_fx, &nBands_fx, &nBands_search_fx, &swb_lowband_fx, &swb_highband_fx ); + allband_fx = add( swb_lowband_fx, swb_highband_fx ); move16(); /* Decoding of the SWB parameters */ @@ -318,29 +316,29 @@ void swb_bwe_dec_lr_fx( Copy32( L_m_core, L_m, swb_lowband_fx + swb_highband_fx ); /* Generic subband processing */ - DecodeSWBSubbands_fx(st_fx,st_fx->hHQ_core,L_m, QsL,swb_lowband_fx, swb_highband_fx, nBands_fx, wBands_fx, subband_offsets_fx, - lagIndices_fx, lagGains_fx, QlagGains,BANDS_fx, band_start_fx, band_end_fx, - L_band_energy, Qbe, p2a_flags_fx, hqswb_clas_fx, har_bands_fx, subband_search_offset_fx, - prev_frm_hfe2, prev_stab_hfe2, band_width_fx, L_y2_ni, ni_seed_fx); + DecodeSWBSubbands_fx( st_fx, st_fx->hHQ_core, L_m, QsL, swb_lowband_fx, swb_highband_fx, nBands_fx, wBands_fx, subband_offsets_fx, + lagIndices_fx, lagGains_fx, QlagGains, BANDS_fx, band_start_fx, band_end_fx, + L_band_energy, Qbe, p2a_flags_fx, hqswb_clas_fx, har_bands_fx, subband_search_offset_fx, + prev_frm_hfe2, prev_stab_hfe2, band_width_fx, L_y2_ni, ni_seed_fx ); - p_L_m = &L_m[sub(allband_fx, 1)]; - *p_L_m = Mult_32_16(*p_L_m, 2028); + p_L_m = &L_m[sub( allband_fx, 1 )]; + *p_L_m = Mult_32_16( *p_L_m, 2028 ); move32(); p_L_m--; /* 0.0625 = 2028 (Q15) */ - *p_L_m = Mult_32_16(*p_L_m, 4096); + *p_L_m = Mult_32_16( *p_L_m, 4096 ); move32(); p_L_m--; /* 0.125 = 4096 (Q15) */ - *p_L_m = Mult_32_16(*p_L_m, 8192); + *p_L_m = Mult_32_16( *p_L_m, 8192 ); move32(); p_L_m--; /* 0.25 = 8192 (Q15) */ - *p_L_m = Mult_32_16(*p_L_m, 16384); + *p_L_m = Mult_32_16( *p_L_m, 16384 ); move32(); p_L_m--; /* 0.5 = 16384 (Q15) */ /* set low frequencies to zero */ - FOR ( k = 0; k < swb_lowband_fx; k++ ) + FOR( k = 0; k < swb_lowband_fx; k++ ) { - L_m[k] = L_deposit_l(0); + L_m[k] = L_deposit_l( 0 ); } return; diff --git a/lib_dec/swb_tbe_dec.c b/lib_dec/swb_tbe_dec.c index a6e9c72a3..37e2b6b08 100644 --- a/lib_dec/swb_tbe_dec.c +++ b/lib_dec/swb_tbe_dec.c @@ -62,8 +62,7 @@ static void Dequant_mirror_point( const float lsf_q[], const int16_t m_idx, floa void find_max_mem_dec_m3( Decoder_State *st, - Word16 *n_mem3 -); + Word16 *n_mem3 ); /*-------------------------------------------------------------------* * ResetSHBbuffer_Dec() @@ -99,7 +98,7 @@ void ResetSHBbuffer_Dec( set_f( hBWE_TD->state_syn_shbexc, 0, L_SHB_LAHEAD ); set_f( hBWE_TD->state_lpc_syn, 0, LPC_SHB_ORDER ); - if (extl == FB_TBE) + if ( extl == FB_TBE ) { set_f( hBWE_TD->fb_state_lpc_syn, 0, LPC_SHB_ORDER ); hBWE_TD->fb_tbe_demph = 0; @@ -107,9 +106,9 @@ void ResetSHBbuffer_Dec( } /* states for the filters used in generating SHB signal from SHB excitation in wideband*/ - set_f(hBWE_TD->mem_genSHBexc_filt_down_shb, 0.0f, (2 * ALLPASSSECTIONS_STEEP + 1)); - set_f(hBWE_TD->mem_genSHBexc_filt_down_wb2, 0.0f, (2 * ALLPASSSECTIONS_STEEP + 1)); - set_f(hBWE_TD->mem_genSHBexc_filt_down_wb3, 0.0f, (2 * ALLPASSSECTIONS_STEEP + 1)); + set_f( hBWE_TD->mem_genSHBexc_filt_down_shb, 0.0f, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); + set_f( hBWE_TD->mem_genSHBexc_filt_down_wb2, 0.0f, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); + set_f( hBWE_TD->mem_genSHBexc_filt_down_wb3, 0.0f, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); set_f( hBWE_TD->state_lsyn_filt_shb, 0, 2 * ALLPASSSECTIONS_STEEP ); set_f( hBWE_TD->state_lsyn_filt_dwn_shb, 0, 2 * ALLPASSSECTIONS_STEEP ); @@ -146,11 +145,11 @@ void ResetSHBbuffer_Dec( hBWE_TD->tbe_premph = 0.0f; set_f( hBWE_TD->mem_stp_swb, 0, LPC_SHB_ORDER ); hBWE_TD->gain_prec_swb = 1.0f; - set_f(hBWE_TD->GainShape_Delay, 0, NUM_SHB_SUBFR / 2); + set_f( hBWE_TD->GainShape_Delay, 0, NUM_SHB_SUBFR / 2 ); hBWE_TD->prev_pow_exc16kWhtnd = 1.0f; hBWE_TD->prev_mix_factor = 1.0f; - set_f(hBWE_TD->old_core_synth, 0, L_FRAME16k); + set_f( hBWE_TD->old_core_synth, 0, L_FRAME16k ); set_f( hBWE_TD->old_tbe_synth, 0, L_SHB_TRANSITION_LENGTH ); hBWE_TD->tilt_swb_fec = 0.0f; @@ -461,56 +460,56 @@ void wb_tbe_dec( static void calc_tilt_bwe_fx_loc( const Word32 *sp_fx, /* i : input signal */ Word32 *tilt_fx, /* o : signal tilt */ - Word16 *tilt_fx_q, /* o : signal tilt */ - const Word16 N /* i : signal length */ + Word16 *tilt_fx_q, /* o : signal tilt */ + const Word16 N /* i : signal length */ ) { Word16 i; Word64 r0_fx, r1_fx; r0_fx = EPSILON_FX_SMALL; - FOR(i = 0; i < N; i++) + FOR( i = 0; i < N; i++ ) { - r0_fx += ((Word64)sp_fx[i]) * (sp_fx[i]); + r0_fx += ( (Word64) sp_fx[i] ) * ( sp_fx[i] ); } - r1_fx = abs(sp_fx[1] - sp_fx[0]); - FOR(i = 2; i < N; i++) + r1_fx = abs( sp_fx[1] - sp_fx[0] ); + FOR( i = 2; i < N; i++ ) { - IF (((Word64)(sp_fx[i] - sp_fx[i - 1])) * (sp_fx[i - 1] - sp_fx[i - 2]) < 0) + IF( ( (Word64) ( sp_fx[i] - sp_fx[i - 1] ) ) * ( sp_fx[i - 1] - sp_fx[i - 2] ) < 0 ) { - r1_fx += abs(sp_fx[i] - sp_fx[i - 1]); + r1_fx += abs( sp_fx[i] - sp_fx[i - 1] ); } } - Word16 headroom_left_r0 = W_norm(r0_fx); - Word16 headroom_left_r1 = W_norm(r1_fx); + Word16 headroom_left_r0 = W_norm( r0_fx ); + Word16 headroom_left_r1 = W_norm( r1_fx ); Word16 r0_q = 0, r1_q = 0; - //Word16 r0_bits_occ = 0, r1_bits_occ = 0; - IF(headroom_left_r0 < 32) + // Word16 r0_bits_occ = 0, r1_bits_occ = 0; + IF( headroom_left_r0 < 32 ) { - r0_fx = W_shr(r0_fx, (32 - headroom_left_r0)); - r0_q = (31 - ((2 * OUTPUT_Q) - (32 - headroom_left_r0))); + r0_fx = W_shr( r0_fx, ( 32 - headroom_left_r0 ) ); + r0_q = ( 31 - ( ( 2 * OUTPUT_Q ) - ( 32 - headroom_left_r0 ) ) ); } ELSE { - r0_q = 31 - (2 * OUTPUT_Q); + r0_q = 31 - ( 2 * OUTPUT_Q ); } - IF(headroom_left_r1 < 32) + IF( headroom_left_r1 < 32 ) { - r1_fx = W_shr(r1_fx, (32 - headroom_left_r1)); - r1_q = (OUTPUT_Q - (32 - headroom_left_r1)); + r1_fx = W_shr( r1_fx, ( 32 - headroom_left_r1 ) ); + r1_q = ( OUTPUT_Q - ( 32 - headroom_left_r1 ) ); } ELSE { r1_q = OUTPUT_Q; } - Word32 temp_r0_inv = ISqrt32((Word32)r0_fx, &r0_q); - Word32 res = Mpy_32_32((Word32)r1_fx, temp_r0_inv); - Word16 res_q = r1_q + (r0_q < 0 ? (31 + (-1 * r0_q)) : r0_q) - 31; - Word16 norm_res = norm_l(res); - IF (norm_res > 0) + Word32 temp_r0_inv = ISqrt32( (Word32) r0_fx, &r0_q ); + Word32 res = Mpy_32_32( (Word32) r1_fx, temp_r0_inv ); + Word16 res_q = r1_q + ( r0_q < 0 ? ( 31 + ( -1 * r0_q ) ) : r0_q ) - 31; + Word16 norm_res = norm_l( res ); + IF( norm_res > 0 ) { - *tilt_fx = L_shl_sat(res, norm_res); + *tilt_fx = L_shl_sat( res, norm_res ); *tilt_fx_q = res_q + norm_res; } ELSE @@ -577,7 +576,7 @@ static void rescale_genSHB_mem_dec( static void gradientGainShape( Decoder_State *st_fx, Word16 *GainShape_fx, - Word32 *GainFrame_fx) + Word32 *GainFrame_fx ) { Word16 i, j, tmp; Word16 GainShapeTemp[NUM_SHB_SUBFR / 4]; @@ -589,13 +588,13 @@ static void gradientGainShape( /* the previous frame gainshape gradient and the gainshape gradient pattern for the current frame */ - FOR(j = 0; j < 3; j++) + FOR( j = 0; j < 3; j++ ) { - GainGrad0[j] = sub(shr(st_fx->GainShape_Delay[j + 1], 1), shr(st_fx->GainShape_Delay[j], 1)); + GainGrad0[j] = sub( shr( st_fx->GainShape_Delay[j + 1], 1 ), shr( st_fx->GainShape_Delay[j], 1 ) ); move16(); /* Q14 */ - GainGrad1[j] = sub(shr(st_fx->GainShape_Delay[j + 5], 1), shr(st_fx->GainShape_Delay[j + 4], 1)); + GainGrad1[j] = sub( shr( st_fx->GainShape_Delay[j + 5], 1 ), shr( st_fx->GainShape_Delay[j + 4], 1 ) ); move16(); /* Q14 */ - GainGradFEC[j + 1] = add(mult_r(GainGrad0[j], 13107), mult_r(GainGrad1[j], 19660)); + GainGradFEC[j + 1] = add( mult_r( GainGrad0[j], 13107 ), mult_r( GainGrad1[j], 19660 ) ); move16(); /* Q14 */ } @@ -603,95 +602,95 @@ static void gradientGainShape( test(); test(); test(); - IF(((GT_16(shr(GainGrad1[2], 1), GainGrad1[1])) && (GT_16(shr(GainGrad1[1], 1), GainGrad1[0]))) || - ((LT_16(shr(GainGrad1[2], 1), GainGrad1[1])) && (LT_16(shr(GainGrad1[1], 1), GainGrad1[0])))) + IF( ( ( GT_16( shr( GainGrad1[2], 1 ), GainGrad1[1] ) ) && ( GT_16( shr( GainGrad1[1], 1 ), GainGrad1[0] ) ) ) || + ( ( LT_16( shr( GainGrad1[2], 1 ), GainGrad1[1] ) ) && ( LT_16( shr( GainGrad1[1], 1 ), GainGrad1[0] ) ) ) ) { - GainGradFEC[0] = add(mult_r(GainGrad1[1], 3277), mult_r(GainGrad1[2], 29490)); + GainGradFEC[0] = add( mult_r( GainGrad1[1], 3277 ), mult_r( GainGrad1[2], 29490 ) ); move16(); /* Q14 */ } ELSE { - GainGradFEC[0] = add(mult_r(GainGrad1[0], 6553), mult_r(GainGrad1[1], 9830)); + GainGradFEC[0] = add( mult_r( GainGrad1[0], 6553 ), mult_r( GainGrad1[1], 9830 ) ); move16(); - GainGradFEC[0] = add(GainGradFEC[0], mult_r(GainGrad1[2], 16384)); + GainGradFEC[0] = add( GainGradFEC[0], mult_r( GainGrad1[2], 16384 ) ); move16(); /* Q14 */ } - /* get the first gainshape template */ + /* get the first gainshape template */ test(); test(); - IF((st_fx->prev_coder_type == UNVOICED || st_fx->last_good == UNVOICED_CLAS) && GainGradFEC[0] > 0) + IF( ( st_fx->prev_coder_type == UNVOICED || st_fx->last_good == UNVOICED_CLAS ) && GainGradFEC[0] > 0 ) { - GainShapeTemp[0] = add(shr(st_fx->GainShape_Delay[7], 1), GainGradFEC[0]); + GainShapeTemp[0] = add( shr( st_fx->GainShape_Delay[7], 1 ), GainGradFEC[0] ); move16(); } - ELSE IF(GainGradFEC[0] > 0) + ELSE IF( GainGradFEC[0] > 0 ) { - GainShapeTemp[0] = add(shr(st_fx->GainShape_Delay[7], 1), mult_r(GainGradFEC[0], 16384)); + GainShapeTemp[0] = add( shr( st_fx->GainShape_Delay[7], 1 ), mult_r( GainGradFEC[0], 16384 ) ); move16(); /* Q14 */ } ELSE { - GainShapeTemp[0] = shr(st_fx->GainShape_Delay[7], 1); + GainShapeTemp[0] = shr( st_fx->GainShape_Delay[7], 1 ); move16(); /* Q14 */ } - /*Get the second the third and the fourth gainshape template*/ + /*Get the second the third and the fourth gainshape template*/ - tmp = shr(GainGrad1[2], 3); /* GainGrad1[2]/8 */ - tmp = mult_r(tmp, 26214); /* 0.8 in Q15 tmp*(8/10) */ + tmp = shr( GainGrad1[2], 3 ); /* GainGrad1[2]/8 */ + tmp = mult_r( tmp, 26214 ); /* 0.8 in Q15 tmp*(8/10) */ test(); - IF((GT_16(tmp, GainGrad1[1])) && GainGrad1[1] > 0) + IF( ( GT_16( tmp, GainGrad1[1] ) ) && GainGrad1[1] > 0 ) { - FOR(i = 1; i < NUM_SHB_SUBFR / 4; i++) + FOR( i = 1; i < NUM_SHB_SUBFR / 4; i++ ) { - GainShapeTemp[i] = add(GainShapeTemp[i - 1], mult_r(GainGradFEC[i], 26214)); + GainShapeTemp[i] = add( GainShapeTemp[i - 1], mult_r( GainGradFEC[i], 26214 ) ); move16(); /* GainShapeTemp[i-1] + 0.8* GainShapeTemp[i] */ - GainShapeTemp[i] = s_max(GainShapeTemp[i], 328 /*0.01f Q15*/); + GainShapeTemp[i] = s_max( GainShapeTemp[i], 328 /*0.01f Q15*/ ); move16(); } } ELSE { test(); - IF((GT_16(tmp, GainGrad1[1])) && GainGrad1[1] < 0) + IF( ( GT_16( tmp, GainGrad1[1] ) ) && GainGrad1[1] < 0 ) { - FOR(i = 1; i < NUM_SHB_SUBFR / 4; i++) + FOR( i = 1; i < NUM_SHB_SUBFR / 4; i++ ) { - GainShapeTemp[i] = add(GainShapeTemp[i - 1], mult_r(GainGradFEC[i], 6553)); + GainShapeTemp[i] = add( GainShapeTemp[i - 1], mult_r( GainGradFEC[i], 6553 ) ); move16(); /* GainShapeTemp[i-1] + 0.8* GainShapeTemp[i] */ - GainShapeTemp[i] = s_max(GainShapeTemp[i], 328 /*0.01f Q15*/); + GainShapeTemp[i] = s_max( GainShapeTemp[i], 328 /*0.01f Q15*/ ); move16(); /* Q14 */ } } ELSE { - FOR(i = 1; i < NUM_SHB_SUBFR / 4; i++) + FOR( i = 1; i < NUM_SHB_SUBFR / 4; i++ ) { - GainShapeTemp[i] = add(GainShapeTemp[i - 1], GainGradFEC[i]); + GainShapeTemp[i] = add( GainShapeTemp[i - 1], GainGradFEC[i] ); move16(); - GainShapeTemp[i] = s_max(GainShapeTemp[i], 328 /*0.01f Q15*/); + GainShapeTemp[i] = s_max( GainShapeTemp[i], 328 /*0.01f Q15*/ ); move16(); } } } - /* Get the gainshape and gain frame for the current frame*/ + /* Get the gainshape and gain frame for the current frame*/ test(); test(); test(); - IF((st_fx->prev_coder_type == UNVOICED || st_fx->last_good == UNVOICED_CLAS) && st_fx->nbLostCmpt == 1) + IF( ( st_fx->prev_coder_type == UNVOICED || st_fx->last_good == UNVOICED_CLAS ) && st_fx->nbLostCmpt == 1 ) { - FOR(i = 0; i < NUM_SHB_SUBFR / 4; i++) + FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) { - FOR(j = 0; j < 4; j++) + FOR( j = 0; j < 4; j++ ) { - tmp = mult_r(GainShapeTemp[i], 19660); /* GainShapeTemp[i]*0.6 */ + tmp = mult_r( GainShapeTemp[i], 19660 ); /* GainShapeTemp[i]*0.6 */ - IF(GT_16(8192, tmp)) + IF( GT_16( 8192, tmp ) ) { - GainShape_fx[i * 4 + j] = shl(tmp, 2); + GainShape_fx[i * 4 + j] = shl( tmp, 2 ); move16(); /* (GainShapeTemp[i]*0.6)>>1 */ } ELSE @@ -701,17 +700,17 @@ static void gradientGainShape( } } } - hBWE_TD->GainAttn_fx = mult_r(hBWE_TD->GainAttn_fx, 31129); + hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 31129 ); } - ELSE IF(st_fx->prev_coder_type == UNVOICED || st_fx->last_good == UNVOICED_CLAS) + ELSE IF( st_fx->prev_coder_type == UNVOICED || st_fx->last_good == UNVOICED_CLAS ) { - FOR(i = 0; i < NUM_SHB_SUBFR / 4; i++) + FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) { - FOR(j = 0; j < 4; j++) + FOR( j = 0; j < 4; j++ ) { - IF(LT_16(GainShapeTemp[i], 16384)) + IF( LT_16( GainShapeTemp[i], 16384 ) ) { - GainShape_fx[i * 4 + j] = shl(GainShapeTemp[i], 1); + GainShape_fx[i * 4 + j] = shl( GainShapeTemp[i], 1 ); move16(); } ELSE @@ -721,29 +720,29 @@ static void gradientGainShape( } } } - hBWE_TD->GainAttn_fx = mult_r(hBWE_TD->GainAttn_fx, 31129); + hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 31129 ); } - ELSE IF(st_fx->nbLostCmpt > 1) + ELSE IF( st_fx->nbLostCmpt > 1 ) { - FOR(i = 0; i < NUM_SHB_SUBFR / 4; i++) + FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) { - FOR(j = 0; j < 4; j++) + FOR( j = 0; j < 4; j++ ) { GainShape_fx[i * 4 + j] = GainShapeTemp[i]; move16(); } } - hBWE_TD->GainAttn_fx = mult_r(hBWE_TD->GainAttn_fx, 16384); + hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 16384 ); } ELSE { - FOR(i = 0; i < NUM_SHB_SUBFR / 4; i++) + FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) { - FOR(j = 0; j < 4; j++) + FOR( j = 0; j < 4; j++ ) { - IF(LT_16(GainShapeTemp[i], 16384)) + IF( LT_16( GainShapeTemp[i], 16384 ) ) { - GainShape_fx[i * 4 + j] = shl(GainShapeTemp[i], 1); + GainShape_fx[i * 4 + j] = shl( GainShapeTemp[i], 1 ); move16(); } ELSE @@ -753,22 +752,21 @@ static void gradientGainShape( } } } - hBWE_TD->GainAttn_fx = mult_r(hBWE_TD->GainAttn_fx, 27852); + hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 27852 ); } - *GainFrame_fx = Mult_32_16(hBWE_TD->GainFrame_prevfrm_fx, hBWE_TD->GainAttn_fx); /* Q18 */ + *GainFrame_fx = Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, hBWE_TD->GainAttn_fx ); /* Q18 */ } static void find_max_mem_dec( Decoder_State *st_fx, Word16 *n_mem, - Word16 *n_mem2 - ,Word16 *n_mem3 -) + Word16 *n_mem2, + Word16 *n_mem3 ) { Word16 i; Word16 n_mem_32; - Word16 max = 0; + Word16 max = 0; Word32 Lmax = 0; Word16 tempQ15, max2 = 0; Word16 max3; @@ -779,66 +777,66 @@ static void find_max_mem_dec( /* old BWE exc max */ FOR( i = 0; i < NL_BUFF_OFFSET; i++ ) { - tempQ15 = abs_s(hBWE_TD->old_bwe_exc_extended_fx[i] ); + tempQ15 = abs_s( hBWE_TD->old_bwe_exc_extended_fx[i] ); max = s_max( max, tempQ15 ); } /* decimate all-pass steep memory */ - FOR ( i = 0; i < 7; i++ ) + FOR( i = 0; i < 7; i++ ) { - tempQ15 = abs_s(hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i] ); - max = s_max(max, tempQ15); + tempQ15 = abs_s( hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i] ); + max = s_max( max, tempQ15 ); } /* -- keep norm of state_lpc_syn_fx, state_syn_shbexc_fx, and mem_stp_swb_fx separately for 24.4 and 32kbps ----*/ /* findMaxMem2() inside tbe com */ - FOR ( i = 0; i < LPC_SHB_ORDER; i++ ) + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - tempQ15 = abs_s(hBWE_TD->state_lpc_syn_fx[i] ); - max2 = s_max(max2, tempQ15); + tempQ15 = abs_s( hBWE_TD->state_lpc_syn_fx[i] ); + max2 = s_max( max2, tempQ15 ); } /* findMaxMem2() inside tbe com */ - FOR ( i = 0; i < L_SHB_LAHEAD; i++ ) + FOR( i = 0; i < L_SHB_LAHEAD; i++ ) { - tempQ15 = abs_s(hBWE_TD->state_syn_shbexc_fx[i] ); - max2 = s_max(max2, tempQ15); + tempQ15 = abs_s( hBWE_TD->state_syn_shbexc_fx[i] ); + max2 = s_max( max2, tempQ15 ); } /* findMaxMem2() inside tbe com */ - FOR ( i = 0; i < LPC_SHB_ORDER; i++ ) + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - tempQ15 = abs_s(hBWE_TD->mem_stp_swb_fx[i] ); - max2 = s_max(max2, tempQ15); + tempQ15 = abs_s( hBWE_TD->mem_stp_swb_fx[i] ); + max2 = s_max( max2, tempQ15 ); } /* for total_brate > 16.4kbps, use n_mem2; else account for the max2 for n_mem calculation */ - *n_mem2 = norm_s(max2); - IF(max2 == 0) *n_mem2 = 15; + *n_mem2 = norm_s( max2 ); + IF( max2 == 0 ) *n_mem2 = 15; - IF(LT_32(st_fx->total_brate, ACELP_24k40)) + IF( LT_32( st_fx->total_brate, ACELP_24k40 ) ) { - max = s_max(max, max2); + max = s_max( max, max2 ); } /* de-emph and pre-emph memory */ - tempQ15 = abs_s(hBWE_TD->tbe_demph_fx ); - max = s_max(max, tempQ15); + tempQ15 = abs_s( hBWE_TD->tbe_demph_fx ); + max = s_max( max, tempQ15 ); - tempQ15 = abs_s(hBWE_TD->tbe_premph_fx ); - max = s_max(max, tempQ15); + tempQ15 = abs_s( hBWE_TD->tbe_premph_fx ); + max = s_max( max, tempQ15 ); - IF( EQ_16(st_fx->extl, FB_TBE)) + IF( EQ_16( st_fx->extl, FB_TBE ) ) { - FOR ( i = 0; i < LPC_SHB_ORDER; i++ ) + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - tempQ15 = abs_s(hBWE_TD->fb_state_lpc_syn_fx[i] ); - max = s_max(max, tempQ15); + tempQ15 = abs_s( hBWE_TD->fb_state_lpc_syn_fx[i] ); + max = s_max( max, tempQ15 ); } /* FB de-emph memory */ - tempQ15 = abs_s(hBWE_TD->fb_tbe_demph_fx); - max = s_max(max, tempQ15); + tempQ15 = abs_s( hBWE_TD->fb_tbe_demph_fx ); + max = s_max( max, tempQ15 ); } /* estimate the norm for 16-bit memories */ *n_mem = norm_s( max ); @@ -848,7 +846,7 @@ static void find_max_mem_dec( } /* estimate the norm for 32-bit memories */ - Lmax = L_abs(hBWE_TD->mem_csfilt_fx[0] ); /* only element [0] is used in env. shaping */ + Lmax = L_abs( hBWE_TD->mem_csfilt_fx[0] ); /* only element [0] is used in env. shaping */ n_mem_32 = norm_l( Lmax ); IF( Lmax == 0 ) @@ -866,32 +864,32 @@ static void find_max_mem_dec( 3. st_fx->genSHBsynth_Hilbert_Mem_fx (32-bit) */ max3 = 0; /* find max in prev overlapSyn */ - FOR ( i = 0; i < L_SHB_LAHEAD; i++ ) + FOR( i = 0; i < L_SHB_LAHEAD; i++ ) { - tempQ15 = abs_s(hBWE_TD->syn_overlap_fx[i] ); - max3 = s_max(max3, tempQ15); + tempQ15 = abs_s( hBWE_TD->syn_overlap_fx[i] ); + max3 = s_max( max3, tempQ15 ); } /* find max in prev genSHBsynth_state_lsyn_filt_shb_local_fx */ - FOR ( i = 0; i < 2*ALLPASSSECTIONS_STEEP; i++ ) + FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ ) { - tempQ15 = abs_s(hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i] ); - max3 = s_max(max3, tempQ15); + tempQ15 = abs_s( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i] ); + max3 = s_max( max3, tempQ15 ); } /* find max in prev int_3_over_2_tbemem_dec_fx */ - IF( EQ_32(st_fx->output_Fs, 48000)) + IF( EQ_32( st_fx->output_Fs, 48000 ) ) { - FOR ( i = 0; i < INTERP_3_2_MEM_LEN; i++ ) + FOR( i = 0; i < INTERP_3_2_MEM_LEN; i++ ) { - tempQ15 = abs_s(hBWE_TD->int_3_over_2_tbemem_dec_fx[i] ); - max3 = s_max(max3, tempQ15); + tempQ15 = abs_s( hBWE_TD->int_3_over_2_tbemem_dec_fx[i] ); + max3 = s_max( max3, tempQ15 ); } } - IF( EQ_32(st_fx->output_Fs, 16000)) + IF( EQ_32( st_fx->output_Fs, 16000 ) ) { - FOR ( i = 0; i < (2*ALLPASSSECTIONS_STEEP+1); i++ ) + FOR( i = 0; i < ( 2 * ALLPASSSECTIONS_STEEP + 1 ); i++ ) { - tempQ15 = abs_s(hBWE_TD->mem_resamp_HB_32k_fx[i] ); - max3 = s_max(max3, tempQ15); + tempQ15 = abs_s( hBWE_TD->mem_resamp_HB_32k_fx[i] ); + max3 = s_max( max3, tempQ15 ); } } /* estimate the norm for 16-bit memories */ @@ -899,22 +897,23 @@ static void find_max_mem_dec( IF( max3 == 0 ) *n_mem3 = 15; Lmax3 = 0; - IF(EQ_16(st_fx->L_frame, L_FRAME)) + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { /* find max in prev genSHBsynth_Hilbert_Mem_fx */ - FOR ( i = 0; i < HILBERT_MEM_SIZE; i++ ) + FOR( i = 0; i < HILBERT_MEM_SIZE; i++ ) { - tempQ32 = L_abs(hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i] ); - Lmax3 = L_max(Lmax3, tempQ32); + tempQ32 = L_abs( hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i] ); + Lmax3 = L_max( Lmax3, tempQ32 ); } } /* estimate the norm for 32-bit memories */ n_mem_32 = norm_l( Lmax3 ); - IF( Lmax3 == 0 ) n_mem_32 = 31; + IF( Lmax3 == 0 ) + n_mem_32 = 31; - tempQ15 = sub( s_min( *n_mem3, n_mem_32 ), 2 ); /* very important leave at least 2 bit head room - because of the Hilber transform and Q14 coeffs */ + tempQ15 = sub( s_min( *n_mem3, n_mem_32 ), 2 ); /* very important leave at least 2 bit head room + because of the Hilber transform and Q14 coeffs */ *n_mem3 = s_max( tempQ15, 0 ); /* --------------------------------------------------------------*/ } @@ -922,14 +921,13 @@ static void find_max_mem_dec( void find_max_mem_dec_m3( Decoder_State *st, - Word16 *n_mem3 -) + Word16 *n_mem3 ) { Word16 i; - //Word16 n_mem_32; + // Word16 n_mem_32; Word16 tempQ15; Word16 max3; - //Word32 tempQ32, Lmax3; + // Word32 tempQ32, Lmax3; TD_BWE_DEC_HANDLE hBWE_TD; hBWE_TD = st->hBWE_TD; @@ -938,55 +936,55 @@ void find_max_mem_dec_m3( 1. st->syn_overlap_fx*/ max3 = 0; /* find max in prev overlapSyn */ - FOR(i = 0; i < L_SHB_LAHEAD; i++) + FOR( i = 0; i < L_SHB_LAHEAD; i++ ) { - tempQ15 = abs_s(hBWE_TD->syn_overlap_fx[i]); - max3 = s_max(max3, tempQ15); + tempQ15 = abs_s( hBWE_TD->syn_overlap_fx[i] ); + max3 = s_max( max3, tempQ15 ); } /* find max in prev genSHBsynth_state_lsyn_filt_shb_local_fx */ - //FOR(i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++) + // FOR(i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++) //{ - // tempQ15 = abs_s(hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i]); - // max3 = s_max(max3, tempQ15); - //} + // tempQ15 = abs_s(hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i]); + // max3 = s_max(max3, tempQ15); + // } ///* find max in prev int_3_over_2_tbemem_dec_fx */ - //IF(EQ_32(st->output_Fs, 48000)) + // IF(EQ_32(st->output_Fs, 48000)) //{ - // FOR(i = 0; i < INTERP_3_2_MEM_LEN; i++) - // { - // tempQ15 = abs_s(hBWE_TD->int_3_over_2_tbemem_dec_fx[i]); - // max3 = s_max(max3, tempQ15); - // } - //} - //IF(EQ_32(st->output_Fs, 16000)) + // FOR(i = 0; i < INTERP_3_2_MEM_LEN; i++) + // { + // tempQ15 = abs_s(hBWE_TD->int_3_over_2_tbemem_dec_fx[i]); + // max3 = s_max(max3, tempQ15); + // } + // } + // IF(EQ_32(st->output_Fs, 16000)) //{ - // FOR(i = 0; i < (2 * ALLPASSSECTIONS_STEEP + 1); i++) - // { - // tempQ15 = abs_s(hBWE_TD->mem_resamp_HB_32k_fx[i]); - // max3 = s_max(max3, tempQ15); - // } - //} + // FOR(i = 0; i < (2 * ALLPASSSECTIONS_STEEP + 1); i++) + // { + // tempQ15 = abs_s(hBWE_TD->mem_resamp_HB_32k_fx[i]); + // max3 = s_max(max3, tempQ15); + // } + // } /* estimate the norm for 16-bit memories */ - *n_mem3 = norm_s(max3); - IF (max3 == 0) *n_mem3 = 15; + *n_mem3 = norm_s( max3 ); + IF( max3 == 0 ) *n_mem3 = 15; - //Lmax3 = 0; - //IF(EQ_16(st->L_frame, L_FRAME)) + // Lmax3 = 0; + // IF(EQ_16(st->L_frame, L_FRAME)) //{ - // /* find max in prev genSHBsynth_Hilbert_Mem_fx */ - // FOR(i = 0; i < HILBERT_MEM_SIZE; i++) - // { - // tempQ32 = L_abs(hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i]); - // Lmax3 = L_max(Lmax3, tempQ32); - // } - //} + // /* find max in prev genSHBsynth_Hilbert_Mem_fx */ + // FOR(i = 0; i < HILBERT_MEM_SIZE; i++) + // { + // tempQ32 = L_abs(hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i]); + // Lmax3 = L_max(Lmax3, tempQ32); + // } + // } ///* estimate the norm for 32-bit memories */ - //n_mem_32 = norm_l(Lmax3); - //if (Lmax3 == 0) n_mem_32 = 31; + // n_mem_32 = norm_l(Lmax3); + // if (Lmax3 == 0) n_mem_32 = 31; - //tempQ15 = sub(s_min(*n_mem3, n_mem_32), 2); /* very important leave at least 2 bit head room - // because of the Hilber transform and Q14 coeffs */ + // tempQ15 = sub(s_min(*n_mem3, n_mem_32), 2); /* very important leave at least 2 bit head room + // because of the Hilber transform and Q14 coeffs */ //*n_mem3 = s_max(tempQ15, 0); ///* --------------------------------------------------------------*/ } @@ -1107,7 +1105,7 @@ void ivas_swb_tbe_dec_fx( /* find tilt */ calc_tilt_bwe_fx_loc( old_syn_12k8_16k_fx, &tilt_swb_fec_32_fx, &tilt_swb_fec_fx_q, L_FRAME ); - tilt_swb_fec_fx = extract_l(L_shr( tilt_swb_fec_32_fx, ( tilt_swb_fec_fx_q - 11 ) )); + tilt_swb_fec_fx = extract_l( L_shr( tilt_swb_fec_32_fx, ( tilt_swb_fec_fx_q - 11 ) ) ); IF( st->bfi && st->clas_dec != UNVOICED_CLAS ) { @@ -1116,7 +1114,7 @@ void ivas_swb_tbe_dec_fx( } /* WB/SWB bandwidth switching */ - IF( ( st->tilt_wb_fx > 10240 && st->clas_dec == UNVOICED_CLAS ) || st->tilt_wb_fx > 20480) + IF( ( st->tilt_wb_fx > 10240 && st->clas_dec == UNVOICED_CLAS ) || st->tilt_wb_fx > 20480 ) { test(); test(); @@ -1627,8 +1625,8 @@ void ivas_swb_tbe_dec_fx( IF( st->extl_brate == SWB_TBE_1k10 || st->extl_brate == SWB_TBE_1k75 ) { - Word32 vind_temp = ( L_add( mixFactors_fx, 1 ) * ( ( 1 << NUM_BITS_SHB_VF ) - 1 ) ); // check addition of 1 - vind = extract_l(L_shr( vind_temp, 15 )); /* 3 for mpy by 8.0f, -15 to bring it to Q0 */ /*mixFactors*7*/ + Word32 vind_temp = ( L_add( mixFactors_fx, 1 ) * ( ( 1 << NUM_BITS_SHB_VF ) - 1 ) ); // check addition of 1 + vind = extract_l( L_shr( vind_temp, 15 ) ); /* 3 for mpy by 8.0f, -15 to bring it to Q0 */ /*mixFactors*7*/ /* i: mixFactors_fx in Q15 */ /* o: vind in Q0 */ } @@ -1914,8 +1912,8 @@ void ivas_swb_tbe_dec_fx( { L_tmp = L_shl( L_mult0( ener_fx, st->tilt_wb_fx ), sub( st->Q_syn2, 13 ) ); /* 2+11 +st->Q_syn2 -13 = st->Q_syn2*/ exp_ener = norm_s( ener_fx ); - tmp = shl( ener_fx, exp_ener ); /*Q(2+exp)*/ - inv_ener = shr(div_s( 16384, tmp ), 1); /*Q(15+14-2-exp-1) = 26 - exp*/ + tmp = shl( ener_fx, exp_ener ); /*Q(2+exp)*/ + inv_ener = shr( div_s( 16384, tmp ), 1 ); /*Q(15+14-2-exp-1) = 26 - exp*/ test(); IF( GT_32( L_tmp, st->enerLH_fx ) ) /*st->Q_syn2*/ @@ -1997,8 +1995,8 @@ void ivas_swb_tbe_dec_fx( { ener_fx = s_max( 1, ener_fx ); exp_ener = norm_s( ener_fx ); - tmp = shl( ener_fx, exp_ener ); /*Q(2+exp)*/ - inv_ener = div_s( 16384, tmp ); /*Q(15+14-2-exp)*/ + tmp = shl( ener_fx, exp_ener ); /*Q(2+exp)*/ + inv_ener = div_s( 16384, tmp ); /*Q(15+14-2-exp)*/ prev_ener_ratio_fx = L_shr( L_mult0( st->prev_ener_shb_fx, inv_ener ), add( sub( 9, exp_ener ), 1 ) ); /*Q: 1+27-exp-9+exp-1 = 18 */ } @@ -3271,7 +3269,7 @@ void swb_tbe_dec( else { /* individual sqrt to avoid infinite (nan) value due to acelp_core_dec changes */ - scale = (float)sqrt(curr_pow / prev_pow); + scale = (float) sqrt( curr_pow / prev_pow ); } for ( i = 0; i < L_SHB_LAHEAD; i++ ) @@ -4589,7 +4587,7 @@ void TBEreset_dec( #endif #ifdef IVAS_FLOAT_FIXED set_val_Word16( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); - hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l(0); + hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 ); st->prev_Q_bwe_exc = 31; #endif } @@ -4747,4 +4745,4 @@ void td_bwe_dec_init( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index b62bcd3ba..11421e1e1 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -3,7 +3,6 @@ ====================================================================================*/ - #include #include "options.h" #include "rom_com.h" @@ -21,25 +20,23 @@ *-----------------------------------------------------------------*/ -static void dequantizeSHBparams_fx_9_1( Decoder_State* st_fx, const Word16 extl, Word32 extl_brate, - Word16* Q_lsf, Word16* Q_subgain, Word32* Q_framegrain, Word16* uv_flag, - Word32* Q_shb_ener_sf_32, Word16* Q_shb_res_gshape, Word16* Q_mixFactors); +static void dequantizeSHBparams_fx_9_1( Decoder_State *st_fx, const Word16 extl, Word32 extl_brate, Word16 *Q_lsf, Word16 *Q_subgain, Word32 *Q_framegrain, Word16 *uv_flag, Word32 *Q_shb_ener_sf_32, Word16 *Q_shb_res_gshape, Word16 *Q_mixFactors ); -static void find_max_mem_dec( Decoder_State* st_fx, Word16* n_mem, Word16 *n_mem2, Word16 *n_mem3 ); -static void rescale_genSHB_mem_dec( Decoder_State* st_fx, Word16 sf ); -static void find_max_mem_wb( Decoder_State* st_fx, Word16* n_mem ); -static void rescale_genWB_mem( Decoder_State* st_fx, Word16 sf ); +static void find_max_mem_dec( Decoder_State *st_fx, Word16 *n_mem, Word16 *n_mem2, Word16 *n_mem3 ); +static void rescale_genSHB_mem_dec( Decoder_State *st_fx, Word16 sf ); +static void find_max_mem_wb( Decoder_State *st_fx, Word16 *n_mem ); +static void rescale_genWB_mem( Decoder_State *st_fx, Word16 sf ); static void Dequant_lower_LSF_fx( const Word16 lsf_idx[], Word16 lsf_q[] ); static void Map_higher_LSF_fx( Word16 lsf_q[], const Word16 m, const Word16 grid_in[] ); -static void Dequant_mirror_point_fx( const Word16 lsf_q[], const Word16 m_idx, Word16* m ); +static void Dequant_mirror_point_fx( const Word16 lsf_q[], const Word16 m_idx, Word16 *m ); Word16 dotp_loc( const Word16 x[], /* i : vector x[] */ const Word32 y[], /* i : vector y[] */ - const int16_t n /* i : vector length */ + const int16_t n /* i : vector length */ ); /* gain shape concealment code */ -static void gradientGainShape(Decoder_State *st_fx, Word16 *GainShape, Word32 *GainFrame); +static void gradientGainShape( Decoder_State *st_fx, Word16 *GainShape, Word32 *GainFrame ); /*-------------------------------------------------------------------* * find_max_mem_dec() @@ -49,13 +46,12 @@ static void gradientGainShape(Decoder_State *st_fx, Word16 *GainShape, Word32 *G static void find_max_mem_dec( Decoder_State *st_fx, Word16 *n_mem, - Word16 *n_mem2 - ,Word16 *n_mem3 -) + Word16 *n_mem2, + Word16 *n_mem3 ) { Word16 i; Word16 n_mem_32; - Word16 max = 0; + Word16 max = 0; Word32 Lmax = 0; Word16 tempQ15, max2 = 0; Word16 max3; @@ -66,79 +62,80 @@ static void find_max_mem_dec( /* old BWE exc max */ FOR( i = 0; i < NL_BUFF_OFFSET; i++ ) { - tempQ15 = abs_s(hBWE_TD->old_bwe_exc_extended_fx[i] ); + tempQ15 = abs_s( hBWE_TD->old_bwe_exc_extended_fx[i] ); max = s_max( max, tempQ15 ); } /* decimate all-pass steep memory */ - FOR ( i = 0; i < 7; i++ ) + FOR( i = 0; i < 7; i++ ) { - tempQ15 = abs_s(hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i] ); - max = s_max(max, tempQ15); + tempQ15 = abs_s( hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i] ); + max = s_max( max, tempQ15 ); } /* -- keep norm of state_lpc_syn_fx, state_syn_shbexc_fx, and mem_stp_swb_fx separately for 24.4 and 32kbps ----*/ /* findMaxMem2() inside tbe com */ - FOR ( i = 0; i < LPC_SHB_ORDER; i++ ) + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - tempQ15 = abs_s(hBWE_TD->state_lpc_syn_fx[i] ); - max2 = s_max(max2, tempQ15); + tempQ15 = abs_s( hBWE_TD->state_lpc_syn_fx[i] ); + max2 = s_max( max2, tempQ15 ); } /* findMaxMem2() inside tbe com */ - FOR ( i = 0; i < L_SHB_LAHEAD; i++ ) + FOR( i = 0; i < L_SHB_LAHEAD; i++ ) { - tempQ15 = abs_s(hBWE_TD->state_syn_shbexc_fx[i] ); - max2 = s_max(max2, tempQ15); + tempQ15 = abs_s( hBWE_TD->state_syn_shbexc_fx[i] ); + max2 = s_max( max2, tempQ15 ); } /* findMaxMem2() inside tbe com */ - FOR ( i = 0; i < LPC_SHB_ORDER; i++ ) + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - tempQ15 = abs_s(hBWE_TD->mem_stp_swb_fx[i] ); - max2 = s_max(max2, tempQ15); + tempQ15 = abs_s( hBWE_TD->mem_stp_swb_fx[i] ); + max2 = s_max( max2, tempQ15 ); } /* for total_brate > 16.4kbps, use n_mem2; else account for the max2 for n_mem calculation */ - *n_mem2 = norm_s(max2); - if(max2 == 0) *n_mem2 = 15; + *n_mem2 = norm_s( max2 ); + if ( max2 == 0 ) + *n_mem2 = 15; - if(LT_32(st_fx->total_brate, ACELP_24k40)) + if ( LT_32( st_fx->total_brate, ACELP_24k40 ) ) { - max = s_max(max, max2); + max = s_max( max, max2 ); } /* de-emph and pre-emph memory */ - tempQ15 = abs_s(hBWE_TD->tbe_demph_fx ); - max = s_max(max, tempQ15); + tempQ15 = abs_s( hBWE_TD->tbe_demph_fx ); + max = s_max( max, tempQ15 ); - tempQ15 = abs_s(hBWE_TD->tbe_premph_fx ); - max = s_max(max, tempQ15); + tempQ15 = abs_s( hBWE_TD->tbe_premph_fx ); + max = s_max( max, tempQ15 ); - IF( EQ_16(st_fx->extl, FB_TBE)) + IF( EQ_16( st_fx->extl, FB_TBE ) ) { - FOR ( i = 0; i < LPC_SHB_ORDER; i++ ) + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - tempQ15 = abs_s(hBWE_TD->fb_state_lpc_syn_fx[i] ); - max = s_max(max, tempQ15); + tempQ15 = abs_s( hBWE_TD->fb_state_lpc_syn_fx[i] ); + max = s_max( max, tempQ15 ); } /* FB de-emph memory */ - tempQ15 = abs_s(hBWE_TD->fb_tbe_demph_fx); - max = s_max(max, tempQ15); + tempQ15 = abs_s( hBWE_TD->fb_tbe_demph_fx ); + max = s_max( max, tempQ15 ); } /* estimate the norm for 16-bit memories */ *n_mem = norm_s( max ); - if( max == 0 ) + if ( max == 0 ) { *n_mem = 15; } /* estimate the norm for 32-bit memories */ - Lmax = L_abs(hBWE_TD->mem_csfilt_fx[0] ); /* only element [0] is used in env. shaping */ + Lmax = L_abs( hBWE_TD->mem_csfilt_fx[0] ); /* only element [0] is used in env. shaping */ n_mem_32 = norm_l( Lmax ); - if( Lmax == 0 ) + if ( Lmax == 0 ) { n_mem_32 = 31; } @@ -153,55 +150,57 @@ static void find_max_mem_dec( 3. st_fx->genSHBsynth_Hilbert_Mem_fx (32-bit) */ max3 = 0; /* find max in prev overlapSyn */ - FOR ( i = 0; i < L_SHB_LAHEAD; i++ ) + FOR( i = 0; i < L_SHB_LAHEAD; i++ ) { - tempQ15 = abs_s(hBWE_TD->syn_overlap_fx[i] ); - max3 = s_max(max3, tempQ15); + tempQ15 = abs_s( hBWE_TD->syn_overlap_fx[i] ); + max3 = s_max( max3, tempQ15 ); } /* find max in prev genSHBsynth_state_lsyn_filt_shb_local_fx */ - FOR ( i = 0; i < 2*ALLPASSSECTIONS_STEEP; i++ ) + FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ ) { - tempQ15 = abs_s(hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i] ); - max3 = s_max(max3, tempQ15); + tempQ15 = abs_s( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i] ); + max3 = s_max( max3, tempQ15 ); } /* find max in prev int_3_over_2_tbemem_dec_fx */ - IF( EQ_32(st_fx->output_Fs, 48000)) + IF( EQ_32( st_fx->output_Fs, 48000 ) ) { - FOR ( i = 0; i < INTERP_3_2_MEM_LEN; i++ ) + FOR( i = 0; i < INTERP_3_2_MEM_LEN; i++ ) { - tempQ15 = abs_s(hBWE_TD->int_3_over_2_tbemem_dec_fx[i] ); - max3 = s_max(max3, tempQ15); + tempQ15 = abs_s( hBWE_TD->int_3_over_2_tbemem_dec_fx[i] ); + max3 = s_max( max3, tempQ15 ); } } - IF( EQ_32(st_fx->output_Fs, 16000)) + IF( EQ_32( st_fx->output_Fs, 16000 ) ) { - FOR ( i = 0; i < (2*ALLPASSSECTIONS_STEEP+1); i++ ) + FOR( i = 0; i < ( 2 * ALLPASSSECTIONS_STEEP + 1 ); i++ ) { - tempQ15 = abs_s(hBWE_TD->mem_resamp_HB_32k_fx[i] ); - max3 = s_max(max3, tempQ15); + tempQ15 = abs_s( hBWE_TD->mem_resamp_HB_32k_fx[i] ); + max3 = s_max( max3, tempQ15 ); } } /* estimate the norm for 16-bit memories */ *n_mem3 = norm_s( max3 ); - if( max3 == 0 ) *n_mem3 = 15; + if ( max3 == 0 ) + *n_mem3 = 15; Lmax3 = 0; - IF(EQ_16(st_fx->L_frame, L_FRAME)) + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { /* find max in prev genSHBsynth_Hilbert_Mem_fx */ - FOR ( i = 0; i < HILBERT_MEM_SIZE; i++ ) + FOR( i = 0; i < HILBERT_MEM_SIZE; i++ ) { - tempQ32 = L_abs(hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i] ); - Lmax3 = L_max(Lmax3, tempQ32); + tempQ32 = L_abs( hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i] ); + Lmax3 = L_max( Lmax3, tempQ32 ); } } /* estimate the norm for 32-bit memories */ n_mem_32 = norm_l( Lmax3 ); - if( Lmax3 == 0 ) n_mem_32 = 31; + if ( Lmax3 == 0 ) + n_mem_32 = 31; - tempQ15 = sub( s_min( *n_mem3, n_mem_32 ), 2 ); /* very important leave at least 2 bit head room - because of the Hilber transform and Q14 coeffs */ + tempQ15 = sub( s_min( *n_mem3, n_mem_32 ), 2 ); /* very important leave at least 2 bit head room + because of the Hilber transform and Q14 coeffs */ *n_mem3 = s_max( tempQ15, 0 ); /* --------------------------------------------------------------*/ } @@ -221,93 +220,92 @@ static void rescale_genSHB_mem_dec( FOR( i = 0; i < NL_BUFF_OFFSET; i++ ) { - hBWE_TD->old_bwe_exc_extended_fx[i] = shl(hBWE_TD->old_bwe_exc_extended_fx[i], sf ); + hBWE_TD->old_bwe_exc_extended_fx[i] = shl( hBWE_TD->old_bwe_exc_extended_fx[i], sf ); move16(); } FOR( i = 0; i < 7; i++ ) { - hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i] = shl(hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i], sf ); + hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i] = shl( hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i], sf ); move16(); } /* -- Apply memory scaling for 13.2 and 16.4k bps using sf ----*/ - IF(LT_32(st_fx->total_brate, ACELP_24k40)) + IF( LT_32( st_fx->total_brate, ACELP_24k40 ) ) { - FOR ( i = 0; i < LPC_SHB_ORDER; i++ ) + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - hBWE_TD->state_lpc_syn_fx[i] = shl(hBWE_TD->state_lpc_syn_fx[i], sf ); + hBWE_TD->state_lpc_syn_fx[i] = shl( hBWE_TD->state_lpc_syn_fx[i], sf ); move16(); } - FOR ( i = 0; i < L_SHB_LAHEAD; i++ ) + FOR( i = 0; i < L_SHB_LAHEAD; i++ ) { - hBWE_TD->state_syn_shbexc_fx[i] = shl(hBWE_TD->state_syn_shbexc_fx[i], sf ); + hBWE_TD->state_syn_shbexc_fx[i] = shl( hBWE_TD->state_syn_shbexc_fx[i], sf ); move16(); } } - IF( EQ_16(st_fx->extl, FB_TBE)) + IF( EQ_16( st_fx->extl, FB_TBE ) ) { } - hBWE_TD->mem_csfilt_fx[0] = L_shl(hBWE_TD->mem_csfilt_fx[0], sf ); + hBWE_TD->mem_csfilt_fx[0] = L_shl( hBWE_TD->mem_csfilt_fx[0], sf ); move32(); - hBWE_TD->tbe_demph_fx = shl_r(hBWE_TD->tbe_demph_fx, sf ); + hBWE_TD->tbe_demph_fx = shl_r( hBWE_TD->tbe_demph_fx, sf ); move16(); - hBWE_TD->tbe_premph_fx = shl_r(hBWE_TD->tbe_premph_fx, sf ); + hBWE_TD->tbe_premph_fx = shl_r( hBWE_TD->tbe_premph_fx, sf ); move16(); - } -void find_max_mem_wb( Decoder_State* st_fx, Word16* n_mem ) +void find_max_mem_wb( Decoder_State *st_fx, Word16 *n_mem ) { Word16 i; - Word16 max = 0; + Word16 max = 0; Word32 Lmax = 0; Word16 n_mem_32; TD_BWE_DEC_HANDLE hBWE_TD; hBWE_TD = st_fx->hBWE_TD; - FOR(i = 0; i < NL_BUFF_OFFSET; i++) + FOR( i = 0; i < NL_BUFF_OFFSET; i++ ) { - max = s_max(max, abs_s(hBWE_TD->old_bwe_exc_extended_fx[i])); + max = s_max( max, abs_s( hBWE_TD->old_bwe_exc_extended_fx[i] ) ); } FOR( i = 0; i < 7; i++ ) { - if( abs_s(hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i] ) > max ) - max = abs_s(hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i] ); + if ( abs_s( hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i] ) > max ) + max = abs_s( hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i] ); } FOR( i = 0; i < 7; i++ ) { - if( abs_s(hBWE_TD->mem_genSHBexc_filt_down_wb2_fx[i] ) > max ) - max = abs_s(hBWE_TD->mem_genSHBexc_filt_down_wb2_fx[i] ); + if ( abs_s( hBWE_TD->mem_genSHBexc_filt_down_wb2_fx[i] ) > max ) + max = abs_s( hBWE_TD->mem_genSHBexc_filt_down_wb2_fx[i] ); } FOR( i = 0; i < 7; i++ ) { - if( abs_s(hBWE_TD->mem_genSHBexc_filt_down_wb3_fx[i] ) > max ) - max = abs_s(hBWE_TD->mem_genSHBexc_filt_down_wb3_fx[i] ); + if ( abs_s( hBWE_TD->mem_genSHBexc_filt_down_wb3_fx[i] ) > max ) + max = abs_s( hBWE_TD->mem_genSHBexc_filt_down_wb3_fx[i] ); } FOR( i = 0; i < 10; i++ ) { - if( abs_s(hBWE_TD->state_lpc_syn_fx[i] ) > max ) - max = abs_s(hBWE_TD->state_lpc_syn_fx[i] ); + if ( abs_s( hBWE_TD->state_lpc_syn_fx[i] ) > max ) + max = abs_s( hBWE_TD->state_lpc_syn_fx[i] ); } FOR( i = 0; i < 5; i++ ) { - if( abs_s(hBWE_TD->state_syn_shbexc_fx[i] ) > max ) - max = abs_s(hBWE_TD->state_syn_shbexc_fx[i] ); + if ( abs_s( hBWE_TD->state_syn_shbexc_fx[i] ) > max ) + max = abs_s( hBWE_TD->state_syn_shbexc_fx[i] ); } - IF ( max == 0 ) + IF( max == 0 ) { *n_mem = 15; move16(); @@ -322,11 +320,11 @@ void find_max_mem_wb( Decoder_State* st_fx, Word16* n_mem ) FOR( i = 0; i < 2; i++ ) { - if( L_abs(hBWE_TD->mem_csfilt_fx[i] ) > Lmax ) - Lmax = L_abs(hBWE_TD->mem_csfilt_fx[i] ); + if ( L_abs( hBWE_TD->mem_csfilt_fx[i] ) > Lmax ) + Lmax = L_abs( hBWE_TD->mem_csfilt_fx[i] ); } - IF ( Lmax == 0 ) + IF( Lmax == 0 ) { n_mem_32 = 31; move16(); @@ -340,7 +338,7 @@ void find_max_mem_wb( Decoder_State* st_fx, Word16* n_mem ) *n_mem = s_max( *n_mem, 0 ); } -void rescale_genWB_mem( Decoder_State* st_fx, Word16 sf ) +void rescale_genWB_mem( Decoder_State *st_fx, Word16 sf ) { Word16 i; TD_BWE_DEC_HANDLE hBWE_TD; @@ -348,43 +346,43 @@ void rescale_genWB_mem( Decoder_State* st_fx, Word16 sf ) FOR( i = 0; i < NL_BUFF_OFFSET; i++ ) { - hBWE_TD->old_bwe_exc_extended_fx[i] = shl(hBWE_TD->old_bwe_exc_extended_fx[i], sf ); + hBWE_TD->old_bwe_exc_extended_fx[i] = shl( hBWE_TD->old_bwe_exc_extended_fx[i], sf ); move16(); } FOR( i = 0; i < 10; i++ ) { - hBWE_TD->state_lpc_syn_fx[i] = shl(hBWE_TD->state_lpc_syn_fx[i], sf ); + hBWE_TD->state_lpc_syn_fx[i] = shl( hBWE_TD->state_lpc_syn_fx[i], sf ); move16(); } FOR( i = 0; i < 5; i++ ) { - hBWE_TD->state_syn_shbexc_fx[i] = shl(hBWE_TD->state_syn_shbexc_fx[i], sf ); + hBWE_TD->state_syn_shbexc_fx[i] = shl( hBWE_TD->state_syn_shbexc_fx[i], sf ); move16(); } FOR( i = 0; i < 7; i++ ) { - hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i] = shl(hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i], sf ); + hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i] = shl( hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i], sf ); move16(); } FOR( i = 0; i < 7; i++ ) { - hBWE_TD->mem_genSHBexc_filt_down_wb2_fx[i] = shl(hBWE_TD->mem_genSHBexc_filt_down_wb2_fx[i], sf ); + hBWE_TD->mem_genSHBexc_filt_down_wb2_fx[i] = shl( hBWE_TD->mem_genSHBexc_filt_down_wb2_fx[i], sf ); move16(); } FOR( i = 0; i < 7; i++ ) { - hBWE_TD->mem_genSHBexc_filt_down_wb3_fx[i] = shl(hBWE_TD->mem_genSHBexc_filt_down_wb3_fx[i], sf ); + hBWE_TD->mem_genSHBexc_filt_down_wb3_fx[i] = shl( hBWE_TD->mem_genSHBexc_filt_down_wb3_fx[i], sf ); move16(); } FOR( i = 0; i < 2; i++ ) { - hBWE_TD->mem_csfilt_fx[i] = L_shl(hBWE_TD->mem_csfilt_fx[i], sf ); + hBWE_TD->mem_csfilt_fx[i] = L_shl( hBWE_TD->mem_csfilt_fx[i], sf ); move32(); } } @@ -392,33 +390,33 @@ void rescale_genWB_mem( Decoder_State* st_fx, Word16 sf ) #ifdef IVAS_FLOAT_FIXED void InitSWBdecBuffer_ivas_fx( - Decoder_State* st_fx /* i/o: SHB decoder structure */ + Decoder_State *st_fx /* i/o: SHB decoder structure */ ) { TD_BWE_DEC_HANDLE hBWE_TD; hBWE_TD = st_fx->hBWE_TD; - set16_fx(hBWE_TD->old_bwe_exc_fx, 0, ( PIT16k_MAX * 2 ) ); + set16_fx( hBWE_TD->old_bwe_exc_fx, 0, ( PIT16k_MAX * 2 ) ); hBWE_TD->bwe_seed[0] = 23; move16(); hBWE_TD->bwe_seed[1] = 59; move16(); - set16_fx(hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); + set16_fx( hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); hBWE_TD->bwe_non_lin_prev_scale_fx = 0; move16(); - set32_fx(hBWE_TD->genSHBsynth_Hilbert_Mem_fx, 0, HILBERT_MEM_SIZE ); - set16_fx(hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, 0, 2*ALLPASSSECTIONS_STEEP); /* Interp all pass memory */ - set32_fx(hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, 0, 2*ALLPASSSECTIONS_STEEP); /* Interp all pass memory */ + set32_fx( hBWE_TD->genSHBsynth_Hilbert_Mem_fx, 0, HILBERT_MEM_SIZE ); + set16_fx( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, 0, 2 * ALLPASSSECTIONS_STEEP ); /* Interp all pass memory */ + set32_fx( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, 0, 2 * ALLPASSSECTIONS_STEEP ); /* Interp all pass memory */ hBWE_TD->syn_dm_phase = 0; move16(); - hBWE_TD->prev_fbbwe_ratio_fx = 32767/*1.0f Q15*/; + hBWE_TD->prev_fbbwe_ratio_fx = 32767 /*1.0f Q15*/; /* these are fd-bwe constants */ - hBWE_TD->prev_wb_bwe_frame_pow_fx = 4194l/*0.001f Q22*/; /* Q22 */ - hBWE_TD->prev_swb_bwe_frame_pow_fx = 4194l/*0.001f Q22*/; /* Q22 */ + hBWE_TD->prev_wb_bwe_frame_pow_fx = 4194l /*0.001f Q22*/; /* Q22 */ + hBWE_TD->prev_swb_bwe_frame_pow_fx = 4194l /*0.001f Q22*/; /* Q22 */ st_fx->prev_Q_bwe_exc = 31; move16(); st_fx->prev_ener_fx_Q = 31; @@ -435,32 +433,32 @@ void InitSWBdecBuffer_ivas_fx( } #endif void InitSWBdecBuffer_fx( - Decoder_State* st_fx /* i/o: SHB decoder structure */ + Decoder_State *st_fx /* i/o: SHB decoder structure */ ) { TD_BWE_DEC_HANDLE hBWE_TD; hBWE_TD = st_fx->hBWE_TD; - set16_fx(hBWE_TD->old_bwe_exc_fx, 0, ( PIT16k_MAX * 2 ) ); + set16_fx( hBWE_TD->old_bwe_exc_fx, 0, ( PIT16k_MAX * 2 ) ); hBWE_TD->bwe_seed[0] = 23; move16(); hBWE_TD->bwe_seed[1] = 59; move16(); - set16_fx(hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); + set16_fx( hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); hBWE_TD->bwe_non_lin_prev_scale_fx = 0; move16(); - set32_fx(hBWE_TD->genSHBsynth_Hilbert_Mem_fx, 0, HILBERT_MEM_SIZE ); - set16_fx(hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, 0, 2*ALLPASSSECTIONS_STEEP); /* Interp all pass memory */ + set32_fx( hBWE_TD->genSHBsynth_Hilbert_Mem_fx, 0, HILBERT_MEM_SIZE ); + set16_fx( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, 0, 2 * ALLPASSSECTIONS_STEEP ); /* Interp all pass memory */ hBWE_TD->syn_dm_phase = 0; move16(); - hBWE_TD->prev_fbbwe_ratio_fx = 32767/*1.0f Q15*/; + hBWE_TD->prev_fbbwe_ratio_fx = 32767 /*1.0f Q15*/; /* these are fd-bwe constants */ - hBWE_TD->prev_wb_bwe_frame_pow_fx = 4194l/*0.001f Q22*/; /* Q22 */ - hBWE_TD->prev_swb_bwe_frame_pow_fx = 4194l/*0.001f Q22*/; /* Q22 */ + hBWE_TD->prev_wb_bwe_frame_pow_fx = 4194l /*0.001f Q22*/; /* Q22 */ + hBWE_TD->prev_swb_bwe_frame_pow_fx = 4194l /*0.001f Q22*/; /* Q22 */ st_fx->prev_Q_bwe_exc = 31; move16(); st_fx->prev_ener_fx_Q = 31; @@ -477,7 +475,7 @@ void InitSWBdecBuffer_fx( } -void ResetSHBbuffer_Dec_fx( Decoder_State* st_fx /* i/o: SHB encoder structure */ ) +void ResetSHBbuffer_Dec_fx( Decoder_State *st_fx /* i/o: SHB encoder structure */ ) { Word16 i; Word16 f; @@ -488,41 +486,41 @@ void ResetSHBbuffer_Dec_fx( Decoder_State* st_fx /* i/o: SHB encoder structure * IF( st_fx->extl != WB_TBE ) { f = 1489; - move16(); /* Q15 */ + move16(); /* Q15 */ inc = 1489; - move16(); /* Q15 */ + move16(); /* Q15 */ } ELSE { f = 5461; - move16();/* Q15 */ + move16(); /* Q15 */ inc = 5461; move16(); /* Q15 */ } /* states for the filters used in generating SHB excitation from WB excitation*/ - set32_fx(hBWE_TD->mem_csfilt_fx, 0, 2 ); + set32_fx( hBWE_TD->mem_csfilt_fx, 0, 2 ); /* states for the filters used in generating SHB signal from SHB excitation*/ - set16_fx(hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD ); - set16_fx(hBWE_TD->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); + set16_fx( hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD ); + set16_fx( hBWE_TD->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); - IF( EQ_16(st_fx->extl, FB_TBE)) + IF( EQ_16( st_fx->extl, FB_TBE ) ) { - set16_fx(hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); + set16_fx( hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); hBWE_TD->fb_tbe_demph_fx = 0; move16(); - fb_tbe_reset_synth_fx(hBWE_TD->fbbwe_hpf_mem_fx, hBWE_TD->fbbwe_hpf_mem_fx_Q,&hBWE_TD->prev_fbbwe_ratio_fx ); + fb_tbe_reset_synth_fx( hBWE_TD->fbbwe_hpf_mem_fx, hBWE_TD->fbbwe_hpf_mem_fx_Q, &hBWE_TD->prev_fbbwe_ratio_fx ); } /* states for the filters used in generating SHB signal from SHB excitation in wideband*/ - set16_fx(hBWE_TD->mem_genSHBexc_filt_down_shb_fx, 0, 2*ALLPASSSECTIONS_STEEP+1); - set16_fx(hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, 0, 2*ALLPASSSECTIONS_STEEP+1); - set16_fx(hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, 0, 2*ALLPASSSECTIONS_STEEP+1); - set16_fx(hBWE_TD->state_lsyn_filt_shb_fx,0, 2 * ALLPASSSECTIONS_STEEP ); - set32_fx(hBWE_TD->state_lsyn_filt_shb_fx_32,0, 2 * ALLPASSSECTIONS_STEEP ); - set16_fx(hBWE_TD->state_lsyn_filt_dwn_shb_fx,0, 2 * ALLPASSSECTIONS_STEEP ); - set32_fx(hBWE_TD->state_lsyn_filt_dwn_shb_fx_32,0, 2 * ALLPASSSECTIONS_STEEP ); - set16_fx(hBWE_TD->state_32and48k_WB_upsample_fx, 0, 2 * ALLPASSSECTIONS_STEEP ); + set16_fx( hBWE_TD->mem_genSHBexc_filt_down_shb_fx, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); + set16_fx( hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); + set16_fx( hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); + set16_fx( hBWE_TD->state_lsyn_filt_shb_fx, 0, 2 * ALLPASSSECTIONS_STEEP ); + set32_fx( hBWE_TD->state_lsyn_filt_shb_fx_32, 0, 2 * ALLPASSSECTIONS_STEEP ); + set16_fx( hBWE_TD->state_lsyn_filt_dwn_shb_fx, 0, 2 * ALLPASSSECTIONS_STEEP ); + set32_fx( hBWE_TD->state_lsyn_filt_dwn_shb_fx_32, 0, 2 * ALLPASSSECTIONS_STEEP ); + set16_fx( hBWE_TD->state_32and48k_WB_upsample_fx, 0, 2 * ALLPASSSECTIONS_STEEP ); /* States for the local synthesis filters */ set16_fx( hBWE_TD->syn_overlap_fx, 0, L_SHB_LAHEAD ); @@ -545,31 +543,31 @@ void ResetSHBbuffer_Dec_fx( Decoder_State* st_fx /* i/o: SHB encoder structure * FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) { hBWE_TD->lsp_prevfrm_fx[i] = f; - move16();/*Q15*/ + move16(); /*Q15*/ f = add( f, inc ); move16(); } - FOR( ; ilsp_prevfrm_fx[i] = 0; move16(); } } hBWE_TD->GainFrame_prevfrm_fx = 0; - move16();/*Q18*/ + move16(); /*Q18*/ hBWE_TD->GainAttn_fx = 32767; - move16();/*Q15*/ + move16(); /*Q15*/ hBWE_TD->tbe_demph_fx = 0; hBWE_TD->tbe_premph_fx = 0; - set16_fx(hBWE_TD->mem_stp_swb_fx, 0, LPC_SHB_ORDER); - hBWE_TD->gain_prec_swb_fx = 16384;/*Q14 =1*/ + set16_fx( hBWE_TD->mem_stp_swb_fx, 0, LPC_SHB_ORDER ); + hBWE_TD->gain_prec_swb_fx = 16384; /*Q14 =1*/ set16_fx( &st_fx->GainShape_Delay[0], 0, NUM_SHB_SUBFR / 2 ); hBWE_TD->prev_pow_exc16kWhtnd_fx32 = 1; /* Q0 1.f */ - hBWE_TD->prev_mix_factor_fx = 32767; /*Q15 1.f*/ + hBWE_TD->prev_mix_factor_fx = 32767; /*Q15 1.f*/ - set16_fx(hBWE_TD->old_core_synth_fx, 0, L_FRAME16k); - set16_fx(hBWE_TD->old_tbe_synth_fx, 0, L_SHB_TRANSITION_LENGTH); - set32_fx(hBWE_TD->old_tbe_synth_fx_32, 0, L_SHB_TRANSITION_LENGTH); + set16_fx( hBWE_TD->old_core_synth_fx, 0, L_FRAME16k ); + set16_fx( hBWE_TD->old_tbe_synth_fx, 0, L_SHB_TRANSITION_LENGTH ); + set32_fx( hBWE_TD->old_tbe_synth_fx_32, 0, L_SHB_TRANSITION_LENGTH ); hBWE_TD->tilt_swb_fec_fx = 0; move16(); @@ -577,8 +575,6 @@ void ResetSHBbuffer_Dec_fx( Decoder_State* st_fx /* i/o: SHB encoder structure * } - - /*==========================================================================*/ /* FUNCTION : void wb_tbe_dec_fx () */ /*--------------------------------------------------------------------------*/ @@ -1189,25 +1185,24 @@ void ivas_wb_tbe_dec_fx( #endif void wb_tbe_dec_fx( - Decoder_State* st_fx, /* i/o: decoder state structure */ - const Word16 coder_type, /* i : coding type */ - Word32* bwe_exc_extended, /* i : bandwidth extended exciatation 2*Q_exc*/ - const Word16 Q_exc, - const Word16 voice_factors[], /* i : voicing factors */ - Word16* synth, /* o : WB synthesis/final synthesis */ - Word16* Q_synth -) + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 coder_type, /* i : coding type */ + Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation 2*Q_exc*/ + const Word16 Q_exc, + const Word16 voice_factors[], /* i : voicing factors */ + Word16 *synth, /* o : WB synthesis/final synthesis */ + Word16 *Q_synth ) { Word16 i; - Word16 shaped_wb_excitation [ ( L_FRAME16k + L_SHB_LAHEAD )/4 ]; - Word16 shaped_wb_excitation_frac[ L_FRAME16k/4 ]; - Word16 bwe_exc_extended_16[ L_FRAME32k+40 ]; - Word16 exc4kWhtnd [ L_FRAME16k / 4]; - Word16 lsf_wb[ LPC_SHB_ORDER_WB ], lpc_wb[ LPC_SHB_ORDER_WB + 1 ], GainShape[ NUM_SHB_SUBFR ]; + Word16 shaped_wb_excitation[( L_FRAME16k + L_SHB_LAHEAD ) / 4]; + Word16 shaped_wb_excitation_frac[L_FRAME16k / 4]; + Word16 bwe_exc_extended_16[L_FRAME32k + 40]; + Word16 exc4kWhtnd[L_FRAME16k / 4]; + Word16 lsf_wb[LPC_SHB_ORDER_WB], lpc_wb[LPC_SHB_ORDER_WB + 1], GainShape[NUM_SHB_SUBFR]; Word32 GainFrame; - Word16 error[ L_FRAME16k ]; - Word16 synth_frac[ L_FRAME16k ]; - Word16 upsampled_synth[ L_FRAME48k ]; + Word16 error[L_FRAME16k]; + Word16 synth_frac[L_FRAME16k]; + Word16 upsampled_synth[L_FRAME48k]; Word32 prev_pow, curr_pow, curr_frame_pow; Word16 curr_frame_pow_exp; Word16 temp, scale, n; @@ -1215,13 +1210,13 @@ void wb_tbe_dec_fx( Word16 Q_bwe_exc, Q_bwe_exc_ext, Qx; Word16 n_mem, cnt; - Word16 max = 0; + Word16 max = 0; Word32 L_tmp, Lacc, Lscale, Lmax = 0; Word16 tmp, exp, sc; - Word16 vf_modified[ NB_SUBFR16k ]; + Word16 vf_modified[NB_SUBFR16k]; Word16 uv_flag = 0; - Word16 dummy=0; - Word32 dummy2[HILBERT_MEM_SIZE]= {0}; + Word16 dummy = 0; + Word32 dummy2[HILBERT_MEM_SIZE] = { 0 }; Word16 f, inc; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; @@ -1232,37 +1227,35 @@ void wb_tbe_dec_fx( IF( st_fx->bws_cnt == 0 ) { /* Initialization */ - set16_fx(GainShape, 11469/*0.35f Q15*/, NUM_SHB_SUBFR); + set16_fx( GainShape, 11469 /*0.35f Q15*/, NUM_SHB_SUBFR ); GainFrame = 1; IF( !st_fx->bfi ) { - IF(EQ_16(st_fx->use_partial_copy,1)) + IF( EQ_16( st_fx->use_partial_copy, 1 ) ) { - IF(NE_16(st_fx->last_extl, WB_TBE)) + IF( NE_16( st_fx->last_extl, WB_TBE ) ) { hBWE_TD->GainFrame_prevfrm_fx = 0; - hBWE_TD->lsp_prevfrm_fx[0] = 3277/*0.1f Q15*/; + hBWE_TD->lsp_prevfrm_fx[0] = 3277 /*0.1f Q15*/; move16(); - FOR (i=1; ilsp_prevfrm_fx[i] = add(hBWE_TD->lsp_prevfrm_fx[i-i], 3277/*0.1f Q15*/); + hBWE_TD->lsp_prevfrm_fx[i] = add( hBWE_TD->lsp_prevfrm_fx[i - i], 3277 /*0.1f Q15*/ ); } } - Copy(hBWE_TD->lsp_prevfrm_fx, lsf_wb, LPC_SHB_ORDER_LBR_WB ); - set16_fx( GainShape, RECIP_ROOT_EIGHT_FX, NUM_SHB_SUBFR/2 ); + Copy( hBWE_TD->lsp_prevfrm_fx, lsf_wb, LPC_SHB_ORDER_LBR_WB ); + set16_fx( GainShape, RECIP_ROOT_EIGHT_FX, NUM_SHB_SUBFR / 2 ); - IF( EQ_16(st_fx->rf_frame_type,RF_NELP)) + IF( EQ_16( st_fx->rf_frame_type, RF_NELP ) ) { /* Frame gain */ - st_fx->rf_indx_tbeGainFr = s_and(st_fx->rf_indx_tbeGainFr, 0xF); /* only four LSBs are valid */ + st_fx->rf_indx_tbeGainFr = s_and( st_fx->rf_indx_tbeGainFr, 0xF ); /* only four LSBs are valid */ Copy32( SHBCB_FrameGain16_fx + st_fx->rf_indx_tbeGainFr, &GainFrame, 1 ); - IF( EQ_16(st_fx->core,ACELP_CORE)&&EQ_16(st_fx->last_core,ACELP_CORE) - && !st_fx->prev_use_partial_copy && EQ_16(st_fx->prev_coder_type,UNVOICED) - && NE_32(GainFrame, hBWE_TD->GainFrame_prevfrm_fx) && EQ_16(st_fx->last_extl, WB_TBE) ) + IF( EQ_16( st_fx->core, ACELP_CORE ) && EQ_16( st_fx->last_core, ACELP_CORE ) && !st_fx->prev_use_partial_copy && EQ_16( st_fx->prev_coder_type, UNVOICED ) && NE_32( GainFrame, hBWE_TD->GainFrame_prevfrm_fx ) && EQ_16( st_fx->last_extl, WB_TBE ) ) { /*GainFrame = 0.2f*GainFrame + 0.8f*st_fx->GainFrame_prevfrm_fx;*/ - GainFrame = L_add(Mult_32_16(hBWE_TD->GainFrame_prevfrm_fx, 26214), Mult_32_16(GainFrame, 6553)); + GainFrame = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 26214 ), Mult_32_16( GainFrame, 6553 ) ); } } ELSE @@ -1270,45 +1263,48 @@ void wb_tbe_dec_fx( temp = 0; move16(); /* Frame gain */ - SWITCH (st_fx->rf_indx_tbeGainFr) + SWITCH( st_fx->rf_indx_tbeGainFr ) { - case 0: - GainFrame = 131072; /* 0.5f in Q18 */ - IF(LE_32(hBWE_TD->GainFrame_prevfrm_fx, 327680l/*1.25 Q18*/)) temp = 26214/*0.8 Q15*/; - move16(); - BREAK; - case 1: - GainFrame = 524288; /* 2.0f in Q18 */ - IF(GT_32(hBWE_TD->GainFrame_prevfrm_fx, 327680l/*1.25 Q18*/)&&LE_32(hBWE_TD->GainFrame_prevfrm_fx,786432l/*3 Q18*/)) temp = 26214/*0.8 Q15*/; - move16(); - test(); - BREAK; - case 2: - GainFrame = 1048576;/* 4.0f in Q18 */ - IF(GT_32(hBWE_TD->GainFrame_prevfrm_fx, 786432l/*3 Q18*/)&&LE_32(hBWE_TD->GainFrame_prevfrm_fx,1572864l/*6 Q18*/)) temp = 26214/*0.8 Q15*/; - move16(); - test(); - BREAK; - case 3: - GainFrame = 2097152;/* 8.0f in Q18 */ - IF(GT_32(hBWE_TD->GainFrame_prevfrm_fx, 1572864l/*6 Q18*/)&&LE_32(hBWE_TD->GainFrame_prevfrm_fx,4194304l/*16 Q18*/)) temp = 26214/*0.8 Q15*/; - move16(); - test(); - BREAK; - default: - fprintf(stderr, "RF SWB-TBE gain bits not supported."); + case 0: + GainFrame = 131072; /* 0.5f in Q18 */ + IF( LE_32( hBWE_TD->GainFrame_prevfrm_fx, 327680l /*1.25 Q18*/ ) ) + temp = 26214 /*0.8 Q15*/; + move16(); + BREAK; + case 1: + GainFrame = 524288; /* 2.0f in Q18 */ + IF( GT_32( hBWE_TD->GainFrame_prevfrm_fx, 327680l /*1.25 Q18*/ ) && LE_32( hBWE_TD->GainFrame_prevfrm_fx, 786432l /*3 Q18*/ ) ) + temp = 26214 /*0.8 Q15*/; + move16(); + test(); + BREAK; + case 2: + GainFrame = 1048576; /* 4.0f in Q18 */ + IF( GT_32( hBWE_TD->GainFrame_prevfrm_fx, 786432l /*3 Q18*/ ) && LE_32( hBWE_TD->GainFrame_prevfrm_fx, 1572864l /*6 Q18*/ ) ) + temp = 26214 /*0.8 Q15*/; + move16(); + test(); + BREAK; + case 3: + GainFrame = 2097152; /* 8.0f in Q18 */ + IF( GT_32( hBWE_TD->GainFrame_prevfrm_fx, 1572864l /*6 Q18*/ ) && LE_32( hBWE_TD->GainFrame_prevfrm_fx, 4194304l /*16 Q18*/ ) ) + temp = 26214 /*0.8 Q15*/; + move16(); + test(); + BREAK; + default: + fprintf( stderr, "RF SWB-TBE gain bits not supported." ); } - IF(EQ_16(st_fx->last_extl, WB_TBE)) + IF( EQ_16( st_fx->last_extl, WB_TBE ) ) { - GainFrame = L_add(Mult_32_16(hBWE_TD->GainFrame_prevfrm_fx, temp), Mult_32_16(GainFrame, sub(32767,temp))); + GainFrame = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, temp ), Mult_32_16( GainFrame, sub( 32767, temp ) ) ); } - IF(EQ_16(st_fx->core,ACELP_CORE)&&EQ_16(st_fx->last_core,ACELP_CORE)) + IF( EQ_16( st_fx->core, ACELP_CORE ) && EQ_16( st_fx->last_core, ACELP_CORE ) ) { - IF(!st_fx->prev_use_partial_copy && EQ_16(st_fx->last_coder_type, VOICED)&&EQ_16(st_fx->rf_frame_type,RF_GENPRED) - && LT_16(st_fx->prev_tilt_code_dec_fx,1497) && GT_16(st_fx->prev_tilt_code_dec_fx,200) ) + IF( !st_fx->prev_use_partial_copy && EQ_16( st_fx->last_coder_type, VOICED ) && EQ_16( st_fx->rf_frame_type, RF_GENPRED ) && LT_16( st_fx->prev_tilt_code_dec_fx, 1497 ) && GT_16( st_fx->prev_tilt_code_dec_fx, 200 ) ) { - GainFrame = Mult_32_16(GainFrame,9830); + GainFrame = Mult_32_16( GainFrame, 9830 ); } } } @@ -1321,22 +1317,22 @@ void wb_tbe_dec_fx( } ELSE { - IF( EQ_32( st_fx->extl_brate, WB_TBE_0k35)) + IF( EQ_32( st_fx->extl_brate, WB_TBE_0k35 ) ) { - Copy(hBWE_TD->lsp_prevfrm_fx, lsf_wb, LPC_SHB_ORDER_LBR_WB ); + Copy( hBWE_TD->lsp_prevfrm_fx, lsf_wb, LPC_SHB_ORDER_LBR_WB ); } ELSE { - Copy(hBWE_TD->lsp_prevfrm_fx, lsf_wb, LPC_SHB_ORDER_WB ); + Copy( hBWE_TD->lsp_prevfrm_fx, lsf_wb, LPC_SHB_ORDER_WB ); } set16_fx( GainShape, RECIP_ROOT_EIGHT_FX, NUM_SHB_SUBFR / 2 ); - hBWE_TD->GainAttn_fx = mult_r(hBWE_TD->GainAttn_fx, 27853 ); + hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 27853 ); move16(); - IF(EQ_16(st_fx->codec_mode, MODE1)) + IF( EQ_16( st_fx->codec_mode, MODE1 ) ) { - GainFrame = Mult_32_16(hBWE_TD->GainFrame_prevfrm_fx, hBWE_TD->GainAttn_fx ); /*Q18*/ + GainFrame = Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, hBWE_TD->GainAttn_fx ); /*Q18*/ } ELSE { @@ -1385,33 +1381,35 @@ void wb_tbe_dec_fx( { FOR( i = 1; i < NB_SUBFR; i++ ) { - vf_modified[i] = add( mult_r( 26214, voice_factors[i] ), mult_r( 6554, voice_factors[i - 1] ) ); /* Q15 */ move16(); + vf_modified[i] = add( mult_r( 26214, voice_factors[i] ), mult_r( 6554, voice_factors[i - 1] ) ); /* Q15 */ + move16(); } IF( st_fx->L_frame != L_FRAME ) { - vf_modified[4] = add( mult_r( 26214, voice_factors[4] ), mult_r( 6554, voice_factors[3] ) ); /* Q15 */ move16(); + vf_modified[4] = add( mult_r( 26214, voice_factors[4] ), mult_r( 6554, voice_factors[3] ) ); /* Q15 */ + move16(); } } /* From low band excitation, generate highband excitation */ Lmax = 0; - FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) + FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) { Lmax = L_max( Lmax, L_abs( bwe_exc_extended[cnt] ) ); } - Q_bwe_exc = ( Lmax == 0 )?31:norm_l( Lmax ); + Q_bwe_exc = ( Lmax == 0 ) ? 31 : norm_l( Lmax ); Q_bwe_exc = sub( Q_bwe_exc, 1 ); Q_bwe_exc = add( Q_bwe_exc, add( Q_exc, Q_exc ) ); find_max_mem_wb( st_fx, &n_mem ); - if( sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ) > n_mem ) + if ( sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ) > n_mem ) { Q_bwe_exc = add( st_fx->prev_Q_bwe_exc, n_mem ); } test(); - if( uv_flag && GT_16( Q_bwe_exc, 20 )) + if ( uv_flag && GT_16( Q_bwe_exc, 20 ) ) { Q_bwe_exc = 20; move16(); /* restrict this to 21 due to the Q factor requireemnt of the random number generator (keep 1 bit headroom) */ @@ -1429,7 +1427,7 @@ void wb_tbe_dec_fx( rescale_genWB_mem( st_fx, sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ) ); - Copy(hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); + Copy( hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); sc = sub( Q_bwe_exc, add( Q_exc, Q_exc ) ); FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) { @@ -1441,30 +1439,26 @@ void wb_tbe_dec_fx( } Copy( bwe_exc_extended_16 + L_FRAME32k, hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET ); - Copy(hBWE_TD->state_syn_shbexc_fx, shaped_wb_excitation, L_SHB_LAHEAD / 4 ); + Copy( hBWE_TD->state_syn_shbexc_fx, shaped_wb_excitation, L_SHB_LAHEAD / 4 ); Q_bwe_exc_ext = sub( Q_bwe_exc, 16 ); GenShapedWBExcitation_fx( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, hBWE_TD->mem_csfilt_fx, - hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, - hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, hBWE_TD->state_lpc_syn_fx, coder_type, - bwe_exc_extended_16, Q_bwe_exc_ext, hBWE_TD->bwe_seed, vf_modified, uv_flag - , st_fx->igf - ); + hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, + hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, hBWE_TD->state_lpc_syn_fx, coder_type, + bwe_exc_extended_16, Q_bwe_exc_ext, hBWE_TD->bwe_seed, vf_modified, uv_flag, st_fx->igf ); curr_pow = 0; FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) { #ifdef BASOP_NOGLOB - curr_pow = L_mac0_sat( curr_pow, shaped_wb_excitation[i + L_SHB_LAHEAD / 4], shaped_wb_excitation[i + - L_SHB_LAHEAD / 4] ); /* Q(2*Q_bwe_exc_ext) */ + curr_pow = L_mac0_sat( curr_pow, shaped_wb_excitation[i + L_SHB_LAHEAD / 4], shaped_wb_excitation[i + L_SHB_LAHEAD / 4] ); /* Q(2*Q_bwe_exc_ext) */ #else - curr_pow = L_mac0( curr_pow, shaped_wb_excitation[i + L_SHB_LAHEAD / 4], shaped_wb_excitation[i + - L_SHB_LAHEAD / 4] ); /* Q(2*Q_bwe_exc_ext) */ + curr_pow = L_mac0( curr_pow, shaped_wb_excitation[i + L_SHB_LAHEAD / 4], shaped_wb_excitation[i + L_SHB_LAHEAD / 4] ); /* Q(2*Q_bwe_exc_ext) */ #endif } - if( GT_16( voice_factors[0], 24576 )) + if ( GT_16( voice_factors[0], 24576 ) ) { curr_pow = L_shr( curr_pow, 2 ); /* Q(2*Q_bwe_exc_ext) */ } @@ -1478,11 +1472,11 @@ void wb_tbe_dec_fx( #ifdef BASOP_NOGLOB shaped_wb_excitation[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc_ext */ #else - shaped_wb_excitation[i] = round_fx( L_shl( L_tmp, exp ) ); /* Q_bwe_exc_ext */ + shaped_wb_excitation[i] = round_fx( L_shl( L_tmp, exp ) ); /* Q_bwe_exc_ext */ #endif } Lscale = root_a_fx( Lscale, 31 - exp, &exp ); - L_tmp = Mult_32_16( Lscale, shaped_wb_excitation[L_SHB_LAHEAD / 4 - 1] ); /* Q(16-exp+Q_bwe_exc_ext) */ + L_tmp = Mult_32_16( Lscale, shaped_wb_excitation[L_SHB_LAHEAD / 4 - 1] ); /* Q(16-exp+Q_bwe_exc_ext) */ shaped_wb_excitation[L_SHB_LAHEAD / 4 - 1] = round_fx( L_shl( L_tmp, exp ) ); /* Q_bwe_exc_ext */ /* Update SHB excitation */ @@ -1493,13 +1487,7 @@ void wb_tbe_dec_fx( /* Scale the shaped excitation */ ScaleShapedWB_fx( SHB_OVERLAP_LEN / 2, shaped_wb_excitation, hBWE_TD->syn_overlap_fx, GainShape, GainFrame, window_wb_fx, subwin_wb_fx, - Q_bwe_exc_ext - , st_fx->L_frame - , 0 - , &dummy - , dummy - , dummy2 - ); + Q_bwe_exc_ext, st_fx->L_frame, 0, &dummy, dummy, dummy2 ); max = 0; FOR( i = 0; i < L_FRAME16k / 4; i++ ) @@ -1520,42 +1508,44 @@ void wb_tbe_dec_fx( FOR( i = 0; i < L_FRAME16k / 4; i++ ) { #ifdef BASOP_NOGLOB - shaped_wb_excitation_frac[i] = shl_o( shaped_wb_excitation[i], n , &Overflow); /*Q14*/ move16(); + shaped_wb_excitation_frac[i] = shl_o( shaped_wb_excitation[i], n, &Overflow ); /*Q14*/ + move16(); #else - shaped_wb_excitation_frac[i] = shl( shaped_wb_excitation[i], n ); /*Q14*/ move16(); + shaped_wb_excitation_frac[i] = shl( shaped_wb_excitation[i], n ); /*Q14*/ + move16(); #endif } n = sub( 14, n ); curr_frame_pow = 1; - FOR( i = 0; i < L_FRAME16k / 4; i++ ) + FOR( i = 0; i < L_FRAME16k / 4; i++ ) { #ifdef BASOP_NOGLOB L_tmp = L_mult_o( shaped_wb_excitation_frac[i], shaped_wb_excitation_frac[i], &Overflow ); /*Q29*/ - curr_frame_pow = L_add_o( curr_frame_pow, L_shr( L_tmp, 7 ), &Overflow); /*Q22*/ + curr_frame_pow = L_add_o( curr_frame_pow, L_shr( L_tmp, 7 ), &Overflow ); /*Q22*/ #else L_tmp = L_mult( shaped_wb_excitation_frac[i], shaped_wb_excitation_frac[i] ); /*Q29*/ - curr_frame_pow = L_add( curr_frame_pow, L_shr( L_tmp, 7 ) ); /*Q22*/ + curr_frame_pow = L_add( curr_frame_pow, L_shr( L_tmp, 7 ) ); /*Q22*/ #endif } } curr_frame_pow_exp = add( n, n ); - IF ( GT_16(st_fx->prev_frame_pow_exp, curr_frame_pow_exp)) + IF( GT_16( st_fx->prev_frame_pow_exp, curr_frame_pow_exp ) ) { curr_frame_pow = L_shr( curr_frame_pow, sub( st_fx->prev_frame_pow_exp, curr_frame_pow_exp ) ); curr_frame_pow_exp = st_fx->prev_frame_pow_exp; } ELSE { - hBWE_TD->prev_wb_bwe_frame_pow_fx = L_shr(hBWE_TD->prev_wb_bwe_frame_pow_fx, sub( curr_frame_pow_exp, st_fx->prev_frame_pow_exp ) ); + hBWE_TD->prev_wb_bwe_frame_pow_fx = L_shr( hBWE_TD->prev_wb_bwe_frame_pow_fx, sub( curr_frame_pow_exp, st_fx->prev_frame_pow_exp ) ); } test(); IF( !st_fx->bfi && st_fx->prev_bfi ) { - IF( GT_32( L_shr( curr_frame_pow, 1 ), hBWE_TD->prev_wb_bwe_frame_pow_fx )) + IF( GT_32( L_shr( curr_frame_pow, 1 ), hBWE_TD->prev_wb_bwe_frame_pow_fx ) ) { - L_tmp = root_a_over_b_fx(hBWE_TD->prev_wb_bwe_frame_pow_fx, 22, curr_frame_pow, 22, &exp ); + L_tmp = root_a_over_b_fx( hBWE_TD->prev_wb_bwe_frame_pow_fx, 22, curr_frame_pow, 22, &exp ); scale = round_fx( L_shl( L_tmp, exp ) ); /*Q15*/ L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); @@ -1566,7 +1556,7 @@ void wb_tbe_dec_fx( ELSE { scale = temp = 32767; - move16();/* Q15 */ + move16(); /* Q15 */ } FOR( j = 0; j < 8; j++ ) @@ -1579,7 +1569,7 @@ void wb_tbe_dec_fx( } IF( temp > 0 ) { - IF( LT_16( scale, temp )) + IF( LT_16( scale, temp ) ) { scale = div_s( scale, temp ); } @@ -1607,7 +1597,7 @@ void wb_tbe_dec_fx( move16(); FOR( cnt = 0; cnt < ( L_FRAME16k + L_SHB_LAHEAD ) / 4; cnt++ ) { - if( abs_s( shaped_wb_excitation[cnt] ) > max ) + if ( abs_s( shaped_wb_excitation[cnt] ) > max ) { max = abs_s( shaped_wb_excitation[cnt] ); } @@ -1623,40 +1613,40 @@ void wb_tbe_dec_fx( max = 0; move16(); - FOR( i = 0; i < 2*ALLPASSSECTIONS_STEEP; i++ ) + FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ ) { - if( abs_s(hBWE_TD->state_lsyn_filt_shb_fx[i] ) > max ) - max = abs_s(hBWE_TD->state_lsyn_filt_shb_fx[i] ); + if ( abs_s( hBWE_TD->state_lsyn_filt_shb_fx[i] ) > max ) + max = abs_s( hBWE_TD->state_lsyn_filt_shb_fx[i] ); } - FOR( i = 0; i < 2*ALLPASSSECTIONS_STEEP; i++ ) + FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ ) { - if( abs_s(hBWE_TD->state_lsyn_filt_dwn_shb_fx[i] ) > max ) - max = abs_s(hBWE_TD->state_lsyn_filt_dwn_shb_fx[i] ); + if ( abs_s( hBWE_TD->state_lsyn_filt_dwn_shb_fx[i] ) > max ) + max = abs_s( hBWE_TD->state_lsyn_filt_dwn_shb_fx[i] ); } - IF( EQ_32(st_fx->output_Fs, 32000)) + IF( EQ_32( st_fx->output_Fs, 32000 ) ) { - FOR ( i = 0; i < 2*ALLPASSSECTIONS_STEEP; i++ ) + FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ ) { - max = s_max(max, abs_s(hBWE_TD->state_32and48k_WB_upsample_fx[i] )); + max = s_max( max, abs_s( hBWE_TD->state_32and48k_WB_upsample_fx[i] ) ); } } - IF( EQ_32(st_fx->output_Fs, 48000)) + IF( EQ_32( st_fx->output_Fs, 48000 ) ) { - FOR ( i = 0; i < INTERP_3_1_MEM_LEN; i++ ) + FOR( i = 0; i < INTERP_3_1_MEM_LEN; i++ ) { - max = s_max(max, abs_s(hBWE_TD->mem_resamp_HB_fx[i] )); + max = s_max( max, abs_s( hBWE_TD->mem_resamp_HB_fx[i] ) ); } } n_mem = 15; - if( max != 0 ) + if ( max != 0 ) { n_mem = norm_s( max ); } n_mem = s_max( n_mem, 0 ); - if( sub( Qx, st_fx->prev_Qx ) > n_mem ) + if ( sub( Qx, st_fx->prev_Qx ) > n_mem ) Qx = add( st_fx->prev_Qx, n_mem ); FOR( i = 0; i < ( L_FRAME16k + L_SHB_LAHEAD ) / 4; i++ ) @@ -1665,15 +1655,15 @@ void wb_tbe_dec_fx( move16(); } - FOR( i = 0; i < 2*ALLPASSSECTIONS_STEEP; i++ ) + FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ ) { - hBWE_TD->state_lsyn_filt_shb_fx[i] = shl(hBWE_TD->state_lsyn_filt_shb_fx[i], sub( Qx, st_fx->prev_Qx ) ); + hBWE_TD->state_lsyn_filt_shb_fx[i] = shl( hBWE_TD->state_lsyn_filt_shb_fx[i], sub( Qx, st_fx->prev_Qx ) ); move16(); } - FOR( i = 0; i < 2*ALLPASSSECTIONS_STEEP; i++ ) + FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ ) { - hBWE_TD->state_lsyn_filt_dwn_shb_fx[i] = shl(hBWE_TD->state_lsyn_filt_dwn_shb_fx[i], sub( Qx, st_fx->prev_Qx ) ); + hBWE_TD->state_lsyn_filt_dwn_shb_fx[i] = shl( hBWE_TD->state_lsyn_filt_dwn_shb_fx[i], sub( Qx, st_fx->prev_Qx ) ); move16(); } @@ -1704,7 +1694,8 @@ void wb_tbe_dec_fx( n = norm_s( max ); FOR( cnt = 0; cnt < L_FRAME16k; cnt++ ) { - synth_frac[cnt] = shl( synth[cnt], n ); /*Q14*/ move16(); + synth_frac[cnt] = shl( synth[cnt], n ); /*Q14*/ + move16(); } n = sub( sub( 14, n ), Qx ); @@ -1712,13 +1703,13 @@ void wb_tbe_dec_fx( FOR( i = 0; i < L_FRAME16k; i++ ) { L_tmp = L_mult( synth_frac[i], synth_frac[i] ); /* Q29 */ - Lacc = L_add( Lacc, L_shr( L_tmp, 7 ) ); /* Q22 */ + Lacc = L_add( Lacc, L_shr( L_tmp, 7 ) ); /* Q22 */ } L_tmp = Mult_32_16( Lacc, 102 ); /* Q22 */ exp = norm_l( L_tmp ); #ifdef BASOP_NOGLOB - tmp = round_fx_o( L_shl_o( L_tmp, exp , &Overflow), &Overflow); + tmp = round_fx_o( L_shl_o( L_tmp, exp, &Overflow ), &Overflow ); #else tmp = round_fx( L_shl( L_tmp, exp ) ); #endif @@ -1733,29 +1724,29 @@ void wb_tbe_dec_fx( } - IF( EQ_32(st_fx->output_Fs, 32000)) /* 32kHz sampling rate, but only WB output - interpolate */ + IF( EQ_32( st_fx->output_Fs, 32000 ) ) /* 32kHz sampling rate, but only WB output - interpolate */ { - Scale_sig(hBWE_TD->state_32and48k_WB_upsample_fx, 2*ALLPASSSECTIONS_STEEP, sub( Qx, st_fx->prev_Qx )); + Scale_sig( hBWE_TD->state_32and48k_WB_upsample_fx, 2 * ALLPASSSECTIONS_STEEP, sub( Qx, st_fx->prev_Qx ) ); Interpolate_allpass_steep_fx( synth, hBWE_TD->state_32and48k_WB_upsample_fx, L_FRAME16k, upsampled_synth ); Copy( upsampled_synth, synth, L_FRAME32k ); } - ELSE IF( EQ_32(st_fx->output_Fs, 48000)) + ELSE IF( EQ_32( st_fx->output_Fs, 48000 ) ) { - Scale_sig(hBWE_TD->mem_resamp_HB_fx, INTERP_3_1_MEM_LEN, sub( Qx, st_fx->prev_Qx )); - interpolate_3_over_1_allpass_fx( synth, L_FRAME16k, upsampled_synth, hBWE_TD->mem_resamp_HB_fx); + Scale_sig( hBWE_TD->mem_resamp_HB_fx, INTERP_3_1_MEM_LEN, sub( Qx, st_fx->prev_Qx ) ); + interpolate_3_over_1_allpass_fx( synth, L_FRAME16k, upsampled_synth, hBWE_TD->mem_resamp_HB_fx ); Copy( upsampled_synth, synth, L_FRAME48k ); } } ELSE { f = 5461; - move16();/* Q15 */ + move16(); /* Q15 */ inc = 5461; - move16();/* Q15 */ + move16(); /* Q15 */ FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) { lsf_wb[i] = f; - move16();/*Q15*/ + move16(); /*Q15*/ #ifdef BASOP_NOGLOB f = add_sat( f, inc ); #else @@ -1766,7 +1757,7 @@ void wb_tbe_dec_fx( GainFrame = 0; /* Q18 */ Qx = 0; Q_bwe_exc = 31; - hBWE_TD->prev_wb_bwe_frame_pow_fx = 4194l/*0.001f Q22*/; /* Q22 */ + hBWE_TD->prev_wb_bwe_frame_pow_fx = 4194l /*0.001f Q22*/; /* Q22 */ st_fx->prev_frame_pow_exp = 0; move16(); } @@ -1782,7 +1773,7 @@ void wb_tbe_dec_fx( } hBWE_TD->GainFrame_prevfrm_fx = GainFrame; /* Q18 */ - if( !st_fx->bfi ) + if ( !st_fx->bfi ) { hBWE_TD->GainAttn_fx = 32767; move16(); @@ -1800,7 +1791,6 @@ void wb_tbe_dec_fx( } - /*======================================================================================*/ /* FUNCTION : void swb_tbe_dec_fx () */ /*--------------------------------------------------------------------------------------*/ @@ -1826,22 +1816,22 @@ void wb_tbe_dec_fx( /* CALLED FROM : RX */ /*======================================================================================*/ void swb_tbe_dec_fx( - Decoder_State* st_fx, /* i/o: decoder state structure */ - const Word16 coder_type, /* i : coding type */ - Word32* bwe_exc_extended, /* i : bandwidth extended excitation 2*Q_exc */ - Word16 Q_exc, - const Word16 voice_factors[], /* i : voicing factors */ - const Word16 old_syn_12k8_16k[], /* i : low band synthesis */ - Word16* White_exc16k, /* o : shaped white excitation for the FB TBE */ - Word16* Q_white_exc, - Word16* synth, /* o : SHB synthesis/final synthesis */ - Word16* Q_synth, - Word16* pitch_buf /* i : pitch buffer Q6 */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 coder_type, /* i : coding type */ + Word32 *bwe_exc_extended, /* i : bandwidth extended excitation 2*Q_exc */ + Word16 Q_exc, + const Word16 voice_factors[], /* i : voicing factors */ + const Word16 old_syn_12k8_16k[], /* i : low band synthesis */ + Word16 *White_exc16k, /* o : shaped white excitation for the FB TBE */ + Word16 *Q_white_exc, + Word16 *synth, /* o : SHB synthesis/final synthesis */ + Word16 *Q_synth, + Word16 *pitch_buf /* i : pitch buffer Q6 */ ) { Word16 i; - Word16 shaped_shb_excitation [ L_FRAME16k + L_SHB_LAHEAD ]; - Word16 bwe_exc_extended_16[L_FRAME32k+NL_BUFF_OFFSET]; + Word16 shaped_shb_excitation[L_FRAME16k + L_SHB_LAHEAD]; + Word16 bwe_exc_extended_16[L_FRAME32k + NL_BUFF_OFFSET]; Word16 lsf_shb[LPC_SHB_ORDER], lpc_shb[LPC_SHB_ORDER + 1], GainShape[NUM_SHB_SUBFR]; Word32 GainFrame; Word16 error[L_FRAME32k]; @@ -1851,7 +1841,7 @@ void swb_tbe_dec_fx( Word32 prev_pow, curr_pow, Lscale; Word16 scale; Word16 exp, tmp; - Word16 j, cnt ; + Word16 j, cnt; Word16 n_mem, n_mem2, Qx, sc; Word16 n_mem3; Word32 Lmax, L_tmp; @@ -1870,7 +1860,7 @@ void swb_tbe_dec_fx( Word16 Q_bwe_exc_fb; Word16 lsp_shb_1[LPC_SHB_ORDER], lsp_shb_2[LPC_SHB_ORDER], lsp_temp[LPC_SHB_ORDER]; - Word16 lpc_shb_sf[4*(LPC_SHB_ORDER+1)]; + Word16 lpc_shb_sf[4 * ( LPC_SHB_ORDER + 1 )]; const Word16 *ptr_lsp_interp_coef; Word32 shb_ener_sf_32; Word16 shb_res_gshape[NB_SUBFR16k]; @@ -1885,15 +1875,15 @@ void swb_tbe_dec_fx( Word16 lsf_diff[LPC_SHB_ORDER], w[LPC_SHB_ORDER]; Word16 refl[M]; Word16 tilt_para; - Word16 tmp1,tmp2; + Word16 tmp1, tmp2; Word16 f_fx, inc_fx; Word32 GainFrame_prevfrm_fx; Word16 synth_scale_fx; Word16 mean_vf; Word16 exp_ener, inv_ener; - Word32 prev_ener_ratio_fx=0; /* initialize just to avoid compiler warning */ - Word16 max,n,temp,shaped_shb_excitation_frac [ L_FRAME16k + L_SHB_LAHEAD ]; + Word32 prev_ener_ratio_fx = 0; /* initialize just to avoid compiler warning */ + Word16 max, n, temp, shaped_shb_excitation_frac[L_FRAME16k + L_SHB_LAHEAD]; Word32 curr_frame_pow; Word16 curr_frame_pow_exp; Word32 L_prev_ener_shb; @@ -1901,28 +1891,28 @@ void swb_tbe_dec_fx( hBWE_TD = st_fx->hBWE_TD; /* initializations */ - GainFrame = L_deposit_l(0); - mixFactors = 0; + GainFrame = L_deposit_l( 0 ); + mixFactors = 0; move16(); - shb_ener_sf_32 = L_deposit_l(0); + shb_ener_sf_32 = L_deposit_l( 0 ); set16_fx( shaped_shb_excitationTemp, 0, L_FRAME16k ); st_fx->shb_dtx_count_fx = 0; move16(); is_fractive = 0; move16(); - set16_fx( shb_res_gshape, 1638/*0.1f Q14*/, NB_SUBFR16k ); /* Q14 */ - Q_shb = 0; /* high band target Q factor set to zero */ + set16_fx( shb_res_gshape, 1638 /*0.1f Q14*/, NB_SUBFR16k ); /* Q14 */ + Q_shb = 0; /* high band target Q factor set to zero */ - L_tmp = calc_tilt_bwe_fx(old_syn_12k8_16k, st_fx->Q_syn2, st_fx->L_frame); + L_tmp = calc_tilt_bwe_fx( old_syn_12k8_16k, st_fx->Q_syn2, st_fx->L_frame ); #ifdef BASOP_NOGLOB - tilt_swb_fec = round_fx_sat(L_shl_sat(L_tmp, 3)); + tilt_swb_fec = round_fx_sat( L_shl_sat( L_tmp, 3 ) ); #else - tilt_swb_fec = round_fx(L_shl(L_tmp, 3)); + tilt_swb_fec = round_fx( L_shl( L_tmp, 3 ) ); #endif /* i: old_syn_12k8_16k in st_fx->Q_syn2 */ /* o: tilt_swb_fec in Q11 */ test(); - IF( st_fx->bfi && NE_16(st_fx->clas_dec,UNVOICED_CLAS)) + IF( st_fx->bfi && NE_16( st_fx->clas_dec, UNVOICED_CLAS ) ) { tilt_swb_fec = hBWE_TD->tilt_swb_fec_fx; move16(); @@ -1931,7 +1921,7 @@ void swb_tbe_dec_fx( /* WB/SWB bandwidth switching */ test(); test(); - IF( ( GT_16(st_fx->tilt_wb_fx, 10240)&&EQ_16(st_fx->clas_dec,UNVOICED_CLAS))||GT_16(st_fx->tilt_wb_fx,20480)) + IF( ( GT_16( st_fx->tilt_wb_fx, 10240 ) && EQ_16( st_fx->clas_dec, UNVOICED_CLAS ) ) || GT_16( st_fx->tilt_wb_fx, 20480 ) ) { test(); test(); @@ -1940,14 +1930,13 @@ void swb_tbe_dec_fx( test(); test(); test(); - IF( (st_fx->prev_fractive == 0 && - (LT_32( st_fx->prev_enerLH_fx, L_shl( st_fx->enerLH_fx, 1 ) ) && GT_32( st_fx->prev_enerLH_fx, L_shr( st_fx->enerLH_fx, 1 ) ) - && LT_32( st_fx->prev_enerLL_fx, L_shl( st_fx->enerLL_fx, 1 ) ) && GT_32( st_fx->prev_enerLL_fx, L_shr( st_fx->enerLL_fx, 1 ) ) )) - || (EQ_16(st_fx->prev_fractive,1) && - GT_32(L_shr(st_fx->prev_enerLH_fx,2), Mult_32_16(st_fx->enerLH_fx,24576)) ) /* 24576 in Q13*/ - || (GT_32(L_shr(st_fx->enerLL_fx,1), Mult_32_16(st_fx->enerLH_fx, 24576)) && /*24576 = 1.5 in Q14*/ - LT_16(st_fx->tilt_wb_fx, 20480) )/* 20480 = 10 in Q11*/ - ) + IF( ( st_fx->prev_fractive == 0 && + ( LT_32( st_fx->prev_enerLH_fx, L_shl( st_fx->enerLH_fx, 1 ) ) && GT_32( st_fx->prev_enerLH_fx, L_shr( st_fx->enerLH_fx, 1 ) ) && LT_32( st_fx->prev_enerLL_fx, L_shl( st_fx->enerLL_fx, 1 ) ) && GT_32( st_fx->prev_enerLL_fx, L_shr( st_fx->enerLL_fx, 1 ) ) ) ) || + ( EQ_16( st_fx->prev_fractive, 1 ) && + GT_32( L_shr( st_fx->prev_enerLH_fx, 2 ), Mult_32_16( st_fx->enerLH_fx, 24576 ) ) ) /* 24576 in Q13*/ + || ( GT_32( L_shr( st_fx->enerLL_fx, 1 ), Mult_32_16( st_fx->enerLH_fx, 24576 ) ) && /*24576 = 1.5 in Q14*/ + LT_16( st_fx->tilt_wb_fx, 20480 ) ) /* 20480 = 10 in Q11*/ + ) { is_fractive = 0; move16(); @@ -1962,19 +1951,19 @@ void swb_tbe_dec_fx( /* WB/SWB bandwidth switching */ IF( st_fx->bws_cnt > 0 ) { - f_fx = 1489; /*Q15*/ - inc_fx = 1489; /*Q15*/ - IF(EQ_16(is_fractive, 1)) + f_fx = 1489; /*Q15*/ + inc_fx = 1489; /*Q15*/ + IF( EQ_16( is_fractive, 1 ) ) { - Copy(lsf_tab_fx, hBWE_TD->lsp_prevfrm_fx, LPC_SHB_ORDER); + Copy( lsf_tab_fx, hBWE_TD->lsp_prevfrm_fx, LPC_SHB_ORDER ); } ELSE { - FOR (i=0; ilsp_prevfrm_fx[i] = f_fx; move16(); - f_fx = add(f_fx, inc_fx); + f_fx = add( f_fx, inc_fx ); } } test(); @@ -1984,17 +1973,15 @@ void swb_tbe_dec_fx( test(); test(); test(); - IF( (NE_16(st_fx->last_extl, SWB_TBE)&&NE_16(st_fx->last_extl,FB_TBE)&& - !(L_sub(L_shr(st_fx->prev_enerLH_fx, 1), st_fx->enerLH_fx) < 0 &&L_sub(st_fx->prev_enerLH_fx, L_shr(st_fx->enerLH_fx,1)>0))) - || sub(st_fx->last_core, ACELP_CORE) != 0 - || (sub(st_fx->last_core, ACELP_CORE) == 0 && L_sub(L_abs(L_sub(st_fx->last_core_brate, st_fx->core_brate)), 3600) > 0) - || sub((is_fractive ^ st_fx->prev_fractive), 1) == 0 ) + IF( ( NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) && + !( L_sub( L_shr( st_fx->prev_enerLH_fx, 1 ), st_fx->enerLH_fx ) < 0 && L_sub( st_fx->prev_enerLH_fx, L_shr( st_fx->enerLH_fx, 1 ) > 0 ) ) ) || + sub( st_fx->last_core, ACELP_CORE ) != 0 || ( sub( st_fx->last_core, ACELP_CORE ) == 0 && L_sub( L_abs( L_sub( st_fx->last_core_brate, st_fx->core_brate ) ), 3600 ) > 0 ) || sub( ( is_fractive ^ st_fx->prev_fractive ), 1 ) == 0 ) { set16_fx( GainShape, 11587, NUM_SHB_SUBFR ); } ELSE { - if(GT_16(hBWE_TD->prev_GainShape_fx, 11587)) + if ( GT_16( hBWE_TD->prev_GainShape_fx, 11587 ) ) { hBWE_TD->prev_GainShape_fx = 11587; move16(); @@ -2002,62 +1989,63 @@ void swb_tbe_dec_fx( set16_fx( GainShape, hBWE_TD->prev_GainShape_fx, NUM_SHB_SUBFR ); } - Copy(hBWE_TD->lsp_prevfrm_fx, lsf_shb, LPC_SHB_ORDER ); - set16_fx( shb_res_gshape, 3277/*0.2f Q14*/, NB_SUBFR16k ); /* Q14 */ + Copy( hBWE_TD->lsp_prevfrm_fx, lsf_shb, LPC_SHB_ORDER ); + set16_fx( shb_res_gshape, 3277 /*0.2f Q14*/, NB_SUBFR16k ); /* Q14 */ } ELSE /* No bandwidth switching */ { test(); - IF( NE_16(st_fx->last_extl, SWB_TBE)&&NE_16(st_fx->last_extl,FB_TBE)) + IF( NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) ) { - f_fx = 1489; /*Q15*/ move16(); - inc_fx = 1489; /*Q15*/ move16(); - FOR (i=0; ilsp_prevfrm_fx[i] = f_fx; move16(); - f_fx = add(f_fx, inc_fx); + f_fx = add( f_fx, inc_fx ); } } IF( !st_fx->bfi ) { - IF(st_fx->use_partial_copy) + IF( st_fx->use_partial_copy ) { - IF(NE_16(st_fx->last_extl, SWB_TBE)) + IF( NE_16( st_fx->last_extl, SWB_TBE ) ) { hBWE_TD->GainFrame_prevfrm_fx = 0; move16(); move16(); move16(); - f_fx = 1489/*0.045454f Q15*/; /*Q15*/ - inc_fx = 1489/*0.045454f Q15*/;; /*Q15*/ - FOR (i=0; ilsp_prevfrm_fx[i] = f_fx; move16(); - f_fx = add(f_fx, inc_fx); + f_fx = add( f_fx, inc_fx ); } } - Copy(hBWE_TD->lsp_prevfrm_fx, lsf_shb, LPC_SHB_ORDER ); + Copy( hBWE_TD->lsp_prevfrm_fx, lsf_shb, LPC_SHB_ORDER ); set16_fx( GainShape, RECIP_ROOT_EIGHT_FX, NUM_SHB_SUBFR ); - IF( EQ_16(st_fx->rf_frame_type,RF_NELP)) + IF( EQ_16( st_fx->rf_frame_type, RF_NELP ) ) { /* Frame gain */ GainFrame = L_mac( SHB_GAIN_QLOW_FX, st_fx->rf_indx_tbeGainFr, SHB_GAIN_QDELTA_FX ); - move32();/*Q18*/ - L_tmp = Mult_32_16( GainFrame, 27213 ); /*Q16*/ /* 3.321928 in Q13 */ + move32(); /*Q18*/ + L_tmp = Mult_32_16( GainFrame, 27213 ); /*Q16*/ /* 3.321928 in Q13 */ frac = L_Extract_lc( L_tmp, &exp ); L_tmp = Pow2( 30, frac ); GainFrame = L_shl( L_tmp, sub( exp, 12 ) ); /*Q18*/ - IF( EQ_16(st_fx->core,ACELP_CORE)&&EQ_16(st_fx->last_core,ACELP_CORE) - && !st_fx->prev_use_partial_copy && EQ_16(st_fx->prev_coder_type,UNVOICED) - && NE_32(GainFrame, hBWE_TD->GainFrame_prevfrm_fx) && NE_16(st_fx->next_coder_type,GENERIC) && EQ_16(st_fx->last_extl, SWB_TBE) ) + IF( EQ_16( st_fx->core, ACELP_CORE ) && EQ_16( st_fx->last_core, ACELP_CORE ) && !st_fx->prev_use_partial_copy && EQ_16( st_fx->prev_coder_type, UNVOICED ) && NE_32( GainFrame, hBWE_TD->GainFrame_prevfrm_fx ) && NE_16( st_fx->next_coder_type, GENERIC ) && EQ_16( st_fx->last_extl, SWB_TBE ) ) { /*GainFrame = 0.2f*GainFrame + 0.8f*st_fx->GainFrame_prevfrm_fx;*/ - GainFrame = L_add(Mult_32_16(hBWE_TD->GainFrame_prevfrm_fx, 26214), Mult_32_16(GainFrame, 6553)); + GainFrame = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 26214 ), Mult_32_16( GainFrame, 6553 ) ); } } ELSE @@ -2065,43 +2053,47 @@ void swb_tbe_dec_fx( temp = 0; move16(); /* Frame gain */ - SWITCH (st_fx->rf_indx_tbeGainFr) + SWITCH( st_fx->rf_indx_tbeGainFr ) { - case 0: - GainFrame = 131072; /* 0.5f in Q18 */ - IF(LE_32(hBWE_TD->GainFrame_prevfrm_fx, 327680l/*1.25 Q18*/)) temp = 26214/*0.8 Q15*/; - move16(); - BREAK; - case 1: - GainFrame = 524288; /* 2.0f in Q18 */ - IF(GT_32(hBWE_TD->GainFrame_prevfrm_fx, 327680l/*1.25 Q18*/)&&LE_32(hBWE_TD->GainFrame_prevfrm_fx,786432l/*3 Q18*/)) temp = 26214/*0.8 Q15*/; - move16(); - test(); - BREAK; - case 2: - GainFrame = 1048576;/* 4.0f in Q18 */ - IF(GT_32(hBWE_TD->GainFrame_prevfrm_fx, 786432l/*3 Q18*/)&&LE_32(hBWE_TD->GainFrame_prevfrm_fx,1572864l/*6 Q18*/)) temp = 26214/*0.8 Q15*/; - move16(); - test(); - BREAK; - case 3: - GainFrame = 2097152;/* 8.0f in Q18 */ - IF(GT_32(hBWE_TD->GainFrame_prevfrm_fx, 1572864l/*6 Q18*/)&&LE_32(hBWE_TD->GainFrame_prevfrm_fx,4194304l/*16Q18*/)) temp = 26214/*0.8 Q15*/; - move16(); - test(); - BREAK; - default: - fprintf(stderr, "RF SWB-TBE gain bits not supported."); + case 0: + GainFrame = 131072; /* 0.5f in Q18 */ + IF( LE_32( hBWE_TD->GainFrame_prevfrm_fx, 327680l /*1.25 Q18*/ ) ) + temp = 26214 /*0.8 Q15*/; + move16(); + BREAK; + case 1: + GainFrame = 524288; /* 2.0f in Q18 */ + IF( GT_32( hBWE_TD->GainFrame_prevfrm_fx, 327680l /*1.25 Q18*/ ) && LE_32( hBWE_TD->GainFrame_prevfrm_fx, 786432l /*3 Q18*/ ) ) + temp = 26214 /*0.8 Q15*/; + move16(); + test(); + BREAK; + case 2: + GainFrame = 1048576; /* 4.0f in Q18 */ + IF( GT_32( hBWE_TD->GainFrame_prevfrm_fx, 786432l /*3 Q18*/ ) && LE_32( hBWE_TD->GainFrame_prevfrm_fx, 1572864l /*6 Q18*/ ) ) + temp = 26214 /*0.8 Q15*/; + move16(); + test(); + BREAK; + case 3: + GainFrame = 2097152; /* 8.0f in Q18 */ + IF( GT_32( hBWE_TD->GainFrame_prevfrm_fx, 1572864l /*6 Q18*/ ) && LE_32( hBWE_TD->GainFrame_prevfrm_fx, 4194304l /*16Q18*/ ) ) + temp = 26214 /*0.8 Q15*/; + move16(); + test(); + BREAK; + default: + fprintf( stderr, "RF SWB-TBE gain bits not supported." ); } - IF(EQ_16(st_fx->last_extl, SWB_TBE)) + IF( EQ_16( st_fx->last_extl, SWB_TBE ) ) { - GainFrame = L_add(Mult_32_16(hBWE_TD->GainFrame_prevfrm_fx, temp), Mult_32_16(GainFrame, sub(32767,temp))); + GainFrame = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, temp ), Mult_32_16( GainFrame, sub( 32767, temp ) ) ); } - IF(EQ_16(st_fx->core,ACELP_CORE)&&EQ_16(st_fx->last_core,ACELP_CORE)) + IF( EQ_16( st_fx->core, ACELP_CORE ) && EQ_16( st_fx->last_core, ACELP_CORE ) ) { - IF(!st_fx->prev_use_partial_copy && EQ_16(st_fx->last_coder_type, VOICED)&&EQ_16(st_fx->rf_frame_type,RF_GENPRED)&>_32(GainFrame,2097152)&<_32(GainFrame,3059606)) + IF( !st_fx->prev_use_partial_copy && EQ_16( st_fx->last_coder_type, VOICED ) && EQ_16( st_fx->rf_frame_type, RF_GENPRED ) && GT_32( GainFrame, 2097152 ) && LT_32( GainFrame, 3059606 ) ) { - GainFrame = Mult_32_16(GainFrame,9830); + GainFrame = Mult_32_16( GainFrame, 9830 ); } } } @@ -2111,7 +2103,7 @@ void swb_tbe_dec_fx( /* de-quantization */ dequantizeSHBparams_fx_9_1( st_fx, st_fx->extl, st_fx->extl_brate, lsf_shb, GainShape, &GainFrame, &stemp, - &shb_ener_sf_32, shb_res_gshape, &mixFactors ); + &shb_ener_sf_32, shb_res_gshape, &mixFactors ); Q_shb = 0; move16(); /* o: shb_ener_sf_32 in (2*Q_shb) */ @@ -2122,13 +2114,13 @@ void swb_tbe_dec_fx( } ELSE /* FER concealment of TBE parameters */ { - Copy(hBWE_TD->lsp_prevfrm_fx, lsf_shb, LPC_SHB_ORDER ); + Copy( hBWE_TD->lsp_prevfrm_fx, lsf_shb, LPC_SHB_ORDER ); /* Gain shape concealment */ - IF( EQ_16(st_fx->codec_mode, MODE1)) + IF( EQ_16( st_fx->codec_mode, MODE1 ) ) { /* Gradient based GS estimation */ - gradientGainShape(st_fx, GainShape, &GainFrame); + gradientGainShape( st_fx, GainShape, &GainFrame ); /* o: GainShape[16] in Q15 */ /* o: GainFrame in Q18 */ } @@ -2138,25 +2130,25 @@ void swb_tbe_dec_fx( { FOR( j = 0; j < 4; j++ ) { - GainShape[i * 4 + j] = mult_r( st_fx->cummulative_damping, st_fx->GainShape_Delay[4+i]); + GainShape[i * 4 + j] = mult_r( st_fx->cummulative_damping, st_fx->GainShape_Delay[4 + i] ); move16(); } } - IF( GT_16( tilt_swb_fec, 8<<11 )) /* tilt_swb_fec in Q11 */ + IF( GT_16( tilt_swb_fec, 8 << 11 ) ) /* tilt_swb_fec in Q11 */ { - IF ( EQ_16(st_fx->nbLostCmpt, 1)) + IF( EQ_16( st_fx->nbLostCmpt, 1 ) ) { - GainFrame = Mult_32_16(hBWE_TD->GainFrame_prevfrm_fx, 19661/*0.6f Q15*/); + GainFrame = Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 19661 /*0.6f Q15*/ ); } - ELSE IF( EQ_16(st_fx->nbLostCmpt, 2)) + ELSE IF( EQ_16( st_fx->nbLostCmpt, 2 ) ) { - GainFrame = Mult_32_16(hBWE_TD->GainFrame_prevfrm_fx, 11469/*0.35f Q15*/); + GainFrame = Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 11469 /*0.35f Q15*/ ); } ELSE { - GainFrame = Mult_32_16(hBWE_TD->GainFrame_prevfrm_fx, 6554/*0.2f Q15*/); + GainFrame = Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 6554 /*0.2f Q15*/ ); } - GainFrame = Mult_32_16( GainFrame, st_fx->cummulative_damping); + GainFrame = Mult_32_16( GainFrame, st_fx->cummulative_damping ); } ELSE { @@ -2167,91 +2159,91 @@ void swb_tbe_dec_fx( /* FER concealment for 24.4kbps and 32kbps */ test(); - IF(EQ_32(st_fx->total_brate,ACELP_24k40)||EQ_32(st_fx->total_brate,ACELP_32k)) + IF( EQ_32( st_fx->total_brate, ACELP_24k40 ) || EQ_32( st_fx->total_brate, ACELP_32k ) ) { - IF(EQ_16(st_fx->codec_mode, MODE1)) + IF( EQ_16( st_fx->codec_mode, MODE1 ) ) { /*scale = st->prev1_shb_ener_sf/root_a(st->prev2_shb_ener_sf * st->prev3_shb_ener_sf); */ - L_tmp = L_mult(extract_l(hBWE_TD->prev2_shb_ener_sf_fx), extract_l(hBWE_TD->prev3_shb_ener_sf_fx)); /*Q1*/ - tmp = round_fx(root_a_fx(L_tmp, 1, &exp)); /* Q = 15-exp */ - tmp1 = extract_l(hBWE_TD->prev1_shb_ener_sf_fx); /*Q0*/ - i = sub(norm_s(tmp1), 1); - tmp1 = shl(tmp1, i); /* Qi */ - if(tmp == 0) + L_tmp = L_mult( extract_l( hBWE_TD->prev2_shb_ener_sf_fx ), extract_l( hBWE_TD->prev3_shb_ener_sf_fx ) ); /*Q1*/ + tmp = round_fx( root_a_fx( L_tmp, 1, &exp ) ); /* Q = 15-exp */ + tmp1 = extract_l( hBWE_TD->prev1_shb_ener_sf_fx ); /*Q0*/ + i = sub( norm_s( tmp1 ), 1 ); + tmp1 = shl( tmp1, i ); /* Qi */ + if ( tmp == 0 ) { - tmp = 32767/*1.0f Q15*/; + tmp = 32767 /*1.0f Q15*/; move16(); /*Q15*/ } ELSE { - scale = div_s(tmp1, tmp); /* Q15 - Q(15-exp) + Qi = Qexp+i */ - scale = s_max(scale, 0); + scale = div_s( tmp1, tmp ); /* Q15 - Q(15-exp) + Qi = Qexp+i */ + scale = s_max( scale, 0 ); /*scale = st->prev_res_shb_gshape * min(scale, 1.0f); */ #ifdef BASOP_NOGLOB - tmp = shl_sat(scale, 15 - exp - i); /*Q15*/ + tmp = shl_sat( scale, 15 - exp - i ); /*Q15*/ #else - tmp = shl(scale, 15 - exp - i); /*Q15*/ + tmp = shl( scale, 15 - exp - i ); /*Q15*/ #endif } - scale = mult_r(hBWE_TD->prev_res_shb_gshape_fx, tmp); /* Q14 */ + scale = mult_r( hBWE_TD->prev_res_shb_gshape_fx, tmp ); /* Q14 */ test(); - IF( GT_32( L_shr(hBWE_TD->prev2_shb_ener_sf_fx, 1), hBWE_TD->prev1_shb_ener_sf_fx )|| - GT_32( L_shr(hBWE_TD->prev3_shb_ener_sf_fx, 1), hBWE_TD->prev2_shb_ener_sf_fx ) ) + IF( GT_32( L_shr( hBWE_TD->prev2_shb_ener_sf_fx, 1 ), hBWE_TD->prev1_shb_ener_sf_fx ) || + GT_32( L_shr( hBWE_TD->prev3_shb_ener_sf_fx, 1 ), hBWE_TD->prev2_shb_ener_sf_fx ) ) { /* shb_ener_sf_32 = 0.5f * scale * st_fx->prev1_shb_ener_sf_fx; */ - shb_ener_sf_32 = Mult_32_16(hBWE_TD->prev1_shb_ener_sf_fx, scale ); + shb_ener_sf_32 = Mult_32_16( hBWE_TD->prev1_shb_ener_sf_fx, scale ); - if( GT_16(st_fx->nbLostCmpt, 1)) + if ( GT_16( st_fx->nbLostCmpt, 1 ) ) { /* shb_ener_sf_32 *= 0.5f; */ - shb_ener_sf_32 = L_shr(shb_ener_sf_32, 1); + shb_ener_sf_32 = L_shr( shb_ener_sf_32, 1 ); } } ELSE { /* shb_ener_sf = scale * scale * st_fx->prev1_shb_ener_sf_fx; */ - L_tmp = L_mult(scale, scale); /* Q29 */ - shb_ener_sf_32 = L_shl(Mult_32_16(hBWE_TD->prev1_shb_ener_sf_fx, round_fx(L_tmp)), 2); + L_tmp = L_mult( scale, scale ); /* Q29 */ + shb_ener_sf_32 = L_shl( Mult_32_16( hBWE_TD->prev1_shb_ener_sf_fx, round_fx( L_tmp ) ), 2 ); } } ELSE { test(); - IF( GT_32( L_shr(hBWE_TD->prev2_shb_ener_sf_fx, 1), hBWE_TD->prev1_shb_ener_sf_fx )|| - GT_32( L_shr(hBWE_TD->prev3_shb_ener_sf_fx, 1), hBWE_TD->prev2_shb_ener_sf_fx ) ) + IF( GT_32( L_shr( hBWE_TD->prev2_shb_ener_sf_fx, 1 ), hBWE_TD->prev1_shb_ener_sf_fx ) || + GT_32( L_shr( hBWE_TD->prev3_shb_ener_sf_fx, 1 ), hBWE_TD->prev2_shb_ener_sf_fx ) ) { /* shb_ener_sf_32 = 0.5f * st->cummulative_damping * st_fx->prev1_shb_ener_sf_fx; */ - shb_ener_sf_32 = L_shr( Mult_32_16(hBWE_TD->prev1_shb_ener_sf_fx, st_fx->cummulative_damping ), 1 ); + shb_ener_sf_32 = L_shr( Mult_32_16( hBWE_TD->prev1_shb_ener_sf_fx, st_fx->cummulative_damping ), 1 ); } ELSE { - shb_ener_sf_32 = Mult_32_16(hBWE_TD->prev1_shb_ener_sf_fx, st_fx->cummulative_damping ); + shb_ener_sf_32 = Mult_32_16( hBWE_TD->prev1_shb_ener_sf_fx, st_fx->cummulative_damping ); } } } - shb_ener_sf_32 = L_max( shb_ener_sf_32, 1l/*1.0f Q0*/ ); + shb_ener_sf_32 = L_max( shb_ener_sf_32, 1l /*1.0f Q0*/ ); mixFactors = hBWE_TD->prev_mixFactors_fx; - IF(EQ_16(st_fx->codec_mode, MODE1)) + IF( EQ_16( st_fx->codec_mode, MODE1 ) ) { - set16_fx( shb_res_gshape, 3277/*0.2f Q14*/, 5 ); /* Q14 */ + set16_fx( shb_res_gshape, 3277 /*0.2f Q14*/, 5 ); /* Q14 */ } ELSE { - set16_fx( shb_res_gshape, 16384/*1.0f Q14*/, 5 ); /* Q14 */ + set16_fx( shb_res_gshape, 16384 /*1.0f Q14*/, 5 ); /* Q14 */ } } } /* get the gainshape delay */ Copy( &st_fx->GainShape_Delay[4], &st_fx->GainShape_Delay[0], NUM_SHB_SUBFR / 4 ); - IF ( (st_fx->rf_flag != 0) || EQ_32(st_fx->total_brate, ACELP_9k60)) + IF( ( st_fx->rf_flag != 0 ) || EQ_32( st_fx->total_brate, ACELP_9k60 ) ) { FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) { - st_fx->GainShape_Delay[i + 4] = s_min( s_max( GainShape[i * 4], 3277/*0.1f Q15*/ ), 16384/*0.5f Q15*/ ); + st_fx->GainShape_Delay[i + 4] = s_min( s_max( GainShape[i * 4], 3277 /*0.1f Q15*/ ), 16384 /*0.5f Q15*/ ); move16(); } } @@ -2266,43 +2258,43 @@ void swb_tbe_dec_fx( /* voice factor modification to limit any spurious jumps in the middle of voiced subframes*/ /* mean(voice_factors[i], 4); */ - L_tmp = L_mult(voice_factors[0], 8192); - L_tmp = L_mac(L_tmp, voice_factors[1], 8192); - L_tmp = L_mac(L_tmp, voice_factors[2], 8192); - mean_vf = mac_r(L_tmp, voice_factors[3], 8192); + L_tmp = L_mult( voice_factors[0], 8192 ); + L_tmp = L_mac( L_tmp, voice_factors[1], 8192 ); + L_tmp = L_mac( L_tmp, voice_factors[2], 8192 ); + mean_vf = mac_r( L_tmp, voice_factors[3], 8192 ); Copy( voice_factors, vf_modified, NB_SUBFR16k ); test(); - IF( EQ_16(coder_type, VOICED)||GT_16(mean_vf,13107/*0.4f Q15*/ )) + IF( EQ_16( coder_type, VOICED ) || GT_16( mean_vf, 13107 /*0.4f Q15*/ ) ) { FOR( i = 1; i < NB_SUBFR; i++ ) { - L_tmp = L_mult(voice_factors[i], 26214/*0.8f Q15*/); - vf_modified[i] = mac_r(L_tmp, voice_factors[i-1], 6554/*0.2f Q15*/); + L_tmp = L_mult( voice_factors[i], 26214 /*0.8f Q15*/ ); + vf_modified[i] = mac_r( L_tmp, voice_factors[i - 1], 6554 /*0.2f Q15*/ ); move16(); } - IF( NE_16(st_fx->L_frame, L_FRAME)) + IF( NE_16( st_fx->L_frame, L_FRAME ) ) { - L_tmp = L_mult(voice_factors[4], 26214/*0.8f Q15*/); - vf_modified[4] = mac_r(L_tmp, voice_factors[3], 6554/*0.2f Q15*/); + L_tmp = L_mult( voice_factors[4], 26214 /*0.8f Q15*/ ); + vf_modified[4] = mac_r( L_tmp, voice_factors[3], 6554 /*0.2f Q15*/ ); move16(); } } /* convert quantized LSFs to LSPs for interpolation */ - E_LPC_lsf_lsp_conversion(lsf_shb, lsp_shb_2, LPC_SHB_ORDER); + E_LPC_lsf_lsp_conversion( lsf_shb, lsp_shb_2, LPC_SHB_ORDER ); test(); - IF( EQ_16(st_fx->last_extl, SWB_TBE)||EQ_16(st_fx->last_extl,FB_TBE)) + IF( EQ_16( st_fx->last_extl, SWB_TBE ) || EQ_16( st_fx->last_extl, FB_TBE ) ) { /* SHB LSP values from prev. frame for interpolation */ - Copy(hBWE_TD->swb_lsp_prev_interp_fx, lsp_shb_1, LPC_SHB_ORDER); + Copy( hBWE_TD->swb_lsp_prev_interp_fx, lsp_shb_1, LPC_SHB_ORDER ); } ELSE { /* Use current frame's LSPs; in effect no interpolation */ - Copy(lsp_shb_2, lsp_shb_1, LPC_SHB_ORDER); + Copy( lsp_shb_2, lsp_shb_1, LPC_SHB_ORDER ); } test(); @@ -2311,50 +2303,50 @@ void swb_tbe_dec_fx( IF( st_fx->bws_cnt == 0 && st_fx->bws_cnt1 == 0 && st_fx->prev_use_partial_copy == 0 && st_fx->use_partial_copy == 0 ) { lsf_diff[0] = 16384; - move16(); /*Q15*/ - lsf_diff[sub(LPC_SHB_ORDER,1)] = 16384; - move16(); /*Q15*/ - FOR(i=1; i < LPC_SHB_ORDER-1; i++) + move16(); /*Q15*/ + lsf_diff[sub( LPC_SHB_ORDER, 1 )] = 16384; + move16(); /*Q15*/ + FOR( i = 1; i < LPC_SHB_ORDER - 1; i++ ) { - lsf_diff[i] = sub(lsf_shb[i],lsf_shb[sub(i,1)]); + lsf_diff[i] = sub( lsf_shb[i], lsf_shb[sub( i, 1 )] ); move16(); } - a2rc_fx (hBWE_TD->cur_sub_Aq_fx+1, refl, M); - tmp = add(16384, shr(refl[0],1)); /*Q14*/ - tmp1 = mult(27425,tmp); - tmp1 = mult(tmp1,tmp); /*Q10*/ - tmp2 = shr(mult(31715,tmp),2); /*Q10*/ - tilt_para = add(sub(tmp1,tmp2),1335); /*Q10*/ + a2rc_fx( hBWE_TD->cur_sub_Aq_fx + 1, refl, M ); + tmp = add( 16384, shr( refl[0], 1 ) ); /*Q14*/ + tmp1 = mult( 27425, tmp ); + tmp1 = mult( tmp1, tmp ); /*Q10*/ + tmp2 = shr( mult( 31715, tmp ), 2 ); /*Q10*/ + tilt_para = add( sub( tmp1, tmp2 ), 1335 ); /*Q10*/ test(); - IF(NE_16(st_fx->last_extl,SWB_TBE)&&NE_16(st_fx->last_extl,FB_TBE)) + IF( NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) ) { - FOR( i=1; iprev_lsf_diff_fx[i-1] = shr(lsf_diff[i], 1); + hBWE_TD->prev_lsf_diff_fx[i - 1] = shr( lsf_diff[i], 1 ); move16(); } } - IF( LE_32(st_fx->total_brate,ACELP_16k40)) + IF( LE_32( st_fx->total_brate, ACELP_16k40 ) ) { test(); test(); test(); test(); test(); - IF(!(GT_16(hBWE_TD->prev_tilt_para_fx,5120)&&(EQ_16(coder_type,TRANSITION)||LT_16(tilt_para,1024)))&& - !(((LT_16(hBWE_TD->prev_tilt_para_fx,3072) && GE_16(st_fx->prev_coder_type,VOICED))) && GT_16(tilt_para,5120) )) + IF( !( GT_16( hBWE_TD->prev_tilt_para_fx, 5120 ) && ( EQ_16( coder_type, TRANSITION ) || LT_16( tilt_para, 1024 ) ) ) && + !( ( ( LT_16( hBWE_TD->prev_tilt_para_fx, 3072 ) && GE_16( st_fx->prev_coder_type, VOICED ) ) ) && GT_16( tilt_para, 5120 ) ) ) { - FOR( i = 1; i < LPC_SHB_ORDER-1; i++ ) + FOR( i = 1; i < LPC_SHB_ORDER - 1; i++ ) { - IF(LT_16(lsf_diff[i], hBWE_TD->prev_lsf_diff_fx[i-1])) + IF( LT_16( lsf_diff[i], hBWE_TD->prev_lsf_diff_fx[i - 1] ) ) { - tmp = mult(26214,lsf_diff[i]); + tmp = mult( 26214, lsf_diff[i] ); test(); - IF(hBWE_TD->prev_lsf_diff_fx[i-1] <= 0 || tmp < 0 ) /* safety check in case of bit errors */ + IF( hBWE_TD->prev_lsf_diff_fx[i - 1] <= 0 || tmp < 0 ) /* safety check in case of bit errors */ { st_fx->BER_detect = 1; move16(); @@ -2362,19 +2354,19 @@ void swb_tbe_dec_fx( } ELSE { - tmp = div_s(tmp,hBWE_TD->prev_lsf_diff_fx[i-1]); + tmp = div_s( tmp, hBWE_TD->prev_lsf_diff_fx[i - 1] ); } - tmp = s_max(tmp,16384); - w[i] = s_min(tmp,32767); + tmp = s_max( tmp, 16384 ); + w[i] = s_min( tmp, 32767 ); move16(); } ELSE { - tmp = mult(26214,hBWE_TD->prev_lsf_diff_fx[i-1]); + tmp = mult( 26214, hBWE_TD->prev_lsf_diff_fx[i - 1] ); test(); - IF( lsf_diff[i] <= 0 || tmp < 0 ) /* safety check in case of bit errors */ + IF( lsf_diff[i] <= 0 || tmp < 0 ) /* safety check in case of bit errors */ { st_fx->BER_detect = 1; move16(); @@ -2382,41 +2374,41 @@ void swb_tbe_dec_fx( } ELSE { - tmp = div_s(tmp,lsf_diff[i]); + tmp = div_s( tmp, lsf_diff[i] ); } - tmp = s_max(tmp,16384); - w[i] = s_min(tmp,32767); + tmp = s_max( tmp, 16384 ); + w[i] = s_min( tmp, 32767 ); move16(); } } w[0] = w[1]; - w[sub(LPC_SHB_ORDER,1)] = w[sub(LPC_SHB_ORDER,2)]; + w[sub( LPC_SHB_ORDER, 1 )] = w[sub( LPC_SHB_ORDER, 2 )]; FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - tmp1 = mult(lsp_shb_1[i],sub(32767,w[i])); - tmp2 = mult(lsp_shb_2[i],w[i]); - lsp_temp[i] =add(tmp1,tmp2); + tmp1 = mult( lsp_shb_1[i], sub( 32767, w[i] ) ); + tmp2 = mult( lsp_shb_2[i], w[i] ); + lsp_temp[i] = add( tmp1, tmp2 ); move16(); } } ELSE { - Copy(lsp_shb_2, lsp_temp, LPC_SHB_ORDER); + Copy( lsp_shb_2, lsp_temp, LPC_SHB_ORDER ); } } - Copy( lsf_diff + 1, hBWE_TD->prev_lsf_diff_fx, LPC_SHB_ORDER-2 ); + Copy( lsf_diff + 1, hBWE_TD->prev_lsf_diff_fx, LPC_SHB_ORDER - 2 ); hBWE_TD->prev_tilt_para_fx = tilt_para; } ELSE { - Copy(lsp_shb_2, lsp_temp, LPC_SHB_ORDER); + Copy( lsp_shb_2, lsp_temp, LPC_SHB_ORDER ); } test(); - IF ( EQ_32(st_fx->total_brate, ACELP_24k40 )||EQ_32(st_fx->total_brate,ACELP_32k)) + IF( EQ_32( st_fx->total_brate, ACELP_24k40 ) || EQ_32( st_fx->total_brate, ACELP_32k ) ) { /* ---------- SHB LSP interpolation ---------- */ ptr_lsp_interp_coef = interpol_frac_shb; /*Q15*/ @@ -2426,8 +2418,8 @@ void swb_tbe_dec_fx( { /*lsp_temp_fx[i] = lsp_shb_1_fx[i]*(*ptr_lsp_interp_coef_fx) */ /* + lsp_shb_2_fx[i]*(*(ptr_lsp_interp_coef_fx+1));*/ - L_tmp = L_mult(lsp_shb_1[i], (*ptr_lsp_interp_coef)); - lsp_temp[i] = mac_r(L_tmp, lsp_shb_2[i], (*(ptr_lsp_interp_coef+1))); + L_tmp = L_mult( lsp_shb_1[i], ( *ptr_lsp_interp_coef ) ); + lsp_temp[i] = mac_r( L_tmp, lsp_shb_2[i], ( *( ptr_lsp_interp_coef + 1 ) ) ); move16(); } ptr_lsp_interp_coef += 2; @@ -2435,22 +2427,22 @@ void swb_tbe_dec_fx( /* convert from lsp to lsf */ /*old code: lsp2lsf_fx(lsp_temp, lsp_temp, LPC_SHB_ORDER, INT_FS_FX); */ /* input lsp_temp_fx in Q15*/ - tmp = i_mult(j, (LPC_SHB_ORDER+1)); + tmp = i_mult( j, ( LPC_SHB_ORDER + 1 ) ); /* convert LSPs to LP coefficients */ - E_LPC_f_lsp_a_conversion(lsp_temp, lpc_shb_sf+tmp, LPC_SHB_ORDER); + E_LPC_f_lsp_a_conversion( lsp_temp, lpc_shb_sf + tmp, LPC_SHB_ORDER ); /* Bring the LPCs to Q12 */ - Copy_Scale_sig( lpc_shb_sf+tmp, lpc_shb_sf+tmp, LPC_SHB_ORDER+1, sub(norm_s(lpc_shb_sf[tmp]),2) ); + Copy_Scale_sig( lpc_shb_sf + tmp, lpc_shb_sf + tmp, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb_sf[tmp] ), 2 ) ); } } /*ELSE*/ { /* for 13.2 and 16.4kbps */ - E_LPC_f_lsp_a_conversion(lsp_temp, lpc_shb, LPC_SHB_ORDER); - Copy_Scale_sig( lpc_shb, lpc_shb, LPC_SHB_ORDER+1, sub(norm_s(lpc_shb[0]),2) ); /* Q12 */ + E_LPC_f_lsp_a_conversion( lsp_temp, lpc_shb, LPC_SHB_ORDER ); + Copy_Scale_sig( lpc_shb, lpc_shb, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb[0] ), 2 ) ); /* Q12 */ } /* Save the SWB LSP values from current frame for interpolation */ - Copy(lsp_shb_2, hBWE_TD->swb_lsp_prev_interp_fx, LPC_SHB_ORDER); + Copy( lsp_shb_2, hBWE_TD->swb_lsp_prev_interp_fx, LPC_SHB_ORDER ); /* lsp_shb_2_fx in Q15 */ /* save the shb_ener Q18, prev_resgainshape Q14, and mixFactor Q15 values */ @@ -2465,7 +2457,7 @@ void swb_tbe_dec_fx( Copy( lsf_shb, st_fx->lsp_shb_prev_fx, LPC_SHB_ORDER ); /* Q15 */ /* vind = (short)(mixFactors*8.0f); */ - vind = shl(mixFactors,3-15); /* 3 for mpy by 8.0f, -15 to bring it to Q0 */ + vind = shl( mixFactors, 3 - 15 ); /* 3 for mpy by 8.0f, -15 to bring it to Q0 */ /* i: mixFactors in Q15 */ /* o: vind in Q0 */ @@ -2481,17 +2473,17 @@ void swb_tbe_dec_fx( Lmax = L_max( Lmax, L_abs( bwe_exc_extended[cnt] ) ); } Q_bwe_exc = norm_l( Lmax ); - if(Lmax == 0) + if ( Lmax == 0 ) { Q_bwe_exc = 31; } Q_bwe_exc = add( Q_bwe_exc, add( Q_exc, Q_exc ) ); /* Account for any outliers in the memories from previous frame for rescaling to avoid saturation */ - find_max_mem_dec( st_fx, &n_mem, &n_mem2, &n_mem3 ); /* for >=24.4, use n_mem2 lpc_syn, shb_20sample, and mem_stp_swb_fx memory */ + find_max_mem_dec( st_fx, &n_mem, &n_mem2, &n_mem3 ); /* for >=24.4, use n_mem2 lpc_syn, shb_20sample, and mem_stp_swb_fx memory */ tmp = add( st_fx->prev_Q_bwe_exc, n_mem ); - if( GT_16( Q_bwe_exc, tmp)) + if ( GT_16( Q_bwe_exc, tmp ) ) { Q_bwe_exc = tmp; } @@ -2504,7 +2496,7 @@ void swb_tbe_dec_fx( } /* rescale the bwe_exc_extended and bring it to 16-bit single precision with dynamic norm */ - Copy(hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); + Copy( hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); sc = sub( Q_bwe_exc, add( Q_exc, Q_exc ) ); FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) @@ -2518,23 +2510,23 @@ void swb_tbe_dec_fx( Copy( bwe_exc_extended_16 + L_FRAME32k, hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET ); /* state_syn_shbexc_fx is kept at (st_fx->prev_Q_bwe_syn) for 24.4/32kbps or is kept at Q_bwe_exc for 13.2/16.4kbps */ - Copy(hBWE_TD->state_syn_shbexc_fx, shaped_shb_excitation, L_SHB_LAHEAD ); + Copy( hBWE_TD->state_syn_shbexc_fx, shaped_shb_excitation, L_SHB_LAHEAD ); /* save the previous Q factor (32-bit) of the buffer */ st_fx->prev_Q_bwe_exc = Q_bwe_exc; move16(); - Q_bwe_exc = sub( Q_bwe_exc, 16 ); /* Q_bwe_exc reflecting the single precision dynamic norm-ed buffers from here */ + Q_bwe_exc = sub( Q_bwe_exc, 16 ); /* Q_bwe_exc reflecting the single precision dynamic norm-ed buffers from here */ /* -------- end of rescaling memories -------- */ Q_bwe_exc_fb = st_fx->prev_Q_bwe_exc_fb; move16(); - IF( GT_32(st_fx->total_brate, ACELP_32k)) + IF( GT_32( st_fx->total_brate, ACELP_32k ) ) { FOR( j = 0; j < 4; j++ ) { - Copy(lpc_shb, &lpc_shb_sf[j*(LPC_SHB_ORDER+1)], LPC_SHB_ORDER+1); + Copy( lpc_shb, &lpc_shb_sf[j * ( LPC_SHB_ORDER + 1 )], LPC_SHB_ORDER + 1 ); } } @@ -2542,12 +2534,12 @@ void swb_tbe_dec_fx( GenShapedSHBExcitation_fx( shaped_shb_excitation + L_SHB_LAHEAD, lpc_shb, White_exc16k, hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, coder_type, bwe_exc_extended_16, hBWE_TD->bwe_seed, vf_modified, st_fx->extl, - &(hBWE_TD->tbe_demph_fx ), &(hBWE_TD->tbe_premph_fx ), lpc_shb_sf, shb_ener_sf_32, + &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), lpc_shb_sf, shb_ener_sf_32, shb_res_gshape, shb_res_dummy, &vind, formant_fac, hBWE_TD->fb_state_lpc_syn_fx, - &(hBWE_TD->fb_tbe_demph_fx), &Q_bwe_exc, &Q_bwe_exc_fb,Q_shb, n_mem2, st_fx->prev_Q_bwe_syn, st_fx->total_brate, st_fx->prev_bfi ); + &( hBWE_TD->fb_tbe_demph_fx ), &Q_bwe_exc, &Q_bwe_exc_fb, Q_shb, n_mem2, st_fx->prev_Q_bwe_syn, st_fx->total_brate, st_fx->prev_bfi ); *Q_white_exc = Q_bwe_exc_fb; - IF( EQ_16(st_fx->extl, FB_TBE)) + IF( EQ_16( st_fx->extl, FB_TBE ) ) { st_fx->prev_Q_bwe_exc_fb = Q_bwe_exc_fb; move16(); @@ -2562,46 +2554,46 @@ void swb_tbe_dec_fx( /* rescale the TBE post proc memory */ FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - hBWE_TD->mem_stp_swb_fx[i] = shl(hBWE_TD->mem_stp_swb_fx[i], Q_bwe_exc - st_fx->prev_Q_bwe_syn); + hBWE_TD->mem_stp_swb_fx[i] = shl( hBWE_TD->mem_stp_swb_fx[i], Q_bwe_exc - st_fx->prev_Q_bwe_syn ); move16(); } - FOR( i = 0; i < L_FRAME16k; i+=L_SUBFR16k ) + FOR( i = 0; i < L_FRAME16k; i += L_SUBFR16k ) { /* TD BWE post-processing */ - PostShortTerm_fx( &shaped_shb_excitation[L_SHB_LAHEAD+i], lpc_shb, &shaped_shb_excitationTemp[i], hBWE_TD->mem_stp_swb_fx, - hBWE_TD->ptr_mem_stp_swb_fx, &(hBWE_TD->gain_prec_swb_fx), hBWE_TD->mem_zero_swb_fx, formant_fac ); + PostShortTerm_fx( &shaped_shb_excitation[L_SHB_LAHEAD + i], lpc_shb, &shaped_shb_excitationTemp[i], hBWE_TD->mem_stp_swb_fx, + hBWE_TD->ptr_mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ), hBWE_TD->mem_zero_swb_fx, formant_fac ); } - Copy( shaped_shb_excitationTemp, &shaped_shb_excitation[L_SHB_LAHEAD], L_FRAME16k ); /* Q_bwe_exc */ + Copy( shaped_shb_excitationTemp, &shaped_shb_excitation[L_SHB_LAHEAD], L_FRAME16k ); /* Q_bwe_exc */ - tmp = sub(shl(Q_bwe_exc, 1), 31+16); + tmp = sub( shl( Q_bwe_exc, 1 ), 31 + 16 ); #ifdef BASOP_NOGLOB - prev_pow = L_shl_sat(1407374848l/*0.00001f Q47*/, tmp); /* 2*(Q_bwe_exc) */ - curr_pow = L_shl_sat(1407374848l/*0.00001f Q47*/, tmp); /* 2*(Q_bwe_exc) */ + prev_pow = L_shl_sat( 1407374848l /*0.00001f Q47*/, tmp ); /* 2*(Q_bwe_exc) */ + curr_pow = L_shl_sat( 1407374848l /*0.00001f Q47*/, tmp ); /* 2*(Q_bwe_exc) */ #else - prev_pow = L_shl(1407374848l/*0.00001f Q47*/, tmp); /* 2*(Q_bwe_exc) */ - curr_pow = L_shl(1407374848l/*0.00001f Q47*/, tmp); /* 2*(Q_bwe_exc) */ + prev_pow = L_shl( 1407374848l /*0.00001f Q47*/, tmp ); /* 2*(Q_bwe_exc) */ + curr_pow = L_shl( 1407374848l /*0.00001f Q47*/, tmp ); /* 2*(Q_bwe_exc) */ #endif FOR( i = 0; i < L_SHB_LAHEAD + 10; i++ ) { #ifdef BASOP_NOGLOB - prev_pow = L_mac0_sat( prev_pow, shaped_shb_excitation[i], shaped_shb_excitation[i] ); /*2*Q_bwe_exc*/ - curr_pow = L_mac0_sat( curr_pow, shaped_shb_excitation[i + L_SHB_LAHEAD + 10], shaped_shb_excitation[i+L_SHB_LAHEAD + 10] ); /* 2*Q_bwe_exc */ + prev_pow = L_mac0_sat( prev_pow, shaped_shb_excitation[i], shaped_shb_excitation[i] ); /*2*Q_bwe_exc*/ + curr_pow = L_mac0_sat( curr_pow, shaped_shb_excitation[i + L_SHB_LAHEAD + 10], shaped_shb_excitation[i + L_SHB_LAHEAD + 10] ); /* 2*Q_bwe_exc */ #else - prev_pow = L_mac0( prev_pow, shaped_shb_excitation[i], shaped_shb_excitation[i] ); /*2*Q_bwe_exc*/ - curr_pow = L_mac0( curr_pow, shaped_shb_excitation[i + L_SHB_LAHEAD + 10], shaped_shb_excitation[i+L_SHB_LAHEAD + 10] ); /* 2*Q_bwe_exc */ + prev_pow = L_mac0( prev_pow, shaped_shb_excitation[i], shaped_shb_excitation[i] ); /*2*Q_bwe_exc*/ + curr_pow = L_mac0( curr_pow, shaped_shb_excitation[i + L_SHB_LAHEAD + 10], shaped_shb_excitation[i + L_SHB_LAHEAD + 10] ); /* 2*Q_bwe_exc */ #endif } - if( GT_16( voice_factors[0], 24576/*0.75f Q15*/ )) + if ( GT_16( voice_factors[0], 24576 /*0.75f Q15*/ ) ) { curr_pow = L_shr( curr_pow, 2 ); /* Q(2*Q_bwe_exc) */ } Lscale = root_a_over_b_fx( curr_pow, - shl(Q_bwe_exc, 1), + shl( Q_bwe_exc, 1 ), prev_pow, - shl(Q_bwe_exc, 1), + shl( Q_bwe_exc, 1 ), &exp ); FOR( i = 0; i < L_SHB_LAHEAD; i++ ) @@ -2611,30 +2603,30 @@ void swb_tbe_dec_fx( } IF( exp < 0 ) { - Lscale = L_shl(Lscale, exp); + Lscale = L_shl( Lscale, exp ); exp = 0; } - FOR( ; i < L_SHB_LAHEAD + 10; i++ ) + FOR( ; i < L_SHB_LAHEAD + 10; i++ ) { #ifdef BASOP_NOGLOB - temp = i_mult_sat(sub(i,19), 3277/*0.1f Q15*/); /* Q15 */ - L_tmp1 = Mult_32_16(L_shl_sat(1, sub(31, exp)), temp); /* Q31-exp */ + temp = i_mult_sat( sub( i, 19 ), 3277 /*0.1f Q15*/ ); /* Q15 */ + L_tmp1 = Mult_32_16( L_shl_sat( 1, sub( 31, exp ) ), temp ); /* Q31-exp */ #else - temp = i_mult(sub(i,19), 3277/*0.1f Q15*/); /* Q15 */ - L_tmp1 = Mult_32_16(L_shl(1, sub(31, exp)), temp); /* Q31-exp */ + temp = i_mult( sub( i, 19 ), 3277 /*0.1f Q15*/ ); /* Q15 */ + L_tmp1 = Mult_32_16( L_shl( 1, sub( 31, exp ) ), temp ); /* Q31-exp */ #endif - temp = sub(32767/*1.0f Q15*/, temp); - Lscale = L_add(Mult_32_16(Lscale, temp), L_tmp1); + temp = sub( 32767 /*1.0f Q15*/, temp ); + Lscale = L_add( Mult_32_16( Lscale, temp ), L_tmp1 ); L_tmp = Mult_32_16( Lscale, shaped_shb_excitation[i] ); /* Q_bwe_exc + (31-exp) - 15 */ shaped_shb_excitation[i] = round_fx( L_shl( L_tmp, exp ) ); /* Q_bwe_exc */ } /* Update SHB excitation */ - Copy( shaped_shb_excitation + L_FRAME16k, hBWE_TD->state_syn_shbexc_fx, L_SHB_LAHEAD ); /* Q_bwe_exc */ + Copy( shaped_shb_excitation + L_FRAME16k, hBWE_TD->state_syn_shbexc_fx, L_SHB_LAHEAD ); /* Q_bwe_exc */ - l_subframe_fx = L_FRAME16k/NUM_SHB_SUBGAINS; + l_subframe_fx = L_FRAME16k / NUM_SHB_SUBGAINS; L_ener = 0; - FOR(i = 0; i < NUM_SHB_SUBGAINS; i++) + FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) { L_tmp = 0; ener_tmp[i] = 0; @@ -2642,43 +2634,45 @@ void swb_tbe_dec_fx( { Word64 tmp64 = 0; move64(); - FOR(j = 0; j < l_subframe_fx; j++) + FOR( j = 0; j < l_subframe_fx; j++ ) { - tmp64 = W_mac0_16_16( tmp64, shaped_shb_excitation[i*l_subframe_fx+j], shaped_shb_excitation[i*l_subframe_fx+j] );/* 2*Q_bwe_exc */ + tmp64 = W_mac0_16_16( tmp64, shaped_shb_excitation[i * l_subframe_fx + j], shaped_shb_excitation[i * l_subframe_fx + j] ); /* 2*Q_bwe_exc */ } - L_tmp = W_sat_l(tmp64); + L_tmp = W_sat_l( tmp64 ); } - L_tmp = Mult_32_16(L_tmp, 410/*0.0125 Q15*/); /* 2*Q_bwe_exc: ener_tmp_fx in (2*Q_bwe_exc) */ + L_tmp = Mult_32_16( L_tmp, 410 /*0.0125 Q15*/ ); /* 2*Q_bwe_exc: ener_tmp_fx in (2*Q_bwe_exc) */ IF( L_tmp != 0 ) { exp = norm_l( L_tmp ); tmp = extract_h( L_shl( L_tmp, exp ) ); - exp = sub( exp, 30 - (2 * Q_bwe_exc) ); + exp = sub( exp, 30 - ( 2 * Q_bwe_exc ) ); tmp = div_s( 16384, tmp ); L_tmp = L_deposit_h( tmp ); L_tmp = Isqrt_lc( L_tmp, &exp ); #ifdef BASOP_NOGLOB - ener_tmp[i] = L_shl_sat( L_tmp, sub(add( exp, shl(Q_bwe_exc,1)),31)); /*2 * Q_bwe_exc: Q31 -exp +exp +2 * Q_bwe_exc -31 */ move32(); - L_ener = L_add_sat(L_ener, L_shr(ener_tmp[i], 2));/* 2*Q_bwe_exc */ + ener_tmp[i] = L_shl_sat( L_tmp, sub( add( exp, shl( Q_bwe_exc, 1 ) ), 31 ) ); /*2 * Q_bwe_exc: Q31 -exp +exp +2 * Q_bwe_exc -31 */ + move32(); + L_ener = L_add_sat( L_ener, L_shr( ener_tmp[i], 2 ) ); /* 2*Q_bwe_exc */ #else - ener_tmp[i] = L_shl( L_tmp, sub(add( exp, shl(Q_bwe_exc,1)),31)); /*2 * Q_bwe_exc: Q31 -exp +exp +2 * Q_bwe_exc -31 */ move32(); - L_ener = L_add(L_ener, L_shr(ener_tmp[i], 2));/* 2*Q_bwe_exc */ + ener_tmp[i] = L_shl( L_tmp, sub( add( exp, shl( Q_bwe_exc, 1 ) ), 31 ) ); /*2 * Q_bwe_exc: Q31 -exp +exp +2 * Q_bwe_exc -31 */ + move32(); + L_ener = L_add( L_ener, L_shr( ener_tmp[i], 2 ) ); /* 2*Q_bwe_exc */ #endif } } #ifdef BASOP_NOGLOB ener = s_max( 1, round_fx_sat( L_shl_sat( L_ener, sub( 19, shl( Q_bwe_exc, 1 ) ) ) ) ); /* Q3: 2*Q_bwe_exc+19-2*Q_bwe_exc-16 */ #else - ener = s_max(1, round_fx( L_shl( L_ener, sub(19, shl(Q_bwe_exc, 1)) ) )); /* Q3: 2*Q_bwe_exc+19-2*Q_bwe_exc-16 */ + ener = s_max( 1, round_fx( L_shl( L_ener, sub( 19, shl( Q_bwe_exc, 1 ) ) ) ) ); /* Q3: 2*Q_bwe_exc+19-2*Q_bwe_exc-16 */ #endif /* WB/SWB bandwidth switching */ IF( st_fx->bws_cnt > 0 ) { - ener = mult(ener, 11587); + ener = mult( ener, 11587 ); /*bandwidth switching should be updated*/ - if( GT_16( st_fx->tilt_swb_fx, 16384 )) + if ( GT_16( st_fx->tilt_swb_fx, 16384 ) ) { st_fx->prev_fractive = 1; move16(); @@ -2686,18 +2680,18 @@ void swb_tbe_dec_fx( IF( is_fractive == 0 ) { - IF( GT_16( st_fx->tilt_wb_fx, 2048 )) /*assuming st_fx->tilt_wb_fx in Q11*/ + IF( GT_16( st_fx->tilt_wb_fx, 2048 ) ) /*assuming st_fx->tilt_wb_fx in Q11*/ { st_fx->tilt_wb_fx = 2048; move16(); } - ELSE IF( LT_16( st_fx->tilt_wb_fx, 1024 )) + ELSE IF( LT_16( st_fx->tilt_wb_fx, 1024 ) ) { st_fx->tilt_wb_fx = 1024; move16(); } test(); - if( st_fx->prev_fractive == 1 && GT_16( st_fx->tilt_wb_fx, 1024 )) + if ( st_fx->prev_fractive == 1 && GT_16( st_fx->tilt_wb_fx, 1024 ) ) { st_fx->tilt_wb_fx = 1024; move16(); @@ -2705,9 +2699,9 @@ void swb_tbe_dec_fx( } ELSE { - IF(GT_16(st_fx->tilt_wb_fx, 8192)) + IF( GT_16( st_fx->tilt_wb_fx, 8192 ) ) { - IF(st_fx->prev_fractive == 0) + IF( st_fx->prev_fractive == 0 ) { st_fx->tilt_wb_fx = 8192; } @@ -2718,41 +2712,41 @@ void swb_tbe_dec_fx( } ELSE { - st_fx->tilt_wb_fx = shl(st_fx->tilt_wb_fx, 2); + st_fx->tilt_wb_fx = shl( st_fx->tilt_wb_fx, 2 ); } } - IF(ener != 0) + IF( ener != 0 ) { - L_tmp = L_shl(L_mult0(ener, st_fx->tilt_wb_fx), sub(st_fx->Q_syn2, 14)); /* 3+11 +st_fx->Q_syn2 -14 = st_fx->Q_syn2*/ - exp_ener = norm_s(ener); - tmp = shl(ener, exp_ener);/*Q(3+exp)*/ - inv_ener = div_s(16384, tmp);/*Q(15+14-3-exp) = 26- exp*/ + L_tmp = L_shl( L_mult0( ener, st_fx->tilt_wb_fx ), sub( st_fx->Q_syn2, 14 ) ); /* 3+11 +st_fx->Q_syn2 -14 = st_fx->Q_syn2*/ + exp_ener = norm_s( ener ); + tmp = shl( ener, exp_ener ); /*Q(3+exp)*/ + inv_ener = div_s( 16384, tmp ); /*Q(15+14-3-exp) = 26- exp*/ test(); - IF( GT_32(L_tmp, st_fx->enerLH_fx)) /*st_fx->Q_syn2*/ + IF( GT_32( L_tmp, st_fx->enerLH_fx ) ) /*st_fx->Q_syn2*/ { #ifdef BASOP_NOGLOB - st_fx->tilt_wb_fx = extract_h(L_shr_sat(Mult_32_16(st_fx->enerLH_fx, inv_ener), sub(sub(st_fx->Q_syn2, exp_ener),16))); /*Q11*/ + st_fx->tilt_wb_fx = extract_h( L_shr_sat( Mult_32_16( st_fx->enerLH_fx, inv_ener ), sub( sub( st_fx->Q_syn2, exp_ener ), 16 ) ) ); /*Q11*/ #else - st_fx->tilt_wb_fx = extract_h(L_shr(Mult_32_16(st_fx->enerLH_fx, inv_ener), sub(sub(st_fx->Q_syn2, exp_ener),16))); /*Q11*/ + st_fx->tilt_wb_fx = extract_h( L_shr( Mult_32_16( st_fx->enerLH_fx, inv_ener ), sub( sub( st_fx->Q_syn2, exp_ener ), 16 ) ) ); /*Q11*/ #endif /*st_fx->Q_syn2 -1 + 26- exp_ener -15 -(st_fx->Q_syn2 -exp_ener -16 ) -16 +1 -1 = (11) *0.5*/ } - ELSE IF( LT_32(L_tmp, Mult_32_16(st_fx->enerLH_fx, 1638))&&EQ_16(is_fractive,1)) + ELSE IF( LT_32( L_tmp, Mult_32_16( st_fx->enerLH_fx, 1638 ) ) && EQ_16( is_fractive, 1 ) ) { #ifdef BASOP_NOGLOB - st_fx->tilt_wb_fx = extract_h(L_shr_sat(Mult_32_16(st_fx->enerLH_fx, inv_ener), sub(sub(st_fx->Q_syn2, exp_ener), 15))); /*Q11*/ + st_fx->tilt_wb_fx = extract_h( L_shr_sat( Mult_32_16( st_fx->enerLH_fx, inv_ener ), sub( sub( st_fx->Q_syn2, exp_ener ), 15 ) ) ); /*Q11*/ #else - st_fx->tilt_wb_fx = extract_h(L_shr(Mult_32_16(st_fx->enerLH_fx, inv_ener), sub(sub(st_fx->Q_syn2, exp_ener), 15))); /*Q11*/ + st_fx->tilt_wb_fx = extract_h( L_shr( Mult_32_16( st_fx->enerLH_fx, inv_ener ), sub( sub( st_fx->Q_syn2, exp_ener ), 15 ) ) ); /*Q11*/ #endif /*st_fx->Q_syn2 -1 + 26- exp_ener -15 -(st_fx->Q_syn2 -exp_ener -15 ) -16 = (11) 0.25*/ } - L_tmp = L_mult0(st_fx->prev_ener_shb_fx, inv_ener); /*Q(1+15+14-3-exp_ener) = 27 -exp_ener*/ + L_tmp = L_mult0( st_fx->prev_ener_shb_fx, inv_ener ); /*Q(1+15+14-3-exp_ener) = 27 -exp_ener*/ #ifdef BASOP_NOGLOB GainFrame_prevfrm_fx = L_shr_sat( L_tmp, sub( 9, exp_ener ) ); /*27 -exp_ener -(9-exp_ener )= Q18*/ #else - GainFrame_prevfrm_fx = L_shr(L_tmp, sub(9, exp_ener)); /*27 -exp_ener -(9-exp_ener )= Q18*/ + GainFrame_prevfrm_fx = L_shr( L_tmp, sub( 9, exp_ener ) ); /*27 -exp_ener -(9-exp_ener )= Q18*/ #endif } ELSE @@ -2760,19 +2754,19 @@ void swb_tbe_dec_fx( GainFrame_prevfrm_fx = 0; } - IF( EQ_16(is_fractive , 1)) + IF( EQ_16( is_fractive, 1 ) ) { - GainFrame = L_shl((Word32)st_fx->tilt_wb_fx, 10); + GainFrame = L_shl( (Word32) st_fx->tilt_wb_fx, 10 ); } ELSE { - GainFrame = L_shl((Word32)st_fx->tilt_wb_fx, 8); + GainFrame = L_shl( (Word32) st_fx->tilt_wb_fx, 8 ); } test(); - IF( EQ_16((is_fractive & st_fx->prev_fractive), 1)&>_32(GainFrame,GainFrame_prevfrm_fx)) + IF( EQ_16( ( is_fractive & st_fx->prev_fractive ), 1 ) && GT_32( GainFrame, GainFrame_prevfrm_fx ) ) { - GainFrame = L_add(Mult_32_16(GainFrame_prevfrm_fx, 26214), Mult_32_16(GainFrame, 6554));/* 18 +15 -15 = 18*/ + GainFrame = L_add( Mult_32_16( GainFrame_prevfrm_fx, 26214 ), Mult_32_16( GainFrame, 6554 ) ); /* 18 +15 -15 = 18*/ } ELSE { @@ -2780,49 +2774,48 @@ void swb_tbe_dec_fx( test(); test(); test(); - IF((LT_32(L_shr(st_fx->prev_enerLH_fx, 1), st_fx->enerLH_fx)&& GT_32(st_fx->prev_enerLH_fx,L_shr(st_fx->enerLH_fx,1))) - && (LT_32(L_shr(st_fx->prev_enerLL_fx, 1), st_fx->enerLL_fx) && GT_32(st_fx->prev_enerLL_fx, L_shr(st_fx->enerLL_fx, 1)) ) && (is_fractive ^ st_fx->prev_fractive) == 0) + IF( ( LT_32( L_shr( st_fx->prev_enerLH_fx, 1 ), st_fx->enerLH_fx ) && GT_32( st_fx->prev_enerLH_fx, L_shr( st_fx->enerLH_fx, 1 ) ) ) && ( LT_32( L_shr( st_fx->prev_enerLL_fx, 1 ), st_fx->enerLL_fx ) && GT_32( st_fx->prev_enerLL_fx, L_shr( st_fx->enerLL_fx, 1 ) ) ) && ( is_fractive ^ st_fx->prev_fractive ) == 0 ) { - GainFrame = L_add(L_shr(GainFrame, 1), L_shr(GainFrame_prevfrm_fx, 1)); + GainFrame = L_add( L_shr( GainFrame, 1 ), L_shr( GainFrame_prevfrm_fx, 1 ) ); } ELSE { test(); - IF(is_fractive == 0 && EQ_16(st_fx->prev_fractive, 1)) + IF( is_fractive == 0 && EQ_16( st_fx->prev_fractive, 1 ) ) { - L_tmp1 = L_shl(Mult_32_16(GainFrame, 3277), 13); /* 31 */ - L_tmp = L_sub(2147483647, L_tmp1); /* 31 */ - GainFrame = L_add(Mult_32_32(GainFrame, L_tmp), Mult_32_32(GainFrame_prevfrm_fx, L_tmp1)); /* 18 */ + L_tmp1 = L_shl( Mult_32_16( GainFrame, 3277 ), 13 ); /* 31 */ + L_tmp = L_sub( 2147483647, L_tmp1 ); /* 31 */ + GainFrame = L_add( Mult_32_32( GainFrame, L_tmp ), Mult_32_32( GainFrame_prevfrm_fx, L_tmp1 ) ); /* 18 */ } ELSE { - GainFrame = L_add(L_shr(GainFrame, 1), L_shr(L_min(GainFrame_prevfrm_fx, GainFrame), 1)); /* 18 */ + GainFrame = L_add( L_shr( GainFrame, 1 ), L_shr( L_min( GainFrame_prevfrm_fx, GainFrame ), 1 ) ); /* 18 */ } } } - GainFrame = Mult_32_16(GainFrame, i_mult(sub(N_WS2N_FRAMES, st_fx->bws_cnt), 819)); /*Q18*/ + GainFrame = Mult_32_16( GainFrame, i_mult( sub( N_WS2N_FRAMES, st_fx->bws_cnt ), 819 ) ); /*Q18*/ } ELSE { - IF(st_fx->bws_cnt1 > 0) + IF( st_fx->bws_cnt1 > 0 ) { - GainFrame = Mult_32_16(GainFrame, i_mult(st_fx->bws_cnt1, 819)); /*Q18*/ + GainFrame = Mult_32_16( GainFrame, i_mult( st_fx->bws_cnt1, 819 ) ); /*Q18*/ } - IF(GE_16(st_fx->nbLostCmpt, 1)) + IF( GE_16( st_fx->nbLostCmpt, 1 ) ) { - ener = s_max(1, ener); - exp_ener = norm_s(ener); - tmp = shl(ener, exp_ener);/*Q(3+exp)*/ - inv_ener = div_s(16384, tmp);/*Q(15+14-3-exp)*/ + ener = s_max( 1, ener ); + exp_ener = norm_s( ener ); + tmp = shl( ener, exp_ener ); /*Q(3+exp)*/ + inv_ener = div_s( 16384, tmp ); /*Q(15+14-3-exp)*/ #ifdef BASOP_NOGLOB prev_ener_ratio_fx = L_shr_sat( L_mult0( st_fx->prev_ener_shb_fx, inv_ener ), sub( 9, exp_ener ) ); /*Q: 1+26-exp-9+exp = 18 */ #else - prev_ener_ratio_fx = L_shr(L_mult0(st_fx->prev_ener_shb_fx, inv_ener), sub(9, exp_ener)); /*Q: 1+26-exp-9+exp = 18 */ + prev_ener_ratio_fx = L_shr( L_mult0( st_fx->prev_ener_shb_fx, inv_ener ), sub( 9, exp_ener ) ); /*Q: 1+26-exp-9+exp = 18 */ #endif } - IF(EQ_16(st_fx->nbLostCmpt, 1)) + IF( EQ_16( st_fx->nbLostCmpt, 1 ) ) { test(); test(); @@ -2834,40 +2827,39 @@ void swb_tbe_dec_fx( test(); test(); test(); - IF( NE_16(st_fx->clas_dec, UNVOICED_CLAS)&&NE_16(st_fx->clas_dec,UNVOICED_TRANSITION)&<_16(hBWE_TD->tilt_swb_fec_fx,16384)&& - ((GT_32(st_fx->enerLL_fx, L_shr(st_fx->prev_enerLL_fx, 1)) && LT_32(L_shr(st_fx->enerLL_fx, 1), st_fx->prev_enerLL_fx) )|| (GT_32(st_fx->enerLH_fx, L_shr(st_fx->prev_enerLH_fx, 1)) && LT_32(L_shr(st_fx->enerLH_fx, 1), st_fx->prev_enerLH_fx)))) + IF( NE_16( st_fx->clas_dec, UNVOICED_CLAS ) && NE_16( st_fx->clas_dec, UNVOICED_TRANSITION ) && LT_16( hBWE_TD->tilt_swb_fec_fx, 16384 ) && + ( ( GT_32( st_fx->enerLL_fx, L_shr( st_fx->prev_enerLL_fx, 1 ) ) && LT_32( L_shr( st_fx->enerLL_fx, 1 ), st_fx->prev_enerLL_fx ) ) || ( GT_32( st_fx->enerLH_fx, L_shr( st_fx->prev_enerLH_fx, 1 ) ) && LT_32( L_shr( st_fx->enerLH_fx, 1 ), st_fx->prev_enerLH_fx ) ) ) ) { - IF(GT_32(L_shr(prev_ener_ratio_fx, 2), GainFrame))/*18*/ + IF( GT_32( L_shr( prev_ener_ratio_fx, 2 ), GainFrame ) ) /*18*/ { - GainFrame = L_add(Mult_32_16(prev_ener_ratio_fx, 13107), Mult_32_16(GainFrame, 19661));/*18*/ + GainFrame = L_add( Mult_32_16( prev_ener_ratio_fx, 13107 ), Mult_32_16( GainFrame, 19661 ) ); /*18*/ } - ELSE IF(GT_32(L_shr(prev_ener_ratio_fx, 1), GainFrame)) + ELSE IF( GT_32( L_shr( prev_ener_ratio_fx, 1 ), GainFrame ) ) { - GainFrame = L_add(Mult_32_16(prev_ener_ratio_fx, 26214), Mult_32_16(GainFrame, 6554)); + GainFrame = L_add( Mult_32_16( prev_ener_ratio_fx, 26214 ), Mult_32_16( GainFrame, 6554 ) ); } ELSE { - GainFrame = L_add(Mult_32_16(prev_ener_ratio_fx, 6554), Mult_32_16(GainFrame, 26214)); + GainFrame = L_add( Mult_32_16( prev_ener_ratio_fx, 6554 ), Mult_32_16( GainFrame, 26214 ) ); } test(); - IF(GT_16(tilt_swb_fec, hBWE_TD->tilt_swb_fec_fx)&& hBWE_TD->tilt_swb_fec_fx>0) + IF( GT_16( tilt_swb_fec, hBWE_TD->tilt_swb_fec_fx ) && hBWE_TD->tilt_swb_fec_fx > 0 ) { - exp = norm_s(hBWE_TD->tilt_swb_fec_fx); - tmp = shl(hBWE_TD->tilt_swb_fec_fx, exp);/*Q(11+exp)*/ - tmp = div_s(16384, tmp);/*Q(15+14-11-exp)*/ - tmp = extract_h(L_shl(L_mult0(tmp, st_fx->tilt_wb_fx),sub(exp,1)));/*18 -exp +11 + exp -1 -16 =12; */ - GainFrame = L_shl(Mult_32_16(GainFrame, s_min(tmp, 20480)), 3); /*Q18 = 18 +12 -15 +3 */ + exp = norm_s( hBWE_TD->tilt_swb_fec_fx ); + tmp = shl( hBWE_TD->tilt_swb_fec_fx, exp ); /*Q(11+exp)*/ + tmp = div_s( 16384, tmp ); /*Q(15+14-11-exp)*/ + tmp = extract_h( L_shl( L_mult0( tmp, st_fx->tilt_wb_fx ), sub( exp, 1 ) ) ); /*18 -exp +11 + exp -1 -16 =12; */ + GainFrame = L_shl( Mult_32_16( GainFrame, s_min( tmp, 20480 ) ), 3 ); /*Q18 = 18 +12 -15 +3 */ } - } - ELSE IF( (NE_16(st_fx->clas_dec, UNVOICED_CLAS)||GT_16(hBWE_TD->tilt_swb_fec_fx,16384))&>_32(L_shr(prev_ener_ratio_fx,2),GainFrame)&& - (GT_32(st_fx->enerLL_fx, L_shr(st_fx->prev_enerLL_fx, 1)) || GT_32(st_fx->enerLH_fx, L_shr(st_fx->prev_enerLH_fx, 1)) ) ) + ELSE IF( ( NE_16( st_fx->clas_dec, UNVOICED_CLAS ) || GT_16( hBWE_TD->tilt_swb_fec_fx, 16384 ) ) && GT_32( L_shr( prev_ener_ratio_fx, 2 ), GainFrame ) && + ( GT_32( st_fx->enerLL_fx, L_shr( st_fx->prev_enerLL_fx, 1 ) ) || GT_32( st_fx->enerLH_fx, L_shr( st_fx->prev_enerLH_fx, 1 ) ) ) ) { - GainFrame = L_add(Mult_32_16(prev_ener_ratio_fx, 6554), Mult_32_16(GainFrame, 26214)); + GainFrame = L_add( Mult_32_16( prev_ener_ratio_fx, 6554 ), Mult_32_16( GainFrame, 26214 ) ); } } - ELSE IF( GT_16(st_fx->nbLostCmpt, 1)) + ELSE IF( GT_16( st_fx->nbLostCmpt, 1 ) ) { test(); test(); @@ -2877,28 +2869,28 @@ void swb_tbe_dec_fx( test(); test(); test(); - IF(GT_32(L_shr(prev_ener_ratio_fx, 2), GainFrame)&&((EQ_16(st_fx->codec_mode,MODE1)&>_32(st_fx->enerLL_fx,st_fx->prev_enerLL_fx)&>_32(st_fx->enerLH_fx,st_fx->prev_enerLH_fx))||EQ_16(st_fx->codec_mode,MODE2))) + IF( GT_32( L_shr( prev_ener_ratio_fx, 2 ), GainFrame ) && ( ( EQ_16( st_fx->codec_mode, MODE1 ) && GT_32( st_fx->enerLL_fx, st_fx->prev_enerLL_fx ) && GT_32( st_fx->enerLH_fx, st_fx->prev_enerLH_fx ) ) || EQ_16( st_fx->codec_mode, MODE2 ) ) ) { test(); - IF( GT_16(tilt_swb_fec, 20480)&>_16(hBWE_TD->tilt_swb_fec_fx,20480)) + IF( GT_16( tilt_swb_fec, 20480 ) && GT_16( hBWE_TD->tilt_swb_fec_fx, 20480 ) ) { - GainFrame = L_min(L_add(Mult_32_16(prev_ener_ratio_fx, 26214), Mult_32_16(GainFrame, 6554)), L_shl(Mult_32_16(GainFrame, 16384), 3)); /*Q18*/ + GainFrame = L_min( L_add( Mult_32_16( prev_ener_ratio_fx, 26214 ), Mult_32_16( GainFrame, 6554 ) ), L_shl( Mult_32_16( GainFrame, 16384 ), 3 ) ); /*Q18*/ } ELSE { - GainFrame = L_min(L_add(Mult_32_16(prev_ener_ratio_fx, 16384), Mult_32_16(GainFrame, 16384)), L_shl(Mult_32_16(GainFrame, 16384), 3)); /*Q18*/ + GainFrame = L_min( L_add( Mult_32_16( prev_ener_ratio_fx, 16384 ), Mult_32_16( GainFrame, 16384 ) ), L_shl( Mult_32_16( GainFrame, 16384 ), 3 ) ); /*Q18*/ } } - ELSE IF(GT_32(prev_ener_ratio_fx, GainFrame)&&((EQ_16(st_fx->codec_mode,MODE1)&>_32(st_fx->enerLL_fx,st_fx->prev_enerLL_fx)&>_32(st_fx->enerLH_fx,st_fx->prev_enerLH_fx))||EQ_16(st_fx->codec_mode,MODE2))) + ELSE IF( GT_32( prev_ener_ratio_fx, GainFrame ) && ( ( EQ_16( st_fx->codec_mode, MODE1 ) && GT_32( st_fx->enerLL_fx, st_fx->prev_enerLL_fx ) && GT_32( st_fx->enerLH_fx, st_fx->prev_enerLH_fx ) ) || EQ_16( st_fx->codec_mode, MODE2 ) ) ) { test(); - IF( GT_16(tilt_swb_fec, 20480)&>_16(hBWE_TD->tilt_swb_fec_fx,20480)) + IF( GT_16( tilt_swb_fec, 20480 ) && GT_16( hBWE_TD->tilt_swb_fec_fx, 20480 ) ) { - GainFrame = L_add(Mult_32_16(prev_ener_ratio_fx, 16384), Mult_32_16(GainFrame, 16384)); + GainFrame = L_add( Mult_32_16( prev_ener_ratio_fx, 16384 ), Mult_32_16( GainFrame, 16384 ) ); } ELSE { - GainFrame = L_add(Mult_32_16(prev_ener_ratio_fx, 6554), Mult_32_16(GainFrame, 26214)); + GainFrame = L_add( Mult_32_16( prev_ener_ratio_fx, 6554 ), Mult_32_16( GainFrame, 26214 ) ); } } } @@ -2907,25 +2899,25 @@ void swb_tbe_dec_fx( move16(); /* Adjust the subframe and frame gain of the synthesized shb signal */ - IF( EQ_16(st_fx->L_frame, L_FRAME)) + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { /* pitch = 0.25f*sum_s(pitch_buf, 4); */ - L_tmp = L_mult(pitch_buf[0], 8192); - FOR (i=1; itotal_brate, ACELP_24k40)&&EQ_16(st_fx->prev_coder_type,coder_type)&&NE_16(coder_type,UNVOICED)) - || (LE_32(st_fx->total_brate, ACELP_16k40) && (EQ_16(st_fx->prev_coder_type, coder_type) || (EQ_16(st_fx->prev_coder_type, VOICED) && EQ_16(coder_type, GENERIC) ) || (EQ_16(st_fx->prev_coder_type, GENERIC) && EQ_16(coder_type, VOICED) )))) - && GT_16(pitch_fx, 4480 /*70 in Q6*/) && LT_16(st_fx->extl, FB_TBE) ) + IF( ( ( GE_32( st_fx->total_brate, ACELP_24k40 ) && EQ_16( st_fx->prev_coder_type, coder_type ) && NE_16( coder_type, UNVOICED ) ) || ( LE_32( st_fx->total_brate, ACELP_16k40 ) && ( EQ_16( st_fx->prev_coder_type, coder_type ) || ( EQ_16( st_fx->prev_coder_type, VOICED ) && EQ_16( coder_type, GENERIC ) ) || ( EQ_16( st_fx->prev_coder_type, GENERIC ) && EQ_16( coder_type, VOICED ) ) ) ) ) && GT_16( pitch_fx, 4480 /*70 in Q6*/ ) && LT_16( st_fx->extl, FB_TBE ) ) { - FOR(i=0; i st_fx->prev_ener_fx*st_fx->prev_GainShape_fx ) */ - L_tmp1 = Mult_32_16(ener_tmp[i], GainShape_tmp[i]); /* (2*Q_bwe_exc) */ - L_tmp2 = Mult_32_16(hBWE_TD->prev_ener_fx, hBWE_TD->prev_GainShape_fx); /* (2*st_fx->prev_ener_fx_Q) */ - tmp = sub(shl(Q_bwe_exc, 1), shl(st_fx->prev_ener_fx_Q, 1)); + L_tmp1 = Mult_32_16( ener_tmp[i], GainShape_tmp[i] ); /* (2*Q_bwe_exc) */ + L_tmp2 = Mult_32_16( hBWE_TD->prev_ener_fx, hBWE_TD->prev_GainShape_fx ); /* (2*st_fx->prev_ener_fx_Q) */ + tmp = sub( shl( Q_bwe_exc, 1 ), shl( st_fx->prev_ener_fx_Q, 1 ) ); #ifdef BASOP_NOGLOB L_tmp2 = L_shl_sat( L_tmp2, tmp ); /* new Q = (2*Q_bwe_exc) */ #else - L_tmp2 = L_shl( L_tmp2, tmp ); /* new Q = (2*Q_bwe_exc) */ + L_tmp2 = L_shl( L_tmp2, tmp ); /* new Q = (2*Q_bwe_exc) */ #endif - IF (GT_32(L_tmp1,L_tmp2)) + IF( GT_32( L_tmp1, L_tmp2 ) ) { /*GainShape_tmp_fx[i] = 0.5f*(L_tmp2/ener_tmp_fx[i] + GainShape_tmp_fx[i]);*/ /* tmp = L_tmp2/ener_tmp_fx[i]*/ L_tmp = L_tmp2; - if(L_tmp2 < 0) + if ( L_tmp2 < 0 ) { - L_tmp = L_negate(L_tmp2); + L_tmp = L_negate( L_tmp2 ); } - expb = norm_l(L_tmp); + expb = norm_l( L_tmp ); #ifdef BASOP_NOGLOB fracb = round_fx_sat( L_shl_sat( L_tmp, expb ) ); #else fracb = round_fx( L_shl( L_tmp, expb ) ); #endif - expb = 30-expb; /* - (2*Q_bwe_exc_ext); */ + expb = 30 - expb; /* - (2*Q_bwe_exc_ext); */ - expa = norm_l(ener_tmp[i]); - fraca = extract_h(L_shl(ener_tmp[i],expa)); - expa = 30-expa ; + expa = norm_l( ener_tmp[i] ); + fraca = extract_h( L_shl( ener_tmp[i], expa ) ); + expa = 30 - expa; - scale = shr(sub(fraca,fracb),15); - fracb = shl(fracb,scale); - expb = sub(expb,scale); + scale = shr( sub( fraca, fracb ), 15 ); + fracb = shl( fracb, scale ); + expb = sub( expb, scale ); - tmp = div_s(fracb,fraca); - exp = sub(sub(expb,expa),1); - tmp = shl(tmp,exp); - GainShape_tmp[i] = add(tmp,shr(GainShape_tmp[i],1));/* Q15 */ + tmp = div_s( fracb, fraca ); + exp = sub( sub( expb, expa ), 1 ); + tmp = shl( tmp, exp ); + GainShape_tmp[i] = add( tmp, shr( GainShape_tmp[i], 1 ) ); /* Q15 */ } hBWE_TD->prev_ener_fx = ener_tmp[i]; hBWE_TD->prev_GainShape_fx = GainShape_tmp[i]; st_fx->prev_ener_fx_Q = Q_bwe_exc; } - FOR(i=0; isyn_overlap_fx, - GainShape, /* Q15 */ - GainFrame, /* Q18 */ + shaped_shb_excitation, /* i/o: Q_bwe_exc */ + hBWE_TD->syn_overlap_fx, + GainShape, /* Q15 */ + GainFrame, /* Q18 */ window_shb_fx, subwin_shb_fx, - &Q_bwe_exc - , &Qx - , n_mem3 - , st_fx->prev_Q_bwe_syn2 - ); + &Q_bwe_exc, &Qx, n_mem3, st_fx->prev_Q_bwe_syn2 ); /* i: GainShape Q15 */ /* i: GainFrame Q18 */ /* i: shaped_shb_excitation Q_bwe_exc */ @@ -3032,7 +3019,7 @@ void swb_tbe_dec_fx( max = 0; - FOR( i = 0; i < L_FRAME16k; i++ ) + FOR( i = 0; i < L_FRAME16k; i++ ) { max = s_max( max, shaped_shb_excitation[i] ); /* Q0 */ } @@ -3048,45 +3035,47 @@ void swb_tbe_dec_fx( { n = norm_s( max ); max = 0; - FOR( i = 0; i < L_FRAME16k; i++ ) + FOR( i = 0; i < L_FRAME16k; i++ ) { #ifdef BASOP_NOGLOB - shaped_shb_excitation_frac[i] = shl_sat( shaped_shb_excitation[i], n ); /*Q_bwe_exc+n*/ move16(); + shaped_shb_excitation_frac[i] = shl_sat( shaped_shb_excitation[i], n ); /*Q_bwe_exc+n*/ + move16(); #else - shaped_shb_excitation_frac[i] = shl( shaped_shb_excitation[i], n ); /*Q_bwe_exc+n*/ move16(); + shaped_shb_excitation_frac[i] = shl( shaped_shb_excitation[i], n ); /*Q_bwe_exc+n*/ + move16(); #endif } curr_frame_pow = 0; - FOR( i = 0; i < L_FRAME16k; i++ ) + FOR( i = 0; i < L_FRAME16k; i++ ) { L_tmp = L_mult0( shaped_shb_excitation_frac[i], shaped_shb_excitation_frac[i] ); /*2*(Q_bwe_exc+n)*/ - curr_frame_pow = L_add( curr_frame_pow, L_shr( L_tmp, 9 ) ); /*2*(Q_bwe_exc+n)-9*/ + curr_frame_pow = L_add( curr_frame_pow, L_shr( L_tmp, 9 ) ); /*2*(Q_bwe_exc+n)-9*/ } } - curr_frame_pow_exp = sub(shl(add( Q_bwe_exc, n ), 1), 9); + curr_frame_pow_exp = sub( shl( add( Q_bwe_exc, n ), 1 ), 9 ); - tmp=sub( st_fx->prev_frame_pow_exp, curr_frame_pow_exp ); - IF( tmp > 0 ) /* shifting prev */ + tmp = sub( st_fx->prev_frame_pow_exp, curr_frame_pow_exp ); + IF( tmp > 0 ) /* shifting prev */ { - IF (GT_16(tmp,32)) + IF( GT_16( tmp, 32 ) ) { - st_fx->prev_frame_pow_exp = add(curr_frame_pow_exp,32); + st_fx->prev_frame_pow_exp = add( curr_frame_pow_exp, 32 ); tmp = 32; } - hBWE_TD->prev_swb_bwe_frame_pow_fx = L_shr(hBWE_TD->prev_swb_bwe_frame_pow_fx, tmp); + hBWE_TD->prev_swb_bwe_frame_pow_fx = L_shr( hBWE_TD->prev_swb_bwe_frame_pow_fx, tmp ); st_fx->prev_frame_pow_exp = curr_frame_pow_exp; move16(); } - ELSE /* shifting curr */ + ELSE /* shifting curr */ { - IF (LT_16(tmp,-32)) + IF( LT_16( tmp, -32 ) ) { - curr_frame_pow_exp = sub(st_fx->prev_frame_pow_exp,32); + curr_frame_pow_exp = sub( st_fx->prev_frame_pow_exp, 32 ); tmp = -32; } - curr_frame_pow = L_shr(curr_frame_pow, -tmp); + curr_frame_pow = L_shr( curr_frame_pow, -tmp ); curr_frame_pow_exp = st_fx->prev_frame_pow_exp; } test(); @@ -3097,10 +3086,10 @@ void swb_tbe_dec_fx( test(); test(); - IF( ( GT_32( L_shr( curr_frame_pow, 1 ), hBWE_TD->prev_swb_bwe_frame_pow_fx ))&& - ( GT_32(hBWE_TD->prev_swb_bwe_frame_pow_fx, L_tmp ) ) && EQ_16(st_fx->prev_coder_type,UNVOICED) ) + IF( ( GT_32( L_shr( curr_frame_pow, 1 ), hBWE_TD->prev_swb_bwe_frame_pow_fx ) ) && + ( GT_32( hBWE_TD->prev_swb_bwe_frame_pow_fx, L_tmp ) ) && EQ_16( st_fx->prev_coder_type, UNVOICED ) ) { - L_tmp = root_a_over_b_fx(hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); + L_tmp = root_a_over_b_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); scale = round_fx( L_shl( L_tmp, exp ) ); /*Q15*/ L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); @@ -3111,7 +3100,7 @@ void swb_tbe_dec_fx( ELSE { scale = temp = 32767; - move16();/*Q15*/ + move16(); /*Q15*/ } FOR( j = 0; j < 8; j++ ) { @@ -3121,7 +3110,7 @@ void swb_tbe_dec_fx( move16(); FOR( i = 0; i < L_FRAME16k / 8; i++ ) { - shaped_shb_excitation[i + j*L_FRAME16k/8] = mult_r( shaped_shb_excitation[i + j*L_FRAME16k/8],scale ); + shaped_shb_excitation[i + j * L_FRAME16k / 8] = mult_r( shaped_shb_excitation[i + j * L_FRAME16k / 8], scale ); move16(); } @@ -3129,7 +3118,7 @@ void swb_tbe_dec_fx( { /* scale <= temp, due to scale = sqrt( st->prev_swb_bwe_frame_pow_fx/curr_frame_pow ), temp = sqrt( scale, 1.f/8.f ) and curr_frame_pow > st->prev_swb_bwe_frame_pow_fx -> scale <= 1.0, sqrt(scale, 1.f/8.f) >= scale */ - IF( LT_16( scale, temp )) + IF( LT_16( scale, temp ) ) { scale = div_s( scale, temp ); } @@ -3151,9 +3140,9 @@ void swb_tbe_dec_fx( IF( st_fx->bfi ) { scale = temp = 4096; - move16();/*Q12*/ + move16(); /*Q12*/ - IF (EQ_16(st_fx->nbLostCmpt,1)) + IF( EQ_16( st_fx->nbLostCmpt, 1 ) ) { test(); test(); @@ -3163,82 +3152,82 @@ void swb_tbe_dec_fx( test(); test(); test(); - IF( GT_32(curr_frame_pow, hBWE_TD->prev_swb_bwe_frame_pow_fx)&& - NE_16(st_fx->prev_coder_type, UNVOICED) && - NE_16(st_fx->last_good,UNVOICED_CLAS) ) + IF( GT_32( curr_frame_pow, hBWE_TD->prev_swb_bwe_frame_pow_fx ) && + NE_16( st_fx->prev_coder_type, UNVOICED ) && + NE_16( st_fx->last_good, UNVOICED_CLAS ) ) { - L_tmp = root_a_over_b_fx(hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); /*31 - exp*/ - scale = round_fx( L_shl( L_tmp, sub(exp,3))); /*Q12*/ + L_tmp = root_a_over_b_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); /*31 - exp*/ + scale = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); - temp = round_fx( L_shl( L_tmp, sub(exp,3))); /*Q12*/ + temp = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ } - ELSE IF( LT_32(curr_frame_pow, L_shr(hBWE_TD->prev_swb_bwe_frame_pow_fx,1))&&EQ_16(st_fx->nbLostCmpt,1)&& - (GT_32(st_fx->enerLL_fx, L_shr( st_fx->prev_enerLL_fx,1)) || GT_32(st_fx->enerLH_fx, L_shr(st_fx->prev_enerLH_fx,1)) ) && - (EQ_16(st_fx->prev_coder_type ,UNVOICED) || EQ_16(st_fx->last_good, UNVOICED_CLAS) || GT_16(hBWE_TD->tilt_swb_fec_fx , 10240) )) + ELSE IF( LT_32( curr_frame_pow, L_shr( hBWE_TD->prev_swb_bwe_frame_pow_fx, 1 ) ) && EQ_16( st_fx->nbLostCmpt, 1 ) && + ( GT_32( st_fx->enerLL_fx, L_shr( st_fx->prev_enerLL_fx, 1 ) ) || GT_32( st_fx->enerLH_fx, L_shr( st_fx->prev_enerLH_fx, 1 ) ) ) && + ( EQ_16( st_fx->prev_coder_type, UNVOICED ) || EQ_16( st_fx->last_good, UNVOICED_CLAS ) || GT_16( hBWE_TD->tilt_swb_fec_fx, 10240 ) ) ) { - L_tmp = root_a_over_b_fx(hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); + L_tmp = root_a_over_b_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); #ifdef BASOP_NOGLOB - scale = round_fx_sat( L_shl_sat( L_tmp, sub(exp,3) ) ); /*Q12*/ + scale = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ #else - scale = round_fx( L_shl( L_tmp, sub(exp,3) ) ); /*Q12*/ + scale = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ #endif L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); - temp = round_fx( L_shl( L_tmp, sub(exp,3) ) ); /*Q12*/ + temp = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ } } - ELSE IF (GT_16(st_fx->nbLostCmpt,1)) + ELSE IF( GT_16( st_fx->nbLostCmpt, 1 ) ) { test(); test(); test(); test(); test(); - IF( GT_32(curr_frame_pow , hBWE_TD->prev_swb_bwe_frame_pow_fx)) + IF( GT_32( curr_frame_pow, hBWE_TD->prev_swb_bwe_frame_pow_fx ) ) { - L_tmp = root_a_over_b_fx(hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); - scale = round_fx( L_shl( L_tmp, sub(exp,3) ) ); /*Q12*/ + L_tmp = root_a_over_b_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); + scale = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); #ifdef BASOP_NOGLOB - temp = round_fx_sat( L_shl_sat( L_tmp, sub(exp,3) ) ); /*Q12*/ + temp = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ #else - temp = round_fx( L_shl( L_tmp, sub(exp,3) ) ); /*Q12*/ + temp = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ #endif } - ELSE IF( LT_32(curr_frame_pow, L_shr(hBWE_TD->prev_swb_bwe_frame_pow_fx,1))&& - (GT_32(st_fx->enerLL_fx, L_shr( st_fx->prev_enerLL_fx,1)) || GT_32(st_fx->enerLH_fx, L_shr(st_fx->prev_enerLH_fx,1)) ) && - (st_fx->prev_coder_type == UNVOICED || st_fx->last_good == UNVOICED_CLAS || GT_16(hBWE_TD->tilt_swb_fec_fx , 10240)) ) + ELSE IF( LT_32( curr_frame_pow, L_shr( hBWE_TD->prev_swb_bwe_frame_pow_fx, 1 ) ) && + ( GT_32( st_fx->enerLL_fx, L_shr( st_fx->prev_enerLL_fx, 1 ) ) || GT_32( st_fx->enerLH_fx, L_shr( st_fx->prev_enerLH_fx, 1 ) ) ) && + ( st_fx->prev_coder_type == UNVOICED || st_fx->last_good == UNVOICED_CLAS || GT_16( hBWE_TD->tilt_swb_fec_fx, 10240 ) ) ) { - L_tmp = root_a_over_b_fx(hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); + L_tmp = root_a_over_b_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); #ifdef BASOP_NOGLOB - L_tmp =L_min(L_tmp,L_shl_sat(2,(31 - exp)));/*31 - exp*/ + L_tmp = L_min( L_tmp, L_shl_sat( 2, ( 31 - exp ) ) ); /*31 - exp*/ #else - L_tmp =L_min(L_tmp,L_shl(2,(31 - exp)));/*31 - exp*/ + L_tmp = L_min( L_tmp, L_shl( 2, ( 31 - exp ) ) ); /*31 - exp*/ #endif - scale = round_fx( L_shl( L_tmp, sub(exp,3) )); /*Q12*/ + scale = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); - temp = round_fx( L_shl( L_tmp, sub(exp,3) ) ); /*Q12*/ + temp = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ } } FOR( j = 0; j < 8; j++ ) { #ifdef BASOP_NOGLOB - GainShape[2 * j] = shl_sat(mult_r( GainShape[2 * j], scale ),3); + GainShape[2 * j] = shl_sat( mult_r( GainShape[2 * j], scale ), 3 ); #else - GainShape[2 * j] = shl(mult_r( GainShape[2 * j], scale ),3); + GainShape[2 * j] = shl( mult_r( GainShape[2 * j], scale ), 3 ); #endif move16(); /* 15 +12 +3-15 =15*/ #ifdef BASOP_NOGLOB - GainShape[2 * j + 1] = shl_sat(mult_r( GainShape[2 * j + 1], scale ),3); + GainShape[2 * j + 1] = shl_sat( mult_r( GainShape[2 * j + 1], scale ), 3 ); #else - GainShape[2 * j + 1] = shl(mult_r( GainShape[2 * j + 1], scale ),3); + GainShape[2 * j + 1] = shl( mult_r( GainShape[2 * j + 1], scale ), 3 ); #endif move16(); FOR( i = 0; i < 40; i++ ) @@ -3246,23 +3235,23 @@ void swb_tbe_dec_fx( #ifdef BASOP_NOGLOB shaped_shb_excitation[add( i, i_mult( j, 40 ) )] = shl_sat( mult_r( shaped_shb_excitation[add( i, i_mult( j, 40 ) )], scale ), 3 ); #else - shaped_shb_excitation[add(i,i_mult(j,40))] = shl(mult_r( shaped_shb_excitation[add(i,i_mult(j,40))], scale) ,3); + shaped_shb_excitation[add( i, i_mult( j, 40 ) )] = shl( mult_r( shaped_shb_excitation[add( i, i_mult( j, 40 ) )], scale ), 3 ); #endif move16(); /* Q_bwe_exc +12+3 -15 =Q_bwe_exc*/ } IF( temp > 0 ) { - IF( LT_16( scale, temp )) + IF( LT_16( scale, temp ) ) { - scale = shr(div_s( scale, temp ),3); + scale = shr( div_s( scale, temp ), 3 ); } ELSE { - tmp1 = sub(norm_s(scale), 1); - tmp2 = norm_s(temp); - scale = div_s( shl(scale, tmp1), shl(temp, tmp2) ); - scale = shr(scale, add(sub(tmp1, tmp2), 3)); + tmp1 = sub( norm_s( scale ), 1 ); + tmp2 = norm_s( temp ); + scale = div_s( shl( scale, tmp1 ), shl( temp, tmp2 ) ); + scale = shr( scale, add( sub( tmp1, tmp2 ), 3 ) ); } } ELSE @@ -3286,7 +3275,7 @@ void swb_tbe_dec_fx( { prev_ener_shb64 = W_mac0_16_16( prev_ener_shb64, shaped_shb_excitation[i], shaped_shb_excitation[i] ); /* Q0 */ } - L_prev_ener_shb = W_sat_l(prev_ener_shb64); + L_prev_ener_shb = W_sat_l( prev_ener_shb64 ); } @@ -3312,7 +3301,7 @@ void swb_tbe_dec_fx( } /* st->prev_SWB_fenv[i] = sqrt(curr_frame_pow/L_FRAME16k); */ L_tmp = Mult_32_16( curr_frame_pow, 26214 ); /* curr_frame_pow_exp+8; 26214=(1/L_FRAME16k) in Q23 */ - tmp =0; + tmp = 0; IF( L_tmp != 0 ) { exp = norm_l( L_tmp ); @@ -3325,37 +3314,37 @@ void swb_tbe_dec_fx( #ifdef BASOP_NOGLOB tmp = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 14 ) ) ); /* Q1 */ #else - tmp = round_fx( L_shl( L_tmp, sub( exp, 14 ) ) ); /* Q1 */ + tmp = round_fx( L_shl( L_tmp, sub( exp, 14 ) ) ); /* Q1 */ #endif } - set16_fx(st_fx->prev_SWB_fenv_fx, tmp, SWB_FENV); /* Q1 */ + set16_fx( st_fx->prev_SWB_fenv_fx, tmp, SWB_FENV ); /* Q1 */ /* rescale the memories if Q_bwe_exc is different from previous frame */ sc = sub( Q_bwe_exc, st_fx->prev_Q_bwe_syn2 ); IF( sc != 0 ) { - FOR( i = 0; i < 2*ALLPASSSECTIONS_STEEP; i++ ) + FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ ) { - hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i] = shl(hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i], sc ); + hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i] = shl( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i], sc ); move16(); } - IF(EQ_16(st_fx->L_frame, L_FRAME)) + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { FOR( i = 0; i < HILBERT_MEM_SIZE; i++ ) { - hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i] = L_shl(hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i], sc ); + hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i] = L_shl( hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i], sc ); move32(); } } IF( st_fx->output_Fs == 48000 ) { - Scale_sig(hBWE_TD->int_3_over_2_tbemem_dec_fx, INTERP_3_2_MEM_LEN, sc); + Scale_sig( hBWE_TD->int_3_over_2_tbemem_dec_fx, INTERP_3_2_MEM_LEN, sc ); } IF( st_fx->output_Fs == 16000 ) { - Scale_sig(hBWE_TD->mem_resamp_HB_32k_fx, 2*ALLPASSSECTIONS_STEEP + 1, sc); + Scale_sig( hBWE_TD->mem_resamp_HB_32k_fx, 2 * ALLPASSSECTIONS_STEEP + 1, sc ); } } /* i: shaped_shb_excitation[320] in (Q_bwe_exc) */ @@ -3363,87 +3352,87 @@ void swb_tbe_dec_fx( /* i/o: st_fx->genSHBsynth_state_lsyn_filt_shb_local_fx in (Q_bwe_exc) */ /* o: error in (Qx) */ GenSHBSynth_fx( shaped_shb_excitation, error, hBWE_TD->genSHBsynth_Hilbert_Mem_fx, - hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, st_fx->L_frame, &(hBWE_TD->syn_dm_phase ) ); + hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, st_fx->L_frame, &( hBWE_TD->syn_dm_phase ) ); Copy( error + L_FRAME32k - L_SHB_TRANSITION_LENGTH, hBWE_TD->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH ); /* resample SHB synthesis (if needed) and scale down */ synth_scale_fx = 32767; move16(); /* 1.0 in Q15 */ - if(EQ_16(st_fx->codec_mode,MODE1)) + if ( EQ_16( st_fx->codec_mode, MODE1 ) ) { synth_scale_fx = 29491; move16(); /* 0.9 in Q15 */ } - IF( EQ_32(st_fx->output_Fs, 48000)) + IF( EQ_32( st_fx->output_Fs, 48000 ) ) { - IF( EQ_32(st_fx->extl,FB_TBE)) + IF( EQ_32( st_fx->extl, FB_TBE ) ) { tmp = norm_l( GainFrame ); - if(GainFrame == 0) + if ( GainFrame == 0 ) { tmp = 31; } - L_tmp = L_shl(GainFrame,tmp);/* 18 + tmp */ + L_tmp = L_shl( GainFrame, tmp ); /* 18 + tmp */ - tmp1 =0; + tmp1 = 0; FOR( i = 0; i < L_FRAME16k; i++ ) { L_tmp1 = Mult_32_16( L_tmp, GainShape[NUM_SHB_SUBFR * i / L_FRAME16k] ); /* Q : 18 + tmp +15 -15*/ - White_exc16k[i] = round_fx( Mult_32_16( L_tmp1, White_exc16k[i] ) );/* 18 + tmp +*Q_white_exc -15 -16 */ - tmp1 = s_max(tmp1,abs_s(White_exc16k[i])); + White_exc16k[i] = round_fx( Mult_32_16( L_tmp1, White_exc16k[i] ) ); /* 18 + tmp +*Q_white_exc -15 -16 */ + tmp1 = s_max( tmp1, abs_s( White_exc16k[i] ) ); } - *Q_white_exc = sub(add(*Q_white_exc, tmp),13); /* *Q_white_exc + 18 + tmp -15 -16 */ + *Q_white_exc = sub( add( *Q_white_exc, tmp ), 13 ); /* *Q_white_exc + 18 + tmp -15 -16 */ tmp = norm_s( tmp1 ); - if(tmp1 == 0) + if ( tmp1 == 0 ) { tmp = 15; } - FOR(i=0; iint_3_over_2_tbemem_dec_fx, allpass_poles_3_ov_2 ); } - ELSE IF( EQ_32(st_fx->output_Fs, 32000)) + ELSE IF( EQ_32( st_fx->output_Fs, 32000 ) ) { - IF( NE_16(synth_scale_fx,32767)) /* 1.0 in Q15 */ + IF( NE_16( synth_scale_fx, 32767 ) ) /* 1.0 in Q15 */ { FOR( i = 0; i < L_FRAME32k; i++ ) { synth[i] = mult_r( synth_scale_fx, error[i] ); - move16();/*Qx*/ + move16(); /*Qx*/ } } ELSE { - Copy(error, synth, L_FRAME32k); + Copy( error, synth, L_FRAME32k ); } } - ELSE IF( EQ_32(st_fx->output_Fs, 16000)) + ELSE IF( EQ_32( st_fx->output_Fs, 16000 ) ) { - IF( NE_16(synth_scale_fx,32767)) /* 1.0 in Q15 */ + IF( NE_16( synth_scale_fx, 32767 ) ) /* 1.0 in Q15 */ { FOR( i = 0; i < L_FRAME32k; i++ ) { - error[i] = mult_r(error[i],synth_scale_fx); + error[i] = mult_r( error[i], synth_scale_fx ); move16(); } } @@ -3453,13 +3442,13 @@ void swb_tbe_dec_fx( /* Update previous frame parameters for FEC */ Copy( lsf_shb, hBWE_TD->lsp_prevfrm_fx, LPC_SHB_ORDER ); - IF(EQ_16(st_fx->codec_mode, MODE1)) + IF( EQ_16( st_fx->codec_mode, MODE1 ) ) { hBWE_TD->GainFrame_prevfrm_fx = GainFrame; move16(); /*Q18*/ hBWE_TD->tilt_swb_fec_fx = tilt_swb_fec; - if( !st_fx->bfi ) + if ( !st_fx->bfi ) { hBWE_TD->GainAttn_fx = 32767; move16(); @@ -3478,8 +3467,8 @@ void swb_tbe_dec_fx( } } - hBWE_TD->prev_ener_fx = ener_tmp[NUM_SHB_SUBGAINS-1]; - hBWE_TD->prev_GainShape_fx = GainShape[NUM_SHB_SUBFR-1]; + hBWE_TD->prev_ener_fx = ener_tmp[NUM_SHB_SUBGAINS - 1]; + hBWE_TD->prev_GainShape_fx = GainShape[NUM_SHB_SUBFR - 1]; *Q_synth = Q_bwe_exc; move16(); st_fx->prev_Q_bwe_syn2 = Q_bwe_exc; @@ -3492,10 +3481,10 @@ void swb_tbe_dec_fx( static void gradientGainShape( Decoder_State *st_fx, Word16 *GainShape, - Word32 *GainFrame) + Word32 *GainFrame ) { - Word16 i,j,tmp; - Word16 GainShapeTemp[NUM_SHB_SUBFR/4]; + Word16 i, j, tmp; + Word16 GainShapeTemp[NUM_SHB_SUBFR / 4]; Word16 GainGrad0[3]; Word16 GainGrad1[3]; Word16 GainGradFEC[4]; @@ -3506,9 +3495,9 @@ static void gradientGainShape( FOR( j = 0; j < 3; j++ ) { GainGrad0[j] = sub( shr( st_fx->GainShape_Delay[j + 1], 1 ), shr( st_fx->GainShape_Delay[j], 1 ) ); - move16();/* Q14 */ + move16(); /* Q14 */ GainGrad1[j] = sub( shr( st_fx->GainShape_Delay[j + 5], 1 ), shr( st_fx->GainShape_Delay[j + 4], 1 ) ); - move16();/* Q14 */ + move16(); /* Q14 */ GainGradFEC[j + 1] = add( mult_r( GainGrad0[j], 13107 ), mult_r( GainGrad1[j], 19660 ) ); move16(); /* Q14 */ } @@ -3517,8 +3506,8 @@ static void gradientGainShape( test(); test(); test(); - IF( ( ( GT_16( shr( GainGrad1[2], 1 ), GainGrad1[1] ))&&(GT_16(shr(GainGrad1[1],1),GainGrad1[0])))|| - ( ( LT_16( shr( GainGrad1[2], 1 ), GainGrad1[1] ) ) && ( LT_16( shr( GainGrad1[1], 1 ), GainGrad1[0] ) ) ) ) + IF( ( ( GT_16( shr( GainGrad1[2], 1 ), GainGrad1[1] ) ) && ( GT_16( shr( GainGrad1[1], 1 ), GainGrad1[0] ) ) ) || + ( ( LT_16( shr( GainGrad1[2], 1 ), GainGrad1[1] ) ) && ( LT_16( shr( GainGrad1[1], 1 ), GainGrad1[0] ) ) ) ) { GainGradFEC[0] = add( mult_r( GainGrad1[1], 3277 ), mult_r( GainGrad1[2], 29490 ) ); move16(); /* Q14 */ @@ -3547,35 +3536,35 @@ static void gradientGainShape( ELSE { GainShapeTemp[0] = shr( st_fx->GainShape_Delay[7], 1 ); - move16();/* Q14 */ + move16(); /* Q14 */ } /*Get the second the third and the fourth gainshape template*/ - tmp = shr( GainGrad1[2], 3 ); /* GainGrad1[2]/8 */ - tmp = mult_r( tmp, 26214 ); /* 0.8 in Q15 tmp*(8/10) */ + tmp = shr( GainGrad1[2], 3 ); /* GainGrad1[2]/8 */ + tmp = mult_r( tmp, 26214 ); /* 0.8 in Q15 tmp*(8/10) */ test(); - IF( ( GT_16( tmp, GainGrad1[1] ))&&GainGrad1[1]>0) + IF( ( GT_16( tmp, GainGrad1[1] ) ) && GainGrad1[1] > 0 ) { FOR( i = 1; i < NUM_SHB_SUBFR / 4; i++ ) { GainShapeTemp[i] = add( GainShapeTemp[i - 1], mult_r( GainGradFEC[i], 26214 ) ); move16(); /* GainShapeTemp[i-1] + 0.8* GainShapeTemp[i] */ - GainShapeTemp[i] = s_max( GainShapeTemp[i], 328/*0.01f Q15*/ ); + GainShapeTemp[i] = s_max( GainShapeTemp[i], 328 /*0.01f Q15*/ ); move16(); } } ELSE { test(); - IF( ( GT_16( tmp, GainGrad1[1] ))&&GainGrad1[1]<0) + IF( ( GT_16( tmp, GainGrad1[1] ) ) && GainGrad1[1] < 0 ) { FOR( i = 1; i < NUM_SHB_SUBFR / 4; i++ ) { GainShapeTemp[i] = add( GainShapeTemp[i - 1], mult_r( GainGradFEC[i], 6553 ) ); move16(); /* GainShapeTemp[i-1] + 0.8* GainShapeTemp[i] */ - GainShapeTemp[i] = s_max( GainShapeTemp[i], 328/*0.01f Q15*/ ); + GainShapeTemp[i] = s_max( GainShapeTemp[i], 328 /*0.01f Q15*/ ); move16(); /* Q14 */ } } @@ -3585,7 +3574,7 @@ static void gradientGainShape( { GainShapeTemp[i] = add( GainShapeTemp[i - 1], GainGradFEC[i] ); move16(); - GainShapeTemp[i] = s_max( GainShapeTemp[i], 328/*0.01f Q15*/ ); + GainShapeTemp[i] = s_max( GainShapeTemp[i], 328 /*0.01f Q15*/ ); move16(); } } @@ -3595,7 +3584,7 @@ static void gradientGainShape( test(); test(); test(); - IF( ( st_fx->prev_coder_type == UNVOICED || st_fx->last_good == UNVOICED_CLAS ) && st_fx->nbLostCmpt == 1 ) + IF( ( st_fx->prev_coder_type == UNVOICED || st_fx->last_good == UNVOICED_CLAS ) && st_fx->nbLostCmpt == 1 ) { FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) { @@ -3603,19 +3592,19 @@ static void gradientGainShape( { tmp = mult_r( GainShapeTemp[i], 19660 ); /* GainShapeTemp[i]*0.6 */ - IF( GT_16( 8192, tmp )) + IF( GT_16( 8192, tmp ) ) { - GainShape[i * 4 + j ] = shl( tmp, 2 ); + GainShape[i * 4 + j] = shl( tmp, 2 ); move16(); /* (GainShapeTemp[i]*0.6)>>1 */ } ELSE { - GainShape[i * 4 + j ] = 32767; + GainShape[i * 4 + j] = 32767; move16(); /* Clipping here to avoid the a huge change of the code due to gain shape change */ } } } - hBWE_TD->GainAttn_fx = mult_r(hBWE_TD->GainAttn_fx, 31129 ); + hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 31129 ); } ELSE IF( st_fx->prev_coder_type == UNVOICED || st_fx->last_good == UNVOICED_CLAS ) { @@ -3623,19 +3612,19 @@ static void gradientGainShape( { FOR( j = 0; j < 4; j++ ) { - IF( LT_16( GainShapeTemp[i], 16384 )) + IF( LT_16( GainShapeTemp[i], 16384 ) ) { - GainShape[i * 4 + j ] = shl( GainShapeTemp[i], 1 ); + GainShape[i * 4 + j] = shl( GainShapeTemp[i], 1 ); move16(); } ELSE { - GainShape[i * 4 + j ] = 32767 ; + GainShape[i * 4 + j] = 32767; move16(); } } } - hBWE_TD->GainAttn_fx = mult_r(hBWE_TD->GainAttn_fx, 31129 ); + hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 31129 ); } ELSE IF( st_fx->nbLostCmpt > 1 ) { @@ -3643,11 +3632,11 @@ static void gradientGainShape( { FOR( j = 0; j < 4; j++ ) { - GainShape[i * 4 + j ] = GainShapeTemp[i]; + GainShape[i * 4 + j] = GainShapeTemp[i]; move16(); } } - hBWE_TD->GainAttn_fx = mult_r(hBWE_TD->GainAttn_fx, 16384 ); + hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 16384 ); } ELSE { @@ -3655,7 +3644,7 @@ static void gradientGainShape( { FOR( j = 0; j < 4; j++ ) { - IF( LT_16( GainShapeTemp[i], 16384 )) + IF( LT_16( GainShapeTemp[i], 16384 ) ) { GainShape[i * 4 + j] = shl( GainShapeTemp[i], 1 ); move16(); @@ -3667,10 +3656,10 @@ static void gradientGainShape( } } } - hBWE_TD->GainAttn_fx = mult_r(hBWE_TD->GainAttn_fx, 27852 ); + hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 27852 ); } - *GainFrame = Mult_32_16(hBWE_TD->GainFrame_prevfrm_fx, hBWE_TD->GainAttn_fx ); /* Q18 */ + *GainFrame = Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, hBWE_TD->GainAttn_fx ); /* Q18 */ } /*-------------------------------------------------------------------* @@ -3681,8 +3670,8 @@ static void gradientGainShape( static void Dequant_lower_LSF_fx( - const Word16 lsf_idx[], /* i : LSF indices */ - Word16 lsf_q[] /* o : Quantized LSFs */ + const Word16 lsf_idx[], /* i : LSF indices */ + Word16 lsf_q[] /* o : Quantized LSFs */ ) { Word16 i; @@ -3705,9 +3694,9 @@ static void Dequant_lower_LSF_fx( *-------------------------------------------------------------------*/ static void Map_higher_LSF_fx( - Word16 lsf_q[], /* i/o : Quantized lower LSFs */ - const Word16 m, /* i : Mirroring point */ - const Word16 grid_in[] /* i : Input LSF smoohthing grid */ ) + Word16 lsf_q[], /* i/o : Quantized lower LSFs */ + const Word16 m, /* i : Mirroring point */ + const Word16 grid_in[] /* i : Input LSF smoohthing grid */ ) { Word16 lsf_map[NUM_MAP_LSF]; Word16 grid[NUM_MAP_LSF]; @@ -3723,7 +3712,7 @@ static void Map_higher_LSF_fx( move16(); } - IF( GT_16( m, MAX_LSF_FX_BY_2 )) + IF( GT_16( m, MAX_LSF_FX_BY_2 ) ) { offset = lsf_map[0]; move16(); @@ -3748,7 +3737,7 @@ static void Map_higher_LSF_fx( FOR( i = 0; i < NUM_MAP_LSF; i++ ) { lsf_smooth[i] = sub( mult_r( grid_smoothing_fx[i], grid[i] ), - mult_r( lsf_map[i], add( grid_smoothing_fx[i], -32768/*-1.0f Q15*/ ) ) ); + mult_r( lsf_map[i], add( grid_smoothing_fx[i], -32768 /*-1.0f Q15*/ ) ) ); move16(); } @@ -3762,11 +3751,10 @@ static void Map_higher_LSF_fx( } - - static void Dequant_mirror_point_fx( - const Word16 lsf_q[], /* i/o : Quantized lower LSFs */ - const Word16 m_idx, /* i : Mirror point index */ Word16* m /* i : Mirroring point */ ) + const Word16 lsf_q[], /* i/o : Quantized lower LSFs */ + const Word16 m_idx, + /* i : Mirror point index */ Word16 *m /* i : Mirroring point */ ) { *m = add( mirror_point_q_cb_fx[m_idx], lsf_q[NUM_Q_LSF - 1] ); move16(); @@ -3776,21 +3764,21 @@ static void Dequant_mirror_point_fx( Word16 dotp_loc( const Word16 x[], /* i : vector x[] */ const Word32 y[], /* i : vector y[] */ - const int16_t n /* i : vector length */ + const int16_t n /* i : vector length */ ) { Word16 i; Word32 suma; - Word16 guarded_bits = find_guarded_bits_fx(n); - suma = L_shr(Mpy_32_16_1(y[0], x[0]), guarded_bits); + Word16 guarded_bits = find_guarded_bits_fx( n ); + suma = L_shr( Mpy_32_16_1( y[0], x[0] ), guarded_bits ); - FOR(i = 1; i < n; i++) + FOR( i = 1; i < n; i++ ) { - suma = L_add(suma, L_shr(Mpy_32_16_1(y[i], x[i]), guarded_bits)); + suma = L_add( suma, L_shr( Mpy_32_16_1( y[i], x[i] ), guarded_bits ) ); } - suma = L_shl_sat(suma, guarded_bits); + suma = L_shl_sat( suma, guarded_bits ); - return extract_h(suma); + return extract_h( suma ); } void ivas_dequantizeSHBparams_fx_9_1( @@ -3804,7 +3792,7 @@ void ivas_dequantizeSHBparams_fx_9_1( Word32 *Q_shb_ener_sf, /* o : Q15 */ Word16 *Q_shb_res_gshape, /* o : Q14 */ Word16 *Q_mixFactors, /* o : Q15 */ - Word16 *MSFlag) + Word16 *MSFlag ) { Word16 i, j, idxLSF, idxSubGain, idxFrameGain; Word16 Q_combined_gains[NUM_SHB_SUBFR / 4]; @@ -3829,50 +3817,50 @@ void ivas_dequantizeSHBparams_fx_9_1( /* LSFs */ - IF(EQ_16(extl, WB_TBE)) + IF( EQ_16( extl, WB_TBE ) ) { - IF(EQ_32(extl_brate, WB_TBE_0k35)) + IF( EQ_32( extl_brate, WB_TBE_0k35 ) ) { - IF(EQ_16(st_fx->codec_mode, MODE2)) + IF( EQ_16( st_fx->codec_mode, MODE2 ) ) { idxFrameGain = hBWE_TD->gFrame_WB; idxLSF = hBWE_TD->lsf_WB; } ELSE { - idxFrameGain = get_next_indice(st_fx, NUM_BITS_SHB_FrameGain_LBR_WB); - idxLSF = get_next_indice(st_fx, NUM_BITS_LBR_WB_LSF); + idxFrameGain = get_next_indice( st_fx, NUM_BITS_SHB_FrameGain_LBR_WB ); + idxLSF = get_next_indice( st_fx, NUM_BITS_LBR_WB_LSF ); } - Copy(lbr_wb_bwe_lsfvq_cbook_2bit_fx + idxLSF * LPC_SHB_ORDER_LBR_WB, Q_lsf, LPC_SHB_ORDER_LBR_WB); - set16_fx(Q_subgain, RECIP_ROOT_EIGHT_FX, NUM_SHB_SUBFR / 2); - Copy32(SHBCB_FrameGain16_fx + idxFrameGain, Q_framegrain, 1); + Copy( lbr_wb_bwe_lsfvq_cbook_2bit_fx + idxLSF * LPC_SHB_ORDER_LBR_WB, Q_lsf, LPC_SHB_ORDER_LBR_WB ); + set16_fx( Q_subgain, RECIP_ROOT_EIGHT_FX, NUM_SHB_SUBFR / 2 ); + Copy32( SHBCB_FrameGain16_fx + idxFrameGain, Q_framegrain, 1 ); } ELSE { - *uv_flag = (Word16)get_next_indice(st_fx, 1); - idxSubGain = (Word16)get_next_indice(st_fx, NUM_BITS_SHB_SUBGAINS); + *uv_flag = (Word16) get_next_indice( st_fx, 1 ); + idxSubGain = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_SUBGAINS ); move16(); - idxFrameGain = (Word16)get_next_indice(st_fx, NUM_BITS_SHB_FrameGain); + idxFrameGain = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_FrameGain ); move16(); - idxLSF = (Word16)get_next_indice(st_fx, NUM_BITS_WB_LSF); + idxLSF = (Word16) get_next_indice( st_fx, NUM_BITS_WB_LSF ); move16(); - Copy(wb_bwe_lsfvq_cbook_8bit_fx + idxLSF * LPC_SHB_ORDER_WB, Q_lsf, LPC_SHB_ORDER_WB); - Copy(HBCB_SubGain5bit_fx + idxSubGain * NUM_SHB_SUBFR / 4, Q_combined_gains, NUM_SHB_SUBFR / 4); + Copy( wb_bwe_lsfvq_cbook_8bit_fx + idxLSF * LPC_SHB_ORDER_WB, Q_lsf, LPC_SHB_ORDER_WB ); + Copy( HBCB_SubGain5bit_fx + idxSubGain * NUM_SHB_SUBFR / 4, Q_combined_gains, NUM_SHB_SUBFR / 4 ); - FOR(i = 0; i < NUM_SHB_SUBFR / 4; i++) + FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) { - L_tmp = L_mult(Q_combined_gains[i], 21771); /*Q26 0.166096 in Q17 */ - L_tmp = L_shr(L_tmp, 10); - frac = L_Extract_lc(L_tmp, &exp); - tmp = extract_l(Pow2(14, frac)); /* Put 14 as exponent so that */ + L_tmp = L_mult( Q_combined_gains[i], 21771 ); /*Q26 0.166096 in Q17 */ + L_tmp = L_shr( L_tmp, 10 ); + frac = L_Extract_lc( L_tmp, &exp ); + tmp = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ - Q_combined_gains[i] = shl(tmp, add(exp, 1)); /* Q15 */ + Q_combined_gains[i] = shl( tmp, add( exp, 1 ) ); /* Q15 */ } - FOR(i = 0; i < NUM_SHB_SUBFR / 2; i += 2) + FOR( i = 0; i < NUM_SHB_SUBFR / 2; i += 2 ) { Q_subgain[i] = Q_combined_gains[i / 2]; // Q15 move16(); @@ -3881,19 +3869,19 @@ void ivas_dequantizeSHBparams_fx_9_1( } /* frame gain */ - Copy32(SHBCB_FrameGain64_fx + idxFrameGain, Q_framegrain, 1); + Copy32( SHBCB_FrameGain64_fx + idxFrameGain, Q_framegrain, 1 ); } } ELSE /* SWB TBE DEC */ { - IF(EQ_16(st_fx->codec_mode, MODE2)) + IF( EQ_16( st_fx->codec_mode, MODE2 ) ) { idxSubGain = hBWE_TD->idxSubGains; idxFrameGain = hBWE_TD->idxFrameGain; } ELSE { - idxSubGain = (Word16)get_next_indice(st_fx, NUM_BITS_SHB_SUBGAINS); + idxSubGain = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_SUBGAINS ); IF( st_fx->extl_brate == SWB_TBE_1k75 ) { idxFrameGain = get_next_indice( st_fx, NUM_BITS_SHB_FRAMEGAIN_1k75 ); @@ -3904,284 +3892,285 @@ void ivas_dequantizeSHBparams_fx_9_1( } } - /* Multi Source Flag */ - IF(st_fx->element_mode >= IVAS_CPE_DFT && !(st_fx->element_mode == IVAS_CPE_TD && st_fx->tdm_LRTD_flag)) + /* Multi Source Flag */ + IF( st_fx->element_mode >= IVAS_CPE_DFT && !( st_fx->element_mode == IVAS_CPE_TD && st_fx->tdm_LRTD_flag ) ) + { + *MSFlag = get_next_indice( st_fx, STEREO_ICBWE_MSFLAG_BITS ); + } + ELSE + { + *MSFlag = 0; + } + test(); + IF( st_fx->extl_brate >= SWB_TBE_2k8 ) + { + IF( EQ_16( st_fx->codec_mode, MODE2 ) ) { - *MSFlag = get_next_indice(st_fx, STEREO_ICBWE_MSFLAG_BITS); + idx_shb_fr_gain = hBWE_TD->idx_shb_fr_gain; } ELSE { - *MSFlag = 0; + idx_shb_fr_gain = get_next_indice( st_fx, NUM_BITS_SHB_ENER_SF ); } - test(); - IF(st_fx->extl_brate >= SWB_TBE_2k8) + temp_shb_ener_sf_fx = usdequant_fx( idx_shb_fr_gain, 0, 86 ); /* 86 = 0.042f in Q11 = Qin-1 */ + /* o: temp_shb_ener_sf_fx in Q12 */ + + /* *Q_shb_ener_sf = Pow(10.0, temp_shb_ener_sf_fx ); */ + /* = pow(2, 3.321928*temp_shb_ener_sf_fx) */ + L_tmp = L_mult( temp_shb_ener_sf_fx, 27213 ); /* 3.321928 in Q13 -> L_tmp in Q12+Q13+1 = Q26 */ + L_tmp = L_shl( L_tmp, -10 ); /* bring L_tmp from Q26 to Q16 */ + frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent */ + L_tmp = Pow2( 14, frac ); + *Q_shb_ener_sf = L_shl( L_tmp, exp - 14 + 0 ); /* In Q_ener: 2*Q_shb+1, Q_shb = 0; */ + + FOR( i = 0; i < 5; i++ ) { - IF(EQ_16(st_fx->codec_mode, MODE2)) + IF( EQ_16( st_fx->codec_mode, MODE2 ) ) { - idx_shb_fr_gain = hBWE_TD->idx_shb_fr_gain; + idx_res_gs[i] = hBWE_TD->idx_res_gs[i]; + move16(); } ELSE { - idx_shb_fr_gain = get_next_indice(st_fx, NUM_BITS_SHB_ENER_SF); - } - temp_shb_ener_sf_fx = usdequant_fx(idx_shb_fr_gain, 0, 86); /* 86 = 0.042f in Q11 = Qin-1 */ - /* o: temp_shb_ener_sf_fx in Q12 */ - - /* *Q_shb_ener_sf = Pow(10.0, temp_shb_ener_sf_fx ); */ - /* = pow(2, 3.321928*temp_shb_ener_sf_fx) */ - L_tmp = L_mult(temp_shb_ener_sf_fx, 27213); /* 3.321928 in Q13 -> L_tmp in Q12+Q13+1 = Q26 */ - L_tmp = L_shl(L_tmp, -10); /* bring L_tmp from Q26 to Q16 */ - frac = L_Extract_lc(L_tmp, &exp); /* Extract exponent */ - L_tmp = Pow2(14, frac); - *Q_shb_ener_sf = L_shl(L_tmp, exp - 14 + 0); /* In Q_ener: 2*Q_shb+1, Q_shb = 0; */ - - FOR(i = 0; i < 5; i++) - { - IF(EQ_16(st_fx->codec_mode, MODE2)) - { - idx_res_gs[i] = hBWE_TD->idx_res_gs[i]; - move16(); - } - ELSE - { - idx_res_gs[i] = get_next_indice(st_fx, NUM_BITS_SHB_RES_GS); - move16(); - } - Q_shb_res_gshape[i] = usdequant_fx(idx_res_gs[i], - 2048 /*0.125f Q14*/, /*2048 = 0.125 in Q14 */ - 1024 /*0.125f Q13*/ /*1024 = 0.125 in Q13 */ - ); + idx_res_gs[i] = get_next_indice( st_fx, NUM_BITS_SHB_RES_GS ); move16(); - /* o: Q_shb_res_gshape in Q14 */ } + Q_shb_res_gshape[i] = usdequant_fx( idx_res_gs[i], + 2048 /*0.125f Q14*/, /*2048 = 0.125 in Q14 */ + 1024 /*0.125f Q13*/ /*1024 = 0.125 in Q13 */ + ); + move16(); + /* o: Q_shb_res_gshape in Q14 */ + } - IF(EQ_16(st_fx->codec_mode, MODE2)) - { - idx_mixFac = hBWE_TD->idx_mixFac; - move16(); - } - ELSE - { - idx_mixFac = (Word16)get_next_indice(st_fx, NUM_BITS_SHB_VF); - } - *Q_mixFactors = usdequant_fx(idx_mixFac, 4096 /* 0.125 in Q15 */, 2048 /* 0.125 in Q14 */); + IF( EQ_16( st_fx->codec_mode, MODE2 ) ) + { + idx_mixFac = hBWE_TD->idx_mixFac; move16(); - /* o: Q_mixFactors in Q15 */ } ELSE { - *Q_shb_ener_sf = L_deposit_l(0); - IF( st_fx->extl_brate == SWB_TBE_1k10 || st_fx->extl_brate == SWB_TBE_1k75 ) + idx_mixFac = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_VF ); + } + *Q_mixFactors = usdequant_fx( idx_mixFac, 4096 /* 0.125 in Q15 */, 2048 /* 0.125 in Q14 */ ); + move16(); + /* o: Q_mixFactors in Q15 */ + } + ELSE + { + *Q_shb_ener_sf = L_deposit_l( 0 ); + IF( st_fx->extl_brate == SWB_TBE_1k10 || st_fx->extl_brate == SWB_TBE_1k75 ) + { + idx_mixFac = get_next_indice( st_fx, NUM_BITS_SHB_VF ); + *Q_mixFactors = usdequant_fx( idx_mixFac, 0 /* 0.0f in Q15*/, 2341 /*1.0f / ((1 << NUM_BITS_SHB_VF) - 1) in Q14*/ ); + } + ELSE + { + *Q_mixFactors = 0; + } + //*Q_mixFactors = 0; + move16(); + set16_fx( Q_shb_res_gshape, 0, 5 ); + } + + /* LSFs */ + + + test(); + test(); + test(); + test(); + test(); + IF( ( st_fx->extl_brate == SWB_TBE_0k95 || st_fx->extl_brate == SWB_TBE_1k10 ) && st_fx->codec_mode == MODE1 ) + { + set16_fx( lsf_idx, 0, 5 ); + lsf_idx[0] = get_next_indice( st_fx, 8 ); + grid_idx = 0; + m_idx = 0; + + Copy( swb_tbe_lsfvq_cbook_8b + lsf_idx[0] * LPC_SHB_ORDER, Q_lsf, LPC_SHB_ORDER ); + } + ELSE IF( st_fx->rf_flag == 0 && !( ( st_fx->element_mode == EVS_MONO && st_fx->total_brate == ACELP_9k60 ) || ( st_fx->element_mode == EVS_MONO && ( st_fx->total_brate == 0 ) && ( ( st_fx->last_total_brate == ACELP_9k60 ) || ( st_fx->last_total_brate == ACELP_13k20 && st_fx->rf_flag_last ) ) ) ) ) + { + IF( st_fx->extl_brate == SWB_TBE_1k75 ) + { + /* read multi-stage LVQ quantizer */ + IF( nbits >= 19 ) { - idx_mixFac = get_next_indice(st_fx, NUM_BITS_SHB_VF); - *Q_mixFactors = usdequant_fx(idx_mixFac, 0 /* 0.0f in Q15*/, 2341 /*1.0f / ((1 << NUM_BITS_SHB_VF) - 1) in Q14*/); + cb_stage = cb_LSF_BWE_fx[0]; } ELSE { - *Q_mixFactors = 0; + cb_stage = cb_LSF_BWE_fx[1]; } - //*Q_mixFactors = 0; - move16(); - set16_fx(Q_shb_res_gshape, 0, 5); - } + set16_fx( lsf_q, 0, LPC_SHB_ORDER ); - /* LSFs */ + /* VQ part */ + num_bits_lvq = config_LSF_BWE[( NUM_BITS_SHB_MSLVQ - nbits ) * 3]; + Idx = get_next_indice( st_fx, num_bits_lvq ); + v_add_16( lsf_q, cb_stage + Idx * 6, lsf_q, 6 ); + /* MSLVQ part */ + num_bits_lvq = nbits - num_bits_lvq - config_LSF_BWE[( NUM_BITS_SHB_MSLVQ - nbits ) * 3 + 2]; + predictor_bits = config_LSF_BWE[( NUM_BITS_SHB_MSLVQ - nbits ) * 3 + 2]; + Idx_pred = 0; - test(); - test(); - test(); - test(); - test(); - IF((st_fx->extl_brate == SWB_TBE_0k95 || st_fx->extl_brate == SWB_TBE_1k10) && st_fx->codec_mode == MODE1) + IF( num_bits_lvq == 16 ) { - set16_fx(lsf_idx, 0, 5); - lsf_idx[0] = get_next_indice(st_fx, 8); - grid_idx = 0; - m_idx = 0; - - Copy(swb_tbe_lsfvq_cbook_8b + lsf_idx[0] * LPC_SHB_ORDER, Q_lsf, LPC_SHB_ORDER); + /* MSLVQ part */ + Idx_lvq = get_next_indice( st_fx, num_bits_lvq - 1 ) + ( ( get_next_indice( st_fx, 1 ) ) << 15 ); + deindex_lvq_SHB_fx( Idx_lvq, out, num_bits_lvq, 0 ); } - ELSE IF(st_fx->rf_flag == 0 && !((st_fx->element_mode == EVS_MONO && st_fx->total_brate == ACELP_9k60) || (st_fx->element_mode == EVS_MONO && (st_fx->total_brate == 0) && ((st_fx->last_total_brate == ACELP_9k60) || (st_fx->last_total_brate == ACELP_13k20 && st_fx->rf_flag_last))))) + ELSE { - IF(st_fx->extl_brate == SWB_TBE_1k75) - { - /* read multi-stage LVQ quantizer */ - IF(nbits >= 19) - { - cb_stage = cb_LSF_BWE_fx[0]; - } - ELSE - { - cb_stage = cb_LSF_BWE_fx[1]; - } - set16_fx(lsf_q,0, LPC_SHB_ORDER); - - /* VQ part */ - num_bits_lvq = config_LSF_BWE[(NUM_BITS_SHB_MSLVQ - nbits) * 3]; - Idx = get_next_indice(st_fx, num_bits_lvq); - v_add_16(lsf_q, cb_stage + Idx * 6, lsf_q, 6); - - /* MSLVQ part */ - num_bits_lvq = nbits - num_bits_lvq - config_LSF_BWE[(NUM_BITS_SHB_MSLVQ - nbits) * 3 + 2]; - predictor_bits = config_LSF_BWE[(NUM_BITS_SHB_MSLVQ - nbits) * 3 + 2]; - Idx_pred = 0; - - IF(num_bits_lvq == 16) - { - /* MSLVQ part */ - Idx_lvq = get_next_indice(st_fx, num_bits_lvq - 1) + ((get_next_indice(st_fx, 1)) << 15); - deindex_lvq_SHB_fx(Idx_lvq, out, num_bits_lvq, 0); - } - ELSE - { - /* MSLVQ part */ - Idx_lvq = get_next_indice(st_fx, num_bits_lvq); - deindex_lvq_SHB_fx(Idx_lvq, out, num_bits_lvq, (nbits < 19)); - } - - /* mvr2r( mean_lsf, Q_lsfs, LPC_SHB_ORDER ); */ - v_add_16(lsf_q, out, lsf_q, LATTICE_DIM); /* quantized mean removed data for first 8 dim*/ - - /* predict last 2 components */ - IF(predictor_bits == 0) - { - lsf_q[LATTICE_DIM] = dotp_loc(lsf_q, LastCoefPred_0bit_fx, LATTICE_DIM); - lsf_q[LATTICE_DIM + 1] = dotp_loc(lsf_q, &LastCoefPred_0bit_fx[LATTICE_DIM + 1], LATTICE_DIM); - } - ELSE - { - Idx_pred = get_next_indice(st_fx, 1); - - lsf_q[LATTICE_DIM] = dotp_loc(lsf_q, &LastCoefPred_1bit_fx[2 * (LATTICE_DIM + 1) * Idx_pred], LATTICE_DIM); - lsf_q[LATTICE_DIM + 1] = dotp_loc(lsf_q, &LastCoefPred_1bit_fx[2 * (LATTICE_DIM + 1) * Idx_pred + LATTICE_DIM + 1], LATTICE_DIM); - } + /* MSLVQ part */ + Idx_lvq = get_next_indice( st_fx, num_bits_lvq ); + deindex_lvq_SHB_fx( Idx_lvq, out, num_bits_lvq, ( nbits < 19 ) ); + } - IF (nbits < NUM_BITS_SHB_MSLVQ) - { - Idx_pred = get_next_indice(st_fx, NUM_BITS_SHB_MSLVQ - nbits); - } + /* mvr2r( mean_lsf, Q_lsfs, LPC_SHB_ORDER ); */ + v_add_16( lsf_q, out, lsf_q, LATTICE_DIM ); /* quantized mean removed data for first 8 dim*/ - v_add_16(SHB_LSF_mean_fx, lsf_q, lsf_q, LPC_SHB_ORDER); - v_sort(lsf_q, 0, LPC_SHB_ORDER - 1); - } - ELSE - { - /* LSFs */ - test(); - test(); - test(); - IF(EQ_32(extl_brate, SWB_TBE_1k6) || EQ_32(extl_brate, FB_TBE_1k8) || EQ_32(extl_brate, SWB_TBE_2k8) || EQ_32(extl_brate, FB_TBE_3k0)) - { - IF(EQ_16(st_fx->codec_mode, MODE2)) - { - FOR(i = 0; i < NUM_Q_LSF; i++) - { - lsf_idx[i] = hBWE_TD->lsf_idx[i]; - move16(); - } - } - ELSE - { - FOR(i = 0; i < NUM_Q_LSF; i++) - { - lsf_idx[i] = (Word16)get_next_indice(st_fx, lsf_q_num_bits[i]); - move16(); - } - } - } - Dequant_lower_LSF_fx(lsf_idx, lsf_q); - - IF(EQ_16(st_fx->codec_mode, MODE2)) - { - m_idx = hBWE_TD->m_idx; - } - ELSE - { - m_idx = (Word16)get_next_indice(st_fx, MIRROR_POINT_BITS); - move16(); - } + /* predict last 2 components */ + IF( predictor_bits == 0 ) + { + lsf_q[LATTICE_DIM] = dotp_loc( lsf_q, LastCoefPred_0bit_fx, LATTICE_DIM ); + lsf_q[LATTICE_DIM + 1] = dotp_loc( lsf_q, &LastCoefPred_0bit_fx[LATTICE_DIM + 1], LATTICE_DIM ); + } + ELSE + { + Idx_pred = get_next_indice( st_fx, 1 ); - Dequant_mirror_point_fx(lsf_q, m_idx, &m); + lsf_q[LATTICE_DIM] = dotp_loc( lsf_q, &LastCoefPred_1bit_fx[2 * ( LATTICE_DIM + 1 ) * Idx_pred], LATTICE_DIM ); + lsf_q[LATTICE_DIM + 1] = dotp_loc( lsf_q, &LastCoefPred_1bit_fx[2 * ( LATTICE_DIM + 1 ) * Idx_pred + LATTICE_DIM + 1], LATTICE_DIM ); + } - /* safety check in case of bit errors */ - IF(GT_16(m, MAX_LSF_FX)) - { - st_fx->BER_detect = 1; - m = MAX_LSF_FX - 1; - } + IF( nbits < NUM_BITS_SHB_MSLVQ ) + { + Idx_pred = get_next_indice( st_fx, NUM_BITS_SHB_MSLVQ - nbits ); + } - IF(EQ_16(st_fx->codec_mode, MODE2)) - { - grid_idx = hBWE_TD->grid_idx; - } - ELSE + v_add_16( SHB_LSF_mean_fx, lsf_q, lsf_q, LPC_SHB_ORDER ); + v_sort( lsf_q, 0, LPC_SHB_ORDER - 1 ); + } + ELSE + { + /* LSFs */ + test(); + test(); + test(); + IF( EQ_32( extl_brate, SWB_TBE_1k6 ) || EQ_32( extl_brate, FB_TBE_1k8 ) || EQ_32( extl_brate, SWB_TBE_2k8 ) || EQ_32( extl_brate, FB_TBE_3k0 ) ) + { + IF( EQ_16( st_fx->codec_mode, MODE2 ) ) + { + FOR( i = 0; i < NUM_Q_LSF; i++ ) { - grid_idx = (Word16)get_next_indice(st_fx, NUM_LSF_GRID_BITS); + lsf_idx[i] = hBWE_TD->lsf_idx[i]; move16(); } - - Map_higher_LSF_fx(lsf_q, m, lsf_grid_fx[grid_idx]); } - FOR(i = 0; i < LPC_SHB_ORDER; i++) + ELSE { - /* safety check in case of bit errors */ - IF(GT_16(lsf_q[LPC_SHB_ORDER - 1 - i], MAX_LSF_FX)) + FOR( i = 0; i < NUM_Q_LSF; i++ ) { - st_fx->BER_detect = 1; - lsf_q[LPC_SHB_ORDER - 1 - i] = MAX_LSF_FX - 1; + lsf_idx[i] = (Word16) get_next_indice( st_fx, lsf_q_num_bits[i] ); + move16(); } - Q_lsf[i] = sub(16384, lsf_q[LPC_SHB_ORDER - 1 - i]); - move16(); } } + Dequant_lower_LSF_fx( lsf_idx, lsf_q ); + + IF( EQ_16( st_fx->codec_mode, MODE2 ) ) + { + m_idx = hBWE_TD->m_idx; + } ELSE { - set16_fx(lsf_idx, 0, 5); - Copy(hBWE_TD->lsf_idx, lsf_idx, 5); - grid_idx = 0; - m_idx = 0; - Copy(swb_tbe_lsfvq_cbook_8b + lsf_idx[0] * LPC_SHB_ORDER, Q_lsf, LPC_SHB_ORDER); + m_idx = (Word16) get_next_indice( st_fx, MIRROR_POINT_BITS ); + move16(); } - space_lsfs_fx(Q_lsf, LPC_SHB_ORDER); + Dequant_mirror_point_fx( lsf_q, m_idx, &m ); - /* Dequantize subgain indices */ - j = idxSubGain * NUM_SHB_SUBGAINS; - move16(); - FOR(i = 0; i < NUM_SHB_SUBGAINS; i++) + /* safety check in case of bit errors */ + IF( GT_16( m, MAX_LSF_FX ) ) { - /* Q_subgain[i] = (float) pow(10.0, SHBCB_SubGain5bit[j++]); */ - - L_tmp = L_mult(SHBCB_SubGain5bit_fx[j++], 27213); /*Q28 3.321928 in Q13 */ - L_tmp = L_shr(L_tmp, 12); - frac = L_Extract_lc(L_tmp, &exp); - tmp = extract_l(Pow2(14, frac)); /* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - Q_subgain[i] = shl(tmp, add(exp, 1)); /*Q15*/ - move16(); + st_fx->BER_detect = 1; + m = MAX_LSF_FX - 1; } - FOR(i = NUM_SHB_SUBFR - 1; i >= 0; i--) + IF( EQ_16( st_fx->codec_mode, MODE2 ) ) + { + grid_idx = hBWE_TD->grid_idx; + } + ELSE { - Q_subgain[i] = Q_subgain[i * NUM_SHB_SUBGAINS / NUM_SHB_SUBFR]; + grid_idx = (Word16) get_next_indice( st_fx, NUM_LSF_GRID_BITS ); move16(); } - /* Frame gain */ - IF(st_fx->extl_brate == SWB_TBE_1k75) + Map_higher_LSF_fx( lsf_q, m, lsf_grid_fx[grid_idx] ); + } + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) + { + /* safety check in case of bit errors */ + IF( GT_16( lsf_q[LPC_SHB_ORDER - 1 - i], MAX_LSF_FX ) ) { - *Q_framegrain = L_mac(SHB_GAIN_QLOW_1k75_FX, idxFrameGain, SHB_GAIN_QDELTA_1k75_FX); - } - ELSE { - *Q_framegrain = L_mac(SHB_GAIN_QLOW_FX, idxFrameGain, SHB_GAIN_QDELTA_FX); + st_fx->BER_detect = 1; + lsf_q[LPC_SHB_ORDER - 1 - i] = MAX_LSF_FX - 1; } - move32(); /*Q18*/ - L_tmp = Mult_32_16(*Q_framegrain, 27213); /*Q16*/ /* 3.321928 in Q13 */ - frac = L_Extract_lc(L_tmp, &exp); - L_tmp = Pow2(30, frac); - *Q_framegrain = L_shl(L_tmp, sub(exp, 12)); /*Q18*/ + Q_lsf[i] = sub( 16384, lsf_q[LPC_SHB_ORDER - 1 - i] ); + move16(); + } + } + ELSE + { + set16_fx( lsf_idx, 0, 5 ); + Copy( hBWE_TD->lsf_idx, lsf_idx, 5 ); + grid_idx = 0; + m_idx = 0; + Copy( swb_tbe_lsfvq_cbook_8b + lsf_idx[0] * LPC_SHB_ORDER, Q_lsf, LPC_SHB_ORDER ); + } + + space_lsfs_fx( Q_lsf, LPC_SHB_ORDER ); + + /* Dequantize subgain indices */ + j = idxSubGain * NUM_SHB_SUBGAINS; + move16(); + FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) + { + /* Q_subgain[i] = (float) pow(10.0, SHBCB_SubGain5bit[j++]); */ + + L_tmp = L_mult( SHBCB_SubGain5bit_fx[j++], 27213 ); /*Q28 3.321928 in Q13 */ + L_tmp = L_shr( L_tmp, 12 ); + frac = L_Extract_lc( L_tmp, &exp ); + tmp = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ + /* output of Pow2() will be: */ + /* 16384 < Pow2() <= 32767 */ + Q_subgain[i] = shl( tmp, add( exp, 1 ) ); /*Q15*/ + move16(); + } + + FOR( i = NUM_SHB_SUBFR - 1; i >= 0; i-- ) + { + Q_subgain[i] = Q_subgain[i * NUM_SHB_SUBGAINS / NUM_SHB_SUBFR]; + move16(); + } + + /* Frame gain */ + IF( st_fx->extl_brate == SWB_TBE_1k75 ) + { + *Q_framegrain = L_mac( SHB_GAIN_QLOW_1k75_FX, idxFrameGain, SHB_GAIN_QDELTA_1k75_FX ); + } + ELSE + { + *Q_framegrain = L_mac( SHB_GAIN_QLOW_FX, idxFrameGain, SHB_GAIN_QDELTA_FX ); + } + move32(); /*Q18*/ + L_tmp = Mult_32_16( *Q_framegrain, 27213 ); /*Q16*/ /* 3.321928 in Q13 */ + frac = L_Extract_lc( L_tmp, &exp ); + L_tmp = Pow2( 30, frac ); + *Q_framegrain = L_shl( L_tmp, sub( exp, 12 ) ); /*Q18*/ } return; @@ -4212,20 +4201,20 @@ void ivas_dequantizeSHBparams_fx_9_1( /*==========================================================================*/ static void dequantizeSHBparams_fx_9_1( - Decoder_State* st_fx, - const Word16 extl, /* i : extension layer */ - Word32 extl_brate, /* i : extensiuon layer bitrate */ - Word16* Q_lsf, /* o : SHB LSF from de-quantization Q15*/ - Word16* Q_subgain, /* o : SHB subframe gains from de-quantization Q15*/ - Word32* Q_framegrain, /* o : SHB frame gain from de-quantization Q18*/ - Word16* uv_flag, /* o : unvoiced flag*/ - Word32* Q_shb_ener_sf, /* o : Q15 */ - Word16* Q_shb_res_gshape, /* o : Q14 */ - Word16* Q_mixFactors /* o : Q15 */ + Decoder_State *st_fx, + const Word16 extl, /* i : extension layer */ + Word32 extl_brate, /* i : extensiuon layer bitrate */ + Word16 *Q_lsf, /* o : SHB LSF from de-quantization Q15*/ + Word16 *Q_subgain, /* o : SHB subframe gains from de-quantization Q15*/ + Word32 *Q_framegrain, /* o : SHB frame gain from de-quantization Q18*/ + Word16 *uv_flag, /* o : unvoiced flag*/ + Word32 *Q_shb_ener_sf, /* o : Q15 */ + Word16 *Q_shb_res_gshape, /* o : Q14 */ + Word16 *Q_mixFactors /* o : Q15 */ ) { Word16 i, j, idxLSF, idxSubGain, idxFrameGain; - Word16 Q_combined_gains[NUM_SHB_SUBFR/4]; + Word16 Q_combined_gains[NUM_SHB_SUBFR / 4]; Word16 lsf_q[LPC_SHB_ORDER]; Word16 lsf_idx[NUM_Q_LSF]; Word16 m_idx, grid_idx; @@ -4239,9 +4228,9 @@ static void dequantizeSHBparams_fx_9_1( /* LSFs */ - IF( EQ_16( extl, WB_TBE )) + IF( EQ_16( extl, WB_TBE ) ) { - IF( EQ_32( extl_brate, WB_TBE_0k35 )) + IF( EQ_32( extl_brate, WB_TBE_0k35 ) ) { idxFrameGain = hBWE_TD->gFrame_WB; idxLSF = hBWE_TD->lsf_WB; @@ -4252,12 +4241,12 @@ static void dequantizeSHBparams_fx_9_1( } ELSE { - *uv_flag = ( Word16 )get_next_indice( st_fx, 1 ); - idxSubGain = ( Word16 )get_next_indice( st_fx, NUM_BITS_SHB_SUBGAINS ); + *uv_flag = (Word16) get_next_indice( st_fx, 1 ); + idxSubGain = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_SUBGAINS ); move16(); - idxFrameGain = ( Word16 )get_next_indice( st_fx, NUM_BITS_SHB_FrameGain ); + idxFrameGain = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_FrameGain ); move16(); - idxLSF = ( Word16 )get_next_indice( st_fx, NUM_BITS_WB_LSF ); + idxLSF = (Word16) get_next_indice( st_fx, NUM_BITS_WB_LSF ); move16(); Copy( wb_bwe_lsfvq_cbook_8bit_fx + idxLSF * LPC_SHB_ORDER_WB, Q_lsf, LPC_SHB_ORDER_WB ); Copy( HBCB_SubGain5bit_fx + idxSubGain * NUM_SHB_SUBFR / 4, Q_combined_gains, NUM_SHB_SUBFR / 4 ); @@ -4265,18 +4254,18 @@ static void dequantizeSHBparams_fx_9_1( FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) { - L_tmp = L_mult( Q_combined_gains[i], 21771 ); /*Q26 0.166096 in Q17 */ + L_tmp = L_mult( Q_combined_gains[i], 21771 ); /*Q26 0.166096 in Q17 */ L_tmp = L_shr( L_tmp, 10 ); frac = L_Extract_lc( L_tmp, &exp ); - tmp = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ + tmp = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ Q_combined_gains[i] = shl( tmp, add( exp, 1 ) ); /* Q15 */ } - FOR( i=0; i < NUM_SHB_SUBFR / 2; i+= 2) + FOR( i = 0; i < NUM_SHB_SUBFR / 2; i += 2 ) { - Q_subgain[i] = Q_combined_gains[i / 2]; + Q_subgain[i] = Q_combined_gains[i / 2]; move16(); Q_subgain[i + 1] = Q_combined_gains[i / 2]; move16(); @@ -4288,21 +4277,21 @@ static void dequantizeSHBparams_fx_9_1( } ELSE /* SWB TBE DEC */ { - IF(EQ_16(st_fx->codec_mode,MODE2)) + IF( EQ_16( st_fx->codec_mode, MODE2 ) ) { idxSubGain = hBWE_TD->idxSubGains; idxFrameGain = hBWE_TD->idxFrameGain; } ELSE { - idxSubGain = ( Word16 )get_next_indice( st_fx, NUM_BITS_SHB_SUBGAINS ); - idxFrameGain = ( Word16 )get_next_indice( st_fx, NUM_BITS_SHB_FRAMEGAIN ); + idxSubGain = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_SUBGAINS ); + idxFrameGain = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_FRAMEGAIN ); } test(); - IF( EQ_32(st_fx->total_brate, ACELP_24k40)||EQ_32(st_fx->total_brate,ACELP_32k)) + IF( EQ_32( st_fx->total_brate, ACELP_24k40 ) || EQ_32( st_fx->total_brate, ACELP_32k ) ) { - IF(EQ_16(st_fx->codec_mode,MODE2)) + IF( EQ_16( st_fx->codec_mode, MODE2 ) ) { idx_shb_fr_gain = hBWE_TD->idx_shb_fr_gain; } @@ -4310,20 +4299,20 @@ static void dequantizeSHBparams_fx_9_1( { idx_shb_fr_gain = get_next_indice( st_fx, NUM_BITS_SHB_ENER_SF ); } - temp_shb_ener_sf_fx = usdequant_fx(idx_shb_fr_gain, 0, 86); /* 86 = 0.042f in Q11 = Qin-1 */ + temp_shb_ener_sf_fx = usdequant_fx( idx_shb_fr_gain, 0, 86 ); /* 86 = 0.042f in Q11 = Qin-1 */ /* o: temp_shb_ener_sf_fx in Q12 */ /* *Q_shb_ener_sf = Pow(10.0, temp_shb_ener_sf_fx ); */ /* = pow(2, 3.321928*temp_shb_ener_sf_fx) */ - L_tmp = L_mult(temp_shb_ener_sf_fx, 27213 ); /* 3.321928 in Q13 -> L_tmp in Q12+Q13+1 = Q26 */ - L_tmp = L_shl( L_tmp, -10 ); /* bring L_tmp from Q26 to Q16 */ - frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent */ - L_tmp = Pow2(14, frac ); - *Q_shb_ener_sf = L_shl(L_tmp, exp-14+0 ); /* In Q_ener: 2*Q_shb+1, Q_shb = 0; */ + L_tmp = L_mult( temp_shb_ener_sf_fx, 27213 ); /* 3.321928 in Q13 -> L_tmp in Q12+Q13+1 = Q26 */ + L_tmp = L_shl( L_tmp, -10 ); /* bring L_tmp from Q26 to Q16 */ + frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent */ + L_tmp = Pow2( 14, frac ); + *Q_shb_ener_sf = L_shl( L_tmp, exp - 14 + 0 ); /* In Q_ener: 2*Q_shb+1, Q_shb = 0; */ - FOR(i=0; i<5; i++) + FOR( i = 0; i < 5; i++ ) { - IF(EQ_16(st_fx->codec_mode,MODE2)) + IF( EQ_16( st_fx->codec_mode, MODE2 ) ) { idx_res_gs[i] = hBWE_TD->idx_res_gs[i]; move16(); @@ -4333,33 +4322,33 @@ static void dequantizeSHBparams_fx_9_1( idx_res_gs[i] = get_next_indice( st_fx, NUM_BITS_SHB_RES_GS ); move16(); } - Q_shb_res_gshape[i] = usdequant_fx(idx_res_gs[i], - 2048/*0.125f Q14*/, /*2048 = 0.125 in Q14 */ - 1024/*0.125f Q13*/ /*1024 = 0.125 in Q13 */ - ); + Q_shb_res_gshape[i] = usdequant_fx( idx_res_gs[i], + 2048 /*0.125f Q14*/, /*2048 = 0.125 in Q14 */ + 1024 /*0.125f Q13*/ /*1024 = 0.125 in Q13 */ + ); move16(); /* o: Q_shb_res_gshape in Q14 */ } - IF(EQ_16(st_fx->codec_mode,MODE2)) + IF( EQ_16( st_fx->codec_mode, MODE2 ) ) { idx_mixFac = hBWE_TD->idx_mixFac; move16(); } ELSE { - idx_mixFac = (Word16)get_next_indice( st_fx, NUM_BITS_SHB_VF ); + idx_mixFac = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_VF ); } - *Q_mixFactors = usdequant_fx(idx_mixFac, 4096 /* 0.125 in Q15 */, 2048 /* 0.125 in Q14 */); + *Q_mixFactors = usdequant_fx( idx_mixFac, 4096 /* 0.125 in Q15 */, 2048 /* 0.125 in Q14 */ ); move16(); /* o: Q_mixFactors in Q15 */ } ELSE { - *Q_shb_ener_sf = L_deposit_l(0); + *Q_shb_ener_sf = L_deposit_l( 0 ); *Q_mixFactors = 0; move16(); - set16_fx(Q_shb_res_gshape, 0, 5); + set16_fx( Q_shb_res_gshape, 0, 5 ); } /* LSFs */ @@ -4370,70 +4359,69 @@ static void dequantizeSHBparams_fx_9_1( test(); test(); test(); - IF( (st_fx->rf_flag == 0) && !((EQ_32(st_fx->total_brate, ACELP_9k60))||((st_fx->total_brate==0)&&((EQ_32(st_fx->last_total_brate,ACELP_9k60))||(EQ_32(st_fx->last_total_brate,ACELP_13k20)&&EQ_16(st_fx->rf_flag_last,1)))))) + IF( ( st_fx->rf_flag == 0 ) && !( ( EQ_32( st_fx->total_brate, ACELP_9k60 ) ) || ( ( st_fx->total_brate == 0 ) && ( ( EQ_32( st_fx->last_total_brate, ACELP_9k60 ) ) || ( EQ_32( st_fx->last_total_brate, ACELP_13k20 ) && EQ_16( st_fx->rf_flag_last, 1 ) ) ) ) ) ) { /* LSFs */ test(); test(); test(); - IF ( EQ_32(extl_brate, SWB_TBE_1k6)||EQ_32(extl_brate,FB_TBE_1k8)||EQ_32(extl_brate,SWB_TBE_2k8)||EQ_32(extl_brate,FB_TBE_3k0)) + IF( EQ_32( extl_brate, SWB_TBE_1k6 ) || EQ_32( extl_brate, FB_TBE_1k8 ) || EQ_32( extl_brate, SWB_TBE_2k8 ) || EQ_32( extl_brate, FB_TBE_3k0 ) ) { - IF(EQ_16(st_fx->codec_mode,MODE2)) + IF( EQ_16( st_fx->codec_mode, MODE2 ) ) { - FOR (i = 0; i < NUM_Q_LSF; i++) + FOR( i = 0; i < NUM_Q_LSF; i++ ) { lsf_idx[i] = hBWE_TD->lsf_idx[i]; move16(); - } } ELSE { - FOR (i = 0; i < NUM_Q_LSF; i++) + FOR( i = 0; i < NUM_Q_LSF; i++ ) { - lsf_idx[i] = (Word16)get_next_indice(st_fx, lsf_q_num_bits[i]); + lsf_idx[i] = (Word16) get_next_indice( st_fx, lsf_q_num_bits[i] ); move16(); } } } Dequant_lower_LSF_fx( lsf_idx, lsf_q ); - IF(EQ_16(st_fx->codec_mode,MODE2)) + IF( EQ_16( st_fx->codec_mode, MODE2 ) ) { m_idx = hBWE_TD->m_idx; } ELSE { - m_idx = (Word16)get_next_indice( st_fx, MIRROR_POINT_BITS ); + m_idx = (Word16) get_next_indice( st_fx, MIRROR_POINT_BITS ); move16(); } Dequant_mirror_point_fx( lsf_q, m_idx, &m ); /* safety check in case of bit errors */ - IF(GT_16(m, MAX_LSF_FX)) + IF( GT_16( m, MAX_LSF_FX ) ) { st_fx->BER_detect = 1; - m = MAX_LSF_FX-1; + m = MAX_LSF_FX - 1; } - IF(EQ_16(st_fx->codec_mode,MODE2)) + IF( EQ_16( st_fx->codec_mode, MODE2 ) ) { grid_idx = hBWE_TD->grid_idx; } ELSE { - grid_idx = (Word16)get_next_indice( st_fx, NUM_LSF_GRID_BITS ); + grid_idx = (Word16) get_next_indice( st_fx, NUM_LSF_GRID_BITS ); move16(); } Map_higher_LSF_fx( lsf_q, m, lsf_grid_fx[grid_idx] ); - FOR (i = 0; i < LPC_SHB_ORDER; i++) + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { /* safety check in case of bit errors */ - IF(GT_16(lsf_q[LPC_SHB_ORDER - 1 - i], MAX_LSF_FX)) + IF( GT_16( lsf_q[LPC_SHB_ORDER - 1 - i], MAX_LSF_FX ) ) { st_fx->BER_detect = 1; lsf_q[LPC_SHB_ORDER - 1 - i] = MAX_LSF_FX - 1; @@ -4444,11 +4432,11 @@ static void dequantizeSHBparams_fx_9_1( } ELSE { - set16_fx(lsf_idx, 0, 5); - Copy(hBWE_TD->lsf_idx, lsf_idx, 5); + set16_fx( lsf_idx, 0, 5 ); + Copy( hBWE_TD->lsf_idx, lsf_idx, 5 ); grid_idx = 0; m_idx = 0; - Copy(swb_tbe_lsfvq_cbook_8b + lsf_idx[0]*LPC_SHB_ORDER, Q_lsf, LPC_SHB_ORDER); + Copy( swb_tbe_lsfvq_cbook_8b + lsf_idx[0] * LPC_SHB_ORDER, Q_lsf, LPC_SHB_ORDER ); } space_lsfs_fx( Q_lsf, LPC_SHB_ORDER ); @@ -4463,10 +4451,11 @@ static void dequantizeSHBparams_fx_9_1( L_tmp = L_mult( SHBCB_SubGain5bit_fx[j++], 27213 ); /*Q28 3.321928 in Q13 */ L_tmp = L_shr( L_tmp, 12 ); frac = L_Extract_lc( L_tmp, &exp ); - tmp = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ + tmp = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ - Q_subgain[i] = shl( tmp, add( exp, 1 ) ); /*Q15*/ move16(); + Q_subgain[i] = shl( tmp, add( exp, 1 ) ); /*Q15*/ + move16(); } FOR( i = NUM_SHB_SUBFR - 1; i >= 0; i-- ) @@ -4477,8 +4466,8 @@ static void dequantizeSHBparams_fx_9_1( /* Frame gain */ *Q_framegrain = L_mac( SHB_GAIN_QLOW_FX, idxFrameGain, SHB_GAIN_QDELTA_FX ); - move32();/*Q18*/ - L_tmp = Mult_32_16( *Q_framegrain, 27213 ); /*Q16*/ /* 3.321928 in Q13 */ + move32(); /*Q18*/ + L_tmp = Mult_32_16( *Q_framegrain, 27213 ); /*Q16*/ /* 3.321928 in Q13 */ frac = L_Extract_lc( L_tmp, &exp ); L_tmp = Pow2( 30, frac ); *Q_framegrain = L_shl( L_tmp, sub( exp, 12 ) ); /*Q18*/ @@ -4493,12 +4482,11 @@ static void dequantizeSHBparams_fx_9_1( * FB TBE decoder, 14(resp. 15.5) - 20 kHz band decoding module *-------------------------------------------------------------------*/ void fb_tbe_dec_fx( - Decoder_State *st, /* i/o: encoder state structure */ - const Word16 fb_exc[], /* i : FB excitation from the SWB part */ - Word16 Q_fb_exc, - Word16 *hb_synth, /* o : high-band synthesis */ - Word16 hb_synth_exp -) + Decoder_State *st, /* i/o: encoder state structure */ + const Word16 fb_exc[], /* i : FB excitation from the SWB part */ + Word16 Q_fb_exc, + Word16 *hb_synth, /* o : high-band synthesis */ + Word16 hb_synth_exp ) { Word16 i; @@ -4511,36 +4499,36 @@ void fb_tbe_dec_fx( /* decode FB slope information */ test(); test(); - IF ( EQ_16(st->extl,FB_TBE)&&!st->bfi) + IF( EQ_16( st->extl, FB_TBE ) && !st->bfi ) { - IF( EQ_16(st->codec_mode,MODE2)) + IF( EQ_16( st->codec_mode, MODE2 ) ) { i = hBWE_TD->idxGain; move16(); } ELSE { - i = (Word16)get_next_indice( st, 4 ); + i = (Word16) get_next_indice( st, 4 ); } #ifdef BASOP_NOGLOB - ratio = shl_sat(1,i); + ratio = shl_sat( 1, i ); #else - ratio = shl(1,i); + ratio = shl( 1, i ); #endif } - ELSE if ( EQ_16(st->extl,FB_TBE)&&st->bfi) + ELSE if ( EQ_16( st->extl, FB_TBE ) && st->bfi ) { ratio = hBWE_TD->prev_fbbwe_ratio_fx; move16(); } - fb_exc_energy = sum2_fx_mod(fb_exc,L_FRAME16k); + fb_exc_energy = sum2_fx_mod( fb_exc, L_FRAME16k ); /* FB TBE synthesis */ - synthesise_fb_high_band_fx( fb_exc,Q_fb_exc,fb_synth,fb_exc_energy,ratio, st->L_frame, st->bfi, &(hBWE_TD->prev_fbbwe_ratio_fx), hBWE_TD->fbbwe_hpf_mem_fx, hBWE_TD->fbbwe_hpf_mem_fx_Q,hb_synth_exp); + synthesise_fb_high_band_fx( fb_exc, Q_fb_exc, fb_synth, fb_exc_energy, ratio, st->L_frame, st->bfi, &( hBWE_TD->prev_fbbwe_ratio_fx ), hBWE_TD->fbbwe_hpf_mem_fx, hBWE_TD->fbbwe_hpf_mem_fx_Q, hb_synth_exp ); /* add the fb_synth component to the hb_synth component */ /* v_add_fx( hb_synth, fb_synth, hb_synth, L_FRAME48k );*/ - FOR (i=0; iL_frame, st->bfi, &( hBWE_TD->prev_fbbwe_ratio_fx ), hBWE_TD->fbbwe_hpf_mem_fx, hBWE_TD->fbbwe_hpf_mem_fx_Q, hb_synth_exp ); - IF (GE_16(st->element_mode, IVAS_CPE_DFT) && EQ_16(st->idchan, 0)) - { - Copy_Scale_sig(fb_synth,fb_synth_ref,L_FRAME48k, sub(Q_fb_synth_ref , hb_synth_exp)); //scaling is required - } + IF( GE_16( st->element_mode, IVAS_CPE_DFT ) && EQ_16( st->idchan, 0 ) ) + { + Copy_Scale_sig( fb_synth, fb_synth_ref, L_FRAME48k, sub( Q_fb_synth_ref, hb_synth_exp ) ); // scaling is required + } /* add the fb_synth component to the hb_synth component */ /* v_add_fx( hb_synth, fb_synth, hb_synth, L_FRAME48k );*/ FOR( i = 0; i < L_FRAME48k; i++ ) { - //hb_synth[i] = L_add( hb_synth[i], L_deposit_l(fb_synth[i])); - hb_synth[i] = L_add( hb_synth[i], L_shl(fb_synth[i], Q11)); + // hb_synth[i] = L_add( hb_synth[i], L_deposit_l(fb_synth[i])); + hb_synth[i] = L_add( hb_synth[i], L_shl( fb_synth[i], Q11 ) ); move16(); } return; @@ -4630,8 +4618,7 @@ void fb_tbe_dec_ivas_fx( #endif void tbe_read_bitstream_fx( - Decoder_State *st_fx -) + Decoder_State *st_fx ) { Word16 i; TD_BWE_DEC_HANDLE hBWE_TD; @@ -4642,34 +4629,33 @@ void tbe_read_bitstream_fx( test(); test(); test(); - IF ( (EQ_16(st_fx->rf_flag,1)||EQ_32(st_fx->total_brate,ACELP_9k60))&&EQ_16(st_fx->bwidth,WB)) + IF( ( EQ_16( st_fx->rf_flag, 1 ) || EQ_32( st_fx->total_brate, ACELP_9k60 ) ) && EQ_16( st_fx->bwidth, WB ) ) { /* WB LSF */ - hBWE_TD->lsf_WB = get_next_indice(st_fx, NUM_BITS_LBR_WB_LSF); + hBWE_TD->lsf_WB = get_next_indice( st_fx, NUM_BITS_LBR_WB_LSF ); /* WB frame gain */ - hBWE_TD->gFrame_WB = get_next_indice(st_fx, NUM_BITS_SHB_FrameGain_LBR_WB); + hBWE_TD->gFrame_WB = get_next_indice( st_fx, NUM_BITS_SHB_FrameGain_LBR_WB ); } - ELSE IF ( ( GE_32( st_fx->total_brate, ACELP_9k60 ))&&(LE_32(st_fx->total_brate,ACELP_32k))&& - ( ( EQ_16( st_fx->bwidth, SWB ) ) || ( EQ_16( st_fx->bwidth, FB ) ) ) ) + ELSE IF( ( GE_32( st_fx->total_brate, ACELP_9k60 ) ) && ( LE_32( st_fx->total_brate, ACELP_32k ) ) && + ( ( EQ_16( st_fx->bwidth, SWB ) ) || ( EQ_16( st_fx->bwidth, FB ) ) ) ) { test(); - IF( (st_fx->rf_flag == 0) && (GT_32(st_fx->total_brate, ACELP_9k60))) + IF( ( st_fx->rf_flag == 0 ) && ( GT_32( st_fx->total_brate, ACELP_9k60 ) ) ) { - FOR (i = 0; i < NUM_Q_LSF; i++) + FOR( i = 0; i < NUM_Q_LSF; i++ ) { - hBWE_TD->lsf_idx[i] = get_next_indice(st_fx, lsf_q_num_bits[i]); + hBWE_TD->lsf_idx[i] = get_next_indice( st_fx, lsf_q_num_bits[i] ); move16(); } - hBWE_TD->m_idx = get_next_indice(st_fx, MIRROR_POINT_BITS); - - hBWE_TD->grid_idx = get_next_indice(st_fx, NUM_LSF_GRID_BITS); + hBWE_TD->m_idx = get_next_indice( st_fx, MIRROR_POINT_BITS ); + hBWE_TD->grid_idx = get_next_indice( st_fx, NUM_LSF_GRID_BITS ); } ELSE { - hBWE_TD->lsf_idx[0] = get_next_indice(st_fx, 8); + hBWE_TD->lsf_idx[0] = get_next_indice( st_fx, 8 ); move16(); hBWE_TD->m_idx = 0; move16(); @@ -4678,33 +4664,33 @@ void tbe_read_bitstream_fx( } /* shape gains */ - hBWE_TD->idxSubGains = get_next_indice(st_fx, NUM_BITS_SHB_SUBGAINS); + hBWE_TD->idxSubGains = get_next_indice( st_fx, NUM_BITS_SHB_SUBGAINS ); /* frame gain */ - hBWE_TD->idxFrameGain = get_next_indice(st_fx, NUM_BITS_SHB_FRAMEGAIN); + hBWE_TD->idxFrameGain = get_next_indice( st_fx, NUM_BITS_SHB_FRAMEGAIN ); - IF ( GE_32( st_fx->total_brate, ACELP_24k40 )) + IF( GE_32( st_fx->total_brate, ACELP_24k40 ) ) { /* sub frame energy*/ - hBWE_TD->idx_shb_fr_gain = get_next_indice(st_fx, NUM_BITS_SHB_ENER_SF); + hBWE_TD->idx_shb_fr_gain = get_next_indice( st_fx, NUM_BITS_SHB_ENER_SF ); /* gain shapes residual */ - FOR (i = 0; i < NB_SUBFR16k; i++) + FOR( i = 0; i < NB_SUBFR16k; i++ ) { - hBWE_TD->idx_res_gs[i] = get_next_indice(st_fx, NUM_BITS_SHB_RES_GS); + hBWE_TD->idx_res_gs[i] = get_next_indice( st_fx, NUM_BITS_SHB_RES_GS ); move16(); } /* voicing factor */ - hBWE_TD->idx_mixFac = get_next_indice(st_fx, NUM_BITS_SHB_VF); + hBWE_TD->idx_mixFac = get_next_indice( st_fx, NUM_BITS_SHB_VF ); } - IF (EQ_16(st_fx->tec_tfa, 1)) + IF( EQ_16( st_fx->tec_tfa, 1 ) ) { - st_fx->tec_flag = get_next_indice(st_fx, BITS_TEC); - st_fx->tfa_flag = get_next_indice(st_fx, BITS_TFA); + st_fx->tec_flag = get_next_indice( st_fx, BITS_TEC ); + st_fx->tfa_flag = get_next_indice( st_fx, BITS_TFA ); test(); - IF (st_fx->tfa_flag && st_fx->tec_flag) + IF( st_fx->tfa_flag && st_fx->tec_flag ) { st_fx->tec_flag = 2; move16(); @@ -4721,80 +4707,79 @@ void tbe_read_bitstream_fx( } } - IF ( EQ_16( st_fx->bwidth, FB )) + IF( EQ_16( st_fx->bwidth, FB ) ) { - hBWE_TD->idxGain = get_next_indice(st_fx, 4); + hBWE_TD->idxGain = get_next_indice( st_fx, 4 ); } } /*---------------------------------------------------------------------* -* GenTransition() -* -* Generate a highband transition signal from the gain shape overlap -* buffer to fill the gap caused by the delay alignment buffer when -* switching from TBE to IGF -*---------------------------------------------------------------------*/ + * GenTransition() + * + * Generate a highband transition signal from the gain shape overlap + * buffer to fill the gap caused by the delay alignment buffer when + * switching from TBE to IGF + *---------------------------------------------------------------------*/ void GenTransition_fx( - const Word16 *input, /* i : gain shape overlap buffer */ - const Word16 *old_hb_synth, /* i : synthesized HB from previous frame */ - Word16 length, /* i : targeted length of transition signal */ - Word16 *output, /* o : synthesized transitions signal */ - Word32 Hilbert_Mem[], /* i/o: memory */ - Word16 state_lsyn_filt_shb_local[],/* i/o: memory */ - Word16 mem_resamp_HB_32k[], /* i/o: memory */ + const Word16 *input, /* i : gain shape overlap buffer */ + const Word16 *old_hb_synth, /* i : synthesized HB from previous frame */ + Word16 length, /* i : targeted length of transition signal */ + Word16 *output, /* o : synthesized transitions signal */ + Word32 Hilbert_Mem[], /* i/o: memory */ + Word16 state_lsyn_filt_shb_local[], /* i/o: memory */ + Word16 mem_resamp_HB_32k[], /* i/o: memory */ Word16 *syn_dm_phase, Word32 target_fs, Word16 *up_mem, - Word16 rf_flag - , Word32 bitrate -) + Word16 rf_flag, + Word32 bitrate ) { Word16 i; Word16 syn_overlap_32k[L_FRAME32k]; Word32 L_tmp; - Word16 ol_len = 2*SHB_OVERLAP_LEN; + Word16 ol_len = 2 * SHB_OVERLAP_LEN; /* upsample overlap snippet */ Interpolate_allpass_steep_fx( input, state_lsyn_filt_shb_local, SHB_OVERLAP_LEN, syn_overlap_32k ); /* perform spectral flip and downmix with overlap snippet to match HB synth */ test(); - IF( (rf_flag != 0) || EQ_32( bitrate, ACELP_9k60 )) + IF( ( rf_flag != 0 ) || EQ_32( bitrate, ACELP_9k60 ) ) { - flip_and_downmix_generic_fx( syn_overlap_32k, syn_overlap_32k, 2*SHB_OVERLAP_LEN, Hilbert_Mem, - Hilbert_Mem + HILBERT_ORDER1, Hilbert_Mem + (HILBERT_ORDER1+2*HILBERT_ORDER2), + flip_and_downmix_generic_fx( syn_overlap_32k, syn_overlap_32k, 2 * SHB_OVERLAP_LEN, Hilbert_Mem, + Hilbert_Mem + HILBERT_ORDER1, Hilbert_Mem + ( HILBERT_ORDER1 + 2 * HILBERT_ORDER2 ), syn_dm_phase ); } ELSE { - FOR(i = 0; i < ol_len; i=i+2) + FOR( i = 0; i < ol_len; i = i + 2 ) { - syn_overlap_32k[i] = negate(syn_overlap_32k[i]); + syn_overlap_32k[i] = negate( syn_overlap_32k[i] ); move16(); - syn_overlap_32k[i+1] = syn_overlap_32k[i+1]; + syn_overlap_32k[i + 1] = syn_overlap_32k[i + 1]; move16(); } } /* cross fade of overlap snippet and mirrored HB synth from previous frame */ - FOR ( i = 0; i < ol_len; i++ ) + FOR( i = 0; i < ol_len; i++ ) { - L_tmp = L_mult( window_shb_32k_fx[i], old_hb_synth[L_SHB_TRANSITION_LENGTH-1-i] ); - output[i] = mac_r( L_tmp, window_shb_32k_fx[2*L_SHB_LAHEAD-1-i], syn_overlap_32k[i] ); + L_tmp = L_mult( window_shb_32k_fx[i], old_hb_synth[L_SHB_TRANSITION_LENGTH - 1 - i] ); + output[i] = mac_r( L_tmp, window_shb_32k_fx[2 * L_SHB_LAHEAD - 1 - i], syn_overlap_32k[i] ); } /* fill transition signal with mirrored HB synth from previous frame to fully fill delay alignment buffer gap */ - FOR ( ; i < length; i++) + FOR( ; i < length; i++ ) { - output[i] = old_hb_synth[L_SHB_TRANSITION_LENGTH-1-i]; + output[i] = old_hb_synth[L_SHB_TRANSITION_LENGTH - 1 - i]; } - IF ( EQ_32( target_fs, 48000 )) + IF( EQ_32( target_fs, 48000 ) ) { interpolate_3_over_2_allpass_fx( output, length, output, up_mem, allpass_poles_3_ov_2 ); } - ELSE IF( EQ_32( target_fs, 16000 )) + ELSE IF( EQ_32( target_fs, 16000 ) ) { Decimate_allpass_steep_fx( output, mem_resamp_HB_32k, L_FRAME32k, output ); } @@ -4809,60 +4794,59 @@ void GenTransition_fx( *---------------------------------------------------------------------*/ void GenTransition_WB_fx( - const Word16 *input, /* i : gain shape overlap buffer */ - const Word16 *old_hb_synth, /* i : synthesized HB from previous frame */ - const Word16 prev_Qx, /* i : scaling of old_hb_synth */ - Word16 length, /* i : targeted length of transition signal */ - Word16 *output, /* o : synthesized transitions signal */ + const Word16 *input, /* i : gain shape overlap buffer */ + const Word16 *old_hb_synth, /* i : synthesized HB from previous frame */ + const Word16 prev_Qx, /* i : scaling of old_hb_synth */ + Word16 length, /* i : targeted length of transition signal */ + Word16 *output, /* o : synthesized transitions signal */ Word16 state_lsyn_filt_shb1[], Word16 state_lsyn_filt_shb2[], Word32 output_Fs, - Word16 *up_mem -) + Word16 *up_mem ) { Word16 i; Word32 L_tmp; Word16 speech_buf_16k1[L_FRAME16k], speech_buf_16k2[L_FRAME16k]; Word16 upsampled_synth[L_FRAME48k]; - Word16 input_scaled[SHB_OVERLAP_LEN/2]; + Word16 input_scaled[SHB_OVERLAP_LEN / 2]; /* upsample overlap snippet */ - Copy_Scale_sig(input, input_scaled, SHB_OVERLAP_LEN/2, prev_Qx); - Interpolate_allpass_steep_fx( input_scaled, state_lsyn_filt_shb1, SHB_OVERLAP_LEN/2, speech_buf_16k1); - Interpolate_allpass_steep_fx( speech_buf_16k1, state_lsyn_filt_shb2, SHB_OVERLAP_LEN, speech_buf_16k2); + Copy_Scale_sig( input, input_scaled, SHB_OVERLAP_LEN / 2, prev_Qx ); + Interpolate_allpass_steep_fx( input_scaled, state_lsyn_filt_shb1, SHB_OVERLAP_LEN / 2, speech_buf_16k1 ); + Interpolate_allpass_steep_fx( speech_buf_16k1, state_lsyn_filt_shb2, SHB_OVERLAP_LEN, speech_buf_16k2 ); /* perform spectral flip and downmix with overlap snippet to match HB synth */ - FOR(i = 0; i < SHB_OVERLAP_LEN; i+=2) + FOR( i = 0; i < SHB_OVERLAP_LEN; i += 2 ) { - speech_buf_16k2[i] = negate(speech_buf_16k2[i]); - speech_buf_16k2[i+1] = speech_buf_16k2[i+1]; + speech_buf_16k2[i] = negate( speech_buf_16k2[i] ); + speech_buf_16k2[i + 1] = speech_buf_16k2[i + 1]; } /* cross fade of overlap snippet and mirrored HB synth from previous frame */ - FOR (i=0; ihBWE_TD; - IF( NE_16(st_fx->last_core,ACELP_CORE)) + IF( NE_16( st_fx->last_core, ACELP_CORE ) ) { - set16_fx(hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); - hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l(0); + set16_fx( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); + hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 ); st_fx->prev_Q_bwe_exc = 31; move16(); } test(); - IF( EQ_16(bandwidth, WB)) + IF( EQ_16( bandwidth, WB ) ) { - wb_tbe_extras_reset_fx(hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx ); - wb_tbe_extras_reset_synth_fx(hBWE_TD->state_lsyn_filt_shb_fx, hBWE_TD->state_lsyn_filt_dwn_shb_fx, hBWE_TD->state_32and48k_WB_upsample_fx, hBWE_TD->mem_resamp_HB_fx ); + wb_tbe_extras_reset_fx( hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx ); + wb_tbe_extras_reset_synth_fx( hBWE_TD->state_lsyn_filt_shb_fx, hBWE_TD->state_lsyn_filt_dwn_shb_fx, hBWE_TD->state_32and48k_WB_upsample_fx, hBWE_TD->mem_resamp_HB_fx ); - set16_fx(hBWE_TD->mem_genSHBexc_filt_down_shb_fx, 0, 7 ); - set16_fx(hBWE_TD->state_lpc_syn_fx, 0, 10 ); - set16_fx(hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD/4 ); - set16_fx(hBWE_TD->syn_overlap_fx, 0, L_SHB_LAHEAD ); - set32_fx(hBWE_TD->mem_csfilt_fx, 0, 2 ); + set16_fx( hBWE_TD->mem_genSHBexc_filt_down_shb_fx, 0, 7 ); + set16_fx( hBWE_TD->state_lpc_syn_fx, 0, 10 ); + set16_fx( hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD / 4 ); + set16_fx( hBWE_TD->syn_overlap_fx, 0, L_SHB_LAHEAD ); + set32_fx( hBWE_TD->mem_csfilt_fx, 0, 2 ); } - ELSE IF( EQ_16(bandwidth, SWB)||EQ_16(bandwidth,FB)) + ELSE IF( EQ_16( bandwidth, SWB ) || EQ_16( bandwidth, FB ) ) { - swb_tbe_reset_fx(hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, - hBWE_TD->syn_overlap_fx, hBWE_TD->state_syn_shbexc_fx, &(hBWE_TD->tbe_demph_fx), - &(hBWE_TD->tbe_premph_fx), hBWE_TD->mem_stp_swb_fx, &(hBWE_TD->gain_prec_swb_fx) ); + swb_tbe_reset_fx( hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, + hBWE_TD->syn_overlap_fx, hBWE_TD->state_syn_shbexc_fx, &( hBWE_TD->tbe_demph_fx ), + &( hBWE_TD->tbe_premph_fx ), hBWE_TD->mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ) ); - swb_tbe_reset_synth_fx(hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx ); + swb_tbe_reset_synth_fx( hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx ); - set16_fx( st_fx->GainShape_Delay, 0, NUM_SHB_SUBFR/2 ); - set16_fx(hBWE_TD->int_3_over_2_tbemem_dec_fx, 0, INTERP_3_2_MEM_LEN); - set32_fx(hBWE_TD->int_3_over_2_tbemem_dec_fx_32, 0, INTERP_3_2_MEM_LEN); - set16_fx(hBWE_TD->mem_resamp_HB_32k_fx, 0, 2*ALLPASSSECTIONS_STEEP+1 ); - set32_fx(hBWE_TD->mem_resamp_HB_32k_fx_32, 0, 2 * ALLPASSSECTIONS_STEEP + 1); + set16_fx( st_fx->GainShape_Delay, 0, NUM_SHB_SUBFR / 2 ); + set16_fx( hBWE_TD->int_3_over_2_tbemem_dec_fx, 0, INTERP_3_2_MEM_LEN ); + set32_fx( hBWE_TD->int_3_over_2_tbemem_dec_fx_32, 0, INTERP_3_2_MEM_LEN ); + set16_fx( hBWE_TD->mem_resamp_HB_32k_fx, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); + set32_fx( hBWE_TD->mem_resamp_HB_32k_fx_32, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); - IF( EQ_16(bandwidth, FB)) + IF( EQ_16( bandwidth, FB ) ) { st_fx->prev_fb_ener_adjust_fx = 0; - set16_fx(hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); + set16_fx( hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); hBWE_TD->fb_tbe_demph_fx = 0; - fb_tbe_reset_synth_fx(hBWE_TD->fbbwe_hpf_mem_fx, hBWE_TD->fbbwe_hpf_mem_fx_Q,&hBWE_TD->prev_fbbwe_ratio_fx ); + fb_tbe_reset_synth_fx( hBWE_TD->fbbwe_hpf_mem_fx, hBWE_TD->fbbwe_hpf_mem_fx_Q, &hBWE_TD->prev_fbbwe_ratio_fx ); } } @@ -4967,10 +4951,10 @@ void TBEreset_dec_ivas_fx( set16_fx( hBWE_TD->int_3_over_2_tbemem_dec_fx, 0, INTERP_3_2_MEM_LEN ); set32_fx( hBWE_TD->int_3_over_2_tbemem_dec_fx_32, 0, INTERP_3_2_MEM_LEN ); set16_fx( hBWE_TD->mem_resamp_HB_32k_fx, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); - set32_fx(hBWE_TD->mem_resamp_HB_32k_fx_32, 0, 2 * ALLPASSSECTIONS_STEEP + 1); + set32_fx( hBWE_TD->mem_resamp_HB_32k_fx_32, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); hBWE_TD->prev_pow_exc16kWhtnd_fx32 = 1; /* Q0 1.f */ hBWE_TD->prev_mix_factor_fx = 32767; /* Q15 1.f */ - //swb_tbe_reset_synth_fx( hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx ); + // swb_tbe_reset_synth_fx( hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx ); swb_tbe_reset_synth_ivas_fx( hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32 ); @@ -5070,72 +5054,76 @@ void td_bwe_dec_init_ivas_fx( } #endif void td_bwe_dec_init_fx( - Decoder_State* st_fx, /* i/o: SHB decoder structure */ + Decoder_State *st_fx, /* i/o: SHB decoder structure */ TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ -#ifdef ADD_IVAS_BWE - const Word16 extl, /* i : BWE extension layer */ +#ifdef ADD_IVAS_BWE + const Word16 extl, /* i : BWE extension layer */ #endif - const Word32 output_Fs /* i : output sampling rate */ + const Word32 output_Fs /* i : output sampling rate */ ) { int16_t i; /* init. SHB buffers */; - InitSWBdecBuffer_fx(st_fx); + InitSWBdecBuffer_fx( st_fx ); /* reset SHB buffers */ - ResetSHBbuffer_Dec_fx(st_fx); - IF(EQ_32(output_Fs, 48000)) + ResetSHBbuffer_Dec_fx( st_fx ); + IF( EQ_32( output_Fs, 48000 ) ) { - set32_fx(hBWE_TD->fbbwe_hpf_mem_fx[0], 0, 4); - set32_fx(hBWE_TD->fbbwe_hpf_mem_fx[1], 0, 4); - set32_fx(hBWE_TD->fbbwe_hpf_mem_fx[2], 0, 4); - set32_fx(hBWE_TD->fbbwe_hpf_mem_fx[3], 0, 4); - set16_fx(hBWE_TD->fbbwe_hpf_mem_fx_Q, 0, 4); + set32_fx( hBWE_TD->fbbwe_hpf_mem_fx[0], 0, 4 ); + set32_fx( hBWE_TD->fbbwe_hpf_mem_fx[1], 0, 4 ); + set32_fx( hBWE_TD->fbbwe_hpf_mem_fx[2], 0, 4 ); + set32_fx( hBWE_TD->fbbwe_hpf_mem_fx[3], 0, 4 ); + set16_fx( hBWE_TD->fbbwe_hpf_mem_fx_Q, 0, 4 ); } - set16_fx(hBWE_TD->mem_resamp_HB_fx, 0, INTERP_3_1_MEM_LEN); + set16_fx( hBWE_TD->mem_resamp_HB_fx, 0, INTERP_3_1_MEM_LEN ); - set16_fx(hBWE_TD->mem_resamp_HB_32k_fx, 0, 2 * ALLPASSSECTIONS_STEEP + 1); - set32_fx(hBWE_TD->mem_resamp_HB_32k_fx_32, 0, 2 * ALLPASSSECTIONS_STEEP + 1); + set16_fx( hBWE_TD->mem_resamp_HB_32k_fx, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); + set32_fx( hBWE_TD->mem_resamp_HB_32k_fx_32, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); hBWE_TD->tilt_mem_fx = 0; move16(); - set16_fx(hBWE_TD->prev_lsf_diff_fx, 16384, LPC_SHB_ORDER - 2); + set16_fx( hBWE_TD->prev_lsf_diff_fx, 16384, LPC_SHB_ORDER - 2 ); hBWE_TD->prev_tilt_para_fx = 0; move16(); - set16_fx(hBWE_TD->cur_sub_Aq_fx, 0, M + 1); - set16_fx(hBWE_TD->int_3_over_2_tbemem_dec_fx, 0, INTERP_3_2_MEM_LEN); - set32_fx(hBWE_TD->int_3_over_2_tbemem_dec_fx_32, 0, INTERP_3_2_MEM_LEN); + set16_fx( hBWE_TD->cur_sub_Aq_fx, 0, M + 1 ); + set16_fx( hBWE_TD->int_3_over_2_tbemem_dec_fx, 0, INTERP_3_2_MEM_LEN ); + set32_fx( hBWE_TD->int_3_over_2_tbemem_dec_fx_32, 0, INTERP_3_2_MEM_LEN ); /* TD BWE post-processing */ hBWE_TD->ptr_mem_stp_swb_fx = hBWE_TD->mem_stp_swb_fx + LPC_SHB_ORDER - 1; - set16_fx(hBWE_TD->mem_zero_swb_fx, 0, LPC_SHB_ORDER); + set16_fx( hBWE_TD->mem_zero_swb_fx, 0, LPC_SHB_ORDER ); - FOR(i = 0; i < LPC_SHB_ORDER; i++) + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { hBWE_TD->swb_lsp_prev_interp_fx[i] = swb_lsp_prev_interp_init[i]; move16(); } - hBWE_TD->prev1_shb_ener_sf_fx = 32767; /* Q15*/ move16(); - hBWE_TD->prev2_shb_ener_sf_fx = 32767; /* Q15*/ move16(); - hBWE_TD->prev3_shb_ener_sf_fx = 32767; /* Q15*/ move16(); - hBWE_TD->prev_res_shb_gshape_fx = 8192; /* 0.125 in Q14*/ move16(); - hBWE_TD->prev_mixFactors_fx = 16384; /* 0.5 in Q15*/ move16(); + hBWE_TD->prev1_shb_ener_sf_fx = 32767; /* Q15*/ + move16(); + hBWE_TD->prev2_shb_ener_sf_fx = 32767; /* Q15*/ + move16(); + hBWE_TD->prev3_shb_ener_sf_fx = 32767; /* Q15*/ + move16(); + hBWE_TD->prev_res_shb_gshape_fx = 8192; /* 0.125 in Q14*/ + move16(); + hBWE_TD->prev_mixFactors_fx = 16384; /* 0.5 in Q15*/ + move16(); hBWE_TD->prev_GainShape_fx = 0; move16(); st_fx->prev_Q_bwe_exc_fb = 51; move16(); - set16_fx(hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER); + set16_fx( hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); hBWE_TD->fb_tbe_demph_fx = 0; move16(); + set16_fx( hBWE_TD->old_hb_synth_fx, 0, L_FRAME48k ); - set16_fx(hBWE_TD->old_hb_synth_fx, 0, L_FRAME48k); - - hBWE_TD->prev_ener_fx = L_deposit_l(0); + hBWE_TD->prev_ener_fx = L_deposit_l( 0 ); return; diff --git a/lib_dec/syn_outp_fx.c b/lib_dec/syn_outp_fx.c index e4299b6dd..d291ba3e4 100644 --- a/lib_dec/syn_outp_fx.c +++ b/lib_dec/syn_outp_fx.c @@ -3,10 +3,10 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Debug prototypes */ -#include "prot_fx2.h" /* Debug prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "prot_fx1.h" /* Debug prototypes */ +#include "prot_fx2.h" /* Debug prototypes */ /*-------------------------------------------------------------------* * syn_output() @@ -16,9 +16,9 @@ void syn_output_fx( const Word16 codec_mode, /* i : MODE1 or MODE2 */ - Word16 *synth, /* i/o: float synthesis signal */ + Word16 *synth, /* i/o: float synthesis signal */ const Word16 output_frame, /* i : output frame length */ - Word16 *synth_out, /* o : integer 16 bits synthesis signal */ + Word16 *synth_out, /* o : integer 16 bits synthesis signal */ const Word16 Q_syn2 /* i : Synthesis scaling factor */ ) { @@ -33,13 +33,13 @@ void syn_output_fx( *-----------------------------------------------------------------*/ test(); - IF( EQ_16(codec_mode, MODE2) || EQ_16(output_frame,L_FRAME8k)) + IF( EQ_16( codec_mode, MODE2 ) || EQ_16( output_frame, L_FRAME8k ) ) { /* integer conversion */ /*mvr2s( synth, synth_out, output_frame ); */ - FOR (i = 0; i < output_frame; i++) + FOR( i = 0; i < output_frame; i++ ) { - L_tmp = L_deposit_h(synth[i]); + L_tmp = L_deposit_h( synth[i] ); #ifdef BASOP_NOGLOB synth_out[i] = round_fx_sat( L_shr_sat( L_tmp, tmp ) ); #else @@ -49,7 +49,7 @@ void syn_output_fx( } ELSE { - Copy_Scale_sig( synth, synth_out, output_frame, negate(tmp) ); + Copy_Scale_sig( synth, synth_out, output_frame, negate( tmp ) ); } return; @@ -61,11 +61,11 @@ void syn_output_fx( * Output synthesis signal with compensation for saturation *-------------------------------------------------------------------*/ void unscale_AGC( - const Word16 x[], /* i: 16kHz synthesis Qx */ - const Word16 Qx, /* i: scale factor of x */ - Word16 y[], /* o: output vector Q0 */ - Word16 mem[], /* i/o: mem[2] should be init to [0,0] */ - const Word16 n /* i: vector size */ + const Word16 x[], /* i: 16kHz synthesis Qx */ + const Word16 Qx, /* i: scale factor of x */ + Word16 y[], /* o: output vector Q0 */ + Word16 mem[], /* i/o: mem[2] should be init to [0,0] */ + const Word16 n /* i: vector size */ ) { Word16 i, fac, tmp, frame_fac, max_val; @@ -78,51 +78,51 @@ void unscale_AGC( * calculate AGC factor to avoid saturation *----------------------------------------------------------------*/ - max_val = abs_s(x[0]); - FOR (i = 1; i < n; i++) + max_val = abs_s( x[0] ); + FOR( i = 1; i < n; i++ ) { - max_val = s_max(max_val, abs_s(x[i])); + max_val = s_max( max_val, abs_s( x[i] ) ); } BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB - tmp = shl_o(30000, Qx, &Overflow); /* saturation can occur here */ + tmp = shl_o( 30000, Qx, &Overflow ); /* saturation can occur here */ #else - tmp = shl(30000, Qx); /* saturation can occurs here */ + tmp = shl( 30000, Qx ); /* saturation can occurs here */ #endif BASOP_SATURATE_WARNING_ON_EVS frame_fac = 0; move16(); - IF (GT_16(max_val, tmp)) + IF( GT_16( max_val, tmp ) ) { - frame_fac = sub(16384, div_s(shr(tmp, 1), max_val)); /* frame fac in Q15 */ + frame_fac = sub( 16384, div_s( shr( tmp, 1 ), max_val ) ); /* frame fac in Q15 */ } /*----------------------------------------------------------------* * AGC *----------------------------------------------------------------*/ /* update AGC factor (slowly) */ - fac = mac_r(L_mult(32440, mem[0]), 328, frame_fac); + fac = mac_r( L_mult( 32440, mem[0] ), 328, frame_fac ); - L_tmp = L_mult(x[0], 16384); - L_tmp = L_msu0(L_tmp, fac, x[0]); - L_tmp = L_msu(L_tmp, fac, mem[1]); - L_tmp = L_shr(L_tmp, -1); /* saturation can occur here */ + L_tmp = L_mult( x[0], 16384 ); + L_tmp = L_msu0( L_tmp, fac, x[0] ); + L_tmp = L_msu( L_tmp, fac, mem[1] ); + L_tmp = L_shr( L_tmp, -1 ); /* saturation can occur here */ - y[0] = round_fx(L_tmp); + y[0] = round_fx( L_tmp ); - FOR (i = 1; i < n; i++) + FOR( i = 1; i < n; i++ ) { /* update AGC factor (slowly) */ - fac = mac_r(L_mult(32440, fac), 328, frame_fac); + fac = mac_r( L_mult( 32440, fac ), 328, frame_fac ); - L_tmp = L_deposit_h(x[i]); - L_tmp = L_msu(L_tmp, fac, x[i]); - L_tmp = L_msu(L_tmp, fac, x[i-1]); - y[i] = round_fx(L_tmp); + L_tmp = L_deposit_h( x[i] ); + L_tmp = L_msu( L_tmp, fac, x[i] ); + L_tmp = L_msu( L_tmp, fac, x[i - 1] ); + y[i] = round_fx( L_tmp ); } mem[0] = fac; move16(); - mem[1] = shr(x[sub(i, 1)], 1); + mem[1] = shr( x[sub( i, 1 )], 1 ); move16(); } diff --git a/lib_dec/tcq_core_dec_fx.c b/lib_dec/tcq_core_dec_fx.c index e2acd3882..894372201 100644 --- a/lib_dec/tcq_core_dec_fx.c +++ b/lib_dec/tcq_core_dec_fx.c @@ -3,9 +3,9 @@ ====================================================================================*/ #include #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ #include "prot_fx1.h" #include "prot_fx2.h" /*---------------------------------------------------------------------* @@ -16,12 +16,12 @@ void tcq_core_LR_dec_fx( Decoder_State *st_fx, - Word16 *inp_vector_fx, /* x5 */ + Word16 *inp_vector_fx, /* x5 */ const Word16 bit_budget, const Word16 BANDS, const Word16 *band_start, const Word16 *band_width, - Word32 *Rk_fx, /* Q16 */ + Word32 *Rk_fx, /* Q16 */ Word16 *npulses, Word16 *k_sort, const Word16 *p2a_flags, @@ -29,13 +29,12 @@ void tcq_core_LR_dec_fx( const Word16 *last_bitalloc, const Word16 input_frame, const Word16 adjustFlag, - const Word16 *is_transient -) + const Word16 *is_transient ) { Word16 i, j, k; Word32 Rk_sort_fx[NB_SFM]; Word16 flag_wbnb = 0; - Word16 USQ_TCQ[NB_SFM]; /* TCQ is selected by default*/ + Word16 USQ_TCQ[NB_SFM]; /* TCQ is selected by default*/ Word16 nb_bytes, pulsesnum, nz; Word16 positions_fx[L_FRAME48k]; @@ -48,7 +47,7 @@ void tcq_core_LR_dec_fx( Word16 nzb = 0; Word16 nzbands = 0; Word16 lsbtcq_bits = TCQ_AMP; - Word16 tcq_arbits = 2; + Word16 tcq_arbits = 2; /* LSB TCQ variables*/ Word16 dpath[280]; @@ -61,27 +60,27 @@ void tcq_core_LR_dec_fx( Word32 divider = 0; #ifndef BASOP_NOGLOB_DECLARE_LOCAL - if (Overflow == 1) + if ( Overflow == 1 ) { Overflow = 0; /* set overflow flag to zero before entering TCQ functions without any message */ } #endif /* initialization */ - set16_fx(dpath, 0, 280); + set16_fx( dpath, 0, 280 ); set16_fx( USQ_TCQ, 0, NB_SFM ); - set16_fx(positions_fx, 0, L_FRAME32k); - set16_fx(mbuffer_fx, 0, 560); + set16_fx( positions_fx, 0, L_FRAME32k ); + set16_fx( mbuffer_fx, 0, 560 ); test(); test(); - IF ( LE_16(input_frame, L_FRAME16k)&&adjustFlag==0&&*is_transient==0) + IF( LE_16( input_frame, L_FRAME16k ) && adjustFlag == 0 && *is_transient == 0 ) { flag_wbnb = 1; move16(); lsbtcq_bits = 0; move16(); - tcq_arbits = 0; + tcq_arbits = 0; move16(); } @@ -89,13 +88,13 @@ void tcq_core_LR_dec_fx( pbs_fx = &bs_fx; pbs_fx->curPos = 7; move16(); - pbs_fx->numbits = L_deposit_l(0); - pbs_fx->numByte = L_deposit_l(0); + pbs_fx->numbits = L_deposit_l( 0 ); + pbs_fx->numByte = L_deposit_l( 0 ); /* Bits distribution analysis*/ - FOR ( i = 0; i < BANDS; i++ ) + FOR( i = 0; i < BANDS; i++ ) { - IF (GE_32(ar_div(Rk_fx[i], band_width[i]), 49152)) + IF( GE_32( ar_div( Rk_fx[i], band_width[i] ), 49152 ) ) { /* USQ used for high importance bands*/ USQ_TCQ[i] = 1; @@ -109,66 +108,66 @@ void tcq_core_LR_dec_fx( } if ( Rk_fx[i] > 0 ) { - nzbands = add(nzbands, 1); + nzbands = add( nzbands, 1 ); } } - FOR ( j = 0; j < BANDS; j++ ) + FOR( j = 0; j < BANDS; j++ ) { if ( Rk_fx[j] > 0 ) { - nzb = add(nzb, 1); + nzb = add( nzb, 1 ); } } - bsub_fx = L_shl(L_add(tcq_arbits, lsbtcq_bits), 16); - if( bsub_fx > 0) + bsub_fx = L_shl( L_add( tcq_arbits, lsbtcq_bits ), 16 ); + if ( bsub_fx > 0 ) { - bsub_fx = L_add( bsub_fx, 2048); + bsub_fx = L_add( bsub_fx, 2048 ); } - FOR ( j = BANDS - 1; j >= 0; j-- ) + FOR( j = BANDS - 1; j >= 0; j-- ) { - IF ( Rk_fx[j] > 0 ) + IF( Rk_fx[j] > 0 ) { - Rk_fx[j] = L_sub(Rk_fx[j], ar_div(bsub_fx, nzb)); - IF ( Rk_fx[j] < 0) + Rk_fx[j] = L_sub( Rk_fx[j], ar_div( bsub_fx, nzb ) ); + IF( Rk_fx[j] < 0 ) { - bsub_fx = L_sub(bsub_fx, L_add(ar_div(bsub_fx, nzb), Rk_fx[j])); - Rk_fx[j] = L_deposit_l(0); + bsub_fx = L_sub( bsub_fx, L_add( ar_div( bsub_fx, nzb ), Rk_fx[j] ) ); + Rk_fx[j] = L_deposit_l( 0 ); } ELSE { - bsub_fx = L_sub(bsub_fx, ar_div(bsub_fx, nzb)); + bsub_fx = L_sub( bsub_fx, ar_div( bsub_fx, nzb ) ); } - nzb = sub(nzb, 1); + nzb = sub( nzb, 1 ); } } - srt_vec_ind_fx(Rk_fx, Rk_sort_fx, k_sort, BANDS); + srt_vec_ind_fx( Rk_fx, Rk_sort_fx, k_sort, BANDS ); /*read the bits*/ - nb_bytes = shr(bit_budget, 3); - k = sub(bit_budget, shl(nb_bytes, 3)); - FOR ( i = 0; i < nb_bytes; i++ ) + nb_bytes = shr( bit_budget, 3 ); + k = sub( bit_budget, shl( nb_bytes, 3 ) ); + FOR( i = 0; i < nb_bytes; i++ ) { - pbs_fx->buf[i] = (UWord8)get_next_indice(st_fx, 8); + pbs_fx->buf[i] = (UWord8) get_next_indice( st_fx, 8 ); move16(); } - IF ( k > 0 ) + IF( k > 0 ) { Word16 tmp; - tmp = (UWord8)get_next_indice(st_fx, k); - pbs_fx->buf[nb_bytes] = (UWord8)shl(tmp,sub(8,k)); + tmp = (UWord8) get_next_indice( st_fx, k ); + pbs_fx->buf[nb_bytes] = (UWord8) shl( tmp, sub( 8, k ) ); /* i++; nb_bytes++; */ - i = add(i, 1); - nb_bytes = add(nb_bytes, 1); + i = add( i, 1 ); + nb_bytes = add( nb_bytes, 1 ); } /* set two more bytes, which are used to flush the arithmetic coder, to 0 -> this avoids reading of uninitialized memory */ - nb_bytes = s_min(add(nb_bytes, 2), MAX_SIZEBUF_PBITSTREAM); - FOR ( ; i < nb_bytes; i++ ) + nb_bytes = s_min( add( nb_bytes, 2 ), MAX_SIZEBUF_PBITSTREAM ); + FOR( ; i < nb_bytes; i++ ) { pbs_fx->buf[i] = 0; move16(); @@ -177,34 +176,34 @@ void tcq_core_LR_dec_fx( pbs_fx->maxBytes = nb_bytes; move16(); - ar_decoder_start_fx(pardec_fx, pbs_fx); + ar_decoder_start_fx( pardec_fx, pbs_fx ); - delta_fx = L_deposit_l(0); - surplus_fx = L_deposit_l(0); + delta_fx = L_deposit_l( 0 ); + surplus_fx = L_deposit_l( 0 ); test(); test(); - IF( LE_16(input_frame, L_FRAME16k)&&adjustFlag==0&&*is_transient==0) + IF( LE_16( input_frame, L_FRAME16k ) && adjustFlag == 0 && *is_transient == 0 ) { surplus_fx = -131072; - move32();/*16 */ + move32(); /*16 */ - bit_allocation_second_fx(Rk_fx, Rk_sort_fx, BANDS, band_width, k_sort, k_num, p2a_flags, p2a_bands, last_bitalloc, input_frame); + bit_allocation_second_fx( Rk_fx, Rk_sort_fx, BANDS, band_width, k_sort, k_num, p2a_flags, p2a_bands, last_bitalloc, input_frame ); nzbands = 0; move16(); - FOR ( j = 0; j < BANDS; j++ ) + FOR( j = 0; j < BANDS; j++ ) { - IF( EQ_16(j, k_num[0])||EQ_16(j,k_num[1])) + IF( EQ_16( j, k_num[0] ) || EQ_16( j, k_num[1] ) ) { - sepbits = L_add( sepbits, Rk_fx[k_sort[j]]); + sepbits = L_add( sepbits, Rk_fx[k_sort[j]] ); } ELSE { - leftbits = L_add( leftbits, Rk_fx[k_sort[j]]); - if( Rk_fx[k_sort[j]] > 0 ) + leftbits = L_add( leftbits, Rk_fx[k_sort[j]] ); + if ( Rk_fx[k_sort[j]] > 0 ) { - nzbands = add(nzbands, 1); + nzbands = add( nzbands, 1 ); } } } @@ -212,18 +211,18 @@ void tcq_core_LR_dec_fx( FOR( k = 0; k < BANDS; k++ ) { test(); - IF( NE_16(k, k_num[0])&&NE_16(k,k_num[1])) + IF( NE_16( k, k_num[0] ) && NE_16( k, k_num[1] ) ) { test(); test(); - IF (Rk_fx[k_sort[k]] > 0 && USQ_TCQ[k_sort[k]] == 0) + IF( Rk_fx[k_sort[k]] > 0 && USQ_TCQ[k_sort[k]] == 0 ) { /* When number of bits per band is less than arithmetic bits overhead, this band is not encoded. It may happens when the actual number of bits per band is near same to estimated number of bits, for most bands (very unprobable but possible) */ - IF( L_add( Rk_fx[k_sort[k]], delta_fx) < 0 ) + IF( L_add( Rk_fx[k_sort[k]], delta_fx ) < 0 ) { pulsesnum = 0; move16(); @@ -235,17 +234,17 @@ void tcq_core_LR_dec_fx( IF( surplus_fx != 0 ) { /* surplus_fx += (Rk[k_sort[k]] + delta);*/ - surplus_fx = L_add( Rk_fx[k_sort[k]], surplus_fx); - surplus_fx = L_add( delta_fx, surplus_fx); + surplus_fx = L_add( Rk_fx[k_sort[k]], surplus_fx ); + surplus_fx = L_add( delta_fx, surplus_fx ); } } ELSE { /*get number of pulses */ pulsesnum = GetScale_fx( band_width[k_sort[k]], - L_add( Rk_fx[k_sort[k]], delta_fx), - &surplus_fx ); - leftbits = L_sub( leftbits, L_add( Rk_fx[k_sort[k]], delta_fx) ); + L_add( Rk_fx[k_sort[k]], delta_fx ), + &surplus_fx ); + leftbits = L_sub( leftbits, L_add( Rk_fx[k_sort[k]], delta_fx ) ); decode_position_ari_fx( pardec_fx, band_width[k_sort[k]], pulsesnum, &nz, &positions_fx[band_start[k_sort[k]]] ); /*decode tcq magniitude and update the surplus bits.*/ decode_mangitude_tcq_fx( pardec_fx, band_width[k_sort[k]], pulsesnum, nz, &positions_fx[band_start[k_sort[k]]], &inp_vector_fx[band_start[k_sort[k]]], &surplus_fx ); @@ -254,14 +253,14 @@ void tcq_core_LR_dec_fx( nzbands--; move16(); } - ELSE IF (Rk_fx[k_sort[k]] > 0 && EQ_16(USQ_TCQ[k_sort[k]], 1)) + ELSE IF( Rk_fx[k_sort[k]] > 0 && EQ_16( USQ_TCQ[k_sort[k]], 1 ) ) { /* When number of bits per band is less than arithmetic bits overhead, this band is not encoded. It may happens when the actual number of bits per band is near same to estimated number of bits, for most bands (very unprobable but possible) */ - IF( L_add( Rk_fx[k_sort[k]], delta_fx) < 0 ) + IF( L_add( Rk_fx[k_sort[k]], delta_fx ) < 0 ) { pulsesnum = 0; move16(); @@ -272,16 +271,16 @@ void tcq_core_LR_dec_fx( } IF( surplus_fx != 0 ) { - surplus_fx = L_add( Rk_fx[k_sort[k]], surplus_fx); - surplus_fx = L_add( delta_fx, surplus_fx); + surplus_fx = L_add( Rk_fx[k_sort[k]], surplus_fx ); + surplus_fx = L_add( delta_fx, surplus_fx ); } } ELSE { - pulsesnum = GetScale_fx(band_width[k_sort[k]], - L_add( Rk_fx[k_sort[k]], delta_fx), - &surplus_fx); - leftbits = L_sub( leftbits, L_add( Rk_fx[k_sort[k]], delta_fx) ); + pulsesnum = GetScale_fx( band_width[k_sort[k]], + L_add( Rk_fx[k_sort[k]], delta_fx ), + &surplus_fx ); + leftbits = L_sub( leftbits, L_add( Rk_fx[k_sort[k]], delta_fx ) ); decode_position_ari_fx( pardec_fx, band_width[k_sort[k]], pulsesnum, &nz, &positions_fx[band_start[k_sort[k]]] ); /*decode usq magnitude and don't need to update surplus bits*/ decode_magnitude_usq_fx( pardec_fx, band_width[k_sort[k]], pulsesnum, nz, &positions_fx[band_start[k_sort[k]]], &inp_vector_fx[band_start[k_sort[k]]] ); @@ -294,7 +293,7 @@ void tcq_core_LR_dec_fx( { pulsesnum = 0; move16(); - FOR ( i = 0; i < band_width[k_sort[k]]; i++ ) + FOR( i = 0; i < band_width[k_sort[k]]; i++ ) { inp_vector_fx[band_start[k_sort[k]] + i] = 0; move16(); @@ -304,7 +303,7 @@ void tcq_core_LR_dec_fx( npulses[k_sort[k]] = pulsesnum; move16(); - delta_fx = L_deposit_l(0); + delta_fx = L_deposit_l( 0 ); test(); IF( Rk_fx[k_sort[k]] > 0 && surplus_fx < 0 ) { @@ -317,17 +316,16 @@ void tcq_core_LR_dec_fx( divider = 2; } - IF( L_add( L_add( surplus_fx, sepbits), ar_div( leftbits, divider ) ) < 0 ) + IF( L_add( L_add( surplus_fx, sepbits ), ar_div( leftbits, divider ) ) < 0 ) { /* Overflow possible => start to distribute negative surplus */ - delta_fx = ar_div( surplus_fx + sepbits, nzbands); + delta_fx = ar_div( surplus_fx + sepbits, nzbands ); } else { delta_fx = 0; } - surplus_fx = L_sub(surplus_fx, delta_fx); - + surplus_fx = L_sub( surplus_fx, delta_fx ); } } } @@ -335,30 +333,30 @@ void tcq_core_LR_dec_fx( test(); test(); test(); - IF (( GT_32(surplus_fx,524288)&&EQ_16(input_frame,L_FRAME8k))||(GT_32(surplus_fx,786432)&&EQ_16(input_frame,L_FRAME16k))) + IF( ( GT_32( surplus_fx, 524288 ) && EQ_16( input_frame, L_FRAME8k ) ) || ( GT_32( surplus_fx, 786432 ) && EQ_16( input_frame, L_FRAME16k ) ) ) { - bit_surplus_fx[0] = Mult_32_16(surplus_fx,24576);/* Q16 */ - bit_surplus_fx[1] = Mult_32_16(surplus_fx,8192);/* Q16 */ + bit_surplus_fx[0] = Mult_32_16( surplus_fx, 24576 ); /* Q16 */ + bit_surplus_fx[1] = Mult_32_16( surplus_fx, 8192 ); /* Q16 */ } ELSE { bit_surplus_fx[0] = surplus_fx; move32(); - bit_surplus_fx[1] = L_deposit_l(0); + bit_surplus_fx[1] = L_deposit_l( 0 ); } - FOR ( k = 0; k < BANDS; k++ ) + FOR( k = 0; k < BANDS; k++ ) { - FOR ( j = 0; j < 2; j++ ) + FOR( j = 0; j < 2; j++ ) { - IF ( EQ_16(k, k_num[j])) + IF( EQ_16( k, k_num[j] ) ) { - Rk_fx[k_sort[k]] = L_add(Rk_fx[k_sort[k]],bit_surplus_fx[j]); + Rk_fx[k_sort[k]] = L_add( Rk_fx[k_sort[k]], bit_surplus_fx[j] ); move32(); test(); test(); - IF ( Rk_fx[k_sort[k]] > 0 && USQ_TCQ[k_sort[k]] == 0 ) + IF( Rk_fx[k_sort[k]] > 0 && USQ_TCQ[k_sort[k]] == 0 ) { /* get number of pulses */ pulsesnum = GetScale_fx( band_width[k_sort[k]], Rk_fx[k_sort[k]], &surplus_fx ); @@ -381,7 +379,7 @@ void tcq_core_LR_dec_fx( { pulsesnum = 0; move16(); - FOR ( i = 0; i < band_width[k_sort[k]]; i++ ) + FOR( i = 0; i < band_width[k_sort[k]]; i++ ) { inp_vector_fx[band_start[k_sort[k]] + i] = 0; move16(); @@ -396,11 +394,11 @@ void tcq_core_LR_dec_fx( } ELSE { - FOR ( k = 0; k < BANDS; k++ ) + FOR( k = 0; k < BANDS; k++ ) { - IF ( Rk_fx[k_sort[k]] > 0 ) + IF( Rk_fx[k_sort[k]] > 0 ) { - pulsesnum = GetScale_fx(band_width[k_sort[k]], Rk_fx[k_sort[k]] + delta_fx, &surplus_fx); + pulsesnum = GetScale_fx( band_width[k_sort[k]], Rk_fx[k_sort[k]] + delta_fx, &surplus_fx ); decode_position_ari_fx( pardec_fx, band_width[k_sort[k]], pulsesnum, &nz, &positions_fx[band_start[k_sort[k]]] ); @@ -408,13 +406,13 @@ void tcq_core_LR_dec_fx( decode_magnitude_usq_fx( pardec_fx, band_width[k_sort[k]], pulsesnum, nz, &positions_fx[band_start[k_sort[k]]], &inp_vector_fx[band_start[k_sort[k]]] ); decode_signs_fx( pardec_fx, band_width[k_sort[k]], &inp_vector_fx[band_start[k_sort[k]]] ); - nzbands = sub(nzbands, 1); + nzbands = sub( nzbands, 1 ); } ELSE { pulsesnum = 0; move16(); - FOR ( i = 0; i < band_width[k_sort[k]]; i++ ) + FOR( i = 0; i < band_width[k_sort[k]]; i++ ) { inp_vector_fx[band_start[k_sort[k]] + i] = 0; move16(); @@ -426,56 +424,55 @@ void tcq_core_LR_dec_fx( /* surplus distribution */ test(); - IF ( surplus_fx > 0 && nzbands > 0 ) + IF( surplus_fx > 0 && nzbands > 0 ) { - delta_fx = ar_div(surplus_fx, nzbands); - surplus_fx = L_sub(surplus_fx, delta_fx); + delta_fx = ar_div( surplus_fx, nzbands ); + surplus_fx = L_sub( surplus_fx, delta_fx ); } } } /* Load TCQ path from bitstream */ - LoadTCQdata_fx(pardec_fx, dpath, lsbtcq_bits); + LoadTCQdata_fx( pardec_fx, dpath, lsbtcq_bits ); - TCQLSBdec_fx(dpath, mbuffer_fx, 2*lsbtcq_bits); + TCQLSBdec_fx( dpath, mbuffer_fx, 2 * lsbtcq_bits ); - ar_decoder_done_fx(pardec_fx); + ar_decoder_done_fx( pardec_fx ); /* Restore TCQ */ - IF ( !flag_wbnb ) + IF( !flag_wbnb ) { - FOR ( k = 0; k < BANDS; k++) + FOR( k = 0; k < BANDS; k++ ) { - IF ( Rk_fx[k_sort[k]] > 0 ) + IF( Rk_fx[k_sort[k]] > 0 ) { - RestoreTCQdec_fx( &inp_vector_fx[ band_start[ k_sort[ k]]], band_width[k_sort[k]], &bcount, mbuffer_fx ); + RestoreTCQdec_fx( &inp_vector_fx[band_start[k_sort[k]]], band_width[k_sort[k]], &bcount, mbuffer_fx ); } } } ELSE { - FOR( k = 0; k < BANDS; k++) + FOR( k = 0; k < BANDS; k++ ) { test(); test(); IF( Rk_fx[k_sort[k]] > 0 && k != k_num[0] && k != k_num[1] ) { - RestoreTCQdec_fx( &inp_vector_fx[ band_start[ k_sort[ k]]], band_width[k_sort[k]], &bcount, mbuffer_fx ); + RestoreTCQdec_fx( &inp_vector_fx[band_start[k_sort[k]]], band_width[k_sort[k]], &bcount, mbuffer_fx ); } } - FOR ( k = 0; k < BANDS; k++) + FOR( k = 0; k < BANDS; k++ ) { test(); test(); - IF ( Rk_fx[k_sort[k]] > 0 && (k == k_num[0] || k == k_num[1]) ) + IF( Rk_fx[k_sort[k]] > 0 && ( k == k_num[0] || k == k_num[1] ) ) { - RestoreTCQdec_fx( &inp_vector_fx[ band_start[ k_sort[ k]]], band_width[k_sort[k]], &bcount, mbuffer_fx ); + RestoreTCQdec_fx( &inp_vector_fx[band_start[k_sort[k]]], band_width[k_sort[k]], &bcount, mbuffer_fx ); } } } - return; } diff --git a/lib_dec/tcx_utils_dec_fx.c b/lib_dec/tcx_utils_dec_fx.c index a3761f2cb..110de580f 100644 --- a/lib_dec/tcx_utils_dec_fx.c +++ b/lib_dec/tcx_utils_dec_fx.c @@ -20,16 +20,16 @@ * *--------------------------------------------------------------*/ void tcx_decoder_memory_update( - Word16 *xn_buf, /* i/o: mdct output buffer used also as temporary buffer */ - Word16 *synthout, /* o: synth */ - Word16 *A, /* i: Quantized LPC coefficients */ - Decoder_State *st, /* i/o: decoder memory state */ - Word8 fb /* i: fullband flag */ + Word16 *xn_buf, /* i/o: mdct output buffer used also as temporary buffer */ + Word16 *synthout, /* o: synth */ + Word16 *A, /* i: Quantized LPC coefficients */ + Decoder_State *st, /* i/o: decoder memory state */ + Word8 fb /* i: fullband flag */ ) { Word16 tmp; Word16 *synth; - Word16 buf[1+M+LFAC+L_FRAME_PLUS]; + Word16 buf[1 + M + LFAC + L_FRAME_PLUS]; Word16 L_frame_glob; Word16 preemph; @@ -38,45 +38,45 @@ void tcx_decoder_memory_update( move16(); /* Output synth */ - Copy(xn_buf, synthout, L_frame_glob); + Copy( xn_buf, synthout, L_frame_glob ); /* Update synth */ - synth = buf + M+1; - Copy(st->syn, buf, M+1); - Copy(xn_buf, synth, L_frame_glob); - Copy(synth + sub(L_frame_glob, M+1), st->syn, M+1); + synth = buf + M + 1; + Copy( st->syn, buf, M + 1 ); + Copy( xn_buf, synth, L_frame_glob ); + Copy( synth + sub( L_frame_glob, M + 1 ), st->syn, M + 1 ); - IF (NE_16(st->element_mode, IVAS_CPE_MDCT)) + IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { - IF(!fb) /* TV2FhG -> Condition differs from floating point */ + IF( !fb ) /* TV2FhG -> Condition differs from floating point */ { /* Emphasis of synth -> synth_pe */ tmp = synth[-M - 1]; move16(); - st->Q_syn = E_UTIL_f_preemph3(synth - M, preemph, add(M, L_frame_glob), &tmp, 1); + st->Q_syn = E_UTIL_f_preemph3( synth - M, preemph, add( M, L_frame_glob ), &tmp, 1 ); st->prev_Q_syn = st->Q_syn = st->Q_syn - 1; - Copy(synth + sub(L_frame_glob, M), st->mem_syn2_fx, M); - Copy(synth + sub(L_frame_glob, L_SYN_MEM), st->mem_syn_r, L_SYN_MEM); + Copy( synth + sub( L_frame_glob, M ), st->mem_syn2_fx, M ); + Copy( synth + sub( L_frame_glob, L_SYN_MEM ), st->mem_syn_r, L_SYN_MEM ); test(); - IF(st->tcxonly == 0 || LE_16(L_frame_glob, L_FRAME16k)) + IF( st->tcxonly == 0 || LE_16( L_frame_glob, L_FRAME16k ) ) { /* Update excitation */ - IF(NE_16(st->Q_syn + 1, st->Q_exc)) + IF( NE_16( st->Q_syn + 1, st->Q_exc ) ) { - Scale_sig(st->old_exc_fx, L_EXC_MEM_DEC, sub(st->Q_syn + 1, st->Q_exc)); + Scale_sig( st->old_exc_fx, L_EXC_MEM_DEC, sub( st->Q_syn + 1, st->Q_exc ) ); } st->Q_exc = st->Q_syn + 1; st->Q_subfr[0] = st->Q_subfr[1] = st->Q_subfr[2] = st->Q_subfr[3] = st->Q_subfr[4] = st->Q_exc; - assert(L_frame_glob < L_EXC_MEM_DEC); - Copy(st->old_exc_fx + L_frame_glob, st->old_exc_fx, sub(L_EXC_MEM_DEC, L_frame_glob)); - Residu3_fx(A, synth, st->old_exc_fx + sub(L_EXC_MEM_DEC, L_frame_glob), L_frame_glob, 1); + assert( L_frame_glob < L_EXC_MEM_DEC ); + Copy( st->old_exc_fx + L_frame_glob, st->old_exc_fx, sub( L_EXC_MEM_DEC, L_frame_glob ) ); + Residu3_fx( A, synth, st->old_exc_fx + sub( L_EXC_MEM_DEC, L_frame_glob ), L_frame_glob, 1 ); } /* Update old_Aq */ - Copy(A, st->old_Aq_12_8_fx, M + 1); + Copy( A, st->old_Aq_12_8_fx, M + 1 ); } } return; @@ -84,14 +84,14 @@ void tcx_decoder_memory_update( /* Returns: number of bits used (including "bits") */ Word16 tcx_ari_res_invQ_spec( - Word32 x_Q[], /* i/o: quantized spectrum Q31-e */ - Word16 x_Q_e, /* i: quantized spectrum exponent Q0 */ - Word16 L_frame, /* i: number of lines Q0 */ - const Word16 prm[], /* i: bitstream Q0 */ - Word16 target_bits, /* i: number of bits available Q0 */ - Word16 bits, /* i: number of bits used so far Q0 */ - Word16 deadzone, /* i: quantizer deadzone Q15 */ - const Word16 x_fac[] /* i: spectrum post-quantization factors Q14 */ + Word32 x_Q[], /* i/o: quantized spectrum Q31-e */ + Word16 x_Q_e, /* i: quantized spectrum exponent Q0 */ + Word16 L_frame, /* i: number of lines Q0 */ + const Word16 prm[], /* i: bitstream Q0 */ + Word16 target_bits, /* i: number of bits available Q0 */ + Word16 bits, /* i: number of bits used so far Q0 */ + Word16 deadzone, /* i: quantizer deadzone Q15 */ + const Word16 x_fac[] /* i: spectrum post-quantization factors Q14 */ ) { Word16 i, j, num_zeros; @@ -102,7 +102,7 @@ Word16 tcx_ari_res_invQ_spec( /* Limit the number of residual bits */ - target_bits = s_min(target_bits, NPRM_RESQ); + target_bits = s_min( target_bits, NPRM_RESQ ); /* Requantize the spectrum line-by-line */ @@ -110,40 +110,41 @@ Word16 tcx_ari_res_invQ_spec( num_zeros = 0; move16(); - FOR (i=0; i < L_frame; i++) + FOR( i = 0; i < L_frame; i++ ) { - IF (GE_16(bits, target_bits)) /* no bits left */ + IF( GE_16( bits, target_bits ) ) /* no bits left */ { BREAK; } - IF (x_Q[i] != 0) + IF( x_Q[i] != 0 ) { sign = x_fac[i]; move16(); - if (x_Q[i] < 0) sign = negate(sign); + if ( x_Q[i] < 0 ) + sign = negate( sign ); /* x_Q[i] += sign*(prm[bits++] * 0.5f - fac_m); */ - x_Q[i] = L_sub(x_Q[i], L_shr(L_mult(sign, add(deadzone, lshl(prm[bits], 15))), x_Q_e)); + x_Q[i] = L_sub( x_Q[i], L_shr( L_mult( sign, add( deadzone, lshl( prm[bits], 15 ) ) ), x_Q_e ) ); move32(); - bits = add(bits, 1); + bits = add( bits, 1 ); } ELSE { zeros[num_zeros] = i; move16(); - num_zeros = add(num_zeros, 1); + num_zeros = add( num_zeros, 1 ); } } /* Requantize zeroed-lines of the spectrum */ - fac_p = msu_r(1417339264l/*0.33f*2.0f Q31*/, deadzone, 21627/*0.33f*2.0f Q15*/); /* Q15 */ - target_bits = sub(target_bits, 1); /* reserve 1 bit for the check below */ + fac_p = msu_r( 1417339264l /*0.33f*2.0f Q31*/, deadzone, 21627 /*0.33f*2.0f Q15*/ ); /* Q15 */ + target_bits = sub( target_bits, 1 ); /* reserve 1 bit for the check below */ - s = sub(x_Q_e, 1); - FOR (j = 0; j < num_zeros; j++) + s = sub( x_Q_e, 1 ); + FOR( j = 0; j < num_zeros; j++ ) { - IF (GE_16(bits, target_bits)) /* 1 or 0 bits left */ + IF( GE_16( bits, target_bits ) ) /* 1 or 0 bits left */ { BREAK; } @@ -151,15 +152,16 @@ Word16 tcx_ari_res_invQ_spec( i = zeros[j]; move16(); - IF (prm[bits] != 0) + IF( prm[bits] != 0 ) { - bits = add(bits, 1); - L_tmp = L_mult(fac_p, x_fac[i]); /* Q30 */ - if (prm[bits] == 0) L_tmp = L_negate(L_tmp); - x_Q[i] = L_shr(L_tmp, s); + bits = add( bits, 1 ); + L_tmp = L_mult( fac_p, x_fac[i] ); /* Q30 */ + if ( prm[bits] == 0 ) + L_tmp = L_negate( L_tmp ); + x_Q[i] = L_shr( L_tmp, s ); move32(); } - bits = add(bits, 1); + bits = add( bits, 1 ); } @@ -174,8 +176,7 @@ Word16 tcx_res_invQ_gain( Word16 *gain_tcx, Word16 *gain_tcx_e, Word16 *prm, - Word16 resQBits -) + Word16 resQBits ) { Word16 bits; Word16 gain, tmp1, tmp2; @@ -185,27 +186,28 @@ Word16 tcx_res_invQ_gain( move16(); /* make sure we have a bit of headroom */ - IF (GT_16(gain, 0x7000)) + IF( GT_16( gain, 0x7000 ) ) { - gain = shr(gain, 1); - *gain_tcx_e = add(*gain_tcx_e, 1); + gain = shr( gain, 1 ); + *gain_tcx_e = add( *gain_tcx_e, 1 ); move16(); } /*Refine the gain quantization*/ - tmp1 = s_min(resQBits, TCX_RES_Q_BITS_GAIN); - FOR (bits=0; bits < tmp1; bits++) + tmp1 = s_min( resQBits, TCX_RES_Q_BITS_GAIN ); + FOR( bits = 0; bits < tmp1; bits++ ) { tmp2 = gain_corr_fac[bits]; move16(); - if (prm[bits] == 0) + if ( prm[bits] == 0 ) { tmp2 = gain_corr_inv_fac[bits]; move16(); } - gain = mult_r(gain, tmp2); - if (prm[bits] != 0) gain = shl(gain, 1); + gain = mult_r( gain, tmp2 ); + if ( prm[bits] != 0 ) + gain = shl( gain, 1 ); } *gain_tcx = gain; @@ -228,8 +230,7 @@ Word16 tcx_res_invQ_spec( Word16 resQBits, Word16 bits, Word16 sq_round, - const Word16 lf_deemph_factors[] -) + const Word16 lf_deemph_factors[] ) { Word16 i; Word16 fac_m, fac_p; @@ -238,45 +239,47 @@ Word16 tcx_res_invQ_spec( /* Limit the number of residual bits */ - resQBits = s_min(resQBits, NPRM_RESQ); + resQBits = s_min( resQBits, NPRM_RESQ ); /* Requantize the spectrum line-by-line */ - fac_m = shr(sq_round, 1); - fac_p = sub(0x4000, fac_m); + fac_m = shr( sq_round, 1 ); + fac_p = sub( 0x4000, fac_m ); lf_deemph_factor = 0x4000; move16(); - s = sub(x_e, 1); + s = sub( x_e, 1 ); - FOR (i = 0; i < L_frame; i++) + FOR( i = 0; i < L_frame; i++ ) { - IF (GE_16(bits, resQBits)) + IF( GE_16( bits, resQBits ) ) { BREAK; } test(); test(); - IF ((x[i] != 0) && ((lf_deemph_factors == NULL) || (GT_16(lf_deemph_factors[i], 0x2000)))) + IF( ( x[i] != 0 ) && ( ( lf_deemph_factors == NULL ) || ( GT_16( lf_deemph_factors[i], 0x2000 ) ) ) ) { - if (lf_deemph_factors != NULL) + if ( lf_deemph_factors != NULL ) { lf_deemph_factor = lf_deemph_factors[i]; move16(); } - IF (prm[bits] == 0) + IF( prm[bits] == 0 ) { /* Debug initialization to catch illegal cases of x[i] */ tmp = 0; - if (x[i] > 0) tmp = L_mult(fac_m, lf_deemph_factor); - if (x[i] < 0) tmp = L_mult(fac_p, lf_deemph_factor); + if ( x[i] > 0 ) + tmp = L_mult( fac_m, lf_deemph_factor ); + if ( x[i] < 0 ) + tmp = L_mult( fac_p, lf_deemph_factor ); - assert(tmp != 0); + assert( tmp != 0 ); - x[i] = L_sub(x[i], L_shr(tmp, s)); + x[i] = L_sub( x[i], L_shr( tmp, s ) ); move32(); } ELSE @@ -285,71 +288,75 @@ Word16 tcx_res_invQ_spec( /* Debug initialization to catch illegal cases of x[i] */ tmp = 0; - if (x[i] > 0) tmp = L_mult(fac_p, lf_deemph_factor); - if (x[i] < 0) tmp = L_mult(fac_m, lf_deemph_factor); + if ( x[i] > 0 ) + tmp = L_mult( fac_p, lf_deemph_factor ); + if ( x[i] < 0 ) + tmp = L_mult( fac_m, lf_deemph_factor ); - assert(tmp != 0); + assert( tmp != 0 ); - x[i] = L_add(x[i], L_shr(tmp, s)); + x[i] = L_add( x[i], L_shr( tmp, s ) ); move32(); } - bits = add(bits, 1); + bits = add( bits, 1 ); } } /*Quantize zeroed-line of the spectrum*/ - resQBits = sub(resQBits, 1); + resQBits = sub( resQBits, 1 ); - IF (lf_deemph_factors == NULL) + IF( lf_deemph_factors == NULL ) { - FOR (i = 0; i < L_frame; i++) + FOR( i = 0; i < L_frame; i++ ) { - IF (GE_16(bits, resQBits)) + IF( GE_16( bits, resQBits ) ) { BREAK; } - IF (x[i] == 0) + IF( x[i] == 0 ) { - IF (prm[bits] != 0) + IF( prm[bits] != 0 ) { - bits = add(bits, 1); + bits = add( bits, 1 ); - tmp = L_mult(21627/*1.32f Q14*/, fac_p); - if (prm[bits] == 0) tmp = L_negate(tmp); + tmp = L_mult( 21627 /*1.32f Q14*/, fac_p ); + if ( prm[bits] == 0 ) + tmp = L_negate( tmp ); - x[i] = L_shr(tmp, s); + x[i] = L_shr( tmp, s ); move32(); } - bits = add(bits, 1); + bits = add( bits, 1 ); } } } ELSE { - c = sub(21627/*0.66f Q15*/, mult_r(sq_round, 21627/*0.66f Q15*/)); + c = sub( 21627 /*0.66f Q15*/, mult_r( sq_round, 21627 /*0.66f Q15*/ ) ); - FOR (i = 0; i < L_frame; i++) + FOR( i = 0; i < L_frame; i++ ) { - IF (GE_16(bits, resQBits)) + IF( GE_16( bits, resQBits ) ) { BREAK; } test(); - IF ((x[i] == 0) && (GT_16(lf_deemph_factors[i], 0x2000))) + IF( ( x[i] == 0 ) && ( GT_16( lf_deemph_factors[i], 0x2000 ) ) ) { - IF (prm[bits] != 0) + IF( prm[bits] != 0 ) { - bits = add(bits, 1); + bits = add( bits, 1 ); - tmp = L_mult(c, lf_deemph_factors[i]); - if (prm[bits] == 0) tmp = L_negate(tmp); + tmp = L_mult( c, lf_deemph_factors[i] ); + if ( prm[bits] == 0 ) + tmp = L_negate( tmp ); - x[i] = L_shr(tmp, s); + x[i] = L_shr( tmp, s ); move32(); } - bits = add(bits, 1); + bits = add( bits, 1 ); } } } diff --git a/lib_dec/tns_base_dec_fx.c b/lib_dec/tns_base_dec_fx.c index 7aa47ecbd..5ef1756b7 100644 --- a/lib_dec/tns_base_dec_fx.c +++ b/lib_dec/tns_base_dec_fx.c @@ -11,13 +11,13 @@ #include "rom_com.h" /** Linear prediction analysis/synthesis filter definition. - * @param order filter order. - * @param parCoeff filter (PARCOR) coefficients. - * @param state state of the filter. Must be at least of 'order' size. - * @param x the current input value. - * @return the output of the filter. - */ -typedef Word32 (* TLinearPredictionFilter)(Word16 order, Word16 const parCoeff[], Word32 * state, Word32 x); + * @param order filter order. + * @param parCoeff filter (PARCOR) coefficients. + * @param state state of the filter. Must be at least of 'order' size. + * @param x the current input value. + * @return the output of the filter. + */ +typedef Word32 ( *TLinearPredictionFilter )( Word16 order, Word16 const parCoeff[], Word32 *state, Word32 x ); /********************************/ /* Interface functions */ @@ -92,15 +92,14 @@ ReadTnsData( #ifdef IVAS_CODE void #else -Word16 +Word16 #endif - ReadTnsData_ivas_fx( - STnsConfig const * pTnsConfig, - Decoder_State *st, - Word16 * pnBits, - Word16 * stream, - Word16 * pnSize -) +ReadTnsData_ivas_fx( + STnsConfig const *pTnsConfig, + Decoder_State *st, + Word16 *pnBits, + Word16 *stream, + Word16 *pnSize ) { Word16 start_bit_pos; @@ -108,41 +107,41 @@ Word16 move16(); start_bit_pos = st->next_bit_pos; - IF ( GT_16(pTnsConfig->nMaxFilters, 1)) + IF( GT_16( pTnsConfig->nMaxFilters, 1 ) ) { #ifdef IVAS_CODE - IF(pTnsConfig->allowTnsOnWhite) + IF( pTnsConfig->allowTnsOnWhite ) { - IF(LT_16(pTnsConfig->iFilterBorders[0], 512)) + IF( LT_16( pTnsConfig->iFilterBorders[0], 512 ) ) { - ReadFromBitstream_fx(&tnsEnabledOnWhiteSWBTCX10BitMap, 1, st, &stream, pnSize); + ReadFromBitstream_fx( &tnsEnabledOnWhiteSWBTCX10BitMap, 1, st, &stream, pnSize ); } ELSE { - ReadFromBitstream_fx(&tnsEnabledOnWhiteSWBTCX20BitMap, 1, st, &stream, pnSize); + ReadFromBitstream_fx( &tnsEnabledOnWhiteSWBTCX20BitMap, 1, st, &stream, pnSize ); } } ELSE #endif { - IF(LT_16(pTnsConfig->iFilterBorders[0], 512)) + IF( LT_16( pTnsConfig->iFilterBorders[0], 512 ) ) { - ReadFromBitstream_fx(&tnsEnabledSWBTCX10BitMap, 1, st, &stream, pnSize); + ReadFromBitstream_fx( &tnsEnabledSWBTCX10BitMap, 1, st, &stream, pnSize ); } ELSE { - ReadFromBitstream_fx(&tnsEnabledSWBTCX20BitMap, 1, st, &stream, pnSize); + ReadFromBitstream_fx( &tnsEnabledSWBTCX20BitMap, 1, st, &stream, pnSize ); } } } ELSE { - ReadFromBitstream_fx(&tnsEnabledWBTCX20BitMap, 1, st, &stream, pnSize); + ReadFromBitstream_fx( &tnsEnabledWBTCX20BitMap, 1, st, &stream, pnSize ); } move16(); - *pnBits = sub(st->next_bit_pos, start_bit_pos); + *pnBits = sub( st->next_bit_pos, start_bit_pos ); #ifdef IVAS_CODE @@ -153,60 +152,58 @@ Word16 } #undef IVAS_CODE /*---------------------------------------------------------------------* -* DecodeTnsData() -* -* -*---------------------------------------------------------------------*/ + * DecodeTnsData() + * + * + *---------------------------------------------------------------------*/ Word16 DecodeTnsData( - STnsConfig const * pTnsConfig, - Word16 const * stream, - Word16 * pnSize, - STnsData * pTnsData -) + STnsConfig const *pTnsConfig, + Word16 const *stream, + Word16 *pnSize, + STnsData *pTnsData ) { Word16 result; + ResetTnsData( pTnsData ); - ResetTnsData(pTnsData); - - IF ( GT_16(pTnsConfig->nMaxFilters, 1)) + IF( GT_16( pTnsConfig->nMaxFilters, 1 ) ) { #ifdef IVAS_CODE - IF (pTnsConfig->allowTnsOnWhite) + IF( pTnsConfig->allowTnsOnWhite ) { - IF(LT_16(pTnsConfig->iFilterBorders[0], 512)) + IF( LT_16( pTnsConfig->iFilterBorders[0], 512 ) ) { - SetParameters(&tnsEnabledOnWhiteSWBTCX10BitMap, 1, pTnsData, &stream, pnSize); + SetParameters( &tnsEnabledOnWhiteSWBTCX10BitMap, 1, pTnsData, &stream, pnSize ); } ELSE { - SetParameters(&tnsEnabledOnWhiteSWBTCX20BitMap, 1, pTnsData, &stream, pnSize); + SetParameters( &tnsEnabledOnWhiteSWBTCX20BitMap, 1, pTnsData, &stream, pnSize ); } } ELSE #endif { - IF(LT_16(pTnsConfig->iFilterBorders[0], 512)) + IF( LT_16( pTnsConfig->iFilterBorders[0], 512 ) ) { - SetParameters(&tnsEnabledSWBTCX10BitMap, 1, pTnsData, &stream, pnSize); + SetParameters( &tnsEnabledSWBTCX10BitMap, 1, pTnsData, &stream, pnSize ); } ELSE { - SetParameters(&tnsEnabledSWBTCX20BitMap, 1, pTnsData, &stream, pnSize); + SetParameters( &tnsEnabledSWBTCX20BitMap, 1, pTnsData, &stream, pnSize ); } } } ELSE { - SetParameters(&tnsEnabledWBTCX20BitMap, 1, pTnsData, &stream, pnSize); + SetParameters( &tnsEnabledWBTCX20BitMap, 1, pTnsData, &stream, pnSize ); } move16(); result = FALSE; - if (pTnsData->nFilters > 0) + if ( pTnsData->nFilters > 0 ) { move16(); result = TRUE; @@ -267,4 +264,4 @@ Word16 DecodeTnsData_ivas_fx( return result; -} \ No newline at end of file +} diff --git a/lib_dec/tonalMDCTconcealment.c b/lib_dec/tonalMDCTconcealment.c index 74768cf0e..922d0a252 100644 --- a/lib_dec/tonalMDCTconcealment.c +++ b/lib_dec/tonalMDCTconcealment.c @@ -120,7 +120,7 @@ ivas_error TonalMDCTConceal_Init_ivas( /* If the second last frame was lost and concealed with tonal PLC, we reuse saved TonalComponentsInfo and don't update pcm buffers */ - assert( sizeof( *hTonalMDCTConc->pTCI ) <= ( hTonalMDCTConc->lastPcmOut_float - hTonalMDCTConc->timeDataBuffer_float) * sizeof( hTonalMDCTConc->timeDataBuffer_float[0] ) ); + assert( sizeof( *hTonalMDCTConc->pTCI ) <= ( hTonalMDCTConc->lastPcmOut_float - hTonalMDCTConc->timeDataBuffer_float ) * sizeof( hTonalMDCTConc->timeDataBuffer_float[0] ) ); #endif return IVAS_ERR_OK; @@ -353,7 +353,7 @@ static void CalcPowerSpecAndDetectTonalComponents( } DetectTonalComponents_flt( hTonalMDCTConc->pTCI->indexOfTonalPeak, hTonalMDCTConc->pTCI->lowerIndex, hTonalMDCTConc->pTCI->upperIndex, &hTonalMDCTConc->pTCI->numIndexes, hTonalMDCTConc->lastPitchLag_float, pitchLag, - hTonalMDCTConc->lastBlockData.spectralData_float, hTonalMDCTConc->lastBlockData.scaleFactors_float, powerSpectrum, nSamples, hTonalMDCTConc->nSamplesCore, floorPowerSpectrum, psychParamsCurrent ); + hTonalMDCTConc->lastBlockData.spectralData_float, hTonalMDCTConc->lastBlockData.scaleFactors_float, powerSpectrum, nSamples, hTonalMDCTConc->nSamplesCore, floorPowerSpectrum, psychParamsCurrent ); FindPhases( hTonalMDCTConc, secondLastMDCT, secondLastMDST ); @@ -450,11 +450,11 @@ static void CalcMDXT( if ( type == 'S' ) { - TCX_MDST_flt( windowedTimeSignal, mdxtOutput, left_overlap, L_frame - ( left_overlap + right_overlap ) / 2, right_overlap, EVS_MONO ); + TCX_MDST_flt( windowedTimeSignal, mdxtOutput, left_overlap, L_frame - ( left_overlap + right_overlap ) / 2, right_overlap, EVS_MONO ); } else { - TCX_MDCT_flt( windowedTimeSignal, mdxtOutput, left_overlap, L_frame - ( left_overlap + right_overlap ) / 2, right_overlap, EVS_MONO ); + TCX_MDCT_flt( windowedTimeSignal, mdxtOutput, left_overlap, L_frame - ( left_overlap + right_overlap ) / 2, right_overlap, EVS_MONO ); } return; @@ -518,9 +518,9 @@ void TonalMDCTConceal_Detect_ivas( v_mult( powerSpectrum, powerSpectrum, powerSpectrum, nSamples ); RefineTonalComponents_flt( hTonalMDCTConc->pTCI->indexOfTonalPeak, hTonalMDCTConc->pTCI->lowerIndex, hTonalMDCTConc->pTCI->upperIndex, hTonalMDCTConc->pTCI->phaseDiff_float, - hTonalMDCTConc->pTCI->phase_currentFramePredicted_float, &hTonalMDCTConc->pTCI->numIndexes, hTonalMDCTConc->lastPitchLag_float, pitchLag, - hTonalMDCTConc->lastBlockData.spectralData_float, hTonalMDCTConc->lastBlockData.scaleFactors_float, powerSpectrum, - nSamples, hTonalMDCTConc->nSamplesCore, hTonalMDCTConc->nSamples * hTonalMDCTConc->nSamples / 400.0f /* floorPowerSpectrum */, psychParamsCurrent ); + hTonalMDCTConc->pTCI->phase_currentFramePredicted_float, &hTonalMDCTConc->pTCI->numIndexes, hTonalMDCTConc->lastPitchLag_float, pitchLag, + hTonalMDCTConc->lastBlockData.spectralData_float, hTonalMDCTConc->lastBlockData.scaleFactors_float, powerSpectrum, + nSamples, hTonalMDCTConc->nSamplesCore, hTonalMDCTConc->nSamples * hTonalMDCTConc->nSamples / 400.0f /* floorPowerSpectrum */, psychParamsCurrent ); } } } @@ -1380,8 +1380,8 @@ void TonalMdctConceal_create_concealment_noise_ivas( *rnd_c = 1979; } - //if ( crossfade_gain == 1.0f ) - if (crossfade_gain > 0.999f) /* Due to precision loss */ + // if ( crossfade_gain == 1.0f ) + if ( crossfade_gain > 0.999f ) /* Due to precision loss */ { /* In first frame, noise is weighted with zero anyway, we only need the random numbers for the sign scrambling */ for ( i = 0; i < max_noise_line; i++ ) @@ -1518,15 +1518,16 @@ void TonalMdctConceal_whiten_noise_shape_ivas( Word16 q = 31; FOR( Word16 k = 0; k < L_FRAME16k; k++ ) { - if(abs((Word32)whitenend_noise_shape[k])!=0) q = s_min(q, norm_l( (Word32)whitenend_noise_shape[k] )); + if ( abs( (Word32) whitenend_noise_shape[k] ) != 0 ) + q = s_min( q, norm_l( (Word32) whitenend_noise_shape[k] ) ); } - q -= find_guarded_bits_fx(L_frame) - 2; - //q -= 1; + q -= find_guarded_bits_fx( L_frame ) - 2; + // q -= 1; FOR( Word16 k = 0; k < L_FRAME16k; k++ ) { - whitenend_noise_shape_fx[k] = q>=0 ? ((Word32) ( whitenend_noise_shape[k] *(1<< q) )):((Word32) ( whitenend_noise_shape[k] / (1<< q) )); + whitenend_noise_shape_fx[k] = q >= 0 ? ( (Word32) ( whitenend_noise_shape[k] * ( 1 << q ) ) ) : ( (Word32) ( whitenend_noise_shape[k] / ( 1 << q ) ) ); } sns_compute_scf_fx( whitenend_noise_shape_fx, psychParams, L_frame, scf_fx, q ); @@ -1571,12 +1572,12 @@ void TonalMdctConceal_whiten_noise_shape_ivas( FOR( Word16 k = 0; k < L_FRAME16k; k++ ) { if ( abs( (Word32) whitenend_noise_shape[k] ) != 0 ) - q_wns = s_min( q_wns, norm_l( (Word32)whitenend_noise_shape[k] ) ); + q_wns = s_min( q_wns, norm_l( (Word32) whitenend_noise_shape[k] ) ); } FOR( Word16 k = 0; k < FDNS_NPTS; k++ ) { if ( abs( (Word32) scfs_for_shaping[k] ) != 0 ) - q_sfs = s_min( q_sfs, norm_l( (Word32)scfs_for_shaping[k] ) ); + q_sfs = s_min( q_sfs, norm_l( (Word32) scfs_for_shaping[k] ) ); } q_wns -= 1; q_sfs -= 1; @@ -1656,7 +1657,7 @@ void TonalMdctConceal_whiten_noise_shape_ivas_fx( { Word32 scf[SNS_NPTS]; - sns_compute_scf_fx( whitenend_noise_shape, psychParams, L_frame, scf, (31 - noiseLevelPtr_exp)); + sns_compute_scf_fx( whitenend_noise_shape, psychParams, L_frame, scf, ( 31 - noiseLevelPtr_exp ) ); sns_interpolate_scalefactors_fx( scfs_int, scf, ENC ); sns_interpolate_scalefactors_fx( scfs_bg, scf, DEC ); diff --git a/lib_dec/tonalMDCTconcealment_fx.c b/lib_dec/tonalMDCTconcealment_fx.c index d709b697f..f64ef3a7b 100644 --- a/lib_dec/tonalMDCTconcealment_fx.c +++ b/lib_dec/tonalMDCTconcealment_fx.c @@ -18,17 +18,17 @@ #include "prot.h" #include "ivas_prot_fx.h" -#define CROSSFADE_THRESHOLD (32762) // close to 1.0f in Q15 such that (x == 1.0f) is true +#define CROSSFADE_THRESHOLD ( 32762 ) // close to 1.0f in Q15 such that (x == 1.0f) is true /************************************************************************************ * local functions ************************************************************************************/ -static void CalcMDXT(const TonalMDCTConcealPtr hTonalMDCTConc, const Word16 type, const Word16 * timeSignal, Word32 * mdxtOutput, Word16 * mdxtOutput_e); -static void CalcPowerSpec(const Word32 * mdctSpec, const Word16 mdctSpec_exp, const Word32 * mdstSpec, const Word16 mdstSpec_exp, const Word16 nSamples, const Word16 floorPowerSpectrum, Word32 * powerSpec, Word16 * powerSpec_exp); -static void CalcPowerSpecAndDetectTonalComponents(TonalMDCTConcealPtr const hTonalMDCTConc, Word32 secondLastMDST[], Word16 secondLastMDST_exp, Word32 secondLastMDCT[], Word16 secondLastMDCT_exp, Word32 const pitchLag, Word16 element_mode); -static void FindPhases(TonalMDCTConcealPtr const hTonalMDCTConc, Word32 secondLastMDCT[], Word32 secondLastMDST[], Word16 diff_exp); -static void FindPhaseDifferences(TonalMDCTConcealPtr const hTonalMDCTConc, Word32 powerSpectrum[]); +static void CalcMDXT( const TonalMDCTConcealPtr hTonalMDCTConc, const Word16 type, const Word16 *timeSignal, Word32 *mdxtOutput, Word16 *mdxtOutput_e ); +static void CalcPowerSpec( const Word32 *mdctSpec, const Word16 mdctSpec_exp, const Word32 *mdstSpec, const Word16 mdstSpec_exp, const Word16 nSamples, const Word16 floorPowerSpectrum, Word32 *powerSpec, Word16 *powerSpec_exp ); +static void CalcPowerSpecAndDetectTonalComponents( TonalMDCTConcealPtr const hTonalMDCTConc, Word32 secondLastMDST[], Word16 secondLastMDST_exp, Word32 secondLastMDCT[], Word16 secondLastMDCT_exp, Word32 const pitchLag, Word16 element_mode ); +static void FindPhases( TonalMDCTConcealPtr const hTonalMDCTConc, Word32 secondLastMDCT[], Word32 secondLastMDST[], Word16 diff_exp ); +static void FindPhaseDifferences( TonalMDCTConcealPtr const hTonalMDCTConc, Word32 powerSpectrum[] ); /*******************************************************/ @@ -44,33 +44,33 @@ ivas_error TonalMDCTConceal_Init( ) { test(); - IF (GT_16(nSamples,L_FRAME_MAX)||GT_16(nScaleFactors,FDNS_NPTS)) + IF( GT_16( nSamples, L_FRAME_MAX ) || GT_16( nScaleFactors, FDNS_NPTS ) ) { - assert(nSamples <= L_FRAME_MAX); - assert(nScaleFactors <= FDNS_NPTS); - return (IVAS_ERROR(IVAS_ERR_INTERNAL, "TonalMDCT FEC: Number of samples larger than max. block size\n")); + assert( nSamples <= L_FRAME_MAX ); + assert( nScaleFactors <= FDNS_NPTS ); + return ( IVAS_ERROR( IVAS_ERR_INTERNAL, "TonalMDCT FEC: Number of samples larger than max. block size\n" ) ); } - assert((hTonalMDCTConc->nScaleFactors == nScaleFactors) || (hTonalMDCTConc->nSamples != nSamples)); /* If nSamples doesn't change then also nScaleFactors must stay the same */ + assert( ( hTonalMDCTConc->nScaleFactors == nScaleFactors ) || ( hTonalMDCTConc->nSamples != nSamples ) ); /* If nSamples doesn't change then also nScaleFactors must stay the same */ hTonalMDCTConc->tcx_cfg = hTcxCfg; - hTonalMDCTConc->lastBlockData.spectralData = hTonalMDCTConc->spectralDataBuffers[0]; + hTonalMDCTConc->lastBlockData.spectralData = hTonalMDCTConc->spectralDataBuffers[0]; move16(); hTonalMDCTConc->secondLastBlockData.spectralData = hTonalMDCTConc->spectralDataBuffers[1]; move16(); hTonalMDCTConc->secondLastPowerSpectrum = hTonalMDCTConc->secondLastBlockData.spectralData; move16(); - hTonalMDCTConc->lastBlockData.scaleFactors = hTonalMDCTConc->scaleFactorsBuffers[0]; + hTonalMDCTConc->lastBlockData.scaleFactors = hTonalMDCTConc->scaleFactorsBuffers[0]; move16(); hTonalMDCTConc->secondLastBlockData.scaleFactors = hTonalMDCTConc->scaleFactorsBuffers[1]; move16(); - hTonalMDCTConc->lastBlockData.scaleFactors_exp = hTonalMDCTConc->scaleFactorsBuffers_exp[0]; + hTonalMDCTConc->lastBlockData.scaleFactors_exp = hTonalMDCTConc->scaleFactorsBuffers_exp[0]; move16(); hTonalMDCTConc->secondLastBlockData.scaleFactors_exp = hTonalMDCTConc->scaleFactorsBuffers_exp[1]; move16(); - hTonalMDCTConc->lastBlockData.blockIsValid = 0; + hTonalMDCTConc->lastBlockData.blockIsValid = 0; move16(); hTonalMDCTConc->secondLastBlockData.blockIsValid = 0; move16(); @@ -79,18 +79,18 @@ ivas_error TonalMDCTConceal_Init( hTonalMDCTConc->nScaleFactors = 0; move16(); - hTonalMDCTConc->lastBlockData.blockIsConcealed = 0; + hTonalMDCTConc->lastBlockData.blockIsConcealed = 0; move16(); hTonalMDCTConc->secondLastBlockData.blockIsConcealed = 0; move16(); - //hTonalMDCTConc->pTCI_fix = (TonalComponentsInfo_fix *)hTonalMDCTConc->timeDataBuffer; + // hTonalMDCTConc->pTCI_fix = (TonalComponentsInfo_fix *)hTonalMDCTConc->timeDataBuffer; move16(); - hTonalMDCTConc->lastPitchLag = L_deposit_l(0); + hTonalMDCTConc->lastPitchLag = L_deposit_l( 0 ); - IF (NE_16(hTonalMDCTConc->nSamples,nSamples)) + IF( NE_16( hTonalMDCTConc->nSamples, nSamples ) ) { hTonalMDCTConc->secondLastBlockData.blockIsValid = 0; move16(); @@ -107,9 +107,9 @@ ivas_error TonalMDCTConceal_Init( move16(); #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT PMTE() - set_zero(hTonalMDCTConc->scaleFactorsBackground_flt, FDNS_NPTS); - PsychoacousticParameters_Init(INT_FS_16k, L_FRAME16k, 64, 1, 1, &hTonalMDCTConc->psychParamsTCX20); - PsychoacousticParameters_Init(INT_FS_16k, L_FRAME16k / 2, 64, 0, 1, &hTonalMDCTConc->psychParamsTCX10); + set_zero( hTonalMDCTConc->scaleFactorsBackground_flt, FDNS_NPTS ); + PsychoacousticParameters_Init( INT_FS_16k, L_FRAME16k, 64, 1, 1, &hTonalMDCTConc->psychParamsTCX20 ); + PsychoacousticParameters_Init( INT_FS_16k, L_FRAME16k / 2, 64, 0, 1, &hTonalMDCTConc->psychParamsTCX10 ); hTonalMDCTConc->psychParams = NULL; hTonalMDCTConc->scf_fadeout_flt = 1.0f; hTonalMDCTConc->last_block_nrg_flt = 0.0f; @@ -118,16 +118,17 @@ ivas_error TonalMDCTConceal_Init( #endif /* Offset the pointer to the end of buffer, so that pTCI is not destroyed when - new time samples are stored in lastPcmOut */ move16(); + new time samples are stored in lastPcmOut */ + move16(); move16(); /* just the second half of the second last pcm output is needed */ - hTonalMDCTConc->secondLastPcmOut = &hTonalMDCTConc->timeDataBuffer[sub((3*L_FRAME_MAX)/2,3*(s_min(L_FRAME_MAX, nSamples))/2)]; - hTonalMDCTConc->lastPcmOut = &hTonalMDCTConc->timeDataBuffer[sub((3*L_FRAME_MAX)/2, s_min(L_FRAME_MAX, nSamples)) ]; + hTonalMDCTConc->secondLastPcmOut = &hTonalMDCTConc->timeDataBuffer[sub( ( 3 * L_FRAME_MAX ) / 2, 3 * ( s_min( L_FRAME_MAX, nSamples ) ) / 2 )]; + hTonalMDCTConc->lastPcmOut = &hTonalMDCTConc->timeDataBuffer[sub( ( 3 * L_FRAME_MAX ) / 2, s_min( L_FRAME_MAX, nSamples ) )]; /* If the second last frame was lost, we reuse saved TonalComponentsInfo and don't update pcm buffers */ #if 1 - //TO do enable when only fix code is present currently disabled due to float array in structure - //assert(sizeof(*hTonalMDCTConc->pTCI) <= (hTonalMDCTConc->lastPcmOut-hTonalMDCTConc->timeDataBuffer)*sizeof(hTonalMDCTConc->timeDataBuffer[0])); + // TO do enable when only fix code is present currently disabled due to float array in structure + // assert(sizeof(*hTonalMDCTConc->pTCI) <= (hTonalMDCTConc->lastPcmOut-hTonalMDCTConc->timeDataBuffer)*sizeof(hTonalMDCTConc->timeDataBuffer[0])); #endif return IVAS_ERR_OK; } @@ -141,16 +142,16 @@ ivas_error TonalMDCTConceal_Init_ivas_fx( test(); IF( GT_16( nSamples, L_FRAME_MAX ) || GT_16( nScaleFactors, FDNS_NPTS ) ) { - assert( LE_16(nSamples , L_FRAME_MAX) ); - assert( LE_16(nScaleFactors , FDNS_NPTS) ); + assert( LE_16( nSamples, L_FRAME_MAX ) ); + assert( LE_16( nScaleFactors, FDNS_NPTS ) ); return ( IVAS_ERROR( IVAS_ERR_INTERNAL, "TonalMDCT FEC: Number of samples larger than max. block size\n" ) ); } - assert( EQ_16( hTonalMDCTConc->nScaleFactors , nScaleFactors ) || NE_16( hTonalMDCTConc->nSamples , nSamples ) ); /* If nSamples doesn't change then also nScaleFactors must stay the same */ + assert( EQ_16( hTonalMDCTConc->nScaleFactors, nScaleFactors ) || NE_16( hTonalMDCTConc->nSamples, nSamples ) ); /* If nSamples doesn't change then also nScaleFactors must stay the same */ hTonalMDCTConc->tcx_cfg = hTcxCfg; hTonalMDCTConc->lastBlockData.spectralData = hTonalMDCTConc->spectralDataBuffers[0]; #ifdef MSAN_FIX - set_s(hTonalMDCTConc->lastBlockData.spectralData, 0, L_FRAME_MAX); + set_s( hTonalMDCTConc->lastBlockData.spectralData, 0, L_FRAME_MAX ); #endif move16(); hTonalMDCTConc->secondLastBlockData.spectralData = hTonalMDCTConc->spectralDataBuffers[1]; @@ -164,12 +165,12 @@ ivas_error TonalMDCTConceal_Init_ivas_fx( move16(); hTonalMDCTConc->lastBlockData.scaleFactors = hTonalMDCTConc->scaleFactorsBuffers[0]; #ifdef MSAN_FIX - set_s(hTonalMDCTConc->lastBlockData.scaleFactors, 0, FDNS_NPTS); + set_s( hTonalMDCTConc->lastBlockData.scaleFactors, 0, FDNS_NPTS ); #endif move16(); hTonalMDCTConc->secondLastBlockData.scaleFactors = hTonalMDCTConc->scaleFactorsBuffers[1]; #ifdef MSAN_FIX - set_s(hTonalMDCTConc->secondLastBlockData.scaleFactors, 0, FDNS_NPTS); + set_s( hTonalMDCTConc->secondLastBlockData.scaleFactors, 0, FDNS_NPTS ); #endif move16(); hTonalMDCTConc->lastBlockData.scaleFactors_exp = hTonalMDCTConc->scaleFactorsBuffers_exp[0]; @@ -192,7 +193,7 @@ ivas_error TonalMDCTConceal_Init_ivas_fx( move16(); hTonalMDCTConc->pTCI = (TonalComponentsInfo *) hTonalMDCTConc->timeDataBuffer; - //hTonalMDCTConc->pTCI = &hTonalMDCTConc->pTCI1; + // hTonalMDCTConc->pTCI = &hTonalMDCTConc->pTCI1; move16(); hTonalMDCTConc->lastPitchLag = L_deposit_l( 0 ); @@ -238,60 +239,66 @@ ivas_error TonalMDCTConceal_Init_ivas_fx( move16(); move16(); /* just the second half of the second last pcm output is needed */ - hTonalMDCTConc->secondLastPcmOut = &hTonalMDCTConc->timeDataBuffer[sub( ( 3 * L_FRAME_MAX ) / 2, imult1616(3 , shr(s_min( L_FRAME_MAX, nSamples ),1 ) ) )]; + hTonalMDCTConc->secondLastPcmOut = &hTonalMDCTConc->timeDataBuffer[sub( ( 3 * L_FRAME_MAX ) / 2, imult1616( 3, shr( s_min( L_FRAME_MAX, nSamples ), 1 ) ) )]; hTonalMDCTConc->lastPcmOut = &hTonalMDCTConc->timeDataBuffer[sub( ( 3 * L_FRAME_MAX ) / 2, s_min( L_FRAME_MAX, nSamples ) )]; /* If the second last frame was lost, we reuse saved TonalComponentsInfo and don't update pcm buffers */ assert( sizeof( *hTonalMDCTConc->pTCI ) <= ( hTonalMDCTConc->lastPcmOut - hTonalMDCTConc->timeDataBuffer ) * sizeof( hTonalMDCTConc->timeDataBuffer[0] ) ); return IVAS_ERR_OK; } -void TonalMDCTConceal_SaveFreqSignal( +void TonalMDCTConceal_SaveFreqSignal( TonalMDCTConcealPtr hTonalMDCTConc, const Word32 *mdctSpectrum, const Word16 mdctSpectrum_exp, Word16 nNewSamples, Word16 nNewSamplesCore, - const Word16 *scaleFactors, + const Word16 *scaleFactors, const Word16 *scaleFactors_exp, const Word16 gain_tcx_exp #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - ,const int16_t infoIGFStartLine + , + const int16_t infoIGFStartLine #endif ) { - Word16 * temp; + Word16 *temp; Word16 nOldSamples, tmp_exp, s, i, max_exp; - assert(nNewSamples > 0 && nNewSamples <= 2*L_FRAME_MAX); + assert( nNewSamples > 0 && nNewSamples <= 2 * L_FRAME_MAX ); /* Avoid overwriting hTonalMDCTConc->secondLastPowerSpectrum stored in spectralData, because it is needed if the second last and the current frame are lost - and concealed using the Tonal MDCT PLC */ test(); - IF (!hTonalMDCTConc->lastBlockData.tonalConcealmentActive || NE_16(hTonalMDCTConc->lastBlockData.nSamples,nNewSamples)) + and concealed using the Tonal MDCT PLC */ + test(); + IF( !hTonalMDCTConc->lastBlockData.tonalConcealmentActive || NE_16( hTonalMDCTConc->lastBlockData.nSamples, nNewSamples ) ) { - IF (LE_16(nNewSamples,L_FRAME_MAX)) + IF( LE_16( nNewSamples, L_FRAME_MAX ) ) { /* Shift the buffers */ - temp = hTonalMDCTConc->secondLastBlockData.spectralData; /* Save the pointer */ move16(); + temp = hTonalMDCTConc->secondLastBlockData.spectralData; /* Save the pointer */ + move16(); hTonalMDCTConc->secondLastBlockData.spectralData = hTonalMDCTConc->lastBlockData.spectralData; move16(); hTonalMDCTConc->lastBlockData.spectralData = temp; move16(); - tmp_exp = hTonalMDCTConc->secondLastBlockData.spectralData_exp; /* Save the pointer */ move16(); + tmp_exp = hTonalMDCTConc->secondLastBlockData.spectralData_exp; /* Save the pointer */ + move16(); hTonalMDCTConc->secondLastBlockData.spectralData_exp = hTonalMDCTConc->lastBlockData.spectralData_exp; move16(); hTonalMDCTConc->lastBlockData.spectralData_exp = tmp_exp; move16(); - tmp_exp = hTonalMDCTConc->secondLastBlockData.gain_tcx_exp; /* Save the pointer */ move16(); + tmp_exp = hTonalMDCTConc->secondLastBlockData.gain_tcx_exp; /* Save the pointer */ + move16(); hTonalMDCTConc->secondLastBlockData.gain_tcx_exp = hTonalMDCTConc->lastBlockData.gain_tcx_exp; move16(); hTonalMDCTConc->lastBlockData.gain_tcx_exp = tmp_exp; move16(); - tmp_exp = hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e; /* Save the pointer */ move16(); + tmp_exp = hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e; /* Save the pointer */ + move16(); hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e = hTonalMDCTConc->lastBlockData.scaleFactors_max_e; move16(); hTonalMDCTConc->lastBlockData.scaleFactors_max_e = tmp_exp; @@ -313,15 +320,15 @@ void TonalMDCTConceal_SaveFreqSignal( } ELSE { - hTonalMDCTConc->lastBlockData.spectralData = hTonalMDCTConc->spectralDataBuffers[0]; + hTonalMDCTConc->lastBlockData.spectralData = hTonalMDCTConc->spectralDataBuffers[0]; move16(); - hTonalMDCTConc->secondLastBlockData.spectralData = hTonalMDCTConc->spectralDataBuffers[1]; + hTonalMDCTConc->secondLastBlockData.spectralData = hTonalMDCTConc->spectralDataBuffers[1]; move16(); - hTonalMDCTConc->lastBlockData.scaleFactors = hTonalMDCTConc->scaleFactorsBuffers[0]; + hTonalMDCTConc->lastBlockData.scaleFactors = hTonalMDCTConc->scaleFactorsBuffers[0]; move16(); - hTonalMDCTConc->secondLastBlockData.scaleFactors = hTonalMDCTConc->scaleFactorsBuffers[1]; + hTonalMDCTConc->secondLastBlockData.scaleFactors = hTonalMDCTConc->scaleFactorsBuffers[1]; move16(); - hTonalMDCTConc->lastBlockData.scaleFactors_exp = hTonalMDCTConc->scaleFactorsBuffers_exp[0]; + hTonalMDCTConc->lastBlockData.scaleFactors_exp = hTonalMDCTConc->scaleFactorsBuffers_exp[0]; move16(); hTonalMDCTConc->secondLastBlockData.scaleFactors_exp = hTonalMDCTConc->scaleFactorsBuffers_exp[1]; move16(); @@ -343,48 +350,48 @@ void TonalMDCTConceal_SaveFreqSignal( } test(); - IF ((nNewSamples > 0) && (LE_16(nNewSamples,2*L_FRAME_MAX))) + IF( ( nNewSamples > 0 ) && ( LE_16( nNewSamples, 2 * L_FRAME_MAX ) ) ) { #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT int16_t i; - PMTE() + PMTE() hTonalMDCTConc->last_block_nrg_flt = 0.0f; - for (i = 0; i < infoIGFStartLine; i++) + for ( i = 0; i < infoIGFStartLine; i++ ) { hTonalMDCTConc->lastBlockData.spectralData[i] = mdctSpectrum[i]; hTonalMDCTConc->last_block_nrg_flt += mdctSpectrum[i] * mdctSpectrum[i]; } - for (; i < nNewSamples; i++) + for ( ; i < nNewSamples; i++ ) { hTonalMDCTConc->lastBlockData.spectralData[i] = mdctSpectrum[i]; } #else /* Store new data */ - s = getScaleFactor32(mdctSpectrum, nNewSamples); + s = getScaleFactor32( mdctSpectrum, nNewSamples ); /*Copy(scaleFactors_exp, hTonalMDCTConc->lastBlockData.scaleFactors_exp, hTonalMDCTConc->nScaleFactors);*/ max_exp = 0; - FOR (i = 0; i < hTonalMDCTConc->nScaleFactors; i++) + FOR( i = 0; i < hTonalMDCTConc->nScaleFactors; i++ ) { hTonalMDCTConc->lastBlockData.scaleFactors_exp[i] = scaleFactors_exp[i]; move16(); - max_exp = s_max(max_exp, scaleFactors_exp[i]); + max_exp = s_max( max_exp, scaleFactors_exp[i] ); } /*s = sub(s, max_exp);*/ hTonalMDCTConc->lastBlockData.scaleFactors_max_e = max_exp; - FOR (i = 0; i < nNewSamples; i++) + FOR( i = 0; i < nNewSamples; i++ ) { - hTonalMDCTConc->lastBlockData.spectralData[i] = extract_h(L_shl(mdctSpectrum[i], s)); + hTonalMDCTConc->lastBlockData.spectralData[i] = extract_h( L_shl( mdctSpectrum[i], s ) ); move16(); } - hTonalMDCTConc->lastBlockData.spectralData_exp = sub(mdctSpectrum_exp,s); + hTonalMDCTConc->lastBlockData.spectralData_exp = sub( mdctSpectrum_exp, s ); #endif move16(); hTonalMDCTConc->lastBlockData.gain_tcx_exp = gain_tcx_exp; - Copy(scaleFactors, hTonalMDCTConc->lastBlockData.scaleFactors, hTonalMDCTConc->nScaleFactors); + Copy( scaleFactors, hTonalMDCTConc->lastBlockData.scaleFactors, hTonalMDCTConc->nScaleFactors ); } return; } @@ -478,11 +485,11 @@ void TonalMDCTConceal_SaveFreqSignal_ivas_fx( move16(); hTonalMDCTConc->secondLastBlockData.nSamples = nOldSamples; move16(); - nOldSamples = (Word16)hTonalMDCTConc->lastBlockData.nSamplesCore; + nOldSamples = (Word16) hTonalMDCTConc->lastBlockData.nSamplesCore; move16(); - hTonalMDCTConc->lastBlockData.nSamplesCore = (UWord16)nNewSamplesCore; + hTonalMDCTConc->lastBlockData.nSamplesCore = (UWord16) nNewSamplesCore; move16(); - hTonalMDCTConc->secondLastBlockData.nSamplesCore = (UWord16)nOldSamples; + hTonalMDCTConc->secondLastBlockData.nSamplesCore = (UWord16) nOldSamples; move16(); } @@ -496,7 +503,7 @@ void TonalMDCTConceal_SaveFreqSignal_ivas_fx( { Word16 tmp = extract_h( mdctSpectrum[i] ); hTonalMDCTConc->last_block_nrg = L_add( hTonalMDCTConc->last_block_nrg, - L_shr( L_mult0( tmp, tmp ), 16 ) ); + L_shr( L_mult0( tmp, tmp ), 16 ) ); } hTonalMDCTConc->last_block_nrg_exp = 31 - ( ( 15 - mdctSpectrum_exp ) * 2 - 16 ); @@ -530,20 +537,19 @@ void TonalMDCTConceal_SaveFreqSignal_ivas_fx( } -TONALMDCTCONCEAL_ERROR TonalMDCTConceal_UpdateState(TonalMDCTConcealPtr hTonalMDCTConc, - Word16 nNewSamples, - Word32 pitchLag, - Word16 badBlock, - Word8 tonalConcealmentActive - ) +TONALMDCTCONCEAL_ERROR TonalMDCTConceal_UpdateState( TonalMDCTConcealPtr hTonalMDCTConc, + Word16 nNewSamples, + Word32 pitchLag, + Word16 badBlock, + Word8 tonalConcealmentActive ) { Word8 newBlockIsValid; - assert(!(!badBlock && tonalConcealmentActive)); + assert( !( !badBlock && tonalConcealmentActive ) ); - IF (badBlock) + IF( badBlock ) { - newBlockIsValid = (Word8)hTonalMDCTConc->lastBlockData.blockIsValid; + newBlockIsValid = (Word8) hTonalMDCTConc->lastBlockData.blockIsValid; move16(); } ELSE @@ -551,7 +557,7 @@ TONALMDCTCONCEAL_ERROR TonalMDCTConceal_UpdateState(TonalMDCTConcealPtr hTonalMD newBlockIsValid = 0; move16(); test(); - if((LE_16(nNewSamples,2*L_FRAME_MAX))&&(nNewSamples>0)) + if ( ( LE_16( nNewSamples, 2 * L_FRAME_MAX ) ) && ( nNewSamples > 0 ) ) { newBlockIsValid = 1; move16(); @@ -577,48 +583,46 @@ TONALMDCTCONCEAL_ERROR TonalMDCTConceal_UpdateState(TonalMDCTConcealPtr hTonalMD return TONALMDCTCONCEAL_OK; } -static void FindPhases( /* o: currenc phase [-pi;pi] 2Q13 */ - TonalMDCTConcealPtr const hTonalMDCTConc, /* i: pointer to internal structure */ - Word32 secondLastMDCT[], /* i: MDST spectrum data */ - Word32 secondLastMDST[], /* i: MDCT spectrum data */ - Word16 diff_exp) /* i: exp_MDST - exp_MDCT */ +static void FindPhases( /* o: currenc phase [-pi;pi] 2Q13 */ + TonalMDCTConcealPtr const hTonalMDCTConc, /* i: pointer to internal structure */ + Word32 secondLastMDCT[], /* i: MDST spectrum data */ + Word32 secondLastMDST[], /* i: MDCT spectrum data */ + Word16 diff_exp ) /* i: exp_MDST - exp_MDCT */ { Word16 i; Word16 l; Word16 *pCurrentPhase; - pCurrentPhase = hTonalMDCTConc->pTCI->phase_currentFramePredicted; /* for each index/index group */ - FOR( i = 0; i < hTonalMDCTConc->pTCI->numIndexes; i++) + FOR( i = 0; i < hTonalMDCTConc->pTCI->numIndexes; i++ ) { - FOR (l = hTonalMDCTConc->pTCI->lowerIndex[i]; l <= hTonalMDCTConc->pTCI->upperIndex[i]; l++) + FOR( l = hTonalMDCTConc->pTCI->lowerIndex[i]; l <= hTonalMDCTConc->pTCI->upperIndex[i]; l++ ) { /* in contrast to the float code, the parameter secondLastMDST[l] needs not to be negated - due to a different implementation of the MDST */ - *pCurrentPhase++ = BASOP_util_atan2(secondLastMDST[l], secondLastMDCT[l], diff_exp); + *pCurrentPhase++ = BASOP_util_atan2( secondLastMDST[l], secondLastMDCT[l], diff_exp ); move16(); } } - } #define BANDWIDTH 7.0f -#define G 789516047l/*1.0/(2*1.36) Q31*/ -#define MAXRATIO 22938/*44.8f Q9*/ /* Maximum ratio |ODFT[k-1]|/|ODFT[k+1]| is 16.5 dB, that is maximum ratio (for fractional = 0) is (cos(PI/bandwidth)/cos(3PI/bandwidth))^1.36 */ -#define MM 1934815907 /* FL2WORD32(cos(EVS_PI/BANDWIDTH)); */ -#define SS 29166 /* FL2WORD16(cos((3*EVS_PI)/BANDWIDTH)*4); Q17*/ -#define N 931758243 /* FL2WORD32(sin(EVS_PI/BANDWIDTH)); */ -#define J 31946 /* FL2WORD16(sin((3*EVS_PI)/BANDWIDTH)); */ - -static void FindPhaseDifferences( /* o: Phase difference [-pi;pi] 2Q13*/ - TonalMDCTConcealPtr const hTonalMDCTConc, /* i: Pointer to internal structure */ - Word32 powerSpectrum[]) /* i: Power spectrum data */ +#define G 789516047l /*1.0/(2*1.36) Q31*/ +#define MAXRATIO 22938 /*44.8f Q9*/ /* Maximum ratio |ODFT[k-1]|/|ODFT[k+1]| is 16.5 dB, that is maximum ratio (for fractional = 0) is (cos(PI/bandwidth)/cos(3PI/bandwidth))^1.36 */ +#define MM 1934815907 /* FL2WORD32(cos(EVS_PI/BANDWIDTH)); */ +#define SS 29166 /* FL2WORD16(cos((3*EVS_PI)/BANDWIDTH)*4); Q17*/ +#define N 931758243 /* FL2WORD32(sin(EVS_PI/BANDWIDTH)); */ +#define J 31946 /* FL2WORD16(sin((3*EVS_PI)/BANDWIDTH)); */ + +static void FindPhaseDifferences( /* o: Phase difference [-pi;pi] 2Q13*/ + TonalMDCTConcealPtr const hTonalMDCTConc, /* i: Pointer to internal structure */ + Word32 powerSpectrum[] ) /* i: Power spectrum data */ { Word16 i, k; - Word16 * phaseDiff; + Word16 *phaseDiff; Word16 fractional, sf, sfn, sfd; Word16 divi, s, j; Word32 a, Q, L_tmp, m, n; @@ -630,7 +634,7 @@ static void FindPhaseDifferences( /* o: Phase phaseDiff = hTonalMDCTConc->pTCI->phaseDiff; - FOR (i = 0; i < hTonalMDCTConc->pTCI->numIndexes; i++) + FOR( i = 0; i < hTonalMDCTConc->pTCI->numIndexes; i++ ) { m = MM; move16(); @@ -640,79 +644,82 @@ static void FindPhaseDifferences( /* o: Phase k = hTonalMDCTConc->pTCI->indexOfTonalPeak[i]; move16(); - IF (GE_32(Mpy_32_16_1(powerSpectrum[k-1],512/*1.0f Q9*/),Mpy_32_16_1(powerSpectrum[k+1], MAXRATIO))) + IF( GE_32( Mpy_32_16_1( powerSpectrum[k - 1], 512 /*1.0f Q9*/ ), Mpy_32_16_1( powerSpectrum[k + 1], MAXRATIO ) ) ) { - phaseDiff[i] = 0; /*(float)tan(0.0f*EVS_PI/bandwidth);*/ move16(); - if (s_and(k, 1) != 0) + phaseDiff[i] = 0; /*(float)tan(0.0f*EVS_PI/bandwidth);*/ + move16(); + if ( s_and( k, 1 ) != 0 ) { - phaseDiff[i] = -12868/*-EVS_PI 3Q12*/; + phaseDiff[i] = -12868 /*-EVS_PI 3Q12*/; } } ELSE { - IF (GE_32(Mpy_32_16_1(powerSpectrum[k+1],512/*1.0f Q9*/),Mpy_32_16_1(powerSpectrum[k-1], MAXRATIO))) + IF( GE_32( Mpy_32_16_1( powerSpectrum[k + 1], 512 /*1.0f Q9*/ ), Mpy_32_16_1( powerSpectrum[k - 1], MAXRATIO ) ) ) { - phaseDiff[i] = 12868/*EVS_PI 3Q12*/; /*(float)tan(2.0f*PI/bandwidth);*/ move16(); - if (s_and(k, 1) != 0) + phaseDiff[i] = 12868 /*EVS_PI 3Q12*/; /*(float)tan(2.0f*PI/bandwidth);*/ + move16(); + if ( s_and( k, 1 ) != 0 ) { - phaseDiff[i] = 0/*0 Q13*/; /*2Q13*/ + phaseDiff[i] = 0 /*0 Q13*/; /*2Q13*/ } } - ELSE + ELSE { /*Q = (float)pow(odft_left/odft_right, G); a = (m - Q * s) / (n + Q * j); phaseDiff[i] = (float)atan(a) * (bandwidth/2.0f);*/ /*max divi=44.8 & sf=6*/ - divi = BASOP_Util_Divide3232_uu_1616_Scale(powerSpectrum[k-1],powerSpectrum[k+1], &sf); - Q = BASOP_Util_fPow(L_deposit_h(divi), sf, G, 0, &sf); - L_tmp = Mpy_32_16_1(Q,s); - sfn = sub(sf, 2); + divi = BASOP_Util_Divide3232_uu_1616_Scale( powerSpectrum[k - 1], powerSpectrum[k + 1], &sf ); + Q = BASOP_Util_fPow( L_deposit_h( divi ), sf, G, 0, &sf ); + L_tmp = Mpy_32_16_1( Q, s ); + sfn = sub( sf, 2 ); - if (sfn > 0) + if ( sfn > 0 ) { - m = L_shr(m, sfn); + m = L_shr( m, sfn ); } - IF(sfn < 0) + IF( sfn < 0 ) { - L_tmp = L_shl(L_tmp, sfn); + L_tmp = L_shl( L_tmp, sfn ); sfn = 0; } - a = L_sub(m, L_tmp); /*sf*/ + a = L_sub( m, L_tmp ); /*sf*/ - L_tmp = Mpy_32_16_1(Q,j); - IF(sf >= 0) + L_tmp = Mpy_32_16_1( Q, j ); + IF( sf >= 0 ) { - L_tmp = L_shr(L_tmp, 1); - sfd = add(sf,1); - n = L_shr(n,sfd); + L_tmp = L_shr( L_tmp, 1 ); + sfd = add( sf, 1 ); + n = L_shr( n, sfd ); } ELSE { sfd = 0; - L_tmp = L_shl(L_tmp, sf); + L_tmp = L_shl( L_tmp, sf ); } - L_tmp = L_add(n,L_tmp); - fractional = BASOP_util_atan2(a, L_tmp, sub(sfn,sfd)); /*2Q13*/ - L_tmp = L_mult(fractional, 28672/*BANDWIDTH/2.0f Q13*/); /*2Q13*2Q13=4Q27*/ move16(); + L_tmp = L_add( n, L_tmp ); + fractional = BASOP_util_atan2( a, L_tmp, sub( sfn, sfd ) ); /*2Q13*/ + L_tmp = L_mult( fractional, 28672 /*BANDWIDTH/2.0f Q13*/ ); /*2Q13*2Q13=4Q27*/ + move16(); /* fractional is in the range 0..+pi */ /* we need to stay in the range -2pi..+2pi */ - if(EQ_16(s_and(k,3),1)) + if ( EQ_16( s_and( k, 3 ), 1 ) ) { - L_tmp = L_add(L_tmp, 421657440l/*+1*EVS_PI Q27*/); + L_tmp = L_add( L_tmp, 421657440l /*+1*EVS_PI Q27*/ ); } - if(EQ_16(s_and(k,3),2)) + if ( EQ_16( s_and( k, 3 ), 2 ) ) { - L_tmp = L_sub(L_tmp, 843314880l/*+2*EVS_PI=-2*EVS_PI Q27*/); + L_tmp = L_sub( L_tmp, 843314880l /*+2*EVS_PI=-2*EVS_PI Q27*/ ); } - if(EQ_16(s_and(k,3),3)) + if ( EQ_16( s_and( k, 3 ), 3 ) ) { - L_tmp = L_sub(L_tmp, 421657440l/*+3*EVS_PI=-1*EVS_PI Q27*/); + L_tmp = L_sub( L_tmp, 421657440l /*+3*EVS_PI=-1*EVS_PI Q27*/ ); } - phaseDiff[i] = round_fx(L_shl(L_tmp,1)); /*3Q12*/ + phaseDiff[i] = round_fx( L_shl( L_tmp, 1 ) ); /*3Q12*/ } } } @@ -726,9 +733,8 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( Word32 secondLastMDCT[], Word16 secondLastMDCT_exp, Word32 const pitchLag, - const PsychoacousticParameters* psychParamsCurrent, - Word16 element_mode -) + const PsychoacousticParameters *psychParamsCurrent, + Word16 element_mode ) { Word16 nSamples; Word16 i; @@ -745,7 +751,7 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( Flag Overflow = 0; #endif - //Word16 nBands; + // Word16 nBands; Word32 invScaleFactors_fx[FDNS_NPTS]; Word16 old_power_spectrum_q, power_spectrum_q; @@ -753,134 +759,134 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( move16(); /* It is taken into account that the MDCT is not normalized. */ - floorPowerSpectrum/*Q0*/ = extract_l(Mpy_32_16_1(L_mult0(hTonalMDCTConc->nSamples,hTonalMDCTConc->nSamples),82)); /*1/400 = 82 Q15*/ + floorPowerSpectrum /*Q0*/ = extract_l( Mpy_32_16_1( L_mult0( hTonalMDCTConc->nSamples, hTonalMDCTConc->nSamples ), 82 ) ); /*1/400 = 82 Q15*/ powerSpectrum_exp = 0; move16(); - CalcPowerSpec(secondLastMDCT, - secondLastMDCT_exp, - secondLastMDST, - secondLastMDST_exp, - nSamples, - floorPowerSpectrum, - powerSpectrum, - &powerSpectrum_exp); + CalcPowerSpec( secondLastMDCT, + secondLastMDCT_exp, + secondLastMDST, + secondLastMDST_exp, + nSamples, + floorPowerSpectrum, + powerSpectrum, + &powerSpectrum_exp ); /* This setting to minimal level is required because the power spectrum is used in the threshold adaptation using the pitch up to hTonalMDCTConc->nSamples. */ - set32_fx(powerSpectrum+nSamples, floorPowerSpectrum, sub(hTonalMDCTConc->nSamples, nSamples)); + set32_fx( powerSpectrum + nSamples, floorPowerSpectrum, sub( hTonalMDCTConc->nSamples, nSamples ) ); /* this setting to zero is needed since the FDNS needs to be called with hTonalMDCTConc->nSamplesCore; it relevant only for nb; it has no effect to the output, but memory checker may complain otherwise due to the usage of uninitialized values */ - IF ( GT_16(hTonalMDCTConc->nSamplesCore, hTonalMDCTConc->nSamples)) - { - set32_fx(powerSpectrum+hTonalMDCTConc->nSamples, 0, sub(hTonalMDCTConc->nSamplesCore, hTonalMDCTConc->nSamples)); - } - - //DetectTonalComponents(hTonalMDCTConc->pTCI->indexOfTonalPeak, - // hTonalMDCTConc->pTCI->lowerIndex, - // hTonalMDCTConc->pTCI->upperIndex, - // &hTonalMDCTConc->pTCI->numIndexes, - // hTonalMDCTConc->lastPitchLag, - // pitchLag, - // hTonalMDCTConc->lastBlockData.spectralData, - // add(hTonalMDCTConc->lastBlockData.spectralData_exp,hTonalMDCTConc->lastBlockData.gain_tcx_exp), - // hTonalMDCTConc->lastBlockData.scaleFactors, - // hTonalMDCTConc->lastBlockData.scaleFactors_exp, - // hTonalMDCTConc->lastBlockData.scaleFactors_max_e, - // powerSpectrum, - // nSamples, - // hTonalMDCTConc->nSamplesCore, - // floorPowerSpectrum); - - ivas_DetectTonalComponents_fx((Word16 *)hTonalMDCTConc->pTCI->indexOfTonalPeak, - (Word16 *)hTonalMDCTConc->pTCI->lowerIndex, - (Word16 *)hTonalMDCTConc->pTCI->upperIndex, - (Word16 *)&hTonalMDCTConc->pTCI->numIndexes, - hTonalMDCTConc->lastPitchLag, - pitchLag, - hTonalMDCTConc->lastBlockData.spectralData, - add(hTonalMDCTConc->lastBlockData.spectralData_exp,hTonalMDCTConc->lastBlockData.gain_tcx_exp), - hTonalMDCTConc->lastBlockData.scaleFactors, - hTonalMDCTConc->lastBlockData.scaleFactors_exp, - hTonalMDCTConc->lastBlockData.scaleFactors_max_e, - powerSpectrum, - nSamples, - hTonalMDCTConc->nSamplesCore, - floorPowerSpectrum, psychParamsCurrent, element_mode); - FindPhases(hTonalMDCTConc, secondLastMDCT, secondLastMDST, sub(secondLastMDST_exp,secondLastMDCT_exp)); - - FindPhaseDifferences(hTonalMDCTConc, powerSpectrum); - - IF (hTonalMDCTConc->pTCI->numIndexes > 0) + IF( GT_16( hTonalMDCTConc->nSamplesCore, hTonalMDCTConc->nSamples ) ) + { + set32_fx( powerSpectrum + hTonalMDCTConc->nSamples, 0, sub( hTonalMDCTConc->nSamplesCore, hTonalMDCTConc->nSamples ) ); + } + + // DetectTonalComponents(hTonalMDCTConc->pTCI->indexOfTonalPeak, + // hTonalMDCTConc->pTCI->lowerIndex, + // hTonalMDCTConc->pTCI->upperIndex, + // &hTonalMDCTConc->pTCI->numIndexes, + // hTonalMDCTConc->lastPitchLag, + // pitchLag, + // hTonalMDCTConc->lastBlockData.spectralData, + // add(hTonalMDCTConc->lastBlockData.spectralData_exp,hTonalMDCTConc->lastBlockData.gain_tcx_exp), + // hTonalMDCTConc->lastBlockData.scaleFactors, + // hTonalMDCTConc->lastBlockData.scaleFactors_exp, + // hTonalMDCTConc->lastBlockData.scaleFactors_max_e, + // powerSpectrum, + // nSamples, + // hTonalMDCTConc->nSamplesCore, + // floorPowerSpectrum); + + ivas_DetectTonalComponents_fx( (Word16 *) hTonalMDCTConc->pTCI->indexOfTonalPeak, + (Word16 *) hTonalMDCTConc->pTCI->lowerIndex, + (Word16 *) hTonalMDCTConc->pTCI->upperIndex, + (Word16 *) &hTonalMDCTConc->pTCI->numIndexes, + hTonalMDCTConc->lastPitchLag, + pitchLag, + hTonalMDCTConc->lastBlockData.spectralData, + add( hTonalMDCTConc->lastBlockData.spectralData_exp, hTonalMDCTConc->lastBlockData.gain_tcx_exp ), + hTonalMDCTConc->lastBlockData.scaleFactors, + hTonalMDCTConc->lastBlockData.scaleFactors_exp, + hTonalMDCTConc->lastBlockData.scaleFactors_max_e, + powerSpectrum, + nSamples, + hTonalMDCTConc->nSamplesCore, + floorPowerSpectrum, psychParamsCurrent, element_mode ); + FindPhases( hTonalMDCTConc, secondLastMDCT, secondLastMDST, sub( secondLastMDST_exp, secondLastMDCT_exp ) ); + + FindPhaseDifferences( hTonalMDCTConc, powerSpectrum ); + + IF( hTonalMDCTConc->pTCI->numIndexes > 0 ) { hTonalMDCTConc->secondLastPowerSpectrum = hTonalMDCTConc->secondLastBlockData.spectralData; /*sqrtFLOAT(powerSpectrum, powerSpectrum, nSamples);*/ old_exp = powerSpectrum_exp; - powerSpectrum_exp = mult_r(sub(powerSpectrum_exp,2), 1 << 14); /*remove 2 bits of headroom from CalcPowerSpec*/ - FOR (i = 0; i < nSamples; i++) + powerSpectrum_exp = mult_r( sub( powerSpectrum_exp, 2 ), 1 << 14 ); /*remove 2 bits of headroom from CalcPowerSpec*/ + FOR( i = 0; i < nSamples; i++ ) { tmp_exp = old_exp; - powerSpectrum[i] = Sqrt32(powerSpectrum[i], &tmp_exp); - powerSpectrum[i] = L_shr(powerSpectrum[i], sub(powerSpectrum_exp, tmp_exp)); + powerSpectrum[i] = Sqrt32( powerSpectrum[i], &tmp_exp ); + powerSpectrum[i] = L_shr( powerSpectrum[i], sub( powerSpectrum_exp, tmp_exp ) ); move32(); } - FOR (i = 0; i < hTonalMDCTConc->nScaleFactors; i++) + FOR( i = 0; i < hTonalMDCTConc->nScaleFactors; i++ ) { move16(); move16(); invScaleFactors_exp[i] = hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[i]; - invScaleFactors[i] = Inv16(hTonalMDCTConc->secondLastBlockData.scaleFactors[i], &invScaleFactors_exp[i]); + invScaleFactors[i] = Inv16( hTonalMDCTConc->secondLastBlockData.scaleFactors[i], &invScaleFactors_exp[i] ); } power_spectrum_q = 31 - powerSpectrum_exp; old_power_spectrum_q = power_spectrum_q; /* here mdct_shaping() is intentionally used rather then mdct_shaping_16() */ - IF (psychParamsCurrent == NULL) + IF( psychParamsCurrent == NULL ) { - mdct_shaping(powerSpectrum, hTonalMDCTConc->nSamplesCore, invScaleFactors, invScaleFactors_exp); + mdct_shaping( powerSpectrum, hTonalMDCTConc->nSamplesCore, invScaleFactors, invScaleFactors_exp ); } ELSE { - FOR( i = 0; i < FDNS_NPTS; i++ ) + FOR( i = 0; i < FDNS_NPTS; i++ ) { - invScaleFactors_fx[i] = L_shl(invScaleFactors[i], 1 + invScaleFactors_exp[i]); // Q16 + invScaleFactors_fx[i] = L_shl( invScaleFactors[i], 1 + invScaleFactors_exp[i] ); // Q16 } sns_shape_spectrum_fx( powerSpectrum, &power_spectrum_q, psychParamsCurrent, invScaleFactors_fx, 16, hTonalMDCTConc->nSamplesCore ); power_spectrum_q++; // sns_shape_spectrum(powerSpectrum, psychParamsCurrent, invScaleFactors, hTonalMDCTConc->nSamplesCore); - //nBands = psychParamsCurrent->nBands; + // nBands = psychParamsCurrent->nBands; } IF( old_power_spectrum_q < power_spectrum_q ) - Scale_sig32( powerSpectrum, hTonalMDCTConc->nSamplesCore, old_power_spectrum_q - power_spectrum_q ); + Scale_sig32( powerSpectrum, hTonalMDCTConc->nSamplesCore, old_power_spectrum_q - power_spectrum_q ); ELSE { Scale_sig32( powerSpectrum + hTonalMDCTConc->nSamplesCore, nSamples - hTonalMDCTConc->nSamplesCore, power_spectrum_q - old_power_spectrum_q ); powerSpectrum_exp = 31 - power_spectrum_q; } - Scale_sig32( powerSpectrum, nSamples, -3 );/*Adding guard bits*/ + Scale_sig32( powerSpectrum, nSamples, -3 ); /*Adding guard bits*/ powerSpectrum_exp += 3; - FOR (i = hTonalMDCTConc->nSamplesCore; i < nSamples; i++) + FOR( i = hTonalMDCTConc->nSamplesCore; i < nSamples; i++ ) { - powerSpectrum[i] = L_shl(Mpy_32_16_1(powerSpectrum[i], invScaleFactors[FDNS_NPTS-1]), invScaleFactors_exp[FDNS_NPTS-1]); + powerSpectrum[i] = L_shl( Mpy_32_16_1( powerSpectrum[i], invScaleFactors[FDNS_NPTS - 1] ), invScaleFactors_exp[FDNS_NPTS - 1] ); move32(); } /* 16 bits are now enough for storing the power spectrum */ - FOR (i = 0; i < nSamples; i++) + FOR( i = 0; i < nSamples; i++ ) { #ifdef BASOP_NOGLOB - hTonalMDCTConc->secondLastPowerSpectrum[i] = round_fx_o(powerSpectrum[i], &Overflow); + hTonalMDCTConc->secondLastPowerSpectrum[i] = round_fx_o( powerSpectrum[i], &Overflow ); #else - hTonalMDCTConc->secondLastPowerSpectrum[i] = round_fx(powerSpectrum[i]); + hTonalMDCTConc->secondLastPowerSpectrum[i] = round_fx( powerSpectrum[i] ); #endif } - powerSpectrum_exp = sub(powerSpectrum_exp, hTonalMDCTConc->secondLastBlockData.gain_tcx_exp); + powerSpectrum_exp = sub( powerSpectrum_exp, hTonalMDCTConc->secondLastBlockData.gain_tcx_exp ); hTonalMDCTConc->secondLastPowerSpectrum_exp = powerSpectrum_exp; move16(); } @@ -896,7 +902,8 @@ static void CalcPowerSpecAndDetectTonalComponents( Word32 const pitchLag, Word16 element_mode #ifdef IVAS_CODE_MDCT_GSHAPE - ,const PsychoacousticParameters* psychParamsCurrent + , + const PsychoacousticParameters *psychParamsCurrent #endif ) { @@ -916,90 +923,90 @@ static void CalcPowerSpecAndDetectTonalComponents( move16(); /* It is taken into account that the MDCT is not normalized. */ - floorPowerSpectrum/*Q0*/ = extract_l(Mpy_32_16_1(L_mult0(hTonalMDCTConc->nSamples,hTonalMDCTConc->nSamples),82)); /*1/400 = 82 Q15*/ + floorPowerSpectrum /*Q0*/ = extract_l( Mpy_32_16_1( L_mult0( hTonalMDCTConc->nSamples, hTonalMDCTConc->nSamples ), 82 ) ); /*1/400 = 82 Q15*/ powerSpectrum_exp = 0; move16(); - CalcPowerSpec(secondLastMDCT, - secondLastMDCT_exp, - secondLastMDST, - secondLastMDST_exp, - nSamples, - floorPowerSpectrum, - powerSpectrum, - &powerSpectrum_exp); + CalcPowerSpec( secondLastMDCT, + secondLastMDCT_exp, + secondLastMDST, + secondLastMDST_exp, + nSamples, + floorPowerSpectrum, + powerSpectrum, + &powerSpectrum_exp ); /* This setting to minimal level is required because the power spectrum is used in the threshold adaptation using the pitch up to hTonalMDCTConc->nSamples. */ - set32_fx(powerSpectrum+nSamples, floorPowerSpectrum, sub(hTonalMDCTConc->nSamples, nSamples)); + set32_fx( powerSpectrum + nSamples, floorPowerSpectrum, sub( hTonalMDCTConc->nSamples, nSamples ) ); /* this setting to zero is needed since the FDNS needs to be called with hTonalMDCTConc->nSamplesCore; it relevant only for nb; it has no effect to the output, but memory checker may complain otherwise due to the usage of uninitialized values */ - IF ( GT_16(hTonalMDCTConc->nSamplesCore, hTonalMDCTConc->nSamples)) + IF( GT_16( hTonalMDCTConc->nSamplesCore, hTonalMDCTConc->nSamples ) ) { - set32_fx(powerSpectrum+hTonalMDCTConc->nSamples, 0, sub(hTonalMDCTConc->nSamplesCore, hTonalMDCTConc->nSamples)); + set32_fx( powerSpectrum + hTonalMDCTConc->nSamples, 0, sub( hTonalMDCTConc->nSamplesCore, hTonalMDCTConc->nSamples ) ); } - DetectTonalComponents((Word16 *)hTonalMDCTConc->pTCI->indexOfTonalPeak, - (Word16 *)hTonalMDCTConc->pTCI->lowerIndex, - (Word16 *)hTonalMDCTConc->pTCI->upperIndex, - (Word16 *)&hTonalMDCTConc->pTCI->numIndexes, - hTonalMDCTConc->lastPitchLag, - pitchLag, - hTonalMDCTConc->lastBlockData.spectralData, - add(hTonalMDCTConc->lastBlockData.spectralData_exp,hTonalMDCTConc->lastBlockData.gain_tcx_exp), - hTonalMDCTConc->lastBlockData.scaleFactors, - hTonalMDCTConc->lastBlockData.scaleFactors_exp, - hTonalMDCTConc->lastBlockData.scaleFactors_max_e, - powerSpectrum, - nSamples, - hTonalMDCTConc->nSamplesCore, - floorPowerSpectrum, element_mode); - FindPhases(hTonalMDCTConc, secondLastMDCT, secondLastMDST, sub(secondLastMDST_exp,secondLastMDCT_exp)); - - FindPhaseDifferences(hTonalMDCTConc, powerSpectrum); - - IF (hTonalMDCTConc->pTCI->numIndexes > 0) + DetectTonalComponents( (Word16 *) hTonalMDCTConc->pTCI->indexOfTonalPeak, + (Word16 *) hTonalMDCTConc->pTCI->lowerIndex, + (Word16 *) hTonalMDCTConc->pTCI->upperIndex, + (Word16 *) &hTonalMDCTConc->pTCI->numIndexes, + hTonalMDCTConc->lastPitchLag, + pitchLag, + hTonalMDCTConc->lastBlockData.spectralData, + add( hTonalMDCTConc->lastBlockData.spectralData_exp, hTonalMDCTConc->lastBlockData.gain_tcx_exp ), + hTonalMDCTConc->lastBlockData.scaleFactors, + hTonalMDCTConc->lastBlockData.scaleFactors_exp, + hTonalMDCTConc->lastBlockData.scaleFactors_max_e, + powerSpectrum, + nSamples, + hTonalMDCTConc->nSamplesCore, + floorPowerSpectrum, element_mode ); + FindPhases( hTonalMDCTConc, secondLastMDCT, secondLastMDST, sub( secondLastMDST_exp, secondLastMDCT_exp ) ); + + FindPhaseDifferences( hTonalMDCTConc, powerSpectrum ); + + IF( hTonalMDCTConc->pTCI->numIndexes > 0 ) { hTonalMDCTConc->secondLastPowerSpectrum = hTonalMDCTConc->secondLastBlockData.spectralData; /*sqrtFLOAT(powerSpectrum, powerSpectrum, nSamples);*/ old_exp = powerSpectrum_exp; - powerSpectrum_exp = mult_r(sub(powerSpectrum_exp,2), 1 << 14); /*remove 2 bits of headroom from CalcPowerSpec*/ - FOR (i = 0; i < nSamples; i++) + powerSpectrum_exp = mult_r( sub( powerSpectrum_exp, 2 ), 1 << 14 ); /*remove 2 bits of headroom from CalcPowerSpec*/ + FOR( i = 0; i < nSamples; i++ ) { tmp_exp = old_exp; - powerSpectrum[i] = Sqrt32(powerSpectrum[i], &tmp_exp); - powerSpectrum[i] = L_shr(powerSpectrum[i], sub(powerSpectrum_exp, tmp_exp)); + powerSpectrum[i] = Sqrt32( powerSpectrum[i], &tmp_exp ); + powerSpectrum[i] = L_shr( powerSpectrum[i], sub( powerSpectrum_exp, tmp_exp ) ); move32(); } - FOR (i = 0; i < hTonalMDCTConc->nScaleFactors; i++) + FOR( i = 0; i < hTonalMDCTConc->nScaleFactors; i++ ) { move16(); move16(); invScaleFactors_exp[i] = hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[i]; - invScaleFactors[i] = Inv16(hTonalMDCTConc->secondLastBlockData.scaleFactors[i], &invScaleFactors_exp[i]); + invScaleFactors[i] = Inv16( hTonalMDCTConc->secondLastBlockData.scaleFactors[i], &invScaleFactors_exp[i] ); } /* here mdct_shaping() is intentionally used rather then mdct_shaping_16() */ #ifdef IVAS_CODE_MDCT_GSHAPE - IF (psychParamsCurrent == NULL) + IF( psychParamsCurrent == NULL ) #endif { - mdct_shaping(powerSpectrum, hTonalMDCTConc->nSamplesCore, invScaleFactors, invScaleFactors_exp); + mdct_shaping( powerSpectrum, hTonalMDCTConc->nSamplesCore, invScaleFactors, invScaleFactors_exp ); } #ifdef IVAS_CODE_MDCT_GSHAPE ELSE { -PMTE() - sns_shape_spectrum(powerSpectrum, psychParamsCurrent, invScaleFactors, hTonalMDCTConc->nSamplesCore); + PMTE() + sns_shape_spectrum( powerSpectrum, psychParamsCurrent, invScaleFactors, hTonalMDCTConc->nSamplesCore ); nBands = psychParamsCurrent->nBands; } #endif - FOR (i = hTonalMDCTConc->nSamplesCore; i < nSamples; i++) + FOR( i = hTonalMDCTConc->nSamplesCore; i < nSamples; i++ ) { #ifdef BASOP_NOGLOB powerSpectrum[i] = L_shl_sat( Mpy_32_16_1( powerSpectrum[i], invScaleFactors[FDNS_NPTS - 1] ), invScaleFactors_exp[FDNS_NPTS - 1] ); @@ -1010,16 +1017,16 @@ PMTE() } /* 16 bits are now enough for storing the power spectrum */ - FOR (i = 0; i < nSamples; i++) + FOR( i = 0; i < nSamples; i++ ) { #ifdef BASOP_NOGLOB - hTonalMDCTConc->secondLastPowerSpectrum[i] = round_fx_o(powerSpectrum[i], &Overflow); + hTonalMDCTConc->secondLastPowerSpectrum[i] = round_fx_o( powerSpectrum[i], &Overflow ); #else - hTonalMDCTConc->secondLastPowerSpectrum[i] = round_fx(powerSpectrum[i]); + hTonalMDCTConc->secondLastPowerSpectrum[i] = round_fx( powerSpectrum[i] ); #endif } - powerSpectrum_exp = sub(powerSpectrum_exp, hTonalMDCTConc->secondLastBlockData.gain_tcx_exp); + powerSpectrum_exp = sub( powerSpectrum_exp, hTonalMDCTConc->secondLastBlockData.gain_tcx_exp ); hTonalMDCTConc->secondLastPowerSpectrum_exp = powerSpectrum_exp; move16(); } @@ -1029,75 +1036,73 @@ PMTE() static void CalcMDXT( const TonalMDCTConcealPtr hTonalMDCTConc, const Word16 type, - const Word16 * timeSignal, - Word32 * mdxtOutput, - Word16 * mdxtOutput_e -) + const Word16 *timeSignal, + Word32 *mdxtOutput, + Word16 *mdxtOutput_e ) { - Word16 windowedTimeSignal[L_FRAME_PLUS+2*L_MDCT_OVLP_MAX]; + Word16 windowedTimeSignal[L_FRAME_PLUS + 2 * L_MDCT_OVLP_MAX]; Word16 left_overlap, right_overlap, L_frame; L_frame = hTonalMDCTConc->nSamples; move16(); - WindowSignal(hTonalMDCTConc->tcx_cfg, hTonalMDCTConc->tcx_cfg->tcx_offsetFB, FULL_OVERLAP, - FULL_OVERLAP, &left_overlap, &right_overlap, timeSignal, &L_frame, windowedTimeSignal, 1, 1); + WindowSignal( hTonalMDCTConc->tcx_cfg, hTonalMDCTConc->tcx_cfg->tcx_offsetFB, FULL_OVERLAP, + FULL_OVERLAP, &left_overlap, &right_overlap, timeSignal, &L_frame, windowedTimeSignal, 1, 1 ); - IF (type == 0) + IF( type == 0 ) { - TCX_MDST(windowedTimeSignal, mdxtOutput, mdxtOutput_e, left_overlap, - sub(L_frame, shr(add(left_overlap, right_overlap), 1)), right_overlap, EVS_MONO); + TCX_MDST( windowedTimeSignal, mdxtOutput, mdxtOutput_e, left_overlap, + sub( L_frame, shr( add( left_overlap, right_overlap ), 1 ) ), right_overlap, EVS_MONO ); } ELSE { - TCX_MDCT(windowedTimeSignal, mdxtOutput, mdxtOutput_e, left_overlap, - sub(L_frame, shr(add(left_overlap, right_overlap), 1)), right_overlap, EVS_MONO); + TCX_MDCT( windowedTimeSignal, mdxtOutput, mdxtOutput_e, left_overlap, + sub( L_frame, shr( add( left_overlap, right_overlap ), 1 ) ), right_overlap, EVS_MONO ); } } -void TonalMDCTConceal_Detect( +void TonalMDCTConceal_Detect( const TonalMDCTConcealPtr hTonalMDCTConc, const Word32 pitchLag, - Word16 * numIndices, + Word16 *numIndices, Word16 element_mode #ifdef IVAS_CODE_MDCT_GSHAPE - ,const PsychoacousticParameters* psychParamsCurrent + , + const PsychoacousticParameters *psychParamsCurrent #endif ) { Word32 secondLastMDST[L_FRAME_MAX]; Word32 secondLastMDCT[L_FRAME_MAX]; Word16 secondLastMDCT_exp; - Word32 * powerSpectrum = secondLastMDST; + Word32 *powerSpectrum = secondLastMDST; Word16 i, powerSpectrum_exp, secondLastMDST_exp, s; Word16 nSamples; nSamples = hTonalMDCTConc->nSamples; move16(); - secondLastMDST_exp = 16; /*time signal Q-1*/ - secondLastMDCT_exp = 16; /*time signal Q-1*/ + secondLastMDST_exp = 16; /*time signal Q-1*/ + secondLastMDCT_exp = 16; /*time signal Q-1*/ test(); test(); test(); test(); test(); - IF (hTonalMDCTConc->lastBlockData.blockIsValid && hTonalMDCTConc->secondLastBlockData.blockIsValid - && (EQ_16(hTonalMDCTConc->lastBlockData.nSamples,nSamples) ) && (EQ_16(hTonalMDCTConc->secondLastBlockData.nSamples,nSamples) ) - && (!hTonalMDCTConc->secondLastBlockData.blockIsConcealed || hTonalMDCTConc->secondLastBlockData.tonalConcealmentActive || (pitchLag != 0)) ) + IF( hTonalMDCTConc->lastBlockData.blockIsValid && hTonalMDCTConc->secondLastBlockData.blockIsValid && ( EQ_16( hTonalMDCTConc->lastBlockData.nSamples, nSamples ) ) && ( EQ_16( hTonalMDCTConc->secondLastBlockData.nSamples, nSamples ) ) && ( !hTonalMDCTConc->secondLastBlockData.blockIsConcealed || hTonalMDCTConc->secondLastBlockData.tonalConcealmentActive || ( pitchLag != 0 ) ) ) { /* Safety if the second last frame was concealed and tonal concealment was inactive */ - IF (hTonalMDCTConc->lastBlockData.blockIsConcealed == 0) + IF( hTonalMDCTConc->lastBlockData.blockIsConcealed == 0 ) { - IF (hTonalMDCTConc->secondLastBlockData.tonalConcealmentActive == 0) + IF( hTonalMDCTConc->secondLastBlockData.tonalConcealmentActive == 0 ) { - CalcMDXT(hTonalMDCTConc, 0, hTonalMDCTConc->secondLastPcmOut, secondLastMDST, &secondLastMDST_exp); - CalcMDXT(hTonalMDCTConc, 1, hTonalMDCTConc->secondLastPcmOut, secondLastMDCT, &secondLastMDCT_exp); + CalcMDXT( hTonalMDCTConc, 0, hTonalMDCTConc->secondLastPcmOut, secondLastMDST, &secondLastMDST_exp ); + CalcMDXT( hTonalMDCTConc, 1, hTonalMDCTConc->secondLastPcmOut, secondLastMDCT, &secondLastMDCT_exp ); hTonalMDCTConc->nNonZeroSamples = 0; - FOR (i = 0; i < hTonalMDCTConc->nSamples; i++) + FOR( i = 0; i < hTonalMDCTConc->nSamples; i++ ) { - if (hTonalMDCTConc->secondLastBlockData.spectralData[i] != 0) + if ( hTonalMDCTConc->secondLastBlockData.spectralData[i] != 0 ) { hTonalMDCTConc->nNonZeroSamples = i; move16(); @@ -1105,81 +1110,80 @@ void TonalMDCTConceal_Detect( } /* 23 is the maximum length of the MA filter in getEnvelope */ - hTonalMDCTConc->nNonZeroSamples = s_min(hTonalMDCTConc->nSamples, add(hTonalMDCTConc->nNonZeroSamples, 23)); + hTonalMDCTConc->nNonZeroSamples = s_min( hTonalMDCTConc->nSamples, add( hTonalMDCTConc->nNonZeroSamples, 23 ) ); move16(); nSamples = hTonalMDCTConc->nNonZeroSamples; move16(); - s = getScaleFactor32(secondLastMDST, nSamples); + s = getScaleFactor32( secondLastMDST, nSamples ); - FOR (i = 0; i < nSamples; i++) + FOR( i = 0; i < nSamples; i++ ) { - secondLastMDST[i] = L_shl(secondLastMDST[i], s); + secondLastMDST[i] = L_shl( secondLastMDST[i], s ); move32(); } - secondLastMDST_exp = sub(secondLastMDST_exp, s); + secondLastMDST_exp = sub( secondLastMDST_exp, s ); move16(); - s = getScaleFactor32(secondLastMDCT, nSamples); + s = getScaleFactor32( secondLastMDCT, nSamples ); - FOR (i = 0; i < nSamples; i++) + FOR( i = 0; i < nSamples; i++ ) { - secondLastMDCT[i] = L_shl(secondLastMDCT[i], s); + secondLastMDCT[i] = L_shl( secondLastMDCT[i], s ); move32(); } - secondLastMDCT_exp = sub(secondLastMDCT_exp, s); + secondLastMDCT_exp = sub( secondLastMDCT_exp, s ); move16(); - CalcPowerSpecAndDetectTonalComponents(hTonalMDCTConc, secondLastMDST, secondLastMDST_exp, secondLastMDCT, secondLastMDCT_exp, pitchLag, element_mode); + CalcPowerSpecAndDetectTonalComponents( hTonalMDCTConc, secondLastMDST, secondLastMDST_exp, secondLastMDCT, secondLastMDCT_exp, pitchLag, element_mode ); } ELSE { /* If the second last frame was also lost, it is expected that pastTimeSignal could hold a bit different signal (e.g. including fade-out) from the one stored in TonalMDCTConceal_SaveTimeSignal. */ /* That is why we reuse the already stored information about the concealed spectrum in the second last frame */ #ifdef IVAS_CODE_MDCT_GSHAPE - IF (psychParamsCurrent == NULL) + IF( psychParamsCurrent == NULL ) #endif { nSamples = hTonalMDCTConc->nNonZeroSamples; move16(); - mdct_shaping_16(hTonalMDCTConc->secondLastPowerSpectrum, hTonalMDCTConc->nSamplesCore, nSamples, - hTonalMDCTConc->secondLastBlockData.scaleFactors, hTonalMDCTConc->secondLastBlockData.scaleFactors_exp, - hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e, powerSpectrum); + mdct_shaping_16( hTonalMDCTConc->secondLastPowerSpectrum, hTonalMDCTConc->nSamplesCore, nSamples, + hTonalMDCTConc->secondLastBlockData.scaleFactors, hTonalMDCTConc->secondLastBlockData.scaleFactors_exp, + hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e, powerSpectrum ); } #ifdef IVAS_CODE_MDCT_GSHAPE ELSE { - sns_shape_spectrum(powerSpectrum, psychParamsCurrent, hTonalMDCTConc->secondLastBlockData.scaleFactors, hTonalMDCTConc->nSamplesCore); + sns_shape_spectrum( powerSpectrum, psychParamsCurrent, hTonalMDCTConc->secondLastBlockData.scaleFactors, hTonalMDCTConc->nSamplesCore ); nBands = psychParamsCurrent->nBands; } #endif - powerSpectrum_exp = getScaleFactor32(powerSpectrum, nSamples); - powerSpectrum_exp = sub(powerSpectrum_exp, 3); /*extra 3 bits of headroom for MA filter in getEnvelope*/ + powerSpectrum_exp = getScaleFactor32( powerSpectrum, nSamples ); + powerSpectrum_exp = sub( powerSpectrum_exp, 3 ); /*extra 3 bits of headroom for MA filter in getEnvelope*/ /* multFLOAT(powerSpectrum, powerSpectrum, powerSpectrum, nSamples); */ - FOR(i = 0; i < nSamples; i++) + FOR( i = 0; i < nSamples; i++ ) { - Word32 const t = L_shl(powerSpectrum[i], powerSpectrum_exp); - powerSpectrum[i] = Mpy_32_32(t, t); + Word32 const t = L_shl( powerSpectrum[i], powerSpectrum_exp ); + powerSpectrum[i] = Mpy_32_32( t, t ); move32(); } - RefineTonalComponents((Word16 *)hTonalMDCTConc->pTCI->indexOfTonalPeak, - (Word16 *)hTonalMDCTConc->pTCI->lowerIndex, - (Word16 *)hTonalMDCTConc->pTCI->upperIndex, - hTonalMDCTConc->pTCI->phaseDiff, - hTonalMDCTConc->pTCI->phase_currentFramePredicted, - (Word16 *)&hTonalMDCTConc->pTCI->numIndexes, - hTonalMDCTConc->lastPitchLag, - pitchLag, - hTonalMDCTConc->lastBlockData.spectralData, - add(hTonalMDCTConc->lastBlockData.spectralData_exp,hTonalMDCTConc->lastBlockData.gain_tcx_exp), - hTonalMDCTConc->lastBlockData.scaleFactors, - hTonalMDCTConc->lastBlockData.scaleFactors_exp, - hTonalMDCTConc->lastBlockData.scaleFactors_max_e, - powerSpectrum, - nSamples, - hTonalMDCTConc->nSamplesCore, - extract_l(Mpy_32_16_1(L_mult0(hTonalMDCTConc->nSamples,hTonalMDCTConc->nSamples),82)), element_mode); /* floorPowerSpectrum */ - + RefineTonalComponents( (Word16 *) hTonalMDCTConc->pTCI->indexOfTonalPeak, + (Word16 *) hTonalMDCTConc->pTCI->lowerIndex, + (Word16 *) hTonalMDCTConc->pTCI->upperIndex, + hTonalMDCTConc->pTCI->phaseDiff, + hTonalMDCTConc->pTCI->phase_currentFramePredicted, + (Word16 *) &hTonalMDCTConc->pTCI->numIndexes, + hTonalMDCTConc->lastPitchLag, + pitchLag, + hTonalMDCTConc->lastBlockData.spectralData, + add( hTonalMDCTConc->lastBlockData.spectralData_exp, hTonalMDCTConc->lastBlockData.gain_tcx_exp ), + hTonalMDCTConc->lastBlockData.scaleFactors, + hTonalMDCTConc->lastBlockData.scaleFactors_exp, + hTonalMDCTConc->lastBlockData.scaleFactors_max_e, + powerSpectrum, + nSamples, + hTonalMDCTConc->nSamplesCore, + extract_l( Mpy_32_16_1( L_mult0( hTonalMDCTConc->nSamples, hTonalMDCTConc->nSamples ), 82 ) ), element_mode ); /* floorPowerSpectrum */ } } } @@ -1193,52 +1197,49 @@ void TonalMDCTConceal_Detect( move16(); - return ; + return; } #ifdef IVAS_FLOAT_FIXED void TonalMDCTConceal_Detect_ivas_fx( const TonalMDCTConcealPtr hTonalMDCTConc, const Word32 pitchLag, - Word16 * numIndices, - const PsychoacousticParameters* psychParamsCurrent, - Word16 element_mode -) + Word16 *numIndices, + const PsychoacousticParameters *psychParamsCurrent, + Word16 element_mode ) { Word32 secondLastMDST[L_FRAME_MAX]; Word32 secondLastMDCT[L_FRAME_MAX]; Word16 secondLastMDCT_exp; - Word32 * powerSpectrum = secondLastMDST; + Word32 *powerSpectrum = secondLastMDST; Word16 i, powerSpectrum_exp, secondLastMDST_exp, s; Word16 nSamples; - //Word16 nBands; + // Word16 nBands; Word32 sns_int_scf_fx[FDNS_NPTS]; nSamples = hTonalMDCTConc->nSamples; move16(); - secondLastMDST_exp = 16; /*time signal Q-1*/ - secondLastMDCT_exp = 16; /*time signal Q-1*/ + secondLastMDST_exp = 16; /*time signal Q-1*/ + secondLastMDCT_exp = 16; /*time signal Q-1*/ test(); test(); test(); test(); test(); - IF(hTonalMDCTConc->lastBlockData.blockIsValid && hTonalMDCTConc->secondLastBlockData.blockIsValid - && (EQ_16(hTonalMDCTConc->lastBlockData.nSamples, nSamples)) && (EQ_16(hTonalMDCTConc->secondLastBlockData.nSamples, nSamples)) - && (!hTonalMDCTConc->secondLastBlockData.blockIsConcealed || hTonalMDCTConc->secondLastBlockData.tonalConcealmentActive || (pitchLag != 0))) + IF( hTonalMDCTConc->lastBlockData.blockIsValid && hTonalMDCTConc->secondLastBlockData.blockIsValid && ( EQ_16( hTonalMDCTConc->lastBlockData.nSamples, nSamples ) ) && ( EQ_16( hTonalMDCTConc->secondLastBlockData.nSamples, nSamples ) ) && ( !hTonalMDCTConc->secondLastBlockData.blockIsConcealed || hTonalMDCTConc->secondLastBlockData.tonalConcealmentActive || ( pitchLag != 0 ) ) ) { /* Safety if the second last frame was concealed and tonal concealment was inactive */ - IF(hTonalMDCTConc->lastBlockData.blockIsConcealed == 0) + IF( hTonalMDCTConc->lastBlockData.blockIsConcealed == 0 ) { - IF(hTonalMDCTConc->secondLastBlockData.tonalConcealmentActive == 0) + IF( hTonalMDCTConc->secondLastBlockData.tonalConcealmentActive == 0 ) { - CalcMDXT(hTonalMDCTConc, 0, hTonalMDCTConc->secondLastPcmOut, secondLastMDST, &secondLastMDST_exp); - CalcMDXT(hTonalMDCTConc, 1, hTonalMDCTConc->secondLastPcmOut, secondLastMDCT, &secondLastMDCT_exp); + CalcMDXT( hTonalMDCTConc, 0, hTonalMDCTConc->secondLastPcmOut, secondLastMDST, &secondLastMDST_exp ); + CalcMDXT( hTonalMDCTConc, 1, hTonalMDCTConc->secondLastPcmOut, secondLastMDCT, &secondLastMDCT_exp ); hTonalMDCTConc->nNonZeroSamples = 0; - FOR(i = 0; i < hTonalMDCTConc->nSamples; i++) + FOR( i = 0; i < hTonalMDCTConc->nSamples; i++ ) { - if (hTonalMDCTConc->secondLastBlockData.spectralData[i] != 0) + if ( hTonalMDCTConc->secondLastBlockData.spectralData[i] != 0 ) { hTonalMDCTConc->nNonZeroSamples = i; move16(); @@ -1246,84 +1247,83 @@ void TonalMDCTConceal_Detect_ivas_fx( } /* 23 is the maximum length of the MA filter in getEnvelope */ - hTonalMDCTConc->nNonZeroSamples = s_min(hTonalMDCTConc->nSamples, add(hTonalMDCTConc->nNonZeroSamples, 23)); + hTonalMDCTConc->nNonZeroSamples = s_min( hTonalMDCTConc->nSamples, add( hTonalMDCTConc->nNonZeroSamples, 23 ) ); move16(); nSamples = hTonalMDCTConc->nNonZeroSamples; move16(); - s = getScaleFactor32(secondLastMDST, nSamples); + s = getScaleFactor32( secondLastMDST, nSamples ); - FOR(i = 0; i < nSamples; i++) + FOR( i = 0; i < nSamples; i++ ) { - secondLastMDST[i] = L_shl(secondLastMDST[i], s); + secondLastMDST[i] = L_shl( secondLastMDST[i], s ); move32(); } - secondLastMDST_exp = sub(secondLastMDST_exp, s); + secondLastMDST_exp = sub( secondLastMDST_exp, s ); move16(); - s = getScaleFactor32(secondLastMDCT, nSamples); + s = getScaleFactor32( secondLastMDCT, nSamples ); - FOR(i = 0; i < nSamples; i++) + FOR( i = 0; i < nSamples; i++ ) { - secondLastMDCT[i] = L_shl(secondLastMDCT[i], s); + secondLastMDCT[i] = L_shl( secondLastMDCT[i], s ); move32(); } - secondLastMDCT_exp = sub(secondLastMDCT_exp, s); + secondLastMDCT_exp = sub( secondLastMDCT_exp, s ); move16(); - //CalcPowerSpecAndDetectTonalComponents(hTonalMDCTConc, secondLastMDST, secondLastMDST_exp, secondLastMDCT, secondLastMDCT_exp, pitchLag); - ivas_CalcPowerSpecAndDetectTonalComponents_fx(hTonalMDCTConc, secondLastMDST, secondLastMDST_exp, secondLastMDCT, secondLastMDCT_exp, pitchLag, psychParamsCurrent, element_mode); + // CalcPowerSpecAndDetectTonalComponents(hTonalMDCTConc, secondLastMDST, secondLastMDST_exp, secondLastMDCT, secondLastMDCT_exp, pitchLag); + ivas_CalcPowerSpecAndDetectTonalComponents_fx( hTonalMDCTConc, secondLastMDST, secondLastMDST_exp, secondLastMDCT, secondLastMDCT_exp, pitchLag, psychParamsCurrent, element_mode ); } ELSE { /* If the second last frame was also lost, it is expected that pastTimeSignal could hold a bit different signal (e.g. including fade-out) from the one stored in TonalMDCTConceal_SaveTimeSignal. */ /* That is why we reuse the already stored information about the concealed spectrum in the second last frame */ - IF(psychParamsCurrent == NULL) + IF( psychParamsCurrent == NULL ) { nSamples = hTonalMDCTConc->nNonZeroSamples; move16(); - mdct_shaping_16(hTonalMDCTConc->secondLastPowerSpectrum, hTonalMDCTConc->nSamplesCore, nSamples, - hTonalMDCTConc->secondLastBlockData.scaleFactors, hTonalMDCTConc->secondLastBlockData.scaleFactors_exp, - hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e, powerSpectrum); + mdct_shaping_16( hTonalMDCTConc->secondLastPowerSpectrum, hTonalMDCTConc->nSamplesCore, nSamples, + hTonalMDCTConc->secondLastBlockData.scaleFactors, hTonalMDCTConc->secondLastBlockData.scaleFactors_exp, + hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e, powerSpectrum ); } ELSE { - //sns_shape_spectrum(powerSpectrum, psychParamsCurrent, hTonalMDCTConc->secondLastBlockData.scaleFactors, hTonalMDCTConc->nSamplesCore); + // sns_shape_spectrum(powerSpectrum, psychParamsCurrent, hTonalMDCTConc->secondLastBlockData.scaleFactors, hTonalMDCTConc->nSamplesCore); Word16 power_spectrum_q; - FOR( i = 0; i < FDNS_NPTS; i++) - { - sns_int_scf_fx[i] = L_shl(hTonalMDCTConc->secondLastBlockData.scaleFactors[i], 1 + hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[i]); // Q16 - } - sns_shape_spectrum_fx(powerSpectrum, &power_spectrum_q, psychParamsCurrent, sns_int_scf_fx, 16, hTonalMDCTConc->nSamplesCore); - //nBands = psychParamsCurrent->nBands; + FOR( i = 0; i < FDNS_NPTS; i++ ) + { + sns_int_scf_fx[i] = L_shl( hTonalMDCTConc->secondLastBlockData.scaleFactors[i], 1 + hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[i] ); // Q16 + } + sns_shape_spectrum_fx( powerSpectrum, &power_spectrum_q, psychParamsCurrent, sns_int_scf_fx, 16, hTonalMDCTConc->nSamplesCore ); + // nBands = psychParamsCurrent->nBands; } - powerSpectrum_exp = getScaleFactor32(powerSpectrum, nSamples); - powerSpectrum_exp = sub(powerSpectrum_exp, 3); /*extra 3 bits of headroom for MA filter in getEnvelope*/ + powerSpectrum_exp = getScaleFactor32( powerSpectrum, nSamples ); + powerSpectrum_exp = sub( powerSpectrum_exp, 3 ); /*extra 3 bits of headroom for MA filter in getEnvelope*/ /* multFLOAT(powerSpectrum, powerSpectrum, powerSpectrum, nSamples); */ - FOR(i = 0; i < nSamples; i++) + FOR( i = 0; i < nSamples; i++ ) { - Word32 const t = L_shl(powerSpectrum[i], powerSpectrum_exp); - powerSpectrum[i] = Mpy_32_32(t, t); + Word32 const t = L_shl( powerSpectrum[i], powerSpectrum_exp ); + powerSpectrum[i] = Mpy_32_32( t, t ); move32(); } - RefineTonalComponents((Word16 *)hTonalMDCTConc->pTCI->indexOfTonalPeak, - (Word16 *)hTonalMDCTConc->pTCI->lowerIndex, - (Word16 *)hTonalMDCTConc->pTCI->upperIndex, - hTonalMDCTConc->pTCI->phaseDiff, - hTonalMDCTConc->pTCI->phase_currentFramePredicted, - (Word16 *)&hTonalMDCTConc->pTCI->numIndexes, - hTonalMDCTConc->lastPitchLag, - pitchLag, - hTonalMDCTConc->lastBlockData.spectralData, - add(hTonalMDCTConc->lastBlockData.spectralData_exp,hTonalMDCTConc->lastBlockData.gain_tcx_exp), - hTonalMDCTConc->lastBlockData.scaleFactors, - hTonalMDCTConc->lastBlockData.scaleFactors_exp, - hTonalMDCTConc->lastBlockData.scaleFactors_max_e, - powerSpectrum, - nSamples, - hTonalMDCTConc->nSamplesCore, - extract_l(Mpy_32_16_1(L_mult0(hTonalMDCTConc->nSamples,hTonalMDCTConc->nSamples),82)), element_mode); /* floorPowerSpectrum */ - + RefineTonalComponents( (Word16 *) hTonalMDCTConc->pTCI->indexOfTonalPeak, + (Word16 *) hTonalMDCTConc->pTCI->lowerIndex, + (Word16 *) hTonalMDCTConc->pTCI->upperIndex, + hTonalMDCTConc->pTCI->phaseDiff, + hTonalMDCTConc->pTCI->phase_currentFramePredicted, + (Word16 *) &hTonalMDCTConc->pTCI->numIndexes, + hTonalMDCTConc->lastPitchLag, + pitchLag, + hTonalMDCTConc->lastBlockData.spectralData, + add( hTonalMDCTConc->lastBlockData.spectralData_exp, hTonalMDCTConc->lastBlockData.gain_tcx_exp ), + hTonalMDCTConc->lastBlockData.scaleFactors, + hTonalMDCTConc->lastBlockData.scaleFactors_exp, + hTonalMDCTConc->lastBlockData.scaleFactors_max_e, + powerSpectrum, + nSamples, + hTonalMDCTConc->nSamplesCore, + extract_l( Mpy_32_16_1( L_mult0( hTonalMDCTConc->nSamples, hTonalMDCTConc->nSamples ), 82 ) ), element_mode ); /* floorPowerSpectrum */ } } } @@ -1390,9 +1390,9 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( tiltFactor = round_fx( BASOP_Util_fPow( L_max( L_tmp, L_deposit_h( tiltCompFactor ) ), 0, L_deposit_h( inv_samples ), inv_exp, &exp ) ); BASOP_SATURATE_WARNING_OFF_EVS /*next op may result in 32768*/ #ifdef BASOP_NOGLOB - tiltFactor = shl_sat( tiltFactor, exp ); + tiltFactor = shl_sat( tiltFactor, exp ); #else - tiltFactor = shl( tiltFactor, exp ); + tiltFactor = shl( tiltFactor, exp ); #endif BASOP_SATURATE_WARNING_ON_EVS tilt = MAX16B; @@ -1540,7 +1540,7 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( Word32 y = concealment_noise[l]; last_block_nrg_correct = L_add( last_block_nrg_correct, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); // exp = 2 * x_exp + ld y = L_negate( Mpy_32_32( y, y ) ); - hTonalMDCTConc->curr_noise_nrg = BASOP_Util_Add_Mant32Exp( hTonalMDCTConc->curr_noise_nrg, hTonalMDCTConc->curr_noise_nrg_exp, y, 2 * concealment_noise_e, &hTonalMDCTConc->curr_noise_nrg_exp); + hTonalMDCTConc->curr_noise_nrg = BASOP_Util_Add_Mant32Exp( hTonalMDCTConc->curr_noise_nrg, hTonalMDCTConc->curr_noise_nrg_exp, y, 2 * concealment_noise_e, &hTonalMDCTConc->curr_noise_nrg_exp ); } } } @@ -1751,353 +1751,350 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( *mdctSpectrum_exp = add( *mdctSpectrum_exp, exp ); } } - ELSE - { - IF( !tonalConcealmentActive ) - { + ELSE{ + IF( !tonalConcealmentActive ){ ld = sub( 14, norm_s( hTonalMDCTConc->lastBlockData.nSamples ) ); - fac = shr( -32768, ld ); - - FOR( i = 0; i < crossOverFreq; i++ ) - { - Word16 x = hTonalMDCTConc->lastBlockData.spectralData[i]; - Word32 y; - rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); /* Q0 */ - y = L_mult( tilt, rnd ); /* 15Q16 */ - - nrgNoiseInLastFrame = L_add( nrgNoiseInLastFrame, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); // Q(31 - x_exp - ld) + Q(15 - x_exp) - 15 = Q(31 - x_exp * 2 - ld) - x = round_fx( y ); /* 15Q16 -> 15Q0 */ - nrgWhiteNoise = L_add( nrgWhiteNoise, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); // Q(31 - (15 - 0) - ld) + Q(0) - 15 = Q(1 - ld) + fac = shr( -32768, ld ); - mdctSpectrum[i] = y; /* 15Q16 */ - move32(); + FOR( i = 0; i < crossOverFreq; i++ ) + { + Word16 x = hTonalMDCTConc->lastBlockData.spectralData[i]; + Word32 y; + rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); /* Q0 */ + y = L_mult( tilt, rnd ); /* 15Q16 */ - tilt = mult_r( tilt, tiltFactor ); /* Q15 */ - } + nrgNoiseInLastFrame = L_add( nrgNoiseInLastFrame, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); // Q(31 - x_exp - ld) + Q(15 - x_exp) - 15 = Q(31 - x_exp * 2 - ld) + x = round_fx( y ); /* 15Q16 -> 15Q0 */ + nrgWhiteNoise = L_add( nrgWhiteNoise, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); // Q(31 - (15 - 0) - ld) + Q(0) - 15 = Q(1 - ld) - IF( nrgNoiseInLastFrame == 0 ) - { - set32_fx( mdctSpectrum, 0, crossOverFreq ); - *mdctSpectrum_exp = SPEC_EXP_DEC; - } - ELSE - { - exp_last = add( ld, shl( hTonalMDCTConc->lastBlockData.spectralData_exp, 1 ) ); - exp_noise = add( ld, 30 ); + mdctSpectrum[i] = y; /* 15Q16 */ + move32(); - IF( nrgWhiteNoise > 0 ) - { - ld = norm_l( nrgNoiseInLastFrame ); - nrgNoiseInLastFrame = L_shl( nrgNoiseInLastFrame, ld ); - exp_last = sub( exp_last, ld ); - ld = norm_l( nrgWhiteNoise ); - nrgWhiteNoise = L_shl( nrgWhiteNoise, ld ); - exp_noise = sub( exp_noise, ld ); + tilt = mult_r( tilt, tiltFactor ); /* Q15 */ + } - exp = sub( exp_last, exp_noise ); + IF( nrgNoiseInLastFrame == 0 ) + { + set32_fx( mdctSpectrum, 0, crossOverFreq ); + *mdctSpectrum_exp = SPEC_EXP_DEC; + } + ELSE + { + exp_last = add( ld, shl( hTonalMDCTConc->lastBlockData.spectralData_exp, 1 ) ); + exp_noise = add( ld, 30 ); - IF( nrgNoiseInLastFrame > nrgWhiteNoise ) - { - nrgNoiseInLastFrame = L_shr( nrgNoiseInLastFrame, 1 ); - exp = add( exp, 1 ); - } - tmp = div_l( nrgNoiseInLastFrame, round_fx( nrgWhiteNoise ) ); - tmp = Sqrt16( tmp, &exp ); - g = mult_r( g, tmp ); // exponent of g = exp + IF( nrgWhiteNoise > 0 ) + { + ld = norm_l( nrgNoiseInLastFrame ); + nrgNoiseInLastFrame = L_shl( nrgNoiseInLastFrame, ld ); + exp_last = sub( exp_last, ld ); + ld = norm_l( nrgWhiteNoise ); + nrgWhiteNoise = L_shl( nrgWhiteNoise, ld ); + exp_noise = sub( exp_noise, ld ); - L_tmp = L_deposit_h( 0 ); - ld = sub( hTonalMDCTConc->lastBlockData.spectralData_exp, 15 ); - exp = sub( ld, exp ); + exp = sub( exp_last, exp_noise ); - IF( exp > 0 ) - { - g = shr( g, exp ); - *mdctSpectrum_exp = hTonalMDCTConc->lastBlockData.spectralData_exp; - } - ELSE - { - crossfadeGain = shl( crossfadeGain, exp ); - *mdctSpectrum_exp = sub( hTonalMDCTConc->lastBlockData.spectralData_exp, exp ); - } - /*make a headroom for mdct_shaping*/ - exp = sub( *mdctSpectrum_exp, SPEC_EXP_DEC ); - /* assert(exp < 0);*/ - IF( exp < 0 ) - { - *mdctSpectrum_exp = SPEC_EXP_DEC; - } - ELSE - { - exp = 0; - } - } - FOR( i = 0; i < crossOverFreq; i++ ) - { - Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[i]; - Word32 const y = mdctSpectrum[i]; + IF( nrgNoiseInLastFrame > nrgWhiteNoise ) + { + nrgNoiseInLastFrame = L_shr( nrgNoiseInLastFrame, 1 ); + exp = add( exp, 1 ); + } + tmp = div_l( nrgNoiseInLastFrame, round_fx( nrgWhiteNoise ) ); + tmp = Sqrt16( tmp, &exp ); + g = mult_r( g, tmp ); // exponent of g = exp - IF( GT_16( g, 0 ) ) - { - L_tmp = Mpy_32_16_1( y, g ); - } + L_tmp = L_deposit_h( 0 ); + ld = sub( hTonalMDCTConc->lastBlockData.spectralData_exp, 15 ); + exp = sub( ld, exp ); - L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); - IF( GT_32( y, 0 ) ) - { - L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); - } - mdctSpectrum[i] = L_shl( L_tmp2, exp ); - move32(); - } + IF( exp > 0 ) + { + g = shr( g, exp ); + *mdctSpectrum_exp = hTonalMDCTConc->lastBlockData.spectralData_exp; } - exp = sub( hTonalMDCTConc->lastBlockData.spectralData_exp, sub( *mdctSpectrum_exp, 16 ) ); - FOR( i = crossOverFreq; i < hTonalMDCTConc->lastBlockData.nSamples; i++ ) + ELSE { - mdctSpectrum[i] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[i] ), exp ); - move32(); + crossfadeGain = shl( crossfadeGain, exp ); + *mdctSpectrum_exp = sub( hTonalMDCTConc->lastBlockData.spectralData_exp, exp ); + } + /*make a headroom for mdct_shaping*/ + exp = sub( *mdctSpectrum_exp, SPEC_EXP_DEC ); + /* assert(exp < 0);*/ + IF( exp < 0 ) + { + *mdctSpectrum_exp = SPEC_EXP_DEC; + } + ELSE + { + exp = 0; } } - ELSE + FOR( i = 0; i < crossOverFreq; i++ ) { - assert( hTonalMDCTConc->pTCI->numIndexes > 0 ); - FOR( l = hTonalMDCTConc->pTCI->lowerIndex[0]; l <= hTonalMDCTConc->pTCI->upperIndex[0]; l++ ) + Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[i]; + Word32 const y = mdctSpectrum[i]; + + IF( GT_16( g, 0 ) ) { - mdctSpectrum[l] = L_deposit_l( 0 ); + L_tmp = Mpy_32_16_1( y, g ); } - ld = sub( 14, norm_s( hTonalMDCTConc->lastBlockData.nSamples ) ); - fac = shr( -32768, ld ); - FOR( l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++ ) + L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); + IF( GT_32( y, 0 ) ) { - Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; - Word32 y; + L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); + } + mdctSpectrum[i] = L_shl( L_tmp2, exp ); + move32(); + } + } + exp = sub( hTonalMDCTConc->lastBlockData.spectralData_exp, sub( *mdctSpectrum_exp, 16 ) ); + FOR( i = crossOverFreq; i < hTonalMDCTConc->lastBlockData.nSamples; i++ ) + { + mdctSpectrum[i] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[i] ), exp ); + move32(); + } +} +ELSE +{ + assert( hTonalMDCTConc->pTCI->numIndexes > 0 ); + FOR( l = hTonalMDCTConc->pTCI->lowerIndex[0]; l <= hTonalMDCTConc->pTCI->upperIndex[0]; l++ ) + { + mdctSpectrum[l] = L_deposit_l( 0 ); + } - rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); - y = L_mult( tilt, rnd ); // 15Q16 + ld = sub( 14, norm_s( hTonalMDCTConc->lastBlockData.nSamples ) ); + fac = shr( -32768, ld ); + FOR( l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++ ) + { + Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word32 y; - nrgNoiseInLastFrame = L_add( nrgNoiseInLastFrame, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); // Q(31 - x_exp - ld) + Q(15 - x_exp) - 15 = Q(31 - x_exp * 2 - ld) - x = round_fx( y ); // 15Q16 -> Q15 - nrgWhiteNoise = L_add( nrgWhiteNoise, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); // Q(31 - (15 - 0) - ld) + Q(0) - 15 = Q(1 - ld) + rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); + y = L_mult( tilt, rnd ); // 15Q16 - mdctSpectrum[l] = y; /* 15Q16 L_deposit_l(y);*/ - move32(); + nrgNoiseInLastFrame = L_add( nrgNoiseInLastFrame, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); // Q(31 - x_exp - ld) + Q(15 - x_exp) - 15 = Q(31 - x_exp * 2 - ld) + x = round_fx( y ); // 15Q16 -> Q15 + nrgWhiteNoise = L_add( nrgWhiteNoise, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); // Q(31 - (15 - 0) - ld) + Q(0) - 15 = Q(1 - ld) - tilt = mult_r( tilt, tiltFactor ); /* Q15 */ - } + mdctSpectrum[l] = y; /* 15Q16 L_deposit_l(y);*/ + move32(); - FOR( i = 1; i < hTonalMDCTConc->pTCI->numIndexes; i++ ) - { - tmp = round_fx( BASOP_Util_fPow( L_deposit_h( tiltFactor ), 0, L_deposit_h( hTonalMDCTConc->pTCI->upperIndex[i - 1] - hTonalMDCTConc->pTCI->lowerIndex[i - 1] + 1 ), 15, &exp ) ); - tmp = shl( tmp, exp ); - tilt = mult_r( tilt, tmp ); // Q15 + tilt = mult_r( tilt, tiltFactor ); /* Q15 */ + } - FOR( l = hTonalMDCTConc->pTCI->lowerIndex[i]; l <= hTonalMDCTConc->pTCI->upperIndex[i]; l++ ) - { - mdctSpectrum[l] = L_deposit_l( 0 ); - } - FOR( l = hTonalMDCTConc->pTCI->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++ ) - { - Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; - Word32 y; + FOR( i = 1; i < hTonalMDCTConc->pTCI->numIndexes; i++ ) + { + tmp = round_fx( BASOP_Util_fPow( L_deposit_h( tiltFactor ), 0, L_deposit_h( hTonalMDCTConc->pTCI->upperIndex[i - 1] - hTonalMDCTConc->pTCI->lowerIndex[i - 1] + 1 ), 15, &exp ) ); + tmp = shl( tmp, exp ); + tilt = mult_r( tilt, tmp ); // Q15 - rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); - y = L_mult( tilt, rnd ); + FOR( l = hTonalMDCTConc->pTCI->lowerIndex[i]; l <= hTonalMDCTConc->pTCI->upperIndex[i]; l++ ) + { + mdctSpectrum[l] = L_deposit_l( 0 ); + } + FOR( l = hTonalMDCTConc->pTCI->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++ ) + { + Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word32 y; - nrgNoiseInLastFrame = L_add( nrgNoiseInLastFrame, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); // Q(31 - hTonalMDCTConc->lastBlockData.spectralData_exp * 2 - ld) - x = round_fx( y ); // Q15 - nrgWhiteNoise = L_add( nrgWhiteNoise, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); // Q(1 - ld) + rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); + y = L_mult( tilt, rnd ); - mdctSpectrum[l] = y; /* 15Q16 L_deposit_l(y);*/ - move32(); + nrgNoiseInLastFrame = L_add( nrgNoiseInLastFrame, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); // Q(31 - hTonalMDCTConc->lastBlockData.spectralData_exp * 2 - ld) + x = round_fx( y ); // Q15 + nrgWhiteNoise = L_add( nrgWhiteNoise, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); // Q(1 - ld) - tilt = mult_r( tilt, tiltFactor ); // Q15 - } - } + mdctSpectrum[l] = y; /* 15Q16 L_deposit_l(y);*/ + move32(); - tmp = round_fx( BASOP_Util_fPow( L_deposit_h( tiltFactor ), 0, - L_deposit_h( hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1] - hTonalMDCTConc->pTCI->lowerIndex[hTonalMDCTConc->pTCI->numIndexes - 1] + 1 ), 15, &exp ) ); - BASOP_SATURATE_WARNING_OFF_EVS /*next op may result in 32768*/ + tilt = mult_r( tilt, tiltFactor ); // Q15 + } + } + + tmp = round_fx( BASOP_Util_fPow( L_deposit_h( tiltFactor ), 0, + L_deposit_h( hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1] - hTonalMDCTConc->pTCI->lowerIndex[hTonalMDCTConc->pTCI->numIndexes - 1] + 1 ), 15, &exp ) ); + BASOP_SATURATE_WARNING_OFF_EVS /*next op may result in 32768*/ #ifdef BASOP_NOGLOB - tmp = shl_sat( tmp, exp ); + tmp = shl_sat( tmp, exp ); #else - tmp = shl( tmp, exp ); + tmp = shl( tmp, exp ); #endif - BASOP_SATURATE_WARNING_ON_EVS - tilt = mult_r( tilt, tmp ); - - FOR( l = add( hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1], 1 ); l < crossOverFreq; l++ ) - { - Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; - Word32 y; - rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); - y = L_mult( tilt, rnd ); + BASOP_SATURATE_WARNING_ON_EVS + tilt = mult_r( tilt, tmp ); - nrgNoiseInLastFrame = L_add( nrgNoiseInLastFrame, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); - x = round_fx( y ); - nrgWhiteNoise = L_add( nrgWhiteNoise, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); + FOR( l = add( hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1], 1 ); l < crossOverFreq; l++ ) + { + Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word32 y; + rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); + y = L_mult( tilt, rnd ); - mdctSpectrum[l] = y; /* 15Q16 L_deposit_l(y);*/ - move32(); + nrgNoiseInLastFrame = L_add( nrgNoiseInLastFrame, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); + x = round_fx( y ); + nrgWhiteNoise = L_add( nrgWhiteNoise, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); - tilt = mult_r( tilt, tiltFactor ); - } + mdctSpectrum[l] = y; /* 15Q16 L_deposit_l(y);*/ + move32(); - IF( EQ_32( nrgNoiseInLastFrame, 0 ) ) - { - set32_fx( mdctSpectrum, 0, crossOverFreq ); - *mdctSpectrum_exp = SPEC_EXP_DEC; - } - ELSE - { - exp_last = add( ld, shl( hTonalMDCTConc->lastBlockData.spectralData_exp, 1 ) ); - exp_noise = add( ld, shl( 15, 1 ) ); + tilt = mult_r( tilt, tiltFactor ); + } - ld = norm_l( nrgNoiseInLastFrame ); - nrgNoiseInLastFrame = L_shl( nrgNoiseInLastFrame, ld ); - exp_last = sub( exp_last, ld ); - ld = norm_l( nrgWhiteNoise ); - nrgWhiteNoise = L_shl( nrgWhiteNoise, ld ); - exp_noise = sub( exp_noise, ld ); - - exp = sub( exp_last, exp_noise ); + IF( EQ_32( nrgNoiseInLastFrame, 0 ) ) + { + set32_fx( mdctSpectrum, 0, crossOverFreq ); + *mdctSpectrum_exp = SPEC_EXP_DEC; + } + ELSE + { + exp_last = add( ld, shl( hTonalMDCTConc->lastBlockData.spectralData_exp, 1 ) ); + exp_noise = add( ld, shl( 15, 1 ) ); - IF( nrgNoiseInLastFrame > nrgWhiteNoise ) - { - nrgNoiseInLastFrame = L_shr( nrgNoiseInLastFrame, 1 ); - exp = add( exp, 1 ); - } - tmp = div_l( nrgNoiseInLastFrame, extract_h( nrgWhiteNoise ) ); - tmp = Sqrt16( tmp, &exp ); - g = mult_r( g, tmp ); + ld = norm_l( nrgNoiseInLastFrame ); + nrgNoiseInLastFrame = L_shl( nrgNoiseInLastFrame, ld ); + exp_last = sub( exp_last, ld ); + ld = norm_l( nrgWhiteNoise ); + nrgWhiteNoise = L_shl( nrgWhiteNoise, ld ); + exp_noise = sub( exp_noise, ld ); - L_tmp = L_deposit_h( 0 ); - ld = sub( hTonalMDCTConc->lastBlockData.spectralData_exp, 15 ); - exp = sub( ld, exp ); - IF( exp > 0 ) - { - g = shr( g, exp ); - *mdctSpectrum_exp = hTonalMDCTConc->lastBlockData.spectralData_exp; - } - ELSE - { - crossfadeGain = shl( crossfadeGain, exp ); - *mdctSpectrum_exp = sub( hTonalMDCTConc->lastBlockData.spectralData_exp, exp ); - } - /*make a headroom for mdct_shaping*/ - exp = sub( *mdctSpectrum_exp, SPEC_EXP_DEC ); + exp = sub( exp_last, exp_noise ); - IF( exp < 0 ) - { - *mdctSpectrum_exp = SPEC_EXP_DEC; - } - ELSE - { - exp = 0; - } + IF( nrgNoiseInLastFrame > nrgWhiteNoise ) + { + nrgNoiseInLastFrame = L_shr( nrgNoiseInLastFrame, 1 ); + exp = add( exp, 1 ); + } + tmp = div_l( nrgNoiseInLastFrame, extract_h( nrgWhiteNoise ) ); + tmp = Sqrt16( tmp, &exp ); + g = mult_r( g, tmp ); + + L_tmp = L_deposit_h( 0 ); + ld = sub( hTonalMDCTConc->lastBlockData.spectralData_exp, 15 ); + exp = sub( ld, exp ); + IF( exp > 0 ) + { + g = shr( g, exp ); + *mdctSpectrum_exp = hTonalMDCTConc->lastBlockData.spectralData_exp; + } + ELSE + { + crossfadeGain = shl( crossfadeGain, exp ); + *mdctSpectrum_exp = sub( hTonalMDCTConc->lastBlockData.spectralData_exp, exp ); + } + /*make a headroom for mdct_shaping*/ + exp = sub( *mdctSpectrum_exp, SPEC_EXP_DEC ); - FOR( l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++ ) - { - Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; - Word32 const y = mdctSpectrum[l]; + IF( exp < 0 ) + { + *mdctSpectrum_exp = SPEC_EXP_DEC; + } + ELSE + { + exp = 0; + } - IF( GT_16( g, 0 ) ) - { - L_tmp = Mpy_32_16_1( y, g ); - } + FOR( l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++ ) + { + Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word32 const y = mdctSpectrum[l]; - L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); - IF( GT_32( y, 0 ) ) - { - L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); - } - mdctSpectrum[l] = L_shl( L_tmp2, exp ); - move32(); - } + IF( GT_16( g, 0 ) ) + { + L_tmp = Mpy_32_16_1( y, g ); + } - FOR( i = 1; i < hTonalMDCTConc->pTCI->numIndexes; i++ ) - { - FOR( l = hTonalMDCTConc->pTCI->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++ ) - { - Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; - Word32 const y = mdctSpectrum[l]; + L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); + IF( GT_32( y, 0 ) ) + { + L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); + } + mdctSpectrum[l] = L_shl( L_tmp2, exp ); + move32(); + } - IF( GT_16( g, 0 ) ) - { - L_tmp = Mpy_32_16_1( y, g ); - } + FOR( i = 1; i < hTonalMDCTConc->pTCI->numIndexes; i++ ) + { + FOR( l = hTonalMDCTConc->pTCI->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++ ) + { + Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word32 const y = mdctSpectrum[l]; - L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); - IF( GT_32( y, 0 ) ) - { - L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); - } - mdctSpectrum[l] = L_shl( L_tmp2, exp ); - move32(); - } + IF( GT_16( g, 0 ) ) + { + L_tmp = Mpy_32_16_1( y, g ); } - /* initialize bins of tonal components with zero: basically not - necessary, but currently the whole spectrum is rescaled in - mdct_noiseShaping() and then there would be a processing of - uninitialized values */ - FOR( i = 0; i < hTonalMDCTConc->pTCI->numIndexes; i++ ) + L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); + IF( GT_32( y, 0 ) ) { - FOR( l = hTonalMDCTConc->pTCI->lowerIndex[i]; l <= hTonalMDCTConc->pTCI->upperIndex[i]; l++ ) - { - mdctSpectrum[l] = L_deposit_l( 0 ); - } + L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); } + mdctSpectrum[l] = L_shl( L_tmp2, exp ); + move32(); + } + } - FOR( l = add( hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1], 1 ); l < crossOverFreq; l++ ) - { - Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; - Word32 const y = mdctSpectrum[l]; + /* initialize bins of tonal components with zero: basically not + necessary, but currently the whole spectrum is rescaled in + mdct_noiseShaping() and then there would be a processing of + uninitialized values */ + FOR( i = 0; i < hTonalMDCTConc->pTCI->numIndexes; i++ ) + { + FOR( l = hTonalMDCTConc->pTCI->lowerIndex[i]; l <= hTonalMDCTConc->pTCI->upperIndex[i]; l++ ) + { + mdctSpectrum[l] = L_deposit_l( 0 ); + } + } - IF( GT_16( g, 0 ) ) - { - L_tmp = Mpy_32_16_1( y, g ); - } + FOR( l = add( hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1], 1 ); l < crossOverFreq; l++ ) + { + Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word32 const y = mdctSpectrum[l]; - L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); - IF( GT_32( y, 0 ) ) - { - L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); - } - mdctSpectrum[l] = L_shl( L_tmp2, exp ); - move32(); - } + IF( GT_16( g, 0 ) ) + { + L_tmp = Mpy_32_16_1( y, g ); } - exp = sub( hTonalMDCTConc->lastBlockData.spectralData_exp, sub( *mdctSpectrum_exp, 16 ) ); - FOR( l = crossOverFreq; l < hTonalMDCTConc->lastBlockData.nSamples; l++ ) + + L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); + IF( GT_32( y, 0 ) ) { - mdctSpectrum[l] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), exp ); - move32(); + L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); } + mdctSpectrum[l] = L_shl( L_tmp2, exp ); + move32(); } } + exp = sub( hTonalMDCTConc->lastBlockData.spectralData_exp, sub( *mdctSpectrum_exp, 16 ) ); + FOR( l = crossOverFreq; l < hTonalMDCTConc->lastBlockData.nSamples; l++ ) + { + mdctSpectrum[l] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), exp ); + move32(); + } +} +} - *pSeed = rnd; +*pSeed = rnd; - pop_wmops(); +pop_wmops(); - return; +return; } -void TonalMDCTConceal_InsertNoise( - const TonalMDCTConcealPtr hTonalMDCTConc, /*IN */ - Word32* mdctSpectrum, /*OUT*/ - Word16* mdctSpectrum_exp, /*OUT*/ - const Word16 tonalConcealmentActive, - Word16* pSeed, /*IN/OUT*/ - const Word16 tiltCompFactor, - Word16 crossfadeGain, +void TonalMDCTConceal_InsertNoise( + const TonalMDCTConcealPtr hTonalMDCTConc, /*IN */ + Word32 *mdctSpectrum, /*OUT*/ + Word16 *mdctSpectrum_exp, /*OUT*/ + const Word16 tonalConcealmentActive, + Word16 *pSeed, /*IN/OUT*/ + const Word16 tiltCompFactor, + Word16 crossfadeGain, #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT const Word16concealment_noise[L_FRAME48k], const float cngLevelBackgroundTrace_bfi, #endif - const Word16 crossOverFreq -) + const Word16 crossOverFreq ) { Word16 i, ld, fac; Word16 rnd, exp, exp_last, exp_noise, inv_samples, inv_exp; @@ -2107,11 +2104,11 @@ void TonalMDCTConceal_InsertNoise( float last_block_nrg_correct; #endif - g = sub(32767/*1.0f Q15*/,crossfadeGain); + g = sub( 32767 /*1.0f Q15*/, crossfadeGain ); rnd = 1977; move16(); - if (hTonalMDCTConc->lastBlockData.blockIsConcealed) + if ( hTonalMDCTConc->lastBlockData.blockIsConcealed ) { rnd = *pSeed; move16(); @@ -2119,30 +2116,30 @@ void TonalMDCTConceal_InsertNoise( #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT /* based on what is done in tcx_noise_filling() */ /* always initialize these to avoid compiler warnings */ - tiltFactor = (float)pow(max(0.375f, tiltCompFactor), 1.0f / hTonalMDCTConc->lastBlockData.nSamples); + tiltFactor = (float) pow( max( 0.375f, tiltCompFactor ), 1.0f / hTonalMDCTConc->lastBlockData.nSamples ); tilt = 1.0f; nrgNoiseInLastFrame = 0.0f; nrgWhiteNoise = 0.0f; hTonalMDCTConc->faded_signal_nrg_flt = 0.0f; last_block_nrg_correct = 0.0f; #endif - IF (hTonalMDCTConc->lastBlockData.blockIsValid == 0) + IF( hTonalMDCTConc->lastBlockData.blockIsValid == 0 ) { /* may just become active if the very first frame is lost */ - set32_fx(mdctSpectrum, 0, hTonalMDCTConc->nSamples); + set32_fx( mdctSpectrum, 0, hTonalMDCTConc->nSamples ); *mdctSpectrum_exp = SPEC_EXP_DEC; } #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - else if (concealment_noise != NULL) + else if ( concealment_noise != NULL ) { - if (!tonalConcealmentActive) + if ( !tonalConcealmentActive ) { /* if fadeout has not started yet, only apply sign scrambling */ - if (crossfadeGain == 1.0f) + if ( crossfadeGain == 1.0f ) { - for (i = 0; i < crossOverFreq; i++) + for ( i = 0; i < crossOverFreq; i++ ) { - if (concealment_noise[i] > 0) + if ( concealment_noise[i] > 0 ) { mdctSpectrum[i] = hTonalMDCTConc->lastBlockData.spectralData[i]; } @@ -2152,7 +2149,7 @@ void TonalMDCTConceal_InsertNoise( } } - for (l = crossOverFreq; l < hTonalMDCTConc->lastBlockData.nSamples; l++) + for ( l = crossOverFreq; l < hTonalMDCTConc->lastBlockData.nSamples; l++ ) { mdctSpectrum[l] = hTonalMDCTConc->lastBlockData.spectralData[l]; } @@ -2160,14 +2157,14 @@ void TonalMDCTConceal_InsertNoise( /* actual fadeout is done in this case */ else { - g *= (float)sqrt(cngLevelBackgroundTrace_bfi / hTonalMDCTConc->curr_noise_nrg_flt); + g *= (float) sqrt( cngLevelBackgroundTrace_bfi / hTonalMDCTConc->curr_noise_nrg_flt ); - for (i = 0; i < crossOverFreq; i++) + for ( i = 0; i < crossOverFreq; i++ ) { x = hTonalMDCTConc->lastBlockData.spectralData[i]; y = concealment_noise[i]; - if (y > 0) + if ( y > 0 ) { mdctSpectrum[i] = g * y + crossfadeGain * x; } @@ -2178,7 +2175,7 @@ void TonalMDCTConceal_InsertNoise( hTonalMDCTConc->faded_signal_nrg_flt += mdctSpectrum[i] * mdctSpectrum[i]; } - for (l = crossOverFreq; l < hTonalMDCTConc->lastBlockData.nSamples; l++) + for ( l = crossOverFreq; l < hTonalMDCTConc->lastBlockData.nSamples; l++ ) { mdctSpectrum[l] = 0.0f; } @@ -2186,18 +2183,18 @@ void TonalMDCTConceal_InsertNoise( } else { - assert(hTonalMDCTConc->pTCI->numIndexes > 0); + assert( hTonalMDCTConc->pTCI->numIndexes > 0 ); /* initialize bins of tonal components with zero: basically not necessary, but currently the whole spectrum is rescaled in mdct_noiseShaping() and then there would be a processing of uninitialized values */ - for (i = 0; i < hTonalMDCTConc->pTCI->numIndexes; i++) + for ( i = 0; i < hTonalMDCTConc->pTCI->numIndexes; i++ ) { - for (l = hTonalMDCTConc->pTCI->lowerIndex[i]; l <= hTonalMDCTConc->pTCI->upperIndex[i]; l++) + for ( l = hTonalMDCTConc->pTCI->lowerIndex[i]; l <= hTonalMDCTConc->pTCI->upperIndex[i]; l++ ) { mdctSpectrum[l] = 0; - if (l < crossOverFreq) + if ( l < crossOverFreq ) { last_block_nrg_correct += hTonalMDCTConc->lastBlockData.spectralData[l] * hTonalMDCTConc->lastBlockData.spectralData[l]; hTonalMDCTConc->curr_noise_nrg_flt -= concealment_noise[l] * concealment_noise[l]; @@ -2206,11 +2203,11 @@ void TonalMDCTConceal_InsertNoise( } /* if fadeout has not started yet, only apply sign scrambling */ - if (crossfadeGain == 1.0f) + if ( crossfadeGain == 1.0f ) { - for (l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++) + for ( l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++ ) { - if (concealment_noise[l] > 0) + if ( concealment_noise[l] > 0 ) { mdctSpectrum[l] = hTonalMDCTConc->lastBlockData.spectralData[l]; } @@ -2219,11 +2216,11 @@ void TonalMDCTConceal_InsertNoise( mdctSpectrum[l] = -hTonalMDCTConc->lastBlockData.spectralData[l]; } } - for (i = 1; i < hTonalMDCTConc->pTCI->numIndexes; i++) + for ( i = 1; i < hTonalMDCTConc->pTCI->numIndexes; i++ ) { - for (l = hTonalMDCTConc->pTCI->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++) + for ( l = hTonalMDCTConc->pTCI->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++ ) { - if (concealment_noise[l] > 0) + if ( concealment_noise[l] > 0 ) { mdctSpectrum[l] = hTonalMDCTConc->lastBlockData.spectralData[l]; } @@ -2234,9 +2231,9 @@ void TonalMDCTConceal_InsertNoise( } } - for (l = hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1] + 1; l < crossOverFreq; l++) + for ( l = hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1] + 1; l < crossOverFreq; l++ ) { - if (concealment_noise[l] > 0) + if ( concealment_noise[l] > 0 ) { mdctSpectrum[l] = hTonalMDCTConc->lastBlockData.spectralData[l]; } @@ -2246,7 +2243,7 @@ void TonalMDCTConceal_InsertNoise( } } - for (l = crossOverFreq; l < hTonalMDCTConc->lastBlockData.nSamples; l++) + for ( l = crossOverFreq; l < hTonalMDCTConc->lastBlockData.nSamples; l++ ) { mdctSpectrum[l] = hTonalMDCTConc->lastBlockData.spectralData[l]; } @@ -2254,14 +2251,14 @@ void TonalMDCTConceal_InsertNoise( /* actual fadeout is done in this case */ else { - g *= (float)sqrt(cngLevelBackgroundTrace_bfi / hTonalMDCTConc->curr_noise_nrg_flt); + g *= (float) sqrt( cngLevelBackgroundTrace_bfi / hTonalMDCTConc->curr_noise_nrg_flt ); - for (l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++) + for ( l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++ ) { x = hTonalMDCTConc->lastBlockData.spectralData[l]; y = concealment_noise[l]; - if (y > 0) + if ( y > 0 ) { mdctSpectrum[l] = g * y + crossfadeGain * x; } @@ -2271,14 +2268,14 @@ void TonalMDCTConceal_InsertNoise( } hTonalMDCTConc->faded_signal_nrg_flt += mdctSpectrum[l] * mdctSpectrum[l]; } - for (i = 1; i < hTonalMDCTConc->pTCI->numIndexes; i++) + for ( i = 1; i < hTonalMDCTConc->pTCI->numIndexes; i++ ) { - for (l = hTonalMDCTConc->pTCI->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++) + for ( l = hTonalMDCTConc->pTCI->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++ ) { x = hTonalMDCTConc->lastBlockData.spectralData[l]; y = concealment_noise[l]; - if (y > 0) + if ( y > 0 ) { mdctSpectrum[l] = g * y + crossfadeGain * x; } @@ -2290,12 +2287,12 @@ void TonalMDCTConceal_InsertNoise( } } - for (l = hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1] + 1; l < crossOverFreq; l++) + for ( l = hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1] + 1; l < crossOverFreq; l++ ) { x = hTonalMDCTConc->lastBlockData.spectralData[l]; y = concealment_noise[l]; - if (y > 0) + if ( y > 0 ) { mdctSpectrum[l] = g * y + crossfadeGain * x; } @@ -2306,116 +2303,117 @@ void TonalMDCTConceal_InsertNoise( hTonalMDCTConc->faded_signal_nrg_flt += mdctSpectrum[l] * mdctSpectrum[l]; } - for (l = crossOverFreq; l < hTonalMDCTConc->lastBlockData.nSamples; l++) + for ( l = crossOverFreq; l < hTonalMDCTConc->lastBlockData.nSamples; l++ ) { mdctSpectrum[l] = 0.0f; } } } - if (hTonalMDCTConc->faded_signal_nrg_flt > 0.0f && hTonalMDCTConc->curr_noise_nrg_flt > MDCT_ST_PLC_FADEOUT_MIN_NOISE_NRG) + if ( hTonalMDCTConc->faded_signal_nrg_flt > 0.0f && hTonalMDCTConc->curr_noise_nrg_flt > MDCT_ST_PLC_FADEOUT_MIN_NOISE_NRG ) { float nrg_corr_factor; - nrg_corr_factor = sqrtf((hTonalMDCTConc->last_block_nrg_flt - last_block_nrg_correct) / hTonalMDCTConc->faded_signal_nrg_flt); - v_multc(mdctSpectrum, nrg_corr_factor, mdctSpectrum, crossOverFreq); + nrg_corr_factor = sqrtf( ( hTonalMDCTConc->last_block_nrg_flt - last_block_nrg_correct ) / hTonalMDCTConc->faded_signal_nrg_flt ); + v_multc( mdctSpectrum, nrg_corr_factor, mdctSpectrum, crossOverFreq ); } } #endif ELSE { #ifndef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - L_tmp = 805306368l/*0.375f Q31*/; + L_tmp = 805306368l /*0.375f Q31*/; inv_exp = 15; move16(); - inv_samples = Inv16(hTonalMDCTConc->lastBlockData.nSamples, &inv_exp); - tiltFactor = round_fx(BASOP_Util_fPow(L_max(L_tmp, L_deposit_h(tiltCompFactor)), 0, L_deposit_h(inv_samples),inv_exp, &exp)); + inv_samples = Inv16( hTonalMDCTConc->lastBlockData.nSamples, &inv_exp ); + tiltFactor = round_fx( BASOP_Util_fPow( L_max( L_tmp, L_deposit_h( tiltCompFactor ) ), 0, L_deposit_h( inv_samples ), inv_exp, &exp ) ); BASOP_SATURATE_WARNING_OFF_EVS /*next op may result in 32768*/ #ifdef BASOP_NOGLOB - tiltFactor = shl_sat( tiltFactor, exp ); + tiltFactor = shl_sat( tiltFactor, exp ); #else - tiltFactor = shl(tiltFactor, exp); + tiltFactor = shl( tiltFactor, exp ); #endif BASOP_SATURATE_WARNING_ON_EVS - tilt = 32767/*1.0f Q15*/; + tilt = 32767 /*1.0f Q15*/; move16(); - nrgNoiseInLastFrame = L_deposit_h(0); - nrgWhiteNoise = L_deposit_h(0); + nrgNoiseInLastFrame = L_deposit_h( 0 ); + nrgWhiteNoise = L_deposit_h( 0 ); exp_last = exp_noise = 0; #endif move16(); move16(); - IF (!tonalConcealmentActive) + IF( !tonalConcealmentActive ) { - ld = sub(14,norm_s(hTonalMDCTConc->lastBlockData.nSamples)); - fac = shr(-32768,ld); + ld = sub( 14, norm_s( hTonalMDCTConc->lastBlockData.nSamples ) ); + fac = shr( -32768, ld ); - FOR (i = 0; i < crossOverFreq; i++) + FOR( i = 0; i < crossOverFreq; i++ ) { Word16 x = hTonalMDCTConc->lastBlockData.spectralData[i]; Word32 y; - rnd = extract_l(L_mac0(13849, rnd, 31821)); - y = L_mult(tilt,rnd); + rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); + y = L_mult( tilt, rnd ); - nrgNoiseInLastFrame = L_add(nrgNoiseInLastFrame, Mpy_32_16_1(L_msu(0, x,fac),x)); - x = round_fx(y); - nrgWhiteNoise = L_add(nrgWhiteNoise, Mpy_32_16_1(L_msu(0, x,fac),x)); + nrgNoiseInLastFrame = L_add( nrgNoiseInLastFrame, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); + x = round_fx( y ); + nrgWhiteNoise = L_add( nrgWhiteNoise, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); - mdctSpectrum[i] = y; /* 15Q16 */ move32(); + mdctSpectrum[i] = y; /* 15Q16 */ + move32(); - tilt = mult_r(tilt,tiltFactor); + tilt = mult_r( tilt, tiltFactor ); } - IF (nrgNoiseInLastFrame == 0) + IF( nrgNoiseInLastFrame == 0 ) { - set32_fx(mdctSpectrum, 0, crossOverFreq); + set32_fx( mdctSpectrum, 0, crossOverFreq ); *mdctSpectrum_exp = SPEC_EXP_DEC; } ELSE { - exp_last = add(ld,shl(hTonalMDCTConc->lastBlockData.spectralData_exp,1)); - exp_noise = add(ld,30); + exp_last = add( ld, shl( hTonalMDCTConc->lastBlockData.spectralData_exp, 1 ) ); + exp_noise = add( ld, 30 ); - IF (nrgWhiteNoise > 0) + IF( nrgWhiteNoise > 0 ) { - ld = norm_l(nrgNoiseInLastFrame); - nrgNoiseInLastFrame = L_shl(nrgNoiseInLastFrame,ld); - exp_last = sub(exp_last,ld); - ld = norm_l(nrgWhiteNoise); - nrgWhiteNoise = L_shl(nrgWhiteNoise,ld); - exp_noise = sub(exp_noise,ld); + ld = norm_l( nrgNoiseInLastFrame ); + nrgNoiseInLastFrame = L_shl( nrgNoiseInLastFrame, ld ); + exp_last = sub( exp_last, ld ); + ld = norm_l( nrgWhiteNoise ); + nrgWhiteNoise = L_shl( nrgWhiteNoise, ld ); + exp_noise = sub( exp_noise, ld ); - exp = sub(exp_last, exp_noise); + exp = sub( exp_last, exp_noise ); - IF(nrgNoiseInLastFrame > nrgWhiteNoise) + IF( nrgNoiseInLastFrame > nrgWhiteNoise ) { - nrgNoiseInLastFrame = L_shr(nrgNoiseInLastFrame,1); - exp = add(exp,1); + nrgNoiseInLastFrame = L_shr( nrgNoiseInLastFrame, 1 ); + exp = add( exp, 1 ); } - tmp = div_l(nrgNoiseInLastFrame,round_fx(nrgWhiteNoise)); - tmp = Sqrt16(tmp, &exp); - g = mult_r(g,tmp); + tmp = div_l( nrgNoiseInLastFrame, round_fx( nrgWhiteNoise ) ); + tmp = Sqrt16( tmp, &exp ); + g = mult_r( g, tmp ); - L_tmp = L_deposit_h(0); - ld = sub(hTonalMDCTConc->lastBlockData.spectralData_exp, 15); - exp = sub(ld, exp); + L_tmp = L_deposit_h( 0 ); + ld = sub( hTonalMDCTConc->lastBlockData.spectralData_exp, 15 ); + exp = sub( ld, exp ); - IF(exp > 0) + IF( exp > 0 ) { - g = shr(g,exp); + g = shr( g, exp ); *mdctSpectrum_exp = hTonalMDCTConc->lastBlockData.spectralData_exp; } ELSE { - crossfadeGain = shl(crossfadeGain,exp); - *mdctSpectrum_exp = sub(hTonalMDCTConc->lastBlockData.spectralData_exp,exp); + crossfadeGain = shl( crossfadeGain, exp ); + *mdctSpectrum_exp = sub( hTonalMDCTConc->lastBlockData.spectralData_exp, exp ); } /*make a headroom for mdct_shaping*/ - exp = sub(*mdctSpectrum_exp, SPEC_EXP_DEC); + exp = sub( *mdctSpectrum_exp, SPEC_EXP_DEC ); /* assert(exp < 0);*/ - IF(exp < 0) + IF( exp < 0 ) { *mdctSpectrum_exp = SPEC_EXP_DEC; } @@ -2425,161 +2423,164 @@ void TonalMDCTConceal_InsertNoise( } } - FOR (i = 0; i < crossOverFreq; i++) + FOR( i = 0; i < crossOverFreq; i++ ) { Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[i]; Word32 const y = mdctSpectrum[i]; - if(g > 0) + if ( g > 0 ) { - L_tmp = Mpy_32_16_1(y,g); + L_tmp = Mpy_32_16_1( y, g ); } - L_tmp2 = L_msu(L_tmp,crossfadeGain,x); - if(y > 0) + L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); + if ( y > 0 ) { - L_tmp2 = L_mac(L_tmp,crossfadeGain,x); + L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); } - mdctSpectrum[i] = L_shl(L_tmp2, exp); + mdctSpectrum[i] = L_shl( L_tmp2, exp ); move32(); } } - exp = sub(hTonalMDCTConc->lastBlockData.spectralData_exp, sub(*mdctSpectrum_exp,16)); - FOR (i = crossOverFreq; i < hTonalMDCTConc->lastBlockData.nSamples; i++) + exp = sub( hTonalMDCTConc->lastBlockData.spectralData_exp, sub( *mdctSpectrum_exp, 16 ) ); + FOR( i = crossOverFreq; i < hTonalMDCTConc->lastBlockData.nSamples; i++ ) { - mdctSpectrum[i] = L_shl(L_deposit_l(hTonalMDCTConc->lastBlockData.spectralData[i]), exp); + mdctSpectrum[i] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[i] ), exp ); move32(); } } ELSE { Word16 l; - assert(hTonalMDCTConc->pTCI->numIndexes > 0); + assert( hTonalMDCTConc->pTCI->numIndexes > 0 ); - FOR (l = hTonalMDCTConc->pTCI->lowerIndex[0]; l <= hTonalMDCTConc->pTCI->upperIndex[0]; l++) + FOR( l = hTonalMDCTConc->pTCI->lowerIndex[0]; l <= hTonalMDCTConc->pTCI->upperIndex[0]; l++ ) { - mdctSpectrum[l] = L_deposit_l(0); + mdctSpectrum[l] = L_deposit_l( 0 ); } - ld = sub(14,norm_s(hTonalMDCTConc->lastBlockData.nSamples)); - fac = shr(-32768,ld); - FOR (l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++) + ld = sub( 14, norm_s( hTonalMDCTConc->lastBlockData.nSamples ) ); + fac = shr( -32768, ld ); + FOR( l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++ ) { Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; Word32 y; - rnd = extract_l(L_mac0(13849, rnd, 31821)); - y = L_mult(tilt,rnd); + rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); + y = L_mult( tilt, rnd ); - nrgNoiseInLastFrame = L_add(nrgNoiseInLastFrame, Mpy_32_16_1(L_msu(0, x,fac),x)); - x = round_fx(y); - nrgWhiteNoise = L_add(nrgWhiteNoise, Mpy_32_16_1(L_msu(0, x,fac),x)); + nrgNoiseInLastFrame = L_add( nrgNoiseInLastFrame, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); + x = round_fx( y ); + nrgWhiteNoise = L_add( nrgWhiteNoise, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); - mdctSpectrum[l] = y; /* 15Q16 L_deposit_l(y);*/ move32(); + mdctSpectrum[l] = y; /* 15Q16 L_deposit_l(y);*/ + move32(); - tilt = mult_r(tilt,tiltFactor); + tilt = mult_r( tilt, tiltFactor ); } - FOR (i = 1; i < hTonalMDCTConc->pTCI->numIndexes; i++) + FOR( i = 1; i < hTonalMDCTConc->pTCI->numIndexes; i++ ) { /*tilt *= (float)pow(tiltFactor, hTonalMDCTConc->pTCI->upperIndex[i-1]-hTonalMDCTConc->pTCI->lowerIndex[i-1]+1);*/ - tmp= round_fx(BASOP_Util_fPow(L_deposit_h(tiltFactor), 0, L_deposit_h(hTonalMDCTConc->pTCI->upperIndex[i-1]-hTonalMDCTConc->pTCI->lowerIndex[i-1]+1),15, &exp)); - tmp = shl(tmp, exp); - tilt = mult_r(tilt,tmp); + tmp = round_fx( BASOP_Util_fPow( L_deposit_h( tiltFactor ), 0, L_deposit_h( hTonalMDCTConc->pTCI->upperIndex[i - 1] - hTonalMDCTConc->pTCI->lowerIndex[i - 1] + 1 ), 15, &exp ) ); + tmp = shl( tmp, exp ); + tilt = mult_r( tilt, tmp ); - FOR (l = hTonalMDCTConc->pTCI->lowerIndex[i]; l <= hTonalMDCTConc->pTCI->upperIndex[i]; l++) + FOR( l = hTonalMDCTConc->pTCI->lowerIndex[i]; l <= hTonalMDCTConc->pTCI->upperIndex[i]; l++ ) { - mdctSpectrum[l] = L_deposit_l(0); + mdctSpectrum[l] = L_deposit_l( 0 ); } - FOR (l = hTonalMDCTConc->pTCI->upperIndex[i-1]+1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++) + FOR( l = hTonalMDCTConc->pTCI->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++ ) { Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; Word32 y; - rnd = extract_l(L_mac0(13849, rnd, 31821)); - y = L_mult(tilt,rnd); + rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); + y = L_mult( tilt, rnd ); - nrgNoiseInLastFrame = L_add(nrgNoiseInLastFrame, Mpy_32_16_1(L_msu(0, x,fac),x)); - x = round_fx(y); - nrgWhiteNoise = L_add(nrgWhiteNoise, Mpy_32_16_1(L_msu(0, x,fac),x)); + nrgNoiseInLastFrame = L_add( nrgNoiseInLastFrame, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); + x = round_fx( y ); + nrgWhiteNoise = L_add( nrgWhiteNoise, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); - mdctSpectrum[l] = y; /* 15Q16 L_deposit_l(y);*/ move32(); + mdctSpectrum[l] = y; /* 15Q16 L_deposit_l(y);*/ + move32(); - tilt = mult_r(tilt,tiltFactor); + tilt = mult_r( tilt, tiltFactor ); } } - tmp = round_fx(BASOP_Util_fPow(L_deposit_h(tiltFactor), 0, L_deposit_h(hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes-1]-hTonalMDCTConc->pTCI->lowerIndex[hTonalMDCTConc->pTCI->numIndexes-1]+1),15, &exp)); + tmp = round_fx( BASOP_Util_fPow( L_deposit_h( tiltFactor ), 0, L_deposit_h( hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1] - hTonalMDCTConc->pTCI->lowerIndex[hTonalMDCTConc->pTCI->numIndexes - 1] + 1 ), 15, &exp ) ); BASOP_SATURATE_WARNING_OFF_EVS /*next op may result in 32768*/ #ifdef BASOP_NOGLOB - tmp = shl_sat( tmp, exp ); + tmp = shl_sat( tmp, exp ); #else - tmp = shl(tmp, exp); + tmp = shl( tmp, exp ); #endif BASOP_SATURATE_WARNING_ON_EVS - tilt = mult_r(tilt,tmp); + tilt = mult_r( tilt, tmp ); - FOR (l = add(hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes-1], 1); l < crossOverFreq; l++) + FOR( l = add( hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1], 1 ); l < crossOverFreq; l++ ) { Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; Word32 y; - rnd = extract_l(L_mac0(13849, rnd, 31821)); - y = L_mult(tilt,rnd); + rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); + y = L_mult( tilt, rnd ); - nrgNoiseInLastFrame = L_add(nrgNoiseInLastFrame, Mpy_32_16_1(L_msu(0, x,fac),x)); - x = round_fx(y); - nrgWhiteNoise = L_add(nrgWhiteNoise, Mpy_32_16_1(L_msu(0, x,fac),x)); + nrgNoiseInLastFrame = L_add( nrgNoiseInLastFrame, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); + x = round_fx( y ); + nrgWhiteNoise = L_add( nrgWhiteNoise, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); - mdctSpectrum[l] = y; /* 15Q16 L_deposit_l(y);*/ move32(); + mdctSpectrum[l] = y; /* 15Q16 L_deposit_l(y);*/ + move32(); - tilt = mult_r(tilt,tiltFactor); + tilt = mult_r( tilt, tiltFactor ); } - IF (nrgNoiseInLastFrame == 0) + IF( nrgNoiseInLastFrame == 0 ) { - set32_fx(mdctSpectrum, 0, crossOverFreq); + set32_fx( mdctSpectrum, 0, crossOverFreq ); *mdctSpectrum_exp = SPEC_EXP_DEC; } ELSE { - exp_last = add(ld,shl(hTonalMDCTConc->lastBlockData.spectralData_exp,1)); - exp_noise = add(ld,shl(15,1)); + exp_last = add( ld, shl( hTonalMDCTConc->lastBlockData.spectralData_exp, 1 ) ); + exp_noise = add( ld, shl( 15, 1 ) ); - ld = norm_l(nrgNoiseInLastFrame); - nrgNoiseInLastFrame = L_shl(nrgNoiseInLastFrame,ld); - exp_last = sub(exp_last,ld); - ld = norm_l(nrgWhiteNoise); - nrgWhiteNoise = L_shl(nrgWhiteNoise,ld); - exp_noise = sub(exp_noise,ld); + ld = norm_l( nrgNoiseInLastFrame ); + nrgNoiseInLastFrame = L_shl( nrgNoiseInLastFrame, ld ); + exp_last = sub( exp_last, ld ); + ld = norm_l( nrgWhiteNoise ); + nrgWhiteNoise = L_shl( nrgWhiteNoise, ld ); + exp_noise = sub( exp_noise, ld ); - exp = sub(exp_last, exp_noise); + exp = sub( exp_last, exp_noise ); - IF(nrgNoiseInLastFrame > nrgWhiteNoise) + IF( nrgNoiseInLastFrame > nrgWhiteNoise ) { - nrgNoiseInLastFrame = L_shr(nrgNoiseInLastFrame,1); - exp = add(exp,1); + nrgNoiseInLastFrame = L_shr( nrgNoiseInLastFrame, 1 ); + exp = add( exp, 1 ); } - tmp = div_l(nrgNoiseInLastFrame,round_fx(nrgWhiteNoise)); - tmp = Sqrt16(tmp, &exp); - g = mult_r(g,tmp); + tmp = div_l( nrgNoiseInLastFrame, round_fx( nrgWhiteNoise ) ); + tmp = Sqrt16( tmp, &exp ); + g = mult_r( g, tmp ); - L_tmp = L_deposit_h(0); - ld = sub(hTonalMDCTConc->lastBlockData.spectralData_exp, 15); - exp = sub(ld, exp); - IF(exp > 0) + L_tmp = L_deposit_h( 0 ); + ld = sub( hTonalMDCTConc->lastBlockData.spectralData_exp, 15 ); + exp = sub( ld, exp ); + IF( exp > 0 ) { - g = shr(g,exp); + g = shr( g, exp ); *mdctSpectrum_exp = hTonalMDCTConc->lastBlockData.spectralData_exp; } - ELSE + ELSE { - crossfadeGain = shl(crossfadeGain,exp); - *mdctSpectrum_exp = sub(hTonalMDCTConc->lastBlockData.spectralData_exp,exp); + crossfadeGain = shl( crossfadeGain, exp ); + *mdctSpectrum_exp = sub( hTonalMDCTConc->lastBlockData.spectralData_exp, exp ); } /*make a headroom for mdct_shaping*/ - exp = sub(*mdctSpectrum_exp, SPEC_EXP_DEC); + exp = sub( *mdctSpectrum_exp, SPEC_EXP_DEC ); - IF(exp < 0) + IF( exp < 0 ) { *mdctSpectrum_exp = SPEC_EXP_DEC; } @@ -2588,43 +2589,43 @@ void TonalMDCTConceal_InsertNoise( exp = 0; } - FOR (l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++) + FOR( l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++ ) { Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; Word32 const y = mdctSpectrum[l]; - if(g > 0) + if ( g > 0 ) { - L_tmp = Mpy_32_16_1(y,g); + L_tmp = Mpy_32_16_1( y, g ); } - L_tmp2 = L_msu(L_tmp,crossfadeGain,x); - if(y > 0) + L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); + if ( y > 0 ) { - L_tmp2 = L_mac(L_tmp,crossfadeGain,x); + L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); } - mdctSpectrum[l] = L_shl(L_tmp2, exp); + mdctSpectrum[l] = L_shl( L_tmp2, exp ); move32(); } - FOR (i = 1; i < hTonalMDCTConc->pTCI->numIndexes; i++) + FOR( i = 1; i < hTonalMDCTConc->pTCI->numIndexes; i++ ) { - FOR (l = hTonalMDCTConc->pTCI->upperIndex[i-1]+1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++) + FOR( l = hTonalMDCTConc->pTCI->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++ ) { Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; Word32 const y = mdctSpectrum[l]; - if(g > 0) + if ( g > 0 ) { - L_tmp = Mpy_32_16_1(y,g); + L_tmp = Mpy_32_16_1( y, g ); } - L_tmp2 = L_msu(L_tmp,crossfadeGain,x); - if(y > 0) + L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); + if ( y > 0 ) { - L_tmp2 = L_mac(L_tmp,crossfadeGain,x); + L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); } - mdctSpectrum[l] = L_shl(L_tmp2, exp); + mdctSpectrum[l] = L_shl( L_tmp2, exp ); move32(); } } @@ -2633,37 +2634,37 @@ void TonalMDCTConceal_InsertNoise( necessary, but currently the whole spectrum is rescaled in mdct_noiseShaping() and then there would be a processing of uninitialized values */ - FOR (i = 0; i < hTonalMDCTConc->pTCI->numIndexes; i++) + FOR( i = 0; i < hTonalMDCTConc->pTCI->numIndexes; i++ ) { - FOR (l = hTonalMDCTConc->pTCI->lowerIndex[i]; l <= hTonalMDCTConc->pTCI->upperIndex[i]; l++) + FOR( l = hTonalMDCTConc->pTCI->lowerIndex[i]; l <= hTonalMDCTConc->pTCI->upperIndex[i]; l++ ) { - mdctSpectrum[l] = L_deposit_l(0); + mdctSpectrum[l] = L_deposit_l( 0 ); } } - FOR (l = add(hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes-1], 1); l < crossOverFreq; l++) + FOR( l = add( hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1], 1 ); l < crossOverFreq; l++ ) { Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; Word32 const y = mdctSpectrum[l]; - if(g > 0) + if ( g > 0 ) { - L_tmp = Mpy_32_16_1(y,g); + L_tmp = Mpy_32_16_1( y, g ); } - L_tmp2 = L_msu(L_tmp,crossfadeGain,x); - if(y > 0) + L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); + if ( y > 0 ) { - L_tmp2 = L_mac(L_tmp,crossfadeGain,x); + L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); } - mdctSpectrum[l] = L_shl(L_tmp2, exp); + mdctSpectrum[l] = L_shl( L_tmp2, exp ); move32(); } } - exp = sub(hTonalMDCTConc->lastBlockData.spectralData_exp, sub(*mdctSpectrum_exp,16)); - FOR (l = crossOverFreq; l < hTonalMDCTConc->lastBlockData.nSamples; l++) + exp = sub( hTonalMDCTConc->lastBlockData.spectralData_exp, sub( *mdctSpectrum_exp, 16 ) ); + FOR( l = crossOverFreq; l < hTonalMDCTConc->lastBlockData.nSamples; l++ ) { - mdctSpectrum[l] = L_shl(L_deposit_l(hTonalMDCTConc->lastBlockData.spectralData[l]), exp); + mdctSpectrum[l] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), exp ); move32(); } } @@ -2672,7 +2673,7 @@ void TonalMDCTConceal_InsertNoise( *pSeed = rnd; move16(); - return ; + return; } void TonalMDCTConceal_Apply( @@ -2685,100 +2686,101 @@ void TonalMDCTConceal_Apply( ) { Word16 i, l, exp; - Word16 * phaseDiff, * pCurrentPhase; + Word16 *phaseDiff, *pCurrentPhase; Word32 phaseToAdd, currentPhase; Word32 powerSpectrum[L_FRAME_MAX]; Word16 nSamples; - - IF (hTonalMDCTConc->lastBlockData.blockIsValid & hTonalMDCTConc->secondLastBlockData.blockIsValid) + IF( hTonalMDCTConc->lastBlockData.blockIsValid & hTonalMDCTConc->secondLastBlockData.blockIsValid ) { - assert(hTonalMDCTConc->pTCI->numIndexes > 0); + assert( hTonalMDCTConc->pTCI->numIndexes > 0 ); nSamples = hTonalMDCTConc->nNonZeroSamples; move16(); - assert(hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes-1] < nSamples); + assert( hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1] < nSamples ); #ifdef IVAS_CODE_MDCT_GSHAPE - IF (psychParamsCurrent == NULL) + IF( psychParamsCurrent == NULL ) #endif { - mdct_shaping_16(hTonalMDCTConc->secondLastPowerSpectrum, hTonalMDCTConc->nSamplesCore, nSamples, - hTonalMDCTConc->secondLastBlockData.scaleFactors, hTonalMDCTConc->secondLastBlockData.scaleFactors_exp, - hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e, powerSpectrum); + mdct_shaping_16( hTonalMDCTConc->secondLastPowerSpectrum, hTonalMDCTConc->nSamplesCore, nSamples, + hTonalMDCTConc->secondLastBlockData.scaleFactors, hTonalMDCTConc->secondLastBlockData.scaleFactors_exp, + hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e, powerSpectrum ); } #ifdef IVAS_CODE_MDCT_GSHAPE ELSE { - sns_shape_spectrum(powerSpectrum, psychParamsCurrent, hTonalMDCTConc->secondLastBlockData.scaleFactors, hTonalMDCTConc->nSamplesCore); + sns_shape_spectrum( powerSpectrum, psychParamsCurrent, hTonalMDCTConc->secondLastBlockData.scaleFactors, hTonalMDCTConc->nSamplesCore ); nBands = psychParamsCurrent->nBands; - } #endif phaseDiff = hTonalMDCTConc->pTCI->phaseDiff; /* if multiple frame loss occurs use the phase from the last frame and continue rotating */ pCurrentPhase = hTonalMDCTConc->pTCI->phase_currentFramePredicted; - exp = sub(*mdctSpectrum_exp, add(add(hTonalMDCTConc->secondLastPowerSpectrum_exp, add(hTonalMDCTConc->secondLastBlockData.gain_tcx_exp,1)),hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e)); + exp = sub( *mdctSpectrum_exp, add( add( hTonalMDCTConc->secondLastPowerSpectrum_exp, add( hTonalMDCTConc->secondLastBlockData.gain_tcx_exp, 1 ) ), hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e ) ); - IF (!hTonalMDCTConc->lastBlockData.blockIsConcealed) + IF( !hTonalMDCTConc->lastBlockData.blockIsConcealed ) { - if (hTonalMDCTConc->secondLastBlockData.tonalConcealmentActive != 0) + if ( hTonalMDCTConc->secondLastBlockData.tonalConcealmentActive != 0 ) { - hTonalMDCTConc->nFramesLost = add(hTonalMDCTConc->nFramesLost,2); /*Q1*/ move16(); + hTonalMDCTConc->nFramesLost = add( hTonalMDCTConc->nFramesLost, 2 ); /*Q1*/ + move16(); } - if (hTonalMDCTConc->secondLastBlockData.tonalConcealmentActive == 0) + if ( hTonalMDCTConc->secondLastBlockData.tonalConcealmentActive == 0 ) { - hTonalMDCTConc->nFramesLost = 3; /*Q1*/ move16(); + hTonalMDCTConc->nFramesLost = 3; /*Q1*/ + move16(); } } /* for each index group */ - FOR (i = 0; i < hTonalMDCTConc->pTCI->numIndexes; i++) + FOR( i = 0; i < hTonalMDCTConc->pTCI->numIndexes; i++ ) { /*phaseToAdd = hTonalMDCTConc->nFramesLost*phaseDiff[i]; */ - phaseToAdd = L_mult0(hTonalMDCTConc->nFramesLost,phaseDiff[i]); /*Q1*3Q12=2Q13*/ + phaseToAdd = L_mult0( hTonalMDCTConc->nFramesLost, phaseDiff[i] ); /*Q1*3Q12=2Q13*/ /* Move phaseToAdd to range -PI..PI */ - WHILE (GT_32(phaseToAdd, 25736l/*EVS_PI Q13*/)) + WHILE( GT_32( phaseToAdd, 25736l /*EVS_PI Q13*/ ) ) { - phaseToAdd = L_sub(phaseToAdd, 51472l/*2*EVS_PI Q13*/); + phaseToAdd = L_sub( phaseToAdd, 51472l /*2*EVS_PI Q13*/ ); } - WHILE (LT_32(phaseToAdd, -25736l/*-EVS_PI Q13*/)) + WHILE( LT_32( phaseToAdd, -25736l /*-EVS_PI Q13*/ ) ) { - phaseToAdd = L_add(phaseToAdd, 51472l/*2*EVS_PI Q13*/); + phaseToAdd = L_add( phaseToAdd, 51472l /*2*EVS_PI Q13*/ ); } - FOR (l = hTonalMDCTConc->pTCI->lowerIndex[i]; l <= hTonalMDCTConc->pTCI->upperIndex[i]; l++) + FOR( l = hTonalMDCTConc->pTCI->lowerIndex[i]; l <= hTonalMDCTConc->pTCI->upperIndex[i]; l++ ) { /* *pCurrentPhase and phaseToAdd are in range -PI..PI */ - currentPhase = L_mac0(phaseToAdd, (*pCurrentPhase++), 1); /*2Q13+2Q13=3Q13*/ + currentPhase = L_mac0( phaseToAdd, ( *pCurrentPhase++ ), 1 ); /*2Q13+2Q13=3Q13*/ - if (GT_32(currentPhase, 25736l/*EVS_PI Q13*/)) + if ( GT_32( currentPhase, 25736l /*EVS_PI Q13*/ ) ) { - currentPhase = L_sub(currentPhase, 51472l/*2*EVS_PI Q13*/); + currentPhase = L_sub( currentPhase, 51472l /*2*EVS_PI Q13*/ ); } - if (LT_32(currentPhase, -25736l/*-EVS_PI Q13*/)) + if ( LT_32( currentPhase, -25736l /*-EVS_PI Q13*/ ) ) { - currentPhase = L_add(currentPhase, 51472l/*2*EVS_PI Q13*/); + currentPhase = L_add( currentPhase, 51472l /*2*EVS_PI Q13*/ ); } /* getCosWord16 returns 1Q14*/ - mdctSpectrum[l] = Mpy_32_16_1(powerSpectrum[l],getCosWord16(extract_l(currentPhase))); + mdctSpectrum[l] = Mpy_32_16_1( powerSpectrum[l], getCosWord16( extract_l( currentPhase ) ) ); move32(); - mdctSpectrum[l] = L_shr(mdctSpectrum[l], exp); + mdctSpectrum[l] = L_shr( mdctSpectrum[l], exp ); } } } - hTonalMDCTConc->nFramesLost = add(hTonalMDCTConc->nFramesLost,2); /*Q1*/ move16(); + hTonalMDCTConc->nFramesLost = add( hTonalMDCTConc->nFramesLost, 2 ); /*Q1*/ + move16(); - return ; + return; } #ifdef IVAS_FLOAT_FIXED void TonalMDCTConceal_Apply_ivas_fx( TonalMDCTConcealPtr hTonalMDCTConc, /*IN */ - Word32 *mdctSpectrum, /*IN/OUT*/ + Word32 *mdctSpectrum, /*IN/OUT*/ Word16 *mdctSpectrum_exp, /*IN */ const PsychoacousticParameters *psychParamsCurrent ) @@ -2795,18 +2797,18 @@ void TonalMDCTConceal_Apply_ivas_fx( Word16 *tmp_secondLastPowerSpectrum = hTonalMDCTConc->secondLastPowerSpectrum; Word16 tmp_secondLastPowerSpectrum_exp = hTonalMDCTConc->secondLastPowerSpectrum_exp; - Word16 max_nSamples = s_max(hTonalMDCTConc->nNonZeroSamples, hTonalMDCTConc->nSamplesCore); + Word16 max_nSamples = s_max( hTonalMDCTConc->nNonZeroSamples, hTonalMDCTConc->nSamplesCore ); // To avoid garbage values - set32_fx(powerSpectrum, 0, L_FRAME_MAX); + set32_fx( powerSpectrum, 0, L_FRAME_MAX ); /* Creating 32-bit scaleFactors with common exponent. */ - FOR(i = 0; i < FDNS_NPTS; i++) + FOR( i = 0; i < FDNS_NPTS; i++ ) { - scaleFactors[i] = L_shr(L_deposit_h(hTonalMDCTConc->secondLastBlockData.scaleFactors[i]), sub(hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e, hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[i])); + scaleFactors[i] = L_shr( L_deposit_h( hTonalMDCTConc->secondLastBlockData.scaleFactors[i] ), sub( hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e, hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[i] ) ); } - IF ( hTonalMDCTConc->lastBlockData.blockIsValid & hTonalMDCTConc->secondLastBlockData.blockIsValid ) + IF( hTonalMDCTConc->lastBlockData.blockIsValid & hTonalMDCTConc->secondLastBlockData.blockIsValid ) { assert( hTonalMDCTConc->pTCI->numIndexes > 0 ); @@ -2814,9 +2816,9 @@ void TonalMDCTConceal_Apply_ivas_fx( move16(); assert( hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1] < nSamples ); - FOR (i = 0; i < nSamples; i++) + FOR( i = 0; i < nSamples; i++ ) { - powerSpectrum[i] = L_deposit_h(tmp_secondLastPowerSpectrum[i]); + powerSpectrum[i] = L_deposit_h( tmp_secondLastPowerSpectrum[i] ); move16(); } powerSpectrum_exp = tmp_secondLastPowerSpectrum_exp; @@ -2824,36 +2826,36 @@ void TonalMDCTConceal_Apply_ivas_fx( Word16 exp1 = powerSpectrum_exp; - IF ( psychParamsCurrent == NULL ) + IF( psychParamsCurrent == NULL ) { nBands = FDNS_NPTS; move16(); - mdct_noiseShaping_ivas_fx(powerSpectrum, &powerSpectrum_exp, hTonalMDCTConc->nSamplesCore, hTonalMDCTConc->secondLastBlockData.scaleFactors, - hTonalMDCTConc->secondLastBlockData.scaleFactors_exp); + mdct_noiseShaping_ivas_fx( powerSpectrum, &powerSpectrum_exp, hTonalMDCTConc->nSamplesCore, hTonalMDCTConc->secondLastBlockData.scaleFactors, + hTonalMDCTConc->secondLastBlockData.scaleFactors_exp ); } ELSE { Word16 q_ps, q_sf; - q_ps = sub(31, powerSpectrum_exp); - q_sf = sub(31, hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e); + q_ps = sub( 31, powerSpectrum_exp ); + q_sf = sub( 31, hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e ); /* adding guard bit */ - q_ps = sub(q_ps, 1); + q_ps = sub( q_ps, 1 ); FOR( Word16 c = 0; c < hTonalMDCTConc->nSamplesCore; c++ ) { - powerSpectrum[c] = L_shr(powerSpectrum[c], 1); + powerSpectrum[c] = L_shr( powerSpectrum[c], 1 ); } /* adding guard bit */ - q_sf = sub(q_sf, 1); - FOR(Word16 c = 0; c < FDNS_NPTS; c++) + q_sf = sub( q_sf, 1 ); + FOR( Word16 c = 0; c < FDNS_NPTS; c++ ) { - scaleFactors[c] = L_shr(scaleFactors[c], 1); + scaleFactors[c] = L_shr( scaleFactors[c], 1 ); } sns_shape_spectrum_fx( powerSpectrum, &q_ps, psychParamsCurrent, scaleFactors, q_sf, hTonalMDCTConc->nSamplesCore ); - powerSpectrum_exp = sub(31, add(q_ps, 1)); + powerSpectrum_exp = sub( 31, add( q_ps, 1 ) ); nBands = psychParamsCurrent->nBands; move16(); @@ -2862,24 +2864,27 @@ void TonalMDCTConceal_Apply_ivas_fx( Word16 exp_left = powerSpectrum_exp; Word16 exp_right = exp1; - FOR (Word16 c = hTonalMDCTConc->nSamplesCore; c < nSamples; c++) + FOR( Word16 c = hTonalMDCTConc->nSamplesCore; c < nSamples; c++ ) { - powerSpectrum[c] = Mpy_32_16_1(powerSpectrum[c], hTonalMDCTConc->secondLastBlockData.scaleFactors[nBands - 1]); + powerSpectrum[c] = Mpy_32_16_1( powerSpectrum[c], hTonalMDCTConc->secondLastBlockData.scaleFactors[nBands - 1] ); } - exp_right = add(exp_right, hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[nBands - 1]); + exp_right = add( exp_right, hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[nBands - 1] ); - Word16 max_e = s_max(exp_right, exp_left); - FOR (Word16 c = 0; c < max_nSamples; c++) + Word16 max_e = s_max( exp_right, exp_left ); + FOR( Word16 c = 0; c < max_nSamples; c++ ) { - test(); test(); test(); test(); - IF (GE_16(c, hTonalMDCTConc->nSamplesCore) && LT_16(c, nSamples) && GT_16(max_e, exp_right)) + test(); + test(); + test(); + test(); + IF( GE_16( c, hTonalMDCTConc->nSamplesCore ) && LT_16( c, nSamples ) && GT_16( max_e, exp_right ) ) { - powerSpectrum[c] = L_shr(powerSpectrum[c], sub(max_e, exp_right)); + powerSpectrum[c] = L_shr( powerSpectrum[c], sub( max_e, exp_right ) ); move32(); } - ELSE IF ((LT_16(c, hTonalMDCTConc->nSamplesCore) || GT_16(c, nSamples)) && GT_16(max_e, exp_left)) + ELSE IF( ( LT_16( c, hTonalMDCTConc->nSamplesCore ) || GT_16( c, nSamples ) ) && GT_16( max_e, exp_left ) ) { - powerSpectrum[c] = L_shr(powerSpectrum[c], sub(max_e, exp_left)); + powerSpectrum[c] = L_shr( powerSpectrum[c], sub( max_e, exp_left ) ); move32(); } } @@ -2889,14 +2894,14 @@ void TonalMDCTConceal_Apply_ivas_fx( phaseDiff = hTonalMDCTConc->pTCI->phaseDiff; /* if multiple frame loss occurs use the phase from the last frame and continue rotating */ pCurrentPhase = hTonalMDCTConc->pTCI->phase_currentFramePredicted; - IF(!hTonalMDCTConc->lastBlockData.blockIsConcealed) + IF( !hTonalMDCTConc->lastBlockData.blockIsConcealed ) { - IF (hTonalMDCTConc->secondLastBlockData.tonalConcealmentActive != 0) + IF( hTonalMDCTConc->secondLastBlockData.tonalConcealmentActive != 0 ) { - hTonalMDCTConc->nFramesLost = add(hTonalMDCTConc->nFramesLost, 2); /*Q1*/ + hTonalMDCTConc->nFramesLost = add( hTonalMDCTConc->nFramesLost, 2 ); /*Q1*/ move16(); } - IF (hTonalMDCTConc->secondLastBlockData.tonalConcealmentActive == 0) + IF( hTonalMDCTConc->secondLastBlockData.tonalConcealmentActive == 0 ) { hTonalMDCTConc->nFramesLost = 3; /*Q1*/ move16(); @@ -2904,115 +2909,115 @@ void TonalMDCTConceal_Apply_ivas_fx( } /* for each index group */ - FOR ( i = 0; i < hTonalMDCTConc->pTCI->numIndexes; i++ ) + FOR( i = 0; i < hTonalMDCTConc->pTCI->numIndexes; i++ ) { - phaseToAdd = L_mult0(hTonalMDCTConc->nFramesLost, phaseDiff[i]); /*Q1*3Q12=2Q13*/ + phaseToAdd = L_mult0( hTonalMDCTConc->nFramesLost, phaseDiff[i] ); /*Q1*3Q12=2Q13*/ /* Move phaseToAdd to range -PI..PI */ - WHILE(GT_32(phaseToAdd, 25736l/*EVS_PI Q13*/)) + WHILE( GT_32( phaseToAdd, 25736l /*EVS_PI Q13*/ ) ) { - phaseToAdd = L_sub(phaseToAdd, 51472l/*2*EVS_PI Q13*/); + phaseToAdd = L_sub( phaseToAdd, 51472l /*2*EVS_PI Q13*/ ); } - WHILE(LT_32(phaseToAdd, -25736l/*-EVS_PI Q13*/)) + WHILE( LT_32( phaseToAdd, -25736l /*-EVS_PI Q13*/ ) ) { - phaseToAdd = L_add(phaseToAdd, 51472l/*2*EVS_PI Q13*/); + phaseToAdd = L_add( phaseToAdd, 51472l /*2*EVS_PI Q13*/ ); } - FOR ( l = hTonalMDCTConc->pTCI->lowerIndex[i]; l <= hTonalMDCTConc->pTCI->upperIndex[i]; l++ ) + FOR( l = hTonalMDCTConc->pTCI->lowerIndex[i]; l <= hTonalMDCTConc->pTCI->upperIndex[i]; l++ ) { /* *pCurrentPhase and phaseToAdd are in range -PI..PI */ - Word32 currentPhase = L_mac0(phaseToAdd, ( *pCurrentPhase++ ), 1); /*2Q13+2Q13=3Q13*/ - IF (GT_32(currentPhase, 25736l/*EVS_PI Q13*/)) + Word32 currentPhase = L_mac0( phaseToAdd, ( *pCurrentPhase++ ), 1 ); /*2Q13+2Q13=3Q13*/ + IF( GT_32( currentPhase, 25736l /*EVS_PI Q13*/ ) ) { - currentPhase = L_sub(currentPhase, 51472l/*2*EVS_PI Q13*/); + currentPhase = L_sub( currentPhase, 51472l /*2*EVS_PI Q13*/ ); } - IF(LT_32(currentPhase, -25736l/*-EVS_PI Q13*/)) + IF( LT_32( currentPhase, -25736l /*-EVS_PI Q13*/ ) ) { - currentPhase = L_add(currentPhase, 51472l/*2*EVS_PI Q13*/); + currentPhase = L_add( currentPhase, 51472l /*2*EVS_PI Q13*/ ); } /* getCosWord16 returns 1Q14*/ - mdctSpectrum[l] = Mpy_32_16_1(powerSpectrum[l], getCosWord16(extract_l(currentPhase))); + mdctSpectrum[l] = Mpy_32_16_1( powerSpectrum[l], getCosWord16( extract_l( currentPhase ) ) ); move32(); - *mdctSpectrum_exp = add(powerSpectrum_exp, 1); // getCosWord16 returns Q14 (exp is 1) + *mdctSpectrum_exp = add( powerSpectrum_exp, 1 ); // getCosWord16 returns Q14 (exp is 1) } } } - hTonalMDCTConc->nFramesLost = add(hTonalMDCTConc->nFramesLost, 2); /*Q1*/ + hTonalMDCTConc->nFramesLost = add( hTonalMDCTConc->nFramesLost, 2 ); /*Q1*/ move16(); return; } #endif -void TonalMDCTConceal_SaveTimeSignal( +void TonalMDCTConceal_SaveTimeSignal( TonalMDCTConcealPtr hTonalMDCTConc, - Word16* timeSignal, - Word16 nNewSamples - + Word16 *timeSignal, + Word16 nNewSamples + ) { - IF (EQ_16(nNewSamples,hTonalMDCTConc->nSamples)) + IF( EQ_16( nNewSamples, hTonalMDCTConc->nSamples ) ) { - assert(nNewSamples <= L_FRAME_MAX); - IF (!hTonalMDCTConc->secondLastBlockData.tonalConcealmentActive) + assert( nNewSamples <= L_FRAME_MAX ); + IF( !hTonalMDCTConc->secondLastBlockData.tonalConcealmentActive ) { - Copy(hTonalMDCTConc->lastPcmOut + hTonalMDCTConc->nSamples/2, hTonalMDCTConc->secondLastPcmOut, hTonalMDCTConc->nSamples/2); + Copy( hTonalMDCTConc->lastPcmOut + hTonalMDCTConc->nSamples / 2, hTonalMDCTConc->secondLastPcmOut, hTonalMDCTConc->nSamples / 2 ); } - Copy(timeSignal, hTonalMDCTConc->lastPcmOut, hTonalMDCTConc->nSamples); + Copy( timeSignal, hTonalMDCTConc->lastPcmOut, hTonalMDCTConc->nSamples ); } - return ; + return; } static void CalcPowerSpec( - const Word32 * mdctSpec, /* i: MDCT spectrum Q31,mdctSpec_exp */ - const Word16 mdctSpec_exp, /* i: exponent of MDCT spectrum */ - const Word32 * mdstSpec, /* i: MDST spectrum Q31,mdstSpec_exp */ - const Word16 mdstSpec_exp, /* i: exponent of MDST spectrum */ - const Word16 nSamples, /* i: frame size */ - const Word16 floorPowerSpectrum, /* i: lower limit for power spectrum bins Q0 */ - Word32 * powerSpec, /* o: power spectrum */ - Word16 * powerSpec_exp) /* o: exponent of power spectrum */ + const Word32 *mdctSpec, /* i: MDCT spectrum Q31,mdctSpec_exp */ + const Word16 mdctSpec_exp, /* i: exponent of MDCT spectrum */ + const Word32 *mdstSpec, /* i: MDST spectrum Q31,mdstSpec_exp */ + const Word16 mdstSpec_exp, /* i: exponent of MDST spectrum */ + const Word16 nSamples, /* i: frame size */ + const Word16 floorPowerSpectrum, /* i: lower limit for power spectrum bins Q0 */ + Word32 *powerSpec, /* o: power spectrum */ + Word16 *powerSpec_exp ) /* o: exponent of power spectrum */ { Word16 k, s1, s2, tmp; Word32 x, L_tmp, L_tmp_floor; - k = s_max(mdctSpec_exp, mdstSpec_exp); - *powerSpec_exp = add(add(k, k), 3); /*extra 3 bits of headroom for MA filter in getEnvelope*/ move16(); - s1 = sub(*powerSpec_exp, add(mdctSpec_exp, mdctSpec_exp)); - s2 = sub(*powerSpec_exp, add(mdstSpec_exp, mdstSpec_exp)); + k = s_max( mdctSpec_exp, mdstSpec_exp ); + *powerSpec_exp = add( add( k, k ), 3 ); /*extra 3 bits of headroom for MA filter in getEnvelope*/ + move16(); + s1 = sub( *powerSpec_exp, add( mdctSpec_exp, mdctSpec_exp ) ); + s2 = sub( *powerSpec_exp, add( mdstSpec_exp, mdstSpec_exp ) ); - k = sub(31, *powerSpec_exp); + k = sub( 31, *powerSpec_exp ); /* If the signal is bellow floor, special care is needed for *powerSpec_exp */ - IF (LT_16(add(16-3, norm_s(floorPowerSpectrum)), k)) /*extra 3 bits of headroom for MA filter in getEnvelope*/ + IF( LT_16( add( 16 - 3, norm_s( floorPowerSpectrum ) ), k ) ) /*extra 3 bits of headroom for MA filter in getEnvelope*/ { - k = sub(k, add(16-3, norm_s(floorPowerSpectrum))); /*extra 3 bits of headroom for MA filter in getEnvelope*/ - *powerSpec_exp = add(*powerSpec_exp, k); - s1 = add(s1, k); - s2 = add(s2, k); - k = add(16-3, norm_s(floorPowerSpectrum)); + k = sub( k, add( 16 - 3, norm_s( floorPowerSpectrum ) ) ); /*extra 3 bits of headroom for MA filter in getEnvelope*/ + *powerSpec_exp = add( *powerSpec_exp, k ); + s1 = add( s1, k ); + s2 = add( s2, k ); + k = add( 16 - 3, norm_s( floorPowerSpectrum ) ); } - L_tmp_floor = L_shl(L_deposit_l(floorPowerSpectrum), k); + L_tmp_floor = L_shl( L_deposit_l( floorPowerSpectrum ), k ); - tmp = sub(nSamples, 2); - FOR (k = 1; k <= tmp; k++) + tmp = sub( nSamples, 2 ); + FOR( k = 1; k <= tmp; k++ ) { - x = Mpy_32_32(mdctSpec[k], mdctSpec[k]); /*Q31,2*mdctSpec_exp*/ + x = Mpy_32_32( mdctSpec[k], mdctSpec[k] ); /*Q31,2*mdctSpec_exp*/ - L_tmp = Mpy_32_32(mdstSpec[k], mdstSpec[k]); /*Q31,2*mdstSpec_exp*/ - x = L_add(L_shr(x,s1), L_shr(L_tmp,s2)); /*Q31,*powerSpec_exp*/ + L_tmp = Mpy_32_32( mdstSpec[k], mdstSpec[k] ); /*Q31,2*mdstSpec_exp*/ + x = L_add( L_shr( x, s1 ), L_shr( L_tmp, s2 ) ); /*Q31,*powerSpec_exp*/ - powerSpec[k] = L_max(L_tmp_floor, x); + powerSpec[k] = L_max( L_tmp_floor, x ); move32(); } - powerSpec[0] = L_shr(powerSpec[1], 1); + powerSpec[0] = L_shr( powerSpec[1], 1 ); move32(); - powerSpec[nSamples-1] = L_shr(powerSpec[nSamples-2], 1); + powerSpec[nSamples - 1] = L_shr( powerSpec[nSamples - 2], 1 ); move32(); - } #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT void TonalMdctConceal_create_concealment_noise( @@ -3024,21 +3029,21 @@ void TonalMdctConceal_create_concealment_noise( const int16_t subframe_idx, const int16_t core, const int16_t crossfade_gain, - const TONALMDCTCONC_NOISE_GEN_MODE noise_gen_mode) + const TONALMDCTCONC_NOISE_GEN_MODE noise_gen_mode ) { STEREO_MDCT_DEC_DATA_HANDLE hStereoMdct; TonalMDCTConcealPtr hTonalMDCTConc; - Decoder_State* st; + Decoder_State *st; HANDLE_FD_CNG_COM hFdCngCom; - int16_t* rnd_c, * rnd; + int16_t *rnd_c, *rnd; int16_t crossOverFreq, i, save_rnd_c, max_noise_line; float c, c_inv; float noise_shape_buffer[L_FRAME48k]; int16_t inc, start_idx, stop_idx; - float* cngNoiseLevelPtr; + float *cngNoiseLevelPtr; float last_scf; - wmops_sub_start("create_conc_noise"); + wmops_sub_start( "create_conc_noise" ); hStereoMdct = hCPE->hStereoMdct; st = hCPE->hCoreCoder[idchan]; @@ -3048,13 +3053,13 @@ void TonalMdctConceal_create_concealment_noise( rnd_c = &hStereoMdct->noise_seed_common; /* determine start bin for IGF */ - if (st->igf == 0) + if ( st->igf == 0 ) { - if (st->narrowBand == 0) + if ( st->narrowBand == 0 ) { /* minimum needed for output with sampling rates lower then the nominal sampling rate */ - crossOverFreq = min(L_frameTCX, L_frame); + crossOverFreq = min( L_frameTCX, L_frame ); } else { @@ -3063,30 +3068,30 @@ void TonalMdctConceal_create_concealment_noise( } else { - crossOverFreq = min(st->hIGFDec->infoIGFStartLine, L_frameTCX); + crossOverFreq = min( st->hIGFDec->infoIGFStartLine, L_frameTCX ); } /* for tonal mdct concealment with tonal components above the crossover frequency, conditionally raise the frequency index until which noise is generated */ max_noise_line = crossOverFreq; - if (st->tonal_mdct_plc_active) + if ( st->tonal_mdct_plc_active ) { - max_noise_line = max(max_noise_line, hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1] + 1); + max_noise_line = max( max_noise_line, hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1] + 1 ); } /* first lost frame is handled separately */ - if (!hTonalMDCTConc->lastBlockData.blockIsConcealed) + if ( !hTonalMDCTConc->lastBlockData.blockIsConcealed ) { *rnd = 1977 + idchan; /* will be set twice when looping over two channels, but does not matter */ *rnd_c = 1979; } - if (crossfade_gain == 1.0f) + if ( crossfade_gain == 1.0f ) { /* In first frame, noise is weighted with zero anyway, we only need the random numbers for the sign scrambling */ - for (i = 0; i < max_noise_line; i++) + for ( i = 0; i < max_noise_line; i++ ) { - *rnd = own_random(rnd); + *rnd = own_random( rnd ); concealment_noise[i] = *rnd; } @@ -3097,62 +3102,62 @@ void TonalMdctConceal_create_concealment_noise( save_rnd_c = *rnd_c; - c = sqrtf(hStereoMdct->lastCoh); - c_inv = sqrtf(1 - hStereoMdct->lastCoh); + c = sqrtf( hStereoMdct->lastCoh ); + c_inv = sqrtf( 1 - hStereoMdct->lastCoh ); /* pre-compute the noise shape for later weighting of the noise spectra */ cngNoiseLevelPtr = &hFdCngCom->cngNoiseLevel_flt[0]; - inc = (st->core > TCX_20_CORE) ? 2 : 1; + inc = ( st->core > TCX_20_CORE ) ? 2 : 1; start_idx = hFdCngCom->startBand / inc; stop_idx = hFdCngCom->stopFFTbin / inc; - for (i = 0; i < start_idx; i++) + for ( i = 0; i < start_idx; i++ ) { noise_shape_buffer[i] = 0.0f; } - for (; i < stop_idx; i++, cngNoiseLevelPtr += inc) + for ( ; i < stop_idx; i++, cngNoiseLevelPtr += inc ) { - noise_shape_buffer[i] = sqrtf(*(cngNoiseLevelPtr)); + noise_shape_buffer[i] = sqrtf( *( cngNoiseLevelPtr ) ); } - last_scf = sqrtf(*(cngNoiseLevelPtr - inc)); + last_scf = sqrtf( *( cngNoiseLevelPtr - inc ) ); - for (; i < max_noise_line; i++) + for ( ; i < max_noise_line; i++ ) { noise_shape_buffer[i] = last_scf; } /* fill the noise vector */ hTonalMDCTConc->curr_noise_nrg_flt = MDCT_ST_PLC_FADEOUT_MIN_NOISE_NRG; - if (noise_gen_mode == EQUAL_CORES || ((noise_gen_mode == TCX20_IN_0_TCX10_IN_1 && idchan == 0) || (noise_gen_mode == TCX10_IN_0_TCX20_IN_1 && idchan == 1))) + if ( noise_gen_mode == EQUAL_CORES || ( ( noise_gen_mode == TCX20_IN_0_TCX10_IN_1 && idchan == 0 ) || ( noise_gen_mode == TCX10_IN_0_TCX20_IN_1 && idchan == 1 ) ) ) { /* current channel is TCX20 -> generate noise for "full-length" spectrum */ - for (i = 0; i < max_noise_line; i++) + for ( i = 0; i < max_noise_line; i++ ) { - *rnd = own_random(rnd); - *rnd_c = own_random(rnd_c); + *rnd = own_random( rnd ); + *rnd_c = own_random( rnd_c ); - concealment_noise[i] = (c_inv * *rnd + c * *rnd_c) * noise_shape_buffer[i]; + concealment_noise[i] = ( c_inv * *rnd + c * *rnd_c ) * noise_shape_buffer[i]; hTonalMDCTConc->curr_noise_nrg_flt += concealment_noise[i] * concealment_noise[i]; } } else /* ( ( noise_gen_mode == TCX10_IN_0_TCX20_IN_1 && idchan == 0 ) || ( noise_gen_mode == TCX20_IN_0_TCX10_IN_1 && idchan == 1 ) ) */ { /* current channel is TCX10 and the other is TCX20 -> generate noise for "half-length" spectrum, but "increment" mid seed twice, to have the same seed in mid as the other (TCX20) channel for next frame */ - for (i = 0; i < max_noise_line; i++) + for ( i = 0; i < max_noise_line; i++ ) { - *rnd = own_random(rnd); - *rnd_c = own_random(rnd_c); + *rnd = own_random( rnd ); + *rnd_c = own_random( rnd_c ); - concealment_noise[i] = (c_inv * *rnd + c * *rnd_c) * noise_shape_buffer[i]; + concealment_noise[i] = ( c_inv * *rnd + c * *rnd_c ) * noise_shape_buffer[i]; hTonalMDCTConc->curr_noise_nrg_flt += concealment_noise[i] * concealment_noise[i]; - *rnd_c = own_random(rnd_c); + *rnd_c = own_random( rnd_c ); } } - if (st->tonal_mdct_plc_active) + if ( st->tonal_mdct_plc_active ) { - for (i = crossOverFreq; i < max(crossOverFreq, hTonalMDCTConc->pTCI->lowerIndex[hTonalMDCTConc->pTCI->numIndexes - 1]); ++i) + for ( i = crossOverFreq; i < max( crossOverFreq, hTonalMDCTConc->pTCI->lowerIndex[hTonalMDCTConc->pTCI->numIndexes - 1] ); ++i ) { concealment_noise[i] *= 0.0f; } @@ -3160,7 +3165,7 @@ void TonalMdctConceal_create_concealment_noise( /* restore common seed - after finishing the first channel - after a first subframe if the current channel is TCX10 */ - if ((idchan == 0 && (core == TCX_20 || (core == TCX_10 && subframe_idx == 1))) || (core == TCX_10 && subframe_idx == 0)) + if ( ( idchan == 0 && ( core == TCX_20 || ( core == TCX_10 && subframe_idx == 1 ) ) ) || ( core == TCX_10 && subframe_idx == 0 ) ) { *rnd_c = save_rnd_c; } @@ -3170,41 +3175,41 @@ void TonalMdctConceal_create_concealment_noise( return; } void TonalMdctConceal_whiten_noise_shape( - Decoder_State* st, + Decoder_State *st, const int16_t L_frame, - const TONALMDCTCONC_NOISE_SHAPE_WHITENING_MODE whitening_mode) + const TONALMDCTCONC_NOISE_SHAPE_WHITENING_MODE whitening_mode ) { int16_t inc, start_idx, stop_idx; - float* noiseLevelPtr, * scfs_bg, * scfs_for_shaping; + float *noiseLevelPtr, *scfs_bg, *scfs_for_shaping; HANDLE_FD_CNG_COM hFdCngCom; float whitenend_noise_shape[L_FRAME16k]; float scfs_int[FDNS_NPTS]; - const PsychoacousticParameters* psychParams; + const PsychoacousticParameters *psychParams; - push_wmops("apply_sns_on_noise_shape"); + push_wmops( "apply_sns_on_noise_shape" ); scfs_bg = &st->hTonalMDCTConc->scaleFactorsBackground_flt[0]; psychParams = st->hTonalMDCTConc->psychParams; hFdCngCom = st->hFdCngDec->hFdCngCom; - inc = ((whitening_mode == ON_FIRST_LOST_FRAME ? st->core : st->last_core) > TCX_20_CORE) ? 2 : 1; + inc = ( ( whitening_mode == ON_FIRST_LOST_FRAME ? st->core : st->last_core ) > TCX_20_CORE ) ? 2 : 1; start_idx = hFdCngCom->startBand / inc; stop_idx = L_frame / inc; noiseLevelPtr = hFdCngCom->cngNoiseLevel_flt; - set_zero(whitenend_noise_shape, start_idx); - for (int16_t j = start_idx; j < stop_idx; j++, noiseLevelPtr += inc) + set_zero( whitenend_noise_shape, start_idx ); + for ( int16_t j = start_idx; j < stop_idx; j++, noiseLevelPtr += inc ) { whitenend_noise_shape[j] = *noiseLevelPtr; } - if (whitening_mode == ON_FIRST_LOST_FRAME) + if ( whitening_mode == ON_FIRST_LOST_FRAME ) { float scf[SNS_NPTS]; - sns_compute_scf(whitenend_noise_shape, psychParams, L_frame, scf); - sns_interpolate_scalefactors(scfs_int, scf, ENC); - sns_interpolate_scalefactors(scfs_bg, scf, DEC); + sns_compute_scf( whitenend_noise_shape, psychParams, L_frame, scf ); + sns_interpolate_scalefactors( scfs_int, scf, ENC ); + sns_interpolate_scalefactors( scfs_bg, scf, DEC ); scfs_for_shaping = &scfs_int[0]; } else /* whitening_mode == ON_FIRST_GOOD_FRAME */ @@ -3212,14 +3217,14 @@ void TonalMdctConceal_whiten_noise_shape( scfs_for_shaping = &scfs_bg[0]; } - if (sum_f(scfs_for_shaping, FDNS_NPTS) > 0.0f) + if ( sum_f( scfs_for_shaping, FDNS_NPTS ) > 0.0f ) { - sns_shape_spectrum(whitenend_noise_shape, psychParams, scfs_for_shaping, L_frame); - mvr2r(whitenend_noise_shape + start_idx, hFdCngCom->cngNoiseLevel_flt, stop_idx - start_idx); + sns_shape_spectrum( whitenend_noise_shape, psychParams, scfs_for_shaping, L_frame ); + mvr2r( whitenend_noise_shape + start_idx, hFdCngCom->cngNoiseLevel_flt, stop_idx - start_idx ); } else { - set_zero(hFdCngCom->cngNoiseLevel_flt, stop_idx - start_idx); + set_zero( hFdCngCom->cngNoiseLevel_flt, stop_idx - start_idx ); } pop_wmops(); diff --git a/lib_dec/transition_dec_fx.c b/lib_dec/transition_dec_fx.c index b932044ab..7cd782036 100644 --- a/lib_dec/transition_dec_fx.c +++ b/lib_dec/transition_dec_fx.c @@ -2,18 +2,17 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ #include "stl.h" /*----------------------------------------------------------------------* - * Local function prototypes - *----------------------------------------------------------------------*/ -static void tc_dec_fx( Decoder_State *st_fx, const Word16 L_frame,Word16 exc[], Word16 *T0,Word16 *T0_frac, const Word16 i_subfr, - const Word16 tc_subfr, Word16 *position, Word16 bwe_exc[], Word16 *Q_exc ); + * Local function prototypes + *----------------------------------------------------------------------*/ +static void tc_dec_fx( Decoder_State *st_fx, const Word16 L_frame, Word16 exc[], Word16 *T0, Word16 *T0_frac, const Word16 i_subfr, const Word16 tc_subfr, Word16 *position, Word16 bwe_exc[], Word16 *Q_exc ); /*======================================================================*/ /* FUNCTION : transition_dec_fx() */ /*----------------------------------------------------------------------*/ @@ -38,31 +37,31 @@ static void tc_dec_fx( Decoder_State *st_fx, const Word16 L_frame,Word16 exc[], void transition_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 tc_subfr, /* i : TC subframe index */ - Word16 *Jopt_flag, /* i : joint optimization flag */ - Word16 *exc, /* o : excitation signal */ - Word16 *T0, /* o : close loop integer pitch */ - Word16 *T0_frac, /* o : close loop fractional part of the pitch */ - Word16 *T0_min, /* i/o: delta search min for sf 2 & 4 */ - Word16 *T0_max, /* i/o: delta search max for sf 2 & 4 */ - Word16 **pt_pitch, /* o : floating pitch values */ - Word16 *position, /* i/o: first glottal impulse position in frame */ - Word16 *bwe_exc, /* o : excitation for SWB TBE */ - Word16 *Q_exc /*i/o : scaling of excitation */ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const Word16 L_frame, /* i : length of the frame */ + const Word16 i_subfr, /* i : subframe index */ + const Word16 tc_subfr, /* i : TC subframe index */ + Word16 *Jopt_flag, /* i : joint optimization flag */ + Word16 *exc, /* o : excitation signal */ + Word16 *T0, /* o : close loop integer pitch */ + Word16 *T0_frac, /* o : close loop fractional part of the pitch */ + Word16 *T0_min, /* i/o: delta search min for sf 2 & 4 */ + Word16 *T0_max, /* i/o: delta search max for sf 2 & 4 */ + Word16 **pt_pitch, /* o : floating pitch values */ + Word16 *position, /* i/o: first glottal impulse position in frame */ + Word16 *bwe_exc, /* o : excitation for SWB TBE */ + Word16 *Q_exc /*i/o : scaling of excitation */ ) { Word16 pit_flag, pit_start, pit_limit, index, nBits; - Word16 i, offset,temp,tmp; + Word16 i, offset, temp, tmp; Word16 limit_flag; Word16 i_subfridx; #ifdef REMOVE_IVAS_UNUSED_PARAMETERS_WARNING - (void)(Opt_AMR_WB); + (void) ( Opt_AMR_WB ); #endif - i_subfridx = shr(i_subfr, 6); /*i_subfr / L_SUBFR*/ + i_subfridx = shr( i_subfr, 6 ); /*i_subfr / L_SUBFR*/ /* Set limit_flag to 0 for restrained limits, and 1 for extended limits */ limit_flag = 0; @@ -70,17 +69,17 @@ void transition_dec_fx( * zero adaptive contribution (glottal shape codebook search not * in first subframe(s) ) *---------------------------------------------------------------------*/ - IF(GT_16(tc_subfr, add(i_subfr,TC_0_192))) + IF( GT_16( tc_subfr, add( i_subfr, TC_0_192 ) ) ) { - set16_fx(&exc[i_subfr], 0, L_SUBFR); + set16_fx( &exc[i_subfr], 0, L_SUBFR ); - IF( EQ_16(L_frame,L_FRAME)) + IF( EQ_16( L_frame, L_FRAME ) ) { - set16_fx(&bwe_exc[i_subfr*HIBND_ACB_L_FAC], 0, (Word16) (L_SUBFR*HIBND_ACB_L_FAC)); /* set past excitation buffer to 0 */ + set16_fx( &bwe_exc[i_subfr * HIBND_ACB_L_FAC], 0, (Word16) ( L_SUBFR * HIBND_ACB_L_FAC ) ); /* set past excitation buffer to 0 */ } ELSE { - set16_fx(&bwe_exc[i_subfr*2], 0, (Word16) (L_SUBFR*2)); /* set past excitation buffer to 0 */ + set16_fx( &bwe_exc[i_subfr * 2], 0, (Word16) ( L_SUBFR * 2 ) ); /* set past excitation buffer to 0 */ } *T0 = L_SUBFR; @@ -95,22 +94,22 @@ void transition_dec_fx( * glottal shape codebook search *---------------------------------------------------------------------*/ - ELSE IF(((GE_16(tc_subfr,i_subfr))&&(LE_16(sub(tc_subfr,i_subfr),TC_0_192)))) + ELSE IF( ( ( GE_16( tc_subfr, i_subfr ) ) && ( LE_16( sub( tc_subfr, i_subfr ), TC_0_192 ) ) ) ) { - set16_fx( exc-L_EXC_MEM, 0, L_EXC_MEM ); /* set past excitation buffer to 0 */ + set16_fx( exc - L_EXC_MEM, 0, L_EXC_MEM ); /* set past excitation buffer to 0 */ - IF( EQ_16(L_frame,L_FRAME)) + IF( EQ_16( L_frame, L_FRAME ) ) { - set16_fx( bwe_exc-PIT_MAX*HIBND_ACB_L_FAC, 0, PIT_MAX*HIBND_ACB_L_FAC); /* set past excitation buffer to 0 */ + set16_fx( bwe_exc - PIT_MAX * HIBND_ACB_L_FAC, 0, PIT_MAX * HIBND_ACB_L_FAC ); /* set past excitation buffer to 0 */ } ELSE { - set16_fx( bwe_exc-PIT16k_MAX*2, 0, PIT16k_MAX*2); /* set past excitation buffer to 0 */ + set16_fx( bwe_exc - PIT16k_MAX * 2, 0, PIT16k_MAX * 2 ); /* set past excitation buffer to 0 */ } /* glottal shape codebook contribution construction */ tc_dec_fx( st_fx, L_frame, exc, T0, T0_frac, i_subfr, tc_subfr, position, bwe_exc, Q_exc ); - **pt_pitch = shl(add(shl(*T0,2),*T0_frac),4); + **pt_pitch = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); move16(); /* save subframe pitch values Q6 */ *Jopt_flag = 1; @@ -125,14 +124,14 @@ void transition_dec_fx( * construction and the pitch period coding is used) *---------------------------------------------------------------------*/ - ELSE IF ( LT_16(tc_subfr,i_subfr)) + ELSE IF( LT_16( tc_subfr, i_subfr ) ) { - IF( EQ_16(L_frame,L_FRAME)) + IF( EQ_16( L_frame, L_FRAME ) ) { *Jopt_flag = 1; move16(); test(); - IF( (GE_16(sub(i_subfr,tc_subfr),L_SUBFR))&&(LE_16(sub(i_subfr,tc_subfr),L_SUBFR+TC_0_192))) + IF( ( GE_16( sub( i_subfr, tc_subfr ), L_SUBFR ) ) && ( LE_16( sub( i_subfr, tc_subfr ), L_SUBFR + TC_0_192 ) ) ) { pit_flag = 0; move16(); @@ -142,9 +141,9 @@ void transition_dec_fx( pit_flag = L_SUBFR; move16(); } - IF( EQ_16(tc_subfr,TC_0_0)) + IF( EQ_16( tc_subfr, TC_0_0 ) ) { - IF( EQ_16(i_subfr,L_SUBFR)) + IF( EQ_16( i_subfr, L_SUBFR ) ) { limit_T0_fx( L_FRAME, 8, pit_flag, limit_flag, *T0, 0, T0_min, T0_max ); } @@ -167,14 +166,14 @@ void transition_dec_fx( test(); test(); test(); - IF( (EQ_16(i_subfr,L_SUBFR))&&(GE_16(tc_subfr,TC_0_128))) + IF( ( EQ_16( i_subfr, L_SUBFR ) ) && ( GE_16( tc_subfr, TC_0_128 ) ) ) { /*--------------------------------------------------------* * second glottal impulse is in the 3rd or 4th subframe * - build exc[] in 2nd subframe *--------------------------------------------------------*/ - *T0 = 2*L_SUBFR; + *T0 = 2 * L_SUBFR; move16(); *T0_frac = 0; move16(); @@ -182,11 +181,10 @@ void transition_dec_fx( move16(); /* set adaptive part of exciation for curent subframe to 0 */ - set16_fx( &exc[i_subfr], 0, (Word16)(L_SUBFR+1) ); - set16_fx( &bwe_exc[i_subfr*HIBND_ACB_L_FAC], 0, (Word16)(L_SUBFR*HIBND_ACB_L_FAC) ); - + set16_fx( &exc[i_subfr], 0, (Word16) ( L_SUBFR + 1 ) ); + set16_fx( &bwe_exc[i_subfr * HIBND_ACB_L_FAC], 0, (Word16) ( L_SUBFR * HIBND_ACB_L_FAC ) ); } - ELSE IF( (EQ_16(i_subfr,L_SUBFR))&&(EQ_16(tc_subfr,TC_0_64))) + ELSE IF( ( EQ_16( i_subfr, L_SUBFR ) ) && ( EQ_16( tc_subfr, TC_0_64 ) ) ) { /*--------------------------------------------------------* * second glottal impulse is in the 2nd subframe, @@ -194,39 +192,38 @@ void transition_dec_fx( *--------------------------------------------------------*/ pit_start = PIT_MIN; move16(); - if (GT_16(PIT_MIN,(*position))) + if ( GT_16( PIT_MIN, ( *position ) ) ) { - pit_start = sub(L_SUBFR, *position); + pit_start = sub( L_SUBFR, *position ); } - pit_start = s_max(pit_start, PIT_MIN ); - pit_limit = add(shl(pit_start,1), *position); + pit_start = s_max( pit_start, PIT_MIN ); + pit_limit = add( shl( pit_start, 1 ), *position ); /* 7 bit pitch DECODER */ - index = (Word16)get_next_indice( st_fx, nBits ); + index = (Word16) get_next_indice( st_fx, nBits ); - *T0 = add(pit_start, shr((index),1)); + *T0 = add( pit_start, shr( ( index ), 1 ) ); move16(); - *T0_frac = shl(sub((index),shl(sub(*T0, pit_start),1)),1); + *T0_frac = shl( sub( ( index ), shl( sub( *T0, pit_start ), 1 ) ), 1 ); move16(); - limit_T0_fx( L_FRAME, 8, pit_flag, limit_flag, *T0, 0, T0_min, T0_max ); /* find T0_min and T0_max */ + limit_T0_fx( L_FRAME, 8, pit_flag, limit_flag, *T0, 0, T0_min, T0_max ); /* find T0_min and T0_max */ /* Find the adaptive codebook vector - ACELP long-term prediction */ - pred_lt4(&exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_SUBFR+1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP); - offset = tbe_celp_exc_offset(*T0, *T0_frac, L_frame); + pred_lt4( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + offset = tbe_celp_exc_offset( *T0, *T0_frac, L_frame ); move16(); - move16(); /* penality for 2 ptrs initialization */ + move16(); /* penality for 2 ptrs initialization */ - FOR (i=0; iBER_detect ); /* Find the adaptive codebook vector */ - pred_lt4(&exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_SUBFR+1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP); - offset = tbe_celp_exc_offset(*T0, *T0_frac, L_frame); + pred_lt4( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + offset = tbe_celp_exc_offset( *T0, *T0_frac, L_frame ); move16(); - move16(); /* penality for 2 ptrs initialization */ - FOR (i=0; iacelp_cfg.ltf_mode, exc); + lp_filt_exc_dec_fx( st_fx, MODE1, i_subfr, L_SUBFR, L_frame, st_fx->acelp_cfg.ltf_mode, exc ); } /*---------------------------------------------------------------------* * fill the pitch buffer - needed for post-processing and FEC_clas_estim() *---------------------------------------------------------------------*/ - **pt_pitch = shl(add(shl(*T0,2),*T0_frac),4); - move16(); /* save subframe pitch values Q6 */ + **pt_pitch = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); + move16(); /* save subframe pitch values Q6 */ test(); test(); test(); test(); test(); - IF( (GE_16(tc_subfr,2*L_SUBFR))&&(EQ_16(i_subfr,3*L_SUBFR))) + IF( ( GE_16( tc_subfr, 2 * L_SUBFR ) ) && ( EQ_16( i_subfr, 3 * L_SUBFR ) ) ) { - tmp = shl(add(shl(*T0,2),*T0_frac),4); - (*pt_pitch) -= 3; + tmp = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); + ( *pt_pitch ) -= 3; move16(); **pt_pitch = tmp; move16(); /*Q6*/ - (*pt_pitch)++; + ( *pt_pitch )++; **pt_pitch = tmp; move16(); /*Q6*/ - (*pt_pitch) ++; + ( *pt_pitch )++; move16(); **pt_pitch = tmp; move16(); /*Q6*/ - (*pt_pitch) ++; + ( *pt_pitch )++; move16(); } - ELSE IF( (EQ_16(tc_subfr,L_SUBFR))&&(EQ_16(i_subfr,2*L_SUBFR))) + ELSE IF( ( EQ_16( tc_subfr, L_SUBFR ) ) && ( EQ_16( i_subfr, 2 * L_SUBFR ) ) ) { - tmp = shl(add(shl(*T0,2),*T0_frac),4); - (*pt_pitch) -= 2; + tmp = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); + ( *pt_pitch ) -= 2; move16(); **pt_pitch = tmp; move16(); /*Q6*/ - (*pt_pitch)++; + ( *pt_pitch )++; **pt_pitch = tmp; move16(); /*Q6*/ - (*pt_pitch) ++; + ( *pt_pitch )++; move16(); - } - ELSE IF( (EQ_16(tc_subfr,TC_0_64))&&(EQ_16(i_subfr,L_SUBFR))) + ELSE IF( ( EQ_16( tc_subfr, TC_0_64 ) ) && ( EQ_16( i_subfr, L_SUBFR ) ) ) { - tmp = shl(add(shl(*T0,2),*T0_frac),4); - (*pt_pitch) -= 1; + tmp = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); + ( *pt_pitch ) -= 1; move16(); **pt_pitch = tmp; move16(); /*Q6*/ - (*pt_pitch)++; + ( *pt_pitch )++; } - ELSE IF( (EQ_16(tc_subfr,TC_0_128))&&(EQ_16(i_subfr,2*L_SUBFR))) + ELSE IF( ( EQ_16( tc_subfr, TC_0_128 ) ) && ( EQ_16( i_subfr, 2 * L_SUBFR ) ) ) { - tmp = shl(add(shl(*T0,2),*T0_frac),4); - (*pt_pitch) -= 2; + tmp = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); + ( *pt_pitch ) -= 2; move16(); **pt_pitch = tmp; move16(); /*Q6*/ - (*pt_pitch)++; + ( *pt_pitch )++; **pt_pitch = tmp; move16(); /*Q6*/ - (*pt_pitch) ++; + ( *pt_pitch )++; move16(); } - ELSE IF( (EQ_16(tc_subfr,TC_0_192))&&(EQ_16(i_subfr,3*L_SUBFR))) + ELSE IF( ( EQ_16( tc_subfr, TC_0_192 ) ) && ( EQ_16( i_subfr, 3 * L_SUBFR ) ) ) { - tmp = shl(add(shl(*T0,2),*T0_frac),4); - (*pt_pitch) -= 3; + tmp = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); + ( *pt_pitch ) -= 3; move16(); **pt_pitch = tmp; move16(); /*Q6*/ - (*pt_pitch)++; + ( *pt_pitch )++; **pt_pitch = tmp; move16(); /*Q6*/ - (*pt_pitch) ++; + ( *pt_pitch )++; move16(); **pt_pitch = tmp; move16(); /*Q6*/ - (*pt_pitch) ++; + ( *pt_pitch )++; move16(); } } - ELSE /* L_frame == L_FRAME16k */ + ELSE /* L_frame == L_FRAME16k */ { test(); - if( GE_16(i_subfr,2*L_SUBFR)) + if ( GE_16( i_subfr, 2 * L_SUBFR ) ) { limit_flag = 1; move16(); } - IF( EQ_16(sub(i_subfr, tc_subfr), L_SUBFR)) + IF( EQ_16( sub( i_subfr, tc_subfr ), L_SUBFR ) ) { limit_T0_fx( L_FRAME16k, 8, 0, limit_flag, *T0, *T0_frac, T0_min, T0_max ); } @@ -484,17 +473,17 @@ void transition_dec_fx( nBits = st_fx->acelp_cfg.pitch_bits[i_subfridx]; move16(); - index = (Word16)get_next_indice( st_fx, nBits ); + index = (Word16) get_next_indice( st_fx, nBits ); /*-----------------------------------------------------------------* * Find adaptive part of excitation, encode pitch period *-----------------------------------------------------------------*/ - IF( EQ_16(nBits,10)) + IF( EQ_16( nBits, 10 ) ) { pit16k_Q_dec_fx( index, nBits, limit_flag, T0, T0_frac, T0_min, T0_max, &st_fx->BER_detect ); } - ELSE IF( EQ_16(nBits,8)) /* tc_subfr==0 && i_subfr==L_SUBFR */ + ELSE IF( EQ_16( nBits, 8 ) ) /* tc_subfr==0 && i_subfr==L_SUBFR */ { /*-----------------------------------------------------------------------------* * The pitch range is encoded absolutely with 8 bits and is divided as follows: @@ -502,28 +491,28 @@ void transition_dec_fx( * PIT16k_FR2_TC0_2SUBFR to 2*L_SUBFR resolution 1/2 (frac = 0 or 2) *-----------------------------------------------------------------------------*/ - IF( LT_16(index,(PIT16k_FR2_TC0_2SUBFR-PIT16k_MIN)*4))/*(PIT16k_FR2_TC0_2SUBFR-PIT16k_MIN)*4*/ + IF( LT_16( index, ( PIT16k_FR2_TC0_2SUBFR - PIT16k_MIN ) * 4 ) ) /*(PIT16k_FR2_TC0_2SUBFR-PIT16k_MIN)*4*/ { - *T0 = add(PIT16k_MIN,shr(index,2)); + *T0 = add( PIT16k_MIN, shr( index, 2 ) ); move16(); - temp = shl(sub(*T0,PIT16k_MIN),2); + temp = shl( sub( *T0, PIT16k_MIN ), 2 ); move16(); - *T0_frac = sub(index,temp); + *T0_frac = sub( index, temp ); move16(); } ELSE { - index = sub(index,(PIT16k_FR2_TC0_2SUBFR-PIT16k_MIN)*4); /* (PIT16k_FR2_TC0_2SUBFR-PIT16k_MIN)*4 */ - *T0 = add(PIT16k_FR2_TC0_2SUBFR,shr(index,1)); + index = sub( index, ( PIT16k_FR2_TC0_2SUBFR - PIT16k_MIN ) * 4 ); /* (PIT16k_FR2_TC0_2SUBFR-PIT16k_MIN)*4 */ + *T0 = add( PIT16k_FR2_TC0_2SUBFR, shr( index, 1 ) ); move16(); - temp = shl(sub(*T0,PIT16k_FR2_TC0_2SUBFR),1); + temp = shl( sub( *T0, PIT16k_FR2_TC0_2SUBFR ), 1 ); move16(); - *T0_frac = shl(sub(index,temp),1); + *T0_frac = shl( sub( index, temp ), 1 ); move16(); } /* biterror detection mechanism */ - IF( GT_16(add((*T0<<2),*T0_frac),((2*L_SUBFR)<<2))) + IF( GT_16( add( ( *T0 << 2 ), *T0_frac ), ( ( 2 * L_SUBFR ) << 2 ) ) ) { *T0 = L_SUBFR; move16(); @@ -533,13 +522,13 @@ void transition_dec_fx( move16(); } } - ELSE IF( EQ_16(nBits,6)) + ELSE IF( EQ_16( nBits, 6 ) ) { delta_pit_dec_fx( 4, index, T0, T0_frac, *T0_min ); } - IF( EQ_16(nBits,6)) + IF( EQ_16( nBits, 6 ) ) { - limit_T0_fx( L_FRAME16k, 8, L_SUBFR, limit_flag, *T0, *T0_frac, T0_min, T0_max ); /* find T0_min and T0_max */ + limit_T0_fx( L_FRAME16k, 8, L_SUBFR, limit_flag, *T0, *T0_frac, T0_min, T0_max ); /* find T0_min and T0_max */ } /*-----------------------------------------------------------------* @@ -547,21 +536,21 @@ void transition_dec_fx( * - LP filtering of the adaptive excitation (if non-zero) *-----------------------------------------------------------------*/ test(); - IF( (EQ_16(i_subfr,L_SUBFR))&&(EQ_16(*T0,2*L_SUBFR))) + IF( ( EQ_16( i_subfr, L_SUBFR ) ) && ( EQ_16( *T0, 2 * L_SUBFR ) ) ) { /* no adaptive excitation in the second subframe */ - set16_fx( &exc[i_subfr], 0, L_SUBFR+1 ); - get_next_indice( st_fx, 1 ); /* this bit is actually not needed */ + set16_fx( &exc[i_subfr], 0, L_SUBFR + 1 ); + get_next_indice( st_fx, 1 ); /* this bit is actually not needed */ set16_fx( &bwe_exc[i_subfr * 2], 0, L_SUBFR * 2 ); } ELSE { /* Find the adaptive codebook vector - ACELP long-term prediction */ - pred_lt4(&exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_SUBFR+1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP); - offset = tbe_celp_exc_offset(*T0, *T0_frac, L_frame); + pred_lt4( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + offset = tbe_celp_exc_offset( *T0, *T0_frac, L_frame ); move16(); - move16(); /* penalty for 2 ptrs initialization */ - FOR (i=0; iacelp_cfg.pitch_bits[shr(i_subfr,6)]; + nBits = st_fx->acelp_cfg.pitch_bits[shr( i_subfr, 6 )]; move16(); /*----------------------------------------------------------------* * decode parameter T0 (pitch period) *----------------------------------------------------------------*/ - IF( EQ_16(L_frame,L_FRAME)) + IF( EQ_16( L_frame, L_FRAME ) ) { test(); test(); test(); test(); test(); - IF ( ((i_subfr == 0) && ((tc_subfr == 0) || (EQ_16(tc_subfr,TC_0_64))||(EQ_16(tc_subfr,TC_0_128))||(EQ_16(tc_subfr,TC_0_192))))||(EQ_16(tc_subfr,L_SUBFR))) + IF( ( ( i_subfr == 0 ) && ( ( tc_subfr == 0 ) || ( EQ_16( tc_subfr, TC_0_64 ) ) || ( EQ_16( tc_subfr, TC_0_128 ) ) || ( EQ_16( tc_subfr, TC_0_192 ) ) ) ) || ( EQ_16( tc_subfr, L_SUBFR ) ) ) { *T0 = L_SUBFR; move16(); *T0_frac = 0; move16(); } - ELSE IF( (tc_subfr == 3*L_SUBFR) ) + ELSE IF( ( tc_subfr == 3 * L_SUBFR ) ) { - i = (Word16)get_next_indice( st_fx, nBits ); + i = (Word16) get_next_indice( st_fx, nBits ); - IF( EQ_16(nBits,9)) + IF( EQ_16( nBits, 9 ) ) { abs_pit_dec_fx( 4, i, 0, T0, T0_frac ); } @@ -687,7 +676,7 @@ static void tc_dec_fx( } ELSE { - i = (Word16)get_next_indice( st_fx, nBits ); + i = (Word16) get_next_indice( st_fx, nBits ); move16(); IF( i == 0 ) @@ -699,46 +688,46 @@ static void tc_dec_fx( } ELSE { - IF( EQ_16(tc_subfr,TC_0_0)) + IF( EQ_16( tc_subfr, TC_0_0 ) ) { - delta_pit_dec_fx( 2, i, T0, T0_frac, PIT_MIN-1 ); + delta_pit_dec_fx( 2, i, T0, T0_frac, PIT_MIN - 1 ); } ELSE { - delta_pit_dec_fx( 0, i, T0, T0_frac, PIT_MIN-1 ); + delta_pit_dec_fx( 0, i, T0, T0_frac, PIT_MIN - 1 ); } } } } - ELSE /* L_frame == L_FRAME16k */ + ELSE /* L_frame == L_FRAME16k */ { - i = (Word16)get_next_indice( st_fx, nBits ); + i = (Word16) get_next_indice( st_fx, nBits ); move16(); - IF( EQ_16(nBits,10)) + IF( EQ_16( nBits, 10 ) ) { - IF( LT_16(i,(PIT16k_FR2_EXTEND_10b-PIT16k_MIN_EXTEND)*4)) + IF( LT_16( i, ( PIT16k_FR2_EXTEND_10b - PIT16k_MIN_EXTEND ) * 4 ) ) { - *T0 = add(PIT16k_MIN_EXTEND,shr(i,2)); + *T0 = add( PIT16k_MIN_EXTEND, shr( i, 2 ) ); move16(); - temp = shl(sub(*T0,PIT16k_MIN_EXTEND),2); - *T0_frac = sub(i,temp); + temp = shl( sub( *T0, PIT16k_MIN_EXTEND ), 2 ); + *T0_frac = sub( i, temp ); move16(); } ELSE { - index = sub(i,shl(sub(PIT16k_FR2_EXTEND_10b,PIT16k_MIN_EXTEND),2)); - *T0 = add(PIT16k_FR2_EXTEND_10b,shr(index,1)); - *T0_frac = sub(index ,shl(sub(*T0,PIT16k_FR2_EXTEND_10b),1)); - (*T0_frac) = shl(*T0_frac,1); + index = sub( i, shl( sub( PIT16k_FR2_EXTEND_10b, PIT16k_MIN_EXTEND ), 2 ) ); + *T0 = add( PIT16k_FR2_EXTEND_10b, shr( index, 1 ) ); + *T0_frac = sub( index, shl( sub( *T0, PIT16k_FR2_EXTEND_10b ), 1 ) ); + ( *T0_frac ) = shl( *T0_frac, 1 ); } } - ELSE IF( EQ_16(nBits,6)) + ELSE IF( EQ_16( nBits, 6 ) ) { - *T0 = add(PIT16k_MIN ,shr(i,1)); + *T0 = add( PIT16k_MIN, shr( i, 1 ) ); move16(); - *T0_frac = sub(i,shl(sub(*T0,PIT16k_MIN),1)); - *T0_frac = shl(*T0_frac,1); + *T0_frac = sub( i, shl( sub( *T0, PIT16k_MIN ), 1 ) ); + *T0_frac = shl( *T0_frac, 1 ); move16(); } } @@ -747,26 +736,26 @@ static void tc_dec_fx( * decode other TC parameters *----------------------------------------------------------------*/ - imp_shape = (Word16)get_next_indice( st_fx, 3 ); + imp_shape = (Word16) get_next_indice( st_fx, 3 ); move16(); - imp_pos = (Word16)get_next_indice( st_fx, 6 ); + imp_pos = (Word16) get_next_indice( st_fx, 6 ); move16(); - imp_sign = (Word16)get_next_indice( st_fx, 1 ); + imp_sign = (Word16) get_next_indice( st_fx, 1 ); move16(); - imp_gain = (Word16)get_next_indice( st_fx, 3 ); + imp_gain = (Word16) get_next_indice( st_fx, 3 ); move16(); /*----------------------------------------------------------------* - * - restore gain_trans - * - build glottal codebook contribution - *----------------------------------------------------------------*/ + * - restore gain_trans + * - build glottal codebook contribution + *----------------------------------------------------------------*/ gain_trans = tbl_gain_trans_tc_fx[imp_gain]; move16(); test(); - if( imp_sign == 0 ) + if ( imp_sign == 0 ) { - gain_trans = negate(gain_trans); + gain_trans = negate( gain_trans ); } /* local max for scaling need */ @@ -775,38 +764,38 @@ static void tc_dec_fx( tempS = 4; move16(); test(); - if (LE_16(imp_gain, 3)) + if ( LE_16( imp_gain, 3 ) ) { tempS = 7; move16(); } /* build glottal codebook contribution */ - sc = add(13-15, tempS); /* scaling of curent exc */ - sc = sub(*Q_exc, sc); + sc = add( 13 - 15, tempS ); /* scaling of curent exc */ + sc = sub( *Q_exc, sc ); - pt_shape = &Glottal_cdbk_fx[add(sub(i_mult2(imp_shape, L_IMPULSE), imp_pos), L_IMPULSE2)]; + pt_shape = &Glottal_cdbk_fx[add( sub( i_mult2( imp_shape, L_IMPULSE ), imp_pos ), L_IMPULSE2 )]; move16(); - j = s_max(0, sub(imp_pos, L_IMPULSE2)); - move16(); /* penalty for exc + i_subfr initialisation */ - FOR (i = 0; i < j; i++) + j = s_max( 0, sub( imp_pos, L_IMPULSE2 ) ); + move16(); /* penalty for exc + i_subfr initialisation */ + FOR( i = 0; i < j; i++ ) { - exc[i+i_subfr] = 0; + exc[i + i_subfr] = 0; move16(); } - j = s_min(L_SUBFR, add(imp_pos, L_IMPULSE2)); - FOR (; i <= j; i++) + j = s_min( L_SUBFR, add( imp_pos, L_IMPULSE2 ) ); + FOR( ; i <= j; i++ ) { #ifdef BASOP_NOGLOB - exc[i+i_subfr] = round_fx_o(L_shl_o(L_mult_o(pt_shape[i], gain_trans, &Overflow), sc, &Overflow), &Overflow); /* (Qx * Q14 ) */ + exc[i + i_subfr] = round_fx_o( L_shl_o( L_mult_o( pt_shape[i], gain_trans, &Overflow ), sc, &Overflow ), &Overflow ); /* (Qx * Q14 ) */ #else - exc[i+i_subfr] = round_fx(L_shl(L_mult(pt_shape[i], gain_trans), sc)); /* (Qx * Q14 ) */ + exc[i + i_subfr] = round_fx( L_shl( L_mult( pt_shape[i], gain_trans ), sc ) ); /* (Qx * Q14 ) */ #endif } - FOR (; i < L_SUBFR; i++) + FOR( ; i < L_SUBFR; i++ ) { - exc[i+i_subfr] = 0; + exc[i + i_subfr] = 0; move16(); } @@ -816,20 +805,18 @@ static void tc_dec_fx( *--------------------------------------------------------------*/ pred_lt4_tc_fx( exc, *T0, *T0_frac, inter4_2_fx, imp_pos, i_subfr ); - IF (st_fx->hBWE_TD != NULL) - { - IF(EQ_16(L_frame, L_FRAME)) - { - interp_code_5over2_fx(&exc[i_subfr], &bwe_exc[i_subfr * HIBND_ACB_L_FAC], L_SUBFR); - } - ELSE - { - interp_code_4over2_fx(&exc[i_subfr], &bwe_exc[i_subfr * 2], L_SUBFR); - } - } - *position = add(imp_pos, i_subfr); - move16(); - return; + IF( st_fx->hBWE_TD != NULL ){ + IF( EQ_16( L_frame, L_FRAME ) ){ + interp_code_5over2_fx( &exc[i_subfr], &bwe_exc[i_subfr * HIBND_ACB_L_FAC], L_SUBFR ); +} +ELSE +{ + interp_code_4over2_fx( &exc[i_subfr], &bwe_exc[i_subfr * 2], L_SUBFR ); +} +} +*position = add( imp_pos, i_subfr ); +move16(); +return; } /*-------------------------------------------------------------------* @@ -839,15 +826,15 @@ static void tc_dec_fx( *-------------------------------------------------------------------*/ Word16 tc_classif_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 L_frame /* i : length of the frame */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 L_frame /* i : length of the frame */ ) { Word16 tc_subfr, indice; #ifdef REMOVE_IVAS_UNUSED_PARAMETERS_WARNING - (void)(L_frame); + (void) ( L_frame ); #endif - IF( EQ_16(st_fx->L_frame, L_FRAME)) + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { if ( get_next_indice( st_fx, 1 ) ) { @@ -856,12 +843,12 @@ Word16 tc_classif_fx( } ELSE { - IF ( get_next_indice( st_fx, 1 ) ) + IF( get_next_indice( st_fx, 1 ) ) { tc_subfr = 0; move16(); - IF ( get_next_indice( st_fx, 1 ) ) + IF( get_next_indice( st_fx, 1 ) ) { tc_subfr = TC_0_192; move16(); @@ -879,43 +866,43 @@ Word16 tc_classif_fx( } ELSE { - IF ( get_next_indice( st_fx, 1 ) ) + IF( get_next_indice( st_fx, 1 ) ) { tc_subfr = L_SUBFR; move16(); } ELSE { - tc_subfr = 3*L_SUBFR; + tc_subfr = 3 * L_SUBFR; move16(); if ( get_next_indice( st_fx, 1 ) ) { - tc_subfr = 2*L_SUBFR; + tc_subfr = 2 * L_SUBFR; move16(); } } } } } - ELSE /* L_frame == L_FRAME16k */ + ELSE /* L_frame == L_FRAME16k */ { indice = (Word16) get_next_indice( st_fx, 2 ); - IF( LT_16(indice,3)) + IF( LT_16( indice, 3 ) ) { - tc_subfr = shl(indice, 6); + tc_subfr = shl( indice, 6 ); } ELSE { - tc_subfr = 4*L_SUBFR; + tc_subfr = 4 * L_SUBFR; move16(); - if( get_next_indice( st_fx, 1 ) == 0 ) + if ( get_next_indice( st_fx, 1 ) == 0 ) { - tc_subfr = 3*L_SUBFR; + tc_subfr = 3 * L_SUBFR; move16(); } } } - return( tc_subfr ); + return ( tc_subfr ); } diff --git a/lib_dec/updt_dec_fx.c b/lib_dec/updt_dec_fx.c index 9749f039a..1f018a243 100644 --- a/lib_dec/updt_dec_fx.c +++ b/lib_dec/updt_dec_fx.c @@ -5,10 +5,10 @@ #include #include #include "options.h" -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ /*-------------------------------------------------------------------* * updt_dec() @@ -16,16 +16,16 @@ * Common updates (all frame types) *-------------------------------------------------------------------*/ void updt_dec_fx( - Decoder_State *st_fx, /* i/o: state structure */ - const Word16 *old_exc_fx, /* i : buffer of excitation */ - const Word16 *pitch_buf_fx, /* i : floating pitch values for each subframe */ - const Word16 Es_pred, /* i : predicited scaled innovation energy */ - const Word16 *Aq, /* i : A(z) quantized for all subframes */ - const Word16 *lsf_new_fx, /* i : current frame LSF vector */ - const Word16 *lsp_new_fx, /* i : current frame LSP vector */ - const Word16 voice_factors[], /* i : voicing factors */ - const Word16 *old_bwe_exc_fx, /* i : buffer of excitation */ - const Word16 *gain_buf /* i : floating pitch gain for each subframe Q14*/ + Decoder_State *st_fx, /* i/o: state structure */ + const Word16 *old_exc_fx, /* i : buffer of excitation */ + const Word16 *pitch_buf_fx, /* i : floating pitch values for each subframe */ + const Word16 Es_pred, /* i : predicited scaled innovation energy */ + const Word16 *Aq, /* i : A(z) quantized for all subframes */ + const Word16 *lsf_new_fx, /* i : current frame LSF vector */ + const Word16 *lsp_new_fx, /* i : current frame LSP vector */ + const Word16 voice_factors[], /* i : voicing factors */ + const Word16 *old_bwe_exc_fx, /* i : buffer of excitation */ + const Word16 *gain_buf /* i : floating pitch gain for each subframe Q14*/ ) { Word16 i, len; @@ -36,7 +36,7 @@ void updt_dec_fx( /* update old excitation buffer */ Copy( &old_exc_fx[st_fx->L_frame], st_fx->old_exc_fx, L_EXC_MEM_DEC ); - IF( !st_fx->Opt_AMR_WB && hBWE_TD != NULL) + IF( !st_fx->Opt_AMR_WB && hBWE_TD != NULL ) { Copy( &old_bwe_exc_fx[L_FRAME32k], hBWE_TD->old_bwe_exc_fx, PIT16k_MAX * 2 ); } @@ -50,26 +50,26 @@ void updt_dec_fx( test(); test(); test(); - if( EQ_16(st_fx->coder_type,INACTIVE) || (EQ_16(st_fx->bpf_off,1) && NE_16(st_fx->coder_type,AUDIO) && NE_16(st_fx->coder_type,TRANSITION))) + if ( EQ_16( st_fx->coder_type, INACTIVE ) || ( EQ_16( st_fx->bpf_off, 1 ) && NE_16( st_fx->coder_type, AUDIO ) && NE_16( st_fx->coder_type, TRANSITION ) ) ) { st_fx->last_coder_type = UNVOICED; move16(); } test(); test(); - IF (st_fx->hGSCDec != NULL ) + IF( st_fx->hGSCDec != NULL ) { - IF ((NE_16(st_fx->coder_type, AUDIO) || st_fx->Last_GSC_noisy_speech_flag != 0) && st_fx->hGSCDec->Last_GSC_pit_band_idx > 0) + IF( ( NE_16( st_fx->coder_type, AUDIO ) || st_fx->Last_GSC_noisy_speech_flag != 0 ) && st_fx->hGSCDec->Last_GSC_pit_band_idx > 0 ) { st_fx->hGSCDec->Last_GSC_pit_band_idx = 0; - move16(); /*The temporal contribution of the GSC is meaningless after 1 frame lost for inactive & unvoiced content */ + move16(); /*The temporal contribution of the GSC is meaningless after 1 frame lost for inactive & unvoiced content */ } } /* this ensures that st_fx->last_coder_type is never set to INACTIVE in case of AVQ inactive because the FEC does not distinguish between GSC inactive and AVQ inactive */ test(); - if( GT_32(st_fx->total_brate,ACELP_24k40) && EQ_16(st_fx->coder_type,INACTIVE)) + if ( GT_32( st_fx->total_brate, ACELP_24k40 ) && EQ_16( st_fx->coder_type, INACTIVE ) ) { st_fx->last_coder_type = GENERIC; move16(); @@ -77,13 +77,13 @@ void updt_dec_fx( test(); test(); test(); - IF( EQ_16(st_fx->Opt_AMR_WB,1) && EQ_16(st_fx->coder_type,INACTIVE) && - NE_32(st_fx->core_brate,SID_1k75) && NE_32(st_fx->core_brate,FRAME_NO_DATA)) + IF( EQ_16( st_fx->Opt_AMR_WB, 1 ) && EQ_16( st_fx->coder_type, INACTIVE ) && + NE_32( st_fx->core_brate, SID_1k75 ) && NE_32( st_fx->core_brate, FRAME_NO_DATA ) ) { /* overwrite previous coding type to help FEC */ st_fx->last_coder_type = UNVOICED; move16(); - st_fx->last_voice_factor_fx = voice_factors[NB_SUBFR-1]; + st_fx->last_voice_factor_fx = voice_factors[NB_SUBFR - 1]; move16(); } @@ -91,26 +91,26 @@ void updt_dec_fx( { /* update voicing factor of TBE to help FEC */ - st_fx->last_voice_factor_fx = voice_factors[NB_SUBFR16k-1]; + st_fx->last_voice_factor_fx = voice_factors[NB_SUBFR16k - 1]; move16(); - if( EQ_16(st_fx->L_frame,L_FRAME)) + if ( EQ_16( st_fx->L_frame, L_FRAME ) ) { - st_fx->last_voice_factor_fx = voice_factors[NB_SUBFR-1]; + st_fx->last_voice_factor_fx = voice_factors[NB_SUBFR - 1]; move16(); } } test(); - IF(st_fx->hGSCDec != NULL && st_fx->coder_type != AUDIO && st_fx->coder_type != INACTIVE) + IF( st_fx->hGSCDec != NULL && st_fx->coder_type != AUDIO && st_fx->coder_type != INACTIVE ) { st_fx->hGSCDec->noise_lev = NOISE_LEVEL_SP3; move16(); - set16_fx(st_fx->hGSCDec->old_y_gain_fx, 0, MBANDS_GN); + set16_fx( st_fx->hGSCDec->old_y_gain_fx, 0, MBANDS_GN ); - FOR(i = 0; i < L_FRAME; i++) + FOR( i = 0; i < L_FRAME; i++ ) { Word16 tmp_seed = st_fx->hGSCDec->seed_tcx; move16(); - st_fx->hGSCDec->Last_GSC_spectrum_fx[i] = shr_r(Random(&tmp_seed), 5); + st_fx->hGSCDec->Last_GSC_spectrum_fx[i] = shr_r( Random( &tmp_seed ), 5 ); move16(); /*Q10*/ } } @@ -120,19 +120,19 @@ void updt_dec_fx( move16(); /* update counter for FEC pitch estimate */ - st_fx->upd_cnt = add(st_fx->upd_cnt,1); + st_fx->upd_cnt = add( st_fx->upd_cnt, 1 ); - st_fx->upd_cnt = s_min(st_fx->upd_cnt, MAX_UPD_CNT); + st_fx->upd_cnt = s_min( st_fx->upd_cnt, MAX_UPD_CNT ); - len = shr(st_fx->L_frame,6); + len = shr( st_fx->L_frame, 6 ); Copy32( &st_fx->old_pitch_buf_fx[len], st_fx->old_pitch_buf_fx, len ); - FOR ( i = 0; i < len; i++ ) + FOR( i = 0; i < len; i++ ) { - st_fx->old_pitch_buf_fx[len+i] = L_mult0(pitch_buf_fx[i], 1<<10); + st_fx->old_pitch_buf_fx[len + i] = L_mult0( pitch_buf_fx[i], 1 << 10 ); move32(); } - Copy( &st_fx->mem_pitch_gain[2], &st_fx->mem_pitch_gain[st_fx->L_frame/L_SUBFR+2], st_fx->L_frame/L_SUBFR ); - IF (EQ_16(st_fx->L_frame , L_FRAME)) + Copy( &st_fx->mem_pitch_gain[2], &st_fx->mem_pitch_gain[st_fx->L_frame / L_SUBFR + 2], st_fx->L_frame / L_SUBFR ); + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { st_fx->mem_pitch_gain[2] = gain_buf[3]; move16(); @@ -163,14 +163,14 @@ void updt_dec_fx( Copy( lsf_new_fx, st_fx->lsfoldbfi0_fx, M ); /* update of pitch and voicing information for HQ FEC */ - IF(hHQ_core != NULL) + IF( hHQ_core != NULL ) { - IF(NE_16(st_fx->last_core, HQ_CORE)) + IF( NE_16( st_fx->last_core, HQ_CORE ) ) { hHQ_core->HqVoicing = 1; move16(); test(); - if (!st_fx->Opt_AMR_WB && EQ_16(st_fx->coder_type, UNVOICED)) + if ( !st_fx->Opt_AMR_WB && EQ_16( st_fx->coder_type, UNVOICED ) ) { hHQ_core->HqVoicing = 0; move16(); @@ -189,7 +189,7 @@ void updt_dec_fx( move16(); /*core switching updates*/ - Copy( &Aq[(st_fx->L_frame/L_SUBFR-1)*(M+1)], st_fx->old_Aq_12_8_fx, M+1 ); + Copy( &Aq[( st_fx->L_frame / L_SUBFR - 1 ) * ( M + 1 )], st_fx->old_Aq_12_8_fx, M + 1 ); st_fx->old_Es_pred_fx = Es_pred; move16(); @@ -202,8 +202,8 @@ void updt_dec_fx( * Common updates for AMR-WB IO mode and EVS primary switching *-------------------------------------------------------------------*/ void updt_IO_switch_dec_fx( - const Word16 output_frame, /* i : output frame length */ - Decoder_State *st_fx /* o : Decoder static variables structure */ + const Word16 output_frame, /* i : output frame length */ + Decoder_State *st_fx /* o : Decoder static variables structure */ ) { Word16 xsp_tmp[M]; @@ -214,60 +214,59 @@ void updt_IO_switch_dec_fx( hBWE_TD = st_fx->hBWE_TD; hBWE_FD = st_fx->hBWE_FD; - IF( EQ_16(st_fx->last_core,AMR_WB_CORE)) /* switching to EVS primary mode */ + IF( EQ_16( st_fx->last_core, AMR_WB_CORE ) ) /* switching to EVS primary mode */ { /* AMR-WB IO mode uses ISF(ISP), but EVS primary mode mode LSF(LSP) */ Copy( stable_LSP_fx, xsp_tmp, M ); - isf2lsf_fx( st_fx->lsf_old_fx, st_fx->lsf_old_fx, xsp_tmp); + isf2lsf_fx( st_fx->lsf_old_fx, st_fx->lsf_old_fx, xsp_tmp ); Copy( stable_LSP_fx, xsp_tmp, M ); /*isp2lsp( st->lsp_old, st->lsp_old, xsp_tmp, M, grid100 );*/ - isp2lsp_fx( st_fx->lsp_old_fx, st_fx->lsp_old_fx, xsp_tmp, M); + isp2lsp_fx( st_fx->lsp_old_fx, st_fx->lsp_old_fx, xsp_tmp, M ); /* AMR-WB IO mode uses ISF(ISP), but EVS primary mode uses LSF(LSP) */ Copy( stable_LSP_fx, xsp_tmp, M ); /*isp2lsp( st->lspCNG, st->lspCNG, xsp_tmp, M, grid100 );*/ - isp2lsp_fx( st_fx->lspCNG_fx, st_fx->lspCNG_fx, xsp_tmp, M); - IF(st_fx->hTdCngDec != NULL) + isp2lsp_fx( st_fx->lspCNG_fx, st_fx->lspCNG_fx, xsp_tmp, M ); + IF( st_fx->hTdCngDec != NULL ) { - st_fx->hTdCngDec->old_enr_index = s_min(shl(st_fx->hTdCngDec->old_enr_index, 1), 127); + st_fx->hTdCngDec->old_enr_index = s_min( shl( st_fx->hTdCngDec->old_enr_index, 1 ), 127 ); } /* reset TD BWE buffers */ st_fx->last_voice_factor_fx = 0; - IF(hBWE_TD != NULL) + IF( hBWE_TD != NULL ) { - set16_fx(hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2); - set16_fx(hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET); + set16_fx( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); + set16_fx( hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); hBWE_TD->bwe_non_lin_prev_scale_fx = 0; move16(); move16(); - wb_tbe_extras_reset_fx(hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx); - wb_tbe_extras_reset_synth_fx(hBWE_TD->state_lsyn_filt_shb_fx, hBWE_TD->state_lsyn_filt_dwn_shb_fx, hBWE_TD->state_32and48k_WB_upsample_fx, hBWE_TD->mem_resamp_HB_fx); - IF( GE_16(output_frame,L_FRAME32k)) + wb_tbe_extras_reset_fx( hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx ); + wb_tbe_extras_reset_synth_fx( hBWE_TD->state_lsyn_filt_shb_fx, hBWE_TD->state_lsyn_filt_dwn_shb_fx, hBWE_TD->state_32and48k_WB_upsample_fx, hBWE_TD->mem_resamp_HB_fx ); + IF( GE_16( output_frame, L_FRAME32k ) ) { - swb_tbe_reset_fx(hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, - hBWE_TD->syn_overlap_fx, hBWE_TD->state_syn_shbexc_fx, &hBWE_TD->tbe_demph_fx, &hBWE_TD->tbe_premph_fx - , hBWE_TD->mem_stp_swb_fx,&(hBWE_TD->gain_prec_swb_fx) ); - set16_fx( st_fx->GainShape_Delay, 0, NUM_SHB_SUBFR/2 ); - hBWE_TD->prev_pow_exc16kWhtnd_fx32 = 1; /*Q0 1.f*/ - hBWE_TD->prev_mix_factor_fx = 32767; /*Q15 1.f*/ - swb_tbe_reset_synth_fx(hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx ); + swb_tbe_reset_fx( hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, + hBWE_TD->syn_overlap_fx, hBWE_TD->state_syn_shbexc_fx, &hBWE_TD->tbe_demph_fx, &hBWE_TD->tbe_premph_fx, hBWE_TD->mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ) ); + set16_fx( st_fx->GainShape_Delay, 0, NUM_SHB_SUBFR / 2 ); + hBWE_TD->prev_pow_exc16kWhtnd_fx32 = 1; /*Q0 1.f*/ + hBWE_TD->prev_mix_factor_fx = 32767; /*Q15 1.f*/ + swb_tbe_reset_synth_fx( hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx ); } - IF( EQ_16(output_frame,L_FRAME48k)) + IF( EQ_16( output_frame, L_FRAME48k ) ) { st_fx->prev_fb_ener_adjust_fx = 0; move16(); - set16_fx(hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); + set16_fx( hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); hBWE_TD->fb_tbe_demph_fx = 0; - fb_tbe_reset_synth_fx(hBWE_TD->fbbwe_hpf_mem_fx, hBWE_TD->fbbwe_hpf_mem_fx_Q,&hBWE_TD->prev_fbbwe_ratio_fx ); + fb_tbe_reset_synth_fx( hBWE_TD->fbbwe_hpf_mem_fx, hBWE_TD->fbbwe_hpf_mem_fx_Q, &hBWE_TD->prev_fbbwe_ratio_fx ); } - hBWE_FD->prev_Energy_wb_fx = L_deposit_l(0); + hBWE_FD->prev_Energy_wb_fx = L_deposit_l( 0 ); hBWE_FD->prev_weight_fx = 6554; } move16(); - IF(hBWE_FD != NULL) + IF( hBWE_FD != NULL ) { /* reset FD BWE buffers */ hBWE_FD->prev_mode = NORMAL; @@ -278,22 +277,22 @@ void updt_IO_switch_dec_fx( move16(); hBWE_FD->prev_frica_flag = 0; move16(); - set16_fx(hBWE_FD->mem_imdct_fx, 0, L_FRAME48k); + set16_fx( hBWE_FD->mem_imdct_fx, 0, L_FRAME48k ); hBWE_FD->prev_td_energy_fx = 0; move16(); - set16_fx(hBWE_FD->L_old_wtda_swb_fx, 0, L_FRAME48k); + set16_fx( hBWE_FD->L_old_wtda_swb_fx, 0, L_FRAME48k ); } /* HQ core buffers */ - set16_fx( st_fx->delay_buf_out_fx, 0, HQ_DELTA_MAX*HQ_DELAY_COMP ); + set16_fx( st_fx->delay_buf_out_fx, 0, HQ_DELTA_MAX * HQ_DELAY_COMP ); /* reset the unvoiced/audio signal improvement memories */ - IF(st_fx->hGSCDec != NULL) + IF( st_fx->hGSCDec != NULL ) { st_fx->hGSCDec->seed_tcx = 15687; } move16(); st_fx->hAmrwb_IO->UV_cnt_fx = 30; - st_fx->hAmrwb_IO->LT_UV_cnt_fx = (60<<6); + st_fx->hAmrwb_IO->LT_UV_cnt_fx = ( 60 << 6 ); move16(); move16(); @@ -306,7 +305,7 @@ void updt_IO_switch_dec_fx( move16(); move16(); move16(); - if (EQ_16(st_fx->last_flag_filter_NB, 1)) + if ( EQ_16( st_fx->last_flag_filter_NB, 1 ) ) { st_fx->cldfbSyn->bandsToZero = 0; } @@ -314,43 +313,44 @@ void updt_IO_switch_dec_fx( st_fx->perc_bwddec = 0; st_fx->last_flag_filter_NB = 0; st_fx->active_frame_cnt_bwddec = 0; - set16_fx(st_fx->flag_buffer, 0, 20); + set16_fx( st_fx->flag_buffer, 0, 20 ); } - ELSE /* switching to AMR-WB IO mode */ + ELSE /* switching to AMR-WB IO mode */ { /* ISF Q memories */ set16_fx( st_fx->mem_MA_fx, 0, M ); /* AMR-WB IO mode uses ISF(ISP), but EVS primary mode LSF(LSP) */ Copy( stable_ISP_fx, xsp_tmp, M ); - lsf2isf_fx( st_fx->lsf_old_fx, st_fx->lsf_old_fx, xsp_tmp, M); + lsf2isf_fx( st_fx->lsf_old_fx, st_fx->lsf_old_fx, xsp_tmp, M ); Copy( stable_ISP_fx, xsp_tmp, M ); - lsp2isp_fx( st_fx->lsp_old_fx, st_fx->lsp_old_fx, xsp_tmp, M); + lsp2isp_fx( st_fx->lsp_old_fx, st_fx->lsp_old_fx, xsp_tmp, M ); /* AMR-WB IO mode uses ISF(ISP), but EVS primary mode LSF(LSP) */ Copy( stable_ISP_fx, xsp_tmp, M ); - lsp2isp_fx( st_fx->lspCNG_fx, st_fx->lspCNG_fx, xsp_tmp, M); + lsp2isp_fx( st_fx->lspCNG_fx, st_fx->lspCNG_fx, xsp_tmp, M ); - IF(st_fx->hTdCngDec != NULL) + IF( st_fx->hTdCngDec != NULL ) { - st_fx->hTdCngDec->old_enr_index = s_max(s_min(shr(st_fx->hTdCngDec->old_enr_index, 1), 63), 0); + st_fx->hTdCngDec->old_enr_index = s_max( s_min( shr( st_fx->hTdCngDec->old_enr_index, 1 ), 63 ), 0 ); } - + /* HF synthesis memories */ - st_fx->Ng_ener_ST_fx = -51*256; /*Q8*/ move16(); + st_fx->Ng_ener_ST_fx = -51 * 256; /*Q8*/ + move16(); /* reset the unvoiced/audio signal improvement memories */ - IF(st_fx->hGSCDec != NULL) + IF( st_fx->hGSCDec != NULL ) { st_fx->hGSCDec->seed_tcx = 15687; } - Copy(st_fx->hAmrwb_IO->lt_diff_etot_fx, tmp_buf, MAX_LT); - amr_wb_dec_init_fx(st_fx->hAmrwb_IO); - Copy(tmp_buf, st_fx->hAmrwb_IO->lt_diff_etot_fx, MAX_LT); - hf_synth_amr_wb_reset_fx(st_fx->hBWE_zero, st_fx->hAmrwb_IO); + Copy( st_fx->hAmrwb_IO->lt_diff_etot_fx, tmp_buf, MAX_LT ); + amr_wb_dec_init_fx( st_fx->hAmrwb_IO ); + Copy( tmp_buf, st_fx->hAmrwb_IO->lt_diff_etot_fx, MAX_LT ); + hf_synth_amr_wb_reset_fx( st_fx->hBWE_zero, st_fx->hAmrwb_IO ); - st_fx->psf_lp_noise_fx = round_fx(L_shl(st_fx->lp_noise,1)); + st_fx->psf_lp_noise_fx = round_fx( L_shl( st_fx->lp_noise, 1 ) ); /* reset VBR signalling */ st_fx->last_ppp_mode_dec = 0; @@ -364,7 +364,7 @@ void updt_IO_switch_dec_fx( } /* CNG - reset */ - IF(st_fx->hTdCngDec != NULL) + IF( st_fx->hTdCngDec != NULL ) { st_fx->hTdCngDec->ho_hist_size = 0; } @@ -388,18 +388,17 @@ void updt_IO_switch_dec_fx( *-------------------------------------------------------------------*/ void updt_bw_switching_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 *synth, /* i : float synthesis signal */ - const Word16 Qpost -) + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 *synth, /* i : float synthesis signal */ + const Word16 Qpost ) { test(); - IF(st_fx->output_Fs == 32000 && st_fx->bwidth == SWB) + IF( st_fx->output_Fs == 32000 && st_fx->bwidth == SWB ) { #ifdef BASOP_NOGLOB - st_fx->tilt_swb_fx = round_fx_sat(L_shl_sat(calc_tilt_bwe_fx(synth, Qpost, L_FRAME32k), 3)); + st_fx->tilt_swb_fx = round_fx_sat( L_shl_sat( calc_tilt_bwe_fx( synth, Qpost, L_FRAME32k ), 3 ) ); #else - st_fx->tilt_swb_fx = round_fx(L_shl(calc_tilt_bwe_fx(synth, Qpost, L_FRAME32k), 3)); + st_fx->tilt_swb_fx = round_fx( L_shl( calc_tilt_bwe_fx( synth, Qpost, L_FRAME32k ), 3 ) ); #endif } @@ -410,12 +409,12 @@ void updt_bw_switching_fx( st_fx->last_bwidth = st_fx->bwidth; move32(); - IF( EQ_16(st_fx->core, ACELP_CORE)) + IF( EQ_16( st_fx->core, ACELP_CORE ) ) { st_fx->last_inner_frame = L_FRAME32k; move16(); test(); - if( EQ_16(st_fx->bwidth, WB)&&st_fx->bws_cnt==0) + if ( EQ_16( st_fx->bwidth, WB ) && st_fx->bws_cnt == 0 ) { st_fx->last_inner_frame = L_FRAME16k; move16(); @@ -426,7 +425,7 @@ void updt_bw_switching_fx( test(); test(); test(); - IF( !(GE_16(st_fx->last_inner_frame, L_FRAME16k)&&LE_16(inner_frame_tbl[st_fx->bwidth],L_FRAME16k)&&st_fx->bws_cnt>0&<_16(st_fx->bws_cnt,N_WS2N_FRAMES))) + IF( !( GE_16( st_fx->last_inner_frame, L_FRAME16k ) && LE_16( inner_frame_tbl[st_fx->bwidth], L_FRAME16k ) && st_fx->bws_cnt > 0 && LT_16( st_fx->bws_cnt, N_WS2N_FRAMES ) ) ) { st_fx->last_inner_frame = inner_frame_tbl[st_fx->bwidth]; move16(); @@ -444,11 +443,11 @@ void updt_bw_switching_fx( *-------------------------------------------------------------------*/ void updt_dec_common_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 hq_core_type_fx, /* i : HQ core type */ - const Word16 concealWholeFrameTmp, /* i : concealWholeFrameTmp flag */ - const Word16 *synth, /* i : decoded synthesis */ - const Word16 Qpostd /* i : Synthesis Q value */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 hq_core_type_fx, /* i : HQ core type */ + const Word16 concealWholeFrameTmp, /* i : concealWholeFrameTmp flag */ + const Word16 *synth, /* i : decoded synthesis */ + const Word16 Qpostd /* i : Synthesis Q value */ ) { @@ -468,7 +467,7 @@ void updt_dec_common_fx( st_fx->prev_old_bfi = st_fx->prev_bfi; st_fx->prev_bfi = st_fx->bfi; move16(); - if (NE_16(st_fx->core, AMR_WB_CORE)) + if ( NE_16( st_fx->core, AMR_WB_CORE ) ) { st_fx->old_bfi_cnt = st_fx->nbLostCmpt; move16(); @@ -479,21 +478,24 @@ void updt_dec_common_fx( st_fx->con_tcx = 0; move16(); - if(st_fx->hHQ_nbfec != NULL) + if ( st_fx->hHQ_nbfec != NULL ) { st_fx->hHQ_nbfec->prev_last_core = st_fx->last_core; } - if(st_fx->hTcxDec != NULL) + if ( st_fx->hTcxDec != NULL ) { hTcxDec->tcxConceal_recalc_exc = 0; move16(); } - test();test(); - IF( (GE_16(st_fx->rf_frame_type,RF_TCXFD) && LE_16(st_fx->rf_frame_type,RF_TCXTD2) && st_fx->use_partial_copy && st_fx->bfi) || !st_fx->bfi) + test(); + test(); + IF( ( GE_16( st_fx->rf_frame_type, RF_TCXFD ) && LE_16( st_fx->rf_frame_type, RF_TCXTD2 ) && st_fx->use_partial_copy && st_fx->bfi ) || !st_fx->bfi ) { - test();test(); - test(); test(); - if( st_fx->bfi && (LE_16(st_fx->last_good, UNVOICED_TRANSITION)) && (GT_16(st_fx->clas_dec,UNVOICED_TRANSITION)) && st_fx->last_con_tcx && st_fx->hTcxDec != NULL) + test(); + test(); + test(); + test(); + if ( st_fx->bfi && ( LE_16( st_fx->last_good, UNVOICED_TRANSITION ) ) && ( GT_16( st_fx->clas_dec, UNVOICED_TRANSITION ) ) && st_fx->last_con_tcx && st_fx->hTcxDec != NULL ) { hTcxDec->tcxConceal_recalc_exc = 1; move16(); @@ -501,7 +503,7 @@ void updt_dec_common_fx( st_fx->last_good = st_fx->clas_dec; move16(); } - IF (st_fx->use_partial_copy) + IF( st_fx->use_partial_copy ) { st_fx->prev_rf_frame_type = st_fx->rf_frame_type; } @@ -510,15 +512,15 @@ void updt_dec_common_fx( st_fx->prev_rf_frame_type = INACTIVE; } - if (EQ_16(st_fx->m_frame_type, ACTIVE_FRAME) && (st_fx->bfi!=1 || st_fx->use_partial_copy!=0)) + if ( EQ_16( st_fx->m_frame_type, ACTIVE_FRAME ) && ( st_fx->bfi != 1 || st_fx->use_partial_copy != 0 ) ) { st_fx->rf_flag_last = st_fx->rf_flag; } - IF( EQ_16(st_fx->codec_mode,MODE1)) + IF( EQ_16( st_fx->codec_mode, MODE1 ) ) { test(); - if( !st_fx->bfi && (st_fx->core_brate > SID_2k40 || (GT_32(st_fx->core_brate, SID_1k75) && EQ_16(st_fx->core, AMR_WB_CORE)))) + if ( !st_fx->bfi && ( st_fx->core_brate > SID_2k40 || ( GT_32( st_fx->core_brate, SID_1k75 ) && EQ_16( st_fx->core, AMR_WB_CORE ) ) ) ) { move16(); st_fx->last_active_brate = st_fx->total_brate; @@ -527,28 +529,28 @@ void updt_dec_common_fx( move16(); move16(); st_fx->last_core = st_fx->core; - if (st_fx->hHQ_core != NULL) + if ( st_fx->hHQ_core != NULL ) { st_fx->hHQ_core->last_hq_core_type = hq_core_type_fx; } } - ELSE IF( EQ_16(st_fx->codec_mode,MODE2)) + ELSE IF( EQ_16( st_fx->codec_mode, MODE2 ) ) { test(); - if ((!st_fx->bfi) && (st_fx->last_is_cng==0)) + if ( ( !st_fx->bfi ) && ( st_fx->last_is_cng == 0 ) ) { move16(); st_fx->last_active_brate = st_fx->total_brate; } /* INFO: moved from update_decoder_LPD_cng() */ - if (NE_16(st_fx->m_frame_type,ACTIVE_FRAME)) + if ( NE_16( st_fx->m_frame_type, ACTIVE_FRAME ) ) { move16(); st_fx->last_is_cng = 1; } - if (!st_fx->bfi) + if ( !st_fx->bfi ) { st_fx->last_core = st_fx->core; } @@ -561,38 +563,36 @@ void updt_dec_common_fx( /* save synthesis for core switching */ test(); - IF (EQ_16(st_fx->element_mode, EVS_MONO) && NE_16(st_fx->core, AMR_WB_CORE)) + IF( EQ_16( st_fx->element_mode, EVS_MONO ) && NE_16( st_fx->core, AMR_WB_CORE ) ) { - Copy_Scale_sig(synth + NS2SA_fx2(st_fx->output_Fs, ACELP_LOOK_NS + DELAY_BWE_TOTAL_NS), st_fx->old_synth_sw_fx, NS2SA_fx2(st_fx->output_Fs, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS), st_fx->hHQ_core->Q_old_postdec); + Copy_Scale_sig( synth + NS2SA_fx2( st_fx->output_Fs, ACELP_LOOK_NS + DELAY_BWE_TOTAL_NS ), st_fx->old_synth_sw_fx, NS2SA_fx2( st_fx->output_Fs, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS ), st_fx->hHQ_core->Q_old_postdec ); } test(); test(); test(); #ifdef IVAS_CODE /* Store long-term estimates of stab_fac and log energy diff to estimate env_stab in case of core switch ACELP/TCX->HQ */ - if (st->element_mode != EVS_MONO) + if ( st->element_mode != EVS_MONO ) { - output_frame = NS2SA(st->output_Fs, FRAME_SIZE_NS); - log_energy = log2f((sum2_f(synth, output_frame) / output_frame) + 1.0f); - log_energy_diff = fabsf(st->log_energy_old - log_energy); + output_frame = NS2SA( st->output_Fs, FRAME_SIZE_NS ); + log_energy = log2f( ( sum2_f( synth, output_frame ) / output_frame ) + 1.0f ); + log_energy_diff = fabsf( st->log_energy_old - log_energy ); st->log_energy_old = log_energy; - st->log_energy_diff_lt = ENV_SMOOTH_FAC * log_energy_diff + (1.0f - ENV_SMOOTH_FAC) * st->log_energy_diff_lt; - if (st->core == HQ_CORE) + st->log_energy_diff_lt = ENV_SMOOTH_FAC * log_energy_diff + ( 1.0f - ENV_SMOOTH_FAC ) * st->log_energy_diff_lt; + if ( st->core == HQ_CORE ) { - st->stab_fac = min(1, (STAB_FAC_EST1 + (STAB_FAC_EST2 * st->hHQ_core->mem_env_delta) + (STAB_FAC_EST3 * st->log_energy_diff_lt))); - st->stab_fac = max(0, st->stab_fac); + st->stab_fac = min( 1, ( STAB_FAC_EST1 + ( STAB_FAC_EST2 * st->hHQ_core->mem_env_delta ) + ( STAB_FAC_EST3 * st->log_energy_diff_lt ) ) ); + st->stab_fac = max( 0, st->stab_fac ); } - st->stab_fac_smooth_lt = ENV_SMOOTH_FAC * st->stab_fac + (1.0f - ENV_SMOOTH_FAC) * st->stab_fac_smooth_lt; + st->stab_fac_smooth_lt = ENV_SMOOTH_FAC * st->stab_fac + ( 1.0f - ENV_SMOOTH_FAC ) * st->stab_fac_smooth_lt; } #endif - IF( ((LE_32(st_fx->core_brate,SID_2k40))&&EQ_16(st_fx->cng_type,FD_CNG)) - || (st_fx->tcxonly && EQ_16(st_fx->codec_mode,MODE2)) - ) + IF( ( ( LE_32( st_fx->core_brate, SID_2k40 ) ) && EQ_16( st_fx->cng_type, FD_CNG ) ) || ( st_fx->tcxonly && EQ_16( st_fx->codec_mode, MODE2 ) ) ) { /* reset LP memories */ - set16_fx( st_fx->mem_MA_fx,0, M ); - IF( EQ_32(st_fx->sr_core,INT_FS_16k)) + set16_fx( st_fx->mem_MA_fx, 0, M ); + IF( EQ_32( st_fx->sr_core, INT_FS_16k ) ) { Copy( GEWB2_Ave_fx, st_fx->mem_AR_fx, M ); } @@ -601,10 +601,10 @@ void updt_dec_common_fx( Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M ); } } - IF(EQ_16(st_fx->codec_mode, MODE2)) + IF( EQ_16( st_fx->codec_mode, MODE2 ) ) { test(); - IF(EQ_16(st_fx->use_partial_copy, 1) && EQ_16(st_fx->rf_frame_type, RF_NELP)) + IF( EQ_16( st_fx->use_partial_copy, 1 ) && EQ_16( st_fx->rf_frame_type, RF_NELP ) ) { st_fx->last_nelp_mode_dec = 1; } @@ -623,41 +623,41 @@ void updt_dec_common_fx( st_fx->prev_Q_exc = st_fx->Q_exc; move16(); - L_tmp = L_mult(st_fx->tilt_code_dec_fx[0], 4096); - FOR(i = 1; i < NB_SUBFR; i++) + L_tmp = L_mult( st_fx->tilt_code_dec_fx[0], 4096 ); + FOR( i = 1; i < NB_SUBFR; i++ ) { - L_tmp = L_mac(L_tmp, st_fx->tilt_code_dec_fx[i], 4096); + L_tmp = L_mac( L_tmp, st_fx->tilt_code_dec_fx[i], 4096 ); } - st_fx->prev_tilt_code_dec_fx = round_fx(L_tmp); + st_fx->prev_tilt_code_dec_fx = round_fx( L_tmp ); - IF (EQ_16(st_fx->core, HQ_CORE)) + IF( EQ_16( st_fx->core, HQ_CORE ) ) { st_fx->prev_coder_type = GENERIC; } - ELSE IF (NE_16(st_fx->core, AMR_WB_CORE) ) + ELSE IF( NE_16( st_fx->core, AMR_WB_CORE ) ) { st_fx->prev_coder_type = st_fx->coder_type; } test(); - IF((GT_32(st_fx->core_brate, SID_2k40) || (GT_32(st_fx->core_brate, SID_1k75) && EQ_16(st_fx->core, AMR_WB_CORE))) && EQ_16(st_fx->first_CNG, 1) && st_fx->hTdCngDec != NULL) + IF( ( GT_32( st_fx->core_brate, SID_2k40 ) || ( GT_32( st_fx->core_brate, SID_1k75 ) && EQ_16( st_fx->core, AMR_WB_CORE ) ) ) && EQ_16( st_fx->first_CNG, 1 ) && st_fx->hTdCngDec != NULL ) { - if (GE_16(st_fx->hTdCngDec->act_cnt, BUF_DEC_RATE)) + if ( GE_16( st_fx->hTdCngDec->act_cnt, BUF_DEC_RATE ) ) { st_fx->hTdCngDec->act_cnt = 0; - move16(); + move16(); } - st_fx->hTdCngDec->act_cnt = add(st_fx->hTdCngDec->act_cnt, 1); + st_fx->hTdCngDec->act_cnt = add( st_fx->hTdCngDec->act_cnt, 1 ); test(); - if ((EQ_16(st_fx->hTdCngDec->act_cnt, BUF_DEC_RATE)) && (st_fx->hTdCngDec->ho_hist_size > 0)) + if ( ( EQ_16( st_fx->hTdCngDec->act_cnt, BUF_DEC_RATE ) ) && ( st_fx->hTdCngDec->ho_hist_size > 0 ) ) { - st_fx->hTdCngDec->ho_hist_size = sub(st_fx->hTdCngDec->ho_hist_size, 1); + st_fx->hTdCngDec->ho_hist_size = sub( st_fx->hTdCngDec->ho_hist_size, 1 ); } - st_fx->hTdCngDec->act_cnt2 = add(st_fx->hTdCngDec->act_cnt2, 1); - if (GE_16(st_fx->hTdCngDec->act_cnt2, MIN_ACT_CNG_UPD)) + st_fx->hTdCngDec->act_cnt2 = add( st_fx->hTdCngDec->act_cnt2, 1 ); + if ( GE_16( st_fx->hTdCngDec->act_cnt2, MIN_ACT_CNG_UPD ) ) { st_fx->hTdCngDec->act_cnt2 = MIN_ACT_CNG_UPD; move16(); @@ -666,41 +666,44 @@ void updt_dec_common_fx( test(); test(); - if (LE_32(st_fx->core_brate, SID_2k40) && st_fx->first_CNG == 0 && (EQ_16(st_fx->cng_type, LP_CNG) || EQ_16(st_fx->element_mode, IVAS_CPE_MDCT))) + if ( LE_32( st_fx->core_brate, SID_2k40 ) && st_fx->first_CNG == 0 && ( EQ_16( st_fx->cng_type, LP_CNG ) || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) { st_fx->first_CNG = 1; move16(); } /* update bandwidth switching parameters */ - test(); test(); + test(); + test(); st_fx->last_flag_cna = st_fx->flag_cna; move16(); - if (st_fx->hFdCngDec != NULL) + if ( st_fx->hFdCngDec != NULL ) { st_fx->hFdCngDec->hFdCngCom->frame_type_previous = st_fx->m_frame_type; move16(); } - if (GT_16(st_fx->element_mode, EVS_MONO)) + if ( GT_16( st_fx->element_mode, EVS_MONO ) ) { st_fx->m_old_frame_type = st_fx->m_frame_type; } /* update bandwidth switching parameters */ - IF ( EQ_16(st_fx->core, AMR_WB_CORE)) + IF( EQ_16( st_fx->core, AMR_WB_CORE ) ) { st_fx->last_bwidth = WB; st_fx->prev_bws_cnt = 0; st_fx->bws_cnt = 0; st_fx->bws_cnt1 = 0; - move16();move16();move16();move16(); - + move16(); + move16(); + move16(); + move16(); } - ELSE IF(EQ_16(st_fx->codec_mode, MODE1) && ((GT_32(st_fx->core_brate, SID_2k40)) || (EQ_16(st_fx->element_mode, EVS_MONO)))) + ELSE IF( EQ_16( st_fx->codec_mode, MODE1 ) && ( ( GT_32( st_fx->core_brate, SID_2k40 ) ) || ( EQ_16( st_fx->element_mode, EVS_MONO ) ) ) ) { - updt_bw_switching_fx(st_fx, synth, Qpostd); + updt_bw_switching_fx( st_fx, synth, Qpostd ); } ELSE { @@ -710,34 +713,37 @@ void updt_dec_common_fx( move16(); } - /* synchronisation of CNG seeds*/ + /* synchronisation of CNG seeds*/ test(); test(); - IF(st_fx->hTdCngDec != NULL && (st_fx->bfi || (NE_32(st_fx->core_brate, FRAME_NO_DATA) && NE_32(st_fx->core_brate, SID_2k40))) && NE_16(st_fx->core, AMR_WB_CORE)) + IF( st_fx->hTdCngDec != NULL && ( st_fx->bfi || ( NE_32( st_fx->core_brate, FRAME_NO_DATA ) && NE_32( st_fx->core_brate, SID_2k40 ) ) ) && NE_16( st_fx->core, AMR_WB_CORE ) ) { - Random(&(st_fx->hTdCngDec->cng_seed)); - Random(&(st_fx->hTdCngDec->cng_ener_seed)); + Random( &( st_fx->hTdCngDec->cng_seed ) ); + Random( &( st_fx->hTdCngDec->cng_ener_seed ) ); } - test();test();test(); - IF(st_fx->hTcxDec != NULL && st_fx->enablePlcWaveadjust && !concealWholeFrameTmp && NE_16(st_fx->core, AMR_WB_CORE)) + test(); + test(); + test(); + IF( st_fx->hTcxDec != NULL && st_fx->enablePlcWaveadjust && !concealWholeFrameTmp && NE_16( st_fx->core, AMR_WB_CORE ) ) { /* update the parameters used in waveform adjustment */ - concealment_update2_x((const Word16 *)synth, &st_fx->plcInfo, hTcxDec->L_frameTCX); + concealment_update2_x( (const Word16 *) synth, &st_fx->plcInfo, hTcxDec->L_frameTCX ); } st_fx->last_total_brate_ber = st_fx->total_brate; move32(); - if (st_fx->bfi == 0) + if ( st_fx->bfi == 0 ) { st_fx->last_total_brate = st_fx->total_brate; st_fx->last_bits_frame_nominal = st_fx->bits_frame_nominal; move32(); } - st_fx->last_low_rate_mode = st_fx->low_rate_mode; move16(); - if (LT_16(st_fx->ini_frame, MAX_FRAME_COUNTER)) + st_fx->last_low_rate_mode = st_fx->low_rate_mode; + move16(); + if ( LT_16( st_fx->ini_frame, MAX_FRAME_COUNTER ) ) { - st_fx->ini_frame = add(st_fx->ini_frame,1); + st_fx->ini_frame = add( st_fx->ini_frame, 1 ); } return; @@ -746,18 +752,17 @@ void updt_dec_common_fx( #ifdef IVAS_FLOAT_FIXED static void ivas_updt_bw_switching_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word32 *synth, /* i : float synthesis signal */ - const Word16 Qpost -) + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word32 *synth, /* i : float synthesis signal */ + const Word16 Qpost ) { test(); - IF(st_fx->output_Fs == 32000 && st_fx->bwidth == SWB) + IF( st_fx->output_Fs == 32000 && st_fx->bwidth == SWB ) { #ifdef BASOP_NOGLOB - st_fx->tilt_swb_fx = ivas_calc_tilt_bwe_fx(synth, Qpost, L_FRAME32k); + st_fx->tilt_swb_fx = ivas_calc_tilt_bwe_fx( synth, Qpost, L_FRAME32k ); #else - st_fx->tilt_swb_fx = round_fx(L_shl(calc_tilt_bwe_fx(synth, Qpost, L_FRAME32k), 3)); + st_fx->tilt_swb_fx = round_fx( L_shl( calc_tilt_bwe_fx( synth, Qpost, L_FRAME32k ), 3 ) ); #endif } @@ -768,12 +773,12 @@ static void ivas_updt_bw_switching_fx( st_fx->last_bwidth = st_fx->bwidth; move32(); - IF( EQ_16(st_fx->core, ACELP_CORE)) + IF( EQ_16( st_fx->core, ACELP_CORE ) ) { st_fx->last_inner_frame = L_FRAME32k; move16(); test(); - IF( EQ_16(st_fx->bwidth, WB) && EQ_16(st_fx->bws_cnt, 0)) + IF( EQ_16( st_fx->bwidth, WB ) && EQ_16( st_fx->bws_cnt, 0 ) ) { st_fx->last_inner_frame = L_FRAME16k; move16(); @@ -784,7 +789,7 @@ static void ivas_updt_bw_switching_fx( test(); test(); test(); - IF( !(GE_16(st_fx->last_inner_frame, L_FRAME16k)&&LE_16(inner_frame_tbl[st_fx->bwidth],L_FRAME16k)&&st_fx->bws_cnt>0&<_16(st_fx->bws_cnt,N_WS2N_FRAMES))) + IF( !( GE_16( st_fx->last_inner_frame, L_FRAME16k ) && LE_16( inner_frame_tbl[st_fx->bwidth], L_FRAME16k ) && st_fx->bws_cnt > 0 && LT_16( st_fx->bws_cnt, N_WS2N_FRAMES ) ) ) { st_fx->last_inner_frame = inner_frame_tbl[st_fx->bwidth]; move16(); @@ -795,23 +800,23 @@ static void ivas_updt_bw_switching_fx( return; } -static Word32 sum_32_32_fx(const Word32 *x, Word16 length) +static Word32 sum_32_32_fx( const Word32 *x, Word16 length ) { Word64 sum = 0; Word16 i; - FOR (i = 0; i < length; i++) + FOR( i = 0; i < length; i++ ) { - sum = W_add(sum, W_mult_32_32(x[i], x[i])); + sum = W_add( sum, W_mult_32_32( x[i], x[i] ) ); } - return W_round64_L(sum); + return W_round64_L( sum ); } void ivas_updt_dec_common_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 hq_core_type_fx, /* i : HQ core type */ - const Word16 concealWholeFrameTmp, /* i : concealWholeFrameTmp flag */ - const Word32 *synth, /* i : decoded synthesis */ - const Word16 Qpostd /* i : Synthesis Q value */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 hq_core_type_fx, /* i : HQ core type */ + const Word16 concealWholeFrameTmp, /* i : concealWholeFrameTmp flag */ + const Word32 *synth, /* i : decoded synthesis */ + const Word16 Qpostd /* i : Synthesis Q value */ ) { @@ -831,7 +836,7 @@ void ivas_updt_dec_common_fx( st_fx->prev_old_bfi = st_fx->prev_bfi; st_fx->prev_bfi = st_fx->bfi; move16(); - IF (NE_16(st_fx->core, AMR_WB_CORE)) + IF( NE_16( st_fx->core, AMR_WB_CORE ) ) { st_fx->old_bfi_cnt = st_fx->nbLostCmpt; move16(); @@ -842,31 +847,34 @@ void ivas_updt_dec_common_fx( st_fx->con_tcx = 0; move16(); - IF(st_fx->hHQ_nbfec != NULL) + IF( st_fx->hHQ_nbfec != NULL ) { - st_fx->hHQ_nbfec->prev_last_core = st_fx->last_core; + st_fx->hHQ_nbfec->prev_last_core = st_fx->last_core; } - IF(st_fx->hTcxDec != NULL) + IF( st_fx->hTcxDec != NULL ) { hTcxDec->tcxConceal_recalc_exc = 0; move16(); } - test();test(); - IF( (GE_16(st_fx->rf_frame_type,RF_TCXFD) && LE_16(st_fx->rf_frame_type,RF_TCXTD2) && st_fx->use_partial_copy && st_fx->bfi) || !st_fx->bfi) + test(); + test(); + IF( ( GE_16( st_fx->rf_frame_type, RF_TCXFD ) && LE_16( st_fx->rf_frame_type, RF_TCXTD2 ) && st_fx->use_partial_copy && st_fx->bfi ) || !st_fx->bfi ) { - test();test(); - test(); test(); - - IF( st_fx->bfi && (LE_16(st_fx->last_good, UNVOICED_TRANSITION)) && (GT_16(st_fx->clas_dec,UNVOICED_TRANSITION)) && st_fx->last_con_tcx && st_fx->hTcxDec != NULL) + test(); + test(); + test(); + test(); + + IF( st_fx->bfi && ( LE_16( st_fx->last_good, UNVOICED_TRANSITION ) ) && ( GT_16( st_fx->clas_dec, UNVOICED_TRANSITION ) ) && st_fx->last_con_tcx && st_fx->hTcxDec != NULL ) { hTcxDec->tcxConceal_recalc_exc = 1; move16(); } - st_fx->last_good = st_fx->clas_dec; + st_fx->last_good = st_fx->clas_dec; move16(); } - IF (st_fx->use_partial_copy) + IF( st_fx->use_partial_copy ) { st_fx->prev_rf_frame_type = st_fx->rf_frame_type; } @@ -875,15 +883,15 @@ void ivas_updt_dec_common_fx( st_fx->prev_rf_frame_type = INACTIVE; } - IF (EQ_16(st_fx->m_frame_type, ACTIVE_FRAME) && (st_fx->bfi!=0 || st_fx->use_partial_copy!=0)) + IF( EQ_16( st_fx->m_frame_type, ACTIVE_FRAME ) && ( st_fx->bfi != 0 || st_fx->use_partial_copy != 0 ) ) { st_fx->rf_flag_last = st_fx->rf_flag; } - IF( EQ_16(st_fx->codec_mode,MODE1)) + IF( EQ_16( st_fx->codec_mode, MODE1 ) ) { test(); - IF( !st_fx->bfi && (st_fx->core_brate > SID_2k40 || (GT_32(st_fx->core_brate, SID_1k75) && EQ_16(st_fx->core, AMR_WB_CORE)))) + IF( !st_fx->bfi && ( st_fx->core_brate > SID_2k40 || ( GT_32( st_fx->core_brate, SID_1k75 ) && EQ_16( st_fx->core, AMR_WB_CORE ) ) ) ) { move16(); st_fx->last_active_brate = st_fx->total_brate; @@ -896,28 +904,28 @@ void ivas_updt_dec_common_fx( st_fx->last_core = st_fx->core; } st_fx->last_core_bfi = st_fx->core; /* also required for clean channel decoding */ - if (st_fx->hHQ_core != NULL) + if ( st_fx->hHQ_core != NULL ) { - st_fx->hHQ_core->last_hq_core_type = hq_core_type_fx; + st_fx->hHQ_core->last_hq_core_type = hq_core_type_fx; } } - ELSE IF( EQ_16(st_fx->codec_mode,MODE2)) + ELSE IF( EQ_16( st_fx->codec_mode, MODE2 ) ) { test(); - IF ((!st_fx->bfi) && (st_fx->last_is_cng==0)) + IF( ( !st_fx->bfi ) && ( st_fx->last_is_cng == 0 ) ) { move16(); st_fx->last_active_brate = st_fx->total_brate; } /* INFO: moved from update_decoder_LPD_cng() */ - IF (NE_16(st_fx->m_frame_type,ACTIVE_FRAME)) + IF( NE_16( st_fx->m_frame_type, ACTIVE_FRAME ) ) { move16(); st_fx->last_is_cng = 1; } - IF (!st_fx->bfi) + IF( !st_fx->bfi ) { st_fx->last_core = st_fx->core; } @@ -930,60 +938,57 @@ void ivas_updt_dec_common_fx( /* save synthesis for core switching */ test(); - IF (EQ_16(st_fx->element_mode, EVS_MONO) && NE_16(st_fx->core, AMR_WB_CORE)) + IF( EQ_16( st_fx->element_mode, EVS_MONO ) && NE_16( st_fx->core, AMR_WB_CORE ) ) { - Copy_Scale_sig_32_16(synth + NS2SA_fx2(st_fx->output_Fs, ACELP_LOOK_NS + DELAY_BWE_TOTAL_NS), st_fx->old_synth_sw_fx, NS2SA_fx2(st_fx->output_Fs, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS), st_fx->hHQ_core->Q_old_postdec); + Copy_Scale_sig_32_16( synth + NS2SA_fx2( st_fx->output_Fs, ACELP_LOOK_NS + DELAY_BWE_TOTAL_NS ), st_fx->old_synth_sw_fx, NS2SA_fx2( st_fx->output_Fs, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS ), st_fx->hHQ_core->Q_old_postdec ); } test(); test(); test(); #ifdef IVAS_CODE /* Store long-term estimates of stab_fac and log energy diff to estimate env_stab in case of core switch ACELP/TCX->HQ */ - if (st->element_mode != EVS_MONO) + if ( st->element_mode != EVS_MONO ) { - output_frame = NS2SA(st->output_Fs, FRAME_SIZE_NS); - log_energy = log2f((sum2_f(synth, output_frame) / output_frame) + 1.0f); - log_energy_diff = fabsf(st->log_energy_old - log_energy); + output_frame = NS2SA( st->output_Fs, FRAME_SIZE_NS ); + log_energy = log2f( ( sum2_f( synth, output_frame ) / output_frame ) + 1.0f ); + log_energy_diff = fabsf( st->log_energy_old - log_energy ); st->log_energy_old = log_energy; - st->log_energy_diff_lt = ENV_SMOOTH_FAC * log_energy_diff + (1.0f - ENV_SMOOTH_FAC) * st->log_energy_diff_lt; - if (st->core == HQ_CORE) + st->log_energy_diff_lt = ENV_SMOOTH_FAC * log_energy_diff + ( 1.0f - ENV_SMOOTH_FAC ) * st->log_energy_diff_lt; + if ( st->core == HQ_CORE ) { - st->stab_fac = min(1, (STAB_FAC_EST1 + (STAB_FAC_EST2 * st->hHQ_core->mem_env_delta) + (STAB_FAC_EST3 * st->log_energy_diff_lt))); - st->stab_fac = max(0, st->stab_fac); + st->stab_fac = min( 1, ( STAB_FAC_EST1 + ( STAB_FAC_EST2 * st->hHQ_core->mem_env_delta ) + ( STAB_FAC_EST3 * st->log_energy_diff_lt ) ) ); + st->stab_fac = max( 0, st->stab_fac ); } - st->stab_fac_smooth_lt = ENV_SMOOTH_FAC * st->stab_fac + (1.0f - ENV_SMOOTH_FAC) * st->stab_fac_smooth_lt; + st->stab_fac_smooth_lt = ENV_SMOOTH_FAC * st->stab_fac + ( 1.0f - ENV_SMOOTH_FAC ) * st->stab_fac_smooth_lt; } #else - if (st_fx->element_mode != EVS_MONO) - { - Word16 q_div = sub(Q31, shl(Qpostd, 1)); - Word16 output_frame = NS2SA(st_fx->output_Fs, FRAME_SIZE_NS); - Word32 sum_val = sum_32_32_fx(synth, output_frame); - Word32 div_val = BASOP_Util_Divide3232_Scale(sum_val, output_frame, &q_div); - Word32 log_energy = L_add(L_shl(L_deposit_l(add(q_div, sub(Q31, shl(Qpostd, 1)))), Q15) , - L_shr(BASOP_Util_Log2(L_shl(L_add(div_val, EPSILON_FX), Q16)), Q10)); - Word32 log_energy_diff = L_abs(L_sub(st_fx->log_energy_old_fx , log_energy)); + if ( st_fx->element_mode != EVS_MONO ) + { + Word16 q_div = sub( Q31, shl( Qpostd, 1 ) ); + Word16 output_frame = NS2SA( st_fx->output_Fs, FRAME_SIZE_NS ); + Word32 sum_val = sum_32_32_fx( synth, output_frame ); + Word32 div_val = BASOP_Util_Divide3232_Scale( sum_val, output_frame, &q_div ); + Word32 log_energy = L_add( L_shl( L_deposit_l( add( q_div, sub( Q31, shl( Qpostd, 1 ) ) ) ), Q15 ), + L_shr( BASOP_Util_Log2( L_shl( L_add( div_val, EPSILON_FX ), Q16 ) ), Q10 ) ); + Word32 log_energy_diff = L_abs( L_sub( st_fx->log_energy_old_fx, log_energy ) ); st_fx->log_energy_old_fx = log_energy; - st_fx->log_energy_diff_lt_fx = Madd_32_16(Mpy_32_16_1(log_energy_diff, ENV_SMOOTH_FAC_FX ), st_fx->log_energy_diff_lt_fx, sub(MAX_16 , ENV_SMOOTH_FAC_FX)); + st_fx->log_energy_diff_lt_fx = Madd_32_16( Mpy_32_16_1( log_energy_diff, ENV_SMOOTH_FAC_FX ), st_fx->log_energy_diff_lt_fx, sub( MAX_16, ENV_SMOOTH_FAC_FX ) ); - if (st_fx->core == HQ_CORE) + if ( st_fx->core == HQ_CORE ) { - st_fx->stab_fac_fx = extract_l(L_min(MAX_16, L_add(L_shr(STAB_FAC_EST1_FX, Q15), Madd_32_32(L_shr(Mpy_32_16_1(STAB_FAC_EST2_FX , st_fx->hHQ_core->mem_env_delta), Q15), STAB_FAC_EST3_FX, st_fx->log_energy_diff_lt_fx)))); - st_fx->stab_fac_fx = s_max(0, st_fx->stab_fac_fx); + st_fx->stab_fac_fx = extract_l( L_min( MAX_16, L_add( L_shr( STAB_FAC_EST1_FX, Q15 ), Madd_32_32( L_shr( Mpy_32_16_1( STAB_FAC_EST2_FX, st_fx->hHQ_core->mem_env_delta ), Q15 ), STAB_FAC_EST3_FX, st_fx->log_energy_diff_lt_fx ) ) ) ); + st_fx->stab_fac_fx = s_max( 0, st_fx->stab_fac_fx ); } - st_fx->stab_fac_smooth_lt_fx = extract_h(L_add(L_mult(ENV_SMOOTH_FAC_FX , st_fx->stab_fac_fx), - L_mult(sub(MAX_16, ENV_SMOOTH_FAC_FX) , st_fx->stab_fac_smooth_lt_fx))); - + st_fx->stab_fac_smooth_lt_fx = extract_h( L_add( L_mult( ENV_SMOOTH_FAC_FX, st_fx->stab_fac_fx ), + L_mult( sub( MAX_16, ENV_SMOOTH_FAC_FX ), st_fx->stab_fac_smooth_lt_fx ) ) ); } #endif - IF( ((LE_32(st_fx->core_brate,SID_2k40))&&EQ_16(st_fx->cng_type,FD_CNG)) - || (st_fx->tcxonly && EQ_16(st_fx->codec_mode,MODE2)) - ) + IF( ( ( LE_32( st_fx->core_brate, SID_2k40 ) ) && EQ_16( st_fx->cng_type, FD_CNG ) ) || ( st_fx->tcxonly && EQ_16( st_fx->codec_mode, MODE2 ) ) ) { /* reset LP memories */ - set16_fx( st_fx->mem_MA_fx,0, M ); - IF( EQ_32(st_fx->sr_core,INT_FS_16k)) + set16_fx( st_fx->mem_MA_fx, 0, M ); + IF( EQ_32( st_fx->sr_core, INT_FS_16k ) ) { Copy( GEWB2_Ave_fx, st_fx->mem_AR_fx, M ); } @@ -992,16 +997,16 @@ void ivas_updt_dec_common_fx( Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M ); } } - IF(EQ_16(st_fx->codec_mode, MODE2)) + IF( EQ_16( st_fx->codec_mode, MODE2 ) ) { test(); - IF(EQ_16(st_fx->use_partial_copy, 1) && EQ_16(st_fx->rf_frame_type, RF_NELP)) + IF( EQ_16( st_fx->use_partial_copy, 1 ) && EQ_16( st_fx->rf_frame_type, RF_NELP ) ) { - st_fx->last_nelp_mode_dec = 1; + st_fx->last_nelp_mode_dec = 1; } ELSE { - st_fx->last_nelp_mode_dec = 0; + st_fx->last_nelp_mode_dec = 0; } } @@ -1014,44 +1019,44 @@ void ivas_updt_dec_common_fx( st_fx->prev_Q_exc = st_fx->Q_exc; move16(); - L_tmp = L_mult(st_fx->tilt_code_dec_fx[0], 4096); - FOR(i = 1; i < NB_SUBFR; i++) + L_tmp = L_mult( st_fx->tilt_code_dec_fx[0], 4096 ); + FOR( i = 1; i < NB_SUBFR; i++ ) { - L_tmp = L_mac(L_tmp, st_fx->tilt_code_dec_fx[i], 4096); + L_tmp = L_mac( L_tmp, st_fx->tilt_code_dec_fx[i], 4096 ); } - st_fx->prev_tilt_code_dec_fx = round_fx(L_tmp); + st_fx->prev_tilt_code_dec_fx = round_fx( L_tmp ); - IF (EQ_16(st_fx->core, HQ_CORE)) + IF( EQ_16( st_fx->core, HQ_CORE ) ) { - st_fx->prev_coder_type = GENERIC; + st_fx->prev_coder_type = GENERIC; } - ELSE IF (NE_16(st_fx->core, AMR_WB_CORE) ) + ELSE IF( NE_16( st_fx->core, AMR_WB_CORE ) ) { - st_fx->prev_coder_type = st_fx->coder_type; + st_fx->prev_coder_type = st_fx->coder_type; } test(); - IF((GT_32(st_fx->core_brate, SID_2k40) || (GT_32(st_fx->core_brate, SID_1k75) && EQ_16(st_fx->core, AMR_WB_CORE))) && EQ_16(st_fx->first_CNG, 1) && st_fx->hTdCngDec != NULL) + IF( ( GT_32( st_fx->core_brate, SID_2k40 ) || ( GT_32( st_fx->core_brate, SID_1k75 ) && EQ_16( st_fx->core, AMR_WB_CORE ) ) ) && EQ_16( st_fx->first_CNG, 1 ) && st_fx->hTdCngDec != NULL ) { - - IF (GE_16(st_fx->hTdCngDec->act_cnt, BUF_DEC_RATE)) + + IF( GE_16( st_fx->hTdCngDec->act_cnt, BUF_DEC_RATE ) ) { - st_fx->hTdCngDec->act_cnt = 0; - move16(); + st_fx->hTdCngDec->act_cnt = 0; + move16(); } - st_fx->hTdCngDec->act_cnt = add(st_fx->hTdCngDec->act_cnt, 1); + st_fx->hTdCngDec->act_cnt = add( st_fx->hTdCngDec->act_cnt, 1 ); test(); - - IF ((EQ_16(st_fx->hTdCngDec->act_cnt, BUF_DEC_RATE)) && (st_fx->hTdCngDec->ho_hist_size > 0)) + + IF( ( EQ_16( st_fx->hTdCngDec->act_cnt, BUF_DEC_RATE ) ) && ( st_fx->hTdCngDec->ho_hist_size > 0 ) ) { - st_fx->hTdCngDec->ho_hist_size = sub(st_fx->hTdCngDec->ho_hist_size, 1); + st_fx->hTdCngDec->ho_hist_size = sub( st_fx->hTdCngDec->ho_hist_size, 1 ); } - //st_fx->hTdCngDec->act_cnt2 = add(st_fx->hTdCngDec->act_cnt2, 1); - - IF (GE_16(st_fx->hTdCngDec->act_cnt2, MIN_ACT_CNG_UPD)) + // st_fx->hTdCngDec->act_cnt2 = add(st_fx->hTdCngDec->act_cnt2, 1); + + IF( GE_16( st_fx->hTdCngDec->act_cnt2, MIN_ACT_CNG_UPD ) ) { st_fx->hTdCngDec->act_cnt2 = MIN_ACT_CNG_UPD; move16(); @@ -1060,41 +1065,44 @@ void ivas_updt_dec_common_fx( test(); test(); - if (LE_32(st_fx->core_brate, SID_2k40) && st_fx->first_CNG == 0 && (EQ_16(st_fx->cng_type, LP_CNG) || EQ_16(st_fx->element_mode, IVAS_CPE_MDCT))) + if ( LE_32( st_fx->core_brate, SID_2k40 ) && st_fx->first_CNG == 0 && ( EQ_16( st_fx->cng_type, LP_CNG ) || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) { st_fx->first_CNG = 1; move16(); } /* update bandwidth switching parameters */ - test(); test(); + test(); + test(); st_fx->last_flag_cna = st_fx->flag_cna; move16(); - if (st_fx->hFdCngDec != NULL) + if ( st_fx->hFdCngDec != NULL ) { st_fx->hFdCngDec->hFdCngCom->frame_type_previous = st_fx->m_frame_type; move16(); } - if (GT_16(st_fx->element_mode, EVS_MONO)) + if ( GT_16( st_fx->element_mode, EVS_MONO ) ) { st_fx->m_old_frame_type = st_fx->m_frame_type; } /* update bandwidth switching parameters */ - IF ( EQ_16(st_fx->core, AMR_WB_CORE)) + IF( EQ_16( st_fx->core, AMR_WB_CORE ) ) { st_fx->last_bwidth = WB; - st_fx->prev_bws_cnt = 0; - st_fx->bws_cnt = 0; - st_fx->bws_cnt1 = 0; - move16();move16();move16();move16(); - + st_fx->prev_bws_cnt = 0; + st_fx->bws_cnt = 0; + st_fx->bws_cnt1 = 0; + move16(); + move16(); + move16(); + move16(); } - ELSE IF(EQ_16(st_fx->codec_mode, MODE1) && ((GT_32(st_fx->core_brate, SID_2k40)) || (EQ_16(st_fx->element_mode, EVS_MONO)))) + ELSE IF( EQ_16( st_fx->codec_mode, MODE1 ) && ( ( GT_32( st_fx->core_brate, SID_2k40 ) ) || ( EQ_16( st_fx->element_mode, EVS_MONO ) ) ) ) { - ivas_updt_bw_switching_fx(st_fx, synth, Qpostd); + ivas_updt_bw_switching_fx( st_fx, synth, Qpostd ); } ELSE { @@ -1104,34 +1112,37 @@ void ivas_updt_dec_common_fx( move16(); } - /* synchronisation of CNG seeds*/ + /* synchronisation of CNG seeds*/ test(); test(); - IF(st_fx->hTdCngDec != NULL && (st_fx->bfi || (NE_32(st_fx->core_brate, FRAME_NO_DATA) && NE_32(st_fx->core_brate, SID_2k40))) && NE_16(st_fx->core, AMR_WB_CORE)) + IF( st_fx->hTdCngDec != NULL && ( st_fx->bfi || ( NE_32( st_fx->core_brate, FRAME_NO_DATA ) && NE_32( st_fx->core_brate, SID_2k40 ) ) ) && NE_16( st_fx->core, AMR_WB_CORE ) ) { - Random(&(st_fx->hTdCngDec->cng_seed)); - Random(&(st_fx->hTdCngDec->cng_ener_seed)); + Random( &( st_fx->hTdCngDec->cng_seed ) ); + Random( &( st_fx->hTdCngDec->cng_ener_seed ) ); } - test();test();test(); - IF(st_fx->hTcxDec != NULL && st_fx->enablePlcWaveadjust && !concealWholeFrameTmp && NE_16(st_fx->core, AMR_WB_CORE)) + test(); + test(); + test(); + IF( st_fx->hTcxDec != NULL && st_fx->enablePlcWaveadjust && !concealWholeFrameTmp && NE_16( st_fx->core, AMR_WB_CORE ) ) { /* update the parameters used in waveform adjustment */ - concealment_update2_x((const Word16 *)synth, &st_fx->plcInfo, hTcxDec->L_frameTCX); + concealment_update2_x( (const Word16 *) synth, &st_fx->plcInfo, hTcxDec->L_frameTCX ); } st_fx->last_total_brate_ber = st_fx->total_brate; move32(); - if (st_fx->bfi == 0) + if ( st_fx->bfi == 0 ) { st_fx->last_total_brate = st_fx->total_brate; st_fx->last_bits_frame_nominal = st_fx->bits_frame_nominal; move32(); } - st_fx->last_low_rate_mode = st_fx->low_rate_mode; move16(); - if (LT_16(st_fx->ini_frame, MAX_FRAME_COUNTER)) + st_fx->last_low_rate_mode = st_fx->low_rate_mode; + move16(); + if ( LT_16( st_fx->ini_frame, MAX_FRAME_COUNTER ) ) { - st_fx->ini_frame = add(st_fx->ini_frame,1); + st_fx->ini_frame = add( st_fx->ini_frame, 1 ); } return; @@ -1144,25 +1155,24 @@ void ivas_updt_dec_common_fx( * *--------------------------------------------------------------------*/ -void update_decoder_LPD_cng( - Decoder_State *st, - Word16 coder_type, - Word16 *timeDomainBuffer, - Word16 *A, - Word16 *bpf_noise_buf -) +void update_decoder_LPD_cng( + Decoder_State *st, + Word16 coder_type, + Word16 *timeDomainBuffer, + Word16 *A, + Word16 *bpf_noise_buf ) { Word16 i; Word16 lsp[M], lsf[M]; - Word16 *synth, synth_buf[M+1+L_FRAME_MAX+L_FRAME_MAX/2], tmp; - Word16 buf_synth[OLD_SYNTH_SIZE_DEC+L_FRAME_MAX+M]; + Word16 *synth, synth_buf[M + 1 + L_FRAME_MAX + L_FRAME_MAX / 2], tmp; + Word16 buf_synth[OLD_SYNTH_SIZE_DEC + L_FRAME_MAX + M]; Word16 pf_pitch[NB_SUBFR16k]; Word16 pf_gain[NB_SUBFR16k]; Word16 pitch[NB_SUBFR16k]; TCX_DEC_HANDLE hTcxDec; hTcxDec = st->hTcxDec; - synth = synth_buf + (1 + M); + synth = synth_buf + ( 1 + M ); /* LPC order */ move16(); @@ -1171,7 +1181,7 @@ void update_decoder_LPD_cng( E_LPC_a_lsp_conversion( A, lsp, st->lsp_old_fx, M ); /* LSP -> LSF */ - IF(EQ_16(st->L_frame, L_FRAME16k)) + IF( EQ_16( st->L_frame, L_FRAME16k ) ) { lsp2lsf_fx( lsp, lsf, M, INT_FS_16k_FX ); } @@ -1180,21 +1190,21 @@ void update_decoder_LPD_cng( E_LPC_lsp_lsf_conversion( lsp, lsf, M ); } - IF(hTcxDec != NULL) + IF( hTcxDec != NULL ) { - Copy(hTcxDec->old_synth, buf_synth, hTcxDec->old_synth_len); - Copy(timeDomainBuffer, buf_synth + hTcxDec->old_synth_len, st->L_frame); + Copy( hTcxDec->old_synth, buf_synth, hTcxDec->old_synth_len ); + Copy( timeDomainBuffer, buf_synth + hTcxDec->old_synth_len, st->L_frame ); /* Update synth memory */ move16(); - Copy(st->syn, synth_buf, 1 + M); - Copy(timeDomainBuffer, synth, st->L_frame); - Copy(synth + st->L_frame - (1 + M), st->syn, 1 + M); - Copy(hTcxDec->old_synth + st->L_frame, hTcxDec->old_synth, hTcxDec->old_synth_len - st->L_frame); - Copy(synth, hTcxDec->old_synth + hTcxDec->old_synth_len - st->L_frame, st->L_frame); - bufferCopyFx(synth + st->L_frame - (st->L_frame / 2), hTcxDec->old_syn_Overl, st->L_frame / 2, 0 /*Qf_syn*/, -1 /*Qf_old_xnq*/, 0, 0 /*Q_old_xnq*/); + Copy( st->syn, synth_buf, 1 + M ); + Copy( timeDomainBuffer, synth, st->L_frame ); + Copy( synth + st->L_frame - ( 1 + M ), st->syn, 1 + M ); + Copy( hTcxDec->old_synth + st->L_frame, hTcxDec->old_synth, hTcxDec->old_synth_len - st->L_frame ); + Copy( synth, hTcxDec->old_synth + hTcxDec->old_synth_len - st->L_frame, st->L_frame ); + bufferCopyFx( synth + st->L_frame - ( st->L_frame / 2 ), hTcxDec->old_syn_Overl, st->L_frame / 2, 0 /*Qf_syn*/, -1 /*Qf_old_xnq*/, 0, 0 /*Q_old_xnq*/ ); hTcxDec->tcxltp_last_gain_unmodified = 0; hTcxDec->envWeighted = 0; @@ -1202,22 +1212,22 @@ void update_decoder_LPD_cng( /* Update pe-synth memory */ move16(); - tmp = synth[-(1+M)]; + tmp = synth[-( 1 + M )]; - st->Q_syn = E_UTIL_f_preemph3( synth-M, st->preemph_fac, M+st->L_frame, &tmp, 1 ); + st->Q_syn = E_UTIL_f_preemph3( synth - M, st->preemph_fac, M + st->L_frame, &tmp, 1 ); st->prev_Q_syn = st->Q_syn = st->Q_syn - 1; - Copy( synth+st->L_frame-M, st->mem_syn2_fx, M ); - Copy( synth+st->L_frame-L_SYN_MEM, st->mem_syn_r, L_SYN_MEM ); + Copy( synth + st->L_frame - M, st->mem_syn2_fx, M ); + Copy( synth + st->L_frame - L_SYN_MEM, st->mem_syn_r, L_SYN_MEM ); /* Update excitation memory */ - assert(st->L_frame < L_EXC_MEM_DEC); - IF(NE_16(add(st->Q_syn,1),st->Q_exc)) + assert( st->L_frame < L_EXC_MEM_DEC ); + IF( NE_16( add( st->Q_syn, 1 ), st->Q_exc ) ) { - Scale_sig(st->old_exc_fx, L_EXC_MEM_DEC, sub(add(st->Q_syn,1),st->Q_exc)); + Scale_sig( st->old_exc_fx, L_EXC_MEM_DEC, sub( add( st->Q_syn, 1 ), st->Q_exc ) ); } st->Q_exc = st->Q_syn + 1; - Copy( st->old_exc_fx+st->L_frame, st->old_exc_fx, sub(L_EXC_MEM_DEC,st->L_frame) ); - Residu3_fx( A, synth, st->old_exc_fx+L_EXC_MEM_DEC-st->L_frame, st->L_frame, 1 ); + Copy( st->old_exc_fx + st->L_frame, st->old_exc_fx, sub( L_EXC_MEM_DEC, st->L_frame ) ); + Residu3_fx( A, synth, st->old_exc_fx + L_EXC_MEM_DEC - st->L_frame, st->L_frame, 1 ); /* Update LPC-related memories */ @@ -1227,14 +1237,14 @@ void update_decoder_LPD_cng( Copy( lsf, st->lsfold_uw, M ); move16(); move16(); - Copy( A, st->old_Aq_12_8_fx, M+1 ); - st->old_Es_pred_fx=0; + Copy( A, st->old_Aq_12_8_fx, M + 1 ); + st->old_Es_pred_fx = 0; /* Reset acelp memories */ move16(); - st->dm_fx.prev_gain_code = L_deposit_l(0); - set16_fx(st->dm_fx.prev_gain_pit, 0, 6); + st->dm_fx.prev_gain_code = L_deposit_l( 0 ); + set16_fx( st->dm_fx.prev_gain_pit, 0, 6 ); st->dm_fx.prev_state = 0; move16(); @@ -1253,19 +1263,19 @@ void update_decoder_LPD_cng( /* Reset TCX overlap */ move16(); move16(); - if (st->hTcxCfg != NULL) + if ( st->hTcxCfg != NULL ) { st->hTcxCfg->tcx_curr_overlap_mode = st->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; } /* For BBWE and Postfilter */ - Copy( A, &(st->mem_Aq[0]), M+1 ); - Copy( A, &(st->mem_Aq[(M+1)]), M+1 ); - Copy( A, &(st->mem_Aq[2*(M+1)]), M+1 ); - Copy( A, &(st->mem_Aq[3*(M+1)]), M+1 ); - IF( EQ_16(st->L_frame, L_FRAME16k)) + Copy( A, &( st->mem_Aq[0] ), M + 1 ); + Copy( A, &( st->mem_Aq[( M + 1 )] ), M + 1 ); + Copy( A, &( st->mem_Aq[2 * ( M + 1 )] ), M + 1 ); + Copy( A, &( st->mem_Aq[3 * ( M + 1 )] ), M + 1 ); + IF( EQ_16( st->L_frame, L_FRAME16k ) ) { - Copy( A, &(st->mem_Aq[4*(M+1)]), M+1 ); + Copy( A, &( st->mem_Aq[4 * ( M + 1 )] ), M + 1 ); } /* Update for concealment */ @@ -1274,54 +1284,52 @@ void update_decoder_LPD_cng( st->nbLostCmpt = 0; st->prev_old_bfi = 0; - FOR (i=0; ilsf_adaptive_mean_fx[i] = add( mult_r(st->lsfoldbfi1_fx[i], 10923/*1.0f/3.0f Q15*/), add( mult_r(st->lsfoldbfi0_fx[i], 10923/*1.0f/3.0f Q15*/), mult_r(lsf[i], 10923/*1.0f/3.0f Q15*/) ) ); + st->lsf_adaptive_mean_fx[i] = add( mult_r( st->lsfoldbfi1_fx[i], 10923 /*1.0f/3.0f Q15*/ ), add( mult_r( st->lsfoldbfi0_fx[i], 10923 /*1.0f/3.0f Q15*/ ), mult_r( lsf[i], 10923 /*1.0f/3.0f Q15*/ ) ) ); st->lsfoldbfi1_fx[i] = st->lsfoldbfi0_fx[i]; st->lsfoldbfi0_fx[i] = lsf[i]; } - set16_fx(pitch, shl(L_SUBFR, 6), NB_SUBFR16k); + set16_fx( pitch, shl( L_SUBFR, 6 ), NB_SUBFR16k ); FEC_clas_estim_fx( st, - /*Opt_AMR_WB*/0, /*A*/ + /*Opt_AMR_WB*/ 0, /*A*/ st->L_frame, - &(st->clas_dec), + &( st->clas_dec ), coder_type, pitch, synth, &st->lp_ener_FER_fx, - /**decision_hyst*/NULL, /* i/o: hysteresis of the music/speech decision */ - /**UV_cnt*/ NULL, /* i/o: number of consecutives frames classified as UV */ - /**LT_UV_cnt*/ NULL, /* i/o: long term consecutives frames classified as UV */ - /**Last_ener*/ NULL, /* i/o: last_energy frame */ - /**locattack*/ NULL, /* i/o: detection of attack (mainly to localized speech burst) */ - /**lt_diff_etot*/NULL, /* i/o: long-term total energy variation */ - /**amr_io_class*/ NULL, /* i/o: classification for AMR-WB IO mode */ - /*bitrate*/ 0 , /* i : Decoded bitrate */ - st->Q_syn, /* i : Synthesis scaling */ - /**class_para*/ NULL, /* o : classification para. fmerit1 */ - st->mem_syn_clas_estim_fx, /* i/o: memory of the synthesis signal for frame class estimation */ - &st->classifier_Q_mem_syn, /*i/o : exponent for memory of synthesis signal for frame class estimation */ - -32768/*-1.f Q15*/, /* i : LTP Gain */ - 0/*CLASSIFIER_ACELP*/, /* i : signal classifier mode */ - 0/*bfi*/, /* i : bad frame indicator */ - st->last_core_brate, /* i : bitrate of previous frame */ - -1 - ); + /**decision_hyst*/ NULL, /* i/o: hysteresis of the music/speech decision */ + /**UV_cnt*/ NULL, /* i/o: number of consecutives frames classified as UV */ + /**LT_UV_cnt*/ NULL, /* i/o: long term consecutives frames classified as UV */ + /**Last_ener*/ NULL, /* i/o: last_energy frame */ + /**locattack*/ NULL, /* i/o: detection of attack (mainly to localized speech burst) */ + /**lt_diff_etot*/ NULL, /* i/o: long-term total energy variation */ + /**amr_io_class*/ NULL, /* i/o: classification for AMR-WB IO mode */ + /*bitrate*/ 0, /* i : Decoded bitrate */ + st->Q_syn, /* i : Synthesis scaling */ + /**class_para*/ NULL, /* o : classification para. fmerit1 */ + st->mem_syn_clas_estim_fx, /* i/o: memory of the synthesis signal for frame class estimation */ + &st->classifier_Q_mem_syn, /*i/o : exponent for memory of synthesis signal for frame class estimation */ + -32768 /*-1.f Q15*/, /* i : LTP Gain */ + 0 /*CLASSIFIER_ACELP*/, /* i : signal classifier mode */ + 0 /*bfi*/, /* i : bad frame indicator */ + st->last_core_brate, /* i : bitrate of previous frame */ + -1 ); /* Postfiltering */ - set16_fx(pf_pitch, L_SUBFR, NB_SUBFR16k); - set16_fx(pf_gain, 0, NB_SUBFR16k); - st->bpf_gain_param=0; + set16_fx( pf_pitch, L_SUBFR, NB_SUBFR16k ); + set16_fx( pf_gain, 0, NB_SUBFR16k ); + st->bpf_gain_param = 0; move16(); post_decoder( st, buf_synth, pf_gain, pf_pitch, timeDomainBuffer, bpf_noise_buf ); return; } - diff --git a/lib_dec/vlpc_1st_dec_fx.c b/lib_dec/vlpc_1st_dec_fx.c index 49751d984..5d89a7696 100644 --- a/lib_dec/vlpc_1st_dec_fx.c +++ b/lib_dec/vlpc_1st_dec_fx.c @@ -11,22 +11,19 @@ void vlpc_1st_dec( - Word16 index, /* input: codebook index */ - Word16 *lsfq) /* i/o: i:prediction o:quantized lsf */ + Word16 index, /* input: codebook index */ + Word16 *lsfq ) /* i/o: i:prediction o:quantized lsf */ { Word16 i; const Word16 *p_dico; - - assert(index < 256); + assert( index < 256 ); p_dico = &dico_lsf_abs_8b[index * M]; - FOR (i = 0; i < M; i++) + FOR( i = 0; i < M; i++ ) { - lsfq[i] = add(lsfq[i], *p_dico); + lsfq[i] = add( lsfq[i], *p_dico ); move16(); p_dico++; } - - } diff --git a/lib_dec/vlpc_2st_dec_fx.c b/lib_dec/vlpc_2st_dec_fx.c index 1a86fdb91..7629ab2c2 100644 --- a/lib_dec/vlpc_2st_dec_fx.c +++ b/lib_dec/vlpc_2st_dec_fx.c @@ -12,10 +12,10 @@ //#endif void vlpc_2st_dec( - Word16 *lsfq, /* i/o: i:1st stage o:1st+2nd stage */ - Word16 *indx, /* i : index[] (4 bits per words) */ - Word16 mode, /* i : 0=abs, >0=rel */ - Word32 sr_core /* i : internal sampling rate */ + Word16 *lsfq, /* i/o: i:1st stage o:1st+2nd stage */ + Word16 *indx, /* i : index[] (4 bits per words) */ + Word16 mode, /* i : 0=abs, >0=rel */ + Word32 sr_core /* i : internal sampling rate */ ) { Word16 i; @@ -24,16 +24,15 @@ void vlpc_2st_dec( Word16 gap; - /* weighting from the 1st stage */ - lsf_weight_2st(lsfq, w, mode); + lsf_weight_2st( lsfq, w, mode ); /* quantize */ - AVQ_dec_lpc(indx, xq, 2); + AVQ_dec_lpc( indx, xq, 2 ); /* quantized lsf */ - FOR (i=0; ibwidth,WB)||EQ_16(st_fx->bwidth,SWB)) + IF( EQ_16( st_fx->bwidth, WB ) || EQ_16( st_fx->bwidth, SWB ) ) { upper_cut_off_freq_of_interest = 0x2800; - move16();/*4000 normalized to 12800 in Q15 */ + move16(); /*4000 normalized to 12800 in Q15 */ upper_cut_off_freq = 0x4000; - move16();/*6400 normalized to 12800 in Q15 */ + move16(); /*6400 normalized to 12800 in Q15 */ } - ELSE IF (EQ_16(st_fx->bwidth,NB)) + ELSE IF( EQ_16( st_fx->bwidth, NB ) ) { upper_cut_off_freq_of_interest = 0x2100; - move16();/*3300 normalized to 12800 in Q15 */ + move16(); /*3300 normalized to 12800 in Q15 */ upper_cut_off_freq = 0x2800; move16(); } temp_Fs = 8000; - if ( EQ_16( st_fx->bwidth, WB)) + if ( EQ_16( st_fx->bwidth, WB ) ) { - temp_Fs = 16000; + temp_Fs = 16000; move16(); } - /* Initialization */ - IF (hSC_VBR->firstTime_voiceddec) + IF( hSC_VBR->firstTime_voiceddec ) { - hSC_VBR->firstTime_voiceddec=0; + hSC_VBR->firstTime_voiceddec = 0; move16(); /* (st_fx->PREV_CW_D) = DTFS_new();*/ @@ -131,7 +130,7 @@ ivas_error ppp_voiced_decoder_fx( hSC_VBR->dtfs_dec_upper_cut_off_freq_fx = 4000; move16(); - FOR(k = 0; k < MAXLAG_WI; k++) + FOR( k = 0; k < MAXLAG_WI; k++ ) { hSC_VBR->dtfs_dec_a_fx[k] = 0; move16(); @@ -142,145 +141,143 @@ ivas_error ppp_voiced_decoder_fx( move16(); } - pl = s_min(rint_new_fx(st_fx->old_pitch_buf_fx[(2*NB_SUBFR)-1]),MAX_LAG_PIT); + pl = s_min( rint_new_fx( st_fx->old_pitch_buf_fx[( 2 * NB_SUBFR ) - 1] ), MAX_LAG_PIT ); delta_lag_D = (Word16) get_next_indice( st_fx, 5 ); - l = s_min(MAX_LAG_PIT,add(pl,sub(delta_lag_D,11))); + l = s_min( MAX_LAG_PIT, add( pl, sub( delta_lag_D, 11 ) ) ); - temp_pl_fx = pl; + temp_pl_fx = pl; move16(); - temp_l_fx = l; + temp_l_fx = l; move16(); - IF (NE_16(temp_pl_fx,temp_l_fx)) + IF( NE_16( temp_pl_fx, temp_l_fx ) ) { - FOR(k=0; klast_coder_type,UNVOICED)) + if ( EQ_16( st_fx->last_coder_type, UNVOICED ) ) { pl = l; move16(); /* if prev frame was sil/uv*/ } - temp = mult(shl(l,3),30310);/*Q3+14+1-16 = Q2 30310 is 1.85 in Q14 */ + temp = mult( shl( l, 3 ), 30310 ); /*Q3+14+1-16 = Q2 30310 is 1.85 in Q14 */ IF( temp >= 0 ) { - temp = add(temp,2); + temp = add( temp, 2 ); } ELSE { - temp = sub(temp,2); + temp = sub( temp, 2 ); } - temp = shr(temp,2);/*Q0 */ + temp = shr( temp, 2 ); /*Q0 */ - if (GT_16(pl,temp)) + if ( GT_16( pl, temp ) ) { - pl = shr(pl,1); + pl = shr( pl, 1 ); } - temp = mult(shl(l,3),8857);/*Q3+14+1-16 = Q2 8847 is 0.54 in Q14 */ + temp = mult( shl( l, 3 ), 8857 ); /*Q3+14+1-16 = Q2 8847 is 0.54 in Q14 */ IF( temp >= 0 ) { - temp = add(temp,2); + temp = add( temp, 2 ); } ELSE { - temp = sub(temp,2); + temp = sub( temp, 2 ); } - temp = shr(temp,2);/*Q0 */ + temp = shr( temp, 2 ); /*Q0 */ test(); - if (LE_16(shl(pl,1),PIT_MAX)&&LE_16(pl,temp)) + if ( LE_16( shl( pl, 1 ), PIT_MAX ) && LE_16( pl, temp ) ) { - pl = shl(pl,1); + pl = shl( pl, 1 ); } /* Restoring PPP memories when the last frame is non-PPP or full-rate PPP */ - IF (NE_16(st_fx->last_ppp_mode_dec,1)) + IF( NE_16( st_fx->last_ppp_mode_dec, 1 ) ) { - GetSinCosTab_fx(pl, S_fx, C_fx); - DTFS_to_fs_fx(exc_fx-pl, pl, dtfs_temp_fx, temp_Fs, 0, S_fx, C_fx); + GetSinCosTab_fx( pl, S_fx, C_fx ); + DTFS_to_fs_fx( exc_fx - pl, pl, dtfs_temp_fx, temp_Fs, 0, S_fx, C_fx ); - hSC_VBR->ph_offset_D_fx = 0 ; + hSC_VBR->ph_offset_D_fx = 0; move16(); /* Copy over PREV_CW_D into TMPDTFS */ - DTFS_copy_fx(TMPDTFS_FX, *dtfs_temp_fx); + DTFS_copy_fx( TMPDTFS_FX, *dtfs_temp_fx ); - DTFS_car2pol_fx(TMPDTFS_FX); + DTFS_car2pol_fx( TMPDTFS_FX ); /*st_fx->lastLgainD = (float) log10(TMPDTFS->lag*DTFS_setEngyHarm(92.0,1104.5,0.0,1104.5,1.0,TMPDTFS)); */ - L_tmp = L_deposit_h(TMPDTFS_FX->lag_fx);/*Q16 */ - exp = norm_l(L_tmp); - tmp = Log2_norm_lc(L_shl(L_tmp,exp)); - exp = (30-exp-16); - L_tmp = Mpy_32_16(exp,tmp,12330);/* Q13 */ /* 10*log10(2) in Q12*/ - logLag = L_shl(L_tmp, 10);/*Q23 */ + L_tmp = L_deposit_h( TMPDTFS_FX->lag_fx ); /*Q16 */ + exp = norm_l( L_tmp ); + tmp = Log2_norm_lc( L_shl( L_tmp, exp ) ); + exp = ( 30 - exp - 16 ); + L_tmp = Mpy_32_16( exp, tmp, 12330 ); /* Q13 */ /* 10*log10(2) in Q12*/ + logLag = L_shl( L_tmp, 10 ); /*Q23 */ - Ltemp_q=L_shl(L_mult(shl(TMPDTFS_FX->Q,1),24660),9); /* Ltemp_q=2Q*10log10(2), Q23 */ + Ltemp_q = L_shl( L_mult( shl( TMPDTFS_FX->Q, 1 ), 24660 ), 9 ); /* Ltemp_q=2Q*10log10(2), Q23 */ /* Process low band */ - Ltemp=DTFS_setEngyHarm_fx(236,2828,0,2828,1,0,&Ql,TMPDTFS_FX);/* Ltemp in 2*TMP.Q */ + Ltemp = DTFS_setEngyHarm_fx( 236, 2828, 0, 2828, 1, 0, &Ql, TMPDTFS_FX ); /* Ltemp in 2*TMP.Q */ /* Compensate for Q factor of energy to get log10(lag*eng) */ - Ltemp=log10_fx(Ltemp); /* Ltemp=10log10(eng), Q23 */ + Ltemp = log10_fx( Ltemp ); /* Ltemp=10log10(eng), Q23 */ #ifdef BASOP_NOGLOB - Ltemp=L_add_sat(L_sub_sat(Ltemp,Ltemp_q),logLag); /* Ltemp=10*log10(lag*eng), Q23 */ - hSC_VBR->lastLgainD_fx = round_fx_sat(L_shl_sat((Word32)Mpy_32_16(extract_h(Ltemp), extract_l(Ltemp), 0x6666), 1)); /* Q11 */ + Ltemp = L_add_sat( L_sub_sat( Ltemp, Ltemp_q ), logLag ); /* Ltemp=10*log10(lag*eng), Q23 */ + hSC_VBR->lastLgainD_fx = round_fx_sat( L_shl_sat( (Word32) Mpy_32_16( extract_h( Ltemp ), extract_l( Ltemp ), 0x6666 ), 1 ) ); /* Q11 */ #else - Ltemp=L_add(L_sub(Ltemp,Ltemp_q),logLag); /* Ltemp=10*log10(lag*eng), Q23 */ - hSC_VBR->lastLgainD_fx = round_fx(L_shl((Word32)Mpy_32_16(extract_h(Ltemp), extract_l(Ltemp), 0x6666), 1)); /* Q11 */ + Ltemp = L_add( L_sub( Ltemp, Ltemp_q ), logLag ); /* Ltemp=10*log10(lag*eng), Q23 */ + hSC_VBR->lastLgainD_fx = round_fx( L_shl( (Word32) Mpy_32_16( extract_h( Ltemp ), extract_l( Ltemp ), 0x6666 ), 1 ) ); /* Q11 */ #endif - /* Process high band */ - Ltemp=DTFS_setEngyHarm_fx(2828,upper_cut_off_freq_of_interest,2828,upper_cut_off_freq,1,0,&Qh,TMPDTFS_FX); + Ltemp = DTFS_setEngyHarm_fx( 2828, upper_cut_off_freq_of_interest, 2828, upper_cut_off_freq, 1, 0, &Qh, TMPDTFS_FX ); - Ltemp=log10_fx(Ltemp); + Ltemp = log10_fx( Ltemp ); #ifdef BASOP_NOGLOB - Ltemp=L_add_sat(L_sub_sat(Ltemp,Ltemp_q),logLag); /* Ltemp=10*log10(lag*eng), Q23 */ - hSC_VBR->lastHgainD_fx=round_fx_sat(L_shl_sat((Word32)Mpy_32_16(extract_h(Ltemp),extract_l(Ltemp),0x6666),1)); /* Q11 */ + Ltemp = L_add_sat( L_sub_sat( Ltemp, Ltemp_q ), logLag ); /* Ltemp=10*log10(lag*eng), Q23 */ + hSC_VBR->lastHgainD_fx = round_fx_sat( L_shl_sat( (Word32) Mpy_32_16( extract_h( Ltemp ), extract_l( Ltemp ), 0x6666 ), 1 ) ); /* Q11 */ #else - Ltemp=L_add(L_sub(Ltemp,Ltemp_q),logLag); /* Ltemp=10*log10(lag*eng), Q23 */ - hSC_VBR->lastHgainD_fx=round_fx(L_shl((Word32)Mpy_32_16(extract_h(Ltemp),extract_l(Ltemp),0x6666),1)); /* Q11 */ + Ltemp = L_add( L_sub( Ltemp, Ltemp_q ), logLag ); /* Ltemp=10*log10(lag*eng), Q23 */ + hSC_VBR->lastHgainD_fx = round_fx( L_shl( (Word32) Mpy_32_16( extract_h( Ltemp ), extract_l( Ltemp ), 0x6666 ), 1 ) ); /* Q11 */ #endif /* Need to unify the Q factors of both bands */ - TMPDTFS_FX->Q=s_min(Ql,Qh); /* set Q factor to be the smaller one */ - n=sub(Ql,Qh); /* compare band Q factors */ + TMPDTFS_FX->Q = s_min( Ql, Qh ); /* set Q factor to be the smaller one */ + n = sub( Ql, Qh ); /* compare band Q factors */ /*This logic adjusts difference between Q formats of both bands */ - IF (n<0) + IF( n < 0 ) { - rshiftHarmBand_fx(TMPDTFS_FX,2828, upper_cut_off_freq,n); + rshiftHarmBand_fx( TMPDTFS_FX, 2828, upper_cut_off_freq, n ); } - ELSE IF (n>0) + ELSE IF( n > 0 ) { - rshiftHarmBand_fx(TMPDTFS_FX,0, 2828, sub(Qh,Ql)); + rshiftHarmBand_fx( TMPDTFS_FX, 0, 2828, sub( Qh, Ql ) ); } - DTFS_to_erb_fx(*TMPDTFS_FX, hSC_VBR->lasterbD_fx); - + DTFS_to_erb_fx( *TMPDTFS_FX, hSC_VBR->lasterbD_fx ); } ELSE { @@ -296,8 +293,8 @@ ivas_error ppp_voiced_decoder_fx( dtfs_temp_fx->upper_cut_off_freq_fx = hSC_VBR->dtfs_dec_upper_cut_off_freq_fx; move16(); - Copy(hSC_VBR->dtfs_dec_a_fx, dtfs_temp_fx->a_fx, MAXLAG_WI); - Copy(hSC_VBR->dtfs_dec_b_fx, dtfs_temp_fx->b_fx, MAXLAG_WI); + Copy( hSC_VBR->dtfs_dec_a_fx, dtfs_temp_fx->a_fx, MAXLAG_WI ); + Copy( hSC_VBR->dtfs_dec_b_fx, dtfs_temp_fx->b_fx, MAXLAG_WI ); dtfs_temp_fx->Q = hSC_VBR->dtfs_dec_Q; move16(); } @@ -315,66 +312,65 @@ ivas_error ppp_voiced_decoder_fx( } /* compute nH for lag */ - Ltemp = L_shl((Word32)upper_cut_off_freq,13);/*Q28 */ - upper_cut_off_freq = (Word16)find_remd(Ltemp, 20971,&rem32);/*denormalize upper_cut_off_freq */ - + Ltemp = L_shl( (Word32) upper_cut_off_freq, 13 ); /*Q28 */ + upper_cut_off_freq = (Word16) find_remd( Ltemp, 20971, &rem32 ); /*denormalize upper_cut_off_freq */ /* temp32_fx = (Word32)divide_dp((Word40)819200,(Word40)L_shl((Word32)CURRP_Q_D_FX->lag_fx,6),-23,1);//Q6 */ - exp = norm_s(CURRP_Q_D_FX->lag_fx); - tmp = div_s(shl(1,sub(14,exp)),CURRP_Q_D_FX->lag_fx);/*29-exp */ + exp = norm_s( CURRP_Q_D_FX->lag_fx ); + tmp = div_s( shl( 1, sub( 14, exp ) ), CURRP_Q_D_FX->lag_fx ); /*29-exp */ #ifdef BASOP_NOGLOB L_tmp = L_shl_sat( L_mult0( tmp, 12800 ), exp - 7 ); temp32_fx = round_fx_sat( L_tmp ); #else - L_tmp =L_shl(L_mult0(tmp,12800),exp - 7); - temp32_fx = round_fx(L_tmp); + L_tmp = L_shl( L_mult0( tmp, 12800 ), exp - 7 ); + temp32_fx = round_fx( L_tmp ); #endif - diff = round_fx(L_shl(temp32_fx,16-6));/*Q0 */ + diff = round_fx( L_shl( temp32_fx, 16 - 6 ) ); /*Q0 */ - CURRP_Q_D_FX->nH_fx = find_rem(upper_cut_off_freq,diff,&rem_fx);/*Q0 */ + CURRP_Q_D_FX->nH_fx = find_rem( upper_cut_off_freq, diff, &rem_fx ); /*Q0 */ - exp = norm_s(diff); - tmp = div_s(shl(1,sub(14,exp)),diff);/*29-exp */ - L_tmp = L_shl(L_mult0(4000,tmp),exp - 7); - tempnH_fx = extract_h(L_tmp); - CURRP_Q_D_FX->nH_4kHz_fx = round_fx(L_shl(tempnH_fx,16-6));/*Q0 */ + exp = norm_s( diff ); + tmp = div_s( shl( 1, sub( 14, exp ) ), diff ); /*29-exp */ + L_tmp = L_shl( L_mult0( 4000, tmp ), exp - 7 ); + tempnH_fx = extract_h( L_tmp ); + CURRP_Q_D_FX->nH_4kHz_fx = round_fx( L_shl( tempnH_fx, 16 - 6 ) ); /*Q0 */ - IF(GE_16(sub(upper_cut_off_freq,shr((Word16)L_mult(diff,CURRP_Q_D_FX->nH_fx),1)),diff)) + IF( GE_16( sub( upper_cut_off_freq, shr( (Word16) L_mult( diff, CURRP_Q_D_FX->nH_fx ), 1 ) ), diff ) ) { - CURRP_Q_D_FX->nH_fx = add(CURRP_Q_D_FX->nH_fx,1); + CURRP_Q_D_FX->nH_fx = add( CURRP_Q_D_FX->nH_fx, 1 ); } - tempnH_fx = L_mult0(extract_l(temp32_fx),CURRP_Q_D_FX->nH_4kHz_fx);/* */ - tempnH_fx = L_sub((Word32)256000,tempnH_fx);/*Q6 */ + tempnH_fx = L_mult0( extract_l( temp32_fx ), CURRP_Q_D_FX->nH_4kHz_fx ); /* */ + tempnH_fx = L_sub( (Word32) 256000, tempnH_fx ); /*Q6 */ - if(GE_32(tempnH_fx,temp32_fx)) + if ( GE_32( tempnH_fx, temp32_fx ) ) { - CURRP_Q_D_FX->nH_4kHz_fx = add(CURRP_Q_D_FX->nH_4kHz_fx,1); + CURRP_Q_D_FX->nH_4kHz_fx = add( CURRP_Q_D_FX->nH_4kHz_fx, 1 ); } CURRP_Q_D_FX->upper_cut_off_freq_fx = dtfs_temp_fx->upper_cut_off_freq_fx; move16(); CURRP_Q_D_FX->upper_cut_off_freq_of_interest_fx = dtfs_temp_fx->upper_cut_off_freq_of_interest_fx; move16(); - GetSinCosTab_fx(CURRP_Q_D_FX->lag_fx,S_fx,C_fx); + GetSinCosTab_fx( CURRP_Q_D_FX->lag_fx, S_fx, C_fx ); - IF ( bfi == 0 ) + IF( bfi == 0 ) { - IF((error = ppp_quarter_decoder_fx(CURRP_Q_D_FX, dtfs_temp_fx->lag_fx, &(hSC_VBR->lastLgainD_fx), - &(hSC_VBR->lastHgainD_fx), hSC_VBR->lasterbD_fx, bfi, S_fx, C_fx, *dtfs_temp_fx, st_fx)) != IVAS_ERR_OK) + IF( ( error = ppp_quarter_decoder_fx( CURRP_Q_D_FX, dtfs_temp_fx->lag_fx, &( hSC_VBR->lastLgainD_fx ), + &( hSC_VBR->lastHgainD_fx ), hSC_VBR->lasterbD_fx, bfi, S_fx, C_fx, *dtfs_temp_fx, st_fx ) ) != IVAS_ERR_OK ) { return error; } } - IF ((error = WIsyn_fx(*dtfs_temp_fx, CURRP_Q_D_FX, lpc2_fx, &(hSC_VBR->ph_offset_D_fx), out_fx, (Word16)L_FRAME, 0, - S_fx, C_fx, pf_temp1, pf_temp2, pf_temp, pf_n2)) != IVAS_ERR_OK) + IF( ( error = WIsyn_fx( *dtfs_temp_fx, CURRP_Q_D_FX, lpc2_fx, &( hSC_VBR->ph_offset_D_fx ), out_fx, (Word16) L_FRAME, 0, + S_fx, C_fx, pf_temp1, pf_temp2, pf_temp, pf_n2 ) ) != IVAS_ERR_OK ) { return error; } - DTFS_copy_fx(dtfs_temp_fx, *CURRP_Q_D_FX); + DTFS_copy_fx( dtfs_temp_fx, *CURRP_Q_D_FX ); /* Copy DTFS related parameters from 'dtfs_temp' to 'st' structure */ hSC_VBR->dtfs_dec_lag = dtfs_temp_fx->lag_fx; @@ -388,23 +384,23 @@ ivas_error ppp_voiced_decoder_fx( hSC_VBR->dtfs_dec_upper_cut_off_freq_fx = dtfs_temp_fx->upper_cut_off_freq_fx; move16(); - Copy(dtfs_temp_fx->a_fx, hSC_VBR->dtfs_dec_a_fx, MAXLAG_WI); - Copy(dtfs_temp_fx->b_fx, hSC_VBR->dtfs_dec_b_fx, MAXLAG_WI); + Copy( dtfs_temp_fx->a_fx, hSC_VBR->dtfs_dec_a_fx, MAXLAG_WI ); + Copy( dtfs_temp_fx->b_fx, hSC_VBR->dtfs_dec_b_fx, MAXLAG_WI ); hSC_VBR->dtfs_dec_Q = dtfs_temp_fx->Q; move16(); - count_free(TMPDTFS_FX); - count_free(CURRP_Q_D_FX); - count_free(dtfs_temp_fx); + count_free( TMPDTFS_FX ); + count_free( CURRP_Q_D_FX ); + count_free( dtfs_temp_fx ); return IVAS_ERR_OK; } /*---------------------------------------------------------------------* -* sc_vbr_dec_init() -* -* Initialize SC-VBR decoder -*---------------------------------------------------------------------*/ + * sc_vbr_dec_init() + * + * Initialize SC-VBR decoder + *---------------------------------------------------------------------*/ void sc_vbr_dec_init( SC_VBR_DEC_HANDLE hSC_VBR /* i/o: SC-VBR decoder handle */ ) @@ -413,8 +409,8 @@ void sc_vbr_dec_init( hSC_VBR->firstTime_voiceddec = 1; /* DTFS variables */ - set16_fx(hSC_VBR->dtfs_dec_a_fx, 0, MAXLAG_WI); - set16_fx(hSC_VBR->dtfs_dec_b_fx, 0, MAXLAG_WI); + set16_fx( hSC_VBR->dtfs_dec_a_fx, 0, MAXLAG_WI ); + set16_fx( hSC_VBR->dtfs_dec_b_fx, 0, MAXLAG_WI ); hSC_VBR->dtfs_dec_lag = 0; hSC_VBR->dtfs_dec_nH = 0; hSC_VBR->dtfs_dec_nH_4kHz = 0; @@ -423,14 +419,14 @@ void sc_vbr_dec_init( hSC_VBR->ph_offset_D_fx = 0; hSC_VBR->lastLgainD_fx = 0; hSC_VBR->lastHgainD_fx = 0; - set16_fx(hSC_VBR->lasterbD_fx, 0, NUM_ERB_WB); + set16_fx( hSC_VBR->lasterbD_fx, 0, NUM_ERB_WB ); /* NELP decoder variables */ - set32_fx(hSC_VBR->bp1_filt_mem_nb_dec_fx, 0, 14); - set16_fx(hSC_VBR->bp1_filt_mem_wb_dec_fx, 0, 8); - set16_fx(hSC_VBR->shape1_filt_mem_dec_fx, 0, 10); - set16_fx(hSC_VBR->shape2_filt_mem_dec_fx, 0, 10); - set16_fx(hSC_VBR->shape3_filt_mem_dec_fx, 0, 10); + set32_fx( hSC_VBR->bp1_filt_mem_nb_dec_fx, 0, 14 ); + set16_fx( hSC_VBR->bp1_filt_mem_wb_dec_fx, 0, 8 ); + set16_fx( hSC_VBR->shape1_filt_mem_dec_fx, 0, 10 ); + set16_fx( hSC_VBR->shape2_filt_mem_dec_fx, 0, 10 ); + set16_fx( hSC_VBR->shape3_filt_mem_dec_fx, 0, 10 ); return; } diff --git a/lib_dec/waveadjust_fec_dec.c b/lib_dec/waveadjust_fec_dec.c index 1a1acb860..245d8bbf6 100644 --- a/lib_dec/waveadjust_fec_dec.c +++ b/lib_dec/waveadjust_fec_dec.c @@ -912,4 +912,4 @@ void concealment_signal_tuning( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/waveadjust_fec_dec_fx.c b/lib_dec/waveadjust_fec_dec_fx.c index d88ced1ce..ddbcb90df 100644 --- a/lib_dec/waveadjust_fec_dec_fx.c +++ b/lib_dec/waveadjust_fec_dec_fx.c @@ -11,37 +11,36 @@ #include "basop_util.h" #include "stat_com.h" #include "rom_com.h" -#include "stl.h" /* FOR wmc_tool */ +#include "stl.h" /* FOR wmc_tool */ #include "vad_basop.h" -void get_maxConv_and_pitch_x(Word16 *s_LP, Word16 s, Word16 e, Word16 N, - Word32 *maxConv, Word16 *maxConv_bits, Word16 *pitch); -Word16 get_voicing_x(Word16 *s_LP, Word16 pitch, Word32 covMax,Word16 maxConv_bits, Word16 Framesize); -Word32 con_Log10(Word32 i_s32Val, Word16 i_s16Q); -Word16 Spl_GetScalingSquare_x(const Word16 *in_vector, const Word16 in_vector_length, Word16 times); +void get_maxConv_and_pitch_x( Word16 *s_LP, Word16 s, Word16 e, Word16 N, Word32 *maxConv, Word16 *maxConv_bits, Word16 *pitch ); +Word16 get_voicing_x( Word16 *s_LP, Word16 pitch, Word32 covMax, Word16 maxConv_bits, Word16 Framesize ); +Word32 con_Log10( Word32 i_s32Val, Word16 i_s16Q ); +Word16 Spl_GetScalingSquare_x( const Word16 *in_vector, const Word16 in_vector_length, Word16 times ); -Word16 vadmin(Word16 a, Word16 b) +Word16 vadmin( Word16 a, Word16 b ) { - return s_min(a, b); + return s_min( a, b ); } -void set_state(Word16 *state, Word16 num, Word16 N) +void set_state( Word16 *state, Word16 num, Word16 N ) { Word16 i, tmp; - tmp = sub(N, 1); - FOR (i = 0; i < tmp; i++) + tmp = sub( N, 1 ); + FOR( i = 0; i < tmp; i++ ) { - state[i] = state[i+1]; + state[i] = state[i + 1]; move16(); } state[tmp] = num; move16(); } -void concealment_update_x(Word16 bfi, Word16 curr_mode, Word16 tonality, Word32 *invkoef, Word16 *invkoef_scale, void *_plcInfo) +void concealment_update_x( Word16 bfi, Word16 curr_mode, Word16 tonality, Word32 *invkoef, Word16 *invkoef_scale, void *_plcInfo ) { - T_PLCInfo *plcInfo = (T_PLCInfo*)_plcInfo; + T_PLCInfo *plcInfo = (T_PLCInfo *) _plcInfo; Word32 *data_reci2 = plcInfo->data_reci2_fx; Word16 *tcx_tonality = plcInfo->TCX_Tonality; Word16 FrameSize = plcInfo->FrameSize; @@ -49,46 +48,45 @@ void concealment_update_x(Word16 bfi, Word16 curr_mode, Word16 tonality, Word32 Word16 i; move16(); move16(); - IF (EQ_16(curr_mode ,1)) + IF( EQ_16( curr_mode, 1 ) ) { - set_state(plcInfo->Transient, curr_mode, MAX_POST_LEN); + set_state( plcInfo->Transient, curr_mode, MAX_POST_LEN ); - FOR (i = 0; i < FrameSize; i++) + FOR( i = 0; i < FrameSize; i++ ) { data_reci2[i] = invkoef[i]; move32(); - } plcInfo->data_reci2_scale = *invkoef_scale; move16(); - IF (!bfi) + IF( !bfi ) { - set_state(tcx_tonality, tonality, DEC_STATE_LEN); + set_state( tcx_tonality, tonality, DEC_STATE_LEN ); } } ELSE { - IF (EQ_16(subframe,0)) + IF( EQ_16( subframe, 0 ) ) { - set_state(plcInfo->Transient, curr_mode, MAX_POST_LEN); + set_state( plcInfo->Transient, curr_mode, MAX_POST_LEN ); - IF (!bfi) + IF( !bfi ) { - set_state(tcx_tonality, tonality, DEC_STATE_LEN); + set_state( tcx_tonality, tonality, DEC_STATE_LEN ); } } /* don't store the second subframe during frameloss; in pitch_search_fx(), low_freq_rate is derived on the last good TCX-10 spectrum */ test(); - IF (!bfi || EQ_16(subframe,0)) + IF( !bfi || EQ_16( subframe, 0 ) ) { - Word32 *ptr = data_reci2+subframe; - Word16 FrameSize2 = shr(FrameSize,1); + Word32 *ptr = data_reci2 + subframe; + Word16 FrameSize2 = shr( FrameSize, 1 ); - FOR (i = 0; i < FrameSize2; i++) + FOR( i = 0; i < FrameSize2; i++ ) { ptr[i] = invkoef[i]; move32(); @@ -101,70 +99,70 @@ void concealment_update_x(Word16 bfi, Word16 curr_mode, Word16 tonality, Word32 return; } -static Word16 zero_pass_w32_x(const Word16 *s, const Word16 N) +static Word16 zero_pass_w32_x( const Word16 *s, const Word16 N ) { Word16 i; - Word32 temp, zp = L_deposit_l(0); + Word32 temp, zp = L_deposit_l( 0 ); - FOR (i = 1; i < N; i++) + FOR( i = 1; i < N; i++ ) { - temp = L_mac0(-1L, s[i],s[i-1]); - zp = L_sub(zp, L_shr(temp,31)); + temp = L_mac0( -1L, s[i], s[i - 1] ); + zp = L_sub( zp, L_shr( temp, 31 ) ); } - return extract_l(zp); + return extract_l( zp ); } -Word16 Sqrt_x_fast(Word32 value) +Word16 Sqrt_x_fast( Word32 value ) { Word16 norm; Word16 result, index; - norm = sub(23, norm_l(value)); - index = extract_l( L_shr_r(value, add(norm, s_and(norm, 1)))); - result = shr(sqrt_table_pitch_search[index], sub(11, shr(add(norm,1),1))); + norm = sub( 23, norm_l( value ) ); + index = extract_l( L_shr_r( value, add( norm, s_and( norm, 1 ) ) ) ); + result = shr( sqrt_table_pitch_search[index], sub( 11, shr( add( norm, 1 ), 1 ) ) ); return result; } -Word32 dot_w32_accuracy_x(Word16 *s1, Word16 *s2, Word16 nbits, Word16 N) +Word32 dot_w32_accuracy_x( Word16 *s1, Word16 *s2, Word16 nbits, Word16 N ) { Word16 i; - Word32 eng = L_deposit_l(0), temp; + Word32 eng = L_deposit_l( 0 ), temp; - FOR (i = 0; i < N; i++) + FOR( i = 0; i < N; i++ ) { - temp = L_mult0(s1[i], s2[i]); - eng = L_add(eng, L_shr(temp,nbits)); + temp = L_mult0( s1[i], s2[i] ); + eng = L_add( eng, L_shr( temp, nbits ) ); } return eng; } -Word16 int_div_s_x(Word16 a, Word16 b) +Word16 int_div_s_x( Word16 a, Word16 b ) { Word16 result = 0; - Word16 norm, left=0, i; + Word16 norm, left = 0, i; move16(); move16(); test(); - IF (LT_16(a,b)||b==0) + IF( LT_16( a, b ) || b == 0 ) { return 0; } ELSE { - a = add(a, shr(b,1)); - norm = sub(norm_s(b),norm_s(a)); + a = add( a, shr( b, 1 ) ); + norm = sub( norm_s( b ), norm_s( a ) ); - FOR (i = norm; i>= 0; i--) + FOR( i = norm; i >= 0; i-- ) { - left = shr(a, i); - result = shl(result,1); - IF (GE_16(left,b)) + left = shr( a, i ); + result = shl( result, 1 ); + IF( GE_16( left, b ) ) { - result = add(result,1); - left= sub(left, b); - a = add(shl(left,i), s_and(a, sub(shl(1,i),1))); + result = add( result, 1 ); + left = sub( left, b ); + a = add( shl( left, i ), s_and( a, sub( shl( 1, i ), 1 ) ) ); } } } @@ -172,210 +170,208 @@ Word16 int_div_s_x(Word16 a, Word16 b) return result; } -Word16 GetW32Norm_x(Word32 *s, Word16 N) +Word16 GetW32Norm_x( Word32 *s, Word16 N ) { - Word32 smax = L_deposit_l(0); + Word32 smax = L_deposit_l( 0 ); Word16 smax_norm, i; - FOR (i = 0; i < N; i++) + FOR( i = 0; i < N; i++ ) { - smax = L_or(smax, L_abs(s[i])); + smax = L_or( smax, L_abs( s[i] ) ); } - smax_norm = norm_l(smax); + smax_norm = norm_l( smax ); return smax_norm; } -Word16 harmo_x(Word32 *X, Word16 Framesize, Word16 pitch) +Word16 harmo_x( Word32 *X, Word16 Framesize, Word16 pitch ) { - Word16 h, k, result = 0; - Word32 ener = L_deposit_l(0), ener_harmo = L_deposit_l(0); + Word16 h, k, result = 0; + Word32 ener = L_deposit_l( 0 ), ener_harmo = L_deposit_l( 0 ); Word16 norm1, d1, d2; Word16 ener_w, ener_harmo_w; - Word16 nbits = sub(15, norm_s(Framesize)); + Word16 nbits = sub( 15, norm_s( Framesize ) ); move16(); - norm1 = GetW32Norm_x(X, Framesize); + norm1 = GetW32Norm_x( X, Framesize ); - FOR (k = 1; k < 9; k++) + FOR( k = 1; k < 9; k++ ) { - h = sub(int_div_s_x(extract_l(L_mult(k, Framesize)), pitch),1); + h = sub( int_div_s_x( extract_l( L_mult( k, Framesize ) ), pitch ), 1 ); - d1 = extract_h(L_shl(X[h], norm1)); - d2 = extract_h(L_shl(X[h+1],norm1)); + d1 = extract_h( L_shl( X[h], norm1 ) ); + d2 = extract_h( L_shl( X[h + 1], norm1 ) ); - ener_harmo = L_add(ener_harmo, - L_shr(L_mac0(L_mult0(d1, d1), d2, d2),nbits)); + ener_harmo = L_add( ener_harmo, + L_shr( L_mac0( L_mult0( d1, d1 ), d2, d2 ), nbits ) ); } - FOR (k = 0; k < Framesize; k++) + FOR( k = 0; k < Framesize; k++ ) { - d1 = extract_h(L_shl(X[k],norm1)); - ener = L_add(ener, L_shr(L_mult0(d1, d1),nbits)); + d1 = extract_h( L_shl( X[k], norm1 ) ); + ener = L_add( ener, L_shr( L_mult0( d1, d1 ), nbits ) ); } - norm1 = norm_l(ener); - ener_w = extract_h(L_shl(ener,norm1)); - ener_harmo_w = extract_h(L_shl(ener_harmo,norm1)); + norm1 = norm_l( ener ); + ener_w = extract_h( L_shl( ener, norm1 ) ); + ener_harmo_w = extract_h( L_shl( ener_harmo, norm1 ) ); - IF (GE_32(ener_harmo ,ener)) + IF( GE_32( ener_harmo, ener ) ) { return 32767; } test(); - IF ((ener_harmo_w <= 0)||(ener_w <= 0)) + IF( ( ener_harmo_w <= 0 ) || ( ener_w <= 0 ) ) { return 0; } - result = div_s(ener_harmo_w, ener_w); + result = div_s( ener_harmo_w, ener_w ); return result; } -static -Word16 get_low_freq_eng_rate_x(Word32 *mdct_data, - Word16 curr_mode, - Word16 N) +static Word16 get_low_freq_eng_rate_x( Word32 *mdct_data, + Word16 curr_mode, + Word16 N ) { Word16 N1, N2, i; - Word32 low_eng = L_deposit_l(0), eng = L_deposit_l(0), smax = L_deposit_l(0); + Word32 low_eng = L_deposit_l( 0 ), eng = L_deposit_l( 0 ), smax = L_deposit_l( 0 ); Word16 nbits, temp, norm = 0; move16(); N1 = 30; N2 = N; move16(); move16(); - IF (EQ_16(2 ,curr_mode)) + IF( EQ_16( 2, curr_mode ) ) { - N1 = shr(30,1); - N2 = shr(N,1); + N1 = shr( 30, 1 ); + N2 = shr( N, 1 ); } - nbits = sub(15, norm_s(N2)); + nbits = sub( 15, norm_s( N2 ) ); - FOR (i = 0; i < N2; i++) + FOR( i = 0; i < N2; i++ ) { - smax = L_or(smax, L_abs(mdct_data[i])); + smax = L_or( smax, L_abs( mdct_data[i] ) ); } - norm = norm_l(smax); + norm = norm_l( smax ); - FOR (i = 0; i < N1; i++) + FOR( i = 0; i < N1; i++ ) { - temp = extract_h(L_shl(mdct_data[i], norm)); - low_eng = L_add(low_eng, L_shr(L_mult0(temp, temp),nbits)); + temp = extract_h( L_shl( mdct_data[i], norm ) ); + low_eng = L_add( low_eng, L_shr( L_mult0( temp, temp ), nbits ) ); } - FOR (i = N1; i < N2; i++) + FOR( i = N1; i < N2; i++ ) { - temp = extract_h(L_shl(mdct_data[i], norm)); - eng = L_add(eng, L_shr(L_mult0(temp, temp),nbits)); + temp = extract_h( L_shl( mdct_data[i], norm ) ); + eng = L_add( eng, L_shr( L_mult0( temp, temp ), nbits ) ); } - eng = L_add(low_eng, eng); + eng = L_add( low_eng, eng ); /* IF (low_eng<(eng+EPSILON)*0.02) return 1;ELSE return 0; */ /* smax=eng*0.02 */ - smax = L_shr(Mpy_32_16_1(eng, 5243), 3); + smax = L_shr( Mpy_32_16_1( eng, 5243 ), 3 ); - return (L_sub(low_eng,smax) <= 0); + return ( L_sub( low_eng, smax ) <= 0 ); } -void LpFilter2_x(Word16 *x, Word16 *y, Word16 N) +void LpFilter2_x( Word16 *x, Word16 *y, Word16 N ) { - Word16 i; + Word16 i; Word16 smax, norm; Word16 a1 = 5898; /* W16(0.18f); */ Word16 a2 = 20971; /* W16(0.64f); */ move16(); move16(); - smax=0; + smax = 0; move16(); - FOR (i = 0; i < N; i++) + FOR( i = 0; i < N; i++ ) { - smax = s_or(smax, abs_s(x[i])); + smax = s_or( smax, abs_s( x[i] ) ); } - norm = norm_s(smax); + norm = norm_s( smax ); - y[0] = mult(shl(x[0],norm), a1); + y[0] = mult( shl( x[0], norm ), a1 ); move16(); - y[1] = add(mult(y[0], a2),mult(shl(x[1],norm), a1)); + y[1] = add( mult( y[0], a2 ), mult( shl( x[1], norm ), a1 ) ); move16(); - FOR (i = 2; i < N; i++) + FOR( i = 2; i < N; i++ ) { /* 5898*2+20971=32767 -->no overflow */ - y[i] = add(mult(y[i-2],a1), add(mult(y[i-1],a2), mult(shl(x[i],norm),a1))); + y[i] = add( mult( y[i - 2], a1 ), add( mult( y[i - 1], a2 ), mult( shl( x[i], norm ), a1 ) ) ); move16(); } } -void sig_tilt_x(Word16 *s, Word16 FrameSize, Word32 *enr1, Word32 *enr2) +void sig_tilt_x( Word16 *s, Word16 FrameSize, Word32 *enr1, Word32 *enr2 ) { Word16 subFrameSize, shIFt; Word16 *p1, *p2; Word16 nbits; - subFrameSize = shr(FrameSize, 2); - p1 = s+subFrameSize; - p2 = s+sub(subFrameSize, 2); + subFrameSize = shr( FrameSize, 2 ); + p1 = s + subFrameSize; + p2 = s + sub( subFrameSize, 2 ); - shIFt = sub(FrameSize, subFrameSize); - nbits = sub(15, norm_s(shIFt)); - *enr1 = dot_w32_accuracy_x(p1, p2, nbits, shIFt); + shIFt = sub( FrameSize, subFrameSize ); + nbits = sub( 15, norm_s( shIFt ) ); + *enr1 = dot_w32_accuracy_x( p1, p2, nbits, shIFt ); move32(); - *enr2 = dot_w32_accuracy_x(p1, p1, nbits, shIFt); + *enr2 = dot_w32_accuracy_x( p1, p1, nbits, shIFt ); move32(); } -void get_maxConv_and_pitch_x(Word16 *s_LP, Word16 s, Word16 e, Word16 N, - Word32 *maxConv, Word16 *maxConv_bits, Word16 *pitch) +void get_maxConv_and_pitch_x( Word16 *s_LP, Word16 s, Word16 e, Word16 N, Word32 *maxConv, Word16 *maxConv_bits, Word16 *pitch ) { Word16 t, cov_size, size = N; - Word32 tmp_sigma = L_deposit_l(0), cov_max_sigma = L_deposit_l(0); - Word16 nbits,tmp_pitch=0; + Word32 tmp_sigma = L_deposit_l( 0 ), cov_max_sigma = L_deposit_l( 0 ); + Word16 nbits, tmp_pitch = 0; Word32 r1_high, r2_high; UWord16 r1_low, r2_low; - Word32 tmp_sigma_last = L_deposit_l(0); /* not needed, just to avoid compiler warning */ - Word16 cov_size_last = N; /* not needed, just to avoid compiler warning */ - Word32 cov_max_sigma_tmp = L_deposit_l(0); - Word16 size_tmp = N; + Word32 tmp_sigma_last = L_deposit_l( 0 ); /* not needed, just to avoid compiler warning */ + Word16 cov_size_last = N; /* not needed, just to avoid compiler warning */ + Word32 cov_max_sigma_tmp = L_deposit_l( 0 ); + Word16 size_tmp = N; move16(); move16(); - nbits = sub(15, norm_s(sub(N, s))); + nbits = sub( 15, norm_s( sub( N, s ) ) ); - FOR (t = s; t < e; t++) + FOR( t = s; t < e; t++ ) { - cov_size = sub(N,t); - tmp_sigma = dot_w32_accuracy_x(s_LP, s_LP+t, nbits, cov_size); + cov_size = sub( N, t ); + tmp_sigma = dot_w32_accuracy_x( s_LP, s_LP + t, nbits, cov_size ); - IF (GT_16(t,s)) /* don't use the first value */ + IF( GT_16( t, s ) ) /* don't use the first value */ { - Mpy_32_16_ss(tmp_sigma , cov_size_last, &r1_high, &r1_low); - Mpy_32_16_ss(tmp_sigma_last, cov_size , &r2_high, &r2_low); + Mpy_32_16_ss( tmp_sigma, cov_size_last, &r1_high, &r1_low ); + Mpy_32_16_ss( tmp_sigma_last, cov_size, &r2_high, &r2_low ); /* tmp_sigma > tmp_sigma_last */ test(); test(); move16(); move16(); /* moves are for the (Word32) casts */ - IF((GT_32(r1_high, r2_high))|| - (EQ_32(r1_high, r2_high) && GT_32((Word32)r1_low, (Word32)r2_low) )) + IF( ( GT_32( r1_high, r2_high ) ) || + ( EQ_32( r1_high, r2_high ) && GT_32( (Word32) r1_low, (Word32) r2_low ) ) ) { /* store the current cov, if it is larger than the last one */ cov_max_sigma_tmp = tmp_sigma; move32(); - size_tmp = cov_size; + size_tmp = cov_size; move16(); } ELSE { - Mpy_32_16_ss(cov_max_sigma , size_tmp, &r1_high, &r1_low); - Mpy_32_16_ss(cov_max_sigma_tmp, size , &r2_high, &r2_low); + Mpy_32_16_ss( cov_max_sigma, size_tmp, &r1_high, &r1_low ); + Mpy_32_16_ss( cov_max_sigma_tmp, size, &r2_high, &r2_low ); /* cov_max_sigma < cov_max_sigma_tmp */ test(); test(); move16(); move16(); /* moves are for the (Word32) casts */ - IF((LT_32(r1_high, r2_high))|| - (EQ_32(r1_high, r2_high) && LT_32((Word32)r1_low, (Word32)r2_low))) + IF( ( LT_32( r1_high, r2_high ) ) || + ( EQ_32( r1_high, r2_high ) && LT_32( (Word32) r1_low, (Word32) r2_low ) ) ) { /* otherwise */ /* use the last value of cov, being a max */ @@ -384,13 +380,13 @@ void get_maxConv_and_pitch_x(Word16 *s_LP, Word16 s, Word16 e, Word16 N, size = cov_size; move16(); /* and use the last index as pitch */ - tmp_pitch = sub(t,1); + tmp_pitch = sub( t, 1 ); } } } tmp_sigma_last = tmp_sigma; move32(); - cov_size_last = cov_size; + cov_size_last = cov_size; move16(); } *pitch = tmp_pitch; @@ -401,109 +397,112 @@ void get_maxConv_and_pitch_x(Word16 *s_LP, Word16 s, Word16 e, Word16 N, move16(); } -Word16 get_voicing_x(Word16 *s_LP, Word16 pitch, Word32 covMax,Word16 maxConv_bits, Word16 Framesize) +Word16 get_voicing_x( Word16 *s_LP, Word16 pitch, Word32 covMax, Word16 maxConv_bits, Word16 Framesize ) { - Word32 eng1 = L_deposit_l(0), eng2 = L_deposit_l(0); + Word32 eng1 = L_deposit_l( 0 ), eng2 = L_deposit_l( 0 ); Word16 voicing, norm; Word16 tmpLen, nbits; Word16 eng1_w, eng2_w; - IF (covMax <= 0) + IF( covMax <= 0 ) { return 0; } ELSE { - tmpLen = sub(Framesize, pitch); + tmpLen = sub( Framesize, pitch ); nbits = maxConv_bits; move16(); - eng1 = dot_w32_accuracy_x(s_LP, s_LP, nbits, tmpLen); - eng2 = dot_w32_accuracy_x(s_LP+pitch, s_LP+pitch, nbits, tmpLen); + eng1 = dot_w32_accuracy_x( s_LP, s_LP, nbits, tmpLen ); + eng2 = dot_w32_accuracy_x( s_LP + pitch, s_LP + pitch, nbits, tmpLen ); - norm = sub(norm_l(L_or(eng1, L_or(eng2, covMax))),1); - eng1 = L_shl(eng1, norm); - eng2 = L_shl(eng2, norm); - covMax = L_shl(covMax, norm); + norm = sub( norm_l( L_or( eng1, L_or( eng2, covMax ) ) ), 1 ); + eng1 = L_shl( eng1, norm ); + eng2 = L_shl( eng2, norm ); + covMax = L_shl( covMax, norm ); - eng1_w = Sqrt_x_fast(eng1); - eng2_w = Sqrt_x_fast(eng2); + eng1_w = Sqrt_x_fast( eng1 ); + eng2_w = Sqrt_x_fast( eng2 ); - eng1 = L_mult0(eng1_w, eng2_w); - norm = norm_l(eng1); - eng1_w = extract_h(L_shl(eng1, norm)); - eng2_w = extract_h(L_shl(covMax, norm)); + eng1 = L_mult0( eng1_w, eng2_w ); + norm = norm_l( eng1 ); + eng1_w = extract_h( L_shl( eng1, norm ) ); + eng2_w = extract_h( L_shl( covMax, norm ) ); - IF (GE_32(covMax , eng1)) + IF( GE_32( covMax, eng1 ) ) { return 32767; } test(); - IF ((eng2_w <= 0)||(eng1_w <= 0)) + IF( ( eng2_w <= 0 ) || ( eng1_w <= 0 ) ) { return 0; } - voicing = div_s(eng2_w, eng1_w); + voicing = div_s( eng2_w, eng1_w ); return voicing; } } -void pitch_modify_x(Word16 *s_LP, Word16 *voicing, Word16 *pitch, Word16 FrameSize) +void pitch_modify_x( Word16 *s_LP, Word16 *voicing, Word16 *pitch, Word16 FrameSize ) { Word32 eng1, eng2, eng3; - Word16 shIFt = shr(*pitch ,1); + Word16 shIFt = shr( *pitch, 1 ); Word16 tmpLen, nbits, norm, voicing2; Word16 eng1_w, eng2_w; - tmpLen = sub(FrameSize, shIFt); - nbits = sub(15, norm_s(tmpLen)); + tmpLen = sub( FrameSize, shIFt ); + nbits = sub( 15, norm_s( tmpLen ) ); - eng1 = dot_w32_accuracy_x(s_LP+shIFt, s_LP+shIFt, nbits, tmpLen); - eng2 = dot_w32_accuracy_x(s_LP, s_LP, nbits, tmpLen); - eng3 = dot_w32_accuracy_x(s_LP+shIFt, s_LP, nbits, tmpLen); + eng1 = dot_w32_accuracy_x( s_LP + shIFt, s_LP + shIFt, nbits, tmpLen ); + eng2 = dot_w32_accuracy_x( s_LP, s_LP, nbits, tmpLen ); + eng3 = dot_w32_accuracy_x( s_LP + shIFt, s_LP, nbits, tmpLen ); - IF (eng3 <= 0) + IF( eng3 <= 0 ) { - return ; + return; } - norm = sub(norm_l(L_or(eng1, L_or(eng2, eng3))),1); - eng1 = L_shl(eng1, norm); - eng2 = L_shl(eng2, norm); - eng3 = L_shl(eng3, norm); + norm = sub( norm_l( L_or( eng1, L_or( eng2, eng3 ) ) ), 1 ); + eng1 = L_shl( eng1, norm ); + eng2 = L_shl( eng2, norm ); + eng3 = L_shl( eng3, norm ); - eng1_w = Sqrt_x_fast(eng1); - eng2_w = Sqrt_x_fast(eng2); + eng1_w = Sqrt_x_fast( eng1 ); + eng2_w = Sqrt_x_fast( eng2 ); - eng1 = L_mult0(eng1_w, eng2_w); + eng1 = L_mult0( eng1_w, eng2_w ); - norm = norm_l(eng1); -#ifdef BASOP_NOGLOB - eng1_w = extract_h(L_shl_sat(eng1, norm)); - eng2_w = extract_h(L_shl_sat(eng3, norm)); + norm = norm_l( eng1 ); +#ifdef BASOP_NOGLOB + eng1_w = extract_h( L_shl_sat( eng1, norm ) ); + eng2_w = extract_h( L_shl_sat( eng3, norm ) ); #else - eng1_w = extract_h(L_shl(eng1, norm)); - eng2_w = extract_h(L_shl(eng3, norm)); + eng1_w = extract_h( L_shl( eng1, norm ) ); + eng2_w = extract_h( L_shl( eng3, norm ) ); #endif - IF (GE_32(eng3,eng1)) + IF( GE_32( eng3, eng1 ) ) { voicing2 = 32767; move16(); } - ELSE { test(); - IF ((eng2_w <= 0)||(eng1_w <= 0)) + ELSE { - voicing2 = 0; - move16(); - } - ELSE { - voicing2 = div_s(eng2_w, eng1_w); + test(); + IF( ( eng2_w <= 0 ) || ( eng1_w <= 0 ) ) + { + voicing2 = 0; + move16(); + } + ELSE + { + voicing2 = div_s( eng2_w, eng1_w ); + } } - } - IF (GT_16(voicing2, *voicing)) + IF( GT_16( voicing2, *voicing ) ) { *pitch = shIFt; move16(); @@ -512,47 +511,45 @@ void pitch_modify_x(Word16 *s_LP, Word16 *voicing, Word16 *pitch, Word16 FrameSi } } -Word16 Is_Periodic_x(Word32 *mdct_data, Word16 cov_max, Word16 zp, Word32 ener, - Word32 ener_mean, Word16 pitch, Word16 Framesize) +Word16 Is_Periodic_x( Word32 *mdct_data, Word16 cov_max, Word16 zp, Word32 ener, Word32 ener_mean, Word16 pitch, Word16 Framesize ) { - Word16 flag =0; + Word16 flag = 0; Word16 harm; move16(); test(); test(); test(); - IF (LT_32(ener, L_shl(50,8))||(LT_32(ener,L_sub(ener_mean,L_shl(8,8))) - && LT_16(cov_max, 29491) )) + IF( LT_32( ener, L_shl( 50, 8 ) ) || ( LT_32( ener, L_sub( ener_mean, L_shl( 8, 8 ) ) ) && LT_16( cov_max, 29491 ) ) ) { flag = 0; move16(); } - ELSE IF (GT_16(cov_max, 26214)) + ELSE IF( GT_16( cov_max, 26214 ) ) { flag = 1; move16(); } - ELSE IF (GT_16(zp, 100)) + ELSE IF( GT_16( zp, 100 ) ) { flag = 0; move16(); } - ELSE IF (LT_32(ener, L_sub(ener_mean,L_shl(6,8)))) + ELSE IF( LT_32( ener, L_sub( ener_mean, L_shl( 6, 8 ) ) ) ) { flag = 0; move16(); } - ELSE IF (GT_32(ener, L_add(ener_mean, L_shl(1,8)))&>_16(cov_max,19661)) + ELSE IF( GT_32( ener, L_add( ener_mean, L_shl( 1, 8 ) ) ) && GT_16( cov_max, 19661 ) ) { flag = 1; move16(); } ELSE { - harm = harmo_x(mdct_data, Framesize, pitch); + harm = harmo_x( mdct_data, Framesize, pitch ); flag = 1; move16(); - if (LT_16(harm, 22938)) + if ( LT_16( harm, 22938 ) ) { flag = 0; move16(); @@ -562,73 +559,71 @@ Word16 Is_Periodic_x(Word32 *mdct_data, Word16 cov_max, Word16 zp, Word32 ener, return flag; } -Word16 get_conv_relation_x(Word16 *s_LP, Word16 shIFt, Word16 N) +Word16 get_conv_relation_x( Word16 *s_LP, Word16 shIFt, Word16 N ) { - Word32 eng1,eng2, eng3; + Word32 eng1, eng2, eng3; Word16 eng1_w, eng2_w; Word16 tmp, norm, nbits; - nbits = sub(15, norm_s(N)); - eng3 = dot_w32_accuracy_x(s_LP, s_LP+shIFt, nbits, N); + nbits = sub( 15, norm_s( N ) ); + eng3 = dot_w32_accuracy_x( s_LP, s_LP + shIFt, nbits, N ); - IF (eng3 <= 0) + IF( eng3 <= 0 ) { return 0; } - eng1 = dot_w32_accuracy_x(s_LP+shIFt, s_LP+shIFt, nbits, N); - eng2 = dot_w32_accuracy_x(s_LP, s_LP, nbits, N); + eng1 = dot_w32_accuracy_x( s_LP + shIFt, s_LP + shIFt, nbits, N ); + eng2 = dot_w32_accuracy_x( s_LP, s_LP, nbits, N ); - norm = sub(norm_l(L_or(eng1, L_or(eng2, eng3))),1); - eng1 = L_shl(eng1, norm); - eng2 = L_shl(eng2, norm); - eng3 = L_shl(eng3, norm); + norm = sub( norm_l( L_or( eng1, L_or( eng2, eng3 ) ) ), 1 ); + eng1 = L_shl( eng1, norm ); + eng2 = L_shl( eng2, norm ); + eng3 = L_shl( eng3, norm ); - eng1_w = Sqrt_x_fast(eng1); - eng2_w = Sqrt_x_fast(eng2); + eng1_w = Sqrt_x_fast( eng1 ); + eng2_w = Sqrt_x_fast( eng2 ); - eng1 = L_mult0(eng1_w, eng2_w); + eng1 = L_mult0( eng1_w, eng2_w ); - norm = norm_l(eng1); - eng1_w = extract_h(L_shl(eng1, norm)); - eng2_w = extract_h(L_shl(eng3, norm)); + norm = norm_l( eng1 ); + eng1_w = extract_h( L_shl( eng1, norm ) ); + eng2_w = extract_h( L_shl( eng3, norm ) ); - IF (GE_32(eng3, eng1)) + IF( GE_32( eng3, eng1 ) ) { return 32767; } test(); - IF ((eng2_w <= 0)||(eng1_w <= 0)) + IF( ( eng2_w <= 0 ) || ( eng1_w <= 0 ) ) { return 0; } - tmp = div_s(eng2_w, eng1_w); + tmp = div_s( eng2_w, eng1_w ); return tmp; } -static -Word16 pitch_search_fx(Word16 *s, /* lastPcmOut */ - Word16 *outx_new, - Word16 Framesize, - Word16 *voicing, - Word16 zp, - Word32 ener, - Word32 ener_mean, - Word32 *mdct_data, - Word16 curr_mode - ) +static Word16 pitch_search_fx( Word16 *s, /* lastPcmOut */ + Word16 *outx_new, + Word16 Framesize, + Word16 *voicing, + Word16 zp, + Word32 ener, + Word32 ener_mean, + Word32 *mdct_data, + Word16 curr_mode ) { Word16 pitch = 0; - Word32 cov_max = L_deposit_l(0), tilt_enr1, tilt_enr2; + Word32 cov_max = L_deposit_l( 0 ), tilt_enr1, tilt_enr2; Word16 s_LP[L_FRAME_MAX]; Word16 start_pos, end_pos; Word16 low_freq_rate_result; Word16 flag = 0, zp_current; Word32 *mdctPtr; Word16 curr_frmsize; - Word16 cov_max_bits=0; + Word16 cov_max_bits = 0; Word16 i; move16(); move16(); @@ -637,54 +632,54 @@ Word16 pitch_search_fx(Word16 *s, /* lastPcmOut */ move16(); curr_frmsize = Framesize; move16(); - if (EQ_16(2, curr_mode)) + if ( EQ_16( 2, curr_mode ) ) { - curr_frmsize = shr(Framesize, 1); + curr_frmsize = shr( Framesize, 1 ); } - zp_current = zero_pass_w32_x(outx_new, curr_frmsize); + zp_current = zero_pass_w32_x( outx_new, curr_frmsize ); - if (EQ_16(2, curr_mode)) + if ( EQ_16( 2, curr_mode ) ) { - zp_current = shl(zp_current,1); + zp_current = shl( zp_current, 1 ); } - IF (LE_16(Framesize, 256)) + IF( LE_16( Framesize, 256 ) ) { - IF (GT_16(zp_current, 70)) + IF( GT_16( zp_current, 70 ) ) { return 0; } } ELSE { - IF (GT_16(zp_current, 105)) + IF( GT_16( zp_current, 105 ) ) { return 0; } } mdctPtr = mdct_data; - if (EQ_16(2, curr_mode)) + if ( EQ_16( 2, curr_mode ) ) { - mdctPtr = mdct_data + shr(Framesize,1); + mdctPtr = mdct_data + shr( Framesize, 1 ); } - low_freq_rate_result = get_low_freq_eng_rate_x(mdctPtr, - curr_mode, - Framesize); + low_freq_rate_result = get_low_freq_eng_rate_x( mdctPtr, + curr_mode, + Framesize ); - IF(low_freq_rate_result) + IF( low_freq_rate_result ) { return 0; } - LpFilter2_x(s, s_LP, Framesize); - sig_tilt_x(s_LP, Framesize, &tilt_enr1, &tilt_enr2); - IF (LE_16(Framesize, 320)) + LpFilter2_x( s, s_LP, Framesize ); + sig_tilt_x( s_LP, Framesize, &tilt_enr1, &tilt_enr2 ); + IF( LE_16( Framesize, 320 ) ) { test(); - IF ((0==tilt_enr2) || - (LT_32(tilt_enr1, L_shr(tilt_enr2, 1)) )) + IF( ( 0 == tilt_enr2 ) || + ( LT_32( tilt_enr1, L_shr( tilt_enr2, 1 ) ) ) ) { return 0; } @@ -692,21 +687,21 @@ Word16 pitch_search_fx(Word16 *s, /* lastPcmOut */ ELSE { test(); - IF ((0==tilt_enr2) || - (LT_32(tilt_enr1, Mpy_32_16_1(tilt_enr2, 22938)) )) + IF( ( 0 == tilt_enr2 ) || + ( LT_32( tilt_enr1, Mpy_32_16_1( tilt_enr2, 22938 ) ) ) ) { return 0; } } - IF (LE_16(Framesize, 320)) + IF( LE_16( Framesize, 320 ) ) { - start_pos = extract_l(L_shr(L_mac0(0x80, 34, Framesize), 8)); - end_pos = extract_l(L_shr(L_mac0(0x2 , 3, Framesize), 2)); - get_maxConv_and_pitch_x(s_LP, start_pos, end_pos, Framesize, &cov_max, &cov_max_bits, &pitch); - *voicing = get_voicing_x(s_LP, pitch, cov_max, cov_max_bits, Framesize); + start_pos = extract_l( L_shr( L_mac0( 0x80, 34, Framesize ), 8 ) ); + end_pos = extract_l( L_shr( L_mac0( 0x2, 3, Framesize ), 2 ) ); + get_maxConv_and_pitch_x( s_LP, start_pos, end_pos, Framesize, &cov_max, &cov_max_bits, &pitch ); + *voicing = get_voicing_x( s_LP, pitch, cov_max, cov_max_bits, Framesize ); move16(); - pitch_modify_x(s_LP, voicing, &pitch, Framesize); + pitch_modify_x( s_LP, voicing, &pitch, Framesize ); } ELSE { @@ -715,43 +710,43 @@ Word16 pitch_search_fx(Word16 *s, /* lastPcmOut */ Word16 pitch_tmp[3]; Word16 cov_size; - Framesize_tmp = shr(Framesize, 1); - FOR (i = 0; i < Framesize_tmp; i++) + Framesize_tmp = shr( Framesize, 1 ); + FOR( i = 0; i < Framesize_tmp; i++ ) { - s_tmp[i] = s_LP[2*i]; + s_tmp[i] = s_LP[2 * i]; move16(); } - start_pos = extract_l( L_shr(L_mac0(0x80, 34, Framesize_tmp), 8)); - end_pos = extract_l( L_shr(L_mac0(0x2, 3, Framesize_tmp), 2)); + start_pos = extract_l( L_shr( L_mac0( 0x80, 34, Framesize_tmp ), 8 ) ); + end_pos = extract_l( L_shr( L_mac0( 0x2, 3, Framesize_tmp ), 2 ) ); - cov_max = L_deposit_l(0); + cov_max = L_deposit_l( 0 ); pitch = 0; move16(); - get_maxConv_and_pitch_x(s_tmp, start_pos, end_pos, Framesize_tmp, &cov_max, &cov_max_bits, &pitch); + get_maxConv_and_pitch_x( s_tmp, start_pos, end_pos, Framesize_tmp, &cov_max, &cov_max_bits, &pitch ); - IF (pitch > 0) + IF( pitch > 0 ) { pitch_tmp[0] = 0; move16(); - if (GT_16(shl(pitch, 1), 1)) + if ( GT_16( shl( pitch, 1 ), 1 ) ) { - pitch_tmp[0] = sub(shl(pitch, 1), 1); + pitch_tmp[0] = sub( shl( pitch, 1 ), 1 ); move16(); } - pitch_tmp[1] = shl(pitch, 1); + pitch_tmp[1] = shl( pitch, 1 ); move16(); - pitch_tmp[2] = add(shl(pitch, 1), 1); + pitch_tmp[2] = add( shl( pitch, 1 ), 1 ); move16(); start_pos = 0; move16(); pitch = 0; move16(); - FOR (i = 0; i < 3; i++) + FOR( i = 0; i < 3; i++ ) { - cov_size = sub(Framesize, pitch_tmp[i]); - end_pos = get_conv_relation_x(s_LP, pitch_tmp[i], cov_size); - IF (GT_16(end_pos, start_pos)) + cov_size = sub( Framesize, pitch_tmp[i] ); + end_pos = get_conv_relation_x( s_LP, pitch_tmp[i], cov_size ); + IF( GT_16( end_pos, start_pos ) ) { start_pos = end_pos; move16(); @@ -764,11 +759,11 @@ Word16 pitch_search_fx(Word16 *s, /* lastPcmOut */ } } - IF (pitch > 0) + IF( pitch > 0 ) { - flag = Is_Periodic_x(mdct_data, *voicing, zp, ener, ener_mean, pitch, Framesize); + flag = Is_Periodic_x( mdct_data, *voicing, zp, ener, ener_mean, pitch, Framesize ); } - if (flag == 0 ) + if ( flag == 0 ) { pitch = 0; move16(); @@ -776,9 +771,9 @@ Word16 pitch_search_fx(Word16 *s, /* lastPcmOut */ return pitch; } -void concealment_init_x(Word16 N, void *_plcInfo) +void concealment_init_x( Word16 N, void *_plcInfo ) { - T_PLCInfo *plcInfo = (T_PLCInfo*)_plcInfo; + T_PLCInfo *plcInfo = (T_PLCInfo *) _plcInfo; Word16 i; plcInfo->FrameSize = N; @@ -793,8 +788,8 @@ void concealment_init_x(Word16 N, void *_plcInfo) move16(); plcInfo->nsapp_gain_n_fx = 0; move16(); - plcInfo->ener_mean_fx = L_deposit_l(15213); /*Q8 59.4260f*256*/ - plcInfo->ener_fx = L_deposit_l(0); + plcInfo->ener_mean_fx = L_deposit_l( 15213 ); /*Q8 59.4260f*256*/ + plcInfo->ener_fx = L_deposit_l( 0 ); plcInfo->zp_fx = N; move16(); plcInfo->recovery_gain = 0; @@ -805,30 +800,30 @@ void concealment_init_x(Word16 N, void *_plcInfo) move16(); plcInfo->subframe_fx = 0; move16(); - plcInfo->nbLostCmpt = (int16_t)L_deposit_l(0); + plcInfo->nbLostCmpt = (int16_t) L_deposit_l( 0 ); plcInfo->seed = 21845; move16(); - FOR (i = 0; i < TCX_TONALITY_INIT_CNT; i++) + FOR( i = 0; i < TCX_TONALITY_INIT_CNT; i++ ) { plcInfo->TCX_Tonality[i] = 1; move16(); } - FOR (i = TCX_TONALITY_INIT_CNT; i < DEC_STATE_LEN; i++) + FOR( i = TCX_TONALITY_INIT_CNT; i < DEC_STATE_LEN; i++ ) { plcInfo->TCX_Tonality[i] = 0; move16(); } - FOR (i = 0; i < MAX_POST_LEN; i++) + FOR( i = 0; i < MAX_POST_LEN; i++ ) { plcInfo->Transient[i] = 1; move16(); } - FOR (i = 0; i < L_FRAME_MAX; i++) + FOR( i = 0; i < L_FRAME_MAX; i++ ) { - plcInfo->data_reci2_fx[i] = L_deposit_l(0); + plcInfo->data_reci2_fx[i] = L_deposit_l( 0 ); } return; } @@ -867,7 +862,7 @@ void concealment_init_ivas_fx( hPlcInfo->subframe = 0; hPlcInfo->subframe_fx = 0; move16(); - hPlcInfo->nbLostCmpt = (Word16)L_deposit_l( 0 ); + hPlcInfo->nbLostCmpt = (Word16) L_deposit_l( 0 ); hPlcInfo->seed = RANDOM_INITSEED; move16(); @@ -895,37 +890,37 @@ void concealment_init_ivas_fx( } #endif // IVAS_FLOAT_FIXED -static Word16 own_random_fix( /* o : output random value */ - Word16 *seed /* i/o: random seed */ +static Word16 own_random_fix( /* o : output random value */ + Word16 *seed /* i/o: random seed */ ) { - *seed = extract_l(L_mac0(13849L, *seed , 31821)); - return(*seed); + *seed = extract_l( L_mac0( 13849L, *seed, 31821 ) ); + return ( *seed ); } -void concealment_decode_fix(Word16 curr_mode, Word32 *invkoef, Word16 *invkoef_scale,void *_plcInfo) +void concealment_decode_fix( Word16 curr_mode, Word32 *invkoef, Word16 *invkoef_scale, void *_plcInfo ) { - T_PLCInfo *plcInfo = (T_PLCInfo*)_plcInfo; + T_PLCInfo *plcInfo = (T_PLCInfo *) _plcInfo; Word16 i; Word16 N = plcInfo->FrameSize; - Word16 *seed = &(plcInfo->seed); + Word16 *seed = &( plcInfo->seed ); Word16 sign; move16(); - IF (plcInfo->concealment_method == TCX_NONTONAL) /* #define TCX_NONTONAL 0 */ + IF( plcInfo->concealment_method == TCX_NONTONAL ) /* #define TCX_NONTONAL 0 */ { - IF (EQ_16(curr_mode, 1)) + IF( EQ_16( curr_mode, 1 ) ) { /* copy the data of the last frame */ - mvr2r_Word32(plcInfo->data_reci2_fx, invkoef, N); + mvr2r_Word32( plcInfo->data_reci2_fx, invkoef, N ); *invkoef_scale = plcInfo->data_reci2_scale; move16(); /* sign randomization */ - FOR (i = 0; i < N; i++) + FOR( i = 0; i < N; i++ ) { - sign = add(shl(shr(own_random_fix(seed),15),1),1); - if(EQ_16(sign,-1)) + sign = add( shl( shr( own_random_fix( seed ), 15 ), 1 ), 1 ); + if ( EQ_16( sign, -1 ) ) { - invkoef[i] = L_negate(invkoef[i]); + invkoef[i] = L_negate( invkoef[i] ); move32(); } } @@ -935,49 +930,48 @@ void concealment_decode_fix(Word16 curr_mode, Word32 *invkoef, Word16 *invkoef_s } -Word16 Spl_GetScalingSquare_x(const Word16 *in_vector, const Word16 in_vector_length, Word16 times) +Word16 Spl_GetScalingSquare_x( const Word16 *in_vector, const Word16 in_vector_length, Word16 times ) { - Word16 nbits = sub(15, norm_s(times))/*Spl_GetSizeInBits_x(times)*/; + Word16 nbits = sub( 15, norm_s( times ) ) /*Spl_GetSizeInBits_x(times)*/; Word16 i; Word16 smax = -1; Word16 sabs; const Word16 *sptr = in_vector; Word16 t; move16(); - FOR (i = in_vector_length; i > 0; i--) + FOR( i = in_vector_length; i > 0; i-- ) { - sabs = abs_s(*sptr); + sabs = abs_s( *sptr ); sptr++; - smax = s_max(sabs, smax); - + smax = s_max( sabs, smax ); } - t = norm_l(L_mult0(smax, smax)); + t = norm_l( L_mult0( smax, smax ) ); - IF (smax == 0) + IF( smax == 0 ) { return 0; /* Since norm(0) returns 0 */ } ELSE { - nbits = sub(nbits, t); - nbits = s_max(0,nbits); + nbits = sub( nbits, t ); + nbits = s_max( 0, nbits ); return nbits; } } -Word32 Spl_Energy_x(const Word16* vector, const Word16 vector_length, Word16* scale_factor) +Word32 Spl_Energy_x( const Word16 *vector, const Word16 vector_length, Word16 *scale_factor ) { - Word32 en = L_deposit_l(0); + Word32 en = L_deposit_l( 0 ); Word32 i; - Word16 scaling = Spl_GetScalingSquare_x(vector, vector_length, vector_length); + Word16 scaling = Spl_GetScalingSquare_x( vector, vector_length, vector_length ); - FOR (i = 0; i < vector_length; i++) + FOR( i = 0; i < vector_length; i++ ) { - en = L_add(en,L_shr(L_mult0(vector[i], vector[i]), scaling)); + en = L_add( en, L_shr( L_mult0( vector[i], vector[i] ), scaling ) ); } move32(); @@ -986,30 +980,30 @@ Word32 Spl_Energy_x(const Word16* vector, const Word16 vector_length, Word16* sc return en; } -void Log10OfEnergy_x(const Word16 *s, Word32 *enerlogval, const Word16 len) +void Log10OfEnergy_x( const Word16 *s, Word32 *enerlogval, const Word16 len ) { - Word32 energy = L_deposit_l(0), tmp2 = L_deposit_l(0); + Word32 energy = L_deposit_l( 0 ), tmp2 = L_deposit_l( 0 ); Word16 shfts = 0; - Word32 Log10_energy = L_deposit_l(0), Log10_len = L_deposit_l(0); + Word32 Log10_energy = L_deposit_l( 0 ), Log10_len = L_deposit_l( 0 ); move16(); - energy = Spl_Energy_x(s, len, &shfts);/* Q:-shfts */ - IF (energy > 0) + energy = Spl_Energy_x( s, len, &shfts ); /* Q:-shfts */ + IF( energy > 0 ) { - Log10_energy = con_Log10(energy, negate(shfts)); /* Q25 */ - Log10_len = con_Log10(L_deposit_l(len), 0); /* Q25 */ - tmp2 = L_sub(Log10_energy,Log10_len); /* Q25 */ - tmp2 = Mpy_32_16_1(tmp2,20480); /* Q11->10 Q=25+11-15=21 */ - *enerlogval = L_shr(tmp2,13); /* Q8 */ move32(); + Log10_energy = con_Log10( energy, negate( shfts ) ); /* Q25 */ + Log10_len = con_Log10( L_deposit_l( len ), 0 ); /* Q25 */ + tmp2 = L_sub( Log10_energy, Log10_len ); /* Q25 */ + tmp2 = Mpy_32_16_1( tmp2, 20480 ); /* Q11->10 Q=25+11-15=21 */ + *enerlogval = L_shr( tmp2, 13 ); /* Q8 */ + move32(); } ELSE { *enerlogval = -25600; move32(); } - } -static Word32 fnLog2(Word32 L_Input) +static Word32 fnLog2( Word32 L_Input ) { Word16 swC0 = -0x2b2a, swC1 = 0x7fc5, swC2 = -0x54d0; @@ -1027,46 +1021,46 @@ static Word32 fnLog2(Word32 L_Input) /* normalize input and store shIFts required */ /* ----------------------------------------- */ - siShIFtCnt = norm_l(L_Input); - LwIn = L_shl(L_Input, siShIFtCnt); - siShIFtCnt = add(siShIFtCnt, 1); - siShIFtCnt = negate(siShIFtCnt); + siShIFtCnt = norm_l( L_Input ); + LwIn = L_shl( L_Input, siShIFtCnt ); + siShIFtCnt = add( siShIFtCnt, 1 ); + siShIFtCnt = negate( siShIFtCnt ); /* calculate x*x*c0 */ /* ---------------- */ - swIn = extract_h(LwIn); - swInSqrd = mult_r(swIn, swIn); - LwIn = L_mult(swInSqrd, swC0); + swIn = extract_h( LwIn ); + swInSqrd = mult_r( swIn, swIn ); + LwIn = L_mult( swInSqrd, swC0 ); /* add x*c1 */ /* --------- */ - LwIn = L_mac(LwIn, swIn, swC1); + LwIn = L_mac( LwIn, swIn, swC1 ); /* add c2 */ /* ------ */ - LwIn = L_add(LwIn, L_deposit_h(swC2)); + LwIn = L_add( LwIn, L_deposit_h( swC2 ) ); /* apply *(4/32) */ /* ------------- */ - LwIn = L_shr(LwIn, 3); - LwIn = L_and(LwIn, 0x03ffffff); - siShIFtCnt = shl(siShIFtCnt, 10); - LwIn = L_add(LwIn, L_deposit_h(siShIFtCnt)); + LwIn = L_shr( LwIn, 3 ); + LwIn = L_and( LwIn, 0x03ffffff ); + siShIFtCnt = shl( siShIFtCnt, 10 ); + LwIn = L_add( LwIn, L_deposit_h( siShIFtCnt ) ); /* return log2 */ /* ----------- */ - return (LwIn); + return ( LwIn ); } -static Word32 fnLog10(Word32 L_Input) +static Word32 fnLog10( Word32 L_Input ) { - Word16 Scale = 9864; /* 0.30103 = log10(2) */ + Word16 Scale = 9864; /* 0.30103 = log10(2) */ Word32 LwIn; move16(); /*_________________________________________________________________________ @@ -1078,59 +1072,60 @@ static Word32 fnLog10(Word32 L_Input) /* 0.30103*log2(x) */ /* ------------------- */ - LwIn = fnLog2(L_Input); - LwIn = Mpy_32_16_1(LwIn, Scale); + LwIn = fnLog2( L_Input ); + LwIn = Mpy_32_16_1( LwIn, Scale ); - return (LwIn); + return ( LwIn ); } -Word32 con_Log10(Word32 i_s32Val, Word16 i_s16Q) +Word32 con_Log10( Word32 i_s32Val, Word16 i_s16Q ) { Word32 s32Out; - Word32 s32Correct; /* corrected (31-q)*log10(2) */ - const Word16 s16Log10_2 = 19728; /* log10(2)~Q16 */ move16(); + Word32 s32Correct; /* corrected (31-q)*log10(2) */ + const Word16 s16Log10_2 = 19728; /* log10(2)~Q16 */ + move16(); - IF(0 == i_s32Val) + IF( 0 == i_s32Val ) { return EVS_LW_MIN; } - s32Out = fnLog10(i_s32Val); /* (2^26)*log10(a) */ + s32Out = fnLog10( i_s32Val ); /* (2^26)*log10(a) */ - s32Correct = L_mult(sub(31,i_s16Q), s16Log10_2); /* q = 17 */ - s32Correct = L_shl(s32Correct, 8); /* q = 25 */ - s32Out = L_shr(s32Out, 1); /* q = 25 */ + s32Correct = L_mult( sub( 31, i_s16Q ), s16Log10_2 ); /* q = 17 */ + s32Correct = L_shl( s32Correct, 8 ); /* q = 25 */ + s32Out = L_shr( s32Out, 1 ); /* q = 25 */ - s32Out = L_add(s32Out, s32Correct); + s32Out = L_add( s32Out, s32Correct ); return s32Out; } -void concealment_update2_x(const Word16 *outx_new, void *_plcInfo, const Word16 FrameSize) +void concealment_update2_x( const Word16 *outx_new, void *_plcInfo, const Word16 FrameSize ) { - T_PLCInfo *plcInfo = (T_PLCInfo*)_plcInfo; + T_PLCInfo *plcInfo = (T_PLCInfo *) _plcInfo; - plcInfo->zp_fx = zero_pass_w32_x(outx_new, FrameSize); + plcInfo->zp_fx = zero_pass_w32_x( outx_new, FrameSize ); move16(); - Log10OfEnergy_x(outx_new, &plcInfo->ener_fx, FrameSize); /* Q8 */ + Log10OfEnergy_x( outx_new, &plcInfo->ener_fx, FrameSize ); /* Q8 */ test(); - IF (LT_16(plcInfo->zp_fx, 100)&>_32(plcInfo->ener_fx,L_shl(50,8))) + IF( LT_16( plcInfo->zp_fx, 100 ) && GT_32( plcInfo->ener_fx, L_shl( 50, 8 ) ) ) { - plcInfo->ener_mean_fx = L_add(Mpy_32_16_1(plcInfo->ener_mean_fx ,32112/* 0.98 Q15 */), - Mpy_32_16_1(plcInfo->ener_fx , 655/* 0.02 Q15 */)); + plcInfo->ener_mean_fx = L_add( Mpy_32_16_1( plcInfo->ener_mean_fx, 32112 /* 0.98 Q15 */ ), + Mpy_32_16_1( plcInfo->ener_fx, 655 /* 0.02 Q15 */ ) ); move32(); } return; } -static Word16 array_max_indx_fx(Word16 *s, Word16 N) +static Word16 array_max_indx_fx( Word16 *s, Word16 N ) { Word16 i, indx = 0; move16(); - FOR (i = 0; i < N; i++) + FOR( i = 0; i < N; i++ ) { - if (GT_16(s[i], s[indx])) + if ( GT_16( s[i], s[indx] ) ) { indx = i; move16(); @@ -1139,9 +1134,9 @@ static Word16 array_max_indx_fx(Word16 *s, Word16 N) return indx; } -Word16 ffr_getSfWord16( /* o: measured headroom in range [0..15], 0 IF all x[i] == 0 */ - Word16 *x, /* i: array containing 16-bit data */ - Word16 len_x) /* i: length of the array to scan */ +Word16 ffr_getSfWord16( /* o: measured headroom in range [0..15], 0 IF all x[i] == 0 */ + Word16 *x, /* i: array containing 16-bit data */ + Word16 len_x ) /* i: length of the array to scan */ { Word16 i, i_min, i_max; Word16 x_min, x_max; @@ -1151,12 +1146,12 @@ Word16 ffr_getSfWord16( /* o: measured headroom in range [0..15] move16(); x_min = 0; move16(); - FOR (i = 0; i < len_x; i++) + FOR( i = 0; i < len_x; i++ ) { - if (x[i] >= 0) - x_max = s_max(x_max,x[i]); - if (x[i] < 0) - x_min = s_min(x_min,x[i]); + if ( x[i] >= 0 ) + x_max = s_max( x_max, x[i] ); + if ( x[i] < 0 ) + x_min = s_min( x_min, x[i] ); } i_max = 0x10; @@ -1164,73 +1159,72 @@ Word16 ffr_getSfWord16( /* o: measured headroom in range [0..15] i_min = 0x10; move16(); - if (x_max != 0) - i_max = norm_s(x_max); + if ( x_max != 0 ) + i_max = norm_s( x_max ); - if (x_min != 0) - i_min = norm_s(x_min); + if ( x_min != 0 ) + i_min = norm_s( x_min ); - i = s_and(s_min(i_max, i_min),0xF); + i = s_and( s_min( i_max, i_min ), 0xF ); return i; } -static Word16 OverlapAdd_fx(Word16 *pitch125_data, Word16 *sbuf, - Word16 n, Word16 pitch, Word16 Framesize) +static Word16 OverlapAdd_fx( Word16 *pitch125_data, Word16 *sbuf, Word16 n, Word16 pitch, Word16 Framesize ) { - Word16 n1,n2,s,s16MaxCoefNorm,s16MaxCoefNorm2,tmp16; + Word16 n1, n2, s, s16MaxCoefNorm, s16MaxCoefNorm2, tmp16; Word16 i; - Word16 pitch125 =extract_l(L_shr(L_add(L_add(L_deposit_h(pitch), L_mult(pitch, 8192)), 32768) ,16)); - Word16 Loverlap = sub(pitch125,pitch); - Word16 Framesize_sub_n = sub(Framesize, n); + Word16 pitch125 = extract_l( L_shr( L_add( L_add( L_deposit_h( pitch ), L_mult( pitch, 8192 ) ), 32768 ), 16 ) ); + Word16 Loverlap = sub( pitch125, pitch ); + Word16 Framesize_sub_n = sub( Framesize, n ); n1 = Framesize_sub_n; move16(); n2 = Framesize_sub_n; move16(); - if(LT_16(Loverlap, Framesize_sub_n)) + if ( LT_16( Loverlap, Framesize_sub_n ) ) { n1 = Loverlap; move16(); } - if(LT_16(pitch125, Framesize_sub_n)) + if ( LT_16( pitch125, Framesize_sub_n ) ) { n2 = pitch125; move16(); } - s16MaxCoefNorm = sub(ffr_getSfWord16(sbuf+n, n1),1); - s16MaxCoefNorm2 = ffr_getSfWord16(pitch125_data, n1); - Loverlap = s_max(1, Loverlap); - tmp16 =BASOP_Util_Divide1616_Scale(1, Loverlap,&s); - FOR (i = 0; i < n1; i++) + s16MaxCoefNorm = sub( ffr_getSfWord16( sbuf + n, n1 ), 1 ); + s16MaxCoefNorm2 = ffr_getSfWord16( pitch125_data, n1 ); + Loverlap = s_max( 1, Loverlap ); + tmp16 = BASOP_Util_Divide1616_Scale( 1, Loverlap, &s ); + FOR( i = 0; i < n1; i++ ) { Word16 tmp; Word16 dat; - dat= shl(sbuf[n+i],s16MaxCoefNorm); - tmp = extract_l(L_shl(L_mult0(i, tmp16), s)); /* q15 */ - sbuf[n+i] = round_fx(L_add(L_shr(L_mult(dat, sub(32767,tmp)),s16MaxCoefNorm), - L_shr(L_mult(shl(pitch125_data[i],s16MaxCoefNorm2),tmp),s16MaxCoefNorm2))); + dat = shl( sbuf[n + i], s16MaxCoefNorm ); + tmp = extract_l( L_shl( L_mult0( i, tmp16 ), s ) ); /* q15 */ + sbuf[n + i] = round_fx( L_add( L_shr( L_mult( dat, sub( 32767, tmp ) ), s16MaxCoefNorm ), + L_shr( L_mult( shl( pitch125_data[i], s16MaxCoefNorm2 ), tmp ), s16MaxCoefNorm2 ) ) ); } - FOR (i = n1; i < n2; i++) + FOR( i = n1; i < n2; i++ ) { - sbuf[n+i] = pitch125_data[i]; + sbuf[n + i] = pitch125_data[i]; move16(); } - pitch = add(n, pitch); + pitch = add( n, pitch ); return pitch; } -static void add_noise (Word16 * const sbuf, - Word16 * const outx_new_n1, - Word16 const* const noise_seg, - Word16 const Len, - Word16 * const gain, - Word16 const* const gain_n, - Word8 const firstFrame) +static void add_noise( Word16 *const sbuf, + Word16 *const outx_new_n1, + Word16 const *const noise_seg, + Word16 const Len, + Word16 *const gain, + Word16 const *const gain_n, + Word8 const firstFrame ) { Word16 i; Word16 temp_OUT; @@ -1238,69 +1232,68 @@ static void add_noise (Word16 * const sbuf, IF( !firstFrame ) { #ifdef BASOP_NOGLOB - temp_OUT = sub_sat(noise_seg[0], mult((*outx_new_n1),22282/* 0.68 Q15 */)); - sbuf[0] = add_sat(sbuf[0], mult((temp_OUT), *gain)); + temp_OUT = sub_sat( noise_seg[0], mult( ( *outx_new_n1 ), 22282 /* 0.68 Q15 */ ) ); + sbuf[0] = add_sat( sbuf[0], mult( ( temp_OUT ), *gain ) ); move16(); - *gain = mac_r_sat(L_mult_sat(32439/* 0.99 Q15 */,*gain),328/* 0.01 Q15 */,*gain_n); + *gain = mac_r_sat( L_mult_sat( 32439 /* 0.99 Q15 */, *gain ), 328 /* 0.01 Q15 */, *gain_n ); #else - temp_OUT = sub(noise_seg[0], mult((*outx_new_n1),22282/* 0.68 Q15 */)); - sbuf[0] = add(sbuf[0], mult((temp_OUT), *gain)); + temp_OUT = sub( noise_seg[0], mult( ( *outx_new_n1 ), 22282 /* 0.68 Q15 */ ) ); + sbuf[0] = add( sbuf[0], mult( ( temp_OUT ), *gain ) ); move16(); - *gain = mac_r(L_mult(32439/* 0.99 Q15 */,*gain),328/* 0.01 Q15 */,*gain_n); + *gain = mac_r( L_mult( 32439 /* 0.99 Q15 */, *gain ), 328 /* 0.01 Q15 */, *gain_n ); #endif } FOR( i = 1; i < Len; i++ ) { #ifdef BASOP_NOGLOB - temp_OUT = sub_sat(noise_seg[i], mult((noise_seg[i-1]),22282/* 0.68 Q15 */)); - sbuf[i] = add_sat(sbuf[i], mult((temp_OUT), *gain)); + temp_OUT = sub_sat( noise_seg[i], mult( ( noise_seg[i - 1] ), 22282 /* 0.68 Q15 */ ) ); + sbuf[i] = add_sat( sbuf[i], mult( ( temp_OUT ), *gain ) ); move16(); - *gain = mac_r_sat(L_mult(32439/* 0.99 Q15 */,*gain),328/* 0.01 Q15 */,*gain_n); + *gain = mac_r_sat( L_mult( 32439 /* 0.99 Q15 */, *gain ), 328 /* 0.01 Q15 */, *gain_n ); #else - temp_OUT = sub(noise_seg[i], mult((noise_seg[i-1]),22282/* 0.68 Q15 */)); - sbuf[i] = add(sbuf[i], mult((temp_OUT), *gain)); + temp_OUT = sub( noise_seg[i], mult( ( noise_seg[i - 1] ), 22282 /* 0.68 Q15 */ ) ); + sbuf[i] = add( sbuf[i], mult( ( temp_OUT ), *gain ) ); move16(); - *gain = mac_r(L_mult(32439/* 0.99 Q15 */,*gain),328/* 0.01 Q15 */,*gain_n); + *gain = mac_r( L_mult( 32439 /* 0.99 Q15 */, *gain ), 328 /* 0.01 Q15 */, *gain_n ); #endif } - *outx_new_n1 = noise_seg[i-1]; /*q0*/ + *outx_new_n1 = noise_seg[i - 1]; /*q0*/ return; } -static -Word16 waveform_adj_fix(Word16 *overlapbuf, - Word16 *outdata2, - Word16 *outx_new, - Word16 *data_noise, - Word16 *outx_new_n1, - Word16 *nsapp_gain, - Word16 *nsapp_gain_n, - Word16 Framesize, - Word8 T_bfi, - Word16 voicing, - Word16 curr_mode, - Word16 pitch) +static Word16 waveform_adj_fix( Word16 *overlapbuf, + Word16 *outdata2, + Word16 *outx_new, + Word16 *data_noise, + Word16 *outx_new_n1, + Word16 *nsapp_gain, + Word16 *nsapp_gain_n, + Word16 Framesize, + Word8 T_bfi, + Word16 voicing, + Word16 curr_mode, + Word16 pitch ) { - Word16 i, zp1, zp2,Framesizediv2,s16MaxCoefNorm; + Word16 i, zp1, zp2, Framesizediv2, s16MaxCoefNorm; Word16 sbuf[L_FRAME_MAX]; Word16 tmp; - Framesizediv2=shr(Framesize,1); - zp1 = zero_pass_w32_x(outdata2, Framesizediv2); - zp2 = zero_pass_w32_x(outdata2+Framesizediv2, Framesizediv2); + Framesizediv2 = shr( Framesize, 1 ); + zp1 = zero_pass_w32_x( outdata2, Framesizediv2 ); + zp2 = zero_pass_w32_x( outdata2 + Framesizediv2, Framesizediv2 ); /* judge if the pitch is usable */ tmp = 1; move16(); - if (GT_16(zp1, 1)) + if ( GT_16( zp1, 1 ) ) { tmp = zp1; move16(); } - IF (LT_16(shl(tmp,2), zp2)) + IF( LT_16( shl( tmp, 2 ), zp2 ) ) { move16(); return 0; @@ -1310,25 +1303,24 @@ Word16 waveform_adj_fix(Word16 *overlapbuf, test(); test(); test(); - IF (T_bfi && (LE_16(pitch , Framesizediv2)) - && (GT_16(Framesize ,256)) && (EQ_16(curr_mode , 1))) + IF( T_bfi && ( LE_16( pitch, Framesizediv2 ) ) && ( GT_16( Framesize, 256 ) ) && ( EQ_16( curr_mode, 1 ) ) ) { Word16 i1 = 0, i2 = 0; - Word16 pos1, pos2, pos3; + Word16 pos1, pos2, pos3; move16(); move16(); - i1 = add(1 , array_max_indx_fx(outx_new, pitch)); - i2 = add(1 , array_max_indx_fx(outx_new+pitch, pitch)); + i1 = add( 1, array_max_indx_fx( outx_new, pitch ) ); + i2 = add( 1, array_max_indx_fx( outx_new + pitch, pitch ) ); - pos1 = add(i2,sub(pitch,i1)); - pos3 = add(pos1, mult(pos1, 8192/* 0.25 Q15 */)); - pos2 = add(pitch,mult(pitch, 8192/* 0.25 Q15 */)); + pos1 = add( i2, sub( pitch, i1 ) ); + pos3 = add( pos1, mult( pos1, 8192 /* 0.25 Q15 */ ) ); + pos2 = add( pitch, mult( pitch, 8192 /* 0.25 Q15 */ ) ); test(); test(); - IF ((LT_16(pos1,pos2))&&(GT_16(pos3,pitch))&&(LT_16(pos1,Framesizediv2))) + IF( ( LT_16( pos1, pos2 ) ) && ( GT_16( pos3, pitch ) ) && ( LT_16( pos1, Framesizediv2 ) ) ) { - pitch = add(i2,sub(pitch,i1)); + pitch = add( i2, sub( pitch, i1 ) ); } } @@ -1337,19 +1329,19 @@ Word16 waveform_adj_fix(Word16 *overlapbuf, Word16 pitch125_data[L_FRAME_MAX]; move16(); move16(); - pitch125 = extract_l((L_shr(L_add(L_add(L_deposit_h(pitch), L_mult(pitch, 8192)), 32768) ,16))); - Loverlap = sub(pitch125,pitch); - FOR (i = 0; i < pitch; i++) + pitch125 = extract_l( ( L_shr( L_add( L_add( L_deposit_h( pitch ), L_mult( pitch, 8192 ) ), 32768 ), 16 ) ) ); + Loverlap = sub( pitch125, pitch ); + FOR( i = 0; i < pitch; i++ ) { - pitch125_data[i] = outdata2[Framesize-pitch+i]; + pitch125_data[i] = outdata2[Framesize - pitch + i]; move16(); } - FOR (i = 0; i < Loverlap; i++) + FOR( i = 0; i < Loverlap; i++ ) { - pitch125_data[pitch+i] = outx_new[i]; + pitch125_data[pitch + i] = outx_new[i]; move16(); } - FOR (i = 0; i < Framesize; i++) + FOR( i = 0; i < Framesize; i++ ) { sbuf[i] = outx_new[i]; move16(); @@ -1357,58 +1349,58 @@ Word16 waveform_adj_fix(Word16 *overlapbuf, { Word16 pitch125a1; - Word16 tmp_buf[2*L_FRAME_MAX], *p_tmp = tmp_buf+1; + Word16 tmp_buf[2 * L_FRAME_MAX], *p_tmp = tmp_buf + 1; - FOR (i = 0; i < pitch125; i++) + FOR( i = 0; i < pitch125; i++ ) { p_tmp[i] = pitch125_data[i]; move16(); } - p_tmp[-1] = outdata2[Framesize-pitch-1]; + p_tmp[-1] = outdata2[Framesize - pitch - 1]; move16(); p_tmp[pitch125] = outx_new[Loverlap]; move16(); - pitch125a1 = add(pitch125,1); - s16MaxCoefNorm = sub(ffr_getSfWord16(p_tmp-1, pitch125a1),1); - FOR (i = 0; i < pitch125a1; i++) + pitch125a1 = add( pitch125, 1 ); + s16MaxCoefNorm = sub( ffr_getSfWord16( p_tmp - 1, pitch125a1 ), 1 ); + FOR( i = 0; i < pitch125a1; i++ ) { - p_tmp[i-1] = shl(p_tmp[i-1],s16MaxCoefNorm); + p_tmp[i - 1] = shl( p_tmp[i - 1], s16MaxCoefNorm ); move16(); } - FOR (i = 0; i < pitch125; i++) + FOR( i = 0; i < pitch125; i++ ) { #ifdef BASOP_NOGLOB - pitch125_data[i] = round_fx_sat(L_shr_sat(L_add_sat((L_mult(p_tmp[i], 20972)),L_mac_sat(L_mult(p_tmp[i-1], 5898),p_tmp[i+1],5898)),s16MaxCoefNorm)); + pitch125_data[i] = round_fx_sat( L_shr_sat( L_add_sat( ( L_mult( p_tmp[i], 20972 ) ), L_mac_sat( L_mult( p_tmp[i - 1], 5898 ), p_tmp[i + 1], 5898 ) ), s16MaxCoefNorm ) ); #else - pitch125_data[i] = round_fx(L_shr(L_add((L_mult(p_tmp[i], 20972)),L_mac(L_mult(p_tmp[i-1], 5898),p_tmp[i+1],5898)),s16MaxCoefNorm)); + pitch125_data[i] = round_fx( L_shr( L_add( ( L_mult( p_tmp[i], 20972 ) ), L_mac( L_mult( p_tmp[i - 1], 5898 ), p_tmp[i + 1], 5898 ) ), s16MaxCoefNorm ) ); #endif } } - WHILE (LT_16(n, Framesize)) /* periodical extension */ + WHILE( LT_16( n, Framesize ) ) /* periodical extension */ { - n = OverlapAdd_fx(pitch125_data,sbuf,n,pitch,Framesize); + n = OverlapAdd_fx( pitch125_data, sbuf, n, pitch, Framesize ); } /* maximum pitch lag is 3/4 Framesize; pitch125_data is reused for temporary storage, since outdata2 (holding the pcm data of the last good frame) is still needed and overlapbuf overlaps outdata2 */ - Copy(&sbuf[Framesize/4], pitch125_data, (3*Framesize)/4); + Copy( &sbuf[Framesize / 4], pitch125_data, ( 3 * Framesize ) / 4 ); - *nsapp_gain = 0; + *nsapp_gain = 0; move16(); - *nsapp_gain_n = sub(32767 ,shr(voicing,1)); /* q15 */ + *nsapp_gain_n = sub( 32767, shr( voicing, 1 ) ); /* q15 */ tmp = Framesize; move16(); /* use last good signal for noise generation */ - add_noise(sbuf, outx_new_n1, outdata2, tmp, nsapp_gain, nsapp_gain_n, 1); + add_noise( sbuf, outx_new_n1, outdata2, tmp, nsapp_gain, nsapp_gain_n, 1 ); /* save current (noisy) output from IMDCT */ - mvr2r_Word16(outx_new, data_noise, tmp); + mvr2r_Word16( outx_new, data_noise, tmp ); /* overlapbuf can now be filled with sbuf, needed for subsequently lost frames */ - Copy(pitch125_data, &overlapbuf[Framesize/4], (3*Framesize)/4); + Copy( pitch125_data, &overlapbuf[Framesize / 4], ( 3 * Framesize ) / 4 ); } - FOR (i = 0; i < Framesize; i++) + FOR( i = 0; i < Framesize; i++ ) { outx_new[i] = sbuf[i]; move16(); @@ -1416,152 +1408,156 @@ Word16 waveform_adj_fix(Word16 *overlapbuf, return pitch; } -void waveform_adj2_fix( Word16 *overlapbuf, - Word16 *outx_new, - Word16 *data_noise, - Word16 *outx_new_n1, - Word16 *nsapp_gain, - Word16 *nsapp_gain_n, - Word16 *recovery_gain, - Word16 step_concealgain, - Word16 pitch, - Word16 Framesize, - Word16 delay, - Word16 bfi_cnt, - Word16 bfi - ) +void waveform_adj2_fix( Word16 *overlapbuf, + Word16 *outx_new, + Word16 *data_noise, + Word16 *outx_new_n1, + Word16 *nsapp_gain, + Word16 *nsapp_gain_n, + Word16 *recovery_gain, + Word16 step_concealgain, + Word16 pitch, + Word16 Framesize, + Word16 delay, + Word16 bfi_cnt, + Word16 bfi ) { - Word16 i, n,tablescale,ratio, - dat,Framesizesubn,Framesizesubp,tmp16,s,ptable,temp_OUT,s16MaxCoefNorm,s16MaxCoefNorm2; + Word16 i, n, tablescale, ratio, + dat, Framesizesubn, Framesizesubp, tmp16, s, ptable, temp_OUT, s16MaxCoefNorm, s16MaxCoefNorm2; Word16 sbuf[L_FRAME_MAX]; - n=0; + n = 0; move16(); - Framesizesubn = sub(Framesize,n); - Framesizesubp = sub(Framesize,pitch); - IF (pitch > 0) + Framesizesubn = sub( Framesize, n ); + Framesizesubp = sub( Framesize, pitch ); + IF( pitch > 0 ) { - WHILE (Framesizesubn>0) + WHILE( Framesizesubn > 0 ) { /* periodical extension */ - Word16 tmp = vadmin(pitch, Framesizesubn); - FOR (i = 0; i < tmp; i++) + Word16 tmp = vadmin( pitch, Framesizesubn ); + FOR( i = 0; i < tmp; i++ ) { - sbuf[n+i] = overlapbuf[Framesizesubp+i]; + sbuf[n + i] = overlapbuf[Framesizesubp + i]; move16(); } - n = add(n, pitch); - Framesizesubn = sub(Framesize,n); + n = add( n, pitch ); + Framesizesubn = sub( Framesize, n ); } - FOR (i = 0; i < Framesize; i++) + FOR( i = 0; i < Framesize; i++ ) { overlapbuf[i] = sbuf[i]; move16(); } { - Word16 size = Framesize; - Word16* noise_ptr = data_noise; + Word16 size = Framesize; + Word16 *noise_ptr = data_noise; /* use last (noisy) output from IMDCT for noise generation */ - add_noise(sbuf, outx_new_n1, noise_ptr, size, nsapp_gain, nsapp_gain_n, 0); + add_noise( sbuf, outx_new_n1, noise_ptr, size, nsapp_gain, nsapp_gain_n, 0 ); /* save current (noisy) output from IMDCT */ IF( bfi ) { - mvr2r_Word16(outx_new, noise_ptr, size); + mvr2r_Word16( outx_new, noise_ptr, size ); } } test(); - IF (EQ_16(bfi_cnt ,4)||bfi==0) + IF( EQ_16( bfi_cnt, 4 ) || bfi == 0 ) { - SWITCH ( Framesize) + SWITCH( Framesize ) { - case 160: + case 160: { - tablescale =8; + tablescale = 8; + move16(); + ptable = 26214; /* (Word16)(32767*256/160.0+0.5); q7+15 */ move16(); - ptable = 26214; /* (Word16)(32767*256/160.0+0.5); q7+15 */ move16(); BREAK; } - case 320: + case 320: { - tablescale =9; + tablescale = 9; + move16(); + ptable = 26214; /* (Word16)(32767*256/320.0+0.5); q8+15 */ move16(); - ptable = 26214; /* (Word16)(32767*256/320.0+0.5); q8+15 */ move16(); BREAK; } - case 512: + case 512: { - tablescale =10; + tablescale = 10; + move16(); + ptable = 32767; /* q9+15 */ move16(); - ptable = 32767; /* q9+15 */ move16(); BREAK; } - case 640: + case 640: { - tablescale =10; + tablescale = 10; + move16(); + ptable = 26214; /* (Word16)(32767*512/640.0+0.5); q9+15 */ move16(); - ptable = 26214; /* (Word16)(32767*512/640.0+0.5); q9+15 */ move16(); BREAK; } - default: /* 960 */ + default: /* 960 */ { - tablescale =10; + tablescale = 10; + move16(); + ptable = 17456; /* (Word16)(32767*512/960.0); q9+15 */ move16(); - ptable = 17456; /* (Word16)(32767*512/960.0); q9+15 */ move16(); BREAK; } } - IF (bfi == 0) /* overlap-and-add */ + IF( bfi == 0 ) /* overlap-and-add */ { Word16 gain_zero_start = 10000; move16(); - IF (step_concealgain > 0) + IF( step_concealgain > 0 ) { - gain_zero_start = BASOP_Util_Divide1616_Scale(*recovery_gain, step_concealgain,&s); - gain_zero_start= shl(gain_zero_start, sub(s,14)); /* q0 */ - gain_zero_start= add(gain_zero_start,1); + gain_zero_start = BASOP_Util_Divide1616_Scale( *recovery_gain, step_concealgain, &s ); + gain_zero_start = shl( gain_zero_start, sub( s, 14 ) ); /* q0 */ + gain_zero_start = add( gain_zero_start, 1 ); } - IF (delay > 0) + IF( delay > 0 ) { - Framesize = sub(Framesize,delay); + Framesize = sub( Framesize, delay ); } - s16MaxCoefNorm = sub(ffr_getSfWord16(sbuf, Framesize),1); - s16MaxCoefNorm2 = ffr_getSfWord16(outx_new, Framesize); - tmp16 = vadmin(gain_zero_start, Framesize); - FOR (i = 0; i < tmp16; i++) + s16MaxCoefNorm = sub( ffr_getSfWord16( sbuf, Framesize ), 1 ); + s16MaxCoefNorm2 = ffr_getSfWord16( outx_new, Framesize ); + tmp16 = vadmin( gain_zero_start, Framesize ); + FOR( i = 0; i < tmp16; i++ ) { - ratio = extract_l(L_shr(L_mult(i, ptable), tablescale)); - dat= shl(sbuf[i],s16MaxCoefNorm); - temp_OUT= mult(*recovery_gain, sub(32767,ratio)); + ratio = extract_l( L_shr( L_mult( i, ptable ), tablescale ) ); + dat = shl( sbuf[i], s16MaxCoefNorm ); + temp_OUT = mult( *recovery_gain, sub( 32767, ratio ) ); #ifdef BASOP_NOGLOB outx_new[i] = round_fx_sat( L_add_sat( L_shr_sat( L_mult( temp_OUT, dat ), s16MaxCoefNorm - 1 ), L_shr_sat( L_mult( shl( outx_new[i], s16MaxCoefNorm2 ), ratio ), s16MaxCoefNorm2 ) ) ); #else - outx_new[i]= round_fx(L_add(L_shr(L_mult(temp_OUT,dat ),s16MaxCoefNorm-1), L_shr(L_mult(shl(outx_new[i],s16MaxCoefNorm2),ratio),s16MaxCoefNorm2))); + outx_new[i] = round_fx( L_add( L_shr( L_mult( temp_OUT, dat ), s16MaxCoefNorm - 1 ), L_shr( L_mult( shl( outx_new[i], s16MaxCoefNorm2 ), ratio ), s16MaxCoefNorm2 ) ) ); #endif move16(); #ifdef BASOP_NOGLOB *recovery_gain = sub_sat( *recovery_gain, shr_r( step_concealgain, 1 ) ); /* q14 */ #else - *recovery_gain =sub(*recovery_gain,shr_r(step_concealgain,1)); /* q14 */ + *recovery_gain = sub( *recovery_gain, shr_r( step_concealgain, 1 ) ); /* q14 */ #endif } - FOR (i = gain_zero_start; i < Framesize; i++) + FOR( i = gain_zero_start; i < Framesize; i++ ) { - ratio = extract_l(L_shr(L_mult(i, ptable), tablescale)); + ratio = extract_l( L_shr( L_mult( i, ptable ), tablescale ) ); #ifdef BASOP_NOGLOB outx_new[i] = round_fx_sat( L_shr_sat( L_mult( shl( outx_new[i], s16MaxCoefNorm2 ), ratio ), s16MaxCoefNorm2 ) ); #else - outx_new[i] = round_fx(L_shr(L_mult(shl(outx_new[i],s16MaxCoefNorm2),ratio),s16MaxCoefNorm2)); + outx_new[i] = round_fx( L_shr( L_mult( shl( outx_new[i], s16MaxCoefNorm2 ), ratio ), s16MaxCoefNorm2 ) ); #endif } - if (*recovery_gain < 0) + if ( *recovery_gain < 0 ) { *recovery_gain = 0; move16(); @@ -1571,19 +1567,19 @@ void waveform_adj2_fix( Word16 *overlapbuf, { /* overlap-and-add */ Word16 tmp; - s16MaxCoefNorm = sub(ffr_getSfWord16(sbuf, Framesize),1); - s16MaxCoefNorm2 = ffr_getSfWord16(outx_new, Framesize); - FOR (i = 0; i < Framesize; i++) + s16MaxCoefNorm = sub( ffr_getSfWord16( sbuf, Framesize ), 1 ); + s16MaxCoefNorm2 = ffr_getSfWord16( outx_new, Framesize ); + FOR( i = 0; i < Framesize; i++ ) { - dat = shl(sbuf[i], s16MaxCoefNorm); - tmp = extract_l(L_shr(L_mult(i, ptable), tablescale)); - outx_new[i] = round_fx(L_add(L_shr(L_mult(dat, sub(32767,tmp)),s16MaxCoefNorm), L_shr(L_mult(shl(outx_new[i],s16MaxCoefNorm2),tmp),s16MaxCoefNorm2))); + dat = shl( sbuf[i], s16MaxCoefNorm ); + tmp = extract_l( L_shr( L_mult( i, ptable ), tablescale ) ); + outx_new[i] = round_fx( L_add( L_shr( L_mult( dat, sub( 32767, tmp ) ), s16MaxCoefNorm ), L_shr( L_mult( shl( outx_new[i], s16MaxCoefNorm2 ), tmp ), s16MaxCoefNorm2 ) ) ); } } } ELSE { - FOR (i = 0; i < Framesize; i++) + FOR( i = 0; i < Framesize; i++ ) { outx_new[i] = sbuf[i]; move16(); @@ -1593,69 +1589,68 @@ void waveform_adj2_fix( Word16 *overlapbuf, return; } -void concealment_signal_tuning_fx(Word16 bfi, Word16 curr_mode, Word16 *outx_new_fx, void *_plcInfo, Word16 nbLostCmpt, Word16 pre_bfi, Word16 *OverlapBuf_fx, Word16 past_core_mode, Word16 *outdata2_fx, Decoder_State *st) +void concealment_signal_tuning_fx( Word16 bfi, Word16 curr_mode, Word16 *outx_new_fx, void *_plcInfo, Word16 nbLostCmpt, Word16 pre_bfi, Word16 *OverlapBuf_fx, Word16 past_core_mode, Word16 *outdata2_fx, Decoder_State *st ) { - T_PLCInfo *plcInfo = (T_PLCInfo*)_plcInfo; - Word16 FrameSize = plcInfo->FrameSize; - Word16 Pitch = plcInfo->Pitch_fx; - Word16 voicing_fx = 0; + T_PLCInfo *plcInfo = (T_PLCInfo *) _plcInfo; + Word16 FrameSize = plcInfo->FrameSize; + Word16 Pitch = plcInfo->Pitch_fx; + Word16 voicing_fx = 0; move16(); move16(); move16(); move16(); - IF (bfi) + IF( bfi ) { test(); - IF (st->enablePlcWaveadjust && plcInfo->concealment_method == TCX_NONTONAL) /* #define TCX_NONTONAL 0 */ + IF( st->enablePlcWaveadjust && plcInfo->concealment_method == TCX_NONTONAL ) /* #define TCX_NONTONAL 0 */ { - IF (EQ_16(nbLostCmpt, 1)) + IF( EQ_16( nbLostCmpt, 1 ) ) { - plcInfo->Pitch_fx = pitch_search_fx(outdata2_fx, - outx_new_fx, - FrameSize, - &voicing_fx, - plcInfo->zp_fx, - (plcInfo->ener_fx), - (plcInfo->ener_mean_fx), - plcInfo->data_reci2_fx, - curr_mode - ); + plcInfo->Pitch_fx = pitch_search_fx( outdata2_fx, + outx_new_fx, + FrameSize, + &voicing_fx, + plcInfo->zp_fx, + ( plcInfo->ener_fx ), + ( plcInfo->ener_mean_fx ), + plcInfo->data_reci2_fx, + curr_mode ); move16(); - IF (plcInfo->Pitch_fx) /* waveform adjustment for the first lost frame */ + IF( plcInfo->Pitch_fx ) /* waveform adjustment for the first lost frame */ { - plcInfo->Pitch_fx = waveform_adj_fix(OverlapBuf_fx, - outdata2_fx, - outx_new_fx, - plcInfo->data_noise, - &plcInfo->outx_new_n1_fx, - &plcInfo->nsapp_gain_fx, - &plcInfo->nsapp_gain_n_fx, - FrameSize, - plcInfo->T_bfi_fx, - voicing_fx, - curr_mode, - plcInfo->Pitch_fx); + plcInfo->Pitch_fx = waveform_adj_fix( OverlapBuf_fx, + outdata2_fx, + outx_new_fx, + plcInfo->data_noise, + &plcInfo->outx_new_n1_fx, + &plcInfo->nsapp_gain_fx, + &plcInfo->nsapp_gain_n_fx, + FrameSize, + plcInfo->T_bfi_fx, + voicing_fx, + curr_mode, + plcInfo->Pitch_fx ); move16(); } } - ELSE IF (LT_16(nbLostCmpt, 5)) /* waveform adjustment for the 2nd~4th lost frame */ + ELSE IF( LT_16( nbLostCmpt, 5 ) ) /* waveform adjustment for the 2nd~4th lost frame */ { - waveform_adj2_fix(OverlapBuf_fx, - outx_new_fx, - plcInfo->data_noise, - &plcInfo->outx_new_n1_fx, - &plcInfo->nsapp_gain_fx, - &plcInfo->nsapp_gain_n_fx, - &plcInfo->recovery_gain, - plcInfo->step_concealgain_fx, - Pitch, - FrameSize, - 0, - nbLostCmpt, - bfi); + waveform_adj2_fix( OverlapBuf_fx, + outx_new_fx, + plcInfo->data_noise, + &plcInfo->outx_new_n1_fx, + &plcInfo->nsapp_gain_fx, + &plcInfo->nsapp_gain_n_fx, + &plcInfo->recovery_gain, + plcInfo->step_concealgain_fx, + Pitch, + FrameSize, + 0, + nbLostCmpt, + bfi ); } } plcInfo->T_bfi_fx = 1; @@ -1666,28 +1661,28 @@ void concealment_signal_tuning_fx(Word16 bfi, Word16 curr_mode, Word16 *outx_new test(); test(); test(); - IF (pre_bfi && - past_core_mode != 0 && - GE_32(st->last_total_brate, 48000) && - EQ_16(st->last_codec_mode, MODE2) ) + IF( pre_bfi && + past_core_mode != 0 && + GE_32( st->last_total_brate, 48000 ) && + EQ_16( st->last_codec_mode, MODE2 ) ) { - IF (plcInfo->concealment_method == TCX_NONTONAL) /* #define TCX_NONTONAL 0 */ + IF( plcInfo->concealment_method == TCX_NONTONAL ) /* #define TCX_NONTONAL 0 */ { - IF (LT_32(plcInfo->nbLostCmpt, 4)) /* smoothing of the concealed signal with the good signal */ + IF( LT_32( plcInfo->nbLostCmpt, 4 ) ) /* smoothing of the concealed signal with the good signal */ { - waveform_adj2_fix(OverlapBuf_fx, - outx_new_fx, - plcInfo->data_noise, - &plcInfo->outx_new_n1_fx, - &plcInfo->nsapp_gain_fx, - &plcInfo->nsapp_gain_n_fx, - &plcInfo->recovery_gain, - plcInfo->step_concealgain_fx, - Pitch, - FrameSize, - 0, - add(extract_l(plcInfo->nbLostCmpt), 1), - bfi); + waveform_adj2_fix( OverlapBuf_fx, + outx_new_fx, + plcInfo->data_noise, + &plcInfo->outx_new_n1_fx, + &plcInfo->nsapp_gain_fx, + &plcInfo->nsapp_gain_n_fx, + &plcInfo->recovery_gain, + plcInfo->step_concealgain_fx, + Pitch, + FrameSize, + 0, + add( extract_l( plcInfo->nbLostCmpt ), 1 ), + bfi ); } } } diff --git a/lib_enc/ACcontextMapping_enc_fx.c b/lib_enc/ACcontextMapping_enc_fx.c index 285d62181..62516fe35 100644 --- a/lib_enc/ACcontextMapping_enc_fx.c +++ b/lib_enc/ACcontextMapping_enc_fx.c @@ -7,7 +7,7 @@ #include "options.h" #include "basop_util.h" #include "cnst.h" -#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ #include "prot_fx2.h" #include "rom_com.h" //#include "prot_fx.h" @@ -18,7 +18,7 @@ * * Arithmetic encoder *-------------------------------------------------------------------*/ - /** +/** * \brief Arithmetic encoder * \param[i] x * \param[o] ntuples amount of encoded tuple (2 lines per tuple) @@ -34,8 +34,7 @@ void ACcontextMapping_encode2_no_mem_s17_LC_fx( Word16 lastnz, Word16 nbbits, Word16 resQMaxBits, - CONTEXT_HM_CONFIG *hm_cfg -) + CONTEXT_HM_CONFIG *hm_cfg ) { Word16 ptr[BITBUFSIZE]; TastatEnc as, as_overflow; @@ -56,27 +55,27 @@ void ACcontextMapping_encode2_no_mem_s17_LC_fx( Word16 signs[N_MAX]; Word16 nbbits_m2; - a1 = 0; /* to avoid compilation warnings */ - b1 = 0; /* to avoid compilation warnings */ + a1 = 0; /* to avoid compilation warnings */ + b1 = 0; /* to avoid compilation warnings */ /* Rate flag */ rateFlag = 0; move16(); - if (GT_16(nbbits, 400)) + if ( GT_16( nbbits, 400 ) ) { rateFlag = 2 << NBITS_CONTEXT; move16(); } /* Init */ - nt_half = shr(nt, 1); + nt_half = shr( nt, 1 ); c[0] = c[1] = 0; move16(); move16(); /* Bits for encoding the number of encoded tuples */ - nbbits_ntuples = sub(14, norm_s(negate(nt))); + nbbits_ntuples = sub( 14, norm_s( negate( nt ) ) ); t = 0; move16(); @@ -86,22 +85,22 @@ void ACcontextMapping_encode2_no_mem_s17_LC_fx( move16(); nbbits_lsbs = 0; move16(); - nbbits_m2 = sub(nbbits, 2); + nbbits_m2 = sub( nbbits, 2 ); flag_overflow = 0; move16(); - IF (hm_cfg) /* mapped domain */ + IF( hm_cfg ) /* mapped domain */ { numPeakIndicesOrig = hm_cfg->numPeakIndices; move16(); - hm_cfg->numPeakIndices = s_min(hm_cfg->numPeakIndices, lastnz); + hm_cfg->numPeakIndices = s_min( hm_cfg->numPeakIndices, lastnz ); move16(); - numHoleIndices = sub(lastnz, hm_cfg->numPeakIndices); + numHoleIndices = sub( lastnz, hm_cfg->numPeakIndices ); /* Mark hole indices beyond lastnz as pruned */ - FOR (k=numHoleIndices; knumHoleIndices; ++k) + FOR( k = numHoleIndices; k < hm_cfg->numHoleIndices; ++k ) { - hm_cfg->holeIndices[k] = add(hm_cfg->holeIndices[k], nt); + hm_cfg->holeIndices[k] = add( hm_cfg->holeIndices[k], nt ); move16(); } @@ -113,7 +112,7 @@ void ACcontextMapping_encode2_no_mem_s17_LC_fx( get_next_coeff = get_next_coeff_mapped; move16(); } - ELSE /* unmapped domain */ + ELSE /* unmapped domain */ { ii[0] = 0; move16(); @@ -132,62 +131,62 @@ void ACcontextMapping_encode2_no_mem_s17_LC_fx( x[0] = 1; move16(); - WHILE (s_or(x[lastnz-1], x[lastnz-2]) == 0) + WHILE( s_or( x[lastnz - 1], x[lastnz - 2] ) == 0 ) { - lastnz = sub(lastnz, 2); + lastnz = sub( lastnz, 2 ); } x[0] = a1; move16(); } - lsbs_bits2 = ptr+nbbits-1; + lsbs_bits2 = ptr + nbbits - 1; /*Start Encoding*/ - ari_start_encoding_14bits_fx(&as); + ari_start_encoding_14bits_fx( &as ); /*Main Loop through the 2-tuples*/ b1_i = -1; move16(); - FOR (k = 0; k < lastnz; k += 2) + FOR( k = 0; k < lastnz; k += 2 ) { /* First coefficient */ - a1_i = get_next_coeff(ii, &p1, &idx1, hm_cfg); + a1_i = get_next_coeff( ii, &p1, &idx1, hm_cfg ); /* Second coefficient */ - b1_i = get_next_coeff(ii, &p2, &idx2, hm_cfg); + b1_i = get_next_coeff( ii, &p2, &idx2, hm_cfg ); - idx = s_min(idx1, idx2); + idx = s_min( idx1, idx2 ); /* Get context */ - ctx = &c[s_or(p1, p2)]; + ctx = &c[s_or( p1, p2 )]; move16(); - /* _DIFF_FLOAT_FIX_ float is using t as UWord16 */ - t = add(*ctx, rateFlag); - if (GT_16(idx, nt_half)) + /* _DIFF_FLOAT_FIX_ float is using t as UWord16 */ + t = add( *ctx, rateFlag ); + if ( GT_16( idx, nt_half ) ) { - t = add(t, 1 << NBITS_CONTEXT); + t = add( t, 1 << NBITS_CONTEXT ); } /* Init current 2-tuple encoding */ - if (flag_overflow != 0) + if ( flag_overflow != 0 ) { x[a1_i] = 0; move16(); } - if (flag_overflow != 0) + if ( flag_overflow != 0 ) { x[b1_i] = 0; move16(); } - a1 = abs_s(x[a1_i]); - b1 = abs_s(x[b1_i]); + a1 = abs_s( x[a1_i] ); + b1 = abs_s( x[b1_i] ); lev1 = -1; move16(); /*Copy states*/ - ari_copy_states_fx(&as, &as_overflow); + ari_copy_states_fx( &as, &as_overflow ); bp_overflow = bp; move16(); nbbits_signs_overflow = nbbits_signs; @@ -196,62 +195,62 @@ void ACcontextMapping_encode2_no_mem_s17_LC_fx( move16(); /*Signs encoding*/ - signs[nbbits_signs] = lshr(x[a1_i], 15); + signs[nbbits_signs] = lshr( x[a1_i], 15 ); move16(); - if (a1 > 0) + if ( a1 > 0 ) { - nbbits_signs = add(nbbits_signs, 1); + nbbits_signs = add( nbbits_signs, 1 ); } - signs[nbbits_signs] = lshr(x[b1_i], 15); + signs[nbbits_signs] = lshr( x[b1_i], 15 ); move16(); - if (b1 > 0) + if ( b1 > 0 ) { - nbbits_signs = add(nbbits_signs, 1); + nbbits_signs = add( nbbits_signs, 1 ); } /* MSBs coding */ - WHILE (GE_16(s_max(a1, b1), A_THRES)) + WHILE( GE_16( s_max( a1, b1 ), A_THRES ) ) { - tmp = add(t, Tab_esc_nb[lev1+1]); - assert(tmp >= 0 && tmp < 4096); + tmp = add( t, Tab_esc_nb[lev1 + 1] ); + assert( tmp >= 0 && tmp < 4096 ); pki = ari_lookup_s17_LC[tmp]; move16(); - bp = ari_encode_14bits_ext_fx(ptr, bp, &as, VAL_ESC, ari_pk_s17_LC_ext[pki]); + bp = ari_encode_14bits_ext_fx( ptr, bp, &as, VAL_ESC, ari_pk_s17_LC_ext[pki] ); - *lsbs_bits2-- = s_and(a1, 1); + *lsbs_bits2-- = s_and( a1, 1 ); move16(); - *lsbs_bits2-- = s_and(b1, 1); + *lsbs_bits2-- = s_and( b1, 1 ); move16(); /* LSBs bit counting */ - nbbits_lsbs = add(nbbits_lsbs, 2); + nbbits_lsbs = add( nbbits_lsbs, 2 ); - a1 = shr(a1, 1); - b1 = shr(b1, 1); + a1 = shr( a1, 1 ); + b1 = shr( b1, 1 ); - lev1 = s_min(add(lev1, 1), 2); + lev1 = s_min( add( lev1, 1 ), 2 ); } - tmp = add(t, Tab_esc_nb[lev1+1]); - assert(tmp >= 0 && tmp < 4096); + tmp = add( t, Tab_esc_nb[lev1 + 1] ); + assert( tmp >= 0 && tmp < 4096 ); pki = ari_lookup_s17_LC[tmp]; move16(); - bp = ari_encode_14bits_ext_fx(ptr, bp, &as, add(a1, shl(b1, A_THRES_SHIFT)), ari_pk_s17_LC_ext[pki]); + bp = ari_encode_14bits_ext_fx( ptr, bp, &as, add( a1, shl( b1, A_THRES_SHIFT ) ), ari_pk_s17_LC_ext[pki] ); /* Check bit budget */ - IF (GT_16(add(add(add(bp, extract_l(as.value)), nbbits_signs), nbbits_lsbs), nbbits_m2)) + IF( GT_16( add( add( add( bp, extract_l( as.value ) ), nbbits_signs ), nbbits_lsbs ), nbbits_m2 ) ) { - ari_copy_states_fx(&as_overflow, &as); + ari_copy_states_fx( &as_overflow, &as ); bp = bp_overflow; move16(); - IF (flag_overflow == 0) + IF( flag_overflow == 0 ) { nbbits_signs = nbbits_signs_overflow; move16(); nbbits_lsbs = nbbits_lsbs_overflow; move16(); - IF (hm_cfg) + IF( hm_cfg ) { flag_overflow = 1; move16(); @@ -264,14 +263,14 @@ void ACcontextMapping_encode2_no_mem_s17_LC_fx( lev1 = -1; move16(); - assert(t >= 0 && t < 4096); + assert( t >= 0 && t < 4096 ); pki = ari_lookup_s17_LC[t]; move16(); - bp = ari_encode_14bits_ext_fx(ptr, bp, &as, 0, ari_pk_s17_LC_ext[pki]); + bp = ari_encode_14bits_ext_fx( ptr, bp, &as, 0, ari_pk_s17_LC_ext[pki] ); - IF (GT_16(add(add(add(bp, extract_l(as.value)), nbbits_signs), nbbits_lsbs), nbbits_m2)) + IF( GT_16( add( add( add( bp, extract_l( as.value ) ), nbbits_signs ), nbbits_lsbs ), nbbits_m2 ) ) { - ari_copy_states_fx(&as_overflow, &as); + ari_copy_states_fx( &as_overflow, &as ); bp = bp_overflow; move16(); BREAK; @@ -289,46 +288,49 @@ void ACcontextMapping_encode2_no_mem_s17_LC_fx( } /* Update context for next 2-tuple */ - IF (EQ_16(p1, p2)) /* peak-peak or hole-hole context */ + IF( EQ_16( p1, p2 ) ) /* peak-peak or hole-hole context */ { - if (lev1 > 0) t = add(12, lev1); - if (lev1 <= 0) t = add(a1, b1); - if (lev1 == 0) t = add(t, t); - - *ctx = add(shl(s_and(*ctx, 0xf), 4), add(t, 1)); + if ( lev1 > 0 ) + t = add( 12, lev1 ); + if ( lev1 <= 0 ) + t = add( a1, b1 ); + if ( lev1 == 0 ) + t = add( t, t ); + + *ctx = add( shl( s_and( *ctx, 0xf ), 4 ), add( t, 1 ) ); move16(); } - ELSE /* mixed context */ + ELSE /* mixed context */ { - IF (s_and(idx1, 1)) /* update first context */ + IF( s_and( idx1, 1 ) ) /* update first context */ { - c[p1] = update_mixed_context(c[p1], abs_s(x[a1_i])); + c[p1] = update_mixed_context( c[p1], abs_s( x[a1_i] ) ); move16(); } - IF (s_and(idx2, 1)) /* update second context */ + IF( s_and( idx2, 1 ) ) /* update second context */ { - c[p2] = update_mixed_context(c[p2], abs_s(x[b1_i])); + c[p2] = update_mixed_context( c[p2], abs_s( x[b1_i] ) ); move16(); } } } /*end of the 2-tuples loop*/ /* End arithmetic coder, overflow management */ - bp = ari_done_encoding_14bits_fx(ptr, bp, &as); + bp = ari_done_encoding_14bits_fx( ptr, bp, &as ); /* Overflow is detected */ - IF (NE_16(k, lastnz)) + IF( NE_16( k, lastnz ) ) { - IF (hm_cfg) + IF( hm_cfg ) { /* Fill with zero to be sure that the decoder finishes the MSB decoding at the same position */ - tmp = sub(nbbits, add(nbbits_signs, nbbits_lsbs)); - set16_fx(&ptr[bp], 0, sub(tmp, bp)); + tmp = sub( nbbits, add( nbbits_signs, nbbits_lsbs ) ); + set16_fx( &ptr[bp], 0, sub( tmp, bp ) ); bp = tmp; move16(); } - if (!hm_cfg) + if ( !hm_cfg ) { lastnz = k; move16(); @@ -336,37 +338,37 @@ void ACcontextMapping_encode2_no_mem_s17_LC_fx( } /* Push number of encoded tuples */ - value = sub(shr(lastnz, 1), 1); - push_next_indice_fx(hBstr, value, nbbits_ntuples); + value = sub( shr( lastnz, 1 ), 1 ); + push_next_indice_fx( hBstr, value, nbbits_ntuples ); /* Push arithmetic coded bits */ - push_next_bits_fx(hBstr, &ptr[nbbits_ntuples], sub(bp, nbbits_ntuples)); + push_next_bits_fx( hBstr, &ptr[nbbits_ntuples], sub( bp, nbbits_ntuples ) ); /* Push sign bits */ - push_next_bits_fx(hBstr, signs, nbbits_signs); - bp = add(bp, nbbits_signs); + push_next_bits_fx( hBstr, signs, nbbits_signs ); + bp = add( bp, nbbits_signs ); /*write residual Quantization bits*/ - tmp = s_min(sub(sub(nbbits, bp), nbbits_lsbs), resQMaxBits); - FOR (k = 0; k < tmp; k++) + tmp = s_min( sub( sub( nbbits, bp ), nbbits_lsbs ), resQMaxBits ); + FOR( k = 0; k < tmp; k++ ) { - ptr[nbbits-1-nbbits_lsbs-k] = x[nt+k]; + ptr[nbbits - 1 - nbbits_lsbs - k] = x[nt + k]; move16(); } /* Write filler bits */ - tmp = sub(nbbits, add(bp, nbbits_lsbs)); - FOR (; kindexBuffer; move16(); @@ -392,53 +393,54 @@ static Word16 find_last_nz_pair( lobs[0] = 4; move16(); - lobs[1] = shr(length, 1); /* length/2 */ move16(); - lobs[2] = add(lobs[1], shr(length, 2)); + lobs[1] = shr( length, 1 ); /* length/2 */ + move16(); + lobs[2] = add( lobs[1], shr( length, 2 ) ); move16(); - lobs[3] = add(lobs[2], shr(length, 3)); + lobs[3] = add( lobs[2], shr( length, 3 ) ); move16(); last_nz = 0; move16(); i = length; move16(); - FOR (stage=3; stage>=0; --stage) + FOR( stage = 3; stage >= 0; --stage ) { - IF (hm_cfg) /* mapped kernel */ + IF( hm_cfg ) /* mapped kernel */ { - FOR (; i >= lobs[stage]; i-=2) + FOR( ; i >= lobs[stage]; i -= 2 ) { - if (x[tmp[i-2]] != 0) + if ( x[tmp[i - 2]] != 0 ) { - last_nz = s_max(last_nz, i); + last_nz = s_max( last_nz, i ); } - if (x[tmp[i-1]] != 0) + if ( x[tmp[i - 1]] != 0 ) { - last_nz = s_max(last_nz, i); + last_nz = s_max( last_nz, i ); } } } - ELSE /* unmapped kernel */ + ELSE /* unmapped kernel */ { - FOR (; i >= lobs[stage]; i-=2) + FOR( ; i >= lobs[stage]; i -= 2 ) { - if (x[i-2] != 0) + if ( x[i - 2] != 0 ) { - last_nz = s_max(last_nz, i); + last_nz = s_max( last_nz, i ); } - if (x[i-1] != 0) + if ( x[i - 1] != 0 ) { - last_nz = s_max(last_nz, i); + last_nz = s_max( last_nz, i ); } } } - IF (last_nz > 0) + IF( last_nz > 0 ) { BREAK; } } - return s_max(last_nz, 2); + return s_max( last_nz, 2 ); } /*-------------------------------------------------------------------* * ACcontextMapping_encode2_estimate_no_mem_s17_LC_fx() @@ -452,8 +454,7 @@ Word16 ACcontextMapping_encode2_estimate_no_mem_s17_LC_fx( Word16 *nEncoded, Word16 target, Word16 *stop, - CONTEXT_HM_CONFIG *hm_cfg -) + CONTEXT_HM_CONFIG *hm_cfg ) { Word16 a1, b1, a1_i, b1_i; Word16 k, t, pki, lev1; @@ -471,24 +472,24 @@ Word16 ACcontextMapping_encode2_estimate_no_mem_s17_LC_fx( Word16 c[2], *ctx; Word16 p1, p2; Word16 ii[2], idx1, idx2, idx; - Word16 numPeakIndicesOrig=0, numHoleIndices=0; /* initialize just to avoid compiler warning */ + Word16 numPeakIndicesOrig = 0, numHoleIndices = 0; /* initialize just to avoid compiler warning */ get_next_coeff_function get_next_coeff; /* Rate flag */ rateFlag = 0; move16(); - if (GT_16(target, 400)) + if ( GT_16( target, 400 ) ) { rateFlag = 2 << NBITS_CONTEXT; move16(); } /* proba coded on 14bits -> proba=1 */ - proba = L_deposit_l(16384); + proba = L_deposit_l( 16384 ); /* Init */ - nt_half = shr(nt, 1); + nt_half = shr( nt, 1 ); stop2 = 0; move16(); c[0] = c[1] = 0; @@ -496,30 +497,30 @@ Word16 ACcontextMapping_encode2_estimate_no_mem_s17_LC_fx( move16(); /* bits to encode lastnz + 2 bits headroom */ - nbits = sub(2+14, norm_s(sub(nt, 1))); + nbits = sub( 2 + 14, norm_s( sub( nt, 1 ) ) ); nbits_old = nbits; move16(); - nbits = sub(nbits, target); + nbits = sub( nbits, target ); /* Find last non-zero tuple in the mapped domain signal */ - lastnz = find_last_nz_pair(x, nt, hm_cfg); + lastnz = find_last_nz_pair( x, nt, hm_cfg ); /* At least one tuple is coded */ lastnz2 = 2; move16(); - IF (hm_cfg) /* mapped domain */ + IF( hm_cfg ) /* mapped domain */ { numPeakIndicesOrig = hm_cfg->numPeakIndices; move16(); - hm_cfg->numPeakIndices = s_min(hm_cfg->numPeakIndices, lastnz); + hm_cfg->numPeakIndices = s_min( hm_cfg->numPeakIndices, lastnz ); move16(); - numHoleIndices = sub(lastnz, hm_cfg->numPeakIndices); + numHoleIndices = sub( lastnz, hm_cfg->numPeakIndices ); /* Mark hole indices beyond lastnz as pruned */ - FOR (k=numHoleIndices; knumHoleIndices; ++k) + FOR( k = numHoleIndices; k < hm_cfg->numHoleIndices; ++k ) { - hm_cfg->holeIndices[k] = add(hm_cfg->holeIndices[k], nt); + hm_cfg->holeIndices[k] = add( hm_cfg->holeIndices[k], nt ); move16(); } @@ -531,7 +532,7 @@ Word16 ACcontextMapping_encode2_estimate_no_mem_s17_LC_fx( get_next_coeff = get_next_coeff_mapped; move16(); } - ELSE /* unmapped domain */ + ELSE /* unmapped domain */ { ii[0] = 0; move16(); @@ -545,41 +546,41 @@ Word16 ACcontextMapping_encode2_estimate_no_mem_s17_LC_fx( } /* Main Loop through the 2-tuples */ - FOR (k=0; k 0) + if ( a1 > 0 ) { - nbits = add(nbits, 1); + nbits = add( nbits, 1 ); } - if (b1 > 0) + if ( b1 > 0 ) { - nbits = add(nbits, 1); + nbits = add( nbits, 1 ); } /* pre-compute address of ari_pk_s17_LC_ext[0][Val_esc] to avoid doing it multiple times inside the loop */ @@ -587,60 +588,60 @@ Word16 ACcontextMapping_encode2_estimate_no_mem_s17_LC_fx( /* check while condition */ /* MSBs coding */ - lookup = (const Word8 *)(&ari_lookup_s17_LC[t] + (1 << (NBITS_CONTEXT+NBITS_RATEQ))); /* address calculation not counted */ - WHILE (GE_16(s_max(a1, b1), A_THRES)) + lookup = (const Word8 *) ( &ari_lookup_s17_LC[t] + ( 1 << ( NBITS_CONTEXT + NBITS_RATEQ ) ) ); /* address calculation not counted */ + WHILE( GE_16( s_max( a1, b1 ), A_THRES ) ) { pki = lookup[lev1]; move16(); cum_freq = ari_pk_s17_LC_ext[pki] + VAL_ESC; /* address calculation not counted */ /*p1*p2=proba on 28 bits: p=0.5->power(2,27)*/ - cum_freq_norm_e = norm_s(cum_freq[0]); - cum_freq_norm = shl(cum_freq[0], cum_freq_norm_e); - proba = Mpy_32_16_1(proba, cum_freq_norm); - proba = L_shl(proba, sub(14, cum_freq_norm_e)); + cum_freq_norm_e = norm_s( cum_freq[0] ); + cum_freq_norm = shl( cum_freq[0], cum_freq_norm_e ); + proba = Mpy_32_16_1( proba, cum_freq_norm ); + proba = L_shl( proba, sub( 14, cum_freq_norm_e ) ); /*Number of leading zero computed in one cycle=norm_l() in BASOP*/ - nlz = sub(norm_l(proba), 2); - proba = L_shl(proba, sub(nlz, 15)); + nlz = sub( norm_l( proba ), 2 ); + proba = L_shl( proba, sub( nlz, 15 ) ); - nbits = add(nbits, nlz); + nbits = add( nbits, nlz ); /*addition added as shift not done in norm_l(): real shift = 14-nlz*/ /*proba is rounded down on 14 bits ->automatic over-estimation of bit consumption*/ - a1 = shr(a1, 1); - b1 = shr(b1, 1); - lev1 = s_min(add(lev1, 1 << (NBITS_CONTEXT+NBITS_RATEQ)), 2 << (NBITS_CONTEXT+NBITS_RATEQ)); + a1 = shr( a1, 1 ); + b1 = shr( b1, 1 ); + lev1 = s_min( add( lev1, 1 << ( NBITS_CONTEXT + NBITS_RATEQ ) ), 2 << ( NBITS_CONTEXT + NBITS_RATEQ ) ); } pki = lookup[lev1]; move16(); - symbol = add(a1, shl(b1, A_THRES_SHIFT)); + symbol = add( a1, shl( b1, A_THRES_SHIFT ) ); cum_freq = ari_pk_s17_LC_ext[pki] + symbol; /* address calculation not counted */ /*p1*p2=proba on 28 bits: p=0.5->power(2,27)*/ - cum_freq_norm = sub(cum_freq[0], cum_freq[1]); - cum_freq_norm_e = norm_s(cum_freq_norm); - cum_freq_norm = shl(cum_freq_norm, cum_freq_norm_e); - proba = Mpy_32_16_1(proba, cum_freq_norm); - proba = L_shl(proba, sub(15, cum_freq_norm_e)); + cum_freq_norm = sub( cum_freq[0], cum_freq[1] ); + cum_freq_norm_e = norm_s( cum_freq_norm ); + cum_freq_norm = shl( cum_freq_norm, cum_freq_norm_e ); + proba = Mpy_32_16_1( proba, cum_freq_norm ); + proba = L_shl( proba, sub( 15, cum_freq_norm_e ) ); /*Number of leading zero computed in one cycle=norm_l() in BASOP*/ - nlz = sub(norm_l(proba), 3); - proba = L_shl(proba, sub(nlz, 14)); + nlz = sub( norm_l( proba ), 3 ); + proba = L_shl( proba, sub( nlz, 14 ) ); - nbits = add(nbits, nlz); + nbits = add( nbits, nlz ); /*addition added as shift not done in norm_l(): real shift = 14-nlz*/ /*proba is rounded down on 14 bits ->automatic over-estimation of bit consumption*/ /* Should we truncate? */ - IF (nbits > 0) + IF( nbits > 0 ) { stop2 = 1; move16(); - IF (*stop) + IF( *stop ) { BREAK; } @@ -649,50 +650,53 @@ Word16 ACcontextMapping_encode2_estimate_no_mem_s17_LC_fx( { test(); test(); - IF (hm_cfg || k==0 || s_or(x[a1_i], x[b1_i])) + IF( hm_cfg || k == 0 || s_or( x[a1_i], x[b1_i] ) ) { - nbits_old = add(nbits, target); - lastnz2 = add(b1_i, 1); + nbits_old = add( nbits, target ); + lastnz2 = add( b1_i, 1 ); } } /* Update context for next 2-tuple */ - IF (EQ_16(p1, p2)) /* peak-peak or hole-hole context */ + IF( EQ_16( p1, p2 ) ) /* peak-peak or hole-hole context */ { - lev1 = shr(lev1, NBITS_CONTEXT+NBITS_RATEQ); - if (lev1 > 0) t = add(12, lev1); - if (lev1 <= 0) t = add(a1, b1); - if (lev1 == 0) t = add(t, t); - - *ctx = add(shl(s_and(*ctx, 0xf), 4), add(t, 1)); + lev1 = shr( lev1, NBITS_CONTEXT + NBITS_RATEQ ); + if ( lev1 > 0 ) + t = add( 12, lev1 ); + if ( lev1 <= 0 ) + t = add( a1, b1 ); + if ( lev1 == 0 ) + t = add( t, t ); + + *ctx = add( shl( s_and( *ctx, 0xf ), 4 ), add( t, 1 ) ); move16(); } - ELSE /* mixed context */ + ELSE /* mixed context */ { - IF (s_and(idx1, 1)) /* update first context */ + IF( s_and( idx1, 1 ) ) /* update first context */ { - c[p1] = update_mixed_context(c[p1], abs_s(x[a1_i])); + c[p1] = update_mixed_context( c[p1], abs_s( x[a1_i] ) ); move16(); } - IF (s_and(idx2, 1)) /* update second context */ + IF( s_and( idx2, 1 ) ) /* update second context */ { - c[p2] = update_mixed_context(c[p2], abs_s(x[b1_i])); + c[p2] = update_mixed_context( c[p2], abs_s( x[b1_i] ) ); move16(); } } } /* end of the 2-tuples loop */ - nbits = add(nbits, target); + nbits = add( nbits, target ); /* Output */ - if (*stop) + if ( *stop ) { nbits = nbits_old; move16(); } - if (stop2) + if ( stop2 ) { stop2 = nbits; move16(); @@ -701,18 +705,18 @@ Word16 ACcontextMapping_encode2_estimate_no_mem_s17_LC_fx( move16(); *stop = stop2; move16(); - if (lastnz_out) + if ( lastnz_out ) { *lastnz_out = lastnz; move16(); } - IF (hm_cfg) + IF( hm_cfg ) { /* Restore hole indices beyond lastnz */ - FOR (k=numHoleIndices; knumHoleIndices; ++k) + FOR( k = numHoleIndices; k < hm_cfg->numHoleIndices; ++k ) { - hm_cfg->holeIndices[k] = sub(hm_cfg->holeIndices[k], nt); + hm_cfg->holeIndices[k] = sub( hm_cfg->holeIndices[k], nt ); move16(); } hm_cfg->numPeakIndices = numPeakIndicesOrig; @@ -735,12 +739,12 @@ Word16 ACcontextMapping_encode2_estimate_no_mem_s17_LC_fx( void RCcontextMapping_encode2_no_mem_s17_LCS( BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ - int16_t* x, + int16_t *x, const int16_t nt, int16_t lastnz, const int16_t nbbits, const int16_t resQMaxBits, - CONTEXT_HM_CONFIG* hm_cfg) + CONTEXT_HM_CONFIG *hm_cfg ) { int16_t ptr[BITBUFSIZE]; RangeUniEncState rc_st_enc; @@ -751,7 +755,7 @@ void RCcontextMapping_encode2_no_mem_s17_LCS( int16_t rateFlag; int16_t value; int16_t nbbits_ntuples, nbbits_lsbs, nbbits_signs; - int16_t* lsbs_bits; + int16_t *lsbs_bits; int16_t nt_half; int16_t signs[N_MAX]; int16_t a1, b1, k; @@ -765,7 +769,7 @@ void RCcontextMapping_encode2_no_mem_s17_LCS( /* Bits for encoding the number of encoded tuples */ nbbits_ntuples = 0; k = 1; - while (k < nt / 2) + while ( k < nt / 2 ) { nbbits_ntuples++; k = k << 1; @@ -775,17 +779,17 @@ void RCcontextMapping_encode2_no_mem_s17_LCS( nbbits_signs = 0; nbbits_lsbs = 0; - if (hm_cfg) + if ( hm_cfg ) { int16_t a1_i, b1_i; - int32_t c[2], * ctx; + int32_t c[2], *ctx; int32_t p1, p2; int16_t ii[2]; int16_t idx1, idx2, idx; int16_t numPeakIndicesOrig, numHoleIndices; /* Rate flag */ - if (nbbits > 400) + if ( nbbits > 400 ) { rateFlag = 2 << NBITS_CONTEXT; } @@ -798,11 +802,11 @@ void RCcontextMapping_encode2_no_mem_s17_LCS( /* mapped domain */ numPeakIndicesOrig = hm_cfg->numPeakIndices; - hm_cfg->numPeakIndices = min(hm_cfg->numPeakIndices, lastnz); + hm_cfg->numPeakIndices = min( hm_cfg->numPeakIndices, lastnz ); numHoleIndices = lastnz - hm_cfg->numPeakIndices; /* Mark hole indices beyond lastnz as pruned */ - for (k = numHoleIndices; k < hm_cfg->numHoleIndices; ++k) + for ( k = numHoleIndices; k < hm_cfg->numHoleIndices; ++k ) { hm_cfg->holeIndices[k] = hm_cfg->holeIndices[k] + nt; } @@ -816,46 +820,46 @@ void RCcontextMapping_encode2_no_mem_s17_LCS( /*Start Encoding*/ /* Initialize range encoder */ - rc_uni_enc_init(&rc_st_enc); + rc_uni_enc_init( &rc_st_enc ); /*Main Loop through the 2-tuples*/ b1_i = -1; - for (k = 0; k < lastnz; k += 2) + for ( k = 0; k < lastnz; k += 2 ) { - a1_i = get_next_coeff_mapped(ii, &p1, &idx1, hm_cfg); - b1_i = get_next_coeff_mapped(ii, &p2, &idx2, hm_cfg); + a1_i = get_next_coeff_mapped( ii, &p1, &idx1, hm_cfg ); + b1_i = get_next_coeff_mapped( ii, &p2, &idx2, hm_cfg ); - idx = min(idx1, idx2); + idx = min( idx1, idx2 ); /* Get context */ ctx = &c[p1 | p2]; - t = (uint16_t)(*ctx + rateFlag); - t += (nt_half >= idx) ? 0 : (1 << NBITS_CONTEXT); + t = (uint16_t) ( *ctx + rateFlag ); + t += ( nt_half >= idx ) ? 0 : ( 1 << NBITS_CONTEXT ); /* Init current 2-tuple encoding */ - a1 = (int16_t)abs(x[a1_i]); - b1 = (int16_t)abs(x[b1_i]); + a1 = (int16_t) abs( x[a1_i] ); + b1 = (int16_t) abs( x[b1_i] ); lev1 = -1; /*Signs encoding*/ - if (a1 > 0) + if ( a1 > 0 ) { - signs[nbbits_signs++] = ((uint16_t)x[a1_i] >> (sizeof(uint16_t) * 8 - 1)); + signs[nbbits_signs++] = ( (uint16_t) x[a1_i] >> ( sizeof( uint16_t ) * 8 - 1 ) ); } - if (b1 > 0) + if ( b1 > 0 ) { - signs[nbbits_signs++] = ((uint16_t)x[b1_i] >> (sizeof(uint16_t) * 8 - 1)); + signs[nbbits_signs++] = ( (uint16_t) x[b1_i] >> ( sizeof( uint16_t ) * 8 - 1 ) ); } /* MSBs coding */ - while (max(a1, b1) >= A_THRES) + while ( max( a1, b1 ) >= A_THRES ) { - pki = ari_lookup_s17_LC[t + ((lev1 + 1) << (NBITS_CONTEXT + NBITS_RATEQ))]; - rc_uni_enc_encode_symbol_fastS(&rc_st_enc, VAL_ESC, cum_freq_ari_pk_s17_LC_ext[pki], sym_freq_ari_pk_s17_LC_ext[pki], 14); /* Encode ESC symbol */ + pki = ari_lookup_s17_LC[t + ( ( lev1 + 1 ) << ( NBITS_CONTEXT + NBITS_RATEQ ) )]; + rc_uni_enc_encode_symbol_fastS( &rc_st_enc, VAL_ESC, cum_freq_ari_pk_s17_LC_ext[pki], sym_freq_ari_pk_s17_LC_ext[pki], 14 ); /* Encode ESC symbol */ *lsbs_bits-- = a1 & 1; *lsbs_bits-- = b1 & 1; @@ -866,47 +870,47 @@ void RCcontextMapping_encode2_no_mem_s17_LCS( a1 >>= 1; b1 >>= 1; - lev1 = min(lev1 + 1, 2); + lev1 = min( lev1 + 1, 2 ); } - pki = ari_lookup_s17_LC[t + ((lev1 + 1) << (NBITS_CONTEXT + NBITS_RATEQ))]; - rc_uni_enc_encode_symbol_fastS(&rc_st_enc, a1 + A_THRES * b1, cum_freq_ari_pk_s17_LC_ext[pki], sym_freq_ari_pk_s17_LC_ext[pki], 14); /* Encode MSB symbol */ + pki = ari_lookup_s17_LC[t + ( ( lev1 + 1 ) << ( NBITS_CONTEXT + NBITS_RATEQ ) )]; + rc_uni_enc_encode_symbol_fastS( &rc_st_enc, a1 + A_THRES * b1, cum_freq_ari_pk_s17_LC_ext[pki], sym_freq_ari_pk_s17_LC_ext[pki], 14 ); /* Encode MSB symbol */ /*Confirm that there is no overflow, i.e. bit-budget has not exceeded */ #ifdef DEBUGGING - assert(rc_uni_enc_virtual_finish(&rc_st_enc) <= nbbits - nbbits_signs - nbbits_lsbs - nbbits_ntuples); + assert( rc_uni_enc_virtual_finish( &rc_st_enc ) <= nbbits - nbbits_signs - nbbits_lsbs - nbbits_ntuples ); #endif /* Update context for next 2-tuple */ - if (p1 == p2) + if ( p1 == p2 ) { /* peak-peak or hole-hole context */ - if (lev1 <= 0) + if ( lev1 <= 0 ) { - t = 1 + (a1 + b1) * (lev1 + 2); + t = 1 + ( a1 + b1 ) * ( lev1 + 2 ); } else { t = 13 + lev1; } - *ctx = (*ctx & 0xf) * 16 + t; + *ctx = ( *ctx & 0xf ) * 16 + t; } else { /* mixed context */ - if (idx1 & 1) + if ( idx1 & 1 ) { /* update first context */ - c[p1] = update_mixed_context(c[p1], (int16_t)abs(x[a1_i])); + c[p1] = update_mixed_context( c[p1], (int16_t) abs( x[a1_i] ) ); } - if (idx2 & 1) + if ( idx2 & 1 ) { /* update second context */ - c[p2] = update_mixed_context(c[p2], (int16_t)abs(x[b1_i])); + c[p2] = update_mixed_context( c[p2], (int16_t) abs( x[b1_i] ) ); } } @@ -919,7 +923,7 @@ void RCcontextMapping_encode2_no_mem_s17_LCS( uint16_t s; /* Rate flag */ - if (nbbits > 400) + if ( nbbits > 400 ) { rateFlag = 2; } @@ -935,7 +939,7 @@ void RCcontextMapping_encode2_no_mem_s17_LCS( a1 = x[0]; x[0] = 1; /* ensure first tuple is non-zero */ - while (x[lastnz - 1] == 0 && x[lastnz - 2] == 0) + while ( x[lastnz - 1] == 0 && x[lastnz - 2] == 0 ) { lastnz -= 2; } @@ -945,37 +949,37 @@ void RCcontextMapping_encode2_no_mem_s17_LCS( /*Start Encoding*/ /* Initialize range encoder */ - rc_uni_enc_init(&rc_st_enc); + rc_uni_enc_init( &rc_st_enc ); /*Main Loop through the 2-tuples*/ - for (k = 0; k < lastnz; k += 2) + for ( k = 0; k < lastnz; k += 2 ) { /* Init current 2-tuple encoding */ - a1 = (int16_t)abs(x[k + 0]); - b1 = (int16_t)abs(x[k + 1]); + a1 = (int16_t) abs( x[k + 0] ); + b1 = (int16_t) abs( x[k + 1] ); lev1 = 0; esc_nb = 0; /*Signs encoding*/ - if (a1 > 0) + if ( a1 > 0 ) { - signs[nbbits_signs++] = ((uint16_t)x[k + 0] >> (sizeof(uint16_t) * 8 - 1)); + signs[nbbits_signs++] = ( (uint16_t) x[k + 0] >> ( sizeof( uint16_t ) * 8 - 1 ) ); } - if (b1 > 0) + if ( b1 > 0 ) { - signs[nbbits_signs++] = ((uint16_t)x[k + 1] >> (sizeof(uint16_t) * 8 - 1)); + signs[nbbits_signs++] = ( (uint16_t) x[k + 1] >> ( sizeof( uint16_t ) * 8 - 1 ) ); } - rateQ = rateFlag + (k > (nt >> 1)); + rateQ = rateFlag + ( k > ( nt >> 1 ) ); /* MSBs coding */ - while (max(a1, b1) >= A_THRES) + while ( max( a1, b1 ) >= A_THRES ) { - pki = ari_lookup_s17_LC[t + ((rateQ) << NBITS_CONTEXT) + (esc_nb << (NBITS_CONTEXT + NBITS_RATEQ))]; - rc_uni_enc_encode_symbol_fastS(&rc_st_enc, VAL_ESC, cum_freq_ari_pk_s17_LC_ext[pki], sym_freq_ari_pk_s17_LC_ext[pki], 14); /* Encode ESC symbol */ + pki = ari_lookup_s17_LC[t + ( ( rateQ ) << NBITS_CONTEXT ) + ( esc_nb << ( NBITS_CONTEXT + NBITS_RATEQ ) )]; + rc_uni_enc_encode_symbol_fastS( &rc_st_enc, VAL_ESC, cum_freq_ari_pk_s17_LC_ext[pki], sym_freq_ari_pk_s17_LC_ext[pki], 14 ); /* Encode ESC symbol */ *lsbs_bits-- = a1 & 1; *lsbs_bits-- = b1 & 1; @@ -987,21 +991,21 @@ void RCcontextMapping_encode2_no_mem_s17_LCS( b1 >>= 1; lev1++; - esc_nb = min(lev1, 3); + esc_nb = min( lev1, 3 ); } - pki = ari_lookup_s17_LC[t + ((rateQ) << NBITS_CONTEXT) + (esc_nb << (NBITS_CONTEXT + NBITS_RATEQ))]; - rc_uni_enc_encode_symbol_fastS(&rc_st_enc, a1 + A_THRES * b1, cum_freq_ari_pk_s17_LC_ext[pki], sym_freq_ari_pk_s17_LC_ext[pki], 14); /* Encode MSB symbol */ + pki = ari_lookup_s17_LC[t + ( ( rateQ ) << NBITS_CONTEXT ) + ( esc_nb << ( NBITS_CONTEXT + NBITS_RATEQ ) )]; + rc_uni_enc_encode_symbol_fastS( &rc_st_enc, a1 + A_THRES * b1, cum_freq_ari_pk_s17_LC_ext[pki], sym_freq_ari_pk_s17_LC_ext[pki], 14 ); /* Encode MSB symbol */ /*Confirm that there is no overflow, i.e. bit-budget has not exceeded */ #ifdef DEBUGGING - assert(rc_uni_enc_virtual_finish(&rc_st_enc) <= nbbits - nbbits_signs - nbbits_lsbs - nbbits_ntuples); + assert( rc_uni_enc_virtual_finish( &rc_st_enc ) <= nbbits - nbbits_signs - nbbits_lsbs - nbbits_ntuples ); #endif /* Update context for next 2-tuple */ - if (esc_nb < 2) + if ( esc_nb < 2 ) { - cp = 1 + ((a1 + b1) * (esc_nb + 1)); + cp = 1 + ( ( a1 + b1 ) * ( esc_nb + 1 ) ); } else { @@ -1009,58 +1013,58 @@ void RCcontextMapping_encode2_no_mem_s17_LCS( } /*Shift old 4 bits, replace last 4 bits*/ - s = (s << 4) + cp; + s = ( s << 4 ) + cp; t = s & 0xFF; } /*end of the 2-tuples loop*/ } /* Finish range encoder */ - rc_tot_bits = rc_uni_enc_finish(&rc_st_enc); /* No. of bits consumed by range coder */ + rc_tot_bits = rc_uni_enc_finish( &rc_st_enc ); /* No. of bits consumed by range coder */ bp = rc_tot_bits + nbbits_ntuples; /* Update bitstream pointer */ /* Cross-check that there is no overflow */ #ifdef DEBUGGING - assert(k == lastnz); + assert( k == lastnz ); #endif /* Push number of encoded tuples */ - value = (lastnz >> 1) - 1; - push_next_indice(hBstr, value, nbbits_ntuples); + value = ( lastnz >> 1 ) - 1; + push_next_indice( hBstr, value, nbbits_ntuples ); /* Push range coded bits from byte_buffer to bitstream */ /* 1) Push all complete bytes, one byte at a time */ - for (k = 0; k < (rc_tot_bits >> 3); k++) + for ( k = 0; k < ( rc_tot_bits >> 3 ); k++ ) { - push_next_indice(hBstr, rc_st_enc.byte_buffer[k], 8); + push_next_indice( hBstr, rc_st_enc.byte_buffer[k], 8 ); } /* 2) Push remaining bits */ - if ((rc_tot_bits & 7) != 0) + if ( ( rc_tot_bits & 7 ) != 0 ) { - push_next_indice(hBstr, rc_st_enc.byte_buffer[k] >> (8 - (rc_tot_bits & 7)), rc_tot_bits & 7); + push_next_indice( hBstr, rc_st_enc.byte_buffer[k] >> ( 8 - ( rc_tot_bits & 7 ) ), rc_tot_bits & 7 ); } /* Push sign bits */ - push_next_bits(hBstr, (uint16_t*)signs, nbbits_signs); + push_next_bits( hBstr, (uint16_t *) signs, nbbits_signs ); bp += nbbits_signs; /*write residual Quantization bits*/ - for (k = 0; k < min(nbbits - bp - nbbits_lsbs, resQMaxBits); k++) + for ( k = 0; k < min( nbbits - bp - nbbits_lsbs, resQMaxBits ); k++ ) { ptr[nbbits - 1 - nbbits_lsbs - k] = x[nt + k]; } /* Write filler bits */ - for (; k < nbbits - bp - nbbits_lsbs; ++k) + for ( ; k < nbbits - bp - nbbits_lsbs; ++k ) { ptr[nbbits - 1 - nbbits_lsbs - k] = 0; } /* Check for debugging */ - assert(bp + k <= nbbits); + assert( bp + k <= nbbits ); /* Push the rest of the buffer */ - push_next_bits(hBstr, (uint16_t*)&ptr[bp], nbbits - bp); + push_next_bits( hBstr, (uint16_t *) &ptr[bp], nbbits - bp ); /* return (bp+nbbits_lsbs);*/ /*return only for debug plot*/ return; @@ -1073,14 +1077,14 @@ void RCcontextMapping_encode2_no_mem_s17_LCS( *-------------------------------------------------------------------*/ int16_t RCcontextMapping_encode2_estimate_no_mem_s17_LCS( - int16_t* x, /* Spectral coefficients */ + int16_t *x, /* Spectral coefficients */ const int16_t nt, /* L - size of spectrum (no. of spectral coefficients) */ - int16_t* lastnz_out, - int16_t* nEncoded, /* No. of spectral coefficients that can be coded without an overflow occuring */ + int16_t *lastnz_out, + int16_t *nEncoded, /* No. of spectral coefficients that can be coded without an overflow occuring */ const int16_t target, /* Target bits */ - int16_t* stop, + int16_t *stop, int16_t mode, - CONTEXT_HM_CONFIG* hm_cfg /* context-based harmonic model configuration */ + CONTEXT_HM_CONFIG *hm_cfg /* context-based harmonic model configuration */ ) { /* Common variables */ @@ -1091,7 +1095,7 @@ int16_t RCcontextMapping_encode2_estimate_no_mem_s17_LCS( int16_t rateFlag; float bit_estimate; int16_t symbol; - const uint8_t* lookup; + const uint8_t *lookup; float nbits2; /* Initialization */ @@ -1101,7 +1105,7 @@ int16_t RCcontextMapping_encode2_estimate_no_mem_s17_LCS( /* bits to encode lastnz */ k = 1; - while (k < nt / 2) + while ( k < nt / 2 ) { bit_estimate++; k = k << 1; @@ -1110,20 +1114,20 @@ int16_t RCcontextMapping_encode2_estimate_no_mem_s17_LCS( nbits2 = bit_estimate; - if (hm_cfg) + if ( hm_cfg ) { int16_t a1_i, b1_i; int16_t stop2; int16_t total_output_bits; int16_t nt_half; - int32_t c[2], * ctx; + int32_t c[2], *ctx; int32_t p1, p2; int16_t ii[2]; int16_t idx1, idx2, idx; int16_t numPeakIndicesOrig = 0, numHoleIndices = 0; /* only to avoid compiler warning */ /* Rate flag */ - if (target > 400) + if ( target > 400 ) { rateFlag = 2 << NBITS_CONTEXT; /* Select context-A for higher bitrates */ } @@ -1137,17 +1141,17 @@ int16_t RCcontextMapping_encode2_estimate_no_mem_s17_LCS( c[0] = c[1] = 0; /* Find last non-zero tuple in the mapped domain signal */ - lastnz = find_last_nz_pair(x, nt, hm_cfg); + lastnz = find_last_nz_pair( x, nt, hm_cfg ); lastnz2 = 2; /* mapped domain */ numPeakIndicesOrig = hm_cfg->numPeakIndices; - hm_cfg->numPeakIndices = min(hm_cfg->numPeakIndices, lastnz); + hm_cfg->numPeakIndices = min( hm_cfg->numPeakIndices, lastnz ); numHoleIndices = lastnz - hm_cfg->numPeakIndices; /* Mark hole indices beyond lastnz as pruned */ - for (k = numHoleIndices; k < hm_cfg->numHoleIndices; ++k) + for ( k = numHoleIndices; k < hm_cfg->numHoleIndices; ++k ) { hm_cfg->holeIndices[k] = hm_cfg->holeIndices[k] + nt; } @@ -1158,44 +1162,44 @@ int16_t RCcontextMapping_encode2_estimate_no_mem_s17_LCS( p1 = p2 = 0; /* to avoid compilation warnings */ /* Main Loop through the 2-tuples */ - for (k = 0; k < lastnz; k += 2) + for ( k = 0; k < lastnz; k += 2 ) { - a1_i = get_next_coeff_mapped(ii, &p1, &idx1, hm_cfg); - b1_i = get_next_coeff_mapped(ii, &p2, &idx2, hm_cfg); + a1_i = get_next_coeff_mapped( ii, &p1, &idx1, hm_cfg ); + b1_i = get_next_coeff_mapped( ii, &p2, &idx2, hm_cfg ); - idx = min(idx1, idx2); + idx = min( idx1, idx2 ); /* Get context */ ctx = &c[p1 | p2]; - t = (uint16_t)(*ctx + rateFlag); - t += (nt_half >= idx) ? 0 : (1 << NBITS_CONTEXT); + t = (uint16_t) ( *ctx + rateFlag ); + t += ( nt_half >= idx ) ? 0 : ( 1 << NBITS_CONTEXT ); /* Init current 2-tuple encoding */ - a1 = (int16_t)abs(x[a1_i]); - b1 = (int16_t)abs(x[b1_i]); - lev1 = -(1 << (NBITS_CONTEXT + NBITS_RATEQ)); + a1 = (int16_t) abs( x[a1_i] ); + b1 = (int16_t) abs( x[b1_i] ); + lev1 = -( 1 << ( NBITS_CONTEXT + NBITS_RATEQ ) ); /* Signs Bits */ - bit_estimate += min(a1, 1); - bit_estimate += min(b1, 1); + bit_estimate += min( a1, 1 ); + bit_estimate += min( b1, 1 ); /* pre-compute address of ari_pk_s17_LC_ext[0][Val_esc] to avoid doing it multiple times inside the loop */ - lookup = &ari_lookup_s17_LC[t] + (1 << (NBITS_CONTEXT + NBITS_RATEQ)); + lookup = &ari_lookup_s17_LC[t] + ( 1 << ( NBITS_CONTEXT + NBITS_RATEQ ) ); /* check while condition */ /* MSBs coding */ - while (max(a1, b1) >= A_THRES) + while ( max( a1, b1 ) >= A_THRES ) { pki = lookup[lev1]; /* ESC symbol */ bit_estimate = bit_estimate + ari_bit_estimate_s17_LC[pki][VAL_ESC]; bit_estimate += 2; /* Add 2 LSB bits corresponding to the bit-plane */ - (a1) >>= 1; - (b1) >>= 1; + ( a1 ) >>= 1; + ( b1 ) >>= 1; - lev1 = min(lev1 + (1 << (NBITS_CONTEXT + NBITS_RATEQ)), 2 << (NBITS_CONTEXT + NBITS_RATEQ)); + lev1 = min( lev1 + ( 1 << ( NBITS_CONTEXT + NBITS_RATEQ ) ), 2 << ( NBITS_CONTEXT + NBITS_RATEQ ) ); /* check while condition */ } @@ -1206,11 +1210,11 @@ int16_t RCcontextMapping_encode2_estimate_no_mem_s17_LCS( bit_estimate = bit_estimate + ari_bit_estimate_s17_LC[pki][symbol]; /* Should we truncate? */ - if (bit_estimate > target) + if ( bit_estimate > target ) { stop2 = 1; - if (*stop) + if ( *stop ) { break; } @@ -1222,47 +1226,47 @@ int16_t RCcontextMapping_encode2_estimate_no_mem_s17_LCS( } /* Update context for next 2-tuple */ - if (p1 == p2) /* peak-peak or hole-hole context */ + if ( p1 == p2 ) /* peak-peak or hole-hole context */ { lev1 >>= NBITS_CONTEXT + NBITS_RATEQ; - if (lev1 <= 0) + if ( lev1 <= 0 ) { - t = 1 + (a1 + b1) * (lev1 + 2); + t = 1 + ( a1 + b1 ) * ( lev1 + 2 ); } else { t = 13 + lev1; } - *ctx = (*ctx & 0xf) * 16 + t; + *ctx = ( *ctx & 0xf ) * 16 + t; } else { /* mixed context */ - if (idx1 & 1) + if ( idx1 & 1 ) { /* update first context */ - c[p1] = update_mixed_context(c[p1], (int16_t)abs(x[a1_i])); + c[p1] = update_mixed_context( c[p1], (int16_t) abs( x[a1_i] ) ); } - if (idx2 & 1) + if ( idx2 & 1 ) { /* update second context */ - c[p2] = update_mixed_context(c[p2], (int16_t)abs(x[b1_i])); + c[p2] = update_mixed_context( c[p2], (int16_t) abs( x[b1_i] ) ); } } } /*end of the 2-tuples loop*/ - total_output_bits = (int16_t)(bit_estimate + 0.5f); - if (*stop) + total_output_bits = (int16_t) ( bit_estimate + 0.5f ); + if ( *stop ) { - total_output_bits = (int16_t)(nbits2 + 0.5f); + total_output_bits = (int16_t) ( nbits2 + 0.5f ); } - if (stop2) + if ( stop2 ) { stop2 = total_output_bits; } @@ -1271,13 +1275,13 @@ int16_t RCcontextMapping_encode2_estimate_no_mem_s17_LCS( *lastnz_out = lastnz; /* Restore hole indices beyond lastnz */ - for (k = numHoleIndices; k < hm_cfg->numHoleIndices; ++k) + for ( k = numHoleIndices; k < hm_cfg->numHoleIndices; ++k ) { hm_cfg->holeIndices[k] = hm_cfg->holeIndices[k] - nt; } hm_cfg->numPeakIndices = numPeakIndicesOrig; - return (int16_t)(nbits2 + 0.5f); + return (int16_t) ( nbits2 + 0.5f ); } else /* if (!hm_cfg) */ { @@ -1287,7 +1291,7 @@ int16_t RCcontextMapping_encode2_estimate_no_mem_s17_LCS( int16_t overflow_flag = 0; /* Rate flag */ - if (target > 400) + if ( target > 400 ) { rateFlag = 2; } @@ -1304,15 +1308,15 @@ int16_t RCcontextMapping_encode2_estimate_no_mem_s17_LCS( tot_bits2 = 0; /* Find last non-zero tuple in the mapped domain signal */ - for (lastnz = (nt - 2); lastnz >= 0; lastnz -= 2) + for ( lastnz = ( nt - 2 ); lastnz >= 0; lastnz -= 2 ) { - if ((x[lastnz] != 0) || (x[lastnz + 1] != 0)) + if ( ( x[lastnz] != 0 ) || ( x[lastnz + 1] != 0 ) ) { break; } } lastnz += 2; - if (lastnz < 2) + if ( lastnz < 2 ) { lastnz = 2; /* At least one tuple is coded */ } @@ -1320,53 +1324,53 @@ int16_t RCcontextMapping_encode2_estimate_no_mem_s17_LCS( lastnz2 = 2; /* Main Loop through the 2-tuples */ - for (k = 0; k < lastnz; k += 2) + for ( k = 0; k < lastnz; k += 2 ) { /* Init current 2-tuple encoding */ - a1 = (int16_t)abs(x[k]); - b1 = (int16_t)abs(x[k + 1]); + a1 = (int16_t) abs( x[k] ); + b1 = (int16_t) abs( x[k + 1] ); lev1 = 0; esc_nb = 0; - rateQ = rateFlag + (k > (nt >> 1)); + rateQ = rateFlag + ( k > ( nt >> 1 ) ); /* Signs Bits */ - bit_estimate += min(a1, 1); - bit_estimate += min(b1, 1); + bit_estimate += min( a1, 1 ); + bit_estimate += min( b1, 1 ); /* pre-compute address of ari_pk_s17_LC_ext[0][Val_esc] to avoid doing it multiple times inside the loop */ - lookup = &ari_lookup_s17_LC[t + (rateQ << NBITS_CONTEXT)]; + lookup = &ari_lookup_s17_LC[t + ( rateQ << NBITS_CONTEXT )]; /* check while condition */ /* MSBs coding */ - while (max(a1, b1) >= A_THRES) + while ( max( a1, b1 ) >= A_THRES ) { - pki = lookup[(esc_nb << (NBITS_CONTEXT + NBITS_RATEQ))]; + pki = lookup[( esc_nb << ( NBITS_CONTEXT + NBITS_RATEQ ) )]; bit_estimate = bit_estimate + ari_bit_estimate_s17_LC[pki][VAL_ESC]; bit_estimate += 2; /* Add 2 LSB bits corresponding to the bit-plane */ - (a1) >>= 1; - (b1) >>= 1; + ( a1 ) >>= 1; + ( b1 ) >>= 1; lev1++; - esc_nb = min(lev1, 3); + esc_nb = min( lev1, 3 ); /* check while condition */ } - pki = lookup[(esc_nb << (NBITS_CONTEXT + NBITS_RATEQ))]; + pki = lookup[( esc_nb << ( NBITS_CONTEXT + NBITS_RATEQ ) )]; symbol = a1 + A_THRES * b1; bit_estimate = bit_estimate + ari_bit_estimate_s17_LC[pki][symbol]; /* Should we truncate? */ - if (bit_estimate > target) /* Overflow occured */ + if ( bit_estimate > target ) /* Overflow occured */ { overflow_flag = 1; } else { - if (abs(x[k]) || abs(x[k + 1])) /* No overflow & non-zero tuple */ + if ( abs( x[k] ) || abs( x[k + 1] ) ) /* No overflow & non-zero tuple */ { nbits2 = bit_estimate; lastnz2 = k + 2; @@ -1374,51 +1378,51 @@ int16_t RCcontextMapping_encode2_estimate_no_mem_s17_LCS( } /* Update context for next 2-tuple */ - if (esc_nb < 2) + if ( esc_nb < 2 ) { - cp = 1 + (a1 + b1) * (esc_nb + 1); + cp = 1 + ( a1 + b1 ) * ( esc_nb + 1 ); } else { cp = 12 + esc_nb; } /*shift old bits and replace last 4 bits*/ - s = (s << 4) + cp; + s = ( s << 4 ) + cp; t = s & 0xFF; } /*end of the 2-tuples loop*/ - tot_bits2 = (int16_t)(nbits2 + 0.5f); - if (lastnz2 < lastnz) /* Overflow occured because unable to code all tuples */ + tot_bits2 = (int16_t) ( nbits2 + 0.5f ); + if ( lastnz2 < lastnz ) /* Overflow occured because unable to code all tuples */ { overflow_flag = 1; } - if (mode == -1) + if ( mode == -1 ) { - tot_bits2 = (int16_t)(bit_estimate + 0.5f); + tot_bits2 = (int16_t) ( bit_estimate + 0.5f ); } - if (overflow_flag == 0) /* No overflow */ + if ( overflow_flag == 0 ) /* No overflow */ { *stop = 0; } else /* Overflow */ { - if (*stop) + if ( *stop ) { *stop = tot_bits2; } else { - *stop = (int16_t)(bit_estimate + 0.5f); + *stop = (int16_t) ( bit_estimate + 0.5f ); } } *lastnz_out = lastnz; *nEncoded = lastnz2; /* Safety mechanism to avoid overflow */ - if (lastnz2 == 2 && overflow_flag == 1) + if ( lastnz2 == 2 && overflow_flag == 1 ) { - for (k = 0; k < lastnz2; k++) + for ( k = 0; k < lastnz2; k++ ) { x[k] = 0; } @@ -1435,15 +1439,15 @@ int16_t RCcontextMapping_encode2_estimate_no_mem_s17_LCS( *-------------------------------------------------------------------*/ int16_t RCcontextMapping_encode2_estimate_bandWise_start( - int16_t* x, + int16_t *x, const int16_t nt, const int16_t target, - HANDLE_RC_CONTEXT_MEM hContextMem) + HANDLE_RC_CONTEXT_MEM hContextMem ) { int16_t i, k; /* Rate flag */ - if (target > 400) + if ( target > 400 ) { hContextMem->rateFlag = 2 << NBITS_CONTEXT; } @@ -1460,7 +1464,7 @@ int16_t RCcontextMapping_encode2_estimate_bandWise_start( /* bits to encode lastnz */ k = 1; - while (k < hContextMem->nt_half) + while ( k < hContextMem->nt_half ) { hContextMem->bit_estimate++; @@ -1469,24 +1473,24 @@ int16_t RCcontextMapping_encode2_estimate_bandWise_start( } /* bits to encode lastnz */ - hContextMem->nbits_old = (int16_t)hContextMem->bit_estimate; + hContextMem->nbits_old = (int16_t) hContextMem->bit_estimate; hContextMem->ctx = 0; hContextMem->lastnz = 2; /* Find last non-zero tuple */ - for (i = nt; i >= 4; i -= 2) + for ( i = nt; i >= 4; i -= 2 ) { - if (x[i - 2] != 0 || x[i - 1] != 0) + if ( x[i - 2] != 0 || x[i - 1] != 0 ) { hContextMem->lastnz = i; break; } } - return (int16_t)hContextMem->bit_estimate; + return (int16_t) hContextMem->bit_estimate; } /*-------------------------------------------------------------------* @@ -1496,10 +1500,10 @@ int16_t RCcontextMapping_encode2_estimate_bandWise_start( *-------------------------------------------------------------------*/ int16_t RCcontextMapping_encode2_estimate_bandWise( - int16_t* x, + int16_t *x, const int16_t start_line, const int16_t end_line, - HANDLE_RC_CONTEXT_MEM hContextMem) + HANDLE_RC_CONTEXT_MEM hContextMem ) { int16_t a1, b1, a1_i, b1_i; int16_t k, pki, lev1; @@ -1507,12 +1511,12 @@ int16_t RCcontextMapping_encode2_estimate_bandWise( int16_t bandBits = 0; int16_t total_output_bits; /* No. of bits after finalization */ int16_t symbol; - const uint8_t* lookup; + const uint8_t *lookup; int16_t idx; /* Main Loop through the 2-tuples */ /*hContextMem->nt_half = end_line >> 1;*/ - for (k = start_line; k < min(hContextMem->lastnz, end_line); k += 2) + for ( k = start_line; k < min( hContextMem->lastnz, end_line ); k += 2 ) { a1_i = k; b1_i = k + 1; @@ -1521,32 +1525,32 @@ int16_t RCcontextMapping_encode2_estimate_bandWise( /* Get context */ t = hContextMem->ctx + hContextMem->rateFlag; - t += (hContextMem->nt_half >= idx) ? 0 : (1 << NBITS_CONTEXT); + t += ( hContextMem->nt_half >= idx ) ? 0 : ( 1 << NBITS_CONTEXT ); /* Init current 2-tuple encoding */ - a1 = (int16_t)abs(x[a1_i]); - b1 = (int16_t)abs(x[b1_i]); - lev1 = -(1 << (NBITS_CONTEXT + NBITS_RATEQ)); + a1 = (int16_t) abs( x[a1_i] ); + b1 = (int16_t) abs( x[b1_i] ); + lev1 = -( 1 << ( NBITS_CONTEXT + NBITS_RATEQ ) ); /* Signs Bits */ - hContextMem->bit_estimate += min(a1, 1); - hContextMem->bit_estimate += min(b1, 1); + hContextMem->bit_estimate += min( a1, 1 ); + hContextMem->bit_estimate += min( b1, 1 ); /* pre-compute address of ari_pk_s17_LC_ext[0][Val_esc] to avoid doing it multiple times inside the loop */ - lookup = &ari_lookup_s17_LC[t] + (1 << (NBITS_CONTEXT + NBITS_RATEQ)); + lookup = &ari_lookup_s17_LC[t] + ( 1 << ( NBITS_CONTEXT + NBITS_RATEQ ) ); /* check while condition */ /* MSBs coding */ - while (max(a1, b1) >= A_THRES) + while ( max( a1, b1 ) >= A_THRES ) { pki = lookup[lev1]; hContextMem->bit_estimate = hContextMem->bit_estimate + ari_bit_estimate_s17_LC[pki][VAL_ESC]; hContextMem->bit_estimate += 2; /* Add the 2 LSB bits that were shifted out */ - (a1) >>= 1; - (b1) >>= 1; + ( a1 ) >>= 1; + ( b1 ) >>= 1; - lev1 = min(lev1 + (1 << (NBITS_CONTEXT + NBITS_RATEQ)), 2 << (NBITS_CONTEXT + NBITS_RATEQ)); + lev1 = min( lev1 + ( 1 << ( NBITS_CONTEXT + NBITS_RATEQ ) ), 2 << ( NBITS_CONTEXT + NBITS_RATEQ ) ); /* check while condition */ } @@ -1557,19 +1561,19 @@ int16_t RCcontextMapping_encode2_estimate_bandWise( /* Update context */ lev1 >>= NBITS_CONTEXT + NBITS_RATEQ; - if (lev1 <= 0) + if ( lev1 <= 0 ) { - t = 1 + (a1 + b1) * (lev1 + 2); + t = 1 + ( a1 + b1 ) * ( lev1 + 2 ); } else { t = 13 + lev1; } - hContextMem->ctx = (hContextMem->ctx & 0xf) * 16 + t; + hContextMem->ctx = ( hContextMem->ctx & 0xf ) * 16 + t; } /*end of the 2-tuples loop*/ - total_output_bits = (int16_t)(hContextMem->bit_estimate + 0.5f); + total_output_bits = (int16_t) ( hContextMem->bit_estimate + 0.5f ); bandBits = total_output_bits - hContextMem->nbits_old; hContextMem->nbits_old = total_output_bits; diff --git a/lib_enc/FEC_enc_fx.c b/lib_enc/FEC_enc_fx.c index 5467a112e..8338409fb 100644 --- a/lib_enc/FEC_enc_fx.c +++ b/lib_enc/FEC_enc_fx.c @@ -2,14 +2,14 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ //#include "prot_fx.h" /* Function prototypes */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "rom_com_fx.h" /* Static table prototypes */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*============================================================================*/ @@ -38,18 +38,18 @@ /* */ /*============================================================================*/ void FEC_encode_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const ACELP_config acelp_cfg, /* i/o: configuration of the ACELP */ - const Word16 *synth, /* i : pointer to synthesized speech for E computation */ - const Word16 coder_type, /* i : type of coder */ - Word16 clas, /* i : signal clas for current frame */ - const Word16 *fpit, /* i : close loop fractional pitch buffer */ - const Word16 *res, /* i : LP residual signal frame */ - Word16 *last_pulse_pos, /* i/o: Position of the last pulse */ - const Word16 L_frame, /* i : Frame length */ - const Word32 total_brate, /* i : total codec bitrate */ - const Word16 Q_new, /* i : input scaling */ - const Word16 shift /* i : scaling to get 12bits */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const ACELP_config acelp_cfg, /* i/o: configuration of the ACELP */ + const Word16 *synth, /* i : pointer to synthesized speech for E computation */ + const Word16 coder_type, /* i : type of coder */ + Word16 clas, /* i : signal clas for current frame */ + const Word16 *fpit, /* i : close loop fractional pitch buffer */ + const Word16 *res, /* i : LP residual signal frame */ + Word16 *last_pulse_pos, /* i/o: Position of the last pulse */ + const Word16 L_frame, /* i : Frame length */ + const Word32 total_brate, /* i : total codec bitrate */ + const Word16 Q_new, /* i : input scaling */ + const Word16 shift /* i : scaling to get 12bits */ ) { Word16 tmpS, index; @@ -65,26 +65,26 @@ void FEC_encode_fx( move16(); test(); test(); - IF( GT_16(coder_type,UNVOICED) && LT_16(coder_type,AUDIO) && acelp_cfg.FEC_mode>0) + IF( GT_16( coder_type, UNVOICED ) && LT_16( coder_type, AUDIO ) && acelp_cfg.FEC_mode > 0 ) { /*-----------------------------------------------------------------* * encode signal class (not needed for VC mode since it is clearly voiced) (2 bits) *-----------------------------------------------------------------*/ - IF ( NE_16(coder_type,VOICED)) + IF( NE_16( coder_type, VOICED ) ) { /* encode signal clas with 2 bits */ test(); - IF(EQ_16(clas,UNVOICED_CLAS)) + IF( EQ_16( clas, UNVOICED_CLAS ) ) { index = 0; move16(); } - ELSE IF( EQ_16(clas,VOICED_TRANSITION)||EQ_16(clas,UNVOICED_TRANSITION)) + ELSE IF( EQ_16( clas, VOICED_TRANSITION ) || EQ_16( clas, UNVOICED_TRANSITION ) ) { index = 1; move16(); } - ELSE IF( EQ_16(clas,VOICED_CLAS)) + ELSE IF( EQ_16( clas, VOICED_CLAS ) ) { index = 2; move16(); @@ -94,59 +94,59 @@ void FEC_encode_fx( index = 3; move16(); } - push_indice_fx(hBstr, IND_FEC_CLAS, index, FEC_BITS_CLS); + push_indice_fx( hBstr, IND_FEC_CLAS, index, FEC_BITS_CLS ); } /*-----------------------------------------------------------------* * encode frame energy (5 bits) *-----------------------------------------------------------------*/ test(); - IF(GT_16(acelp_cfg.FEC_mode, 1)) /* GENERIC and VOICED frames */ + IF( GT_16( acelp_cfg.FEC_mode, 1 ) ) /* GENERIC and VOICED frames */ { /* frame energy (maximum energy per pitch period for voiced frames or mean energy per sample over 2nd halframe for unvoiced frames) */ /*frame_ener( L_frame, clas, synth, fpit[(L_frame>>6)-1], &enr_q, 0 );*/ - exp_enrq = frame_ener_fx( L_frame, clas, synth, shr_r(fpit[sub(shr(L_frame , 6),1)],6), &enr_q, L_frame, Q_new, shift, 1); + exp_enrq = frame_ener_fx( L_frame, clas, synth, shr_r( fpit[sub( shr( L_frame, 6 ), 1 )], 6 ), &enr_q, L_frame, Q_new, shift, 1 ); /* linearly quantize the energy in the range 0 : FEC_ENR_STEP : 96 dB */ /*tmpS = (short)( 10.0 * log10( enr_q + 0.001f ) / FEC_ENR_STEP )*/ /*To be converted fl_2_fx*/ - enr_lg_frac = Log2_norm_lc(enr_q); - enr_lg_ent = sub(30, exp_enrq); - Ltmp = Mpy_32_16(enr_lg_ent,enr_lg_frac, LG10_s3_0); - tmpS = extract_h(L_shl(Ltmp, 1)); + enr_lg_frac = Log2_norm_lc( enr_q ); + enr_lg_ent = sub( 30, exp_enrq ); + Ltmp = Mpy_32_16( enr_lg_ent, enr_lg_frac, LG10_s3_0 ); + tmpS = extract_h( L_shl( Ltmp, 1 ) ); - tmpS = s_min(tmpS, 31); - tmpS = s_max(tmpS, 0); + tmpS = s_min( tmpS, 31 ); + tmpS = s_max( tmpS, 0 ); - push_indice_fx(hBstr, IND_FEC_ENR, tmpS, FEC_BITS_ENR ); + push_indice_fx( hBstr, IND_FEC_ENR, tmpS, FEC_BITS_ENR ); } /*-----------------------------------------------------------------* - * Encode last glottal pulse position (8 bits) + * Encode last glottal pulse position (8 bits) *-----------------------------------------------------------------*/ test(); - IF(GT_16(acelp_cfg.FEC_mode, 2)) /* GENERIC frames */ + IF( GT_16( acelp_cfg.FEC_mode, 2 ) ) /* GENERIC frames */ { /* retrieve the last glottal pulse position of the previous frame */ /* use the current pitch information to scale or not the quantization */ - tmp_FER_pitch = shr(fpit[0],6); /* take the 1st subframe pit, since it is easier to get on decoder side */ + tmp_FER_pitch = shr( fpit[0], 6 ); /* take the 1st subframe pit, since it is easier to get on decoder side */ sign = 0; move16(); maxi = *last_pulse_pos; move16(); - IF ( maxi < 0 ) + IF( maxi < 0 ) { sign = 1; move16(); /*maxi = -maxi; */ - maxi = negate(maxi); + maxi = negate( maxi ); } - if ( GE_16(tmp_FER_pitch,128)) + if ( GE_16( tmp_FER_pitch, 128 ) ) { - maxi = shr(maxi , 1); + maxi = shr( maxi, 1 ); } - if ( GT_16(maxi,127)) + if ( GT_16( maxi, 127 ) ) { /* better not use the glottal pulse position at all instead of using a wrong pulse */ /* can happen only with pitch > 254 and max pit = 289 and should happen very rarely */ @@ -154,12 +154,12 @@ void FEC_encode_fx( move16(); } - if( sign == 1 ) + if ( sign == 1 ) { - maxi = add(maxi,128);/* use 8 bits (MSB represent the sign of the pulse) */ + maxi = add( maxi, 128 ); /* use 8 bits (MSB represent the sign of the pulse) */ } - push_indice_fx(hBstr, IND_FEC_POS, maxi, FEC_BITS_POS ); + push_indice_fx( hBstr, IND_FEC_POS, maxi, FEC_BITS_POS ); } maxi = 0; move16(); @@ -167,14 +167,14 @@ void FEC_encode_fx( /* If bitrate < 24k4, then the pitch is not represented in the same domain (12.k instead of 16k) */ test(); - IF( GE_16(clas,VOICED_CLAS)&&GE_32(total_brate,ACELP_24k40)) + IF( GE_16( clas, VOICED_CLAS ) && GE_32( total_brate, ACELP_24k40 ) ) { /*maxi = findpulse( L_frame, res, (short)(fpit[(L_frame>>6)-1]), 0, &sign ); */ - maxi = findpulse_fx( L_frame, res, shr_r(fpit[sub(shr(L_frame , 6) , 1)], 6), 0, &sign ); + maxi = findpulse_fx( L_frame, res, shr_r( fpit[sub( shr( L_frame, 6 ), 1 )], 6 ), 0, &sign ); if ( sign == 1 ) { /*maxi = -maxi;*/ - maxi = negate(maxi); + maxi = negate( maxi ); } } @@ -192,22 +192,22 @@ void FEC_encode_fx( /*-------------------------------------------------------------------* -* FEC_lsf_estim_enc_fx() -* -* Simulates LSF estimation in case of FEC in the encoder ( only one frame erasure is considered ) -* The estimated LSF vector is then used to check LSF stability and may invoke safety-net usage in the next frame -*-------------------------------------------------------------------*/ + * FEC_lsf_estim_enc_fx() + * + * Simulates LSF estimation in case of FEC in the encoder ( only one frame erasure is considered ) + * The estimated LSF vector is then used to check LSF stability and may invoke safety-net usage in the next frame + *-------------------------------------------------------------------*/ void FEC_lsf_estim_enc_fx( - Encoder_State *st_fx, /* i : Encoder static memory */ - Word16 *lsf /* o : estimated LSF vector */ + Encoder_State *st_fx, /* i : Encoder static memory */ + Word16 *lsf /* o : estimated LSF vector */ ) { Word16 i; Word16 alpha, lsf_mean[M]; Word16 tmp; - IF( EQ_16(st_fx->L_frame, L_FRAME)) + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { Copy( UVWB_Ave_fx, lsf_mean, M ); } @@ -220,7 +220,7 @@ void FEC_lsf_estim_enc_fx( * Initialize the alpha factor *----------------------------------------------------------------------*/ - IF( EQ_16(st_fx->last_coder_type, UNVOICED)) + IF( EQ_16( st_fx->last_coder_type, UNVOICED ) ) { /* clearly unvoiced */ alpha = _ALPHA_UU_FX; @@ -230,29 +230,29 @@ void FEC_lsf_estim_enc_fx( { test(); test(); - IF( EQ_16(st_fx->last_coder_type, AUDIO)||EQ_16(st_fx->clas,INACTIVE_CLAS)) + IF( EQ_16( st_fx->last_coder_type, AUDIO ) || EQ_16( st_fx->clas, INACTIVE_CLAS ) ) { alpha = 32604; move16(); } - ELSE IF( EQ_16(st_fx->clas, UNVOICED_CLAS)) + ELSE IF( EQ_16( st_fx->clas, UNVOICED_CLAS ) ) { /* if stable, do not flatten the spectrum in the first erased frame */ /* alpha = st->stab_fac * (1.0f - 2.0f*ALPHA_U) + 2.0f*ALPHA_U; */ - alpha = add(mult(st_fx->stab_fac_fx, 32768 - _ALPHA_U_FX_X_2), _ALPHA_U_FX_X_2); + alpha = add( mult( st_fx->stab_fac_fx, 32768 - _ALPHA_U_FX_X_2 ), _ALPHA_U_FX_X_2 ); } - ELSE IF( EQ_16(st_fx->clas, UNVOICED_TRANSITION)) + ELSE IF( EQ_16( st_fx->clas, UNVOICED_TRANSITION ) ) { alpha = _ALPHA_UT_FX; move16(); } - ELSE IF( EQ_16(st_fx->clas, VOICED_CLAS)||EQ_16(st_fx->clas,ONSET)) + ELSE IF( EQ_16( st_fx->clas, VOICED_CLAS ) || EQ_16( st_fx->clas, ONSET ) ) { /* clearly voiced - mild convergence to the CNG spectrum for the first three erased frames */ alpha = _ALPHA_V_FX; move16(); } - ELSE IF( EQ_16(st_fx->clas, SIN_ONSET)) + ELSE IF( EQ_16( st_fx->clas, SIN_ONSET ) ) { alpha = _ALPHA_S_FX; move16(); @@ -267,27 +267,27 @@ void FEC_lsf_estim_enc_fx( /*----------------------------------------------------------------------* * Extrapolate LSF vector *----------------------------------------------------------------------*/ - tmp = sub(32767, alpha); + tmp = sub( 32767, alpha ); /* extrapolate the old LSF vector */ - FOR (i=0; ilsf_adaptive_mean[i]; */ - lsf_mean[i] = mac_r(L_mult(BETA_FEC_FX, lsf_mean[i]), 32768-BETA_FEC_FX, st_fx->lsf_adaptive_mean_fx[i]); + lsf_mean[i] = mac_r( L_mult( BETA_FEC_FX, lsf_mean[i] ), 32768 - BETA_FEC_FX, st_fx->lsf_adaptive_mean_fx[i] ); /* move old LSF vector towards the mean LSF vector */ /* lsf[i] = alpha * st->lsf_old[i] + (1.0f - alpha) * lsf_mean[i]; */ - lsf[i] = mac_r(L_mult(alpha, st_fx->lsf_old_fx[i]), tmp, lsf_mean[i]); + lsf[i] = mac_r( L_mult( alpha, st_fx->lsf_old_fx[i] ), tmp, lsf_mean[i] ); } /* check LSF stability through LSF ordering */ - IF( EQ_16(st_fx->L_frame, L_FRAME)) + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { - reorder_lsf_fx( lsf, MODE1_LSF_GAP_FX, M , INT_FS_FX); + reorder_lsf_fx( lsf, MODE1_LSF_GAP_FX, M, INT_FS_FX ); } - ELSE /* L_frame == L_FRAME16k */ + ELSE /* L_frame == L_FRAME16k */ { - reorder_lsf_fx( lsf, MODE1_LSF_GAP_FX, M, INT_FS_16k_FX); + reorder_lsf_fx( lsf, MODE1_LSF_GAP_FX, M, INT_FS_16k_FX ); } return; diff --git a/lib_enc/SNR_calc_fx.c b/lib_enc/SNR_calc_fx.c index 90fee4382..f39bc2b86 100644 --- a/lib_enc/SNR_calc_fx.c +++ b/lib_enc/SNR_calc_fx.c @@ -1,71 +1,71 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include #include "options.h" #include "basop_util.h" #include "vad_basop.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ #include "rom_enc.h" #include "rom_com.h" - /*-------------------------------------------------------------------* - * calc_lf_snr_fx() - * - * - *-------------------------------------------------------------------*/ +/*-------------------------------------------------------------------* + * calc_lf_snr_fx() + * + * + *-------------------------------------------------------------------*/ void calc_lf_snr_fx( - Word32 *lf_snr_smooth, /* o : smoothed lf_snr*/ - Word32 *lf_snr, /* o : long time frequency domain - SNR calculated by l_speech_snr and l_silence_snr*/ - const Word32 l_speech_snr, /* i : sum of active frames snr */ - const Word32 l_speech_snr_count, /* i : amount of the active frame */ - const Word32 l_silence_snr, /* i : sum of the nonactive frames snr*/ - const Word32 l_silence_snr_count,/* i : amount of the nonactive frame */ - const Word16 fg_energy_count, /* i : amount of the foreground energy frame */ - const Word16 bg_energy_count, /* i : amount of the background energy frame */ - const Word16 bw_index /* i : band width index*/ + Word32 *lf_snr_smooth, /* o : smoothed lf_snr*/ + Word32 *lf_snr, /* o : long time frequency domain + SNR calculated by l_speech_snr and l_silence_snr*/ + const Word32 l_speech_snr, /* i : sum of active frames snr */ + const Word32 l_speech_snr_count, /* i : amount of the active frame */ + const Word32 l_silence_snr, /* i : sum of the nonactive frames snr*/ + const Word32 l_silence_snr_count, /* i : amount of the nonactive frame */ + const Word16 fg_energy_count, /* i : amount of the foreground energy frame */ + const Word16 bg_energy_count, /* i : amount of the background energy frame */ + const Word16 bw_index /* i : band width index*/ ) { - Word32 l_snr, div1, div2, tmp; - Word16 q_divout, q_divout1; + Word32 l_snr, div1, div2, tmp; + Word16 q_divout, q_divout1; - div1 = VAD_L_div(l_speech_snr, l_speech_snr_count, 16, 0, &q_divout); - div2 = VAD_L_div(l_silence_snr, l_silence_snr_count, 16, 0, &q_divout1); - l_snr = VAD_L_ADD(div1, q_divout, L_negate(div2), q_divout1, &q_divout); + div1 = VAD_L_div( l_speech_snr, l_speech_snr_count, 16, 0, &q_divout ); + div2 = VAD_L_div( l_silence_snr, l_silence_snr_count, 16, 0, &q_divout1 ); + l_snr = VAD_L_ADD( div1, q_divout, L_negate( div2 ), q_divout1, &q_divout ); - *lf_snr_smooth = MUL_F(*lf_snr_smooth, 29490/* 0.9 Q15 */); - move32(); - tmp = MUL_F(l_snr, 26214); - *lf_snr_smooth = VAD_L_ADD(*lf_snr_smooth, 25, tmp, add(3, q_divout), &q_divout1); - move32(); - *lf_snr_smooth = L_shr(*lf_snr_smooth, sub(q_divout1, 25)); - move32(); - l_snr = L_shr(l_snr, sub(q_divout, 25)); + *lf_snr_smooth = MUL_F( *lf_snr_smooth, 29490 /* 0.9 Q15 */ ); + move32(); + tmp = MUL_F( l_snr, 26214 ); + *lf_snr_smooth = VAD_L_ADD( *lf_snr_smooth, 25, tmp, add( 3, q_divout ), &q_divout1 ); + move32(); + *lf_snr_smooth = L_shr( *lf_snr_smooth, sub( q_divout1, 25 ) ); + move32(); + l_snr = L_shr( l_snr, sub( q_divout, 25 ) ); - test(); - if ((LT_16(bg_energy_count, 56)) || (LT_16(fg_energy_count, 56))) - { - l_snr = 161061275/* 4.8 Q25 */; - move32(); - } + test(); + if ( ( LT_16( bg_energy_count, 56 ) ) || ( LT_16( fg_energy_count, 56 ) ) ) + { + l_snr = 161061275 /* 4.8 Q25 */; + move32(); + } - l_snr = MUL_F(l_snr, 3932/* 0.12 Q15 */); - l_snr = L_sub(l_snr, 12079595/* 0.36 Q25 */); + l_snr = MUL_F( l_snr, 3932 /* 0.12 Q15 */ ); + l_snr = L_sub( l_snr, 12079595 /* 0.36 Q25 */ ); - l_snr = L_max(0, l_snr); - l_snr = L_min(l_snr, MAX_LF_SNR_TAB_FX[bw_index]); + l_snr = L_max( 0, l_snr ); + l_snr = L_min( l_snr, MAX_LF_SNR_TAB_FX[bw_index] ); - *lf_snr = l_snr; - move32(); - return; + *lf_snr = l_snr; + move32(); + return; } /*-------------------------------------------------------------------* * calc_lt_snr_fx() @@ -73,97 +73,98 @@ void calc_lf_snr_fx( * *-------------------------------------------------------------------*/ void calc_lt_snr_fx( - VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ - Word32 *lt_snr_org_fp, /* o : original long time SNR*/ - Word32 *lt_snr_fp, /* o : long time SNR calculated by fg_energy and bg_energy*/ - Word32 fg_energy, /* i : foreground energy sum */ - Word16 fg_energy_count, /* i : amount of the foreground energy frame */ - Word32 bg_energy, /* i : background energy sum */ - Word16 bg_energy_count, /* i : amount of the background energy frame */ - Word16 bw_index, /* i : band width index*/ - Word16 lt_noise_sp_center0 /* i : long time noise spectral center by 0*/ + VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ + Word32 *lt_snr_org_fp, /* o : original long time SNR*/ + Word32 *lt_snr_fp, /* o : long time SNR calculated by fg_energy and bg_energy*/ + Word32 fg_energy, /* i : foreground energy sum */ + Word16 fg_energy_count, /* i : amount of the foreground energy frame */ + Word32 bg_energy, /* i : background energy sum */ + Word16 bg_energy_count, /* i : amount of the background energy frame */ + Word16 bw_index, /* i : band width index*/ + Word16 lt_noise_sp_center0 /* i : long time noise spectral center by 0*/ ) { - Word16 tmp_lt_noise_sp_center; - Word16 q_div1, q_div2, q_divout, q_divout1; - Word32 lt_snr_org; - Word32 lt_snr, div1, div2, tmp; - - - tmp_lt_noise_sp_center = sub(lt_noise_sp_center0, 1432/* 1.4 Q10 */); - if (GT_16(tmp_lt_noise_sp_center, 818/* 0.8 Q10 */)) - { - tmp_lt_noise_sp_center = 818/* 0.8 Q10 */; - move16(); - } - - if (tmp_lt_noise_sp_center < 0) - { - tmp_lt_noise_sp_center = 0; - move16(); - } - - div1 = MUL_F(fg_energy, bg_energy_count); - div1 = VAD_L_ADD(div1, hVAD_CLDFB->fg_energy_scale, 1, 126, &q_div1); - div2 = MUL_F(bg_energy, fg_energy_count); - div2 = VAD_L_ADD(div2, hVAD_CLDFB->bg_energy_scale, 1, 126, &q_div2); - if (div2 == 0) - { - div2 = 1; - move32(); /* div2==0 , may occur for >30000 frames all zero input */ - if (div1 != 0) - { - hVAD_CLDFB->bg_energy_scale = add(hVAD_CLDFB->fg_energy_scale, 50); - } - } - div2 = VAD_L_div(div1, div2, q_div1, q_div2, &q_divout); - lt_snr_org = VAD_Log2(div2, q_divout); - lt_snr_org = MUL_F(lt_snr_org, 9864); - lt_snr = lt_snr_org; move32(); - *lt_snr_org_fp = lt_snr; - move32(); - - test(); - IF(LT_16(bg_energy_count, 56) || LT_16(fg_energy_count, 56)) - { - lt_snr = 70464302/* 2.1 Q25 */; - move32(); - } - - IF(EQ_16(bw_index, CLDFBVAD_NB_ID)) - { - lt_snr = L_sub(L_shr(lt_snr, 1), 25165823/* 0.75 Q25 */); - } - ELSE IF(EQ_16(bw_index, CLDFBVAD_WB_ID)) - { - lt_snr = L_sub(L_shr(lt_snr, 1), 25165823/* 0.75 Q25 */); - } - ELSE - { - lt_snr = MUL_F(lt_snr, 15073/* 0.46 Q15 */); - lt_snr = L_sub(lt_snr, 23152557/* 0.69 Q25 */); - } - - tmp = MUL_F(lt_snr, 13107/* 0.4 Q15 */); - - tmp = L_add(L_shr(tmp, 1), -26214); - - tmp = MUL_F(tmp, 13107/* 0.4 Q15 */); - tmp = MUL_F(tmp, tmp_lt_noise_sp_center); - lt_snr = VAD_L_ADD(lt_snr, 25, tmp, 19, &q_divout1); - lt_snr = L_shr(lt_snr, sub(q_divout1, 25)); - - lt_snr = L_max(0, lt_snr); - - if (GT_32(lt_snr, 67108862/* 2.0 Q25 */)) - { - lt_snr = 67108862/* 2.0 Q25 */; - move32(); - } - - *lt_snr_fp = lt_snr; - move32(); - return; + Word16 tmp_lt_noise_sp_center; + Word16 q_div1, q_div2, q_divout, q_divout1; + Word32 lt_snr_org; + Word32 lt_snr, div1, div2, tmp; + + + tmp_lt_noise_sp_center = sub( lt_noise_sp_center0, 1432 /* 1.4 Q10 */ ); + if ( GT_16( tmp_lt_noise_sp_center, 818 /* 0.8 Q10 */ ) ) + { + tmp_lt_noise_sp_center = 818 /* 0.8 Q10 */; + move16(); + } + + if ( tmp_lt_noise_sp_center < 0 ) + { + tmp_lt_noise_sp_center = 0; + move16(); + } + + div1 = MUL_F( fg_energy, bg_energy_count ); + div1 = VAD_L_ADD( div1, hVAD_CLDFB->fg_energy_scale, 1, 126, &q_div1 ); + div2 = MUL_F( bg_energy, fg_energy_count ); + div2 = VAD_L_ADD( div2, hVAD_CLDFB->bg_energy_scale, 1, 126, &q_div2 ); + if ( div2 == 0 ) + { + div2 = 1; + move32(); /* div2==0 , may occur for >30000 frames all zero input */ + if ( div1 != 0 ) + { + hVAD_CLDFB->bg_energy_scale = add( hVAD_CLDFB->fg_energy_scale, 50 ); + } + } + div2 = VAD_L_div( div1, div2, q_div1, q_div2, &q_divout ); + lt_snr_org = VAD_Log2( div2, q_divout ); + lt_snr_org = MUL_F( lt_snr_org, 9864 ); + lt_snr = lt_snr_org; + move32(); + *lt_snr_org_fp = lt_snr; + move32(); + + test(); + IF( LT_16( bg_energy_count, 56 ) || LT_16( fg_energy_count, 56 ) ) + { + lt_snr = 70464302 /* 2.1 Q25 */; + move32(); + } + + IF( EQ_16( bw_index, CLDFBVAD_NB_ID ) ) + { + lt_snr = L_sub( L_shr( lt_snr, 1 ), 25165823 /* 0.75 Q25 */ ); + } + ELSE IF( EQ_16( bw_index, CLDFBVAD_WB_ID ) ) + { + lt_snr = L_sub( L_shr( lt_snr, 1 ), 25165823 /* 0.75 Q25 */ ); + } + ELSE + { + lt_snr = MUL_F( lt_snr, 15073 /* 0.46 Q15 */ ); + lt_snr = L_sub( lt_snr, 23152557 /* 0.69 Q25 */ ); + } + + tmp = MUL_F( lt_snr, 13107 /* 0.4 Q15 */ ); + + tmp = L_add( L_shr( tmp, 1 ), -26214 ); + + tmp = MUL_F( tmp, 13107 /* 0.4 Q15 */ ); + tmp = MUL_F( tmp, tmp_lt_noise_sp_center ); + lt_snr = VAD_L_ADD( lt_snr, 25, tmp, 19, &q_divout1 ); + lt_snr = L_shr( lt_snr, sub( q_divout1, 25 ) ); + + lt_snr = L_max( 0, lt_snr ); + + if ( GT_32( lt_snr, 67108862 /* 2.0 Q25 */ ) ) + { + lt_snr = 67108862 /* 2.0 Q25 */; + move32(); + } + + *lt_snr_fp = lt_snr; + move32(); + return; } /*-------------------------------------------------------------------* @@ -172,55 +173,54 @@ void calc_lt_snr_fx( * *-------------------------------------------------------------------*/ void calc_snr_flux_fx( - Word32 tsnr, /* i : time-domain SNR*/ - Word32 *pre_snr, /* i/o: time-domain SNR storage*/ - Word32 *snr_flux_fp /* o : average tsnr*/ + Word32 tsnr, /* i : time-domain SNR*/ + Word32 *pre_snr, /* i/o: time-domain SNR storage*/ + Word32 *snr_flux_fp /* o : average tsnr*/ ) { - Word32 i; - Word32 tmp, snr_flux; - Word16 s16MaxCoefNorm; - /*save a new time-domain SNR to pre_snr[0]*/ - - - test(); - IF((LT_32(L_shr(tsnr, 1), 43620759/* 2.6f/2.0f Q25 */)) && tsnr > 0) - { - pre_snr[0] = tsnr; - move32(); - } - ELSE IF(tsnr <= 0) - { - pre_snr[0] = 0; - move32(); - } - ELSE - { - pre_snr[0] = 87241517/* 2.6 Q25 */; - move32(); - } - - /*calculate snr_flux*/ - snr_flux = 0; - move32(); - s16MaxCoefNorm = sub(ffr_getSfWord32(pre_snr, 32), 5); - FOR(i = 0; i < 32; i++) - { - tmp = L_shl(pre_snr[i], s16MaxCoefNorm); - snr_flux = L_add(snr_flux, tmp); - } - snr_flux = L_shr(snr_flux, add(s16MaxCoefNorm, 5)); - *snr_flux_fp = snr_flux; - move32(); - - /*update the tsnr storage pre_snr*/ - FOR(i = PRE_SNR_NUM - 1; i > 0; i--) - { - pre_snr[i] = pre_snr[i - 1]; - move32(); - } - return; - + Word32 i; + Word32 tmp, snr_flux; + Word16 s16MaxCoefNorm; + /*save a new time-domain SNR to pre_snr[0]*/ + + + test(); + IF( ( LT_32( L_shr( tsnr, 1 ), 43620759 /* 2.6f/2.0f Q25 */ ) ) && tsnr > 0 ) + { + pre_snr[0] = tsnr; + move32(); + } + ELSE IF( tsnr <= 0 ) + { + pre_snr[0] = 0; + move32(); + } + ELSE + { + pre_snr[0] = 87241517 /* 2.6 Q25 */; + move32(); + } + + /*calculate snr_flux*/ + snr_flux = 0; + move32(); + s16MaxCoefNorm = sub( ffr_getSfWord32( pre_snr, 32 ), 5 ); + FOR( i = 0; i < 32; i++ ) + { + tmp = L_shl( pre_snr[i], s16MaxCoefNorm ); + snr_flux = L_add( snr_flux, tmp ); + } + snr_flux = L_shr( snr_flux, add( s16MaxCoefNorm, 5 ) ); + *snr_flux_fp = snr_flux; + move32(); + + /*update the tsnr storage pre_snr*/ + FOR( i = PRE_SNR_NUM - 1; i > 0; i-- ) + { + pre_snr[i] = pre_snr[i - 1]; + move32(); + } + return; } @@ -230,320 +230,324 @@ void calc_snr_flux_fx( * *-------------------------------------------------------------------*/ void snr_calc( - VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ - const Word16 sacle_sbpower, /* i : the Scaling of sbpower*/ - Word32 *snr, /* o : frequency domain SNR */ - Word32* tsnr, /* o : time domain SNR */ - const Word32 frame_energy, /* i : current frame energy */ - const Word32 bwidth /* i : audio band width*/ + VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ + const Word16 sacle_sbpower, /* i : the Scaling of sbpower*/ + Word32 *snr, /* o : frequency domain SNR */ + Word32 *tsnr, /* o : time domain SNR */ + const Word32 frame_energy, /* i : current frame energy */ + const Word32 bwidth /* i : audio band width*/ ) { - Word32 i; - Word32 tmpframe_eg, tmpsb_eg, constff, div1, div2; - Word32 snr_tmp, tmp; - - Word32 SNR_sb_num; - Word32 *sb_bg_energy; - Word32 *frame_sb_energy; - Word32 t_bg_energy; - Word16 tmp_addQ1, tmp_addQ2, minscale, minscale1, minscale2, s16MaxCoefNorm, q_divout; - Word32 tmpspec_amp; - Word32 const CONSTfix = 1759218560; - Word32 snr_tmpidx[12] = { 0 }; - - - SNR_sb_num = SNR_SUB_BAND_NUM[bwidth - CLDFBVAD_NB_ID]; - move16(); - sb_bg_energy = hVAD_CLDFB->sb_bg_energy; - frame_sb_energy = hVAD_CLDFB->frame_sb_energy; - t_bg_energy = hVAD_CLDFB->t_bg_energy; - move32(); - - snr_tmp = 0; - move32(); - FOR(i = 0; i < SNR_sb_num; i++) - { - div1 = VAD_L_ADD(frame_sb_energy[i], hVAD_CLDFB->frame_sb_energy_scale, CONSTfix, 44, &tmp_addQ1); - div2 = VAD_L_ADD(sb_bg_energy[i], hVAD_CLDFB->sb_bg_energy_scale, CONSTfix, 44, &tmp_addQ2); - tmp = VAD_L_div(div1, div2, tmp_addQ1, tmp_addQ2, &q_divout); - tmp = VAD_Log2(tmp, q_divout); - - if (GT_32(tmp, -3355443/* -0.10 Q25 */)) - { - snr_tmpidx[i] = tmp; - move32(); - } - } - - s16MaxCoefNorm = sub(ffr_getSfWord32(snr_tmpidx, (Word16)SNR_sb_num), 4); - FOR(i = 0; i < SNR_sb_num; i++) - { - tmpspec_amp = L_shl(snr_tmpidx[i], s16MaxCoefNorm); - snr_tmp = L_add(snr_tmp, tmpspec_amp); - } - snr_tmp = L_max(0, snr_tmp); - snr_tmp = MUL_F(snr_tmp, BAND_MUL[bwidth - CLDFBVAD_NB_ID]); - *snr = L_shr(snr_tmp, s16MaxCoefNorm); - move32(); - - IF(bwidth == CLDFBVAD_SWB_ID) - { - IF(t_bg_energy) - { - minscale = norm_l(t_bg_energy); - minscale2 = sub(s_min(add(minscale, hVAD_CLDFB->scale_t_bg_energy), 31), 1); - tmpsb_eg = L_shr(t_bg_energy, sub(hVAD_CLDFB->scale_t_bg_energy, minscale2)); - constff = L_shr(1, sub(31, minscale2)); - } - ELSE - { - tmpsb_eg = 0; move32(); - constff = 1; move32(); - minscale2 = 31; - move16(); - } - div2 = L_add(tmpsb_eg, constff); - tmp = VAD_L_div(frame_energy, div2, sacle_sbpower, minscale2, &q_divout); - IF(tmp) - { - minscale = norm_l(tmp); - minscale2 = sub(s_min(add(minscale, q_divout), 31), 1); - tmpsb_eg = L_shr(tmp, limitScale32(sub(q_divout, minscale2))); - constff = L_shr(1, sub(31, minscale2)); - tmp = L_add(tmpsb_eg, constff); - } - ELSE - { - tmp = 1; move32(); - minscale2 = 31; - move16(); - } - *tsnr = VAD_Log2(tmp, minscale2); - move32(); + Word32 i; + Word32 tmpframe_eg, tmpsb_eg, constff, div1, div2; + Word32 snr_tmp, tmp; + + Word32 SNR_sb_num; + Word32 *sb_bg_energy; + Word32 *frame_sb_energy; + Word32 t_bg_energy; + Word16 tmp_addQ1, tmp_addQ2, minscale, minscale1, minscale2, s16MaxCoefNorm, q_divout; + Word32 tmpspec_amp; + Word32 const CONSTfix = 1759218560; + Word32 snr_tmpidx[12] = { 0 }; + + + SNR_sb_num = SNR_SUB_BAND_NUM[bwidth - CLDFBVAD_NB_ID]; + move16(); + sb_bg_energy = hVAD_CLDFB->sb_bg_energy; + frame_sb_energy = hVAD_CLDFB->frame_sb_energy; + t_bg_energy = hVAD_CLDFB->t_bg_energy; + move32(); + + snr_tmp = 0; + move32(); + FOR( i = 0; i < SNR_sb_num; i++ ) + { + div1 = VAD_L_ADD( frame_sb_energy[i], hVAD_CLDFB->frame_sb_energy_scale, CONSTfix, 44, &tmp_addQ1 ); + div2 = VAD_L_ADD( sb_bg_energy[i], hVAD_CLDFB->sb_bg_energy_scale, CONSTfix, 44, &tmp_addQ2 ); + tmp = VAD_L_div( div1, div2, tmp_addQ1, tmp_addQ2, &q_divout ); + tmp = VAD_Log2( tmp, q_divout ); + + if ( GT_32( tmp, -3355443 /* -0.10 Q25 */ ) ) + { + snr_tmpidx[i] = tmp; + move32(); + } + } + + s16MaxCoefNorm = sub( ffr_getSfWord32( snr_tmpidx, (Word16) SNR_sb_num ), 4 ); + FOR( i = 0; i < SNR_sb_num; i++ ) + { + tmpspec_amp = L_shl( snr_tmpidx[i], s16MaxCoefNorm ); + snr_tmp = L_add( snr_tmp, tmpspec_amp ); + } + snr_tmp = L_max( 0, snr_tmp ); + snr_tmp = MUL_F( snr_tmp, BAND_MUL[bwidth - CLDFBVAD_NB_ID] ); + *snr = L_shr( snr_tmp, s16MaxCoefNorm ); + move32(); + + IF( bwidth == CLDFBVAD_SWB_ID ) + { + IF( t_bg_energy ) + { + minscale = norm_l( t_bg_energy ); + minscale2 = sub( s_min( add( minscale, hVAD_CLDFB->scale_t_bg_energy ), 31 ), 1 ); + tmpsb_eg = L_shr( t_bg_energy, sub( hVAD_CLDFB->scale_t_bg_energy, minscale2 ) ); + constff = L_shr( 1, sub( 31, minscale2 ) ); + } + ELSE + { + tmpsb_eg = 0; + move32(); + constff = 1; + move32(); + minscale2 = 31; + move16(); + } + div2 = L_add( tmpsb_eg, constff ); + tmp = VAD_L_div( frame_energy, div2, sacle_sbpower, minscale2, &q_divout ); + IF( tmp ) + { + minscale = norm_l( tmp ); + minscale2 = sub( s_min( add( minscale, q_divout ), 31 ), 1 ); + tmpsb_eg = L_shr( tmp, limitScale32( sub( q_divout, minscale2 ) ) ); + constff = L_shr( 1, sub( 31, minscale2 ) ); + tmp = L_add( tmpsb_eg, constff ); + } + ELSE + { + tmp = 1; + move32(); + minscale2 = 31; + move16(); + } + *tsnr = VAD_Log2( tmp, minscale2 ); + move32(); #ifdef BASOP_NOGLOB *tsnr = L_add_sat( *tsnr, MUL_F( *tsnr, 6226 ) ); /* *tsnr *= 1.2; */ #else - *tsnr = L_add(*tsnr, MUL_F(*tsnr, 6226)); /* *tsnr *= 1.2; */ + *tsnr = L_add( *tsnr, MUL_F( *tsnr, 6226 ) ); /* *tsnr *= 1.2; */ #endif - move32(); - } - ELSE - { - IF(frame_energy) - { - minscale = norm_l(frame_energy); - minscale1 = sub(s_min(add(minscale,sacle_sbpower),44),1); - tmpframe_eg = L_shr(frame_energy,sub(sacle_sbpower,minscale1)); - constff = L_shr(CONSTfix,sub(44,minscale1)); - } - ELSE - { - tmpframe_eg = 0; move32(); - constff = CONSTfix; move32(); - minscale1 = 44; - move16(); - } - div1 = L_add(tmpframe_eg, constff); - IF(t_bg_energy) - { - minscale = norm_l(t_bg_energy); - minscale2 = sub(s_min(add(minscale,hVAD_CLDFB->scale_t_bg_energy),44),1); - tmpsb_eg = L_shr(t_bg_energy,sub(hVAD_CLDFB->scale_t_bg_energy,minscale2)); - constff = L_shr(CONSTfix,sub(44,minscale2)); - } - ELSE - { - tmpsb_eg = 0; move32(); - constff = CONSTfix; move32(); - minscale2 = 44; - move16(); - } - div2 = L_add(tmpsb_eg, constff); - tmp = VAD_L_div(div1, div2, minscale1, minscale2, &q_divout); - *tsnr = VAD_Log2(tmp,q_divout); - move32(); - } - return; + move32(); + } + ELSE + { + IF( frame_energy ) + { + minscale = norm_l( frame_energy ); + minscale1 = sub( s_min( add( minscale, sacle_sbpower ), 44 ), 1 ); + tmpframe_eg = L_shr( frame_energy, sub( sacle_sbpower, minscale1 ) ); + constff = L_shr( CONSTfix, sub( 44, minscale1 ) ); + } + ELSE + { + tmpframe_eg = 0; + move32(); + constff = CONSTfix; + move32(); + minscale1 = 44; + move16(); + } + div1 = L_add( tmpframe_eg, constff ); + IF( t_bg_energy ) + { + minscale = norm_l( t_bg_energy ); + minscale2 = sub( s_min( add( minscale, hVAD_CLDFB->scale_t_bg_energy ), 44 ), 1 ); + tmpsb_eg = L_shr( t_bg_energy, sub( hVAD_CLDFB->scale_t_bg_energy, minscale2 ) ); + constff = L_shr( CONSTfix, sub( 44, minscale2 ) ); + } + ELSE + { + tmpsb_eg = 0; + move32(); + constff = CONSTfix; + move32(); + minscale2 = 44; + move16(); + } + div2 = L_add( tmpsb_eg, constff ); + tmp = VAD_L_div( div1, div2, minscale1, minscale2, &q_divout ); + *tsnr = VAD_Log2( tmp, q_divout ); + move32(); + } + return; } Word32 construct_snr_thresh_fx( - Word16 sp_center[], /* i : spectral center*/ - Word32 snr_flux, /* i : snr flux*/ - Word32 lt_snr, /* i : long time time domain snr*/ - Word32 l_snr, /* i : long time frequency domain snr*/ - Word32 continuous_speech_num, /* i : amount of continuous speech frames*/ - Word16 continuous_noise_num, /* i : amount of continuous noise frames*/ - Word32 fg_energy_est_start, /* i : whether if estimated energy*/ - Word16 bw_index /* i : band width index*/ + Word16 sp_center[], /* i : spectral center*/ + Word32 snr_flux, /* i : snr flux*/ + Word32 lt_snr, /* i : long time time domain snr*/ + Word32 l_snr, /* i : long time frequency domain snr*/ + Word32 continuous_speech_num, /* i : amount of continuous speech frames*/ + Word16 continuous_noise_num, /* i : amount of continuous noise frames*/ + Word32 fg_energy_est_start, /* i : whether if estimated energy*/ + Word16 bw_index /* i : band width index*/ ) { - Word32 bw_snr, tmp_snr, snr_delta, test_l_snr, tmp, div1, div2; - - - - - snr_delta = COMVAD_INIT_SNR_DELTA_FX[bw_index]; - move32(); - bw_snr = lt_snr; - move32(); - - - - test_l_snr = lt_snr; move32(); - IF(EQ_16(bw_index, CLDFBVAD_SWB_ID)) - { - - IF(GT_16(sp_center[3], 2864/* 2.80 Q10 */)) - { - snr_delta = snr_delta; - move32(); - } - ELSE IF(GT_16(sp_center[2], 2660/* 2.6 Q10 */)) - { - snr_delta = L_add(snr_delta, 1006633/* 0.03 Q25 */); - } - ELSE IF(GT_16(sp_center[2], 1637/* 1.6 Q10 */)) - { - snr_delta = L_add(snr_delta, 1677722/* 0.05 Q25 */); - } - ELSE IF(GT_16(sp_center[3], 1432/* 1.4 Q10 */)) - { - snr_delta = L_add(snr_delta, 3355443/* 0.10 Q25 */); - } - ELSE - { - snr_delta = L_add(snr_delta , 13421773/* 0.40 Q25 */); - } - - tmp = MUL_F(l_snr, 3277/* 0.1 Q15 */); - tmp = L_add(tmp, 20132659/* 0.6 Q25 */); - - test(); - test(); - IF(GT_32(continuous_speech_num, 8) && EQ_32(fg_energy_est_start, 1)) - { - snr_delta = L_sub(snr_delta, 6710886/* 0.2 Q25 */); - } - ELSE IF(GT_16(continuous_noise_num, 12) && (GT_32(snr_flux, tmp))) - { - snr_delta = L_add(snr_delta, 3355443/* 0.10 Q25 */); - } - ELSE IF(GT_16(continuous_noise_num, 24)) - { - snr_delta = L_add(snr_delta, 6710886/* 0.2 Q25 */); - } - ELSE IF((GT_16(continuous_noise_num, 4))) - { - snr_delta = L_add(snr_delta, 3355443/* 0.10 Q25 */); - } - } - ELSE IF(EQ_16(bw_index, CLDFBVAD_WB_ID)) - { - - IF(GT_16(sp_center[3], 2864/* 2.80 Q10 */)) - { - snr_delta = snr_delta; - move32(); - } - ELSE IF(GT_16(sp_center[2], 2660/* 2.6 Q10 */)) - { - snr_delta = L_add(snr_delta, 1006633/* 0.03 Q25 */); - } - ELSE IF(GT_16(sp_center[2], 1637/* 1.6 Q10 */)) - { - snr_delta = L_add(snr_delta, 1677722/* 0.05 Q25 */); - } - ELSE IF(GT_16(sp_center[3], 1432/* 1.4 Q10 */)) - { - snr_delta = L_add(snr_delta, 3355443/* 0.10 Q25 */); - } - ELSE - { - snr_delta = L_add(snr_delta, 10066330/* 0.30 Q25 */); - } - - tmp = MUL_F(bw_snr, 3277/* 0.1 Q15 */); - tmp = L_add(tmp, 20132659/* 0.6 Q25 */); - - test(); - test(); - IF(GT_32(continuous_speech_num, 8) && EQ_32(fg_energy_est_start, 1)) - { - snr_delta = L_sub(snr_delta, 3355443/* 0.10 Q25 */); - } - ELSE IF(GT_16(continuous_noise_num, 12) && (GT_32(snr_flux, tmp))) - { - snr_delta = L_add(snr_delta, 3355443/* 0.10 Q25 */); - } - ELSE IF(GT_16(continuous_noise_num, 24)) - { - snr_delta = L_add(snr_delta, 6710886/* 0.20 Q25 */); - } - ELSE IF((GT_16(continuous_noise_num, 4))) - { - snr_delta = L_add(snr_delta, 3355443/* 0.10 Q25 */); - } - } - ELSE IF(EQ_16(bw_index, CLDFBVAD_NB_ID)) - { - - IF(GT_16(sp_center[3], 3069/* 3.0 Q10 */)) - { - snr_delta = snr_delta; - move32(); - } - ELSE IF(GT_16(sp_center[2], 2660/* 2.6 Q10 */)) - { - snr_delta = L_add(snr_delta, 671089/* 0.02 Q25 */); - } - ELSE IF(GT_16(sp_center[2], 1637/* 1.6 Q10 */)) - { - snr_delta = L_add(snr_delta, 1342177/* 0.04 Q25 */); - } - ELSE IF(GT_16(sp_center[2], 1494/* 1.46 Q10 */)) - { - snr_delta = L_add(snr_delta, 3355443/* 0.10 Q25 */); - } - ELSE - { - snr_delta = L_add(snr_delta , 6039798/* 0.18 Q25 */); - } - - tmp = MUL_F(l_snr, 3277/* 0.1 Q15 */); - div1 = L_add(tmp, 6710886/* 0.2 Q25 */); - div2 = L_add(tmp, 20132659/* 0.6 Q25 */); - - test(); - test(); - test(); - test(); - test(); - IF(GT_32(continuous_speech_num, 80) && EQ_32(fg_energy_est_start, 1) && (GT_16(sp_center[0], 1432/* 1.4 Q10 */))) - { - snr_delta = L_sub(snr_delta, 10737418/* 0.32 Q25 */); - } - ELSE IF(GT_32(continuous_speech_num, 8) && EQ_32(fg_energy_est_start, 1) && (GT_32(snr_flux, div1))) - { - snr_delta = L_sub(snr_delta, 3355443/* 0.10 Q25 */); - } - ELSE IF(GT_16(continuous_noise_num, 12) && (GT_32(snr_flux, div2))) - { - snr_delta = L_add(snr_delta, 3355443/* 0.10 Q25 */); - } - ELSE IF(GT_16(continuous_noise_num, 24)) - { - snr_delta = L_add(snr_delta, 6710886/* 0.2 Q25 */); - } - } - ELSE - { - snr_delta = 33554431/* 1.0 Q25 */; - move32(); - } - tmp_snr = L_add(snr_delta, test_l_snr); - - - return tmp_snr; + Word32 bw_snr, tmp_snr, snr_delta, test_l_snr, tmp, div1, div2; + + + snr_delta = COMVAD_INIT_SNR_DELTA_FX[bw_index]; + move32(); + bw_snr = lt_snr; + move32(); + + + test_l_snr = lt_snr; + move32(); + IF( EQ_16( bw_index, CLDFBVAD_SWB_ID ) ) + { + + IF( GT_16( sp_center[3], 2864 /* 2.80 Q10 */ ) ) + { + snr_delta = snr_delta; + move32(); + } + ELSE IF( GT_16( sp_center[2], 2660 /* 2.6 Q10 */ ) ) + { + snr_delta = L_add( snr_delta, 1006633 /* 0.03 Q25 */ ); + } + ELSE IF( GT_16( sp_center[2], 1637 /* 1.6 Q10 */ ) ) + { + snr_delta = L_add( snr_delta, 1677722 /* 0.05 Q25 */ ); + } + ELSE IF( GT_16( sp_center[3], 1432 /* 1.4 Q10 */ ) ) + { + snr_delta = L_add( snr_delta, 3355443 /* 0.10 Q25 */ ); + } + ELSE + { + snr_delta = L_add( snr_delta, 13421773 /* 0.40 Q25 */ ); + } + + tmp = MUL_F( l_snr, 3277 /* 0.1 Q15 */ ); + tmp = L_add( tmp, 20132659 /* 0.6 Q25 */ ); + + test(); + test(); + IF( GT_32( continuous_speech_num, 8 ) && EQ_32( fg_energy_est_start, 1 ) ) + { + snr_delta = L_sub( snr_delta, 6710886 /* 0.2 Q25 */ ); + } + ELSE IF( GT_16( continuous_noise_num, 12 ) && ( GT_32( snr_flux, tmp ) ) ) + { + snr_delta = L_add( snr_delta, 3355443 /* 0.10 Q25 */ ); + } + ELSE IF( GT_16( continuous_noise_num, 24 ) ) + { + snr_delta = L_add( snr_delta, 6710886 /* 0.2 Q25 */ ); + } + ELSE IF( ( GT_16( continuous_noise_num, 4 ) ) ) + { + snr_delta = L_add( snr_delta, 3355443 /* 0.10 Q25 */ ); + } + } + ELSE IF( EQ_16( bw_index, CLDFBVAD_WB_ID ) ) + { + + IF( GT_16( sp_center[3], 2864 /* 2.80 Q10 */ ) ) + { + snr_delta = snr_delta; + move32(); + } + ELSE IF( GT_16( sp_center[2], 2660 /* 2.6 Q10 */ ) ) + { + snr_delta = L_add( snr_delta, 1006633 /* 0.03 Q25 */ ); + } + ELSE IF( GT_16( sp_center[2], 1637 /* 1.6 Q10 */ ) ) + { + snr_delta = L_add( snr_delta, 1677722 /* 0.05 Q25 */ ); + } + ELSE IF( GT_16( sp_center[3], 1432 /* 1.4 Q10 */ ) ) + { + snr_delta = L_add( snr_delta, 3355443 /* 0.10 Q25 */ ); + } + ELSE + { + snr_delta = L_add( snr_delta, 10066330 /* 0.30 Q25 */ ); + } + + tmp = MUL_F( bw_snr, 3277 /* 0.1 Q15 */ ); + tmp = L_add( tmp, 20132659 /* 0.6 Q25 */ ); + + test(); + test(); + IF( GT_32( continuous_speech_num, 8 ) && EQ_32( fg_energy_est_start, 1 ) ) + { + snr_delta = L_sub( snr_delta, 3355443 /* 0.10 Q25 */ ); + } + ELSE IF( GT_16( continuous_noise_num, 12 ) && ( GT_32( snr_flux, tmp ) ) ) + { + snr_delta = L_add( snr_delta, 3355443 /* 0.10 Q25 */ ); + } + ELSE IF( GT_16( continuous_noise_num, 24 ) ) + { + snr_delta = L_add( snr_delta, 6710886 /* 0.20 Q25 */ ); + } + ELSE IF( ( GT_16( continuous_noise_num, 4 ) ) ) + { + snr_delta = L_add( snr_delta, 3355443 /* 0.10 Q25 */ ); + } + } + ELSE IF( EQ_16( bw_index, CLDFBVAD_NB_ID ) ) + { + + IF( GT_16( sp_center[3], 3069 /* 3.0 Q10 */ ) ) + { + snr_delta = snr_delta; + move32(); + } + ELSE IF( GT_16( sp_center[2], 2660 /* 2.6 Q10 */ ) ) + { + snr_delta = L_add( snr_delta, 671089 /* 0.02 Q25 */ ); + } + ELSE IF( GT_16( sp_center[2], 1637 /* 1.6 Q10 */ ) ) + { + snr_delta = L_add( snr_delta, 1342177 /* 0.04 Q25 */ ); + } + ELSE IF( GT_16( sp_center[2], 1494 /* 1.46 Q10 */ ) ) + { + snr_delta = L_add( snr_delta, 3355443 /* 0.10 Q25 */ ); + } + ELSE + { + snr_delta = L_add( snr_delta, 6039798 /* 0.18 Q25 */ ); + } + + tmp = MUL_F( l_snr, 3277 /* 0.1 Q15 */ ); + div1 = L_add( tmp, 6710886 /* 0.2 Q25 */ ); + div2 = L_add( tmp, 20132659 /* 0.6 Q25 */ ); + + test(); + test(); + test(); + test(); + test(); + IF( GT_32( continuous_speech_num, 80 ) && EQ_32( fg_energy_est_start, 1 ) && ( GT_16( sp_center[0], 1432 /* 1.4 Q10 */ ) ) ) + { + snr_delta = L_sub( snr_delta, 10737418 /* 0.32 Q25 */ ); + } + ELSE IF( GT_32( continuous_speech_num, 8 ) && EQ_32( fg_energy_est_start, 1 ) && ( GT_32( snr_flux, div1 ) ) ) + { + snr_delta = L_sub( snr_delta, 3355443 /* 0.10 Q25 */ ); + } + ELSE IF( GT_16( continuous_noise_num, 12 ) && ( GT_32( snr_flux, div2 ) ) ) + { + snr_delta = L_add( snr_delta, 3355443 /* 0.10 Q25 */ ); + } + ELSE IF( GT_16( continuous_noise_num, 24 ) ) + { + snr_delta = L_add( snr_delta, 6710886 /* 0.2 Q25 */ ); + } + } + ELSE + { + snr_delta = 33554431 /* 1.0 Q25 */; + move32(); + } + tmp_snr = L_add( snr_delta, test_l_snr ); + + + return tmp_snr; } - diff --git a/lib_enc/acelp_core_enc.c b/lib_enc/acelp_core_enc.c index 923cd6eea..771e0bc9e 100644 --- a/lib_enc/acelp_core_enc.c +++ b/lib_enc/acelp_core_enc.c @@ -70,12 +70,12 @@ ivas_error acelp_core_enc( float pitch_buf[NB_SUBFR16k], /* o : floating pitch for each subframe */ int16_t *unbits, /* o : number of unused bits */ STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ - float tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ + float tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ ) { int16_t i, nBits; /* reserved bits */ LPD_state_HANDLE hLPDmem; /* i/o: acelp memories */ - float old_exc_flt[L_EXC], *exc; /* excitation signal buffer */ + float old_exc_flt[L_EXC], *exc; /* excitation signal buffer */ float lsf_new[M]; /* ISFs at the end of the frame */ float Aq[NB_SUBFR16k * ( M + 1 )]; /* A(z) quantized for the 4 subframes */ float syn[L_FRAME16k]; /* synthesis signal buffer */ @@ -422,22 +422,22 @@ ivas_error acelp_core_enc( Word16 lsp_new_fx[M]; Word16 tdm_lsfQ_PCh_fx[M]; Word16 lsf_wgts_fx[M]; - for (int ii = 0; ii < M; ii++) + for ( int ii = 0; ii < M; ii++ ) { - lsf_new_fx[ii] = (Word16)((lsf_new[ii]) * 2.56f); - tdm_lsfQ_PCh_fx[ii] = (Word16)((tdm_lsfQ_PCh[ii]) * 2.56f); - lsf_wgts_fx[ii] = (Word16)((lsf_wgts[ii]) * 2.56f); + lsf_new_fx[ii] = (Word16) ( ( lsf_new[ii] ) * 2.56f ); + tdm_lsfQ_PCh_fx[ii] = (Word16) ( ( tdm_lsfQ_PCh[ii] ) * 2.56f ); + lsf_wgts_fx[ii] = (Word16) ( ( lsf_wgts[ii] ) * 2.56f ); } - floatToFixed_arr(lsp_new, lsp_new_fx, 15, M); + floatToFixed_arr( lsp_new, lsp_new_fx, 15, M ); - tdm_SCh_lsf_reuse_fx(ENC, st->element_brate, lsf_new_fx, lsp_new_fx, tdm_lsfQ_PCh_fx, lsf_wgts_fx, &beta_index); + tdm_SCh_lsf_reuse_fx( ENC, st->element_brate, lsf_new_fx, lsp_new_fx, tdm_lsfQ_PCh_fx, lsf_wgts_fx, &beta_index ); - for (int ii = 0; ii < M; ii++) + for ( int ii = 0; ii < M; ii++ ) { - lsf_new[ii] = (Word16)((lsf_new_fx[ii]) / 2.56f); - lsf_wgts[ii] = (Word16)((lsf_wgts_fx[ii]) / 2.56f); + lsf_new[ii] = (Word16) ( ( lsf_new_fx[ii] ) / 2.56f ); + lsf_wgts[ii] = (Word16) ( ( lsf_wgts_fx[ii] ) / 2.56f ); } - fixedToFloat_arr(lsp_new_fx, lsp_new, 15, M); + fixedToFloat_arr( lsp_new_fx, lsp_new, 15, M ); #else tdm_SCh_lsf_reuse( ENC, st->element_brate, lsf_new, lsp_new, tdm_lsfQ_PCh, lsf_wgts, &beta_index ); #endif diff --git a/lib_enc/acelp_core_enc_fx.c b/lib_enc/acelp_core_enc_fx.c index ecc3557bf..3d4eda605 100644 --- a/lib_enc/acelp_core_enc_fx.c +++ b/lib_enc/acelp_core_enc_fx.c @@ -4,16 +4,16 @@ #include #include -#include "options.h" /* Compilation switches */ +#include "options.h" /* Compilation switches */ #include "cnst.h" #include "prot_fx1.h" #include "prot_fx2.h" #include "stat_enc.h" #include "rom_com.h" -#include "rom_enc.h" /* Encoder static table prototypes */ -#include "rom_com_fx.h" /* Static table prototypes */ +#include "rom_enc.h" /* Encoder static table prototypes */ +#include "rom_com_fx.h" /* Static table prototypes */ //#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* * acelp_core_enc() @@ -21,51 +21,51 @@ * ACELP core encoder *--------------------------------------------------------------------*/ ivas_error acelp_core_enc_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 inp_fx[], /* i : input signal of the current frame */ - const Word32 ener_fx, /* i : residual energy from Levinson-Durbin*/ - Word16 A_fx[NB_SUBFR16k*(M+1)], /* i : A(z) unquantized for the 4 subframes*/ - Word16 Aw_fx[NB_SUBFR16k*(M+1)], /* i : weighted A(z) unquant. for subframes*/ - const Word16 epsP_h_fx[M+1], /* i : LP prediction errors */ - const Word16 epsP_l_fx[M+1], /* i : LP prediction errors */ - Word16 lsp_new_fx[M], /* i : LSPs at the end of the frame */ - Word16 lsp_mid_fx[M], /* i : LSPs in the middle of the frame */ - Word16 vad_hover_flag_fx, /* i : VAD hangover flag */ - const Word16 attack_flag, /* i : attack flag (GSC or TC) */ - Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation */ - Word16 *voice_factors_fx, /* o : voicing factors */ - Word16 old_syn_12k8_16k_fx[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE */ - Word16 pitch_buf_fx[NB_SUBFR16k], /* o : floating pitch for each subframe */ - Word16 *unbits_fx, /* o : number of unused bits */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word16 inp_fx[], /* i : input signal of the current frame */ + const Word32 ener_fx, /* i : residual energy from Levinson-Durbin*/ + Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes*/ + Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquant. for subframes*/ + const Word16 epsP_h_fx[M + 1], /* i : LP prediction errors */ + const Word16 epsP_l_fx[M + 1], /* i : LP prediction errors */ + Word16 lsp_new_fx[M], /* i : LSPs at the end of the frame */ + Word16 lsp_mid_fx[M], /* i : LSPs in the middle of the frame */ + Word16 vad_hover_flag_fx, /* i : VAD hangover flag */ + const Word16 attack_flag, /* i : attack flag (GSC or TC) */ + Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation */ + Word16 *voice_factors_fx, /* o : voicing factors */ + Word16 old_syn_12k8_16k_fx[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE */ + Word16 pitch_buf_fx[NB_SUBFR16k], /* o : floating pitch for each subframe */ + Word16 *unbits_fx, /* o : number of unused bits */ const Word16 Q_new, const Word16 shift #ifdef ADD_LRTD - , + , STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ const float tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ #endif ) { - Word16 nBits; /* reserved bits */ + Word16 nBits; /* reserved bits */ Word16 i; - Word16 old_exc_fx[L_EXC], *exc_fx; /* excitation signal buffer */ - Word16 lsf_new_fx[M]; /* ISFs at the end of the frame */ - Word16 Aq_fx[NB_SUBFR16k*(M+1)]; /* A(z) quantized for the 4 subframes */ - Word16 syn_fx[L_FRAME16k]; /* synthesis vector */ - Word16 res_fx[L_FRAME16k]; /* Residual signal for FER protection */ - Word16 exc2_fx[L_FRAME16k]; /* enhanced excitation */ - Word16 Es_pred_fx; /* predicited scaled innovation energy */ - Word16 tmp_noise_fx; /* NB post-filter long-term noise energy*/ - Word16 tc_subfr_fx, position; /* TC sub-frame indication */ - Word16 old_bwe_exc_fx[(PIT16k_MAX + (L_FRAME16k + 1) + L_SUBFR16k) * 2]; /* excitation buffer */ - Word16 *bwe_exc_fx; /* excitation for SWB TBE */ + Word16 old_exc_fx[L_EXC], *exc_fx; /* excitation signal buffer */ + Word16 lsf_new_fx[M]; /* ISFs at the end of the frame */ + Word16 Aq_fx[NB_SUBFR16k * ( M + 1 )]; /* A(z) quantized for the 4 subframes */ + Word16 syn_fx[L_FRAME16k]; /* synthesis vector */ + Word16 res_fx[L_FRAME16k]; /* Residual signal for FER protection */ + Word16 exc2_fx[L_FRAME16k]; /* enhanced excitation */ + Word16 Es_pred_fx; /* predicited scaled innovation energy */ + Word16 tmp_noise_fx; /* NB post-filter long-term noise energy*/ + Word16 tc_subfr_fx, position; /* TC sub-frame indication */ + Word16 old_bwe_exc_fx[( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2]; /* excitation buffer */ + Word16 *bwe_exc_fx; /* excitation for SWB TBE */ Word16 allow_cn_step_fx; Word16 int_fs_fx; Word32 L_epsP[2]; /* SC-VBR - back-up memories for LSF quantizer and synthesis filter */ Word16 mCb1_fx, pstreaklen_fx; Word16 mem_MA_fx[M], mem_AR_fx[M], lsp_new_bck_fx[M], lsf_new_bck_fx[M], lsp_mid_bck_fx[M], mem_syn_bck_fx[M]; - Word32 Bin_E_fx[L_FFT], Bin_E_old_fx[L_FFT/2]; + Word32 Bin_E_fx[L_FFT], Bin_E_old_fx[L_FFT / 2]; Word16 clip_var_fx, mem_w0_bck_fx, streaklimit_fx; Word16 nb_bits; Word16 indice; @@ -78,19 +78,19 @@ ivas_error acelp_core_enc_fx( Word16 clip_var_bck_fx[6]; Word16 next_force_sf_bck_fx; Word32 q_env[NUM_ENV_CNG]; - Word16 sid_bw=-1; + Word16 sid_bw = -1; Word16 coder_type; Word16 exc3_fx[L_FRAME16k]; Word16 syn1_fx[L_FRAME16k]; Word16 ppp_mode, nelp_mode; Word16 tdm_lp_reuse_flag, tdm_low_rate_mode, tdm_Pitch_reuse_flag; - Word16* tdm_Pri_pitch_buf; + Word16 *tdm_Pri_pitch_buf; Word16 uc_two_stage_flag; Word16 att; - SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; - DTX_ENC_HANDLE hDtxEnc = st_fx->hDtxEnc; - TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; + SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; + DTX_ENC_HANDLE hDtxEnc = st_fx->hDtxEnc; + TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc; TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; @@ -101,7 +101,7 @@ ivas_error acelp_core_enc_fx( error = IVAS_ERR_OK; test(); - IF (EQ_16(st_fx->element_mode, IVAS_CPE_MDCT) && LE_32(st_fx->core_brate, SID_2k40) ) + IF( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) && LE_32( st_fx->core_brate, SID_2k40 ) ) { /* Core was ACELP because of DTX in MDCT-Stereo, but SID encoding for that is done in separate function */ return error; @@ -115,13 +115,13 @@ ivas_error acelp_core_enc_fx( coder_type = st_fx->coder_type; - exc_fx = old_exc_fx + L_EXC_MEM; /* pointer to excitation signal in the current frame */ - Copy(hLPDmem->old_exc, old_exc_fx, L_EXC_MEM ); + exc_fx = old_exc_fx + L_EXC_MEM; /* pointer to excitation signal in the current frame */ + Copy( hLPDmem->old_exc, old_exc_fx, L_EXC_MEM ); - IF(hBWE_TD != NULL) + IF( hBWE_TD != NULL ) { - bwe_exc_fx = old_bwe_exc_fx + PIT16k_MAX * 2; /* pointer to BWE excitation signal in the current frame */ - Copy(hBWE_TD->old_bwe_exc_fx, old_bwe_exc_fx, PIT16k_MAX * 2); + bwe_exc_fx = old_bwe_exc_fx + PIT16k_MAX * 2; /* pointer to BWE excitation signal in the current frame */ + Copy( hBWE_TD->old_bwe_exc_fx, old_bwe_exc_fx, PIT16k_MAX * 2 ); } ELSE { @@ -130,14 +130,16 @@ ivas_error acelp_core_enc_fx( st_fx->bpf_off = 0; move16(); - test();test();test(); - IF( EQ_16(st_fx->last_core,HQ_CORE) || EQ_16(st_fx->last_codec_mode,MODE2) || - EQ_16(st_fx->last_core, TCX_20_CORE) || EQ_16(st_fx->last_core, TCX_10_CORE) ) + test(); + test(); + test(); + IF( EQ_16( st_fx->last_core, HQ_CORE ) || EQ_16( st_fx->last_codec_mode, MODE2 ) || + EQ_16( st_fx->last_core, TCX_20_CORE ) || EQ_16( st_fx->last_core, TCX_10_CORE ) ) { /* in case of HQ->ACELP switching, do not apply BPF */ st_fx->bpf_off = 1; move16(); - if (hGSCEnc != NULL) + if ( hGSCEnc != NULL ) { hGSCEnc->Last_frame_ener_fx = MAX_32; move32(); @@ -145,16 +147,16 @@ ivas_error acelp_core_enc_fx( } /* force safety-net LSFQ in the first frames after CNG segment */ - if( LE_32(st_fx->last_core_brate,SID_2k40)) + if ( LE_32( st_fx->last_core_brate, SID_2k40 ) ) { st_fx->Nb_ACELP_frames = 0; move16(); } - st_fx->Nb_ACELP_frames = add(st_fx->Nb_ACELP_frames,1); + st_fx->Nb_ACELP_frames = add( st_fx->Nb_ACELP_frames, 1 ); int_fs_fx = INT_FS_16k_FX; move16(); - if( EQ_16(st_fx->L_frame, L_FRAME)) + if ( EQ_16( st_fx->L_frame, L_FRAME ) ) { int_fs_fx = INT_FS_FX; move16(); @@ -180,26 +182,27 @@ ivas_error acelp_core_enc_fx( move16(); /* channel-aware mode */ - reset_rf_indices_fx(st_fx); + reset_rf_indices_fx( st_fx ); /* VBR modes */ - IF (st_fx->Opt_SC_VBR) + IF( st_fx->Opt_SC_VBR ) { ppp_mode = hSC_VBR->ppp_mode; nelp_mode = hSC_VBR->nelp_mode; - move16(); move16(); - + move16(); + move16(); } ELSE { ppp_mode = 0; nelp_mode = 0; - move16();move16(); + move16(); + move16(); } /* TD stereo */ test(); #ifdef ADD_LRTD - IF (EQ_16(st_fx->element_mode, IVAS_CPE_TD) && EQ_16(st_fx->idchan, 1)) + IF( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && EQ_16( st_fx->idchan, 1 ) ) { tdm_lp_reuse_flag = hStereoTD->tdm_lp_reuse_flag; tdm_low_rate_mode = hStereoTD->tdm_low_rate_mode; @@ -211,21 +214,23 @@ ivas_error acelp_core_enc_fx( { tdm_lp_reuse_flag = 0; tdm_low_rate_mode = 0; - move16(); move16(); - if (EQ_16(st_fx->element_mode, IVAS_SCE) && st_fx->low_rate_mode) + move16(); + move16(); + if ( EQ_16( st_fx->element_mode, IVAS_SCE ) && st_fx->low_rate_mode ) { tdm_low_rate_mode = 1; move16(); } tdm_Pitch_reuse_flag = 0; tdm_Pri_pitch_buf = NULL; - move16(); move16(); + move16(); + move16(); } /*-----------------------------------------------------------------* * ACELP@12k8 / ACELP@16k switching *-----------------------------------------------------------------*/ test(); - IF( NE_16(st_fx->last_L_frame,st_fx->L_frame) && (EQ_16(st_fx->last_core, ACELP_CORE) || EQ_16(st_fx->last_core, AMR_WB_CORE) ) ) + IF( NE_16( st_fx->last_L_frame, st_fx->L_frame ) && ( EQ_16( st_fx->last_core, ACELP_CORE ) || EQ_16( st_fx->last_core, AMR_WB_CORE ) ) ) { /* in case of switching, do not apply BPF */ st_fx->bpf_off = 1; @@ -236,13 +241,13 @@ ivas_error acelp_core_enc_fx( move16(); /* convert old quantized LSP vector */ - IF( EQ_16(st_fx->L_frame,L_FRAME)) + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { st_fx->rate_switching_reset = lsp_convert_poly_fx( st_fx->lsp_old_fx, st_fx->L_frame, 0 ); } ELSE { - st_fx->rate_switching_reset=st_fx->rate_switching_reset_16kHz; + st_fx->rate_switching_reset = st_fx->rate_switching_reset_16kHz; move16(); Copy( st_fx->lsp_old16k_fx, st_fx->lsp_old_fx, M ); } @@ -263,49 +268,48 @@ ivas_error acelp_core_enc_fx( /* Reset LPC mem */ Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M ); - set16_fx( st_fx->mem_MA_fx,0, M ); + set16_fx( st_fx->mem_MA_fx, 0, M ); /* update synthesis filter memories */ - synth_mem_updt2( st_fx->L_frame, st_fx->last_L_frame, hLPDmem->old_exc, hLPDmem->mem_syn_r,hLPDmem->mem_syn2, hLPDmem->mem_syn, ENC ); + synth_mem_updt2( st_fx->L_frame, st_fx->last_L_frame, hLPDmem->old_exc, hLPDmem->mem_syn_r, hLPDmem->mem_syn2, hLPDmem->mem_syn, ENC ); Copy( hLPDmem->old_exc, old_exc_fx, L_EXC_MEM ); Copy( hLPDmem->mem_syn2, hLPDmem->mem_syn1_fx, M ); Copy( hLPDmem->mem_syn2, hLPDmem->mem_syn3, M ); /* update Aw[] coefficients */ - weight_a_subfr_fx( shr(st_fx->L_frame,6), A_fx, Aw_fx, st_fx->gamma, M ); - + weight_a_subfr_fx( shr( st_fx->L_frame, 6 ), A_fx, Aw_fx, st_fx->gamma, M ); } test(); test(); - if(EQ_16(st_fx->last_bwidth,NB)&&NE_16(st_fx->bwidth,NB)&&st_fx->ini_frame!=0) + if ( EQ_16( st_fx->last_bwidth, NB ) && NE_16( st_fx->bwidth, NB ) && st_fx->ini_frame != 0 ) { - st_fx->rate_switching_reset=1; + st_fx->rate_switching_reset = 1; move16(); } /*----------------------------------------------------------------* * Encoding of CNG frames *----------------------------------------------------------------*/ test(); - IF ( EQ_32(st_fx->core_brate,SID_2k40)||EQ_32(st_fx->core_brate,FRAME_NO_DATA)) + IF( EQ_32( st_fx->core_brate, SID_2k40 ) || EQ_32( st_fx->core_brate, FRAME_NO_DATA ) ) { - IF( EQ_16(st_fx->cng_type,LP_CNG)) + IF( EQ_16( st_fx->cng_type, LP_CNG ) ) { /* Run CNG post parameter update */ - cng_params_postupd_fx(hTdCngEnc->ho_circ_ptr, &hTdCngEnc->cng_buf_cnt, hTdCngEnc->cng_exc2_buf, hTdCngEnc->cng_Qexc_buf, - hTdCngEnc->cng_brate_buf, hTdCngEnc->ho_env_circ_fx); + cng_params_postupd_fx( hTdCngEnc->ho_circ_ptr, &hTdCngEnc->cng_buf_cnt, hTdCngEnc->cng_exc2_buf, hTdCngEnc->cng_Qexc_buf, + hTdCngEnc->cng_brate_buf, hTdCngEnc->ho_env_circ_fx ); /* encode CNG parameters */ - CNG_enc_fx( st_fx, Aq_fx, inp_fx, ener_fx, lsp_mid_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step_fx, sub(Q_new,1), q_env, &sid_bw); + CNG_enc_fx( st_fx, Aq_fx, inp_fx, ener_fx, lsp_mid_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step_fx, sub( Q_new, 1 ), q_env, &sid_bw ); /* comfort noise generation */ CNG_exc_fx( st_fx->core_brate, st_fx->L_frame, &hTdCngEnc->Enew_fx, &hTdCngEnc->cng_seed, exc_fx, exc2_fx, &hTdCngEnc->lp_ener_fx, st_fx->last_core_brate, - &hDtxEnc->first_CNG, &hTdCngEnc->cng_ener_seed, bwe_exc_fx, allow_cn_step_fx, &hTdCngEnc->last_allow_cn_step, sub(st_fx->prev_Q_new,1), sub(Q_new,1), hTdCngEnc->num_ho, - q_env, hTdCngEnc->lp_env_fx, hTdCngEnc->old_env_fx, hTdCngEnc->exc_mem_fx, hTdCngEnc->exc_mem1_fx, &sid_bw, &hTdCngEnc->cng_ener_seed1, exc3_fx, st_fx->Opt_AMR_WB, st_fx->element_mode); + &hDtxEnc->first_CNG, &hTdCngEnc->cng_ener_seed, bwe_exc_fx, allow_cn_step_fx, &hTdCngEnc->last_allow_cn_step, sub( st_fx->prev_Q_new, 1 ), sub( Q_new, 1 ), hTdCngEnc->num_ho, + q_env, hTdCngEnc->lp_env_fx, hTdCngEnc->old_env_fx, hTdCngEnc->exc_mem_fx, hTdCngEnc->exc_mem1_fx, &sid_bw, &hTdCngEnc->cng_ener_seed1, exc3_fx, st_fx->Opt_AMR_WB, st_fx->element_mode ); } ELSE { test(); - IF( EQ_32(st_fx->core_brate, SID_2k40) && NE_16(st_fx->element_mode, IVAS_CPE_MDCT) ) + IF( EQ_32( st_fx->core_brate, SID_2k40 ) && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) { FdCng_encodeSID_fx( st_fx->hFdCngEnc, st_fx, st_fx->preemph_fac ); hDtxEnc->last_CNG_L_frame = st_fx->L_frame; @@ -315,24 +319,24 @@ ivas_error acelp_core_enc_fx( generate_comfort_noise_enc_fx( st_fx, Q_new, 1 ); FdCng_exc( st_fx->hFdCngEnc->hFdCngCom, &hDtxEnc->CNG_mode, st_fx->L_frame, st_fx->lsp_old_fx, - hDtxEnc->first_CNG, hDtxEnc->lspCNG_fx, Aq_fx, lsp_new_fx, lsf_new_fx, exc_fx, exc2_fx, bwe_exc_fx ); + hDtxEnc->first_CNG, hDtxEnc->lspCNG_fx, Aq_fx, lsp_new_fx, lsf_new_fx, exc_fx, exc2_fx, bwe_exc_fx ); Copy( exc2_fx, exc3_fx, st_fx->L_frame ); - IF( EQ_32(st_fx->core_brate, SID_2k40)) + IF( EQ_32( st_fx->core_brate, SID_2k40 ) ) { - IF (hTdCngEnc != NULL) + IF( hTdCngEnc != NULL ) { /*IVAS_CODE CNG_att is missing */ - enr = cng_energy_fx(st_fx->element_mode, st_fx->bwidth, hDtxEnc->CNG_mode, /*st_fx->hTdCngEnc->CNG_att*/0, exc_fx, st_fx->L_frame, Q_new); + enr = cng_energy_fx( st_fx->element_mode, st_fx->bwidth, hDtxEnc->CNG_mode, /*st_fx->hTdCngEnc->CNG_att*/ 0, exc_fx, st_fx->L_frame, Q_new ); /* calculate the energy quantization index */ - enr_index = add(enr, 512 /* Q8(2.0) */); /* enr + 2.0 */ - enr_index = extract_l(L_shr(L_mult0(enr_index, STEP_SID_FX), 12 + 8)); /* Q0 (8+12-(8+12)) */ + enr_index = add( enr, 512 /* Q8(2.0) */ ); /* enr + 2.0 */ + enr_index = extract_l( L_shr( L_mult0( enr_index, STEP_SID_FX ), 12 + 8 ) ); /* Q0 (8+12-(8+12)) */ /* limit the energy quantization index */ - enr_index = s_min(enr_index, 127); - enr_index = s_max(enr_index, 0); + enr_index = s_min( enr_index, 127 ); + enr_index = s_max( enr_index, 0 ); hTdCngEnc->old_enr_index = enr_index; move16(); @@ -340,7 +344,7 @@ ivas_error acelp_core_enc_fx( } } /* Reset HO counter in the first SID frame */ - if (hTdCngEnc != NULL) + if ( hTdCngEnc != NULL ) { hTdCngEnc->burst_ho_cnt = 0; move16(); @@ -360,7 +364,7 @@ ivas_error acelp_core_enc_fx( /* update old synthesis buffer - needed for ACELP internal sampling rate switching */ Copy( syn1_fx + st_fx->L_frame - L_SYN_MEM, hLPDmem->mem_syn_r, L_SYN_MEM ); - IF (hBWE_FD != NULL) + IF( hBWE_FD != NULL ) { /* save and delay synthesis to be used by SWB BWE */ save_old_syn_fx( st_fx->L_frame, syn1_fx, old_syn_12k8_16k_fx, hBWE_FD->old_syn_12k8_16k_fx, st_fx->preemph_fac, &hBWE_FD->mem_deemph_old_syn_fx ); @@ -368,9 +372,8 @@ ivas_error acelp_core_enc_fx( /* Update MODE2 core switching memory */ tmp16 = hLPDmem->syn[M]; move16(); - E_UTIL_deemph2( sub(Q_new,1), syn1_fx, st_fx->preemph_fac, st_fx->L_frame, &tmp16 ); - Copy( syn1_fx+st_fx->L_frame-M-1, hLPDmem->syn, M+1 ); - + E_UTIL_deemph2( sub( Q_new, 1 ), syn1_fx, st_fx->preemph_fac, st_fx->L_frame, &tmp16 ); + Copy( syn1_fx + st_fx->L_frame - M - 1, hLPDmem->syn, M + 1 ); } /*----------------------------------------------------------------* @@ -383,17 +386,19 @@ ivas_error acelp_core_enc_fx( * Configure ACELP bit allocation *-----------------------------------------------------------------*/ - nb_bits = 0; + nb_bits = 0; st_fx->acelp_cfg.FEC_mode = 0; uc_two_stage_flag = 0; - move16();move16();move16(); + move16(); + move16(); + move16(); test(); - IF (!nelp_mode && !ppp_mode) + IF( !nelp_mode && !ppp_mode ) { - config_acelp1(ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, - st_fx->L_frame, st_fx->GSC_noisy_speech, &(st_fx->acelp_cfg), hBstr->nb_bits_tot_fx, st_fx->coder_type, - tc_subfr_fx, 0, &nb_bits, unbits_fx, st_fx->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st_fx->idchan, st_fx->active_fr_cnt_fx, - tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode); + config_acelp1( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, + st_fx->L_frame, st_fx->GSC_noisy_speech, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot_fx, st_fx->coder_type, + tc_subfr_fx, 0, &nb_bits, unbits_fx, st_fx->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st_fx->idchan, st_fx->active_fr_cnt_fx, + tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode ); } /*-----------------------------------------------------------------* @@ -401,11 +406,11 @@ ivas_error acelp_core_enc_fx( *-----------------------------------------------------------------*/ test(); - IF ( EQ_32(st_fx->last_core_brate,FRAME_NO_DATA)||EQ_32(st_fx->last_core_brate,SID_2k40)) + IF( EQ_32( st_fx->last_core_brate, FRAME_NO_DATA ) || EQ_32( st_fx->last_core_brate, SID_2k40 ) ) { - Copy(hDtxEnc->lspCNG_fx, st_fx->lsp_old_fx, M ); + Copy( hDtxEnc->lspCNG_fx, st_fx->lsp_old_fx, M ); - lsp2lsf_fx(hDtxEnc->lspCNG_fx, st_fx->lsf_old_fx, M, int_fs_fx ); + lsp2lsf_fx( hDtxEnc->lspCNG_fx, st_fx->lsf_old_fx, M, int_fs_fx ); } /*-----------------------------------------------------------------* @@ -413,7 +418,7 @@ ivas_error acelp_core_enc_fx( *-----------------------------------------------------------------*/ IF( !st_fx->use_acelp_preq ) { - st_fx->mem_deemp_preQ_fx = 0; + st_fx->mem_deemp_preQ_fx = 0; move16(); st_fx->mem_preemp_preQ_fx = 0; move16(); @@ -431,80 +436,80 @@ ivas_error acelp_core_enc_fx( /* SC-VBR - back-up memories for LSF quantizer and synthesis filter */ lsf_syn_mem_backup_fx( st_fx, &tilt_code_bck_fx, &gc_threshold_bck_fx, clip_var_bck_fx, &next_force_sf_bck_fx, - lsp_new_fx, lsf_new_fx, lsp_mid_fx, &clip_var_fx, mem_AR_fx, mem_MA_fx, lsp_new_bck_fx, lsf_new_bck_fx, - lsp_mid_bck_fx, &mCb1_fx, Bin_E_fx, Bin_E_old_fx, mem_syn_bck_fx, &mem_w0_bck_fx, &streaklimit_fx, &pstreaklen_fx); + lsp_new_fx, lsf_new_fx, lsp_mid_fx, &clip_var_fx, mem_AR_fx, mem_MA_fx, lsp_new_bck_fx, lsf_new_bck_fx, + lsp_mid_bck_fx, &mCb1_fx, Bin_E_fx, Bin_E_old_fx, mem_syn_bck_fx, &mem_w0_bck_fx, &streaklimit_fx, &pstreaklen_fx ); - if (!tdm_lp_reuse_flag) + if ( !tdm_lp_reuse_flag ) { #ifdef LSF_RE_USE_SECONDARY_CHANNEL - lsf_enc_fx(st_fx, lsf_new_fx, lsp_new_fx, lsp_mid_fx, Aq_fx, st_fx->Nb_ACELP_frames, tdm_low_rate_mode, st_fx->GSC_IVAS_mode, tdm_lsfQ_PCh, Q_new); + lsf_enc_fx( st_fx, lsf_new_fx, lsp_new_fx, lsp_mid_fx, Aq_fx, st_fx->Nb_ACELP_frames, tdm_low_rate_mode, st_fx->GSC_IVAS_mode, tdm_lsfQ_PCh, Q_new ); #else - lsf_enc_fx(st_fx, lsf_new_fx, lsp_new_fx, lsp_mid_fx, Aq_fx, st_fx->Nb_ACELP_frames, tdm_low_rate_mode, st_fx->GSC_IVAS_mode, Q_new); + lsf_enc_fx( st_fx, lsf_new_fx, lsp_new_fx, lsp_mid_fx, Aq_fx, st_fx->Nb_ACELP_frames, tdm_low_rate_mode, st_fx->GSC_IVAS_mode, Q_new ); #endif } #ifdef ADD_LRTD else { - const float* pt_interp_2; + const float *pt_interp_2; #ifdef LSF_RE_USE_SECONDARY_CHANNEL - if (st->active_cnt != 1) + if ( st->active_cnt != 1 ) { int16_t beta_index; float lsf_wgts[M]; /* intra_frame prediction for the LSFs */ - lsp2lsf(lsp_new, lsf_new, M, 12800); + lsp2lsf( lsp_new, lsf_new, M, 12800 ); - Unified_weighting(&st->Bin_E[L_FFT / 2], lsf_new, lsf_wgts, st->bwidth == NB, st->coder_type == UNVOICED, st->sr_core, M); + Unified_weighting( &st->Bin_E[L_FFT / 2], lsf_new, lsf_wgts, st->bwidth == NB, st->coder_type == UNVOICED, st->sr_core, M ); - tdm_SCh_lsf_reuse(ENC, st->element_brate, lsf_new, lsp_new, tdm_lsfQ_PCh, lsf_wgts, &beta_index); + tdm_SCh_lsf_reuse( ENC, st->element_brate, lsf_new, lsp_new, tdm_lsfQ_PCh, lsf_wgts, &beta_index ); - push_indice(hBstr, IND_IC_LSF_PRED, beta_index, TDM_IC_LSF_PRED_BITS); + push_indice( hBstr, IND_IC_LSF_PRED, beta_index, TDM_IC_LSF_PRED_BITS ); } #endif pt_interp_2 = interpol_frac_12k8; - if (tdm_low_rate_mode == 1 && st->coder_type > UNVOICED) + if ( tdm_low_rate_mode == 1 && st->coder_type > UNVOICED ) { pt_interp_2 = interpol_frac2; } #ifndef LSF_RE_USE_SECONDARY_CHANNEL - if (st->active_cnt == 1) + if ( st->active_cnt == 1 ) { - mvr2r(lsp_new, st->lsp_old, M); - lsp2lsf(lsp_new, st->lsf_old, M, st->sr_core); - lsp2lsf(lsp_new, lsf_new, M, st->sr_core); + mvr2r( lsp_new, st->lsp_old, M ); + lsp2lsf( lsp_new, st->lsf_old, M, st->sr_core ); + lsp2lsf( lsp_new, lsf_new, M, st->sr_core ); } #endif /* LSP interpolation and conversion of LSPs to A(z) */ - int_lsp(st->L_frame, st->lsp_old, lsp_new, Aq, M, pt_interp_2, 0); + int_lsp( st->L_frame, st->lsp_old, lsp_new, Aq, M, pt_interp_2, 0 ); /* Check LSF stability (distance between old LSFs and current LSFs) */ - st->stab_fac = lsf_stab(lsf_new, st->lsf_old, 0, st->L_frame); + st->stab_fac = lsf_stab( lsf_new, st->lsf_old, 0, st->L_frame ); } - if (st->last_core == HQ_CORE && st->element_mode > EVS_MONO) + if ( st->last_core == HQ_CORE && st->element_mode > EVS_MONO ) { /* Prepare ACB memory from last HQ frame */ tmpF = hLPDmem->old_exc[0]; - preemph(hLPDmem->old_exc, st->preemph_fac, st->L_frame, &tmpF); - mvr2r(hLPDmem->old_exc + st->L_frame - M, hLPDmem->mem_syn, M); - residu(Aq, M, hLPDmem->old_exc, old_exc, st->L_frame); + preemph( hLPDmem->old_exc, st->preemph_fac, st->L_frame, &tmpF ); + mvr2r( hLPDmem->old_exc + st->L_frame - M, hLPDmem->mem_syn, M ); + residu( Aq, M, hLPDmem->old_exc, old_exc, st->L_frame ); } - if (st->last_core != ACELP_CORE && st->element_mode > EVS_MONO) + if ( st->last_core != ACELP_CORE && st->element_mode > EVS_MONO ) { /* Prepare ACB memory of old_bwe_exc */ #ifdef CR_FIX_639_HQ_ACELP_TRANSITION - if (st->L_frame == L_FRAME) + if ( st->L_frame == L_FRAME ) { - lerp(old_exc, old_bwe_exc, L_EXC_MEM_DEC * HIBND_ACB_L_FAC, L_EXC_MEM_DEC); + lerp( old_exc, old_bwe_exc, L_EXC_MEM_DEC * HIBND_ACB_L_FAC, L_EXC_MEM_DEC ); } else { - lerp(old_exc, old_bwe_exc, L_EXC_MEM_DEC * 2, L_EXC_MEM_DEC); + lerp( old_exc, old_bwe_exc, L_EXC_MEM_DEC * 2, L_EXC_MEM_DEC ); } #else - lerp(old_exc, old_bwe_exc, L_EXC_MEM_DEC * HIBND_ACB_L_FAC, L_EXC_MEM_DEC); + lerp( old_exc, old_bwe_exc, L_EXC_MEM_DEC * HIBND_ACB_L_FAC, L_EXC_MEM_DEC ); #endif } #endif @@ -513,28 +518,28 @@ ivas_error acelp_core_enc_fx( /*---------------------------------------------------------------* * Calculation of LP residual (filtering through A[z] filter) *---------------------------------------------------------------*/ - calc_residu_fx(st_fx, inp_fx, res_fx, Aq_fx); - calculate_hangover_attenuation_gain_fx(st_fx, &att, vad_hover_flag_fx); - v_multc_att(res_fx, att, res_fx, st_fx->L_frame); + calc_residu_fx( st_fx, inp_fx, res_fx, Aq_fx ); + calculate_hangover_attenuation_gain_fx( st_fx, &att, vad_hover_flag_fx ); + v_multc_att( res_fx, att, res_fx, st_fx->L_frame ); /*-----------------------------------------------------------------* * Determine TC subframe classification *-----------------------------------------------------------------*/ - IF (EQ_16(st_fx->coder_type, TRANSITION ) ) + IF( EQ_16( st_fx->coder_type, TRANSITION ) ) { - tc_classif_enc_fx(Q_new, st_fx->L_frame, &tc_subfr_fx, &position, attack_flag, st_fx->pitch_fx[0], res_fx); + tc_classif_enc_fx( Q_new, st_fx->L_frame, &tc_subfr_fx, &position, attack_flag, st_fx->pitch_fx[0], res_fx ); - config_acelp1(ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, st_fx->L_frame, - -1, &(st_fx->acelp_cfg), hBstr->nb_bits_tot_fx, st_fx->coder_type, tc_subfr_fx, 1, NULL, unbits_fx, st_fx->element_mode, &uc_two_stage_flag, - tdm_lp_reuse_flag, tdm_low_rate_mode, st_fx->idchan, st_fx->active_fr_cnt_fx, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode); + config_acelp1( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, st_fx->L_frame, + -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot_fx, st_fx->coder_type, tc_subfr_fx, 1, NULL, unbits_fx, st_fx->element_mode, &uc_two_stage_flag, + tdm_lp_reuse_flag, tdm_low_rate_mode, st_fx->idchan, st_fx->active_fr_cnt_fx, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode ); } /*---------------------------------------------------------------* * Calculation of prediction for scaled innovation energy * (for memory-less gain quantizer) *---------------------------------------------------------------*/ - IF(nb_bits > 0) + IF( nb_bits > 0 ) { Es_pred_enc_fx( &Es_pred_fx, &indice, st_fx->L_frame, res_fx, st_fx->voicing_fx, nb_bits, 0, Q_new ); push_indice_fx( st_fx->hBstr, IND_ES_PRED, indice, nb_bits ); @@ -547,83 +552,83 @@ ivas_error acelp_core_enc_fx( test(); test(); #ifdef ADD_LRTD - if (tdm_low_rate_mode) /* tdm stereo low rate mode */ + if ( tdm_low_rate_mode ) /* tdm stereo low rate mode */ { - if (st->coder_type <= UNVOICED) + if ( st->coder_type <= UNVOICED ) { - tdm_low_rate_enc(st, Aq, res, syn, exc, pitch_buf, voice_factors, bwe_exc, 0 /*attack_flag*/, lsf_new, &tmp_noise); + tdm_low_rate_enc( st, Aq, res, syn, exc, pitch_buf, voice_factors, bwe_exc, 0 /*attack_flag*/, lsf_new, &tmp_noise ); } else /* GENERIC */ { - encod_gen_2sbfr(st, inp, Aw, Aq, res, syn, exc, exc2, pitch_buf, voice_factors, bwe_exc, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf); + encod_gen_2sbfr( st, inp, Aw, Aq, res, syn, exc, exc2, pitch_buf, voice_factors, bwe_exc, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); } } else #endif - IF(hSC_VBR->nelp_mode ) - { - /* SC-VBR - NELP frames */ - encod_nelp_fx( st_fx, inp_fx, Aw_fx, Aq_fx, res_fx, syn_fx, &tmp_noise_fx, exc_fx, exc2_fx, pitch_buf_fx, - voice_factors_fx, bwe_exc_fx, Q_new, shift); - } - ELSE IF( EQ_16(coder_type,UNVOICED)) + IF( hSC_VBR->nelp_mode ) + { + /* SC-VBR - NELP frames */ + encod_nelp_fx( st_fx, inp_fx, Aw_fx, Aq_fx, res_fx, syn_fx, &tmp_noise_fx, exc_fx, exc2_fx, pitch_buf_fx, + voice_factors_fx, bwe_exc_fx, Q_new, shift ); + } + ELSE IF( EQ_16( coder_type, UNVOICED ) ) { /* UNVOICED frames (Gauss. excitation) */ - encod_unvoiced_fx( st_fx, inp_fx, Aw_fx, Aq_fx, Es_pred_fx, uc_two_stage_flag, res_fx, syn_fx, &tmp_noise_fx, exc_fx, - pitch_buf_fx, voice_factors_fx, bwe_exc_fx,Q_new,shift ); + encod_unvoiced_fx( st_fx, inp_fx, Aw_fx, Aq_fx, Es_pred_fx, uc_two_stage_flag, res_fx, syn_fx, &tmp_noise_fx, exc_fx, + pitch_buf_fx, voice_factors_fx, bwe_exc_fx, Q_new, shift ); } - ELSE IF( EQ_16(coder_type,TRANSITION)) + ELSE IF( EQ_16( coder_type, TRANSITION ) ) { tc_subfr_fx = encod_tran_fx( st_fx, inp_fx, Aw_fx, Aq_fx, Es_pred_fx, res_fx, syn_fx, - exc_fx, exc2_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, tc_subfr_fx, position, unbits_fx, shift, Q_new ); + exc_fx, exc2_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, tc_subfr_fx, position, unbits_fx, shift, Q_new ); move16(); } - ELSE IF(hSC_VBR->ppp_mode ) + ELSE IF( hSC_VBR->ppp_mode ) { - IF ((error = encod_ppp_fx( st_fx, inp_fx, Aw_fx, Aq_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, Q_new, shift)) != IVAS_ERR_OK) + IF( ( error = encod_ppp_fx( st_fx, inp_fx, Aw_fx, Aq_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, Q_new, shift ) ) != IVAS_ERR_OK ) { return error; } - IF(hSC_VBR->bump_up ) /* PPP failed, bump up */ + IF( hSC_VBR->bump_up ) /* PPP failed, bump up */ { /* restore memories of LSF quantizer and synthesis filter */ lsf_syn_mem_restore_fx( st_fx, tilt_code_bck_fx, gc_threshold_bck_fx, clip_var_bck_fx, next_force_sf_bck_fx, - lsp_new_fx, lsf_new_fx, lsp_mid_fx, clip_var_fx, mem_AR_fx, mem_MA_fx, lsp_new_bck_fx, lsf_new_bck_fx, - lsp_mid_bck_fx, mCb1_fx, Bin_E_fx,Bin_E_old_fx,mem_syn_bck_fx, mem_w0_bck_fx, streaklimit_fx, pstreaklen_fx ); + lsp_new_fx, lsf_new_fx, lsp_mid_fx, clip_var_fx, mem_AR_fx, mem_MA_fx, lsp_new_bck_fx, lsf_new_bck_fx, + lsp_mid_bck_fx, mCb1_fx, Bin_E_fx, Bin_E_old_fx, mem_syn_bck_fx, mem_w0_bck_fx, streaklimit_fx, pstreaklen_fx ); /* Configure ACELP bit allocation */ - config_acelp1(ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, st_fx->L_frame, - -1, &(st_fx->acelp_cfg), hBstr->nb_bits_tot_fx, st_fx->coder_type, tc_subfr_fx, 0, &nb_bits, unbits_fx, 0, &uc_two_stage_flag, 0, 0, - st_fx->idchan, st_fx->active_fr_cnt_fx, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode); + config_acelp1( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, st_fx->L_frame, + -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot_fx, st_fx->coder_type, tc_subfr_fx, 0, &nb_bits, unbits_fx, 0, &uc_two_stage_flag, 0, 0, + st_fx->idchan, st_fx->active_fr_cnt_fx, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode ); /* redo LSF quantization */ #ifdef LSF_RE_USE_SECONDARY_CHANNEL - lsf_enc_fx(st_fx, lsf_new_fx, lsp_new_fx, lsp_mid_fx, Aq_fx, st_fx->Nb_ACELP_frames, tdm_low_rate_mode, st_fx->GSC_IVAS_mode, tdm_lsfQ_PCh, Q_new); + lsf_enc_fx( st_fx, lsf_new_fx, lsp_new_fx, lsp_mid_fx, Aq_fx, st_fx->Nb_ACELP_frames, tdm_low_rate_mode, st_fx->GSC_IVAS_mode, tdm_lsfQ_PCh, Q_new ); #else lsf_enc_fx( st_fx, lsf_new_fx, lsp_new_fx, lsp_mid_fx, Aq_fx, st_fx->Nb_ACELP_frames, tdm_low_rate_mode, st_fx->GSC_IVAS_mode, Q_new ); #endif /* recalculation of LP residual (filtering through A[z] filter) */ - calc_residu_fx( st_fx, inp_fx, res_fx, Aq_fx); + calc_residu_fx( st_fx, inp_fx, res_fx, Aq_fx ); hTdCngEnc->burst_ho_cnt = 0; move16(); /* VOICED frames in SC-VBR when bumped up*/ encod_gen_voic_fx( st_fx, inp_fx, Aw_fx, Aq_fx, Es_pred_fx, res_fx, syn_fx, - exc_fx, exc2_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, unbits_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf, shift, Q_new ); + exc_fx, exc2_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, unbits_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf, shift, Q_new ); } } - ELSE IF( EQ_16(coder_type,AUDIO)||(EQ_16(coder_type,INACTIVE)&&LE_32(st_fx->core_brate,ACELP_24k40))) + ELSE IF( EQ_16( coder_type, AUDIO ) || ( EQ_16( coder_type, INACTIVE ) && LE_32( st_fx->core_brate, ACELP_24k40 ) ) ) { /* AUDIO and INACTIVE frames (coded by GSC technology) */ encod_audio_fx( st_fx, inp_fx, Aw_fx, Aq_fx, res_fx, syn_fx, exc_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, - attack_flag, lsf_new_fx, &tmp_noise_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf, Q_new , shift); + attack_flag, lsf_new_fx, &tmp_noise_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf, Q_new, shift ); } ELSE { /* GENERIC, VOICED and INACTIVE frames (coded by AVQ technology) */ encod_gen_voic_fx( st_fx, inp_fx, Aw_fx, Aq_fx, Es_pred_fx, res_fx, syn_fx, - exc_fx, exc2_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, unbits_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf, shift, Q_new ); + exc_fx, exc2_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, unbits_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf, shift, Q_new ); } /* update st->mem_syn1 for ACELP core switching */ @@ -633,30 +638,30 @@ ivas_error acelp_core_enc_fx( Copy( syn_fx + st_fx->L_frame - L_SYN_MEM, hLPDmem->mem_syn_r, L_SYN_MEM ); /* save and delay synthesis to be used by SWB BWE */ - IF (hBWE_FD != NULL) + IF( hBWE_FD != NULL ) { - save_old_syn_fx(st_fx->L_frame, syn_fx, old_syn_12k8_16k_fx, hBWE_FD->old_syn_12k8_16k_fx, st_fx->preemph_fac, &hBWE_FD->mem_deemph_old_syn_fx); + save_old_syn_fx( st_fx->L_frame, syn_fx, old_syn_12k8_16k_fx, hBWE_FD->old_syn_12k8_16k_fx, st_fx->preemph_fac, &hBWE_FD->mem_deemph_old_syn_fx ); } /*Update MODE2 core switching memory*/ Copy( syn_fx, syn1_fx, st_fx->L_frame ); - E_UTIL_deemph2( sub(Q_new,1), syn1_fx, st_fx->preemph_fac, st_fx->L_frame, &hLPDmem->syn[M] ); - Copy( syn1_fx+st_fx->L_frame-M-1, hLPDmem->syn, M+1 ); - IF (GT_16(st_fx->element_mode, EVS_MONO) && st_fx->hTcxEnc != NULL) + E_UTIL_deemph2( sub( Q_new, 1 ), syn1_fx, st_fx->preemph_fac, st_fx->L_frame, &hLPDmem->syn[M] ); + Copy( syn1_fx + st_fx->L_frame - M - 1, hLPDmem->syn, M + 1 ); + IF( GT_16( st_fx->element_mode, EVS_MONO ) && st_fx->hTcxEnc != NULL ) { - Copy(syn1_fx + st_fx->L_frame / 2, st_fx->hTcxEnc->Txnq, st_fx->L_frame / 2); + Copy( syn1_fx + st_fx->L_frame / 2, st_fx->hTcxEnc->Txnq, st_fx->L_frame / 2 ); } /*--------------------------------------------------------------------------------------* * Modify the excitation signal when the noise is stationary *--------------------------------------------------------------------------------------*/ - IF (!(EQ_16(st_fx->idchan, 1) && EQ_16(st_fx->element_mode, IVAS_CPE_TD)) && NE_16(nelp_mode, 1) && !(EQ_16(st_fx->element_mode, IVAS_SCE) && tdm_low_rate_mode)) + IF( !( EQ_16( st_fx->idchan, 1 ) && EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) && NE_16( nelp_mode, 1 ) && !( EQ_16( st_fx->element_mode, IVAS_SCE ) && tdm_low_rate_mode ) ) { - L_epsP[0] = L_Comp(epsP_h_fx[2],epsP_l_fx[2]); + L_epsP[0] = L_Comp( epsP_h_fx[2], epsP_l_fx[2] ); move32(); - L_epsP[1] = L_Comp(epsP_h_fx[M],epsP_l_fx[M]); + L_epsP[1] = L_Comp( epsP_h_fx[M], epsP_l_fx[M] ); move32(); - Copy(exc_fx, exc2_fx, st_fx->L_frame); + Copy( exc_fx, exc2_fx, st_fx->L_frame ); stat_noise_uv_enc_fx( st_fx, L_epsP, lsp_new_fx, lsp_mid_fx, Aq_fx, exc2_fx, uc_two_stage_flag, Q_new ); } @@ -664,22 +669,22 @@ ivas_error acelp_core_enc_fx( * Encode supplementary information for Frame Error Concealment *-----------------------------------------------------------------*/ - FEC_encode_fx(hBstr, st_fx->acelp_cfg, syn_fx, coder_type, st_fx->clas, pitch_buf_fx, res_fx, &st_fx->Last_pulse_pos, - st_fx->L_frame, st_fx->total_brate, Q_new, shift ); + FEC_encode_fx( hBstr, st_fx->acelp_cfg, syn_fx, coder_type, st_fx->clas, pitch_buf_fx, res_fx, &st_fx->Last_pulse_pos, + st_fx->L_frame, st_fx->total_brate, Q_new, shift ); - IF (hBWE_TD != NULL) + IF( hBWE_TD != NULL ) { - IF(EQ_16(st_fx->L_frame, L_FRAME)) + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { - Copy(Aq_fx + 2 * (M + 1), hBWE_TD->cur_sub_Aq_fx, (M + 1)); + Copy( Aq_fx + 2 * ( M + 1 ), hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) ); } ELSE { - Copy(Aq_fx + 3 * (M + 1), hBWE_TD->cur_sub_Aq_fx, (M + 1)); + Copy( Aq_fx + 3 * ( M + 1 ), hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) ); } } - } /* end of active inp coding */ + } /* end of active inp coding */ /*-----------------------------------------------------------------* * Write ACELP unused bits @@ -687,16 +692,16 @@ ivas_error acelp_core_enc_fx( test(); test(); - IF ( NE_32(st_fx->core_brate,SID_2k40)&&NE_32(st_fx->core_brate,FRAME_NO_DATA)&&NE_32(st_fx->core_brate,PPP_NELP_2k80)) + IF( NE_32( st_fx->core_brate, SID_2k40 ) && NE_32( st_fx->core_brate, FRAME_NO_DATA ) && NE_32( st_fx->core_brate, PPP_NELP_2k80 ) ) { /* reserved bits */ nBits = st_fx->acelp_cfg.ubits; WHILE( nBits > 0 ) { - i = s_min(nBits, 16); + i = s_min( nBits, 16 ); push_indice_fx( st_fx->hBstr, IND_UNUSED, 0, i ); - nBits = sub(nBits,i); + nBits = sub( nBits, i ); } } @@ -704,69 +709,73 @@ ivas_error acelp_core_enc_fx( /*-----------------------------------------------------------------* * Apply non linearity in case of SWB TBE *-----------------------------------------------------------------*/ - IF(hBWE_TD != NULL) + IF( hBWE_TD != NULL ) { - test(); test(); - test(); test(); - test(); test(); test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); - IF((EQ_16(st_fx->last_Opt_SC_VBR, 1) && st_fx->Opt_SC_VBR == 0) || ((EQ_16(st_fx->extl, SWB_TBE) || EQ_16(st_fx->extl, WB_TBE) || EQ_16(st_fx->extl, FB_TBE)) && NE_16(st_fx->last_extl, SWB_TBE) && NE_16(st_fx->last_extl, WB_TBE) && NE_16(st_fx->last_extl, FB_TBE))) + IF( ( EQ_16( st_fx->last_Opt_SC_VBR, 1 ) && st_fx->Opt_SC_VBR == 0 ) || ( ( EQ_16( st_fx->extl, SWB_TBE ) || EQ_16( st_fx->extl, WB_TBE ) || EQ_16( st_fx->extl, FB_TBE ) ) && NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, WB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) ) ) { - hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l(0); - set16_fx(hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET); + hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 ); + set16_fx( hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); } - IF(!st_fx->Opt_SC_VBR) + IF( !st_fx->Opt_SC_VBR ) { /* Apply a non linearity to the SHB excitation */ - non_linearity_fx(bwe_exc_fx, bwe_exc_extended_fx, L_FRAME32k, &hBWE_TD->bwe_non_lin_prev_scale_fx, Q_new, coder_type, voice_factors_fx, st_fx->L_frame); + non_linearity_fx( bwe_exc_fx, bwe_exc_extended_fx, L_FRAME32k, &hBWE_TD->bwe_non_lin_prev_scale_fx, Q_new, coder_type, voice_factors_fx, st_fx->L_frame ); } test(); - if (EQ_32(st_fx->core_brate, SID_2k40) || EQ_32(st_fx->core_brate, FRAME_NO_DATA)) + if ( EQ_32( st_fx->core_brate, SID_2k40 ) || EQ_32( st_fx->core_brate, FRAME_NO_DATA ) ) { - hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l(0); + hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 ); } } /*-----------------------------------------------------------------* * Updates *-----------------------------------------------------------------*/ - updt_enc_fx( st_fx, old_exc_fx, pitch_buf_fx, Es_pred_fx,Aq_fx, lsf_new_fx, lsp_new_fx, old_bwe_exc_fx ); + updt_enc_fx( st_fx, old_exc_fx, pitch_buf_fx, Es_pred_fx, Aq_fx, lsf_new_fx, lsp_new_fx, old_bwe_exc_fx ); test(); - IF(hTdCngEnc != NULL && (st_fx->Opt_DTX_ON != 0 ) && (GT_32(st_fx->core_brate,SID_2k40))) + IF( hTdCngEnc != NULL && ( st_fx->Opt_DTX_ON != 0 ) && ( GT_32( st_fx->core_brate, SID_2k40 ) ) ) { /* update CNG parameters in active frames */ cng_params_upd_fx( lsp_new_fx, exc_fx, st_fx->L_frame, &hTdCngEnc->ho_circ_ptr, hTdCngEnc->ho_ener_circ_fx, &hTdCngEnc->ho_circ_size, hTdCngEnc->ho_lsp_circ_fx, Q_new, ENC, NULL, &hTdCngEnc->cng_buf_cnt, - hTdCngEnc->cng_exc2_buf, hTdCngEnc->cng_Qexc_buf, hTdCngEnc->cng_brate_buf, hDtxEnc->last_active_brate ); + hTdCngEnc->cng_exc2_buf, hTdCngEnc->cng_Qexc_buf, hTdCngEnc->cng_brate_buf, hDtxEnc->last_active_brate ); - IF( EQ_16(st_fx->L_frame,L_FRAME)) + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { /* store LSPs@16k, potentially to be used in CNG@16k */ - Copy( st_fx->lsp_old16k_fx, &(hTdCngEnc->ho_lsp_circ2_fx[(hTdCngEnc->ho_circ_ptr)*M]), M ); + Copy( st_fx->lsp_old16k_fx, &( hTdCngEnc->ho_lsp_circ2_fx[( hTdCngEnc->ho_circ_ptr ) * M] ), M ); } /* Set 16k LSP flag for CNG buffer */ hTdCngEnc->ho_16k_lsp[hTdCngEnc->ho_circ_ptr] = 0; move16(); - if(NE_16(st_fx->L_frame, L_FRAME)) + if ( NE_16( st_fx->L_frame, L_FRAME ) ) { hTdCngEnc->ho_16k_lsp[hTdCngEnc->ho_circ_ptr] = 1; move16(); } /* efficient DTX hangover control */ - IF ( GT_16(hTdCngEnc->burst_ho_cnt,1)) + IF( GT_16( hTdCngEnc->burst_ho_cnt, 1 ) ) { dtx_hangover_control_fx( st_fx, lsp_new_fx ); } } /* SC-VBR update of average data rate */ - IF ( EQ_16(st_fx->vad_flag,1) && (hSC_VBR != NULL) ) + IF( EQ_16( st_fx->vad_flag, 1 ) && ( hSC_VBR != NULL ) ) { - update_average_rate_fx(hSC_VBR, st_fx->core_brate); + update_average_rate_fx( hSC_VBR, st_fx->core_brate ); } return error; diff --git a/lib_enc/acelp_core_switch_enc_fx.c b/lib_enc/acelp_core_switch_enc_fx.c index 178f90d39..e71900fc2 100644 --- a/lib_enc/acelp_core_switch_enc_fx.c +++ b/lib_enc/acelp_core_switch_enc_fx.c @@ -8,22 +8,29 @@ #include "rom_com_fx.h" //#include "prot_fx.h" #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ -#include "basop_util.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ +#include "basop_util.h" /* Function prototypes */ /*---------------------------------------------------------------------* - * Local function prototypes - *---------------------------------------------------------------------*/ + * Local function prototypes + *---------------------------------------------------------------------*/ static void encod_gen_voic_core_switch_fx( Encoder_State *st_fx, - const Word16 L_frame_fx, const Word16 inp_fx[], const Word16 Aq_fx[], const Word16 A_fx[], const Word16 T_op[], - Word16 *exc_fx, const Word32 core_bitrate_fx, Word16 shift, Word16 Q_new ); + const Word16 L_frame_fx, + const Word16 inp_fx[], + const Word16 Aq_fx[], + const Word16 A_fx[], + const Word16 T_op[], + Word16 *exc_fx, + const Word32 core_bitrate_fx, + Word16 shift, + Word16 Q_new ); -static void bwe_switch_enc_fx(Encoder_State *st_fx, const Word16 *new_speech ); +static void bwe_switch_enc_fx( Encoder_State *st_fx, const Word16 *new_speech ); -static Word16 dotprod_satcont(const Word16 *x, const Word16 *y, Word16 qx, Word16 qy, Word16 *qo, Word16 len, Word16 delta); +static Word16 dotprod_satcont( const Word16 *x, const Word16 *y, Word16 qx, Word16 qy, Word16 *qo, Word16 len, Word16 delta ); /*-------------------------------------------------------------------* * acelp_core_switch_enc_fx() @@ -32,19 +39,18 @@ static Word16 dotprod_satcont(const Word16 *x, const Word16 *y, Word16 qx, Word1 *--------------------------------------------------------------------*/ void acelp_core_switch_enc_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 inp12k8[], /* i : input signal @12.8 kHz Q0 */ - const Word16 inp16k[], /* i : input signal @16 kHz Q0 */ - const Word16 A[NB_SUBFR16k*(M+1)], /* i : A(z) unquantized for the 4 subframes Q12*/ + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word16 inp12k8[], /* i : input signal @12.8 kHz Q0 */ + const Word16 inp16k[], /* i : input signal @16 kHz Q0 */ + const Word16 A[NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes Q12*/ Word16 shift, - Word16 Q_new -) + Word16 Q_new ) { Word16 i, j, T_op[2]; - Word16 old_exc[L_EXC], *exc; /* excitation signal buffer Qexc */ + Word16 old_exc[L_EXC], *exc; /* excitation signal buffer Qexc */ const Word16 *inp; - Word32 cbrate; - Word16 Aq[2*(M+1)]; + Word32 cbrate; + Word16 Aq[2 * ( M + 1 )]; LPD_state_HANDLE hLPDmem; /* ACELP LPDmem memories */ BSTR_ENC_HANDLE hBstr = st_fx->hBstr; @@ -52,11 +58,11 @@ void acelp_core_switch_enc_fx( /* initializations */ exc = &old_exc[L_EXC_MEM]; - move16(); /* pointer to excitation signal in the current frame */ - Copy( hLPDmem->old_exc, old_exc, L_EXC_MEM ); /*now old_exc has the same scaling as st_fx->old_exc; need to change later? */ + move16(); /* pointer to excitation signal in the current frame */ + Copy( hLPDmem->old_exc, old_exc, L_EXC_MEM ); /*now old_exc has the same scaling as st_fx->old_exc; need to change later? */ - Copy( st_fx->old_Aq_12_8_fx, Aq, M+1 ); - Copy( st_fx->old_Aq_12_8_fx, Aq + (M+1), M+1 ); + Copy( st_fx->old_Aq_12_8_fx, Aq, M + 1 ); + Copy( st_fx->old_Aq_12_8_fx, Aq + ( M + 1 ), M + 1 ); T_op[0] = st_fx->pitch_fx[0]; move16(); T_op[1] = st_fx->pitch_fx[1]; @@ -66,30 +72,30 @@ void acelp_core_switch_enc_fx( * set switching frame bitrate *----------------------------------------------------------------*/ - IF( EQ_16(st_fx->last_L_frame, L_FRAME)) /* ACELP@12k8 core */ + IF( EQ_16( st_fx->last_L_frame, L_FRAME ) ) /* ACELP@12k8 core */ { inp = inp12k8; - IF( GT_32(st_fx->core_brate, ACELP_24k40 )) + IF( GT_32( st_fx->core_brate, ACELP_24k40 ) ) { - cbrate = L_add(ACELP_24k40, 0); + cbrate = L_add( ACELP_24k40, 0 ); } ELSE { - cbrate = L_add(st_fx->core_brate, 0); + cbrate = L_add( st_fx->core_brate, 0 ); } } ELSE /* ACELP@16k core */ { inp = inp16k; - IF( LE_32(st_fx->core_brate, ACELP_8k00)) + IF( LE_32( st_fx->core_brate, ACELP_8k00 ) ) { - cbrate = L_add(ACELP_8k00, 0); + cbrate = L_add( ACELP_8k00, 0 ); } - ELSE IF (LE_32(st_fx->core_brate, ACELP_14k80)) + ELSE IF( LE_32( st_fx->core_brate, ACELP_14k80 ) ) { - cbrate = L_add(ACELP_14k80, 0); + cbrate = L_add( ACELP_14k80, 0 ); } ELSE { @@ -97,42 +103,43 @@ void acelp_core_switch_enc_fx( } } #ifdef FIX_I4_OL_PITCH - PMTE() - IF (EQ_16(st_fx->last_codec_mode, MODE1)) + PMTE() + IF( EQ_16( st_fx->last_codec_mode, MODE1 ) ) { /* in MODE1 T_op is at 12.8 kHz */ - IF (NE_16(st_fx->last_L_frame, L_FRAME)) /* ACELP@16k core -> convert T_op to 16 kHz */ + IF( NE_16( st_fx->last_L_frame, L_FRAME ) ) /* ACELP@16k core -> convert T_op to 16 kHz */ { - T_op[0] = shr(add(round_fx(L_shl(L_mult(20480, T_op[0]), 2)), 1), 1); + T_op[0] = shr( add( round_fx( L_shl( L_mult( 20480, T_op[0] ), 2 ) ), 1 ), 1 ); move16(); - T_op[1] = shr(add(round_fx(L_shl(L_mult(20480, T_op[1]), 2)), 1), 1); + T_op[1] = shr( add( round_fx( L_shl( L_mult( 20480, T_op[1] ), 2 ) ), 1 ), 1 ); move16(); } } ELSE { /* in MODE2 T_op is at 16 kHz */ - IF (EQ_16(st_fx->last_L_frame, L_FRAME)) /* ACELP@12.8k core -> convert T_op to 12.8 kHz */ + IF( EQ_16( st_fx->last_L_frame, L_FRAME ) ) /* ACELP@12.8k core -> convert T_op to 12.8 kHz */ { - move16();move16(); - T_op[0] = mult_r(26214, T_op[0]); - T_op[1] = mult_r(26214, T_op[1]); + move16(); + move16(); + T_op[0] = mult_r( 26214, T_op[0] ); + T_op[1] = mult_r( 26214, T_op[1] ); } } #else - IF( NE_16(st_fx->last_L_frame, L_FRAME) ) + IF( NE_16( st_fx->last_L_frame, L_FRAME ) ) { - T_op[0] = shr(add(round_fx(L_shl(L_mult(20480, T_op[0]), 2)), 1), 1); + T_op[0] = shr( add( round_fx( L_shl( L_mult( 20480, T_op[0] ), 2 ) ), 1 ), 1 ); move16(); - T_op[1] = shr(add(round_fx(L_shl(L_mult(20480, T_op[1]), 2)), 1), 1); + T_op[1] = shr( add( round_fx( L_shl( L_mult( 20480, T_op[1] ), 2 ) ), 1 ), 1 ); move16(); } #endif /*----------------------------------------------------------------* * Excitation encoding *----------------------------------------------------------------*/ - config_acelp1(ENC, st_fx->total_brate, cbrate, st_fx->core, -1, -1, st_fx->last_L_frame, -1, &(st_fx->acelp_cfg), hBstr->nb_bits_tot_fx, - GENERIC, -1, -1, &j, &i, st_fx->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st_fx->idchan, st_fx->active_fr_cnt_fx, 0 /*tdm_Pitch_reuse_flag*/, 0, 0 /*GSC_IVAS_mode*/); + config_acelp1( ENC, st_fx->total_brate, cbrate, st_fx->core, -1, -1, st_fx->last_L_frame, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot_fx, + GENERIC, -1, -1, &j, &i, st_fx->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st_fx->idchan, st_fx->active_fr_cnt_fx, 0 /*tdm_Pitch_reuse_flag*/, 0, 0 /*GSC_IVAS_mode*/ ); encod_gen_voic_core_switch_fx( st_fx, st_fx->last_L_frame, inp, Aq, A, T_op, exc, cbrate, shift, Q_new ); @@ -140,24 +147,24 @@ void acelp_core_switch_enc_fx( * bit-stream: modify the layer of sub frame CELP *----------------------------------------------------------------*/ #ifdef IVAS_CODE_BITSTREAM - i = find_indice(hBstr, TAG_ACELP_SUBFR_LOOP_START, &value, &nb_bits); + i = find_indice( hBstr, TAG_ACELP_SUBFR_LOOP_START, &value, &nb_bits ); #ifdef DEBUGGING - assert(i >= 0 && "Internal error in ACELP core switching - unable to find ACELP subframe indices!"); + assert( i >= 0 && "Internal error in ACELP core switching - unable to find ACELP subframe indices!" ); #endif - while (hBstr->ind_list[i].id == TAG_ACELP_SUBFR_LOOP_START) + while ( hBstr->ind_list[i].id == TAG_ACELP_SUBFR_LOOP_START ) { - push_indice(hBstr, IND_CORE_SWITCHING_CELP_SUBFRAME, hBstr->ind_list[i].value, hBstr->ind_list[i].nb_bits); + push_indice( hBstr, IND_CORE_SWITCHING_CELP_SUBFRAME, hBstr->ind_list[i].value, hBstr->ind_list[i].nb_bits ); i++; } - delete_indice(hBstr, TAG_ACELP_SUBFR_LOOP_START); + delete_indice( hBstr, TAG_ACELP_SUBFR_LOOP_START ); #else - FOR( i=0; i<20; i++ ) + FOR( i = 0; i < 20; i++ ) { - hBstr->ind_list_fx[IND_CORE_SWITCHING_CELP_SUBFRAME+i].value= hBstr->ind_list_fx[TAG_ACELP_SUBFR_LOOP_START+i].value; + hBstr->ind_list_fx[IND_CORE_SWITCHING_CELP_SUBFRAME + i].value = hBstr->ind_list_fx[TAG_ACELP_SUBFR_LOOP_START + i].value; move16(); - hBstr->ind_list_fx[IND_CORE_SWITCHING_CELP_SUBFRAME+i].nb_bits= hBstr->ind_list_fx[TAG_ACELP_SUBFR_LOOP_START+i].nb_bits; + hBstr->ind_list_fx[IND_CORE_SWITCHING_CELP_SUBFRAME + i].nb_bits = hBstr->ind_list_fx[TAG_ACELP_SUBFR_LOOP_START + i].nb_bits; move16(); - hBstr->ind_list_fx[TAG_ACELP_SUBFR_LOOP_START+i].nb_bits=-1; + hBstr->ind_list_fx[TAG_ACELP_SUBFR_LOOP_START + i].nb_bits = -1; move16(); } #endif @@ -167,61 +174,60 @@ void acelp_core_switch_enc_fx( test(); test(); - IF( !( ( EQ_16(st_fx->last_L_frame, L_FRAME16k)&&EQ_16(inner_frame_tbl[st_fx->bwidth],L_FRAME16k))||EQ_16(inner_frame_tbl[st_fx->bwidth],L_FRAME8k))) + IF( !( ( EQ_16( st_fx->last_L_frame, L_FRAME16k ) && EQ_16( inner_frame_tbl[st_fx->bwidth], L_FRAME16k ) ) || EQ_16( inner_frame_tbl[st_fx->bwidth], L_FRAME8k ) ) ) { - bwe_switch_enc_fx( st_fx, (const Word16 *)st_fx->old_input_signal_fx ); + bwe_switch_enc_fx( st_fx, (const Word16 *) st_fx->old_input_signal_fx ); } return; } /*-------------------------------------------------------------------* - * encod_gen_voic_core_switch() - * - * Encode excitation signal in ACELP->HQ switching frame - *-------------------------------------------------------------------*/ + * encod_gen_voic_core_switch() + * + * Encode excitation signal in ACELP->HQ switching frame + *-------------------------------------------------------------------*/ static void encod_gen_voic_core_switch_fx( - Encoder_State *st_fx, /* i/o: state structure */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 inp[], /* i : input signal */ - const Word16 Aq[], /* i : LP coefficients */ - const Word16 A[], /* i : unquantized A(z) filter */ - const Word16 T_op[], /* i : open loop pitch */ - Word16 *exc, /* i/o: current non-enhanced excitation */ - const Word32 core_bitrate, /* i : switching frame bitrate */ + Encoder_State *st_fx, /* i/o: state structure */ + const Word16 L_frame, /* i : length of the frame */ + const Word16 inp[], /* i : input signal */ + const Word16 Aq[], /* i : LP coefficients */ + const Word16 A[], /* i : unquantized A(z) filter */ + const Word16 T_op[], /* i : open loop pitch */ + Word16 *exc, /* i/o: current non-enhanced excitation */ + const Word32 core_bitrate, /* i : switching frame bitrate */ Word16 shift, - Word16 Q_new -) + Word16 Q_new ) { Word16 res[L_SUBFR]; /* residual signal Qexc */ - Word16 Ap[M+1]; /* A(z) with spectral expansion Q12 */ + Word16 Ap[M + 1]; /* A(z) with spectral expansion Q12 */ Word16 xn[L_SUBFR]; /* Target vector for pitch search */ Word16 xn2[L_SUBFR]; /* Target vector for codebook search */ Word16 cn[L_SUBFR]; /* Target vector in residual domain */ - Word16 h1[L_SUBFR+(M+1)]; /* Impulse response vector */ - - Word16 code[L_SUBFR]; /* Fixed codebook excitation Q9 */ - Word16 y1[L_SUBFR]; /* Filtered adaptive excitation */ - Word16 y2[L_SUBFR]; /* Filtered algebraic excitation */ - Word16 gain_pit ; /* Pitch gain Q15 */ - Word16 voice_fac; /* Voicing factor Q15 */ - Word32 gain_code; /* Gain of code Q16 */ - Word16 gain_inov; /* inovation gain */ - Word16 i,gcode16; /* tmp variables */ - Word16 T0, T0_frac; /* close loop integer pitch and fractional part */ - Word16 T0_min, T0_max; /* pitch variables */ - - Word16 pitch,tmp16; /* floating pitch value */ - Word16 g_corr[6]; /* ACELP correl, values + gain pitch */ - Word16 clip_gain; /* ISF clip gain */ - - Word16 unbits; /* number of unused bits for PI */ + Word16 h1[L_SUBFR + ( M + 1 )]; /* Impulse response vector */ + + Word16 code[L_SUBFR]; /* Fixed codebook excitation Q9 */ + Word16 y1[L_SUBFR]; /* Filtered adaptive excitation */ + Word16 y2[L_SUBFR]; /* Filtered algebraic excitation */ + Word16 gain_pit; /* Pitch gain Q15 */ + Word16 voice_fac; /* Voicing factor Q15 */ + Word32 gain_code; /* Gain of code Q16 */ + Word16 gain_inov; /* inovation gain */ + Word16 i, gcode16; /* tmp variables */ + Word16 T0, T0_frac; /* close loop integer pitch and fractional part */ + Word16 T0_min, T0_max; /* pitch variables */ + + Word16 pitch, tmp16; /* floating pitch value */ + Word16 g_corr[6]; /* ACELP correl, values + gain pitch */ + Word16 clip_gain; /* ISF clip gain */ + + Word16 unbits; /* number of unused bits for PI */ Word32 norm_gain_code; Word16 pitch_limit_flag; Word32 L_tmp, Lgcode; Word16 shift_wsp; - Word16 h2[L_SUBFR + (M + 1)]; + Word16 h2[L_SUBFR + ( M + 1 )]; Word16 dummyF[NB_SUBFR16k]; Word16 lp_select, lp_flag; LPD_state_HANDLE hLPDmem; /* ACELP LPDmem memories */ @@ -230,18 +236,18 @@ static void encod_gen_voic_core_switch_fx( hLPDmem = st_fx->hLPDmem; hBstr = st_fx->hBstr; - TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; + TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; /*------------------------------------------------------------------* - * Initializations - *------------------------------------------------------------------*/ + * Initializations + *------------------------------------------------------------------*/ - shift_wsp = add(Q_new,shift); + shift_wsp = add( Q_new, shift ); unbits = 0; move16(); - IF( EQ_16(L_frame, L_FRAME)) + IF( EQ_16( L_frame, L_FRAME ) ) { T0_max = PIT_MAX; move16(); @@ -257,145 +263,144 @@ static void encod_gen_voic_core_switch_fx( } /*------------------------------------------------------------------* - * Calculation of LP residual (filtering through A[z] filter) - *------------------------------------------------------------------*/ + * Calculation of LP residual (filtering through A[z] filter) + *------------------------------------------------------------------*/ - tmp16=st_fx->L_frame; + tmp16 = st_fx->L_frame; move16(); - st_fx->L_frame=L_SUBFR; + st_fx->L_frame = L_SUBFR; move16(); - calc_residu_fx(st_fx, inp, res, Aq); + calc_residu_fx( st_fx, inp, res, Aq ); hTdCngEnc->burst_ho_cnt = 0; move16(); - st_fx->L_frame=tmp16; + st_fx->L_frame = tmp16; move16(); /*------------------------------------------------------------------* - * ACELP subframe loop - *------------------------------------------------------------------*/ + * ACELP subframe loop + *------------------------------------------------------------------*/ Copy( res, exc, L_SUBFR ); - IF( EQ_16(L_frame,L_FRAME16k)) + IF( EQ_16( L_frame, L_FRAME16k ) ) { weight_a_fx( A, Ap, GAMMA16k, M ); /* Bandwidth expansion of A(z) filter coefficients */ - find_targets_fx(inp, hLPDmem->mem_syn, 0, &(hLPDmem->mem_w0), Aq, res, L_SUBFR, Ap, PREEMPH_FAC_16k, xn, cn, h1); + find_targets_fx( inp, hLPDmem->mem_syn, 0, &( hLPDmem->mem_w0 ), Aq, res, L_SUBFR, Ap, PREEMPH_FAC_16k, xn, cn, h1 ); } ELSE { - weight_a_fx( A, Ap, GAMMA1, M ); /* Bandwidth expansion of A(z) filter coefficients */ - find_targets_fx(inp, hLPDmem->mem_syn,0,&(hLPDmem->mem_w0), Aq, res, L_SUBFR, Ap, TILT_FAC_FX, xn, cn ,h1); + weight_a_fx( A, Ap, GAMMA1, M ); /* Bandwidth expansion of A(z) filter coefficients */ + find_targets_fx( inp, hLPDmem->mem_syn, 0, &( hLPDmem->mem_w0 ), Aq, res, L_SUBFR, Ap, TILT_FAC_FX, xn, cn, h1 ); } - /*Scale_sig(h1, L_SUBFR, shift); *//*Q14-shift */ - Copy_Scale_sig(h1, h2, L_SUBFR, -2); - Scale_sig(h1, L_SUBFR, add(1, shift)); /* set h1[] in Q14 with scaling for convolution */ + /*Scale_sig(h1, L_SUBFR, shift); */ /*Q14-shift */ + Copy_Scale_sig( h1, h2, L_SUBFR, -2 ); + Scale_sig( h1, L_SUBFR, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution */ /* scaling of xn[] to limit dynamic at 12 bits */ - Scale_sig(xn, L_SUBFR, shift); + Scale_sig( xn, L_SUBFR, shift ); /*----------------------------------------------------------------* - * Close-loop pitch search and quantization - * Adaptive exc. construction - *----------------------------------------------------------------*/ - set16_fx(dummyF, -1, NB_SUBFR16k); /* hack to signal ACELP->HQ switching frame */ - pitch = pit_encode_fx(hBstr, - st_fx->acelp_cfg.pitch_bits, core_bitrate, 0, L_frame, GENERIC, &pitch_limit_flag, 0, exc, L_SUBFR, T_op, &T0_min, &T0_max, &T0, &T0_frac, h1, xn - , 0 /*hStereoTD->tdm_Pitch_reuse_flag*/, dummyF /*hStereoTD->tdm_Pri_pitch_buf*/); + * Close-loop pitch search and quantization + * Adaptive exc. construction + *----------------------------------------------------------------*/ + set16_fx( dummyF, -1, NB_SUBFR16k ); /* hack to signal ACELP->HQ switching frame */ + pitch = pit_encode_fx( hBstr, + st_fx->acelp_cfg.pitch_bits, core_bitrate, 0, L_frame, GENERIC, &pitch_limit_flag, 0, exc, L_SUBFR, T_op, &T0_min, &T0_max, &T0, &T0_frac, h1, xn, 0 /*hStereoTD->tdm_Pitch_reuse_flag*/, dummyF /*hStereoTD->tdm_Pri_pitch_buf*/ ); /*-----------------------------------------------------------------* - * Find adaptive exitation - *-----------------------------------------------------------------*/ + * Find adaptive exitation + *-----------------------------------------------------------------*/ - pred_lt4( &exc[0], &exc[0], T0, T0_frac, L_SUBFR+1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + pred_lt4( &exc[0], &exc[0], T0, T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); /*-----------------------------------------------------------------* - * Gain clipping test to avoid unstable synthesis on frame erasure - * or in case of floating point encoder & fixed p. decoder - *-----------------------------------------------------------------*/ + * Gain clipping test to avoid unstable synthesis on frame erasure + * or in case of floating point encoder & fixed p. decoder + *-----------------------------------------------------------------*/ - clip_gain = gp_clip_fx(st_fx->element_mode, core_bitrate, st_fx->voicing_fx, 0, GENERIC, xn, st_fx->clip_var_fx, sub(shift_wsp, 1) ); + clip_gain = gp_clip_fx( st_fx->element_mode, core_bitrate, st_fx->voicing_fx, 0, GENERIC, xn, st_fx->clip_var_fx, sub( shift_wsp, 1 ) ); /*-----------------------------------------------------------------* - * LP filtering of the adaptive excitation, codebook target computation - *-----------------------------------------------------------------*/ + * LP filtering of the adaptive excitation, codebook target computation + *-----------------------------------------------------------------*/ lp_flag = st_fx->acelp_cfg.ltf_mode; lp_select = lp_filt_exc_enc_fx( MODE1, GENERIC, 0, exc, h1, xn, y1, xn2, L_SUBFR, L_frame, g_corr, clip_gain, &gain_pit, &lp_flag ); - IF( EQ_16(lp_flag,NORMAL_OPERATION)) + IF( EQ_16( lp_flag, NORMAL_OPERATION ) ) { - push_indice_fx(hBstr, IND_LP_FILT_SELECT, lp_select, 1 ); + push_indice_fx( hBstr, IND_LP_FILT_SELECT, lp_select, 1 ); } /*-----------------------------------------------------------------* - * Innovation encoding - *-----------------------------------------------------------------*/ + * Innovation encoding + *-----------------------------------------------------------------*/ - inov_encode_fx( st_fx, core_bitrate, 0, L_frame,st_fx->last_L_frame, GENERIC, st_fx->bwidth, 0, 0, -1, Aq, gain_pit, cn, exc, - h2, hLPDmem->tilt_code, pitch, xn2, code, y2, &unbits, L_SUBFR, shift); + inov_encode_fx( st_fx, core_bitrate, 0, L_frame, st_fx->last_L_frame, GENERIC, st_fx->bwidth, 0, 0, -1, Aq, gain_pit, cn, exc, + h2, hLPDmem->tilt_code, pitch, xn2, code, y2, &unbits, L_SUBFR, shift ); /*-----------------------------------------------------------------* - * Gain encoding - *-----------------------------------------------------------------*/ - IF( EQ_16(L_frame,L_FRAME)) + * Gain encoding + *-----------------------------------------------------------------*/ + IF( EQ_16( L_frame, L_FRAME ) ) { - gain_enc_mless_fx(hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, L_frame, 0, -1, xn, y1, shift_wsp, y2, code, st_fx->old_Es_pred_fx, + gain_enc_mless_fx( hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, L_frame, 0, -1, xn, y1, shift_wsp, y2, code, st_fx->old_Es_pred_fx, &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain ); } ELSE { - gain_enc_mless_fx(hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, L_frame, 0, -1, xn, y1, shift_wsp, y2, code, st_fx->old_Es_pred_fx, - &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain ); + gain_enc_mless_fx( hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, L_frame, 0, -1, xn, y1, shift_wsp, y2, code, st_fx->old_Es_pred_fx, + &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain ); } - gp_clip_test_gain_pit_fx(st_fx->element_mode, core_bitrate, gain_pit, st_fx->clip_var_fx ); + gp_clip_test_gain_pit_fx( st_fx->element_mode, core_bitrate, gain_pit, st_fx->clip_var_fx ); - Lgcode = L_shl(gain_code, Q_new); /* scaled gain_code with Qnew -> Q16*/ - gcode16 = round_fx(Lgcode); + Lgcode = L_shl( gain_code, Q_new ); /* scaled gain_code with Qnew -> Q16*/ + gcode16 = round_fx( Lgcode ); - hLPDmem->tilt_code = Est_tilt2( exc+0, gain_pit, code, gain_code, &voice_fac,shift ); + hLPDmem->tilt_code = Est_tilt2( exc + 0, gain_pit, code, gain_code, &voice_fac, shift ); /*-----------------------------------------------------------------* - * Construct adaptive part of the excitation - *-----------------------------------------------------------------*/ + * Construct adaptive part of the excitation + *-----------------------------------------------------------------*/ FOR( i = 0; i < L_SUBFR; i++ ) { /* code in Q9, gain_pit in Q14 */ - L_tmp = L_mult(gcode16, code[i]); + L_tmp = L_mult( gcode16, code[i] ); #ifdef BASOP_NOGLOB L_tmp = L_shl_sat( L_tmp, 5 ); - L_tmp = L_mac_sat(L_tmp, exc[i ], gain_pit); - L_tmp = L_shl_sat(L_tmp, 1); /* saturation can occur here */ - exc[i ] = round_fx_sat(L_tmp); + L_tmp = L_mac_sat( L_tmp, exc[i], gain_pit ); + L_tmp = L_shl_sat( L_tmp, 1 ); /* saturation can occur here */ + exc[i] = round_fx_sat( L_tmp ); #else - L_tmp = L_shl(L_tmp, 5); - L_tmp = L_mac(L_tmp, exc[i ], gain_pit); - L_tmp = L_shl(L_tmp, 1); /* saturation can occur here */ - exc[i ] = round_fx(L_tmp); + L_tmp = L_shl( L_tmp, 5 ); + L_tmp = L_mac( L_tmp, exc[i], gain_pit ); + L_tmp = L_shl( L_tmp, 1 ); /* saturation can occur here */ + exc[i] = round_fx( L_tmp ); #endif } /* write reserved bits */ IF( unbits ) { - push_indice_fx(hBstr, IND_UNUSED, 0, unbits ); + push_indice_fx( hBstr, IND_UNUSED, 0, unbits ); } /*-----------------------------------------------------------------* * long term prediction on the 2nd sub frame *-----------------------------------------------------------------*/ - pred_lt4(&exc[L_SUBFR], &exc[L_SUBFR], T0, T0_frac, L_SUBFR+1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP); + pred_lt4( &exc[L_SUBFR], &exc[L_SUBFR], T0, T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); - FOR( i = L_SUBFR; i < 2*L_SUBFR; i++ ) + FOR( i = L_SUBFR; i < 2 * L_SUBFR; i++ ) { #ifdef BASOP_NOGLOB exc[i] = round_fx_sat( L_shl_sat( L_mult_sat( exc[i], gain_pit ), 1 ) ); #else - exc[i] = round_fx(L_shl(L_mult(exc[i], gain_pit), 1)); + exc[i] = round_fx( L_shl( L_mult( exc[i], gain_pit ), 1 ) ); #endif } @@ -404,72 +409,72 @@ static void encod_gen_voic_core_switch_fx( /*-------------------------------------------------------------------* - * bwe_switch_enc() - * - * Encode BWE in ACELP->HQ switching frame - *-------------------------------------------------------------------*/ + * bwe_switch_enc() + * + * Encode BWE in ACELP->HQ switching frame + *-------------------------------------------------------------------*/ static void bwe_switch_enc_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 *new_speech_fx /* i : original input signal Q0 */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word16 *new_speech_fx /* i : original input signal Q0 */ ) { Word16 k, Loverlapp_fx, d1m_fx, maxd1_fx, ind1_fx, gapsize_fx; Word16 delta_fx, fdelay_fx; const Word16 *hp_filter_fx; - const Word16 *fpointers_tab[6] = {hp12800_16000_fx, hp12800_32000_fx, hp12800_48000_fx, hp16000_48000_fx, hp16000_32000_fx, hp16000_48000_fx}; + const Word16 *fpointers_tab[6] = { hp12800_16000_fx, hp12800_32000_fx, hp12800_48000_fx, hp16000_48000_fx, hp16000_32000_fx, hp16000_48000_fx }; Word16 tmp, shift; const Word16 *ptmp; - Word16 tmp_mem_fx[2*L_FILT48k], tmp_mem2_fx[2*L_FILT48k], hb_synth_tmp_fx[480]; + Word16 tmp_mem_fx[2 * L_FILT48k], tmp_mem2_fx[2 * L_FILT48k], hb_synth_tmp_fx[480]; Word16 Fs_kHz; Word16 q_tmp1, q_tmp2, Qmc, Qsq; Word32 L_tmp1, L_tmp2, L_tmp3, min_sq_cross_fx; Word16 accA_fx, accB_fx, min_corr_fx, E1_fx, E2_fx, gain_fx; - Word16 synth_subfr_bwe_fx[SWITCH_MAX_GAP]; /* synthesized bwe for core switching */ + Word16 synth_subfr_bwe_fx[SWITCH_MAX_GAP]; /* synthesized bwe for core switching */ Word16 n, L; BSTR_ENC_HANDLE hBstr; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif hBstr = st_fx->hBstr; - L = NS2SA_fx2(st_fx->input_Fs,FRAME_SIZE_NS); + L = NS2SA_fx2( st_fx->input_Fs, FRAME_SIZE_NS ); /* set multiplication factor according to the sampling rate */ - tmp = extract_l(L_shr(st_fx->input_Fs,14)); - delta_fx = add(tmp,1); - Fs_kHz = shl(delta_fx,4); - tmp = add(tmp,i_mult2(3,(sub(st_fx->last_L_frame,L_FRAME)!=0))); + tmp = extract_l( L_shr( st_fx->input_Fs, 14 ) ); + delta_fx = add( tmp, 1 ); + Fs_kHz = shl( delta_fx, 4 ); + tmp = add( tmp, i_mult2( 3, ( sub( st_fx->last_L_frame, L_FRAME ) != 0 ) ) ); ptmp = fpointers_tab[tmp]; move16(); hp_filter_fx = ptmp; - fdelay_fx=i_mult2(16,delta_fx); - IF(EQ_16(st_fx->last_L_frame,L_FRAME)) + fdelay_fx = i_mult2( 16, delta_fx ); + IF( EQ_16( st_fx->last_L_frame, L_FRAME ) ) { - fdelay_fx=i_mult2(20,delta_fx); + fdelay_fx = i_mult2( 20, delta_fx ); } - n = i_mult2(N16_CORE_SW,delta_fx); + n = i_mult2( N16_CORE_SW, delta_fx ); - set16_fx( tmp_mem_fx, 0, 2*L_FILT48k); - set16_fx( tmp_mem2_fx, 0, 2*L_FILT48k); + set16_fx( tmp_mem_fx, 0, 2 * L_FILT48k ); + set16_fx( tmp_mem2_fx, 0, 2 * L_FILT48k ); - Loverlapp_fx = i_mult2(delta_fx,SWITCH_OVERLAP_8k*2); - gapsize_fx = i_mult2(delta_fx,NS2SA(16000,SWITCH_GAP_LENGTH_NS)); + Loverlapp_fx = i_mult2( delta_fx, SWITCH_OVERLAP_8k * 2 ); + gapsize_fx = i_mult2( delta_fx, NS2SA( 16000, SWITCH_GAP_LENGTH_NS ) ); - shift = sub(add(add(shr(L,1),n),Loverlapp_fx),gapsize_fx) ; - Copy( new_speech_fx+shift,synth_subfr_bwe_fx,add(gapsize_fx,fdelay_fx) ); - Copy( new_speech_fx+sub(shift,fdelay_fx),tmp_mem_fx,fdelay_fx ); + shift = sub( add( add( shr( L, 1 ), n ), Loverlapp_fx ), gapsize_fx ); + Copy( new_speech_fx + shift, synth_subfr_bwe_fx, add( gapsize_fx, fdelay_fx ) ); + Copy( new_speech_fx + sub( shift, fdelay_fx ), tmp_mem_fx, fdelay_fx ); - tmp = add(gapsize_fx, fdelay_fx); + tmp = add( gapsize_fx, fdelay_fx ); fir_fx( synth_subfr_bwe_fx, hp_filter_fx, synth_subfr_bwe_fx, tmp_mem_fx, tmp, fdelay_fx, 1, 0 ); - Copy(synth_subfr_bwe_fx+shr(fdelay_fx,1),synth_subfr_bwe_fx,sub(gapsize_fx,shr(fdelay_fx,1)) ); + Copy( synth_subfr_bwe_fx + shr( fdelay_fx, 1 ), synth_subfr_bwe_fx, sub( gapsize_fx, shr( fdelay_fx, 1 ) ) ); - tmp = i_mult2(Fs_kHz,10); + tmp = i_mult2( Fs_kHz, 10 ); fir_fx( new_speech_fx, hp_filter_fx, hb_synth_tmp_fx, tmp_mem2_fx, tmp, fdelay_fx, 1, 0 ); - min_sq_cross_fx = L_negate(1); + min_sq_cross_fx = L_negate( 1 ); Qsq = 0; move16(); min_corr_fx = 0; @@ -479,15 +484,15 @@ static void bwe_switch_enc_fx( d1m_fx = 0; move16(); - maxd1_fx = sub(tmp,add(gapsize_fx,fdelay_fx)); + maxd1_fx = sub( tmp, add( gapsize_fx, fdelay_fx ) ); - IF (EQ_16(delta_fx, 2)) + IF( EQ_16( delta_fx, 2 ) ) { - maxd1_fx = shr(maxd1_fx,1); + maxd1_fx = shr( maxd1_fx, 1 ); } - ELSE IF (EQ_16(delta_fx, 3)) + ELSE IF( EQ_16( delta_fx, 3 ) ) { - maxd1_fx = extract_h(L_mult(maxd1_fx, 10923)); + maxd1_fx = extract_h( L_mult( maxd1_fx, 10923 ) ); } /* find delay */ @@ -495,17 +500,17 @@ static void bwe_switch_enc_fx( move16(); FOR( k = 0; k < maxd1_fx; k++ ) { - accA_fx = dotprod_satcont(ptmp, ptmp, 0, 0, &q_tmp1, gapsize_fx, delta_fx); - accB_fx = dotprod_satcont(ptmp, synth_subfr_bwe_fx, 0, 0, &q_tmp2, gapsize_fx, delta_fx); + accA_fx = dotprod_satcont( ptmp, ptmp, 0, 0, &q_tmp1, gapsize_fx, delta_fx ); + accB_fx = dotprod_satcont( ptmp, synth_subfr_bwe_fx, 0, 0, &q_tmp2, gapsize_fx, delta_fx ); ptmp += delta_fx; - L_tmp1 = L_mult0(accB_fx, accB_fx); /*2*q_tmp2; */ - L_tmp2 = Mult_32_16(L_tmp1, min_corr_fx); /*2*q_tmp2+Qmc-15 */ - L_tmp3 = Mult_32_16(min_sq_cross_fx, accA_fx); /*Qsq+q_tmp1-15 */ - shift = s_min(add(shl(q_tmp2,1),Qmc),add(q_tmp1,Qsq)); - L_tmp2 = L_shr(L_tmp2, sub(add(shl(q_tmp2,1),Qmc),shift)); - L_tmp3 = L_shr(L_tmp3, sub(add(q_tmp1,Qsq),shift)); - - IF (GE_32(L_tmp2,L_tmp3)) + L_tmp1 = L_mult0( accB_fx, accB_fx ); /*2*q_tmp2; */ + L_tmp2 = Mult_32_16( L_tmp1, min_corr_fx ); /*2*q_tmp2+Qmc-15 */ + L_tmp3 = Mult_32_16( min_sq_cross_fx, accA_fx ); /*Qsq+q_tmp1-15 */ + shift = s_min( add( shl( q_tmp2, 1 ), Qmc ), add( q_tmp1, Qsq ) ); + L_tmp2 = L_shr( L_tmp2, sub( add( shl( q_tmp2, 1 ), Qmc ), shift ) ); + L_tmp3 = L_shr( L_tmp3, sub( add( q_tmp1, Qsq ), shift ) ); + + IF( GE_32( L_tmp2, L_tmp3 ) ) { d1m_fx = k; move16(); @@ -513,49 +518,49 @@ static void bwe_switch_enc_fx( move16(); Qmc = q_tmp1; move16(); - min_sq_cross_fx = L_add(L_tmp1, 0); - Qsq = shl(q_tmp2,1); + min_sq_cross_fx = L_add( L_tmp1, 0 ); + Qsq = shl( q_tmp2, 1 ); move16(); } } - push_indice_fx(hBstr, IND_CORE_SWITCHING_AUDIO_DELAY, d1m_fx, AUDIODELAYBITS ); + push_indice_fx( hBstr, IND_CORE_SWITCHING_AUDIO_DELAY, d1m_fx, AUDIODELAYBITS ); - tmp = add(i_mult2(d1m_fx,delta_fx),fdelay_fx); + tmp = add( i_mult2( d1m_fx, delta_fx ), fdelay_fx ); ptmp = &hb_synth_tmp_fx[tmp]; move16(); - E1_fx = dotprod_satcont(synth_subfr_bwe_fx, synth_subfr_bwe_fx, 0, 0, &q_tmp1, gapsize_fx, 1); - E2_fx = dotprod_satcont(ptmp, ptmp, 0, 0, &q_tmp2, gapsize_fx, 1); + E1_fx = dotprod_satcont( synth_subfr_bwe_fx, synth_subfr_bwe_fx, 0, 0, &q_tmp1, gapsize_fx, 1 ); + E2_fx = dotprod_satcont( ptmp, ptmp, 0, 0, &q_tmp2, gapsize_fx, 1 ); - IF (!E1_fx) + IF( !E1_fx ) { - E1_fx = shl(1,14); + E1_fx = shl( 1, 14 ); q_tmp1 = 14; move16(); } - IF (!E2_fx) + IF( !E2_fx ) { - E2_fx = shl(1,14); + E2_fx = shl( 1, 14 ); q_tmp2 = 14; move16(); } - tmp = div_s(shl(1, 14), E1_fx); /*Q(29-q_tmp1) */ - L_tmp1 = L_mult(tmp, E2_fx); /*30-q_tmp1+q_tmp2 */ - q_tmp2 = sub(q_tmp1, q_tmp2); /*30-q_tmp2 */ - L_tmp1 = L_shl(L_tmp1, sub(q_tmp2, 24)); + tmp = div_s( shl( 1, 14 ), E1_fx ); /*Q(29-q_tmp1) */ + L_tmp1 = L_mult( tmp, E2_fx ); /*30-q_tmp1+q_tmp2 */ + q_tmp2 = sub( q_tmp1, q_tmp2 ); /*30-q_tmp2 */ + L_tmp1 = L_shl( L_tmp1, sub( q_tmp2, 24 ) ); #ifdef BASOP_NOGLOB - gain_fx = round_fx_o(Isqrt(L_tmp1), &Overflow); /*Q12 */ + gain_fx = round_fx_o( Isqrt( L_tmp1 ), &Overflow ); /*Q12 */ #else - gain_fx = round_fx(Isqrt(L_tmp1)); /*Q12 */ + gain_fx = round_fx( Isqrt( L_tmp1 ) ); /*Q12 */ #endif - ind1_fx = usquant_fx( gain_fx, &gain_fx, shr(MINVALUEOFFIRSTGAIN_FX,1), shr(DELTAOFFIRSTGAIN_FX,4), (1 << NOOFGAINBITS1) ); - push_indice_fx(hBstr,IND_CORE_SWITCHING_AUDIO_GAIN, ind1_fx, NOOFGAINBITS1 ); + ind1_fx = usquant_fx( gain_fx, &gain_fx, shr( MINVALUEOFFIRSTGAIN_FX, 1 ), shr( DELTAOFFIRSTGAIN_FX, 4 ), ( 1 << NOOFGAINBITS1 ) ); + push_indice_fx( hBstr, IND_CORE_SWITCHING_AUDIO_GAIN, ind1_fx, NOOFGAINBITS1 ); return; } -static Word16 dotprod_satcont(const Word16 *x, const Word16 *y, Word16 qx, Word16 qy, Word16 *qo, Word16 len, Word16 delta) +static Word16 dotprod_satcont( const Word16 *x, const Word16 *y, Word16 qx, Word16 qy, Word16 *qo, Word16 len, Word16 delta ) { Word16 tmp_tabx[L_FRAME48k], tmp_taby[L_FRAME48k]; Word16 shift, q, ener, i; @@ -570,37 +575,37 @@ static Word16 dotprod_satcont(const Word16 *x, const Word16 *y, Word16 qx, Word1 move16(); DO { - L_tmp = L_deposit_l(0); + L_tmp = L_deposit_l( 0 ); Overflow = 0; move16(); - FOR ( i = 0; i < len; i += delta ) - { -#ifdef BASOP_NOGLOB /* Critical Overflow*/ - L_tmp = L_mac0_o(L_tmp, tmp_tabx[i], tmp_taby[i], &Overflow); /*Q(qx+qy-shift) */ -#else /* BASOP_NOGLOB */ - L_tmp = L_mac0(L_tmp, tmp_tabx[i], tmp_taby[i]); /*Q(qx+qy-shift) */ + FOR( i = 0; i < len; i += delta ) + { +#ifdef BASOP_NOGLOB /* Critical Overflow*/ + L_tmp = L_mac0_o( L_tmp, tmp_tabx[i], tmp_taby[i], &Overflow ); /*Q(qx+qy-shift) */ +#else /* BASOP_NOGLOB */ + L_tmp = L_mac0( L_tmp, tmp_tabx[i], tmp_taby[i] ); /*Q(qx+qy-shift) */ #endif } - IF(Overflow != 0) + IF( Overflow != 0 ) { FOR( i = 0; i < len; i += delta ) { - tmp_tabx[i] = shr(tmp_tabx[i], 2); + tmp_tabx[i] = shr( tmp_tabx[i], 2 ); move16(); - tmp_taby[i] = shr(tmp_taby[i], 2); + tmp_taby[i] = shr( tmp_taby[i], 2 ); move16(); } - shift = add(shift, 4); + shift = add( shift, 4 ); } } - WHILE(Overflow != 0); + WHILE( Overflow != 0 ); - q = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, q); /*Q(qx+qy-shift+q) */ - ener = extract_h(L_tmp); /*Q(qx+qy-shift+q-16) */ - q = add(q, add(qx, qy)); - *qo = sub(q, add(shift, 16)); + q = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, q ); /*Q(qx+qy-shift+q) */ + ener = extract_h( L_tmp ); /*Q(qx+qy-shift+q-16) */ + q = add( q, add( qx, qy ) ); + *qo = sub( q, add( shift, 16 ) ); return ener; } diff --git a/lib_enc/acelp_enc_util_fx.c b/lib_enc/acelp_enc_util_fx.c index 4cd28a324..8dde5a319 100644 --- a/lib_enc/acelp_enc_util_fx.c +++ b/lib_enc/acelp_enc_util_fx.c @@ -9,9 +9,9 @@ //#include "prot_fx.h" #include "basop_util.h" #include "cnst.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ #include "stat_enc.h" #include "rom_com.h" #include "rom_com_fx.h" @@ -33,14 +33,13 @@ * Multiplication of Toeplitz matrix with vector c, such that * d = toeplitz(R)*c * Vector length is L_SUBFR -*/ + */ Word16 E_ACELP_toeplitz_mul_fx( - const Word16 R[], - const Word16 c[], - Word16 d[], - const Word16 L_subfr, - const Word16 highrate -) + const Word16 R[], + const Word16 c[], + Word16 d[], + const Word16 L_subfr, + const Word16 highrate ) { static const Word16 step = 4; Word16 k, j, i; @@ -48,61 +47,61 @@ Word16 E_ACELP_toeplitz_mul_fx( Word32 y32[L_SUBFR16k], L_maxloc, L_tot; - assert(L_subfr <= L_SUBFR16k); + assert( L_subfr <= L_SUBFR16k ); /* first keep the result on 32 bits and find absolute maximum */ - L_tot = L_deposit_l(1); + L_tot = L_deposit_l( 1 ); - FOR (k = 0; k < step; k++) + FOR( k = 0; k < step; k++ ) { - L_maxloc = L_deposit_l(0); - FOR (i = k; i < L_subfr; i += step) + L_maxloc = L_deposit_l( 0 ); + FOR( i = k; i < L_subfr; i += step ) { - s = L_mult(R[i], c[0]); - FOR (j = 1; j < i; j++) + s = L_mult( R[i], c[0] ); + FOR( j = 1; j < i; j++ ) { - s = L_mac(s, R[i-j], c[j]); + s = L_mac( s, R[i - j], c[j] ); } - FOR (; j 16 x tot */ + j = s_min( sub( norm_l( L_tot ), 4 + 16 ), 15 - 16 ); /* 4 -> 16 x tot */ - Copy_Scale_sig_32_16(y32, d, L_subfr, j); + Copy_Scale_sig_32_16( y32, d, L_subfr, j ); return j; } @@ -133,38 +132,38 @@ void E_ACELP_weighted_code( /* Collect nonzeros */ n = 0; move16(); - FOR (i=0; i 0); + assert( n > 0 ); - one = shl(1, Q); - Q = sub(15, Q); + one = shl( 1, Q ); + Q = sub( 15, Q ); /* Generate weighted code */ j = nz[0]; move16(); - set16_fx(y, 0, j); - FOR (k=0; knb_pulse+(k*4) <= 40); + assert( config->nb_pulse + ( k * 4 ) <= 40 ); - copyWord8((const Word8*)E_ROM_tipos+(k * 4), (Word8*)ipos, config->nb_pulse); + copyWord8( (const Word8 *) E_ROM_tipos + ( k * 4 ), (Word8 *) ipos, config->nb_pulse ); /* if all tracks do not have equal number of pulses */ - restpulses = s_and(config->nb_pulse, 3); + restpulses = s_and( config->nb_pulse, 3 ); - IF (restpulses) + IF( restpulses ) { - SWITCH (config->codetrackpos) + SWITCH( config->codetrackpos ) { - case TRACKPOS_FIXED_FIRST: /* fixed track positions, starting from left */ - /* add tracks from left */ - FOR (iPulse=0; iPulsenb_pulse-restpulses+iPulse] = (UWord8)iPulse; + case TRACKPOS_FIXED_FIRST: /* fixed track positions, starting from left */ + /* add tracks from left */ + FOR( iPulse = 0; iPulse < restpulses; iPulse++ ) + { + ipos[config->nb_pulse - restpulses + iPulse] = (UWord8) iPulse; + move16(); + } + /* Put the same track on the next position, because the 1-pulse search + * will access it to determine if this could be in any track. */ + ipos[config->nb_pulse] = ipos[config->nb_pulse - 1]; move16(); - } - /* Put the same track on the next position, because the 1-pulse search - * will access it to determine if this could be in any track. */ - ipos[config->nb_pulse] = ipos[config->nb_pulse-1]; - move16(); - BREAK; - case TRACKPOS_FIXED_EVEN: /* fixed track positions, odd tracks */ - /* odd tracks, switch order for every iteration */ - ipos[config->nb_pulse-restpulses] = (UWord8)s_and(lshl(k,1),2); - move16();/* 0 for even k, 2 for odd */ - ipos[config->nb_pulse-restpulses+1] = (UWord8)s_xor(ipos[config->nb_pulse-restpulses], 2); - move16();/* 2 for even k, 0 for odd */ - BREAK; - case TRACKPOS_FIXED_TWO: /* two tracks instead of four */ - /* Put the next track on the next position, because the 1-pulse search - * will access it to determine if this could be in any track. */ - ipos[config->nb_pulse] = (UWord8)s_and(add(ipos[config->nb_pulse-1],1),3); - move16(); - BREAK; - default: /* one or three free track positions */ - /* copy an extra position from table - 1pulse search will access this */ - ipos[config->nb_pulse] = E_ROM_tipos[add(shl(k,2),config->nb_pulse)]; - move16(); - BREAK; + BREAK; + case TRACKPOS_FIXED_EVEN: /* fixed track positions, odd tracks */ + /* odd tracks, switch order for every iteration */ + ipos[config->nb_pulse - restpulses] = (UWord8) s_and( lshl( k, 1 ), 2 ); + move16(); /* 0 for even k, 2 for odd */ + ipos[config->nb_pulse - restpulses + 1] = (UWord8) s_xor( ipos[config->nb_pulse - restpulses], 2 ); + move16(); /* 2 for even k, 0 for odd */ + BREAK; + case TRACKPOS_FIXED_TWO: /* two tracks instead of four */ + /* Put the next track on the next position, because the 1-pulse search + * will access it to determine if this could be in any track. */ + ipos[config->nb_pulse] = (UWord8) s_and( add( ipos[config->nb_pulse - 1], 1 ), 3 ); + move16(); + BREAK; + default: /* one or three free track positions */ + /* copy an extra position from table - 1pulse search will access this */ + ipos[config->nb_pulse] = E_ROM_tipos[add( shl( k, 2 ), config->nb_pulse )]; + move16(); + BREAK; } } } - diff --git a/lib_enc/amr_wb_enc.c b/lib_enc/amr_wb_enc.c index f8540bf52..054332d5f 100644 --- a/lib_enc/amr_wb_enc.c +++ b/lib_enc/amr_wb_enc.c @@ -59,7 +59,7 @@ void amr_wb_enc( int16_t i, delay, harm_flag; float old_inp[L_INP_12k8], *new_inp, *inp; /* buffer of old input signal */ float old_inp_16k[L_INP_12k8 + L_SUBFR], *inp_16k, *new_inp_16k; /* buffer of old input signal @16kHz*/ - float old_exc_flt[L_EXC], *exc; /* excitation signal buffer */ + float old_exc_flt[L_EXC], *exc; /* excitation signal buffer */ float old_wsp[L_WSP], *wsp; /* weighted input signal buffer */ int16_t input_frame; /* frame length at input sampling freq. */ float fr_bands[2 * NB_BANDS]; /* energy in frequency bands */ @@ -519,7 +519,6 @@ void amr_wb_enc( updt_enc_common( st ); - return; } diff --git a/lib_enc/amr_wb_enc_fx.c b/lib_enc/amr_wb_enc_fx.c index 7c468d561..3f5ddbb4b 100644 --- a/lib_enc/amr_wb_enc_fx.c +++ b/lib_enc/amr_wb_enc_fx.c @@ -3,16 +3,16 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_enc.h" /* Encoder static table prototypes */ -#include "rom_com_fx.h" /* Static table prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_enc.h" /* Encoder static table prototypes */ +#include "rom_com_fx.h" /* Static table prototypes */ //#include "prot_fx.h" /* Function prototypes */ #include "basop_util.h" -#include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "basop_util.h" /* Function prototypes */ +#include "rom_com.h" /* Common constants */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "basop_util.h" /* Function prototypes */ #include "prot_fx_enc.h" /*-------------------------------------------------------------------* @@ -22,40 +22,40 @@ *--------------------------------------------------------------------*/ void amr_wb_enc_fx( - Encoder_State *st, /* i/o: encoder state structure */ - const Word16 input_sp[], /* i : input signal */ - const Word16 n_samples /* i : number of input samples */ + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 input_sp[], /* i : input signal */ + const Word16 n_samples /* i : number of input samples */ ) { Word16 i, delay; - Word16 old_inp[L_INP_12k8], *new_inp, *inp; /* buffer of old input signal */ - Word16 old_inp_16k[L_INP_12k8+L_SUBFR], *inp_16k, *new_inp_16k;/* buffer of old input signal @16kHz*/ - Word16 old_exc[L_EXC], *exc; /* excitation signal buffer */ - Word16 old_wsp[L_WSP], *wsp; /* weighted input signal buffer */ - Word16 input_frame; /* frame length at input sampling freq. */ - Word32 fr_bands[2*NB_BANDS]; /* energy in frequency bands */ - Word32 lf_E[2*VOIC_BINS]; /* per bin spectrum energy in lf */ - Word32 tmpN[NB_BANDS]; /* temporary noise update */ - Word32 tmpE[NB_BANDS], PS[L_FFT/2]; /* temporary averaged energy of 2 sf. */ - Word16 corr_shift; /* correlation shift */ - Word16 relE; /* frame relative energy */ + Word16 old_inp[L_INP_12k8], *new_inp, *inp; /* buffer of old input signal */ + Word16 old_inp_16k[L_INP_12k8 + L_SUBFR], *inp_16k, *new_inp_16k; /* buffer of old input signal @16kHz*/ + Word16 old_exc[L_EXC], *exc; /* excitation signal buffer */ + Word16 old_wsp[L_WSP], *wsp; /* weighted input signal buffer */ + Word16 input_frame; /* frame length at input sampling freq. */ + Word32 fr_bands[2 * NB_BANDS]; /* energy in frequency bands */ + Word32 lf_E[2 * VOIC_BINS]; /* per bin spectrum energy in lf */ + Word32 tmpN[NB_BANDS]; /* temporary noise update */ + Word32 tmpE[NB_BANDS], PS[L_FFT / 2]; /* temporary averaged energy of 2 sf. */ + Word16 corr_shift; /* correlation shift */ + Word16 relE; /* frame relative energy */ Word16 cor_map_sum, sp_div; - Word16 Etot; /* total energy */ - Word32 ener = 0; /* residual energy from Levinson-Durbin */ - Word16 A[NB_SUBFR*(M+1)]; /* A(z) unquantized for the 4 subframes */ - Word16 Aw[NB_SUBFR*(M+1)]; /* A(z) unquantized for the 4 subframes */ + Word16 Etot; /* total energy */ + Word32 ener = 0; /* residual energy from Levinson-Durbin */ + Word16 A[NB_SUBFR * ( M + 1 )]; /* A(z) unquantized for the 4 subframes */ + Word16 Aw[NB_SUBFR * ( M + 1 )]; /* A(z) unquantized for the 4 subframes */ Word16 vad_hover_flag, noisy_speech_HO, clean_speech_HO, NB_speech_HO; - Word16 epsP_h[M+1]; /* LP prediction errors */ - Word16 epsP_l[M+1]; /* LP prediction errors */ - Word16 isp_new[M]; /* ISPs at the end of the frame */ - Word16 isf_new[M]; /* ISFs at the end of the frame */ + Word16 epsP_h[M + 1]; /* LP prediction errors */ + Word16 epsP_l[M + 1]; /* LP prediction errors */ + Word16 isp_new[M]; /* ISPs at the end of the frame */ + Word16 isf_new[M]; /* ISFs at the end of the frame */ Word16 isp_tmp[M]; - Word16 Aq[NB_SUBFR*(M+1)]; /* A(z) quantized for the 4 subframes */ - Word16 syn[L_FRAME]; /* synthesis vector */ - Word16 res[L_FRAME]; /* residual signal for FER protection */ - Word16 exc2[L_FRAME]; /* enhanced excitation */ - Word16 pitch_buf[NB_SUBFR]; /* floating pitch for each subframe */ - Word16 dummy_buf[L_FRAME32k]; /* dummy buffer - no usage */ + Word16 Aq[NB_SUBFR * ( M + 1 )]; /* A(z) quantized for the 4 subframes */ + Word16 syn[L_FRAME]; /* synthesis vector */ + Word16 res[L_FRAME]; /* residual signal for FER protection */ + Word16 exc2[L_FRAME]; /* enhanced excitation */ + Word16 pitch_buf[NB_SUBFR]; /* floating pitch for each subframe */ + Word16 dummy_buf[L_FRAME32k]; /* dummy buffer - no usage */ Word16 snr_sum_he; Word16 allow_cn_step; Word16 tmps; @@ -64,23 +64,23 @@ void amr_wb_enc_fx( Word16 localVAD_HE_SAD; Word16 vad_flag_dtx; Word16 hf_gain_fx[NB_SUBFR]; - Word16 Q_new, Q_exp,Q_r[2]; + Word16 Q_new, Q_exp, Q_r[2]; Word16 excitation_max_test, shift; Word32 Le_min_scaled; Word16 Q_sp_div; Word16 non_staX, Scale_fac[2]; Word16 sp_floor; - Word16 fft_buff[2*L_FFT]; + Word16 fft_buff[2 * L_FFT]; Word32 q_env[NUM_ENV_CNG]; Word16 sid_bw = 0; Word16 exc3[L_FRAME]; Word32 lp_bckr, hp_bckr, Ltmp; Word16 tmp, e_tmp; Word16 old_pitch1; - TD_CNG_ENC_HANDLE hTdCngEnc = st->hTdCngEnc; + TD_CNG_ENC_HANDLE hTdCngEnc = st->hTdCngEnc; NOISE_EST_HANDLE hNoiseEst = st->hNoiseEst; VAD_HANDLE hVAD = st->hVAD; - DTX_ENC_HANDLE hDtxEnc = st->hDtxEnc; + DTX_ENC_HANDLE hDtxEnc = st->hDtxEnc; LPD_state_HANDLE hLPDmem = st->hLPDmem; GSC_ENC_HANDLE hGSCEnc = st->hGSCEnc; AMRWB_IO_ENC_HANDLE hAmrwb_IO = st->hAmrwb_IO; @@ -106,14 +106,14 @@ void amr_wb_enc_fx( st->coder_type = GENERIC; move16(); input_frame = st->input_frame_fx; - move16(); /* frame length of the input signal */ + move16(); /* frame length of the input signal */ st->extl = -1; - st->encoderPastSamples_enc = (L_FRAME*9)/16; + st->encoderPastSamples_enc = ( L_FRAME * 9 ) / 16; st->encoderLookahead_enc = L_LOOK_12k8; st->bpf_off = 0; move16(); test(); - if( EQ_16(st->last_core,HQ_CORE)||EQ_16(st->last_codec_mode,MODE2)) + if ( EQ_16( st->last_core, HQ_CORE ) || EQ_16( st->last_codec_mode, MODE2 ) ) { st->bpf_off = 1; move16(); @@ -122,38 +122,38 @@ void amr_wb_enc_fx( move16(); /* Updates in case of EVS primary mode -> AMR-WB IO mode switching */ - IF( NE_16(st->last_core,AMR_WB_CORE)) + IF( NE_16( st->last_core, AMR_WB_CORE ) ) { - updt_IO_switch_enc_fx( st, input_frame); + updt_IO_switch_enc_fx( st, input_frame ); } /* Updates in case of HQ -> AMR-WB IO mode switching */ Q_new = 0; - move16(); /* prevent compiler warning only*/ + move16(); /* prevent compiler warning only*/ core_switching_pre_enc_fx( st, NULL, NULL, 0, 0 ); set16_fx( hf_gain_fx, 0, NB_SUBFR ); set16_fx( old_inp, 0, L_INP_12k8 ); - exc = old_exc + L_EXC_MEM; /* pointer to excitation signal in the current frame */ + exc = old_exc + L_EXC_MEM; /* pointer to excitation signal in the current frame */ Copy( hLPDmem->old_exc, old_exc, L_EXC_MEM ); - new_inp = old_inp + L_INP_MEM; /* pointer to new samples of the input signal */ - inp = new_inp - L_LOOK_12k8; /* pointer to current frame of input signal */ - wsp = old_wsp + L_WSP_MEM; /* pointer to current frame of weighted signal */ + new_inp = old_inp + L_INP_MEM; /* pointer to new samples of the input signal */ + inp = new_inp - L_LOOK_12k8; /* pointer to current frame of input signal */ + wsp = old_wsp + L_WSP_MEM; /* pointer to current frame of weighted signal */ Copy( st->old_inp_12k8_fx, old_inp, L_INP_MEM ); Copy( st->old_wsp_fx, old_wsp, L_WSP_MEM ); - new_inp_16k = old_inp_16k + L_INP_MEM; /* pointer to new samples of the input signal in 16kHz core */ - inp_16k = new_inp_16k - L_LOOK_16k; /* pointer to the current frame of input signal in 16kHz core */ + new_inp_16k = old_inp_16k + L_INP_MEM; /* pointer to new samples of the input signal in 16kHz core */ + inp_16k = new_inp_16k - L_LOOK_16k; /* pointer to the current frame of input signal in 16kHz core */ Copy( st->old_inp_16k_fx, old_inp_16k, L_INP_MEM ); /* in case of switching, reset AMR-WB BWE memories */ test(); - IF( EQ_32(st->total_brate,ACELP_23k85)&&NE_32(st->last_core_brate,ACELP_23k85)) + IF( EQ_32( st->total_brate, ACELP_23k85 ) && NE_32( st->last_core_brate, ACELP_23k85 ) ) { - hf_cod_init_fx(hAmrwb_IO->mem_hp400_enc_fx, hAmrwb_IO->mem_hf_enc_fx, hAmrwb_IO->mem_syn_hf_enc_fx, hAmrwb_IO->mem_hf2_enc_fx, &hAmrwb_IO->gain_alpha_fx ); + hf_cod_init_fx( hAmrwb_IO->mem_hp400_enc_fx, hAmrwb_IO->mem_hf_enc_fx, hAmrwb_IO->mem_syn_hf_enc_fx, hAmrwb_IO->mem_hf2_enc_fx, &hAmrwb_IO->gain_alpha_fx ); } /*----------------------------------------------------------------* @@ -161,9 +161,9 @@ void amr_wb_enc_fx( *----------------------------------------------------------------*/ /* get delay to synchronize ACELP and MDCT frame */ - delay = NS2SA_fx2(st->input_Fs, DELAY_FIR_RESAMPL_NS); + delay = NS2SA_fx2( st->input_Fs, DELAY_FIR_RESAMPL_NS ); - Copy( st->input_fx - delay, st->old_input_signal_fx, input_frame+delay ); + Copy( st->input_fx - delay, st->old_input_signal_fx, input_frame + delay ); /*----------------------------------------------------------------* * Buffering of input signal @@ -182,27 +182,27 @@ void amr_wb_enc_fx( * switching from ACELP@16k core to AMR-WB IO mode *-----------------------------------------------------------------*/ - st->rate_switching_reset=0; + st->rate_switching_reset = 0; move16(); test(); test(); - IF( NE_16(st->last_core,AMR_WB_CORE)&&EQ_16(st->last_L_frame,L_FRAME16k)&&NE_16(st->last_core,HQ_CORE)) + IF( NE_16( st->last_core, AMR_WB_CORE ) && EQ_16( st->last_L_frame, L_FRAME16k ) && NE_16( st->last_core, HQ_CORE ) ) { /* in case of switching, do not apply BPF */ st->bpf_off = 1; move16(); - st->rate_switching_reset=lsp_convert_poly_fx(st->lsp_old_fx, L_FRAME, 1); + st->rate_switching_reset = lsp_convert_poly_fx( st->lsp_old_fx, L_FRAME, 1 ); /* convert old quantized LSF vector */ lsp2lsf_fx( st->lsp_old_fx, st->lsf_old_fx, M, INT_FS_FX ); /* Reset LPC mem */ Copy( GEWB_Ave_fx, st->mem_AR_fx, M ); - set16_fx( st->mem_MA_fx,0, M ); + set16_fx( st->mem_MA_fx, 0, M ); /* update synthesis filter memories */ - synth_mem_updt2(L_FRAME, st->last_L_frame, hLPDmem->old_exc, hLPDmem->mem_syn_r, hLPDmem->mem_syn1_fx, hLPDmem->mem_syn, ENC); - Copy(hLPDmem->mem_syn1_fx, hLPDmem->mem_syn2, M); + synth_mem_updt2( L_FRAME, st->last_L_frame, hLPDmem->old_exc, hLPDmem->mem_syn_r, hLPDmem->mem_syn1_fx, hLPDmem->mem_syn, ENC ); + Copy( hLPDmem->mem_syn1_fx, hLPDmem->mem_syn2, M ); Copy( hLPDmem->old_exc, old_exc, L_EXC_MEM ); Copy( hLPDmem->mem_syn2, hLPDmem->mem_syn3, M ); @@ -210,19 +210,18 @@ void amr_wb_enc_fx( /* lsp -> isp */ Copy( stable_ISP_fx, isp_tmp, M ); lsp2isp_fx( st->lsp_old_fx, st->lsp_old_fx, isp_tmp, M ); - } /* update buffer of old subframe pitch values */ - IF( NE_16(st->last_L_frame,L_FRAME)) + IF( NE_16( st->last_L_frame, L_FRAME ) ) { move16(); - IF( EQ_16(st->last_L_frame,L_FRAME32k)) + IF( EQ_16( st->last_L_frame, L_FRAME32k ) ) { /* (float)12800/(float)32000; */ tmp = 13107; } - ELSE IF( EQ_16(st->last_L_frame,512)) + ELSE IF( EQ_16( st->last_L_frame, 512 ) ) { /* (float)12800/(float)25600; */ tmp = 16384; @@ -233,23 +232,23 @@ void amr_wb_enc_fx( tmp = 26214; } - FOR( i=NB_SUBFR16k-NB_SUBFR; iold_pitch_buf_fx[i-1] = mult_r(tmp, st->old_pitch_buf_fx[i]); + st->old_pitch_buf_fx[i - 1] = mult_r( tmp, st->old_pitch_buf_fx[i] ); move16(); } - FOR( i=2*NB_SUBFR16k-NB_SUBFR; i<2*NB_SUBFR16k; i++ ) + FOR( i = 2 * NB_SUBFR16k - NB_SUBFR; i < 2 * NB_SUBFR16k; i++ ) { - st->old_pitch_buf_fx[i-2] = mult_r(tmp, st->old_pitch_buf_fx[i]); + st->old_pitch_buf_fx[i - 2] = mult_r( tmp, st->old_pitch_buf_fx[i] ); move16(); } } test(); - if( EQ_16(st->last_bwidth,NB)&&st->ini_frame !=0) + if ( EQ_16( st->last_bwidth, NB ) && st->ini_frame != 0 ) { - st->rate_switching_reset=1; + st->rate_switching_reset = 1; move16(); } @@ -260,8 +259,8 @@ void amr_wb_enc_fx( modify_Fs_fx( st->input_fx, input_frame, st->input_Fs, new_inp, 12800, st->mem_decim_fx, 0 ); /* update signal buffer */ - Copy( new_inp, st->buf_speech_enc+L_FRAME, L_FRAME ); - Scale_sig( st->buf_speech_enc+L_FRAME, L_FRAME, 1 ); + Copy( new_inp, st->buf_speech_enc + L_FRAME, L_FRAME ); + Scale_sig( st->buf_speech_enc + L_FRAME, L_FRAME, 1 ); /*------------------------------------------------------------------* * Perform fixed preemphasis through 1 - g*z^-1 @@ -269,17 +268,17 @@ void amr_wb_enc_fx( Preemph_scaled( new_inp, &Q_new, &st->mem_preemph_fx, st->Q_max, PREEMPH_FAC, 0, 1, L_Q_MEM, L_FRAME, st->last_coder_type, 1 ); - Q_exp = sub(Q_new, st->Q_old); + Q_exp = sub( Q_new, st->Q_old ); move16(); st->Q_old = Q_new; move16(); - Le_min_scaled = Scale_mem_pre_proc( st->ini_frame, Q_exp, &Q_new, old_inp, &(st->mem_wsp_fx), hNoiseEst->enrO_fx, hNoiseEst->bckr_fx, hNoiseEst->ave_enr_fx, - hNoiseEst->ave_enr2_fx, hNoiseEst->fr_bands1_fx, hNoiseEst->fr_bands2_fx, st->Bin_E_old_fx ); + Le_min_scaled = Scale_mem_pre_proc( st->ini_frame, Q_exp, &Q_new, old_inp, &( st->mem_wsp_fx ), hNoiseEst->enrO_fx, hNoiseEst->bckr_fx, hNoiseEst->ave_enr_fx, + hNoiseEst->ave_enr2_fx, hNoiseEst->fr_bands1_fx, hNoiseEst->fr_bands2_fx, st->Bin_E_old_fx ); - Q_exp = sub(Q_new, st->prev_Q_new); + Q_exp = sub( Q_new, st->prev_Q_new ); move16(); - Scale_mem_enc( Q_exp, old_inp_16k, old_exc, hBWE_TD->old_bwe_exc_fx, &(hLPDmem->mem_w0), hLPDmem->mem_syn, hLPDmem->mem_syn2, + Scale_mem_enc( Q_exp, old_inp_16k, old_exc, hBWE_TD->old_bwe_exc_fx, &( hLPDmem->mem_w0 ), hLPDmem->mem_syn, hLPDmem->mem_syn2, &st->mem_deemp_preQ_fx, hGSCEnc->last_exc_dct_in_fx, hBWE_FD->old_input_lp_fx ); /*----------------------------------------------------------------* @@ -288,44 +287,43 @@ void amr_wb_enc_fx( * Detect NB spectrum in a 16kHz-sampled input *----------------------------------------------------------------*/ - analy_sp_fx(st->element_mode, + analy_sp_fx( st->element_mode, #ifdef IVAS_CODE_CPE - hCPE, + hCPE, #endif - st->input_Fs, inp, Q_new, fr_bands, lf_E, & Etot, st->min_band, st->max_band, Le_min_scaled, Scale_fac, st->Bin_E_fx, - st->Bin_E_old_fx, PS, st->lgBin_E_fx, st->band_energies, fft_buff ); + st->input_Fs, inp, Q_new, fr_bands, lf_E, &Etot, st->min_band, st->max_band, Le_min_scaled, Scale_fac, st->Bin_E_fx, + st->Bin_E_old_fx, PS, st->lgBin_E_fx, st->band_energies, fft_buff ); - noise_est_pre_fx( Etot, st->ini_frame, hNoiseEst, 0, EVS_MONO, EVS_MONO); + noise_est_pre_fx( Etot, st->ini_frame, hNoiseEst, 0, EVS_MONO, EVS_MONO ); /*----------------------------------------------------------------* * VAD *----------------------------------------------------------------*/ st->vad_flag = wb_vad_fx( st, fr_bands, &noisy_speech_HO, &clean_speech_HO, &NB_speech_HO, - &snr_sum_he, &localVAD_HE_SAD, &(st->flag_noisy_speech_snr_fx), Q_new - , hVAD,hNoiseEst, st->lp_speech_fx, st->lp_noise_fx ) ; + &snr_sum_he, &localVAD_HE_SAD, &( st->flag_noisy_speech_snr_fx ), Q_new, hVAD, hNoiseEst, st->lp_speech_fx, st->lp_noise_fx ); - if (st->vad_flag == 0 ) + if ( st->vad_flag == 0 ) { st->coder_type = INACTIVE; move16(); } /* apply DTX hangover for CNG analysis */ - vad_flag_dtx = dtx_hangover_addition_fx( st, st->vad_flag, sub(st->lp_speech_fx, st->lp_noise_fx), 0, &vad_hover_flag, NULL, NULL); + vad_flag_dtx = dtx_hangover_addition_fx( st, st->vad_flag, sub( st->lp_speech_fx, st->lp_noise_fx ), 0, &vad_hover_flag, NULL, NULL ); /*-----------------------------------------------------------------* * Select SID or FRAME_NO_DATA frame if DTX enabled *-----------------------------------------------------------------*/ - IF ( NE_16(st->last_core,AMR_WB_CORE)) + IF( NE_16( st->last_core, AMR_WB_CORE ) ) { st->fd_cng_reset_flag = 1; move16(); } - ELSE IF ( s_and((st->fd_cng_reset_flag > 0),(Word16)(LT_16(st->fd_cng_reset_flag,10)))) + ELSE IF( s_and( ( st->fd_cng_reset_flag > 0 ), (Word16) ( LT_16( st->fd_cng_reset_flag, 10 ) ) ) ) { - st->fd_cng_reset_flag = add(st->fd_cng_reset_flag,1); + st->fd_cng_reset_flag = add( st->fd_cng_reset_flag, 1 ); } ELSE { @@ -346,44 +344,45 @@ void amr_wb_enc_fx( high_lpn_flag = 0; move16(); /* Q0 flag */ - long_enr_fx( st, Etot, localVAD_HE_SAD, high_lpn_flag + long_enr_fx( st, Etot, localVAD_HE_SAD, high_lpn_flag #ifdef IVAS_CODE - , NULL, 1, NULL, NULL + , + NULL, 1, NULL, NULL #endif - ); - relE = sub(Etot, st->lp_speech_fx); /* Q8 */ + ); + relE = sub( Etot, st->lp_speech_fx ); /* Q8 */ - IF( NE_16(st->bwidth, NB)) + IF( NE_16( st->bwidth, NB ) ) { - lp_bckr = Mean32(hNoiseEst->bckr_fx, 10 ); + lp_bckr = Mean32( hNoiseEst->bckr_fx, 10 ); } ELSE { - lp_bckr = Mean32(hNoiseEst->bckr_fx+1, 9 ); + lp_bckr = Mean32( hNoiseEst->bckr_fx + 1, 9 ); } #ifdef BASOP_NOGLOB hp_bckr = L_shr( L_add_sat( hNoiseEst->bckr_fx[st->max_band - 1], hNoiseEst->bckr_fx[st->max_band] ), 1 ); #else - hp_bckr = L_shr(L_add(hNoiseEst->bckr_fx[st->max_band -1] , hNoiseEst->bckr_fx[st->max_band]),1); + hp_bckr = L_shr( L_add( hNoiseEst->bckr_fx[st->max_band - 1], hNoiseEst->bckr_fx[st->max_band] ), 1 ); #endif - if( hp_bckr == 0 ) /* Avoid division by zero. */ + if ( hp_bckr == 0 ) /* Avoid division by zero. */ { - hp_bckr = L_deposit_l(1); + hp_bckr = L_deposit_l( 1 ); } tmp = BASOP_Util_Divide3232_Scale( lp_bckr, hp_bckr, &e_tmp ); Ltmp = L_shr_r( L_deposit_h( tmp ), sub( 15, e_tmp ) ); st->bckr_tilt_lt = L_add( Mpy_32_16_r( st->bckr_tilt_lt, 29491 ), Mpy_32_16_r( Ltmp, 3277 ) ); - corr_shift = correlation_shift_fx(hNoiseEst->totalNoise_fx ); + corr_shift = correlation_shift_fx( hNoiseEst->totalNoise_fx ); /*----------------------------------------------------------------* * WB, SWB and FB bandwidth detector *----------------------------------------------------------------*/ - bw_detect_fx( st, st->input_fx, NULL, NULL, NULL, MONO_FORMAT, 0); + bw_detect_fx( st, st->input_fx, NULL, NULL, NULL, MONO_FORMAT, 0 ); /* in AMR_WB IO, limit the maximum band-width to WB */ - if( GT_16(st->bwidth,WB)) + if ( GT_16( st->bwidth, WB ) ) { st->bwidth = WB; move16(); @@ -396,10 +395,10 @@ void amr_wb_enc_fx( * Perform 1/4 pitch precision improvement *----------------------------------------------------------------*/ - IF (st->vad_flag == 0 ) + IF( st->vad_flag == 0 ) { /* reset the OL pitch tracker memories during inactive frames */ - pitch_ol_init_fx( &st->old_thres_fx, &st->old_pitch, &st->delta_pit, &st->old_corr_fx) ; + pitch_ol_init_fx( &st->old_thres_fx, &st->old_pitch, &st->delta_pit, &st->old_corr_fx ); } old_pitch1 = st->pitch_fx[1]; move16(); @@ -407,18 +406,18 @@ void amr_wb_enc_fx( isf_new, st->old_pitch_la, st->old_voicing_la, Q_new, Q_r ); find_wsp_fx( A, inp, wsp, &st->mem_wsp_fx, TILT_FAC_FX, L_FRAME, L_LOOK_12k8, L_SUBFR, Aw, GAMMA1, NB_SUBFR ); - Scale_wsp( wsp, &(st->old_wsp_max), &shift, &Q_exp, &(st->old_wsp_shift), - st->old_wsp2_fx, st->mem_decim2_fx, st->old_wsp_fx, add(L_FRAME, L_LOOK_12k8)); + Scale_wsp( wsp, &( st->old_wsp_max ), &shift, &Q_exp, &( st->old_wsp_shift ), + st->old_wsp2_fx, st->mem_decim2_fx, st->old_wsp_fx, add( L_FRAME, L_LOOK_12k8 ) ); excitation_max_test = -32768; move16(); - FOR (i = 0; i < L_EXC_MEM; i++) + FOR( i = 0; i < L_EXC_MEM; i++ ) { - excitation_max_test = s_max(abs_s(old_exc[i]),excitation_max_test); + excitation_max_test = s_max( abs_s( old_exc[i] ), excitation_max_test ); } test(); - if( GT_16(excitation_max_test,8192)&&shift==0) + if ( GT_16( excitation_max_test, 8192 ) && shift == 0 ) { shift = -1; move16(); @@ -430,19 +429,19 @@ void amr_wb_enc_fx( move16(); /* VAD parameters update */ - vad_param_updt_fx( st, old_pitch1 , corr_shift, corr_shift, A, NULL, 1 ); + vad_param_updt_fx( st, old_pitch1, corr_shift, corr_shift, A, NULL, 1 ); /*------------------------------------------------------------------* * Update estimated noise energy and voicing cut-off frequency *-----------------------------------------------------------------*/ noise_est_fx( st, old_pitch1, tmpN, epsP_h, epsP_l, Etot, relE, corr_shift, tmpE, fr_bands, &cor_map_sum, - NULL, &sp_div, &Q_sp_div, &non_staX, &harm_flag, - lf_E, &hNoiseEst->harm_cor_cnt, hNoiseEst->Etot_l_lp_fx, hNoiseEst->Etot_v_h2_fx, &hNoiseEst->bg_cnt, st->lgBin_E_fx, Q_new, Le_min_scaled, &sp_floor, NULL, + NULL, &sp_div, &Q_sp_div, &non_staX, &harm_flag, + lf_E, &hNoiseEst->harm_cor_cnt, hNoiseEst->Etot_l_lp_fx, hNoiseEst->Etot_v_h2_fx, &hNoiseEst->bg_cnt, st->lgBin_E_fx, Q_new, Le_min_scaled, &sp_floor, NULL, #ifdef IVAS_CODE - NULL, NULL, + NULL, NULL, #endif - st->ini_frame); + st->ini_frame ); /*----------------------------------------------------------------* * Change the sampling frequency to 16 kHz, @@ -450,15 +449,15 @@ void amr_wb_enc_fx( *----------------------------------------------------------------*/ test(); - IF( EQ_32(st->input_Fs, 16000)) + IF( EQ_32( st->input_Fs, 16000 ) ) { /* no resampling needed, only delay adjustement to account for the FIR resampling delay */ - tmps = NS2SA_fx2(16000, DELAY_FIR_RESAMPL_NS); - Copy_Scale_sig( &st->mem_decim16k_fx[tmps], new_inp_16k, tmps, -1 ); /* Input in Q0 -> Output in Q-1 to mimic the resampling filter */ - Copy_Scale_sig( st->input_fx, new_inp_16k + tmps, sub(input_frame, tmps), -1 ); /* Input in Q0 -> Output in Q-1 to mimic the resampling filter */ - Copy( st->input_fx + input_frame - shl(tmps,1), st->mem_decim16k_fx, shl(tmps,1) ); /* memory still in Q0 */ + tmps = NS2SA_fx2( 16000, DELAY_FIR_RESAMPL_NS ); + Copy_Scale_sig( &st->mem_decim16k_fx[tmps], new_inp_16k, tmps, -1 ); /* Input in Q0 -> Output in Q-1 to mimic the resampling filter */ + Copy_Scale_sig( st->input_fx, new_inp_16k + tmps, sub( input_frame, tmps ), -1 ); /* Input in Q0 -> Output in Q-1 to mimic the resampling filter */ + Copy( st->input_fx + input_frame - shl( tmps, 1 ), st->mem_decim16k_fx, shl( tmps, 1 ) ); /* memory still in Q0 */ } - ELSE IF( EQ_32(st->input_Fs, 32000)||EQ_32(st->input_Fs,48000)) + ELSE IF( EQ_32( st->input_Fs, 32000 ) || EQ_32( st->input_Fs, 48000 ) ) { modify_Fs_fx( st->input_fx, input_frame, st->input_Fs, new_inp_16k, 16000, st->mem_decim16k_fx, 0 ); } @@ -468,18 +467,18 @@ void amr_wb_enc_fx( *----------------------------------------------------------------*/ test(); - IF ( EQ_32(st->core_brate,SID_1k75)||EQ_32(st->core_brate,FRAME_NO_DATA)) + IF( EQ_32( st->core_brate, SID_1k75 ) || EQ_32( st->core_brate, FRAME_NO_DATA ) ) { /* encode CNG parameters */ - CNG_enc_fx( st, Aq, inp, ener, isp_new, isp_new, isf_new , &allow_cn_step, sub(Q_new,1), q_env, &sid_bw ); + CNG_enc_fx( st, Aq, inp, ener, isp_new, isp_new, isf_new, &allow_cn_step, sub( Q_new, 1 ), q_env, &sid_bw ); /* comfort noise generation */ CNG_exc_fx( st->core_brate, L_FRAME, &hTdCngEnc->Enew_fx, &hTdCngEnc->cng_seed, exc, exc2, &hTdCngEnc->lp_ener_fx, st->last_core_brate, &hDtxEnc->first_CNG, &hTdCngEnc->cng_ener_seed, dummy_buf, allow_cn_step, - &hTdCngEnc->last_allow_cn_step, sub(st->prev_Q_new,1), sub(Q_new,1), hTdCngEnc->num_ho, q_env, hTdCngEnc->lp_env_fx, - hTdCngEnc->old_env_fx, hTdCngEnc->exc_mem_fx, hTdCngEnc->exc_mem1_fx, &sid_bw, &hTdCngEnc->cng_ener_seed1, exc3, st->Opt_AMR_WB, st->element_mode); + &hTdCngEnc->last_allow_cn_step, sub( st->prev_Q_new, 1 ), sub( Q_new, 1 ), hTdCngEnc->num_ho, q_env, hTdCngEnc->lp_env_fx, + hTdCngEnc->old_env_fx, hTdCngEnc->exc_mem_fx, hTdCngEnc->exc_mem1_fx, &sid_bw, &hTdCngEnc->cng_ener_seed1, exc3, st->Opt_AMR_WB, st->element_mode ); - if (hDtxEnc->first_CNG == 0 ) + if ( hDtxEnc->first_CNG == 0 ) { hDtxEnc->first_CNG = 1; move16(); @@ -489,10 +488,10 @@ void amr_wb_enc_fx( syn_12k8_fx( L_FRAME, Aq, exc2, dummy_buf, hLPDmem->mem_syn3, 1, Q_new, st->Q_syn ); /* reset the encoder */ - CNG_reset_enc_fx( st, hLPDmem, pitch_buf, dummy_buf+L_FRAME, 0 ); + CNG_reset_enc_fx( st, hLPDmem, pitch_buf, dummy_buf + L_FRAME, 0 ); /* update st->mem_syn1 for ACELP core switching */ - Copy(hLPDmem->mem_syn3, hLPDmem->mem_syn1_fx, M); + Copy( hLPDmem->mem_syn3, hLPDmem->mem_syn1_fx, M ); /* update ACELP core synthesis filter memory */ Copy( hLPDmem->mem_syn3, hLPDmem->mem_syn, M ); @@ -500,9 +499,8 @@ void amr_wb_enc_fx( /* update old synthesis buffer - needed for ACELP internal sampling rate switching */ Copy( dummy_buf + L_FRAME - L_SYN_MEM, hLPDmem->mem_syn_r, L_SYN_MEM ); /* Update MODE2 core switching memory */ - E_UTIL_deemph2( sub(Q_new,1), dummy_buf, PREEMPH_FAC, L_FRAME, &(hLPDmem->syn[M]) ); - Copy( dummy_buf+L_FRAME-M-1, hLPDmem->syn, M+1 ); - + E_UTIL_deemph2( sub( Q_new, 1 ), dummy_buf, PREEMPH_FAC, L_FRAME, &( hLPDmem->syn[M] ) ); + Copy( dummy_buf + L_FRAME - M - 1, hLPDmem->syn, M + 1 ); } /*----------------------------------------------------------------* @@ -515,10 +513,10 @@ void amr_wb_enc_fx( * After inactive period, use the most up-to-date ISPs *-----------------------------------------------------------------*/ test(); - IF( EQ_32(st->last_core_brate,FRAME_NO_DATA)||EQ_32(st->last_core_brate,SID_1k75)) + IF( EQ_32( st->last_core_brate, FRAME_NO_DATA ) || EQ_32( st->last_core_brate, SID_1k75 ) ) { - Copy(hDtxEnc->lspCNG_fx, st->lsp_old_fx, M ); - E_LPC_isp_isf_conversion(hDtxEnc->lspCNG_fx, st->lsf_old_fx, M); + Copy( hDtxEnc->lspCNG_fx, st->lsp_old_fx, M ); + E_LPC_isp_isf_conversion( hDtxEnc->lspCNG_fx, st->lsf_old_fx, M ); set16_fx( old_exc, 0, L_EXC_MEM ); } @@ -526,14 +524,14 @@ void amr_wb_enc_fx( * ISF Quantization and interpolation *-----------------------------------------------------------------*/ - isf_enc_amr_wb_fx( st, isf_new, isp_new, Aq); + isf_enc_amr_wb_fx( st, isf_new, isp_new, Aq ); /*---------------------------------------------------------------* * Calculation of LP residual (filtering through A[z] filter) *---------------------------------------------------------------*/ - calc_residu_fx(st, inp, res, Aq); - if (hTdCngEnc != NULL) + calc_residu_fx( st, inp, res, Aq ); + if ( hTdCngEnc != NULL ) { hTdCngEnc->burst_ho_cnt = 0; } @@ -553,8 +551,8 @@ void amr_wb_enc_fx( Copy( syn + L_FRAME - L_SYN_MEM, hLPDmem->mem_syn_r, L_SYN_MEM ); /* Update MODE2 core switching memory */ - E_UTIL_deemph2( sub(Q_new,1), syn, PREEMPH_FAC, L_FRAME, &(hLPDmem->syn[M]) ); - Copy( syn+L_FRAME-M-1, hLPDmem->syn, M+1 ); + E_UTIL_deemph2( sub( Q_new, 1 ), syn, PREEMPH_FAC, L_FRAME, &( hLPDmem->syn[M] ) ); + Copy( syn + L_FRAME - M - 1, hLPDmem->syn, M + 1 ); /*--------------------------------------------------------------------------------------* * Write VAD information into the bitstream in AMR-WB IO mode @@ -574,7 +572,7 @@ void amr_wb_enc_fx( Copy( &old_inp[L_FRAME], st->old_inp_12k8_fx, L_INP_MEM ); /* update old input signal @16kHz buffer */ - IF( GT_32(st->input_Fs,8000)) + IF( GT_32( st->input_Fs, 8000 ) ) { Copy( &old_inp_16k[L_FRAME16k], st->old_inp_16k_fx, L_INP_MEM ); } @@ -587,14 +585,14 @@ void amr_wb_enc_fx( st->last_bwidth = st->bwidth; /* update signal buffers */ - Copy( new_inp, st->buf_speech_enc_pe+L_FRAME, L_FRAME ); - Copy( wsp, st->buf_wspeech_enc+L_FRAME+L_SUBFR, L_FRAME + L_LOOK_12k8 ); + Copy( new_inp, st->buf_speech_enc_pe + L_FRAME, L_FRAME ); + Copy( wsp, st->buf_wspeech_enc + L_FRAME + L_SUBFR, L_FRAME + L_LOOK_12k8 ); updt_enc_fx( st, old_exc, pitch_buf, 0, Aq, isf_new, isp_new, dummy_buf ); /* update main codec parameters */ - updt_enc_common_fx(st, Etot, Q_new); + updt_enc_common_fx( st, Etot, Q_new ); #ifdef MY_DEBUG - dbgwrite_indices(st); + dbgwrite_indices( st ); #endif return; } @@ -614,13 +612,13 @@ void amr_wb_enc_init_fx( hAmrwb_IO->seed2_enc = RANDOM_INITSEED; move16(); - FOR (i = 0; i < GAIN_PRED_ORDER; i++) + FOR( i = 0; i < GAIN_PRED_ORDER; i++ ) { - hAmrwb_IO->past_qua_en_fx[i] = -14336; /* Q10gain quantization memory (used also in AMR-WB IO mode) */ + hAmrwb_IO->past_qua_en_fx[i] = -14336; /* Q10gain quantization memory (used also in AMR-WB IO mode) */ move16(); } - hf_cod_init_fx(hAmrwb_IO->mem_hp400_enc_fx, hAmrwb_IO->mem_hf_enc_fx, hAmrwb_IO->mem_syn_hf_enc_fx, hAmrwb_IO->mem_hf2_enc_fx, &hAmrwb_IO->gain_alpha_fx); + hf_cod_init_fx( hAmrwb_IO->mem_hp400_enc_fx, hAmrwb_IO->mem_hf_enc_fx, hAmrwb_IO->mem_syn_hf_enc_fx, hAmrwb_IO->mem_hf2_enc_fx, &hAmrwb_IO->gain_alpha_fx ); return; } diff --git a/lib_enc/analy_lp_fx.c b/lib_enc/analy_lp_fx.c index cd24dbfbf..51c40ec5e 100644 --- a/lib_enc/analy_lp_fx.c +++ b/lib_enc/analy_lp_fx.c @@ -3,15 +3,15 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ +#include "options.h" /* Compilation switches */ #include "cnst.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ +#include "rom_com_fx.h" /* Static table prototypes */ #include "rom_com.h" /* Static table prototypes */ #include "rom_enc.h" /* Static table prototypes */ //#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* * analy_lp() @@ -26,34 +26,33 @@ *-------------------------------------------------------------------*/ void analy_lp_fx( - const Word16 speech[], /* i : pointer to the speech frame */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 L_look, /* i : look-ahead */ - Word32 *ener, /* o : residual energy from Levinson-Durbin */ - Word16 A[], /* o : A(z) filter coefficients */ - Word16 epsP_h[], /* o : LP analysis residual energies for each iteration */ - Word16 epsP_l[], /* o : LP analysis residual energies for each iteration */ - Word16 lsp_new[], /* o : current frame LSPs */ - Word16 lsp_mid[], /* o : current mid-frame LSPs */ - Word16 lsp_old[], /* i/o: previous frame unquantized LSPs */ - const Word16 Top[2], /* i : open loop pitch lag */ - const Word16 Tnc[2], /* i : open loop pitch gain */ - const Word32 Core_sr, /* i : Internal core sampling rate */ - const Word16 sec_chan_low_rate, /* i : flag to signal second channel */ + const Word16 speech[], /* i : pointer to the speech frame */ + const Word16 L_frame, /* i : length of the frame */ + const Word16 L_look, /* i : look-ahead */ + Word32 *ener, /* o : residual energy from Levinson-Durbin */ + Word16 A[], /* o : A(z) filter coefficients */ + Word16 epsP_h[], /* o : LP analysis residual energies for each iteration */ + Word16 epsP_l[], /* o : LP analysis residual energies for each iteration */ + Word16 lsp_new[], /* o : current frame LSPs */ + Word16 lsp_mid[], /* o : current mid-frame LSPs */ + Word16 lsp_old[], /* i/o: previous frame unquantized LSPs */ + const Word16 Top[2], /* i : open loop pitch lag */ + const Word16 Tnc[2], /* i : open loop pitch gain */ + const Word32 Core_sr, /* i : Internal core sampling rate */ + const Word16 sec_chan_low_rate, /* i : flag to signal second channel */ Word16 Q_new, - Word16 *Q_r -) + Word16 *Q_r ) { - Word16 r_h[M+1]; /* Autocorrelations of windowed speech MSB */ - Word16 r_l[M+1]; /* Autocorrelations of windowed speech LSB */ - Word32 LepsP[M+1]; + Word16 r_h[M + 1]; /* Autocorrelations of windowed speech MSB */ + Word16 r_l[M + 1]; /* Autocorrelations of windowed speech LSB */ + Word32 LepsP[M + 1]; Word16 i, i_subfr, wind_length = 0; Word16 *lsp; const Word16 *wind = NULL; const Word16 *pt; Word16 half_frame; - IF( EQ_16(L_frame,L_FRAME)) + IF( EQ_16( L_frame, L_FRAME ) ) { wind_length = L_LP; move16(); @@ -66,27 +65,27 @@ void analy_lp_fx( wind = assym_window_16k_fx; } lsp = lsp_mid; - half_frame = shr(L_frame,1); + half_frame = shr( L_frame, 1 ); FOR( i_subfr = 0; i_subfr <= 1; i_subfr++ ) { - pt = speech + sub(add(half_frame, L_look), wind_length); - half_frame = shl(half_frame,1); + pt = speech + sub( add( half_frame, L_look ), wind_length ); + half_frame = shl( half_frame, 1 ); /* Autocorrelations */ - autocorr_fx(pt, M, r_h, r_l, &Q_r[1-i_subfr], wind_length, wind, 0, 0 ); + autocorr_fx( pt, M, r_h, r_l, &Q_r[1 - i_subfr], wind_length, wind, 0, 0 ); /* Lag windowing */ adapt_lag_wind( r_h, r_l, M, Top[i_subfr], Tnc[i_subfr], Core_sr ); /* Levinson-Durbin */ - E_LPC_lev_dur(r_h, r_l, A, LepsP, M, NULL); - FOR (i = 0; i <= M; i++) + E_LPC_lev_dur( r_h, r_l, A, LepsP, M, NULL ); + FOR( i = 0; i <= M; i++ ) { - L_Extract(LepsP[i], &epsP_h[i], &epsP_l[i]); + L_Extract( LepsP[i], &epsP_h[i], &epsP_l[i] ); } /*Q_r[... might not be needed from external...*/ - Q_r[1-i_subfr] = add(Q_r[1-i_subfr], shl(Q_new, 1)); + Q_r[1 - i_subfr] = add( Q_r[1 - i_subfr], shl( Q_new, 1 ) ); move16(); /* Conversion of A(z) to LSPs */ @@ -94,22 +93,21 @@ void analy_lp_fx( lsp = lsp_new; } - IF (EQ_16(sec_chan_low_rate, 1) ) + IF( EQ_16( sec_chan_low_rate, 1 ) ) { /* LSP interpolation */ - int_lsp4_fx(L_frame, lsp_old, lsp_mid, lsp_new, A, M, -2); + int_lsp4_fx( L_frame, lsp_old, lsp_mid, lsp_new, A, M, -2 ); } ELSE { /* LSP interpolation */ - int_lsp4_fx(L_frame, lsp_old, lsp_mid, lsp_new, A, M, 0); + int_lsp4_fx( L_frame, lsp_old, lsp_mid, lsp_new, A, M, 0 ); } - Copy (lsp_new, lsp_old, M); - *ener = L_Comp(epsP_h[M],epsP_l[M]); + Copy( lsp_new, lsp_old, M ); + *ener = L_Comp( epsP_h[M], epsP_l[M] ); move32(); return; - } @@ -126,23 +124,22 @@ void analy_lp_fx( *-------------------------------------------------------------------*/ void analy_lp_AMR_WB_fx( - const Word16 speech[], /* i : pointer to the speech frame */ - Word32 *ener, /* o : residual energy from Levinson-Durbin */ - Word16 A[], /* o : A(z) filter coefficients */ - Word16 epsP_h[], /* o : LP analysis residual energies for each iteration */ - Word16 epsP_l[], /* o : LP analysis residual energies for each iteration */ - Word16 isp_new[], /* o : current frame ISPs */ - Word16 isp_old[], /* i/o: previous frame unquantized ISPs */ - Word16 isf_new[], /* o : current frame ISPs */ - Word16 Top, /* i : open loop pitch lag */ - Word16 Tnc, /* i : open loop pitch gain */ + const Word16 speech[], /* i : pointer to the speech frame */ + Word32 *ener, /* o : residual energy from Levinson-Durbin */ + Word16 A[], /* o : A(z) filter coefficients */ + Word16 epsP_h[], /* o : LP analysis residual energies for each iteration */ + Word16 epsP_l[], /* o : LP analysis residual energies for each iteration */ + Word16 isp_new[], /* o : current frame ISPs */ + Word16 isp_old[], /* i/o: previous frame unquantized ISPs */ + Word16 isf_new[], /* o : current frame ISPs */ + Word16 Top, /* i : open loop pitch lag */ + Word16 Tnc, /* i : open loop pitch gain */ Word16 Q_new, - Word16 *Q_r -) + Word16 *Q_r ) { - Word16 r_h[M+1]; /* Autocorrelations of windowed speech MSB */ - Word16 r_l[M+1]; /* Autocorrelations of windowed speech LSB */ - Word32 LepsP[M+1]; + Word16 r_h[M + 1]; /* Autocorrelations of windowed speech MSB */ + Word16 r_l[M + 1]; /* Autocorrelations of windowed speech LSB */ + Word32 LepsP[M + 1]; Word16 i, wind_length = 0; const Word16 *wind; @@ -159,13 +156,13 @@ void analy_lp_AMR_WB_fx( /* Levinson-Durbin */ /*lev_dur( A, r, M, epsP );*/ - E_LPC_lev_dur(r_h, r_l, A, LepsP, M, NULL); - FOR (i = 0; i <= M; i++) + E_LPC_lev_dur( r_h, r_l, A, LepsP, M, NULL ); + FOR( i = 0; i <= M; i++ ) { - L_Extract(LepsP[i], &epsP_h[i], &epsP_l[i]); + L_Extract( LepsP[i], &epsP_h[i], &epsP_l[i] ); } /*Q_r[... might not be needed from external...*/ - Q_r[0] = add(Q_r[0], shl(Q_new, 1)); + Q_r[0] = add( Q_r[0], shl( Q_new, 1 ) ); move16(); E_LPC_a_lsf_isf_conversion( A, isf_new, stable_ISF_fx, M, 0 ); @@ -175,7 +172,7 @@ void analy_lp_AMR_WB_fx( int_lsp_fx( L_FRAME, isp_old, isp_new, A, M, interpol_isp_amr_wb_fx, 1 ); /**ener = epsP[M];*/ - *ener = L_Comp(epsP_h[M],epsP_l[M]); + *ener = L_Comp( epsP_h[M], epsP_l[M] ); move32(); /* updates */ diff --git a/lib_enc/analy_sp_fx.c b/lib_enc/analy_sp_fx.c index a1c7a4427..fd96bfe4e 100644 --- a/lib_enc/analy_sp_fx.c +++ b/lib_enc/analy_sp_fx.c @@ -7,9 +7,9 @@ #include "cnst.h" #include "basop_util.h" //#include "prot_fx.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ #include "rom_enc.h" #include "rom_com.h" #include @@ -18,11 +18,10 @@ * Local prototypes *-------------------------------------------------------------------*/ -static void find_enr( Word16 data[], Word32 band[], Word32 *ptE, Word32 *LEtot, const Word16 min_band, const Word16 max_band, - const Word16 Q_new2, const Word32 e_min, Word32 *Bin_E, Word16 BIN_FREQ_FX, Word32 *band_energies ); +static void find_enr( Word16 data[], Word32 band[], Word32 *ptE, Word32 *LEtot, const Word16 min_band, const Word16 max_band, const Word16 Q_new2, const Word32 e_min, Word32 *Bin_E, Word16 BIN_FREQ_FX, Word32 *band_energies ); #ifdef IVAS_CODE_CPE -static void find_enr_dft(CPE_ENC_HANDLE hCPE, const int32_t input_Fs, float DFT_past_DMX[], float band[], float* ptE, float* Etot, const int16_t min_band, const int16_t max_band, float* Bin_E, float* band_ener); +static void find_enr_dft( CPE_ENC_HANDLE hCPE, const int32_t input_Fs, float DFT_past_DMX[], float band[], float *ptE, float *Etot, const int16_t min_band, const int16_t max_band, float *Bin_E, float *band_ener ); #endif /*-------------------------------------------------------------------* @@ -34,24 +33,24 @@ static void find_enr_dft(CPE_ENC_HANDLE hCPE, const int32_t input_Fs, float DFT_ void analy_sp_fx( const Word16 element_mode, /* i : element mode */ #ifdef IVAS_CODE_CPE - CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ + CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ #endif - const Word32 input_Fs, /* i : input sampling rate */ - Word16 *speech, /* i : speech buffer Q_new - preemph_bits */ - const Word16 Q_new, /* i : current scaling exp Q0 */ - Word32 *fr_bands, /* o : energy in critical frequency bands Q_new + QSCALE */ - Word32 *lf_E, /* o : per bin E for first... Q_new + QSCALE - 2*/ - Word16 *Etot, /* o : total input energy Q8 */ - const Word16 min_band, /* i : minimum critical band Q0 */ - const Word16 max_band, /* i : maximum critical band Q0 */ - const Word32 e_min_scaled, /* i : minimum energy scaled Q_new + QSCALE */ - Word16 Scale_fac[2], /* o : FFT scales factors (2 values by frame) Q0 */ - Word32 *Bin_E, /* o : per-bin energy spectrum */ - Word32 *Bin_E_old, /* o : per-bin energy spectrum of the previous frame */ - Word32 *PS, /* o : per-bin energy spectrum */ - Word16 *EspecdB, /* o : per-bin log energy spectrum (with f=0) Q7 */ - Word32 *band_energies, /* o : energy in critical frequency bands without minimum noise floor MODE2_E_MIN */ - Word16 *fft_buff /* o : FFT coefficients */ + const Word32 input_Fs, /* i : input sampling rate */ + Word16 *speech, /* i : speech buffer Q_new - preemph_bits */ + const Word16 Q_new, /* i : current scaling exp Q0 */ + Word32 *fr_bands, /* o : energy in critical frequency bands Q_new + QSCALE */ + Word32 *lf_E, /* o : per bin E for first... Q_new + QSCALE - 2*/ + Word16 *Etot, /* o : total input energy Q8 */ + const Word16 min_band, /* i : minimum critical band Q0 */ + const Word16 max_band, /* i : maximum critical band Q0 */ + const Word32 e_min_scaled, /* i : minimum energy scaled Q_new + QSCALE */ + Word16 Scale_fac[2], /* o : FFT scales factors (2 values by frame) Q0 */ + Word32 *Bin_E, /* o : per-bin energy spectrum */ + Word32 *Bin_E_old, /* o : per-bin energy spectrum of the previous frame */ + Word32 *PS, /* o : per-bin energy spectrum */ + Word16 *EspecdB, /* o : per-bin log energy spectrum (with f=0) Q7 */ + Word32 *band_energies, /* o : energy in critical frequency bands without minimum noise floor MODE2_E_MIN */ + Word16 *fft_buff /* o : FFT coefficients */ ) { Word16 *pt; @@ -63,7 +62,7 @@ void analy_sp_fx( Word16 Scale_fac2; Word16 fft_temp[L_FFT]; #ifndef IVAS_CODE_CPE - (void)input_Fs; + (void) input_Fs; #endif /*-----------------------------------------------------------------* * Compute spectrum @@ -72,15 +71,15 @@ void analy_sp_fx( pt_bands = fr_bands; pt_fft = fft_buff; - LEtot = L_deposit_l(0); - IF(NE_16(element_mode, IVAS_CPE_DFT)) + LEtot = L_deposit_l( 0 ); + IF( NE_16( element_mode, IVAS_CPE_DFT ) ) { - FOR(i_subfr = 0; i_subfr <= 1; i_subfr++) + FOR( i_subfr = 0; i_subfr <= 1; i_subfr++ ) { - pt = speech + 3 * (L_SUBFR / 2) - L_FFT / 2; - if (i_subfr != 0) + pt = speech + 3 * ( L_SUBFR / 2 ) - L_FFT / 2; + if ( i_subfr != 0 ) { - pt = speech + 7 * (L_SUBFR / 2) - L_FFT / 2; + pt = speech + 7 * ( L_SUBFR / 2 ) - L_FFT / 2; } /* Clear 1st value of 1st part, copy 1st value of 2nd part */ @@ -88,41 +87,41 @@ void analy_sp_fx( move16(); fft_temp[L_FFT / 2] = pt[L_FFT / 2]; move16(); - Max_val = s_max(fft_temp[0], fft_temp[L_FFT / 2]); - Min_val = s_min(fft_temp[0], fft_temp[L_FFT / 2]); + Max_val = s_max( fft_temp[0], fft_temp[L_FFT / 2] ); + Min_val = s_min( fft_temp[0], fft_temp[L_FFT / 2] ); - FOR(i = 1; i < L_FFT / 2; i++) + FOR( i = 1; i < L_FFT / 2; i++ ) { /* 1st windowed part */ - fft_temp[i] = mult_r(pt[i], sqrt_han_window_fx[i]); + fft_temp[i] = mult_r( pt[i], sqrt_han_window_fx[i] ); move16(); - if (fft_temp[i] > 0) - Max_val = s_max(Max_val, fft_temp[i]); - if (fft_temp[i] < 0) - Min_val = s_min(Min_val, fft_temp[i]); + if ( fft_temp[i] > 0 ) + Max_val = s_max( Max_val, fft_temp[i] ); + if ( fft_temp[i] < 0 ) + Min_val = s_min( Min_val, fft_temp[i] ); /* 2nd windowed part */ - fft_temp[L_FFT - i] = mult_r(pt[L_FFT - i], sqrt_han_window_fx[i]); + fft_temp[L_FFT - i] = mult_r( pt[L_FFT - i], sqrt_han_window_fx[i] ); move16(); - if (fft_temp[L_FFT - i] > 0) - Max_val = s_max(Max_val, fft_temp[L_FFT - i]); - if (fft_temp[L_FFT - i] < 0) - Min_val = s_min(Min_val, fft_temp[L_FFT - i]); + if ( fft_temp[L_FFT - i] > 0 ) + Max_val = s_max( Max_val, fft_temp[L_FFT - i] ); + if ( fft_temp[L_FFT - i] < 0 ) + Min_val = s_min( Min_val, fft_temp[L_FFT - i] ); } /* Combine -Min_val and Max_val into one */ - Max_val = s_max(negate(Min_val), Max_val); + Max_val = s_max( negate( Min_val ), Max_val ); - Scale_fac[i_subfr] = s_min(sub(norm_s(Max_val), 1), 6); + Scale_fac[i_subfr] = s_min( sub( norm_s( Max_val ), 1 ), 6 ); move16(); - Scale_fac2 = shl(Scale_fac[i_subfr], 1); - Scale_sig(fft_temp, L_FRAME_12k8, Scale_fac[i_subfr]); + Scale_fac2 = shl( Scale_fac[i_subfr], 1 ); + Scale_sig( fft_temp, L_FRAME_12k8, Scale_fac[i_subfr] ); - r_fft_fx_lc(FFT_W128, SIZE_256, SIZE2_256, NUM_STAGE_256, fft_temp, pt_fft, 1); + r_fft_fx_lc( FFT_W128, SIZE_256, SIZE2_256, NUM_STAGE_256, fft_temp, pt_fft, 1 ); /* find energy per critical band */ - find_enr(pt_fft, pt_bands, lf_E + i_subfr * VOIC_BINS, &LEtot, min_band, max_band, - add(Q_new, Scale_fac2), e_min_scaled, &Bin_E[i_subfr * L_FFT / 2], BIN, band_energies + i_subfr * NB_BANDS); + find_enr( pt_fft, pt_bands, lf_E + i_subfr * VOIC_BINS, &LEtot, min_band, max_band, + add( Q_new, Scale_fac2 ), e_min_scaled, &Bin_E[i_subfr * L_FFT / 2], BIN, band_energies + i_subfr * NB_BANDS ); pt_bands += NB_BANDS; pt_fft += L_FFT; @@ -132,11 +131,11 @@ void analy_sp_fx( ELSE { /* find energy per critical band */ - find_enr_dft(hCPE, input_Fs, hCPE->hStereoDft->DFT[0], pt_bands, lf_E, Etot, min_band, max_band, Bin_E, band_ener); - mvr2r(lf_E, lf_E + VOIC_BINS, VOIC_BINS); - mvr2r(Bin_E, Bin_E + (L_FFT / 2), L_FFT / 2); - mvr2r(band_ener, band_ener + NB_BANDS, NB_BANDS); - mvr2r(pt_bands, pt_bands + NB_BANDS, NB_BANDS); + find_enr_dft( hCPE, input_Fs, hCPE->hStereoDft->DFT[0], pt_bands, lf_E, Etot, min_band, max_band, Bin_E, band_ener ); + mvr2r( lf_E, lf_E + VOIC_BINS, VOIC_BINS ); + mvr2r( Bin_E, Bin_E + ( L_FFT / 2 ), L_FFT / 2 ); + mvr2r( band_ener, band_ener + NB_BANDS, NB_BANDS ); + mvr2r( pt_bands, pt_bands + NB_BANDS, NB_BANDS ); *Etot *= 2.f; } #endif @@ -144,34 +143,34 @@ void analy_sp_fx( /* Average total log energy over both half-frames */ frac_etot = 0; move16(); - exp_etot = norm_l(LEtot); - IF (LEtot != 0) /* Log2_norm_lc doesn't Support Input <= 0; deal with it here */ + exp_etot = norm_l( LEtot ); + IF( LEtot != 0 ) /* Log2_norm_lc doesn't Support Input <= 0; deal with it here */ { - frac_etot = Log2_norm_lc(L_shl(LEtot, exp_etot)); - exp_etot = sub(30, exp_etot); + frac_etot = Log2_norm_lc( L_shl( LEtot, exp_etot ) ); + exp_etot = sub( 30, exp_etot ); } - exp_etot = sub(exp_etot, add(Q_new, 1+3)); /* remove scaling effect, 4 already removed */ - Ltmp = Mpy_32(exp_etot, frac_etot, LG10, 0); + exp_etot = sub( exp_etot, add( Q_new, 1 + 3 ) ); /* remove scaling effect, 4 already removed */ + Ltmp = Mpy_32( exp_etot, frac_etot, LG10, 0 ); /*Q8 Averaged the total energy over both half-frames in log10 */ - *Etot = extract_l(L_shr(Ltmp, 14-8)); + *Etot = extract_l( L_shr( Ltmp, 14 - 8 ) ); - Bin_E[L_FFT/2-1] = Bin_E[L_FFT/2-2]; + Bin_E[L_FFT / 2 - 1] = Bin_E[L_FFT / 2 - 2]; move32(); - Bin_E[L_FFT-1] = Bin_E[L_FFT-2]; + Bin_E[L_FFT - 1] = Bin_E[L_FFT - 2]; move32(); /* Per-bin log-energy spectrum */ - exp2 = sub(31, add(Q_new, QSCALE-2)); - L_tmp2 = L_mac(-56783L, exp2, 28391); - FOR (i = 0; i < L_FFT/2; i++) + exp2 = sub( 31, add( Q_new, QSCALE - 2 ) ); + L_tmp2 = L_mac( -56783L, exp2, 28391 ); + FOR( i = 0; i < L_FFT / 2; i++ ) { Bin_E_old[i] = Bin_E[i]; move32(); /* tmp = (input[i] + input[i+Len]+0.001f)/2.0f */ - Ltmp = L_max(1, L_add(L_shr(Bin_E[i],1), L_shr(Bin_E[i+L_FFT/2],1))); - if(PS != NULL) + Ltmp = L_max( 1, L_add( L_shr( Bin_E[i], 1 ), L_shr( Bin_E[i + L_FFT / 2], 1 ) ) ); + if ( PS != NULL ) { PS[i] = Ltmp; move32(); @@ -183,12 +182,12 @@ void analy_sp_fx( /* 0.86643*(Log2(L_tmp)-1)*8 */ /* 0.86643*Log2(L_tmp)*8 - 6.93147 */ /* We'll put it in Q8 */ - exp = norm_l(Ltmp); - exp_frac = Log2_norm_lc(L_shl(Ltmp, exp)); + exp = norm_l( Ltmp ); + exp_frac = Log2_norm_lc( L_shl( Ltmp, exp ) ); /* -56783L is to substract 0.86643 in Q16 */ /* 28391 is 0.86643 in Q15 */ /* 1774 is (0.86643 in Q15) * 8 / 128 (/128 to go in Q7) */ - EspecdB[i] = mac_r(L_shl(L_msu(L_tmp2, exp, 28391), 3+7), exp_frac, 887); + EspecdB[i] = mac_r( L_shl( L_msu( L_tmp2, exp, 28391 ), 3 + 7 ), exp_frac, 887 ); move16(); } @@ -204,17 +203,17 @@ void analy_sp_fx( *------------------------------------------------------------------------*/ static void find_enr( - Word16 data[], /* i : fft result */ - Word32 band[], /* o : per band energy Q_new + QSCALE */ - Word32 *ptE, /* o : per bin energy for low frequencies Q_new + QSCALE-2 */ - Word32 *LEtot, /* o : total energy Q_new + QSCALE */ - const Word16 min_band, /* i : minimum critical band Q0 */ - const Word16 max_band, /* i : maximum critical band Q0 */ - const Word16 Q_new2, /* i : scaling factor Q0 */ - const Word32 e_min, /* i : minimum energy scaled Q_new + QSCALE */ - Word32 *Bin_E, /* o : Per bin energy Q_new + QSCALE-2 */ - Word16 BIN_FREQ_FX, /* i : Number of frequency bins */ - Word32 *band_energies /* o : per band energy without MODE2_E_MIN */ + Word16 data[], /* i : fft result */ + Word32 band[], /* o : per band energy Q_new + QSCALE */ + Word32 *ptE, /* o : per bin energy for low frequencies Q_new + QSCALE-2 */ + Word32 *LEtot, /* o : total energy Q_new + QSCALE */ + const Word16 min_band, /* i : minimum critical band Q0 */ + const Word16 max_band, /* i : maximum critical band Q0 */ + const Word16 Q_new2, /* i : scaling factor Q0 */ + const Word32 e_min, /* i : minimum energy scaled Q_new + QSCALE */ + Word32 *Bin_E, /* o : Per bin energy Q_new + QSCALE-2 */ + Word16 BIN_FREQ_FX, /* i : Number of frequency bins */ + Word32 *band_energies /* o : per band energy without MODE2_E_MIN */ ) { Word16 i, cnt, shift_to_norm; @@ -231,8 +230,8 @@ static void find_enr( #endif - ptR = &data[1]; /* first real */ - ptI = &data[L_FFT-1]; /* first imaginary */ + ptR = &data[1]; /* first real */ + ptI = &data[L_FFT - 1]; /* first imaginary */ /*-----------------------------------------------------------------------------------* * Scaling needed by band and ptE output @@ -243,14 +242,14 @@ static void find_enr( * shift left (QSCALE - Q_new + 1) == shift left by (QSCALE+1) - Q_new *-----------------------------------------------------------------------------------*/ - diff_scaleP1 = sub(QSCALE+1 + 1, Q_new2); - diff_scaleM2 = sub(QSCALE+1 - 2, Q_new2); + diff_scaleP1 = sub( QSCALE + 1 + 1, Q_new2 ); + diff_scaleM2 = sub( QSCALE + 1 - 2, Q_new2 ); voic_band = VOIC_BAND_8k; move16(); - assert (VOIC_BAND == VOIC_BAND_8k); + assert( VOIC_BAND == VOIC_BAND_8k ); - etot = L_deposit_l(0); + etot = L_deposit_l( 0 ); exp_etot = 0; move16(); @@ -261,164 +260,164 @@ static void find_enr( freq = BIN_FREQ_FX; move16(); - FOR (i = 0; i < voic_band; i++) /* up to maximum allowed voiced critical band */ + FOR( i = 0; i < voic_band; i++ ) /* up to maximum allowed voiced critical band */ { tmpptr = Bin_E; move16(); - Ltmp1 = L_deposit_l(0); + Ltmp1 = L_deposit_l( 0 ); - FOR (; freq <= crit_bands[i]; freq += BIN_FREQ_FX) + FOR( ; freq <= crit_bands[i]; freq += BIN_FREQ_FX ) { - /*ptE = *ptR * *ptR + *ptI * *ptI */ /* energy */ - Ltmp = L_mult(*ptI, *ptI); - Ltmp = L_mac(Ltmp, *ptR, *ptR); + /*ptE = *ptR * *ptR + *ptI * *ptI */ /* energy */ + Ltmp = L_mult( *ptI, *ptI ); + Ltmp = L_mac( Ltmp, *ptR, *ptR ); /* *ptE *= 4.0 / (L_FFT*L_FFT) */ /* normalization - corresponds to FFT normalization by 2/L_FFT */ BASOP_SATURATE_WARNING_OFF_EVS; /* saturation seems to have no effect (tested by simulation) */ #ifdef BASOP_NOGLOB - *ptE = L_shl_o(Ltmp, diff_scaleM2, &Overflow); -#else /* BASOP_NOGLOB */ - *ptE = L_shl(Ltmp, diff_scaleM2); -#endif /* BASOP_NOGLOB */ + *ptE = L_shl_o( Ltmp, diff_scaleM2, &Overflow ); +#else /* BASOP_NOGLOB */ + *ptE = L_shl( Ltmp, diff_scaleM2 ); +#endif /* BASOP_NOGLOB */ move32(); /* scaled by Q_new + QSCALE - 2 */ BASOP_SATURATE_WARNING_ON_EVS; /*band[i] += *ptE++;*/ - *Bin_E = *ptE; + *Bin_E = *ptE; move32(); Bin_E++; - Ltmp1 = L_add(Ltmp1, Ltmp); + Ltmp1 = L_add( Ltmp1, Ltmp ); ptE++; ptR++; ptI--; } - exp_band = sub(norm_l(Ltmp1), 1);/* divide by 2 to ensure band < cnt */ - wtmp = round_fx(L_shl(Ltmp1, exp_band)); + exp_band = sub( norm_l( Ltmp1 ), 1 ); /* divide by 2 to ensure band < cnt */ + wtmp = round_fx( L_shl( Ltmp1, exp_band ) ); - /* band[i] /= cnt */ /* normalization per frequency bin */ - cnt = (Word16)(Bin_E - tmpptr); - shift_to_norm = norm_s(cnt); - wtmp = div_s(wtmp, shl(cnt, shift_to_norm)); - Ltmp1 = L_deposit_l(wtmp); + /* band[i] /= cnt */ /* normalization per frequency bin */ + cnt = (Word16) ( Bin_E - tmpptr ); + shift_to_norm = norm_s( cnt ); + wtmp = div_s( wtmp, shl( cnt, shift_to_norm ) ); + Ltmp1 = L_deposit_l( wtmp ); - exp_band = sub(exp_band, shift_to_norm); - exp_band = sub(diff_scaleP1, exp_band); + exp_band = sub( exp_band, shift_to_norm ); + exp_band = sub( diff_scaleP1, exp_band ); BASOP_SATURATE_WARNING_OFF_EVS; /* saturation seems to have no effect (tested by simulation) */ #ifdef BASOP_NOGLOB - band[i] = L_shl_o(Ltmp1, exp_band, &Overflow); -#else /* BASOP_NOGLOB */ - band[i] = L_shl(Ltmp1, exp_band); -#endif /* BASOP_NOGLOB */ - move32();/* band scaled by Q_new + QSCALE */ + band[i] = L_shl_o( Ltmp1, exp_band, &Overflow ); +#else /* BASOP_NOGLOB */ + band[i] = L_shl( Ltmp1, exp_band ); +#endif /* BASOP_NOGLOB */ + move32(); /* band scaled by Q_new + QSCALE */ BASOP_SATURATE_WARNING_ON_EVS; test(); - IF (GE_16(i,min_band)&&LE_16(i,max_band)) + IF( GE_16( i, min_band ) && LE_16( i, max_band ) ) { - IF (LT_32(band[i],e_min)) + IF( LT_32( band[i], e_min ) ) { - Ltmp1 = L_shl(e_min, 0); + Ltmp1 = L_shl( e_min, 0 ); exp_band = 0; move16(); } - wtmp = sub(exp_band, exp_etot); - if (wtmp > 0) + wtmp = sub( exp_band, exp_etot ); + if ( wtmp > 0 ) { - etot = L_shr(etot, wtmp); + etot = L_shr( etot, wtmp ); } - exp_etot = s_max(exp_etot, exp_band); - etot = L_add(etot, L_shl(Ltmp1, sub(exp_band, exp_etot))); + exp_etot = s_max( exp_etot, exp_band ); + etot = L_add( etot, L_shl( Ltmp1, sub( exp_band, exp_etot ) ) ); } band_energies[i] = band[i]; move32(); - band[i] = L_max(band[i], e_min); + band[i] = L_max( band[i], e_min ); move32(); } - IF (EQ_16(BIN_FREQ_FX, 50)) + IF( EQ_16( BIN_FREQ_FX, 50 ) ) { /*-----------------------------------------------------------------* * Continue compute the E per critical band for high frequencies *-----------------------------------------------------------------*/ - FOR (i = voic_band; i < NB_BANDS; i++) + FOR( i = voic_band; i < NB_BANDS; i++ ) { tmpptr = Bin_E; move16(); - Ltmp1 = L_deposit_l(0); + Ltmp1 = L_deposit_l( 0 ); - FOR (; freq <= crit_bands[i]; freq += BIN_FREQ_FX) + FOR( ; freq <= crit_bands[i]; freq += BIN_FREQ_FX ) { /* *ptE = *ptR * *ptR + *ptI * *ptI */ - Ltmp = L_mult(*ptI, *ptI); - Ltmp = L_mac(Ltmp, *ptR, *ptR); + Ltmp = L_mult( *ptI, *ptI ); + Ltmp = L_mac( Ltmp, *ptR, *ptR ); /* *ptE *= 4.0 / (L_FFT*L_FFT) */ /* normalization - corresponds to FFT normalization by 2/L_FFT */ BASOP_SATURATE_WARNING_OFF_EVS; /* saturation seems to have no effect (tested by simulation) */ #ifdef BASOP_NOGLOB - *Bin_E = L_shl_o(Ltmp, diff_scaleM2, &Overflow); -#else /* BASOP_NOGLOB */ - *Bin_E = L_shl(Ltmp, diff_scaleM2); -#endif /* BASOP_NOGLOB */ - move32(); /* scaled by Q_new + QSCALE - 2 */ + *Bin_E = L_shl_o( Ltmp, diff_scaleM2, &Overflow ); +#else /* BASOP_NOGLOB */ + *Bin_E = L_shl( Ltmp, diff_scaleM2 ); +#endif /* BASOP_NOGLOB */ + move32(); /* scaled by Q_new + QSCALE - 2 */ BASOP_SATURATE_WARNING_ON_EVS; Bin_E++; - Ltmp1 = L_add(Ltmp1, Ltmp); + Ltmp1 = L_add( Ltmp1, Ltmp ); ptR++; ptI--; } - exp_band = sub(norm_l(Ltmp1), 1); /* divide by 2 to ensure band < cnt */ - wtmp = round_fx(L_shl(Ltmp1, exp_band)); + exp_band = sub( norm_l( Ltmp1 ), 1 ); /* divide by 2 to ensure band < cnt */ + wtmp = round_fx( L_shl( Ltmp1, exp_band ) ); - /* band[i] /= cnt */ /* normalization per frequency bin */ - cnt = (Word16)(Bin_E - tmpptr); - shift_to_norm = norm_s(cnt); - wtmp = div_s(wtmp, shl(cnt, shift_to_norm)); - Ltmp1 = L_deposit_l(wtmp); + /* band[i] /= cnt */ /* normalization per frequency bin */ + cnt = (Word16) ( Bin_E - tmpptr ); + shift_to_norm = norm_s( cnt ); + wtmp = div_s( wtmp, shl( cnt, shift_to_norm ) ); + Ltmp1 = L_deposit_l( wtmp ); - exp_band = sub(exp_band, shift_to_norm); - exp_band = sub(diff_scaleP1, exp_band); + exp_band = sub( exp_band, shift_to_norm ); + exp_band = sub( diff_scaleP1, exp_band ); BASOP_SATURATE_WARNING_OFF_EVS; /* saturation seems to have no effect (tested by simulation) */ #ifdef BASOP_NOGLOB - band[i] = L_shl_o(Ltmp1, exp_band, &Overflow); + band[i] = L_shl_o( Ltmp1, exp_band, &Overflow ); #else /* BASOP_NOGLOB */ - band[i] = L_shl(Ltmp1, exp_band); + band[i] = L_shl( Ltmp1, exp_band ); #endif - move32();/* band scaled by Q_new + QSCALE */ + move32(); /* band scaled by Q_new + QSCALE */ BASOP_SATURATE_WARNING_ON_EVS; test(); - IF (GE_16(i,min_band)&&LE_16(i,max_band)) + IF( GE_16( i, min_band ) && LE_16( i, max_band ) ) { - IF (LT_32(band[i],e_min)) + IF( LT_32( band[i], e_min ) ) { - Ltmp1 = L_shl(e_min, 0); + Ltmp1 = L_shl( e_min, 0 ); exp_band = 0; move16(); } - wtmp = sub(exp_band, exp_etot); - if (wtmp > 0) + wtmp = sub( exp_band, exp_etot ); + if ( wtmp > 0 ) { - etot = L_shr(etot, wtmp); + etot = L_shr( etot, wtmp ); } - exp_etot = s_max(exp_etot, exp_band); + exp_etot = s_max( exp_etot, exp_band ); - etot = L_add(etot, L_shl(Ltmp1, sub(exp_band, exp_etot))); + etot = L_add( etot, L_shl( Ltmp1, sub( exp_band, exp_etot ) ) ); } band_energies[i] = band[i]; move32(); - band[i] = L_max(band[i], e_min); + band[i] = L_max( band[i], e_min ); move32(); } } @@ -430,7 +429,7 @@ static void find_enr( #ifdef BASOP_NOGLOB etot = L_add_sat( *LEtot, L_shl_sat( etot, sub( exp_etot, 4 ) ) ); #else - etot = L_add(*LEtot, L_shl(etot, sub(exp_etot, 4))); + etot = L_add( *LEtot, L_shl( etot, sub( exp_etot, 4 ) ) ); #endif *LEtot = etot; move32(); @@ -450,35 +449,35 @@ static void find_enr_dft( const int32_t input_Fs, /* i : input sampling rate */ float DFT_past_DMX[], float band[], /* o : per band energy */ - float* ptE, /* o : per bin energy for low frequencies */ - float* Etot, /* i/o: total energy */ + float *ptE, /* o : per bin energy for low frequencies */ + float *Etot, /* i/o: total energy */ const int16_t min_band, /* i : minimum critical band */ const int16_t max_band, /* i : maximum critical band */ - float* Bin_E, /* o : Per bin energy */ - float* band_ener /* o : per band energy without E_MIN */ + float *Bin_E, /* o : Per bin energy */ + float *band_ener /* o : per band energy without E_MIN */ ) { int16_t i, cnt; float freq, tmp; - const float* ptR, * ptI; + const float *ptR, *ptI; float norm_val; int16_t bin_cnt = 0; float c, s; /* One window - 40ms*12.8kHz = 512 samples */ - float c_1 = cosf(PI2 / STEREO_DFT_N_12k8_ENC); - float s_1 = sinf(PI2 / STEREO_DFT_N_12k8_ENC); + float c_1 = cosf( PI2 / STEREO_DFT_N_12k8_ENC ); + float s_1 = sinf( PI2 / STEREO_DFT_N_12k8_ENC ); float g_1 = 1.f + 0.68f * 0.68f; float g_2 = 2 * 0.68f; float g; float scaleWin; float BinE[STEREO_DFT_N_12k8_ENC / 2]; /* NB_BANDS = 20 (= 6350Hz) = highest band available for SR 12.8 -> bin_cnt = 158 */ - float bin_freq = input_Fs / (float)hCPE->hStereoDft->NFFT; /* adaptive frequency bin width */ + float bin_freq = input_Fs / (float) hCPE->hStereoDft->NFFT; /* adaptive frequency bin width */ - scaleWin = 1 / (2 * hCPE->hStereoDft->win_ana_energy); - scaleWin *= (float)BIN / bin_freq; - norm_val = scaleWin * 4.0f / (hCPE->hStereoDft->NFFT * hCPE->hStereoDft->NFFT); + scaleWin = 1 / ( 2 * hCPE->hStereoDft->win_ana_energy ); + scaleWin *= (float) BIN / bin_freq; + norm_val = scaleWin * 4.0f / ( hCPE->hStereoDft->NFFT * hCPE->hStereoDft->NFFT ); ptR = &DFT_past_DMX[2]; /* first real */ ptI = &DFT_past_DMX[3]; /* first imaginary */ @@ -487,7 +486,7 @@ static void find_enr_dft( /* for low frequency bins, save per bin energy for the use in find_tilt() */ freq = bin_freq; - for (i = 0; i < NB_BANDS - 1; i++) /* up to maximum allowed voiced critical band */ + for ( i = 0; i < NB_BANDS - 1; i++ ) /* up to maximum allowed voiced critical band */ { band[i] = 0.0f; cnt = 0; @@ -497,7 +496,7 @@ static void find_enr_dft( * bin_cnt new (bin_width 40 Hz): 92 (92 * 40 = 3680) */ - while (freq <= crit_bands[i]) + while ( freq <= crit_bands[i] ) { BinE[bin_cnt] = *ptR * *ptR + *ptI * *ptI; /* energy */ g = g_1 - g_2 * c; @@ -518,7 +517,7 @@ static void find_enr_dft( band_ener[i] = band[i]; /* per band energy without E_MIN */ - if (band[i] < E_MIN) + if ( band[i] < E_MIN ) { band[i] = E_MIN; } @@ -529,19 +528,19 @@ static void find_enr_dft( /* old version, FFT 256 @ SR12.8 (-> bin_width = 50 Hz): NB_BANDS = 20 (= 6350Hz) = highest band available for SR 12.8 -> bin_cnt = 127 = L_FFT/2-1*/ - /* new version: DFT (1200/800/400) @ input SR (48/32/16) (-> bin_width = 40 Hz): - * - */ - /* NB_BANDS = 20 (= 6350Hz) = highest band available for SR 12.8 -> bin_cnt = 158 */ - /* NB_BANDS = 21 (= 7700Hz) = highest band available for SR 16 -> bin_cnt = 192 */ - /* NB_BANDS = 24 (= 15500Hz) = highest band available for SR 32 -> bin_cnt = 387 */ - /* NB_BANDS = 24 (= 15500Hz) = highest band available for SR 48 -> bin_cnt = 387 */ + /* new version: DFT (1200/800/400) @ input SR (48/32/16) (-> bin_width = 40 Hz): + * + */ + /* NB_BANDS = 20 (= 6350Hz) = highest band available for SR 12.8 -> bin_cnt = 158 */ + /* NB_BANDS = 21 (= 7700Hz) = highest band available for SR 16 -> bin_cnt = 192 */ + /* NB_BANDS = 24 (= 15500Hz) = highest band available for SR 32 -> bin_cnt = 387 */ + /* NB_BANDS = 24 (= 15500Hz) = highest band available for SR 48 -> bin_cnt = 387 */ - for (; i < NB_BANDS; i++) + for ( ; i < NB_BANDS; i++ ) { band[i] = 0.0f; cnt = 0; - while (freq < 6399.0f) + while ( freq < 6399.0f ) { BinE[bin_cnt] = *ptR * *ptR + *ptI * *ptI; g = g_1 - g_2 * c; @@ -559,7 +558,7 @@ static void find_enr_dft( band_ener[i] = band[i]; /* per band energy without E_MIN */ - if (band[i] < E_MIN) + if ( band[i] < E_MIN ) { band[i] = E_MIN; } @@ -567,15 +566,15 @@ static void find_enr_dft( /* put bin energies from BinE into Bin_E[L_FFT/2-1] (interpolate 40 Hz bin values to fit into 50 Hz bins) */ /* Last value of Bin_E is handled outside this function*/ - assert(bin_cnt == (STEREO_DFT_N_12k8_ENC / 2 - 1)); + assert( bin_cnt == ( STEREO_DFT_N_12k8_ENC / 2 - 1 ) ); BinE[STEREO_DFT_N_12k8_ENC / 2 - 1] = BinE[STEREO_DFT_N_12k8_ENC / 2 - 2]; - lerp(BinE, Bin_E, L_FFT / 2, STEREO_DFT_N_12k8_ENC / 2); - mvr2r(Bin_E, ptE, VOIC_BINS); + lerp( BinE, Bin_E, L_FFT / 2, STEREO_DFT_N_12k8_ENC / 2 ); + mvr2r( Bin_E, ptE, VOIC_BINS ); /* find the total log energy */ tmp = *Etot; - for (i = min_band; i <= max_band; i++) + for ( i = min_band; i <= max_band; i++ ) { tmp += band[i]; } @@ -585,4 +584,4 @@ static void find_enr_dft( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_enc/ari_enc_fx.c b/lib_enc/ari_enc_fx.c index 08b35f918..5e01f8f35 100644 --- a/lib_enc/ari_enc_fx.c +++ b/lib_enc/ari_enc_fx.c @@ -9,9 +9,9 @@ #include "cnst.h" #include "rom_com.h" //#include "prot_fx.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*--------------------------------------------------------------- * ari_copy_states_fx() @@ -21,9 +21,9 @@ * * \return none *-------------------------------------------------------------*/ -void ari_copy_states_fx(TastatEnc *source, TastatEnc *dest) +void ari_copy_states_fx( TastatEnc *source, TastatEnc *dest ) { - dest->low = source->low; + dest->low = source->low; move32(); dest->high = source->high; move32(); @@ -39,13 +39,13 @@ void ari_copy_states_fx(TastatEnc *source, TastatEnc *dest) /*--------------------------------------------------------------- * ari_start_encoding_14bits_fx() * - * \param[o] s + * \param[o] s * * \return none *-------------------------------------------------------------*/ -void ari_start_encoding_14bits_fx(TastatEnc *s) +void ari_start_encoding_14bits_fx( TastatEnc *s ) { - s->low = L_deposit_l(0); + s->low = L_deposit_l( 0 ); s->high = ari_q4new + 1; move32(); s->value = 0; @@ -54,7 +54,7 @@ void ari_start_encoding_14bits_fx(TastatEnc *s) /*--------------------------------------------------------------- * Ari encoder 14 bits routines - * Returns: new bit-stream position + * Returns: new bit-stream position *-------------------------------------------------------------*/ static Word16 ari_put_bit_plus_follow( Word16 ptr[], /* o: bit-stream */ @@ -63,12 +63,14 @@ static Word16 ari_put_bit_plus_follow( Word16 bit /* i: bit to send */ ) { - assert(bit == 0 || bit == 1); - ptr[bp++] = bit; /* send initially a zero or one */ move16(); - bit = s_xor(bit, 1); /* invert bit to send */ - FOR ( ; bits_to_follow > 0; bits_to_follow--) + assert( bit == 0 || bit == 1 ); + ptr[bp++] = bit; /* send initially a zero or one */ + move16(); + bit = s_xor( bit, 1 ); /* invert bit to send */ + FOR( ; bits_to_follow > 0; bits_to_follow-- ) { - ptr[bp++] = bit; /* send inverted bit */ move16(); + ptr[bp++] = bit; /* send inverted bit */ + move16(); } return bp; } @@ -83,17 +85,17 @@ static Word16 ari_put_bit_plus_follow( * * \return bit consumption * ------------------------------------------------------------ - */ -Word16 ari_done_encoding_14bits_fx(Word16 *ptr, Word16 bp, TastatEnc *s) +Word16 ari_done_encoding_14bits_fx( Word16 *ptr, Word16 bp, TastatEnc *s ) { Word16 bit; bit = 0; move16(); - if ( GE_32(s->low,ari_q1new)) + if ( GE_32( s->low, ari_q1new ) ) { - bit = s_xor(bit,1); + bit = s_xor( bit, 1 ); } - return ari_put_bit_plus_follow(ptr, bp, add(s->value, 1), bit); + return ari_put_bit_plus_follow( ptr, bp, add( s->value, 1 ), bit ); } @@ -112,12 +114,11 @@ Word16 ari_done_encoding_14bits_fx(Word16 *ptr, Word16 bp, TastatEnc *s) * \return bit consumption * ------------------------------------------------------------ - */ Word16 ari_encode_14bits_ext_fx( - Word16 *ptr, - Word16 bp, + Word16 *ptr, + Word16 bp, TastatEnc *s, - Word32 symbol, - UWord16 const *cum_freq -) + Word32 symbol, + UWord16 const *cum_freq ) { Word32 low; Word32 high; @@ -127,59 +128,60 @@ Word16 ari_encode_14bits_ext_fx( UWord16 temp; Word32 L_temp1, L_temp2; - high = L_add(s->high, 0); - low = L_add(s->low, 0); - range = L_sub(high, low); + high = L_add( s->high, 0 ); + low = L_add( s->low, 0 ); + range = L_sub( high, low ); - L_temp1 = L_shl(range,15-stat_bitsnew/*both are constants*/); - Mpy_32_16_ss(L_temp1, cum_freq[symbol+1], &L_temp2, &temp); - if (symbol != 0) /* when symbol is 0, range remains unchanged */ + L_temp1 = L_shl( range, 15 - stat_bitsnew /*both are constants*/ ); + Mpy_32_16_ss( L_temp1, cum_freq[symbol + 1], &L_temp2, &temp ); + if ( symbol != 0 ) /* when symbol is 0, range remains unchanged */ { - Mpy_32_16_ss(L_temp1, cum_freq[symbol], &range, &temp); + Mpy_32_16_ss( L_temp1, cum_freq[symbol], &range, &temp ); } - high = L_add(low, range); - low = L_add(low, L_temp2); + high = L_add( low, range ); + low = L_add( low, L_temp2 ); bits_to_follow = s->value; move16(); - FOR (i = 0; i < 0x7FFF; i++) + FOR( i = 0; i < 0x7FFF; i++ ) { - IF (LE_32(high, ari_q2new)) + IF( LE_32( high, ari_q2new ) ) { - bp = ari_put_bit_plus_follow(ptr, bp, bits_to_follow, 0); + bp = ari_put_bit_plus_follow( ptr, bp, bits_to_follow, 0 ); bits_to_follow = 0; move16(); } - ELSE IF (GE_32(low, ari_q2new)) + ELSE IF( GE_32( low, ari_q2new ) ) { - bp = ari_put_bit_plus_follow(ptr, bp, bits_to_follow, 1); + bp = ari_put_bit_plus_follow( ptr, bp, bits_to_follow, 1 ); bits_to_follow = 0; move16(); - low = L_sub(low, ari_q2new); - high = L_sub(high, ari_q2new); /* Subtract offset to top. */ + low = L_sub( low, ari_q2new ); + high = L_sub( high, ari_q2new ); /* Subtract offset to top. */ } ELSE { test(); - IF (GE_32(low, ari_q1new)&&LE_32(high,ari_q3new)) + IF( GE_32( low, ari_q1new ) && LE_32( high, ari_q3new ) ) { /* Output an opposite bit */ /* later if in middle half. */ - bits_to_follow = add(bits_to_follow, 1); - low = L_sub(low, ari_q1new); /* Subtract offset to middle*/ - high = L_sub(high, ari_q1new); + bits_to_follow = add( bits_to_follow, 1 ); + low = L_sub( low, ari_q1new ); /* Subtract offset to middle*/ + high = L_sub( high, ari_q1new ); } - ELSE { + ELSE + { BREAK; /* Otherwise exit loop. */ } } - low = L_add(low, low); - high = L_add(high, high); /* Scale up code range. */ + low = L_add( low, low ); + high = L_add( high, high ); /* Scale up code range. */ } - s->low = low; + s->low = low; move32(); s->high = high; move32(); @@ -191,19 +193,19 @@ Word16 ari_encode_14bits_ext_fx( /*------------------------------------------------------------------------ * Function: ari_encode_overflow_fx() * - * + * *-------------------------------------------------------------------------*/ -Word16 ari_encode_overflow_fx(TastatEnc *s) +Word16 ari_encode_overflow_fx( TastatEnc *s ) { - return L_sub(L_sub(s->high, 1), s->low) <= 0; + return L_sub( L_sub( s->high, 1 ), s->low ) <= 0; } /*------------------------------------------------------------------------ * Function: ari_encode_14bits_high_low() * - * + * *-------------------------------------------------------------------------*/ -static Word16 ari_encode_14bits_high_low(Word16 *ptr, Word16 bp, Word16 bits, TastatEnc *s, Word32 high, Word32 low) +static Word16 ari_encode_14bits_high_low( Word16 *ptr, Word16 bp, Word16 bits, TastatEnc *s, Word32 high, Word32 low ) { Word16 bits_to_follow, tmp; @@ -211,44 +213,45 @@ static Word16 ari_encode_14bits_high_low(Word16 *ptr, Word16 bp, Word16 bits, Ta move16(); /* while there are more than 16 bits left */ - tmp = sub(16, bits); - WHILE (add(add(bp, bits_to_follow), tmp) < 0) + tmp = sub( 16, bits ); + WHILE( add( add( bp, bits_to_follow ), tmp ) < 0 ) { - IF (LE_32(high, ari_q2new)) + IF( LE_32( high, ari_q2new ) ) { - bp = ari_put_bit_plus_follow(ptr, bp, bits_to_follow, 0); + bp = ari_put_bit_plus_follow( ptr, bp, bits_to_follow, 0 ); bits_to_follow = 0; move16(); } - ELSE IF (GE_32(low, ari_q2new)) + ELSE IF( GE_32( low, ari_q2new ) ) { - bp = ari_put_bit_plus_follow(ptr, bp, bits_to_follow, 1); + bp = ari_put_bit_plus_follow( ptr, bp, bits_to_follow, 1 ); bits_to_follow = 0; move16(); - low = L_sub(low, ari_q2new); - high = L_sub(high, ari_q2new); /* Subtract offset to top. */ + low = L_sub( low, ari_q2new ); + high = L_sub( high, ari_q2new ); /* Subtract offset to top. */ } ELSE { test(); - IF (GE_32(low, ari_q1new)&&LE_32(high,ari_q3new)) + IF( GE_32( low, ari_q1new ) && LE_32( high, ari_q3new ) ) { /* Output an opposite bit */ /* later if in middle half. */ - bits_to_follow = add(bits_to_follow, 1); - low = L_sub(low, ari_q1new); /* Subtract offset to middle*/ - high = L_sub(high, ari_q1new); + bits_to_follow = add( bits_to_follow, 1 ); + low = L_sub( low, ari_q1new ); /* Subtract offset to middle*/ + high = L_sub( high, ari_q1new ); } - ELSE { + ELSE + { BREAK; /* Otherwise exit loop. */ } } - low = L_add(low, low); - high = L_add(high, high); /* Scale up code range. */ + low = L_add( low, low ); + high = L_add( high, high ); /* Scale up code range. */ } - s->low = low; + s->low = low; move32(); s->high = high; move32(); @@ -264,16 +267,16 @@ static Word16 ari_encode_14bits_high_low(Word16 *ptr, Word16 bp, Word16 bits, Ta * Encode an cumulative frequency interval. *-------------------------------------------------------------------------*/ -Word16 ari_encode_14bits_range_fx(Word16 *ptr, Word16 bp, Word16 bits, TastatEnc *s, Word16 cum_freq_low, Word16 cum_freq_high) +Word16 ari_encode_14bits_range_fx( Word16 *ptr, Word16 bp, Word16 bits, TastatEnc *s, Word16 cum_freq_low, Word16 cum_freq_high ) { Word32 low, high, range; - range = L_sub(s->high, s->low); + range = L_sub( s->high, s->low ); - high = L_add(s->low, mul_sbc_14bits(range, cum_freq_high)); - low = L_add(s->low, mul_sbc_14bits(range, cum_freq_low)); + high = L_add( s->low, mul_sbc_14bits( range, cum_freq_high ) ); + low = L_add( s->low, mul_sbc_14bits( range, cum_freq_low ) ); - return ari_encode_14bits_high_low(ptr, bp, bits, s, high, low); + return ari_encode_14bits_high_low( ptr, bp, bits, s, high, low ); } @@ -282,26 +285,26 @@ Word16 ari_encode_14bits_range_fx(Word16 *ptr, Word16 bp, Word16 bits, TastatEnc * * Encode a sign with equal probabilities. *-------------------------------------------------------------------------*/ -Word16 ari_encode_14bits_sign_fx(Word16 *ptr, Word16 bp, Word16 bits, TastatEnc *s, Word16 sign) +Word16 ari_encode_14bits_sign_fx( Word16 *ptr, Word16 bp, Word16 bits, TastatEnc *s, Word16 sign ) { Word32 low, high, range; Word32 L_tmp; - high = L_add(s->high, 0); - low = L_add(s->low, 0); - range = L_sub(high, low); + high = L_add( s->high, 0 ); + low = L_add( s->low, 0 ); + range = L_sub( high, low ); - L_tmp = L_shr(range, 1); - if (sign != 0) + L_tmp = L_shr( range, 1 ); + if ( sign != 0 ) { - high = L_add(low, L_tmp); + high = L_add( low, L_tmp ); } - if (sign == 0) + if ( sign == 0 ) { - low = L_add(low, L_tmp); + low = L_add( low, L_tmp ); } - return ari_encode_14bits_high_low(ptr, bp, bits, s, high, low); + return ari_encode_14bits_high_low( ptr, bp, bits, s, high, low ); } /*------------------------------------------------------------------------ @@ -309,29 +312,28 @@ Word16 ari_encode_14bits_sign_fx(Word16 *ptr, Word16 bp, Word16 bits, TastatEnc * * Finish up encoding in CBR mode. *-------------------------------------------------------------------------*/ -Word16 ari_done_cbr_encoding_14bits_fx(Word16 *ptr, Word16 bp, Word16 bits, TastatEnc *s) +Word16 ari_done_cbr_encoding_14bits_fx( Word16 *ptr, Word16 bp, Word16 bits, TastatEnc *s ) { Word16 high, tmp, k; - tmp = sub(bits, 16); - WHILE (GT_16(sub(tmp, bp), s->value)) + tmp = sub( bits, 16 ); + WHILE( GT_16( sub( tmp, bp ), s->value ) ) { - bp = ari_encode_14bits_sign_fx(ptr, bp, bits, s, 0); + bp = ari_encode_14bits_sign_fx( ptr, bp, bits, s, 0 ); } - high = extract_l(L_sub(s->high, 1)); + high = extract_l( L_sub( s->high, 1 ) ); - bp = ari_put_bit_plus_follow(ptr, bp, s->value, lshr(high, 15)); - high = lshl(high, 1); + bp = ari_put_bit_plus_follow( ptr, bp, s->value, lshr( high, 15 ) ); + high = lshl( high, 1 ); - tmp = s_min(15, sub(bits, bp)); - FOR (k=0; k 0) && (GT_16(LtpGain, kLtpHmGainThr))) + IF( ( LtpPitchLag > 0 ) && ( GT_16( LtpGain, kLtpHmGainThr ) ) ) { Bandwidth = 0; move16(); - if (GE_16(NumToConsider, 256)) + if ( GE_16( NumToConsider, 256 ) ) { Bandwidth = 1; move16(); } - LtpPitchIndex = sub(mult_r(LtpPitchLag, 1 << (15-kLtpHmFractionalResolution)), 2); - assert(0 <= LtpPitchIndex && LtpPitchIndex <= 16); + LtpPitchIndex = sub( mult_r( LtpPitchLag, 1 << ( 15 - kLtpHmFractionalResolution ) ), 2 ); + assert( 0 <= LtpPitchIndex && LtpPitchIndex <= 16 ); - tmp32 = L_shl(L_deposit_l(sub(NumToConsider, 2)), kLtpHmFractionalResolution); - tmp = shl(1, NumRatioBits[Bandwidth][LtpPitchIndex]); - FOR (Multiplier = 1; Multiplier <= tmp; ++Multiplier) + tmp32 = L_shl( L_deposit_l( sub( NumToConsider, 2 ) ), kLtpHmFractionalResolution ); + tmp = shl( 1, NumRatioBits[Bandwidth][LtpPitchIndex] ); + FOR( Multiplier = 1; Multiplier <= tmp; ++Multiplier ) { - Lag = L_shr(L_mult0(LtpPitchLag, Ratios_fx[Bandwidth][LtpPitchIndex][Multiplier-1]), 8); + Lag = L_shr( L_mult0( LtpPitchLag, Ratios_fx[Bandwidth][LtpPitchIndex][Multiplier - 1] ), 8 ); test(); - IF ((GE_32(Lag, 4< 0) + IF( AbsTotal > 0 ) { - tmp32 = L_mult0(Score, NumToConsider); /* -> 16Q15 */ - tmp = sub(norm_l(tmp32), 1); - tmp2 = norm_l(AbsTotal); + tmp32 = L_mult0( Score, NumToConsider ); /* -> 16Q15 */ + tmp = sub( norm_l( tmp32 ), 1 ); + tmp2 = norm_l( AbsTotal ); #ifdef BASOP_NOGLOB - tmp3 = div_s(round_fx_o(L_shl_o(tmp32, tmp, &Overflow), &Overflow), round_fx_o(L_shl_o(AbsTotal, tmp2, &Overflow), &Overflow)); - * RelativeScore = shr_o(tmp3, add(sub(tmp, tmp2), 2), &Overflow); /* -> 2Q13 */ move16(); + tmp3 = div_s( round_fx_o( L_shl_o( tmp32, tmp, &Overflow ), &Overflow ), round_fx_o( L_shl_o( AbsTotal, tmp2, &Overflow ), &Overflow ) ); + *RelativeScore = shr_o( tmp3, add( sub( tmp, tmp2 ), 2 ), &Overflow ); /* -> 2Q13 */ + move16(); #else - tmp3 = div_s(round_fx(L_shl(tmp32, tmp)), round_fx(L_shl(AbsTotal, tmp2))); + tmp3 = div_s( round_fx( L_shl( tmp32, tmp ) ), round_fx( L_shl( AbsTotal, tmp2 ) ) ); BASOP_SATURATE_WARNING_OFF_EVS - *RelativeScore = shr(tmp3, add(sub(tmp, tmp2), 2)); /* -> 2Q13 */ move16(); + *RelativeScore = shr( tmp3, add( sub( tmp, tmp2 ), 2 ) ); /* -> 2Q13 */ + move16(); BASOP_SATURATE_WARNING_ON_EVS #endif } @@ -461,48 +452,47 @@ Word16 SearchPeriodicityIndex_fx( *-------------------------------------------------------------------*/ static void PeakFilter( - const Word32 x[], /* i : absolute spectrum */ - Word32 y[], /* O : filtered absolute spectrum, must not alias x[] */ - const Word16 L_frame /* i : number of spectral lines */ + const Word32 x[], /* i : absolute spectrum */ + Word32 y[], /* O : filtered absolute spectrum, must not alias x[] */ + const Word16 L_frame /* i : number of spectral lines */ ) { Word16 flen, i; -/*#define kPeakElevationThreshold 1.0f*/ + /*#define kPeakElevationThreshold 1.0f*/ Word16 m; Word32 a; - flen = shr(L_frame, 4); + flen = shr( L_frame, 4 ); /* m = kPeakElevationThreshold / (float)(2*flen + 1); */ - m = shr(div_s(8/*kPeakElevationThreshold Q3*/, add(shl(flen,1), 1)), 3); + m = shr( div_s( 8 /*kPeakElevationThreshold Q3*/, add( shl( flen, 1 ), 1 ) ), 3 ); - a = L_deposit_l(0); - FOR (i=0; i 0 ) + IF( gain > 0 ) { - prm_hm[0] = 1; /* flag: on */ move16(); + prm_hm[0] = 1; /* flag: on */ + move16(); - hm_bits = add(hm_bits, CountIndexBits(bw_flag, prm_hm[1])); + hm_bits = add( hm_bits, CountIndexBits( bw_flag, prm_hm[1] ) ); - if (EQ_16(coder_type, VOICED)) + if ( EQ_16( coder_type, VOICED ) ) { - hm_bits = add(hm_bits, kTcxHmNumGainBits); + hm_bits = add( hm_bits, kTcxHmNumGainBits ); } tcx_hm_modify_envelope( @@ -828,17 +810,18 @@ void tcx_hm_analyse_fx( fract_res, p, env, - L_frame - ); + L_frame ); } ELSE { - prm_hm[0] = 0; /* flag: off */ move16(); - prm_hm[1] = -1; /* pitch index */ move16(); - prm_hm[2] = 0; /* gain index */ move16(); + prm_hm[0] = 0; /* flag: off */ + move16(); + prm_hm[1] = -1; /* pitch index */ + move16(); + prm_hm[2] = 0; /* gain index */ + move16(); } *hm_bits_out = hm_bits; move16(); } - diff --git a/lib_enc/arith_coder_enc.c b/lib_enc/arith_coder_enc.c index e48f0806f..eedd260ee 100644 --- a/lib_enc/arith_coder_enc.c +++ b/lib_enc/arith_coder_enc.c @@ -609,7 +609,7 @@ void tcx_arith_encode_envelope( gamma_uw = 1.0f / st->gamma_flt; #define WMC_TOOL_SKIP - tcx_arith_render_envelope_flt( A_ind, L_frame, L_spec, FL2WORD16( hTcxCfg->preemph_fac_flt), FL2WORD16( gamma_w ), FL2WORD16( 0.5f * gamma_uw ), env ); + tcx_arith_render_envelope_flt( A_ind, L_frame, L_spec, FL2WORD16( hTcxCfg->preemph_fac_flt ), FL2WORD16( gamma_w ), FL2WORD16( 0.5f * gamma_uw ), env ); #undef WMC_TOOL_SKIP for ( k = 0; k < L_spec; ++k ) @@ -653,7 +653,7 @@ void tcx_arith_encode_envelope( exponents[k] = expfp_evs( negate( envelope[k] ), tmp ); } #undef WMC_TOOL_SKIP - scale = tcx_arith_rateloop( spectrum, L_spec, envelope, envelope_e, exponents, target_bits, deadzone, deadzone_flags, &( hTcxEnc->tcx_target_bits_fac_flt) ); + scale = tcx_arith_rateloop( spectrum, L_spec, envelope, envelope_e, exponents, target_bits, deadzone, deadzone_flags, &( hTcxEnc->tcx_target_bits_fac_flt ) ); /* Final quantization */ kMax = tcx_arith_find_kMax( spectrum, L_spec, scale, deadzone, deadzone_flags ); diff --git a/lib_enc/arith_coder_enc_fx.c b/lib_enc/arith_coder_enc_fx.c index da9de9b92..5c96532be 100644 --- a/lib_enc/arith_coder_enc_fx.c +++ b/lib_enc/arith_coder_enc_fx.c @@ -6,9 +6,9 @@ #include #include "options.h" #include "cnst.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" #include "rom_com.h" @@ -18,7 +18,7 @@ *-------------------------------------------------------------------*/ #define kMaxNumHeapElems 10 -#define LOG2_E 23637/*1.44269504089f Q14*/ +#define LOG2_E 23637 /*1.44269504089f Q14*/ typedef struct HeapElem { @@ -36,15 +36,15 @@ typedef struct Heap * tcx_arith_estimate_scale() * * - * Returns: estimated SQ scale Q15-e + * Returns: estimated SQ scale Q15-e *-------------------------------------------------------------------*/ static Word16 tcx_arith_estimate_scale( - const Word32 abs_spectrum[], /* i: absolute MDCT coefficients Q31-e */ - const Word16 abs_spectrum_e, /* i: MDCT exponent Q0 */ - const Word16 L_frame, /* i: number of spectral lines Q0 */ - const Word16 envelope[], /* i: scaled envelope Q15-e */ - const Word16 envelope_e, /* i: scaled envelope exponent Q0 */ - Word16 *scale_e /* o: scale exponent Q0 */ + const Word32 abs_spectrum[], /* i: absolute MDCT coefficients Q31-e */ + const Word16 abs_spectrum_e, /* i: MDCT exponent Q0 */ + const Word16 L_frame, /* i: number of spectral lines Q0 */ + const Word16 envelope[], /* i: scaled envelope Q15-e */ + const Word16 envelope_e, /* i: scaled envelope exponent Q0 */ + Word16 *scale_e /* o: scale exponent Q0 */ ) { Word16 scale, tmp, k, s, s1; @@ -54,13 +54,12 @@ static Word16 tcx_arith_estimate_scale( #endif - /* compute normalised standard deviation and determine approximate scale */ - accu = L_deposit_l(0); + accu = L_deposit_l( 0 ); s = 30; move16(); - FOR (k = 0; k < L_frame; k++) + FOR( k = 0; k < L_frame; k++ ) { /* tmp = abs_spectrum[k] * envelope[k]; scale += tmp * tmp; */ @@ -68,44 +67,47 @@ static Word16 tcx_arith_estimate_scale( /* normalize, multiply, square */ s1 = 30; move16(); - if (abs_spectrum[k] != 0) + if ( abs_spectrum[k] != 0 ) { - s1 = norm_l(abs_spectrum[k]); + s1 = norm_l( abs_spectrum[k] ); } #ifdef BASOP_NOGLOB - tmp = mult_r(round_fx_o(L_shl(abs_spectrum[k], s1), &Overflow), envelope[k]); -#else /* BASOP_NOGLOB */ - tmp = mult_r(round_fx(L_shl(abs_spectrum[k], s1)), envelope[k]); + tmp = mult_r( round_fx_o( L_shl( abs_spectrum[k], s1 ), &Overflow ), envelope[k] ); +#else /* BASOP_NOGLOB */ + tmp = mult_r( round_fx( L_shl( abs_spectrum[k], s1 ) ), envelope[k] ); #endif /* BASOP_NOGLOB */ - L_tmp = L_mult0(tmp, tmp); - tmp = sub(shl(s1, 1), 1); + L_tmp = L_mult0( tmp, tmp ); + tmp = sub( shl( s1, 1 ), 1 ); /* adjust accu scaling */ s1 = s; move16(); - if (L_and(accu, 0x40000000) != 0) s = sub(s, 1); - s = s_min(s, tmp); + if ( L_and( accu, 0x40000000 ) != 0 ) + s = sub( s, 1 ); + s = s_min( s, tmp ); - s1 = sub(s1, s); - if (s1 != 0) accu = L_shr(accu, s1); + s1 = sub( s1, s ); + if ( s1 != 0 ) + accu = L_shr( accu, s1 ); /* scale and accumulate */ BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB accu = L_add_sat( accu, L_shr( L_tmp, sub( tmp, s ) ) ); #else - accu = L_add(accu, L_shr(L_tmp, sub(tmp, s))); + accu = L_add( accu, L_shr( L_tmp, sub( tmp, s ) ) ); #endif BASOP_SATURATE_WARNING_ON_EVS; } - s = sub(shl(add(abs_spectrum_e, envelope_e), 1), s); - if (accu == 0) accu = L_deposit_l(1); + s = sub( shl( add( abs_spectrum_e, envelope_e ), 1 ), s ); + if ( accu == 0 ) + accu = L_deposit_l( 1 ); /* scale = (float)sqrt((L_frame * 65536.0f*65536.0f*4.0f) / scale); */ - scale = BASOP_Util_Divide3216_Scale(accu, shl(L_frame, 2), &tmp); - s = sub(add(s, tmp), 15); - scale = ISqrt16(scale, &s); + scale = BASOP_Util_Divide3216_Scale( accu, shl( L_frame, 2 ), &tmp ); + s = sub( add( s, tmp ), 15 ); + scale = ISqrt16( scale, &s ); *scale_e = s; return scale; @@ -116,33 +118,33 @@ static Word16 tcx_arith_estimate_scale( * * *-------------------------------------------------------------------*/ -static void MinHeapify_i(Heap *H, Word16 i) +static void MinHeapify_i( Heap *H, Word16 i ) { Word16 left, right, largest; HeapElem T; - left = add(shl(i, 1), 1); - right = add(left, 1); + left = add( shl( i, 1 ), 1 ); + right = add( left, 1 ); largest = i; move16(); - if (LT_32(H->mElem[left].mScore, H->mElem[largest].mScore)) + if ( LT_32( H->mElem[left].mScore, H->mElem[largest].mScore ) ) { largest = left; move16(); } - if (LT_32(H->mElem[right].mScore, H->mElem[largest].mScore)) + if ( LT_32( H->mElem[right].mScore, H->mElem[largest].mScore ) ) { largest = right; move16(); } - WHILE (NE_16(largest, i)) + WHILE( NE_16( largest, i ) ) { T.mIndex = H->mElem[i].mIndex; move16(); - T.mScore = L_add(H->mElem[i].mScore, 0); + T.mScore = L_add( H->mElem[i].mScore, 0 ); H->mElem[i].mIndex = H->mElem[largest].mIndex; move16(); @@ -157,137 +159,136 @@ static void MinHeapify_i(Heap *H, Word16 i) i = largest; move16(); - left = add(shl(i, 1), 1); - right = add(left, 1); + left = add( shl( i, 1 ), 1 ); + right = add( left, 1 ); - if (LT_32(H->mElem[left].mScore, H->mElem[largest].mScore)) + if ( LT_32( H->mElem[left].mScore, H->mElem[largest].mScore ) ) { largest = left; move16(); } - if (LT_32(H->mElem[right].mScore, H->mElem[largest].mScore)) + if ( LT_32( H->mElem[right].mScore, H->mElem[largest].mScore ) ) { largest = right; move16(); } } - } /*-------------------------------------------------------------------* * tcx_arith_find_max_scale() * * *-------------------------------------------------------------------*/ -static Word16 tcx_arith_find_max_scale( /* Q15-e */ - const Word32 abs_spectrum[], /* i: absolute MDCT coefficients Q31-e */ - const Word16 abs_spectrum_e, /* i: MDCT exponent Q0 */ - const Word16 L_frame, /* i: number of spectral lines Q0 */ - const Word16 envelope[], /* i: scaled envelope Q15-e */ - const Word16 envelope_e, /* i: scaled envelope exponent Q0 */ - const Word16 exps[], /* i: expfp(-(int)envelope[]/2) Q15 */ - const Word16 deadzone, /* i: deadzone (0.5f = no deadzone) Q15 */ - Word16 *scale_e /* o: scale exponent Q0 */ +static Word16 tcx_arith_find_max_scale( /* Q15-e */ + const Word32 abs_spectrum[], /* i: absolute MDCT coefficients Q31-e */ + const Word16 abs_spectrum_e, /* i: MDCT exponent Q0 */ + const Word16 L_frame, /* i: number of spectral lines Q0 */ + const Word16 envelope[], /* i: scaled envelope Q15-e */ + const Word16 envelope_e, /* i: scaled envelope exponent Q0 */ + const Word16 exps[], /* i: expfp(-(int)envelope[]/2) Q15 */ + const Word16 deadzone, /* i: deadzone (0.5f = no deadzone) Q15 */ + Word16 *scale_e /* o: scale exponent Q0 */ ) { Word16 i, k, q, scale, tmp, s; Word32 p, L_tmp; - Heap heap = {{{0,0}},0}; /* silence a compiler warning */ + Heap heap = { { { 0, 0 } }, 0 }; /* silence a compiler warning */ Word16 tmpi1, tmpi2; - const Word32 limit = -325614240l/*-9.70406052784f Q25*/; /* = ln(1/16384): log of smallest allowed probability */ + const Word32 limit = -325614240l /*-9.70406052784f Q25*/; /* = ln(1/16384): log of smallest allowed probability */ /* Find the top most offending lines according to probability estimates */ - FOR (i = 0; i < kMaxNumHeapElems; i++) + FOR( i = 0; i < kMaxNumHeapElems; i++ ) { heap.mElem[i].mIndex = 0; move16(); - heap.mElem[i].mScore = L_deposit_l(0); + heap.mElem[i].mScore = L_deposit_l( 0 ); } - tmp = add(shl(kMaxNumHeapElems, 1), 1); - FOR (; i < tmp; i++) + tmp = add( shl( kMaxNumHeapElems, 1 ), 1 ); + FOR( ; i < tmp; i++ ) { - heap.mElem[i].mScore = L_deposit_h(0x7FFF); + heap.mElem[i].mScore = L_deposit_h( 0x7FFF ); } - FOR (k = 0; k < L_frame; k++) + FOR( k = 0; k < L_frame; k++ ) { - p = Mpy_32_16_1(abs_spectrum[k], envelope[k]); + p = Mpy_32_16_1( abs_spectrum[k], envelope[k] ); - IF (GT_32(p, heap.mElem[0].mScore)) + IF( GT_32( p, heap.mElem[0].mScore ) ) { heap.mElem[0].mScore = p; move32(); heap.mElem[0].mIndex = k; move16(); - MinHeapify_i(&heap, 0); + MinHeapify_i( &heap, 0 ); } } /* Make sure the scale is limited so that the offending lines don't cause probability underflow. */ /* Also limit scale to avoiding saturation of the gain quantizer */ /* scale = 1.0f/(float)sqrt(L_frame*0.5f); */ - tmp = 15-1; - scale = ISqrt16(L_frame, &tmp); + tmp = 15 - 1; + scale = ISqrt16( L_frame, &tmp ); move16(); *scale_e = tmp; move16(); - FOR (i = 0; i < kMaxNumHeapElems; i++) + FOR( i = 0; i < kMaxNumHeapElems; i++ ) { k = heap.mElem[i].mIndex; move16(); /* Get approximate maximum allowed magnitude */ /* q = (int)ceil(((limit - log(1.0f - (exps[k]/65536.0) * (exps[k]/65536.0))) / (-(int)envelope[k]/2/65536.0) - 1) / 2.0f); */ - L_tmp = L_sub(0x7FFFFFFF, L_mult(exps[k], exps[k])); - L_tmp = Mpy_32_16_1(BASOP_Util_Log2(L_tmp), 22713); /* Q25; 22713 -> 1/log2(e) */ - L_tmp = L_sub(limit, L_tmp); - tmp = negate(BASOP_Util_Divide3216_Scale(L_tmp, envelope[k], &s)); - s = sub(add(s, 6), sub(envelope_e, 1)); - L_tmp = L_shl(L_deposit_h(tmp), sub(s, 15+1)); /* Q16 */ - L_tmp = L_sub(L_tmp, 0x8000); - q = extract_h(L_add(L_tmp, 0xFFFF)); /* ceil */ + L_tmp = L_sub( 0x7FFFFFFF, L_mult( exps[k], exps[k] ) ); + L_tmp = Mpy_32_16_1( BASOP_Util_Log2( L_tmp ), 22713 ); /* Q25; 22713 -> 1/log2(e) */ + L_tmp = L_sub( limit, L_tmp ); + tmp = negate( BASOP_Util_Divide3216_Scale( L_tmp, envelope[k], &s ) ); + s = sub( add( s, 6 ), sub( envelope_e, 1 ) ); + L_tmp = L_shl( L_deposit_h( tmp ), sub( s, 15 + 1 ) ); /* Q16 */ + L_tmp = L_sub( L_tmp, 0x8000 ); + q = extract_h( L_add( L_tmp, 0xFFFF ) ); /* ceil */ /* Refinement: get the exact q */ - powfp_odd2(exps[k], q, &tmpi1, &tmpi2); + powfp_odd2( exps[k], q, &tmpi1, &tmpi2 ); - IF (GE_16(sub(tmpi1, tmpi2), 2)) /* q may be too low */ + IF( GE_16( sub( tmpi1, tmpi2 ), 2 ) ) /* q may be too low */ { - powfp_odd2(exps[k], add(q, 1), &tmpi1, &tmpi2); + powfp_odd2( exps[k], add( q, 1 ), &tmpi1, &tmpi2 ); - WHILE (GE_16(sub(tmpi1, tmpi2), 2)) + WHILE( GE_16( sub( tmpi1, tmpi2 ), 2 ) ) { - q = add(q, 1); - powfp_odd2(exps[k], add(q, 1), &tmpi1, &tmpi2); + q = add( q, 1 ); + powfp_odd2( exps[k], add( q, 1 ), &tmpi1, &tmpi2 ); } } - ELSE /* q is too high */ + ELSE /* q is too high */ { - q = sub(q, 1); - powfp_odd2(exps[k], q, &tmpi1, &tmpi2); + q = sub( q, 1 ); + powfp_odd2( exps[k], q, &tmpi1, &tmpi2 ); - WHILE (LT_16(sub(tmpi1, tmpi2), 2)) + WHILE( LT_16( sub( tmpi1, tmpi2 ), 2 ) ) { - q = sub(q, 1); - powfp_odd2(exps[k], q, &tmpi1, &tmpi2); + q = sub( q, 1 ); + powfp_odd2( exps[k], q, &tmpi1, &tmpi2 ); } } /* Find the largest scale so that the quantized magnitude is at most q */ /* p = (q+0.99f-deadzone)/(abs_spectrum[k] + 0.000001f); */ - L_tmp = L_add(L_deposit_h(q), L_mult(sub(32440/*0.99f Q15*/, deadzone), 1)); /* Q16 */ - tmp = BASOP_Util_Divide3232_Scale(L_tmp, L_add(abs_spectrum[k], 1), &s); - s = sub(add(s, 15), abs_spectrum_e); + L_tmp = L_add( L_deposit_h( q ), L_mult( sub( 32440 /*0.99f Q15*/, deadzone ), 1 ) ); /* Q16 */ + tmp = BASOP_Util_Divide3232_Scale( L_tmp, L_add( abs_spectrum[k], 1 ), &s ); + s = sub( add( s, 15 ), abs_spectrum_e ); - k = norm_s(tmp); - tmp = shl(tmp, k); - s = sub(s, k); + k = norm_s( tmp ); + tmp = shl( tmp, k ); + s = sub( s, k ); /* assert((int)(abs_spectrum[k] * p + deadzone) <= q); */ /* scale = min(scale, p); */ - IF (compMantExp16Unorm(tmp, s, scale, *scale_e) < 0) + IF( compMantExp16Unorm( tmp, s, scale, *scale_e ) < 0 ) { scale = tmp; move16(); @@ -303,16 +304,16 @@ static Word16 tcx_arith_find_max_scale( /* Q15-e */ * tcx_arith_find_kMax() * * - * Returns: index of highest freq. nonzero line (-1 if all zeros) + * Returns: index of highest freq. nonzero line (-1 if all zeros) *-------------------------------------------------------------------*/ static Word16 tcx_arith_find_kMax( - const Word32 abs_spectrum[], /* i: absolute MDCT coefficients Q31-e */ - const Word16 abs_spectrum_e, /* i: MDCT exponent Q0 */ - const Word16 L_frame, /* i: number of spectral lines Q0 */ - const Word16 scale, /* i: scalar quantizer scale Q15-e */ - const Word16 scale_e, /* i: scale exponent Q0 */ - const Word16 deadzone, /* i: deadzone (0.5f = no deadzone) Q15 */ - const Word8 deadzone_flags[] /* i: line-wise deadzone control */ + const Word32 abs_spectrum[], /* i: absolute MDCT coefficients Q31-e */ + const Word16 abs_spectrum_e, /* i: MDCT exponent Q0 */ + const Word16 L_frame, /* i: number of spectral lines Q0 */ + const Word16 scale, /* i: scalar quantizer scale Q15-e */ + const Word16 scale_e, /* i: scale exponent Q0 */ + const Word16 deadzone, /* i: deadzone (0.5f = no deadzone) Q15 */ + const Word8 deadzone_flags[] /* i: line-wise deadzone control */ ) { Word16 kMax; @@ -321,12 +322,12 @@ static Word16 tcx_arith_find_kMax( move32(); move32(); - tmp[0] = L_shr(L_mac(0x7FFFFFFF, deadzone, (Word16)0x8000), abs_spectrum_e); /* 1.0f - deadzone scaled to MDCT exponent */ - tmp[1] = L_shr(0x7FFFFFFF, abs_spectrum_e); /* 1.0f scaled to MDCT exponent */ + tmp[0] = L_shr( L_mac( 0x7FFFFFFF, deadzone, (Word16) 0x8000 ), abs_spectrum_e ); /* 1.0f - deadzone scaled to MDCT exponent */ + tmp[1] = L_shr( 0x7FFFFFFF, abs_spectrum_e ); /* 1.0f scaled to MDCT exponent */ - FOR (kMax = sub(L_frame, 1); kMax >= 0; kMax--) + FOR( kMax = sub( L_frame, 1 ); kMax >= 0; kMax-- ) { - IF (GE_32(L_shl(Mpy_32_16_1(abs_spectrum[kMax], scale), scale_e), tmp[deadzone_flags[kMax]])) + IF( GE_32( L_shl( Mpy_32_16_1( abs_spectrum[kMax], scale ), scale_e ), tmp[deadzone_flags[kMax]] ) ) { BREAK; } @@ -340,35 +341,35 @@ static Word16 tcx_arith_find_kMax( * tcx_arith_rateloop() * * - * Returns: best scale Q15-e + * Returns: best scale Q15-e *-------------------------------------------------------------------*/ static Word16 tcx_arith_rateloop( - const Word32 abs_spectrum[], /* i: absolute MDCT coefficients Q31-e */ - const Word16 abs_spectrum_e, /* i: MDCT exponent Q0 */ - const Word16 L_frame, /* i: number of spectral lines Q0 */ - const Word16 envelope[], /* i: scaled envelope Q15-e */ - const Word16 envelope_e, /* i: scaled envelope exponent Q0 */ - const Word16 exps[], /* i: expfp(-(int)envelope[]/2) Q15 */ - const Word16 target_bits, /* i: target bit budget Q0 */ - const Word16 deadzone, /* i: deadzone (0.5f = no deadzone) Q15 */ - const Word8 deadzone_flags[], /* i: line-wise deadzone control Q0 */ - Word16 *target_bits_fac, /* i/o: scale estimator compensation Q14 */ - Word16 *scale_e /* o: scale exponent Q0 */ + const Word32 abs_spectrum[], /* i: absolute MDCT coefficients Q31-e */ + const Word16 abs_spectrum_e, /* i: MDCT exponent Q0 */ + const Word16 L_frame, /* i: number of spectral lines Q0 */ + const Word16 envelope[], /* i: scaled envelope Q15-e */ + const Word16 envelope_e, /* i: scaled envelope exponent Q0 */ + const Word16 exps[], /* i: expfp(-(int)envelope[]/2) Q15 */ + const Word16 target_bits, /* i: target bit budget Q0 */ + const Word16 deadzone, /* i: deadzone (0.5f = no deadzone) Q15 */ + const Word8 deadzone_flags[], /* i: line-wise deadzone control Q0 */ + Word16 *target_bits_fac, /* i/o: scale estimator compensation Q14 */ + Word16 *scale_e /* o: scale exponent Q0 */ ) { Word16 k, kMax, q; Word16 s, adjust; Word16 fixed_bits[2][N_MAX_ARI]; Word32 max_complexity; - Word16 iter; /* rate loop iteration counter */ - Word16 scale; /* SQ scale factor to try next */ - Word16 scale_best; /* best SQ scale factor */ - Word16 scale_max; /* maximum allowable scale factor */ - Word16 lob; /* lower bound of SQ scale factor */ - Word16 hib; /* upper bound of SQ scale factor */ - Word16 flag; /* 1:bit surplus, -1:bit deficit, 0:unknown */ - Word32 complexity; /* cumulative rate loop complexity */ - Word32 bits; /* number of bits (approximate) Q9 */ + Word16 iter; /* rate loop iteration counter */ + Word16 scale; /* SQ scale factor to try next */ + Word16 scale_best; /* best SQ scale factor */ + Word16 scale_max; /* maximum allowable scale factor */ + Word16 lob; /* lower bound of SQ scale factor */ + Word16 hib; /* upper bound of SQ scale factor */ + Word16 flag; /* 1:bit surplus, -1:bit deficit, 0:unknown */ + Word32 complexity; /* cumulative rate loop complexity */ + Word32 bits; /* number of bits (approximate) Q9 */ Word32 L_tmp; Word16 tmp, tmp3; Word32 tmp2; @@ -377,145 +378,145 @@ static Word16 tcx_arith_rateloop( #endif + scale = tcx_arith_estimate_scale( abs_spectrum, abs_spectrum_e, L_frame, envelope, envelope_e, &tmp ); + scale = mult_r( scale, *target_bits_fac ); + tmp = add( tmp, 1 ); - scale = tcx_arith_estimate_scale(abs_spectrum, abs_spectrum_e, L_frame, envelope, envelope_e, &tmp); - scale = mult_r(scale, *target_bits_fac); - tmp = add(tmp, 1); - - scale_max = tcx_arith_find_max_scale(abs_spectrum, abs_spectrum_e, L_frame, envelope, envelope_e, exps, deadzone, scale_e); + scale_max = tcx_arith_find_max_scale( abs_spectrum, abs_spectrum_e, L_frame, envelope, envelope_e, exps, deadzone, scale_e ); #ifdef BASOP_NOGLOB - scale = shl_o(scale, sub(tmp, *scale_e), &Overflow); + scale = shl_o( scale, sub( tmp, *scale_e ), &Overflow ); #else BASOP_SATURATE_WARNING_OFF_EVS; - scale = shl(scale, sub(tmp, *scale_e)); + scale = shl( scale, sub( tmp, *scale_e ) ); BASOP_SATURATE_WARNING_ON_EVS; #endif - scale = s_min(scale, scale_max); + scale = s_min( scale, scale_max ); - scale_best = scale; + scale_best = scale; move16(); - lob = 0; + lob = 0; move16(); - hib = 0; + hib = 0; move16(); - flag = 0; + flag = 0; move16(); - complexity = L_deposit_l(0); - bits = L_deposit_l(0); - iter = 0; + complexity = L_deposit_l( 0 ); + bits = L_deposit_l( 0 ); + iter = 0; move16(); - max_complexity = L_mult0(96, L_frame); + max_complexity = L_mult0( 96, L_frame ); /* Precalculate fixed bit costs */ - FOR (k = 0; k < L_frame; k++) + FOR( k = 0; k < L_frame; k++ ) { /* fixed_bits[0][k] = -log2f(1 - exps[k] / 65536.0f); */ - L_tmp = L_mac(0x7FFFFFFF, exps[k], (Word16)0x8000); /* Q31 */ - L_tmp = L_negate(BASOP_Util_Log2(L_tmp)); /* Q25 */ - fixed_bits[0][k] = round_fx(L_tmp); /* Q9 */ + L_tmp = L_mac( 0x7FFFFFFF, exps[k], (Word16) 0x8000 ); /* Q31 */ + L_tmp = L_negate( BASOP_Util_Log2( L_tmp ) ); /* Q25 */ + fixed_bits[0][k] = round_fx( L_tmp ); /* Q9 */ /* fixed_bits[1][k] = 1 - s*0.5f*LOG2_E - log2f(1 - (exps[k]/65536.0f) * (exps[k]/65536.0f)); */ - L_tmp = L_msu(0x7FFFFFFF, exps[k], exps[k]); /* Q31 */ - L_tmp = BASOP_Util_Log2(L_tmp); /* Q25 */ - L_tmp = L_sub(1<<25, L_tmp); - L_tmp = L_sub(L_tmp, L_shl(L_mult0(mult_r(envelope[k], LOG2_E), 1<<10), envelope_e)); - fixed_bits[1][k] = round_fx(L_tmp); /* Q9 */ + L_tmp = L_msu( 0x7FFFFFFF, exps[k], exps[k] ); /* Q31 */ + L_tmp = BASOP_Util_Log2( L_tmp ); /* Q25 */ + L_tmp = L_sub( 1 << 25, L_tmp ); + L_tmp = L_sub( L_tmp, L_shl( L_mult0( mult_r( envelope[k], LOG2_E ), 1 << 10 ), envelope_e ) ); + fixed_bits[1][k] = round_fx( L_tmp ); /* Q9 */ } - tmp2 = L_msu0(L_sub(max_complexity, 48), L_frame, 11); - WHILE (LT_32(complexity, tmp2)) + tmp2 = L_msu0( L_sub( max_complexity, 48 ), L_frame, 11 ); + WHILE( LT_32( complexity, tmp2 ) ) { - kMax = tcx_arith_find_kMax(abs_spectrum, abs_spectrum_e, L_frame, scale, *scale_e, deadzone, deadzone_flags); + kMax = tcx_arith_find_kMax( abs_spectrum, abs_spectrum_e, L_frame, scale, *scale_e, deadzone, deadzone_flags ); - complexity = L_mac0(L_mac0(L_add(complexity, 16+2), sub(L_frame, kMax), 5), kMax, 2); + complexity = L_mac0( L_mac0( L_add( complexity, 16 + 2 ), sub( L_frame, kMax ), 5 ), kMax, 2 ); - bits = /*estimator_undershoot * kMax +*/ L_deposit_l(1<<9); /* Q9 */ + bits = /*estimator_undershoot * kMax +*/ L_deposit_l( 1 << 9 ); /* Q9 */ - L_tmp = L_mult(deadzone, 1); /* Q16 */ - tmp = add(sub(abs_spectrum_e, 15), *scale_e); - tmp3 = add(2+9, envelope_e); - FOR (k = 0; k <= kMax; k++) + L_tmp = L_mult( deadzone, 1 ); /* Q16 */ + tmp = add( sub( abs_spectrum_e, 15 ), *scale_e ); + tmp3 = add( 2 + 9, envelope_e ); + FOR( k = 0; k <= kMax; k++ ) { - q = extract_h(L_add(L_shl(Mpy_32_16_1(abs_spectrum[k], scale), tmp), L_tmp)); - bits = L_mac0(bits, fixed_bits[s_min(1,q)][k], 1); /* Q9 */ - bits = L_mac0(bits, round_fx(L_shl(L_mult0(mult_r(envelope[k], LOG2_E), q), tmp3)), 1); + q = extract_h( L_add( L_shl( Mpy_32_16_1( abs_spectrum[k], scale ), tmp ), L_tmp ) ); + bits = L_mac0( bits, fixed_bits[s_min( 1, q )][k], 1 ); /* Q9 */ + bits = L_mac0( bits, round_fx( L_shl( L_mult0( mult_r( envelope[k], LOG2_E ), q ), tmp3 ) ), 1 ); } - complexity = L_mac0(L_add(complexity, 32), 6, kMax); + complexity = L_mac0( L_add( complexity, 32 ), 6, kMax ); - IF (iter == 0) /* First rate loop iteration */ + IF( iter == 0 ) /* First rate loop iteration */ { - IF (LT_16(scale, scale_max)) /* Only update in non-degenerate case */ + IF( LT_16( scale, scale_max ) ) /* Only update in non-degenerate case */ { /* Update estimator temporal compensation factor */ - tmp = BASOP_Util_Divide3232_Scale(L_mult0(target_bits, 1<<9), bits, &s); + tmp = BASOP_Util_Divide3232_Scale( L_mult0( target_bits, 1 << 9 ), bits, &s ); #ifdef BASOP_NOGLOB - tmp = shl_o(mult_r(*target_bits_fac, tmp), s, &Overflow); + tmp = shl_o( mult_r( *target_bits_fac, tmp ), s, &Overflow ); #else BASOP_SATURATE_WARNING_OFF_EVS; - tmp = shl(mult_r(*target_bits_fac, tmp), s); + tmp = shl( mult_r( *target_bits_fac, tmp ), s ); BASOP_SATURATE_WARNING_ON_EVS; #endif - tmp = s_min(tmp, 20480/*1.25f Q14*/); - tmp = s_max(tmp, 12288/*0.75f Q14*/); + tmp = s_min( tmp, 20480 /*1.25f Q14*/ ); + tmp = s_max( tmp, 12288 /*0.75f Q14*/ ); *target_bits_fac = tmp; move16(); } } - IF (LE_32(bits, L_mult0(target_bits, 1<<9))) /* Bits leftover => scale is too small */ + IF( LE_32( bits, L_mult0( target_bits, 1 << 9 ) ) ) /* Bits leftover => scale is too small */ { test(); - IF (flag <= 0 || GE_16(scale, scale_best)) + IF( flag <= 0 || GE_16( scale, scale_best ) ) { scale_best = scale; move16(); - flag = 1; + flag = 1; move16(); } lob = scale; move16(); - IF (hib > 0) /* Bisection search */ + IF( hib > 0 ) /* Bisection search */ { - scale = add(shr(lob, 1), shr(hib, 1)); + scale = add( shr( lob, 1 ), shr( hib, 1 ) ); } - ELSE /* Initial scale adaptation */ + ELSE /* Initial scale adaptation */ { /* adjust = 1.25f * target_bits / (float)bits; */ - tmp = BASOP_Util_Divide3232_Scale(L_mult0(target_bits, 0x280), bits, &s); + tmp = BASOP_Util_Divide3232_Scale( L_mult0( target_bits, 0x280 ), bits, &s ); #ifdef BASOP_NOGLOB - adjust = shl_o(tmp, sub(s, 1), &Overflow); /* Q14 */ - scale = shl_o(mult_r(scale, adjust), 1, &Overflow); + adjust = shl_o( tmp, sub( s, 1 ), &Overflow ); /* Q14 */ + scale = shl_o( mult_r( scale, adjust ), 1, &Overflow ); #else - BASOP_SATURATE_WARNING_OFF_EVS; /* adjust limited to <= 2.0, scale to <= scale_max */ - adjust = shl(tmp, sub(s, 1)); /* Q14 */ - scale = shl(mult_r(scale, adjust), 1); + BASOP_SATURATE_WARNING_OFF_EVS; /* adjust limited to <= 2.0, scale to <= scale_max */ + adjust = shl( tmp, sub( s, 1 ) ); /* Q14 */ + scale = shl( mult_r( scale, adjust ), 1 ); BASOP_SATURATE_WARNING_ON_EVS; #endif - scale = s_min(scale, scale_max); + scale = s_min( scale, scale_max ); } } - ELSE /* Ran out of bits => scale is too large */ + ELSE /* Ran out of bits => scale is too large */ { hib = scale; move16(); - IF (lob > 0) /* Bisection search */ + IF( lob > 0 ) /* Bisection search */ { - scale = add(shr(lob, 1), shr(hib, 1)); + scale = add( shr( lob, 1 ), shr( hib, 1 ) ); } - ELSE { /* Initial scale adaptation */ + ELSE + { /* Initial scale adaptation */ /* adjust = 0.8f * target_bits / (float)bits; */ - tmp = BASOP_Util_Divide3232_Scale(L_mult0(target_bits, 0x19A), bits, &s); - adjust = shl(tmp, s); /* Q15 */ - adjust = s_max(adjust, 16384/*0.5f Q15*/); - scale = mult_r(scale, adjust); + tmp = BASOP_Util_Divide3232_Scale( L_mult0( target_bits, 0x19A ), bits, &s ); + adjust = shl( tmp, s ); /* Q15 */ + adjust = s_max( adjust, 16384 /*0.5f Q15*/ ); + scale = mult_r( scale, adjust ); } - IF (flag <= 0) + IF( flag <= 0 ) { scale_best = scale; move16(); @@ -523,7 +524,7 @@ static Word16 tcx_arith_rateloop( move16(); } } - iter = add(iter, 1); + iter = add( iter, 1 ); } @@ -533,16 +534,16 @@ static Word16 tcx_arith_rateloop( * tcx_arith_encode() * * - * Returns: number of bits consumed + * Returns: number of bits consumed *-------------------------------------------------------------------*/ static Word16 tcx_arith_encode( - Word16 q_abs_spectrum[], /* i/o: scalar quantized absolute spectrum Q0 */ - const Word16 signs[], /* i: signs */ - const Word16 kMax, /* i: number of nonzero spectral lines to code Q0 */ - Word16 L_frame, /* i: nominal number of spectral lines Q0 */ - const Word16 exps[], /* i: expfp(-(int)envelope[]/2) Q15 */ - Word16 target_bits, /* i: target bit budget Q0 */ - Word16 prm[] /* o: bit-stream Q0 */ + Word16 q_abs_spectrum[], /* i/o: scalar quantized absolute spectrum Q0 */ + const Word16 signs[], /* i: signs */ + const Word16 kMax, /* i: number of nonzero spectral lines to code Q0 */ + Word16 L_frame, /* i: nominal number of spectral lines Q0 */ + const Word16 exps[], /* i: expfp(-(int)envelope[]/2) Q15 */ + Word16 target_bits, /* i: target bit budget Q0 */ + Word16 prm[] /* o: bit-stream Q0 */ ) { TastatEnc as, as_lastgood; @@ -552,10 +553,9 @@ static Word16 tcx_arith_encode( Word16 tmpi1, tmpi2; - /* Final coding */ - ari_start_encoding_14bits_fx(&as); - ari_copy_states_fx(&as, &as_lastgood); + ari_start_encoding_14bits_fx( &as ); + ari_copy_states_fx( &as, &as_lastgood ); bp = 0; move16(); bp_lastgood = 0; @@ -563,108 +563,108 @@ static Word16 tcx_arith_encode( kEncoded = kMax; move16(); - FOR (k = 0; k <= kMax; k++) + FOR( k = 0; k <= kMax; k++ ) { - IF (q_abs_spectrum[k] == 0) + IF( q_abs_spectrum[k] == 0 ) { - assert(exps[k] >= 2); - bp = ari_encode_14bits_range_fx(prm, bp, target_bits, &as, shr(exps[k], 1), 16384); + assert( exps[k] >= 2 ); + bp = ari_encode_14bits_range_fx( prm, bp, target_bits, &as, shr( exps[k], 1 ), 16384 ); } - ELSE /* q_abs_spectrum[k] != 0 */ + ELSE /* q_abs_spectrum[k] != 0 */ { - powfp_odd2(exps[k], q_abs_spectrum[k], &tmpi1, &tmpi2); + powfp_odd2( exps[k], q_abs_spectrum[k], &tmpi1, &tmpi2 ); - WHILE (LT_16(tmpi1, add(tmpi2, 2))) + WHILE( LT_16( tmpi1, add( tmpi2, 2 ) ) ) { - q_abs_spectrum[k] = sub(q_abs_spectrum[k], 1); + q_abs_spectrum[k] = sub( q_abs_spectrum[k], 1 ); move16(); - powfp_odd2(exps[k], q_abs_spectrum[k], &tmpi1, &tmpi2); + powfp_odd2( exps[k], q_abs_spectrum[k], &tmpi1, &tmpi2 ); } - bp = ari_encode_14bits_range_fx(prm, bp, target_bits, &as, shr(tmpi2, 1), shr(tmpi1, 1)); - bp = ari_encode_14bits_sign_fx(prm, bp, target_bits, &as, signs[k]); + bp = ari_encode_14bits_range_fx( prm, bp, target_bits, &as, shr( tmpi2, 1 ), shr( tmpi1, 1 ) ); + bp = ari_encode_14bits_sign_fx( prm, bp, target_bits, &as, signs[k] ); } /* Check bit budget status */ - IF (ari_encode_overflow_fx(&as)) /* no bits left */ + IF( ari_encode_overflow_fx( &as ) ) /* no bits left */ { /* printf("\noverflow at %d\n\n", k); */ - IF (GT_16(q_abs_spectrum[k], 1)) /* Lower magnitude is still > 0 */ + IF( GT_16( q_abs_spectrum[k], 1 ) ) /* Lower magnitude is still > 0 */ { /* Restore state */ - ari_copy_states_fx(&as_lastgood, &as); + ari_copy_states_fx( &as_lastgood, &as ); bp = bp_lastgood; move16(); /* Quantize to lower magnitude */ - q_abs_spectrum[k] = sub(q_abs_spectrum[k], 1); + q_abs_spectrum[k] = sub( q_abs_spectrum[k], 1 ); move16(); /* Retry encoding */ - powfp_odd2(exps[k], q_abs_spectrum[k], &tmpi1, &tmpi2); + powfp_odd2( exps[k], q_abs_spectrum[k], &tmpi1, &tmpi2 ); - bp = ari_encode_14bits_range_fx(prm, bp, target_bits, &as, shr(tmpi2, 1), shr(tmpi1, 1)); - bp = ari_encode_14bits_sign_fx(prm, bp, target_bits, &as, signs[k]); + bp = ari_encode_14bits_range_fx( prm, bp, target_bits, &as, shr( tmpi2, 1 ), shr( tmpi1, 1 ) ); + bp = ari_encode_14bits_sign_fx( prm, bp, target_bits, &as, signs[k] ); - IF (!ari_encode_overflow_fx(&as)) /* Success */ + IF( !ari_encode_overflow_fx( &as ) ) /* Success */ { - ari_copy_states_fx(&as, &as_lastgood); + ari_copy_states_fx( &as, &as_lastgood ); bp_lastgood = bp; move16(); kEncoded = k; move16(); - set16_fx(q_abs_spectrum+k+1, 0, sub(kMax, k)); + set16_fx( q_abs_spectrum + k + 1, 0, sub( kMax, k ) ); BREAK; } } - ari_copy_states_fx(&as_lastgood, &as); + ari_copy_states_fx( &as_lastgood, &as ); bp = bp_lastgood; move16(); - kEncoded = sub(k, 1); + kEncoded = sub( k, 1 ); - set16_fx(q_abs_spectrum+k, 0, sub(kMax, kEncoded)); + set16_fx( q_abs_spectrum + k, 0, sub( kMax, kEncoded ) ); BREAK; } ELSE { - ari_copy_states_fx(&as, &as_lastgood); + ari_copy_states_fx( &as, &as_lastgood ); bp_lastgood = bp; move16(); } } /* Send zeros until L_frame */ - tmpi1 = add(kEncoded, 1); - kEncoded = sub(L_frame, 1); - FOR (k = tmpi1; k < L_frame; k++) + tmpi1 = add( kEncoded, 1 ); + kEncoded = sub( L_frame, 1 ); + FOR( k = tmpi1; k < L_frame; k++ ) { - assert(exps[k] >= 1); + assert( exps[k] >= 1 ); - bp = ari_encode_14bits_range_fx(prm, bp, target_bits, &as, shr(exps[k],1), 16384); + bp = ari_encode_14bits_range_fx( prm, bp, target_bits, &as, shr( exps[k], 1 ), 16384 ); /* Check bit budget status */ - IF (ari_encode_overflow_fx(&as)) /* no bits left */ + IF( ari_encode_overflow_fx( &as ) ) /* no bits left */ { - ari_copy_states_fx(&as_lastgood, &as); + ari_copy_states_fx( &as_lastgood, &as ); bp = bp_lastgood; move16(); - kEncoded = sub(k, 1); + kEncoded = sub( k, 1 ); BREAK; } ELSE { - ari_copy_states_fx(&as, &as_lastgood); + ari_copy_states_fx( &as, &as_lastgood ); bp_lastgood = bp; move16(); } } - IF (EQ_16(kEncoded, sub(L_frame, 1))) /* RESQ bits possibly available */ + IF( EQ_16( kEncoded, sub( L_frame, 1 ) ) ) /* RESQ bits possibly available */ { /* Limit target bits to actually needed bits */ - target_bits = add(add(bp, 16), extract_l(as.value)); + target_bits = add( add( bp, 16 ), extract_l( as.value ) ); } - return ari_done_cbr_encoding_14bits_fx(prm, bp, target_bits, &as); + return ari_done_cbr_encoding_14bits_fx( prm, bp, target_bits, &as ); } /*-------------------------------------------------------------------* * tcx_arith_encode_envelope_fx() @@ -672,26 +672,26 @@ static Word16 tcx_arith_encode( * *-------------------------------------------------------------------*/ void tcx_arith_encode_envelope_fx( - Word32 spectrum[], /* i/o: MDCT coefficients Q31-e */ - Word16 *spectrum_e, /* i/o: MDCT exponent Q0 */ - Word16 signs[], /* o: signs (spectrum[.]<0) Q0 */ - const Word16 L_frame, /* i: frame or MDCT length Q0 */ - const Word16 L_spec, /* i: frame or MDCT length Q0 */ - Encoder_State *st, /* i/o: coder state */ - const Word16 A_ind[], /* i: quantised LPC coefficients Q12 */ - Word16 target_bits, /* i: number of available bits Q0 */ - Word16 prm[], /* o: bitstream parameters Q0 */ - const Word8 use_hm, /* i: use HM in current frame? */ - Word16 prm_hm[], /* o: HM parameter area Q0 */ - const Word16 tcxltp_pitch, /* i: TCX LTP pitch in FD, -1 if n/a Q0*/ - Word16 *arith_bits, /* o: bits used for ari. coding Q0 */ - Word16 *signaling_bits, /* o: bits used for signaling Q0 */ - Word16 *nf_seed, /* o: noise filling seed Q0 */ - const Word16 low_complexity /* i: low-complexity flag Q0 */ + Word32 spectrum[], /* i/o: MDCT coefficients Q31-e */ + Word16 *spectrum_e, /* i/o: MDCT exponent Q0 */ + Word16 signs[], /* o: signs (spectrum[.]<0) Q0 */ + const Word16 L_frame, /* i: frame or MDCT length Q0 */ + const Word16 L_spec, /* i: frame or MDCT length Q0 */ + Encoder_State *st, /* i/o: coder state */ + const Word16 A_ind[], /* i: quantised LPC coefficients Q12 */ + Word16 target_bits, /* i: number of available bits Q0 */ + Word16 prm[], /* o: bitstream parameters Q0 */ + const Word8 use_hm, /* i: use HM in current frame? */ + Word16 prm_hm[], /* o: HM parameter area Q0 */ + const Word16 tcxltp_pitch, /* i: TCX LTP pitch in FD, -1 if n/a Q0*/ + Word16 *arith_bits, /* o: bits used for ari. coding Q0 */ + Word16 *signaling_bits, /* o: bits used for signaling Q0 */ + Word16 *nf_seed, /* o: noise filling seed Q0 */ + const Word16 low_complexity /* i: low-complexity flag Q0 */ ) { - Word32 env[N_MAX_ARI]; /* unscaled envelope (Q16) */ - Word16 *envelope; /* scaled envelope (Q15-e) */ + Word32 env[N_MAX_ARI]; /* unscaled envelope (Q16) */ + Word16 *envelope; /* scaled envelope (Q15-e) */ Word16 envelope_e; Word16 exponents[N_MAX_ARI]; /* Q15 */ Word16 L_spec_core; @@ -711,103 +711,104 @@ void tcx_arith_encode_envelope_fx( Flag Carry = 0; #endif - assert(L_spec <= N_MAX_ARI); + assert( L_spec <= N_MAX_ARI ); - hTcxCfg = st->hTcxCfg; - deadzone = hTcxCfg->sq_rounding; + hTcxCfg = st->hTcxCfg; + deadzone = hTcxCfg->sq_rounding; move16(); deadzone_flags = hTcxEnc->memQuantZeros_fx; *signaling_bits = 0; move16(); - assert(st->enableTcxLpc); - gamma_w = 32767/*1.0f Q15*/; + assert( st->enableTcxLpc ); + gamma_w = 32767 /*1.0f Q15*/; move16(); gamma_uw = st->inv_gamma; move16(); - tcx_arith_render_envelope(A_ind, L_frame, L_spec, hTcxCfg->preemph_fac, gamma_w, gamma_uw, env); + tcx_arith_render_envelope( A_ind, L_frame, L_spec, hTcxCfg->preemph_fac, gamma_w, gamma_uw, env ); - FOR (k = 0; k < L_spec; k++) + FOR( k = 0; k < L_spec; k++ ) { - signs[k] = extract_l(L_lshr(spectrum[k], 31)); - if (spectrum[k] < 0) + signs[k] = extract_l( L_lshr( spectrum[k], 31 ) ); + if ( spectrum[k] < 0 ) { - spectrum[k] = L_abs(spectrum[k]); + spectrum[k] = L_abs( spectrum[k] ); move32(); } } - IF (use_hm != 0) + IF( use_hm != 0 ) { - tcx_hm_analyse_fx(spectrum, spectrum_e, L_spec, env, target_bits, hTcxCfg->coder_type, prm_hm, tcxltp_pitch, hTcxEnc->tcxltp_gain, &hm_bits); + tcx_hm_analyse_fx( spectrum, spectrum_e, L_spec, env, target_bits, hTcxCfg->coder_type, prm_hm, tcxltp_pitch, hTcxEnc->tcxltp_gain, &hm_bits ); - target_bits = sub(target_bits, hm_bits); - *signaling_bits = add(*signaling_bits, hm_bits); + target_bits = sub( target_bits, hm_bits ); + *signaling_bits = add( *signaling_bits, hm_bits ); move16(); } ELSE { - prm_hm[0] = 0; /* just to be sure */ move16(); - hm_bits = 0; + prm_hm[0] = 0; /* just to be sure */ + move16(); + hm_bits = 0; move16(); } L_spec_core = L_spec; move16(); - if (st->igf) + if ( st->igf ) { - L_spec_core = s_min(L_spec_core, st->hIGFEnc->infoStartLine); + L_spec_core = s_min( L_spec_core, st->hIGFEnc->infoStartLine ); } - envelope = (Word16*)env; + envelope = (Word16 *) env; - tcx_arith_scale_envelope( L_spec, L_spec_core, env, target_bits, low_complexity, envelope, &envelope_e); + tcx_arith_scale_envelope( L_spec, L_spec_core, env, target_bits, low_complexity, envelope, &envelope_e ); - tmp = sub(envelope_e, 1+15); - FOR (k = 0; k < L_spec; k++) + tmp = sub( envelope_e, 1 + 15 ); + FOR( k = 0; k < L_spec; k++ ) { - exponents[k] = round_fx(expfp(envelope[k], tmp)); + exponents[k] = round_fx( expfp( envelope[k], tmp ) ); } - scale = tcx_arith_rateloop(spectrum, *spectrum_e, L_spec, envelope, envelope_e, exponents, target_bits, deadzone, deadzone_flags, &(hTcxEnc->tcx_target_bits_fac), &scale_e); + scale = tcx_arith_rateloop( spectrum, *spectrum_e, L_spec, envelope, envelope_e, exponents, target_bits, deadzone, deadzone_flags, &( hTcxEnc->tcx_target_bits_fac ), &scale_e ); /* Final quantization */ kMax = tcx_arith_find_kMax( spectrum, *spectrum_e, L_spec, scale, scale_e, deadzone, deadzone_flags ); - q_spectrum = (Word16*)env; /* Reuse buffer */ + q_spectrum = (Word16 *) env; /* Reuse buffer */ - L_tmp = L_mult(deadzone, 1); /* Q16 */ - tmp = add(sub(*spectrum_e, 15), scale_e); - FOR (k = 0; k <= kMax; k++) + L_tmp = L_mult( deadzone, 1 ); /* Q16 */ + tmp = add( sub( *spectrum_e, 15 ), scale_e ); + FOR( k = 0; k <= kMax; k++ ) { /* quantise using dead-zone */ - q_spectrum[k] = extract_h(L_add(L_shl(Mpy_32_16_1(spectrum[k], scale), tmp), L_tmp)); + q_spectrum[k] = extract_h( L_add( L_shl( Mpy_32_16_1( spectrum[k], scale ), tmp ), L_tmp ) ); } /* Final encoding */ - *arith_bits = tcx_arith_encode( q_spectrum, signs, kMax, L_spec, exponents, target_bits, prm); + *arith_bits = tcx_arith_encode( q_spectrum, signs, kMax, L_spec, exponents, target_bits, prm ); /* Multiply back the signs */ - L_tmp2 = L_deposit_l(0); - FOR (k = 0; k <= kMax; k++) + L_tmp2 = L_deposit_l( 0 ); + FOR( k = 0; k <= kMax; k++ ) { #ifdef BASOP_NOGLOB - L_tmp2 = L_macNs_co(L_tmp2, q_spectrum[k], k, &Carry, &Overflow); + L_tmp2 = L_macNs_co( L_tmp2, q_spectrum[k], k, &Carry, &Overflow ); #else /* BASOP_NOGLOB */ - L_tmp2 = L_macNs(L_tmp2, q_spectrum[k], k); + L_tmp2 = L_macNs( L_tmp2, q_spectrum[k], k ); #endif - if (signs[k] != 0) L_tmp = L_mult(q_spectrum[k], -(1<< (30 - SPEC_EXP_DEC))); - if (signs[k] == 0) L_tmp = L_mult(q_spectrum[k], 1 << (30 - SPEC_EXP_DEC)); + if ( signs[k] != 0 ) + L_tmp = L_mult( q_spectrum[k], -( 1 << ( 30 - SPEC_EXP_DEC ) ) ); + if ( signs[k] == 0 ) + L_tmp = L_mult( q_spectrum[k], 1 << ( 30 - SPEC_EXP_DEC ) ); spectrum[k] = L_tmp; move32(); } *spectrum_e = SPEC_EXP_DEC; move16(); - set32_fx(spectrum+k, 0, sub(s_max(L_frame, L_spec), k)); + set32_fx( spectrum + k, 0, sub( s_max( L_frame, L_spec ), k ) ); /* noise filling seed */ - *nf_seed = extract_l(L_tmp2); - + *nf_seed = extract_l( L_tmp2 ); } - diff --git a/lib_enc/avq_cod_fx.c b/lib_enc/avq_cod_fx.c index de85c7755..5b1756bfd 100644 --- a/lib_enc/avq_cod_fx.c +++ b/lib_enc/avq_cod_fx.c @@ -3,81 +3,81 @@ ====================================================================================*/ #include #include -#include "options.h" /* Compilation switches */ +#include "options.h" /* Compilation switches */ #include "cnst.h" -#include /* Compilation switches */ -#include "prot.h" /* Function prototypes */ +#include /* Compilation switches */ +#include "prot.h" /* Function prototypes */ //#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ #include "rom_com.h" /* Static table prototypes */ /*-------------------------------------------------------------------* * Local prototypes *-------------------------------------------------------------------*/ -static void wrte_cv(BSTR_ENC_HANDLE hBstr, const Word16 nq, const Word16 i_ind, const Word16 kv_ind, UWord16 I, Word16 kv[], Word16 * bits); +static void wrte_cv( BSTR_ENC_HANDLE hBstr, const Word16 nq, const Word16 i_ind, const Word16 kv_ind, UWord16 I, Word16 kv[], Word16 *bits ); /*-------------------------------------------------------------------* -* Function AVQ_cod() * -* * -* Split algevraic vector quantizer (AVQ) base on RE8 latice * -*-------------------------------------------------------------------*/ - -void AVQ_cod_fx( /* o: comfort noise gain factor */ - const Word16 xri[], /* i: vector to quantize */ - Word16 xriq[], /* o: quantized normalized vector (assuming the bit budget is enough) */ - const Word16 NB_BITS, /* i: number of allocated bits */ - const Word16 Nsv, /* i: number of subvectors (lg=Nsv*8) */ - const Word16 Q_in_ref /* i: Scaling input */ + * Function AVQ_cod() * + * * + * Split algevraic vector quantizer (AVQ) base on RE8 latice * + *-------------------------------------------------------------------*/ + +void AVQ_cod_fx( /* o: comfort noise gain factor */ + const Word16 xri[], /* i: vector to quantize */ + Word16 xriq[], /* o: quantized normalized vector (assuming the bit budget is enough) */ + const Word16 NB_BITS, /* i: number of allocated bits */ + const Word16 Nsv, /* i: number of subvectors (lg=Nsv*8) */ + const Word16 Q_in_ref /* i: Scaling input */ ) { Word16 i, l, iter, c[8]; Word16 gain_inv, tmp, nbits, nbits_max, fac, offset; - Word16 ebits[NSV_MAX], e_ebits, f_ebits, e_tmp,f_tmp, tmp16, l_8; + Word16 ebits[NSV_MAX], e_ebits, f_ebits, e_tmp, f_tmp, tmp16, l_8; Word32 Lener, Ltmp, Lgain, x1[8]; Word16 tot_est_bits, Q_in; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - Q_in = sub(Q_in_ref,1); + Q_in = sub( Q_in_ref, 1 ); move16(); /* find energy of each subvector in log domain (scaled for bits estimation) */ /* if the number of allocated bits is high, recompute the energy of sub vectors with a different scaling factor (applicable only in BASOP code) */ DO { - Q_in = add(Q_in,1); + Q_in = add( Q_in, 1 ); tot_est_bits = 0; move16(); - FOR (l=0; l= 0 */ - FOR (i=0; i<8; i++) + Lener = L_shl( 4, shl( Q_in, 1 ) ); /* to set ebits >= 0 */ + FOR( i = 0; i < 8; i++ ) { #ifdef BASOP_NOGLOB - Lener = L_mac_o(Lener, xri[l*8+i], xri[l*8+i], &Overflow); + Lener = L_mac_o( Lener, xri[l * 8 + i], xri[l * 8 + i], &Overflow ); #else - Lener = L_mac(Lener, xri[l*8+i], xri[l*8+i]); + Lener = L_mac( Lener, xri[l * 8 + i], xri[l * 8 + i] ); #endif } /* estimated bit consumption when gain=1 */ /* ebits[l] = 5.0 * FAC_LOG2 * (Word16)log10(ener * 0.5) */ - e_ebits = norm_l(Lener); - f_ebits = Log2_norm_lc(L_shl(Lener, e_ebits)); - e_ebits = sub(30-2, e_ebits); /* -2 = *0.25 */ - e_ebits = sub(e_ebits, shl(Q_in,1)); - - Ltmp = L_deposit_h(e_ebits); - Ltmp = L_mac(Ltmp, f_ebits, 1); - Ltmp = L_add(L_shl(Ltmp,6), L_shl(Ltmp,4)); /* Mult by 5.0 and then by 16 (To go to Q4). Do it using Mult by 80 (which is 64+16) */ - ebits[l] = round_fx(Ltmp); /*Q4*/ - tot_est_bits = add(tot_est_bits, shr(ebits[l],4)); + e_ebits = norm_l( Lener ); + f_ebits = Log2_norm_lc( L_shl( Lener, e_ebits ) ); + e_ebits = sub( 30 - 2, e_ebits ); /* -2 = *0.25 */ + e_ebits = sub( e_ebits, shl( Q_in, 1 ) ); + + Ltmp = L_deposit_h( e_ebits ); + Ltmp = L_mac( Ltmp, f_ebits, 1 ); + Ltmp = L_add( L_shl( Ltmp, 6 ), L_shl( Ltmp, 4 ) ); /* Mult by 5.0 and then by 16 (To go to Q4). Do it using Mult by 80 (which is 64+16) */ + ebits[l] = round_fx( Ltmp ); /*Q4*/ + tot_est_bits = add( tot_est_bits, shr( ebits[l], 4 ) ); } test(); test(); } - WHILE( (LE_16(Q_in, Q_in_ref))&&LE_16(tot_est_bits,mult(26214,NB_BITS))&>_16(tot_est_bits,600)); /* limited to 1 possible iteration */ + WHILE( ( LE_16( Q_in, Q_in_ref ) ) && LE_16( tot_est_bits, mult( 26214, NB_BITS ) ) && GT_16( tot_est_bits, 600 ) ); /* limited to 1 possible iteration */ /*----------------------------------------------------------------* * subvector energy worst case: @@ -94,75 +94,74 @@ void AVQ_cod_fx( /* o: comfort noise gain factor */ offset = 0; move16(); - Ltmp = L_mult(31130, sub(NB_BITS, Nsv)); /* (1810 - 8 - 1152/8)*.95*/ - nbits_max = round_fx(L_shl(Ltmp, 4)); + Ltmp = L_mult( 31130, sub( NB_BITS, Nsv ) ); /* (1810 - 8 - 1152/8)*.95*/ + nbits_max = round_fx( L_shl( Ltmp, 4 ) ); /* tree search with 10 iterations : offset with step of 0.25 bits (0.3 dB) */ - FOR (iter=0; iter<10; iter++) + FOR( iter = 0; iter < 10; iter++ ) { - offset = add(fac, offset); + offset = add( fac, offset ); /* calculate the required number of bits */ nbits = 0; move16(); - FOR (l=0; l 0 ) { j = pos_max; move16(); - j = s_max(pos,j); + j = s_max( pos, j ); /* compute (number of bits -1) to describe Q #nq */ - IF(GE_16(nq[pos],2)) + IF( GE_16( nq[pos], 2 ) ) { - overflow = sub(i_mult2(nq[pos],5),1); + overflow = sub( i_mult2( nq[pos], 5 ), 1 ); } ELSE { @@ -291,46 +290,51 @@ void AVQ_encmux_fx( } /* check for overflow and compute number of bits-1 (n) */ - IF( GT_16(add(bits,add(overflow,j)),*nb_bits)) + IF( GT_16( add( bits, add( overflow, j ) ), *nb_bits ) ) { /* if budget overflow */ - pos_tmp = add(shl(pos,3),8); /*(pos*8)+8*/ - FOR( j=pos*8; j 0) + IF( EQ_16( k, trgtSvPos ) && avq_bit_sFlag > 0 ) { - test();test(); - IF (EQ_16(sub(*nb_bits, bits), 7) || LT_16(bits, BIT_SAVING_LOW_THR) || GE_16(bits, BIT_SAVING_HIGH_THR)) + test(); + test(); + IF( EQ_16( sub( *nb_bits, bits ), 7 ) || LT_16( bits, BIT_SAVING_LOW_THR ) || GE_16( bits, BIT_SAVING_HIGH_THR ) ) { avq_bit_sFlag = 0; move16(); } ELSE { - BREAK; + BREAK; } } - if( EQ_16(sub(i_mult2(5,nq[k]),1),bits)) /* check the overflow */ + if ( EQ_16( sub( i_mult2( 5, nq[k] ), 1 ), bits ) ) /* check the overflow */ { overflow = 1; move16(); } - IF( GT_16(bits,8)) + IF( GT_16( bits, 8 ) ) { - /* write the unary code for nq[i] */ - j = sub(nq[k], 1); - IF ( nq[k] > 0 ) + /* write the unary code for nq[i] */ + j = sub( nq[k], 1 ); + IF( nq[k] > 0 ) { /* write the unary code */ FOR( ; j > 16; j -= 16 ) { push_indice_fx( hBstr, nq_ind, 65535, 16 ); - bits = sub(bits,16); + bits = sub( bits, 16 ); } - IF ( j > 0 ) + IF( j > 0 ) { - push_indice_fx( hBstr, nq_ind, extract_l(L_sub(L_shl(1L,j),1L)), j ); - bits = sub(bits,j); + push_indice_fx( hBstr, nq_ind, extract_l( L_sub( L_shl( 1L, j ), 1L ) ), j ); + bits = sub( bits, j ); } } - IF ( !overflow ) + IF( !overflow ) { /* write the stop bit */ push_indice_fx( hBstr, nq_ind, 0, 1 ); - bits = sub(bits,1); + bits = sub( bits, 1 ); } - wrte_cv(hBstr, nq[k], i_ind, kv_ind, I[k], &kv[shl(k, 3 )], &bits); + wrte_cv( hBstr, nq[k], i_ind, kv_ind, I[k], &kv[shl( k, 3 )], &bits ); } } /* for */ /* Bit Saving Solution */ test(); - IF (avq_bit_sFlag > 0 && bits > 8) + IF( avq_bit_sFlag > 0 && bits > 8 ) { -//PMT("code not validated yet") - bitsMod = s_and(bits, 4/*bits%5*/); + // PMT("code not validated yet") + bitsMod = s_and( bits, 4 /*bits%5*/ ); i = svOrder[Nsvm1]; move16(); - IF ( NE_16(i, Nsvm1)) + IF( NE_16( i, Nsvm1 ) ) { nullVec = 0; move16(); - FOR (j = i; j < Nsv - 1; j++) + FOR( j = i; j < Nsv - 1; j++ ) { - if (nq[svOrder[j]] == 0) + if ( nq[svOrder[j]] == 0 ) { - nullVec = add(nullVec,1); + nullVec = add( nullVec, 1 ); } } /*nq_est = bits / 5;*/ - nq_est = mult(bits,6554); - assert(nq_est == bits / 5); - - test();test();test();test();test();test();test();test();test();test();test(); - IF ((bitsMod > 0 || (EQ_16(nullVec, 4) && EQ_16(nq_est, 5))) && NE_16(bitsMod, 4) && GE_16(add(bits, nullVec), add(add(shl(nq_est ,2), nq_est),4))/*5 * nq_est + 4*/ && nq[svOrder[Nsvm2]] == 0) /* detect need for dummy bits */ + nq_est = mult( bits, 6554 ); + assert( nq_est == bits / 5 ); + + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( bitsMod > 0 || ( EQ_16( nullVec, 4 ) && EQ_16( nq_est, 5 ) ) ) && NE_16( bitsMod, 4 ) && GE_16( add( bits, nullVec ), add( add( shl( nq_est, 2 ), nq_est ), 4 ) ) /*5 * nq_est + 4*/ && nq[svOrder[Nsvm2]] == 0 ) /* detect need for dummy bits */ { - dummy_bits = sub(5, bitsMod); - bits = add(bits, dummy_bits); /* add dummy bits */ + dummy_bits = sub( 5, bitsMod ); + bits = add( bits, dummy_bits ); /* add dummy bits */ bitsMod = 0; move16(); } - ELSE IF (nq_est > 4 && ((bitsMod == 0 && nullVec > 3 && nullVec < 6) || (bitsMod == 4 && nullVec == 5)) && nq[svOrder[Nsvm2]] == 0) /* wasted bits 4, 5 for nq 6,7..*/ + ELSE IF( nq_est > 4 && ( ( bitsMod == 0 && nullVec > 3 && nullVec < 6 ) || ( bitsMod == 4 && nullVec == 5 ) ) && nq[svOrder[Nsvm2]] == 0 ) /* wasted bits 4, 5 for nq 6,7..*/ { overflow = 0; move16(); - if (s_and(add(bitsMod, nullVec), 4) != 0) + if ( s_and( add( bitsMod, nullVec ), 4 ) != 0 ) { overflow = 1; move16(); } - dummy_bits = add(nullVec, overflow); - bits = add(bits, dummy_bits); /* add dummy bits */ + dummy_bits = add( nullVec, overflow ); + bits = add( bits, dummy_bits ); /* add dummy bits */ bitsMod = 0; move16(); } @@ -452,105 +471,108 @@ void AVQ_encmux_fx( overflow = 1; move16(); - IF (NE_16(bitsMod, 4)) + IF( NE_16( bitsMod, 4 ) ) { overflow = 0; move16(); - bits = sub(bits, bitsMod); + bits = sub( bits, bitsMod ); } - bits = add(bits, overflow); /*add fake bit */ - unused_bits = sub(bits, add(shl(nq[i],2), nq[i])); - if (nq[i] == 0) /*no bit savings*/ + bits = add( bits, overflow ); /*add fake bit */ + unused_bits = sub( bits, add( shl( nq[i], 2 ), nq[i] ) ); + if ( nq[i] == 0 ) /*no bit savings*/ { - unused_bits = sub(unused_bits, 1); /*Stop Bit*/ + unused_bits = sub( unused_bits, 1 ); /*Stop Bit*/ } /*unused_bits_idx = (int16_t)unused_bits / 5;*/ - unused_bits_idx = mult(unused_bits, 6554); - assert(unused_bits_idx == unused_bits / 5); + unused_bits_idx = mult( unused_bits, 6554 ); + assert( unused_bits_idx == unused_bits / 5 ); unusedbitsFlag = 0; - move16(); - IF (dummy_bits == 0) + move16(); + IF( dummy_bits == 0 ) { - test(); test(); - IF (EQ_16(unused_bits_idx, 1) && GT_16(bits, BIT_SAVING_LOW_THR)) + test(); + test(); + IF( EQ_16( unused_bits_idx, 1 ) && GT_16( bits, BIT_SAVING_LOW_THR ) ) { unused_bits_idx = 0; unusedbitsFlag = 1; - move16();move16(); + move16(); + move16(); } - ELSE IF (unused_bits_idx == 0 && GT_16(bits, BIT_SAVING_LOW_THR)) + ELSE IF( unused_bits_idx == 0 && GT_16( bits, BIT_SAVING_LOW_THR ) ) { unused_bits_idx = 1; unusedbitsFlag = -1; - move16(); move16(); + move16(); + move16(); } } j = unused_bits_idx; move16(); /*Encode Unused Bit Unary Codeword */ - IF (j > 0) + IF( j > 0 ) { /* write the unary code */ - push_indice_fx(hBstr, nq_ind, sub(shl(1, j), 1), j); + push_indice_fx( hBstr, nq_ind, sub( shl( 1, j ), 1 ), j ); } - IF (nq[i] != 0) + IF( nq[i] != 0 ) { /* write the stop bit */ - push_indice_fx(hBstr, nq_ind, 0, 1); + push_indice_fx( hBstr, nq_ind, 0, 1 ); } /*Compute AVQ code book number from unused Bits */ - bit_tmp = add(unusedbitsFlag, unused_bits_idx); + bit_tmp = add( unusedbitsFlag, unused_bits_idx ); /*nq_est = (int16_t)ceil(0.2f * (bits - 5 * (unusedbitsFlag + unused_bits_idx)));*/ - nq_est = mult(6554, sub(bits, add(shl(bit_tmp, 2), bit_tmp))); - assert((int16_t)ceil(0.2f * (bits - 5 * (unusedbitsFlag + unused_bits_idx))) == nq_est); + nq_est = mult( 6554, sub( bits, add( shl( bit_tmp, 2 ), bit_tmp ) ) ); + assert( (int16_t) ceil( 0.2f * ( bits - 5 * ( unusedbitsFlag + unused_bits_idx ) ) ) == nq_est ); - if (EQ_16(nq_est, 1)) + if ( EQ_16( nq_est, 1 ) ) { nq_est = 0; move16(); } - bits = sub(bits, overflow); + bits = sub( bits, overflow ); - bits = sub(bits, j); + bits = sub( bits, j ); - if (nq_est != 0) + if ( nq_est != 0 ) { - bits = sub(bits, 1); + bits = sub( bits, 1 ); } nq[i] = nq_est; move16(); /* write codebook indices (rank I and event. Voronoi index kv) */ - wrte_cv(hBstr, nq[i], i_ind, kv_ind, I[i], &kv[shl(i, 3)], &bits); + wrte_cv( hBstr, nq[i], i_ind, kv_ind, I[i], &kv[shl( i, 3 )], &bits ); - bits = sub (bits, dummy_bits); + bits = sub( bits, dummy_bits ); - if (NE_16(bitsMod, 4)) + if ( NE_16( bitsMod, 4 ) ) { - bits = add(bits, bitsMod); + bits = add( bits, bitsMod ); } } *nb_bits = bits; move16(); - FOR(i = 0; i < Nsv; i++) + FOR( i = 0; i < Nsv; i++ ) { nq_out[i] = nq[i]; move16(); } - + return; } /*-------------------------------------------------------------------* -* Function AVQ_cod_lpc_fx() * -* * -* Split algebraic vector quantizer (AVQ) for LPC quantization * -*-------------------------------------------------------------------*/ + * Function AVQ_cod_lpc_fx() * + * * + * Split algebraic vector quantizer (AVQ) for LPC quantization * + *-------------------------------------------------------------------*/ void AVQ_cod_lpc_fx( Word16 *nvec, /* input: vector to quantize (normalized) (5Q10)*/ @@ -559,9 +581,9 @@ void AVQ_cod_lpc_fx( Word16 Nsv /* input: number of subvectors (lg=Nsv*8) */ ) { - Word16 ival, n, nq, nk, c[8], kv[8]; - Word16 i, l, pos; - Word32 I; + Word16 ival, n, nq, nk, c[8], kv[8]; + Word16 i, l, pos; + Word32 I; Word32 x1[8]; UWord16 I16; @@ -569,56 +591,60 @@ void AVQ_cod_lpc_fx( /* quantize all subvector using estimated gain */ pos = Nsv; move16(); - FOR (l=0; l 16Q15*/ move32(); + x1[i] = L_mult( nvec[l * 8 + i], 1 << 4 ); /* 5Q10 -> 16Q15*/ + move32(); } - re8_PPV_fx(x1, c); /*x1:8Q15, c:15Q0*/ - re8_cod_fx(c, &nq, &I16, kv); - I = UL_deposit_l(I16); + re8_PPV_fx( x1, c ); /*x1:8Q15, c:15Q0*/ + re8_cod_fx( c, &nq, &I16, kv ); + I = UL_deposit_l( I16 ); - FOR (i=0; i<8; i++) + FOR( i = 0; i < 8; i++ ) { - nvecq[l*8+i] = shl(c[i],10); /*15Q0->5Q10*/ move16(); + nvecq[l * 8 + i] = shl( c[i], 10 ); /*15Q0->5Q10*/ + move16(); } - indx[l] = nq; /* index[0..Nsv-1] = quantizer number (0,2,3,4...) */ move16(); + indx[l] = nq; /* index[0..Nsv-1] = quantizer number (0,2,3,4...) */ + move16(); nk = 0; move16(); n = nq; move16(); - IF (GT_16(nq,4)) + IF( GT_16( nq, 4 ) ) { - nk = shr(sub(nq,3),1); /*nk = (nq-3)>>1;*/ - n = sub(nq,shl(nk,1)); /*n = nq - nk*2; */ + nk = shr( sub( nq, 3 ), 1 ); /*nk = (nq-3)>>1;*/ + n = sub( nq, shl( nk, 1 ) ); /*n = nq - nk*2; */ } /* write n groups of 4-bit for base codebook index (I) */ - FOR ( ; n > 0; n-- ) + FOR( ; n > 0; n-- ) { - indx[pos++] = s_and(extract_l(I),0x000F); + indx[pos++] = s_and( extract_l( I ), 0x000F ); move16(); - I = L_shr(I,4); + I = L_shr( I, 4 ); } /* write n groups of 4-bit for Voronoi index (k[]) */ - FOR ( ; nk > 0; nk--) + FOR( ; nk > 0; nk-- ) { ival = 0; move16(); - FOR (i=0; i<8; i++) + FOR( i = 0; i < 8; i++ ) { - ival = shl(ival,1); /*ival <<= 1;*/ - ival = add(ival,s_and(kv[i],0x0001)); /*ival += (kv[i] & 0x01);*/ - kv[i] = shr(kv[i],1); /*kv[i] >>= 1;*/ move16(); + ival = shl( ival, 1 ); /*ival <<= 1;*/ + ival = add( ival, s_and( kv[i], 0x0001 ) ); /*ival += (kv[i] & 0x01);*/ + kv[i] = shr( kv[i], 1 ); /*kv[i] >>= 1;*/ + move16(); } - indx[pos++] = s_and(ival,0x000F); + indx[pos++] = s_and( ival, 0x000F ); move16(); - ival = shr(ival,4); - indx[pos++] = s_and(ival,0x000F); + ival = shr( ival, 4 ); + indx[pos++] = s_and( ival, 0x000F ); move16(); } } @@ -627,18 +653,18 @@ void AVQ_cod_lpc_fx( return; } /*------------------------------------------------------------------ - * - * Function wrte_cv() + * Function wrte_cv() * * write codebook indices(rank I and event.Voronoi index kv) * *------------------------------------------------------------------ - */ static void wrte_cv( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 nq, /* i : AVQ nq index */ - const Word16 i_ind, /* i : Base Bitstream index */ - const Word16 kv_ind, /* i : Vornoi Bitstream index */ - UWord16 I, /* o : rank I code book index */ - Word16 kv[], /* o : Vornoi index kv */ - Word16 *nbits /* i/o: bits */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 nq, /* i : AVQ nq index */ + const Word16 i_ind, /* i : Base Bitstream index */ + const Word16 kv_ind, /* i : Vornoi Bitstream index */ + UWord16 I, /* o : rank I code book index */ + Word16 kv[], /* o : Vornoi index kv */ + Word16 *nbits /* i/o: bits */ ) { int16_t pos, j; @@ -648,45 +674,45 @@ static void wrte_cv( move16(); /* write codebook indices (rank I and event. Voronoi index kv) */ - IF (nq == 0) /* Q0 */ + IF( nq == 0 ) /* Q0 */ { /* nothing to write */ } - ELSE IF (LT_16(nq, 5)) /* Q2, Q3, Q4 */ + ELSE IF( LT_16( nq, 5 ) ) /* Q2, Q3, Q4 */ { - nq4 = shl(nq, 2); - push_indice_fx(hBstr, i_ind, I, nq4); - bits = sub(bits, nq4); + nq4 = shl( nq, 2 ); + push_indice_fx( hBstr, i_ind, I, nq4 ); + bits = sub( bits, nq4 ); } - ELSE IF (EQ_16(s_and(nq, 1), 0)) /* Q4 + Voronoi extensions r=1,2,3,... */ + ELSE IF( EQ_16( s_and( nq, 1 ), 0 ) ) /* Q4 + Voronoi extensions r=1,2,3,... */ { - push_indice_fx(hBstr, i_ind, I, 4 * 4); - bits = sub(bits, 4 * 4); + push_indice_fx( hBstr, i_ind, I, 4 * 4 ); + bits = sub( bits, 4 * 4 ); /*pos = (int16_t)(nq / 2 - 2);*/ /* Voronoi order determination */ - pos = sub(shr(nq,1), 2); - FOR (j = 0; j < 8; j++) + pos = sub( shr( nq, 1 ), 2 ); + FOR( j = 0; j < 8; j++ ) { - push_indice_fx(hBstr, kv_ind, kv[j], pos); + push_indice_fx( hBstr, kv_ind, kv[j], pos ); } - bits = sub(bits, shl(pos, 3)); + bits = sub( bits, shl( pos, 3 ) ); } ELSE /* Q3 + Voronoi extensions r=1,2,3,... */ { - push_indice_fx(hBstr, i_ind, I, 4 * 3); - bits = sub(bits, 4 * 3); + push_indice_fx( hBstr, i_ind, I, 4 * 3 ); + bits = sub( bits, 4 * 3 ); /*pos = (int16_t)(nq / 2 - 1);*/ /* Voronoi order determination */ - pos = sub(shr(nq, 1), 1); - FOR (j = 0; j < 8; j++) + pos = sub( shr( nq, 1 ), 1 ); + FOR( j = 0; j < 8; j++ ) { - push_indice_fx(hBstr, kv_ind, kv[j], pos); + push_indice_fx( hBstr, kv_ind, kv[j], pos ); } - bits = sub(bits, shl(pos, 3)); + bits = sub( bits, shl( pos, 3 ) ); } *nbits = bits; move16(); return; -} \ No newline at end of file +} diff --git a/lib_enc/bass_psfilter_enc_fx.c b/lib_enc/bass_psfilter_enc_fx.c index 42927271e..c8ea49bf3 100644 --- a/lib_enc/bass_psfilter_enc_fx.c +++ b/lib_enc/bass_psfilter_enc_fx.c @@ -3,14 +3,13 @@ ====================================================================================*/ - #include #include "options.h" #include "cnst.h" #include "rom_com.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" /*---------------------------------------------------------------------* @@ -19,22 +18,22 @@ * Low-frequency postfiltering, decoder parammeter estimation *---------------------------------------------------------------------*/ Word16 bass_pf_enc_fx( - const Word16* orig, /* i : 12.8kHz original signal Q0 */ - const Word16* syn, /* i : 12.8kHz synthesis to postfilter Q0 */ - const Word16* T_sf, /* i : Pitch period for all subframes (T_sf[16]) Q0 */ - const Word16* gainT_sf, /* i : Pitch gain for all subframes (gainT_sf[16]) Q14 */ - const Word16 l_frame, /* i : frame length (should be multiple of l_subfr) Q0 */ - const Word16 l_subfr, /* i : sub-frame length (60/64) Q0 */ - Word16 *gain_factor_param, /* o : quantized gain factor Q0 */ - const Word16 mode, /* i : coding mode of adapt bpf */ - struct MEM_BPF *mem_bpf /* i/o: memory state */ + const Word16 *orig, /* i : 12.8kHz original signal Q0 */ + const Word16 *syn, /* i : 12.8kHz synthesis to postfilter Q0 */ + const Word16 *T_sf, /* i : Pitch period for all subframes (T_sf[16]) Q0 */ + const Word16 *gainT_sf, /* i : Pitch gain for all subframes (gainT_sf[16]) Q14 */ + const Word16 l_frame, /* i : frame length (should be multiple of l_subfr) Q0 */ + const Word16 l_subfr, /* i : sub-frame length (60/64) Q0 */ + Word16 *gain_factor_param, /* o : quantized gain factor Q0 */ + const Word16 mode, /* i : coding mode of adapt bpf */ + struct MEM_BPF *mem_bpf /* i/o: memory state */ ) { Word16 i, j, sf, i_subfr, T, lg, l_filt; Word16 gain, d, tmp16, hr, s1, s2, s2_old, s3, s4, st, st2, st3; Word32 nrg, tmp, nrg1, nrg2, n, snr, lp_error, tmp32; - Word16 noise_buf[L_FILT16k+2*L_SUBFR], *noise, *noise_in; - Word16 error_buf[L_FILT16k+2*L_SUBFR], *error, *error_in; + Word16 noise_buf[L_FILT16k + 2 * L_SUBFR], *noise, *noise_in; + Word16 error_buf[L_FILT16k + 2 * L_SUBFR], *error, *error_in; Word32 cross_n_d, nrg_n; const Word16 *pFilt; Word32 ener2; @@ -43,7 +42,7 @@ Word16 bass_pf_enc_fx( #endif - IF (NE_16(l_frame, L_FRAME16k)) + IF( NE_16( l_frame, L_FRAME16k ) ) { pFilt = filt_lp_fx; l_filt = L_FILT; @@ -57,197 +56,198 @@ Word16 bass_pf_enc_fx( } noise = noise_buf + l_filt; - noise_in = noise_buf + shl(l_filt, 1); + noise_in = noise_buf + shl( l_filt, 1 ); error = error_buf; error_in = error_buf + l_filt; sf = 0; move16(); - snr = L_deposit_l(0); - nrg_n = L_deposit_l(0); - cross_n_d = L_deposit_l(0); - lp_error = L_shl(mem_bpf->lp_error, 0); + snr = L_deposit_l( 0 ); + nrg_n = L_deposit_l( 0 ); + cross_n_d = L_deposit_l( 0 ); + lp_error = L_shl( mem_bpf->lp_error, 0 ); s2_old = mem_bpf->noise_shift_old; move16(); - s3 = s4 = 0; /* initialization of s3 and s4 to suppress compiler warnings; - s3 and s4 get initialized for i_subfr == 0 */ + s3 = s4 = 0; /* initialization of s3 and s4 to suppress compiler warnings; + s3 and s4 get initialized for i_subfr == 0 */ - nrg1 = nrg2 = 0; /* initialization fo nrg1 and nrg2 to suppress compiler warnings; - nrg1 and nrg1 get initialized for i_subfr == 0 */ + nrg1 = nrg2 = 0; /* initialization fo nrg1 and nrg2 to suppress compiler warnings; + nrg1 and nrg1 get initialized for i_subfr == 0 */ - FOR (i_subfr = 0; i_subfr < l_frame; i_subfr += l_subfr) + FOR( i_subfr = 0; i_subfr < l_frame; i_subfr += l_subfr ) { T = T_sf[sf]; move16(); - lg = sub(sub(l_frame, T), i_subfr); - if (lg < 0) + lg = sub( sub( l_frame, T ), i_subfr ); + if ( lg < 0 ) { lg = 0; move16(); } - if (GT_16(lg, l_subfr)) + if ( GT_16( lg, l_subfr ) ) { lg = l_subfr; move16(); } - IF (gainT_sf[sf] > 0) + IF( gainT_sf[sf] > 0 ) { /* get headroom for used part of syn */ - tmp16 = s_max(add(lg, shl(T, 1)), add(l_subfr, T)); - hr = getScaleFactor16(syn + sub(i_subfr, T), tmp16); - s1 = sub(hr, 3); + tmp16 = s_max( add( lg, shl( T, 1 ) ), add( l_subfr, T ) ); + hr = getScaleFactor16( syn + sub( i_subfr, T ), tmp16 ); + s1 = sub( hr, 3 ); - tmp = L_deposit_l(1); - nrg = L_deposit_l(1); + tmp = L_deposit_l( 1 ); + nrg = L_deposit_l( 1 ); - IF (lg > 0) + IF( lg > 0 ) { - FOR (i = 0; i < lg; i++) + FOR( i = 0; i < lg; i++ ) { - tmp32 = L_mult(syn[i+i_subfr-T], 0x4000); - tmp32 = L_mac(tmp32, syn[i+i_subfr+T], 0x4000); - tmp16 = round_fx(L_shl(tmp32, s1)); /* Q0+s1 */ + tmp32 = L_mult( syn[i + i_subfr - T], 0x4000 ); + tmp32 = L_mac( tmp32, syn[i + i_subfr + T], 0x4000 ); + tmp16 = round_fx( L_shl( tmp32, s1 ) ); /* Q0+s1 */ - tmp = L_mac0(tmp, shl(syn[i+i_subfr], s1), tmp16); /* Q0+2*s1 */ - nrg = L_mac0(nrg, tmp16, tmp16); /* Q0+2*s1 */ + tmp = L_mac0( tmp, shl( syn[i + i_subfr], s1 ), tmp16 ); /* Q0+2*s1 */ + nrg = L_mac0( nrg, tmp16, tmp16 ); /* Q0+2*s1 */ } } - IF (LT_16(lg, l_subfr)) + IF( LT_16( lg, l_subfr ) ) { - FOR (i = lg; i < l_subfr; i++) + FOR( i = lg; i < l_subfr; i++ ) { - tmp16 = shl(syn[i+i_subfr-T], s1); /* Q0+s1 */ - tmp = L_mac0(tmp, shl(syn[i+i_subfr], s1), tmp16); /* Q0+2*s1 */ - nrg = L_mac0(nrg, tmp16, tmp16); /* Q0+2*s1 */ + tmp16 = shl( syn[i + i_subfr - T], s1 ); /* Q0+s1 */ + tmp = L_mac0( tmp, shl( syn[i + i_subfr], s1 ), tmp16 ); /* Q0+2*s1 */ + nrg = L_mac0( nrg, tmp16, tmp16 ); /* Q0+2*s1 */ } } /* gain = tmp/nrg; */ - gain = BASOP_Util_Divide3232_Scale(tmp, nrg, &tmp16); + gain = BASOP_Util_Divide3232_Scale( tmp, nrg, &tmp16 ); BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB - gain = shl_o(gain, tmp16, &Overflow); /* Q15 */ -#else /* BASOP_NOGLOB */ - gain = shl(gain, tmp16); /* Q15 */ -#endif /* BASOP_NOGLOB */ + gain = shl_o( gain, tmp16, &Overflow ); /* Q15 */ +#else /* BASOP_NOGLOB */ + gain = shl( gain, tmp16 ); /* Q15 */ +#endif /* BASOP_NOGLOB */ BASOP_SATURATE_WARNING_ON_EVS; - if (gain < 0) + if ( gain < 0 ) { gain = 0; move16(); } - st = sub(norm_l(lp_error), 3); + st = sub( norm_l( lp_error ), 3 ); test(); - if ((LT_16(st, s1))&&(lp_error!=0)) + if ( ( LT_16( st, s1 ) ) && ( lp_error != 0 ) ) { s1 = st; move16(); } - ener2 = L_deposit_l(0); + ener2 = L_deposit_l( 0 ); - IF (lg > 0) + IF( lg > 0 ) { - FOR (i = 0; i < lg; i++) + FOR( i = 0; i < lg; i++ ) { - tmp32 = L_msu0(0, gain, syn[i+i_subfr-T]); + tmp32 = L_msu0( 0, gain, syn[i + i_subfr - T] ); #ifdef BASOP_NOGLOB - tmp32 = L_msu0_o(tmp32, gain, syn[i + i_subfr + T], &Overflow); - tmp16 = mac_ro(tmp32, gain, syn[i+i_subfr], &Overflow); /* Q0 */ + tmp32 = L_msu0_o( tmp32, gain, syn[i + i_subfr + T], &Overflow ); + tmp16 = mac_ro( tmp32, gain, syn[i + i_subfr], &Overflow ); /* Q0 */ #else - tmp32 = L_msu0(tmp32, gain, syn[i + i_subfr + T]); - tmp16 = mac_r(tmp32, gain, syn[i+i_subfr]); /* Q0 */ + tmp32 = L_msu0( tmp32, gain, syn[i + i_subfr + T] ); + tmp16 = mac_r( tmp32, gain, syn[i + i_subfr] ); /* Q0 */ #endif - lp_error = Mpy_32_16_1(lp_error, 29491/*0.9f Q15*/); + lp_error = Mpy_32_16_1( lp_error, 29491 /*0.9f Q15*/ ); #ifdef BASOP_NOGLOB - lp_error = L_mac_o(lp_error, tmp16, 0x1000, &Overflow); /* Q13 */ + lp_error = L_mac_o( lp_error, tmp16, 0x1000, &Overflow ); /* Q13 */ - tmp16 = round_fx_o(L_shl_o(lp_error, s1, &Overflow), &Overflow); /* Q0+s1-3 */ - ener2 = L_mac0_o(ener2, tmp16, tmp16, &Overflow); /* Q0+(s1-3)*2 */ + tmp16 = round_fx_o( L_shl_o( lp_error, s1, &Overflow ), &Overflow ); /* Q0+s1-3 */ + ener2 = L_mac0_o( ener2, tmp16, tmp16, &Overflow ); /* Q0+(s1-3)*2 */ #else - lp_error = L_mac(lp_error, tmp16, 0x1000); /* Q13 */ + lp_error = L_mac( lp_error, tmp16, 0x1000 ); /* Q13 */ - tmp16 = round_fx(L_shl(lp_error, s1)); /* Q0+s1-3 */ - ener2 = L_mac0(ener2, tmp16, tmp16); /* Q0+(s1-3)*2 */ + tmp16 = round_fx( L_shl( lp_error, s1 ) ); /* Q0+s1-3 */ + ener2 = L_mac0( ener2, tmp16, tmp16 ); /* Q0+(s1-3)*2 */ #endif - } } - IF (LT_16(lg, l_subfr)) + IF( LT_16( lg, l_subfr ) ) { - FOR (i = lg; i < l_subfr; i++) + FOR( i = lg; i < l_subfr; i++ ) { - tmp32 = L_mult0(gain, syn[i+i_subfr]); + tmp32 = L_mult0( gain, syn[i + i_subfr] ); #ifdef BASOP_NOGLOB - tmp32 = L_msu0_o(tmp32, gain, syn[i+i_subfr-T], &Overflow); /* Q0 */ - tmp16 = round_fx_o(tmp32, &Overflow); + tmp32 = L_msu0_o( tmp32, gain, syn[i + i_subfr - T], &Overflow ); /* Q0 */ + tmp16 = round_fx_o( tmp32, &Overflow ); #else - tmp32 = L_msu0(tmp32, gain, syn[i+i_subfr-T]); /* Q0 */ - tmp16 = round_fx(tmp32); + tmp32 = L_msu0( tmp32, gain, syn[i + i_subfr - T] ); /* Q0 */ + tmp16 = round_fx( tmp32 ); #endif - lp_error = Mpy_32_16_1(lp_error, 29491/*0.9f Q15*/); + lp_error = Mpy_32_16_1( lp_error, 29491 /*0.9f Q15*/ ); #ifdef BASOP_NOGLOB - lp_error = L_mac_o(lp_error, tmp16, 0x1000, &Overflow); /* Q13 */ + lp_error = L_mac_o( lp_error, tmp16, 0x1000, &Overflow ); /* Q13 */ - tmp16 = round_fx_o(L_shl_o(lp_error, s1, &Overflow), &Overflow); /* Q0+s1-3 */ - ener2 = L_mac0_o(ener2, tmp16, tmp16, &Overflow); /* Q0+(s1-3)*2 */ + tmp16 = round_fx_o( L_shl_o( lp_error, s1, &Overflow ), &Overflow ); /* Q0+s1-3 */ + ener2 = L_mac0_o( ener2, tmp16, tmp16, &Overflow ); /* Q0+(s1-3)*2 */ #else - lp_error = L_mac(lp_error, tmp16, 0x1000); /* Q13 */ + lp_error = L_mac( lp_error, tmp16, 0x1000 ); /* Q13 */ - tmp16 = round_fx(L_shl(lp_error, s1)); /* Q0+s1-3 */ - ener2 = L_mac0(ener2, tmp16, tmp16); /* Q0+(s1-3)*2 */ + tmp16 = round_fx( L_shl( lp_error, s1 ) ); /* Q0+s1-3 */ + ener2 = L_mac0( ener2, tmp16, tmp16 ); /* Q0+(s1-3)*2 */ #endif } } - st = shl(sub(s1, 3), 1); + st = shl( sub( s1, 3 ), 1 ); - IF (ener2 > 0) + IF( ener2 > 0 ) { - ener2 = L_shr(BASOP_Util_Log2(ener2), 9); /* 15Q16 */ - ener2 = L_add(ener2, L_deposit_h(sub(31, st))); + ener2 = L_shr( BASOP_Util_Log2( ener2 ), 9 ); /* 15Q16 */ + ener2 = L_add( ener2, L_deposit_h( sub( 31, st ) ) ); } ELSE { - ener2 = 0xFFF95B2C; /* log2(0.01) (15Q16) */ move32(); + ener2 = 0xFFF95B2C; /* log2(0.01) (15Q16) */ + move32(); } - mem_bpf->lp_error_ener = L_add(Mpy_32_16_1(L_sub(mem_bpf->lp_error_ener, ener2), 32440/*0.99f Q15*/), ener2); /* 15Q16 */ + mem_bpf->lp_error_ener = L_add( Mpy_32_16_1( L_sub( mem_bpf->lp_error_ener, ener2 ), 32440 /*0.99f Q15*/ ), ener2 ); /* 15Q16 */ - st = add(st, 6); - ener2 = L_sub(mem_bpf->lp_error_ener, L_deposit_h(sub(31, st))); - IF (ener2 >= 0) + st = add( st, 6 ); + ener2 = L_sub( mem_bpf->lp_error_ener, L_deposit_h( sub( 31, st ) ) ); + IF( ener2 >= 0 ) { - tmp16 = add(extract_h(ener2), 1); - ener2 = L_sub(ener2, L_deposit_h(tmp16)); - tmp = L_shr(tmp, tmp16); - nrg = L_shr(nrg, tmp16); + tmp16 = add( extract_h( ener2 ), 1 ); + ener2 = L_sub( ener2, L_deposit_h( tmp16 ) ); + tmp = L_shr( tmp, tmp16 ); + nrg = L_shr( nrg, tmp16 ); } - ener2 = BASOP_Util_InvLog2(L_shl(ener2, 9)); /* Q0+2*s1 */ + ener2 = BASOP_Util_InvLog2( L_shl( ener2, 9 ) ); /* Q0+2*s1 */ - tmp32 = L_add(L_shr(nrg, 1), L_shr(ener2, 1)); - if (tmp32 == 0) tmp32 = L_deposit_l(1); - tmp16 = BASOP_Util_Divide3232_Scale(tmp, tmp32, &st); + tmp32 = L_add( L_shr( nrg, 1 ), L_shr( ener2, 1 ) ); + if ( tmp32 == 0 ) + tmp32 = L_deposit_l( 1 ); + tmp16 = BASOP_Util_Divide3232_Scale( tmp, tmp32, &st ); BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB - tmp16 = shl_o(tmp16, sub(st, 2), &Overflow); /* Q15 */ -#else /* BASOP_NOGLOB */ - tmp16 = shl(tmp16, sub(st, 2)); /* Q15 */ -#endif /* BASOP_NOGLOB */ + tmp16 = shl_o( tmp16, sub( st, 2 ), &Overflow ); /* Q15 */ +#else /* BASOP_NOGLOB */ + tmp16 = shl( tmp16, sub( st, 2 ) ); /* Q15 */ +#endif /* BASOP_NOGLOB */ - if (GT_16(tmp16, 16384/*0.5f Q15*/)) + if ( GT_16( tmp16, 16384 /*0.5f Q15*/ ) ) { - tmp16 = 16384/*0.5f Q15*/; + tmp16 = 16384 /*0.5f Q15*/; move16(); } - if (tmp16 < 0) + if ( tmp16 < 0 ) { tmp16 = 0; move16(); @@ -257,165 +257,169 @@ Word16 bass_pf_enc_fx( s2 = hr; move16(); - IF (lg > 0) + IF( lg > 0 ) { - FOR (i = 0; i < lg; i++) + FOR( i = 0; i < lg; i++ ) { - tmp32 = L_msu0(0, tmp16, syn[i+i_subfr-T]); - tmp32 = L_msu0(tmp32, tmp16, syn[i+i_subfr+T]); - tmp32 = L_mac(tmp32, tmp16, syn[i+i_subfr]); - noise_in[i] = round_fx(L_shl(tmp32, s2)); /* Q0+s2 */ + tmp32 = L_msu0( 0, tmp16, syn[i + i_subfr - T] ); + tmp32 = L_msu0( tmp32, tmp16, syn[i + i_subfr + T] ); + tmp32 = L_mac( tmp32, tmp16, syn[i + i_subfr] ); + noise_in[i] = round_fx( L_shl( tmp32, s2 ) ); /* Q0+s2 */ #ifdef BASOP_NOGLOB - error_in[i] = sub_o(orig[i+i_subfr], syn[i+i_subfr], &Overflow); /*Q0*/ move16(); -#else - error_in[i] = sub(orig[i+i_subfr], syn[i+i_subfr]); /*Q0*/ move16(); + error_in[i] = sub_o( orig[i + i_subfr], syn[i + i_subfr], &Overflow ); /*Q0*/ + move16(); +#else + error_in[i] = sub( orig[i + i_subfr], syn[i + i_subfr] ); /*Q0*/ + move16(); #endif } } - IF (LT_16(lg, l_subfr)) + IF( LT_16( lg, l_subfr ) ) { - FOR (i = lg; i < l_subfr; i++) + FOR( i = lg; i < l_subfr; i++ ) { - tmp32 = L_mult0(tmp16, syn[i+i_subfr]); - tmp32 = L_msu0(tmp32, tmp16, syn[i+i_subfr-T]); - noise_in[i] = round_fx(L_shl(tmp32, s2)); /* Q0+s2 */ + tmp32 = L_mult0( tmp16, syn[i + i_subfr] ); + tmp32 = L_msu0( tmp32, tmp16, syn[i + i_subfr - T] ); + noise_in[i] = round_fx( L_shl( tmp32, s2 ) ); /* Q0+s2 */ #ifdef BASOP_NOGLOB - error_in[i] = sub_o(orig[i+i_subfr], syn[i+i_subfr], &Overflow); /*Q0*/ move16(); + error_in[i] = sub_o( orig[i + i_subfr], syn[i + i_subfr], &Overflow ); /*Q0*/ + move16(); #else - error_in[i] = sub(orig[i+i_subfr], syn[i+i_subfr]); /*Q0*/ move16(); + error_in[i] = sub( orig[i + i_subfr], syn[i + i_subfr] ); /*Q0*/ + move16(); #endif } } } ELSE { - set16_fx(noise_in, 0, l_subfr); - set16_fx(error_in, 0, l_subfr); + set16_fx( noise_in, 0, l_subfr ); + set16_fx( error_in, 0, l_subfr ); s2 = s2_old; } - tmp16 = shl(l_filt, 1); + tmp16 = shl( l_filt, 1 ); /* copy history buffers (rescale noise history to new exponent) */ - st = sub(s2, s2_old); - FOR (i = 0; i < tmp16; i++) + st = sub( s2, s2_old ); + FOR( i = 0; i < tmp16; i++ ) { - noise_buf[i] = shl(mem_bpf->noise_buf[i], st); + noise_buf[i] = shl( mem_bpf->noise_buf[i], st ); move16(); } - Copy(noise_buf+l_subfr, mem_bpf->noise_buf, tmp16); + Copy( noise_buf + l_subfr, mem_bpf->noise_buf, tmp16 ); s2_old = s2; move16(); - Copy(mem_bpf->error_buf, error_buf, l_filt); - Copy(error_buf+l_subfr, mem_bpf->error_buf, l_filt); + Copy( mem_bpf->error_buf, error_buf, l_filt ); + Copy( error_buf + l_subfr, mem_bpf->error_buf, l_filt ); /* get noise shift */ - st = getScaleFactor16(noise-l_filt, add(l_subfr, shl(l_filt, 1))); - st = add(sub(st, 3), s2); - if (i_subfr == 0) + st = getScaleFactor16( noise - l_filt, add( l_subfr, shl( l_filt, 1 ) ) ); + st = add( sub( st, 3 ), s2 ); + if ( i_subfr == 0 ) { s3 = st; move16(); } - tmp16 = sub(st, s3); - IF (tmp16 < 0) + tmp16 = sub( st, s3 ); + IF( tmp16 < 0 ) { - nrg_n = L_shl(nrg_n, s_max(-15, shl(tmp16, 1))); - cross_n_d = L_shl(cross_n_d, tmp16); + nrg_n = L_shl( nrg_n, s_max( -15, shl( tmp16, 1 ) ) ); + cross_n_d = L_shl( cross_n_d, tmp16 ); s3 = st; move16(); } /* get error shift */ - st = getScaleFactor16(error, l_subfr); - st = sub(st, 3); - if (i_subfr == 0) + st = getScaleFactor16( error, l_subfr ); + st = sub( st, 3 ); + if ( i_subfr == 0 ) { s4 = st; move16(); } - tmp16 = sub(st, s4); - IF (tmp16 < 0) + tmp16 = sub( st, s4 ); + IF( tmp16 < 0 ) { - cross_n_d = L_shl(cross_n_d, tmp16); - nrg1 = L_shl(nrg1, shl(tmp16, 1)); - nrg2 = L_shl(nrg2, shl(tmp16, 1)); + cross_n_d = L_shl( cross_n_d, tmp16 ); + nrg1 = L_shl( nrg1, shl( tmp16, 1 ) ); + nrg2 = L_shl( nrg2, shl( tmp16, 1 ) ); s4 = st; move16(); } - nrg1 = L_deposit_l(1); - nrg2 = L_deposit_l(1); + nrg1 = L_deposit_l( 1 ); + nrg2 = L_deposit_l( 1 ); /* substract from voiced speech low-pass filtered noise */ - st = sub(s_min(s3, s4), 1); - st2 = sub(s3, s2); - st3 = sub(st,s2); - FOR (i = 0; i < l_subfr; i++) + st = sub( s_min( s3, s4 ), 1 ); + st2 = sub( s3, s2 ); + st3 = sub( st, s2 ); + FOR( i = 0; i < l_subfr; i++ ) { - n = L_mult(pFilt[0], noise[i]); /* Q16+s2 */ + n = L_mult( pFilt[0], noise[i] ); /* Q16+s2 */ - FOR (j = 1; j <= l_filt; j++) + FOR( j = 1; j <= l_filt; j++ ) { - n = L_mac(n, pFilt[j], noise[i-j]); - n = L_mac(n, pFilt[j], noise[i+j]); + n = L_mac( n, pFilt[j], noise[i - j] ); + n = L_mac( n, pFilt[j], noise[i + j] ); } /*for optimal g*/ - tmp16 = round_fx(L_shl(n, st2)); /* Q0+s3 */ - d = shl(error[i], s4); /* Q0+s4 */ - nrg_n = L_mac0(nrg_n, tmp16, tmp16); /* Q0+2*s3 */ - cross_n_d = L_mac0(cross_n_d, tmp16, d); /* Q0+s3+s4 */ + tmp16 = round_fx( L_shl( n, st2 ) ); /* Q0+s3 */ + d = shl( error[i], s4 ); /* Q0+s4 */ + nrg_n = L_mac0( nrg_n, tmp16, tmp16 ); /* Q0+2*s3 */ + cross_n_d = L_mac0( cross_n_d, tmp16, d ); /* Q0+s3+s4 */ /*for evaluating SNR*/ - tmp16 = round_fx(L_shl(n, st3)); /* Q0+st */ - tmp16 = add(tmp16, shl(error[i], st)); /* Q0+st */ - nrg1 = L_mac0(nrg1, tmp16, tmp16); /* Q0+2*st */ - nrg2 = L_mac0(nrg2, d, d); /* Q0+2*s4 */ + tmp16 = round_fx( L_shl( n, st3 ) ); /* Q0+st */ + tmp16 = add( tmp16, shl( error[i], st ) ); /* Q0+st */ + nrg1 = L_mac0( nrg1, tmp16, tmp16 ); /* Q0+2*st */ + nrg2 = L_mac0( nrg2, d, d ); /* Q0+2*s4 */ } /*SegSNR*/ - snr = L_add(snr, L_shr(L_sub(BASOP_Util_Log2(nrg2), BASOP_Util_Log2(nrg1)), 9)); /* 15Q16 */ - snr = L_add(snr, L_deposit_h(shl(sub(st, s4), 1))); + snr = L_add( snr, L_shr( L_sub( BASOP_Util_Log2( nrg2 ), BASOP_Util_Log2( nrg1 ) ), 9 ) ); /* 15Q16 */ + snr = L_add( snr, L_deposit_h( shl( sub( st, s4 ), 1 ) ) ); - sf = add(sf, 1); + sf = add( sf, 1 ); } - if (nrg_n == 0) + if ( nrg_n == 0 ) { - nrg_n = L_deposit_l(1); + nrg_n = L_deposit_l( 1 ); } /*Compute and quantize optimal gain*/ /* optimal gain = -/ */ *gain_factor_param = 2; move16(); - IF (EQ_16(mode, 2)) + IF( EQ_16( mode, 2 ) ) { /* *gain_factor_param = (int)(-2.f*(cross_n_d/nrg_n)+0.5f); */ - tmp16 = BASOP_Util_Divide3232_Scale(cross_n_d, nrg_n, &st); /* Q15-st-s3+s4 */ + tmp16 = BASOP_Util_Divide3232_Scale( cross_n_d, nrg_n, &st ); /* Q15-st-s3+s4 */ BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB tmp16 = shl_sat( negate( tmp16 ), add( sub( add( st, s3 ), s4 ), 1 - 14 ) ); /* Q1 */ - tmp16 = shr(add_sat(tmp16, 1), 1); /* Q0 */ + tmp16 = shr( add_sat( tmp16, 1 ), 1 ); /* Q0 */ #else - tmp16 = shl(negate(tmp16), add(sub(add(st, s3), s4), 1-14)); /* Q1 */ - tmp16 = shr(add(tmp16, 1), 1); /* Q0 */ + tmp16 = shl( negate( tmp16 ), add( sub( add( st, s3 ), s4 ), 1 - 14 ) ); /* Q1 */ + tmp16 = shr( add( tmp16, 1 ), 1 ); /* Q0 */ #endif BASOP_SATURATE_WARNING_ON_EVS; *gain_factor_param = tmp16; move16(); - if (GT_16(tmp16, 3)) + if ( GT_16( tmp16, 3 ) ) { *gain_factor_param = 3; move16(); } - if (tmp16 < 0) + if ( tmp16 < 0 ) { *gain_factor_param = 0; move16(); @@ -423,7 +427,7 @@ Word16 bass_pf_enc_fx( /*If optimal gain negatif or zero but snr still positif->gain=0.5f*/ test(); - if (snr > 0 && *gain_factor_param == 0) + if ( snr > 0 && *gain_factor_param == 0 ) { *gain_factor_param = 1; move16(); @@ -438,4 +442,3 @@ Word16 bass_pf_enc_fx( return 0; } - diff --git a/lib_enc/bw_detect_fx.c b/lib_enc/bw_detect_fx.c index 07fcc6763..eb3e62ddf 100644 --- a/lib_enc/bw_detect_fx.c +++ b/lib_enc/bw_detect_fx.c @@ -3,16 +3,16 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ //#include "prot_fx.h" /* Function prototypes */ -#include "rom_enc.h" /* Encoder static table prototypes */ +#include "rom_enc.h" /* Encoder static table prototypes */ #include "rom_com.h" #include "basop_util.h" #include "ivas_cnst.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* * Local constants @@ -22,16 +22,16 @@ #define BWD_MAX_BRATE_WIDER_BW_MDCT IVAS_80k #define BWD_MAX_BRATE_WIDER_BW_ISM IVAS_64k -#define ALPHA_BWD_FX 24576 /* 0.75 in Q15*/ -#define BWD_LT_THRESH_FX 19661 /* 0.6 in Q15*/ +#define ALPHA_BWD_FX 24576 /* 0.75 in Q15*/ +#define BWD_LT_THRESH_FX 19661 /* 0.6 in Q15*/ -#define BWD_COUNT_MAX 100 -#define BWD_COUNT_WIDER_BW 10 +#define BWD_COUNT_MAX 100 +#define BWD_COUNT_WIDER_BW 10 #define BWD_COUNT_WIDER_BW_MDCT 0 -#define BWD_N_BINS_MAX 13 +#define BWD_N_BINS_MAX 13 -#define CLDFB_ENER_OFFSET_FX 26214 /* 1.6 in Q14 */ +#define CLDFB_ENER_OFFSET_FX 26214 /* 1.6 in Q14 */ /*-------------------------------------------------------------------* * bw_detect() @@ -40,21 +40,21 @@ *--------------------------------------------------------------------*/ void bw_detect_fx( - Encoder_State *st, /* i/o: Encoder State */ - const Word16 signal_in[], /* i : input signal */ - Word16* spectrum, /* i : MDCT spectrum */ - const Word32 *enerBuffer, /* i : CLDFB Energy Q31 */ - const Word16 *cldfbBuf_Ener_Exp,/* i : CLDFB Energy Exponent */ - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const int16_t mct_on /* i : flag MCT mode */ + Encoder_State *st, /* i/o: Encoder State */ + const Word16 signal_in[], /* i : input signal */ + Word16 *spectrum, /* i : MDCT spectrum */ + const Word32 *enerBuffer, /* i : CLDFB Energy Q31 */ + const Word16 *cldfbBuf_Ener_Exp, /* i : CLDFB Energy Exponent */ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const int16_t mct_on /* i : flag MCT mode */ ) { Word16 Q_dct; Word16 i, j, k, bw_max, bin_width, n_bins; - Word16 max_NB, max_WB, max_SWB, max_FB, mean_NB, mean_WB, mean_SWB, mean_FB; /* Q11*/ + Word16 max_NB, max_WB, max_SWB, max_FB, mean_NB, mean_WB, mean_SWB, mean_FB; /* Q11*/ const Word16 *pt, *pt1; Word16 spect[L_FRAME48k], spect_bin[BWD_N_BINS_MAX]; - Word32 spect32[L_FRAME48k],in_win32[BWD_TOTAL_WIDTH]; + Word32 spect32[L_FRAME48k], in_win32[BWD_TOTAL_WIDTH]; Word16 e_tmp, f_tmp; Word32 L_tmp, sum32; @@ -65,107 +65,113 @@ void bw_detect_fx( Word16 cldfb_bin_Exp[9]; Word16 cldfb_bin_width = 4; const Word32 *pt32; - Word32 max_NB32, max_WB32, max_SWB32, max_FB32, mean_NB32, mean_WB32, mean_SWB32, mean_FB32; /* Q11*/ /* we need Word32 for the new cldfb energy vectors */ + Word32 max_NB32, max_WB32, max_SWB32, max_FB32, mean_NB32, mean_WB32, mean_SWB32, mean_FB32; /* Q11*/ /* we need Word32 for the new cldfb energy vectors */ Word16 bwd_count_wider_bw; #ifdef IVAS_CODE_DFT Word16 l_frame; #endif #ifndef IVAS_CODE_BWD - (void)spectrum; + (void) spectrum; #endif #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - bwd_count_wider_bw = BWD_COUNT_WIDER_BW; move16(); - test();test();test();test();test(); - if (st->ini_frame > 0 && ((EQ_16(st->element_mode, IVAS_CPE_MDCT) && (GE_32(st->element_brate, BWD_MIN_BRATE_WIDER_BW_MDCT) || mct_on)) || - (EQ_16(ivas_format, ISM_FORMAT) && GE_32(st->element_brate, BWD_MIN_BRATE_WIDER_BW_ISM)))) + bwd_count_wider_bw = BWD_COUNT_WIDER_BW; + move16(); + test(); + test(); + test(); + test(); + test(); + if ( st->ini_frame > 0 && ( ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && ( GE_32( st->element_brate, BWD_MIN_BRATE_WIDER_BW_MDCT ) || mct_on ) ) || + ( EQ_16( ivas_format, ISM_FORMAT ) && GE_32( st->element_brate, BWD_MIN_BRATE_WIDER_BW_ISM ) ) ) ) { - bwd_count_wider_bw = BWD_COUNT_WIDER_BW_MDCT; move16(); + bwd_count_wider_bw = BWD_COUNT_WIDER_BW_MDCT; + move16(); } - IF( GT_32(st->input_Fs,8000)) + IF( GT_32( st->input_Fs, 8000 ) ) { - IF ( enerBuffer != NULL) + IF( enerBuffer != NULL ) { n_bins = 9; move16(); scale = st->cldfbAnaEnc->scale; - move16();/* 7Q8 */ + move16(); /* 7Q8 */ /*ScalFac = 1/ ( st->cldfbAnaEnc->scale * st->cldfbAnaEnc->scale * 8.f);*/ /*hs->CLDFBscalingFactor = div_s(1, shl(i_mult2(CLDFBscale, CLDFBscale), 3));*/ - assert(2048/*1.0/(1<<4) Q15*/ < mult(scale, scale)); + assert( 2048 /*1.0/(1<<4) Q15*/ < mult( scale, scale ) ); /* Exponent ScalFacInv: -16 = -(2*7 (CLDFBscale) + 2 (8.0) */ - ScalFacInv = shl(mult(scale,scale),1); /* Q8*Q8 = Q16 + shl -> Q17 -16 -> Q1; shl -> Q2 */ + ScalFacInv = shl( mult( scale, scale ), 1 ); /* Q8*Q8 = Q16 + shl -> Q17 -16 -> Q1; shl -> Q2 */ /* Exponent ScalFac: -15 = -(2*7 (CLDFBscale) + 2 (8.0) - 1 (1.0)) */ - ScalFac = div_s(0x4000,ScalFacInv); /* bin(17214) *2^-15 * 2^-15 = 0.0000160 , use CLDFBscalingFactor_EXP for this*/ /*Q15*/ + ScalFac = div_s( 0x4000, ScalFacInv ); /* bin(17214) *2^-15 * 2^-15 = 0.0000160 , use CLDFBscalingFactor_EXP for this*/ /*Q15*/ /*set_f( cldfb_bin, 0.001f, 9 );*/ - set32_fx( cldfb_bin, 1, n_bins ); /* Q31*/ + set32_fx( cldfb_bin, 1, n_bins ); /* Q31*/ set16_fx( cldfb_bin_Exp, -15, n_bins ); /* NB: 1.2 - 2.8 kHz, 4 cldfb-bands */ - FOR(i=0; i< cldfb_bin_width; i++ ) + FOR( i = 0; i < cldfb_bin_width; i++ ) { - cldfb_bin[0] = BASOP_Util_Add_Mant32Exp( cldfb_bin[0],cldfb_bin_Exp[0], enerBuffer[3+i], cldfbBuf_Ener_Exp[3+i], &(cldfb_bin_Exp[0]) ); - move32();/* result: Q31 */ + cldfb_bin[0] = BASOP_Util_Add_Mant32Exp( cldfb_bin[0], cldfb_bin_Exp[0], enerBuffer[3 + i], cldfbBuf_Ener_Exp[3 + i], &( cldfb_bin_Exp[0] ) ); + move32(); /* result: Q31 */ } - cldfb_bin[0] = Mpy_32_16_1(cldfb_bin[0], ScalFac ); + cldfb_bin[0] = Mpy_32_16_1( cldfb_bin[0], ScalFac ); move32(); /* Q31 */ - cldfb_bin_Exp[0] = add( cldfb_bin_Exp[0], CLDFBscalingFactor_EXP); + cldfb_bin_Exp[0] = add( cldfb_bin_Exp[0], CLDFBscalingFactor_EXP ); move16(); - if(cldfb_bin[i] == 0) + if ( cldfb_bin[i] == 0 ) { - cldfb_bin[i] = L_deposit_l(1); + cldfb_bin[i] = L_deposit_l( 1 ); } - L_tmp = BASOP_Util_Log2(cldfb_bin[0]); /*(log2(660423549*2^(-31))/64)*2^31*/ + L_tmp = BASOP_Util_Log2( cldfb_bin[0] ); /*(log2(660423549*2^(-31))/64)*2^31*/ #ifdef BASOP_NOGLOB - L_tmp = L_add_o(L_tmp,L_shl(L_deposit_l(cldfb_bin_Exp[0]),31-LD_DATA_SCALE), &Overflow); /* Q25 */ -#else /* BASOP_NOGLOB */ - L_tmp = L_add(L_tmp,L_shl(L_deposit_l(cldfb_bin_Exp[0]),31-LD_DATA_SCALE)); /* Q25 */ -#endif /* BASOP_NOGLOB */ - cldfb_bin[0] = Mpy_32_16_1(L_tmp, 9864/*1.0f/3.3219280948873623478703194294894f Q15*/); - move32();/* 1/log2(10) */ /* Q25 */ + L_tmp = L_add_o( L_tmp, L_shl( L_deposit_l( cldfb_bin_Exp[0] ), 31 - LD_DATA_SCALE ), &Overflow ); /* Q25 */ +#else /* BASOP_NOGLOB */ + L_tmp = L_add( L_tmp, L_shl( L_deposit_l( cldfb_bin_Exp[0] ), 31 - LD_DATA_SCALE ) ); /* Q25 */ +#endif /* BASOP_NOGLOB */ + cldfb_bin[0] = Mpy_32_16_1( L_tmp, 9864 /*1.0f/3.3219280948873623478703194294894f Q15*/ ); + move32(); /* 1/log2(10) */ /* Q25 */ /* WB: 4.4 - 7.2 kHz, 8 cldfb-bands, mid band(14) counted twice */ - IF( GE_32(st->input_Fs,16000)) + IF( GE_32( st->input_Fs, 16000 ) ) { /* cldfb_bin[1] += Sum( &(enerBuffer[11]), cldfb_bin_width ); cldfb_bin[2] += Sum( &(enerBuffer[14]), cldfb_bin_width );*/ - FOR(i=0; i< cldfb_bin_width; i++ ) + FOR( i = 0; i < cldfb_bin_width; i++ ) { - cldfb_bin[1] = BASOP_Util_Add_Mant32Exp( cldfb_bin[1],cldfb_bin_Exp[1], enerBuffer[11+i], cldfbBuf_Ener_Exp[11+i], &(cldfb_bin_Exp[1]) ); + cldfb_bin[1] = BASOP_Util_Add_Mant32Exp( cldfb_bin[1], cldfb_bin_Exp[1], enerBuffer[11 + i], cldfbBuf_Ener_Exp[11 + i], &( cldfb_bin_Exp[1] ) ); move32(); - cldfb_bin[2] = BASOP_Util_Add_Mant32Exp( cldfb_bin[2],cldfb_bin_Exp[2], enerBuffer[14+i], cldfbBuf_Ener_Exp[14+i], &(cldfb_bin_Exp[2]) ); + cldfb_bin[2] = BASOP_Util_Add_Mant32Exp( cldfb_bin[2], cldfb_bin_Exp[2], enerBuffer[14 + i], cldfbBuf_Ener_Exp[14 + i], &( cldfb_bin_Exp[2] ) ); move32(); } - FOR(i=1; i<= 2; i++ ) + FOR( i = 1; i <= 2; i++ ) { - cldfb_bin[i] = Mpy_32_16_1(cldfb_bin[i], ScalFac ); + cldfb_bin[i] = Mpy_32_16_1( cldfb_bin[i], ScalFac ); move32(); - cldfb_bin_Exp[i] = add( cldfb_bin_Exp[i], CLDFBscalingFactor_EXP); + cldfb_bin_Exp[i] = add( cldfb_bin_Exp[i], CLDFBscalingFactor_EXP ); move16(); - if(cldfb_bin[i] == 0) + if ( cldfb_bin[i] == 0 ) { - cldfb_bin[i] = L_deposit_l(1); + cldfb_bin[i] = L_deposit_l( 1 ); } - L_tmp = BASOP_Util_Log2(cldfb_bin[i]); /*(log2(660423549*2^(-31))/64)*2^31*/ - L_tmp = L_add(L_tmp,L_shl(L_deposit_l(cldfb_bin_Exp[i]),31-LD_DATA_SCALE)); /* Q25 */ - cldfb_bin[i] = Mpy_32_16_1(L_tmp, 9864/*1.0f/3.3219280948873623478703194294894f Q15*/); - move32();/* 1/log2(10) */ /* Q25 */ + L_tmp = BASOP_Util_Log2( cldfb_bin[i] ); /*(log2(660423549*2^(-31))/64)*2^31*/ + L_tmp = L_add( L_tmp, L_shl( L_deposit_l( cldfb_bin_Exp[i] ), 31 - LD_DATA_SCALE ) ); /* Q25 */ + cldfb_bin[i] = Mpy_32_16_1( L_tmp, 9864 /*1.0f/3.3219280948873623478703194294894f Q15*/ ); + move32(); /* 1/log2(10) */ /* Q25 */ } } /* SWB: 9.2 - 15.6 kHz, 16 cldfb-bands */ - IF( GE_32(st->input_Fs,32000)) + IF( GE_32( st->input_Fs, 32000 ) ) { /* cldfb_bin[3] += Sum( &(enerBuffer[23]), cldfb_bin_width ); @@ -173,104 +179,103 @@ void bw_detect_fx( cldfb_bin[5] += Sum( &(enerBuffer[31]), cldfb_bin_width ); cldfb_bin[6] += Sum( &(enerBuffer[35]), cldfb_bin_width ); */ - FOR(i=0; i< cldfb_bin_width; i++ ) + FOR( i = 0; i < cldfb_bin_width; i++ ) { - cldfb_bin[3] = BASOP_Util_Add_Mant32Exp( cldfb_bin[3],cldfb_bin_Exp[3], enerBuffer[23+i], cldfbBuf_Ener_Exp[23+i], &(cldfb_bin_Exp[3]) ); + cldfb_bin[3] = BASOP_Util_Add_Mant32Exp( cldfb_bin[3], cldfb_bin_Exp[3], enerBuffer[23 + i], cldfbBuf_Ener_Exp[23 + i], &( cldfb_bin_Exp[3] ) ); move32(); - cldfb_bin[4] = BASOP_Util_Add_Mant32Exp( cldfb_bin[4],cldfb_bin_Exp[4], enerBuffer[27+i], cldfbBuf_Ener_Exp[27+i], &(cldfb_bin_Exp[4]) ); + cldfb_bin[4] = BASOP_Util_Add_Mant32Exp( cldfb_bin[4], cldfb_bin_Exp[4], enerBuffer[27 + i], cldfbBuf_Ener_Exp[27 + i], &( cldfb_bin_Exp[4] ) ); move32(); - cldfb_bin[5] = BASOP_Util_Add_Mant32Exp( cldfb_bin[5],cldfb_bin_Exp[5], enerBuffer[31+i], cldfbBuf_Ener_Exp[31+i], &(cldfb_bin_Exp[5]) ); + cldfb_bin[5] = BASOP_Util_Add_Mant32Exp( cldfb_bin[5], cldfb_bin_Exp[5], enerBuffer[31 + i], cldfbBuf_Ener_Exp[31 + i], &( cldfb_bin_Exp[5] ) ); move32(); - cldfb_bin[6] = BASOP_Util_Add_Mant32Exp( cldfb_bin[6],cldfb_bin_Exp[6], enerBuffer[35+i], cldfbBuf_Ener_Exp[35+i], &(cldfb_bin_Exp[6]) ); + cldfb_bin[6] = BASOP_Util_Add_Mant32Exp( cldfb_bin[6], cldfb_bin_Exp[6], enerBuffer[35 + i], cldfbBuf_Ener_Exp[35 + i], &( cldfb_bin_Exp[6] ) ); move32(); } - FOR(i=3; i<= 6; i++ ) + FOR( i = 3; i <= 6; i++ ) { - cldfb_bin[i] = Mpy_32_16_1(cldfb_bin[i], ScalFac ); + cldfb_bin[i] = Mpy_32_16_1( cldfb_bin[i], ScalFac ); move32(); - cldfb_bin_Exp[i] = add( cldfb_bin_Exp[i], CLDFBscalingFactor_EXP); + cldfb_bin_Exp[i] = add( cldfb_bin_Exp[i], CLDFBscalingFactor_EXP ); move16(); - if(cldfb_bin[i] == 0) + if ( cldfb_bin[i] == 0 ) { - cldfb_bin[i] = L_deposit_l(1); + cldfb_bin[i] = L_deposit_l( 1 ); } - L_tmp = BASOP_Util_Log2(cldfb_bin[i]); /*(log2(660423549*2^(-31))/64)*2^31*/ - L_tmp = L_add(L_tmp,L_shl(L_deposit_l(cldfb_bin_Exp[i]),31-LD_DATA_SCALE)); /* Q25 */ - cldfb_bin[i] = Mpy_32_16_1(L_tmp, 9864/*1.0f/3.3219280948873623478703194294894f Q15*/); - move32();/* 1/log2(10) */ /* Q25 */ + L_tmp = BASOP_Util_Log2( cldfb_bin[i] ); /*(log2(660423549*2^(-31))/64)*2^31*/ + L_tmp = L_add( L_tmp, L_shl( L_deposit_l( cldfb_bin_Exp[i] ), 31 - LD_DATA_SCALE ) ); /* Q25 */ + cldfb_bin[i] = Mpy_32_16_1( L_tmp, 9864 /*1.0f/3.3219280948873623478703194294894f Q15*/ ); + move32(); /* 1/log2(10) */ /* Q25 */ } } /* FB: 16.8 - 20.0 kHz, 8 cldfb-bands */ - IF( GE_32(st->input_Fs,48000)) + IF( GE_32( st->input_Fs, 48000 ) ) { /* cldfb_bin[7] += Sum( &(enerBuffer[42]), cldfb_bin_width ); cldfb_bin[8] += Sum( &(enerBuffer[46]), cldfb_bin_width ); */ - FOR(i=0; i< cldfb_bin_width; i++ ) + FOR( i = 0; i < cldfb_bin_width; i++ ) { - cldfb_bin[7] = BASOP_Util_Add_Mant32Exp( cldfb_bin[7],cldfb_bin_Exp[7], enerBuffer[42+i], cldfbBuf_Ener_Exp[42+i], &(cldfb_bin_Exp[7]) ); + cldfb_bin[7] = BASOP_Util_Add_Mant32Exp( cldfb_bin[7], cldfb_bin_Exp[7], enerBuffer[42 + i], cldfbBuf_Ener_Exp[42 + i], &( cldfb_bin_Exp[7] ) ); move32(); - cldfb_bin[8] = BASOP_Util_Add_Mant32Exp( cldfb_bin[8],cldfb_bin_Exp[8], enerBuffer[46+i], cldfbBuf_Ener_Exp[46+i], &(cldfb_bin_Exp[8]) ); + cldfb_bin[8] = BASOP_Util_Add_Mant32Exp( cldfb_bin[8], cldfb_bin_Exp[8], enerBuffer[46 + i], cldfbBuf_Ener_Exp[46 + i], &( cldfb_bin_Exp[8] ) ); move32(); } - FOR(i=7; i<= 8; i++ ) + FOR( i = 7; i <= 8; i++ ) { - cldfb_bin[i] = Mpy_32_16_1(cldfb_bin[i], ScalFac ); + cldfb_bin[i] = Mpy_32_16_1( cldfb_bin[i], ScalFac ); move32(); - cldfb_bin_Exp[i] = add( cldfb_bin_Exp[i], CLDFBscalingFactor_EXP); + cldfb_bin_Exp[i] = add( cldfb_bin_Exp[i], CLDFBscalingFactor_EXP ); move16(); - if(cldfb_bin[i] == 0) + if ( cldfb_bin[i] == 0 ) { - cldfb_bin[i] = L_deposit_l(1); + cldfb_bin[i] = L_deposit_l( 1 ); } - L_tmp = BASOP_Util_Log2(cldfb_bin[i]); /*(log2(660423549*2^(-31))/64)*2^31*/ - L_tmp = L_add(L_tmp,L_shl(L_deposit_l(cldfb_bin_Exp[i]),31-LD_DATA_SCALE)); /* Q25 */ - cldfb_bin[i] = Mpy_32_16_1(L_tmp, 9864/*1.0f/3.3219280948873623478703194294894f Q15*/); - move32();/* 1/log2(10) */ /* Q25 */ + L_tmp = BASOP_Util_Log2( cldfb_bin[i] ); /*(log2(660423549*2^(-31))/64)*2^31*/ + L_tmp = L_add( L_tmp, L_shl( L_deposit_l( cldfb_bin_Exp[i] ), 31 - LD_DATA_SCALE ) ); /* Q25 */ + cldfb_bin[i] = Mpy_32_16_1( L_tmp, 9864 /*1.0f/3.3219280948873623478703194294894f Q15*/ ); + move32(); /* 1/log2(10) */ /* Q25 */ } } /* cldfb_bin_Exp[] are applied now in cldfb_bin[i] -> don't use again */ set16_fx( cldfb_bin_Exp, 0, n_bins ); - } ELSE { /* set width of a speactral bin (corresponds to 1.5kHz) */ - IF( EQ_32(st->input_Fs,16000)) + IF( EQ_32( st->input_Fs, 16000 ) ) { bw_max = WB; move16(); bin_width = 60; move16(); n_bins = 5; - move16(); /* spectrum to 7.5 kHz */ + move16(); /* spectrum to 7.5 kHz */ } - ELSE IF( EQ_32(st->input_Fs,32000)) + ELSE IF( EQ_32( st->input_Fs, 32000 ) ) { bw_max = SWB; move16(); bin_width = 30; move16(); n_bins = 10; - move16(); /* spectrum to 15.0 kHz */ + move16(); /* spectrum to 15.0 kHz */ } - ELSE /* st->input_Fs == 48000 */ + ELSE /* st->input_Fs == 48000 */ { bw_max = FB; move16(); bin_width = 20; move16(); n_bins = BWD_N_BINS_MAX; - move16(); /* spectrum to 19.5 kHz */ + move16(); /* spectrum to 19.5 kHz */ } Q_dct = 0; move16(); - IF(signal_in != NULL) + IF( signal_in != NULL ) { /*---------------------------------------------------------------------* * windowing of the input signal @@ -278,28 +283,28 @@ void bw_detect_fx( pt = signal_in; pt1 = hann_window_320_fx; /* 1st half of the window */ - FOR(i = 0; i < BWD_TOTAL_WIDTH / 2; i++) + FOR( i = 0; i < BWD_TOTAL_WIDTH / 2; i++ ) { /*in_win[i] = *pt++ * *pt1++;*/ - in_win32[i] = L_mult(*pt++,*pt1++); - move32(); /* Q0*Q15 -> Q16*/ + in_win32[i] = L_mult( *pt++, *pt1++ ); + move32(); /* Q0*Q15 -> Q16*/ } pt1--; /* 2nd half of the window */ - FOR(; i < BWD_TOTAL_WIDTH; i++) + FOR( ; i < BWD_TOTAL_WIDTH; i++ ) { /*in_win[i] = *pt++ * *pt1--;*/ - in_win32[i] = L_mult(*pt++,*pt1--); + in_win32[i] = L_mult( *pt++, *pt1-- ); move32(); } - edct_fx(in_win32, spect32, BWD_TOTAL_WIDTH, &Q_dct /*,st->element_mode*/); + edct_fx( in_win32, spect32, BWD_TOTAL_WIDTH, &Q_dct /*,st->element_mode*/ ); - FOR(i = 0; i < BWD_TOTAL_WIDTH; i++) + FOR( i = 0; i < BWD_TOTAL_WIDTH; i++ ) { #ifdef BASOP_NOGLOB - spect[i] = round_fx_o(L_shr_o(spect32[i],Q_dct, &Overflow), &Overflow); + spect[i] = round_fx_o( L_shr_o( spect32[i], Q_dct, &Overflow ), &Overflow ); #else /* BASOP_NOGLOB */ - spect[i] = round_fx(L_shr(spect32[i],Q_dct)); + spect[i] = round_fx( L_shr( spect32[i], Q_dct ) ); #endif } Q_dct = -2; @@ -308,14 +313,14 @@ void bw_detect_fx( ELSE { #ifdef IVAS_CODE_DFT - l_frame = (int16_t)(st->input_Fs / FRAMES_PER_SEC); - if (st->core == TCX_10_CORE) + l_frame = (int16_t) ( st->input_Fs / FRAMES_PER_SEC ); + if ( st->core == TCX_10_CORE ) { l_frame /= 2; } - bin_width *= (l_frame / BWD_TOTAL_WIDTH); - mvr2r(spectrum, spect, l_frame); + bin_width *= ( l_frame / BWD_TOTAL_WIDTH ); + mvr2r( spectrum, spect, l_frame ); #endif } /*---------------------------------------------------------------------* @@ -323,25 +328,25 @@ void bw_detect_fx( *---------------------------------------------------------------------*/ set16_fx( spect_bin, 1, n_bins ); - Q_dct = shl(Q_dct,1); + Q_dct = shl( Q_dct, 1 ); - FOR( k=0; k<=bw_max; k++ ) + FOR( k = 0; k <= bw_max; k++ ) { - FOR( i=bwd_start_bin[k]; i<=bwd_end_bin[k]; i++ ) + FOR( i = bwd_start_bin[k]; i <= bwd_end_bin[k]; i++ ) { - sum32 = L_deposit_l(1); - pt1 = &spect[i_mult2(i,bin_width)]; - FOR( j=0; j Q25 */ + cldfb_ener_offset = (Word16) CLDFB_ENER_OFFSET_FX; /* Q14 */ + move16(); + cldfb_ener_offset_32 = L_deposit_l( cldfb_ener_offset ); /* Q14 in 32bit var */ + cldfb_ener_offset_32 = L_shl( cldfb_ener_offset_32, 25 - 14 ); /* Q14 -> Q25 */ - mean_NB = extract_l(L_shr( L_add(mean_NB32 ,cldfb_ener_offset_32), 25-11)); /* (Q25 + Q25) -> Q11 */ - max_NB = extract_l(L_shr( L_add(max_NB32 ,cldfb_ener_offset_32), 25-11)); /* (Q25 + Q25) -> Q11 */ - mean_WB = extract_l(L_shr( L_add(mean_WB32 ,cldfb_ener_offset_32), 25-11)); /* (Q25 + Q25) -> Q11 */ - max_WB = extract_l(L_shr( L_add(max_WB32 ,cldfb_ener_offset_32), 25-11)); /* (Q25 + Q25) -> Q11 */ + mean_NB = extract_l( L_shr( L_add( mean_NB32, cldfb_ener_offset_32 ), 25 - 11 ) ); /* (Q25 + Q25) -> Q11 */ + max_NB = extract_l( L_shr( L_add( max_NB32, cldfb_ener_offset_32 ), 25 - 11 ) ); /* (Q25 + Q25) -> Q11 */ + mean_WB = extract_l( L_shr( L_add( mean_WB32, cldfb_ener_offset_32 ), 25 - 11 ) ); /* (Q25 + Q25) -> Q11 */ + max_WB = extract_l( L_shr( L_add( max_WB32, cldfb_ener_offset_32 ), 25 - 11 ) ); /* (Q25 + Q25) -> Q11 */ /*if WB */ - IF( EQ_32(st->input_Fs,16000)) + IF( EQ_32( st->input_Fs, 16000 ) ) { /* for 16kHz sampled inputs, do not check SWB & FB */ mean_SWB = 0; move16(); - max_SWB = 0; + max_SWB = 0; move16(); - mean_FB = 0; + mean_FB = 0; move16(); - max_FB = 0; + max_FB = 0; move16(); } ELSE { /* else if SWB */ - IF( EQ_32(st->input_Fs,32000)) + IF( EQ_32( st->input_Fs, 32000 ) ) { /* for 32kHz sampled inputs, do not check FB */ mean_FB = 0; move16(); - max_FB = 0; + max_FB = 0; move16(); /* SWB: 8,8 - 15,2 kHz, 16 cldfb-bands (4 bins) */ maximum_32_fx( pt32, 4, &max_SWB32 ); - L_tmp = L_shr(*pt32++, 2); /* /4 */ - L_tmp = L_add(L_tmp,L_shr(*pt32++, 2)); - L_tmp = L_add(L_tmp,L_shr(*pt32++, 2)); - mean_SWB32 = L_add(L_tmp,L_shr(*pt32++, 2)); - - mean_SWB = extract_l(L_shr(L_add(mean_SWB32, cldfb_ener_offset_32), 25-11)); /* (Q25 + Q25) -> Q11 */ - max_SWB = extract_l(L_shr(L_add(max_SWB32 , cldfb_ener_offset_32), 25-11)); /* (Q25 + Q25) -> Q11 */ + L_tmp = L_shr( *pt32++, 2 ); /* /4 */ + L_tmp = L_add( L_tmp, L_shr( *pt32++, 2 ) ); + L_tmp = L_add( L_tmp, L_shr( *pt32++, 2 ) ); + mean_SWB32 = L_add( L_tmp, L_shr( *pt32++, 2 ) ); + mean_SWB = extract_l( L_shr( L_add( mean_SWB32, cldfb_ener_offset_32 ), 25 - 11 ) ); /* (Q25 + Q25) -> Q11 */ + max_SWB = extract_l( L_shr( L_add( max_SWB32, cldfb_ener_offset_32 ), 25 - 11 ) ); /* (Q25 + Q25) -> Q11 */ } ELSE { /* FB */ @@ -439,31 +444,30 @@ void bw_detect_fx( maximum_32_fx( pt32, 4, &max_SWB32 ); - L_tmp = L_shr(*pt32++, 2); /* /4 */ - L_tmp = L_add(L_tmp,L_shr(*pt32++, 2)); - L_tmp = L_add(L_tmp,L_shr(*pt32++, 2)); - mean_SWB32 = L_add(L_tmp,L_shr(*pt32++, 2)); + L_tmp = L_shr( *pt32++, 2 ); /* /4 */ + L_tmp = L_add( L_tmp, L_shr( *pt32++, 2 ) ); + L_tmp = L_add( L_tmp, L_shr( *pt32++, 2 ) ); + mean_SWB32 = L_add( L_tmp, L_shr( *pt32++, 2 ) ); - mean_SWB = extract_l(L_shr(L_add(mean_SWB32, cldfb_ener_offset_32), 25-11)); /* (Q25 + Q25) -> Q11 */ - max_SWB = extract_l(L_shr(L_add(max_SWB32 , cldfb_ener_offset_32), 25-11)); /* (Q25 + Q25) -> Q11 */ + mean_SWB = extract_l( L_shr( L_add( mean_SWB32, cldfb_ener_offset_32 ), 25 - 11 ) ); /* (Q25 + Q25) -> Q11 */ + max_SWB = extract_l( L_shr( L_add( max_SWB32, cldfb_ener_offset_32 ), 25 - 11 ) ); /* (Q25 + Q25) -> Q11 */ /* FB: 16,4 - 19,6 kHz, 8 cldfb-bands (2 bins) */ maximum_32_fx( pt32, 2, &max_FB32 ); - L_tmp = L_shr(*pt32++, 1); - mean_FB32 = L_add(L_tmp,L_shr(*pt32++, 1)); - - mean_FB = extract_l(L_shr(L_add(mean_FB32, cldfb_ener_offset_32), 25-11)); /* (Q25 + Q25) -> Q11 */ - max_FB = extract_l(L_shr(L_add(max_FB32 , cldfb_ener_offset_32), 25-11)); /* (Q25 + Q25) -> Q11 */ + L_tmp = L_shr( *pt32++, 1 ); + mean_FB32 = L_add( L_tmp, L_shr( *pt32++, 1 ) ); + mean_FB = extract_l( L_shr( L_add( mean_FB32, cldfb_ener_offset_32 ), 25 - 11 ) ); /* (Q25 + Q25) -> Q11 */ + max_FB = extract_l( L_shr( L_add( max_FB32, cldfb_ener_offset_32 ), 25 - 11 ) ); /* (Q25 + Q25) -> Q11 */ } } } ELSE { - pt = (const Word16 *)spect_bin; + pt = (const Word16 *) spect_bin; /* NB: 1.5-3.0kHz (1 bin) */ pt++; mean_NB = *pt++; @@ -474,11 +478,11 @@ void bw_detect_fx( /* WB: 4.5-7.5kHz (2 bins) */ pt++; maximum_fx( pt, 2, &max_WB ); - L_tmp = L_mult(*pt++,16384); - L_tmp = L_mac(L_tmp,*pt++,16384); - mean_WB = round_fx(L_tmp); + L_tmp = L_mult( *pt++, 16384 ); + L_tmp = L_mac( L_tmp, *pt++, 16384 ); + mean_WB = round_fx( L_tmp ); - IF( EQ_32(st->input_Fs,16000)) + IF( EQ_32( st->input_Fs, 16000 ) ) { /* for 16kHz sampled inputs, do not check SWB & FB */ mean_SWB = 0; @@ -495,20 +499,20 @@ void bw_detect_fx( /* SWB: 9.0-15.0kHz (4 bins) */ pt++; maximum_fx( pt, 4, &max_SWB ); - L_tmp = L_mult(*pt++,8192); - L_tmp = L_mac(L_tmp,*pt++,8192); - L_tmp = L_mac(L_tmp,*pt++,8192); - L_tmp = L_mac(L_tmp,*pt++,8192); - mean_SWB = round_fx(L_tmp); + L_tmp = L_mult( *pt++, 8192 ); + L_tmp = L_mac( L_tmp, *pt++, 8192 ); + L_tmp = L_mac( L_tmp, *pt++, 8192 ); + L_tmp = L_mac( L_tmp, *pt++, 8192 ); + mean_SWB = round_fx( L_tmp ); - IF( EQ_32(st->input_Fs,48000)) + IF( EQ_32( st->input_Fs, 48000 ) ) { /* FB: 16.5-19.5kHz (2 bins) */ pt++; maximum_fx( pt, 2, &max_FB ); - L_tmp = L_mult(*pt++,16384); - L_tmp = L_mac(L_tmp,*pt++,16384); - mean_FB = round_fx(L_tmp); + L_tmp = L_mult( *pt++, 16384 ); + L_tmp = L_mac( L_tmp, *pt++, 16384 ); + mean_FB = round_fx( L_tmp ); } ELSE { @@ -526,56 +530,55 @@ void bw_detect_fx( /*if( localVAD || st->lp_noise > 30 )*/ test(); - IF( st->localVAD || GT_16(st->lp_noise_fx,7680)) + IF( st->localVAD || GT_16( st->lp_noise_fx, 7680 ) ) { /*st->lt_mean_NB_fx = ALPHA_BWD * st->lt_mean_NB_fx + (1-ALPHA_BWD) * mean_NB;*/ - L_tmp = L_mult(ALPHA_BWD_FX, st->lt_mean_NB_fx); /* Q15 * Q11 -> Q27 */ - L_tmp = L_mac(L_tmp, 32768-ALPHA_BWD_FX, mean_NB); /* Q15 * Q11) -> L_mac(Q27, Q27) -> Q27*/ - st->lt_mean_NB_fx = round_fx(L_tmp); /* Q11 (27-16) */ + L_tmp = L_mult( ALPHA_BWD_FX, st->lt_mean_NB_fx ); /* Q15 * Q11 -> Q27 */ + L_tmp = L_mac( L_tmp, 32768 - ALPHA_BWD_FX, mean_NB ); /* Q15 * Q11) -> L_mac(Q27, Q27) -> Q27*/ + st->lt_mean_NB_fx = round_fx( L_tmp ); /* Q11 (27-16) */ /*st->lt_mean_WB_fx = ALPHA_BWD * st->lt_mean_WB_fx + (1-ALPHA_BWD) * mean_WB;*/ - L_tmp = L_mult(ALPHA_BWD_FX, st->lt_mean_WB_fx); - L_tmp = L_mac(L_tmp, 32768-ALPHA_BWD_FX, mean_WB); - st->lt_mean_WB_fx = round_fx(L_tmp); + L_tmp = L_mult( ALPHA_BWD_FX, st->lt_mean_WB_fx ); + L_tmp = L_mac( L_tmp, 32768 - ALPHA_BWD_FX, mean_WB ); + st->lt_mean_WB_fx = round_fx( L_tmp ); /*st->lt_mean_SWB_fx = ALPHA_BWD * st->lt_mean_SWB_fx + (1-ALPHA_BWD) * mean_SWB;*/ - L_tmp = L_mult(ALPHA_BWD_FX, st->lt_mean_SWB_fx); - L_tmp = L_mac(L_tmp, 32768-ALPHA_BWD_FX, mean_SWB); - st->lt_mean_SWB_fx = round_fx(L_tmp); + L_tmp = L_mult( ALPHA_BWD_FX, st->lt_mean_SWB_fx ); + L_tmp = L_mac( L_tmp, 32768 - ALPHA_BWD_FX, mean_SWB ); + st->lt_mean_SWB_fx = round_fx( L_tmp ); - - IF ( enerBuffer != NULL ) + IF( enerBuffer != NULL ) { /*if( 0.9f * max_WB > BWD_LT_THRESH_FX * st->lt_mean_NB_fx )*/ /* optim: if( max_WB > (BWD_LT_THRESH_FX / 0.9) * st->lt_mean_NB_fx )*/ - L_tmp = L_mult(3686,max_WB); /* (0.9 in Q12) x Q11 -> Q24*/ + L_tmp = L_mult( 3686, max_WB ); /* (0.9 in Q12) x Q11 -> Q24*/ - L_tmp1 = L_mult(BWD_LT_THRESH_FX,st->lt_mean_NB_fx); /* Q15 x Q11 -> Q27 */ - L_tmp1 = L_shl(L_tmp1, 24-27); /* Q27 -> Q24) */ - L_tmp1 = L_sub(L_tmp, L_tmp1 ); + L_tmp1 = L_mult( BWD_LT_THRESH_FX, st->lt_mean_NB_fx ); /* Q15 x Q11 -> Q27 */ + L_tmp1 = L_shl( L_tmp1, 24 - 27 ); /* Q27 -> Q24) */ + L_tmp1 = L_sub( L_tmp, L_tmp1 ); IF( L_tmp1 > 0 ) { /*if( 2.5f * max_WB > max_NB )*/ - L_tmp = L_mult(10240,max_WB); /* 2.5 in Q12 x Q11 -> Q24 */ - L_tmp1 = L_mult(max_NB, 4096); /* Q11 x (1 in Q12) -> Q24 */ - IF( GT_32(L_tmp,L_tmp1)) /* Q24 */ + L_tmp = L_mult( 10240, max_WB ); /* 2.5 in Q12 x Q11 -> Q24 */ + L_tmp1 = L_mult( max_NB, 4096 ); /* Q11 x (1 in Q12) -> Q24 */ + IF( GT_32( L_tmp, L_tmp1 ) ) /* Q24 */ { - st->count_WB = add(st->count_WB,1); + st->count_WB = add( st->count_WB, 1 ); } } ELSE { /*if( 3.5f * mean_WB < mean_NB )*/ - L_tmp = L_mult(14336,mean_WB); /* 3.5 in Q12 x Q11 -> Q24*/ - L_tmp1 = L_mult(mean_NB,4096); - L_tmp = L_sub(L_tmp, L_tmp1); + L_tmp = L_mult( 14336, mean_WB ); /* 3.5 in Q12 x Q11 -> Q24*/ + L_tmp1 = L_mult( mean_NB, 4096 ); + L_tmp = L_sub( L_tmp, L_tmp1 ); IF( L_tmp < 0 ) { - st->count_WB = sub(st->count_WB, 1); + st->count_WB = sub( st->count_WB, 1 ); } } @@ -583,169 +586,168 @@ void bw_detect_fx( /* IF( L_msu( L_tmp,BWD_LT_THRESH_FX,st->lt_mean_WB_fx) > 0 && L_msu( L_deposit_h(max_WB),BWD_LT_THRESH_FX,st->lt_mean_NB_fx) > 0 ) {*/ - L_tmp = L_mult(3400,max_SWB); /* (0.83 in Q12) x Q11 -> Q24*/ - L_tmp1 = L_mult(BWD_LT_THRESH_FX,st->lt_mean_WB_fx); /* Q15 x Q11 -> Q27 */ - L_tmp1 = L_shl(L_tmp1, 24-27); /* Q27 -> Q24) */ - L_tmp1 = L_sub(L_tmp, L_tmp1 ); + L_tmp = L_mult( 3400, max_SWB ); /* (0.83 in Q12) x Q11 -> Q24*/ + L_tmp1 = L_mult( BWD_LT_THRESH_FX, st->lt_mean_WB_fx ); /* Q15 x Q11 -> Q27 */ + L_tmp1 = L_shl( L_tmp1, 24 - 27 ); /* Q27 -> Q24) */ + L_tmp1 = L_sub( L_tmp, L_tmp1 ); - L_tmp = L_mult( max_WB,4096); - L_tmp2 = L_mult(BWD_LT_THRESH_FX,st->lt_mean_NB_fx); /* Q15 x Q11 -> Q27 */ - L_tmp2 = L_shl(L_tmp2, 24-27); /* Q27 -> Q24) */ - L_tmp2 = L_sub(L_tmp, L_tmp2 ); + L_tmp = L_mult( max_WB, 4096 ); + L_tmp2 = L_mult( BWD_LT_THRESH_FX, st->lt_mean_NB_fx ); /* Q15 x Q11 -> Q27 */ + L_tmp2 = L_shl( L_tmp2, 24 - 27 ); /* Q27 -> Q24) */ + L_tmp2 = L_sub( L_tmp, L_tmp2 ); test(); - IF(L_tmp1 > 0 && L_tmp2 > 0 ) + IF( L_tmp1 > 0 && L_tmp2 > 0 ) { /*if( 2 * max_SWB > max_WB )*/ - L_tmp = L_mult(max_WB,4096); - L_tmp1 = L_mult(8192,max_SWB); /* 2.0 in Q12 x Q11 -> Q24*/ - L_tmp1 = L_sub(L_tmp1, L_tmp); /* Q24 - (Q11 x (1 in Q12) ) = Q24 */ - IF(L_tmp1 > 0 ) + L_tmp = L_mult( max_WB, 4096 ); + L_tmp1 = L_mult( 8192, max_SWB ); /* 2.0 in Q12 x Q11 -> Q24*/ + L_tmp1 = L_sub( L_tmp1, L_tmp ); /* Q24 - (Q11 x (1 in Q12) ) = Q24 */ + IF( L_tmp1 > 0 ) { - st->count_SWB = add(st->count_SWB, 1); + st->count_SWB = add( st->count_SWB, 1 ); } } ELSE { /*if( 3 * mean_SWB < mean_WB )*/ - L_tmp = L_mult(mean_WB,4096); - L_tmp1 = L_mult(12288,mean_SWB); /* 3.0 in Q12 x Q11 -> Q24*/ - L_tmp1 = L_sub(L_tmp1,L_tmp); /* Q24 - (Q11 x (1 in Q12) ) = Q24 */ - IF(L_tmp1 < 0 ) + L_tmp = L_mult( mean_WB, 4096 ); + L_tmp1 = L_mult( 12288, mean_SWB ); /* 3.0 in Q12 x Q11 -> Q24*/ + L_tmp1 = L_sub( L_tmp1, L_tmp ); /* Q24 - (Q11 x (1 in Q12) ) = Q24 */ + IF( L_tmp1 < 0 ) { - st->count_SWB = sub(st->count_SWB,1); + st->count_SWB = sub( st->count_SWB, 1 ); } } /*if( max_FB > BWD_LT_THRESH_FX * st->lt_mean_SWB_fx && 0.83f * max_SWB > BWD_LT_THRESH_FX * st->lt_mean_WB_fx && max_WB > BWD_LT_THRESH_FX * st->lt_mean_NB_fx )*/ - L_tmp = L_mult(max_FB, 4096); /* Q11 x (1 in Q12) = Q24 */ - L_tmp1 = L_mult(BWD_LT_THRESH_FX, st->lt_mean_SWB_fx); /* Q15 x Q11 -> Q27 */ - L_tmp1 = L_shl(L_tmp1, 24-27); /* Q27 -> Q24) */ - L_tmp1 = L_sub( L_tmp, L_tmp1); /* Q24 */ + L_tmp = L_mult( max_FB, 4096 ); /* Q11 x (1 in Q12) = Q24 */ + L_tmp1 = L_mult( BWD_LT_THRESH_FX, st->lt_mean_SWB_fx ); /* Q15 x Q11 -> Q27 */ + L_tmp1 = L_shl( L_tmp1, 24 - 27 ); /* Q27 -> Q24) */ + L_tmp1 = L_sub( L_tmp, L_tmp1 ); /* Q24 */ - L_tmp = L_mult(max_SWB, 3400 ); /* (0.83 in Q12) x Q11) = Q24 */ - L_tmp2 = L_mult(BWD_LT_THRESH_FX,st->lt_mean_WB_fx); /* Q15 x Q11 -> Q27 */ - L_tmp2 = L_shl(L_tmp2, 24-27); /* Q27 -> Q24) */ - L_tmp2 = L_sub(L_tmp, L_tmp2 ); /* Q24 */ + L_tmp = L_mult( max_SWB, 3400 ); /* (0.83 in Q12) x Q11) = Q24 */ + L_tmp2 = L_mult( BWD_LT_THRESH_FX, st->lt_mean_WB_fx ); /* Q15 x Q11 -> Q27 */ + L_tmp2 = L_shl( L_tmp2, 24 - 27 ); /* Q27 -> Q24) */ + L_tmp2 = L_sub( L_tmp, L_tmp2 ); /* Q24 */ - L_tmp = L_mult(max_WB,4096); /* Q11 x (1 in Q12) = Q24*/ + L_tmp = L_mult( max_WB, 4096 ); /* Q11 x (1 in Q12) = Q24*/ - L_tmp3 = L_mult(BWD_LT_THRESH_FX,st->lt_mean_NB_fx); /* Q15 x Q11 -> Q27 */ - L_tmp3 = L_shl(L_tmp3, 24-27); /* Q27 -> Q24) */ - L_tmp3 = L_sub(L_tmp, L_tmp3 ); + L_tmp3 = L_mult( BWD_LT_THRESH_FX, st->lt_mean_NB_fx ); /* Q15 x Q11 -> Q27 */ + L_tmp3 = L_shl( L_tmp3, 24 - 27 ); /* Q27 -> Q24) */ + L_tmp3 = L_sub( L_tmp, L_tmp3 ); test(); test(); - IF(L_tmp1 > 0 && L_tmp2 > 0 && L_tmp3 > 0 ) + IF( L_tmp1 > 0 && L_tmp2 > 0 && L_tmp3 > 0 ) { /*if( 3 * max_FB > max_SWB )*/ - L_tmp = L_mult( max_SWB,4096 ); /* Q11 x (1 in Q12) = Q24*/ - L_tmp1 = L_mult(12288,max_FB); /* 3.0 in Q12 x Q11 -> Q24*/ - L_tmp1 = L_sub(L_tmp1, L_tmp); /* Q24 */ - IF(L_tmp1 > 0 ) + L_tmp = L_mult( max_SWB, 4096 ); /* Q11 x (1 in Q12) = Q24*/ + L_tmp1 = L_mult( 12288, max_FB ); /* 3.0 in Q12 x Q11 -> Q24*/ + L_tmp1 = L_sub( L_tmp1, L_tmp ); /* Q24 */ + IF( L_tmp1 > 0 ) { - st->count_FB = add(st->count_FB,1); + st->count_FB = add( st->count_FB, 1 ); } } ELSE { /* if( 4.1f * mean_FB < mean_SWB )*/ - L_tmp = L_mult(mean_SWB,4096); /* Q11 x (1 in Q12) = Q24 */ - L_tmp1 = L_mult(16794,mean_FB); /* 4.1 in Q12 x Q11 -> Q24*/ - L_tmp1 = L_sub(L_tmp1,L_tmp); /* Q24 */ - IF(L_tmp1 < 0 ) + L_tmp = L_mult( mean_SWB, 4096 ); /* Q11 x (1 in Q12) = Q24 */ + L_tmp1 = L_mult( 16794, mean_FB ); /* 4.1 in Q12 x Q11 -> Q24*/ + L_tmp1 = L_sub( L_tmp1, L_tmp ); /* Q24 */ + IF( L_tmp1 < 0 ) { - st->count_FB = sub(st->count_FB,1); + st->count_FB = sub( st->count_FB, 1 ); } } - } - ELSE /* DCT based detection */ + ELSE /* DCT based detection */ { /*if( max_WB > BWD_LT_THRESH * st->lt_mean_NB_fx )*/ - IF( L_msu( L_deposit_h(max_WB),BWD_LT_THRESH_FX,st->lt_mean_NB_fx) > 0 ) + IF( L_msu( L_deposit_h( max_WB ), BWD_LT_THRESH_FX, st->lt_mean_NB_fx ) > 0 ) { /*if( 2 * max_WB > max_NB )*/ - L_tmp = L_mult(8192,max_WB); /* 2.0 in Q12 x Q11 -> Q24*/ - if( L_msu(L_tmp,max_NB,4096) > 0 ) + L_tmp = L_mult( 8192, max_WB ); /* 2.0 in Q12 x Q11 -> Q24*/ + if ( L_msu( L_tmp, max_NB, 4096 ) > 0 ) { - st->count_WB = add(st->count_WB,1); + st->count_WB = add( st->count_WB, 1 ); } } ELSE { /*if( 2.6f * mean_WB < mean_NB )*/ - L_tmp = L_mult(10650,mean_WB); /* 2.6 in Q12 x Q11 -> Q24*/ - L_tmp = L_msu(L_tmp,mean_NB,4096); + L_tmp = L_mult( 10650, mean_WB ); /* 2.6 in Q12 x Q11 -> Q24*/ + L_tmp = L_msu( L_tmp, mean_NB, 4096 ); test(); test(); - if( L_tmp < 0 && !(EQ_16(mean_WB,-1)&&EQ_16(mean_NB,-1))) + if ( L_tmp < 0 && !( EQ_16( mean_WB, -1 ) && EQ_16( mean_NB, -1 ) ) ) { - st->count_WB = sub(st->count_WB, 1); + st->count_WB = sub( st->count_WB, 1 ); } } test(); /*if( max_SWB > BWD_LT_THRESH * st->lt_mean_WB_fx && max_WB > BWD_LT_THRESH * st->lt_mean_NB_fx )*/ test(); - IF( L_msu( L_deposit_h(max_SWB),BWD_LT_THRESH_FX,st->lt_mean_WB_fx) > 0 && L_msu( L_deposit_h(max_WB),BWD_LT_THRESH_FX,st->lt_mean_NB_fx) > 0 ) + IF( L_msu( L_deposit_h( max_SWB ), BWD_LT_THRESH_FX, st->lt_mean_WB_fx ) > 0 && L_msu( L_deposit_h( max_WB ), BWD_LT_THRESH_FX, st->lt_mean_NB_fx ) > 0 ) { /*if( 2 * max_SWB > max_WB )*/ - L_tmp = L_mult(8192,max_SWB); /* 2.0 in Q12 x Q11 -> Q24*/ - if( L_msu(L_tmp,max_WB,4096) > 0 ) + L_tmp = L_mult( 8192, max_SWB ); /* 2.0 in Q12 x Q11 -> Q24*/ + if ( L_msu( L_tmp, max_WB, 4096 ) > 0 ) { - st->count_SWB = add(st->count_SWB,1); + st->count_SWB = add( st->count_SWB, 1 ); } } ELSE { /*if( 3 * mean_SWB < mean_WB )*/ - L_tmp = L_mult(12288,mean_SWB); /* 3.0 in Q12 x Q11 -> Q24*/ - L_tmp = L_msu(L_tmp,mean_WB,4096); + L_tmp = L_mult( 12288, mean_SWB ); /* 3.0 in Q12 x Q11 -> Q24*/ + L_tmp = L_msu( L_tmp, mean_WB, 4096 ); test(); test(); - if( L_tmp < 0 && !(EQ_16(mean_SWB,-1)&&EQ_16(mean_WB,-1))) + if ( L_tmp < 0 && !( EQ_16( mean_SWB, -1 ) && EQ_16( mean_WB, -1 ) ) ) { - st->count_SWB = sub(st->count_SWB,1); + st->count_SWB = sub( st->count_SWB, 1 ); } } test(); test(); /*if( max_FB > BWD_LT_THRESH * st->lt_mean_SWB_fx && max_SWB > BWD_LT_THRESH * st->lt_mean_WB_fx && max_WB > BWD_LT_THRESH * st->lt_mean_NB_fx )*/ - IF( L_msu( L_deposit_h(max_FB),BWD_LT_THRESH_FX,st->lt_mean_SWB_fx) > 0 && L_msu( L_deposit_h(max_SWB),BWD_LT_THRESH_FX,st->lt_mean_WB_fx) > 0 && L_msu( L_deposit_h(max_WB),BWD_LT_THRESH_FX,st->lt_mean_NB_fx) > 0 ) + IF( L_msu( L_deposit_h( max_FB ), BWD_LT_THRESH_FX, st->lt_mean_SWB_fx ) > 0 && L_msu( L_deposit_h( max_SWB ), BWD_LT_THRESH_FX, st->lt_mean_WB_fx ) > 0 && L_msu( L_deposit_h( max_WB ), BWD_LT_THRESH_FX, st->lt_mean_NB_fx ) > 0 ) { /*if( 2 * max_FB > max_SWB )*/ - L_tmp = L_mult(8192,max_FB); /* 2.0 in Q12 x Q11 -> Q24*/ - if( L_msu(L_tmp,max_SWB,4096) > 0 ) + L_tmp = L_mult( 8192, max_FB ); /* 2.0 in Q12 x Q11 -> Q24*/ + if ( L_msu( L_tmp, max_SWB, 4096 ) > 0 ) { - st->count_FB = add(st->count_FB,1); + st->count_FB = add( st->count_FB, 1 ); } } ELSE { /*if( 3 * mean_FB < mean_SWB )*/ - L_tmp = L_mult(12288,mean_FB); /* 3.0 in Q12 x Q11 -> Q24*/ + L_tmp = L_mult( 12288, mean_FB ); /* 3.0 in Q12 x Q11 -> Q24*/ test(); test(); - if( L_msu(L_tmp,mean_SWB,4096) < 0 && !(EQ_16(mean_FB,-1)&&EQ_16(mean_SWB,-1))) + if ( L_msu( L_tmp, mean_SWB, 4096 ) < 0 && !( EQ_16( mean_FB, -1 ) && EQ_16( mean_SWB, -1 ) ) ) { - st->count_FB = sub(st->count_FB,1); + st->count_FB = sub( st->count_FB, 1 ); } } } - st->count_WB = s_min(st->count_WB,BWD_COUNT_MAX); + st->count_WB = s_min( st->count_WB, BWD_COUNT_MAX ); move16(); - st->count_SWB = s_min(st->count_SWB,BWD_COUNT_MAX); + st->count_SWB = s_min( st->count_SWB, BWD_COUNT_MAX ); move16(); - st->count_FB = s_min(st->count_FB,BWD_COUNT_MAX); + st->count_FB = s_min( st->count_FB, BWD_COUNT_MAX ); move16(); - st->count_WB = s_max(st->count_WB,0); + st->count_WB = s_max( st->count_WB, 0 ); move16(); - st->count_SWB = s_max(st->count_SWB,0); + st->count_SWB = s_max( st->count_SWB, 0 ); move16(); - st->count_FB = s_max(st->count_FB,0); + st->count_FB = s_max( st->count_FB, 0 ); move16(); /*---------------------------------------------------------------------* @@ -754,23 +756,23 @@ void bw_detect_fx( *---------------------------------------------------------------------*/ /* switching to a higher BW */ - IF( EQ_16(st->last_input_bwidth,NB)) + IF( EQ_16( st->last_input_bwidth, NB ) ) { - IF( GT_16(st->count_WB, bwd_count_wider_bw)) + IF( GT_16( st->count_WB, bwd_count_wider_bw ) ) { st->input_bwidth = WB; move16(); st->count_WB = BWD_COUNT_MAX; move16(); - IF( GT_16(st->count_SWB, bwd_count_wider_bw)) + IF( GT_16( st->count_SWB, bwd_count_wider_bw ) ) { st->input_bwidth = SWB; move16(); st->count_SWB = BWD_COUNT_MAX; move16(); - IF( GT_16(st->count_FB, bwd_count_wider_bw)) + IF( GT_16( st->count_FB, bwd_count_wider_bw ) ) { st->input_bwidth = FB; move16(); @@ -782,16 +784,16 @@ void bw_detect_fx( } test(); - IF( EQ_16(st->last_input_bwidth,WB)&>_32(st->input_Fs,16000)) + IF( EQ_16( st->last_input_bwidth, WB ) && GT_32( st->input_Fs, 16000 ) ) { - IF( GT_16(st->count_SWB, bwd_count_wider_bw)) + IF( GT_16( st->count_SWB, bwd_count_wider_bw ) ) { st->input_bwidth = SWB; move16(); st->count_SWB = BWD_COUNT_MAX; move16(); - IF( GT_16(st->count_FB, bwd_count_wider_bw)) + IF( GT_16( st->count_FB, bwd_count_wider_bw ) ) { st->input_bwidth = FB; move16(); @@ -802,9 +804,9 @@ void bw_detect_fx( } test(); - IF( EQ_16(st->last_input_bwidth,SWB)&>_32(st->input_Fs,32000)) + IF( EQ_16( st->last_input_bwidth, SWB ) && GT_32( st->input_Fs, 32000 ) ) { - IF( GT_16(st->count_FB, bwd_count_wider_bw)) + IF( GT_16( st->count_FB, bwd_count_wider_bw ) ) { st->input_bwidth = FB; move16(); @@ -814,16 +816,16 @@ void bw_detect_fx( } /* switching to a lower BW */ - IF( EQ_16(st->last_input_bwidth,FB)) + IF( EQ_16( st->last_input_bwidth, FB ) ) { - IF( LT_16(st->count_FB,10)) + IF( LT_16( st->count_FB, 10 ) ) { st->input_bwidth = SWB; move16(); st->count_FB = 0; move16(); } - IF( LT_16(st->count_SWB,10)) + IF( LT_16( st->count_SWB, 10 ) ) { st->input_bwidth = WB; move16(); @@ -832,7 +834,7 @@ void bw_detect_fx( st->count_FB = 0; move16(); } - IF( LT_16(st->count_WB,10)) + IF( LT_16( st->count_WB, 10 ) ) { st->input_bwidth = NB; move16(); @@ -845,9 +847,9 @@ void bw_detect_fx( } } - IF( EQ_16(st->last_input_bwidth,SWB)) + IF( EQ_16( st->last_input_bwidth, SWB ) ) { - IF( LT_16(st->count_SWB,10)) + IF( LT_16( st->count_SWB, 10 ) ) { st->input_bwidth = WB; move16(); @@ -856,7 +858,7 @@ void bw_detect_fx( st->count_FB = 0; move16(); } - IF( LT_16(st->count_WB,10)) + IF( LT_16( st->count_WB, 10 ) ) { st->input_bwidth = NB; move16(); @@ -867,12 +869,11 @@ void bw_detect_fx( st->count_FB = 0; move16(); } - } - IF( EQ_16(st->last_input_bwidth,WB)) + IF( EQ_16( st->last_input_bwidth, WB ) ) { - IF( LT_16(st->count_WB,10)) + IF( LT_16( st->count_WB, 10 ) ) { st->input_bwidth = NB; move16(); @@ -889,16 +890,16 @@ void bw_detect_fx( /* verify that maximum encoded bandwidth (specified on the command line) is not exceeded */ - IF( GT_16(st->input_bwidth,st->max_bwidth)) + IF( GT_16( st->input_bwidth, st->max_bwidth ) ) { st->input_bwidth = st->max_bwidth; move16(); } - IF (EQ_16(st->element_mode, EVS_MONO) ) + IF( EQ_16( st->element_mode, EVS_MONO ) ) { - set_bw_fx(-1, -1, st, st->codec_mode); + set_bw_fx( -1, -1, st, st->codec_mode ); } - + return; } @@ -911,7 +912,7 @@ void bw_detect_fx( void set_bw_fx( const Word16 element_mode, /* i : element mode */ const Word32 element_brate, /* i : element bitrate */ - Encoder_State* st, /* i/o: Encoder State */ + Encoder_State *st, /* i/o: Encoder State */ const Word16 codec_mode /* i : codec mode */ ) { @@ -921,13 +922,13 @@ void set_bw_fx( move16(); /* Set and limit the encoded bandwidth */ - IF(EQ_16(st->codec_mode, MODE1)) + IF( EQ_16( st->codec_mode, MODE1 ) ) { st->bwidth = st->input_bwidth; move16(); - total_brate_fx = L_add(st->total_brate, 0); + total_brate_fx = L_add( st->total_brate, 0 ); /* change the encoded bandwidth, if not supported at particular bitrate */ test(); @@ -935,10 +936,10 @@ void set_bw_fx( test(); test(); test(); - IF (GT_16(element_mode, IVAS_SCE)) + IF( GT_16( element_mode, IVAS_SCE ) ) { - //PMT("this IVAS_SCE section has not been verified ") - IF (LT_32(element_brate, MIN_BRATE_SWB_STEREO)) + // PMT("this IVAS_SCE section has not been verified ") + IF( LT_32( element_brate, MIN_BRATE_SWB_STEREO ) ) { st->bwidth = WB; move16(); @@ -946,17 +947,17 @@ void set_bw_fx( ELSE { test(); - IF (st->idchan == 0 || EQ_16(element_mode, IVAS_CPE_MDCT)) + IF( st->idchan == 0 || EQ_16( element_mode, IVAS_CPE_MDCT ) ) { - IF (GE_32(element_brate, MIN_BRATE_FB_STEREO)) + IF( GE_32( element_brate, MIN_BRATE_FB_STEREO ) ) { - st->bwidth = s_min(st->bwidth, FB); + st->bwidth = s_min( st->bwidth, FB ); } ELSE { - st->bwidth = s_min(st->bwidth, SWB); + st->bwidth = s_min( st->bwidth, SWB ); } - st->bwidth = s_max(st->bwidth, WB); + st->bwidth = s_max( st->bwidth, WB ); } ELSE { @@ -965,68 +966,69 @@ void set_bw_fx( } } } - ELSE IF (EQ_16(element_mode, IVAS_SCE)) + ELSE IF( EQ_16( element_mode, IVAS_SCE ) ) { test(); - IF ( LT_32(element_brate, MIN_BRATE_SWB_SCE) || LT_16(st->bwidth, WB) ) + IF( LT_32( element_brate, MIN_BRATE_SWB_SCE ) || LT_16( st->bwidth, WB ) ) { st->bwidth = WB; move16(); } - ELSE IF (GT_16(st->bwidth, SWB) && ((LT_32(element_brate, MIN_BRATE_FB_STEREO) && !st->is_ism_format) || (LT_32(element_brate, MIN_BRATE_FB_ISM) && st->is_ism_format))) + ELSE IF( GT_16( st->bwidth, SWB ) && ( ( LT_32( element_brate, MIN_BRATE_FB_STEREO ) && !st->is_ism_format ) || ( LT_32( element_brate, MIN_BRATE_FB_ISM ) && st->is_ism_format ) ) ) { st->bwidth = SWB; move16(); } - ELSE IF (GT_32(element_brate, BWD_MAX_BRATE_WIDER_BW_ISM)) + ELSE IF( GT_32( element_brate, BWD_MAX_BRATE_WIDER_BW_ISM ) ) { - st->bwidth = st->max_bwidth; move16(); + st->bwidth = st->max_bwidth; + move16(); } } /* element_mode == EVS_MONO */ - ELSE IF(LE_32(total_brate_fx, ACELP_9k60) && GT_16(st->bwidth, WB) ) + ELSE IF( LE_32( total_brate_fx, ACELP_9k60 ) && GT_16( st->bwidth, WB ) ) { st->bwidth = WB; move16(); } - ELSE IF(GE_32(st->total_brate, ACELP_13k20) && LE_32(st->total_brate, ACELP_16k40) && GT_16(st->bwidth, SWB)) + ELSE IF( GE_32( st->total_brate, ACELP_13k20 ) && LE_32( st->total_brate, ACELP_16k40 ) && GT_16( st->bwidth, SWB ) ) { st->bwidth = SWB; move16(); } - ELSE IF(GE_32(st->total_brate, ACELP_32k) && LT_16(st->bwidth, WB)) + ELSE IF( GE_32( st->total_brate, ACELP_32k ) && LT_16( st->bwidth, WB ) ) { st->bwidth = WB; move16(); } } - ELSE IF (EQ_16(codec_mode , MODE2) ) + ELSE IF( EQ_16( codec_mode, MODE2 ) ) { Word16 n, bits_frame_nominal; UWord16 lsb; Word16 tmpbandwidthMin; - Mpy_32_16_ss(st->total_brate, 5243, &L_tmp, &lsb); /* 5243 is 1/50 in Q18. (0+18-15=3) */ - bits_frame_nominal = extract_l(L_shr(L_tmp, 3)); /* Q0 */ + Mpy_32_16_ss( st->total_brate, 5243, &L_tmp, &lsb ); /* 5243 is 1/50 in Q18. (0+18-15=3) */ + bits_frame_nominal = extract_l( L_shr( L_tmp, 3 ) ); /* Q0 */ - FOR(n = 0; n < FRAME_SIZE_NB; n++) + FOR( n = 0; n < FRAME_SIZE_NB; n++ ) { - IF(EQ_16(FrameSizeConfig[n].frame_bits,bits_frame_nominal)) + IF( EQ_16( FrameSizeConfig[n].frame_bits, bits_frame_nominal ) ) { BREAK; } } - if (n == FRAME_SIZE_NB) + if ( n == FRAME_SIZE_NB ) { - assert(!"Bitrate not supported: not part of EVS"); + assert( !"Bitrate not supported: not part of EVS" ); } tmpbandwidthMin = FrameSizeConfig[n].bandwidth_min; - if (EQ_16(st->rf_mode,1)) + if ( EQ_16( st->rf_mode, 1 ) ) { tmpbandwidthMin = WB; } - st->bwidth = s_max(s_min(st->input_bwidth, FrameSizeConfig[n].bandwidth_max), tmpbandwidthMin); + st->bwidth = s_max( s_min( st->input_bwidth, FrameSizeConfig[n].bandwidth_max ), tmpbandwidthMin ); } } #ifdef IVAS_CODE_BWD @@ -1041,30 +1043,30 @@ void set_bw_stereo( CPE_ENC_HANDLE hCPE /* i/o: CPE encoder structures */ ) { - Encoder_State** sts = hCPE->hCoreCoder; + Encoder_State **sts = hCPE->hCoreCoder; - if (hCPE->element_brate > BWD_MAX_BRATE_WIDER_BW_MDCT) + if ( hCPE->element_brate > BWD_MAX_BRATE_WIDER_BW_MDCT ) { sts[0]->bwidth = sts[0]->max_bwidth; sts[1]->bwidth = sts[1]->max_bwidth; } - else if (hCPE->element_mode == IVAS_CPE_MDCT) + else if ( hCPE->element_mode == IVAS_CPE_MDCT ) { /* ensure that both CPE channels have the same audio band-width */ - if (sts[0]->input_bwidth == sts[1]->input_bwidth) + if ( sts[0]->input_bwidth == sts[1]->input_bwidth ) { sts[0]->bwidth = sts[0]->input_bwidth; sts[1]->bwidth = sts[0]->input_bwidth; } else { - sts[0]->bwidth = max(sts[0]->input_bwidth, sts[1]->input_bwidth); - sts[1]->bwidth = max(sts[0]->input_bwidth, sts[1]->input_bwidth); + sts[0]->bwidth = max( sts[0]->input_bwidth, sts[1]->input_bwidth ); + sts[1]->bwidth = max( sts[0]->input_bwidth, sts[1]->input_bwidth ); } } - sts[0]->bwidth = max(sts[0]->bwidth, WB); - sts[1]->bwidth = max(sts[1]->bwidth, WB); + sts[0]->bwidth = max( sts[0]->bwidth, WB ); + sts[1]->bwidth = max( sts[1]->bwidth, WB ); return; } @@ -1075,47 +1077,47 @@ void set_bw_stereo( * Set encoded bandwidth for MCT *-------------------------------------------------------------------*/ - /*! r: flag indicating whether the coded BW has changed */ +/*! r: flag indicating whether the coded BW has changed */ int16_t set_bw_mct( CPE_ENC_HANDLE hCPE[MCT_MAX_BLOCKS], /* i/o: CPE encoder structures */ const int16_t nCPE /* i : number of CPEs */ ) { - Encoder_State* sts[MCT_MAX_CHANNELS]; + Encoder_State *sts[MCT_MAX_CHANNELS]; int16_t ch, cpe_id; int16_t mct_bwidth, last_mct_bwidth, bw_changed; mct_bwidth = WB; /* minimum coded audio band-width */ last_mct_bwidth = hCPE[0]->hCoreCoder[0]->last_bwidth; /* supposes that LFE is not in the first channel */ - for (cpe_id = 0; cpe_id < nCPE; cpe_id++) + for ( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) { - for (ch = 0; ch < CPE_CHANNELS; ch++) + for ( ch = 0; ch < CPE_CHANNELS; ch++ ) { sts[ch] = hCPE[cpe_id]->hCoreCoder[ch]; - if (st->mct_chan_mode == MCT_CHAN_MODE_IGNORE) + if ( st->mct_chan_mode == MCT_CHAN_MODE_IGNORE ) { continue; } - mct_bwidth = max(mct_bwidth, sts[ch]->input_bwidth); + mct_bwidth = max( mct_bwidth, sts[ch]->input_bwidth ); } } - for (cpe_id = 0; cpe_id < nCPE; cpe_id++) + for ( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) { - if (hCPE[cpe_id]->element_brate > BWD_MAX_BRATE_WIDER_BW_MDCT) + if ( hCPE[cpe_id]->element_brate > BWD_MAX_BRATE_WIDER_BW_MDCT ) { - mct_bwidth = max(mct_bwidth, hCPE[cpe_id]->hCoreCoder[0]->max_bwidth); + mct_bwidth = max( mct_bwidth, hCPE[cpe_id]->hCoreCoder[0]->max_bwidth ); } } bw_changed = 0; - if (mct_bwidth != last_mct_bwidth) + if ( mct_bwidth != last_mct_bwidth ) { bw_changed = 1; - for (cpe_id = 0; cpe_id < nCPE; cpe_id++) + for ( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) { - for (ch = 0; ch < CPE_CHANNELS; ch++) + for ( ch = 0; ch < CPE_CHANNELS; ch++ ) { sts[ch] = hCPE[cpe_id]->hCoreCoder[ch]; sts[ch]->bwidth = mct_bwidth; @@ -1126,4 +1128,4 @@ int16_t set_bw_mct( return bw_changed; } -#endif \ No newline at end of file +#endif diff --git a/lib_enc/cng_enc_fx.c b/lib_enc/cng_enc_fx.c index 23a31264b..401eb6412 100644 --- a/lib_enc/cng_enc_fx.c +++ b/lib_enc/cng_enc_fx.c @@ -2,59 +2,58 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_enc.h" /* Encoder static table prototypes */ -#include "rom_com.h" /* Static table prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_enc.h" /* Encoder static table prototypes */ +#include "rom_com.h" /* Static table prototypes */ //#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ //#include "basop_mpy.h" #include /*---------------------------------------------------------------------* -* Local constants -*---------------------------------------------------------------------*/ + * Local constants + *---------------------------------------------------------------------*/ -#define MAX_DELTA 1 -#define MIN_CNT 50 /* Minimum frame number before SID interval adaptation */ -#define INT_H 50 -#define INT_L 8 +#define MAX_DELTA 1 +#define MIN_CNT 50 /* Minimum frame number before SID interval adaptation */ +#define INT_H 50 +#define INT_L 8 /*---------------------------------------------------------------------* * Local function prototypes *---------------------------------------------------------------------*/ -static void shb_CNG_encod_fx(Encoder_State *st_fx, const Word16 update_fx ); -static Word16 shb_DTX_fx(Encoder_State *st_fx, const Word16 *shb_speech_fx, const Word16 *syn_12k8_16k ); +static void shb_CNG_encod_fx( Encoder_State *st_fx, const Word16 update_fx ); +static Word16 shb_DTX_fx( Encoder_State *st_fx, const Word16 *shb_speech_fx, const Word16 *syn_12k8_16k ); /*---------------------------------------------------------------------* -* CNG_enc() -* -* Confort noise generation for the coder -*---------------------------------------------------------------------*/ + * CNG_enc() + * + * Confort noise generation for the coder + *---------------------------------------------------------------------*/ void CNG_enc_fx( - Encoder_State *st_fx,/* i/o: State structure */ - Word16 Aq[], /* o : LP coefficients Q12 */ - const Word16 *speech, /* i : pointer to current frame input speech buffer Q_new */ - Word32 L_enr, /* i : residual energy from Levinson-Durbin Q6 */ - const Word16* lsp_mid, /* i : mid frame LSPs Q15 */ - Word16 *lsp_new, /* i/o: current frame ISPs Q15 */ - Word16 *lsf_new, /* i/o: current frame ISFs Qlog2(2.56) */ - Word16 *allow_cn_step, /* o : allow CN step Q0 */ - Word16 Q_new, /* i : Q value of speech */ + Encoder_State *st_fx, /* i/o: State structure */ + Word16 Aq[], /* o : LP coefficients Q12 */ + const Word16 *speech, /* i : pointer to current frame input speech buffer Q_new */ + Word32 L_enr, /* i : residual energy from Levinson-Durbin Q6 */ + const Word16 *lsp_mid, /* i : mid frame LSPs Q15 */ + Word16 *lsp_new, /* i/o: current frame ISPs Q15 */ + Word16 *lsf_new, /* i/o: current frame ISFs Qlog2(2.56) */ + Word16 *allow_cn_step, /* o : allow CN step Q0 */ + Word16 Q_new, /* i : Q value of speech */ Word32 *q_env, - Word16 *sid_bw -) + Word16 *sid_bw ) { Word16 enr_index; Word16 i, j, ptr; Word16 m1; Word16 res[L_FRAME16k]; - Word16 step_inv=0; + Word16 step_inv = 0; Word16 hi, lo; - Word16 maxl=0; - Word16 num_bits=0; - Word16 step=0; + Word16 maxl = 0; + Word16 num_bits = 0; + Word16 step = 0; Word16 *pt_res; const Word16 *pt_sp; Word16 enr; @@ -65,7 +64,7 @@ void CNG_enc_fx( Word32 L_tmp1; Word16 exp; Word16 m = 0; - Word16 tmp[HO_HIST_SIZE*M]; + Word16 tmp[HO_HIST_SIZE * M]; Word16 ll, s_ptr; Word16 tmpv, maxv, scale, att = 1; Word16 lsf_tmp[M]; @@ -77,24 +76,24 @@ void CNG_enc_fx( Word16 dev; Word16 max_dev; Word16 dist; - Word16 max_idx1[2]= {0,0}; + Word16 max_idx1[2] = { 0, 0 }; Word16 fft_io[L_FRAME16k]; - Word16 *ptR,*ptI; - Word32 enr1=0; + Word16 *ptR, *ptI; + Word32 enr1 = 0; Word32 env[NUM_ENV_CNG]; Word32 min1; Word16 min1_idx; Word32 d; Word16 res1[L_FRAME16k]; - Word32 tmp_env[HO_HIST_SIZE*NUM_ENV_CNG]; + Word32 tmp_env[HO_HIST_SIZE * NUM_ENV_CNG]; Word16 fra; Word16 temp_lo_fx, temp_hi_fx; Word16 exp_pow; - Word16 force_cn_step=0; + Word16 force_cn_step = 0; Word16 tmp_loop; Word16 st_lp_sp_enr; - DTX_ENC_HANDLE hDtxEnc = st_fx->hDtxEnc; - TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; + DTX_ENC_HANDLE hDtxEnc = st_fx->hDtxEnc; + TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; BSTR_ENC_HANDLE hBstr = st_fx->hBstr; st_lp_sp_enr = hTdCngEnc->lp_sp_enr_fx; Word16 lp_ener_thr_scale; @@ -103,60 +102,60 @@ void CNG_enc_fx( #endif /* Temp variables for floating point functions */ - lp_ener_thr_scale = 8; /* 4.0f*/ /*IVAS_CODE Q2 */ + lp_ener_thr_scale = 8; /* 4.0f*/ /*IVAS_CODE Q2 */ move16(); - if (NE_16(st_fx->element_mode, EVS_MONO)) + if ( NE_16( st_fx->element_mode, EVS_MONO ) ) { lp_ener_thr_scale = 7; /* 3.5f;*/ move16(); } - /*sp_enr = (float) log10( sum2_f( speech, L_frame )/L_frame + 0.1f )/ (float)log10(2.0f);*//*9.1 */ + /*sp_enr = (float) log10( sum2_f( speech, L_frame )/L_frame + 0.1f )/ (float)log10(2.0f);*/ /*9.1 */ pt_sp = speech; - L_ener = L_deposit_l(1); + L_ener = L_deposit_l( 1 ); /* L_ener = L_add(L_shr(sum2_f_fx( speech, L_frame ), 8) , L_ener);*/ - IF( EQ_16(st_fx->L_frame, L_FRAME)) + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { - FOR (j=0; j<128; j++) + FOR( j = 0; j < 128; j++ ) { - L_tmp = L_mult0(*pt_sp, *pt_sp); + L_tmp = L_mult0( *pt_sp, *pt_sp ); pt_sp++; - L_tmp = L_mac0(L_tmp, *pt_sp, *pt_sp); + L_tmp = L_mac0( L_tmp, *pt_sp, *pt_sp ); pt_sp++; - L_ener = L_add(L_ener, L_shr(L_tmp, 7)); /* 2*Q_new + 1, divide by L_frame done here */ + L_ener = L_add( L_ener, L_shr( L_tmp, 7 ) ); /* 2*Q_new + 1, divide by L_frame done here */ } } ELSE /* L_FRAME16k */ { - FOR (i=0; i<2; i++) + FOR( i = 0; i < 2; i++ ) { - FOR (j=0; j<80; j++) + FOR( j = 0; j < 80; j++ ) { - L_tmp = L_mult0(*pt_sp, *pt_sp); + L_tmp = L_mult0( *pt_sp, *pt_sp ); pt_sp++; - L_tmp = L_mac0(L_tmp, *pt_sp, *pt_sp); + L_tmp = L_mac0( L_tmp, *pt_sp, *pt_sp ); pt_sp++; - L_ener = L_add(L_ener, L_shr(Mult_32_16(L_tmp,26214 /* 256/320, Q15 */), 7)); /* 2*Q_new + 1, divide by L_frame done here */ + L_ener = L_add( L_ener, L_shr( Mult_32_16( L_tmp, 26214 /* 256/320, Q15 */ ), 7 ) ); /* 2*Q_new + 1, divide by L_frame done here */ } } } - hi = norm_l(L_ener); - lo = Log2_norm_lc(L_shl(L_ener, hi)); - hi = sub(29, hi); /* log2 exp in Q2*Q_new */ - hi = sub(hi, shl(Q_new, 1)); /* Q0 */ - L_tmp = L_Comp(hi, lo); /* Q16 */ - sp_enr = round_fx(L_shl(L_tmp, 8)); /* Q8 (16+8-16) */ + hi = norm_l( L_ener ); + lo = Log2_norm_lc( L_shl( L_ener, hi ) ); + hi = sub( 29, hi ); /* log2 exp in Q2*Q_new */ + hi = sub( hi, shl( Q_new, 1 ) ); /* Q0 */ + L_tmp = L_Comp( hi, lo ); /* Q16 */ + sp_enr = round_fx( L_shl( L_tmp, 8 ) ); /* Q8 (16+8-16) */ - if (sp_enr < 0) + if ( sp_enr < 0 ) { sp_enr = 0; move16(); } test(); - IF (hDtxEnc->first_CNG == 0 || hTdCngEnc->old_enr_index < 0 ) + IF( hDtxEnc->first_CNG == 0 || hTdCngEnc->old_enr_index < 0 ) { hTdCngEnc->lp_sp_enr_fx = sp_enr; - move16(); /* Q8 */ + move16(); /* Q8 */ } ELSE { @@ -164,8 +163,8 @@ void CNG_enc_fx( test(); test(); test(); - IF( GT_32(st_fx->last_core_brate, SID_2k40) && ( EQ_16( st_fx->last_core, HQ_CORE ) || st_fx->hTdCngEnc->burst_ho_cnt > 0 ) && LT_16(hTdCngEnc->lp_sp_enr_fx, 1536) && - GT_16(sub(sp_enr, hTdCngEnc->lp_sp_enr_fx), 1024) && GT_16(sp_enr, 1536) ) + IF( GT_32( st_fx->last_core_brate, SID_2k40 ) && ( EQ_16( st_fx->last_core, HQ_CORE ) || st_fx->hTdCngEnc->burst_ho_cnt > 0 ) && LT_16( hTdCngEnc->lp_sp_enr_fx, 1536 ) && + GT_16( sub( sp_enr, hTdCngEnc->lp_sp_enr_fx ), 1024 ) && GT_16( sp_enr, 1536 ) ) { hTdCngEnc->lp_sp_enr_fx = sp_enr; move16(); @@ -174,62 +173,62 @@ void CNG_enc_fx( } ELSE { - hTdCngEnc->lp_sp_enr_fx = round_fx(L_mac(L_mult(29491 /* 0.9, Q15 */,hTdCngEnc->lp_sp_enr_fx), 3277 /* 0.1, Q15 */,sp_enr)); /* Q8 (8+15+1-16) */ + hTdCngEnc->lp_sp_enr_fx = round_fx( L_mac( L_mult( 29491 /* 0.9, Q15 */, hTdCngEnc->lp_sp_enr_fx ), 3277 /* 0.1, Q15 */, sp_enr ) ); /* Q8 (8+15+1-16) */ } } /* update the pointer to circular buffer of old LSP vectors */ - hTdCngEnc->cng_hist_ptr = add(hTdCngEnc->cng_hist_ptr,1); - if(EQ_16(hTdCngEnc->cng_hist_ptr, DTX_HIST_SIZE)) + hTdCngEnc->cng_hist_ptr = add( hTdCngEnc->cng_hist_ptr, 1 ); + if ( EQ_16( hTdCngEnc->cng_hist_ptr, DTX_HIST_SIZE ) ) { hTdCngEnc->cng_hist_ptr = 0; move16(); } /* update the circular buffer of old LSP vectors with the new LSP vector */ - Copy( lsp_new, &(hTdCngEnc->cng_lsp_hist_fx[(hTdCngEnc->cng_hist_ptr)*M]), M ); + Copy( lsp_new, &( hTdCngEnc->cng_lsp_hist_fx[( hTdCngEnc->cng_hist_ptr ) * M] ), M ); /*-----------------------------------------------------------------* - * Find CNG spectral envelope - * Find LSP median - *-----------------------------------------------------------------*/ + * Find CNG spectral envelope + * Find LSP median + *-----------------------------------------------------------------*/ test(); test(); - IF( (EQ_32(st_fx->core_brate, SID_2k40) || EQ_32(st_fx->core_brate,SID_1k75)) && GE_16(hDtxEnc->cng_cnt,sub(hDtxEnc->cng_hist_size,1))) + IF( ( EQ_32( st_fx->core_brate, SID_2k40 ) || EQ_32( st_fx->core_brate, SID_1k75 ) ) && GE_16( hDtxEnc->cng_cnt, sub( hDtxEnc->cng_hist_size, 1 ) ) ) { set32_fx( max_val, 0, 2 ); set16_fx( max_idx, 0, 2 ); - FOR( i=0; i< hDtxEnc->cng_hist_size; i++ ) + FOR( i = 0; i < hDtxEnc->cng_hist_size; i++ ) { - IF ( EQ_16(st_fx->L_frame,L_FRAME)) + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { - lsp2lsf_fx( &hTdCngEnc->cng_lsp_hist_fx[i*M], lsf_tmp, M, INT_FS_FX ); + lsp2lsf_fx( &hTdCngEnc->cng_lsp_hist_fx[i * M], lsf_tmp, M, INT_FS_FX ); ftmp_fx = 964; - move16();/*QX2.56 */ - tmpv = sub(16384,add(lsf_tmp[M-1],ftmp_fx)); /*QX2.56 */ - L_tmp = L_mult0(tmpv,tmpv); /*QX6.5536 */ + move16(); /*QX2.56 */ + tmpv = sub( 16384, add( lsf_tmp[M - 1], ftmp_fx ) ); /*QX2.56 */ + L_tmp = L_mult0( tmpv, tmpv ); /*QX6.5536 */ } ELSE { - lsp2lsf_fx( &hTdCngEnc->cng_lsp_hist_fx[i*M], lsf_tmp, M, INT_FS_16k ); + lsp2lsf_fx( &hTdCngEnc->cng_lsp_hist_fx[i * M], lsf_tmp, M, INT_FS_16k ); ftmp_fx = 1205; - move16();/*QX2.56 */ - tmpv = sub(20480,add(lsf_tmp[M-1],ftmp_fx)); /*QX2.56 */ - L_tmp = L_mult0(tmpv,tmpv); /*QX6.5536 */ + move16(); /*QX2.56 */ + tmpv = sub( 20480, add( lsf_tmp[M - 1], ftmp_fx ) ); /*QX2.56 */ + L_tmp = L_mult0( tmpv, tmpv ); /*QX6.5536 */ } - tmpv = sub(lsf_tmp[0],ftmp_fx); /*QX2.56 */ - L_tmp = L_mac0(L_tmp,tmpv,tmpv); /*QX6.5536 */ - FOR ( j=0; jcng_hist_size; j++ ) + FOR( j = 0; j < hDtxEnc->cng_hist_size; j++ ) { - L_tmp = L_add(L_tmp,L_deposit_l(hTdCngEnc->cng_lsp_hist_fx[j*M+i])); /*Q15 */ + L_tmp = L_add( L_tmp, L_deposit_l( hTdCngEnc->cng_lsp_hist_fx[j * M + i] ) ); /*Q15 */ } - L_tmp = L_sub(L_tmp,L_add(L_deposit_l(hTdCngEnc->cng_lsp_hist_fx[max_idx[0]*M+i]),L_deposit_l(hTdCngEnc->cng_lsp_hist_fx[max_idx[1]*M+i]))); /*Q15 */ - tmpv= div_s(1,sub(hDtxEnc->cng_hist_size,2)); /*Q15 */ - L_tmp = Mpy_32_16_1(L_tmp,tmpv); /*Q15 */ - lsp_new[i] = extract_l(L_tmp); /*Q15 */ + L_tmp = L_sub( L_tmp, L_add( L_deposit_l( hTdCngEnc->cng_lsp_hist_fx[max_idx[0] * M + i] ), L_deposit_l( hTdCngEnc->cng_lsp_hist_fx[max_idx[1] * M + i] ) ) ); /*Q15 */ + tmpv = div_s( 1, sub( hDtxEnc->cng_hist_size, 2 ) ); /*Q15 */ + L_tmp = Mpy_32_16_1( L_tmp, tmpv ); /*Q15 */ + lsp_new[i] = extract_l( L_tmp ); /*Q15 */ } max_idx1[0] = max_idx[0]; move16(); @@ -269,9 +268,9 @@ void CNG_enc_fx( } /*-----------------------------------------------------------------* - * Quantize CNG spectral envelope (only in SID frame) - * Quantize the LSF vector - *-----------------------------------------------------------------*/ + * Quantize CNG spectral envelope (only in SID frame) + * Quantize the LSF vector + *-----------------------------------------------------------------*/ *allow_cn_step = 0; move16(); test(); @@ -280,30 +279,30 @@ void CNG_enc_fx( test(); test(); test(); - IF( ((hDtxEnc->cng_cnt == 0) && - GT_16(hTdCngEnc->lp_sp_enr_fx, 1536) && - (LT_16(add(st_lp_sp_enr, 1024 /* 4.0, Q8 */), sp_enr)) && - (hDtxEnc->first_CNG != 0) && - (hTdCngEnc->old_enr_index >= 0) && - (GT_32(st_fx->last_core_brate, SID_2k40))) || - EQ_16(force_cn_step, 1)) + IF( ( ( hDtxEnc->cng_cnt == 0 ) && + GT_16( hTdCngEnc->lp_sp_enr_fx, 1536 ) && + ( LT_16( add( st_lp_sp_enr, 1024 /* 4.0, Q8 */ ), sp_enr ) ) && + ( hDtxEnc->first_CNG != 0 ) && + ( hTdCngEnc->old_enr_index >= 0 ) && + ( GT_32( st_fx->last_core_brate, SID_2k40 ) ) ) || + EQ_16( force_cn_step, 1 ) ) { *allow_cn_step = 1; move16(); } /* Initialize the CNG spectral envelope in case of the very first CNG frame */ - IF(hDtxEnc->first_CNG == 0) + IF( hDtxEnc->first_CNG == 0 ) { - Copy(st_fx->lsp_old_fx, hDtxEnc->lspCNG_fx, M); - + Copy( st_fx->lsp_old_fx, hDtxEnc->lspCNG_fx, M ); + /* Average the CNG spectral envelope in case of the very first CNG frame */ - IF (NE_16(st_fx->element_mode, EVS_MONO)) + IF( NE_16( st_fx->element_mode, EVS_MONO ) ) { - FOR (i = 0; i < M; i++) + FOR( i = 0; i < M; i++ ) { /*lsp_new[i] = 0.5f * (lsp_mid[i] + lsp_new[i]);*/ - lsp_new[i] = mac_r(L_mult(lsp_mid[i], 16384), lsp_new[i], 16384); + lsp_new[i] = mac_r( L_mult( lsp_mid[i], 16384 ), lsp_new[i], 16384 ); move16(); } } @@ -311,25 +310,25 @@ void CNG_enc_fx( test(); - IF( EQ_32(st_fx->core_brate, SID_2k40) || EQ_32(st_fx->core_brate,SID_1k75)) + IF( EQ_32( st_fx->core_brate, SID_2k40 ) || EQ_32( st_fx->core_brate, SID_1k75 ) ) { /* LSF quantization */ - IF ( st_fx->Opt_AMR_WB != 0 ) + IF( st_fx->Opt_AMR_WB != 0 ) { - isf_enc_amr_wb_fx( st_fx, lsf_new, lsp_new, 0); + isf_enc_amr_wb_fx( st_fx, lsf_new, lsp_new, 0 ); } ELSE { #ifdef LSF_RE_USE_SECONDARY_CHANNEL - lsf_enc_fx(st_fx, lsf_new, lsp_new, NULL, NULL, 100, 0, 0, NULL, Q_new); + lsf_enc_fx( st_fx, lsf_new, lsp_new, NULL, NULL, 100, 0, 0, NULL, Q_new ); #else - lsf_enc_fx( st_fx, lsf_new, lsp_new, NULL, NULL,100, 0, 0, Q_new ); + lsf_enc_fx( st_fx, lsf_new, lsp_new, NULL, NULL, 100, 0, 0, Q_new ); #endif } /* Reset CNG history if CNG frame length is changed */ test(); test(); - if ( EQ_16(st_fx->bwidth,WB) && hDtxEnc->first_CNG!=0 && NE_16(st_fx->L_frame, hDtxEnc->last_CNG_L_frame)) + if ( EQ_16( st_fx->bwidth, WB ) && hDtxEnc->first_CNG != 0 && NE_16( st_fx->L_frame, hDtxEnc->last_CNG_L_frame ) ) { hTdCngEnc->ho_hist_size = 0; move16(); @@ -343,26 +342,26 @@ void CNG_enc_fx( } /*---------------------------------------------------------------------* - * CNG spectral envelope update - * Find A(z) coefficients - *---------------------------------------------------------------------*/ + * CNG spectral envelope update + * Find A(z) coefficients + *---------------------------------------------------------------------*/ - IF( LE_32(st_fx->last_core_brate, SID_2k40)) + IF( LE_32( st_fx->last_core_brate, SID_2k40 ) ) { /* Reset hangover counter if not first SID period */ - if( GT_32(st_fx->core_brate,FRAME_NO_DATA)) + if ( GT_32( st_fx->core_brate, FRAME_NO_DATA ) ) { hTdCngEnc->num_ho = 0; move16(); } /* Update LSPs if last SID energy not outlier or insufficient number of hangover frames */ test(); - IF( LT_16(hTdCngEnc->num_ho,3) || LT_32(Mult_32_16(hTdCngEnc->Enew_fx,21845 /*1/1.5f, Q15*/), hTdCngEnc->lp_ener_fx)) + IF( LT_16( hTdCngEnc->num_ho, 3 ) || LT_32( Mult_32_16( hTdCngEnc->Enew_fx, 21845 /*1/1.5f, Q15*/ ), hTdCngEnc->lp_ener_fx ) ) { - FOR( i=0; ilspCNG_fx[i] = mac_r(L_mult(CNG_ISF_FACT_FX, hDtxEnc->lspCNG_fx[i]),32768-CNG_ISF_FACT_FX,lsp_new[i]); + hDtxEnc->lspCNG_fx[i] = mac_r( L_mult( CNG_ISF_FACT_FX, hDtxEnc->lspCNG_fx[i] ), 32768 - CNG_ISF_FACT_FX, lsp_new[i] ); move16(); /* Q15 (15+15+1-16) */ } } @@ -373,35 +372,34 @@ void CNG_enc_fx( test(); test(); test(); - IF( EQ_16(st_fx->element_mode, EVS_MONO) && (( st_fx->Opt_AMR_WB || EQ_16(st_fx->bwidth,WB)) - && ( !hDtxEnc->first_CNG || GE_16(hTdCngEnc->act_cnt2,MIN_ACT_CNG_UPD) ) ) ) + IF( EQ_16( st_fx->element_mode, EVS_MONO ) && ( ( st_fx->Opt_AMR_WB || EQ_16( st_fx->bwidth, WB ) ) && ( !hDtxEnc->first_CNG || GE_16( hTdCngEnc->act_cnt2, MIN_ACT_CNG_UPD ) ) ) ) { - IF (GT_32(hDtxEnc->last_active_brate, ACELP_16k40)) + IF( GT_32( hDtxEnc->last_active_brate, ACELP_16k40 ) ) { hDtxEnc->CNG_mode = -1; move16(); } ELSE { - hDtxEnc->CNG_mode = get_cng_mode(hDtxEnc->last_active_brate); + hDtxEnc->CNG_mode = get_cng_mode( hDtxEnc->last_active_brate ); } } /* If first sid after active burst update LSF history from circ buffer */ - hTdCngEnc->burst_ho_cnt = s_min(hTdCngEnc->burst_ho_cnt, hTdCngEnc->ho_circ_size); + hTdCngEnc->burst_ho_cnt = s_min( hTdCngEnc->burst_ho_cnt, hTdCngEnc->ho_circ_size ); hTdCngEnc->act_cnt = 0; move16(); - s_ptr = add(sub(hTdCngEnc->ho_circ_ptr, hTdCngEnc->burst_ho_cnt),1); + s_ptr = add( sub( hTdCngEnc->ho_circ_ptr, hTdCngEnc->burst_ho_cnt ), 1 ); - if( s_ptr < 0 ) + if ( s_ptr < 0 ) { - s_ptr = add(s_ptr, hTdCngEnc->ho_circ_size); + s_ptr = add( s_ptr, hTdCngEnc->ho_circ_size ); } FOR( ll = hTdCngEnc->burst_ho_cnt; ll > 0; ll-- ) { - hTdCngEnc->ho_hist_ptr = add(hTdCngEnc->ho_hist_ptr,1); - if( EQ_16(hTdCngEnc->ho_hist_ptr, HO_HIST_SIZE)) + hTdCngEnc->ho_hist_ptr = add( hTdCngEnc->ho_hist_ptr, 1 ); + if ( EQ_16( hTdCngEnc->ho_hist_ptr, HO_HIST_SIZE ) ) { hTdCngEnc->ho_hist_ptr = 0; move16(); @@ -410,154 +408,155 @@ void CNG_enc_fx( /* Conversion between 12.8k and 16k LSPs */ test(); test(); - IF( EQ_16(st_fx->L_frame,L_FRAME )&&EQ_16(hTdCngEnc->ho_16k_lsp[s_ptr],1)) + IF( EQ_16( st_fx->L_frame, L_FRAME ) && EQ_16( hTdCngEnc->ho_16k_lsp[s_ptr], 1 ) ) { /* Conversion from 16k LPSs to 12k8 */ - lsp_convert_poly_fx( &(hTdCngEnc->ho_lsp_circ_fx[s_ptr*M]), st_fx->L_frame, 0 ); + lsp_convert_poly_fx( &( hTdCngEnc->ho_lsp_circ_fx[s_ptr * M] ), st_fx->L_frame, 0 ); } - ELSE IF ( EQ_16(st_fx->L_frame,L_FRAME16k)&& hTdCngEnc->ho_16k_lsp[s_ptr]==0) + ELSE IF( EQ_16( st_fx->L_frame, L_FRAME16k ) && hTdCngEnc->ho_16k_lsp[s_ptr] == 0 ) { /* 16k LSPs already converted and stored, just copy to the other buffer */ - Copy(&(hTdCngEnc->ho_lsp_circ2_fx[s_ptr*M]), &(hTdCngEnc->ho_lsp_circ_fx[s_ptr*M]), M ); + Copy( &( hTdCngEnc->ho_lsp_circ2_fx[s_ptr * M] ), &( hTdCngEnc->ho_lsp_circ_fx[s_ptr * M] ), M ); } /* update the circular buffers */ - Copy(&(hTdCngEnc->ho_lsp_circ_fx[s_ptr*M]), &(hTdCngEnc->ho_lsp_hist_fx[hTdCngEnc->ho_hist_ptr*M]), M ); - Copy32(&(hTdCngEnc->ho_ener_circ_fx[s_ptr]), &(hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr]), 1 ); - hTdCngEnc->ho_sid_bw = L_shl(L_and(hTdCngEnc->ho_sid_bw, (Word32) 0x3fffffffL ), 1); - Copy32(&(hTdCngEnc->ho_env_circ_fx[s_ptr*NUM_ENV_CNG]), &(hTdCngEnc->ho_env_hist_fx[hTdCngEnc->ho_hist_ptr*NUM_ENV_CNG]), NUM_ENV_CNG ); + Copy( &( hTdCngEnc->ho_lsp_circ_fx[s_ptr * M] ), &( hTdCngEnc->ho_lsp_hist_fx[hTdCngEnc->ho_hist_ptr * M] ), M ); + Copy32( &( hTdCngEnc->ho_ener_circ_fx[s_ptr] ), &( hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr] ), 1 ); + hTdCngEnc->ho_sid_bw = L_shl( L_and( hTdCngEnc->ho_sid_bw, (Word32) 0x3fffffffL ), 1 ); + Copy32( &( hTdCngEnc->ho_env_circ_fx[s_ptr * NUM_ENV_CNG] ), &( hTdCngEnc->ho_env_hist_fx[hTdCngEnc->ho_hist_ptr * NUM_ENV_CNG] ), NUM_ENV_CNG ); - hTdCngEnc->ho_hist_size = add(hTdCngEnc->ho_hist_size,1); - if (GT_16(hTdCngEnc->ho_hist_size, HO_HIST_SIZE)) + hTdCngEnc->ho_hist_size = add( hTdCngEnc->ho_hist_size, 1 ); + if ( GT_16( hTdCngEnc->ho_hist_size, HO_HIST_SIZE ) ) { hTdCngEnc->ho_hist_size = HO_HIST_SIZE; move16(); } - s_ptr = add(s_ptr,1); + s_ptr = add( s_ptr, 1 ); - if( EQ_16(s_ptr, hTdCngEnc->ho_circ_size)) + if ( EQ_16( s_ptr, hTdCngEnc->ho_circ_size ) ) { s_ptr = 0; move16(); } } - IF(hTdCngEnc->burst_ho_cnt > 0) + IF( hTdCngEnc->burst_ho_cnt > 0 ) { /**allow_cn_step |= ( hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr] > 4 * hTdCngEnc->lp_ener_fx ); */ #if 1 /*allow_cn_step |= (hDtxEnc->first_CNG || st->element_mode == EVS_MONO) && (hTdCngEnc->ho_ener_hist[hTdCngEnc->ho_hist_ptr] > lp_ener_thr_scale * hTdCngEnc->lp_ener);*/ /* (hTdCngEnc->ho_ener_hist[hTdCngEnc->ho_hist_ptr] > lp_ener_thr_scale * hTdCngEnc->lp_ener); */ - L_tmp1 = L_shr(hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr], 2); - IF(NE_16(lp_ener_thr_scale, 8)) + L_tmp1 = L_shr( hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr], 2 ); + IF( NE_16( lp_ener_thr_scale, 8 ) ) { - L_tmp1 = L_add(L_tmp1, L_shr(hTdCngEnc->lp_ener_fx, 8)); + L_tmp1 = L_add( L_tmp1, L_shr( hTdCngEnc->lp_ener_fx, 8 ) ); } - L_tmp1 = L_sub(L_tmp1, hTdCngEnc->lp_ener_fx); + L_tmp1 = L_sub( L_tmp1, hTdCngEnc->lp_ener_fx ); #else - L_tmp1 = L_shr(hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr],2); - L_tmp1 = L_sub(L_tmp1,hTdCngEnc->lp_ener_fx); + L_tmp1 = L_shr( hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr], 2 ); + L_tmp1 = L_sub( L_tmp1, hTdCngEnc->lp_ener_fx ); #endif - test();test(); - IF((hDtxEnc->first_CNG > 0 || EQ_16(st_fx->element_mode, EVS_MONO)) && L_tmp1>0) + test(); + test(); + IF( ( hDtxEnc->first_CNG > 0 || EQ_16( st_fx->element_mode, EVS_MONO ) ) && L_tmp1 > 0 ) { - *allow_cn_step = s_or(*allow_cn_step,1); + *allow_cn_step = s_or( *allow_cn_step, 1 ); } } test(); - IF ( *allow_cn_step == 0 && hTdCngEnc->ho_hist_size > 0 ) + IF( *allow_cn_step == 0 && hTdCngEnc->ho_hist_size > 0 ) { /* Use average of energies below last energy */ ptr = hTdCngEnc->ho_hist_ptr; move16(); - Copy( &(hTdCngEnc->ho_lsp_hist_fx[ptr*M]), tmp, M ); + Copy( &( hTdCngEnc->ho_lsp_hist_fx[ptr * M] ), tmp, M ); m1 = 0; move16(); - IF( L_and(hTdCngEnc->ho_sid_bw, (Word32) 0x1) == 0 ) + IF( L_and( hTdCngEnc->ho_sid_bw, (Word32) 0x1 ) == 0 ) { - Copy32( &hTdCngEnc->ho_env_hist_fx[ptr*NUM_ENV_CNG], tmp_env, NUM_ENV_CNG ); + Copy32( &hTdCngEnc->ho_env_hist_fx[ptr * NUM_ENV_CNG], tmp_env, NUM_ENV_CNG ); m1 = 1; move16(); } - L_enr = Mult_32_16(hTdCngEnc->ho_ener_hist_fx[ptr],W_DTX_HO_FX[0]) ;/* Q6+15-15->Q6 */ + L_enr = Mult_32_16( hTdCngEnc->ho_ener_hist_fx[ptr], W_DTX_HO_FX[0] ); /* Q6+15-15->Q6 */ weights = W_DTX_HO_FX[0]; /* Q15 */ m = 1; move16(); - FOR( k=1; kho_hist_size; k++ ) + FOR( k = 1; k < hTdCngEnc->ho_hist_size; k++ ) { - ptr = sub(ptr,1); - if( ptr < 0 ) + ptr = sub( ptr, 1 ); + if ( ptr < 0 ) { ptr = HO_HIST_SIZE - 1; move16(); } test(); - IF ( LT_32(Mult_32_16(hTdCngEnc->ho_ener_hist_fx[ptr],ONE_OVER_BUF_H_NRG_FX),hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr])&& - GT_32(hTdCngEnc->ho_ener_hist_fx[ptr],Mult_32_16(hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr], BUF_L_NRG_FX)) ) + IF( LT_32( Mult_32_16( hTdCngEnc->ho_ener_hist_fx[ptr], ONE_OVER_BUF_H_NRG_FX ), hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr] ) && + GT_32( hTdCngEnc->ho_ener_hist_fx[ptr], Mult_32_16( hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr], BUF_L_NRG_FX ) ) ) { /*enr += W_DTX_HO[k] * st_fx->ho_ener_hist[ptr]; */ - L_tmp1 = Mult_32_16(hTdCngEnc->ho_ener_hist_fx[ptr],W_DTX_HO_FX[k]) ; /* Q6+15-15->Q6 */ - L_enr = L_add(L_enr,L_tmp1); /* Q6 */ + L_tmp1 = Mult_32_16( hTdCngEnc->ho_ener_hist_fx[ptr], W_DTX_HO_FX[k] ); /* Q6+15-15->Q6 */ + L_enr = L_add( L_enr, L_tmp1 ); /* Q6 */ /*weights += W_DTX_HO[k]; */ - weights = add( weights, W_DTX_HO_FX[k]); /* Q15 */ + weights = add( weights, W_DTX_HO_FX[k] ); /* Q15 */ - Copy( &hTdCngEnc->ho_lsp_hist_fx[ptr*M], &tmp[m*M], M ); - IF( L_and(hTdCngEnc->ho_sid_bw, L_shl((Word32)0x1,k)) == 0 ) + Copy( &hTdCngEnc->ho_lsp_hist_fx[ptr * M], &tmp[m * M], M ); + IF( L_and( hTdCngEnc->ho_sid_bw, L_shl( (Word32) 0x1, k ) ) == 0 ) { - Copy32( &hTdCngEnc->ho_env_hist_fx[ptr*NUM_ENV_CNG], &tmp_env[m1*NUM_ENV_CNG], NUM_ENV_CNG ); - m1 = add(m1,1); + Copy32( &hTdCngEnc->ho_env_hist_fx[ptr * NUM_ENV_CNG], &tmp_env[m1 * NUM_ENV_CNG], NUM_ENV_CNG ); + m1 = add( m1, 1 ); } - m = add(m,1); + m = add( m, 1 ); } } /*enr /= weights; */ - exp = norm_s(weights); - tmp1 = div_s(shl(1,sub(14,exp)),weights); /* Q(15+14-exp-15) */ - L_tmp1 = Mult_32_16(L_enr,tmp1); /* Q(14-exp+6-15)->Q(5-exp) */ - L_enr = L_shl(L_tmp1,add(exp,1)); /* Q6 */ + exp = norm_s( weights ); + tmp1 = div_s( shl( 1, sub( 14, exp ) ), weights ); /* Q(15+14-exp-15) */ + L_tmp1 = Mult_32_16( L_enr, tmp1 ); /* Q(14-exp+6-15)->Q(5-exp) */ + L_enr = L_shl( L_tmp1, add( exp, 1 ) ); /* Q6 */ hTdCngEnc->lp_ener_fx = L_enr; - move32();/* Q6 */ + move32(); /* Q6 */ set32_fx( max_val, 0, 2 ); set16_fx( max_idx, 0, 2 ); - FOR( i=0; iL_frame,L_FRAME)) + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { - lsp2lsf_fx( &tmp[i*M], lsf_tmp, M, INT_FS_FX ); + lsp2lsf_fx( &tmp[i * M], lsf_tmp, M, INT_FS_FX ); ftmp_fx = 964; - move16();/*QX2.56 */ - tmpv = sub(16384,add(lsf_tmp[M-1],ftmp_fx)); /*QX2.56 */ - L_tmp = L_mult0(tmpv,tmpv); /*QX6.5536 */ + move16(); /*QX2.56 */ + tmpv = sub( 16384, add( lsf_tmp[M - 1], ftmp_fx ) ); /*QX2.56 */ + L_tmp = L_mult0( tmpv, tmpv ); /*QX6.5536 */ } ELSE { - lsp2lsf_fx( &tmp[i*M], lsf_tmp, M, INT_FS_16k ); + lsp2lsf_fx( &tmp[i * M], lsf_tmp, M, INT_FS_16k ); ftmp_fx = 1205; - move16();/*QX2.56 */ - tmpv = sub(20480,add(lsf_tmp[M-1],ftmp_fx)); /*QX2.56 */ - L_tmp = L_mult0(tmpv,tmpv); /*QX6.5536 */ + move16(); /*QX2.56 */ + tmpv = sub( 20480, add( lsf_tmp[M - 1], ftmp_fx ) ); /*QX2.56 */ + L_tmp = L_mult0( tmpv, tmpv ); /*QX6.5536 */ } - tmpv = sub(lsf_tmp[0],ftmp_fx); /*QX2.56 */ - L_tmp = L_mac0(L_tmp,tmpv,tmpv); /*QX6.5536 */ - FOR ( j=0; jlspCNG_fx[i] = lsp_tmp[i]; move16(); /*Q15 */ @@ -642,94 +641,94 @@ void CNG_enc_fx( } ELSE { - FOR( i=0; ilspCNG_fx[i] = add(mult_r(26214,lsp_tmp[i]),mult_r(6554,lsp_new[i])); + hDtxEnc->lspCNG_fx[i] = add( mult_r( 26214, lsp_tmp[i] ), mult_r( 6554, lsp_new[i] ) ); move16(); } } IF( m1 > 0 ) { - FOR ( i=0; ilp_ener_fx; */ - IF(EQ_16(m1,1)) + IF( EQ_16( m1, 1 ) ) { #ifdef BASOP_NOGLOB L_tmp = L_sub_sat( L_tmp, L_add_sat( hTdCngEnc->lp_ener_fx, hTdCngEnc->lp_ener_fx ) ); #else - L_tmp = L_sub(L_tmp,L_add(hTdCngEnc->lp_ener_fx,hTdCngEnc->lp_ener_fx)); + L_tmp = L_sub( L_tmp, L_add( hTdCngEnc->lp_ener_fx, hTdCngEnc->lp_ener_fx ) ); #endif } ELSE { - tmp1 = div_s(1,m1); - L_tmp = Mult_32_16(L_tmp,tmp1); + tmp1 = div_s( 1, m1 ); + L_tmp = Mult_32_16( L_tmp, tmp1 ); #ifdef BASOP_NOGLOB L_tmp = L_sub_sat( L_tmp, L_add_sat( hTdCngEnc->lp_ener_fx, hTdCngEnc->lp_ener_fx ) ); #else - L_tmp = L_sub(L_tmp,L_add(hTdCngEnc->lp_ener_fx,hTdCngEnc->lp_ener_fx)); + L_tmp = L_sub( L_tmp, L_add( hTdCngEnc->lp_ener_fx, hTdCngEnc->lp_ener_fx ) ); #endif } env[i] = L_tmp; move32(); } - Copy32(env, hTdCngEnc->lp_env_fx, NUM_ENV_CNG); + Copy32( env, hTdCngEnc->lp_env_fx, NUM_ENV_CNG ); } } ELSE { - Copy( lsp_new, hDtxEnc->lspCNG_fx, M ); /* use newly analyzed ISFs */ + Copy( lsp_new, hDtxEnc->lspCNG_fx, M ); /* use newly analyzed ISFs */ } } - IF ( st_fx->Opt_AMR_WB != 0 ) + IF( st_fx->Opt_AMR_WB != 0 ) { - E_LPC_f_isp_a_conversion(hDtxEnc->lspCNG_fx, Aq, M ); + E_LPC_f_isp_a_conversion( hDtxEnc->lspCNG_fx, Aq, M ); } ELSE { - E_LPC_f_lsp_a_conversion(hDtxEnc->lspCNG_fx, Aq, M ); /* Find A(z) (not interpolated) */ + E_LPC_f_lsp_a_conversion( hDtxEnc->lspCNG_fx, Aq, M ); /* Find A(z) (not interpolated) */ } - tmp_loop = shr(st_fx->L_frame,6); - FOR( i=1; iL_frame, 6 ); + FOR( i = 1; i < tmp_loop; i++ ) { - Copy( Aq, &Aq[i*(M+1)], M+1 ); + Copy( Aq, &Aq[i * ( M + 1 )], M + 1 ); } /*-----------------------------------------------------------------* - * Find residual signal - * Calculate residual signal energy per sample - *-----------------------------------------------------------------*/ + * Find residual signal + * Calculate residual signal energy per sample + *-----------------------------------------------------------------*/ /* calculate the residual signal */ - Residu3_fx(Aq, speech, res, st_fx->L_frame, 0); - Copy(res, res1, st_fx->L_frame); + Residu3_fx( Aq, speech, res, st_fx->L_frame, 0 ); + Copy( res, res1, st_fx->L_frame ); test(); - IF (EQ_16(st_fx->element_mode, IVAS_CPE_DFT) || EQ_16(st_fx->element_mode, IVAS_CPE_TD)) + IF( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) { - //PMT("Code to be completed") + // PMT("Code to be completed") #ifdef IVAS_CODE - att = powf(10.0f, hTdCngEnc->CNG_att / 20.0f); - v_multc(res1, att, res1, st->L_frame); + att = powf( 10.0f, hTdCngEnc->CNG_att / 20.0f ); + v_multc( res1, att, res1, st->L_frame ); #endif } - ELSE IF( NE_16(st_fx->bwidth,NB)) + ELSE IF( NE_16( st_fx->bwidth, NB ) ) { test(); - IF( EQ_16(st_fx->bwidth,WB) && hDtxEnc->CNG_mode>=0) + IF( EQ_16( st_fx->bwidth, WB ) && hDtxEnc->CNG_mode >= 0 ) { ftmp_fx = HO_ATT_FX[hDtxEnc->CNG_mode]; } @@ -739,197 +738,197 @@ void CNG_enc_fx( move16(); } - att = mult(ftmp_fx,5461);/* Q15 */ - L_tmp = L_mult(att,8);/* Q16 */ - tmp1 = extract_l(L_shr(L_tmp,2));/* Q14 */ - tmp1 = add(16384,tmp1); - att = div_s(16374,tmp1); /* Q15 */ + att = mult( ftmp_fx, 5461 ); /* Q15 */ + L_tmp = L_mult( att, 8 ); /* Q16 */ + tmp1 = extract_l( L_shr( L_tmp, 2 ) ); /* Q14 */ + tmp1 = add( 16384, tmp1 ); + att = div_s( 16374, tmp1 ); /* Q15 */ - att = s_max(att, ftmp_fx); + att = s_max( att, ftmp_fx ); FOR( i = 0; i < st_fx->L_frame; i++ ) { /*res1[i] *= att;*/ - res1[i] = mult(res1[i],att); - move16();/* Q_new */ + res1[i] = mult( res1[i], att ); + move16(); /* Q_new */ } - att = shr(att,7);/* Q8 */ + att = shr( att, 7 ); /* Q8 */ } /* calculate the spectrum of residual signal */ - Copy(res1, fft_io, st_fx->L_frame); + Copy( res1, fft_io, st_fx->L_frame ); - IF ( EQ_16(st_fx->L_frame,L_FRAME16k)) + IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { - modify_Fs_fx( fft_io, L_FRAME16k, 16000, fft_io, 12800, hTdCngEnc->exc_mem2_fx,0); + modify_Fs_fx( fft_io, L_FRAME16k, 16000, fft_io, 12800, hTdCngEnc->exc_mem2_fx, 0 ); } - fft_rel_fx(fft_io, L_FFT, LOG2_L_FFT); + fft_rel_fx( fft_io, L_FFT, LOG2_L_FFT ); ptR = &fft_io[1]; - ptI = &fft_io[L_FFT-1]; - FOR ( i=0; icng_res_env_fx[(hTdCngEnc->cng_hist_ptr)*NUM_ENV_CNG]), NUM_ENV_CNG ); + Copy32( env, &( hTdCngEnc->cng_res_env_fx[( hTdCngEnc->cng_hist_ptr ) * NUM_ENV_CNG] ), NUM_ENV_CNG ); /* calculate the residual signal energy */ /*enr = dotp( res, res, L_frame ) / L_frame; */ maxv = 0; move16(); - FOR(i = 0; i < st_fx->L_frame; i++) + FOR( i = 0; i < st_fx->L_frame; i++ ) { - maxv = s_max(maxv, abs_s(res[i])); + maxv = s_max( maxv, abs_s( res[i] ) ); } - scale = norm_s(maxv); + scale = norm_s( maxv ); pt_res = res; - L_ener = L_deposit_l(1); - IF( EQ_16(st_fx->L_frame, L_FRAME)) + L_ener = L_deposit_l( 1 ); + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { - FOR (j=0; j<128; j++) + FOR( j = 0; j < 128; j++ ) { - tmpv = shl(*pt_res,scale); - L_tmp = L_mult0(tmpv, tmpv); + tmpv = shl( *pt_res, scale ); + L_tmp = L_mult0( tmpv, tmpv ); pt_res++; - tmpv = shl(*pt_res,scale); + tmpv = shl( *pt_res, scale ); #ifdef BASOP_NOGLOB L_tmp = L_mac0_sat( L_tmp, tmpv, tmpv ); /* 2*(Q_new+scale) */ pt_res++; - L_ener = L_add_sat(L_ener, L_shr(L_tmp, 7)); /* 2*(Q_new+scale)+1, divide by L_frame done here */ + L_ener = L_add_sat( L_ener, L_shr( L_tmp, 7 ) ); /* 2*(Q_new+scale)+1, divide by L_frame done here */ #else - L_tmp = L_mac0(L_tmp, tmpv, tmpv); /* 2*(Q_new+scale) */ + L_tmp = L_mac0( L_tmp, tmpv, tmpv ); /* 2*(Q_new+scale) */ pt_res++; - L_ener = L_add(L_ener, L_shr(L_tmp, 7)); /* 2*(Q_new+scale)+1, divide by L_frame done here */ + L_ener = L_add( L_ener, L_shr( L_tmp, 7 ) ); /* 2*(Q_new+scale)+1, divide by L_frame done here */ #endif } } ELSE /* L_FRAME16k */ { - FOR (j=0; j<160; j++) + FOR( j = 0; j < 160; j++ ) { - tmpv = shl(*pt_res,scale); - L_tmp = L_mult0(tmpv, tmpv); + tmpv = shl( *pt_res, scale ); + L_tmp = L_mult0( tmpv, tmpv ); pt_res++; - tmpv = shl(*pt_res,scale); + tmpv = shl( *pt_res, scale ); #ifdef BASOP_NOGLOB L_tmp = L_mac0_sat( L_tmp, tmpv, tmpv ); /* 2*(Q_new+scale) */ pt_res++; - L_ener = L_add_sat(L_ener, L_shr(Mult_32_16(L_tmp,26214 /* 256/320, Q15 */), 7)); /* 2*(Q_new+scale)+15+1-16+1, divide by L_frame done here */ + L_ener = L_add_sat( L_ener, L_shr( Mult_32_16( L_tmp, 26214 /* 256/320, Q15 */ ), 7 ) ); /* 2*(Q_new+scale)+15+1-16+1, divide by L_frame done here */ #else - L_tmp = L_mac0(L_tmp, tmpv, tmpv); /* 2*(Q_new+scale) */ + L_tmp = L_mac0( L_tmp, tmpv, tmpv ); /* 2*(Q_new+scale) */ pt_res++; - L_ener = L_add(L_ener, L_shr(Mult_32_16(L_tmp,26214 /* 256/320, Q15 */), 7)); /* 2*(Q_new+scale)+15+1-16+1, divide by L_frame done here */ + L_ener = L_add( L_ener, L_shr( Mult_32_16( L_tmp, 26214 /* 256/320, Q15 */ ), 7 ) ); /* 2*(Q_new+scale)+15+1-16+1, divide by L_frame done here */ #endif } } /* convert log2 of residual signal energy */ /*enr = (float)log10( enr + 0.1f ) / (float)log10( 2.0f ); */ - hi = norm_l(L_ener); - lo = Log2_norm_lc(L_shl(L_ener, hi)); - hi = sub(29, hi); /* log2 exp in Q2*(Q_new+scale) */ - hi = sub(hi, shl(add(Q_new,scale), 1)); /* Q0 */ - L_tmp = L_Comp(hi, lo); /* Q16 */ - enr = round_fx(L_shl(L_tmp, 8)); /* Q8 (16+8-16) */ + hi = norm_l( L_ener ); + lo = Log2_norm_lc( L_shl( L_ener, hi ) ); + hi = sub( 29, hi ); /* log2 exp in Q2*(Q_new+scale) */ + hi = sub( hi, shl( add( Q_new, scale ), 1 ) ); /* Q0 */ + L_tmp = L_Comp( hi, lo ); /* Q16 */ + enr = round_fx( L_shl( L_tmp, 8 ) ); /* Q8 (16+8-16) */ /* update the circular buffer of old energies */ hTdCngEnc->cng_ener_hist_fx[hTdCngEnc->cng_hist_ptr] = enr; - move16(); /* Q8 */ + move16(); /* Q8 */ /*-----------------------------------------------------------------* - * Quantize residual signal energy (only in SID frame) - *-----------------------------------------------------------------*/ + * Quantize residual signal energy (only in SID frame) + *-----------------------------------------------------------------*/ test(); - IF( EQ_32(st_fx->core_brate, SID_2k40)||EQ_32(st_fx->core_brate,SID_1k75)) + IF( EQ_32( st_fx->core_brate, SID_2k40 ) || EQ_32( st_fx->core_brate, SID_1k75 ) ) { - IF( GE_16(hDtxEnc->cng_cnt,sub(hDtxEnc->cng_hist_size,1))) + IF( GE_16( hDtxEnc->cng_cnt, sub( hDtxEnc->cng_hist_size, 1 ) ) ) { /* average the envelope except outliers */ - FOR ( i=0; icng_hist_size; j++ ) + L_tmp1 = L_add( env[i], 0 ); + FOR( j = 0; j < hDtxEnc->cng_hist_size; j++ ) { #ifdef BASOP_NOGLOB L_tmp1 = L_add_sat( L_tmp1, hTdCngEnc->cng_res_env_fx[j * NUM_ENV_CNG + i] ); #else - L_tmp1 = L_add(L_tmp1,hTdCngEnc->cng_res_env_fx[j*NUM_ENV_CNG+i]); + L_tmp1 = L_add( L_tmp1, hTdCngEnc->cng_res_env_fx[j * NUM_ENV_CNG + i] ); #endif } - L_tmp = L_add(hTdCngEnc->cng_res_env_fx[max_idx1[0]*NUM_ENV_CNG+i],hTdCngEnc->cng_res_env_fx[max_idx1[1]*NUM_ENV_CNG+i]); - L_tmp1 = L_sub(L_tmp1,L_tmp); + L_tmp = L_add( hTdCngEnc->cng_res_env_fx[max_idx1[0] * NUM_ENV_CNG + i], hTdCngEnc->cng_res_env_fx[max_idx1[1] * NUM_ENV_CNG + i] ); + L_tmp1 = L_sub( L_tmp1, L_tmp ); /* env[i] /= (float)(st_fx->cng_hist_size - 2); */ - tmp1 = sub(hDtxEnc->cng_hist_size,2); - IF(GT_16(tmp1,1)) + tmp1 = sub( hDtxEnc->cng_hist_size, 2 ); + IF( GT_16( tmp1, 1 ) ) { - tmp1 = div_s(1,tmp1); - L_tmp1 = Mult_32_16(L_tmp1,tmp1); + tmp1 = div_s( 1, tmp1 ); + L_tmp1 = Mult_32_16( L_tmp1, tmp1 ); } env[i] = L_tmp1; move32(); } /* compute average excitation energy */ - L_tmp = L_deposit_l(0); + L_tmp = L_deposit_l( 0 ); ptr = hTdCngEnc->cng_hist_ptr; move16(); - FOR (k=0; k< hDtxEnc->cng_hist_size; k++) + FOR( k = 0; k < hDtxEnc->cng_hist_size; k++ ) { /* enr += W_HIST[k]*cng_ener_hist[ptr] */ - L_tmp = L_mac0(L_tmp, W_HIST_FX[k], hTdCngEnc->cng_ener_hist_fx[ptr]); /* Q24 (8+16) */ - ptr = sub(ptr, 1); - if (ptr < 0) /* check for circular pointer */ + L_tmp = L_mac0( L_tmp, W_HIST_FX[k], hTdCngEnc->cng_ener_hist_fx[ptr] ); /* Q24 (8+16) */ + ptr = sub( ptr, 1 ); + if ( ptr < 0 ) /* check for circular pointer */ { ptr = DTX_HIST_SIZE - 1; move16(); } } /*----------------------------------------------------------- - * here we want to divide L_tmp by the sum - * of all the coefs used W_HIST[0..cng_hist_size-1] - * The table W_HIST_S already contains the inverted sum. - * That is - * W_HIST_S[k] 1 - * ------------- = --------------------------- - * 4096 W_HIST[0] + ... + W_HIST[k] - * - * 1 / Sum(W_HIST[0..k]) is always > 1 since the sum - * of the coefs 0..k is always < 1 but > 0 - * enr is in Q8 since the history buffer constains Q8 energies - *-----------------------------------------------------------*/ + * here we want to divide L_tmp by the sum + * of all the coefs used W_HIST[0..cng_hist_size-1] + * The table W_HIST_S already contains the inverted sum. + * That is + * W_HIST_S[k] 1 + * ------------- = --------------------------- + * 4096 W_HIST[0] + ... + W_HIST[k] + * + * 1 / Sum(W_HIST[0..k]) is always > 1 since the sum + * of the coefs 0..k is always < 1 but > 0 + * enr is in Q8 since the history buffer constains Q8 energies + *-----------------------------------------------------------*/ /*L_tmp = Mpy_32_16_1(L_tmp, W_HIST_S_FX[k-1]); */ /* normalize average value */ - L_tmp = Mult_32_16(L_tmp, W_HIST_S_FX[k-1]); /* Q21 (24+12+1-16) */ - L_tmp = L_shl(L_tmp, 3); /* Q24 */ - enr = round_fx(L_tmp); /* Q8 */ + L_tmp = Mult_32_16( L_tmp, W_HIST_S_FX[k - 1] ); /* Q21 (24+12+1-16) */ + L_tmp = L_shl( L_tmp, 3 ); /* Q24 */ + enr = round_fx( L_tmp ); /* Q8 */ } /* decrease the energy in case of WB input */ - IF ( EQ_16(st_fx->element_mode, IVAS_SCE) || EQ_16(st_fx->element_mode, IVAS_CPE_DFT)) + IF( EQ_16( st_fx->element_mode, IVAS_SCE ) || EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) ) { - //PMT("CNG IVAS_SCE and IVAS_CPE_DFT code missing") - //IVAS_CODE - //enr += hTdCngEnc->CNG_att * FAC_LOG2 / 10.0f; + // PMT("CNG IVAS_SCE and IVAS_CPE_DFT code missing") + // IVAS_CODE + // enr += hTdCngEnc->CNG_att * FAC_LOG2 / 10.0f; } - ELSE IF( NE_16(st_fx->bwidth, NB)) + ELSE IF( NE_16( st_fx->bwidth, NB ) ) { - IF( EQ_16(st_fx->bwidth,WB)) + IF( EQ_16( st_fx->bwidth, WB ) ) { - IF(hDtxEnc->CNG_mode >= 0 ) + IF( hDtxEnc->CNG_mode >= 0 ) { /* Bitrate adapted attenuation */ att = ENR_ATT_fx[hDtxEnc->CNG_mode]; @@ -945,9 +944,9 @@ void CNG_enc_fx( ELSE { att = 384; - move16();/*Q8*/ + move16(); /*Q8*/ } - enr = sub(enr, att ); + enr = sub( enr, att ); } /* intialize the energy quantization parameters */ IF( st_fx->Opt_AMR_WB == 0 ) @@ -974,25 +973,25 @@ void CNG_enc_fx( } /* calculate the energy quantization index */ - enr_index = add(enr, 512 /* Q8(2.0) */); /* enr + 2.0 */ - enr_index = extract_l(L_shr(L_mult0(enr_index, step), 12+8)); /* Q0 (8+12-(8+12)) */ + enr_index = add( enr, 512 /* Q8(2.0) */ ); /* enr + 2.0 */ + enr_index = extract_l( L_shr( L_mult0( enr_index, step ), 12 + 8 ) ); /* Q0 (8+12-(8+12)) */ /* limit the energy quantization index */ - enr_index = s_min(enr_index, maxl); - enr_index = s_max(enr_index, 0); + enr_index = s_min( enr_index, maxl ); + enr_index = s_max( enr_index, 0 ); /* allow only slow energy increase */ test(); - IF( hTdCngEnc->old_enr_index >= 0 && GT_16(enr_index, add(hTdCngEnc->old_enr_index, MAX_DELTA))) + IF( hTdCngEnc->old_enr_index >= 0 && GT_16( enr_index, add( hTdCngEnc->old_enr_index, MAX_DELTA ) ) ) { IF( *allow_cn_step != 0 ) { - tmp1 = mult(27853 /* Q15(0.85) */,sub(enr_index,hTdCngEnc->old_enr_index)); - enr_index = add(hTdCngEnc->old_enr_index,tmp1); + tmp1 = mult( 27853 /* Q15(0.85) */, sub( enr_index, hTdCngEnc->old_enr_index ) ); + enr_index = add( hTdCngEnc->old_enr_index, tmp1 ); } ELSE { - enr_index = add(hTdCngEnc->old_enr_index, MAX_DELTA); + enr_index = add( hTdCngEnc->old_enr_index, MAX_DELTA ); } } hTdCngEnc->old_enr_index = enr_index; @@ -1007,140 +1006,139 @@ void CNG_enc_fx( /* Find quantized energy */ /* *Enew = (float)enr_index / step - 2.0 */ /* *Enew = (float)pow(2.0, *Enew) */ - L_tmp = L_mult(enr_index, step_inv); /* Q16(0+15+1) */ + L_tmp = L_mult( enr_index, step_inv ); /* Q16(0+15+1) */ /* substract by 2 not done to leave Energy in Q2 */ - lo = L_Extract_lc(L_tmp, &hi); - hTdCngEnc->Enew_fx = Pow2(add(hi, 4), lo); /* Q6 */ - IF ( EQ_32(st_fx->core_brate, SID_2k40)) + lo = L_Extract_lc( L_tmp, &hi ); + hTdCngEnc->Enew_fx = Pow2( add( hi, 4 ), lo ); /* Q6 */ + IF( EQ_32( st_fx->core_brate, SID_2k40 ) ) { /* enr1 = (float)log10( st->Enew*L_frame + 0.1f ) / (float)log10( 2.0f );*/ - exp = norm_l(hTdCngEnc->Enew_fx); - L_tmp = L_shl(hTdCngEnc->Enew_fx,exp); /*Q(exp+6) */ - L_tmp = Mult_32_16(L_tmp,shl(st_fx->L_frame,5));/* Q(exp+6+5-15=exp-4) */ + exp = norm_l( hTdCngEnc->Enew_fx ); + L_tmp = L_shl( hTdCngEnc->Enew_fx, exp ); /*Q(exp+6) */ + L_tmp = Mult_32_16( L_tmp, shl( st_fx->L_frame, 5 ) ); /* Q(exp+6+5-15=exp-4) */ -#ifdef BASOP_NOGLOB - L_tmp = L_shr_sat(L_tmp,sub(exp,10)); /* Q6 */ +#ifdef BASOP_NOGLOB + L_tmp = L_shr_sat( L_tmp, sub( exp, 10 ) ); /* Q6 */ #else - L_tmp = L_shr(L_tmp,sub(exp,10)); /* Q6 */ + L_tmp = L_shr( L_tmp, sub( exp, 10 ) ); /* Q6 */ #endif - exp = norm_l(L_tmp); - fra = Log2_norm_lc(L_shl(L_tmp,exp)); - exp = sub(sub(30,exp),6); - L_tmp = L_Comp(exp,fra); - enr1 = L_shr(L_tmp,10);/* Q6 */ + exp = norm_l( L_tmp ); + fra = Log2_norm_lc( L_shl( L_tmp, exp ) ); + exp = sub( sub( 30, exp ), 6 ); + L_tmp = L_Comp( exp, fra ); + enr1 = L_shr( L_tmp, 10 ); /* Q6 */ - FOR ( i=0; iEnew;*/ - L_tmp1 = L_add(env[i], 0); - L_tmp = L_add(hTdCngEnc->Enew_fx,hTdCngEnc->Enew_fx); - L_tmp1 = L_sub(L_tmp1,L_tmp); /*Q6*/ + L_tmp1 = L_add( env[i], 0 ); + L_tmp = L_add( hTdCngEnc->Enew_fx, hTdCngEnc->Enew_fx ); + L_tmp1 = L_sub( L_tmp1, L_tmp ); /*Q6*/ - IF ( L_tmp1 < 0 ) + IF( L_tmp1 < 0 ) { - L_tmp1 = L_deposit_l(6); /* (0.1)Q6 */ + L_tmp1 = L_deposit_l( 6 ); /* (0.1)Q6 */ } /* env[i] = (float)log10( env[i] + 0.1f ) / (float)log10( 2.0f ); */ - exp = norm_l(L_tmp1); - fra = Log2_norm_lc(L_shl(L_tmp1,exp)); - exp = sub(sub(30,exp),6); - L_tmp = L_Comp(exp,fra); - L_tmp1 = L_shr(L_tmp,10); /* Q6 */ + exp = norm_l( L_tmp1 ); + fra = Log2_norm_lc( L_shl( L_tmp1, exp ) ); + exp = sub( sub( 30, exp ), 6 ); + L_tmp = L_Comp( exp, fra ); + L_tmp1 = L_shr( L_tmp, 10 ); /* Q6 */ - L_tmp = L_shr(L_deposit_l(att),2);/* Q6 */ - L_tmp1 = L_sub(L_tmp1,L_tmp); + L_tmp = L_shr( L_deposit_l( att ), 2 ); /* Q6 */ + L_tmp1 = L_sub( L_tmp1, L_tmp ); - IF ( L_tmp1 < 0 ) + IF( L_tmp1 < 0 ) { - L_tmp1 = L_deposit_l(0); + L_tmp1 = L_deposit_l( 0 ); } - L_tmp1 = L_sub(enr1,L_tmp1); + L_tmp1 = L_sub( enr1, L_tmp1 ); env[i] = L_tmp1; move32(); } /* codebook search */ - min1 = L_add(1310588928, 0); /* Q17 */ + min1 = L_add( 1310588928, 0 ); /* Q17 */ min1_idx = 0; move16(); - FOR ( i=0; i<64; i++ ) + FOR( i = 0; i < 64; i++ ) { - d = L_deposit_l(0); - FOR ( j=0; jEnew_fx,21845 /*1/1.5f, Q15*/), hTdCngEnc->lp_ener_fx)) + IF( *allow_cn_step == 0 && LT_32( Mult_32_16( hTdCngEnc->Enew_fx, 21845 /*1/1.5f, Q15*/ ), hTdCngEnc->lp_ener_fx ) ) { /* update the pointer to circular buffer of old LSP vectors */ - hTdCngEnc->ho_hist_ptr = add(hTdCngEnc->ho_hist_ptr, 1); - if( EQ_16(hTdCngEnc->ho_hist_ptr,HO_HIST_SIZE)) + hTdCngEnc->ho_hist_ptr = add( hTdCngEnc->ho_hist_ptr, 1 ); + if ( EQ_16( hTdCngEnc->ho_hist_ptr, HO_HIST_SIZE ) ) { hTdCngEnc->ho_hist_ptr = 0; move16(); } /* update the circular buffer of old LSP vectors with the new LSP vector */ - Copy( lsp_new, &(hTdCngEnc->ho_lsp_hist_fx[(hTdCngEnc->ho_hist_ptr)*M]), M ); + Copy( lsp_new, &( hTdCngEnc->ho_lsp_hist_fx[( hTdCngEnc->ho_hist_ptr ) * M] ), M ); /* update the hangover energy buffer */ hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr] = hTdCngEnc->Enew_fx; move32(); - IF ( EQ_32(st_fx->core_brate, SID_2k40)) + IF( EQ_32( st_fx->core_brate, SID_2k40 ) ) { - FOR ( i=0; iEnew;*/ - L_tmp = L_sub(enr1,q_env[i]);/* Q6 */ - L_tmp = L_shl(L_tmp, 10);/* 16 */ - temp_lo_fx = L_Extract_lc(L_tmp, &temp_hi_fx); + L_tmp = L_sub( enr1, q_env[i] ); /* Q6 */ + L_tmp = L_shl( L_tmp, 10 ); /* 16 */ + temp_lo_fx = L_Extract_lc( L_tmp, &temp_hi_fx ); - exp_pow = sub(14, temp_hi_fx); - L_tmp = Pow2(14, temp_lo_fx); /* Qexp_pow */ - env[i] = L_shl(L_tmp, sub(6, exp_pow)); + exp_pow = sub( 14, temp_hi_fx ); + L_tmp = Pow2( 14, temp_lo_fx ); /* Qexp_pow */ + env[i] = L_shl( L_tmp, sub( 6, exp_pow ) ); + move32(); /* Q6 */ + L_tmp = L_add( hTdCngEnc->Enew_fx, hTdCngEnc->Enew_fx ); + env[i] = L_add( env[i], L_tmp ); move32(); /* Q6 */ - L_tmp = L_add(hTdCngEnc->Enew_fx,hTdCngEnc->Enew_fx); - env[i] = L_add(env[i],L_tmp); - move32();/* Q6 */ } - Copy32( env, &(hTdCngEnc->ho_env_hist_fx[(hTdCngEnc->ho_hist_ptr)*NUM_ENV_CNG]), NUM_ENV_CNG ); + Copy32( env, &( hTdCngEnc->ho_env_hist_fx[( hTdCngEnc->ho_hist_ptr ) * NUM_ENV_CNG] ), NUM_ENV_CNG ); } - hTdCngEnc->ho_hist_size = add(hTdCngEnc->ho_hist_size,1); - if( GT_16(hTdCngEnc->ho_hist_size,HO_HIST_SIZE)) + hTdCngEnc->ho_hist_size = add( hTdCngEnc->ho_hist_size, 1 ); + if ( GT_16( hTdCngEnc->ho_hist_size, HO_HIST_SIZE ) ) { hTdCngEnc->ho_hist_size = HO_HIST_SIZE; move16(); @@ -1148,13 +1146,13 @@ void CNG_enc_fx( } } /* dithering bit for AMR-WB IO mode is always set to 0 */ - IF( EQ_32(st_fx->core_brate, SID_1k75)) + IF( EQ_32( st_fx->core_brate, SID_1k75 ) ) { push_indice_fx( hBstr, IND_DITHERING, 0, 1 ); } - IF ( EQ_32(st_fx->core_brate, SID_2k40)) + IF( EQ_32( st_fx->core_brate, SID_2k40 ) ) { - IF(EQ_16(st_fx->L_frame, L_FRAME16k)) + IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { push_indice_fx( hBstr, IND_ACELP_16KHZ, 1, 1 ); } @@ -1163,12 +1161,12 @@ void CNG_enc_fx( push_indice_fx( hBstr, IND_ACELP_16KHZ, 0, 1 ); } - push_indice_fx( hBstr, IND_CNG_HO, s_min(hTdCngEnc->burst_ho_cnt, 7 ), 3 ); + push_indice_fx( hBstr, IND_CNG_HO, s_min( hTdCngEnc->burst_ho_cnt, 7 ), 3 ); hTdCngEnc->num_ho = m; move16(); push_indice_fx( hBstr, IND_SID_TYPE, 0, 1 ); - IF ( LT_32(st_fx->input_Fs, 32000) && NE_16(st_fx->element_mode, IVAS_CPE_DFT)) + IF( LT_32( st_fx->input_Fs, 32000 ) && NE_16( st_fx->element_mode, IVAS_CPE_DFT ) ) { push_indice_fx( hBstr, IND_SID_BW, 0, 1 ); *sid_bw = 0; @@ -1177,11 +1175,11 @@ void CNG_enc_fx( } /*-----------------------------------------------------------------* - * Updates - *-----------------------------------------------------------------*/ + * Updates + *-----------------------------------------------------------------*/ /* update the SID frames counter */ test(); - IF( EQ_32(st_fx->core_brate, SID_2k40)||EQ_32(st_fx->core_brate,SID_1k75)) + IF( EQ_32( st_fx->core_brate, SID_2k40 ) || EQ_32( st_fx->core_brate, SID_1k75 ) ) { hDtxEnc->cng_cnt = 0; move16(); @@ -1193,7 +1191,7 @@ void CNG_enc_fx( } ELSE { - hDtxEnc->cng_cnt = add(hDtxEnc->cng_cnt,1); + hDtxEnc->cng_cnt = add( hDtxEnc->cng_cnt, 1 ); } return; @@ -1204,36 +1202,36 @@ void CNG_enc_fx( * SWB DTX/CNG encoding *---------------------------------------------------------------------*/ void swb_CNG_enc_fx( - Encoder_State *st_fx, /* i/o: State structure */ - const Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz (Q0) */ - const Word16 *syn_12k8_16k_fx /* i : ACELP core synthesis at 12.8kHz or 16kHz (st_fx->Q_syn = 0) */ + Encoder_State *st_fx, /* i/o: State structure */ + const Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz (Q0) */ + const Word16 *syn_12k8_16k_fx /* i : ACELP core synthesis at 12.8kHz or 16kHz (st_fx->Q_syn = 0) */ ) { - Word16 shb_SID_updt_fx=0; - TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; + Word16 shb_SID_updt_fx = 0; + TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; test(); - IF ( EQ_32(st_fx->core_brate, SID_2k40)||st_fx->core_brate==FRAME_NO_DATA) + IF( EQ_32( st_fx->core_brate, SID_2k40 ) || st_fx->core_brate == FRAME_NO_DATA ) { - IF (EQ_16(st_fx->cng_type,LP_CNG)) + IF( EQ_16( st_fx->cng_type, LP_CNG ) ) { - IF (GE_32(st_fx->input_Fs, L_FRAME32k * FRAMES_PER_SEC)) + IF( GE_32( st_fx->input_Fs, L_FRAME32k * FRAMES_PER_SEC ) ) { /* decide if SHB SID encoding or not */ - shb_SID_updt_fx = shb_DTX_fx(st_fx, shb_speech_fx, syn_12k8_16k_fx); + shb_SID_updt_fx = shb_DTX_fx( st_fx, shb_speech_fx, syn_12k8_16k_fx ); /* SHB CNG encoding */ - shb_CNG_encod_fx(st_fx, shb_SID_updt_fx); + shb_CNG_encod_fx( st_fx, shb_SID_updt_fx ); } - ELSE IF (EQ_16(st_fx->element_mode, IVAS_CPE_DFT) && EQ_32(st_fx->core_brate, SID_2k40)) + ELSE IF( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) && EQ_32( st_fx->core_brate, SID_2k40 ) ) { - //PMT("CNG IVAS_CPE_DFT code not implemented") + // PMT("CNG IVAS_CPE_DFT code not implemented") #ifdef IVAS_CODE /* LF-boost not used in DFT-stereo, instead the bandwidth is transmitted */ - delete_indice(st->hBstr, IND_CNG_ENV1); - push_indice(st->hBstr, IND_BWIDTH, st->bwidth, 2); - push_indice(st->hBstr, IND_UNUSED, 0, 4); - push_indice(st->hBstr, IND_SID_BW, 1, 1); + delete_indice( st->hBstr, IND_CNG_ENV1 ); + push_indice( st->hBstr, IND_BWIDTH, st->bwidth, 2 ); + push_indice( st->hBstr, IND_UNUSED, 0, 4 ); + push_indice( st->hBstr, IND_SID_BW, 1, 1 ); #endif } } @@ -1255,12 +1253,12 @@ void swb_CNG_enc_fx( * SID parameters encoding for SHB signal *---------------------------------------------------------------------*/ static void shb_CNG_encod_fx( - Encoder_State *st_fx, /* i/o: State structure */ - const Word16 update_fx /* i : SID update flag */ + Encoder_State *st_fx, /* i/o: State structure */ + const Word16 update_fx /* i : SID update flag */ ) { Word16 idx_ener_fx; - TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; + TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; BSTR_ENC_HANDLE hBstr = st_fx->hBstr; #ifdef IVAS_CODE Word16 ener_mid_dec_thr; @@ -1268,47 +1266,47 @@ static void shb_CNG_encod_fx( idx_ener_fx = 0; move16(); - IF ( EQ_16(update_fx, 1)) + IF( EQ_16( update_fx, 1 ) ) { /* SHB energy quantization */ - IF (EQ_16(st_fx->element_mode, EVS_MONO)) + IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) { - idx_ener_fx = shr(add(mult(hTdCngEnc->mov_shb_cng_ener_fx, 9797), 1510), 8); /* Q0 */ + idx_ener_fx = shr( add( mult( hTdCngEnc->mov_shb_cng_ener_fx, 9797 ), 1510 ), 8 ); /* Q0 */ } ELSE { /*idx_ener = (int16_t)(0.7f * (0.1f * st->hTdCngEnc->mov_shb_cng_ener / (float)log10(2.0f) + 6.0f) + 0.5f);*/ - //PMT("shb_CNG_encod_fx quantization in missing") + // PMT("shb_CNG_encod_fx quantization in missing") #if 0 idx_ener_fx = shr(add(mult(hTdCngEnc->mov_shb_cng_ener_fx, 9797), 1510), 8); /* Q0 */ #endif } - if ( LT_16(st_fx->bwidth, SWB)) + if ( LT_16( st_fx->bwidth, SWB ) ) { idx_ener_fx = 0; move16(); } - IF ( GT_16(idx_ener_fx, 15)) + IF( GT_16( idx_ener_fx, 15 ) ) { idx_ener_fx = 15; move16(); } ELSE { - idx_ener_fx = s_max(idx_ener_fx,0); + idx_ener_fx = s_max( idx_ener_fx, 0 ); } #ifdef IVAS_CODE - /* prevent toggling of idx_ener by adding small dead-zone interval around decision thresholds */ - if (st->element_mode != EVS_MONO) + /* prevent toggling of idx_ener by adding small dead-zone interval around decision thresholds */ + if ( st->element_mode != EVS_MONO ) { - if (abs(idx_ener - st->hTdCngEnc->last_idx_ener) == 1) + if ( abs( idx_ener - st->hTdCngEnc->last_idx_ener ) == 1 ) { - ener_mid_dec_thr = 0.5f * ((st->hTdCngEnc->last_idx_ener / 0.7f - 6.0f) / 0.1f) * (float)log10(2.0f); - ener_mid_dec_thr += 0.5f * ((idx_ener / 0.7f - 6.0f) / 0.1f) * (float)log10(2.0f); + ener_mid_dec_thr = 0.5f * ( ( st->hTdCngEnc->last_idx_ener / 0.7f - 6.0f ) / 0.1f ) * (float) log10( 2.0f ); + ener_mid_dec_thr += 0.5f * ( ( idx_ener / 0.7f - 6.0f ) / 0.1f ) * (float) log10( 2.0f ); - if (fabs(st->hTdCngEnc->mov_shb_cng_ener - ener_mid_dec_thr) / ener_mid_dec_thr < ENER_MID_DEAD_ZONE) + if ( fabs( st->hTdCngEnc->mov_shb_cng_ener - ener_mid_dec_thr ) / ener_mid_dec_thr < ENER_MID_DEAD_ZONE ) { idx_ener = st->hTdCngEnc->last_idx_ener; } @@ -1317,33 +1315,33 @@ static void shb_CNG_encod_fx( st->hTdCngEnc->last_idx_ener = idx_ener; #endif - push_indice_fx( hBstr, IND_SHB_CNG_GAIN, idx_ener_fx, 4); + push_indice_fx( hBstr, IND_SHB_CNG_GAIN, idx_ener_fx, 4 ); push_indice_fx( hBstr, IND_SID_BW, 1, 1 ); #ifndef IVAS_CODE - hBstr->nb_bits_tot_fx = sub(hBstr->nb_bits_tot_fx, hBstr->ind_list_fx[IND_CNG_ENV1].nb_bits); + hBstr->nb_bits_tot_fx = sub( hBstr->nb_bits_tot_fx, hBstr->ind_list_fx[IND_CNG_ENV1].nb_bits ); hBstr->ind_list_fx[IND_CNG_ENV1].nb_bits = -1; #else - delete_indice(hBstr, IND_CNG_ENV1); + delete_indice( hBstr, IND_CNG_ENV1 ); #endif move16(); #ifdef IVAS_CODE - if (st->element_mode == IVAS_CPE_DFT) + if ( st->element_mode == IVAS_CPE_DFT ) { - push_indice(st->hBstr, IND_BWIDTH, st->bwidth, 2); + push_indice( st->hBstr, IND_BWIDTH, st->bwidth, 2 ); } else #endif { - push_indice_fx(hBstr, IND_UNUSED, 0, 2); + push_indice_fx( hBstr, IND_UNUSED, 0, 2 ); } - hTdCngEnc->ho_sid_bw = L_shl(L_and(hTdCngEnc->ho_sid_bw, (Word32) 0x3fffffffL ), 1); - hTdCngEnc->ho_sid_bw = L_or(hTdCngEnc->ho_sid_bw, 0x1L); + hTdCngEnc->ho_sid_bw = L_shl( L_and( hTdCngEnc->ho_sid_bw, (Word32) 0x3fffffffL ), 1 ); + hTdCngEnc->ho_sid_bw = L_or( hTdCngEnc->ho_sid_bw, 0x1L ); } ELSE { - IF ( EQ_32(st_fx->core_brate, SID_2k40)) + IF( EQ_32( st_fx->core_brate, SID_2k40 ) ) { - hTdCngEnc->ho_sid_bw = L_shl(L_and(hTdCngEnc->ho_sid_bw, (Word32) 0x3fffffffL ), 1); + hTdCngEnc->ho_sid_bw = L_shl( L_and( hTdCngEnc->ho_sid_bw, (Word32) 0x3fffffffL ), 1 ); push_indice_fx( hBstr, IND_SID_BW, 0, 1 ); } } @@ -1352,19 +1350,19 @@ static void shb_CNG_encod_fx( } /*---------------------------------------------------------------------* -* shb_DTX() -* -* Decide if encoding SHB SID or not -*---------------------------------------------------------------------*/ + * shb_DTX() + * + * Decide if encoding SHB SID or not + *---------------------------------------------------------------------*/ static Word16 shb_DTX_fx( - Encoder_State *st_fx, /* i/o: State structure */ - const Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz (Q0) */ - const Word16 *syn_12k8_16k /* i : ACELP core synthesis at 12.8kHz or 16kHz (st_fx->Q_syn = 0) */ + Encoder_State *st_fx, /* i/o: State structure */ + const Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz (Q0) */ + const Word16 *syn_12k8_16k /* i : ACELP core synthesis at 12.8kHz or 16kHz (st_fx->Q_syn = 0) */ ) { Word16 i; Word16 update_fx; - Word16 shb_old_speech_fx[(ACELP_LOOK_12k8 + L_SUBFR + L_FRAME) * 5/4]; + Word16 shb_old_speech_fx[( ACELP_LOOK_12k8 + L_SUBFR + L_FRAME ) * 5 / 4]; Word16 *shb_new_speech_fx; Word32 wb_ener_fx; Word32 shb_ener_fx; @@ -1373,79 +1371,79 @@ static Word16 shb_DTX_fx( Word16 tmp; Word16 exp; Word16 fra; - Word16 att; /*Q8*/ - Word16 allow_cn_step_fx=0; - DTX_ENC_HANDLE hDtxEnc = st_fx->hDtxEnc; - TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; + Word16 att; /*Q8*/ + Word16 allow_cn_step_fx = 0; + DTX_ENC_HANDLE hDtxEnc = st_fx->hDtxEnc; + TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - shb_new_speech_fx = shb_old_speech_fx + (ACELP_LOOK_12k8 + L_SUBFR) * 5/4; - Copy(hBWE_TD->old_speech_shb_fx, shb_old_speech_fx, (ACELP_LOOK_12k8 + L_SUBFR) * 5/4 ); + shb_new_speech_fx = shb_old_speech_fx + ( ACELP_LOOK_12k8 + L_SUBFR ) * 5 / 4; + Copy( hBWE_TD->old_speech_shb_fx, shb_old_speech_fx, ( ACELP_LOOK_12k8 + L_SUBFR ) * 5 / 4 ); Copy( shb_speech_fx, shb_new_speech_fx, L_FRAME16k ); - Copy( shb_old_speech_fx + L_FRAME16k, hBWE_TD->old_speech_shb_fx, (ACELP_LOOK_12k8 + L_SUBFR) * 5/4 ); + Copy( shb_old_speech_fx + L_FRAME16k, hBWE_TD->old_speech_shb_fx, ( ACELP_LOOK_12k8 + L_SUBFR ) * 5 / 4 ); - shb_ener_fx = L_deposit_l(0); - FOR ( i=0; iL_frame; i++ ) + wb_ener_fx = L_deposit_l( 0 ); + FOR( i = 0; i < st_fx->L_frame; i++ ) { #ifdef BASOP_NOGLOB - wb_ener_fx = L_mac_o(wb_ener_fx, syn_12k8_16k[i], syn_12k8_16k[i], &Overflow); + wb_ener_fx = L_mac_o( wb_ener_fx, syn_12k8_16k[i], syn_12k8_16k[i], &Overflow ); #else - wb_ener_fx = L_mac(wb_ener_fx, syn_12k8_16k[i], syn_12k8_16k[i]); + wb_ener_fx = L_mac( wb_ener_fx, syn_12k8_16k[i], syn_12k8_16k[i] ); #endif } - wb_ener_fx = L_add(Mpy_32_16_1(wb_ener_fx, 128), 1); /* 128 in Q15, wb_ener_fx in Q1 */ + wb_ener_fx = L_add( Mpy_32_16_1( wb_ener_fx, 128 ), 1 ); /* 128 in Q15, wb_ener_fx in Q1 */ - exp = norm_l(wb_ener_fx); - fra = Log2_norm_lc(L_shl(wb_ener_fx, exp)); - exp = sub(30-1, exp); - wb_ener_fx = Mpy_32_16(exp, fra, LG10); + exp = norm_l( wb_ener_fx ); + fra = Log2_norm_lc( L_shl( wb_ener_fx, exp ) ); + exp = sub( 30 - 1, exp ); + wb_ener_fx = Mpy_32_16( exp, fra, LG10 ); #ifdef BASOP_NOGLOB - log_wb_ener_fx = round_fx_o(L_shl_o(wb_ener_fx, 10, &Overflow), &Overflow); /* log_wb_ener_fx in Q8 */ + log_wb_ener_fx = round_fx_o( L_shl_o( wb_ener_fx, 10, &Overflow ), &Overflow ); /* log_wb_ener_fx in Q8 */ #else - log_wb_ener_fx = round_fx(L_shl(wb_ener_fx, 10)); /* log_wb_ener_fx in Q8 */ + log_wb_ener_fx = round_fx( L_shl( wb_ener_fx, 10 ) ); /* log_wb_ener_fx in Q8 */ #endif - exp = norm_l(shb_ener_fx); - fra = Log2_norm_lc(L_shl(shb_ener_fx, exp)); - exp = sub(30-1, exp); - shb_ener_fx = Mpy_32_16(exp, fra, LG10); + exp = norm_l( shb_ener_fx ); + fra = Log2_norm_lc( L_shl( shb_ener_fx, exp ) ); + exp = sub( 30 - 1, exp ); + shb_ener_fx = Mpy_32_16( exp, fra, LG10 ); test(); - IF (EQ_16(st_fx->element_mode, IVAS_SCE) || EQ_16(st_fx->element_mode, IVAS_CPE_DFT)) + IF( EQ_16( st_fx->element_mode, IVAS_SCE ) || EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) ) { att = 0; move16(); - //PMT("apply_scale is not implemented") + // PMT("apply_scale is not implemented") #if 0 apply_scale(&att, st->hFdCngEnc->hFdCngCom->CngBandwidth, st->hFdCngEnc->hFdCngCom->CngBitrate, scaleTableStereo, SIZE_SCALE_TABLE_STEREO); #endif } else { - att = 1664; /*6.5 in Q8*/ + att = 1664; /*6.5 in Q8*/ move16(); } #ifdef BASOP_NOGLOB - log_shb_ener_fx = sub_o(round_fx_o(L_shl_o(shb_ener_fx, 10, &Overflow), &Overflow), att, &Overflow); /* log_shb_ener_fx in Q8 */ + log_shb_ener_fx = sub_o( round_fx_o( L_shl_o( shb_ener_fx, 10, &Overflow ), &Overflow ), att, &Overflow ); /* log_shb_ener_fx in Q8 */ #else - log_shb_ener_fx = sub(round_fx(L_shl(shb_ener_fx, 10)), att); /* log_shb_ener_fx in Q8 */ + log_shb_ener_fx = sub( round_fx( L_shl( shb_ener_fx, 10 ) ), att ); /* log_shb_ener_fx in Q8 */ #endif - IF (hDtxEnc->first_CNG == 0 ) + IF( hDtxEnc->first_CNG == 0 ) { hTdCngEnc->mov_wb_cng_ener_fx = log_wb_ener_fx; move16(); @@ -1457,19 +1455,19 @@ static Word16 shb_DTX_fx( move16(); } - if ( GT_16(abs_s(sub(log_wb_ener_fx, hTdCngEnc->mov_wb_cng_ener_fx)), 3072)) + if ( GT_16( abs_s( sub( log_wb_ener_fx, hTdCngEnc->mov_wb_cng_ener_fx ) ), 3072 ) ) { allow_cn_step_fx = 1; move16(); } #ifdef IVAS_CODE /* Also allow step if shb energy has dropped 12 dB */ - if ((st->element_mode == IVAS_CPE_DFT || st->element_mode == IVAS_CPE_TD) && ((hTdCngEnc->mov_shb_cng_ener - log_shb_ener) > 12.0f)) + if ( ( st->element_mode == IVAS_CPE_DFT || st->element_mode == IVAS_CPE_TD ) && ( ( hTdCngEnc->mov_shb_cng_ener - log_shb_ener ) > 12.0f ) ) { allow_cn_step = 1; } #endif - IF ( EQ_16(allow_cn_step_fx, 1)) + IF( EQ_16( allow_cn_step_fx, 1 ) ) { hTdCngEnc->mov_wb_cng_ener_fx = log_wb_ener_fx; move16(); @@ -1478,38 +1476,38 @@ static Word16 shb_DTX_fx( } ELSE { - tmp = sub(log_wb_ener_fx, hTdCngEnc->mov_wb_cng_ener_fx); /* Q8 */ - tmp = mult(tmp, 29491); /* Q8 */ - hTdCngEnc->mov_wb_cng_ener_fx = add(hTdCngEnc->mov_wb_cng_ener_fx, tmp); /* Q8 */ + tmp = sub( log_wb_ener_fx, hTdCngEnc->mov_wb_cng_ener_fx ); /* Q8 */ + tmp = mult( tmp, 29491 ); /* Q8 */ + hTdCngEnc->mov_wb_cng_ener_fx = add( hTdCngEnc->mov_wb_cng_ener_fx, tmp ); /* Q8 */ - tmp = sub(log_shb_ener_fx, hTdCngEnc->mov_shb_cng_ener_fx); - tmp = mult(tmp, 8192); /* Q8 */ - hTdCngEnc->mov_shb_cng_ener_fx = add(hTdCngEnc->mov_shb_cng_ener_fx, tmp); /* Q8 */ + tmp = sub( log_shb_ener_fx, hTdCngEnc->mov_shb_cng_ener_fx ); + tmp = mult( tmp, 8192 ); /* Q8 */ + hTdCngEnc->mov_shb_cng_ener_fx = add( hTdCngEnc->mov_shb_cng_ener_fx, tmp ); /* Q8 */ } - hTdCngEnc->shb_NO_DATA_cnt = add(hTdCngEnc->shb_NO_DATA_cnt, 1); + hTdCngEnc->shb_NO_DATA_cnt = add( hTdCngEnc->shb_NO_DATA_cnt, 1 ); update_fx = 0; move16(); - IF ( EQ_32(st_fx->core_brate, SID_2k40)) + IF( EQ_32( st_fx->core_brate, SID_2k40 ) ) { test(); test(); - IF (hDtxEnc->first_CNG == 0 || EQ_16(hTdCngEnc->last_vad, 1)||GE_16(hTdCngEnc->shb_NO_DATA_cnt,100)) + IF( hDtxEnc->first_CNG == 0 || EQ_16( hTdCngEnc->last_vad, 1 ) || GE_16( hTdCngEnc->shb_NO_DATA_cnt, 100 ) ) { update_fx = 1; move16(); } ELSE { - IF ( hTdCngEnc->shb_cng_ini_cnt > 0 ) + IF( hTdCngEnc->shb_cng_ini_cnt > 0 ) { update_fx = 1; move16(); - hTdCngEnc->shb_cng_ini_cnt = sub(hTdCngEnc->shb_cng_ini_cnt, 1); + hTdCngEnc->shb_cng_ini_cnt = sub( hTdCngEnc->shb_cng_ini_cnt, 1 ); } ELSE { - IF ( GT_16(abs_s(sub(sub(hTdCngEnc->mov_wb_cng_ener_fx, hTdCngEnc->mov_shb_cng_ener_fx), sub(hTdCngEnc->last_wb_cng_ener_fx, hTdCngEnc->last_shb_cng_ener_fx))), 768)) + IF( GT_16( abs_s( sub( sub( hTdCngEnc->mov_wb_cng_ener_fx, hTdCngEnc->mov_shb_cng_ener_fx ), sub( hTdCngEnc->last_wb_cng_ener_fx, hTdCngEnc->last_shb_cng_ener_fx ) ) ), 768 ) ) { update_fx = 1; move16(); @@ -1517,7 +1515,7 @@ static Word16 shb_DTX_fx( ELSE { test(); - IF ( GE_16(st_fx->bwidth, SWB)&<_16(hTdCngEnc->last_SID_bwidth,SWB)) + IF( GE_16( st_fx->bwidth, SWB ) && LT_16( hTdCngEnc->last_SID_bwidth, SWB ) ) { update_fx = 1; move16(); @@ -1525,7 +1523,7 @@ static Word16 shb_DTX_fx( ELSE { test(); - IF ( LT_16(st_fx->bwidth, SWB)&&GE_16(hTdCngEnc->last_SID_bwidth,SWB)) + IF( LT_16( st_fx->bwidth, SWB ) && GE_16( hTdCngEnc->last_SID_bwidth, SWB ) ) { update_fx = 1; move16(); @@ -1539,14 +1537,15 @@ static Word16 shb_DTX_fx( move16(); } /* LF-boost not yet implemented in decoder which means that the specific wb_sid information is not used */ - test();test(); - if ((EQ_16(st_fx->element_mode, IVAS_CPE_DFT) || EQ_16(st_fx->element_mode, IVAS_CPE_TD)) && EQ_32(st_fx->core_brate, SID_2k40)) + test(); + test(); + if ( ( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) && EQ_32( st_fx->core_brate, SID_2k40 ) ) { update_fx = 1; move16(); } - IF ( EQ_16(update_fx, 1)) + IF( EQ_16( update_fx, 1 ) ) { hTdCngEnc->last_wb_cng_ener_fx = hTdCngEnc->mov_wb_cng_ener_fx; move16(); @@ -1557,7 +1556,7 @@ static Word16 shb_DTX_fx( } - return (update_fx); + return ( update_fx ); } /*---------------------------------------------------------------------* @@ -1567,45 +1566,45 @@ static Word16 shb_DTX_fx( *---------------------------------------------------------------------*/ void calculate_hangover_attenuation_gain_fx( - Encoder_State* st, /* i : encoder state structure */ - Word16* att, /* o : attenuation factor */ - const Word16 vad_hover_flag /* i : VAD hangover flag */ + Encoder_State *st, /* i : encoder state structure */ + Word16 *att, /* o : attenuation factor */ + const Word16 vad_hover_flag /* i : VAD hangover flag */ ) { Word16 offset; - TD_CNG_ENC_HANDLE hTdCngEnc = st->hTdCngEnc; + TD_CNG_ENC_HANDLE hTdCngEnc = st->hTdCngEnc; *att = 32767; move16(); /* smoothing in case of CNG */ - IF (hTdCngEnc != NULL) + IF( hTdCngEnc != NULL ) { - test();test();test(); - IF( hTdCngEnc->burst_ho_cnt > 0 && (vad_hover_flag != 0) && (NE_16(st->bwidth, NB) || GT_16(st->element_mode, EVS_MONO))) /* corresponds to line 504 in FLT acelp_core_enc.c */ + test(); + test(); + test(); + IF( hTdCngEnc->burst_ho_cnt > 0 && ( vad_hover_flag != 0 ) && ( NE_16( st->bwidth, NB ) || GT_16( st->element_mode, EVS_MONO ) ) ) /* corresponds to line 504 in FLT acelp_core_enc.c */ { #ifdef IVAS_CODE - if (st->element_mode == IVAS_CPE_DFT || st->element_mode == IVAS_CPE_TD) + if ( st->element_mode == IVAS_CPE_DFT || st->element_mode == IVAS_CPE_TD ) { - *att = powf(10.0f, (st->hTdCngEnc->CNG_att / 160.0f) * st->hTdCngEnc->burst_ho_cnt); + *att = powf( 10.0f, ( st->hTdCngEnc->CNG_att / 160.0f ) * st->hTdCngEnc->burst_ho_cnt ); } else #endif { offset = 5; test(); - if (EQ_16(st->bwidth, WB) && st->hDtxEnc->CNG_mode >= 0) + if ( EQ_16( st->bwidth, WB ) && st->hDtxEnc->CNG_mode >= 0 ) { offset = st->hDtxEnc->CNG_mode; move16(); } - assert(hTdCngEnc->burst_ho_cnt > 0); - *att = CNG_burst_att_fx[offset][sub(hTdCngEnc->burst_ho_cnt, 1)]; /*Q15*/ + assert( hTdCngEnc->burst_ho_cnt > 0 ); + *att = CNG_burst_att_fx[offset][sub( hTdCngEnc->burst_ho_cnt, 1 )]; /*Q15*/ move16(); } } - - } return; } diff --git a/lib_enc/cod2t32_fx.c b/lib_enc/cod2t32_fx.c index dfbe4806e..afb4d7ff3 100644 --- a/lib_enc/cod2t32_fx.c +++ b/lib_enc/cod2t32_fx.c @@ -2,46 +2,46 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Common constants */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Common constants */ //#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* -* Local Constants -*-------------------------------------------------------------------*/ + * Local Constants + *-------------------------------------------------------------------*/ -#define STEP 2 -#define MSIZE 1024 +#define STEP 2 +#define MSIZE 1024 /*---------------------------------------------------------------------------------- -* Function acelp_2t32() -* -* 12 bits algebraic codebook. -* 2 tracks x 32 positions per track = 64 samples. -* -* 12 bits --> 2 pulses in a frame of 64 samples. -* -* All pulses can have two (2) possible amplitudes: +1 or -1. -* Each pulse can have 32 possible positions. -*----------------------------------------------------------------------------------*/ + * Function acelp_2t32() + * + * 12 bits algebraic codebook. + * 2 tracks x 32 positions per track = 64 samples. + * + * 12 bits --> 2 pulses in a frame of 64 samples. + * + * All pulses can have two (2) possible amplitudes: +1 or -1. + * Each pulse can have 32 possible positions. + *----------------------------------------------------------------------------------*/ void acelp_2t32_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 dn[], /* i : corr. between target and h[]. */ - const Word16 h[], /* i : impulse response of weighted synthesis filter */ - Word16 code[], /* o : algebraic (fixed) codebook excitation */ - Word16 y[] /* o : filtered fixed codebook excitation */ + const Word16 dn[], /* i : corr. between target and h[]. */ + const Word16 h[], /* i : impulse response of weighted synthesis filter */ + Word16 code[], /* o : algebraic (fixed) codebook excitation */ + Word16 y[] /* o : filtered fixed codebook excitation */ ) { - Word16 i, j, k, i0, i1, ix, iy, pos, pos2, sign0, sign1,index; + Word16 i, j, k, i0, i1, ix, iy, pos, pos2, sign0, sign1, index; Word16 ps1, ps2, alpk, alp1, alp2; - Word16 sq,psk; + Word16 sq, psk; Word16 pol[L_SUBFR], dn_p[L_SUBFR]; - Word16 ii,jj; + Word16 ii, jj; Word16 *p0, *p1, *p2; const Word16 *ptr_h1, *ptr_h2, *ptr_hf; @@ -64,25 +64,25 @@ void acelp_2t32_fx( ptr_h1 = h; move16(); - L_cor = L_deposit_h(1); - FOR (i = 0; i < NB_POS_FCB_2T; i++) + L_cor = L_deposit_h( 1 ); + FOR( i = 0; i < NB_POS_FCB_2T; i++ ) { #ifdef BASOP_NOGLOB - L_cor = L_mac_o(L_cor, *ptr_h1, *ptr_h1, &Overflow); + L_cor = L_mac_o( L_cor, *ptr_h1, *ptr_h1, &Overflow ); #else - L_cor = L_mac(L_cor, *ptr_h1, *ptr_h1); + L_cor = L_mac( L_cor, *ptr_h1, *ptr_h1 ); #endif ptr_h1++; - *p1-- = extract_h(L_cor); - move16(); /*Q9 Q7*/ + *p1-- = extract_h( L_cor ); + move16(); /*Q9 Q7*/ #ifdef BASOP_NOGLOB - L_cor = L_mac_o(L_cor, *ptr_h1, *ptr_h1, &Overflow); + L_cor = L_mac_o( L_cor, *ptr_h1, *ptr_h1, &Overflow ); #else - L_cor = L_mac(L_cor, *ptr_h1, *ptr_h1); + L_cor = L_mac( L_cor, *ptr_h1, *ptr_h1 ); #endif ptr_h1++; - *p0-- = extract_h(L_cor); - move16(); /*Q9 Q7*/ + *p0-- = extract_h( L_cor ); + move16(); /*Q9 Q7*/ } p0 = rrixix[0]; @@ -90,19 +90,19 @@ void acelp_2t32_fx( p1 = rrixix[1]; move16(); - FOR (i = 0; i < NB_POS_FCB_2T; i++) + FOR( i = 0; i < NB_POS_FCB_2T; i++ ) { - *p0 = shr(*p0, 1); + *p0 = shr( *p0, 1 ); move16(); p0++; - *p1 = shr(*p1, 1); + *p1 = shr( *p1, 1 ); move16(); p1++; } /*------------------------------------------------------------* - * Compute rrixiy[][] needed for the codebook search. - *------------------------------------------------------------*/ + * Compute rrixiy[][] needed for the codebook search. + *------------------------------------------------------------*/ pos = MSIZE - 1; move16(); @@ -111,7 +111,7 @@ void acelp_2t32_fx( ptr_hf = h + 1; move16(); - FOR (k = 0; k < NB_POS_FCB_2T; k++) + FOR( k = 0; k < NB_POS_FCB_2T; k++ ) { /* Init pointers to last position of diagonals */ p1 = &rrixiy[pos]; @@ -124,33 +124,33 @@ void acelp_2t32_fx( ptr_h2 = ptr_hf; move16(); - L_cor = L_mult(*ptr_h1++, *ptr_h2++); - FOR (i = k; i < NB_POS_FCB_2T-1; i++) + L_cor = L_mult( *ptr_h1++, *ptr_h2++ ); + FOR( i = k; i < NB_POS_FCB_2T - 1; i++ ) { #ifdef BASOP_NOGLOB - * p1 = round_fx_o(L_cor, &Overflow); - L_cor = L_mac_o(L_cor, *ptr_h1++, *ptr_h2++, &Overflow); + *p1 = round_fx_o( L_cor, &Overflow ); + L_cor = L_mac_o( L_cor, *ptr_h1++, *ptr_h2++, &Overflow ); #else - * p1 = round_fx(L_cor); - L_cor = L_mac(L_cor, *ptr_h1++, *ptr_h2++); + *p1 = round_fx( L_cor ); + L_cor = L_mac( L_cor, *ptr_h1++, *ptr_h2++ ); #endif #ifdef BASOP_NOGLOB - * p0 = round_fx_o(L_cor, &Overflow); - L_cor = L_mac_o(L_cor, *ptr_h1++, *ptr_h2++, &Overflow); + *p0 = round_fx_o( L_cor, &Overflow ); + L_cor = L_mac_o( L_cor, *ptr_h1++, *ptr_h2++, &Overflow ); #else - * p0 = round_fx(L_cor); - L_cor = L_mac(L_cor, *ptr_h1++, *ptr_h2++); + *p0 = round_fx( L_cor ); + L_cor = L_mac( L_cor, *ptr_h1++, *ptr_h2++ ); #endif - p1 -= (NB_POS_FCB_2T + 1); + p1 -= ( NB_POS_FCB_2T + 1 ); move16(); - p0 -= (NB_POS_FCB_2T + 1); + p0 -= ( NB_POS_FCB_2T + 1 ); move16(); } #ifdef BASOP_NOGLOB - *p1 = round_fx_o(L_cor, &Overflow); + *p1 = round_fx_o( L_cor, &Overflow ); #else - *p1 = round_fx(L_cor); + *p1 = round_fx( L_cor ); #endif pos -= NB_POS_FCB_2T; move16(); @@ -163,28 +163,28 @@ void acelp_2t32_fx( * computing reference vector and pre-selection of polarities *----------------------------------------------------------------*/ - L_tmp = L_deposit_h(dn[0]); - FOR(i=0; i=0) + IF( L_tmp >= 0 ) { pol[i] = 1; move16(); @@ -195,7 +195,7 @@ void acelp_2t32_fx( { pol[i] = -1; move16(); - dn_p[i] = negate(dn[i]); + dn_p[i] = negate( dn[i] ); move16(); } } @@ -204,33 +204,33 @@ void acelp_2t32_fx( * compute denominator ( multiplied by polarity ) *----------------------------------------------------------------*/ - k=0; - ii=0; + k = 0; + ii = 0; move16(); move16(); - FOR(i=0; i 0) + IF( s > 0 ) { psk = sq; move16(); @@ -282,7 +282,7 @@ void acelp_2t32_fx( p1 -= NB_POS_FCB_2T; move16(); - IF (pos >= 0) + IF( pos >= 0 ) { ix = i0; move16(); @@ -291,15 +291,15 @@ void acelp_2t32_fx( } } - i0 = shr(ix,1); - i1 = shr(iy,1); + i0 = shr( ix, 1 ); + i1 = shr( iy, 1 ); - sign0 = shl(pol[ix],9); - sign1 = shl(pol[iy],9); + sign0 = shl( pol[ix], 9 ); + sign1 = shl( pol[iy], 9 ); /*-------------------------------------------------------------------* - * Build the codeword, the filtered codeword and index of codevector. - *-------------------------------------------------------------------*/ + * Build the codeword, the filtered codeword and index of codevector. + *-------------------------------------------------------------------*/ set16_fx( code, 0, L_SUBFR ); @@ -308,32 +308,32 @@ void acelp_2t32_fx( code[iy] = sign1; move16(); - index = add(shl(i0, 6), i1); + index = add( shl( i0, 6 ), i1 ); - if (sign0 < 0) + if ( sign0 < 0 ) { - index = add(index, 0x800); + index = add( index, 0x800 ); } - if (sign1 < 0) + if ( sign1 < 0 ) { - index = add(index, 0x20); /* move16();*/ + index = add( index, 0x20 ); /* move16();*/ } set16_fx( y, 0, L_SUBFR ); /* y_Q9 = sign_Q9<<3 * h_Q12 */ - sign0 = shl(sign0, 3); - sign1 = shl(sign1, 3); + sign0 = shl( sign0, 3 ); + sign1 = shl( sign1, 3 ); - FOR(i=ix; i0) + IF( sgn > 0 ) { - y[i] = shr_r(h[i-pos],3); + y[i] = shr_r( h[i - pos], 3 ); move16(); } ELSE { - y[i] = negate(shr_r(h[i-pos],3)); + y[i] = negate( shr_r( h[i - pos], 3 ) ); move16(); } } index = pos; move16(); - if( sgn > 0 ) + if ( sgn > 0 ) { - index = add(index,L_subfr); + index = add( index, L_subfr ); } - IF (EQ_16(L_subfr, L_SUBFR) ) + IF( EQ_16( L_subfr, L_SUBFR ) ) { push_indice_fx( hBstr, IND_ALG_CDBK_1T64, index, 7 ); } ELSE /* L_subfr == 2*L_SUBFR */ { - push_indice_fx(hBstr, IND_ALG_CDBK_1T64, index, 8); + push_indice_fx( hBstr, IND_ALG_CDBK_1T64, index, 8 ); } return; diff --git a/lib_enc/cod4t64.c b/lib_enc/cod4t64.c index cbcf0adf4..88bbc93ec 100644 --- a/lib_enc/cod4t64.c +++ b/lib_enc/cod4t64.c @@ -117,8 +117,8 @@ int16_t acelp_4t64( config.nbpos[1] = 8; break; - case 28: /* EVS pulse indexing: 28 bits, 6 pulses, 4 tracks */ - config.nbiter = 4; /* 4x20x16=1280 loops */ + case 28: /* EVS pulse indexing: 28 bits, 6 pulses, 4 tracks */ + config.nbiter = 4; /* 4x20x16=1280 loops */ config.alp_flt = 1.0f; /* coeff for sign setting */ config.nb_pulse = 6; config.fixedpulses = 0; @@ -127,8 +127,8 @@ int16_t acelp_4t64( config.nbpos[2] = 8; break; - case 36: /* EVS/AMR-WB pulse indexing: 36 bits, 8 pulses, 4 tracks */ - config.nbiter = 4; /* 4x20x16=1280 loops */ + case 36: /* EVS/AMR-WB pulse indexing: 36 bits, 8 pulses, 4 tracks */ + config.nbiter = 4; /* 4x20x16=1280 loops */ config.alp_flt = 1.0f; /* coeff for sign setting */ config.nb_pulse = 8; config.fixedpulses = 2; diff --git a/lib_enc/cod4t64_fx.c b/lib_enc/cod4t64_fx.c index cb272c771..43d1e6434 100644 --- a/lib_enc/cod4t64_fx.c +++ b/lib_enc/cod4t64_fx.c @@ -2,295 +2,294 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* VMR-WB compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_enc.h" /* Encoder static table prototypes */ +#include "options.h" /* VMR-WB compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_enc.h" /* Encoder static table prototypes */ //#include "prot_fx.h" /* Function prototypes */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "rom_com_fx.h" /* Static table prototypes */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* * Local constants *-------------------------------------------------------------------*/ -#define STEP 4 -#define MSIZE 256 -#define NB_MAX 8 +#define STEP 4 +#define MSIZE 256 +#define NB_MAX 8 /*-------------------------------------------------------------------* * Local function prototypes *-------------------------------------------------------------------*/ -static Word16 quant_1p_N1_fx(const Word16 pos,const Word16 N); -static Word16 quant_2p_2N1_fx(const Word16 pos1, const Word16 pos2, const Word16 N); +static Word16 quant_1p_N1_fx( const Word16 pos, const Word16 N ); +static Word16 quant_2p_2N1_fx( const Word16 pos1, const Word16 pos2, const Word16 N ); static Word16 quant_3p_3N1_fx( const Word16 pos1, const Word16 pos2, const Word16 pos3, const Word16 N ); static Word32 quant_4p_4N_fx( const Word16 pos[], const Word16 N ); static Word32 quant_5p_5N_fx( const Word16 pos[], const Word16 N ); static Word32 quant_6p_6N_2_fx( const Word16 pos[], const Word16 N ); - -static Word32 fcb_encode_position_fx(const Word16 pos_vector[],Word32 n, const Word32 pos_num, const Word32 flag); -static Word32 fcb_encode_class_fx(const Word32 sector_6p_num[], const Word32 pulse_num, const Word32 pulse_pos_num); -static Word32 fcb_encode_PI_fx(const Word16 v[], const Word32 pulse_num); +static Word32 fcb_encode_position_fx( const Word16 pos_vector[], Word32 n, const Word32 pos_num, const Word32 flag ); +static Word32 fcb_encode_class_fx( const Word32 sector_6p_num[], const Word32 pulse_num, const Word32 pulse_pos_num ); +static Word32 fcb_encode_PI_fx( const Word16 v[], const Word32 pulse_num ); static Word32 pre_process_fx( const Word16 v[], Word16 sector_6p[], Word32 sector_6p_num[], Word32 *pulse_pos_num ); /*---------------------------------------------------------------------* - * ACELP_4t64() - * - * 20, 36, 44, 52, 64, 72, 88 bits algebraic codebook. - * 4 tracks x 16 positions per track = 64 samples. - * - * 20 bits --> 4 pulses in a frame of 64 samples. - * 36 bits --> 8 pulses in a frame of 64 samples. - * 44 bits 13 + 9 + 13 + 9 --> 10 pulses in a frame of 64 samples. - * 52 bits 13 + 13 + 13 + 13 --> 12 pulses in a frame of 64 samples. - * 64 bits 2 + 2 + 2 + 2 + 14 + 14 + 14 + 14 --> - * 16 pulses in a frame of 64 samples. - * 72 bits 10 + 2 + 10 + 2 + 10 + 14 + 10 + 14 --> - * 18 pulses in a frame of 64 samples. - * 88 bits 11 + 11 + 11 + 11 + 11 + 11 + 11 + 11 --> - * 24 pulses in a frame of 64 samples. - * All pulses can have two (2) possible amplitudes: +1 or -1. - * Each pulse can have sixteen (16) possible positions. - *---------------------------------------------------------------------*/ + * ACELP_4t64() + * + * 20, 36, 44, 52, 64, 72, 88 bits algebraic codebook. + * 4 tracks x 16 positions per track = 64 samples. + * + * 20 bits --> 4 pulses in a frame of 64 samples. + * 36 bits --> 8 pulses in a frame of 64 samples. + * 44 bits 13 + 9 + 13 + 9 --> 10 pulses in a frame of 64 samples. + * 52 bits 13 + 13 + 13 + 13 --> 12 pulses in a frame of 64 samples. + * 64 bits 2 + 2 + 2 + 2 + 14 + 14 + 14 + 14 --> + * 16 pulses in a frame of 64 samples. + * 72 bits 10 + 2 + 10 + 2 + 10 + 14 + 10 + 14 --> + * 18 pulses in a frame of 64 samples. + * 88 bits 11 + 11 + 11 + 11 + 11 + 11 + 11 + 11 --> + * 24 pulses in a frame of 64 samples. + * All pulses can have two (2) possible amplitudes: +1 or -1. + * Each pulse can have sixteen (16) possible positions. + *---------------------------------------------------------------------*/ Word16 acelp_4t64_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - Word16 dn[], /* i : corr. between target and h[]. */ - const Word16 cn[], /* i : residual after long term prediction Q_new*/ - const Word16 H[], /* i : impulse response of weighted synthesis filter Q12*/ - Word16 R[], /* i : autocorrelation values */ - const Word16 acelpautoc, /* i : autocorrealtion flag */ - Word16 code[], /* o : algebraic (fixed) codebook excitation Q9*/ - Word16 y[], /* o : filtered fixed codebook excitation Q9*/ - Word16 nbbits, /* i : number of bits per codebook */ - const Word16 cmpl_flag, /* i : complexity reduction flag */ - const Word16 Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 dn[], /* i : corr. between target and h[]. */ + const Word16 cn[], /* i : residual after long term prediction Q_new*/ + const Word16 H[], /* i : impulse response of weighted synthesis filter Q12*/ + Word16 R[], /* i : autocorrelation values */ + const Word16 acelpautoc, /* i : autocorrealtion flag */ + Word16 code[], /* o : algebraic (fixed) codebook excitation Q9*/ + Word16 y[], /* o : filtered fixed codebook excitation Q9*/ + Word16 nbbits, /* i : number of bits per codebook */ + const Word16 cmpl_flag, /* i : complexity reduction flag */ + const Word16 Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ ) { Word16 i, k, index, track; Word32 L_index; - Word16 ind[NPMAXPT*NB_TRACK_FCB_4T+32]; /* VE3: why +32 ???*/ - Word16 codvec[NB_PULSE_MAX+4]= {0}; + Word16 ind[NPMAXPT * NB_TRACK_FCB_4T + 32]; /* VE3: why +32 ???*/ + Word16 codvec[NB_PULSE_MAX + 4] = { 0 }; Word16 saved_bits = 0; PulseConfig config; Word16 indexing_indices[6], wordcnt, bitcnt; - set16_fx(codvec, 0, NB_PULSE_MAX+4); - SWITCH (nbbits) + set16_fx( codvec, 0, NB_PULSE_MAX + 4 ); + SWITCH( nbbits ) { - case 20: /* EVS/AMR-WB pulse indexing: 20 bits, 4 pulses, 4 tracks */ - config.nbiter = 4; - move16(); /* 4x12x16=768 loop */ - config.alp = 16384; - move16(); /* 2 in Q13*/ - config.nb_pulse = 4; - move16(); - config.fixedpulses = 0; - move16(); - config.nbpos[0] = 4; - move16(); - config.nbpos[1] = 8; - move16(); - BREAK; - - case 28: /* EVS pulse indexing: 28 bits, 6 pulses, 4 tracks */ - config.nbiter = 4; - move16(); /* 4x20x16=1280 loops */ - config.alp = 8192; - move16(); /* coeff FOR sign setting */ - config.nb_pulse = 6; - move16(); - config.fixedpulses = 0; - move16(); - config.nbpos[0] = 6; - move16(); - config.nbpos[1] = 6; - move16(); - config.nbpos[2] = 8; - move16(); - BREAK; - - case 36: /* EVS/AMR-WB pulse indexing: 36 bits, 8 pulses, 4 tracks */ - config.nbiter = 4; - move16(); /* 4x20x16=1280 loops */ - config.alp = 8192; - move16(); /* coeff FOR sign setting */ - config.nb_pulse = 8; - move16(); - config.fixedpulses = 2; - move16(); - config.nbpos[0] = 4; - move16(); - config.nbpos[1] = 8; - move16(); - config.nbpos[2] = 8; - move16(); - BREAK; + case 20: /* EVS/AMR-WB pulse indexing: 20 bits, 4 pulses, 4 tracks */ + config.nbiter = 4; + move16(); /* 4x12x16=768 loop */ + config.alp = 16384; + move16(); /* 2 in Q13*/ + config.nb_pulse = 4; + move16(); + config.fixedpulses = 0; + move16(); + config.nbpos[0] = 4; + move16(); + config.nbpos[1] = 8; + move16(); + BREAK; + + case 28: /* EVS pulse indexing: 28 bits, 6 pulses, 4 tracks */ + config.nbiter = 4; + move16(); /* 4x20x16=1280 loops */ + config.alp = 8192; + move16(); /* coeff FOR sign setting */ + config.nb_pulse = 6; + move16(); + config.fixedpulses = 0; + move16(); + config.nbpos[0] = 6; + move16(); + config.nbpos[1] = 6; + move16(); + config.nbpos[2] = 8; + move16(); + BREAK; + + case 36: /* EVS/AMR-WB pulse indexing: 36 bits, 8 pulses, 4 tracks */ + config.nbiter = 4; + move16(); /* 4x20x16=1280 loops */ + config.alp = 8192; + move16(); /* coeff FOR sign setting */ + config.nb_pulse = 8; + move16(); + config.fixedpulses = 2; + move16(); + config.nbpos[0] = 4; + move16(); + config.nbpos[1] = 8; + move16(); + config.nbpos[2] = 8; + move16(); + BREAK; - case 43: /* EVS pulse indexing: 43 bits, 10 pulses, 4 tracks */ - case 44: /* AMR-WB pulse indexing: 44 bits, 10 pulses, 4 tracks */ - config.nbiter = 4; - move16(); /* 4x26x16=1664 loops */ - config.alp = 8192; - move16(); - config.nb_pulse = 10; - move16(); - config.fixedpulses = 2; - move16(); - config.nbpos[0] = 4; - move16(); - config.nbpos[1] = 6; - move16(); - config.nbpos[2] = 8; - move16(); - config.nbpos[3] = 8; - move16(); - BREAK; + case 43: /* EVS pulse indexing: 43 bits, 10 pulses, 4 tracks */ + case 44: /* AMR-WB pulse indexing: 44 bits, 10 pulses, 4 tracks */ + config.nbiter = 4; + move16(); /* 4x26x16=1664 loops */ + config.alp = 8192; + move16(); + config.nb_pulse = 10; + move16(); + config.fixedpulses = 2; + move16(); + config.nbpos[0] = 4; + move16(); + config.nbpos[1] = 6; + move16(); + config.nbpos[2] = 8; + move16(); + config.nbpos[3] = 8; + move16(); + BREAK; - case 50: /* EVS pulse indexing: 50 bits, 12 pulses, 4 tracks */ - case 52: /* AMR-WB pulse indexing: 52 bits, 12 pulses, 4 tracks */ - config.nbiter = 4; - move16(); /* 4x26x16=1664 loops */ - config.alp = 8192; - move16(); - config.nb_pulse = 12; - move16(); - config.fixedpulses = 4; - move16(); - config.nbpos[0] = 4; - move16(); - config.nbpos[1] = 6; - move16(); - config.nbpos[2] = 8; - move16(); - config.nbpos[3] = 8; - move16(); - BREAK; + case 50: /* EVS pulse indexing: 50 bits, 12 pulses, 4 tracks */ + case 52: /* AMR-WB pulse indexing: 52 bits, 12 pulses, 4 tracks */ + config.nbiter = 4; + move16(); /* 4x26x16=1664 loops */ + config.alp = 8192; + move16(); + config.nb_pulse = 12; + move16(); + config.fixedpulses = 4; + move16(); + config.nbpos[0] = 4; + move16(); + config.nbpos[1] = 6; + move16(); + config.nbpos[2] = 8; + move16(); + config.nbpos[3] = 8; + move16(); + BREAK; - case 62: /* EVS pulse indexing: 62 bits, 16 pulses, 4 tracks */ - case 64: /* AMR-WB pulse indexing: 64 bits, 16 pulses, 4 tracks */ - config.nbiter = 3; - move16(); /* 3x36x16=1728 loops */ - config.alp = 6554; - move16(); - config.nb_pulse = 16; - move16(); - config.fixedpulses = 4; - move16(); - config.nbpos[0] = 4; - move16(); - config.nbpos[1] = 4; - move16(); - config.nbpos[2] = 6; - move16(); - config.nbpos[3] = 6; - move16(); - config.nbpos[4] = 8; - move16(); - config.nbpos[5] = 8; - move16(); - BREAK; + case 62: /* EVS pulse indexing: 62 bits, 16 pulses, 4 tracks */ + case 64: /* AMR-WB pulse indexing: 64 bits, 16 pulses, 4 tracks */ + config.nbiter = 3; + move16(); /* 3x36x16=1728 loops */ + config.alp = 6554; + move16(); + config.nb_pulse = 16; + move16(); + config.fixedpulses = 4; + move16(); + config.nbpos[0] = 4; + move16(); + config.nbpos[1] = 4; + move16(); + config.nbpos[2] = 6; + move16(); + config.nbpos[3] = 6; + move16(); + config.nbpos[4] = 8; + move16(); + config.nbpos[5] = 8; + move16(); + BREAK; - case 72: /* AMR-WB pulse indexing: 72 bits, 18 pulses, 4 tracks */ - config.nbiter = 3; - move16(); /* 3x35x16=1680 loops */ - config.alp = 6144; - move16(); - config.nb_pulse = 18; - move16(); - config.fixedpulses = 4; - move16(); - config.nbpos[0] = 2; - move16(); - config.nbpos[1] = 3; - move16(); - config.nbpos[2] = 4; - move16(); - config.nbpos[3] = 5; - move16(); - config.nbpos[4] = 6; - move16(); - config.nbpos[5] = 7; - move16(); - config.nbpos[6] = 8; - move16(); - BREAK; + case 72: /* AMR-WB pulse indexing: 72 bits, 18 pulses, 4 tracks */ + config.nbiter = 3; + move16(); /* 3x35x16=1680 loops */ + config.alp = 6144; + move16(); + config.nb_pulse = 18; + move16(); + config.fixedpulses = 4; + move16(); + config.nbpos[0] = 2; + move16(); + config.nbpos[1] = 3; + move16(); + config.nbpos[2] = 4; + move16(); + config.nbpos[3] = 5; + move16(); + config.nbpos[4] = 6; + move16(); + config.nbpos[5] = 7; + move16(); + config.nbpos[6] = 8; + move16(); + BREAK; - case 88: /* AMR-WB pulse indexing: 88 bits, 24 pulses, 4 tracks */ - config.nbiter = 2; - move16(); /* 2x53x16=1696 loop */ - config.alp = 4096; - move16(); - config.nb_pulse = 24; - move16(); - config.fixedpulses = 4; - move16(); - config.nbpos[0] = 2; - move16(); - config.nbpos[1] = 2; - move16(); - config.nbpos[2] = 3; - move16(); - config.nbpos[3] = 4; - move16(); - config.nbpos[4] = 5; - move16(); - config.nbpos[5] = 6; - move16(); - config.nbpos[6] = 7; - move16(); - config.nbpos[7] = 8; - move16(); - config.nbpos[8] = 8; - move16(); - config.nbpos[9] = 8; - move16(); - BREAK; + case 88: /* AMR-WB pulse indexing: 88 bits, 24 pulses, 4 tracks */ + config.nbiter = 2; + move16(); /* 2x53x16=1696 loop */ + config.alp = 4096; + move16(); + config.nb_pulse = 24; + move16(); + config.fixedpulses = 4; + move16(); + config.nbpos[0] = 2; + move16(); + config.nbpos[1] = 2; + move16(); + config.nbpos[2] = 3; + move16(); + config.nbpos[3] = 4; + move16(); + config.nbpos[4] = 5; + move16(); + config.nbpos[5] = 6; + move16(); + config.nbpos[6] = 7; + move16(); + config.nbpos[7] = 8; + move16(); + config.nbpos[8] = 8; + move16(); + config.nbpos[9] = 8; + move16(); + BREAK; - case 87: /* EVS pulse indexing: 87 bits, 26 pulses, 4 tracks */ - config.nbiter = 1; - move16(); - config.alp = 4096; - move16(); - config.nb_pulse = 26; - move16(); - config.fixedpulses = 4; - move16(); - config.nbpos[0] = 4; - move16(); - config.nbpos[1] = 6; - move16(); - config.nbpos[2] = 6; - move16(); - config.nbpos[3] = 8; - move16(); - config.nbpos[4] = 8; - move16(); - config.nbpos[5] = 8; - move16(); - config.nbpos[6] = 8; - move16(); - config.nbpos[7] = 8; - move16(); - config.nbpos[8] = 8; - move16(); - config.nbpos[9] = 8; - move16(); - config.nbpos[10] = 8; - move16(); - BREAK; + case 87: /* EVS pulse indexing: 87 bits, 26 pulses, 4 tracks */ + config.nbiter = 1; + move16(); + config.alp = 4096; + move16(); + config.nb_pulse = 26; + move16(); + config.fixedpulses = 4; + move16(); + config.nbpos[0] = 4; + move16(); + config.nbpos[1] = 6; + move16(); + config.nbpos[2] = 6; + move16(); + config.nbpos[3] = 8; + move16(); + config.nbpos[4] = 8; + move16(); + config.nbpos[5] = 8; + move16(); + config.nbpos[6] = 8; + move16(); + config.nbpos[7] = 8; + move16(); + config.nbpos[8] = 8; + move16(); + config.nbpos[9] = 8; + move16(); + config.nbpos[10] = 8; + move16(); + BREAK; } /* reduce the number of iterations as a compromise between the performance and complexity */ - if( cmpl_flag > 0 ) + if ( cmpl_flag > 0 ) { config.nbiter = cmpl_flag; move16(); @@ -301,21 +300,21 @@ Word16 acelp_4t64_fx( config.bits = nbbits; move16(); - IF (acelpautoc) + IF( acelpautoc ) { E_ACELP_4tsearchx_fx( dn, cn, R, code, &config, ind ); /* Generate weighted code */ - E_ACELP_weighted_code(code, H, 12, y); + E_ACELP_weighted_code( code, H, 12, y ); } ELSE { - E_ACELP_4tsearch_fx(dn, cn, H, code, &config, ind, y); + E_ACELP_4tsearch_fx( dn, cn, H, code, &config, ind, y ); - FOR(i=0; i it doesn't need to be operated by Basic Operators */ - n_1 = (Word16) (N - 1); + n_1 = (Word16) ( N - 1 ); move16(); - nb_pos = shl(1, n_1); /* nb_pos = (1< 1, Q0 */ + IF( v[k] > 0 ) { - IF (v[k]) - { - pos_vector[j] = shr(k,2); - pos_vector_num[j] = L_shr( abs_s(v[k]), 9 ); /* Q9: 512 -> 1, Q0 */ - IF (v[k]>0) - { - sign = L_shl(sign, 1); - } - ELSE - { - sign = L_add(L_shl( sign, 1), 1); - } - j =add(j, 1); - } + sign = L_shl( sign, 1 ); } - *pulse_pos_num = L_deposit_l(j); + ELSE + { + sign = L_add( L_shl( sign, 1 ), 1 ); + } + j = add( j, 1 ); +} +} +*pulse_pos_num = L_deposit_l( j ); - return sign; +return sign; } /*--------------------------------------------------------------------------* -* E_ACELP_code43bit_fx -* -* Fixed bit-length arithmetic coding of pulses -* v - (input) pulse vector -* s - (output) encoded state -* n - (output) range of possible states (0...n-1) -* p - (output) number of pulses found -* len - (input) length of pulse vector -* trackstep - (input) step between tracks -*--------------------------------------------------------------------------*/ + * E_ACELP_code43bit_fx + * + * Fixed bit-length arithmetic coding of pulses + * v - (input) pulse vector + * s - (output) encoded state + * n - (output) range of possible states (0...n-1) + * p - (output) number of pulses found + * len - (input) length of pulse vector + * trackstep - (input) step between tracks + *--------------------------------------------------------------------------*/ Word16 E_ACELP_code43bit_fx( - const Word16 code[], - UWord32 *ps, - Word16 *p, - UWord16 idxs[] -) + const Word16 code[], + UWord32 *ps, + Word16 *p, + UWord16 idxs[] ) { - Word16 i,j,k,track; + Word16 i, j, k, track; Word16 ind[32]; Word16 tmp; Word32 L_tmp; Word32 joint_index; - static const Word32 joint_offset = 3611648; /*offset for 3 pulses per track*/ + static const Word32 joint_offset = 3611648; /*offset for 3 pulses per track*/ Word16 saved_bits = 0; - FOR (track = 0; track < 2; track++) + FOR( track = 0; track < 2; track++ ) { - ps[track] = fcb_encode_PI_fx(code+track, 3); + ps[track] = fcb_encode_PI_fx( code + track, 3 ); move32(); p[track] = 3; move16(); } - FOR (track = 2; track < NB_TRACK_FCB_4T; track++) + FOR( track = 2; track < NB_TRACK_FCB_4T; track++ ) { - i = j = i_mult2(track, NPMAXPT); + i = j = i_mult2( track, NPMAXPT ); move16(); - FOR (k = track; k < 64; k += 4) + FOR( k = track; k < 64; k += 4 ) { - IF (code[k]) + IF( code[k] ) { - tmp = shr(k, 2); - if (code[k] < 0) + tmp = shr( k, 2 ); + if ( code[k] < 0 ) { - tmp = add(tmp, 16); + tmp = add( tmp, 16 ); } ind[j] = tmp; move16(); - IF (GT_16(abs_s(code[k]), 512)) + IF( GT_16( abs_s( code[k] ), 512 ) ) { ind[j + 1] = tmp; move16(); BREAK; } - j = add(j, 1); + j = add( j, 1 ); } } - ps[track] = quant_2p_2N1_fx(ind[i], ind[i+1], 4); + ps[track] = quant_2p_2N1_fx( ind[i], ind[i + 1], 4 ); move32(); p[track] = 2; move16(); } /* joint_index = ps[0]*5472 + ps[1]; */ - L_tmp = L_shl(ps[0], 12); - L_tmp = L_add(L_tmp, L_shl(ps[0], 10)); - L_tmp = L_add(L_tmp, L_shl(ps[0], 8)); - L_tmp = L_add(L_tmp, L_shl(ps[0], 6)); - L_tmp = L_add(L_tmp, L_shl(ps[0], 5)); - joint_index = L_add(L_tmp, ps[1]); - L_tmp = L_sub(joint_index, joint_offset); - if (L_tmp >= 0) + L_tmp = L_shl( ps[0], 12 ); + L_tmp = L_add( L_tmp, L_shl( ps[0], 10 ) ); + L_tmp = L_add( L_tmp, L_shl( ps[0], 8 ) ); + L_tmp = L_add( L_tmp, L_shl( ps[0], 6 ) ); + L_tmp = L_add( L_tmp, L_shl( ps[0], 5 ) ); + joint_index = L_add( L_tmp, ps[1] ); + L_tmp = L_sub( joint_index, joint_offset ); + if ( L_tmp >= 0 ) { - joint_index = L_add(joint_index, joint_offset); + joint_index = L_add( joint_index, joint_offset ); } - if (L_tmp < 0) + if ( L_tmp < 0 ) { - saved_bits = add(saved_bits, 1); + saved_bits = add( saved_bits, 1 ); } - idxs[0] = extract_l(L_add(L_shl(ps[2], 9), ps[3])); - idxs[1] = extract_l(L_add(L_shl(joint_index, 2), L_shr(ps[2], 7))); - idxs[2] = extract_l(L_shr(joint_index, 14)); + idxs[0] = extract_l( L_add( L_shl( ps[2], 9 ), ps[3] ) ); + idxs[1] = extract_l( L_add( L_shl( joint_index, 2 ), L_shr( ps[2], 7 ) ) ); + idxs[2] = extract_l( L_shr( joint_index, 14 ) ); return saved_bits; } diff --git a/lib_enc/cod_ace.c b/lib_enc/cod_ace.c index 60e6ccde4..4e0e4692a 100644 --- a/lib_enc/cod_ace.c +++ b/lib_enc/cod_ace.c @@ -267,7 +267,7 @@ void coder_acelp( if ( st->igf ) { - tbe_celp_exc_flt( st->element_mode, st->idchan, bwe_exc, st->L_frame, L_SUBFR, i_subfr, T0, T0_frac, &error, 0 ); + tbe_celp_exc_flt( st->element_mode, st->idchan, bwe_exc, st->L_frame, L_SUBFR, i_subfr, T0, T0_frac, &error, 0 ); } pitch_buf[i_subfr / L_SUBFR] = (float) T0 + (float) T0_frac / (float) T0_res; @@ -353,7 +353,7 @@ void coder_acelp( * Enhance the excitation * *---------------------------------------------------------*/ - enhancer( MODE2, -1, acelp_cfg->fixed_cdk_index[i_subfr / L_SUBFR], 0, st->coder_type, st->L_frame, voice_fac, stab_fac, norm_gain_code, gain_inov, &( LPDmem->gc_threshold_flt ), code, exc2, gain_pit, LPDmem->dispMem_flt); + enhancer( MODE2, -1, acelp_cfg->fixed_cdk_index[i_subfr / L_SUBFR], 0, st->coder_type, st->L_frame, voice_fac, stab_fac, norm_gain_code, gain_inov, &( LPDmem->gc_threshold_flt ), code, exc2, gain_pit, LPDmem->dispMem_flt ); /*----------------------------------------------------------* * - compute the synthesis speech * diff --git a/lib_enc/cod_ace_fx.c b/lib_enc/cod_ace_fx.c index 0bfdc51b1..667843880 100644 --- a/lib_enc/cod_ace_fx.c +++ b/lib_enc/cod_ace_fx.c @@ -11,10 +11,10 @@ #include "options.h" #include "rom_basop_util.h" #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ -#include "basop_util.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ +#include "basop_util.h" /* Function prototypes */ /*-------------------------------------------------------------------* * coder_acelp_fx() @@ -22,20 +22,20 @@ * Encode ACELP frame *-------------------------------------------------------------------*/ -Word16 coder_acelp_fx( /* o : SEGSNR for CL decision */ - const Word16 A[], /* i : coefficients 4xAz[M+1] */ - const Word16 Aq[], /* i : coefficients 4xAz_q[M+1] */ - const Word16 speech[], /* i : speech[-M..lg] */ - Word16 *prm, /* o : acelp parameters */ - Word16 stab_fac, - Encoder_State *st, - PLC_ENC_EVS_HANDLE hPlc_Ext, - const Word16 target_bits, /* i/o: coder memory state */ - const Word16 Q_new, - const Word16 shift, - Word16 *pitch_buf, /* o : pitch values for each subfr.*/ - Word16 *voice_factors, /* o : voicing factors */ - Word16 *bwe_exc /* o : excitation for SWB TBE */ +Word16 coder_acelp_fx( /* o : SEGSNR for CL decision */ + const Word16 A[], /* i : coefficients 4xAz[M+1] */ + const Word16 Aq[], /* i : coefficients 4xAz_q[M+1] */ + const Word16 speech[], /* i : speech[-M..lg] */ + Word16 *prm, /* o : acelp parameters */ + Word16 stab_fac, + Encoder_State *st, + PLC_ENC_EVS_HANDLE hPlc_Ext, + const Word16 target_bits, /* i/o: coder memory state */ + const Word16 Q_new, + const Word16 shift, + Word16 *pitch_buf, /* o : pitch values for each subfr.*/ + Word16 *voice_factors, /* o : voicing factors */ + Word16 *bwe_exc /* o : excitation for SWB TBE */ ) { #ifndef SIMPLIFY_CODE_BE @@ -52,19 +52,19 @@ Word16 coder_acelp_fx( /* o : SEGSNR for CL decision */ Word32 gain_code, Ltmp, Ltmp2; ACELP_CbkCorr g_corr; const Word16 *p_A, *p_Aq; - Word16 h1[L_SUBFR]; /* weighted impulse response of LP */ + Word16 h1[L_SUBFR]; /* weighted impulse response of LP */ Word16 code[L_SUBFR]; Word16 xn_exp; Word16 Q_xn; Word16 Q_new_p5; Word16 cn[L_SUBFR]; Word16 xn[L_SUBFR]; - Word16 y1[L_SUBFR]; /* Filtered adaptive excitation */ - Word16 y2[L_SUBFR]; /* Filtered adaptive excitation */ + Word16 y1[L_SUBFR]; /* Filtered adaptive excitation */ + Word16 y2[L_SUBFR]; /* Filtered adaptive excitation */ Word16 res_save; - Word16 exc_buf[L_EXC_MEM+L_DIV_MAX+1], *exc; + Word16 exc_buf[L_EXC_MEM + L_DIV_MAX + 1], *exc; Word16 exc2[L_SUBFR]; - Word16 *syn,syn_buf[M+L_DIV_MAX+L_DIV_MAX/2]; /*128 for the memory, L_DIV for the current synth and 128 for the ZIR for next TCX*/ + Word16 *syn, syn_buf[M + L_DIV_MAX + L_DIV_MAX / 2]; /*128 for the memory, L_DIV for the current synth and 128 for the ZIR for next TCX*/ Word16 syn2[L_DIV_MAX]; Word16 gain_inov; Word32 past_gcode; @@ -74,28 +74,28 @@ Word16 coder_acelp_fx( /* o : SEGSNR for CL decision */ Word16 code2[L_SUBFR]; Word16 y22[L_SUBFR]; /* Filtered adaptive excitation */ Word16 error = 0; - Word16 gain_preQ = 0; /* Gain of prequantizer excitation */ - Word16 code_preQ[L_SUBFR]; /* Prequantizer excitation */ + Word16 gain_preQ = 0; /* Gain of prequantizer excitation */ + Word16 code_preQ[L_SUBFR]; /* Prequantizer excitation */ Word16 dummy = 0; - ACELP_config* acelp_cfg; + ACELP_config *acelp_cfg; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - acelp_cfg = &(st->acelp_cfg); + acelp_cfg = &( st->acelp_cfg ); LPD_state_HANDLE hLPDmem = st->hLPDmem; RF_ENC_HANDLE hRF = st->hRF; TD_BWE_ENC_HANDLE hBWE_TD = st->hBWE_TD; TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; - set16_fx(code_preQ, 0, L_SUBFR); + set16_fx( code_preQ, 0, L_SUBFR ); - T0 = 0; /* to avoid compilation warnings */ - T0_frac = 0; /* to avoid compilation warnings */ - T0_res = 0; /* to avoid compilation warnings */ - gain_pit = 0; /* to avoid compilation warnings */ + T0 = 0; /* to avoid compilation warnings */ + T0_frac = 0; /* to avoid compilation warnings */ + T0_res = 0; /* to avoid compilation warnings */ + gain_pit = 0; /* to avoid compilation warnings */ /* Configure ACELP */ @@ -117,57 +117,56 @@ Word16 coder_acelp_fx( /* o : SEGSNR for CL decision */ *------------------------------------------------------------------------*/ /* Rescale ACELP memories, which were not scaled yet*/ - xn_exp = sub(sub(15+1, Q_new),shift); - Q_xn = add(sub(Q_new,1),shift); - Q_new_p5 = add(Q_new, 5); + xn_exp = sub( sub( 15 + 1, Q_new ), shift ); + Q_xn = add( sub( Q_new, 1 ), shift ); + Q_new_p5 = add( Q_new, 5 ); /* Reset phase dispersion */ - IF (GT_16(st->last_core, ACELP_CORE)) + IF( GT_16( st->last_core, ACELP_CORE ) ) { move16(); move16(); move16(); hLPDmem->dm_fx.prev_gain_code = 0; - set16_fx(hLPDmem->dm_fx.prev_gain_pit, 0, 6); + set16_fx( hLPDmem->dm_fx.prev_gain_pit, 0, 6 ); hLPDmem->dm_fx.prev_state = 0; - } /* set excitation memory*/ move16(); move16(); - exc = exc_buf+L_EXC_MEM; - Copy(hLPDmem->old_exc, exc_buf, L_EXC_MEM); - *(exc+st->L_frame) = 0; + exc = exc_buf + L_EXC_MEM; + Copy( hLPDmem->old_exc, exc_buf, L_EXC_MEM ); + *( exc + st->L_frame ) = 0; /* Init syn buffer */ move16(); syn = syn_buf + M; - Copy(hLPDmem->mem_syn, syn_buf, M); + Copy( hLPDmem->mem_syn, syn_buf, M ); /* calculate residual */ - calc_residu_fx(st, speech, exc, Aq); + calc_residu_fx( st, speech, exc, Aq ); /*------------------------------------------------------------------------* * Find and quantize mean_ener_code for gain quantizer * *------------------------------------------------------------------------*/ - Es_pred=0; + Es_pred = 0; move16(); - IF (acelp_cfg->nrg_mode>0) + IF( acelp_cfg->nrg_mode > 0 ) { - Es_pred_enc_fx(&Es_pred, prm, L_frame, exc, st->voicing_fx, acelp_cfg->nrg_bits, acelp_cfg->nrg_mode>1, Q_new); + Es_pred_enc_fx( &Es_pred, prm, L_frame, exc, st->voicing_fx, acelp_cfg->nrg_bits, acelp_cfg->nrg_mode > 1, Q_new ); prm++; } - IF (EQ_16(st->L_frame,L_FRAME)) + IF( EQ_16( st->L_frame, L_FRAME ) ) { - Copy(Aq+2*(M+1), hBWE_TD->cur_sub_Aq_fx, (M+1)); + Copy( Aq + 2 * ( M + 1 ), hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) ); } ELSE { - Copy(Aq+3*(M+1), hBWE_TD->cur_sub_Aq_fx, (M+1)); + Copy( Aq + 3 * ( M + 1 ), hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) ); } @@ -200,28 +199,28 @@ Word16 coder_acelp_fx( /* o : SEGSNR for CL decision */ j_subfr = 0; move16(); - FOR (i_subfr=0; i_subfrmem_w0, p_Aq, exc, L_SUBFR, p_A, st->preemph_fac, xn, cn, h1); + find_targets_fx( speech, &syn[i_subfr - M], i_subfr, &hLPDmem->mem_w0, p_Aq, exc, L_SUBFR, p_A, st->preemph_fac, xn, cn, h1 ); /*---------------------------------------------------------------* * Compute impulse response, h1[], of weighted synthesis filter * *---------------------------------------------------------------*/ - Scale_sig(h1, L_SUBFR, add(1,shift)); /* Q13+1-shift */ + Scale_sig( h1, L_SUBFR, add( 1, shift ) ); /* Q13+1-shift */ /* scaling of xn[] to limit dynamic at 12 bits */ - Scale_sig(xn, L_SUBFR, shift); + Scale_sig( xn, L_SUBFR, shift ); /*-----------------------------------------------------------------* * Gain clipping test to avoid unstable synthesis on frame erasure @@ -237,68 +236,74 @@ Word16 coder_acelp_fx( /* o : SEGSNR for CL decision */ * - compute pitch gain1 * *-----------------------------------------------------------------*/ - IF ( acelp_cfg->ltp_bits!=0 ) + IF( acelp_cfg->ltp_bits != 0 ) { /* Adaptive Codebook (GC and VC) */ Mode2_pit_encode_fx( acelp_cfg->ltp_mode, i_subfr, &prm, &exc[i_subfr], st->pitch_fx, &T0_min, &T0_min_frac, &T0_max, &T0_max_frac, - &T0, &T0_frac, &T0_res, h1, xn, st->pit_min, st->pit_fr1, st->pit_fr1b, st->pit_fr2, st->pit_max, st->pit_res_max); + &T0, &T0_frac, &T0_res, h1, xn, st->pit_min, st->pit_fr1, st->pit_fr1b, st->pit_fr2, st->pit_max, st->pit_res_max ); E_ACELP_adaptive_codebook( exc, T0, T0_frac, T0_res, st->pit_res_max, acelp_cfg->ltf_mode, i_subfr, L_SUBFR, L_frame, h1, clip_gain, xn, - y1, &g_corr, &prm, &gain_pit, xn_exp, 0, 0, &dummy); - + y1, &g_corr, &prm, &gain_pit, xn_exp, 0, 0, &dummy ); } - ELSE IF ( acelp_cfg->ltp_bits==0 ) + ELSE IF( acelp_cfg->ltp_bits == 0 ) { /* No adaptive codebook (UC) */ - gain_pit=0; - g_corr.xy1=0; - g_corr.xy1_e=0; - g_corr.y1y1=0; - g_corr.y1y1_e=0; - set16_fx(y1,0,L_SUBFR); - set16_fx(exc+i_subfr,0,L_SUBFR); + gain_pit = 0; + g_corr.xy1 = 0; + g_corr.xy1_e = 0; + g_corr.y1y1 = 0; + g_corr.y1y1_e = 0; + set16_fx( y1, 0, L_SUBFR ); + set16_fx( exc + i_subfr, 0, L_SUBFR ); T0 = L_SUBFR; T0_frac = 0; T0_res = 1; - move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); } IF( st->igf != 0 ) { - tbe_celp_exc(L_frame, i_subfr, T0, T0_frac, &error, bwe_exc); + tbe_celp_exc( L_frame, i_subfr, T0, T0_frac, &error, bwe_exc ); } - pitch_buf[i_subfr/L_SUBFR] = shl(add(shl(T0,2),T0_frac), 4); + pitch_buf[i_subfr / L_SUBFR] = shl( add( shl( T0, 2 ), T0_frac ), 4 ); /*----------------------------------------------------------------------* * Encode the algebraic innovation * *----------------------------------------------------------------------*/ - E_ACELP_innovative_codebook_fx( exc, T0, T0_frac, T0_res, gain_pit, hLPDmem->tilt_code, acelp_cfg, i_subfr, p_Aq, h1, xn, cn, y1, y2, (Word8)st->acelp_autocorr, &prm, code, shift ,st->L_frame, st->last_L_frame, st->total_brate); + E_ACELP_innovative_codebook_fx( exc, T0, T0_frac, T0_res, gain_pit, hLPDmem->tilt_code, acelp_cfg, i_subfr, p_Aq, h1, xn, cn, y1, y2, (Word8) st->acelp_autocorr, &prm, code, shift, st->L_frame, st->last_L_frame, st->total_brate ); - E_ACELP_xy2_corr(xn, y1, y2, &g_corr, L_SUBFR, Q_xn); + E_ACELP_xy2_corr( xn, y1, y2, &g_corr, L_SUBFR, Q_xn ); - g_corr.y2y2_e = sub(g_corr.y2y2_e, 18); /* -18 (y2*y2: Q9*Q9) */ - g_corr.xy2_e = sub(g_corr.xy2_e, add(Q_xn,9)); /* -(Q_xn+9) (xn: Q_xn y2: Q9) */ - g_corr.y1y2_e = sub(g_corr.y1y2_e, add(Q_xn,9)); /* -(Q_xn+9) (y1: Q_xn y2: Q9) */ - g_corr.xx_e = sub(g_corr.xx_e, add(Q_xn,Q_xn)); /* -(Q_xn+Q_xn) (xn: Q_xn) */ + g_corr.y2y2_e = sub( g_corr.y2y2_e, 18 ); /* -18 (y2*y2: Q9*Q9) */ + g_corr.xy2_e = sub( g_corr.xy2_e, add( Q_xn, 9 ) ); /* -(Q_xn+9) (xn: Q_xn y2: Q9) */ + g_corr.y1y2_e = sub( g_corr.y1y2_e, add( Q_xn, 9 ) ); /* -(Q_xn+9) (y1: Q_xn y2: Q9) */ + g_corr.xx_e = sub( g_corr.xx_e, add( Q_xn, Q_xn ) ); /* -(Q_xn+Q_xn) (xn: Q_xn) */ /*----------------------------------------------------------------------* * Add Gaussian excitation * *----------------------------------------------------------------------*/ - IF (EQ_16(acelp_cfg->gains_mode[j_subfr], 7)) + IF( EQ_16( acelp_cfg->gains_mode[j_subfr], 7 ) ) { - assert(gain_pit == 0); - gauss_L2_fx(h1, code2, y2, y22, &gain_code2, &g_corr, gain_pit, hLPDmem->tilt_code, p_Aq, acelp_cfg->formant_enh_num, &(st->seed_acelp), shift ); + assert( gain_pit == 0 ); + gauss_L2_fx( h1, code2, y2, y22, &gain_code2, &g_corr, gain_pit, hLPDmem->tilt_code, p_Aq, acelp_cfg->formant_enh_num, &( st->seed_acelp ), shift ); } ELSE { - gain_code2 = L_deposit_l(0); - set16_fx(code2, 0, L_SUBFR); - set16_fx(y22, 0, L_SUBFR); + gain_code2 = L_deposit_l( 0 ); + set16_fx( code2, 0, L_SUBFR ); + set16_fx( y22, 0, L_SUBFR ); } /*----------------------------------------------------------* @@ -307,9 +312,9 @@ Word16 coder_acelp_fx( /* o : SEGSNR for CL decision */ *----------------------------------------------------------*/ encode_acelp_gains_fx( code, acelp_cfg->gains_mode[j_subfr], Es_pred, clip_gain, &g_corr, &gain_pit, &gain_code, &prm, - &past_gcode, &gain_inov, L_SUBFR, code2, &gain_code2, st->flag_noisy_speech_snr_fx); + &past_gcode, &gain_inov, L_SUBFR, code2, &gain_code2, st->flag_noisy_speech_snr_fx ); - gp_clip_test_gain_pit_fx(st->element_mode, st->core_brate, gain_pit, st->clip_var_fx ); + gp_clip_test_gain_pit_fx( st->element_mode, st->core_brate, gain_pit, st->clip_var_fx ); #ifndef SIMPLIFY_CODE_BE gain_code_vect[0] = gain_code; @@ -320,9 +325,9 @@ Word16 coder_acelp_fx( /* o : SEGSNR for CL decision */ /*----------------------------------------------------------* * - voice factor (for pitch enhancement) * *----------------------------------------------------------*/ - E_UTIL_voice_factor( exc, i_subfr, code, gain_pit, gain_code, &voice_fac, &(hLPDmem->tilt_code), L_SUBFR, acelp_cfg->voice_tilt, Q_new, shift); + E_UTIL_voice_factor( exc, i_subfr, code, gain_pit, gain_code, &voice_fac, &( hLPDmem->tilt_code ), L_SUBFR, acelp_cfg->voice_tilt, Q_new, shift ); - IF(st->Opt_RF_ON) + IF( st->Opt_RF_ON ) { hRF->rf_tilt_buf[i_subfr / L_SUBFR] = hLPDmem->tilt_code; } @@ -330,20 +335,20 @@ Word16 coder_acelp_fx( /* o : SEGSNR for CL decision */ * Update memory of the weighting filter *-----------------------------------------------------------------*/ /* st_fx->mem_w0 = xn[L_SUBFR-1] - (gain_pit*y1[L_SUBFR-1]) - (gain_code*y2[L_SUBFR-1]); */ - Ltmp = Mpy_32_16_1(gain_code, y2[L_SUBFR-1]); - Ltmp = L_shl(Ltmp, add(5,Q_xn)); - Ltmp = L_mac(Ltmp, y1[L_SUBFR-1], gain_pit); + Ltmp = Mpy_32_16_1( gain_code, y2[L_SUBFR - 1] ); + Ltmp = L_shl( Ltmp, add( 5, Q_xn ) ); + Ltmp = L_mac( Ltmp, y1[L_SUBFR - 1], gain_pit ); /* Add Gaussian contribution*/ - Ltmp2 = Mpy_32_16_1(gain_code2, y22[L_SUBFR-1]); - Ltmp2 = L_shl(Ltmp2, add(5,Q_xn)); - Ltmp = L_add(Ltmp, Ltmp2); - hLPDmem->mem_w0 =sub(xn[L_SUBFR-1], round_fx(L_shl(Ltmp, 1))); + Ltmp2 = Mpy_32_16_1( gain_code2, y22[L_SUBFR - 1] ); + Ltmp2 = L_shl( Ltmp2, add( 5, Q_xn ) ); + Ltmp = L_add( Ltmp, Ltmp2 ); + hLPDmem->mem_w0 = sub( xn[L_SUBFR - 1], round_fx( L_shl( Ltmp, 1 ) ) ); move16(); BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB hLPDmem->mem_w0 = shr_sat( hLPDmem->mem_w0, shift ); /*Qnew-1*/ #else - hLPDmem->mem_w0 =shr(hLPDmem->mem_w0, shift); /*Qnew-1*/ + hLPDmem->mem_w0 = shr( hLPDmem->mem_w0, shift ); /*Qnew-1*/ #endif BASOP_SATURATE_WARNING_ON_EVS; @@ -351,104 +356,104 @@ Word16 coder_acelp_fx( /* o : SEGSNR for CL decision */ * - Find the total excitation. * *-------------------------------------------------------*/ #ifndef SIMPLIFY_CODE_BE - tmp2 = shr(L_SUBFR, 1); - FOR (j = 0; j < 2; j++) + tmp2 = shr( L_SUBFR, 1 ); + FOR( j = 0; j < 2; j++ ) { - FOR (i = sub(tmp2, shr(L_SUBFR, 1)); i < tmp2; i++) + FOR( i = sub( tmp2, shr( L_SUBFR, 1 ) ); i < tmp2; i++ ) { /* code in Q9, gain_pit in Q14; exc Q_new */ - Ltmp = Mpy_32_16_1(gain_code2, code2[i]); - Ltmp = L_shl(Ltmp, Q_new_p5); - Ltmp = L_mac(Ltmp, gain_pit, exc[i+i_subfr]); + Ltmp = Mpy_32_16_1( gain_code2, code2[i] ); + Ltmp = L_shl( Ltmp, Q_new_p5 ); + Ltmp = L_mac( Ltmp, gain_pit, exc[i + i_subfr] ); BASOP_SATURATE_WARNING_OFF_EVS - exc2[i] = round_fx(L_shl(Ltmp, 1)); + exc2[i] = round_fx( L_shl( Ltmp, 1 ) ); BASOP_SATURATE_WARNING_ON_EVS - Ltmp2 = Mpy_32_16_1(gain_code_vect[j], code[i]); - Ltmp2 = L_shl(Ltmp2, Q_new_p5); - Ltmp = L_add(Ltmp, Ltmp2); + Ltmp2 = Mpy_32_16_1( gain_code_vect[j], code[i] ); + Ltmp2 = L_shl( Ltmp2, Q_new_p5 ); + Ltmp = L_add( Ltmp, Ltmp2 ); BASOP_SATURATE_WARNING_OFF_EVS - Ltmp = L_shl(Ltmp, 1); /* saturation can occur here */ + Ltmp = L_shl( Ltmp, 1 ); /* saturation can occur here */ BASOP_SATURATE_WARNING_ON_EVS - exc[i + i_subfr] = round_fx(Ltmp); + exc[i + i_subfr] = round_fx( Ltmp ); } tmp2 = L_SUBFR; move16(); } #else - FOR (i = 0; i < L_SUBFR; i++) + FOR( i = 0; i < L_SUBFR; i++ ) { /* code in Q9, gain_pit in Q14; exc Q_new */ - Ltmp = Mpy_32_16_1(gain_code2, code2[i]); - Ltmp = L_shl(Ltmp, Q_new_p5); - Ltmp = L_mac(Ltmp, gain_pit, exc[i+i_subfr]); + Ltmp = Mpy_32_16_1( gain_code2, code2[i] ); + Ltmp = L_shl( Ltmp, Q_new_p5 ); + Ltmp = L_mac( Ltmp, gain_pit, exc[i + i_subfr] ); #ifdef BASOP_NOGLOB - exc2[i] = round_fx_sat(L_shl_o(Ltmp, 1, &Overflow)); + exc2[i] = round_fx_sat( L_shl_o( Ltmp, 1, &Overflow ) ); #else BASOP_SATURATE_WARNING_OFF_EVS - exc2[i] = round_fx(L_shl(Ltmp, 1)); + exc2[i] = round_fx( L_shl( Ltmp, 1 ) ); BASOP_SATURATE_WARNING_ON_EVS #endif - Ltmp2 = Mpy_32_16_1(gain_code, code[i]); + Ltmp2 = Mpy_32_16_1( gain_code, code[i] ); #ifdef BASOP_NOGLOB Ltmp2 = L_shl_sat( Ltmp2, Q_new_p5 ); Ltmp = L_add_sat( Ltmp, Ltmp2 ); #else - Ltmp2 = L_shl(Ltmp2, Q_new_p5); - Ltmp = L_add(Ltmp, Ltmp2); + Ltmp2 = L_shl( Ltmp2, Q_new_p5 ); + Ltmp = L_add( Ltmp, Ltmp2 ); #endif #ifdef BASOP_NOGLOB - Ltmp = L_shl_o(Ltmp, 1, &Overflow); /* saturation can occur here */ - exc[i + i_subfr] = round_fx_o(Ltmp, &Overflow); + Ltmp = L_shl_o( Ltmp, 1, &Overflow ); /* saturation can occur here */ + exc[i + i_subfr] = round_fx_o( Ltmp, &Overflow ); #else BASOP_SATURATE_WARNING_OFF_EVS - Ltmp = L_shl(Ltmp, 1); /* saturation can occur here */ + Ltmp = L_shl( Ltmp, 1 ); /* saturation can occur here */ BASOP_SATURATE_WARNING_ON_EVS - exc[i + i_subfr] = round_fx(Ltmp); + exc[i + i_subfr] = round_fx( Ltmp ); #endif } #endif /*-----------------------------------------------------------------* - * Prepare TBE excitation - *-----------------------------------------------------------------*/ + * Prepare TBE excitation + *-----------------------------------------------------------------*/ IF( st->igf != 0 ) { - prep_tbe_exc_fx( L_frame, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr/L_SUBFR], - bwe_exc, gain_preQ, code_preQ, Q_new, T0, T0_frac, st->coder_type, st->core_brate ); + prep_tbe_exc_fx( L_frame, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR], + bwe_exc, gain_preQ, code_preQ, Q_new, T0, T0_frac, st->coder_type, st->core_brate ); } /*---------------------------------------------------------* * Enhance the excitation * *---------------------------------------------------------*/ - E_UTIL_enhancer( voice_fac, stab_fac, past_gcode, gain_inov, &hLPDmem->gc_threshold, code, exc2, gain_pit, &hLPDmem->dm_fx.prev_gain_code, - hLPDmem->dm_fx.prev_gain_pit, &hLPDmem->dm_fx.prev_state, st->coder_type, acelp_cfg->fixed_cdk_index[j_subfr], L_SUBFR, L_frame, Q_new); + E_UTIL_enhancer( voice_fac, stab_fac, past_gcode, gain_inov, &hLPDmem->gc_threshold, code, exc2, gain_pit, &hLPDmem->dm_fx.prev_gain_code, + hLPDmem->dm_fx.prev_gain_pit, &hLPDmem->dm_fx.prev_state, st->coder_type, acelp_cfg->fixed_cdk_index[j_subfr], L_SUBFR, L_frame, Q_new ); /*----------------------------------------------------------* * - compute the synthesis speech * *----------------------------------------------------------*/ - E_UTIL_synthesis(1, p_Aq, exc2, &syn2[i_subfr], L_SUBFR, hLPDmem->mem_syn2, 1, M); + E_UTIL_synthesis( 1, p_Aq, exc2, &syn2[i_subfr], L_SUBFR, hLPDmem->mem_syn2, 1, M ); /*Save data for BPF*/ move16(); move16(); /* st->bpf_T[j_subfr] = (int)((float)T0+(float)T0_frac/(float)T0_res+0.5f); */ - st->bpf_T[j_subfr] = add(T0, shr(div_s(T0_frac, T0_res), 14)); + st->bpf_T[j_subfr] = add( T0, shr( div_s( T0_frac, T0_res ), 14 ) ); st->bpf_gainT[j_subfr] = gain_pit; - E_UTIL_synthesis(1, p_Aq, &exc[i_subfr], &syn[i_subfr], L_SUBFR, &syn[i_subfr-M], 0, M); + E_UTIL_synthesis( 1, p_Aq, &exc[i_subfr], &syn[i_subfr], L_SUBFR, &syn[i_subfr - M], 0, M ); /*----------------------------------------------------------* * Update * *----------------------------------------------------------*/ move16(); move16(); - p_A += (M+1); - p_Aq += (M+1); + p_A += ( M + 1 ); + p_Aq += ( M + 1 ); IF( hPlc_Ext != NULL ) { @@ -459,19 +464,19 @@ Word16 coder_acelp_fx( /* o : SEGSNR for CL decision */ move32(); st->gain_code[j_subfr] = gain_code; - j_subfr = add(j_subfr, 1); + j_subfr = add( j_subfr, 1 ); } /* end of subframe loop */ - p_A -= (M+1); - p_Aq -= (M+1); + p_A -= ( M + 1 ); + p_Aq -= ( M + 1 ); /*----------------------------------------------------------* * Update LPD memory * *----------------------------------------------------------*/ - Copy (exc+L_frame-L_EXC_MEM, hLPDmem->old_exc, L_EXC_MEM); - Copy(syn+L_frame-M, hLPDmem->mem_syn, M); - Copy(syn+L_frame-L_SYN_MEM, hLPDmem->mem_syn_r, L_SYN_MEM); + Copy( exc + L_frame - L_EXC_MEM, hLPDmem->old_exc, L_EXC_MEM ); + Copy( syn + L_frame - M, hLPDmem->mem_syn, M ); + Copy( syn + L_frame - L_SYN_MEM, hLPDmem->mem_syn_r, L_SYN_MEM ); IF( hPlc_Ext != NULL ) { @@ -479,28 +484,28 @@ Word16 coder_acelp_fx( /* o : SEGSNR for CL decision */ move16(); hPlc_Ext->Q_new = Q_new; move16(); - Copy( exc+L_frame-L_EXC_MEM-8, hPlc_Ext->old_exc_Qold, 8); + Copy( exc + L_frame - L_EXC_MEM - 8, hPlc_Ext->old_exc_Qold, 8 ); } /*----------------------------------------------------------* * ZIR at the end of the ACELP frame (for TCX) * *----------------------------------------------------------*/ - Copy(syn2, syn, L_frame); + Copy( syn2, syn, L_frame ); move16(); tmp = hLPDmem->syn[M]; - E_UTIL_deemph2(sub(Q_new,1), syn, st->preemph_fac, L_frame, &tmp); + E_UTIL_deemph2( sub( Q_new, 1 ), syn, st->preemph_fac, L_frame, &tmp ); - if (st->hTcxEnc != NULL) + if ( st->hTcxEnc != NULL ) { - bufferCopyFx(syn + L_frame - (L_frame / 2), hTcxEnc->Txnq, shr(L_frame, 1), 0 /*Qf_syn*/, -1 /*Qf_Txnq*/, 0 /*Q_syn*/, 0 /*Q_Txnq*/); + bufferCopyFx( syn + L_frame - ( L_frame / 2 ), hTcxEnc->Txnq, shr( L_frame, 1 ), 0 /*Qf_syn*/, -1 /*Qf_Txnq*/, 0 /*Q_syn*/, 0 /*Q_Txnq*/ ); } - Copy(syn+L_frame-M-1, hLPDmem->syn, 1+M); /*Q0*/ - Copy(syn, st->synth, L_frame); + Copy( syn + L_frame - M - 1, hLPDmem->syn, 1 + M ); /*Q0*/ + Copy( syn, st->synth, L_frame ); - assert(T0_res <= 6); + assert( T0_res <= 6 ); /*Update MODE1*/ - Copy(p_Aq, st->old_Aq_12_8_fx, M+1 ); + Copy( p_Aq, st->old_Aq_12_8_fx, M + 1 ); st->old_Es_pred_fx = Es_pred; return 0; diff --git a/lib_enc/cod_tcx.c b/lib_enc/cod_tcx.c index 502e885bc..96acb8f40 100644 --- a/lib_enc/cod_tcx.c +++ b/lib_enc/cod_tcx.c @@ -103,13 +103,13 @@ void HBAutocorrelation( #define TNS_GAIN_THRESHOLD_FOR_WHITE ( 3.0f ) void TNSAnalysisStereo( - Encoder_State **sts, /* i : encoder state handle */ + Encoder_State **sts, /* i : encoder state handle */ float *mdst_spectrum[CPE_CHANNELS][NB_DIV], /* o : MDST spectrum */ - const int16_t bWhitenedDomain, /* i : whitened domain flag */ - int16_t tnsSize[CPE_CHANNELS][NB_DIV], /* i : number of tns parameters put into prm */ - int16_t tnsBits[CPE_CHANNELS][NB_DIV], /* i : number of tns bits in the frame */ - int16_t param_core[][NB_DIV * NPRM_DIV], /* o : TNS parameters */ - const int16_t mct_on /* i : flag mct block (1) or stereo (0) */ + const int16_t bWhitenedDomain, /* i : whitened domain flag */ + int16_t tnsSize[CPE_CHANNELS][NB_DIV], /* i : number of tns parameters put into prm */ + int16_t tnsBits[CPE_CHANNELS][NB_DIV], /* i : number of tns bits in the frame */ + int16_t param_core[][NB_DIV * NPRM_DIV], /* o : TNS parameters */ + const int16_t mct_on /* i : flag mct block (1) or stereo (0) */ ) { int16_t ch, k, L_spec, L_frame, nSubframes, iFilter; @@ -227,21 +227,21 @@ void TNSAnalysisStereo( /* if prediction gain and avgSqrCoef are both close we are pretty sure the filters are quite similar, use the avg of * both filters for the decision */ - meanPredictionGain = ( pFilter[0]->predictionGain_flt + pFilter[1]->predictionGain_flt) * 0.5f; + meanPredictionGain = ( pFilter[0]->predictionGain_flt + pFilter[1]->predictionGain_flt ) * 0.5f; maxPredictionGain = max( maxPredictionGain, meanPredictionGain ); - if ( ( pFilter[0]->predictionGain_flt > pTnsParameters[0]->minPredictionGain_flt) && ( sts[0]->element_brate < IVAS_80k ) && - ( pFilter[1]->predictionGain_flt > pTnsParameters[1]->minPredictionGain_flt) && ( sts[0]->hTcxEnc->tnsData[k].nFilters == sts[1]->hTcxEnc->tnsData[k].nFilters ) ) + if ( ( pFilter[0]->predictionGain_flt > pTnsParameters[0]->minPredictionGain_flt ) && ( sts[0]->element_brate < IVAS_80k ) && + ( pFilter[1]->predictionGain_flt > pTnsParameters[1]->minPredictionGain_flt ) && ( sts[0]->hTcxEnc->tnsData[k].nFilters == sts[1]->hTcxEnc->tnsData[k].nFilters ) ) { pFilter[0]->predictionGain_flt = pFilter[1]->predictionGain_flt = meanPredictionGain; /* more TNS filter sync at 48kbps */ } - if ( ( fabs( pFilter[0]->predictionGain_flt - pFilter[1]->predictionGain_flt) < SIMILAR_TNS_THRESHOLD * meanPredictionGain ) && + if ( ( fabs( pFilter[0]->predictionGain_flt - pFilter[1]->predictionGain_flt ) < SIMILAR_TNS_THRESHOLD * meanPredictionGain ) && ( sts[0]->hTcxEnc->tnsData[k].nFilters == sts[1]->hTcxEnc->tnsData[k].nFilters ) ) { - float maxAvgSqrCoef = max( pFilter[0]->avgSqrCoef_flt, pFilter[1]->avgSqrCoef_flt); + float maxAvgSqrCoef = max( pFilter[0]->avgSqrCoef_flt, pFilter[1]->avgSqrCoef_flt ); float meanLtpGain = ( sts[0]->hTcxEnc->tcxltp_gain_flt + sts[1]->hTcxEnc->tcxltp_gain_flt ) * 0.5f; maxPredGain = max( maxPredGain, meanPredictionGain ); - if ( ( meanPredictionGain > pTnsParameters[0]->minPredictionGain_flt) || ( maxAvgSqrCoef > pTnsParameters[0]->minAvgSqrCoef_flt) ) + if ( ( meanPredictionGain > pTnsParameters[0]->minPredictionGain_flt ) || ( maxAvgSqrCoef > pTnsParameters[0]->minAvgSqrCoef_flt ) ) { if ( sts[0]->hTcxEnc->tnsData[k].nFilters > 0 || sts[1]->hTcxEnc->tnsData[k].nFilters > 0 || isTCX10 || meanLtpGain < 0.6f ) { @@ -254,7 +254,7 @@ void TNSAnalysisStereo( { const float maxEnergyChange = ( GetTCXMaxenergyChange( sts[0]->hTranDet, isTCX10, NSUBBLOCKS, 3 ) + GetTCXMaxenergyChange( sts[1]->hTranDet, isTCX10, NSUBBLOCKS, 3 ) ) * 0.5f; - if ( maxEnergyChange >= pTnsParameters[0]->minEnergyChange_flt) + if ( maxEnergyChange >= pTnsParameters[0]->minEnergyChange_flt ) { ++sts[0]->hTcxEnc->tnsData[k].nFilters; pFilter[0]->filterType = TNS_FILTER_ON; @@ -394,9 +394,9 @@ void TNSAnalysisStereo( const struct TnsParameters *pTnsParameters; pFilter = sts[ch]->hTcxEnc->tnsData[k].filter + iFilter; pTnsParameters = sts[ch]->hTcxCfg->pCurrentTnsConfig->pTnsParameters + iFilter; - maxPredGain = max( maxPredGain, pFilter->predictionGain_flt); + maxPredGain = max( maxPredGain, pFilter->predictionGain_flt ); - if ( ( pFilter->predictionGain_flt > pTnsParameters->minPredictionGain_flt) || ( pFilter->avgSqrCoef_flt > pTnsParameters->minAvgSqrCoef_flt) ) + if ( ( pFilter->predictionGain_flt > pTnsParameters->minPredictionGain_flt ) || ( pFilter->avgSqrCoef_flt > pTnsParameters->minAvgSqrCoef_flt ) ) { if ( sts[ch]->hTcxEnc->tnsData[k].nFilters > 0 || isTCX10 || sts[ch]->hTcxEnc->tcxltp_gain_flt < 0.6f ) { @@ -407,7 +407,7 @@ void TNSAnalysisStereo( { const float maxEnergyChange = GetTCXMaxenergyChange( sts[ch]->hTranDet, isTCX10, NSUBBLOCKS, 3 ); - if ( maxEnergyChange >= pTnsParameters->minEnergyChange_flt) + if ( maxEnergyChange >= pTnsParameters->minEnergyChange_flt ) { ++sts[ch]->hTcxEnc->tnsData[k].nFilters; pFilter->filterType = TNS_FILTER_ON; @@ -700,7 +700,7 @@ void ShapeSpectrum( } } - tcxGetNoiseFillingTilt_flt( A, L_frame, ( total_brate >= ACELP_13k20 && !st->rf_mode ), &st->hTcxEnc->noiseTiltFactor_flt); + tcxGetNoiseFillingTilt_flt( A, L_frame, ( total_brate >= ACELP_13k20 && !st->rf_mode ), &st->hTcxEnc->noiseTiltFactor_flt ); /* Calculate Spectrum Flatness Measure for the TCX Concealment */ if ( st->enablePlcWaveadjust ) @@ -1666,7 +1666,7 @@ void InternalTCXDecoder( if ( fac_ns > 0.0f ) { - iStart = tcxGetNoiseFillingTilt_flt( A, L_frame, ( st->total_brate >= ACELP_13k20 && !st->rf_mode ), &hTcxEnc->noiseTiltFactor_flt); + iStart = tcxGetNoiseFillingTilt_flt( A, L_frame, ( st->total_brate >= ACELP_13k20 && !st->rf_mode ), &hTcxEnc->noiseTiltFactor_flt ); noiseTransWidth = GetTransWidth( st->tcxonly, ( L_frame == st->L_frame >> 1 ), hTcxEnc->tcxltp_gain_flt, ( st->hTcxCfg->ctx_hm && st->last_core != ACELP_CORE && hm_active ) ); assert( st->element_mode != IVAS_CPE_MDCT ); @@ -1838,7 +1838,7 @@ void InternalTCXDecoder( TCX_MDCT_Inverse_flt( spectrum + L_spec_TCX5, win, L_ola, L_win - L_ola, L_ola, st->element_mode ); tcx_windowing_synthesis_current_frame_flt( win, st->hTcxCfg->tcx_aldo_window_2_flt, st->hTcxCfg->tcx_mdct_window_half_flt, st->hTcxCfg->tcx_mdct_window_minimum_flt, L_ola, st->hTcxCfg->tcx_mdct_window_half_length, st->hTcxCfg->tcx_mdct_window_min_length, 0, /* left_rect */ - 2, /* left_mode */ st->hTcxEnc->acelp_zir_flt, st->hTcxEnc->Txnq_flt, NULL, Aq_old, st->hTcxCfg->tcx_mdct_window_trans_flt, L_win, tcx_offset < 0 ? -tcx_offset : 0, 1, /* not st->last_core */ 0, 0 ); + 2, /* left_mode */ st->hTcxEnc->acelp_zir_flt, st->hTcxEnc->Txnq_flt, NULL, Aq_old, st->hTcxCfg->tcx_mdct_window_trans_flt, L_win, tcx_offset < 0 ? -tcx_offset : 0, 1, /* not st->last_core */ 0, 0 ); tcx_windowing_synthesis_past_frame_flt( xn_buf + ( overlap >> 1 ) + L_win - ( L_ola >> 1 ), st->hTcxCfg->tcx_aldo_window_1_trunc_flt, st->hTcxCfg->tcx_mdct_window_half_flt, st->hTcxCfg->tcx_mdct_window_minimum_flt, L_ola, st->hTcxCfg->tcx_mdct_window_half_length, st->hTcxCfg->tcx_mdct_window_min_length, 2 ); @@ -2100,7 +2100,7 @@ void coder_tcx( { SetTnsConfig_flt( hTcxCfg, L_frame_glob == st->L_frame, st->last_core == ACELP_CORE ); - TNSAnalysis( hTcxCfg, L_frame, L_spec, TCX_20, st->last_core == ACELP_CORE, spectrum, NULL, -1, hTcxEnc->tnsData, hTcxEnc->fUseTns, &st->hIGFEnc->tns_predictionGain_flt); + TNSAnalysis( hTcxCfg, L_frame, L_spec, TCX_20, st->last_core == ACELP_CORE, spectrum, NULL, -1, hTcxEnc->tnsData, hTcxEnc->fUseTns, &st->hIGFEnc->tns_predictionGain_flt ); } else { diff --git a/lib_enc/cod_tcx_fx.c b/lib_enc/cod_tcx_fx.c index c4d441304..0c3f7d4df 100644 --- a/lib_enc/cod_tcx_fx.c +++ b/lib_enc/cod_tcx_fx.c @@ -9,7 +9,7 @@ #include "rom_com.h" #include "stat_com.h" //#include "prot_fx.h" -#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ #include "prot_fx2.h" #include "basop_util.h" #include "stl.h" @@ -17,22 +17,21 @@ #include "prot_fx_enc.h" - /* Up to the Autocorrelation it is the same code as in GetMDCT, with the difference in the parameters in the call to tcx_windowing_analysis */ void HBAutocorrelation_fx( TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */ - Word16 left_overlap_mode, /* input: overlap mode of left window half */ - Word16 right_overlap_mode, /* input: overlap mode of right window half */ - Word16 speech[], /* input: speech[-LFAC..L_frame+LFAC] */ - Word16 L_frame, /* input: frame length */ - Word32 *r, /* output: autocorrelations vector */ - Word16 m /* input : order of LP filter */ + Word16 left_overlap_mode, /* input: overlap mode of left window half */ + Word16 right_overlap_mode, /* input: overlap mode of right window half */ + Word16 speech[], /* input: speech[-LFAC..L_frame+LFAC] */ + Word16 L_frame, /* input: frame length */ + Word32 *r, /* output: autocorrelations vector */ + Word16 m /* input : order of LP filter */ ) { Word16 i, j, left_overlap, right_overlap; Word16 len, norm, shift, fact; Word32 L_tmp, L_sum; - Word16 y[L_MDCT_OVLP_MAX+L_FRAME_PLUS+L_MDCT_OVLP_MAX]; + Word16 y[L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX]; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; @@ -42,29 +41,29 @@ void HBAutocorrelation_fx( * Windowing * *-----------------------------------------------------------*/ - WindowSignal(hTcxCfg, hTcxCfg->tcx_offset, left_overlap_mode, right_overlap_mode, &left_overlap, &right_overlap, speech, &L_frame, y, 1, 0); + WindowSignal( hTcxCfg, hTcxCfg->tcx_offset, left_overlap_mode, right_overlap_mode, &left_overlap, &right_overlap, speech, &L_frame, y, 1, 0 ); /*-----------------------------------------------------------* * Autocorrelation * *-----------------------------------------------------------*/ - len = add(L_frame, shr(add(left_overlap, right_overlap), 1)); + len = add( L_frame, shr( add( left_overlap, right_overlap ), 1 ) ); /* calculate shift */ shift = 0; move16(); - L_sum = L_deposit_l(0); + L_sum = L_deposit_l( 0 ); Overflow = 0; move16(); - FOR (i = 0; i < len; i+=1) + FOR( i = 0; i < len; i += 1 ) { /* Test Addition */ -#ifdef BASOP_NOGLOB /* Critical Overflow, all operations below needs to check for Overflow if we want to ensure bit exactness */ - L_mac0_o(L_sum, y[i], y[i], &Overflow); -#else /* BASOP_NOGLOB */ - L_mac0(L_sum, y[i], y[i]); +#ifdef BASOP_NOGLOB /* Critical Overflow, all operations below needs to check for Overflow if we want to ensure bit exactness */ + L_mac0_o( L_sum, y[i], y[i], &Overflow ); +#else /* BASOP_NOGLOB */ + L_mac0( L_sum, y[i], y[i] ); #endif /* BASOP_NOGLOB */ - IF (Overflow) + IF( Overflow ) { Overflow = 0; move16(); @@ -72,28 +71,28 @@ void HBAutocorrelation_fx( move16(); L_tmp = L_msu0( 0, y[i], y[i] ); L_tmp = L_shr( L_tmp, 1 ); -#ifdef BASOP_NOGLOB /* Only the sub can overflow if the current L_sum is negative and already close to MIN */ +#ifdef BASOP_NOGLOB /* Only the sub can overflow if the current L_sum is negative and already close to MIN */ L_sum = L_add( L_shr( L_sub_o( L_sum, 1, &Overflow ), 1 ), 1 ); #else L_sum = L_add( L_shr( L_sub( L_sum, 1 ), 1 ), 1 ); #endif -#ifdef BASOP_NOGLOB /* Critical Overflow */ +#ifdef BASOP_NOGLOB /* Critical Overflow */ L_sum = L_sub_o( L_sum, L_tmp, &Overflow ); #else L_sum = L_sub( L_sum, L_tmp ); #endif - FOR (j = add(i,1); j 0) + IF( shift > 0 ) { - fact = lshr(-32768, shift); - FOR (i = 0; i < len; i++) + fact = lshr( -32768, shift ); + FOR( i = 0; i < len; i++ ) { - y[i] = mult_r(y[i], fact); + y[i] = mult_r( y[i], fact ); move16(); } } /* Compute and normalize r[0] */ - L_sum = L_mac0(1, y[0], y[0]); - FOR (i = 1; i < len; i++) + L_sum = L_mac0( 1, y[0], y[0] ); + FOR( i = 1; i < len; i++ ) { - L_sum = L_mac0(L_sum, y[i], y[i]); + L_sum = L_mac0( L_sum, y[i], y[i] ); } - norm = norm_l(L_sum); - L_sum = L_shl(L_sum, norm); + norm = norm_l( L_sum ); + L_sum = L_shl( L_sum, norm ); r[0] = L_sum; move32(); /* Compute r[1] to r[m] */ - FOR (i = 1; i <= m; i++) + FOR( i = 1; i <= m; i++ ) { - L_sum = L_mult0(y[0],y[i]); - FOR (j = 1; j < len - i; j++) + L_sum = L_mult0( y[0], y[i] ); + FOR( j = 1; j < len - i; j++ ) { - L_sum = L_mac0(L_sum, y[j], y[j + i]); + L_sum = L_mac0( L_sum, y[j], y[j + i] ); } - L_sum = L_shl(L_sum, norm); + L_sum = L_shl( L_sum, norm ); r[i] = L_sum; move32(); } - } #ifdef ADD_IVAS_TNS @@ -171,8 +169,8 @@ void HBAutocorrelation_fx( #define TNS_GAIN_THRESHOLD_FOR_WHITE ( 3.0f ) void TNSAnalysisStereo( - Encoder_State** sts, /* i : encoder state handle */ - float* mdst_spectrum[MCT_MAX_CHANNELS][NB_DIV], /* o : MDST spectrum */ + Encoder_State **sts, /* i : encoder state handle */ + float *mdst_spectrum[MCT_MAX_CHANNELS][NB_DIV], /* o : MDST spectrum */ const int16_t bWhitenedDomain, /* i : whitened domain flag */ int16_t tnsSize[MCT_MAX_CHANNELS][NB_DIV], /* i : number of tns parameters put into prm */ int16_t tnsBits[MCT_MAX_CHANNELS][NB_DIV], /* i : number of tns bits in the frame */ @@ -181,8 +179,8 @@ void TNSAnalysisStereo( ) { int16_t ch, k, L_spec, L_frame, nSubframes, iFilter; - float* spectrum; - Encoder_State* st = NULL; + float *spectrum; + Encoder_State *st = NULL; TCX_ENC_HANDLE hTcxEnc = NULL; int16_t individual_decision[NB_DIV]; float maxPredictionGain = 0.f, meanPredictionGain; @@ -193,73 +191,73 @@ void TNSAnalysisStereo( L_frame = -1; /* TNS filter analysis, loop over channels */ - for (ch = 0; ch < CPE_CHANNELS; ch++) + for ( ch = 0; ch < CPE_CHANNELS; ch++ ) { st = sts[ch]; - if (st->mct_chan_mode == MCT_CHAN_MODE_IGNORE) + if ( st->mct_chan_mode == MCT_CHAN_MODE_IGNORE ) { continue; } hTcxEnc = st->hTcxEnc; - nSubframes = (hTcxEnc->tcxMode == TCX_20) ? 1 : NB_DIV; + nSubframes = ( hTcxEnc->tcxMode == TCX_20 ) ? 1 : NB_DIV; - for (k = 0; k < nSubframes; k++) + for ( k = 0; k < nSubframes; k++ ) { /* reset tns on whitened domain flag */ - if (!bWhitenedDomain) + if ( !bWhitenedDomain ) { hTcxEnc->bTnsOnWhithenedSpectra[k] = 0; hTcxEnc->fUseTns[k] = 0; } - if (st->hTcxCfg->fIsTNSAllowed && (!bWhitenedDomain || hTcxEnc->bTnsOnWhithenedSpectra[k])) + if ( st->hTcxCfg->fIsTNSAllowed && ( !bWhitenedDomain || hTcxEnc->bTnsOnWhithenedSpectra[k] ) ) { spectrum = hTcxEnc->spectrum[k]; L_frame = hTcxEnc->L_frameTCX; - st->hTcxCfg->pCurrentTnsConfig = &st->hTcxCfg->tnsConfig[hTcxEnc->transform_type[k] == TCX_20][(k == 0) && (st->last_core == ACELP_CORE)]; + st->hTcxCfg->pCurrentTnsConfig = &st->hTcxCfg->tnsConfig[hTcxEnc->transform_type[k] == TCX_20][( k == 0 ) && ( st->last_core == ACELP_CORE )]; L_spec = st->hTcxCfg->pCurrentTnsConfig->iFilterBorders[0]; /*-----------------------------------------------------------* * Temporal Noise Shaping analysis * *-----------------------------------------------------------*/ - if (hTcxEnc->transform_type[k] == TCX_5) + if ( hTcxEnc->transform_type[k] == TCX_5 ) { /* rearrange LF sub-window lines prior to TNS analysis & filtering */ - tcx5TnsGrouping(L_frame >> 2, L_spec >> 1, spectrum); + tcx5TnsGrouping( L_frame >> 2, L_spec >> 1, spectrum ); } /* WMOPS: All initializations are either for safety or static (tables) and thus not to be counted */ - ResetTnsData(&hTcxEnc->tnsData[k]); - if (st->hTcxCfg->pCurrentTnsConfig->maxOrder <= 0) + ResetTnsData( &hTcxEnc->tnsData[k] ); + if ( st->hTcxCfg->pCurrentTnsConfig->maxOrder <= 0 ) { break; } - CalculateTnsFilt(st->hTcxCfg->pCurrentTnsConfig, spectrum, &hTcxEnc->tnsData[k], NULL); + CalculateTnsFilt( st->hTcxCfg->pCurrentTnsConfig, spectrum, &hTcxEnc->tnsData[k], NULL ); } } } - if (!mct_on) + if ( !mct_on ) { /* TNS decision */ /* if framing differs between channels, keep the filter decision per channel */ - if ((sts[0]->hTcxEnc->transform_type[0] != sts[1]->hTcxEnc->transform_type[0] && - sts[0]->hTcxEnc->transform_type[1] != sts[1]->hTcxEnc->transform_type[1]) || - sts[0]->hTcxCfg->fIsTNSAllowed != sts[1]->hTcxCfg->fIsTNSAllowed) + if ( ( sts[0]->hTcxEnc->transform_type[0] != sts[1]->hTcxEnc->transform_type[0] && + sts[0]->hTcxEnc->transform_type[1] != sts[1]->hTcxEnc->transform_type[1] ) || + sts[0]->hTcxCfg->fIsTNSAllowed != sts[1]->hTcxCfg->fIsTNSAllowed ) { individual_decision[0] = individual_decision[1] = 1; } - else if (bWhitenedDomain) + else if ( bWhitenedDomain ) { - nSubframes = (sts[0]->hTcxEnc->tcxMode == TCX_20) ? 1 : NB_DIV; - for (k = 0; k < nSubframes; k++) + nSubframes = ( sts[0]->hTcxEnc->tcxMode == TCX_20 ) ? 1 : NB_DIV; + for ( k = 0; k < nSubframes; k++ ) { - if (sts[0]->hTcxEnc->bTnsOnWhithenedSpectra[k] != sts[1]->hTcxEnc->bTnsOnWhithenedSpectra[k]) + if ( sts[0]->hTcxEnc->bTnsOnWhithenedSpectra[k] != sts[1]->hTcxEnc->bTnsOnWhithenedSpectra[k] ) { individual_decision[k] = 1; } @@ -271,54 +269,54 @@ void TNSAnalysisStereo( */ { int16_t isTCX10; - isTCX10 = (sts[0]->hTcxEnc->tcxMode == TCX_20) ? 0 : 1; + isTCX10 = ( sts[0]->hTcxEnc->tcxMode == TCX_20 ) ? 0 : 1; - nSubframes = (sts[0]->hTcxEnc->tcxMode == TCX_20) ? 1 : NB_DIV; + nSubframes = ( sts[0]->hTcxEnc->tcxMode == TCX_20 ) ? 1 : NB_DIV; - for (k = 0; k < nSubframes; k++) + for ( k = 0; k < nSubframes; k++ ) { - if (sts[0]->hTcxCfg->fIsTNSAllowed && individual_decision[k] != 1 && (!bWhitenedDomain || sts[0]->hTcxEnc->bTnsOnWhithenedSpectra[k])) + if ( sts[0]->hTcxCfg->fIsTNSAllowed && individual_decision[k] != 1 && ( !bWhitenedDomain || sts[0]->hTcxEnc->bTnsOnWhithenedSpectra[k] ) ) { float maxPredGain = -1.0f; - sts[0]->hTcxCfg->pCurrentTnsConfig = &sts[0]->hTcxCfg->tnsConfig[sts[0]->hTcxEnc->transform_type[k] == TCX_20][(k == 0) && (sts[0]->last_core == ACELP_CORE)]; - sts[1]->hTcxCfg->pCurrentTnsConfig = &sts[1]->hTcxCfg->tnsConfig[sts[1]->hTcxEnc->transform_type[k] == TCX_20][(k == 0) && (sts[1]->last_core == ACELP_CORE)]; + sts[0]->hTcxCfg->pCurrentTnsConfig = &sts[0]->hTcxCfg->tnsConfig[sts[0]->hTcxEnc->transform_type[k] == TCX_20][( k == 0 ) && ( sts[0]->last_core == ACELP_CORE )]; + sts[1]->hTcxCfg->pCurrentTnsConfig = &sts[1]->hTcxCfg->tnsConfig[sts[1]->hTcxEnc->transform_type[k] == TCX_20][( k == 0 ) && ( sts[1]->last_core == ACELP_CORE )]; #ifdef DEBUGGING - assert(sts[0]->hTcxCfg->pCurrentTnsConfig->nMaxFilters == sts[1]->hTcxCfg->pCurrentTnsConfig->nMaxFilters); + assert( sts[0]->hTcxCfg->pCurrentTnsConfig->nMaxFilters == sts[1]->hTcxCfg->pCurrentTnsConfig->nMaxFilters ); #endif - for (iFilter = sts[0]->hTcxCfg->pCurrentTnsConfig->nMaxFilters - 1; iFilter >= 0; iFilter--) + for ( iFilter = sts[0]->hTcxCfg->pCurrentTnsConfig->nMaxFilters - 1; iFilter >= 0; iFilter-- ) { - STnsFilter* pFilter[2]; - struct TnsParameters const* pTnsParameters[2]; + STnsFilter *pFilter[2]; + struct TnsParameters const *pTnsParameters[2]; pFilter[0] = sts[0]->hTcxEnc->tnsData[k].filter + iFilter; pTnsParameters[0] = sts[0]->hTcxCfg->pCurrentTnsConfig->pTnsParameters + iFilter; pFilter[1] = sts[1]->hTcxEnc->tnsData[k].filter + iFilter; pTnsParameters[1] = sts[1]->hTcxCfg->pCurrentTnsConfig->pTnsParameters + iFilter; #ifdef DEBUGGING - assert(pTnsParameters[0]->startLineFrequency == pTnsParameters[1]->startLineFrequency); - assert(pTnsParameters[0]->nSubdivisions == pTnsParameters[1]->nSubdivisions); + assert( pTnsParameters[0]->startLineFrequency == pTnsParameters[1]->startLineFrequency ); + assert( pTnsParameters[0]->nSubdivisions == pTnsParameters[1]->nSubdivisions ); #endif /* if prediction gain and avgSqrCoef are both close we are pretty sure the filters are quite similar, use the avg of * both filters for the decision */ - meanPredictionGain = (pFilter[0]->predictionGain + pFilter[1]->predictionGain) * 0.5f; - maxPredictionGain = max(maxPredictionGain, meanPredictionGain); + meanPredictionGain = ( pFilter[0]->predictionGain + pFilter[1]->predictionGain ) * 0.5f; + maxPredictionGain = max( maxPredictionGain, meanPredictionGain ); - if ((pFilter[0]->predictionGain > pTnsParameters[0]->minPredictionGain) && (sts[0]->element_brate < IVAS_80k) && - (pFilter[1]->predictionGain > pTnsParameters[1]->minPredictionGain) && (sts[0]->hTcxEnc->tnsData[k].nFilters == sts[1]->hTcxEnc->tnsData[k].nFilters)) + if ( ( pFilter[0]->predictionGain > pTnsParameters[0]->minPredictionGain ) && ( sts[0]->element_brate < IVAS_80k ) && + ( pFilter[1]->predictionGain > pTnsParameters[1]->minPredictionGain ) && ( sts[0]->hTcxEnc->tnsData[k].nFilters == sts[1]->hTcxEnc->tnsData[k].nFilters ) ) { pFilter[0]->predictionGain = pFilter[1]->predictionGain = meanPredictionGain; /* more TNS filter sync at 48kbps */ } - if ((fabs(pFilter[0]->predictionGain - pFilter[1]->predictionGain) < SIMILAR_TNS_THRESHOLD * meanPredictionGain) && - (sts[0]->hTcxEnc->tnsData[k].nFilters == sts[1]->hTcxEnc->tnsData[k].nFilters)) + if ( ( fabs( pFilter[0]->predictionGain - pFilter[1]->predictionGain ) < SIMILAR_TNS_THRESHOLD * meanPredictionGain ) && + ( sts[0]->hTcxEnc->tnsData[k].nFilters == sts[1]->hTcxEnc->tnsData[k].nFilters ) ) { - float maxAvgSqrCoef = max(pFilter[0]->avgSqrCoef, pFilter[1]->avgSqrCoef); - float meanLtpGain = (sts[0]->hTcxEnc->tcxltp_gain + sts[1]->hTcxEnc->tcxltp_gain) * 0.5f; - maxPredGain = max(maxPredGain, meanPredictionGain); - if ((meanPredictionGain > pTnsParameters[0]->minPredictionGain) || (maxAvgSqrCoef > pTnsParameters[0]->minAvgSqrCoef)) + float maxAvgSqrCoef = max( pFilter[0]->avgSqrCoef, pFilter[1]->avgSqrCoef ); + float meanLtpGain = ( sts[0]->hTcxEnc->tcxltp_gain + sts[1]->hTcxEnc->tcxltp_gain ) * 0.5f; + maxPredGain = max( maxPredGain, meanPredictionGain ); + if ( ( meanPredictionGain > pTnsParameters[0]->minPredictionGain ) || ( maxAvgSqrCoef > pTnsParameters[0]->minAvgSqrCoef ) ) { - if (sts[0]->hTcxEnc->tnsData[k].nFilters > 0 || sts[1]->hTcxEnc->tnsData[k].nFilters > 0 || isTCX10 || meanLtpGain < 0.6f) + if ( sts[0]->hTcxEnc->tnsData[k].nFilters > 0 || sts[1]->hTcxEnc->tnsData[k].nFilters > 0 || isTCX10 || meanLtpGain < 0.6f ) { ++sts[0]->hTcxEnc->tnsData[k].nFilters; pFilter[0]->filterType = TNS_FILTER_ON; @@ -327,9 +325,9 @@ void TNSAnalysisStereo( } else { - const float maxEnergyChange = (GetTCXMaxenergyChange(sts[0]->hTranDet, isTCX10, NSUBBLOCKS, 3) + GetTCXMaxenergyChange(sts[1]->hTranDet, isTCX10, NSUBBLOCKS, 3)) * 0.5f; + const float maxEnergyChange = ( GetTCXMaxenergyChange( sts[0]->hTranDet, isTCX10, NSUBBLOCKS, 3 ) + GetTCXMaxenergyChange( sts[1]->hTranDet, isTCX10, NSUBBLOCKS, 3 ) ) * 0.5f; - if (maxEnergyChange >= pTnsParameters[0]->minEnergyChange) + if ( maxEnergyChange >= pTnsParameters[0]->minEnergyChange ) { ++sts[0]->hTcxEnc->tnsData[k].nFilters; pFilter[0]->filterType = TNS_FILTER_ON; @@ -343,39 +341,39 @@ void TNSAnalysisStereo( } } } - else if (sts[0]->hTcxEnc->tnsData[k].nFilters > 0 && sts[1]->hTcxEnc->tnsData[k].nFilters > 0) /* If a previous filter is turned on */ + else if ( sts[0]->hTcxEnc->tnsData[k].nFilters > 0 && sts[1]->hTcxEnc->tnsData[k].nFilters > 0 ) /* If a previous filter is turned on */ { pFilter[0]->filterType = TNS_FILTER_ON_ZERO; pFilter[1]->filterType = TNS_FILTER_ON_ZERO; ++sts[0]->hTcxEnc->tnsData[k].nFilters; ++sts[1]->hTcxEnc->tnsData[k].nFilters; } - else if (sts[0]->hTcxEnc->tnsData[k].nFilters != sts[1]->hTcxEnc->tnsData[k].nFilters) /* sanity check */ + else if ( sts[0]->hTcxEnc->tnsData[k].nFilters != sts[1]->hTcxEnc->tnsData[k].nFilters ) /* sanity check */ { - assert(0); + assert( 0 ); } else { pFilter[0]->filterType = TNS_FILTER_OFF; pFilter[1]->filterType = TNS_FILTER_OFF; } - if ((pFilter[0]->filterType == TNS_FILTER_ON) && (pFilter[1]->filterType == TNS_FILTER_ON) && (sts[0]->element_brate < IVAS_80k)) + if ( ( pFilter[0]->filterType == TNS_FILTER_ON ) && ( pFilter[1]->filterType == TNS_FILTER_ON ) && ( sts[0]->element_brate < IVAS_80k ) ) { int16_t tmpIntValue = 0; int16_t tmpCoeff[TNS_MAX_FILTER_ORDER]; - int16_t i, maxOrder = max(pFilter[0]->order, pFilter[1]->order); + int16_t i, maxOrder = max( pFilter[0]->order, pFilter[1]->order ); - set_s(tmpCoeff, 0, TNS_MAX_FILTER_ORDER); - for (i = 0; i < maxOrder; i++) + set_s( tmpCoeff, 0, TNS_MAX_FILTER_ORDER ); + for ( i = 0; i < maxOrder; i++ ) { - tmpIntValue = (int16_t)max(tmpIntValue, abs(pFilter[0]->coefIndex[i] - pFilter[1]->coefIndex[i])); + tmpIntValue = (int16_t) max( tmpIntValue, abs( pFilter[0]->coefIndex[i] - pFilter[1]->coefIndex[i] ) ); } - if (tmpIntValue == 1) /* the TNS coefficients are sufficiently similar to equalize the two filters */ + if ( tmpIntValue == 1 ) /* the TNS coefficients are sufficiently similar to equalize the two filters */ { - for (i = maxOrder - 1; i >= 0; i--) + for ( i = maxOrder - 1; i >= 0; i-- ) { - tmpCoeff[i] = (abs(pFilter[0]->coefIndex[i]) < abs(pFilter[1]->coefIndex[i]) ? pFilter[0]->coefIndex[i] : pFilter[1]->coefIndex[i]); - if ((tmpIntValue > 0) && (tmpCoeff[i] == 0)) + tmpCoeff[i] = ( abs( pFilter[0]->coefIndex[i] ) < abs( pFilter[1]->coefIndex[i] ) ? pFilter[0]->coefIndex[i] : pFilter[1]->coefIndex[i] ); + if ( ( tmpIntValue > 0 ) && ( tmpCoeff[i] == 0 ) ) { maxOrder--; } @@ -385,9 +383,9 @@ void TNSAnalysisStereo( } } /* make sure that maxOrder is non zero and not all coefficients are zero (could happen in rare cases) */ - if (maxOrder > 0) + if ( maxOrder > 0 ) { - for (i = TNS_MAX_FILTER_ORDER - 1; i >= 0; i--) + for ( i = TNS_MAX_FILTER_ORDER - 1; i >= 0; i-- ) { pFilter[0]->coefIndex[i] = pFilter[1]->coefIndex[i] = tmpCoeff[i]; } @@ -403,10 +401,10 @@ void TNSAnalysisStereo( } } - if (individual_decision[k] == 0) + if ( individual_decision[k] == 0 ) { - sts[0]->hTcxEnc->fUseTns[k] = (sts[0]->hTcxEnc->tnsData[k].nFilters > 0) ? 1 : 0; - sts[1]->hTcxEnc->fUseTns[k] = (sts[1]->hTcxEnc->tnsData[k].nFilters > 0) ? 1 : 0; + sts[0]->hTcxEnc->fUseTns[k] = ( sts[0]->hTcxEnc->tnsData[k].nFilters > 0 ) ? 1 : 0; + sts[1]->hTcxEnc->fUseTns[k] = ( sts[1]->hTcxEnc->tnsData[k].nFilters > 0 ) ? 1 : 0; } else { @@ -414,14 +412,14 @@ void TNSAnalysisStereo( sts[1]->hTcxEnc->tnsData[k].nFilters = 0; sts[0]->hTcxEnc->fUseTns[k] = 0; sts[1]->hTcxEnc->fUseTns[k] = 0; - for (iFilter = sts[0]->hTcxCfg->pCurrentTnsConfig->nMaxFilters - 1; iFilter >= 0; iFilter--) + for ( iFilter = sts[0]->hTcxCfg->pCurrentTnsConfig->nMaxFilters - 1; iFilter >= 0; iFilter-- ) { sts[0]->hTcxEnc->tnsData[k].filter[iFilter].filterType = TNS_FILTER_OFF; sts[1]->hTcxEnc->tnsData[k].filter[iFilter].filterType = TNS_FILTER_OFF; } } - if (!bWhitenedDomain && individual_decision[k] == 0 && maxPredGain < TNS_GAIN_THRESHOLD_FOR_WHITE && sts[0]->hTcxEnc->transform_type[k] != TCX_5) + if ( !bWhitenedDomain && individual_decision[k] == 0 && maxPredGain < TNS_GAIN_THRESHOLD_FOR_WHITE && sts[0]->hTcxEnc->transform_type[k] != TCX_5 ) { sts[0]->hTcxEnc->bTnsOnWhithenedSpectra[k] = 1; sts[1]->hTcxEnc->bTnsOnWhithenedSpectra[k] = 1; @@ -429,60 +427,60 @@ void TNSAnalysisStereo( sts[1]->hTcxEnc->tnsData[k].nFilters = 0; sts[0]->hTcxEnc->fUseTns[k] = 0; sts[1]->hTcxEnc->fUseTns[k] = 0; - for (iFilter = sts[0]->hTcxCfg->pCurrentTnsConfig->nMaxFilters - 1; iFilter >= 0; iFilter--) + for ( iFilter = sts[0]->hTcxCfg->pCurrentTnsConfig->nMaxFilters - 1; iFilter >= 0; iFilter-- ) { - ClearTnsFilterCoefficients(sts[0]->hTcxEnc->tnsData[k].filter + iFilter); - ClearTnsFilterCoefficients(sts[1]->hTcxEnc->tnsData[k].filter + iFilter); + ClearTnsFilterCoefficients( sts[0]->hTcxEnc->tnsData[k].filter + iFilter ); + ClearTnsFilterCoefficients( sts[1]->hTcxEnc->tnsData[k].filter + iFilter ); } } - maxPredictionGain = max(maxPredictionGain, maxPredGain); + maxPredictionGain = max( maxPredictionGain, maxPredGain ); } } } } /* individual decision for each channel */ - for (ch = 0; ch < CPE_CHANNELS; ch++) + for ( ch = 0; ch < CPE_CHANNELS; ch++ ) { - if (sts[ch]->mct_chan_mode == MCT_CHAN_MODE_IGNORE) + if ( sts[ch]->mct_chan_mode == MCT_CHAN_MODE_IGNORE ) { continue; } int16_t isTCX10; - isTCX10 = (sts[ch]->hTcxEnc->tcxMode == TCX_20) ? 0 : 1; + isTCX10 = ( sts[ch]->hTcxEnc->tcxMode == TCX_20 ) ? 0 : 1; - nSubframes = (sts[ch]->hTcxEnc->tcxMode == TCX_20) ? 1 : NB_DIV; + nSubframes = ( sts[ch]->hTcxEnc->tcxMode == TCX_20 ) ? 1 : NB_DIV; - for (k = 0; k < nSubframes; k++) + for ( k = 0; k < nSubframes; k++ ) { - if (sts[ch]->hTcxCfg->fIsTNSAllowed && (individual_decision[k] || mct_on) && - (!bWhitenedDomain || sts[ch]->hTcxEnc->bTnsOnWhithenedSpectra[k])) + if ( sts[ch]->hTcxCfg->fIsTNSAllowed && ( individual_decision[k] || mct_on ) && + ( !bWhitenedDomain || sts[ch]->hTcxEnc->bTnsOnWhithenedSpectra[k] ) ) { float maxPredGain = -1.0f; - sts[ch]->hTcxCfg->pCurrentTnsConfig = &sts[ch]->hTcxCfg->tnsConfig[sts[ch]->hTcxEnc->transform_type[k] == TCX_20][(k == 0) && (sts[ch]->last_core == ACELP_CORE)]; + sts[ch]->hTcxCfg->pCurrentTnsConfig = &sts[ch]->hTcxCfg->tnsConfig[sts[ch]->hTcxEnc->transform_type[k] == TCX_20][( k == 0 ) && ( sts[ch]->last_core == ACELP_CORE )]; - for (iFilter = sts[ch]->hTcxCfg->pCurrentTnsConfig->nMaxFilters - 1; iFilter >= 0; iFilter--) + for ( iFilter = sts[ch]->hTcxCfg->pCurrentTnsConfig->nMaxFilters - 1; iFilter >= 0; iFilter-- ) { - STnsFilter* pFilter; - const struct TnsParameters* pTnsParameters; + STnsFilter *pFilter; + const struct TnsParameters *pTnsParameters; pFilter = sts[ch]->hTcxEnc->tnsData[k].filter + iFilter; pTnsParameters = sts[ch]->hTcxCfg->pCurrentTnsConfig->pTnsParameters + iFilter; - maxPredGain = max(maxPredGain, pFilter->predictionGain); + maxPredGain = max( maxPredGain, pFilter->predictionGain ); - if ((pFilter->predictionGain > pTnsParameters->minPredictionGain) || (pFilter->avgSqrCoef > pTnsParameters->minAvgSqrCoef)) + if ( ( pFilter->predictionGain > pTnsParameters->minPredictionGain ) || ( pFilter->avgSqrCoef > pTnsParameters->minAvgSqrCoef ) ) { - if (sts[ch]->hTcxEnc->tnsData[k].nFilters > 0 || isTCX10 || sts[ch]->hTcxEnc->tcxltp_gain < 0.6f) + if ( sts[ch]->hTcxEnc->tnsData[k].nFilters > 0 || isTCX10 || sts[ch]->hTcxEnc->tcxltp_gain < 0.6f ) { ++sts[ch]->hTcxEnc->tnsData[k].nFilters; pFilter->filterType = TNS_FILTER_ON; } else { - const float maxEnergyChange = GetTCXMaxenergyChange(sts[ch]->hTranDet, isTCX10, NSUBBLOCKS, 3); + const float maxEnergyChange = GetTCXMaxenergyChange( sts[ch]->hTranDet, isTCX10, NSUBBLOCKS, 3 ); - if (maxEnergyChange >= pTnsParameters->minEnergyChange) + if ( maxEnergyChange >= pTnsParameters->minEnergyChange ) { ++sts[ch]->hTcxEnc->tnsData[k].nFilters; pFilter->filterType = TNS_FILTER_ON; @@ -493,7 +491,7 @@ void TNSAnalysisStereo( } } } - else if (sts[ch]->hTcxEnc->tnsData[k].nFilters > 0) /* If a previous filter is turned on */ + else if ( sts[ch]->hTcxEnc->tnsData[k].nFilters > 0 ) /* If a previous filter is turned on */ { pFilter->filterType = TNS_FILTER_ON_ZERO; ++sts[ch]->hTcxEnc->tnsData[k].nFilters; @@ -504,55 +502,55 @@ void TNSAnalysisStereo( } } - sts[ch]->hTcxEnc->fUseTns[k] = (sts[ch]->hTcxEnc->tnsData[k].nFilters > 0) ? 1 : 0; + sts[ch]->hTcxEnc->fUseTns[k] = ( sts[ch]->hTcxEnc->tnsData[k].nFilters > 0 ) ? 1 : 0; - if (!bWhitenedDomain && maxPredGain < TNS_GAIN_THRESHOLD_FOR_WHITE && sts[ch]->hTcxEnc->transform_type[k] != TCX_5) + if ( !bWhitenedDomain && maxPredGain < TNS_GAIN_THRESHOLD_FOR_WHITE && sts[ch]->hTcxEnc->transform_type[k] != TCX_5 ) { sts[ch]->hTcxEnc->fUseTns[k] = 0; sts[ch]->hTcxEnc->bTnsOnWhithenedSpectra[k] = 1; sts[ch]->hTcxEnc->tnsData[k].nFilters = 0; - for (iFilter = sts[ch]->hTcxCfg->pCurrentTnsConfig->nMaxFilters - 1; iFilter >= 0; iFilter--) + for ( iFilter = sts[ch]->hTcxCfg->pCurrentTnsConfig->nMaxFilters - 1; iFilter >= 0; iFilter-- ) { - ClearTnsFilterCoefficients(sts[ch]->hTcxEnc->tnsData[k].filter + iFilter); + ClearTnsFilterCoefficients( sts[ch]->hTcxEnc->tnsData[k].filter + iFilter ); sts[ch]->hTcxEnc->tnsData[k].filter[iFilter].filterType = TNS_FILTER_OFF; } } - maxPredictionGain = max(maxPredictionGain, maxPredGain); + maxPredictionGain = max( maxPredictionGain, maxPredGain ); } } } /* we have the decision, set filter data accordingly */ - for (ch = 0; ch < CPE_CHANNELS; ch++) + for ( ch = 0; ch < CPE_CHANNELS; ch++ ) { - if (sts[ch]->mct_chan_mode == MCT_CHAN_MODE_IGNORE) + if ( sts[ch]->mct_chan_mode == MCT_CHAN_MODE_IGNORE ) { continue; } - nSubframes = (sts[ch]->hTcxEnc->tcxMode == TCX_20) ? 1 : NB_DIV; + nSubframes = ( sts[ch]->hTcxEnc->tcxMode == TCX_20 ) ? 1 : NB_DIV; - for (k = 0; k < nSubframes; k++) + for ( k = 0; k < nSubframes; k++ ) { - if (sts[ch]->hTcxCfg->fIsTNSAllowed && (!bWhitenedDomain || sts[ch]->hTcxEnc->bTnsOnWhithenedSpectra[k])) + if ( sts[ch]->hTcxCfg->fIsTNSAllowed && ( !bWhitenedDomain || sts[ch]->hTcxEnc->bTnsOnWhithenedSpectra[k] ) ) { - sts[ch]->hTcxCfg->pCurrentTnsConfig = &sts[ch]->hTcxCfg->tnsConfig[sts[ch]->hTcxEnc->transform_type[k] == TCX_20][(k == 0) && (sts[ch]->last_core == ACELP_CORE)]; + sts[ch]->hTcxCfg->pCurrentTnsConfig = &sts[ch]->hTcxCfg->tnsConfig[sts[ch]->hTcxEnc->transform_type[k] == TCX_20][( k == 0 ) && ( sts[ch]->last_core == ACELP_CORE )]; - for (iFilter = sts[ch]->hTcxCfg->pCurrentTnsConfig->nMaxFilters - 1; iFilter >= 0; iFilter--) + for ( iFilter = sts[ch]->hTcxCfg->pCurrentTnsConfig->nMaxFilters - 1; iFilter >= 0; iFilter-- ) { - STnsFilter* pFilter; + STnsFilter *pFilter; pFilter = sts[ch]->hTcxEnc->tnsData[k].filter + iFilter; - switch (pFilter->filterType) + switch ( pFilter->filterType ) { - case TNS_FILTER_OFF: - ClearTnsFilterCoefficients(sts[ch]->hTcxEnc->tnsData[k].filter + iFilter); - break; - case TNS_FILTER_ON_ZERO: - /* Since TNS filter of order 0 is not allowed we have to signal in the stream filter of order 1 with the 0th coefficient equal to 0 */ - ClearTnsFilterCoefficients(pFilter); - pFilter->order = 1; - break; + case TNS_FILTER_OFF: + ClearTnsFilterCoefficients( sts[ch]->hTcxEnc->tnsData[k].filter + iFilter ); + break; + case TNS_FILTER_ON_ZERO: + /* Since TNS filter of order 0 is not allowed we have to signal in the stream filter of order 1 with the 0th coefficient equal to 0 */ + ClearTnsFilterCoefficients( pFilter ); + pFilter->order = 1; + break; } } } @@ -560,77 +558,77 @@ void TNSAnalysisStereo( } /* Apply filters, loop over channels */ - for (ch = 0; ch < CPE_CHANNELS; ch++) + for ( ch = 0; ch < CPE_CHANNELS; ch++ ) { st = sts[ch]; - if (st->mct_chan_mode == MCT_CHAN_MODE_IGNORE) + if ( st->mct_chan_mode == MCT_CHAN_MODE_IGNORE ) { continue; } - nSubframes = (st->hTcxEnc->tcxMode == TCX_20) ? 1 : NB_DIV; + nSubframes = ( st->hTcxEnc->tcxMode == TCX_20 ) ? 1 : NB_DIV; - for (k = 0; k < nSubframes; k++) + for ( k = 0; k < nSubframes; k++ ) { - if (bWhitenedDomain && (ch > 0) && /* test for identical TNS filter data in both channels */ - sts[0]->hTcxCfg->fIsTNSAllowed && sts[0]->hTcxEnc->fUseTns[k] && - sts[1]->hTcxCfg->fIsTNSAllowed && sts[1]->hTcxEnc->fUseTns[k]) + if ( bWhitenedDomain && ( ch > 0 ) && /* test for identical TNS filter data in both channels */ + sts[0]->hTcxCfg->fIsTNSAllowed && sts[0]->hTcxEnc->fUseTns[k] && + sts[1]->hTcxCfg->fIsTNSAllowed && sts[1]->hTcxEnc->fUseTns[k] ) { - int16_t equalFilterData = (sts[0]->hTcxCfg->pCurrentTnsConfig->nMaxFilters == sts[1]->hTcxCfg->pCurrentTnsConfig->nMaxFilters && - sts[0]->hTcxEnc->bTnsOnWhithenedSpectra[k] == sts[1]->hTcxEnc->bTnsOnWhithenedSpectra[k] && - sts[0]->hTcxEnc->tnsData[k].nFilters == sts[1]->hTcxEnc->tnsData[k].nFilters) - ? 1 - : 0; - if (equalFilterData) + int16_t equalFilterData = ( sts[0]->hTcxCfg->pCurrentTnsConfig->nMaxFilters == sts[1]->hTcxCfg->pCurrentTnsConfig->nMaxFilters && + sts[0]->hTcxEnc->bTnsOnWhithenedSpectra[k] == sts[1]->hTcxEnc->bTnsOnWhithenedSpectra[k] && + sts[0]->hTcxEnc->tnsData[k].nFilters == sts[1]->hTcxEnc->tnsData[k].nFilters ) + ? 1 + : 0; + if ( equalFilterData ) { - for (iFilter = st->hTcxCfg->pCurrentTnsConfig->nMaxFilters - 1; iFilter >= 0; iFilter--) + for ( iFilter = st->hTcxCfg->pCurrentTnsConfig->nMaxFilters - 1; iFilter >= 0; iFilter-- ) { - const int16_t* pDataCh0 = (const int16_t*)&sts[0]->hTcxEnc->tnsData[k].filter[iFilter]; - const int16_t* pDataCh1 = (const int16_t*)&sts[1]->hTcxEnc->tnsData[k].filter[iFilter]; + const int16_t *pDataCh0 = (const int16_t *) &sts[0]->hTcxEnc->tnsData[k].filter[iFilter]; + const int16_t *pDataCh1 = (const int16_t *) &sts[1]->hTcxEnc->tnsData[k].filter[iFilter]; int16_t i = 2 + TNS_MAX_FILTER_ORDER; /* excl. informative float data. Portable? */ - while ((i >= 0) && (pDataCh0[i] == pDataCh1[i])) + while ( ( i >= 0 ) && ( pDataCh0[i] == pDataCh1[i] ) ) { i--; } - if (i >= 0) + if ( i >= 0 ) { equalFilterData = 0; break; } } - if (equalFilterData) + if ( equalFilterData ) { st->hTcxEnc->tnsData[k].nFilters *= -1; /* signals common TNS */ } } } - if (st->hTcxCfg->fIsTNSAllowed && (!bWhitenedDomain || st->hTcxEnc->bTnsOnWhithenedSpectra[k])) + if ( st->hTcxCfg->fIsTNSAllowed && ( !bWhitenedDomain || st->hTcxEnc->bTnsOnWhithenedSpectra[k] ) ) { L_spec = st->hTcxCfg->pCurrentTnsConfig->iFilterBorders[0]; spectrum = st->hTcxEnc->spectrum[k]; /* If TNS should be used then get the residual after applying it inplace in the spectrum */ - if (st->hTcxEnc->fUseTns[k]) + if ( st->hTcxEnc->fUseTns[k] ) { - st->hTcxCfg->pCurrentTnsConfig = &st->hTcxCfg->tnsConfig[st->hTcxEnc->transform_type[k] == TCX_20][(k == 0) && (st->last_core == ACELP_CORE)]; + st->hTcxCfg->pCurrentTnsConfig = &st->hTcxCfg->tnsConfig[st->hTcxEnc->transform_type[k] == TCX_20][( k == 0 ) && ( st->last_core == ACELP_CORE )]; - ApplyTnsFilter(st->hTcxCfg->pCurrentTnsConfig, &st->hTcxEnc->tnsData[k], spectrum, 1); + ApplyTnsFilter( st->hTcxCfg->pCurrentTnsConfig, &st->hTcxEnc->tnsData[k], spectrum, 1 ); } - if (st->hTcxEnc->transform_type[k] == TCX_5) + if ( st->hTcxEnc->transform_type[k] == TCX_5 ) { - tcx5TnsUngrouping(L_frame >> 2, L_spec >> 1, st->hTcxEnc->spectrum[k], ENC); + tcx5TnsUngrouping( L_frame >> 2, L_spec >> 1, st->hTcxEnc->spectrum[k], ENC ); } st->hTcxEnc->tnsData[k].tnsOnWhitenedSpectra = st->hTcxEnc->bTnsOnWhithenedSpectra[k]; - EncodeTnsData(st->hTcxCfg->pCurrentTnsConfig, &st->hTcxEnc->tnsData[k], param_core[ch] + k * NPRM_DIV + 1 + NOISE_FILL_RANGES + LTPSIZE, tnsSize[ch] + k, tnsBits[ch] + k); + EncodeTnsData( st->hTcxCfg->pCurrentTnsConfig, &st->hTcxEnc->tnsData[k], param_core[ch] + k * NPRM_DIV + 1 + NOISE_FILL_RANGES + LTPSIZE, tnsSize[ch] + k, tnsBits[ch] + k ); } - if (st->hTcxEnc->transform_type[k] == TCX_5) + if ( st->hTcxEnc->transform_type[k] == TCX_5 ) { - tcx5SpectrumInterleaving(st->hTcxCfg->tcx5SizeFB, st->hTcxEnc->spectrum[k]); - tcx5SpectrumInterleaving(st->hTcxCfg->tcx5SizeFB, mdst_spectrum[ch][k]); + tcx5SpectrumInterleaving( st->hTcxCfg->tcx5SizeFB, st->hTcxEnc->spectrum[k] ); + tcx5SpectrumInterleaving( st->hTcxCfg->tcx5SizeFB, mdst_spectrum[ch][k] ); } } } @@ -642,18 +640,17 @@ void TNSAnalysisStereo( #endif void TNSAnalysis_fx( TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */ - Word16 L_frame, /* input: frame length */ + Word16 L_frame, /* input: frame length */ Word16 L_spec, - Word16 tcxMode, /* input: TCX mode for the frame/subframe - TCX20 | TCX10 | TCX 5 (meaning 2 x TCX 5) */ - Word8 isAfterACELP, /* input: Flag indicating if the last frame was ACELP. For the second TCX subframe it should be 0 */ - Word32 spectrum[], /* input: MDCT spectrum */ - STnsData * pTnsData, /* output: Tns data */ - Word8 * pfUseTns, /* output: Flag indicating if TNS is used */ - Word16 *predictionGain -) + Word16 tcxMode, /* input: TCX mode for the frame/subframe - TCX20 | TCX10 | TCX 5 (meaning 2 x TCX 5) */ + Word8 isAfterACELP, /* input: Flag indicating if the last frame was ACELP. For the second TCX subframe it should be 0 */ + Word32 spectrum[], /* input: MDCT spectrum */ + STnsData *pTnsData, /* output: Tns data */ + Word8 *pfUseTns, /* output: Flag indicating if TNS is used */ + Word16 *predictionGain ) { Word32 buff[8]; - Word16 tmp = 0; /* initialization only to avoid compiler warning, not counted */ + Word16 tmp = 0; /* initialization only to avoid compiler warning, not counted */ Word16 tmp2 = 0; /* initialization only to avoid compiler warning, not counted */ @@ -661,9 +658,9 @@ void TNSAnalysis_fx( *pfUseTns = 0; move16(); - IF (hTcxCfg->fIsTNSAllowed != 0) + IF( hTcxCfg->fIsTNSAllowed != 0 ) { - hTcxCfg->pCurrentTnsConfig = &hTcxCfg->tnsConfig[sub(tcxMode, TCX_20) == 0][isAfterACELP]; + hTcxCfg->pCurrentTnsConfig = &hTcxCfg->tnsConfig[sub( tcxMode, TCX_20 ) == 0][isAfterACELP]; test(); L_spec = hTcxCfg->pCurrentTnsConfig->iFilterBorders[0]; move16(); @@ -672,72 +669,70 @@ void TNSAnalysis_fx( * Temporal Noise Shaping analysis * *-----------------------------------------------------------*/ - IF (EQ_16(tcxMode, TCX_5)) + IF( EQ_16( tcxMode, TCX_5 ) ) { - tmp = shr(L_frame,2); + tmp = shr( L_frame, 2 ); /* rearrange LF sub-window lines prior to TNS analysis & filtering */ - tmp2 = shr(L_spec,1); + tmp2 = shr( L_spec, 1 ); - IF (LT_16(tmp2, tmp)) + IF( LT_16( tmp2, tmp ) ) { - Copy32(spectrum+8, spectrum+16, sub(tmp2, 8)); - Copy32(spectrum+tmp, spectrum+8, 8); - Copy32(spectrum+tmp+8, spectrum+tmp2+8, sub(tmp2, 8)); + Copy32( spectrum + 8, spectrum + 16, sub( tmp2, 8 ) ); + Copy32( spectrum + tmp, spectrum + 8, 8 ); + Copy32( spectrum + tmp + 8, spectrum + tmp2 + 8, sub( tmp2, 8 ) ); } ELSE { - Copy32(spectrum+tmp, buff, 8); - Copy32(spectrum+8, spectrum+16, sub(tmp, 8)); - Copy32(buff, spectrum+8, 8); + Copy32( spectrum + tmp, buff, 8 ); + Copy32( spectrum + 8, spectrum + 16, sub( tmp, 8 ) ); + Copy32( buff, spectrum + 8, 8 ); } } move16(); - *pfUseTns = (Word8)DetectTnsFilt_fx(hTcxCfg->pCurrentTnsConfig, spectrum, pTnsData, predictionGain); + *pfUseTns = (Word8) DetectTnsFilt_fx( hTcxCfg->pCurrentTnsConfig, spectrum, pTnsData, predictionGain ); /* If TNS should be used then get the residual after applying it inplace in spectrum */ - IF (*pfUseTns != 0) + IF( *pfUseTns != 0 ) { - ApplyTnsFilter(hTcxCfg->pCurrentTnsConfig, pTnsData, spectrum, 1); + ApplyTnsFilter( hTcxCfg->pCurrentTnsConfig, pTnsData, spectrum, 1 ); } - IF (EQ_16(tcxMode, TCX_5)) + IF( EQ_16( tcxMode, TCX_5 ) ) { /* undo rearrangement of LF sub-window lines prior to TNS analysis */ - IF (LT_16(tmp2, tmp)) + IF( LT_16( tmp2, tmp ) ) { - Copy32(spectrum+tmp2+8, spectrum+tmp+8, sub(tmp2, 8)); - Copy32(spectrum+8, spectrum+tmp, 8); - Copy32(spectrum+16, spectrum+8, sub(tmp2, 8)); - set32_fx(spectrum+tmp2, 0, sub(tmp,tmp2)); - set32_fx(spectrum+tmp+tmp2, 0, sub(tmp,tmp2)); + Copy32( spectrum + tmp2 + 8, spectrum + tmp + 8, sub( tmp2, 8 ) ); + Copy32( spectrum + 8, spectrum + tmp, 8 ); + Copy32( spectrum + 16, spectrum + 8, sub( tmp2, 8 ) ); + set32_fx( spectrum + tmp2, 0, sub( tmp, tmp2 ) ); + set32_fx( spectrum + tmp + tmp2, 0, sub( tmp, tmp2 ) ); } ELSE { - Copy32(spectrum+8, buff, 8); - Copy32(spectrum+16, spectrum+8, sub(tmp, 8)); - Copy32(buff, spectrum+tmp, 8); + Copy32( spectrum + 8, buff, 8 ); + Copy32( spectrum + 16, spectrum + 8, sub( tmp, 8 ) ); + Copy32( buff, spectrum + tmp, 8 ); } } } - } void ShapeSpectrum_fx( TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */ - Word16 A[], /* input: quantized coefficients NxAz_q[M+1] */ - Word16 gainlpc[], /* output: MDCT gains for the previous frame */ - Word16 gainlpc_e[], /* output: MDCT gains exponents */ - Word16 L_frame_glob,/* input: frame length */ + Word16 A[], /* input: quantized coefficients NxAz_q[M+1] */ + Word16 gainlpc[], /* output: MDCT gains for the previous frame */ + Word16 gainlpc_e[], /* output: MDCT gains exponents */ + Word16 L_frame_glob, /* input: frame length */ Word16 L_spec, - Word32 spectrum[], /* i/o: MDCT spectrum */ - Word8 pfUseTns, /* output: Flag indicating if TNS is used */ - Encoder_State *st -) + Word32 spectrum[], /* i/o: MDCT spectrum */ + Word8 pfUseTns, /* output: Flag indicating if TNS is used */ + Encoder_State *st ) { Word16 L_frame; - Word16 Ap[M+2]; + Word16 Ap[M + 2]; Word16 gamma1; Word16 gainlpc_noinv[FDNS_NPTS]; Word16 gainlpc_noinv_e[FDNS_NPTS]; @@ -754,7 +749,7 @@ void ShapeSpectrum_fx( move16(); gamma1 = st->gamma; move16(); - if (st->enableTcxLpc != 0) + if ( st->enableTcxLpc != 0 ) { gamma1 = 0x7FFF; move16(); @@ -762,57 +757,57 @@ void ShapeSpectrum_fx( /* if past frame is ACELP */ - IF (st->last_core == ACELP_CORE) + IF( st->last_core == ACELP_CORE ) { - L_frame = add(L_frame, hTcxCfg->tcx_offset); - L_spec = add(L_spec, shr(hTcxCfg->tcx_coded_lines, 2)); - if(hTcxCfg->lfacNext<0) + L_frame = add( L_frame, hTcxCfg->tcx_offset ); + L_spec = add( L_spec, shr( hTcxCfg->tcx_coded_lines, 2 ) ); + if ( hTcxCfg->lfacNext < 0 ) { - L_frame = sub(L_frame,hTcxCfg->lfacNext); + L_frame = sub( L_frame, hTcxCfg->lfacNext ); move16(); } } test(); - tcxGetNoiseFillingTilt(A, - M, - L_frame, - (GE_32(st->total_brate, ACELP_13k20) && st->rf_mode == 0 ), - &hTcxEnc->noiseTiltFactor); + tcxGetNoiseFillingTilt( A, + M, + L_frame, + ( GE_32( st->total_brate, ACELP_13k20 ) && st->rf_mode == 0 ), + &hTcxEnc->noiseTiltFactor ); /* Calculate Spectrum Flatness Measure for the TCX Concealment */ - IF (st->enablePlcWaveadjust) + IF( st->enablePlcWaveadjust ) { - hTcxCfg->SFM2 = SFM_Cal_fx(spectrum, s_min(200, L_frame)); + hTcxCfg->SFM2 = SFM_Cal_fx( spectrum, s_min( 200, L_frame ) ); } test(); test(); test(); - IF( (EQ_32(st->total_brate, ACELP_9k60)&&EQ_16(st->bwidth,SWB))|| - (EQ_32(st->total_brate, ACELP_13k20) && EQ_16(st->bwidth, SWB) ) ) + IF( ( EQ_32( st->total_brate, ACELP_9k60 ) && EQ_16( st->bwidth, SWB ) ) || + ( EQ_32( st->total_brate, ACELP_13k20 ) && EQ_16( st->bwidth, SWB ) ) ) { max_low_pre = 0; move32(); - FOR (i = 0; i < L_frame; i++) + FOR( i = 0; i < L_frame; i++ ) { - Word32 tmp = L_abs(spectrum[i]); - if( GT_32(tmp, max_low_pre)) + Word32 tmp = L_abs( spectrum[i] ); + if ( GT_32( tmp, max_low_pre ) ) { - max_low_pre = tmp; - move32(); + max_low_pre = tmp; + move32(); } } max_high_pre = 0; move32(); - for (i = 0; i < L_spec - L_frame; i++) + for ( i = 0; i < L_spec - L_frame; i++ ) { - Word32 tmp = L_abs(spectrum[L_frame + i]); - if( GT_32( tmp, max_high_pre)) + Word32 tmp = L_abs( spectrum[L_frame + i] ); + if ( GT_32( tmp, max_high_pre ) ) { max_high_pre = tmp; - move32(); + move32(); } } } @@ -823,19 +818,19 @@ void ShapeSpectrum_fx( weight_a_fx( A, Ap, gamma1, M ); - lpc2mdct( Ap, M, gainlpc_noinv, gainlpc_noinv_e, gainlpc, gainlpc_e, FDNS_NPTS, 0); + lpc2mdct( Ap, M, gainlpc_noinv, gainlpc_noinv_e, gainlpc, gainlpc_e, FDNS_NPTS, 0 ); mdct_shaping( spectrum, L_frame, gainlpc_noinv, gainlpc_noinv_e ); - FOR (i = L_frame; i < L_spec; i++) + FOR( i = L_frame; i < L_spec; i++ ) { - spectrum[i] = L_shl(Mpy_32_16_1(spectrum[i], gainlpc_noinv[FDNS_NPTS-1]), gainlpc_noinv_e[FDNS_NPTS-1]); + spectrum[i] = L_shl( Mpy_32_16_1( spectrum[i], gainlpc_noinv[FDNS_NPTS - 1] ), gainlpc_noinv_e[FDNS_NPTS - 1] ); move32(); } /* reduce the peaks in the IGF region, to make life of the core-coder easier... */ test(); - IF( ( EQ_32(st->total_brate, ACELP_9k60)&&EQ_16(st->bwidth,SWB))|| - ( EQ_32(st->total_brate, ACELP_13k20)&&EQ_16(st->bwidth, SWB)) ) + IF( ( EQ_32( st->total_brate, ACELP_9k60 ) && EQ_16( st->bwidth, SWB ) ) || + ( EQ_32( st->total_brate, ACELP_13k20 ) && EQ_16( st->bwidth, SWB ) ) ) { Word16 sf_width; Word16 dist_low, dist_high; @@ -849,26 +844,26 @@ void ShapeSpectrum_fx( /* max_fac = 3 */ max_fac_s = 2; move16(); - if(hTcxEnc->tcx_lpc_shaped_ari ) + if ( hTcxEnc->tcx_lpc_shaped_ari ) { /* max_fac = 1.5 */ max_fac_s = 1; move16(); } - sf_width = shr(L_frame, 1); + sf_width = shr( L_frame, 1 ); max_low2 = 0; move32(); dist_low = 0; move16(); - FOR (i = 0; i < sf_width; i++) + FOR( i = 0; i < sf_width; i++ ) { - Word32 tmp = L_abs(spectrum[L_frame - 1 - i]); - IF( GT_32(tmp, max_low2)) + Word32 tmp = L_abs( spectrum[L_frame - 1 - i] ); + IF( GT_32( tmp, max_low2 ) ) { max_low2 = tmp; - move32(); + move32(); dist_low = i; move16(); } @@ -876,33 +871,33 @@ void ShapeSpectrum_fx( max_low1 = 0; move32(); - FOR (i = 0; i < sub(L_frame, sf_width); i++) + FOR( i = 0; i < sub( L_frame, sf_width ); i++ ) { - Word32 tmp = L_abs(spectrum[L_frame - sf_width - 1 - i]); - if( GT_32(tmp, max_low1)) + Word32 tmp = L_abs( spectrum[L_frame - sf_width - 1 - i] ); + if ( GT_32( tmp, max_low1 ) ) { - max_low1 = tmp; - move32(); + max_low1 = tmp; + move32(); } - if( tmp > max_low2 ) + if ( tmp > max_low2 ) { - dist_low = add(sf_width, i); + dist_low = add( sf_width, i ); } } - max_low = L_max(max_low1, max_low2); + max_low = L_max( max_low1, max_low2 ); max_high = 0; move32(); dist_high = 0; move16(); - FOR (i = 0; i < sub(L_spec, L_frame); i++) + FOR( i = 0; i < sub( L_spec, L_frame ); i++ ) { - Word32 tmp = L_abs(spectrum[L_frame + i]); - if( GT_32(tmp, max_high)) + Word32 tmp = L_abs( spectrum[L_frame + i] ); + if ( GT_32( tmp, max_high ) ) { - max_high = tmp; - move32(); + max_high = tmp; + move32(); dist_high = i; move16(); } @@ -914,34 +909,37 @@ void ShapeSpectrum_fx( headroom = 31; move16(); - tmp16 = norm_l(max_low); - if(max_low != 0) headroom = s_min(headroom, tmp16); + tmp16 = norm_l( max_low ); + if ( max_low != 0 ) + headroom = s_min( headroom, tmp16 ); - tmp16 = norm_l(max_low2); - if(max_low2 != 0) headroom = s_min(headroom, tmp16); + tmp16 = norm_l( max_low2 ); + if ( max_low2 != 0 ) + headroom = s_min( headroom, tmp16 ); - tmp16 = norm_l(max_high); - if(max_high != 0) headroom = s_min(headroom, tmp16); + tmp16 = norm_l( max_high ); + if ( max_high != 0 ) + headroom = s_min( headroom, tmp16 ); - if( LT_16(headroom, 9)) + if ( LT_16( headroom, 9 ) ) { - shift = sub(9, headroom); + shift = sub( 9, headroom ); } - max_low = L_shr(max_low, shift); - max_low2 = L_shr(max_low2, shift); - max_high = L_shr(max_high, shift); + max_low = L_shr( max_low, shift ); + max_low2 = L_shr( max_low2, shift ); + max_high = L_shr( max_high, shift ); test(); test(); - IF( GT_32(imult3216(max_high, dist_high), imult3216(L_shr(max_low, 2), dist_low))&&(GT_32(max_low_pre,L_shr(max_high_pre,4)))&&(GT_32(max_high,L_shl(Mpy_32_16_r(max_low2,max_fac_m),max_fac_s)))) + IF( GT_32( imult3216( max_high, dist_high ), imult3216( L_shr( max_low, 2 ), dist_low ) ) && ( GT_32( max_low_pre, L_shr( max_high_pre, 4 ) ) ) && ( GT_32( max_high, L_shl( Mpy_32_16_r( max_low2, max_fac_m ), max_fac_s ) ) ) ) { Word16 fac; - fac = divide3232(max_low2, max_high); - fac = shl(mult_r( fac, max_fac_m ), max_fac_s); + fac = divide3232( max_low2, max_high ); + fac = shl( mult_r( fac, max_fac_m ), max_fac_s ); - FOR (i = 0; i < sub(L_spec, L_frame); i++) + FOR( i = 0; i < sub( L_spec, L_frame ); i++ ) { - spectrum[L_frame + i] = Mpy_32_16_1(spectrum[L_frame + i], fac); + spectrum[L_frame + i] = Mpy_32_16_1( spectrum[L_frame + i], fac ); } } } @@ -950,11 +948,10 @@ void ShapeSpectrum_fx( test(); test(); test(); - IF( st->tcxonly && hTcxEnc->tcxltp && (hTcxEnc->tcxltp_gain > 0) && !pfUseTns ) + IF( st->tcxonly && hTcxEnc->tcxltp && ( hTcxEnc->tcxltp_gain > 0 ) && !pfUseTns ) { - PsychAdaptLowFreqEmph_fx(spectrum, gainlpc, gainlpc_e); + PsychAdaptLowFreqEmph_fx( spectrum, gainlpc, gainlpc_e ); } - } #ifdef ADD_IVAS_TNS /*-----------------------------------------------------------* @@ -964,8 +961,8 @@ void ShapeSpectrum_fx( *-----------------------------------------------------------*/ void EstimateStereoTCXNoiseLevel( - Encoder_State** sts, /* i : state handle */ - float* q_spectrum[CPE_CHANNELS][NB_DIV], /* i : quantized MDCT spectrum */ + Encoder_State **sts, /* i : state handle */ + float *q_spectrum[CPE_CHANNELS][NB_DIV], /* i : quantized MDCT spectrum */ float gain_tcx[][NB_DIV], /* i : global gain */ int16_t L_frame[][NB_DIV], /* i : frame length */ int16_t noiseFillingBorder[][NB_DIV], /* i : noise filling border */ @@ -980,62 +977,62 @@ void EstimateStereoTCXNoiseLevel( int16_t nSubframes, maxNfCalcBw, iStart, noiseTransWidth; float smooth_gain; float combined_q_spectrum[N_MAX]; - int16_t* fac_ns_q; + int16_t *fac_ns_q; int32_t total_brate; - for (ch = 0; ch < CPE_CHANNELS; ch++) + for ( ch = 0; ch < CPE_CHANNELS; ch++ ) { - Encoder_State* st = sts[ch]; + Encoder_State *st = sts[ch]; TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; - nSubframes = (st->hTcxEnc->tcxMode == TCX_20) ? 1 : NB_DIV; + nSubframes = ( st->hTcxEnc->tcxMode == TCX_20 ) ? 1 : NB_DIV; - if (ignore_chan[ch]) + if ( ignore_chan[ch] ) { continue; } - total_brate = (st->element_mode == IVAS_CPE_MDCT && !MCT_flag) ? st->element_brate : st->total_brate; + total_brate = ( st->element_mode == IVAS_CPE_MDCT && !MCT_flag ) ? st->element_brate : st->total_brate; - for (n = 0; n < nSubframes; n++) + for ( n = 0; n < nSubframes; n++ ) { fac_ns_q = param_core[ch] + n * NPRM_DIV + 1; - maxNfCalcBw = min(noiseFillingBorder[ch][n], (int16_t)(hTcxEnc->measuredBwRatio * (float)L_frame[ch][n] + 0.5f)); - if ((total_brate >= HQ_96k && (st->element_mode <= IVAS_SCE || st->bwidth < SWB)) || total_brate > IVAS_192k) + maxNfCalcBw = min( noiseFillingBorder[ch][n], (int16_t) ( hTcxEnc->measuredBwRatio * (float) L_frame[ch][n] + 0.5f ) ); + if ( ( total_brate >= HQ_96k && ( st->element_mode <= IVAS_SCE || st->bwidth < SWB ) ) || total_brate > IVAS_192k ) { fac_ns[ch][n] = 0.0f; *fac_ns_q = 0; } else { - iStart = L_frame[ch][n] / ((total_brate >= ACELP_13k20 && !st->rf_mode) ? 6 : 8); /* noise filling start bin*/ + iStart = L_frame[ch][n] / ( ( total_brate >= ACELP_13k20 && !st->rf_mode ) ? 6 : 8 ); /* noise filling start bin*/ - if (n == 0) + if ( n == 0 ) { - mvr2r(hTcxEnc->ltpGainMemory, &hTcxEnc->ltpGainMemory[1], N_LTP_GAIN_MEMS - 1); + mvr2r( hTcxEnc->ltpGainMemory, &hTcxEnc->ltpGainMemory[1], N_LTP_GAIN_MEMS - 1 ); hTcxEnc->ltpGainMemory[0] = st->hTcxEnc->tcxltp_gain; } - smooth_gain = dotp(hTcxEnc->ltpGainMemory, nf_tw_smoothing_coeffs, N_LTP_GAIN_MEMS); + smooth_gain = dotp( hTcxEnc->ltpGainMemory, nf_tw_smoothing_coeffs, N_LTP_GAIN_MEMS ); - noiseTransWidth = GetTransWidth(st->tcxonly, (L_frame[ch][n] == st->L_frame >> 1), smooth_gain, (st->hTcxCfg->ctx_hm && st->last_core != ACELP_CORE && hm_active[ch][n])); + noiseTransWidth = GetTransWidth( st->tcxonly, ( L_frame[ch][n] == st->L_frame >> 1 ), smooth_gain, ( st->hTcxCfg->ctx_hm && st->last_core != ACELP_CORE && hm_active[ch][n] ) ); - mvr2r(q_spectrum[ch][n], combined_q_spectrum, L_frame[ch][n]); - tcx_noise_factor(hTcxEnc->spectrum[n], combined_q_spectrum, iStart, maxNfCalcBw, noiseTransWidth, L_frame[ch][n], gain_tcx[ch][n], hTcxEnc->noiseTiltFactor, &fac_ns[ch][n], fac_ns_q, st->element_mode); + mvr2r( q_spectrum[ch][n], combined_q_spectrum, L_frame[ch][n] ); + tcx_noise_factor( hTcxEnc->spectrum[n], combined_q_spectrum, iStart, maxNfCalcBw, noiseTransWidth, L_frame[ch][n], gain_tcx[ch][n], hTcxEnc->noiseTiltFactor, &fac_ns[ch][n], fac_ns_q, st->element_mode ); /* hysteresis for very tonal passages (more stationary noise filling level) */ - if (*fac_ns_q == 1) + if ( *fac_ns_q == 1 ) { - hTcxEnc->noiseLevelMemory_cnt = (int16_t)min(INT16_MAX, 1 + abs(hTcxEnc->noiseLevelMemory_cnt)); /* update counter */ + hTcxEnc->noiseLevelMemory_cnt = (int16_t) min( INT16_MAX, 1 + abs( hTcxEnc->noiseLevelMemory_cnt ) ); /* update counter */ } else { - if ((*fac_ns_q == 2) && (abs(hTcxEnc->noiseLevelMemory_cnt) > 5)) + if ( ( *fac_ns_q == 2 ) && ( abs( hTcxEnc->noiseLevelMemory_cnt ) > 5 ) ) { *fac_ns_q = 1; /* reduce noise filling level by one step */ - fac_ns[ch][n] = 0.75f / (1 << NBITS_NOISE_FILL_LEVEL); + fac_ns[ch][n] = 0.75f / ( 1 << NBITS_NOISE_FILL_LEVEL ); /* signal that noise level is changed by inverting sign of level memory */ - hTcxEnc->noiseLevelMemory_cnt = (hTcxEnc->noiseLevelMemory_cnt < 0) ? 5 : -1 - hTcxEnc->noiseLevelMemory_cnt; + hTcxEnc->noiseLevelMemory_cnt = ( hTcxEnc->noiseLevelMemory_cnt < 0 ) ? 5 : -1 - hTcxEnc->noiseLevelMemory_cnt; } else { @@ -1045,10 +1042,10 @@ void EstimateStereoTCXNoiseLevel( } /* bitrate */ } #ifdef DEBUG_MODE_MDCT - dbgwrite(&smooth_gain, sizeof(float), 1, 1, "./res/smooth_gain"); - dbgwrite(&st->hTcxEnc->tcxltp_gain, sizeof(float), 1, 1, "./res/tcxltp_gain"); - dbgwrite(&noiseTransWidth, sizeof(int16_t), 1, 1, "./res/noiseTrans"); - dbgwrite(&fac_ns[ch][0], sizeof(float), 2, 1, "./res/fac_ns"); + dbgwrite( &smooth_gain, sizeof( float ), 1, 1, "./res/smooth_gain" ); + dbgwrite( &st->hTcxEnc->tcxltp_gain, sizeof( float ), 1, 1, "./res/tcxltp_gain" ); + dbgwrite( &noiseTransWidth, sizeof( int16_t ), 1, 1, "./res/noiseTrans" ); + dbgwrite( &fac_ns[ch][0], sizeof( float ), 2, 1, "./res/fac_ns" ); #endif } @@ -1065,19 +1062,19 @@ void EstimateStereoTCXNoiseLevel( static int16_t DecideTonalSideInfo( const float spectrum[], const int16_t L_frame_glob, - float SFM2) + float SFM2 ) { float SFM, K, K2; int16_t Tonal_SideInfo; - SFM = SFM_Cal(spectrum, min(200, L_frame_glob)); + SFM = SFM_Cal( spectrum, min( 200, L_frame_glob ) ); - if (L_frame_glob <= 256) + if ( L_frame_glob <= 256 ) { K = 0.4f; K2 = 0.1f; } - else if (L_frame_glob == 320 || L_frame_glob == 512) + else if ( L_frame_glob == 320 || L_frame_glob == 512 ) { K = 0.4f; K2 = 0.1f; @@ -1090,12 +1087,12 @@ static int16_t DecideTonalSideInfo( Tonal_SideInfo = 0; - if (SFM < K) + if ( SFM < K ) { Tonal_SideInfo = 1; } - if (SFM2 < K2) + if ( SFM2 < K2 ) { Tonal_SideInfo = 1; } @@ -1106,26 +1103,25 @@ static int16_t DecideTonalSideInfo( void QuantizeSpectrum_fx( TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */ - Word16 A[], /* input: quantized coefficients NxAz_q[M+1] */ - Word16 Aqind[], /* input: frame-independent quantized coefficients (M+1) */ - Word16 gainlpc[], /* input: MDCT gains of the previous frame */ - Word16 gainlpc_e[], /* input: MDCT gains exponents */ + Word16 A[], /* input: quantized coefficients NxAz_q[M+1] */ + Word16 Aqind[], /* input: frame-independent quantized coefficients (M+1) */ + Word16 gainlpc[], /* input: MDCT gains of the previous frame */ + Word16 gainlpc_e[], /* input: MDCT gains exponents */ Word16 synth[], - Word16 L_frame_glob, /* input: frame length */ + Word16 L_frame_glob, /* input: frame length */ Word16 L_frameTCX_glob, Word16 L_spec, - Word16 nb_bits, /*input: bit budget*/ - Word8 tcxonly, /*input: only TCX flag*/ - Word32 spectrum[], /* i/o: MDCT spectrum, input is shaped MDCT spectrum */ - Word16 *spectrum_e, /* i/o: MDCT spectrum exponent */ - STnsData * pTnsData, /* input: Tns data */ - Word8 fUseTns, /* input: Flag indicating if TNS is used */ - Word16 tnsSize, /* input: number of tns parameters put into prm */ - Word16 prm[], /* output: tcx parameters */ - Word16 frame_cnt, /* input: frame counter in the super_frame */ + Word16 nb_bits, /*input: bit budget*/ + Word8 tcxonly, /*input: only TCX flag*/ + Word32 spectrum[], /* i/o: MDCT spectrum, input is shaped MDCT spectrum */ + Word16 *spectrum_e, /* i/o: MDCT spectrum exponent */ + STnsData *pTnsData, /* input: Tns data */ + Word8 fUseTns, /* input: Flag indicating if TNS is used */ + Word16 tnsSize, /* input: number of tns parameters put into prm */ + Word16 prm[], /* output: tcx parameters */ + Word16 frame_cnt, /* input: frame counter in the super_frame */ Encoder_State *st, - CONTEXT_HM_CONFIG *hm_cfg -) + CONTEXT_HM_CONFIG *hm_cfg ) { Word16 i, L_frame, tcx_offset; Word16 stop; @@ -1150,12 +1146,12 @@ void QuantizeSpectrum_fx( Word16 *signs; Word16 signaling_bits; Word16 *prm_ltp, *prm_tns, *prm_hm, *prm_lastnz, *prm_target; - Word16 Aq_old[M+1]; + Word16 Aq_old[M + 1]; Word32 SFM; Word32 K, K2; - Word16 aldo; /* ALDO flag in current frame*/ - Word16 nz; /* non-zero length in ALDO window*/ - CONTEXT_HM_CONFIG * phm_cfg; + Word16 aldo; /* ALDO flag in current frame*/ + Word16 nz; /* non-zero length in ALDO window*/ + CONTEXT_HM_CONFIG *phm_cfg; TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; @@ -1206,7 +1202,7 @@ void QuantizeSpectrum_fx( move16(); aldo = 0; move16(); - nz = NS2SA_fx2(st->sr_core, N_ZERO_MDCT_NS); + nz = NS2SA_fx2( st->sr_core, N_ZERO_MDCT_NS ); move16(); /* Modified the overlap to the delay in case of short blocks*/ tcx_offset = hTcxCfg->tcx_offset; @@ -1222,7 +1218,7 @@ void QuantizeSpectrum_fx( move16(); resQBits = 0; move16(); - prm_ltp = &prm[1+NOISE_FILL_RANGES]; + prm_ltp = &prm[1 + NOISE_FILL_RANGES]; move16(); prm_tns = prm_ltp + LTPSIZE; move16(); @@ -1235,20 +1231,20 @@ void QuantizeSpectrum_fx( /* if past frame is ACELP */ - IF (st->last_core == ACELP_CORE) + IF( st->last_core == ACELP_CORE ) { hTcxCfg->last_aldo = 0; move16(); - L_frame = add(L_frame, tcx_offset); - L_frameTCX = add(L_frameTCX, hTcxCfg->tcx_offsetFB); - L_spec = add(L_spec, shr(hTcxCfg->tcx_coded_lines, 2)); + L_frame = add( L_frame, tcx_offset ); + L_frameTCX = add( L_frameTCX, hTcxCfg->tcx_offsetFB ); + L_spec = add( L_spec, shr( hTcxCfg->tcx_coded_lines, 2 ) ); tcx_offset = 0; move16(); - IF(hTcxCfg->lfacNext<0) + IF( hTcxCfg->lfacNext < 0 ) { - L_frame = sub(L_frame,hTcxCfg->lfacNext); - L_frameTCX = sub(L_frameTCX, hTcxCfg->lfacNextFB); + L_frame = sub( L_frame, hTcxCfg->lfacNext ); + L_frameTCX = sub( L_frameTCX, hTcxCfg->lfacNextFB ); tcx_offset = hTcxCfg->lfacNext; move16(); } @@ -1257,42 +1253,42 @@ void QuantizeSpectrum_fx( } - E_LPC_f_lsp_a_conversion(st->lsp_old_fx, Aq_old, M); + E_LPC_f_lsp_a_conversion( st->lsp_old_fx, Aq_old, M ); /* target bitrate for SQ */ - sqTargetBits = sub(nb_bits, 7 + NBITS_NOISE_FILL_LEVEL); + sqTargetBits = sub( nb_bits, 7 + NBITS_NOISE_FILL_LEVEL ); /*Unquantized spectrum here*/ - IF (st->enablePlcWaveadjust) + IF( st->enablePlcWaveadjust ) { - SFM = SFM_Cal_fx(spectrum, s_min(200, L_frame_glob)); + SFM = SFM_Cal_fx( spectrum, s_min( 200, L_frame_glob ) ); test(); - IF (LE_16(L_frame_glob, 256)) + IF( LE_16( L_frame_glob, 256 ) ) { - K = 0x33333333; + K = 0x33333333; move32(); K2 = 0xCCCCCCD; move32(); } - ELSE IF (EQ_16(L_frame_glob,320)||EQ_16(L_frame_glob,512)) + ELSE IF( EQ_16( L_frame_glob, 320 ) || EQ_16( L_frame_glob, 512 ) ) { - K = 0x33333333; + K = 0x33333333; move32(); K2 = 0xCCCCCCD; move32(); } ELSE /*FrameSize_Core == 640*/ { - K = 0x2CCCCCCD; + K = 0x2CCCCCCD; move32(); K2 = 0x51EB852; move32(); } - IF ( LT_32(SFM, K)) + IF( LT_32( SFM, K ) ) { st->Tonal_SideInfo = 1; move16(); @@ -1303,7 +1299,7 @@ void QuantizeSpectrum_fx( move16(); } - if ( LT_32(hTcxCfg->SFM2, K2)) + if ( LT_32( hTcxCfg->SFM2, K2 ) ) { st->Tonal_SideInfo = 1; move16(); @@ -1311,7 +1307,7 @@ void QuantizeSpectrum_fx( } /* Save pre-shaped spectrum*/ - Copy32(spectrum, x_orig, L_spec); + Copy32( spectrum, x_orig, L_spec ); x_orig_e = *spectrum_e; move16(); @@ -1321,7 +1317,7 @@ void QuantizeSpectrum_fx( noiseFillingSize = L_spec; move16(); - IF (st->igf != 0) + IF( st->igf != 0 ) { noiseFillingSize = st->hIGFEnc->infoStartLine; move16(); @@ -1332,35 +1328,35 @@ void QuantizeSpectrum_fx( move16(); } - FOR (i=st->hIGFEnc->infoStopLine; ihIGFEnc->infoStopLine; i < L_frameTCX; i++ ) { - spectrum[i] = L_deposit_l(0); + spectrum[i] = L_deposit_l( 0 ); } /*-----------------------------------------------------------* * Quantization * *-----------------------------------------------------------*/ - IF (hTcxEnc->tcx_lpc_shaped_ari == 0) /* old arithmetic coder */ + IF( hTcxEnc->tcx_lpc_shaped_ari == 0 ) /* old arithmetic coder */ { /* Fast estimation of the scalar quantizer step size */ test(); - IF ((hTcxCfg->ctx_hm != 0) && (st->last_core != ACELP_CORE)) + IF( ( hTcxCfg->ctx_hm != 0 ) && ( st->last_core != ACELP_CORE ) ) { LtpPitchLag = -1; move16(); test(); - IF ((tcxonly == 0) && (LT_16(hTcxEnc->tcxltp_pitch_int, st->L_frame))) + IF( ( tcxonly == 0 ) && ( LT_16( hTcxEnc->tcxltp_pitch_int, st->L_frame ) ) ) { - tmp32 = L_shl(L_mult0(st->L_frame, st->pit_res_max), 1+kLtpHmFractionalResolution+1); - tmp1 = add(imult1616(hTcxEnc->tcxltp_pitch_int, st->pit_res_max), hTcxEnc->tcxltp_pitch_fr); - LtpPitchLag = div_l(tmp32, tmp1); + tmp32 = L_shl( L_mult0( st->L_frame, st->pit_res_max ), 1 + kLtpHmFractionalResolution + 1 ); + tmp1 = add( imult1616( hTcxEnc->tcxltp_pitch_int, st->pit_res_max ), hTcxEnc->tcxltp_pitch_fr ); + LtpPitchLag = div_l( tmp32, tmp1 ); } - ctxHmBits = add(ctxHmBits, 1); /* ContextHM flag */ - sqTargetBits = sub(sqTargetBits, 1); /* ContextHM flag */ + ctxHmBits = add( ctxHmBits, 1 ); /* ContextHM flag */ + sqTargetBits = sub( sqTargetBits, 1 ); /* ContextHM flag */ OriginalSpectrum = spectrum; OriginalSpectrum_e = *spectrum_e; @@ -1368,66 +1364,63 @@ void QuantizeSpectrum_fx( tmp1 = -1; move16(); - if (hTcxEnc->tcxltp != 0) + if ( hTcxEnc->tcxltp != 0 ) { tmp1 = hTcxEnc->tcxltp_gain; move16(); } PeriodicityIndex = SearchPeriodicityIndex_fx( - OriginalSpectrum, - NULL, - L_spec, - sqTargetBits, - LtpPitchLag, - tmp1, - &RelativeScore - ); + OriginalSpectrum, + NULL, + L_spec, + sqTargetBits, + LtpPitchLag, + tmp1, + &RelativeScore ); ConfigureContextHm( L_spec, sqTargetBits, PeriodicityIndex, LtpPitchLag, - hm_cfg - ); + hm_cfg ); tmp1 = 1; move16(); - if (LT_16(L_spec, 256)) + if ( LT_16( L_spec, 256 ) ) { tmp1 = 0; move16(); } - NumIndexBits = CountIndexBits( tmp1, PeriodicityIndex); - + NumIndexBits = CountIndexBits( tmp1, PeriodicityIndex ); /* Quantize original spectrum */ - sqGain = SQ_gain_fx(OriginalSpectrum, OriginalSpectrum_e, - shl(mult(hTcxEnc->tcx_target_bits_fac, sqTargetBits), 1), - L_spec, - &sqGain_e); + sqGain = SQ_gain_fx( OriginalSpectrum, OriginalSpectrum_e, + shl( mult( hTcxEnc->tcx_target_bits_fac, sqTargetBits ), 1 ), + L_spec, + &sqGain_e ); - tcx_scalar_quantization_fx(OriginalSpectrum, OriginalSpectrum_e, - sqQ, - L_spec, - sqGain, sqGain_e, - hTcxCfg->sq_rounding, - hTcxEnc->memQuantZeros_fx, - tcxonly); + tcx_scalar_quantization_fx( OriginalSpectrum, OriginalSpectrum_e, + sqQ, + L_spec, + sqGain, sqGain_e, + hTcxCfg->sq_rounding, + hTcxEnc->memQuantZeros_fx, + tcxonly ); /* Estimate original bitrate */ stop = 0; move16(); - sqBits = ACcontextMapping_encode2_estimate_no_mem_s17_LC_fx(sqQ, - L_spec, - &lastnz, - &nEncoded, - sqTargetBits, - &stop, - NULL); + sqBits = ACcontextMapping_encode2_estimate_no_mem_s17_LC_fx( sqQ, + L_spec, + &lastnz, + &nEncoded, + sqTargetBits, + &stop, + NULL ); /* Estimate context mapped bitrate */ @@ -1435,26 +1428,25 @@ void QuantizeSpectrum_fx( move16(); /* Context Mapping */ - sqBitsCtxHm = ACcontextMapping_encode2_estimate_no_mem_s17_LC_fx(sqQ, - L_spec, - &lastnzCtxHm, - &nEncodedCtxHm, - sub(sqTargetBits, NumIndexBits), - &stopCtxHm, - hm_cfg - ); + sqBitsCtxHm = ACcontextMapping_encode2_estimate_no_mem_s17_LC_fx( sqQ, + L_spec, + &lastnzCtxHm, + &nEncodedCtxHm, + sub( sqTargetBits, NumIndexBits ), + &stopCtxHm, + hm_cfg ); /* Decide whether or not to use context mapping */ - Selector = sub(s_max(stop, sqBits), add(s_max(stopCtxHm, sqBitsCtxHm), NumIndexBits)); + Selector = sub( s_max( stop, sqBits ), add( s_max( stopCtxHm, sqBitsCtxHm ), NumIndexBits ) ); test(); test(); - IF ((GT_16(Selector, 2))||((LE_16(abs_s(Selector),2))&& - (LT_16(kCtxHmOlRSThr, RelativeScore) ))) + IF( ( GT_16( Selector, 2 ) ) || ( ( LE_16( abs_s( Selector ), 2 ) ) && + ( LT_16( kCtxHmOlRSThr, RelativeScore ) ) ) ) { /* CtxHm is likely better */ - sqTargetBits = sub(sqTargetBits, NumIndexBits); - ctxHmBits = add(ctxHmBits, NumIndexBits); + sqTargetBits = sub( sqTargetBits, NumIndexBits ); + ctxHmBits = add( ctxHmBits, NumIndexBits ); prm_hm[0] = 1; move16(); prm_hm[1] = PeriodicityIndex; @@ -1469,7 +1461,7 @@ void QuantizeSpectrum_fx( stop = stopCtxHm; move16(); } - ELSE /* Original is better or not much difference */ + ELSE /* Original is better or not much difference */ { prm_hm[0] = 0; move16(); @@ -1485,49 +1477,48 @@ void QuantizeSpectrum_fx( } - if (stop != 0) + if ( stop != 0 ) { sqBits = stop; move16(); } } - ELSE /* no context hm*/ + ELSE /* no context hm*/ { PeriodicityIndex = -1; move16(); - sqGain = SQ_gain_fx(spectrum, *spectrum_e, - shl(mult(hTcxEnc->tcx_target_bits_fac, sqTargetBits), 1), - L_spec, - &sqGain_e); + sqGain = SQ_gain_fx( spectrum, *spectrum_e, + shl( mult( hTcxEnc->tcx_target_bits_fac, sqTargetBits ), 1 ), + L_spec, + &sqGain_e ); /* Quantize spectrum */ - tcx_scalar_quantization_fx(spectrum, *spectrum_e, - sqQ, - L_spec, - sqGain, sqGain_e, - hTcxCfg->sq_rounding, - hTcxEnc->memQuantZeros_fx, - tcxonly - ); + tcx_scalar_quantization_fx( spectrum, *spectrum_e, + sqQ, + L_spec, + sqGain, sqGain_e, + hTcxCfg->sq_rounding, + hTcxEnc->memQuantZeros_fx, + tcxonly ); /* Estimate bitrate */ stop = 0; move16(); - sqBits = ACcontextMapping_encode2_estimate_no_mem_s17_LC_fx(sqQ, - L_spec, - prm_lastnz, /* lastnz */ - &nEncoded, - sqTargetBits, - &stop, - NULL); + sqBits = ACcontextMapping_encode2_estimate_no_mem_s17_LC_fx( sqQ, + L_spec, + prm_lastnz, /* lastnz */ + &nEncoded, + sqTargetBits, + &stop, + NULL ); sqBits_noStop = sqBits; move16(); - if (stop != 0) + if ( stop != 0 ) { sqBits = stop; move16(); @@ -1538,26 +1529,26 @@ void QuantizeSpectrum_fx( tmp1 = sqBits; move16(); - if (s_and(L_spec, sub(L_spec, 1)) == 0) /* power-of-2 */ + if ( s_and( L_spec, sub( L_spec, 1 ) ) == 0 ) /* power-of-2 */ { - tmp1 = add(tmp1, 1); + tmp1 = add( tmp1, 1 ); } - tmp1 = BASOP_Util_Divide1616_Scale(sqTargetBits, tmp1, &tmp2); + tmp1 = BASOP_Util_Divide1616_Scale( sqTargetBits, tmp1, &tmp2 ); BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB - hTcxEnc->tcx_target_bits_fac = shl_o(mult(hTcxEnc->tcx_target_bits_fac, tmp1), tmp2, &Overflow); -#else /* BASOP_NOGLOB */ - hTcxEnc->tcx_target_bits_fac = shl(mult(hTcxEnc->tcx_target_bits_fac, tmp1), tmp2); + hTcxEnc->tcx_target_bits_fac = shl_o( mult( hTcxEnc->tcx_target_bits_fac, tmp1 ), tmp2, &Overflow ); +#else /* BASOP_NOGLOB */ + hTcxEnc->tcx_target_bits_fac = shl( mult( hTcxEnc->tcx_target_bits_fac, tmp1 ), tmp2 ); #endif /* BASOP_NOGLOB */ BASOP_SATURATE_WARNING_ON_EVS - if (GT_16(hTcxEnc->tcx_target_bits_fac, 0x5000)) + if ( GT_16( hTcxEnc->tcx_target_bits_fac, 0x5000 ) ) { hTcxEnc->tcx_target_bits_fac = 0x5000; move16(); } - if (LT_16(hTcxEnc->tcx_target_bits_fac, 0x3000)) + if ( LT_16( hTcxEnc->tcx_target_bits_fac, 0x3000 ) ) { hTcxEnc->tcx_target_bits_fac = 0x3000; move16(); @@ -1566,55 +1557,54 @@ void QuantizeSpectrum_fx( /* Refine quantizer step size with a rate-control-loop (optional) */ phm_cfg = NULL; move16(); - if (PeriodicityIndex >= 0) + if ( PeriodicityIndex >= 0 ) { phm_cfg = hm_cfg; move16(); } - sqBits = tcx_scalar_quantization_rateloop_fx(spectrum, *spectrum_e, - sqQ, - L_spec, - &sqGain, &sqGain_e, - hTcxCfg->sq_rounding, - hTcxEnc->memQuantZeros_fx, - prm_lastnz, /* lastnz */ - sqTargetBits, - &nEncoded, - &stop, - sqBits_noStop, - sqBits, - hTcxCfg->tcxRateLoopOpt, - tcxonly, - phm_cfg - ); - - IF (ctxHmBits > 0) /* Mapping tool is enabled */ + sqBits = tcx_scalar_quantization_rateloop_fx( spectrum, *spectrum_e, + sqQ, + L_spec, + &sqGain, &sqGain_e, + hTcxCfg->sq_rounding, + hTcxEnc->memQuantZeros_fx, + prm_lastnz, /* lastnz */ + sqTargetBits, + &nEncoded, + &stop, + sqBits_noStop, + sqBits, + hTcxCfg->tcxRateLoopOpt, + tcxonly, + phm_cfg ); + + IF( ctxHmBits > 0 ) /* Mapping tool is enabled */ { /* Truncate spectrum */ - set16_fx(sqQ+nEncoded, 0, sub(L_spec, nEncoded)); + set16_fx( sqQ + nEncoded, 0, sub( L_spec, nEncoded ) ); - IF (PeriodicityIndex >= 0) /* Mapping is used */ + IF( PeriodicityIndex >= 0 ) /* Mapping is used */ { /* Estimate non-mapped bitrate */ stopCtxHm = 1; move16(); - sqBitsCtxHm = ACcontextMapping_encode2_estimate_no_mem_s17_LC_fx(sqQ, - L_spec, - &lastnz, - &nEncodedCtxHm, - sqTargetBits, - &stopCtxHm, - NULL); + sqBitsCtxHm = ACcontextMapping_encode2_estimate_no_mem_s17_LC_fx( sqQ, + L_spec, + &lastnz, + &nEncodedCtxHm, + sqTargetBits, + &stopCtxHm, + NULL ); /* Decide whether or not to revert mapping */ - Selector = sub(sqBits, add(sqBitsCtxHm, NumIndexBits)); + Selector = sub( sqBits, add( sqBitsCtxHm, NumIndexBits ) ); test(); - IF (stopCtxHm == 0 && Selector > 0) /* Non-mapped is better */ + IF( stopCtxHm == 0 && Selector > 0 ) /* Non-mapped is better */ { - sqTargetBits = add(sqTargetBits, NumIndexBits); - ctxHmBits = sub(ctxHmBits, NumIndexBits); + sqTargetBits = add( sqTargetBits, NumIndexBits ); + ctxHmBits = sub( ctxHmBits, NumIndexBits ); prm_hm[0] = 0; move16(); *prm_lastnz = lastnz; @@ -1630,28 +1620,27 @@ void QuantizeSpectrum_fx( move16(); } } - ELSE /* Mapping is not used */ + ELSE /* Mapping is not used */ { /* Estimate mapped bitrate */ stopCtxHm = 1; move16(); - sqBitsCtxHm = ACcontextMapping_encode2_estimate_no_mem_s17_LC_fx(sqQ, - L_spec, - &lastnzCtxHm, - &nEncodedCtxHm, - sub(sqTargetBits, NumIndexBits), - &stopCtxHm, - hm_cfg - ); + sqBitsCtxHm = ACcontextMapping_encode2_estimate_no_mem_s17_LC_fx( sqQ, + L_spec, + &lastnzCtxHm, + &nEncodedCtxHm, + sub( sqTargetBits, NumIndexBits ), + &stopCtxHm, + hm_cfg ); /* Decide whether or not to use mapping */ - Selector = sub(sqBits, add(sqBitsCtxHm, NumIndexBits)); + Selector = sub( sqBits, add( sqBitsCtxHm, NumIndexBits ) ); test(); - IF (stopCtxHm == 0 && Selector > 0) /* Mapped is better */ + IF( stopCtxHm == 0 && Selector > 0 ) /* Mapped is better */ { - sqTargetBits = sub(sqTargetBits, NumIndexBits); - ctxHmBits = add(ctxHmBits, NumIndexBits); + sqTargetBits = sub( sqTargetBits, NumIndexBits ); + ctxHmBits = add( ctxHmBits, NumIndexBits ); prm_hm[0] = 1; move16(); *prm_lastnz = lastnzCtxHm; @@ -1671,103 +1660,99 @@ void QuantizeSpectrum_fx( /* Limit low sqGain for avoiding saturation of the gain quantizer*/ #ifdef BASOP_NOGLOB - tmp1 = mult_r(shl_o(L_spec, 5, &Overflow), 26214/*128.f/NORM_MDCT_FACTOR Q15*/); + tmp1 = mult_r( shl_o( L_spec, 5, &Overflow ), 26214 /*128.f/NORM_MDCT_FACTOR Q15*/ ); #else - tmp1 = mult_r(shl(L_spec, 5), 26214/*128.f/NORM_MDCT_FACTOR Q15*/); + tmp1 = mult_r( shl( L_spec, 5 ), 26214 /*128.f/NORM_MDCT_FACTOR Q15*/ ); #endif - s = 15-5-7; + s = 15 - 5 - 7; IF( L_spec >= 1024 ) { /*reduce precision for avoiding overflow*/ - tmp1 = mult_r(shl(L_spec, 4), 26214/*128.f/NORM_MDCT_FACTOR Q15*/); - s = 15-4-7; + tmp1 = mult_r( shl( L_spec, 4 ), 26214 /*128.f/NORM_MDCT_FACTOR Q15*/ ); + s = 15 - 4 - 7; } - tmp1 = ISqrt16(tmp1, &s); + tmp1 = ISqrt16( tmp1, &s ); - tmp2 = sub(sqGain_e, s); - IF (tmp2 >= 0) + tmp2 = sub( sqGain_e, s ); + IF( tmp2 >= 0 ) { BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB tmp2 = sub_sat( sqGain, shr_sat( tmp1, tmp2 ) ); #else - tmp2 = sub(sqGain, shr(tmp1, tmp2)); + tmp2 = sub( sqGain, shr( tmp1, tmp2 ) ); #endif BASOP_SATURATE_WARNING_ON_EVS; } ELSE { - tmp2 = sub(shl(sqGain, s_max(-15, tmp2)), tmp1); + tmp2 = sub( shl( sqGain, s_max( -15, tmp2 ) ), tmp1 ); } - IF (tmp2 < 0) + IF( tmp2 < 0 ) { sqGain = tmp1; sqGain_e = s; tcx_scalar_quantization_fx( spectrum, *spectrum_e, - sqQ, - L_spec, - sqGain, sqGain_e, - hTcxCfg->sq_rounding, - hTcxEnc->memQuantZeros_fx, - tcxonly - ); + sqQ, + L_spec, + sqGain, sqGain_e, + hTcxCfg->sq_rounding, + hTcxEnc->memQuantZeros_fx, + tcxonly ); move16(); - stop=1; + stop = 1; phm_cfg = NULL; move16(); - if (PeriodicityIndex >= 0) + if ( PeriodicityIndex >= 0 ) { phm_cfg = hm_cfg; move16(); } - sqBits = ACcontextMapping_encode2_estimate_no_mem_s17_LC_fx(sqQ, - L_spec, - prm_lastnz, - &nEncoded, - sqTargetBits, - &stop, - phm_cfg - ); + sqBits = ACcontextMapping_encode2_estimate_no_mem_s17_LC_fx( sqQ, + L_spec, + prm_lastnz, + &nEncoded, + sqTargetBits, + &stop, + phm_cfg ); } /* Truncate spectrum (for CBR) */ - IF (stop != 0) + IF( stop != 0 ) { - set16_fx(sqQ+nEncoded, 0, sub(L_spec, nEncoded)); + set16_fx( sqQ + nEncoded, 0, sub( L_spec, nEncoded ) ); } /* Save quantized Values */ - tmp32 = L_deposit_l(0); - FOR(i=0; itcx_lpc_shaped_ari, - gainlpc, gainlpc_e, - L_frame - ); + AdaptLowFreqEmph_fx( spectrum, *spectrum_e, + NULL, + 0, 0, + hTcxEnc->tcx_lpc_shaped_ari, + gainlpc, gainlpc_e, + L_frame ); prm_target = sqQ; move16(); @@ -1779,16 +1764,16 @@ void QuantizeSpectrum_fx( LtpPitchLag = -1; move16(); - IF (LT_16(hTcxEnc->tcxltp_pitch_int, st->L_frame)) + IF( LT_16( hTcxEnc->tcxltp_pitch_int, st->L_frame ) ) { - tmp32 = L_shl(L_mult0(st->L_frame, st->pit_res_max), 1+kLtpHmFractionalResolution+1); - tmp1 = add(imult1616(hTcxEnc->tcxltp_pitch_int, st->pit_res_max), hTcxEnc->tcxltp_pitch_fr); - LtpPitchLag = div_l(tmp32, tmp1); + tmp32 = L_shl( L_mult0( st->L_frame, st->pit_res_max ), 1 + kLtpHmFractionalResolution + 1 ); + tmp1 = add( imult1616( hTcxEnc->tcxltp_pitch_int, st->pit_res_max ), hTcxEnc->tcxltp_pitch_fr ); + LtpPitchLag = div_l( tmp32, tmp1 ); } tmp8 = 1; move16(); - if (EQ_16(st->last_core, ACELP_CORE)) + if ( EQ_16( st->last_core, ACELP_CORE ) ) { tmp8 = 0; move16(); @@ -1809,11 +1794,10 @@ void QuantizeSpectrum_fx( LtpPitchLag, &sqBits, &signaling_bits, - &nf_seed - , shr(st->bwidth, 1) /* equivalent to: (st->bwidth > WB)?1:0 */ + &nf_seed, shr( st->bwidth, 1 ) /* equivalent to: (st->bwidth > WB)?1:0 */ ); - sqTargetBits = sub(sqTargetBits, signaling_bits); + sqTargetBits = sub( sqTargetBits, signaling_bits ); *prm_target = sqTargetBits; move16(); } @@ -1822,26 +1806,26 @@ void QuantizeSpectrum_fx( * Compute optimal TCX gain. * *-----------------------------------------------------------*/ /* initialize LF deemphasis factors in xn_buf */ - set16_fx(xn_buf16, 0x4000, L_spec); + set16_fx( xn_buf16, 0x4000, L_spec ); - IF (tcxonly == 0) + IF( tcxonly == 0 ) { - AdaptLowFreqDeemph(spectrum, *spectrum_e, - hTcxEnc->tcx_lpc_shaped_ari, - gainlpc, gainlpc_e, - L_frame, - xn_buf16 /* LF deemphasis factors */ - ); + AdaptLowFreqDeemph( spectrum, *spectrum_e, + hTcxEnc->tcx_lpc_shaped_ari, + gainlpc, gainlpc_e, + L_frame, + xn_buf16 /* LF deemphasis factors */ + ); } - tcx_get_gain(x_orig, x_orig_e, - spectrum, *spectrum_e, - L_spec, - &gain_tcx_opt, &gain_tcx_opt_e, - &ener, &ener_e); + tcx_get_gain( x_orig, x_orig_e, + spectrum, *spectrum_e, + L_spec, + &gain_tcx_opt, &gain_tcx_opt_e, + &ener, &ener_e ); - IF (gain_tcx_opt <= 0) + IF( gain_tcx_opt <= 0 ) { gain_tcx_opt = sqGain; move16(); @@ -1859,9 +1843,9 @@ void QuantizeSpectrum_fx( * Quantize TCX gain * *-----------------------------------------------------------*/ - IF (GE_32(st->total_brate, ACELP_13k20)&&st->rf_mode==0) + IF( GE_32( st->total_brate, ACELP_13k20 ) && st->rf_mode == 0 ) { - QuantizeGain(L_spec, &gain_tcx, &gain_tcx_e, &prm[0]); + QuantizeGain( L_spec, &gain_tcx, &gain_tcx_e, &prm[0] ); } @@ -1869,54 +1853,52 @@ void QuantizeSpectrum_fx( * Residual Quantization * *-----------------------------------------------------------*/ - IF (hTcxCfg->resq) + IF( hTcxCfg->resq ) { - resQTargetBits = sub(sqTargetBits, sqBits); + resQTargetBits = sub( sqTargetBits, sqBits ); - IF (hTcxEnc->tcx_lpc_shaped_ari) /* new arithmetic coder */ + IF( hTcxEnc->tcx_lpc_shaped_ari ) /* new arithmetic coder */ { Word16 *prm_resq; prm_resq = sqQ + sqTargetBits - resQTargetBits; - resQBits = tcx_ari_res_Q_spec_fx(x_orig, x_orig_e, signs, spectrum, *spectrum_e, L_spec, gain_tcx, gain_tcx_e, - prm_resq, - resQTargetBits, - resQBits, - hTcxCfg->sq_rounding, - xn_buf16 /* LF deemphasis factors */ ); + resQBits = tcx_ari_res_Q_spec_fx( x_orig, x_orig_e, signs, spectrum, *spectrum_e, L_spec, gain_tcx, gain_tcx_e, + prm_resq, + resQTargetBits, + resQBits, + hTcxCfg->sq_rounding, + xn_buf16 /* LF deemphasis factors */ ); /* Transmit zeros when there bits remain after RESQ */ - set16_fx(prm_resq+resQBits, 0, sub(resQTargetBits, resQBits)); + set16_fx( prm_resq + resQBits, 0, sub( resQTargetBits, resQBits ) ); } - ELSE /* old arithmetic coder */ + ELSE /* old arithmetic coder */ { move16(); tmpP16 = NULL; - if (tcxonly == 0) + if ( tcxonly == 0 ) { move16(); tmpP16 = xn_buf16; } - resQBits = tcx_res_Q_gain_fx(gain_tcx_opt, gain_tcx_opt_e, - &gain_tcx, &gain_tcx_e, - &sqQ[L_spec], - resQTargetBits); + resQBits = tcx_res_Q_gain_fx( gain_tcx_opt, gain_tcx_opt_e, + &gain_tcx, &gain_tcx_e, + &sqQ[L_spec], + resQTargetBits ); - resQBits = tcx_res_Q_spec_fx(x_orig, x_orig_e, - spectrum, *spectrum_e, - L_spec, - gain_tcx, gain_tcx_e, - &sqQ[L_spec], - resQTargetBits, - resQBits, - hTcxCfg->sq_rounding, - tmpP16 /* LF deemphasis factors */ ); + resQBits = tcx_res_Q_spec_fx( x_orig, x_orig_e, + spectrum, *spectrum_e, + L_spec, + gain_tcx, gain_tcx_e, + &sqQ[L_spec], + resQTargetBits, + resQBits, + hTcxCfg->sq_rounding, + tmpP16 /* LF deemphasis factors */ ); } - - } @@ -1924,14 +1906,14 @@ void QuantizeSpectrum_fx( * ALFE tcx only bitrates * *-----------------------------------------------------------*/ - IF (st->tcxonly != 0) + IF( st->tcxonly != 0 ) { test(); test(); - IF (hTcxEnc->tcxltp != 0 && (hTcxEnc->tcxltp_gain > 0) && fUseTns == 0) + IF( hTcxEnc->tcxltp != 0 && ( hTcxEnc->tcxltp_gain > 0 ) && fUseTns == 0 ) { - PsychAdaptLowFreqDeemph(spectrum, gainlpc, gainlpc_e, NULL); + PsychAdaptLowFreqDeemph( spectrum, gainlpc, gainlpc_e, NULL ); } } @@ -1940,13 +1922,13 @@ void QuantizeSpectrum_fx( *-----------------------------------------------------------*/ { - maxNfCalcBw = s_min(noiseFillingSize, round_fx(L_shl(L_mult(hTcxEnc->measuredBwRatio, L_frame), 1))); + maxNfCalcBw = s_min( noiseFillingSize, round_fx( L_shl( L_mult( hTcxEnc->measuredBwRatio, L_frame ), 1 ) ) ); /*-----------------------------------------------------------* * Estimate and quantize noise factor * *-----------------------------------------------------------*/ - IF (GE_32(st->total_brate, HQ_96k)) + IF( GE_32( st->total_brate, HQ_96k ) ) { fac_ns = 0; move16(); @@ -1956,26 +1938,26 @@ void QuantizeSpectrum_fx( ELSE { /* noise filling start bin */ - i = shr(L_frame, 3); - IF (GE_32(st->total_brate, ACELP_13k20)&&st->rf_mode==0) + i = shr( L_frame, 3 ); + IF( GE_32( st->total_brate, ACELP_13k20 ) && st->rf_mode == 0 ) { - i = idiv1616U(L_frame, 6); + i = idiv1616U( L_frame, 6 ); } - IF (tcxonly) + IF( tcxonly ) { tmp1 = 0; move16(); test(); test(); - if ((hTcxCfg->ctx_hm != 0) && (st->last_core != ACELP_CORE) && (prm_hm[0] != 0)) + if ( ( hTcxCfg->ctx_hm != 0 ) && ( st->last_core != ACELP_CORE ) && ( prm_hm[0] != 0 ) ) { - tmp1 = 10240/*0.3125f Q15*/; + tmp1 = 10240 /*0.3125f Q15*/; move16(); } - noiseTransWidth = HOLE_SIZE_FROM_LTP(s_max(hTcxEnc->tcxltp_gain, tmp1)); + noiseTransWidth = HOLE_SIZE_FROM_LTP( s_max( hTcxEnc->tcxltp_gain, tmp1 ) ); - if (EQ_16(L_frame, shr(st->L_frame, 1))) + if ( EQ_16( L_frame, shr( st->L_frame, 1 ) ) ) { /* minimum transition for noise filling in TCX-10 */ noiseTransWidth = 3; @@ -1984,41 +1966,43 @@ void QuantizeSpectrum_fx( } tcx_noise_factor_fx( x_orig, x_orig_e, - spectrum, - i, - maxNfCalcBw, - noiseTransWidth, - L_frame, - gain_tcx, gain_tcx_e, - hTcxEnc->noiseTiltFactor, - &fac_ns, &prm[NOISE_FILL_RANGES] ); + spectrum, + i, + maxNfCalcBw, + noiseTransWidth, + L_frame, + gain_tcx, gain_tcx_e, + hTcxEnc->noiseTiltFactor, + &fac_ns, &prm[NOISE_FILL_RANGES] ); /* hysteresis for very tonal passages (more stationary noise filling level) */ - IF (EQ_16(prm[NOISE_FILL_RANGES], 1)) + IF( EQ_16( prm[NOISE_FILL_RANGES], 1 ) ) { - hTcxEnc->noiseLevelMemory_cnt = add(1, abs_s(hTcxEnc->noiseLevelMemory_cnt)); /* update counter */ + hTcxEnc->noiseLevelMemory_cnt = add( 1, abs_s( hTcxEnc->noiseLevelMemory_cnt ) ); /* update counter */ } - ELSE { + ELSE + { test(); - IF ((EQ_16(prm[NOISE_FILL_RANGES], 2))&& - (GT_16(abs_s(hTcxEnc->noiseLevelMemory_cnt), 5))) + IF( ( EQ_16( prm[NOISE_FILL_RANGES], 2 ) ) && + ( GT_16( abs_s( hTcxEnc->noiseLevelMemory_cnt ), 5 ) ) ) { /* reduce noise filling level by one step */ prm[NOISE_FILL_RANGES] = 1; move16(); - fac_ns = shr(0x6000, NBITS_NOISE_FILL_LEVEL); + fac_ns = shr( 0x6000, NBITS_NOISE_FILL_LEVEL ); /* signal that noise level is changed by inverting sign of level memory */ tmp1 = 5; move16(); - if (hTcxEnc->noiseLevelMemory_cnt >= 0) + if ( hTcxEnc->noiseLevelMemory_cnt >= 0 ) { - tmp1 = sub(-1, hTcxEnc->noiseLevelMemory_cnt); + tmp1 = sub( -1, hTcxEnc->noiseLevelMemory_cnt ); } hTcxEnc->noiseLevelMemory_cnt = tmp1; } - ELSE { + ELSE + { /* reset memory since level is too different */ hTcxEnc->noiseLevelMemory_cnt = 0; move16(); @@ -2037,12 +2021,12 @@ void QuantizeSpectrum_fx( { /* Overlay of a 16-bit buffer xn_buf16 with a 32-bit buffer xn_buf32 */ /* The size is determined by the requirements of the 16-bit buffer. */ - Word32 xn_buf32[(L_MDCT_OVLP_MAX+L_FRAME_PLUS+L_MDCT_OVLP_MAX)/2]; - Word16 *xn_buf16 = (Word16*)xn_buf32; + Word32 xn_buf32[( L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX ) / 2]; + Word16 *xn_buf16 = (Word16 *) xn_buf32; /*Enable internal TCX decoder to run always to update LPD memory for rate switching */ - IF (tcxonly == 0) + IF( tcxonly == 0 ) { } @@ -2051,50 +2035,50 @@ void QuantizeSpectrum_fx( *-----------------------------------------------------------*/ /* Replication of ACELP formant enhancement for low rates */ - IF ( LT_32(st->total_brate, ACELP_13k20)||st->rf_mode!=0) + IF( LT_32( st->total_brate, ACELP_13k20 ) || st->rf_mode != 0 ) { - tcxFormantEnhancement(xn_buf16, gainlpc, gainlpc_e, spectrum, spectrum_e, L_frame, L_spec); + tcxFormantEnhancement( xn_buf16, gainlpc, gainlpc_e, spectrum, spectrum_e, L_frame, L_spec ); } - IF (fac_ns > 0) + IF( fac_ns > 0 ) { tmp1 = 0; move16(); - if ( GE_32(st->total_brate, ACELP_13k20)&&st->rf_mode==0) + if ( GE_32( st->total_brate, ACELP_13k20 ) && st->rf_mode == 0 ) { tmp1 = 1; move16(); } - i = tcxGetNoiseFillingTilt(A, - M, - L_frame, - tmp1, - &hTcxEnc->noiseTiltFactor); + i = tcxGetNoiseFillingTilt( A, + M, + L_frame, + tmp1, + &hTcxEnc->noiseTiltFactor ); - tcx_noise_filling(spectrum, *spectrum_e,nf_seed /* seed */, i, noiseFillingSize, noiseTransWidth, L_frame, hTcxEnc->noiseTiltFactor, fac_ns, NULL, st->element_mode ); + tcx_noise_filling( spectrum, *spectrum_e, nf_seed /* seed */, i, noiseFillingSize, noiseTransWidth, L_frame, hTcxEnc->noiseTiltFactor, fac_ns, NULL, st->element_mode ); } - IF (LT_32(st->total_brate, ACELP_13k20)||st->rf_mode!=0) + IF( LT_32( st->total_brate, ACELP_13k20 ) || st->rf_mode != 0 ) { /* partially recompute global gain (energy part), taking noise filling and formant enhancement into account */ - s = sub(getScaleFactor32(spectrum, L_spec), 4); - tmp32 = L_deposit_l(1); + s = sub( getScaleFactor32( spectrum, L_spec ), 4 ); + tmp32 = L_deposit_l( 1 ); - FOR (i = 0; i < L_spec; i++) + FOR( i = 0; i < L_spec; i++ ) { - tmp1 = round_fx(L_shl(spectrum[i], s)); - tmp32 = L_mac0(tmp32, tmp1, tmp1); + tmp1 = round_fx( L_shl( spectrum[i], s ) ); + tmp32 = L_mac0( tmp32, tmp1, tmp1 ); } - tmp1 = BASOP_Util_Divide3232_Scale(ener, tmp32, &tmp2); - tmp2 = add(tmp2, sub(ener_e, add(shl(sub(*spectrum_e, s), 1), 1))); - tmp1 = Sqrt16(tmp1, &tmp2); + tmp1 = BASOP_Util_Divide3232_Scale( ener, tmp32, &tmp2 ); + tmp2 = add( tmp2, sub( ener_e, add( shl( sub( *spectrum_e, s ), 1 ), 1 ) ) ); + tmp1 = Sqrt16( tmp1, &tmp2 ); - gain_tcx = mult(gain_tcx, tmp1); - gain_tcx_e = add(gain_tcx_e, tmp2); + gain_tcx = mult( gain_tcx, tmp1 ); + gain_tcx_e = add( gain_tcx_e, tmp2 ); - QuantizeGain(L_spec, &gain_tcx, &gain_tcx_e, &prm[0]); + QuantizeGain( L_spec, &gain_tcx, &gain_tcx_e, &prm[0] ); } /*end of noise filling*/ @@ -2104,82 +2088,83 @@ void QuantizeSpectrum_fx( *-----------------------------------------------------------*/ /* LPC gains already available */ - mdct_shaping(spectrum, L_frame, gainlpc, gainlpc_e); + mdct_shaping( spectrum, L_frame, gainlpc, gainlpc_e ); /*-----------------------------------------------------------* * Apply gain * *-----------------------------------------------------------*/ - IF (EQ_16(st->hTcxCfg->coder_type, INACTIVE)) + IF( EQ_16( st->hTcxCfg->coder_type, INACTIVE ) ) { - gain_tcx = mult_r(gain_tcx, hTcxCfg->na_scale); + gain_tcx = mult_r( gain_tcx, hTcxCfg->na_scale ); } - FOR (i = 0; i < L_spec; i++) + FOR( i = 0; i < L_spec; i++ ) { - spectrum[i] = Mpy_32_16_1(spectrum[i], gain_tcx); + spectrum[i] = Mpy_32_16_1( spectrum[i], gain_tcx ); move32(); } - *spectrum_e = add(*spectrum_e, gain_tcx_e); + *spectrum_e = add( *spectrum_e, gain_tcx_e ); move16(); - stop = hTcxCfg->tcx_last_overlap_mode; /* backup last TCX overlap mode */ move16(); + stop = hTcxCfg->tcx_last_overlap_mode; /* backup last TCX overlap mode */ + move16(); test(); - IF ((EQ_16(L_frame, shr(st->L_frame, 1)))&&(tcxonly!=0)) + IF( ( EQ_16( L_frame, shr( st->L_frame, 1 ) ) ) && ( tcxonly != 0 ) ) { Word16 L = L_frame; move16(); test(); test(); - if (((hTcxCfg->fIsTNSAllowed != 0) && (fUseTns != 0)) || (GT_16(L_spec, L_frame))) + if ( ( ( hTcxCfg->fIsTNSAllowed != 0 ) && ( fUseTns != 0 ) ) || ( GT_16( L_spec, L_frame ) ) ) { L = L_spec; move16(); } - tcxInvertWindowGrouping(hTcxCfg, - xn_buf32, - spectrum, - L, - fUseTns, - st->last_core, - stop, - frame_cnt, - 0); + tcxInvertWindowGrouping( hTcxCfg, + xn_buf32, + spectrum, + L, + fUseTns, + st->last_core, + stop, + frame_cnt, + 0 ); } /*-----------------------------------------------------------* * Temporal Noise Shaping Synthesis * *-----------------------------------------------------------*/ - IF (hTcxCfg->fIsTNSAllowed != 0) + IF( hTcxCfg->fIsTNSAllowed != 0 ) { test(); test(); test(); - SetTnsConfig(hTcxCfg, sub(L_frame_glob, st->L_frame) == 0, (st->last_core == ACELP_CORE) && (frame_cnt == 0)); + SetTnsConfig( hTcxCfg, sub( L_frame_glob, st->L_frame ) == 0, ( st->last_core == ACELP_CORE ) && ( frame_cnt == 0 ) ); /* Apply TNS to get the reconstructed signal */ - IF (fUseTns != 0) + IF( fUseTns != 0 ) { - ApplyTnsFilter(hTcxCfg->pCurrentTnsConfig, pTnsData, spectrum, 0); + ApplyTnsFilter( hTcxCfg->pCurrentTnsConfig, pTnsData, spectrum, 0 ); test(); - IF ((EQ_16(L_frame, shr(st->L_frame, 1)))&&(tcxonly!=0)) + IF( ( EQ_16( L_frame, shr( st->L_frame, 1 ) ) ) && ( tcxonly != 0 ) ) { test(); test(); test(); - IF ( (hTcxCfg->tcx_last_overlap_mode != FULL_OVERLAP) || - ((hTcxCfg->tcx_curr_overlap_mode == FULL_OVERLAP) && (frame_cnt == 0) && (stop == 0)) ) + IF( ( hTcxCfg->tcx_last_overlap_mode != FULL_OVERLAP ) || + ( ( hTcxCfg->tcx_curr_overlap_mode == FULL_OVERLAP ) && ( frame_cnt == 0 ) && ( stop == 0 ) ) ) { - tmp1 = shr(L_spec, 1); + tmp1 = shr( L_spec, 1 ); /* undo rearrangement of LF sub-window lines for TNS synthesis filter */ - assert(L_frame <= L_spec); - Copy32(spectrum+8, xn_buf32, 8); - Copy32(spectrum+16, spectrum+8, sub(tmp1,8)); - Copy32(xn_buf32, spectrum+tmp1, 8); + assert( L_frame <= L_spec ); + Copy32( spectrum + 8, xn_buf32, 8 ); + Copy32( spectrum + 16, spectrum + 8, sub( tmp1, 8 ) ); + Copy32( xn_buf32, spectrum + tmp1, 8 ); } } } @@ -2187,58 +2172,58 @@ void QuantizeSpectrum_fx( { /* normalize spectrum to minimize IMDCT noise */ - s = getScaleFactor32(spectrum, L_frame); - FOR (i = 0; i < L_frame; i++) + s = getScaleFactor32( spectrum, L_frame ); + FOR( i = 0; i < L_frame; i++ ) { - spectrum[i] = L_shl(spectrum[i], s); + spectrum[i] = L_shl( spectrum[i], s ); move32(); } - *spectrum_e = sub(*spectrum_e, s); + *spectrum_e = sub( *spectrum_e, s ); /*-----------------------------------------------------------* - * Compute inverse MDCT of spectrum[]. * - *-----------------------------------------------------------*/ + * Compute inverse MDCT of spectrum[]. * + *-----------------------------------------------------------*/ test(); - IF ((EQ_16(L_frame, shr(st->L_frame, 1)))&&(tcxonly!=0)) + IF( ( EQ_16( L_frame, shr( st->L_frame, 1 ) ) ) && ( tcxonly != 0 ) ) { - IF (hTcxCfg->tcx_last_overlap_mode != FULL_OVERLAP) + IF( hTcxCfg->tcx_last_overlap_mode != FULL_OVERLAP ) { - Word16 win[(L_FRAME_PLUS+L_MDCT_OVLP_MAX)/2]; + Word16 win[( L_FRAME_PLUS + L_MDCT_OVLP_MAX ) / 2]; Word16 L_win, L_spec_TCX5, L_ola, w; /* minimum or half overlap, two transforms, grouping into one window */ - L_win = shr(L_frame, 1); - L_spec_TCX5 = shr(s_max(L_frame, L_spec), 1); + L_win = shr( L_frame, 1 ); + L_spec_TCX5 = shr( s_max( L_frame, L_spec ), 1 ); L_ola = hTcxCfg->tcx_mdct_window_half_length; move16(); - if ( EQ_16(hTcxCfg->tcx_last_overlap_mode, MIN_OVERLAP)) + if ( EQ_16( hTcxCfg->tcx_last_overlap_mode, MIN_OVERLAP ) ) { L_ola = hTcxCfg->tcx_mdct_window_min_length; move16(); } - set16_fx(win, 0, (L_FRAME_PLUS+L_MDCT_OVLP_MAX)/2); - set16_fx(xn_buf16, 0, add(tcx_offset, shr(L_ola, 1))); /* zero left end of buffer */ + set16_fx( win, 0, ( L_FRAME_PLUS + L_MDCT_OVLP_MAX ) / 2 ); + set16_fx( xn_buf16, 0, add( tcx_offset, shr( L_ola, 1 ) ) ); /* zero left end of buffer */ - FOR (w = 0; w < 2; w++) + FOR( w = 0; w < 2; w++ ) { - IF (EQ_16(hTcxCfg->tcx_last_overlap_mode, MIN_OVERLAP)) + IF( EQ_16( hTcxCfg->tcx_last_overlap_mode, MIN_OVERLAP ) ) { - TCX_MDCT_Inverse(spectrum + L_mult0(w, L_spec_TCX5), sub(*spectrum_e, TCX_IMDCT_SCALE+TCX_IMDCT_HEADROOM), - win, L_ola, sub(L_win, L_ola), L_ola, st->element_mode); + TCX_MDCT_Inverse( spectrum + L_mult0( w, L_spec_TCX5 ), sub( *spectrum_e, TCX_IMDCT_SCALE + TCX_IMDCT_HEADROOM ), + win, L_ola, sub( L_win, L_ola ), L_ola, st->element_mode ); } ELSE { - TCX_MDCT_Inverse(spectrum + L_mult0(w, L_spec_TCX5), sub(*spectrum_e, TCX_IMDCT_SCALE+TCX_IMDCT_HEADROOM), win, - L_ola, sub(L_win, L_ola), L_ola, st->element_mode); + TCX_MDCT_Inverse( spectrum + L_mult0( w, L_spec_TCX5 ), sub( *spectrum_e, TCX_IMDCT_SCALE + TCX_IMDCT_HEADROOM ), win, + L_ola, sub( L_win, L_ola ), L_ola, st->element_mode ); } tmp1 = hTcxCfg->tcx_last_overlap_mode; move16(); test(); test(); - if ((w > 0) || ((w == 0) && (EQ_16(stop, 2)))) + if ( ( w > 0 ) || ( ( w == 0 ) && ( EQ_16( stop, 2 ) ) ) ) { tmp1 = MIN_OVERLAP; move16(); @@ -2247,7 +2232,7 @@ void QuantizeSpectrum_fx( tmp2 = 0; move16(); test(); - if ((w == 0) && (st->last_core == ACELP_CORE)) + if ( ( w == 0 ) && ( st->last_core == ACELP_CORE ) ) { tmp2 = 1; move16(); @@ -2255,7 +2240,7 @@ void QuantizeSpectrum_fx( tmp3 = st->last_core; move16(); - if (w > 0) + if ( w > 0 ) { tmp3 = 1; move16(); @@ -2263,196 +2248,189 @@ void QuantizeSpectrum_fx( tmp4 = 0; move16(); - if (tcx_offset < 0) + if ( tcx_offset < 0 ) { - tmp4 = negate(tcx_offset); + tmp4 = negate( tcx_offset ); } - tcx_windowing_synthesis_current_frame(win, - hTcxCfg->tcx_aldo_window_2, - hTcxCfg->tcx_mdct_window_half, - hTcxCfg->tcx_mdct_window_minimum, - L_ola, - hTcxCfg->tcx_mdct_window_half_length, - hTcxCfg->tcx_mdct_window_min_length, - tmp2, - tmp1, - hTcxEnc->acelp_zir, - hTcxEnc->Txnq, - NULL, - Aq_old, - hTcxCfg->tcx_mdct_window_trans, - L_win, - tmp4, - tmp3, - 0, - 0 - ); - - tmp1 = add(tcx_offset, imult1616(w, L_win)); - move16(); - tmpP16 = xn_buf16 + sub(tmp1, shr(L_ola, 1)); - - IF (w > 0) - { - tcx_windowing_synthesis_past_frame(tmpP16, - hTcxCfg->tcx_aldo_window_1_trunc, + tcx_windowing_synthesis_current_frame( win, + hTcxCfg->tcx_aldo_window_2, hTcxCfg->tcx_mdct_window_half, hTcxCfg->tcx_mdct_window_minimum, L_ola, hTcxCfg->tcx_mdct_window_half_length, hTcxCfg->tcx_mdct_window_min_length, - 2 - ); + tmp2, + tmp1, + hTcxEnc->acelp_zir, + hTcxEnc->Txnq, + NULL, + Aq_old, + hTcxCfg->tcx_mdct_window_trans, + L_win, + tmp4, + tmp3, + 0, + 0 ); + + tmp1 = add( tcx_offset, imult1616( w, L_win ) ); + move16(); + tmpP16 = xn_buf16 + sub( tmp1, shr( L_ola, 1 ) ); + + IF( w > 0 ) + { + tcx_windowing_synthesis_past_frame( tmpP16, + hTcxCfg->tcx_aldo_window_1_trunc, + hTcxCfg->tcx_mdct_window_half, + hTcxCfg->tcx_mdct_window_minimum, + L_ola, + hTcxCfg->tcx_mdct_window_half_length, + hTcxCfg->tcx_mdct_window_min_length, + 2 ); } /* add part of current sub-window overlapping with previous window */ - FOR (i = 0; i < L_ola; i++) + FOR( i = 0; i < L_ola; i++ ) { #ifdef BASOP_NOGLOB tmpP16[i] = add_sat( tmpP16[i], win[i] ); #else - tmpP16[i] = add(tmpP16[i], win[i]); + tmpP16[i] = add( tmpP16[i], win[i] ); #endif move16(); } /* copy new sub-window region not overlapping with previous window */ - Copy(win + L_ola, xn_buf16 + add(tmp1, shr(L_ola, 1)), L_win); + Copy( win + L_ola, xn_buf16 + add( tmp1, shr( L_ola, 1 ) ), L_win ); } /* To assure that no garbage values are copied to hLPDmem->Txnq */ - set16_fx(xn_buf16 + add(add(L_frame, tcx_offset), shr(L_ola, 1)), - 0, sub(sub(overlap, tcx_offset), shr(L_ola, 1))); - - + set16_fx( xn_buf16 + add( add( L_frame, tcx_offset ), shr( L_ola, 1 ) ), + 0, sub( sub( overlap, tcx_offset ), shr( L_ola, 1 ) ) ); } - ELSE IF ( s_and(frame_cnt == 0, (hTcxCfg->tcx_curr_overlap_mode == FULL_OVERLAP)) ) + ELSE IF( s_and( frame_cnt == 0, ( hTcxCfg->tcx_curr_overlap_mode == FULL_OVERLAP ) ) ) { /* special overlap attempt, two transforms, grouping into one window */ - Word16 win[(L_FRAME_PLUS+L_MDCT_OVLP_MAX)/2]; + Word16 win[( L_FRAME_PLUS + L_MDCT_OVLP_MAX ) / 2]; Word16 L_win, L_spec_TCX5, L_ola, w; - L_win = shr(L_frame, 1); - L_spec_TCX5 = shr(s_max(L_frame, L_spec), 1); + L_win = shr( L_frame, 1 ); + L_spec_TCX5 = shr( s_max( L_frame, L_spec ), 1 ); L_ola = hTcxCfg->tcx_mdct_window_min_length; move16(); - set16_fx(win, 0, (L_FRAME_PLUS+L_MDCT_OVLP_MAX)/2); + set16_fx( win, 0, ( L_FRAME_PLUS + L_MDCT_OVLP_MAX ) / 2 ); /* Resize overlap (affect only asymmetric window)*/ overlap = st->hTcxCfg->tcx_mdct_window_delay; /* 1st TCX-5 window, special MDCT with minimum overlap on right side */ - TCX_MDCT_Inverse(spectrum, sub(*spectrum_e, TCX_IMDCT_SCALE+TCX_IMDCT_HEADROOM), - win + L_win, 0, sub(L_win, shr(L_ola, 1)), L_ola, st->element_mode); + TCX_MDCT_Inverse( spectrum, sub( *spectrum_e, TCX_IMDCT_SCALE + TCX_IMDCT_HEADROOM ), + win + L_win, 0, sub( L_win, shr( L_ola, 1 ) ), L_ola, st->element_mode ); /* copy new sub-window region not overlapping with previous window */ - Copy(win+L_win, xn_buf16+shr(overlap, 1), add(L_win, shr(L_ola, 1))); + Copy( win + L_win, xn_buf16 + shr( overlap, 1 ), add( L_win, shr( L_ola, 1 ) ) ); /* 2nd TCX-5 window, regular MDCT with minimum overlap on both sides */ - TCX_MDCT_Inverse(spectrum + L_spec_TCX5, sub(*spectrum_e, TCX_IMDCT_SCALE+TCX_IMDCT_HEADROOM), - win, L_ola, sub(L_win, L_ola), L_ola, st->element_mode); + TCX_MDCT_Inverse( spectrum + L_spec_TCX5, sub( *spectrum_e, TCX_IMDCT_SCALE + TCX_IMDCT_HEADROOM ), + win, L_ola, sub( L_win, L_ola ), L_ola, st->element_mode ); tmp4 = 0; move16(); - if (tcx_offset <0) + if ( tcx_offset < 0 ) { - tmp4 = negate(tcx_offset); + tmp4 = negate( tcx_offset ); } - tcx_windowing_synthesis_current_frame(win, - hTcxCfg->tcx_aldo_window_2, - hTcxCfg->tcx_mdct_window_half, - hTcxCfg->tcx_mdct_window_minimum, - L_ola, - hTcxCfg->tcx_mdct_window_half_length, - hTcxCfg->tcx_mdct_window_min_length, - 0, /* left_rect */ - 2, /* left_mode */ - hTcxEnc->acelp_zir, - hTcxEnc->Txnq, - NULL, - Aq_old, - hTcxCfg->tcx_mdct_window_trans, - L_win, - tmp4, - 1, /* not LPDmem->mode */ - 0, - 0 - ); + tcx_windowing_synthesis_current_frame( win, + hTcxCfg->tcx_aldo_window_2, + hTcxCfg->tcx_mdct_window_half, + hTcxCfg->tcx_mdct_window_minimum, + L_ola, + hTcxCfg->tcx_mdct_window_half_length, + hTcxCfg->tcx_mdct_window_min_length, + 0, /* left_rect */ + 2, /* left_mode */ + hTcxEnc->acelp_zir, + hTcxEnc->Txnq, + NULL, + Aq_old, + hTcxCfg->tcx_mdct_window_trans, + L_win, + tmp4, + 1, /* not LPDmem->mode */ + 0, + 0 ); move16(); - tmpP16 = xn_buf16 + add(sub(L_win, shr(L_ola, 1)), shr(overlap,1)); - - tcx_windowing_synthesis_past_frame(tmpP16, - hTcxCfg->tcx_aldo_window_1_trunc, - hTcxCfg->tcx_mdct_window_half, - hTcxCfg->tcx_mdct_window_minimum, - L_ola, - hTcxCfg->tcx_mdct_window_half_length, - hTcxCfg->tcx_mdct_window_min_length, - 2 - ); + tmpP16 = xn_buf16 + add( sub( L_win, shr( L_ola, 1 ) ), shr( overlap, 1 ) ); + + tcx_windowing_synthesis_past_frame( tmpP16, + hTcxCfg->tcx_aldo_window_1_trunc, + hTcxCfg->tcx_mdct_window_half, + hTcxCfg->tcx_mdct_window_minimum, + L_ola, + hTcxCfg->tcx_mdct_window_half_length, + hTcxCfg->tcx_mdct_window_min_length, + 2 ); /* add part of current sub-window overlapping with previous window */ - FOR (i = 0; i < L_ola; i++) + FOR( i = 0; i < L_ola; i++ ) { #ifdef BASOP_NOGLOB tmpP16[i] = add_sat( tmpP16[i], win[i] ); #else - tmpP16[i] = add(tmpP16[i], win[i]); + tmpP16[i] = add( tmpP16[i], win[i] ); #endif move16(); } /* copy new sub-window region not overlapping with previous window */ - Copy(win + L_ola, - xn_buf16 + add(add(shr(overlap,1), shr(L_ola, 1)), L_win), - L_win); + Copy( win + L_ola, + xn_buf16 + add( add( shr( overlap, 1 ), shr( L_ola, 1 ) ), L_win ), + L_win ); /* extra folding-out on left side of win, for perfect reconstruction */ - FOR (w = shr(overlap,1); w < overlap; w++) + FOR( w = shr( overlap, 1 ); w < overlap; w++ ) { - xn_buf16[overlap-1-w] = negate(xn_buf16[w]); + xn_buf16[overlap - 1 - w] = negate( xn_buf16[w] ); move16(); } tmp4 = 0; move16(); - if (tcx_offset < 0) + if ( tcx_offset < 0 ) { - tmp4 = negate(tcx_offset); + tmp4 = negate( tcx_offset ); } - tcx_windowing_synthesis_current_frame(xn_buf16, - hTcxCfg->tcx_aldo_window_2, - hTcxCfg->tcx_mdct_window_half, - hTcxCfg->tcx_mdct_window_minimum, - overlap, - hTcxCfg->tcx_mdct_window_half_length, - hTcxCfg->tcx_mdct_window_min_length, - st->last_core==ACELP_CORE, - 0, - hTcxEnc->acelp_zir, - hTcxEnc->Txnq, - NULL, - Aq_old, - hTcxCfg->tcx_mdct_window_trans, - L_win, - tmp4, - st->last_core, - 0, - 0 - ); + tcx_windowing_synthesis_current_frame( xn_buf16, + hTcxCfg->tcx_aldo_window_2, + hTcxCfg->tcx_mdct_window_half, + hTcxCfg->tcx_mdct_window_minimum, + overlap, + hTcxCfg->tcx_mdct_window_half_length, + hTcxCfg->tcx_mdct_window_min_length, + st->last_core == ACELP_CORE, + 0, + hTcxEnc->acelp_zir, + hTcxEnc->Txnq, + NULL, + Aq_old, + hTcxCfg->tcx_mdct_window_trans, + L_win, + tmp4, + st->last_core, + 0, + 0 ); } - ELSE /* default, i.e. maximum overlap, single transform, no grouping */ + ELSE /* default, i.e. maximum overlap, single transform, no grouping */ { - TCX_MDCT_Inverse(spectrum, sub(*spectrum_e, TCX_IMDCT_SCALE+TCX_IMDCT_HEADROOM), - xn_buf16,overlap, sub(L_frame, overlap), overlap, st->element_mode); + TCX_MDCT_Inverse( spectrum, sub( *spectrum_e, TCX_IMDCT_SCALE + TCX_IMDCT_HEADROOM ), + xn_buf16, overlap, sub( L_frame, overlap ), overlap, st->element_mode ); tmp1 = stop; move16(); test(); test(); - if ((frame_cnt > 0) && (stop == 0) && (st->last_core != ACELP_CORE)) + if ( ( frame_cnt > 0 ) && ( stop == 0 ) && ( st->last_core != ACELP_CORE ) ) { tmp1 = 2; move16(); @@ -2460,78 +2438,76 @@ void QuantizeSpectrum_fx( tmp4 = 0; move16(); - if (tcx_offset <0) + if ( tcx_offset < 0 ) { - tmp4 = negate(tcx_offset); + tmp4 = negate( tcx_offset ); } - tcx_windowing_synthesis_current_frame(xn_buf16, - hTcxCfg->tcx_aldo_window_2, - hTcxCfg->tcx_mdct_window_half, - hTcxCfg->tcx_mdct_window_minimum, - overlap, /*hTcxCfg->tcx_mdct_window_length*/ - hTcxCfg->tcx_mdct_window_half_length, - hTcxCfg->tcx_mdct_window_min_length, - st->last_core==ACELP_CORE, - tmp1, - hTcxEnc->acelp_zir, - hTcxEnc->Txnq, - NULL, - Aq_old, - hTcxCfg->tcx_mdct_window_trans, - shr(L_frame_glob, 1), - tmp4, - st->last_core, - 0, - 0 - ); + tcx_windowing_synthesis_current_frame( xn_buf16, + hTcxCfg->tcx_aldo_window_2, + hTcxCfg->tcx_mdct_window_half, + hTcxCfg->tcx_mdct_window_minimum, + overlap, /*hTcxCfg->tcx_mdct_window_length*/ + hTcxCfg->tcx_mdct_window_half_length, + hTcxCfg->tcx_mdct_window_min_length, + st->last_core == ACELP_CORE, + tmp1, + hTcxEnc->acelp_zir, + hTcxEnc->Txnq, + NULL, + Aq_old, + hTcxCfg->tcx_mdct_window_trans, + shr( L_frame_glob, 1 ), + tmp4, + st->last_core, + 0, + 0 ); } /* tcx_last_overlap_mode > 0 */ - } - ELSE /* frame is TCX-20 or not TCX-only */ + ELSE /* frame is TCX-20 or not TCX-only */ { - IF (NE_16(st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP)) + IF( NE_16( st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) ) { Word32 tmp_buf[L_FRAME_PLUS]; Word16 Q; /* DCT */ - Q = sub(31, *spectrum_e); - edct_fx(spectrum, tmp_buf, L_frame, &Q); + Q = sub( 31, *spectrum_e ); + edct_fx( spectrum, tmp_buf, L_frame, &Q ); /* scale by sqrt(L / NORM_MDCT_FACTOR) */ - tmp1 = mult_r(shl(L_frame, 4), 26214/*128.f / NORM_MDCT_FACTOR Q15*/); /* 4Q11 */ + tmp1 = mult_r( shl( L_frame, 4 ), 26214 /*128.f / NORM_MDCT_FACTOR Q15*/ ); /* 4Q11 */ tmp2 = 4; move16(); - tmp1 = Sqrt16(tmp1, &tmp2); + tmp1 = Sqrt16( tmp1, &tmp2 ); - FOR (i = 0; i < L_frame; i++) + FOR( i = 0; i < L_frame; i++ ) { - tmp_buf[i] = Mpy_32_16_1(tmp_buf[i], tmp1); + tmp_buf[i] = Mpy_32_16_1( tmp_buf[i], tmp1 ); move32(); } - Q = sub(Q, tmp2); + Q = sub( Q, tmp2 ); - window_ola_fx(tmp_buf, - xn_buf16, - &Q, - hTcxEnc->old_out_fx, - &hTcxEnc->Q_old_out, - L_frame, - hTcxCfg->tcx_last_overlap_mode, - hTcxCfg->tcx_curr_overlap_mode, - 0, - 0, - NULL); + window_ola_fx( tmp_buf, + xn_buf16, + &Q, + hTcxEnc->old_out_fx, + &hTcxEnc->Q_old_out, + L_frame, + hTcxCfg->tcx_last_overlap_mode, + hTcxCfg->tcx_curr_overlap_mode, + 0, + 0, + NULL ); /* scale output */ - FOR (i = 0; i < L_frame; i++) + FOR( i = 0; i < L_frame; i++ ) { #ifdef BASOP_NOGLOB - xn_buf16[i] = shr_o(xn_buf16[i], Q, &Overflow); -#else /* BASOP_NOGLOB */ - xn_buf16[i] = shr(xn_buf16[i], Q); + xn_buf16[i] = shr_o( xn_buf16[i], Q, &Overflow ); +#else /* BASOP_NOGLOB */ + xn_buf16[i] = shr( xn_buf16[i], Q ); #endif /* BASOP_NOGLOB */ move16(); } @@ -2542,8 +2518,8 @@ void QuantizeSpectrum_fx( ELSE { - TCX_MDCT_Inverse(spectrum, sub(*spectrum_e, TCX_IMDCT_SCALE+TCX_IMDCT_HEADROOM), - xn_buf16, overlap, sub(L_frame, overlap), overlap, st->element_mode); + TCX_MDCT_Inverse( spectrum, sub( *spectrum_e, TCX_IMDCT_SCALE + TCX_IMDCT_HEADROOM ), + xn_buf16, overlap, sub( L_frame, overlap ), overlap, st->element_mode ); /*-----------------------------------------------------------* * Windowing, overlap and add * @@ -2552,30 +2528,29 @@ void QuantizeSpectrum_fx( /* Window current frame */ tmp4 = 0; move16(); - if (tcx_offset<0) + if ( tcx_offset < 0 ) { - tmp4 = negate(tcx_offset); + tmp4 = negate( tcx_offset ); } - tcx_windowing_synthesis_current_frame(xn_buf16, - hTcxCfg->tcx_aldo_window_2, - hTcxCfg->tcx_mdct_window_half, - hTcxCfg->tcx_mdct_window_minimum, - overlap, /*hTcxCfg->tcx_mdct_window_length*/ - hTcxCfg->tcx_mdct_window_half_length, - hTcxCfg->tcx_mdct_window_min_length, - st->last_core==ACELP_CORE, - hTcxCfg->tcx_last_overlap_mode, /*left mode*/ - hTcxEnc->acelp_zir, - hTcxEnc->Txnq, - NULL, - Aq_old, - hTcxCfg->tcx_mdct_window_trans, - shr(L_frame_glob, 1), - tmp4, - st->last_core, - 0, - 0 - ); + tcx_windowing_synthesis_current_frame( xn_buf16, + hTcxCfg->tcx_aldo_window_2, + hTcxCfg->tcx_mdct_window_half, + hTcxCfg->tcx_mdct_window_minimum, + overlap, /*hTcxCfg->tcx_mdct_window_length*/ + hTcxCfg->tcx_mdct_window_half_length, + hTcxCfg->tcx_mdct_window_min_length, + st->last_core == ACELP_CORE, + hTcxCfg->tcx_last_overlap_mode, /*left mode*/ + hTcxEnc->acelp_zir, + hTcxEnc->Txnq, + NULL, + Aq_old, + hTcxCfg->tcx_mdct_window_trans, + shr( L_frame_glob, 1 ), + tmp4, + st->last_core, + 0, + 0 ); } } /* TCX-10 and TCX-only */ @@ -2583,53 +2558,53 @@ void QuantizeSpectrum_fx( test(); test(); test(); - IF ((st->last_core > ACELP_CORE) && (((EQ_16(L_frameTCX, shr(hTcxEnc->L_frameTCX, 1)))&&(st->tcxonly!=0))||(EQ_16(st->hTcxCfg->tcx_last_overlap_mode,TRANSITION_OVERLAP)))) + IF( ( st->last_core > ACELP_CORE ) && ( ( ( EQ_16( L_frameTCX, shr( hTcxEnc->L_frameTCX, 1 ) ) ) && ( st->tcxonly != 0 ) ) || ( EQ_16( st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) ) ) ) { - IF (hTcxCfg->last_aldo != 0) + IF( hTcxCfg->last_aldo != 0 ) { - tmp2 = add(hTcxEnc->Q_old_out, TCX_IMDCT_HEADROOM); + tmp2 = add( hTcxEnc->Q_old_out, TCX_IMDCT_HEADROOM ); - tmp1 = sub(overlap, hTcxCfg->tcx_mdct_window_min_length); - FOR (i=0; i < tmp1; i++) + tmp1 = sub( overlap, hTcxCfg->tcx_mdct_window_min_length ); + FOR( i = 0; i < tmp1; i++ ) { #ifdef BASOP_NOGLOB xn_buf16[i] = shl_sat( add_sat( xn_buf16[i], shr_sat( hTcxEnc->old_out_fx[i + nz], tmp2 ) ), TCX_IMDCT_HEADROOM ); #else - xn_buf16[i] = shl(add(xn_buf16[i], shr(hTcxEnc->old_out_fx[i+nz], tmp2)), TCX_IMDCT_HEADROOM); + xn_buf16[i] = shl( add( xn_buf16[i], shr( hTcxEnc->old_out_fx[i + nz], tmp2 ) ), TCX_IMDCT_HEADROOM ); #endif move16(); } /* fade truncated ALDO window */ - tmp1 = sub(overlap, shr(hTcxCfg->tcx_mdct_window_min_length, 1)); - FOR ( ; i < tmp1; i++) + tmp1 = sub( overlap, shr( hTcxCfg->tcx_mdct_window_min_length, 1 ) ); + FOR( ; i < tmp1; i++ ) { - tmp3 = mult_r(shr(hTcxEnc->old_out_fx[i+nz], tmp2), hTcxCfg->tcx_mdct_window_minimum[i-overlap+hTcxCfg->tcx_mdct_window_min_length].v.re); + tmp3 = mult_r( shr( hTcxEnc->old_out_fx[i + nz], tmp2 ), hTcxCfg->tcx_mdct_window_minimum[i - overlap + hTcxCfg->tcx_mdct_window_min_length].v.re ); #ifdef BASOP_NOGLOB xn_buf16[i] = shl_sat( add_sat( xn_buf16[i], tmp3 ), TCX_IMDCT_HEADROOM ); #else - xn_buf16[i] = shl(add(xn_buf16[i], tmp3), TCX_IMDCT_HEADROOM); + xn_buf16[i] = shl( add( xn_buf16[i], tmp3 ), TCX_IMDCT_HEADROOM ); #endif move16(); } - FOR ( ; i < overlap; i++) + FOR( ; i < overlap; i++ ) { - tmp3 = mult_r(shr(hTcxEnc->old_out_fx[i+nz], tmp2), hTcxCfg->tcx_mdct_window_minimum[overlap-1-i].v.im); + tmp3 = mult_r( shr( hTcxEnc->old_out_fx[i + nz], tmp2 ), hTcxCfg->tcx_mdct_window_minimum[overlap - 1 - i].v.im ); #ifdef BASOP_NOGLOB xn_buf16[i] = shl_sat( add_sat( xn_buf16[i], tmp3 ), TCX_IMDCT_HEADROOM ); #else - xn_buf16[i] = shl(add(xn_buf16[i], tmp3), TCX_IMDCT_HEADROOM); + xn_buf16[i] = shl( add( xn_buf16[i], tmp3 ), TCX_IMDCT_HEADROOM ); #endif move16(); } - FOR ( ; i < L_frame; i++) + FOR( ; i < L_frame; i++ ) { #ifdef BASOP_NOGLOB xn_buf16[i] = shl_sat( xn_buf16[i], TCX_IMDCT_HEADROOM ); #else - xn_buf16[i] = shl(xn_buf16[i], TCX_IMDCT_HEADROOM); + xn_buf16[i] = shl( xn_buf16[i], TCX_IMDCT_HEADROOM ); #endif move16(); } @@ -2639,25 +2614,26 @@ void QuantizeSpectrum_fx( test(); test(); test(); - if ((frame_cnt > 0) && (stop == 0) && (hTcxCfg->tcx_curr_overlap_mode == 0) && (st->last_core != ACELP_CORE)) + if ( ( frame_cnt > 0 ) && ( stop == 0 ) && ( hTcxCfg->tcx_curr_overlap_mode == 0 ) && ( st->last_core != ACELP_CORE ) ) { - stop = 2; /* use minimum overlap between the two TCX-10 windows */ move16(); + stop = 2; /* use minimum overlap between the two TCX-10 windows */ + move16(); } tmp1 = stop; move16(); test(); - if ((stop == 0) || (EQ_16(hTcxCfg->tcx_last_overlap_mode, MIN_OVERLAP))) + if ( ( stop == 0 ) || ( EQ_16( hTcxCfg->tcx_last_overlap_mode, MIN_OVERLAP ) ) ) { tmp1 = hTcxCfg->tcx_last_overlap_mode; move16(); } - tcx_windowing_synthesis_past_frame(hTcxEnc->Txnq,hTcxCfg->tcx_aldo_window_1_trunc,hTcxCfg->tcx_mdct_window_half, - hTcxCfg->tcx_mdct_window_minimum,overlap,hTcxCfg->tcx_mdct_window_half_length,hTcxCfg->tcx_mdct_window_min_length,tmp1); + tcx_windowing_synthesis_past_frame( hTcxEnc->Txnq, hTcxCfg->tcx_aldo_window_1_trunc, hTcxCfg->tcx_mdct_window_half, + hTcxCfg->tcx_mdct_window_minimum, overlap, hTcxCfg->tcx_mdct_window_half_length, hTcxCfg->tcx_mdct_window_min_length, tmp1 ); BASOP_SATURATE_WARNING_OFF_EVS; - FOR (i=0; iTxnq[i] ), TCX_IMDCT_HEADROOM ); @@ -2667,9 +2643,9 @@ void QuantizeSpectrum_fx( move16(); } - IF (LT_16(i, L_frame)) + IF( LT_16( i, L_frame ) ) { - FOR ( ; i < L_frame; i++) + FOR( ; i < L_frame; i++ ) { #ifdef BASOP_NOGLOB xn_buf16[i] = shl_sat( xn_buf16[i], TCX_IMDCT_HEADROOM ); @@ -2684,15 +2660,15 @@ void QuantizeSpectrum_fx( } ELSE { - IF (aldo == 0) + IF( aldo == 0 ) { BASOP_SATURATE_WARNING_OFF_EVS; - FOR (i = 0; i < L_frame; i++) + FOR( i = 0; i < L_frame; i++ ) { #ifdef BASOP_NOGLOB - xn_buf16[i] = shl_o(xn_buf16[i], TCX_IMDCT_HEADROOM, &Overflow); + xn_buf16[i] = shl_o( xn_buf16[i], TCX_IMDCT_HEADROOM, &Overflow ); #else /* BASOP_NOGLOB */ - xn_buf16[i] = shl(xn_buf16[i], TCX_IMDCT_HEADROOM); + xn_buf16[i] = shl( xn_buf16[i], TCX_IMDCT_HEADROOM ); #endif move16(); } @@ -2703,35 +2679,34 @@ void QuantizeSpectrum_fx( test(); test(); test(); - IF ( (aldo == 0) && - ((EQ_16(L_frameTCX, shr(hTcxEnc->L_frameTCX, 1)) && frame_cnt > 0) || - NE_16(L_frameTCX, shr(hTcxEnc->L_frameTCX, 1)) ) ) + IF( ( aldo == 0 ) && + ( ( EQ_16( L_frameTCX, shr( hTcxEnc->L_frameTCX, 1 ) ) && frame_cnt > 0 ) || + NE_16( L_frameTCX, shr( hTcxEnc->L_frameTCX, 1 ) ) ) ) { /*Compute windowed synthesis in case of switching to ALDO windows in next frame*/ - FOR (i = 0; i < nz; i++) + FOR( i = 0; i < nz; i++ ) { - hTcxEnc->old_out_fx[i] = shr(xn_buf16[L_frame-nz+i], TCX_IMDCT_HEADROOM); + hTcxEnc->old_out_fx[i] = shr( xn_buf16[L_frame - nz + i], TCX_IMDCT_HEADROOM ); move16(); } - Copy(xn_buf16+L_frame, hTcxEnc->old_out_fx+nz, overlap); - set16_fx(hTcxEnc->old_out_fx+nz+overlap, 0, nz); + Copy( xn_buf16 + L_frame, hTcxEnc->old_out_fx + nz, overlap ); + set16_fx( hTcxEnc->old_out_fx + nz + overlap, 0, nz ); - tcx_windowing_synthesis_past_frame(hTcxEnc->old_out_fx+nz, + tcx_windowing_synthesis_past_frame( hTcxEnc->old_out_fx + nz, hTcxCfg->tcx_aldo_window_1_trunc, hTcxCfg->tcx_mdct_window_half, hTcxCfg->tcx_mdct_window_minimum, overlap, hTcxCfg->tcx_mdct_window_half_length, hTcxCfg->tcx_mdct_window_min_length, - hTcxCfg->tcx_curr_overlap_mode - ); + hTcxCfg->tcx_curr_overlap_mode ); /* If current overlap mode = FULL_OVERLAP -> ALDO_WINDOW */ - IF (EQ_16(hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP)) + IF( EQ_16( hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) ) { - FOR (i=0; iold_out_fx[nz+overlap+i] = shr(mult_r(xn_buf16[L_frame-1-i], hTcxCfg->tcx_aldo_window_1[nz-1-i]), TCX_IMDCT_HEADROOM); + hTcxEnc->old_out_fx[nz + overlap + i] = shr( mult_r( xn_buf16[L_frame - 1 - i], hTcxCfg->tcx_aldo_window_1[nz - 1 - i] ), TCX_IMDCT_HEADROOM ); move16(); } hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; @@ -2745,15 +2720,14 @@ void QuantizeSpectrum_fx( move16(); /* Update Txnq */ - IF (hTcxCfg->last_aldo == 0) + IF( hTcxCfg->last_aldo == 0 ) { - Copy(xn_buf16 + L_frame, hTcxEnc->Txnq, overlap); + Copy( xn_buf16 + L_frame, hTcxEnc->Txnq, overlap ); } /* Output */ - Copy(xn_buf16+shr(overlap,1)-tcx_offset, synth, L_frame_glob); - + Copy( xn_buf16 + shr( overlap, 1 ) - tcx_offset, synth, L_frame_glob ); } /* Free internal TCX decoder stack memory */ @@ -2762,27 +2736,25 @@ void QuantizeSpectrum_fx( /* Update L_frame_past */ st->L_frame_past = L_frame; move16(); - } void coder_tcx_fx( Word16 n, TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */ - Word16 A[], /* input: quantized coefficients NxAz_q[M+1] */ - Word16 Aqind[], /* input: frame-independent quantized coefficients (M+1) */ + Word16 A[], /* input: quantized coefficients NxAz_q[M+1] */ + Word16 Aqind[], /* input: frame-independent quantized coefficients (M+1) */ Word16 synth[], - Word16 L_frame_glob, /* input: frame length */ + Word16 L_frame_glob, /* input: frame length */ Word16 L_frameTCX_glob, Word16 L_spec, - Word16 nb_bits, /*input: bit budget*/ - Word8 tcxonly, /*input: only TCX flag*/ - Word32 spectrum[], /* i/o: MDCT spectrum */ - Word16 *spectrum_e, /* i/o: MDCT spectrum exponent */ - Word16 prm[], /* output: tcx parameters */ + Word16 nb_bits, /*input: bit budget*/ + Word8 tcxonly, /*input: only TCX flag*/ + Word32 spectrum[], /* i/o: MDCT spectrum */ + Word16 *spectrum_e, /* i/o: MDCT spectrum exponent */ + Word16 prm[], /* output: tcx parameters */ Encoder_State *st, - CONTEXT_HM_CONFIG *hm_cfg -) + CONTEXT_HM_CONFIG *hm_cfg ) { Word16 L_frame; Word16 left_overlap, right_overlap; @@ -2790,10 +2762,10 @@ void coder_tcx_fx( Word16 tnsBits; /* number of tns bits in the frame */ Word16 ltpBits; Word16 gainlpc[FDNS_NPTS], gainlpc_e[FDNS_NPTS]; - Word16 win[N_MAX+L_MDCT_OVLP_MAX]; + Word16 win[N_MAX + L_MDCT_OVLP_MAX]; Word32 powerSpec[N_MAX]; Word16 powerSpec_e; - Word16 winMDST[N_MAX+L_MDCT_OVLP_MAX]; + Word16 winMDST[N_MAX + L_MDCT_OVLP_MAX]; Word16 *pWinMDST; Word16 left_overlap_mode, right_overlap_mode; LPD_state_HANDLE hLPDmem = st->hLPDmem; @@ -2815,11 +2787,11 @@ void coder_tcx_fx( /*-----------------------------------------------------------* * Windowing * *-----------------------------------------------------------*/ - IF (EQ_16(st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP)) + IF( EQ_16( st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) ) { - WindowSignal(hTcxCfg, hTcxCfg->tcx_offsetFB, hTcxCfg->tcx_last_overlap_mode, hTcxCfg->tcx_curr_overlap_mode, &left_overlap, &right_overlap, - hTcxEnc->speech_TCX, &L_frame, win ,1, 1); + WindowSignal( hTcxCfg, hTcxCfg->tcx_offsetFB, hTcxCfg->tcx_last_overlap_mode, hTcxCfg->tcx_curr_overlap_mode, &left_overlap, &right_overlap, + hTcxEnc->speech_TCX, &L_frame, win, 1, 1 ); /*-----------------------------------------------------------* * Compute MDCT * @@ -2827,7 +2799,7 @@ void coder_tcx_fx( *spectrum_e = 16; move16(); - TCX_MDCT(win, spectrum, spectrum_e, left_overlap, sub(L_frame, shr(add(left_overlap, right_overlap), 1)), right_overlap, st->element_mode); + TCX_MDCT( win, spectrum, spectrum_e, left_overlap, sub( L_frame, shr( add( left_overlap, right_overlap ), 1 ) ), right_overlap, st->element_mode ); } ELSE { @@ -2837,18 +2809,18 @@ void coder_tcx_fx( Q = 0; move16(); - wtda_fx(hTcxEnc->new_speech_TCX,&Q,tmp_buf,NULL,NULL,hTcxCfg->tcx_last_overlap_mode,hTcxCfg->tcx_curr_overlap_mode,L_frame); + wtda_fx( hTcxEnc->new_speech_TCX, &Q, tmp_buf, NULL, NULL, hTcxCfg->tcx_last_overlap_mode, hTcxCfg->tcx_curr_overlap_mode, L_frame ); left_overlap_mode = hTcxCfg->tcx_last_overlap_mode; move16(); - if (EQ_16(left_overlap_mode, ALDO_WINDOW)) + if ( EQ_16( left_overlap_mode, ALDO_WINDOW ) ) { left_overlap_mode = FULL_OVERLAP; move16(); } right_overlap_mode = hTcxCfg->tcx_curr_overlap_mode; move16(); - if (EQ_16(right_overlap_mode, ALDO_WINDOW)) + if ( EQ_16( right_overlap_mode, ALDO_WINDOW ) ) { right_overlap_mode = FULL_OVERLAP; move16(); @@ -2857,21 +2829,21 @@ void coder_tcx_fx( WindowSignal( hTcxCfg, hTcxCfg->tcx_offsetFB, left_overlap_mode, right_overlap_mode, &left_overlap, &right_overlap, hTcxEnc->speech_TCX, &L_frame, winMDST, 1, 1 ); /* scale by NORM_MDCT_FACTOR / L */ - tmp1 = mult_r(shl(L_frame, 4), 26214/*128.f / NORM_MDCT_FACTOR Q15*/); /* 4Q11 */ + tmp1 = mult_r( shl( L_frame, 4 ), 26214 /*128.f / NORM_MDCT_FACTOR Q15*/ ); /* 4Q11 */ tmp2 = 4; move16(); - tmp1 = ISqrt16(tmp1, &tmp2); + tmp1 = ISqrt16( tmp1, &tmp2 ); - FOR (i = 0; i < L_frame; i++) + FOR( i = 0; i < L_frame; i++ ) { - tmp_buf[i] = Mpy_32_16_1(tmp_buf[i], tmp1); + tmp_buf[i] = Mpy_32_16_1( tmp_buf[i], tmp1 ); move32(); } - Q = sub(Q, tmp2); + Q = sub( Q, tmp2 ); /* DCT */ - edct_fx(tmp_buf, spectrum, L_frame, &Q); - *spectrum_e = sub(31, Q); + edct_fx( tmp_buf, spectrum, L_frame, &Q ); + *spectrum_e = sub( 31, Q ); } @@ -2880,9 +2852,9 @@ void coder_tcx_fx( * to simulate ACELP behavior * *-----------------------------------------------------------*/ - IF (st->narrowBand != 0) + IF( st->narrowBand != 0 ) { - attenuateNbSpectrum_fx(L_frame, spectrum); + attenuateNbSpectrum_fx( L_frame, spectrum ); } /*-----------------------------------------------------------* @@ -2893,30 +2865,28 @@ void coder_tcx_fx( pWinMDST = winMDST; move16(); - if (EQ_16(st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP)) + if ( EQ_16( st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) ) { pWinMDST = win; move16(); } - AnalyzePowerSpectrum_fx(st, - round_fx(L_shl(Mpy_32_16_1(L_mult0(L_frame,st->L_frame)/*Q0*/, - getInvFrameLen(hTcxEnc->L_frameTCX)/*Q21*/)/*Q6*/,16-6)), - L_frame, - left_overlap, right_overlap, - spectrum, *spectrum_e, - pWinMDST, - powerSpec, &powerSpec_e); - IF (hTcxCfg->fIsTNSAllowed != 0) + AnalyzePowerSpectrum_fx( st, + round_fx( L_shl( Mpy_32_16_1( L_mult0( L_frame, st->L_frame ) /*Q0*/, + getInvFrameLen( hTcxEnc->L_frameTCX ) /*Q21*/ ) /*Q6*/, + 16 - 6 ) ), + L_frame, + left_overlap, right_overlap, + spectrum, *spectrum_e, + pWinMDST, + powerSpec, &powerSpec_e ); + IF( hTcxCfg->fIsTNSAllowed != 0 ) { test(); test(); - SetTnsConfig(hTcxCfg, sub(L_frame_glob, st->L_frame) == 0, st->last_core == 0); - - TNSAnalysis_fx(hTcxCfg, L_frame, L_spec, TCX_20, st->last_core == 0, spectrum, hTcxEnc->tnsData, hTcxEnc->fUseTns_fx - , &st->hIGFEnc->tns_predictionGain - ); + SetTnsConfig( hTcxCfg, sub( L_frame_glob, st->L_frame ) == 0, st->last_core == 0 ); + TNSAnalysis_fx( hTcxCfg, L_frame, L_spec, TCX_20, st->last_core == 0, spectrum, hTcxEnc->tnsData, hTcxEnc->fUseTns_fx, &st->hIGFEnc->tns_predictionGain ); } ELSE { @@ -2925,68 +2895,65 @@ void coder_tcx_fx( move16(); } - IF(st->igf) + IF( st->igf ) { - ProcessIGF_fx(st->hIGFEnc, st, spectrum, spectrum_e, powerSpec, &powerSpec_e, 1, hTcxEnc->fUseTns_fx[0], (st->last_core == ACELP_CORE), 0); + ProcessIGF_fx( st->hIGFEnc, st, spectrum, spectrum_e, powerSpec, &powerSpec_e, 1, hTcxEnc->fUseTns_fx[0], ( st->last_core == ACELP_CORE ), 0 ); } - ShapeSpectrum_fx(hTcxCfg, A, gainlpc, gainlpc_e, - L_frame_glob, - L_spec, - spectrum, - hTcxEnc->fUseTns_fx[0], - st - ); - if(st->igf) + ShapeSpectrum_fx( hTcxCfg, A, gainlpc, gainlpc_e, + L_frame_glob, + L_spec, + spectrum, + hTcxEnc->fUseTns_fx[0], + st ); + if ( st->igf ) { - nb_bits = sub(nb_bits, st->hIGFEnc->infoTotalBitsPerFrameWritten); + nb_bits = sub( nb_bits, st->hIGFEnc->infoTotalBitsPerFrameWritten ); } - IF (hTcxCfg->fIsTNSAllowed != 0) + IF( hTcxCfg->fIsTNSAllowed != 0 ) { - EncodeTnsData_fx(hTcxCfg->pCurrentTnsConfig, hTcxEnc->tnsData, prm+1+NOISE_FILL_RANGES+LTPSIZE, &tnsSize, &tnsBits); + EncodeTnsData_fx( hTcxCfg->pCurrentTnsConfig, hTcxEnc->tnsData, prm + 1 + NOISE_FILL_RANGES + LTPSIZE, &tnsSize, &tnsBits ); } - QuantizeSpectrum_fx(hTcxCfg, - A, - Aqind, - gainlpc, gainlpc_e, - synth, - L_frame_glob, - L_frameTCX_glob, - L_spec, - sub(sub(nb_bits, tnsBits), ltpBits), - tcxonly, - spectrum, spectrum_e, - hTcxEnc->tnsData, - hTcxEnc->fUseTns_fx[0], - tnsSize, - prm, - n, - st, - hm_cfg - ); - - hLPDmem->nbits = add(hLPDmem->nbits, add(tnsBits, ltpBits)); - + QuantizeSpectrum_fx( hTcxCfg, + A, + Aqind, + gainlpc, gainlpc_e, + synth, + L_frame_glob, + L_frameTCX_glob, + L_spec, + sub( sub( nb_bits, tnsBits ), ltpBits ), + tcxonly, + spectrum, spectrum_e, + hTcxEnc->tnsData, + hTcxEnc->fUseTns_fx[0], + tnsSize, + prm, + n, + st, + hm_cfg ); + + hLPDmem->nbits = add( hLPDmem->nbits, add( tnsBits, ltpBits ) ); } /*-------------------------------------------------------------------* -* coder_tcx_post_fx() -* -* -*-------------------------------------------------------------------*/ + * coder_tcx_post_fx() + * + * + *-------------------------------------------------------------------*/ void coder_tcx_post_fx( Encoder_State *st, LPD_state *LPDmem, - TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */ Word16 *synth, + TCX_CONFIG_HANDLE hTcxCfg, + /* i : configuration of TCX */ Word16 *synth, const Word16 *A, const Word16 *Ai, Word16 *wsig, Word16 Q_new, - Word16 shift -) + Word16 shift ) { Word16 xn_buf[L_FRAME_MAX]; diff --git a/lib_enc/cod_uv_fx.c b/lib_enc/cod_uv_fx.c index e091a1ce9..5ebfe4840 100644 --- a/lib_enc/cod_uv_fx.c +++ b/lib_enc/cod_uv_fx.c @@ -7,10 +7,10 @@ #include //#include "prot_fx.h" #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ -#include "basop_util.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ +#include "basop_util.h" /* Function prototypes */ /*-------------------------------------------------------------------* * gauss_L2_fx: @@ -21,71 +21,68 @@ * Gaussian excitation is generated by a white noise and shapes it with LPC-derived filter *-------------------------------------------------------------------*/ void gauss_L2_fx( - const Word16 h[], /* i : weighted LP filter impulse response Q14+s */ - Word16 code[], /* o : gaussian excitation Q9 */ - const Word16 y2[], /* i : zero-memory filtered code. excitation Q9 */ - Word16 y11[], /* o : zero-memory filtered gauss. excitation Q9 */ - Word32 *gain, /* o : excitation gain Q16 */ - ACELP_CbkCorr *g_corr, /*i/o : correlation structure for gain coding */ - const Word16 gain_pit, /* i : unquantized gain of code Q14 */ - const Word16 tilt_code, /* i : tilt of code Q15 */ - const Word16 *Aq, /* i : quantized LPCs Q12 */ + const Word16 h[], /* i : weighted LP filter impulse response Q14+s */ + Word16 code[], /* o : gaussian excitation Q9 */ + const Word16 y2[], /* i : zero-memory filtered code. excitation Q9 */ + Word16 y11[], /* o : zero-memory filtered gauss. excitation Q9 */ + Word32 *gain, /* o : excitation gain Q16 */ + ACELP_CbkCorr *g_corr, /*i/o : correlation structure for gain coding */ + const Word16 gain_pit, /* i : unquantized gain of code Q14 */ + const Word16 tilt_code, /* i : tilt of code Q15 */ + const Word16 *Aq, /* i : quantized LPCs Q12 */ const Word16 formant_enh_num, /* i : formant enhancement numerator factor Q15 */ - Word16 *seed_acelp, /*i/o : random seed Q0 */ - const Word16 shift -) + Word16 *seed_acelp, /*i/o : random seed Q0 */ + const Word16 shift ) { Word16 i, tmp16; Word32 tmp32, tmp32_2; - assert(gain_pit==0); + assert( gain_pit == 0 ); /*-----------------------------------------------------------------* * Find new target for the Gaussian codebook *-----------------------------------------------------------------*/ /*Generate white gaussian noise using central limit theorem method (N only 4 as E_util_random is not purely uniform)*/ - FOR (i = 0; i < L_SUBFR; i++) + FOR( i = 0; i < L_SUBFR; i++ ) { - *seed_acelp = own_random2_fx(*seed_acelp); - tmp32 = L_mac(0, *seed_acelp, 1<<9); + *seed_acelp = own_random2_fx( *seed_acelp ); + tmp32 = L_mac( 0, *seed_acelp, 1 << 9 ); - *seed_acelp = own_random2_fx(*seed_acelp); - tmp32 = L_mac(tmp32, *seed_acelp, 1<<9); + *seed_acelp = own_random2_fx( *seed_acelp ); + tmp32 = L_mac( tmp32, *seed_acelp, 1 << 9 ); - *seed_acelp = own_random2_fx(*seed_acelp); - code[i] = mac_r(tmp32, *seed_acelp, 1<<9); + *seed_acelp = own_random2_fx( *seed_acelp ); + code[i] = mac_r( tmp32, *seed_acelp, 1 << 9 ); move16(); } /*Shape the gaussian excitation*/ - cb_shape_fx( 1, 0, 0, 1, 0, formant_enh_num, FORMANT_SHARPENING_G2, Aq, code, tilt_code, 0, 1 , L_SUBFR); + cb_shape_fx( 1, 0, 0, 1, 0, formant_enh_num, FORMANT_SHARPENING_G2, Aq, code, tilt_code, 0, 1, L_SUBFR ); /*compute 0s memory weighted synthesis contribution and find gain*/ - E_UTIL_f_convolve(code, h, y11, L_SUBFR); /* y11: Q8+shift */ - Scale_sig(y11, L_SUBFR, sub(1, shift)); /* Q9 */ - *gain = L_deposit_l(0); + E_UTIL_f_convolve( code, h, y11, L_SUBFR ); /* y11: Q8+shift */ + Scale_sig( y11, L_SUBFR, sub( 1, shift ) ); /* Q9 */ + *gain = L_deposit_l( 0 ); /*Update correlations for gains coding */ - tmp32 = L_shr(21474836l/*0.01f Q31*/, 31-18); /* Q18 */ - tmp32_2 = L_shr(21474836l/*0.01f Q31*/, 31-18); /* Q18 */ + tmp32 = L_shr( 21474836l /*0.01f Q31*/, 31 - 18 ); /* Q18 */ + tmp32_2 = L_shr( 21474836l /*0.01f Q31*/, 31 - 18 ); /* Q18 */ - FOR (i = 0; i < L_SUBFR; i++) + FOR( i = 0; i < L_SUBFR; i++ ) { - tmp32 = L_mac0(tmp32, y11[i], y11[i]); /* Q18 */ - tmp32_2 = L_mac0(tmp32_2, y11[i], y2[i]); /* Q18 */ + tmp32 = L_mac0( tmp32, y11[i], y11[i] ); /* Q18 */ + tmp32_2 = L_mac0( tmp32_2, y11[i], y2[i] ); /* Q18 */ } - tmp16 = norm_l(tmp32); - g_corr->y1y1 = round_fx(L_shl(tmp32, tmp16)); - g_corr->y1y1_e = sub(31-18, tmp16); + tmp16 = norm_l( tmp32 ); + g_corr->y1y1 = round_fx( L_shl( tmp32, tmp16 ) ); + g_corr->y1y1_e = sub( 31 - 18, tmp16 ); move16(); - tmp16 = norm_l(tmp32_2); - g_corr->y1y2 = round_fx(L_shl(tmp32_2, tmp16)); - g_corr->y1y2_e = sub(31-18, tmp16); + tmp16 = norm_l( tmp32_2 ); + g_corr->y1y2 = round_fx( L_shl( tmp32_2, tmp16 ) ); + g_corr->y1y2_e = sub( 31 - 18, tmp16 ); move16(); - } - diff --git a/lib_enc/comvad_decision_fx.c b/lib_enc/comvad_decision_fx.c index ebd736e80..2fa8069f8 100644 --- a/lib_enc/comvad_decision_fx.c +++ b/lib_enc/comvad_decision_fx.c @@ -5,36 +5,35 @@ #include #include "options.h" -#include "cnst.h" /* Common constants */ +#include "cnst.h" /* Common constants */ #include "basop_util.h" #include "vad_basop.h" //#include "prot_fx.h" -#include "rom_enc.h" /* Encoder static table prototypes */ -#include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "basop_util.h" /* Function prototypes */ +#include "rom_enc.h" /* Encoder static table prototypes */ +#include "rom_com.h" /* Common constants */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "basop_util.h" /* Function prototypes */ #include "prot_fx_enc.h" - /*-------------------------------------------------------------------* * local function prototypes *-------------------------------------------------------------------*/ /* only one is activated in below preprocessing*/ -/*#define CLDFB_VAD*/ /* test on the CLDFB-VAD */ +/*#define CLDFB_VAD*/ /* test on the CLDFB-VAD */ static Word16 comvad_hangover( - const Word32 lt_snr_org, /* i : original long time SNR*/ - const Word32 snr, /* i : frequency domain SNR */ - const Word32 l_snr, /* i : long time frequency domain SNR calculated by l_speech_snr and l_silence_snr*/ - const Word32 snr_flux, /* i : average tsnr*/ - const Word16 bw_index, /* i : band width index*/ + const Word32 lt_snr_org, /* i : original long time SNR*/ + const Word32 snr, /* i : frequency domain SNR */ + const Word32 l_snr, /* i : long time frequency domain SNR calculated by l_speech_snr and l_silence_snr*/ + const Word32 snr_flux, /* i : average tsnr*/ + const Word16 bw_index, /* i : band width index*/ const Word16 vad_flag, - const Word16 pre_res_hang_num, /* i : residual amount of previous hangover */ - const Word16 continuous_speech_num2, /* i : amount of continuous speech frames*/ - const Word16 noisy_type /* i : noisy type*/ + const Word16 pre_res_hang_num, /* i : residual amount of previous hangover */ + const Word16 continuous_speech_num2, /* i : amount of continuous speech frames*/ + const Word16 noisy_type /* i : noisy type*/ ) { Word32 l_snr_add; @@ -44,13 +43,13 @@ static Word16 comvad_hangover( speech_flag = pre_res_hang_num; move16(); - IF(EQ_16(bw_index, CLDFBVAD_SWB_ID)) + IF( EQ_16( bw_index, CLDFBVAD_SWB_ID ) ) { - IF(vad_flag) + IF( vad_flag ) { speech_flag = 4; move16(); - if(GT_32(lt_snr_org, 117440509/* 3.5 Q25 */)) + if ( GT_32( lt_snr_org, 117440509 /* 3.5 Q25 */ ) ) { speech_flag = 3; move16(); @@ -58,23 +57,23 @@ static Word16 comvad_hangover( test(); test(); - IF((LT_16(continuous_speech_num2, 8))&&(LT_32(lt_snr_org,134217724/* 4.0 Q25 */))) + IF( ( LT_16( continuous_speech_num2, 8 ) ) && ( LT_32( lt_snr_org, 134217724 /* 4.0 Q25 */ ) ) ) { - speech_flag = sub(8, continuous_speech_num2); + speech_flag = sub( 8, continuous_speech_num2 ); } - ELSE IF((GT_32(snr_flux, 26843545/* 0.8 Q25 */))&&(GT_16(continuous_speech_num2,24))) + ELSE IF( ( GT_32( snr_flux, 26843545 /* 0.8 Q25 */ ) ) && ( GT_16( continuous_speech_num2, 24 ) ) ) { - IF(GT_32(lt_snr_org, 120795952/* 3.6 Q25 */)) + IF( GT_32( lt_snr_org, 120795952 /* 3.6 Q25 */ ) ) { speech_flag = 3; move16(); } - ELSE IF(GT_32(lt_snr_org, 87241521/* 2.6 Q25 */)) + ELSE IF( GT_32( lt_snr_org, 87241521 /* 2.6 Q25 */ ) ) { speech_flag = 3; move16(); } - ELSE IF(GT_32(lt_snr_org, 53687090/* 1.6 Q25 */)) + ELSE IF( GT_32( lt_snr_org, 53687090 /* 1.6 Q25 */ ) ) { speech_flag = 4; move16(); @@ -84,55 +83,55 @@ static Word16 comvad_hangover( speech_flag = 5; move16(); } - speech_flag = sub(speech_flag,1); + speech_flag = sub( speech_flag, 1 ); } - IF(LT_16(continuous_speech_num2, 120)) + IF( LT_16( continuous_speech_num2, 120 ) ) { test(); - IF(GT_32(snr, 50331647/* 1.5 Q25 */)) + IF( GT_32( snr, 50331647 /* 1.5 Q25 */ ) ) { speech_flag = 9; move16(); } - ELSE IF(GT_32(snr, 33554431/* 1.0 Q25 */)&<_16(speech_flag,7)) + ELSE IF( GT_32( snr, 33554431 /* 1.0 Q25 */ ) && LT_16( speech_flag, 7 ) ) { speech_flag = 7; move16(); } - ELSE IF(LT_16(speech_flag,3)) + ELSE IF( LT_16( speech_flag, 3 ) ) { speech_flag = 3; move16(); } - if(GT_16(speech_flag,3)) + if ( GT_16( speech_flag, 3 ) ) { - speech_flag =sub(speech_flag,2); + speech_flag = sub( speech_flag, 2 ); } } ELSE { - IF(GT_32(lt_snr_org, 120795952/* 3.6 Q25 */)) + IF( GT_32( lt_snr_org, 120795952 /* 3.6 Q25 */ ) ) { speech_flag = 1; move16(); } - ELSE IF(GT_32(lt_snr_org, 100663293/* 3.0 Q25 */)) + ELSE IF( GT_32( lt_snr_org, 100663293 /* 3.0 Q25 */ ) ) { speech_flag = 2; move16(); } - ELSE IF(GT_32(lt_snr_org, 83886078/* 2.5 Q25 */)) + ELSE IF( GT_32( lt_snr_org, 83886078 /* 2.5 Q25 */ ) ) { speech_flag = 3; move16(); } - ELSE IF(GT_32(lt_snr_org, 67108862/* 2.0 Q25 */)) + ELSE IF( GT_32( lt_snr_org, 67108862 /* 2.0 Q25 */ ) ) { speech_flag = 3; move16(); } - ELSE IF(GT_32(lt_snr_org, 50331647/* 1.5 Q25 */)) + ELSE IF( GT_32( lt_snr_org, 50331647 /* 1.5 Q25 */ ) ) { speech_flag = 4; move16(); @@ -144,18 +143,18 @@ static Word16 comvad_hangover( } } - if(EQ_16(noisy_type, SILENCE)) + if ( EQ_16( noisy_type, SILENCE ) ) { speech_flag = 6; move16(); } } } - ELSE IF(EQ_16(bw_index, CLDFBVAD_WB_ID)) + ELSE IF( EQ_16( bw_index, CLDFBVAD_WB_ID ) ) { - IF(vad_flag) + IF( vad_flag ) { - IF(GT_32(lt_snr_org, 117440509/* 3.5 Q25 */)) + IF( GT_32( lt_snr_org, 117440509 /* 3.5 Q25 */ ) ) { speech_flag = 1; move16(); @@ -168,23 +167,23 @@ static Word16 comvad_hangover( test(); test(); - IF((LT_16(continuous_speech_num2, 8))&&(LT_32(lt_snr_org,134217724/* 4.0 Q25 */))) + IF( ( LT_16( continuous_speech_num2, 8 ) ) && ( LT_32( lt_snr_org, 134217724 /* 4.0 Q25 */ ) ) ) { - speech_flag = sub(8, continuous_speech_num2); + speech_flag = sub( 8, continuous_speech_num2 ); } - ELSE IF((GT_32(snr_flux, 30198988/* 0.9 Q25 */))&&(GT_16(continuous_speech_num2,50))) + ELSE IF( ( GT_32( snr_flux, 30198988 /* 0.9 Q25 */ ) ) && ( GT_16( continuous_speech_num2, 50 ) ) ) { - IF(GT_32(lt_snr_org, 120795952/* 3.6 Q25 */)) + IF( GT_32( lt_snr_org, 120795952 /* 3.6 Q25 */ ) ) { speech_flag = 1; move16(); } - ELSE IF(GT_32(lt_snr_org, 87241521/* 2.6 Q25 */)) + ELSE IF( GT_32( lt_snr_org, 87241521 /* 2.6 Q25 */ ) ) { speech_flag = 5; move16(); } - ELSE IF(GT_32(lt_snr_org, 53687090/* 1.6 Q25 */)) + ELSE IF( GT_32( lt_snr_org, 53687090 /* 1.6 Q25 */ ) ) { speech_flag = 6; move16(); @@ -194,33 +193,33 @@ static Word16 comvad_hangover( speech_flag = 7; move16(); } - IF(GT_16(speech_flag , 1)) + IF( GT_16( speech_flag, 1 ) ) { - speech_flag = sub(speech_flag , 1); + speech_flag = sub( speech_flag, 1 ); } } - IF(LT_16(continuous_speech_num2, 120)) + IF( LT_16( continuous_speech_num2, 120 ) ) { test(); test(); test(); - IF(GT_32(snr, 50331647/* 1.5 Q25 */)) + IF( GT_32( snr, 50331647 /* 1.5 Q25 */ ) ) { speech_flag = 6; move16(); } - ELSE IF(GT_32(snr, 33554431/* 1.0 Q25 */)&<_16(speech_flag,5)) + ELSE IF( GT_32( snr, 33554431 /* 1.0 Q25 */ ) && LT_16( speech_flag, 5 ) ) { speech_flag = 5; move16(); } - ELSE IF(GT_32(snr, 26843545/* 0.8 Q25 */)&<_32(lt_snr_org,67108862/* 2.0 Q25 */)&<_16(speech_flag,4)) + ELSE IF( GT_32( snr, 26843545 /* 0.8 Q25 */ ) && LT_32( lt_snr_org, 67108862 /* 2.0 Q25 */ ) && LT_16( speech_flag, 4 ) ) { speech_flag = 4; move16(); } - ELSE IF(LT_16(speech_flag, 3)) + ELSE IF( LT_16( speech_flag, 3 ) ) { speech_flag = 3; move16(); @@ -228,33 +227,34 @@ static Word16 comvad_hangover( } ELSE { - IF(GT_32(lt_snr_org,120795952/* 3.6 Q25 */)) + IF( GT_32( lt_snr_org, 120795952 /* 3.6 Q25 */ ) ) { speech_flag = 1; move16(); } - ELSE IF(GT_32(lt_snr_org, 100663293/* 3.0 Q25 */)) + ELSE IF( GT_32( lt_snr_org, 100663293 /* 3.0 Q25 */ ) ) { speech_flag = 2; move16(); } - ELSE IF(GT_32(lt_snr_org, 83886078/* 2.5 Q25 */)) + ELSE IF( GT_32( lt_snr_org, 83886078 /* 2.5 Q25 */ ) ) { speech_flag = 2; move16(); } - ELSE IF(GT_32(lt_snr_org, 67108862/* 2.0 Q25 */)) + ELSE IF( GT_32( lt_snr_org, 67108862 /* 2.0 Q25 */ ) ) { speech_flag = 3; move16(); } - ELSE { + ELSE + { speech_flag = 3; move16(); } } - if(EQ_16(noisy_type, SILENCE)) + if ( EQ_16( noisy_type, SILENCE ) ) { speech_flag = 6; move16(); @@ -263,11 +263,11 @@ static Word16 comvad_hangover( } ELSE /* NB */ { - IF(vad_flag) + IF( vad_flag ) { - l_snr_add = L_add(0x0199999a,MUL_F(l_snr,0x0ccd)); + l_snr_add = L_add( 0x0199999a, MUL_F( l_snr, 0x0ccd ) ); - IF(GT_32(lt_snr_org, 117440509/* 3.5 Q25 */)) + IF( GT_32( lt_snr_org, 117440509 /* 3.5 Q25 */ ) ) { speech_flag = 3; move16(); @@ -280,23 +280,23 @@ static Word16 comvad_hangover( test(); test(); - IF((LT_16(continuous_speech_num2,8))&&(LT_32(lt_snr_org,134217724/* 4.0 Q25 */))) + IF( ( LT_16( continuous_speech_num2, 8 ) ) && ( LT_32( lt_snr_org, 134217724 /* 4.0 Q25 */ ) ) ) { - speech_flag = sub(8, continuous_speech_num2); + speech_flag = sub( 8, continuous_speech_num2 ); } - ELSE IF((GT_32(snr_flux, l_snr_add))&&(GT_16(continuous_speech_num2,24))) + ELSE IF( ( GT_32( snr_flux, l_snr_add ) ) && ( GT_16( continuous_speech_num2, 24 ) ) ) { - IF(GT_32(lt_snr_org, 120795952/* 3.6 Q25 */)) + IF( GT_32( lt_snr_org, 120795952 /* 3.6 Q25 */ ) ) { speech_flag = 3; move16(); } - ELSE IF(GT_32(lt_snr_org, 87241521/* 2.6 Q25 */)) + ELSE IF( GT_32( lt_snr_org, 87241521 /* 2.6 Q25 */ ) ) { speech_flag = 8; move16(); } - ELSE IF(GT_32(lt_snr_org, 40265317/* 1.2 Q25 */)) + ELSE IF( GT_32( lt_snr_org, 40265317 /* 1.2 Q25 */ ) ) { speech_flag = 10; move16(); @@ -307,27 +307,27 @@ static Word16 comvad_hangover( move16(); } - IF(GT_16(speech_flag ,2)) + IF( GT_16( speech_flag, 2 ) ) { - speech_flag = sub(speech_flag,2); + speech_flag = sub( speech_flag, 2 ); } } - IF(LT_16(continuous_speech_num2, 120)) + IF( LT_16( continuous_speech_num2, 120 ) ) { test(); test(); - IF(GT_32(snr, 50331647/* 1.5 Q25 */)) + IF( GT_32( snr, 50331647 /* 1.5 Q25 */ ) ) { speech_flag = 10; move16(); } - ELSE IF(GT_32(snr, 33554431/* 1.0 Q25 */)&<_16(speech_flag,7)) + ELSE IF( GT_32( snr, 33554431 /* 1.0 Q25 */ ) && LT_16( speech_flag, 7 ) ) { speech_flag = 7; move16(); } - ELSE IF(LT_16(speech_flag, 3)&>_16(continuous_speech_num2,12)) + ELSE IF( LT_16( speech_flag, 3 ) && GT_16( continuous_speech_num2, 12 ) ) { speech_flag = 3; move16(); @@ -335,27 +335,27 @@ static Word16 comvad_hangover( } ELSE { - IF(GT_32(lt_snr_org, 120795952/* 3.6 Q25 */)) + IF( GT_32( lt_snr_org, 120795952 /* 3.6 Q25 */ ) ) { speech_flag = 2; move16(); } - ELSE IF(GT_32(lt_snr_org, 100663293/* 3.0 Q25 */)) + ELSE IF( GT_32( lt_snr_org, 100663293 /* 3.0 Q25 */ ) ) { speech_flag = 2; move16(); } - ELSE IF(GT_32(lt_snr_org, 83886078/* 2.5 Q25 */)) + ELSE IF( GT_32( lt_snr_org, 83886078 /* 2.5 Q25 */ ) ) { speech_flag = 3; move16(); } - ELSE IF(GT_32(lt_snr_org, 67108862/* 2.0 Q25 */)) + ELSE IF( GT_32( lt_snr_org, 67108862 /* 2.0 Q25 */ ) ) { speech_flag = 3; move16(); } - ELSE IF(GT_32(lt_snr_org, 50331647/* 1.5 Q25 */)) + ELSE IF( GT_32( lt_snr_org, 50331647 /* 1.5 Q25 */ ) ) { speech_flag = 4; move16(); @@ -367,7 +367,7 @@ static Word16 comvad_hangover( } } - if(EQ_16(noisy_type, SILENCE)) + if ( EQ_16( noisy_type, SILENCE ) ) { speech_flag = 2; move16(); @@ -376,17 +376,17 @@ static Word16 comvad_hangover( } - IF((EQ_16(vad_flag,1))) + IF( ( EQ_16( vad_flag, 1 ) ) ) { - IF((NE_16(noisy_type, SILENCE))) + IF( ( NE_16( noisy_type, SILENCE ) ) ) { speech_flag--; } ELSE { - speech_flag = sub(speech_flag, 3); + speech_flag = sub( speech_flag, 3 ); } - speech_flag = s_max(speech_flag, 0); + speech_flag = s_max( speech_flag, 0 ); } @@ -394,21 +394,19 @@ static Word16 comvad_hangover( } - Word16 comvad_decision_fx( VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ - const Word32 l_snr, /* i : long time frequency domain*/ - const Word32 lt_snr_org, /* i : original long time SNR*/ - const Word32 lt_snr, /* i : long time SNR calculated by fg_energy and bg_energy*/ - const Word32 snr_flux, /* i : average tsnr of several frames*/ - const Word32 snr, /* i : frequency domain SNR */ - Word32 tsnr, /* i : time domain SNR */ - const Word32 frame_energy, /* i : current frame energy */ - const Word16 music_backgound_f, /* i : background music flag*/ - const Word16 frame_energy_Q, /* i : the Scaling of current frame energy*/ - Word16 *cldfb_addition, /* o : adjust the harmonized hangover */ - const Word16 vada_flag -) + const Word32 l_snr, /* i : long time frequency domain*/ + const Word32 lt_snr_org, /* i : original long time SNR*/ + const Word32 lt_snr, /* i : long time SNR calculated by fg_energy and bg_energy*/ + const Word32 snr_flux, /* i : average tsnr of several frames*/ + const Word32 snr, /* i : frequency domain SNR */ + Word32 tsnr, /* i : time domain SNR */ + const Word32 frame_energy, /* i : current frame energy */ + const Word16 music_backgound_f, /* i : background music flag*/ + const Word16 frame_energy_Q, /* i : the Scaling of current frame energy*/ + Word16 *cldfb_addition, /* o : adjust the harmonized hangover */ + const Word16 vada_flag ) { Word16 speech_flag; Word32 fg_energy; @@ -422,23 +420,22 @@ Word16 comvad_decision_fx( Word32 l_silence_snr; Word16 snr_div_fix; - Word16 Qnorm_silence,Qnorm_silence_count; + Word16 Qnorm_silence, Qnorm_silence_count; Word16 tmpout; Word16 noisy_type; Word32 lt_snr_org_cmp; - /* avoid overflows in the following if conditions */ - tsnr = L_shr(tsnr,1); + tsnr = L_shr( tsnr, 1 ); noisy_type = UNKNOWN_NOISE; move16(); - speech_flag = hVAD_CLDFB ->speech_flag; + speech_flag = hVAD_CLDFB->speech_flag; move16(); - fg_energy = hVAD_CLDFB ->fg_energy; + fg_energy = hVAD_CLDFB->fg_energy; move32(); - bg_energy = hVAD_CLDFB ->bg_energy; + bg_energy = hVAD_CLDFB->bg_energy; move32(); Qnorm_silence = 0; @@ -447,123 +444,123 @@ Word16 comvad_decision_fx( move16(); test(); - IF(GT_32(hVAD_CLDFB ->lf_snr_smooth, LS_MIN_SILENCE_SNR[hVAD_CLDFB ->bw_index - CLDFBVAD_NB_ID] )&>_32(lt_snr_org,LT_MIN_SILENCE_SNR_FX[hVAD_CLDFB ->bw_index-CLDFBVAD_NB_ID])) + IF( GT_32( hVAD_CLDFB->lf_snr_smooth, LS_MIN_SILENCE_SNR[hVAD_CLDFB->bw_index - CLDFBVAD_NB_ID] ) && GT_32( lt_snr_org, LT_MIN_SILENCE_SNR_FX[hVAD_CLDFB->bw_index - CLDFBVAD_NB_ID] ) ) { noisy_type = SILENCE; move16(); } - tmp_snr = construct_snr_thresh_fx( hVAD_CLDFB ->sp_center, snr_flux, lt_snr, l_snr, hVAD_CLDFB ->continuous_speech_num, - hVAD_CLDFB ->continuous_noise_num, hVAD_CLDFB ->fg_energy_est_start, hVAD_CLDFB ->bw_index); + tmp_snr = construct_snr_thresh_fx( hVAD_CLDFB->sp_center, snr_flux, lt_snr, l_snr, hVAD_CLDFB->continuous_speech_num, + hVAD_CLDFB->continuous_noise_num, hVAD_CLDFB->fg_energy_est_start, hVAD_CLDFB->bw_index ); + - vad_flag = 0; move16(); - if(GT_32(snr, tmp_snr)) + if ( GT_32( snr, tmp_snr ) ) { vad_flag = 1; move16(); } - if(GT_32(tsnr, 67108862/* 4.0/2.0 Q25 */)) + if ( GT_32( tsnr, 67108862 /* 4.0/2.0 Q25 */ ) ) { vad_flag = 1; move16(); } - - IF(GT_16(hVAD_CLDFB ->frameloop, 25)) + + IF( GT_16( hVAD_CLDFB->frameloop, 25 ) ) { test(); - IF(EQ_16(vad_flag, 1)&&EQ_32(hVAD_CLDFB ->fg_energy_est_start,1)) + IF( EQ_16( vad_flag, 1 ) && EQ_32( hVAD_CLDFB->fg_energy_est_start, 1 ) ) { - Word32 frame_energy_mult_fix32,bg_energy_mult_fix32; - Word16 frame_energy_mult_Q,bg_energy_mult_Q; + Word32 frame_energy_mult_fix32, bg_energy_mult_fix32; + Word16 frame_energy_mult_Q, bg_energy_mult_Q; - IF(EQ_16(hVAD_CLDFB ->fg_energy_count, 512)) + IF( EQ_16( hVAD_CLDFB->fg_energy_count, 512 ) ) { - fg_energy = MUL_F(fg_energy, 0x6000); - hVAD_CLDFB ->fg_energy_count = 384; + fg_energy = MUL_F( fg_energy, 0x6000 ); + hVAD_CLDFB->fg_energy_count = 384; move16(); } - frame_energy_mult_fix32 = MUL_F(frame_energy, hVAD_CLDFB ->bg_energy_count); - frame_energy_mult_Q = sub(frame_energy_Q, 15); + frame_energy_mult_fix32 = MUL_F( frame_energy, hVAD_CLDFB->bg_energy_count ); + frame_energy_mult_Q = sub( frame_energy_Q, 15 ); - bg_energy_mult_fix32 = MUL_F(bg_energy, 6); - bg_energy_mult_Q = sub(hVAD_CLDFB ->bg_energy_scale, 15); + bg_energy_mult_fix32 = MUL_F( bg_energy, 6 ); + bg_energy_mult_Q = sub( hVAD_CLDFB->bg_energy_scale, 15 ); - IF(GT_16(frame_energy_mult_Q, bg_energy_mult_Q)) + IF( GT_16( frame_energy_mult_Q, bg_energy_mult_Q ) ) { - frame_energy_mult_fix32 = L_shr(frame_energy_mult_fix32,sub(frame_energy_mult_Q, bg_energy_mult_Q)); + frame_energy_mult_fix32 = L_shr( frame_energy_mult_fix32, sub( frame_energy_mult_Q, bg_energy_mult_Q ) ); } - IF(LT_16(frame_energy_mult_Q, bg_energy_mult_Q)) + IF( LT_16( frame_energy_mult_Q, bg_energy_mult_Q ) ) { - bg_energy_mult_fix32 = L_shr(bg_energy_mult_fix32,limitScale32(sub(bg_energy_mult_Q, frame_energy_mult_Q))); + bg_energy_mult_fix32 = L_shr( bg_energy_mult_fix32, limitScale32( sub( bg_energy_mult_Q, frame_energy_mult_Q ) ) ); } - IF(GT_32(frame_energy_mult_fix32, bg_energy_mult_fix32)) + IF( GT_32( frame_energy_mult_fix32, bg_energy_mult_fix32 ) ) { - fg_energy = VAD_L_ADD(fg_energy, hVAD_CLDFB ->fg_energy_scale, frame_energy, frame_energy_Q, &hVAD_CLDFB ->fg_energy_scale); - hVAD_CLDFB ->fg_energy_count = add(hVAD_CLDFB ->fg_energy_count, 1); + fg_energy = VAD_L_ADD( fg_energy, hVAD_CLDFB->fg_energy_scale, frame_energy, frame_energy_Q, &hVAD_CLDFB->fg_energy_scale ); + hVAD_CLDFB->fg_energy_count = add( hVAD_CLDFB->fg_energy_count, 1 ); move16(); } } } - if(music_backgound_f) + if ( music_backgound_f ) { vad_flag = 1; move16(); } - IF(EQ_16(vad_flag, 1)) + IF( EQ_16( vad_flag, 1 ) ) { - IF (hVAD_CLDFB ->l_silence_snr == 0) + IF( hVAD_CLDFB->l_silence_snr == 0 ) { snr_div_fix = 0; move16(); } ELSE { - Qnorm_silence=sub(norm_l(hVAD_CLDFB ->l_silence_snr), 1); - Qnorm_silence_count=norm_l(hVAD_CLDFB ->l_silence_snr_count); - l_silence_snr = L_shl(hVAD_CLDFB ->l_silence_snr,Qnorm_silence); - l_silence_snr_count = L_shl(hVAD_CLDFB ->l_silence_snr_count,Qnorm_silence_count); - snr_div_fix = div_l(l_silence_snr,extract_h(l_silence_snr_count)); + Qnorm_silence = sub( norm_l( hVAD_CLDFB->l_silence_snr ), 1 ); + Qnorm_silence_count = norm_l( hVAD_CLDFB->l_silence_snr_count ); + l_silence_snr = L_shl( hVAD_CLDFB->l_silence_snr, Qnorm_silence ); + l_silence_snr_count = L_shl( hVAD_CLDFB->l_silence_snr_count, Qnorm_silence_count ); + snr_div_fix = div_l( l_silence_snr, extract_h( l_silence_snr_count ) ); } - snr_sub = L_sub(snr, 0x3000000); - snr_div_fix32 = L_deposit_l(snr_div_fix); - snr_div_fix32 = L_shr(snr_div_fix32, add(6, sub(Qnorm_silence, Qnorm_silence_count))); + snr_sub = L_sub( snr, 0x3000000 ); + snr_div_fix32 = L_deposit_l( snr_div_fix ); + snr_div_fix32 = L_shr( snr_div_fix32, add( 6, sub( Qnorm_silence, Qnorm_silence_count ) ) ); - IF(GT_32(snr_sub, snr_div_fix32)) + IF( GT_32( snr_sub, snr_div_fix32 ) ) { - IF(EQ_32(hVAD_CLDFB ->l_speech_snr_count, 512)) + IF( EQ_32( hVAD_CLDFB->l_speech_snr_count, 512 ) ) { - hVAD_CLDFB ->l_speech_snr = L_add(MUL_F(hVAD_CLDFB ->l_speech_snr, 0x6000), L_shr(snr, 9)); + hVAD_CLDFB->l_speech_snr = L_add( MUL_F( hVAD_CLDFB->l_speech_snr, 0x6000 ), L_shr( snr, 9 ) ); move32(); - hVAD_CLDFB ->l_speech_snr_count = L_deposit_l(384+1); + hVAD_CLDFB->l_speech_snr_count = L_deposit_l( 384 + 1 ); move32(); } ELSE { - hVAD_CLDFB ->l_speech_snr = L_add(hVAD_CLDFB ->l_speech_snr, L_shr(snr, 9)); + hVAD_CLDFB->l_speech_snr = L_add( hVAD_CLDFB->l_speech_snr, L_shr( snr, 9 ) ); move32(); - hVAD_CLDFB ->l_speech_snr_count = L_add(hVAD_CLDFB ->l_speech_snr_count, 1); + hVAD_CLDFB->l_speech_snr_count = L_add( hVAD_CLDFB->l_speech_snr_count, 1 ); move32(); } } } - lt_snr_org_cmp = L_sub(lt_snr_org, 117440509/* 3.5 Q25 */); + lt_snr_org_cmp = L_sub( lt_snr_org, 117440509 /* 3.5 Q25 */ ); - IF(EQ_16(hVAD_CLDFB ->bw_index, CLDFBVAD_NB_ID)) + IF( EQ_16( hVAD_CLDFB->bw_index, CLDFBVAD_NB_ID ) ) { Word32 lt_snr_add; - lt_snr_add = L_add(0x03cccccd, MUL_F(lt_snr, 0x23d7)); + lt_snr_add = L_add( 0x03cccccd, MUL_F( lt_snr, 0x23d7 ) ); - if(GT_32(snr_flux, lt_snr_add)) + if ( GT_32( snr_flux, lt_snr_add ) ) { vad_flag = 1; move16(); @@ -571,7 +568,7 @@ Word16 comvad_decision_fx( test(); test(); - if( (GT_32(snr_flux, 50331647/* 1.5 Q25 */))&&(GT_16(hVAD_CLDFB ->sp_center[3],1637/* 1.6 Q10 */))&&(lt_snr_org_cmp<0)) + if ( ( GT_32( snr_flux, 50331647 /* 1.5 Q25 */ ) ) && ( GT_16( hVAD_CLDFB->sp_center[3], 1637 /* 1.6 Q10 */ ) ) && ( lt_snr_org_cmp < 0 ) ) { vad_flag = 1; move16(); @@ -579,7 +576,7 @@ Word16 comvad_decision_fx( test(); test(); - if( (GT_32(snr_flux, 40265317/* 1.2 Q25 */))&&(GT_16(hVAD_CLDFB ->sp_center[3],1944/* 1.9 Q10 */))&&(lt_snr_org_cmp<0)) + if ( ( GT_32( snr_flux, 40265317 /* 1.2 Q25 */ ) ) && ( GT_16( hVAD_CLDFB->sp_center[3], 1944 /* 1.9 Q10 */ ) ) && ( lt_snr_org_cmp < 0 ) ) { vad_flag = 1; move16(); @@ -587,19 +584,19 @@ Word16 comvad_decision_fx( test(); test(); - if((GT_32(snr_flux, 33554431/* 1.0 Q25 */))&&(GT_16(hVAD_CLDFB ->sp_center[3],3274/* 3.2 Q10 */))&&(lt_snr_org_cmp<0)) + if ( ( GT_32( snr_flux, 33554431 /* 1.0 Q25 */ ) ) && ( GT_16( hVAD_CLDFB->sp_center[3], 3274 /* 3.2 Q10 */ ) ) && ( lt_snr_org_cmp < 0 ) ) { vad_flag = 1; move16(); } } - ELSE IF(EQ_16(hVAD_CLDFB ->bw_index, CLDFBVAD_WB_ID)) + ELSE IF( EQ_16( hVAD_CLDFB->bw_index, CLDFBVAD_WB_ID ) ) { Word32 lt_snr_add; - lt_snr_add = L_add(0x04333333, MUL_F(lt_snr, 0x1eb8)); + lt_snr_add = L_add( 0x04333333, MUL_F( lt_snr, 0x1eb8 ) ); - if(GT_32(snr_flux, lt_snr_add)) + if ( GT_32( snr_flux, lt_snr_add ) ) { vad_flag = 1; move16(); @@ -607,7 +604,7 @@ Word16 comvad_decision_fx( test(); test(); - if((GT_32(snr_flux, 53687090/* 1.6 Q25 */))&&(GT_16(hVAD_CLDFB ->sp_center[3],2558/* 2.5 Q10 */))&&(lt_snr_org_cmp<0)) + if ( ( GT_32( snr_flux, 53687090 /* 1.6 Q25 */ ) ) && ( GT_16( hVAD_CLDFB->sp_center[3], 2558 /* 2.5 Q10 */ ) ) && ( lt_snr_org_cmp < 0 ) ) { vad_flag = 1; move16(); @@ -615,7 +612,7 @@ Word16 comvad_decision_fx( test(); test(); - if((GT_32(snr_flux, 40265317/* 1.2 Q25 */))&&(GT_16(hVAD_CLDFB ->sp_center[3],2864/* 2.8 Q10 */))&&(lt_snr_org_cmp<0)) + if ( ( GT_32( snr_flux, 40265317 /* 1.2 Q25 */ ) ) && ( GT_16( hVAD_CLDFB->sp_center[3], 2864 /* 2.8 Q10 */ ) ) && ( lt_snr_org_cmp < 0 ) ) { vad_flag = 1; move16(); @@ -623,7 +620,7 @@ Word16 comvad_decision_fx( test(); test(); - if((GT_32(snr_flux, 33554431/* 1.0 Q25 */))&&(GT_16(hVAD_CLDFB ->sp_center[3],4604/* 4.5 Q10 */))&&(lt_snr_org_cmp<0)) + if ( ( GT_32( snr_flux, 33554431 /* 1.0 Q25 */ ) ) && ( GT_16( hVAD_CLDFB->sp_center[3], 4604 /* 4.5 Q10 */ ) ) && ( lt_snr_org_cmp < 0 ) ) { vad_flag = 1; move16(); @@ -633,9 +630,9 @@ Word16 comvad_decision_fx( { Word32 lt_snr_add; - lt_snr_add = L_add(0x04333333, MUL_F(lt_snr, 0x28f5)); + lt_snr_add = L_add( 0x04333333, MUL_F( lt_snr, 0x28f5 ) ); - if((GT_32(snr_flux, lt_snr_add))) + if ( ( GT_32( snr_flux, lt_snr_add ) ) ) { vad_flag = 1; move16(); @@ -643,7 +640,7 @@ Word16 comvad_decision_fx( test(); test(); - if((GT_32(snr_flux, 56371444/* 1.68 Q25 */))&&(GT_16(hVAD_CLDFB ->sp_center[3],2823/* 2.76 Q10 */))&&(lt_snr_org_cmp<0)) + if ( ( GT_32( snr_flux, 56371444 /* 1.68 Q25 */ ) ) && ( GT_16( hVAD_CLDFB->sp_center[3], 2823 /* 2.76 Q10 */ ) ) && ( lt_snr_org_cmp < 0 ) ) { vad_flag = 1; move16(); @@ -651,7 +648,7 @@ Word16 comvad_decision_fx( test(); test(); - if((GT_32(snr_flux, 41607494/* 1.24 Q25 */))&&(GT_16(hVAD_CLDFB ->sp_center[3],2987/* 2.92 Q10 */))&&(lt_snr_org_cmp<0)) + if ( ( GT_32( snr_flux, 41607494 /* 1.24 Q25 */ ) ) && ( GT_16( hVAD_CLDFB->sp_center[3], 2987 /* 2.92 Q10 */ ) ) && ( lt_snr_org_cmp < 0 ) ) { vad_flag = 1; move16(); @@ -659,7 +656,7 @@ Word16 comvad_decision_fx( test(); test(); - if((GT_32(snr_flux, 36909874/* 1.10 Q25 */))&&(GT_16(hVAD_CLDFB ->sp_center[3],4706/* 4.6 Q10 */))&&(lt_snr_org_cmp<0)) + if ( ( GT_32( snr_flux, 36909874 /* 1.10 Q25 */ ) ) && ( GT_16( hVAD_CLDFB->sp_center[3], 4706 /* 4.6 Q10 */ ) ) && ( lt_snr_org_cmp < 0 ) ) { vad_flag = 1; move16(); @@ -667,107 +664,94 @@ Word16 comvad_decision_fx( } - IF(hVAD_CLDFB ->fg_energy_est_start==0) + IF( hVAD_CLDFB->fg_energy_est_start == 0 ) { - tmpout = VAD_L_CMP(frame_energy, frame_energy_Q, 50, 0); + tmpout = VAD_L_CMP( frame_energy, frame_energy_Q, 50, 0 ); test(); test(); - if(GT_16(hVAD_CLDFB ->ltd_stable_rate[0], 2621/* 0.08 Q15 */)&&EQ_16(vad_flag,1)&&(tmpout>0)) + if ( GT_16( hVAD_CLDFB->ltd_stable_rate[0], 2621 /* 0.08 Q15 */ ) && EQ_16( vad_flag, 1 ) && ( tmpout > 0 ) ) { - hVAD_CLDFB ->fg_energy_est_start = L_deposit_l(1); + hVAD_CLDFB->fg_energy_est_start = L_deposit_l( 1 ); } } - speech_flag = comvad_hangover( lt_snr_org, - snr, - l_snr, - snr_flux, - hVAD_CLDFB ->bw_index, - vad_flag, - speech_flag, - hVAD_CLDFB ->continuous_speech_num2, - noisy_type); - + speech_flag = comvad_hangover( lt_snr_org, + snr, + l_snr, + snr_flux, + hVAD_CLDFB->bw_index, + vad_flag, + speech_flag, + hVAD_CLDFB->continuous_speech_num2, + noisy_type ); test(); - IF(vad_flag == 0 && speech_flag > 0) + IF( vad_flag == 0 && speech_flag > 0 ) { - speech_flag = sub(speech_flag, 1); + speech_flag = sub( speech_flag, 1 ); vad_flag = 1; move16(); } vadb_flag = vad_flag; - IF(EQ_16(hVAD_CLDFB ->bw_index, CLDFBVAD_SWB_ID)) + IF( EQ_16( hVAD_CLDFB->bw_index, CLDFBVAD_SWB_ID ) ) { test(); test(); test(); - IF(EQ_16(SILENCE, noisy_type) - && GT_32(snr, 6710886/* 0.2 Q25 */) - && vad_flag == 0) + IF( EQ_16( SILENCE, noisy_type ) && GT_32( snr, 6710886 /* 0.2 Q25 */ ) && vad_flag == 0 ) { vad_flag = vada_flag; move16(); } - ELSE IF(LT_32(hVAD_CLDFB ->lf_snr_smooth,352321526/* 10.5 Q25 */)||NE_16(SILENCE,noisy_type)) + ELSE IF( LT_32( hVAD_CLDFB->lf_snr_smooth, 352321526 /* 10.5 Q25 */ ) || NE_16( SILENCE, noisy_type ) ) { test(); test(); test(); - IF(GT_32(snr_flux, 83886078/* 2.5 Q25 */) - || ( hVAD_CLDFB ->continuous_speech_num2 > 40 && GT_32(snr_flux, 67108862/* 2.0 Q25 */) ) - || music_backgound_f == 1) + IF( GT_32( snr_flux, 83886078 /* 2.5 Q25 */ ) || ( hVAD_CLDFB->continuous_speech_num2 > 40 && GT_32( snr_flux, 67108862 /* 2.0 Q25 */ ) ) || music_backgound_f == 1 ) { - vad_flag = s_or(vad_flag, vada_flag); + vad_flag = s_or( vad_flag, vada_flag ); } - ELSE IF(EQ_16(SILENCE, noisy_type)) + ELSE IF( EQ_16( SILENCE, noisy_type ) ) { vad_flag = vada_flag; } } - } - ELSE IF(EQ_16(hVAD_CLDFB ->bw_index, CLDFBVAD_WB_ID)) + ELSE IF( EQ_16( hVAD_CLDFB->bw_index, CLDFBVAD_WB_ID ) ) { test(); test(); test(); - IF(EQ_16(SILENCE, noisy_type) - && GT_32(snr, 6710886/* 0.2 Q25 */) - && vad_flag == 0) + IF( EQ_16( SILENCE, noisy_type ) && GT_32( snr, 6710886 /* 0.2 Q25 */ ) && vad_flag == 0 ) { vad_flag = vada_flag; move16(); } - ELSE IF(LT_32(hVAD_CLDFB ->lf_snr_smooth,352321526/* 10.5 Q25 */)||NE_16(SILENCE,noisy_type)) + ELSE IF( LT_32( hVAD_CLDFB->lf_snr_smooth, 352321526 /* 10.5 Q25 */ ) || NE_16( SILENCE, noisy_type ) ) { test(); test(); test(); - IF(GT_32(snr_flux, 73819748/* 2.2 Q25 */) - || (hVAD_CLDFB ->continuous_speech_num2 > 40 && GT_32(snr_flux, 57042532/* 1.7 Q25 */) ) - || music_backgound_f == 1) + IF( GT_32( snr_flux, 73819748 /* 2.2 Q25 */ ) || ( hVAD_CLDFB->continuous_speech_num2 > 40 && GT_32( snr_flux, 57042532 /* 1.7 Q25 */ ) ) || music_backgound_f == 1 ) { - vad_flag = s_or(vad_flag, vada_flag); + vad_flag = s_or( vad_flag, vada_flag ); } - ELSE IF(EQ_16(SILENCE, noisy_type)) + ELSE IF( EQ_16( SILENCE, noisy_type ) ) { vad_flag = vada_flag; } - } - } ELSE { - IF(EQ_16(SILENCE, noisy_type)) + IF( EQ_16( SILENCE, noisy_type ) ) { test(); - IF(GT_32(hVAD_CLDFB ->lf_snr_smooth , 419430388/* 12.5 Q25 */) - && music_backgound_f == 0) + IF( GT_32( hVAD_CLDFB->lf_snr_smooth, 419430388 /* 12.5 Q25 */ ) && music_backgound_f == 0 ) { vad_flag = vada_flag; } @@ -777,81 +761,76 @@ Word16 comvad_decision_fx( test(); test(); test(); - IF(GT_32(snr_flux, 67108862/* 2.0 Q25 */) - || (hVAD_CLDFB ->continuous_speech_num2 > 30 && GT_32(snr_flux, 50331647/* 1.5 Q25 */) ) - || music_backgound_f == 1) + IF( GT_32( snr_flux, 67108862 /* 2.0 Q25 */ ) || ( hVAD_CLDFB->continuous_speech_num2 > 30 && GT_32( snr_flux, 50331647 /* 1.5 Q25 */ ) ) || music_backgound_f == 1 ) { - vad_flag = s_or(vad_flag, vada_flag); + vad_flag = s_or( vad_flag, vada_flag ); } } } - IF(vad_flag == 0) + IF( vad_flag == 0 ) { - IF(EQ_32(hVAD_CLDFB ->l_silence_snr_count, 512)) + IF( EQ_32( hVAD_CLDFB->l_silence_snr_count, 512 ) ) { - hVAD_CLDFB ->l_silence_snr = L_add(MUL_F(hVAD_CLDFB ->l_silence_snr, 0x6000),L_shr(snr, 9)); + hVAD_CLDFB->l_silence_snr = L_add( MUL_F( hVAD_CLDFB->l_silence_snr, 0x6000 ), L_shr( snr, 9 ) ); move32(); - hVAD_CLDFB ->l_silence_snr_count = L_deposit_l(384+1); + hVAD_CLDFB->l_silence_snr_count = L_deposit_l( 384 + 1 ); move32(); } - ELSE IF(LT_32(snr, 26843545/* 0.8 Q25 */)) + ELSE IF( LT_32( snr, 26843545 /* 0.8 Q25 */ ) ) { - hVAD_CLDFB ->l_silence_snr = L_add(hVAD_CLDFB ->l_silence_snr, L_shr(snr,9)); + hVAD_CLDFB->l_silence_snr = L_add( hVAD_CLDFB->l_silence_snr, L_shr( snr, 9 ) ); move32(); - hVAD_CLDFB ->l_silence_snr_count = L_add(hVAD_CLDFB ->l_silence_snr_count, 1); + hVAD_CLDFB->l_silence_snr_count = L_add( hVAD_CLDFB->l_silence_snr_count, 1 ); move32(); } } - IF(vad_flag == 0) + IF( vad_flag == 0 ) { - IF(EQ_16(hVAD_CLDFB ->bg_energy_count, 512)) + IF( EQ_16( hVAD_CLDFB->bg_energy_count, 512 ) ) { - bg_energy = MUL_F(bg_energy, 0x6000); - hVAD_CLDFB ->bg_energy_count = 384; + bg_energy = MUL_F( bg_energy, 0x6000 ); + hVAD_CLDFB->bg_energy_count = 384; move16(); } - IF(LT_32(tsnr, 16777216/* 1.0/2.0 Q25 */)) + IF( LT_32( tsnr, 16777216 /* 1.0/2.0 Q25 */ ) ) { - bg_energy = VAD_L_ADD(bg_energy, hVAD_CLDFB ->bg_energy_scale, frame_energy, frame_energy_Q, &hVAD_CLDFB ->bg_energy_scale); - hVAD_CLDFB ->bg_energy_count = add(hVAD_CLDFB ->bg_energy_count, 1); + bg_energy = VAD_L_ADD( bg_energy, hVAD_CLDFB->bg_energy_scale, frame_energy, frame_energy_Q, &hVAD_CLDFB->bg_energy_scale ); + hVAD_CLDFB->bg_energy_count = add( hVAD_CLDFB->bg_energy_count, 1 ); move16(); } } test(); - hVAD_CLDFB ->vad_flag_for_bk_update = vad_flag; - IF(LT_16(hVAD_CLDFB ->update_count, 12)&&EQ_16(vadb_flag,1)) + hVAD_CLDFB->vad_flag_for_bk_update = vad_flag; + IF( LT_16( hVAD_CLDFB->update_count, 12 ) && EQ_16( vadb_flag, 1 ) ) { - hVAD_CLDFB ->warm_hang_num = s_max(20, speech_flag); + hVAD_CLDFB->warm_hang_num = s_max( 20, speech_flag ); } test(); - IF(vad_flag == 0 && hVAD_CLDFB ->warm_hang_num > 0) + IF( vad_flag == 0 && hVAD_CLDFB->warm_hang_num > 0 ) { - hVAD_CLDFB ->warm_hang_num = sub(hVAD_CLDFB ->warm_hang_num, 1); + hVAD_CLDFB->warm_hang_num = sub( hVAD_CLDFB->warm_hang_num, 1 ); vad_flag = 1; move16(); } - - - hVAD_CLDFB ->lt_snr_org = lt_snr_org; + hVAD_CLDFB->lt_snr_org = lt_snr_org; move32(); - hVAD_CLDFB ->fg_energy = fg_energy; + hVAD_CLDFB->fg_energy = fg_energy; move32(); - hVAD_CLDFB ->bg_energy = bg_energy; + hVAD_CLDFB->bg_energy = bg_energy; move32(); - hVAD_CLDFB ->speech_flag = speech_flag; + hVAD_CLDFB->speech_flag = speech_flag; move16(); move16(); test(); - IF(EQ_16(noisy_type, SILENCE) - && NE_16(hVAD_CLDFB ->bw_index, CLDFBVAD_NB_ID)) + IF( EQ_16( noisy_type, SILENCE ) && NE_16( hVAD_CLDFB->bw_index, CLDFBVAD_NB_ID ) ) { *cldfb_addition = 2; } @@ -859,27 +838,23 @@ Word16 comvad_decision_fx( { *cldfb_addition = 0; - if(EQ_16(hVAD_CLDFB ->bw_index, CLDFBVAD_WB_ID)) + if ( EQ_16( hVAD_CLDFB->bw_index, CLDFBVAD_WB_ID ) ) { *cldfb_addition = 3; move16(); } - if(EQ_16(hVAD_CLDFB ->bw_index, CLDFBVAD_SWB_ID)) + if ( EQ_16( hVAD_CLDFB->bw_index, CLDFBVAD_SWB_ID ) ) { *cldfb_addition = 1; move16(); } - if(EQ_16(hVAD_CLDFB ->bw_index, CLDFBVAD_NB_ID)) + if ( EQ_16( hVAD_CLDFB->bw_index, CLDFBVAD_NB_ID ) ) { *cldfb_addition = 1; move16(); } - } - - return vad_flag; } - diff --git a/lib_enc/cor_shif_fx.c b/lib_enc/cor_shif_fx.c index 7f2315512..6645155ef 100644 --- a/lib_enc/cor_shif_fx.c +++ b/lib_enc/cor_shif_fx.c @@ -2,12 +2,12 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include "options.h" /* Compilation switches */ +#include "options.h" /* Compilation switches */ #include "cnst.h" /* Common constants */ //#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* @@ -19,38 +19,38 @@ * it can be assumed about 0 *-------------------------------------------------------------------*/ -Word16 correlation_shift_fx( /* o : noise dependent voicing correction Q15 */ - const Word16 totalNoise_fx /* i/o: noise estimate over all critical bands Q8 */ +Word16 correlation_shift_fx( /* o : noise dependent voicing correction Q15 */ + const Word16 totalNoise_fx /* i/o: noise estimate over all critical bands Q8 */ ) { - Word16 corr_shift_fx, e_Noise, f_Noise, wtmp; + Word16 corr_shift_fx, e_Noise, f_Noise, wtmp; Word32 Ltmp; corr_shift_fx = 0; move16(); - IF (GT_16(totalNoise_fx, 7215)) /* to make corr_shift > 0.0 */ + IF( GT_16( totalNoise_fx, 7215 ) ) /* to make corr_shift > 0.0 */ { /*------------------------------------------------------------* * useful values range from 0 to 1 (can saturate at 1.0) Q31 value * corr_shift = 2.4492E-4 * exp(0.1596 * totalNoise) - 0.022 * Result in Q14 *------------------------------------------------------------*/ - Ltmp = L_mult(totalNoise_fx, 7545); /* Q24 */ - Ltmp = L_shr(Ltmp, 8); /* Q24 -> Q16 */ - f_Noise = L_Extract_lc(Ltmp, &e_Noise); - wtmp = extract_l(Pow2(14, f_Noise)); /* Put 14 as exponent */ + Ltmp = L_mult( totalNoise_fx, 7545 ); /* Q24 */ + Ltmp = L_shr( Ltmp, 8 ); /* Q24 -> Q16 */ + f_Noise = L_Extract_lc( Ltmp, &e_Noise ); + wtmp = extract_l( Pow2( 14, f_Noise ) ); /* Put 14 as exponent */ - e_Noise = sub(e_Noise, 14); /* Retreive exponent of wtmp */ - Ltmp = Mpy_32_16(8, 837, wtmp); /* 2.4492e-4(Q31) * exp(0.1596*totalNoise) */ + e_Noise = sub( e_Noise, 14 ); /* Retreive exponent of wtmp */ + Ltmp = Mpy_32_16( 8, 837, wtmp ); /* 2.4492e-4(Q31) * exp(0.1596*totalNoise) */ #ifdef BASOP_NOGLOB - Ltmp = L_shl_sat(Ltmp,add(e_Noise, 15)); /* Result in Q31 */ + Ltmp = L_shl_sat( Ltmp, add( e_Noise, 15 ) ); /* Result in Q31 */ #else - Ltmp = L_shl(Ltmp,add(e_Noise, 15)); /* Result in Q31 */ + Ltmp = L_shl( Ltmp, add( e_Noise, 15 ) ); /* Result in Q31 */ #endif - corr_shift_fx = round_fx(L_sub(Ltmp, 47244640)); /* Represents corr_shift in Q15 */ + corr_shift_fx = round_fx( L_sub( Ltmp, 47244640 ) ); /* Represents corr_shift in Q15 */ } - corr_shift_fx = s_min(corr_shift_fx,16384); /* limit to 0.5 */ + corr_shift_fx = s_min( corr_shift_fx, 16384 ); /* limit to 0.5 */ return corr_shift_fx; } diff --git a/lib_enc/core_enc_2div_fx.c b/lib_enc/core_enc_2div_fx.c index a458ba3d6..37df43e37 100644 --- a/lib_enc/core_enc_2div_fx.c +++ b/lib_enc/core_enc_2div_fx.c @@ -6,39 +6,38 @@ #include #include #include "options.h" -#include "cnst.h" /* Common constants */ -#include "ivas_cnst.h" /* Common constants */ +#include "cnst.h" /* Common constants */ +#include "ivas_cnst.h" /* Common constants */ //#include "prot_fx.h" #include "basop_util.h" #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ -#include "basop_util.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ +#include "basop_util.h" /* Function prototypes */ - /*-------------------------------------------------------------------* +/*-------------------------------------------------------------------* * core_encode_twodiv_fx() * * Two-div core encoder *-------------------------------------------------------------------*/ void core_encode_twodiv_fx( - const Word16 new_samples[], /* i : new samples */ - Encoder_State *st, /* i/o: coder memory state */ - const Word16 coder_type, /* i : coding type */ - Word16 Aw[NB_SUBFR16k*(M+1)], /* i : weighted A(z) unquant. for subframes*/ - const Word16 vad_hover_flag, /* i : VAD hangover flag */ + const Word16 new_samples[], /* i : new samples */ + Encoder_State *st, /* i/o: coder memory state */ + const Word16 coder_type, /* i : coding type */ + Word16 Aw[NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquant. for subframes*/ + const Word16 vad_hover_flag, /* i : VAD hangover flag */ Word16 *Q_new, - Word16 *shift -) + Word16 *shift ) { Word16 n; Word16 lsp_new[M], lsp_mid[M]; Word16 lsf_q[M], lsp_q[M], lspmid_q[M]; - Word16 A_q[M+1]; + Word16 A_q[M + 1]; Word16 param_lpc[NPRM_LPC_NEW]; Word16 nbits_lpc[2]; - Word16 param_core[2*NPRM_DIV]; + Word16 param_core[2 * NPRM_DIV]; Word16 target_bits; Word16 gainlpc[2][FDNS_NPTS]; Word16 gainlpc_e[2][FDNS_NPTS]; @@ -49,10 +48,10 @@ void core_encode_twodiv_fx( Word32 spectrum_buf[N_MAX]; Word32 *spectrum[2]; /* MDCT spectrum */ Word16 spectrum_e[2]; - Word16 indexBuffer[2*((N_MAX/2)+1)]; + Word16 indexBuffer[2 * ( ( N_MAX / 2 ) + 1 )]; CONTEXT_HM_CONFIG hm_cfg[2]; Word16 i, T_op[3]; - Word16 bits_param_lpc[10], no_param_lpc; + Word16 bits_param_lpc[10], no_param_lpc; TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; LPD_state_HANDLE hLPDmem; /* ACELP LPDmem memories */ @@ -63,7 +62,7 @@ void core_encode_twodiv_fx( hm_cfg[0].indexBuffer = &indexBuffer[0]; move16(); - hm_cfg[1].indexBuffer = &indexBuffer[N_MAX/2+1]; + hm_cfg[1].indexBuffer = &indexBuffer[N_MAX / 2 + 1]; move16(); move16(); @@ -83,78 +82,76 @@ void core_encode_twodiv_fx( T_op[i] = st->pitch_fx[i]; /* check minimum pitch for quantization */ - IF ( LT_16(T_op[i], PIT_MIN_SHORTER)) + IF( LT_16( T_op[i], PIT_MIN_SHORTER ) ) { move16(); - T_op[i] = shl(T_op[i], 1); + T_op[i] = shl( T_op[i], 1 ); } /* convert pitch values to core sampling-rate */ - IF ( NE_16(st->L_frame, L_FRAME)) + IF( NE_16( st->L_frame, L_FRAME ) ) { move16(); /* T_op[i] = (short)(T_op[i] * (float)st->L_frame/(float)L_FRAME + 0.5f); */ - T_op[i] = round_fx(L_shr(L_mult0(T_op[i], st->L_frame), 8 - 16)); + T_op[i] = round_fx( L_shr( L_mult0( T_op[i], st->L_frame ), 8 - 16 ) ); } } /*--------------------------------------------------------------* - * TCX20/TCX10 switching decision - *---------------------------------------------------------------*/ + * TCX20/TCX10 switching decision + *---------------------------------------------------------------*/ move16(); st->core = TCX_10_CORE; - if ( EQ_16(hTcxEnc->tcxMode,TCX_20)) + if ( EQ_16( hTcxEnc->tcxMode, TCX_20 ) ) { move16(); st->core = TCX_20_CORE; } - assert(hTcxEnc->tcxMode == TCX_20 || hTcxEnc->tcxMode == TCX_10); + assert( hTcxEnc->tcxMode == TCX_20 || hTcxEnc->tcxMode == TCX_10 ); /*--------------------------------------------------------------* - * Core Signal Analysis: MDCT, TNS, LPC analysis - *---------------------------------------------------------------*/ - - core_signal_analysis_high_bitrate_fx( new_samples, - T_op, - lsp_new, - lsp_mid, - st, - tnsSize, - tnsBits, - param_core, - <pBits, - st->L_frame, - hTcxEnc->L_frameTCX, - EVS_MONO, - vad_hover_flag, - spectrum, - spectrum_e, - Q_new - ); + * Core Signal Analysis: MDCT, TNS, LPC analysis + *---------------------------------------------------------------*/ + + core_signal_analysis_high_bitrate_fx( new_samples, + T_op, + lsp_new, + lsp_mid, + st, + tnsSize, + tnsBits, + param_core, + <pBits, + st->L_frame, + hTcxEnc->L_frameTCX, + EVS_MONO, + vad_hover_flag, + spectrum, + spectrum_e, + Q_new ); /*--------------------------------------------------------------* - * LPC Quantization - *---------------------------------------------------------------*/ + * LPC Quantization + *---------------------------------------------------------------*/ lpc_quantization_fx( st, lsp_new, lsp_mid, lsp_q, lsf_q, lspmid_q, NULL, st->clip_var_fx, coder_type, - 0, param_lpc, nbits_lpc, bits_param_lpc, &no_param_lpc, add(*Q_new, Q_SCALE - 2) ); + 0, param_lpc, nbits_lpc, bits_param_lpc, &no_param_lpc, add( *Q_new, Q_SCALE - 2 ) ); /*--------------------------------------------------------------* - * Rate switching - *---------------------------------------------------------------*/ - IF( st->rate_switching_reset!=0 ) + * Rate switching + *---------------------------------------------------------------*/ + IF( st->rate_switching_reset != 0 ) { Copy( lsp_q, st->lsp_old_fx, M ); Copy( lsf_q, st->lsf_old_fx, M ); } - /*--------------------------------------------------------------* - * Run Two TCX10 - *---------------------------------------------------------------*/ + * Run Two TCX10 + *---------------------------------------------------------------*/ - IF ( EQ_16(st->core,TCX_10_CORE)) + IF( EQ_16( st->core, TCX_10_CORE ) ) { Word16 last_ace_mode; @@ -163,28 +160,27 @@ void core_encode_twodiv_fx( last_ace_mode = st->last_core; - FOR (n = 0; n < 2; n++) + FOR( n = 0; n < 2; n++ ) { - IF(n == 0) + IF( n == 0 ) { - E_LPC_f_lsp_a_conversion(lspmid_q, A_q, M); + E_LPC_f_lsp_a_conversion( lspmid_q, A_q, M ); } ELSE { - E_LPC_f_lsp_a_conversion(lsp_q, A_q, M); + E_LPC_f_lsp_a_conversion( lsp_q, A_q, M ); } /* Shape spectrum */ - ShapeSpectrum_fx(st->hTcxCfg, - A_q, - gainlpc[n], - gainlpc_e[n], - shr(st->L_frame, 1), - shr(st->hTcxCfg->tcx_coded_lines, 1), - spectrum[n], - hTcxEnc->fUseTns_fx[n], - st - ); + ShapeSpectrum_fx( st->hTcxCfg, + A_q, + gainlpc[n], + gainlpc_e[n], + shr( st->L_frame, 1 ), + shr( st->hTcxCfg->tcx_coded_lines, 1 ), + spectrum[n], + hTcxEnc->fUseTns_fx[n], + st ); st->last_core = st->core; move16(); @@ -194,35 +190,35 @@ void core_encode_twodiv_fx( /* Calculate target bits */ - bitsAvailable = sub(sub(sub(st->bits_frame_core, nbits_lpc[0]), nbits_lpc[1]), st->nb_bits_header_tcx); + bitsAvailable = sub( sub( sub( st->bits_frame_core, nbits_lpc[0] ), nbits_lpc[1] ), st->nb_bits_header_tcx ); /* subtract bits for TCX overlap mode (1 bit: full, 2 bits: half or no overlap) */ - bitsAvailable = sub(bitsAvailable,1); + bitsAvailable = sub( bitsAvailable, 1 ); test(); - if (EQ_16(st->hTcxCfg->tcx_curr_overlap_mode, HALF_OVERLAP)||EQ_16(st->hTcxCfg->tcx_curr_overlap_mode,MIN_OVERLAP)) + if ( EQ_16( st->hTcxCfg->tcx_curr_overlap_mode, HALF_OVERLAP ) || EQ_16( st->hTcxCfg->tcx_curr_overlap_mode, MIN_OVERLAP ) ) { - bitsAvailable = sub(bitsAvailable,1); + bitsAvailable = sub( bitsAvailable, 1 ); } - bitsAvailable = sub(bitsAvailable, st->hIGFEnc->infoTotalBitsWritten); + bitsAvailable = sub( bitsAvailable, st->hIGFEnc->infoTotalBitsWritten ); /* calculate noise-filling over whole spectrum for TCX10 frames */ move16(); hTcxEnc->measuredBwRatio = 0x4000; - FOR (n = 0; n < 2; n++) + FOR( n = 0; n < 2; n++ ) { - target_bits = sub(shr(sub(add(bitsAvailable, 1), n),1), tnsBits[n]); + target_bits = sub( shr( sub( add( bitsAvailable, 1 ), n ), 1 ), tnsBits[n] ); - if (n == 0) + if ( n == 0 ) { - target_bits = sub(target_bits, ltpBits); + target_bits = sub( target_bits, ltpBits ); } test(); - if(st->enablePlcWaveadjust && n) + if ( st->enablePlcWaveadjust && n ) { - target_bits = sub(target_bits, 1); + target_bits = sub( target_bits, 1 ); } @@ -234,76 +230,73 @@ void core_encode_twodiv_fx( NULL, gainlpc[n], gainlpc_e[n], - st->synth+n*st->L_frame/2, - shr(st->L_frame, 1), - shr(hTcxEnc->L_frameTCX, 1), - shr(st->hTcxCfg->tcx_coded_lines, 1), + st->synth + n * st->L_frame / 2, + shr( st->L_frame, 1 ), + shr( hTcxEnc->L_frameTCX, 1 ), + shr( st->hTcxCfg->tcx_coded_lines, 1 ), target_bits, - (Word8)st->tcxonly, + (Word8) st->tcxonly, spectrum[n], &spectrum_e[n], - hTcxEnc->tnsData+n, + hTcxEnc->tnsData + n, hTcxEnc->fUseTns_fx[n], tnsSize[n], - param_core+n*NPRM_DIV, + param_core + n * NPRM_DIV, n, st, - &hm_cfg[n] - ); + &hm_cfg[n] ); /* Update tcx overlap mode */ test(); - if ((n > 0) || (st->tcxonly==0)) + if ( ( n > 0 ) || ( st->tcxonly == 0 ) ) { move16(); st->hTcxCfg->tcx_last_overlap_mode = st->hTcxCfg->tcx_curr_overlap_mode; } - } coder_tcx_post_fx( st, hLPDmem, st->hTcxCfg, st->synth, A_q, Aw, st->wspeech_enc, *Q_new, *shift ); } /*--------------------------------------------------------------* - * Run One TCX20 - *---------------------------------------------------------------*/ + * Run One TCX20 + *---------------------------------------------------------------*/ - IF ( EQ_16(st->core,TCX_20_CORE)) + IF( EQ_16( st->core, TCX_20_CORE ) ) { - E_LPC_f_lsp_a_conversion(lsp_q, A_q, M); + E_LPC_f_lsp_a_conversion( lsp_q, A_q, M ); - ShapeSpectrum_fx(st->hTcxCfg, - A_q, - gainlpc[0], - gainlpc_e[0], - st->L_frame, - st->hTcxCfg->tcx_coded_lines, - spectrum[0], - hTcxEnc->fUseTns_fx[0], - st - ); + ShapeSpectrum_fx( st->hTcxCfg, + A_q, + gainlpc[0], + gainlpc_e[0], + st->L_frame, + st->hTcxCfg->tcx_coded_lines, + spectrum[0], + hTcxEnc->fUseTns_fx[0], + st ); /*_DIFF_FLOAT_FIX_ -> The line below is present in float */ - //hTcxEnc->measuredBwRatio = 0x4000; + // hTcxEnc->measuredBwRatio = 0x4000; /* Calculate target bits */ - target_bits = sub(sub(sub(sub(st->bits_frame_core, tnsBits[0]), nbits_lpc[0]), st->nb_bits_header_tcx), ltpBits); + target_bits = sub( sub( sub( sub( st->bits_frame_core, tnsBits[0] ), nbits_lpc[0] ), st->nb_bits_header_tcx ), ltpBits ); /* subtract bits for TCX overlap mode (1 bit: full, 2 bits: half or no overlap) */ - target_bits = sub(target_bits,1); + target_bits = sub( target_bits, 1 ); test(); - if (EQ_16(st->hTcxCfg->tcx_curr_overlap_mode, HALF_OVERLAP)||EQ_16(st->hTcxCfg->tcx_curr_overlap_mode,MIN_OVERLAP)) + if ( EQ_16( st->hTcxCfg->tcx_curr_overlap_mode, HALF_OVERLAP ) || EQ_16( st->hTcxCfg->tcx_curr_overlap_mode, MIN_OVERLAP ) ) { - target_bits = sub(target_bits,1); + target_bits = sub( target_bits, 1 ); } - target_bits = sub(target_bits, st->hIGFEnc->infoTotalBitsPerFrameWritten); + target_bits = sub( target_bits, st->hIGFEnc->infoTotalBitsPerFrameWritten ); - if(st->enablePlcWaveadjust) + if ( st->enablePlcWaveadjust ) { - target_bits = sub(target_bits, 1); + target_bits = sub( target_bits, 1 ); } @@ -318,7 +311,7 @@ void core_encode_twodiv_fx( hTcxEnc->L_frameTCX, st->hTcxCfg->tcx_coded_lines, target_bits, - (Word8)st->tcxonly, + (Word8) st->tcxonly, spectrum[0], &spectrum_e[0], &hTcxEnc->tnsData[0], @@ -327,24 +320,19 @@ void core_encode_twodiv_fx( param_core, 0, st, - &hm_cfg[0] - ); + &hm_cfg[0] ); coder_tcx_post_fx( st, hLPDmem, st->hTcxCfg, st->synth, A_q, Aw, st->wspeech_enc, *Q_new, *shift ); - } /* Update lsp/lsf memory */ - Copy(lsf_q, st->lsf_old_fx, M); - Copy(lsp_q, st->lsp_old_fx, M); - + Copy( lsf_q, st->lsf_old_fx, M ); + Copy( lsp_q, st->lsp_old_fx, M ); /*--------------------------------------------------------------* - * Generate Bitstream - *---------------------------------------------------------------*/ - - enc_prm_fx( coder_type, param_core, param_lpc, st, st->L_frame, hm_cfg, bits_param_lpc, no_param_lpc ); + * Generate Bitstream + *---------------------------------------------------------------*/ + enc_prm_fx( coder_type, param_core, param_lpc, st, st->L_frame, hm_cfg, bits_param_lpc, no_param_lpc ); } - diff --git a/lib_enc/core_enc_init_fx.c b/lib_enc/core_enc_init_fx.c index f56cb3ca6..938997bd4 100644 --- a/lib_enc/core_enc_init_fx.c +++ b/lib_enc/core_enc_init_fx.c @@ -6,7 +6,7 @@ //#include "prot_fx.h" //#include "basop_mpy.h" #include "options.h" -#include "cnst.h" /* Common constants */ +#include "cnst.h" /* Common constants */ #include "stl.h" #include "count.h" #include "basop_util.h" @@ -15,21 +15,21 @@ #include #include "rom_com.h" /* Common constants */ #include "prot.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ -#include "basop_util.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ +#include "basop_util.h" /* Function prototypes */ /*-----------------------------------------------------------------------* * Local functions *-----------------------------------------------------------------------*/ -static void init_tcx_fx( Encoder_State *st, Word16 L_frame_old, const Word32 total_brate, const Word32 last_total_brate, const Word16 MCT_flag); -static void init_core_sig_ana_fx(Encoder_State *st ); -static void init_acelp_fx(Encoder_State *st, Word16 L_frame_old, const Word16 shift); -static void init_modes_fx(Encoder_State *st, const Word32 Last_total_brate ); -static void init_sig_buffers_fx(Encoder_State *st, const Word16 L_frame_old, const Word16 L_subfr); +static void init_tcx_fx( Encoder_State *st, Word16 L_frame_old, const Word32 total_brate, const Word32 last_total_brate, const Word16 MCT_flag ); +static void init_core_sig_ana_fx( Encoder_State *st ); +static void init_acelp_fx( Encoder_State *st, Word16 L_frame_old, const Word16 shift ); +static void init_modes_fx( Encoder_State *st, const Word32 Last_total_brate ); +static void init_sig_buffers_fx( Encoder_State *st, const Word16 L_frame_old, const Word16 L_subfr ); /*-----------------------------------------------------------------------* * init_coder_ace_plus_fx() @@ -39,9 +39,9 @@ static void init_sig_buffers_fx(Encoder_State *st, const Word16 L_frame_old, con void init_coder_ace_plus_fx( Encoder_State *st, - const Word32 last_total_brate, /* i : last total bitrate */ - const Word16 shift, - const Word16 MCT_flag /* i : hMCT handle allocated (1) or not (0) */ + const Word32 last_total_brate, /* i : last total bitrate */ + const Word16 shift, + const Word16 MCT_flag /* i : hMCT handle allocated (1) or not (0) */ ) { Word16 L_frame_old; /*keep old frame size for switching */ @@ -50,26 +50,27 @@ void init_coder_ace_plus_fx( TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; /* Bitrate */ - st->tcxonly = (Word8)getTcxonly( + st->tcxonly = (Word8) getTcxonly( #ifdef IVAS_CODE_SWITCHING - st->element_mode, + st->element_mode, #endif - st->total_brate + st->total_brate #ifdef IVAS_CODE_SWITCHING - , MCT_flag, st->is_ism_format + , + MCT_flag, st->is_ism_format #endif ); move16(); /* Core Sampling Rate */ - st->sr_core = getCoreSamplerateMode2(st->element_mode, st->total_brate, st->bwidth, st->flag_ACELP16k, st->rf_mode, st->is_ism_format); - st->fscale = sr2fscale(st->sr_core); + st->sr_core = getCoreSamplerateMode2( st->element_mode, st->total_brate, st->bwidth, st->flag_ACELP16k, st->rf_mode, st->is_ism_format ); + st->fscale = sr2fscale( st->sr_core ); move16(); /* Narrowband? */ st->narrowBand = 0; move16(); - if( EQ_16(st->bwidth, NB)) + if ( EQ_16( st->bwidth, NB ) ) { st->narrowBand = 1; move16(); @@ -78,44 +79,45 @@ void init_coder_ace_plus_fx( /* Core Framing */ L_frame_old = st->last_L_frame; move16(); - st->L_frame = extract_l(Mult_32_16(st->sr_core , 0x0290)); + st->L_frame = extract_l( Mult_32_16( st->sr_core, 0x0290 ) ); st->L_frame_past = -1; move16(); - hTcxEnc->L_frameTCX = extract_l(Mult_32_16(st->input_Fs , 0x0290)); + hTcxEnc->L_frameTCX = extract_l( Mult_32_16( st->input_Fs, 0x0290 ) ); st->nb_subfr = NB_SUBFR; move16(); - L_subfr = shr(st->L_frame, 2); + L_subfr = shr( st->L_frame, 2 ); test(); - IF ( EQ_16(st->L_frame, L_FRAME16k)&&LE_32(st->total_brate,32000)) + IF( EQ_16( st->L_frame, L_FRAME16k ) && LE_32( st->total_brate, 32000 ) ) { st->nb_subfr = NB_SUBFR16k; move16(); - L_subfr = mult(st->L_frame, 0x199A); /*1/5 = 0x199A Q15*/ move16(); + L_subfr = mult( st->L_frame, 0x199A ); /*1/5 = 0x199A Q15*/ + move16(); } /* Core Lookahead */ - st->encoderLookahead_enc = NS2SA_fx2(st->sr_core, ACELP_LOOK_NS); + st->encoderLookahead_enc = NS2SA_fx2( st->sr_core, ACELP_LOOK_NS ); move16(); - st->encoderLookahead_FB = NS2SA_fx2(st->input_Fs, ACELP_LOOK_NS); + st->encoderLookahead_FB = NS2SA_fx2( st->input_Fs, ACELP_LOOK_NS ); move16(); - IF ( st->ini_frame == 0 ) + IF( st->ini_frame == 0 ) { st->acelpFramesCount = 0; move16(); - st->prevTempFlatness_fx = 128/*1.0f Q7*/; + st->prevTempFlatness_fx = 128 /*1.0f Q7*/; move16(); } /* Initialize TBE */ hBWE_TD->prev_coder_type = GENERIC; move16(); - set16_fx(hBWE_TD->prev_lsf_diff_fx, 16384, LPC_SHB_ORDER-2 ); + set16_fx( hBWE_TD->prev_lsf_diff_fx, 16384, LPC_SHB_ORDER - 2 ); hBWE_TD->prev_tilt_para_fx = 0; move16(); - set16_fx(hBWE_TD->cur_sub_Aq_fx, 0, M+1 ); + set16_fx( hBWE_TD->cur_sub_Aq_fx, 0, M + 1 ); st->currEnergyHF_fx = 0; move16(); @@ -128,7 +130,7 @@ void init_coder_ace_plus_fx( st->lpcQuantization = 0; move16(); test(); - if( LE_32(st->sr_core,16000)&&st->tcxonly==0) + if ( LE_32( st->sr_core, 16000 ) && st->tcxonly == 0 ) { st->lpcQuantization = 1; move16(); @@ -139,26 +141,26 @@ void init_coder_ace_plus_fx( move16(); test(); test(); - IF ( NE_16(st->last_L_frame,st->L_frame)||EQ_16(st->last_core,AMR_WB_CORE)||EQ_16(st->last_core,HQ_CORE)) + IF( NE_16( st->last_L_frame, st->L_frame ) || EQ_16( st->last_core, AMR_WB_CORE ) || EQ_16( st->last_core, HQ_CORE ) ) { set16_fx( st->mem_MA_fx, 0, M ); - Copy(GEWB_Ave_fx, st->mem_AR_fx, M); + Copy( GEWB_Ave_fx, st->mem_AR_fx, M ); } /* Initialize IGF */ - if (st->hIGFEnc != NULL) + if ( st->hIGFEnc != NULL ) { st->hIGFEnc->infoStopFrequency = -1; } move16(); IF( st->igf ) { - IGFEncSetMode_fx(st->hIGFEnc, st->total_brate, st->bwidth, st->element_mode, st->rf_mode); + IGFEncSetMode_fx( st->hIGFEnc, st->total_brate, st->bwidth, st->element_mode, st->rf_mode ); } - ELSE IF (st->hIGFEnc != NULL) + ELSE IF( st->hIGFEnc != NULL ) { st->hIGFEnc->infoTotalBitsWritten = 0; - if (EQ_16(MCT_flag, -10)) + if ( EQ_16( MCT_flag, -10 ) ) { st->hIGFEnc->infoTotalBitsPerFrameWritten = 0; } @@ -166,9 +168,9 @@ void init_coder_ace_plus_fx( } /* Initialize TCX */ - if (hTcxEnc != NULL) + if ( hTcxEnc != NULL ) { - init_tcx_fx(st, L_frame_old, st->total_brate, last_total_brate, MCT_flag); + init_tcx_fx( st, L_frame_old, st->total_brate, last_total_brate, MCT_flag ); } /* Initialize Core Signal Analysis Module */ init_core_sig_ana_fx( st ); @@ -177,26 +179,26 @@ void init_coder_ace_plus_fx( init_sig_buffers_fx( st, L_frame_old, L_subfr ); /* Initialize ACELP */ - init_acelp_fx( st, L_frame_old , shift); + init_acelp_fx( st, L_frame_old, shift ); - if(st->ini_frame == 0) + if ( st->ini_frame == 0 ) { st->tec_tfa = 0; move16(); } - IF(st->tec_tfa == 0) + IF( st->tec_tfa == 0 ) { - resetTecEnc_Fx(st->hTECEnc, 0); + resetTecEnc_Fx( st->hTECEnc, 0 ); } ELSE { - resetTecEnc_Fx(st->hTECEnc, 1); + resetTecEnc_Fx( st->hTECEnc, 1 ); } st->tec_tfa = 0; move16(); test(); test(); - if( EQ_16(st->bwidth, SWB)&&(EQ_32(st->total_brate,ACELP_16k40)||EQ_32(st->total_brate,ACELP_24k40))) + if ( EQ_16( st->bwidth, SWB ) && ( EQ_32( st->total_brate, ACELP_16k40 ) || EQ_32( st->total_brate, ACELP_24k40 ) ) ) { st->tec_tfa = 1; move16(); @@ -210,7 +212,7 @@ void init_coder_ace_plus_fx( IF( st->ini_frame == 0 ) { - vad_init_fx(&st->vad_st); + vad_init_fx( &st->vad_st ); } st->glr = 0; @@ -219,8 +221,8 @@ void init_coder_ace_plus_fx( test(); test(); test(); - if( (EQ_32(st->total_brate, ACELP_9k60))||(EQ_32(st->total_brate,ACELP_16k40))|| - (EQ_32(st->total_brate, ACELP_24k40))||(EQ_32(st->total_brate, ACELP_32k))) + if ( ( EQ_32( st->total_brate, ACELP_9k60 ) ) || ( EQ_32( st->total_brate, ACELP_16k40 ) ) || + ( EQ_32( st->total_brate, ACELP_24k40 ) ) || ( EQ_32( st->total_brate, ACELP_32k ) ) ) { st->glr = 1; move16(); @@ -230,22 +232,22 @@ void init_coder_ace_plus_fx( move16(); /* Initialize ACELP/TCX Modes */ - init_modes_fx( st, last_total_brate); + init_modes_fx( st, last_total_brate ); /* Init I/O */ /* Adaptive BPF */ - set16_fx(st->mem_bpf_fx.noise_buf, 0, 2*L_FILT16k); - set16_fx(st->mem_bpf_fx.error_buf, 0, L_FILT16k); - set16_fx(st->bpf_gainT, 0, NB_SUBFR16k); + set16_fx( st->mem_bpf_fx.noise_buf, 0, 2 * L_FILT16k ); + set16_fx( st->mem_bpf_fx.error_buf, 0, L_FILT16k ); + set16_fx( st->bpf_gainT, 0, NB_SUBFR16k ); - set16_fx(st->bpf_T, PIT_MIN_12k8, NB_SUBFR16k); + set16_fx( st->bpf_T, PIT_MIN_12k8, NB_SUBFR16k ); st->mem_bpf_fx.noise_shift_old = 0; move16(); - IF ( st->ini_frame == 0 ) + IF( st->ini_frame == 0 ) { st->Q_max_enc[0] = 15; move16(); @@ -255,7 +257,7 @@ void init_coder_ace_plus_fx( st->enablePlcWaveadjust = 0; move16(); - if (GE_32(st->total_brate, 48000)) + if ( GE_32( st->total_brate, 48000 ) ) { st->enablePlcWaveadjust = 1; move16(); @@ -269,8 +271,8 @@ void init_coder_ace_plus_fx( move16(); move16(); move16(); /* casts */ - st->mean_gc[0] = L_deposit_h(0); - st->mean_gc[1] = L_deposit_h(0); + st->mean_gc[0] = L_deposit_h( 0 ); + st->mean_gc[1] = L_deposit_h( 0 ); st->prev_lsf4_mean = 0; move16(); @@ -281,42 +283,41 @@ void init_coder_ace_plus_fx( return; } -static void init_tcx_fx( - Encoder_State *st, +static void init_tcx_fx( + Encoder_State *st, Word16 L_frame_old, const Word32 total_brate, const Word32 last_total_brate, - const Word16 MCT_flag -) + const Word16 MCT_flag ) { Word16 i; Word16 fscaleFB; TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; #ifdef REMOVE_IVAS_UNUSED_PARAMETERS_WARNING - (void)MCT_flag; - (void)total_brate; - (void)last_total_brate; + (void) MCT_flag; + (void) total_brate; + (void) last_total_brate; #endif -//PMT("init_tcx_fx needs an entire review to adapt to IVAS") - fscaleFB = div_l(L_shl(st->input_Fs, LD_FSCALE_DENOM+1), 12800); + // PMT("init_tcx_fx needs an entire review to adapt to IVAS") + fscaleFB = div_l( L_shl( st->input_Fs, LD_FSCALE_DENOM + 1 ), 12800 ); - init_TCX_config(st->hTcxCfg, st->L_frame, st->fscale, hTcxEnc->L_frameTCX, fscaleFB ); + init_TCX_config( st->hTcxCfg, st->L_frame, st->fscale, hTcxEnc->L_frameTCX, fscaleFB ); st->hTcxCfg->tcx_mdct_window_length_old = st->hTcxCfg->tcx_mdct_window_length; move16(); /* TCX Offset */ - st->hTcxCfg->tcx_offset = shr(st->hTcxCfg->tcx_mdct_window_delay, 1); + st->hTcxCfg->tcx_offset = shr( st->hTcxCfg->tcx_mdct_window_delay, 1 ); move16(); - st->hTcxCfg->tcx_offsetFB = shr(st->hTcxCfg->tcx_mdct_window_delayFB, 1); + st->hTcxCfg->tcx_offsetFB = shr( st->hTcxCfg->tcx_mdct_window_delayFB, 1 ); move16(); /*<0 rectangular transition with optimized window size = L_frame+L_frame/4*/ - st->hTcxCfg->lfacNext = sub(st->hTcxCfg->tcx_offset, shr(st->L_frame, 2)); + st->hTcxCfg->lfacNext = sub( st->hTcxCfg->tcx_offset, shr( st->L_frame, 2 ) ); move16(); - st->hTcxCfg->lfacNextFB = sub(st->hTcxCfg->tcx_offsetFB, shr(hTcxEnc->L_frameTCX, 2)); + st->hTcxCfg->lfacNextFB = sub( st->hTcxCfg->tcx_offsetFB, shr( hTcxEnc->L_frameTCX, 2 ) ); - IF ( st->ini_frame == 0 ) + IF( st->ini_frame == 0 ) { st->hTcxCfg->tcx_curr_overlap_mode = st->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; move16(); @@ -324,18 +325,21 @@ static void init_tcx_fx( } /* Init TCX target bits correction factor */ - hTcxEnc->tcx_target_bits_fac = 0x4000; /*1.0f in 1Q14*/ move16(); - hTcxEnc->measuredBwRatio = 0x4000; /*1.0f in 1Q14*/ move16(); - hTcxEnc->noiseTiltFactor = 9216; /*0.5625f in 1Q14*/ move16(); + hTcxEnc->tcx_target_bits_fac = 0x4000; /*1.0f in 1Q14*/ + move16(); + hTcxEnc->measuredBwRatio = 0x4000; /*1.0f in 1Q14*/ + move16(); + hTcxEnc->noiseTiltFactor = 9216; /*0.5625f in 1Q14*/ + move16(); hTcxEnc->noiseLevelMemory_cnt = 0; move16(); /*SQ deadzone & memory quantization*/ /*0.375f: deadzone of 1.25->rounding=1-1.25/2 (No deadzone=0.5)*/ - st->hTcxCfg->sq_rounding = 12288/*0.375f Q15*/; + st->hTcxCfg->sq_rounding = 12288 /*0.375f Q15*/; move16(); - FOR (i = 0; i < L_FRAME_PLUS; i++) + FOR( i = 0; i < L_FRAME_PLUS; i++ ) { hTcxEnc->memQuantZeros_fx[i] = 0; move16(); @@ -353,26 +357,26 @@ static void init_tcx_fx( /* TCX bandwidth */ move16(); - st->hTcxCfg->bandwidth = getTcxBandwidth(st->bwidth); + st->hTcxCfg->bandwidth = getTcxBandwidth( st->bwidth ); /* set number of coded lines */ - st->hTcxCfg->tcx_coded_lines = getNumTcxCodedLines(st->bwidth); + st->hTcxCfg->tcx_coded_lines = getNumTcxCodedLines( st->bwidth ); /* TNS in TCX */ move16(); move16(); - st->hTcxCfg->fIsTNSAllowed = (Word8)getTnsAllowed(st->total_brate ,st->igf, st->element_mode); + st->hTcxCfg->fIsTNSAllowed = (Word8) getTnsAllowed( st->total_brate, st->igf, st->element_mode ); st->hTcxCfg->pCurrentTnsConfig = NULL; - IF ( st->hTcxCfg->fIsTNSAllowed != 0 ) + IF( st->hTcxCfg->fIsTNSAllowed != 0 ) { - InitTnsConfigs(st->bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFEnc->infoStopFrequency, st->total_brate, st->element_mode, 0/*is_mct*/); + InitTnsConfigs( st->bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFEnc->infoStopFrequency, st->total_brate, st->element_mode, 0 /*is_mct*/ ); } /* TCX-LTP */ - hTcxEnc->tcxltp = getTcxLtp(st->sr_core); + hTcxEnc->tcxltp = getTcxLtp( st->sr_core ); test(); test(); @@ -390,25 +394,25 @@ static void init_tcx_fx( hTcxEnc->tcxltp_norm_corr_past = 0; move16(); } - ELSE IF ( NE_16(st->L_frame,L_frame_old)&&!((st->total_brate==16400||st->total_brate==24400)&&(st->total_brate==st->last_total_brate)&&(st->last_bwidth==st->bwidth))) + ELSE IF( NE_16( st->L_frame, L_frame_old ) && !( ( st->total_brate == 16400 || st->total_brate == 24400 ) && ( st->total_brate == st->last_total_brate ) && ( st->last_bwidth == st->bwidth ) ) ) { - Word16 pitres, pitres_old; - Word16 pit, pit_old; + Word16 pitres, pitres_old; + Word16 pit, pit_old; pitres_old = 4; move16(); - if (EQ_16(160,shr(L_frame_old,sub(7,norm_s(L_frame_old))))) /*if ( L_frame_old%160==0 )*/ + if ( EQ_16( 160, shr( L_frame_old, sub( 7, norm_s( L_frame_old ) ) ) ) ) /*if ( L_frame_old%160==0 )*/ { pitres_old = 6; move16(); } /*pit_old = (float)st->tcxltp_pitch_int_past + (float)st->tcxltp_pitch_fr_past/(float)pitres_old;*/ - pit_old = add(hTcxEnc->tcxltp_pitch_int_past, mult_r(hTcxEnc->tcxltp_pitch_fr_past, div_s(1,pitres_old))); + pit_old = add( hTcxEnc->tcxltp_pitch_int_past, mult_r( hTcxEnc->tcxltp_pitch_fr_past, div_s( 1, pitres_old ) ) ); pitres = 4; move16(); - if (EQ_16(160,shr(st->L_frame,sub(7,norm_s(st->L_frame))))) /*if ( st->L_frame%160==0 )*/ + if ( EQ_16( 160, shr( st->L_frame, sub( 7, norm_s( st->L_frame ) ) ) ) ) /*if ( st->L_frame%160==0 )*/ { pitres = 6; move16(); @@ -416,35 +420,34 @@ static void init_tcx_fx( #ifdef BASOP_NOGLOB /*pit = pit_old * (float)st->L_frame/(float)L_frame_old;*/ - pit = shl_sat(mult_r(pit_old, div_s(st->L_frame, shl(L_frame_old, 2))), 2); + pit = shl_sat( mult_r( pit_old, div_s( st->L_frame, shl( L_frame_old, 2 ) ) ), 2 ); /* Note : the saturation here that can happens when FS == 32kHz*/ #else - pit = shl(mult_r(pit_old, div_s(st->L_frame, shl(L_frame_old, 2))), 2); + pit = shl( mult_r( pit_old, div_s( st->L_frame, shl( L_frame_old, 2 ) ) ), 2 ); #endif /* assert(pit <= st->L_frame);*/ hTcxEnc->tcxltp_pitch_int_past = pit; move16(); move16(); - hTcxEnc->tcxltp_pitch_fr_past = i_mult2(sub(pit, hTcxEnc->tcxltp_pitch_int_past),pitres); + hTcxEnc->tcxltp_pitch_fr_past = i_mult2( sub( pit, hTcxEnc->tcxltp_pitch_int_past ), pitres ); move16(); } /* Residual Coding*/ - st->hTcxCfg->resq = getResq(st->total_brate); + st->hTcxCfg->resq = getResq( st->total_brate ); move16(); test(); - if ( st->hTcxCfg->resq != 0 && st->tcxonly == 0) + if ( st->hTcxCfg->resq != 0 && st->tcxonly == 0 ) { st->hTcxCfg->tcxRateLoopOpt = 1; move16(); } - st->hTcxCfg->ctx_hm = getCtxHm(st->element_mode, st->total_brate, st->rf_mode ); - - hTcxEnc->tcx_lpc_shaped_ari = getTcxLpcShapedAri(st->total_brate,st->rf_mode, st->element_mode); + st->hTcxCfg->ctx_hm = getCtxHm( st->element_mode, st->total_brate, st->rf_mode ); + hTcxEnc->tcx_lpc_shaped_ari = getTcxLpcShapedAri( st->total_brate, st->rf_mode, st->element_mode ); } void init_sig_buffers_fx( Encoder_State *st, const Word16 L_frame_old, const Word16 L_subfr ) @@ -454,15 +457,15 @@ void init_sig_buffers_fx( Encoder_State *st, const Word16 L_frame_old, const Wor TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; /* Encoder Past Samples at encoder-sampling-rate */ - st->encoderPastSamples_enc = shr(imult1616(st->L_frame, 9), 4); + st->encoderPastSamples_enc = shr( imult1616( st->L_frame, 9 ), 4 ); /* Initialize Signal Buffers and Pointers at encoder-sampling-rate */ - IF ( st->ini_frame == 0 ) + IF( st->ini_frame == 0 ) { - set16_fx(st->buf_speech_enc, 0, L_PAST_MAX_32k+L_FRAME32k+L_NEXT_MAX_32k); - set16_fx(st->buf_speech_enc_pe, 0, L_PAST_MAX_32k+L_FRAME32k+L_NEXT_MAX_32k); - set16_fx(hTcxEnc->buf_speech_ltp, 0, L_PAST_MAX_32k+L_FRAME32k+L_NEXT_MAX_32k); - set16_fx(st->buf_wspeech_enc, 0, L_FRAME16k+L_SUBFR+L_FRAME16k+L_NEXT_MAX_16k); + set16_fx( st->buf_speech_enc, 0, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); + set16_fx( st->buf_speech_enc_pe, 0, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); + set16_fx( hTcxEnc->buf_speech_ltp, 0, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); + set16_fx( st->buf_wspeech_enc, 0, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k ); } ELSE { @@ -471,75 +474,73 @@ void init_sig_buffers_fx( Encoder_State *st, const Word16 L_frame_old, const Wor test(); test(); test(); - IF ( NE_16(st->L_frame,L_frame_old)&&!((EQ_32(st->total_brate,ACELP_16k40)||EQ_32(st->total_brate,ACELP_24k40))&&(EQ_32(st->total_brate,st->last_total_brate))&&(EQ_16(st->last_bwidth,st->bwidth)))) + IF( NE_16( st->L_frame, L_frame_old ) && !( ( EQ_32( st->total_brate, ACELP_16k40 ) || EQ_32( st->total_brate, ACELP_24k40 ) ) && ( EQ_32( st->total_brate, st->last_total_brate ) ) && ( EQ_16( st->last_bwidth, st->bwidth ) ) ) ) { lerp( st->buf_speech_enc, st->buf_speech_enc, st->L_frame, L_frame_old ); test(); - IF( NE_16(st->last_core,TCX_20_CORE)&&NE_16(st->last_core,TCX_10_CORE)) /* condition should be checked again */ + IF( NE_16( st->last_core, TCX_20_CORE ) && NE_16( st->last_core, TCX_10_CORE ) ) /* condition should be checked again */ { Copy( st->buf_speech_enc, hTcxEnc->buf_speech_ltp, st->L_frame ); } - Copy_Scale_sig( st->old_wsp_fx, st->buf_wspeech_enc+st->L_frame + L_SUBFR-L_WSP_MEM,L_WSP_MEM, sub(st->prev_Q_new, st->prev_Q_old)); + Copy_Scale_sig( st->old_wsp_fx, st->buf_wspeech_enc + st->L_frame + L_SUBFR - L_WSP_MEM, L_WSP_MEM, sub( st->prev_Q_new, st->prev_Q_old ) ); /*Resamp buffers needed only for ACELP*/ test(); test(); - IF( EQ_16(st->L_frame,L_FRAME)&&!st->tcxonly) + IF( EQ_16( st->L_frame, L_FRAME ) && !st->tcxonly ) { - Copy_Scale_sig( st->old_inp_12k8_fx, st->buf_speech_enc_pe+st->L_frame-L_INP_MEM,L_INP_MEM, sub(st->prev_Q_new, st->prev_Q_old)); - + Copy_Scale_sig( st->old_inp_12k8_fx, st->buf_speech_enc_pe + st->L_frame - L_INP_MEM, L_INP_MEM, sub( st->prev_Q_new, st->prev_Q_old ) ); } - ELSE IF( EQ_16(st->L_frame,L_FRAME16k)&&!st->tcxonly) + ELSE IF( EQ_16( st->L_frame, L_FRAME16k ) && !st->tcxonly ) { - lerp( st->buf_wspeech_enc+st->L_frame + L_SUBFR-L_WSP_MEM, st->buf_wspeech_enc+st->L_frame + L_SUBFR-310, 310, L_WSP_MEM ); - Copy( st->old_inp_16k_fx, st->buf_speech_enc_pe+st->L_frame-L_INP_MEM,L_INP_MEM); - + lerp( st->buf_wspeech_enc + st->L_frame + L_SUBFR - L_WSP_MEM, st->buf_wspeech_enc + st->L_frame + L_SUBFR - 310, 310, L_WSP_MEM ); + Copy( st->old_inp_16k_fx, st->buf_speech_enc_pe + st->L_frame - L_INP_MEM, L_INP_MEM ); } - st->mem_preemph_enc = st->buf_speech_enc[st->encoderPastSamples_enc+st->encoderLookahead_enc-1]; + st->mem_preemph_enc = st->buf_speech_enc[st->encoderPastSamples_enc + st->encoderLookahead_enc - 1]; move16(); - st->mem_wsp_enc = st->buf_wspeech_enc[st->L_frame+L_SUBFR-1]; + st->mem_wsp_enc = st->buf_wspeech_enc[st->L_frame + L_SUBFR - 1]; move16(); } /*coming from TCXonly modes*/ - ELSE IF( !st->tcxonly && GE_32(st->last_total_brate,ACELP_32k)) + ELSE IF( !st->tcxonly && GE_32( st->last_total_brate, ACELP_32k ) ) { - Copy_Scale_sig( st->old_wsp_fx, st->buf_wspeech_enc+st->L_frame + L_SUBFR-L_WSP_MEM,L_WSP_MEM, sub(st->prev_Q_new, st->prev_Q_old)); + Copy_Scale_sig( st->old_wsp_fx, st->buf_wspeech_enc + st->L_frame + L_SUBFR - L_WSP_MEM, L_WSP_MEM, sub( st->prev_Q_new, st->prev_Q_old ) ); /*Resamp buffers needed only for ACELP*/ - IF( EQ_16(st->L_frame,L_FRAME16k)) + IF( EQ_16( st->L_frame, L_FRAME16k ) ) { - lerp( st->buf_wspeech_enc+st->L_frame + L_SUBFR-L_WSP_MEM, st->buf_wspeech_enc+st->L_frame + L_SUBFR-310, 310, L_WSP_MEM ); + lerp( st->buf_wspeech_enc + st->L_frame + L_SUBFR - L_WSP_MEM, st->buf_wspeech_enc + st->L_frame + L_SUBFR - 310, 310, L_WSP_MEM ); } hLPDmem->mem_w0 = 0; move16(); - st->mem_wsp_enc = st->buf_wspeech_enc[st->L_frame+L_SUBFR-1]; + st->mem_wsp_enc = st->buf_wspeech_enc[st->L_frame + L_SUBFR - 1]; move16(); } } - st->new_speech_enc = st->buf_speech_enc + st->encoderPastSamples_enc + st->encoderLookahead_enc; - st->new_speech_enc_pe = st->buf_speech_enc_pe + st->encoderPastSamples_enc + st->encoderLookahead_enc; - hTcxEnc->new_speech_ltp = hTcxEnc->buf_speech_ltp + st->encoderPastSamples_enc + st->encoderLookahead_enc; - hTcxEnc->new_speech_TCX = st->input_buff_fx + L_FRAME48k + NS2SA(48000, DELAY_FIR_RESAMPL_NS) - NS2SA(st->input_Fs, DELAY_FIR_RESAMPL_NS); + st->new_speech_enc = st->buf_speech_enc + st->encoderPastSamples_enc + st->encoderLookahead_enc; + st->new_speech_enc_pe = st->buf_speech_enc_pe + st->encoderPastSamples_enc + st->encoderLookahead_enc; + hTcxEnc->new_speech_ltp = hTcxEnc->buf_speech_ltp + st->encoderPastSamples_enc + st->encoderLookahead_enc; + hTcxEnc->new_speech_TCX = st->input_buff_fx + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) - NS2SA( st->input_Fs, DELAY_FIR_RESAMPL_NS ); - st->speech_enc = st->buf_speech_enc + st->encoderPastSamples_enc; - st->speech_enc_pe = st->buf_speech_enc_pe + st->encoderPastSamples_enc; - hTcxEnc->speech_ltp = hTcxEnc->buf_speech_ltp + st->encoderPastSamples_enc; - hTcxEnc->speech_TCX = hTcxEnc->new_speech_TCX - st->encoderLookahead_FB; + st->speech_enc = st->buf_speech_enc + st->encoderPastSamples_enc; + st->speech_enc_pe = st->buf_speech_enc_pe + st->encoderPastSamples_enc; + hTcxEnc->speech_ltp = hTcxEnc->buf_speech_ltp + st->encoderPastSamples_enc; + hTcxEnc->speech_TCX = hTcxEnc->new_speech_TCX - st->encoderLookahead_FB; - st->wspeech_enc = st->buf_wspeech_enc + st->L_frame + L_subfr; + st->wspeech_enc = st->buf_wspeech_enc + st->L_frame + L_subfr; test(); test(); - IF( st->ini_frame == 0 || NE_16(st->L_frame,L_frame_old)||EQ_16(st->last_codec_mode,MODE1)) + IF( st->ini_frame == 0 || NE_16( st->L_frame, L_frame_old ) || EQ_16( st->last_codec_mode, MODE1 ) ) { - set16_fx(st->buf_synth, 0, OLD_SYNTH_SIZE_ENC+L_FRAME32k); + set16_fx( st->buf_synth, 0, OLD_SYNTH_SIZE_ENC + L_FRAME32k ); } - st->synth = st->buf_synth + st->L_frame + L_subfr; + st->synth = st->buf_synth + st->L_frame + L_subfr; return; @@ -550,24 +551,27 @@ static void init_core_sig_ana_fx( Encoder_State *st ) /* Pre-emphasis factor and memory */ - st->preemph_fac = PREEMPH_FAC_SWB; /*SWB*/ move16(); - IF ( LT_16(st->fscale, (16000*FSCALE_DENOM)/12800)) + st->preemph_fac = PREEMPH_FAC_SWB; /*SWB*/ + move16(); + IF( LT_16( st->fscale, ( 16000 * FSCALE_DENOM ) / 12800 ) ) { - st->preemph_fac = PREEMPH_FAC; /*WB*/ move16(); + st->preemph_fac = PREEMPH_FAC; /*WB*/ + move16(); } - ELSE IF ( LT_16(st->fscale, (24000*FSCALE_DENOM)/12800)) + ELSE IF( LT_16( st->fscale, ( 24000 * FSCALE_DENOM ) / 12800 ) ) { - st->preemph_fac = PREEMPH_FAC_16k; /*WB*/ move16(); + st->preemph_fac = PREEMPH_FAC_16k; /*WB*/ + move16(); } - st->hTcxCfg->preemph_fac=st->preemph_fac; + st->hTcxCfg->preemph_fac = st->preemph_fac; move16(); st->gamma = GAMMA1; move16(); st->inv_gamma = GAMMA1_INV; move16(); - IF ( EQ_32(st->sr_core, 16000)) + IF( EQ_32( st->sr_core, 16000 ) ) { st->gamma = GAMMA16k; move16(); @@ -581,7 +585,7 @@ static void init_core_sig_ana_fx( Encoder_State *st ) st->max_band = 16; move16(); - IF ( st->narrowBand == 0) + IF( st->narrowBand == 0 ) { st->min_band = 0; move16(); @@ -593,7 +597,7 @@ static void init_core_sig_ana_fx( Encoder_State *st ) return; } -static void init_acelp_fx( Encoder_State *st, Word16 L_frame_old , const Word16 shift) +static void init_acelp_fx( Encoder_State *st, Word16 L_frame_old, const Word16 shift ) { Word16 mem_syn_r_size_old; Word16 mem_syn_r_size_new; @@ -601,59 +605,59 @@ static void init_acelp_fx( Encoder_State *st, Word16 L_frame_old , const Word16 TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; /* Init pitch lag */ - st->pit_res_max = initPitchLagParameters(st->sr_core, &st->pit_min, &st->pit_fr1, &st->pit_fr1b, &st->pit_fr2, &st->pit_max); + st->pit_res_max = initPitchLagParameters( st->sr_core, &st->pit_min, &st->pit_fr1, &st->pit_fr1b, &st->pit_fr2, &st->pit_max ); /* Init LPDmem */ IF( st->ini_frame == 0 ) { - set16_fx( hLPDmem->syn, 0, 1+M ); + set16_fx( hLPDmem->syn, 0, 1 + M ); - set16_fx(hTcxEnc->Txnq, 0, L_FRAME32k/2+64); - hTcxEnc->acelp_zir = hTcxEnc->Txnq + shr(st->L_frame,1); + set16_fx( hTcxEnc->Txnq, 0, L_FRAME32k / 2 + 64 ); + hTcxEnc->acelp_zir = hTcxEnc->Txnq + shr( st->L_frame, 1 ); set16_fx( hLPDmem->mem_syn_r, 0, L_SYN_MEM ); } ELSE /*Rate switching*/ { - IF( EQ_16(st->last_core,ACELP_CORE)) + IF( EQ_16( st->last_core, ACELP_CORE ) ) { - lerp(hTcxEnc->Txnq,hTcxEnc->Txnq, shr(st->L_frame,1), shr(L_frame_old,1) ); + lerp( hTcxEnc->Txnq, hTcxEnc->Txnq, shr( st->L_frame, 1 ), shr( L_frame_old, 1 ) ); } ELSE { - lerp(hTcxEnc->Txnq,hTcxEnc->Txnq, st->hTcxCfg->tcx_mdct_window_length, st->hTcxCfg->tcx_mdct_window_length_old ); + lerp( hTcxEnc->Txnq, hTcxEnc->Txnq, st->hTcxCfg->tcx_mdct_window_length, st->hTcxCfg->tcx_mdct_window_length_old ); } - hTcxEnc->acelp_zir = hTcxEnc->Txnq + shr(st->L_frame,1); + hTcxEnc->acelp_zir = hTcxEnc->Txnq + shr( st->L_frame, 1 ); /* Rate switching */ - IF( EQ_16(st->last_codec_mode,MODE1)) + IF( EQ_16( st->last_codec_mode, MODE1 ) ) { - Copy(hLPDmem->mem_syn1_fx, hLPDmem->mem_syn2, M ); - set16_fx(hTcxEnc->Txnq, 0, L_FRAME32k/2+64); + Copy( hLPDmem->mem_syn1_fx, hLPDmem->mem_syn2, M ); + set16_fx( hTcxEnc->Txnq, 0, L_FRAME32k / 2 + 64 ); set16_fx( hLPDmem->syn, 0, M ); } /*AMR-WBIO->MODE2*/ - IF( EQ_16(st->last_core,AMR_WB_CORE)) + IF( EQ_16( st->last_core, AMR_WB_CORE ) ) { - st->next_force_safety_net_fx=1; + st->next_force_safety_net_fx = 1; move16(); st->last_core = ACELP_CORE; move16(); } /*HQ-CORE->MODE2*/ test(); - IF( EQ_16(st->last_codec_mode,MODE1)&&EQ_16(st->last_core,HQ_CORE)) + IF( EQ_16( st->last_codec_mode, MODE1 ) && EQ_16( st->last_core, HQ_CORE ) ) { /*Reset of ACELP memories*/ - st->next_force_safety_net_fx=1; + st->next_force_safety_net_fx = 1; move16(); st->rate_switching_reset = 1; move16(); hLPDmem->tilt_code = TILT_CODE; move16(); set16_fx( hLPDmem->old_exc, 0, L_EXC_MEM ); - set16_fx( hLPDmem->syn, 0, 1+M ); + set16_fx( hLPDmem->syn, 0, 1 + M ); hLPDmem->mem_w0 = 0; move16(); set16_fx( hLPDmem->mem_syn, 0, M ); @@ -661,10 +665,10 @@ static void init_acelp_fx( Encoder_State *st, Word16 L_frame_old , const Word16 /* unquantized LPC*/ test(); - IF ( !((EQ_32(st->total_brate,ACELP_16k40)||EQ_32(st->total_brate,ACELP_24k40))&&(EQ_32(st->total_brate,st->last_total_brate))&&(EQ_16(st->last_bwidth,st->bwidth)))) + IF( !( ( EQ_32( st->total_brate, ACELP_16k40 ) || EQ_32( st->total_brate, ACELP_24k40 ) ) && ( EQ_32( st->total_brate, st->last_total_brate ) ) && ( EQ_16( st->last_bwidth, st->bwidth ) ) ) ) { Copy( st->lsp_old1_fx, st->lspold_enc_fx, M ); /*lsp old @12.8kHz*/ - IF( EQ_16(st->L_frame,L_FRAME16k)) + IF( EQ_16( st->L_frame, L_FRAME16k ) ) { lsp_convert_poly_fx( st->lspold_enc_fx, st->L_frame, 0 ); } @@ -681,19 +685,19 @@ static void init_acelp_fx( Encoder_State *st, Word16 L_frame_old , const Word16 st->last_core = TCX_20_CORE; move16(); - st->hTcxCfg->last_aldo=1; /*It was previously ALDO*/ + st->hTcxCfg->last_aldo = 1; /*It was previously ALDO*/ st->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; /*ALDO overlap windowed past: also used in MODE1 but for other MDCT-FB*/ - set16_fx(hTcxEnc->old_out_fx, 0, st->L_frame ); + set16_fx( hTcxEnc->old_out_fx, 0, st->L_frame ); } ELSE { test(); test(); - IF( (NE_16(st->L_frame,L_frame_old))&&(LE_16(st->L_frame,L_FRAME16k))&&(LE_16(L_frame_old,L_FRAME16k))) + IF( ( NE_16( st->L_frame, L_frame_old ) ) && ( LE_16( st->L_frame, L_FRAME16k ) ) && ( LE_16( L_frame_old, L_FRAME16k ) ) ) { /* convert quantized LSP vector */ - st->rate_switching_reset=lsp_convert_poly_fx( st->lsp_old_fx, st->L_frame, 0 ); + st->rate_switching_reset = lsp_convert_poly_fx( st->lsp_old_fx, st->L_frame, 0 ); IF( st->tcxonly == 0 ) { lsp2lsf_fx( st->lsp_old_fx, st->lsf_old_fx, M, st->sr_core ); @@ -702,7 +706,7 @@ static void init_acelp_fx( Encoder_State *st, Word16 L_frame_old , const Word16 { E_LPC_lsp_lsf_conversion( st->lsp_old_fx, st->lsf_old_fx, M ); } - IF( EQ_16(st->L_frame,L_FRAME16k)) + IF( EQ_16( st->L_frame, L_FRAME16k ) ) { Copy( st->lsp_old_fx, st->lspold_enc_fx, M ); } @@ -715,29 +719,29 @@ static void init_acelp_fx( Encoder_State *st, Word16 L_frame_old , const Word16 /*Mem of deemphasis stay unchanged : hLPDmem->syn*/ { - Word16 tmp, A[M+1], Ap[M+1],tmp_buf[M+1]; + Word16 tmp, A[M + 1], Ap[M + 1], tmp_buf[M + 1]; /* Update wsyn */ /* lsp2a_stab( st->lsp_old, A, M ); */ - E_LPC_f_lsp_a_conversion(st->lsp_old_fx, A, M); + E_LPC_f_lsp_a_conversion( st->lsp_old_fx, A, M ); weight_a_fx( A, Ap, GAMMA1, M ); - tmp=0; + tmp = 0; move16(); - tmp_buf[0]=0; + tmp_buf[0] = 0; move16(); - Copy( hLPDmem->mem_syn2, tmp_buf+1, M ); - deemph_fx( tmp_buf+1, st->preemph_fac, M, &tmp ); - Residu3_fx( Ap, tmp_buf+M, &tmp, 1, 1 ); + Copy( hLPDmem->mem_syn2, tmp_buf + 1, M ); + deemph_fx( tmp_buf + 1, st->preemph_fac, M, &tmp ); + Residu3_fx( Ap, tmp_buf + M, &tmp, 1, 1 ); #ifdef BASOP_NOGLOB hLPDmem->mem_w0 = sub_sat( shr_sat( st->wspeech_enc[-1], shift ), tmp ); #else - hLPDmem->mem_w0 = sub(shr(st->wspeech_enc[-1],shift), tmp); + hLPDmem->mem_w0 = sub( shr( st->wspeech_enc[-1], shift ), tmp ); #endif } } - ELSE IF((NE_16(st->L_frame,L_frame_old))) + ELSE IF( ( NE_16( st->L_frame, L_frame_old ) ) ) { /*Partial reset of ACELP memories*/ - st->next_force_safety_net_fx=1; + st->next_force_safety_net_fx = 1; move16(); st->rate_switching_reset = 1; move16(); @@ -751,11 +755,11 @@ static void init_acelp_fx( Encoder_State *st, Word16 L_frame_old , const Word16 /*Resamp others memories*/ /*Size of LPC syn memory*/ /* 1.25/20.0 = 1.0/16.0 -> shift 4 to the right. */ - mem_syn_r_size_old = shr(L_frame_old, 4); - mem_syn_r_size_new = shr(st->L_frame, 4); + mem_syn_r_size_old = shr( L_frame_old, 4 ); + mem_syn_r_size_new = shr( st->L_frame, 4 ); - lerp( hLPDmem->mem_syn_r+L_SYN_MEM-mem_syn_r_size_old, hLPDmem->mem_syn_r+L_SYN_MEM-mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); - Copy( hLPDmem->mem_syn_r+L_SYN_MEM-M, hLPDmem->mem_syn, M); + lerp( hLPDmem->mem_syn_r + L_SYN_MEM - mem_syn_r_size_old, hLPDmem->mem_syn_r + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); + Copy( hLPDmem->mem_syn_r + L_SYN_MEM - M, hLPDmem->mem_syn, M ); Copy( hLPDmem->mem_syn, hLPDmem->mem_syn2, M ); /*Untouched memories : hLPDmem->syn & hLPDmem->mem_w0*/ @@ -764,7 +768,7 @@ static void init_acelp_fx( Encoder_State *st, Word16 L_frame_old , const Word16 /* unquantized LPC*/ Copy( st->lsp_old1_fx, st->lspold_enc_fx, M ); /*lsp old @12.8kHz*/ - IF( EQ_16(st->L_frame,L_FRAME16k)) + IF( EQ_16( st->L_frame, L_FRAME16k ) ) { lsp_convert_poly_fx( st->lspold_enc_fx, st->L_frame, 0 ); } @@ -778,7 +782,7 @@ static void init_acelp_fx( Encoder_State *st, Word16 L_frame_old , const Word16 E_LPC_lsp_lsf_conversion( st->lsp_old_fx, st->lsf_old_fx, M ); } } - ELSE IF( !st->tcxonly && EQ_16(st->L_frame,L_FRAME16k)&>_32(st->last_total_brate,ACELP_32k)) + ELSE IF( !st->tcxonly && EQ_16( st->L_frame, L_FRAME16k ) && GT_32( st->last_total_brate, ACELP_32k ) ) { lsp2lsf_fx( st->lsp_old_fx, st->lsf_old_fx, M, st->sr_core ); } @@ -787,15 +791,15 @@ static void init_acelp_fx( Encoder_State *st, Word16 L_frame_old , const Word16 test(); test(); - if(EQ_16(st->last_bwidth,NB)&&NE_16(st->bwidth,NB)&&st->ini_frame!=0) + if ( EQ_16( st->last_bwidth, NB ) && NE_16( st->bwidth, NB ) && st->ini_frame != 0 ) { - st->rate_switching_reset=1; + st->rate_switching_reset = 1; move16(); } /* Post-processing */ - hLPDmem->dm_fx.prev_gain_code = L_deposit_l(0); - set16_fx(hLPDmem->dm_fx.prev_gain_pit, 0, 6); + hLPDmem->dm_fx.prev_gain_code = L_deposit_l( 0 ); + set16_fx( hLPDmem->dm_fx.prev_gain_pit, 0, 6 ); hLPDmem->dm_fx.prev_state = 0; move16(); @@ -807,7 +811,7 @@ static void init_acelp_fx( Encoder_State *st, Word16 L_frame_old , const Word16 move16(); /*Use for 12.8 kHz sampling rate and low bitrates, the conventional pulse search->better SNR*/ - if ((LE_32(st->total_brate, ACELP_9k60)||st->rf_mode!=0)&&(EQ_32(st->sr_core,12800))) + if ( ( LE_32( st->total_brate, ACELP_9k60 ) || st->rf_mode != 0 ) && ( EQ_32( st->sr_core, 12800 ) ) ) { st->acelp_autocorr = 0; move16(); @@ -815,12 +819,12 @@ static void init_acelp_fx( Encoder_State *st, Word16 L_frame_old , const Word16 /*BPF parameters for adjusting gain in function of background noise*/ - IF( EQ_16(st->codec_mode,MODE2)) + IF( EQ_16( st->codec_mode, MODE2 ) ) { - st->mem_bpf_fx.lp_error_ener = L_deposit_l(0); - if( st->last_codec_mode == MODE1 ) + st->mem_bpf_fx.lp_error_ener = L_deposit_l( 0 ); + if ( st->last_codec_mode == MODE1 ) { - st->mem_bpf_fx.lp_error = L_deposit_l(0); + st->mem_bpf_fx.lp_error = L_deposit_l( 0 ); } } @@ -828,10 +832,9 @@ static void init_acelp_fx( Encoder_State *st, Word16 L_frame_old , const Word16 return; } -static void init_modes_fx( +static void init_modes_fx( Encoder_State *st, - const Word32 last_total_brate -) + const Word32 last_total_brate ) { Word8 n; Word32 tmp32; @@ -840,7 +843,7 @@ static void init_modes_fx( /* Restrict ACE/TCX20/TCX10 mode */ move16(); - st->restrictedMode = getRestrictedMode(st->element_mode, st->total_brate, st->Opt_AMR_WB); + st->restrictedMode = getRestrictedMode( st->element_mode, st->total_brate, st->Opt_AMR_WB ); move16(); st->acelpEnabled = 0; move16(); @@ -848,17 +851,17 @@ static void init_modes_fx( move16(); st->tcx10Enabled = 0; - if (EQ_16(s_and(st->restrictedMode,1),1)) + if ( EQ_16( s_and( st->restrictedMode, 1 ), 1 ) ) { st->acelpEnabled = 1; move16(); } - if (EQ_16(s_and(st->restrictedMode,2),2)) + if ( EQ_16( s_and( st->restrictedMode, 2 ), 2 ) ) { st->tcx20Enabled = 1; move16(); } - if (EQ_16(s_and(st->restrictedMode,4),4)) + if ( EQ_16( s_and( st->restrictedMode, 4 ), 4 ) ) { st->tcx10Enabled = 1; move16(); @@ -876,24 +879,24 @@ static void init_modes_fx( /* st->bits_frame_nominal = extract_h(L_add(L_mult(div_l(L_mult(shl(st->L_frame,2),st->bitrate),st->fscale),328),16056)); */ /* st->bits_frame_nominal = (int)( (float)st->L_frame/(float)st->fscale * (float)FSCALE_DENOM/128.0f * (float)st->bitrate/100.0f + 0.49f ); */ - assert(FSCALE_DENOM == 512); - assert(st->fscale == 2 * st->L_frame); /* this assumption is true if operated in 20ms frames with FSCALE_DENOM == 512, which is the current default */ - tmp32 = L_shl(st->total_brate, 1); /* (float)st->L_frame/(float)st->fscale * (float)FSCALE_DENOM/128.0f * (float)st->bitrate */ - st->bits_frame_nominal = extract_l(L_shr(Mpy_32_16_1(tmp32, 20972), 6)); /* 20972 = 0.01 * 64 * 32768 */ - assert(st->bits_frame_nominal == (int)( (float)st->L_frame/(float)st->fscale * (float)FSCALE_DENOM/128.0f * (float)st->total_brate/100.0f + 0.49f )); + assert( FSCALE_DENOM == 512 ); + assert( st->fscale == 2 * st->L_frame ); /* this assumption is true if operated in 20ms frames with FSCALE_DENOM == 512, which is the current default */ + tmp32 = L_shl( st->total_brate, 1 ); /* (float)st->L_frame/(float)st->fscale * (float)FSCALE_DENOM/128.0f * (float)st->bitrate */ + st->bits_frame_nominal = extract_l( L_shr( Mpy_32_16_1( tmp32, 20972 ), 6 ) ); /* 20972 = 0.01 * 64 * 32768 */ + assert( st->bits_frame_nominal == (int) ( (float) st->L_frame / (float) st->fscale * (float) FSCALE_DENOM / 128.0f * (float) st->total_brate / 100.0f + 0.49f ) ); - IF (st->Opt_AMR_WB) + IF( st->Opt_AMR_WB ) { - st->bits_frame = st->bits_frame_nominal; + st->bits_frame = st->bits_frame_nominal; st->bits_frame_core = st->bits_frame_nominal; st->frame_size_index = 0; move16(); } ELSE { - FOR (n=0; nbits_frame_nominal)) + IF( EQ_16( FrameSizeConfig[n].frame_bits, st->bits_frame_nominal ) ) { move16(); move16(); @@ -904,14 +907,14 @@ static void init_modes_fx( BREAK; } } - if (n==FRAME_SIZE_NB) + if ( n == FRAME_SIZE_NB ) { - assert(!"Bitrate not supported: not part of EVS"); + assert( !"Bitrate not supported: not part of EVS" ); } } /* Reconfigure core */ - core_coder_reconfig_fx( st, last_total_brate); + core_coder_reconfig_fx( st, last_total_brate ); return; diff --git a/lib_enc/core_enc_ol.c b/lib_enc/core_enc_ol.c index b7498cfa0..85c1c0b04 100644 --- a/lib_enc/core_enc_ol.c +++ b/lib_enc/core_enc_ol.c @@ -185,7 +185,7 @@ void core_encode_openloop( if ( st->envWeighted ) { /* Unweight the envelope */ - E_LPC_lsp_unweight_float( st->lsp_old, st->lsp_old, st->lsf_old, 1.0f / st->gamma_flt); + E_LPC_lsp_unweight_float( st->lsp_old, st->lsp_old, st->lsf_old, 1.0f / st->gamma_flt ); st->envWeighted = 0; } @@ -268,11 +268,11 @@ void core_encode_openloop( if ( st->hPlcExt ) { - st->glr_idx[0] = encSideSpecPowDiffuseDetector( st->hPlcExt->last_lsf_ref_flt, st->hPlcExt->last_lsf_con_flt, st->last_sr_core, &( st->prev_lsf4_mean_flt), st->glr, st->coder_type ); + st->glr_idx[0] = encSideSpecPowDiffuseDetector( st->hPlcExt->last_lsf_ref_flt, st->hPlcExt->last_lsf_con_flt, st->last_sr_core, &( st->prev_lsf4_mean_flt ), st->glr, st->coder_type ); mvr2r( lsf_q, st->hPlcExt->last_lsf_ref_flt, M ); mvr2r( st->hPlcExt->lsf_con_flt, st->hPlcExt->last_lsf_con_flt, M ); - updateSpecPowDiffuseIdx( gain_pitch_buf, gain_code_buf, st->glr_idx, st->mean_gc_flt); + updateSpecPowDiffuseIdx( gain_pitch_buf, gain_code_buf, st->glr_idx, st->mean_gc_flt ); if ( st->last_stab_fac_flt > 0.02 ) { @@ -385,7 +385,7 @@ void core_encode_openloop( if ( st->enableTcxLpc ) { - E_LPC_lsp_unweight_float( lsp_tcx_q, lsp_q, lsf_q, 1.0f / st->gamma_flt); /* Update lsf_q for encoderSideLossSimulation() */ + E_LPC_lsp_unweight_float( lsp_tcx_q, lsp_q, lsf_q, 1.0f / st->gamma_flt ); /* Update lsf_q for encoderSideLossSimulation() */ } if ( st->hPlcExt ) { diff --git a/lib_enc/core_enc_ol_fx.c b/lib_enc/core_enc_ol_fx.c index a603c3fcc..4a7db5f69 100644 --- a/lib_enc/core_enc_ol_fx.c +++ b/lib_enc/core_enc_ol_fx.c @@ -5,25 +5,24 @@ #include #include #include "options.h" -#include "cnst.h" /* Common constants */ +#include "cnst.h" /* Common constants */ //#include "prot_fx.h" #include "basop_util.h" #include "rom_com_fx.h" #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ -#include "basop_util.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ +#include "basop_util.h" /* Function prototypes */ /*-------------------------------------------------------------------* * Local function prototypes *-------------------------------------------------------------------*/ -static void closest_centroid_rf(const Word16 *data, const Word16 *weights, const Word16 *quantizer, const Word16 centroids, const Word16 length, Word16 *ind_vec); -static void BITS_ALLOC_ACELP_config_rf(const Word16 coder_type, Word16* tilt_code, Word16* rf_frame_type, Word16* rf_target_bits, Word16 nb_subfr, Word16 rf_fec_indicator, Word16* pitch_buf); -static void BITS_ALLOC_TCX_config_rf(Word16* rf_frame_type, Word16* rf_target_bits, Word16 PLC_Mode, Word16 coder_type, Word16 last_core, Word16 TD_mode); - +static void closest_centroid_rf( const Word16 *data, const Word16 *weights, const Word16 *quantizer, const Word16 centroids, const Word16 length, Word16 *ind_vec ); +static void BITS_ALLOC_ACELP_config_rf( const Word16 coder_type, Word16 *tilt_code, Word16 *rf_frame_type, Word16 *rf_target_bits, Word16 nb_subfr, Word16 rf_fec_indicator, Word16 *pitch_buf ); +static void BITS_ALLOC_TCX_config_rf( Word16 *rf_frame_type, Word16 *rf_target_bits, Word16 PLC_Mode, Word16 coder_type, Word16 last_core, Word16 TD_mode ); /*-------------------------------------------------------------------* @@ -33,41 +32,40 @@ static void BITS_ALLOC_TCX_config_rf(Word16* rf_frame_type, Word16* rf_target_bi *-------------------------------------------------------------------*/ void core_encode_openloop_fx( - Encoder_State *st, /* i/o: encoder state structure */ - const Word16 coder_type, /* i : coding type */ - const Word16 Aw[NB_SUBFR16k*(M+1)], /* i : weighted A(z) unquant. for subframes*/ - const Word16 *lsp_new, /* i : LSPs at the end of the frame */ - const Word16 *lsp_mid, /* i : LSPs at the middle of the frame */ - Word16 *pitch_buf, /* i/o: floating pitch values for each subfr*/ - Word16 *voice_factors, /* o : voicing factors */ - Word16 *ptr_bwe_exc, /* o : excitation for SWB TBE */ + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 coder_type, /* i : coding type */ + const Word16 Aw[NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquant. for subframes*/ + const Word16 *lsp_new, /* i : LSPs at the end of the frame */ + const Word16 *lsp_mid, /* i : LSPs at the middle of the frame */ + Word16 *pitch_buf, /* i/o: floating pitch values for each subfr*/ + Word16 *voice_factors, /* o : voicing factors */ + Word16 *ptr_bwe_exc, /* o : excitation for SWB TBE */ const Word16 vad_hover_flag, const Word16 vad_flag_dtx, Word16 Q_new, - Word16 shift -) + Word16 shift ) { Word16 lsf_q[M], lsp_q[M], lspmid_q[M], lsf_tcx_q[M], lsp_tcx_q[M]; Word16 lspq_ind[M]; - Word16 A_q_ind[M+1]; + Word16 A_q_ind[M + 1]; Word16 tcx_lpc_cdk; - Word16 A_w[M+1]; - Word16 A_q[NB_SUBFR16k*(M+1)]; + Word16 A_w[M + 1]; + Word16 A_q[NB_SUBFR16k * ( M + 1 )]; Word16 param_lpc[NPRM_LPC_NEW]; Word16 nbits_lpc; - Word16 param_core[2*NPRM_DIV]; + Word16 param_core[2 * NPRM_DIV]; Word16 target_bits; Word16 stab_fac; Word32 spectrum_long[N_MAX]; /* MDCT output for a long block */ Word16 spectrum_long_e; - Word16 indexBuffer[N_MAX+1]; + Word16 indexBuffer[N_MAX + 1]; CONTEXT_HM_CONFIG hm_cfg; - Word16 bits_param_lpc[10], no_param_lpc; + Word16 bits_param_lpc[10], no_param_lpc; Word16 i; /* lsf quant parameters */ Word16 lsp_q_rf[M]; - Word16 Aq_rf[NB_SUBFR*(M+1)]; + Word16 Aq_rf[NB_SUBFR * ( M + 1 )]; Word16 stab_fac_rf; Word16 *exc_rf; Word16 *syn_rf; @@ -78,14 +76,14 @@ void core_encode_openloop_fx( Word16 rf_mem_MA[M]; Word16 exc_buf_rf[L_EXC_MEM + L_FRAME + 1]; - Word16 syn_buf_rf[M+L_FRAME16k+L_FRAME16k/2]; + Word16 syn_buf_rf[M + L_FRAME16k + L_FRAME16k / 2]; - Word16 w_rf[M+1], lsf_uq_rf[M+1]; - Word16 lsf_q_1st_rf[M+1], lsf_q_d_rf[M+1], lsf_q_rf[M+1]; - Word16 lsp_old_q_rf[M+1], lsf_old_q_rf[M+1]; + Word16 w_rf[M + 1], lsf_uq_rf[M + 1]; + Word16 lsf_q_1st_rf[M + 1], lsf_q_d_rf[M + 1], lsf_q_rf[M + 1]; + Word16 lsp_old_q_rf[M + 1], lsf_old_q_rf[M + 1]; #ifdef REMOVE_IVAS_UNUSED_PARAMETERS_WARNING - (void)vad_hover_flag; - (void)vad_flag_dtx; + (void) vad_hover_flag; + (void) vad_flag_dtx; #endif #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; @@ -95,8 +93,8 @@ void core_encode_openloop_fx( LPD_state_HANDLE hLPDmem; /* ACELP LPDmem memories */ hLPDmem = st->hLPDmem; - DTX_ENC_HANDLE hDtxEnc = st->hDtxEnc; - TD_CNG_ENC_HANDLE hTdCngEnc = st->hTdCngEnc; + DTX_ENC_HANDLE hDtxEnc = st->hDtxEnc; + TD_CNG_ENC_HANDLE hTdCngEnc = st->hTdCngEnc; /* copy primary memories to use later during partial copy assembly */ @@ -108,21 +106,21 @@ void core_encode_openloop_fx( */ /* back up the old LSPs and LSFs */ - Copy(st->lsp_old_fx, lsp_old_q_rf, M); - Copy(st->lsf_old_fx, lsf_old_q_rf, M); + Copy( st->lsp_old_fx, lsp_old_q_rf, M ); + Copy( st->lsf_old_fx, lsf_old_q_rf, M ); /* back up old exc before primary encoding */ - set16_fx( exc_buf_rf, 0, (L_EXC_MEM+L_FRAME+1) ); + set16_fx( exc_buf_rf, 0, ( L_EXC_MEM + L_FRAME + 1 ) ); exc_rf = exc_buf_rf + L_EXC_MEM; - Copy(hLPDmem->old_exc, exc_buf_rf, L_EXC_MEM); + Copy( hLPDmem->old_exc, exc_buf_rf, L_EXC_MEM ); /* back up old synthesis before primary encoding */ - set16_fx( syn_buf_rf, 0, (M+L_FRAME16k+L_FRAME16k/2) ); + set16_fx( syn_buf_rf, 0, ( M + L_FRAME16k + L_FRAME16k / 2 ) ); syn_rf = syn_buf_rf + M; - Copy(hLPDmem->mem_syn, syn_buf_rf, M); + Copy( hLPDmem->mem_syn, syn_buf_rf, M ); /* back up syn2 mem */ - Copy(hLPDmem->mem_syn2, hRF->rf_mem_syn2, M); + Copy( hLPDmem->mem_syn2, hRF->rf_mem_syn2, M ); /* back up LPD mem_w0 target generation memory */ hRF->rf_mem_w0 = hLPDmem->mem_w0; @@ -136,7 +134,7 @@ void core_encode_openloop_fx( /* back up dispMem */ hRF->rf_dm_fx.prev_state = hLPDmem->dm_fx.prev_state; hRF->rf_dm_fx.prev_gain_code = hLPDmem->dm_fx.prev_gain_code; - FOR(i=0; i<6; i++) + FOR( i = 0; i < 6; i++ ) { hRF->rf_dm_fx.prev_gain_pit[i] = hLPDmem->dm_fx.prev_gain_pit[i]; } @@ -148,38 +146,38 @@ void core_encode_openloop_fx( tcx_lpc_cdk = 0; move16(); set16_fx( param_lpc, 0, NPRM_LPC_NEW ); - set16_fx( param_core, 0, 2*NPRM_DIV ); - Copy(hTcxEnc->tcxltp_param, ¶m_core[1+NOISE_FILL_RANGES], LTPSIZE ); + set16_fx( param_core, 0, 2 * NPRM_DIV ); + Copy( hTcxEnc->tcxltp_param, ¶m_core[1 + NOISE_FILL_RANGES], LTPSIZE ); no_param_lpc = 0; - move16(); /* avoid MSVC warnings */ + move16(); /* avoid MSVC warnings */ nbits_lpc = 0; - move16(); /* avoid MSVC warnings */ + move16(); /* avoid MSVC warnings */ stab_fac = 0; - move16(); /* avoid MSVC warnings */ + move16(); /* avoid MSVC warnings */ - set32_fx(spectrum_long, 0, N_MAX); + set32_fx( spectrum_long, 0, N_MAX ); hm_cfg.indexBuffer = indexBuffer; move16(); /*--------------------------------------------------------------* - * LPC Quantization - *---------------------------------------------------------------*/ + * LPC Quantization + *---------------------------------------------------------------*/ st->acelp_cfg.midLpc = st->acelp_cfg.midLpc_enable; move16(); test(); - if ( EQ_16(st->lpcQuantization, 1) && EQ_16(coder_type,VOICED)) + if ( EQ_16( st->lpcQuantization, 1 ) && EQ_16( coder_type, VOICED ) ) { st->acelp_cfg.midLpc = 0; move16(); } test(); - IF ( st->core==ACELP_CORE || !st->enableTcxLpc ) + IF( st->core == ACELP_CORE || !st->enableTcxLpc ) { - IF (st->envWeighted) + IF( st->envWeighted ) { /* Unweight the envelope */ E_LPC_lsp_unweight( st->lsp_old_fx, st->lsp_old_fx, st->lsf_old_fx, st->inv_gamma, M ); @@ -187,41 +185,38 @@ void core_encode_openloop_fx( move16(); } - IF(EQ_16(st->core,TCX_20_CORE)) + IF( EQ_16( st->core, TCX_20_CORE ) ) { - lpc_quantization_fx( st, lsp_new, lsp_mid, lsp_q, lsf_q, lspmid_q, lspq_ind, st->clip_var_fx, - AUDIO, st->acelp_cfg.midLpc, param_lpc, &nbits_lpc, bits_param_lpc, &no_param_lpc, add(Q_new, Q_SCALE - 2) ); - + lpc_quantization_fx( st, lsp_new, lsp_mid, lsp_q, lsf_q, lspmid_q, lspq_ind, st->clip_var_fx, + AUDIO, st->acelp_cfg.midLpc, param_lpc, &nbits_lpc, bits_param_lpc, &no_param_lpc, add( Q_new, Q_SCALE - 2 ) ); } ELSE { lpc_quantization_fx( st, lsp_new, lsp_mid, lsp_q, lsf_q, lspmid_q, lspq_ind, st->clip_var_fx, coder_type, - st->acelp_cfg.midLpc, param_lpc, &nbits_lpc, bits_param_lpc, &no_param_lpc, add(Q_new, Q_SCALE - 2) ); + st->acelp_cfg.midLpc, param_lpc, &nbits_lpc, bits_param_lpc, &no_param_lpc, add( Q_new, Q_SCALE - 2 ) ); } /*-------------------------------------------------------------* * Rate switching: reset *---------------------------------------------------------------*/ - IF( st->rate_switching_reset!=0 ) + IF( st->rate_switching_reset != 0 ) { Copy( lsp_q, st->lsp_old_fx, M ); Copy( lsf_q, st->lsf_old_fx, M ); Copy( lsp_q, lspmid_q, M ); } - stab_fac = lsf_stab_fx(lsf_q, st->lsf_old_fx, 0, st->L_frame); + stab_fac = lsf_stab_fx( lsf_q, st->lsf_old_fx, 0, st->L_frame ); } - - /*--------------------------------------------------------------* - * Run ACELP - *---------------------------------------------------------------*/ - IF ( st->core==ACELP_CORE ) + * Run ACELP + *---------------------------------------------------------------*/ + IF( st->core == ACELP_CORE ) { - IF ( st->acelp_cfg.midLpc != 0 ) + IF( st->acelp_cfg.midLpc != 0 ) { int_lsp4_fx( st->L_frame, st->lsp_old_fx, lspmid_q, lsp_q, A_q, M, 0 ); } @@ -231,32 +226,31 @@ void core_encode_openloop_fx( } /* Calculate target bits */ - target_bits = sub(sub(st->bits_frame_core, nbits_lpc), st->nb_bits_header_ace); + target_bits = sub( sub( st->bits_frame_core, nbits_lpc ), st->nb_bits_header_ace ); - if(EQ_16(st->rf_mode,1)) + if ( EQ_16( st->rf_mode, 1 ) ) { /* joint bit allocation for redundant frame and TBE */ /* calculate target bits for core coding */ - target_bits = sub(target_bits, st->rf_target_bits_write); + target_bits = sub( target_bits, st->rf_target_bits_write ); } IF( st->igf != 0 ) { target_bits = sub( target_bits, get_tbe_bits_fx( st->total_brate, st->bwidth, st->rf_mode ) ); - } - if ( st->acelp_cfg.midLpc != 0) + if ( st->acelp_cfg.midLpc != 0 ) { - target_bits = sub(target_bits, MIDLSF_NBITS ); + target_bits = sub( target_bits, MIDLSF_NBITS ); } - if( st->hPlcExt->enableGplc ) + if ( st->hPlcExt->enableGplc ) { - target_bits = sub(target_bits, st->hPlcExt->nBits); + target_bits = sub( target_bits, st->hPlcExt->nBits ); } /* reset TBE buffers previous frame frame wasn't ACELP*/ - IF( NE_16( st->last_core, ACELP_CORE )) + IF( NE_16( st->last_core, ACELP_CORE ) ) { TBEreset_enc_fx( st, st->bwidth ); } @@ -264,16 +258,16 @@ void core_encode_openloop_fx( /* Run ACELP encoder */ coder_acelp_fx( Aw, A_q, st->speech_enc_pe, param_core, stab_fac, st, st->hPlcExt, target_bits, - Q_new, shift, pitch_buf, voice_factors, ptr_bwe_exc); - IF (st->hPlcExt) + Q_new, shift, pitch_buf, voice_factors, ptr_bwe_exc ); + IF( st->hPlcExt ) { - st->glr_idx[0] = encSideSpecPowDiffuseDetector_fx(st->hPlcExt->last_lsf_ref, st->hPlcExt->last_lsf_con, st->last_sr_core, &(st->prev_lsf4_mean), (Word8)st->glr, coder_type); - Copy(lsf_q, st->hPlcExt->last_lsf_ref, M); - Copy(st->hPlcExt->lsf_con, st->hPlcExt->last_lsf_con, M); + st->glr_idx[0] = encSideSpecPowDiffuseDetector_fx( st->hPlcExt->last_lsf_ref, st->hPlcExt->last_lsf_con, st->last_sr_core, &( st->prev_lsf4_mean ), (Word8) st->glr, coder_type ); + Copy( lsf_q, st->hPlcExt->last_lsf_ref, M ); + Copy( st->hPlcExt->lsf_con, st->hPlcExt->last_lsf_con, M ); - updateSpecPowDiffuseIdx_fx(st); + updateSpecPowDiffuseIdx_fx( st ); - if (GT_16(st->last_stab_fac, 655/*0.02f Q15*/)) + if ( GT_16( st->last_stab_fac, 655 /*0.02f Q15*/ ) ) { move16(); st->glr_idx[0] = 0; @@ -281,7 +275,7 @@ void core_encode_openloop_fx( move16(); move16(); st->hPlcExt->LPDmem = hLPDmem; - encoderSideLossSimulation_fx( st,st->hPlcExt, lsf_q, stab_fac, st->hPlcExt->calcOnlylsf, st->L_frame); + encoderSideLossSimulation_fx( st, st->hPlcExt, lsf_q, stab_fac, st->hPlcExt->calcOnlylsf, st->L_frame ); } st->last_stab_fac = stab_fac; @@ -291,98 +285,96 @@ void core_encode_openloop_fx( st->hTcxCfg->tcx_curr_overlap_mode = st->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; move16(); - } - /*--------------------------------------------------------------* - * Run TCX20 - *---------------------------------------------------------------*/ + * Run TCX20 + *---------------------------------------------------------------*/ - IF ( EQ_16(st->core, TCX_20_CORE)) + IF( EQ_16( st->core, TCX_20_CORE ) ) { - IF (st->enableTcxLpc) + IF( st->enableTcxLpc ) { - IF( EQ_16(st->rf_mode,1)) + IF( EQ_16( st->rf_mode, 1 ) ) { - Copy(st->mem_MA_fx, rf_mem_MA, M); + Copy( st->mem_MA_fx, rf_mem_MA, M ); } - tcx_lpc_cdk = tcxlpc_get_cdk(st->hTcxCfg->coder_type); + tcx_lpc_cdk = tcxlpc_get_cdk( st->hTcxCfg->coder_type ); /* Get the envelope corresponding to the current frame */ E_LPC_int_lpc_tcx( st->lspold_enc_fx, lsp_new, A_q ); /* Weight the envelope */ - weight_a_fx(A_q, A_q, st->gamma, M); + weight_a_fx( A_q, A_q, st->gamma, M ); /* Save the weighted envelope */ - Copy(A_q, A_w, M+1); + Copy( A_q, A_w, M + 1 ); /* Convert to xSP and xSF */ - E_LPC_a_lsp_conversion(A_q, xsp, lsp_new, M ); - E_LPC_lsp_lsf_conversion(xsp, xsf, M); + E_LPC_a_lsp_conversion( A_q, xsp, lsp_new, M ); + E_LPC_lsp_lsf_conversion( xsp, xsf, M ); /* Quantize */ - Q_lsf_tcxlpc_fx( xsf, lsf_tcx_q, lspq_ind, param_lpc, M, st->narrowBand, tcx_lpc_cdk, st-> mem_MA_fx, - st->hTcxCfg->coder_type, st->Bin_E_fx, add(Q_new, Q_SCALE-2) ); + Q_lsf_tcxlpc_fx( xsf, lsf_tcx_q, lspq_ind, param_lpc, M, st->narrowBand, tcx_lpc_cdk, st->mem_MA_fx, + st->hTcxCfg->coder_type, st->Bin_E_fx, add( Q_new, Q_SCALE - 2 ) ); /* Account for consumed bits */ nbits_lpc = TCXLPC_NUMBITS; move16(); - if (param_lpc[0]) + if ( param_lpc[0] ) { - nbits_lpc = add(nbits_lpc, TCXLPC_IND_NUMBITS); + nbits_lpc = add( nbits_lpc, TCXLPC_IND_NUMBITS ); } /* Convert quantized xSF to xSP and A */ - E_LPC_lsf_lsp_conversion(lsf_tcx_q, lsp_tcx_q, M); - E_LPC_f_lsp_a_conversion(lsp_tcx_q, A_q, M); + E_LPC_lsf_lsp_conversion( lsf_tcx_q, lsp_tcx_q, M ); + E_LPC_f_lsp_a_conversion( lsp_tcx_q, A_q, M ); } ELSE { E_LPC_int_lpc_tcx( st->lsp_old_fx, lsp_q, A_q ); } - IF (hTcxEnc->tcx_lpc_shaped_ari != 0) + IF( hTcxEnc->tcx_lpc_shaped_ari != 0 ) { - E_LPC_f_lsp_a_conversion(lspq_ind, A_q_ind, M); + E_LPC_f_lsp_a_conversion( lspq_ind, A_q_ind, M ); } /* Calculate target bits */ - target_bits = sub(sub(st->bits_frame_core, nbits_lpc), st->nb_bits_header_tcx); - if(EQ_16(st->rf_mode,1)) + target_bits = sub( sub( st->bits_frame_core, nbits_lpc ), st->nb_bits_header_tcx ); + if ( EQ_16( st->rf_mode, 1 ) ) { /* joint bit allocation for redundant frame and TBE */ /* calculate target bits for core coding */ - target_bits = sub(target_bits, st->rf_target_bits_write); + target_bits = sub( target_bits, st->rf_target_bits_write ); } - IF (EQ_16(st->mdct_sw, MODE1)) + IF( EQ_16( st->mdct_sw, MODE1 ) ) { /* Account for core signaling bits difference: bandwidth and ACELP/TCX signaling bit are replaced */ - target_bits = add(target_bits, sub(add(FrameSizeConfig[st->frame_size_index].bandwidth_bits, 1), signalling_mode1_tcx20_enc(st, 0))); + target_bits = add( target_bits, sub( add( FrameSizeConfig[st->frame_size_index].bandwidth_bits, 1 ), signalling_mode1_tcx20_enc( st, 0 ) ) ); } - ELSE if ( EQ_16(st->mdct_sw_enable, MODE2)) + ELSE if ( EQ_16( st->mdct_sw_enable, MODE2 ) ) { - target_bits = sub(target_bits, 1); + target_bits = sub( target_bits, 1 ); } - if( st->hPlcExt->enableGplc ) + if ( st->hPlcExt->enableGplc ) { - target_bits = sub(target_bits, st->hPlcExt->nBits); + target_bits = sub( target_bits, st->hPlcExt->nBits ); } /* subtract bits for TCX overlap mode (1 bit: full, 2 bits: half or no overlap) */ - target_bits = sub(target_bits,1); + target_bits = sub( target_bits, 1 ); test(); - if (EQ_16(st->hTcxCfg->tcx_curr_overlap_mode, HALF_OVERLAP)||EQ_16(st->hTcxCfg->tcx_curr_overlap_mode,MIN_OVERLAP)) + if ( EQ_16( st->hTcxCfg->tcx_curr_overlap_mode, HALF_OVERLAP ) || EQ_16( st->hTcxCfg->tcx_curr_overlap_mode, MIN_OVERLAP ) ) { - target_bits = sub(target_bits,1); + target_bits = sub( target_bits, 1 ); } - target_bits = sub(target_bits, hTcxEnc->tcxltp_bits); + target_bits = sub( target_bits, hTcxEnc->tcxltp_bits ); coder_tcx_fx( @@ -395,63 +387,60 @@ void core_encode_openloop_fx( hTcxEnc->L_frameTCX, st->hTcxCfg->tcx_coded_lines, target_bits, - (Word8)st->tcxonly, + (Word8) st->tcxonly, spectrum_long, &spectrum_long_e, param_core, st, - &hm_cfg - ); + &hm_cfg ); coder_tcx_post_fx( st, hLPDmem, st->hTcxCfg, st->synth, A_q, Aw, st->wspeech_enc, Q_new, shift ); move16(); - IF(st->hPlcExt) + IF( st->hPlcExt ) { st->hPlcExt->LPDmem = hLPDmem; - GplcTcxEncSetup_fx(st,st->hPlcExt, Q_new); + GplcTcxEncSetup_fx( st, st->hPlcExt, Q_new ); } - IF (st->enableTcxLpc) + IF( st->enableTcxLpc ) { E_LPC_lsp_unweight( lsp_tcx_q, lsp_q, lsf_q, st->inv_gamma, M ); } - IF(st->hPlcExt) + IF( st->hPlcExt ) { - encoderSideLossSimulation_fx(st,st->hPlcExt, lsf_q, stab_fac, 1, st->L_frame); + encoderSideLossSimulation_fx( st, st->hPlcExt, lsf_q, stab_fac, 1, st->L_frame ); } - } - /* Update lsp/lsf memory */ Copy( lsp_new, st->lspold_enc_fx, M ); test(); - IF ( st->enableTcxLpc && st->core != ACELP_CORE ) + IF( st->enableTcxLpc && st->core != ACELP_CORE ) { /* Update lsf/lsp memory */ - Copy(lsf_tcx_q, st->lsf_old_fx, M); - Copy(lsp_tcx_q, st->lsp_old_fx, M); + Copy( lsf_tcx_q, st->lsf_old_fx, M ); + Copy( lsp_tcx_q, st->lsp_old_fx, M ); st->envWeighted = 1; move16(); /* Update ACELP quantizer state */ - lsf_update_memory( st->narrowBand, st->lsf_old_fx, st-> mem_MA_fx, st-> mem_MA_fx, M ); + lsf_update_memory( st->narrowBand, st->lsf_old_fx, st->mem_MA_fx, st->mem_MA_fx, M ); st->pstreaklen_fx = 0; st->streaklimit_fx = 32767; /* check resonance for pitch clipping algorithm */ - gp_clip_test_lsf_fx(st->element_mode, st->lsf_old_fx, st->clip_var_fx, 0 ); - Copy(st->lsf_old_fx, st->mem_AR_fx, M); + gp_clip_test_lsf_fx( st->element_mode, st->lsf_old_fx, st->clip_var_fx, 0 ); + Copy( st->lsf_old_fx, st->mem_AR_fx, M ); } ELSE { /* Update ISP/ISF memory */ - Copy(lsf_q, st->lsf_old_fx, M); - Copy(lsp_q, st->lsp_old_fx, M); + Copy( lsf_q, st->lsf_old_fx, M ); + Copy( lsp_q, st->lsp_old_fx, M ); } /*--------------------------------------------------------------* @@ -460,93 +449,91 @@ void core_encode_openloop_fx( IF( st->Opt_DTX_ON != 0 ) { /* update CNG parameters in active frames */ - IF ( EQ_16(st->bwidth,NB)&&st->enableTcxLpc&&st->core!=ACELP_CORE) + IF( EQ_16( st->bwidth, NB ) && st->enableTcxLpc && st->core != ACELP_CORE ) { - Word16 buf[L_LP], res[L_FRAME], A[M+1], r_l[M+1], r_h[M+1], lsptmp[M], Q_r; - assert(st->L_frame==L_FRAME); - Copy(st->synth+L_FRAME-L_LP, buf, L_LP); - tmp = st->synth[L_FRAME-L_LP-1]; - E_UTIL_f_preemph2(Q_new-1, buf, st->preemph_fac, L_LP, &tmp); + Word16 buf[L_LP], res[L_FRAME], A[M + 1], r_l[M + 1], r_h[M + 1], lsptmp[M], Q_r; + assert( st->L_frame == L_FRAME ); + Copy( st->synth + L_FRAME - L_LP, buf, L_LP ); + tmp = st->synth[L_FRAME - L_LP - 1]; + E_UTIL_f_preemph2( Q_new - 1, buf, st->preemph_fac, L_LP, &tmp ); autocorr_fx( buf, M, r_h, r_l, &Q_r, L_LP, Assym_window_W16fx, 0, 0 ); - lag_wind(r_h, r_l, M, INT_FS_FX, LAGW_WEAK); - E_LPC_lev_dur(r_h, r_l, A, NULL, M, NULL); - E_LPC_a_lsp_conversion(A, lsptmp, lsp_new, M); - Residu3_fx(A, buf+L_LP-L_FRAME, res, L_FRAME, 1); + lag_wind( r_h, r_l, M, INT_FS_FX, LAGW_WEAK ); + E_LPC_lev_dur( r_h, r_l, A, NULL, M, NULL ); + E_LPC_a_lsp_conversion( A, lsptmp, lsp_new, M ); + Residu3_fx( A, buf + L_LP - L_FRAME, res, L_FRAME, 1 ); cng_params_upd_fx( lsptmp, res, st->L_frame, &hTdCngEnc->ho_circ_ptr, - hTdCngEnc->ho_ener_circ_fx, &hTdCngEnc->ho_circ_size, hTdCngEnc->ho_lsp_circ_fx, + hTdCngEnc->ho_ener_circ_fx, &hTdCngEnc->ho_circ_size, hTdCngEnc->ho_lsp_circ_fx, Q_new, ENC, NULL, &hTdCngEnc->cng_buf_cnt, hTdCngEnc->cng_exc2_buf, - hTdCngEnc->cng_Qexc_buf, hTdCngEnc->cng_brate_buf, hDtxEnc->last_active_brate ); + hTdCngEnc->cng_Qexc_buf, hTdCngEnc->cng_brate_buf, hDtxEnc->last_active_brate ); } ELSE { - cng_params_upd_fx( lsp_new, hLPDmem->old_exc+L_EXC_MEM-st->L_frame, - st->L_frame, &hTdCngEnc->ho_circ_ptr, hTdCngEnc->ho_ener_circ_fx, - &hTdCngEnc->ho_circ_size, hTdCngEnc->ho_lsp_circ_fx, Q_new, ENC, NULL, - &hTdCngEnc->cng_buf_cnt, hTdCngEnc->cng_exc2_buf, hTdCngEnc->cng_Qexc_buf, hTdCngEnc->cng_brate_buf, - hDtxEnc->last_active_brate ); + cng_params_upd_fx( lsp_new, hLPDmem->old_exc + L_EXC_MEM - st->L_frame, + st->L_frame, &hTdCngEnc->ho_circ_ptr, hTdCngEnc->ho_ener_circ_fx, + &hTdCngEnc->ho_circ_size, hTdCngEnc->ho_lsp_circ_fx, Q_new, ENC, NULL, + &hTdCngEnc->cng_buf_cnt, hTdCngEnc->cng_exc2_buf, hTdCngEnc->cng_Qexc_buf, hTdCngEnc->cng_brate_buf, + hDtxEnc->last_active_brate ); } - IF( EQ_16(st->L_frame,L_FRAME)) + IF( EQ_16( st->L_frame, L_FRAME ) ) { /* store LSPs@16k, potentially to be used in CNG@16k */ - Copy( st->lsp_old16k_fx, &(hTdCngEnc->ho_lsp_circ2_fx[(hTdCngEnc->ho_circ_ptr)*M]), M ); + Copy( st->lsp_old16k_fx, &( hTdCngEnc->ho_lsp_circ2_fx[( hTdCngEnc->ho_circ_ptr ) * M] ), M ); } /* Set 16k LSP flag for CNG buffer */ hTdCngEnc->ho_16k_lsp[hTdCngEnc->ho_circ_ptr] = 1; move16(); - if ( EQ_16(st->L_frame,L_FRAME)) + if ( EQ_16( st->L_frame, L_FRAME ) ) { hTdCngEnc->ho_16k_lsp[hTdCngEnc->ho_circ_ptr] = 0; move16(); } /* efficient DTX hangover control */ - IF ( GT_16(hTdCngEnc->burst_ho_cnt, 1)) + IF( GT_16( hTdCngEnc->burst_ho_cnt, 1 ) ) { dtx_hangover_control_fx( st, lsp_new ); } } /*--------------------------------------------------------------* - * Adaptive Bass Post-filter - *---------------------------------------------------------------*/ + * Adaptive Bass Post-filter + *---------------------------------------------------------------*/ test(); - IF (GT_16(st->core, ACELP_CORE)||(st->rate_switching_reset!=0)) + IF( GT_16( st->core, ACELP_CORE ) || ( st->rate_switching_reset != 0 ) ) { /*TCX mode: copy values*/ - set16_fx(st->mem_bpf_fx.noise_buf, 0, 2*L_FILT16k); /*TCX->no gain*/ - set16_fx(st->mem_bpf_fx.error_buf, 0, L_FILT16k); /*TCX->no gain*/ - st->bpf_gain_param=0; + set16_fx( st->mem_bpf_fx.noise_buf, 0, 2 * L_FILT16k ); /*TCX->no gain*/ + set16_fx( st->mem_bpf_fx.error_buf, 0, L_FILT16k ); /*TCX->no gain*/ + st->bpf_gain_param = 0; } - ELSE IF (st->acelp_cfg.bpf_mode > 0) + ELSE IF( st->acelp_cfg.bpf_mode > 0 ) { /*ACELP: estimate bpf parameter with delay=0*/ /*Estimate bpf parameter*/ - bass_pf_enc_fx( st->speech_enc, st->synth, st->bpf_T, st->bpf_gainT, st->L_frame, L_SUBFR, &(st->bpf_gain_param), st->acelp_cfg.bpf_mode, &(st->mem_bpf_fx) ); + bass_pf_enc_fx( st->speech_enc, st->synth, st->bpf_T, st->bpf_gainT, st->L_frame, L_SUBFR, &( st->bpf_gain_param ), st->acelp_cfg.bpf_mode, &( st->mem_bpf_fx ) ); } - - /*--------------------------------------------------------------* - * Analysis Print Out - *---------------------------------------------------------------*/ + * Analysis Print Out + *---------------------------------------------------------------*/ /*--------------------------------------------------------------* - * Generate Bitstream - *---------------------------------------------------------------*/ + * Generate Bitstream + *---------------------------------------------------------------*/ enc_prm_fx( coder_type, param_core, param_lpc, st, st->L_frame, &hm_cfg, bits_param_lpc, no_param_lpc ); /* Channel-aware mode - encode partial copy */ - IF( EQ_16(st->rf_mode,1)) + IF( EQ_16( st->rf_mode, 1 ) ) { - set16_fx(lsf_q_1st_rf, 0, M); - IF (EQ_16(st->core, ACELP_CORE)) + set16_fx( lsf_q_1st_rf, 0, M ); + IF( EQ_16( st->core, ACELP_CORE ) ) { /* convert LSPs to LP coefficients */ lsp2lsf_fx( lsp_new, lsf_uq_rf, M, st->sr_core ); @@ -554,14 +541,14 @@ void core_encode_openloop_fx( /*o: lsf_uq_rf Qx2.56*/ /* first stage VQ, 8 bits; reuse TCX high rate codebook */ - hRF->rf_indx_lsf[0][0] = vlpc_1st_cod_fx(lsf_uq_rf, lsf_q_1st_rf, w_rf, st->rf_mode); + hRF->rf_indx_lsf[0][0] = vlpc_1st_cod_fx( lsf_uq_rf, lsf_q_1st_rf, w_rf, st->rf_mode ); /*v_sub(lsf_uq_rf, lsf_q_1st_rf, lsf_q_d_rf, M);*/ - FOR (i=0; irf_indx_lsf[0][1]); + closest_centroid_rf( lsf_q_d_rf, w_rf, lsf_q_diff_cb_8b_rf, ( 1 << 8 ), M, &hRF->rf_indx_lsf[0][1] ); /*i: lsf_q_d_rf in Q6 */ /*o: quantization index Q0 */ /* quantized lsf from two stages */ /*v_add(lsf_q_1st_rf, lsf_q_diff_cb_8b_rf + M * st->rf_indx_lsf[0][1], lsf_q_rf, M);*/ - FOR (i=0; irf_indx_lsf[0][1]]; /*tmp = quantized lsf_q_d_rf in Q6*/ - tmp = shr(mult_r(tmp,20972),4); /* bring lsf_q_d_rf to Qx2.56 for addition */ - lsf_q_rf[i] = add(lsf_q_1st_rf[i], tmp); + tmp = lsf_q_diff_cb_8b_rf[i + M * hRF->rf_indx_lsf[0][1]]; /*tmp = quantized lsf_q_d_rf in Q6*/ + tmp = shr( mult_r( tmp, 20972 ), 4 ); /* bring lsf_q_d_rf to Qx2.56 for addition */ + lsf_q_rf[i] = add( lsf_q_1st_rf[i], tmp ); } - v_sort( lsf_q_rf, 0, M-1 ); + v_sort( lsf_q_rf, 0, M - 1 ); reorder_lsf_fx( lsf_q_rf, LSF_GAP_FX, M, st->sr_core ); } ELSE @@ -592,7 +579,7 @@ void core_encode_openloop_fx( rf_tcx_lpc_cdk = tcxlpc_get_cdk( GENERIC ); /* Quantize */ - Q_lsf_tcxlpc_fx( xsf, lsf_tcx_q, lspq_ind, param_lpc, M, st->narrowBand, rf_tcx_lpc_cdk, rf_mem_MA, GENERIC, st->Bin_E_fx, add(Q_new, Q_SCALE-2) ); + Q_lsf_tcxlpc_fx( xsf, lsf_tcx_q, lspq_ind, param_lpc, M, st->narrowBand, rf_tcx_lpc_cdk, rf_mem_MA, GENERIC, st->Bin_E_fx, add( Q_new, Q_SCALE - 2 ) ); /* VQ, 5+4+4 bits; reuse TCX low rate codebook */ hRF->rf_indx_lsf[0][0] = param_lpc[1]; @@ -600,7 +587,7 @@ void core_encode_openloop_fx( hRF->rf_indx_lsf[0][2] = param_lpc[3]; } - IF (EQ_16(st->core, ACELP_CORE)) + IF( EQ_16( st->core, ACELP_CORE ) ) { /* current n-th ACELP frame and its corresponding partial copy */ @@ -623,11 +610,11 @@ void core_encode_openloop_fx( hRF->rf_indx_frametype[0] = hRF->rf_frame_type; hRF->rf_targetbits_buff[0] = hRF->rf_target_bits; - IF( NE_16(hRF->rf_frame_type,RF_NO_DATA)) + IF( NE_16( hRF->rf_frame_type, RF_NO_DATA ) ) { /* coder_acelp_rf_fx does the partial copy encoding based on the rf frame type chosen for the RF encoding */ - coder_acelp_rf_fx(&(hRF->acelp_cfg_rf), coder_type, Aw, Aq_rf, st->speech_enc_pe, st->voicing_fx, st->pitch_fx, - stab_fac_rf, st, hRF->rf_target_bits, hRF->rf_frame_type, exc_rf, syn_rf, Q_new, shift); + coder_acelp_rf_fx( &( hRF->acelp_cfg_rf ), coder_type, Aw, Aq_rf, st->speech_enc_pe, st->voicing_fx, st->pitch_fx, + stab_fac_rf, st, hRF->rf_target_bits, hRF->rf_frame_type, exc_rf, syn_rf, Q_new, shift ); } } ELSE @@ -638,16 +625,16 @@ void core_encode_openloop_fx( move16(); /* attenuate somewhat the gain for onset when the correlation with previous frame is too low: avoid preecho */ - tmp = mult_r(shl(hRF->rf_gain_tcx[1], 1), 26214/*0.8f Q15*/); + tmp = mult_r( shl( hRF->rf_gain_tcx[1], 1 ), 26214 /*0.8f Q15*/ ); test(); test(); - IF( (hRF->rf_gain_tcx[1] != 0) && (GT_16(hRF->rf_gain_tcx[0], tmp))&&(LE_16(hTcxEnc->tcxltp_gain,6554/*0.2 Q15*/))) + IF( ( hRF->rf_gain_tcx[1] != 0 ) && ( GT_16( hRF->rf_gain_tcx[0], tmp ) ) && ( LE_16( hTcxEnc->tcxltp_gain, 6554 /*0.2 Q15*/ ) ) ) { hRF->rf_gain_tcx[0] = tmp; move16(); - if( GT_16(tmp, 127)) + if ( GT_16( tmp, 127 ) ) { hRF->rf_gain_tcx[0] = 127; move16(); @@ -666,26 +653,25 @@ void core_encode_openloop_fx( test(); test(); IF( - (EQ_16(st->core, TCX_20_CORE) )/*(st->core == TCX_20_CORE)*/ - && (EQ_16(st->last_core,TCX_20_CORE) )/*&&(st->last_core == TCX_20_CORE)*/ - && (EQ_16(hRF->rf_second_last_core, TCX_20_CORE) )/*&& (st->rf_second_last_core == TCX_20_CORE)*/ - && ( (LE_16(hTcxEnc->tcxltp_pitch_int, shr(st->L_frame, 1)) ) || ( LE_16(hTcxEnc->tcxltp_gain, 13107/*0.4f Q15*/) ) )/*&& ((st->tcxltp_pitch_int <= 0.5f*st->L_frame) || ( st->tcxltp_gain <= 0.4f))*/ - && (EQ_16(hTcxEnc->tcxltp_pitch_int, hRF->rf_tcxltp_pitch_int_past) )/*&& (st->tcxltp_pitch_int == st->rf_tcxltp_pitch_int_past)*/ - && (hRF->rf_last_tns_active == 0)/*!st->rf_last_tns_active*/ - && (hRF->rf_second_last_tns_active == 0)/*!st->rf_second_last_tns_active*/ - && ( (st->hTcxCfg->fIsTNSAllowed & hTcxEnc->fUseTns_fx[0]) == 0)/*!(st->hTcxCfg->fIsTNSAllowed & st->fUseTns[0])*/ + ( EQ_16( st->core, TCX_20_CORE ) ) /*(st->core == TCX_20_CORE)*/ + && ( EQ_16( st->last_core, TCX_20_CORE ) ) /*&&(st->last_core == TCX_20_CORE)*/ + && ( EQ_16( hRF->rf_second_last_core, TCX_20_CORE ) ) /*&& (st->rf_second_last_core == TCX_20_CORE)*/ + && ( ( LE_16( hTcxEnc->tcxltp_pitch_int, shr( st->L_frame, 1 ) ) ) || ( LE_16( hTcxEnc->tcxltp_gain, 13107 /*0.4f Q15*/ ) ) ) /*&& ((st->tcxltp_pitch_int <= 0.5f*st->L_frame) || ( st->tcxltp_gain <= 0.4f))*/ + && ( EQ_16( hTcxEnc->tcxltp_pitch_int, hRF->rf_tcxltp_pitch_int_past ) ) /*&& (st->tcxltp_pitch_int == st->rf_tcxltp_pitch_int_past)*/ + && ( hRF->rf_last_tns_active == 0 ) /*!st->rf_last_tns_active*/ + && ( hRF->rf_second_last_tns_active == 0 ) /*!st->rf_second_last_tns_active*/ + && ( ( st->hTcxCfg->fIsTNSAllowed & hTcxEnc->fUseTns_fx[0] ) == 0 ) /*!(st->hTcxCfg->fIsTNSAllowed & st->fUseTns[0])*/ ) { rf_PLC_Mode = 1; move16(); } - ELSE IF (st->last_core != 0) + ELSE IF( st->last_core != 0 ) { test(); test(); test(); - IF ( ((LE_16(st->clas, UNVOICED_TRANSITION))||(LE_16(st->last_clas,UNVOICED_TRANSITION))||(LE_16(hTcxEnc->tcxltp_gain,13107/*0.4f Q15*/))) - && NE_16(st->last_core, -1) ) + IF( ( ( LE_16( st->clas, UNVOICED_TRANSITION ) ) || ( LE_16( st->last_clas, UNVOICED_TRANSITION ) ) || ( LE_16( hTcxEnc->tcxltp_gain, 13107 /*0.4f Q15*/ ) ) ) && NE_16( st->last_core, -1 ) ) { rf_PLC_Mode = st->last_core; move16(); @@ -698,9 +684,8 @@ void core_encode_openloop_fx( test(); test(); IF( rf_PLC_Mode == 0 && hRF->rf_gain_tcx[1] != 0 && - ( (st->transientDetection.transientDetector.bIsAttackPresent != 0 && LT_16(hRF->rf_gain_tcx[0], mult_r(hRF->rf_gain_tcx[1], 31785/*0.97f Q15*/)) ) || - LT_16(hRF->rf_gain_tcx[0], mult_r(hRF->rf_gain_tcx[1], 29491/*0.90f Q15*/)) ) - ) + ( ( st->transientDetection.transientDetector.bIsAttackPresent != 0 && LT_16( hRF->rf_gain_tcx[0], mult_r( hRF->rf_gain_tcx[1], 31785 /*0.97f Q15*/ ) ) ) || + LT_16( hRF->rf_gain_tcx[0], mult_r( hRF->rf_gain_tcx[1], 29491 /*0.90f Q15*/ ) ) ) ) { TD_mode = 0; } @@ -710,13 +695,13 @@ void core_encode_openloop_fx( } /* updates */ - hRF->rf_tcxltp_pitch_int_past = hTcxEnc->tcxltp_pitch_int; + hRF->rf_tcxltp_pitch_int_past = hTcxEnc->tcxltp_pitch_int; move16(); hRF->rf_second_last_tns_active = hRF->rf_last_tns_active; move16(); - hRF->rf_last_tns_active = (st->hTcxCfg->fIsTNSAllowed & hTcxEnc->fUseTns_fx[0]); + hRF->rf_last_tns_active = ( st->hTcxCfg->fIsTNSAllowed & hTcxEnc->fUseTns_fx[0] ); move16(); - hRF->rf_second_last_core = st->last_core; + hRF->rf_second_last_core = st->last_core; move16(); hRF->rf_tcxltp_param[0] = hTcxEnc->tcxltp_param[1]; @@ -724,38 +709,36 @@ void core_encode_openloop_fx( /* Configure partial copy estimation of the current n-th frame to be packed in future with n+fec_offset frame */ /* o: rf_frame_type, o: rf_target_bits */ - BITS_ALLOC_TCX_config_rf( &hRF->rf_frame_type, &hRF->rf_target_bits, rf_PLC_Mode, coder_type, st->last_core, TD_mode); + BITS_ALLOC_TCX_config_rf( &hRF->rf_frame_type, &hRF->rf_target_bits, rf_PLC_Mode, coder_type, st->last_core, TD_mode ); /* RF frame type in the buffer */ hRF->rf_indx_frametype[0] = hRF->rf_frame_type; move16(); hRF->rf_targetbits_buff[0] = hRF->rf_target_bits; move16(); - } } - return; } /*-------------------------------------------------------------------* -* closest_centroid_rf() -* -* Determine a set of closest VQ centroids for a given input -*-------------------------------------------------------------------*/ + * closest_centroid_rf() + * + * Determine a set of closest VQ centroids for a given input + *-------------------------------------------------------------------*/ static void closest_centroid_rf( - const Word16 *data, /* i : input data Qx */ - const Word16 *weights, /* i : weights */ - const Word16 *quantizer, /* i : quantizer table Qx */ - const Word16 centroids, /* i : number of centroids */ - const Word16 length, /* i : dimension of quantiser */ + const Word16 *data, /* i : input data Qx */ + const Word16 *weights, /* i : weights */ + const Word16 *quantizer, /* i : quantizer table Qx */ + const Word16 centroids, /* i : number of centroids */ + const Word16 length, /* i : dimension of quantiser */ Word16 *ind_vec /* o : list of best match indice vectors */ ) { - Word16 i,j; + Word16 i, j; Word16 tmp, tmpL; Word64 werr_64; Word32 L_tmp, best_werr, werr; @@ -773,25 +756,25 @@ static void closest_centroid_rf( werr_64 = 0; move64(); - tmpL = i_mult2(i, length); + tmpL = i_mult2( i, length ); FOR( j = 0; j < length; j++ ) { #ifdef BASOP_NOGLOB tmp = sub_o( data[j], quantizer[tmpL + j], &Overflow ); - L_tmp = L_mult_o(tmp, tmp, &Overflow); + L_tmp = L_mult_o( tmp, tmp, &Overflow ); #else tmp = sub( data[j], quantizer[tmpL + j] ); - L_tmp = L_mult(tmp, tmp); + L_tmp = L_mult( tmp, tmp ); #endif werr_64 = W_mac_32_16( werr_64, L_tmp, weights[j] ); - } - werr = W_sat_m( werr_64); - if( LT_32( werr, best_werr) ) + } + werr = W_sat_m( werr_64 ); + if ( LT_32( werr, best_werr ) ) { ind_vec[0] = i; - move16(); + move16(); } - best_werr = L_min( best_werr, werr ); + best_werr = L_min( best_werr, werr ); } return; @@ -799,23 +782,22 @@ static void closest_centroid_rf( void core_acelp_tcx20_switching_fx( - Encoder_State *st, /* i/o: encoder state structure */ - Word16 non_staX, /* i : unbound non-stationarity for sp/mu clas */ - Word16 *pitch_fr, /* i/o: fraction pitch values */ - Word16 *voicing_fr, /* i/o: fractional voicing values */ - const Word16 currFlatness, /* i : flatness */ - const Word16 lsp_mid[M], /* i : LSPs at the middle of the frame */ - const Word16 stab_fac, /* i : LP filter stability */ + Encoder_State *st, /* i/o: encoder state structure */ + Word16 non_staX, /* i : unbound non-stationarity for sp/mu clas */ + Word16 *pitch_fr, /* i/o: fraction pitch values */ + Word16 *voicing_fr, /* i/o: fractional voicing values */ + const Word16 currFlatness, /* i : flatness */ + const Word16 lsp_mid[M], /* i : LSPs at the middle of the frame */ + const Word16 stab_fac, /* i : LP filter stability */ Word16 Q_new, - Word16 shift -) + Word16 shift ) { Word16 i, j, iter; - Word16 xn_buf[L_MDCT_OVLP_MAX+L_FRAME_PLUS+L_MDCT_OVLP_MAX]; - Word16 Ap[M+1]; + Word16 xn_buf[L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX]; + Word16 Ap[M + 1]; Word16 gainlpc[FDNS_NPTS]; Word16 gainlpc_e[FDNS_NPTS]; - Word32 en[N_MAX/4]; + Word32 en[N_MAX / 4]; Word32 ener, tmp32, fac, offset; Word32 offset_tcx; Word16 ener_e; @@ -831,7 +813,7 @@ void core_acelp_tcx20_switching_fx( Word16 L_frame_4; Word16 i2, T0; Word32 gain, signal, noise; - Word16 A_q_tcx[(NB_SUBFR16k+1)*(M+1)]; + Word16 A_q_tcx[( NB_SUBFR16k + 1 ) * ( M + 1 )]; Word16 snr_tcx, snr_acelp, dsnr; TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; SP_MUS_CLAS_HANDLE hSpMusClas = st->hSpMusClas; @@ -845,63 +827,62 @@ void core_acelp_tcx20_switching_fx( tmp16 = st->pitch_fx[i]; move16(); /* check minimum pitch for quantization */ - if (LT_16(tmp16, PIT_MIN_SHORTER)) + if ( LT_16( tmp16, PIT_MIN_SHORTER ) ) { - tmp16 = shl(tmp16, 1); + tmp16 = shl( tmp16, 1 ); } /* convert pitch values to 16kHz domain */ - s = mult_r(tmp16, 8192/*0.25f Q15*/); - if (EQ_16(st->L_frame, L_FRAME16k)) + s = mult_r( tmp16, 8192 /*0.25f Q15*/ ); + if ( EQ_16( st->L_frame, L_FRAME16k ) ) { /*pitch[i] = (short)(pitch[i] * 1.25f + 0.5f);*/ - tmp16 = add(tmp16, s); + tmp16 = add( tmp16, s ); } st->pitch_fx[i] = tmp16; move16(); } - IF (st->narrowBand != 0) + IF( st->narrowBand != 0 ) { pitchDoubling_det_fx( st->wspeech_enc, st->pitch_fx, pitch_fr, voicing_fr ); } - E_LPC_f_lsp_a_conversion(lsp_mid, A_q_tcx, M); + E_LPC_f_lsp_a_conversion( lsp_mid, A_q_tcx, M ); /* LTP */ - tcx_ltp_encode_fx(hTcxEnc->tcxltp, - (Word8)st->tcxonly, - TCX_20, - st->L_frame, - L_SUBFR, - st->speech_enc + st->encoderLookahead_enc, - hTcxEnc->speech_ltp + st->encoderLookahead_enc, - st->wspeech_enc + st->encoderLookahead_enc, - st->pitch_fx[1], - hTcxEnc->tcxltp_param, - &hTcxEnc->tcxltp_bits, - &hTcxEnc->tcxltp_pitch_int, - &hTcxEnc->tcxltp_pitch_fr, - &hTcxEnc->tcxltp_gain, - &hTcxEnc->tcxltp_pitch_int_past, - &hTcxEnc->tcxltp_pitch_fr_past, - &hTcxEnc->tcxltp_gain_past, - &hTcxEnc->tcxltp_norm_corr_past, - st->last_core, - st->pit_min, - st->pit_fr1, - st->pit_fr2, - st->pit_max, - st->pit_res_max, - &st->transientDetection, - 0, - A_q_tcx, - M - ); + tcx_ltp_encode_fx( hTcxEnc->tcxltp, + (Word8) st->tcxonly, + TCX_20, + st->L_frame, + L_SUBFR, + st->speech_enc + st->encoderLookahead_enc, + hTcxEnc->speech_ltp + st->encoderLookahead_enc, + st->wspeech_enc + st->encoderLookahead_enc, + st->pitch_fx[1], + hTcxEnc->tcxltp_param, + &hTcxEnc->tcxltp_bits, + &hTcxEnc->tcxltp_pitch_int, + &hTcxEnc->tcxltp_pitch_fr, + &hTcxEnc->tcxltp_gain, + &hTcxEnc->tcxltp_pitch_int_past, + &hTcxEnc->tcxltp_pitch_fr_past, + &hTcxEnc->tcxltp_gain_past, + &hTcxEnc->tcxltp_norm_corr_past, + st->last_core, + st->pit_min, + st->pit_fr1, + st->pit_fr2, + st->pit_max, + st->pit_res_max, + &st->transientDetection, + 0, + A_q_tcx, + M ); /* Force TCX when TCX20 in MODE1 is selected */ - IF ( EQ_16(st->mdct_sw, MODE1)) + IF( EQ_16( st->mdct_sw, MODE1 ) ) { st->core = TCX_20_CORE; move16(); @@ -909,240 +890,245 @@ void core_acelp_tcx20_switching_fx( ELSE { /*--------------------------------------------------------------* - * Estimate TCX SNR - *---------------------------------------------------------------*/ + * Estimate TCX SNR + *---------------------------------------------------------------*/ L_frame = st->L_frame; move16(); tcx_offset = st->hTcxCfg->tcx_offset; move16(); - target = L_add(0x14C315C, 0); /* 1000.f * log2(10)/10 (15Q16) */ + target = L_add( 0x14C315C, 0 ); /* 1000.f * log2(10)/10 (15Q16) */ test(); - if (EQ_32(st->sr_core, INT_FS_16k)||EQ_32(st->sr_core, INT_FS_12k8)) + if ( EQ_32( st->sr_core, INT_FS_16k ) || EQ_32( st->sr_core, INT_FS_12k8 ) ) { - target = L_add(0x11A5D28, 0); /* 850.f * log2(10)/10 (15Q16) */ + target = L_add( 0x11A5D28, 0 ); /* 850.f * log2(10)/10 (15Q16) */ } if ( st->narrowBand != 0 ) { - target = L_add(0xA618AE, 0); /* 500f * log2(10)/10 (15Q16) */ + target = L_add( 0xA618AE, 0 ); /* 500f * log2(10)/10 (15Q16) */ } - IF (st->last_core == ACELP_CORE) + IF( st->last_core == ACELP_CORE ) { - L_frame = add(L_frame, tcx_offset); - tcx_offset = s_min(st->hTcxCfg->lfacNext, 0); - L_frame = sub(L_frame, tcx_offset); + L_frame = add( L_frame, tcx_offset ); + tcx_offset = s_min( st->hTcxCfg->lfacNext, 0 ); + L_frame = sub( L_frame, tcx_offset ); } - L_frame_4 = shr(L_frame, 2); + L_frame_4 = shr( L_frame, 2 ); overlap = st->hTcxCfg->tcx_mdct_window_delay; move16(); - Copy(hTcxEnc->speech_ltp + sub(tcx_offset, shr(overlap, 1)), xn_buf, add(L_frame, overlap)); + Copy( hTcxEnc->speech_ltp + sub( tcx_offset, shr( overlap, 1 ) ), xn_buf, add( L_frame, overlap ) ); - tmp16 = shr(overlap, 1); - IF (EQ_16(st->last_core,ACELP_CORE)) + tmp16 = shr( overlap, 1 ); + IF( EQ_16( st->last_core, ACELP_CORE ) ) { - IF (tcx_offset < 0) + IF( tcx_offset < 0 ) { - set16_fx(xn_buf, 0, tmp16); + set16_fx( xn_buf, 0, tmp16 ); } } ELSE { - FOR (i = 0; i < tmp16; i++) + FOR( i = 0; i < tmp16; i++ ) { - xn_buf[i] = mult_r(xn_buf[i], st->hTcxCfg->tcx_mdct_window[i].v.im); + xn_buf[i] = mult_r( xn_buf[i], st->hTcxCfg->tcx_mdct_window[i].v.im ); move16(); } - FOR ( ; i < overlap; i++) + FOR( ; i < overlap; i++ ) { - xn_buf[i] = mult_r(xn_buf[i], st->hTcxCfg->tcx_mdct_window[overlap-1-i].v.re); + xn_buf[i] = mult_r( xn_buf[i], st->hTcxCfg->tcx_mdct_window[overlap - 1 - i].v.re ); move16(); } } - FOR (i = 0; i < tmp16; i++) + FOR( i = 0; i < tmp16; i++ ) { - xn_buf[L_frame+i] = mult_r(xn_buf[L_frame+i], st->hTcxCfg->tcx_mdct_window[i].v.re); + xn_buf[L_frame + i] = mult_r( xn_buf[L_frame + i], st->hTcxCfg->tcx_mdct_window[i].v.re ); move16(); } - FOR ( ; i < overlap; i++) + FOR( ; i < overlap; i++ ) { - xn_buf[L_frame+i] = mult_r(xn_buf[L_frame+i], st->hTcxCfg->tcx_mdct_window[overlap-1-i].v.im); + xn_buf[L_frame + i] = mult_r( xn_buf[L_frame + i], st->hTcxCfg->tcx_mdct_window[overlap - 1 - i].v.im ); move16(); } x_e = 16; move16(); - TCX_MDCT(xn_buf, x, &x_e, overlap, sub(L_frame, overlap), overlap, st->element_mode); - tmp16 = mult_r(shl(L_frame, 5), 29309/*16*0.0559017 Q15*/); /* L_frame / sqrt(2*NORM_MDCT_FACTOR); Q9 */ - FOR (i = 0; i < L_frame; i++) + TCX_MDCT( xn_buf, x, &x_e, overlap, sub( L_frame, overlap ), overlap, st->element_mode ); + tmp16 = mult_r( shl( L_frame, 5 ), 29309 /*16*0.0559017 Q15*/ ); /* L_frame / sqrt(2*NORM_MDCT_FACTOR); Q9 */ + FOR( i = 0; i < L_frame; i++ ) { - x[i] = Mpy_32_16_1(x[i], tmp16); + x[i] = Mpy_32_16_1( x[i], tmp16 ); move32(); } - x_e = add(x_e, 6); + x_e = add( x_e, 6 ); - weight_a_fx(A_q_tcx, Ap, st->gamma, M); + weight_a_fx( A_q_tcx, Ap, st->gamma, M ); - lpc2mdct(Ap, M, gainlpc, gainlpc_e, NULL, NULL, FDNS_NPTS, 0); + lpc2mdct( Ap, M, gainlpc, gainlpc_e, NULL, NULL, FDNS_NPTS, 0 ); - mdct_shaping(x, L_frame, gainlpc, gainlpc_e); + mdct_shaping( x, L_frame, gainlpc, gainlpc_e ); - IF ( st->narrowBand ) + IF( st->narrowBand ) { j = mult( L_frame, 20480 ); - set32_fx(&x[j], 0, sub(L_frame, j)); + set32_fx( &x[j], 0, sub( L_frame, j ) ); } - FOR (i = 0; i < L_frame_4; i++) + FOR( i = 0; i < L_frame_4; i++ ) { /* normalization */ s = 31; move16(); - tmp16 = norm_l(x[0]); - if (x[0] != 0) s = s_min(s, tmp16); + tmp16 = norm_l( x[0] ); + if ( x[0] != 0 ) + s = s_min( s, tmp16 ); - tmp16 = norm_l(x[1]); - if (x[1] != 0) s = s_min(s, tmp16); + tmp16 = norm_l( x[1] ); + if ( x[1] != 0 ) + s = s_min( s, tmp16 ); - tmp16 = norm_l(x[2]); - if (x[2] != 0) s = s_min(s, tmp16); + tmp16 = norm_l( x[2] ); + if ( x[2] != 0 ) + s = s_min( s, tmp16 ); - tmp16 = norm_l(x[3]); - if (x[3] != 0) s = s_min(s, tmp16); + tmp16 = norm_l( x[3] ); + if ( x[3] != 0 ) + s = s_min( s, tmp16 ); - s = sub(s, 2); /* 2 bits headroom */ + s = sub( s, 2 ); /* 2 bits headroom */ /* calc quadruple energy */ - ener = L_deposit_l(1); + ener = L_deposit_l( 1 ); - tmp16 = extract_h(L_shl(x[0], s)); - ener = L_mac(ener, tmp16, tmp16); + tmp16 = extract_h( L_shl( x[0], s ) ); + ener = L_mac( ener, tmp16, tmp16 ); - tmp16 = extract_h(L_shl(x[1], s)); - ener = L_mac(ener, tmp16, tmp16); + tmp16 = extract_h( L_shl( x[1], s ) ); + ener = L_mac( ener, tmp16, tmp16 ); - tmp16 = extract_h(L_shl(x[2], s)); - ener = L_mac(ener, tmp16, tmp16); + tmp16 = extract_h( L_shl( x[2], s ) ); + ener = L_mac( ener, tmp16, tmp16 ); - tmp16 = extract_h(L_shl(x[3], s)); - ener = L_mac(ener, tmp16, tmp16); + tmp16 = extract_h( L_shl( x[3], s ) ); + ener = L_mac( ener, tmp16, tmp16 ); - s = shl(sub(x_e, s), 1); + s = shl( sub( x_e, s ), 1 ); - tmp32 = L_add(BASOP_Util_Log2(ener), L_shl(L_deposit_l(s), 25)); /* log2, 6Q25 */ - tmp32 = L_shr(tmp32, 9); /* 15Q16 */ - en[i] = L_add(tmp32, 0x2FD5F); /* 0x2FD5F -> 9.f * log2(10)/10 (15Q16) */ move32(); + tmp32 = L_add( BASOP_Util_Log2( ener ), L_shl( L_deposit_l( s ), 25 ) ); /* log2, 6Q25 */ + tmp32 = L_shr( tmp32, 9 ); /* 15Q16 */ + en[i] = L_add( tmp32, 0x2FD5F ); /* 0x2FD5F -> 9.f * log2(10)/10 (15Q16) */ + move32(); x += 4; } - fac = L_add(0x2A854B, 0); /* 0x2A854B -> 128.f * log2(10)/10 (15Q16) */ - offset = L_add(fac, 0); + fac = L_add( 0x2A854B, 0 ); /* 0x2A854B -> 128.f * log2(10)/10 (15Q16) */ + offset = L_add( fac, 0 ); - FOR (iter = 0; iter < 10; iter++) + FOR( iter = 0; iter < 10; iter++ ) { - fac = L_shr(fac, 1); - offset = L_sub(offset, fac); - ener = L_deposit_l(0); + fac = L_shr( fac, 1 ); + offset = L_sub( offset, fac ); + ener = L_deposit_l( 0 ); - assert(L_frame_4 % 4 == 0); - FOR (i=0; i < L_frame_4; i+=4) + assert( L_frame_4 % 4 == 0 ); + FOR( i = 0; i < L_frame_4; i += 4 ) { - tmp32 = L_sub(en[i], offset); + tmp32 = L_sub( en[i], offset ); - if (GT_32(tmp32, 0xFF20)) /* 0xFF20 -> 3.f * log2(10)/10 */ + if ( GT_32( tmp32, 0xFF20 ) ) /* 0xFF20 -> 3.f * log2(10)/10 */ { - ener = L_add(ener, tmp32); + ener = L_add( ener, tmp32 ); } - tmp32 = L_sub(en[i+1], offset); + tmp32 = L_sub( en[i + 1], offset ); - if (GT_32(tmp32, 0xFF20)) /* 0xFF20 -> 3.f * log2(10)/10 */ + if ( GT_32( tmp32, 0xFF20 ) ) /* 0xFF20 -> 3.f * log2(10)/10 */ { - ener = L_add(ener, tmp32); + ener = L_add( ener, tmp32 ); } - tmp32 = L_sub(en[i+2], offset); + tmp32 = L_sub( en[i + 2], offset ); - if (GT_32(tmp32, 0xFF20)) /* 0xFF20 -> 3.f * log2(10)/10 */ + if ( GT_32( tmp32, 0xFF20 ) ) /* 0xFF20 -> 3.f * log2(10)/10 */ { - ener = L_add(ener, tmp32); + ener = L_add( ener, tmp32 ); } - tmp32 = L_sub(en[i+3], offset); + tmp32 = L_sub( en[i + 3], offset ); - if (GT_32(tmp32, 0xFF20)) /* 0xFF20 -> 3.f * log2(10)/10 */ + if ( GT_32( tmp32, 0xFF20 ) ) /* 0xFF20 -> 3.f * log2(10)/10 */ { - ener = L_add(ener, tmp32); + ener = L_add( ener, tmp32 ); } - IF (GT_32(ener, target)) + IF( GT_32( ener, target ) ) { - offset = L_add(offset, fac); + offset = L_add( offset, fac ); BREAK; } } } - if (LE_32(offset, 0xAA153)) /* 0xAA153 -> 32.f * log2(10)/10 */ + if ( LE_32( offset, 0xAA153 ) ) /* 0xAA153 -> 32.f * log2(10)/10 */ { - offset = L_add(0xFFD57AB5, 0); /* 0xFFD57AB5 -> -128.f * log2(10)/10; */ + offset = L_add( 0xFFD57AB5, 0 ); /* 0xFFD57AB5 -> -128.f * log2(10)/10; */ } offset_tcx = offset; move32(); - s = add(extract_h(offset), 1); - offset = L_sub(L_and(offset, 0xFFFF), 0x10000); - ener = BASOP_Util_InvLog2(L_shl(offset, 9)); + s = add( extract_h( offset ), 1 ); + offset = L_sub( L_and( offset, 0xFFFF ), 0x10000 ); + ener = BASOP_Util_InvLog2( L_shl( offset, 9 ) ); - ener = Mpy_32_16_1(Mpy_32_16_1(ener, 0x78AE), getInvFrameLen(L_frame)); /* 0x78AE -> sqrt(2)/12 (Q18) */ - ener_e = sub(s, 9); + ener = Mpy_32_16_1( Mpy_32_16_1( ener, 0x78AE ), getInvFrameLen( L_frame ) ); /* 0x78AE -> sqrt(2)/12 (Q18) */ + ener_e = sub( s, 9 ); - tcx_snr = L_deposit_l(0); + tcx_snr = L_deposit_l( 0 ); - FOR (i = 0; i < st->L_frame; i += L_SUBFR) + FOR( i = 0; i < st->L_frame; i += L_SUBFR ) { - tmp32 = L_deposit_l(0); + tmp32 = L_deposit_l( 0 ); - FOR (j = 0; j < L_SUBFR; j++) + FOR( j = 0; j < L_SUBFR; j++ ) { #ifdef BASOP_NOGLOB - tmp32 = L_mac0_o(tmp32, st->wspeech_enc[i+j], st->wspeech_enc[i+j], &Overflow); + tmp32 = L_mac0_o( tmp32, st->wspeech_enc[i + j], st->wspeech_enc[i + j], &Overflow ); #else - tmp32 = L_mac0(tmp32, st->wspeech_enc[i+j], st->wspeech_enc[i+j]); + tmp32 = L_mac0( tmp32, st->wspeech_enc[i + j], st->wspeech_enc[i + j] ); #endif } - tmp32 = L_shr(BASOP_Util_Log2(tmp32), 9); /* 15Q16 */ - tmp32 = L_add(tmp32, L_sub( 0x1F0000, L_shl( L_deposit_h( add( Q_new, sub( shift, 1 ) ) ), 1 ) ) ); /* wspeech_enc scaling */ - if (LT_32(tmp32, (Word32)0xFFEC1185)) + tmp32 = L_shr( BASOP_Util_Log2( tmp32 ), 9 ); /* 15Q16 */ + tmp32 = L_add( tmp32, L_sub( 0x1F0000, L_shl( L_deposit_h( add( Q_new, sub( shift, 1 ) ) ), 1 ) ) ); /* wspeech_enc scaling */ + if ( LT_32( tmp32, (Word32) 0xFFEC1185 ) ) { tmp32 = 0xFFEC1185; /* 0xFFEC1185 -> log2(1e-6) in 15Q16 */ - move32(); + move32(); } - tcx_snr = L_add(tcx_snr, tmp32); + tcx_snr = L_add( tcx_snr, tmp32 ); } - tcx_snr = Mpy_32_16_1(tcx_snr, div_s(L_SUBFR, st->L_frame)); - tcx_snr = L_sub(tcx_snr, L_shr(BASOP_Util_Log2(Mpy_32_16_1(ener, L_SUBFR)), 9)); - tcx_snr = L_sub(tcx_snr, L_deposit_h(add(ener_e, 15))); - tcx_snr = L_shl(Mpy_32_16_1(tcx_snr, 0x6054), 2); /* 0x6054 -> 10/log2(10) (2Q13) */ + tcx_snr = Mpy_32_16_1( tcx_snr, div_s( L_SUBFR, st->L_frame ) ); + tcx_snr = L_sub( tcx_snr, L_shr( BASOP_Util_Log2( Mpy_32_16_1( ener, L_SUBFR ) ), 9 ) ); + tcx_snr = L_sub( tcx_snr, L_deposit_h( add( ener_e, 15 ) ) ); + tcx_snr = L_shl( Mpy_32_16_1( tcx_snr, 0x6054 ), 2 ); /* 0x6054 -> 10/log2(10) (2Q13) */ BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB - snr_tcx = round_fx_o(L_shl_o(tcx_snr, 8, &Overflow), &Overflow); /* 7Q8 */ -#else /* BASOP_NOGLOB */ - snr_tcx = round_fx(L_shl(tcx_snr, 8)); /* 7Q8 */ -#endif /* BASOP_NOGLOB */ + snr_tcx = round_fx_o( L_shl_o( tcx_snr, 8, &Overflow ), &Overflow ); /* 7Q8 */ +#else /* BASOP_NOGLOB */ + snr_tcx = round_fx( L_shl( tcx_snr, 8 ) ); /* 7Q8 */ +#endif /* BASOP_NOGLOB */ BASOP_SATURATE_WARNING_ON_EVS /*--------------------------------------------------------------* - * Estimate ACELP SNR - *---------------------------------------------------------------*/ + * Estimate ACELP SNR + *---------------------------------------------------------------*/ - tmp32 = L_deposit_l(0); + tmp32 = L_deposit_l( 0 ); /* snr_acelp = 1/nSubFrames + sum( 10*log10( signal / (noise*0.055) ) @@ -1151,157 +1137,175 @@ void core_acelp_tcx20_switching_fx( i2 = 0; move16(); - FOR (i = 0; i < st->L_frame; i += L_SUBFR) + FOR( i = 0; i < st->L_frame; i += L_SUBFR ) { - IF ( EQ_32( st->sr_core, INT_FS_16k)) + IF( EQ_32( st->sr_core, INT_FS_16k ) ) { - T0 = shr(add( add(pitch_fr[mult_r(i2,26214/*(float)L_FRAME/(float)L_FRAME16k Q15*/)], shr(pitch_fr[mult_r(i2,26214/*(float)L_FRAME/(float)L_FRAME16k Q15*/)], 2)) , (1 << 5) ), 6); + T0 = shr( add( add( pitch_fr[mult_r( i2, 26214 /*(float)L_FRAME/(float)L_FRAME16k Q15*/ )], shr( pitch_fr[mult_r( i2, 26214 /*(float)L_FRAME/(float)L_FRAME16k Q15*/ )], 2 ) ), ( 1 << 5 ) ), 6 ); } ELSE { - T0 = shr(add( pitch_fr[i2] , (1 << 5) ), 6); + T0 = shr( add( pitch_fr[i2], ( 1 << 5 ) ), 6 ); } - gain = get_gain( st->wspeech_enc + i, st->wspeech_enc + sub(i, T0), L_SUBFR ); + gain = get_gain( st->wspeech_enc + i, st->wspeech_enc + sub( i, T0 ), L_SUBFR ); - signal = L_deposit_l(1); - noise = L_deposit_l(1); + signal = L_deposit_l( 1 ); + noise = L_deposit_l( 1 ); - FOR (j = 0; j < L_SUBFR; j++) + FOR( j = 0; j < L_SUBFR; j++ ) { #ifdef BASOP_NOGLOB - signal = L_mac0_o(signal, st->wspeech_enc[i+j], st->wspeech_enc[i+j], &Overflow); + signal = L_mac0_o( signal, st->wspeech_enc[i + j], st->wspeech_enc[i + j], &Overflow ); - tmp16 = round_fx_o(L_shl_o(Mpy_32_16_r(gain, st->wspeech_enc[i+j-T0]), 15, &Overflow), &Overflow); - tmp16 = sub_o(st->wspeech_enc[i+j], tmp16, &Overflow); - noise = L_mac0_o(noise, tmp16, tmp16, &Overflow); + tmp16 = round_fx_o( L_shl_o( Mpy_32_16_r( gain, st->wspeech_enc[i + j - T0] ), 15, &Overflow ), &Overflow ); + tmp16 = sub_o( st->wspeech_enc[i + j], tmp16, &Overflow ); + noise = L_mac0_o( noise, tmp16, tmp16, &Overflow ); #else - signal = L_mac0(signal, st->wspeech_enc[i+j], st->wspeech_enc[i+j]); + signal = L_mac0( signal, st->wspeech_enc[i + j], st->wspeech_enc[i + j] ); - tmp16 = round_fx(L_shl(Mpy_32_16_r(gain, st->wspeech_enc[i+j-T0]), 15)); - tmp16 = sub(st->wspeech_enc[i+j], tmp16); - noise = L_mac0(noise, tmp16, tmp16); + tmp16 = round_fx( L_shl( Mpy_32_16_r( gain, st->wspeech_enc[i + j - T0] ), 15 ) ); + tmp16 = sub( st->wspeech_enc[i + j], tmp16 ); + noise = L_mac0( noise, tmp16, tmp16 ); #endif } /* Assume always 4 sub frames. */ /*assert( (st->L_frame / L_SUBFR) == 4);*/ - tmp32 = L_add(tmp32, Mpy_32_16_1(L_sub(BASOP_Util_Log2(signal), BASOP_Util_Log2(noise)), 12330/*3.0102999566398119521373889472449 Q12*/)); - i2 = add(i2, 1); + tmp32 = L_add( tmp32, Mpy_32_16_1( L_sub( BASOP_Util_Log2( signal ), BASOP_Util_Log2( noise ) ), 12330 /*3.0102999566398119521373889472449 Q12*/ ) ); + i2 = add( i2, 1 ); } - if(EQ_16(st->L_frame,L_FRAME16k)) + if ( EQ_16( st->L_frame, L_FRAME16k ) ) { - tmp32 = Mpy_32_16_1(tmp32,26214/*(float)L_FRAME/(float)L_FRAME16k Q15*/); + tmp32 = Mpy_32_16_1( tmp32, 26214 /*(float)L_FRAME/(float)L_FRAME16k Q15*/ ); } - offset = -211332072l/*-12.5963731051575616 Q24*/; /* 10*log10(0.055f) */ - move32(); - if (EQ_32(st->sr_core, INT_FS_16k)) + offset = -211332072l /*-12.5963731051575616 Q24*/; /* 10*log10(0.055f) */ + move32(); + if ( EQ_32( st->sr_core, INT_FS_16k ) ) { - offset = -173847554l/*-10.362121726544446 Q24*/; /* 10*log10(0.092f) */ - move32(); + offset = -173847554l /*-10.362121726544446 Q24*/; /* 10*log10(0.092f) */ + move32(); } - if (EQ_32(st->sr_core, INT_FS_12k8)) + if ( EQ_32( st->sr_core, INT_FS_12k8 ) ) { - offset = -206216813l/*-12.291479883578557 Q24*/; /* 10*log10(0.059f) */ - move32(); + offset = -206216813l /*-12.291479883578557 Q24*/; /* 10*log10(0.059f) */ + move32(); } - if (st->narrowBand != 0) + if ( st->narrowBand != 0 ) { - offset = -138228949l/*-8.2390874094431865 Q24*/; /* 10*log10(0.15f) */ - move32(); + offset = -138228949l /*-8.2390874094431865 Q24*/; /* 10*log10(0.15f) */ + move32(); } - tmp32 = L_sub(tmp32, offset); + tmp32 = L_sub( tmp32, offset ); - snr_acelp = round_fx(tmp32); /* 7Q8 */ + snr_acelp = round_fx( tmp32 ); /* 7Q8 */ /*--------------------------------------------------------------* - * Switching Decision - *---------------------------------------------------------------*/ + * Switching Decision + *---------------------------------------------------------------*/ dsnr = 0; move16(); /* hysteresis for very small SNR differences between ACELP and TCX */ /* try to use TCX instead of ACELP on temporally stationary frames */ - test();test();test();test();test();test();test(); - if ((GT_16(snr_acelp, snr_tcx))&& - (LT_16(snr_acelp, add(snr_tcx, 512/*2.0f Q8*/)) ) && + test(); + test(); + test(); + test(); + test(); + test(); + test(); + if ( ( GT_16( snr_acelp, snr_tcx ) ) && + ( LT_16( snr_acelp, add( snr_tcx, 512 /*2.0f Q8*/ ) ) ) && #ifdef BASOP_NOGLOB - (LT_16(add_o(st->prevTempFlatness_fx, currFlatness, &Overflow), 416/*3.25f Q7*/) || EQ_16(stab_fac, 0x7fff) || + ( LT_16( add_o( st->prevTempFlatness_fx, currFlatness, &Overflow ), 416 /*3.25f Q7*/ ) || EQ_16( stab_fac, 0x7fff ) || #else /* BASOP_NOGLOB */ - (LT_16(add(st->prevTempFlatness_fx, currFlatness), 416/*3.25f Q7*/) || EQ_16(stab_fac, 0x7fff) || + ( LT_16( add( st->prevTempFlatness_fx, currFlatness ), 416 /*3.25f Q7*/ ) || EQ_16( stab_fac, 0x7fff ) || #endif #ifdef BASOP_NOGLOB ( EQ_32( st->sr_core, INT_FS_12k8 ) && EQ_16( st->sp_aud_decision0, 1 ) && LT_16( add_sat( st->prevTempFlatness_fx, currFlatness ), 2560 /*20.f Q7*/ ) ) ) && #else - (EQ_32(st->sr_core, INT_FS_12k8) && EQ_16(st->sp_aud_decision0,1) && LT_16(add(st->prevTempFlatness_fx, currFlatness), 2560/*20.f Q7*/) )) && + ( EQ_32( st->sr_core, INT_FS_12k8 ) && EQ_16( st->sp_aud_decision0, 1 ) && LT_16( add( st->prevTempFlatness_fx, currFlatness ), 2560 /*20.f Q7*/ ) ) ) && #endif - (LE_16(st->acelpFramesCount, 6) )) + ( LE_16( st->acelpFramesCount, 6 ) ) ) { - dsnr = -512/*-2.0f Q8*/; + dsnr = -512 /*-2.0f Q8*/; move16(); } /* try to use ACELP instead of TCX on transient and "buzzy" frames */ - test();test();test(); - if ((LT_16(snr_acelp, snr_tcx))&& - (GT_16(snr_acelp, sub(snr_tcx, 512/*2.0f Q8*/)) ) && + test(); + test(); + test(); + if ( ( LT_16( snr_acelp, snr_tcx ) ) && + ( GT_16( snr_acelp, sub( snr_tcx, 512 /*2.0f Q8*/ ) ) ) && #ifdef BASOP_NOGLOB ( GT_16( add_sat( st->prevTempFlatness_fx, currFlatness ), 416 /*3.25f Q7*/ ) ) && #else - (GT_16(add(st->prevTempFlatness_fx, currFlatness), 416/*3.25f Q7*/) ) && + ( GT_16( add( st->prevTempFlatness_fx, currFlatness ), 416 /*3.25f Q7*/ ) ) && #endif - (GE_16(st->acelpFramesCount, 6) )) + ( GE_16( st->acelpFramesCount, 6 ) ) ) { - dsnr = 512/*2.0f Q8*/; + dsnr = 512 /*2.0f Q8*/; move16(); } tmp16 = 0; move16(); - FOR(i = 0; i < 4; i++) + FOR( i = 0; i < 4; i++ ) { - tmp16 = add(tmp16, shr(voicing_fr[i],2)); /*mean of voicing_fr in Q15*/ + tmp16 = add( tmp16, shr( voicing_fr[i], 2 ) ); /*mean of voicing_fr in Q15*/ } - test();test();test();test(); - test();test();test();test();test();test(); - if( EQ_32(st->sr_core, INT_FS_12k8) && (offset_tcx<0x18950F) && GT_16(non_staX,1280 /*5.0f Q8*/ ) && (snr_acelp>=snr_tcx-1024 /*4.0f in Q8*/) && GE_16(st->acelpFramesCount,1) && ((GT_16(hSpMusClas->lps_fx, hSpMusClas->lpm_fx) && GE_16(tmp16,9830)) - || (GE_16(st->acelpFramesCount,6) && (hSpMusClas->lps_fx> hSpMusClas->lpm_fx-768))) && (st->sp_aud_decision0==0) && st->vad_flag!=0) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + if ( EQ_32( st->sr_core, INT_FS_12k8 ) && ( offset_tcx < 0x18950F ) && GT_16( non_staX, 1280 /*5.0f Q8*/ ) && ( snr_acelp >= snr_tcx - 1024 /*4.0f in Q8*/ ) && GE_16( st->acelpFramesCount, 1 ) && ( ( GT_16( hSpMusClas->lps_fx, hSpMusClas->lpm_fx ) && GE_16( tmp16, 9830 ) ) || ( GE_16( st->acelpFramesCount, 6 ) && ( hSpMusClas->lps_fx > hSpMusClas->lpm_fx - 768 ) ) ) && ( st->sp_aud_decision0 == 0 ) && st->vad_flag != 0 ) { /* Fine tuned across various databases based on various metrics to detect TCX frames in speech.*/ dsnr = 1024; move16(); } - IF ( st->flag_noisy_speech_snr_fx) + IF( st->flag_noisy_speech_snr_fx ) { test(); - IF ( st->vad_flag || st->Opt_DTX_ON ) + IF( st->vad_flag || st->Opt_DTX_ON ) { - dsnr = add(dsnr, 512/*2.0f Q8*/); + dsnr = add( dsnr, 512 /*2.0f Q8*/ ); } ELSE { - dsnr = sub(dsnr, 512/*2.0f Q8*/); + dsnr = sub( dsnr, 512 /*2.0f Q8*/ ); } } - test();test();test(); - test();test();test(); - if (EQ_32(st->sr_core, INT_FS_12k8) && (LT_16(non_staX,512/*2.0f Q8*/) || - (st->flag_noisy_speech_snr_fx ==0 && EQ_16(st->vad_flag,1) && (offset_tcx==L_add(0xFFD57AB5,0)) && GE_16(st->acelpFramesCount,6))) && - (st->last_core==ACELP_CORE || st->last_core==TCX_20_CORE)) + test(); + test(); + test(); + test(); + test(); + test(); + if ( EQ_32( st->sr_core, INT_FS_12k8 ) && ( LT_16( non_staX, 512 /*2.0f Q8*/ ) || ( st->flag_noisy_speech_snr_fx == 0 && EQ_16( st->vad_flag, 1 ) && ( offset_tcx == L_add( 0xFFD57AB5, 0 ) ) && GE_16( st->acelpFramesCount, 6 ) ) ) && + ( st->last_core == ACELP_CORE || st->last_core == TCX_20_CORE ) ) { st->core = st->last_core; } - ELSE IF ( GT_16(add(snr_acelp, dsnr), snr_tcx)) + ELSE IF( GT_16( add( snr_acelp, dsnr ), snr_tcx ) ) { st->core = ACELP_CORE; move16(); - st->acelpFramesCount = s_min(32767-1, add(st->acelpFramesCount, 1)); + st->acelpFramesCount = s_min( 32767 - 1, add( st->acelpFramesCount, 1 ) ); } ELSE { @@ -1310,7 +1314,6 @@ void core_acelp_tcx20_switching_fx( st->acelpFramesCount = 0; move16(); } - } /* Fixed Decision (using -C) */ @@ -1334,8 +1337,6 @@ void core_acelp_tcx20_switching_fx( } - - /*-------------------------------------------------------------------* * BITS_ALLOC_ACELP_config_rf() * @@ -1346,10 +1347,9 @@ static void BITS_ALLOC_ACELP_config_rf( Word16 *tilt_code, Word16 *rf_frame_type, Word16 *rf_target_bits, - Word16 nb_subfr, + Word16 nb_subfr, Word16 rf_fec_indicator, - Word16 *pitch_buf -) + Word16 *pitch_buf ) { Word16 mean_tc, min_tilt_code, max_tilt_code; Word16 nrgMode, ltfMode, ltpMode, gainsMode; @@ -1369,52 +1369,52 @@ static void BITS_ALLOC_ACELP_config_rf( mean_tc = 0; move16(); /*mean_tc = mean_fx(tilt_code, nb_subfr);*/ - IF( EQ_16(nb_subfr, 4)) + IF( EQ_16( nb_subfr, 4 ) ) { /* subframe 4 case */ - L_tmp = L_mult(tilt_code[0], 8192); - L_tmp = L_mac(L_tmp, tilt_code[1], 8192 ); - L_tmp = L_mac(L_tmp, tilt_code[2], 8192 ); - mean_tc = mac_r(L_tmp, tilt_code[3], 8192 ); /* mean_tc in Q15 */ + L_tmp = L_mult( tilt_code[0], 8192 ); + L_tmp = L_mac( L_tmp, tilt_code[1], 8192 ); + L_tmp = L_mac( L_tmp, tilt_code[2], 8192 ); + mean_tc = mac_r( L_tmp, tilt_code[3], 8192 ); /* mean_tc in Q15 */ } ELSE { /* subframe 5 case */ - L_tmp = L_mult(tilt_code[0], 6554); - L_tmp = L_mac(L_tmp, tilt_code[1], 6554 ); - L_tmp = L_mac(L_tmp, tilt_code[2], 6554 ); - L_tmp = L_mac(L_tmp, tilt_code[3], 6554 ); - mean_tc = mac_r(L_tmp, tilt_code[4], 6554 ); /* mean_tc in Q15 */ + L_tmp = L_mult( tilt_code[0], 6554 ); + L_tmp = L_mac( L_tmp, tilt_code[1], 6554 ); + L_tmp = L_mac( L_tmp, tilt_code[2], 6554 ); + L_tmp = L_mac( L_tmp, tilt_code[3], 6554 ); + mean_tc = mac_r( L_tmp, tilt_code[4], 6554 ); /* mean_tc in Q15 */ } /* Maximum tilt code estimation */ max_tilt_code = tilt_code[0]; move16(); - maximum_fx(tilt_code, nb_subfr, &max_tilt_code); + maximum_fx( tilt_code, nb_subfr, &max_tilt_code ); /* Minimum tilt code estimation */ - min_tilt_code=tilt_code[0]; + min_tilt_code = tilt_code[0]; move16(); - minimum_fx(tilt_code, nb_subfr, &min_tilt_code); + minimum_fx( tilt_code, nb_subfr, &min_tilt_code ); /* Estimate the frame's criticality and decide whether to transmit partial redundancy information */ - dpit1 = abs_s( sub(pitch_buf[1], pitch_buf[0])); - dpit2 = abs_s( sub(pitch_buf[2], pitch_buf[1])); - dpit3 = abs_s( sub(pitch_buf[3], pitch_buf[2])); + dpit1 = abs_s( sub( pitch_buf[1], pitch_buf[0] ) ); + dpit2 = abs_s( sub( pitch_buf[2], pitch_buf[1] ) ); + dpit3 = abs_s( sub( pitch_buf[3], pitch_buf[2] ) ); - IF ( EQ_16( rf_fec_indicator, 1 )) + IF( EQ_16( rf_fec_indicator, 1 ) ) { test(); test(); test(); test(); - IF ( GT_16( max_tilt_code, 15729/*0.48f Q15*/ )&&LE_16(dpit1,0)&&LE_16(dpit2,0)&&LE_16(dpit3,0)&&EQ_16(coder_type,VOICED)) + IF( GT_16( max_tilt_code, 15729 /*0.48f Q15*/ ) && LE_16( dpit1, 0 ) && LE_16( dpit2, 0 ) && LE_16( dpit3, 0 ) && EQ_16( coder_type, VOICED ) ) { en_partial_red = 0; move16(); } - ELSE IF ( GT_16( max_tilt_code, 15401/*0.47f Q15*/ )&&LE_16(dpit1,64)&&LE_16(dpit2,64)&&LE_16(dpit3,64)&&EQ_16(coder_type,GENERIC)) + ELSE IF( GT_16( max_tilt_code, 15401 /*0.47f Q15*/ ) && LE_16( dpit1, 64 ) && LE_16( dpit2, 64 ) && LE_16( dpit3, 64 ) && EQ_16( coder_type, GENERIC ) ) { en_partial_red = 0; move16(); @@ -1426,12 +1426,12 @@ static void BITS_ALLOC_ACELP_config_rf( test(); test(); test(); - IF ( GT_16( max_tilt_code, 15401/*0.47f Q15*/ )&&LE_16(dpit1,16)&&LE_16(dpit2,16)&&LE_16(dpit3,16)&&EQ_16(coder_type,VOICED)) + IF( GT_16( max_tilt_code, 15401 /*0.47f Q15*/ ) && LE_16( dpit1, 16 ) && LE_16( dpit2, 16 ) && LE_16( dpit3, 16 ) && EQ_16( coder_type, VOICED ) ) { en_partial_red = 0; move16(); } - ELSE IF ( GT_16( max_tilt_code, 14746/*0.45f Q15*/ )&&LE_16(dpit1,80)&&LE_16(dpit2,80)&&LE_16(dpit3,80)&&EQ_16(coder_type,GENERIC)) + ELSE IF( GT_16( max_tilt_code, 14746 /*0.45f Q15*/ ) && LE_16( dpit1, 80 ) && LE_16( dpit2, 80 ) && LE_16( dpit3, 80 ) && EQ_16( coder_type, GENERIC ) ) { en_partial_red = 0; move16(); @@ -1443,34 +1443,34 @@ static void BITS_ALLOC_ACELP_config_rf( * ---------------------------------------------------------*/ /* rf_mode, 1 bit */ - *rf_target_bits = add(*rf_target_bits,1); + *rf_target_bits = add( *rf_target_bits, 1 ); /* rf_fec_offset 2 bits */ - *rf_target_bits = add(*rf_target_bits,2); + *rf_target_bits = add( *rf_target_bits, 2 ); /* rf_frame_type, 3 bits */ - *rf_target_bits = add(*rf_target_bits,3); + *rf_target_bits = add( *rf_target_bits, 3 ); /* LSF bits 8 + 8 bits */ - *rf_target_bits = add(*rf_target_bits,16); + *rf_target_bits = add( *rf_target_bits, 16 ); /* Intialize the RF mode frame type to all-pred */ *rf_frame_type = RF_ALLPRED; test(); - IF( EQ_16(coder_type,INACTIVE)||en_partial_red==0) + IF( EQ_16( coder_type, INACTIVE ) || en_partial_red == 0 ) { *rf_frame_type = RF_NO_DATA; } - ELSE IF ( EQ_16(coder_type,UNVOICED)||EQ_16(coder_type,INACTIVE)) + ELSE IF( EQ_16( coder_type, UNVOICED ) || EQ_16( coder_type, INACTIVE ) ) { *rf_frame_type = RF_NELP; } - ELSE IF( EQ_16(coder_type,GENERIC)&<_16(max_tilt_code,1638/*0.05f Q15*/)) + ELSE IF( EQ_16( coder_type, GENERIC ) && LT_16( max_tilt_code, 1638 /*0.05f Q15*/ ) ) { *rf_frame_type = RF_NOPRED; } - ELSE IF( EQ_16(coder_type,GENERIC)&<_16(mean_tc,9830/*0.3f Q15*/)) + ELSE IF( EQ_16( coder_type, GENERIC ) && LT_16( mean_tc, 9830 /*0.3f Q15*/ ) ) { *rf_frame_type = RF_GENPRED; } @@ -1481,73 +1481,58 @@ static void BITS_ALLOC_ACELP_config_rf( gainsMode = ACELP_GAINS_MODE[1][1][*rf_frame_type]; /* Number of RF bits for different RF coder types */ - SWITCH (*rf_frame_type) + SWITCH( *rf_frame_type ) { - case RF_ALLPRED: - /* Es_pred bits 3 bits, LTF: 1, pitch: 8,5,5,5, FCB: 0, gain: 7,0,7,0, Diff GFr: 4*/ - *rf_target_bits += ( ACELP_NRG_BITS[nrgMode] - + ACELP_LTF_BITS[ltfMode] - + ACELP_LTP_BITS_SFR[ltpMode][0] + ACELP_LTP_BITS_SFR[ltpMode][1] + ACELP_LTP_BITS_SFR[ltpMode][2] + ACELP_LTP_BITS_SFR[ltpMode][3] - + ACELP_GAINS_BITS[gainsMode] + ACELP_GAINS_BITS[gainsMode] - + 2 /*2 bits for PartialCopy GainFrame*/ - ); - BREAK; - - case RF_NOPRED: - /* Es_pred bits 3 bits, LTF: 0, pitch: 0, FCB: 7,7,7,7, gain: 6,0,6,0, Diff GFr: 2*/ - /*bits += (3 + 0 + 0 + 28 + 12 + 2); *//* 64 rf bits */ - *rf_target_bits += ( ACELP_NRG_BITS[nrgMode] - + ACELP_LTF_BITS[ltfMode] - + 28 - + ACELP_GAINS_BITS[gainsMode] + ACELP_GAINS_BITS[gainsMode] - + 2 /*2 bits for PartialCopy GainFrame*/ - ); - BREAK; - - case RF_GENPRED: - /* Es_pred bits 3 bits, LTF: 0, pitch: 8,0,8,0, FCB: 6,7,5,5, gain: 5,0,5,0, Diff GFr: 0*/ - /*bits += (3 + 0 + 16 + 23 + 10 + 0); */ /* 72 rf bits */ - *rf_target_bits += ( ACELP_NRG_BITS[nrgMode] - + ACELP_LTF_BITS[ltfMode] - + ACELP_LTP_BITS_SFR[ltpMode][0] + ACELP_LTP_BITS_SFR[ltpMode][1] + ACELP_LTP_BITS_SFR[ltpMode][2] + ACELP_LTP_BITS_SFR[ltpMode][3] - + 14 - + ACELP_GAINS_BITS[gainsMode] + ACELP_GAINS_BITS[gainsMode] - + 2 /*2 bits for PartialCopy GainFrame*/ - ); - BREAK; - - case RF_NELP: - /* gain: 19, Diff GFr: 5 */ - /*bits += (19 + 5); */ - *rf_target_bits += (19 + NUM_BITS_SHB_FRAMEGAIN); - BREAK; - - case RF_NO_DATA: - *rf_target_bits = 6; - BREAK; - - default: - assert(!"RF_Frame_type does not belong to ACELP Partial copy frame types possible!"); - break; + case RF_ALLPRED: + /* Es_pred bits 3 bits, LTF: 1, pitch: 8,5,5,5, FCB: 0, gain: 7,0,7,0, Diff GFr: 4*/ + *rf_target_bits += ( ACELP_NRG_BITS[nrgMode] + ACELP_LTF_BITS[ltfMode] + ACELP_LTP_BITS_SFR[ltpMode][0] + ACELP_LTP_BITS_SFR[ltpMode][1] + ACELP_LTP_BITS_SFR[ltpMode][2] + ACELP_LTP_BITS_SFR[ltpMode][3] + ACELP_GAINS_BITS[gainsMode] + ACELP_GAINS_BITS[gainsMode] + 2 /*2 bits for PartialCopy GainFrame*/ + ); + BREAK; + + case RF_NOPRED: + /* Es_pred bits 3 bits, LTF: 0, pitch: 0, FCB: 7,7,7,7, gain: 6,0,6,0, Diff GFr: 2*/ + /*bits += (3 + 0 + 0 + 28 + 12 + 2); */ /* 64 rf bits */ + *rf_target_bits += ( ACELP_NRG_BITS[nrgMode] + ACELP_LTF_BITS[ltfMode] + 28 + ACELP_GAINS_BITS[gainsMode] + ACELP_GAINS_BITS[gainsMode] + 2 /*2 bits for PartialCopy GainFrame*/ + ); + BREAK; + + case RF_GENPRED: + /* Es_pred bits 3 bits, LTF: 0, pitch: 8,0,8,0, FCB: 6,7,5,5, gain: 5,0,5,0, Diff GFr: 0*/ + /*bits += (3 + 0 + 16 + 23 + 10 + 0); */ /* 72 rf bits */ + *rf_target_bits += ( ACELP_NRG_BITS[nrgMode] + ACELP_LTF_BITS[ltfMode] + ACELP_LTP_BITS_SFR[ltpMode][0] + ACELP_LTP_BITS_SFR[ltpMode][1] + ACELP_LTP_BITS_SFR[ltpMode][2] + ACELP_LTP_BITS_SFR[ltpMode][3] + 14 + ACELP_GAINS_BITS[gainsMode] + ACELP_GAINS_BITS[gainsMode] + 2 /*2 bits for PartialCopy GainFrame*/ + ); + BREAK; + + case RF_NELP: + /* gain: 19, Diff GFr: 5 */ + /*bits += (19 + 5); */ + *rf_target_bits += ( 19 + NUM_BITS_SHB_FRAMEGAIN ); + BREAK; + + case RF_NO_DATA: + *rf_target_bits = 6; + BREAK; + + default: + assert( !"RF_Frame_type does not belong to ACELP Partial copy frame types possible!" ); + break; } return; - } /*-------------------------------------------------------------------* - * BITS_ALLOC_TCX_config_rf() - * - * configure channel aware mode - *-------------------------------------------------------------------*/ + * BITS_ALLOC_TCX_config_rf() + * + * configure channel aware mode + *-------------------------------------------------------------------*/ static void BITS_ALLOC_TCX_config_rf( Word16 *rf_frame_type, Word16 *rf_target_bits, Word16 PLC_Mode, Word16 coder_type, Word16 last_core, - Word16 TD_mode -) + Word16 TD_mode ) { Word16 bits; @@ -1556,7 +1541,7 @@ static void BITS_ALLOC_TCX_config_rf( move16(); test(); - IF( EQ_16(coder_type, INACTIVE)||EQ_16(last_core,ACELP_CORE)) + IF( EQ_16( coder_type, INACTIVE ) || EQ_16( last_core, ACELP_CORE ) ) { *rf_frame_type = RF_NO_DATA; move16(); @@ -1564,12 +1549,12 @@ static void BITS_ALLOC_TCX_config_rf( ELSE { /* classification */ - bits = add(bits, 2); + bits = add( bits, 2 ); IF( PLC_Mode != 0 ) { /* TCX global gain = 7 bits */ - bits = add(bits, 7); + bits = add( bits, 7 ); *rf_frame_type = RF_TCXFD; move16(); } @@ -1577,25 +1562,25 @@ static void BITS_ALLOC_TCX_config_rf( { /* pitch and gain */ /* LTP data */ - IF( TD_mode != 0) + IF( TD_mode != 0 ) { - bits = add(bits, 9); + bits = add( bits, 9 ); *rf_frame_type = RF_TCXTD2; move16(); } ELSE { - bits = add(bits, 9); + bits = add( bits, 9 ); *rf_frame_type = RF_TCXTD1; move16(); } } - if( EQ_16(*rf_frame_type, RF_TCXFD)) + if ( EQ_16( *rf_frame_type, RF_TCXFD ) ) { /* TCXFD: LSF bits 5 + 4 + 4 bits */ /* only embed LSF for FD concealment */ - bits = add(bits, TCXLPC_NUMBITS); + bits = add( bits, TCXLPC_NUMBITS ); } } @@ -1604,9 +1589,3 @@ static void BITS_ALLOC_TCX_config_rf( return; } - - - - - - diff --git a/lib_enc/core_enc_reconf_fx.c b/lib_enc/core_enc_reconf_fx.c index d91318146..49631b178 100644 --- a/lib_enc/core_enc_reconf_fx.c +++ b/lib_enc/core_enc_reconf_fx.c @@ -5,14 +5,14 @@ #include #include "options.h" //#include "prot_fx.h" -#include "cnst.h" /* Common constants */ +#include "cnst.h" /* Common constants */ #include "rom_com_fx.h" #include "rom_enc.h" /* Encoder static table prototypes */ #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ -#include "basop_util.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ +#include "basop_util.h" /* Function prototypes */ /*-----------------------------------------------------------------* * Funtion core_coder_reconfig_fx * @@ -20,20 +20,19 @@ * - reconfig core coder when switching to another frame type * *-----------------------------------------------------------------*/ void core_coder_reconfig_fx( - Encoder_State* st, - const Word32 last_total_brate -) + Encoder_State *st, + const Word32 last_total_brate ) { Word16 i, bwidth, index; TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; #ifdef REMOVE_IVAS_UNUSED_PARAMETERS_WARNING - (void)last_total_brate; + (void) last_total_brate; #endif /*Configuration of ACELP*/ - BITS_ALLOC_init_config_acelp(st->total_brate, st->narrowBand, st->nb_subfr, &(st->acelp_cfg)); + BITS_ALLOC_init_config_acelp( st->total_brate, st->narrowBand, st->nb_subfr, &( st->acelp_cfg ) ); /*Configuration of partial copy*/ - if (st->Opt_RF_ON) + if ( st->Opt_RF_ON ) { st->hRF->acelp_cfg_rf.mode_index = 1; st->hRF->acelp_cfg_rf.midLpc = 0; @@ -44,45 +43,51 @@ void core_coder_reconfig_fx( st->hRF->acelp_cfg_rf.voice_tilt = 1; st->hRF->acelp_cfg_rf.formant_enh_num = FORMANT_SHARPENING_G1; st->hRF->acelp_cfg_rf.formant_enh_den = FORMANT_SHARPENING_G2; - move16(); move16(); move16(); move16(); - move16(); move16(); move16(); move16(); - + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); } - st->nb_bits_header_tcx = 2; /*Mode(1) + Last_mode(1)*/ move16(); + st->nb_bits_header_tcx = 2; /*Mode(1) + Last_mode(1)*/ + move16(); - IF(EQ_16(st->element_mode, IVAS_CPE_MDCT)) + IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) { st->nb_bits_header_tcx = 2; /* signal class */ } - ELSE IF(st->tcxonly == 0) + ELSE IF( st->tcxonly == 0 ) { move16(); st->nb_bits_header_ace = 4; st->nb_bits_header_tcx = st->nb_bits_header_ace; move16(); - IF (st->hTcxCfg != NULL) + IF( st->hTcxCfg != NULL ) { - if (st->hTcxCfg->lfacNext <= 0) + if ( st->hTcxCfg->lfacNext <= 0 ) { /*st->nb_bits_header_ace--;*/ /*No Last_mode*/ - st->nb_bits_header_ace = sub(st->nb_bits_header_ace, 1); + st->nb_bits_header_ace = sub( st->nb_bits_header_ace, 1 ); } } } - if (st->tcxonly) + if ( st->tcxonly ) { - st->nb_bits_header_tcx = add(st->nb_bits_header_tcx, 2); + st->nb_bits_header_tcx = add( st->nb_bits_header_tcx, 2 ); } /*Switch off TCX or ACELP?*/ - IF(EQ_32(st->sr_core, INT_FS_12k8)) + IF( EQ_32( st->sr_core, INT_FS_12k8 ) ) { st->acelpEnabled = 0; move16(); - if (s_and(st->restrictedMode, 1) != 0) + if ( s_and( st->restrictedMode, 1 ) != 0 ) { st->acelpEnabled = 1; move16(); @@ -90,7 +95,7 @@ void core_coder_reconfig_fx( st->tcx20Enabled = 0; move16(); - if (s_and(st->restrictedMode, 2) != 0) + if ( s_and( st->restrictedMode, 2 ) != 0 ) { st->tcx20Enabled = 1; @@ -100,23 +105,23 @@ void core_coder_reconfig_fx( move32(); move32(); move16(); - st->prevEnergyHF_fx = st->currEnergyHF_fx = 1073725440l/*65535.0f Q14*/; /* prevent block switch */ + st->prevEnergyHF_fx = st->currEnergyHF_fx = 1073725440l /*65535.0f Q14*/; /* prevent block switch */ st->currEnergyHF_e_fx = 17; /*Sanity check : don't need to be instrumented*/ - if (st->tcxonly == 0) + if ( st->tcxonly == 0 ) { - assert(st->acelpEnabled || st->tcx20Enabled || st->frame_size_index == 0); + assert( st->acelpEnabled || st->tcx20Enabled || st->frame_size_index == 0 ); } else { - assert(st->tcx10Enabled || st->tcx20Enabled || st->frame_size_index == 0); + assert( st->tcx10Enabled || st->tcx20Enabled || st->frame_size_index == 0 ); } /* TCX-LTP */ - IF(st->hTcxEnc != NULL) + IF( st->hTcxEnc != NULL ) { - hTcxEnc->tcxltp = getTcxLtp(st->sr_core); + hTcxEnc->tcxltp = getTcxLtp( st->sr_core ); } /*Use for 12.8 kHz sampling rate and low bitrates, the conventional pulse search->better SNR*/ @@ -125,19 +130,19 @@ void core_coder_reconfig_fx( move16(); test(); - if ((LE_32(st->total_brate, ACELP_9k60)) && (EQ_32(st->sr_core, INT_FS_12k8))) + if ( ( LE_32( st->total_brate, ACELP_9k60 ) ) && ( EQ_32( st->sr_core, INT_FS_12k8 ) ) ) { st->acelp_autocorr = 0; move16(); } /*Get bandwidth mode*/ - IF(st->narrowBand) + IF( st->narrowBand ) { move16(); bwidth = 0; } - ELSE IF(LE_32(st->sr_core, INT_FS_16k)) + ELSE IF( LE_32( st->sr_core, INT_FS_16k ) ) { move16(); bwidth = 1; @@ -148,26 +153,26 @@ void core_coder_reconfig_fx( bwidth = 2; } - /*Scale TCX for non-active frames to adjust loudness with ACELP*/ - IF (st->hTcxCfg != NULL) + /*Scale TCX for non-active frames to adjust loudness with ACELP*/ + IF( st->hTcxCfg != NULL ) { - st->hTcxCfg->na_scale = 32767/*1.0f Q15*/; + st->hTcxCfg->na_scale = 32767 /*1.0f Q15*/; test(); - IF(LT_16(bwidth, 2) && (st->tcxonly == 0)) + IF( LT_16( bwidth, 2 ) && ( st->tcxonly == 0 ) ) { /*const Word16 scaleTableSize = sizeof(scaleTcxTable) / sizeof(scaleTcxTable[0]);*/ - FOR(i = 0; i < SIZE_SCALE_TABLE_TCX; i++) + FOR( i = 0; i < SIZE_SCALE_TABLE_TCX; i++ ) { test(); test(); - IF(EQ_16(bwidth, scaleTcxTable[i].bwmode) && - GE_32(st->total_brate, scaleTcxTable[i].bitrateFrom) && - LT_32(st->total_brate, scaleTcxTable[i].bitrateTo)) + IF( EQ_16( bwidth, scaleTcxTable[i].bwmode ) && + GE_32( st->total_brate, scaleTcxTable[i].bitrateFrom ) && + LT_32( st->total_brate, scaleTcxTable[i].bitrateTo ) ) { - if (st->rf_mode) + if ( st->rf_mode ) { i--; } @@ -180,23 +185,25 @@ void core_coder_reconfig_fx( } st->enableTcxLpc = 0; move16(); - IF (GT_16(st->element_mode, IVAS_SCE)) + IF( GT_16( st->element_mode, IVAS_SCE ) ) { - test();test(); - st->enableTcxLpc = (EQ_16(st->lpcQuantization, 1) && (LE_32(st->total_brate, LOWRATE_TCXLPC_MAX_BR_CPE) || st->rf_mode)); + test(); + test(); + st->enableTcxLpc = ( EQ_16( st->lpcQuantization, 1 ) && ( LE_32( st->total_brate, LOWRATE_TCXLPC_MAX_BR_CPE ) || st->rf_mode ) ); move16(); } ELSE { - test();test(); - if (EQ_16(st->lpcQuantization, 1) && (LE_32(st->total_brate, LOWRATE_TCXLPC_MAX_BR) || st->rf_mode != 0)) + test(); + test(); + if ( EQ_16( st->lpcQuantization, 1 ) && ( LE_32( st->total_brate, LOWRATE_TCXLPC_MAX_BR ) || st->rf_mode != 0 ) ) { st->enableTcxLpc = 1; move16(); } } test(); - IF ( st->ini_frame == 0 || EQ_16(st->last_codec_mode, MODE1)) + IF( st->ini_frame == 0 || EQ_16( st->last_codec_mode, MODE1 ) ) { st->envWeighted = 0; move16(); @@ -204,12 +211,12 @@ void core_coder_reconfig_fx( test(); test(); - IF( EQ_16(st->bwidth, SWB)&& - (EQ_32(st->total_brate, ACELP_16k40) || EQ_32(st->total_brate, ACELP_24k40)) ) + IF( EQ_16( st->bwidth, SWB ) && + ( EQ_32( st->total_brate, ACELP_16k40 ) || EQ_32( st->total_brate, ACELP_24k40 ) ) ) { - IF(st->tec_tfa == 0) + IF( st->tec_tfa == 0 ) { - FOR (i = 0; i < MAX_TEC_SMOOTHING_DEG; i++) + FOR( i = 0; i < MAX_TEC_SMOOTHING_DEG; i++ ) { st->hTECEnc->loBuffer[i] = 0; move16(); @@ -226,7 +233,7 @@ void core_coder_reconfig_fx( st->enablePlcWaveadjust = 0; move16(); - IF (GE_32(st->total_brate, 48000)) + IF( GE_32( st->total_brate, 48000 ) ) { st->enablePlcWaveadjust = 1; move16(); @@ -239,74 +246,78 @@ void core_coder_reconfig_fx( test(); test(); test(); - if( (EQ_32(st->total_brate, ACELP_9k60) || EQ_32(st->total_brate, ACELP_16k40) || EQ_32(st->total_brate, ACELP_24k40)) && EQ_16(st->element_mode, EVS_MONO) ) + if ( ( EQ_32( st->total_brate, ACELP_9k60 ) || EQ_32( st->total_brate, ACELP_16k40 ) || EQ_32( st->total_brate, ACELP_24k40 ) ) && EQ_16( st->element_mode, EVS_MONO ) ) { move16(); st->glr = 1; } - if(st->glr) + if ( st->glr ) { - st->nb_bits_header_ace = add(st->nb_bits_header_ace, G_LPC_RECOVERY_BITS); + st->nb_bits_header_ace = add( st->nb_bits_header_ace, G_LPC_RECOVERY_BITS ); } - IF (hTcxEnc != NULL) + IF( hTcxEnc != NULL ) { test(); - IF(EQ_16(st->bwidth, NB) || EQ_16(st->bwidth, WB)) + IF( EQ_16( st->bwidth, NB ) || EQ_16( st->bwidth, WB ) ) { test(); - IF(st->rf_mode == 0) + IF( st->rf_mode == 0 ) { - index = s_min(N_TCX_STARTLINE_NOISE_WB - 1, s_max(3, st->frame_size_index)); + index = s_min( N_TCX_STARTLINE_NOISE_WB - 1, s_max( 3, st->frame_size_index ) ); } ELSE { - index = s_min(N_TCX_STARTLINE_NOISE_WB - 1, s_max(3, st->frame_size_index - 1)); + index = s_min( N_TCX_STARTLINE_NOISE_WB - 1, s_max( 3, st->frame_size_index - 1 ) ); } hTcxEnc->nmStartLine = startLineWB[index]; move16(); } ELSE /* (st->bwidth == SWB || st->bwidth == FB) */ { - IF(st->rf_mode == 0) + IF( st->rf_mode == 0 ) { - index = s_min(N_TCX_STARTLINE_NOISE_SWB - 1, sub(s_max(3, st->frame_size_index), 3)); + index = s_min( N_TCX_STARTLINE_NOISE_SWB - 1, sub( s_max( 3, st->frame_size_index ), 3 ) ); } - ELSE + ELSE { - index = s_min(N_TCX_STARTLINE_NOISE_SWB - 1, sub(s_max(3, st->frame_size_index - 1), 3)); + index = s_min( N_TCX_STARTLINE_NOISE_SWB - 1, sub( s_max( 3, st->frame_size_index - 1 ), 3 ) ); } - test();test(); - if (GE_32(st->total_brate, IVAS_96k) && LE_32(st->total_brate, IVAS_192k) && GT_16(st->element_mode, IVAS_SCE)) + test(); + test(); + if ( GE_32( st->total_brate, IVAS_96k ) && LE_32( st->total_brate, IVAS_192k ) && GT_16( st->element_mode, IVAS_SCE ) ) { - index = sub(index, 1); + index = sub( index, 1 ); } hTcxEnc->nmStartLine = startLineSWB[index]; move16(); - if (EQ_32(st->total_brate, IVAS_48k) && EQ_16(st->element_mode, IVAS_CPE_MDCT) && LT_16(add(hTcxEnc->nmStartLine, shl(hTcxEnc->nmStartLine,2)) , shl(st->L_frame, 2)) ) + if ( EQ_32( st->total_brate, IVAS_48k ) && EQ_16( st->element_mode, IVAS_CPE_MDCT ) && LT_16( add( hTcxEnc->nmStartLine, shl( hTcxEnc->nmStartLine, 2 ) ), shl( st->L_frame, 2 ) ) ) { - hTcxEnc->nmStartLine = shr(add(hTcxEnc->nmStartLine, shl(hTcxEnc->nmStartLine, 2)), 2); /* low-rate stereo is more efficient than dual-mono due to stereo processing */ + hTcxEnc->nmStartLine = shr( add( hTcxEnc->nmStartLine, shl( hTcxEnc->nmStartLine, 2 ) ), 2 ); /* low-rate stereo is more efficient than dual-mono due to stereo processing */ } } } - IF(hTcxEnc != NULL) + IF( hTcxEnc != NULL ) { - test(); test(); - test(); test(); test(); - IF((LT_32(st->total_brate, ACELP_24k40)) && ((GT_32(st->total_brate, st->last_total_brate)) || (EQ_16(st->last_codec_mode, MODE1)))) + test(); + test(); + test(); + test(); + test(); + IF( ( LT_32( st->total_brate, ACELP_24k40 ) ) && ( ( GT_32( st->total_brate, st->last_total_brate ) ) || ( EQ_16( st->last_codec_mode, MODE1 ) ) ) ) { /* low-freq memQuantZeros_fx must be reset partially if bitrate increased */ - FOR(i = 0; i < hTcxEnc->nmStartLine; i++) + FOR( i = 0; i < hTcxEnc->nmStartLine; i++ ) { hTcxEnc->memQuantZeros_fx[i] = 0; move16(); } } - ELSE IF((GE_32(st->total_brate, ACELP_24k40)) && (LE_32(st->total_brate, ACELP_32k)) && (GE_32(st->last_total_brate, ACELP_13k20)) && (LT_32(st->last_total_brate, ACELP_24k40))) + ELSE IF( ( GE_32( st->total_brate, ACELP_24k40 ) ) && ( LE_32( st->total_brate, ACELP_32k ) ) && ( GE_32( st->last_total_brate, ACELP_13k20 ) ) && ( LT_32( st->last_total_brate, ACELP_24k40 ) ) ) { - FOR(i = 0; i < st->L_frame; i++) /* memQuantZeros_fx won't be updated */ + FOR( i = 0; i < st->L_frame; i++ ) /* memQuantZeros_fx won't be updated */ { hTcxEnc->memQuantZeros_fx[i] = 0; move16(); @@ -314,4 +325,3 @@ void core_coder_reconfig_fx( } } } - diff --git a/lib_enc/core_enc_switch.c b/lib_enc/core_enc_switch.c index b3427d246..93aca7e0d 100644 --- a/lib_enc/core_enc_switch.c +++ b/lib_enc/core_enc_switch.c @@ -174,7 +174,7 @@ void core_coder_mode_switch( if ( st->envWeighted && !st->enableTcxLpc ) { /* Unweight the envelope */ - E_LPC_lsp_unweight_float( st->lsp_old, st->lsp_old, st->lsf_old, 1.0f / st->gamma_flt); + E_LPC_lsp_unweight_float( st->lsp_old, st->lsp_old, st->lsf_old, 1.0f / st->gamma_flt ); st->envWeighted = 0; } diff --git a/lib_enc/core_enc_switch_fx.c b/lib_enc/core_enc_switch_fx.c index 8612f685c..0eede724a 100644 --- a/lib_enc/core_enc_switch_fx.c +++ b/lib_enc/core_enc_switch_fx.c @@ -7,22 +7,21 @@ #include "prot.h" //#include "prot_fx.h" //#include "basop_mpy.h" -#include "cnst.h" /* Common constants */ +#include "cnst.h" /* Common constants */ #include "ivas_cnst.h" #include "rom_com_fx.h" #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ -#include "basop_util.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ +#include "basop_util.h" /* Function prototypes */ void core_coder_mode_switch_fx( - Encoder_State *st, + Encoder_State *st, const Word32 last_total_bitrate, const Word16 MCT_flag, - const Word16 shift -) + const Word16 shift ) { Word16 i, fscale, switchWB; Word16 bSwitchFromAmrwbIO, tcxonly_tmp; @@ -31,112 +30,114 @@ void core_coder_mode_switch_fx( TD_BWE_ENC_HANDLE hBWE_TD = st->hBWE_TD; TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; - move16();move16(); - move16();move16(); + move16(); + move16(); + move16(); + move16(); switchWB = 0; bSwitchFromAmrwbIO = 0; - if ( EQ_16(st->last_core, AMR_WB_CORE)) + if ( EQ_16( st->last_core, AMR_WB_CORE ) ) { move16(); bSwitchFromAmrwbIO = 1; } - sr_core = getCoreSamplerateMode2(st->element_mode, st->total_brate, st->bwidth, st->flag_ACELP16k, st->rf_mode, st->is_ism_format); + sr_core = getCoreSamplerateMode2( st->element_mode, st->total_brate, st->bwidth, st->flag_ACELP16k, st->rf_mode, st->is_ism_format ); move16(); - fscale = sr2fscale(sr_core); + fscale = sr2fscale( sr_core ); move16(); - if( EQ_16(st->last_codec_mode,MODE1)) + if ( EQ_16( st->last_codec_mode, MODE1 ) ) { move16(); - switchWB = 1; /*force init when coming from MODE1*/ + switchWB = 1; /*force init when coming from MODE1*/ } #ifdef IVAS_CODE_SWITCHING - tcxonly_tmp = getTcxonly(st->element_mode, st->total_brate, MCT_flag, st->is_ism_format); + tcxonly_tmp = getTcxonly( st->element_mode, st->total_brate, MCT_flag, st->is_ism_format ); #else - tcxonly_tmp = getTcxonly(st->total_brate); + tcxonly_tmp = getTcxonly( st->total_brate ); #endif test(); - if( NE_16(tcxonly_tmp, st->tcxonly)) + if ( NE_16( tcxonly_tmp, st->tcxonly ) ) { move16(); - switchWB = 1; /*force init when coming from MODE1*/ + switchWB = 1; /*force init when coming from MODE1*/ } test(); test(); - IF ( (EQ_16(fscale, st->fscale)) && (bSwitchFromAmrwbIO==0) && (switchWB==0)) + IF( ( EQ_16( fscale, st->fscale ) ) && ( bSwitchFromAmrwbIO == 0 ) && ( switchWB == 0 ) ) { /*st->total_brate = bitrate; */ move32(); st->sr_core = sr_core; move32(); - st->L_frame = extract_l(Mult_32_16(st->sr_core , 0x0290)); - assert(st->L_frame == st->sr_core / 50); + st->L_frame = extract_l( Mult_32_16( st->sr_core, 0x0290 ) ); + assert( st->L_frame == st->sr_core / 50 ); #ifdef IVAS_CODE_SWITCHING - st->tcxonly = getTcxonly(st->element_mode, st->total_brate, MCT_flag, st->is_ism_format); + st->tcxonly = getTcxonly( st->element_mode, st->total_brate, MCT_flag, st->is_ism_format ); #else - st->tcxonly = (Word8)getTcxonly(st->total_brate); + st->tcxonly = (Word8) getTcxonly( st->total_brate ); #endif /* st->bits_frame_nominal = (int)( (float)st->L_frame/(float)st->fscale ) * (float)FSCALE_DENOM/128.0f * (float)st->bitrate/100.0f + 0.49f ; */ /* st->bits_frame_nominal = extract_l(L_shr(Mpy_32_16_1( L_shl(st->bitrate,8), mult_r(div_s(st->fscale, shl(st->L_frame,4)), FL2WORD16(FSCALE_DENOM/12800.f))), 6)); */ - tmp32 = L_shl(st->total_brate, 1); /* (float)st->L_frame/(float)st->fscale * (float)FSCALE_DENOM/128.0f * (float)st->bitrate */ - st->bits_frame_nominal = extract_l(L_shr(Mpy_32_16_1(tmp32, 20972), 6)); /* 20972 = 0.01 * 64 * 32768 */ - assert(st->bits_frame_nominal == (int)( (float)st->L_frame/(float)st->fscale * (float)FSCALE_DENOM/128.0f * (float)st->total_brate/100.0f + 0.49f )); + tmp32 = L_shl( st->total_brate, 1 ); /* (float)st->L_frame/(float)st->fscale * (float)FSCALE_DENOM/128.0f * (float)st->bitrate */ + st->bits_frame_nominal = extract_l( L_shr( Mpy_32_16_1( tmp32, 20972 ), 6 ) ); /* 20972 = 0.01 * 64 * 32768 */ + assert( st->bits_frame_nominal == (int) ( (float) st->L_frame / (float) st->fscale * (float) FSCALE_DENOM / 128.0f * (float) st->total_brate / 100.0f + 0.49f ) ); - st->igf = getIgfPresent_fx(st->element_mode, st->total_brate, st->bwidth, st->rf_mode); + st->igf = getIgfPresent_fx( st->element_mode, st->total_brate, st->bwidth, st->rf_mode ); /* switch IGF configuration */ - IF (st->igf) + IF( st->igf ) { - IGFEncSetMode_fx(st->hIGFEnc, st->total_brate, st->bwidth, st->element_mode, st->rf_mode); + IGFEncSetMode_fx( st->hIGFEnc, st->total_brate, st->bwidth, st->element_mode, st->rf_mode ); } - st->hTcxCfg->tcx_coded_lines = getNumTcxCodedLines(st->bwidth); + st->hTcxCfg->tcx_coded_lines = getNumTcxCodedLines( st->bwidth ); move16(); - st->hTcxCfg->bandwidth = getTcxBandwidth(st->bwidth); + st->hTcxCfg->bandwidth = getTcxBandwidth( st->bwidth ); move16(); move16(); st->hTcxCfg->tcxRateLoopOpt = 0; - if (st->tcxonly) + if ( st->tcxonly ) { move16(); st->hTcxCfg->tcxRateLoopOpt = 2; } - st->hTcxCfg->ctx_hm = getCtxHm(st->element_mode, st->total_brate, st->rf_mode ); + st->hTcxCfg->ctx_hm = getCtxHm( st->element_mode, st->total_brate, st->rf_mode ); move16(); - st->hTcxCfg->resq = getResq(st->total_brate); + st->hTcxCfg->resq = getResq( st->total_brate ); move16(); - hTcxEnc->tcx_lpc_shaped_ari = getTcxLpcShapedAri(st->total_brate, st->rf_mode, st->element_mode); + hTcxEnc->tcx_lpc_shaped_ari = getTcxLpcShapedAri( st->total_brate, st->rf_mode, st->element_mode ); test(); - if (st->hTcxCfg->resq != 0 && st->tcxonly == 0) + if ( st->hTcxCfg->resq != 0 && st->tcxonly == 0 ) { st->hTcxCfg->tcxRateLoopOpt = 1; move16(); } - st->hTcxCfg->fIsTNSAllowed = getTnsAllowed(st->total_brate, st->igf, st->element_mode); - IF (st->hTcxCfg->fIsTNSAllowed != 0) + st->hTcxCfg->fIsTNSAllowed = getTnsAllowed( st->total_brate, st->igf, st->element_mode ); + IF( st->hTcxCfg->fIsTNSAllowed != 0 ) { - InitTnsConfigs(st->bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFEnc->infoStopFrequency, st->total_brate, st->element_mode, MCT_flag); + InitTnsConfigs( st->bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFEnc->infoStopFrequency, st->total_brate, st->element_mode, MCT_flag ); #ifdef IVAS_CODE - SetAllowTnsOnWhite(st->hTcxCfg->tnsConfig, EQ_16(st->element_mode, IVAS_CPE_MDCT)); -#endif + SetAllowTnsOnWhite( st->hTcxCfg->tnsConfig, EQ_16( st->element_mode, IVAS_CPE_MDCT ) ); +#endif } move16(); st->narrowBand = 0; move16(); - if(EQ_16(st->bwidth, NB)) + if ( EQ_16( st->bwidth, NB ) ) { st->narrowBand = 1; move16(); } - IF ( st->narrowBand ) + IF( st->narrowBand ) { st->min_band = 1; move16(); @@ -151,10 +152,10 @@ void core_coder_mode_switch_fx( move16(); } - FOR (i=0; ibits_frame_nominal)) + IF( EQ_16( FrameSizeConfig[i].frame_bits, st->bits_frame_nominal ) ) { move16(); move16(); @@ -166,63 +167,62 @@ void core_coder_mode_switch_fx( } } - st->restrictedMode = getRestrictedMode(st->element_mode, st->total_brate, 0); + st->restrictedMode = getRestrictedMode( st->element_mode, st->total_brate, 0 ); - core_coder_reconfig_fx( st, last_total_bitrate); + core_coder_reconfig_fx( st, last_total_bitrate ); } ELSE { - st->igf = getIgfPresent_fx(st->element_mode, st->total_brate, st->bwidth, st->rf_mode); - init_coder_ace_plus_fx(st, last_total_bitrate, shift, MCT_flag); + st->igf = getIgfPresent_fx( st->element_mode, st->total_brate, st->bwidth, st->rf_mode ); + init_coder_ace_plus_fx( st, last_total_bitrate, shift, MCT_flag ); } test(); - IF( st->igf != 0 && st->hBWE_TD != NULL) + IF( st->igf != 0 && st->hBWE_TD != NULL ) { test(); test(); test(); test(); test(); - IF( (EQ_16(st->bwidth, WB)&&NE_16(st->last_extl,WB_TBE))|| - (EQ_16(st->bwidth, SWB) && NE_16(st->last_extl, SWB_TBE) ) || - (EQ_16(st->bwidth, FB) && NE_16(st->last_extl, FB_TBE) ) ) + IF( ( EQ_16( st->bwidth, WB ) && NE_16( st->last_extl, WB_TBE ) ) || + ( EQ_16( st->bwidth, SWB ) && NE_16( st->last_extl, SWB_TBE ) ) || + ( EQ_16( st->bwidth, FB ) && NE_16( st->last_extl, FB_TBE ) ) ) { /* reset TBE buffers as previous frame wasn't using TBE */ TBEreset_enc_fx( st, st->bwidth ); } ELSE { - set16_fx(hBWE_TD->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); - set16_fx(hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD ); - set16_fx(hBWE_TD->mem_stp_swb_fx, 0, LPC_SHB_ORDER ); - set16_fx(hBWE_TD->mem_zero_swb_fx, 0, LPC_SHB_ORDER ); + set16_fx( hBWE_TD->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); + set16_fx( hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD ); + set16_fx( hBWE_TD->mem_stp_swb_fx, 0, LPC_SHB_ORDER ); + set16_fx( hBWE_TD->mem_zero_swb_fx, 0, LPC_SHB_ORDER ); hBWE_TD->gain_prec_swb_fx = 16384; move16(); /*Q14 = 1 */ } } - IF ( s_and(st->envWeighted!=0, st->enableTcxLpc==0) ) + IF( s_and( st->envWeighted != 0, st->enableTcxLpc == 0 ) ) { /* Unweight the envelope */ - E_LPC_lsp_unweight(st->lsp_old_fx, st->lsp_old_fx, st->lsf_old_fx, st->inv_gamma, M ); + E_LPC_lsp_unweight( st->lsp_old_fx, st->lsp_old_fx, st->lsf_old_fx, st->inv_gamma, M ); move16(); st->envWeighted = 0; } st->enablePlcWaveadjust = 0; move16(); - if (GE_32(st->total_brate, HQ_48k)) + if ( GE_32( st->total_brate, HQ_48k ) ) { st->enablePlcWaveadjust = 1; move16(); } test(); - IF( (GT_32(last_total_bitrate, HQ_32k) || EQ_32(st->last_codec_mode,MODE1)) && EQ_16(st->element_mode, EVS_MONO)) + IF( ( GT_32( last_total_bitrate, HQ_32k ) || EQ_32( st->last_codec_mode, MODE1 ) ) && EQ_16( st->element_mode, EVS_MONO ) ) { move16(); st->glr_reset = 1; } } - diff --git a/lib_enc/core_enc_updt_fx.c b/lib_enc/core_enc_updt_fx.c index 2d83d8e81..9fa4f0ff3 100644 --- a/lib_enc/core_enc_updt_fx.c +++ b/lib_enc/core_enc_updt_fx.c @@ -5,79 +5,80 @@ #include //#include "prot_fx.h" #include "options.h" -#include "cnst.h" /* Common constants */ +#include "cnst.h" /* Common constants */ #include "basop_util.h" #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ -#include "basop_util.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ +#include "basop_util.h" /* Function prototypes */ -void core_encode_update_fx(Encoder_State *st - ) +void core_encode_update_fx( Encoder_State *st ) { Word16 n; TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; /*--------------------------------------------------------------* - * Update Buffers - *---------------------------------------------------------------*/ + * Update Buffers + *---------------------------------------------------------------*/ /* Update Input Signal Buffers */ - n = add(st->encoderPastSamples_enc, st->encoderLookahead_enc); + n = add( st->encoderPastSamples_enc, st->encoderLookahead_enc ); - Copy(st->buf_speech_enc +st->L_frame, st->buf_speech_enc, n); - Copy(st->buf_speech_enc_pe+st->L_frame, st->buf_speech_enc_pe, n); + Copy( st->buf_speech_enc + st->L_frame, st->buf_speech_enc, n ); + Copy( st->buf_speech_enc_pe + st->L_frame, st->buf_speech_enc_pe, n ); - IF(!st->tcxonly) + IF( !st->tcxonly ) { - n = add(st->L_frame, shr(st->L_frame,2)); - Copy(st->buf_wspeech_enc+st->L_frame, st->buf_wspeech_enc, n); + n = add( st->L_frame, shr( st->L_frame, 2 ) ); + Copy( st->buf_wspeech_enc + st->L_frame, st->buf_wspeech_enc, n ); } - IF (hTcxEnc != NULL) + IF( hTcxEnc != NULL ) { - IF(EQ_16(st->core, ACELP_CORE) || EQ_32(st->core_brate, SID_2k40) || EQ_32(st->core_brate, FRAME_NO_DATA) || EQ_32(st->core, AMR_WB_CORE)) + IF( EQ_16( st->core, ACELP_CORE ) || EQ_32( st->core_brate, SID_2k40 ) || EQ_32( st->core_brate, FRAME_NO_DATA ) || EQ_32( st->core, AMR_WB_CORE ) ) { - Copy(st->buf_speech_enc + st->L_frame, hTcxEnc->buf_speech_ltp + st->L_frame, st->L_frame); + Copy( st->buf_speech_enc + st->L_frame, hTcxEnc->buf_speech_ltp + st->L_frame, st->L_frame ); } } - n = add(st->encoderPastSamples_enc, st->encoderLookahead_enc); - Copy(st->buf_synth+st->L_frame, st->buf_synth, add(st->L_frame,L_SUBFR)); - if (hTcxEnc != NULL) + n = add( st->encoderPastSamples_enc, st->encoderLookahead_enc ); + Copy( st->buf_synth + st->L_frame, st->buf_synth, add( st->L_frame, L_SUBFR ) ); + if ( hTcxEnc != NULL ) { - Copy(hTcxEnc->buf_speech_ltp+st->L_frame, hTcxEnc->buf_speech_ltp, n); + Copy( hTcxEnc->buf_speech_ltp + st->L_frame, hTcxEnc->buf_speech_ltp, n ); #ifdef IVAS_CODE - IF (NE_16(st->element_mode, IVAS_CPE_MDCT)) + IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { st->hTcxEnc->kernel_switch_corr_past = 0.f; st->hTcxEnc->kernel_type[0] = MDCT_IV; st->hTcxEnc->kernel_symmetry_past = 0; st->hTcxEnc->enc_ste_pre_corr_past = 0; - move16();move16();move16();move16(); + move16(); + move16(); + move16(); + move16(); } #endif } /* Update previous mode */ - //move16(); - //st->last_core = st->core; /* _DIFF_FLOAT_FIX_ not in float -> remove? */ + // move16(); + // st->last_core = st->core; /* _DIFF_FLOAT_FIX_ not in float -> remove? */ test(); - test(); test(); - IF( ( st->Opt_DTX_ON && LE_32(st->core_brate,SID_2k40) && EQ_16(st->cng_type,FD_CNG)) || (st->tcxonly && EQ_16(st->codec_mode,MODE2))) + test(); + IF( ( st->Opt_DTX_ON && LE_32( st->core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) ) || ( st->tcxonly && EQ_16( st->codec_mode, MODE2 ) ) ) { /* reset LP memories */ - set16_fx( st->mem_MA_fx,0, M ); + set16_fx( st->mem_MA_fx, 0, M ); Copy( GEWB_Ave_fx, st->mem_AR_fx, M ); } - } /*-------------------------------------------------------------------* * core_encode_update_cng_fx() @@ -90,25 +91,24 @@ void core_encode_update_cng_fx( Word16 *A, Word16 *Aw, Word16 Q_new, - Word16 shift -) + Word16 shift ) { Word16 i; Word16 lsp[M]; Word16 lsf[M]; /* 14Q1 * 1.28 */ - Word16 *synth, synth_buf[M+1+L_FRAME_PLUS+L_FRAME_PLUS/2], wsyn[L_FRAME_PLUS]; + Word16 *synth, synth_buf[M + 1 + L_FRAME_PLUS + L_FRAME_PLUS / 2], wsyn[L_FRAME_PLUS]; Word16 *p_A, tmp; Word16 enr_index; Word16 enr; - DTX_ENC_HANDLE hDtxEnc = st->hDtxEnc; - TD_CNG_ENC_HANDLE hTdCngEnc = st->hTdCngEnc; + DTX_ENC_HANDLE hDtxEnc = st->hDtxEnc; + TD_CNG_ENC_HANDLE hTdCngEnc = st->hTdCngEnc; LPD_state_HANDLE hLPDmem = st->hLPDmem; TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; /* LPC -> LSP/lsp */ /* LSP/lsp -> LSF/lsf */ E_LPC_a_lsp_conversion( A, lsp, st->lsp_old_fx, M ); - IF(EQ_16(st->L_frame, L_FRAME16k)) + IF( EQ_16( st->L_frame, L_FRAME16k ) ) { lsp2lsf_fx( lsp, lsf, M, INT_FS_16k_FX ); } @@ -119,43 +119,43 @@ void core_encode_update_cng_fx( /* Update synth memory */ move16(); - synth = synth_buf + (1+M); - Copy( hLPDmem->syn, synth_buf, 1+M ); + synth = synth_buf + ( 1 + M ); + Copy( hLPDmem->syn, synth_buf, 1 + M ); Copy( timeDomainBuffer, synth, st->L_frame ); - Copy( synth+st->L_frame-(1+M), hLPDmem->syn, 1+M ); + Copy( synth + st->L_frame - ( 1 + M ), hLPDmem->syn, 1 + M ); Copy( synth, st->synth, st->L_frame ); /* Update ZIR */ - set16_fx( synth+st->L_frame, 0, shr(st->L_frame,1) ); - E_UTIL_synthesis(1, A, synth+st->L_frame, synth+st->L_frame, shr(st->L_frame,1), &synth[st->L_frame-M], 0, M ); - IF (hTcxEnc != NULL) + set16_fx( synth + st->L_frame, 0, shr( st->L_frame, 1 ) ); + E_UTIL_synthesis( 1, A, synth + st->L_frame, synth + st->L_frame, shr( st->L_frame, 1 ), &synth[st->L_frame - M], 0, M ); + IF( hTcxEnc != NULL ) { - Copy(synth + st->L_frame - (st->L_frame / 2), hTcxEnc->Txnq, shr(st->L_frame, 1)); + Copy( synth + st->L_frame - ( st->L_frame / 2 ), hTcxEnc->Txnq, shr( st->L_frame, 1 ) ); } /* Update pe-synth memory */ move16(); - tmp = synth[-(1+M)]; - E_UTIL_f_preemph2( Q_new-1, synth-M, st->preemph_fac, M+st->L_frame, &tmp ); - Copy( synth+st->L_frame-M, hLPDmem->mem_syn, M ); - Copy( synth+st->L_frame-M, hLPDmem->mem_syn2, M ); + tmp = synth[-( 1 + M )]; + E_UTIL_f_preemph2( Q_new - 1, synth - M, st->preemph_fac, M + st->L_frame, &tmp ); + Copy( synth + st->L_frame - M, hLPDmem->mem_syn, M ); + Copy( synth + st->L_frame - M, hLPDmem->mem_syn2, M ); /* Update excitation memory */ - Copy( hLPDmem->old_exc+st->L_frame, hLPDmem->old_exc, s_max(L_EXC_MEM-st->L_frame, 0 )); - Residu3_fx( A, synth, hLPDmem->old_exc+s_max(L_EXC_MEM-st->L_frame, 0), st->L_frame, 1 ); + Copy( hLPDmem->old_exc + st->L_frame, hLPDmem->old_exc, s_max( L_EXC_MEM - st->L_frame, 0 ) ); + Residu3_fx( A, synth, hLPDmem->old_exc + s_max( L_EXC_MEM - st->L_frame, 0 ), st->L_frame, 1 ); /* Update LP_CNG memory */ - IF( EQ_32(st->core_brate, SID_2k40)) + IF( EQ_32( st->core_brate, SID_2k40 ) ) { /*IVAS_CODE CNG_att is missing */ - enr = cng_energy_fx(st->element_mode, st->bwidth, hDtxEnc->CNG_mode, /*st->hTdCngEnc->CNG_att*/0, hLPDmem->old_exc + s_max(L_EXC_MEM - st->L_frame, 0), st->L_frame, Q_new); + enr = cng_energy_fx( st->element_mode, st->bwidth, hDtxEnc->CNG_mode, /*st->hTdCngEnc->CNG_att*/ 0, hLPDmem->old_exc + s_max( L_EXC_MEM - st->L_frame, 0 ), st->L_frame, Q_new ); /* calculate the energy quantization index */ - enr_index = add(enr, 512 /* Q8(2.0) */); /* enr + 2.0 */ - enr_index = extract_l(L_shr(L_mult0(enr_index, STEP_SID_FX), 12+8)); /* Q0 (8+12-(8+12)) */ + enr_index = add( enr, 512 /* Q8(2.0) */ ); /* enr + 2.0 */ + enr_index = extract_l( L_shr( L_mult0( enr_index, STEP_SID_FX ), 12 + 8 ) ); /* Q0 (8+12-(8+12)) */ /* limit the energy quantization index */ - enr_index = s_min(enr_index, 127); - enr_index = s_max(enr_index, 0); + enr_index = s_min( enr_index, 127 ); + enr_index = s_max( enr_index, 0 ); hTdCngEnc->old_enr_index = enr_index; } @@ -163,18 +163,18 @@ void core_encode_update_cng_fx( /* Update weighted synthesis memory */ move16(); p_A = Aw; - FOR ( i = 0; i < st->L_frame; i += L_SUBFR ) + FOR( i = 0; i < st->L_frame; i += L_SUBFR ) { - Residu3_fx( p_A, &synth[i], &wsyn[i], L_SUBFR, 0); - p_A += (M+1); + Residu3_fx( p_A, &synth[i], &wsyn[i], L_SUBFR, 0 ); + p_A += ( M + 1 ); } move16(); - tmp = sub(st->wspeech_enc[-1],shl(hLPDmem->mem_w0,shift)); + tmp = sub( st->wspeech_enc[-1], shl( hLPDmem->mem_w0, shift ) ); E_UTIL_deemph2( -shift, wsyn, st->preemph_fac, st->L_frame, &tmp ); - hLPDmem->mem_w0 = sub(st->wspeech_enc[st->L_frame-1], tmp); - hLPDmem->mem_w0 =shr(hLPDmem->mem_w0, shift); + hLPDmem->mem_w0 = sub( st->wspeech_enc[st->L_frame - 1], tmp ); + hLPDmem->mem_w0 = shr( hLPDmem->mem_w0, shift ); /* Update LPC-related memories */ @@ -182,18 +182,18 @@ void core_encode_update_cng_fx( Copy( lsf, st->lsf_old_fx, M ); move16(); st->envWeighted = 0; - Copy( A, st->old_Aq_12_8_fx, M+1 ); - st->old_Es_pred_fx=0; + Copy( A, st->old_Aq_12_8_fx, M + 1 ); + st->old_Es_pred_fx = 0; /* Reset acelp memories */ move16(); move16(); - hLPDmem->dm_fx.prev_gain_code = L_deposit_l(0); - set16_fx(hLPDmem->dm_fx.prev_gain_pit,0,6); + hLPDmem->dm_fx.prev_gain_code = L_deposit_l( 0 ); + set16_fx( hLPDmem->dm_fx.prev_gain_pit, 0, 6 ); hLPDmem->dm_fx.prev_state = 0; hLPDmem->tilt_code = TILT_CODE; - hLPDmem->gc_threshold = L_deposit_l(0); + hLPDmem->gc_threshold = L_deposit_l( 0 ); /* Update ace/tcx mode */ move16(); @@ -203,11 +203,10 @@ void core_encode_update_cng_fx( st->hTcxCfg->tcx_curr_overlap_mode = st->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; move16(); - IF(hDtxEnc->first_CNG == 0 ) + IF( hDtxEnc->first_CNG == 0 ) { Copy( st->lsp_old_fx, hDtxEnc->lspCNG_fx, M ); } return; } - diff --git a/lib_enc/core_switching_enc_fx.c b/lib_enc/core_switching_enc_fx.c index f5876ee33..457d93bd8 100644 --- a/lib_enc/core_switching_enc_fx.c +++ b/lib_enc/core_switching_enc_fx.c @@ -2,25 +2,25 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_enc.h" /* Encoder static table prototypes */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "rom_com.h" /* Static table prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_enc.h" /* Encoder static table prototypes */ +#include "rom_com_fx.h" /* Static table prototypes */ +#include "rom_com.h" /* Static table prototypes */ //#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*---------------------------------------------------------------------* -* core_switching_pre_enc() -* -* Preprocessing (preparing) for ACELP/HQ core switching -*---------------------------------------------------------------------*/ + * core_switching_pre_enc() + * + * Preprocessing (preparing) for ACELP/HQ core switching + *---------------------------------------------------------------------*/ void core_switching_pre_enc_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ + Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 *old_inp_12k8, /* i : old input signal @12.8kHz */ const Word16 *old_inp_16k, /* i : old input signal @16kHz */ const Word16 active_cnt, /* i : active frame counter */ @@ -30,7 +30,7 @@ void core_switching_pre_enc_fx( Word16 Sample_Delay_HP, Sample_Delay_LP; Word16 tmp16; Word16 tmp; - SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; + SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; HQ_ENC_HANDLE hHQ_core = st_fx->hHQ_core; TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; @@ -38,46 +38,47 @@ void core_switching_pre_enc_fx( FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD; /* Mode switching */ - test();test();test(); - IF( EQ_16(st_fx->last_codec_mode,MODE2) || (((EQ_16(st_fx->last_core, TCX_20_CORE) - || EQ_16(st_fx->last_core, TCX_10_CORE)) && GT_16(st_fx->element_mode, EVS_MONO)))) + test(); + test(); + test(); + IF( EQ_16( st_fx->last_codec_mode, MODE2 ) || ( ( ( EQ_16( st_fx->last_core, TCX_20_CORE ) || EQ_16( st_fx->last_core, TCX_10_CORE ) ) && GT_16( st_fx->element_mode, EVS_MONO ) ) ) ) { - IF (hLPDmem != NULL) + IF( hLPDmem != NULL ) { st_fx->mem_deemph_fx = hLPDmem->syn[M]; move16(); Copy( hLPDmem->mem_syn2, hLPDmem->mem_syn1_fx, M ); } - if (NE_16(st_fx->element_mode, IVAS_CPE_MDCT)) + if ( NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) { st_fx->igf = 0; move16(); } - IF (hBWE_TD != NULL) + IF( hBWE_TD != NULL ) { - IF(NE_16(st_fx->last_core, ACELP_CORE)) + IF( NE_16( st_fx->last_core, ACELP_CORE ) ) { /* reset BWE memories */ - set16_fx(hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2); - hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l(0); + set16_fx( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); + hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 ); } - set16_fx(hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA(16000, DELAY_FD_BWE_ENC_NS)); + set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); } test(); - IF( EQ_16(st_fx->last_core,TCX_20_CORE)||EQ_16(st_fx->last_core,TCX_10_CORE)) + IF( EQ_16( st_fx->last_core, TCX_20_CORE ) || EQ_16( st_fx->last_core, TCX_10_CORE ) ) { - if (EQ_16(st_fx->element_mode, EVS_MONO)) + if ( EQ_16( st_fx->element_mode, EVS_MONO ) ) { st_fx->last_core = HQ_CORE; move16(); } - IF (hHQ_core != NULL) + IF( hHQ_core != NULL ) { - set32_fx(hHQ_core->last_ni_gain_fx, 0, BANDS_MAX); - set16_fx(hHQ_core->last_env_fx, 0, BANDS_MAX); + set32_fx( hHQ_core->last_ni_gain_fx, 0, BANDS_MAX ); + set16_fx( hHQ_core->last_env_fx, 0, BANDS_MAX ); hHQ_core->last_max_pos_pulse = 0; move16(); @@ -86,21 +87,21 @@ void core_switching_pre_enc_fx( hHQ_core->mode_count1 = 0; move16(); - set16_fx(hHQ_core->prev_SWB_peak_pos, 0, SPT_SHORTEN_SBNUM); + set16_fx( hHQ_core->prev_SWB_peak_pos, 0, SPT_SHORTEN_SBNUM ); hHQ_core->prev_frm_hfe2 = 0; move16(); hHQ_core->prev_stab_hfe2 = 0; move16(); } /*ALDO overlap windowed past: also used in MODE2 but for other MDCT-LB*/ - IF (EQ_16(st_fx->element_mode, EVS_MONO) && hTcxEnc != NULL) + IF( EQ_16( st_fx->element_mode, EVS_MONO ) && hTcxEnc != NULL ) { - set16_fx(hTcxEnc->old_out_fx, 0, L_FRAME32k); + set16_fx( hTcxEnc->old_out_fx, 0, L_FRAME32k ); } } test(); - IF( (EQ_16(st_fx->L_frame,L_FRAME16k))&&(EQ_16(st_fx->last_L_frame,L_FRAME))) + IF( ( EQ_16( st_fx->L_frame, L_FRAME16k ) ) && ( EQ_16( st_fx->last_L_frame, L_FRAME ) ) ) { Copy( st_fx->lsp_old_fx, st_fx->lsp_old16k_fx, M ); @@ -109,11 +110,12 @@ void core_switching_pre_enc_fx( st_fx->use_acelp_preq = 0; move16(); - } - test();test();test(); - IF( EQ_16(st_fx->last_core, -1) && ( EQ_16(st_fx->core, HQ_CORE) || EQ_16(st_fx->core, TCX_20_CORE) || EQ_16(st_fx->core, TCX_10_CORE))) + test(); + test(); + test(); + IF( EQ_16( st_fx->last_core, -1 ) && ( EQ_16( st_fx->core, HQ_CORE ) || EQ_16( st_fx->core, TCX_20_CORE ) || EQ_16( st_fx->core, TCX_10_CORE ) ) ) { /* very first frame is HQ_CORE */ st_fx->last_core = HQ_CORE; @@ -122,10 +124,10 @@ void core_switching_pre_enc_fx( test(); test(); - IF( EQ_16(st_fx->core, HQ_CORE)&&(EQ_16(st_fx->last_core,ACELP_CORE)||EQ_16(st_fx->last_core,AMR_WB_CORE))) /* HQ init */ + IF( EQ_16( st_fx->core, HQ_CORE ) && ( EQ_16( st_fx->last_core, ACELP_CORE ) || EQ_16( st_fx->last_core, AMR_WB_CORE ) ) ) /* HQ init */ { - set32_fx(hHQ_core->last_ni_gain_fx, 0, BANDS_MAX ); - set16_fx(hHQ_core->last_env_fx, 0, BANDS_MAX ); + set32_fx( hHQ_core->last_ni_gain_fx, 0, BANDS_MAX ); + set16_fx( hHQ_core->last_env_fx, 0, BANDS_MAX ); hHQ_core->last_max_pos_pulse = 0; move16(); @@ -134,15 +136,15 @@ void core_switching_pre_enc_fx( hHQ_core->mode_count1 = 0; move16(); - set16_fx(hHQ_core->prev_SWB_peak_pos, 0, SPT_SHORTEN_SBNUM ); + set16_fx( hHQ_core->prev_SWB_peak_pos, 0, SPT_SHORTEN_SBNUM ); hHQ_core->prev_frm_hfe2 = 0; move16(); hHQ_core->prev_stab_hfe2 = 0; move16(); - if (hTcxEnc != NULL) + if ( hTcxEnc != NULL ) { - set16_fx(hTcxEnc->old_out_fx, 0, L_FRAME32k); + set16_fx( hTcxEnc->old_out_fx, 0, L_FRAME32k ); } } @@ -150,9 +152,9 @@ void core_switching_pre_enc_fx( within ACELP_CORE if switching from another bitarate to vbr, last_ppp and last_nelp is always updated in the previous frame */ test(); test(); - IF( EQ_16(st_fx->core, ACELP_CORE)&&(NE_16(st_fx->last_core,ACELP_CORE)||EQ_16(st_fx->last_codec_mode,MODE2))) + IF( EQ_16( st_fx->core, ACELP_CORE ) && ( NE_16( st_fx->last_core, ACELP_CORE ) || EQ_16( st_fx->last_codec_mode, MODE2 ) ) ) { - IF (hSC_VBR != NULL) + IF( hSC_VBR != NULL ) { hSC_VBR->last_last_ppp_mode = 0; move16(); @@ -166,7 +168,7 @@ void core_switching_pre_enc_fx( test(); test(); test(); - IF( EQ_16(st_fx->core, ACELP_CORE)&&(NE_16(st_fx->last_core,ACELP_CORE)||EQ_16(st_fx->last_codec_mode,MODE2)||LE_32(st_fx->last_total_brate,PPP_NELP_2k80))) + IF( EQ_16( st_fx->core, ACELP_CORE ) && ( NE_16( st_fx->last_core, ACELP_CORE ) || EQ_16( st_fx->last_codec_mode, MODE2 ) || LE_32( st_fx->last_total_brate, PPP_NELP_2k80 ) ) ) { st_fx->act_count = 3; move16(); @@ -176,11 +178,10 @@ void core_switching_pre_enc_fx( test(); test(); - IF( ( ( EQ_16(st_fx->core, ACELP_CORE)||EQ_16(st_fx->core,AMR_WB_CORE))&&EQ_16(st_fx->last_core,HQ_CORE)) || - ((EQ_16(st_fx->element_mode, IVAS_CPE_DFT) || EQ_16(st_fx->element_mode, IVAS_CPE_TD) || (EQ_16(st_fx->element_mode, IVAS_CPE_MDCT) - && EQ_16(last_element_mode, IVAS_CPE_DFT))) && EQ_16(active_cnt, 1))) + IF( ( ( EQ_16( st_fx->core, ACELP_CORE ) || EQ_16( st_fx->core, AMR_WB_CORE ) ) && EQ_16( st_fx->last_core, HQ_CORE ) ) || + ( ( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) || ( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) && EQ_16( last_element_mode, IVAS_CPE_DFT ) ) ) && EQ_16( active_cnt, 1 ) ) ) { - IF(EQ_16(st_fx->L_frame, L_FRAME16k)) + IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { Copy( TRWB2_Ave_fx, st_fx->lsf_old_fx, M ); /* init of LSP */ lsf2lsp_fx( st_fx->lsf_old_fx, st_fx->lsp_old_fx, M, INT_FS_16k ); @@ -193,14 +194,14 @@ void core_switching_pre_enc_fx( st_fx->mem_deemph_fx = 0; /* Reset ACELP parameters */ - IF (hLPDmem != NULL) + IF( hLPDmem != NULL ) { move16(); hLPDmem->syn[M] = 0; move16(); - set16_fx(hLPDmem->mem_syn2, 0, M); - set16_fx(hLPDmem->mem_syn, 0, M); - set16_fx(hLPDmem->mem_syn1_fx, 0, M); + set16_fx( hLPDmem->mem_syn2, 0, M ); + set16_fx( hLPDmem->mem_syn, 0, M ); + set16_fx( hLPDmem->mem_syn1_fx, 0, M ); hLPDmem->mem_w0 = 0; move16(); hLPDmem->tilt_code = 0; @@ -208,57 +209,60 @@ void core_switching_pre_enc_fx( hLPDmem->gc_threshold = 0; move32(); /* set16_fx( st_fx->dispMem, 0, 8 ); */ - set16_fx(hLPDmem->dm_fx.prev_gain_pit, 0, 6); + set16_fx( hLPDmem->dm_fx.prev_gain_pit, 0, 6 ); hLPDmem->dm_fx.prev_state = 0; move16(); - hLPDmem->dm_fx.prev_gain_code = L_deposit_l(0); + hLPDmem->dm_fx.prev_gain_code = L_deposit_l( 0 ); } st_fx->Nb_ACELP_frames = 0; move16(); - set16_fx( st_fx->mem_MA_fx,0, M ); + set16_fx( st_fx->mem_MA_fx, 0, M ); Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M ); init_gp_clip_fx( st_fx->clip_var_fx ); st_fx->last_coder_type = GENERIC; move16(); - tmp16 = add(NB_SUBFR,1); + tmp16 = add( NB_SUBFR, 1 ); move16(); - if( EQ_16(st_fx->L_frame,L_FRAME)) + if ( EQ_16( st_fx->L_frame, L_FRAME ) ) { - tmp16=NB_SUBFR; + tmp16 = NB_SUBFR; move16(); } Copy( st_fx->old_pitch_buf_fx + tmp16, st_fx->old_pitch_buf_fx, tmp16 ); - set16_fx( st_fx->old_pitch_buf_fx + tmp16, L_SUBFR,tmp16); + set16_fx( st_fx->old_pitch_buf_fx + tmp16, L_SUBFR, tmp16 ); /* Reset old ACELP buffers */ test(); - IF (EQ_16(st_fx->element_mode, EVS_MONO) && hLPDmem != NULL) + IF( EQ_16( st_fx->element_mode, EVS_MONO ) && hLPDmem != NULL ) { - set16_fx(hLPDmem->old_exc, 0, L_EXC_MEM); + set16_fx( hLPDmem->old_exc, 0, L_EXC_MEM ); } - IF (hBWE_TD != NULL) + IF( hBWE_TD != NULL ) { - set16_fx(hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2); + set16_fx( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); /* reset BWE memories */ hBWE_TD->bwe_non_lin_prev_scale_fx = 0; } - IF(hBWE_FD != NULL) + IF( hBWE_FD != NULL ) { - set16_fx(hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA(16000, DELAY_FD_BWE_ENC_NS) ); + set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); } } - test();test();test(); - IF ((EQ_16(st_fx->core, ACELP_CORE) || EQ_16(st_fx->core, AMR_WB_CORE)) && (EQ_16(st_fx->last_core, TCX_20_CORE) || EQ_16(st_fx->last_core, TCX_10_CORE))) + test(); + test(); + test(); + IF( ( EQ_16( st_fx->core, ACELP_CORE ) || EQ_16( st_fx->core, AMR_WB_CORE ) ) && ( EQ_16( st_fx->last_core, TCX_20_CORE ) || EQ_16( st_fx->last_core, TCX_10_CORE ) ) ) { /* Reset the ACELP core in case of TCX->ACELP core switching */ - st_fx->Nb_ACELP_frames = 0; move16(); + st_fx->Nb_ACELP_frames = 0; + move16(); - IF (hLPDmem != NULL) + IF( hLPDmem != NULL ) { hLPDmem->mem_w0 = 0; move16(); @@ -266,37 +270,41 @@ void core_switching_pre_enc_fx( move16(); hLPDmem->gc_threshold = 0; move32(); - init_gp_clip_fx(st_fx->clip_var_fx); - set16_fx(hLPDmem->dm_fx.prev_gain_pit, 0, 6); + init_gp_clip_fx( st_fx->clip_var_fx ); + set16_fx( hLPDmem->dm_fx.prev_gain_pit, 0, 6 ); hLPDmem->dm_fx.prev_state = 0; move16(); - hLPDmem->dm_fx.prev_gain_code = L_deposit_l(0); + hLPDmem->dm_fx.prev_gain_code = L_deposit_l( 0 ); } - st_fx->last_coder_type = GENERIC; move16(); + st_fx->last_coder_type = GENERIC; + move16(); - tmp16 = shr(st_fx->L_frame, 6); - Copy(st_fx->old_pitch_buf_fx + tmp16, st_fx->old_pitch_buf_fx, tmp16); - set16_fx(st_fx->old_pitch_buf_fx + tmp16, L_SUBFR, tmp16); + tmp16 = shr( st_fx->L_frame, 6 ); + Copy( st_fx->old_pitch_buf_fx + tmp16, st_fx->old_pitch_buf_fx, tmp16 ); + set16_fx( st_fx->old_pitch_buf_fx + tmp16, L_SUBFR, tmp16 ); /* Reset old TD BWE buffers */ - IF (hBWE_TD != NULL) + IF( hBWE_TD != NULL ) { - set16_fx(hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2); - hBWE_TD->bwe_non_lin_prev_scale_fx = 0; move16(); + set16_fx( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); + hBWE_TD->bwe_non_lin_prev_scale_fx = 0; + move16(); } /* reset BWE memories */ - IF (hBWE_FD != NULL) + IF( hBWE_FD != NULL ) { - set16_fx(hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA(16000, DELAY_FD_BWE_ENC_NS));/* TODO : this might not be needed */ + set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); /* TODO : this might not be needed */ } } - test();test();test(); - IF( GE_32(st_fx->input_Fs, 16000)&&NE_16(st_fx->last_extl,WB_BWE)&&EQ_16(st_fx->extl,WB_BWE) && hBWE_FD != NULL) + test(); + test(); + test(); + IF( GE_32( st_fx->input_Fs, 16000 ) && NE_16( st_fx->last_extl, WB_BWE ) && EQ_16( st_fx->extl, WB_BWE ) && hBWE_FD != NULL ) { test(); - IF( NE_16(st_fx->last_extl, SWB_BWE)&&NE_16(st_fx->last_extl,FB_BWE)) + IF( NE_16( st_fx->last_extl, SWB_BWE ) && NE_16( st_fx->last_extl, FB_BWE ) ) { hBWE_FD->prev_mode = NORMAL; move16(); @@ -308,78 +316,81 @@ void core_switching_pre_enc_fx( move16(); } - test();test();test();test();test(); - IF( ( GE_32(st_fx->input_Fs, 32000)&&NE_16(st_fx->last_extl,SWB_BWE)&&EQ_16(st_fx->extl,SWB_BWE))|| - ( GE_32(st_fx->input_Fs, 48000) && NE_16(st_fx->last_extl, FB_BWE) && EQ_16(st_fx->extl, FB_BWE) ) ) + test(); + test(); + test(); + test(); + test(); + IF( ( GE_32( st_fx->input_Fs, 32000 ) && NE_16( st_fx->last_extl, SWB_BWE ) && EQ_16( st_fx->extl, SWB_BWE ) ) || + ( GE_32( st_fx->input_Fs, 48000 ) && NE_16( st_fx->last_extl, FB_BWE ) && EQ_16( st_fx->extl, FB_BWE ) ) ) { /* we are switching to SWB BWE - reset SWB BWE buffers */ - IF( EQ_16(st_fx->L_frame, L_FRAME)) + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { Sample_Delay_HP = NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS ); Sample_Delay_LP = NS2SA( 12800, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS ); - IF (GT_16(st_fx->element_mode, EVS_MONO)) + IF( GT_16( st_fx->element_mode, EVS_MONO ) ) { - IF (EQ_16(st_fx->element_mode, IVAS_CPE_TD)) + IF( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) { - Sample_Delay_HP = NS2SA(16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS - L_MEM_RECALC_TBE_NS); + Sample_Delay_HP = NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS - L_MEM_RECALC_TBE_NS ); } - Sample_Delay_HP = sub(Sample_Delay_HP , NS2SA(16000, DELAY_FIR_RESAMPL_NS)); + Sample_Delay_HP = sub( Sample_Delay_HP, NS2SA( 16000, DELAY_FIR_RESAMPL_NS ) ); } - Copy( old_inp_12k8 + sub(L_INP_MEM + L_FRAME, Sample_Delay_LP), hBWE_FD->old_input_lp_fx, Sample_Delay_LP ); + Copy( old_inp_12k8 + sub( L_INP_MEM + L_FRAME, Sample_Delay_LP ), hBWE_FD->old_input_lp_fx, Sample_Delay_LP ); } ELSE { Sample_Delay_HP = NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_16k_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS ); Sample_Delay_LP = NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_16k_NS ); - IF(GT_16(st_fx->element_mode, EVS_MONO)) + IF( GT_16( st_fx->element_mode, EVS_MONO ) ) { - IF(EQ_16(st_fx->element_mode, IVAS_CPE_TD)) + IF( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) { - Sample_Delay_HP = NS2SA(16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_16k_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS - L_MEM_RECALC_TBE_NS); + Sample_Delay_HP = NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_16k_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS - L_MEM_RECALC_TBE_NS ); } - Sample_Delay_HP = sub(Sample_Delay_HP,NS2SA(16000, DELAY_FIR_RESAMPL_NS)); + Sample_Delay_HP = sub( Sample_Delay_HP, NS2SA( 16000, DELAY_FIR_RESAMPL_NS ) ); } - Copy( old_inp_16k + sub(L_INP_MEM + L_FRAME, Sample_Delay_LP), hBWE_FD->old_input_lp_fx, Sample_Delay_LP ); + Copy( old_inp_16k + sub( L_INP_MEM + L_FRAME, Sample_Delay_LP ), hBWE_FD->old_input_lp_fx, Sample_Delay_LP ); } - tmp = sub(L_LOOK_16k + L_SUBFR16k, Sample_Delay_HP); + tmp = sub( L_LOOK_16k + L_SUBFR16k, Sample_Delay_HP ); Copy( &hBWE_TD->old_speech_shb_fx[tmp], hBWE_FD->new_input_hp_fx, Sample_Delay_HP ); - add(0,0); + add( 0, 0 ); - IF (NE_16(st_fx->last_extl,WB_BWE)) + IF( NE_16( st_fx->last_extl, WB_BWE ) ) { hBWE_FD->prev_mode = NORMAL; move16(); hBWE_FD->modeCount = 0; move16(); } - hBWE_FD->EnergyLF_fx = L_deposit_l(0); + hBWE_FD->EnergyLF_fx = L_deposit_l( 0 ); hBWE_FD->prev_L_swb_norm1 = 8; - move16();/*8.0 in Q0 */ + move16(); /*8.0 in Q0 */ st_fx->EnergyLT_fx_exp = 30; move16(); /* Set to a High Exponent so it is 1^-30 */ - } /*---------------------------------------------------------------------* * band-width switching from WB -> SWB/FB *---------------------------------------------------------------------*/ #ifdef IVAS_CODE - IF (GT_16(st_fx->element_mode, EVS_MONO)) + IF( GT_16( st_fx->element_mode, EVS_MONO ) ) { - IF (st_fx->bwidth_sw_cnt_fx == 0) + IF( st_fx->bwidth_sw_cnt_fx == 0 ) { - IF (GE_16(st_fx->bwidth, SWB) && EQ_16(st_fx->last_bwidth,WB)) + IF( GE_16( st_fx->bwidth, SWB ) && EQ_16( st_fx->last_bwidth, WB ) ) { - st_fx->bwidth_sw_cnt_fx = add(st_fx->bwidth_sw_cnt_fx, 1); + st_fx->bwidth_sw_cnt_fx = add( st_fx->bwidth_sw_cnt_fx, 1 ); } } ELSE { - st_fx->bwidth_sw_cnt_fx = add(st_fx->bwidth_sw_cnt_fx, 1); + st_fx->bwidth_sw_cnt_fx = add( st_fx->bwidth_sw_cnt_fx, 1 ); - IF (EQ_16(st_fx->bwidth_sw_cnt_fx, BWS_TRAN_PERIOD)) + IF( EQ_16( st_fx->bwidth_sw_cnt_fx, BWS_TRAN_PERIOD ) ) { st_fx->bwidth_sw_cnt_fx = 0; move16(); @@ -392,126 +403,138 @@ void core_switching_pre_enc_fx( } - /*---------------------------------------------------------------------* -* core_switching_post_enc() -* -* Postprocessing for ACELP/HQ core switching -*---------------------------------------------------------------------*/ + * core_switching_post_enc() + * + * Postprocessing for ACELP/HQ core switching + *---------------------------------------------------------------------*/ void core_switching_post_enc_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 old_inp_12k8[], /* i : input signal @12.8 kHz Qinp */ - const Word16 old_inp_16k[], /* i : input signal @16 kHz Qinp */ - const Word16 A[], /* i : unquant. LP filter coefs. (Q12) */ + const Word16 old_inp_12k8[], /* i : input signal @12.8 kHz Qinp */ + const Word16 old_inp_16k[], /* i : input signal @16 kHz Qinp */ + const Word16 A[], /* i : unquant. LP filter coefs. (Q12) */ Word16 Qshift, Word16 Q_new, - const Word16 Qsp, /* i/o : Q from acelp synthsis */ - Word16 *Qmus /* i/o : Q from mdct synthsis / Q of output synthesis */ + const Word16 Qsp, /* i/o : Q from acelp synthsis */ + Word16 *Qmus /* i/o : Q from mdct synthsis / Q of output synthesis */ ) { TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD; - IF( EQ_16(st_fx->core, HQ_CORE)) + IF( EQ_16( st_fx->core, HQ_CORE ) ) { st_fx->use_acelp_preq = 0; move16(); - test();test(); - IF( ( EQ_16(st_fx->last_core, ACELP_CORE)||EQ_16(st_fx->last_core,AMR_WB_CORE)) && EQ_16(st_fx->element_mode, EVS_MONO) ) /* core switching ==> CELP subframe encoding */ + test(); + test(); + IF( ( EQ_16( st_fx->last_core, ACELP_CORE ) || EQ_16( st_fx->last_core, AMR_WB_CORE ) ) && EQ_16( st_fx->element_mode, EVS_MONO ) ) /* core switching ==> CELP subframe encoding */ { - acelp_core_switch_enc_fx( st_fx, old_inp_12k8 + L_INP_MEM - NS2SA_fx2(INT_FS_FX, ACELP_LOOK_NS), - old_inp_16k + L_INP_MEM - NS2SA_fx2(INT_FS_16k, ACELP_LOOK_NS), A, Qshift, Q_new ); + acelp_core_switch_enc_fx( st_fx, old_inp_12k8 + L_INP_MEM - NS2SA_fx2( INT_FS_FX, ACELP_LOOK_NS ), + old_inp_16k + L_INP_MEM - NS2SA_fx2( INT_FS_16k, ACELP_LOOK_NS ), A, Qshift, Q_new ); } - hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l(0); + hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 ); hBWE_FD->mem_deemph_old_syn_fx = 0; move16(); - } ELSE { - *Qmus=Qsp; /* Write Qout */ + *Qmus = Qsp; /* Write Qout */ move16(); - IF (hBWE_TD == NULL) + IF( hBWE_TD == NULL ) { return; } /* reset SWB TBE buffers */ test(); - IF( EQ_16(st_fx->extl, WB_TBE)&&NE_16(st_fx->last_extl,WB_TBE)) + IF( EQ_16( st_fx->extl, WB_TBE ) && NE_16( st_fx->last_extl, WB_TBE ) ) { - wb_tbe_extras_reset_fx(hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx ); + wb_tbe_extras_reset_fx( hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx ); - IF ( NE_16(st_fx->last_extl, WB_BWE)) + IF( NE_16( st_fx->last_extl, WB_BWE ) ) { - set16_fx(hBWE_TD->decim_state1_fx, 0, 2*ALLPASSSECTIONS_STEEP+1 ); - set16_fx(hBWE_TD->decim_state2_fx, 0, 2*ALLPASSSECTIONS_STEEP+1 ); + set16_fx( hBWE_TD->decim_state1_fx, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); + set16_fx( hBWE_TD->decim_state2_fx, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); } - set16_fx(hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD/4 ); - set16_fx(hBWE_TD->syn_overlap_fx, 0, L_SHB_LAHEAD ); - set32_fx(hBWE_TD->mem_csfilt_fx, 0, 2 ); + set16_fx( hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD / 4 ); + set16_fx( hBWE_TD->syn_overlap_fx, 0, L_SHB_LAHEAD ); + set32_fx( hBWE_TD->mem_csfilt_fx, 0, 2 ); } - test();test();test();test(); - test();test();test();test();test();test(); - test();IF( (EQ_16(st_fx->extl, SWB_TBE)||EQ_16(st_fx->extl,FB_TBE))&& - ( EQ_16(st_fx->last_core,HQ_CORE) || NE_16(st_fx->L_frame, st_fx->last_L_frame) || - ( NE_16(st_fx->last_extl, SWB_TBE) && NE_16(st_fx->last_extl, FB_TBE) && NE_16(st_fx->last_core, TCX_20_CORE) && NE_16(st_fx->last_core, TCX_10_CORE)) ) - ) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( EQ_16( st_fx->extl, SWB_TBE ) || EQ_16( st_fx->extl, FB_TBE ) ) && + ( EQ_16( st_fx->last_core, HQ_CORE ) || NE_16( st_fx->L_frame, st_fx->last_L_frame ) || + ( NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) && NE_16( st_fx->last_core, TCX_20_CORE ) && NE_16( st_fx->last_core, TCX_10_CORE ) ) ) ) { - set16_fx(hBWE_TD->state_ana_filt_shb_fx, 0, (2*ALLPASSSECTIONS_STEEP+1) ); - set16_fx(hBWE_TD->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k ); - + set16_fx( hBWE_TD->state_ana_filt_shb_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); + set16_fx( hBWE_TD->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k ); + #ifdef IVAS_CODE - set16_fx(hBWE_TD->mem_shb_res_fx, 0, MAX_LEN_MA_FILTER); - set16_fx(hBWE_TD->old_EnvSHBres_fx, 0, L_FRAME4k); + set16_fx( hBWE_TD->mem_shb_res_fx, 0, MAX_LEN_MA_FILTER ); + set16_fx( hBWE_TD->old_EnvSHBres_fx, 0, L_FRAME4k ); hBWE_TD->old_mean_EnvSHBres_fx = 0; hBWE_TD->prev_enr_EnvSHBres_fx = 32767; /*Q15 ??? */ hBWE_TD->prev_shb_env_tilt_fx = 0; hBWE_TD->prev_pow_exc16kWhtnd_fx = 32767; /*Q15 ??? */ - hBWE_TD->prev_mix_factor_fx = 32767; /*Q15 ??? */ + hBWE_TD->prev_mix_factor_fx = 32767; /*Q15 ??? */ hBWE_TD->prev_Env_error_fx = 0; - move16();move16();move16();move16();move16();move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); #endif - swb_tbe_reset_fx(hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, - hBWE_TD->syn_overlap_fx, hBWE_TD->state_syn_shbexc_fx, &(hBWE_TD->tbe_demph_fx), &(hBWE_TD->tbe_premph_fx), - hBWE_TD->mem_stp_swb_fx, &(hBWE_TD->gain_prec_swb_fx)); + swb_tbe_reset_fx( hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, + hBWE_TD->syn_overlap_fx, hBWE_TD->state_syn_shbexc_fx, &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), + hBWE_TD->mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ) ); - set16_fx(hBWE_TD->dec_2_over_3_mem_fx,0, 12 ); - set16_fx(hBWE_TD->dec_2_over_3_mem_lp_fx,0, 6 ); + set16_fx( hBWE_TD->dec_2_over_3_mem_fx, 0, 12 ); + set16_fx( hBWE_TD->dec_2_over_3_mem_lp_fx, 0, 6 ); } - ELSE IF( ( EQ_16(st_fx->extl, SWB_TBE)||EQ_16(st_fx->extl,FB_TBE))&& - ( NE_32(st_fx->last_total_brate, st_fx->total_brate) || NE_16(st_fx->last_bwidth, st_fx->bwidth) || - NE_16(st_fx->last_codec_mode, MODE1) || NE_16(st_fx->rf_mode, st_fx->rf_mode_last) ) ) + ELSE IF( ( EQ_16( st_fx->extl, SWB_TBE ) || EQ_16( st_fx->extl, FB_TBE ) ) && + ( NE_32( st_fx->last_total_brate, st_fx->total_brate ) || NE_16( st_fx->last_bwidth, st_fx->bwidth ) || + NE_16( st_fx->last_codec_mode, MODE1 ) || NE_16( st_fx->rf_mode, st_fx->rf_mode_last ) ) ) { - set16_fx(hBWE_TD->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); - set16_fx(hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD ); - set16_fx(hBWE_TD->mem_stp_swb_fx, 0, LPC_SHB_ORDER ); - set16_fx(hBWE_TD->mem_zero_swb_fx, 0, LPC_SHB_ORDER ); + set16_fx( hBWE_TD->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); + set16_fx( hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD ); + set16_fx( hBWE_TD->mem_stp_swb_fx, 0, LPC_SHB_ORDER ); + set16_fx( hBWE_TD->mem_zero_swb_fx, 0, LPC_SHB_ORDER ); hBWE_TD->gain_prec_swb_fx = 16384; move16(); /*Q14 = 1 */ } - ELSE IF (EQ_16(st_fx->last_core, TCX_20_CORE) || EQ_16(st_fx->last_core, TCX_10_CORE)) + ELSE IF( EQ_16( st_fx->last_core, TCX_20_CORE ) || EQ_16( st_fx->last_core, TCX_10_CORE ) ) { - TBEreset_enc_fx( st_fx, st_fx->bwidth); + TBEreset_enc_fx( st_fx, st_fx->bwidth ); } test(); test(); - IF( EQ_16(st_fx->extl, FB_TBE) && ((NE_16(st_fx->last_extl, FB_TBE) && NE_16(st_fx->last_core, TCX_20_CORE) && NE_16(st_fx->last_core, TCX_10_CORE)) || NE_16(st_fx->L_frame, st_fx->last_L_frame))) + IF( EQ_16( st_fx->extl, FB_TBE ) && ( ( NE_16( st_fx->last_extl, FB_TBE ) && NE_16( st_fx->last_core, TCX_20_CORE ) && NE_16( st_fx->last_core, TCX_10_CORE ) ) || NE_16( st_fx->L_frame, st_fx->last_L_frame ) ) ) { - set16_fx(hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); + set16_fx( hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); hBWE_TD->fb_tbe_demph_fx = 0; - fb_tbe_reset_enc_fx(hBWE_TD->elliptic_bpf_2_48k_mem_fx, &hBWE_TD->prev_fb_energy_fx, hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q,&hBWE_TD->prev_fb_energy_fx_Q); + fb_tbe_reset_enc_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx, &hBWE_TD->prev_fb_energy_fx, hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, &hBWE_TD->prev_fb_energy_fx_Q ); } /* Fade towards init value for non HQ_CORE */ - IF (st_fx->hHQ_core != NULL) + IF( st_fx->hHQ_core != NULL ) { #ifdef IVAS_CODE - st_fx->hHQ_core->crest_lp = HQ_CREST_FAC_SM * (st_fx->hHQ_core->crest_lp) + (1.0f - HQ_CREST_FAC_SM) * HQ_CREST_THRESHOLD; - st_fx->hHQ_core->crest_mod_lp = HQ_CREST_FAC_SM * (st_fx->hHQ_core->crest_mod_lp) + (1.0f - HQ_CREST_FAC_SM) * HQ_CREST_MOD_THRESHOLD; + st_fx->hHQ_core->crest_lp = HQ_CREST_FAC_SM * ( st_fx->hHQ_core->crest_lp ) + ( 1.0f - HQ_CREST_FAC_SM ) * HQ_CREST_THRESHOLD; + st_fx->hHQ_core->crest_mod_lp = HQ_CREST_FAC_SM * ( st_fx->hHQ_core->crest_mod_lp ) + ( 1.0f - HQ_CREST_FAC_SM ) * HQ_CREST_MOD_THRESHOLD; #endif } } @@ -520,132 +543,131 @@ void core_switching_post_enc_fx( } /*---------------------------------------------------------------------* -* core_switching_hq_prepare_enc() -* -* Preprocessing in the first HQ frame after ACELP frame -* - modify bit allocation for HQcore removing CELP subframe budget -* - update st->old_wtda to modify windows at the encoder -*---------------------------------------------------------------------*/ + * core_switching_hq_prepare_enc() + * + * Preprocessing in the first HQ frame after ACELP frame + * - modify bit allocation for HQcore removing CELP subframe budget + * - update st->old_wtda to modify windows at the encoder + *---------------------------------------------------------------------*/ void core_switching_hq_prepare_enc_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ + Encoder_State *st_fx, /* i/o: encoder state structure */ Word16 *num_bits, /* i/o: bit budget update */ - const Word16 input_frame, /* i : frame length */ + const Word16 input_frame, /* i : frame length */ Word32 *wtda_audio, /* shall be q_audio + 15, audio allready scalled in wtda function */ - const Word16 *audio -) + const Word16 *audio ) { - Word16 delta, Loverlapp, i; + Word16 delta, Loverlapp, i; Word16 tmp16; Word32 cbrate, *pt_32; const Word16 *pt_cos, *pt_16; Word16 n; TCX_ENC_HANDLE hTcxEnc = st_fx->hTcxEnc; - SWITCH (input_frame) + SWITCH( input_frame ) { - case L_FRAME8k: - delta = 1; - move16(); - pt_cos= sin_switch_8; - BREAK; - case L_FRAME16k: - delta = 2; - move16(); - pt_cos= sin_switch_16; - BREAK; - case L_FRAME32k: - delta = 4; - move16(); - pt_cos= sin_switch_32; - BREAK; - default : - delta = 6; - move16(); - pt_cos= sin_switch_48; - BREAK; + case L_FRAME8k: + delta = 1; + move16(); + pt_cos = sin_switch_8; + BREAK; + case L_FRAME16k: + delta = 2; + move16(); + pt_cos = sin_switch_16; + BREAK; + case L_FRAME32k: + delta = 4; + move16(); + pt_cos = sin_switch_32; + BREAK; + default: + delta = 6; + move16(); + pt_cos = sin_switch_48; + BREAK; } /* set switching frame bitrate */ - IF( EQ_16(st_fx->last_L_frame, L_FRAME)) + IF( EQ_16( st_fx->last_L_frame, L_FRAME ) ) { - IF( GT_32(st_fx->core_brate, ACELP_24k40)) + IF( GT_32( st_fx->core_brate, ACELP_24k40 ) ) { - cbrate = L_add(ACELP_24k40, 0); + cbrate = L_add( ACELP_24k40, 0 ); } ELSE { - cbrate = L_add(st_fx->core_brate, 0); + cbrate = L_add( st_fx->core_brate, 0 ); } /* subtract ACELP switching frame bits */ - IF( GE_32(st_fx->core_brate, ACELP_11k60)) + IF( GE_32( st_fx->core_brate, ACELP_11k60 ) ) { - (*num_bits) = sub((*num_bits), 1); /* LP_FLAG bit */ + ( *num_bits ) = sub( ( *num_bits ), 1 ); /* LP_FLAG bit */ } - *num_bits = sub( (*num_bits), ACB_bits_tbl[BIT_ALLOC_IDX_fx(cbrate, GENERIC, 0, 0)] ); /* pitch bits*/ - *num_bits = sub( (*num_bits), gain_bits_tbl[BIT_ALLOC_IDX_fx(cbrate, TRANSITION, 0, 0)] ); /* gain bits */ - *num_bits = sub( (*num_bits), FCB_bits_tbl[BIT_ALLOC_IDX_fx(cbrate, GENERIC, 0, 0)] ); /* FCB bits */ + *num_bits = sub( ( *num_bits ), ACB_bits_tbl[BIT_ALLOC_IDX_fx( cbrate, GENERIC, 0, 0 )] ); /* pitch bits*/ + *num_bits = sub( ( *num_bits ), gain_bits_tbl[BIT_ALLOC_IDX_fx( cbrate, TRANSITION, 0, 0 )] ); /* gain bits */ + *num_bits = sub( ( *num_bits ), FCB_bits_tbl[BIT_ALLOC_IDX_fx( cbrate, GENERIC, 0, 0 )] ); /* FCB bits */ } - ELSE /* L_frame == L_FRAME16k */ + ELSE /* L_frame == L_FRAME16k */ { - IF( LE_32(st_fx->core_brate, ACELP_8k00)) + IF( LE_32( st_fx->core_brate, ACELP_8k00 ) ) { - cbrate = L_add(ACELP_8k00, 0); + cbrate = L_add( ACELP_8k00, 0 ); } - ELSE IF( LE_32(st_fx->core_brate, ACELP_14k80)) + ELSE IF( LE_32( st_fx->core_brate, ACELP_14k80 ) ) { - cbrate = L_add(ACELP_14k80, 0); + cbrate = L_add( ACELP_14k80, 0 ); } ELSE { - cbrate = L_min(st_fx->core_brate, ACELP_22k60); + cbrate = L_min( st_fx->core_brate, ACELP_22k60 ); } /* subtract ACELP switching frame bits */ - IF( GE_32(st_fx->core_brate, ACELP_11k60)) + IF( GE_32( st_fx->core_brate, ACELP_11k60 ) ) { - (*num_bits) = sub((*num_bits), 1); /* LP_FLAG bit */ + ( *num_bits ) = sub( ( *num_bits ), 1 ); /* LP_FLAG bit */ } - *num_bits = sub((*num_bits), ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(cbrate, GENERIC, 0, 0)]); /* pitch bits*/ - *num_bits = sub((*num_bits), gain_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(cbrate, GENERIC, 0, 0)]); /* gain bits */ - *num_bits = sub((*num_bits), FCB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(cbrate, GENERIC, 0, 0)]); /* FCB bits */ + *num_bits = sub( ( *num_bits ), ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx( cbrate, GENERIC, 0, 0 )] ); /* pitch bits*/ + *num_bits = sub( ( *num_bits ), gain_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx( cbrate, GENERIC, 0, 0 )] ); /* gain bits */ + *num_bits = sub( ( *num_bits ), FCB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx( cbrate, GENERIC, 0, 0 )] ); /* FCB bits */ } /* subtract BWE bits */ test(); test(); - IF( !( ( EQ_16(inner_frame_tbl[st_fx->bwidth], L_FRAME16k)&&EQ_16(st_fx->last_L_frame,L_FRAME16k))||EQ_16(inner_frame_tbl[st_fx->bwidth],L_FRAME8k))) + IF( !( ( EQ_16( inner_frame_tbl[st_fx->bwidth], L_FRAME16k ) && EQ_16( st_fx->last_L_frame, L_FRAME16k ) ) || EQ_16( inner_frame_tbl[st_fx->bwidth], L_FRAME8k ) ) ) { - *num_bits = sub((*num_bits), (NOOFGAINBITS1 + AUDIODELAYBITS)); + *num_bits = sub( ( *num_bits ), ( NOOFGAINBITS1 + AUDIODELAYBITS ) ); } /* Transition window at the encoder */ - n=i_mult2(N_ZERO_8,delta); - Loverlapp=i_mult2(SWITCH_OVERLAP_8k,delta); + n = i_mult2( N_ZERO_8, delta ); + Loverlapp = i_mult2( SWITCH_OVERLAP_8k, delta ); /*Overflow=0; */ - pt_32 = wtda_audio+shr(input_frame,1); - pt_16 = audio+sub(n,1); - tmp16 = sub(shr(input_frame,1),Loverlapp); + pt_32 = wtda_audio + shr( input_frame, 1 ); + pt_16 = audio + sub( n, 1 ); + tmp16 = sub( shr( input_frame, 1 ), Loverlapp ); FOR( i = 0; i < tmp16; i++ ) { /* wtda_audio[i+input_frame/2] = - audio[n-i-1]; */ - *pt_32++=L_negate(L_shr(L_deposit_h(*pt_16--),1)); /* Q +16 -1 */ + *pt_32++ = L_negate( L_shr( L_deposit_h( *pt_16-- ), 1 ) ); /* Q +16 -1 */ } pt_cos = pt_cos + Loverlapp - 1; - FOR( i = tmp16; i < shr(input_frame,1); i++ ) + FOR( i = tmp16; i < shr( input_frame, 1 ); i++ ) { /* *pt_32++ = - audio[n-i-1] *(float)cos((i+1-input_frame/2+Loverlapp)*EVS_PI/(2*(Loverlapp+1))); win=cos() */ - *pt_32++=L_negate(L_mult0(*pt_16--,*pt_cos--)); + *pt_32++ = L_negate( L_mult0( *pt_16--, *pt_cos-- ) ); } - IF(hTcxEnc != NULL) + IF( hTcxEnc != NULL ) { /* reset state of old_out if switching */ - set16_fx(hTcxEnc->old_out_fx, 0, L_FRAME32k); + set16_fx( hTcxEnc->old_out_fx, 0, L_FRAME32k ); } return; } diff --git a/lib_enc/corr_xh_fx.c b/lib_enc/corr_xh_fx.c index ead9e753a..698d14830 100644 --- a/lib_enc/corr_xh_fx.c +++ b/lib_enc/corr_xh_fx.c @@ -5,16 +5,16 @@ #include "options.h" #include "cnst.h" //#include "prot_fx.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* * local constants * -----------------------------------------------------------------*/ -#define NB_TRACK 4 -#define STEP NB_TRACK +#define NB_TRACK 4 +#define STEP NB_TRACK /*-------------------------------------------------------------------* * corr_xh_fx: @@ -25,9 +25,9 @@ * y[i]=sum(j=i,l-1) x[j]*h[j-i], i=0,l-1 *-------------------------------------------------------------------*/ void corr_xh_fx( - const Word16 x[], /* i : target signal */ - Word16 dn[], /* o : correlation between x[] and h[] */ - const Word16 h[] /* i : impulse response (of weighted synthesis filter) */ + const Word16 x[], /* i : target signal */ + Word16 dn[], /* o : correlation between x[] and h[] */ + const Word16 h[] /* i : impulse response (of weighted synthesis filter) */ ) { Word16 i, j, k; @@ -37,47 +37,47 @@ void corr_xh_fx( #endif /* first keep the result on 32 bits and find absolute maximum */ - L_tot = L_deposit_l(1); + L_tot = L_deposit_l( 1 ); - FOR (k = 0; k < NB_TRACK; k++) + FOR( k = 0; k < NB_TRACK; k++ ) { - L_maxloc = L_deposit_l(0); - FOR (i = k; i < L_SUBFR; i += STEP) + L_maxloc = L_deposit_l( 0 ); + FOR( i = k; i < L_SUBFR; i += STEP ) { - L_tmp = L_mac(1L, x[i], h[0]); /* 1 -> to avoid null dn[] */ - FOR (j = i; j < L_SUBFR-1; j++) + L_tmp = L_mac( 1L, x[i], h[0] ); /* 1 -> to avoid null dn[] */ + FOR( j = i; j < L_SUBFR - 1; j++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_mac_o(L_tmp, x[j+1], h[j+1 - i], &Overflow); + L_tmp = L_mac_o( L_tmp, x[j + 1], h[j + 1 - i], &Overflow ); #else - L_tmp = L_mac(L_tmp, x[j+1], h[j+1 - i]); + L_tmp = L_mac( L_tmp, x[j + 1], h[j + 1 - i] ); #endif } y32[i] = L_tmp; move32(); - L_tmp = L_abs(L_tmp); - L_maxloc = L_max(L_tmp, L_maxloc); + L_tmp = L_abs( L_tmp ); + L_maxloc = L_max( L_tmp, L_maxloc ); } /* tot += 3*max / 8 */ - L_maxloc = L_shr(L_maxloc, 2); + L_maxloc = L_shr( L_maxloc, 2 ); #ifdef BASOP_NOGLOB - L_tot = L_add_o(L_tot, L_maxloc, &Overflow); /* +max/4 */ - L_tot = L_add_o(L_tot, L_shr(L_maxloc, 1), &Overflow); /* +max/8 */ + L_tot = L_add_o( L_tot, L_maxloc, &Overflow ); /* +max/4 */ + L_tot = L_add_o( L_tot, L_shr( L_maxloc, 1 ), &Overflow ); /* +max/8 */ #else - L_tot = L_add(L_tot, L_maxloc); /* +max/4 */ - L_tot = L_add(L_tot, L_shr(L_maxloc, 1)); /* +max/8 */ + L_tot = L_add( L_tot, L_maxloc ); /* +max/4 */ + L_tot = L_add( L_tot, L_shr( L_maxloc, 1 ) ); /* +max/8 */ #endif } /* Find the number of right shifts to do on y32[] so that */ /* 6.0 x sumation of max of dn[] in each track not saturate. */ - j = sub(norm_l(L_tot), 4); /* 4 -> 16 x tot */ + j = sub( norm_l( L_tot ), 4 ); /* 4 -> 16 x tot */ - FOR (i = 0; i < L_SUBFR; i++) + FOR( i = 0; i < L_SUBFR; i++ ) { - dn[i] = round_fx(L_shl(y32[i], j)); + dn[i] = round_fx( L_shl( y32[i], j ) ); } return; } diff --git a/lib_enc/decision_matrix_enc_fx.c b/lib_enc/decision_matrix_enc_fx.c index a61b42e70..5f0eaf0cd 100644 --- a/lib_enc/decision_matrix_enc_fx.c +++ b/lib_enc/decision_matrix_enc_fx.c @@ -5,15 +5,15 @@ #include #include #include "options.h" -#include "cnst.h" /* Common constants */ +#include "cnst.h" /* Common constants */ //#include "prot_fx.h" #include "stat_enc.h" #include "rom_com_fx.h" #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ -#include "basop_util.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ +#include "basop_util.h" /* Function prototypes */ /*-----------------------------------------------------------------* @@ -82,12 +82,12 @@ *-----------------------------------------------------------------*/ void decision_matrix_enc_fx( - Encoder_State *st_fx, /* i : encoder state structure */ - Word16 *hq_core_type /* o : HQ core type */ + Encoder_State *st_fx, /* i : encoder state structure */ + Word16 *hq_core_type /* o : HQ core type */ ) { - SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; - + SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; + /* initialization */ st_fx->core = -1; move16(); @@ -102,13 +102,13 @@ void decision_matrix_enc_fx( /* SID and FRAME_NO_DATA frames */ test(); test(); - IF( st_fx->Opt_DTX_ON && (EQ_32(st_fx->core_brate,SID_2k40)||EQ_32(st_fx->core_brate,FRAME_NO_DATA))) + IF( st_fx->Opt_DTX_ON && ( EQ_32( st_fx->core_brate, SID_2k40 ) || EQ_32( st_fx->core_brate, FRAME_NO_DATA ) ) ) { st_fx->core = ACELP_CORE; move16(); test(); - if( GE_32(st_fx->input_Fs,32000)&&GE_16(st_fx->bwidth,SWB)) + if ( GE_32( st_fx->input_Fs, 32000 ) && GE_16( st_fx->bwidth, SWB ) ) { st_fx->extl = SWB_CNG; move16(); @@ -120,10 +120,10 @@ void decision_matrix_enc_fx( return; } - st_fx->core_brate = L_deposit_l(0); + st_fx->core_brate = L_deposit_l( 0 ); /* SC-VBR */ - IF ( st_fx->Opt_SC_VBR ) + IF( st_fx->Opt_SC_VBR ) { /* SC-VBR */ st_fx->core = ACELP_CORE; @@ -136,13 +136,13 @@ void decision_matrix_enc_fx( test(); test(); test(); - IF ( EQ_16(hSC_VBR->ppp_mode,1)) + IF( EQ_16( hSC_VBR->ppp_mode, 1 ) ) { /* PPP mode */ st_fx->core_brate = PPP_NELP_2k80; move16(); } - ELSE IF ( ( ( EQ_16(st_fx->coder_type,UNVOICED)||EQ_16(st_fx->coder_type,TRANSITION))&&st_fx->sp_aud_decision1==0)||NE_16(st_fx->bwidth,NB)) + ELSE IF( ( ( EQ_16( st_fx->coder_type, UNVOICED ) || EQ_16( st_fx->coder_type, TRANSITION ) ) && st_fx->sp_aud_decision1 == 0 ) || NE_16( st_fx->bwidth, NB ) ) { test(); test(); @@ -155,9 +155,9 @@ void decision_matrix_enc_fx( test(); test(); test(); - IF ( EQ_16(st_fx->coder_type,UNVOICED)&&EQ_16(st_fx->vad_flag,1)&& - ( ( GE_16(st_fx->last_bwidth,SWB) && st_fx->last_Opt_SC_VBR == 1 ) || LT_16(st_fx->last_bwidth, SWB) ) && - ( NE_16(st_fx->last_core,HQ_CORE) || NE_16(st_fx->bwidth, NB) ) ) + IF( EQ_16( st_fx->coder_type, UNVOICED ) && EQ_16( st_fx->vad_flag, 1 ) && + ( ( GE_16( st_fx->last_bwidth, SWB ) && st_fx->last_Opt_SC_VBR == 1 ) || LT_16( st_fx->last_bwidth, SWB ) ) && + ( NE_16( st_fx->last_core, HQ_CORE ) || NE_16( st_fx->bwidth, NB ) ) ) { /* NELP mode */ hSC_VBR->nelp_mode = 1; @@ -165,8 +165,8 @@ void decision_matrix_enc_fx( st_fx->core_brate = PPP_NELP_2k80; move32(); } - ELSE IF ( EQ_16(st_fx->coder_type,TRANSITION)||(EQ_16(st_fx->coder_type,UNVOICED)&&NE_16(hSC_VBR->nelp_mode,1))|| - ( ( EQ_16(st_fx->coder_type,AUDIO) || EQ_16(st_fx->coder_type,INACTIVE) ) && NE_16(st_fx->bwidth, NB) ) ) + ELSE IF( EQ_16( st_fx->coder_type, TRANSITION ) || ( EQ_16( st_fx->coder_type, UNVOICED ) && NE_16( hSC_VBR->nelp_mode, 1 ) ) || + ( ( EQ_16( st_fx->coder_type, AUDIO ) || EQ_16( st_fx->coder_type, INACTIVE ) ) && NE_16( st_fx->bwidth, NB ) ) ) { /* silence portions */ @@ -184,13 +184,13 @@ void decision_matrix_enc_fx( * NB *---------------------------------------------------------------------*/ - ELSE IF ( EQ_16(st_fx->bwidth,NB)) + ELSE IF( EQ_16( st_fx->bwidth, NB ) ) { st_fx->core = ACELP_CORE; move16(); test(); - if ( GE_32(st_fx->total_brate,HQCORE_NB_MIN_RATE)&&EQ_16(st_fx->sp_aud_decision1,1)) + if ( GE_32( st_fx->total_brate, HQCORE_NB_MIN_RATE ) && EQ_16( st_fx->sp_aud_decision1, 1 ) ) { st_fx->core = HQ_CORE; move16(); @@ -201,15 +201,15 @@ void decision_matrix_enc_fx( * WB *---------------------------------------------------------------------*/ - ELSE IF ( EQ_16(st_fx->bwidth,WB)) + ELSE IF( EQ_16( st_fx->bwidth, WB ) ) { st_fx->core = ACELP_CORE; move16(); test(); test(); - IF ( ( GE_32(st_fx->total_brate,HQCORE_WB_MIN_RATE)&&EQ_16(st_fx->sp_aud_decision1,1))|| - GE_32(st_fx->total_brate,HQ_96k) ) + IF( ( GE_32( st_fx->total_brate, HQCORE_WB_MIN_RATE ) && EQ_16( st_fx->sp_aud_decision1, 1 ) ) || + GE_32( st_fx->total_brate, HQ_96k ) ) { st_fx->core = HQ_CORE; move16(); @@ -220,18 +220,18 @@ void decision_matrix_enc_fx( test(); test(); test(); - IF ( EQ_16(st_fx->bwidth,WB)&<_32(st_fx->total_brate,ACELP_9k60)) + IF( EQ_16( st_fx->bwidth, WB ) && LT_32( st_fx->total_brate, ACELP_9k60 ) ) { st_fx->extl = WB_BWE; move16(); } - ELSE IF ( EQ_16(st_fx->bwidth,WB)&&GE_32(st_fx->total_brate,ACELP_9k60)&&LE_32(st_fx->total_brate,ACELP_16k40)) + ELSE IF( EQ_16( st_fx->bwidth, WB ) && GE_32( st_fx->total_brate, ACELP_9k60 ) && LE_32( st_fx->total_brate, ACELP_16k40 ) ) { /* Note: WB BWE is used exceptionally at 13.2 kbps if GSC is selected instead of LR-MDCT */ test(); test(); test(); - IF ( EQ_16(st_fx->sp_aud_decision1,1)||EQ_16(st_fx->coder_type,INACTIVE)||(st_fx->sp_aud_decision1==0&&EQ_16(st_fx->sp_aud_decision2,1))) + IF( EQ_16( st_fx->sp_aud_decision1, 1 ) || EQ_16( st_fx->coder_type, INACTIVE ) || ( st_fx->sp_aud_decision1 == 0 && EQ_16( st_fx->sp_aud_decision2, 1 ) ) ) { st_fx->extl = WB_BWE; move16(); @@ -253,12 +253,12 @@ void decision_matrix_enc_fx( * SWB and FB *---------------------------------------------------------------------*/ - ELSE IF ( EQ_16(st_fx->bwidth,SWB)||EQ_16(st_fx->bwidth,FB)) + ELSE IF( EQ_16( st_fx->bwidth, SWB ) || EQ_16( st_fx->bwidth, FB ) ) { test(); test(); - IF ( ( GE_32(st_fx->total_brate,HQCORE_SWB_MIN_RATE)&&EQ_16(st_fx->sp_aud_decision1,1))|| - GE_32(st_fx->total_brate,HQ_96k) ) + IF( ( GE_32( st_fx->total_brate, HQCORE_SWB_MIN_RATE ) && EQ_16( st_fx->sp_aud_decision1, 1 ) ) || + GE_32( st_fx->total_brate, HQ_96k ) ) { st_fx->core = HQ_CORE; move16(); @@ -270,7 +270,7 @@ void decision_matrix_enc_fx( test(); test(); - IF ( GE_32(st_fx->total_brate,ACELP_13k20)&<_32(st_fx->total_brate,ACELP_48k)) + IF( GE_32( st_fx->total_brate, ACELP_13k20 ) && LT_32( st_fx->total_brate, ACELP_48k ) ) { /* Note: SWB BWE is not used in case of GSC noisy speech */ /* Note: SWB BWE is used exceptionally at 13.2 kbps if GSC is selected instead of LR-MDCT */ @@ -278,7 +278,7 @@ void decision_matrix_enc_fx( test(); test(); test(); - IF ( (EQ_16(st_fx->sp_aud_decision1,1)||EQ_16(st_fx->coder_type,INACTIVE)||(st_fx->sp_aud_decision1==0&&EQ_16(st_fx->sp_aud_decision2,1)))&&st_fx->GSC_noisy_speech==0) + IF( ( EQ_16( st_fx->sp_aud_decision1, 1 ) || EQ_16( st_fx->coder_type, INACTIVE ) || ( st_fx->sp_aud_decision1 == 0 && EQ_16( st_fx->sp_aud_decision2, 1 ) ) ) && st_fx->GSC_noisy_speech == 0 ) { st_fx->extl = SWB_BWE; move16(); @@ -286,7 +286,7 @@ void decision_matrix_enc_fx( move32(); test(); - IF ( EQ_16(st_fx->bwidth,FB)&&GE_32(st_fx->total_brate,ACELP_24k40)) + IF( EQ_16( st_fx->bwidth, FB ) && GE_32( st_fx->total_brate, ACELP_24k40 ) ) { st_fx->extl = FB_BWE; move16(); @@ -300,14 +300,14 @@ void decision_matrix_enc_fx( move16(); st_fx->extl_brate = SWB_TBE_1k6; move32(); - if( GE_32(st_fx->total_brate,ACELP_24k40)) + if ( GE_32( st_fx->total_brate, ACELP_24k40 ) ) { st_fx->extl_brate = SWB_TBE_2k8; move32(); } test(); - IF ( EQ_16(st_fx->bwidth,FB)&&GE_32(st_fx->total_brate,ACELP_24k40)) + IF( EQ_16( st_fx->bwidth, FB ) && GE_32( st_fx->total_brate, ACELP_24k40 ) ) { st_fx->extl = FB_TBE; move16(); @@ -318,14 +318,14 @@ void decision_matrix_enc_fx( } } } - ELSE IF ( GE_32(st_fx->total_brate,ACELP_48k)) + ELSE IF( GE_32( st_fx->total_brate, ACELP_48k ) ) { st_fx->extl = SWB_BWE_HIGHRATE; move16(); st_fx->extl_brate = SWB_BWE_16k; move32(); - if( EQ_16(st_fx->bwidth,FB)) + if ( EQ_16( st_fx->bwidth, FB ) ) { st_fx->extl = FB_BWE_HIGHRATE; move32(); @@ -338,20 +338,20 @@ void decision_matrix_enc_fx( * Set HQ core type *-----------------------------------------------------------------*/ - IF( EQ_16(st_fx->core,HQ_CORE)) + IF( EQ_16( st_fx->core, HQ_CORE ) ) { *hq_core_type = NORMAL_HQ_CORE; move16(); test(); test(); - IF( (EQ_16(st_fx->bwidth,SWB)||EQ_16(st_fx->bwidth,WB))&&LE_32(st_fx->total_brate,LRMDCT_CROSSOVER_POINT)) + IF( ( EQ_16( st_fx->bwidth, SWB ) || EQ_16( st_fx->bwidth, WB ) ) && LE_32( st_fx->total_brate, LRMDCT_CROSSOVER_POINT ) ) { /* note that FB (bitrate >= 24400 bps) is always coded with NORMAL_HQ_CORE */ *hq_core_type = LOW_RATE_HQ_CORE; move16(); } - ELSE IF( EQ_16(st_fx->bwidth,NB)) + ELSE IF( EQ_16( st_fx->bwidth, NB ) ) { *hq_core_type = LOW_RATE_HQ_CORE; move16(); @@ -359,9 +359,9 @@ void decision_matrix_enc_fx( } /* set core bitrate */ - st_fx->core_brate = L_sub(st_fx->total_brate, st_fx->extl_brate); + st_fx->core_brate = L_sub( st_fx->total_brate, st_fx->extl_brate ); - IF ( st_fx->ini_frame == 0 ) + IF( st_fx->ini_frame == 0 ) { /* avoid switching in the very first frame */ st_fx->last_core = st_fx->core; @@ -382,95 +382,94 @@ void decision_matrix_enc_fx( *---------------------------------------------------------------------*/ Word16 signalling_mode1_tcx20_enc( - Encoder_State *st, /* i : encoder state structure */ - Word16 push -) + Encoder_State *st, /* i : encoder state structure */ + Word16 push ) { Word16 num_bits; Word16 nBits, idx, start_idx; BSTR_ENC_HANDLE hBstr; hBstr = st->hBstr; - assert(st->core == TCX_20_CORE); + assert( st->core == TCX_20_CORE ); num_bits = 0; move16(); /* Use ACELP signaling for LR MDCT */ - IF ( LE_32(st->total_brate, ACELP_16k40)) + IF( LE_32( st->total_brate, ACELP_16k40 ) ) { /* find the section in the ACELP signalling table corresponding to bitrate */ idx = 0; move16(); - WHILE ( NE_32(acelp_sig_tbl[idx], st->total_brate)) + WHILE( NE_32( acelp_sig_tbl[idx], st->total_brate ) ) { - idx = add(idx, 1); + idx = add( idx, 1 ); } /* retrieve the number of bits for signalling */ - idx = add(idx, 1); - nBits = extract_l(acelp_sig_tbl[idx]); + idx = add( idx, 1 ); + nBits = extract_l( acelp_sig_tbl[idx] ); /* retrieve the signalling index */ - idx = add(idx, 1); + idx = add( idx, 1 ); start_idx = idx; move16(); - WHILE ( NE_32(acelp_sig_tbl[idx], SIG2IND_fx(LR_MDCT, st->bwidth, 0, 0))) + WHILE( NE_32( acelp_sig_tbl[idx], SIG2IND_fx( LR_MDCT, st->bwidth, 0, 0 ) ) ) { - idx = add(idx, 1); + idx = add( idx, 1 ); } - num_bits = add(num_bits, nBits); - IF (push != 0) + num_bits = add( num_bits, nBits ); + IF( push != 0 ) { - push_indice_fx(hBstr, IND_ACELP_SIGNALLING, sub(idx, start_idx), nBits ); + push_indice_fx( hBstr, IND_ACELP_SIGNALLING, sub( idx, start_idx ), nBits ); } /* HQ/TCX core switching flag */ - num_bits = add(num_bits, 1); - IF (push != 0) + num_bits = add( num_bits, 1 ); + IF( push != 0 ) { - push_indice_fx(hBstr, IND_MDCT_CORE, 1, 1 ); + push_indice_fx( hBstr, IND_MDCT_CORE, 1, 1 ); } } ELSE { - IF ( LE_32(st->core_brate, ACELP_64k)) + IF( LE_32( st->core_brate, ACELP_64k ) ) { /* write ACELP/HQ core indication flag */ - num_bits = add(num_bits, 1); - IF (push != 0) + num_bits = add( num_bits, 1 ); + IF( push != 0 ) { - push_indice_fx(hBstr, IND_CORE, 1, 1 ); + push_indice_fx( hBstr, IND_CORE, 1, 1 ); } } /* HQ/TCX core switching flag */ - num_bits = add(num_bits, 1); - IF (push != 0) + num_bits = add( num_bits, 1 ); + IF( push != 0 ) { - push_indice_fx(hBstr, IND_MDCT_CORE, 1, 1 ); + push_indice_fx( hBstr, IND_MDCT_CORE, 1, 1 ); } - num_bits = add(num_bits, 2); - IF (push != 0) + num_bits = add( num_bits, 2 ); + IF( push != 0 ) { /* write band-width (needed for different I/O sampling rate support) */ - IF ( EQ_16(st->bwidth, NB)) + IF( EQ_16( st->bwidth, NB ) ) { - push_indice_fx(hBstr, IND_HQ_BWIDTH, 0, 2 ); + push_indice_fx( hBstr, IND_HQ_BWIDTH, 0, 2 ); } - ELSE IF ( EQ_16(st->bwidth, WB)) + ELSE IF( EQ_16( st->bwidth, WB ) ) { - push_indice_fx(hBstr, IND_HQ_BWIDTH, 1, 2 ); + push_indice_fx( hBstr, IND_HQ_BWIDTH, 1, 2 ); } - ELSE IF ( EQ_16(st->bwidth, SWB)) + ELSE IF( EQ_16( st->bwidth, SWB ) ) { - push_indice_fx(hBstr, IND_HQ_BWIDTH, 2, 2 ); + push_indice_fx( hBstr, IND_HQ_BWIDTH, 2, 2 ); } - ELSE /* st->bwidth == FB */ + ELSE /* st->bwidth == FB */ { - push_indice_fx(hBstr, IND_HQ_BWIDTH, 3, 2 ); + push_indice_fx( hBstr, IND_HQ_BWIDTH, 3, 2 ); } } } @@ -485,101 +484,110 @@ Word16 signalling_mode1_tcx20_enc( *---------------------------------------------------------------------*/ void signalling_enc_fx( - Encoder_State *st_fx /* i : encoder state structure */ + Encoder_State *st_fx /* i : encoder state structure */ ) { Word16 nBits, idx, start_idx; Word32 k, total_brate_temp; - SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; + SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; BSTR_ENC_HANDLE hBstr; hBstr = st_fx->hBstr; - IF (EQ_16(st_fx->mdct_sw, MODE2)) + IF( EQ_16( st_fx->mdct_sw, MODE2 ) ) { - assert(!st_fx->tcxonly); - assert(st_fx->core == HQ_CORE); + assert( !st_fx->tcxonly ); + assert( st_fx->core == HQ_CORE ); - push_next_indice_fx(hBstr, 1, 1); /* TCX */ - push_next_indice_fx(hBstr, 1, 1); /* HQ_CORE */ + push_next_indice_fx( hBstr, 1, 1 ); /* TCX */ + push_next_indice_fx( hBstr, 1, 1 ); /* HQ_CORE */ /* write ACELP->HQ core switching flag */ test(); - IF ( EQ_16(st_fx->last_core, ACELP_CORE)||EQ_16(st_fx->last_core,AMR_WB_CORE)) + IF( EQ_16( st_fx->last_core, ACELP_CORE ) || EQ_16( st_fx->last_core, AMR_WB_CORE ) ) { - push_indice_fx(hBstr, IND_HQ_SWITCHING_FLG, 1, 1 ); + push_indice_fx( hBstr, IND_HQ_SWITCHING_FLG, 1, 1 ); /* write ACELP L_frame info */ - IF( EQ_16(st_fx->last_L_frame, L_FRAME)) + IF( EQ_16( st_fx->last_L_frame, L_FRAME ) ) { - push_indice_fx(hBstr, IND_LAST_L_FRAME, 0, 1 ); + push_indice_fx( hBstr, IND_LAST_L_FRAME, 0, 1 ); } ELSE { - push_indice_fx(hBstr, IND_LAST_L_FRAME, 1, 1 ); + push_indice_fx( hBstr, IND_LAST_L_FRAME, 1, 1 ); } } ELSE { - push_indice_fx(hBstr, IND_HQ_SWITCHING_FLG, 0, 1 ); + push_indice_fx( hBstr, IND_HQ_SWITCHING_FLG, 0, 1 ); } return; } - IF( EQ_16(st_fx->core,ACELP_CORE )) + IF( EQ_16( st_fx->core, ACELP_CORE ) ) { - Word16 ppp_mode, nelp_mode, sig; + Word16 ppp_mode, nelp_mode, sig; ppp_mode = 0; nelp_mode = 0; - move16(); move16(); - IF(st_fx->Opt_SC_VBR) + move16(); + move16(); + IF( st_fx->Opt_SC_VBR ) { ppp_mode = hSC_VBR->ppp_mode; nelp_mode = hSC_VBR->nelp_mode; - move16(); move16(); + move16(); + move16(); } test(); test(); - IF( EQ_16(ppp_mode,1) || EQ_16(nelp_mode,1)) + IF( EQ_16( ppp_mode, 1 ) || EQ_16( nelp_mode, 1 ) ) { /* 1 bit to distinguish between 2.8kbps PPP/NELP frame and SID frame */ - push_indice_fx(hBstr, IND_CORE, 0, 1 ); + push_indice_fx( hBstr, IND_CORE, 0, 1 ); /* SC-VBR: 0 - PPP_NB, 1 - PPP_WB, 2 - NELP_NB, 3 - NELP_WB */ - test();test();test();test();test();test();test();test(); - IF ( EQ_16(st_fx->coder_type,VOICED)&&EQ_16(st_fx->bwidth,NB)&&EQ_16(ppp_mode,1)) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( EQ_16( st_fx->coder_type, VOICED ) && EQ_16( st_fx->bwidth, NB ) && EQ_16( ppp_mode, 1 ) ) { - push_indice_fx(hBstr, IND_PPP_NELP_MODE, 0, 2 ); + push_indice_fx( hBstr, IND_PPP_NELP_MODE, 0, 2 ); } - ELSE IF ( EQ_16(st_fx->coder_type,VOICED)&&NE_16(st_fx->bwidth,NB)&&EQ_16(ppp_mode,1)) + ELSE IF( EQ_16( st_fx->coder_type, VOICED ) && NE_16( st_fx->bwidth, NB ) && EQ_16( ppp_mode, 1 ) ) { - push_indice_fx(hBstr, IND_PPP_NELP_MODE, 1, 2 ); + push_indice_fx( hBstr, IND_PPP_NELP_MODE, 1, 2 ); } - ELSE IF ( EQ_16(st_fx->coder_type,UNVOICED)&&EQ_16(st_fx->bwidth,NB)&&EQ_16(nelp_mode,1)) + ELSE IF( EQ_16( st_fx->coder_type, UNVOICED ) && EQ_16( st_fx->bwidth, NB ) && EQ_16( nelp_mode, 1 ) ) { - push_indice_fx(hBstr, IND_PPP_NELP_MODE, 2, 2); + push_indice_fx( hBstr, IND_PPP_NELP_MODE, 2, 2 ); } - ELSE IF ( EQ_16(st_fx->coder_type,UNVOICED)&&NE_16(st_fx->bwidth,NB)&&EQ_16(nelp_mode,1)) + ELSE IF( EQ_16( st_fx->coder_type, UNVOICED ) && NE_16( st_fx->bwidth, NB ) && EQ_16( nelp_mode, 1 ) ) { - push_indice_fx(hBstr, IND_PPP_NELP_MODE, 3, 2 ); + push_indice_fx( hBstr, IND_PPP_NELP_MODE, 3, 2 ); } } - ELSE IF( NE_32(st_fx->core_brate,SID_2k40)&&NE_32(st_fx->core_brate,FRAME_NO_DATA)) + ELSE IF( NE_32( st_fx->core_brate, SID_2k40 ) && NE_32( st_fx->core_brate, FRAME_NO_DATA ) ) { /* write the ACELP/HQ core selection bit */ - IF (GE_32(st_fx->total_brate,ACELP_24k40)) + IF( GE_32( st_fx->total_brate, ACELP_24k40 ) ) { - push_indice_fx(hBstr, IND_CORE, 0, 1 ); + push_indice_fx( hBstr, IND_CORE, 0, 1 ); } /* find the section in the ACELP signalling table corresponding to bitrate */ idx = 0; move16(); - WHILE (LT_16(idx, MAX_ACELP_SIG)) + WHILE( LT_16( idx, MAX_ACELP_SIG ) ) { - IF (LE_32(st_fx->total_brate, brate_tbl[idx])) + IF( LE_32( st_fx->total_brate, brate_tbl[idx] ) ) { BREAK; } @@ -590,13 +598,13 @@ void signalling_enc_fx( idx = 0; move16(); - WHILE ( NE_32(acelp_sig_tbl[idx], total_brate_temp)) + WHILE( NE_32( acelp_sig_tbl[idx], total_brate_temp ) ) { idx++; } /* retrieve the number of bits for signalling */ - nBits = (Word16)acelp_sig_tbl[++idx]; + nBits = (Word16) acelp_sig_tbl[++idx]; move16(); /* retrieve the signalling index */ @@ -607,23 +615,23 @@ void signalling_enc_fx( #else start_idx = ++idx; move16(); - IF (EQ_16(st_fx->element_mode, IVAS_CPE_TD) && EQ_16(st_fx->bwidth, SWB) && LE_32(st_fx->total_brate, ACELP_9k60)) + IF( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && EQ_16( st_fx->bwidth, SWB ) && LE_32( st_fx->total_brate, ACELP_9k60 ) ) { /* patch to signal SWB as NB in Stereo */ - sig = (Word16)SIG2IND(st_fx->coder_type, NB, st_fx->sharpFlag, st_fx->rf_mode); + sig = (Word16) SIG2IND( st_fx->coder_type, NB, st_fx->sharpFlag, st_fx->rf_mode ); } ELSE { - sig = (Word16)SIG2IND(st_fx->coder_type, st_fx->bwidth, st_fx->sharpFlag, st_fx->rf_mode); + sig = (Word16) SIG2IND( st_fx->coder_type, st_fx->bwidth, st_fx->sharpFlag, st_fx->rf_mode ); } - WHILE (NE_16((Word16)acelp_sig_tbl[idx] , sig)) + WHILE( NE_16( (Word16) acelp_sig_tbl[idx], sig ) ) #endif { idx++; } - push_indice_fx(hBstr, IND_ACELP_SIGNALLING, idx - start_idx, nBits ); + push_indice_fx( hBstr, IND_ACELP_SIGNALLING, idx - start_idx, nBits ); } /* write extension layer flag to distinguish between TBE (0) and BWE (1) */ @@ -633,90 +641,90 @@ void signalling_enc_fx( test(); test(); test(); - IF( EQ_16(st_fx->extl,WB_TBE)||EQ_16(st_fx->extl,SWB_TBE)||EQ_16(st_fx->extl,FB_TBE)) + IF( EQ_16( st_fx->extl, WB_TBE ) || EQ_16( st_fx->extl, SWB_TBE ) || EQ_16( st_fx->extl, FB_TBE ) ) { - push_indice_fx(hBstr, IND_BWE_FLAG, 0, 1 ); + push_indice_fx( hBstr, IND_BWE_FLAG, 0, 1 ); } - ELSE IF( EQ_16(st_fx->extl,WB_BWE)||EQ_16(st_fx->extl,SWB_BWE)||EQ_16(st_fx->extl,FB_BWE)) + ELSE IF( EQ_16( st_fx->extl, WB_BWE ) || EQ_16( st_fx->extl, SWB_BWE ) || EQ_16( st_fx->extl, FB_BWE ) ) { - push_indice_fx(hBstr, IND_BWE_FLAG, 1, 1 ); + push_indice_fx( hBstr, IND_BWE_FLAG, 1, 1 ); } } } - ELSE /* HQ core */ + ELSE /* HQ core */ { /* write ACELP->HQ switching frame flag */ test(); - IF( EQ_16(st_fx->last_core,ACELP_CORE)||EQ_16(st_fx->last_core,AMR_WB_CORE)) + IF( EQ_16( st_fx->last_core, ACELP_CORE ) || EQ_16( st_fx->last_core, AMR_WB_CORE ) ) { - push_indice_fx(hBstr, IND_HQ_SWITCHING_FLG, 1, 1 ); + push_indice_fx( hBstr, IND_HQ_SWITCHING_FLG, 1, 1 ); /* write ACELP L_frame info */ - IF( EQ_16(st_fx->last_L_frame, L_FRAME)) + IF( EQ_16( st_fx->last_L_frame, L_FRAME ) ) { - push_indice_fx(hBstr, IND_LAST_L_FRAME, 0, 1 ); + push_indice_fx( hBstr, IND_LAST_L_FRAME, 0, 1 ); } ELSE { - push_indice_fx(hBstr, IND_LAST_L_FRAME, 1, 1 ); + push_indice_fx( hBstr, IND_LAST_L_FRAME, 1, 1 ); } } ELSE { - push_indice_fx(hBstr, IND_HQ_SWITCHING_FLG, 0, 1 ); + push_indice_fx( hBstr, IND_HQ_SWITCHING_FLG, 0, 1 ); } /* HQ/TCX core switching flag */ - push_indice_fx(hBstr, IND_MDCT_CORE, 0, 1 ); + push_indice_fx( hBstr, IND_MDCT_CORE, 0, 1 ); /* Use ACELP signaling for LR MDCT */ - IF ( LE_32(st_fx->total_brate,ACELP_16k40)) + IF( LE_32( st_fx->total_brate, ACELP_16k40 ) ) { /* find the section in the ACELP signalling table corresponding to bitrate */ idx = 0; - WHILE ( NE_32(acelp_sig_tbl[idx],st_fx->total_brate)) + WHILE( NE_32( acelp_sig_tbl[idx], st_fx->total_brate ) ) { idx++; } /* retrieve the number of bits for signalling */ - nBits = extract_l(acelp_sig_tbl[++idx]); + nBits = extract_l( acelp_sig_tbl[++idx] ); /* retrieve the signalling index */ start_idx = ++idx; move16(); - k = SIG2IND_fx(LR_MDCT, st_fx->bwidth, 0, 0); - WHILE( NE_32(acelp_sig_tbl[idx], k)) + k = SIG2IND_fx( LR_MDCT, st_fx->bwidth, 0, 0 ); + WHILE( NE_32( acelp_sig_tbl[idx], k ) ) { idx++; } - push_indice_fx(hBstr, IND_ACELP_SIGNALLING, idx - start_idx, nBits ); + push_indice_fx( hBstr, IND_ACELP_SIGNALLING, idx - start_idx, nBits ); } ELSE { - IF( LE_32(st_fx->core_brate,ACELP_64k)) + IF( LE_32( st_fx->core_brate, ACELP_64k ) ) { /* write ACELP/HQ core indication flag */ - push_indice_fx(hBstr, IND_CORE, 1, 1 ); + push_indice_fx( hBstr, IND_CORE, 1, 1 ); } /* write band-width (needed for different I/O sampling rate support) */ - IF( EQ_16(st_fx->bwidth,NB)) + IF( EQ_16( st_fx->bwidth, NB ) ) { - push_indice_fx(hBstr, IND_HQ_BWIDTH, 0, 2 ); + push_indice_fx( hBstr, IND_HQ_BWIDTH, 0, 2 ); } - ELSE IF( EQ_16(st_fx->bwidth,WB)) + ELSE IF( EQ_16( st_fx->bwidth, WB ) ) { - push_indice_fx(hBstr, IND_HQ_BWIDTH, 1, 2 ); + push_indice_fx( hBstr, IND_HQ_BWIDTH, 1, 2 ); } - ELSE IF( EQ_16(st_fx->bwidth,SWB)) + ELSE IF( EQ_16( st_fx->bwidth, SWB ) ) { - push_indice_fx(hBstr, IND_HQ_BWIDTH, 2, 2 ); + push_indice_fx( hBstr, IND_HQ_BWIDTH, 2, 2 ); } - ELSE /* st_fx->bwidth == FB */ + ELSE /* st_fx->bwidth == FB */ { - push_indice_fx(hBstr, IND_HQ_BWIDTH, 3, 2 ); + push_indice_fx( hBstr, IND_HQ_BWIDTH, 3, 2 ); } } } @@ -731,7 +739,7 @@ void signalling_enc_fx( *---------------------------------------------------------------------*/ void signalling_enc_rf( - Encoder_State *st /* i : encoder state structure */ + Encoder_State *st /* i : encoder state structure */ ) { Word16 i; @@ -739,53 +747,51 @@ void signalling_enc_rf( RF_ENC_HANDLE hRF = st->hRF; /* write partial copy into bitstream */ - IF(EQ_16(st->rf_mode,1)) + IF( EQ_16( st->rf_mode, 1 ) ) { - enc_prm_rf_fx(st, hRF->rf_indx_frametype[st->rf_fec_offset], st->rf_fec_offset); + enc_prm_rf_fx( st, hRF->rf_indx_frametype[st->rf_fec_offset], st->rf_fec_offset ); hRF->rf_indx_tbeGainFr[0] = hRF->RF_bwe_gainFr_ind; } /* Shift the RF indices such that the partial copy associated with (n-fec_offset)th frame is included in the bitstream in nth frame. */ - FOR(i = st->rf_fec_offset; i >= 0 ; i--) + FOR( i = st->rf_fec_offset; i >= 0; i-- ) { /* rf frame type */ - hRF->rf_indx_frametype[i+1] = hRF->rf_indx_frametype[i]; + hRF->rf_indx_frametype[i + 1] = hRF->rf_indx_frametype[i]; /* rf target bits buffer */ - hRF->rf_targetbits_buff[i+1] = hRF->rf_targetbits_buff[i]; + hRF->rf_targetbits_buff[i + 1] = hRF->rf_targetbits_buff[i]; /* lsf indx */ - hRF->rf_indx_lsf[i+1][0] = hRF->rf_indx_lsf[i][0]; - hRF->rf_indx_lsf[i+1][1] = hRF->rf_indx_lsf[i][1]; - hRF->rf_indx_lsf[i+1][2] = hRF->rf_indx_lsf[i][2]; + hRF->rf_indx_lsf[i + 1][0] = hRF->rf_indx_lsf[i][0]; + hRF->rf_indx_lsf[i + 1][1] = hRF->rf_indx_lsf[i][1]; + hRF->rf_indx_lsf[i + 1][2] = hRF->rf_indx_lsf[i][2]; /* ES pred energy */ - hRF->rf_indx_EsPred[i+1] = hRF->rf_indx_EsPred[i]; + hRF->rf_indx_EsPred[i + 1] = hRF->rf_indx_EsPred[i]; /* LTF mode, sfr params: pitch, fcb and gain */ - FOR(sfr = 0; sfr < st->nb_subfr; sfr++) + FOR( sfr = 0; sfr < st->nb_subfr; sfr++ ) { - hRF->rf_indx_ltfMode[i+1][sfr] = hRF->rf_indx_ltfMode[i][sfr]; - hRF->rf_indx_pitch[i+1][sfr] = hRF->rf_indx_pitch[i][sfr]; - hRF->rf_indx_fcb[i+1][sfr] = hRF->rf_indx_fcb[i][sfr]; - hRF->rf_indx_gain[i+1][sfr] = hRF->rf_indx_gain[i][sfr]; + hRF->rf_indx_ltfMode[i + 1][sfr] = hRF->rf_indx_ltfMode[i][sfr]; + hRF->rf_indx_pitch[i + 1][sfr] = hRF->rf_indx_pitch[i][sfr]; + hRF->rf_indx_fcb[i + 1][sfr] = hRF->rf_indx_fcb[i][sfr]; + hRF->rf_indx_gain[i + 1][sfr] = hRF->rf_indx_gain[i][sfr]; } /* shift the nelp indices */ - hRF->rf_indx_nelp_iG1[i+1] = hRF->rf_indx_nelp_iG1[i]; - hRF->rf_indx_nelp_iG2[i+1][0] = hRF->rf_indx_nelp_iG2[i][0]; - hRF->rf_indx_nelp_iG2[i+1][1] = hRF->rf_indx_nelp_iG2[i][1]; - hRF->rf_indx_nelp_fid[i+1] = hRF->rf_indx_nelp_fid[i]; + hRF->rf_indx_nelp_iG1[i + 1] = hRF->rf_indx_nelp_iG1[i]; + hRF->rf_indx_nelp_iG2[i + 1][0] = hRF->rf_indx_nelp_iG2[i][0]; + hRF->rf_indx_nelp_iG2[i + 1][1] = hRF->rf_indx_nelp_iG2[i][1]; + hRF->rf_indx_nelp_fid[i + 1] = hRF->rf_indx_nelp_fid[i]; /* tbe gain Fr shift */ - hRF->rf_indx_tbeGainFr[i+1] = hRF->rf_indx_tbeGainFr[i]; - hRF->rf_clas[i+1] = hRF->rf_clas[i]; - hRF->rf_gain_tcx[i+1] = hRF->rf_gain_tcx[i]; - hRF->rf_tcxltp_param[i+1] = hRF->rf_tcxltp_param[i]; + hRF->rf_indx_tbeGainFr[i + 1] = hRF->rf_indx_tbeGainFr[i]; + hRF->rf_clas[i + 1] = hRF->rf_clas[i]; + hRF->rf_gain_tcx[i + 1] = hRF->rf_gain_tcx[i]; + hRF->rf_tcxltp_param[i + 1] = hRF->rf_tcxltp_param[i]; } return; } - - diff --git a/lib_enc/detect_transient_fx.c b/lib_enc/detect_transient_fx.c index 6c430921f..0d86e3aab 100644 --- a/lib_enc/detect_transient_fx.c +++ b/lib_enc/detect_transient_fx.c @@ -31,76 +31,74 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include #include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ - /*--------------------------------------------------------------------------*/ - /* Function hp_filter */ - /* ~~~~~~~~~~~~~~~~~~~~ */ - /* */ - /* High pass filter */ - /*--------------------------------------------------------------------------*/ - /* float x (i) in Q_new input to filter */ - /* float y (o) in Q_new +2 output of filter */ - /* float *oldy (i/o) previous output of filter */ - /* float *oldx (i/o) in Q_memx previous input of filter */ - /* short L (i) in Q_memx +2 length (32 or 48 kHz) */ - /*--------------------------------------------------------------------------*/ +/*--------------------------------------------------------------------------*/ +/* Function hp_filter */ +/* ~~~~~~~~~~~~~~~~~~~~ */ +/* */ +/* High pass filter */ +/*--------------------------------------------------------------------------*/ +/* float x (i) in Q_new input to filter */ +/* float y (o) in Q_new +2 output of filter */ +/* float *oldy (i/o) previous output of filter */ +/* float *oldx (i/o) in Q_memx previous input of filter */ +/* short L (i) in Q_memx +2 length (32 or 48 kHz) */ +/*--------------------------------------------------------------------------*/ static void hp_filter_fx( - const Word16 *x, /*Q_new */ - Word16 *y, /*Q_new */ - Word16 *oldy, /*Q_new */ - Word16 *oldx, /*Q_new */ - const Word16 L -) + const Word16 *x, /*Q_new */ + Word16 *y, /*Q_new */ + Word16 *oldy, /*Q_new */ + Word16 *oldx, /*Q_new */ + const Word16 L ) { - Word16 i; - Word32 L_tmp; + Word16 i; + Word32 L_tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; + Flag Overflow = 0; #endif - /*y[0] = 0.4931f * *oldy + 0.7466f*(x[0] - *oldx); */ + /*y[0] = 0.4931f * *oldy + 0.7466f*(x[0] - *oldx); */ #ifdef BASOP_NOGLOB - L_tmp = L_mult(sub_o(x[0], *oldx, &Overflow), 24465);/*Q_new+16 */ -#else /* BASOP_NOGLOB */ - L_tmp = L_mult(sub(x[0], *oldx), 24465);/*Q_new+16 */ -#endif /* BASOP_NOGLOB */ + L_tmp = L_mult( sub_o( x[0], *oldx, &Overflow ), 24465 ); /*Q_new+16 */ +#else /* BASOP_NOGLOB */ + L_tmp = L_mult( sub( x[0], *oldx ), 24465 ); /*Q_new+16 */ +#endif /* BASOP_NOGLOB */ #ifdef BASOP_NOGLOB L_tmp = L_mac_sat( L_tmp, *oldy, 16158 ); /*Q_new+16 */ - y[0] = round_fx_sat(L_tmp);/*Q_new */ + y[0] = round_fx_sat( L_tmp ); /*Q_new */ #else - L_tmp = L_mac(L_tmp, *oldy, 16158);/*Q_new+16 */ - y[0] = round_fx(L_tmp);/*Q_new */ + L_tmp = L_mac( L_tmp, *oldy, 16158 ); /*Q_new+16 */ + y[0] = round_fx( L_tmp ); /*Q_new */ #endif - FOR(i = 1; i < L; i++) - { - /*y[i] = 0.4931f*y[i-1] + 0.7466f*(x[i] - x[i-1]); */ + FOR( i = 1; i < L; i++ ) + { + /*y[i] = 0.4931f*y[i-1] + 0.7466f*(x[i] - x[i-1]); */ #ifdef BASOP_NOGLOB - L_tmp = L_mult(sub_o(x[i], x[i - 1], &Overflow), 24465);/*Q_new+16 */ - L_tmp = L_mac_o(L_tmp, y[i - 1], 16158, &Overflow);/*Q_new+16 */ - y[i] = round_fx_o(L_tmp, &Overflow); /*Q_new */ -#else /* BASOP_NOGLOB */ - L_tmp = L_mult(sub(x[i], x[i - 1]), 24465);/*Q_new+16 */ - L_tmp = L_mac(L_tmp, y[i - 1], 16158);/*Q_new+16 */ - y[i] = round_fx(L_tmp); /*Q_new */ -#endif /* BASOP_NOGLOB */ - } - - *oldx = x[L - 1]; - move16();/*Q_new */ - *oldy = y[L - 1]; - move16();/*Q_new */ + L_tmp = L_mult( sub_o( x[i], x[i - 1], &Overflow ), 24465 ); /*Q_new+16 */ + L_tmp = L_mac_o( L_tmp, y[i - 1], 16158, &Overflow ); /*Q_new+16 */ + y[i] = round_fx_o( L_tmp, &Overflow ); /*Q_new */ +#else /* BASOP_NOGLOB */ + L_tmp = L_mult( sub( x[i], x[i - 1] ), 24465 ); /*Q_new+16 */ + L_tmp = L_mac( L_tmp, y[i - 1], 16158 ); /*Q_new+16 */ + y[i] = round_fx( L_tmp ); /*Q_new */ +#endif /* BASOP_NOGLOB */ + } + *oldx = x[L - 1]; + move16(); /*Q_new */ + *oldy = y[L - 1]; + move16(); /*Q_new */ } /*--------------------------------------------------------------------------*/ /* Function detect_transient */ @@ -116,333 +114,331 @@ static void hp_filter_fx( /*--------------------------------------------------------------------------*/ Word16 detect_transient_fx( - const Word16 *in_fx, /*Q_new */ - const Word16 L, - Word16 Q_new, - Encoder_State *st_fx -) + const Word16 *in_fx, /*Q_new */ + const Word16 L, + Word16 Q_new, + Encoder_State *st_fx ) { - Word32 Energy, L_tmp; - Word32 EnergyLT; - Word16 i, blk; - Word16 IsTransient; - Word16 out_filt_fx[L_FRAME48k]; - Word16 position = 0; - Word16 thr; - Word32 L_tmp2; - Word16 shift; - Word32 Energy_fx, E_in_fx = 0, E_out_fx = 0, Energy_in_fx[5] = { 0,0,0,0,0 }; /* Energy_fx can be replaced by Energy */ - Word32 E_low_fx, E_high_fx; - Word16 temp16, Thres_fx = 0; - Word16 exp; + Word32 Energy, L_tmp; + Word32 EnergyLT; + Word16 i, blk; + Word16 IsTransient; + Word16 out_filt_fx[L_FRAME48k]; + Word16 position = 0; + Word16 thr; + Word32 L_tmp2; + Word16 shift; + Word32 Energy_fx, E_in_fx = 0, E_out_fx = 0, Energy_in_fx[5] = { 0, 0, 0, 0, 0 }; /* Energy_fx can be replaced by Energy */ + Word32 E_low_fx, E_high_fx; + Word16 temp16, Thres_fx = 0; + Word16 exp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; + Flag Overflow = 0; #endif - shift = 0; - move16(); + shift = 0; + move16(); - IsTransient = 0; - move16(); - IF(NE_16(st_fx->last_extl, st_fx->extl)) - { - st_fx->TransientHangOver = 0; - move16(); - st_fx->old_hpfilt_in_fx = 0; - move16(); - st_fx->old_hpfilt_out_fx = 0; - move16(); - } + IsTransient = 0; + move16(); + IF( NE_16( st_fx->last_extl, st_fx->extl ) ) + { + st_fx->TransientHangOver = 0; + move16(); + st_fx->old_hpfilt_in_fx = 0; + move16(); + st_fx->old_hpfilt_out_fx = 0; + move16(); + } - /* High pass filter */ - hp_filter_fx(in_fx, out_filt_fx, &(st_fx->old_hpfilt_in_fx), &(st_fx->old_hpfilt_out_fx), L); + /* High pass filter */ + hp_filter_fx( in_fx, out_filt_fx, &( st_fx->old_hpfilt_in_fx ), &( st_fx->old_hpfilt_out_fx ), L ); - /* Long term energy */ - test(); - test(); - test(); - IF(NE_16(st_fx->last_extl, st_fx->extl) || (EQ_16(st_fx->last_extl, st_fx->extl) && NE_16(st_fx->last_core, st_fx->core)) || EQ_16(st_fx->last_codec_mode, MODE2)) - { - /*EnergyLT = EPSILON_FX; */ - EnergyLT = L_deposit_l(0); - FOR(i = 0; i < L / 4; i++) - { - /*EnergyLT += out_filt[i] * out_filt[i]; */ + /* Long term energy */ + test(); + test(); + test(); + IF( NE_16( st_fx->last_extl, st_fx->extl ) || ( EQ_16( st_fx->last_extl, st_fx->extl ) && NE_16( st_fx->last_core, st_fx->core ) ) || EQ_16( st_fx->last_codec_mode, MODE2 ) ) + { + /*EnergyLT = EPSILON_FX; */ + EnergyLT = L_deposit_l( 0 ); + FOR( i = 0; i < L / 4; i++ ) + { + /*EnergyLT += out_filt[i] * out_filt[i]; */ #ifdef BASOP_NOGLOB - EnergyLT = L_mac0_o(EnergyLT, out_filt_fx[i], out_filt_fx[i], &Overflow); /*2Q_new */ -#else - EnergyLT = L_mac0(EnergyLT, out_filt_fx[i], out_filt_fx[i]); /*2Q_new */ + EnergyLT = L_mac0_o( EnergyLT, out_filt_fx[i], out_filt_fx[i], &Overflow ); /*2Q_new */ +#else + EnergyLT = L_mac0( EnergyLT, out_filt_fx[i], out_filt_fx[i] ); /*2Q_new */ #endif - } - } - ELSE - { - EnergyLT = L_add(st_fx->EnergyLT_fx, 0); /*2Q_new */ - } - IF(EQ_16(L, L_FRAME8k)) - { - Energy_in_fx[0] = st_fx->Energy_Old_fx; - move32(); - /* Compute block energy */ - FOR(blk = 0; blk < 4; blk++) - { - Energy_fx = L_deposit_l(0); - Energy_in_fx[blk + 1] = L_deposit_l(0); - FOR(i = 0; i < L / 4; i++) - { - temp16 = extract_l(L_shr(out_filt_fx[i + blk * (L / 4)], 12)); + } + } + ELSE + { + EnergyLT = L_add( st_fx->EnergyLT_fx, 0 ); /*2Q_new */ + } + IF( EQ_16( L, L_FRAME8k ) ) + { + Energy_in_fx[0] = st_fx->Energy_Old_fx; + move32(); + /* Compute block energy */ + FOR( blk = 0; blk < 4; blk++ ) + { + Energy_fx = L_deposit_l( 0 ); + Energy_in_fx[blk + 1] = L_deposit_l( 0 ); + FOR( i = 0; i < L / 4; i++ ) + { + temp16 = extract_l( L_shr( out_filt_fx[i + blk * ( L / 4 )], 12 ) ); #ifdef BASOP_NOGLOB - Energy_fx = L_add_o(Energy_fx, L_mult0(temp16, temp16), &Overflow); + Energy_fx = L_add_o( Energy_fx, L_mult0( temp16, temp16 ), &Overflow ); #else - Energy_fx = L_add(Energy_fx, L_mult0(temp16, temp16)); + Energy_fx = L_add( Energy_fx, L_mult0( temp16, temp16 ) ); #endif - temp16 = shr(in_fx[i + blk * (L / 4)], Q_new); + temp16 = shr( in_fx[i + blk * ( L / 4 )], Q_new ); #ifdef BASOP_NOGLOB - Energy_in_fx[blk + 1] = L_add_o(Energy_in_fx[blk + 1], L_mult0(temp16, temp16), &Overflow); + Energy_in_fx[blk + 1] = L_add_o( Energy_in_fx[blk + 1], L_mult0( temp16, temp16 ), &Overflow ); #else - Energy_in_fx[blk + 1] = L_add(Energy_in_fx[blk + 1], L_mult0(temp16, temp16)); + Energy_in_fx[blk + 1] = L_add( Energy_in_fx[blk + 1], L_mult0( temp16, temp16 ) ); #endif - move32(); - } + move32(); + } #ifdef BASOP_NOGLOB - E_in_fx = L_add_o(E_in_fx, Energy_in_fx[blk + 1], &Overflow); - E_out_fx = L_add_o(E_out_fx, Energy_fx, &Overflow); + E_in_fx = L_add_o( E_in_fx, Energy_in_fx[blk + 1], &Overflow ); + E_out_fx = L_add_o( E_out_fx, Energy_fx, &Overflow ); #else - E_in_fx = L_add(E_in_fx, Energy_in_fx[blk + 1]); - E_out_fx = L_add(E_out_fx, Energy_fx); + E_in_fx = L_add( E_in_fx, Energy_in_fx[blk + 1] ); + E_out_fx = L_add( E_out_fx, Energy_fx ); #endif - Thres_fx = 2185;/*1 /15 */ - move16(); - IF(GT_32(Mult_32_16(Energy_fx, 5461), EnergyLT)) - { - IsTransient = 1; - move16(); - position = blk; - move16(); - } + Thres_fx = 2185; /*1 /15 */ + move16(); + IF( GT_32( Mult_32_16( Energy_fx, 5461 ), EnergyLT ) ) + { + IsTransient = 1; + move16(); + position = blk; + move16(); + } - EnergyLT = L_add(Mult_32_16(EnergyLT, 24576), Mult_32_16(Energy_fx, 8192)); - } - } - ELSE - { - /* Compute block energy */ - FOR(blk = 0; blk < 4; blk++) - { - L_tmp = L_deposit_l(0); - FOR(i = 0; i < L / 8; i++) - { - /*Energy += out_filt_fx[i + blk*(L/4)] * out_filt_fx[i + blk*(L/4)]; */ + EnergyLT = L_add( Mult_32_16( EnergyLT, 24576 ), Mult_32_16( Energy_fx, 8192 ) ); + } + } + ELSE + { + /* Compute block energy */ + FOR( blk = 0; blk < 4; blk++ ) + { + L_tmp = L_deposit_l( 0 ); + FOR( i = 0; i < L / 8; i++ ) + { + /*Energy += out_filt_fx[i + blk*(L/4)] * out_filt_fx[i + blk*(L/4)]; */ #ifdef BASOP_NOGLOB - L_tmp = L_mac0_o(L_tmp, out_filt_fx[i + blk * (L / 4)], out_filt_fx[i + blk * (L / 4)], &Overflow); /*2Q_new */ -#else - L_tmp = L_mac0(L_tmp, out_filt_fx[i + blk * (L / 4)], out_filt_fx[i + blk * (L / 4)]); /*2Q_new */ + L_tmp = L_mac0_o( L_tmp, out_filt_fx[i + blk * ( L / 4 )], out_filt_fx[i + blk * ( L / 4 )], &Overflow ); /*2Q_new */ +#else + L_tmp = L_mac0( L_tmp, out_filt_fx[i + blk * ( L / 4 )], out_filt_fx[i + blk * ( L / 4 )] ); /*2Q_new */ #endif - } - L_tmp2 = L_deposit_l(0); - FOR(; i < L / 4; i++) - { - /*Energy += out_filt_fx[i + blk*(L/4)] * out_filt_fx[i + blk*(L/4)]; */ + } + L_tmp2 = L_deposit_l( 0 ); + FOR( ; i < L / 4; i++ ) + { + /*Energy += out_filt_fx[i + blk*(L/4)] * out_filt_fx[i + blk*(L/4)]; */ #ifdef BASOP_NOGLOB - L_tmp2 = L_mac0_o(L_tmp2, out_filt_fx[i + blk * (L / 4)], out_filt_fx[i + blk * (L / 4)], &Overflow); /*2Q_new */ -#else - L_tmp2 = L_mac0(L_tmp2, out_filt_fx[i + blk * (L / 4)], out_filt_fx[i + blk * (L / 4)]); /*2Q_new */ + L_tmp2 = L_mac0_o( L_tmp2, out_filt_fx[i + blk * ( L / 4 )], out_filt_fx[i + blk * ( L / 4 )], &Overflow ); /*2Q_new */ +#else + L_tmp2 = L_mac0( L_tmp2, out_filt_fx[i + blk * ( L / 4 )], out_filt_fx[i + blk * ( L / 4 )] ); /*2Q_new */ #endif - } - Overflow = 0; - move16(); -#ifdef BASOP_NOGLOB /* Critical Overflow */ - Energy = L_add_o(L_tmp, L_tmp2, &Overflow); -#else - Energy = L_add(L_tmp, L_tmp2); + } + Overflow = 0; + move16(); +#ifdef BASOP_NOGLOB /* Critical Overflow */ + Energy = L_add_o( L_tmp, L_tmp2, &Overflow ); +#else + Energy = L_add( L_tmp, L_tmp2 ); #endif - shift = 0; - if (Overflow != 0) - { - shift = 1; - move16(); - } - Overflow = 0; - move16(); + shift = 0; + if ( Overflow != 0 ) + { + shift = 1; + move16(); + } + Overflow = 0; + move16(); #ifdef BASOP_NOGLOB /* shift is >= 0, not overflow possible for shr */ - Energy = L_add_o(L_shr(L_tmp, shift), L_shr(L_tmp2, shift), &Overflow); + Energy = L_add_o( L_shr( L_tmp, shift ), L_shr( L_tmp2, shift ), &Overflow ); #else - Energy = L_add(L_shr(L_tmp, shift), L_shr(L_tmp2, shift)); + Energy = L_add( L_shr( L_tmp, shift ), L_shr( L_tmp2, shift ) ); #endif - test(); - IF(EQ_16(st_fx->extl,SWB_BWE) || EQ_16(st_fx->extl,FB_BWE)) - { - /*Calculate shift to get to Q0*/ - test(); - test(); - IF((GT_32(Mult_32_16(Energy, shl(2427, shift)), EnergyLT)) || (GT_32(Mult_32_16(Energy,shl(3277,shift)),EnergyLT) - && EQ_16(st_fx->core,ACELP_CORE) && EQ_16(st_fx->coder_type,INACTIVE))) - { - IsTransient = 1; - move16(); - position = blk; - move16(); - } - } - ELSE - { - test(); - IF(LE_32(st_fx->total_brate,HQ_16k40) && EQ_16(st_fx->bwidth,SWB)) - { - thr = 2427; - move16(); - } - ELSE - { - thr = 5461; - move16(); - } - thr = shl(thr, shift); - /*if(Energy > L_shr(Mult_32_16(EnergyLT,22624),shift_cnt)) //getting in Q0 32*16 = Q_inp1+Q_inp2+1-16 */ - IF(GT_32(Mult_32_16(Energy, thr),EnergyLT)) - /*if(Energy > 6.0f * EnergyLT) */ - { - IsTransient = 1; - move16(); - position = blk; - move16(); - } - } - /*EnergyLT = 0.75f*EnergyLT + 0.25f*Energy; */ - /*0.75f*EnergyLT in Q0 //0.25f*Energy in Q0 */ - #ifdef BASOP_NOGLOB - EnergyLT = L_add_o(Mult_32_16(EnergyLT,24576),Mult_32_16(Energy, shl(8192, shift)), &Overflow); /*2Q_new */ - #else /* BASOP_NOGLOB */ - EnergyLT = L_add(Mult_32_16(EnergyLT,24576),Mult_32_16(Energy, shl(8192, shift))); /*2Q_new */ - #endif - } - } - st_fx->EnergyLT_fx = EnergyLT; - move32(); + test(); + IF( EQ_16( st_fx->extl, SWB_BWE ) || EQ_16( st_fx->extl, FB_BWE ) ) + { + /*Calculate shift to get to Q0*/ + test(); + test(); + IF( ( GT_32( Mult_32_16( Energy, shl( 2427, shift ) ), EnergyLT ) ) || ( GT_32( Mult_32_16( Energy, shl( 3277, shift ) ), EnergyLT ) && EQ_16( st_fx->core, ACELP_CORE ) && EQ_16( st_fx->coder_type, INACTIVE ) ) ) + { + IsTransient = 1; + move16(); + position = blk; + move16(); + } + } + ELSE + { + test(); + IF( LE_32( st_fx->total_brate, HQ_16k40 ) && EQ_16( st_fx->bwidth, SWB ) ) + { + thr = 2427; + move16(); + } + ELSE + { + thr = 5461; + move16(); + } + thr = shl( thr, shift ); + /*if(Energy > L_shr(Mult_32_16(EnergyLT,22624),shift_cnt)) //getting in Q0 32*16 = Q_inp1+Q_inp2+1-16 */ + IF( GT_32( Mult_32_16( Energy, thr ), EnergyLT ) ) + /*if(Energy > 6.0f * EnergyLT) */ + { + IsTransient = 1; + move16(); + position = blk; + move16(); + } + } + /*EnergyLT = 0.75f*EnergyLT + 0.25f*Energy; */ + /*0.75f*EnergyLT in Q0 //0.25f*Energy in Q0 */ +#ifdef BASOP_NOGLOB + EnergyLT = L_add_o( Mult_32_16( EnergyLT, 24576 ), Mult_32_16( Energy, shl( 8192, shift ) ), &Overflow ); /*2Q_new */ +#else /* BASOP_NOGLOB */ + EnergyLT = L_add( Mult_32_16( EnergyLT, 24576 ), Mult_32_16( Energy, shl( 8192, shift ) ) ); /*2Q_new */ +#endif + } + } + st_fx->EnergyLT_fx = EnergyLT; + move32(); - test(); - test(); - test(); - test(); - test(); - if ((NE_16(st_fx->last_extl, SWB_BWE) && NE_16(st_fx->last_extl, SWB_TBE) && EQ_16(st_fx->extl, SWB_BWE)) || - (NE_16(st_fx->last_extl, FB_BWE) && NE_16(st_fx->last_extl, FB_TBE) && EQ_16(st_fx->extl, FB_BWE))) - { - IsTransient = 0; - move16(); - } + test(); + test(); + test(); + test(); + test(); + if ( ( NE_16( st_fx->last_extl, SWB_BWE ) && NE_16( st_fx->last_extl, SWB_TBE ) && EQ_16( st_fx->extl, SWB_BWE ) ) || + ( NE_16( st_fx->last_extl, FB_BWE ) && NE_16( st_fx->last_extl, FB_TBE ) && EQ_16( st_fx->extl, FB_BWE ) ) ) + { + IsTransient = 0; + move16(); + } - test(); - IF(IsTransient && L == L_FRAME8k) - { - blk = 0; - move16(); - E_low_fx = L_deposit_l(0); - FOR(i = 0; i < position + 1; i++) - { - /*blk++; */ - blk = add(blk, 1); -#ifdef BASOP_NOGLOB - E_low_fx = L_add_sat(E_low_fx, Energy_in_fx[i]); + test(); + IF( IsTransient && L == L_FRAME8k ) + { + blk = 0; + move16(); + E_low_fx = L_deposit_l( 0 ); + FOR( i = 0; i < position + 1; i++ ) + { + /*blk++; */ + blk = add( blk, 1 ); +#ifdef BASOP_NOGLOB + E_low_fx = L_add_sat( E_low_fx, Energy_in_fx[i] ); #else - E_low_fx = L_add(E_low_fx, Energy_in_fx[i]); + E_low_fx = L_add( E_low_fx, Energy_in_fx[i] ); #endif - } + } - exp = norm_s(blk); - temp16 = div_s(16384, shl(blk, exp));/* 15 + 14 - exp; */ - exp = 15 + 14 - exp; - temp16 = shl(temp16, sub(15, exp)); - E_low_fx = Mult_32_16(E_low_fx, temp16); + exp = norm_s( blk ); + temp16 = div_s( 16384, shl( blk, exp ) ); /* 15 + 14 - exp; */ + exp = 15 + 14 - exp; + temp16 = shl( temp16, sub( 15, exp ) ); + E_low_fx = Mult_32_16( E_low_fx, temp16 ); - blk = 0; - move16(); - E_high_fx = L_deposit_l(0); - FOR(i = position + 1; i < 5; i++) - { - /*blk++; */ - blk = add(blk, 1); + blk = 0; + move16(); + E_high_fx = L_deposit_l( 0 ); + FOR( i = position + 1; i < 5; i++ ) + { + /*blk++; */ + blk = add( blk, 1 ); #ifdef BASOP_NOGLOB E_high_fx = L_add_sat( E_high_fx, Energy_in_fx[i] ); #else - E_high_fx = L_add(E_high_fx, Energy_in_fx[i]); + E_high_fx = L_add( E_high_fx, Energy_in_fx[i] ); #endif - } + } - exp = norm_s(blk); - temp16 = div_s(16384, shl(blk, exp));/* 15 + 14 - exp; */ - exp = 15 + 14 - exp; - temp16 = shl(temp16, 15 - exp); - E_high_fx = Mult_32_16(E_high_fx, temp16); + exp = norm_s( blk ); + temp16 = div_s( 16384, shl( blk, exp ) ); /* 15 + 14 - exp; */ + exp = 15 + 14 - exp; + temp16 = shl( temp16, 15 - exp ); + E_high_fx = Mult_32_16( E_high_fx, temp16 ); - test(); - test(); - IF(LT_32(L_shr(E_high_fx, 1), E_low_fx) && GT_32(E_high_fx, Mult_32_16(E_low_fx, 22938)) && GT_32(Mult_32_16(E_in_fx, Thres_fx), E_out_fx)) - { - IsTransient = 0; - move16(); - } - } - IF(EQ_32(st_fx->core_brate, ACELP_24k40)) - { - test(); - IF(NE_16(st_fx->last_core, HQ_CORE) || NE_32(st_fx->last_core_brate, ACELP_24k40)) - { - st_fx->TransientHangOver = 0; - move16(); - IsTransient = 0; - move16(); - } - ELSE - { - IF(IsTransient) - { - IF(EQ_16(position,3)) - { - /* Set Hangover */ - st_fx->TransientHangOver = 1; - move16(); - } - } - ELSE - { - IF(st_fx->TransientHangOver) - { - st_fx->TransientHangOver = 0; - move16(); - IsTransient = 1; - move16(); - } - } - } - } - ELSE - { - IF(IsTransient) - { - st_fx->TransientHangOver = 1; - move16(); - } - ELSE - { - IF(st_fx->TransientHangOver) - { - st_fx->TransientHangOver = 0; - move16(); - IsTransient = 1; - move16(); - } - } - } + test(); + test(); + IF( LT_32( L_shr( E_high_fx, 1 ), E_low_fx ) && GT_32( E_high_fx, Mult_32_16( E_low_fx, 22938 ) ) && GT_32( Mult_32_16( E_in_fx, Thres_fx ), E_out_fx ) ) + { + IsTransient = 0; + move16(); + } + } + IF( EQ_32( st_fx->core_brate, ACELP_24k40 ) ) + { + test(); + IF( NE_16( st_fx->last_core, HQ_CORE ) || NE_32( st_fx->last_core_brate, ACELP_24k40 ) ) + { + st_fx->TransientHangOver = 0; + move16(); + IsTransient = 0; + move16(); + } + ELSE + { + IF( IsTransient ) + { + IF( EQ_16( position, 3 ) ) + { + /* Set Hangover */ + st_fx->TransientHangOver = 1; + move16(); + } + } + ELSE + { + IF( st_fx->TransientHangOver ) + { + st_fx->TransientHangOver = 0; + move16(); + IsTransient = 1; + move16(); + } + } + } + } + ELSE + { + IF( IsTransient ) + { + st_fx->TransientHangOver = 1; + move16(); + } + ELSE + { + IF( st_fx->TransientHangOver ) + { + st_fx->TransientHangOver = 0; + move16(); + IsTransient = 1; + move16(); + } + } + } - IF(EQ_16(L, L_FRAME8k)) - { - st_fx->Energy_Old_fx = Energy_in_fx[4]; - move32(); - } + IF( EQ_16( L, L_FRAME8k ) ) + { + st_fx->Energy_Old_fx = Energy_in_fx[4]; + move32(); + } - return IsTransient; + return IsTransient; } diff --git a/lib_enc/diffcod_fx.c b/lib_enc/diffcod_fx.c index 53275e2f3..5fd01046a 100644 --- a/lib_enc/diffcod_fx.c +++ b/lib_enc/diffcod_fx.c @@ -2,13 +2,13 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Compilation switches */ -#include "rom_com_fx.h" /* Static table prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Compilation switches */ +#include "rom_com_fx.h" /* Static table prototypes */ //#include "prot_fx.h" /* Function Prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*--------------------------------------------------------------------------*/ /* Function diffcod */ @@ -18,36 +18,36 @@ /*--------------------------------------------------------------------------*/ void diffcod_fx( - const Word16 N, /* i : number of sub-vectors */ - Word16 *y, /* i/o: indices of quantized norms */ - Word16 *difidx /* o : differential code */ + const Word16 N, /* i : number of sub-vectors */ + Word16 *y, /* i/o: indices of quantized norms */ + Word16 *difidx /* o : differential code */ ) { Word16 i, k, r; - FOR (i=N-1; i>0; i--) + FOR( i = N - 1; i > 0; i-- ) { - r = sub(i, 1); - k = sub(y[i], y[r]); - if ( LT_16(k, -15)) + r = sub( i, 1 ); + k = sub( y[i], y[r] ); + if ( LT_16( k, -15 ) ) { - y[r] = add(y[i], 15); + y[r] = add( y[i], 15 ); move16(); } } - FOR (i=1; i0; i--) + m = sub( N, 1 ); + FOR( i = m; i > 0; i-- ) { - r = sub(i, 1); - k = sub(y[i], y[r]); + r = sub( i, 1 ); + k = sub( y[i], y[r] ); move16(); - if ( LT_16(k, thr_l)) + if ( LT_16( k, thr_l ) ) { - y[r] = sub(y[i], thr_l); + y[r] = sub( y[i], thr_l ); move16(); } } - FOR (i=1; i -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ //#include "prot_fx.h" /* Function prototypes */ #include "rom_com_fx.h" #include "rom_com.h" //#include "basop_mpy.h" #include -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* * Local constants *-------------------------------------------------------------------*/ -#define ALPHA_ENER_FAST_FX 29491 /* Fast adaptation (noise down, speech up) */ -#define ALPHA_ENER_SLOW_FX 32440 /* Fast adaptation (noise down, speech up) */ +#define ALPHA_ENER_FAST_FX 29491 /* Fast adaptation (noise down, speech up) */ +#define ALPHA_ENER_SLOW_FX 32440 /* Fast adaptation (noise down, speech up) */ -#define MIN_CNT 50 /* Minimum frame number before SID interval adaptation */ +#define MIN_CNT 50 /* Minimum frame number before SID interval adaptation */ -#define SNR_H_FX 13056 /* Estimated SNR and corresponding SID interval */ -#define SNR_L_FX 9216 /* 51dB corresponds to 25dB SNR before noise supressor */ -#define INT_H 50 -#define INT_L 8 -#define RATIO (INT_H - INT_L)/((SNR_H_FX - SNR_L_FX)/256) +#define SNR_H_FX 13056 /* Estimated SNR and corresponding SID interval */ +#define SNR_L_FX 9216 /* 51dB corresponds to 25dB SNR before noise supressor */ +#define INT_H 50 +#define INT_L 8 +#define RATIO ( INT_H - INT_L ) / ( ( SNR_H_FX - SNR_L_FX ) / 256 ) -#define LTE_VAR_FX -1024 /* Q8, -4.0f */ +#define LTE_VAR_FX -1024 /* Q8, -4.0f */ -#define CNG_TYPE_HO 20 /* hangover for switching between CNG types */ +#define CNG_TYPE_HO 20 /* hangover for switching between CNG types */ - /* _DIFF_FLOAT_FIX_ : lp_noise_fx threshold is different between float (15) and fix (5*256) */ -#define LP_NOISE_LV 5 /* LP_NOISE level */ +/* _DIFF_FLOAT_FIX_ : lp_noise_fx threshold is different between float (15) and fix (5*256) */ +#define LP_NOISE_LV 5 /* LP_NOISE level */ #define MAX_BRATE_DTX_EVS ACELP_24k40 /* maximum bitrate to which the default DTX is applied in EVS; otherwise DTX is applied only in silence */ #define MAX_BRATE_DTX_IVAS IVAS_64k /* maximum bitrate to which the default DTX is applied in IVAS; otherwise DTX is applied only in silence */ @@ -41,7 +41,7 @@ * Local function prototypes *-------------------------------------------------------------------*/ -static void update_SID_cnt(DTX_ENC_HANDLE hDtxEnc, const Word32 core_brate, const Word16 Opt_AMR_WB); +static void update_SID_cnt( DTX_ENC_HANDLE hDtxEnc, const Word32 core_brate, const Word16 Opt_AMR_WB ); /*==================================================================================*/ @@ -66,17 +66,17 @@ static void update_SID_cnt(DTX_ENC_HANDLE hDtxEnc, const Word32 core_brate, cons /* _ None */ /*==================================================================================*/ void dtx_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 vad, /* i : vad flag for DTX */ - const Word16 speech[], /* i : Pointer to the speech frame */ - Word16 Q_speech /* i : Q factor for speech */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word16 vad, /* i : vad flag for DTX */ + const Word16 speech[], /* i : Pointer to the speech frame */ + Word16 Q_speech /* i : Q factor for speech */ ) { - Word16 alpha,j,i,Q_speech2; + Word16 alpha, j, i, Q_speech2; Word32 L_tmp; - DTX_ENC_HANDLE hDtxEnc = st_fx->hDtxEnc; - TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; + DTX_ENC_HANDLE hDtxEnc = st_fx->hDtxEnc; + TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; Word16 last_br_cng_flag, last_br_flag, br_dtx_flag; #ifdef BASOP_NOGLOB_DECLARE_LOCAL @@ -84,22 +84,24 @@ void dtx_fx( #endif #ifdef IVAS_CODE - IF (st_fx->dtx_sce_sba != 0) + IF( st_fx->dtx_sce_sba != 0 ) #else - if (0) + if ( 0 ) #endif { last_br_cng_flag = 1; last_br_flag = 1; br_dtx_flag = 1; - move16();move16();move16(); + move16(); + move16(); + move16(); } ELSE { /* _DIFF_FLOAT_FIX_ : lp_noise_fx threshold is different between float (15) and fix (5*256) */ - last_br_cng_flag = LE_32(st_fx->last_total_brate_cng, ACELP_24k40) || LT_16(st_fx->lp_noise_fx, LP_NOISE_LV *256) || (EQ_16(st_fx->element_mode, IVAS_SCE) && LE_32(st_fx->last_total_brate_cng, ACELP_32k)); + last_br_cng_flag = LE_32( st_fx->last_total_brate_cng, ACELP_24k40 ) || LT_16( st_fx->lp_noise_fx, LP_NOISE_LV * 256 ) || ( EQ_16( st_fx->element_mode, IVAS_SCE ) && LE_32( st_fx->last_total_brate_cng, ACELP_32k ) ); - last_br_flag = LE_32(st_fx->last_total_brate, ACELP_24k40) || LT_16(st_fx->lp_noise_fx, LP_NOISE_LV * 256) || (EQ_16(st_fx->element_mode, IVAS_SCE) && LE_32(st_fx->last_total_brate, ACELP_32k)); + last_br_flag = LE_32( st_fx->last_total_brate, ACELP_24k40 ) || LT_16( st_fx->lp_noise_fx, LP_NOISE_LV * 256 ) || ( EQ_16( st_fx->element_mode, IVAS_SCE ) && LE_32( st_fx->last_total_brate, ACELP_32k ) ); br_dtx_flag = 0; move16(); } @@ -112,7 +114,7 @@ void dtx_fx( st_fx->cng_type = FD_CNG; move16(); test(); - if( (EQ_16( st_fx->codec_mode, MODE1 )||st_fx->Opt_AMR_WB) && EQ_16(st_fx->element_mode, IVAS_SCE) && EQ_16(st_fx->element_mode, IVAS_CPE_MDCT)) + if ( ( EQ_16( st_fx->codec_mode, MODE1 ) || st_fx->Opt_AMR_WB ) && EQ_16( st_fx->element_mode, IVAS_SCE ) && EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) { st_fx->cng_type = LP_CNG; move16(); @@ -121,21 +123,21 @@ void dtx_fx( test(); test(); IF( st_fx->Opt_DTX_ON && vad == 0 && - GT_16(st_fx->ini_frame,2) && /* CNG coding starts after 2 frames */ - st_fx->fd_cng_reset_flag == 0 && - NE_16(st_fx->last_core, AMR_WB_CORE) && + GT_16( st_fx->ini_frame, 2 ) && /* CNG coding starts after 2 frames */ + st_fx->fd_cng_reset_flag == 0 && + NE_16( st_fx->last_core, AMR_WB_CORE ) && st_fx->Opt_AMR_WB == 0 ) { test(); test(); test(); - IF ( GT_32(st_fx->last_core_brate,SID_2k40) && NE_32(st_fx->last_total_brate_cng,-1) && - NE_32(st_fx->last_total_brate_cng,st_fx->total_brate) && last_br_cng_flag) + IF( GT_32( st_fx->last_core_brate, SID_2k40 ) && NE_32( st_fx->last_total_brate_cng, -1 ) && + NE_32( st_fx->last_total_brate_cng, st_fx->total_brate ) && last_br_cng_flag ) { st_fx->total_brate = st_fx->last_total_brate_cng; move32(); test(); - if( !(EQ_32(st_fx->total_brate,ACELP_7k20)&&st_fx->Opt_SC_VBR)) + if ( !( EQ_32( st_fx->total_brate, ACELP_7k20 ) && st_fx->Opt_SC_VBR ) ) { st_fx->Opt_SC_VBR = 0; move16(); @@ -149,13 +151,13 @@ void dtx_fx( } test(); test(); - IF ( LE_32(st_fx->last_core_brate,SID_2k40) && NE_32(st_fx->last_total_brate,st_fx->total_brate) && last_br_flag) + IF( LE_32( st_fx->last_core_brate, SID_2k40 ) && NE_32( st_fx->last_total_brate, st_fx->total_brate ) && last_br_flag ) { st_fx->total_brate = st_fx->last_total_brate; move32(); test(); - if( !(EQ_32(st_fx->total_brate,ACELP_7k20)&&st_fx->Opt_SC_VBR)) + if ( !( EQ_32( st_fx->total_brate, ACELP_7k20 ) && st_fx->Opt_SC_VBR ) ) { st_fx->Opt_SC_VBR = 0; move16(); @@ -166,7 +168,7 @@ void dtx_fx( test(); test(); test(); - if( st_fx->rf_mode && st_fx->rf_fec_offset > 0 && EQ_32(st_fx->total_brate,ACELP_13k20)&&NE_16(st_fx->bwidth,NB)) + if ( st_fx->rf_mode && st_fx->rf_fec_offset > 0 && EQ_32( st_fx->total_brate, ACELP_13k20 ) && NE_16( st_fx->bwidth, NB ) ) { st_fx->Opt_RF_ON = 1; move16(); @@ -175,14 +177,14 @@ void dtx_fx( move16(); st_fx->bwidth = st_fx->last_bwidth; move32(); - IF (GT_16(st_fx->element_mode, EVS_MONO)) + IF( GT_16( st_fx->element_mode, EVS_MONO ) ) { st_fx->codec_mode = MODE1; move16(); } ELSE { - st_fx->codec_mode = get_codec_mode(st_fx->total_brate); + st_fx->codec_mode = get_codec_mode( st_fx->total_brate ); } } } @@ -191,18 +193,18 @@ void dtx_fx( * Select SID or FRAME_NO_DATA frame if DTX is enabled *------------------------------------------------------------------------*/ #ifdef IVAS_CODE - if (st_fx->dtx_sce_sba == 0) + if ( st_fx->dtx_sce_sba == 0 ) #endif { - br_dtx_flag = LE_32(st_fx->total_brate, ACELP_24k40) || LT_16(st_fx->lp_noise_fx, LP_NOISE_LV * 256) || (EQ_16(st_fx->element_mode, IVAS_SCE) && LE_32(st_fx->total_brate, ACELP_32k)) || - EQ_16(st_fx->element_mode, IVAS_CPE_DFT) || (EQ_16(st_fx->element_mode, IVAS_CPE_MDCT) && (LE_32(st_fx->element_brate, IVAS_64k) || LT_16(st_fx->lp_noise_fx, LP_NOISE_LV * 256))); + br_dtx_flag = LE_32( st_fx->total_brate, ACELP_24k40 ) || LT_16( st_fx->lp_noise_fx, LP_NOISE_LV * 256 ) || ( EQ_16( st_fx->element_mode, IVAS_SCE ) && LE_32( st_fx->total_brate, ACELP_32k ) ) || + EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) || ( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) && ( LE_32( st_fx->element_brate, IVAS_64k ) || LT_16( st_fx->lp_noise_fx, LP_NOISE_LV * 256 ) ) ); } test(); test(); test(); test(); IF( st_fx->Opt_DTX_ON && vad == 0 && - GT_16(st_fx->ini_frame,2) && /* CNG coding starts after 2 frames */ + GT_16( st_fx->ini_frame, 2 ) && /* CNG coding starts after 2 frames */ br_dtx_flag && st_fx->fd_cng_reset_flag == 0 ) { @@ -223,10 +225,10 @@ void dtx_fx( st_fx->last_codec_mode_cng = st_fx->codec_mode; } - IF(hDtxEnc->cnt_SID == 0 ) + IF( hDtxEnc->cnt_SID == 0 ) { /* this will be a SID frame */ - IF ( st_fx->Opt_AMR_WB ) + IF( st_fx->Opt_AMR_WB ) { st_fx->core_brate = SID_1k75; move32(); @@ -246,30 +248,36 @@ void dtx_fx( test(); test(); - IF( EQ_32(st_fx->core_brate,FRAME_NO_DATA)&&NE_16(st_fx->last_core,ACELP_CORE)&&!st_fx->Opt_AMR_WB) + IF( EQ_32( st_fx->core_brate, FRAME_NO_DATA ) && NE_16( st_fx->last_core, ACELP_CORE ) && !st_fx->Opt_AMR_WB ) { /* force SID frame when switching from HQ core or AMR-WB IO mode into inactive frame in ACELP core when DTX is on */ st_fx->core_brate = SID_2k40; move32(); } - //PMT("dtx_sce_sba code is missing") + // PMT("dtx_sce_sba code is missing") #ifdef IVAS_CODE - IF ((NE_16(st_fx->last_core, ACELP_CORE) || EQ_16(st_fx->cng_type, FD_CNG)) && EQ_16(st_fx->dtx_sce_sba, 1)) + IF( ( NE_16( st_fx->last_core, ACELP_CORE ) || EQ_16( st_fx->cng_type, FD_CNG ) ) && EQ_16( st_fx->dtx_sce_sba, 1 ) ) { - st_fx->cng_type = FD_CNG; move16(); - if (EQ_16(st_fx->element_mode, EVS_MONO) && (EQ_32(st_fx->total_brate, ACELP_9k60) || EQ_32(st_fx->total_brate, ACELP_16k40) || EQ_32(st_fx->total_brate, ACELP_24k40) || EQ_32(st_fx->total_brate, ACELP_48k) || EQ_32(st_fx->total_brate, HQ_96k) || EQ_32(st_fx->total_brate, HQ_128k))) + st_fx->cng_type = FD_CNG; + move16(); + if ( EQ_16( st_fx->element_mode, EVS_MONO ) && ( EQ_32( st_fx->total_brate, ACELP_9k60 ) || EQ_32( st_fx->total_brate, ACELP_16k40 ) || EQ_32( st_fx->total_brate, ACELP_24k40 ) || EQ_32( st_fx->total_brate, ACELP_48k ) || EQ_32( st_fx->total_brate, HQ_96k ) || EQ_32( st_fx->total_brate, HQ_128k ) ) ) { - st_fx->codec_mode = MODE2; move16(); + st_fx->codec_mode = MODE2; + move16(); } } - ELSE + ELSE #endif { - test(); test(); test(); test(); - IF((EQ_16(st_fx->cng_type,FD_CNG) && (LE_32(st_fx->total_brate,ACELP_24k40) || (NE_16(st_fx->element_mode, EVS_MONO) && LE_32(st_fx->total_brate, ACELP_32k)))) || (EQ_16(st_fx->element_mode, IVAS_CPE_MDCT))) /* at highest bitrates, use exclusively LP_CNG */ + test(); + test(); + test(); + test(); + IF( ( EQ_16( st_fx->cng_type, FD_CNG ) && ( LE_32( st_fx->total_brate, ACELP_24k40 ) || ( NE_16( st_fx->element_mode, EVS_MONO ) && LE_32( st_fx->total_brate, ACELP_32k ) ) ) ) || ( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) /* at highest bitrates, use exclusively LP_CNG */ { - test(); test(); - IF(EQ_16(st_fx->element_mode, EVS_MONO) && (EQ_32(st_fx->total_brate,ACELP_9k60) || EQ_32(st_fx->total_brate,ACELP_16k40) || EQ_32(st_fx->total_brate,ACELP_24k40))) + test(); + test(); + IF( EQ_16( st_fx->element_mode, EVS_MONO ) && ( EQ_32( st_fx->total_brate, ACELP_9k60 ) || EQ_32( st_fx->total_brate, ACELP_16k40 ) || EQ_32( st_fx->total_brate, ACELP_24k40 ) ) ) { st_fx->codec_mode = MODE2; move16(); @@ -279,7 +287,7 @@ void dtx_fx( { st_fx->cng_type = LP_CNG; move16(); - IF(st_fx->codec_mode == MODE2) + IF( st_fx->codec_mode == MODE2 ) { hTdCngEnc->lp_cng_mode2 = 1; move16(); @@ -289,14 +297,14 @@ void dtx_fx( } } -#if 1//def IVAS_CODE - /* reset the bitstream (IVAS format signalling was already written) */ - IF (NE_16(st_fx->element_mode, IVAS_CPE_MDCT) && st_fx->hBstr != NULL) +#if 1 // def IVAS_CODE + /* reset the bitstream (IVAS format signalling was already written) */ + IF( NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) && st_fx->hBstr != NULL ) { #ifndef IVAS_CODE_BITSTREAM - reset_indices_enc_fx(st_fx->hBstr); + reset_indices_enc_fx( st_fx->hBstr ); #else - reset_indices_enc(st_fx->hBstr, st_fx->hBstr->nb_ind_tot); + reset_indices_enc( st_fx->hBstr, st_fx->hBstr->nb_ind_tot ); #endif } #endif @@ -308,16 +316,16 @@ void dtx_fx( /* NB core bit rate can be "-1" at startup , so one can not use core_brate_fx <=2400 */ test(); test(); - IF ( (NE_32(st_fx->core_brate ,SID_2k40)) && (NE_32(st_fx->core_brate,SID_1k75)) && (NE_32(st_fx->core_brate, FRAME_NO_DATA))) + IF( ( NE_32( st_fx->core_brate, SID_2k40 ) ) && ( NE_32( st_fx->core_brate, SID_1k75 ) ) && ( NE_32( st_fx->core_brate, FRAME_NO_DATA ) ) ) { - IF(hDtxEnc != NULL) + IF( hDtxEnc != NULL ) { hDtxEnc->cnt_SID = 0; move16(); /* change SID update rate */ /* first SID update is only 8 (3) frames after the active speech end */ - IF(!st_fx->Opt_AMR_WB) + IF( !st_fx->Opt_AMR_WB ) { hDtxEnc->max_SID = FIXED_SID_RATE; move16(); @@ -325,28 +333,28 @@ void dtx_fx( ELSE { hDtxEnc->max_SID = 3; - move16(); /* first SID update is only 3 frames after the active speech end */ + move16(); /* first SID update is only 3 frames after the active speech end */ } - IF(LT_16(hDtxEnc->interval_SID, hDtxEnc->max_SID)) + IF( LT_16( hDtxEnc->interval_SID, hDtxEnc->max_SID ) ) { hDtxEnc->max_SID = hDtxEnc->interval_SID; - move16();/* change SID update rate */ + move16(); /* change SID update rate */ } hDtxEnc->cng_cnt = 0; - move16(); /* reset the counter of CNG frames for averaging */ + move16(); /* reset the counter of CNG frames for averaging */ } test(); - IF( GE_16(st_fx->active_fr_cnt_fx,CNG_TYPE_HO) && st_fx->Opt_AMR_WB==0 && NE_16(st_fx->element_mode, IVAS_CPE_MDCT)) + IF( GE_16( st_fx->active_fr_cnt_fx, CNG_TYPE_HO ) && st_fx->Opt_AMR_WB == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) { - IF (EQ_16(st_fx->element_mode, IVAS_SCE)) + IF( EQ_16( st_fx->element_mode, IVAS_SCE ) ) { #ifdef IVAS_CODE Word16 lp_thresh, fd_thresh; - PMT("lp_thresh scaling is to be found") + PMT( "lp_thresh scaling is to be found" ) test(); - IF (st_fx->Opt_DTX_ON && EQ_16(st_fx->dtx_sce_sba, 1) ) + IF( st_fx->Opt_DTX_ON && EQ_16( st_fx->dtx_sce_sba, 1 ) ) { lp_thresh = 5.f; fd_thresh = 2.f; @@ -359,11 +367,11 @@ void dtx_fx( } /*More conservative selection of LP-CNG for SCE*/ - if (st->cng_type == LP_CNG && (st->bckr_tilt_lt > lp_thresh)) + if ( st->cng_type == LP_CNG && ( st->bckr_tilt_lt > lp_thresh ) ) { st->cng_type = FD_CNG; } - else if (st->cng_type == FD_CNG && (st->bckr_tilt_lt < fd_thresh) && (st->lp_noise > 2.f)) + else if ( st->cng_type == FD_CNG && ( st->bckr_tilt_lt < fd_thresh ) && ( st->lp_noise > 2.f ) ) { st->cng_type = LP_CNG; } @@ -371,13 +379,20 @@ void dtx_fx( } ELSE { - test(); test(); test(); test(); test(); test(); test(); test(); - IF(EQ_16(st_fx->cng_type, LP_CNG) && ((EQ_16(st_fx->input_bwidth, NB) && GT_32(st_fx->bckr_tilt_lt, 589824l/*9.f Q16*/)) || (GT_16(st_fx->input_bwidth, NB) && GT_32(st_fx->bckr_tilt_lt, 2949120l/*45.f Q16*/)))) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( EQ_16( st_fx->cng_type, LP_CNG ) && ( ( EQ_16( st_fx->input_bwidth, NB ) && GT_32( st_fx->bckr_tilt_lt, 589824l /*9.f Q16*/ ) ) || ( GT_16( st_fx->input_bwidth, NB ) && GT_32( st_fx->bckr_tilt_lt, 2949120l /*45.f Q16*/ ) ) ) ) { st_fx->cng_type = FD_CNG; move16(); } - ELSE IF(EQ_16(st_fx->cng_type, FD_CNG) && ((EQ_16(st_fx->input_bwidth, NB) && LT_32(st_fx->bckr_tilt_lt, 131072l/*2.f Q16*/)) || (GT_16(st_fx->input_bwidth, NB) && LT_32(st_fx->bckr_tilt_lt, 655360l/*10.f Q16*/)))) + ELSE IF( EQ_16( st_fx->cng_type, FD_CNG ) && ( ( EQ_16( st_fx->input_bwidth, NB ) && LT_32( st_fx->bckr_tilt_lt, 131072l /*2.f Q16*/ ) ) || ( GT_16( st_fx->input_bwidth, NB ) && LT_32( st_fx->bckr_tilt_lt, 655360l /*10.f Q16*/ ) ) ) ) { st_fx->cng_type = LP_CNG; move16(); @@ -391,93 +406,93 @@ void dtx_fx( move16(); } st_fx->active_fr_cnt_fx = add( st_fx->active_fr_cnt_fx, 1 ); - st_fx->active_fr_cnt_fx = s_min(st_fx->active_fr_cnt_fx, 200); + st_fx->active_fr_cnt_fx = s_min( st_fx->active_fr_cnt_fx, 200 ); } /*------------------------------------------------------------------------* * Update speech and background noise long-term energy *------------------------------------------------------------------------*/ - IF (hDtxEnc != NULL) + IF( hDtxEnc != NULL ) { - hDtxEnc->frame_ener_fx = L_deposit_l(0); + hDtxEnc->frame_ener_fx = L_deposit_l( 0 ); - IF(st_fx->Opt_DTX_ON) + IF( st_fx->Opt_DTX_ON ) { - Q_speech2 = add(shl(Q_speech, 1), 7); - FOR(j = 0; j < 16; j++) + Q_speech2 = add( shl( Q_speech, 1 ), 7 ); + FOR( j = 0; j < 16; j++ ) { - L_tmp = L_mult0(*speech, *speech); + L_tmp = L_mult0( *speech, *speech ); speech++; - FOR(i = 1; i < L_FRAME / 16; i++) + FOR( i = 1; i < L_FRAME / 16; i++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_mac0_o(L_tmp, *speech, *speech, &Overflow); -#else /* BASOP_NOGLOB */ - L_tmp = L_mac0(L_tmp, *speech, *speech); + L_tmp = L_mac0_o( L_tmp, *speech, *speech, &Overflow ); +#else /* BASOP_NOGLOB */ + L_tmp = L_mac0( L_tmp, *speech, *speech ); #endif /* BASOP_NOGLOB */ speech++; } - hDtxEnc->frame_ener_fx = L_add(hDtxEnc->frame_ener_fx, L_shr(L_tmp, Q_speech2));/*Q(-7) */ + hDtxEnc->frame_ener_fx = L_add( hDtxEnc->frame_ener_fx, L_shr( L_tmp, Q_speech2 ) ); /*Q(-7) */ } /* Active speech (voiced) */ - IF(EQ_16(st_fx->clas, VOICED_CLAS)) + IF( EQ_16( st_fx->clas, VOICED_CLAS ) ) { alpha = ALPHA_ENER_SLOW_FX; move16(); - if (GT_32(hDtxEnc->frame_ener_fx, hDtxEnc->lt_ener_voiced_fx)) + if ( GT_32( hDtxEnc->frame_ener_fx, hDtxEnc->lt_ener_voiced_fx ) ) { alpha = ALPHA_ENER_FAST_FX; - move16();/*Q15 */ + move16(); /*Q15 */ } /*st_fx->lt_ener_voiced_fx = alpha * st_fx->lt_ener_voiced_fx + (1.0f-alpha) * st_fx->frame_ener_fx;*/ - L_tmp = L_sub(hDtxEnc->lt_ener_voiced_fx, hDtxEnc->frame_ener_fx); - L_tmp = Mult_32_16(L_tmp, alpha); - hDtxEnc->lt_ener_voiced_fx = L_add(L_tmp, hDtxEnc->frame_ener_fx); /*Q(-7) */ + L_tmp = L_sub( hDtxEnc->lt_ener_voiced_fx, hDtxEnc->frame_ener_fx ); + L_tmp = Mult_32_16( L_tmp, alpha ); + hDtxEnc->lt_ener_voiced_fx = L_add( L_tmp, hDtxEnc->frame_ener_fx ); /*Q(-7) */ - hDtxEnc->VarDTX_cnt_voiced = add(hDtxEnc->VarDTX_cnt_voiced, 1); + hDtxEnc->VarDTX_cnt_voiced = add( hDtxEnc->VarDTX_cnt_voiced, 1 ); - hDtxEnc->VarDTX_cnt_voiced = s_min(hDtxEnc->VarDTX_cnt_voiced, MIN_CNT); + hDtxEnc->VarDTX_cnt_voiced = s_min( hDtxEnc->VarDTX_cnt_voiced, MIN_CNT ); } /* Background noise */ - ELSE IF(!st_fx->Opt_AMR_WB) + ELSE IF( !st_fx->Opt_AMR_WB ) { alpha = ALPHA_ENER_SLOW_FX; move16(); - if (LT_32(hDtxEnc->frame_ener_fx, hDtxEnc->lt_ener_noise_fx)) + if ( LT_32( hDtxEnc->frame_ener_fx, hDtxEnc->lt_ener_noise_fx ) ) { alpha = ALPHA_ENER_FAST_FX; move16(); } /*st_fx->lt_ener_noise_fx = alpha * st_fx->lt_ener_noise_fx + (1.0f-alpha) * st_fx->frame_ener_fx;*/ - L_tmp = L_sub(hDtxEnc->lt_ener_noise_fx, hDtxEnc->frame_ener_fx); - L_tmp = Mult_32_16(L_tmp, alpha); - hDtxEnc->lt_ener_noise_fx = L_add(L_tmp, hDtxEnc->frame_ener_fx); - move32();/*Q(-7) */ + L_tmp = L_sub( hDtxEnc->lt_ener_noise_fx, hDtxEnc->frame_ener_fx ); + L_tmp = Mult_32_16( L_tmp, alpha ); + hDtxEnc->lt_ener_noise_fx = L_add( L_tmp, hDtxEnc->frame_ener_fx ); + move32(); /*Q(-7) */ - hDtxEnc->VarDTX_cnt_noise = add(hDtxEnc->VarDTX_cnt_noise, 1); + hDtxEnc->VarDTX_cnt_noise = add( hDtxEnc->VarDTX_cnt_noise, 1 ); - hDtxEnc->VarDTX_cnt_noise = s_min(hDtxEnc->VarDTX_cnt_noise, MIN_CNT); + hDtxEnc->VarDTX_cnt_noise = s_min( hDtxEnc->VarDTX_cnt_noise, MIN_CNT ); } } } /* Update of the SID counter */ - update_SID_cnt(hDtxEnc, st_fx->core_brate, st_fx->Opt_AMR_WB); + update_SID_cnt( hDtxEnc, st_fx->core_brate, st_fx->Opt_AMR_WB ); /* Update encoded bandwidth */ test(); test(); - IF( st_fx->Opt_DTX_ON && (st_fx->core_brate == SID_2k40 || st_fx->core_brate == FRAME_NO_DATA ) ) + IF( st_fx->Opt_DTX_ON && ( st_fx->core_brate == SID_2k40 || st_fx->core_brate == FRAME_NO_DATA ) ) { st_fx->bwidth = st_fx->last_bwidth; move16(); test(); - if( GT_32(st_fx->last_core_brate, SID_2k40)&&NE_32(st_fx->last_total_brate_cng,-1)) + if ( GT_32( st_fx->last_core_brate, SID_2k40 ) && NE_32( st_fx->last_total_brate_cng, -1 ) ) { st_fx->bwidth = st_fx->last_bwidth_cng; move16(); @@ -485,11 +500,11 @@ void dtx_fx( test(); test(); - IF( st_fx->Opt_RF_ON && (EQ_32(st_fx->total_brate, ACELP_13k20))&&(EQ_16(st_fx->bwidth,NB))) + IF( st_fx->Opt_RF_ON && ( EQ_32( st_fx->total_brate, ACELP_13k20 ) ) && ( EQ_16( st_fx->bwidth, NB ) ) ) { st_fx->codec_mode = MODE1; move16(); - reset_rf_indices_fx(st_fx); + reset_rf_indices_fx( st_fx ); st_fx->Opt_RF_ON = 0; move16(); st_fx->rf_mode = 0; @@ -498,9 +513,9 @@ void dtx_fx( test(); test(); - IF( st_fx->Opt_RF_ON && NE_32(st_fx->total_brate, ACELP_13k20) ) + IF( st_fx->Opt_RF_ON && NE_32( st_fx->total_brate, ACELP_13k20 ) ) { - reset_rf_indices_fx(st_fx); + reset_rf_indices_fx( st_fx ); move16(); st_fx->Opt_RF_ON = 0; move16(); @@ -508,35 +523,34 @@ void dtx_fx( } /* Set and limit the encoded bandwidth */ - IF ( EQ_16(st_fx->codec_mode, MODE2)) + IF( EQ_16( st_fx->codec_mode, MODE2 ) ) { Word16 n, bits_frame_nominal; UWord16 lsb; Word16 tmpbandwidthMin; - Mpy_32_16_ss(st_fx->total_brate, 5243, &L_tmp, &lsb); /* 5243 is 1/50 in Q18. (0+18-15=3) */ - bits_frame_nominal = extract_l(L_shr(L_tmp, 3)); /* Q0 */ + Mpy_32_16_ss( st_fx->total_brate, 5243, &L_tmp, &lsb ); /* 5243 is 1/50 in Q18. (0+18-15=3) */ + bits_frame_nominal = extract_l( L_shr( L_tmp, 3 ) ); /* Q0 */ - FOR (n=0; nrf_mode,1)) + if ( EQ_16( st_fx->rf_mode, 1 ) ) { tmpbandwidthMin = WB; } - st_fx->bwidth = s_max(s_min(st_fx->bwidth, FrameSizeConfig[n].bandwidth_max), tmpbandwidthMin); + st_fx->bwidth = s_max( s_min( st_fx->bwidth, FrameSizeConfig[n].bandwidth_max ), tmpbandwidthMin ); } - } return; @@ -549,7 +563,7 @@ void dtx_fx( *---------------------------------------------------------------------*/ static void update_SID_cnt( - DTX_ENC_HANDLE hDtxEnc, /* i/o: common DTX handle */ + DTX_ENC_HANDLE hDtxEnc, /* i/o: common DTX handle */ const Word32 core_brate, /* i : core coder core bitrate */ const Word16 Opt_AMR_WB /* i : AMR BW IO mode? */ ) @@ -559,75 +573,75 @@ static void update_SID_cnt( test(); test(); - IF( EQ_32(core_brate, SID_2k40)||EQ_32(core_brate,SID_1k75)||core_brate==FRAME_NO_DATA) + IF( EQ_32( core_brate, SID_2k40 ) || EQ_32( core_brate, SID_1k75 ) || core_brate == FRAME_NO_DATA ) { /* Adapt the SID interval */ test(); test(); - IF (hDtxEnc->var_SID_rate_flag != 0 && EQ_16(hDtxEnc->VarDTX_cnt_voiced, MIN_CNT)&&EQ_16(hDtxEnc->VarDTX_cnt_noise,MIN_CNT)) + IF( hDtxEnc->var_SID_rate_flag != 0 && EQ_16( hDtxEnc->VarDTX_cnt_voiced, MIN_CNT ) && EQ_16( hDtxEnc->VarDTX_cnt_noise, MIN_CNT ) ) { /* EstimatedSNR = 10.0f * (float)log10( (0.01f + st_fx->lt_ener_voiced) / (0.01f + st_fx->lt_ener_noise) ); */ - L_tmp1 = L_max(hDtxEnc->lt_ener_voiced_fx, 1); - exp = norm_l(L_tmp1); - frac = Log2_norm_lc(L_shl(L_tmp1, exp)); - exp = sub(30, exp); - L_tmp1 = L_Comp(exp, frac); - L_tmp2 = L_max(hDtxEnc->lt_ener_noise_fx, 1); - exp = norm_l(L_tmp2); - frac = Log2_norm_lc(L_shl(L_tmp2, exp)); - exp = sub(30, exp); - L_tmp1 = L_sub(L_tmp1, L_Comp(exp, frac)); + L_tmp1 = L_max( hDtxEnc->lt_ener_voiced_fx, 1 ); + exp = norm_l( L_tmp1 ); + frac = Log2_norm_lc( L_shl( L_tmp1, exp ) ); + exp = sub( 30, exp ); + L_tmp1 = L_Comp( exp, frac ); + L_tmp2 = L_max( hDtxEnc->lt_ener_noise_fx, 1 ); + exp = norm_l( L_tmp2 ); + frac = Log2_norm_lc( L_shl( L_tmp2, exp ) ); + exp = sub( 30, exp ); + L_tmp1 = L_sub( L_tmp1, L_Comp( exp, frac ) ); /* 10 x Log10(a/b) = 10 x Log10(2) x [Log2(a) - Log2(b)] */ /* 10 x Log10(2) = ~3.0103 */ - L_tmp1 = Mpy_32_16_1(L_tmp1, 24660); /* mult by 3.0103 / 4 in Q15 */ - L_tmp1 = L_shl(L_tmp1, 2+8); /* mult by 4 and shift left 8 to go in Q24 */ - EstimatedSNR = round_fx(L_tmp1); /* now in Q8 */ - IF ( GT_16(EstimatedSNR,SNR_H_FX)) + L_tmp1 = Mpy_32_16_1( L_tmp1, 24660 ); /* mult by 3.0103 / 4 in Q15 */ + L_tmp1 = L_shl( L_tmp1, 2 + 8 ); /* mult by 4 and shift left 8 to go in Q24 */ + EstimatedSNR = round_fx( L_tmp1 ); /* now in Q8 */ + IF( GT_16( EstimatedSNR, SNR_H_FX ) ) { hDtxEnc->interval_SID = INT_H; move16(); } - ELSE IF ( LT_16(EstimatedSNR,SNR_L_FX)) + ELSE IF( LT_16( EstimatedSNR, SNR_L_FX ) ) { hDtxEnc->interval_SID = INT_L; move16(); } ELSE { - hDtxEnc->interval_SID = extract_h(L_mac(INT_L*65536L-SNR_L_FX/256*65536L*RATIO,(32768/256)*RATIO, EstimatedSNR)); + hDtxEnc->interval_SID = extract_h( L_mac( INT_L * 65536L - SNR_L_FX / 256 * 65536L * RATIO, ( 32768 / 256 ) * RATIO, EstimatedSNR ) ); } - hDtxEnc->interval_SID = s_min(s_max(hDtxEnc->interval_SID, INT_L), INT_H); + hDtxEnc->interval_SID = s_min( s_max( hDtxEnc->interval_SID, INT_L ), INT_H ); test(); - if( Opt_AMR_WB== 0 || NE_16(hDtxEnc->max_SID,3)) + if ( Opt_AMR_WB == 0 || NE_16( hDtxEnc->max_SID, 3 ) ) { hDtxEnc->max_SID = hDtxEnc->interval_SID; - move16(); /* change SID update rate */ + move16(); /* change SID update rate */ } } test(); - IF( hDtxEnc->cnt_SID != 0 ) + IF( hDtxEnc->cnt_SID != 0 ) { - L_tmp1 = L_max(hDtxEnc->lt_ener_noise_fx, 1); - exp = norm_l(L_tmp1); - frac = Log2_norm_lc(L_shl(L_tmp1, exp)); - exp = sub(30, exp); - L_tmp1 = L_Comp(exp, frac); - L_tmp2 = L_max(hDtxEnc->lt_ener_last_SID_fx, 1); - exp = norm_l(L_tmp2); - frac = Log2_norm_lc(L_shl(L_tmp2, exp)); - exp = sub(30, exp); - L_tmp1 = L_sub(L_tmp1, L_Comp(exp, frac)); + L_tmp1 = L_max( hDtxEnc->lt_ener_noise_fx, 1 ); + exp = norm_l( L_tmp1 ); + frac = Log2_norm_lc( L_shl( L_tmp1, exp ) ); + exp = sub( 30, exp ); + L_tmp1 = L_Comp( exp, frac ); + L_tmp2 = L_max( hDtxEnc->lt_ener_last_SID_fx, 1 ); + exp = norm_l( L_tmp2 ); + frac = Log2_norm_lc( L_shl( L_tmp2, exp ) ); + exp = sub( 30, exp ); + L_tmp1 = L_sub( L_tmp1, L_Comp( exp, frac ) ); /* 10 x Log10(a/b) = 10 x Log10(2) x [Log2(a) - Log2(b)] */ /* 10 x Log10(2) = ~3.0103 */ - L_tmp1 = Mpy_32_16_1(L_tmp1, 24660); /* mult by 3.0103 / 4 in Q15 */ - L_tmp1 = L_shl(L_tmp1, 2+8); /* mult by 4 and shift left 8 to go in Q24 */ - delta = round_fx(L_tmp1); /* now in Q8 */ + L_tmp1 = Mpy_32_16_1( L_tmp1, 24660 ); /* mult by 3.0103 / 4 in Q15 */ + L_tmp1 = L_shl( L_tmp1, 2 + 8 ); /* mult by 4 and shift left 8 to go in Q24 */ + delta = round_fx( L_tmp1 ); /* now in Q8 */ test(); test(); - if ( LT_16(delta,LTE_VAR_FX)&&EQ_16(hDtxEnc->VarDTX_cnt_voiced,MIN_CNT)&&EQ_16(hDtxEnc->VarDTX_cnt_noise,MIN_CNT)) + if ( LT_16( delta, LTE_VAR_FX ) && EQ_16( hDtxEnc->VarDTX_cnt_voiced, MIN_CNT ) && EQ_16( hDtxEnc->VarDTX_cnt_noise, MIN_CNT ) ) { /* Send SID frame, and reset lt_ener_noise */ hDtxEnc->lt_ener_noise_fx = hDtxEnc->frame_ener_fx; @@ -640,15 +654,15 @@ static void update_SID_cnt( hDtxEnc->lt_ener_last_SID_fx = hDtxEnc->lt_ener_noise_fx; move32(); } - hDtxEnc->cnt_SID = add(hDtxEnc->cnt_SID,1); + hDtxEnc->cnt_SID = add( hDtxEnc->cnt_SID, 1 ); - IF(hDtxEnc->var_SID_rate_flag ) + IF( hDtxEnc->var_SID_rate_flag ) { test(); test(); test(); - if( Opt_AMR_WB!= 0 && EQ_16(hDtxEnc->max_SID,3)&&EQ_16(hDtxEnc->cnt_SID,3)) + if ( Opt_AMR_WB != 0 && EQ_16( hDtxEnc->max_SID, 3 ) && EQ_16( hDtxEnc->cnt_SID, 3 ) ) { /* set the size of CNG history buffer for averaging to DTX_HIST_SIZE frames */ /* be sure that DTX_HIST_SIZE >= INT_L */ @@ -657,7 +671,7 @@ static void update_SID_cnt( } test(); /*else if ( st_fx->max_SID != 3 && st_fx->cnt_SID == DTX_HIST_SIZE )//compile error */ - if( NE_16(hDtxEnc->max_SID,3)&&EQ_16(hDtxEnc->cnt_SID,DTX_HIST_SIZE)) + if ( NE_16( hDtxEnc->max_SID, 3 ) && EQ_16( hDtxEnc->cnt_SID, DTX_HIST_SIZE ) ) { /* set the size of CNG history buffer for averaging to 3 frames */ hDtxEnc->cng_hist_size = DTX_HIST_SIZE; @@ -665,18 +679,18 @@ static void update_SID_cnt( } } test(); - IF(hDtxEnc->var_SID_rate_flag == 0 && GT_16(hDtxEnc->interval_SID,1)) + IF( hDtxEnc->var_SID_rate_flag == 0 && GT_16( hDtxEnc->interval_SID, 1 ) ) { /* set the size of CNG history buffer for averaging to interval_SID frames */ hDtxEnc->cng_hist_size = hDtxEnc->interval_SID; move16(); - if ( GT_16(hDtxEnc->cng_hist_size, DTX_HIST_SIZE)) + if ( GT_16( hDtxEnc->cng_hist_size, DTX_HIST_SIZE ) ) { hDtxEnc->cng_hist_size = DTX_HIST_SIZE; move16(); } } - IF( GE_16(hDtxEnc->cnt_SID, hDtxEnc->max_SID)) + IF( GE_16( hDtxEnc->cnt_SID, hDtxEnc->max_SID ) ) { /* adaptive SID update interval */ hDtxEnc->max_SID = hDtxEnc->interval_SID; @@ -691,44 +705,44 @@ static void update_SID_cnt( void dtx_hangover_control_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 lsp_new_fx[M] /* i : current frame LSPs */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word16 lsp_new_fx[M] /* i : current frame LSPs */ ) { Word16 ptr; - Word16 i,j,m; - Word16 tmp_lsp[/*max(DTX_HIST_SIZE,*/HO_HIST_SIZE/*)*/*M]; - Word32 tmp_enr[/*max(DTX_HIST_SIZE,*/HO_HIST_SIZE/*)*/]; - Word16 tmp[/*max(DTX_HIST_SIZE,*/HO_HIST_SIZE/*)*/*M]; + Word16 i, j, m; + Word16 tmp_lsp[/*max(DTX_HIST_SIZE,*/ HO_HIST_SIZE /*)*/ * M]; + Word32 tmp_enr[/*max(DTX_HIST_SIZE,*/ HO_HIST_SIZE /*)*/]; + Word16 tmp[/*max(DTX_HIST_SIZE,*/ HO_HIST_SIZE /*)*/ * M]; Word16 enr_new; Word16 weights; Word32 enr_est; Word16 enr_est_log; Word16 lsp_est[M]; - Word16 Dlsp,Denr; + Word16 Dlsp, Denr; Word16 lsf_tmp[M]; Word32 C[M]; Word32 max_val[2]; Word16 max_idx[2]; Word16 ftmp_fx; - Word16 Dlsp_n2e,Denr_n2e; - Word16 exp,fra,exp2,fra2; + Word16 Dlsp_n2e, Denr_n2e; + Word16 exp, fra, exp2, fra2; Word16 S_max; Word16 S_tmp; Word32 L_tmp; VAD_HANDLE hVAD = st_fx->hVAD; - DTX_ENC_HANDLE hDtxEnc = st_fx->hDtxEnc; - TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; + DTX_ENC_HANDLE hDtxEnc = st_fx->hDtxEnc; + TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif /* get current frame exc energy in log2 */ - exp = norm_l(hTdCngEnc->ho_ener_circ_fx[hTdCngEnc->ho_circ_ptr]); - fra = Log2_norm_lc(L_shl(hTdCngEnc->ho_ener_circ_fx[hTdCngEnc->ho_circ_ptr],exp)); - exp = sub(sub(30,exp),6); - L_tmp = L_Comp(exp,fra); - enr_new = round_fx(L_shl(L_tmp,8)); /*Q8 */ + exp = norm_l( hTdCngEnc->ho_ener_circ_fx[hTdCngEnc->ho_circ_ptr] ); + fra = Log2_norm_lc( L_shl( hTdCngEnc->ho_ener_circ_fx[hTdCngEnc->ho_circ_ptr], exp ) ); + exp = sub( sub( 30, exp ), 6 ); + L_tmp = L_Comp( exp, fra ); + enr_new = round_fx( L_shl( L_tmp, 8 ) ); /*Q8 */ if ( enr_new < 0 ) { @@ -737,20 +751,20 @@ void dtx_hangover_control_fx( } /* get energies and lsps of hangover frames */ - ptr = sub(hTdCngEnc->ho_circ_ptr,sub(hTdCngEnc->burst_ho_cnt,1)); - IF ( ptr < 0 ) + ptr = sub( hTdCngEnc->ho_circ_ptr, sub( hTdCngEnc->burst_ho_cnt, 1 ) ); + IF( ptr < 0 ) { - ptr = add(hTdCngEnc->ho_circ_size,ptr); + ptr = add( hTdCngEnc->ho_circ_size, ptr ); } - FOR ( i=0; i< hTdCngEnc->burst_ho_cnt-1; i++ ) + FOR( i = 0; i < hTdCngEnc->burst_ho_cnt - 1; i++ ) { - Copy( &(hTdCngEnc->ho_lsp_circ_fx[ptr*M]), &(tmp_lsp[i*M]), M ); + Copy( &( hTdCngEnc->ho_lsp_circ_fx[ptr * M] ), &( tmp_lsp[i * M] ), M ); tmp_enr[i] = hTdCngEnc->ho_ener_circ_fx[ptr]; - move32();/*Q6 */ + move32(); /*Q6 */ - ptr = add(ptr,1); - if ( EQ_16(ptr, hTdCngEnc->ho_circ_size)) + ptr = add( ptr, 1 ); + if ( EQ_16( ptr, hTdCngEnc->ho_circ_size ) ) { ptr = 0; move16(); @@ -758,71 +772,71 @@ void dtx_hangover_control_fx( } /* get estimated CNG energy and lsps assuming terminate hangover at current frame */ - ptr = sub(hTdCngEnc->burst_ho_cnt,2); - enr_est = Mpy_32_16_1(tmp_enr[ptr],W_DTX_HO_FX[0]); /*Q6 */ + ptr = sub( hTdCngEnc->burst_ho_cnt, 2 ); + enr_est = Mpy_32_16_1( tmp_enr[ptr], W_DTX_HO_FX[0] ); /*Q6 */ weights = W_DTX_HO_FX[0]; - move16();/*Q15 */ - Copy( &(tmp_lsp[ptr*M]), tmp, M ); + move16(); /*Q15 */ + Copy( &( tmp_lsp[ptr * M] ), tmp, M ); m = 1; move16(); - FOR ( i=1; i< hTdCngEnc->burst_ho_cnt-2; i++ ) + FOR( i = 1; i < hTdCngEnc->burst_ho_cnt - 2; i++ ) { test(); - IF ( LT_32(Mpy_32_16_1(tmp_enr[ptr-i],ONE_OVER_BUF_H_NRG_FX),tmp_enr[ptr])&& - GT_32(tmp_enr[ptr-i],Mpy_32_16_1(tmp_enr[ptr], BUF_L_NRG_FX)) ) + IF( LT_32( Mpy_32_16_1( tmp_enr[ptr - i], ONE_OVER_BUF_H_NRG_FX ), tmp_enr[ptr] ) && + GT_32( tmp_enr[ptr - i], Mpy_32_16_1( tmp_enr[ptr], BUF_L_NRG_FX ) ) ) { - enr_est = L_add(enr_est,Mpy_32_16_1(tmp_enr[ptr-i],W_DTX_HO_FX[i])); /*Q6 */ - weights = add(weights,W_DTX_HO_FX[i]); /*Q15 */ - Copy( &tmp_lsp[(ptr-i)*M], &tmp[m*M], M ); - m = add(m,1); + enr_est = L_add( enr_est, Mpy_32_16_1( tmp_enr[ptr - i], W_DTX_HO_FX[i] ) ); /*Q6 */ + weights = add( weights, W_DTX_HO_FX[i] ); /*Q15 */ + Copy( &tmp_lsp[( ptr - i ) * M], &tmp[m * M], M ); + m = add( m, 1 ); } } - exp = norm_l(enr_est); + exp = norm_l( enr_est ); #ifdef BASOP_NOGLOB fra = round_fx_sat( L_shl_sat( enr_est, exp ) ); #else - fra = round_fx(L_shl(enr_est,exp)); + fra = round_fx( L_shl( enr_est, exp ) ); #endif - exp2 = norm_s(weights); - fra2 = shl(weights,exp2); - exp = sub(sub(exp,16),exp2); - IF ( GT_16(fra,fra2)) + exp2 = norm_s( weights ); + fra2 = shl( weights, exp2 ); + exp = sub( sub( exp, 16 ), exp2 ); + IF( GT_16( fra, fra2 ) ) { - fra = shr(fra,1); - exp = sub(exp,1); + fra = shr( fra, 1 ); + exp = sub( exp, 1 ); } - L_tmp = L_deposit_l(div_s(fra,fra2)); - enr_est = L_shr(L_tmp,exp); /*Q6 */ + L_tmp = L_deposit_l( div_s( fra, fra2 ) ); + enr_est = L_shr( L_tmp, exp ); /*Q6 */ - if ( LT_32(enr_est,64)) + if ( LT_32( enr_est, 64 ) ) { enr_est = 64; - move16();/*Q6 */ + move16(); /*Q6 */ } - exp = norm_l(enr_est); - fra = Log2_norm_lc(L_shl(enr_est,exp)); - exp = sub(sub(30,exp),6); - L_tmp = L_Comp(exp,fra); - enr_est_log = round_fx(L_shl(L_tmp,8)); /*Q8 */ - Denr_n2e = abs_s(sub(enr_new,enr_est_log)); /*Q8 */ + exp = norm_l( enr_est ); + fra = Log2_norm_lc( L_shl( enr_est, exp ) ); + exp = sub( sub( 30, exp ), 6 ); + L_tmp = L_Comp( exp, fra ); + enr_est_log = round_fx( L_shl( L_tmp, 8 ) ); /*Q8 */ + Denr_n2e = abs_s( sub( enr_new, enr_est_log ) ); /*Q8 */ - IF ( LT_16(m,3)) + IF( LT_16( m, 3 ) ) { - enr_est = L_add(Mpy_32_16_1(enr_est,26214),Mpy_32_16_1(hTdCngEnc->ho_ener_circ_fx[hTdCngEnc->ho_circ_ptr],6554)); /*Q6 */ + enr_est = L_add( Mpy_32_16_1( enr_est, 26214 ), Mpy_32_16_1( hTdCngEnc->ho_ener_circ_fx[hTdCngEnc->ho_circ_ptr], 6554 ) ); /*Q6 */ } ELSE { - enr_est = L_add(Mpy_32_16_1(enr_est,31130),Mpy_32_16_1(hTdCngEnc->ho_ener_circ_fx[hTdCngEnc->ho_circ_ptr],1638)); /*Q6 */ + enr_est = L_add( Mpy_32_16_1( enr_est, 31130 ), Mpy_32_16_1( hTdCngEnc->ho_ener_circ_fx[hTdCngEnc->ho_circ_ptr], 1638 ) ); /*Q6 */ } - exp = norm_l(enr_est); - fra = Log2_norm_lc(L_shl(enr_est,exp)); - exp = sub(sub(30,exp),6); - L_tmp = L_Comp(exp,fra); - enr_est_log = round_fx(L_shl(L_tmp,8)); /*Q8 */ + exp = norm_l( enr_est ); + fra = Log2_norm_lc( L_shl( enr_est, exp ) ); + exp = sub( sub( 30, exp ), 6 ); + L_tmp = L_Comp( exp, fra ); + enr_est_log = round_fx( L_shl( L_tmp, 8 ) ); /*Q8 */ if ( enr_est_log < 0 ) { @@ -833,36 +847,36 @@ void dtx_hangover_control_fx( set32_fx( max_val, 0, 2 ); set16_fx( max_idx, 0, 2 ); - FOR( i=0; iL_frame,L_FRAME)) + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { - lsp2lsf_fx( &tmp[i*M], lsf_tmp, M, INT_FS_FX ); + lsp2lsf_fx( &tmp[i * M], lsf_tmp, M, INT_FS_FX ); ftmp_fx = 964; - move16();/*QX2.56 */ - S_tmp = sub(16384,add(lsf_tmp[M-1],ftmp_fx)); /*QX2.56 */ - C[i] = L_mult0(S_tmp,S_tmp); /*QX6.5536 */ + move16(); /*QX2.56 */ + S_tmp = sub( 16384, add( lsf_tmp[M - 1], ftmp_fx ) ); /*QX2.56 */ + C[i] = L_mult0( S_tmp, S_tmp ); /*QX6.5536 */ } ELSE { - lsp2lsf_fx( &tmp[i*M], lsf_tmp, M, INT_FS_16k ); + lsp2lsf_fx( &tmp[i * M], lsf_tmp, M, INT_FS_16k ); ftmp_fx = 1205; - move16();/*QX2.56 */ - S_tmp = sub(20480,add(lsf_tmp[M-1],ftmp_fx)); /*QX2.56 */ - C[i] = L_mult0(S_tmp,S_tmp); /*QX6.5536 */ + move16(); /*QX2.56 */ + S_tmp = sub( 20480, add( lsf_tmp[M - 1], ftmp_fx ) ); /*QX2.56 */ + C[i] = L_mult0( S_tmp, S_tmp ); /*QX6.5536 */ } - S_tmp = sub(lsf_tmp[0],ftmp_fx); /*QX2.56 */ - C[i] = L_mac0(C[i],S_tmp,S_tmp); /*QX6.5536 */ - FOR ( j=0; jlspCNG_fx[i],lsp_est[i])); /*Q15 */ + S_tmp = abs_s( sub( hDtxEnc->lspCNG_fx[i], lsp_est[i] ) ); /*Q15 */ #ifdef BASOP_NOGLOB - Dlsp = add_o(Dlsp,S_tmp, &Overflow); /*Q15 */ -#else /* BASOP_NOGLOB */ - Dlsp = add(Dlsp,S_tmp); /*Q15 */ + Dlsp = add_o( Dlsp, S_tmp, &Overflow ); /*Q15 */ +#else /* BASOP_NOGLOB */ + Dlsp = add( Dlsp, S_tmp ); /*Q15 */ #endif - IF ( GT_16(S_tmp,S_max)) + IF( GT_16( S_tmp, S_max ) ) { S_max = S_tmp; /*Q15 */ } } - exp = norm_l(hTdCngEnc->lp_ener_fx); - fra = Log2_norm_lc(L_shl(hTdCngEnc->lp_ener_fx,exp)); - exp = sub(sub(30,exp),6); - L_tmp = L_Comp(exp,fra); - S_tmp = round_fx(L_shl(L_tmp,8)); /*Q8 */ - Denr = abs_s(sub(S_tmp,enr_est_log)); /*Q8 */ + exp = norm_l( hTdCngEnc->lp_ener_fx ); + fra = Log2_norm_lc( L_shl( hTdCngEnc->lp_ener_fx, exp ) ); + exp = sub( sub( 30, exp ), 6 ); + L_tmp = L_Comp( exp, fra ); + S_tmp = round_fx( L_shl( L_tmp, 8 ) ); /*Q8 */ + Denr = abs_s( sub( S_tmp, enr_est_log ) ); /*Q8 */ /* make decision if DTX hangover can be terminated */ hVAD->hangover_terminate_flag = 0; move16(); /*Q0 */ - test();test();test();test();test();test();test();test();test();test();test(); - IF ( ( LT_16(Dlsp,13107)&<_16(Denr,359)&<_16(S_max,3277) - && LT_16(Dlsp_n2e,13107) && LT_16(Denr_n2e,308) && st_fx->Opt_SC_VBR == 1 ) || - ( LT_16(Dlsp,13107) && LT_16(Denr,205) && LT_16(S_max,3277) - && LT_16(Dlsp_n2e,13107) && LT_16(Denr_n2e,205) && st_fx->Opt_SC_VBR == 0 ) ) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( LT_16( Dlsp, 13107 ) && LT_16( Denr, 359 ) && LT_16( S_max, 3277 ) && LT_16( Dlsp_n2e, 13107 ) && LT_16( Denr_n2e, 308 ) && st_fx->Opt_SC_VBR == 1 ) || + ( LT_16( Dlsp, 13107 ) && LT_16( Denr, 205 ) && LT_16( S_max, 3277 ) && LT_16( Dlsp_n2e, 13107 ) && LT_16( Denr_n2e, 205 ) && st_fx->Opt_SC_VBR == 0 ) ) { hVAD->hangover_terminate_flag = 1; @@ -996,8 +1018,8 @@ void dtx_hangover_control_fx( void td_cng_enc_init_fx( TD_CNG_ENC_HANDLE hTdCngEnc, /* i/o: DTX/TD CNG data handle */ - const Word16 Opt_DTX_ON, /* i : flag indicating DTX operation */ - const Word16 max_bwidth /* i : maximum encoded bandwidth */ + const Word16 Opt_DTX_ON, /* i : flag indicating DTX operation */ + const Word16 max_bwidth /* i : maximum encoded bandwidth */ ) { @@ -1010,29 +1032,34 @@ void td_cng_enc_init_fx( hTdCngEnc->lp_sp_enr_fx = 0; hTdCngEnc->last_allow_cn_step = 0; - move16();move32();move16();move16();move32();move16();move16(); + move16(); + move32(); + move16(); + move16(); + move32(); + move16(); + move16(); - IF (Opt_DTX_ON) + IF( Opt_DTX_ON ) { hTdCngEnc->cng_hist_ptr = -1; move16(); - set16_fx(hTdCngEnc->cng_lsp_hist_fx, 0, DTX_HIST_SIZE * M); - set16_fx(hTdCngEnc->cng_ener_hist_fx, 0, DTX_HIST_SIZE); + set16_fx( hTdCngEnc->cng_lsp_hist_fx, 0, DTX_HIST_SIZE * M ); + set16_fx( hTdCngEnc->cng_ener_hist_fx, 0, DTX_HIST_SIZE ); hTdCngEnc->ho_hist_ptr = -1; move16(); - hTdCngEnc->ho_sid_bw = L_deposit_l(0); - set16_fx(hTdCngEnc->ho_lsp_hist_fx, 0, HO_HIST_SIZE * M); - set32_fx(hTdCngEnc->ho_ener_hist_fx, 0, HO_HIST_SIZE); - set32_fx(hTdCngEnc->ho_env_hist_fx, 0, HO_HIST_SIZE * NUM_ENV_CNG); + hTdCngEnc->ho_sid_bw = L_deposit_l( 0 ); + set16_fx( hTdCngEnc->ho_lsp_hist_fx, 0, HO_HIST_SIZE * M ); + set32_fx( hTdCngEnc->ho_ener_hist_fx, 0, HO_HIST_SIZE ); + set32_fx( hTdCngEnc->ho_env_hist_fx, 0, HO_HIST_SIZE * NUM_ENV_CNG ); hTdCngEnc->ho_hist_size = 0; move16(); hTdCngEnc->act_cnt = 0; move16(); - } - set16_fx(hTdCngEnc->ho_16k_lsp, 0, HO_HIST_SIZE); + set16_fx( hTdCngEnc->ho_16k_lsp, 0, HO_HIST_SIZE ); hTdCngEnc->act_cnt2 = 0; hTdCngEnc->num_ho = 0; move16(); @@ -1040,9 +1067,9 @@ void td_cng_enc_init_fx( hTdCngEnc->ho_circ_ptr = -1; move16(); - set16_fx(hTdCngEnc->ho_lsp_circ_fx, 0, HO_HIST_SIZE * M); - set32_fx(hTdCngEnc->ho_ener_circ_fx, 0, HO_HIST_SIZE); - set32_fx(hTdCngEnc->ho_env_circ_fx, 0, HO_HIST_SIZE * NUM_ENV_CNG); + set16_fx( hTdCngEnc->ho_lsp_circ_fx, 0, HO_HIST_SIZE * M ); + set32_fx( hTdCngEnc->ho_ener_circ_fx, 0, HO_HIST_SIZE ); + set32_fx( hTdCngEnc->ho_env_circ_fx, 0, HO_HIST_SIZE * NUM_ENV_CNG ); hTdCngEnc->ho_circ_size = 0; hTdCngEnc->burst_ho_cnt = 0; move16(); @@ -1052,31 +1079,31 @@ void td_cng_enc_init_fx( hTdCngEnc->CNG_att_fx = 0; hTdCngEnc->last_idx_ener_fx = 0; #endif - + hTdCngEnc->cng_buf_cnt = 0; - set32_fx(hTdCngEnc->lp_env_fx, 0, 20); - set32_fx(hTdCngEnc->cng_res_env_fx, 0, 20 * 8); - set16_fx(hTdCngEnc->exc_mem_fx, 0, 24); - set16_fx(hTdCngEnc->exc_mem1_fx, 0, 30); - set16_fx(hTdCngEnc->exc_mem2_fx, 0, 30); - set32_fx(hTdCngEnc->old_env_fx, 0, NUM_ENV_CNG); + set32_fx( hTdCngEnc->lp_env_fx, 0, 20 ); + set32_fx( hTdCngEnc->cng_res_env_fx, 0, 20 * 8 ); + set16_fx( hTdCngEnc->exc_mem_fx, 0, 24 ); + set16_fx( hTdCngEnc->exc_mem1_fx, 0, 30 ); + set16_fx( hTdCngEnc->exc_mem2_fx, 0, 30 ); + set32_fx( hTdCngEnc->old_env_fx, 0, NUM_ENV_CNG ); /* SWB CNG/DTX */ hTdCngEnc->last_wb_cng_ener_fx = -1541; - move16(); /* Q8 */ + move16(); /* Q8 */ hTdCngEnc->last_shb_cng_ener_fx = -1541; - move16(); /* Q8 */ + move16(); /* Q8 */ hTdCngEnc->mov_wb_cng_ener_fx = -1541; - move16(); /* Q8 */ + move16(); /* Q8 */ hTdCngEnc->mov_shb_cng_ener_fx = -1541; - move16(); /* Q8 */ + move16(); /* Q8 */ hTdCngEnc->shb_cng_ini_cnt = 1; move16(); hTdCngEnc->shb_NO_DATA_cnt = 0; move16(); - hTdCngEnc->last_SID_bwidth = s_min(max_bwidth, SWB); + hTdCngEnc->last_SID_bwidth = s_min( max_bwidth, SWB ); hTdCngEnc->last_vad = 0; move16(); @@ -1090,7 +1117,7 @@ void td_cng_enc_init_fx( *-------------------------------------------------------------------*/ void dtx_enc_init_fx( - Encoder_State* st, /* i : Encoder state handle */ + Encoder_State *st, /* i : Encoder state handle */ const Word16 var_SID_rate_flag, /* i : flag for variable SID update rate */ const Word16 interval_SID /* i : interval for SID update */ ) @@ -1098,34 +1125,52 @@ void dtx_enc_init_fx( DTX_ENC_HANDLE hDtxEnc; hDtxEnc = st->hDtxEnc; - hDtxEnc->first_CNG = 0; move16(); - hDtxEnc->cnt_SID = 0; move16(); - hDtxEnc->max_SID = 2; move16(); - hDtxEnc->CNG_mode = -1; move16(); - Copy(st->lsp_old1_fx, hDtxEnc->lspCNG_fx, M); - hDtxEnc->VarDTX_cnt_voiced = 0; move16(); - hDtxEnc->VarDTX_cnt_noise = 0; move16(); - hDtxEnc->lt_ener_voiced_fx = 0; move16(); - hDtxEnc->lt_ener_noise_fx = 0; move16(); - hDtxEnc->frame_ener_fx = 0; move16(); - hDtxEnc->lt_ener_last_SID_fx = 0; move16(); - hDtxEnc->last_CNG_L_frame = L_FRAME; move16(); - hDtxEnc->var_SID_rate_flag = var_SID_rate_flag; move16(); - hDtxEnc->last_active_brate = ACELP_7k20; move16(); - hDtxEnc->cng_cnt = 0; move16(); - - IF (hDtxEnc->var_SID_rate_flag) + hDtxEnc->first_CNG = 0; + move16(); + hDtxEnc->cnt_SID = 0; + move16(); + hDtxEnc->max_SID = 2; + move16(); + hDtxEnc->CNG_mode = -1; + move16(); + Copy( st->lsp_old1_fx, hDtxEnc->lspCNG_fx, M ); + hDtxEnc->VarDTX_cnt_voiced = 0; + move16(); + hDtxEnc->VarDTX_cnt_noise = 0; + move16(); + hDtxEnc->lt_ener_voiced_fx = 0; + move16(); + hDtxEnc->lt_ener_noise_fx = 0; + move16(); + hDtxEnc->frame_ener_fx = 0; + move16(); + hDtxEnc->lt_ener_last_SID_fx = 0; + move16(); + hDtxEnc->last_CNG_L_frame = L_FRAME; + move16(); + hDtxEnc->var_SID_rate_flag = var_SID_rate_flag; + move16(); + hDtxEnc->last_active_brate = ACELP_7k20; + move16(); + hDtxEnc->cng_cnt = 0; + move16(); + + IF( hDtxEnc->var_SID_rate_flag ) { - hDtxEnc->interval_SID = 12; move16(); move16(); + hDtxEnc->interval_SID = 12; + move16(); + move16(); hDtxEnc->cng_hist_size = DTX_HIST_SIZE; } ELSE { - hDtxEnc->interval_SID = interval_SID; move16(); - if (GE_16(hDtxEnc->interval_SID, DTX_HIST_SIZE)) + hDtxEnc->interval_SID = interval_SID; + move16(); + if ( GE_16( hDtxEnc->interval_SID, DTX_HIST_SIZE ) ) { - hDtxEnc->cng_hist_size = hDtxEnc->interval_SID; move16(); + hDtxEnc->cng_hist_size = hDtxEnc->interval_SID; + move16(); } } return; -} \ No newline at end of file +} diff --git a/lib_enc/enc_acelp_fx.c b/lib_enc/enc_acelp_fx.c index f00ef8255..b8aacc998 100644 --- a/lib_enc/enc_acelp_fx.c +++ b/lib_enc/enc_acelp_fx.c @@ -12,34 +12,28 @@ #include "rom_com_fx.h" #include "rom_com.h" #include "rom_enc.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ -#define _2_ 0x4000 /*Q12*/ -#define _1_ 0x2000 /*Q12*/ +#define _2_ 0x4000 /*Q12*/ +#define _1_ 0x2000 /*Q12*/ #define _1_Q9 0x200 -static void E_ACELP_codearithp_fx(const Word16 v[], UWord32 *n, UWord32 *ps, Word16 *p); +static void E_ACELP_codearithp_fx( const Word16 v[], UWord32 *n, UWord32 *ps, Word16 *p ); -void E_ACELP_h_vec_corr1(Word16 h[], Word16 vec[], UWord8 track, - Word16 sign[], Word16 (*rrixix)[16], - Word16 cor[], Word16 dn2_pos[], - Word16 nb_pulse); +void E_ACELP_h_vec_corr1( Word16 h[], Word16 vec[], UWord8 track, Word16 sign[], Word16 ( *rrixix )[16], Word16 cor[], Word16 dn2_pos[], Word16 nb_pulse ); -void E_ACELP_h_vec_corr2(Word16 h[], Word16 vec[], UWord8 track, - Word16 sign[], Word16 (*rrixix)[16], - Word16 cor[]); +void E_ACELP_h_vec_corr2( Word16 h[], Word16 vec[], UWord8 track, Word16 sign[], Word16 ( *rrixix )[16], Word16 cor[] ); -Word16 E_ACELP_xy1_corr(Word16 xn[], Word16 y1[], ACELP_CbkCorr *g_corr, Word16 norm_flag, Word16 L_subfr, Word16 exp_xn); +Word16 E_ACELP_xy1_corr( Word16 xn[], Word16 y1[], ACELP_CbkCorr *g_corr, Word16 norm_flag, Word16 L_subfr, Word16 exp_xn ); -void E_ACELP_codebook_target_update(Word16 *x, Word16 *x2, Word16 *y, - Word16 gain, Word16 L_subfr); +void E_ACELP_codebook_target_update( Word16 *x, Word16 *x2, Word16 *y, Word16 gain, Word16 L_subfr ); -void E_ACELP_vec_neg(Word16 h[], Word16 h_inv[], Word16 L_subfr); +void E_ACELP_vec_neg( Word16 h[], Word16 h_inv[], Word16 L_subfr ); -void E_ACELP_corrmatrix(Word16 h[], Word16 sign[], Word16 vec[], Word16 rrixix[4][16], Word16 rrixiy[4][256]); +void E_ACELP_corrmatrix( Word16 h[], Word16 sign[], Word16 vec[], Word16 rrixix[4][16], Word16 rrixiy[4][256] ); /* * E_ACELP_h_vec_corrx @@ -58,10 +52,7 @@ void E_ACELP_corrmatrix(Word16 h[], Word16 sign[], Word16 vec[], Word16 rrixix[4 * Returns: * void */ -void E_ACELP_h_vec_corr1(Word16 h[], Word16 vec[], UWord8 track, - Word16 sign[], Word16 (*rrixix)[16], - Word16 cor[], Word16 dn2_pos[], - Word16 nb_pulse) +void E_ACELP_h_vec_corr1( Word16 h[], Word16 vec[], UWord8 track, Word16 sign[], Word16 ( *rrixix )[16], Word16 cor[], Word16 dn2_pos[], Word16 nb_pulse ) { Word16 i, j; Word16 dn, corr; @@ -72,47 +63,47 @@ void E_ACELP_h_vec_corr1(Word16 h[], Word16 vec[], UWord8 track, Flag Overflow = 0; #endif - dn2 = &dn2_pos[shl(track,3)]; + dn2 = &dn2_pos[shl( track, 3 )]; p0 = rrixix[track]; - FOR (i = 0; i < nb_pulse; i++) + FOR( i = 0; i < nb_pulse; i++ ) { dn = dn2[i]; move16(); - L_sum = L_deposit_l(0); + L_sum = L_deposit_l( 0 ); p1 = h; p2 = &vec[dn]; - FOR(j = dn; j < L_SUBFR - 1; j++) + FOR( j = dn; j < L_SUBFR - 1; j++ ) { #ifdef BASOP_NOGLOB - L_sum = L_mac_o(L_sum, *p1++, *p2++, &Overflow); + L_sum = L_mac_o( L_sum, *p1++, *p2++, &Overflow ); #else - L_sum = L_mac(L_sum, *p1++, *p2++); + L_sum = L_mac( L_sum, *p1++, *p2++ ); #endif } #ifdef BASOP_NOGLOB - corr = mac_ro(L_sum, *p1++, *p2++, &Overflow); /*Q9*/ -#else /* BASOP_NOGLOB */ - corr = mac_r(L_sum, *p1++, *p2++); /*Q9*/ -#endif /* BASOP_NOGLOB */ + corr = mac_ro( L_sum, *p1++, *p2++, &Overflow ); /*Q9*/ +#else /* BASOP_NOGLOB */ + corr = mac_r( L_sum, *p1++, *p2++ ); /*Q9*/ +#endif /* BASOP_NOGLOB */ /*cor[dn >> 2] = sign[dn] * s + p0[dn >> 2];*/ - j = shr(dn,2); - if(sign[dn] > 0) + j = shr( dn, 2 ); + if ( sign[dn] > 0 ) { #ifdef BASOP_NOGLOB - corr = add_o(p0[j], corr, &Overflow); + corr = add_o( p0[j], corr, &Overflow ); #else - corr = add(p0[j], corr); + corr = add( p0[j], corr ); #endif } - if(sign[dn] < 0) + if ( sign[dn] < 0 ) { #ifdef BASOP_NOGLOB - corr = sub_o(p0[j], corr, &Overflow); -#else /* BASOP_NOGLOB */ - corr = sub(p0[j], corr); + corr = sub_o( p0[j], corr, &Overflow ); +#else /* BASOP_NOGLOB */ + corr = sub( p0[j], corr ); #endif /* BASOP_NOGLOB */ } @@ -122,9 +113,7 @@ void E_ACELP_h_vec_corr1(Word16 h[], Word16 vec[], UWord8 track, return; } -void E_ACELP_h_vec_corr2(Word16 h[], Word16 vec[], UWord8 track, - Word16 sign[], Word16 (*rrixix)[16], - Word16 cor[]) +void E_ACELP_h_vec_corr2( Word16 h[], Word16 vec[], UWord8 track, Word16 sign[], Word16 ( *rrixix )[16], Word16 cor[] ) { Word16 i, j, pos, corr; Word16 *p0, *p1, *p2; @@ -137,47 +126,47 @@ void E_ACELP_h_vec_corr2(Word16 h[], Word16 vec[], UWord8 track, pos = track; move16(); - FOR (i = 0; i < 16; i++) + FOR( i = 0; i < 16; i++ ) { - L_sum = L_deposit_l(0); + L_sum = L_deposit_l( 0 ); p1 = h; p2 = &vec[pos]; - FOR(j = pos; j < L_SUBFR - 1; j++) + FOR( j = pos; j < L_SUBFR - 1; j++ ) { #ifdef BASOP_NOGLOB - L_sum = L_mac_o(L_sum, *p1++, *p2++, &Overflow); + L_sum = L_mac_o( L_sum, *p1++, *p2++, &Overflow ); #else - L_sum = L_mac(L_sum, *p1++, *p2++); + L_sum = L_mac( L_sum, *p1++, *p2++ ); #endif } #ifdef BASOP_NOGLOB - corr = mac_ro(L_sum, *p1++, *p2++, &Overflow); /*Q9*/ -#else /* BASOP_NOGLOB */ - corr = mac_r(L_sum, *p1++, *p2++); /*Q9*/ -#endif /* BASOP_NOGLOB */ + corr = mac_ro( L_sum, *p1++, *p2++, &Overflow ); /*Q9*/ +#else /* BASOP_NOGLOB */ + corr = mac_r( L_sum, *p1++, *p2++ ); /*Q9*/ +#endif /* BASOP_NOGLOB */ /*cor[i] = s * sign[track] + p0[i];*/ - if(sign[pos] > 0) + if ( sign[pos] > 0 ) { #ifdef BASOP_NOGLOB - corr = add_o(*p0++, corr, &Overflow); + corr = add_o( *p0++, corr, &Overflow ); #else - corr = add(*p0++, corr); + corr = add( *p0++, corr ); #endif } - if(sign[pos] < 0) + if ( sign[pos] < 0 ) { #ifdef BASOP_NOGLOB - corr = sub_o(*p0++, corr, &Overflow); + corr = sub_o( *p0++, corr, &Overflow ); #else - corr = sub(*p0++, corr); + corr = sub( *p0++, corr ); #endif } cor[i] = corr; move16(); - pos = add(pos,4); + pos = add( pos, 4 ); } return; } @@ -206,11 +195,7 @@ void E_ACELP_h_vec_corr2(Word16 h[], Word16 vec[], UWord8 track, * Returns: * void */ -static void E_ACELP_2pulse_search(Word16 nb_pos_ix, UWord8 track_x, - UWord8 track_y, Word16 *ps, Word16 *alp, - Word16 *ix, Word16 *iy, Word16 dn[], - Word16 *dn2, Word16 cor_x[], - Word16 cor_y[], Word16 (*rrixiy)[256]) +static void E_ACELP_2pulse_search( Word16 nb_pos_ix, UWord8 track_x, UWord8 track_y, Word16 *ps, Word16 *alp, Word16 *ix, Word16 *iy, Word16 dn[], Word16 *dn2, Word16 cor_x[], Word16 cor_y[], Word16 ( *rrixiy )[256] ) { Word16 x, x2, y, i, *pos_x; Word16 ps0, ps1, alp2_16, ps2, sq; @@ -226,11 +211,11 @@ static void E_ACELP_2pulse_search(Word16 nb_pos_ix, UWord8 track_x, /* eight dn2 max positions per track */ /*pos_x = &dn2[track_x << 3]; SHIFT(1); PTR_INIT(1);*/ - pos_x = &dn2[shl(track_x, 3)]; + pos_x = &dn2[shl( track_x, 3 )]; move16(); /* save these to limit memory searches */ - alp0 = L_deposit_h(*alp); + alp0 = L_deposit_h( *alp ); ps0 = *ps; move16(); @@ -238,11 +223,11 @@ static void E_ACELP_2pulse_search(Word16 nb_pos_ix, UWord8 track_x, move16(); sqk[0] = -1; move16(); - x2 = shr(pos_x[0], 2); + x2 = shr( pos_x[0], 2 ); #ifdef BASOP_NOGLOB - if (mac_ro(L_mac_o(L_mac_o(alp0, cor_x[x2], _1_, &Overflow), cor_y[0], _1_, &Overflow), rrixiy[track_x][shl(x2,4)], _1_, &Overflow) < 0) -#else /* BASOP_NOGLOB */ - if (mac_r(L_mac(L_mac(alp0, cor_x[x2], _1_), cor_y[0], _1_), rrixiy[track_x][shl(x2,4)], _1_) < 0) + if ( mac_ro( L_mac_o( L_mac_o( alp0, cor_x[x2], _1_, &Overflow ), cor_y[0], _1_, &Overflow ), rrixiy[track_x][shl( x2, 4 )], _1_, &Overflow ) < 0 ) +#else /* BASOP_NOGLOB */ + if ( mac_r( L_mac( L_mac( alp0, cor_x[x2], _1_ ), cor_y[0], _1_ ), rrixiy[track_x][shl( x2, 4 )], _1_ ) < 0 ) #endif /* BASOP_NOGLOB */ { sqk[0] = 1; @@ -250,74 +235,74 @@ static void E_ACELP_2pulse_search(Word16 nb_pos_ix, UWord8 track_x, } ik = 0; move16(); - xy_save = L_mac0(L_deposit_l(track_y), track_x, L_SUBFR); + xy_save = L_mac0( L_deposit_l( track_y ), track_x, L_SUBFR ); /* loop track 1 */ - FOR (i = 0; i < nb_pos_ix; i++) + FOR( i = 0; i < nb_pos_ix; i++ ) { x = pos_x[i]; move16(); - x2 = shr(x, 2); + x2 = shr( x, 2 ); /* dn[x] has only nb_pos_ix positions saved */ /*ps1 = ps0 + dn[x];*/ - ps1 = add(ps0, dn[x]); + ps1 = add( ps0, dn[x] ); /*alp1 = alp0 + cor_x[x2];*/ #ifdef BASOP_NOGLOB - alp1 = L_mac_o(alp0, cor_x[x2], _1_, &Overflow); /*Q22*/ -#else /* BASOP_NOGLOB */ - alp1 = L_mac(alp0, cor_x[x2], _1_); /*Q22*/ -#endif /* BASOP_NOGLOB */ + alp1 = L_mac_o( alp0, cor_x[x2], _1_, &Overflow ); /*Q22*/ +#else /* BASOP_NOGLOB */ + alp1 = L_mac( alp0, cor_x[x2], _1_ ); /*Q22*/ +#endif /* BASOP_NOGLOB */ p1 = cor_y; - p2 = &rrixiy[track_x][shl(x2,4)]; + p2 = &rrixiy[track_x][shl( x2, 4 )]; - FOR (y = track_y; y < L_SUBFR; y += 4) + FOR( y = track_y; y < L_SUBFR; y += 4 ) { /*ps2 = ps1 + dn[y];*/ - ps2 = add(ps1, dn[y]); + ps2 = add( ps1, dn[y] ); /*alp2 = alp1 + (*p1++) + (*p2++);*/ #ifdef BASOP_NOGLOB - alp2 = L_mac_o(alp1, *p1++, _1_, &Overflow); - alp2_16 = mac_ro(alp2, *p2++, _1_, &Overflow); /*Q6*/ -#else /* BASOP_NOGLOB */ - alp2 = L_mac(alp1, *p1++, _1_); - alp2_16 = mac_r(alp2, *p2++, _1_); /*Q6*/ -#endif /* BASOP_NOGLOB */ - alpk[1-ik] = alp2_16; + alp2 = L_mac_o( alp1, *p1++, _1_, &Overflow ); + alp2_16 = mac_ro( alp2, *p2++, _1_, &Overflow ); /*Q6*/ +#else /* BASOP_NOGLOB */ + alp2 = L_mac( alp1, *p1++, _1_ ); + alp2_16 = mac_r( alp2, *p2++, _1_ ); /*Q6*/ +#endif /* BASOP_NOGLOB */ + alpk[1 - ik] = alp2_16; move16(); /*sq = ps2 * ps2;*/ - sq = mult(ps2, ps2); - sqk[1-ik] = sq; + sq = mult( ps2, ps2 ); + sqk[1 - ik] = sq; move16(); /*s = (alpk[ik] * sq) - (sqk[0] * alp2);*/ - s = L_msu(L_mult(alpk[ik], sq), sqk[ik], alp2_16); /*Q16*/ + s = L_msu( L_mult( alpk[ik], sq ), sqk[ik], alp2_16 ); /*Q16*/ - if (s > 0) + if ( s > 0 ) { - ik = sub(1, ik); + ik = sub( 1, ik ); check = 1; /* debug code not instrumented */ } - if (s > 0) + if ( s > 0 ) { - xy_save = L_mac0(y, x, L_SUBFR); + xy_save = L_mac0( y, x, L_SUBFR ); } } } - assert(check); /* debug code not instrumented */ + assert( check ); /* debug code not instrumented */ - ps2 = extract_l(xy_save); - *iy = s_and(ps2, L_SUBFR-1); + ps2 = extract_l( xy_save ); + *iy = s_and( ps2, L_SUBFR - 1 ); move16(); - *ix = lshr(ps2, 6); + *ix = lshr( ps2, 6 ); move16(); /**ps = ps0 + dn[*ix] + dn[*iy];*/ - *ps = add(ps0, add(dn[*ix], dn[*iy])); + *ps = add( ps0, add( dn[*ix], dn[*iy] ) ); move16(); *alp = alpk[ik]; @@ -326,7 +311,6 @@ static void E_ACELP_2pulse_search(Word16 nb_pos_ix, UWord8 track_x, } - /* * E_ACELP_1pulse_search * @@ -346,13 +330,13 @@ static void E_ACELP_2pulse_search(Word16 nb_pos_ix, UWord8 track_x, * Returns: * void */ -static void E_ACELP_1pulse_search(UWord8 tracks[2], - Word16 *ps, - Word16 *alp, - Word16 *ix, - Word16 dn[], - Word16 cor_x[], - Word16 cor_y[]) +static void E_ACELP_1pulse_search( UWord8 tracks[2], + Word16 *ps, + Word16 *alp, + Word16 *ix, + Word16 dn[], + Word16 cor_x[], + Word16 cor_y[] ) { Word16 x, x_save = 0; Word16 ps0; @@ -364,7 +348,7 @@ static void E_ACELP_1pulse_search(UWord8 tracks[2], Word16 check = 0; /* debug code not instrumented */ /* save these to limit memory searches */ - alp0 = L_deposit_h(*alp); + alp0 = L_deposit_h( *alp ); ps0 = *ps; move16(); @@ -372,7 +356,7 @@ static void E_ACELP_1pulse_search(UWord8 tracks[2], move16(); sqk[0] = -1; move16(); - if (mac_r(alp0, cor_x[shr(tracks[0],2)], _1_) < 0) + if ( mac_r( alp0, cor_x[shr( tracks[0], 2 )], _1_ ) < 0 ) { sqk[0] = 1; move16(); @@ -381,42 +365,42 @@ static void E_ACELP_1pulse_search(UWord8 tracks[2], move16(); ntracks = 1; - if (NE_16(tracks[1], tracks[0])) + if ( NE_16( tracks[1], tracks[0] ) ) { ntracks = 2; move16(); } - FOR (t=0; t>2]; SHIFT(1);ADD(1);*/ - alp1 = mac_r(alp0, cor_x[shr(x,2)], _1_); /*Q6*/ - alpk[1-ik] = alp1; + alp1 = mac_r( alp0, cor_x[shr( x, 2 )], _1_ ); /*Q6*/ + alpk[1 - ik] = alp1; move16(); /*sq = ps1 * ps1; MULT(1);*/ - sq = mult(ps1, ps1); - sqk[1-ik] = sq; + sq = mult( ps1, ps1 ); + sqk[1 - ik] = sq; move16(); /*s = (alpk * sq) - (sqk * alp1); MULT(1);MAC(1); */ - s = L_msu(L_mult(alpk[ik], sq), sqk[ik], alp1);/*Q16*/ + s = L_msu( L_mult( alpk[ik], sq ), sqk[ik], alp1 ); /*Q16*/ - if (s > 0) + if ( s > 0 ) { - ik = sub(1, ik); + ik = sub( 1, ik ); check = 1; /* debug code not instrumented */ } - if (s > 0) + if ( s > 0 ) { x_save = x; move16(); @@ -425,7 +409,7 @@ static void E_ACELP_1pulse_search(UWord8 tracks[2], assert( check ); /* debug code not instrumented */ } - *ps = add(ps0, dn[x_save]); + *ps = add( ps0, dn[x_save] ); move16(); *alp = alpk[ik]; move16(); @@ -454,42 +438,42 @@ static void E_ACELP_1pulse_search(UWord8 tracks[2], * Returns: * void */ -static void E_ACELP_xh_corr(Word16 *x, Word16 *y, Word16 *h, Word16 L_subfr) +static void E_ACELP_xh_corr( Word16 *x, Word16 *y, Word16 *h, Word16 L_subfr ) { - Word16 i, j,k; + Word16 i, j, k; Word32 L_tmp, y32[L_SUBFR16k], L_maxloc, L_tot; - assert(L_subfr <= L_SUBFR16k); + assert( L_subfr <= L_SUBFR16k ); /* first keep the result on 32 bits and find absolute maximum */ - L_tot = L_deposit_l(1); + L_tot = L_deposit_l( 1 ); - FOR (k = 0; k < 4; k++) + FOR( k = 0; k < 4; k++ ) { - L_maxloc = L_deposit_l(0); - FOR (i = k; i < L_subfr; i += 4) + L_maxloc = L_deposit_l( 0 ); + FOR( i = k; i < L_subfr; i += 4 ) { - L_tmp = L_mac0(1L, x[i], h[0]); /* 1 -> to avoid null dn[] */ - FOR (j = i; j < L_subfr-1; j++) + L_tmp = L_mac0( 1L, x[i], h[0] ); /* 1 -> to avoid null dn[] */ + FOR( j = i; j < L_subfr - 1; j++ ) { - L_tmp = L_mac0(L_tmp, x[j+1], h[j+1 - i]); + L_tmp = L_mac0( L_tmp, x[j + 1], h[j + 1 - i] ); } y32[i] = L_tmp; move32(); - L_tmp = L_abs(L_tmp); - L_maxloc = L_max(L_tmp, L_maxloc); + L_tmp = L_abs( L_tmp ); + L_maxloc = L_max( L_tmp, L_maxloc ); } /* tot += 3*max / 8 */ - L_maxloc = L_shr(L_maxloc, 2); + L_maxloc = L_shr( L_maxloc, 2 ); /* Do not warn saturation of L_tot, since its for headroom estimation. */ BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB L_tot = L_add_sat( L_tot, L_maxloc ); /* +max/4 */ - L_tot = L_add_sat(L_tot, L_shr(L_maxloc, 1)); /* +max/8 */ + L_tot = L_add_sat( L_tot, L_shr( L_maxloc, 1 ) ); /* +max/8 */ #else - L_tot = L_add(L_tot, L_maxloc); /* +max/4 */ - L_tot = L_add(L_tot, L_shr(L_maxloc, 1)); /* +max/8 */ + L_tot = L_add( L_tot, L_maxloc ); /* +max/4 */ + L_tot = L_add( L_tot, L_shr( L_maxloc, 1 ) ); /* +max/8 */ #endif BASOP_SATURATE_WARNING_ON_EVS } @@ -497,9 +481,9 @@ static void E_ACELP_xh_corr(Word16 *x, Word16 *y, Word16 *h, Word16 L_subfr) /* Find the number of right shifts to do on y32[] so that */ /* 6.0 x sumation of max of dn[] in each track not saturate. */ - j = sub(norm_l(L_tot), 4+16); /* 4 -> 16 x tot */ + j = sub( norm_l( L_tot ), 4 + 16 ); /* 4 -> 16 x tot */ - Copy_Scale_sig_32_16(y32, y, L_subfr, j); + Copy_Scale_sig_32_16( y32, y, L_subfr, j ); return; } @@ -511,39 +495,39 @@ static void E_ACELP_xh_corr(Word16 *x, Word16 *y, Word16 *h, Word16 L_subfr) * \param bits amount of target headroom bits for y * \return exponent of y */ -Word16 E_ACELP_hh_corr(Word16 *x, Word16 *y, Word16 L_subfr, Word16 bits) +Word16 E_ACELP_hh_corr( Word16 *x, Word16 *y, Word16 L_subfr, Word16 bits ) { Word16 i, j, k = 0; /* initialize just to avoid compiler warning */ Word32 L_tmp, L_sum; - FOR (i = 0; i < L_subfr-1; i++) + FOR( i = 0; i < L_subfr - 1; i++ ) { Word64 L_tmp_64; Word64 L_sum_64; L_tmp_64 = W_mult0_16_16( x[i], x[0] ); - FOR (j = i+2; j < L_subfr; j+=2) + FOR( j = i + 2; j < L_subfr; j += 2 ) { - L_tmp_64 = W_mac0_16_16( L_tmp_64, x[j], x[j-i] ); + L_tmp_64 = W_mac0_16_16( L_tmp_64, x[j], x[j - i] ); } L_sum_64 = L_tmp_64; move64(); - L_tmp_64 = W_mult0_16_16( x[i+1], x[1] ); - FOR (j = i+3; j < L_subfr; j+=2) + L_tmp_64 = W_mult0_16_16( x[i + 1], x[1] ); + FOR( j = i + 3; j < L_subfr; j += 2 ) { - L_tmp_64 = W_mac0_16_16( L_tmp_64, x[j], x[j-i] ); + L_tmp_64 = W_mac0_16_16( L_tmp_64, x[j], x[j - i] ); } - L_sum_64 = W_add_nosat( W_shr(L_sum_64,1), W_shr(L_tmp_64,1) ); - L_sum = W_sat_l( L_sum_64 ); + L_sum_64 = W_add_nosat( W_shr( L_sum_64, 1 ), W_shr( L_tmp_64, 1 ) ); + L_sum = W_sat_l( L_sum_64 ); /* L_sum = L_shr( L_sum, 1 ); */ - if (i == 0) + if ( i == 0 ) { - k = norm_l(L_sum); + k = norm_l( L_sum ); } - if (i == 0) + if ( i == 0 ) { - k = sub(k, bits); + k = sub( k, bits ); } y[i] = round_fx( L_shl( L_sum, k ) ); @@ -553,7 +537,7 @@ Word16 E_ACELP_hh_corr(Word16 *x, Word16 *y, Word16 L_subfr, Word16 bits) L_sum = L_shr( L_tmp, 1 ); y[i] = round_fx( L_shl( L_sum, k ) ); - k = add(1, k); + k = add( 1, k ); return k; } @@ -577,7 +561,7 @@ Word16 E_ACELP_hh_corr(Word16 *x, Word16 *y, Word16 L_subfr, Word16 bits) * Returns: * pitch gain (0 ... 1.2F) (Q14) */ -Word16 E_ACELP_xy1_corr(Word16 xn[], Word16 y1[], ACELP_CbkCorr *g_corr, Word16 norm_flag, Word16 L_subfr, Word16 exp_xn) +Word16 E_ACELP_xy1_corr( Word16 xn[], Word16 y1[], ACELP_CbkCorr *g_corr, Word16 norm_flag, Word16 L_subfr, Word16 exp_xn ) { Word16 i, Q_xn; Word16 xy, yy, exp_xy, exp_yy, gain; @@ -586,35 +570,35 @@ Word16 E_ACELP_xy1_corr(Word16 xn[], Word16 y1[], ACELP_CbkCorr *g_corr, Word16 Flag Overflow = 0; #endif - L_off = L_shr(10737418l/*0.01f/2.0f Q31*/, s_min(add(exp_xn,exp_xn), 31)); - L_off = L_max(1,L_off); /* ensure at least a '1' */ + L_off = L_shr( 10737418l /*0.01f/2.0f Q31*/, s_min( add( exp_xn, exp_xn ), 31 ) ); + L_off = L_max( 1, L_off ); /* ensure at least a '1' */ #ifdef BASOP_NOGLOB /* Compute scalar product t1: */ - yy = round_fx_o(Dot_product15_offs(y1, y1, L_subfr, &exp_yy, L_off), &Overflow); + yy = round_fx_o( Dot_product15_offs( y1, y1, L_subfr, &exp_yy, L_off ), &Overflow ); /* Compute scalar product t0: */ - xy = round_fx_o(Dot_product12_offs(xn, y1, L_subfr, &exp_xy, L_off), &Overflow); + xy = round_fx_o( Dot_product12_offs( xn, y1, L_subfr, &exp_xy, L_off ), &Overflow ); #else /* Compute scalar product t1: */ - yy = round_fx(Dot_product15_offs(y1, y1, L_subfr, &exp_yy, L_off)); + yy = round_fx( Dot_product15_offs( y1, y1, L_subfr, &exp_yy, L_off ) ); /* Compute scalar product t0: */ - xy = round_fx(Dot_product12_offs(xn, y1, L_subfr, &exp_xy, L_off)); + xy = round_fx( Dot_product12_offs( xn, y1, L_subfr, &exp_xy, L_off ) ); #endif /* Compute doubled format out of the exponent */ - Q_xn = shl(sub(15,exp_xn),1); - g_corr->y1y1 = yy; + Q_xn = shl( sub( 15, exp_xn ), 1 ); + g_corr->y1y1 = yy; move16(); - g_corr->y1y1_e = sub(exp_yy, Q_xn); + g_corr->y1y1_e = sub( exp_yy, Q_xn ); move16(); - g_corr->xy1 = xy; + g_corr->xy1 = xy; move16(); - g_corr->xy1_e = sub(exp_xy, Q_xn); + g_corr->xy1_e = sub( exp_xy, Q_xn ); move16(); /* If (xy < 0) gain = 0 */ - IF (xy < 0) + IF( xy < 0 ) { move16(); gain = 0; @@ -623,58 +607,58 @@ Word16 E_ACELP_xy1_corr(Word16 xn[], Word16 y1[], ACELP_CbkCorr *g_corr, Word16 /* compute gain = xy/yy */ - xy = mult_r(xy,0x4000); /* Be sure xy < yy */ - gain = div_s(xy, yy); + xy = mult_r( xy, 0x4000 ); /* Be sure xy < yy */ + gain = div_s( xy, yy ); - i = add(exp_xy, 1 - 1); /* -1 -> gain in Q14 */ - i = sub(i, exp_yy); + i = add( exp_xy, 1 - 1 ); /* -1 -> gain in Q14 */ + i = sub( i, exp_yy ); BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB - gain = shl_o(gain, i, &Overflow); /* saturation can occur here */ -#else /* BASOP_NOGLOB */ - gain = shl(gain, i); /* saturation can occur here */ -#endif /* BASOP_NOGLOB */ + gain = shl_o( gain, i, &Overflow ); /* saturation can occur here */ +#else /* BASOP_NOGLOB */ + gain = shl( gain, i ); /* saturation can occur here */ +#endif /* BASOP_NOGLOB */ BASOP_SATURATE_WARNING_ON_EVS /* gain = s_max(0, gain); */ /* see above xy < 0. */ /* if (gain > 1.2) gain = 1.2 in Q14 */ - gain = s_min(19661/*1.2f Q14*/ /* 19661 */, gain); + gain = s_min( 19661 /*1.2f Q14*/ /* 19661 */, gain ); /*Limit the energy of pitch contribution*/ - IF (norm_flag) + IF( norm_flag ) { Word16 tmp, exp_tmp, exp_div; /* Compute scalar product */ #ifdef BASOP_NOGLOB - tmp = round_fx_o(Dot_product12_offs(xn, xn, L_subfr, &exp_tmp, 1), &Overflow); + tmp = round_fx_o( Dot_product12_offs( xn, xn, L_subfr, &exp_tmp, 1 ), &Overflow ); #else - tmp = round_fx(Dot_product12_offs(xn, xn, L_subfr, &exp_tmp, 1)); + tmp = round_fx( Dot_product12_offs( xn, xn, L_subfr, &exp_tmp, 1 ) ); #endif /* gain_p_snr = sqrt(/) */ - tmp = BASOP_Util_Divide1616_Scale(tmp, yy, &exp_div); - exp_tmp = add(sub(exp_tmp, exp_yy), exp_div); + tmp = BASOP_Util_Divide1616_Scale( tmp, yy, &exp_div ); + exp_tmp = add( sub( exp_tmp, exp_yy ), exp_div ); - tmp = Sqrt16(tmp, &exp_tmp); + tmp = Sqrt16( tmp, &exp_tmp ); /* Note: shl works as shl or shr. */ - exp_tmp = sub(exp_tmp,1); + exp_tmp = sub( exp_tmp, 1 ); BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB - tmp = round_fx_o(L_shl_o(Mpy_32_16_1( 1717986944l/*ACELP_GAINS_CONST Q31*/, tmp), exp_tmp, &Overflow), &Overflow); -#else /* BASOP_NOGLOB */ - tmp = round_fx(L_shl(Mpy_32_16_1( 1717986944l/*ACELP_GAINS_CONST Q31*/, tmp), exp_tmp)); + tmp = round_fx_o( L_shl_o( Mpy_32_16_1( 1717986944l /*ACELP_GAINS_CONST Q31*/, tmp ), exp_tmp, &Overflow ), &Overflow ); +#else /* BASOP_NOGLOB */ + tmp = round_fx( L_shl( Mpy_32_16_1( 1717986944l /*ACELP_GAINS_CONST Q31*/, tmp ), exp_tmp ) ); #endif /* BASOP_NOGLOB */ BASOP_SATURATE_WARNING_ON_EVS - gain = s_min(gain, tmp); + gain = s_min( gain, tmp ); } bail: - return (gain); + return ( gain ); } /* @@ -696,8 +680,7 @@ bail: * Returns: * pitch gain (0 ... 1.2F) */ -void E_ACELP_xy2_corr(Word16 xn[], Word16 y1[], Word16 y2[], - ACELP_CbkCorr *g_corr, Word16 L_subfr, Word16 exp_xn) +void E_ACELP_xy2_corr( Word16 xn[], Word16 y1[], Word16 y2[], ACELP_CbkCorr *g_corr, Word16 L_subfr, Word16 exp_xn ) { Word16 xny2, y2y2, y1y2, xx, exp_xny2, exp_y2y2, exp_y1y2, exp_xx; Word32 L_off; @@ -705,37 +688,37 @@ void E_ACELP_xy2_corr(Word16 xn[], Word16 y1[], Word16 y2[], BASOP_SATURATE_ERROR_ON_EVS; /* Compute scalar product */ - y2y2 = extract_h(Dot_product15_offs(y2, y2, L_subfr, &exp_y2y2, 5243l/*0.01f Q19*/)); + y2y2 = extract_h( Dot_product15_offs( y2, y2, L_subfr, &exp_y2y2, 5243l /*0.01f Q19*/ ) ); /* L_off = 1L; */ - L_off = L_shr(10737418l/*0.01f/2.0f Q31*/, sub(30-9, exp_xn)); + L_off = L_shr( 10737418l /*0.01f/2.0f Q31*/, sub( 30 - 9, exp_xn ) ); /* Compute scalar product */ - xny2 = extract_h(Dot_product12_offs(xn, y2, L_subfr, &exp_xny2, L_off)); + xny2 = extract_h( Dot_product12_offs( xn, y2, L_subfr, &exp_xny2, L_off ) ); /* Compute scalar product */ - y1y2 = extract_h(Dot_product12_offs(y1, y2, L_subfr, &exp_y1y2, L_off)); + y1y2 = extract_h( Dot_product12_offs( y1, y2, L_subfr, &exp_y1y2, L_off ) ); /* Compute scalar product */ - L_off = L_shr(21474836l/*0.01f Q31*/, s_min(31, sub(30, shl(exp_xn, 1)))); - xx = extract_h(Dot_product12_offs(xn, xn, L_subfr, &exp_xx, L_off)); + L_off = L_shr( 21474836l /*0.01f Q31*/, s_min( 31, sub( 30, shl( exp_xn, 1 ) ) ) ); + xx = extract_h( Dot_product12_offs( xn, xn, L_subfr, &exp_xx, L_off ) ); - g_corr->y2y2 = y2y2; + g_corr->y2y2 = y2y2; move16(); g_corr->y2y2_e = exp_y2y2; move16(); - g_corr->xy2 = xny2; + g_corr->xy2 = xny2; move16(); - g_corr->xy2_e = exp_xny2; + g_corr->xy2_e = exp_xny2; move16(); - g_corr->y1y2 = y1y2; + g_corr->y1y2 = y1y2; move16(); - g_corr->y1y2_e = exp_y1y2; + g_corr->y1y2_e = exp_y1y2; move16(); - g_corr->xx = xx; + g_corr->xx = xx; move16(); - g_corr->xx_e = exp_xx; + g_corr->xx_e = exp_xx; move16(); @@ -744,7 +727,6 @@ void E_ACELP_xy2_corr(Word16 xn[], Word16 y1[], Word16 y2[], } - /* * E_ACELP_codebook_target_update * @@ -760,40 +742,39 @@ void E_ACELP_xy2_corr(Word16 xn[], Word16 y1[], Word16 y2[], * Returns: * void */ -void E_ACELP_codebook_target_update(Word16 *x, Word16 *x2, Word16 *y, - Word16 gain, Word16 L_subfr) +void E_ACELP_codebook_target_update( Word16 *x, Word16 *x2, Word16 *y, Word16 gain, Word16 L_subfr ) { Word16 i, Q15_flag; Word32 L_tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - assert(gain >= 0); + assert( gain >= 0 ); Q15_flag = 0; move16(); - if (LT_16(gain, 1<<14)) + if ( LT_16( gain, 1 << 14 ) ) { Q15_flag = 1; move16(); } - gain = shl(gain, Q15_flag); + gain = shl( gain, Q15_flag ); - FOR (i = 0; i < L_subfr; i++) + FOR( i = 0; i < L_subfr; i++ ) { - L_tmp = L_deposit_h(x[i]); - if (Q15_flag == 0) + L_tmp = L_deposit_h( x[i] ); + if ( Q15_flag == 0 ) { #ifdef BASOP_NOGLOB - L_tmp = L_msu_o(L_tmp, y[i], gain, &Overflow); + L_tmp = L_msu_o( L_tmp, y[i], gain, &Overflow ); #else - L_tmp = L_msu(L_tmp, y[i], gain); + L_tmp = L_msu( L_tmp, y[i], gain ); #endif } #ifdef BASOP_NOGLOB - x2[i] = msu_ro(L_tmp, y[i], gain, &Overflow); + x2[i] = msu_ro( L_tmp, y[i], gain, &Overflow ); #else - x2[i] = msu_r(L_tmp, y[i], gain); + x2[i] = msu_r( L_tmp, y[i], gain ); #endif move16(); } @@ -820,7 +801,7 @@ void E_ACELP_codebook_target_update(Word16 *x, Word16 *x2, Word16 *y, * Returns: * void */ -void E_ACELP_pulsesign(const Word16 cn[], Word16 dn[], Word16 dn2[], Word16 sign[], Word16 vec[], const Word16 alp, const Word16 sign_val, const Word16 L_subfr) +void E_ACELP_pulsesign( const Word16 cn[], Word16 dn[], Word16 dn2[], Word16 sign[], Word16 vec[], const Word16 alp, const Word16 sign_val, const Word16 L_subfr ) { Word16 i; Word32 Lval, Lcor; @@ -834,17 +815,17 @@ void E_ACELP_pulsesign(const Word16 cn[], Word16 dn[], Word16 dn2[], Word16 sign /* calculate energy for normalization of cn[] and dn[] */ - Lval = L_mac0(1, cn[0], cn[0]); - Lcor = L_mac0(1, dn[0], dn[0]); + Lval = L_mac0( 1, cn[0], cn[0] ); + Lcor = L_mac0( 1, dn[0], dn[0] ); - FOR (i = 1; i < L_subfr; i++) + FOR( i = 1; i < L_subfr; i++ ) { #ifdef BASOP_NOGLOB - Lval = L_mac0_o(Lval, cn[i], cn[i], &Overflow); -#else /* BASOP_NOGLOB */ - Lval = L_mac0(Lval, cn[i], cn[i]); + Lval = L_mac0_o( Lval, cn[i], cn[i], &Overflow ); +#else /* BASOP_NOGLOB */ + Lval = L_mac0( Lval, cn[i], cn[i] ); #endif /* BASOP_NOGLOB */ - Lcor = L_mac0(Lcor, dn[i], dn[i]); + Lcor = L_mac0( Lcor, dn[i], dn[i] ); } e_dn = 31; @@ -852,26 +833,26 @@ void E_ACELP_pulsesign(const Word16 cn[], Word16 dn[], Word16 dn2[], Word16 sign e_cn = 31; move16(); - Lval = Sqrt32(Lval, &e_dn); - Lcor = Sqrt32(Lcor, &e_cn); - i = sub(e_dn,e_cn); - if(i < 0) - Lval = L_shl(Lval, i); - if(i > 0) - Lcor = L_shr(Lcor, i); + Lval = Sqrt32( Lval, &e_dn ); + Lcor = Sqrt32( Lcor, &e_cn ); + i = sub( e_dn, e_cn ); + if ( i < 0 ) + Lval = L_shl( Lval, i ); + if ( i > 0 ) + Lcor = L_shr( Lcor, i ); #ifdef BASOP_NOGLOB - k_dn = round_fx_o(Lval, &Overflow); - k_cn = round_fx_o(Lcor, &Overflow); -#else /* BASOP_NOGLOB */ - k_dn = round_fx(Lval); - k_cn = round_fx(Lcor); + k_dn = round_fx_o( Lval, &Overflow ); + k_cn = round_fx_o( Lcor, &Overflow ); +#else /* BASOP_NOGLOB */ + k_dn = round_fx( Lval ); + k_cn = round_fx( Lcor ); #endif /* BASOP_NOGLOB */ - k_cn = mult_r(0x2000, k_cn); /* 1 in Q13 */ - k_dn = mult_r(alp, k_dn); /* alp in Q13 */ + k_cn = mult_r( 0x2000, k_cn ); /* 1 in Q13 */ + k_dn = mult_r( alp, k_dn ); /* alp in Q13 */ - sign_neg = negate(sign_val); + sign_neg = negate( sign_val ); signs[0] = sign_neg; move16(); @@ -881,57 +862,58 @@ void E_ACELP_pulsesign(const Word16 cn[], Word16 dn[], Word16 dn2[], Word16 sign move16(); ptr16 = &signs[1]; - FOR (i = 0; i < L_subfr; i++) + FOR( i = 0; i < L_subfr; i++ ) { /*cor = (s * cn[i]) + (alp * dn[i]); MULT(1);MAC(1);*/ - Lcor = L_mult(cn[i], k_cn); - Lcor = L_mac(Lcor, dn[i], k_dn); + Lcor = L_mult( cn[i], k_cn ); + Lcor = L_mac( Lcor, dn[i], k_dn ); #ifdef BASOP_NOGLOB - val = round_fx_o(L_shl_o(Lcor,4, &Overflow), &Overflow); /*shifting by 4 may overflow but improves accuracy*/ + val = round_fx_o( L_shl_o( Lcor, 4, &Overflow ), &Overflow ); /*shifting by 4 may overflow but improves accuracy*/ #else - val = round_fx(L_shl(Lcor,4)); /*shifting by 4 may overflow but improves accuracy*/ + val = round_fx( L_shl( Lcor, 4 ) ); /*shifting by 4 may overflow but improves accuracy*/ #endif - index = shr(val, 15); + index = shr( val, 15 ); sign[i] = ptr16[index]; - move16(); /* yields -1 (when ps < 0) or 0 (when ps >= 0) */ - vec[i] = ptr16[index+1]; + move16(); /* yields -1 (when ps < 0) or 0 (when ps >= 0) */ + vec[i] = ptr16[index + 1]; move16(); - if (val < 0) + if ( val < 0 ) { - dn[i] = negate(dn[i]); + dn[i] = negate( dn[i] ); move16(); } - dn2[i] = abs_s(val); - move16(); /* dn2[] = mix of dn[] and cn[] */ + dn2[i] = abs_s( val ); + move16(); /* dn2[] = mix of dn[] and cn[] */ } } -void E_ACELP_findcandidates(Word16 dn2[], Word16 dn2_pos[], Word16 pos_max[]) +void E_ACELP_findcandidates( Word16 dn2[], Word16 dn2_pos[], Word16 pos_max[] ) { Word16 i, k, j, i8; Word16 *ps_ptr; - FOR (i = 0; i < 4; i++) + FOR( i = 0; i < 4; i++ ) { - i8 = shl(i, 3); - FOR (k = i8; k < i8+8; k++) + i8 = shl( i, 3 ); + FOR( k = i8; k < i8 + 8; k++ ) { ps_ptr = &dn2[i]; - FOR (j = i+4; j < L_SUBFR; j += 4) + FOR( j = i + 4; j < L_SUBFR; j += 4 ) { - if (GT_16(dn2[j], *ps_ptr)) + if ( GT_16( dn2[j], *ps_ptr ) ) { ps_ptr = &dn2[j]; move16(); } } - *ps_ptr = -1; /* dn2 < 0 when position is selected */ move16(); - dn2_pos[k] = (Word16)(ps_ptr - dn2); + *ps_ptr = -1; /* dn2 < 0 when position is selected */ + move16(); + dn2_pos[k] = (Word16) ( ps_ptr - dn2 ); move16(); } pos_max[i] = dn2_pos[i8]; @@ -940,90 +922,90 @@ void E_ACELP_findcandidates(Word16 dn2[], Word16 dn2_pos[], Word16 pos_max[]) } -static void E_ACELP_apply_sign(Word16 *p0, Word16 *psign0) +static void E_ACELP_apply_sign( Word16 *p0, Word16 *psign0 ) { - p0[0] = mult_r( p0[0] , psign0[ 0]); + p0[0] = mult_r( p0[0], psign0[0] ); move16(); - p0[1] = mult_r( p0[1] , psign0[ 4]); + p0[1] = mult_r( p0[1], psign0[4] ); move16(); - p0[2] = mult_r( p0[2] , psign0[ 8]); + p0[2] = mult_r( p0[2], psign0[8] ); move16(); - p0[3] = mult_r( p0[3] , psign0[12]); + p0[3] = mult_r( p0[3], psign0[12] ); move16(); - p0[4] = mult_r( p0[4] , psign0[16]); + p0[4] = mult_r( p0[4], psign0[16] ); move16(); - p0[5] = mult_r( p0[5] , psign0[20]); + p0[5] = mult_r( p0[5], psign0[20] ); move16(); - p0[6] = mult_r( p0[6] , psign0[24]); + p0[6] = mult_r( p0[6], psign0[24] ); move16(); - p0[7] = mult_r( p0[7] , psign0[28]); + p0[7] = mult_r( p0[7], psign0[28] ); move16(); - p0[8] = mult_r( p0[8] , psign0[32]); + p0[8] = mult_r( p0[8], psign0[32] ); move16(); - p0[9] = mult_r( p0[9] , psign0[36]); + p0[9] = mult_r( p0[9], psign0[36] ); move16(); - p0[10] = mult_r( p0[10] , psign0[40]); + p0[10] = mult_r( p0[10], psign0[40] ); move16(); - p0[11] = mult_r( p0[11] , psign0[44]); + p0[11] = mult_r( p0[11], psign0[44] ); move16(); - p0[12] = mult_r( p0[12] , psign0[48]); + p0[12] = mult_r( p0[12], psign0[48] ); move16(); - p0[13] = mult_r( p0[13] , psign0[52]); + p0[13] = mult_r( p0[13], psign0[52] ); move16(); - p0[14] = mult_r( p0[14] , psign0[56]); + p0[14] = mult_r( p0[14], psign0[56] ); move16(); - p0[15] = mult_r( p0[15] , psign0[60]); + p0[15] = mult_r( p0[15], psign0[60] ); move16(); } -void E_ACELP_vec_neg(Word16 h[], Word16 h_inv[], Word16 L_subfr) +void E_ACELP_vec_neg( Word16 h[], Word16 h_inv[], Word16 L_subfr ) { Word16 i; - FOR(i = 0; i < L_subfr; i ++) + FOR( i = 0; i < L_subfr; i++ ) { - h_inv[i] = negate(h[i]); + h_inv[i] = negate( h[i] ); move16(); } } -void E_ACELP_corrmatrix(Word16 h[], Word16 sign[], Word16 vec[], Word16 rrixix[4][16], Word16 rrixiy[4][256]) +void E_ACELP_corrmatrix( Word16 h[], Word16 sign[], Word16 vec[], Word16 rrixix[4][16], Word16 rrixiy[4][256] ) { Word16 *p0, *p1, *p2, *p3, *psign0, *psign1, *psign2, *psign3; Word16 *ptr_h1, *ptr_h2, *ptr_hf; Word32 cor; - Word16 i, /* j, */ k,pos; + Word16 i, /* j, */ k, pos; /* - * Compute rrixix[][] needed for the codebook search. - */ + * Compute rrixix[][] needed for the codebook search. + */ /* storage order --> i3i3, i2i2, i1i1, i0i0 */ /* Init pointers to last position of rrixix[] */ - p0 = &rrixix[0][16 - 1]; /* Q9 */ + p0 = &rrixix[0][16 - 1]; /* Q9 */ p1 = &rrixix[1][16 - 1]; p2 = &rrixix[2][16 - 1]; p3 = &rrixix[3][16 - 1]; ptr_h1 = h; - cor = L_deposit_l(0); - FOR (i = 0; i < 16; i++) + cor = L_deposit_l( 0 ); + FOR( i = 0; i < 16; i++ ) { - cor = L_mac(cor, *ptr_h1, *ptr_h1); + cor = L_mac( cor, *ptr_h1, *ptr_h1 ); ptr_h1++; - *p3-- = round_fx(L_shr(cor, 1)); - cor = L_mac(cor, *ptr_h1, *ptr_h1); + *p3-- = round_fx( L_shr( cor, 1 ) ); + cor = L_mac( cor, *ptr_h1, *ptr_h1 ); ptr_h1++; - *p2-- = round_fx(L_shr(cor, 1)); - cor = L_mac(cor, *ptr_h1, *ptr_h1); + *p2-- = round_fx( L_shr( cor, 1 ) ); + cor = L_mac( cor, *ptr_h1, *ptr_h1 ); ptr_h1++; - *p1-- = round_fx(L_shr(cor, 1)); - cor = L_mac(cor, *ptr_h1, *ptr_h1); + *p1-- = round_fx( L_shr( cor, 1 ) ); + cor = L_mac( cor, *ptr_h1, *ptr_h1 ); ptr_h1++; - *p0-- = round_fx(L_shr(cor, 1)); /* Q9 */ + *p0-- = round_fx( L_shr( cor, 1 ) ); /* Q9 */ } @@ -1035,39 +1017,39 @@ void E_ACELP_corrmatrix(Word16 h[], Word16 sign[], Word16 vec[], Word16 rrixix[4 pos = 256 - 1; ptr_hf = h + 1; - FOR (k = 0; k < 16; k++) + FOR( k = 0; k < 16; k++ ) { p3 = &rrixiy[2][pos]; p2 = &rrixiy[1][pos]; p1 = &rrixiy[0][pos]; p0 = &rrixiy[3][pos - 16]; - cor = L_deposit_h(0); + cor = L_deposit_h( 0 ); ptr_h1 = h; ptr_h2 = ptr_hf; - FOR (i = k; i < 16-1; i++) + FOR( i = k; i < 16 - 1; i++ ) { - cor = L_mac(cor, *ptr_h1++, *ptr_h2++); - *p3 = round_fx(cor); - cor = L_mac(cor, *ptr_h1++, *ptr_h2++); - *p2 = round_fx(cor); - cor = L_mac(cor, *ptr_h1++, *ptr_h2++); - *p1 = round_fx(cor); - cor = L_mac(cor, *ptr_h1++, *ptr_h2++); - *p0 = round_fx(cor); - - p3 -= (16 + 1); - p2 -= (16 + 1); - p1 -= (16 + 1); - p0 -= (16 + 1); + cor = L_mac( cor, *ptr_h1++, *ptr_h2++ ); + *p3 = round_fx( cor ); + cor = L_mac( cor, *ptr_h1++, *ptr_h2++ ); + *p2 = round_fx( cor ); + cor = L_mac( cor, *ptr_h1++, *ptr_h2++ ); + *p1 = round_fx( cor ); + cor = L_mac( cor, *ptr_h1++, *ptr_h2++ ); + *p0 = round_fx( cor ); + + p3 -= ( 16 + 1 ); + p2 -= ( 16 + 1 ); + p1 -= ( 16 + 1 ); + p0 -= ( 16 + 1 ); } - cor = L_mac(cor, *ptr_h1++, *ptr_h2++); - *p3 = round_fx(cor); - cor = L_mac(cor, *ptr_h1++, *ptr_h2++); - *p2 = round_fx(cor); - cor = L_mac(cor, *ptr_h1++, *ptr_h2++); - *p1 = round_fx(cor); + cor = L_mac( cor, *ptr_h1++, *ptr_h2++ ); + *p3 = round_fx( cor ); + cor = L_mac( cor, *ptr_h1++, *ptr_h2++ ); + *p2 = round_fx( cor ); + cor = L_mac( cor, *ptr_h1++, *ptr_h2++ ); + *p1 = round_fx( cor ); pos -= 16; ptr_hf += 4; @@ -1077,34 +1059,34 @@ void E_ACELP_corrmatrix(Word16 h[], Word16 sign[], Word16 vec[], Word16 rrixix[4 pos = 256 - 1; ptr_hf = h + 3; - FOR (k = 0; k < 16; k++) + FOR( k = 0; k < 16; k++ ) { p3 = &rrixiy[3][pos]; p2 = &rrixiy[2][pos - 1]; p1 = &rrixiy[1][pos - 1]; p0 = &rrixiy[0][pos - 1]; - cor = L_deposit_h(0); + cor = L_deposit_h( 0 ); ptr_h1 = h; ptr_h2 = ptr_hf; - FOR (i = k; i < 16-1; i++) + FOR( i = k; i < 16 - 1; i++ ) { - cor = L_mac(cor, *ptr_h1++, *ptr_h2++); - *p3 = round_fx(cor); - cor = L_mac(cor, *ptr_h1++, *ptr_h2++); - *p2 = round_fx(cor); - cor = L_mac(cor, *ptr_h1++, *ptr_h2++); - *p1 = round_fx(cor); - cor = L_mac(cor, *ptr_h1++, *ptr_h2++); - *p0 = round_fx(cor); - - p3 -= (16 + 1); - p2 -= (16 + 1); - p1 -= (16 + 1); - p0 -= (16 + 1); + cor = L_mac( cor, *ptr_h1++, *ptr_h2++ ); + *p3 = round_fx( cor ); + cor = L_mac( cor, *ptr_h1++, *ptr_h2++ ); + *p2 = round_fx( cor ); + cor = L_mac( cor, *ptr_h1++, *ptr_h2++ ); + *p1 = round_fx( cor ); + cor = L_mac( cor, *ptr_h1++, *ptr_h2++ ); + *p0 = round_fx( cor ); + + p3 -= ( 16 + 1 ); + p2 -= ( 16 + 1 ); + p1 -= ( 16 + 1 ); + p0 -= ( 16 + 1 ); } - cor = L_mac(cor, *ptr_h1++, *ptr_h2++); - *p3 = round_fx(cor); + cor = L_mac( cor, *ptr_h1++, *ptr_h2++ ); + *p3 = round_fx( cor ); pos--; ptr_hf += 4; @@ -1121,38 +1103,41 @@ void E_ACELP_corrmatrix(Word16 h[], Word16 sign[], Word16 vec[], Word16 rrixix[4 p2 = &rrixiy[2][0]; p3 = &rrixiy[3][0]; - FOR(i = 0; i < L_SUBFR; i += 4) + FOR( i = 0; i < L_SUBFR; i += 4 ) { psign0 = &vec[1]; - if (sign[i+0] > 0 ) psign0 = &sign[1]; + if ( sign[i + 0] > 0 ) + psign0 = &sign[1]; psign1 = &vec[2]; - if (sign[i+1] > 0 ) psign1 = &sign[2]; + if ( sign[i + 1] > 0 ) + psign1 = &sign[2]; psign2 = &vec[3]; - if (sign[i+2] > 0 ) psign2 = &sign[3]; + if ( sign[i + 2] > 0 ) + psign2 = &sign[3]; psign3 = &vec[0]; - if (sign[i+3] > 0 ) psign3 = &sign[0]; + if ( sign[i + 3] > 0 ) + psign3 = &sign[0]; - E_ACELP_apply_sign(p0, psign0); + E_ACELP_apply_sign( p0, psign0 ); p0 += 16; - E_ACELP_apply_sign(p1, psign1); + E_ACELP_apply_sign( p1, psign1 ); p1 += 16; - E_ACELP_apply_sign(p2, psign2); + E_ACELP_apply_sign( p2, psign2 ); p2 += 16; - E_ACELP_apply_sign(p3, psign3); + E_ACELP_apply_sign( p3, psign3 ); p3 += 16; } return; } -void E_ACELP_4tsearch_fx(Word16 dn[], const Word16 cn[], const Word16 H[], Word16 code[], - const PulseConfig *config, Word16 ind[], Word16 y[]) +void E_ACELP_4tsearch_fx( Word16 dn[], const Word16 cn[], const Word16 H[], Word16 code[], const PulseConfig *config, Word16 ind[], Word16 y[] ) { Word16 sign[L_SUBFR], vec[L_SUBFR]; Word16 cor_x[16], cor_y[16], h_buf[4 * L_SUBFR]; @@ -1176,70 +1161,71 @@ void E_ACELP_4tsearch_fx(Word16 dn[], const Word16 cn[], const Word16 H[], Word1 #endif - alp = config->alp; /* Q13 */ /* initial value for energy of all fixed pulses */ move16(); + alp = config->alp; /* Q13 */ /* initial value for energy of all fixed pulses */ + move16(); nb_pulse = config->nb_pulse; move16(); - nb_pulse_m2 = sub(nb_pulse, 2); + nb_pulse_m2 = sub( nb_pulse, 2 ); - set16_fx(codvec, 0, nb_pulse); + set16_fx( codvec, 0, nb_pulse ); /* * Find sign for each pulse position. */ - E_ACELP_pulsesign(cn, dn, dn2, sign, vec, alp, 0x7fff, L_SUBFR); + E_ACELP_pulsesign( cn, dn, dn2, sign, vec, alp, 0x7fff, L_SUBFR ); /* * Select the most important 8 position per track according to dn2[]. */ - E_ACELP_findcandidates(dn2, dn2_pos, pos_max); + E_ACELP_findcandidates( dn2, dn2_pos, pos_max ); /* * Compute h_inv[i]. */ - set16_fx(h_buf, 0, L_SUBFR); + set16_fx( h_buf, 0, L_SUBFR ); - set16_fx(h_buf + (2 * L_SUBFR),0,L_SUBFR); + set16_fx( h_buf + ( 2 * L_SUBFR ), 0, L_SUBFR ); h = h_buf + L_SUBFR; - h_inv = h_buf + (3 * L_SUBFR); + h_inv = h_buf + ( 3 * L_SUBFR ); /*Check the energy if it is too high then scale to prevent an overflow*/ scale = 0; move16(); - L_tmp = L_deposit_l(0); + L_tmp = L_deposit_l( 0 ); BASOP_SATURATE_WARNING_OFF_EVS - FOR (i = 0; i < L_SUBFR; i++) + FOR( i = 0; i < L_SUBFR; i++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_mac_o(L_tmp, H[i], H[i], &Overflow); + L_tmp = L_mac_o( L_tmp, H[i], H[i], &Overflow ); #else - L_tmp = L_mac(L_tmp, H[i], H[i]); + L_tmp = L_mac( L_tmp, H[i], H[i] ); #endif } - val = extract_h(L_tmp); + val = extract_h( L_tmp ); BASOP_SATURATE_WARNING_ON_EVS - if (GT_16(val, 0x2000)) + if ( GT_16( val, 0x2000 ) ) { scale = -1; move16(); } - if (GT_16(val, 0x7000)) + if ( GT_16( val, 0x7000 ) ) { scale = -2; move16(); } - Copy_Scale_sig(H, h, L_SUBFR, scale); + Copy_Scale_sig( H, h, L_SUBFR, scale ); - E_ACELP_vec_neg(h, h_inv, L_SUBFR); + E_ACELP_vec_neg( h, h_inv, L_SUBFR ); /* * Compute correlation matrices needed for the codebook search. */ - E_ACELP_corrmatrix(h, sign, vec, rrixix, rrixiy); + E_ACELP_corrmatrix( h, sign, vec, rrixix, rrixiy ); /* @@ -1258,57 +1244,57 @@ void E_ACELP_4tsearch_fx(Word16 dn[], const Word16 cn[], const Word16 H[], Word1 move16(); /*Number of iterations*/ - FOR (k = 0; k < config->nbiter; k++) + FOR( k = 0; k < config->nbiter; k++ ) { - E_ACELP_setup_pulse_search_pos(config, k, ipos); + E_ACELP_setup_pulse_search_pos( config, k, ipos ); /* format of alp changes to Q(15-ALP2_E) */ pos = config->fixedpulses; move16(); - IF (config->fixedpulses == 0) /* 1100, 11, 1110, 1111, 2211 */ + IF( config->fixedpulses == 0 ) /* 1100, 11, 1110, 1111, 2211 */ { ps = 0; move16(); alp = 0; move16(); - set16_fx(vec, 0, L_SUBFR); + set16_fx( vec, 0, L_SUBFR ); } - ELSE IF (EQ_16(config->fixedpulses, 2)) /* 2222 and 3322 */ + ELSE IF( EQ_16( config->fixedpulses, 2 ) ) /* 2222 and 3322 */ { /* first stage: fix 2 pulses */ ind[0] = pos_max[ipos[0]]; move16(); ind[1] = pos_max[ipos[1]]; move16(); - ps = add(dn[ind[0]], dn[ind[1]]); + ps = add( dn[ind[0]], dn[ind[1]] ); /*alp = rrixix[ipos[0]][ind[0] >> 2] + rrixix[ipos[1]][ind[1] >> 2] + rrixiy[ipos[0]][((ind[0] >> 2) << 4) + (ind[1] >> 2)];*/ - i = shr(ind[0], 2); - j = shr(ind[1], 2); - l = add(shl(i, 4), j); - s = L_mult(rrixix[ipos[0]][i], _1_); /* Q9+Q12+1 */ - s = L_mac(s, rrixix[ipos[1]][j], _1_); - alp = mac_r(s, rrixiy[ipos[0]][l], _1_); + i = shr( ind[0], 2 ); + j = shr( ind[1], 2 ); + l = add( shl( i, 4 ), j ); + s = L_mult( rrixix[ipos[0]][i], _1_ ); /* Q9+Q12+1 */ + s = L_mac( s, rrixix[ipos[1]][j], _1_ ); + alp = mac_r( s, rrixiy[ipos[0]][l], _1_ ); p0 = h - ind[0]; - if (sign[ind[0]] < 0) + if ( sign[ind[0]] < 0 ) { p0 = h_inv - ind[0]; } p1 = h - ind[1]; - if (sign[ind[1]] < 0) + if ( sign[ind[1]] < 0 ) { p1 = h_inv - ind[1]; } - FOR (i = 0; i < L_SUBFR; i++) + FOR( i = 0; i < L_SUBFR; i++ ) { - vec[i] = add(*p0++, *p1++); + vec[i] = add( *p0++, *p1++ ); move16(); } } @@ -1326,47 +1312,47 @@ void E_ACELP_4tsearch_fx(Word16 dn[], const Word16 cn[], const Word16 H[], Word1 move16(); /*ps = dn[ind[0]] + dn[ind[1]] + dn[ind[2]] + dn[ind[3]];*/ - ps = add(add(add(dn[ind[0]], dn[ind[1]]), dn[ind[2]]), dn[ind[3]]); + ps = add( add( add( dn[ind[0]], dn[ind[1]] ), dn[ind[2]] ), dn[ind[3]] ); p0 = h - ind[0]; - if (sign[ind[0]] < 0) + if ( sign[ind[0]] < 0 ) { p0 = h_inv - ind[0]; } p1 = h - ind[1]; - if (sign[ind[1]] < 0) + if ( sign[ind[1]] < 0 ) { p1 = h_inv - ind[1]; } p2 = h - ind[2]; - if (sign[ind[2]] < 0) + if ( sign[ind[2]] < 0 ) { p2 = h_inv - ind[2]; } p3 = h - ind[3]; - if (sign[ind[3]] < 0) + if ( sign[ind[3]] < 0 ) { p3 = h_inv - ind[3]; } - FOR (i = 0; i < L_SUBFR; i++) + FOR( i = 0; i < L_SUBFR; i++ ) { - vec[i] = add(add(add(*p0++, *p1++), *p2++), *p3++); + vec[i] = add( add( add( *p0++, *p1++ ), *p2++ ), *p3++ ); move16(); } - L_tmp = L_mult(vec[0], vec[0]); - FOR (i = 1; i < L_SUBFR; i++) + L_tmp = L_mult( vec[0], vec[0] ); + FOR( i = 1; i < L_SUBFR; i++ ) #ifdef BASOP_NOGLOB - L_tmp = L_mac_o(L_tmp, vec[i], vec[i], &Overflow); -#else - L_tmp = L_mac(L_tmp, vec[i], vec[i]); -#endif + L_tmp = L_mac_o( L_tmp, vec[i], vec[i], &Overflow ); +#else + L_tmp = L_mac( L_tmp, vec[i], vec[i] ); +#endif - alp = round_fx(L_shr(L_tmp, 3)); + alp = round_fx( L_shr( L_tmp, 3 ) ); /*alp *= 0.5F; */ } @@ -1374,83 +1360,83 @@ void E_ACELP_4tsearch_fx(Word16 dn[], const Word16 cn[], const Word16 H[], Word1 /* other stages of 2 pulses */ st = 0; move16(); - FOR (j = pos; j < nb_pulse; j += 2) + FOR( j = pos; j < nb_pulse; j += 2 ) { - IF (GE_16(nb_pulse_m2, j)) /* pair-wise search */ + IF( GE_16( nb_pulse_m2, j ) ) /* pair-wise search */ { /* * Calculate correlation of all possible positions * of the next 2 pulses with previous fixed pulses. * Each pulse can have 16 possible positions. */ - E_ACELP_h_vec_corr1(h, vec, ipos[j], sign, rrixix, cor_x, dn2_pos, config->nbpos[st]); + E_ACELP_h_vec_corr1( h, vec, ipos[j], sign, rrixix, cor_x, dn2_pos, config->nbpos[st] ); - E_ACELP_h_vec_corr2(h, vec, ipos[j + 1], sign, rrixix, cor_y); + E_ACELP_h_vec_corr2( h, vec, ipos[j + 1], sign, rrixix, cor_y ); /* * Find best positions of 2 pulses. */ - E_ACELP_2pulse_search(config->nbpos[st], ipos[j], ipos[j + 1], &ps, &alp, - &ind[j], &ind[j+1], dn, dn2_pos, cor_x, cor_y, rrixiy); - + E_ACELP_2pulse_search( config->nbpos[st], ipos[j], ipos[j + 1], &ps, &alp, + &ind[j], &ind[j + 1], dn, dn2_pos, cor_x, cor_y, rrixiy ); } ELSE /* single pulse search */ { - E_ACELP_h_vec_corr2(h, vec, ipos[j], sign, rrixix, cor_x); + E_ACELP_h_vec_corr2( h, vec, ipos[j], sign, rrixix, cor_x ); - E_ACELP_h_vec_corr2(h, vec, ipos[j + 1], sign, rrixix, cor_y); + E_ACELP_h_vec_corr2( h, vec, ipos[j + 1], sign, rrixix, cor_y ); - E_ACELP_1pulse_search(&ipos[j], &ps, &alp, - &ind[j], dn, cor_x, cor_y); + E_ACELP_1pulse_search( &ipos[j], &ps, &alp, + &ind[j], dn, cor_x, cor_y ); } - IF (GT_16(nb_pulse_m2, j)) + IF( GT_16( nb_pulse_m2, j ) ) { p0 = h - ind[j]; - if (sign[ind[j]] < 0) + if ( sign[ind[j]] < 0 ) { p0 = h_inv - ind[j]; } p1 = h - ind[j + 1]; - if (sign[ind[j + 1]] < 0) + if ( sign[ind[j + 1]] < 0 ) { p1 = h_inv - ind[j + 1]; } - FOR (i = 0; i < L_SUBFR; i++) + FOR( i = 0; i < L_SUBFR; i++ ) { - tmp = add(*p0++, *p1++); + tmp = add( *p0++, *p1++ ); #ifdef BASOP_NOGLOB - vec[i] = add_o(vec[i], tmp, &Overflow); /* can saturate here. */ move16(); + vec[i] = add_o( vec[i], tmp, &Overflow ); /* can saturate here. */ + move16(); #else - vec[i] = add(vec[i], tmp); /* can saturate here. */ move16(); + vec[i] = add( vec[i], tmp ); /* can saturate here. */ + move16(); #endif } - } - st = add(st, 1); + st = add( st, 1 ); } /* memorise the best codevector */ /*ps = ps * ps; MULT(1);*/ - ps = mult(ps, ps); + ps = mult( ps, ps ); /*s = (alpk * ps) - (psk * alp); MULT(2);ADD(1);*/ - s = L_msu(L_mult(alpk, ps), psk, alp); /*Q9+Q6+1=Q16*/ + s = L_msu( L_mult( alpk, ps ), psk, alp ); /*Q9+Q6+1=Q16*/ - if (psk < 0) + if ( psk < 0 ) { s = 1; } - IF (s > 0) + IF( s > 0 ) { psk = ps; move16(); alpk = alp; move16(); - Copy(ind,codvec, nb_pulse); + Copy( ind, codvec, nb_pulse ); check = 1; /* debug code not instrumented */ } } @@ -1461,24 +1447,24 @@ void E_ACELP_4tsearch_fx(Word16 dn[], const Word16 cn[], const Word16 H[], Word1 * Build the codeword, the filtered codeword and index of codevector, as well as store weighted correlations. */ - E_ACELP_build_code(nb_pulse, codvec, sign, code, ind); + E_ACELP_build_code( nb_pulse, codvec, sign, code, ind ); - set16_fx(y, 0, L_SUBFR); - FOR (k = 0; k 0) + if ( sign[i] > 0 ) { - p0 -= 2*L_SUBFR; + p0 -= 2 * L_SUBFR; } - FOR (i=0; i 0) + if ( cmpl_flag > 0 ) { config.nbiter = cmpl_flag; move16(); } test(); test(); - IF( NE_16(L_frame,last_L_frame)&&EQ_32(total_brate,ACELP_24k40)&<_32(i_subfr,5*L_SUBFR)) + IF( NE_16( L_frame, last_L_frame ) && EQ_32( total_brate, ACELP_24k40 ) && LT_32( i_subfr, 5 * L_SUBFR ) ) { - config.nbiter = sub(config.nbiter, 1); - config.nbiter = s_max(config.nbiter, 1); + config.nbiter = sub( config.nbiter, 1 ); + config.nbiter = s_max( config.nbiter, 1 ); } - IF (acelpautoc) + IF( acelpautoc ) { - E_ACELP_4tsearchx_fx(dn, cn, R, code, &config, ind); + E_ACELP_4tsearchx_fx( dn, cn, R, code, &config, ind ); } ELSE { - E_ACELP_4tsearch_fx(dn, cn, H, code, &config, ind, y); + E_ACELP_4tsearch_fx( dn, cn, H, code, &config, ind, y ); } - E_ACELP_indexing_fx(code, &config, NB_TRACK_FCB_4T, _index); + E_ACELP_indexing_fx( code, &config, NB_TRACK_FCB_4T, _index ); return; } @@ -1593,16 +1580,16 @@ static void E_ACELP_indexing_shift( { Word16 right_shift, i; - assert(shift_bits <= 16); + assert( shift_bits <= 16 ); - right_shift = sub(16, shift_bits); + right_shift = sub( 16, shift_bits ); - FOR (i=sub(wordcnt, 1); i>0; --i) + FOR( i = sub( wordcnt, 1 ); i > 0; --i ) { - dst[i] = s_or(lshl(src[i], shift_bits), lshr(src[i-1], right_shift)); + dst[i] = s_or( lshl( src[i], shift_bits ), lshr( src[i - 1], right_shift ) ); move16(); } - dst[i] = s_or(lshl(src[i], shift_bits), lsb_bits); + dst[i] = s_or( lshl( src[i], shift_bits ), lsb_bits ); move16(); return; } @@ -1613,8 +1600,7 @@ Word16 E_ACELP_indexing_fx( const Word16 code[], const PulseConfig *config, Word16 num_tracks, - Word16 prm[] -) + Word16 prm[] ) { Word16 track, shift_bits; Word16 p[NB_TRACK_FCB_4T], wordcnt; @@ -1622,7 +1608,7 @@ Word16 E_ACELP_indexing_fx( UWord16 idx[MAX_IDX_LEN]; Word16 saved_bits; - assert(num_tracks == NB_TRACK_FCB_4T); + assert( num_tracks == NB_TRACK_FCB_4T ); saved_bits = 0; move16(); @@ -1630,22 +1616,22 @@ Word16 E_ACELP_indexing_fx( /* * Code state of pulses of all tracks * */ - wordcnt = shr(add(config->bits, 15), 4); /* ceil(bits/16) */ + wordcnt = shr( add( config->bits, 15 ), 4 ); /* ceil(bits/16) */ - set16_fx((Word16*)idx, 0, wordcnt); + set16_fx( (Word16 *) idx, 0, wordcnt ); - IF (EQ_16(config->bits, 43)) /* EVS pulse indexing */ + IF( EQ_16( config->bits, 43 ) ) /* EVS pulse indexing */ { - saved_bits = E_ACELP_code43bit_fx(code, s, p, idx); + saved_bits = E_ACELP_code43bit_fx( code, s, p, idx ); } ELSE { - FOR (track = 0; track < num_tracks; track++) + FOR( track = 0; track < num_tracks; track++ ) { /* Code track of length 2^4 where step between tracks is 4. */ - E_ACELP_codearithp_fx(code+track, &n[track], &s[track], &p[track]); + E_ACELP_codearithp_fx( code + track, &n[track], &s[track], &p[track] ); } - fcb_pulse_track_joint_fx(idx, wordcnt, s, p, num_tracks); + fcb_pulse_track_joint_fx( idx, wordcnt, s, p, num_tracks ); } /* check if we need to code track positions */ @@ -1653,80 +1639,80 @@ Word16 E_ACELP_indexing_fx( move16(); shift_bits = 0; move16(); - SWITCH (config->codetrackpos) + SWITCH( config->codetrackpos ) { - case TRACKPOS_FIXED_TWO: - /* Code position of consecutive tracks with single extra pulses */ - /* Find track with one pulse less. */ - if (NE_16(p[0], p[1])) - { - /* Either 0110 or 1001 */ - track = 1; + case TRACKPOS_FIXED_TWO: + /* Code position of consecutive tracks with single extra pulses */ + /* Find track with one pulse less. */ + if ( NE_16( p[0], p[1] ) ) + { + /* Either 0110 or 1001 */ + track = 1; + move16(); + } + if ( GT_16( p[3], p[1] ) ) + { + track = add( track, 2 ); + } + shift_bits = 2; move16(); - } - if (GT_16(p[3], p[1])) - { - track = add(track, 2); - } - shift_bits = 2; - move16(); - BREAK; + BREAK; - case TRACKPOS_FREE_THREE: - /* Code position of track with one pulse less than others */ - /* Find track with one pulse less. */ - if (LT_16(p[1], p[0])) - { - track = 1; - move16(); - } - if (LT_16(p[2], p[0])) - { - track = 2; - move16(); - } - if (LT_16(p[3], p[0])) - { - track = 3; + case TRACKPOS_FREE_THREE: + /* Code position of track with one pulse less than others */ + /* Find track with one pulse less. */ + if ( LT_16( p[1], p[0] ) ) + { + track = 1; + move16(); + } + if ( LT_16( p[2], p[0] ) ) + { + track = 2; + move16(); + } + if ( LT_16( p[3], p[0] ) ) + { + track = 3; + move16(); + } + shift_bits = 2; move16(); - } - shift_bits = 2; - move16(); - BREAK; + BREAK; - case TRACKPOS_FREE_ONE: - /* Code position of track with one pulse less than others */ - /* Find track with one pulse less. */ - if (GT_16(p[1], p[0])) - { - track = 1; - move16(); - } - if (GT_16(p[2], p[0])) - { - track = 2; - move16(); - } - if (GT_16(p[3], p[0])) - { - track = 3; + case TRACKPOS_FREE_ONE: + /* Code position of track with one pulse less than others */ + /* Find track with one pulse less. */ + if ( GT_16( p[1], p[0] ) ) + { + track = 1; + move16(); + } + if ( GT_16( p[2], p[0] ) ) + { + track = 2; + move16(); + } + if ( GT_16( p[3], p[0] ) ) + { + track = 3; + move16(); + } + shift_bits = 2; move16(); - } - shift_bits = 2; - move16(); - BREAK; + BREAK; - case TRACKPOS_FIXED_EVEN: - case TRACKPOS_FIXED_FIRST: - BREAK; + case TRACKPOS_FIXED_EVEN: + case TRACKPOS_FIXED_FIRST: + BREAK; - default: - printf("Codebook mode not implemented.\n"); - assert(0); /* mode not yet implemented*/ - BREAK; + default: + printf( "Codebook mode not implemented.\n" ); + assert( 0 ); /* mode not yet implemented*/ + BREAK; } - E_ACELP_indexing_shift(wordcnt, shift_bits, track, idx, (UWord16*)prm); + E_ACELP_indexing_shift( wordcnt, shift_bits, track, idx, (UWord16 *) prm ); return saved_bits; } @@ -1737,26 +1723,27 @@ Word16 E_ACELP_indexing_fx( * Find adaptive codebook. *--------------------------------------------------------------------------*/ void E_ACELP_adaptive_codebook( - Word16 *exc, /* i/o: pointer to the excitation frame Q_new */ - Word16 T0, /* i : integer pitch lag Q0 */ - Word16 T0_frac, /* i : fraction of lag */ - Word16 T0_res, /* i : pitch resolution */ - Word16 T0_res_max, /* i : maximum pitch resolution */ - Word16 mode, /* i : filtering mode (0: no, 1: yes, 2: adaptive) */ - Word16 i_subfr, /* i : subframe index */ - Word16 L_subfr, /* i : subframe length */ - Word16 L_frame, /* i : subframe length */ - Word16 *h1, /* i : impulse response of weighted synthesis filter 1Q14+shift */ - Word16 clip_gain, /* i : flag to indicate ??? */ - Word16 *xn, /* i : Close-loop Pitch search target vector Q_xn */ - Word16 *y1, /* o : zero-memory filtered adaptive excitation Q_xn */ - ACELP_CbkCorr *g_corr,/* o : ACELP correlation values */ - Word16 **pt_indice, /* i/o: quantization indices pointer */ - Word16 *pitch_gain, /* o : adaptive codebook gain 1Q14 */ - Word16 exp_xn /* i : exponent of xn (Q_xn-15) */ - ,Word16 rf_mode - ,Word16 rf_coder_type - ,Word16* lp_select + Word16 *exc, /* i/o: pointer to the excitation frame Q_new */ + Word16 T0, /* i : integer pitch lag Q0 */ + Word16 T0_frac, /* i : fraction of lag */ + Word16 T0_res, /* i : pitch resolution */ + Word16 T0_res_max, /* i : maximum pitch resolution */ + Word16 mode, /* i : filtering mode (0: no, 1: yes, 2: adaptive) */ + Word16 i_subfr, /* i : subframe index */ + Word16 L_subfr, /* i : subframe length */ + Word16 L_frame, /* i : subframe length */ + Word16 *h1, /* i : impulse response of weighted synthesis filter 1Q14+shift */ + Word16 clip_gain, /* i : flag to indicate ??? */ + Word16 *xn, /* i : Close-loop Pitch search target vector Q_xn */ + Word16 *y1, /* o : zero-memory filtered adaptive excitation Q_xn */ + ACELP_CbkCorr *g_corr, /* o : ACELP correlation values */ + Word16 **pt_indice, /* i/o: quantization indices pointer */ + Word16 *pitch_gain, /* o : adaptive codebook gain 1Q14 */ + Word16 exp_xn /* i : exponent of xn (Q_xn-15) */ + , + Word16 rf_mode, + Word16 rf_coder_type, + Word16 *lp_select ) { @@ -1769,23 +1756,23 @@ void E_ACELP_adaptive_codebook( Word16 pit_L_interpol, pit_up_samp; Word16 use_prev_sf_pit_gain = 0; - if( rf_mode == 1 && rf_coder_type == 100) + if ( rf_mode == 1 && rf_coder_type == 100 ) { use_prev_sf_pit_gain = 1; } BASOP_SATURATE_ERROR_ON_EVS; - L_ener = L_deposit_l(0); + L_ener = L_deposit_l( 0 ); /* find pitch excitation */ /*for &exc[i_subfr]*/ - if (EQ_16(T0_res, shr(T0_res_max, 1))) + if ( EQ_16( T0_res, shr( T0_res_max, 1 ) ) ) { - T0_frac = shl(T0_frac, 1); + T0_frac = shl( T0_frac, 1 ); } - IF (EQ_16(T0_res_max, 6)&&rf_mode==0) + IF( EQ_16( T0_res_max, 6 ) && rf_mode == 0 ) { pitch_inter = pitch_inter6_2; pit_L_interpol = PIT_L_INTERPOL6_2; @@ -1802,21 +1789,21 @@ void E_ACELP_adaptive_codebook( move16(); } - pred_lt4( &exc[i_subfr], &exc[i_subfr], T0, T0_frac, L_SUBFR+1, pitch_inter, pit_L_interpol, pit_up_samp); + pred_lt4( &exc[i_subfr], &exc[i_subfr], T0, T0_frac, L_SUBFR + 1, pitch_inter, pit_L_interpol, pit_up_samp ); test(); - IF(EQ_16(mode,NORMAL_OPERATION)||(EQ_16(mode,FULL_BAND))) + IF( EQ_16( mode, NORMAL_OPERATION ) || ( EQ_16( mode, FULL_BAND ) ) ) { - E_UTIL_f_convolve(&exc[i_subfr], h1, y1,L_subfr); + E_UTIL_f_convolve( &exc[i_subfr], h1, y1, L_subfr ); - IF(use_prev_sf_pit_gain == 0) + IF( use_prev_sf_pit_gain == 0 ) { - gain1 = E_ACELP_xy1_corr(xn, y1, g_corr,1,L_subfr,exp_xn); + gain1 = E_ACELP_xy1_corr( xn, y1, g_corr, 1, L_subfr, exp_xn ); /* clip gain if necessary to avoid problem at decoder */ test(); - if (clip_gain && GT_16(gain1,15565/*0.95 Q14*/)) + if ( clip_gain && GT_16( gain1, 15565 /*0.95 Q14*/ ) ) { - gain1 = 15565/*0.95f Q14*/; + gain1 = 15565 /*0.95f Q14*/; move16(); } *pitch_gain = gain1; @@ -1824,60 +1811,62 @@ void E_ACELP_adaptive_codebook( } /* find energy of new target xn2[] */ - E_ACELP_codebook_target_update(xn, xn2, y1, gain1, L_subfr); - L_ener = Dot_product12_offs(xn2, xn2, L_subfr, &exp_ener, 0); - L_ener = L_shr(L_ener,sub(31,exp_ener)); + E_ACELP_codebook_target_update( xn, xn2, y1, gain1, L_subfr ); + L_ener = Dot_product12_offs( xn2, xn2, L_subfr, &exp_ener, 0 ); + L_ener = L_shr( L_ener, sub( 31, exp_ener ) ); } /*-----------------------------------------------------------------* * - find pitch excitation filtered by 1st order LP filter. * * - find filtered pitch exc. y2[]=exc[] convolved with h1[]) * * - compute pitch gain2 * - *-----------------------------------------------------------------*/ test(); - IF(EQ_16(mode,NORMAL_OPERATION)||EQ_16(mode,LOW_PASS)) + *-----------------------------------------------------------------*/ + test(); + IF( EQ_16( mode, NORMAL_OPERATION ) || EQ_16( mode, LOW_PASS ) ) { /* find pitch excitation with lp filter */ - fac_m = 20972/*0.64f Q15*/; + fac_m = 20972 /*0.64f Q15*/; move16(); - if ( EQ_16(L_frame,L_FRAME16k)) + if ( EQ_16( L_frame, L_FRAME16k ) ) { - fac_m = 19005/*0.58f Q15*/; + fac_m = 19005 /*0.58f Q15*/; move16(); } /* fac_n = 0.5*(1.0-fac_m); */ - fac_n = mult_r(sub(0x7FFF,fac_m),0x4000); - FOR (i=0; iy1y1 = g_corr2.y1y1; @@ -1898,10 +1887,10 @@ void E_ACELP_adaptive_codebook( move16(); } - IF(EQ_16(mode,NORMAL_OPERATION)) + IF( EQ_16( mode, NORMAL_OPERATION ) ) { **pt_indice = select; - (*pt_indice)++; + ( *pt_indice )++; move16(); } } @@ -1911,7 +1900,7 @@ void E_ACELP_adaptive_codebook( select = FULL_BAND; move16(); } - *lp_select=select; + *lp_select = select; BASOP_SATURATE_ERROR_OFF_EVS; } @@ -1923,27 +1912,27 @@ void E_ACELP_adaptive_codebook( * Find innovative codebook. *--------------------------------------------------------------------------*/ void E_ACELP_innovative_codebook_fx( - Word16 *exc, /* i : pointer to the excitation frame Q_new */ - Word16 T0, /* i : integer pitch lag Q0 */ - Word16 T0_frac, /* i : fraction of lag Q0 */ - Word16 T0_res, /* i : pitch resolution Q0 */ - Word16 pitch_gain, /* i : adaptive codebook gain 1Q14 */ - Word16 tilt_code, /* i : tilt factor Q15 */ - ACELP_config* acelp_cfg,/* i/o: configuration of the ACELP */ - Word16 i_subfr, /* i : subframe index */ - const Word16 *Aq, /* i : quantized LPC coefficients 3Q12 */ - Word16 *h1, /* i : impulse response of weighted synthesis filter 1Q14+shift */ - Word16 *xn, /* i : Close-loop Pitch search target vector Q_xn */ - Word16 *cn, /* i : Innovative codebook search target vector Q_new */ - Word16 *y1, /* i : zero-memory filtered adaptive excitation Q_xn */ - Word16 *y2, /* o : zero-memory filtered algebraic excitation Q9 */ - Word8 acelpautoc, /* i : autocorrelation mode enabled */ - Word16 **pt_indice, /* i/o: quantization indices pointer */ - Word16 *code, /* o : innovative codebook Q9 Q9 */ - Word16 shift, /* i : Scaling to get 12 bits */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 last_L_frame,/* i : length of the last frame */ - const Word32 total_brate /* i : ttoal bit-rate */ + Word16 *exc, /* i : pointer to the excitation frame Q_new */ + Word16 T0, /* i : integer pitch lag Q0 */ + Word16 T0_frac, /* i : fraction of lag Q0 */ + Word16 T0_res, /* i : pitch resolution Q0 */ + Word16 pitch_gain, /* i : adaptive codebook gain 1Q14 */ + Word16 tilt_code, /* i : tilt factor Q15 */ + ACELP_config *acelp_cfg, /* i/o: configuration of the ACELP */ + Word16 i_subfr, /* i : subframe index */ + const Word16 *Aq, /* i : quantized LPC coefficients 3Q12 */ + Word16 *h1, /* i : impulse response of weighted synthesis filter 1Q14+shift */ + Word16 *xn, /* i : Close-loop Pitch search target vector Q_xn */ + Word16 *cn, /* i : Innovative codebook search target vector Q_new */ + Word16 *y1, /* i : zero-memory filtered adaptive excitation Q_xn */ + Word16 *y2, /* o : zero-memory filtered algebraic excitation Q9 */ + Word8 acelpautoc, /* i : autocorrelation mode enabled */ + Word16 **pt_indice, /* i/o: quantization indices pointer */ + Word16 *code, /* o : innovative codebook Q9 Q9 */ + Word16 shift, /* i : Scaling to get 12 bits */ + const Word16 L_frame, /* i : length of the frame */ + const Word16 last_L_frame, /* i : length of the last frame */ + const Word32 total_brate /* i : ttoal bit-rate */ ) { Word16 xn2[L_SUBFR] /* Q_xn */, cn2[L_SUBFR] /* Q_xn */, dn[L_SUBFR] /* Rw2*cn2 */, h2[L_SUBFR] /* 4Q11 */; @@ -1953,67 +1942,65 @@ void E_ACELP_innovative_codebook_fx( pitch = T0; move16(); - idx = shr(i_subfr, 6); - if (GT_16(T0_frac, shr(T0_res, 1))) + idx = shr( i_subfr, 6 ); + if ( GT_16( T0_frac, shr( T0_res, 1 ) ) ) { - pitch = add(pitch,1); + pitch = add( pitch, 1 ); } BASOP_SATURATE_ERROR_ON_EVS; /* Update target vector for ACELP codebook search */ - E_ACELP_codebook_target_update(xn, xn2, y1, pitch_gain, L_SUBFR); + E_ACELP_codebook_target_update( xn, xn2, y1, pitch_gain, L_SUBFR ); /* Include fixed-gain pitch contribution into impulse resp. h1[] */ - Copy_Scale_sig(h1, h2, L_SUBFR, sub(-3, shift)); /*h2 1Q14+shift -> 4Q11, 1bit of headroom for Residu and xh_corr*/ + Copy_Scale_sig( h1, h2, L_SUBFR, sub( -3, shift ) ); /*h2 1Q14+shift -> 4Q11, 1bit of headroom for Residu and xh_corr*/ - cb_shape_fx(acelp_cfg->pre_emphasis, acelp_cfg->pitch_sharpening, acelp_cfg->phase_scrambling, acelp_cfg->formant_enh, acelp_cfg->formant_tilt, - acelp_cfg->formant_enh_num, acelp_cfg->formant_enh_den, Aq, h2, tilt_code, pitch, 1, L_SUBFR); + cb_shape_fx( acelp_cfg->pre_emphasis, acelp_cfg->pitch_sharpening, acelp_cfg->phase_scrambling, acelp_cfg->formant_enh, acelp_cfg->formant_tilt, + acelp_cfg->formant_enh_num, acelp_cfg->formant_enh_den, Aq, h2, tilt_code, pitch, 1, L_SUBFR ); /* Correlation between target xn2[] and impulse response h1[] */ - IF (acelpautoc) + IF( acelpautoc ) { /* h2: 4Q11, Rw2: (Rw2_e)Q */ - /* Rw2_e = */ E_ACELP_hh_corr(h2, Rw2, L_SUBFR, 3); + /* Rw2_e = */ E_ACELP_hh_corr( h2, Rw2, L_SUBFR, 3 ); - E_ACELP_conv(xn2, h2, cn2); + E_ACELP_conv( xn2, h2, cn2 ); /* dn_e -> Rw2_e*Q_xn */ - /*dn_e = */ E_ACELP_toeplitz_mul_fx(Rw2,cn2,dn,L_SUBFR,sub((Word16)PulseConfTable[acelp_cfg->fixed_cdk_index[idx]].nb_pulse, 24) > 0); - + /*dn_e = */ E_ACELP_toeplitz_mul_fx( Rw2, cn2, dn, L_SUBFR, sub( (Word16) PulseConfTable[acelp_cfg->fixed_cdk_index[idx]].nb_pulse, 24 ) > 0 ); } ELSE { BASOP_SATURATE_WARNING_OFF_EVS; - E_ACELP_codebook_target_update(cn, cn2, &exc[i_subfr], pitch_gain, L_SUBFR); + E_ACELP_codebook_target_update( cn, cn2, &exc[i_subfr], pitch_gain, L_SUBFR ); BASOP_SATURATE_WARNING_ON_EVS; - Scale_sig(cn2, L_SUBFR, shift); - E_ACELP_xh_corr(xn2, dn, h2, L_SUBFR); + Scale_sig( cn2, L_SUBFR, shift ); + E_ACELP_xh_corr( xn2, dn, h2, L_SUBFR ); } /* Innovative codebook search */ - assert(acelp_cfg->fixed_cdk_index[idx] < ACELP_FIXED_CDK_NB); + assert( acelp_cfg->fixed_cdk_index[idx] < ACELP_FIXED_CDK_NB ); E_ACELP_4t_fx( dn, cn2, h2, Rw2, acelpautoc, code, acelp_cfg->fixed_cdk_index[idx], *pt_indice, L_frame, last_L_frame, total_brate, i_subfr, 0 ); *pt_indice += 8; /* Generate weighted code */ - E_ACELP_weighted_code(code, h2, 11, y2); + E_ACELP_weighted_code( code, h2, 11, y2 ); /*-------------------------------------------------------* * - Add the fixed-gain pitch contribution to code[]. * *-------------------------------------------------------*/ - cb_shape_fx(acelp_cfg->pre_emphasis, acelp_cfg->pitch_sharpening, acelp_cfg->phase_scrambling, acelp_cfg->formant_enh, acelp_cfg->formant_tilt, - acelp_cfg->formant_enh_num, acelp_cfg->formant_enh_den, Aq, code, tilt_code, pitch, 1, L_SUBFR); + cb_shape_fx( acelp_cfg->pre_emphasis, acelp_cfg->pitch_sharpening, acelp_cfg->phase_scrambling, acelp_cfg->formant_enh, acelp_cfg->formant_tilt, + acelp_cfg->formant_enh_num, acelp_cfg->formant_enh_den, Aq, code, tilt_code, pitch, 1, L_SUBFR ); BASOP_SATURATE_ERROR_OFF_EVS; return; } - /*--------------------------------------------------------------------------* * E_ACELP_codearithp_fx * @@ -2023,7 +2010,7 @@ void E_ACELP_innovative_codebook_fx( * n - (output) range of possible states (0...n-1) * p - (output) number of pulses found *--------------------------------------------------------------------------*/ -static void E_ACELP_codearithp_fx(const Word16 v[], UWord32 *n, UWord32 *ps, Word16 *p) +static void E_ACELP_codearithp_fx( const Word16 v[], UWord32 *n, UWord32 *ps, Word16 *p ) { Word16 k, nb_pulse, i, t, pos[NPMAXPT], posno; Word16 sign, m; @@ -2038,42 +2025,42 @@ static void E_ACELP_codearithp_fx(const Word16 v[], UWord32 *n, UWord32 *ps, Wor move16(); t = 0; move16(); - FOR (k=0; k= 0 ) + t = add( t, 1 ); + if ( sub( posno, NPMAXPT ) >= 0 ) { BREAK; } } /* Iterate over the different pulse positions */ - s = L_deposit_l(0); + s = L_deposit_l( 0 ); t = 0; move16(); nb_pulse = 0; move16(); - FOR (k=0; k 0 ) + t = add( t, 1 ); + if ( sub( t, NPMAXPT ) > 0 ) { BREAK; } @@ -2083,32 +2070,32 @@ static void E_ACELP_codearithp_fx(const Word16 v[], UWord32 *n, UWord32 *ps, Wor /* We use L_add_c since we want to work with unsigned UWord32 */ /* Therefore, we have to clear carry */ Carry = 0; - s = L_lshl(s, 1); - if (sign < 0) + s = L_lshl( s, 1 ); + if ( sign < 0 ) { #ifdef BASOP_NOGLOB - s = L_add_co(s, 1, &Carry, &Overflow); -#else /* BASOP_NOGLOB */ - s = L_add_c(s, 1); + s = L_add_co( s, 1, &Carry, &Overflow ); +#else /* BASOP_NOGLOB */ + s = L_add_c( s, 1 ); #endif /* BASOP_NOGLOB */ } /* Code last pulse */ Carry = 0; #ifdef BASOP_NOGLOB - s = L_add_co(s, pulsestostates[pos[k]][t], &Carry, &Overflow); + s = L_add_co( s, pulsestostates[pos[k]][t], &Carry, &Overflow ); #else /* BASOP_NOGLOB */ - s = L_add_c(s, pulsestostates[pos[k]][t]); + s = L_add_c( s, pulsestostates[pos[k]][t] ); #endif - t = add(t, 1); + t = add( t, 1 ); } *ps = s; move32(); - *n = L_deposit_l(0); - if (nb_pulse) + *n = L_deposit_l( 0 ); + if ( nb_pulse ) { - *n = pulsestostates[NB_POS_FCB_4T][nb_pulse-1]; + *n = pulsestostates[NB_POS_FCB_4T][nb_pulse - 1]; move32(); } @@ -2117,7 +2104,7 @@ static void E_ACELP_codearithp_fx(const Word16 v[], UWord32 *n, UWord32 *ps, Wor return; } -void fcb_pulse_track_joint_fx(UWord16 *idxs, Word16 wordcnt, UWord32 *index_n, Word16 *pulse_num, Word16 track_num) +void fcb_pulse_track_joint_fx( UWord16 *idxs, Word16 wordcnt, UWord32 *index_n, Word16 *pulse_num, Word16 track_num ) { Word16 hi_to_low[10]; UWord32 index, index_mask; @@ -2126,7 +2113,7 @@ void fcb_pulse_track_joint_fx(UWord16 *idxs, Word16 wordcnt, UWord32 *index_n, W Word16 track, track_num1, pulse_num0, pulse_num1; Word16 indx_flag_2; - Copy(hi_to_low_tmpl, hi_to_low, 10); + Copy( hi_to_low_tmpl, hi_to_low, 10 ); indx_flag = 0; move16(); @@ -2135,14 +2122,14 @@ void fcb_pulse_track_joint_fx(UWord16 *idxs, Word16 wordcnt, UWord32 *index_n, W indx_flag_2 = 0; move16(); - FOR (track = 0; track < track_num; track++) + FOR( track = 0; track < track_num; track++ ) { - indx_flag = add(indx_flag, shr(pulse_num[track], 2)); - indx_flag_1 = add(indx_flag_1, shr(pulse_num[track], 1)); - indx_flag_2 = add(indx_flag_2, shr(pulse_num[track], 3)); + indx_flag = add( indx_flag, shr( pulse_num[track], 2 ) ); + indx_flag_1 = add( indx_flag_1, shr( pulse_num[track], 1 ) ); + indx_flag_2 = add( indx_flag_2, shr( pulse_num[track], 3 ) ); } - IF (GE_16(indx_flag_2, 1)) + IF( GE_16( indx_flag_2, 1 ) ) { hi_to_low[7] = 9; move16(); @@ -2151,64 +2138,65 @@ void fcb_pulse_track_joint_fx(UWord16 *idxs, Word16 wordcnt, UWord32 *index_n, W } ELSE { - if (LT_16(indx_flag, track_num)) + if ( LT_16( indx_flag, track_num ) ) { hi_to_low[4] = 1; move16(); } - index_mask = L_shr(0xFFFF, sub(9, hi_to_low[4])); + index_mask = L_shr( 0xFFFF, sub( 9, hi_to_low[4] ) ); } - IF (GE_16(indx_flag_1, track_num)) + IF( GE_16( indx_flag_1, track_num ) ) { - indx_tmp = L_deposit_l(0); - index = L_shr(index_n[0], low_len[pulse_num[0]]); - FOR (track = 1; track < track_num; track++) + indx_tmp = L_deposit_l( 0 ); + index = L_shr( index_n[0], low_len[pulse_num[0]] ); + FOR( track = 1; track < track_num; track++ ) { pulse_num0 = pulse_num[track - 1]; move16(); pulse_num1 = pulse_num[track]; move16(); - indx_tmp = L_lshr(index_n[track], low_len[pulse_num1]); + indx_tmp = L_lshr( index_n[track], low_len[pulse_num1] ); /* index = index * indx_fact[pulse_num1] + indx_tmp; */ - index = UL_Mpy_32_32(index, UL_deposit_l(indx_fact[pulse_num1])); - index = UL_addNsD(index, indx_tmp); - index_n[track - 1] = L_add(L_and(index_n[track - 1], low_mask[pulse_num0]), - L_and(L_lshl(index, low_len[pulse_num0]), index_mask)); + index = UL_Mpy_32_32( index, UL_deposit_l( indx_fact[pulse_num1] ) ); + index = UL_addNsD( index, indx_tmp ); + index_n[track - 1] = L_add( L_and( index_n[track - 1], low_mask[pulse_num0] ), + L_and( L_lshl( index, low_len[pulse_num0] ), index_mask ) ); - index = L_lshr(index, hi_to_low[pulse_num0]); + index = L_lshr( index, hi_to_low[pulse_num0] ); } - track_num1 = sub(track_num, 1); + track_num1 = sub( track_num, 1 ); pulse_num1 = pulse_num[track_num1]; move16(); - index_n[track_num1] = L_and(L_add(L_and(index_n[track_num1], low_mask[pulse_num1]), - L_lshl(index, low_len[pulse_num1])), index_mask); - index = L_lshr(index, hi_to_low[pulse_num1]); - IF (GE_16(indx_flag, track_num)) + index_n[track_num1] = L_and( L_add( L_and( index_n[track_num1], low_mask[pulse_num1] ), + L_lshl( index, low_len[pulse_num1] ) ), + index_mask ); + index = L_lshr( index, hi_to_low[pulse_num1] ); + IF( GE_16( indx_flag, track_num ) ) { - IF (GE_16(indx_flag_2, 1)) + IF( GE_16( indx_flag_2, 1 ) ) { - idxs[0] = extract_l(index_n[0]); - idxs[1] = extract_l(L_add(L_lshl(index_n[1], 8), L_lshr(index_n[0], 16))); - idxs[2] = extract_l(L_lshr(index_n[1], 8)); - idxs[3] = extract_l(index_n[2]); - idxs[4] = extract_l(L_add(L_lshl(index_n[3], 8), L_lshr(index_n[2], 16))); - idxs[5] = extract_l(L_lshr(index_n[3], 8)); + idxs[0] = extract_l( index_n[0] ); + idxs[1] = extract_l( L_add( L_lshl( index_n[1], 8 ), L_lshr( index_n[0], 16 ) ) ); + idxs[2] = extract_l( L_lshr( index_n[1], 8 ) ); + idxs[3] = extract_l( index_n[2] ); + idxs[4] = extract_l( L_add( L_lshl( index_n[3], 8 ), L_lshr( index_n[2], 16 ) ) ); + idxs[5] = extract_l( L_lshr( index_n[3], 8 ) ); track = 6; move16(); } ELSE { - FOR (track = 0; track < track_num; track++) + FOR( track = 0; track < track_num; track++ ) { - idxs[track] = extract_l(index_n[track]); + idxs[track] = extract_l( index_n[track] ); } } } ELSE { - idxs[0] = extract_l(L_add(L_lshl(index_n[0], 8), index_n[1])); - idxs[1] = extract_l(L_add(L_lshl(index_n[2], 8), index_n[3])); + idxs[0] = extract_l( L_add( L_lshl( index_n[0], 8 ), index_n[1] ) ); + idxs[1] = extract_l( L_add( L_lshl( index_n[2], 8 ), index_n[3] ) ); track = 2; move16(); } @@ -2217,18 +2205,18 @@ void fcb_pulse_track_joint_fx(UWord16 *idxs, Word16 wordcnt, UWord32 *index_n, W { index = index_n[0]; move32(); - FOR (track = 1; track < 4; track++) + FOR( track = 1; track < 4; track++ ) { pulse_num1 = pulse_num[track]; - index = L_add(L_lshl(index, index_len[pulse_num1]), index_n[track]); + index = L_add( L_lshl( index, index_len[pulse_num1] ), index_n[track] ); } track = 0; move16(); } - FOR (; track < wordcnt; track++) + FOR( ; track < wordcnt; track++ ) { - idxs[track] = extract_l(index); - index = L_lshr(index, 16); + idxs[track] = extract_l( index ); + index = L_lshr( index, 16 ); } return; } diff --git a/lib_enc/enc_acelp_tcx_main_fx.c b/lib_enc/enc_acelp_tcx_main_fx.c index 236402c3c..0688f7311 100644 --- a/lib_enc/enc_acelp_tcx_main_fx.c +++ b/lib_enc/enc_acelp_tcx_main_fx.c @@ -7,11 +7,11 @@ //#include "prot_fx.h" #include "cnst.h" /* Common constants */ #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ -#include "basop_util.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ +#include "basop_util.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* * enc_acelp_tcx_main_fx() @@ -20,8 +20,8 @@ *--------------------------------------------------------------------*/ void enc_acelp_tcx_main_fx( const Word16 new_samples[], /* i : new samples */ - Encoder_State *st, /* i/o: encoder state structure */ - Word16 Aw[NB_SUBFR16k*(M+1)], /* i : weighted A(z) unquant. for subframes*/ + Encoder_State *st, /* i/o: encoder state structure */ + Word16 Aw[NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquant. for subframes*/ const Word16 lsp_new[M], /* i : LSPs at the end of the frame */ const Word16 lsp_mid[M], /* i : LSPs at the middle of the frame */ Word32 bwe_exc_extended[], /* i/o: bandwidth extended excitation */ @@ -29,41 +29,40 @@ void enc_acelp_tcx_main_fx( Word16 pitch_buf[], /* o : floating pitch for each subframe */ Word16 vad_hover_flag, /* i : VAD hangover flag */ Word16 *Q_new, - Word16 *shift -) + Word16 *shift ) { - Word16 old_bwe_exc[(PIT16k_MAX + (L_FRAME16k + 1) + L_SUBFR16k) * 2]; /* excitation buffer */ + Word16 old_bwe_exc[( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2]; /* excitation buffer */ Word16 *ptr_bwe_exc; TD_BWE_ENC_HANDLE hBWE_TD = st->hBWE_TD; ptr_bwe_exc = old_bwe_exc + PIT16k_MAX * 2; - IF( EQ_16( st->last_core, ACELP_CORE)) + IF( EQ_16( st->last_core, ACELP_CORE ) ) { - set16_fx( old_bwe_exc + PIT16k_MAX * 2, 0, ((L_FRAME16k + 1) + L_SUBFR16k) * 2 ); - Copy(hBWE_TD->old_bwe_exc_fx, old_bwe_exc, PIT16k_MAX * 2 ); + set16_fx( old_bwe_exc + PIT16k_MAX * 2, 0, ( ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2 ); + Copy( hBWE_TD->old_bwe_exc_fx, old_bwe_exc, PIT16k_MAX * 2 ); } ELSE { - set16_fx( old_bwe_exc, 0, ((L_FRAME16k + 1) + L_SUBFR16k + PIT16k_MAX) * 2 ); + set16_fx( old_bwe_exc, 0, ( ( L_FRAME16k + 1 ) + L_SUBFR16k + PIT16k_MAX ) * 2 ); } - if (st->hPlcExt) - {/* PLC: [Guided ACELP PLC] */ - gPLC_encInfo_fx(st->hPlcExt ,st->total_brate, st->bwidth, st->clas, st->coder_type); + if ( st->hPlcExt ) + { /* PLC: [Guided ACELP PLC] */ + gPLC_encInfo_fx( st->hPlcExt, st->total_brate, st->bwidth, st->clas, st->coder_type ); } - IF ( s_and(st->core_brate!=FRAME_NO_DATA, st->core_brate!=SID_2k40) ) + IF( s_and( st->core_brate != FRAME_NO_DATA, st->core_brate != SID_2k40 ) ) { /* Run Core Coder */ - IF (st->tcxonly == 0) + IF( st->tcxonly == 0 ) { core_encode_openloop_fx( st, st->coder_type, Aw, lsp_new, lsp_mid, pitch_buf, voice_factors, ptr_bwe_exc, - vad_hover_flag, st->vad_flag, *Q_new, *shift ); + vad_hover_flag, st->vad_flag, *Q_new, *shift ); } ELSE { - core_encode_twodiv_fx( new_samples, st,st->coder_type, Aw, vad_hover_flag, Q_new, shift ); + core_encode_twodiv_fx( new_samples, st, st->coder_type, Aw, vad_hover_flag, Q_new, shift ); } /*-----------------------------------------------------------------* * Apply non linearity to the SHB excitation @@ -71,25 +70,24 @@ void enc_acelp_tcx_main_fx( test(); - IF( EQ_16( st->core, ACELP_CORE )&&st->igf!=0) + IF( EQ_16( st->core, ACELP_CORE ) && st->igf != 0 ) { - non_linearity_fx( ptr_bwe_exc, bwe_exc_extended, L_FRAME32k, &hBWE_TD->bwe_non_lin_prev_scale_fx, *Q_new - , st->coder_type, voice_factors, st->L_frame); + non_linearity_fx( ptr_bwe_exc, bwe_exc_extended, L_FRAME32k, &hBWE_TD->bwe_non_lin_prev_scale_fx, *Q_new, st->coder_type, voice_factors, st->L_frame ); /* update the old BWE exe memory */ Copy( &old_bwe_exc[L_FRAME32k], hBWE_TD->old_bwe_exc_fx, PIT16k_MAX * 2 ); } ELSE { - set16_fx(hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); - set16_fx(hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); + set16_fx( hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); + set16_fx( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); hBWE_TD->bwe_non_lin_prev_scale_fx = 0; } } ELSE { /* Run SID Coder */ - IF ( st->core_brate == SID_2k40 ) + IF( st->core_brate == SID_2k40 ) { FdCng_encodeSID_fx( st->hFdCngEnc, st, st->preemph_fac ); } diff --git a/lib_enc/enc_acelpx_fx.c b/lib_enc/enc_acelpx_fx.c index ae65423eb..b24bcd066 100644 --- a/lib_enc/enc_acelpx_fx.c +++ b/lib_enc/enc_acelpx_fx.c @@ -8,17 +8,17 @@ #include "basop_util.h" #include "options.h" #include "rom_enc.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*--------------------------------------------------------------------------------------* * Local constant *--------------------------------------------------------------------------------------*/ -#define _1_Q11 (2048/*1.0f Q11*/) /* 1.0f in 4Q11 */ +#define _1_Q11 ( 2048 /*1.0f Q11*/ ) /* 1.0f in 4Q11 */ /*--------------------------------------------------------------------------------------* - * E_ACELP_update_cor + * E_ACELP_update_cor *--------------------------------------------------------------------------------------*/ static void E_ACELP_update_cor( const Word16 pos[], /* i */ @@ -33,7 +33,7 @@ static void E_ACELP_update_cor( const Word16 *pRx, *pRy; Word16 i, tmp; - IF (EQ_16(nb_pulse, 2)) + IF( EQ_16( nb_pulse, 2 ) ) { /* Update product of autocorrelation and already fixed pulses. with the * two newly found ones */ @@ -42,24 +42,24 @@ static void E_ACELP_update_cor( sign_y = sign[pos[1]]; move16(); - IF (s_xor(sign_x, sign_y) < 0) + IF( s_xor( sign_x, sign_y ) < 0 ) { i = 1; move16(); - if (sign_x > 0) + if ( sign_x > 0 ) { i = 0; move16(); } - pRx = R-pos[i]; - pRy = R-pos[1-i]; + pRx = R - pos[i]; + pRy = R - pos[1 - i]; /* different sign x and y */ - FOR (i=0; i 0) + pRx = R - pos[0]; + pRy = R - pos[1]; + IF( sign_x > 0 ) { /* sign x and y is positive */ - FOR (i=0; i 0) + if ( sgnx > 0 ) { #ifdef BASOP_NOGLOB - alp2_16 = mac_ro(alp2, pR[y], sign[y], &Overflow); /* Qalp = (Q_R=Q_cor)*Q_signval */ + alp2_16 = mac_ro( alp2, pR[y], sign[y], &Overflow ); /* Qalp = (Q_R=Q_cor)*Q_signval */ #else - alp2_16 = mac_r(alp2, pR[y], sign[y]); /* Qalp = (Q_R=Q_cor)*Q_signval */ + alp2_16 = mac_r( alp2, pR[y], sign[y] ); /* Qalp = (Q_R=Q_cor)*Q_signval */ #endif } - if (sgnx < 0) + if ( sgnx < 0 ) { #ifdef BASOP_NOGLOB - alp2_16 = msu_ro(alp2, pR[y], sign[y], &Overflow); /* Qalp = (Q_R=Q_cor)*Q_signval */ + alp2_16 = msu_ro( alp2, pR[y], sign[y], &Overflow ); /* Qalp = (Q_R=Q_cor)*Q_signval */ #else - alp2_16 = msu_r(alp2, pR[y], sign[y]); /* Qalp = (Q_R=Q_cor)*Q_signval */ + alp2_16 = msu_r( alp2, pR[y], sign[y] ); /* Qalp = (Q_R=Q_cor)*Q_signval */ #endif } - alpk[1-ik] = alp2_16; + alpk[1 - ik] = alp2_16; move16(); /*sq = ps2 * ps2; MULT(1);*/ - sq = mult_r(ps2, ps2); /* (3+3)Q -> 6Q9 */ - sqk[1-ik] = sq; + sq = mult_r( ps2, ps2 ); /* (3+3)Q -> 6Q9 */ + sqk[1 - ik] = sq; move16(); /*s = (alpk * sq) - (sqk * alp2); MULT(1);MAC(1);*/ #ifdef BASOP_NOGLOB - s = L_msu_o(L_mult(alpk[ik], sq), sqk[ik], alp2_16, &Overflow); /* Q_sq = Q_sqk, Q_alpk = Q_alp */ + s = L_msu_o( L_mult( alpk[ik], sq ), sqk[ik], alp2_16, &Overflow ); /* Q_sq = Q_sqk, Q_alpk = Q_alp */ #else - s = L_msu(L_mult(alpk[ik], sq), sqk[ik], alp2_16); /* Q_sq = Q_sqk, Q_alpk = Q_alp */ + s = L_msu( L_mult( alpk[ik], sq ), sqk[ik], alp2_16 ); /* Q_sq = Q_sqk, Q_alpk = Q_alp */ #endif - if (s > 0) + if ( s > 0 ) { - ik = sub(1, ik); + ik = sub( 1, ik ); } - if (s > 0) + if ( s > 0 ) { - xy_save = L_mac0(y, x, L_SUBFR); + xy_save = L_mac0( y, x, L_SUBFR ); } - assert( ((s >= 0 && i==0 && y == track_y)) || (y > track_y) || (i > 0)); + assert( ( ( s >= 0 && i == 0 && y == track_y ) ) || ( y > track_y ) || ( i > 0 ) ); } } - ps1 = extract_l(xy_save); - pos[1] = s_and(ps1, L_SUBFR-1); + ps1 = extract_l( xy_save ); + pos[1] = s_and( ps1, L_SUBFR - 1 ); move16(); - pos[0] = lshr(ps1, 6); + pos[0] = lshr( ps1, 6 ); move16(); /* Update numerator */ - *ps = add(add(ps0,dn[pos[0]]),dn[pos[1]]); + *ps = add( add( ps0, dn[pos[0]] ), dn[pos[1]] ); move16(); /* Update denominator */ *alp = alpk[ik]; move16(); - E_ACELP_update_cor(pos, 2, sign, R, cor, cor); + E_ACELP_update_cor( pos, 2, sign, R, cor, cor ); *ix = pos[0]; move16(); *iy = pos[1]; move16(); - assert(((pos[0] & 3) == track_x) && ((pos[1] & 3) == track_y)); /* sanity check */ + assert( ( ( pos[0] & 3 ) == track_x ) && ( ( pos[1] & 3 ) == track_y ) ); /* sanity check */ } /*--------------------------------------------------------------------------------------* @@ -300,15 +299,14 @@ static void E_ACELP_2pulse_searchx( *--------------------------------------------------------------------------------------*/ static void E_ACELP_1pulse_searchx( UWord8 tracks[2], - Word16 *R, - Word16 *ps, + Word16 *R, + Word16 *ps, Word16 *alp, - Word16 *ix, + Word16 *ix, Word16 dn[], - Word16 cor[], - Word16 sign[], - Word16 sign_val_1 -) + Word16 cor[], + Word16 sign[], + Word16 sign_val_1 ) { Word16 x, x_save = 0; Word16 ps0; @@ -325,8 +323,8 @@ static void E_ACELP_1pulse_searchx( /*alp0 = *alp + R[0]; INDIRECT(1);*/ ps0 = *ps; move16(); - alp0 = L_deposit_h(*alp); - alp0 = L_mac(alp0, R[0], sign_val_1); /* Qalp = (Q_R=Q_cor)*Q_signval */ + alp0 = L_deposit_h( *alp ); + alp0 = L_mac( alp0, R[0], sign_val_1 ); /* Qalp = (Q_R=Q_cor)*Q_signval */ /* Ensure that in the loop below s > 0 in the first iteration, the actual values do not matter. */ move16(); @@ -336,9 +334,9 @@ static void E_ACELP_1pulse_searchx( ik = 0; move16(); #ifdef BASOP_NOGLOB - if (mac_ro(alp0, cor[tracks[0]], sign[tracks[0]], &Overflow) < 0) + if ( mac_ro( alp0, cor[tracks[0]], sign[tracks[0]], &Overflow ) < 0 ) #else - if (mac_r(alp0, cor[tracks[0]], sign[tracks[0]]) < 0) + if ( mac_r( alp0, cor[tracks[0]], sign[tracks[0]] ) < 0 ) #endif { sqk[0] = 1; @@ -349,53 +347,53 @@ static void E_ACELP_1pulse_searchx( move16(); ntracks = 1; - if (NE_16(tracks[1], tracks[0])) + if ( NE_16( tracks[1], tracks[0] ) ) { ntracks = 2; move16(); } - FOR (t=0; t 0) + if ( s > 0 ) { - ik = sub(1, ik); + ik = sub( 1, ik ); } - if (s > 0) + if ( s > 0 ) { x_save = x; move16(); } - assert( t>0 || ((s >= 0) && (x == tracks[t])) || x > tracks[t]); + assert( t > 0 || ( ( s >= 0 ) && ( x == tracks[t] ) ) || x > tracks[t] ); } } - *ps = add(ps0, dn[x_save]); + *ps = add( ps0, dn[x_save] ); move16(); *alp = alpk[ik]; move16(); @@ -409,17 +407,16 @@ static void E_ACELP_1pulse_searchx( * Algorithm is identical to traditional covariance method *--------------------------------------------------------------------------------------*/ void E_ACELP_4tsearchx_fx( - Word16 dn[], - const Word16 cn[], - Word16 Rw[], - Word16 code[], - const PulseConfig *config, - Word16 ind[] -) + Word16 dn[], + const Word16 cn[], + Word16 Rw[], + Word16 code[], + const PulseConfig *config, + Word16 ind[] ) { Word16 sign[L_SUBFR], vec[L_SUBFR]; Word16 cor[L_SUBFR]; - Word16 R_buf[2*L_SUBFR-1], *R; + Word16 R_buf[2 * L_SUBFR - 1], *R; Word16 dn2[L_SUBFR]; Word16 ps2k, ps /* same format as dn[] */, ps2, alpk, alp = 0 /* Q13 and later Q_Rw*Q_signval=Q_cor*Q_signval */; Word32 s; @@ -432,18 +429,18 @@ void E_ACELP_4tsearchx_fx( Word16 sign_val_1, sign_val_2; Word16 nb_pulse, nb_pulse_m2; - ps = 0; /* to avoid compilation warnings */ + ps = 0; /* to avoid compilation warnings */ - - alp = config->alp; /* Q13 */ move16(); + alp = config->alp; /* Q13 */ + move16(); nb_pulse = config->nb_pulse; move16(); move16(); - nb_pulse_m2 = sub(nb_pulse, 2); + nb_pulse_m2 = sub( nb_pulse, 2 ); /* Init to avoid crash when the search does not find a solution */ - FOR (k=0; knbiter; k++) + FOR( k = 0; k < config->nbiter; k++ ) { - E_ACELP_setup_pulse_search_pos(config, k, ipos); + E_ACELP_setup_pulse_search_pos( config, k, ipos ); /* index to first non-fixed position */ pos = config->fixedpulses; move16(); - IF (config->fixedpulses == 0)/* 1100, 11, 1110, 1111, 2211 */ + IF( config->fixedpulses == 0 ) /* 1100, 11, 1110, 1111, 2211 */ { ps = 0; move16(); alp = 0; move16(); - set16_fx(cor, 0, L_SUBFR); + set16_fx( cor, 0, L_SUBFR ); } ELSE { - assert(config->fixedpulses == 2 || config->fixedpulses == 4); + assert( config->fixedpulses == 2 || config->fixedpulses == 4 ); /* set fixed positions */ - FOR (i=0; ifixedpulses, sign, R, NULL, cor); + E_ACELP_update_cor( ind, config->fixedpulses, sign, R, NULL, cor ); /* normalisation contribution of fixed part */ - s = L_mult0(cor[ind[0]], sign[ind[0]]); + s = L_mult0( cor[ind[0]], sign[ind[0]] ); ps = dn[ind[0]]; move16(); - FOR (i=1; i>1 sign = 2*/ + alp = round_fx( s ); /*mac0 >>1 sign = 2*/ } /* other stages of 2 pulses */ st = 0; move16(); - FOR (j = pos; j < nb_pulse; j += 2) + FOR( j = pos; j < nb_pulse; j += 2 ) { - IF (GE_16(nb_pulse_m2, j)) /* pair-wise search */ + IF( GE_16( nb_pulse_m2, j ) ) /* pair-wise search */ { /* * Calculate correlation of all possible positions @@ -589,34 +586,33 @@ void E_ACELP_4tsearchx_fx( * Each pulse can have 16 possible positions. */ - E_ACELP_2pulse_searchx(config->nbpos[st], ipos[j], ipos[j + 1], R, &ps, &alp, - &ind[j], &ind[j+1], dn, dn2_pos, cor, sign, sign_val_2); - + E_ACELP_2pulse_searchx( config->nbpos[st], ipos[j], ipos[j + 1], R, &ps, &alp, + &ind[j], &ind[j + 1], dn, dn2_pos, cor, sign, sign_val_2 ); } ELSE /* single pulse search */ { - E_ACELP_1pulse_searchx(&ipos[j], R, &ps, &alp, - &ind[j], dn, cor, sign, sign_val_1); + E_ACELP_1pulse_searchx( &ipos[j], R, &ps, &alp, + &ind[j], dn, cor, sign, sign_val_1 ); } - st = add(st, 1); + st = add( st, 1 ); } /* memorise the best codevector */ /*ps2 = ps * ps; MULT(1);*/ - ps2 = mult(ps, ps); + ps2 = mult( ps, ps ); /*s = (alpk * ps2) - (ps2k * alp); MULT(2);ADD(1);*/ - s = L_msu(L_mult(alpk, ps2), ps2k, alp); + s = L_msu( L_mult( alpk, ps2 ), ps2k, alp ); - IF (s > 0) + IF( s > 0 ) { ps2k = ps2; move16(); alpk = alp; move16(); - Copy(ind, codvec, nb_pulse); + Copy( ind, codvec, nb_pulse ); } } @@ -624,5 +620,5 @@ void E_ACELP_4tsearchx_fx( /* * Store weighted energy of code, build the codeword and index of codevector. */ - E_ACELP_build_code(nb_pulse, codvec, sign, code, ind); + E_ACELP_build_code( nb_pulse, codvec, sign, code, ind ); } diff --git a/lib_enc/enc_amr_wb_fx.c b/lib_enc/enc_amr_wb_fx.c index 461b742af..492dd620d 100644 --- a/lib_enc/enc_amr_wb_fx.c +++ b/lib_enc/enc_amr_wb_fx.c @@ -2,15 +2,15 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ //#include "prot_fx.h" /* Function prototypes */ -#include "rom_com_fx.h" /* Static table prototypes */ +#include "rom_com_fx.h" /* Static table prototypes */ #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ -#include "basop_util.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ +#include "basop_util.h" /* Function prototypes */ /*-------------------------------------------------------------------* * encod_amr_wb() @@ -18,40 +18,39 @@ * Encode excitation signal in AMR-WB IO mode *-------------------------------------------------------------------*/ void encod_amr_wb_fx( - Encoder_State *st, /* i/o: state structure */ - const Word16 speech[], /* i : input speech */ - const Word16 Aw[], /* i : weighted A(z) unquantized for subframes */ - const Word16 Aq[], /* i : 12k8 Lp coefficient */ - const Word16 *res, /* i : residual signal */ - Word16 *syn, /* i/o: core synthesis */ - Word16 *exc, /* i/o: current non-enhanced excitation */ - Word16 *exc2, /* i/o: current enhanced excitation */ - Word16 *pitch_buf, /* i/o: floating pitch values for each subframe */ - Word16 hf_gain_fx[NB_SUBFR],/* o : decoded HF gain */ - const Word16 *speech16k_fx, /* i : input speech @16kHz */ + Encoder_State *st, /* i/o: state structure */ + const Word16 speech[], /* i : input speech */ + const Word16 Aw[], /* i : weighted A(z) unquantized for subframes */ + const Word16 Aq[], /* i : 12k8 Lp coefficient */ + const Word16 *res, /* i : residual signal */ + Word16 *syn, /* i/o: core synthesis */ + Word16 *exc, /* i/o: current non-enhanced excitation */ + Word16 *exc2, /* i/o: current enhanced excitation */ + Word16 *pitch_buf, /* i/o: floating pitch values for each subframe */ + Word16 hf_gain_fx[NB_SUBFR], /* o : decoded HF gain */ + const Word16 *speech16k_fx, /* i : input speech @16kHz */ Word16 shift, - Word16 Q_new -) + Word16 Q_new ) { - Word16 xn[L_SUBFR]; /* Target vector for pitch search */ - Word16 xn2[L_SUBFR]; /* Target vector for codebook search */ - Word16 cn[L_SUBFR]; /* Target vector in residual domain */ - Word16 h1[L_SUBFR+(M+1)]; /* Impulse response vector */ - Word16 h2[L_SUBFR+(M+1)]; /* Impulse response vector */ - Word16 code[L_SUBFR]; /* Fixed codebook excitation */ - Word16 y1[L_SUBFR]; /* Filtered adaptive excitation */ - Word16 y2[L_SUBFR]; /* Filtered algebraic excitation */ - Word16 gain_pit ; /* Pitch gain */ - Word16 voice_fac; /* Voicing factor */ - Word32 gain_code; /* Gain of code */ - Word16 gain_inov; /* inovation gain */ - Word16 i, i_subfr; /* tmp variables */ - Word16 T0, T0_frac; /* close loop integer pitch and fractional part */ - Word16 T0_min, T0_max; /* pitch variables */ - Word16 *pt_pitch; /* pointer to floating pitch buffer */ - Word16 g_corr[10]; /* ACELP correl, values + gain pitch */ - Word16 clip_gain; /* LSF clip gain */ - const Word16 *p_Aw, *p_Aq; /* pointer to LP filter coeff. vector*/ + Word16 xn[L_SUBFR]; /* Target vector for pitch search */ + Word16 xn2[L_SUBFR]; /* Target vector for codebook search */ + Word16 cn[L_SUBFR]; /* Target vector in residual domain */ + Word16 h1[L_SUBFR + ( M + 1 )]; /* Impulse response vector */ + Word16 h2[L_SUBFR + ( M + 1 )]; /* Impulse response vector */ + Word16 code[L_SUBFR]; /* Fixed codebook excitation */ + Word16 y1[L_SUBFR]; /* Filtered adaptive excitation */ + Word16 y2[L_SUBFR]; /* Filtered algebraic excitation */ + Word16 gain_pit; /* Pitch gain */ + Word16 voice_fac; /* Voicing factor */ + Word32 gain_code; /* Gain of code */ + Word16 gain_inov; /* inovation gain */ + Word16 i, i_subfr; /* tmp variables */ + Word16 T0, T0_frac; /* close loop integer pitch and fractional part */ + Word16 T0_min, T0_max; /* pitch variables */ + Word16 *pt_pitch; /* pointer to floating pitch buffer */ + Word16 g_corr[10]; /* ACELP correl, values + gain pitch */ + Word16 clip_gain; /* LSF clip gain */ + const Word16 *p_Aw, *p_Aq; /* pointer to LP filter coeff. vector*/ Word16 unbits; Word32 norm_gain_code; Word16 pitch_limit_flag; @@ -60,7 +59,7 @@ void encod_amr_wb_fx( Word16 gcode16; Word32 Ltmp; Word32 Lgcode; - Word16 T_op[3]; /* pitch period for quantization */ + Word16 T_op[3]; /* pitch period for quantization */ Word16 lp_select, lp_flag; VAD_HANDLE hVAD = st->hVAD; AMRWB_IO_ENC_HANDLE hAmrwb_IO = st->hAmrwb_IO; @@ -89,19 +88,19 @@ void encod_amr_wb_fx( p_Aw = Aw; p_Aq = Aq; pt_pitch = pitch_buf; - shift_wsp = add(Q_new,shift); + shift_wsp = add( Q_new, shift ); - Copy(st->pitch_fx, T_op, 2 ); - if (LE_16(T_op[0],PIT_MIN)) + Copy( st->pitch_fx, T_op, 2 ); + if ( LE_16( T_op[0], PIT_MIN ) ) { - T_op[0] = shl(T_op[0],1); + T_op[0] = shl( T_op[0], 1 ); move16(); } - if (LE_16(T_op[1],PIT_MIN)) + if ( LE_16( T_op[1], PIT_MIN ) ) { /*T_op[1] *= 2;*/ - T_op[1] = shl(T_op[1],1); + T_op[1] = shl( T_op[1], 1 ); move16(); } st->acelp_cfg.fcb_mode = 0; /* flag used in inov_encode() */ @@ -111,16 +110,16 @@ void encod_amr_wb_fx( *-----------------------------------------------------------------*/ lp_flag = NORMAL_OPERATION; - if (LT_32(st->core_brate, ACELP_11k60)) + if ( LT_32( st->core_brate, ACELP_11k60 ) ) { lp_flag = LOW_PASS; move16(); } - + /*------------------------------------------------------------------* * ACELP subframe loop *------------------------------------------------------------------*/ - FOR ( i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR ) + FOR( i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR ) { /*----------------------------------------------------------------* * Bandwidth expansion of A(z) filter coefficients @@ -133,33 +132,32 @@ void encod_amr_wb_fx( find_targets_fx( speech, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq, res, L_SUBFR, p_Aw, TILT_FAC_FX, xn, cn, h1 ); - Copy_Scale_sig(h1, h2, L_SUBFR, -2); - Scale_sig(h1, L_SUBFR, add(1, shift)); /* set h1[] in Q14 with scaling for convolution */ + Copy_Scale_sig( h1, h2, L_SUBFR, -2 ); + Scale_sig( h1, L_SUBFR, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution */ /* scaling of xn[] to limit dynamic at 12 bits */ - Scale_sig(xn, L_SUBFR, shift); + Scale_sig( xn, L_SUBFR, shift ); /*----------------------------------------------------------------* * Close-loop pitch search and quantization * Adaptive exc. construction *----------------------------------------------------------------*/ - *pt_pitch = pit_encode_fx(hBstr, st->acelp_cfg.pitch_bits, st->core_brate, 1, L_FRAME, -1, &pitch_limit_flag, i_subfr, exc, - L_SUBFR, T_op, &T0_min, &T0_max, &T0, &T0_frac, h1, xn - , 0 /*hStereoTD->tdm_Pitch_reuse_flag*/, NULL /*hStereoTD->tdm_Pri_pitch_buf*/); + *pt_pitch = pit_encode_fx( hBstr, st->acelp_cfg.pitch_bits, st->core_brate, 1, L_FRAME, -1, &pitch_limit_flag, i_subfr, exc, + L_SUBFR, T_op, &T0_min, &T0_max, &T0, &T0_frac, h1, xn, 0 /*hStereoTD->tdm_Pitch_reuse_flag*/, NULL /*hStereoTD->tdm_Pri_pitch_buf*/ ); /*-----------------------------------------------------------------* * Find adaptive exitation *-----------------------------------------------------------------*/ - pred_lt4(&exc[i_subfr], &exc[i_subfr], T0, T0_frac, L_SUBFR+1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP); + pred_lt4( &exc[i_subfr], &exc[i_subfr], T0, T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); /*-----------------------------------------------------------------* * Gain clipping test to avoid unstable synthesis on frame erasure * or in case of floating point encoder & fixed p. decoder *-----------------------------------------------------------------*/ - clip_gain = gp_clip_fx(st->element_mode, st->core_brate, st->voicing_fx, i_subfr, 0, xn, st->clip_var_fx, sub(shift_wsp,1)); + clip_gain = gp_clip_fx( st->element_mode, st->core_brate, st->voicing_fx, i_subfr, 0, xn, st->clip_var_fx, sub( shift_wsp, 1 ) ); /*-----------------------------------------------------------------* * LP filtering of the adaptive excitation, codebook target computation @@ -168,9 +166,9 @@ void encod_amr_wb_fx( lp_select = lp_filt_exc_enc_fx( MODE1, -1, i_subfr, exc, h1, xn, y1, xn2, L_SUBFR, L_FRAME, g_corr, clip_gain, &gain_pit, &lp_flag ); - IF( EQ_16(lp_flag,NORMAL_OPERATION)) + IF( EQ_16( lp_flag, NORMAL_OPERATION ) ) { - push_indice_fx(hBstr, IND_LP_FILT_SELECT, lp_select, 1 ); + push_indice_fx( hBstr, IND_LP_FILT_SELECT, lp_select, 1 ); } /*-----------------------------------------------------------------* @@ -183,26 +181,26 @@ void encod_amr_wb_fx( * Pitch gain clipping test * Estimate spectrum tilt and voicing *-----------------------------------------------------------------*/ - gain_enc_amr_wb_fx(hBstr, xn, shift_wsp, y1, y2, code, st->core_brate, &gain_pit, &gain_code, + gain_enc_amr_wb_fx( hBstr, xn, shift_wsp, y1, y2, code, st->core_brate, &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain, hAmrwb_IO->past_qua_en_fx ); - gp_clip_test_gain_pit_fx(st->element_mode, st->core_brate, gain_pit, st->clip_var_fx ); + gp_clip_test_gain_pit_fx( st->element_mode, st->core_brate, gain_pit, st->clip_var_fx ); #ifdef BASOP_NOGLOB - Lgcode = L_shl_o(gain_code, Q_new, &Overflow); /* scaled gain_code with Qnew -> Q16*/ - gcode16 = round_fx_o(Lgcode, &Overflow); -#else /* BASOP_NOGLOB */ - Lgcode = L_shl(gain_code, Q_new); /* scaled gain_code with Qnew -> Q16*/ - gcode16 = round_fx(Lgcode); + Lgcode = L_shl_o( gain_code, Q_new, &Overflow ); /* scaled gain_code with Qnew -> Q16*/ + gcode16 = round_fx_o( Lgcode, &Overflow ); +#else /* BASOP_NOGLOB */ + Lgcode = L_shl( gain_code, Q_new ); /* scaled gain_code with Qnew -> Q16*/ + gcode16 = round_fx( Lgcode ); #endif /* BASOP_NOGLOB */ - hLPDmem->tilt_code = Est_tilt2( exc+i_subfr, gain_pit, code, Lgcode, &voice_fac, shift ); + hLPDmem->tilt_code = Est_tilt2( exc + i_subfr, gain_pit, code, Lgcode, &voice_fac, shift ); - FOR (i = 0; i < L_SUBFR; i++) + FOR( i = 0; i < L_SUBFR; i++ ) { #ifdef BASOP_NOGLOB - exc2[i+i_subfr] = round_fx_o(L_shl_o(L_mult(gain_pit,exc[i+i_subfr]),1, &Overflow), &Overflow); -#else /* BASOP_NOGLOB */ - exc2[i+i_subfr] = round_fx(L_shl(L_mult(gain_pit,exc[i+i_subfr]),1)); + exc2[i + i_subfr] = round_fx_o( L_shl_o( L_mult( gain_pit, exc[i + i_subfr] ), 1, &Overflow ), &Overflow ); +#else /* BASOP_NOGLOB */ + exc2[i + i_subfr] = round_fx( L_shl( L_mult( gain_pit, exc[i + i_subfr] ), 1 ) ); #endif /* BASOP_NOGLOB */ } @@ -211,37 +209,37 @@ void encod_amr_wb_fx( *-----------------------------------------------------------------*/ /*st->mem_w0 = xn[L_SUBFR-1] - gain_pit * y1[L_SUBFR-1] - gain_code * y2[L_SUBFR-1];*/ - Ltmp = L_mult(gcode16, y2[L_SUBFR - 1]); - Ltmp = L_shl(Ltmp, add(5, shift)); - Ltmp = L_negate(Ltmp); - Ltmp = L_mac(Ltmp, xn[L_SUBFR - 1], 16384); - Ltmp = L_msu(Ltmp, y1[L_SUBFR - 1], gain_pit); + Ltmp = L_mult( gcode16, y2[L_SUBFR - 1] ); + Ltmp = L_shl( Ltmp, add( 5, shift ) ); + Ltmp = L_negate( Ltmp ); + Ltmp = L_mac( Ltmp, xn[L_SUBFR - 1], 16384 ); + Ltmp = L_msu( Ltmp, y1[L_SUBFR - 1], gain_pit ); #ifdef BASOP_NOGLOB Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) ); - hLPDmem->mem_w0 = round_fx_sat(Ltmp); /*Q_new-1 */ + hLPDmem->mem_w0 = round_fx_sat( Ltmp ); /*Q_new-1 */ #else - Ltmp = L_shl(Ltmp, sub(1, shift)); - hLPDmem->mem_w0 = round_fx(Ltmp); /*Q_new-1 */ + Ltmp = L_shl( Ltmp, sub( 1, shift ) ); + hLPDmem->mem_w0 = round_fx( Ltmp ); /*Q_new-1 */ #endif /*-----------------------------------------------------------------* * Find the total excitation *-----------------------------------------------------------------*/ - FOR (i = 0; i < L_SUBFR; i++) + FOR( i = 0; i < L_SUBFR; i++ ) { - L_tmp = L_mult(gcode16, code[i]); + L_tmp = L_mult( gcode16, code[i] ); #ifdef BASOP_NOGLOB L_tmp = L_shl_sat( L_tmp, 5 ); L_tmp = L_mac_sat( L_tmp, exc[i + i_subfr], gain_pit ); #else - L_tmp = L_shl(L_tmp, 5); - L_tmp = L_mac(L_tmp, exc[i + i_subfr], gain_pit); + L_tmp = L_shl( L_tmp, 5 ); + L_tmp = L_mac( L_tmp, exc[i + i_subfr], gain_pit ); #endif #ifdef BASOP_NOGLOB - L_tmp = L_shl_o(L_tmp, 1, &Overflow); /* saturation can occur here */ - exc[i + i_subfr] = round_fx_o(L_tmp, &Overflow); + L_tmp = L_shl_o( L_tmp, 1, &Overflow ); /* saturation can occur here */ + exc[i + i_subfr] = round_fx_o( L_tmp, &Overflow ); #else /* BASOP_NOGLOB */ - L_tmp = L_shl(L_tmp, 1); /* saturation can occur here */ - exc[i + i_subfr] = round_fx(L_tmp); + L_tmp = L_shl( L_tmp, 1 ); /* saturation can occur here */ + exc[i + i_subfr] = round_fx( L_tmp ); #endif } @@ -249,26 +247,26 @@ void encod_amr_wb_fx( * Synthesize speech to update mem_syn[] * Update A(z) filters *-----------------------------------------------------------------*/ - Syn_filt_s(1, p_Aq, M, &exc[i_subfr], &syn[i_subfr], L_SUBFR, hLPDmem->mem_syn, 1 ); + Syn_filt_s( 1, p_Aq, M, &exc[i_subfr], &syn[i_subfr], L_SUBFR, hLPDmem->mem_syn, 1 ); /*-----------------------------------------------------------------* * HF gain modification factors at 23.85 kbps *-----------------------------------------------------------------*/ - IF ( EQ_32(st->core_brate,ACELP_23k85)) + IF( EQ_32( st->core_brate, ACELP_23k85 ) ) { - IF( GE_32(st->input_Fs,16000)) + IF( GE_32( st->input_Fs, 16000 ) ) { - hf_cod_fx( st->core_brate, &speech16k_fx[i_subfr * L_SUBFR16k/L_SUBFR], Aq, &exc[i_subfr], &syn[i_subfr], + hf_cod_fx( st->core_brate, &speech16k_fx[i_subfr * L_SUBFR16k / L_SUBFR], Aq, &exc[i_subfr], &syn[i_subfr], &hAmrwb_IO->seed2_enc, hAmrwb_IO->mem_hp400_enc_fx, hAmrwb_IO->mem_syn_hf_enc_fx, hAmrwb_IO->mem_hf_enc_fx, hAmrwb_IO->mem_hf2_enc_fx, - hVAD->hangover_cnt, &hAmrwb_IO->gain_alpha_fx, &hf_gain_fx[i_subfr/L_SUBFR], add(Q_new,1), st->Q_syn); + hVAD->hangover_cnt, &hAmrwb_IO->gain_alpha_fx, &hf_gain_fx[i_subfr / L_SUBFR], add( Q_new, 1 ), st->Q_syn ); } - push_indice_fx(hBstr, IND_HF_GAIN_MODIFICATION, hf_gain_fx[i_subfr/L_SUBFR], 4 ); + push_indice_fx( hBstr, IND_HF_GAIN_MODIFICATION, hf_gain_fx[i_subfr / L_SUBFR], 4 ); } - p_Aw += (M+1); - p_Aq += (M+1); + p_Aw += ( M + 1 ); + p_Aq += ( M + 1 ); pt_pitch++; } diff --git a/lib_enc/enc_gain_fx.c b/lib_enc/enc_gain_fx.c index fcfe02219..8cd87ad10 100644 --- a/lib_enc/enc_gain_fx.c +++ b/lib_enc/enc_gain_fx.c @@ -11,12 +11,11 @@ #include "rom_com.h" #include "rom_enc.h" #include "basop_util.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ -void E_GAIN_norm_corr(Word16 exc[], Word16 xn[], Word16 h[], - Word16 t_min, Word16 t_max, Word16 corr_norm[], Word16 L_subfr); +void E_GAIN_norm_corr( Word16 exc[], Word16 xn[], Word16 h[], Word16 t_min, Word16 t_max, Word16 corr_norm[], Word16 L_subfr ); /* * E_GAIN_norm_corr @@ -38,29 +37,28 @@ void E_GAIN_norm_corr(Word16 exc[], Word16 xn[], Word16 h[], * Returns: * void */ -void E_GAIN_norm_corr(Word16 exc[], Word16 xn[], Word16 h[], - Word16 t_min, Word16 t_max, Word16 corr_norm[], Word16 L_subfr) +void E_GAIN_norm_corr( Word16 exc[], Word16 xn[], Word16 h[], Word16 t_min, Word16 t_max, Word16 corr_norm[], Word16 L_subfr ) { - Word16 excf[L_SUBFR]; /* filtered past excitation (Q_new+shift-1) */ + Word16 excf[L_SUBFR]; /* filtered past excitation (Q_new+shift-1) */ Word16 ps, norm, exp_alp, exp_ps, scale, L_subfr2; Word16 t, j, k; Word32 L_tmp, L_tmp2; - k = negate(t_min); - L_subfr2 = shr(L_subfr, 1); + k = negate( t_min ); + L_subfr2 = shr( L_subfr, 1 ); /* compute the filtered excitation for the first delay t_min */ - E_UTIL_f_convolve(&exc[k], h, excf,L_subfr); + E_UTIL_f_convolve( &exc[k], h, excf, L_subfr ); /* Compute rounded down 1/sqrt(energy of xn[]) */ - Dot_product12_offs(xn, xn, L_subfr, &scale, 1); + Dot_product12_offs( xn, xn, L_subfr, &scale, 1 ); - scale = add(scale, 2+1); /* energy of xn[] x 2 + rounded up */ - scale = negate(shr(scale, 1)); /* (1< 0; j--) + FOR( j = L_subfr - 1; j > 0; j-- ) { /*excf[j] = excf[j - 1] + exc[k] * h[j]; MAC(1); STORE(1);*/ /* saturation can occur in add() */ - excf[j] = add(mult_r(exc[k], h[j]), excf[j - 1]); + excf[j] = add( mult_r( exc[k], h[j] ), excf[j - 1] ); move16(); - } - excf[0] = mult_r(exc[k],h[0]); + excf[0] = mult_r( exc[k], h[0] ); move16(); } /* Last reduced iteration for t=t_max */ - L_tmp = Dot_product12_offs(xn, excf, L_subfr, &exp_ps, 1); - ps = extract_h(L_tmp); + L_tmp = Dot_product12_offs( xn, excf, L_subfr, &exp_ps, 1 ); + ps = extract_h( L_tmp ); /* Compute 1/sqrt(energy of excf[]) */ - L_tmp = Dot_product12_offs(excf, excf, L_subfr2, NULL, 1); - L_tmp2 = Dot_product12_offs(excf+L_subfr2, excf+L_subfr2, L_subfr2, NULL, 1); - exp_alp = sub(s_min(norm_l(L_tmp), norm_l(L_tmp2)), 1); - L_tmp = L_add(L_shl(L_tmp, exp_alp), L_shl(L_tmp2, exp_alp)); - exp_alp = sub(31+1, exp_alp); + L_tmp = Dot_product12_offs( excf, excf, L_subfr2, NULL, 1 ); + L_tmp2 = Dot_product12_offs( excf + L_subfr2, excf + L_subfr2, L_subfr2, NULL, 1 ); + exp_alp = sub( s_min( norm_l( L_tmp ), norm_l( L_tmp2 ) ), 1 ); + L_tmp = L_add( L_shl( L_tmp, exp_alp ), L_shl( L_tmp2, exp_alp ) ); + exp_alp = sub( 31 + 1, exp_alp ); /*norm = (Float32)(1.0F / sqrt(alp)); SQRT(1);*/ - L_tmp = ISqrt32(L_tmp, &exp_alp); - norm = extract_h(L_tmp); + L_tmp = ISqrt32( L_tmp, &exp_alp ); + norm = extract_h( L_tmp ); /* Normalize correlation = correlation * (1/sqrt(energy)) */ /*corr_norm[t-t_min] = ps * norm; MULT(1); STORE(1);*/ - L_tmp = L_mult(ps, norm); - L_tmp = L_shl(L_tmp, add(add(exp_ps, exp_alp), scale)); - corr_norm[t-t_min] = round_fx(L_tmp); + L_tmp = L_mult( ps, norm ); + L_tmp = L_shl( L_tmp, add( add( exp_ps, exp_alp ), scale ) ); + corr_norm[t - t_min] = round_fx( L_tmp ); return; } @@ -145,15 +142,15 @@ void E_GAIN_norm_corr(Word16 exc[], Word16 xn[], Word16 h[], * Returns: * interpolated value */ -static Word16 E_GAIN_norm_corr_interpolate(Word16 *x, Word16 frac) +static Word16 E_GAIN_norm_corr_interpolate( Word16 *x, Word16 frac ) { Word16 *x1, *x2, i; const Word16 *c1, *c2; Word32 s; - IF (frac < 0) + IF( frac < 0 ) { - frac = add(frac,4); + frac = add( frac, 4 ); x--; } @@ -167,27 +164,27 @@ static Word16 E_GAIN_norm_corr_interpolate(Word16 *x, Word16 frac) s += x1[-2] * c1[8] + x2[2] * c2[8]; s += x1[-3] * c1[12] + x2[3] * c2[12];*/ - s = L_deposit_l(0); - FOR (i = 0; i < 4; i++) + s = L_deposit_l( 0 ); + FOR( i = 0; i < 4; i++ ) { - s = L_mac(s,*x1--,*c1); - s = L_mac(s,*x2++,*c2); + s = L_mac( s, *x1--, *c1 ); + s = L_mac( s, *x2++, *c2 ); c1 += 4; c2 += 4; } - return round_fx(L_shl(s, 1)); + return round_fx( L_shl( s, 1 ) ); } -static Word16 E_GAIN_norm_corr_interpolate6(Word16 *x, Word16 frac) +static Word16 E_GAIN_norm_corr_interpolate6( Word16 *x, Word16 frac ) { Word16 *x1, *x2, i; const Word16 *c1, *c2; Word32 s; - IF (frac < 0) + IF( frac < 0 ) { - frac = add(frac,6); + frac = add( frac, 6 ); x--; } @@ -200,16 +197,16 @@ static Word16 E_GAIN_norm_corr_interpolate6(Word16 *x, Word16 frac) s += x1[-1] * c1[6] + x2[1] * c2[6]; s += x1[-2] * c1[12] + x2[2] * c2[12]; s += x1[-3] * c1[18] + x2[3] * c2[18];*/ - s = L_deposit_l(0); - FOR (i = 0; i < 4; i++) + s = L_deposit_l( 0 ); + FOR( i = 0; i < 4; i++ ) { - s = L_mac(s,*x1--,*c1); - s = L_mac(s,*x2++,*c2); + s = L_mac( s, *x1--, *c1 ); + s = L_mac( s, *x2++, *c2 ); c1 += 6; c2 += 6; } - return round_fx(L_shl(s, 1)); + return round_fx( L_shl( s, 1 ) ); } /* @@ -233,10 +230,22 @@ static Word16 E_GAIN_norm_corr_interpolate6(Word16 *x, Word16 frac) * Returns: * chosen integer pitch lag */ -Word16 E_GAIN_closed_loop_search_fx(Word16 exc[], - Word16 xn[], Word16 h[], - Word16 t0_min, Word16 t0_min_frac, Word16 t0_max, Word16 t0_max_frac, Word16 t0_min_max_res, Word16 *pit_frac, Word16 *pit_res, Word16 pit_res_max, - Word16 i_subfr, Word16 pit_min, Word16 pit_fr2, Word16 pit_fr1, Word16 L_subfr) +Word16 E_GAIN_closed_loop_search_fx( Word16 exc[], + Word16 xn[], + Word16 h[], + Word16 t0_min, + Word16 t0_min_frac, + Word16 t0_max, + Word16 t0_max_frac, + Word16 t0_min_max_res, + Word16 *pit_frac, + Word16 *pit_res, + Word16 pit_res_max, + Word16 i_subfr, + Word16 pit_min, + Word16 pit_fr2, + Word16 pit_fr1, + Word16 L_subfr ) { Word16 corr_v[32 + 2 * L_INTERPOL1 + 1]; Word16 cor_max, max, temp; @@ -244,50 +253,49 @@ Word16 E_GAIN_closed_loop_search_fx(Word16 exc[], Word16 i, fraction, frac1, frac2, step; Word16 t0, t_min, t_max; - set16_fx(corr_v, 0, 32 + 2 * L_INTERPOL1 + 1); + set16_fx( corr_v, 0, 32 + 2 * L_INTERPOL1 + 1 ); /* Find interval to compute normalized correlation */ - if (t0_min_frac>0) + if ( t0_min_frac > 0 ) { - t0_min = add(t0_min,1); + t0_min = add( t0_min, 1 ); } - t_min = sub(t0_min,L_INTERPOL1); - t_max = add(t0_max,L_INTERPOL1); + t_min = sub( t0_min, L_INTERPOL1 ); + t_max = add( t0_max, L_INTERPOL1 ); /* allocate memory to normalized correlation vector */ - corr = &corr_v[negate(t_min)]; /* corr[t_min..t_max] */ + corr = &corr_v[negate( t_min )]; /* corr[t_min..t_max] */ /* Compute normalized correlation between target and filtered excitation */ - E_GAIN_norm_corr(exc, xn, h, t_min, t_max, corr_v, L_subfr); + E_GAIN_norm_corr( exc, xn, h, t_min, t_max, corr_v, L_subfr ); /* find integer pitch */ max = corr[t0_min]; move16(); - t0 = t0_min; + t0 = t0_min; move16(); - FOR(i = t0_min + 1; i <= t0_max; i++) + FOR( i = t0_min + 1; i <= t0_max; i++ ) { BASOP_SATURATE_WARNING_OFF_EVS; - if( GE_16(corr[i],max)) + if ( GE_16( corr[i], max ) ) { t0 = i; move16(); } - max = s_max(max, corr[i]); + max = s_max( max, corr[i] ); BASOP_SATURATE_WARNING_ON_EVS; } - /* If first subframe and t0 >= pit_fr1, do not search fractionnal pitch */ test(); - IF((i_subfr == 0) && GE_16(t0,pit_fr1)) + IF( ( i_subfr == 0 ) && GE_16( t0, pit_fr1 ) ) { *pit_frac = 0; move16(); *pit_res = 1; move16(); - return(t0); + return ( t0 ); } @@ -297,26 +305,26 @@ Word16 E_GAIN_closed_loop_search_fx(Word16 exc[], * the interpolated normalized correlation. */ - IF ( EQ_16(t0_min_max_res,shr(pit_res_max,1))) + IF( EQ_16( t0_min_max_res, shr( pit_res_max, 1 ) ) ) { - t0_min_frac = shl(t0_min_frac,1); - t0_max_frac = shl(t0_max_frac,1); + t0_min_frac = shl( t0_min_frac, 1 ); + t0_max_frac = shl( t0_max_frac, 1 ); } step = 1; - frac1 = sub(1,pit_res_max); - frac2 = sub(pit_res_max,1); + frac1 = sub( 1, pit_res_max ); + frac2 = sub( pit_res_max, 1 ); test(); test(); - IF (((i_subfr == 0) && GE_16(t0,pit_fr2))||LE_16(pit_fr2,pit_min)) + IF( ( ( i_subfr == 0 ) && GE_16( t0, pit_fr2 ) ) || LE_16( pit_fr2, pit_min ) ) { step = 2; - frac1 = sub(2,pit_res_max); - frac2 = sub(pit_res_max,2); + frac1 = sub( 2, pit_res_max ); + frac2 = sub( pit_res_max, 2 ); } test(); - IF ( (EQ_16(t0,t0_min))&&(t0_min_frac==0)) + IF( ( EQ_16( t0, t0_min ) ) && ( t0_min_frac == 0 ) ) { frac1 = t0_min_frac; move16(); @@ -324,69 +332,67 @@ Word16 E_GAIN_closed_loop_search_fx(Word16 exc[], ELSE { test(); - IF ( (EQ_16(t0,t0_min))&&(LT_16(add(frac1,pit_res_max),t0_min_frac))) + IF( ( EQ_16( t0, t0_min ) ) && ( LT_16( add( frac1, pit_res_max ), t0_min_frac ) ) ) { - frac1 = sub(t0_min_frac,pit_res_max); + frac1 = sub( t0_min_frac, pit_res_max ); } } - if (EQ_16(t0,t0_max)) + if ( EQ_16( t0, t0_max ) ) { frac2 = t0_max_frac; move16(); } - assert(frac1<=0 && frac2>=0 && frac2>frac1); + assert( frac1 <= 0 && frac2 >= 0 && frac2 > frac1 ); - IF (EQ_16(pit_res_max,6)) + IF( EQ_16( pit_res_max, 6 ) ) { - cor_max = E_GAIN_norm_corr_interpolate6(&corr[t0], frac1); + cor_max = E_GAIN_norm_corr_interpolate6( &corr[t0], frac1 ); fraction = frac1; - FOR (i = (frac1 + step); i <= frac2; i += step) + FOR( i = ( frac1 + step ); i <= frac2; i += step ) { - temp = E_GAIN_norm_corr_interpolate6(&corr[t0], i); - IF (GT_16(temp,cor_max)) + temp = E_GAIN_norm_corr_interpolate6( &corr[t0], i ); + IF( GT_16( temp, cor_max ) ) { cor_max = temp; move16(); fraction = i; move16(); } - } } ELSE { - cor_max = E_GAIN_norm_corr_interpolate(&corr[t0], frac1); + cor_max = E_GAIN_norm_corr_interpolate( &corr[t0], frac1 ); fraction = frac1; - FOR (i = (frac1 + step); i <= frac2; i += step) + FOR( i = ( frac1 + step ); i <= frac2; i += step ) { - temp = E_GAIN_norm_corr_interpolate(&corr[t0], i); - IF (GT_16(temp,cor_max)) + temp = E_GAIN_norm_corr_interpolate( &corr[t0], i ); + IF( GT_16( temp, cor_max ) ) { cor_max = temp; move16(); fraction = i; move16(); } - } } /* limit the fraction value */ - IF (fraction < 0) + IF( fraction < 0 ) { - fraction = add(fraction,pit_res_max); - t0 = sub(t0,1); + fraction = add( fraction, pit_res_max ); + t0 = sub( t0, 1 ); } test(); test(); - IF (((i_subfr == 0) && GE_16(t0,pit_fr2))||LE_16(pit_fr2,pit_min)) + IF( ( ( i_subfr == 0 ) && GE_16( t0, pit_fr2 ) ) || LE_16( pit_fr2, pit_min ) ) { - *pit_res = shr(pit_res_max,1); + *pit_res = shr( pit_res_max, 1 ); move16(); - *pit_frac = shr(fraction,1); + *pit_frac = shr( fraction, 1 ); move16(); } ELSE @@ -396,6 +402,5 @@ Word16 E_GAIN_closed_loop_search_fx(Word16 exc[], *pit_frac = fraction; move16(); } - return (t0); + return ( t0 ); } - diff --git a/lib_enc/enc_gen_voic_fx.c b/lib_enc/enc_gen_voic_fx.c index 477074839..1b9823e73 100644 --- a/lib_enc/enc_gen_voic_fx.c +++ b/lib_enc/enc_gen_voic_fx.c @@ -2,14 +2,14 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ //#include "prot_fx.h" /* Function prototypes */ -#include "rom_com_fx.h" /* Static table prototypes */ +#include "rom_com_fx.h" /* Static table prototypes */ #include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*======================================================================*/ @@ -52,51 +52,50 @@ /*=======================================================================*/ void encod_gen_voic_fx( - Encoder_State *st_fx, /* i/o: state structure */ - const Word16 speech_fx[], /* i : input speech */ - const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */ - const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - const Word16 *res_fx, /* i : residual signal */ - Word16 *syn_fx, /* i/o: core synthesis */ - Word16 *exc_fx, /* i/o: current non-enhanced excitation */ - Word16 *exc2_fx, /* i/o: current enhanced excitation */ - Word16 *pitch_buf_fx, /* i/o: floating pitch values for each subframe */ - Word16 *voice_factors_fx, /* o : voicing factors */ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ - Word16 *unbits_fx, /* i/o: number of unused bits */ - const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ - const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer */ + Encoder_State *st_fx, /* i/o: state structure */ + const Word16 speech_fx[], /* i : input speech */ + const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */ + const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ + const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ + const Word16 *res_fx, /* i : residual signal */ + Word16 *syn_fx, /* i/o: core synthesis */ + Word16 *exc_fx, /* i/o: current non-enhanced excitation */ + Word16 *exc2_fx, /* i/o: current enhanced excitation */ + Word16 *pitch_buf_fx, /* i/o: floating pitch values for each subframe */ + Word16 *voice_factors_fx, /* o : voicing factors */ + Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ + Word16 *unbits_fx, /* i/o: number of unused bits */ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer */ Word16 shift, - Word16 Q_new -) + Word16 Q_new ) { - Word16 xn_fx[L_SUBFR]; /* Target vector for pitch search */ - Word16 xn2_fx[L_SUBFR]; /* Target vector for codebook search */ - Word16 cn_fx[L_SUBFR]; /* Target vector in residual domain */ - Word16 h1_fx[L_SUBFR+(M+1)]; /* Impulse response vector */ - Word16 h2_fx[L_SUBFR+(M+1)]; /* Impulse response vector */ - Word16 code_fx[L_SUBFR]; /* Fixed codebook excitation */ - Word16 y1_fx[L_SUBFR]= {0}; /* Filtered adaptive excitation */ - Word16 y2_fx[L_SUBFR]; /* Filtered algebraic excitation */ - Word16 gain_pit_fx = 0; /* Pitch gain */ - Word16 voice_fac_fx; /* Voicing factor */ - Word32 gain_code_fx = 0; /* Gain of code */ - Word16 gain_inov_fx=0; /* inovation gain */ - Word32 gc_mem[NB_SUBFR-1]; /* gain_code from previous subframes */ - Word16 gp_mem[NB_SUBFR-1]; /* gain_pitch from previous subframes*/ - Word16 i, i_subfr_fx; /* tmp variables */ - Word16 T0_fx=0, T0_frac_fx=0; /* close loop integer pitch and fractional part */ - Word16 T0_min_fx, T0_max_fx; /* pitch variables */ - Word16 *pt_pitch_fx; /* pointer to floating pitch buffer */ - Word16 g_corr_fx[10]; /* ACELP correl, values + gain pitch */ - Word16 clip_gain_fx; /* LSF clip gain */ - const Word16 *p_Aw_fx, *p_Aq_fx; /* pointer to LP filter coeff. vector*/ + Word16 xn_fx[L_SUBFR]; /* Target vector for pitch search */ + Word16 xn2_fx[L_SUBFR]; /* Target vector for codebook search */ + Word16 cn_fx[L_SUBFR]; /* Target vector in residual domain */ + Word16 h1_fx[L_SUBFR + ( M + 1 )]; /* Impulse response vector */ + Word16 h2_fx[L_SUBFR + ( M + 1 )]; /* Impulse response vector */ + Word16 code_fx[L_SUBFR]; /* Fixed codebook excitation */ + Word16 y1_fx[L_SUBFR] = { 0 }; /* Filtered adaptive excitation */ + Word16 y2_fx[L_SUBFR]; /* Filtered algebraic excitation */ + Word16 gain_pit_fx = 0; /* Pitch gain */ + Word16 voice_fac_fx; /* Voicing factor */ + Word32 gain_code_fx = 0; /* Gain of code */ + Word16 gain_inov_fx = 0; /* inovation gain */ + Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes */ + Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes*/ + Word16 i, i_subfr_fx; /* tmp variables */ + Word16 T0_fx = 0, T0_frac_fx = 0; /* close loop integer pitch and fractional part */ + Word16 T0_min_fx, T0_max_fx; /* pitch variables */ + Word16 *pt_pitch_fx; /* pointer to floating pitch buffer */ + Word16 g_corr_fx[10]; /* ACELP correl, values + gain pitch */ + Word16 clip_gain_fx; /* LSF clip gain */ + const Word16 *p_Aw_fx, *p_Aq_fx; /* pointer to LP filter coeff. vector*/ Word16 error_fx = 0; - Word16 gain_preQ_fx = 0; /* Gain of prequantizer excitation */ - Word16 code_preQ_fx[L_SUBFR]; /* Prequantizer excitation */ - Word16 unbits_PI_fx = 0; /* number of unused bits for PI */ - Word32 norm_gain_code_fx=0; + Word16 gain_preQ_fx = 0; /* Gain of prequantizer excitation */ + Word16 code_preQ_fx[L_SUBFR]; /* Prequantizer excitation */ + Word16 unbits_PI_fx = 0; /* number of unused bits for PI */ + Word32 norm_gain_code_fx = 0; Word16 pitch_limit_flag; Word16 gcode16; Word32 Ltmp; @@ -109,7 +108,7 @@ void encod_gen_voic_fx( #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; + SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; BSTR_ENC_HANDLE hBstr = st_fx->hBstr; SP_MUS_CLAS_HANDLE hSpMusClas = st_fx->hSpMusClas; LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; @@ -120,7 +119,7 @@ void encod_gen_voic_fx( gain_pit_fx = 0; move16(); - gain_code_fx = L_deposit_l(0); + gain_code_fx = L_deposit_l( 0 ); gain_preQ_fx = 0; move16(); unbits_PI_fx = 0; @@ -131,7 +130,7 @@ void encod_gen_voic_fx( move16(); - IF( EQ_16(L_frame,L_FRAME)) + IF( EQ_16( L_frame, L_FRAME ) ) { T0_max_fx = PIT_MAX; move16(); @@ -158,29 +157,29 @@ void encod_gen_voic_fx( move16(); set16_fx( code_preQ_fx, 0, L_SUBFR ); - shift_wsp = add(Q_new,shift); + shift_wsp = add( Q_new, shift ); /* set and write harmonicity flag */ harm_flag_acelp = 0; move16(); test(); test(); - IF( GE_32(st_fx->core_brate, MIN_BRATE_AVQ_EXC) && LE_32(st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD) && EQ_16(st_fx->coder_type,GENERIC)) + IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && LE_32( st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD ) && EQ_16( st_fx->coder_type, GENERIC ) ) { - if( GT_16(st_fx->last_harm_flag_acelp,2)) + if ( GT_16( st_fx->last_harm_flag_acelp, 2 ) ) { harm_flag_acelp = 1; move16(); } - push_indice_fx(hBstr, IND_HARM_FLAG_ACELP, harm_flag_acelp, 1 ); + push_indice_fx( hBstr, IND_HARM_FLAG_ACELP, harm_flag_acelp, 1 ); } /*------------------------------------------------------------------* * ACELP subframe loop *------------------------------------------------------------------*/ - FOR( i_subfr_fx=0; i_subfr_fxpreemph_fac, xn_fx, cn_fx, h1_fx ); Copy_Scale_sig( h1_fx, h2_fx, L_SUBFR, -2 ); - Scale_sig( h1_fx, L_SUBFR, add(1, shift) ); /* set h1[] in Q14 with scaling for convolution */ + Scale_sig( h1_fx, L_SUBFR, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution */ /* scaling of xn[] to limit dynamic at 12 bits */ Scale_sig( xn_fx, L_SUBFR, shift ); - *pt_pitch_fx = pit_encode_fx(hBstr, st_fx->acelp_cfg.pitch_bits, st_fx->core_brate, 0, L_frame, st_fx->coder_type, &pitch_limit_flag, i_subfr_fx, exc_fx, - L_SUBFR, st_fx->pitch_fx, &T0_min_fx, &T0_max_fx, &T0_fx, &T0_frac_fx, h1_fx, xn_fx , tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf); + *pt_pitch_fx = pit_encode_fx( hBstr, st_fx->acelp_cfg.pitch_bits, st_fx->core_brate, 0, L_frame, st_fx->coder_type, &pitch_limit_flag, i_subfr_fx, exc_fx, + L_SUBFR, st_fx->pitch_fx, &T0_min_fx, &T0_max_fx, &T0_fx, &T0_frac_fx, h1_fx, xn_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); - tbe_celp_exc(L_frame,i_subfr_fx,T0_fx, T0_frac_fx, &error_fx, bwe_exc_fx); + tbe_celp_exc( L_frame, i_subfr_fx, T0_fx, T0_frac_fx, &error_fx, bwe_exc_fx ); /*-----------------------------------------------------------------* * Find adaptive exitation *-----------------------------------------------------------------*/ - pred_lt4(&exc_fx[i_subfr_fx], &exc_fx[i_subfr_fx], T0_fx, T0_frac_fx, L_SUBFR+1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP); + pred_lt4( &exc_fx[i_subfr_fx], &exc_fx[i_subfr_fx], T0_fx, T0_frac_fx, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); /*-----------------------------------------------------------------* * Gain clipping test to avoid unstable synthesis on frame erasure *-----------------------------------------------------------------*/ - clip_gain_fx = gp_clip_fx(st_fx->element_mode, st_fx->core_brate, st_fx->voicing_fx,i_subfr_fx,st_fx->coder_type,xn_fx,st_fx->clip_var_fx,sub(shift_wsp, 1)); + clip_gain_fx = gp_clip_fx( st_fx->element_mode, st_fx->core_brate, st_fx->voicing_fx, i_subfr_fx, st_fx->coder_type, xn_fx, st_fx->clip_var_fx, sub( shift_wsp, 1 ) ); - if( EQ_16(st_fx->coder_type,INACTIVE)) + if ( EQ_16( st_fx->coder_type, INACTIVE ) ) { /* in case of AVQ inactive, limit the gain to 0.65 */ clip_gain_fx = 2; @@ -231,16 +230,16 @@ void encod_gen_voic_fx( lp_select = lp_filt_exc_enc_fx( MODE1, st_fx->coder_type, i_subfr_fx, exc_fx, h1_fx, xn_fx, y1_fx, xn2_fx, L_SUBFR, L_frame, g_corr_fx, clip_gain_fx, &gain_pit_fx, &lp_flag ); - IF( EQ_16(lp_flag,NORMAL_OPERATION)) + IF( EQ_16( lp_flag, NORMAL_OPERATION ) ) { - push_indice_fx(hBstr, IND_LP_FILT_SELECT, lp_select, 1 ); + push_indice_fx( hBstr, IND_LP_FILT_SELECT, lp_select, 1 ); } /*st_fx->lowrate_pitchGain = 0.9f * st_fx->lowrate_pitchGain + 0.1f * gain_pit_fx;*/ #ifdef BASOP_NOGLOB - hSpMusClas->lowrate_pitchGain = round_fx_o(L_mac_o(L_mult(29491, hSpMusClas->lowrate_pitchGain), 6554, gain_pit_fx, &Overflow), &Overflow); /*Q14*Q16(0.1) + Q15 -> Q15*/ + hSpMusClas->lowrate_pitchGain = round_fx_o( L_mac_o( L_mult( 29491, hSpMusClas->lowrate_pitchGain ), 6554, gain_pit_fx, &Overflow ), &Overflow ); /*Q14*Q16(0.1) + Q15 -> Q15*/ #else - hSpMusClas->lowrate_pitchGain = round_fx(L_mac(L_mult(29491, hSpMusClas->lowrate_pitchGain), 6554, gain_pit_fx)); /*Q14*Q16(0.1) + Q15 -> Q15*/ + hSpMusClas->lowrate_pitchGain = round_fx( L_mac( L_mult( 29491, hSpMusClas->lowrate_pitchGain ), 6554, gain_pit_fx ) ); /*Q14*Q16(0.1) + Q15 -> Q15*/ #endif /*-----------------------------------------------------------------* @@ -248,10 +247,10 @@ void encod_gen_voic_fx( *-----------------------------------------------------------------*/ test(); - IF( GE_32(st_fx->core_brate, MIN_BRATE_AVQ_EXC )&& NE_16(st_fx->coder_type,INACTIVE)) + IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && NE_16( st_fx->coder_type, INACTIVE ) ) { - transf_cdbk_enc_fx( st_fx, harm_flag_acelp, i_subfr_fx, cn_fx, exc_fx, p_Aq_fx, p_Aw_fx, h1_fx, xn_fx, - xn2_fx, y1_fx, y2_fx, Es_pred_fx, &gain_pit_fx, gain_code_fx, g_corr_fx, clip_gain_fx, &gain_preQ_fx, code_preQ_fx, unbits_fx, Q_new, shift); + transf_cdbk_enc_fx( st_fx, harm_flag_acelp, i_subfr_fx, cn_fx, exc_fx, p_Aq_fx, p_Aw_fx, h1_fx, xn_fx, + xn2_fx, y1_fx, y2_fx, Es_pred_fx, &gain_pit_fx, gain_code_fx, g_corr_fx, clip_gain_fx, &gain_preQ_fx, code_preQ_fx, unbits_fx, Q_new, shift ); } /*-----------------------------------------------------------------* @@ -266,108 +265,107 @@ void encod_gen_voic_fx( * Gain encoding *-----------------------------------------------------------------*/ - IF ( LE_32(st_fx->core_brate,ACELP_8k00)) + IF( LE_32( st_fx->core_brate, ACELP_8k00 ) ) { - gain_enc_lbr_fx(hBstr, st_fx->acelp_cfg.gains_mode, st_fx->coder_type, i_subfr_fx, xn_fx, y1_fx, shift_wsp, y2_fx, code_fx, + gain_enc_lbr_fx( hBstr, st_fx->acelp_cfg.gains_mode, st_fx->coder_type, i_subfr_fx, xn_fx, y1_fx, shift_wsp, y2_fx, code_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, g_corr_fx, gc_mem, gp_mem, clip_gain_fx, L_SUBFR ); } - ELSE IF ( GT_32(st_fx->core_brate,ACELP_32k)) + ELSE IF( GT_32( st_fx->core_brate, ACELP_32k ) ) { - gain_enc_SQ_fx(hBstr, st_fx->acelp_cfg.gains_mode, i_subfr_fx, xn_fx, y1_fx, y2_fx, code_fx, Es_pred_fx, + gain_enc_SQ_fx( hBstr, st_fx->acelp_cfg.gains_mode, i_subfr_fx, xn_fx, y1_fx, y2_fx, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, g_corr_fx, clip_gain_fx, shift_wsp ); } ELSE { - gain_enc_mless_fx(hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, L_frame, i_subfr_fx, -1, xn_fx, y1_fx, shift_wsp, y2_fx, code_fx, Es_pred_fx, - &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, g_corr_fx, clip_gain_fx ); + gain_enc_mless_fx( hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, L_frame, i_subfr_fx, -1, xn_fx, y1_fx, shift_wsp, y2_fx, code_fx, Es_pred_fx, + &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, g_corr_fx, clip_gain_fx ); } - IF (st_fx->Opt_SC_VBR) + IF( st_fx->Opt_SC_VBR ) { - if (EQ_16(hSC_VBR->last_ppp_mode, 1)) + if ( EQ_16( hSC_VBR->last_ppp_mode, 1 ) ) { /* SC-VBR - all other st->clip_var values will be updated even in a PPP frame */ st_fx->clip_var_fx[1] = gain_pit_fx; move16(); } } - gp_clip_test_gain_pit_fx(st_fx->element_mode, st_fx->core_brate, gain_pit_fx, st_fx->clip_var_fx ); + gp_clip_test_gain_pit_fx( st_fx->element_mode, st_fx->core_brate, gain_pit_fx, st_fx->clip_var_fx ); #ifdef BASOP_NOGLOB - Lgcode = L_shl_o(gain_code_fx, Q_new, &Overflow); /* scaled gain_code with Qnew -> Q16*/ - gcode16 = round_fx_o(Lgcode, &Overflow); + Lgcode = L_shl_o( gain_code_fx, Q_new, &Overflow ); /* scaled gain_code with Qnew -> Q16*/ + gcode16 = round_fx_o( Lgcode, &Overflow ); #else - Lgcode = L_shl(gain_code_fx, Q_new); /* scaled gain_code with Qnew -> Q16*/ - gcode16 = round_fx(Lgcode); + Lgcode = L_shl( gain_code_fx, Q_new ); /* scaled gain_code with Qnew -> Q16*/ + gcode16 = round_fx( Lgcode ); #endif - hLPDmem->tilt_code = Est_tilt2(&exc_fx[i_subfr_fx], gain_pit_fx, code_fx, Lgcode, &voice_fac_fx, shift); + hLPDmem->tilt_code = Est_tilt2( &exc_fx[i_subfr_fx], gain_pit_fx, code_fx, Lgcode, &voice_fac_fx, shift ); /*-----------------------------------------------------------------* * Transform domain contribution encoding - inactive frames *-----------------------------------------------------------------*/ test(); - IF ( GE_32(st_fx->core_brate, MAX_GSC_INACTIVE_BRATE) && EQ_16(st_fx->coder_type,INACTIVE)) + IF( GE_32( st_fx->core_brate, MAX_GSC_INACTIVE_BRATE ) && EQ_16( st_fx->coder_type, INACTIVE ) ) { - transf_cdbk_enc_fx( st_fx, 0, i_subfr_fx, cn_fx, exc_fx, p_Aq_fx, p_Aw_fx, h1_fx, xn_fx, xn2_fx, y1_fx, y2_fx, - Es_pred_fx, &gain_pit_fx, gain_code_fx, g_corr_fx, clip_gain_fx, &gain_preQ_fx, code_preQ_fx, unbits_fx, Q_new, shift); + transf_cdbk_enc_fx( st_fx, 0, i_subfr_fx, cn_fx, exc_fx, p_Aq_fx, p_Aw_fx, h1_fx, xn_fx, xn2_fx, y1_fx, y2_fx, + Es_pred_fx, &gain_pit_fx, gain_code_fx, g_corr_fx, clip_gain_fx, &gain_preQ_fx, code_preQ_fx, unbits_fx, Q_new, shift ); } /*-----------------------------------------------------------------* - * Update memory of the weighting filter - *-----------------------------------------------------------------*/ + * Update memory of the weighting filter + *-----------------------------------------------------------------*/ /* st_fx->mem_w0 = xn[L_SUBFR-1] - (gain_pit*y1[L_SUBFR-1]) - (gain_code*y2[L_SUBFR-1]); */ - Ltmp = L_mult(gcode16, y2_fx[L_SUBFR - 1]); - Ltmp = L_shl(Ltmp, add(5, shift)); - Ltmp = L_negate(Ltmp); - Ltmp = L_mac(Ltmp, xn_fx[L_SUBFR - 1], 16384); - Ltmp = L_msu(Ltmp, y1_fx[L_SUBFR - 1], gain_pit_fx); + Ltmp = L_mult( gcode16, y2_fx[L_SUBFR - 1] ); + Ltmp = L_shl( Ltmp, add( 5, shift ) ); + Ltmp = L_negate( Ltmp ); + Ltmp = L_mac( Ltmp, xn_fx[L_SUBFR - 1], 16384 ); + Ltmp = L_msu( Ltmp, y1_fx[L_SUBFR - 1], gain_pit_fx ); #ifdef BASOP_NOGLOB Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) ); - hLPDmem->mem_w0 = round_fx_sat(Ltmp); /*Q_new-1 */ + hLPDmem->mem_w0 = round_fx_sat( Ltmp ); /*Q_new-1 */ #else - Ltmp = L_shl(Ltmp, sub(1, shift)); - hLPDmem->mem_w0 = round_fx(Ltmp); /*Q_new-1 */ + Ltmp = L_shl( Ltmp, sub( 1, shift ) ); + hLPDmem->mem_w0 = round_fx( Ltmp ); /*Q_new-1 */ #endif - IF(gain_preQ_fx != 0 ) + IF( gain_preQ_fx != 0 ) { - tmp1_fx = add(16-(2+Q_AVQ_OUT_DEC+1),Q_new); + tmp1_fx = add( 16 - ( 2 + Q_AVQ_OUT_DEC + 1 ), Q_new ); FOR( i = 0; i < L_SUBFR; i++ ) { #ifdef BASOP_NOGLOB /* Contribution from AVQ layer */ - Ltmp1 = L_mult_o(gain_preQ_fx, code_preQ_fx[i], &Overflow); /* Q2 + Q6 -> Q9*/ - Ltmp1 = L_shl_o(Ltmp1, tmp1_fx, &Overflow); /* Q16 + Q_exc */ + Ltmp1 = L_mult_o( gain_preQ_fx, code_preQ_fx[i], &Overflow ); /* Q2 + Q6 -> Q9*/ + Ltmp1 = L_shl_o( Ltmp1, tmp1_fx, &Overflow ); /* Q16 + Q_exc */ /* Compute exc2 */ - Ltmp = L_shl_o(L_mult(gain_pit_fx,exc_fx[i+i_subfr_fx]),1, &Overflow); - exc2_fx[i+i_subfr_fx] = round_fx_o(L_add_o(Ltmp, Ltmp1, &Overflow), &Overflow); + Ltmp = L_shl_o( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1, &Overflow ); + exc2_fx[i + i_subfr_fx] = round_fx_o( L_add_o( Ltmp, Ltmp1, &Overflow ), &Overflow ); #else /* Contribution from AVQ layer */ - Ltmp1 = L_mult(gain_preQ_fx, code_preQ_fx[i]); /* Q2 + Q6 -> Q9*/ - Ltmp1 = L_shl(Ltmp1, tmp1_fx); /* Q16 + Q_exc */ + Ltmp1 = L_mult( gain_preQ_fx, code_preQ_fx[i] ); /* Q2 + Q6 -> Q9*/ + Ltmp1 = L_shl( Ltmp1, tmp1_fx ); /* Q16 + Q_exc */ /* Compute exc2 */ - Ltmp = L_shl(L_mult(gain_pit_fx,exc_fx[i+i_subfr_fx]),1); - exc2_fx[i+i_subfr_fx] = round_fx(L_add(Ltmp, Ltmp1)); + Ltmp = L_shl( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 ); + exc2_fx[i + i_subfr_fx] = round_fx( L_add( Ltmp, Ltmp1 ) ); #endif /* code in Q9, gain_pit in Q14 */ - Ltmp = L_mult(gcode16, code_fx[i]); - Ltmp = L_shl(Ltmp, 5); - Ltmp = L_mac(Ltmp, exc_fx[i + i_subfr_fx], gain_pit_fx); + Ltmp = L_mult( gcode16, code_fx[i] ); + Ltmp = L_shl( Ltmp, 5 ); + Ltmp = L_mac( Ltmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); #ifdef BASOP_NOGLOB - Ltmp = L_shl_o(Ltmp, 1, &Overflow); /* saturation can occur here */ - exc_fx[i + i_subfr_fx] = round_fx_o(L_add_o(Ltmp, Ltmp1, &Overflow), &Overflow); + Ltmp = L_shl_o( Ltmp, 1, &Overflow ); /* saturation can occur here */ + exc_fx[i + i_subfr_fx] = round_fx_o( L_add_o( Ltmp, Ltmp1, &Overflow ), &Overflow ); #else - Ltmp = L_shl(Ltmp, 1); /* saturation can occur here */ + Ltmp = L_shl( Ltmp, 1 ); /* saturation can occur here */ - exc_fx[i+i_subfr_fx] = round_fx(L_add(Ltmp, Ltmp1)); + exc_fx[i + i_subfr_fx] = round_fx( L_add( Ltmp, Ltmp1 ) ); #endif } - } ELSE { @@ -375,20 +373,20 @@ void encod_gen_voic_fx( * Construct adaptive part of the excitation * Save the non-enhanced excitation for FEC_exc *-----------------------------------------------------------------*/ - FOR (i = 0; i < L_SUBFR; i++) + FOR( i = 0; i < L_SUBFR; i++ ) { /* code in Q9, gain_pit in Q14 */ - Ltmp = L_mult(gcode16, code_fx[i]); + Ltmp = L_mult( gcode16, code_fx[i] ); #ifdef BASOP_NOGLOB - Ltmp = L_shl_o(Ltmp, 5, &Overflow); - Ltmp = L_mac_o(Ltmp, exc_fx[i + i_subfr_fx], gain_pit_fx, &Overflow); - Ltmp = L_shl_o(Ltmp, 1, &Overflow); /* saturation can occur here */ - exc_fx[i + i_subfr_fx] = round_fx_o(Ltmp, &Overflow); + Ltmp = L_shl_o( Ltmp, 5, &Overflow ); + Ltmp = L_mac_o( Ltmp, exc_fx[i + i_subfr_fx], gain_pit_fx, &Overflow ); + Ltmp = L_shl_o( Ltmp, 1, &Overflow ); /* saturation can occur here */ + exc_fx[i + i_subfr_fx] = round_fx_o( Ltmp, &Overflow ); #else - Ltmp = L_shl(Ltmp, 5); - Ltmp = L_mac(Ltmp, exc_fx[i + i_subfr_fx], gain_pit_fx); - Ltmp = L_shl(Ltmp, 1); /* saturation can occur here */ - exc_fx[i + i_subfr_fx] = round_fx(Ltmp); + Ltmp = L_shl( Ltmp, 5 ); + Ltmp = L_mac( Ltmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); + Ltmp = L_shl( Ltmp, 1 ); /* saturation can occur here */ + exc_fx[i + i_subfr_fx] = round_fx( Ltmp ); #endif } } @@ -397,7 +395,7 @@ void encod_gen_voic_fx( *-----------------------------------------------------------------*/ prep_tbe_exc_fx( L_frame, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, - &voice_factors_fx[i_subfr_fx/L_SUBFR], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, Q_new, + &voice_factors_fx[i_subfr_fx / L_SUBFR], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, Q_new, T0_fx, T0_frac_fx, st_fx->coder_type, st_fx->core_brate ); /*-----------------------------------------------------------------* @@ -407,19 +405,19 @@ void encod_gen_voic_fx( Syn_filt_s( 1, p_Aq_fx, M, &exc_fx[i_subfr_fx], &syn_fx[i_subfr_fx], L_SUBFR, hLPDmem->mem_syn, 1 ); - p_Aw_fx += (M+1); - p_Aq_fx += (M+1); + p_Aw_fx += ( M + 1 ); + p_Aq_fx += ( M + 1 ); pt_pitch_fx++; } /* write reserved bits */ WHILE( unbits_PI_fx > 0 ) { - i = s_min(unbits_PI_fx, 16); - push_indice_fx(hBstr, IND_UNUSED, 0, i ); + i = s_min( unbits_PI_fx, 16 ); + push_indice_fx( hBstr, IND_UNUSED, 0, i ); unbits_PI_fx -= i; } - IF (st_fx->Opt_SC_VBR) + IF( st_fx->Opt_SC_VBR ) { /* SC-VBR */ hSC_VBR->prev_ppp_gain_pit_fx = gain_pit_fx; @@ -428,5 +426,4 @@ void encod_gen_voic_fx( move16(); } return; - } diff --git a/lib_enc/enc_gen_voic_rf.c b/lib_enc/enc_gen_voic_rf.c index f2c3f391f..ae4458960 100644 --- a/lib_enc/enc_gen_voic_rf.c +++ b/lib_enc/enc_gen_voic_rf.c @@ -220,7 +220,7 @@ void coder_acelp_rf( * and impulse response of the weighted synthesis filter (h1[]). * *--------------------------------------------------------------------------*/ - find_targets( speech, &syn_rf[i_subfr - M], i_subfr, &( hRF->rf_mem_w0_flt), p_Aq, exc_rf, L_SUBFR, p_A, st->preemph_fac_flt, xn, cn, h1 ); + find_targets( speech, &syn_rf[i_subfr - M], i_subfr, &( hRF->rf_mem_w0_flt ), p_Aq, exc_rf, L_SUBFR, p_A, st->preemph_fac_flt, xn, cn, h1 ); } /* full frame nelp partial copy encoding */ @@ -240,7 +240,7 @@ void coder_acelp_rf( * or in case of floating point encoder & fixed p. decoder *-----------------------------------------------------------------*/ - clip_gain = gp_clip( st->element_mode, st->core_brate, voicing, i_subfr, coder_type, xn, hRF->rf_clip_var_flt); + clip_gain = gp_clip( st->element_mode, st->core_brate, voicing, i_subfr, coder_type, xn, hRF->rf_clip_var_flt ); /*-----------------------------------------------------------------* * - find unity gain pitch excitation (adaptive codebook entry) * @@ -338,7 +338,7 @@ void coder_acelp_rf( encode_acelp_gains( code, acelp_cfg->gains_mode[i_subfr / L_SUBFR], Es_pred_rf, clip_gain, &g_corr, &gain_pit, &gain_code, &prm_rf, &past_gcode, &gain_inov, L_SUBFR, code2, &gain_code2, st->flag_noisy_speech_snr ); } - gp_clip_test_gain_pit( st->element_mode, st->core_brate, gain_pit, hRF->rf_clip_var_flt); + gp_clip_test_gain_pit( st->element_mode, st->core_brate, gain_pit, hRF->rf_clip_var_flt ); /*----------------------------------------------------------* * - voice factor (for codebook tilt sharpening) * diff --git a/lib_enc/enc_gen_voic_rf_fx.c b/lib_enc/enc_gen_voic_rf_fx.c index afd51342d..c60767394 100644 --- a/lib_enc/enc_gen_voic_rf_fx.c +++ b/lib_enc/enc_gen_voic_rf_fx.c @@ -11,36 +11,35 @@ #include "rom_basop_util.h" //#include "basop_mpy.h" #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ -#include "basop_util.h" /* Function prototypes */ - +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ +#include "basop_util.h" /* Function prototypes */ void reset_rf_indices_fx( - Encoder_State *st /* i: state structure - contains partial RF indices */ + Encoder_State *st /* i: state structure - contains partial RF indices */ ) { RF_ENC_HANDLE hRF = st->hRF; Word16 i, j; - if (hRF != NULL) + if ( hRF != NULL ) { hRF->rf_frame_type = 0; /* since this function is called every frame this will happen even for a SID frame, hence treating it as GSC frame, i.e no RF encoding */ hRF->rf_mem_w0 = 0; move16(); st->rf_target_bits_write = 0; move16(); - set16_fx(hRF->rf_clip_var, 0 ,6); + set16_fx( hRF->rf_clip_var, 0, 6 ); hRF->rf_tilt_code = 0; move16(); - set16_fx(hRF->rf_mem_syn2, 0, M); + set16_fx( hRF->rf_mem_syn2, 0, M ); hRF->rf_dm_fx.prev_state = 0; move16(); hRF->rf_dm_fx.prev_gain_code = 0; move32(); - FOR(i=0; i<6; i++) + FOR( i = 0; i < 6; i++ ) { hRF->rf_dm_fx.prev_gain_pit[i] = 0; move16(); @@ -48,7 +47,7 @@ void reset_rf_indices_fx( hRF->rf_gc_threshold = 0; move32(); - set16_fx(hRF->rf_tilt_buf, 0, NB_SUBFR16k); + set16_fx( hRF->rf_tilt_buf, 0, NB_SUBFR16k ); hRF->rf_target_bits = 0; move16(); @@ -58,13 +57,13 @@ void reset_rf_indices_fx( move16(); hRF->rf_second_last_tns_active = 0; move16(); - hRF->rf_second_last_core= 0; + hRF->rf_second_last_core = 0; move16(); - FOR( i = 0; i < MAX_RF_FEC_OFFSET; i++) + FOR( i = 0; i < MAX_RF_FEC_OFFSET; i++ ) { hRF->rf_indx_frametype[i] = RF_NO_DATA; - move16(); /* rf_mode: 1, rf_frame_type: 3, and fec_offset: 2 */ + move16(); /* rf_mode: 1, rf_frame_type: 3, and fec_offset: 2 */ hRF->rf_targetbits_buff[i] = 6; move16(); hRF->rf_indx_lsf[i][0] = 0; @@ -84,7 +83,7 @@ void reset_rf_indices_fx( hRF->rf_indx_nelp_iG2[i][1] = 0; move16(); - FOR( j = 0; j < NB_SUBFR16k; j++) + FOR( j = 0; j < NB_SUBFR16k; j++ ) { hRF->rf_indx_ltfMode[i][j] = 0; move16(); @@ -119,12 +118,12 @@ void reset_rf_indices_fx( *-------------------------------------------------------------------*/ void coder_acelp_rf_fx( ACELP_config *acelp_cfg, /*input/output: configuration of the ACELP coding*/ - const Word16 coder_type, /* input: coding type */ - const Word16 A[], /* input: coefficients 4xAz[M+1] */ - const Word16 Aq[], /* input: coefficients 4xAz_q[M+1] */ - Word16 speech[], /* input: speech[-M..lg] */ - const Word16 voicing[], /* input: open-loop LTP gain */ - const Word16 T_op[], /* input: open-loop LTP lag */ + const Word16 coder_type, /* input: coding type */ + const Word16 A[], /* input: coefficients 4xAz[M+1] */ + const Word16 Aq[], /* input: coefficients 4xAz_q[M+1] */ + Word16 speech[], /* input: speech[-M..lg] */ + const Word16 voicing[], /* input: open-loop LTP gain */ + const Word16 T_op[], /* input: open-loop LTP lag */ Word16 stab_fac, Encoder_State *st, Word16 target_bits, /* i/o : coder memory state */ @@ -132,8 +131,7 @@ void coder_acelp_rf_fx( Word16 *exc_rf, /* i/o: pointer to RF excitation */ Word16 *syn_rf, /* i/o: pointer to RF synthesis */ Word16 Q_new, - Word16 shift -) + Word16 shift ) { Word16 i, j, i_subfr, j_subfr; Word16 T0, T0_min, T0_min_frac, T0_max, T0_max_frac, T0_res; @@ -143,15 +141,15 @@ void coder_acelp_rf_fx( Word32 gain_code, Ltmp, Ltmp2; ACELP_CbkCorr g_corr; const Word16 *p_A, *p_Aq; - Word16 h1[L_SUBFR]; /* weighted impulse response of LP */ + Word16 h1[L_SUBFR]; /* weighted impulse response of LP */ Word16 code[L_SUBFR]; Word16 xn_exp; Word16 Q_xn; Word16 Q_new_p5; Word16 cn[L_SUBFR]; Word16 xn[L_SUBFR]; - Word16 y1[L_SUBFR]; /* Filtered adaptive excitation */ - Word16 y2[L_SUBFR]; /* Filtered adaptive excitation */ + Word16 y1[L_SUBFR]; /* Filtered adaptive excitation */ + Word16 y2[L_SUBFR]; /* Filtered adaptive excitation */ Word16 res_save; Word16 exc_nelp[L_FRAME]; Word16 exc2[L_SUBFR]; @@ -185,68 +183,68 @@ void coder_acelp_rf_fx( gain_pit = 0; gain_code = 0; voice_fac = 0; - prev_gain_pit=0; + prev_gain_pit = 0; Es_pred_rf = 0; - set16_fx(code, 0, L_SUBFR); + set16_fx( code, 0, L_SUBFR ); /*-----------------------------------------------------------------------* - * Configure ACELP partial copy * - *------------------------------------------------------------------------*/ - tmp2 = BITS_ALLOC_config_acelp( target_bits, rf_frame_type, &(hRF->acelp_cfg_rf), 0, st->nb_subfr ); + * Configure ACELP partial copy * + *------------------------------------------------------------------------*/ + tmp2 = BITS_ALLOC_config_acelp( target_bits, rf_frame_type, &( hRF->acelp_cfg_rf ), 0, st->nb_subfr ); /* Init Framing parameters */ L_frame = st->L_frame; /*------------------------------------------------------------------------* - * Initialize buffers * - *------------------------------------------------------------------------*/ + * Initialize buffers * + *------------------------------------------------------------------------*/ /* Rescale ACELP memories, which were not scaled yet*/ - xn_exp = sub(sub(15+1, Q_new),shift); - Q_xn = add(sub(Q_new,1),shift); - Q_new_p5 = add(Q_new, 5); + xn_exp = sub( sub( 15 + 1, Q_new ), shift ); + Q_xn = add( sub( Q_new, 1 ), shift ); + Q_new_p5 = add( Q_new, 5 ); /* Reset phase dispersion */ - IF (GT_16(st->last_core, ACELP_CORE)) + IF( GT_16( st->last_core, ACELP_CORE ) ) { hRF->rf_dm_fx.prev_gain_code = 0; - set16_fx(hRF->rf_dm_fx.prev_gain_pit, 0, 6); + set16_fx( hRF->rf_dm_fx.prev_gain_pit, 0, 6 ); hRF->rf_dm_fx.prev_state = 0; } /* calculate residual */ - calc_residu_fx(st, speech, exc_rf, Aq); + calc_residu_fx( st, speech, exc_rf, Aq ); /*------------------------------------------------------------------------* - * Find and quantize mean_ener_code for gain quantizer * - *------------------------------------------------------------------------*/ + * Find and quantize mean_ener_code for gain quantizer * + *------------------------------------------------------------------------*/ Es_pred_rf = 0; - IF( acelp_cfg->nrg_mode > 0 && NE_16(rf_frame_type,RF_NELP)) + IF( acelp_cfg->nrg_mode > 0 && NE_16( rf_frame_type, RF_NELP ) ) { - Es_pred_enc_fx(&Es_pred_rf, &hRF->rf_indx_EsPred[0], L_frame, exc_rf, voicing, - acelp_cfg->nrg_bits, acelp_cfg->nrg_mode>1, Q_new); + Es_pred_enc_fx( &Es_pred_rf, &hRF->rf_indx_EsPred[0], L_frame, exc_rf, voicing, + acelp_cfg->nrg_bits, acelp_cfg->nrg_mode > 1, Q_new ); } /*------------------------------------------------------------------------* - * Loop for every subframe in the analysis frame * - *------------------------------------------------------------------------* - * To find the pitch and innovation parameters. The subframe size is * - * L_SUBFR and the loop is repeated L_FRAME_PLUS/L_SUBFR * - * times. * - * - compute impulse response of weighted synthesis filter (h1[]) * - * - compute the target signal for pitch search * - * - find the closed-loop pitch parameters * - * - encode the pitch delay * - * - update the impulse response h1[] by including fixed-gain pitch * - * - find target vector for codebook search * - * - correlation between target vector and impulse response * - * - codebook search * - * - encode codebook address * - * - VQ of pitch and codebook gains * - * - find synthesis speech * - * - update states of weighting filter * - *------------------------------------------------------------------------*/ + * Loop for every subframe in the analysis frame * + *------------------------------------------------------------------------* + * To find the pitch and innovation parameters. The subframe size is * + * L_SUBFR and the loop is repeated L_FRAME_PLUS/L_SUBFR * + * times. * + * - compute impulse response of weighted synthesis filter (h1[]) * + * - compute the target signal for pitch search * + * - find the closed-loop pitch parameters * + * - encode the pitch delay * + * - update the impulse response h1[] by including fixed-gain pitch * + * - find target vector for codebook search * + * - correlation between target vector and impulse response * + * - codebook search * + * - encode codebook address * + * - VQ of pitch and codebook gains * + * - find synthesis speech * + * - update states of weighting filter * + *------------------------------------------------------------------------*/ p_A = A; p_Aq = Aq; @@ -254,32 +252,31 @@ void coder_acelp_rf_fx( nSubfr = 0; j_subfr = 0; - FOR (i_subfr=0; i_subfrrf_mem_w0), p_Aq, - exc_rf, L_SUBFR, p_A, st->preemph_fac, xn, cn ,h1 ); + * Find target for pitch search (xn[]), target for innovation search (cn[]) * + * and impulse response of the weighted synthesis filter (h1[]). * + *--------------------------------------------------------------------------*/ + find_targets_fx( speech, &syn_rf[i_subfr - M], i_subfr, &( hRF->rf_mem_w0 ), p_Aq, + exc_rf, L_SUBFR, p_A, st->preemph_fac, xn, cn, h1 ); /*---------------------------------------------------------------* * Compute impulse response, h1[], of weighted synthesis filter * *---------------------------------------------------------------*/ - Scale_sig(h1, L_SUBFR, add(1,shift)); /* Q13+1-shift */ + Scale_sig( h1, L_SUBFR, add( 1, shift ) ); /* Q13+1-shift */ /* scaling of xn[] to limit dynamic at 12 bits */ - Scale_sig(xn, L_SUBFR, shift); - + Scale_sig( xn, L_SUBFR, shift ); } @@ -288,129 +285,133 @@ void coder_acelp_rf_fx( * or in case of floating point encoder & fixed p. decoder *-----------------------------------------------------------------*/ /* full frame nelp partial copy encoding */ - IF( EQ_16(rf_frame_type,RF_NELP)) + IF( EQ_16( rf_frame_type, RF_NELP ) ) { IF( i_subfr == 0 ) { - nelp_encoder_fx( st, exc_rf, exc_nelp, &Q_new,0); + nelp_encoder_fx( st, exc_rf, exc_nelp, &Q_new, 0 ); } Copy( &exc_nelp[i_subfr], exc2, L_SUBFR ); Copy( &exc_nelp[i_subfr], exc_rf, L_SUBFR ); - } ELSE { clip_gain = Mode2_gp_clip( voicing, i_subfr, coder_type, xn, hRF->rf_clip_var, L_SUBFR, Q_xn ); /*-----------------------------------------------------------------* - * - find unity gain pitch excitation (adaptive codebook entry) * - * with fractional interpolation. * - * - find filtered pitch exc. y1[]=exc[] convolved with h1[]) * - * - compute pitch gain1 * - *-----------------------------------------------------------------*/ - if( acelp_cfg->gains_mode[i_subfr/L_SUBFR] == 0 ) + * - find unity gain pitch excitation (adaptive codebook entry) * + * with fractional interpolation. * + * - find filtered pitch exc. y1[]=exc[] convolved with h1[]) * + * - compute pitch gain1 * + *-----------------------------------------------------------------*/ + if ( acelp_cfg->gains_mode[i_subfr / L_SUBFR] == 0 ) { gain_pit = prev_gain_pit; move16(); } - IF ( acelp_cfg->ltp_bits!=0 ) + IF( acelp_cfg->ltp_bits != 0 ) { prm_rf = &hRF->rf_indx_pitch[0][nSubfr]; /* Adaptive Codebook (GC and VC) */ Mode2_pit_encode_fx( acelp_cfg->ltp_mode, i_subfr, &prm_rf, &exc_rf[i_subfr], - T_op, &T0_min, &T0_min_frac, &T0_max, &T0_max_frac, &T0, - &T0_frac, &T0_res, h1, xn, st->pit_min, st->pit_fr1, st->pit_fr1b, - st->pit_fr2, st->pit_max,st->pit_res_max); + T_op, &T0_min, &T0_min_frac, &T0_max, &T0_max_frac, &T0, + &T0_frac, &T0_res, h1, xn, st->pit_min, st->pit_fr1, st->pit_fr1b, + st->pit_fr2, st->pit_max, st->pit_res_max ); /* find ACB excitation */ rf_coder_type = 100; move16(); - if( acelp_cfg->gains_mode[i_subfr/L_SUBFR] > 0 ) + if ( acelp_cfg->gains_mode[i_subfr / L_SUBFR] > 0 ) { - rf_coder_type = acelp_cfg->gains_mode[i_subfr/L_SUBFR]; + rf_coder_type = acelp_cfg->gains_mode[i_subfr / L_SUBFR]; move16(); } E_ACELP_adaptive_codebook( exc_rf, T0, T0_frac, T0_res, st->pit_res_max, acelp_cfg->ltf_mode, - i_subfr, L_SUBFR, L_frame, h1,clip_gain, xn, y1, &g_corr, &prm_rf, - &gain_pit, xn_exp, st->rf_mode, rf_coder_type, &lp_select); - + i_subfr, L_SUBFR, L_frame, h1, clip_gain, xn, y1, &g_corr, &prm_rf, + &gain_pit, xn_exp, st->rf_mode, rf_coder_type, &lp_select ); - if( EQ_16(acelp_cfg->ltf_mode, NORMAL_OPERATION) ) + if ( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) { hRF->rf_indx_ltfMode[0][nSubfr] = lp_select; move16(); } } - ELSE IF ( acelp_cfg->ltp_bits==0 ) + ELSE IF( acelp_cfg->ltp_bits == 0 ) { /* No adaptive codebook (UC) */ - gain_pit=0; - g_corr.xy1=0; - g_corr.xy1_e=0; - g_corr.y1y1=0x4000; /* set to 0x4000 instead of 0 to avoid assert failue in gain_enc : assert(coeff0 >= 0x4000) */ - g_corr.y1y1_e=0; - set16_fx(y1,0,L_SUBFR); - set16_fx(exc_rf+i_subfr,0,L_SUBFR); + gain_pit = 0; + g_corr.xy1 = 0; + g_corr.xy1_e = 0; + g_corr.y1y1 = 0x4000; /* set to 0x4000 instead of 0 to avoid assert failue in gain_enc : assert(coeff0 >= 0x4000) */ + g_corr.y1y1_e = 0; + set16_fx( y1, 0, L_SUBFR ); + set16_fx( exc_rf + i_subfr, 0, L_SUBFR ); T0 = L_SUBFR; T0_frac = 0; T0_res = 1; - move16();move16();move16();move16();move16();move16();move16();move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); } /*----------------------------------------------------------------------* - * Encode the algebraic innovation * - *----------------------------------------------------------------------*/ - IF( acelp_cfg->fixed_cdk_index[i_subfr/L_SUBFR] >= 0 ) + * Encode the algebraic innovation * + *----------------------------------------------------------------------*/ + IF( acelp_cfg->fixed_cdk_index[i_subfr / L_SUBFR] >= 0 ) { prm_rf = &hRF->rf_indx_fcb[0][nSubfr]; - E_ACELP_innovative_codebook_fx( exc_rf,T0,T0_frac,T0_res, gain_pit, hRF->rf_tilt_code, - acelp_cfg, i_subfr,p_Aq,h1,xn,cn,y1,y2,(Word8)st->acelp_autocorr, - &prm_rf,code,shift,st->L_frame, st->last_L_frame,st->total_brate); + E_ACELP_innovative_codebook_fx( exc_rf, T0, T0_frac, T0_res, gain_pit, hRF->rf_tilt_code, + acelp_cfg, i_subfr, p_Aq, h1, xn, cn, y1, y2, (Word8) st->acelp_autocorr, + &prm_rf, code, shift, st->L_frame, st->last_L_frame, st->total_brate ); } ELSE { - set16_fx(code, 0, L_SUBFR); - set16_fx(y2, 0, L_SUBFR); + set16_fx( code, 0, L_SUBFR ); + set16_fx( y2, 0, L_SUBFR ); } - IF( LT_16(i_subfr, sub(L_frame,L_SUBFR)) ) + IF( LT_16( i_subfr, sub( L_frame, L_SUBFR ) ) ) { - E_ACELP_xy2_corr(xn, y1, y2, &g_corr, L_SUBFR, Q_xn); + E_ACELP_xy2_corr( xn, y1, y2, &g_corr, L_SUBFR, Q_xn ); - g_corr.y2y2_e = sub(g_corr.y2y2_e, 18); /* -18 (y2*y2: Q9*Q9) */ - g_corr.xy2_e = sub(g_corr.xy2_e, add(Q_xn,9)); /* -(Q_xn+9) (xn: Q_xn y2: Q9) */ - g_corr.y1y2_e = sub(g_corr.y1y2_e, add(Q_xn,9)); /* -(Q_xn+9) (y1: Q_xn y2: Q9) */ - g_corr.xx_e = sub(g_corr.xx_e, add(Q_xn,Q_xn)); /* -(Q_xn+Q_xn) (xn: Q_xn) */ + g_corr.y2y2_e = sub( g_corr.y2y2_e, 18 ); /* -18 (y2*y2: Q9*Q9) */ + g_corr.xy2_e = sub( g_corr.xy2_e, add( Q_xn, 9 ) ); /* -(Q_xn+9) (xn: Q_xn y2: Q9) */ + g_corr.y1y2_e = sub( g_corr.y1y2_e, add( Q_xn, 9 ) ); /* -(Q_xn+9) (y1: Q_xn y2: Q9) */ + g_corr.xx_e = sub( g_corr.xx_e, add( Q_xn, Q_xn ) ); /* -(Q_xn+Q_xn) (xn: Q_xn) */ /*----------------------------------------------------------------------* * Add Gaussian excitation * *----------------------------------------------------------------------*/ - gain_code2 = L_deposit_l(0); - set16_fx(code2, 0, L_SUBFR); - set16_fx(y22, 0, L_SUBFR); + gain_code2 = L_deposit_l( 0 ); + set16_fx( code2, 0, L_SUBFR ); + set16_fx( y22, 0, L_SUBFR ); /*----------------------------------------------------------* - * - Compute the fixed codebook gain * - * - quantize fixed codebook gain * - *----------------------------------------------------------*/ - IF( acelp_cfg->gains_mode[i_subfr/L_SUBFR] != 0 ) + * - Compute the fixed codebook gain * + * - quantize fixed codebook gain * + *----------------------------------------------------------*/ + IF( acelp_cfg->gains_mode[i_subfr / L_SUBFR] != 0 ) { prm_rf = &hRF->rf_indx_gain[0][nSubfr]; encode_acelp_gains_fx( code, acelp_cfg->gains_mode[j_subfr], Es_pred_rf, - clip_gain, &g_corr, &gain_pit, &gain_code, &prm_rf, &past_gcode, - &gain_inov, L_SUBFR, code2, &gain_code2, st->flag_noisy_speech_snr_fx ); + clip_gain, &g_corr, &gain_pit, &gain_code, &prm_rf, &past_gcode, + &gain_inov, L_SUBFR, code2, &gain_code2, st->flag_noisy_speech_snr_fx ); } - - gp_clip_test_gain_pit_fx(st->element_mode, st->core_brate, gain_pit, hRF->rf_clip_var ); + gp_clip_test_gain_pit_fx( st->element_mode, st->core_brate, gain_pit, hRF->rf_clip_var ); gain_code_vect[0] = gain_code; move32(); @@ -418,127 +419,122 @@ void coder_acelp_rf_fx( move32(); /*----------------------------------------------------------* - * - voice factor (for pitch enhancement) * - *----------------------------------------------------------*/ + * - voice factor (for pitch enhancement) * + *----------------------------------------------------------*/ E_UTIL_voice_factor( exc_rf, i_subfr, code, gain_pit, gain_code, - &voice_fac, &(hRF->rf_tilt_code), L_SUBFR, acelp_cfg->voice_tilt, Q_new, shift); + &voice_fac, &( hRF->rf_tilt_code ), L_SUBFR, acelp_cfg->voice_tilt, Q_new, shift ); /*-----------------------------------------------------------------* * Update memory of the weighting filter *-----------------------------------------------------------------*/ /* st_fx->_rf_mem_w0 = xn[L_SUBFR-1] - (gain_pit*y1[L_SUBFR-1]) - (gain_code*y2[L_SUBFR-1]); */ - Ltmp = Mpy_32_16_1(gain_code, y2[L_SUBFR-1]); + Ltmp = Mpy_32_16_1( gain_code, y2[L_SUBFR - 1] ); #ifdef BASOP_NOGLOB - Ltmp = L_shl_o(Ltmp, add(5,Q_xn), &Overflow); - Ltmp = L_mac_o(Ltmp, y1[L_SUBFR-1], gain_pit, &Overflow); + Ltmp = L_shl_o( Ltmp, add( 5, Q_xn ), &Overflow ); + Ltmp = L_mac_o( Ltmp, y1[L_SUBFR - 1], gain_pit, &Overflow ); #else - Ltmp = L_shl(Ltmp, add(5,Q_xn)); - Ltmp = L_mac(Ltmp, y1[L_SUBFR-1], gain_pit); + Ltmp = L_shl( Ltmp, add( 5, Q_xn ) ); + Ltmp = L_mac( Ltmp, y1[L_SUBFR - 1], gain_pit ); #endif /* Add Gaussian contribution*/ - Ltmp2 = Mpy_32_16_1(gain_code2, y22[L_SUBFR-1]); + Ltmp2 = Mpy_32_16_1( gain_code2, y22[L_SUBFR - 1] ); #ifdef BASOP_NOGLOB - Ltmp2 = L_shl_o(Ltmp2, add(5,Q_xn), &Overflow); - Ltmp = L_add_o(Ltmp, Ltmp2, &Overflow); - hRF->rf_mem_w0 =sub_o(xn[L_SUBFR-1], round_fx_o(L_shl_o(Ltmp, 1, &Overflow), &Overflow), &Overflow); + Ltmp2 = L_shl_o( Ltmp2, add( 5, Q_xn ), &Overflow ); + Ltmp = L_add_o( Ltmp, Ltmp2, &Overflow ); + hRF->rf_mem_w0 = sub_o( xn[L_SUBFR - 1], round_fx_o( L_shl_o( Ltmp, 1, &Overflow ), &Overflow ), &Overflow ); move16(); - hRF->rf_mem_w0 =shr_o(hRF->rf_mem_w0, shift, &Overflow); /*Qnew-1*/ + hRF->rf_mem_w0 = shr_o( hRF->rf_mem_w0, shift, &Overflow ); /*Qnew-1*/ #else - Ltmp2 = L_shl(Ltmp2, add(5,Q_xn)); - Ltmp = L_add(Ltmp, Ltmp2); - hRF->rf_mem_w0 =sub(xn[L_SUBFR-1], round_fx(L_shl(Ltmp, 1))); + Ltmp2 = L_shl( Ltmp2, add( 5, Q_xn ) ); + Ltmp = L_add( Ltmp, Ltmp2 ); + hRF->rf_mem_w0 = sub( xn[L_SUBFR - 1], round_fx( L_shl( Ltmp, 1 ) ) ); move16(); BASOP_SATURATE_WARNING_OFF_EVS; - hRF->rf_mem_w0 =shr(hRF->rf_mem_w0, shift); /*Qnew-1*/ + hRF->rf_mem_w0 = shr( hRF->rf_mem_w0, shift ); /*Qnew-1*/ BASOP_SATURATE_WARNING_ON_EVS; #endif /*-------------------------------------------------------* - * - Find the total excitation. * - *-------------------------------------------------------*/ + * - Find the total excitation. * + *-------------------------------------------------------*/ - tmp2 = shr(L_SUBFR, 1); - FOR (j = 0; j < 2; j++) + tmp2 = shr( L_SUBFR, 1 ); + FOR( j = 0; j < 2; j++ ) { - FOR (i = sub(tmp2, shr(L_SUBFR, 1)); i < tmp2; i++) + FOR( i = sub( tmp2, shr( L_SUBFR, 1 ) ); i < tmp2; i++ ) { /* code in Q9, gain_pit in Q14; exc Q_new */ - Ltmp = Mpy_32_16_1(gain_code2, code2[i]); + Ltmp = Mpy_32_16_1( gain_code2, code2[i] ); #ifdef BASOP_NOGLOB - Ltmp = L_shl_o(Ltmp, Q_new_p5, &Overflow); - Ltmp = L_mac_o(Ltmp, gain_pit, exc_rf[i+i_subfr], &Overflow); - exc2[i] = round_fx_o(L_shl_o(Ltmp, 1, &Overflow), &Overflow); + Ltmp = L_shl_o( Ltmp, Q_new_p5, &Overflow ); + Ltmp = L_mac_o( Ltmp, gain_pit, exc_rf[i + i_subfr], &Overflow ); + exc2[i] = round_fx_o( L_shl_o( Ltmp, 1, &Overflow ), &Overflow ); #else - Ltmp = L_shl(Ltmp, Q_new_p5); - Ltmp = L_mac(Ltmp, gain_pit, exc_rf[i+i_subfr]); + Ltmp = L_shl( Ltmp, Q_new_p5 ); + Ltmp = L_mac( Ltmp, gain_pit, exc_rf[i + i_subfr] ); BASOP_SATURATE_WARNING_OFF_EVS - exc2[i] = round_fx(L_shl(Ltmp, 1)); + exc2[i] = round_fx( L_shl( Ltmp, 1 ) ); BASOP_SATURATE_WARNING_ON_EVS #endif - Ltmp2 = Mpy_32_16_1(gain_code_vect[j], code[i]); + Ltmp2 = Mpy_32_16_1( gain_code_vect[j], code[i] ); #ifdef BASOP_NOGLOB - Ltmp2 = L_shl_o(Ltmp2, Q_new_p5, &Overflow); - Ltmp = L_add_o(Ltmp, Ltmp2, &Overflow); - Ltmp = L_shl_o(Ltmp, 1, &Overflow); /* saturation can occur here */ - exc_rf[i + i_subfr] = round_fx_o(Ltmp, &Overflow); + Ltmp2 = L_shl_o( Ltmp2, Q_new_p5, &Overflow ); + Ltmp = L_add_o( Ltmp, Ltmp2, &Overflow ); + Ltmp = L_shl_o( Ltmp, 1, &Overflow ); /* saturation can occur here */ + exc_rf[i + i_subfr] = round_fx_o( Ltmp, &Overflow ); #else - Ltmp2 = L_shl(Ltmp2, Q_new_p5); - Ltmp = L_add(Ltmp, Ltmp2); + Ltmp2 = L_shl( Ltmp2, Q_new_p5 ); + Ltmp = L_add( Ltmp, Ltmp2 ); BASOP_SATURATE_WARNING_OFF_EVS - Ltmp = L_shl(Ltmp, 1); /* saturation can occur here */ + Ltmp = L_shl( Ltmp, 1 ); /* saturation can occur here */ BASOP_SATURATE_WARNING_ON_EVS - exc_rf[i + i_subfr] = round_fx(Ltmp); + exc_rf[i + i_subfr] = round_fx( Ltmp ); #endif } tmp2 = L_SUBFR; } - /*---------------------------------------------------------* - * Enhance the excitation * - *---------------------------------------------------------*/ - E_UTIL_enhancer( voice_fac, stab_fac, past_gcode, gain_inov, - &hRF->rf_gc_threshold, code, exc2, gain_pit, &hRF->rf_dm_fx.prev_gain_code, - hRF->rf_dm_fx.prev_gain_pit, &hRF->rf_dm_fx.prev_state, coder_type, - acelp_cfg->fixed_cdk_index[j_subfr], L_SUBFR, L_frame, Q_new ); + * Enhance the excitation * + *---------------------------------------------------------*/ + E_UTIL_enhancer( voice_fac, stab_fac, past_gcode, gain_inov, + &hRF->rf_gc_threshold, code, exc2, gain_pit, &hRF->rf_dm_fx.prev_gain_code, + hRF->rf_dm_fx.prev_gain_pit, &hRF->rf_dm_fx.prev_state, coder_type, + acelp_cfg->fixed_cdk_index[j_subfr], L_SUBFR, L_frame, Q_new ); } } - IF( i_subfr < sub(L_frame,L_SUBFR) || NE_16(rf_frame_type,RF_NELP) ) + IF( i_subfr < sub( L_frame, L_SUBFR ) || NE_16( rf_frame_type, RF_NELP ) ) { /*----------------------------------------------------------* - * - compute the synthesis speech * - *----------------------------------------------------------*/ + * - compute the synthesis speech * + *----------------------------------------------------------*/ - E_UTIL_synthesis(1, p_Aq, exc2, &syn2[i_subfr], L_SUBFR, hRF->rf_mem_syn2, 1, M); + E_UTIL_synthesis( 1, p_Aq, exc2, &syn2[i_subfr], L_SUBFR, hRF->rf_mem_syn2, 1, M ); - E_UTIL_synthesis(1, p_Aq, &exc_rf[i_subfr], &syn_rf[i_subfr], L_SUBFR, &syn_rf[i_subfr-M], 0, M); + E_UTIL_synthesis( 1, p_Aq, &exc_rf[i_subfr], &syn_rf[i_subfr], L_SUBFR, &syn_rf[i_subfr - M], 0, M ); /*----------------------------------------------------------* - * Update * - *----------------------------------------------------------*/ - p_A += (M+1); - p_Aq += (M+1); + * Update * + *----------------------------------------------------------*/ + p_A += ( M + 1 ); + p_Aq += ( M + 1 ); nSubfr++; st->gain_code[j_subfr] = gain_code; - j_subfr = add(j_subfr, 1); + j_subfr = add( j_subfr, 1 ); /* copy current gain for next subframe use, in case there is no explicit encoding */ prev_gain_pit = gain_pit; - } - } /* end of subframe loop */ return; } - - diff --git a/lib_enc/enc_higher_acelp_fx.c b/lib_enc/enc_higher_acelp_fx.c index 939632ebc..a67071533 100644 --- a/lib_enc/enc_higher_acelp_fx.c +++ b/lib_enc/enc_higher_acelp_fx.c @@ -2,10 +2,10 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ //#include "prot_fx.h" /* Function prototypes */ -#include "rom_com_fx.h" /* Static table prototypes */ +#include "rom_com_fx.h" /* Static table prototypes */ #include "rom_com.h" /* Static table prototypes */ #include "prot_fx1.h" #include "prot_fx2.h" @@ -21,36 +21,36 @@ static void find_cn_fx( const Word16 xn[], const Word16 Ap[], const Word16 *p_Aq *-----------------------------------------------------------------*/ #define Q_MINUS 4 void transf_cdbk_enc_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 harm_flag_acelp,/* i : harmonic flag for higher rates ACELP */ - const Word16 i_subfr, /* i : subframe index */ - Word16 cn[], /* i/o: target vector in residual domain */ - Word16 exc[], /* i/o: pointer to excitation signal frame */ - const Word16 *p_Aq, /* i : 12k8 Lp coefficient */ - const Word16 Ap[], /* i : weighted LP filter coefficients */ - const Word16 h1[], /* i : weighted filter input response */ - Word16 xn[], /* i/o: target vector */ - Word16 xn2[], /* i/o: target vector for innovation search */ - Word16 y1[], /* i/o: zero-memory filtered adaptive excitation */ - const Word16 y2[], /* i : zero-memory filtered innovative excitation */ - const Word16 Es_pred, /* i : predicited scaled innovation energy */ - Word16 *gain_pit, /* i/o: adaptive excitation gain */ - const Word32 gain_code, /* i : innovative excitation gain */ - Word16 g_corr[], /* o : ACELP correlation values */ - const Word16 clip_gain, /* i : adaptive gain clipping flag */ - Word16 *gain_preQ, /* o : prequantizer excitation gain */ - Word16 code_preQ[], /* o : prequantizer excitation */ - Word16 *unbits, /* o : number of AVQ unused bits */ - const Word16 Q_new, /* i : Current frame scaling */ - const Word16 shift /* i : shifting applied to y1, xn,... */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word16 harm_flag_acelp, /* i : harmonic flag for higher rates ACELP */ + const Word16 i_subfr, /* i : subframe index */ + Word16 cn[], /* i/o: target vector in residual domain */ + Word16 exc[], /* i/o: pointer to excitation signal frame */ + const Word16 *p_Aq, /* i : 12k8 Lp coefficient */ + const Word16 Ap[], /* i : weighted LP filter coefficients */ + const Word16 h1[], /* i : weighted filter input response */ + Word16 xn[], /* i/o: target vector */ + Word16 xn2[], /* i/o: target vector for innovation search */ + Word16 y1[], /* i/o: zero-memory filtered adaptive excitation */ + const Word16 y2[], /* i : zero-memory filtered innovative excitation */ + const Word16 Es_pred, /* i : predicited scaled innovation energy */ + Word16 *gain_pit, /* i/o: adaptive excitation gain */ + const Word32 gain_code, /* i : innovative excitation gain */ + Word16 g_corr[], /* o : ACELP correlation values */ + const Word16 clip_gain, /* i : adaptive gain clipping flag */ + Word16 *gain_preQ, /* o : prequantizer excitation gain */ + Word16 code_preQ[], /* o : prequantizer excitation */ + Word16 *unbits, /* o : number of AVQ unused bits */ + const Word16 Q_new, /* i : Current frame scaling */ + const Word16 shift /* i : shifting applied to y1, xn,... */ ) { Word16 i, index, nBits, Nsv, Es_pred_loc; Word16 x_in[L_SUBFR], x_tran[L_SUBFR], gcode16, stmp; Word16 e_corr, m_corr, e_ener, m_ener, m_den, e_den; - Word16 x_norm[L_SUBFR+L_SUBFR/WIDTH_BAND]; + Word16 x_norm[L_SUBFR + L_SUBFR / WIDTH_BAND]; Word32 L_corr, L_ener, Ltmp, Ltmp1; - Word16 nq[L_SUBFR/WIDTH_BAND]; + Word16 nq[L_SUBFR / WIDTH_BAND]; Word32 out32[L_SUBFR]; Word16 Qdct; Word16 avq_bit_sFlag; @@ -61,7 +61,7 @@ void transf_cdbk_enc_fx( avq_bit_sFlag = 0; move16(); - if (GT_16(st_fx->element_mode, EVS_MONO)) + if ( GT_16( st_fx->element_mode, EVS_MONO ) ) { avq_bit_sFlag = 1; move16(); @@ -73,38 +73,38 @@ void transf_cdbk_enc_fx( Nsv = 8; move16(); - nBits = st_fx->acelp_cfg.AVQ_cdk_bits[shr(i_subfr, 6)]; + nBits = st_fx->acelp_cfg.AVQ_cdk_bits[shr( i_subfr, 6 )]; move16(); /* increase # of AVQ allocated bits by unused bits from the previous subframe */ - nBits = add(nBits, *unbits); + nBits = add( nBits, *unbits ); /*--------------------------------------------------------------* * Compute/Update target * For inactive frame, find target in residual domain * Deemphasis *--------------------------------------------------------------*/ - IF (EQ_16(st_fx->coder_type,INACTIVE)) + IF( EQ_16( st_fx->coder_type, INACTIVE ) ) { #ifdef BASOP_NOGLOB - gcode16 = round_fx_o(L_shl_o(gain_code, Q_new, &Overflow), &Overflow); + gcode16 = round_fx_o( L_shl_o( gain_code, Q_new, &Overflow ), &Overflow ); #else - gcode16 = round_fx(L_shl(gain_code, Q_new)); + gcode16 = round_fx( L_shl( gain_code, Q_new ) ); #endif - FOR( i=0; imem_deemp_preQ_fx) ); + Deemph2( x_in, FAC_PRE_AVQ_FX, L_SUBFR, &( st_fx->mem_deemp_preQ_fx ) ); /*--------------------------------------------------------------* * DCT-II @@ -122,20 +122,20 @@ void transf_cdbk_enc_fx( test(); test(); test(); - IF( NE_16(st_fx->coder_type,INACTIVE) && LE_32(st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD) && GE_32(st_fx->core_brate, MIN_BRATE_AVQ_EXC) && !harm_flag_acelp) + IF( NE_16( st_fx->coder_type, INACTIVE ) && LE_32( st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD ) && GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && !harm_flag_acelp ) { - Copy_Scale_sig( x_in, x_tran, L_SUBFR,-Q_MINUS+1 ); /*Q_new-1 -> Q_new-4*/ + Copy_Scale_sig( x_in, x_tran, L_SUBFR, -Q_MINUS + 1 ); /*Q_new-1 -> Q_new-4*/ /*Copy( x_in, x_tran, L_SUBFR );*/ - Qdct = sub(Q_new,Q_MINUS); + Qdct = sub( Q_new, Q_MINUS ); } ELSE { Qdct = 0; move16(); edct2_fx( L_SUBFR, -1, x_in, out32, &Qdct, ip_edct2_64, w_edct2_64_fx ); - Qdct = negate(Qdct); - Copy_Scale_sig_32_16(out32, x_tran, L_SUBFR, sub(Qdct,Q_MINUS-1)); /* Output in Q_new-4 */ - Qdct = sub(Q_new,Q_MINUS); + Qdct = negate( Qdct ); + Copy_Scale_sig_32_16( out32, x_tran, L_SUBFR, sub( Qdct, Q_MINUS - 1 ) ); /* Output in Q_new-4 */ + Qdct = sub( Q_new, Q_MINUS ); } /*--------------------------------------------------------------* @@ -147,66 +147,66 @@ void transf_cdbk_enc_fx( * Find prequantizer excitation gain * Quantize the gain *--------------------------------------------------------------*/ - L_corr = L_deposit_l(0); - L_ener = L_deposit_l(0); - FOR (i = 0; i < Nsv*8; i++) + L_corr = L_deposit_l( 0 ); + L_ener = L_deposit_l( 0 ); + FOR( i = 0; i < Nsv * 8; i++ ) { /*fcorr += fx_tran[i]*(float)ix_norm[i];*/ /*fener += (float)ix_norm[i]*(float)ix_norm[i];*/ #ifdef BASOP_NOGLOB stmp = shl_sat( x_norm[i], Q_AVQ_OUT ); L_corr = L_mac_sat( L_corr, x_tran[i], stmp ); - L_ener = L_mac_sat(L_ener, stmp, stmp); + L_ener = L_mac_sat( L_ener, stmp, stmp ); #else stmp = shl( x_norm[i], Q_AVQ_OUT ); L_corr = L_mac( L_corr, x_tran[i], stmp ); - L_ener = L_mac(L_ener, stmp, stmp); + L_ener = L_mac( L_ener, stmp, stmp ); #endif } - L_ener = L_max(L_ener,1); + L_ener = L_max( L_ener, 1 ); /* No negative gains allowed in the quantizer*/ - L_corr = L_max(L_corr,0); + L_corr = L_max( L_corr, 0 ); - e_corr = norm_l(L_corr); - m_corr = extract_h(L_shl(L_corr, e_corr)); - e_corr = sub(30, add(e_corr,sub(Qdct,Q_AVQ_OUT))); - e_ener = norm_l(L_ener); - m_ener = extract_h(L_shl(L_ener, e_ener)); - e_ener = sub(30, e_ener); + e_corr = norm_l( L_corr ); + m_corr = extract_h( L_shl( L_corr, e_corr ) ); + e_corr = sub( 30, add( e_corr, sub( Qdct, Q_AVQ_OUT ) ) ); + e_ener = norm_l( L_ener ); + m_ener = extract_h( L_shl( L_ener, e_ener ) ); + e_ener = sub( 30, e_ener ); - IF(GT_16(m_corr,m_ener)) + IF( GT_16( m_corr, m_ener ) ) { - m_corr = shr(m_corr,1); - e_corr = add(e_corr,1); + m_corr = shr( m_corr, 1 ); + e_corr = add( e_corr, 1 ); } - m_corr = div_s(m_corr, m_ener); - e_corr = sub(e_corr, e_ener); + m_corr = div_s( m_corr, m_ener ); + e_corr = sub( e_corr, e_ener ); #ifdef BASOP_NOGLOB Ltmp = L_shl_sat( m_corr, s_min( add( e_corr, 1 ), 31 ) ); /* Lgain in Q16 */ #else - Ltmp = L_shl(m_corr, s_min(add(e_corr,1),31)); /* Lgain in Q16 */ + Ltmp = L_shl( m_corr, s_min( add( e_corr, 1 ), 31 ) ); /* Lgain in Q16 */ #endif - IF ( EQ_16(st_fx->coder_type,INACTIVE)) + IF( EQ_16( st_fx->coder_type, INACTIVE ) ) { - Ltmp1 = L_max(gain_code,1); - e_den = norm_l(Ltmp1); + Ltmp1 = L_max( gain_code, 1 ); + e_den = norm_l( Ltmp1 ); #ifdef BASOP_NOGLOB m_den = extract_h( L_shl_sat( Ltmp1, e_den ) ); #else - m_den = extract_h(L_shl(Ltmp1, e_den)); + m_den = extract_h( L_shl( Ltmp1, e_den ) ); #endif /* ensure m_corr < m_den */ test(); - IF( m_corr>0 && m_den >0) + IF( m_corr > 0 && m_den > 0 ) { - m_corr = div_s(16384, m_den); - e_corr = sub(14+4, e_den); - Ltmp = L_shr(Mult_32_16(Ltmp, m_corr), e_corr); /*Q12*/ + m_corr = div_s( 16384, m_den ); + e_corr = sub( 14 + 4, e_den ); + Ltmp = L_shr( Mult_32_16( Ltmp, m_corr ), e_corr ); /*Q12*/ #ifdef BASOP_NOGLOB - stmp = round_fx_o(L_shl_o(Ltmp,16, &Overflow), &Overflow); + stmp = round_fx_o( L_shl_o( Ltmp, 16, &Overflow ), &Overflow ); #else - stmp = round_fx(L_shl(Ltmp,16)); + stmp = round_fx( L_shl( Ltmp, 16 ) ); #endif } ELSE @@ -214,32 +214,32 @@ void transf_cdbk_enc_fx( stmp = 0; move16(); } - IF( GT_32(st_fx->core_brate,56000)) + IF( GT_32( st_fx->core_brate, 56000 ) ) { - index = usquant_fx( stmp, &stmp, G_AVQ_MIN_INACT_64k_Q12, G_AVQ_DELTA_INACT_64k_Q12>>1, (1 << G_AVQ_BITS) ); + index = usquant_fx( stmp, &stmp, G_AVQ_MIN_INACT_64k_Q12, G_AVQ_DELTA_INACT_64k_Q12 >> 1, ( 1 << G_AVQ_BITS ) ); } - ELSE IF( GT_32(st_fx->core_brate,42000)) + ELSE IF( GT_32( st_fx->core_brate, 42000 ) ) { - index = usquant_fx( stmp, &stmp, G_AVQ_MIN_INACT_48k_Q12, G_AVQ_DELTA_INACT_48k_Q12>>1, (1 << G_AVQ_BITS) ); + index = usquant_fx( stmp, &stmp, G_AVQ_MIN_INACT_48k_Q12, G_AVQ_DELTA_INACT_48k_Q12 >> 1, ( 1 << G_AVQ_BITS ) ); } ELSE { - index = usquant_fx( stmp, &stmp, G_AVQ_MIN_INACT_Q12, G_AVQ_DELTA_INACT_Q12>>1, (1 << G_AVQ_BITS) ); + index = usquant_fx( stmp, &stmp, G_AVQ_MIN_INACT_Q12, G_AVQ_DELTA_INACT_Q12 >> 1, ( 1 << G_AVQ_BITS ) ); } - Ltmp = Mult_32_16(gain_code,stmp); /* Q16 * Q12 - 15 -> Q13*/ + Ltmp = Mult_32_16( gain_code, stmp ); /* Q16 * Q12 - 15 -> Q13*/ #ifdef BASOP_NOGLOB Ltmp = L_shl_sat( Ltmp, 5 ); /* Q13 -> Q18*/ - *gain_preQ = round_fx_sat(Ltmp); /* Q2*/ + *gain_preQ = round_fx_sat( Ltmp ); /* Q2*/ #else - Ltmp = L_shl(Ltmp,5); /* Q13 -> Q18*/ - *gain_preQ = round_fx(Ltmp); /* Q2*/ + Ltmp = L_shl( Ltmp, 5 ); /* Q13 -> Q18*/ + *gain_preQ = round_fx( Ltmp ); /* Q2*/ #endif } ELSE { - IF( Es_pred < 0 ) + IF( Es_pred < 0 ) { - Es_pred_loc = shr(negate(Es_pred),2); + Es_pred_loc = shr( negate( Es_pred ), 2 ); } ELSE { @@ -247,32 +247,32 @@ void transf_cdbk_enc_fx( move16(); } - e_den = norm_s(Es_pred_loc); - m_den = shl(Es_pred_loc, e_den); + e_den = norm_s( Es_pred_loc ); + m_den = shl( Es_pred_loc, e_den ); /* ensure m_corr < m_den */ test(); - IF( m_corr>0 && m_den >0) + IF( m_corr > 0 && m_den > 0 ) { - m_corr = div_s(16384, m_den); - e_corr = sub(14-8, e_den); - Ltmp = L_shr(Mult_32_16(Ltmp, m_corr), e_corr); + m_corr = div_s( 16384, m_den ); + e_corr = sub( 14 - 8, e_den ); + Ltmp = L_shr( Mult_32_16( Ltmp, m_corr ), e_corr ); } ELSE { - Ltmp = L_deposit_l(0); + Ltmp = L_deposit_l( 0 ); } test(); - IF( LE_32(st_fx->core_brate,42000) && GT_32(st_fx->core_brate ,ACELP_24k40)) + IF( LE_32( st_fx->core_brate, 42000 ) && GT_32( st_fx->core_brate, ACELP_24k40 ) ) { - index = gain_quant_fx(&Ltmp, &stmp, LG10_G_AVQ_MIN_32kbps_Q14, LG10_G_AVQ_MAX_Q13, G_AVQ_BITS, &e_den ); + index = gain_quant_fx( &Ltmp, &stmp, LG10_G_AVQ_MIN_32kbps_Q14, LG10_G_AVQ_MAX_Q13, G_AVQ_BITS, &e_den ); } ELSE { - index = gain_quant_fx(&Ltmp, &stmp, LG10_G_AVQ_MIN_Q14, LG10_G_AVQ_MAX_Q13, G_AVQ_BITS, &e_den ); + index = gain_quant_fx( &Ltmp, &stmp, LG10_G_AVQ_MIN_Q14, LG10_G_AVQ_MAX_Q13, G_AVQ_BITS, &e_den ); } - Ltmp = L_mult(stmp,Es_pred_loc); /* Q0*Q8 -> Q9*/ - Ltmp = L_shl(Ltmp,add(e_den,9)); /* Q18*/ - *gain_preQ = round_fx(Ltmp); /* Q2*/ + Ltmp = L_mult( stmp, Es_pred_loc ); /* Q0*Q8 -> Q9*/ + Ltmp = L_shl( Ltmp, add( e_den, 9 ) ); /* Q18*/ + *gain_preQ = round_fx( Ltmp ); /* Q2*/ } push_indice_fx( st_fx->hBstr, IND_AVQ_GAIN, index, G_AVQ_BITS ); @@ -281,16 +281,20 @@ void transf_cdbk_enc_fx( *--------------------------------------------------------------*/ trgtSvPos = Nsv - 1; move16(); - test();test();test();test();test(); - IF (avq_bit_sFlag && GT_16(nBits, 85) && !harm_flag_acelp && (EQ_16(st_fx->coder_type, GENERIC) || - EQ_16(st_fx->coder_type, TRANSITION) || EQ_16(st_fx->coder_type, INACTIVE) )) + test(); + test(); + test(); + test(); + test(); + IF( avq_bit_sFlag && GT_16( nBits, 85 ) && !harm_flag_acelp && ( EQ_16( st_fx->coder_type, GENERIC ) || EQ_16( st_fx->coder_type, TRANSITION ) || EQ_16( st_fx->coder_type, INACTIVE ) ) ) { trgtSvPos = 2; avq_bit_sFlag = 2; - move16();move16(); + move16(); + move16(); } - AVQ_encmux_fx( st_fx->hBstr, -1, x_norm, &nBits, Nsv, nq, avq_bit_sFlag, trgtSvPos); + AVQ_encmux_fx( st_fx->hBstr, -1, x_norm, &nBits, Nsv, nq, avq_bit_sFlag, trgtSvPos ); /* save # of AVQ unused bits for next subframe */ *unbits = nBits; @@ -299,11 +303,11 @@ void transf_cdbk_enc_fx( /* at the last subframe, write AVQ unused bits */ test(); test(); - IF( EQ_16(i_subfr,4*L_SUBFR) && NE_16(st_fx->extl,SWB_BWE_HIGHRATE) && NE_16(st_fx->extl,FB_BWE_HIGHRATE)) + IF( EQ_16( i_subfr, 4 * L_SUBFR ) && NE_16( st_fx->extl, SWB_BWE_HIGHRATE ) && NE_16( st_fx->extl, FB_BWE_HIGHRATE ) ) { WHILE( *unbits > 0 ) { - i = s_min(*unbits, 16); + i = s_min( *unbits, 16 ); push_indice_fx( st_fx->hBstr, IND_UNUSED, 0, i ); *unbits -= i; } @@ -313,21 +317,21 @@ void transf_cdbk_enc_fx( * DCT transform *--------------------------------------------------------------*/ - FOR( i=0; icoder_type,INACTIVE) && LE_32(st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD) && GE_32(st_fx->core_brate, MIN_BRATE_AVQ_EXC) && !harm_flag_acelp) + IF( NE_16( st_fx->coder_type, INACTIVE ) && LE_32( st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD ) && GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && !harm_flag_acelp ) { Copy( x_tran, code_preQ, L_SUBFR ); } @@ -337,8 +341,8 @@ void transf_cdbk_enc_fx( move16(); edct2_fx( L_SUBFR, 1, x_tran, out32, &Qdct, ip_edct2_64, w_edct2_64_fx ); /*qdct = sub(Q_AVQ_OUT_DEC,qdct+Q_AVQ_OUT_DEC);*/ - Qdct = negate(Qdct); - Copy_Scale_sig_32_16(out32, code_preQ, L_SUBFR, Qdct); /* Output in Q_AVQ_OUT_DEC */ + Qdct = negate( Qdct ); + Copy_Scale_sig_32_16( out32, code_preQ, L_SUBFR, Qdct ); /* Output in Q_AVQ_OUT_DEC */ /*qdct = Q_AVQ_OUT_DEC;*/ } @@ -347,31 +351,31 @@ void transf_cdbk_enc_fx( *--------------------------------------------------------------*/ /* in extreme cases at subframe boundaries, lower the preemphasis memory to avoid a saturation */ test(); - if( (nq[7] != 0) && (GT_16( sub(st_fx->last_nq_preQ, nq[0]), 7))) + if ( ( nq[7] != 0 ) && ( GT_16( sub( st_fx->last_nq_preQ, nq[0] ), 7 ) ) ) { /* *mem_preemp /= 16; */ - st_fx->mem_preemp_preQ_fx = shr(st_fx->mem_preemp_preQ_fx,4); + st_fx->mem_preemp_preQ_fx = shr( st_fx->mem_preemp_preQ_fx, 4 ); move16(); } st_fx->last_nq_preQ = nq[7]; move16(); #ifdef IVAS_CODE /* TD pre-quantizer: in extreme cases at subframe boundaries, lower the preemphasis memory to avoid a saturation */ - if (st->element_mode > EVS_MONO && st->coder_type != INACTIVE && st->core_brate >= MIN_BRATE_AVQ_EXC && st->core_brate <= MAX_BRATE_AVQ_EXC_TD && !harm_flag_acelp && code_preQ[0] != 0) + if ( st->element_mode > EVS_MONO && st->coder_type != INACTIVE && st->core_brate >= MIN_BRATE_AVQ_EXC && st->core_brate <= MAX_BRATE_AVQ_EXC_TD && !harm_flag_acelp && code_preQ[0] != 0 ) { - if ((float)abs(st->last_code_preq) > 16.0f * (float)fabs(code_preQ[0])) + if ( (float) abs( st->last_code_preq ) > 16.0f * (float) fabs( code_preQ[0] ) ) { st->mem_preemp_preQ /= 16; } - else if ((float)abs(st->last_code_preq) > 8.0f * (float)fabs(code_preQ[0])) + else if ( (float) abs( st->last_code_preq ) > 8.0f * (float) fabs( code_preQ[0] ) ) { st->mem_preemp_preQ /= 8; } } - st->last_code_preq = (int16_t)code_preQ[L_SUBFR - 1]; + st->last_code_preq = (int16_t) code_preQ[L_SUBFR - 1]; #endif - preemph_fx( code_preQ, FAC_PRE_AVQ_FX, L_SUBFR, &(st_fx->mem_preemp_preQ_fx)); + preemph_fx( code_preQ, FAC_PRE_AVQ_FX, L_SUBFR, &( st_fx->mem_preemp_preQ_fx ) ); /*--------------------------------------------------------------* * For inactive segments @@ -381,25 +385,25 @@ void transf_cdbk_enc_fx( * - Update xn[L_subfr-1] for updating the memory of the weighting filter *--------------------------------------------------------------*/ - IF ( EQ_16(st_fx->coder_type,INACTIVE)) + IF( EQ_16( st_fx->coder_type, INACTIVE ) ) { /*ftemp = fcode_preQ[0] *fh1[L_SUBFR-1];*/ - Ltmp = L_mult(code_preQ[0], h1[L_SUBFR-1]); /*1+14+shift + Q_AVQ_OUT */ - FOR( i=1; i Q_new + shift -1 */ + Ltmp = L_shr( Mult_32_16( Ltmp, *gain_preQ ), sub( add( Q_AVQ_OUT_DEC, 2 ), Q_new ) ); /* (2 + 1 + 14 +shift+Q_AVQ_OUT)-(Q_AVQ_OUT+2-Q_new) = 15 + Q_new + shift */ + xn[L_SUBFR - 1] = round_fx( L_sub( L_mult( xn[L_SUBFR - 1], 32767 ), Ltmp ) ); /* -> Q_new + shift -1 */ } ELSE { conv_fx( code_preQ, h1, x_tran, L_SUBFR ); - updt_tar_HR_fx( cn, cn, code_preQ, *gain_preQ, sub(Q_new, add(-15+2,Q_AVQ_OUT_DEC)), L_SUBFR ); + updt_tar_HR_fx( cn, cn, code_preQ, *gain_preQ, sub( Q_new, add( -15 + 2, Q_AVQ_OUT_DEC ) ), L_SUBFR ); - updt_tar_HR_fx( xn, xn, x_tran, *gain_preQ, sub(Q_new, add(-15+2,Q_AVQ_OUT_DEC)), L_SUBFR ); + updt_tar_HR_fx( xn, xn, x_tran, *gain_preQ, sub( Q_new, add( -15 + 2, Q_AVQ_OUT_DEC ) ), L_SUBFR ); #ifdef BASOP_NOGLOB *gain_pit = corr_xy1_fx( xn, y1, g_corr, L_SUBFR, 0, &Overflow ); #else @@ -407,7 +411,7 @@ void transf_cdbk_enc_fx( #endif /* clip gain if necessary to avoid problems at decoder */ test(); - if( EQ_16(clip_gain,1)&>_16(*gain_pit,15565)) + if ( EQ_16( clip_gain, 1 ) && GT_16( *gain_pit, 15565 ) ) { *gain_pit = 15565; move16(); @@ -419,28 +423,27 @@ void transf_cdbk_enc_fx( move16(); return; - } /*-------------------------------------------------------------------* * Find target in residual domain - cn[] *-------------------------------------------------------------------*/ static void find_cn_fx( - const Word16 xn[], /* i : target signal */ - const Word16 Ap[], /* i : weighted LP filter coefficients */ - const Word16 *p_Aq, /* i : 12k8 LP coefficients */ - Word16 cn[] /* o : target signal in residual domain */ + const Word16 xn[], /* i : target signal */ + const Word16 Ap[], /* i : weighted LP filter coefficients */ + const Word16 *p_Aq, /* i : 12k8 LP coefficients */ + Word16 cn[] /* o : target signal in residual domain */ ) { - Word16 tmp, tmp_fl[L_SUBFR+M]; + Word16 tmp, tmp_fl[L_SUBFR + M]; set16_fx( tmp_fl, 0, M ); - Copy( xn, tmp_fl+M, L_SUBFR ); + Copy( xn, tmp_fl + M, L_SUBFR ); tmp = 0; move16(); - preemph_fx( tmp_fl+M, PREEMPH_FAC_16k, L_SUBFR, &tmp ); - syn_filt_s_lc_fx(0, Ap, tmp_fl+M, tmp_fl+M, L_SUBFR); - Residu3_lc_fx( p_Aq, M, tmp_fl+M, cn, L_SUBFR, 1 ); + preemph_fx( tmp_fl + M, PREEMPH_FAC_16k, L_SUBFR, &tmp ); + syn_filt_s_lc_fx( 0, Ap, tmp_fl + M, tmp_fl + M, L_SUBFR ); + Residu3_lc_fx( p_Aq, M, tmp_fl + M, cn, L_SUBFR, 1 ); return; } @@ -449,13 +452,13 @@ static void find_cn_fx( /*-----------------------------------------------------------------* * Transform domain contribution encoding *-----------------------------------------------------------------*/ -Word16 gain_quant_fx( /* o: quantization index */ - Word32 *gain, /* i: quantized gain (Q16) */ - Word16 *gain16, /* o: quantized gain (expg) */ - const Word16 c_min, /* i: log10 of lower limit in Q14 */ - const Word16 c_max, /* i: log10 of upper limit in Q13 */ - const Word16 bits, /* i: number of bits to quantize */ - Word16 *expg /* o: output exponent of gain16 */ +Word16 gain_quant_fx( /* o: quantization index */ + Word32 *gain, /* i: quantized gain (Q16) */ + Word16 *gain16, /* o: quantized gain (expg) */ + const Word16 c_min, /* i: log10 of lower limit in Q14 */ + const Word16 c_max, /* i: log10 of upper limit in Q13 */ + const Word16 bits, /* i: number of bits to quantize */ + Word16 *expg /* o: output exponent of gain16 */ ) { Word16 index, levels; @@ -464,72 +467,72 @@ Word16 gain_quant_fx( /* o: quantization index */ Word16 tmp, tmp1, tmp2, frac; Word32 L_tmp; - levels = shl(1, bits); + levels = shl( 1, bits ); /* Prevent gain to be smaller than 0.0003. */ /* This is to avoid an overflow when the gain is very small */ /* the log10 give a high negative value in Q13 that overflow */ /* on this code (the resulting value of 'index' is not affected. */ /* tmp2 = msu_r(L_deposit_h(c_gain),c_min,16384) */ - L_tmp = L_max(*gain, 20); + L_tmp = L_max( *gain, 20 ); /*c_min = (float)log10(min);*/ /*c_mult = (float) ((levels-1)/(log10(max)-c_min));*/ /*tmp = c_mult * ((float)log10(*gain) - c_min); - = ((levels-1)/(log10(max)-log10(min)))*((float)log10(*gain) - log10(min));*/ + = ((levels-1)/(log10(max)-log10(min)))*((float)log10(*gain) - log10(min));*/ - e_tmp = norm_l(L_tmp); - f_tmp = Log2_norm_lc(L_shl(L_tmp, e_tmp)); - e_tmp = sub(30-16,e_tmp);/*Q(min)=16*/ - L_tmp = Mpy_32_16(e_tmp, f_tmp, 9864); /* Q16 */ /*log10(2) in Q15*/ - c_gain = round_fx(L_shl(L_tmp, 13)); /* Q13 */ + e_tmp = norm_l( L_tmp ); + f_tmp = Log2_norm_lc( L_shl( L_tmp, e_tmp ) ); + e_tmp = sub( 30 - 16, e_tmp ); /*Q(min)=16*/ + L_tmp = Mpy_32_16( e_tmp, f_tmp, 9864 ); /* Q16 */ /*log10(2) in Q15*/ + c_gain = round_fx( L_shl( L_tmp, 13 ) ); /* Q13 */ /*tmp1 = sub(c_max,c_min); Q14*/ /*tmp2 = sub(c_gain,c_min); Q14*/ #ifdef BASOP_NOGLOB tmp1 = msu_r_sat( L_deposit_h( c_max /*in Q13 already*/ ), c_min, 16384 ); /*Q13*/ - tmp2 = msu_r_sat(L_deposit_h(c_gain/*in Q13 already*/),c_min,16384); /*Q13*/ + tmp2 = msu_r_sat( L_deposit_h( c_gain /*in Q13 already*/ ), c_min, 16384 ); /*Q13*/ #else - tmp1 = msu_r(L_deposit_h(c_max/*in Q13 already*/),c_min, 16384); /*Q13*/ - tmp2 = msu_r(L_deposit_h(c_gain/*in Q13 already*/),c_min,16384); /*Q13*/ + tmp1 = msu_r( L_deposit_h( c_max /*in Q13 already*/ ), c_min, 16384 ); /*Q13*/ + tmp2 = msu_r( L_deposit_h( c_gain /*in Q13 already*/ ), c_min, 16384 ); /*Q13*/ #endif - IF(tmp1 != 0) + IF( tmp1 != 0 ) { - exp = norm_s(tmp1); - frac = div_s(shl(1,sub(14,exp)),tmp1); /*Q(15-exp)*/ - L_tmp = L_mult(tmp2,frac); /*Q(30-exp)*/ - L_tmp = Mult_32_16(L_tmp,sub(levels,1)); /*Q(15-exp)*/ - index = extract_l(L_shr(L_add(L_tmp,shr(1<<14,exp)),sub(15,exp))); + exp = norm_s( tmp1 ); + frac = div_s( shl( 1, sub( 14, exp ) ), tmp1 ); /*Q(15-exp)*/ + L_tmp = L_mult( tmp2, frac ); /*Q(30-exp)*/ + L_tmp = Mult_32_16( L_tmp, sub( levels, 1 ) ); /*Q(15-exp)*/ + index = extract_l( L_shr( L_add( L_tmp, shr( 1 << 14, exp ) ), sub( 15, exp ) ) ); } ELSE { - L_tmp = L_mult(tmp2,sub(levels,1)); /*Q15*/ - index = extract_l(L_shr(L_add(L_tmp,1<<14),15)); + L_tmp = L_mult( tmp2, sub( levels, 1 ) ); /*Q15*/ + index = extract_l( L_shr( L_add( L_tmp, 1 << 14 ), 15 ) ); } - index = s_max(index ,0); - index = s_min(index ,sub(levels,1)); + index = s_max( index, 0 ); + index = s_min( index, sub( levels, 1 ) ); /**gain = (float)pow( 10.0, (((float)index)/c_mult) + c_min ); y = index/c_mult + c_min; = (index/(levels-1))*(log10(max) - log10(min)) + log10(min); = z*log10(max) + (1-z)*log10(min) z = (index/(levels-1))*/ - tmp = div_s(index,sub(levels,1)); /*Q15*/ - L_tmp = L_mult(tmp,c_max);/*Q29*/ - L_tmp = L_mac0(L_tmp,sub(32767,tmp),c_min); /*Q29*/ + tmp = div_s( index, sub( levels, 1 ) ); /*Q15*/ + L_tmp = L_mult( tmp, c_max ); /*Q29*/ + L_tmp = L_mac0( L_tmp, sub( 32767, tmp ), c_min ); /*Q29*/ - L_tmp = Mult_32_16(L_tmp,27213); /*Q27, 3.321928 in Q13*/ - L_tmp = L_shr(L_tmp,11); /*Q27->Q16*/ + L_tmp = Mult_32_16( L_tmp, 27213 ); /*Q27, 3.321928 in Q13*/ + L_tmp = L_shr( L_tmp, 11 ); /*Q27->Q16*/ - frac = L_Extract_lc(L_tmp, expg); /* Extract exponent of gcode0 */ + frac = L_Extract_lc( L_tmp, expg ); /* Extract exponent of gcode0 */ - *gain16 = extract_l(Pow2(14, frac));/* Put 14 as exponent so that */ + *gain16 = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ - *expg = sub(*expg, 14); + *expg = sub( *expg, 14 ); move16(); - return(index); + return ( index ); } diff --git a/lib_enc/enc_nelp.c b/lib_enc/enc_nelp.c index 3a06b5daf..f151bc085 100644 --- a/lib_enc/enc_nelp.c +++ b/lib_enc/enc_nelp.c @@ -79,7 +79,7 @@ void encod_nelp( { set_f( hSC_VBR->nelp_lp_fit_mem_flt, 0, NELP_LP_ORDER * 2 ); } - polezero_filter( res, res, L_FRAME, num_nelp_lp, den_nelp_lp, NELP_LP_ORDER, hSC_VBR->nelp_lp_fit_mem_flt); /*16-Q of filter coeff*/ + polezero_filter( res, res, L_FRAME, num_nelp_lp, den_nelp_lp, NELP_LP_ORDER, hSC_VBR->nelp_lp_fit_mem_flt ); /*16-Q of filter coeff*/ } p_Aw = Aw; diff --git a/lib_enc/enc_nelp_fx.c b/lib_enc/enc_nelp_fx.c index 1ba66f9bf..bca4d2a77 100644 --- a/lib_enc/enc_nelp_fx.c +++ b/lib_enc/enc_nelp_fx.c @@ -4,12 +4,12 @@ #include #include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ +#include "cnst.h" /* Common constants */ //#include "prot_fx.h" /* Function prototypes */ #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" /*==============================================================================*/ @@ -43,25 +43,25 @@ /* _ None */ /*==============================================================================*/ void encod_nelp_fx( - Encoder_State *st_fx, /* i/o: state structure */ - const Word16 *speech_fx, /* i : input speech */ - const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */ - const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ - Word16 *res_fx, /* o : residual signal */ - Word16 *synth_fx, /* o : core synthesis */ - Word16 *tmp_noise_fx, /* o : long-term noise energy */ - Word16 *exc_fx, /* i/o: current non-enhanced excitation */ - Word16 *exc2_fx, /* i/o: current enhanced excitation */ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ - Word16* voice_factors_fx, /* o : voicing factors */ - Word16* bwe_exc_fx, /* o : excitation for SWB TBE */ + Encoder_State *st_fx, /* i/o: state structure */ + const Word16 *speech_fx, /* i : input speech */ + const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */ + const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ + Word16 *res_fx, /* o : residual signal */ + Word16 *synth_fx, /* o : core synthesis */ + Word16 *tmp_noise_fx, /* o : long-term noise energy */ + Word16 *exc_fx, /* i/o: current non-enhanced excitation */ + Word16 *exc2_fx, /* i/o: current enhanced excitation */ + Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ + Word16 *voice_factors_fx, /* o : voicing factors */ + Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ Word16 Q_new, Word16 shift ) { - Word16 xn_fx[L_SUBFR]; /* Target vector for pitch search */ - Word16 h1_fx[L_SUBFR]; /* Impulse response vector */ + Word16 xn_fx[L_SUBFR]; /* Target vector for pitch search */ + Word16 h1_fx[L_SUBFR]; /* Impulse response vector */ Word16 exc_nelp_fx[L_FRAME]; Word16 i_subfr, j; @@ -73,23 +73,22 @@ void encod_nelp_fx( LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; - IF ( EQ_16(st_fx->bwidth, NB)&&GE_32(st_fx->input_Fs,16000)) + IF( EQ_16( st_fx->bwidth, NB ) && GE_32( st_fx->input_Fs, 16000 ) ) { - IF (hSC_VBR->last_nelp_mode == 0) + IF( hSC_VBR->last_nelp_mode == 0 ) { - set16_fx(hSC_VBR->nelp_lp_fit_mem, 0, NELP_LP_ORDER*2 ); + set16_fx( hSC_VBR->nelp_lp_fit_mem, 0, NELP_LP_ORDER * 2 ); } - Scale_sig(hSC_VBR->nelp_lp_fit_mem, NELP_LP_ORDER*2, sub(Q_new, st_fx->prev_Q_new)); - - pz_filter_sp_fx( num_nelp_lp_fx, den_nelp_lp_fx, res_fx, res_fx, hSC_VBR->nelp_lp_fit_mem, NELP_LP_ORDER, NELP_LP_ORDER, L_FRAME, 3); /*16-Q of filter coeff*/ + Scale_sig( hSC_VBR->nelp_lp_fit_mem, NELP_LP_ORDER * 2, sub( Q_new, st_fx->prev_Q_new ) ); + pz_filter_sp_fx( num_nelp_lp_fx, den_nelp_lp_fx, res_fx, res_fx, hSC_VBR->nelp_lp_fit_mem, NELP_LP_ORDER, NELP_LP_ORDER, L_FRAME, 3 ); /*16-Q of filter coeff*/ } p_Aw_fx = Aw_fx; p_Aq_fx = Aq_fx; - FOR (i_subfr=0; i_subfrmem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq_fx, - res_fx, L_SUBFR, p_Aw_fx, TILT_FAC_FX, xn_fx, NULL, h1_fx); + res_fx, L_SUBFR, p_Aw_fx, TILT_FAC_FX, xn_fx, NULL, h1_fx ); /* scale xn[] and h1[] to avoid overflow in dot_product12() */ - Scale_sig(xn_fx, L_SUBFR, shift); /* scaling of xn[] to limit dynamic at 12 bits */ + Scale_sig( xn_fx, L_SUBFR, shift ); /* scaling of xn[] to limit dynamic at 12 bits */ - IF (i_subfr == 0) + IF( i_subfr == 0 ) { test(); - IF ( EQ_16(hSC_VBR->Local_VAD, 1 ) && EQ_16(st_fx->bwidth,NB)) + IF( EQ_16( hSC_VBR->Local_VAD, 1 ) && EQ_16( st_fx->bwidth, NB ) ) { reduce_gains = 1; } - nelp_encoder_fx( st_fx, res_fx, exc_nelp_fx, &Q_new, reduce_gains); + nelp_encoder_fx( st_fx, res_fx, exc_nelp_fx, &Q_new, reduce_gains ); - Scale_sig(exc_nelp_fx, L_FRAME, (saved_Q_new - Q_new)); + Scale_sig( exc_nelp_fx, L_FRAME, ( saved_Q_new - Q_new ) ); } @@ -126,11 +125,11 @@ void encod_nelp_fx( * Synthesize speech to update mem_syn[]. * Update A(z) filters *-----------------------------------------------------------------*/ - Syn_filt_s(1, p_Aq_fx, M, &exc_nelp_fx[i_subfr], &synth_fx[i_subfr], L_SUBFR, hLPDmem->mem_syn, 1); + Syn_filt_s( 1, p_Aq_fx, M, &exc_nelp_fx[i_subfr], &synth_fx[i_subfr], L_SUBFR, hLPDmem->mem_syn, 1 ); - p_Aw_fx += (M+1); + p_Aw_fx += ( M + 1 ); move16(); - p_Aq_fx += (M+1); + p_Aq_fx += ( M + 1 ); move16(); *pitch_buf_fx = L_SUBFR_Q6; move16(); @@ -139,7 +138,7 @@ void encod_nelp_fx( move16(); } - Copy(exc_nelp_fx, exc_fx, L_FRAME); + Copy( exc_nelp_fx, exc_fx, L_FRAME ); /*-----------------------------------------------------------------* * Updates: last value of new target is stored in mem_w0 @@ -148,15 +147,15 @@ void encod_nelp_fx( #ifdef BASOP_NOGLOB hLPDmem->mem_w0 = sub_sat( shr_sat( xn_fx[L_SUBFR - 1], shift ), shr( exc_fx[L_FRAME - 1], 1 ) ); #else - hLPDmem->mem_w0 = sub(shr(xn_fx[L_SUBFR-1],shift), shr(exc_fx[L_FRAME-1],1)); + hLPDmem->mem_w0 = sub( shr( xn_fx[L_SUBFR - 1], shift ), shr( exc_fx[L_FRAME - 1], 1 ) ); #endif - move16();/*Q_new-1 */ + move16(); /*Q_new-1 */ hLPDmem->tilt_code = 0; - move16();/* purely unvoiced */ + move16(); /* purely unvoiced */ hSC_VBR->prev_tilt_code_fx = hLPDmem->tilt_code; move16(); - Copy(exc_fx, exc2_fx, L_FRAME); + Copy( exc_fx, exc2_fx, L_FRAME ); hSC_VBR->prev_ppp_gain_pit_fx = 0; move16(); @@ -166,9 +165,9 @@ void encod_nelp_fx( hLPDmem->dm_fx.prev_gain_pit[0] = hSC_VBR->prev_ppp_gain_pit_fx; move16(); - FOR(j=1; j<5; j++) + FOR( j = 1; j < 5; j++ ) { - hLPDmem->dm_fx.prev_gain_pit[j] = hLPDmem->dm_fx.prev_gain_pit[j-1]; + hLPDmem->dm_fx.prev_gain_pit[j] = hLPDmem->dm_fx.prev_gain_pit[j - 1]; move16(); } interp_code_5over2_fx( exc2_fx, bwe_exc_fx, L_FRAME ); diff --git a/lib_enc/enc_pit_exc_fx.c b/lib_enc/enc_pit_exc_fx.c index d20e133da..f8d6eb8a4 100644 --- a/lib_enc/enc_pit_exc_fx.c +++ b/lib_enc/enc_pit_exc_fx.c @@ -2,14 +2,14 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "rom_com.h" /* Static table prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com_fx.h" /* Static table prototypes */ +#include "rom_com.h" /* Static table prototypes */ //#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*======================================================================*/ /* FUNCTION : enc_pit_exc_fx() */ @@ -48,58 +48,57 @@ /* _ None */ /*=======================================================================*/ void enc_pit_exc_fx( - Encoder_State *st_fx, /* i/o: State structure */ - const Word16 *speech, /* i : Input speech */ - const Word16 Aw[], /* i : weighted A(z) unquantized for subframes */ - const Word16 Aq[], /* i : 12k8 Lp coefficient */ - const Word16 Es_pred, /* i : predicted scaled innov. energy */ - const Word16 *res, /* i : residual signal */ - Word16 *synth, /* i/o: core synthesis */ - Word16 *exc, /* i/o: current non-enhanced excitation */ - Word16 *T0, /* i/o: close loop integer pitch */ - Word16 *T0_frac, /* i/o: close-loop pitch period - fractional part */ - Word16 *pitch_buf, /* i/o: Fractionnal per subframe pitch */ - const Word16 nb_subfr, /* i : Number of subframe considered */ - Word16 *gpit, /* o : pitch mean gpit */ - Word16 *saved_bit_pos, /* o : saved position in the bitstream before pitch contribution */ - const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ - const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer */ + Encoder_State *st_fx, /* i/o: State structure */ + const Word16 *speech, /* i : Input speech */ + const Word16 Aw[], /* i : weighted A(z) unquantized for subframes */ + const Word16 Aq[], /* i : 12k8 Lp coefficient */ + const Word16 Es_pred, /* i : predicted scaled innov. energy */ + const Word16 *res, /* i : residual signal */ + Word16 *synth, /* i/o: core synthesis */ + Word16 *exc, /* i/o: current non-enhanced excitation */ + Word16 *T0, /* i/o: close loop integer pitch */ + Word16 *T0_frac, /* i/o: close-loop pitch period - fractional part */ + Word16 *pitch_buf, /* i/o: Fractionnal per subframe pitch */ + const Word16 nb_subfr, /* i : Number of subframe considered */ + Word16 *gpit, /* o : pitch mean gpit */ + Word16 *saved_bit_pos, /* o : saved position in the bitstream before pitch contribution */ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer */ Word16 Q_new, - Word16 shift -) + Word16 shift ) { - Word16 xn[PIT_EXC_L_SUBFR]; /* Target vector for pitch search */ - Word16 xn2[PIT_EXC_L_SUBFR]; /* Target vector for codebook search */ - Word16 h1[PIT_EXC_L_SUBFR+(M+1)]; /* Impulse response vector */ - Word16 y1[PIT_EXC_L_SUBFR]; /* Filtered adaptive excitation */ - Word16 code[2*L_SUBFR]; /* Fixed codebook excitation */ - Word16 y2[2*L_SUBFR]; /* Filtered algebraic excitation */ - Word16 voice_fac; /* Voicing factor */ - Word32 gain_code; /* Gain of code */ - Word16 gain_inov; /* inovation gain */ - Word16 gain_pit; /* Pitch gain */ - Word16 pit_idx, i_subfr; /* tmp variables */ - Word16 T0_min, T0_max; /* pitch variables */ - Word16 g_corr[10]; /* ACELP correlation values + gain pitch */ - Word16 clip_gain, i; /* LSF clip gain and LP flag */ - const Word16 *p_Aw, *p_Aq; /* pointer to LP filter coefficient vector */ - Word16 cn1[L_SUBFR], *cn; /* (Used only when L_subfr == L_SUBFR) Target vector in residual domain */ - Word16 *pt_pitch; /* pointer to floating pitch */ + Word16 xn[PIT_EXC_L_SUBFR]; /* Target vector for pitch search */ + Word16 xn2[PIT_EXC_L_SUBFR]; /* Target vector for codebook search */ + Word16 h1[PIT_EXC_L_SUBFR + ( M + 1 )]; /* Impulse response vector */ + Word16 y1[PIT_EXC_L_SUBFR]; /* Filtered adaptive excitation */ + Word16 code[2 * L_SUBFR]; /* Fixed codebook excitation */ + Word16 y2[2 * L_SUBFR]; /* Filtered algebraic excitation */ + Word16 voice_fac; /* Voicing factor */ + Word32 gain_code; /* Gain of code */ + Word16 gain_inov; /* inovation gain */ + Word16 gain_pit; /* Pitch gain */ + Word16 pit_idx, i_subfr; /* tmp variables */ + Word16 T0_min, T0_max; /* pitch variables */ + Word16 g_corr[10]; /* ACELP correlation values + gain pitch */ + Word16 clip_gain, i; /* LSF clip gain and LP flag */ + const Word16 *p_Aw, *p_Aq; /* pointer to LP filter coefficient vector */ + Word16 cn1[L_SUBFR], *cn; /* (Used only when L_subfr == L_SUBFR) Target vector in residual domain */ + Word16 *pt_pitch; /* pointer to floating pitch */ Word16 L_subfr; Word16 cum_gpit, gpit_tmp; Word32 Local_BR, Pitch_BR; - Word16 Pitch_CT, unbits_PI = 0; /* saved bits for PI */ + Word16 Pitch_CT, unbits_PI = 0; /* saved bits for PI */ Word32 norm_gain_code; Word16 pitch_limit_flag; - Word16 h2[PIT_EXC_L_SUBFR+(M+1)]; /* Impulse response vector */ + Word16 h2[PIT_EXC_L_SUBFR + ( M + 1 )]; /* Impulse response vector */ Word32 Ltmp; Word32 Lgcode; Word16 gcode16; Word16 shift_wsp; Word16 lp_select, lp_flag; Word16 use_fcb; - Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes */ - Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes*/ + Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes */ + Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes*/ SP_MUS_CLAS_HANDLE hSpMusClas = st_fx->hSpMusClas; BSTR_ENC_HANDLE hBstr = st_fx->hBstr; GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc; @@ -109,27 +108,29 @@ void enc_pit_exc_fx( #endif /*------------------------------------------------------------------* - * Initialization - *------------------------------------------------------------------*/ + * Initialization + *------------------------------------------------------------------*/ pitch_limit_flag = 1; move16(); /* always extended pitch Q range */ use_fcb = 0; unbits_PI = 0; - test();test(); + test(); + test(); Pitch_CT = GENERIC; move16(); - IF (st_fx->GSC_IVAS_mode > 0 && (st_fx->GSC_noisy_speech || GT_32(st_fx->core_brate, GSC_H_RATE_STG))) + IF( st_fx->GSC_IVAS_mode > 0 && ( st_fx->GSC_noisy_speech || GT_32( st_fx->core_brate, GSC_H_RATE_STG ) ) ) { Local_BR = ACELP_8k00; Pitch_BR = ACELP_8k00; - move32();move32(); - IF (EQ_16(st_fx->L_frame, L_FRAME16k)) + move32(); + move32(); + IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { Local_BR = ACELP_14k80; move32(); - if (st_fx->GSC_IVAS_mode > 0) + if ( st_fx->GSC_IVAS_mode > 0 ) { Local_BR = ACELP_9k60; move32(); @@ -146,7 +147,7 @@ void enc_pit_exc_fx( move32(); Pitch_CT = GENERIC; move16(); - if (EQ_16(st_fx->L_frame, L_FRAME16k)) + if ( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { Pitch_BR = st_fx->core_brate; move32(); @@ -162,7 +163,7 @@ void enc_pit_exc_fx( Pitch_CT = AUDIO; move16(); - if (EQ_16(st_fx->L_frame, L_FRAME16k)) + if ( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { Local_BR = ACELP_13k20; move32(); @@ -173,7 +174,7 @@ void enc_pit_exc_fx( gain_code = 0; move16(); - IF (EQ_16(st_fx->L_frame, L_FRAME16k)) + IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { T0_max = PIT16k_MAX; T0_min = PIT16k_MIN; @@ -188,26 +189,35 @@ void enc_pit_exc_fx( cum_gpit = 0; move16(); - L_subfr = mult_r(st_fx->L_frame,div_s(1,nb_subfr)); - + L_subfr = mult_r( st_fx->L_frame, div_s( 1, nb_subfr ) ); + lp_flag = st_fx->acelp_cfg.ltf_mode; - test();test();test();test();test();test();test();test(); - IF (((GE_32(st_fx->core_brate, MIN_RATE_FCB) || (EQ_16(st_fx->GSC_noisy_speech, 1) && - ((EQ_16(st_fx->L_frame, L_FRAME) && GE_32(st_fx->core_brate, ACELP_13k20)) || - (EQ_16(st_fx->L_frame, L_FRAME16k) && GE_32(st_fx->core_brate, GSC_H_RATE_STG)) || st_fx->GSC_IVAS_mode == 0))) && EQ_16(L_subfr, L_SUBFR))) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( ( GE_32( st_fx->core_brate, MIN_RATE_FCB ) || ( EQ_16( st_fx->GSC_noisy_speech, 1 ) && + ( ( EQ_16( st_fx->L_frame, L_FRAME ) && GE_32( st_fx->core_brate, ACELP_13k20 ) ) || + ( EQ_16( st_fx->L_frame, L_FRAME16k ) && GE_32( st_fx->core_brate, GSC_H_RATE_STG ) ) || st_fx->GSC_IVAS_mode == 0 ) ) ) && + EQ_16( L_subfr, L_SUBFR ) ) ) { use_fcb = 1; move16(); } - ELSE IF (st_fx->GSC_IVAS_mode > 0 && EQ_16(L_subfr, 2 * L_SUBFR) && LT_16(st_fx->GSC_IVAS_mode, 3)) + ELSE IF( st_fx->GSC_IVAS_mode > 0 && EQ_16( L_subfr, 2 * L_SUBFR ) && LT_16( st_fx->GSC_IVAS_mode, 3 ) ) { use_fcb = 2; st_fx->acelp_cfg.fcb_mode = 1; - move16();move16(); - set16_fx(st_fx->acelp_cfg.gains_mode, 6, NB_SUBFR); - set16_fx(st_fx->acelp_cfg.pitch_bits, 9, NB_SUBFR); - set16_fx(st_fx->acelp_cfg.fixed_cdk_index, 14, NB_SUBFR16k); + move16(); + move16(); + set16_fx( st_fx->acelp_cfg.gains_mode, 6, NB_SUBFR ); + set16_fx( st_fx->acelp_cfg.pitch_bits, 9, NB_SUBFR ); + set16_fx( st_fx->acelp_cfg.fixed_cdk_index, 14, NB_SUBFR16k ); } *saved_bit_pos = st_fx->next_bit_pos_fx; @@ -217,7 +227,7 @@ void enc_pit_exc_fx( * ACELP subframe loop *------------------------------------------------------------------*/ cn = NULL; - if(EQ_16(L_subfr, L_SUBFR)) + if ( EQ_16( L_subfr, L_SUBFR ) ) { cn = cn1; move16(); @@ -225,9 +235,9 @@ void enc_pit_exc_fx( p_Aw = Aw; p_Aq = Aq; - pt_pitch = pitch_buf; /* pointer to the pitch buffer */ - shift_wsp = add(Q_new,shift); - FOR ( i_subfr = 0; i_subfr < st_fx->L_frame; i_subfr += L_subfr ) + pt_pitch = pitch_buf; /* pointer to the pitch buffer */ + shift_wsp = add( Q_new, shift ); + FOR( i_subfr = 0; i_subfr < st_fx->L_frame; i_subfr += L_subfr ) { /*----------------------------------------------------------------* @@ -238,36 +248,36 @@ void enc_pit_exc_fx( *----------------------------------------------------------------*/ Copy( &res[i_subfr], &exc[i_subfr], L_subfr ); /* condition on target (compared to float) has been put outside the loop */ -#if 1//ndef BUG_FIX - find_targets_fx( speech, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq, - res, L_subfr, p_Aw, st_fx->preemph_fac, xn, cn,h1); +#if 1 // ndef BUG_FIX + find_targets_fx( speech, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq, + res, L_subfr, p_Aw, st_fx->preemph_fac, xn, cn, h1 ); #else - find_targets_fx(speech, hGSCEnc->mem_syn_tmp_fx, i_subfr, &hLPDmem->mem_w0, p_Aq, /*_DIFF_FLOAT_FIX_ --> Here I think mem_syn_tmp_fx should be used */ - res, L_subfr, p_Aw, st_fx->preemph_fac, xn, cn, h1); + find_targets_fx( speech, hGSCEnc->mem_syn_tmp_fx, i_subfr, &hLPDmem->mem_w0, p_Aq, /*_DIFF_FLOAT_FIX_ --> Here I think mem_syn_tmp_fx should be used */ + res, L_subfr, p_Aw, st_fx->preemph_fac, xn, cn, h1 ); #endif - Copy_Scale_sig(h1, h2, L_subfr, -2); - Scale_sig(h1, L_subfr, add(1, shift)); /* set h1[] in Q14 with scaling for convolution */ + Copy_Scale_sig( h1, h2, L_subfr, -2 ); + Scale_sig( h1, L_subfr, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution */ /* scaling of xn[] to limit dynamic at 12 bits */ - Scale_sig(xn, L_subfr, shift); + Scale_sig( xn, L_subfr, shift ); /*----------------------------------------------------------------* * Close-loop pitch search and quantization * Adaptive exc. construction *----------------------------------------------------------------*/ - *pt_pitch = pit_encode_fx(hBstr, st_fx->acelp_cfg.pitch_bits, Pitch_BR, 0, st_fx->L_frame, Pitch_CT, &pitch_limit_flag, i_subfr, exc, - L_subfr, st_fx->pitch_fx, &T0_min, &T0_max, T0, T0_frac, h1, xn, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf); + *pt_pitch = pit_encode_fx( hBstr, st_fx->acelp_cfg.pitch_bits, Pitch_BR, 0, st_fx->L_frame, Pitch_CT, &pitch_limit_flag, i_subfr, exc, + L_subfr, st_fx->pitch_fx, &T0_min, &T0_max, T0, T0_frac, h1, xn, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); /*-----------------------------------------------------------------* * Find adaptive exitation *-----------------------------------------------------------------*/ - pred_lt4(&exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_subfr+1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP); + pred_lt4( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_subfr + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); /*-----------------------------------------------------------------* * Gain clipping test to avoid unstable synthesis on frame erasure * or in case of floating point encoder & fixed p. decoder *-----------------------------------------------------------------*/ - clip_gain = gp_clip_fx(st_fx->element_mode, st_fx->core_brate, st_fx->voicing_fx, i_subfr, AUDIO, xn, st_fx->clip_var_fx,sub(shift_wsp, 1)); + clip_gain = gp_clip_fx( st_fx->element_mode, st_fx->core_brate, st_fx->voicing_fx, i_subfr, AUDIO, xn, st_fx->clip_var_fx, sub( shift_wsp, 1 ) ); /*-----------------------------------------------------------------* * Codebook target computation @@ -277,123 +287,123 @@ void enc_pit_exc_fx( lp_select = lp_filt_exc_enc_fx( MODE1, AUDIO, i_subfr, exc, h1, xn, y1, xn2, L_subfr, st_fx->L_frame, g_corr, clip_gain, &gain_pit, &lp_flag ); - IF( EQ_16(lp_flag,NORMAL_OPERATION)) + IF( EQ_16( lp_flag, NORMAL_OPERATION ) ) { - push_indice_fx(hBstr, IND_LP_FILT_SELECT, lp_select, 1 ); + push_indice_fx( hBstr, IND_LP_FILT_SELECT, lp_select, 1 ); } /*st_fx->lowrate_pitchGain = 0.9f * st_fx->lowrate_pitchGain + 0.1f * gain_pit;*/ #ifdef BASOP_NOGLOB - hSpMusClas->lowrate_pitchGain = round_fx_o(L_mac_o(L_mult(29491, hSpMusClas->lowrate_pitchGain), 6554, gain_pit, &Overflow), &Overflow); /*Q14*Q16(0.1) + Q15 -> Q15*/ + hSpMusClas->lowrate_pitchGain = round_fx_o( L_mac_o( L_mult( 29491, hSpMusClas->lowrate_pitchGain ), 6554, gain_pit, &Overflow ), &Overflow ); /*Q14*Q16(0.1) + Q15 -> Q15*/ #else - hSpMusClas->lowrate_pitchGain = round_fx(L_mac(L_mult(29491, hSpMusClas->lowrate_pitchGain), 6554, gain_pit)); /*Q14*Q16(0.1) + Q15 -> Q15*/ + hSpMusClas->lowrate_pitchGain = round_fx( L_mac( L_mult( 29491, hSpMusClas->lowrate_pitchGain ), 6554, gain_pit ) ); /*Q14*Q16(0.1) + Q15 -> Q15*/ #endif - gpit_tmp = gain_pit; + gpit_tmp = gain_pit; move16(); /*Q14*/ test(); - IF(use_fcb > 0) + IF( use_fcb > 0 ) { /* h2 in Q12 for codebook search */ /* h1 has been scaled with 1 + shift so we need to remove 2 and (1+shift) = -3 - shift*/ - Copy_Scale_sig(h1, h2, L_subfr, sub(-2 - 1, shift)); + Copy_Scale_sig( h1, h2, L_subfr, sub( -2 - 1, shift ) ); } - IF(use_fcb == 0) + IF( use_fcb == 0 ) { - IF (GE_32(st_fx->core_brate, MIN_RATE_FCB)) + IF( GE_32( st_fx->core_brate, MIN_RATE_FCB ) ) { - pit_idx = vquant_fx(&gain_pit, mean_gp_fx, &gain_pit, dic_gp_fx, 1, 32); - push_indice_fx(hBstr, IND_PIT_IDX, pit_idx, 5); + pit_idx = vquant_fx( &gain_pit, mean_gp_fx, &gain_pit, dic_gp_fx, 1, 32 ); + push_indice_fx( hBstr, IND_PIT_IDX, pit_idx, 5 ); } ELSE { - pit_idx = vquant_fx(&gain_pit, mean_gp_fx, &gain_pit, dic_gp_fx, 1, 16); - push_indice_fx(hBstr, IND_PIT_IDX, pit_idx, 4); + pit_idx = vquant_fx( &gain_pit, mean_gp_fx, &gain_pit, dic_gp_fx, 1, 16 ); + push_indice_fx( hBstr, IND_PIT_IDX, pit_idx, 4 ); } } - else if (use_fcb == 2) + else if ( use_fcb == 2 ) { /*-----------------------------------------------------------------* * Innovation encoding *-----------------------------------------------------------------*/ - inov_encode_fx(st_fx, st_fx->core_brate, 0, st_fx->L_frame, st_fx->last_L_frame, GENERIC, st_fx->bwidth, 0, i_subfr, -1, p_Aq, - gain_pit, cn, exc, h2, st_fx->hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI, 2 * L_SUBFR, shift); -//PMT("code to be validated") + inov_encode_fx( st_fx, st_fx->core_brate, 0, st_fx->L_frame, st_fx->last_L_frame, GENERIC, st_fx->bwidth, 0, i_subfr, -1, p_Aq, + gain_pit, cn, exc, h2, st_fx->hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI, 2 * L_SUBFR, shift ); + // PMT("code to be validated") /*-----------------------------------------------------------------* * Gain encoding *-----------------------------------------------------------------*/ - gain_enc_lbr_fx(st_fx->hBstr, st_fx->acelp_cfg.gains_mode, GENERIC, i_subfr, xn, y1, shift_wsp, y2, code, &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, gc_mem, gp_mem, clip_gain, 2 * L_SUBFR); + gain_enc_lbr_fx( st_fx->hBstr, st_fx->acelp_cfg.gains_mode, GENERIC, i_subfr, xn, y1, shift_wsp, y2, code, &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, gc_mem, gp_mem, clip_gain, 2 * L_SUBFR ); } ELSE { /*-----------------------------------------------------------------* - * Innovation & gain encoding - *-----------------------------------------------------------------*/ + * Innovation & gain encoding + *-----------------------------------------------------------------*/ - inov_encode_fx(st_fx, Local_BR, 0, st_fx->L_frame, st_fx->last_L_frame, LOCAL_CT, WB, 1, i_subfr, -1, p_Aq, - gain_pit, cn, exc, h2, hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI, L_SUBFR, shift); + inov_encode_fx( st_fx, Local_BR, 0, st_fx->L_frame, st_fx->last_L_frame, LOCAL_CT, WB, 1, i_subfr, -1, p_Aq, + gain_pit, cn, exc, h2, hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI, L_SUBFR, shift ); /*-----------------------------------------------------------------* - * Gain encoding - *-----------------------------------------------------------------*/ - gain_enc_mless_fx(hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, L_FRAME, i_subfr, -1, xn, y1, shift_wsp, y2, code, Es_pred, - &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain); + * Gain encoding + *-----------------------------------------------------------------*/ + gain_enc_mless_fx( hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, L_FRAME, i_subfr, -1, xn, y1, shift_wsp, y2, code, Es_pred, + &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain ); } - gp_clip_test_gain_pit_fx(st_fx->element_mode, st_fx->core_brate, gain_pit, st_fx->clip_var_fx ); + gp_clip_test_gain_pit_fx( st_fx->element_mode, st_fx->core_brate, gain_pit, st_fx->clip_var_fx ); #ifdef BASOP_NOGLOB Lgcode = L_shl_sat( gain_code, Q_new ); /* scaled gain_code with Qnew -> Q16*/ gcode16 = round_fx_sat( Lgcode ); #else - Lgcode = L_shl(gain_code, Q_new); /* scaled gain_code with Qnew -> Q16*/ - gcode16 = round_fx(Lgcode); + Lgcode = L_shl( gain_code, Q_new ); /* scaled gain_code with Qnew -> Q16*/ + gcode16 = round_fx( Lgcode ); #endif - IF( use_fcb != 0) + IF( use_fcb != 0 ) { - hLPDmem->tilt_code = Est_tilt2(&exc[i_subfr], gain_pit, code, Lgcode, &voice_fac, shift); + hLPDmem->tilt_code = Est_tilt2( &exc[i_subfr], gain_pit, code, Lgcode, &voice_fac, shift ); move16(); } ELSE { - hLPDmem->tilt_code = 0; + hLPDmem->tilt_code = 0; move16(); } /*-----------------------------------------------------------------* * Update memory of the weighting filter *-----------------------------------------------------------------*/ - IF(use_fcb != 0) + IF( use_fcb != 0 ) { - Ltmp = L_mult(gcode16, y2[L_subfr - 1]); + Ltmp = L_mult( gcode16, y2[L_subfr - 1] ); #ifdef BASOP_NOGLOB - Ltmp = L_shl_o(Ltmp, add(5, shift), &Overflow); - Ltmp = L_negate(Ltmp); - Ltmp = L_mac_o(Ltmp, xn[L_subfr - 1], 16384, &Overflow); - Ltmp = L_msu_o(Ltmp, y1[L_subfr - 1], gain_pit, &Overflow); - Ltmp = L_shl_o(Ltmp, sub(1, shift), &Overflow); - hLPDmem->mem_w0 = round_fx_o(Ltmp, &Overflow); /*Q_new-1 */ + Ltmp = L_shl_o( Ltmp, add( 5, shift ), &Overflow ); + Ltmp = L_negate( Ltmp ); + Ltmp = L_mac_o( Ltmp, xn[L_subfr - 1], 16384, &Overflow ); + Ltmp = L_msu_o( Ltmp, y1[L_subfr - 1], gain_pit, &Overflow ); + Ltmp = L_shl_o( Ltmp, sub( 1, shift ), &Overflow ); + hLPDmem->mem_w0 = round_fx_o( Ltmp, &Overflow ); /*Q_new-1 */ #else - Ltmp = L_mult(gcode16, y2[L_subfr - 1]); - Ltmp = L_shl(Ltmp, add(5, shift)); - Ltmp = L_negate(Ltmp); - Ltmp = L_mac(Ltmp, xn[L_subfr - 1], 16384); - Ltmp = L_msu(Ltmp, y1[L_subfr - 1], gain_pit); - Ltmp = L_shl(Ltmp, sub(1, shift)); - hLPDmem->mem_w0 = round_fx(Ltmp); /*Q_new-1 */ + Ltmp = L_mult( gcode16, y2[L_subfr - 1] ); + Ltmp = L_shl( Ltmp, add( 5, shift ) ); + Ltmp = L_negate( Ltmp ); + Ltmp = L_mac( Ltmp, xn[L_subfr - 1], 16384 ); + Ltmp = L_msu( Ltmp, y1[L_subfr - 1], gain_pit ); + Ltmp = L_shl( Ltmp, sub( 1, shift ) ); + hLPDmem->mem_w0 = round_fx( Ltmp ); /*Q_new-1 */ #endif } ELSE { - Ltmp = L_mult(xn[L_subfr - 1], 16384); + Ltmp = L_mult( xn[L_subfr - 1], 16384 ); #ifdef BASOP_NOGLOB Ltmp = L_msu_sat( Ltmp, y1[L_subfr - 1], gain_pit ); - Ltmp = L_shl_sat(Ltmp, sub(1, shift)); - hLPDmem->mem_w0 = round_fx_sat(Ltmp); /*Q_new-1 */ + Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) ); + hLPDmem->mem_w0 = round_fx_sat( Ltmp ); /*Q_new-1 */ #else - Ltmp = L_msu(Ltmp, y1[L_subfr - 1], gain_pit); - Ltmp = L_shl(Ltmp, sub(1, shift)); - hLPDmem->mem_w0 = round_fx(Ltmp); /*Q_new-1 */ + Ltmp = L_msu( Ltmp, y1[L_subfr - 1], gain_pit ); + Ltmp = L_shl( Ltmp, sub( 1, shift ) ); + hLPDmem->mem_w0 = round_fx( Ltmp ); /*Q_new-1 */ #endif } @@ -401,38 +411,38 @@ void enc_pit_exc_fx( * Construct adaptive part of the excitation * Save the non-enhanced excitation for FEC_exc *-----------------------------------------------------------------*/ - IF(use_fcb != 0) + IF( use_fcb != 0 ) { - FOR ( i = 0; i < L_subfr; i++ ) + FOR( i = 0; i < L_subfr; i++ ) { /* code in Q9, gain_pit in Q14 */ - Ltmp = L_mult(gcode16, code[i]); + Ltmp = L_mult( gcode16, code[i] ); #ifdef BASOP_NOGLOB - Ltmp = L_shl_o(Ltmp, 5, &Overflow); - Ltmp = L_mac_o(Ltmp, exc[i + i_subfr], gain_pit, &Overflow); - Ltmp = L_shl_o(Ltmp, 1, &Overflow); /* saturation can occur here */ - exc[i + i_subfr] = round_fx_o(Ltmp, &Overflow); + Ltmp = L_shl_o( Ltmp, 5, &Overflow ); + Ltmp = L_mac_o( Ltmp, exc[i + i_subfr], gain_pit, &Overflow ); + Ltmp = L_shl_o( Ltmp, 1, &Overflow ); /* saturation can occur here */ + exc[i + i_subfr] = round_fx_o( Ltmp, &Overflow ); #else - Ltmp = L_mult(gcode16, code[i]); - Ltmp = L_shl(Ltmp, 5); - Ltmp = L_mac(Ltmp, exc[i + i_subfr], gain_pit); - Ltmp = L_shl(Ltmp, 1); /* saturation can occur here */ - exc[i + i_subfr] = round_fx(Ltmp); + Ltmp = L_mult( gcode16, code[i] ); + Ltmp = L_shl( Ltmp, 5 ); + Ltmp = L_mac( Ltmp, exc[i + i_subfr], gain_pit ); + Ltmp = L_shl( Ltmp, 1 ); /* saturation can occur here */ + exc[i + i_subfr] = round_fx( Ltmp ); #endif } } ELSE { - FOR ( i = 0; i < L_subfr; i++ ) + FOR( i = 0; i < L_subfr; i++ ) { - Ltmp = L_mult(exc[i + i_subfr], gain_pit); + Ltmp = L_mult( exc[i + i_subfr], gain_pit ); #ifdef BASOP_NOGLOB Ltmp = L_shl_sat( Ltmp, 1 ); /* saturation can occur here */ - exc[i + i_subfr] = round_fx_sat(Ltmp); + exc[i + i_subfr] = round_fx_sat( Ltmp ); #else - Ltmp = L_shl(Ltmp, 1); /* saturation can occur here */ - exc[i + i_subfr] = round_fx(Ltmp); + Ltmp = L_shl( Ltmp, 1 ); /* saturation can occur here */ + exc[i + i_subfr] = round_fx( Ltmp ); #endif } } @@ -443,114 +453,112 @@ void enc_pit_exc_fx( *-----------------------------------------------------------------*/ Syn_filt_s( 1, p_Aq, M, &exc[i_subfr], &synth[i_subfr], L_subfr, hGSCEnc->mem_syn_tmp_fx, 1 ); - - IF (EQ_16(L_subfr, 5 * L_SUBFR)) + + IF( EQ_16( L_subfr, 5 * L_SUBFR ) ) { cum_gpit = gpit_tmp; move16(); pt_pitch++; - *pt_pitch = *(pt_pitch - 1); + *pt_pitch = *( pt_pitch - 1 ); move16(); pt_pitch++; - *pt_pitch = *(pt_pitch - 1); + *pt_pitch = *( pt_pitch - 1 ); move16(); pt_pitch++; - *pt_pitch = *(pt_pitch - 1); + *pt_pitch = *( pt_pitch - 1 ); move16(); pt_pitch++; - *pt_pitch = *(pt_pitch - 1); + *pt_pitch = *( pt_pitch - 1 ); move16(); pt_pitch++; - p_Aw += 5 * (M + 1); - p_Aq += 5 * (M + 1); + p_Aw += 5 * ( M + 1 ); + p_Aq += 5 * ( M + 1 ); } - ELSE IF (EQ_16(L_subfr, 5 * L_SUBFR / 2)) + ELSE IF( EQ_16( L_subfr, 5 * L_SUBFR / 2 ) ) { - IF (i_subfr == 0) + IF( i_subfr == 0 ) { - cum_gpit = mult_r(gpit_tmp, 13107); /* .4f*/ + cum_gpit = mult_r( gpit_tmp, 13107 ); /* .4f*/ pt_pitch++; - *pt_pitch = *(pt_pitch - 1); + *pt_pitch = *( pt_pitch - 1 ); move16(); pt_pitch++; - p_Aw += 2 * (M + 1); - p_Aq += 2 * (M + 1); + p_Aw += 2 * ( M + 1 ); + p_Aq += 2 * ( M + 1 ); } ELSE { - cum_gpit = add(cum_gpit, mult_r(gpit_tmp, 19660)); /*0.6*/ + cum_gpit = add( cum_gpit, mult_r( gpit_tmp, 19660 ) ); /*0.6*/ pt_pitch++; - *pt_pitch = *(pt_pitch - 1); + *pt_pitch = *( pt_pitch - 1 ); move16(); pt_pitch++; - *pt_pitch = *(pt_pitch - 1); + *pt_pitch = *( pt_pitch - 1 ); move16(); pt_pitch++; - p_Aw += 3 * (M + 1); - p_Aq += 3 * (M + 1); + p_Aw += 3 * ( M + 1 ); + p_Aq += 3 * ( M + 1 ); } } - ELSE IF( EQ_16(L_subfr,2*L_SUBFR)) + ELSE IF( EQ_16( L_subfr, 2 * L_SUBFR ) ) { IF( i_subfr == 0 ) { - cum_gpit = mult_r(gpit_tmp,16384); + cum_gpit = mult_r( gpit_tmp, 16384 ); } ELSE { - cum_gpit = add(cum_gpit,mult_r(gpit_tmp,16384)); + cum_gpit = add( cum_gpit, mult_r( gpit_tmp, 16384 ) ); } - p_Aw += 2*(M+1); + p_Aw += 2 * ( M + 1 ); move16(); - p_Aq += 2*(M+1); + p_Aq += 2 * ( M + 1 ); move16(); pt_pitch++; - *pt_pitch = *(pt_pitch-1); + *pt_pitch = *( pt_pitch - 1 ); move16(); pt_pitch++; } - ELSE IF(EQ_16(L_subfr,4*L_SUBFR)) + ELSE IF( EQ_16( L_subfr, 4 * L_SUBFR ) ) { cum_gpit = gpit_tmp; move16(); pt_pitch++; - *pt_pitch = *(pt_pitch-1); + *pt_pitch = *( pt_pitch - 1 ); move16(); pt_pitch++; - *pt_pitch = *(pt_pitch-1); + *pt_pitch = *( pt_pitch - 1 ); move16(); pt_pitch++; - *pt_pitch = *(pt_pitch-1); + *pt_pitch = *( pt_pitch - 1 ); pt_pitch++; - p_Aw += 4*(M+1); - p_Aq += 4*(M+1); + p_Aw += 4 * ( M + 1 ); + p_Aq += 4 * ( M + 1 ); } ELSE { IF( i_subfr == 0 ) { - cum_gpit = mult_r(gpit_tmp,8192); + cum_gpit = mult_r( gpit_tmp, 8192 ); } ELSE { - cum_gpit = add(cum_gpit,mult_r(gpit_tmp,8192)); + cum_gpit = add( cum_gpit, mult_r( gpit_tmp, 8192 ) ); } pt_pitch++; - p_Aw += (M+1); - p_Aq += (M+1); + p_Aw += ( M + 1 ); + p_Aq += ( M + 1 ); } } #ifdef BASOP_NOGLOB - cum_gpit = shl_o(cum_gpit,1, &Overflow); /*Q15*/ -#else /* BASOP_NOGLOB */ - cum_gpit = shl(cum_gpit,1); /*Q15*/ + cum_gpit = shl_o( cum_gpit, 1, &Overflow ); /*Q15*/ +#else /* BASOP_NOGLOB */ + cum_gpit = shl( cum_gpit, 1 ); /*Q15*/ #endif - *gpit = round_fx(L_mac(L_mult(3277 , *gpit), 29491, cum_gpit)); /*Q15*/ - - + *gpit = round_fx( L_mac( L_mult( 3277, *gpit ), 29491, cum_gpit ) ); /*Q15*/ } diff --git a/lib_enc/enc_ppp_fx.c b/lib_enc/enc_ppp_fx.c index a0c617dd0..31cdc0a5c 100644 --- a/lib_enc/enc_ppp_fx.c +++ b/lib_enc/enc_ppp_fx.c @@ -2,17 +2,17 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ //#include "prot_fx.h" /* Function prototypes */ #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ -#include "basop_util.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ +#include "basop_util.h" /* Function prototypes */ /*Temporary location to be move in prot* when merge is done */ -void E_LPC_f_lsp_a_conversion(const Word16 *lsp, Word16 *a, const Word16 m); +void E_LPC_f_lsp_a_conversion( const Word16 *lsp, Word16 *a, const Word16 m ); /*=======================================================================================*/ /* FUNCTION : encod_ppp_fx() */ @@ -53,30 +53,29 @@ void E_LPC_f_lsp_a_conversion(const Word16 *lsp, Word16 *a, const Word16 m); /* CALLED FROM : TX */ /*=======================================================================================*/ ivas_error encod_ppp_fx( - Encoder_State* st_fx, /* i/o: state structure */ - const Word16 speech_fx[], /* i : input speech Q_new*/ - const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */ - const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ - Word16 *res_fx, /* i : residual signal Q_new*/ - Word16 *synth_fx, /* o : core synthesis Q-1*/ - Word16 *exc_fx, /* i/o: current non-enhanced excitation Q_new*/ - Word16 *exc2_fx, /* o : current enhanced excitation Q0*/ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe Q6*/ - Word16 *voice_factors, /* o : voicing factors */ - Word16 *bwe_exc, /* o : excitation for SWB TBE */ + Encoder_State *st_fx, /* i/o: state structure */ + const Word16 speech_fx[], /* i : input speech Q_new*/ + const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */ + const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ + Word16 *res_fx, /* i : residual signal Q_new*/ + Word16 *synth_fx, /* o : core synthesis Q-1*/ + Word16 *exc_fx, /* i/o: current non-enhanced excitation Q_new*/ + Word16 *exc2_fx, /* o : current enhanced excitation Q0*/ + Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe Q6*/ + Word16 *voice_factors, /* o : voicing factors */ + Word16 *bwe_exc, /* o : excitation for SWB TBE */ Word16 Q_new, - Word16 shift -) + Word16 shift ) { - Word16 xn_fx[L_SUBFR]; /* Target vector for pitch search */ - Word16 h1_fx[L_SUBFR+(M+1)]; /* Impulse response vector */ - Word16 i_subfr; /* tmp variables */ - const Word16 *p_Aw_fx, *p_Aq_fx; /* pointer to LP filter coeff. vector*/ + Word16 xn_fx[L_SUBFR]; /* Target vector for pitch search */ + Word16 h1_fx[L_SUBFR + ( M + 1 )]; /* Impulse response vector */ + Word16 i_subfr; /* tmp variables */ + const Word16 *p_Aw_fx, *p_Aq_fx; /* pointer to LP filter coeff. vector*/ Word16 k; - Word16 p_Aq_old_fx[M+1], excQ_ppp_fx[L_FRAME] ,p_Aq_curr_fx[M], pitch_fx[NB_SUBFR]; - Word16 LPC_de_old_fx[M+1], LPC_de_curr_fx[M+1]; - Word16 shift_wsp = add(Q_new,shift); + Word16 p_Aq_old_fx[M + 1], excQ_ppp_fx[L_FRAME], p_Aq_curr_fx[M], pitch_fx[NB_SUBFR]; + Word16 LPC_de_old_fx[M + 1], LPC_de_curr_fx[M + 1]; + Word16 shift_wsp = add( Q_new, shift ); Word16 rate_ctrl_fx; Word16 saved_Q_new = Q_new; LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; @@ -90,11 +89,11 @@ ivas_error encod_ppp_fx( move16(); /*------------------------------------------------------------------* - * ACELP subframe loop - *------------------------------------------------------------------*/ + * ACELP subframe loop + *------------------------------------------------------------------*/ p_Aw_fx = Aw_fx; p_Aq_fx = Aq_fx; - FOR (i_subfr=0; i_subfrmem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq_fx, - res_fx, L_SUBFR, p_Aw_fx, TILT_FAC_FX, xn_fx, NULL, h1_fx); + res_fx, L_SUBFR, p_Aw_fx, TILT_FAC_FX, xn_fx, NULL, h1_fx ); /* scale xn[] and h1[] to avoid overflow in dot_product12() */ - Scale_sig(xn_fx, L_SUBFR, shift); /* scaling of xn[] to limit dynamic at 12 bits */ + Scale_sig( xn_fx, L_SUBFR, shift ); /* scaling of xn[] to limit dynamic at 12 bits */ /* call voiced encoder at this point */ - IF (i_subfr == 0) /* generate the L_FRAME exc */ + IF( i_subfr == 0 ) /* generate the L_FRAME exc */ { - FOR(k=0; klsp_old_fx, p_Aq_old_fx, M ); - deemph_lpc_fx( p_Aq_curr_fx, p_Aq_old_fx, LPC_de_curr_fx, LPC_de_old_fx ,1); + deemph_lpc_fx( p_Aq_curr_fx, p_Aq_old_fx, LPC_de_curr_fx, LPC_de_old_fx, 1 ); /* both outputs LPC_de_curr_fx and LPC_de_old_fx are in Q12 */ /* last frame-end lpc and curr frame-end lpc */ - IF((error = ppp_voiced_encoder_fx(hBstr, hSC_VBR, st_fx->bwidth, st_fx->last_coder_type_raw, st_fx->old_pitch_buf_fx, res_fx, - excQ_ppp_fx, st_fx->pitch_fx[1], LPC_de_old_fx, LPC_de_curr_fx, exc_fx, pitch_fx, Q_new)) != IVAS_ERR_OK) + IF( ( error = ppp_voiced_encoder_fx( hBstr, hSC_VBR, st_fx->bwidth, st_fx->last_coder_type_raw, st_fx->old_pitch_buf_fx, res_fx, + excQ_ppp_fx, st_fx->pitch_fx[1], LPC_de_old_fx, LPC_de_curr_fx, exc_fx, pitch_fx, Q_new ) ) != IVAS_ERR_OK ) { return error; } - Scale_sig(exc_fx, L_FRAME, (saved_Q_new - Q_new)); - if (EQ_16(hSC_VBR->bump_up,1)) + Scale_sig( exc_fx, L_FRAME, ( saved_Q_new - Q_new ) ); + if ( EQ_16( hSC_VBR->bump_up, 1 ) ) { i_subfr = L_FRAME; move16(); } } - IF( NE_16(hSC_VBR->bump_up,1)) + IF( NE_16( hSC_VBR->bump_up, 1 ) ) { /*-----------------------------------------------------------------* * Gain clipping test to avoid unstable synthesis on frame erasure * or in case of floating point encoder & fixed p. decoder *-----------------------------------------------------------------*/ - gp_clip_fx(st_fx->element_mode, st_fx->core_brate, st_fx->voicing_fx, i_subfr, st_fx->coder_type, xn_fx, st_fx->clip_var_fx, sub(shift_wsp,1)); + gp_clip_fx( st_fx->element_mode, st_fx->core_brate, st_fx->voicing_fx, i_subfr, st_fx->coder_type, xn_fx, st_fx->clip_var_fx, sub( shift_wsp, 1 ) ); /* run the above to maintain gain clipping memories */ - gp_clip_test_gain_pit_fx(st_fx->element_mode, st_fx->core_brate, hSC_VBR->prev_ppp_gain_pit_fx, st_fx->clip_var_fx ); + gp_clip_test_gain_pit_fx( st_fx->element_mode, st_fx->core_brate, hSC_VBR->prev_ppp_gain_pit_fx, st_fx->clip_var_fx ); /*-----------------------------------------------------------------* @@ -161,13 +160,13 @@ ivas_error encod_ppp_fx( Syn_filt_s( 1, p_Aq_fx, M, &excQ_ppp_fx[i_subfr], &synth_fx[i_subfr], L_SUBFR, hLPDmem->mem_syn, 1 ); - p_Aw_fx += (M+1); - p_Aq_fx += (M+1); + p_Aw_fx += ( M + 1 ); + p_Aq_fx += ( M + 1 ); } - } /* end of subframe loop */ + } /* end of subframe loop */ - IF(hSC_VBR->bump_up ) + IF( hSC_VBR->bump_up ) { /* PPP failed, bump up */ hSC_VBR->ppp_mode = 0; @@ -177,7 +176,7 @@ ivas_error encod_ppp_fx( hSC_VBR->pppcountE = 0; move16(); - IF (hSC_VBR->set_ppp_generic ) + IF( hSC_VBR->set_ppp_generic ) { st_fx->coder_type = GENERIC; move16(); @@ -191,41 +190,41 @@ ivas_error encod_ppp_fx( /* We write signalling indices again only in case of bump_up */ /* delete previous indices */ #ifndef IVAS_CODE_BITSTREAM - reset_indices_enc_fx(hBstr); + reset_indices_enc_fx( hBstr ); #else - reset_indices_enc_fx(hBstr, hBstr->nb_ind_tot ); + reset_indices_enc_fx( hBstr, hBstr->nb_ind_tot ); #endif /* signalling matrix (writing of signalling bits) */ - signalling_enc_fx( st_fx); + signalling_enc_fx( st_fx ); } ELSE { - Copy(excQ_ppp_fx, exc_fx, L_FRAME); + Copy( excQ_ppp_fx, exc_fx, L_FRAME ); /*-----------------------------------------------------------------* * Updates: last value of new target is stored in mem_w0 *-----------------------------------------------------------------*/ - hLPDmem->mem_w0 = sub(shr(xn_fx[L_SUBFR-1],shift), shr(exc_fx[L_FRAME-1],1)); /*Q_new-1 */ + hLPDmem->mem_w0 = sub( shr( xn_fx[L_SUBFR - 1], shift ), shr( exc_fx[L_FRAME - 1], 1 ) ); /*Q_new-1 */ - Copy(exc_fx, exc2_fx, L_FRAME); + Copy( exc_fx, exc2_fx, L_FRAME ); hLPDmem->dm_fx.prev_state = 2; - move16();/*Q0 dispMem index 0 */ + move16(); /*Q0 dispMem index 0 */ hLPDmem->dm_fx.prev_gain_pit[0] = hSC_VBR->prev_ppp_gain_pit_fx; - move16();/*Q14 dispMem index 2 */ + move16(); /*Q14 dispMem index 2 */ - FOR( k=1; k<5; k++ ) + FOR( k = 1; k < 5; k++ ) { - hLPDmem->dm_fx.prev_gain_pit[k] = hLPDmem->dm_fx.prev_gain_pit[k-1]; + hLPDmem->dm_fx.prev_gain_pit[k] = hLPDmem->dm_fx.prev_gain_pit[k - 1]; move16(); } hLPDmem->tilt_code = hSC_VBR->prev_tilt_code_fx; move16(); - Copy(pitch_fx, pitch_buf_fx, NB_SUBFR); - pitch_buf_fx[ NB_SUBFR16k -1 ] = pitch_fx[ NB_SUBFR - 1 ]; + Copy( pitch_fx, pitch_buf_fx, NB_SUBFR ); + pitch_buf_fx[NB_SUBFR16k - 1] = pitch_fx[NB_SUBFR - 1]; interp_code_5over2_fx( exc2_fx, bwe_exc, L_FRAME ); set16_fx( voice_factors, 0, NB_SUBFR16k ); @@ -234,7 +233,7 @@ ivas_error encod_ppp_fx( hSC_VBR->rate_control = rate_ctrl_fx; move16(); - set16_fx(hSC_VBR->nelp_lp_fit_mem, 0, NELP_LP_ORDER * 2); + set16_fx( hSC_VBR->nelp_lp_fit_mem, 0, NELP_LP_ORDER * 2 ); return error; } diff --git a/lib_enc/enc_prm_fx.c b/lib_enc/enc_prm_fx.c index ab499b0e3..93b4698fc 100644 --- a/lib_enc/enc_prm_fx.c +++ b/lib_enc/enc_prm_fx.c @@ -12,16 +12,15 @@ #include "rom_com.h" #include "stl.h" //#include "prot_fx.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ static void enc_prm_hm( Word16 *prm_hm, Encoder_State *st, - Word16 L_frame -) + Word16 L_frame ) { Word8 flag; BSTR_ENC_HANDLE hBstr = st->hBstr; @@ -29,30 +28,30 @@ static void enc_prm_hm( /* Disable HM for non-GC,VC modes */ test(); - IF (NE_16(st->hTcxCfg->coder_type, VOICED)&&NE_16(st->hTcxCfg->coder_type,GENERIC)) + IF( NE_16( st->hTcxCfg->coder_type, VOICED ) && NE_16( st->hTcxCfg->coder_type, GENERIC ) ) { return; } /* Flag */ - push_next_indice_fx(hBstr, prm_hm[0], 1); + push_next_indice_fx( hBstr, prm_hm[0], 1 ); - IF (prm_hm[0]) + IF( prm_hm[0] ) { /* Periodicy index */ flag = 0; move16(); - if ( GE_16(L_frame, 256)) + if ( GE_16( L_frame, 256 ) ) { flag = 1; move16(); } - EncodeIndex_fx(flag, prm_hm[1], hBstr); + EncodeIndex_fx( flag, prm_hm[1], hBstr ); - IF (EQ_16(st->hTcxCfg->coder_type, VOICED)) + IF( EQ_16( st->hTcxCfg->coder_type, VOICED ) ) { /* Gain index */ - push_next_indice_fx(hBstr, prm_hm[2], kTcxHmNumGainBits); + push_next_indice_fx( hBstr, prm_hm[2], kTcxHmNumGainBits ); } } } @@ -65,9 +64,8 @@ static void enc_prm_hm( *-----------------------------------------------------------------*/ void enc_prm_rf_fx( Encoder_State *st, - const Word16 rf_frame_type, - const Word16 fec_offset - ) + const Word16 rf_frame_type, + const Word16 fec_offset ) { Word16 sfr, nb_subfr, n, index; Word16 ltp_mode, ltf_mode, gains_mode; @@ -80,32 +78,32 @@ void enc_prm_rf_fx( Encoder_State *st, /* partial copy bitstream writing */ test(); - IF ( GE_16(rf_frame_type,RF_TCXFD)&&LE_16(rf_frame_type,RF_TCXTD2)) + IF( GE_16( rf_frame_type, RF_TCXFD ) && LE_16( rf_frame_type, RF_TCXTD2 ) ) { /* TCX frames partial copy write */ /* LSF indices */ - IF( EQ_16(rf_frame_type, RF_TCXFD)) + IF( EQ_16( rf_frame_type, RF_TCXFD ) ) { - push_next_indice_fx( hBstr, hRF->rf_indx_lsf[fec_offset][0], lsf_numbits[0]); /* VQ 1 */ - push_next_indice_fx( hBstr, hRF->rf_indx_lsf[fec_offset][1], lsf_numbits[1]); /* VQ 2 */ - push_next_indice_fx( hBstr, hRF->rf_indx_lsf[fec_offset][2], lsf_numbits[2]); /* VQ 3 */ + push_next_indice_fx( hBstr, hRF->rf_indx_lsf[fec_offset][0], lsf_numbits[0] ); /* VQ 1 */ + push_next_indice_fx( hBstr, hRF->rf_indx_lsf[fec_offset][1], lsf_numbits[1] ); /* VQ 2 */ + push_next_indice_fx( hBstr, hRF->rf_indx_lsf[fec_offset][2], lsf_numbits[2] ); /* VQ 3 */ } /* classification */ test(); test(); - IF( EQ_16(hRF->rf_clas[fec_offset], UNVOICED_CLAS)) + IF( EQ_16( hRF->rf_clas[fec_offset], UNVOICED_CLAS ) ) { index = 0; move16(); } - ELSE IF( (EQ_16(hRF->rf_clas[fec_offset], VOICED_TRANSITION))||(EQ_16(hRF->rf_clas[fec_offset],UNVOICED_TRANSITION))) + ELSE IF( ( EQ_16( hRF->rf_clas[fec_offset], VOICED_TRANSITION ) ) || ( EQ_16( hRF->rf_clas[fec_offset], UNVOICED_TRANSITION ) ) ) { index = 1; move16(); } - ELSE IF( EQ_16(hRF->rf_clas[fec_offset], VOICED_CLAS)) + ELSE IF( EQ_16( hRF->rf_clas[fec_offset], VOICED_CLAS ) ) { index = 2; move16(); @@ -115,12 +113,12 @@ void enc_prm_rf_fx( Encoder_State *st, index = 3; move16(); } - push_next_indice_fx( hBstr, index, 2); + push_next_indice_fx( hBstr, index, 2 ); - IF( EQ_16(rf_frame_type, RF_TCXFD)) + IF( EQ_16( rf_frame_type, RF_TCXFD ) ) { /* TCX global gain = 7 bits */ - push_next_indice_fx( hBstr, hRF->rf_gain_tcx[fec_offset], 7); + push_next_indice_fx( hBstr, hRF->rf_gain_tcx[fec_offset], 7 ); /*window info 1 bit for long overlap 2 if minimum or half overlap*/ @@ -134,17 +132,17 @@ void enc_prm_rf_fx( Encoder_State *st, /* pitch and gain */ /* LTP data */ test(); - IF ( (EQ_16(rf_frame_type, RF_TCXTD1)||EQ_16(rf_frame_type,RF_TCXTD2))&& hTcxEnc->tcxltp!=0) + IF( ( EQ_16( rf_frame_type, RF_TCXTD1 ) || EQ_16( rf_frame_type, RF_TCXTD2 ) ) && hTcxEnc->tcxltp != 0 ) { - push_next_indice_fx( hBstr, hRF->rf_tcxltp_param[fec_offset], 9); + push_next_indice_fx( hBstr, hRF->rf_tcxltp_param[fec_offset], 9 ); } } } - ELSE IF( EQ_16(rf_frame_type,7)) /* NELP bitstream writing */ + ELSE IF( EQ_16( rf_frame_type, 7 ) ) /* NELP bitstream writing */ { /* LSF indices */ - push_next_indice_fx( hBstr, hRF->rf_indx_lsf[fec_offset][0], 8); /* VQ 1 */ - push_next_indice_fx( hBstr, hRF->rf_indx_lsf[fec_offset][1], 8); /* VQ 2 */ + push_next_indice_fx( hBstr, hRF->rf_indx_lsf[fec_offset][0], 8 ); /* VQ 1 */ + push_next_indice_fx( hBstr, hRF->rf_indx_lsf[fec_offset][1], 8 ); /* VQ 2 */ /* NELP gain indices */ push_next_indice_fx( hBstr, hRF->rf_indx_nelp_iG1[fec_offset], 5 ); @@ -157,14 +155,14 @@ void enc_prm_rf_fx( Encoder_State *st, /* tbe gainFr */ push_next_indice_fx( hBstr, hRF->rf_indx_tbeGainFr[fec_offset], 5 ); } - ELSE IF ( GE_16(rf_frame_type,4)) /* rf_frame_type ALL_PRED: 4, NO_PRED: 5, GEN_PRED: 6 */ + ELSE IF( GE_16( rf_frame_type, 4 ) ) /* rf_frame_type ALL_PRED: 4, NO_PRED: 5, GEN_PRED: 6 */ { /* LSF indices */ - push_next_indice_fx( hBstr, hRF->rf_indx_lsf[fec_offset][0], 8); /* VQ 1 */ - push_next_indice_fx( hBstr, hRF->rf_indx_lsf[fec_offset][1], 8); /* VQ 2 */ + push_next_indice_fx( hBstr, hRF->rf_indx_lsf[fec_offset][0], 8 ); /* VQ 1 */ + push_next_indice_fx( hBstr, hRF->rf_indx_lsf[fec_offset][1], 8 ); /* VQ 2 */ /* ES pred */ - push_next_indice_fx( hBstr, hRF->rf_indx_EsPred[fec_offset], 3); + push_next_indice_fx( hBstr, hRF->rf_indx_EsPred[fec_offset], 3 ); ltp_mode = ACELP_LTP_MODE[1][1][rf_frame_type]; ltf_mode = ACELP_LTF_MODE[1][1][rf_frame_type]; @@ -175,34 +173,34 @@ void enc_prm_rf_fx( Encoder_State *st, { /* Pitch lag (5, or 8 bits) */ n = ACELP_LTP_BITS_SFR[ltp_mode][sfr]; - IF (n != 0) + IF( n != 0 ) { - push_next_indice_fx( hBstr, hRF->rf_indx_pitch[fec_offset][sfr], n); + push_next_indice_fx( hBstr, hRF->rf_indx_pitch[fec_offset][sfr], n ); } /* Adaptive codebook filtering (1 bit) */ - IF( EQ_16(ltf_mode,2)) + IF( EQ_16( ltf_mode, 2 ) ) { - push_next_indice_fx( hBstr, hRF->rf_indx_ltfMode[fec_offset][sfr], 1); + push_next_indice_fx( hBstr, hRF->rf_indx_ltfMode[fec_offset][sfr], 1 ); } /*Innovative codebook*/ test(); test(); test(); - IF( (EQ_16(rf_frame_type,RF_NOPRED))|| - (EQ_16(rf_frame_type,RF_GENPRED) && - (sfr == 0 || EQ_16(sfr,2))) ) + IF( ( EQ_16( rf_frame_type, RF_NOPRED ) ) || + ( EQ_16( rf_frame_type, RF_GENPRED ) && + ( sfr == 0 || EQ_16( sfr, 2 ) ) ) ) { - push_next_indice_fx( hBstr, hRF->rf_indx_fcb[fec_offset][sfr], 7); + push_next_indice_fx( hBstr, hRF->rf_indx_fcb[fec_offset][sfr], 7 ); } /* Gains (5b, 6b or 7b / subfr) */ test(); - IF( sfr == 0 || EQ_16(sfr,2)) + IF( sfr == 0 || EQ_16( sfr, 2 ) ) { n = ACELP_GAINS_BITS[gains_mode]; - push_next_indice_fx( hBstr, hRF->rf_indx_gain[fec_offset][sfr], n); + push_next_indice_fx( hBstr, hRF->rf_indx_gain[fec_offset][sfr], n ); } } /* tbe gainFr */ @@ -218,23 +216,20 @@ void enc_prm_rf_fx( Encoder_State *st, /* write FEC offset just before the rf_frame_type */ test(); test(); - IF(EQ_16(fec_offset,2)) + IF( EQ_16( fec_offset, 2 ) ) { - push_next_indice_fx( hBstr, 0, 2); + push_next_indice_fx( hBstr, 0, 2 ); } - ELSE IF(EQ_16(fec_offset,3)||EQ_16(fec_offset,5)||EQ_16(fec_offset,7)) + ELSE IF( EQ_16( fec_offset, 3 ) || EQ_16( fec_offset, 5 ) || EQ_16( fec_offset, 7 ) ) { - push_next_indice_fx( hBstr, (fec_offset - 1)/2, 2); + push_next_indice_fx( hBstr, ( fec_offset - 1 ) / 2, 2 ); } /* write RF frame type last in the bitstream */ - push_next_indice_fx( hBstr, rf_frame_type, 3); - + push_next_indice_fx( hBstr, rf_frame_type, 3 ); } - - /*-----------------------------------------------------------------* * Funtion enc_prm_fx() * * ~~~~~~~~~~~~~~~~~~~~~~ * @@ -247,19 +242,18 @@ void enc_prm_fx( const Word16 coder_type, /* (i) : coding type */ Word16 param[], /* (i) : parameters */ Word16 param_lpc[], /* (i) : LPC parameters */ - Encoder_State *st, /* i/o : quantization Analysis values */ + Encoder_State *st, /* i/o : quantization Analysis values */ Word16 L_frame, - CONTEXT_HM_CONFIG hm_cfg[] - ,Word16 * bits_param_lpc, - Word16 no_param_lpc -) + CONTEXT_HM_CONFIG hm_cfg[], + Word16 *bits_param_lpc, + Word16 no_param_lpc ) { Word16 j, k, n, sfr, core, last_core, *prm, tmp; Word16 nbits_start, total_nbbits; Word16 nbits_header; Word16 nbits_lpc; Word16 nbits_tcx; - Word16 lg,nb_subfr; + Word16 lg, nb_subfr; Word16 lgFB; Word16 nTnsParams; Word16 nTnsBits; @@ -269,7 +263,7 @@ void enc_prm_fx( Word8 flag_ctx_hm; Word16 index; Word32 tmp32; - CONTEXT_HM_CONFIG * phm_cfg; + CONTEXT_HM_CONFIG *phm_cfg; Word16 idx; Word16 start_idx; Word16 nBits; @@ -286,7 +280,7 @@ void enc_prm_fx( move16(); move16(); move16(); - nbits_lpc=0; + nbits_lpc = 0; nbits_tcx = 0; flag_ctx_hm = 0; @@ -314,101 +308,101 @@ void enc_prm_fx( * HEADER *--------------------------------------------------------------------------------*/ - IF (EQ_16(st->mdct_sw, MODE1)) + IF( EQ_16( st->mdct_sw, MODE1 ) ) { /* Adjust st->bits_frame_core not to subtract MODE2 bandwidth signaling */ - st->bits_frame_core = add(st->bits_frame_core, FrameSizeConfig[st->frame_size_index].bandwidth_bits); + st->bits_frame_core = add( st->bits_frame_core, FrameSizeConfig[st->frame_size_index].bandwidth_bits ); /* Write MODE1 core mode signaling */ - signalling_mode1_tcx20_enc(st, 1); + signalling_mode1_tcx20_enc( st, 1 ); } /* Modes (ACE_GC, ACE_UC, TCX20, TCX10...) */ - IF ( st->tcxonly ) + IF( st->tcxonly ) { - push_next_indice_fx( hBstr, core==TCX_10_CORE, 1); + push_next_indice_fx( hBstr, core == TCX_10_CORE, 1 ); { index = 3; move16(); test(); - IF( EQ_16(st->clas, UNVOICED_CLAS)) + IF( EQ_16( st->clas, UNVOICED_CLAS ) ) { index = 0; move16(); } - ELSE IF( (EQ_16(st->clas, VOICED_TRANSITION))||(EQ_16(st->clas,UNVOICED_TRANSITION))) + ELSE IF( ( EQ_16( st->clas, VOICED_TRANSITION ) ) || ( EQ_16( st->clas, UNVOICED_TRANSITION ) ) ) { index = 1; move16(); } - ELSE IF( EQ_16(st->clas, VOICED_CLAS)) + ELSE IF( EQ_16( st->clas, VOICED_CLAS ) ) { index = 2; move16(); } - push_next_indice_fx( hBstr, index, 2); + push_next_indice_fx( hBstr, index, 2 ); } } ELSE { - IF ( core==ACELP_CORE ) + IF( core == ACELP_CORE ) { /* write the RF signalling information */ - IF( EQ_16(st->rf_mode,1)) + IF( EQ_16( st->rf_mode, 1 ) ) { /* find the section in the ACELP signalling table corresponding to bitrate */ idx = 0; - WHILE ( NE_32(acelp_sig_tbl[idx],st->total_brate)) /* total bitrate is kept at 13.2kbps */ + WHILE( NE_32( acelp_sig_tbl[idx], st->total_brate ) ) /* total bitrate is kept at 13.2kbps */ { - idx = add(idx,1); + idx = add( idx, 1 ); } /* retrieve the number of bits for signalling */ nBits = (Word16) acelp_sig_tbl[++idx]; /* retrieve the signalling index */ - idx = add(idx,1); + idx = add( idx, 1 ); start_idx = idx; - tmp32 = SIG2IND_fx(coder_type, st->bwidth, st->sharpFlag, st->rf_mode); - WHILE( NE_32(acelp_sig_tbl[idx], tmp32)) + tmp32 = SIG2IND_fx( coder_type, st->bwidth, st->sharpFlag, st->rf_mode ); + WHILE( NE_32( acelp_sig_tbl[idx], tmp32 ) ) { - idx = add(idx,1); + idx = add( idx, 1 ); } - push_next_indice_fx( hBstr, idx - start_idx, nBits); - push_next_indice_fx( hBstr, 0, 1); /* Indicate to the decoder that the core is ACELP*/ + push_next_indice_fx( hBstr, idx - start_idx, nBits ); + push_next_indice_fx( hBstr, 0, 1 ); /* Indicate to the decoder that the core is ACELP*/ nbits_start = 3; } ELSE { - push_next_indice_fx( hBstr, coder_type, 3); + push_next_indice_fx( hBstr, coder_type, 3 ); } } ELSE { - IF (EQ_16(st->mdct_sw, MODE1)) + IF( EQ_16( st->mdct_sw, MODE1 ) ) { /* 2 bits instead of 3 as TCX is already signaled */ push_next_indice_fx( hBstr, st->hTcxCfg->coder_type, 2 ); } ELSE { - IF (EQ_16(st->mdct_sw_enable, MODE2)) + IF( EQ_16( st->mdct_sw_enable, MODE2 ) ) { - push_next_indice_fx( hBstr, 1, 1); /* TCX */ - push_next_indice_fx( hBstr, 0, 1); /* not HQ_CORE */ - push_next_indice_fx( hBstr, st->hTcxCfg->coder_type, 2); + push_next_indice_fx( hBstr, 1, 1 ); /* TCX */ + push_next_indice_fx( hBstr, 0, 1 ); /* not HQ_CORE */ + push_next_indice_fx( hBstr, st->hTcxCfg->coder_type, 2 ); } ELSE { /*write the RF signalling information*/ - IF( EQ_16(st->rf_mode,1)) + IF( EQ_16( st->rf_mode, 1 ) ) { /* find the section in the ACELP signalling table corresponding to bitrate */ idx = 0; - WHILE (NE_32(acelp_sig_tbl[idx],st->total_brate)) + WHILE( NE_32( acelp_sig_tbl[idx], st->total_brate ) ) { - idx = add(idx,1); + idx = add( idx, 1 ); } /* retrieve the number of bits for signalling */ @@ -416,32 +410,32 @@ void enc_prm_fx( test(); test(); - IF(EQ_16(st->hTcxCfg->coder_type,VOICED)|| - EQ_16(st->hTcxCfg->coder_type,GENERIC)|| - EQ_16(st->hTcxCfg->coder_type,TRANSITION)) + IF( EQ_16( st->hTcxCfg->coder_type, VOICED ) || + EQ_16( st->hTcxCfg->coder_type, GENERIC ) || + EQ_16( st->hTcxCfg->coder_type, TRANSITION ) ) { - st->sharpFlag=1; + st->sharpFlag = 1; } ELSE { - st->sharpFlag=0; + st->sharpFlag = 0; } /* retrieve the signalling index */ - idx = add(idx,1); + idx = add( idx, 1 ); start_idx = idx; - tmp32 = SIG2IND_fx(st->hTcxCfg->coder_type, st->bwidth, st->sharpFlag, st->rf_mode); - WHILE( NE_32(acelp_sig_tbl[idx], tmp32)) + tmp32 = SIG2IND_fx( st->hTcxCfg->coder_type, st->bwidth, st->sharpFlag, st->rf_mode ); + WHILE( NE_32( acelp_sig_tbl[idx], tmp32 ) ) { - idx = add(idx,1); + idx = add( idx, 1 ); } - push_next_indice_fx( hBstr, idx - start_idx, nBits); - push_next_indice_fx( hBstr, 1, 1); /* Indicate to the decoder that the core is TCX*/ + push_next_indice_fx( hBstr, idx - start_idx, nBits ); + push_next_indice_fx( hBstr, 1, 1 ); /* Indicate to the decoder that the core is TCX*/ nbits_start = 3; } ELSE { - push_next_indice_fx( hBstr, 4+st->hTcxCfg->coder_type, 3 ); + push_next_indice_fx( hBstr, 4 + st->hTcxCfg->coder_type, 3 ); } } } @@ -450,33 +444,33 @@ void enc_prm_fx( /* Encode previous mode for error concealment */ test(); - IF (!(core==ACELP_CORE&&st->hTcxCfg->lfacNext<=0)) + IF( !( core == ACELP_CORE && st->hTcxCfg->lfacNext <= 0 ) ) { tmp = 0; move16(); test(); - IF( NE_16(last_core, ACELP_CORE)||EQ_16(core,TCX_10_CORE)) + IF( NE_16( last_core, ACELP_CORE ) || EQ_16( core, TCX_10_CORE ) ) { tmp = TCX_20_CORE; move16(); } - push_next_indice_fx( hBstr, tmp, 1); + push_next_indice_fx( hBstr, tmp, 1 ); } /* write TCX overlap mode (1 bit: full, 2 bits: half or no overlap) */ - IF ( core!=ACELP_CORE ) + IF( core != ACELP_CORE ) { Word16 overlap_code; - assert(st->hTcxCfg->tcx_curr_overlap_mode != NOT_SUPPORTED && st->hTcxCfg->tcx_curr_overlap_mode <= ALDO_WINDOW && st->hTcxCfg->tcx_curr_overlap_mode >= FULL_OVERLAP); /*1 is not allowed!*/ - IF (EQ_16(st->hTcxCfg->tcx_curr_overlap_mode, MIN_OVERLAP)) + assert( st->hTcxCfg->tcx_curr_overlap_mode != NOT_SUPPORTED && st->hTcxCfg->tcx_curr_overlap_mode <= ALDO_WINDOW && st->hTcxCfg->tcx_curr_overlap_mode >= FULL_OVERLAP ); /*1 is not allowed!*/ + IF( EQ_16( st->hTcxCfg->tcx_curr_overlap_mode, MIN_OVERLAP ) ) { nbits_tcx = 2; move16(); overlap_code = 2; move16(); } - ELSE IF (EQ_16(st->hTcxCfg->tcx_curr_overlap_mode, HALF_OVERLAP)) + ELSE IF( EQ_16( st->hTcxCfg->tcx_curr_overlap_mode, HALF_OVERLAP ) ) { nbits_tcx = 2; move16(); @@ -490,7 +484,7 @@ void enc_prm_fx( overlap_code = 0; move16(); } - push_next_indice_fx( hBstr, overlap_code, nbits_tcx); + push_next_indice_fx( hBstr, overlap_code, nbits_tcx ); } IF( st->hPlcExt->enableGplc ) @@ -499,70 +493,70 @@ void enc_prm_fx( enc_prm_side_Info_fx( st->hPlcExt, st ); } - IF( st->glr != 0) + IF( st->glr != 0 ) { test(); test(); test(); test(); - if (core != ACELP_CORE || EQ_16(coder_type,INACTIVE)||(st->last_core==ACELP_CORE&&EQ_16(st->last_coder_type_raw,INACTIVE))||st->glr_reset!=0) + if ( core != ACELP_CORE || EQ_16( coder_type, INACTIVE ) || ( st->last_core == ACELP_CORE && EQ_16( st->last_coder_type_raw, INACTIVE ) ) || st->glr_reset != 0 ) { st->glr_idx[0] = 0; move16(); } - IF( EQ_16(core,ACELP_CORE)) + IF( EQ_16( core, ACELP_CORE ) ) { - push_next_indice_fx( hBstr, st->glr_idx[0], G_LPC_RECOVERY_BITS); + push_next_indice_fx( hBstr, st->glr_idx[0], G_LPC_RECOVERY_BITS ); } } st->glr_reset = 0; move16(); - nbits_header = sub(hBstr->nb_bits_tot_fx, nbits_start); + nbits_header = sub( hBstr->nb_bits_tot_fx, nbits_start ); /*--------------------------------------------------------------------------------* * LPC PARAMETERS *--------------------------------------------------------------------------------*/ - IF ( s_and(st->enableTcxLpc!=0, core != ACELP_CORE) ) + IF( s_and( st->enableTcxLpc != 0, core != ACELP_CORE ) ) { /* Encode the indices */ - nbits_lpc = enc_lsf_tcxlpc_fx(¶m_lpc, hBstr); + nbits_lpc = enc_lsf_tcxlpc_fx( ¶m_lpc, hBstr ); } ELSE { - IF (st->lpcQuantization == 0) + IF( st->lpcQuantization == 0 ) { /* LPC quantizer */ numlpc = 2; move16(); - if(EQ_16(core, TCX_20_CORE)) + if ( EQ_16( core, TCX_20_CORE ) ) { numlpc = 1; move16(); } - nbits_lpc = encode_lpc_avq_fx(hBstr, numlpc, param_lpc, st->core, st->element_mode); + nbits_lpc = encode_lpc_avq_fx( hBstr, numlpc, param_lpc, st->core, st->element_mode ); } - ELSE IF (EQ_16(st->lpcQuantization, 1)) + ELSE IF( EQ_16( st->lpcQuantization, 1 ) ) { test(); test(); - IF(EQ_32(st->sr_core, 16000)&&EQ_16(coder_type,VOICED)&&EQ_16(core,ACELP_CORE)) + IF( EQ_32( st->sr_core, 16000 ) && EQ_16( coder_type, VOICED ) && EQ_16( core, ACELP_CORE ) ) { - nbits_lpc = lsf_bctcvq_encprm_fx(hBstr, param_lpc, bits_param_lpc, no_param_lpc); + nbits_lpc = lsf_bctcvq_encprm_fx( hBstr, param_lpc, bits_param_lpc, no_param_lpc ); } ELSE { - nbits_lpc = lsf_msvq_ma_encprm_fx(hBstr, param_lpc, core, coder_type, st->acelp_cfg.midLpc, bits_param_lpc, no_param_lpc ); + nbits_lpc = lsf_msvq_ma_encprm_fx( hBstr, param_lpc, core, coder_type, st->acelp_cfg.midLpc, bits_param_lpc, no_param_lpc ); } } ELSE { - assert(0 && "LPC quant not supported!"); + assert( 0 && "LPC quant not supported!" ); } } @@ -572,47 +566,46 @@ void enc_prm_fx( *--------------------------------------------------------------------------------*/ - /*--------------------------------------------------------------------------------* * ACELP *--------------------------------------------------------------------------------*/ - IF (core == ACELP_CORE) + IF( core == ACELP_CORE ) { /* Adaptive BPF (2 bits)*/ n = ACELP_BPF_BITS[st->acelp_cfg.bpf_mode]; - IF(n!=0) + IF( n != 0 ) { - push_next_indice_fx( hBstr, st->bpf_gain_param, n); + push_next_indice_fx( hBstr, st->bpf_gain_param, n ); } /* Mean energy (2 or 3 bits) */ n = ACELP_NRG_BITS[st->acelp_cfg.nrg_mode]; - IF(n!=0) + IF( n != 0 ) { - push_next_indice_fx( hBstr, prm[j++], n); + push_next_indice_fx( hBstr, prm[j++], n ); } /* Subframe parameters */ - FOR (sfr=0; sfracelp_cfg.ltp_mode][sfr]; - IF (n!=0) + IF( n != 0 ) { - push_next_indice_fx( hBstr, prm[j++], n); + push_next_indice_fx( hBstr, prm[j++], n ); } /* Adaptive codebook filtering (1 bit) */ - IF(EQ_16(st->acelp_cfg.ltf_mode,2)) + IF( EQ_16( st->acelp_cfg.ltf_mode, 2 ) ) { - push_next_indice_fx( hBstr, prm[j++], 1); + push_next_indice_fx( hBstr, prm[j++], 1 ); } /*Innovative codebook*/ @@ -620,72 +613,72 @@ void enc_prm_fx( move16(); j_old = j; - if ((st->acelp_cfg.fixed_cdk_index[sfr] >= ACELP_FIXED_CDK_NB) || (st->acelp_cfg.fixed_cdk_index[sfr] < 0)) + if ( ( st->acelp_cfg.fixed_cdk_index[sfr] >= ACELP_FIXED_CDK_NB ) || ( st->acelp_cfg.fixed_cdk_index[sfr] < 0 ) ) { - fprintf(stderr,"ACELP bits allocation: wrong fixed cdk bit allocation\n"); - assert(0); + fprintf( stderr, "ACELP bits allocation: wrong fixed cdk bit allocation\n" ); + assert( 0 ); } - wordcnt = shr(ACELP_FIXED_CDK_BITS(st->acelp_cfg.fixed_cdk_index[sfr]), 4); + wordcnt = shr( ACELP_FIXED_CDK_BITS( st->acelp_cfg.fixed_cdk_index[sfr] ), 4 ); - bitcnt = s_and(ACELP_FIXED_CDK_BITS(st->acelp_cfg.fixed_cdk_index[sfr]), 15); + bitcnt = s_and( ACELP_FIXED_CDK_BITS( st->acelp_cfg.fixed_cdk_index[sfr] ), 15 ); - FOR (ix = 0; ix < wordcnt; ix++) + FOR( ix = 0; ix < wordcnt; ix++ ) { - push_next_indice_fx( hBstr, prm[j++], 16); + push_next_indice_fx( hBstr, prm[j++], 16 ); } - IF (bitcnt) + IF( bitcnt ) { - push_next_indice_fx( hBstr, prm[j++], bitcnt); + push_next_indice_fx( hBstr, prm[j++], bitcnt ); } - j = add(j_old, 8); + j = add( j_old, 8 ); } /* Gains (5b, 6b or 7b / subfr) */ n = ACELP_GAINS_BITS[st->acelp_cfg.gains_mode[sfr]]; - push_next_indice_fx( hBstr, prm[j++], n); - }/*end of for(sfr)*/ - }/*end of mode[0]==0*/ + push_next_indice_fx( hBstr, prm[j++], n ); + } /*end of for(sfr)*/ + } /*end of mode[0]==0*/ /*--------------------------------------------------------------------------------* * TCX20 *--------------------------------------------------------------------------------*/ - IF ( s_or((Word16)EQ_16(core,TCX_20_CORE),(Word16)EQ_16(core,HQ_CORE))) + IF( s_or( (Word16) EQ_16( core, TCX_20_CORE ), (Word16) EQ_16( core, HQ_CORE ) ) ) { flag_ctx_hm = 0; move16(); - IF(st->enablePlcWaveadjust) + IF( st->enablePlcWaveadjust ) { - push_next_indice_fx( hBstr, st->Tonal_SideInfo, 1); + push_next_indice_fx( hBstr, st->Tonal_SideInfo, 1 ); } /* TCX Gain = 7 bits */ - push_next_indice_fx( hBstr, prm[j++], 7); + push_next_indice_fx( hBstr, prm[j++], 7 ); /* TCX Noise Filling = NBITS_NOISE_FILL_LEVEL bits */ - push_next_indice_fx( hBstr, prm[j++], NBITS_NOISE_FILL_LEVEL); + push_next_indice_fx( hBstr, prm[j++], NBITS_NOISE_FILL_LEVEL ); /* LTP data */ test(); - IF (hTcxEnc->tcxltp || GT_32(st->sr_core, 25600)) + IF( hTcxEnc->tcxltp || GT_32( st->sr_core, 25600 ) ) { - IF ( prm[j] ) + IF( prm[j] ) { - push_next_indice_fx( hBstr, 1 , 1); - push_next_indice_fx( hBstr, prm[j+1], 9); - push_next_indice_fx( hBstr, prm[j+2], 2); + push_next_indice_fx( hBstr, 1, 1 ); + push_next_indice_fx( hBstr, prm[j + 1], 9 ); + push_next_indice_fx( hBstr, prm[j + 2], 2 ); } ELSE { - push_next_indice_fx( hBstr, 0 , 1); + push_next_indice_fx( hBstr, 0, 1 ); } } - j = add(j, 3); + j = add( j, 3 ); /* TCX spectral data */ lg = L_frame; @@ -693,14 +686,14 @@ void enc_prm_fx( lgFB = st->hTcxCfg->tcx_coded_lines; move16(); - IF ( last_core==ACELP_CORE ) + IF( last_core == ACELP_CORE ) { /* ACE->TCX transition */ - lg = add(lg, st->hTcxCfg->tcx_offset); - lgFB = add(lgFB, shr(lgFB, 2)); - if(st->hTcxCfg->lfacNext<0) + lg = add( lg, st->hTcxCfg->tcx_offset ); + lgFB = add( lgFB, shr( lgFB, 2 ) ); + if ( st->hTcxCfg->lfacNext < 0 ) { - lg = sub(lg,st->hTcxCfg->lfacNext); + lg = sub( lg, st->hTcxCfg->lfacNext ); } } @@ -710,39 +703,39 @@ void enc_prm_fx( nTnsBits = 0; move16(); - IF (st->hTcxCfg->fIsTNSAllowed) + IF( st->hTcxCfg->fIsTNSAllowed ) { - WriteTnsData_fx(st->hTcxCfg->pCurrentTnsConfig, prm+j, &nTnsParams, st, &nTnsBits); - j = add(j, nTnsParams); + WriteTnsData_fx( st->hTcxCfg->pCurrentTnsConfig, prm + j, &nTnsParams, st, &nTnsBits ); + j = add( j, nTnsParams ); } - hm_size = shl(mult(st->hTcxCfg->bandwidth, lg), 1); + hm_size = shl( mult( st->hTcxCfg->bandwidth, lg ), 1 ); test(); - IF (hTcxEnc->tcx_lpc_shaped_ari && NE_16(last_core, ACELP_CORE)) + IF( hTcxEnc->tcx_lpc_shaped_ari && NE_16( last_core, ACELP_CORE ) ) { - enc_prm_hm(&prm[j], st, hm_size); + enc_prm_hm( &prm[j], st, hm_size ); } /*Context HM flag*/ test(); - IF ( st->hTcxCfg->ctx_hm && NE_16(last_core, ACELP_CORE)) + IF( st->hTcxCfg->ctx_hm && NE_16( last_core, ACELP_CORE ) ) { - push_next_indice_fx( hBstr, prm[j], 1); + push_next_indice_fx( hBstr, prm[j], 1 ); - IF (prm[j]) + IF( prm[j] ) { - EncodeIndex_fx(sub(hm_size,256) >= 0, prm[j+1], hBstr); + EncodeIndex_fx( sub( hm_size, 256 ) >= 0, prm[j + 1], hBstr ); flag_ctx_hm = 1; move16(); } } - j = add(j, NPRM_CTX_HM); + j = add( j, NPRM_CTX_HM ); - IF (st->igf) + IF( st->igf ) { st->hIGFEnc->infoTotalBitsPerFrameWritten = 0; move16(); - IF (EQ_16(st->last_core, ACELP_CORE)) + IF( EQ_16( st->last_core, ACELP_CORE ) ) { IGFEncWriteBitstream_fx( st->hIGFEnc, hBstr, &st->hIGFEnc->infoTotalBitsPerFrameWritten, IGF_GRID_LB_TRAN, 1 ); } @@ -751,33 +744,32 @@ void enc_prm_fx( IGFEncWriteBitstream_fx( st->hIGFEnc, hBstr, &st->hIGFEnc->infoTotalBitsPerFrameWritten, IGF_GRID_LB_NORM, 1 ); } } - total_nbbits = sub(hBstr->nb_bits_tot_fx, nbits_start); - if(EQ_16(st->rf_mode,1)) + total_nbbits = sub( hBstr->nb_bits_tot_fx, nbits_start ); + if ( EQ_16( st->rf_mode, 1 ) ) { - total_nbbits = add(total_nbbits,st->rf_target_bits_write); + total_nbbits = add( total_nbbits, st->rf_target_bits_write ); } - nbits_tcx = sub(st->bits_frame_core, total_nbbits); + nbits_tcx = sub( st->bits_frame_core, total_nbbits ); - IF (hTcxEnc->tcx_lpc_shaped_ari != 0) + IF( hTcxEnc->tcx_lpc_shaped_ari != 0 ) { - push_next_bits_fx(hBstr, &prm[++j], nbits_tcx); - j = add(j, nbits_tcx); + push_next_bits_fx( hBstr, &prm[++j], nbits_tcx ); + j = add( j, nbits_tcx ); } ELSE { phm_cfg = NULL; move16(); - if (flag_ctx_hm) + if ( flag_ctx_hm ) { phm_cfg = hm_cfg; move16(); } - ACcontextMapping_encode2_no_mem_s17_LC_fx(hBstr, prm+j, - lgFB, - prm[j-1], /* lastnz */ - nbits_tcx, NPRM_RESQ * st->hTcxCfg->resq, phm_cfg); + ACcontextMapping_encode2_no_mem_s17_LC_fx( hBstr, prm + j, + lgFB, + prm[j - 1], /* lastnz */ + nbits_tcx, NPRM_RESQ * st->hTcxCfg->resq, phm_cfg ); } - } @@ -786,70 +778,70 @@ void enc_prm_fx( *--------------------------------------------------------------------------------*/ - IF (EQ_16(core,TCX_10_CORE)) + IF( EQ_16( core, TCX_10_CORE ) ) { Word16 nbits_igf = 0; move16(); - IF (st->igf) + IF( st->igf ) { nbits_igf = IGFEncWriteConcatenatedBitstream_fx( st->hIGFEnc, hBstr ); } - FOR (k = 0; k < 2; k++) + FOR( k = 0; k < 2; k++ ) { flag_ctx_hm = 0; move16(); move16(); move16(); - prm = param + (k*NPRM_DIV); + prm = param + ( k * NPRM_DIV ); j = 0; move16(); - nbits_tcx = total_nbbits = sub(hBstr->nb_bits_tot_fx, nbits_start); + nbits_tcx = total_nbbits = sub( hBstr->nb_bits_tot_fx, nbits_start ); test(); - IF(st->enablePlcWaveadjust && k) + IF( st->enablePlcWaveadjust && k ) { - push_next_indice_fx( hBstr, st->Tonal_SideInfo, 1); + push_next_indice_fx( hBstr, st->Tonal_SideInfo, 1 ); } /* TCX Gain = 7 bits */ - push_next_indice_fx( hBstr, prm[j++], 7); + push_next_indice_fx( hBstr, prm[j++], 7 ); /* TCX Noise Filling = NBITS_NOISE_FILL_LEVEL bits */ - push_next_indice_fx( hBstr, prm[j++], NBITS_NOISE_FILL_LEVEL); + push_next_indice_fx( hBstr, prm[j++], NBITS_NOISE_FILL_LEVEL ); /* LTP data */ test(); test(); - IF ( (k == 0) && (hTcxEnc->tcxltp!=0 || GT_32(st->sr_core, 25600)))/* PLC pitch info for HB */ + IF( ( k == 0 ) && ( hTcxEnc->tcxltp != 0 || GT_32( st->sr_core, 25600 ) ) ) /* PLC pitch info for HB */ { - IF ( prm[j] ) + IF( prm[j] ) { - push_next_indice_fx( hBstr, 1 , 1); - push_next_indice_fx( hBstr, prm[j+1], 9); - push_next_indice_fx( hBstr, prm[j+2], 2); + push_next_indice_fx( hBstr, 1, 1 ); + push_next_indice_fx( hBstr, prm[j + 1], 9 ); + push_next_indice_fx( hBstr, prm[j + 2], 2 ); } ELSE { - push_next_indice_fx( hBstr, 0 , 1); + push_next_indice_fx( hBstr, 0, 1 ); } } - j = add(j, 3); + j = add( j, 3 ); /* TCX spectral data */ - lg = shr(L_frame, 1); - lgFB = shr(st->hTcxCfg->tcx_coded_lines, 1); + lg = shr( L_frame, 1 ); + lgFB = shr( st->hTcxCfg->tcx_coded_lines, 1 ); - IF ( s_and(k==0, last_core==ACELP_CORE) ) + IF( s_and( k == 0, last_core == ACELP_CORE ) ) { /* ACE->TCX transition */ - lg = add(lg, st->hTcxCfg->tcx_offset); - lgFB = add(lgFB, shr(lgFB, 1)); - if(st->hTcxCfg->lfacNext<0) + lg = add( lg, st->hTcxCfg->tcx_offset ); + lgFB = add( lgFB, shr( lgFB, 1 ) ); + if ( st->hTcxCfg->lfacNext < 0 ) { - lg = sub(lg,st->hTcxCfg->lfacNext); + lg = sub( lg, st->hTcxCfg->lfacNext ); } } @@ -859,48 +851,48 @@ void enc_prm_fx( nTnsParams = 0; nTnsBits = 0; - IF (st->hTcxCfg->fIsTNSAllowed) + IF( st->hTcxCfg->fIsTNSAllowed ) { - SetTnsConfig(st->hTcxCfg, 0, (last_core == ACELP_CORE) && (k == 0)); + SetTnsConfig( st->hTcxCfg, 0, ( last_core == ACELP_CORE ) && ( k == 0 ) ); - WriteTnsData_fx(st->hTcxCfg->pCurrentTnsConfig, prm+j, &nTnsParams, st, &nTnsBits); - j = add(j, nTnsParams); + WriteTnsData_fx( st->hTcxCfg->pCurrentTnsConfig, prm + j, &nTnsParams, st, &nTnsBits ); + j = add( j, nTnsParams ); } - hm_size = shl(mult(st->hTcxCfg->bandwidth, lgFB), 1); + hm_size = shl( mult( st->hTcxCfg->bandwidth, lgFB ), 1 ); /*Context HM flag*/ test(); test(); - IF ( st->hTcxCfg->ctx_hm && !(last_core == ACELP_CORE && k == 0) ) + IF( st->hTcxCfg->ctx_hm && !( last_core == ACELP_CORE && k == 0 ) ) { - push_next_indice_fx( hBstr, prm[j], 1); + push_next_indice_fx( hBstr, prm[j], 1 ); - IF (prm[j]) + IF( prm[j] ) { - EncodeIndex_fx(sub(hm_size,256) >= 0, prm[j+1], hBstr); + EncodeIndex_fx( sub( hm_size, 256 ) >= 0, prm[j + 1], hBstr ); flag_ctx_hm = 1; move16(); } } - j = add(j, NPRM_CTX_HM); + j = add( j, NPRM_CTX_HM ); - total_nbbits = sub(hBstr->nb_bits_tot_fx, nbits_start); + total_nbbits = sub( hBstr->nb_bits_tot_fx, nbits_start ); - nbits_tcx = sub(shr(sub(add(sub(sub(sub(st->bits_frame_core, nbits_header), nbits_lpc), nbits_igf), 1), k), 1), sub(total_nbbits, nbits_tcx)); + nbits_tcx = sub( shr( sub( add( sub( sub( sub( st->bits_frame_core, nbits_header ), nbits_lpc ), nbits_igf ), 1 ), k ), 1 ), sub( total_nbbits, nbits_tcx ) ); phm_cfg = NULL; move16(); - if (flag_ctx_hm) + if ( flag_ctx_hm ) { phm_cfg = &hm_cfg[k]; move16(); } - ACcontextMapping_encode2_no_mem_s17_LC_fx(hBstr, prm+j, - lgFB, - prm[j-1], /* lastnz */ - nbits_tcx, NPRM_RESQ * st->hTcxCfg->resq, phm_cfg); + ACcontextMapping_encode2_no_mem_s17_LC_fx( hBstr, prm + j, + lgFB, + prm[j - 1], /* lastnz */ + nbits_tcx, NPRM_RESQ * st->hTcxCfg->resq, phm_cfg ); } /* k, window index */ } @@ -911,16 +903,15 @@ void enc_prm_fx( *--------------------------------------------------------------------------------*/ - total_nbbits = sub(hBstr->nb_bits_tot_fx, nbits_start); + total_nbbits = sub( hBstr->nb_bits_tot_fx, nbits_start ); /* Check if total encoded bits does not exceed CBR target bits (->this must never happen) */ - if (st->bits_frame_core&&(total_nbbits>st->bits_frame_core)) + if ( st->bits_frame_core && ( total_nbbits > st->bits_frame_core ) ) { - fprintf(stderr,"AllocatedBits: %d Used bits: %d \n", st->bits_frame_core,total_nbbits); - assert(!"Core totalbits > CBR target bitrate"); + fprintf( stderr, "AllocatedBits: %d Used bits: %d \n", st->bits_frame_core, total_nbbits ); + assert( !"Core totalbits > CBR target bitrate" ); } return; } - diff --git a/lib_enc/enc_tran_fx.c b/lib_enc/enc_tran_fx.c index 879d391cf..a0a9ff902 100644 --- a/lib_enc/enc_tran_fx.c +++ b/lib_enc/enc_tran_fx.c @@ -2,14 +2,14 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ +#include "options.h" /* Compilation switches */ #include "cnst.h" /* Compilation switches */ //#include "prot_fx.h" /* Function prototypes */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "rom_com_fx.h" /* Static table prototypes */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*=================================================================================*/ /* FUNCTION : void encod_tran_fx () */ @@ -46,51 +46,51 @@ /*---------------------------------------------------------------------------------*/ Word16 encod_tran_fx( - Encoder_State *st_fx, /* i/o: state structure */ - const Word16 speech_fx[], /* i : input speech */ - const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */ - const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - const Word16 *res_fx, /* i : residual signal */ - Word16 *syn_fx, /* i/o: core synthesis */ - Word16 *exc_fx, /* i/o: current non-enhanced excitation */ - Word16 *exc2_fx, /* i/o: current enhanced excitation */ - Word16 *pitch_buf_fx, /* i/o: floating pitch values for each subframe */ - Word16 *voice_factors, /* o : voicing factors */ - Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE */ - Word16 tc_subfr, /* i/o: TC subframe classification */ - Word16 position, /* i : maximum of residual signal index */ - Word16 *unbits, /* i/o: number of unused bits */ - const Word16 shift, /* i : Scaling to get 12 bits */ - const Word16 Q_new /* i : Input scaling */ + Encoder_State *st_fx, /* i/o: state structure */ + const Word16 speech_fx[], /* i : input speech */ + const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */ + const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ + const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ + const Word16 *res_fx, /* i : residual signal */ + Word16 *syn_fx, /* i/o: core synthesis */ + Word16 *exc_fx, /* i/o: current non-enhanced excitation */ + Word16 *exc2_fx, /* i/o: current enhanced excitation */ + Word16 *pitch_buf_fx, /* i/o: floating pitch values for each subframe */ + Word16 *voice_factors, /* o : voicing factors */ + Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE */ + Word16 tc_subfr, /* i/o: TC subframe classification */ + Word16 position, /* i : maximum of residual signal index */ + Word16 *unbits, /* i/o: number of unused bits */ + const Word16 shift, /* i : Scaling to get 12 bits */ + const Word16 Q_new /* i : Input scaling */ ) { - Word16 xn[L_SUBFR]; /* Target vector for pitch search */ - Word16 xn2[L_SUBFR]; /* Target vector for codebook search */ - Word16 cn[L_SUBFR]; /* Target vector in residual domain */ - Word16 h1[L_SUBFR+(M+1)]; /* Impulse response vector */ - Word16 h2_fx[L_SUBFR+(M+1)]; /* Impulse response vector */ - Word16 code[L_SUBFR]; /* Fixed codebook excitation */ - Word16 y1[L_SUBFR]; /* Filtered adaptive excitation */ - Word16 y2[L_SUBFR]; /* Filtered algebraic excitation */ - Word16 gain_pit = 0,Gain_pitX2,gcode16; /* Pitch gain */ - Word16 voice_fac; /* Voicing factor */ - Word32 gain_code = 0; /* Gain of code */ + Word16 xn[L_SUBFR]; /* Target vector for pitch search */ + Word16 xn2[L_SUBFR]; /* Target vector for codebook search */ + Word16 cn[L_SUBFR]; /* Target vector in residual domain */ + Word16 h1[L_SUBFR + ( M + 1 )]; /* Impulse response vector */ + Word16 h2_fx[L_SUBFR + ( M + 1 )]; /* Impulse response vector */ + Word16 code[L_SUBFR]; /* Fixed codebook excitation */ + Word16 y1[L_SUBFR]; /* Filtered adaptive excitation */ + Word16 y2[L_SUBFR]; /* Filtered algebraic excitation */ + Word16 gain_pit = 0, Gain_pitX2, gcode16; /* Pitch gain */ + Word16 voice_fac; /* Voicing factor */ + Word32 gain_code = 0; /* Gain of code */ Word32 Lgcode; - Word16 gain_inov=0; /* inovation gain */ - Word16 i, i_subfr,tmp1_fx,tmp_fx; /* tmp variables */ + Word16 gain_inov = 0; /* inovation gain */ + Word16 i, i_subfr, tmp1_fx, tmp_fx; /* tmp variables */ Word16 unbits_ACELP; - Word16 T0_min, T0_max; /* pitch and TC variables */ - Word16 T0, T0_frac; /* close loop integer pitch and fractional part */ - Word16 *pt_pitch; /* pointer to floating pitch buffer */ - Word16 g_corr[10]; /* ACELP correlation values and gain pitch */ - Word16 clip_gain; /* LSF clip gain */ - const Word16 *p_Aw, *p_Aq; /* pointer to LP filter coefficient vector */ - Word16 gain_preQ = 0; /* Gain of prequantizer excitation */ - Word16 code_preQ[L_SUBFR]; /* Prequantizer excitation */ - Word16 Jopt_flag; /* joint optimization flag */ - Word16 unbits_PI = 0; /* saved bits for PI */ - Word32 norm_gain_code=0; + Word16 T0_min, T0_max; /* pitch and TC variables */ + Word16 T0, T0_frac; /* close loop integer pitch and fractional part */ + Word16 *pt_pitch; /* pointer to floating pitch buffer */ + Word16 g_corr[10]; /* ACELP correlation values and gain pitch */ + Word16 clip_gain; /* LSF clip gain */ + const Word16 *p_Aw, *p_Aq; /* pointer to LP filter coefficient vector */ + Word16 gain_preQ = 0; /* Gain of prequantizer excitation */ + Word16 code_preQ[L_SUBFR]; /* Prequantizer excitation */ + Word16 Jopt_flag; /* joint optimization flag */ + Word16 unbits_PI = 0; /* saved bits for PI */ + Word32 norm_gain_code = 0; Word16 L_frame_fx; Word16 shift_wsp; Word32 L_tmp; @@ -98,7 +98,7 @@ Word16 encod_tran_fx( Flag Overflow = 0; #endif BSTR_ENC_HANDLE hBstr = st_fx->hBstr; - SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; + SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; L_frame_fx = st_fx->L_frame; @@ -108,12 +108,12 @@ Word16 encod_tran_fx( *------------------------------------------------------------------*/ gain_pit = 0; move16(); - gain_code = L_deposit_l(0); + gain_code = L_deposit_l( 0 ); gain_preQ = 0; move16(); unbits_PI = 0; move16(); - IF( EQ_16(L_frame_fx,L_FRAME)) + IF( EQ_16( L_frame_fx, L_FRAME ) ) { T0_max = PIT_MAX; move16(); @@ -142,13 +142,13 @@ Word16 encod_tran_fx( gain_preQ = 0; move16(); set16_fx( code_preQ, 0, L_SUBFR ); - shift_wsp = add(Q_new,shift); + shift_wsp = add( Q_new, shift ); /*----------------------------------------------------------------* * ACELP subframe loop *----------------------------------------------------------------*/ - FOR ( i_subfr=0; i_subfrmem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq, res_fx, L_SUBFR, p_Aw, st_fx->preemph_fac, xn, cn, h1 ); - Copy_Scale_sig(h1, h2_fx, L_SUBFR, -2); - Scale_sig(h1, L_SUBFR, add(1, shift)); /* set h1[] in Q14 with scaling for convolution */ + Copy_Scale_sig( h1, h2_fx, L_SUBFR, -2 ); + Scale_sig( h1, L_SUBFR, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution */ /* scaling of xn[] to limit dynamic at 12 bits */ - Scale_sig(xn, L_SUBFR, shift); + Scale_sig( xn, L_SUBFR, shift ); /*-----------------------------------------------------------------* * TC: subframe determination & * adaptive/glottal part of excitation construction *-----------------------------------------------------------------*/ - transition_enc_fx( st_fx, i_subfr, &tc_subfr, &Jopt_flag, &position, &T0, &T0_frac, &T0_min, &T0_max, exc_fx, y1, - h1, xn, xn2, st_fx->clip_var_fx, &gain_pit, g_corr, &clip_gain, &pt_pitch, bwe_exc_fx ,&unbits_ACELP, Q_new,shift); + transition_enc_fx( st_fx, i_subfr, &tc_subfr, &Jopt_flag, &position, &T0, &T0_frac, &T0_min, &T0_max, exc_fx, y1, + h1, xn, xn2, st_fx->clip_var_fx, &gain_pit, g_corr, &clip_gain, &pt_pitch, bwe_exc_fx, &unbits_ACELP, Q_new, shift ); /*-----------------------------------------------------------------* * Transform domain contribution encoding - active frames *-----------------------------------------------------------------*/ - IF( GE_32(st_fx->core_brate, MIN_BRATE_AVQ_EXC)) + IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) ) { - transf_cdbk_enc_fx( st_fx, 0, i_subfr, cn, exc_fx, p_Aq, Aw_fx, h1, xn, xn2, y1, y2, Es_pred_fx, - &gain_pit, gain_code, g_corr, clip_gain, &gain_preQ, code_preQ, unbits, Q_new, shift); + transf_cdbk_enc_fx( st_fx, 0, i_subfr, cn, exc_fx, p_Aq, Aw_fx, h1, xn, xn2, y1, y2, Es_pred_fx, + &gain_pit, gain_code, g_corr, clip_gain, &gain_preQ, code_preQ, unbits, Q_new, shift ); } /*-----------------------------------------------------------------* @@ -195,7 +195,7 @@ Word16 encod_tran_fx( test(); test(); test(); - if( (EQ_16(st_fx->L_frame,L_FRAME16k))&&(tc_subfr==0)&&(EQ_16(i_subfr,L_SUBFR))&&(EQ_16(T0,2*L_SUBFR))) + if ( ( EQ_16( st_fx->L_frame, L_FRAME16k ) ) && ( tc_subfr == 0 ) && ( EQ_16( i_subfr, L_SUBFR ) ) && ( EQ_16( T0, 2 * L_SUBFR ) ) ) { Jopt_flag = 1; move16(); @@ -208,50 +208,50 @@ Word16 encod_tran_fx( IF( Jopt_flag == 0 ) { /* SQ gain_code */ - gain_enc_tc_fx(hBstr, st_fx->acelp_cfg.gains_mode, i_subfr, xn, y2, code, Es_pred_fx, + gain_enc_tc_fx( hBstr, st_fx->acelp_cfg.gains_mode, i_subfr, xn, y2, code, Es_pred_fx, &gain_pit, &gain_code, &gain_inov, &norm_gain_code, shift_wsp ); } ELSE { - IF ( GT_32(st_fx->core_brate,ACELP_32k)) + IF( GT_32( st_fx->core_brate, ACELP_32k ) ) { /* SQ gain_pit and gain_code */ - gain_enc_SQ_fx(hBstr, st_fx->acelp_cfg.gains_mode, i_subfr, xn, y1, y2, code, Es_pred_fx, - &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain, shift_wsp ); + gain_enc_SQ_fx( hBstr, st_fx->acelp_cfg.gains_mode, i_subfr, xn, y1, y2, code, Es_pred_fx, + &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain, shift_wsp ); } ELSE { /* VQ gain_pit and gain_code */ - gain_enc_mless_fx(hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, L_frame_fx, i_subfr, tc_subfr, xn, y1, shift_wsp, y2, code, Es_pred_fx, - &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain ); + gain_enc_mless_fx( hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, L_frame_fx, i_subfr, tc_subfr, xn, y1, shift_wsp, y2, code, Es_pred_fx, + &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain ); } } - gp_clip_test_gain_pit_fx(st_fx->element_mode, st_fx->core_brate, gain_pit, st_fx->clip_var_fx ); + gp_clip_test_gain_pit_fx( st_fx->element_mode, st_fx->core_brate, gain_pit, st_fx->clip_var_fx ); #ifdef BASOP_NOGLOB - Lgcode = L_shl_o(gain_code, Q_new, &Overflow); /* scaled gain_code with Qnew -> Q16*/ - gcode16 = round_fx_o(Lgcode, &Overflow); + Lgcode = L_shl_o( gain_code, Q_new, &Overflow ); /* scaled gain_code with Qnew -> Q16*/ + gcode16 = round_fx_o( Lgcode, &Overflow ); #else - Lgcode = L_shl(gain_code, Q_new); /* scaled gain_code with Qnew -> Q16*/ - gcode16 = round_fx(Lgcode); + Lgcode = L_shl( gain_code, Q_new ); /* scaled gain_code with Qnew -> Q16*/ + gcode16 = round_fx( Lgcode ); #endif - hLPDmem->tilt_code = Est_tilt2(&exc_fx[i_subfr], gain_pit, code, Lgcode, &voice_fac, shift); + hLPDmem->tilt_code = Est_tilt2( &exc_fx[i_subfr], gain_pit, code, Lgcode, &voice_fac, shift ); /*-----------------------------------------------------------------* - * Update memory of the weighting filter - *-----------------------------------------------------------------*/ + * Update memory of the weighting filter + *-----------------------------------------------------------------*/ /*st->mem_w0 = xn[L_SUBFR-1] - (gain_pit*y1[L_SUBFR-1]) - (gain_code*y2[L_SUBFR-1]);*/ - L_tmp = L_mult(gcode16, y2[L_SUBFR - 1]); - L_tmp = L_shl(L_tmp, add(5, shift)); - L_tmp = L_negate(L_tmp); - L_tmp = L_mac(L_tmp, xn[L_SUBFR - 1], 16384); - L_tmp = L_msu(L_tmp, y1[L_SUBFR - 1], gain_pit); + L_tmp = L_mult( gcode16, y2[L_SUBFR - 1] ); + L_tmp = L_shl( L_tmp, add( 5, shift ) ); + L_tmp = L_negate( L_tmp ); + L_tmp = L_mac( L_tmp, xn[L_SUBFR - 1], 16384 ); + L_tmp = L_msu( L_tmp, y1[L_SUBFR - 1], gain_pit ); #ifdef BASOP_NOGLOB L_tmp = L_shl_sat( L_tmp, sub( 1, shift ) ); - hLPDmem->mem_w0 = round_fx_sat(L_tmp); /*Q_new-1*/ + hLPDmem->mem_w0 = round_fx_sat( L_tmp ); /*Q_new-1*/ #else - L_tmp = L_shl(L_tmp, sub(1, shift)); - hLPDmem->mem_w0 = round_fx(L_tmp); /*Q_new-1*/ + L_tmp = L_shl( L_tmp, sub( 1, shift ) ); + hLPDmem->mem_w0 = round_fx( L_tmp ); /*Q_new-1*/ #endif /*-----------------------------------------------------------------* * Construct adaptive part of the excitation @@ -264,23 +264,23 @@ Word16 encod_tran_fx( /* when they don't use all 16 bits of precision */ /* exc Q_exc, gpit Q14, code Q12, gcode Q0 */ - IF (norm_s(gain_pit) == 0) + IF( norm_s( gain_pit ) == 0 ) { - FOR (i = 0; i < L_SUBFR; i++) + FOR( i = 0; i < L_SUBFR; i++ ) { #ifdef BASOP_NOGLOB exc2_fx[i + i_subfr] = round_fx_sat( L_shl_sat( L_mult_sat( gain_pit, exc_fx[i + i_subfr] ), 1 ) ); #else - exc2_fx[i+i_subfr] = round_fx(L_shl(L_mult(gain_pit,exc_fx[i+i_subfr]),1)); + exc2_fx[i + i_subfr] = round_fx( L_shl( L_mult( gain_pit, exc_fx[i + i_subfr] ), 1 ) ); #endif } } ELSE { - Gain_pitX2 = shl(gain_pit, 1); - FOR (i = 0; i < L_SUBFR; i++) + Gain_pitX2 = shl( gain_pit, 1 ); + FOR( i = 0; i < L_SUBFR; i++ ) { - exc2_fx[i+i_subfr] = mult_r(Gain_pitX2,exc_fx[i+i_subfr]); + exc2_fx[i + i_subfr] = mult_r( Gain_pitX2, exc_fx[i + i_subfr] ); } } @@ -288,20 +288,20 @@ Word16 encod_tran_fx( * Construct adaptive part of the excitation * Save the non-enhanced excitation for FEC_exc *-----------------------------------------------------------------*/ - FOR (i = 0; i < L_SUBFR; i++) + FOR( i = 0; i < L_SUBFR; i++ ) { /* code in Q9, gain_pit in Q14 */ - L_tmp = L_mult(gcode16, code[i]); + L_tmp = L_mult( gcode16, code[i] ); #ifdef BASOP_NOGLOB - L_tmp = L_shl_o(L_tmp, 5, &Overflow); - L_tmp = L_mac_o(L_tmp, exc_fx[i + i_subfr], gain_pit, &Overflow); - L_tmp = L_shl_o(L_tmp, 1, &Overflow); /* saturation can occur here */ - exc_fx[i + i_subfr] = round_fx_o(L_tmp, &Overflow); + L_tmp = L_shl_o( L_tmp, 5, &Overflow ); + L_tmp = L_mac_o( L_tmp, exc_fx[i + i_subfr], gain_pit, &Overflow ); + L_tmp = L_shl_o( L_tmp, 1, &Overflow ); /* saturation can occur here */ + exc_fx[i + i_subfr] = round_fx_o( L_tmp, &Overflow ); #else - L_tmp = L_shl(L_tmp, 5); - L_tmp = L_mac(L_tmp, exc_fx[i + i_subfr], gain_pit); - L_tmp = L_shl(L_tmp, 1); /* saturation can occur here */ - exc_fx[i + i_subfr] = round_fx(L_tmp); + L_tmp = L_shl( L_tmp, 5 ); + L_tmp = L_mac( L_tmp, exc_fx[i + i_subfr], gain_pit ); + L_tmp = L_shl( L_tmp, 1 ); /* saturation can occur here */ + exc_fx[i + i_subfr] = round_fx( L_tmp ); #endif } @@ -309,27 +309,27 @@ Word16 encod_tran_fx( * Add the ACELP pre-quantizer contribution *-----------------------------------------------------------------*/ - IF( GE_32(st_fx->core_brate, MIN_BRATE_AVQ_EXC)) + IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) ) { - tmp1_fx = add(16-(2+Q_AVQ_OUT_DEC+1),Q_new); + tmp1_fx = add( 16 - ( 2 + Q_AVQ_OUT_DEC + 1 ), Q_new ); FOR( i = 0; i < L_SUBFR; i++ ) { - L_tmp = L_mult(gain_preQ, code_preQ[i]); /* Q2 + Q10 -> Q13*/ + L_tmp = L_mult( gain_preQ, code_preQ[i] ); /* Q2 + Q10 -> Q13*/ #ifdef BASOP_NOGLOB - L_tmp = L_shl_o(L_tmp,tmp1_fx, &Overflow); /* Q16 + Q_exc */ - tmp_fx = round_fx_o(L_tmp, &Overflow); + L_tmp = L_shl_o( L_tmp, tmp1_fx, &Overflow ); /* Q16 + Q_exc */ + tmp_fx = round_fx_o( L_tmp, &Overflow ); - exc2_fx[i+i_subfr] = add_o(exc2_fx[i+i_subfr],tmp_fx, &Overflow); + exc2_fx[i + i_subfr] = add_o( exc2_fx[i + i_subfr], tmp_fx, &Overflow ); move16(); - exc_fx[i+i_subfr] = add_o(exc_fx[i+i_subfr],tmp_fx, &Overflow); + exc_fx[i + i_subfr] = add_o( exc_fx[i + i_subfr], tmp_fx, &Overflow ); move16(); #else - L_tmp = L_shl(L_tmp,tmp1_fx); /* Q16 + Q_exc */ - tmp_fx = round_fx(L_tmp); + L_tmp = L_shl( L_tmp, tmp1_fx ); /* Q16 + Q_exc */ + tmp_fx = round_fx( L_tmp ); - exc2_fx[i+i_subfr] = add(exc2_fx[i+i_subfr],tmp_fx); + exc2_fx[i + i_subfr] = add( exc2_fx[i + i_subfr], tmp_fx ); move16(); - exc_fx[i+i_subfr] = add(exc_fx[i+i_subfr],tmp_fx); + exc_fx[i + i_subfr] = add( exc_fx[i + i_subfr], tmp_fx ); move16(); #endif } @@ -339,7 +339,7 @@ Word16 encod_tran_fx( * Prepare TBE excitation *-----------------------------------------------------------------*/ - prep_tbe_exc_fx( L_frame_fx, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr/L_SUBFR], + prep_tbe_exc_fx( L_frame_fx, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR], bwe_exc_fx, gain_preQ, code_preQ, Q_new, T0, T0_frac, st_fx->coder_type, st_fx->core_brate ); /*-----------------------------------------------------------------* @@ -349,96 +349,94 @@ Word16 encod_tran_fx( Syn_filt_s( 1, p_Aq, M, &exc_fx[i_subfr], &syn_fx[i_subfr], L_SUBFR, hLPDmem->mem_syn, 1 ); - p_Aw += (M+1); - p_Aq += (M+1); + p_Aw += ( M + 1 ); + p_Aq += ( M + 1 ); pt_pitch++; } /* write reserved bits */ WHILE( unbits_PI > 0 ) { - i = s_min(unbits_PI, 16); + i = s_min( unbits_PI, 16 ); push_indice_fx( hBstr, IND_UNUSED, 0, i ); unbits_PI -= i; } /* write TC configuration */ - IF( EQ_16(L_frame_fx,L_FRAME)) + IF( EQ_16( L_frame_fx, L_FRAME ) ) { - IF( EQ_16(tc_subfr,TC_0_0)) + IF( EQ_16( tc_subfr, TC_0_0 ) ) { push_indice_fx( hBstr, IND_TC_SUBFR, 1, 1 ); } - ELSE IF( EQ_16(tc_subfr,TC_0_64)) + ELSE IF( EQ_16( tc_subfr, TC_0_64 ) ) { push_indice_fx( hBstr, IND_TC_SUBFR, 0, 1 ); push_indice_fx( hBstr, IND_TC_SUBFR, 1, 1 ); push_indice_fx( hBstr, IND_TC_SUBFR, 0, 1 ); push_indice_fx( hBstr, IND_TC_SUBFR, 1, 1 ); } - ELSE IF( EQ_16(tc_subfr,TC_0_128)) + ELSE IF( EQ_16( tc_subfr, TC_0_128 ) ) { push_indice_fx( hBstr, IND_TC_SUBFR, 0, 1 ); push_indice_fx( hBstr, IND_TC_SUBFR, 1, 1 ); push_indice_fx( hBstr, IND_TC_SUBFR, 0, 1 ); push_indice_fx( hBstr, IND_TC_SUBFR, 0, 1 ); } - ELSE IF( EQ_16(tc_subfr,TC_0_192)) + ELSE IF( EQ_16( tc_subfr, TC_0_192 ) ) { push_indice_fx( hBstr, IND_TC_SUBFR, 0, 1 ); push_indice_fx( hBstr, IND_TC_SUBFR, 1, 1 ); push_indice_fx( hBstr, IND_TC_SUBFR, 1, 1 ); } - ELSE IF( EQ_16(tc_subfr,L_SUBFR)) + ELSE IF( EQ_16( tc_subfr, L_SUBFR ) ) { push_indice_fx( hBstr, IND_TC_SUBFR, 0, 1 ); push_indice_fx( hBstr, IND_TC_SUBFR, 0, 1 ); push_indice_fx( hBstr, IND_TC_SUBFR, 1, 1 ); } - ELSE IF( EQ_16(tc_subfr,2*L_SUBFR)) + ELSE IF( EQ_16( tc_subfr, 2 * L_SUBFR ) ) { push_indice_fx( hBstr, IND_TC_SUBFR, 0, 1 ); push_indice_fx( hBstr, IND_TC_SUBFR, 0, 1 ); push_indice_fx( hBstr, IND_TC_SUBFR, 0, 1 ); push_indice_fx( hBstr, IND_TC_SUBFR, 1, 1 ); } - ELSE IF( EQ_16(tc_subfr,3*L_SUBFR)) + ELSE IF( EQ_16( tc_subfr, 3 * L_SUBFR ) ) { push_indice_fx( hBstr, IND_TC_SUBFR, 0, 1 ); push_indice_fx( hBstr, IND_TC_SUBFR, 0, 1 ); push_indice_fx( hBstr, IND_TC_SUBFR, 0, 1 ); push_indice_fx( hBstr, IND_TC_SUBFR, 0, 1 ); } - } - ELSE /* L_frame == L_FRAME16k */ + ELSE /* L_frame == L_FRAME16k */ { IF( tc_subfr == 0 ) { push_indice_fx( hBstr, IND_TC_SUBFR, 0, 2 ); } - ELSE IF( EQ_16(tc_subfr,L_SUBFR)) + ELSE IF( EQ_16( tc_subfr, L_SUBFR ) ) { push_indice_fx( hBstr, IND_TC_SUBFR, 1, 2 ); } - ELSE IF( EQ_16(tc_subfr,2*L_SUBFR)) + ELSE IF( EQ_16( tc_subfr, 2 * L_SUBFR ) ) { push_indice_fx( hBstr, IND_TC_SUBFR, 2, 2 ); } - ELSE IF( EQ_16(tc_subfr,3*L_SUBFR)) + ELSE IF( EQ_16( tc_subfr, 3 * L_SUBFR ) ) { push_indice_fx( hBstr, IND_TC_SUBFR, 3, 2 ); push_indice_fx( hBstr, IND_TC_SUBFR, 0, 1 ); } - ELSE IF( EQ_16(tc_subfr,4*L_SUBFR)) + ELSE IF( EQ_16( tc_subfr, 4 * L_SUBFR ) ) { push_indice_fx( hBstr, IND_TC_SUBFR, 3, 2 ); push_indice_fx( hBstr, IND_TC_SUBFR, 1, 1 ); } - } - IF(st_fx->Opt_SC_VBR) + IF( st_fx->Opt_SC_VBR ) { /* SC-VBR */ hSC_VBR->prev_ppp_gain_pit_fx = gain_pit; diff --git a/lib_enc/enc_uv_fx.c b/lib_enc/enc_uv_fx.c index 418b12f53..c67a5781e 100644 --- a/lib_enc/enc_uv_fx.c +++ b/lib_enc/enc_uv_fx.c @@ -3,13 +3,13 @@ ====================================================================================*/ #include #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ //#include "prot_fx.h" /* Function prototypes */ #include "rom_com.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* * encod_unvoiced() @@ -18,7 +18,7 @@ *-------------------------------------------------------------------*/ /*fixed point implementation of unvoiced_encoder*/ void encod_unvoiced_fx( - Encoder_State *st_fx, /* i/o: state structure */ + Encoder_State *st_fx, /* i/o: state structure */ const Word16 *speech_fx, /* i : Input speech */ const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */ const Word16 *Aq_fx, /* i : 12k8 Lp coefficient */ @@ -32,26 +32,25 @@ void encod_unvoiced_fx( Word16 *voice_factors_fx, /* o : voicing factors */ Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE */ const Word16 Q_new, - const Word16 shift -) + const Word16 shift ) { - Word16 xn_fx[L_SUBFR]; /* Target vector for pitch search */ - Word16 h1_fx[L_SUBFR]; /* Impulse response vector */ - Word16 code_fx[L_SUBFR]; /* Fixed codebook excitation */ - Word16 y2_fx[L_SUBFR]; /* Filtered algebraic excitation */ - Word16 *pt_pitch_fx; /* pointer to floating pitch buffer */ - Word16 gain_pit_fx; /* Pitch gain */ - Word16 voice_fac_fx; /* Voicing factor */ - Word32 L_gain_code_fx; /* gain of code */ - Word16 gain_inov_fx; /* inovative gain */ - Word16 cn_fx[L_SUBFR]; /* Target vector in residual domain */ - Word16 y1[L_SUBFR]; /* Filtered adaptive excitation */ - Word16 code2[L_SUBFR]; /* Gaussian excitation */ - Word16 y22[L_SUBFR]; /* Filtered Gaussian excitation */ + Word16 xn_fx[L_SUBFR]; /* Target vector for pitch search */ + Word16 h1_fx[L_SUBFR]; /* Impulse response vector */ + Word16 code_fx[L_SUBFR]; /* Fixed codebook excitation */ + Word16 y2_fx[L_SUBFR]; /* Filtered algebraic excitation */ + Word16 *pt_pitch_fx; /* pointer to floating pitch buffer */ + Word16 gain_pit_fx; /* Pitch gain */ + Word16 voice_fac_fx; /* Voicing factor */ + Word32 L_gain_code_fx; /* gain of code */ + Word16 gain_inov_fx; /* inovative gain */ + Word16 cn_fx[L_SUBFR]; /* Target vector in residual domain */ + Word16 y1[L_SUBFR]; /* Filtered adaptive excitation */ + Word16 code2[L_SUBFR]; /* Gaussian excitation */ + Word16 y22[L_SUBFR]; /* Filtered Gaussian excitation */ Word16 prm_t[2 * NPRM_DIV], *prm = prm_t; - const Word16 *p_Aw_fx, *p_Aq_fx; /* pointer to LP filter coeff. vector */ + const Word16 *p_Aw_fx, *p_Aq_fx; /* pointer to LP filter coeff. vector */ Word32 norm_gain_code_fx; - ACELP_config* acelp_cfg; + ACELP_config *acelp_cfg; ACELP_CbkCorr g_corr; Word32 gain_code2; Word32 gain_code_vect[2], Ltmp, Ltmp2; @@ -62,20 +61,20 @@ void encod_unvoiced_fx( Word16 i_subfr, Q_xn, Q_new_p5, tmp2, j, i; Word16 index, i_subfr_idx; #endif - acelp_cfg = &(st_fx->acelp_cfg); - SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; + acelp_cfg = &( st_fx->acelp_cfg ); + SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; /*------------------------------------------------------------------* - * Initializations - *------------------------------------------------------------------*/ + * Initializations + *------------------------------------------------------------------*/ gain_pit_fx = 0; move16(); test(); test(); test(); - IF( st_fx->Opt_SC_VBR && st_fx->vad_flag == 0 && (EQ_16(hSC_VBR->last_ppp_mode,1) || EQ_16(hSC_VBR->last_nelp_mode,1))) + IF( st_fx->Opt_SC_VBR && st_fx->vad_flag == 0 && ( EQ_16( hSC_VBR->last_ppp_mode, 1 ) || EQ_16( hSC_VBR->last_nelp_mode, 1 ) ) ) { /* SC_VBR - reset the encoder, to avoid memory not updated issue for the case when UNVOICED mode is used to code inactive speech */ @@ -86,46 +85,46 @@ void encod_unvoiced_fx( p_Aq_fx = Aq_fx; pt_pitch_fx = pitch_buf_fx; move16(); - Q_xn = add(sub(Q_new, 1), shift); - Q_new_p5 = add(Q_new, 5); + Q_xn = add( sub( Q_new, 1 ), shift ); + Q_new_p5 = add( Q_new, 5 ); - FOR (i_subfr=0; i_subfrmem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq_fx, - res_fx, L_SUBFR, p_Aw_fx, st_fx->preemph_fac, xn_fx, cn_fx, h1_fx); + res_fx, L_SUBFR, p_Aw_fx, st_fx->preemph_fac, xn_fx, cn_fx, h1_fx ); /*Copy_Scale_sig(h1_fx, h2_fx, L_SUBFR, -2);*/ - Scale_sig(h1_fx, L_SUBFR, add(1, shift)); /* set h1[] in Q14 with scaling for convolution */ + Scale_sig( h1_fx, L_SUBFR, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution */ /* scaling of xn[] to limit dynamic at 12 bits */ - Scale_sig(xn_fx, L_SUBFR, shift); + Scale_sig( xn_fx, L_SUBFR, shift ); /*----------------------------------------------------------------* * Unvoiced subframe processing *----------------------------------------------------------------*/ - IF (!uc_two_stage_flag) + IF( !uc_two_stage_flag ) { - *pt_pitch_fx = gaus_encode_fx(st_fx, i_subfr, h1_fx, xn_fx, exc_fx, &hLPDmem->mem_w0, st_fx->clip_var_fx, - &hLPDmem->tilt_code, code_fx, &L_gain_code_fx, y2_fx, &gain_inov_fx, - &voice_fac_fx, &gain_pit_fx, Q_new, shift, &norm_gain_code_fx); + *pt_pitch_fx = gaus_encode_fx( st_fx, i_subfr, h1_fx, xn_fx, exc_fx, &hLPDmem->mem_w0, st_fx->clip_var_fx, + &hLPDmem->tilt_code, code_fx, &L_gain_code_fx, y2_fx, &gain_inov_fx, + &voice_fac_fx, &gain_pit_fx, Q_new, shift, &norm_gain_code_fx ); } ELSE { /*----------------------------------------------------------------* * Unvoiced subframe processing in two stages *----------------------------------------------------------------*/ - //PMT("The code below needs validation, never been tested") + // PMT("The code below needs validation, never been tested") /* No adaptive codebook (UC) */ - set16_fx(y1, 0, L_SUBFR); - set16_fx(exc_fx + i_subfr, 0, L_SUBFR); + set16_fx( y1, 0, L_SUBFR ); + set16_fx( exc_fx + i_subfr, 0, L_SUBFR ); /*-----------------------------------------------------------------* * Gain clipping test to avoid unstable synthesis on frame erasure * or in case of floating point encoder & fixed p. decoder @@ -133,7 +132,7 @@ void encod_unvoiced_fx( #if 0 clip_gain = Mode2_gp_clip(st_fx->voicing_fx, i_subfr, st_fx->coder_type, xn_fx, st_fx->clip_var_fx, L_SUBFR, Q_xn); #else - Mode2_gp_clip(st_fx->voicing_fx, i_subfr, st_fx->coder_type, xn_fx, st_fx->clip_var_fx, L_SUBFR, Q_xn); + Mode2_gp_clip( st_fx->voicing_fx, i_subfr, st_fx->coder_type, xn_fx, st_fx->clip_var_fx, L_SUBFR, Q_xn ); #endif *pt_pitch_fx = L_SUBFR; move16(); @@ -141,32 +140,32 @@ void encod_unvoiced_fx( * Encode the algebraic innovation * *----------------------------------------------------------------------*/ - E_ACELP_innovative_codebook_fx(exc_fx, *pt_pitch_fx, 0, 1, gain_pit_fx, hLPDmem->tilt_code, acelp_cfg, i_subfr, p_Aq_fx, h1_fx, xn_fx, cn_fx, y1, y2_fx, (Word8)st_fx->acelp_autocorr, &prm, code_fx, shift, st_fx->L_frame, st_fx->last_L_frame, st_fx->total_brate); + E_ACELP_innovative_codebook_fx( exc_fx, *pt_pitch_fx, 0, 1, gain_pit_fx, hLPDmem->tilt_code, acelp_cfg, i_subfr, p_Aq_fx, h1_fx, xn_fx, cn_fx, y1, y2_fx, (Word8) st_fx->acelp_autocorr, &prm, code_fx, shift, st_fx->L_frame, st_fx->last_L_frame, st_fx->total_brate ); - E_ACELP_xy2_corr(xn_fx, y1, y2_fx, &g_corr, L_SUBFR, Q_xn); + E_ACELP_xy2_corr( xn_fx, y1, y2_fx, &g_corr, L_SUBFR, Q_xn ); - g_corr.y2y2_e = sub(g_corr.y2y2_e, 18); /* -18 (y2*y2: Q9*Q9) */ - g_corr.xy2_e = sub(g_corr.xy2_e, add(Q_xn, 9)); /* -(Q_xn+9) (xn: Q_xn y2: Q9) */ - g_corr.y1y2_e = sub(g_corr.y1y2_e, add(Q_xn, 9)); /* -(Q_xn+9) (y1: Q_xn y2: Q9) */ - g_corr.xx_e = sub(g_corr.xx_e, add(Q_xn, Q_xn)); /* -(Q_xn+Q_xn) (xn: Q_xn) */ + g_corr.y2y2_e = sub( g_corr.y2y2_e, 18 ); /* -18 (y2*y2: Q9*Q9) */ + g_corr.xy2_e = sub( g_corr.xy2_e, add( Q_xn, 9 ) ); /* -(Q_xn+9) (xn: Q_xn y2: Q9) */ + g_corr.y1y2_e = sub( g_corr.y1y2_e, add( Q_xn, 9 ) ); /* -(Q_xn+9) (y1: Q_xn y2: Q9) */ + g_corr.xx_e = sub( g_corr.xx_e, add( Q_xn, Q_xn ) ); /* -(Q_xn+Q_xn) (xn: Q_xn) */ - assert(gain_pit_fx == 0); - gauss_L2_fx(h1_fx, code2, y2_fx, y22, &gain_code2, &g_corr, gain_pit_fx, hLPDmem->tilt_code, p_Aq_fx, acelp_cfg->formant_enh_num, &(st_fx->seed_acelp), shift); + assert( gain_pit_fx == 0 ); + gauss_L2_fx( h1_fx, code2, y2_fx, y22, &gain_code2, &g_corr, gain_pit_fx, hLPDmem->tilt_code, p_Aq_fx, acelp_cfg->formant_enh_num, &( st_fx->seed_acelp ), shift ); /*----------------------------------------------------------* * - Compute the fixed codebook gain * * - quantize fixed codebook gain * *----------------------------------------------------------*/ - index = gain_enc_uv_fx(code_fx, code2, L_SUBFR, &gain_pit_fx, &L_gain_code_fx, &gain_code2, - st_fx->flag_noisy_speech_snr_fx, &g_corr, Es_pred, &norm_gain_code_fx, &gain_inov_fx, FUNC_GAIN_ENC_GACELP_UV); + index = gain_enc_uv_fx( code_fx, code2, L_SUBFR, &gain_pit_fx, &L_gain_code_fx, &gain_code2, + st_fx->flag_noisy_speech_snr_fx, &g_corr, Es_pred, &norm_gain_code_fx, &gain_inov_fx, FUNC_GAIN_ENC_GACELP_UV ); #ifdef DEBUGGING - assert(st_fx->acelp_cfg.gains_mode[i_subfr_idx] == 7 && "Error: UC two-stage, only 5+2 gain Q is supported"); + assert( st_fx->acelp_cfg.gains_mode[i_subfr_idx] == 7 && "Error: UC two-stage, only 5+2 gain Q is supported" ); #endif - push_indice_fx(st_fx->hBstr, IND_GAIN, index, st_fx->acelp_cfg.gains_mode[i_subfr_idx]); + push_indice_fx( st_fx->hBstr, IND_GAIN, index, st_fx->acelp_cfg.gains_mode[i_subfr_idx] ); - gp_clip_test_gain_pit_fx(st_fx->element_mode, st_fx->core_brate, gain_pit_fx, st_fx->clip_var_fx); + gp_clip_test_gain_pit_fx( st_fx->element_mode, st_fx->core_brate, gain_pit_fx, st_fx->clip_var_fx ); gain_code_vect[0] = L_gain_code_fx; move32(); @@ -176,30 +175,30 @@ void encod_unvoiced_fx( /*----------------------------------------------------------* * - voice factor (for pitch enhancement) * *----------------------------------------------------------*/ - E_UTIL_voice_factor(exc_fx, i_subfr, code_fx, gain_pit_fx, L_gain_code_fx, &voice_fac_fx, &(hLPDmem->tilt_code), L_SUBFR, acelp_cfg->voice_tilt, Q_new, shift); + E_UTIL_voice_factor( exc_fx, i_subfr, code_fx, gain_pit_fx, L_gain_code_fx, &voice_fac_fx, &( hLPDmem->tilt_code ), L_SUBFR, acelp_cfg->voice_tilt, Q_new, shift ); - IF(st_fx->Opt_RF_ON) + IF( st_fx->Opt_RF_ON ) { st_fx->hRF->rf_tilt_buf[i_subfr_idx] = hLPDmem->tilt_code; } /*-----------------------------------------------------------------* * Update memory of the weighting filter *-----------------------------------------------------------------*/ - /* st_fx->mem_w0 = xn[L_SUBFR-1] - (gain_pit*y1[L_SUBFR-1]) - (gain_code*y2[L_SUBFR-1]); */ - Ltmp = Mpy_32_16_1(L_gain_code_fx, y2_fx[L_SUBFR - 1]); - Ltmp = L_shl(Ltmp, add(5, Q_xn)); - Ltmp = L_mac(Ltmp, y1[L_SUBFR - 1], gain_pit_fx); + /* st_fx->mem_w0 = xn[L_SUBFR-1] - (gain_pit*y1[L_SUBFR-1]) - (gain_code*y2[L_SUBFR-1]); */ + Ltmp = Mpy_32_16_1( L_gain_code_fx, y2_fx[L_SUBFR - 1] ); + Ltmp = L_shl( Ltmp, add( 5, Q_xn ) ); + Ltmp = L_mac( Ltmp, y1[L_SUBFR - 1], gain_pit_fx ); /* Add Gaussian contribution*/ - Ltmp2 = Mpy_32_16_1(gain_code2, y22[L_SUBFR - 1]); - Ltmp2 = L_shl(Ltmp2, add(5, Q_xn)); - Ltmp = L_add(Ltmp, Ltmp2); - hLPDmem->mem_w0 = sub(xn_fx[L_SUBFR - 1], round_fx(L_shl(Ltmp, 1))); + Ltmp2 = Mpy_32_16_1( gain_code2, y22[L_SUBFR - 1] ); + Ltmp2 = L_shl( Ltmp2, add( 5, Q_xn ) ); + Ltmp = L_add( Ltmp, Ltmp2 ); + hLPDmem->mem_w0 = sub( xn_fx[L_SUBFR - 1], round_fx( L_shl( Ltmp, 1 ) ) ); move16(); BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB hLPDmem->mem_w0 = shr_sat( hLPDmem->mem_w0, shift ); /*Qnew-1*/ #else - hLPDmem->mem_w0 = shr(hLPDmem->mem_w0, shift); /*Qnew-1*/ + hLPDmem->mem_w0 = shr( hLPDmem->mem_w0, shift ); /*Qnew-1*/ #endif BASOP_SATURATE_WARNING_ON_EVS; @@ -207,31 +206,31 @@ void encod_unvoiced_fx( * - Find the total excitation. * *-------------------------------------------------------*/ - tmp2 = shr(L_SUBFR, 1); - FOR(j = 0; j < 2; j++) + tmp2 = shr( L_SUBFR, 1 ); + FOR( j = 0; j < 2; j++ ) { - FOR(i = sub(tmp2, shr(L_SUBFR, 1)); i < tmp2; i++) + FOR( i = sub( tmp2, shr( L_SUBFR, 1 ) ); i < tmp2; i++ ) { /* code in Q9, gain_pit in Q14; exc Q_new */ - Ltmp = Mpy_32_16_1(gain_code2, code2[i]); - Ltmp = L_shl(Ltmp, Q_new_p5); - Ltmp = L_mac(Ltmp, gain_pit_fx, exc_fx[i + i_subfr]); + Ltmp = Mpy_32_16_1( gain_code2, code2[i] ); + Ltmp = L_shl( Ltmp, Q_new_p5 ); + Ltmp = L_mac( Ltmp, gain_pit_fx, exc_fx[i + i_subfr] ); #if 0 BASOP_SATURATE_WARNING_OFF_EVS exc2[i] = round_fx(L_shl(Ltmp, 1)); BASOP_SATURATE_WARNING_ON_EVS #endif - Ltmp2 = Mpy_32_16_1(gain_code_vect[j], code_fx[i]); - Ltmp2 = L_shl(Ltmp2, Q_new_p5); - Ltmp = L_add(Ltmp, Ltmp2); + Ltmp2 = Mpy_32_16_1( gain_code_vect[j], code_fx[i] ); + Ltmp2 = L_shl( Ltmp2, Q_new_p5 ); + Ltmp = L_add( Ltmp, Ltmp2 ); #ifdef BASOP_NOGLOB - Ltmp = L_shl_sat(Ltmp, 1); /* saturation can occur here */ - exc_fx[i + i_subfr] = round_fx_sat(Ltmp); + Ltmp = L_shl_sat( Ltmp, 1 ); /* saturation can occur here */ + exc_fx[i + i_subfr] = round_fx_sat( Ltmp ); #else BASOP_SATURATE_WARNING_OFF_EVS - Ltmp = L_shl(Ltmp, 1); /* saturation can occur here */ + Ltmp = L_shl( Ltmp, 1 ); /* saturation can occur here */ BASOP_SATURATE_WARNING_ON_EVS - exc_fx[i + i_subfr] = round_fx(Ltmp); + exc_fx[i + i_subfr] = round_fx( Ltmp ); #endif } tmp2 = L_SUBFR; @@ -239,8 +238,8 @@ void encod_unvoiced_fx( } } - *tmp_noise_fx = extract_h(norm_gain_code_fx); - voice_factors_fx[i_subfr/L_SUBFR] = 0; + *tmp_noise_fx = extract_h( norm_gain_code_fx ); + voice_factors_fx[i_subfr / L_SUBFR] = 0; move16(); interp_code_5over2_fx( &exc_fx[i_subfr], &bwe_exc_fx[i_subfr * HIBND_ACB_L_FAC], L_SUBFR ); @@ -249,10 +248,10 @@ void encod_unvoiced_fx( * Synthesize speech to update mem_syn[]. * Update A(z) filters *-----------------------------------------------------------------*/ - Syn_filt_s(1, p_Aq_fx, M, &exc_fx[i_subfr], &syn_fx[i_subfr], L_SUBFR, hLPDmem->mem_syn, 1 ); + Syn_filt_s( 1, p_Aq_fx, M, &exc_fx[i_subfr], &syn_fx[i_subfr], L_SUBFR, hLPDmem->mem_syn, 1 ); - p_Aw_fx += (M+1); - p_Aq_fx += (M+1); + p_Aw_fx += ( M + 1 ); + p_Aq_fx += ( M + 1 ); pt_pitch_fx++; } diff --git a/lib_enc/energy_fx.c b/lib_enc/energy_fx.c index ca455bf55..f14e0b407 100644 --- a/lib_enc/energy_fx.c +++ b/lib_enc/energy_fx.c @@ -9,37 +9,37 @@ #include "rom_enc.h" #include "vad_basop.h" //#include "prot_fx.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* * est_energy_fx() * * *-------------------------------------------------------------------*/ void est_energy_fx( - Word32 enerBuffer[CLDFB_NO_CHANNELS_MAX], /* i : energy vector per band */ - Word16 enerBuffer_exp, /* i : exponent of energy vector */ - Word32 *frame_sb_energy, /* o : energy of sub-band divided non-uniformly*/ - Word32 *frame_energy2_p, /* o : frame energy 2*/ - Word32 *HB_Power_p, /* o : high frequency energy*/ - Word32 *frame_energy_p, /* o : frame energy 1*/ - Word16 *sb_power_Q, /* o : the scaling of sb_power*/ - Word16 *frame_energy2_Q, /* o : the scaling of frame_energy*/ - Word16 *HB_Power_Q, /* o : the scaling of HB_Power*/ - Word16 *frame_energy_Q, /* o : the Scaling of frame_energy*/ - Word16 *frame_sb_energy_scale, /* o : the Scaling of frame_sb_energy[]*/ - const Word32 bandwidth /* i : band width*/ + Word32 enerBuffer[CLDFB_NO_CHANNELS_MAX], /* i : energy vector per band */ + Word16 enerBuffer_exp, /* i : exponent of energy vector */ + Word32 *frame_sb_energy, /* o : energy of sub-band divided non-uniformly*/ + Word32 *frame_energy2_p, /* o : frame energy 2*/ + Word32 *HB_Power_p, /* o : high frequency energy*/ + Word32 *frame_energy_p, /* o : frame energy 1*/ + Word16 *sb_power_Q, /* o : the scaling of sb_power*/ + Word16 *frame_energy2_Q, /* o : the scaling of frame_energy*/ + Word16 *HB_Power_Q, /* o : the scaling of HB_Power*/ + Word16 *frame_energy_Q, /* o : the Scaling of frame_energy*/ + Word16 *frame_sb_energy_scale, /* o : the Scaling of frame_sb_energy[]*/ + const Word32 bandwidth /* i : band width*/ ) { - Word32 i,j; - Word32 frame_energy2,HB_Power,tmpspec_amp; + Word32 i, j; + Word32 frame_energy2, HB_Power, tmpspec_amp; Word32 sb_power_tmp; - Word32 frame_energy,s32CopyPower; + Word32 frame_energy, s32CopyPower; Word32 SNR_sb_num; Word16 shr_tmp; Word32 BandNum; - Word16 widthsb,s16MaxCoefNorm; + Word16 widthsb, s16MaxCoefNorm; const Word16 *Nregion_index; Word32 *sb_power = enerBuffer; Word32 Ltmp32 = 0; @@ -47,9 +47,9 @@ void est_energy_fx( Flag Overflow = 0; #endif move32(); - SNR_sb_num = SNR_SUB_BAND_NUM[bandwidth-CLDFBVAD_NB_ID]; + SNR_sb_num = SNR_SUB_BAND_NUM[bandwidth - CLDFBVAD_NB_ID]; move16(); - Nregion_index = REGION_INDEX[bandwidth-CLDFBVAD_NB_ID]; + Nregion_index = REGION_INDEX[bandwidth - CLDFBVAD_NB_ID]; move16(); shr_tmp = BAND_SCALE_AJ[bandwidth]; @@ -57,42 +57,44 @@ void est_energy_fx( BandNum = BAND_NUM_TAB[bandwidth]; move16(); - frame_energy2 = L_shr(sb_power[1], shr_tmp); - HB_Power = L_shr(sb_power[6], shr_tmp); - FOR(i = 2; i < BandNum; i++) + frame_energy2 = L_shr( sb_power[1], shr_tmp ); + HB_Power = L_shr( sb_power[6], shr_tmp ); + FOR( i = 2; i < BandNum; i++ ) { - Ltmp32 = L_shr(sb_power[i],shr_tmp); + Ltmp32 = L_shr( sb_power[i], shr_tmp ); #ifdef BASOP_NOGLOB frame_energy2 = L_add_sat( frame_energy2, Ltmp32 ); - if(i > 6) HB_Power = L_add_sat(HB_Power, Ltmp32 ); + if ( i > 6 ) + HB_Power = L_add_sat( HB_Power, Ltmp32 ); #else - frame_energy2 = L_add(frame_energy2, Ltmp32 ); - if(i > 6) HB_Power = L_add(HB_Power, Ltmp32 ); + frame_energy2 = L_add( frame_energy2, Ltmp32 ); + if ( i > 6 ) + HB_Power = L_add( HB_Power, Ltmp32 ); #endif } - frame_energy2 = L_sub(frame_energy2, Ltmp32 ); + frame_energy2 = L_sub( frame_energy2, Ltmp32 ); - sb_power_tmp = L_shr(sb_power[0],shr_tmp); + sb_power_tmp = L_shr( sb_power[0], shr_tmp ); - IF(EQ_32(bandwidth,1)) + IF( EQ_32( bandwidth, 1 ) ) { - frame_energy = L_add(frame_energy2,MUL_F(sb_power_tmp,0x147a)); + frame_energy = L_add( frame_energy2, MUL_F( sb_power_tmp, 0x147a ) ); } - ELSE IF(EQ_32(bandwidth,2)) + ELSE IF( EQ_32( bandwidth, 2 ) ) { - frame_energy = L_add(frame_energy2,MUL_F(sb_power_tmp,0x1eb8)); + frame_energy = L_add( frame_energy2, MUL_F( sb_power_tmp, 0x1eb8 ) ); } - ELSE IF(EQ_32(bandwidth,3)) + ELSE IF( EQ_32( bandwidth, 3 ) ) { - frame_energy = L_add(frame_energy2,MUL_F(sb_power_tmp,0x23d7)); + frame_energy = L_add( frame_energy2, MUL_F( sb_power_tmp, 0x23d7 ) ); } - ELSE IF(EQ_32(bandwidth,4)) + ELSE IF( EQ_32( bandwidth, 4 ) ) { - frame_energy = L_add(frame_energy2,MUL_F(sb_power_tmp,0x23d7)); + frame_energy = L_add( frame_energy2, MUL_F( sb_power_tmp, 0x23d7 ) ); } ELSE { - frame_energy = L_add(frame_energy2,MUL_F(sb_power_tmp,0x23d7)); + frame_energy = L_add( frame_energy2, MUL_F( sb_power_tmp, 0x23d7 ) ); } *frame_energy2_p = frame_energy2; @@ -103,37 +105,37 @@ void est_energy_fx( move32(); /* enerBuffer(float) = enerBuffer(fixed) * 2^(-(31-enerBuffer_exp)) */ /* +30 is to keep original precision */ - *sb_power_Q = sub(31+30,enerBuffer_exp); + *sb_power_Q = sub( 31 + 30, enerBuffer_exp ); move16(); - *frame_energy2_Q = sub(*sb_power_Q,shr_tmp); + *frame_energy2_Q = sub( *sb_power_Q, shr_tmp ); move16(); - *HB_Power_Q = sub(*sb_power_Q,shr_tmp); + *HB_Power_Q = sub( *sb_power_Q, shr_tmp ); move16(); - *frame_energy_Q = sub(*sb_power_Q,shr_tmp); + *frame_energy_Q = sub( *sb_power_Q, shr_tmp ); move16(); - FOR(i=0; i<6; i++) + FOR( i = 0; i < 6; i++ ) { frame_sb_energy[i] = sb_power[i]; move32(); } - FOR(i=6; if_tonality_rate; Word16 *ltd_stable_rate = hVAD_CLDFB->ltd_stable_rate; Word32 bandwith = hVAD_CLDFB->bw_index; @@ -245,7 +243,7 @@ void background_update_fx( move16(); - tmp = L_deposit_l(-1); + tmp = L_deposit_l( -1 ); CONST32fix.s16Exp = 44; move16(); @@ -265,13 +263,13 @@ void background_update_fx( t_bg_energy_sum = hVAD_CLDFB->t_bg_energy_sum; move32(); - normscal = norm_l(frame_energy); - exp_frame_energy.s16Exp = add(scale,normscal); - exp_frame_energy.s32Mantissa = L_shl(frame_energy,normscal); - exp_frame_energy = VAD_AddExp(exp_frame_energy,CONST32fix); - cmp_lt_frame = VAD_L_CMP(exp_frame_energy.s32Mantissa,exp_frame_energy.s16Exp,46,0); + normscal = norm_l( frame_energy ); + exp_frame_energy.s16Exp = add( scale, normscal ); + exp_frame_energy.s32Mantissa = L_shl( frame_energy, normscal ); + exp_frame_energy = VAD_AddExp( exp_frame_energy, CONST32fix ); + cmp_lt_frame = VAD_L_CMP( exp_frame_energy.s32Mantissa, exp_frame_energy.s16Exp, 46, 0 ); - FOR(i=0; iframeloop, 60)) && (GT_16(hVAD_CLDFB->frameloop,5)) && (LT_16(f_tonality_rate[0],9174/* 0.56 Q14 */)) - && (LT_16(f_tonality_rate[1],8192/* 0.5 Q14 */)) && (LT_16(ltd_stable_rate[1],1966/* 0.06 Q15 */)) - && LT_32(snr, 83886080) ) + IF( ( LT_16( hVAD_CLDFB->frameloop, 60 ) ) && ( GT_16( hVAD_CLDFB->frameloop, 5 ) ) && ( LT_16( f_tonality_rate[0], 9174 /* 0.56 Q14 */ ) ) && ( LT_16( f_tonality_rate[1], 8192 /* 0.5 Q14 */ ) ) && ( LT_16( ltd_stable_rate[1], 1966 /* 0.06 Q15 */ ) ) && LT_32( snr, 83886080 ) ) { - IF( LT_16(hVAD_CLDFB->frameloop, 50) ) - { - exp_frame_energy_amendment.s32Mantissa = VAD_L_div(exp_frame_energy.s32Mantissa, 10, exp_frame_energy.s16Exp, 0, &q_divout); + IF( LT_16( hVAD_CLDFB->frameloop, 50 ) ) + { + exp_frame_energy_amendment.s32Mantissa = VAD_L_div( exp_frame_energy.s32Mantissa, 10, exp_frame_energy.s16Exp, 0, &q_divout ); exp_frame_energy_amendment.s16Exp = q_divout; - t_bg_energy_sum = VAD_AddExp(t_bg_energy_sum,exp_frame_energy_amendment); - } - ELSE - { - t_bg_energy_sum = VAD_AddExp(t_bg_energy_sum,exp_frame_energy); - } - update_sb_bg_energy(sb_bg_energy, &hVAD_CLDFB->tbg_energy_count, p_scale_sb_energy, SNR_sb_num, frame_sb_energy, hVAD_CLDFB->frame_sb_energy_scale, - 29490/* 0.90 Q15 */, 3, 5242/* 0.01 Q19 */);//5243 + t_bg_energy_sum = VAD_AddExp( t_bg_energy_sum, exp_frame_energy_amendment ); + } + ELSE + { + t_bg_energy_sum = VAD_AddExp( t_bg_energy_sum, exp_frame_energy ); + } + update_sb_bg_energy( sb_bg_energy, &hVAD_CLDFB->tbg_energy_count, p_scale_sb_energy, SNR_sb_num, frame_sb_energy, hVAD_CLDFB->frame_sb_energy_scale, + 29490 /* 0.90 Q15 */, 3, 5242 /* 0.01 Q19 */ ); // 5243 } test(); test(); - IF((EQ_32(update_flag,1)) && (GT_16(hVAD_CLDFB->frameloop,2)) && music_backgound_f==0) + IF( ( EQ_32( update_flag, 1 ) ) && ( GT_16( hVAD_CLDFB->frameloop, 2 ) ) && music_backgound_f == 0 ) { - IF(LT_16(hVAD_CLDFB->bg_update_count, 16)) + IF( LT_16( hVAD_CLDFB->bg_update_count, 16 ) ) { - IF( LT_16(hVAD_CLDFB->frameloop, 50) ) + IF( LT_16( hVAD_CLDFB->frameloop, 50 ) ) { - exp_frame_energy_amendment.s32Mantissa = VAD_L_div(exp_frame_energy.s32Mantissa, 10, exp_frame_energy.s16Exp, 0, &q_divout); + exp_frame_energy_amendment.s32Mantissa = VAD_L_div( exp_frame_energy.s32Mantissa, 10, exp_frame_energy.s16Exp, 0, &q_divout ); exp_frame_energy_amendment.s16Exp = q_divout; - t_bg_energy_sum = VAD_AddExp(t_bg_energy_sum,exp_frame_energy_amendment); + t_bg_energy_sum = VAD_AddExp( t_bg_energy_sum, exp_frame_energy_amendment ); } ELSE { - t_bg_energy_sum = VAD_AddExp(t_bg_energy_sum,exp_frame_energy); + t_bg_energy_sum = VAD_AddExp( t_bg_energy_sum, exp_frame_energy ); } - update_sb_bg_energy(sb_bg_energy, &hVAD_CLDFB->tbg_energy_count, p_scale_sb_energy, SNR_sb_num, frame_sb_energy, hVAD_CLDFB->frame_sb_energy_scale, - 31456/* 0.96 Q15 */, 4, 20971/* 0.04 Q19 */); + update_sb_bg_energy( sb_bg_energy, &hVAD_CLDFB->tbg_energy_count, p_scale_sb_energy, SNR_sb_num, frame_sb_energy, hVAD_CLDFB->frame_sb_energy_scale, + 31456 /* 0.96 Q15 */, 4, 20971 /* 0.04 Q19 */ ); - hVAD_CLDFB->bg_update_count = add(hVAD_CLDFB->bg_update_count, 1); + hVAD_CLDFB->bg_update_count = add( hVAD_CLDFB->bg_update_count, 1 ); } ELSE { - cmp_lt_frame = VAD_L_CMP(t_bg_energy, hVAD_CLDFB->scale_t_bg_energy, exp_frame_energy.s32Mantissa, exp_frame_energy.s16Exp); - cmp_pre_frame = VAD_L_CMP(MUL_F(hVAD_CLDFB->frame_energy_smooth, 24576), sub(hVAD_CLDFB->frame_energy_smooth_scale, 5), exp_frame_energy.s32Mantissa, exp_frame_energy.s16Exp); - cmp_tmp = VAD_L_CMP(MUL_F(t_bg_energy, 24576), sub(hVAD_CLDFB->scale_t_bg_energy, 4), exp_frame_energy.s32Mantissa, exp_frame_energy.s16Exp); + cmp_lt_frame = VAD_L_CMP( t_bg_energy, hVAD_CLDFB->scale_t_bg_energy, exp_frame_energy.s32Mantissa, exp_frame_energy.s16Exp ); + cmp_pre_frame = VAD_L_CMP( MUL_F( hVAD_CLDFB->frame_energy_smooth, 24576 ), sub( hVAD_CLDFB->frame_energy_smooth_scale, 5 ), exp_frame_energy.s32Mantissa, exp_frame_energy.s16Exp ); + cmp_tmp = VAD_L_CMP( MUL_F( t_bg_energy, 24576 ), sub( hVAD_CLDFB->scale_t_bg_energy, 4 ), exp_frame_energy.s32Mantissa, exp_frame_energy.s16Exp ); test(); - IF( (cmp_lt_frame < 0) && (cmp_pre_frame < 0) ) + IF( ( cmp_lt_frame < 0 ) && ( cmp_pre_frame < 0 ) ) { - tmpQ = add(9, hVAD_CLDFB->frame_sb_energy_scale); - FOR(i=0; iframe_sb_energy_scale ); + FOR( i = 0; i < SNR_sb_num; i++ ) { - sb_bg_energy_ti = MUL_F(sb_bg_energy[i], 32734/* 0.999 Q15 */); - tmp = MUL_F(frame_sb_energy[i], 16777/* 0.001 Q24 */); - sb_bg_energy[i] = VAD_L_ADD(sb_bg_energy_ti, p_scale_sb_energy[i], tmp, tmpQ, &p_scale_sb_energy[i]); + sb_bg_energy_ti = MUL_F( sb_bg_energy[i], 32734 /* 0.999 Q15 */ ); + tmp = MUL_F( frame_sb_energy[i], 16777 /* 0.001 Q24 */ ); + sb_bg_energy[i] = VAD_L_ADD( sb_bg_energy_ti, p_scale_sb_energy[i], tmp, tmpQ, &p_scale_sb_energy[i] ); move32(); } } /*ELSE IF(L_sub(tmp, -1) == 0) fixed bug*/ - ELSE IF(cmp_tmp < 0) + ELSE IF( cmp_tmp < 0 ) { - IF( LT_16(hVAD_CLDFB->frameloop, 50) ) + IF( LT_16( hVAD_CLDFB->frameloop, 50 ) ) { - exp_frame_energy_amendment.s32Mantissa = VAD_L_div(exp_frame_energy.s32Mantissa, 10, exp_frame_energy.s16Exp, 0, &q_divout); - exp_frame_energy_amendment.s16Exp = q_divout; - t_bg_energy_sum = VAD_AddExp(t_bg_energy_sum,exp_frame_energy_amendment); + exp_frame_energy_amendment.s32Mantissa = VAD_L_div( exp_frame_energy.s32Mantissa, 10, exp_frame_energy.s16Exp, 0, &q_divout ); + exp_frame_energy_amendment.s16Exp = q_divout; + t_bg_energy_sum = VAD_AddExp( t_bg_energy_sum, exp_frame_energy_amendment ); } ELSE { - t_bg_energy_sum = VAD_AddExp(t_bg_energy_sum,exp_frame_energy); + t_bg_energy_sum = VAD_AddExp( t_bg_energy_sum, exp_frame_energy ); } - update_sb_bg_energy(sb_bg_energy, &hVAD_CLDFB->tbg_energy_count, p_scale_sb_energy, SNR_sb_num, frame_sb_energy, hVAD_CLDFB->frame_sb_energy_scale, - 31456/* 0.96 Q15 */, 4, 20971/* 0.04 Q19 */); - + update_sb_bg_energy( sb_bg_energy, &hVAD_CLDFB->tbg_energy_count, p_scale_sb_energy, SNR_sb_num, frame_sb_energy, hVAD_CLDFB->frame_sb_energy_scale, + 31456 /* 0.96 Q15 */, 4, 20971 /* 0.04 Q19 */ ); } ELSE { - cmp_pre_frame = VAD_L_CMP(t_bg_energy, hVAD_CLDFB->scale_t_bg_energy, exp_frame_energy.s32Mantissa, exp_frame_energy.s16Exp); - IF(cmp_pre_frame>0) + cmp_pre_frame = VAD_L_CMP( t_bg_energy, hVAD_CLDFB->scale_t_bg_energy, exp_frame_energy.s32Mantissa, exp_frame_energy.s16Exp ); + IF( cmp_pre_frame > 0 ) { - IF( LT_16(hVAD_CLDFB->frameloop, 50) ) + IF( LT_16( hVAD_CLDFB->frameloop, 50 ) ) { - exp_frame_energy_amendment.s32Mantissa = VAD_L_div(exp_frame_energy.s32Mantissa, 10, exp_frame_energy.s16Exp, 0, &q_divout); + exp_frame_energy_amendment.s32Mantissa = VAD_L_div( exp_frame_energy.s32Mantissa, 10, exp_frame_energy.s16Exp, 0, &q_divout ); exp_frame_energy_amendment.s16Exp = q_divout; - t_bg_energy_sum = VAD_AddExp(t_bg_energy_sum,exp_frame_energy_amendment); + t_bg_energy_sum = VAD_AddExp( t_bg_energy_sum, exp_frame_energy_amendment ); } ELSE { - t_bg_energy_sum = VAD_AddExp(t_bg_energy_sum,exp_frame_energy); + t_bg_energy_sum = VAD_AddExp( t_bg_energy_sum, exp_frame_energy ); } - update_sb_bg_energy(sb_bg_energy, &hVAD_CLDFB->tbg_energy_count, p_scale_sb_energy, SNR_sb_num, frame_sb_energy, hVAD_CLDFB->frame_sb_energy_scale, - 31129/* 0.95 Q15 */, 4, 26214/* 0.05 Q19 */); - + update_sb_bg_energy( sb_bg_energy, &hVAD_CLDFB->tbg_energy_count, p_scale_sb_energy, SNR_sb_num, frame_sb_energy, hVAD_CLDFB->frame_sb_energy_scale, + 31129 /* 0.95 Q15 */, 4, 26214 /* 0.05 Q19 */ ); } ELSE { - IF( LT_16(hVAD_CLDFB->frameloop, 50) ) + IF( LT_16( hVAD_CLDFB->frameloop, 50 ) ) { - exp_frame_energy_amendment.s32Mantissa = VAD_L_div(exp_frame_energy.s32Mantissa, 10, exp_frame_energy.s16Exp, 0, &q_divout); + exp_frame_energy_amendment.s32Mantissa = VAD_L_div( exp_frame_energy.s32Mantissa, 10, exp_frame_energy.s16Exp, 0, &q_divout ); exp_frame_energy_amendment.s16Exp = q_divout; - t_bg_energy_sum = VAD_AddExp(t_bg_energy_sum,exp_frame_energy_amendment); + t_bg_energy_sum = VAD_AddExp( t_bg_energy_sum, exp_frame_energy_amendment ); } ELSE { - t_bg_energy_sum = VAD_AddExp(t_bg_energy_sum,exp_frame_energy); + t_bg_energy_sum = VAD_AddExp( t_bg_energy_sum, exp_frame_energy ); } - update_sb_bg_energy(sb_bg_energy, &hVAD_CLDFB->tbg_energy_count, p_scale_sb_energy, SNR_sb_num, frame_sb_energy, hVAD_CLDFB->frame_sb_energy_scale, - 31456/* 0.96 Q15 */, 4, 20971/* 0.04 Q19 */); - + update_sb_bg_energy( sb_bg_energy, &hVAD_CLDFB->tbg_energy_count, p_scale_sb_energy, SNR_sb_num, frame_sb_energy, hVAD_CLDFB->frame_sb_energy_scale, + 31456 /* 0.96 Q15 */, 4, 20971 /* 0.04 Q19 */ ); } } } } ELSE { - cmp_pre_frame = VAD_L_CMP(t_bg_energy, hVAD_CLDFB->scale_t_bg_energy, MUL_F(exp_frame_energy.s32Mantissa, 32000), sub(exp_frame_energy.s16Exp, 9)); - cmp_lt_frame = VAD_L_CMP(sb_bg_energy[0], scale_sb_energy, MUL_F(frame_sb_energy[0], 20480), sub(hVAD_CLDFB->frame_sb_energy_scale, 4)); + cmp_pre_frame = VAD_L_CMP( t_bg_energy, hVAD_CLDFB->scale_t_bg_energy, MUL_F( exp_frame_energy.s32Mantissa, 32000 ), sub( exp_frame_energy.s16Exp, 9 ) ); + cmp_lt_frame = VAD_L_CMP( sb_bg_energy[0], scale_sb_energy, MUL_F( frame_sb_energy[0], 20480 ), sub( hVAD_CLDFB->frame_sb_energy_scale, 4 ) ); test(); - IF( (cmp_pre_frame > 0) && (cmp_lt_frame > 0) ) + IF( ( cmp_pre_frame > 0 ) && ( cmp_lt_frame > 0 ) ) { - tmpQ = add(3, hVAD_CLDFB->frame_sb_energy_scale); - FOR(i=0; iframe_sb_energy_scale ); + FOR( i = 0; i < SNR_sb_num; i++ ) { - sb_bg_energy_ti = MUL_F(sb_bg_energy[i], 29490/* 0.90 Q15 */); - tmp = MUL_F(frame_sb_energy[i], 26214/* 0.10 Q18 */); - sb_bg_energy[i] = VAD_L_ADD(sb_bg_energy_ti, p_scale_sb_energy[i], tmp, tmpQ, &p_scale_sb_energy[i]); + sb_bg_energy_ti = MUL_F( sb_bg_energy[i], 29490 /* 0.90 Q15 */ ); + tmp = MUL_F( frame_sb_energy[i], 26214 /* 0.10 Q18 */ ); + sb_bg_energy[i] = VAD_L_ADD( sb_bg_energy_ti, p_scale_sb_energy[i], tmp, tmpQ, &p_scale_sb_energy[i] ); move32(); } } ELSE { - cmp_pre_frame = VAD_L_CMP(t_bg_energy, hVAD_CLDFB->scale_t_bg_energy, MUL_F(exp_frame_energy.s32Mantissa, 20480), sub(exp_frame_energy.s16Exp, 4)); + cmp_pre_frame = VAD_L_CMP( t_bg_energy, hVAD_CLDFB->scale_t_bg_energy, MUL_F( exp_frame_energy.s32Mantissa, 20480 ), sub( exp_frame_energy.s16Exp, 4 ) ); IF( cmp_pre_frame > 0 ) { - tmpQ = add(9, hVAD_CLDFB->frame_sb_energy_scale); - FOR(i=0; iframe_sb_energy_scale ); + FOR( i = 0; i < SNR_sb_num; i++ ) { - sb_bg_energy_ti = MUL_F(sb_bg_energy[i], 32734/* 0.999 Q15 */); - tmp = MUL_F(frame_sb_energy[i], 16777/* 0.001 Q24 */); - sb_bg_energy[i] = VAD_L_ADD(sb_bg_energy_ti, p_scale_sb_energy[i], tmp, tmpQ, &p_scale_sb_energy[i]); + sb_bg_energy_ti = MUL_F( sb_bg_energy[i], 32734 /* 0.999 Q15 */ ); + tmp = MUL_F( frame_sb_energy[i], 16777 /* 0.001 Q24 */ ); + sb_bg_energy[i] = VAD_L_ADD( sb_bg_energy_ti, p_scale_sb_energy[i], tmp, tmpQ, &p_scale_sb_energy[i] ); move32(); } } } } - tmp = L_mult0(160, (Word16)hVAD_CLDFB->tbg_energy_count); - cmp_pre_frame = VAD_L_CMP(t_bg_energy_sum.s32Mantissa, t_bg_energy_sum.s16Exp, tmp, 0); - IF(cmp_pre_frame > 0) + tmp = L_mult0( 160, (Word16) hVAD_CLDFB->tbg_energy_count ); + cmp_pre_frame = VAD_L_CMP( t_bg_energy_sum.s32Mantissa, t_bg_energy_sum.s16Exp, tmp, 0 ); + IF( cmp_pre_frame > 0 ) { - i = norm_l(tmp); - t_bg_energy_sum.s32Mantissa = L_shl(tmp, i); + i = norm_l( tmp ); + t_bg_energy_sum.s32Mantissa = L_shl( tmp, i ); t_bg_energy_sum.s16Exp = i; move16(); } - NormEnergyWord32(sb_bg_energy, SNR_sb_num, p_scale_sb_energy, &scale_sb_energy); - cmp_pre_frame = VAD_L_CMP(t_bg_energy, hVAD_CLDFB->scale_t_bg_energy, 1, 0); + NormEnergyWord32( sb_bg_energy, SNR_sb_num, p_scale_sb_energy, &scale_sb_energy ); + cmp_pre_frame = VAD_L_CMP( t_bg_energy, hVAD_CLDFB->scale_t_bg_energy, 1, 0 ); test(); test(); test(); - IF( (EQ_16(music_backgound_f, 1))&&(LT_32(hVAD_CLDFB->lt_snr_org,107374179/* 3.2 Q25 */)) - && (cmp_pre_frame > 0) && update_flag == 0) + IF( ( EQ_16( music_backgound_f, 1 ) ) && ( LT_32( hVAD_CLDFB->lt_snr_org, 107374179 /* 3.2 Q25 */ ) ) && ( cmp_pre_frame > 0 ) && update_flag == 0 ) { - tmp = L_shr(2147/* 0.000001 Q31 */, sub(31, scale_sb_energy)); - FOR(i=0; iscale_t_bg_energy, 15)); - IF(cmp_pre_frame < 0) + cmp_pre_frame = VAD_L_CMP( exp_frame_energy.s32Mantissa, exp_frame_energy.s16Exp, MUL_F( t_bg_energy, 5000 ), sub( hVAD_CLDFB->scale_t_bg_energy, 15 ) ); + IF( cmp_pre_frame < 0 ) { - tmp = L_shr(2147/* 0.000001 Q31 */, sub(31, scale_sb_energy)); - FOR(i=0; itbg_energy_count, 64))) + IF( ( EQ_32( hVAD_CLDFB->tbg_energy_count, 64 ) ) ) { hVAD_CLDFB->tbg_energy_count = 48; move16(); - t_bg_energy_sum.s32Mantissa = MUL_F(t_bg_energy_sum.s32Mantissa, 24575/* 0.75 Q15 */); + t_bg_energy_sum.s32Mantissa = MUL_F( t_bg_energy_sum.s32Mantissa, 24575 /* 0.75 Q15 */ ); } - t_bg_energy = VAD_L_div(t_bg_energy_sum.s32Mantissa, hVAD_CLDFB->tbg_energy_count, t_bg_energy_sum.s16Exp, 0, &q_divout); + t_bg_energy = VAD_L_div( t_bg_energy_sum.s32Mantissa, hVAD_CLDFB->tbg_energy_count, t_bg_energy_sum.s16Exp, 0, &q_divout ); hVAD_CLDFB->scale_t_bg_energy = q_divout; move16(); hVAD_CLDFB->t_bg_energy = t_bg_energy; @@ -489,4 +481,3 @@ void background_update_fx( return; } - diff --git a/lib_enc/eval_pit_contr_fx.c b/lib_enc/eval_pit_contr_fx.c index c73e9fccb..308f3ec4e 100644 --- a/lib_enc/eval_pit_contr_fx.c +++ b/lib_enc/eval_pit_contr_fx.c @@ -2,28 +2,28 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ +#include "options.h" /* Compilation switches */ #include "cnst.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ +#include "rom_com_fx.h" /* Static table prototypes */ #include "rom_com.h" /* Static table prototypes */ //#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* * Local constantes *-------------------------------------------------------------------*/ -#define NB_VOIC_FX 13 -#define DIV_NB_VOIC_FX 2521 +#define NB_VOIC_FX 13 +#define DIV_NB_VOIC_FX 2521 -#define ALPA_FX 31130 -#define ALPAM1_FX (32768-ALPA_FX) +#define ALPA_FX 31130 +#define ALPAM1_FX ( 32768 - ALPA_FX ) -#define BETA_FX 819 -#define AFREQ_THR 2 +#define BETA_FX 819 +#define AFREQ_THR 2 -#define HANGOVER_DELAY 2 +#define HANGOVER_DELAY 2 /*======================================================================*/ /* FUNCTION : Pit_exc_contribution_len_fx() */ @@ -50,19 +50,18 @@ /* _ None */ /*=======================================================================*/ -Word16 Pit_exc_contribution_len_fx( /* o : bin where pitch contribution is significant */ - Encoder_State *st_fx, /* i/o: state structure */ - const Word16 *dct_res, /* i : DCT of residual */ - Word16 *dct_pitex, /* i/o: DCT of pitch contribution */ - Word16 *pitch_buf, /* i/o: Pitch per subframe */ - const Word16 nb_subfr, /* i : Number of subframe considered */ - Word16 *hangover, /* i : hangover for the time contribution switching */ - Word16 Qnew -) +Word16 Pit_exc_contribution_len_fx( /* o : bin where pitch contribution is significant */ + Encoder_State *st_fx, /* i/o: state structure */ + const Word16 *dct_res, /* i : DCT of residual */ + Word16 *dct_pitex, /* i/o: DCT of pitch contribution */ + Word16 *pitch_buf, /* i/o: Pitch per subframe */ + const Word16 nb_subfr, /* i : Number of subframe considered */ + Word16 *hangover, /* i : hangover for the time contribution switching */ + Word16 Qnew ) { Word16 corr_dct_pit[MBANDS_LOC]; - Word32 corr_tmp,L_tmp; + Word32 corr_tmp, L_tmp; Word16 av_corr, min_corr, ftmp, tmp_ex, tmp_res; Word16 freq, i, j; Word16 last_pit_band, pit_contr_idx, last_pit_bin; @@ -73,8 +72,8 @@ Word16 Pit_exc_contribution_len_fx( /* o : bin where pitch contribution is sign Word16 time_flg = 0; Word16 Len, max_len; Word16 tmp_dec; - Word16 Mbands_loc = MBANDS_LOC-2; - Word16 exp1,tmp,exp2; + Word16 Mbands_loc = MBANDS_LOC - 2; + Word16 exp1, tmp, exp2; Word32 L_tmp1, ener_init; Word16 exp_norm; Word16 norm; @@ -83,113 +82,115 @@ Word16 Pit_exc_contribution_len_fx( /* o : bin where pitch contribution is sign BSTR_ENC_HANDLE hBstr = st_fx->hBstr; GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc; - if( EQ_16(st_fx->L_frame,L_FRAME16k)) + if ( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { Mbands_loc = MBANDS_LOC; move16(); } - minimum_fx( pitch_buf, nb_subfr, &low_pit); - exp1 = norm_s(low_pit); - tmp = shl(low_pit,exp1); - tmp_dec = 12800; move16(); - if (EQ_16(st_fx->L_frame, L_FRAME16k)) + minimum_fx( pitch_buf, nb_subfr, &low_pit ); + exp1 = norm_s( low_pit ); + tmp = shl( low_pit, exp1 ); + tmp_dec = 12800; + move16(); + if ( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { - tmp_dec = 16000; move16(); + tmp_dec = 16000; + move16(); } /*F1st_harm = (12800.0f|160000.f)/low_pit;*/ - tmp = div_s(tmp_dec,tmp); /*15-6-exp1(->9-exp1)*/ - F1st_harm = shr_r(tmp,sub(5,exp1)); /*Q4*/ + tmp = div_s( tmp_dec, tmp ); /*15-6-exp1(->9-exp1)*/ + F1st_harm = shr_r( tmp, sub( 5, exp1 ) ); /*Q4*/ /*F8th_harm = 8.0f*F1st_harm;*/ - F8th_harm = extract_l(L_shr_r(L_mult0(F1st_harm,8),2)); /*Q2*/ + F8th_harm = extract_l( L_shr_r( L_mult0( F1st_harm, 8 ), 2 ) ); /*Q2*/ freq = 0; move16(); - ener_init = L_shl(3,2*Qnew-5); /*(0.1->3 in Q5) 2*Qnew*/ - FOR (i = 0; i 3 in Q5) 2*Qnew*/ + FOR( i = 0; i < Mbands_loc; i++ ) /* up to maximum allowed voiced critical band */ { - corr_tmp = L_deposit_l(0); - ener_res = L_add(ener_init, 0); - ener_pit = L_add(ener_init, 0); + corr_tmp = L_deposit_l( 0 ); + ener_res = L_add( ener_init, 0 ); + ener_pit = L_add( ener_init, 0 ); - FOR (j = 0; j < mfreq_bindiv_loc[i]; j++) /* up to maximum allowed voiced critical band */ + FOR( j = 0; j < mfreq_bindiv_loc[i]; j++ ) /* up to maximum allowed voiced critical band */ { - tmp_ex = mult_r(dct_pitex[j+freq],8192); - tmp_res = mult_r(dct_res[j+freq],8192); - corr_tmp = L_mac0(corr_tmp,tmp_res,tmp_ex); /*2*Qnew*/ - ener_res = L_mac0(ener_res,tmp_res,tmp_res); /*2*Qnew*/ - ener_pit = L_mac0(ener_pit,tmp_ex,tmp_ex); /*2*Qnew*/ + tmp_ex = mult_r( dct_pitex[j + freq], 8192 ); + tmp_res = mult_r( dct_res[j + freq], 8192 ); + corr_tmp = L_mac0( corr_tmp, tmp_res, tmp_ex ); /*2*Qnew*/ + ener_res = L_mac0( ener_res, tmp_res, tmp_res ); /*2*Qnew*/ + ener_pit = L_mac0( ener_pit, tmp_ex, tmp_ex ); /*2*Qnew*/ } - L_tmp1 = Mult_32_32(ener_res,ener_pit); - exp2 = norm_l(L_tmp1); - L_tmp1 = L_shl(L_tmp1, exp2); - exp_norm = sub(30, exp2); - L_tmp1 = Isqrt_lc(L_tmp1, &exp_norm); - norm = extract_h(L_tmp1); /*15-exp_norm*/ - L_tmp1 = L_shl(Mult_32_16(corr_tmp,norm),exp_norm); - corr_dct_pit[i] = round_fx(L_shl(L_tmp1,14)); /*Q14*/ + L_tmp1 = Mult_32_32( ener_res, ener_pit ); + exp2 = norm_l( L_tmp1 ); + L_tmp1 = L_shl( L_tmp1, exp2 ); + exp_norm = sub( 30, exp2 ); + L_tmp1 = Isqrt_lc( L_tmp1, &exp_norm ); + norm = extract_h( L_tmp1 ); /*15-exp_norm*/ + L_tmp1 = L_shl( Mult_32_16( corr_tmp, norm ), exp_norm ); + corr_dct_pit[i] = round_fx( L_shl( L_tmp1, 14 ) ); /*Q14*/ - freq = add(freq,mfreq_bindiv_loc[i]); + freq = add( freq, mfreq_bindiv_loc[i] ); } val_thrs = 8192; move16(); /* 0.5 in Q14*/ /* Smooth the inter-correlation value and skip the last band for the average (since last band is almost always 0)*/ - tmp = mac_r(L_mult(ALPA_FX,corr_dct_pit[0]),ALPAM1_FX,corr_dct_pit[1]);/*Qnew*/ - tmp = s_max(tmp , val_thrs); + tmp = mac_r( L_mult( ALPA_FX, corr_dct_pit[0] ), ALPAM1_FX, corr_dct_pit[1] ); /*Qnew*/ + tmp = s_max( tmp, val_thrs ); - corr_dct_pit_tmp[0] = shl(sub(tmp,val_thrs),1); + corr_dct_pit_tmp[0] = shl( sub( tmp, val_thrs ), 1 ); move16(); - FOR (i = 1; i L_frame, L_FRAME16k)) + if ( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { /*av_corr *= 1.25f;*/ - av_corr = add(av_corr, shr(av_corr, 2)); + av_corr = add( av_corr, shr( av_corr, 2 ) ); } test(); - if (GE_16(st_fx->GSC_IVAS_mode, 1)|| LT_32(st_fx->core_brate, ACELP_9k60)) + if ( GE_16( st_fx->GSC_IVAS_mode, 1 ) || LT_32( st_fx->core_brate, ACELP_9k60 ) ) { - av_corr = shl(av_corr,1); /*Q2 Correlation really poor at low rate, time domain still valide*/ + av_corr = shl( av_corr, 1 ); /*Q2 Correlation really poor at low rate, time domain still valide*/ } - min_corr = abs_s(sub(mfreq_loc_Q2fx[0],av_corr)); /*Q2*/ + min_corr = abs_s( sub( mfreq_loc_Q2fx[0], av_corr ) ); /*Q2*/ - FOR (i = 1; i GSC_IVAS_mode, 1)) + if ( GE_16( st_fx->GSC_IVAS_mode, 1 ) ) { - last_pit_band = s_max(last_pit_band, 7); + last_pit_band = s_max( last_pit_band, 7 ); } test(); test(); test(); - IF( GT_16(last_pit_band,7+BAND1k2)&&(LT_32(st_fx->core_brate,CFREQ_BITRATE)||EQ_16(st_fx->bwidth,NB)))/*Added for 9.1*/ + IF( GT_16( last_pit_band, 7 + BAND1k2 ) && ( LT_32( st_fx->core_brate, CFREQ_BITRATE ) || EQ_16( st_fx->bwidth, NB ) ) ) /*Added for 9.1*/ { - last_pit_band = 7+BAND1k2; + last_pit_band = 7 + BAND1k2; move16(); } - ELSE IF ( GT_16(last_pit_band,10+BAND1k2)&&GE_32(st_fx->core_brate,CFREQ_BITRATE)) + ELSE IF( GT_16( last_pit_band, 10 + BAND1k2 ) && GE_32( st_fx->core_brate, CFREQ_BITRATE ) ) { - last_pit_band = add(10,BAND1k2); + last_pit_band = add( 10, BAND1k2 ); } time_flg = 0; @@ -235,11 +236,7 @@ Word16 Pit_exc_contribution_len_fx( /* o : bin where pitch contribution is sign test(); test(); test(); - IF( (hGSCEnc->mem_last_pit_band > 0 && GT_16(st_fx->old_corr_fx,16384)&>_16(hSpMusClas->mold_corr_fx,16384)&&GE_16(hGSCEnc->lt_gpitch_fx,19661)/*1.5f*GPIT_THR*/) - || (GT_16(last_pit_band,6) ) - || (GE_16(last_pit_band,4) && GE_16(hGSCEnc->lt_gpitch_fx,19661) /*1.5f*GPIT_THR*/ && GT_16(st_fx->old_corr_fx,22938) ) - || (GT_16(last_pit_band,BAND1k2) && GT_16(hSpMusClas->mold_corr_fx,26214) && GE_16(hGSCEnc->lt_gpitch_fx,13107) /*GPIT_THR*/) - ) + IF( ( hGSCEnc->mem_last_pit_band > 0 && GT_16( st_fx->old_corr_fx, 16384 ) && GT_16( hSpMusClas->mold_corr_fx, 16384 ) && GE_16( hGSCEnc->lt_gpitch_fx, 19661 ) /*1.5f*GPIT_THR*/ ) || ( GT_16( last_pit_band, 6 ) ) || ( GE_16( last_pit_band, 4 ) && GE_16( hGSCEnc->lt_gpitch_fx, 19661 ) /*1.5f*GPIT_THR*/ && GT_16( st_fx->old_corr_fx, 22938 ) ) || ( GT_16( last_pit_band, BAND1k2 ) && GT_16( hSpMusClas->mold_corr_fx, 26214 ) && GE_16( hGSCEnc->lt_gpitch_fx, 13107 ) /*GPIT_THR*/ ) ) { tmp_dec = 1; move16(); @@ -254,7 +251,7 @@ Word16 Pit_exc_contribution_len_fx( /* o : bin where pitch contribution is sign test(); test(); test(); - IF ( (hGSCEnc->mem_last_pit_band == 0 && EQ_16(tmp_dec,1))||(hGSCEnc->mem_last_pit_band>0&&tmp_dec==0)) + IF( ( hGSCEnc->mem_last_pit_band == 0 && EQ_16( tmp_dec, 1 ) ) || ( hGSCEnc->mem_last_pit_band > 0 && tmp_dec == 0 ) ) { IF( *hangover == 0 ) { @@ -267,14 +264,14 @@ Word16 Pit_exc_contribution_len_fx( /* o : bin where pitch contribution is sign { time_flg = 0; move16(); - if(hGSCEnc->mem_last_pit_band > 0 ) + if ( hGSCEnc->mem_last_pit_band > 0 ) { time_flg = 1; move16(); } - (*hangover) = sub((*hangover),1); - if( *hangover < 0 ) + ( *hangover ) = sub( ( *hangover ), 1 ); + if ( *hangover < 0 ) { *hangover = 0; move16(); @@ -294,30 +291,30 @@ Word16 Pit_exc_contribution_len_fx( /* o : bin where pitch contribution is sign move16(); test(); test(); - IF( EQ_16(time_flg,1) || NE_16(st_fx->coder_type,INACTIVE) || st_fx->GSC_noisy_speech) + IF( EQ_16( time_flg, 1 ) || NE_16( st_fx->coder_type, INACTIVE ) || st_fx->GSC_noisy_speech ) { test(); test(); /*if(st_fx->core_brate core_brate,ACELP_9k60) && LT_16(low_pit,4096)) + IF( LT_32( st_fx->core_brate, ACELP_9k60 ) && LT_16( low_pit, 4096 ) ) { - last_pit_band = add(9 , BAND1k2); - if(EQ_16(st_fx->bwidth,NB)) + last_pit_band = add( 9, BAND1k2 ); + if ( EQ_16( st_fx->bwidth, NB ) ) { - last_pit_band = add(7,BAND1k2); + last_pit_band = add( 7, BAND1k2 ); } } - ELSE IF(LT_32(st_fx->core_brate,ACELP_9k60) && LT_16(low_pit,8192)) + ELSE IF( LT_32( st_fx->core_brate, ACELP_9k60 ) && LT_16( low_pit, 8192 ) ) { - last_pit_band = add(5 , BAND1k2); + last_pit_band = add( 5, BAND1k2 ); } - ELSE IF(LT_32(st_fx->core_brate,ACELP_9k60)) + ELSE IF( LT_32( st_fx->core_brate, ACELP_9k60 ) ) { - last_pit_band = add(3 , BAND1k2); + last_pit_band = add( 3, BAND1k2 ); } - ELSE IF( LT_16(last_pit_band,add(BAND1k2,1))) + ELSE IF( LT_16( last_pit_band, add( BAND1k2, 1 ) ) ) { - last_pit_band = add(BAND1k2,1); + last_pit_band = add( BAND1k2, 1 ); } last_pit_bin = mfreq_loc_div_25[last_pit_band]; move16(); @@ -325,50 +322,50 @@ Word16 Pit_exc_contribution_len_fx( /* o : bin where pitch contribution is sign st_fx->bpf_off = 0; move16(); - max_len = sub(st_fx->L_frame,last_pit_bin); + max_len = sub( st_fx->L_frame, last_pit_bin ); - if( EQ_16(st_fx->bwidth,NB)) + if ( EQ_16( st_fx->bwidth, NB ) ) { - max_len = sub(160,last_pit_bin); + max_len = sub( 160, last_pit_bin ); } Len = 80; move16(); - if(LT_16(max_len,80)) + if ( LT_16( max_len, 80 ) ) { Len = max_len; move16(); } test(); - IF((EQ_32(st_fx->core_brate,ACELP_8k00)) && (NE_16(st_fx->bwidth,NB))) + IF( ( EQ_32( st_fx->core_brate, ACELP_8k00 ) ) && ( NE_16( st_fx->bwidth, NB ) ) ) { - move16(); /*ptr init*/ - FOR (i=0; i < max_len; i++) + move16(); /*ptr init*/ + FOR( i = 0; i < max_len; i++ ) { - dct_pitex[i+last_pit_bin] = 0; + dct_pitex[i + last_pit_bin] = 0; move16(); } } ELSE { - FOR (i = 0; i < Len; i++) + FOR( i = 0; i < Len; i++ ) { - dct_pitex[i+last_pit_bin] = mult_r(dct_pitex[i+last_pit_bin],sm_table_fx[i]); + dct_pitex[i + last_pit_bin] = mult_r( dct_pitex[i + last_pit_bin], sm_table_fx[i] ); } - FOR (; i < max_len; i++) + FOR( ; i < max_len; i++ ) { - dct_pitex[i+last_pit_bin] = 0; + dct_pitex[i + last_pit_bin] = 0; move16(); } } hGSCEnc->mem_last_pit_band = last_pit_band; move16(); - pit_contr_idx = sub(last_pit_band,BAND1k2); + pit_contr_idx = sub( last_pit_band, BAND1k2 ); } ELSE { - set16_fx(dct_pitex, 0, st_fx->L_frame); + set16_fx( dct_pitex, 0, st_fx->L_frame ); st_fx->bpf_off = 1; move16(); last_pit_bin = 0; @@ -380,58 +377,57 @@ Word16 Pit_exc_contribution_len_fx( /* o : bin where pitch contribution is sign hGSCEnc->mem_last_pit_band = 0; move16(); - set16_fx( pitch_buf, shl(L_SUBFR,6), NB_SUBFR16k ); + set16_fx( pitch_buf, shl( L_SUBFR, 6 ), NB_SUBFR16k ); /* pitch contribution useless - delete all previously written indices belonging to pitch contribution */ - FOR ( i = TAG_ACELP_SUBFR_LOOP_START; i < TAG_ACELP_SUBFR_LOOP_END; i++ ) + FOR( i = TAG_ACELP_SUBFR_LOOP_START; i < TAG_ACELP_SUBFR_LOOP_END; i++ ) { #ifndef IVAS_CODE_BITSTREAM - IF (hBstr->ind_list_fx[i].nb_bits != -1 ) + IF( hBstr->ind_list_fx[i].nb_bits != -1 ) { - hBstr->nb_bits_tot_fx = sub(hBstr->nb_bits_tot_fx, hBstr->ind_list_fx[i].nb_bits); + hBstr->nb_bits_tot_fx = sub( hBstr->nb_bits_tot_fx, hBstr->ind_list_fx[i].nb_bits ); hBstr->ind_list_fx[i].nb_bits = -1; move16(); } #else - delete_indice(hBstr, i); + delete_indice( hBstr, i ); #endif } #ifndef IVAS_CODE_BITSTREAM - IF (hBstr->ind_list_fx[IND_ES_PRED].nb_bits != -1 ) + IF( hBstr->ind_list_fx[IND_ES_PRED].nb_bits != -1 ) { - hBstr->nb_bits_tot_fx = sub(hBstr->nb_bits_tot_fx, hBstr->ind_list_fx[IND_ES_PRED].nb_bits); + hBstr->nb_bits_tot_fx = sub( hBstr->nb_bits_tot_fx, hBstr->ind_list_fx[IND_ES_PRED].nb_bits ); hBstr->ind_list_fx[IND_ES_PRED].nb_bits = -1; move16(); } #else - delete_indice(hBstr, i); + delete_indice( hBstr, i ); #endif } - IF( LT_32(st_fx->core_brate,CFREQ_BITRATE)) + IF( LT_32( st_fx->core_brate, CFREQ_BITRATE ) ) { - IF(LT_32(st_fx->core_brate,ACELP_9k60)) + IF( LT_32( st_fx->core_brate, ACELP_9k60 ) ) { - if(pit_contr_idx>0) + if ( pit_contr_idx > 0 ) { - pit_contr_idx=1; + pit_contr_idx = 1; move16(); } - IF( EQ_16(st_fx->coder_type,INACTIVE)) + IF( EQ_16( st_fx->coder_type, INACTIVE ) ) { - push_indice_fx(hBstr, IND_PIT_CONTR_IDX, pit_contr_idx, 1 ); + push_indice_fx( hBstr, IND_PIT_CONTR_IDX, pit_contr_idx, 1 ); } } ELSE { - push_indice_fx(hBstr, IND_PIT_CONTR_IDX, pit_contr_idx, 3 ); + push_indice_fx( hBstr, IND_PIT_CONTR_IDX, pit_contr_idx, 3 ); } } ELSE { - push_indice_fx(hBstr, IND_PIT_CONTR_IDX, pit_contr_idx, 4 ); + push_indice_fx( hBstr, IND_PIT_CONTR_IDX, pit_contr_idx, 4 ); } return last_pit_bin; - } diff --git a/lib_enc/evs_enc.c b/lib_enc/evs_enc.c index 5a14111f1..dadacb408 100644 --- a/lib_enc/evs_enc.c +++ b/lib_enc/evs_enc.c @@ -95,7 +95,7 @@ ivas_error evs_enc( int16_t padBits; float realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* real buffer */ float imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* imag buffer */ - int16_t pitch_orig[3]; /* original open-loop pitch values that might be altered in core_acelp_tcx20_switching() within MODE2 */ + int16_t pitch_orig[3]; /* original open-loop pitch values that might be altered in core_acelp_tcx20_switching() within MODE2 */ ivas_error error; error = IVAS_ERR_OK; diff --git a/lib_enc/evs_enc_fx.c b/lib_enc/evs_enc_fx.c index 922c70501..53b52d3dc 100644 --- a/lib_enc/evs_enc_fx.c +++ b/lib_enc/evs_enc_fx.c @@ -3,13 +3,13 @@ ====================================================================================*/ #include #include -#include "options.h" /* Compilation switches */ +#include "options.h" /* Compilation switches */ #include "prot.h" -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "basop_util.h" /* Function prototypes */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Common constants */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "basop_util.h" /* Function prototypes */ #include "prot_fx_enc.h" /*-------------------------------------------------------------------* @@ -17,8 +17,8 @@ *-------------------------------------------------------------------*/ static void initFrameHeader_loc( Encoder_State *st ); -static void writeFrameHeader_loc(Encoder_State *st ); -static void configure_core_coder_loc(Encoder_State *st ); +static void writeFrameHeader_loc( Encoder_State *st ); +static void configure_core_coder_loc( Encoder_State *st ); /*-------------------------------------------------------------------* * evs_enc() @@ -27,35 +27,35 @@ static void configure_core_coder_loc(Encoder_State *st ); *-------------------------------------------------------------------*/ ivas_error evs_enc_fx( - Encoder_State *st, /* i/o: encoder state structure */ - const Word16 *data, /* i : input signal */ - Word32 * mem_hp20_in_fx, /* i/o: hp20 filter memory */ - const Word16 n_samples /* i : number of input samples */ + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 *data, /* i : input signal */ + Word32 *mem_hp20_in_fx, /* i/o: hp20 filter memory */ + const Word16 n_samples /* i : number of input samples */ ) { Word16 i, input_frame, delay; - Word16 old_inp_12k8[L_INP_12k8], *inp = 0; /* buffer of input signal @ 12k8 */ - Word16 old_inp_16k[L_INP]; /* buffer of input signal @ 16kHz */ - Word32 fr_bands[2*NB_BANDS]; /* energy in frequency bands */ - Word16 Etot; /* total energy; correlation shift */ - Word32 ener; /* residual energy from Levinson-Durbin */ - Word16 A[NB_SUBFR16k*(M+1)]; /* A(z) unquantized for subframes */ - Word16 Aw[NB_SUBFR16k*(M+1)]; /* weighted A(z) unquantized for subframes */ - Word16 epsP_h[M+1]; /* LP prediction errors */ - Word16 epsP_l[M+1]; /* LP prediction errors */ - Word32 epsP[M+1]; /* LP prediction errors */ - Word16 lsp_new[M]; /* LSPs at the end of the frame */ - Word16 lsp_mid[M]; /* ISPs in the middle of the frame */ + Word16 old_inp_12k8[L_INP_12k8], *inp = 0; /* buffer of input signal @ 12k8 */ + Word16 old_inp_16k[L_INP]; /* buffer of input signal @ 16kHz */ + Word32 fr_bands[2 * NB_BANDS]; /* energy in frequency bands */ + Word16 Etot; /* total energy; correlation shift */ + Word32 ener; /* residual energy from Levinson-Durbin */ + Word16 A[NB_SUBFR16k * ( M + 1 )]; /* A(z) unquantized for subframes */ + Word16 Aw[NB_SUBFR16k * ( M + 1 )]; /* weighted A(z) unquantized for subframes */ + Word16 epsP_h[M + 1]; /* LP prediction errors */ + Word16 epsP_l[M + 1]; /* LP prediction errors */ + Word32 epsP[M + 1]; /* LP prediction errors */ + Word16 lsp_new[M]; /* LSPs at the end of the frame */ + Word16 lsp_mid[M]; /* ISPs in the middle of the frame */ Word16 vad_hover_flag; - Word16 hq_core_type; /* HQ core type (HQ, or LR-MDCT) */ + Word16 hq_core_type; /* HQ core type (HQ, or LR-MDCT) */ - Word16 attack_flag; /* attack flag (GSC or TC) */ - Word16 new_inp_resamp16k[L_FRAME16k]; /* new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ - Word16 old_syn_12k8_16k[L_FRAME16k]; /* ACELP core synthesis at 12.8kHz or 16kHz to be used by the SWB BWE */ + Word16 attack_flag; /* attack flag (GSC or TC) */ + Word16 new_inp_resamp16k[L_FRAME16k]; /* new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ + Word16 old_syn_12k8_16k[L_FRAME16k]; /* ACELP core synthesis at 12.8kHz or 16kHz to be used by the SWB BWE */ Word16 shb_speech[L_FRAME16k]; - Word16 hb_speech[L_FRAME16k/4]; + Word16 hb_speech[L_FRAME16k / 4]; Word16 new_swb_speech[L_FRAME48k]; - Word32 bwe_exc_extended[L_FRAME32k + NL_BUFF_OFFSET]; /* non-linear bandwidth extension buffer */ + Word32 bwe_exc_extended[L_FRAME32k + NL_BUFF_OFFSET]; /* non-linear bandwidth extension buffer */ Word16 voice_factors[NB_SUBFR16k]; Word16 fb_exc[L_FRAME16k]; Word16 Voicing_flag; @@ -77,10 +77,10 @@ ivas_error evs_enc_fx( #endif ivas_error error; SC_VBR_ENC_HANDLE hSC_VBR = st->hSC_VBR; - //NOISE_EST_HANDLE hNoiseEst = st->hNoiseEst; - //VAD_HANDLE hVAD = st->hVAD; - //DTX_ENC_HANDLE hDtxEnc = st->hDtxEnc; - TD_CNG_ENC_HANDLE hTdCngEnc = st->hTdCngEnc; + // NOISE_EST_HANDLE hNoiseEst = st->hNoiseEst; + // VAD_HANDLE hVAD = st->hVAD; + // DTX_ENC_HANDLE hDtxEnc = st->hDtxEnc; + TD_CNG_ENC_HANDLE hTdCngEnc = st->hTdCngEnc; LPD_state_HANDLE hLPDmem = st->hLPDmem; TD_BWE_ENC_HANDLE hBWE_TD = st->hBWE_TD; BSTR_ENC_HANDLE hBstr = st->hBstr; @@ -90,9 +90,7 @@ ivas_error evs_enc_fx( Q_shb_spch = 0; - move16(); /* to avoid compiler warnings */ - - + move16(); /* to avoid compiler warnings */ /*------------------------------------------------------------------* @@ -131,7 +129,7 @@ ivas_error evs_enc_fx( st->idchan = 0; move16(); - st->flag_ACELP16k = set_ACELP_flag(EVS_MONO, -1, st->total_brate, 0, 0, -1, -1); + st->flag_ACELP16k = set_ACELP_flag( EVS_MONO, -1, st->total_brate, 0, 0, -1, -1 ); move16(); @@ -140,18 +138,18 @@ ivas_error evs_enc_fx( *----------------------------------------------------------------*/ /* get delay to synchronize ACELP and MDCT frame */ - delay = NS2SA_fx2(st->input_Fs, DELAY_FIR_RESAMPL_NS); + delay = NS2SA_fx2( st->input_Fs, DELAY_FIR_RESAMPL_NS ); - Copy( st->input_fx - delay, st->old_input_signal_fx, input_frame+delay ); + Copy( st->input_fx - delay, st->old_input_signal_fx, input_frame + delay ); /*----------------------------------------------------------------* * convert 'short' input data to 'float' *----------------------------------------------------------------*/ - Copy(data, st->input_fx, input_frame); - IF( LT_16(n_samples,input_frame)) + Copy( data, st->input_fx, input_frame ); + IF( LT_16( n_samples, input_frame ) ) { - set16_fx( st->input_fx + n_samples, 0, sub(input_frame, n_samples) ); + set16_fx( st->input_fx + n_samples, 0, sub( input_frame, n_samples ) ); } /*----------------------------------------------------------------* @@ -164,20 +162,20 @@ ivas_error evs_enc_fx( * Updates in case of AMR-WB IO mode -> EVS primary mode switching *----------------------------------------------------------------*/ - IF( EQ_16(st->last_core, AMR_WB_CORE)) + IF( EQ_16( st->last_core, AMR_WB_CORE ) ) { updt_IO_switch_enc_fx( st, input_frame ); - set16_fx(hBWE_TD->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k); -#if defined IVAS_CODE -PMT("find scaling factor for prev_enr_EnvSHBres, prev_pow_exc16kWhtnd and prev_mix_factor ") - set16_fx(st->hBWE_TD->old_speech_shb, 0, L_LOOK_16k + L_SUBFR16k); - set16_fx(st->hBWE_TD->mem_shb_res, 0, MAX_LEN_MA_FILTER); - set16_fx(st->hBWE_TD->old_EnvSHBres, 0, L_FRAME4k); + set16_fx( hBWE_TD->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k ); +#if defined IVAS_CODE + PMT( "find scaling factor for prev_enr_EnvSHBres, prev_pow_exc16kWhtnd and prev_mix_factor " ) + set16_fx( st->hBWE_TD->old_speech_shb, 0, L_LOOK_16k + L_SUBFR16k ); + set16_fx( st->hBWE_TD->mem_shb_res, 0, MAX_LEN_MA_FILTER ); + set16_fx( st->hBWE_TD->old_EnvSHBres, 0, L_FRAME4k ); st->hBWE_TD->old_mean_EnvSHBres = 0; st->hBWE_TD->prev_enr_EnvSHBres = 1.0f; st->hBWE_TD->prev_shb_env_tilt = 0; st->hBWE_TD->prev_pow_exc16kWhtnd = 1.0f; - st->hBWE_TD->prev_mix_factor = 1.0f; + st->hBWE_TD->prev_mix_factor = 1.0f; st->hBWE_TD->prev_Env_error = 0; #endif cldfb_reset_memory( st->cldfbAnaEnc ); @@ -188,20 +186,20 @@ PMT("find scaling factor for prev_enr_EnvSHBres, prev_pow_exc16kWhtnd and prev_m * Pre-processing *---------------------------------------------------------------------*/ #ifdef FIX_I4_OL_PITCH - pre_proc(st, input_frame, old_inp_12k8, old_inp_16k, &inp, fr_bands, &Etot, &ener, A, Aw, epsP, lsp_new, lsp_mid, &vad_hover_flag, &attack_flag, new_inp_resamp16k, &Voicing_flag, realBuffer, imagBuffer, &hq_core_type); + pre_proc( st, input_frame, old_inp_12k8, old_inp_16k, &inp, fr_bands, &Etot, &ener, A, Aw, epsP, lsp_new, lsp_mid, &vad_hover_flag, &attack_flag, new_inp_resamp16k, &Voicing_flag, realBuffer, imagBuffer, &hq_core_type ); #else - pre_proc_fx( st, input_frame, old_inp_12k8, old_inp_16k, &inp, fr_bands, &Etot, &ener, - pitch_orig, A, Aw, epsP_h, epsP_l, epsP, lsp_new, lsp_mid, &vad_hover_flag, + pre_proc_fx( st, input_frame, old_inp_12k8, old_inp_16k, &inp, fr_bands, &Etot, &ener, + pitch_orig, A, Aw, epsP_h, epsP_l, epsP, lsp_new, lsp_mid, &vad_hover_flag, &attack_flag, new_inp_resamp16k, &Voicing_flag, realBuffer, imagBuffer, &cldfbScale, hLPDmem->old_exc, &hq_core_type, &Q_new, &shift, Q_r ); #endif - //st->sharpFlag = sharpFlag; + // st->sharpFlag = sharpFlag; - IF (EQ_16(st->mdct_sw,MODE2)) + IF( EQ_16( st->mdct_sw, MODE2 ) ) { - Mpy_32_16_ss(st->total_brate, 5243, &L_tmp, &lsb); /* 5243 is 1/50 in Q18. (0+18-15=3) */ - st->bits_frame_nominal = extract_l(L_shr(L_tmp, 3)); /* Q0 */ + Mpy_32_16_ss( st->total_brate, 5243, &L_tmp, &lsb ); /* 5243 is 1/50 in Q18. (0+18-15=3) */ + st->bits_frame_nominal = extract_l( L_shr( L_tmp, 3 ) ); /* Q0 */ initFrameHeader_loc( st ); writeFrameHeader_loc( st ); @@ -209,7 +207,7 @@ PMT("find scaling factor for prev_enr_EnvSHBres, prev_pow_exc16kWhtnd and prev_m test(); test(); test(); - IF ((GT_32(st->total_brate,ACELP_24k40)&<_32(st->total_brate,HQ_96k))||(EQ_32(st->total_brate,ACELP_24k40)&&GE_16(st->bwidth,WB))) + IF( ( GT_32( st->total_brate, ACELP_24k40 ) && LT_32( st->total_brate, HQ_96k ) ) || ( EQ_32( st->total_brate, ACELP_24k40 ) && GE_16( st->bwidth, WB ) ) ) { st->L_frame = L_FRAME16k; move16(); @@ -220,7 +218,7 @@ PMT("find scaling factor for prev_enr_EnvSHBres, prev_pow_exc16kWhtnd and prev_m weight_a_subfr_fx( NB_SUBFR16k, A, Aw, GAMMA16k, M ); test(); - IF (EQ_16(st->last_L_frame,L_FRAME)&&st->ini_frame!=0) + IF( EQ_16( st->last_L_frame, L_FRAME ) && st->ini_frame != 0 ) { /* this is just an approximation, but it is sufficient */ Copy( st->lsp_old1_fx, st->lspold_enc_fx, M ); @@ -236,7 +234,7 @@ PMT("find scaling factor for prev_enr_EnvSHBres, prev_pow_exc16kWhtnd and prev_m move16(); } - st->sr_core = L_mult0(FRAMES_PER_SEC,st->L_frame); + st->sr_core = L_mult0( FRAMES_PER_SEC, st->L_frame ); st->core_brate = st->total_brate; move32(); @@ -246,43 +244,44 @@ PMT("find scaling factor for prev_enr_EnvSHBres, prev_pow_exc16kWhtnd and prev_m move16(); test(); test(); - IF( (EQ_16(st->bwidth,SWB)||EQ_16(st->bwidth,WB))&&LE_32(st->total_brate,LRMDCT_CROSSOVER_POINT)) + IF( ( EQ_16( st->bwidth, SWB ) || EQ_16( st->bwidth, WB ) ) && LE_32( st->total_brate, LRMDCT_CROSSOVER_POINT ) ) { /* note that FB (bitrate >= 24400bps) is always coded with NORMAL_HQ_CORE */ hq_core_type = LOW_RATE_HQ_CORE; move16(); } - ELSE IF( EQ_16(st->bwidth,NB)) + ELSE IF( EQ_16( st->bwidth, NB ) ) { hq_core_type = LOW_RATE_HQ_CORE; move16(); } } - IF( EQ_16(st->codec_mode,MODE1)) + IF( EQ_16( st->codec_mode, MODE1 ) ) { /*---------------------------------------------------------------------* * Write signalling info into the bitstream *---------------------------------------------------------------------*/ - signalling_enc_fx( st); + signalling_enc_fx( st ); /*---------------------------------------------------------------------* * Preprocessing (preparing) for ACELP/HQ core switching *---------------------------------------------------------------------*/ - core_switching_pre_enc_fx( st, old_inp_12k8, old_inp_16k, 0, 0); + core_switching_pre_enc_fx( st, old_inp_12k8, old_inp_16k, 0, 0 ); /*---------------------------------------------------------------------* * ACELP core encoding *---------------------------------------------------------------------*/ - IF( EQ_16(st->core,ACELP_CORE)) + IF( EQ_16( st->core, ACELP_CORE ) ) { acelp_core_enc_fx( st, inp, ener, A, Aw, epsP_h, epsP_l, lsp_new, lsp_mid, vad_hover_flag, attack_flag, bwe_exc_extended, voice_factors, old_syn_12k8_16k, pitch_buf, &unbits, Q_new, shift #ifdef ADD_LRTD - ,NULL, NULL + , + NULL, NULL #endif ); } @@ -290,9 +289,9 @@ PMT("find scaling factor for prev_enr_EnvSHBres, prev_pow_exc16kWhtnd and prev_m * HQ core encoding *---------------------------------------------------------------------*/ - IF( EQ_16(st->core,HQ_CORE)) + IF( EQ_16( st->core, HQ_CORE ) ) { - hq_core_enc_fx( st, st->input_fx - delay, input_frame, hq_core_type, Voicing_flag, vad_hover_flag); + hq_core_enc_fx( st, st->input_fx - delay, input_frame, hq_core_type, Voicing_flag, vad_hover_flag ); } /*---------------------------------------------------------------------* @@ -300,22 +299,22 @@ PMT("find scaling factor for prev_enr_EnvSHBres, prev_pow_exc16kWhtnd and prev_m *---------------------------------------------------------------------*/ core_switching_post_enc_fx( st, old_inp_12k8, old_inp_16k, A, shift, Q_new, st->Q_syn2, &Q_synth ); #ifndef FIX_I4_OL_PITCH - IF (EQ_16(st->core, HQ_CORE)) + IF( EQ_16( st->core, HQ_CORE ) ) { - Copy(pitch_orig, st->pitch_fx, 3); /* original open-loop pitch values might be altered in core_acelp_tcx20_switching_fx() */ + Copy( pitch_orig, st->pitch_fx, 3 ); /* original open-loop pitch values might be altered in core_acelp_tcx20_switching_fx() */ } #endif } - ELSE /* MODE2 */ + ELSE /* MODE2 */ { /*----------------------------------------------------------------* * Configuration of core coder/SID * Write Frame Header *----------------------------------------------------------------*/ - configure_core_coder_loc( st); + configure_core_coder_loc( st ); - IF (st->mdct_sw != MODE1) + IF( st->mdct_sw != MODE1 ) { writeFrameHeader_loc( st ); } @@ -326,10 +325,10 @@ PMT("find scaling factor for prev_enr_EnvSHBres, prev_pow_exc16kWhtnd and prev_m /* Call main encoding function */ enc_acelp_tcx_main_fx( old_inp_16k + L_INP_MEM, st, Aw, lsp_new, lsp_mid, - bwe_exc_extended, voice_factors, pitch_buf, - vad_hover_flag, &Q_new, &shift ); + bwe_exc_extended, voice_factors, pitch_buf, + vad_hover_flag, &Q_new, &shift ); #ifndef FIX_I4_OL_PITCH - Copy(pitch_orig, st->pitch_fx, 3); /* populate the original OL pitch values back */ + Copy( pitch_orig, st->pitch_fx, 3 ); /* populate the original OL pitch values back */ #endif /*---------------------------------------------------------------------* @@ -337,47 +336,47 @@ PMT("find scaling factor for prev_enr_EnvSHBres, prev_pow_exc16kWhtnd and prev_m *---------------------------------------------------------------------*/ /* TBE interface */ test(); - IF ( st->igf != 0 && GT_32(st->core_brate,SID_2k40)) + IF( st->igf != 0 && GT_32( st->core_brate, SID_2k40 ) ) { - IF( EQ_16(st->core,ACELP_CORE)) + IF( EQ_16( st->core, ACELP_CORE ) ) { - SWITCH (st->bwidth) + SWITCH( st->bwidth ) { - case WB: - st->extl = WB_TBE; - move16(); - st->extl_brate = WB_TBE_0k35; - move32(); - BREAK; + case WB: + st->extl = WB_TBE; + move16(); + st->extl_brate = WB_TBE_0k35; + move32(); + BREAK; - case SWB: - st->extl = SWB_TBE; - move16(); - st->extl_brate = SWB_TBE_1k6; - move32(); - IF (LT_32(st->total_brate, ACELP_13k20)) - { - st->extl_brate = SWB_TBE_0k95; + case SWB: + st->extl = SWB_TBE; + move16(); + st->extl_brate = SWB_TBE_1k6; move32(); - } - ELSE IF (GE_32(st->total_brate, ACELP_24k40)) - { - st->extl_brate = SWB_TBE_2k8; + IF( LT_32( st->total_brate, ACELP_13k20 ) ) + { + st->extl_brate = SWB_TBE_0k95; + move32(); + } + ELSE IF( GE_32( st->total_brate, ACELP_24k40 ) ) + { + st->extl_brate = SWB_TBE_2k8; + move32(); + } + BREAK; + case FB: + st->extl = FB_TBE; + move16(); + st->extl_brate = FB_TBE_1k8; move32(); - } - BREAK; - case FB: - st->extl = FB_TBE; - move16(); - st->extl_brate = FB_TBE_1k8; - move32(); - if (GE_32(st->total_brate, ACELP_24k40)) - { - st->extl_brate = FB_TBE_3k0; - move32(); - } - BREAK; + if ( GE_32( st->total_brate, ACELP_24k40 ) ) + { + st->extl_brate = FB_TBE_3k0; + move32(); + } + BREAK; } } ELSE @@ -390,12 +389,12 @@ PMT("find scaling factor for prev_enr_EnvSHBres, prev_pow_exc16kWhtnd and prev_m move32(); } - st->core_brate = L_sub(st->total_brate, st->extl_brate); + st->core_brate = L_sub( st->total_brate, st->extl_brate ); - IF( EQ_16(st->tec_tfa, 1)) + IF( EQ_16( st->tec_tfa, 1 ) ) { - st->core_brate = L_sub(st->core_brate, BITS_TEC); - st->core_brate = L_sub(st->core_brate, BITS_TFA); + st->core_brate = L_sub( st->core_brate, BITS_TEC ); + st->core_brate = L_sub( st->core_brate, BITS_TFA ); } } @@ -407,24 +406,23 @@ PMT("find scaling factor for prev_enr_EnvSHBres, prev_pow_exc16kWhtnd and prev_m test(); test(); - IF( st->igf != 0 && EQ_16(st->core,ACELP_CORE)&>_32(st->core_brate,SID_2k40)) + IF( st->igf != 0 && EQ_16( st->core, ACELP_CORE ) && GT_32( st->core_brate, SID_2k40 ) ) { /* padBits = ((st->bits_frame+7)/8)*8 - (st->nb_bits_tot + (st->rf_target_bits_write - ((st->Opt_RF_ON==1)?1:0) ) + get_tbe_bits(st->total_brate, st->bwidth, st->rf_mode )); */ - tmp = add(get_tbe_bits_fx(st->total_brate, st->bwidth, st->rf_mode), sub(st->rf_target_bits_write, st->rf_mode)); - padBits = sub(sub(shl(shr(add(st->bits_frame,7),3),3), hBstr->nb_bits_tot_fx), tmp); + tmp = add( get_tbe_bits_fx( st->total_brate, st->bwidth, st->rf_mode ), sub( st->rf_target_bits_write, st->rf_mode ) ); + padBits = sub( sub( shl( shr( add( st->bits_frame, 7 ), 3 ), 3 ), hBstr->nb_bits_tot_fx ), tmp ); } ELSE { /* padBits = ((st->bits_frame+7)/8)*8 - (st->nb_bits_tot + (st->rf_target_bits_write - ((st->Opt_RF_ON==1)?1:0) )); */ - tmp = sub(st->rf_target_bits_write, st->rf_mode); - padBits = sub(shl(shr(add(st->bits_frame,7),3),3), add(hBstr->nb_bits_tot_fx, tmp)); + tmp = sub( st->rf_target_bits_write, st->rf_mode ); + padBits = sub( shl( shr( add( st->bits_frame, 7 ), 3 ), 3 ), add( hBstr->nb_bits_tot_fx, tmp ) ); } - FOR( i = 0; iinput_Fs,16000 )&&(LT_16(st->bwidth,SWB))) + IF( GE_32( st->input_Fs, 16000 ) && ( LT_16( st->bwidth, SWB ) ) ) { /* Common pre-processing for WB TBE and WB BWE */ wb_pre_proc_fx( st, new_inp_resamp16k, hb_speech ); /* o: new_inp_resamp16k at Q = -1 */ } - IF ( EQ_16(st->extl,WB_TBE)) + IF( EQ_16( st->extl, WB_TBE ) ) { /* WB TBE encoder */ - wb_tbe_enc_fx( st, st->coder_type, hb_speech, bwe_exc_extended, Q_new, voice_factors, pitch_buf, st->voicing_fx); + wb_tbe_enc_fx( st, st->coder_type, hb_speech, bwe_exc_extended, Q_new, voice_factors, pitch_buf, st->voicing_fx ); - IF( EQ_16(st->codec_mode,MODE2)) + IF( EQ_16( st->codec_mode, MODE2 ) ) { tbe_write_bitstream_fx( st ); } } - ELSE IF ( EQ_16(st->extl, WB_BWE)) + ELSE IF( EQ_16( st->extl, WB_BWE ) ) { /* WB BWE encoder */ wb_bwe_enc_fx( st, new_inp_resamp16k, st->coder_type ); - } /*---------------------------------------------------------------------* @@ -462,18 +459,18 @@ PMT("find scaling factor for prev_enr_EnvSHBres, prev_pow_exc16kWhtnd and prev_m * SWB BWE encoding *---------------------------------------------------------------------*/ test(); - IF (!st->Opt_SC_VBR && GE_32(st->input_Fs,32000)) + IF( !st->Opt_SC_VBR && GE_32( st->input_Fs, 32000 ) ) { /* Common pre-processing for SWB(FB) TBE and SWB BWE */ - swb_pre_proc_fx(st, st->input_fx, new_swb_speech, shb_speech, &Q_shb_spch, realBuffer, imagBuffer, &cldfbScale ); + swb_pre_proc_fx( st, st->input_fx, new_swb_speech, shb_speech, &Q_shb_spch, realBuffer, imagBuffer, &cldfbScale ); } - ELSE IF( GE_32(st->input_Fs,32000)) + ELSE IF( GE_32( st->input_Fs, 32000 ) ) { - set16_fx(hBWE_TD->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k ); + set16_fx( hBWE_TD->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k ); set16_fx( shb_speech, 0, L_FRAME16k ); -#if defined IVAS_CODE - set_f(st->hBWE_TD->mem_shb_res, 0.0f, MAX_LEN_MA_FILTER); - set_f(st->hBWE_TD->old_EnvSHBres, 0.0f, L_FRAME4k); +#if defined IVAS_CODE + set_f( st->hBWE_TD->mem_shb_res, 0.0f, MAX_LEN_MA_FILTER ); + set_f( st->hBWE_TD->old_EnvSHBres, 0.0f, L_FRAME4k ); st->hBWE_TD->old_mean_EnvSHBres = 0.0f; st->hBWE_TD->prev_enr_EnvSHBres = 1.0f; st->hBWE_TD->prev_shb_env_tilt = 0.0f; @@ -490,33 +487,33 @@ PMT("find scaling factor for prev_enr_EnvSHBres, prev_pow_exc16kWhtnd and prev_m test(); test(); test(); - IF ( EQ_16(st->extl, SWB_TBE)||EQ_16(st->extl,FB_TBE)||(st->igf!=0&&EQ_16(st->core,ACELP_CORE)&&NE_16(st->extl,WB_TBE))) + IF( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, FB_TBE ) || ( st->igf != 0 && EQ_16( st->core, ACELP_CORE ) && NE_16( st->extl, WB_TBE ) ) ) { test(); - IF( NE_32(st->core_brate,FRAME_NO_DATA)&&NE_32(st->core_brate,SID_2k40)) + IF( NE_32( st->core_brate, FRAME_NO_DATA ) && NE_32( st->core_brate, SID_2k40 ) ) { swb_tbe_enc_fx( st, st->coder_type, shb_speech, bwe_exc_extended, voice_factors, fb_exc, &Q_fb_exc, Q_new, Q_shb_spch, st->voicing_fx, pitch_buf ); - IF ( EQ_16(st->extl,FB_TBE)) + IF( EQ_16( st->extl, FB_TBE ) ) { /* FB TBE encoder */ fb_tbe_enc_fx( st, st->input_fx, fb_exc, Q_fb_exc ); } - IF( EQ_16(st->codec_mode,MODE2)) + IF( EQ_16( st->codec_mode, MODE2 ) ) { - IF( EQ_16(st->tec_tfa, 1)) + IF( EQ_16( st->tec_tfa, 1 ) ) { - tecEnc_TBE_fx(&(st->hTECEnc->corrFlag), st->voicing_fx, st->coder_type); + tecEnc_TBE_fx( &( st->hTECEnc->corrFlag ), st->voicing_fx, st->coder_type ); - IF( EQ_16(st->coder_type, INACTIVE)) + IF( EQ_16( st->coder_type, INACTIVE ) ) { st->tec_flag = 0; move16(); st->hTECEnc->corrFlag = 0; move16(); } - st->tfa_flag = tfaEnc_TBE_fx( st->tfa_enr, st->last_core, st->voicing_fx, pitch_buf, shl(Q_shb_spch, 1)); + st->tfa_flag = tfaEnc_TBE_fx( st->tfa_enr, st->last_core, st->voicing_fx, pitch_buf, shl( Q_shb_spch, 1 ) ); set_TEC_TFA_code_fx( st->hTECEnc->corrFlag, &st->tec_flag, &st->tfa_flag ); } ELSE @@ -533,15 +530,15 @@ PMT("find scaling factor for prev_enr_EnvSHBres, prev_pow_exc16kWhtnd and prev_m } } } - ELSE IF ( EQ_16(st->extl,SWB_BWE)||EQ_16(st->extl,FB_BWE)) + ELSE IF( EQ_16( st->extl, SWB_BWE ) || EQ_16( st->extl, FB_BWE ) ) { /* SWB BWE encoder */ - swb_bwe_enc_fx( st, old_inp_12k8, old_inp_16k, old_syn_12k8_16k, new_swb_speech, shb_speech, st->coder_type, Q_shb_spch, sub(Q_new, 1) ); + swb_bwe_enc_fx( st, old_inp_12k8, old_inp_16k, old_syn_12k8_16k, new_swb_speech, shb_speech, st->coder_type, Q_shb_spch, sub( Q_new, 1 ) ); } - ELSE IF( EQ_16(st->extl,SWB_BWE_HIGHRATE)||EQ_16(st->extl,FB_BWE_HIGHRATE)) + ELSE IF( EQ_16( st->extl, SWB_BWE_HIGHRATE ) || EQ_16( st->extl, FB_BWE_HIGHRATE ) ) { /* SWB HR BWE encoder */ - swb_bwe_enc_hr_fx(st, st->input_fx - delay, st->Q_syn2, input_frame, unbits ); + swb_bwe_enc_hr_fx( st, st->input_fx - delay, st->Q_syn2, input_frame, unbits ); } /*---------------------------------------------------------------------* @@ -549,7 +546,7 @@ PMT("find scaling factor for prev_enr_EnvSHBres, prev_pow_exc16kWhtnd and prev_m *---------------------------------------------------------------------*/ test(); - IF ( st->Opt_DTX_ON && GE_16(input_frame,L_FRAME32k)) + IF( st->Opt_DTX_ON && GE_16( input_frame, L_FRAME32k ) ) { swb_CNG_enc_fx( st, shb_speech, old_syn_12k8_16k ); } @@ -560,22 +557,22 @@ PMT("find scaling factor for prev_enr_EnvSHBres, prev_pow_exc16kWhtnd and prev_m signalling_enc_rf( st ); - updt_enc_common_fx(st, Etot, Q_new); + updt_enc_common_fx( st, Etot, Q_new ); - if( EQ_16(st->mdct_sw,MODE1)) + if ( EQ_16( st->mdct_sw, MODE1 ) ) { st->codec_mode = MODE1; move16(); } - if(hTdCngEnc->lp_cng_mode2 ) + if ( hTdCngEnc->lp_cng_mode2 ) { st->codec_mode = MODE2; move16(); } - IF (EQ_16(st->rf_mode,1)) + IF( EQ_16( st->rf_mode, 1 ) ) { - IF (EQ_16(hRF->rf_frame_type,RF_NELP)) + IF( EQ_16( hRF->rf_frame_type, RF_NELP ) ) { hSC_VBR->last_nelp_mode = 1; } @@ -587,13 +584,13 @@ PMT("find scaling factor for prev_enr_EnvSHBres, prev_pow_exc16kWhtnd and prev_m /* RF mode updates */ st->rf_mode_last = st->rf_mode; - IF(EQ_16(st->Opt_RF_ON,1)) + IF( EQ_16( st->Opt_RF_ON, 1 ) ) { st->L_frame = L_FRAME; st->rf_mode = 1; } #ifdef MY_DEBUG - dbgwrite_indices(st); + dbgwrite_indices( st ); #endif return error; } @@ -604,34 +601,34 @@ PMT("find scaling factor for prev_enr_EnvSHBres, prev_pow_exc16kWhtnd and prev_m * * Initialize MODE2 frame header *-------------------------------------------------------------------*/ -static void initFrameHeader_loc(Encoder_State *st ) +static void initFrameHeader_loc( Encoder_State *st ) { Word16 n; - IF( EQ_32(st->core_brate, SID_2k40)) + IF( EQ_32( st->core_brate, SID_2k40 ) ) { /*Get size of frame*/ - st->bits_frame = FRAME_2_4; + st->bits_frame = FRAME_2_4; move16(); - st->bits_frame_core = add(st->bits_frame_core, FRAME_2_4-4); /*1 bit for SID on/off + 3 bits for bandwith in case of SID.*/ + st->bits_frame_core = add( st->bits_frame_core, FRAME_2_4 - 4 ); /*1 bit for SID on/off + 3 bits for bandwith in case of SID.*/ st->frame_size_index = 2; move16(); } - ELSE IF( EQ_32(st->core_brate,FRAME_NO_DATA)) + ELSE IF( EQ_32( st->core_brate, FRAME_NO_DATA ) ) { - st->bits_frame = FRAME_0; + st->bits_frame = FRAME_0; move16(); - st->bits_frame_core = add(st->bits_frame_core,st->bits_frame); + st->bits_frame_core = add( st->bits_frame_core, st->bits_frame ); st->frame_size_index = 0; move16(); } ELSE { - //PMT("Frame header needs review") - FOR( n=0; nbits_frame_nominal)) + IF( EQ_16( FrameSizeConfig[n].frame_bits, st->bits_frame_nominal ) ) { st->frame_size_index = n; move16(); @@ -652,48 +649,48 @@ static void initFrameHeader_loc(Encoder_State *st ) * * Write MODE2 frame header *-------------------------------------------------------------------*/ -static void writeFrameHeader_loc(Encoder_State *st ) +static void writeFrameHeader_loc( Encoder_State *st ) { BSTR_ENC_HANDLE hBstr = st->hBstr; - IF( NE_32(st->core_brate,FRAME_NO_DATA)) + IF( NE_32( st->core_brate, FRAME_NO_DATA ) ) { /* SID flag at 2.4kbps */ - IF( EQ_32(st->core_brate,SID_2k40)) + IF( EQ_32( st->core_brate, SID_2k40 ) ) { - IF ( EQ_16(st->cng_type,FD_CNG)) + IF( EQ_16( st->cng_type, FD_CNG ) ) { /* write SID/CNG type flag */ - push_next_indice_fx(hBstr, 1, 1 ); + push_next_indice_fx( hBstr, 1, 1 ); /* write bandwidth mode */ - push_next_indice_fx(hBstr, st->bwidth, 2 ); + push_next_indice_fx( hBstr, st->bwidth, 2 ); /* write L_frame */ - IF( EQ_16(st->L_frame,L_FRAME)) + IF( EQ_16( st->L_frame, L_FRAME ) ) { - push_next_indice_fx(hBstr, 0, 1 ); + push_next_indice_fx( hBstr, 0, 1 ); } ELSE { - push_next_indice_fx(hBstr, 1, 1 ); + push_next_indice_fx( hBstr, 1, 1 ); } } } ELSE /* active frames */ { - IF(st->rf_mode == 0) + IF( st->rf_mode == 0 ) { - push_next_indice_fx(hBstr, sub(st->bwidth,FrameSizeConfig[st->frame_size_index].bandwidth_min), FrameSizeConfig[st->frame_size_index].bandwidth_bits); + push_next_indice_fx( hBstr, sub( st->bwidth, FrameSizeConfig[st->frame_size_index].bandwidth_min ), FrameSizeConfig[st->frame_size_index].bandwidth_bits ); } } /* Write reserved bit */ test(); - IF( FrameSizeConfig[st->frame_size_index].reserved_bits && st->rf_mode == 0) + IF( FrameSizeConfig[st->frame_size_index].reserved_bits && st->rf_mode == 0 ) { - push_next_indice_fx(hBstr, 0, FrameSizeConfig[st->frame_size_index].reserved_bits ); + push_next_indice_fx( hBstr, 0, FrameSizeConfig[st->frame_size_index].reserved_bits ); } } @@ -701,20 +698,20 @@ static void writeFrameHeader_loc(Encoder_State *st ) } /*------------------------------------------------------------------------* -* Configuration of core coder/SID -*------------------------------------------------------------------------*/ + * Configuration of core coder/SID + *------------------------------------------------------------------------*/ static void configure_core_coder_loc( - Encoder_State *st /* i/o: encoder state structure */ + Encoder_State *st /* i/o: encoder state structure */ ) { initFrameHeader_loc( st ); test(); - IF( NE_32(st->core_brate, SID_2k40)&&NE_32(st->core_brate,FRAME_NO_DATA)) + IF( NE_32( st->core_brate, SID_2k40 ) && NE_32( st->core_brate, FRAME_NO_DATA ) ) { - if( st->tcxonly ) + if ( st->tcxonly ) { st->coder_type = GENERIC; move16(); @@ -726,17 +723,17 @@ static void configure_core_coder_loc( test(); test(); - if( !st->tcxonly && !st->localVAD && EQ_16(st->hTcxCfg->coder_type,GENERIC)) + if ( !st->tcxonly && !st->localVAD && EQ_16( st->hTcxCfg->coder_type, GENERIC ) ) { st->hTcxCfg->coder_type = UNVOICED; move16(); } } - st->igf = getIgfPresent_fx(st->element_mode, st->total_brate, st->bwidth, st->rf_mode); + st->igf = getIgfPresent_fx( st->element_mode, st->total_brate, st->bwidth, st->rf_mode ); test(); - if( NE_32(st->core_brate,SID_2k40)&&NE_32(st->core_brate,FRAME_NO_DATA)) + if ( NE_32( st->core_brate, SID_2k40 ) && NE_32( st->core_brate, FRAME_NO_DATA ) ) { st->core_brate = st->total_brate; move32(); diff --git a/lib_enc/ext_sig_ana.c b/lib_enc/ext_sig_ana.c index 75259d1df..6005d9cf6 100644 --- a/lib_enc/ext_sig_ana.c +++ b/lib_enc/ext_sig_ana.c @@ -128,7 +128,7 @@ void core_signal_analysis_high_bitrate( { mvr2r( st->speech_enc_flt + st->encoderLookahead_enc, st->new_speech_enc_pe_flt, L_frame ); - preemph( st->new_speech_enc_pe_flt, st->preemph_fac_flt, L_frame, &( st->mem_preemph_enc_flt) ); + preemph( st->new_speech_enc_pe_flt, st->preemph_fac_flt, L_frame, &( st->mem_preemph_enc_flt ) ); } if ( hTcxEnc->tcxMode == TCX_10 ) diff --git a/lib_enc/ext_sig_ana_fx.c b/lib_enc/ext_sig_ana_fx.c index 5b086e5d7..a24b15f88 100644 --- a/lib_enc/ext_sig_ana_fx.c +++ b/lib_enc/ext_sig_ana_fx.c @@ -9,10 +9,9 @@ //#include "prot_fx.h" #include "rom_com.h" #include "basop_util.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ - +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* @@ -22,8 +21,8 @@ *-------------------------------------------------------------------*/ void core_signal_analysis_high_bitrate_fx( - const Word16 *new_samples, /*i: 0Q15*/ - const Word16 T_op[3], /* i : open-loop pitch values for quantiz. */ + const Word16 *new_samples, /*i: 0Q15*/ + const Word16 T_op[3], /* i : open-loop pitch values for quantiz. */ Word16 lsp_new[], Word16 lsp_mid[], Encoder_State *st, @@ -34,11 +33,10 @@ void core_signal_analysis_high_bitrate_fx( const Word16 L_frame, const Word16 L_frameTCX, const Word16 last_element_mode, - const Word16 vad_hover_flag, /* i : VAD hangover flag */ + const Word16 vad_hover_flag, /* i : VAD hangover flag */ Word32 **spectrum, Word16 *spectrum_e, - Word16 *Q_new -) + Word16 *Q_new ) { const Word16 last_overlap = st->hTcxCfg->tcx_last_overlap_mode; const Word16 curr_overlap = st->hTcxCfg->tcx_curr_overlap_mode; @@ -46,21 +44,21 @@ void core_signal_analysis_high_bitrate_fx( Word16 L_subframe; Word16 left_overlap, right_overlap, folding_offset; Word32 buf[N_MAX]; /* Buffer for TCX20/TCX10 windowing, power spectrum */ - Word16 A[M+1]; - Word16 mdstWin[N_MAX+L_MDCT_OVLP_MAX]; /* Buffer for MDST windowing */ - Word16 * pMdstWin; + Word16 A[M + 1]; + Word16 mdstWin[N_MAX + L_MDCT_OVLP_MAX]; /* Buffer for MDST windowing */ + Word16 *pMdstWin; Word16 lpc_left_overlap_mode, lpc_right_overlap_mode; - Word16 * tcx20Win = (Word16*)buf; + Word16 *tcx20Win = (Word16 *) buf; Word32 powerSpec[N_MAX]; Word16 powerSpec_e; Word32 interleaveBuf[N_TCX10_MAX]; - Word16 *tcx5Win = (Word16*)interleaveBuf; /* Buffer for TCX5 windowing and interleaving. */ - Word16 r_h[NB_DIV][M+1], r_l[NB_DIV][M+1]; - Word32 r[M+1], epsP[M+1]; + Word16 *tcx5Win = (Word16 *) interleaveBuf; /* Buffer for TCX5 windowing and interleaving. */ + Word16 r_h[NB_DIV][M + 1], r_l[NB_DIV][M + 1]; + Word32 r[M + 1], epsP[M + 1]; Word16 *lsp[2]; - Word8 tmp8; + Word8 tmp8; Word16 alw_pitch_lag_12k8[2], alw_pitch_lag_12k8_wc = -1; - Word16 alw_voicing[2] , alw_voicing_wc = -1; + Word16 alw_voicing[2], alw_voicing_wc = -1; Word16 nSubframes; Word16 overlap_mode[3]; Word16 transform_type[2]; @@ -77,14 +75,14 @@ void core_signal_analysis_high_bitrate_fx( TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; #ifndef IVAS_CODE - (void)vad_hover_flag; - (void)last_element_mode; + (void) vad_hover_flag; + (void) last_element_mode; #endif #ifdef IVAS_CODE - if (NE_16(last_element_mode, st->element_mode) ) + if ( NE_16( last_element_mode, st->element_mode ) ) { disable_ltp = 1; /* disable TCX-LTP in stereo switching to avoid discontinuities in synthesis */ - move16(); + move16(); } #endif left_overlap = -1; @@ -92,88 +90,88 @@ void core_signal_analysis_high_bitrate_fx( right_overlap = -1; move16(); - tcx10SizeFB = shl(st->hTcxCfg->tcx5SizeFB, 1); + tcx10SizeFB = shl( st->hTcxCfg->tcx5SizeFB, 1 ); tcx5SizeFB = st->hTcxCfg->tcx5SizeFB; move16(); - tcx10Size = shl(st->hTcxCfg->tcx5Size, 1); + tcx10Size = shl( st->hTcxCfg->tcx5Size, 1 ); /*--------------------------------------------------------------* - * Input Signal Processing: copy, HP filter, pre-emphasis - *---------------------------------------------------------------*/ + * Input Signal Processing: copy, HP filter, pre-emphasis + *---------------------------------------------------------------*/ /* Copy Samples */ - IF (st->tcxonly && NE_16(st->element_mode, IVAS_CPE_MDCT)) + IF( st->tcxonly && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { - Copy(new_samples, st->new_speech_enc, L_frame); - Scale_sig(st->new_speech_enc, L_frame, 1); + Copy( new_samples, st->new_speech_enc, L_frame ); + Scale_sig( st->new_speech_enc, L_frame, 1 ); } /*--------------------------------------------------------------* - * TCX-LTP - *---------------------------------------------------------------*/ + * TCX-LTP + *---------------------------------------------------------------*/ tmp8 = 0; move16(); - if(GT_32(st->sr_core, 25600)) + if ( GT_32( st->sr_core, 25600 ) ) { tmp8 = 1; move16(); } - IF (EQ_16(st->element_mode, IVAS_CPE_DFT)) + IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) { - //PMT("tcx_ltp_encode_fx should be verified for IVAS") - tcx_ltp_encode_fx(hTcxEnc->tcxltp, (Word8)st->tcxonly, hTcxEnc->tcxMode, - L_frame, L_SUBFR, st->speech_enc + st->encoderLookahead_enc, - hTcxEnc->speech_ltp + st->encoderLookahead_enc, st->speech_enc + st->encoderLookahead_enc, - T_op[1], ¶m_core[1 + NOISE_FILL_RANGES], ltpBits, - &hTcxEnc->tcxltp_pitch_int, &hTcxEnc->tcxltp_pitch_fr, &hTcxEnc->tcxltp_gain, - &hTcxEnc->tcxltp_pitch_int_past, &hTcxEnc->tcxltp_pitch_fr_past, &hTcxEnc->tcxltp_gain_past, - &hTcxEnc->tcxltp_norm_corr_past, st->last_core, st->pit_min, st->pit_fr1, - st->pit_fr2, st->pit_max, st->pit_res_max, &st->transientDetection, - tmp8, NULL, M); + // PMT("tcx_ltp_encode_fx should be verified for IVAS") + tcx_ltp_encode_fx( hTcxEnc->tcxltp, (Word8) st->tcxonly, hTcxEnc->tcxMode, + L_frame, L_SUBFR, st->speech_enc + st->encoderLookahead_enc, + hTcxEnc->speech_ltp + st->encoderLookahead_enc, st->speech_enc + st->encoderLookahead_enc, + T_op[1], ¶m_core[1 + NOISE_FILL_RANGES], ltpBits, + &hTcxEnc->tcxltp_pitch_int, &hTcxEnc->tcxltp_pitch_fr, &hTcxEnc->tcxltp_gain, + &hTcxEnc->tcxltp_pitch_int_past, &hTcxEnc->tcxltp_pitch_fr_past, &hTcxEnc->tcxltp_gain_past, + &hTcxEnc->tcxltp_norm_corr_past, st->last_core, st->pit_min, st->pit_fr1, + st->pit_fr2, st->pit_max, st->pit_res_max, &st->transientDetection, + tmp8, NULL, M ); } ELSE { - tcx_ltp_encode_fx(hTcxEnc->tcxltp, (Word8)st->tcxonly, hTcxEnc->tcxMode, - L_frame, L_SUBFR, st->speech_enc + st->encoderLookahead_enc, - hTcxEnc->speech_ltp + st->encoderLookahead_enc, st->speech_enc + st->encoderLookahead_enc, - T_op[1], ¶m_core[1 + NOISE_FILL_RANGES], ltpBits, - &hTcxEnc->tcxltp_pitch_int, &hTcxEnc->tcxltp_pitch_fr, &hTcxEnc->tcxltp_gain, - &hTcxEnc->tcxltp_pitch_int_past, &hTcxEnc->tcxltp_pitch_fr_past, &hTcxEnc->tcxltp_gain_past, - &hTcxEnc->tcxltp_norm_corr_past, st->last_core, st->pit_min, st->pit_fr1, - st->pit_fr2, st->pit_max, st->pit_res_max, &st->transientDetection, - tmp8, NULL, M); + tcx_ltp_encode_fx( hTcxEnc->tcxltp, (Word8) st->tcxonly, hTcxEnc->tcxMode, + L_frame, L_SUBFR, st->speech_enc + st->encoderLookahead_enc, + hTcxEnc->speech_ltp + st->encoderLookahead_enc, st->speech_enc + st->encoderLookahead_enc, + T_op[1], ¶m_core[1 + NOISE_FILL_RANGES], ltpBits, + &hTcxEnc->tcxltp_pitch_int, &hTcxEnc->tcxltp_pitch_fr, &hTcxEnc->tcxltp_gain, + &hTcxEnc->tcxltp_pitch_int_past, &hTcxEnc->tcxltp_pitch_fr_past, &hTcxEnc->tcxltp_gain_past, + &hTcxEnc->tcxltp_norm_corr_past, st->last_core, st->pit_min, st->pit_fr1, + st->pit_fr2, st->pit_max, st->pit_res_max, &st->transientDetection, + tmp8, NULL, M ); } test(); - IF(st->tcxonly&& NE_16(st->element_mode, IVAS_CPE_MDCT)) + IF( st->tcxonly && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { - Copy(st->speech_enc + st->encoderLookahead_enc, st->new_speech_enc_pe, L_frame); + Copy( st->speech_enc + st->encoderLookahead_enc, st->new_speech_enc_pe, L_frame ); - Preemph_scaled(st->new_speech_enc_pe, Q_new, &(st->mem_preemph_enc), - st->Q_max_enc, st->preemph_fac, 1, 0, 2, L_frame, st->coder_type_raw, 1); + Preemph_scaled( st->new_speech_enc_pe, Q_new, &( st->mem_preemph_enc ), + st->Q_max_enc, st->preemph_fac, 1, 0, 2, L_frame, st->coder_type_raw, 1 ); } - Q_exp = sub(*Q_new, st->prev_Q_new); + Q_exp = sub( *Q_new, st->prev_Q_new ); move16(); /* Rescale Memory */ - Scale_sig(st->old_inp_16k_fx, L_INP_MEM, sub(*Q_new,st->Q_old)); - IF (Q_exp != 0) + Scale_sig( st->old_inp_16k_fx, L_INP_MEM, sub( *Q_new, st->Q_old ) ); + IF( Q_exp != 0 ) { - Scale_sig(st->buf_speech_enc_pe, st->encoderPastSamples_enc+st->encoderLookahead_enc, Q_exp); - Scale_sig(&(st->mem_wsp_enc), 1, Q_exp); + Scale_sig( st->buf_speech_enc_pe, st->encoderPastSamples_enc + st->encoderLookahead_enc, Q_exp ); + Scale_sig( &( st->mem_wsp_enc ), 1, Q_exp ); } - IF (EQ_16(hTcxEnc->tcxMode,TCX_10)) + IF( EQ_16( hTcxEnc->tcxMode, TCX_10 ) ) { - Copy( ¶m_core[1+NOISE_FILL_RANGES], ¶m_core[NPRM_DIV+1+NOISE_FILL_RANGES], LTPSIZE ); + Copy( ¶m_core[1 + NOISE_FILL_RANGES], ¶m_core[NPRM_DIV + 1 + NOISE_FILL_RANGES], LTPSIZE ); } /*-------------------------------------------------------------------------* - * Decision matrix for the transform and overlap length - *--------------------------------------------------------------------------*/ - IF(NE_16(st->element_mode, IVAS_CPE_MDCT)) + * Decision matrix for the transform and overlap length + *--------------------------------------------------------------------------*/ + IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { lsp[0] = lsp_new; lsp[1] = lsp_mid; @@ -186,21 +184,23 @@ void core_signal_analysis_high_bitrate_fx( alw_voicing[1] = st->voicing_fx[1]; move16(); - alw_pitch_lag_12k8_wc = s_min(alw_pitch_lag_12k8[0], alw_pitch_lag_12k8[1]); - alw_voicing_wc = s_max(alw_voicing[0], alw_voicing[1]); + alw_pitch_lag_12k8_wc = s_min( alw_pitch_lag_12k8[0], alw_pitch_lag_12k8[1] ); + alw_voicing_wc = s_max( alw_voicing[0], alw_voicing[1] ); } - overlap_mode[0] = last_overlap; /* Overlap between the last and the current frame */ move16(); + overlap_mode[0] = last_overlap; /* Overlap between the last and the current frame */ + move16(); - IF (EQ_16(hTcxEnc->tcxMode, TCX_20)) + IF( EQ_16( hTcxEnc->tcxMode, TCX_20 ) ) { nSubframes = 1; move16(); transform_type[0] = TCX_20; transform_type[1] = TCX_20; move16(); - overlap_mode[1] = curr_overlap; /* Overlap between the current and the next frame */ move16(); - - IF(NE_16(st->element_mode, IVAS_CPE_MDCT)) + overlap_mode[1] = curr_overlap; /* Overlap between the current and the next frame */ + move16(); + + IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { alw_pitch_lag_12k8[0] = alw_pitch_lag_12k8_wc; move16(); @@ -212,29 +212,31 @@ void core_signal_analysis_high_bitrate_fx( { nSubframes = 2; move16(); - IF (EQ_16(curr_overlap, FULL_OVERLAP)) + IF( EQ_16( curr_overlap, FULL_OVERLAP ) ) { transform_type[0] = TCX_5; move16(); transform_type[1] = TCX_10; move16(); - overlap_mode[1] = MIN_OVERLAP; /* Overlap between 2nd and 3rd sub-frame */ move16(); - if (EQ_16(last_overlap, HALF_OVERLAP)) + overlap_mode[1] = MIN_OVERLAP; /* Overlap between 2nd and 3rd sub-frame */ + move16(); + if ( EQ_16( last_overlap, HALF_OVERLAP ) ) { overlap_mode[1] = HALF_OVERLAP; move16(); } } - ELSE IF (EQ_16(last_overlap, FULL_OVERLAP)) + ELSE IF( EQ_16( last_overlap, FULL_OVERLAP ) ) { transform_type[0] = TCX_10; move16(); transform_type[1] = TCX_5; move16(); - overlap_mode[1] = MIN_OVERLAP; /* Overlap between 1st and 2nd sub-frame */ move16(); - if (EQ_16(curr_overlap, HALF_OVERLAP)) + overlap_mode[1] = MIN_OVERLAP; /* Overlap between 1st and 2nd sub-frame */ + move16(); + if ( EQ_16( curr_overlap, HALF_OVERLAP ) ) { overlap_mode[1] = HALF_OVERLAP; move16(); @@ -246,89 +248,92 @@ void core_signal_analysis_high_bitrate_fx( move16(); move16(); - overlap_mode[1] = MIN_OVERLAP; /* Overlap between 2nd and 3rd sub-frame */ move16(); + overlap_mode[1] = MIN_OVERLAP; /* Overlap between 2nd and 3rd sub-frame */ + move16(); test(); - if (EQ_16(last_overlap, HALF_OVERLAP)&&EQ_16(curr_overlap,HALF_OVERLAP)) + if ( EQ_16( last_overlap, HALF_OVERLAP ) && EQ_16( curr_overlap, HALF_OVERLAP ) ) { overlap_mode[1] = HALF_OVERLAP; move16(); } } - overlap_mode[2] = curr_overlap; /* Overlap between the current and the next frame */ move16(); + overlap_mode[2] = curr_overlap; /* Overlap between the current and the next frame */ + move16(); } - IF (NE_16(transform_type[0], TCX_20)) + IF( NE_16( transform_type[0], TCX_20 ) ) { - IGFEncResetTCX10BitCounter_fx(st->hIGFEnc); + IGFEncResetTCX10BitCounter_fx( st->hIGFEnc ); } /*-------------------------------------------------------------------------* - * Get MDCT output and TNS parameters. Apply TNS in the spectrum if needed - *--------------------------------------------------------------------------*/ + * Get MDCT output and TNS parameters. Apply TNS in the spectrum if needed + *--------------------------------------------------------------------------*/ - FOR(frameno = 0; frameno < nSubframes; frameno++) + FOR( frameno = 0; frameno < nSubframes; frameno++ ) { L_subframe = L_frameTCX; move16(); - if (NE_16(nSubframes, 1))L_subframe = shr(L_frameTCX, 1); + if ( NE_16( nSubframes, 1 ) ) + L_subframe = shr( L_frameTCX, 1 ); lpc_left_overlap_mode = overlap_mode[frameno]; move16(); lpc_right_overlap_mode = overlap_mode[frameno + 1]; move16(); - if (EQ_16(lpc_left_overlap_mode, ALDO_WINDOW)) + if ( EQ_16( lpc_left_overlap_mode, ALDO_WINDOW ) ) { lpc_left_overlap_mode = FULL_OVERLAP; move16(); } - if (EQ_16(lpc_right_overlap_mode, ALDO_WINDOW)) + if ( EQ_16( lpc_right_overlap_mode, ALDO_WINDOW ) ) { lpc_right_overlap_mode = FULL_OVERLAP; move16(); } test(); - IF((NE_16(transform_type[frameno], TCX_20)) || (EQ_16(st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP))) + IF( ( NE_16( transform_type[frameno], TCX_20 ) ) || ( EQ_16( st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) ) ) { /* Windowing of the 2xTCX5 subframes or 1xTCX10 or 1xTCX20 */ - WindowSignal(st->hTcxCfg, st->hTcxCfg->tcx_offsetFB, overlap_mode[frameno], - overlap_mode[frameno + 1], &left_overlap, &right_overlap, &hTcxEnc->speech_TCX[frameno * tcx10SizeFB], - &L_subframe, tcx20Win, st->element_mode != IVAS_CPE_MDCT /* truncate_aldo */, 1); -#ifdef IVAS_CODE - if (windowed_samples != NULL) /* save windowed speech_TCX samples */ + WindowSignal( st->hTcxCfg, st->hTcxCfg->tcx_offsetFB, overlap_mode[frameno], + overlap_mode[frameno + 1], &left_overlap, &right_overlap, &hTcxEnc->speech_TCX[frameno * tcx10SizeFB], + &L_subframe, tcx20Win, st->element_mode != IVAS_CPE_MDCT /* truncate_aldo */, 1 ); +#ifdef IVAS_CODE + if ( windowed_samples != NULL ) /* save windowed speech_TCX samples */ { - assert(L_subframe + (left_overlap + right_overlap) / 2 < 2 * L_FRAME_MAX / nSubframes - L_FRAME_MAX / 8); - windowed_samples[frameno * L_FRAME_MAX + 0] = (float)overlap_mode[frameno]; - windowed_samples[frameno * L_FRAME_MAX + 1] = (float)overlap_mode[frameno + 1]; - mvr2r(tcx20Win, windowed_samples + frameno * L_FRAME_MAX + 2, L_subframe + (left_overlap + right_overlap) / 2); + assert( L_subframe + ( left_overlap + right_overlap ) / 2 < 2 * L_FRAME_MAX / nSubframes - L_FRAME_MAX / 8 ); + windowed_samples[frameno * L_FRAME_MAX + 0] = (float) overlap_mode[frameno]; + windowed_samples[frameno * L_FRAME_MAX + 1] = (float) overlap_mode[frameno + 1]; + mvr2r( tcx20Win, windowed_samples + frameno * L_FRAME_MAX + 2, L_subframe + ( left_overlap + right_overlap ) / 2 ); } #endif } - IF(EQ_16(transform_type[frameno], TCX_5)) + IF( EQ_16( transform_type[frameno], TCX_5 ) ) { - folding_offset = shr(left_overlap, 1); + folding_offset = shr( left_overlap, 1 ); /* Outter left folding */ - FOR(i = 0; i < folding_offset; i++) + FOR( i = 0; i < folding_offset; i++ ) { #ifdef BASOP_NOGLOB tcx20Win[folding_offset + i] = sub_sat( tcx20Win[folding_offset + i], tcx20Win[folding_offset - 1 - i] ); #else - tcx20Win[folding_offset + i] = sub(tcx20Win[folding_offset + i], tcx20Win[folding_offset - 1 - i]); + tcx20Win[folding_offset + i] = sub( tcx20Win[folding_offset + i], tcx20Win[folding_offset - 1 - i] ); #endif move16(); } -#ifdef IVAS_CODE - if (st->element_mode == IVAS_CPE_MDCT && frameno == 0 && overlap_mode[0] == FULL_OVERLAP && L_subframe - left_overlap > minWindowLen) +#ifdef IVAS_CODE + if ( st->element_mode == IVAS_CPE_MDCT && frameno == 0 && overlap_mode[0] == FULL_OVERLAP && L_subframe - left_overlap > minWindowLen ) { - for (i = minWindowLen; i >= 0; i--) /* outer left folding of shortened long ALDO slope */ + for ( i = minWindowLen; i >= 0; i-- ) /* outer left folding of shortened long ALDO slope */ { tcx20Win[left_overlap + i] -= hTcxEnc->speech_TCX[-1 - i] * st->hTcxCfg->tcx_aldo_window_1_FB[left_overlap / 2 + minWindowLen - i] * st->hTcxCfg->tcx_mdct_window_minimumFB[minWindowLen - i]; } } #endif /* Outter right folding */ - tmp = shr(right_overlap, 1); - FOR(i = 0; i < tmp; i++) + tmp = shr( right_overlap, 1 ); + FOR( i = 0; i < tmp; i++ ) { #ifdef BASOP_NOGLOB tcx20Win[L_subframe + folding_offset - 1 - i] = add_sat( tcx20Win[L_subframe + folding_offset - 1 - i], tcx20Win[L_subframe + folding_offset + i] ); @@ -343,156 +348,157 @@ void core_signal_analysis_high_bitrate_fx( tmpP16 = tcx20Win; tmpP32 = spectrum[frameno]; - assert(st->mct_chan_mode != MCT_CHAN_MODE_LFE); - FOR(i = 0; i < 2; i++) + assert( st->mct_chan_mode != MCT_CHAN_MODE_LFE ); + FOR( i = 0; i < 2; i++ ) { test(); test(); - WindowSignal(st->hTcxCfg, - folding_offset, - mac_r(-(1 << 16), 3 << 8, shl(i, 7)), /* equivalent to: i == 0 ? RECTANGULAR_OVERLAP : MIN_OVERLAP */ - mac_r(2 << 16, -(3 << 8), shl(i, 7)), /* equivalent to: sub(i, 1) == 0 ? RECTANGULAR_OVERLAP : MIN_OVERLAP */ - &left_overlap, &right_overlap, tmpP16, &L_subframe, tcx5Win, st->element_mode != IVAS_CPE_MDCT, 1); + WindowSignal( st->hTcxCfg, + folding_offset, + mac_r( -( 1 << 16 ), 3 << 8, shl( i, 7 ) ), /* equivalent to: i == 0 ? RECTANGULAR_OVERLAP : MIN_OVERLAP */ + mac_r( 2 << 16, -( 3 << 8 ), shl( i, 7 ) ), /* equivalent to: sub(i, 1) == 0 ? RECTANGULAR_OVERLAP : MIN_OVERLAP */ + &left_overlap, &right_overlap, tmpP16, &L_subframe, tcx5Win, st->element_mode != IVAS_CPE_MDCT, 1 ); spectrum_e[frameno] = 16; move16(); - TCX_MDCT(tcx5Win, - tmpP32, - &spectrum_e[frameno], - left_overlap, - sub(L_subframe, shr(add(left_overlap, right_overlap), 1)), - right_overlap, st->element_mode); + TCX_MDCT( tcx5Win, + tmpP32, + &spectrum_e[frameno], + left_overlap, + sub( L_subframe, shr( add( left_overlap, right_overlap ), 1 ) ), + right_overlap, st->element_mode ); tmpP16 += tcx5SizeFB; tmpP32 += tcx5SizeFB; -#ifdef IVAS_CODE +#ifdef IVAS_CODE /* high-band gain control in case of BWS */ - if (st->bwidth_sw_cnt > 0) + if ( st->bwidth_sw_cnt > 0 ) { - v_multc(hTcxEnc->spectrum[frameno] + i * tcx5SizeFB + L_FRAME16k / (2 * nSubframes), (float)(st->bwidth_sw_cnt) / (float)BWS_TRAN_PERIOD, hTcxEnc->spectrum[frameno] + i * tcx5SizeFB + L_FRAME16k / (2 * nSubframes), L_subframe - L_FRAME16k / (2 * nSubframes)); + v_multc( hTcxEnc->spectrum[frameno] + i * tcx5SizeFB + L_FRAME16k / ( 2 * nSubframes ), (float) ( st->bwidth_sw_cnt ) / (float) BWS_TRAN_PERIOD, hTcxEnc->spectrum[frameno] + i * tcx5SizeFB + L_FRAME16k / ( 2 * nSubframes ), L_subframe - L_FRAME16k / ( 2 * nSubframes ) ); } #endif } - } ELSE /* transform_type[frameno] != TCX_5 */ { - assert(transform_type[frameno] == TCX_10 || transform_type[frameno] == TCX_20); + assert( transform_type[frameno] == TCX_10 || transform_type[frameno] == TCX_20 ); - /* TCX20/TCX10 */ - spectrum_e[frameno] = 16; - move16(); - test(); test(); - IF((EQ_16(transform_type[frameno], TCX_20)) && (NE_16(st->hTcxCfg->tcx_last_overlap_mode,TRANSITION_OVERLAP)) && NE_16(st->mct_chan_mode, MCT_CHAN_MODE_LFE)) - { - Word32 tmp_buf[L_FRAME_PLUS]; - Word16 Q, tmp1, tmp2; - - Q = 0; + /* TCX20/TCX10 */ + spectrum_e[frameno] = 16; move16(); + test(); + test(); + IF( ( EQ_16( transform_type[frameno], TCX_20 ) ) && ( NE_16( st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) ) && NE_16( st->mct_chan_mode, MCT_CHAN_MODE_LFE ) ) + { + Word32 tmp_buf[L_FRAME_PLUS]; + Word16 Q, tmp1, tmp2; - wtda_fx(hTcxEnc->new_speech_TCX,&Q, tmp_buf, NULL, NULL, overlap_mode[frameno], overlap_mode[frameno + 1], L_frameTCX); + Q = 0; + move16(); - WindowSignal(st->hTcxCfg, st->hTcxCfg->tcx_offsetFB, lpc_left_overlap_mode, lpc_right_overlap_mode, &left_overlap, &right_overlap, &hTcxEnc->speech_TCX[frameno * tcx10SizeFB], &L_subframe, mdstWin, st->element_mode != IVAS_CPE_MDCT, 1); + wtda_fx( hTcxEnc->new_speech_TCX, &Q, tmp_buf, NULL, NULL, overlap_mode[frameno], overlap_mode[frameno + 1], L_frameTCX ); - /* scale by NORM_MDCT_FACTOR / L */ - tmp1 = mult_r(shl(L_subframe, 4), 26214/*128.f / NORM_MDCT_FACTOR Q15*/); /* 4Q11 */ - tmp2 = 4; - move16(); - tmp1 = ISqrt16(tmp1, &tmp2); + WindowSignal( st->hTcxCfg, st->hTcxCfg->tcx_offsetFB, lpc_left_overlap_mode, lpc_right_overlap_mode, &left_overlap, &right_overlap, &hTcxEnc->speech_TCX[frameno * tcx10SizeFB], &L_subframe, mdstWin, st->element_mode != IVAS_CPE_MDCT, 1 ); - FOR(i = 0; i < L_subframe; i++) - { - tmp_buf[i] = Mpy_32_16_1(tmp_buf[i], tmp1); - move32(); - } - Q = sub(Q, tmp2); + /* scale by NORM_MDCT_FACTOR / L */ + tmp1 = mult_r( shl( L_subframe, 4 ), 26214 /*128.f / NORM_MDCT_FACTOR Q15*/ ); /* 4Q11 */ + tmp2 = 4; + move16(); + tmp1 = ISqrt16( tmp1, &tmp2 ); - /* DCT */ - edct_fx(tmp_buf, spectrum[frameno], L_subframe, &Q); - *spectrum_e = sub(31, Q); - } - ELSE - { + FOR( i = 0; i < L_subframe; i++ ) + { + tmp_buf[i] = Mpy_32_16_1( tmp_buf[i], tmp1 ); + move32(); + } + Q = sub( Q, tmp2 ); + + /* DCT */ + edct_fx( tmp_buf, spectrum[frameno], L_subframe, &Q ); + *spectrum_e = sub( 31, Q ); + } + ELSE + { #ifdef IVAS_CODE - if (st->element_mode == IVAS_CPE_MDCT && frameno == 0 && transform_type[0] == TCX_10 && overlap_mode[0] == FULL_OVERLAP && L_subframe - left_overlap > minWindowLen) + if ( st->element_mode == IVAS_CPE_MDCT && frameno == 0 && transform_type[0] == TCX_10 && overlap_mode[0] == FULL_OVERLAP && L_subframe - left_overlap > minWindowLen ) { - for (i = minWindowLen; i >= 0; i--) /* outer left folding of shortened long ALDO slope */ + for ( i = minWindowLen; i >= 0; i-- ) /* outer left folding of shortened long ALDO slope */ { tcx20Win[left_overlap + i] -= hTcxEnc->speech_TCX[-1 - i] * st->hTcxCfg->tcx_aldo_window_1_FB[left_overlap / 2 + minWindowLen - i] * st->hTcxCfg->tcx_mdct_window_minimumFB[minWindowLen - i]; } } #endif - TCX_MDCT(tcx20Win,spectrum[frameno], &spectrum_e[frameno], left_overlap, sub(L_subframe, shr(add(left_overlap, right_overlap), 1)), right_overlap, st->element_mode); + TCX_MDCT( tcx20Win, spectrum[frameno], &spectrum_e[frameno], left_overlap, sub( L_subframe, shr( add( left_overlap, right_overlap ), 1 ) ), right_overlap, st->element_mode ); } /* For TCX20 at bitrates up to 64 kbps we need the power spectrum */ /* high-band gain control in case of BWS */ #ifdef IVAS_CODE - if (st->bwidth_sw_cnt > 0) + if ( st->bwidth_sw_cnt > 0 ) { - v_multc(hTcxEnc->spectrum[frameno] + L_FRAME16k / nSubframes, (float)(st->bwidth_sw_cnt) / (float)BWS_TRAN_PERIOD, hTcxEnc->spectrum[frameno] + L_FRAME16k / nSubframes, L_subframe - L_FRAME16k / nSubframes); + v_multc( hTcxEnc->spectrum[frameno] + L_FRAME16k / nSubframes, (float) ( st->bwidth_sw_cnt ) / (float) BWS_TRAN_PERIOD, hTcxEnc->spectrum[frameno] + L_FRAME16k / nSubframes, L_subframe - L_FRAME16k / nSubframes ); } - if (st->mct_chan_mode == MCT_CHAN_MODE_LFE) + if ( st->mct_chan_mode == MCT_CHAN_MODE_LFE ) { - set_f(&hTcxEnc->spectrum[frameno][MCT_LFE_MAX_LINE], 0.f, L_subframe - MCT_LFE_MAX_LINE); + set_f( &hTcxEnc->spectrum[frameno][MCT_LFE_MAX_LINE], 0.f, L_subframe - MCT_LFE_MAX_LINE ); st->hTcxCfg->tcx_coded_lines = MCT_LFE_MAX_LINE; } #endif - IF(NE_16(st->element_mode, IVAS_CPE_MDCT)) + IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { - test(); test(); - IF(EQ_16(hTcxEnc->tcxMode, TCX_20) && ((LT_32(st->total_brate, HQ_96k)) || st->igf)) + test(); + test(); + IF( EQ_16( hTcxEnc->tcxMode, TCX_20 ) && ( ( LT_32( st->total_brate, HQ_96k ) ) || st->igf ) ) { pMdstWin = tcx20Win; test(); - if (((EQ_16(hTcxEnc->tcxMode, TCX_20)) && (NE_16(st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP)))) + if ( ( ( EQ_16( hTcxEnc->tcxMode, TCX_20 ) ) && ( NE_16( st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) ) ) ) { pMdstWin = mdstWin; } /* Compute noise-measure flags for spectrum filling and quantization */ - AnalyzePowerSpectrum_fx(st, div_l(L_mult(L_subframe, st->L_frame), hTcxEnc->L_frameTCX), - L_subframe, left_overlap, right_overlap, spectrum[frameno], spectrum_e[frameno], - pMdstWin, powerSpec, &powerSpec_e); + AnalyzePowerSpectrum_fx( st, div_l( L_mult( L_subframe, st->L_frame ), hTcxEnc->L_frameTCX ), + L_subframe, left_overlap, right_overlap, spectrum[frameno], spectrum_e[frameno], + pMdstWin, powerSpec, &powerSpec_e ); } } #ifdef IVAS_CODE - if (st->element_mode == IVAS_CPE_MDCT) + if ( st->element_mode == IVAS_CPE_MDCT ) { L_subframe = L_frameTCX / nSubframes; - if (transform_type[frameno] == TCX_20 && st->hTcxCfg->tcx_last_overlap_mode != TRANSITION_OVERLAP && st->mct_chan_mode != MCT_CHAN_MODE_LFE) + if ( transform_type[frameno] == TCX_20 && st->hTcxCfg->tcx_last_overlap_mode != TRANSITION_OVERLAP && st->mct_chan_mode != MCT_CHAN_MODE_LFE ) { - wtda_ext(hTcxEnc->new_speech_TCX, mdstWin, overlap_mode[frameno], overlap_mode[frameno + 1], L_frameTCX, 3); + wtda_ext( hTcxEnc->new_speech_TCX, mdstWin, overlap_mode[frameno], overlap_mode[frameno + 1], L_frameTCX, 3 ); } else { /* Windowing for the MDST */ - WindowSignal(st->hTcxCfg, st->hTcxCfg->tcx_offsetFB, overlap_mode[frameno] == ALDO_WINDOW ? FULL_OVERLAP : overlap_mode[frameno], overlap_mode[frameno + 1] == ALDO_WINDOW ? FULL_OVERLAP : overlap_mode[frameno + 1], &left_overlap, &right_overlap, &hTcxEnc->speech_TCX[frameno * tcx10SizeFB], &L_subframe, mdstWin, 0, 1); + WindowSignal( st->hTcxCfg, st->hTcxCfg->tcx_offsetFB, overlap_mode[frameno] == ALDO_WINDOW ? FULL_OVERLAP : overlap_mode[frameno], overlap_mode[frameno + 1] == ALDO_WINDOW ? FULL_OVERLAP : overlap_mode[frameno + 1], &left_overlap, &right_overlap, &hTcxEnc->speech_TCX[frameno * tcx10SizeFB], &L_subframe, mdstWin, 0, 1 ); } - if (transform_type[frameno] == TCX_5) + if ( transform_type[frameno] == TCX_5 ) { /* Outer left folding */ - for (i = 0; i < left_overlap / 2; i++) + for ( i = 0; i < left_overlap / 2; i++ ) { mdstWin[left_overlap / 2 + i] += mdstWin[left_overlap / 2 - 1 - i]; } - if (frameno == 0 && overlap_mode[0] == FULL_OVERLAP && L_subframe - left_overlap > minWindowLen) + if ( frameno == 0 && overlap_mode[0] == FULL_OVERLAP && L_subframe - left_overlap > minWindowLen ) { - for (i = minWindowLen; i >= 0; i--) /* outer left folding of shortened long ALDO slope */ + for ( i = minWindowLen; i >= 0; i-- ) /* outer left folding of shortened long ALDO slope */ { mdstWin[left_overlap + i] += hTcxEnc->speech_TCX[-1 - i] * st->hTcxCfg->tcx_aldo_window_1_FB[left_overlap / 2 + minWindowLen - i] * st->hTcxCfg->tcx_mdct_window_minimumFB[minWindowLen - i]; } } /* Outer right folding */ - for (i = 0; i < right_overlap / 2; i++) + for ( i = 0; i < right_overlap / 2; i++ ) { mdstWin[L_subframe + left_overlap / 2 - 1 - i] -= mdstWin[L_subframe + left_overlap / 2 + i]; } @@ -501,115 +507,112 @@ void core_signal_analysis_high_bitrate_fx( L_subframe = tcx5SizeFB; folding_offset = left_overlap / 2; - for (i = 0; i < 2; i++) + for ( i = 0; i < 2; i++ ) { - assert(st->mct_chan_mode != MCT_CHAN_MODE_LFE); - WindowSignal(st->hTcxCfg, folding_offset, i == 0 ? RECTANGULAR_OVERLAP : MIN_OVERLAP, i == 1 ? RECTANGULAR_OVERLAP : MIN_OVERLAP, &left_overlap, &right_overlap, mdstWin + i * tcx5SizeFB, &L_subframe, tcx5Win, 0, 1); + assert( st->mct_chan_mode != MCT_CHAN_MODE_LFE ); + WindowSignal( st->hTcxCfg, folding_offset, i == 0 ? RECTANGULAR_OVERLAP : MIN_OVERLAP, i == 1 ? RECTANGULAR_OVERLAP : MIN_OVERLAP, &left_overlap, &right_overlap, mdstWin + i * tcx5SizeFB, &L_subframe, tcx5Win, 0, 1 ); - TCX_MDST(tcx5Win, mdst_spectrum[frameno] + i * tcx5SizeFB, left_overlap, L_subframe - (left_overlap + right_overlap) / 2, right_overlap, st->element_mode); + TCX_MDST( tcx5Win, mdst_spectrum[frameno] + i * tcx5SizeFB, left_overlap, L_subframe - ( left_overlap + right_overlap ) / 2, right_overlap, st->element_mode ); /* high-band gain control in case of BWS */ - if (st->bwidth_sw_cnt > 0) + if ( st->bwidth_sw_cnt > 0 ) { - v_multc(mdst_spectrum[frameno] + i * tcx5SizeFB + L_FRAME16k / (2 * nSubframes), (float)(st->bwidth_sw_cnt) / (float)BWS_TRAN_PERIOD, mdst_spectrum[frameno] + i * tcx5SizeFB + L_FRAME16k / (2 * nSubframes), L_subframe - L_FRAME16k / (2 * nSubframes)); + v_multc( mdst_spectrum[frameno] + i * tcx5SizeFB + L_FRAME16k / ( 2 * nSubframes ), (float) ( st->bwidth_sw_cnt ) / (float) BWS_TRAN_PERIOD, mdst_spectrum[frameno] + i * tcx5SizeFB + L_FRAME16k / ( 2 * nSubframes ), L_subframe - L_FRAME16k / ( 2 * nSubframes ) ); } } } else /* transform_type[frameno] != TCX_5 */ { - if (transform_type[frameno] == TCX_20 && st->hTcxCfg->tcx_last_overlap_mode != TRANSITION_OVERLAP && st->mct_chan_mode != MCT_CHAN_MODE_LFE) + if ( transform_type[frameno] == TCX_20 && st->hTcxCfg->tcx_last_overlap_mode != TRANSITION_OVERLAP && st->mct_chan_mode != MCT_CHAN_MODE_LFE ) { - edst(mdstWin, mdst_spectrum[frameno], L_subframe, st->element_mode); + edst( mdstWin, mdst_spectrum[frameno], L_subframe, st->element_mode ); - v_multc(mdst_spectrum[frameno], (float)sqrt((float)NORM_MDCT_FACTOR / L_subframe), mdst_spectrum[frameno], L_subframe); + v_multc( mdst_spectrum[frameno], (float) sqrt( (float) NORM_MDCT_FACTOR / L_subframe ), mdst_spectrum[frameno], L_subframe ); } else { - if (frameno == 0 && transform_type[0] == TCX_10 && overlap_mode[0] == FULL_OVERLAP && L_subframe - left_overlap > minWindowLen) + if ( frameno == 0 && transform_type[0] == TCX_10 && overlap_mode[0] == FULL_OVERLAP && L_subframe - left_overlap > minWindowLen ) { - for (i = minWindowLen; i >= 0; i--) /* outer left folding of shortened long ALDO slope */ + for ( i = minWindowLen; i >= 0; i-- ) /* outer left folding of shortened long ALDO slope */ { mdstWin[left_overlap + i] += hTcxEnc->speech_TCX[-1 - i] * st->hTcxCfg->tcx_aldo_window_1_FB[left_overlap / 2 + minWindowLen - i] * st->hTcxCfg->tcx_mdct_window_minimumFB[minWindowLen - i]; } } - TCX_MDST(mdstWin, mdst_spectrum[frameno], left_overlap, L_subframe - (left_overlap + right_overlap) / 2, right_overlap, st->element_mode); + TCX_MDST( mdstWin, mdst_spectrum[frameno], left_overlap, L_subframe - ( left_overlap + right_overlap ) / 2, right_overlap, st->element_mode ); } /* high-band gain control in case of BWS */ - if (st->bwidth_sw_cnt > 0) + if ( st->bwidth_sw_cnt > 0 ) { - v_multc(mdst_spectrum[frameno] + L_FRAME16k / nSubframes, (float)(st->bwidth_sw_cnt) / (float)BWS_TRAN_PERIOD, mdst_spectrum[frameno] + L_FRAME16k / nSubframes, L_subframe - L_FRAME16k / nSubframes); + v_multc( mdst_spectrum[frameno] + L_FRAME16k / nSubframes, (float) ( st->bwidth_sw_cnt ) / (float) BWS_TRAN_PERIOD, mdst_spectrum[frameno] + L_FRAME16k / nSubframes, L_subframe - L_FRAME16k / nSubframes ); } } - if (st->mct_chan_mode == MCT_CHAN_MODE_LFE) + if ( st->mct_chan_mode == MCT_CHAN_MODE_LFE ) { - set_f(&mdst_spectrum[frameno][MCT_LFE_MAX_LINE], 0.f, L_subframe - MCT_LFE_MAX_LINE); + set_f( &mdst_spectrum[frameno][MCT_LFE_MAX_LINE], 0.f, L_subframe - MCT_LFE_MAX_LINE ); } #endif - } - IF(NE_16(st->element_mode, IVAS_CPE_MDCT)) - { - test(); - test(); - TNSAnalysis_fx(st->hTcxCfg, L_frameTCX, - st->hTcxCfg->tcx_coded_lines, - transform_type[frameno], (frameno == 0) && (st->last_core == ACELP_CORE), - spectrum[frameno], &hTcxEnc->tnsData[frameno], &hTcxEnc->fUseTns_fx[frameno], NULL - ); -#ifdef IVAS_CODE - IF (st->hTcxCfg->fIsTNSAllowed) -#endif - { - EncodeTnsData_fx(st->hTcxCfg->pCurrentTnsConfig, &hTcxEnc->tnsData[frameno], - param_core + frameno * NPRM_DIV + 1 + NOISE_FILL_RANGES + LTPSIZE, pTnsSize + frameno, pTnsBits + frameno); } - IF(EQ_16(transform_type[frameno], TCX_5)) + IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { - /* group sub-windows: interleave bins according to their frequencies */ - FOR(i = 0; i < tcx5SizeFB; i++) + test(); + test(); + TNSAnalysis_fx( st->hTcxCfg, L_frameTCX, + st->hTcxCfg->tcx_coded_lines, + transform_type[frameno], ( frameno == 0 ) && ( st->last_core == ACELP_CORE ), + spectrum[frameno], &hTcxEnc->tnsData[frameno], &hTcxEnc->fUseTns_fx[frameno], NULL ); +#ifdef IVAS_CODE + IF( st->hTcxCfg->fIsTNSAllowed ) +#endif { - interleaveBuf[2 * i] = spectrum[frameno][i]; - move32(); - interleaveBuf[2 * i + 1] = spectrum[frameno][tcx5SizeFB + i]; - move32(); + EncodeTnsData_fx( st->hTcxCfg->pCurrentTnsConfig, &hTcxEnc->tnsData[frameno], + param_core + frameno * NPRM_DIV + 1 + NOISE_FILL_RANGES + LTPSIZE, pTnsSize + frameno, pTnsBits + frameno ); + } + IF( EQ_16( transform_type[frameno], TCX_5 ) ) + { + /* group sub-windows: interleave bins according to their frequencies */ + FOR( i = 0; i < tcx5SizeFB; i++ ) + { + interleaveBuf[2 * i] = spectrum[frameno][i]; + move32(); + interleaveBuf[2 * i + 1] = spectrum[frameno][tcx5SizeFB + i]; + move32(); + } + Copy32( interleaveBuf, spectrum[frameno], tcx10SizeFB ); } - Copy32(interleaveBuf, spectrum[frameno], tcx10SizeFB); - } - /*--------------------------------------------------------------* - * LPC analysis - *---------------------------------------------------------------*/ + /*--------------------------------------------------------------* + * LPC analysis + *---------------------------------------------------------------*/ #ifdef IVAS_CODE - IF(st->tcxonly) + IF( st->tcxonly ) #endif - { - HBAutocorrelation_fx(st->hTcxCfg, lpc_left_overlap_mode, lpc_right_overlap_mode, &st->speech_enc_pe[frameno * tcx10Size], - shr(L_frame, sub(nSubframes, 1)), r, M); - - FOR(i = 0; i <= M; i++) { - move16(); - move16(); - r_l[frameno][i] = L_Extract_lc(r[i], &r_h[frameno][i]); - } + HBAutocorrelation_fx( st->hTcxCfg, lpc_left_overlap_mode, lpc_right_overlap_mode, &st->speech_enc_pe[frameno * tcx10Size], + shr( L_frame, sub( nSubframes, 1 ) ), r, M ); - adapt_lag_wind(r_h[frameno], r_l[frameno], M, alw_pitch_lag_12k8[frameno], alw_voicing[frameno], st->sr_core); + FOR( i = 0; i <= M; i++ ) + { + move16(); + move16(); + r_l[frameno][i] = L_Extract_lc( r[i], &r_h[frameno][i] ); + } - E_LPC_lev_dur(r_h[frameno], r_l[frameno], A, epsP, M, NULL); + adapt_lag_wind( r_h[frameno], r_l[frameno], M, alw_pitch_lag_12k8[frameno], alw_voicing[frameno], st->sr_core ); - E_LPC_a_lsp_conversion(A, lsp[nSubframes - 1 - frameno], st->lspold_enc_fx, M); - } - IF(st->igf) - { - ProcessIGF_fx(st->hIGFEnc, st, spectrum[frameno], &(spectrum_e[frameno]), powerSpec, &powerSpec_e, transform_type[frameno] == TCX_20, hTcxEnc->fUseTns_fx[frameno], (st->last_core == ACELP_CORE), frameno); - } + E_LPC_lev_dur( r_h[frameno], r_l[frameno], A, epsP, M, NULL ); + + E_LPC_a_lsp_conversion( A, lsp[nSubframes - 1 - frameno], st->lspold_enc_fx, M ); + } + IF( st->igf ) + { + ProcessIGF_fx( st->hIGFEnc, st, spectrum[frameno], &( spectrum_e[frameno] ), powerSpec, &powerSpec_e, transform_type[frameno] == TCX_20, hTcxEnc->fUseTns_fx[frameno], ( st->last_core == ACELP_CORE ), frameno ); + } - /* Copy memory */ - mvr2r_Word16(lsp_new, st->lspold_enc_fx, M); + /* Copy memory */ + mvr2r_Word16( lsp_new, st->lspold_enc_fx, M ); + } } } - -} - diff --git a/lib_enc/fd_cng_enc.c b/lib_enc/fd_cng_enc.c index 71197decb..fad93012f 100644 --- a/lib_enc/fd_cng_enc.c +++ b/lib_enc/fd_cng_enc.c @@ -275,7 +275,7 @@ void deleteFdCngEnc( HANDLE_FD_CNG_ENC hsEnc = *hFdCngEnc; - IF ( hsEnc != NULL ) + IF( hsEnc != NULL ) { deleteFdCngCom_flt( &( hsEnc->hFdCngCom ) ); free( hsEnc ); @@ -426,7 +426,7 @@ void perform_noise_estimation_enc( /* Call the minimum statistics routine for noise estimation */ minimum_statistics_flt( npart, nFFTpart, psize_flt, msLogPeriodog, hFdCngEnc->msNoiseFloor, msLogNoiseEst, hFdCngEnc->msAlpha, hFdCngEnc->msPsd, hFdCngEnc->msPsdFirstMoment, hFdCngEnc->msPsdSecondMoment, hFdCngEnc->msMinBuf, hFdCngEnc->msBminWin, hFdCngEnc->msBminSubWin, hFdCngEnc->msCurrentMin, hFdCngEnc->msCurrentMinOut, hFdCngEnc->msCurrentMinSubWindow, hFdCngEnc->msLocalMinFlag, hFdCngEnc->msNewMinFlag, hFdCngEnc->msPeriodogBuf, &( hFdCngEnc->msPeriodogBufPtr ), hFdCngEnc->hFdCngCom, - ENC, ( hCPE == NULL ) ? 0 : hCPE->element_mode ); + ENC, ( hCPE == NULL ) ? 0 : hCPE->element_mode ); /* Expand MS outputs */ expand_range_flt( msLogNoiseEst, msNoiseEst, npart ); @@ -569,8 +569,8 @@ void FdCng_encodeSID( } else { /* EVS_MONO tables */ - msvq_enc(cdk_37bits_flt, NULL, NULL, v, levels_37bits, FD_CNG_maxC_37bits, FD_CNG_stages_37bits, w, N, FD_CNG_maxN_37bits, 0, NULL, indices ); - msvq_dec_float(cdk_37bits_flt, NULL, NULL, FD_CNG_stages_37bits, N, FD_CNG_maxN_37bits, indices, 0, NULL, v, NULL ); + msvq_enc( cdk_37bits_flt, NULL, NULL, v, levels_37bits, FD_CNG_maxC_37bits, FD_CNG_stages_37bits, w, N, FD_CNG_maxN_37bits, 0, NULL, indices ); + msvq_dec_float( cdk_37bits_flt, NULL, NULL, FD_CNG_stages_37bits, N, FD_CNG_maxN_37bits, indices, 0, NULL, v, NULL ); } @@ -753,7 +753,7 @@ void generate_comfort_noise_enc( if ( st->last_core > ACELP_CORE ) { tcx_windowing_synthesis_current_frame_flt( timeDomainOutput, st->hTcxCfg->tcx_mdct_window_flt, /*Keep sine windows for limiting Time modulation*/ - st->hTcxCfg->tcx_mdct_window_half_flt, st->hTcxCfg->tcx_mdct_window_minimum_flt, st->hTcxCfg->tcx_mdct_window_length, st->hTcxCfg->tcx_mdct_window_half_length, st->hTcxCfg->tcx_mdct_window_min_length, 0, st->hTcxCfg->tcx_last_overlap_mode == ALDO_WINDOW ? FULL_OVERLAP : st->hTcxCfg->tcx_last_overlap_mode, NULL, NULL, NULL, NULL, NULL, N / 2, st->hTcxCfg->tcx_offset < 0 ? -st->hTcxCfg->tcx_offset : 0, 1, 0, 0 ); + st->hTcxCfg->tcx_mdct_window_half_flt, st->hTcxCfg->tcx_mdct_window_minimum_flt, st->hTcxCfg->tcx_mdct_window_length, st->hTcxCfg->tcx_mdct_window_half_length, st->hTcxCfg->tcx_mdct_window_min_length, 0, st->hTcxCfg->tcx_last_overlap_mode == ALDO_WINDOW ? FULL_OVERLAP : st->hTcxCfg->tcx_last_overlap_mode, NULL, NULL, NULL, NULL, NULL, N / 2, st->hTcxCfg->tcx_offset < 0 ? -st->hTcxCfg->tcx_offset : 0, 1, 0, 0 ); if ( st->hTcxCfg->last_aldo ) { @@ -1160,7 +1160,7 @@ void FdCngEncodeMDCTStereoSID( /* scale bands and get scalefactors */ scalebands_flt( lr_out_ptr[ch], hFdCngEnc->partDec, N, hFdCngEnc->midbandDec, hFdCngEnc->nFFTpartDec, hFdCngEnc->stopBandDec - hFdCngEnc->startBandDec, hFdCngCom->cngNoiseLevel_flt, 1 ); - lpc_from_spectrum_flt( hFdCngCom, hFdCngEnc->startBandDec, hFdCngEnc->stopFFTbinDec, sts[ch]->preemph_fac_flt); + lpc_from_spectrum_flt( hFdCngCom, hFdCngEnc->startBandDec, hFdCngEnc->stopFFTbinDec, sts[ch]->preemph_fac_flt ); sts[ch]->hDtxEnc->last_CNG_L_frame = sts[ch]->L_frame; } @@ -1335,7 +1335,7 @@ void FdCngEncodeDiracMDCTStereoSID( /* scale bands and get scalefactors */ scalebands_flt( lr_out_ptr[ch], hFdCngEnc->partDec, N[ch], hFdCngEnc->midbandDec, hFdCngEnc->nFFTpartDec, hFdCngEnc->stopBandDec - hFdCngEnc->startBandDec, hFdCngCom->cngNoiseLevel_flt, 1 ); - lpc_from_spectrum_flt( hFdCngCom, hFdCngEnc->startBandDec, hFdCngEnc->stopFFTbinDec, sts[ch]->preemph_fac_flt); + lpc_from_spectrum_flt( hFdCngCom, hFdCngEnc->startBandDec, hFdCngEnc->stopFFTbinDec, sts[ch]->preemph_fac_flt ); sts[ch]->hDtxEnc->last_CNG_L_frame = sts[ch]->L_frame; } diff --git a/lib_enc/fd_cng_enc_fx.c b/lib_enc/fd_cng_enc_fx.c index 83b4a1b38..410cec202 100644 --- a/lib_enc/fd_cng_enc_fx.c +++ b/lib_enc/fd_cng_enc_fx.c @@ -12,7 +12,7 @@ #include "rom_com.h" #include "rom_enc.h" //#include "prot_fx.h" -#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ #include "prot_fx2.h" #include "prot_fx_enc.h" #include "basop_util.h" @@ -20,32 +20,38 @@ /******************************** -* External functions * -********************************/ + * External functions * + ********************************/ #ifndef swap - #define swap(x,y,type) {type u__p; u__p=x; x=y; y=u__p;} +#define swap( x, y, type ) \ + { \ + type u__p; \ + u__p = x; \ + x = y; \ + y = u__p; \ + } #endif /************************************* -* Create an instance of type FD_CNG * -*************************************/ -void createFdCngEnc_fx(HANDLE_FD_CNG_ENC* hFdCngEnc) + * Create an instance of type FD_CNG * + *************************************/ +void createFdCngEnc_fx( HANDLE_FD_CNG_ENC *hFdCngEnc ) { HANDLE_FD_CNG_ENC hs; /* Allocate memory */ - hs = (HANDLE_FD_CNG_ENC) calloc(1, sizeof (FD_CNG_ENC)); + hs = (HANDLE_FD_CNG_ENC) calloc( 1, sizeof( FD_CNG_ENC ) ); move16(); - createFdCngCom(&(hs->hFdCngCom)); + createFdCngCom( &( hs->hFdCngCom ) ); *hFdCngEnc = hs; move16(); return; } -void initFdCngEnc_fx(HANDLE_FD_CNG_ENC hsEnc, Word32 input_Fs, Word16 scale) +void initFdCngEnc_fx( HANDLE_FD_CNG_ENC hsEnc, Word32 input_Fs, Word16 scale ) { Word16 j; HANDLE_FD_CNG_COM hsCom = hsEnc->hFdCngCom; @@ -56,12 +62,12 @@ void initFdCngEnc_fx(HANDLE_FD_CNG_ENC hsEnc, Word32 input_Fs, Word16 scale) /* Configure the Noise Estimator */ - hsCom->numSlots = 16; + hsCom->numSlots = 16; move16(); - hsCom->numCoreBands = 16; + hsCom->numCoreBands = 16; move16(); - hsCom->regularStopBand = idiv1616U( extract_l( L_shr( input_Fs, 5 ) ), 25 ); - if ( GT_16( hsCom->regularStopBand, 40 )) + hsCom->regularStopBand = idiv1616U( extract_l( L_shr( input_Fs, 5 ) ), 25 ); + if ( GT_16( hsCom->regularStopBand, 40 ) ) { hsCom->regularStopBand = 40; move16(); @@ -69,7 +75,7 @@ void initFdCngEnc_fx(HANDLE_FD_CNG_ENC hsEnc, Word32 input_Fs, Word16 scale) hsCom->startBand = 2; move16(); - IF ( EQ_16( hsCom->regularStopBand, 10 )) + IF( EQ_16( hsCom->regularStopBand, 10 ) ) { hsCom->stopFFTbin = 160; move16(); @@ -87,13 +93,13 @@ void initFdCngEnc_fx(HANDLE_FD_CNG_ENC hsEnc, Word32 input_Fs, Word16 scale) move16(); } - initPartitions( sidparts_encoder_noise_est, 24, hsCom->startBand, hsCom->stopBand, hsCom->part, &hsCom->npart, hsCom->midband, hsCom->psize, hsCom->psize_norm, &hsCom->psize_norm_exp, hsCom->psize_inv, 0); + initPartitions( sidparts_encoder_noise_est, 24, hsCom->startBand, hsCom->stopBand, hsCom->part, &hsCom->npart, hsCom->midband, hsCom->psize, hsCom->psize_norm, &hsCom->psize_norm_exp, hsCom->psize_inv, 0 ); hsCom->nCLDFBpart = sub( hsCom->npart, hsCom->nFFTpart ); - FOR(j=0; jnCLDFBpart; j++) + FOR( j = 0; j < hsCom->nCLDFBpart; j++ ) { - hsCom->CLDFBpart[j] = sub( hsCom->part[j+hsCom->nFFTpart], sub( 256, hsCom->startBand ) ); - hsCom->CLDFBpsize_inv[j] = hsCom->psize_inv[j+hsCom->nFFTpart]; + hsCom->CLDFBpart[j] = sub( hsCom->part[j + hsCom->nFFTpart], sub( 256, hsCom->startBand ) ); + hsCom->CLDFBpsize_inv[j] = hsCom->psize_inv[j + hsCom->nFFTpart]; } /* Initialize noise estimation algorithm */ @@ -116,12 +122,12 @@ void initFdCngEnc_fx(HANDLE_FD_CNG_ENC hsEnc, Word32 input_Fs, Word16 scale) set16_fx( hsEnc->msLogNoiseEst_fx, 0, NPART ); set16_fx( hsEnc->msPsd_fx, 0, NPART ); set16_fx( hsEnc->msNoiseFloor_fx, 0, NPART ); - set32_fx( hsEnc->msMinBuf_fx, 2147483647l/*1.0 Q31*/, MSNUMSUBFR*NPART ); - set32_fx( hsEnc->msCurrentMin_fx, 2147483647l/*1.0 Q31*/, NPART ); - set32_fx( hsEnc->msCurrentMinOut_fx, 2147483647l/*1.0 Q31*/, NPART ); - set32_fx( hsEnc->msCurrentMinSubWindow_fx, 2147483647l/*1.0 Q31*/, NPART ); + set32_fx( hsEnc->msMinBuf_fx, 2147483647l /*1.0 Q31*/, MSNUMSUBFR * NPART ); + set32_fx( hsEnc->msCurrentMin_fx, 2147483647l /*1.0 Q31*/, NPART ); + set32_fx( hsEnc->msCurrentMinOut_fx, 2147483647l /*1.0 Q31*/, NPART ); + set32_fx( hsEnc->msCurrentMinSubWindow_fx, 2147483647l /*1.0 Q31*/, NPART ); set16_fx( hsEnc->msPsdFirstMoment_fx, 0, NPART ); - set16_fx( hsEnc->msPeriodogBuf_fx, 0, MSBUFLEN*NPART ); + set16_fx( hsEnc->msPeriodogBuf_fx, 0, MSBUFLEN * NPART ); set16_fx( hsEnc->msLocalMinFlag, 0, NPART ); set16_fx( hsEnc->msNewMinFlag, 0, NPART ); @@ -134,24 +140,23 @@ void initFdCngEnc_fx(HANDLE_FD_CNG_ENC hsEnc, Word32 input_Fs, Word16 scale) } /************************************ -* Configure FD_CNG * -************************************/ -void configureFdCngEnc_fx(HANDLE_FD_CNG_ENC hsEnc, /* i/o: Contains the variables related to the FD-based CNG process */ - Word16 bandwidth, /* i: bandwidth */ - Word32 bitrate - ) + * Configure FD_CNG * + ************************************/ +void configureFdCngEnc_fx( HANDLE_FD_CNG_ENC hsEnc, /* i/o: Contains the variables related to the FD-based CNG process */ + Word16 bandwidth, /* i: bandwidth */ + Word32 bitrate ) { HANDLE_FD_CNG_COM hsCom = hsEnc->hFdCngCom; - Word16 psizeDec[NPART]; - Word16 psizeDec_norm[NPART]; - Word16 psizeDec_norm_exp; - Word16 psize_invDec[NPART]; + Word16 psizeDec[NPART]; + Word16 psizeDec_norm[NPART]; + Word16 psizeDec_norm_exp; + Word16 psize_invDec[NPART]; - set16_fx(psizeDec, 0, NPART); + set16_fx( psizeDec, 0, NPART ); hsCom->CngBandwidth = bandwidth; move16(); - IF ( EQ_16( hsCom->CngBandwidth, FB )) + IF( EQ_16( hsCom->CngBandwidth, FB ) ) { hsCom->CngBandwidth = SWB; } @@ -159,21 +164,21 @@ void configureFdCngEnc_fx(HANDLE_FD_CNG_ENC hsEnc, /* i/o: Contains the variab move32(); /* NB configuration */ - IF ( EQ_16(bandwidth,NB)) + IF( EQ_16( bandwidth, NB ) ) { - hsCom->FdCngSetup = FdCngSetup_nb; /* PTR assignation -> no move needed*/ + hsCom->FdCngSetup = FdCngSetup_nb; /* PTR assignation -> no move needed*/ } /* WB configuration */ - ELSE IF ( EQ_16(bandwidth,WB)) + ELSE IF( EQ_16( bandwidth, WB ) ) { /* FFT 6.4kHz, no CLDFB */ - IF ( LE_32(bitrate,ACELP_8k00)) + IF( LE_32( bitrate, ACELP_8k00 ) ) { hsCom->FdCngSetup = FdCngSetup_wb1; } /* FFT 6.4kHz, CLDFB 8.0kHz */ - ELSE IF ( LE_32(bitrate,ACELP_13k20)) + ELSE IF( LE_32( bitrate, ACELP_13k20 ) ) { hsCom->FdCngSetup = FdCngSetup_wb2; } @@ -188,7 +193,7 @@ void configureFdCngEnc_fx(HANDLE_FD_CNG_ENC hsEnc, /* i/o: Contains the variab ELSE { /* FFT 6.4kHz, CLDFB 14kHz */ - IF ( LE_32(bitrate,ACELP_13k20)) + IF( LE_32( bitrate, ACELP_13k20 ) ) { hsCom->FdCngSetup = FdCngSetup_swb1; } @@ -207,7 +212,7 @@ void configureFdCngEnc_fx(HANDLE_FD_CNG_ENC hsEnc, /* i/o: Contains the variab hsEnc->startBandDec = hsCom->startBand; move16(); - hsEnc->stopBandDec = add( hsCom->FdCngSetup.sidPartitions[hsCom->FdCngSetup.numPartitions-1], 1 ); + hsEnc->stopBandDec = add( hsCom->FdCngSetup.sidPartitions[hsCom->FdCngSetup.numPartitions - 1], 1 ); move16(); initPartitions( hsCom->FdCngSetup.sidPartitions, hsCom->FdCngSetup.numPartitions, @@ -220,14 +225,13 @@ void configureFdCngEnc_fx(HANDLE_FD_CNG_ENC hsEnc, /* i/o: Contains the variab psizeDec_norm, &psizeDec_norm_exp, psize_invDec, - 0 - ); - IF ( EQ_16(hsEnc->stopFFTbinDec,160)) + 0 ); + IF( EQ_16( hsEnc->stopFFTbinDec, 160 ) ) { hsEnc->nFFTpartDec = 17; move16(); } - ELSE IF ( EQ_16(hsEnc->stopFFTbinDec,256)) + ELSE IF( EQ_16( hsEnc->stopFFTbinDec, 256 ) ) { hsEnc->nFFTpartDec = 20; move16(); @@ -238,43 +242,42 @@ void configureFdCngEnc_fx(HANDLE_FD_CNG_ENC hsEnc, /* i/o: Contains the variab move16(); } - SWITCH (hsCom->fftlen) + SWITCH( hsCom->fftlen ) { - case 512: - hsCom->fftlenShift = 8; - move16(); - hsCom->fftlenFac = 32767/*1.0 Q15*/; - move16(); - BREAK; - case 640: - hsCom->fftlenShift = 9; - move16(); - hsCom->fftlenFac = 20480/*0.625 Q15*/; - move16(); - BREAK; - default: - assert(!"Unsupported FFT length for FD-based CNG"); - BREAK; + case 512: + hsCom->fftlenShift = 8; + move16(); + hsCom->fftlenFac = 32767 /*1.0 Q15*/; + move16(); + BREAK; + case 640: + hsCom->fftlenShift = 9; + move16(); + hsCom->fftlenFac = 20480 /*0.625 Q15*/; + move16(); + BREAK; + default: + assert( !"Unsupported FFT length for FD-based CNG" ); + BREAK; } - BASOP_getTables( &hsCom->olapWinAna, NULL, NULL, shr(hsCom->fftlen, 1)); - BASOP_getTables( &hsCom->olapWinSyn, NULL, NULL, shr(hsCom->fftlen, 2)); + BASOP_getTables( &hsCom->olapWinAna, NULL, NULL, shr( hsCom->fftlen, 1 ) ); + BASOP_getTables( &hsCom->olapWinSyn, NULL, NULL, shr( hsCom->fftlen, 2 ) ); hsCom->frameSize = shr( hsCom->fftlen, 1 ); - } /************************************** -* Delete the instance of type FD_CNG * -**************************************/ -void deleteFdCngEnc_fx(HANDLE_FD_CNG_ENC * hFdCngEnc) + * Delete the instance of type FD_CNG * + **************************************/ +void deleteFdCngEnc_fx( HANDLE_FD_CNG_ENC *hFdCngEnc ) { HANDLE_FD_CNG_ENC hsEnc; hsEnc = *hFdCngEnc; move16(); - IF (hsEnc != NULL) + IF( hsEnc != NULL ) { - deleteFdCngCom(&(hsEnc->hFdCngCom)); - free(hsEnc); + deleteFdCngCom( &( hsEnc->hFdCngCom ) ); + free( hsEnc ); *hFdCngEnc = NULL; move16(); } @@ -282,38 +285,37 @@ void deleteFdCngEnc_fx(HANDLE_FD_CNG_ENC * hFdCngEnc) void resetFdCngEnc_fx( - Encoder_State * st -) + Encoder_State *st ) { Word16 tmpTest; Word16 n; Word16 totalNoiseIncrease; - Word16 thresh = 5 * 256; /* 5.0 in Q8 */ + Word16 thresh = 5 * 256; /* 5.0 in Q8 */ NOISE_EST_HANDLE hNoiseEst = st->hNoiseEst; /* st->totalNoise_fx; Q8 Noise estimator - total noise energy */ /* Detect fast increase of totalNoise */ - totalNoiseIncrease = sub(hNoiseEst->totalNoise_fx, st->last_totalNoise_fx); + totalNoiseIncrease = sub( hNoiseEst->totalNoise_fx, st->last_totalNoise_fx ); st->last_totalNoise_fx = hNoiseEst->totalNoise_fx; move16(); - IF ( totalNoiseIncrease > 0 ) + IF( totalNoiseIncrease > 0 ) { - IF ( EQ_16(st->totalNoise_increase_len,TOTALNOISE_HIST_SIZE)) + IF( EQ_16( st->totalNoise_increase_len, TOTALNOISE_HIST_SIZE ) ) { - FOR ( n = 0; n < TOTALNOISE_HIST_SIZE-1; n++ ) + FOR( n = 0; n < TOTALNOISE_HIST_SIZE - 1; n++ ) { - st->totalNoise_increase_hist_fx[n] = st->totalNoise_increase_hist_fx[n+1]; + st->totalNoise_increase_hist_fx[n] = st->totalNoise_increase_hist_fx[n + 1]; move16(); } - st->totalNoise_increase_hist_fx[TOTALNOISE_HIST_SIZE-1] = totalNoiseIncrease; + st->totalNoise_increase_hist_fx[TOTALNOISE_HIST_SIZE - 1] = totalNoiseIncrease; move16(); } ELSE { st->totalNoise_increase_hist_fx[st->totalNoise_increase_len] = totalNoiseIncrease; move16(); - st->totalNoise_increase_len = add(st->totalNoise_increase_len, 1); + st->totalNoise_increase_len = add( st->totalNoise_increase_len, 1 ); } } ELSE @@ -323,17 +325,17 @@ void resetFdCngEnc_fx( } totalNoiseIncrease = 0; move16(); - FOR ( n = 0; n < st->totalNoise_increase_len; n++ ) + FOR( n = 0; n < st->totalNoise_increase_len; n++ ) { - totalNoiseIncrease = add(totalNoiseIncrease, st->totalNoise_increase_hist_fx[n]); + totalNoiseIncrease = add( totalNoiseIncrease, st->totalNoise_increase_hist_fx[n] ); } test(); test(); - tmpTest = ((GT_16 (totalNoiseIncrease,thresh) ) && (EQ_16(st->totalNoise_increase_len,TOTALNOISE_HIST_SIZE)) && (GT_16(st->ini_frame,150)) ); + tmpTest = ( ( GT_16( totalNoiseIncrease, thresh ) ) && ( EQ_16( st->totalNoise_increase_len, TOTALNOISE_HIST_SIZE ) ) && ( GT_16( st->ini_frame, 150 ) ) ); test(); - IF ( tmpTest || ( GT_16(st->input_bwidth,st->last_input_bwidth) ) || EQ_16(st->last_core,AMR_WB_CORE)) + IF( tmpTest || ( GT_16( st->input_bwidth, st->last_input_bwidth ) ) || EQ_16( st->last_core, AMR_WB_CORE ) ) { st->fd_cng_reset_flag = 1; move16(); @@ -342,9 +344,9 @@ void resetFdCngEnc_fx( st->hFdCngEnc->hFdCngCom->init_old = 32767; move16(); } - ELSE IF ( s_and((st->fd_cng_reset_flag > 0),(Word16)(LT_16(st->fd_cng_reset_flag,10)))) + ELSE IF( s_and( ( st->fd_cng_reset_flag > 0 ), (Word16) ( LT_16( st->fd_cng_reset_flag, 10 ) ) ) ) { - st->fd_cng_reset_flag = add(st->fd_cng_reset_flag,1); + st->fd_cng_reset_flag = add( st->fd_cng_reset_flag, 1 ); } ELSE { @@ -372,27 +374,26 @@ void resetFdCngEnc_fx( Returns: void */ -void perform_noise_estimation_enc_fx(Word32 *band_energies, /* i: energy in critical bands without minimum noise floor MODE2_E_MIN */ - Word16 band_energies_exp, /* i: exponent for energy in critical bands without minimum noise floor MODE2_E_MIN */ - Word32 *enerBuffer, - Word16 enerBuffer_exp, - HANDLE_FD_CNG_ENC st /* i/o: FD_CNG structure containing all buffers and variables */ - ) +void perform_noise_estimation_enc_fx( Word32 *band_energies, /* i: energy in critical bands without minimum noise floor MODE2_E_MIN */ + Word16 band_energies_exp, /* i: exponent for energy in critical bands without minimum noise floor MODE2_E_MIN */ + Word32 *enerBuffer, + Word16 enerBuffer_exp, + HANDLE_FD_CNG_ENC st /* i/o: FD_CNG structure containing all buffers and variables */ +) { - Word16 i, j, s, s1, s2; - Word16 nFFTpart; - Word16 nCLDFBpart; - Word16 numBands; - Word16 numCoreBands; - Word16 regularStopBand; - Word16 numSlots; - Word32 tmp; + Word16 i, j, s, s1, s2; + Word16 nFFTpart; + Word16 nCLDFBpart; + Word16 numBands; + Word16 numCoreBands; + Word16 regularStopBand; + Word16 numSlots; + Word32 tmp; Word32 *periodog; Word32 *ptr_per; Word32 *msPeriodog; - nFFTpart = st->hFdCngCom->nFFTpart; move16(); nCLDFBpart = st->hFdCngCom->nCLDFBpart; @@ -410,39 +411,39 @@ void perform_noise_estimation_enc_fx(Word32 *band_energies, /* i: energy msPeriodog = st->msPeriodog_fx; move16(); - assert(numSlots == 16); + assert( numSlots == 16 ); /* preemphasis compensation and grouping of per bin energies into msPeriodog */ - FOR (i=0; i < nFFTpart; i++) + FOR( i = 0; i < nFFTpart; i++ ) { - tmp = L_add(L_shr(band_energies[i], 1), L_shr(band_energies[i+NB_BANDS], 1)); - msPeriodog[i] = Mpy_32_16_1(tmp, preemphCompensation_fx[i]); + tmp = L_add( L_shr( band_energies[i], 1 ), L_shr( band_energies[i + NB_BANDS], 1 ) ); + msPeriodog[i] = Mpy_32_16_1( tmp, preemphCompensation_fx[i] ); move32(); } /* exponent for fft part of msPeriodog */ - st->msPeriodog_fx_exp_fft = add(band_energies_exp, PREEMPH_COMPENSATION_EXP); + st->msPeriodog_fx_exp_fft = add( band_energies_exp, PREEMPH_COMPENSATION_EXP ); move16(); - numBands = sub(regularStopBand, numCoreBands); + numBands = sub( regularStopBand, numCoreBands ); - IF ( numBands > 0 ) + IF( numBands > 0 ) { /* Adjust to the desired time resolution by averaging the periodograms over the CLDFB time slots */ - FOR (j=numCoreBands; j < regularStopBand; j++) + FOR( j = numCoreBands; j < regularStopBand; j++ ) { - *ptr_per = Mpy_32_16_1(enerBuffer[j], st->hFdCngCom->scalingFactor); + *ptr_per = Mpy_32_16_1( enerBuffer[j], st->hFdCngCom->scalingFactor ); move32(); ptr_per++; } /* exponent for cldfb part of msPeriodog */ - st->hFdCngCom->exp_cldfb_periodog = add( sub(enerBuffer_exp, 4), CLDFBscalingFactor_EXP ); + st->hFdCngCom->exp_cldfb_periodog = add( sub( enerBuffer_exp, 4 ), CLDFBscalingFactor_EXP ); /* Adjust CLDFB filterbank to the desired frequency resolution by averaging over spectral partitions for SID transmission */ - bandcombinepow ( + bandcombinepow( periodog, st->hFdCngCom->exp_cldfb_periodog, numBands, @@ -450,31 +451,30 @@ void perform_noise_estimation_enc_fx(Word32 *band_energies, /* i: energy st->hFdCngCom->nCLDFBpart, st->hFdCngCom->CLDFBpsize_inv, &msPeriodog[nFFTpart], - &st->msPeriodog_fx_exp_cldfb - ); + &st->msPeriodog_fx_exp_cldfb ); /* find common exponent for fft part and cldfb part of msperiodog */ - s1 = getScaleFactor32 (msPeriodog,nFFTpart); - s2 = getScaleFactor32 (&msPeriodog[nFFTpart],nCLDFBpart); + s1 = getScaleFactor32( msPeriodog, nFFTpart ); + s2 = getScaleFactor32( &msPeriodog[nFFTpart], nCLDFBpart ); - s = s_max(sub(st->msPeriodog_fx_exp_fft,s1), sub(st->msPeriodog_fx_exp_cldfb,s2)); - s1 = sub(s,st->msPeriodog_fx_exp_fft); - s2 = sub(s,st->msPeriodog_fx_exp_cldfb); + s = s_max( sub( st->msPeriodog_fx_exp_fft, s1 ), sub( st->msPeriodog_fx_exp_cldfb, s2 ) ); + s1 = sub( s, st->msPeriodog_fx_exp_fft ); + s2 = sub( s, st->msPeriodog_fx_exp_cldfb ); st->msPeriodog_fx_exp_fft = s; move16(); st->msPeriodog_fx_exp_cldfb = s; move16(); - FOR (i=0; i < nFFTpart; i++) + FOR( i = 0; i < nFFTpart; i++ ) { - msPeriodog[i] = L_shr(msPeriodog[i],s1); + msPeriodog[i] = L_shr( msPeriodog[i], s1 ); move32(); } - FOR (i=0; i < nCLDFBpart; i++) + FOR( i = 0; i < nCLDFBpart; i++ ) { - msPeriodog[nFFTpart+i] = L_shr(msPeriodog[nFFTpart+i],s_min(31,s2)); + msPeriodog[nFFTpart + i] = L_shr( msPeriodog[nFFTpart + i], s_min( 31, s2 ) ); move32(); } } @@ -484,10 +484,10 @@ void perform_noise_estimation_enc_fx(Word32 *band_energies, /* i: energy move16(); /* Compress MS inputs */ - compress_range(st->msPeriodog_fx, st->msPeriodog_fx_exp, st->msLogPeriodog_fx, st->hFdCngCom->npart); + compress_range( st->msPeriodog_fx, st->msPeriodog_fx_exp, st->msLogPeriodog_fx, st->hFdCngCom->npart ); /* Call the minimum statistics routine for noise estimation */ - minimum_statistics ( + minimum_statistics( st->hFdCngCom->npart, st->hFdCngCom->nFFTpart, st->hFdCngCom->psize_norm, @@ -507,14 +507,11 @@ void perform_noise_estimation_enc_fx(Word32 *band_energies, /* i: energy st->msLocalMinFlag, st->msNewMinFlag, st->msPeriodogBuf_fx, - &(st->msPeriodogBufPtr), - st->hFdCngCom - ); + &( st->msPeriodogBufPtr ), + st->hFdCngCom ); /* Expand MS outputs */ - expand_range(st->msLogNoiseEst_fx, st->msNoiseEst_fx, &st->msNoiseEst_fx_exp, st->hFdCngCom->npart); - - + expand_range( st->msLogNoiseEst_fx, st->msNoiseEst_fx, &st->msNoiseEst_fx_exp, st->hFdCngCom->npart ); } /* @@ -542,35 +539,35 @@ void perform_noise_estimation_enc_fx(Word32 *band_energies, /* i: energy */ Word16 AdjustFirstSID_fx( - Word16 npart, /* i : number of parts */ - Word32 *msPeriodog, /* i : pointer to periodog vector */ - Word16 msPeriodog_exp, /* i : exponent of periodog vector */ - Word32 *energy_ho, /* i/o : pointer to energy */ - Word16 *energy_ho_exp, /* i/o : pointer to exponent of energy */ - Word32 *msNoiseEst, /* i/o : pointer to estimated noise */ - Word16 *msNoiseEst_exp, /* i/o : pointer to exponent of estimated noise */ - Word32 *msNoiseEst_old, /* i/o : pointer to old estimated noise */ - Word16 *msNoiseEst_old_exp, /* i/o : pointer to exponent of old estimated noise */ - Word16 *active_frame_counter, /* i/o : pointer to active frame counter */ + Word16 npart, /* i : number of parts */ + Word32 *msPeriodog, /* i : pointer to periodog vector */ + Word16 msPeriodog_exp, /* i : exponent of periodog vector */ + Word32 *energy_ho, /* i/o : pointer to energy */ + Word16 *energy_ho_exp, /* i/o : pointer to exponent of energy */ + Word32 *msNoiseEst, /* i/o : pointer to estimated noise */ + Word16 *msNoiseEst_exp, /* i/o : pointer to exponent of estimated noise */ + Word32 *msNoiseEst_old, /* i/o : pointer to old estimated noise */ + Word16 *msNoiseEst_old_exp, /* i/o : pointer to exponent of old estimated noise */ + Word16 *active_frame_counter, /* i/o : pointer to active frame counter */ Encoder_State *stcod /* i : pointer to Coder_State_Plus structure */ ) { Word16 i, sc, s1, s2, lambda, lambdaM1, invFac; Word32 tmp32, energy_ho_local, msNoiseEst_local; - DTX_ENC_HANDLE hDtxEnc = stcod->hDtxEnc; + DTX_ENC_HANDLE hDtxEnc = stcod->hDtxEnc; test(); - IF ( EQ_16(hDtxEnc->cnt_SID,1)&>_32(stcod->last_core_brate,SID_2k40)) + IF( EQ_16( hDtxEnc->cnt_SID, 1 ) && GT_32( stcod->last_core_brate, SID_2k40 ) ) { /* Detect the hangover period and the first SID frame at the beginning of each CNG phase */ /* First hangover frame */ - Copy32 (msPeriodog, energy_ho, npart); + Copy32( msPeriodog, energy_ho, npart ); *energy_ho_exp = msPeriodog_exp; move16(); /* Set first SID to current input level but add some smoothing */ - IF ( GE_16(*active_frame_counter,254)) + IF( GE_16( *active_frame_counter, 254 ) ) { lambda = 0; move16(); @@ -581,43 +578,43 @@ AdjustFirstSID_fx( { /* -0.94229902485 = 1024.0*log10(0.96)/log10(2.0)/64.0 */ /* active_frame_counter scaled by (1/1024.0) for compensation */ - tmp32 = L_shl(L_deposit_l(add(*active_frame_counter, 1)), WORD32_BITS-1-10); - tmp32 = BASOP_Util_InvLog2(Mpy_32_16_1(tmp32, -30877/*-0.94229902485 Q15*/)); - lambda = extract_h(tmp32); - lambdaM1 = extract_h(L_sub(0x7FFFFFFF, tmp32)); + tmp32 = L_shl( L_deposit_l( add( *active_frame_counter, 1 ) ), WORD32_BITS - 1 - 10 ); + tmp32 = BASOP_Util_InvLog2( Mpy_32_16_1( tmp32, -30877 /*-0.94229902485 Q15*/ ) ); + lambda = extract_h( tmp32 ); + lambdaM1 = extract_h( L_sub( 0x7FFFFFFF, tmp32 ) ); } - invFac = getNormReciprocalWord16(1); + invFac = getNormReciprocalWord16( 1 ); /* one bit headroom for addition */ - sc = add(s_max(*msNoiseEst_old_exp, *energy_ho_exp), 1); - s1 = limitScale32(sub(sc, *msNoiseEst_old_exp)); - s2 = limitScale32(sub(sc, *energy_ho_exp)); + sc = add( s_max( *msNoiseEst_old_exp, *energy_ho_exp ), 1 ); + s1 = limitScale32( sub( sc, *msNoiseEst_old_exp ) ); + s2 = limitScale32( sub( sc, *energy_ho_exp ) ); *energy_ho_exp = sc; move16(); - FOR (i=0; i 0 ) { tmp32 = 1; - move32(); + move32(); } } /* Set exponent to zero if msNoiseEst is zero */ - if ( tmp32==0 ) + if ( tmp32 == 0 ) { *msNoiseEst_exp = 0; move16(); @@ -644,19 +641,18 @@ AdjustFirstSID_fx( move16(); } test(); - IF ( NE_32(stcod->core_brate,SID_2k40)&&NE_32(stcod->core_brate,FRAME_NO_DATA)) + IF( NE_32( stcod->core_brate, SID_2k40 ) && NE_32( stcod->core_brate, FRAME_NO_DATA ) ) { /* Count the number of active frames in a row */ - *active_frame_counter = add(*active_frame_counter, 1); + *active_frame_counter = add( *active_frame_counter, 1 ); move16(); } ELSE { /* Store the noise estimate obtained in the CNG phases */ - Copy32 (msNoiseEst, msNoiseEst_old, npart); + Copy32( msNoiseEst, msNoiseEst_old, npart ); *msNoiseEst_old_exp = *msNoiseEst_exp; move16(); - } @@ -685,15 +681,15 @@ AdjustFirstSID_fx( Returns: void */ -static void msvq_encoder (const Word16 * const cb[], /* i : Codebook (indexed cb[*stages][levels][p]) scaled with 8 bits */ - Word16 u[], /* i : Vector to be encoded (prediction and mean removed) */ - const Word16 levels[], /* i : Number of levels in each stage */ - Word16 maxC, /* i : Tree search size */ - Word16 stages, /* i : Number of stages */ - Word16 N, /* i : Vector dimension */ - Word16 maxN, /* i : Codebook vector dimension */ - Word16 Idx[] /* o : Indices */ - ) +static void msvq_encoder( const Word16 *const cb[], /* i : Codebook (indexed cb[*stages][levels][p]) scaled with 8 bits */ + Word16 u[], /* i : Vector to be encoded (prediction and mean removed) */ + const Word16 levels[], /* i : Number of levels in each stage */ + Word16 maxC, /* i : Tree search size */ + Word16 stages, /* i : Number of stages */ + Word16 N, /* i : Vector dimension */ + Word16 maxN, /* i : Codebook vector dimension */ + Word16 Idx[] /* o : Indices */ +) { Word32 *dist[2]; Word32 t1, en, ss2, tmp; @@ -702,41 +698,40 @@ static void msvq_encoder (const Word16 * const cb[], /* i : Codebook (indexed c Word16 *indices[2], *resid[2], Tmp[M_MAX]; Word16 i, j, m, s, c, c2, p_max; Word16 parents[MBEST_MAX]; - Word32 dist_buf[2*MBEST_MAX]; - Word16 resid_buf[2*MBEST_MAX*M_MAX]; - Word16 idx_buf[2*MBEST_MAX*NSTAGES_MAX]; - + Word32 dist_buf[2 * MBEST_MAX]; + Word16 resid_buf[2 * MBEST_MAX * M_MAX]; + Word16 idx_buf[2 * MBEST_MAX * NSTAGES_MAX]; /*----------------------------------------------------------------* - * Allocate memory for previous (parent) and current nodes. - * Parent node is indexed [0], current node is indexed [1]. - *----------------------------------------------------------------*/ + * Allocate memory for previous (parent) and current nodes. + * Parent node is indexed [0], current node is indexed [1]. + *----------------------------------------------------------------*/ indices[0] = idx_buf; - indices[1] = idx_buf + maxC*stages; - set16_fx(idx_buf, 0, 2*stages*maxC); + indices[1] = idx_buf + maxC * stages; + set16_fx( idx_buf, 0, 2 * stages * maxC ); resid[0] = resid_buf; - resid[1] = resid_buf + maxC*N; + resid[1] = resid_buf + maxC * N; dist[0] = dist_buf; dist[1] = dist_buf + maxC; - set16_fx(parents, 0, maxC); + set16_fx( parents, 0, maxC ); /*----------------------------------------------------------------* - * ISF weights are normalized, so it is always better to multiply it first - * Set up inital distance vector - *----------------------------------------------------------------*/ + * ISF weights are normalized, so it is always better to multiply it first + * Set up inital distance vector + *----------------------------------------------------------------*/ - ss2 = L_mult(u[0], u[0]); - FOR (j=1; j < N; j++) + ss2 = L_mult( u[0], u[0] ); + FOR( j = 1; j < N; j++ ) { - ss2 = L_mac(ss2, u[j], u[j]); + ss2 = L_mac( ss2, u[j], u[j] ); } - FOR (j=0; j < maxC; j++) + FOR( j = 0; j < maxC; j++ ) { dist[1][j] = ss2; move32(); @@ -744,9 +739,9 @@ static void msvq_encoder (const Word16 * const cb[], /* i : Codebook (indexed c /* Set up inital error (residual) vectors */ pTmp = resid[1]; - FOR (c=0; chBstr; HANDLE_FD_CNG_COM st; Word16 maxC_37bits = FD_CNG_maxC_37bits, stages_37bits = FD_CNG_stages_37bits, maxN_37bits = FD_CNG_maxN_37bits; -#ifdef IVAS_CODE_CNG - float* invTrfMatrix; +#ifdef IVAS_CODE_CNG + float *invTrfMatrix; float tmpRAM[FDCNG_VQ_MAX_LEN][FDCNG_VQ_DCT_MAXTRUNC]; float dct_target[FDCNG_VQ_DCT_MAXTRUNC]; float tot_sig_ext[FDCNG_VQ_MAX_LEN]; - const float gain_q_offset = (st->element_mode == EVS_MONO) ? GAIN_Q_OFFSET_EVS : GAIN_Q_OFFSET_IVAS; + const float gain_q_offset = ( st->element_mode == EVS_MONO ) ? GAIN_Q_OFFSET_EVS : GAIN_Q_OFFSET_IVAS; /* Init */ N = hFdCngEnc->npartDec; - invTrfMatrix = (float*)tmpRAM; /* dynamically filled */ - set_zero(v, FDCNG_VQ_MAX_LEN); + invTrfMatrix = (float *) tmpRAM; /* dynamically filled */ + set_zero( v, FDCNG_VQ_MAX_LEN ); #endif @@ -939,116 +932,116 @@ void FdCng_encodeSID_fx(HANDLE_FD_CNG_ENC stenc, /* i/o: pointer to FD_CNG stru E_Exp = stenc->msNoiseEst_fx_exp; move16(); - E_ExpLd64 = L_shl(E_Exp, WORD32_BITS-1-LD_DATA_SCALE); + E_ExpLd64 = L_shl( E_Exp, WORD32_BITS - 1 - LD_DATA_SCALE ); E = stenc->msNoiseEst_fx; N = stenc->npartDec; move16(); - normFacN = getNormReciprocalWord16(N); - normShiftN = BASOP_util_norm_s_bands2shift(N); + normFacN = getNormReciprocalWord16( N ); + normShiftN = BASOP_util_norm_s_bands2shift( N ); - normFacGain = getNormReciprocalWord16(N_GAIN_MAX-N_GAIN_MIN); - normShiftGain = BASOP_util_norm_s_bands2shift(N_GAIN_MAX-N_GAIN_MIN); + normFacGain = getNormReciprocalWord16( N_GAIN_MAX - N_GAIN_MIN ); + normShiftGain = BASOP_util_norm_s_bands2shift( N_GAIN_MAX - N_GAIN_MIN ); /* Convert to LOG */ /* e: Q14.23 format, v: Q9.23 format */ - e = L_deposit_l(0); - tmp = Mpy_32_32_r(L_shl(1, sub(31, E_Exp)), 214748); /* 1e-4f, Q31-E_Exp */ - FOR (i=0; ielement_mode != EVS_MONO) +#ifdef IVAS_CODE_CNG + IF( st->element_mode != EVS_MONO ) { /* DCT domain compressed/truncated indices used for first stage */ /* quantization with stage1 stored in DCT24 domain, stages 2 through 6 directly dearched in FDCNG band domain */ - if (N == FDCNG_VQ_MAX_LEN_WB) + if ( N == FDCNG_VQ_MAX_LEN_WB ) { - create_IDCT_N_Matrix(invTrfMatrix, N, FDCNG_VQ_DCT_MAXTRUNC, sizeof(tmpRAM) / (sizeof(float))); + create_IDCT_N_Matrix( invTrfMatrix, N, FDCNG_VQ_DCT_MAXTRUNC, sizeof( tmpRAM ) / ( sizeof( float ) ) ); /* truncated DCT21 analysis */ - dctT2_N_apply_matrix((const float*)v, dct_target, FDCNG_VQ_DCT_MAXTRUNC, N, invTrfMatrix, FDCNG_VQ_DCT_MAXTRUNC, DCT_T2_21_XX); + dctT2_N_apply_matrix( (const float *) v, dct_target, FDCNG_VQ_DCT_MAXTRUNC, N, invTrfMatrix, FDCNG_VQ_DCT_MAXTRUNC, DCT_T2_21_XX ); /* truncated IDCT21 extension to 24 bands */ - extend_dctN_input(v, dct_target, N, tot_sig_ext, FDCNG_VQ_MAX_LEN, invTrfMatrix, FDCNG_VQ_DCT_MAXTRUNC, IDCT_T2_XX_21); + extend_dctN_input( v, dct_target, N, tot_sig_ext, FDCNG_VQ_MAX_LEN, invTrfMatrix, FDCNG_VQ_DCT_MAXTRUNC, IDCT_T2_XX_21 ); - mvr2r(tot_sig_ext, v, FDCNG_VQ_MAX_LEN); /* write extended result as input to VQ stage #1 */ + mvr2r( tot_sig_ext, v, FDCNG_VQ_MAX_LEN ); /* write extended result as input to VQ stage #1 */ } - create_IDCT_N_Matrix(invTrfMatrix, FDCNG_VQ_MAX_LEN, FDCNG_VQ_DCT_MAXTRUNC, sizeof(tmpRAM) / (sizeof(float))); - msvq_enc_fx(cdk_37bits_ivas, NULL, NULL, v, levels_37bits, FD_CNG_maxC_37bits, FD_CNG_stages_37bits, w, N, FD_CNG_maxN_37bits, 1, invTrfMatrix, indices); - msvq_dec(cdk_37bits_ivas, NULL, NULL, FD_CNG_stages_37bits, N, FD_CNG_maxN_37bits, indices, 1, invTrfMatrix, v, NULL); + create_IDCT_N_Matrix( invTrfMatrix, FDCNG_VQ_MAX_LEN, FDCNG_VQ_DCT_MAXTRUNC, sizeof( tmpRAM ) / ( sizeof( float ) ) ); + msvq_enc_fx( cdk_37bits_ivas, NULL, NULL, v, levels_37bits, FD_CNG_maxC_37bits, FD_CNG_stages_37bits, w, N, FD_CNG_maxN_37bits, 1, invTrfMatrix, indices ); + msvq_dec( cdk_37bits_ivas, NULL, NULL, FD_CNG_stages_37bits, N, FD_CNG_maxN_37bits, indices, 1, invTrfMatrix, v, NULL ); } ELSE #endif { /* MSVQ encoder */ - msvq_encoder(cdk_37bits, v16, levels_37bits, maxC_37bits, stages_37bits, N, maxN_37bits, indices ); + msvq_encoder( cdk_37bits, v16, levels_37bits, maxC_37bits, stages_37bits, N, maxN_37bits, indices ); /* MSVQ decoder */ - msvq_decoder(cdk_37bits, stages_37bits, N, maxN_37bits, indices, v16); + msvq_decoder( cdk_37bits, stages_37bits, N, maxN_37bits, indices, v16 ); } - FOR (i=0; ielement_mode > EVS_MONO) +#ifdef IVAS_CODE_CNG + if ( st->element_mode > EVS_MONO ) { - apply_scale(&gain, hFdCngCom->CngBandwidth, hFdCngCom->CngBitrate, scaleTableStereo, SIZE_SCALE_TABLE_STEREO); + apply_scale( &gain, hFdCngCom->CngBandwidth, hFdCngCom->CngBitrate, scaleTableStereo, SIZE_SCALE_TABLE_STEREO ); } else #endif { - apply_scale(&gain, st->CngBandwidth, st->CngBitrate, scaleTableMono, SIZE_SCALE_TABLE_MONO); + apply_scale( &gain, st->CngBandwidth, st->CngBitrate, scaleTableMono, SIZE_SCALE_TABLE_MONO ); } -#ifdef IVAS_CODE_CNG +#ifdef IVAS_CODE_CNG /* Quantize gain, Q14.23 format */ - gain = L_add(gain, L_shr(gain, 1)); - gain = L_add(gain, gain_q_offset/*gain_q_offset+.5 Q23*/); - index = extract_l(L_shr(gain, WORD32_BITS - 1 - 8)); + gain = L_add( gain, L_shr( gain, 1 ) ); + gain = L_add( gain, gain_q_offset /*gain_q_offset+.5 Q23*/ ); + index = extract_l( L_shr( gain, WORD32_BITS - 1 - 8 ) ); #else /* Quantize gain, Q14.23 format */ - gain = L_add(gain, L_shr(gain,1)); - gain = L_add(gain, 507510784l/*60.5 Q23*/); - index = extract_l(L_shr(gain,WORD32_BITS-1-8)); + gain = L_add( gain, L_shr( gain, 1 ) ); + gain = L_add( gain, 507510784l /*60.5 Q23*/ ); + index = extract_l( L_shr( gain, WORD32_BITS - 1 - 8 ) ); #endif if ( index < 0 ) @@ -1057,21 +1050,21 @@ void FdCng_encodeSID_fx(HANDLE_FD_CNG_ENC stenc, /* i/o: pointer to FD_CNG stru move16(); } - if ( GT_16(index,127)) + if ( GT_16( index, 127 ) ) { index = 127; move16(); } -#ifndef IVAS_CODE_CNG +#ifndef IVAS_CODE_CNG /* gain Q14.23 format */ - gain = L_shl(L_deposit_l(index), WORD32_BITS - 1 - 8); - gain = L_sub(gain, 503316480l/*60.0 Q23*/); - gain = Mpy_32_16_1(gain, 21845/*2.0f/3.0f Q15*/); + gain = L_shl( L_deposit_l( index ), WORD32_BITS - 1 - 8 ); + gain = L_sub( gain, 503316480l /*60.0 Q23*/ ); + gain = Mpy_32_16_1( gain, 21845 /*2.0f/3.0f Q15*/ ); #else /* gain Q14.23 format */ - gain = L_shl(L_deposit_l(index), WORD32_BITS-1-8); - gain = L_sub(gain, gain_q_offset/*60.0 Q23*/); - gain = Mpy_32_16_1(gain, 21845/*2.0f/3.0f Q15*/); + gain = L_shl( L_deposit_l( index ), WORD32_BITS - 1 - 8 ); + gain = L_sub( gain, gain_q_offset /*60.0 Q23*/ ); + gain = Mpy_32_16_1( gain, 21845 /*2.0f/3.0f Q15*/ ); #endif /* Apply gain and undo log */ @@ -1079,66 +1072,66 @@ void FdCng_encodeSID_fx(HANDLE_FD_CNG_ENC stenc, /* i/o: pointer to FD_CNG stru /* sidNoiseEst: format Q6.26, 0.66438561897 = log10(10)/log10(2.0) / 10.0 * 2.0 */ /* calculate worst case for scaling */ - maxVal = 0x80000000/*-1.0 Q31*/; + maxVal = 0x80000000 /*-1.0 Q31*/; move32(); - FOR (i=0; i= 0) + WHILE( maxVal >= 0 ) { - maxVal = L_sub(maxVal, 33554432l/*0.015625 Q31*/); - sidNoiseEst_Exp = add(sidNoiseEst_Exp,1); + maxVal = L_sub( maxVal, 33554432l /*0.015625 Q31*/ ); + sidNoiseEst_Exp = add( sidNoiseEst_Exp, 1 ); } st->sidNoiseEstExp = sidNoiseEst_Exp; move16(); - E_ExpLd64 = L_shl(sidNoiseEst_Exp, WORD32_BITS-1-LD_DATA_SCALE); + E_ExpLd64 = L_shl( sidNoiseEst_Exp, WORD32_BITS - 1 - LD_DATA_SCALE ); - FOR (i=0; isidNoiseEst[i] = BASOP_Util_InvLog2(tmp); + tmp = L_add( v[i], gain ); + tmp = L_shl( Mpy_32_16_1( tmp, 21771 /*0.66438561897 Q15*/ ), 1 ); + tmp = L_sub( tmp, E_ExpLd64 ); + assert( tmp < 0 ); + st->sidNoiseEst[i] = BASOP_Util_InvLog2( tmp ); move32(); } /* NB last band energy compensation */ - IF ( EQ_16(st->CngBandwidth,NB)) + IF( EQ_16( st->CngBandwidth, NB ) ) { - st->sidNoiseEst[N-1] = Mpy_32_16_1(st->sidNoiseEst[N-1], NB_LAST_BAND_SCALE); + st->sidNoiseEst[N - 1] = Mpy_32_16_1( st->sidNoiseEst[N - 1], NB_LAST_BAND_SCALE ); move32(); } test(); - if (EQ_16( st->CngBandwidth,SWB)&&LE_32(st->CngBitrate,ACELP_13k20)) + if ( EQ_16( st->CngBandwidth, SWB ) && LE_32( st->CngBitrate, ACELP_13k20 ) ) { - st->sidNoiseEst[N-1] = Mpy_32_16_1(st->sidNoiseEst[N-1], SWB_13k2_LAST_BAND_SCALE); + st->sidNoiseEst[N - 1] = Mpy_32_16_1( st->sidNoiseEst[N - 1], SWB_13k2_LAST_BAND_SCALE ); move32(); } /* Write bitstream */ - IF ( EQ_16(corest->codec_mode, MODE2)) + IF( EQ_16( corest->codec_mode, MODE2 ) ) { - FOR (i=0; ibwidth, 2 ); - IF (EQ_16(corest->L_frame, L_FRAME16k)) + IF( EQ_16( corest->L_frame, L_FRAME16k ) ) { push_indice_fx( hBstr, IND_ACELP_16KHZ, 1, 1 ); } @@ -1146,7 +1139,7 @@ void FdCng_encodeSID_fx(HANDLE_FD_CNG_ENC stenc, /* i/o: pointer to FD_CNG stru { push_indice_fx( hBstr, IND_ACELP_16KHZ, 0, 1 ); } - FOR (i=0; i cngNoiseLevel: Q6.26 format */ - scalebands(st->sidNoiseEst, stenc->partDec, stenc->npartDec, stenc->midbandDec, stenc->nFFTpartDec, sub(stenc->stopBandDec,stenc->startBandDec), st->cngNoiseLevel, 1); + scalebands( st->sidNoiseEst, stenc->partDec, stenc->npartDec, stenc->midbandDec, stenc->nFFTpartDec, sub( stenc->stopBandDec, stenc->startBandDec ), st->cngNoiseLevel, 1 ); st->cngNoiseLevelExp = st->sidNoiseEstExp; move16(); - lpc_from_spectrum(st, stenc->startBandDec, stenc->stopFFTbinDec, preemph_fac ); - - + lpc_from_spectrum( st, stenc->startBandDec, stenc->stopFFTbinDec, preemph_fac ); } -void generate_comfort_noise_enc_fx(Encoder_State *stcod, - Word16 Q_new, - Word16 gen_exc - ) +void generate_comfort_noise_enc_fx( Encoder_State *stcod, + Word16 Q_new, + Word16 gen_exc ) { - Word16 i, s, sn, cnt; - Word16 startBand2; - Word16 stopFFTbin2; - Word16 preemph_fac; - Word32 sqrtNoiseLevel; - Word16 randGaussExp; - Word16 fftBufferExp; - Word16 cngNoiseLevelExp; + Word16 i, s, sn, cnt; + Word16 startBand2; + Word16 stopFFTbin2; + Word16 preemph_fac; + Word32 sqrtNoiseLevel; + Word16 randGaussExp; + Word16 fftBufferExp; + Word16 cngNoiseLevelExp; Word16 *seed; Word16 *timeDomainOutput; Word32 *ptr_r, *ptr_i; Word32 *cngNoiseLevel; Word32 *ptr_level; Word32 *fftBuffer; - Word16 old_syn_pe_tmp[16]; + Word16 old_syn_pe_tmp[16]; Word16 tcx_transition = 0; HANDLE_FD_CNG_ENC stenc = stcod->hFdCngEnc; HANDLE_FD_CNG_COM st = stenc->hFdCngCom; - DTX_ENC_HANDLE hDtxEnc = stcod->hDtxEnc; - TD_CNG_ENC_HANDLE hTdCngEnc = stcod->hTdCngEnc; + DTX_ENC_HANDLE hDtxEnc = stcod->hDtxEnc; + TD_CNG_ENC_HANDLE hTdCngEnc = stcod->hTdCngEnc; LPD_state_HANDLE hLPDmem = stcod->hLPDmem; TCX_ENC_HANDLE hTcxEnc = stcod->hTcxEnc; @@ -1203,7 +1193,7 @@ void generate_comfort_noise_enc_fx(Encoder_State *stcod, cngNoiseLevel = st->cngNoiseLevel; cngNoiseLevelExp = st->cngNoiseLevelExp; ptr_level = cngNoiseLevel; - seed = &(st->seed); + seed = &( st->seed ); fftBuffer = st->fftBuffer; timeDomainOutput = st->timeDomainBuffer; @@ -1214,54 +1204,54 @@ void generate_comfort_noise_enc_fx(Encoder_State *stcod, */ sn = 0; move16(); - IF ( s_and(cngNoiseLevelExp,1) != 0 ) + IF( s_and( cngNoiseLevelExp, 1 ) != 0 ) { - sn = add(sn,1); - cngNoiseLevelExp = add(cngNoiseLevelExp,sn); + sn = add( sn, 1 ); + cngNoiseLevelExp = add( cngNoiseLevelExp, sn ); move16(); } randGaussExp = CNG_RAND_GAUSS_SHIFT; move16(); - cnt = sub(stenc->stopFFTbinDec, stenc->startBandDec); - IF ( stenc->startBandDec == 0 ) + cnt = sub( stenc->stopFFTbinDec, stenc->startBandDec ); + IF( stenc->startBandDec == 0 ) { /* DC component in FFT */ s = 0; move16(); - sqrtNoiseLevel = Sqrt32(L_shr(*ptr_level,sn), &s); + sqrtNoiseLevel = Sqrt32( L_shr( *ptr_level, sn ), &s ); - fftBuffer[0] = L_shl(Mpy_32_32(rand_gauss(seed),sqrtNoiseLevel),s); + fftBuffer[0] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), s ); move32(); /* Nyquist frequency is discarded */ - fftBuffer[1] = L_deposit_l(0); + fftBuffer[1] = L_deposit_l( 0 ); ptr_level = ptr_level + 1; ptr_r = fftBuffer + 2; - cnt = sub(cnt, 1); + cnt = sub( cnt, 1 ); } ELSE { - startBand2 = shl(stenc->startBandDec,1); - set32_fx(fftBuffer, 0, startBand2); + startBand2 = shl( stenc->startBandDec, 1 ); + set32_fx( fftBuffer, 0, startBand2 ); ptr_r = fftBuffer + startBand2; } - sn = add(sn,1); + sn = add( sn, 1 ); ptr_i = ptr_r + 1; - FOR (i=0; i < cnt; i++) + FOR( i = 0; i < cnt; i++ ) { s = 0; move16(); - sqrtNoiseLevel = Sqrt32(L_shr(*ptr_level,sn), &s); + sqrtNoiseLevel = Sqrt32( L_shr( *ptr_level, sn ), &s ); /* Real part in FFT bins */ - *ptr_r = L_shl(Mpy_32_32(rand_gauss(seed),sqrtNoiseLevel),s); + *ptr_r = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), s ); move32(); /* Imaginary part in FFT bins */ - *ptr_i = L_shl(Mpy_32_32(rand_gauss(seed),sqrtNoiseLevel),s); + *ptr_i = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), s ); move32(); ptr_r = ptr_r + 2; @@ -1270,18 +1260,18 @@ void generate_comfort_noise_enc_fx(Encoder_State *stcod, } /* Remaining FFT bins are set to zero */ - stopFFTbin2 = shl(stenc->stopFFTbinDec,1); - set32_fx(fftBuffer+stopFFTbin2, 0, sub(st->fftlen,stopFFTbin2)); + stopFFTbin2 = shl( stenc->stopFFTbinDec, 1 ); + set32_fx( fftBuffer + stopFFTbin2, 0, sub( st->fftlen, stopFFTbin2 ) ); - fftBufferExp = add(shr(cngNoiseLevelExp,1),randGaussExp); + fftBufferExp = add( shr( cngNoiseLevelExp, 1 ), randGaussExp ); /* If previous frame is active, reset the overlap-add buffer */ - IF ( GT_32(stcod->last_core_brate,SID_2k40)) + IF( GT_32( stcod->last_core_brate, SID_2k40 ) ) { - set16_fx(st->olapBufferSynth, 0, st->fftlen); + set16_fx( st->olapBufferSynth, 0, st->fftlen ); test(); test(); - IF ( (GT_32(stcod->last_core,ACELP_CORE)&&EQ_16(stcod->codec_mode,MODE2))||EQ_16(stcod->codec_mode,MODE1)) + IF( ( GT_32( stcod->last_core, ACELP_CORE ) && EQ_16( stcod->codec_mode, MODE2 ) ) || EQ_16( stcod->codec_mode, MODE1 ) ) { tcx_transition = 1; move16(); @@ -1289,8 +1279,8 @@ void generate_comfort_noise_enc_fx(Encoder_State *stcod, } /* Perform STFT synthesis */ - SynthesisSTFT (fftBuffer, fftBufferExp, timeDomainOutput, st->olapBufferSynth, st->olapWinSyn, - tcx_transition,st, gen_exc, &Q_new, -1, -1); + SynthesisSTFT( fftBuffer, fftBufferExp, timeDomainOutput, st->olapBufferSynth, st->olapWinSyn, + tcx_transition, st, gen_exc, &Q_new, -1, -1 ); { Word32 Lener, att; Word16 exp; @@ -1298,125 +1288,123 @@ void generate_comfort_noise_enc_fx(Encoder_State *stcod, /* calculate the residual signal energy */ /*enr = dotp( st->exc_cng, st->exc_cng, st->frameSize ) / st->frameSize;*/ - Lener = Dot_productSq16HQ(1,st->exc_cng,stcod->L_frame,&exp); - exp = add(sub(shl(sub(15,Q_new),1),8),exp); /*8 = log2(256)*/ + Lener = Dot_productSq16HQ( 1, st->exc_cng, stcod->L_frame, &exp ); + exp = add( sub( shl( sub( 15, Q_new ), 1 ), 8 ), exp ); /*8 = log2(256)*/ /* convert log2 of residual signal energy */ /*(float)log10( enr + 0.1f ) / (float)log10( 2.0f );*/ - Lener = BASOP_Util_Log2(Lener); - Lener = L_add(Lener,L_shl(L_deposit_l(exp),WORD32_BITS-1-LD_DATA_SCALE)); /*Q25*/ - if(EQ_16(stcod->L_frame,L_FRAME16k)) + Lener = BASOP_Util_Log2( Lener ); + Lener = L_add( Lener, L_shl( L_deposit_l( exp ), WORD32_BITS - 1 - LD_DATA_SCALE ) ); /*Q25*/ + if ( EQ_16( stcod->L_frame, L_FRAME16k ) ) { - Lener = L_sub(Lener, 10802114l/*0.3219280949f Q25*/); /*log2(320) = 8.3219280949f*/ + Lener = L_sub( Lener, 10802114l /*0.3219280949f Q25*/ ); /*log2(320) = 8.3219280949f*/ } /* decrease the energy in case of WB input */ - IF( NE_16(stcod->bwidth, NB)) + IF( NE_16( stcod->bwidth, NB ) ) { - IF( EQ_16(stcod->bwidth,WB)) + IF( EQ_16( stcod->bwidth, WB ) ) { - IF(hDtxEnc->CNG_mode >= 0 ) + IF( hDtxEnc->CNG_mode >= 0 ) { /* Bitrate adapted attenuation */ - att = L_shl(L_deposit_l(ENR_ATT_fx[hDtxEnc->CNG_mode]),17); + att = L_shl( L_deposit_l( ENR_ATT_fx[hDtxEnc->CNG_mode] ), 17 ); } ELSE { /* Use least attenuation for higher bitrates */ - att = L_shl(L_deposit_l(ENR_ATT_fx[4]),17); + att = L_shl( L_deposit_l( ENR_ATT_fx[4] ), 17 ); } } ELSE { - att = 384<<17; - move32();/*1.5 Q8<<17=Q25*/ + att = 384 << 17; + move32(); /*1.5 Q8<<17=Q25*/ } - Lener = L_sub(Lener, att ); + Lener = L_sub( Lener, att ); } /*stdec->lp_ener = 0.8f * stcod->lp_ener + 0.2f * pow( 2.0f, enr );*/ - Lener = BASOP_util_Pow2(Lener, 6, &exp); - Lener = Mult_32_16(Lener, 6554/*0.2f Q15*/); - exp = sub(25,exp); - Lener = L_shr(Lener, exp); /*Q6*/ - hTdCngEnc->lp_ener_fx = L_add(Mult_32_16(hTdCngEnc->lp_ener_fx, 26214/*0.8f Q15*/), Lener); /*Q6*/ + Lener = BASOP_util_Pow2( Lener, 6, &exp ); + Lener = Mult_32_16( Lener, 6554 /*0.2f Q15*/ ); + exp = sub( 25, exp ); + Lener = L_shr( Lener, exp ); /*Q6*/ + hTdCngEnc->lp_ener_fx = L_add( Mult_32_16( hTdCngEnc->lp_ener_fx, 26214 /*0.8f Q15*/ ), Lener ); /*Q6*/ } /* Overlap-add when previous frame is active */ test(); - IF ( ( GT_32(stcod->last_core_brate,SID_2k40))&&(EQ_16(stcod->codec_mode,MODE2))) + IF( ( GT_32( stcod->last_core_brate, SID_2k40 ) ) && ( EQ_16( stcod->codec_mode, MODE2 ) ) ) { Word32 old_exc_ener, gain, noise32; Word16 seed_loc, lpcorder, old_syn, tmp, gain16, N, N2, N4, N8; Word16 old_exc_ener_exp, gain_exp; Word16 normFacE, normShiftE, normShiftEM1; Word16 normFacG, normShiftG, normShiftGM1; - Word16 noiseExp, *old_exc, old_Aq[M+1], *old_syn_pe; + Word16 noiseExp, *old_exc, old_Aq[M + 1], *old_syn_pe; Word16 noise[640], normShiftP2; Word16 Q_exc, Q_syn; - assert(st->frameSize <= 640); + assert( st->frameSize <= 640 ); seed_loc = st->seed; move16(); N = st->frameSize; move16(); - N2 = shr(st->frameSize,1); + N2 = shr( st->frameSize, 1 ); - IF ( GT_16(stcod->last_core,ACELP_CORE)) + IF( GT_16( stcod->last_core, ACELP_CORE ) ) { Word16 left_overlap_mode; left_overlap_mode = stcod->hTcxCfg->tcx_last_overlap_mode; move16(); - if (EQ_16(left_overlap_mode, ALDO_WINDOW)) + if ( EQ_16( left_overlap_mode, ALDO_WINDOW ) ) { left_overlap_mode = FULL_OVERLAP; move16(); } - tcx_windowing_synthesis_current_frame( timeDomainOutput, - stcod->hTcxCfg->tcx_mdct_window, /*Keep sine windows for limiting Time modulation*/ - stcod->hTcxCfg->tcx_mdct_window_half, - stcod->hTcxCfg->tcx_mdct_window_minimum, - stcod->hTcxCfg->tcx_mdct_window_length, - stcod->hTcxCfg->tcx_mdct_window_half_length, - stcod->hTcxCfg->tcx_mdct_window_min_length, - 0, - left_overlap_mode, - NULL, - NULL, - NULL, - NULL, - NULL, - N/2, - shr(sub(abs_s(stcod->hTcxCfg->tcx_offset), stcod->hTcxCfg->tcx_offset), 1), /* equivalent to: stdec->hTcxCfg->tcx_offset<0?-stdec->hTcxCfg->tcx_offset:0 */ - 1, - 0, - 0 - ); - - IF (stcod->hTcxCfg->last_aldo != 0) + tcx_windowing_synthesis_current_frame( timeDomainOutput, + stcod->hTcxCfg->tcx_mdct_window, /*Keep sine windows for limiting Time modulation*/ + stcod->hTcxCfg->tcx_mdct_window_half, + stcod->hTcxCfg->tcx_mdct_window_minimum, + stcod->hTcxCfg->tcx_mdct_window_length, + stcod->hTcxCfg->tcx_mdct_window_half_length, + stcod->hTcxCfg->tcx_mdct_window_min_length, + 0, + left_overlap_mode, + NULL, + NULL, + NULL, + NULL, + NULL, + N / 2, + shr( sub( abs_s( stcod->hTcxCfg->tcx_offset ), stcod->hTcxCfg->tcx_offset ), 1 ), /* equivalent to: stdec->hTcxCfg->tcx_offset<0?-stdec->hTcxCfg->tcx_offset:0 */ + 1, + 0, + 0 ); + + IF( stcod->hTcxCfg->last_aldo != 0 ) { - FOR (i=0; iframeSize; i++) + FOR( i = 0; i < st->frameSize; i++ ) { - timeDomainOutput[i] = add(timeDomainOutput[i], shr_r(hTcxEnc->old_out_fx[i+NS2SA(stcod->sr_core, N_ZERO_MDCT_NS)], hTcxEnc->Q_old_out)); + timeDomainOutput[i] = add( timeDomainOutput[i], shr_r( hTcxEnc->old_out_fx[i + NS2SA( stcod->sr_core, N_ZERO_MDCT_NS )], hTcxEnc->Q_old_out ) ); move16(); } } ELSE { - tcx_windowing_synthesis_past_frame(hTcxEnc->Txnq, - stcod->hTcxCfg->tcx_aldo_window_1_trunc, - stcod->hTcxCfg->tcx_mdct_window_half, - stcod->hTcxCfg->tcx_mdct_window_minimum, - stcod->hTcxCfg->tcx_mdct_window_length, - stcod->hTcxCfg->tcx_mdct_window_half_length, - stcod->hTcxCfg->tcx_mdct_window_min_length, - stcod->hTcxCfg->tcx_last_overlap_mode - ); - - FOR (i=0; iTxnq, + stcod->hTcxCfg->tcx_aldo_window_1_trunc, + stcod->hTcxCfg->tcx_mdct_window_half, + stcod->hTcxCfg->tcx_mdct_window_minimum, + stcod->hTcxCfg->tcx_mdct_window_length, + stcod->hTcxCfg->tcx_mdct_window_half_length, + stcod->hTcxCfg->tcx_mdct_window_min_length, + stcod->hTcxCfg->tcx_last_overlap_mode ); + + FOR( i = 0; i < N2; i++ ) { - timeDomainOutput[i] = add(timeDomainOutput[i],shl(hTcxEnc->Txnq[i],TCX_IMDCT_HEADROOM)); + timeDomainOutput[i] = add( timeDomainOutput[i], shl( hTcxEnc->Txnq[i], TCX_IMDCT_HEADROOM ) ); move16(); } } @@ -1438,125 +1426,124 @@ void generate_comfort_noise_enc_fx(Encoder_State *stcod, lpcorder = M; move16(); - E_LPC_f_lsp_a_conversion(stcod->lsp_old_fx, old_Aq, M); - old_exc = hLPDmem->old_exc+sub(L_EXC_MEM,N2); + E_LPC_f_lsp_a_conversion( stcod->lsp_old_fx, old_Aq, M ); + old_exc = hLPDmem->old_exc + sub( L_EXC_MEM, N2 ); old_syn_pe = hLPDmem->mem_syn2; old_syn = hLPDmem->syn[lpcorder]; move16(); preemph_fac = stcod->preemph_fac; move16(); Q_exc = Q_new; - Q_syn = sub(Q_new,1); + Q_syn = sub( Q_new, 1 ); /* shift to be in the range of values supported by getNormReciprocalWord16() */ - N8 = shr(N2, CNG_NORM_RECIPROCAL_RANGE_SHIFT); + N8 = shr( N2, CNG_NORM_RECIPROCAL_RANGE_SHIFT ); - assert( N2 == (N8<olapWinSyn[i].v.re); - timeDomainOutput[i] = add(timeDomainOutput[i],tmp); + tmp = mult( noise[i], st->olapWinSyn[i].v.re ); + timeDomainOutput[i] = add( timeDomainOutput[i], tmp ); move16(); - tmp = mult(noise[i+N4],st->olapWinSyn[N4-1-i].v.im); - timeDomainOutput[i+N4] = add(timeDomainOutput[i+N4],tmp); + tmp = mult( noise[i + N4], st->olapWinSyn[N4 - 1 - i].v.im ); + timeDomainOutput[i + N4] = add( timeDomainOutput[i + N4], tmp ); move16(); } } } - } /*-------------------------------------------------------------------* @@ -1565,80 +1552,80 @@ void generate_comfort_noise_enc_fx(Encoder_State *stcod, * *-------------------------------------------------------------------*/ - /*! r: CNG energy */ +/*! r: CNG energy */ Word16 cng_energy_fx( const Word16 element_mode, /* i : element mode */ const Word16 bwidth, /* i : audio bandwidh */ - const Word16 CNG_mode, /* i : mode for DTX configuration */ - const Word16 CNG_att, /* i : attenuation factor for CNG */ - const Word16* exc, /* i : input signal */ - const Word16 len, /* i : vector length */ - const Word16 Q_new /* i : Input scaling */ + const Word16 CNG_mode, /* i : mode for DTX configuration */ + const Word16 CNG_att, /* i : attenuation factor for CNG */ + const Word16 *exc, /* i : input signal */ + const Word16 len, /* i : vector length */ + const Word16 Q_new /* i : Input scaling */ ) { Word16 i, maxv, scale; Word16 hi, lo, enr, tmp16, att; - const Word16* pt_res; + const Word16 *pt_res; Word32 L_ener, L_tmp; maxv = 0; move16(); - FOR(i = 0; i < len; i++) + FOR( i = 0; i < len; i++ ) { - maxv = s_max(maxv, abs_s(exc[i])); + maxv = s_max( maxv, abs_s( exc[i] ) ); } - scale = norm_s(maxv); + scale = norm_s( maxv ); pt_res = exc; - L_ener = L_deposit_l(1); - IF(EQ_16(len, L_FRAME)) + L_ener = L_deposit_l( 1 ); + IF( EQ_16( len, L_FRAME ) ) { - FOR(i = 0; i < 128; i++) + FOR( i = 0; i < 128; i++ ) { - tmp16 = shl(*pt_res, scale); - L_tmp = L_mult0(tmp16, tmp16); + tmp16 = shl( *pt_res, scale ); + L_tmp = L_mult0( tmp16, tmp16 ); pt_res++; - tmp16 = shl(*pt_res, scale); - L_tmp = L_mac0(L_tmp, tmp16, tmp16); /* 2*(Q_new+scale) */ + tmp16 = shl( *pt_res, scale ); + L_tmp = L_mac0( L_tmp, tmp16, tmp16 ); /* 2*(Q_new+scale) */ pt_res++; - L_ener = L_add(L_ener, L_shr(L_tmp, 7)); /* 2*(Q_new+scale)+1, divide by L_frame done here */ + L_ener = L_add( L_ener, L_shr( L_tmp, 7 ) ); /* 2*(Q_new+scale)+1, divide by L_frame done here */ } } ELSE /* L_FRAME16k */ { - FOR(i = 0; i < 160; i++) + FOR( i = 0; i < 160; i++ ) { - tmp16 = shl(*pt_res,scale); - L_tmp = L_mult0(tmp16, tmp16); + tmp16 = shl( *pt_res, scale ); + L_tmp = L_mult0( tmp16, tmp16 ); pt_res++; - tmp16 = shl(*pt_res,scale); - L_tmp = L_mac0(L_tmp, tmp16, tmp16); /* 2*(Q_new+scale) */ + tmp16 = shl( *pt_res, scale ); + L_tmp = L_mac0( L_tmp, tmp16, tmp16 ); /* 2*(Q_new+scale) */ pt_res++; - L_ener = L_add(L_ener, L_shr(Mult_32_16(L_tmp,26214 /* 256/320, Q15 */), 7)); /* 2*(Q_new+scale)+15+1-16+1, divide by L_frame done here */ + L_ener = L_add( L_ener, L_shr( Mult_32_16( L_tmp, 26214 /* 256/320, Q15 */ ), 7 ) ); /* 2*(Q_new+scale)+15+1-16+1, divide by L_frame done here */ } } - hi = norm_l(L_ener); - lo = Log2_norm_lc(L_shl(L_ener, hi)); - hi = sub(30, add(hi, shl(add(Q_new, scale), 1))); /* log2 exp in Q2*(Q_new+scale) */ - L_tmp = L_Comp(hi, lo); /* Q16 */ - enr = round_fx(L_shl(L_tmp, 8)); /* Q8 (16+8-16) */ + hi = norm_l( L_ener ); + lo = Log2_norm_lc( L_shl( L_ener, hi ) ); + hi = sub( 30, add( hi, shl( add( Q_new, scale ), 1 ) ) ); /* log2 exp in Q2*(Q_new+scale) */ + L_tmp = L_Comp( hi, lo ); /* Q16 */ + enr = round_fx( L_shl( L_tmp, 8 ) ); /* Q8 (16+8-16) */ /* decrease the energy in case of WB input */ test(); - IF (EQ_16(element_mode, IVAS_CPE_DFT) || EQ_16(element_mode, IVAS_CPE_TD)) + IF( EQ_16( element_mode, IVAS_CPE_DFT ) || EQ_16( element_mode, IVAS_CPE_TD ) ) { - //PMT(" IVAS CNG ener computing is missing") + // PMT(" IVAS CNG ener computing is missing") #ifdef IVAS_CODE enr += CNG_att * FAC_LOG2 / 10.0f; -#else - (void)CNG_att; +#else + (void) CNG_att; #endif } - ELSE IF(NE_16(bwidth, NB)) + ELSE IF( NE_16( bwidth, NB ) ) { - IF(EQ_16(bwidth, WB)) + IF( EQ_16( bwidth, WB ) ) { - IF(CNG_mode >= 0) + IF( CNG_mode >= 0 ) { /* Bitrate adapted attenuation */ att = ENR_ATT_fx[CNG_mode]; @@ -1652,9 +1639,9 @@ Word16 cng_energy_fx( ELSE { att = 384; - move16();/*Q8*/ + move16(); /*Q8*/ } - enr = sub(enr, att); + enr = sub( enr, att ); } return enr; } diff --git a/lib_enc/find_tar_fx.c b/lib_enc/find_tar_fx.c index f00b77b9f..14de5fe44 100644 --- a/lib_enc/find_tar_fx.c +++ b/lib_enc/find_tar_fx.c @@ -2,36 +2,35 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ +#include "options.h" /* Compilation switches */ //#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ -#include "cnst.h" /* Common constants */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ +#include "cnst.h" /* Common constants */ #include "basop_util.h" #include "stl.h" - void find_targets_fx( - const Word16 *speech, /* i : pointer to the speech frame Q_new-1*/ - const Word16 *mem_syn, /* i : memory of the synthesis filter Q_new-1*/ - const Word16 i_subfr, /* i : subframe index */ - Word16 *mem_w0, /* i/o: weighting filter denominator memory Q_new-1*/ - const Word16 *p_Aq, /* i : interpolated quantized A(z) filter Q12*/ - const Word16 *res, /* i : residual signal Q_new*/ - const Word16 L_subfr, /* i : length of vectors for gain quantization */ - const Word16 *Ap, /* i : unquantized A(z) filter with bandwidth expansion Q12*/ - Word16 tilt_fac, /* i : tilt factor Q15 */ - Word16 *xn, /* o : Close-loop Pitch search target vector Q_new-1*/ - Word16 *cn, /* o : target vector in residual domain Q_new*/ - Word16 *h1 /* o : impulse response of weighted synthesis filter */ + const Word16 *speech, /* i : pointer to the speech frame Q_new-1*/ + const Word16 *mem_syn, /* i : memory of the synthesis filter Q_new-1*/ + const Word16 i_subfr, /* i : subframe index */ + Word16 *mem_w0, /* i/o: weighting filter denominator memory Q_new-1*/ + const Word16 *p_Aq, /* i : interpolated quantized A(z) filter Q12*/ + const Word16 *res, /* i : residual signal Q_new*/ + const Word16 L_subfr, /* i : length of vectors for gain quantization */ + const Word16 *Ap, /* i : unquantized A(z) filter with bandwidth expansion Q12*/ + Word16 tilt_fac, /* i : tilt factor Q15 */ + Word16 *xn, /* o : Close-loop Pitch search target vector Q_new-1*/ + Word16 *cn, /* o : target vector in residual domain Q_new*/ + Word16 *h1 /* o : impulse response of weighted synthesis filter */ ) { Word16 i; - Word16 temp[M+6*L_SUBFR]; /* error of quantization */ - Word16 scale,scaleq,j,d,s,s2,tmp; - Word16 Aqs[M+1]; + Word16 temp[M + 6 * L_SUBFR]; /* error of quantization */ + Word16 scale, scaleq, j, d, s, s2, tmp; + Word16 Aqs[M + 1]; Word32 Ltmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; @@ -49,7 +48,7 @@ void find_targets_fx( * the weighted input speech, the above configuration is used to * compute the target vector. *-----------------------------------------------------------------------*/ - FOR (i=0; i cn[] */ temp[0] = 0; move16(); - preemph_copy_fx(xn, cn, tilt_fac, L_SUBFR/2, temp); - syn_filt_s_lc_fx(1, Ap, cn, temp, L_SUBFR/2); /* Q-1 -> Q-2 */ - Residu3_lc_fx(p_Aq, M, temp, cn, L_SUBFR/2, 1); /* Q-2 -> Q-1 */ - Scale_sig(cn, L_SUBFR/2,1); + preemph_copy_fx( xn, cn, tilt_fac, L_SUBFR / 2, temp ); + syn_filt_s_lc_fx( 1, Ap, cn, temp, L_SUBFR / 2 ); /* Q-1 -> Q-2 */ + Residu3_lc_fx( p_Aq, M, temp, cn, L_SUBFR / 2, 1 ); /* Q-2 -> Q-1 */ + Scale_sig( cn, L_SUBFR / 2, 1 ); /* second half: res[] --> cn[] (approximated and faster) */ - Copy(&res[i_subfr+(L_SUBFR/2)], cn+(L_SUBFR/2), L_SUBFR/2); + Copy( &res[i_subfr + ( L_SUBFR / 2 )], cn + ( L_SUBFR / 2 ), L_SUBFR / 2 ); } /*---------------------------------------------------------------* - * Compute impulse response, h1[], of weighted synthesis filter * - *---------------------------------------------------------------*/ + * Compute impulse response, h1[], of weighted synthesis filter * + *---------------------------------------------------------------*/ scale = norm_s( Ap[0] ); scaleq = norm_s( p_Aq[0] ); d = sub( scaleq, scale ); - IF ( d >= 0 ) + IF( d >= 0 ) { - Copy( p_Aq, Aqs, M+1 ); + Copy( p_Aq, Aqs, M + 1 ); s = add( scaleq, 1 ); s2 = shr( 16384, d ); } ELSE { - Copy_Scale_sig( p_Aq, Aqs, M+1, d ); + Copy_Scale_sig( p_Aq, Aqs, M + 1, d ); s = add( scale, 1 ); s2 = 16384; } - Overflow = 0; + Overflow = 0; move16(); - FOR (i = 0; i < M; i++) + FOR( i = 0; i < M; i++ ) { - Ltmp = L_mult(Ap[i], s2); - FOR (j = 1; j <= i; j++) + Ltmp = L_mult( Ap[i], s2 ); + FOR( j = 1; j <= i; j++ ) { -#ifdef BASOP_NOGLOB /* Critical Overflow , as well as those below*/ - Ltmp = L_msu_o(Ltmp, Aqs[j], h1[i - j], &Overflow); +#ifdef BASOP_NOGLOB /* Critical Overflow , as well as those below*/ + Ltmp = L_msu_o( Ltmp, Aqs[j], h1[i - j], &Overflow ); #else - Ltmp = L_msu(Ltmp, Aqs[j], h1[i-j]); + Ltmp = L_msu( Ltmp, Aqs[j], h1[i - j] ); #endif } -#ifdef BASOP_NOGLOB /* Critical Overflow */ - h1[i] = round_fx_o(L_shl_o(Ltmp, s, &Overflow), &Overflow); -#else - h1[i] = round_fx(L_shl(Ltmp, s)); -#endif +#ifdef BASOP_NOGLOB /* Critical Overflow */ + h1[i] = round_fx_o( L_shl_o( Ltmp, s, &Overflow ), &Overflow ); +#else + h1[i] = round_fx( L_shl( Ltmp, s ) ); +#endif } - Ltmp = L_mult(Ap[i], s2); - FOR (j = 1; j <= M; j++) + Ltmp = L_mult( Ap[i], s2 ); + FOR( j = 1; j <= M; j++ ) { -#ifdef BASOP_NOGLOB /* Critical Overflow */ - Ltmp = L_msu_o(Ltmp, Aqs[j], h1[i-j], &Overflow); +#ifdef BASOP_NOGLOB /* Critical Overflow */ + Ltmp = L_msu_o( Ltmp, Aqs[j], h1[i - j], &Overflow ); #else - Ltmp = L_msu(Ltmp, Aqs[j], h1[i-j]); + Ltmp = L_msu( Ltmp, Aqs[j], h1[i - j] ); #endif } -#ifdef BASOP_NOGLOB /* Critical Overflow */ - h1[M] = round_fx_o(L_shl_o(Ltmp, s, &Overflow), &Overflow); +#ifdef BASOP_NOGLOB /* Critical Overflow */ + h1[M] = round_fx_o( L_shl_o( Ltmp, s, &Overflow ), &Overflow ); #else - h1[M] = round_fx(L_shl(Ltmp, s)); + h1[M] = round_fx( L_shl( Ltmp, s ) ); #endif -//PMT("should we used extended basop here for when the L_subfr > L_SUBFR, to prevent saturation/overflow and the subsequent loop\n") - FOR (i=M+1; i < L_subfr; i++) + // PMT("should we used extended basop here for when the L_subfr > L_SUBFR, to prevent saturation/overflow and the subsequent loop\n") + FOR( i = M + 1; i < L_subfr; i++ ) { - Ltmp = L_msu(0, Aqs[1], h1[i-1]); - FOR (j = 2; j <= M; j++) + Ltmp = L_msu( 0, Aqs[1], h1[i - 1] ); + FOR( j = 2; j <= M; j++ ) { -#ifdef BASOP_NOGLOB /* Critical Overflow */ - Ltmp = L_msu_o(Ltmp, Aqs[j], h1[i-j], &Overflow); +#ifdef BASOP_NOGLOB /* Critical Overflow */ + Ltmp = L_msu_o( Ltmp, Aqs[j], h1[i - j], &Overflow ); #else - Ltmp = L_msu(Ltmp, Aqs[j], h1[i-j]); + Ltmp = L_msu( Ltmp, Aqs[j], h1[i - j] ); #endif } -#ifdef BASOP_NOGLOB /* Critical Overflow */ - h1[i] = round_fx_o(L_shl_o(Ltmp, s, &Overflow), &Overflow); +#ifdef BASOP_NOGLOB /* Critical Overflow */ + h1[i] = round_fx_o( L_shl_o( Ltmp, s, &Overflow ), &Overflow ); #else - h1[i] = round_fx(L_shl(Ltmp, s)); + h1[i] = round_fx( L_shl( Ltmp, s ) ); #endif } - IF(Overflow) + IF( Overflow ) { - s2 = shr(s2, 1); - FOR (i = 0; i < M; i++) + s2 = shr( s2, 1 ); + FOR( i = 0; i < M; i++ ) { - Ltmp = L_mult(Ap[i], s2); - FOR (j = 1; j <= i; j++) + Ltmp = L_mult( Ap[i], s2 ); + FOR( j = 1; j <= i; j++ ) { - Ltmp = L_msu(Ltmp, Aqs[j], h1[i-j]); + Ltmp = L_msu( Ltmp, Aqs[j], h1[i - j] ); } #ifdef BASOP_NOGLOB - h1[i] = round_fx(L_shl_o(Ltmp, s, &Overflow)); -#else - h1[i] = round_fx(L_shl(Ltmp, s)); + h1[i] = round_fx( L_shl_o( Ltmp, s, &Overflow ) ); +#else + h1[i] = round_fx( L_shl( Ltmp, s ) ); #endif } - Ltmp = L_mult(Ap[i], s2); - FOR (j = 1; j <= M; j++) + Ltmp = L_mult( Ap[i], s2 ); + FOR( j = 1; j <= M; j++ ) { - Ltmp = L_msu(Ltmp, Aqs[j], h1[i-j]); + Ltmp = L_msu( Ltmp, Aqs[j], h1[i - j] ); } - h1[M] = round_fx(L_shl(Ltmp, s)); - FOR (i=M+1; i < L_subfr; i++) + h1[M] = round_fx( L_shl( Ltmp, s ) ); + FOR( i = M + 1; i < L_subfr; i++ ) { - Ltmp = L_msu(0, Aqs[1], h1[i-1]); - FOR (j = 2; j <= M; j++) + Ltmp = L_msu( 0, Aqs[1], h1[i - 1] ); + FOR( j = 2; j <= M; j++ ) { - Ltmp = L_msu(Ltmp, Aqs[j], h1[i-j]); + Ltmp = L_msu( Ltmp, Aqs[j], h1[i - j] ); } - h1[i] = round_fx(L_shl(Ltmp, s)); + h1[i] = round_fx( L_shl( Ltmp, s ) ); } } tmp = 0; - Deemph2(h1, tilt_fac, L_subfr, &tmp); + Deemph2( h1, tilt_fac, L_subfr, &tmp ); return; - } diff --git a/lib_enc/find_tilt_fx.c b/lib_enc/find_tilt_fx.c index 044dff710..11106323e 100644 --- a/lib_enc/find_tilt_fx.c +++ b/lib_enc/find_tilt_fx.c @@ -2,12 +2,12 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ //#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" /*-------------------------------------------------------------------* @@ -17,23 +17,23 @@ *-------------------------------------------------------------------*/ void find_tilt_fx( - const Word32 fr_bands[], /* i : energy in frequency bands Q_new + Q_SCALE*/ - const Word32 bckr[], /* i : per band background noise energy estimate Q_new + Q_SCALE*/ - Word32 ee[2], /* o : lf/hf E ration for present frame Q6*/ - const Word16 pitch[3], /* i : open loop pitch values for 3 half-frames Q0*/ - const Word16 voicing[3], /* i : normalized correlation for 3 half-frames Q15*/ - const Word32 *lf_E, /* i : per bin energy for low frequencies Q_new + Q_SCALE - 2*/ - const Word16 corr_shift, /* i : normalized correlation correction Q15*/ - const Word16 bwidth, /* i : input signal bandwidth */ - const Word16 max_band, /* i : maximum critical band */ - Word32 hp_E[], /* o : energy in HF Q_new + Q_SCALE*/ - const Word16 codec_mode, /* i : MODE1 or MODE2 */ - const Word16 Q_new, /* i : scaling factor */ - Word32 *bckr_tilt_lt /* i/o: lf/hf E ratio of background noise Q16 */ - ,Word16 Opt_vbr_mode -) + const Word32 fr_bands[], /* i : energy in frequency bands Q_new + Q_SCALE*/ + const Word32 bckr[], /* i : per band background noise energy estimate Q_new + Q_SCALE*/ + Word32 ee[2], /* o : lf/hf E ration for present frame Q6*/ + const Word16 pitch[3], /* i : open loop pitch values for 3 half-frames Q0*/ + const Word16 voicing[3], /* i : normalized correlation for 3 half-frames Q15*/ + const Word32 *lf_E, /* i : per bin energy for low frequencies Q_new + Q_SCALE - 2*/ + const Word16 corr_shift, /* i : normalized correlation correction Q15*/ + const Word16 bwidth, /* i : input signal bandwidth */ + const Word16 max_band, /* i : maximum critical band */ + Word32 hp_E[], /* o : energy in HF Q_new + Q_SCALE*/ + const Word16 codec_mode, /* i : MODE1 or MODE2 */ + const Word16 Q_new, /* i : scaling factor */ + Word32 *bckr_tilt_lt /* i/o: lf/hf E ratio of background noise Q16 */ + , + Word16 Opt_vbr_mode ) { - Word32 lp_bckr = 0, hp_bckr = 0, lp_E, Ltmp; + Word32 lp_bckr = 0, hp_bckr = 0, lp_E, Ltmp; const Word32 *pt_E, *pt_bands, *pt_bckr, *hf_bands, *tmp_E; Word16 tmp, freq, f0, f1, f2, mean_voi, bin; Word16 i, nb_bands; @@ -49,12 +49,12 @@ void find_tilt_fx( * Initializations *-----------------------------------------------------------------*/ - scaling = add(Q_new, QSCALE); - IF( NE_16(bwidth,NB)) + scaling = add( Q_new, QSCALE ); + IF( NE_16( bwidth, NB ) ) { /* WB processing */ bin = BIN4_FX; - move16(); /* First useful frequency bin ~ 50 Hz */ + move16(); /* First useful frequency bin ~ 50 Hz */ pt_bands = fr_bands; tmp_E = lf_E; pt_bckr = bckr; @@ -64,207 +64,207 @@ void find_tilt_fx( ELSE { /* NB processing */ - bin = add(shl(BIN4_FX,1), BIN4_FX); /* First useful frequency bin ~ 150 Hz */ - pt_bands = fr_bands+1; /* Exlcude 1st critical band */ - tmp_E = lf_E + 2; /* Start at the 3rd bin (150 Hz) */ - pt_bckr = bckr+1; /* Exlcude 1st critical band */ + bin = add( shl( BIN4_FX, 1 ), BIN4_FX ); /* First useful frequency bin ~ 150 Hz */ + pt_bands = fr_bands + 1; /* Exlcude 1st critical band */ + tmp_E = lf_E + 2; /* Start at the 3rd bin (150 Hz) */ + pt_bckr = bckr + 1; /* Exlcude 1st critical band */ nb_bands = 9; - move16(); /* Nb. of "low" frequency bands taken into account in NB processing */ + move16(); /* Nb. of "low" frequency bands taken into account in NB processing */ } /*-----------------------------------------------------------------* * Find spectrum tilt *-----------------------------------------------------------------*/ - pt_E = tmp_E; /* Point at the 1st useful element of the per-bin energy vector */ + pt_E = tmp_E; /* Point at the 1st useful element of the per-bin energy vector */ hf_bands = fr_bands; /* bckr + voicing */ - /*lp_bckr = mean( pt_bckr, nb_bands );*/ /* estimated noise E in first critical bands, up to 1270 Hz */ - lp_bckr = Mean32(pt_bckr, nb_bands); - /*hp_bckr = 0.5f * (bckr[max_band-1] + bckr[max_band]);*/ /* estimated noise E in last 2 critical bands */ + /*lp_bckr = mean( pt_bckr, nb_bands );*/ /* estimated noise E in first critical bands, up to 1270 Hz */ + lp_bckr = Mean32( pt_bckr, nb_bands ); + /*hp_bckr = 0.5f * (bckr[max_band-1] + bckr[max_band]);*/ /* estimated noise E in last 2 critical bands */ #ifdef BASOP_NOGLOB hp_bckr = L_shr( L_add_sat( bckr[max_band - 1], bckr[max_band] ), 1 ); #else - hp_bckr = L_shr(L_add(bckr[max_band-1] , bckr[max_band]),1); + hp_bckr = L_shr( L_add( bckr[max_band - 1], bckr[max_band] ), 1 ); #endif - if (hp_bckr == 0) /* Avoid division by zero. */ + if ( hp_bckr == 0 ) /* Avoid division by zero. */ { - hp_bckr = L_deposit_l(1); + hp_bckr = L_deposit_l( 1 ); } tmp = BASOP_Util_Divide3232_Scale( lp_bckr, hp_bckr, &e_tmp ); Ltmp = L_shr_r( L_deposit_h( tmp ), sub( 15, e_tmp ) ); *bckr_tilt_lt = L_add( Mpy_32_16_r( *bckr_tilt_lt, 29491 ), Mpy_32_16_r( Ltmp, 3277 ) ); test(); - IF ( EQ_16(codec_mode,MODE2)||Opt_vbr_mode==1) + IF( EQ_16( codec_mode, MODE2 ) || Opt_vbr_mode == 1 ) { /*lp_bckr *= FACT;*/ /*hp_bckr *= FACT;*/ #ifdef BASOP_NOGLOB lp_bckr = L_add_sat( L_shl_sat( lp_bckr, 1 ), lp_bckr ); - hp_bckr = L_add_sat(L_shl_sat(hp_bckr,1),hp_bckr); + hp_bckr = L_add_sat( L_shl_sat( hp_bckr, 1 ), hp_bckr ); #else - lp_bckr = L_add(L_shl(lp_bckr,1),lp_bckr); - hp_bckr = L_add(L_shl(hp_bckr,1),hp_bckr); + lp_bckr = L_add( L_shl( lp_bckr, 1 ), lp_bckr ); + hp_bckr = L_add( L_shl( hp_bckr, 1 ), hp_bckr ); #endif } /*mean_voi = 0.5f * (voicing[1] + voicing[2]) + corr_shift;*/ - Ltmp = L_mult(voicing[1], 16384); - Ltmp = L_mac(Ltmp, voicing[2], 16384); + Ltmp = L_mult( voicing[1], 16384 ); + Ltmp = L_mac( Ltmp, voicing[2], 16384 ); #ifdef BASOP_NOGLOB - Ltmp = L_mac_o(Ltmp,corr_shift, 32767, &Overflow); - mean_voi = round_fx_o(Ltmp, &Overflow); -#else - Ltmp = L_mac(Ltmp,corr_shift, 32767); - mean_voi = round_fx(Ltmp); + Ltmp = L_mac_o( Ltmp, corr_shift, 32767, &Overflow ); + mean_voi = round_fx_o( Ltmp, &Overflow ); +#else + Ltmp = L_mac( Ltmp, corr_shift, 32767 ); + mean_voi = round_fx( Ltmp ); #endif /*f0 = INT_FS_FX / pitch[2];*/ - e_tmp = norm_s(pitch[2]); - m_tmp = shl(pitch[2], e_tmp); + e_tmp = norm_s( pitch[2] ); + m_tmp = shl( pitch[2], e_tmp ); - m_Fs = div_s(INT_FS_FX, m_tmp); - e_Fs = sub(15, e_tmp); - f0 = shr(m_Fs, sub(e_Fs,4)); /* Q4 */ + m_Fs = div_s( INT_FS_FX, m_tmp ); + e_Fs = sub( 15, e_tmp ); + f0 = shr( m_Fs, sub( e_Fs, 4 ) ); /* Q4 */ - FOR( i=0; i<2; i++ ) + FOR( i = 0; i < 2; i++ ) { - /*hp_E[i] = 0.5f * (hf_bands[max_band-1] + hf_bands[max_band]) - hp_bckr; *//* averaged E in last 2 critical bands */ - Ltmp = L_add(L_shr(hf_bands[max_band-1], 1), L_shr(hf_bands[max_band], 1)); - hp_E[i] = L_sub(Ltmp, hp_bckr); - IF ( Opt_vbr_mode == 0 ) + /*hp_E[i] = 0.5f * (hf_bands[max_band-1] + hf_bands[max_band]) - hp_bckr; */ /* averaged E in last 2 critical bands */ + Ltmp = L_add( L_shr( hf_bands[max_band - 1], 1 ), L_shr( hf_bands[max_band], 1 ) ); + hp_E[i] = L_sub( Ltmp, hp_bckr ); + IF( Opt_vbr_mode == 0 ) { - hp_E[i] = L_max(hp_E[i], L_shl(E_MIN_FX, Q_new)); + hp_E[i] = L_max( hp_E[i], L_shl( E_MIN_FX, Q_new ) ); move32(); } ELSE { - hp_E[i] = L_max(hp_E[i], L_shl(1, scaling)); + hp_E[i] = L_max( hp_E[i], L_shl( 1, scaling ) ); move32(); } test(); - IF(GT_16(mean_voi,TH_COR_FX)&<_16(pitch[2],TH_PIT_FX)) /* High-pitched voiced frames */ + IF( GT_16( mean_voi, TH_COR_FX ) && LT_16( pitch[2], TH_PIT_FX ) ) /* High-pitched voiced frames */ { freq = bin; - move16(); /* 1st useful frequency bin */ + move16(); /* 1st useful frequency bin */ m_cnt = 0; move16(); - lp_E = L_deposit_l(0); + lp_E = L_deposit_l( 0 ); - f1 = add(shr(f0,1),f0); /* Middle between 2 harmonics */ + f1 = add( shr( f0, 1 ), f0 ); /* Middle between 2 harmonics */ f2 = f0; move16(); - WHILE(LE_16(freq, 20320)) /* End frequency of 10th critical band */ + WHILE( LE_16( freq, 20320 ) ) /* End frequency of 10th critical band */ { - FOR (; freq <= f1; freq += BIN4_FX) + FOR( ; freq <= f1; freq += BIN4_FX ) { /* include only bins sufficiently close to harmonics */ - tmp = sub(freq, f2); - IF(L_mac0(-(Word32)TH_D_FX*TH_D_FX, tmp, tmp) < 0) + tmp = sub( freq, f2 ); + IF( L_mac0( -(Word32) TH_D_FX * TH_D_FX, tmp, tmp ) < 0 ) { #ifdef BASOP_NOGLOB - lp_E = L_add_o(*pt_E, lp_E, &Overflow); -#else - lp_E = L_add(*pt_E, lp_E); + lp_E = L_add_o( *pt_E, lp_E, &Overflow ); +#else + lp_E = L_add( *pt_E, lp_E ); #endif - m_cnt = add(m_cnt, 1); + m_cnt = add( m_cnt, 1 ); } pt_E++; } #ifdef BASOP_NOGLOB - f1 = add_o(f1,f0, &Overflow); - f2 = add_o(f2, f0, &Overflow); -#else - f1 = add(f1,f0); - f2 = add(f2,f0); + f1 = add_o( f1, f0, &Overflow ); + f2 = add_o( f2, f0, &Overflow ); +#else + f1 = add( f1, f0 ); + f2 = add( f2, f0 ); #endif } /*lp_E = lp_E / (float)cnt - lp_bckr;*/ - e_tmp = sub(norm_l(lp_E), 1); - m_tmp = extract_h(L_shl(lp_E, e_tmp)); + e_tmp = sub( norm_l( lp_E ), 1 ); + m_tmp = extract_h( L_shl( lp_E, e_tmp ) ); - e_tmp = sub(e_tmp,2); /* lf_e divided by 4 in anal_sp */ + e_tmp = sub( e_tmp, 2 ); /* lf_e divided by 4 in anal_sp */ - e_cnt = norm_s(m_cnt); - m_cnt = shl(m_cnt, e_cnt); + e_cnt = norm_s( m_cnt ); + m_cnt = shl( m_cnt, e_cnt ); - m_tmp = div_s(m_tmp, m_cnt); - e_tmp = sub(e_tmp, e_cnt); + m_tmp = div_s( m_tmp, m_cnt ); + e_tmp = sub( e_tmp, e_cnt ); #ifdef BASOP_NOGLOB - lp_E = L_sub_o(L_shr_o(m_tmp, sub(e_tmp, 1), &Overflow), lp_bckr, &Overflow); + lp_E = L_sub_o( L_shr_o( m_tmp, sub( e_tmp, 1 ), &Overflow ), lp_bckr, &Overflow ); #else - lp_E = L_sub(L_shr(m_tmp, sub(e_tmp, 1)), lp_bckr); + lp_E = L_sub( L_shr( m_tmp, sub( e_tmp, 1 ) ), lp_bckr ); #endif - pt_E = tmp_E + VOIC_BINS; /* Update for next half-frame */ + pt_E = tmp_E + VOIC_BINS; /* Update for next half-frame */ } - ELSE /* Other than high-pitched voiced frames */ + ELSE /* Other than high-pitched voiced frames */ { /*lp_E = mean( pt_bands, nb_bands ) - lp_bckr;*/ /* averaged E in first critical bands, up to 1270 Hz */ - lp_E = L_sub(Mean32( pt_bands, nb_bands ) , lp_bckr); + lp_E = L_sub( Mean32( pt_bands, nb_bands ), lp_bckr ); } - IF ( Opt_vbr_mode == 0 ) + IF( Opt_vbr_mode == 0 ) { - lp_E = L_max(lp_E, L_shl(E_MIN_FX,Q_new)); + lp_E = L_max( lp_E, L_shl( E_MIN_FX, Q_new ) ); } ELSE { - lp_E = L_max(lp_E, 0); + lp_E = L_max( lp_E, 0 ); } - /*ee[i] = lp_E / hp_E[i];*/ /* LF/HF ratio */ + /*ee[i] = lp_E / hp_E[i];*/ /* LF/HF ratio */ test(); - IF (lp_E != 0 && hp_E[i] != 0) + IF( lp_E != 0 && hp_E[i] != 0 ) { - e_tmp = sub(norm_l(lp_E), 1); - m_tmp = extract_h(L_shl(lp_E, e_tmp)); - e_hpE = norm_l(hp_E[i]); - m_hpE = extract_h(L_shl(hp_E[i], e_hpE)); - m_tmp = div_s(m_tmp, m_hpE); - e_tmp = sub(e_tmp, e_hpE); + e_tmp = sub( norm_l( lp_E ), 1 ); + m_tmp = extract_h( L_shl( lp_E, e_tmp ) ); + e_hpE = norm_l( hp_E[i] ); + m_hpE = extract_h( L_shl( hp_E[i], e_hpE ) ); + m_tmp = div_s( m_tmp, m_hpE ); + e_tmp = sub( e_tmp, e_hpE ); #ifdef BASOP_NOGLOB - ee[i] = L_shr_o(m_tmp, add(e_tmp, 15-6), &Overflow); /* ee in Q6 */ -#else /* BASOP_NOGLOB */ - ee[i] = L_shr(m_tmp, add(e_tmp, 15-6)); /* ee in Q6 */ + ee[i] = L_shr_o( m_tmp, add( e_tmp, 15 - 6 ), &Overflow ); /* ee in Q6 */ +#else /* BASOP_NOGLOB */ + ee[i] = L_shr( m_tmp, add( e_tmp, 15 - 6 ) ); /* ee in Q6 */ #endif } - ELSE IF (lp_E == 0) + ELSE IF( lp_E == 0 ) { - ee[i] = L_deposit_l(0); + ee[i] = L_deposit_l( 0 ); } ELSE { ee[i] = MAX_32; } - IF( EQ_16(bwidth,NB)) /* For NB input, compensate for the missing bands */ + IF( EQ_16( bwidth, NB ) ) /* For NB input, compensate for the missing bands */ { #ifdef BASOP_NOGLOB - Ltmp = L_shl_o(ee[i], 3, &Overflow); + Ltmp = L_shl_o( ee[i], 3, &Overflow ); #else - Ltmp = L_shl(ee[i], 3); + Ltmp = L_shl( ee[i], 3 ); #endif - IF (EQ_32(Ltmp, MAX_32)) /* if Overflow: Compute with less precision */ + IF( EQ_32( Ltmp, MAX_32 ) ) /* if Overflow: Compute with less precision */ { - Ltmp = Mult_32_16(ee[i], 24576); /* 6/8 */ + Ltmp = Mult_32_16( ee[i], 24576 ); /* 6/8 */ #ifdef BASOP_NOGLOB ee[i] = L_shl_sat( Ltmp, 3 ); #else - ee[i] = L_shl(Ltmp, 3); + ee[i] = L_shl( Ltmp, 3 ); #endif - move32(); /* x8 */ + move32(); /* x8 */ } ELSE { - ee[i] = Mult_32_16(Ltmp, 24576); - move32();/* 6/8 */ + ee[i] = Mult_32_16( Ltmp, 24576 ); + move32(); /* 6/8 */ } } - pt_bands += NB_BANDS; /* Update for next half-frame */ + pt_bands += NB_BANDS; /* Update for next half-frame */ hf_bands += NB_BANDS; } diff --git a/lib_enc/find_uv_fx.c b/lib_enc/find_uv_fx.c index 4be2524b3..dbe7714c9 100644 --- a/lib_enc/find_uv_fx.c +++ b/lib_enc/find_uv_fx.c @@ -2,20 +2,19 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ //#include "prot_fx.h" /* Function prototypes */ -#include "rom_com.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "rom_com.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* * Local constants *-------------------------------------------------------------------*/ -#define L_ENR (NB_SSF+2) - +#define L_ENR ( NB_SSF + 2 ) /*-------------------------------------------------------------------* @@ -25,9 +24,9 @@ * energy is trailing off after a spike *-------------------------------------------------------------------*/ -static Word16 find_ener_decrease_fx( /* o : maximum energy ratio Q10 */ - const Word16 ind_deltaMax, /* i : index of the beginning of maximum energy search */ - const Word32 *pt_enr_ssf /* i : Pointer to the energy buffer */ +static Word16 find_ener_decrease_fx( /* o : maximum energy ratio Q10 */ + const Word16 ind_deltaMax, /* i : index of the beginning of maximum energy search */ + const Word32 *pt_enr_ssf /* i : Pointer to the energy buffer */ ) { Word16 i, j, end, flag; @@ -41,21 +40,21 @@ static Word16 find_ener_decrease_fx( /* o : maximum energy ratio Q10 dE2 = 0; move16(); - j = ind_deltaMax+2; + j = ind_deltaMax + 2; move16(); - end = j+L_ENR; + end = j + L_ENR; move16(); - maxEnr = L_add(pt_enr_ssf[j], 0); - j = add(j, 1); + maxEnr = L_add( pt_enr_ssf[j], 0 ); + j = add( j, 1 ); flag = 0; move16(); - FOR( i=j; ihNoiseEst; - SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; + NOISE_EST_HANDLE hNoiseEst = st_fx->hNoiseEst; + SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - Word16 Last_Resort; + Word16 Last_Resort; Word16 vadnoise; - IF (hSC_VBR != NULL) + IF( hSC_VBR != NULL ) { Last_Resort = hSC_VBR->Last_Resort; vadnoise = hSC_VBR->vadnoise_fx; @@ -152,7 +152,7 @@ Word16 find_uv_fx( /* o : coding type vadnoise = 0; } - Q_in = sub(Q_new,1); + Q_in = sub( Q_new, 1 ); /*-----------------------------------------------------------------* * Detect sudden energy increases to catch voice and music @@ -165,11 +165,11 @@ Word16 find_uv_fx( /* o : coding type /* Find maximum energy per short subblocks */ pt_speech = speech - SSF; - pt_enr_ssf = enr_ssf + 2*NB_SSF; - FOR( i=0 ; i < 2*(NB_SSF+1) ; i++ ) + pt_enr_ssf = enr_ssf + 2 * NB_SSF; + FOR( i = 0; i < 2 * ( NB_SSF + 1 ); i++ ) { - emaximum_fx(Q_in, pt_speech, SSF, pt_enr_ssf ); - pt_speech += (SSF/2); + emaximum_fx( Q_in, pt_speech, SSF, pt_enr_ssf ); + pt_speech += ( SSF / 2 ); pt_enr_ssf++; } @@ -177,42 +177,42 @@ Word16 find_uv_fx( /* o : coding type move16(); ind_deltaMax = 0; move16(); - pt_enr_ssf = enr_ssf + 2*NB_SSF; + pt_enr_ssf = enr_ssf + 2 * NB_SSF; pt_enr_ssf1 = pt_enr_ssf + 2; /* Test on energy increase between adjacent sub-subframes */ exp1 = 0; move16(); - FOR( i=0; i < 2*NB_SSF; i++ ) + FOR( i = 0; i < 2 * NB_SSF; i++ ) { /*fac = *pt_enr_ssf1 / (*pt_enr_ssf + 1);*/ - Ltmp0 = L_max(*pt_enr_ssf, 1); - exp0 = norm_l(Ltmp0); - wtmp0 = extract_h(L_shl(Ltmp0, exp0)); - exp1 = sub(norm_l(*pt_enr_ssf1),1); - wtmp1 = extract_h(L_shl(*pt_enr_ssf1, exp1)); - fac = div_s(wtmp1,wtmp0); + Ltmp0 = L_max( *pt_enr_ssf, 1 ); + exp0 = norm_l( Ltmp0 ); + wtmp0 = extract_h( L_shl( Ltmp0, exp0 ) ); + exp1 = sub( norm_l( *pt_enr_ssf1 ), 1 ); + wtmp1 = extract_h( L_shl( *pt_enr_ssf1, exp1 ) ); + fac = div_s( wtmp1, wtmp0 ); #ifdef BASOP_NOGLOB - fac_32 = L_shr_o(L_deposit_l(fac), add(sub(exp1, exp0),15-13), &Overflow); /* fac32 in Q13*/ -#else /* BASOP_NOGLOB */ - fac_32 = L_shr(L_deposit_l(fac), add(sub(exp1, exp0),15-13)); /* fac32 in Q13*/ -#endif /* BASOP_NOGLOB */ + fac_32 = L_shr_o( L_deposit_l( fac ), add( sub( exp1, exp0 ), 15 - 13 ), &Overflow ); /* fac32 in Q13*/ +#else /* BASOP_NOGLOB */ + fac_32 = L_shr( L_deposit_l( fac ), add( sub( exp1, exp0 ), 15 - 13 ) ); /* fac32 in Q13*/ +#endif /* BASOP_NOGLOB */ - if(GT_32(fac_32, dE1 )) + if ( GT_32( fac_32, dE1 ) ) { ind_deltaMax = i; move16(); } - dE1 = L_max(dE1, fac_32); + dE1 = L_max( dE1, fac_32 ); pt_enr_ssf++; pt_enr_ssf1++; } #ifdef IVAS_CODE - IF (hStereoClassif != NULL) + IF( hStereoClassif != NULL ) { - IF (st_fx->idchan == 0) + IF( st_fx->idchan == 0 ) { hStereoClassif->dE1_ch1 = dE1; } @@ -222,7 +222,7 @@ Word16 find_uv_fx( /* o : coding type } } - if (dE1X != NULL) + if ( dE1X != NULL ) { *dE1X = dE1; move32(); @@ -233,45 +233,45 @@ Word16 find_uv_fx( /* o : coding type * Average voicing (normalized correlation) *-----------------------------------------------------------------*/ - /*mean_ee = 1.0f/3.0f * (st->ee_old + ee[0] + ee[1]); */ /* coefficients take into account the position of the window */ + /*mean_ee = 1.0f/3.0f * (st->ee_old + ee[0] + ee[1]); */ /* coefficients take into account the position of the window */ #ifdef BASOP_NOGLOB - mean_ee = L_add_o(L_add_o(st_fx->ee_old_fx, ee[0], &Overflow), ee[1], &Overflow); -#else /* BASOP_NOGLOB */ - mean_ee = L_add(L_add(st_fx->ee_old_fx, ee[0]), ee[1]); -#endif /* BASOP_NOGLOB */ - mean_ee = Mult_32_16(mean_ee, 10923); /*Q6*/ + mean_ee = L_add_o( L_add_o( st_fx->ee_old_fx, ee[0], &Overflow ), ee[1], &Overflow ); +#else /* BASOP_NOGLOB */ + mean_ee = L_add( L_add( st_fx->ee_old_fx, ee[0] ), ee[1] ); +#endif /* BASOP_NOGLOB */ + mean_ee = Mult_32_16( mean_ee, 10923 ); /*Q6*/ /* mean_voi3 = 1.0f/3.0f * (voicing[0] + voicing[1] + voicing[2]);*/ - Ltmp0 = L_mult( st_fx->voicing_fx[0], 10923); - Ltmp0 = L_mac(Ltmp0, st_fx->voicing_fx[1], 10923); + Ltmp0 = L_mult( st_fx->voicing_fx[0], 10923 ); + Ltmp0 = L_mac( Ltmp0, st_fx->voicing_fx[1], 10923 ); #ifdef BASOP_NOGLOB // -dtx 12650 amrwb\Dtx3.INP mean_voi3 = mac_r_sat( Ltmp0, st_fx->voicing_fx[2], 10923 ); /*Q15*/ #else - mean_voi3 = mac_r(Ltmp0, st_fx->voicing_fx[2], 10923); /*Q15*/ + mean_voi3 = mac_r( Ltmp0, st_fx->voicing_fx[2], 10923 ); /*Q15*/ #endif /*-----------------------------------------------------------------* * Total frame energy difference (dE3) *-----------------------------------------------------------------*/ - dE3 = sub(Etot, hNoiseEst->Etot_last_fx); /*Q8*/ + dE3 = sub( Etot, hNoiseEst->Etot_last_fx ); /*Q8*/ /*-----------------------------------------------------------------* - * Energy decrease after spike (dE2) - *-----------------------------------------------------------------*/ + * Energy decrease after spike (dE2) + *-----------------------------------------------------------------*/ /* set different thresholds and conditions for NB and WB input */ - dE2_th = 30<<10; + dE2_th = 30 << 10; move32(); nb_cond = 1; move16(); /* no additional condition for WB input */ - IF ( EQ_16(st_fx->input_bwidth,NB)) + IF( EQ_16( st_fx->input_bwidth, NB ) ) { - dE2_th = 21<<10; + dE2_th = 21 << 10; move32(); #ifdef BASOP_NOGLOB - if(GE_16(add_o(mean_voi3, corr_shift, &Overflow), 22282)) /*( mean_voi3 + corr_shift ) >= 0.68f*/ + if ( GE_16( add_o( mean_voi3, corr_shift, &Overflow ), 22282 ) ) /*( mean_voi3 + corr_shift ) >= 0.68f*/ #else - if(GE_16(add(mean_voi3, corr_shift), 22282)) /*( mean_voi3 + corr_shift ) >= 0.68f*/ + if ( GE_16( add( mean_voi3, corr_shift ), 22282 ) ) /*( mean_voi3 + corr_shift ) >= 0.68f*/ #endif { nb_cond = 0; @@ -281,25 +281,25 @@ Word16 find_uv_fx( /* o : coding type /* calcualte maximum energy decrease */ dE2 = 0; - move16(); /* Test on energy decrease after an energy spike */ - pt_enr_ssf = enr_ssf + 2*NB_SSF; + move16(); /* Test on energy decrease after an energy spike */ + pt_enr_ssf = enr_ssf + 2 * NB_SSF; test(); - IF( GT_32(dE1, 30<<13)&&nb_cond) /*>30 Q13*/ + IF( GT_32( dE1, 30 << 13 ) && nb_cond ) /*>30 Q13*/ { - IF( LT_16(sub(shl(NB_SSF,1), ind_deltaMax),L_ENR)) + IF( LT_16( sub( shl( NB_SSF, 1 ), ind_deltaMax ), L_ENR ) ) { st_fx->old_ind_deltaMax = ind_deltaMax; move16(); - Copy32( pt_enr_ssf, st_fx->old_enr_ssf_fx, 2*NB_SSF ); + Copy32( pt_enr_ssf, st_fx->old_enr_ssf_fx, 2 * NB_SSF ); } ELSE { st_fx->old_ind_deltaMax = -1; move16(); - dE2 = find_ener_decrease_fx( ind_deltaMax, pt_enr_ssf ); /*Q10*/ + dE2 = find_ener_decrease_fx( ind_deltaMax, pt_enr_ssf ); /*Q10*/ - if( GT_32(dE2,dE2_th)) + if ( GT_32( dE2, dE2_th ) ) { st_fx->spike_hyst = 0; move16(); @@ -310,10 +310,10 @@ Word16 find_uv_fx( /* o : coding type { IF( st_fx->old_ind_deltaMax >= 0 ) { - Copy32( st_fx->old_enr_ssf_fx, enr_ssf, 2*NB_SSF ); + Copy32( st_fx->old_enr_ssf_fx, enr_ssf, 2 * NB_SSF ); dE2 = find_ener_decrease_fx( st_fx->old_ind_deltaMax, enr_ssf ); - if( GT_32(dE2,dE2_th)) + if ( GT_32( dE2, dE2_th ) ) { st_fx->spike_hyst = 1; move16(); @@ -331,29 +331,33 @@ Word16 find_uv_fx( /* o : coding type tmp_offset_flag = 1; move16(); - IF ( NE_16(st_fx->input_bwidth, NB)) + IF( NE_16( st_fx->input_bwidth, NB ) ) { - ee0_th = 154; /*2.4 in Q6 */ move16(); - voi_th = 24248; /*0.74f Q15 */ move16(); + ee0_th = 154; /*2.4 in Q6 */ + move16(); + voi_th = 24248; /*0.74f Q15 */ + move16(); } ELSE { - ee0_th = 627; /*9.8f Q6 */ move16(); - voi_th = 24904; /*0.76f Q15*/ move16(); + ee0_th = 627; /*9.8f Q6 */ + move16(); + voi_th = 24904; /*0.76f Q15*/ + move16(); } test(); test(); test(); #ifdef BASOP_NOGLOB - if( ( EQ_16(st_fx->last_coder_type_raw,UNVOICED))|| /* previous frame was unvoiced */ - ( ( LT_32(ee[0],ee0_th) ) && ( GT_32(hp_E[0],L_shl(E_MIN_FX,Q_new)) ) && /* energy is concentrated in high frequencies provided that some energy is present in HF */ - ( LT_16(add_o(st_fx->voicing_fx[0],corr_shift, &Overflow),voi_th)))) /* normalized correlation is low */ -#else /* BASOP_NOGLOB */ - if( ( EQ_16(st_fx->last_coder_type_raw,UNVOICED))|| /* previous frame was unvoiced */ - ( ( LT_32(ee[0],ee0_th) ) && ( GT_32(hp_E[0],L_shl(E_MIN_FX,Q_new)) ) && /* energy is concentrated in high frequencies provided that some energy is present in HF */ - ( LT_16(add(st_fx->voicing_fx[0],corr_shift),voi_th)))) /* normalized correlation is low */ -#endif /* BASOP_NOGLOB */ + if ( ( EQ_16( st_fx->last_coder_type_raw, UNVOICED ) ) || /* previous frame was unvoiced */ + ( ( LT_32( ee[0], ee0_th ) ) && ( GT_32( hp_E[0], L_shl( E_MIN_FX, Q_new ) ) ) && /* energy is concentrated in high frequencies provided that some energy is present in HF */ + ( LT_16( add_o( st_fx->voicing_fx[0], corr_shift, &Overflow ), voi_th ) ) ) ) /* normalized correlation is low */ +#else /* BASOP_NOGLOB */ + if ( ( EQ_16( st_fx->last_coder_type_raw, UNVOICED ) ) || /* previous frame was unvoiced */ + ( ( LT_32( ee[0], ee0_th ) ) && ( GT_32( hp_E[0], L_shl( E_MIN_FX, Q_new ) ) ) && /* energy is concentrated in high frequencies provided that some energy is present in HF */ + ( LT_16( add( st_fx->voicing_fx[0], corr_shift ), voi_th ) ) ) ) /* normalized correlation is low */ +#endif /* BASOP_NOGLOB */ { tmp_offset_flag = 0; move16(); @@ -368,34 +372,36 @@ Word16 find_uv_fx( /* o : coding type move16(); flag_low_relE = 0; move16(); - ee1_th = 608; /*9.5 Q6*/ move16(); - IF ( st_fx->Opt_SC_VBR || (EQ_16(st_fx->idchan, 1) && EQ_16(st_fx->element_mode, IVAS_CPE_TD))) /* Allow the low energy flag for the secondary channel */ + ee1_th = 608; /*9.5 Q6*/ + move16(); + IF( st_fx->Opt_SC_VBR || ( EQ_16( st_fx->idchan, 1 ) && EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) ) /* Allow the low energy flag for the secondary channel */ { - ee1_th = 544; /*8.5f Q6*/ move16(); + ee1_th = 544; /*8.5f Q6*/ + move16(); /* SC-VBR - determine the threshold on relative energy as a function of lp_noise */ - IF ( NE_16(st_fx->input_bwidth,NB)) + IF( NE_16( st_fx->input_bwidth, NB ) ) { /*relE_thres = 0.700f * st->lp_noise - 33.5f; (lp_noise in Q8, constant Q8<<16) */ - L_tmp = L_mac(-562036736, 22938, st_fx->lp_noise_fx); + L_tmp = L_mac( -562036736, 22938, st_fx->lp_noise_fx ); if ( Last_Resort == 0 ) { /*relE_thres = 0.650f * st->lp_noise - 33.5f; (lp_noise in Q8, constant Q8<<16)*/ - L_tmp = L_mac(-562036736, 21299, st_fx->lp_noise_fx); + L_tmp = L_mac( -562036736, 21299, st_fx->lp_noise_fx ); } - relE_thres = round_fx(L_tmp); + relE_thres = round_fx( L_tmp ); } ELSE { /*relE_thres = 0.60f * st->lp_noise - 28.2f; (lp_noise in Q8, constant Q8<<16)*/ - L_tmp = L_mac(-473117491, 19661, st_fx->lp_noise_fx); - relE_thres = round_fx(L_tmp); + L_tmp = L_mac( -473117491, 19661, st_fx->lp_noise_fx ); + relE_thres = round_fx( L_tmp ); } - relE_thres = s_max(relE_thres , -6400); /* Q8 */ + relE_thres = s_max( relE_thres, -6400 ); /* Q8 */ /* SC-VBR = set flag on low relative energy */ - if ( LT_16(relE,relE_thres)) + if ( LT_16( relE, relE_thres ) ) { flag_low_relE = 1; move16(); @@ -403,17 +409,18 @@ Word16 find_uv_fx( /* o : coding type /* SC-VBR - correction of voicing threshold for NB inputs (important only in noisy conditions) */ test(); - if ( EQ_16(st_fx->input_bwidth,NB)&<_16( vadnoise ,20<<8)) /* vadnoise in Q8, constant Q0<<8 */ + if ( EQ_16( st_fx->input_bwidth, NB ) && LT_16( vadnoise, 20 << 8 ) ) /* vadnoise in Q8, constant Q0<<8 */ { - mean_voi3_offset = 1638; /*0.05f Q15*/ move16(); + mean_voi3_offset = 1638; /*0.05f Q15*/ + move16(); } } /* make decision whether frame is unvoiced */ - E_min_th = L_shl(E_MIN_FX,Q_new); + E_min_th = L_shl( E_MIN_FX, Q_new ); coder_type = GENERIC; move16(); - IF ( EQ_16(st_fx->input_bwidth,NB)) + IF( EQ_16( st_fx->input_bwidth, NB ) ) { test(); test(); @@ -427,27 +434,27 @@ Word16 find_uv_fx( /* o : coding type test(); test(); #ifdef BASOP_NOGLOB - if( ( ( LT_16(add_o(mean_voi3, corr_shift, &Overflow),add(22282,mean_voi3_offset)))&& /* normalized correlation low */ - ( LT_16(add_o(st_fx->voicing_fx[2], corr_shift, &Overflow),25887) ) && /* normalized correlation low on look-ahead - onset detection */ - ( LT_32(ee[0], 640) ) && ( GT_32(hp_E[0], E_min_th) ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */ - ( LT_32(ee[1], ee1_th) ) && ( GT_32(hp_E[1], E_min_th) ) && /* ... biased towards look-ahead to detect onsets */ - ( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */ - /*( st_fx->music_hysteresis_fx == 0 ) &&*/ /* ... and in segment after AUDIO frames */ - ( LE_32(dE1, 237568) ) && /* Avoid on sharp energy spikes */ - ( LE_32(st_fx->old_dE1_fx,237568) ) && /* + one frame hysteresis */ - ( st_fx->spike_hyst < 0 ) ) || /* Avoid after sharp energy spikes followed by decay (e.g. castanets) */ - flag_low_relE ) /* low relative frame energy (only for SC-VBR) */ + if ( ( ( LT_16( add_o( mean_voi3, corr_shift, &Overflow ), add( 22282, mean_voi3_offset ) ) ) && /* normalized correlation low */ + ( LT_16( add_o( st_fx->voicing_fx[2], corr_shift, &Overflow ), 25887 ) ) && /* normalized correlation low on look-ahead - onset detection */ + ( LT_32( ee[0], 640 ) ) && ( GT_32( hp_E[0], E_min_th ) ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */ + ( LT_32( ee[1], ee1_th ) ) && ( GT_32( hp_E[1], E_min_th ) ) && /* ... biased towards look-ahead to detect onsets */ + ( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */ + /*( st_fx->music_hysteresis_fx == 0 ) &&*/ /* ... and in segment after AUDIO frames */ + ( LE_32( dE1, 237568 ) ) && /* Avoid on sharp energy spikes */ + ( LE_32( st_fx->old_dE1_fx, 237568 ) ) && /* + one frame hysteresis */ + ( st_fx->spike_hyst < 0 ) ) || /* Avoid after sharp energy spikes followed by decay (e.g. castanets) */ + flag_low_relE ) /* low relative frame energy (only for SC-VBR) */ #else - if( ( ( LT_16(add(mean_voi3, corr_shift),add(22282,mean_voi3_offset)))&& /* normalized correlation low */ - ( LT_16(add(st_fx->voicing_fx[2], corr_shift),25887) ) && /* normalized correlation low on look-ahead - onset detection */ - ( LT_32(ee[0], 640) ) && ( GT_32(hp_E[0], E_min_th) ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */ - ( LT_32(ee[1], ee1_th) ) && ( GT_32(hp_E[1], E_min_th) ) && /* ... biased towards look-ahead to detect onsets */ - ( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */ - /*( st_fx->music_hysteresis_fx == 0 ) &&*/ /* ... and in segment after AUDIO frames */ - ( LE_32(dE1, 237568) ) && /* Avoid on sharp energy spikes */ - ( LE_32(st_fx->old_dE1_fx,237568) ) && /* + one frame hysteresis */ - ( st_fx->spike_hyst < 0 ) ) || /* Avoid after sharp energy spikes followed by decay (e.g. castanets) */ - flag_low_relE ) /* low relative frame energy (only for SC-VBR) */ + if ( ( ( LT_16( add( mean_voi3, corr_shift ), add( 22282, mean_voi3_offset ) ) ) && /* normalized correlation low */ + ( LT_16( add( st_fx->voicing_fx[2], corr_shift ), 25887 ) ) && /* normalized correlation low on look-ahead - onset detection */ + ( LT_32( ee[0], 640 ) ) && ( GT_32( hp_E[0], E_min_th ) ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */ + ( LT_32( ee[1], ee1_th ) ) && ( GT_32( hp_E[1], E_min_th ) ) && /* ... biased towards look-ahead to detect onsets */ + ( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */ + /*( st_fx->music_hysteresis_fx == 0 ) &&*/ /* ... and in segment after AUDIO frames */ + ( LE_32( dE1, 237568 ) ) && /* Avoid on sharp energy spikes */ + ( LE_32( st_fx->old_dE1_fx, 237568 ) ) && /* + one frame hysteresis */ + ( st_fx->spike_hyst < 0 ) ) || /* Avoid after sharp energy spikes followed by decay (e.g. castanets) */ + flag_low_relE ) /* low relative frame energy (only for SC-VBR) */ #endif { coder_type = UNVOICED; @@ -469,26 +476,23 @@ Word16 find_uv_fx( /* o : coding type test(); test(); #ifdef BASOP_NOGLOB - if( ( ( LT_16(add_o(mean_voi3, corr_shift, &Overflow), add(22774,mean_voi3_offset)))&& /* normalized correlation low */ -#else /* BASOP_NOGLOB */ - if( ( ( LT_16(add(mean_voi3, corr_shift),add(22774,mean_voi3_offset)))&& /* normalized correlation low */ + if ( ( ( LT_16( add_o( mean_voi3, corr_shift, &Overflow ), add( 22774, mean_voi3_offset ) ) ) && /* normalized correlation low */ +#else /* BASOP_NOGLOB */ + if ( ( ( LT_16( add( mean_voi3, corr_shift ), add( 22774, mean_voi3_offset ) ) ) && /* normalized correlation low */ #endif #ifdef BASOP_NOGLOB - ( LT_16(add_sat(st_fx->voicing_fx[2], corr_shift),25887) ) && /* normalized correlation low on look-ahead - onset detection */ + ( LT_16( add_sat( st_fx->voicing_fx[2], corr_shift ), 25887 ) ) && /* normalized correlation low on look-ahead - onset detection */ #else - ( LT_16(add(st_fx->voicing_fx[2], corr_shift),25887) ) && /* normalized correlation low on look-ahead - onset detection */ + ( LT_16( add( st_fx->voicing_fx[2], corr_shift ), 25887 ) ) && /* normalized correlation low on look-ahead - onset detection */ #endif - ( LT_32(ee[0], 397) ) && ( GT_32(hp_E[0], E_min_th) ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */ - ( LT_32(ee[1], 397) ) && ( GT_32(hp_E[1], E_min_th) ) && /* ... biased towards look-ahead to detect onsets */ - ( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */ - /*( st_fx->music_hysteresis_fx == 0 ) && */ /* ... and in segment after AUDIO frames */ - ( LE_32(dE1, 245760) ) && /* Avoid on sharp energy spikes */ - ( LE_32(st_fx->old_dE1_fx,245760) ) && /* + one frame hysteresis */ - ( st_fx->spike_hyst < 0 ) ) /* Avoid after sharp energy spikes followed by decay (e.g. castanets) */ - || ( flag_low_relE - && ( LE_32(st_fx->old_dE1_fx,245760) ) - ) - ) /* low relative frame energy (only for SC-VBR) */ + ( LT_32( ee[0], 397 ) ) && ( GT_32( hp_E[0], E_min_th ) ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */ + ( LT_32( ee[1], 397 ) ) && ( GT_32( hp_E[1], E_min_th ) ) && /* ... biased towards look-ahead to detect onsets */ + ( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */ + /*( st_fx->music_hysteresis_fx == 0 ) && */ /* ... and in segment after AUDIO frames */ + ( LE_32( dE1, 245760 ) ) && /* Avoid on sharp energy spikes */ + ( LE_32( st_fx->old_dE1_fx, 245760 ) ) && /* + one frame hysteresis */ + ( st_fx->spike_hyst < 0 ) ) /* Avoid after sharp energy spikes followed by decay (e.g. castanets) */ + || ( flag_low_relE && ( LE_32( st_fx->old_dE1_fx, 245760 ) ) ) ) /* low relative frame energy (only for SC-VBR) */ { coder_type = UNVOICED; move16(); @@ -498,7 +502,7 @@ Word16 find_uv_fx( /* o : coding type /*-----------------------------------------------------------------* * Decision about VC *-----------------------------------------------------------------*/ - if (st_fx->Opt_SC_VBR) + if ( st_fx->Opt_SC_VBR ) { hSC_VBR->set_ppp_generic = 0; } @@ -506,11 +510,11 @@ Word16 find_uv_fx( /* o : coding type test(); test(); - IF( EQ_16(st_fx->localVAD,1)&&EQ_16(coder_type,GENERIC)&&NE_16(last_core_orig,AMR_WB_CORE)) + IF( EQ_16( st_fx->localVAD, 1 ) && EQ_16( coder_type, GENERIC ) && NE_16( last_core_orig, AMR_WB_CORE ) ) { - dpit1 = abs_s( sub(T_op_fr[1], T_op_fr[0])); - dpit2 = abs_s( sub(T_op_fr[2], T_op_fr[1])); - dpit3 = abs_s( sub(T_op_fr[3], T_op_fr[2])); + dpit1 = abs_s( sub( T_op_fr[1], T_op_fr[0] ) ); + dpit2 = abs_s( sub( T_op_fr[2], T_op_fr[1] ) ); + dpit3 = abs_s( sub( T_op_fr[3], T_op_fr[2] ) ); test(); test(); @@ -521,19 +525,19 @@ Word16 find_uv_fx( /* o : coding type test(); test(); test(); - IF( ( GT_16(voicing_fr[0],19825))&& /* normalized correlation high in 1st sf. */ - ( GT_16(voicing_fr[1],19825) ) && /* normalized correlation high in 2st sf. */ - ( GT_16(voicing_fr[2],19825) ) && /* normalized correlation high in 3st sf. */ - ( GT_16(voicing_fr[3],19825) ) && /* normalized correlation high in 4st sf. */ - ( GT_32(mean_ee,256) ) && /* energy concentrated in low frequencies */ - ( LT_16(dpit1,3<<6) ) && - ( LT_16(dpit2,3<<6) ) && - ( LT_16(dpit3,3<<6) ) ) + IF( ( GT_16( voicing_fr[0], 19825 ) ) && /* normalized correlation high in 1st sf. */ + ( GT_16( voicing_fr[1], 19825 ) ) && /* normalized correlation high in 2st sf. */ + ( GT_16( voicing_fr[2], 19825 ) ) && /* normalized correlation high in 3st sf. */ + ( GT_16( voicing_fr[3], 19825 ) ) && /* normalized correlation high in 4st sf. */ + ( GT_32( mean_ee, 256 ) ) && /* energy concentrated in low frequencies */ + ( LT_16( dpit1, 3 << 6 ) ) && + ( LT_16( dpit2, 3 << 6 ) ) && + ( LT_16( dpit3, 3 << 6 ) ) ) { coder_type = VOICED; move16(); } - ELSE IF ( st_fx->Opt_SC_VBR && EQ_16(st_fx->input_bwidth,NB) && LT_16(vadnoise,20<<8)) + ELSE IF( st_fx->Opt_SC_VBR && EQ_16( st_fx->input_bwidth, NB ) && LT_16( vadnoise, 20 << 8 ) ) { test(); test(); @@ -542,14 +546,14 @@ Word16 find_uv_fx( /* o : coding type test(); test(); test(); - IF( GT_16(voicing_fr[0],8192)&& /* normalized correlation high in 1st sf. */ - ( GT_16(voicing_fr[1],8192) ) && /* normalized correlation high in 2st sf. */ - ( GT_16(voicing_fr[2],8192) ) && /* normalized correlation high in 3st sf. */ - ( GT_16(voicing_fr[3],8192) ) && /* normalized correlation high in 4st sf. */ - ( GT_32(mean_ee,64) ) && /* energy concentrated in low frequencies */ - ( LT_16(dpit1,5<<6) ) && - ( LT_16(dpit2,5<<6) ) && - ( LT_16(dpit3,5<<6) ) ) + IF( GT_16( voicing_fr[0], 8192 ) && /* normalized correlation high in 1st sf. */ + ( GT_16( voicing_fr[1], 8192 ) ) && /* normalized correlation high in 2st sf. */ + ( GT_16( voicing_fr[2], 8192 ) ) && /* normalized correlation high in 3st sf. */ + ( GT_16( voicing_fr[3], 8192 ) ) && /* normalized correlation high in 4st sf. */ + ( GT_32( mean_ee, 64 ) ) && /* energy concentrated in low frequencies */ + ( LT_16( dpit1, 5 << 6 ) ) && + ( LT_16( dpit2, 5 << 6 ) ) && + ( LT_16( dpit3, 5 << 6 ) ) ) { hSC_VBR->set_ppp_generic = 1; move16(); @@ -560,19 +564,19 @@ Word16 find_uv_fx( /* o : coding type /* set VOICED mode for frames with very stable pitch and high correlation and avoid to switch to AUDIO/MUSIC later */ - voicing_m = mac_r(L_mac(L_mac(L_mult(voicing_fr[3], 8192), voicing_fr[2], 8192),voicing_fr[1], 8192),voicing_fr[0], 8192); + voicing_m = mac_r( L_mac( L_mac( L_mult( voicing_fr[3], 8192 ), voicing_fr[2], 8192 ), voicing_fr[1], 8192 ), voicing_fr[0], 8192 ); test(); test(); test(); test(); test(); - IF ( *flag_spitch || ( LE_16(dpit1,3<<6)&&LE_16(dpit2,3<<6)&&LE_16(dpit3,3<<6)&& - GT_16(voicing_m, 31130) && GT_16(st_fx->voicing_sm_fx, 31785) ) ) + IF( *flag_spitch || ( LE_16( dpit1, 3 << 6 ) && LE_16( dpit2, 3 << 6 ) && LE_16( dpit3, 3 << 6 ) && + GT_16( voicing_m, 31130 ) && GT_16( st_fx->voicing_sm_fx, 31785 ) ) ) { coder_type = VOICED; move16(); *flag_spitch = 1; - move16();/*to avoid switch to AUDIO/MUSIC later*/ + move16(); /*to avoid switch to AUDIO/MUSIC later*/ } } @@ -583,24 +587,24 @@ Word16 find_uv_fx( /* o : coding type st_fx->rf_mode = st_fx->Opt_RF_ON; move16(); - IF ( EQ_16 ( coder_type, GENERIC ) ) + IF( EQ_16( coder_type, GENERIC ) ) { test(); test(); test(); test(); - IF( ( LT_16(voicing_fr[0],6554))&& /* normalized correlation high in 2st sf. */ - ( LT_16(voicing_fr[1],6554) ) && /* normalized correlation high in 2st sf. */ - ( LT_16(voicing_fr[2],6554) ) && /* normalized correlation high in 3rd sf. */ - ( LT_16(voicing_fr[3],6554) ) && /* normalized correlation high in 4th sf. */ - ( GT_16(vadnoise, 25 << 8 ) )) /* when speech is clean */ + IF( ( LT_16( voicing_fr[0], 6554 ) ) && /* normalized correlation high in 2st sf. */ + ( LT_16( voicing_fr[1], 6554 ) ) && /* normalized correlation high in 2st sf. */ + ( LT_16( voicing_fr[2], 6554 ) ) && /* normalized correlation high in 3rd sf. */ + ( LT_16( voicing_fr[3], 6554 ) ) && /* normalized correlation high in 4th sf. */ + ( GT_16( vadnoise, 25 << 8 ) ) ) /* when speech is clean */ { st_fx->rf_mode = 0; move16(); /* Current frame cannot be compressed to pack the partial redundancy;*/ - if( st_fx->rf_mode != st_fx->Opt_RF_ON ) + if ( st_fx->rf_mode != st_fx->Opt_RF_ON ) { core_coder_mode_switch_fx( st_fx, st_fx->last_total_brate, 0, shift ); } @@ -611,9 +615,9 @@ Word16 find_uv_fx( /* o : coding type * UNCLR classifier *-----------------------------------------------------------------*/ - if (hStereoClassif != NULL) + if ( hStereoClassif != NULL ) { - if (st->element_mode > EVS_MONO && (coder_type == GENERIC || coder_type == UNVOICED || coder_type == INACTIVE || st->localVAD == 0) && hStereoClassif->unclr_sw_enable_cnt[st->idchan] < MAX_UV_CNT) + if ( st->element_mode > EVS_MONO && ( coder_type == GENERIC || coder_type == UNVOICED || coder_type == INACTIVE || st->localVAD == 0 ) && hStereoClassif->unclr_sw_enable_cnt[st->idchan] < MAX_UV_CNT ) { hStereoClassif->unclr_sw_enable_cnt[st->idchan]++; } @@ -631,21 +635,21 @@ Word16 find_uv_fx( /* o : coding type /* update spike hysteresis parameters */ test(); - if( st_fx->spike_hyst >= 0 && LT_16(st_fx->spike_hyst,2)) + if ( st_fx->spike_hyst >= 0 && LT_16( st_fx->spike_hyst, 2 ) ) { - st_fx->spike_hyst = add(st_fx->spike_hyst,1); + st_fx->spike_hyst = add( st_fx->spike_hyst, 1 ); } /* reset spike hysteresis */ test(); test(); test(); - if( ( GT_16(st_fx->spike_hyst,1))&& - ( GT_16(dE3,5<<8) || /* energy increases */ + if ( ( GT_16( st_fx->spike_hyst, 1 ) ) && + ( GT_16( dE3, 5 << 8 ) || /* energy increases */ #ifdef BASOP_NOGLOB ( GT_16( relE, -3328 ) && ( GT_16( add_sat( mean_voi3, corr_shift ), 22774 ) ) ) ) ) /* normalized correlation is high */ #else - ( GT_16( relE, -3328 ) && ( GT_16( add( mean_voi3, corr_shift ), 22774 ) ) ) ) ) /* normalized correlation is high */ + ( GT_16( relE, -3328 ) && ( GT_16( add( mean_voi3, corr_shift ), 22774 ) ) ) ) ) /* normalized correlation is high */ #endif { st_fx->spike_hyst = -1; @@ -654,9 +658,9 @@ Word16 find_uv_fx( /* o : coding type /* update tilt parameters */ st_fx->ee_old_fx = ee[1]; - move32(); /*Q6*/ + move32(); /*Q6*/ st_fx->old_dE1_fx = dE1; - move32(); /*Q13*/ + move32(); /*Q13*/ /* save the raw coder_type for various modules later in the codec (the reason is that e.g. UNVOICED is lost at higher rates) */ st_fx->coder_type_raw = coder_type; diff --git a/lib_enc/find_wsp_fx.c b/lib_enc/find_wsp_fx.c index a4279d4b0..21be0073b 100644 --- a/lib_enc/find_wsp_fx.c +++ b/lib_enc/find_wsp_fx.c @@ -7,10 +7,9 @@ #include "options.h" #include "cnst.h" //#include "prot_fx.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ - +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /* @@ -56,31 +55,27 @@ void find_wsp_fx( /*----------------------------------------------------------------* - * Compute weighted speech for all subframes - *----------------------------------------------------------------*/ + * Compute weighted speech for all subframes + *----------------------------------------------------------------*/ BASOP_SATURATE_WARNING_OFF_EVS - p_Az = Aw; /*move16();*/ - FOR (i_subfr = 0; i_subfr < L_frame; i_subfr += L_subfr) + p_Az = Aw; /*move16();*/ + FOR( i_subfr = 0; i_subfr < L_frame; i_subfr += L_subfr ) { - Residu3_fx(p_Az, &speech[i_subfr], &wsp[i_subfr], L_subfr, 0); - p_Az += (M+1); + Residu3_fx( p_Az, &speech[i_subfr], &wsp[i_subfr], L_subfr, 0 ); + p_Az += ( M + 1 ); } - p_Az -= (M+1); + p_Az -= ( M + 1 ); BASOP_SATURATE_WARNING_ON_EVS /*----------------------------------------------------------------* * Weighted speech computation is extended on look-ahead *----------------------------------------------------------------*/ - deemph_fx(wsp, preemph_fac, L_frame, mem_wsp); /* use Deemph2 to prevent saturation */ + deemph_fx( wsp, preemph_fac, L_frame, mem_wsp ); /* use Deemph2 to prevent saturation */ - IF ( lookahead != 0 ) + IF( lookahead != 0 ) { - Residu3_fx(p_Az, &speech[L_frame], &wsp[L_frame], lookahead, 0); + Residu3_fx( p_Az, &speech[L_frame], &wsp[L_frame], lookahead, 0 ); wtmp = *mem_wsp; move16(); - deemph_fx(&wsp[L_frame], preemph_fac, lookahead, &wtmp); + deemph_fx( &wsp[L_frame], preemph_fac, lookahead, &wtmp ); } - } - - - diff --git a/lib_enc/frame_spec_dif_cor_rate_fx.c b/lib_enc/frame_spec_dif_cor_rate_fx.c index f9ed3e789..fb0930579 100644 --- a/lib_enc/frame_spec_dif_cor_rate_fx.c +++ b/lib_enc/frame_spec_dif_cor_rate_fx.c @@ -10,10 +10,10 @@ #include "vad_basop.h" //#include "prot_fx.h" #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ -#include "basop_util.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ +#include "basop_util.h" /* Function prototypes */ /*-------------------------------------------------------------------* * frame_spec_dif_cor_rate_fx() @@ -21,101 +21,102 @@ * *-------------------------------------------------------------------*/ void frame_spec_dif_cor_rate_fx( - VAD_CLDFB_HANDLE_FX hVAD_CLDFB , /* i/o: CLDFB VAD state */ + VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ Word32 *spec_amp, /* i : spectral amplitude*/ Word16 sacle, /* i : the scaling of spec_amp*/ Word16 f_tonality_rate[3] /* o : tonality rate*/ ) { - Word32 i,tmp; - Word16 spec_low_dif_tmp,tmpq,tmpq2,*p_dx_Q,dx_Q=0; + Word32 i, tmp; + Word16 spec_low_dif_tmp, tmpq, tmpq2, *p_dx_Q, dx_Q = 0; Word32 tmpspec_low_dif[PRE_SPEC_DIF_NUM]; Word32 maxVal; Word16 resu; - Word16 scalefactor,spec_dif_cor_rate; - Word32 m,dx,dy; + Word16 scalefactor, spec_dif_cor_rate; + Word32 m, dx, dy; Word16 *pre_spec_low_dif = hVAD_CLDFB->pre_spec_low_dif; - const Word32 FIX_cost1 = 2147484/* 0.001f Q31 */; - + const Word32 FIX_cost1 = 2147484 /* 0.001f Q31 */; p_dx_Q = &dx_Q; - maxVal = 0; move32(); - FOR(i=0; i< PRE_SPEC_DIF_NUM; i++) + maxVal = 0; + move32(); + FOR( i = 0; i < PRE_SPEC_DIF_NUM; i++ ) { - tmp = L_sub(spec_amp[i+6] ,spec_amp[i+5]); - if ( tmp < 0 ) + tmp = L_sub( spec_amp[i + 6], spec_amp[i + 5] ); + if ( tmp < 0 ) { tmp = 0; - move32(); + move32(); } tmpspec_low_dif[i] = tmp; move32(); - maxVal = L_max(maxVal,tmp); + maxVal = L_max( maxVal, tmp ); } resu = 31; move16(); if ( maxVal ) { - resu = norm_l(maxVal); + resu = norm_l( maxVal ); } - m = 0; move32(); - dx = 0; move32(); - dy = 0; move32(); + m = 0; + move32(); + dx = 0; + move32(); + dy = 0; + move32(); - scalefactor = sub(resu,3); + scalefactor = sub( resu, 3 ); - FOR (i = 0; i < PRE_SPEC_DIF_NUM; i++) + FOR( i = 0; i < PRE_SPEC_DIF_NUM; i++ ) { - spec_low_dif_tmp = round_fx(L_shl(tmpspec_low_dif[i],scalefactor)); - m = L_mac0(m,spec_low_dif_tmp,pre_spec_low_dif[i]); - dx = L_mac0(dx, spec_low_dif_tmp, spec_low_dif_tmp); - dy = L_mac0(dy, pre_spec_low_dif[i], pre_spec_low_dif[i]); + spec_low_dif_tmp = round_fx( L_shl( tmpspec_low_dif[i], scalefactor ) ); + m = L_mac0( m, spec_low_dif_tmp, pre_spec_low_dif[i] ); + dx = L_mac0( dx, spec_low_dif_tmp, spec_low_dif_tmp ); + dy = L_mac0( dy, pre_spec_low_dif[i], pre_spec_low_dif[i] ); pre_spec_low_dif[i] = spec_low_dif_tmp; move16(); } - dx = L_mult0(round_fx(dx),round_fx(dy)); - tmpq = add(sacle,scalefactor); - tmpq = sub(tmpq,16); - tmpq2 = add(tmpq,hVAD_CLDFB->scale_spec_low_dif); - *p_dx_Q = shl(tmpq2,1); + dx = L_mult0( round_fx( dx ), round_fx( dy ) ); + tmpq = add( sacle, scalefactor ); + tmpq = sub( tmpq, 16 ); + tmpq2 = add( tmpq, hVAD_CLDFB->scale_spec_low_dif ); + *p_dx_Q = shl( tmpq2, 1 ); move16(); - *p_dx_Q = sub(*p_dx_Q ,32); + *p_dx_Q = sub( *p_dx_Q, 32 ); move16(); - IF(LT_16(*p_dx_Q , 31)) + IF( LT_16( *p_dx_Q, 31 ) ) { - dx = L_add(dx,L_shr(FIX_cost1,limitScale32(sub(31,*p_dx_Q)))); + dx = L_add( dx, L_shr( FIX_cost1, limitScale32( sub( 31, *p_dx_Q ) ) ) ); } ELSE { - dx = L_add(L_shr(dx,limitScale32(sub(*p_dx_Q,31))),FIX_cost1); - *p_dx_Q = 31; + dx = L_add( L_shr( dx, limitScale32( sub( *p_dx_Q, 31 ) ) ), FIX_cost1 ); + *p_dx_Q = 31; move16(); } - dx = vad_Sqrt_l(dx,p_dx_Q); + dx = vad_Sqrt_l( dx, p_dx_Q ); - m = L_shr(m,limitScale32(add(sub(tmpq2,*p_dx_Q),1))); + m = L_shr( m, limitScale32( add( sub( tmpq2, *p_dx_Q ), 1 ) ) ); spec_dif_cor_rate = 16384; move16(); - if(dx) + if ( dx ) { - spec_dif_cor_rate = divide3232(m,dx); + spec_dif_cor_rate = divide3232( m, dx ); } f_tonality_rate[0] = spec_dif_cor_rate; move16(); - tmp = L_mac0(L_mult0(f_tonality_rate[1],31456/* 0.96 Q15 */), spec_dif_cor_rate,1311/* 0.04 Q15 */); - f_tonality_rate[1] = shl(round_fx(tmp),1); + tmp = L_mac0( L_mult0( f_tonality_rate[1], 31456 /* 0.96 Q15 */ ), spec_dif_cor_rate, 1311 /* 0.04 Q15 */ ); + f_tonality_rate[1] = shl( round_fx( tmp ), 1 ); move16(); - tmp = L_mac0(L_mult0(f_tonality_rate[2],29490/* 0.90 Q15 */), spec_dif_cor_rate,3277/* 0.1 Q15 */); - f_tonality_rate[2] = shl(round_fx(tmp),1); + tmp = L_mac0( L_mult0( f_tonality_rate[2], 29490 /* 0.90 Q15 */ ), spec_dif_cor_rate, 3277 /* 0.1 Q15 */ ); + f_tonality_rate[2] = shl( round_fx( tmp ), 1 ); move16(); hVAD_CLDFB->scale_spec_low_dif = tmpq; move16(); - } - diff --git a/lib_enc/gain_enc_fx.c b/lib_enc/gain_enc_fx.c index f7cc7a2b3..ad366278c 100644 --- a/lib_enc/gain_enc_fx.c +++ b/lib_enc/gain_enc_fx.c @@ -2,28 +2,27 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ +#include "options.h" /* Compilation switches */ #include "cnst.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ +#include "rom_com_fx.h" /* Static table prototypes */ #include "rom_com.h" /* Static table prototypes */ //#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* * Local constants *-------------------------------------------------------------------*/ -#define RANGE 64 -#define NB_QUA_GAIN7B 128 /* Number of quantization levels */ +#define RANGE 64 +#define NB_QUA_GAIN7B 128 /* Number of quantization levels */ /*-------------------------------------------------------------------* * Local function prototype *-------------------------------------------------------------------*/ -static Word16 Find_Opt_gainQ_fx(Word16 *coeff, Word16 *exp_coeff, Word16 *gain_pit, Word32 *gain_code, - Word16 gcode0,Word16 exp_gcode0,const Word16 *cdbk, const Word16 size ); +static Word16 Find_Opt_gainQ_fx( Word16 *coeff, Word16 *exp_coeff, Word16 *gain_pit, Word32 *gain_code, Word16 gcode0, Word16 exp_gcode0, const Word16 *cdbk, const Word16 size ); /*==========================================================================*/ /* FUNCTION : Es_pred_enc_fx() */ @@ -51,142 +50,142 @@ static Word16 Find_Opt_gainQ_fx(Word16 *coeff, Word16 *exp_coeff, Word16 *gain_p /*==========================================================================*/ void Es_pred_enc_fx( - Word16 *Es_pred, /* o : predicited scaled innovation energy Q8 */ - Word16 *indice, /* o : indice of quantization */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 *res, /* i : residual signal */ - const Word16 *voicing, /* i : normalized correlation in three 1/2frames */ - const Word16 nb_bits, /* i : allocated number of bits */ - const Word16 no_ltp, /* i : no_ltp flag */ - Word16 Q_new /* i : Scaling in speech Q0 */ + Word16 *Es_pred, /* o : predicited scaled innovation energy Q8 */ + Word16 *indice, /* o : indice of quantization */ + const Word16 L_frame, /* i : length of the frame */ + const Word16 *res, /* i : residual signal */ + const Word16 *voicing, /* i : normalized correlation in three 1/2frames */ + const Word16 nb_bits, /* i : allocated number of bits */ + const Word16 no_ltp, /* i : no_ltp flag */ + Word16 Q_new /* i : Scaling in speech Q0 */ ) { - Word16 i, i_subfr,size, tmp16, tmp16_2, Q_res; + Word16 i, i_subfr, size, tmp16, tmp16_2, Q_res; Word16 weight; - Word16 s0,s1, ener_dB, mean_ener_code16; + Word16 s0, s1, ener_dB, mean_ener_code16; const Word16 *qua_table; Word32 ener_fx, Lmean_ener_code, Ltmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - Lmean_ener_code = L_deposit_l(0); - Q_res = sub(shl(Q_new, 1), 3); + Lmean_ener_code = L_deposit_l( 0 ); + Q_res = sub( shl( Q_new, 1 ), 3 ); - IF( EQ_16(L_frame,L_FRAME)) + IF( EQ_16( L_frame, L_FRAME ) ) { weight = 8192; - move16();/*0.25f in Q15*/ + move16(); /*0.25f in Q15*/ } - ELSE /* L_frame == L_FRAME16k */ + ELSE /* L_frame == L_FRAME16k */ { weight = 6554; - move16();/*0.2f in Q15*/ + move16(); /*0.2f in Q15*/ } /*----------------------------------------------------------* * calculate the average residual signal energy in four sframes *----------------------------------------------------------*/ - FOR (i_subfr = 0; i_subfr < L_frame; i_subfr += L_SUBFR) + FOR( i_subfr = 0; i_subfr < L_frame; i_subfr += L_SUBFR ) { /* calculate the energy of residual signal */ - tmp16 = mult_r(res[i_subfr+0], 8192); /* remove 2bits */ - ener_fx = L_mult(tmp16, tmp16); - FOR (i=1; i, -2,, -2 and 2 */ - const Word16 clip_gain /* i : gain pitch clipping flag (1 = clipping) */ - ) + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 gains_mode[], /* i : gain bits */ + const Word16 element_mode, /* i : element mode */ + const Word16 L_frame, /* i : length of the frame */ + const Word16 i_subfr, /* i : subframe index */ + const Word16 tc_subfr, /* i : TC subframe index */ + const Word16 *xn, /* i : target vector */ + const Word16 *y1, /* i : zero-memory filtered adaptive excitation */ + const Word16 Q_xn, /* i : xn and y1 scaling */ + const Word16 *y2, /* i : zero-memory filtered algebraic codebook excitation */ + const Word16 *code, /* i : algebraic excitation */ + const Word16 Es_pred, /* i : predicted scaled innovation energy */ + Word16 *gain_pit, /* o : quantized pitch gain */ + Word32 *gain_code, /* o : quantized codebook gain */ + Word16 *gain_inov, /* o : gain of the innovation (used for normalization) */ + Word32 *norm_gain_code, /* o : norm. gain of the codebook excitation */ + Word16 *g_corr, /* i/o: correlations , -2,, -2 and 2 */ + const Word16 clip_gain /* i : gain pitch clipping flag (1 = clipping) */ +) { Word16 index, size, nBits, nBits2; @@ -254,24 +253,24 @@ void gain_enc_mless_fx( move16(); exp_coeff[0] = g_corr[1]; move16(); - coeff[1] = negate(g_corr[2]); - move16(); /* coeff[1] = -2 xn yy1 */ - exp_coeff[1] = add(g_corr[3], 1); + coeff[1] = negate( g_corr[2] ); + move16(); /* coeff[1] = -2 xn yy1 */ + exp_coeff[1] = add( g_corr[3], 1 ); move16(); /* Compute scalar product */ - coeff[2] = extract_h(Dot_product12(y2, y2, L_SUBFR, &exp)); - exp_coeff[2] = add(sub(exp, 18), shl(Q_xn, 1)); + coeff[2] = extract_h( Dot_product12( y2, y2, L_SUBFR, &exp ) ); + exp_coeff[2] = add( sub( exp, 18 ), shl( Q_xn, 1 ) ); move16(); /* -18 (y2 Q9) */ /* Compute scalar product -2* */ - coeff[3] = extract_h(L_negate(Dot_product12(xn, y2, L_SUBFR, &exp))); - exp_coeff[3] = add(sub(exp, 9 - 1), Q_xn); + coeff[3] = extract_h( L_negate( Dot_product12( xn, y2, L_SUBFR, &exp ) ) ); + exp_coeff[3] = add( sub( exp, 9 - 1 ), Q_xn ); move16(); /* -9 (y2 Q9), +1 (2 xn y2) */ /* Compute scalar product 2* */ - coeff[4] = extract_h(Dot_product12(y1, y2, L_SUBFR, &exp)); - exp_coeff[4] = add(sub(exp, 9 - 1), Q_xn); + coeff[4] = extract_h( Dot_product12( y1, y2, L_SUBFR, &exp ) ); + exp_coeff[4] = add( sub( exp, 9 - 1 ), Q_xn ); move16(); /* -9 (y2 Q9), +1 (2 y1 y2) */ /*-----------------------------------------------------------------* @@ -280,31 +279,31 @@ void gain_enc_mless_fx( *-----------------------------------------------------------------*/ /* gain_inov = 1.0f / sqrt((dot_product(code, code, L_SUBFR) + 0.01) / L_SUBFR) */ - L_tmp = Dot_product12(code, code, L_SUBFR, &exp_code); - exp_inov = sub(exp_code, 18+6); - exp_code = sub(exp_code, 30); + L_tmp = Dot_product12( code, code, L_SUBFR, &exp_code ); + exp_inov = sub( exp_code, 18 + 6 ); + exp_code = sub( exp_code, 30 ); /*Ei = 10 * log10((dot_product(code, code, L_SUBFR) + 0.01) / L_SUBFR) */ /*----------------------------------------------------------------* * calculate the predicted gain code *----------------------------------------------------------------*/ - tmp = norm_l(L_tmp); - frac = Log2_norm_lc(L_shl(L_tmp, tmp)); - tmp = add(30-18-6-1, sub(exp_code, tmp)); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ - L_tmp1 = Mpy_32_16(tmp, frac, 12330); /* Q13 */ - Ei = round_fx(L_shl(L_tmp1, 11)); /* Q8 */ + tmp = norm_l( L_tmp ); + frac = Log2_norm_lc( L_shl( L_tmp, tmp ) ); + tmp = add( 30 - 18 - 6 - 1, sub( exp_code, tmp ) ); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ + L_tmp1 = Mpy_32_16( tmp, frac, 12330 ); /* Q13 */ + Ei = round_fx( L_shl( L_tmp1, 11 ) ); /* Q8 */ /* predicted codebook gain */ - gcode0 = sub(Es_pred, Ei); /* Q8 */ + gcode0 = sub( Es_pred, Ei ); /* Q8 */ /*---------------------------------------------------------------* * Decode codebook gain and the adaptive excitation low-pass * filtering factor (Finalize computation ) *---------------------------------------------------------------*/ /* gain_inov = 1.0f / sqrt((dot_product(code, code, L_SUBFR) + 0.01) / L_SUBFR) */ - L_tmp = Isqrt_lc(L_tmp, &exp_inov); - *gain_inov = extract_h(L_shl(L_tmp, sub(exp_inov, 3))); /* gain_inov in Q12 */ + L_tmp = Isqrt_lc( L_tmp, &exp_inov ); + *gain_inov = extract_h( L_shl( L_tmp, sub( exp_inov, 3 ) ) ); /* gain_inov in Q12 */ /* gcode0 = pow(10, 0.05 * (Es_pred - Ei)) */ /*----------------------------------------------------------------* @@ -313,25 +312,29 @@ void gain_enc_mless_fx( * = pow(2, 0.166096*gcode0) *----------------------------------------------------------------*/ - L_tmp = L_mult(gcode0, 21771); /* *0.166096 in Q17 -> Q26 */ - L_tmp = L_shr(L_tmp, 10); /* From Q26 to Q16 */ - frac = L_Extract_lc(L_tmp, &exp_gcode0); /* Extract exponent of gcode0 */ + L_tmp = L_mult( gcode0, 21771 ); /* *0.166096 in Q17 -> Q26 */ + L_tmp = L_shr( L_tmp, 10 ); /* From Q26 to Q16 */ + frac = L_Extract_lc( L_tmp, &exp_gcode0 ); /* Extract exponent of gcode0 */ - gcode0 = extract_l(Pow2(14, frac)); /* Put 14 as exponent so that */ + gcode0 = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ - exp_gcode0 = sub(exp_gcode0, 14); + exp_gcode0 = sub( exp_gcode0, 14 ); /*-----------------------------------------------------------------* * select the codebook, size and number of bits * set the gains searching range *-----------------------------------------------------------------*/ - nBits = gains_mode[shr(i_subfr, 6)]; + nBits = gains_mode[shr( i_subfr, 6 )]; move16(); - test();test();test();test();test(); - IF( (EQ_16(tc_subfr,3*L_SUBFR)&&EQ_16(i_subfr,3*L_SUBFR)&&EQ_16(L_frame,L_FRAME))|| - (EQ_16(tc_subfr,4*L_SUBFR) && EQ_16(i_subfr,4*L_SUBFR) && EQ_16(L_frame,L_FRAME16k) ) ) + test(); + test(); + test(); + test(); + test(); + IF( ( EQ_16( tc_subfr, 3 * L_SUBFR ) && EQ_16( i_subfr, 3 * L_SUBFR ) && EQ_16( L_frame, L_FRAME ) ) || + ( EQ_16( tc_subfr, 4 * L_SUBFR ) && EQ_16( i_subfr, 4 * L_SUBFR ) && EQ_16( L_frame, L_FRAME16k ) ) ) { /* *gain_pit = (g_corr[2]*tmp2) - (0.5f*g_corr[4]*tmp3); = ((-0.5f*g_corr[1]*g_corr[2]) - (-0.25*g_corr[3]*g_corr[4]))/tmp1; @@ -341,171 +344,171 @@ void gain_enc_mless_fx( = ((-0.5*g_corr[3]*g_corr[0]) - (-0.25*g_corr[1]*g_corr[4]))/tmp1; = ((0.25*g_corr[1]*g_corr[4]) - (0.5*g_corr[0]*g_corr[3]))/tmp1; */ - L_tmp1 = L_mult(coeff[0],coeff[2]); /*Q31*/ - exp1 = add(exp_coeff[0], exp_coeff[2]); + L_tmp1 = L_mult( coeff[0], coeff[2] ); /*Q31*/ + exp1 = add( exp_coeff[0], exp_coeff[2] ); - L_tmp2 = L_shr(L_mult(coeff[4],coeff[4]),2); /*Q31*/ - exp2 = add(exp_coeff[4], exp_coeff[4]); + L_tmp2 = L_shr( L_mult( coeff[4], coeff[4] ), 2 ); /*Q31*/ + exp2 = add( exp_coeff[4], exp_coeff[4] ); - IF(GT_16(exp1,exp2)) + IF( GT_16( exp1, exp2 ) ) { - L_tmp2 = L_shr(L_tmp2,sub(exp1,exp2)); /*Q31*/ + L_tmp2 = L_shr( L_tmp2, sub( exp1, exp2 ) ); /*Q31*/ exp_den = exp1; move16(); } ELSE { - L_tmp1 = L_shr(L_tmp1,sub(exp2,exp1)); /*Q31*/ + L_tmp1 = L_shr( L_tmp1, sub( exp2, exp1 ) ); /*Q31*/ exp_den = exp2; move16(); } - L_frac_den = L_sub(L_tmp1,L_tmp2); /*Q31*/ + L_frac_den = L_sub( L_tmp1, L_tmp2 ); /*Q31*/ - frac_den = extract_h(L_frac_den); - frac_den = s_max(frac_den,1); - L_frac_den = L_max(L_frac_den,1); - exp = norm_l(L_frac_den); - tmp = div_s(shl(1,sub(14,exp)),frac_den); /*Q(14-exp)*/ + frac_den = extract_h( L_frac_den ); + frac_den = s_max( frac_den, 1 ); + L_frac_den = L_max( L_frac_den, 1 ); + exp = norm_l( L_frac_den ); + tmp = div_s( shl( 1, sub( 14, exp ) ), frac_den ); /*Q(14-exp)*/ - L_tmp1 = L_shr(L_mult(coeff[3],coeff[4]),2); /*Q31*/ - exp1 = add(exp_coeff[3], exp_coeff[4]); + L_tmp1 = L_shr( L_mult( coeff[3], coeff[4] ), 2 ); /*Q31*/ + exp1 = add( exp_coeff[3], exp_coeff[4] ); - L_tmp2 = L_shr(L_mult(coeff[1],coeff[2]),1); /*Q31*/ - exp2 = add(exp_coeff[1], exp_coeff[2]); + L_tmp2 = L_shr( L_mult( coeff[1], coeff[2] ), 1 ); /*Q31*/ + exp2 = add( exp_coeff[1], exp_coeff[2] ); - IF(GT_16(exp1,exp2)) + IF( GT_16( exp1, exp2 ) ) { - L_tmp2 = L_shr(L_tmp2,sub(exp1,exp2)); /*Q31*/ + L_tmp2 = L_shr( L_tmp2, sub( exp1, exp2 ) ); /*Q31*/ exp_num = exp1; move16(); } ELSE { - L_tmp1 = L_shr(L_tmp1,sub(exp2,exp1)); /*Q31*/ + L_tmp1 = L_shr( L_tmp1, sub( exp2, exp1 ) ); /*Q31*/ exp_num = exp2; move16(); } - L_frac_num = L_sub(L_tmp1,L_tmp2); /*Q31*/ + L_frac_num = L_sub( L_tmp1, L_tmp2 ); /*Q31*/ - L_div = Mult_32_16(L_frac_num,tmp); /*Q(30-exp)*/ - exp_div = sub(exp_num,exp_den); + L_div = Mult_32_16( L_frac_num, tmp ); /*Q(30-exp)*/ + exp_div = sub( exp_num, exp_den ); #ifdef BASOP_NOGLOB - *gain_pit = round_fx_o(L_shl_o(L_div,add(exp,exp_div), &Overflow), &Overflow); /*Q14*/ + *gain_pit = round_fx_o( L_shl_o( L_div, add( exp, exp_div ), &Overflow ), &Overflow ); /*Q14*/ #else - *gain_pit = round_fx(L_shl(L_div,add(exp,exp_div))); /*Q14*/ + *gain_pit = round_fx( L_shl( L_div, add( exp, exp_div ) ) ); /*Q14*/ #endif - L_tmp1 = L_shr(L_mult(coeff[1],coeff[4]),2); /*Q31*/ - exp1 = add(exp_coeff[1], exp_coeff[4]); + L_tmp1 = L_shr( L_mult( coeff[1], coeff[4] ), 2 ); /*Q31*/ + exp1 = add( exp_coeff[1], exp_coeff[4] ); - L_tmp2 = L_shr(L_mult(coeff[0],coeff[3]),1); /*Q31*/ - exp2 = add(exp_coeff[0], exp_coeff[3]); + L_tmp2 = L_shr( L_mult( coeff[0], coeff[3] ), 1 ); /*Q31*/ + exp2 = add( exp_coeff[0], exp_coeff[3] ); - IF(GT_16(exp1,exp2)) + IF( GT_16( exp1, exp2 ) ) { - L_tmp2 = L_shr(L_tmp2,sub(exp1,exp2)); /*Q31*/ + L_tmp2 = L_shr( L_tmp2, sub( exp1, exp2 ) ); /*Q31*/ exp_num = exp1; } ELSE { - L_tmp1 = L_shr(L_tmp1,sub(exp2,exp1)); /*Q31*/ + L_tmp1 = L_shr( L_tmp1, sub( exp2, exp1 ) ); /*Q31*/ exp_num = exp2; } - L_frac_num = L_sub(L_tmp1,L_tmp2); /*Q31*/ + L_frac_num = L_sub( L_tmp1, L_tmp2 ); /*Q31*/ - L_div = Mult_32_16(L_frac_num,tmp); /*Q(30-exp)*/ - exp_div = sub(exp_num,exp_den); + L_div = Mult_32_16( L_frac_num, tmp ); /*Q(30-exp)*/ + exp_div = sub( exp_num, exp_den ); #ifdef BASOP_NOGLOB - *gain_code = L_shl_o(L_div,sub(add(exp,exp_div),14), &Overflow); + *gain_code = L_shl_o( L_div, sub( add( exp, exp_div ), 14 ), &Overflow ); #else - *gain_code = L_shl(L_div,sub(add(exp,exp_div),14)); + *gain_code = L_shl( L_div, sub( add( exp, exp_div ), 14 ) ); #endif - move32();/*Q16*/ + move32(); /*Q16*/ - *gain_pit = s_max(G_PITCH_MIN_TC192_Q14,s_min(*gain_pit,G_PITCH_MAX_TC192_Q14)); + *gain_pit = s_max( G_PITCH_MIN_TC192_Q14, s_min( *gain_pit, G_PITCH_MAX_TC192_Q14 ) ); /* set number of bits for two SQs */ - nBits2 = shr(add(nBits,1),1); - nBits = shr(nBits,1); + nBits2 = shr( add( nBits, 1 ), 1 ); + nBits = shr( nBits, 1 ); /* gain_pit Q */ - tmp1 = mult_r(G_PITCH_MAX_MINUS_MIN_TC192_Q13,div_s(1,sub(shl(1, nBits), 1))); /*Q13*/ /* set quantization step */ - index = usquant_fx( *gain_pit, gain_pit, G_PITCH_MIN_TC192_Q14, tmp1, shl(1, nBits) ); + tmp1 = mult_r( G_PITCH_MAX_MINUS_MIN_TC192_Q13, div_s( 1, sub( shl( 1, nBits ), 1 ) ) ); /*Q13*/ /* set quantization step */ + index = usquant_fx( *gain_pit, gain_pit, G_PITCH_MIN_TC192_Q14, tmp1, shl( 1, nBits ) ); move16(); push_indice_fx( hBstr, IND_GAIN_PIT, index, nBits ); /* gain_code Q */ /**gain_code /= gcode0;*/ - IF(gcode0 != 0) + IF( gcode0 != 0 ) { - tmp = div_s(16384,gcode0); /*Q15*/ - L_tmp = Mult_32_16(*gain_code,tmp); /*Q16*/ - *gain_code = L_shr(L_tmp,add(14,exp_gcode0)); /*Q16*/ + tmp = div_s( 16384, gcode0 ); /*Q15*/ + L_tmp = Mult_32_16( *gain_code, tmp ); /*Q16*/ + *gain_code = L_shr( L_tmp, add( 14, exp_gcode0 ) ); /*Q16*/ } index = gain_quant_fx( gain_code, &gain_code16, LG10_G_CODE_MIN_TC192_Q14, LG10_G_CODE_MAX_TC192_Q13, nBits2, &expg ); push_indice_fx( hBstr, IND_GAIN_CODE, index, nBits2 ); - L_tmp = L_mult(gain_code16,gcode0); /*Q0*Q0 -> Q1*/ + L_tmp = L_mult( gain_code16, gcode0 ); /*Q0*Q0 -> Q1*/ #ifdef BASOP_NOGLOB - *gain_code = L_shl_o(L_tmp,add(add(expg,exp_gcode0),15), &Overflow); /*Q16*/ + *gain_code = L_shl_o( L_tmp, add( add( expg, exp_gcode0 ), 15 ), &Overflow ); /*Q16*/ #else - *gain_code = L_shl(L_tmp,add(add(expg,exp_gcode0),15)); /*Q16*/ + *gain_code = L_shl( L_tmp, add( add( expg, exp_gcode0 ), 15 ) ); /*Q16*/ #endif } ELSE { - size = shl(1,nBits); + size = shl( 1, nBits ); - SWITCH ( nBits ) + SWITCH( nBits ) { - case 7: + case 7: { qua_table = gain_qua_mless_7b_fx; move16(); - if (EQ_16(clip_gain, 1)) + if ( EQ_16( clip_gain, 1 ) ) { - size = sub(size, 30); + size = sub( size, 30 ); } BREAK; } - case 6: + case 6: { qua_table = gain_qua_mless_6b_fx; - if (GT_16(element_mode, EVS_MONO)) + if ( GT_16( element_mode, EVS_MONO ) ) { #ifdef IVAS_CODE qua_table = gain_qua_mless_6b_stereo; #else - //PMTE() + // PMTE() #endif } move16(); - if (EQ_16(clip_gain, 1)) + if ( EQ_16( clip_gain, 1 ) ) { - size = sub(size, 14); + size = sub( size, 14 ); } BREAK; } - case 5: + case 5: { qua_table = gain_qua_mless_5b_fx; move16(); - if (EQ_16(clip_gain, 1)) + if ( EQ_16( clip_gain, 1 ) ) { - size = sub(size, 6); + size = sub( size, 6 ); } BREAK; } - default: + default: { qua_table = gain_qua_mless_6b_fx; move16(); - if (EQ_16(clip_gain, 1)) - { - size = sub(size, 14); + if ( EQ_16( clip_gain, 1 ) ) + { + size = sub( size, 14 ); } BREAK; } @@ -513,25 +516,25 @@ void gain_enc_mless_fx( /* in case of AVQ inactive, limit the gain_pit to 0.65 */ test(); - IF( EQ_16(clip_gain,2)&&EQ_16(nBits,6)) + IF( EQ_16( clip_gain, 2 ) && EQ_16( nBits, 6 ) ) { - size = sub(size,36); - nBits = sub(nBits,1); + size = sub( size, 36 ); + nBits = sub( nBits, 1 ); } /*-----------------------------------------------------------------* * search for the best quantizer *-----------------------------------------------------------------*/ - index = Find_Opt_gainQ_fx(coeff, exp_coeff, gain_pit, gain_code, gcode0, exp_gcode0, qua_table, size); + index = Find_Opt_gainQ_fx( coeff, exp_coeff, gain_pit, gain_code, gcode0, exp_gcode0, qua_table, size ); push_indice_fx( hBstr, IND_GAIN, index, nBits ); } /* *norm_gain_code = *gain_code / *gain_inov; */ - exp = sub(norm_s(*gain_inov),1); - exp = s_max(exp, 0); + exp = sub( norm_s( *gain_inov ), 1 ); + exp = s_max( exp, 0 ); - tmp = div_s(shr(8192,exp),*gain_inov); - *norm_gain_code = L_shr(Mult_32_16(*gain_code, tmp),sub(1,exp)); + tmp = div_s( shr( 8192, exp ), *gain_inov ); + *norm_gain_code = L_shr( Mult_32_16( *gain_code, tmp ), sub( 1, exp ) ); move32(); return; @@ -539,32 +542,32 @@ void gain_enc_mless_fx( /*---------------------------------------------------------------------* -* gain_enc_SQ() -* -* Scalar Quantization of pitch and codebook gains without prediction -* - an initial predicted gain, gcode0, is first determined based on -* the predicted scaled innovation energy -* - a correction factor gamma = g_code / gcode0 is then vector quantized -* along with gain_pit -* - the mean-squared weighted error criterion is used for codebook search -*---------------------------------------------------------------------*/ + * gain_enc_SQ() + * + * Scalar Quantization of pitch and codebook gains without prediction + * - an initial predicted gain, gcode0, is first determined based on + * the predicted scaled innovation energy + * - a correction factor gamma = g_code / gcode0 is then vector quantized + * along with gain_pit + * - the mean-squared weighted error criterion is used for codebook search + *---------------------------------------------------------------------*/ void gain_enc_SQ_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 gains_mode[], /* i : gain bits */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 *xn, /* i : target vector Q_xn */ - const Word16 *yy1, /* i : zero-memory filtered adaptive excitation Q_xn */ - const Word16 *y2, /* i : zero-memory filtered algebraic codebook excitation Q9 */ - const Word16 *code, /* i : algebraic excitation Q9 */ - const Word16 Es_pred, /* i : predicted scaled innovation energy Q8 */ - Word16 *gain_pit, /* o : quantized pitch gain Q14 */ - Word32 *gain_code, /* o : quantized codebook gain Q16 */ - Word16 *gain_inov, /* o : gain of the innovation (used for normalization) Q12 */ - Word32 *norm_gain_code, /* o : norm. gain of the codebook excitation Q16 */ - Word16 *g_corr, /* i/o: correlations , ,, -2 and 2 */ - const Word16 clip_gain, /* i : gain pitch clipping flag (1 = clipping) */ - const Word16 Q_xn /* i : xn and y1 scaling */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 gains_mode[], /* i : gain bits */ + const Word16 i_subfr, /* i : subframe index */ + const Word16 *xn, /* i : target vector Q_xn */ + const Word16 *yy1, /* i : zero-memory filtered adaptive excitation Q_xn */ + const Word16 *y2, /* i : zero-memory filtered algebraic codebook excitation Q9 */ + const Word16 *code, /* i : algebraic excitation Q9 */ + const Word16 Es_pred, /* i : predicted scaled innovation energy Q8 */ + Word16 *gain_pit, /* o : quantized pitch gain Q14 */ + Word32 *gain_code, /* o : quantized codebook gain Q16 */ + Word16 *gain_inov, /* o : gain of the innovation (used for normalization) Q12 */ + Word32 *norm_gain_code, /* o : norm. gain of the codebook excitation Q16 */ + Word16 *g_corr, /* i/o: correlations , ,, -2 and 2 */ + const Word16 clip_gain, /* i : gain pitch clipping flag (1 = clipping) */ + const Word16 Q_xn /* i : xn and y1 scaling */ ) { Word16 index, nBits_pitch, nBits_code; @@ -595,23 +598,23 @@ void gain_enc_SQ_fx( exp_coeff[0] = g_corr[1]; move16(); coeff[1] = g_corr[2]; - move16(); /* coeff[1] = xn yy1 */ + move16(); /* coeff[1] = xn yy1 */ exp_coeff[1] = g_corr[3]; move16(); /* Compute scalar product */ - coeff[2] = extract_h(Dot_product12(y2, y2, L_SUBFR, &exp)); - exp_coeff[2] = add(sub(exp, 18), shl(Q_xn, 1)); + coeff[2] = extract_h( Dot_product12( y2, y2, L_SUBFR, &exp ) ); + exp_coeff[2] = add( sub( exp, 18 ), shl( Q_xn, 1 ) ); move16(); /* -18 (y2 Q9) */ /* Compute scalar product */ - coeff[3] = extract_h(Dot_product12(xn, y2, L_SUBFR, &exp)); - exp_coeff[3] = add(sub(exp, 9 ), Q_xn); + coeff[3] = extract_h( Dot_product12( xn, y2, L_SUBFR, &exp ) ); + exp_coeff[3] = add( sub( exp, 9 ), Q_xn ); move16(); /* -9 (y2 Q9), (xn y2) */ /* Compute scalar product */ - coeff[4] = extract_h(Dot_product12(yy1, y2, L_SUBFR, &exp)); - exp_coeff[4] = add(sub(exp, 9), Q_xn); + coeff[4] = extract_h( Dot_product12( yy1, y2, L_SUBFR, &exp ) ); + exp_coeff[4] = add( sub( exp, 9 ), Q_xn ); move16(); /* -9 (y2 Q9), (y1 y2) */ /*-----------------------------------------------------------------* @@ -622,30 +625,30 @@ void gain_enc_SQ_fx( /*Ecode = (dotp( code, code, L_SUBFR) + 0.01f) / L_SUBFR;*/ /**gain_inov = 1.0f / (float)sqrt( Ecode );*/ - L_tmp = Dot_product12(code, code, L_SUBFR, &exp_code); - exp_inov = sub(exp_code, 18+6); - exp_code = sub(exp_code, 30); + L_tmp = Dot_product12( code, code, L_SUBFR, &exp_code ); + exp_inov = sub( exp_code, 18 + 6 ); + exp_code = sub( exp_code, 30 ); /*Ei = 10 * log10((dot_product(code, code, L_SUBFR) + 0.01) / L_SUBFR) */ /*----------------------------------------------------------------* * calculate the predicted gain code *----------------------------------------------------------------*/ - tmp = norm_l(L_tmp); - frac = Log2_norm_lc(L_shl(L_tmp, tmp)); - tmp = add(30-18-6-1, sub(exp_code, tmp)); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ - L_tmp1 = Mpy_32_16(tmp, frac, 12330); /* Q13 */ - Ei = round_fx(L_shl(L_tmp1, 11)); /* Q8 */ + tmp = norm_l( L_tmp ); + frac = Log2_norm_lc( L_shl( L_tmp, tmp ) ); + tmp = add( 30 - 18 - 6 - 1, sub( exp_code, tmp ) ); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ + L_tmp1 = Mpy_32_16( tmp, frac, 12330 ); /* Q13 */ + Ei = round_fx( L_shl( L_tmp1, 11 ) ); /* Q8 */ /* predicted codebook gain */ - gcode0 = sub(Es_pred, Ei); /* Q8 */ + gcode0 = sub( Es_pred, Ei ); /* Q8 */ /*---------------------------------------------------------------* * Decode codebook gain and the adaptive excitation low-pass * filtering factor (Finalize computation ) *---------------------------------------------------------------*/ /* gain_inov = 1.0f / sqrt((dot_product(code, code, L_SUBFR) + 0.01) / L_SUBFR) */ - L_tmp = Isqrt_lc(L_tmp, &exp_inov); - *gain_inov = extract_h(L_shl(L_tmp, sub(exp_inov, 3))); /* gain_inov in Q12 */ + L_tmp = Isqrt_lc( L_tmp, &exp_inov ); + *gain_inov = extract_h( L_shl( L_tmp, sub( exp_inov, 3 ) ) ); /* gain_inov in Q12 */ /* gcode0 = pow(10, 0.05 * (Es_pred - Ei)) */ /*----------------------------------------------------------------* @@ -654,14 +657,14 @@ void gain_enc_SQ_fx( * = pow(2, 0.166096*gcode0) *----------------------------------------------------------------*/ - L_tmp = L_mult(gcode0, 21771); /* *0.166096 in Q17 -> Q26 */ - L_tmp = L_shr(L_tmp, 10); /* From Q26 to Q16 */ - frac = L_Extract_lc(L_tmp, &exp_gcode0); /* Extract exponent of gcode0 */ + L_tmp = L_mult( gcode0, 21771 ); /* *0.166096 in Q17 -> Q26 */ + L_tmp = L_shr( L_tmp, 10 ); /* From Q26 to Q16 */ + frac = L_Extract_lc( L_tmp, &exp_gcode0 ); /* Extract exponent of gcode0 */ - gcode0 = extract_l(Pow2(14, frac)); /* Put 14 as exponent so that */ + gcode0 = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ - exp_gcode0 = sub(exp_gcode0, 14); + exp_gcode0 = sub( exp_gcode0, 14 ); /*tmp1 = (g_corr[0]*g_corr[2]) - (g_corr[4]*g_corr[4]); @@ -677,104 +680,103 @@ void gain_enc_SQ_fx( /* *gain_code = (g_corr[0]*tmp3) - (g_corr[4]*tmp2); = ((g_corr[3]*g_corr[0]) - (g_corr[1]*g_corr[4]))/tmp1;*/ - L_tmp1 = L_mult(coeff[0],coeff[2]); /*Q31*/ - exp1 = add(exp_coeff[0], exp_coeff[2]); + L_tmp1 = L_mult( coeff[0], coeff[2] ); /*Q31*/ + exp1 = add( exp_coeff[0], exp_coeff[2] ); #ifdef BASOP_NOGLOB - L_tmp2 = L_mult_o(coeff[4],coeff[4], &Overflow); /*Q31*/ + L_tmp2 = L_mult_o( coeff[4], coeff[4], &Overflow ); /*Q31*/ #else - L_tmp2 = L_mult(coeff[4],coeff[4]); /*Q31*/ + L_tmp2 = L_mult( coeff[4], coeff[4] ); /*Q31*/ #endif - exp2 = add(exp_coeff[4], exp_coeff[4]); + exp2 = add( exp_coeff[4], exp_coeff[4] ); - IF(GT_16(exp1,exp2)) + IF( GT_16( exp1, exp2 ) ) { - L_tmp2 = L_shr(L_tmp2,sub(exp1,exp2)); /*Q31*/ + L_tmp2 = L_shr( L_tmp2, sub( exp1, exp2 ) ); /*Q31*/ exp_den = exp1; move16(); } ELSE { - L_tmp1 = L_shr(L_tmp1,sub(exp2,exp1)); /*Q31*/ + L_tmp1 = L_shr( L_tmp1, sub( exp2, exp1 ) ); /*Q31*/ exp_den = exp2; move16(); } - L_frac_den = L_sub(L_tmp1,L_tmp2); /*Q31*/ + L_frac_den = L_sub( L_tmp1, L_tmp2 ); /*Q31*/ - frac_den = extract_h(L_frac_den); - frac_den = s_max(frac_den,1); - L_frac_den = L_max(L_frac_den,1); - exp = norm_l(L_frac_den); - tmp = div_s(shl(1,sub(14,exp)),frac_den); /*Q(14-exp)*/ + frac_den = extract_h( L_frac_den ); + frac_den = s_max( frac_den, 1 ); + L_frac_den = L_max( L_frac_den, 1 ); + exp = norm_l( L_frac_den ); + tmp = div_s( shl( 1, sub( 14, exp ) ), frac_den ); /*Q(14-exp)*/ + L_tmp1 = L_mult( coeff[3], coeff[4] ); /*Q31*/ + exp1 = add( exp_coeff[3], exp_coeff[4] ); - L_tmp1 = L_mult(coeff[3],coeff[4]); /*Q31*/ - exp1 = add(exp_coeff[3], exp_coeff[4]); + L_tmp2 = L_mult( coeff[1], coeff[2] ); /*Q31*/ + exp2 = add( exp_coeff[1], exp_coeff[2] ); - L_tmp2 = L_mult(coeff[1],coeff[2]); /*Q31*/ - exp2 = add(exp_coeff[1], exp_coeff[2]); - - IF(GT_16(exp1,exp2)) + IF( GT_16( exp1, exp2 ) ) { - L_tmp2 = L_shr(L_tmp2,sub(exp1,exp2)); /*Q31*/ + L_tmp2 = L_shr( L_tmp2, sub( exp1, exp2 ) ); /*Q31*/ exp_num = exp1; move16(); } ELSE { - L_tmp1 = L_shr(L_tmp1,sub(exp2,exp1)); /*Q31*/ + L_tmp1 = L_shr( L_tmp1, sub( exp2, exp1 ) ); /*Q31*/ exp_num = exp2; move16(); } #ifdef BASOP_NOGLOB - L_frac_num = L_sub_o(L_tmp2, L_tmp1, &Overflow); /*Q31*/ -#else /* BASOP_NOGLOB */ - L_frac_num = L_sub(L_tmp2, L_tmp1); /*Q31*/ -#endif /* BASOP_NOGLOB */ + L_frac_num = L_sub_o( L_tmp2, L_tmp1, &Overflow ); /*Q31*/ +#else /* BASOP_NOGLOB */ + L_frac_num = L_sub( L_tmp2, L_tmp1 ); /*Q31*/ +#endif /* BASOP_NOGLOB */ - L_div = Mult_32_16(L_frac_num,tmp); /*Q(30-exp)*/ - exp_div = sub(exp_num,exp_den); + L_div = Mult_32_16( L_frac_num, tmp ); /*Q(30-exp)*/ + exp_div = sub( exp_num, exp_den ); #ifdef BASOP_NOGLOB - *gain_pit = round_fx_o(L_shl_o(L_div,add(exp,exp_div), &Overflow), &Overflow); /*Q14*/ -#else /* BASOP_NOGLOB */ - *gain_pit = round_fx(L_shl(L_div,add(exp,exp_div))); /*Q14*/ -#endif /* BASOP_NOGLOB */ + *gain_pit = round_fx_o( L_shl_o( L_div, add( exp, exp_div ), &Overflow ), &Overflow ); /*Q14*/ +#else /* BASOP_NOGLOB */ + *gain_pit = round_fx( L_shl( L_div, add( exp, exp_div ) ) ); /*Q14*/ +#endif /* BASOP_NOGLOB */ - L_tmp1 = L_mult(coeff[1],coeff[4]); /*Q31*/ - exp1 = add(exp_coeff[1], exp_coeff[4]); + L_tmp1 = L_mult( coeff[1], coeff[4] ); /*Q31*/ + exp1 = add( exp_coeff[1], exp_coeff[4] ); - L_tmp2 = L_mult(coeff[0],coeff[3]); /*Q31*/ - exp2 = add(exp_coeff[0], exp_coeff[3]); + L_tmp2 = L_mult( coeff[0], coeff[3] ); /*Q31*/ + exp2 = add( exp_coeff[0], exp_coeff[3] ); - IF(GT_16(exp1,exp2)) + IF( GT_16( exp1, exp2 ) ) { - L_tmp2 = L_shr(L_tmp2,sub(exp1,exp2)); /*Q31*/ + L_tmp2 = L_shr( L_tmp2, sub( exp1, exp2 ) ); /*Q31*/ exp_num = exp1; } ELSE { - L_tmp1 = L_shr(L_tmp1,sub(exp2,exp1)); /*Q31*/ + L_tmp1 = L_shr( L_tmp1, sub( exp2, exp1 ) ); /*Q31*/ exp_num = exp2; } #ifdef BASOP_NOGLOB - L_frac_num = L_sub_o(L_tmp2, L_tmp1, &Overflow); /*Q31*/ -#else /* BASOP_NOGLOB */ - L_frac_num = L_sub(L_tmp2, L_tmp1); /*Q31*/ -#endif /* BASOP_NOGLOB */ + L_frac_num = L_sub_o( L_tmp2, L_tmp1, &Overflow ); /*Q31*/ +#else /* BASOP_NOGLOB */ + L_frac_num = L_sub( L_tmp2, L_tmp1 ); /*Q31*/ +#endif /* BASOP_NOGLOB */ - L_div = Mult_32_16(L_frac_num,tmp); /*Q(30-exp)*/ - exp_div = sub(exp_num,exp_den); + L_div = Mult_32_16( L_frac_num, tmp ); /*Q(30-exp)*/ + exp_div = sub( exp_num, exp_den ); #ifdef BASOP_NOGLOB *gain_code = L_shl_sat( L_div, s_max( -31, sub( add( exp, exp_div ), 14 ) ) ); #else - *gain_code = L_shl(L_div,s_max(-31,sub(add(exp,exp_div),14))); + *gain_code = L_shl( L_div, s_max( -31, sub( add( exp, exp_div ), 14 ) ) ); #endif - move32();/*Q16*/ + move32(); /*Q16*/ - *gain_pit = s_max(G_PITCH_MIN_Q14,s_min(*gain_pit,G_PITCH_MAX_Q14)); + *gain_pit = s_max( G_PITCH_MIN_Q14, s_min( *gain_pit, G_PITCH_MAX_Q14 ) ); /*-----------------------------------------------------------------* * limit the pitch gain searching range (if indicated by clip_gain) @@ -782,12 +784,12 @@ void gain_enc_SQ_fx( test(); test(); - IF( EQ_16(clip_gain,1)&>_16(*gain_pit,15565)) + IF( EQ_16( clip_gain, 1 ) && GT_16( *gain_pit, 15565 ) ) { *gain_pit = 15565; move16(); } - ELSE IF( EQ_16(clip_gain,2)&>_16(*gain_pit,10650)) + ELSE IF( EQ_16( clip_gain, 2 ) && GT_16( *gain_pit, 10650 ) ) { *gain_pit = 10650; move16(); @@ -797,45 +799,45 @@ void gain_enc_SQ_fx( * search for the best quantized values *-----------------------------------------------------------------*/ - nBits_pitch = gains_mode[shr(i_subfr,6)]; + nBits_pitch = gains_mode[shr( i_subfr, 6 )]; /* set number of bits for two SQs */ - nBits_code = shr(add(nBits_pitch,1),1); - nBits_pitch = shr(nBits_pitch,1); + nBits_code = shr( add( nBits_pitch, 1 ), 1 ); + nBits_pitch = shr( nBits_pitch, 1 ); /* gain_pit Q */ - /*tmp1 = (G_PITCH_MAX - G_PITCH_MIN) / ((1 << nBits_pitch) - 1);*/ /* set quantization step */ - tmp1 = mult_r(G_PITCH_MAX_Q13,div_s(1,sub(shl(1, nBits_pitch), 1))); /*Q13*/ /* set quantization step */ + /*tmp1 = (G_PITCH_MAX - G_PITCH_MIN) / ((1 << nBits_pitch) - 1);*/ /* set quantization step */ + tmp1 = mult_r( G_PITCH_MAX_Q13, div_s( 1, sub( shl( 1, nBits_pitch ), 1 ) ) ); /*Q13*/ /* set quantization step */ - index = usquant_fx( *gain_pit, gain_pit, G_PITCH_MIN_Q14, tmp1, shl(1, nBits_pitch) ); + index = usquant_fx( *gain_pit, gain_pit, G_PITCH_MIN_Q14, tmp1, shl( 1, nBits_pitch ) ); move16(); push_indice_fx( hBstr, IND_GAIN_PIT, index, nBits_pitch ); /* gain_code Q */ /* *gain_code /= gcode0; */ - IF(gcode0 != 0) + IF( gcode0 != 0 ) { - tmp = div_s(16384,gcode0); /*Q15*/ - L_tmp = Mult_32_16(*gain_code,tmp); /*Q16*/ - *gain_code = L_shr(L_tmp,add(14,exp_gcode0)); /*Q16*/ + tmp = div_s( 16384, gcode0 ); /*Q15*/ + L_tmp = Mult_32_16( *gain_code, tmp ); /*Q16*/ + *gain_code = L_shr( L_tmp, add( 14, exp_gcode0 ) ); /*Q16*/ } index = gain_quant_fx( gain_code, &gain_code16, LG10_G_CODE_MIN_Q14, LG10_G_CODE_MAX_Q13, nBits_code, &expg ); push_indice_fx( hBstr, IND_GAIN_CODE, index, nBits_code ); - L_tmp = L_mult(gain_code16,gcode0); /*Q0*Q0 -> Q1*/ + L_tmp = L_mult( gain_code16, gcode0 ); /*Q0*Q0 -> Q1*/ #ifdef BASOP_NOGLOB *gain_code = L_shl_sat( L_tmp, add( add( expg, exp_gcode0 ), 15 ) ); #else - *gain_code = L_shl(L_tmp,add(add(expg,exp_gcode0),15)); + *gain_code = L_shl( L_tmp, add( add( expg, exp_gcode0 ), 15 ) ); #endif - move32(); /*Q16*/ + move32(); /*Q16*/ /* *norm_gain_code = *gain_code / *gain_inov; */ - exp = sub(norm_s(*gain_inov),1); - exp = s_max(exp, 0); + exp = sub( norm_s( *gain_inov ), 1 ); + exp = s_max( exp, 0 ); - tmp = div_s(shr(8192,exp),*gain_inov); - *norm_gain_code = L_shr(Mult_32_16(*gain_code, tmp),sub(1,exp)); + tmp = div_s( shr( 8192, exp ), *gain_inov ); + *norm_gain_code = L_shr( Mult_32_16( *gain_code, tmp ), sub( 1, exp ) ); move32(); return; @@ -846,12 +848,12 @@ void gain_enc_SQ_fx( * * Quantization of gain for Gaussian codebook *-------------------------------------------------------------------*/ -Word16 gain_enc_gaus_fx( /* o : Return index of quantization */ - Word32 *gain, /* i/o: Code gain to quantize */ - const Word16 bits, /* i : number of bits to quantize */ - const Word16 lowBound, /* i : lower bound of quantizer (dB) Q8 */ - const Word16 stepSize, /* i : Step size choice Q14 */ - const Word16 inv_stepSize /* i : Step size choice Q15 */ +Word16 gain_enc_gaus_fx( /* o : Return index of quantization */ + Word32 *gain, /* i/o: Code gain to quantize */ + const Word16 bits, /* i : number of bits to quantize */ + const Word16 lowBound, /* i : lower bound of quantizer (dB) Q8 */ + const Word16 stepSize, /* i : Step size choice Q14 */ + const Word16 inv_stepSize /* i : Step size choice Q15 */ ) { Word16 index, exp_gain, frac_gain, wtmp; @@ -861,79 +863,79 @@ Word16 gain_enc_gaus_fx( /* o : Return index of quantization */ Flag Overflow = 0; #endif /*enr = 20.0 * log10(*gain + 0.001) codebook gain in dB */ - exp_gain = norm_l(*gain); - frac_gain = Log2_norm_lc(L_shl(*gain, exp_gain)); - exp_gain = sub(30-16, exp_gain); + exp_gain = norm_l( *gain ); + frac_gain = Log2_norm_lc( L_shl( *gain, exp_gain ) ); + exp_gain = sub( 30 - 16, exp_gain ); - enr = Mpy_32_16(exp_gain, frac_gain, LG10); /* Output in Q13 */ - wenr = extract_h(L_shl(enr, 8+3)); + enr = Mpy_32_16( exp_gain, frac_gain, LG10 ); /* Output in Q13 */ + wenr = extract_h( L_shl( enr, 8 + 3 ) ); /*----------------------------------------------------------------* * Quantize linearly the log E *----------------------------------------------------------------*/ - wtmp = sub(wenr, lowBound); /* Q8 */ + wtmp = sub( wenr, lowBound ); /* Q8 */ - index = extract_l(L_shr(L_mac(8388608, wtmp, inv_stepSize),16+8)); + index = extract_l( L_shr( L_mac( 8388608, wtmp, inv_stepSize ), 16 + 8 ) ); /* index [0 (1< Q26 */ - enr = L_shr(enr, 10); /*Q26->Q16*/ - frac_gain = L_Extract_lc(enr, &exp_gain); + enr = L_mult( enr_q, 21772 ); /* 0.166096 in Q17 -> Q26 */ + enr = L_shr( enr, 10 ); /*Q26->Q16*/ + frac_gain = L_Extract_lc( enr, &exp_gain ); - Ltmp = Pow2(14, frac_gain); /* Put 14 as exponent */ - exp_gain= sub(exp_gain, 14); /* Retreive exponent of wtmp */ + Ltmp = Pow2( 14, frac_gain ); /* Put 14 as exponent */ + exp_gain = sub( exp_gain, 14 ); /* Retreive exponent of wtmp */ #ifdef BASOP_NOGLOB - *gain = L_shl_o(Ltmp ,add(16,exp_gain), &Overflow); + *gain = L_shl_o( Ltmp, add( 16, exp_gain ), &Overflow ); #else - *gain = L_shl(Ltmp ,add(16,exp_gain)); + *gain = L_shl( Ltmp, add( 16, exp_gain ) ); #endif move32(); /*Q16*/ return index; } /*-----------------------------------------------------------------* - * gain_enc_tc() - * - * Search and quantization of gain_code for subframes (in the - * beginning of frame) without pulses in TC - 3b coding. - * In this case: - * - gain_pit = 0 - * - gain_code - scalar quantization (no prediciton history used) - *-----------------------------------------------------------------*/ + * gain_enc_tc() + * + * Search and quantization of gain_code for subframes (in the + * beginning of frame) without pulses in TC - 3b coding. + * In this case: + * - gain_pit = 0 + * - gain_code - scalar quantization (no prediciton history used) + *-----------------------------------------------------------------*/ void gain_enc_tc_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 gains_mode[], /* i : gain bits */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 xn_fx[], /* i : target vector */ - const Word16 y2_fx[], /* i : zero-memory filtered algebraic codebook excitation */ - const Word16 code_fx[], /* i : algebraic excitation */ - const Word16 Es_pred_fx, /* i : predicted scaled innovation energy */ - Word16 *gain_pit_fx, /* o : Pitch gain / Quantized pitch gain */ - Word32 *gain_code_fx, /* o : quantized codebook gain */ - Word16 *gain_inov_fx, /* o : innovation gain */ - Word32 *norm_gain_code_fx, /* o : norm. gain of the codebook excitation */ - const Word16 Q_xn /* i : xn and y1 scaling Q0 */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 gains_mode[], /* i : gain bits */ + const Word16 i_subfr, /* i : subframe index */ + const Word16 xn_fx[], /* i : target vector */ + const Word16 y2_fx[], /* i : zero-memory filtered algebraic codebook excitation */ + const Word16 code_fx[], /* i : algebraic excitation */ + const Word16 Es_pred_fx, /* i : predicted scaled innovation energy */ + Word16 *gain_pit_fx, /* o : Pitch gain / Quantized pitch gain */ + Word32 *gain_code_fx, /* o : quantized codebook gain */ + Word16 *gain_inov_fx, /* o : innovation gain */ + Word32 *norm_gain_code_fx, /* o : norm. gain of the codebook excitation */ + const Word16 Q_xn /* i : xn and y1 scaling Q0 */ ) { - Word16 i, index=0, nBits, num, den, exp_num, exp_den; + Word16 i, index = 0, nBits, num, den, exp_num, exp_den; Word16 Ei_fx, g_code_fx, gcode0_fx; - Word16 expg, expg2, e_tmp, f_tmp, exp_gcode0, tmp_fx, frac,tmp16; + Word16 expg, expg2, e_tmp, f_tmp, exp_gcode0, tmp_fx, frac, tmp16; Word32 L_tmp, L_tmp1; - Word16 wgain_code=0, gain_code16; + Word16 wgain_code = 0, gain_code16; *gain_pit_fx = 0; move16(); /*----------------------------------------------------------------* * get number of bits for gain quantization *----------------------------------------------------------------*/ - nBits = gains_mode[shr(i_subfr,6)]; + nBits = gains_mode[shr( i_subfr, 6 )]; /*----------------------------------------------------------------* * find the code pitch (for current subframe) @@ -941,31 +943,31 @@ void gain_enc_tc_fx( /**gain_code = dotp( xn, y2, L_SUBFR )/( dotp( y2, y2, L_SUBFR ) + 0.01f );*/ /* Compute scalar product */ - L_tmp = Dot_product(y2_fx, y2_fx, L_SUBFR); /* -18 (y2 Q9) */ - exp_den = norm_l(L_tmp); - den = extract_h(L_shl(L_tmp, exp_den)); - exp_den = sub(add(exp_den, 18), shl(Q_xn, 1)); + L_tmp = Dot_product( y2_fx, y2_fx, L_SUBFR ); /* -18 (y2 Q9) */ + exp_den = norm_l( L_tmp ); + den = extract_h( L_shl( L_tmp, exp_den ) ); + exp_den = sub( add( exp_den, 18 ), shl( Q_xn, 1 ) ); /* Compute scalar product */ - L_tmp1 = Dot_product(xn_fx, y2_fx, L_SUBFR); /* -9 (y2 Q9) */ - exp_num = sub(norm_l(L_tmp1),1); - num = extract_h(L_shl(L_tmp1, exp_num)); - exp_num = sub(add(exp_num, 8 ), Q_xn); + L_tmp1 = Dot_product( xn_fx, y2_fx, L_SUBFR ); /* -9 (y2 Q9) */ + exp_num = sub( norm_l( L_tmp1 ), 1 ); + num = extract_h( L_shl( L_tmp1, exp_num ) ); + exp_num = sub( add( exp_num, 8 ), Q_xn ); - tmp16 = s_or(shr(num, 16), 1); /* extract sign if num < 0 tmp16 = -1 else tmp16 = 1 */ - num = abs_s(num); + tmp16 = s_or( shr( num, 16 ), 1 ); /* extract sign if num < 0 tmp16 = -1 else tmp16 = 1 */ + num = abs_s( num ); /*----------------------------------------------------------------* * compute gain = xy/yy *----------------------------------------------------------------*/ - g_code_fx = div_s(num, den); + g_code_fx = div_s( num, den ); - i = sub(exp_num, exp_den); /* Gain_trans in Q7 */ - g_code_fx = i_mult2(g_code_fx, tmp16); /* apply sign */ + i = sub( exp_num, exp_den ); /* Gain_trans in Q7 */ + g_code_fx = i_mult2( g_code_fx, tmp16 ); /* apply sign */ #ifdef BASOP_NOGLOB *gain_code_fx = L_shr_sat( L_deposit_l( g_code_fx ), i ); #else - *gain_code_fx = L_shr(L_deposit_l(g_code_fx),i); + *gain_code_fx = L_shr( L_deposit_l( g_code_fx ), i ); #endif move32(); @@ -978,45 +980,45 @@ void gain_enc_tc_fx( move16(); /*Ecode = (dotp( code, code, L_SUBFR) + 0.01f) / L_SUBFR; - *gain_inov = 1.0f / (float)sqrt( Ecode );*/ + *gain_inov = 1.0f / (float)sqrt( Ecode );*/ - L_tmp = Dot_product12(code_fx, code_fx, L_SUBFR, &expg); - expg = sub(expg, 18 + 6); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ + L_tmp = Dot_product12( code_fx, code_fx, L_SUBFR, &expg ); + expg = sub( expg, 18 + 6 ); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ expg2 = expg; move16(); L_tmp1 = L_tmp; /* sets to 'L_tmp' in 1 clock */ - move32(); - L_tmp = Isqrt_lc(L_tmp, &expg); + move32(); + L_tmp = Isqrt_lc( L_tmp, &expg ); - *gain_inov_fx = extract_h(L_shl(L_tmp, sub(expg, 3))); - move16();/* gain_inov in Q12 */ + *gain_inov_fx = extract_h( L_shl( L_tmp, sub( expg, 3 ) ) ); + move16(); /* gain_inov in Q12 */ /*Ei = 10 * (float)log10( Ecode );*/ - e_tmp = norm_l(L_tmp1); - f_tmp = Log2_norm_lc(L_shl(L_tmp1, e_tmp)); - e_tmp = sub(expg2,add(1,e_tmp)); - L_tmp1 = Mpy_32_16(e_tmp, f_tmp, 12330); /* Q13 */ /* 10*log10(2) in Q12*/ - Ei_fx = round_fx(L_shl(L_tmp1, 11)); /* Q8 */ + e_tmp = norm_l( L_tmp1 ); + f_tmp = Log2_norm_lc( L_shl( L_tmp1, e_tmp ) ); + e_tmp = sub( expg2, add( 1, e_tmp ) ); + L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 12330 ); /* Q13 */ /* 10*log10(2) in Q12*/ + Ei_fx = round_fx( L_shl( L_tmp1, 11 ) ); /* Q8 */ /*gcode0 = (float) pow(10, 0.05 * (Es_pred - Ei));*/ - gcode0_fx = sub(Es_pred_fx, Ei_fx); /* Q8 */ + gcode0_fx = sub( Es_pred_fx, Ei_fx ); /* Q8 */ /*-----------------------------------------------------------------* * gcode0 = pow(10.0, gcode0/20) * = pow(2, 3.321928*gcode0/20) * = pow(2, 0.166096*gcode0) *-----------------------------------------------------------------*/ - L_tmp = L_mult(gcode0_fx, 21771); /* *0.166096 in Q17 -> Q26 */ - L_tmp = L_shr(L_tmp, 10); /* From Q26 to Q16 */ - frac = L_Extract_lc(L_tmp, &exp_gcode0); /* Extract exponent of gcode0 */ - gcode0_fx = extract_l(Pow2(14, frac));/* Put 14 as exponent so that */ - exp_gcode0 = sub(exp_gcode0, 14); - IF( GT_16(nBits,3)) + L_tmp = L_mult( gcode0_fx, 21771 ); /* *0.166096 in Q17 -> Q26 */ + L_tmp = L_shr( L_tmp, 10 ); /* From Q26 to Q16 */ + frac = L_Extract_lc( L_tmp, &exp_gcode0 ); /* Extract exponent of gcode0 */ + gcode0_fx = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ + exp_gcode0 = sub( exp_gcode0, 14 ); + IF( GT_16( nBits, 3 ) ) { /*g_code = *gain_code / gcode0;*/ - IF(gcode0_fx != 0) + IF( gcode0_fx != 0 ) { - tmp16 = div_s(16384,gcode0_fx); /*Q15*/ - L_tmp = Mult_32_16(*gain_code_fx,tmp16); /*Q16*/ - *gain_code_fx = L_shr(L_tmp,add(14,exp_gcode0)); /*Q16*/ + tmp16 = div_s( 16384, gcode0_fx ); /*Q15*/ + L_tmp = Mult_32_16( *gain_code_fx, tmp16 ); /*Q16*/ + *gain_code_fx = L_shr( L_tmp, add( 14, exp_gcode0 ) ); /*Q16*/ } ELSE { @@ -1028,21 +1030,22 @@ void gain_enc_tc_fx( index = gain_quant_fx( gain_code_fx, &gain_code16, LG10_G_CODE_MIN_TC_Q14, LG10_G_CODE_MAX_TC_Q13, nBits, &expg ); /**gain_code = g_code * gcode0;*/ - L_tmp = L_mult(gain_code16,gcode0_fx); /*Q0*Q0 -> Q1*/ - *gain_code_fx = L_shl(L_tmp,add(add(expg,exp_gcode0),15)); /*Q16*/ move32(); + L_tmp = L_mult( gain_code16, gcode0_fx ); /*Q0*Q0 -> Q1*/ + *gain_code_fx = L_shl( L_tmp, add( add( expg, exp_gcode0 ), 15 ) ); /*Q16*/ + move32(); push_indice_fx( hBstr, IND_GAIN_CODE, index, nBits ); } ELSE { - index = N_GAIN_CODE_TC-1; + index = N_GAIN_CODE_TC - 1; move16(); - FOR( i=0; i < N_GAIN_CODE_TC-1; i++ ) + FOR( i = 0; i < N_GAIN_CODE_TC - 1; i++ ) { - L_tmp = L_mult(tbl_gain_code_tc_quant_mean[i], gcode0_fx); /* Q13*Q0 -> Q14 */ - L_tmp = L_shl(L_tmp, add(exp_gcode0, 2)); /* Q14 -> Q16 */ + L_tmp = L_mult( tbl_gain_code_tc_quant_mean[i], gcode0_fx ); /* Q13*Q0 -> Q14 */ + L_tmp = L_shl( L_tmp, add( exp_gcode0, 2 ) ); /* Q14 -> Q16 */ - IF( LT_32(*gain_code_fx, L_tmp)) + IF( LT_32( *gain_code_fx, L_tmp ) ) { index = i; move16(); @@ -1052,15 +1055,15 @@ void gain_enc_tc_fx( /*----------------------------------------------------------------* * 3-bit -> 2-bit encoding *----------------------------------------------------------------*/ - IF( EQ_16(nBits,2)) + IF( EQ_16( nBits, 2 ) ) { /* 2-bit -> 3-bit decoding */ - index = shr(index ,1); - wgain_code = tbl_gain_code_tc_fx[shl(index,1)]; + index = shr( index, 1 ); + wgain_code = tbl_gain_code_tc_fx[shl( index, 1 )]; move16(); /**gain_code *= gcode0;*/ - L_tmp = L_mult(wgain_code, gcode0_fx); /* Q13*Q0 -> Q14 */ - *gain_code_fx= L_shl(L_tmp, add(exp_gcode0, 2)); + L_tmp = L_mult( wgain_code, gcode0_fx ); /* Q13*Q0 -> Q14 */ + *gain_code_fx = L_shl( L_tmp, add( exp_gcode0, 2 ) ); move32(); /* Q14 -> Q16 */ push_indice_fx( hBstr, IND_GAIN_CODE, index, nBits ); } @@ -1069,11 +1072,11 @@ void gain_enc_tc_fx( wgain_code = tbl_gain_code_tc_fx[index]; move16(); /**gain_code *= gcode0;*/ - L_tmp = L_mult(wgain_code, gcode0_fx); /* Q13*Q0 -> Q14 */ + L_tmp = L_mult( wgain_code, gcode0_fx ); /* Q13*Q0 -> Q14 */ #ifdef BASOP_NOGLOB *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 2 ) ); #else - *gain_code_fx= L_shl(L_tmp, add(exp_gcode0, 2)); + *gain_code_fx = L_shl( L_tmp, add( exp_gcode0, 2 ) ); #endif move32(); /* Q14 -> Q16 */ push_indice_fx( hBstr, IND_GAIN_CODE, index, nBits ); @@ -1084,19 +1087,19 @@ void gain_enc_tc_fx( * decode normalized codebook gain *-----------------------------------------------------------------*/ /**norm_gain_code = *gain_code / *gain_inov;*/ - expg = sub(norm_s(*gain_inov_fx),1); - expg = s_max(expg, 0); + expg = sub( norm_s( *gain_inov_fx ), 1 ); + expg = s_max( expg, 0 ); - tmp_fx = div_s(shr(8192,expg),*gain_inov_fx); - *norm_gain_code_fx = L_shr(Mult_32_16(*gain_code_fx, tmp_fx),sub(1,expg)); + tmp_fx = div_s( shr( 8192, expg ), *gain_inov_fx ); + *norm_gain_code_fx = L_shr( Mult_32_16( *gain_code_fx, tmp_fx ), sub( 1, expg ) ); move32(); return; } /*-----------------------------------------------------------------* - * Find_Opt_gainQ_fx() - * - * Find the best quantizer - *-----------------------------------------------------------------*/ + * Find_Opt_gainQ_fx() + * + * Find the best quantizer + *-----------------------------------------------------------------*/ static Word16 Find_Opt_gainQ_fx( Word16 *coeff, Word16 *exp_coeff, @@ -1104,12 +1107,12 @@ static Word16 Find_Opt_gainQ_fx( Word32 *gain_code, Word16 gcode0, Word16 exp_gcode0, - const Word16 *cdbk, /* i : Codebook used */ - const Word16 size /* i : size of Codebook used */ + const Word16 *cdbk, /* i : Codebook used */ + const Word16 size /* i : size of Codebook used */ ) { Word16 index, i, j; - const Word16 *p; + const Word16 *p; Word16 g_pitch, g2_pitch, g_code, g_pit_cod, g2_code, g2_code_lo; Word32 dist_min; Word16 coeff_lo[5]; @@ -1148,130 +1151,134 @@ static Word16 Find_Opt_gainQ_fx( * g_pitch*g_code * coeff[4] ;exp_max4 = exp_coeff[4] + 1 + exp_code *----------------------------------------------------------------*/ - exp_code = add(exp_gcode0, 6); + exp_code = add( exp_gcode0, 6 ); - exp_max[0] = sub(exp_coeff[0], 13); + exp_max[0] = sub( exp_coeff[0], 13 ); move16(); - exp_max[1] = sub(exp_coeff[1], 14); + exp_max[1] = sub( exp_coeff[1], 14 ); move16(); - exp_max[2] = add(exp_coeff[2], add(15, shl(exp_code, 1))); + exp_max[2] = add( exp_coeff[2], add( 15, shl( exp_code, 1 ) ) ); move16(); - exp_max[3] = add(exp_coeff[3], exp_code); + exp_max[3] = add( exp_coeff[3], exp_code ); move16(); - exp_max[4] = add(exp_coeff[4], add(1, exp_code)); + exp_max[4] = add( exp_coeff[4], add( 1, exp_code ) ); move16(); /* Find maximum exponant */ e_max = exp_max[0]; move16(); - FOR (i = 1; i < 5; i++) + FOR( i = 1; i < 5; i++ ) { - e_max = s_max(exp_max[i], e_max); + e_max = s_max( exp_max[i], e_max ); } /* align coeff[] and save in special 32 bit double precision */ - FOR (i = 0; i < 5; i++) + FOR( i = 0; i < 5; i++ ) { - j = add(sub(e_max, exp_max[i]), 2); /* /4 to avoid overflow */ - L_tmp = L_deposit_h(coeff[i]); - L_tmp = L_shr(L_tmp, j); - L_Extract(L_tmp, &coeff[i], &coeff_lo[i]); - coeff_lo[i] = shr(coeff_lo[i], 3);/* lo >> 3 */ move16(); + j = add( sub( e_max, exp_max[i] ), 2 ); /* /4 to avoid overflow */ + L_tmp = L_deposit_h( coeff[i] ); + L_tmp = L_shr( L_tmp, j ); + L_Extract( L_tmp, &coeff[i], &coeff_lo[i] ); + coeff_lo[i] = shr( coeff_lo[i], 3 ); /* lo >> 3 */ + move16(); } /* searching of codebook */ p = cdbk; move16(); - dist_min = L_deposit_h(MAX_16); + dist_min = L_deposit_h( MAX_16 ); index = 0; move16(); - FOR (i = 0; i < size; i++) + FOR( i = 0; i < size; i++ ) { g_pitch = *p++; move16(); g_code = *p++; move16(); - g_code = mult_r(g_code, gcode0); - g2_pitch = mult_r(g_pitch, g_pitch); - g_pit_cod = mult_r(g_code, g_pitch); - L_tmp = L_mult(g_code, g_code); - g2_code_lo = L_Extract_lc(L_tmp, &g2_code); - - L_tmp = L_mult(coeff[2], g2_code_lo); - L_tmp = L_shr(L_tmp, 3); - L_tmp = L_mac(L_tmp, coeff_lo[0], g2_pitch); - L_tmp = L_mac(L_tmp, coeff_lo[1], g_pitch); - L_tmp = L_mac(L_tmp, coeff_lo[2], g2_code); - L_tmp = L_mac(L_tmp, coeff_lo[3], g_code); - L_tmp = L_mac(L_tmp, coeff_lo[4], g_pit_cod); - L_tmp = L_shr(L_tmp, 12); - L_tmp = L_mac(L_tmp, coeff[0], g2_pitch); - L_tmp = L_mac(L_tmp, coeff[1], g_pitch); - L_tmp = L_mac(L_tmp, coeff[2], g2_code); - L_tmp = L_mac(L_tmp, coeff[3], g_code); - L_tmp = L_mac(L_tmp, coeff[4], g_pit_cod); + g_code = mult_r( g_code, gcode0 ); + g2_pitch = mult_r( g_pitch, g_pitch ); + g_pit_cod = mult_r( g_code, g_pitch ); + L_tmp = L_mult( g_code, g_code ); + g2_code_lo = L_Extract_lc( L_tmp, &g2_code ); + + L_tmp = L_mult( coeff[2], g2_code_lo ); + L_tmp = L_shr( L_tmp, 3 ); + L_tmp = L_mac( L_tmp, coeff_lo[0], g2_pitch ); + L_tmp = L_mac( L_tmp, coeff_lo[1], g_pitch ); + L_tmp = L_mac( L_tmp, coeff_lo[2], g2_code ); + L_tmp = L_mac( L_tmp, coeff_lo[3], g_code ); + L_tmp = L_mac( L_tmp, coeff_lo[4], g_pit_cod ); + L_tmp = L_shr( L_tmp, 12 ); + L_tmp = L_mac( L_tmp, coeff[0], g2_pitch ); + L_tmp = L_mac( L_tmp, coeff[1], g_pitch ); + L_tmp = L_mac( L_tmp, coeff[2], g2_code ); + L_tmp = L_mac( L_tmp, coeff[3], g_code ); + L_tmp = L_mac( L_tmp, coeff[4], g_pit_cod ); #ifdef BASOP_NOGLOB - L_tmp1 = L_sub_o(L_tmp, dist_min, &Overflow); -#else /* BASOP_NOGLOB */ - L_tmp1 = L_sub(L_tmp, dist_min); + L_tmp1 = L_sub_o( L_tmp, dist_min, &Overflow ); +#else /* BASOP_NOGLOB */ + L_tmp1 = L_sub( L_tmp, dist_min ); #endif /* BASOP_NOGLOB */ - if (L_tmp1 < 0) + if ( L_tmp1 < 0 ) { index = i; move16(); } - dist_min = L_min(L_tmp, dist_min); + dist_min = L_min( L_tmp, dist_min ); } - p = &cdbk[add(index, index)]; + p = &cdbk[add( index, index )]; move16(); - *gain_pit = *p++; /* selected pitch gain in Q14 */ move16(); - g_code = *p++; /* selected code gain in Q9 */ move16(); + *gain_pit = *p++; /* selected pitch gain in Q14 */ + move16(); + g_code = *p++; /* selected code gain in Q9 */ + move16(); - L_tmp = L_mult(g_code, gcode0); /* Q9*Q0 -> Q10 */ + L_tmp = L_mult( g_code, gcode0 ); /* Q9*Q0 -> Q10 */ #ifdef BASOP_NOGLOB L_tmp = L_shl_sat( L_tmp, add( exp_gcode0, 6 ) ); /* Q10 -> Q16 */ #else L_tmp = L_shl( L_tmp, add( exp_gcode0, 6 ) ); /* Q10 -> Q16 */ #endif - *gain_code = L_tmp; /* gain of code in Q16 */ move16(); + *gain_code = L_tmp; /* gain of code in Q16 */ + move16(); return index; } /*---------------------------------------------------------------------* - * gain_enc_lbr() - * - * Quantization of pitch and codebook gains without prediction (memory-less) - * in ACELP at 6.6 and 7.5 kbps - * - the gain codebooks and gain estimation constants are different in each subframe - * - the estimated gain, gcode0, is first determined based on - * classification and/or previous quantized gains (from previous subframes in the current frame) - * - a correction factor gamma = g_code / gcode0 is then vector quantized - * along with gain_pit - * - the mean-squared error criterion is used for codebook search - *---------------------------------------------------------------------*/ + * gain_enc_lbr() + * + * Quantization of pitch and codebook gains without prediction (memory-less) + * in ACELP at 6.6 and 7.5 kbps + * - the gain codebooks and gain estimation constants are different in each subframe + * - the estimated gain, gcode0, is first determined based on + * classification and/or previous quantized gains (from previous subframes in the current frame) + * - a correction factor gamma = g_code / gcode0 is then vector quantized + * along with gain_pit + * - the mean-squared error criterion is used for codebook search + *---------------------------------------------------------------------*/ void gain_enc_lbr_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 gains_mode[], /* i : gain bits */ - const Word16 coder_type, /* i : coding type */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 *xn, /* i : target vector Q_xn*/ - const Word16 *y1, /* i : zero-memory filtered adaptive excitation Q_xn*/ - const Word16 Q_xn, /* i : xn and y1 format */ - const Word16 *y2, /* i : zero-memory filtered algebraic codebook excitation Q9*/ - const Word16 *code, /* i : algebraic excitation Q9*/ - Word16 *gain_pit, /* o : quantized pitch gain Q14*/ - Word32 *gain_code, /* o : quantized codebook gain Q16*/ - Word16 *gain_inov, /* o : gain of the innovation (used for normalization) Q12*/ - Word32 *norm_gain_code, /* o : norm. gain of the codebook excitation Q16*/ - Word16 *g_corr, /* i/o: correlations , -2,, -2 and 2 mant/exp*/ - Word32 gc_mem[], /* i/o: gain_code from previous subframes */ - Word16 gp_mem[], /* i/o: gain_pitch from previous subframes */ - const Word16 clip_gain, /* i : gain pitch clipping flag (1 = clipping) */ - const int16_t L_subfr /* i : subframe length */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 gains_mode[], /* i : gain bits */ + const Word16 coder_type, /* i : coding type */ + const Word16 i_subfr, /* i : subframe index */ + const Word16 *xn, /* i : target vector Q_xn*/ + const Word16 *y1, /* i : zero-memory filtered adaptive excitation Q_xn*/ + const Word16 Q_xn, /* i : xn and y1 format */ + const Word16 *y2, /* i : zero-memory filtered algebraic codebook excitation Q9*/ + const Word16 *code, /* i : algebraic excitation Q9*/ + Word16 *gain_pit, /* o : quantized pitch gain Q14*/ + Word32 *gain_code, /* o : quantized codebook gain Q16*/ + Word16 *gain_inov, /* o : gain of the innovation (used for normalization) Q12*/ + Word32 *norm_gain_code, /* o : norm. gain of the codebook excitation Q16*/ + Word16 *g_corr, /* i/o: correlations , -2,, -2 and 2 mant/exp*/ + Word32 gc_mem[], /* i/o: gain_code from previous subframes */ + Word16 gp_mem[], /* i/o: gain_pitch from previous subframes */ + const Word16 clip_gain, /* i : gain pitch clipping flag (1 = clipping) */ + const int16_t L_subfr /* i : subframe length */ ) { @@ -1284,7 +1291,7 @@ void gain_enc_lbr_fx( L_subfr_sf = 6; move16(); - if (GT_16(L_subfr, L_SUBFR)) + if ( GT_16( L_subfr, L_SUBFR ) ) { L_subfr_sf = 7; move16(); @@ -1299,43 +1306,46 @@ void gain_enc_lbr_fx( move16(); exp_coeff[0] = g_corr[1]; move16(); - coeff[1] = negate(g_corr[2]); - move16(); /* coeff[1] = -2 xn yy1 */ - exp_coeff[1] = add(g_corr[3], 1); + coeff[1] = negate( g_corr[2] ); + move16(); /* coeff[1] = -2 xn yy1 */ + exp_coeff[1] = add( g_corr[3], 1 ); move16(); /* Compute scalar product */ #ifdef DEBUG - if (L_subfr != L_SUBFR) + if ( L_subfr != L_SUBFR ) { - PMT("Entire function needs review to accommode for L_subfr > L_SUBFR"); + PMT( "Entire function needs review to accommode for L_subfr > L_SUBFR" ); } #endif - coeff[2] = extract_h(Dot_product12(y2, y2, L_subfr, &exp)); - exp_coeff[2] = add(sub(exp, 18), shl(Q_xn, 1)); /* -18 (y2 Q9) */ move16(); + coeff[2] = extract_h( Dot_product12( y2, y2, L_subfr, &exp ) ); + exp_coeff[2] = add( sub( exp, 18 ), shl( Q_xn, 1 ) ); /* -18 (y2 Q9) */ + move16(); /* Compute scalar product -2* */ - coeff[3] = extract_h(L_negate(Dot_product12(xn, y2, L_subfr, &exp))); - exp_coeff[3] = add(sub(exp, 9 - 1), Q_xn); /* -9 (y2 Q9), +1 (2 xn y2) */ move16(); + coeff[3] = extract_h( L_negate( Dot_product12( xn, y2, L_subfr, &exp ) ) ); + exp_coeff[3] = add( sub( exp, 9 - 1 ), Q_xn ); /* -9 (y2 Q9), +1 (2 xn y2) */ + move16(); /* Compute scalar product 2* */ - coeff[4] = extract_h(Dot_product12(y1, y2, L_subfr, &exp)); - exp_coeff[4] = add(sub(exp, 9 - 1), Q_xn); /* -9 (y2 Q9), +1 (2 yy1 y2) */ move16(); + coeff[4] = extract_h( Dot_product12( y1, y2, L_subfr, &exp ) ); + exp_coeff[4] = add( sub( exp, 9 - 1 ), Q_xn ); /* -9 (y2 Q9), +1 (2 yy1 y2) */ + move16(); /*g_corr[2] += 0.01F; g_corr[3] -= 0.02F; g_corr[4] += 0.02F;*/ /*Ecode = ( dotp( code, code, L_SUBFR ) + 0.01f ) / L_SUBFR; - *gain_inov = 1.0f / (float)sqrt(Ecode);*/ - L_tmp = Dot_product12(code, code, L_subfr, &exp_code); + *gain_inov = 1.0f / (float)sqrt(Ecode);*/ + L_tmp = Dot_product12( code, code, L_subfr, &exp_code ); L_inov = L_tmp; /* sets to 'L_tmp' in 1 clock */ - move32(); + move32(); /* exp_code: -18 (code in Q9), -6 (/L_SUBFR), -31 (L_tmp Q31->Q0) */ /* output gain_inov*/ - exp_inov = sub(exp_code, add(18, L_subfr_sf)); - L_inov = Isqrt_lc(L_inov, &exp_inov); - *gain_inov = extract_h(L_shl(L_inov, sub(exp_inov, 3))); /* gain_inov in Q12 */ + exp_inov = sub( exp_code, add( 18, L_subfr_sf ) ); + L_inov = Isqrt_lc( L_inov, &exp_inov ); + *gain_inov = extract_h( L_shl( L_inov, sub( exp_inov, 3 ) ) ); /* gain_inov in Q12 */ /*-----------------------------------------------------------------* @@ -1343,54 +1353,54 @@ void gain_enc_lbr_fx( * set the gains searching range *-----------------------------------------------------------------*/ - nBits = gains_mode[shr(i_subfr, L_subfr_sf)]; + nBits = gains_mode[shr( i_subfr, L_subfr_sf )]; move16(); - size = shl(1, nBits); + size = shl( 1, nBits ); - ctype = shl(sub(coder_type, 1), 1); + ctype = shl( sub( coder_type, 1 ), 1 ); /*-----------------------------------------------------------------* * calculate prediction of gcode * search for the best codeword *-----------------------------------------------------------------*/ - IF (i_subfr == 0) + IF( i_subfr == 0 ) { b = b_1sfr_fx; move16(); n_pred = 2; move16(); - SWITCH ( nBits ) + SWITCH( nBits ) { - case 8: + case 8: { cdbk = gp_gamma_1sfr_8b_fx; move16(); - if (EQ_16(clip_gain, 1)) + if ( EQ_16( clip_gain, 1 ) ) { - size = sub(size, 60); + size = sub( size, 60 ); } move16(); BREAK; } - case 7: + case 7: { cdbk = gp_gamma_1sfr_7b_fx; move16(); - if (EQ_16(clip_gain, 1)) + if ( EQ_16( clip_gain, 1 ) ) { - size = sub(size, 27); + size = sub( size, 27 ); } move16(); BREAK; } - case 6: + case 6: { cdbk = gp_gamma_1sfr_6b_fx; move16(); - if (EQ_16(clip_gain, 1)) + if ( EQ_16( clip_gain, 1 ) ) { - size = sub(size, 10); + size = sub( size, 10 ); } move16(); BREAK; @@ -1400,23 +1410,23 @@ void gain_enc_lbr_fx( /* calculate predicted gain */ aux[0] = 4096; move16(); - aux[1] = shl(ctype,12); + aux[1] = shl( ctype, 12 ); /* gcode0 = (float)pow(10, dotp(b, aux, n_pred) - 0.5f * (float)log10(Ecode)); gcode0 = (float)pow(10, dotp(b, aux, n_pred) - 0.05f * 10 * (float)log10(Ecode)); gcode0 = (float)pow(10, 0.05(20 * dotp(b, aux, n_pred) - 10 * (float)log10(Ecode))); */ - exp_code = sub(exp_code, 18 + 6 + 1); - exp = norm_l(L_tmp); - frac = Log2_norm_lc(L_shl(L_tmp, exp)); - exp = sub(exp_code,exp); - L_tmp1 = Mpy_32_16(exp, frac, 24660); /* Q14 */ /* 10*log10(2) in Q13*/ + exp_code = sub( exp_code, 18 + 6 + 1 ); + exp = norm_l( L_tmp ); + frac = Log2_norm_lc( L_shl( L_tmp, exp ) ); + exp = sub( exp_code, exp ); + L_tmp1 = Mpy_32_16( exp, frac, 24660 ); /* Q14 */ /* 10*log10(2) in Q13*/ - L_tmp = Dot_product(b, aux, n_pred); /*Q25*/ - L_tmp = Mult_32_16(L_tmp,320);/*Q14, 20 in Q4*/ - L_tmp = L_sub(L_tmp,L_tmp1);/*Q14*/ + L_tmp = Dot_product( b, aux, n_pred ); /*Q25*/ + L_tmp = Mult_32_16( L_tmp, 320 ); /*Q14, 20 in Q4*/ + L_tmp = L_sub( L_tmp, L_tmp1 ); /*Q14*/ - gcode0 = round_fx(L_shl(L_tmp, 10)); /* Q8 */ + gcode0 = round_fx( L_shl( L_tmp, 10 ) ); /* Q8 */ /*-----------------------------------------------------------------* * gcode0 = pow(10.0, gcode0/20) @@ -1424,22 +1434,22 @@ void gain_enc_lbr_fx( * = pow(2, 0.166096*gcode0) *-----------------------------------------------------------------*/ - L_tmp = L_mult(gcode0, 21771); /* *0.166096 in Q17 -> Q26 */ - L_tmp = L_shr(L_tmp, 10); /* From Q26 to Q16 */ - frac = L_Extract_lc(L_tmp, &exp_gcode0); /* Extract exponent of gcode0 */ + L_tmp = L_mult( gcode0, 21771 ); /* *0.166096 in Q17 -> Q26 */ + L_tmp = L_shr( L_tmp, 10 ); /* From Q26 to Q16 */ + frac = L_Extract_lc( L_tmp, &exp_gcode0 ); /* Extract exponent of gcode0 */ - gcode0 = extract_l(Pow2(14, frac));/* Put 14 as exponent so that */ + gcode0 = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ - exp_gcode0 = sub(exp_gcode0, 14); - index= Find_Opt_gainQ_fx(coeff, exp_coeff, gain_pit, gain_code, gcode0, exp_gcode0, cdbk, size); + exp_gcode0 = sub( exp_gcode0, 14 ); + index = Find_Opt_gainQ_fx( coeff, exp_coeff, gain_pit, gain_code, gcode0, exp_gcode0, cdbk, size ); gc_mem[0] = *gain_code; move16(); /*Q16*/ gp_mem[0] = *gain_pit; - move16();/*Q14*/ + move16(); /*Q14*/ } - ELSE IF (EQ_16(i_subfr,L_SUBFR) || EQ_16(L_subfr, 2 * L_SUBFR)) + ELSE IF( EQ_16( i_subfr, L_SUBFR ) || EQ_16( L_subfr, 2 * L_SUBFR ) ) { b = b_2sfr_fx; move16(); @@ -1448,135 +1458,135 @@ void gain_enc_lbr_fx( switch ( nBits ) { - case 7: - { - cdbk = gp_gamma_2sfr_7b_fx; - move16(); - if (EQ_16(clip_gain, 1)) + case 7: { - size = sub(size, 30); + cdbk = gp_gamma_2sfr_7b_fx; + move16(); + if ( EQ_16( clip_gain, 1 ) ) + { + size = sub( size, 30 ); + } + move16(); + BREAK; } - move16(); - BREAK; - } - case 6: - { - cdbk = gp_gamma_2sfr_6b_fx; - move16(); - if (EQ_16(clip_gain, 1)) + case 6: { - size = sub(size, 12); + cdbk = gp_gamma_2sfr_6b_fx; + move16(); + if ( EQ_16( clip_gain, 1 ) ) + { + size = sub( size, 12 ); + } + move16(); + BREAK; } - move16(); - BREAK; - } } /* calculate predicted gain */ aux[0] = 4096; move16(); - aux[1] = shl(ctype,12); + aux[1] = shl( ctype, 12 ); move16(); /*aux[2] = (float)log10(gc_mem[0]); = log2(gc_mem[0])*log10(2);*/ - exp = norm_l(gc_mem[0]); - frac = Log2_norm_lc(L_shl(gc_mem[0], exp)); - exp = sub(sub(30,exp),16); /*Q_format(gc_1sfr_fx)=16*/ - L_tmp1 = Mpy_32_16(exp, frac, 9864); - move16(); /* Q16 */ - aux[2] = round_fx(L_shl(L_tmp1, 12)); /* Q12 */ + exp = norm_l( gc_mem[0] ); + frac = Log2_norm_lc( L_shl( gc_mem[0], exp ) ); + exp = sub( sub( 30, exp ), 16 ); /*Q_format(gc_1sfr_fx)=16*/ + L_tmp1 = Mpy_32_16( exp, frac, 9864 ); + move16(); /* Q16 */ + aux[2] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ - aux[3] = shr(gp_mem[0],2); - move16();/*Q12*/ + aux[3] = shr( gp_mem[0], 2 ); + move16(); /*Q12*/ /*-----------------------------------------------------------------* * gcode0 = pow(10.0, dotp(b, aux, n_pred) * = pow(2, 3.321928*dotp(b, aux, n_pred) *-----------------------------------------------------------------*/ - L_tmp = Dot_product(b, aux, n_pred); /*Q25*/ - L_tmp = Mult_32_16(L_tmp, 27213); /* *3.321928 in Q13 -> Q23 */ - L_tmp = L_shr(L_tmp, 7); /* From Q23 to Q16 */ - frac = L_Extract_lc(L_tmp, &exp_gcode0); /* Extract exponent of gcode0 */ + L_tmp = Dot_product( b, aux, n_pred ); /*Q25*/ + L_tmp = Mult_32_16( L_tmp, 27213 ); /* *3.321928 in Q13 -> Q23 */ + L_tmp = L_shr( L_tmp, 7 ); /* From Q23 to Q16 */ + frac = L_Extract_lc( L_tmp, &exp_gcode0 ); /* Extract exponent of gcode0 */ - gcode0 = extract_l(Pow2(14, frac));/* Put 14 as exponent so that */ + gcode0 = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ - exp_gcode0 = sub(exp_gcode0, 14); + exp_gcode0 = sub( exp_gcode0, 14 ); - index= Find_Opt_gainQ_fx(coeff, exp_coeff, gain_pit, gain_code, gcode0, exp_gcode0, cdbk, size); + index = Find_Opt_gainQ_fx( coeff, exp_coeff, gain_pit, gain_code, gcode0, exp_gcode0, cdbk, size ); gc_mem[1] = *gain_code; move32(); gp_mem[1] = *gain_pit; move16(); } - ELSE IF (EQ_16(i_subfr,2*L_SUBFR)) + ELSE IF( EQ_16( i_subfr, 2 * L_SUBFR ) ) { b = b_3sfr_fx; move16(); n_pred = 6; move16(); - IF(EQ_16(nBits, 7)) + IF( EQ_16( nBits, 7 ) ) { #ifdef IVAS_CODE cdbk = gp_gamma_3sfr_7b_fx; - if (clip_gain == 1) + if ( clip_gain == 1 ) { size -= 28; } #else - //PMT("gp_gamma_3sfr_7b_fx is missing") + // PMT("gp_gamma_3sfr_7b_fx is missing") #endif } ELSE { cdbk = gp_gamma_3sfr_6b_fx; move16(); - if (EQ_16(clip_gain, 1)) + if ( EQ_16( clip_gain, 1 ) ) { - size = sub(size, 11); + size = sub( size, 11 ); } } /* calculate predicted gain */ aux[0] = 4096; move16(); - aux[1] = shl(ctype,12); + aux[1] = shl( ctype, 12 ); move16(); /*aux[2] = (float)log10(gc_mem[0]); = log2(gc_mem[0])*log10(2);*/ - exp = norm_l(gc_mem[0]); - frac = Log2_norm_lc(L_shl(gc_mem[0], exp)); - exp = sub(sub(30,exp),16); /*Q_format(gc_mem[0])=16*/ - L_tmp1 = Mpy_32_16(exp, frac, 9864); /* Q16 */ - aux[2] = round_fx(L_shl(L_tmp1, 12)); /* Q12 */ + exp = norm_l( gc_mem[0] ); + frac = Log2_norm_lc( L_shl( gc_mem[0], exp ) ); + exp = sub( sub( 30, exp ), 16 ); /*Q_format(gc_mem[0])=16*/ + L_tmp1 = Mpy_32_16( exp, frac, 9864 ); /* Q16 */ + aux[2] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ /*aux[3] = (float)log10(gc_mem[1]); = log2(gc_mem[1])*log10(2);*/ - exp = norm_l(gc_mem[1]); - frac = Log2_norm_lc(L_shl(gc_mem[1], exp)); - exp = sub(sub(30,exp),16); /*Q_format(gc_mem[1])=16*/ - L_tmp1 = Mpy_32_16(exp, frac, 9864); /* Q16 */ - aux[3] = round_fx(L_shl(L_tmp1, 12)); /* Q12 */ + exp = norm_l( gc_mem[1] ); + frac = Log2_norm_lc( L_shl( gc_mem[1], exp ) ); + exp = sub( sub( 30, exp ), 16 ); /*Q_format(gc_mem[1])=16*/ + L_tmp1 = Mpy_32_16( exp, frac, 9864 ); /* Q16 */ + aux[3] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ - aux[4] = shr(gp_mem[0],2); - move16();/*Q12*/ - aux[5] = shr(gp_mem[1],2); - move16();/*Q12*/ + aux[4] = shr( gp_mem[0], 2 ); + move16(); /*Q12*/ + aux[5] = shr( gp_mem[1], 2 ); + move16(); /*Q12*/ /*-----------------------------------------------------------------* * gcode0 = pow(10.0, dotp(b, aux, n_pred) * = pow(2, 3.321928*dotp(b, aux, n_pred) *-----------------------------------------------------------------*/ - L_tmp = Dot_product(b, aux, n_pred); /*Q25*/ - L_tmp = Mult_32_16(L_tmp, 27213); /* *3.321928 in Q13 -> Q23 */ - L_tmp = L_shr(L_tmp, 7); /* From Q23 to Q16 */ - frac = L_Extract_lc(L_tmp, &exp_gcode0); /* Extract exponent of gcode0 */ + L_tmp = Dot_product( b, aux, n_pred ); /*Q25*/ + L_tmp = Mult_32_16( L_tmp, 27213 ); /* *3.321928 in Q13 -> Q23 */ + L_tmp = L_shr( L_tmp, 7 ); /* From Q23 to Q16 */ + frac = L_Extract_lc( L_tmp, &exp_gcode0 ); /* Extract exponent of gcode0 */ - gcode0 = extract_l(Pow2(14, frac));/* Put 14 as exponent so that */ + gcode0 = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ - exp_gcode0 = sub(exp_gcode0, 14); + exp_gcode0 = sub( exp_gcode0, 14 ); /*----------------------------------------------------------------* * Find the best quantizer @@ -1605,101 +1615,101 @@ void gain_enc_lbr_fx( * g_pitch*g_code * coeff[4] ;exp_max4 = exp_coeff[4] + 1 + exp_code *----------------------------------------------------------------*/ - index= Find_Opt_gainQ_fx(coeff, exp_coeff, gain_pit, gain_code, gcode0, exp_gcode0, cdbk, size); + index = Find_Opt_gainQ_fx( coeff, exp_coeff, gain_pit, gain_code, gcode0, exp_gcode0, cdbk, size ); gc_mem[2] = *gain_code; move32(); gp_mem[2] = *gain_pit; move16(); } - ELSE IF (EQ_16(i_subfr,3*L_SUBFR)) + ELSE IF( EQ_16( i_subfr, 3 * L_SUBFR ) ) { b = b_4sfr_fx; move16(); n_pred = 8; move16(); - IF(EQ_16(nBits, 7)) + IF( EQ_16( nBits, 7 ) ) { #ifdef IVAS_CODE cdbk = gp_gamma_4sfr_7b_fx; - if (clip_gain == 1) + if ( clip_gain == 1 ) { size -= 25; } #else - //PMT("gp_gamma_4sfr_7b_fx is missing") + // PMT("gp_gamma_4sfr_7b_fx is missing") #endif } ELSE { cdbk = gp_gamma_4sfr_6b_fx; move16(); - if (EQ_16(clip_gain,1)) + if ( EQ_16( clip_gain, 1 ) ) { - size = sub(size,11); + size = sub( size, 11 ); move16(); } } /* calculate predicted gain */ aux[0] = 4096; move16(); - aux[1] = shl(ctype,12); + aux[1] = shl( ctype, 12 ); move16(); /*aux[2] = (float)log10(gc_mem[0]); = log2(gc_mem[0])*log10(2);*/ - exp = norm_l(gc_mem[0]); - frac = Log2_norm_lc(L_shl(gc_mem[0], exp)); - exp = sub(sub(30,exp),16); /*Q_format(gc_mem[0])=16*/ - L_tmp1 = Mpy_32_16(exp, frac, 9864); /* Q16 */ - aux[2] = round_fx(L_shl(L_tmp1, 12)); /* Q12 */ + exp = norm_l( gc_mem[0] ); + frac = Log2_norm_lc( L_shl( gc_mem[0], exp ) ); + exp = sub( sub( 30, exp ), 16 ); /*Q_format(gc_mem[0])=16*/ + L_tmp1 = Mpy_32_16( exp, frac, 9864 ); /* Q16 */ + aux[2] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ /*aux[3] = (float)log10(gc_mem[1]); = log2(gc_mem[1])*log10(2);*/ - exp = norm_l(gc_mem[1]); - frac = Log2_norm_lc(L_shl(gc_mem[1], exp)); - exp = sub(sub(30,exp),16); /*Q_format(gc_mem[1])=16*/ - L_tmp1 = Mpy_32_16(exp, frac, 9864); /* Q16 */ - aux[3] = round_fx(L_shl(L_tmp1, 12)); /* Q12 */ + exp = norm_l( gc_mem[1] ); + frac = Log2_norm_lc( L_shl( gc_mem[1], exp ) ); + exp = sub( sub( 30, exp ), 16 ); /*Q_format(gc_mem[1])=16*/ + L_tmp1 = Mpy_32_16( exp, frac, 9864 ); /* Q16 */ + aux[3] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ /*aux[4] = (float)log10(gc_mem[2]); = log2(gc_mem[2])*log10(2);*/ - exp = norm_l(gc_mem[2]); - frac = Log2_norm_lc(L_shl(gc_mem[2], exp)); - exp = sub(sub(30,exp),16); /*Q_format(gc_mem[2])=16*/ - L_tmp1 = Mpy_32_16(exp, frac, 9864); /* Q16 */ - aux[4] = round_fx(L_shl(L_tmp1, 12)); /* Q12 */ - - aux[5] = shr(gp_mem[0],2); - move16();/*Q12*/ - aux[6] = shr(gp_mem[1],2); - move16();/*Q12*/ - aux[7] = shr(gp_mem[2],2); - move16();/*Q12*/ + exp = norm_l( gc_mem[2] ); + frac = Log2_norm_lc( L_shl( gc_mem[2], exp ) ); + exp = sub( sub( 30, exp ), 16 ); /*Q_format(gc_mem[2])=16*/ + L_tmp1 = Mpy_32_16( exp, frac, 9864 ); /* Q16 */ + aux[4] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ + + aux[5] = shr( gp_mem[0], 2 ); + move16(); /*Q12*/ + aux[6] = shr( gp_mem[1], 2 ); + move16(); /*Q12*/ + aux[7] = shr( gp_mem[2], 2 ); + move16(); /*Q12*/ /*-----------------------------------------------------------------* * gcode0 = pow(10.0, dotp(b, aux, n_pred) * = pow(2, 3.321928*dotp(b, aux, n_pred) *-----------------------------------------------------------------*/ - L_tmp = Dot_product(b, aux, n_pred); /*Q25*/ - L_tmp = Mult_32_16(L_tmp, 27213); /* *3.321928 in Q13 -> Q23 */ - L_tmp = L_shr(L_tmp, 7); /* From Q23 to Q16 */ - frac = L_Extract_lc(L_tmp, &exp_gcode0); /* Extract exponent of gcode0 */ + L_tmp = Dot_product( b, aux, n_pred ); /*Q25*/ + L_tmp = Mult_32_16( L_tmp, 27213 ); /* *3.321928 in Q13 -> Q23 */ + L_tmp = L_shr( L_tmp, 7 ); /* From Q23 to Q16 */ + frac = L_Extract_lc( L_tmp, &exp_gcode0 ); /* Extract exponent of gcode0 */ - gcode0 = extract_l(Pow2(14, frac));/* Put 14 as exponent so that */ + gcode0 = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ - exp_gcode0 = sub(exp_gcode0, 14); + exp_gcode0 = sub( exp_gcode0, 14 ); - index = Find_Opt_gainQ_fx(coeff, exp_coeff, gain_pit, gain_code, gcode0, exp_gcode0, cdbk, size); + index = Find_Opt_gainQ_fx( coeff, exp_coeff, gain_pit, gain_code, gcode0, exp_gcode0, cdbk, size ); } /* *norm_gain_code = *gain_code / *gain_inov; */ - exp = sub(norm_s(*gain_inov),1); - exp = s_max(exp, 0); + exp = sub( norm_s( *gain_inov ), 1 ); + exp = s_max( exp, 0 ); - tmp = div_s(shr(8192,exp),*gain_inov); - *norm_gain_code = L_shr(Mult_32_16(*gain_code, tmp),sub(1,exp)); + tmp = div_s( shr( 8192, exp ), *gain_inov ); + *norm_gain_code = L_shr( Mult_32_16( *gain_code, tmp ), sub( 1, exp ) ); move32(); { push_indice_fx( hBstr, IND_GAIN, index, nBits ); @@ -1720,20 +1730,20 @@ void gain_enc_lbr_fx( void gain_enc_amr_wb_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 *xn, /* i : target vector */ - const Word16 Q_xn, /* i : xn and yy1 format Q0 */ - const Word16 *yy1, /* i : zero-memory filtered adaptive excitation */ - const Word16 *y2, /* i : zero-memory filtered algebraic codebook excitation */ - const Word16 *code, /* i : algebraic excitation */ - const Word32 core_brate, /* i : core bitrate */ - Word16 *gain_pit, /* i/o: pitch gain / Quantized pitch gain */ - Word32 *gain_code, /* o : quantized codebook gain */ - Word16 *gain_inov, /* o : gain of the innovation (used for normalization) */ - Word32 *norm_gain_code, /* o : norm. gain of the codebook excitation */ - Word16 *g_coeff, /* i/o: correlations , -2,, -2 and 2 */ - const Word16 clip_gain, /* i : gain pitch clipping flag (1 = clipping) */ - Word16 *past_qua_en /* i/o: gain quantization memory (4 words) */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 *xn, /* i : target vector */ + const Word16 Q_xn, /* i : xn and yy1 format Q0 */ + const Word16 *yy1, /* i : zero-memory filtered adaptive excitation */ + const Word16 *y2, /* i : zero-memory filtered algebraic codebook excitation */ + const Word16 *code, /* i : algebraic excitation */ + const Word32 core_brate, /* i : core bitrate */ + Word16 *gain_pit, /* i/o: pitch gain / Quantized pitch gain */ + Word32 *gain_code, /* o : quantized codebook gain */ + Word16 *gain_inov, /* o : gain of the innovation (used for normalization) */ + Word32 *norm_gain_code, /* o : norm. gain of the codebook excitation */ + Word16 *g_coeff, /* i/o: correlations , -2,, -2 and 2 */ + const Word16 clip_gain, /* i : gain pitch clipping flag (1 = clipping) */ + Word16 *past_qua_en /* i/o: gain quantization memory (4 words) */ ) { @@ -1752,7 +1762,7 @@ void gain_enc_amr_wb_fx( * Find the initial quantization pitch index * Set gains search range *----------------------------------------------------------------*/ - IF (core_brate>= ACELP_12k65) + IF( core_brate >= ACELP_12k65 ) { t_qua_gain = t_qua_gain7b_fx; move16(); @@ -1763,20 +1773,20 @@ void gain_enc_amr_wb_fx( j = NB_QUA_GAIN7B - RANGE; move16(); - IF (EQ_16(clip_gain, 1)) + IF( EQ_16( clip_gain, 1 ) ) { - j = sub(j, 27); /* limit gain pitch to 1.0 */ + j = sub( j, 27 ); /* limit gain pitch to 1.0 */ } min_ind = 0; move16(); g_pitch = *gain_pit; move16(); - FOR (i = 0; i < j; i++) + FOR( i = 0; i < j; i++ ) { - if (GT_16(g_pitch, *p)) + if ( GT_16( g_pitch, *p ) ) { - min_ind = add(min_ind, 1); + min_ind = add( min_ind, 1 ); } p += 2; } @@ -1791,9 +1801,9 @@ void gain_enc_amr_wb_fx( move16(); size = RANGE; move16(); - if (EQ_16(clip_gain, 1)) + if ( EQ_16( clip_gain, 1 ) ) { - size = sub(size, 16); /* limit gain pitch to 1.0 */ + size = sub( size, 16 ); /* limit gain pitch to 1.0 */ } nBits = 6; } @@ -1813,22 +1823,22 @@ void gain_enc_amr_wb_fx( move16(); exp_coeff[0] = g_coeff[1]; move16(); - coeff[1] = negate(g_coeff[2]); - move16(); /* coeff[1] = -2 xn yy1 */ - exp_coeff[1] = add(g_coeff[3], 1); + coeff[1] = negate( g_coeff[2] ); + move16(); /* coeff[1] = -2 xn yy1 */ + exp_coeff[1] = add( g_coeff[3], 1 ); move16(); /* Compute scalar product */ - coeff[2] = extract_h(Dot_product12(y2, y2, L_SUBFR, &exp)); - exp_coeff[2] = add(sub(exp, 18), shl(Q_xn, 1)); /* -18 (y2 Q9) */ + coeff[2] = extract_h( Dot_product12( y2, y2, L_SUBFR, &exp ) ); + exp_coeff[2] = add( sub( exp, 18 ), shl( Q_xn, 1 ) ); /* -18 (y2 Q9) */ /* Compute scalar product -2* */ - coeff[3] = extract_h(L_negate(Dot_product12(xn, y2, L_SUBFR, &exp))); - exp_coeff[3] = add(sub(exp, 9 - 1), Q_xn); /* -9 (y2 Q9), +1 (2 xn y2) */ + coeff[3] = extract_h( L_negate( Dot_product12( xn, y2, L_SUBFR, &exp ) ) ); + exp_coeff[3] = add( sub( exp, 9 - 1 ), Q_xn ); /* -9 (y2 Q9), +1 (2 xn y2) */ /* Compute scalar product 2* */ - coeff[4] = extract_h(Dot_product12(yy1, y2, L_SUBFR, &exp)); - exp_coeff[4] = add(sub(exp, 9 - 1), Q_xn); /* -9 (y2 Q9), +1 (2 yy1 y2) */ + coeff[4] = extract_h( Dot_product12( yy1, y2, L_SUBFR, &exp ) ); + exp_coeff[4] = add( sub( exp, 9 - 1 ), Q_xn ); /* -9 (y2 Q9), +1 (2 yy1 y2) */ /*----------------------------------------------------------------* * Find energy of code and compute: @@ -1836,45 +1846,45 @@ void gain_enc_amr_wb_fx( * L_tmp = MEAN_ENER - 10log10(energy of code/ L_subfr) * = MEAN_ENER - 3.0103*log2(energy of code/ L_subfr) *----------------------------------------------------------------*/ - L_tmp = Dot_product12(code, code, L_SUBFR, &exp_code); - L_inov = L_add(L_tmp, 0); + L_tmp = Dot_product12( code, code, L_SUBFR, &exp_code ); + L_inov = L_add( L_tmp, 0 ); /* exp_code: -18 (code in Q9), -6 (/L_subfr), -31 (L_tmp Q31->Q0) */ /* output gain_inov*/ - exp_inov = sub(exp_code, 18 + 6); - L_inov = Isqrt_lc(L_inov, &exp_inov); - *gain_inov = extract_h(L_shl(L_inov, sub(exp_inov, 3))); /* gain_inov in Q12 */ + exp_inov = sub( exp_code, 18 + 6 ); + L_inov = Isqrt_lc( L_inov, &exp_inov ); + *gain_inov = extract_h( L_shl( L_inov, sub( exp_inov, 3 ) ) ); /* gain_inov in Q12 */ - exp_code = sub(exp_code, 18 + 6 + 31); - frac = Log2_lc(L_tmp, &exp); - exp = add(exp, exp_code); - L_tmp = Mpy_32_16(exp, frac, -24660); /* x -3.0103(Q13) -> Q14 */ + exp_code = sub( exp_code, 18 + 6 + 31 ); + frac = Log2_lc( L_tmp, &exp ); + exp = add( exp, exp_code ); + L_tmp = Mpy_32_16( exp, frac, -24660 ); /* x -3.0103(Q13) -> Q14 */ - L_tmp = L_mac(L_tmp, MEAN_ENER, 8192); /* + MEAN_ENER in Q14 */ + L_tmp = L_mac( L_tmp, MEAN_ENER, 8192 ); /* + MEAN_ENER in Q14 */ /*----------------------------------------------------------------* * predicted codebook gain *----------------------------------------------------------------*/ - L_tmp = L_shl(L_tmp, 10); /* From Q14 to Q24 */ - L_tmp = L_mac0(L_tmp, pred_gain_fx[0], past_qua_en[0]); /* Q14*Q10 -> Q24 */ - L_tmp = L_mac0(L_tmp, pred_gain_fx[1], past_qua_en[1]); /* Q14*Q10 -> Q24 */ - L_tmp = L_mac0(L_tmp, pred_gain_fx[2], past_qua_en[2]); /* Q14*Q10 -> Q24 */ - L_tmp = L_mac0(L_tmp, pred_gain_fx[3], past_qua_en[3]); /* Q14*Q10 -> Q24 */ + L_tmp = L_shl( L_tmp, 10 ); /* From Q14 to Q24 */ + L_tmp = L_mac0( L_tmp, pred_gain_fx[0], past_qua_en[0] ); /* Q14*Q10 -> Q24 */ + L_tmp = L_mac0( L_tmp, pred_gain_fx[1], past_qua_en[1] ); /* Q14*Q10 -> Q24 */ + L_tmp = L_mac0( L_tmp, pred_gain_fx[2], past_qua_en[2] ); /* Q14*Q10 -> Q24 */ + L_tmp = L_mac0( L_tmp, pred_gain_fx[3], past_qua_en[3] ); /* Q14*Q10 -> Q24 */ - gcode0 = extract_h(L_tmp); /* From Q24 to Q8 */ + gcode0 = extract_h( L_tmp ); /* From Q24 to Q8 */ /*----------------------------------------------------------------* * gcode0 = pow(10.0, gcode0/20) * = pow(2, 3.321928*gcode0/20) * = pow(2, 0.166096*gcode0) *----------------------------------------------------------------*/ - L_tmp = L_mult(gcode0, 5443); /* *0.166096 in Q15 -> Q24 */ - L_tmp = L_shr(L_tmp, 8); /* From Q24 to Q16 */ - L_Extract(L_tmp, &exp_gcode0, &frac); /* Extract exponent of gcode0 */ + L_tmp = L_mult( gcode0, 5443 ); /* *0.166096 in Q15 -> Q24 */ + L_tmp = L_shr( L_tmp, 8 ); /* From Q24 to Q16 */ + L_Extract( L_tmp, &exp_gcode0, &frac ); /* Extract exponent of gcode0 */ - gcode0 = extract_l(Pow2(14, frac)); /* Put 14 as exponent so that */ + gcode0 = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ - exp_gcode0 = sub(exp_gcode0, 14); + exp_gcode0 = sub( exp_gcode0, 14 ); /*----------------------------------------------------------------* * Find the best quantizer @@ -1903,118 +1913,121 @@ void gain_enc_amr_wb_fx( * g_pitch*g_code * coeff[4] ;exp_max4 = exp_coeff[4] + 1 + exp_code *----------------------------------------------------------------*/ - exp_code = add(exp_gcode0, 4); + exp_code = add( exp_gcode0, 4 ); - exp_max[0] = sub(exp_coeff[0], 13); + exp_max[0] = sub( exp_coeff[0], 13 ); move16(); - exp_max[1] = sub(exp_coeff[1], 14); + exp_max[1] = sub( exp_coeff[1], 14 ); move16(); - exp_max[2] = add(exp_coeff[2], - add(15, shl(exp_code, 1))); + exp_max[2] = add( exp_coeff[2], + add( 15, shl( exp_code, 1 ) ) ); move16(); - exp_max[3] = add(exp_coeff[3], exp_code); + exp_max[3] = add( exp_coeff[3], exp_code ); move16(); - exp_max[4] = add(exp_coeff[4], - add(1, exp_code)); + exp_max[4] = add( exp_coeff[4], + add( 1, exp_code ) ); move16(); /* Find maximum exponant */ e_max = exp_max[0]; move16(); - FOR (i = 1; i < 5; i++) + FOR( i = 1; i < 5; i++ ) { - e_max = s_max(exp_max[i], e_max); + e_max = s_max( exp_max[i], e_max ); } /* align coeff[] and save in special 32 bit double precision */ - FOR (i = 0; i < 5; i++) + FOR( i = 0; i < 5; i++ ) { - j = add(sub(e_max, exp_max[i]), 2); /* /4 to avoid overflow */ - L_tmp = L_deposit_h(coeff[i]); - L_tmp = L_shr(L_tmp, j); - L_Extract(L_tmp, &coeff[i], &coeff_lo[i]); - coeff_lo[i] = shr(coeff_lo[i], 3);/* lo >> 3 */move16(); + j = add( sub( e_max, exp_max[i] ), 2 ); /* /4 to avoid overflow */ + L_tmp = L_deposit_h( coeff[i] ); + L_tmp = L_shr( L_tmp, j ); + L_Extract( L_tmp, &coeff[i], &coeff_lo[i] ); + coeff_lo[i] = shr( coeff_lo[i], 3 ); /* lo >> 3 */ + move16(); } /* Codebook search */ - dist_min = L_add(MAX_32, 0); - p = &t_qua_gain[shl(min_ind, 1)]; + dist_min = L_add( MAX_32, 0 ); + p = &t_qua_gain[shl( min_ind, 1 )]; move16(); index = 0; move16(); - FOR (i = 0; i < size; i++) + FOR( i = 0; i < size; i++ ) { g_pitch = *p++; move16(); g_code = *p++; move16(); - g_code = mult_r(g_code, gcode0); - g2_pitch = mult_r(g_pitch, g_pitch); - g_pit_cod = mult_r(g_code, g_pitch); - L_tmp = L_mult(g_code, g_code); - L_Extract(L_tmp, &g2_code, &g2_code_lo); - - L_tmp = L_mult(coeff[2], g2_code_lo); - L_tmp = L_shr(L_tmp, 3); - L_tmp = L_mac(L_tmp, coeff_lo[0], g2_pitch); - L_tmp = L_mac(L_tmp, coeff_lo[1], g_pitch); - L_tmp = L_mac(L_tmp, coeff_lo[2], g2_code); - L_tmp = L_mac(L_tmp, coeff_lo[3], g_code); - L_tmp = L_mac(L_tmp, coeff_lo[4], g_pit_cod); - L_tmp = L_shr(L_tmp, 12); - L_tmp = L_mac(L_tmp, coeff[0], g2_pitch); - L_tmp = L_mac(L_tmp, coeff[1], g_pitch); - L_tmp = L_mac(L_tmp, coeff[2], g2_code); - L_tmp = L_mac(L_tmp, coeff[3], g_code); - L_tmp = L_mac(L_tmp, coeff[4], g_pit_cod); + g_code = mult_r( g_code, gcode0 ); + g2_pitch = mult_r( g_pitch, g_pitch ); + g_pit_cod = mult_r( g_code, g_pitch ); + L_tmp = L_mult( g_code, g_code ); + L_Extract( L_tmp, &g2_code, &g2_code_lo ); + + L_tmp = L_mult( coeff[2], g2_code_lo ); + L_tmp = L_shr( L_tmp, 3 ); + L_tmp = L_mac( L_tmp, coeff_lo[0], g2_pitch ); + L_tmp = L_mac( L_tmp, coeff_lo[1], g_pitch ); + L_tmp = L_mac( L_tmp, coeff_lo[2], g2_code ); + L_tmp = L_mac( L_tmp, coeff_lo[3], g_code ); + L_tmp = L_mac( L_tmp, coeff_lo[4], g_pit_cod ); + L_tmp = L_shr( L_tmp, 12 ); + L_tmp = L_mac( L_tmp, coeff[0], g2_pitch ); + L_tmp = L_mac( L_tmp, coeff[1], g_pitch ); + L_tmp = L_mac( L_tmp, coeff[2], g2_code ); + L_tmp = L_mac( L_tmp, coeff[3], g_code ); + L_tmp = L_mac( L_tmp, coeff[4], g_pit_cod ); #ifdef BASOP_NOGLOB - L_tmp1 = L_sub_o(L_tmp, dist_min, &Overflow); -#else /* BASOP_NOGLOB */ - L_tmp1 = L_sub(L_tmp, dist_min); + L_tmp1 = L_sub_o( L_tmp, dist_min, &Overflow ); +#else /* BASOP_NOGLOB */ + L_tmp1 = L_sub( L_tmp, dist_min ); #endif /* BASOP_NOGLOB */ /* splitting the if cost half the complexity of using IF macro */ - if (L_tmp1 < 0) + if ( L_tmp1 < 0 ) { - dist_min = L_add(L_tmp, 0); + dist_min = L_add( L_tmp, 0 ); } - if (L_tmp1 < 0) + if ( L_tmp1 < 0 ) { index = i; move16(); } - } /* Read the quantized gains */ - index = add(index, min_ind); + index = add( index, min_ind ); - p = &t_qua_gain[add(index, index)]; + p = &t_qua_gain[add( index, index )]; + move16(); + *gain_pit = *p++; /* selected pitch gain in Q14 */ + move16(); + g_code = *p++; /* selected code gain in Q11 */ move16(); - *gain_pit = *p++; /* selected pitch gain in Q14 */ move16(); - g_code = *p++; /* selected code gain in Q11 */ move16(); - L_tmp = L_mult(g_code, gcode0); /* Q11*Q0 -> Q12 */ + L_tmp = L_mult( g_code, gcode0 ); /* Q11*Q0 -> Q12 */ #ifdef BASOP_NOGLOB - L_tmp = L_shl_o(L_tmp, add(exp_gcode0, 4), &Overflow); /* Q12 -> Q16 */ -#else /* BASOP_NOGLOB */ - L_tmp = L_shl(L_tmp, add(exp_gcode0, 4)); /* Q12 -> Q16 */ + L_tmp = L_shl_o( L_tmp, add( exp_gcode0, 4 ), &Overflow ); /* Q12 -> Q16 */ +#else /* BASOP_NOGLOB */ + L_tmp = L_shl( L_tmp, add( exp_gcode0, 4 ) ); /* Q12 -> Q16 */ #endif - *gain_code = L_tmp; /* gain of code in Q16 */ move16(); + *gain_code = L_tmp; /* gain of code in Q16 */ + move16(); /*---------------------------------------------------* * qua_ener = 20*log10(g_code) * = 6.0206*log2(g_code) * = 6.0206*(log2(g_codeQ11) - 11) *---------------------------------------------------*/ - L_tmp = L_deposit_l(g_code); - frac = Log2_lc(L_tmp, &exp); - exp = sub(exp, 11); - L_tmp = Mpy_32_16(exp, frac, 24660); /* x 6.0206 in Q12 */ + L_tmp = L_deposit_l( g_code ); + frac = Log2_lc( L_tmp, &exp ); + exp = sub( exp, 11 ); + L_tmp = Mpy_32_16( exp, frac, 24660 ); /* x 6.0206 in Q12 */ - qua_ener = extract_l(L_shr(L_tmp, 3)); /* result in Q10 */ + qua_ener = extract_l( L_shr( L_tmp, 3 ) ); /* result in Q10 */ /*----------------------------------------------------------------* * update table of past quantized energies @@ -2030,14 +2043,14 @@ void gain_enc_amr_wb_fx( move16(); - exp = sub(norm_s(*gain_inov),1); - exp = s_max(exp, 0); + exp = sub( norm_s( *gain_inov ), 1 ); + exp = s_max( exp, 0 ); - tmp = div_s(shr(8192,exp),*gain_inov); - *norm_gain_code = L_shr(Mult_32_16(*gain_code, tmp),sub(1,exp)); + tmp = div_s( shr( 8192, exp ), *gain_inov ); + *norm_gain_code = L_shr( Mult_32_16( *gain_code, tmp ), sub( 1, exp ) ); move32(); - push_indice_fx(hBstr, IND_GAIN, index, nBits ); + push_indice_fx( hBstr, IND_GAIN, index, nBits ); return; } diff --git a/lib_enc/gaus_enc_fx.c b/lib_enc/gaus_enc_fx.c index e004d110f..56ac45f26 100644 --- a/lib_enc/gaus_enc_fx.c +++ b/lib_enc/gaus_enc_fx.c @@ -2,24 +2,24 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "rom_com.h" /* Static table prototypes */ -#include "rom_enc.h" /* Static table prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com_fx.h" /* Static table prototypes */ +#include "rom_com.h" /* Static table prototypes */ +#include "rom_enc.h" /* Static table prototypes */ //#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ //#include "basop_mpy.h" /*-------------------------------------------------------------------* * Local constants *-------------------------------------------------------------------*/ -#define NMAX 8 /* Control of the routine's complexity */ +#define NMAX 8 /* Control of the routine's complexity */ /* #define FAC_DELTA 16.0f */ -#define SFAC_DELTA 11 +#define SFAC_DELTA 11 /*-------------------------------------------------------------------* * Local functions @@ -27,8 +27,7 @@ static Word16 cod_2pos_fx( const Word16 ind1, const Word16 ind2, const Word16 sign1, const Word16 sign2, const Word16 n ); -static void gauss2v_fx(BSTR_ENC_HANDLE hBstr, const Word16 h[], const Word16 xn[], const Word16 dn[], Word16 code[], - Word16 y1[], Word32 *gain, const Word16 lg, const Word16 shift, const Word16 Q_new, const Word16 nb_bits ); +static void gauss2v_fx( BSTR_ENC_HANDLE hBstr, const Word16 h[], const Word16 xn[], const Word16 dn[], Word16 code[], Word16 y1[], Word32 *gain, const Word16 lg, const Word16 shift, const Word16 Q_new, const Word16 nb_bits ); /*-------------------------------------------------------------------* * Gaus_encode @@ -40,30 +39,30 @@ static void gauss2v_fx(BSTR_ENC_HANDLE hBstr, const Word16 h[], const Word16 xn[ * - Updates *-------------------------------------------------------------------*/ Word16 gaus_encode_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 *h1, /* i : weighted filter input response */ - const Word16 *xn, /* i : target vector */ - Word16 *exc, /* o : pointer to excitation signal frame */ - Word16 *mem_w0, /* o : weighting filter denominator memory */ - Word16 *clip_gain, /* o : memory of gain of pitch clipping algorithm */ - Word16 *tilt_code, /* o : synthesis excitation spectrum tilt */ - Word16 *code, /* o : algebraic excitation Q9 */ - Word32 *gain_code, /* o : Code gain. Q16 */ - Word16 *y2, /* o : zero-memory filtered adaptive excitation Q9 */ - Word16 *gain_inov, /* o : innovation gain Q12 */ - Word16 *voice_fac, /* o : voicing factor Q15 */ - Word16 *gain_pit, /* o : adaptive excitation gain Q14 */ - const Word16 Q_new, /* i : scaling factor */ - const Word16 shift, /* i : scaling factor */ - Word32 *norm_gain_code /* o : normalized innovative cb. gain Q16 */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word16 i_subfr, /* i : subframe index */ + const Word16 *h1, /* i : weighted filter input response */ + const Word16 *xn, /* i : target vector */ + Word16 *exc, /* o : pointer to excitation signal frame */ + Word16 *mem_w0, /* o : weighting filter denominator memory */ + Word16 *clip_gain, /* o : memory of gain of pitch clipping algorithm */ + Word16 *tilt_code, /* o : synthesis excitation spectrum tilt */ + Word16 *code, /* o : algebraic excitation Q9 */ + Word32 *gain_code, /* o : Code gain. Q16 */ + Word16 *y2, /* o : zero-memory filtered adaptive excitation Q9 */ + Word16 *gain_inov, /* o : innovation gain Q12 */ + Word16 *voice_fac, /* o : voicing factor Q15 */ + Word16 *gain_pit, /* o : adaptive excitation gain Q14 */ + const Word16 Q_new, /* i : scaling factor */ + const Word16 shift, /* i : scaling factor */ + Word32 *norm_gain_code /* o : normalized innovative cb. gain Q16 */ ) { Word16 nb_bits, idx; - Word16 i=0; + Word16 i = 0; Word32 Ltmp; - Word16 dn[L_SUBFR], exp_code, gcode; /* Correlation between xn and h1 */ - Word16 exp,tmp,tmp_idx; + Word16 dn[L_SUBFR], exp_code, gcode; /* Correlation between xn and h1 */ + Word16 exp, tmp, tmp_idx; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif @@ -73,72 +72,74 @@ Word16 gaus_encode_fx( *----------------------------------------------------------------*/ /* Correlation between target xn2[] and impulse response h1[] */ - corr_xh_fx(xn, dn, h1); + corr_xh_fx( xn, dn, h1 ); - tmp_idx = shr(i_subfr, 6); - nb_bits = st_fx->acelp_cfg.fixed_cdk_index[tmp_idx]; move16(); + tmp_idx = shr( i_subfr, 6 ); + nb_bits = st_fx->acelp_cfg.fixed_cdk_index[tmp_idx]; + move16(); - gauss2v_fx(st_fx->hBstr, h1, xn, dn, code, y2, gain_code, L_SUBFR, shift, Q_new, shr(nb_bits,1)); + gauss2v_fx( st_fx->hBstr, h1, xn, dn, code, y2, gain_code, L_SUBFR, shift, Q_new, shr( nb_bits, 1 ) ); /*----------------------------------------------------------------* - * Encode gaussian gain - *----------------------------------------------------------------*/ + * Encode gaussian gain + *----------------------------------------------------------------*/ /* codeword energy computation */ - Ltmp = Dot_product12(code, code, L_SUBFR, &exp_code); + Ltmp = Dot_product12( code, code, L_SUBFR, &exp_code ); - exp_code = sub(exp_code, 18 + 6); /* exp: -18 (code in Q9), -6 (L_subfr = 64) */ - Ltmp = Isqrt_lc(Ltmp, &exp_code); - *gain_inov = extract_h(L_shl(Ltmp, sub(exp_code, 3))); /* g_code_inov in Q12 */ + exp_code = sub( exp_code, 18 + 6 ); /* exp: -18 (code in Q9), -6 (L_subfr = 64) */ + Ltmp = Isqrt_lc( Ltmp, &exp_code ); + *gain_inov = extract_h( L_shl( Ltmp, sub( exp_code, 3 ) ) ); /* g_code_inov in Q12 */ - nb_bits = st_fx->acelp_cfg.gains_mode[tmp_idx]; move16(); + nb_bits = st_fx->acelp_cfg.gains_mode[tmp_idx]; + move16(); /* low bound = -30; stepSize = 1.71875; inv_stepSize = 0.5818181 */ - idx = gain_enc_gaus_fx(gain_code, nb_bits, -7680, 28160, 19065); + idx = gain_enc_gaus_fx( gain_code, nb_bits, -7680, 28160, 19065 ); push_indice_fx( st_fx->hBstr, IND_GAIN, idx, nb_bits ); /*----------------------------------------------------------------* * Total excitation for Unvoiced coders *----------------------------------------------------------------*/ #ifdef BASOP_NOGLOB - gcode = round_fx_o(L_shl_o(*gain_code, Q_new, &Overflow), &Overflow); /* scaled gain_code with Qnew */ -#else /* BASOP_NOGLOB */ - gcode = round_fx(L_shl(*gain_code, Q_new)); /* scaled gain_code with Qnew */ -#endif /* BASOP_NOGLOB */ - FOR (i = 0; i < L_SUBFR; i++) + gcode = round_fx_o( L_shl_o( *gain_code, Q_new, &Overflow ), &Overflow ); /* scaled gain_code with Qnew */ +#else /* BASOP_NOGLOB */ + gcode = round_fx( L_shl( *gain_code, Q_new ) ); /* scaled gain_code with Qnew */ +#endif /* BASOP_NOGLOB */ + FOR( i = 0; i < L_SUBFR; i++ ) { - exc[i+i_subfr] = round_fx(L_shl(L_mult(gcode, code[i]), 15-9)); + exc[i + i_subfr] = round_fx( L_shl( L_mult( gcode, code[i] ), 15 - 9 ) ); } /*----------------------------------------------------------------* * Updates: last value of new target is stored in mem_w0 *----------------------------------------------------------------*/ - Ltmp = L_mult(gcode, y2[L_SUBFR - 1]); - Ltmp = L_shl(Ltmp, add(5, shift)); - Ltmp = L_negate(Ltmp); - Ltmp = L_mac(Ltmp, xn[L_SUBFR - 1], 16384); + Ltmp = L_mult( gcode, y2[L_SUBFR - 1] ); + Ltmp = L_shl( Ltmp, add( 5, shift ) ); + Ltmp = L_negate( Ltmp ); + Ltmp = L_mac( Ltmp, xn[L_SUBFR - 1], 16384 ); #ifdef BASOP_NOGLOB Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) ); *mem_w0 = round_fx_sat( Ltmp ); #else - Ltmp = L_shl(Ltmp, sub(1, shift)); - *mem_w0 = round_fx(Ltmp); + Ltmp = L_shl( Ltmp, sub( 1, shift ) ); + *mem_w0 = round_fx( Ltmp ); #endif - init_gp_clip_fx(clip_gain); /* reset pitch clipping parameters */ + init_gp_clip_fx( clip_gain ); /* reset pitch clipping parameters */ *gain_pit = 0; *tilt_code = 0; move16(); /* purely unvoiced */ *voice_fac = -32768; move16(); /* purely unvoiced */ - exp = sub(norm_s(*gain_inov),1); - exp = s_max(exp, 0); + exp = sub( norm_s( *gain_inov ), 1 ); + exp = s_max( exp, 0 ); - tmp = div_s(shr(8192,exp),*gain_inov); - *norm_gain_code = L_shr(Mult_32_16(*gain_code, tmp),sub(1,exp)); + tmp = div_s( shr( 8192, exp ), *gain_inov ); + *norm_gain_code = L_shr( Mult_32_16( *gain_code, tmp ), sub( 1, exp ) ); move16(); - return (L_SUBFR<<6); + return ( L_SUBFR << 6 ); } /*-------------------------------------------------------------------* @@ -150,32 +151,32 @@ Word16 gaus_encode_fx( * One Gaussian vector of 192 values vectors delayed by 2 *-------------------------------------------------------------------*/ void gauss2v_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder state structure */ - const Word16 h[], /* i : weighted LP filter impulse response Q15 */ - const Word16 xn[], /* i : target signal Q12 */ - const Word16 dn[], /* i : backward filtered target Q12 */ - Word16 code[], /* o : gaussian excitation Q9 */ - Word16 y1[], /* o : zero-memory filtered gauss. excitation Q8 */ - Word32 *gain, /* o : excitation gain. 32-bit number in Q16 */ - const Word16 lg, /* i : subframe size Q0 */ - const Word16 shift, /* i : Scaling factor Q0 */ - const Word16 Q_new, /* i : Scaling factor Q0 */ - const Word16 nb_bits /* i : nb ob bits per track (max 6) */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder state structure */ + const Word16 h[], /* i : weighted LP filter impulse response Q15 */ + const Word16 xn[], /* i : target signal Q12 */ + const Word16 dn[], /* i : backward filtered target Q12 */ + Word16 code[], /* o : gaussian excitation Q9 */ + Word16 y1[], /* o : zero-memory filtered gauss. excitation Q8 */ + Word32 *gain, /* o : excitation gain. 32-bit number in Q16 */ + const Word16 lg, /* i : subframe size Q0 */ + const Word16 shift, /* i : Scaling factor Q0 */ + const Word16 Q_new, /* i : Scaling factor Q0 */ + const Word16 nb_bits /* i : nb ob bits per track (max 6) */ ) { Word16 i, j, ind1, ind2; Word16 nvec, step; Word32 cor, cora, dotprod; Word16 enerw; - Word32 eneri,cor2; - Word32 enerw32,cor2w32; + Word32 eneri, cor2; + Word32 enerw32, cor2w32; Word16 *cpt1; Word16 *pt1, *pt2; - Word32 max_val[NMAX+1]; - Word16 *pos[NMAX+1]; - Word32 sign[NMAX+1]; - Word32 ener[NMAX+1], corr[NMAX+1], ener1; - Word16 dico2[L_SUBFR*NMAX]; + Word32 max_val[NMAX + 1]; + Word16 *pos[NMAX + 1]; + Word32 sign[NMAX + 1]; + Word32 ener[NMAX + 1], corr[NMAX + 1], ener1; + Word16 dico2[L_SUBFR * NMAX]; Word16 exp_num; Word16 exp_den; Word16 Num; @@ -187,19 +188,19 @@ void gauss2v_fx( Word16 div_result; Word32 ener_sqrt; Word32 Portion; - Word16 sign1,sign2; - Word16 enerw_norm,enerw_mantissa; - Word16 cor2w_norm,cor2w_mantissa; - Word16 eneri_norm,eneri_mantissa; - Word16 cor2_norm ,cor2_mantissa; + Word16 sign1, sign2; + Word16 enerw_norm, enerw_mantissa; + Word16 cor2w_norm, cor2w_mantissa; + Word16 eneri_norm, eneri_mantissa; + Word16 cor2_norm, cor2_mantissa; Word16 difference_norm; Word32 cor32; /* 32-bit intermediate value*/ Word16 hi1, lo1; Word16 update_best; Word16 idx; - Word32 Lc0,Lc1, Lnum, Lden; - Word16 gxx, gcc,index_delta, delta, m_sign, inv_delta; - Word16 hg[190],Gaus_dico2[190]; + Word32 Lc0, Lc1, Lnum, Lden; + Word16 gxx, gcc, index_delta, delta, m_sign, inv_delta; + Word16 hg[190], Gaus_dico2[190]; Word16 shiftP3; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; @@ -210,105 +211,105 @@ void gauss2v_fx( *----------------------------------------------------------------*/ /* Compute spectral tilt of target */ - Lc0 = L_mult(xn[1], xn[1]); - Lc1 = L_mult(xn[1], xn[0]); - FOR (i=2; i 0) /* Adapt spectral tilt of initial codebook */ + IF( delta > 0 ) /* Adapt spectral tilt of initial codebook */ { /* Computation of 1 / (1+fdelta*fdelta) */ - inv_delta = inv_delta_tab[sub(index_delta, 1)]; - move16(); /* Q15 */ + inv_delta = inv_delta_tab[sub( index_delta, 1 )]; + move16(); /* Q15 */ /* fgaus_dico2[0] = gaus_dico[0] */ Gaus_dico2[0] = gaus_dico_fx[0]; - FOR (i=1; i<190; i++) + FOR( i = 1; i < 190; i++ ) { /* fgaus_dico2[i] = (gaus_dico[i] - fdelta*gaus_dico[i-1]) / (1 + fdelta*fdelta) */ - Lnum = L_msu(L_deposit_h(gaus_dico_fx[i]), delta, gaus_dico_fx[i-1]); - Gaus_dico2[i] = round_fx(Mpy_32_16_1(Lnum, inv_delta)); + Lnum = L_msu( L_deposit_h( gaus_dico_fx[i] ), delta, gaus_dico_fx[i - 1] ); + Gaus_dico2[i] = round_fx( Mpy_32_16_1( Lnum, inv_delta ) ); } } ELSE { - FOR (i=0; i<190; i++) + FOR( i = 0; i < 190; i++ ) { /* fgaus_dico2[i] = gaus_dico[i] */ Gaus_dico2[i] = gaus_dico_fx[i]; @@ -325,53 +326,53 @@ void gauss2v_fx( ind2 = 0; move16(); - nvec = shl(1, nb_bits); - step = shr(0x80, nb_bits); + nvec = shl( 1, nb_bits ); + step = shr( 0x80, nb_bits ); /*----------------------------------------------------------------* * dot product between dn and gaussian codevectors, * keep NMAX best vectors *----------------------------------------------------------------*/ - set32_fx(max_val, 0, NMAX+1); - set32_fx(sign, 0, NMAX+1); + set32_fx( max_val, 0, NMAX + 1 ); + set32_fx( sign, 0, NMAX + 1 ); - FOR (i = 0; i < NMAX+1; i++) + FOR( i = 0; i < NMAX + 1; i++ ) { - pos[i] = (Word16 *)Gaus_dico2; + pos[i] = (Word16 *) Gaus_dico2; } cpt1 = Gaus_dico2; move16(); - FOR (i=0; i< nvec; i++) + FOR( i = 0; i < nvec; i++ ) { /* Dot product without normalization, because values are compared with each other afterwards. */ - cor = Dot_product(cpt1, dn, lg); /* Q12 * Q12 * length of 64 + 1 left shift ==> Q31*/ - cora = L_abs(cor); - j = NMAX-1; + cor = Dot_product( cpt1, dn, lg ); /* Q12 * Q12 * length of 64 + 1 left shift ==> Q31*/ + cora = L_abs( cor ); + j = NMAX - 1; move16(); DO { - IF (GE_32(cora, max_val[j])) + IF( GE_32( cora, max_val[j] ) ) { - max_val[j+1] = max_val[j]; - move32(); /*Q31*/ - pos[j+1] = pos[j]; - move16(); /*Pointer*/ - sign[j+1] = sign[j]; - move32(); /*Q31*/ - max_val[j] = cora; - move32(); /*Q31*/ - pos[j] = cpt1; - move16(); /*Pointer*/ - sign[j] = cor; - move32(); /*Q31*/ + max_val[j + 1] = max_val[j]; + move32(); /*Q31*/ + pos[j + 1] = pos[j]; + move16(); /*Pointer*/ + sign[j + 1] = sign[j]; + move32(); /*Q31*/ + max_val[j] = cora; + move32(); /*Q31*/ + pos[j] = cpt1; + move16(); /*Pointer*/ + sign[j] = cor; + move32(); /*Q31*/ } j--; } - WHILE (j >= 0); + WHILE( j >= 0 ); cpt1 += step; } @@ -383,24 +384,24 @@ void gauss2v_fx( pt1 = dico2; move16(); - FOR (i=0; i Q31 */ - corr[i] = Dot_product(pt1,xn,lg); /* must be equal to sign[i] !! */ - move32(); /* pt1 points into dico2, in Q12. xn is in Q12 */ + ener[i] = Dot_product( pt1, pt1, lg ); /* pt1 points to filtered vector in dico2, in Q12 */ + move32(); /* Result is for Q12 * Q12 with length of 64 (6 bits) + 1 left shift => Q31 */ + corr[i] = Dot_product( pt1, xn, lg ); /* must be equal to sign[i] !! */ + move32(); /* pt1 points into dico2, in Q12. xn is in Q12 */ /* Result is for Q12 * Q12 with length of 64 (6 bits) + 1 left shift => Q31 */ pt1 += L_SUBFR; } @@ -413,50 +414,50 @@ void gauss2v_fx( move16(); /* Initial values for search algorithm */ - enerw32 = L_deposit_h(0x80); - cor2w32 = L_deposit_l(-2); - enerw_norm = norm_l(enerw32); - cor2w_norm = norm_l(cor2w32); - cor2w_mantissa = round_fx(L_shl(cor2w32,cor2w_norm)); - enerw_mantissa = round_fx(L_shl(enerw32,enerw_norm)); - - FOR (i=0; i< NMAX; i++) + enerw32 = L_deposit_h( 0x80 ); + cor2w32 = L_deposit_l( -2 ); + enerw_norm = norm_l( enerw32 ); + cor2w_norm = norm_l( cor2w32 ); + cor2w_mantissa = round_fx( L_shl( cor2w32, cor2w_norm ) ); + enerw_mantissa = round_fx( L_shl( enerw32, enerw_norm ) ); + + FOR( i = 0; i < NMAX; i++ ) { pt2 = pt1; move16(); - FOR (j=i; j Q31 */ + dotprod = Dot_product( pt1, pt2, lg ); /* Q12 * Q12 * length of 64 + 1 left shift ==> Q31 */ /* eneri = round_fx(ener[i]) + round_fx(ener[j]) + 2*round_fx(dotprod) */ /* Use ScalingShift to stay aligned with ener[] */ - eneri=L_shl(dotprod, 1); /* One left shift added for factor of 2 */ - eneri=L_add(ener[i], eneri); - eneri=L_add(ener[j], eneri); /* Q31 */ + eneri = L_shl( dotprod, 1 ); /* One left shift added for factor of 2 */ + eneri = L_add( ener[i], eneri ); + eneri = L_add( ener[j], eneri ); /* Q31 */ - lo1 = L_Extract_lc(cor32, &hi1); - cor2 = Sad_32(0, hi1, lo1); /* Square + Add */ + lo1 = L_Extract_lc( cor32, &hi1 ); + cor2 = Sad_32( 0, hi1, lo1 ); /* Square + Add */ - cor2_norm = norm_l(cor2); - eneri_norm = norm_l(eneri); + cor2_norm = norm_l( cor2 ); + eneri_norm = norm_l( eneri ); #ifdef BASOP_NOGLOB - cor2_mantissa = round_fx_o(L_shl_o(cor2, cor2_norm, &Overflow), &Overflow); - eneri_mantissa = round_fx_o(L_shl_o(eneri, eneri_norm, &Overflow), &Overflow); + cor2_mantissa = round_fx_o( L_shl_o( cor2, cor2_norm, &Overflow ), &Overflow ); + eneri_mantissa = round_fx_o( L_shl_o( eneri, eneri_norm, &Overflow ), &Overflow ); #else - cor2_mantissa = round_fx(L_shl(cor2, cor2_norm)); - eneri_mantissa = round_fx(L_shl(eneri, eneri_norm)); + cor2_mantissa = round_fx( L_shl( cor2, cor2_norm ) ); + eneri_mantissa = round_fx( L_shl( eneri, eneri_norm ) ); #endif - difference_norm = sub(add(cor2_norm, enerw_norm), add(cor2w_norm, eneri_norm)); + difference_norm = sub( add( cor2_norm, enerw_norm ), add( cor2w_norm, eneri_norm ) ); update_best = 0; move16(); - IF (difference_norm > 0) + IF( difference_norm > 0 ) { - if (GT_32(L_shr(L_mult(cor2_mantissa, enerw_mantissa), difference_norm), - L_mult(cor2w_mantissa, eneri_mantissa))) + if ( GT_32( L_shr( L_mult( cor2_mantissa, enerw_mantissa ), difference_norm ), + L_mult( cor2w_mantissa, eneri_mantissa ) ) ) { update_best = 1; move16(); @@ -464,13 +465,13 @@ void gauss2v_fx( } ELSE { - if (L_msu(L_shl(L_mult(cor2w_mantissa, eneri_mantissa), difference_norm), cor2_mantissa, enerw_mantissa) < 0) + if ( L_msu( L_shl( L_mult( cor2w_mantissa, eneri_mantissa ), difference_norm ), cor2_mantissa, enerw_mantissa ) < 0 ) { - update_best=1; + update_best = 1; move16(); } } - IF (update_best != 0) + IF( update_best != 0 ) { cor2w_mantissa = cor2_mantissa; move16(); @@ -490,40 +491,40 @@ void gauss2v_fx( pt1 += L_SUBFR; } - enerw = round_fx(L_shr(L_deposit_h(enerw_mantissa), enerw_norm)); + enerw = round_fx( L_shr( L_deposit_h( enerw_mantissa ), enerw_norm ) ); /*----------------------------------------------------------------* * Compute zero-memory filtered gauss. excitation y *----------------------------------------------------------------*/ - pt1 = dico2 + ind1*L_SUBFR; + pt1 = dico2 + ind1 * L_SUBFR; move16(); /*Pointer arithmetic*/ - pt2 = dico2 + ind2*L_SUBFR; + pt2 = dico2 + ind2 * L_SUBFR; move16(); - shiftP3 = add(shift, 3); - FOR (i=0; i= 0) + if ( sign[ind1] >= 0 ) { sign1 = 32767; move16(); } - sign2 = (-32768); + sign2 = ( -32768 ); move16(); - if (sign[ind2] >= 0) + if ( sign[ind2] >= 0 ) { sign2 = 32767; move16(); @@ -534,32 +535,32 @@ void gauss2v_fx( *----------------------------------------------------------------*/ pt1 = pos[ind1]; - move16(); /* Points to gaussian vector (gaus_dico_fx) in Q12 */ + move16(); /* Points to gaussian vector (gaus_dico_fx) in Q12 */ pt2 = pos[ind2]; - move16(); /* Points to gaussian vector (gaus_dico_fx) in Q12 */ + move16(); /* Points to gaussian vector (gaus_dico_fx) in Q12 */ /* sign[ind1] and sign[ind2] */ - FOR (i=0; i Q31 */ + ener1 = Dot_product( xn, xn, lg ); /* Q12 * Q12 * length of 64 + 1 left shift ==> Q31 */ - exp_num = sub(norm_s(enerw), 1); - exp_den = norm_l(ener1); - Num = shl(enerw, exp_num); + exp_num = sub( norm_s( enerw ), 1 ); + exp_den = norm_l( ener1 ); + Num = shl( enerw, exp_num ); #ifdef BASOP_NOGLOB Den = round_fx_sat( L_shl_sat( ener1, exp_den ) ); #else Den = round_fx( L_shl( ener1, exp_den ) ); #endif - GainPortion2 = L_deposit_l(0); /* Unexpected division by zero. Eliminate this gain contribution */ - IF (Den != 0) /* Protection against division by zero */ + GainPortion2 = L_deposit_l( 0 ); /* Unexpected division by zero. Eliminate this gain contribution */ + IF( Den != 0 ) /* Protection against division by zero */ { - div_result = div_s(Num, Den); /* Q15 */ + div_result = div_s( Num, Den ); /* Q15 */ /* Re-scale to compensate for normalization*/ #ifdef BASOP_NOGLOB GainPortion2 = L_shr_sat( L_deposit_l( div_result ), sub( exp_num, exp_den ) ); #else - GainPortion2 = L_shr(L_deposit_l(div_result), sub(exp_num, exp_den)); + GainPortion2 = L_shr( L_deposit_l( div_result ), sub( exp_num, exp_den ) ); #endif } #ifdef BASOP_NOGLOB ener_sqrt = Isqrt( L_shl_sat( GainPortion2, 1 ) ); /* Make value a Q16 prior to division (align on power of 4) */ #else - ener_sqrt = Isqrt(L_shl(GainPortion2, 1)); /* Make value a Q16 prior to division (align on power of 4) */ + ener_sqrt = Isqrt( L_shl( GainPortion2, 1 ) ); /* Make value a Q16 prior to division (align on power of 4) */ #endif - ener_sqrt = L_shr(ener_sqrt, 8); /* Left-shift Q23 result to make a Q15 result */ + ener_sqrt = L_shr( ener_sqrt, 8 ); /* Left-shift Q23 result to make a Q15 result */ - Portion = Mult_32_16(GainPortion1, 19661); /* Performs GainPortion1*.6 */ - Portion = Madd_32_16(Portion, ener_sqrt, 13107); /* Performs ener_sqrt*.4 */ + Portion = Mult_32_16( GainPortion1, 19661 ); /* Performs GainPortion1*.6 */ + Portion = Madd_32_16( Portion, ener_sqrt, 13107 ); /* Performs ener_sqrt*.4 */ /* Gain must be output in a 32-bit variable as a Q16 */ /* Compensate for Q_new */ #ifdef BASOP_NOGLOB - *gain = L_shl_o(Portion, sub(13, Q_new), &Overflow); + *gain = L_shl_o( Portion, sub( 13, Q_new ), &Overflow ); #else - *gain = L_shl(Portion, sub(13, Q_new)); + *gain = L_shl( Portion, sub( 13, Q_new ) ); #endif move32(); @@ -642,34 +643,34 @@ void gauss2v_fx( /*---------------------------------------------------------------------* * Put selected codevector positions and signs into quantization index *---------------------------------------------------------------------*/ -static Word16 cod_2pos_fx(/* o : codebook quantization index */ - const Word16 ind1, /* i : index of 1st gaussian vector */ - const Word16 ind2, /* i : index of 2nd gaussian vector */ - const Word16 sign1, /* i : sign of 1st gaussian vector */ - const Word16 sign2, /* i : sign of 2nd gaussian vector */ - const Word16 n /* i : nb. of codebook vectors */ +static Word16 cod_2pos_fx( /* o : codebook quantization index */ + const Word16 ind1, /* i : index of 1st gaussian vector */ + const Word16 ind2, /* i : index of 2nd gaussian vector */ + const Word16 sign1, /* i : sign of 1st gaussian vector */ + const Word16 sign2, /* i : sign of 2nd gaussian vector */ + const Word16 n /* i : nb. of codebook vectors */ ) { Word16 i1, i2, index, s1, s2; s1 = 1; move16(); - if (sign1 > 0) + if ( sign1 > 0 ) { s1 = 0; move16(); } s2 = 1; move16(); - if (sign2 > 0) + if ( sign2 > 0 ) { s2 = 0; move16(); } - IF (EQ_16(s1, s2)) + IF( EQ_16( s1, s2 ) ) { - IF (LE_16(ind1, ind2)) + IF( LE_16( ind1, ind2 ) ) { i1 = ind1; move16(); @@ -686,7 +687,7 @@ static Word16 cod_2pos_fx(/* o : codebook quantization index */ } ELSE { - IF (GT_16(ind1, ind2)) + IF( GT_16( ind1, ind2 ) ) { i1 = ind1; move16(); @@ -704,9 +705,9 @@ static Word16 cod_2pos_fx(/* o : codebook quantization index */ } } - index = extract_l(L_mult(i1, n)); - index = add(index, shl(i2, 1)); - index = add(index, s1); + index = extract_l( L_mult( i1, n ) ); + index = add( index, shl( i2, 1 ) ); + index = add( index, s1 ); return index; } diff --git a/lib_enc/gp_clip_fx.c b/lib_enc/gp_clip_fx.c index 7bffed0bf..1a1f1debf 100644 --- a/lib_enc/gp_clip_fx.c +++ b/lib_enc/gp_clip_fx.c @@ -31,60 +31,61 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" - /*-------------------------------------------------------------------* - * Local constants - *-------------------------------------------------------------------*/ +/*-------------------------------------------------------------------* + * Local constants + *-------------------------------------------------------------------*/ -#define DIST_ISF_MAX_IO 384 /* 150 Hz (6400Hz=16384) */ -#define DIST_ISF_MAX 307 /* 120 Hz (6400Hz=16384) */ -#define DIST_ISF_THRES 154 /* 60 (6400Hz=16384) */ -#define GAIN_PIT_THRES 14746 /* 0.9 in Q14 */ -#define GAIN_PIT_MIN 9830 /* 0.6 in Q14 */ +#define DIST_ISF_MAX_IO 384 /* 150 Hz (6400Hz=16384) */ +#define DIST_ISF_MAX 307 /* 120 Hz (6400Hz=16384) */ +#define DIST_ISF_THRES 154 /* 60 (6400Hz=16384) */ +#define GAIN_PIT_THRES 14746 /* 0.9 in Q14 */ +#define GAIN_PIT_MIN 9830 /* 0.6 in Q14 */ -#define ALPHA1 32113 /* 0.98f */ -#define ALPHA4 32440 /* 0.99f */ -#define WINDOW_SIZE 50 -#define THRESH_TYPE 13926 /* 0.85f in Q14 */ -#define THRESH_VOICING 14090 /* 0.86f in Q14 */ +#define ALPHA1 32113 /* 0.98f */ +#define ALPHA4 32440 /* 0.99f */ +#define WINDOW_SIZE 50 +#define THRESH_TYPE 13926 /* 0.85f in Q14 */ +#define THRESH_VOICING 14090 /* 0.86f in Q14 */ -#define GPCLIP_E (6+2) +#define GPCLIP_E ( 6 + 2 ) -#define ALPHA1_M1 21474836l/*1.0f-0.98 Q30*/ -#define ALPHA4_M1 10737408l/*1.0f-0.99f Q30*/ +#define ALPHA1_M1 21474836l /*1.0f-0.98 Q30*/ +#define ALPHA4_M1 10737408l /*1.0f-0.99f Q30*/ - /*-------------------------------------------------------------------* - * init_gp_clip - * - * Pitch Gain clipping initializations - *-------------------------------------------------------------------*/ +/*-------------------------------------------------------------------* + * init_gp_clip + * + * Pitch Gain clipping initializations + *-------------------------------------------------------------------*/ void init_gp_clip_fx( - Word16 mem[] /* o : memory of gain of pitch clipping algorithm */ + Word16 mem[] /* o : memory of gain of pitch clipping algorithm */ ) { - mem[0] = DIST_ISF_MAX; - move16(); /* Q0 */ - mem[1] = GAIN_PIT_MIN; - move16(); /* 1Q14 */ - mem[2] = 0; - move16(); /* 8Q7 */ /* old energy of target (dB) */ - mem[3] = 0; - move16(); /* Q0 */ - mem[4] = 0; - move16(); /* Q14 */ - mem[5] = 13107;/*0.8*/ move16(); /* Q14 */ - - return; + mem[0] = DIST_ISF_MAX; + move16(); /* Q0 */ + mem[1] = GAIN_PIT_MIN; + move16(); /* 1Q14 */ + mem[2] = 0; + move16(); /* 8Q7 */ /* old energy of target (dB) */ + mem[3] = 0; + move16(); /* Q0 */ + mem[4] = 0; + move16(); /* Q14 */ + mem[5] = 13107; /*0.8*/ + move16(); /* Q14 */ + + return; } /*-------------------------------------------------------------------* @@ -98,125 +99,125 @@ void init_gp_clip_fx( *-------------------------------------------------------------------*/ Word16 gp_clip_fx( - const Word16 element_mode, /* i : element mode */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 *voicing, /* i : normalized correlations (from OL pitch) */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 coder_type, /* i : type of coder */ - const Word16 xn[], /* i : target vector */ - Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm */ - const Word16 Q_new /* i : scaling factor */ + const Word16 element_mode, /* i : element mode */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 *voicing, /* i : normalized correlations (from OL pitch) */ + const Word16 i_subfr, /* i : subframe index */ + const Word16 coder_type, /* i : type of coder */ + const Word16 xn[], /* i : target vector */ + Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm */ + const Word16 Q_new /* i : scaling factor */ ) { - Word16 clip; - Word16 i, wener; - Word16 e_ener, f_ener; - Word32 ener; - Word32 L_tmp; - Word16 thres; + Word16 clip; + Word16 i, wener; + Word16 e_ener, f_ener; + Word32 ener; + Word32 L_tmp; + Word16 thres; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; + Flag Overflow = 0; #endif - clip = 0; - move16(); - test(); - test(); - IF(EQ_32(core_brate, ACELP_6k60) || EQ_32(core_brate, ACELP_8k85) || GT_16(element_mode, EVS_MONO)) - { - thres = add(14746, mult(1638, extract_l(L_mult(mem[0], (Word16)(16384 / DIST_ISF_MAX_IO))))); /* clipping is activated when filtered pitch gain > threshold (0.94 to 1 in Q14) */ - test(); - if (GT_16(mem[1], thres)) - { - clip = 1; - move16(); - } - } - ELSE - { - test(); - if (LT_16(mem[0], DIST_ISF_THRES) && GT_16(mem[1],GAIN_PIT_THRES)) - { - clip = 1; - move16(); - } - } + clip = 0; + move16(); + test(); + test(); + IF( EQ_32( core_brate, ACELP_6k60 ) || EQ_32( core_brate, ACELP_8k85 ) || GT_16( element_mode, EVS_MONO ) ) + { + thres = add( 14746, mult( 1638, extract_l( L_mult( mem[0], (Word16) ( 16384 / DIST_ISF_MAX_IO ) ) ) ) ); /* clipping is activated when filtered pitch gain > threshold (0.94 to 1 in Q14) */ + test(); + if ( GT_16( mem[1], thres ) ) + { + clip = 1; + move16(); + } + } + ELSE + { + test(); + if ( LT_16( mem[0], DIST_ISF_THRES ) && GT_16( mem[1], GAIN_PIT_THRES ) ) + { + clip = 1; + move16(); + } + } #ifdef BASOP_NOGLOB - ener = L_mac_o(1L, xn[0], xn[0], &Overflow); + ener = L_mac_o( 1L, xn[0], xn[0], &Overflow ); #else - ener = L_mac(1L, xn[0], xn[0]); + ener = L_mac( 1L, xn[0], xn[0] ); #endif - FOR(i = 1; i < L_SUBFR; i++) - { + FOR( i = 1; i < L_SUBFR; i++ ) + { #ifdef BASOP_NOGLOB - ener = L_mac_o(ener, xn[i], xn[i], &Overflow); + ener = L_mac_o( ener, xn[i], xn[i], &Overflow ); #else /* BASOP_NOGLOB */ - ener = L_mac(ener, xn[i], xn[i]); + ener = L_mac( ener, xn[i], xn[i] ); #endif - } - - /* ener = 10.0f*(float)log10(ener) */ - e_ener = norm_l(ener); - f_ener = Log2_norm_lc(L_shl(ener, e_ener)); - e_ener = sub(30, e_ener); - e_ener = sub(e_ener, Q_new); - ener = Mpy_32_16(e_ener, f_ener, LG10); - wener = round_fx(L_shl(ener, 10)); - - test(); - if (LT_16(wener, sub(mem[2], 1536)) && GT_16(mem[1], 16384)) - { - clip = 1; - move16(); - } - - mem[2] = wener; - move16(); - - L_tmp = L_mult(ALPHA1, mem[4]); - - test(); - test(); - if (EQ_16(coder_type, GENERIC) || EQ_16(coder_type, TRANSITION) || EQ_16(coder_type, INACTIVE)) - { - /* mem[4] = (1-ALPHA1) + ALPHA1 * mem[4], if branch taken */ - /* mem[4] = ALPHA1 * mem[4], otherwise */ - L_tmp = L_add(L_tmp, 32768L * (32768 - ALPHA1)); - } - mem[4] = round_fx(L_tmp); - - L_tmp = L_mult(ALPHA4, mem[5]); - if (i_subfr == 0) - { - /* mem[5] = (1-ALPHA4) * voicing[0] + ALPHA4 * mem[5] */ - mem[5] = mac_r(L_tmp, (32768 - ALPHA4) / 2, voicing[0]); - move16(); /* /2 to put voicing from Q15 to Q14 */ - } - - if (EQ_16(i_subfr, 2 * L_SUBFR)) - { - /* mem[5] = (1-ALPHA4) * voicing[1] + ALPHA4 * mem[5] */ - mem[5] = mac_r(L_tmp, (32768 - ALPHA4) / 2, voicing[1]); - move16(); /* /2 to put voicing from Q15 to Q14 */ - } - - IF(GT_16(mem[3], WINDOW_SIZE)) - { - test(); - if (GT_16(mem[4], THRESH_TYPE) && GT_16(mem[5], THRESH_VOICING)) - { - clip = 1; - move16(); - } - } - ELSE - { - mem[3] = add(mem[3], 1); - move16(); - } - - return (clip); + } + + /* ener = 10.0f*(float)log10(ener) */ + e_ener = norm_l( ener ); + f_ener = Log2_norm_lc( L_shl( ener, e_ener ) ); + e_ener = sub( 30, e_ener ); + e_ener = sub( e_ener, Q_new ); + ener = Mpy_32_16( e_ener, f_ener, LG10 ); + wener = round_fx( L_shl( ener, 10 ) ); + + test(); + if ( LT_16( wener, sub( mem[2], 1536 ) ) && GT_16( mem[1], 16384 ) ) + { + clip = 1; + move16(); + } + + mem[2] = wener; + move16(); + + L_tmp = L_mult( ALPHA1, mem[4] ); + + test(); + test(); + if ( EQ_16( coder_type, GENERIC ) || EQ_16( coder_type, TRANSITION ) || EQ_16( coder_type, INACTIVE ) ) + { + /* mem[4] = (1-ALPHA1) + ALPHA1 * mem[4], if branch taken */ + /* mem[4] = ALPHA1 * mem[4], otherwise */ + L_tmp = L_add( L_tmp, 32768L * ( 32768 - ALPHA1 ) ); + } + mem[4] = round_fx( L_tmp ); + + L_tmp = L_mult( ALPHA4, mem[5] ); + if ( i_subfr == 0 ) + { + /* mem[5] = (1-ALPHA4) * voicing[0] + ALPHA4 * mem[5] */ + mem[5] = mac_r( L_tmp, ( 32768 - ALPHA4 ) / 2, voicing[0] ); + move16(); /* /2 to put voicing from Q15 to Q14 */ + } + + if ( EQ_16( i_subfr, 2 * L_SUBFR ) ) + { + /* mem[5] = (1-ALPHA4) * voicing[1] + ALPHA4 * mem[5] */ + mem[5] = mac_r( L_tmp, ( 32768 - ALPHA4 ) / 2, voicing[1] ); + move16(); /* /2 to put voicing from Q15 to Q14 */ + } + + IF( GT_16( mem[3], WINDOW_SIZE ) ) + { + test(); + if ( GT_16( mem[4], THRESH_TYPE ) && GT_16( mem[5], THRESH_VOICING ) ) + { + clip = 1; + move16(); + } + } + ELSE + { + mem[3] = add( mem[3], 1 ); + move16(); + } + + return ( clip ); } /*-------------------------------------------------------------------* @@ -226,48 +227,48 @@ Word16 gp_clip_fx( *-------------------------------------------------------------------*/ void gp_clip_test_isf_fx( - const Word16 element_mode, /* i : element mode */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 isf[], /* i : isf values (in frequency domain) */ - Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm */ - const Word16 Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ + const Word16 element_mode, /* i : element mode */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 isf[], /* i : isf values (in frequency domain) */ + Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm */ + const Word16 Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ ) { - Word16 i, dist, dist_min, m; - - dist_min = sub(isf[1], isf[0]); - - m = M; - move16(); - if (EQ_16(Opt_AMR_WB, 1)) - { - m = M - 1; - move16(); - } - - move16(); /* ptr init*/ - FOR(i = 2; i < m; i++) - { - dist = sub(isf[i], isf[i - 1]); - dist_min = s_min(dist, dist_min); - } - - dist = extract_h(L_mac(L_mult(26214, mem[0]), 6554, dist_min)); - - test(); - test(); - IF(EQ_32(core_brate, ACELP_6k60) || EQ_32(core_brate, ACELP_8k85) || GT_16(element_mode, EVS_MONO)) - { - dist = s_min(dist, DIST_ISF_MAX_IO); - } - ELSE - { - dist = s_min(dist, DIST_ISF_MAX); - } - mem[0] = dist; - move16(); - - return; + Word16 i, dist, dist_min, m; + + dist_min = sub( isf[1], isf[0] ); + + m = M; + move16(); + if ( EQ_16( Opt_AMR_WB, 1 ) ) + { + m = M - 1; + move16(); + } + + move16(); /* ptr init*/ + FOR( i = 2; i < m; i++ ) + { + dist = sub( isf[i], isf[i - 1] ); + dist_min = s_min( dist, dist_min ); + } + + dist = extract_h( L_mac( L_mult( 26214, mem[0] ), 6554, dist_min ) ); + + test(); + test(); + IF( EQ_32( core_brate, ACELP_6k60 ) || EQ_32( core_brate, ACELP_8k85 ) || GT_16( element_mode, EVS_MONO ) ) + { + dist = s_min( dist, DIST_ISF_MAX_IO ); + } + ELSE + { + dist = s_min( dist, DIST_ISF_MAX ); + } + mem[0] = dist; + move16(); + + return; } /*-------------------------------------------------------------------* @@ -277,33 +278,33 @@ void gp_clip_test_isf_fx( *-------------------------------------------------------------------*/ void gp_clip_test_gain_pit_fx( - const Word16 element_mode, /* i : element mode */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 gain_pit, /* i : gain of quantized pitch Q14 */ - Word16 mem[] /* i/o: memory of gain of pitch clipping algorithm 1Q14 */ + const Word16 element_mode, /* i : element mode */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 gain_pit, /* i : gain of quantized pitch Q14 */ + Word16 mem[] /* i/o: memory of gain of pitch clipping algorithm 1Q14 */ ) { - Word16 gain; - Word32 L_tmp; - - test(); - test(); - IF(EQ_32(core_brate, ACELP_6k60) || EQ_32(core_brate, ACELP_8k85) || GT_16(element_mode, EVS_MONO)) - { - L_tmp = L_mult(32113, mem[1]); /* long term LTP gain average (>250ms) */ - L_tmp = L_mac(L_tmp, 655, gain_pit); - } - ELSE - { - L_tmp = L_mult(29491, mem[1]); - L_tmp = L_mac(L_tmp, 3277, gain_pit); - } - gain = extract_h(L_tmp); - gain = s_max(gain, GAIN_PIT_MIN); - mem[1] = gain; - move16(); - - return; + Word16 gain; + Word32 L_tmp; + + test(); + test(); + IF( EQ_32( core_brate, ACELP_6k60 ) || EQ_32( core_brate, ACELP_8k85 ) || GT_16( element_mode, EVS_MONO ) ) + { + L_tmp = L_mult( 32113, mem[1] ); /* long term LTP gain average (>250ms) */ + L_tmp = L_mac( L_tmp, 655, gain_pit ); + } + ELSE + { + L_tmp = L_mult( 29491, mem[1] ); + L_tmp = L_mac( L_tmp, 3277, gain_pit ); + } + gain = extract_h( L_tmp ); + gain = s_max( gain, GAIN_PIT_MIN ); + mem[1] = gain; + move16(); + + return; } @@ -317,145 +318,145 @@ void gp_clip_test_gain_pit_fx( * - target energy drops by 6 dB AND a good pitch prediction (lp_gp>1.0) *-------------------------------------------------------------------*/ Word16 Mode2_gp_clip( - const Word16 *voicing, /* i : normalized correlations from OL pitch Q15 */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 coder_type, /* i : type of coder */ - const Word16 xn[], /* i : target vector Q_xn */ - Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm */ - /* mem[0]: Q0 */ - /* mem[1]: 1Q14 */ - /* mem[2]: 8Q7 */ - /* mem[3]: Q0 (integer) */ - /* mem[4]: Q14 */ - /* mem[5]: Q14 */ - const Word16 L_subfr, - const Word16 Q_xn /* i : scaling factor of vector xn[] */ + const Word16 *voicing, /* i : normalized correlations from OL pitch Q15 */ + const Word16 i_subfr, /* i : subframe index */ + const Word16 coder_type, /* i : type of coder */ + const Word16 xn[], /* i : target vector Q_xn */ + Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm */ + /* mem[0]: Q0 */ + /* mem[1]: 1Q14 */ + /* mem[2]: 8Q7 */ + /* mem[3]: Q0 (integer) */ + /* mem[4]: Q14 */ + /* mem[5]: Q14 */ + const Word16 L_subfr, + const Word16 Q_xn /* i : scaling factor of vector xn[] */ ) { - Word16 clip, tmp, exp_xn; - Word16 i; - Word32 wener, Ltmp; + Word16 clip, tmp, exp_xn; + Word16 i; + Word32 wener, Ltmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; + Flag Overflow = 0; #endif - move16(); - clip = 0; - - test(); - if ((LT_16(mem[0], DIST_ISF_THRES)) && (GT_16(mem[1], GAIN_PIT_THRES))) - { - move16(); - clip = 1; - } - - /*ener_exp = exp_xn * 2 + 1*/ - exp_xn = add(shl(sub(15, Q_xn), 1), 1); - wener = L_shr(21474836l/*0.01f Q31*/, s_min(31, exp_xn)); - wener = L_max(1, wener); - - FOR(i = 0; i < L_subfr; i++) - { + move16(); + clip = 0; + + test(); + if ( ( LT_16( mem[0], DIST_ISF_THRES ) ) && ( GT_16( mem[1], GAIN_PIT_THRES ) ) ) + { + move16(); + clip = 1; + } + + /*ener_exp = exp_xn * 2 + 1*/ + exp_xn = add( shl( sub( 15, Q_xn ), 1 ), 1 ); + wener = L_shr( 21474836l /*0.01f Q31*/, s_min( 31, exp_xn ) ); + wener = L_max( 1, wener ); + + FOR( i = 0; i < L_subfr; i++ ) + { #ifdef BASOP_NOGLOB - wener = L_mac0_o(wener, xn[i], xn[i], &Overflow); + wener = L_mac0_o( wener, xn[i], xn[i], &Overflow ); #else - wener = L_mac0(wener, xn[i], xn[i]); + wener = L_mac0( wener, xn[i], xn[i] ); #endif - } - - /*wener = 10.0f*(float)log10(wener);*/ - wener = BASOP_Util_Log2(wener); - wener = L_add(wener, L_shl(exp_xn, 31 - LD_DATA_SCALE)); - wener = Mpy_32_16_1(wener, LG10); /* wener in 8Q7 */ -#if (GPCLIP_E != 6+2) - wener = shl(wener, GPCLIP_E - (6 + 2)); + } + + /*wener = 10.0f*(float)log10(wener);*/ + wener = BASOP_Util_Log2( wener ); + wener = L_add( wener, L_shl( exp_xn, 31 - LD_DATA_SCALE ) ); + wener = Mpy_32_16_1( wener, LG10 ); /* wener in 8Q7 */ +#if ( GPCLIP_E != 6 + 2 ) + wener = shl( wener, GPCLIP_E - ( 6 + 2 ) ); #endif - tmp = round_fx(wener); - /* exponent of wener = 6+2 */ - - test(); - if (LT_16(tmp, sub(mem[2], 768/*6.0f Q7*/)) && - GT_16(mem[1], 16384/*1.0f Q14*/)) - { - move16(); - clip = 1; - } - - move16(); - mem[2] = tmp; /* wener in 8Q7 format */ - Ltmp = Mpy_32_16_1(ALPHA1, mem[4]); /* mem[4] in Q14 format, Ltmp in Q14 */ - - if (s_or((Word16)EQ_16(coder_type, GENERIC), (Word16)EQ_16(coder_type, TRANSITION))) - { - Ltmp = L_add(Ltmp, ALPHA1_M1); - } - mem[4] = round_fx(Ltmp); - - Ltmp = Mpy_32_16_1(ALPHA4, mem[5]); /* mem[5] in Q14 format, Ltmp in Q14 */ - IF(i_subfr == 0) - { - move16(); /* voicing: Q15 */ - mem[5] = round_fx(L_add(Mpy_32_16_1(ALPHA4_M1, voicing[0]), Ltmp)); - } - ELSE IF(EQ_16(i_subfr, shl(L_subfr, 1))) - { - move16(); - mem[5] = round_fx(L_add(Mpy_32_16_1(ALPHA4_M1, voicing[1]), Ltmp)); - } - - IF(GT_16(mem[3], WINDOW_SIZE)) - { - test(); - if ((GT_16(mem[4], THRESH_TYPE)) && (GT_16(mem[5], THRESH_VOICING))) - { - move16(); - clip = 1; - } - } - ELSE - { - move16(); - mem[3] = add(mem[3], 1); - } - - - return (clip); + tmp = round_fx( wener ); + /* exponent of wener = 6+2 */ + + test(); + if ( LT_16( tmp, sub( mem[2], 768 /*6.0f Q7*/ ) ) && + GT_16( mem[1], 16384 /*1.0f Q14*/ ) ) + { + move16(); + clip = 1; + } + + move16(); + mem[2] = tmp; /* wener in 8Q7 format */ + Ltmp = Mpy_32_16_1( ALPHA1, mem[4] ); /* mem[4] in Q14 format, Ltmp in Q14 */ + + if ( s_or( (Word16) EQ_16( coder_type, GENERIC ), (Word16) EQ_16( coder_type, TRANSITION ) ) ) + { + Ltmp = L_add( Ltmp, ALPHA1_M1 ); + } + mem[4] = round_fx( Ltmp ); + + Ltmp = Mpy_32_16_1( ALPHA4, mem[5] ); /* mem[5] in Q14 format, Ltmp in Q14 */ + IF( i_subfr == 0 ) + { + move16(); /* voicing: Q15 */ + mem[5] = round_fx( L_add( Mpy_32_16_1( ALPHA4_M1, voicing[0] ), Ltmp ) ); + } + ELSE IF( EQ_16( i_subfr, shl( L_subfr, 1 ) ) ) + { + move16(); + mem[5] = round_fx( L_add( Mpy_32_16_1( ALPHA4_M1, voicing[1] ), Ltmp ) ); + } + + IF( GT_16( mem[3], WINDOW_SIZE ) ) + { + test(); + if ( ( GT_16( mem[4], THRESH_TYPE ) ) && ( GT_16( mem[5], THRESH_VOICING ) ) ) + { + move16(); + clip = 1; + } + } + ELSE + { + move16(); + mem[3] = add( mem[3], 1 ); + } + + + return ( clip ); } /*-------------------------------------------------------------------* -* gp_clip_test_lsf: -* -* check the minimum distance of LSFs for pitch gain clipping flag -*-------------------------------------------------------------------*/ + * gp_clip_test_lsf: + * + * check the minimum distance of LSFs for pitch gain clipping flag + *-------------------------------------------------------------------*/ void gp_clip_test_lsf_fx( - const Word16 element_mode, /* i : element mode */ - const Word16 lsf[], /* i : lsf values (in frequency domain) 14Q1*1.28 */ - Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm */ - const Word16 m /* i : dimension of lsf */ + const Word16 element_mode, /* i : element mode */ + const Word16 lsf[], /* i : lsf values (in frequency domain) 14Q1*1.28 */ + Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm */ + const Word16 m /* i : dimension of lsf */ ) { - Word16 i; - Word16 dist, dist_min, dist_max; - - dist_max = DIST_ISF_MAX; - move16(); - if (GT_16(element_mode, EVS_MONO)) - { - dist_max = DIST_ISF_MAX_IO; - move16(); - } - dist_min = sub(lsf[1], lsf[0]); - - FOR(i = 2; i < m - 1; i++) - { - dist = sub(lsf[i], lsf[i - 1]); - dist_min = s_min(dist, dist_min); - } - /*dist = 0.8f*mem[0] + 0.2f*dist_min;*/ - dist = s_min(dist_max, mac_r(L_mult(26214/*0.8f Q15*/, mem[0]), 6554/*0.2f Q15*/, dist_min)); - - mem[0] = dist; - move16(); - - - return; + Word16 i; + Word16 dist, dist_min, dist_max; + + dist_max = DIST_ISF_MAX; + move16(); + if ( GT_16( element_mode, EVS_MONO ) ) + { + dist_max = DIST_ISF_MAX_IO; + move16(); + } + dist_min = sub( lsf[1], lsf[0] ); + + FOR( i = 2; i < m - 1; i++ ) + { + dist = sub( lsf[i], lsf[i - 1] ); + dist_min = s_min( dist, dist_min ); + } + /*dist = 0.8f*mem[0] + 0.2f*dist_min;*/ + dist = s_min( dist_max, mac_r( L_mult( 26214 /*0.8f Q15*/, mem[0] ), 6554 /*0.2f Q15*/, dist_min ) ); + + mem[0] = dist; + move16(); + + + return; } diff --git a/lib_enc/gs_enc_fx.c b/lib_enc/gs_enc_fx.c index 8ca6b2273..a0396a97f 100644 --- a/lib_enc/gs_enc_fx.c +++ b/lib_enc/gs_enc_fx.c @@ -7,40 +7,39 @@ #include "rom_com_fx.h" #include "rom_com.h" //#include "prot_fx.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* * Local function prototypes *-------------------------------------------------------------------*/ -static Word16 edyn_fx(const Word16 *vec, const Word16 lvec, Word16 Qnew); +static Word16 edyn_fx( const Word16 *vec, const Word16 lvec, Word16 Qnew ); /*-------------------------------------------------------------------* - * encod_audio() - * - * Encode audio (AC) frames - *-------------------------------------------------------------------*/ + * encod_audio() + * + * Encode audio (AC) frames + *-------------------------------------------------------------------*/ void encod_audio_fx( - Encoder_State *st_fx, /* i/o: State structure */ - const Word16 speech[], /* i : input speech Q_new */ - const Word16 Aw[], /* i : weighted A(z) unquantized for subframes */ - const Word16 Aq[], /* i : 12k8 Lp coefficient */ - const Word16 *res, /* i : residual signal Q_new */ - Word16 *synth, /* i/o: core synthesis Q-1 */ - Word16 *exc, /* i/o: current non-enhanced excitation Q_new */ - Word16 *pitch_buf, /* i/o: floating pitch values for each subframe Q6 */ - Word16 *voice_factors, /* o : voicing factors Q15 */ - Word16 *bwe_exc, /* o : excitation for SWB TBE Q0 */ - const Word16 attack_flag, /* i : Flag that point to an attack coded with AC mode (GSC) */ - Word16 *lsf_new, /* i : current frame ISF vector */ - Word16 *tmp_noise, /* o : noise energy */ + Encoder_State *st_fx, /* i/o: State structure */ + const Word16 speech[], /* i : input speech Q_new */ + const Word16 Aw[], /* i : weighted A(z) unquantized for subframes */ + const Word16 Aq[], /* i : 12k8 Lp coefficient */ + const Word16 *res, /* i : residual signal Q_new */ + Word16 *synth, /* i/o: core synthesis Q-1 */ + Word16 *exc, /* i/o: current non-enhanced excitation Q_new */ + Word16 *pitch_buf, /* i/o: floating pitch values for each subframe Q6 */ + Word16 *voice_factors, /* o : voicing factors Q15 */ + Word16 *bwe_exc, /* o : excitation for SWB TBE Q0 */ + const Word16 attack_flag, /* i : Flag that point to an attack coded with AC mode (GSC) */ + Word16 *lsf_new, /* i : current frame ISF vector */ + Word16 *tmp_noise, /* o : noise energy */ const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer */ Word16 Q_new, - Word16 shift -) + Word16 shift ) { const Word16 *p_Aq; Word16 i, i_subfr, nb_subfr, last_pit_bin; @@ -68,7 +67,7 @@ void encod_audio_fx( move16(); T0_frac_tmp = 0; move16(); - Copy(hLPDmem->mem_syn, hGSCEnc->mem_syn_tmp_fx, M); + Copy( hLPDmem->mem_syn, hGSCEnc->mem_syn_tmp_fx, M ); hGSCEnc->mem_w0_tmp_fx = hLPDmem->mem_w0; move16(); Es_pred = 0; @@ -81,38 +80,42 @@ void encod_audio_fx( *---------------------------------------------------------------*/ #ifdef GSC_IVAS // TVB -->>>>>> test(); - if (GT_16( st_fx->element_mode, EVS_MONO) && st_fx->idchan == 0) + if ( GT_16( st_fx->element_mode, EVS_MONO ) && st_fx->idchan == 0 ) { - push_indice_fx(hBstr, IND_GSC_IVAS_SP, st_fx->GSC_IVAS_mode, 2); + push_indice_fx( hBstr, IND_GSC_IVAS_SP, st_fx->GSC_IVAS_mode, 2 ); } #endif - IF (attack_flag > 0) + IF( attack_flag > 0 ) { - push_indice_fx(hBstr, IND_GSC_ATTACK, 1, 1); + push_indice_fx( hBstr, IND_GSC_ATTACK, 1, 1 ); } ELSE { - push_indice_fx(hBstr, IND_GSC_ATTACK, 0, 1); + push_indice_fx( hBstr, IND_GSC_ATTACK, 0, 1 ); } - - test(); test(); test(); - test();test();test(); - IF (GE_16(st_fx->GSC_IVAS_mode, 1) || (NE_16(st_fx->coder_type, INACTIVE) && ((EQ_16(st_fx->element_mode, EVS_MONO) && GE_32(st_fx->total_brate, ACELP_13k20)) || - (GT_16(st_fx->element_mode, EVS_MONO) && GT_32(st_fx->total_brate, MIN_BRATE_GSC_NOISY_FLAG) && GE_16(st_fx->bwidth, SWB) && !st_fx->flag_ACELP16k)))) + + test(); + test(); + test(); + test(); + test(); + test(); + IF( GE_16( st_fx->GSC_IVAS_mode, 1 ) || ( NE_16( st_fx->coder_type, INACTIVE ) && ( ( EQ_16( st_fx->element_mode, EVS_MONO ) && GE_32( st_fx->total_brate, ACELP_13k20 ) ) || + ( GT_16( st_fx->element_mode, EVS_MONO ) && GT_32( st_fx->total_brate, MIN_BRATE_GSC_NOISY_FLAG ) && GE_16( st_fx->bwidth, SWB ) && !st_fx->flag_ACELP16k ) ) ) ) { - push_indice_fx(hBstr,IND_GSC_SWB_SPEECH, st_fx->GSC_noisy_speech, 1); + push_indice_fx( hBstr, IND_GSC_SWB_SPEECH, st_fx->GSC_noisy_speech, 1 ); } /*---------------------------------------------------------------* * Find and encode the number of subframes *---------------------------------------------------------------*/ test(); - IF ( GE_32(st_fx->core_brate,ACELP_9k60) && LE_32(st_fx->core_brate,ACELP_13k20)) + IF( GE_32( st_fx->core_brate, ACELP_9k60 ) && LE_32( st_fx->core_brate, ACELP_13k20 ) ) { - FOR( i = 0; i < 5; i++) + FOR( i = 0; i < 5; i++ ) { test(); - if( GT_16(abs_s(hSpMusClas->gsc_lt_diff_etot_fx[MAX_LT-i-1]),1536)&&EQ_16(hGSCEnc->cor_strong_limit,1)) + if ( GT_16( abs_s( hSpMusClas->gsc_lt_diff_etot_fx[MAX_LT - i - 1] ), 1536 ) && EQ_16( hGSCEnc->cor_strong_limit, 1 ) ) { hGSCEnc->cor_strong_limit = 0; move16(); @@ -120,12 +123,13 @@ void encod_audio_fx( } } test(); - IF(GE_16(st_fx->GSC_IVAS_mode, 1) || (st_fx->GSC_noisy_speech && st_fx->GSC_IVAS_mode == 0)) + IF( GE_16( st_fx->GSC_IVAS_mode, 1 ) || ( st_fx->GSC_noisy_speech && st_fx->GSC_IVAS_mode == 0 ) ) { nb_subfr = NB_SUBFR; move16(); - test();test(); - if (st_fx->GSC_IVAS_mode > 0 && LT_16(st_fx->GSC_IVAS_mode, 3) && LT_32(st_fx->core_brate, GSC_L_RATE_STG)) + test(); + test(); + if ( st_fx->GSC_IVAS_mode > 0 && LT_16( st_fx->GSC_IVAS_mode, 3 ) && LT_32( st_fx->core_brate, GSC_L_RATE_STG ) ) { nb_subfr = 2; move16(); @@ -135,19 +139,20 @@ void encod_audio_fx( nb_subfr_flag = 1; move16(); } - ELSE IF (EQ_16(st_fx->L_frame, L_FRAME16k) && (LE_32(st_fx->core_brate, ACELP_13k20) || EQ_16(st_fx->coder_type, INACTIVE))) + ELSE IF( EQ_16( st_fx->L_frame, L_FRAME16k ) && ( LE_32( st_fx->core_brate, ACELP_13k20 ) || EQ_16( st_fx->coder_type, INACTIVE ) ) ) { hGSCEnc->cor_strong_limit = 0; nb_subfr = SWNB_SUBFR; nb_subfr_flag = 1; - move16();move16();move16(); - + move16(); + move16(); + move16(); } ELSE { test(); test(); - IF( (hGSCEnc->cor_strong_limit == 0 || EQ_16(st_fx->coder_type,INACTIVE)) && GE_32(st_fx->core_brate,ACELP_9k60)) + IF( ( hGSCEnc->cor_strong_limit == 0 || EQ_16( st_fx->coder_type, INACTIVE ) ) && GE_32( st_fx->core_brate, ACELP_9k60 ) ) { nb_subfr = 2; move16(); @@ -163,24 +168,25 @@ void encod_audio_fx( nb_subfr_flag = 1; move16(); } - IF (EQ_16(st_fx->L_frame, L_FRAME16k) && (GT_16(hSpMusClas->mold_corr_fx, 26214) && GE_32(st_fx->core_brate, MIN_RATE_4SBFR) && NE_16(st_fx->coder_type, INACTIVE))) + IF( EQ_16( st_fx->L_frame, L_FRAME16k ) && ( GT_16( hSpMusClas->mold_corr_fx, 26214 ) && GE_32( st_fx->core_brate, MIN_RATE_4SBFR ) && NE_16( st_fx->coder_type, INACTIVE ) ) ) { - nb_subfr = shl(nb_subfr, 1); - nb_subfr_flag |= 0x2; logic16(); + nb_subfr = shl( nb_subfr, 1 ); + nb_subfr_flag |= 0x2; + logic16(); } - IF (EQ_16(st_fx->L_frame, L_FRAME16k) && GE_32(st_fx->core_brate, MIN_RATE_4SBFR)) + IF( EQ_16( st_fx->L_frame, L_FRAME16k ) && GE_32( st_fx->core_brate, MIN_RATE_4SBFR ) ) { - push_indice_fx(hBstr, IND_HF_NOISE, nb_subfr_flag, 2); + push_indice_fx( hBstr, IND_HF_NOISE, nb_subfr_flag, 2 ); } - ELSE IF( GE_32(st_fx->core_brate,ACELP_9k60)) + ELSE IF( GE_32( st_fx->core_brate, ACELP_9k60 ) ) { /* nb_subfr_flag can only have the value 0 or 1 */ - push_indice_fx(hBstr, IND_HF_NOISE, nb_subfr_flag, 1); + push_indice_fx( hBstr, IND_HF_NOISE, nb_subfr_flag, 1 ); } } test(); - if (EQ_16(st_fx->L_frame, L_FRAME16k) && EQ_16(nb_subfr, NB_SUBFR)) + if ( EQ_16( st_fx->L_frame, L_FRAME16k ) && EQ_16( nb_subfr, NB_SUBFR ) ) { nb_subfr = NB_SUBFR16k; move16(); @@ -191,79 +197,79 @@ void encod_audio_fx( *---------------------------------------------------------------*/ test(); - IF (!(st_fx->GSC_IVAS_mode > 0 && EQ_16(st_fx->L_frame, i_mult(nb_subfr, 2 * L_SUBFR)) && LT_16(st_fx->GSC_IVAS_mode, 3)) && - ((GE_32(st_fx->core_brate, MIN_RATE_FCB) || st_fx->GSC_noisy_speech) && - ((EQ_16(nb_subfr, NB_SUBFR) && EQ_16(st_fx->L_frame, L_FRAME)) || (EQ_16(nb_subfr, NB_SUBFR16k) && EQ_16(st_fx->L_frame, L_FRAME16k))))) + IF( !( st_fx->GSC_IVAS_mode > 0 && EQ_16( st_fx->L_frame, i_mult( nb_subfr, 2 * L_SUBFR ) ) && LT_16( st_fx->GSC_IVAS_mode, 3 ) ) && + ( ( GE_32( st_fx->core_brate, MIN_RATE_FCB ) || st_fx->GSC_noisy_speech ) && + ( ( EQ_16( nb_subfr, NB_SUBFR ) && EQ_16( st_fx->L_frame, L_FRAME ) ) || ( EQ_16( nb_subfr, NB_SUBFR16k ) && EQ_16( st_fx->L_frame, L_FRAME16k ) ) ) ) ) { - IF (GT_16(st_fx->element_mode, EVS_MONO)) + IF( GT_16( st_fx->element_mode, EVS_MONO ) ) { nb_bits = 5; } - ELSE + ELSE { - nb_bits = Es_pred_bits_tbl[BIT_ALLOC_IDX_fx(st_fx->core_brate, GENERIC, -1, -1)]; + nb_bits = Es_pred_bits_tbl[BIT_ALLOC_IDX_fx( st_fx->core_brate, GENERIC, -1, -1 )]; move16(); } - Es_pred_enc_fx(&Es_pred, &indice, st_fx->L_frame, res, st_fx->voicing_fx, nb_bits, 0, Q_new); - push_indice_fx(hBstr, IND_ES_PRED, indice, nb_bits ); + Es_pred_enc_fx( &Es_pred, &indice, st_fx->L_frame, res, st_fx->voicing_fx, nb_bits, 0, Q_new ); + push_indice_fx( hBstr, IND_ES_PRED, indice, nb_bits ); } - enc_pit_exc_fx( st_fx, speech, Aw, Aq,Es_pred, res, synth, exc, &T0_tmp, + enc_pit_exc_fx( st_fx, speech, Aw, Aq, Es_pred, res, synth, exc, &T0_tmp, &T0_frac_tmp, pitch_buf, nb_subfr, &hGSCEnc->lt_gpitch_fx, &saved_bit_pos, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf, Q_new, shift ); /*---------------------------------------------------------------* * DCT transform *---------------------------------------------------------------*/ - edct_16fx( exc, dct_epit, st_fx->L_frame, 7, st_fx->element_mode); - edct_16fx( res, dct_res, st_fx->L_frame, 7, st_fx->element_mode); + edct_16fx( exc, dct_epit, st_fx->L_frame, 7, st_fx->element_mode ); + edct_16fx( res, dct_res, st_fx->L_frame, 7, st_fx->element_mode ); /*---------------------------------------------------------------* * Calculate energy dynamics *---------------------------------------------------------------*/ - Lm_mean = L_deposit_l(0); + Lm_mean = L_deposit_l( 0 ); FOR( i = 7; i < 15; i++ ) { /*m_mean = add(m_mean,edyn_fx( dct_res+i*16, 16, Q_new )); */ - Lm_mean = L_mac(Lm_mean, edyn_fx( dct_res+i*16, 16, Q_new ), 4096);/*Q7*/ + Lm_mean = L_mac( Lm_mean, edyn_fx( dct_res + i * 16, 16, Q_new ), 4096 ); /*Q7*/ } - m_mean = round_fx(Lm_mean);/*Q7*/ + m_mean = round_fx( Lm_mean ); /*Q7*/ - IF( GT_16(m_mean, hGSCEnc->mid_dyn_fx)) + IF( GT_16( m_mean, hGSCEnc->mid_dyn_fx ) ) { /*st_fx->mid_dyn_fx = 0.2f * st_fx->mid_dyn_fx + 0.8f * m_mean;*/ - hGSCEnc->mid_dyn_fx = round_fx(L_mac(L_mult(26214,m_mean),6554, hGSCEnc->mid_dyn_fx));/*Q7*/ + hGSCEnc->mid_dyn_fx = round_fx( L_mac( L_mult( 26214, m_mean ), 6554, hGSCEnc->mid_dyn_fx ) ); /*Q7*/ } ELSE { /*st_fx->mid_dyn_fx = 0.6f * st_fx->mid_dyn_fx + 0.4f * m_mean;*/ - hGSCEnc->mid_dyn_fx = round_fx(L_mac(L_mult(13107,m_mean),19661,hGSCEnc->mid_dyn_fx));/*Q7*/ + hGSCEnc->mid_dyn_fx = round_fx( L_mac( L_mult( 13107, m_mean ), 19661, hGSCEnc->mid_dyn_fx ) ); /*Q7*/ } - IF( NE_16(st_fx->coder_type,INACTIVE)) + IF( NE_16( st_fx->coder_type, INACTIVE ) ) { - hGSCEnc->noise_lev = sub((NOISE_LEVEL_SP3+1), usquant_fx(hGSCEnc->mid_dyn_fx, &m_mean, MIN_DYNAMIC_FX, shr(GSF_NF_DELTA_FX,1), GSC_NF_STEPS)); + hGSCEnc->noise_lev = sub( ( NOISE_LEVEL_SP3 + 1 ), usquant_fx( hGSCEnc->mid_dyn_fx, &m_mean, MIN_DYNAMIC_FX, shr( GSF_NF_DELTA_FX, 1 ), GSC_NF_STEPS ) ); - hGSCEnc->noise_lev = s_min(hGSCEnc->noise_lev, NOISE_LEVEL_SP3); + hGSCEnc->noise_lev = s_min( hGSCEnc->noise_lev, NOISE_LEVEL_SP3 ); } hGSCEnc->past_dyn_dec = hGSCEnc->noise_lev; move16(); - IF (GE_16(st_fx->GSC_IVAS_mode, 1)) + IF( GE_16( st_fx->GSC_IVAS_mode, 1 ) ) { hGSCEnc->noise_lev = NOISE_LEVEL_SP2; - IF (EQ_16(st_fx->GSC_IVAS_mode, 3) ) /* Music like */ + IF( EQ_16( st_fx->GSC_IVAS_mode, 3 ) ) /* Music like */ { hGSCEnc->noise_lev = NOISE_LEVEL_SP0; move16(); } - ELSE IF (st_fx->GSC_noisy_speech == 0) + ELSE IF( st_fx->GSC_noisy_speech == 0 ) { hGSCEnc->noise_lev = NOISE_LEVEL_SP3; move16(); } } - ELSE IF( LE_32(st_fx->core_brate,ACELP_8k00)) + ELSE IF( LE_32( st_fx->core_brate, ACELP_8k00 ) ) { - hGSCEnc->noise_lev = s_max(hGSCEnc->noise_lev, NOISE_LEVEL_SP2); - push_indice_fx(hBstr, IND_NOISE_LEVEL, sub(hGSCEnc->noise_lev, NOISE_LEVEL_SP2), 2 ); + hGSCEnc->noise_lev = s_max( hGSCEnc->noise_lev, NOISE_LEVEL_SP2 ); + push_indice_fx( hBstr, IND_NOISE_LEVEL, sub( hGSCEnc->noise_lev, NOISE_LEVEL_SP2 ), 2 ); } ELSE IF( st_fx->GSC_noisy_speech ) { @@ -272,7 +278,7 @@ void encod_audio_fx( } ELSE { - push_indice_fx(hBstr, IND_NOISE_LEVEL, sub(hGSCEnc->noise_lev, NOISE_LEVEL_SP0), 3 ); + push_indice_fx( hBstr, IND_NOISE_LEVEL, sub( hGSCEnc->noise_lev, NOISE_LEVEL_SP0 ), 3 ); } /*---------------------------------------------------------------* @@ -289,7 +295,7 @@ void encod_audio_fx( ELSE { /*last_pit_bin++;*/ - last_pit_bin = add(last_pit_bin,1); + last_pit_bin = add( last_pit_bin, 1 ); } /*--------------------------------------------------------------------------------------* @@ -301,16 +307,17 @@ void encod_audio_fx( move16(); - if( st_fx->extl_brate > 0 ) + if ( st_fx->extl_brate > 0 ) { /* subtract 1 bit for TBE/BWE BWE flag (bit counted in extl_brate) */ - tmp_nb_bits_tot = sub(tmp_nb_bits_tot,1); + tmp_nb_bits_tot = sub( tmp_nb_bits_tot, 1 ); } - test(); test(); - if( EQ_16(st_fx->coder_type,INACTIVE) && LE_32(st_fx->core_brate,ACELP_9k60) && st_fx->idchan == 0) + test(); + test(); + if ( EQ_16( st_fx->coder_type, INACTIVE ) && LE_32( st_fx->core_brate, ACELP_9k60 ) && st_fx->idchan == 0 ) { /* add 5 bits for noisiness */ - tmp_nb_bits_tot = add(tmp_nb_bits_tot,5); + tmp_nb_bits_tot = add( tmp_nb_bits_tot, 5 ); } gsc_enc_fx( st_fx, dct_res, dct_epit, last_pit_bin, tmp_nb_bits_tot, nb_subfr, lsf_new, exc_wo_nf, tmp_noise, Q_new ); @@ -319,28 +326,28 @@ void encod_audio_fx( * iDCT transform *--------------------------------------------------------------------------------------*/ - edct_16fx( dct_epit, exc, st_fx->L_frame , 7, st_fx->element_mode); - edct_16fx( exc_wo_nf, exc_wo_nf, st_fx->L_frame , 7, st_fx->element_mode); + edct_16fx( dct_epit, exc, st_fx->L_frame, 7, st_fx->element_mode ); + edct_16fx( exc_wo_nf, exc_wo_nf, st_fx->L_frame, 7, st_fx->element_mode ); /*--------------------------------------------------------------------------------------* * Remove potential pre-echo in case an onset has been detected *--------------------------------------------------------------------------------------*/ - pre_echo_att_fx( &hGSCEnc->Last_frame_ener_fx, exc, attack_flag, Q_new, st_fx->last_coder_type, st_fx->L_frame); + pre_echo_att_fx( &hGSCEnc->Last_frame_ener_fx, exc, attack_flag, Q_new, st_fx->last_coder_type, st_fx->L_frame ); /*--------------------------------------------------------------------------------------* * Update BWE excitation *--------------------------------------------------------------------------------------*/ - IF (st_fx->hBWE_TD != NULL) + IF( st_fx->hBWE_TD != NULL ) { - IF (EQ_16(st_fx->L_frame, L_FRAME16k)) + IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { - set16_fx(voice_factors, 0, NB_SUBFR16k); - interp_code_4over2_fx(exc, bwe_exc, L_FRAME16k); + set16_fx( voice_factors, 0, NB_SUBFR16k ); + interp_code_4over2_fx( exc, bwe_exc, L_FRAME16k ); } ELSE { - set16_fx(voice_factors, 0, NB_SUBFR); - interp_code_5over2_fx(exc, bwe_exc, L_FRAME); + set16_fx( voice_factors, 0, NB_SUBFR ); + interp_code_5over2_fx( exc, bwe_exc, L_FRAME ); } } /*--------------------------------------------------------------------------------------* @@ -348,19 +355,19 @@ void encod_audio_fx( *--------------------------------------------------------------------------------------*/ p_Aq = Aq; - FOR (i_subfr=0; i_subfr< st_fx->L_frame; i_subfr+=L_SUBFR) + FOR( i_subfr = 0; i_subfr < st_fx->L_frame; i_subfr += L_SUBFR ) { Syn_filt_s( 1, p_Aq, M, &exc_wo_nf[i_subfr], &synth[i_subfr], L_SUBFR, hLPDmem->mem_syn, 1 ); - p_Aq += (M+1); + p_Aq += ( M + 1 ); } /*--------------------------------------------------------------------------------------* * Updates *--------------------------------------------------------------------------------------*/ - hLPDmem->mem_w0 = hGSCEnc->mem_w0_tmp_fx; /*_DIFF_FLOAT_FIX_ The way it is written in the original fix point is that at this point mem_w0 falls back to its original value (before enc_pit_exc, seems not the case in float */ + hLPDmem->mem_w0 = hGSCEnc->mem_w0_tmp_fx; /*_DIFF_FLOAT_FIX_ The way it is written in the original fix point is that at this point mem_w0 falls back to its original value (before enc_pit_exc, seems not the case in float */ move16(); - Copy( exc_wo_nf, exc, st_fx->L_frame); + Copy( exc_wo_nf, exc, st_fx->L_frame ); return; } @@ -391,22 +398,21 @@ void encod_audio_fx( void gsc_enc_fx( - Encoder_State *st_fx, /* i/o: State structure */ - Word16 res_dct_in[], /* i : dct of residual signal */ - Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation */ + Encoder_State *st_fx, /* i/o: State structure */ + Word16 res_dct_in[], /* i : dct of residual signal */ + Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation */ const Word16 Diff_len, const Word16 bits_used, const Word16 nb_subfr, - Word16 *lsf_new, /* i : ISFs at the end of the frame */ - Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill */ - Word16 *tmp_noise, /* o : noise energy */ - Word16 Q_exc -) + Word16 *lsf_new, /* i : ISFs at the end of the frame */ + Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill */ + Word16 *tmp_noise, /* o : noise energy */ + Word16 Q_exc ) { Word16 y2_filt[L_FRAME16k]; Word16 exc_diffQ[L_FRAME16k]; Word16 exc_diff[L_FRAME16k]; - Word16 bit,tmp; + Word16 bit, tmp; Word16 nb_subbands; Word16 pvq_len, i; Word16 bits_per_bands[MBANDS_GN_BITALLOC16k]; @@ -438,21 +444,23 @@ void gsc_enc_fx( *--------------------------------------------------------------------------------------*/ bit = bits_used; - test();test();test(); - if (EQ_16(st_fx->coder_type, INACTIVE) && (EQ_16(st_fx->tdm_LRTD_flag, 1) || EQ_16(st_fx->element_mode, IVAS_SCE)) && LE_32(st_fx->core_brate, GSC_LRES_GAINQ_LIMIT)) + test(); + test(); + test(); + if ( EQ_16( st_fx->coder_type, INACTIVE ) && ( EQ_16( st_fx->tdm_LRTD_flag, 1 ) || EQ_16( st_fx->element_mode, IVAS_SCE ) ) && LE_32( st_fx->core_brate, GSC_LRES_GAINQ_LIMIT ) ) { - bit = add(bit, GSC_LRES_NB_NITS); + bit = add( bit, GSC_LRES_NB_NITS ); } move16(); set16_fx( exc_diffQ, 0, st_fx->L_frame ); - set16_fx( y2_filt, 0, st_fx->L_frame ); + set16_fx( y2_filt, 0, st_fx->L_frame ); /*--------------------------------------------------------------------------------------* * Calculate the difference between the residual spectrum and the spectrum of adaptive excitation * (non valuable temporal content present in exc_dct_in is already zeroed) *--------------------------------------------------------------------------------------*/ - Vr_subt( res_dct_in, exc_dct_in, exc_diff, st_fx->L_frame ); + Vr_subt( res_dct_in, exc_dct_in, exc_diff, st_fx->L_frame ); exc_diff[0] = 0; move16(); @@ -472,7 +480,7 @@ void gsc_enc_fx( move16(); } - Ener_per_band_comp_fx( exc_diff, Ener_per_bd_iQ, Q_exc, MBANDS_GN, 1/*, st_fx->L_frame IVAS_CODE*/ ); + Ener_per_band_comp_fx( exc_diff, Ener_per_bd_iQ, Q_exc, MBANDS_GN, 1 /*, st_fx->L_frame IVAS_CODE*/ ); /*--------------------------------------------------------------------------------------* * Gain quantizaion @@ -480,98 +488,99 @@ void gsc_enc_fx( #if 0 mean_gain = gsc_gainQ_fx(hBstr, Ener_per_bd_iQ, Ener_per_bd_iQ, st_fx->core_brate, st_fx->coder_type, st_fx->bwidth ); #else - i = 0; move16(); - WHILE (LT_16(i, SIZE_BRATE_INTERMED_TBL)) + i = 0; + move16(); + WHILE( LT_16( i, SIZE_BRATE_INTERMED_TBL ) ) { - IF (LE_32(st_fx->core_brate, brate_intermed_tbl[i])) + IF( LE_32( st_fx->core_brate, brate_intermed_tbl[i] ) ) { break; } i++; } - if (GT_16(st_fx->element_mode, EVS_MONO) && EQ_16(st_fx->coder_type, AUDIO) && - LE_32(st_fx->core_brate, STEREO_GSC_BIT_RATE_ALLOC) && EQ_32(brate_intermed_tbl[i], ACELP_9k60)) /* Bit allocation should be mapped to 8 kb/s instead of 9.6 kb/s in this case */ + if ( GT_16( st_fx->element_mode, EVS_MONO ) && EQ_16( st_fx->coder_type, AUDIO ) && + LE_32( st_fx->core_brate, STEREO_GSC_BIT_RATE_ALLOC ) && EQ_32( brate_intermed_tbl[i], ACELP_9k60 ) ) /* Bit allocation should be mapped to 8 kb/s instead of 9.6 kb/s in this case */ { i--; } - mean_gain = gsc_gainQ_fx(hBstr, /*st_fX->element_mode, st_fx->idchan,IVAS_CODE*/ Ener_per_bd_iQ, Ener_per_bd_iQ, brate_intermed_tbl[i], st_fx->coder_type, st_fx->bwidth/*, st_fx->L_frame, st_fx->tdm_LRTD_flag, st_fx->core_brate*/); + mean_gain = gsc_gainQ_fx( hBstr, /*st_fX->element_mode, st_fx->idchan,IVAS_CODE*/ Ener_per_bd_iQ, Ener_per_bd_iQ, brate_intermed_tbl[i], st_fx->coder_type, st_fx->bwidth /*, st_fx->L_frame, st_fx->tdm_LRTD_flag, st_fx->core_brate*/ ); #endif - *tmp_noise = mult_r(320,mean_gain); /*10 in Q5 lp_gainc in Q3 */ + *tmp_noise = mult_r( 320, mean_gain ); /*10 in Q5 lp_gainc in Q3 */ /*--------------------------------------------------------------------------------------* * Frequency encoder *--------------------------------------------------------------------------------------*/ - bands_and_bit_alloc_fx(hGSCEnc->cor_strong_limit, hGSCEnc->noise_lev, st_fx->core_brate, Diff_len, bit, &bit, Ener_per_bd_iQ, + bands_and_bit_alloc_fx( hGSCEnc->cor_strong_limit, hGSCEnc->noise_lev, st_fx->core_brate, Diff_len, bit, &bit, Ener_per_bd_iQ, max_ener_band, bits_per_bands, &nb_subbands, exc_diff, concat_in, &pvq_len, st_fx->coder_type, st_fx->bwidth, - st_fx->GSC_noisy_speech, st_fx->L_frame, st_fx->element_mode, st_fx->GSC_IVAS_mode); + st_fx->GSC_noisy_speech, st_fx->L_frame, st_fx->element_mode, st_fx->GSC_IVAS_mode ); Q_tmp = Q_exc; move16(); - IF (bit == 0) + IF( bit == 0 ) { - set16_fx(concat_out, 0, L_FRAME16k); + set16_fx( concat_out, 0, L_FRAME16k ); } ELSE { - tmp = pvq_core_enc_fx(hBstr, concat_in, concat_out, &Q_tmp, bit, nb_subbands, gsc_sfm_start, gsc_sfm_end, - gsc_sfm_size, bits_per_bands, NULL, inpulses_fx, imaxpulse_fx, ACELP_CORE); - Scale_sig(concat_out, gsc_sfm_end[nb_subbands - 1], sub(Q_PVQ_OUT, Q_tmp)); - bit = sub(bit, tmp); + tmp = pvq_core_enc_fx( hBstr, concat_in, concat_out, &Q_tmp, bit, nb_subbands, gsc_sfm_start, gsc_sfm_end, + gsc_sfm_size, bits_per_bands, NULL, inpulses_fx, imaxpulse_fx, ACELP_CORE ); + Scale_sig( concat_out, gsc_sfm_end[nb_subbands - 1], sub( Q_PVQ_OUT, Q_tmp ) ); + bit = sub( bit, tmp ); } /* write unused bits */ WHILE( bit > 0 ) { i = s_min( bit, 16 ); - push_indice_fx(hBstr, IND_UNUSED, 0, i ); - bit = sub(bit,i); + push_indice_fx( hBstr, IND_UNUSED, 0, i ); + bit = sub( bit, i ); } /* Reorder Q bands */ seed_init = 0; move16(); last_bin = 0; move16(); - set16_fx( bitallocation_band, 0, MBANDS_GN_BITALLOC16k); + set16_fx( bitallocation_band, 0, MBANDS_GN_BITALLOC16k ); #ifdef ADD_LRTD max_eq = 0; max_eq_val = 1.0f; - IF ((((LT_32(st_fx->core_brate, ACELP_7k20) && EQ_16(st_fx->GSC_noisy_speech, 1)) || LT_32(st_fx->core_brate, 6000)) && LE_16(st_fx->coder_type, UNVOICED)) || GE_16(st_fx->GSC_IVAS_mode, 1)) + IF( ( ( ( LT_32( st_fx->core_brate, ACELP_7k20 ) && EQ_16( st_fx->GSC_noisy_speech, 1 ) ) || LT_32( st_fx->core_brate, 6000 ) ) && LE_16( st_fx->coder_type, UNVOICED ) ) || GE_16( st_fx->GSC_IVAS_mode, 1 ) ) { - j = emaximum(concat_out, nb_subbands * 16, &max_eq); - max_eq = max_eq_val / (fabsf(concat_out[j]) + 0.01f); - max_eq = min(max_eq_val, max_eq); + j = emaximum( concat_out, nb_subbands * 16, &max_eq ); + max_eq = max_eq_val / ( fabsf( concat_out[j] ) + 0.01f ); + max_eq = min( max_eq_val, max_eq ); } #endif - FOR(j = 0; j < nb_subbands; j++) + FOR( j = 0; j < nb_subbands; j++ ) { - Copy( concat_out+j*16, exc_diffQ + max_ener_band[j]*16, 16 );/*Q12*/ + Copy( concat_out + j * 16, exc_diffQ + max_ener_band[j] * 16, 16 ); /*Q12*/ - last_bin = s_max(last_bin , max_ener_band[j]); + last_bin = s_max( last_bin, max_ener_band[j] ); - bitallocation_band[ max_ener_band[j]] = 1; + bitallocation_band[max_ener_band[j]] = 1; move16(); - seed_init = add(seed_init,inpulses_fx[j]); + seed_init = add( seed_init, inpulses_fx[j] ); move16(); } test(); - IF( NE_16(st_fx->last_coder_type, AUDIO) /* First audio frame */ - && NE_16(st_fx->last_coder_type, UNVOICED) )/* last_coder_type == INACTIVE is overwritten in update_enc to UNVOICED */ + IF( NE_16( st_fx->last_coder_type, AUDIO ) /* First audio frame */ + && NE_16( st_fx->last_coder_type, UNVOICED ) ) /* last_coder_type == INACTIVE is overwritten in update_enc to UNVOICED */ { - FOR( j = 0; j < shl(nb_subbands,4); j++ ) + FOR( j = 0; j < shl( nb_subbands, 4 ); j++ ) { IF( concat_out[j] > 0 ) { - seed_init = extract_l(L_shl(seed_init,3)); + seed_init = extract_l( L_shl( seed_init, 3 ) ); } IF( concat_out[j] < 0 ) { - seed_init = add(seed_init,3); + seed_init = add( seed_init, 3 ); move16(); } } @@ -579,18 +588,18 @@ void gsc_enc_fx( move16(); } test(); - IF( EQ_32(st_fx->core_brate,ACELP_8k00)&&NE_16(st_fx->bwidth,NB)) + IF( EQ_32( st_fx->core_brate, ACELP_8k00 ) && NE_16( st_fx->bwidth, NB ) ) { bitallocation_exc[0] = 0; move16(); bitallocation_exc[1] = 0; move16(); - if( exc_diffQ[L_FRAME8k - 2] != 0 ) + if ( exc_diffQ[L_FRAME8k - 2] != 0 ) { bitallocation_exc[0] = 1; move16(); } - if( exc_diffQ[L_FRAME8k - 1] != 0 ) + if ( exc_diffQ[L_FRAME8k - 1] != 0 ) { bitallocation_exc[1] = 1; move16(); @@ -603,17 +612,19 @@ void gsc_enc_fx( * Gain is based on the inter-correlation gain between the pulses found and residual signal *--------------------------------------------------------------------------------------*/ #ifdef ADD_LRTD - test();test();test(); - IF (GE_16(st_fx->GSC_IVAS_mode, 1) && EQ_16(st_fx->GSC_noisy_speech, 1)) + test(); + test(); + test(); + IF( GE_16( st_fx->GSC_IVAS_mode, 1 ) && EQ_16( st_fx->GSC_noisy_speech, 1 ) ) { - FOR (i = 64; i < st->L_frame; i++) + FOR( i = 64; i < st->L_frame; i++ ) { exc_diffQ[i] *= max_eq; } } - ELSE IF (LT_32(st_fx->core_brate, ACELP_7k20) && EQ_16(st_fx->GSC_noisy_speech, 1) && LE_16(st_fx->coder_type, UNVOICED)) + ELSE IF( LT_32( st_fx->core_brate, ACELP_7k20 ) && EQ_16( st_fx->GSC_noisy_speech, 1 ) && LE_16( st_fx->coder_type, UNVOICED ) ) { - FOR (i = 0; i < L_FRAME; i++) + FOR( i = 0; i < L_FRAME; i++ ) { exc_diffQ[i] *= max_eq; } @@ -621,7 +632,7 @@ void gsc_enc_fx( else #endif { - freq_dnw_scaling_fx(hGSCEnc->cor_strong_limit, st_fx->coder_type, hGSCEnc->noise_lev, st_fx->core_brate, exc_diffQ, Q_PVQ_OUT, st_fx->L_frame); + freq_dnw_scaling_fx( hGSCEnc->cor_strong_limit, st_fx->coder_type, hGSCEnc->noise_lev, st_fx->core_brate, exc_diffQ, Q_PVQ_OUT, st_fx->L_frame ); } /*--------------------------------------------------------------------------------------* * Estimate noise level @@ -629,8 +640,8 @@ void gsc_enc_fx( highband_exc_dct_in_fx( st_fx->core_brate, mfreq_bindiv_loc, last_bin, Diff_len, hGSCEnc->noise_lev, tmp_band, exc_diffQ, &hGSCEnc->seed_tcx, Ener_per_bd_iQ, nb_subfr, exc_dct_in, st_fx->last_coder_type, bitallocation_band, lsf_new, - hGSCEnc->last_exc_dct_in_fx, &st_fx->last_ener_fx, hGSCEnc->last_bitallocation_band, bitallocation_exc, 0, st_fx->coder_type, - st_fx->bwidth, exc_wo_nf, Q_PVQ_OUT, Q_exc, st_fx->GSC_noisy_speech, NULL, st_fx->L_frame, st_fx->element_mode, st_fx->GSC_IVAS_mode); + hGSCEnc->last_exc_dct_in_fx, &st_fx->last_ener_fx, hGSCEnc->last_bitallocation_band, bitallocation_exc, 0, st_fx->coder_type, + st_fx->bwidth, exc_wo_nf, Q_PVQ_OUT, Q_exc, st_fx->GSC_noisy_speech, NULL, st_fx->L_frame, st_fx->element_mode, st_fx->GSC_IVAS_mode ); exc_dct_in[0] = 0; move16(); @@ -659,61 +670,60 @@ void gsc_enc_fx( /* _ None */ /*=======================================================================*/ -static Word16 edyn_fx( /* o : ratio of max to mean */ - const Word16 *vec, /* i : input vector */ - const Word16 lvec, /* i : length of input vector */ - Word16 Qnew -) +static Word16 edyn_fx( /* o : ratio of max to mean */ + const Word16 *vec, /* i : input vector */ + const Word16 lvec, /* i : length of input vector */ + Word16 Qnew ) { - Word16 j=0; + Word16 j = 0; Word16 dyn; Word32 L_tmp, ener_max, ener_mean; - Word16 tmp,exp2,tmp2,tmp1,exp1,exp3; + Word16 tmp, exp2, tmp2, tmp1, exp1, exp3; Word16 scale; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - ener_mean = L_shl(1,shl(Qnew,1)); /*2*Qnew*/ - ener_max = L_shl(1,shl(Qnew,1)); + ener_mean = L_shl( 1, shl( Qnew, 1 ) ); /*2*Qnew*/ + ener_max = L_shl( 1, shl( Qnew, 1 ) ); - FOR( j=0; j 0) + IF( ener_mean > 0 ) { - exp1 = norm_l(ener_mean); + exp1 = norm_l( ener_mean ); #ifdef BASOP_NOGLOB - tmp1 = round_fx_o(L_shl(ener_mean,exp1), &Overflow); + tmp1 = round_fx_o( L_shl( ener_mean, exp1 ), &Overflow ); #else /* BASOP_NOGLOB */ - tmp1 = round_fx(L_shl(ener_mean,exp1)); + tmp1 = round_fx( L_shl( ener_mean, exp1 ) ); #endif - exp1 = sub(30,exp1); + exp1 = sub( 30, exp1 ); - exp2 = norm_l(ener_max); - tmp2 = extract_h(L_shl(ener_max,exp2)); - exp2 = sub(30,exp2); + exp2 = norm_l( ener_max ); + tmp2 = extract_h( L_shl( ener_max, exp2 ) ); + exp2 = sub( 30, exp2 ); - scale = shr(sub(tmp1, tmp2), 15); - tmp2 = shl(tmp2, scale); - exp2 = sub(exp2, scale); + scale = shr( sub( tmp1, tmp2 ), 15 ); + tmp2 = shl( tmp2, scale ); + exp2 = sub( exp2, scale ); - exp3 = sub(exp1,exp2); + exp3 = sub( exp1, exp2 ); - tmp = div_s(tmp2, tmp1); /*Q(15+exp3)*/ + tmp = div_s( tmp2, tmp1 ); /*Q(15+exp3)*/ - L_tmp = L_shr_r(L_mult(tmp,10),exp3); - dyn = round_fx(L_shl(L_tmp,7)); /*Q7*/ + L_tmp = L_shr_r( L_mult( tmp, 10 ), exp3 ); + dyn = round_fx( L_shl( L_tmp, 7 ) ); /*Q7*/ } ELSE { @@ -721,7 +731,6 @@ static Word16 edyn_fx( /* o : ratio of max to mean */ move16(); } return dyn; - } @@ -740,9 +749,9 @@ void GSC_enc_init_fx( move16(); hGSCEnc->cor_strong_limit = 1; move16(); - set16_fx(hGSCEnc->last_exc_dct_in_fx, 0, L_FRAME16k); - //hGSCEnc->last_ener = 0.0f; IVAS_CODE - set16_fx(hGSCEnc->last_bitallocation_band, 0, 6); + set16_fx( hGSCEnc->last_exc_dct_in_fx, 0, L_FRAME16k ); + // hGSCEnc->last_ener = 0.0f; IVAS_CODE + set16_fx( hGSCEnc->last_bitallocation_band, 0, 6 ); hGSCEnc->mem_last_pit_band = BAND1k2 + 1; hGSCEnc->Last_frame_ener_fx = MAX_32; @@ -756,7 +765,7 @@ void GSC_enc_init_fx( hGSCEnc->mem_w0_tmp_fx = 0; move16(); - set16_fx(hGSCEnc->mem_syn_tmp_fx, 0, M); + set16_fx( hGSCEnc->mem_syn_tmp_fx, 0, M ); hGSCEnc->mid_dyn_fx = 5120; move16(); /*40 -> Q7 */ hGSCEnc->noise_lev = NOISE_LEVEL_SP0; diff --git a/lib_enc/guided_plc_enc_fx.c b/lib_enc/guided_plc_enc_fx.c index a387d0387..aebdfb748 100644 --- a/lib_enc/guided_plc_enc_fx.c +++ b/lib_enc/guided_plc_enc_fx.c @@ -7,9 +7,9 @@ #include "options.h" #include "cnst.h" //#include "prot_fx.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ #include "stat_enc.h" #include "basop_util.h" @@ -20,26 +20,25 @@ * *-------------------------------------------------------------------*/ static void coderLookAheadInnovation( - Word16 A_3Q12[], /* input: coefficients NxAz[M+1] */ - Word16 *pT, /* out: pitch */ - PLC_ENC_EVS_HANDLE st, /* i/o: coder memory state */ - Word16 *speechLookAhead_Qx, /* i: input speech in Q(st->Qold) */ - Word16 *old_exc, /* i: input excitation in Q(st->Qold) */ - Word16 L_frame -) + Word16 A_3Q12[], /* input: coefficients NxAz[M+1] */ + Word16 *pT, /* out: pitch */ + PLC_ENC_EVS_HANDLE st, /* i/o: coder memory state */ + Word16 *speechLookAhead_Qx, /* i: input speech in Q(st->Qold) */ + Word16 *old_exc, /* i: input excitation in Q(st->Qold) */ + Word16 L_frame ) { Word16 i; Word16 prev_pitch, T0_fx; - Word16 *exc_Qx, exc_buf_Qx[L_EXC_MEM+2*L_SUBFR+8]; + Word16 *exc_Qx, exc_buf_Qx[L_EXC_MEM + 2 * L_SUBFR + 8]; Word32 mantissa_max = -0x7fffffffL; Word16 subfr_len = 0; Word16 search_range = 9; Word16 exc_max; Word16 exc_sh; - Word32 ps,alp, alp_ini; + Word32 ps, alp, alp_ini; Word32 alp_s1, alp_s2; Word16 k; - Word16 ps_e,alp_e; + Word16 ps_e, alp_e; Word32 max_ps, max_ps_tmp; Word16 max_ps_e; Word16 tmp_loop; @@ -50,19 +49,19 @@ static void coderLookAheadInnovation( /* Debug init (not instrumented) */ T0_fx = -3000; - subfr_len = shl(L_SUBFR,1); /* 2*L_SUBFR */ - if( GT_16( L_FRAME16k, L_frame )) + subfr_len = shl( L_SUBFR, 1 ); /* 2*L_SUBFR */ + if ( GT_16( L_FRAME16k, L_frame ) ) { - subfr_len = add(L_SUBFR,48); /* 1.75*L_SUBFR */ + subfr_len = add( L_SUBFR, 48 ); /* 1.75*L_SUBFR */ } - set16_fx(exc_buf_Qx, 0, L_EXC_MEM + 2 * L_SUBFR + 8); + set16_fx( exc_buf_Qx, 0, L_EXC_MEM + 2 * L_SUBFR + 8 ); /*------------------------------------------------------------------------* * - BASOP specific initialization. * *------------------------------------------------------------------------*/ /* initialization */ exc_Qx = exc_buf_Qx + L_EXC_MEM + 8; - FOR( i=0; ipit_max)||LT_16(add(prev_pitch,i),st->pit_min)) + IF( GT_16( add( prev_pitch, i ), st->pit_max ) || LT_16( add( prev_pitch, i ), st->pit_min ) ) { CONTINUE; } - ps = L_deposit_l(0); - alp_s1 = L_deposit_l(0); - alp_s2 = L_deposit_l(0); + ps = L_deposit_l( 0 ); + alp_s1 = L_deposit_l( 0 ); + alp_s2 = L_deposit_l( 0 ); - FOR(k=0; kT0_4th; move16(); @@ -204,9 +202,8 @@ static void coderLookAheadInnovation( * *-------------------------------------------------------------------*/ void enc_prm_side_Info_fx( - PLC_ENC_EVS_HANDLE hPlc_Ext, - Encoder_State *st -) + PLC_ENC_EVS_HANDLE hPlc_Ext, + Encoder_State *st ) { Word16 diff_pitch; Word16 bits_per_subfr, search_range; @@ -216,24 +213,24 @@ void enc_prm_side_Info_fx( search_range = 8; move16(); - IF( GT_16(hPlc_Ext->nBits,1)) + IF( GT_16( hPlc_Ext->nBits, 1 ) ) { - push_next_indice_fx(st->hBstr, 1, 1); + push_next_indice_fx( st->hBstr, 1, 1 ); - diff_pitch = sub(hPlc_Ext->T0, hPlc_Ext->T0_4th); + diff_pitch = sub( hPlc_Ext->T0, hPlc_Ext->T0_4th ); test(); - if( (GT_16(diff_pitch,sub(search_range,1)))||(LT_16(diff_pitch,add(-search_range,1)))) + if ( ( GT_16( diff_pitch, sub( search_range, 1 ) ) ) || ( LT_16( diff_pitch, add( -search_range, 1 ) ) ) ) { diff_pitch = -8; move16(); } - push_next_indice_fx(st->hBstr, add(diff_pitch, search_range), bits_per_subfr); + push_next_indice_fx( st->hBstr, add( diff_pitch, search_range ), bits_per_subfr ); } ELSE { - push_next_indice_fx(st->hBstr, 0, 1); + push_next_indice_fx( st->hBstr, 0, 1 ); } return; @@ -247,18 +244,17 @@ void enc_prm_side_Info_fx( void encoderSideLossSimulation_fx( Encoder_State *st, PLC_ENC_EVS_HANDLE hPlc_Ext, - Word16 *lsf_q, /* Q1*1.28 */ - const Word16 stab_fac, /* Q15 */ + Word16 *lsf_q, /* Q1*1.28 */ + const Word16 stab_fac, /* Q15 */ const Word16 calcOnlyISF, - const Word16 L_frame -) + const Word16 L_frame ) { Word16 lspLocal_Q15[M]; - Word16 const* xsfBase; /* base for differential XSF coding */ + Word16 const *xsfBase; /* base for differential XSF coding */ /* Decoder State Update */ - IF( EQ_16(L_frame,L_FRAME_16k)) + IF( EQ_16( L_frame, L_FRAME_16k ) ) { lsf2lsp_fx( lsf_q, lspLocal_Q15, M, INT_FS_16k_FX ); } @@ -268,16 +264,16 @@ void encoderSideLossSimulation_fx( } - xsfBase = PlcGetLsfBase (st->lpcQuantization, + xsfBase = PlcGetLsfBase( st->lpcQuantization, st->narrowBand, - st->sr_core); + st->sr_core ); Copy( st->mem_MA_fx, hPlc_Ext->mem_MA_14Q1, M ); Copy( st->mem_AR_fx, hPlc_Ext->mem_AR, M ); /* ISF parameter processing for concealment */ - updateLSFForConcealment( hPlc_Ext, lsf_q); + updateLSFForConcealment( hPlc_Ext, lsf_q ); hPlc_Ext->stab_fac_Q15 = stab_fac; move16(); @@ -285,7 +281,7 @@ void encoderSideLossSimulation_fx( Copy( lspLocal_Q15, hPlc_Ext->lspold_Q15, M ); - IF (calcOnlyISF != 0) + IF( calcOnlyISF != 0 ) { /* ISF concealment simulation */ getConcealedLSF( hPlc_Ext, xsfBase, st->clas, L_frame ); @@ -294,12 +290,12 @@ void encoderSideLossSimulation_fx( } ELSE { - Word16 old_exc_Qx[L_EXC_MEM+8]; - Word16 A_3Q12[(NB_SUBFR16k+1)*(M+1)]; + Word16 old_exc_Qx[L_EXC_MEM + 8]; + Word16 A_3Q12[( NB_SUBFR16k + 1 ) * ( M + 1 )]; Word16 *speechLookAhead_Qx; /* calculate Q-value for input speech */ - speechLookAhead_Qx = &(st->speech_enc_pe[L_frame]); + speechLookAhead_Qx = &( st->speech_enc_pe[L_frame] ); Copy( hPlc_Ext->old_exc_Qold, old_exc_Qx, 8 ); Copy( hPlc_Ext->LPDmem->old_exc, &old_exc_Qx[8], L_EXC_MEM ); @@ -313,7 +309,7 @@ void encoderSideLossSimulation_fx( move16(); hPlc_Ext->pit_max = st->pit_max; move16(); - coderLookAheadInnovation( A_3Q12, &(hPlc_Ext->T0), hPlc_Ext, speechLookAhead_Qx, old_exc_Qx, L_frame ); + coderLookAheadInnovation( A_3Q12, &( hPlc_Ext->T0 ), hPlc_Ext, speechLookAhead_Qx, old_exc_Qx, L_frame ); } return; } @@ -325,20 +321,19 @@ void encoderSideLossSimulation_fx( *-------------------------------------------------------------------*/ void GplcTcxEncSetup_fx( - Encoder_State *st, - PLC_ENC_EVS_HANDLE hPlc_Ext, - Word16 Q_new -) + Encoder_State *st, + PLC_ENC_EVS_HANDLE hPlc_Ext, + Word16 Q_new ) { TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; hPlc_Ext->T0_4th = hTcxEnc->tcxltp_pitch_int; move16(); - hPlc_Ext->Q_exp = sub( Q_new, hPlc_Ext->Q_new); + hPlc_Ext->Q_exp = sub( Q_new, hPlc_Ext->Q_new ); move16(); hPlc_Ext->Q_new = Q_new; move16(); - set16_fx( hPlc_Ext->old_exc_Qold, 0, 8); + set16_fx( hPlc_Ext->old_exc_Qold, 0, 8 ); } /*-------------------------------------------------------------------* * encSideSpecPowDiffuseDetector_fx() @@ -351,8 +346,7 @@ Word16 encSideSpecPowDiffuseDetector_fx( const Word32 sr_core, Word16 *prev_lsf4_mean, const Word8 sw, - const Word16 coder_type -) + const Word16 coder_type ) { Word16 tmp; Word16 lsf_mod[M]; @@ -366,16 +360,16 @@ Word16 encSideSpecPowDiffuseDetector_fx( /* calculate the mean of the lowest 4 LSFs */ - L_tmp = L_mult(lsf_ref[0], 8192/*1.0/4.0 Q15*/); - L_tmp = L_mac(L_tmp, lsf_ref[1], 8192/*1.0/4.0 Q15*/); - L_tmp = L_mac(L_tmp, lsf_ref[2], 8192/*1.0/4.0 Q15*/); - lsf4_mean = mac_r(L_tmp, lsf_ref[3], 8192/*1.0/4.0 Q15*/); + L_tmp = L_mult( lsf_ref[0], 8192 /*1.0/4.0 Q15*/ ); + L_tmp = L_mac( L_tmp, lsf_ref[1], 8192 /*1.0/4.0 Q15*/ ); + L_tmp = L_mac( L_tmp, lsf_ref[2], 8192 /*1.0/4.0 Q15*/ ); + lsf4_mean = mac_r( L_tmp, lsf_ref[3], 8192 /*1.0/4.0 Q15*/ ); - IF(sw) + IF( sw ) { - Copy(lsf_con, lsf_mod, M); + Copy( lsf_con, lsf_mod, M ); - modify_lsf(lsf_mod, M, sr_core, 1 ); + modify_lsf( lsf_mod, M, sr_core, 1 ); move16(); move16(); @@ -384,7 +378,7 @@ Word16 encSideSpecPowDiffuseDetector_fx( cnt_imprv = 0; - IF( EQ_32( sr_core, INT_FS_16k)) + IF( EQ_32( sr_core, INT_FS_16k ) ) { th = 2560; move16(); /* LSF */ @@ -399,19 +393,19 @@ Word16 encSideSpecPowDiffuseDetector_fx( move16(); /* LSF */ } - FOR(i = 0; i < M; i++) + FOR( i = 0; i < M; i++ ) { - tmp = sub(lsf_con[i], lsf_ref[i]); - dist1 = L_mult(tmp, tmp); - tmp = sub(lsf_mod[i], lsf_ref[i]); - dist2 = L_mult(tmp, tmp); + tmp = sub( lsf_con[i], lsf_ref[i] ); + dist1 = L_mult( tmp, tmp ); + tmp = sub( lsf_mod[i], lsf_ref[i] ); + dist2 = L_mult( tmp, tmp ); - if(GT_32(dist1, dist2)) + if ( GT_32( dist1, dist2 ) ) { - cnt_imprv = add(cnt_imprv, 1); + cnt_imprv = add( cnt_imprv, 1 ); } - cum_dist1 = L_add(cum_dist1, dist1); - cum_dist2 = L_add(cum_dist2, dist2); + cum_dist1 = L_add( cum_dist1, dist1 ); + cum_dist2 = L_add( cum_dist2, dist2 ); } idx = 0; @@ -420,16 +414,11 @@ Word16 encSideSpecPowDiffuseDetector_fx( test(); test(); test(); - if(GT_32(cum_dist1, L_add(cum_dist2, Mpy_32_16_1(cum_dist2, 4915))) - && GT_16(sub(lsf4_mean, *prev_lsf4_mean), th_dif) - && LT_16(*prev_lsf4_mean, th) - && GT_16(cnt_imprv, 2) - && EQ_16(coder_type, GENERIC) ) + if ( GT_32( cum_dist1, L_add( cum_dist2, Mpy_32_16_1( cum_dist2, 4915 ) ) ) && GT_16( sub( lsf4_mean, *prev_lsf4_mean ), th_dif ) && LT_16( *prev_lsf4_mean, th ) && GT_16( cnt_imprv, 2 ) && EQ_16( coder_type, GENERIC ) ) { idx = 1; move16(); } - } ELSE { @@ -448,8 +437,7 @@ Word16 encSideSpecPowDiffuseDetector_fx( * *-------------------------------------------------------------------*/ void updateSpecPowDiffuseIdx_fx( - Encoder_State *st -) + Encoder_State *st ) { Word16 min_gp; Word16 k; @@ -463,28 +451,27 @@ void updateSpecPowDiffuseIdx_fx( st->mean_gc[1] = st->gain_code[0]; min_gp = st->bpf_gainT[0]; - FOR(k = 1; k < 4; k++) + FOR( k = 1; k < 4; k++ ) { #ifdef BASOP_NOGLOB - st->mean_gc[1] = L_add_o(st->mean_gc[1], st->gain_code[k], &Overflow); + st->mean_gc[1] = L_add_o( st->mean_gc[1], st->gain_code[k], &Overflow ); #else /* BASOP_NOGLOB */ - st->mean_gc[1] = L_add(st->mean_gc[1], st->gain_code[k]); + st->mean_gc[1] = L_add( st->mean_gc[1], st->gain_code[k] ); #endif - min_gp = s_min(min_gp, st->bpf_gainT[k]); + min_gp = s_min( min_gp, st->bpf_gainT[k] ); } /* Suppress saturation warning in threshold comparison. */ test(); #ifdef BASOP_NOGLOB - if(LT_32(st->mean_gc[1], L_add_o(st->mean_gc[0], Mpy_32_16_r(st->mean_gc[0], 3211/*0.098 Q15*/), &Overflow))||GT_16(min_gp, 13435/*0.82 Q14*/)) + if ( LT_32( st->mean_gc[1], L_add_o( st->mean_gc[0], Mpy_32_16_r( st->mean_gc[0], 3211 /*0.098 Q15*/ ), &Overflow ) ) || GT_16( min_gp, 13435 /*0.82 Q14*/ ) ) #else - if(LT_32(st->mean_gc[1], L_add(st->mean_gc[0], Mpy_32_16_r(st->mean_gc[0], 3211/*0.098 Q15*/)))||GT_16(min_gp, 13435/*0.82 Q14*/)) + if ( LT_32( st->mean_gc[1], L_add( st->mean_gc[0], Mpy_32_16_r( st->mean_gc[0], 3211 /*0.098 Q15*/ ) ) ) || GT_16( min_gp, 13435 /*0.82 Q14*/ ) ) #endif { move16(); - st->glr_idx [0]= 0; + st->glr_idx[0] = 0; } move16(); st->mean_gc[0] = st->mean_gc[1]; - } diff --git a/lib_enc/hf_cod_amrwb_fx.c b/lib_enc/hf_cod_amrwb_fx.c index 20a1296f9..0fa53be51 100644 --- a/lib_enc/hf_cod_amrwb_fx.c +++ b/lib_enc/hf_cod_amrwb_fx.c @@ -2,34 +2,34 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ //#include "prot_fx.h" #include "rom_com_fx.h" #include "cnst.h" #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ -#include "basop_util.h" /* Function prototypes */ - - /*---------------------------------------------------------------------* - * hf_cod_init() - * - * - *---------------------------------------------------------------------*/ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ +#include "basop_util.h" /* Function prototypes */ + +/*---------------------------------------------------------------------* + * hf_cod_init() + * + * + *---------------------------------------------------------------------*/ void hf_cod_init_fx( - Word16 *mem_hp400_enc, /* o: memory of hp 400 Hz filter */ - Word16 *mem_hf1_enc, /* o: HF band-pass filter memory */ - Word16 *mem_syn_hf_enc, /* o: HF synthesis memory */ - Word16 *mem_hf2_enc, /* o: HF band-pass filter memory */ - Word16 *gain_alpha_fx /* o: smoothing gain for transitions between active and inactive frames */ + Word16 *mem_hp400_enc, /* o: memory of hp 400 Hz filter */ + Word16 *mem_hf1_enc, /* o: HF band-pass filter memory */ + Word16 *mem_syn_hf_enc, /* o: HF synthesis memory */ + Word16 *mem_hf2_enc, /* o: HF band-pass filter memory */ + Word16 *gain_alpha_fx /* o: smoothing gain for transitions between active and inactive frames */ ) { - set16_fx( mem_hp400_enc, 0, 6); - set16_fx( mem_hf1_enc, 0, L_FIR-1 ); + set16_fx( mem_hp400_enc, 0, 6 ); + set16_fx( mem_hf1_enc, 0, L_FIR - 1 ); set16_fx( mem_syn_hf_enc, 0, M ); - set16_fx( mem_hf2_enc, 0, L_FIR-1 ); + set16_fx( mem_hf2_enc, 0, L_FIR - 1 ); *gain_alpha_fx = 16384; move16(); @@ -44,22 +44,21 @@ void hf_cod_init_fx( *---------------------------------------------------------------------*/ void hf_cod_fx( - const Word32 core_brate_fx, /* i : core bitrate */ - const Word16 *speech16k_fx, /* i : original speech at 16 kHz */ - const Word16 Aq_fx[], /* i : quantized Aq */ - const Word16 exc_fx[], /* i : excitation at 12.8 kHz */ - Word16 synth_fx[], /* i : 12.8kHz synthesis signal */ - Word16 *seed2_enc_fx, /* i/o: random seed for HF noise gen */ - Word16 *mem_hp400_enc_fx, /* i/o: memory of hp 400 Hz filter */ - Word16 *mem_syn_hf_enc_fx, /* i/o: HF synthesis memory */ - Word16 *mem_hf1_enc_fx, /* i/o: HF band-pass filter memory */ - Word16 *mem_hf2_enc_fx, /* i/o: HF band-pass filter memory */ + const Word32 core_brate_fx, /* i : core bitrate */ + const Word16 *speech16k_fx, /* i : original speech at 16 kHz */ + const Word16 Aq_fx[], /* i : quantized Aq */ + const Word16 exc_fx[], /* i : excitation at 12.8 kHz */ + Word16 synth_fx[], /* i : 12.8kHz synthesis signal */ + Word16 *seed2_enc_fx, /* i/o: random seed for HF noise gen */ + Word16 *mem_hp400_enc_fx, /* i/o: memory of hp 400 Hz filter */ + Word16 *mem_syn_hf_enc_fx, /* i/o: HF synthesis memory */ + Word16 *mem_hf1_enc_fx, /* i/o: HF band-pass filter memory */ + Word16 *mem_hf2_enc_fx, /* i/o: HF band-pass filter memory */ const Word16 dtxHangoverCount_fx, - Word16 *gain_alpha_fx, /* i/o: smoothing gain for transitions between active and inactive frames */ - Word16 *hf_gain_fx, /* o : HF gain to be transmitted to decoder */ + Word16 *gain_alpha_fx, /* i/o: smoothing gain for transitions between active and inactive frames */ + Word16 *hf_gain_fx, /* o : HF gain to be transmitted to decoder */ Word16 Q_exc, - Word16 Q_syn -) + Word16 Q_syn ) { /*------------------------Scaling------------------------------------------------- speech16k - Q0 @@ -80,11 +79,11 @@ void hf_cod_fx( Word16 i, q1, q2, sign; Word16 shift; Word16 ener_hf_fx, ener_exc_fx, ener_input_fx, fac_fx, tmp_fx, ener_fx, scale_fx; - Word16 Ap_fx[M+1]; + Word16 Ap_fx[M + 1]; Word16 HF_SP_fx[L_SUBFR16k]; Word16 HF_est_gain_fx, HF_calc_gain_fx, HF_corr_gain_fx, HF_gain_ind_fx; Word32 dist_min_fx, dist_fx; - Word16 HF_fx[L_SUBFR16k], HF_syn_fx[L_SUBFR16k]; /* o : HF excitation */ + Word16 HF_fx[L_SUBFR16k], HF_syn_fx[L_SUBFR16k]; /* o : HF excitation */ Word32 L_tmp; Word16 *pt1; const Word16 *pt2; @@ -93,135 +92,135 @@ void hf_cod_fx( #endif /* Original speech signal as reference for high band gain quantisation */ - Copy(speech16k_fx, HF_SP_fx, L_SUBFR16k); + Copy( speech16k_fx, HF_SP_fx, L_SUBFR16k ); /*-----------------------------------------------------------------* - * generate white noise vector - *-----------------------------------------------------------------*/ + * generate white noise vector + *-----------------------------------------------------------------*/ - Random_Fill(seed2_enc_fx, L_SUBFR16k, HF_fx, 3); /*Q(-3) */ + Random_Fill( seed2_enc_fx, L_SUBFR16k, HF_fx, 3 ); /*Q(-3) */ /*-----------------------------------------------------------------* - * calculate energy scaling factor so that white noise would have the - * same energy as exc12k8 - *-----------------------------------------------------------------*/ + * calculate energy scaling factor so that white noise would have the + * same energy as exc12k8 + *-----------------------------------------------------------------*/ - ener_exc_fx = dot_prod_satcontr(exc_fx, exc_fx, Q_exc, Q_exc, &q1, L_SUBFR); - ener_hf_fx = dot_prod_satcontr(HF_fx, HF_fx, -3, -3, &q2, L_SUBFR16k); + ener_exc_fx = dot_prod_satcontr( exc_fx, exc_fx, Q_exc, Q_exc, &q1, L_SUBFR ); + ener_hf_fx = dot_prod_satcontr( HF_fx, HF_fx, -3, -3, &q2, L_SUBFR16k ); - scale_fx = div_s(shl(1, 14), ener_exc_fx); /*Q(29-q1) */ - L_tmp = L_mult(ener_hf_fx, scale_fx); /*30-q1+q2 */ - q2 = sub(q1, q2); /*30-q2 */ + scale_fx = div_s( shl( 1, 14 ), ener_exc_fx ); /*Q(29-q1) */ + L_tmp = L_mult( ener_hf_fx, scale_fx ); /*30-q1+q2 */ + q2 = sub( q1, q2 ); /*30-q2 */ #ifdef BASOP_NOGLOB - scale_fx = round_fx(Isqrt(L_shl_o(L_tmp, sub(q2, 26), &Overflow))); /*Q13 */ -#else /* BASOP_NOGLOB */ - scale_fx = round_fx(Isqrt(L_shl(L_tmp, sub(q2, 26)))); /*Q13 */ -#endif /* BASOP_NOGLOB */ + scale_fx = round_fx( Isqrt( L_shl_o( L_tmp, sub( q2, 26 ), &Overflow ) ) ); /*Q13 */ +#else /* BASOP_NOGLOB */ + scale_fx = round_fx( Isqrt( L_shl( L_tmp, sub( q2, 26 ) ) ) ); /*Q13 */ +#endif /* BASOP_NOGLOB */ pt1 = HF_fx; FOR( i = 0; i < L_SUBFR16k; i++ ) { - *pt1 = round_fx(L_shl(L_mult((*pt1), scale_fx), 5)); /*Q0 */ + *pt1 = round_fx( L_shl( L_mult( ( *pt1 ), scale_fx ), 5 ) ); /*Q0 */ pt1++; } /*-----------------------------------------------------------------* - * calculate energy scaling factor to respect tilt of synth12k8 - * (tilt: 1=voiced, -1=unvoiced) - *-----------------------------------------------------------------*/ + * calculate energy scaling factor to respect tilt of synth12k8 + * (tilt: 1=voiced, -1=unvoiced) + *-----------------------------------------------------------------*/ hp400_12k8_fx( synth_fx, L_SUBFR, mem_hp400_enc_fx ); /*synth_fx: Q(Q_syn-4) */ - ener_fx = dot_prod_satcontr(&synth_fx[1], &synth_fx[1], sub(Q_syn, 4), sub(Q_syn, 4), &q1, sub(L_SUBFR, 1)); - tmp_fx = dot_prod_satcontr(&synth_fx[1], synth_fx, sub(Q_syn ,4), sub(Q_syn, 4), &q2, sub(L_SUBFR, 1)); + ener_fx = dot_prod_satcontr( &synth_fx[1], &synth_fx[1], sub( Q_syn, 4 ), sub( Q_syn, 4 ), &q1, sub( L_SUBFR, 1 ) ); + tmp_fx = dot_prod_satcontr( &synth_fx[1], synth_fx, sub( Q_syn, 4 ), sub( Q_syn, 4 ), &q2, sub( L_SUBFR, 1 ) ); - IF ( GE_16(abs_s(tmp_fx), ener_fx )) + IF( GE_16( abs_s( tmp_fx ), ener_fx ) ) { - tmp_fx = shr(tmp_fx, 1); - q2 = sub(q2, 1); + tmp_fx = shr( tmp_fx, 1 ); + q2 = sub( q2, 1 ); } sign = 0; move16(); - IF ( tmp_fx < 0 ) + IF( tmp_fx < 0 ) { - tmp_fx = abs_s(tmp_fx); + tmp_fx = abs_s( tmp_fx ); sign = 1; move16(); } - fac_fx = div_s(tmp_fx, ener_fx); /*Q(15+q2-q1) */ - shift = sub(q1, add(q2, 5)); - fac_fx = shl(fac_fx, shift); /*Q10 */ - IF (sign) + fac_fx = div_s( tmp_fx, ener_fx ); /*Q(15+q2-q1) */ + shift = sub( q1, add( q2, 5 ) ); + fac_fx = shl( fac_fx, shift ); /*Q10 */ + IF( sign ) { - fac_fx = s_xor(fac_fx, -1); + fac_fx = s_xor( fac_fx, -1 ); } - HF_est_gain_fx = sub(1024, fac_fx); /*Q12 */ + HF_est_gain_fx = sub( 1024, fac_fx ); /*Q12 */ test(); - IF( EQ_32(core_brate_fx, SID_1k75)||core_brate_fx==FRAME_NO_DATA) + IF( EQ_32( core_brate_fx, SID_1k75 ) || core_brate_fx == FRAME_NO_DATA ) { - HF_est_gain_fx = round_fx(L_shl(L_mult(HF_est_gain_fx, 20480), 1)); /*Q10 */ + HF_est_gain_fx = round_fx( L_shl( L_mult( HF_est_gain_fx, 20480 ), 1 ) ); /*Q10 */ } - HF_est_gain_fx = s_max(HF_est_gain_fx, 102); - HF_est_gain_fx = s_min(HF_est_gain_fx, 1024); + HF_est_gain_fx = s_max( HF_est_gain_fx, 102 ); + HF_est_gain_fx = s_min( HF_est_gain_fx, 1024 ); /*-----------------------------------------------------------------* - * synthesis of noise: 4.8kHz..5.6kHz --> 6kHz..7kHz - *-----------------------------------------------------------------*/ + * synthesis of noise: 4.8kHz..5.6kHz --> 6kHz..7kHz + *-----------------------------------------------------------------*/ weight_a_lc_fx( Aq_fx, Ap_fx, Gamma_19661_Tbl_fx, M ); Syn_filt_s( 0, Ap_fx, M, HF_fx, HF_syn_fx, L_SUBFR16k, mem_syn_hf_enc_fx, 1 ); /*Q0 */ /*-----------------------------------------------------------------* - * high pass filtering (0.9375ms of delay = 15 samples@16k) - *-----------------------------------------------------------------*/ + * high pass filtering (0.9375ms of delay = 15 samples@16k) + *-----------------------------------------------------------------*/ - fir_fx(HF_syn_fx, fir_6k_8k_fx, HF_syn_fx, mem_hf1_enc_fx, L_SUBFR16k, L_FIR-1, 1, 0); - fir_fx(HF_SP_fx, fir_6k_8k_fx, HF_SP_fx, mem_hf2_enc_fx, L_SUBFR16k, L_FIR-1, 1, 0); + fir_fx( HF_syn_fx, fir_6k_8k_fx, HF_syn_fx, mem_hf1_enc_fx, L_SUBFR16k, L_FIR - 1, 1, 0 ); + fir_fx( HF_SP_fx, fir_6k_8k_fx, HF_SP_fx, mem_hf2_enc_fx, L_SUBFR16k, L_FIR - 1, 1, 0 ); /* check the gain difference */ - ener_hf_fx = dot_prod_satcontr(HF_syn_fx, HF_syn_fx, 0, 0, &q2, L_SUBFR16k); - ener_input_fx = dot_prod_satcontr(HF_SP_fx, HF_SP_fx, 0, 0, &q1, L_SUBFR16k); + ener_hf_fx = dot_prod_satcontr( HF_syn_fx, HF_syn_fx, 0, 0, &q2, L_SUBFR16k ); + ener_input_fx = dot_prod_satcontr( HF_SP_fx, HF_SP_fx, 0, 0, &q1, L_SUBFR16k ); - HF_calc_gain_fx = div_s(shl(1, 14), ener_input_fx); /*Q(29-q1) */ - L_tmp = L_mult(ener_hf_fx, HF_calc_gain_fx); /*30-q1+q2 */ - q2 = sub(q1, q2); /*30-q2 */ + HF_calc_gain_fx = div_s( shl( 1, 14 ), ener_input_fx ); /*Q(29-q1) */ + L_tmp = L_mult( ener_hf_fx, HF_calc_gain_fx ); /*30-q1+q2 */ + q2 = sub( q1, q2 ); /*30-q2 */ #ifdef BASOP_NOGLOB - HF_calc_gain_fx = round_fx_o(Isqrt(L_shl_sat(L_tmp, sub(q2, 20))), &Overflow); /*Q10 */ -#else /* BASOP_NOGLOB */ - HF_calc_gain_fx = round_fx(Isqrt(L_shl(L_tmp, sub(q2, 20)))); /*Q10 */ + HF_calc_gain_fx = round_fx_o( Isqrt( L_shl_sat( L_tmp, sub( q2, 20 ) ) ), &Overflow ); /*Q10 */ +#else /* BASOP_NOGLOB */ + HF_calc_gain_fx = round_fx( Isqrt( L_shl( L_tmp, sub( q2, 20 ) ) ) ); /*Q10 */ #endif /* set energy of HF synthesis to energy of original HF: cross-fade between HF levels in active and inactive frame in hangover period */ - IF ( GT_16(4, dtxHangoverCount_fx)) + IF( GT_16( 4, dtxHangoverCount_fx ) ) { *gain_alpha_fx = 16384; move16(); } ELSE { - L_tmp = L_shl(L_mult(sub(10, dtxHangoverCount_fx), 4681), 15);/*Q31 */ - L_tmp = Mult_32_16(L_tmp, *gain_alpha_fx); /*Q30 */ - *gain_alpha_fx = round_fx(L_tmp); /*Q14 */ + L_tmp = L_shl( L_mult( sub( 10, dtxHangoverCount_fx ), 4681 ), 15 ); /*Q31 */ + L_tmp = Mult_32_16( L_tmp, *gain_alpha_fx ); /*Q30 */ + *gain_alpha_fx = round_fx( L_tmp ); /*Q14 */ } - L_tmp = L_mult(sub(16384, *gain_alpha_fx), HF_est_gain_fx); /*Q25 */ - L_tmp = L_mac(L_tmp, *gain_alpha_fx, HF_calc_gain_fx); /*Q25 */ - IF (GE_32(L_tmp,67108863)) + L_tmp = L_mult( sub( 16384, *gain_alpha_fx ), HF_est_gain_fx ); /*Q25 */ + L_tmp = L_mac( L_tmp, *gain_alpha_fx, HF_calc_gain_fx ); /*Q25 */ + IF( GE_32( L_tmp, 67108863 ) ) { L_tmp = 67108863; move32(); } - L_tmp = L_shl(L_tmp, 5); - HF_corr_gain_fx = extract_h(L_tmp); /*Q14; HF_corr_gain_fx/2 in Q15 */ + L_tmp = L_shl( L_tmp, 5 ); + HF_corr_gain_fx = extract_h( L_tmp ); /*Q14; HF_corr_gain_fx/2 in Q15 */ /* Quantize the correction gain */ dist_min_fx = 2147483647; @@ -229,13 +228,13 @@ void hf_cod_fx( HF_gain_ind_fx = 0; move16(); pt2 = HP_gain_fx; - FOR ( i = 0; i < 16; i++ ) + FOR( i = 0; i < 16; i++ ) { - dist_fx = L_mult(sub(HF_corr_gain_fx, *pt2), sub(HF_corr_gain_fx, *pt2)); + dist_fx = L_mult( sub( HF_corr_gain_fx, *pt2 ), sub( HF_corr_gain_fx, *pt2 ) ); pt2++; - IF ( GT_32(dist_min_fx, dist_fx)) + IF( GT_32( dist_min_fx, dist_fx ) ) { - dist_min_fx = L_add(dist_fx, 0); + dist_min_fx = L_add( dist_fx, 0 ); HF_gain_ind_fx = i; move16(); } diff --git a/lib_enc/hq_classifier_enc_fx.c b/lib_enc/hq_classifier_enc_fx.c index 6525f57f9..ebf3855ee 100644 --- a/lib_enc/hq_classifier_enc_fx.c +++ b/lib_enc/hq_classifier_enc_fx.c @@ -2,24 +2,24 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ //#include "prot_fx.h" /* Function prototypes */ -#include "rom_com_fx.h" /* Static table prototypes */ +#include "rom_com_fx.h" /* Static table prototypes */ #include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*-----------------------------------------------------------------* * Local constants *-----------------------------------------------------------------*/ -#define SHARP_DIST_THRES_FX 1420 /* Q6, 22.2 */ +#define SHARP_DIST_THRES_FX 1420 /* Q6, 22.2 */ #define HALF_WIN_LENGTH 10 #define L_SPEC_HB 320 -#define PEAK_THRESHOLD 3277 /*Q15 0.1f*/ +#define PEAK_THRESHOLD 3277 /*Q15 0.1f*/ #define LOW_COUNT_THRESHOLD 220 @@ -27,9 +27,7 @@ * Local functions *-----------------------------------------------------------------*/ -void hvq_classifier_fx( const Word32 *input, Word16 *prev_Npeaks, Word16 *prev_peaks, - Word16 *hqswb_clas, Word16 *Npeaks, Word16 *peaks, const Word32 L_core_brate, - const Word16 last_core, Word32 *L_nf_gains, Word16 *hvq_hangover, Word32 *L_pe_gains ); +void hvq_classifier_fx( const Word32 *input, Word16 *prev_Npeaks, Word16 *prev_peaks, Word16 *hqswb_clas, Word16 *Npeaks, Word16 *peaks, const Word32 L_core_brate, const Word16 last_core, Word32 *L_nf_gains, Word16 *hvq_hangover, Word32 *L_pe_gains ); /*--------------------------------------------------------------------------* * hq_classifier_enc_fx() @@ -37,16 +35,16 @@ void hvq_classifier_fx( const Word32 *input, Word16 *prev_Npeaks, Word16 *prev_p * HQ mode selector (decision_matrix) *--------------------------------------------------------------------------*/ -Word16 hq_classifier_enc_fx( /* o : Consumed bits Q0 */ - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 length, /* i : Frame length Q0 */ - const Word32 *coefs, /* i : Spectral coefficients Q12 */ - const Word16 is_transient, /* i : Transient flag Q0 */ - Word16 *Npeaks, /* o : Number of identified peaks Q0 */ - Word16 *peaks, /* o : Peak indices Q0 */ - Word32 *pe_gains, /* o : Peak gains Q12 */ - Word32 *nf_gains, /* o : Noise-fill gains Q12 */ - Word16 *hqswb_clas /* o : HQ class Q0 */ +Word16 hq_classifier_enc_fx( /* o : Consumed bits Q0 */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word16 length, /* i : Frame length Q0 */ + const Word32 *coefs, /* i : Spectral coefficients Q12 */ + const Word16 is_transient, /* i : Transient flag Q0 */ + Word16 *Npeaks, /* o : Number of identified peaks Q0 */ + Word16 *peaks, /* o : Peak indices Q0 */ + Word32 *pe_gains, /* o : Peak gains Q12 */ + Word32 *nf_gains, /* o : Noise-fill gains Q12 */ + Word16 *hqswb_clas /* o : HQ class Q0 */ ) { #ifndef SOLVED_COMP_ENC_DEC @@ -54,7 +52,7 @@ Word16 hq_classifier_enc_fx( /* o : Consumed bits Q0 */ HQ_ENC_HANDLE hHQ_core = st_fx->hHQ_core; *hqswb_clas = HQ_NORMAL; - IF(EQ_16(is_transient, 1)) + IF( EQ_16( is_transient, 1 ) ) { *hqswb_clas = HQ_TRANSIENT; move16(); @@ -64,38 +62,38 @@ Word16 hq_classifier_enc_fx( /* o : Consumed bits Q0 */ test(); test(); test(); - IF(EQ_16(length, L_FRAME32k) && NE_16(is_transient, 1) && LE_32(st_fx->core_brate, HQ_32k) && EQ_16(st_fx->bwidth, st_fx->last_bwidth)) + IF( EQ_16( length, L_FRAME32k ) && NE_16( is_transient, 1 ) && LE_32( st_fx->core_brate, HQ_32k ) && EQ_16( st_fx->bwidth, st_fx->last_bwidth ) ) { /* Detect HQ_HARMONIC mode */ - *hqswb_clas = peak_avrg_ratio_fx(st_fx->total_brate, coefs, NUMC_N + 96, &hHQ_core->mode_count, &hHQ_core->mode_count1, 12); + *hqswb_clas = peak_avrg_ratio_fx( st_fx->total_brate, coefs, NUMC_N + 96, &hHQ_core->mode_count, &hHQ_core->mode_count1, 12 ); /* Detect harmonic VQ mode HQ_HVQ */ - hvq_classifier_fx(coefs, &hHQ_core->prev_Npeaks, hHQ_core->prev_peaks, hqswb_clas, Npeaks, peaks, st_fx->core_brate, st_fx->last_core, - nf_gains, &hHQ_core->hvq_hangover, pe_gains); + hvq_classifier_fx( coefs, &hHQ_core->prev_Npeaks, hHQ_core->prev_peaks, hqswb_clas, Npeaks, peaks, st_fx->core_brate, st_fx->last_core, + nf_gains, &hHQ_core->hvq_hangover, pe_gains ); } test(); test(); test(); - IF(EQ_16(length, L_FRAME48k) && NE_16(is_transient, 1) && LE_32(st_fx->core_brate, HQ_32k) && EQ_16(st_fx->bwidth, st_fx->last_bwidth)) + IF( EQ_16( length, L_FRAME48k ) && NE_16( is_transient, 1 ) && LE_32( st_fx->core_brate, HQ_32k ) && EQ_16( st_fx->bwidth, st_fx->last_bwidth ) ) { /* Detect HQ_HARMONIC mode */ - *hqswb_clas = peak_avrg_ratio_fx(st_fx->total_brate, coefs, NUMC_N + 96, &hHQ_core->mode_count, &hHQ_core->mode_count1, 12); + *hqswb_clas = peak_avrg_ratio_fx( st_fx->total_brate, coefs, NUMC_N + 96, &hHQ_core->mode_count, &hHQ_core->mode_count1, 12 ); /* Detect harmonic VQ mode HQ_HVQ */ - hvq_classifier_fx(coefs, &hHQ_core->prev_Npeaks, hHQ_core->prev_peaks, hqswb_clas, Npeaks, peaks, - st_fx->core_brate, st_fx->last_core, nf_gains, &hHQ_core->hvq_hangover, pe_gains); + hvq_classifier_fx( coefs, &hHQ_core->prev_Npeaks, hHQ_core->prev_peaks, hqswb_clas, Npeaks, peaks, + st_fx->core_brate, st_fx->last_core, nf_gains, &hHQ_core->hvq_hangover, pe_gains ); } test(); test(); - IF(EQ_16(length, L_FRAME48k) && LE_32(st_fx->core_brate, HQ_32k) && EQ_16(*hqswb_clas, HQ_NORMAL)) + IF( EQ_16( length, L_FRAME48k ) && LE_32( st_fx->core_brate, HQ_32k ) && EQ_16( *hqswb_clas, HQ_NORMAL ) ) { *hqswb_clas = HQ_GEN_FB; move16(); } test(); - IF(GE_16(length, L_FRAME32k) && LE_32(st_fx->core_brate, HQ_32k)) + IF( GE_16( length, L_FRAME32k ) && LE_32( st_fx->core_brate, HQ_32k ) ) { bits = 2; move16(); @@ -107,25 +105,25 @@ Word16 hq_classifier_enc_fx( /* o : Consumed bits Q0 */ } test(); - IF(EQ_16(length, L_FRAME48k) && LE_32(st_fx->core_brate, HQ_32k)) + IF( EQ_16( length, L_FRAME48k ) && LE_32( st_fx->core_brate, HQ_32k ) ) { - IF(GE_16(*hqswb_clas, HQ_GEN_SWB)) + IF( GE_16( *hqswb_clas, HQ_GEN_SWB ) ) { - push_indice_fx(st_fx->hBstr, IND_HQ_SWB_CLAS, *hqswb_clas - 5, bits); + push_indice_fx( st_fx->hBstr, IND_HQ_SWB_CLAS, *hqswb_clas - 5, bits ); } ELSE { - push_indice_fx(st_fx->hBstr, IND_HQ_SWB_CLAS, *hqswb_clas, bits); + push_indice_fx( st_fx->hBstr, IND_HQ_SWB_CLAS, *hqswb_clas, bits ); } } ELSE { - push_indice_fx(st_fx->hBstr, IND_HQ_SWB_CLAS, *hqswb_clas, bits); + push_indice_fx( st_fx->hBstr, IND_HQ_SWB_CLAS, *hqswb_clas, bits ); } test(); test(); - IF(EQ_16(*hqswb_clas, HQ_NORMAL) && EQ_16(length, L_FRAME32k) && LE_32(st_fx->core_brate, HQ_32k)) + IF( EQ_16( *hqswb_clas, HQ_NORMAL ) && EQ_16( length, L_FRAME32k ) && LE_32( st_fx->core_brate, HQ_32k ) ) { *hqswb_clas = HQ_GEN_SWB; move16(); @@ -138,16 +136,18 @@ Word16 hq_classifier_enc_fx( /* o : Consumed bits Q0 */ Word16 harmonic_decision; - max_brate = HQ_32k; move32(); - if (GT_16(st_fx->element_mode, EVS_MONO)) + max_brate = HQ_32k; + move32(); + if ( GT_16( st_fx->element_mode, EVS_MONO ) ) { max_brate = HQ_48k; move32(); } *hqswb_clas = HQ_NORMAL; - bits = 1; move16(); - IF( EQ_16( is_transient, 1)) + bits = 1; + move16(); + IF( EQ_16( is_transient, 1 ) ) { *hqswb_clas = HQ_TRANSIENT; move16(); @@ -155,23 +155,23 @@ Word16 hq_classifier_enc_fx( /* o : Consumed bits Q0 */ /* classification and limit bandwidth for bit allocation */ test(); - IF (EQ_16(length, L_SPEC32k) || EQ_16(length, L_SPEC48k)) + IF( EQ_16( length, L_SPEC32k ) || EQ_16( length, L_SPEC48k ) ) { - IF(LE_32(st_fx->core_brate, max_brate)) + IF( LE_32( st_fx->core_brate, max_brate ) ) { test(); - IF(!is_transient && EQ_16(st_fx->bwidth, st_fx->last_bwidth)) + IF( !is_transient && EQ_16( st_fx->bwidth, st_fx->last_bwidth ) ) { /* Detect HQ_HARMONIC mode */ - *hqswb_clas = peak_avrg_ratio_fx(st_fx->total_brate, coefs, NUMC_N + 96, &hHQ_core->mode_count, &hHQ_core->mode_count1, 12); + *hqswb_clas = peak_avrg_ratio_fx( st_fx->total_brate, coefs, NUMC_N + 96, &hHQ_core->mode_count, &hHQ_core->mode_count1, 12 ); #ifdef ADD_IVAS_HQ_CODE - harmonic_decision = hf_spectrum_sparseness(st, coefs); + harmonic_decision = hf_spectrum_sparseness( st, coefs ); #else harmonic_decision = 0; #endif test(); - IF(EQ_16(*hqswb_clas, HQ_HARMONIC) && !harmonic_decision) + IF( EQ_16( *hqswb_clas, HQ_HARMONIC ) && !harmonic_decision ) { *hqswb_clas = HQ_NORMAL; move16(); @@ -179,30 +179,33 @@ Word16 hq_classifier_enc_fx( /* o : Consumed bits Q0 */ ELSE { /* Detect harmonic VQ mode HQ_HVQ */ - hvq_classifier_fx(coefs, &hHQ_core->prev_Npeaks, hHQ_core->prev_peaks, hqswb_clas, Npeaks, peaks, st_fx->core_brate, st_fx->last_core, - nf_gains, &hHQ_core->hvq_hangover, pe_gains); + hvq_classifier_fx( coefs, &hHQ_core->prev_Npeaks, hHQ_core->prev_peaks, hqswb_clas, Npeaks, peaks, st_fx->core_brate, st_fx->last_core, + nf_gains, &hHQ_core->hvq_hangover, pe_gains ); } } - bits = 2; move16(); + bits = 2; + move16(); } } - ELSE IF(EQ_16(length, L_SPEC16k_EXT) || EQ_16(length, L_SPEC48k_EXT)) + ELSE IF( EQ_16( length, L_SPEC16k_EXT ) || EQ_16( length, L_SPEC48k_EXT ) ) { bits = 0; /* HQ_NORMAL only -- no signalling needed */ move16(); } /* write signalling info to the bitstream */ - push_indice_fx(st_fx->hBstr, IND_HQ_SWB_CLAS, *hqswb_clas, bits); + push_indice_fx( st_fx->hBstr, IND_HQ_SWB_CLAS, *hqswb_clas, bits ); - IF (LE_32(st_fx->core_brate, HQ_32k) && EQ_16(*hqswb_clas, HQ_NORMAL)) + IF( LE_32( st_fx->core_brate, HQ_32k ) && EQ_16( *hqswb_clas, HQ_NORMAL ) ) { - IF (EQ_16(length, L_SPEC32k)) + IF( EQ_16( length, L_SPEC32k ) ) { - *hqswb_clas = HQ_GEN_SWB; move16(); + *hqswb_clas = HQ_GEN_SWB; + move16(); } - ELSE IF (EQ_16(length, L_SPEC48k)) + ELSE IF( EQ_16( length, L_SPEC48k ) ) { - *hqswb_clas = HQ_GEN_FB; move16(); + *hqswb_clas = HQ_GEN_FB; + move16(); } } #endif @@ -215,92 +218,91 @@ Word16 hq_classifier_enc_fx( /* o : Consumed bits Q0 */ * Classify the input signal and decide if it has a harmonic structure *--------------------------------------------------------------------------*/ Word16 peak_avrg_ratio_fx( - const Word32 total_brate, /* i : total bitrate */ - const Word32 *input_hi_fx, /* i : input signal */ - const Word16 length, /* i : number of coefficients */ - Word16 *mode_count, /* i/o: HQ_HARMONIC mode count */ - Word16 *mode_count1, /* i/o: HQ_NORMAL mode count */ - Word16 Q_coeff -) + const Word32 total_brate, /* i : total bitrate */ + const Word32 *input_hi_fx, /* i : input signal */ + const Word16 length, /* i : number of coefficients */ + Word16 *mode_count, /* i/o: HQ_HARMONIC mode count */ + Word16 *mode_count1, /* i/o: HQ_NORMAL mode count */ + Word16 Q_coeff ) { Word16 i, j, q, k, k1, hqswb_clas; Word32 mean_fx, peak_fx; Word32 input_abs_fx[L_FRAME32k]; Word32 peak_th_fx; - FOR ( i = 96; i < length; i++) + FOR( i = 96; i < length; i++ ) { - input_abs_fx[i] = L_abs(input_hi_fx[i]); + input_abs_fx[i] = L_abs( input_hi_fx[i] ); } hqswb_clas = HQ_NORMAL; move16(); - peak_th_fx = L_shl(10L, sub(Q_coeff, 5)); /* 5 is safe shift */ + peak_th_fx = L_shl( 10L, sub( Q_coeff, 5 ) ); /* 5 is safe shift */ k = 0; move16(); k1 = 0; move16(); - q = 96; /* q used for indexing */ + q = 96; /* q used for indexing */ - FOR( i = 3; i < 17; i ++ ) + FOR( i = 3; i < 17; i++ ) { - peak_fx = L_deposit_l(0); - mean_fx = L_deposit_l(1); + peak_fx = L_deposit_l( 0 ); + mean_fx = L_deposit_l( 1 ); /*for(j = 0; j < 32; j ++, q ++) */ - FOR(j = 0; j < 32; j ++) + FOR( j = 0; j < 32; j++ ) { - input_abs_fx[q] =L_shr(input_abs_fx[q],5); /*Q_coeff-5 */ - mean_fx =L_add(mean_fx,input_abs_fx[q]); /*Q_coeff-5 */ - IF (GT_32(input_abs_fx[q] , peak_fx)) + input_abs_fx[q] = L_shr( input_abs_fx[q], 5 ); /*Q_coeff-5 */ + mean_fx = L_add( mean_fx, input_abs_fx[q] ); /*Q_coeff-5 */ + IF( GT_32( input_abs_fx[q], peak_fx ) ) { - peak_fx =input_abs_fx[q] ; /*Q_coeff-5 */ + peak_fx = input_abs_fx[q]; /*Q_coeff-5 */ } - q ++; + q++; } - IF(LT_16(i,8)) + IF( LT_16( i, 8 ) ) { - if(GT_32(peak_fx, Mult_32_16(mean_fx, 4608))) /* Q15 0.140625 */ + if ( GT_32( peak_fx, Mult_32_16( mean_fx, 4608 ) ) ) /* Q15 0.140625 */ { - k = add(k,1); + k = add( k, 1 ); } } ELSE { test(); - if(GT_32(peak_fx, Mult_32_16(mean_fx, 3686)) /*Q15 0.1125 */ - && GT_32(peak_fx, peak_th_fx)) /*Q27 10 */ + if ( GT_32( peak_fx, Mult_32_16( mean_fx, 3686 ) ) /*Q15 0.1125 */ + && GT_32( peak_fx, peak_th_fx ) ) /*Q27 10 */ { - k1 = add(k1,1); + k1 = add( k1, 1 ); } } } test(); - IF( GE_16(add(k,k1),10)&>_16(k1,5)) + IF( GE_16( add( k, k1 ), 10 ) && GT_16( k1, 5 ) ) { - if( LT_16(*mode_count,8)) + if ( LT_16( *mode_count, 8 ) ) { - *mode_count = add(*mode_count,1); + *mode_count = add( *mode_count, 1 ); } - if( *mode_count1 > 0 ) + if ( *mode_count1 > 0 ) { - *mode_count1 = sub(*mode_count1,1); + *mode_count1 = sub( *mode_count1, 1 ); } } ELSE { - if( LT_16(*mode_count1,8)) + if ( LT_16( *mode_count1, 8 ) ) { - *mode_count1 = add(*mode_count1,1); + *mode_count1 = add( *mode_count1, 1 ); } - if( *mode_count > 0 ) + if ( *mode_count > 0 ) { - *mode_count = sub(*mode_count,1); + *mode_count = sub( *mode_count, 1 ); } } @@ -310,12 +312,10 @@ Word16 peak_avrg_ratio_fx( test(); test(); test(); -#ifndef SOLVED_COMP_ENC_DEC /*This affect BE even if it shouldn't*/ - if ((GE_16(add(k, k1), 5) && GT_16(k1, 2) && EQ_32(total_brate, HQ_24k40)) - || (((GE_16(add(k, k1), 10) && GT_16(k1, 5)) || GE_16(*mode_count, 5)) && LT_16(*mode_count1, 5))) +#ifndef SOLVED_COMP_ENC_DEC /*This affect BE even if it shouldn't*/ + if ( ( GE_16( add( k, k1 ), 5 ) && GT_16( k1, 2 ) && EQ_32( total_brate, HQ_24k40 ) ) || ( ( ( GE_16( add( k, k1 ), 10 ) && GT_16( k1, 5 ) ) || GE_16( *mode_count, 5 ) ) && LT_16( *mode_count1, 5 ) ) ) #else - if ((GE_16(add(k, k1), 5) && GT_16(k1,2) && LT_32(total_brate, HQ_BWE_CROSSOVER_BRATE)) - || (((GE_16(add(k, k1), 10) && GT_16(k1, 5) ) || GE_16(*mode_count, 5) ) && LT_16(*mode_count1, 5) )) + if ( ( GE_16( add( k, k1 ), 5 ) && GT_16( k1, 2 ) && LT_32( total_brate, HQ_BWE_CROSSOVER_BRATE ) ) || ( ( ( GE_16( add( k, k1 ), 10 ) && GT_16( k1, 5 ) ) || GE_16( *mode_count, 5 ) ) && LT_16( *mode_count1, 5 ) ) ) #endif { hqswb_clas = HQ_HARMONIC; @@ -376,56 +376,56 @@ void hvq_classifier_fx( #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - L_input_max = L_deposit_l(0); - set32_fx(L_thr, 0, L_FRAME16k); + L_input_max = L_deposit_l( 0 ); + set32_fx( L_thr, 0, L_FRAME16k ); #ifndef SOLVED_COMP_ENC_DEC - IF(EQ_32(L_core_brate, HQ_24k40)) + IF( EQ_32( L_core_brate, HQ_24k40 ) ) #else - IF ( LT_32(L_core_brate, HQ_BWE_CROSSOVER_BRATE)) + IF( LT_32( L_core_brate, HQ_BWE_CROSSOVER_BRATE ) ) #endif { nsub = HVQ_NSUB_24k; move16(); inv_nsub = 4681; - move16(); /* 1/7 in Q15 */ + move16(); /* 1/7 in Q15 */ inv_gains_nsub = 10923; - move16(); /* 1/3 in Q15 */ + move16(); /* 1/3 in Q15 */ } ELSE { nsub = HVQ_NSUB_32k; move16(); inv_nsub = 3277; - move16(); /* 1/10 in Q15 */ + move16(); /* 1/10 in Q15 */ inv_gains_nsub = 6554; - move16(); /* 1/5 in Q15 */ + move16(); /* 1/5 in Q15 */ } - N = shl(nsub, 5); /* Mult by 32 (HVQ_BW) */ + N = shl( nsub, 5 ); /* Mult by 32 (HVQ_BW) */ test(); test(); - IF ( EQ_16(*hqswb_clas, HQ_HARMONIC)&&last_core!=ACELP_CORE&&NE_16(last_core,AMR_WB_CORE)) + IF( EQ_16( *hqswb_clas, HQ_HARMONIC ) && last_core != ACELP_CORE && NE_16( last_core, AMR_WB_CORE ) ) { - FOR ( i = 0; i < N; i++ ) + FOR( i = 0; i < N; i++ ) { - L_input_abs[i] = L_abs(input[i]); - if (L_input_abs[i] > L_input_max) + L_input_abs[i] = L_abs( input[i] ); + if ( L_input_abs[i] > L_input_max ) { L_input_max = L_input_abs[i]; move16(); } } - exp1 = norm_l(L_input_max); + exp1 = norm_l( L_input_max ); *Npeaks = 0; move16(); L_nf = 3276800; - move32(); /* 800 in Q12 */ + move32(); /* 800 in Q12 */ L_pe = 3276800; - move32(); /* 800 in Q12 */ + move32(); /* 800 in Q12 */ num_sharp_bands = 0; move16(); k = 0; @@ -436,139 +436,139 @@ void hvq_classifier_fx( move16(); /* Find peak threshold */ - FOR ( i = 0; i < nsub; i++ ) + FOR( i = 0; i < nsub; i++ ) { L_peak = 0; L_nf_mean[i] = 0; L_pe_mean[i] = 0; - FOR ( j = 0; j < HVQ_BW; j++ ) + FOR( j = 0; j < HVQ_BW; j++ ) { L_d = L_input_abs[q]; - IF ( GT_32(L_d, L_nf)) + IF( GT_32( L_d, L_nf ) ) { /*nf = HVQ_NF_WEIGHT1 * nf + (1 - HVQ_NF_WEIGHT1) * d; */ - Mpy_32_16_ss(L_d, HVQ_NF_WEIGHT1B, &L_tmp, &lsb); /* 12+15-15=12 */ - Mpy_32_16_ss(L_nf, HVQ_NF_WEIGHT1_FX, &L_nf, &lsb); /* 12+15-15=12 */ - L_nf = L_add(L_nf, L_tmp); /*Q12 */ + Mpy_32_16_ss( L_d, HVQ_NF_WEIGHT1B, &L_tmp, &lsb ); /* 12+15-15=12 */ + Mpy_32_16_ss( L_nf, HVQ_NF_WEIGHT1_FX, &L_nf, &lsb ); /* 12+15-15=12 */ + L_nf = L_add( L_nf, L_tmp ); /*Q12 */ } ELSE { /*nf = HVQ_NF_WEIGHT2 * nf + (1 - HVQ_NF_WEIGHT2) * d; */ - Mpy_32_16_ss(L_d, HVQ_NF_WEIGHT2B, &L_tmp, &lsb); /* 12+15-15=12 */ - Mpy_32_16_ss(L_nf, HVQ_NF_WEIGHT2_FX, &L_nf, &lsb); /* 12+15-15=12 */ - L_nf = L_add(L_nf, L_tmp); /*Q12 */ + Mpy_32_16_ss( L_d, HVQ_NF_WEIGHT2B, &L_tmp, &lsb ); /* 12+15-15=12 */ + Mpy_32_16_ss( L_nf, HVQ_NF_WEIGHT2_FX, &L_nf, &lsb ); /* 12+15-15=12 */ + L_nf = L_add( L_nf, L_tmp ); /*Q12 */ } - IF ( GT_32(L_d, L_pe)) + IF( GT_32( L_d, L_pe ) ) { /*pe = HVQ_PE_WEIGHT1 * pe + (1 - HVQ_PE_WEIGHT1) * d; */ - Mpy_32_16_ss(L_d, HVQ_PE_WEIGHT1B, &L_tmp, &lsb); /* 12+15-15=12 */ - Mpy_32_16_ss(L_pe, HVQ_PE_WEIGHT1_FX, &L_pe, &lsb); /* 12+15-15=12 */ - L_pe = L_add(L_pe, L_tmp); /*Q12 */ + Mpy_32_16_ss( L_d, HVQ_PE_WEIGHT1B, &L_tmp, &lsb ); /* 12+15-15=12 */ + Mpy_32_16_ss( L_pe, HVQ_PE_WEIGHT1_FX, &L_pe, &lsb ); /* 12+15-15=12 */ + L_pe = L_add( L_pe, L_tmp ); /*Q12 */ } ELSE { /*pe = HVQ_PE_WEIGHT2 * pe + (1 - HVQ_PE_WEIGHT2) * d; */ - Mpy_32_16_ss(L_d, HVQ_PE_WEIGHT2B, &L_tmp, &lsb); /* 12+15-15=12 */ - Mpy_32_16_ss(L_pe, HVQ_PE_WEIGHT2_FX, &L_pe, &lsb); /* 12+15-15=12 */ - L_pe = L_add(L_pe, L_tmp); /*Q12 */ + Mpy_32_16_ss( L_d, HVQ_PE_WEIGHT2B, &L_tmp, &lsb ); /* 12+15-15=12 */ + Mpy_32_16_ss( L_pe, HVQ_PE_WEIGHT2_FX, &L_pe, &lsb ); /* 12+15-15=12 */ + L_pe = L_add( L_pe, L_tmp ); /*Q12 */ } #ifdef BASOP_NOGLOB L_nf_mean[i] = L_add_sat( L_nf_mean[i], L_nf ); - L_pe_mean[i] = L_add_sat(L_pe_mean[i], L_pe); + L_pe_mean[i] = L_add_sat( L_pe_mean[i], L_pe ); #else L_nf_mean[i] = L_add( L_nf_mean[i], L_nf ); - L_pe_mean[i] = L_add(L_pe_mean[i], L_pe); + L_pe_mean[i] = L_add( L_pe_mean[i], L_pe ); #endif - IF ( GT_32(L_d, L_peak)) + IF( GT_32( L_d, L_peak ) ) { - L_peak = L_add(L_d, 0); + L_peak = L_add( L_d, 0 ); } - q = add(q, 1); + q = add( q, 1 ); } - L_nf_mean[i] = L_shr(L_nf_mean[i], 5); /* Divide by 5 (HVQ_BW) */ - L_pe_mean[i] = L_shr(L_pe_mean[i], 5); /* Divide by 5 (HVQ_BW) */ + L_nf_mean[i] = L_shr( L_nf_mean[i], 5 ); /* Divide by 5 (HVQ_BW) */ + L_pe_mean[i] = L_shr( L_pe_mean[i], 5 ); /* Divide by 5 (HVQ_BW) */ /*thr_tmp = (float)pow( pe_mean[i]/nf_mean[i], HVQ_THR_POW ) * nf_mean[i]; */ - exp1 = norm_l(L_nf_mean[i]); - nf_mean_norm = extract_h(L_shl(L_nf_mean[i], exp1)); /* 12+s-16=s-4 */ - IF ( nf_mean_norm == 0 ) + exp1 = norm_l( L_nf_mean[i] ); + nf_mean_norm = extract_h( L_shl( L_nf_mean[i], exp1 ) ); /* 12+s-16=s-4 */ + IF( nf_mean_norm == 0 ) { inv_nf_mean = 0; } ELSE { - inv_nf_mean = div_s(1<<14, nf_mean_norm); /* 15+14-s+4=33-s */ + inv_nf_mean = div_s( 1 << 14, nf_mean_norm ); /* 15+14-s+4=33-s */ } - Mpy_32_16_ss(L_pe_mean[i], inv_nf_mean, &L_tmp, &lsb); /*12+33-s-15=30-s */ + Mpy_32_16_ss( L_pe_mean[i], inv_nf_mean, &L_tmp, &lsb ); /*12+33-s-15=30-s */ - exp2 = norm_l(L_tmp); - tmp = Log2_norm_lc(L_shl(L_tmp, exp2)); /* Q15 */ + exp2 = norm_l( L_tmp ); + tmp = Log2_norm_lc( L_shl( L_tmp, exp2 ) ); /* Q15 */ exp2 = exp1 - exp2; /* Q0 */ - L_tmp = Mpy_32_16(exp2, tmp, 32767); /* 1 in Q15. Q16 */ - Mpy_32_16_ss(L_tmp, 28836, &L_tmp, &lsb); /* 16+15-15=16 */ - frac = L_Extract_lc(L_tmp, &tmp); /* Q15 and Q0 */ - L_tmp = Pow2(14, frac); /* Q14 */ - L_tmp = L_shl(L_tmp, tmp); /* Q14 */ + L_tmp = Mpy_32_16( exp2, tmp, 32767 ); /* 1 in Q15. Q16 */ + Mpy_32_16_ss( L_tmp, 28836, &L_tmp, &lsb ); /* 16+15-15=16 */ + frac = L_Extract_lc( L_tmp, &tmp ); /* Q15 and Q0 */ + L_tmp = Pow2( 14, frac ); /* Q14 */ + L_tmp = L_shl( L_tmp, tmp ); /* Q14 */ - Mpy_32_16_ss(L_tmp, nf_mean_norm, &L_tmp, &lsb); /*14+s-4-15=s-5 */ - shift = sub(17, exp1); /* 16-(s-5)=17-s */ - L_thr_tmp = L_shl(L_tmp, shift); /* Q16 */ - L_thr_tmp = L_add(L_thr_tmp, lshr(lsb, sub(16, shift))); /*Q16 */ + Mpy_32_16_ss( L_tmp, nf_mean_norm, &L_tmp, &lsb ); /*14+s-4-15=s-5 */ + shift = sub( 17, exp1 ); /* 16-(s-5)=17-s */ + L_thr_tmp = L_shl( L_tmp, shift ); /* Q16 */ + L_thr_tmp = L_add( L_thr_tmp, lshr( lsb, sub( 16, shift ) ) ); /*Q16 */ - set32_fx(&L_thr[k], L_thr_tmp, HVQ_BW); - k = add(k, HVQ_BW); + set32_fx( &L_thr[k], L_thr_tmp, HVQ_BW ); + k = add( k, HVQ_BW ); /*sharp[i] = peak/nf_mean[i]; */ - Mpy_32_16_ss(L_peak, inv_nf_mean, &L_tmp, &lsb); /* 12+33-s-15=30-s */ - shift = sub(exp1, 8); - sharp[i] = extract_h(L_shl(L_tmp, shift)); /* 30-s+s-8-16 -> Q6 */ + Mpy_32_16_ss( L_peak, inv_nf_mean, &L_tmp, &lsb ); /* 12+33-s-15=30-s */ + shift = sub( exp1, 8 ); + sharp[i] = extract_h( L_shl( L_tmp, shift ) ); /* 30-s+s-8-16 -> Q6 */ /*sharp_dist += (sharp[i]-HVQ_SHARP_THRES); */ #ifdef BASOP_NOGLOB - sharp_dist = add_o(sharp_dist, sub(sharp[i], HVQ_SHARP_THRES_FX), &Overflow); + sharp_dist = add_o( sharp_dist, sub( sharp[i], HVQ_SHARP_THRES_FX ), &Overflow ); #else - sharp_dist = add(sharp_dist, sub(sharp[i], HVQ_SHARP_THRES_FX)); + sharp_dist = add( sharp_dist, sub( sharp[i], HVQ_SHARP_THRES_FX ) ); #endif - if ( GT_16(sharp[i], HVQ_SHARP_THRES_FX)) + if ( GT_16( sharp[i], HVQ_SHARP_THRES_FX ) ) { - num_sharp_bands = add(num_sharp_bands, 1); + num_sharp_bands = add( num_sharp_bands, 1 ); } } /* Estimate noise floor gains */ - offset = s_and(nsub, 1); - FOR ( i = 0; i < s_and(nsub, (Word16)0xFFFE); i++ ) + offset = s_and( nsub, 1 ); + FOR( i = 0; i < s_and( nsub, (Word16) 0xFFFE ); i++ ) { /*(2*i+1)/nsub */ - idx = mult(add(shl(i, 1), 1), add(inv_nsub, 1)); /*0+15-15 = 0 */ - L_nf_gains[idx] = L_add(L_nf_gains[idx], L_nf_mean[i+offset]); - L_pe_gains[idx] = L_add(L_pe_gains[idx], L_pe_mean[i+offset]); + idx = mult( add( shl( i, 1 ), 1 ), add( inv_nsub, 1 ) ); /*0+15-15 = 0 */ + L_nf_gains[idx] = L_add( L_nf_gains[idx], L_nf_mean[i + offset] ); + L_pe_gains[idx] = L_add( L_pe_gains[idx], L_pe_mean[i + offset] ); } - FOR ( i = 0; i < HVQ_NF_GROUPS; i++ ) + FOR( i = 0; i < HVQ_NF_GROUPS; i++ ) { - Mpy_32_16_ss(L_nf_gains[i], inv_gains_nsub, &L_nf_gains[i], &lsb); /*12+15-15=12 */ - Mpy_32_16_ss(L_pe_gains[i], inv_gains_nsub, &L_pe_gains[i], &lsb); /*12+15-15=12 */ + Mpy_32_16_ss( L_nf_gains[i], inv_gains_nsub, &L_nf_gains[i], &lsb ); /*12+15-15=12 */ + Mpy_32_16_ss( L_pe_gains[i], inv_gains_nsub, &L_pe_gains[i], &lsb ); /*12+15-15=12 */ } /* Allocate available peaks */ - FOR ( i = 0; i < nsub; i++ ) + FOR( i = 0; i < nsub; i++ ) { avail_peaks[i] = HVQ_PA_PEAKS_SHARP1; move16(); - idx = mult(add(shl(i, 1), 1), add(inv_nsub, 1)); /*0+15-15 = 0 */ - Mpy_32_16_ss(L_nf_gains[idx], HVQ_PA_FAC_FX, &L_tmp, &lsb); /* 12+15-15 -> Q12 */ - IF( LT_32(L_nf_mean[i], L_tmp)) + idx = mult( add( shl( i, 1 ), 1 ), add( inv_nsub, 1 ) ); /*0+15-15 = 0 */ + Mpy_32_16_ss( L_nf_gains[idx], HVQ_PA_FAC_FX, &L_tmp, &lsb ); /* 12+15-15 -> Q12 */ + IF( LT_32( L_nf_mean[i], L_tmp ) ) { - IF ( LT_16(sharp[i], HVQ_PA_SHARP_THRES3_FX)) + IF( LT_16( sharp[i], HVQ_PA_SHARP_THRES3_FX ) ) { avail_peaks[i] = HVQ_PA_PEAKS_SHARP3; move16(); } - ELSE IF( LT_16(sharp[i], HVQ_PA_SHARP_THRES2_FX)) + ELSE IF( LT_16( sharp[i], HVQ_PA_SHARP_THRES2_FX ) ) { avail_peaks[i] = HVQ_PA_PEAKS_SHARP2; move16(); @@ -577,17 +577,16 @@ void hvq_classifier_fx( } - /* Adjust threshold around previous peaks */ - FOR ( i = 0; i < *prev_Npeaks; i++ ) + FOR( i = 0; i < *prev_Npeaks; i++ ) { - j = sub(prev_peaks[i], 2); - k = add(prev_peaks[i], 2); + j = sub( prev_peaks[i], 2 ); + k = add( prev_peaks[i], 2 ); p_adj = hvq_thr_adj_fx; FOR( q = j; q < k; q++ ) { - Mpy_32_16_ss(L_thr[q], *p_adj++, &L_thr[q], &lsb); /* 12+15-15=12 */ + Mpy_32_16_ss( L_thr[q], *p_adj++, &L_thr[q], &lsb ); /* 12+15-15=12 */ move32(); } } @@ -596,15 +595,15 @@ void hvq_classifier_fx( move16(); /* Remove everything below threshold for peak search */ - L_input_abs[0] = L_deposit_l(0); - L_input_abs[1] = L_deposit_l(0); - L_input_abs[N-2] = L_deposit_l(0); - L_input_abs[N-1] = L_deposit_l(0); - FOR ( i = 0; i < N-2; i++ ) + L_input_abs[0] = L_deposit_l( 0 ); + L_input_abs[1] = L_deposit_l( 0 ); + L_input_abs[N - 2] = L_deposit_l( 0 ); + L_input_abs[N - 1] = L_deposit_l( 0 ); + FOR( i = 0; i < N - 2; i++ ) { - IF ( LT_32(L_input_abs[i], L_thr[i])) + IF( LT_32( L_input_abs[i], L_thr[i] ) ) { - L_input_abs[i] = L_deposit_l(0); + L_input_abs[i] = L_deposit_l( 0 ); } ELSE { @@ -612,11 +611,11 @@ void hvq_classifier_fx( move32(); peak_cand_idx[num_peak_cands] = i; move16(); - num_peak_cands = add(num_peak_cands, 1); + num_peak_cands = add( num_peak_cands, 1 ); } } #ifndef ADD_IVAS_HQ_CODE - IF ( EQ_32(L_core_brate, HQ_24k40)) + IF( EQ_32( L_core_brate, HQ_24k40 ) ) { peak_th = HVQ_MAX_PEAKS_24k_CLAS; move16(); @@ -627,24 +626,24 @@ void hvq_classifier_fx( move16(); } #else - peak_th = (int16_t)((core_brate * HVQ_PEAKS_PER_DELTA_THR + HVQ_PEAKS_PER_DELTA_THR_OFFS) / HVQ_PEAKS_BPS_DELTA); + peak_th = (int16_t) ( ( core_brate * HVQ_PEAKS_PER_DELTA_THR + HVQ_PEAKS_PER_DELTA_THR_OFFS ) / HVQ_PEAKS_BPS_DELTA ); #endif /* Find peaks */ - pindx = maximum_32_fx(L_input_abs, num_peak_cands, &L_m); + pindx = maximum_32_fx( L_input_abs, num_peak_cands, &L_m ); i = 0; move16(); - WHILE ( L_m > 0 && LT_16(i, peak_th+1)) + WHILE( L_m > 0 && LT_16( i, peak_th + 1 ) ) { - idx = mult(peak_cand_idx[pindx], INV_HVQ_BW); /* 0+15-15=0 */ - IF ( avail_peaks[idx] > 0 ) + idx = mult( peak_cand_idx[pindx], INV_HVQ_BW ); /* 0+15-15=0 */ + IF( avail_peaks[idx] > 0 ) { peaks[i++] = peak_cand_idx[pindx]; avail_peaks[idx]--; } - j = sub(pindx, 2); - k = add(pindx, 2); + j = sub( pindx, 2 ); + k = add( pindx, 2 ); if ( j < 0 ) { @@ -652,15 +651,15 @@ void hvq_classifier_fx( move16(); } - tmp = sub(num_peak_cands, 1); - if ( GT_16(k, tmp)) + tmp = sub( num_peak_cands, 1 ); + if ( GT_16( k, tmp ) ) { k = tmp; move16(); } - low = sub(peak_cand_idx[pindx], 2); - high = add(peak_cand_idx[pindx], 2); + low = sub( peak_cand_idx[pindx], 2 ); + high = add( peak_cand_idx[pindx], 2 ); if ( low < 0 ) { @@ -668,8 +667,8 @@ void hvq_classifier_fx( move16(); } - tmp = sub(N, 1); - if ( GT_16(high, tmp)) + tmp = sub( N, 1 ); + if ( GT_16( high, tmp ) ) { high = tmp; move16(); @@ -677,7 +676,7 @@ void hvq_classifier_fx( FOR( q = j; q <= pindx; q++ ) { - IF( GE_16(peak_cand_idx[q], low)) + IF( GE_16( peak_cand_idx[q], low ) ) { peak_cand_idx[q] = 0; move16(); @@ -688,7 +687,7 @@ void hvq_classifier_fx( FOR( q = pindx + 1; q <= k; q++ ) { - IF ( LE_16(peak_cand_idx[q], high)) + IF( LE_16( peak_cand_idx[q], high ) ) { peak_cand_idx[q] = 0; move16(); @@ -697,21 +696,21 @@ void hvq_classifier_fx( } } - pindx = maximum_32_fx(L_input_abs, num_peak_cands, &L_m); + pindx = maximum_32_fx( L_input_abs, num_peak_cands, &L_m ); } *Npeaks = i; move16(); - IF ( GT_16(*Npeaks, HVQ_MIN_PEAKS)) + IF( GT_16( *Npeaks, HVQ_MIN_PEAKS ) ) { test(); - IF ( GT_16(num_sharp_bands, sub(nsub, 3))&&LE_16(*Npeaks,peak_th)) + IF( GT_16( num_sharp_bands, sub( nsub, 3 ) ) && LE_16( *Npeaks, peak_th ) ) { - sharp_dist = mult(sharp_dist, inv_nsub); /*x+15-15=x */ + sharp_dist = mult( sharp_dist, inv_nsub ); /*x+15-15=x */ test(); - IF ( LE_16(sharp_dist, SHARP_DIST_THRES_FX)&&*hvq_hangover<0) + IF( LE_16( sharp_dist, SHARP_DIST_THRES_FX ) && *hvq_hangover < 0 ) { - *hvq_hangover = add(*hvq_hangover, 1); + *hvq_hangover = add( *hvq_hangover, 1 ); } ELSE { @@ -732,7 +731,7 @@ void hvq_classifier_fx( { *hqswb_clas = HQ_HVQ; move16(); - *hvq_hangover = sub(*hvq_hangover, 1); + *hvq_hangover = sub( *hvq_hangover, 1 ); move16(); } ELSE @@ -750,7 +749,7 @@ void hvq_classifier_fx( } #ifndef ADD_IVAS_HQ_CODE - IF ( EQ_32(L_core_brate, HQ_24k40)) + IF( EQ_32( L_core_brate, HQ_24k40 ) ) { *Npeaks = s_min( HVQ_MAX_PEAKS_24k, *Npeaks ); move16(); @@ -761,7 +760,7 @@ void hvq_classifier_fx( move16(); } #else - *Npeaks = (int16_t)(min((core_brate * HVQ_PEAKS_PER_DELTA + HVQ_PEAKS_PER_DELTA_OFFS) / HVQ_PEAKS_BPS_DELTA, *Npeaks)); + *Npeaks = (int16_t) ( min( ( core_brate * HVQ_PEAKS_PER_DELTA + HVQ_PEAKS_PER_DELTA_OFFS ) / HVQ_PEAKS_BPS_DELTA, *Npeaks ) ); #endif } ELSE @@ -778,15 +777,15 @@ void hvq_classifier_fx( #ifdef ADD_IVAS_HQ_CODE /*--------------------------------------------------------------------------* -* hf_spectrum_sparseness() -* -* Detection of sparse spectrum in high band for activation of harmonic -* modes HQ_HARMONIC and HQ_HVQ -*--------------------------------------------------------------------------*/ + * hf_spectrum_sparseness() + * + * Detection of sparse spectrum in high band for activation of harmonic + * modes HQ_HARMONIC and HQ_HVQ + *--------------------------------------------------------------------------*/ /*! r: Harmonic decision for high band */ static int16_t hf_spectrum_sparseness( - Encoder_State* st, /* i/o: encoder state structure */ - const float* coefs /* i : MDCT spectrum */ + Encoder_State *st, /* i/o: encoder state structure */ + const float *coefs /* i : MDCT spectrum */ ) { int16_t i; @@ -798,71 +797,71 @@ static int16_t hf_spectrum_sparseness( float inv_rms; float crest; float crest_mod; - const float* p_num; - float* crest_lp; - float* crest_mod_lp; + const float *p_num; + float *crest_lp; + float *crest_mod_lp; int16_t result; crest_lp = &st->hHQ_core->crest_lp; crest_mod_lp = &st->hHQ_core->crest_mod_lp; result = TRUE; - if (st->element_mode != EVS_MONO) + if ( st->element_mode != EVS_MONO ) { - for (i = 0; i < L_SPEC_HB; i++) + for ( i = 0; i < L_SPEC_HB; i++ ) { - A[i] = (float)fabsf(coefs[i + L_SPEC_HB]); + A[i] = (float) fabsf( coefs[i + L_SPEC_HB] ); } low_count = 0; inv_rms = 0.0f; crest_mod = 0.0f; - maximum(A, L_SPEC_HB, &Amax); + maximum( A, L_SPEC_HB, &Amax ); thr = Amax * PEAK_THRESHOLD; movmean = 0.0f; /* avoid uninitialized warning */ p_num = &inv_tbl[HALF_WIN_LENGTH + 1]; /* Table for division 1./(11:21) */ - for (i = 0; i < L_SPEC_HB; i++) + for ( i = 0; i < L_SPEC_HB; i++ ) { inv_rms += A[i] * A[i]; - if (A[i] < thr) + if ( A[i] < thr ) { low_count += 1; } - if (i <= HALF_WIN_LENGTH) + if ( i <= HALF_WIN_LENGTH ) { - if (i == 0) + if ( i == 0 ) { - movmean = sum_f(&A[0], i + HALF_WIN_LENGTH + 1) * (*p_num); + movmean = sum_f( &A[0], i + HALF_WIN_LENGTH + 1 ) * ( *p_num ); } else { p_num++; - movmean = movmean + (A[i + HALF_WIN_LENGTH] - movmean) * (*p_num); + movmean = movmean + ( A[i + HALF_WIN_LENGTH] - movmean ) * ( *p_num ); } } else { - if (L_SPEC_HB <= i + HALF_WIN_LENGTH) + if ( L_SPEC_HB <= i + HALF_WIN_LENGTH ) { p_num--; - movmean = movmean + (movmean - A[i - HALF_WIN_LENGTH - 1]) * (*p_num); + movmean = movmean + ( movmean - A[i - HALF_WIN_LENGTH - 1] ) * ( *p_num ); } else { - movmean = movmean + (A[i + HALF_WIN_LENGTH] - A[i - HALF_WIN_LENGTH - 1]) * (*p_num); + movmean = movmean + ( A[i + HALF_WIN_LENGTH] - A[i - HALF_WIN_LENGTH - 1] ) * ( *p_num ); } } - if (crest_mod < movmean) + if ( crest_mod < movmean ) { crest_mod = movmean; } } - inv_rms = 1.0f / (float)sqrtf(inv_rms / L_SPEC_HB); + inv_rms = 1.0f / (float) sqrtf( inv_rms / L_SPEC_HB ); crest = Amax * inv_rms; crest_mod = crest_mod * inv_rms; - *crest_lp = HQ_CREST_FAC_SM * (*crest_lp) + (1.0f - HQ_CREST_FAC_SM) * crest; - *crest_mod_lp = HQ_CREST_FAC_SM * (*crest_mod_lp) + (1.0f - HQ_CREST_FAC_SM) * crest_mod; + *crest_lp = HQ_CREST_FAC_SM * ( *crest_lp ) + ( 1.0f - HQ_CREST_FAC_SM ) * crest; + *crest_mod_lp = HQ_CREST_FAC_SM * ( *crest_mod_lp ) + ( 1.0f - HQ_CREST_FAC_SM ) * crest_mod; - if (((*crest_lp) > HQ_CREST_THRESHOLD) && ((*crest_mod_lp) > HQ_CREST_MOD_THRESHOLD) && (low_count > LOW_COUNT_THRESHOLD)) + if ( ( ( *crest_lp ) > HQ_CREST_THRESHOLD ) && ( ( *crest_mod_lp ) > HQ_CREST_MOD_THRESHOLD ) && ( low_count > LOW_COUNT_THRESHOLD ) ) { result = FALSE; } diff --git a/lib_enc/hq_core_enc_fx.c b/lib_enc/hq_core_enc_fx.c index 0a89fb5d6..700ac8726 100644 --- a/lib_enc/hq_core_enc_fx.c +++ b/lib_enc/hq_core_enc_fx.c @@ -2,14 +2,14 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ +#include "options.h" /* Compilation switches */ #include "cnst.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ +#include "rom_com_fx.h" /* Static table prototypes */ #include "rom_com.h" /* Static table prototypes */ //#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------------- * hq_core_enc() @@ -28,10 +28,10 @@ void hq_core_enc_fx( { Word16 i, is_transient, num_bits, extra_unused; Word32 wtda_audio[2 * L_FRAME48k]; - Word32 t_audio[L_FRAME48k_EXT]; /* Q12 */ + Word32 t_audio[L_FRAME48k_EXT]; /* Q12 */ Word16 Q_audio = 0; Word16 inner_frame, input_frame; - Word16 ener_match; /* Q13/Q15 */ + Word16 ener_match; /* Q13/Q15 */ Word16 tmp; Word32 L_tmp; @@ -45,7 +45,7 @@ void hq_core_enc_fx( Word16 Aq_old[M + 1]; Word16 output[L_FRAME16k]; #endif - Word16 two_frames_buffer[2*L_FRAME48k]; + Word16 two_frames_buffer[2 * L_FRAME48k]; BSTR_ENC_HANDLE hBstr = st_fx->hBstr; set32_fx( t_audio, 0, L_FRAME48k ); @@ -56,9 +56,10 @@ void hq_core_enc_fx( input_frame = input_frame_orig; move16(); /* Sanity check, it should never happen at the encoder side (no BFI) */ - IF (EQ_16(st_fx->hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP)) + IF( EQ_16( st_fx->hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) ) { - st_fx->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW;; + st_fx->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; + ; move16(); } ELSE @@ -76,8 +77,8 @@ void hq_core_enc_fx( *--------------------------------------------------------------------------*/ /*num_bits = (short)(st->total_brate / 50); */ - Mpy_32_16_ss(st_fx->total_brate, 5243, &L_tmp, &lsb); /* 5243 is 1/50 in Q18. (0+18-15=3) */ - num_bits = extract_l(L_shr(L_tmp, 3)); /*Q0 */ + Mpy_32_16_ss( st_fx->total_brate, 5243, &L_tmp, &lsb ); /* 5243 is 1/50 in Q18. (0+18-15=3) */ + num_bits = extract_l( L_shr( L_tmp, 3 ) ); /*Q0 */ extra_unused = 0; move16(); @@ -85,11 +86,13 @@ void hq_core_enc_fx( * Detect signal transition *--------------------------------------------------------------------------*/ - is_transient = detect_transient_fx( audio, input_frame, 0, st_fx); + is_transient = detect_transient_fx( audio, input_frame, 0, st_fx ); #ifdef ADD_IVAS_HQ_CODE - test();test();test(); - IF (GT_16(st_fx->element_mode, EVS_MONO) && (EQ_16(st_fx->last_core, ACELP_CORE) || EQ_16(st_fx->last_core, AMR_WB_CORE))) + test(); + test(); + test(); + IF( GT_16( st_fx->element_mode, EVS_MONO ) && ( EQ_16( st_fx->last_core, ACELP_CORE ) || EQ_16( st_fx->last_core, AMR_WB_CORE ) ) ) { /*-------------------------------------------------------------------------- * IVAS switching frame @@ -98,16 +101,21 @@ void hq_core_enc_fx( L_spec = input_frame; left_overlap = -1; right_overlap = -1; - move16();move16();move16(); + move16(); + move16(); + move16(); - WindowSignal(&(st_fx->tcx_cfg), st_fx->hTcxCfg->tcx_offsetFB, TRANSITION_OVERLAP, FULL_OVERLAP, &left_overlap, &right_overlap, st_fx->hTcxEnc->speech_TCX, &L_spec, wtda_audio, 1, 1); - Q_audio = 16; move16(); /*tbv inspired from core_enc_ol*/ - TCX_MDCT(wtda_audio, t_audio, &Q_audio, left_overlap, sub(L_spec, shr( add(left_overlap, right_overlap), 1)), right_overlap, st_fx->element_mode); + WindowSignal( &( st_fx->tcx_cfg ), st_fx->hTcxCfg->tcx_offsetFB, TRANSITION_OVERLAP, FULL_OVERLAP, &left_overlap, &right_overlap, st_fx->hTcxEnc->speech_TCX, &L_spec, wtda_audio, 1, 1 ); + Q_audio = 16; + move16(); /*tbv inspired from core_enc_ol*/ + TCX_MDCT( wtda_audio, t_audio, &Q_audio, left_overlap, sub( L_spec, shr( add( left_overlap, right_overlap ), 1 ) ), right_overlap, st_fx->element_mode ); inner_frame = inner_frame_tbl[st_fx->bwidth]; L_spec = l_spec_ext_tbl[st_fx->bwidth]; is_transient = 0; - move16();move16();move16(); + move16(); + move16(); + move16(); } ELSE #endif @@ -117,48 +125,48 @@ void hq_core_enc_fx( * DCT transform *--------------------------------------------------------------------------*/ - Copy(st_fx->old_input_signal_fx, two_frames_buffer, input_frame); - Copy(audio, two_frames_buffer + input_frame, input_frame); + Copy( st_fx->old_input_signal_fx, two_frames_buffer, input_frame ); + Copy( audio, two_frames_buffer + input_frame, input_frame ); - wtda_fx(two_frames_buffer + input_frame, &Q_audio, wtda_audio, NULL, 0, - st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, input_frame); + wtda_fx( two_frames_buffer + input_frame, &Q_audio, wtda_audio, NULL, 0, + st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, input_frame ); test(); - IF(st_fx->last_core == ACELP_CORE || EQ_16(st_fx->last_core, AMR_WB_CORE)) + IF( st_fx->last_core == ACELP_CORE || EQ_16( st_fx->last_core, AMR_WB_CORE ) ) { /* Preprocessing in the first HQ frame after ACELP frame */ - core_switching_hq_prepare_enc_fx(st_fx, &num_bits, input_frame, wtda_audio, two_frames_buffer + input_frame); + core_switching_hq_prepare_enc_fx( st_fx, &num_bits, input_frame, wtda_audio, two_frames_buffer + input_frame ); /* During ACELP->HQ core switching, limit the HQ core bitrate to 48kbps */ - IF(GT_16(num_bits, ACELP_48k_BITS)) + IF( GT_16( num_bits, ACELP_48k_BITS ) ) { - extra_unused = sub(num_bits, ACELP_48k_BITS); + extra_unused = sub( num_bits, ACELP_48k_BITS ); num_bits = ACELP_48k_BITS; move16(); } } #ifndef ADD_IVAS_HQ_CODE /* subtract signalling bits */ - num_bits = sub(num_bits, hBstr->nb_bits_tot_fx); + num_bits = sub( num_bits, hBstr->nb_bits_tot_fx ); #endif - direct_transform_fx(wtda_audio, t_audio, is_transient, input_frame, &Q_audio, st_fx->element_mode); + direct_transform_fx( wtda_audio, t_audio, is_transient, input_frame, &Q_audio, st_fx->element_mode ); /* scale coefficients to their nominal level (8kHz) */ - IF(NE_16(input_frame, NORM_MDCT_FACTOR)) + IF( NE_16( input_frame, NORM_MDCT_FACTOR ) ) { - IF(EQ_16(input_frame, L_FRAME32k)) + IF( EQ_16( input_frame, L_FRAME32k ) ) { - Q_audio = add(Q_audio, 1); /* Divide by 2 */ + Q_audio = add( Q_audio, 1 ); /* Divide by 2 */ } ELSE { - tmp = mult_r(input_frame, 410 / 2); /* 1/8000 in Q15 */ + tmp = mult_r( input_frame, 410 / 2 ); /* 1/8000 in Q15 */ ener_match = hq_nominal_scaling[tmp]; - FOR(i = 0; i < input_frame; i++) + FOR( i = 0; i < input_frame; i++ ) { /*t_audio_q[i] *= ener_match; */ - Mpy_32_16_ss(t_audio[i], ener_match, &t_audio[i], &lsb); - move16(); /* Q12 */ + Mpy_32_16_ss( t_audio[i], ener_match, &t_audio[i], &lsb ); + move16(); /* Q12 */ } } } @@ -170,24 +178,24 @@ void hq_core_enc_fx( L_spec = l_spec_tbl[st_fx->bwidth]; move16(); #endif - IF(GT_16(input_frame, inner_frame)) + IF( GT_16( input_frame, inner_frame ) ) { - IF(EQ_16(is_transient, 1)) + IF( EQ_16( is_transient, 1 ) ) { - FOR(i = 1; i < NUM_TIME_SWITCHING_BLOCKS; i++) + FOR( i = 1; i < NUM_TIME_SWITCHING_BLOCKS; i++ ) { - tmp = i_mult2(i, shr(input_frame, 2)); - tmp = shr(inner_frame, 2); - Copy32(t_audio + i_mult2(i, shr(input_frame, 2)), t_audio + i_mult2(i, tmp), tmp); + tmp = i_mult2( i, shr( input_frame, 2 ) ); + tmp = shr( inner_frame, 2 ); + Copy32( t_audio + i_mult2( i, shr( input_frame, 2 ) ), t_audio + i_mult2( i, tmp ), tmp ); } } - set32_fx(t_audio + inner_frame, 0, sub(input_frame, inner_frame)); + set32_fx( t_audio + inner_frame, 0, sub( input_frame, inner_frame ) ); } } #ifdef ADD_IVAS_HQ_CODE_L_SPEC - /* subtract signalling bits */ - num_bits = sub(num_bits, hBstr->nb_bits_tot_fx); + /* subtract signalling bits */ + num_bits = sub( num_bits, hBstr->nb_bits_tot_fx ); #endif /*-------------------------------------------------------------------------- @@ -195,18 +203,18 @@ void hq_core_enc_fx( *--------------------------------------------------------------------------*/ #ifdef ADD_IVAS_HQ_CODE - IF (st_fx->bwidth_sw_cnt > 0) + IF( st_fx->bwidth_sw_cnt > 0 ) { - IF (is_transient) + IF( is_transient ) { - FOR (i = 0; i < NUM_TIME_SWITCHING_BLOCKS; i++) + FOR( i = 0; i < NUM_TIME_SWITCHING_BLOCKS; i++ ) { - v_multc(t_audio + i * inner_frame / NUM_TIME_SWITCHING_BLOCKS + L_FRAME16k / NUM_TIME_SWITCHING_BLOCKS, (float)(st->bwidth_sw_cnt) / (float)BWS_TRAN_PERIOD, t_audio + i * inner_frame / NUM_TIME_SWITCHING_BLOCKS + L_FRAME16k / NUM_TIME_SWITCHING_BLOCKS, inner_frame / NUM_TIME_SWITCHING_BLOCKS - L_FRAME16k / NUM_TIME_SWITCHING_BLOCKS); + v_multc( t_audio + i * inner_frame / NUM_TIME_SWITCHING_BLOCKS + L_FRAME16k / NUM_TIME_SWITCHING_BLOCKS, (float) ( st->bwidth_sw_cnt ) / (float) BWS_TRAN_PERIOD, t_audio + i * inner_frame / NUM_TIME_SWITCHING_BLOCKS + L_FRAME16k / NUM_TIME_SWITCHING_BLOCKS, inner_frame / NUM_TIME_SWITCHING_BLOCKS - L_FRAME16k / NUM_TIME_SWITCHING_BLOCKS ); } } ELSE { - v_multc(t_audio + L_FRAME16k, (float)(st->bwidth_sw_cnt) / (float)BWS_TRAN_PERIOD, t_audio + L_FRAME16k, L_spec - L_FRAME16k); + v_multc( t_audio + L_FRAME16k, (float) ( st->bwidth_sw_cnt ) / (float) BWS_TRAN_PERIOD, t_audio + L_FRAME16k, L_spec - L_FRAME16k ); } } #endif @@ -215,18 +223,17 @@ void hq_core_enc_fx( *--------------------------------------------------------------------------*/ test(); - IF ((EQ_16(st_fx->last_core, TCX_20_CORE) || EQ_16(st_fx->last_core, TCX_10_CORE) || EQ_16(st_fx->last_core, HQ_CORE)) && GT_32(st_fx->core_brate, MINIMUM_RATE_TO_ENCODE_VOICING_FLAG)) + IF( ( EQ_16( st_fx->last_core, TCX_20_CORE ) || EQ_16( st_fx->last_core, TCX_10_CORE ) || EQ_16( st_fx->last_core, HQ_CORE ) ) && GT_32( st_fx->core_brate, MINIMUM_RATE_TO_ENCODE_VOICING_FLAG ) ) { - IF ( Voicing_flag > 0 ) + IF( Voicing_flag > 0 ) { - push_indice_fx(hBstr, IND_HQ_VOICING_FLAG, 1, 1 ); - num_bits = sub(num_bits, 1); - + push_indice_fx( hBstr, IND_HQ_VOICING_FLAG, 1, 1 ); + num_bits = sub( num_bits, 1 ); } ELSE { - push_indice_fx(hBstr, IND_HQ_VOICING_FLAG, 0, 1 ); - num_bits = sub(num_bits, 1); + push_indice_fx( hBstr, IND_HQ_VOICING_FLAG, 0, 1 ); + num_bits = sub( num_bits, 1 ); } } @@ -234,12 +241,12 @@ void hq_core_enc_fx( * Transform-domain encoding *--------------------------------------------------------------------------*/ - IF ( EQ_16(hq_core_type, LOW_RATE_HQ_CORE)) + IF( EQ_16( hq_core_type, LOW_RATE_HQ_CORE ) ) { /* HQ low rate encoder */ - FOR (i = 0; i < inner_frame; i++) + FOR( i = 0; i < inner_frame; i++ ) { - t_audio[i] = L_shr(t_audio[i], sub(Q_audio, 12)); /* Q12 */ + t_audio[i] = L_shr( t_audio[i], sub( Q_audio, 12 ) ); /* Q12 */ } hq_lr_enc_fx( st_fx, t_audio, inner_frame, &num_bits, is_transient ); Q_audio = 12; @@ -248,75 +255,75 @@ void hq_core_enc_fx( ELSE { /* HQ high rate encoder */ - FOR (i = 0; i < inner_frame; i++) + FOR( i = 0; i < inner_frame; i++ ) { - t_audio[i] = L_shr(t_audio[i], sub(Q_audio, 12)); /* Q12 */ + t_audio[i] = L_shr( t_audio[i], sub( Q_audio, 12 ) ); /* Q12 */ } #ifdef ADD_IVAS_HQ_CODE_L_SPEC - hq_hr_enc_fx( st_fx, t_audio, L_spec, &num_bits, is_transient, vad_hover_flag); + hq_hr_enc_fx( st_fx, t_audio, L_spec, &num_bits, is_transient, vad_hover_flag ); #else - hq_hr_enc_fx(st_fx, t_audio, inner_frame, &num_bits, is_transient, vad_hover_flag); + hq_hr_enc_fx( st_fx, t_audio, inner_frame, &num_bits, is_transient, vad_hover_flag ); #endif Q_audio = 12; move16(); } /* write all unused bits to the bitstream */ - num_bits = add(num_bits, extra_unused); + num_bits = add( num_bits, extra_unused ); WHILE( num_bits >= 16 ) { - push_indice_fx(hBstr, IND_UNUSED, 0, 16 ); - num_bits = sub(num_bits, 16); + push_indice_fx( hBstr, IND_UNUSED, 0, 16 ); + num_bits = sub( num_bits, 16 ); } - IF ( num_bits != 0 ) + IF( num_bits != 0 ) { - push_indice_fx(hBstr, IND_UNUSED, 0, num_bits ); + push_indice_fx( hBstr, IND_UNUSED, 0, num_bits ); } #ifdef ADD_IVAS_HQ_CODE - if (st->element_mode > EVS_MONO && (st->last_core == ACELP_CORE || st->last_core == AMR_WB_CORE)) + if ( st->element_mode > EVS_MONO && ( st->last_core == ACELP_CORE || st->last_core == AMR_WB_CORE ) ) { overlap = st->hTcxCfg->tcx_mdct_window_length; - nz = NS2SA(st->sr_core, N_ZERO_MDCT_NS); - L_frame = (int16_t)(st->L_frame + st->hTcxCfg->tcx_offset - st->hTcxCfg->lfacNext); + nz = NS2SA( st->sr_core, N_ZERO_MDCT_NS ); + L_frame = (int16_t) ( st->L_frame + st->hTcxCfg->tcx_offset - st->hTcxCfg->lfacNext ); tcx_offset = st->hTcxCfg->lfacNext; - set_f(Aq_old, 0, M + 1); /* Dummy filter */ + set_f( Aq_old, 0, M + 1 ); /* Dummy filter */ Aq_old[0] = 1; /* Code taken from InternalTCXDecoder() */ - TCX_MDCT_Inverse(t_audio, wtda_audio, overlap, L_frame - overlap, overlap, st->element_mode); + TCX_MDCT_Inverse( t_audio, wtda_audio, overlap, L_frame - overlap, overlap, st->element_mode ); /* Window current frame */ - tcx_windowing_synthesis_current_frame(wtda_audio, st->hTcxCfg->tcx_aldo_window_2, st->hTcxCfg->tcx_mdct_window_half, st->hTcxCfg->tcx_mdct_window_minimum, overlap, /*st->hTcxCfg->tcx_mdct_window_length*/ st->hTcxCfg->tcx_mdct_window_half_length, st->hTcxCfg->tcx_mdct_window_min_length, st->last_core == ACELP_CORE, st->hTcxCfg->tcx_last_overlap_mode, /*left mode*/ st->hTcxEnc->acelp_zir, st->hTcxEnc->Txnq, NULL, Aq_old, st->hTcxCfg->tcx_mdct_window_trans, st->L_frame >> 1, tcx_offset < 0 ? -tcx_offset : 0, st->last_core, 0, 0); + tcx_windowing_synthesis_current_frame( wtda_audio, st->hTcxCfg->tcx_aldo_window_2, st->hTcxCfg->tcx_mdct_window_half, st->hTcxCfg->tcx_mdct_window_minimum, overlap, /*st->hTcxCfg->tcx_mdct_window_length*/ st->hTcxCfg->tcx_mdct_window_half_length, st->hTcxCfg->tcx_mdct_window_min_length, st->last_core == ACELP_CORE, st->hTcxCfg->tcx_last_overlap_mode, /*left mode*/ st->hTcxEnc->acelp_zir, st->hTcxEnc->Txnq, NULL, Aq_old, st->hTcxCfg->tcx_mdct_window_trans, st->L_frame >> 1, tcx_offset < 0 ? -tcx_offset : 0, st->last_core, 0, 0 ); /*Compute windowed synthesis in case of switching to ALDO windows in next frame*/ - mvr2r(wtda_audio + L_frame - nz, st->hTcxEnc->old_out, nz + overlap); - set_zero(st->hTcxEnc->old_out + nz + overlap, nz); + mvr2r( wtda_audio + L_frame - nz, st->hTcxEnc->old_out, nz + overlap ); + set_zero( st->hTcxEnc->old_out + nz + overlap, nz ); - tcx_windowing_synthesis_past_frame(st->hTcxEnc->old_out + nz, st->hTcxCfg->tcx_aldo_window_1_trunc, st->hTcxCfg->tcx_mdct_window_half, st->hTcxCfg->tcx_mdct_window_minimum, overlap, st->hTcxCfg->tcx_mdct_window_half_length, st->hTcxCfg->tcx_mdct_window_min_length, FULL_OVERLAP); + tcx_windowing_synthesis_past_frame( st->hTcxEnc->old_out + nz, st->hTcxCfg->tcx_aldo_window_1_trunc, st->hTcxCfg->tcx_mdct_window_half, st->hTcxCfg->tcx_mdct_window_minimum, overlap, st->hTcxCfg->tcx_mdct_window_half_length, st->hTcxCfg->tcx_mdct_window_min_length, FULL_OVERLAP ); - for (i = 0; i < nz; i++) + for ( i = 0; i < nz; i++ ) { st->hTcxEnc->old_out[nz + overlap + i] = wtda_audio[L_frame - 1 - i] * st->hTcxCfg->tcx_aldo_window_1_trunc[-1 - i]; } - mvr2r(wtda_audio + (overlap >> 1) - tcx_offset, output, st->L_frame); + mvr2r( wtda_audio + ( overlap >> 1 ) - tcx_offset, output, st->L_frame ); } else { - ener_match = (float)sqrt((float)L_FRAME16k / (float)NORM_MDCT_FACTOR); - v_multc(t_audio, ener_match, t_audio, inner_frame); + ener_match = (float) sqrt( (float) L_FRAME16k / (float) NORM_MDCT_FACTOR ); + v_multc( t_audio, ener_match, t_audio, inner_frame ); - inverse_transform(t_audio, wtda_audio, is_transient, L_FRAME16k, inner_frame, st->element_mode); + inverse_transform( t_audio, wtda_audio, is_transient, L_FRAME16k, inner_frame, st->element_mode ); - window_ola(wtda_audio, output, st->hTcxEnc->old_out, L_FRAME16k, st->hTcxCfg->tcx_last_overlap_mode, st->hTcxCfg->tcx_curr_overlap_mode, 0, 0, NULL); + window_ola( wtda_audio, output, st->hTcxEnc->old_out, L_FRAME16k, st->hTcxCfg->tcx_last_overlap_mode, st->hTcxCfg->tcx_curr_overlap_mode, 0, 0, NULL ); } - if (st->element_mode > EVS_MONO) + if ( st->element_mode > EVS_MONO ) { /* Store LB synthesis in case of switch to ACELP */ - mvr2r(output, st->hLPDmem->old_exc, L_FRAME16k); + mvr2r( output, st->hLPDmem->old_exc, L_FRAME16k ); } #endif @@ -341,27 +348,27 @@ void HQ_core_enc_init_fx( hHQ_core->hq_generic_speech_class = 0; move16(); hHQ_core->prev_Npeaks = 0; - set16_fx(hHQ_core->prev_peaks, 0, HVQ_MAX_PEAKS); + set16_fx( hHQ_core->prev_peaks, 0, HVQ_MAX_PEAKS ); hHQ_core->hvq_hangover = 0; hHQ_core->prev_hqswb_clas = HQ_NORMAL; - set16_fx(hHQ_core->prev_SWB_peak_pos, 0, SPT_SHORTEN_SBNUM); - set16_fx(hHQ_core->prev_frm_index, -1, NB_SWB_SUBBANDS_HAR_SEARCH_SB); + set16_fx( hHQ_core->prev_SWB_peak_pos, 0, SPT_SHORTEN_SBNUM ); + set16_fx( hHQ_core->prev_frm_index, -1, NB_SWB_SUBBANDS_HAR_SEARCH_SB ); hHQ_core->prev_frm_hfe2 = 0; move16(); hHQ_core->prev_stab_hfe2 = 0; move16(); hHQ_core->prev_ni_ratio_fx = 16384; move16(); /* 0.5 */ - set16_fx(hHQ_core->prev_En_sb_fx, 0, NB_SWB_SUBBANDS); - set16_fx(hHQ_core->last_bitalloc_max_band, 0, 2); - set32_fx(hHQ_core->last_ni_gain_fx, 0, BANDS_MAX); - set16_fx(hHQ_core->last_env_fx, 0, BANDS_MAX); + set16_fx( hHQ_core->prev_En_sb_fx, 0, NB_SWB_SUBBANDS ); + set16_fx( hHQ_core->last_bitalloc_max_band, 0, 2 ); + set32_fx( hHQ_core->last_ni_gain_fx, 0, BANDS_MAX ); + set16_fx( hHQ_core->last_env_fx, 0, BANDS_MAX ); hHQ_core->last_max_pos_pulse = 0; move16(); - //hHQ_core->crest_lp = HQ_CREST_THRESHOLD; IVAS_CODE - //hHQ_core->crest_mod_lp = HQ_CREST_MOD_THRESHOLD;IVAS_CODE + // hHQ_core->crest_lp = HQ_CREST_THRESHOLD; IVAS_CODE + // hHQ_core->crest_mod_lp = HQ_CREST_MOD_THRESHOLD;IVAS_CODE return; } diff --git a/lib_enc/hq_env_enc_fx.c b/lib_enc/hq_env_enc_fx.c index 0dc9ac761..d64685dda 100644 --- a/lib_enc/hq_env_enc_fx.c +++ b/lib_enc/hq_env_enc_fx.c @@ -3,14 +3,14 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ +#include "options.h" /* Compilation switches */ //#include "prot_fx.h" /* Function prototypes */ #include "rom_enc.h" #include "rom_com.h" #include "stl.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*--------------------------------------------------------------------------------------* * encode_envelope_indices_fx() @@ -18,24 +18,24 @@ * Encode envelope indices *--------------------------------------------------------------------------------------*/ -Word16 encode_envelope_indices_fx( /* o : Number of bits if flag_pack=0,0 if flag_pack=1 Q0 */ - BSTR_ENC_HANDLE hBstr, /* i : handle to the bitstream */ - const Word16 num_sfm, /* i : Number of subbands Q0 */ - const Word16 numnrmibits, /* i : Bitrate of fall-back coding mode Q0 */ - Word16 *difidx, /* i/o: Diff indices/encoded diff indices Q0 */ - Word16 *LCmode, /* o : Coding mode if flag_pack=0, i : if flag_pack=1 Q0 */ - const Word16 flag_pack, /* i : indicator of packing or estimating bits Q0 */ - const Word16 flag_HQ2, /* i : indicator of HQ2 core Q0 */ - const Word16 is_transient /* i : indicator of HQ_TRANSIENT Q0 */ +Word16 encode_envelope_indices_fx( /* o : Number of bits if flag_pack=0,0 if flag_pack=1 Q0 */ + BSTR_ENC_HANDLE hBstr, /* i : handle to the bitstream */ + const Word16 num_sfm, /* i : Number of subbands Q0 */ + const Word16 numnrmibits, /* i : Bitrate of fall-back coding mode Q0 */ + Word16 *difidx, /* i/o: Diff indices/encoded diff indices Q0 */ + Word16 *LCmode, /* o : Coding mode if flag_pack=0, i : if flag_pack=1 Q0 */ + const Word16 flag_pack, /* i : indicator of packing or estimating bits Q0 */ + const Word16 flag_HQ2, /* i : indicator of HQ2 core Q0 */ + const Word16 is_transient /* i : indicator of HQ_TRANSIENT Q0 */ ) { Word16 bits; Word16 prevj; Word16 hcode_l; - Word16 i,j; + Word16 i, j; Word16 difidx_flag; Word16 index_max, index_min, index_rad; - Word16 difidx_org[NB_SFM]; /* length of this buffer is max(BANDS_MAX,NB_SFM) */ + Word16 difidx_org[NB_SFM]; /* length of this buffer is max(BANDS_MAX,NB_SFM) */ Word16 m, r; Word16 v, k; @@ -53,10 +53,10 @@ Word16 encode_envelope_indices_fx( /* o : Number of bits if flag_pack=0,0 if f /* LC mode 1 = resized huffman coding */ /* LC mode 2 = normal Huffman Coding */ /* LC mode 3 = bit packing */ - IF ( flag_pack == 0 ) + IF( flag_pack == 0 ) { test(); - IF( is_transient && EQ_16(flag_HQ2, LOW_RATE_HQ_CORE_TRAN)) + IF( is_transient && EQ_16( flag_HQ2, LOW_RATE_HQ_CORE_TRAN ) ) { bits = 0; move16(); @@ -64,62 +64,62 @@ Word16 encode_envelope_indices_fx( /* o : Number of bits if flag_pack=0,0 if f move16(); index_min = 31; move16(); - FOR( i = 0; i< num_sfm; i++ ) + FOR( i = 0; i < num_sfm; i++ ) { - IF( GT_16(difidx[i], index_max)) + IF( GT_16( difidx[i], index_max ) ) { index_max = difidx[i]; move16(); } - IF( LT_16(difidx[i], index_min)) + IF( LT_16( difidx[i], index_min ) ) { index_min = difidx[i]; move16(); } } test(); - IF(GT_16(index_min, 10)&<_16(index_max,22)) + IF( GT_16( index_min, 10 ) && LT_16( index_max, 22 ) ) { FOR( i = 1; i < num_sfm; i++ ) { j = difidx[i]; move16(); - bits = add(bits, huffsizn_tran[j]); + bits = add( bits, huffsizn_tran[j] ); } } - hcode_l= 0; + hcode_l = 0; move16(); *LCmode = 0; move16(); - prevj = add(difidx[0], OFFSET_NORM); + prevj = add( difidx[0], OFFSET_NORM ); /* LC mode 0 = Context based coding */ FOR( i = 1; i < num_sfm; i++ ) { j = difidx[i]; move16(); - IF( GT_16(prevj, HTH_NORM)) + IF( GT_16( prevj, HTH_NORM ) ) { /* above */ - hcode_l = add(hcode_l, huffsizn_n[31-j]); + hcode_l = add( hcode_l, huffsizn_n[31 - j] ); } ELSE { - IF( LT_16(prevj, LTH_NORM)) + IF( LT_16( prevj, LTH_NORM ) ) { /* less */ - hcode_l = add(hcode_l, huffsizn_n[j]); + hcode_l = add( hcode_l, huffsizn_n[j] ); } ELSE { /* equal */ - hcode_l = add(hcode_l, huffsizn_e[j]); + hcode_l = add( hcode_l, huffsizn_e[j] ); } } prevj = j; move16(); } test(); - IF( GE_16(hcode_l, bits)&&bits!=0) + IF( GE_16( hcode_l, bits ) && bits != 0 ) { /* LC mode 1 Transient Huffman Coding */ *LCmode = 1; @@ -131,29 +131,29 @@ Word16 encode_envelope_indices_fx( /* o : Number of bits if flag_pack=0,0 if f ELSE { /* Check bits if LC mode == 3 -> Check bits if LC mode == 0 */ - hcode_l= 0; + hcode_l = 0; move16(); - prevj = add(difidx[0], OFFSET_NORM); + prevj = add( difidx[0], OFFSET_NORM ); FOR( i = 1; i < num_sfm; i++ ) { j = difidx[i]; move16(); - IF( GT_16(prevj, HTH_NORM)) + IF( GT_16( prevj, HTH_NORM ) ) { /* above */ - hcode_l = add(hcode_l, huffsizn_n[sub(31,j)]); + hcode_l = add( hcode_l, huffsizn_n[sub( 31, j )] ); } ELSE { - IF( LT_16(prevj, LTH_NORM)) + IF( LT_16( prevj, LTH_NORM ) ) { /* less */ - hcode_l = add(hcode_l, huffsizn_n[j]); + hcode_l = add( hcode_l, huffsizn_n[j] ); } ELSE { /* equal */ - hcode_l = add(hcode_l, huffsizn_e[j]); + hcode_l = add( hcode_l, huffsizn_e[j] ); } } prevj = j; @@ -173,19 +173,19 @@ Word16 encode_envelope_indices_fx( /* o : Number of bits if flag_pack=0,0 if f { j = difidx[i]; move16(); - bits = add(bits, huffsizn[j]); + bits = add( bits, huffsizn[j] ); } /*------------------------------------------------------------------------------* * comparing bit expenses of coding mode 2 with that of the optimal coding mode *------------------------------------------------------------------------------*/ - if( GT_16(hcode_l, bits)) + if ( GT_16( hcode_l, bits ) ) { *LCmode = 2; move16(); } - hcode_l = s_min(hcode_l, bits); + hcode_l = s_min( hcode_l, bits ); } /* Check bits if LC mode == 2 -> Check bits if LC mode == 1 */ @@ -205,11 +205,11 @@ Word16 encode_envelope_indices_fx( /* o : Number of bits if flag_pack=0,0 if f move16(); FOR( i = 2; i < num_sfm; i++ ) { - IF( GT_16(difidx_org[i-1], 17)) + IF( GT_16( difidx_org[i - 1], 17 ) ) { - difidx[i] = add(difidx_org[i], s_min(sub(difidx_org[i-1],17),3)); + difidx[i] = add( difidx_org[i], s_min( sub( difidx_org[i - 1], 17 ), 3 ) ); move16(); - IF( GT_16(difidx[i], 31)) + IF( GT_16( difidx[i], 31 ) ) { difidx_flag = 1; move16(); @@ -217,9 +217,9 @@ Word16 encode_envelope_indices_fx( /* o : Number of bits if flag_pack=0,0 if f } } - IF( LT_16(difidx_org[i-1], 13)) + IF( LT_16( difidx_org[i - 1], 13 ) ) { - difidx[i] = add(difidx_org[i], s_max(sub(difidx_org[i-1],13),-3)); + difidx[i] = add( difidx_org[i], s_max( sub( difidx_org[i - 1], 13 ), -3 ) ); move16(); IF( difidx[i] < 0 ) { @@ -234,34 +234,33 @@ Word16 encode_envelope_indices_fx( /* o : Number of bits if flag_pack=0,0 if f move16(); IF( difidx_flag == 0 ) { - FOR( i = 1; i< num_sfm; i++ ) + FOR( i = 1; i < num_sfm; i++ ) { - index_max = s_max(index_max, difidx[i]); - index_min = s_min(index_min, difidx[i]); + index_max = s_max( index_max, difidx[i] ); + index_min = s_min( index_min, difidx[i] ); } - index_rad = s_max(sub(15, index_min),sub(index_max, 15)); + index_rad = s_max( sub( 15, index_min ), sub( index_max, 15 ) ); - IF( LE_16(index_rad, HUFF_THR)) + IF( LE_16( index_rad, HUFF_THR ) ) { FOR( i = 1; i < num_sfm; i++ ) { j = difidx[i]; move16(); - bits = add(bits, resize_huffsizn[j]); + bits = add( bits, resize_huffsizn[j] ); } /*------------------------------------------------------------------* * comparing bit expenses of coding mode 1 with that of coding mode 0 *------------------------------------------------------------------*/ - if( GT_16(hcode_l, bits)) + if ( GT_16( hcode_l, bits ) ) { *LCmode = 1; move16(); } - hcode_l = s_min(hcode_l, bits); - + hcode_l = s_min( hcode_l, bits ); } } @@ -272,19 +271,19 @@ Word16 encode_envelope_indices_fx( /* o : Number of bits if flag_pack=0,0 if f * comparing bit expenses of coding mode 3 with that of the optimal coding mode *------------------------------------------------------------------------------*/ - if( GE_16(hcode_l, numnrmibits)) + if ( GE_16( hcode_l, numnrmibits ) ) { *LCmode = 3; move16(); } - hcode_l = s_min(hcode_l, numnrmibits); + hcode_l = s_min( hcode_l, numnrmibits ); } test(); test(); - IF( (NE_16(*LCmode, 1)&&flag_HQ2==NORMAL_HQ_CORE)||EQ_16(flag_HQ2,LOW_RATE_HQ_CORE)) + IF( ( NE_16( *LCmode, 1 ) && flag_HQ2 == NORMAL_HQ_CORE ) || EQ_16( flag_HQ2, LOW_RATE_HQ_CORE ) ) { - FOR(i = 2; i< num_sfm; i++) + FOR( i = 2; i < num_sfm; i++ ) { difidx[i] = difidx_org[i]; move16(); @@ -295,10 +294,10 @@ Word16 encode_envelope_indices_fx( /* o : Number of bits if flag_pack=0,0 if f ELSE { test(); - IF( EQ_16(flag_HQ2, LOW_RATE_HQ_CORE_TRAN)||EQ_16(flag_HQ2,LOW_RATE_HQ_CORE)) + IF( EQ_16( flag_HQ2, LOW_RATE_HQ_CORE_TRAN ) || EQ_16( flag_HQ2, LOW_RATE_HQ_CORE ) ) { - push_indice_fx( hBstr, IND_HQ2_DENG_HMODE, *LCmode, BITS_DE_HMODE); - push_indice_fx( hBstr, IND_HQ2_DIFF_ENERGY, difidx[0], BITS_DE_FCOMP); + push_indice_fx( hBstr, IND_HQ2_DENG_HMODE, *LCmode, BITS_DE_HMODE ); + push_indice_fx( hBstr, IND_HQ2_DIFF_ENERGY, difidx[0], BITS_DE_FCOMP ); } ELSE { @@ -307,11 +306,11 @@ Word16 encode_envelope_indices_fx( /* o : Number of bits if flag_pack=0,0 if f } test(); - IF(is_transient && EQ_16(flag_HQ2, LOW_RATE_HQ_CORE_TRAN)) + IF( is_transient && EQ_16( flag_HQ2, LOW_RATE_HQ_CORE_TRAN ) ) { hcode_l = 0; move16(); - IF ( EQ_16(*LCmode, 1)) + IF( EQ_16( *LCmode, 1 ) ) { /* LC mode 0 Transient Huffman Coding */ FOR( i = 1; i < num_sfm; i++ ) @@ -328,34 +327,34 @@ Word16 encode_envelope_indices_fx( /* o : Number of bits if flag_pack=0,0 if f /* Bit reverse */ FOR( k = 0; k < r; k++ ) { - v = lshl(v, 1); - v = s_or(v, s_and(m, 1)); - m = lshr(m, 1); + v = lshl( v, 1 ); + v = s_or( v, s_and( m, 1 ) ); + m = lshr( m, 1 ); } - push_indice_fx(hBstr, IND_HQ2_DIFF_ENERGY, v, r); + push_indice_fx( hBstr, IND_HQ2_DIFF_ENERGY, v, r ); } } ELSE { /* LC mode 1 context based Coding */ - prevj = add(difidx[0], OFFSET_NORM); + prevj = add( difidx[0], OFFSET_NORM ); FOR( i = 1; i < num_sfm; i++ ) { j = difidx[i]; move16(); - IF( GT_16(prevj, HTH_NORM)) + IF( GT_16( prevj, HTH_NORM ) ) { /* above */ - r = huffsizn_n[sub(31,j)]; + r = huffsizn_n[sub( 31, j )]; move16(); - m = huffnorm_n[sub(31,j)]; + m = huffnorm_n[sub( 31, j )]; move16(); } ELSE { - IF( LT_16(prevj, LTH_NORM)) + IF( LT_16( prevj, LTH_NORM ) ) { /* less */ r = huffsizn_n[j]; @@ -372,7 +371,7 @@ Word16 encode_envelope_indices_fx( /* o : Number of bits if flag_pack=0,0 if f move16(); } } - push_indice_fx(hBstr, IND_HQ2_DIFF_ENERGY, m, r); + push_indice_fx( hBstr, IND_HQ2_DIFF_ENERGY, m, r ); prevj = j; move16(); } @@ -382,26 +381,26 @@ Word16 encode_envelope_indices_fx( /* o : Number of bits if flag_pack=0,0 if f { hcode_l = 0; move16(); - IF ( *LCmode == 0 ) + IF( *LCmode == 0 ) { /* LC mode 3 -> LC mode 0 */ - prevj = add(difidx[0], OFFSET_NORM); + prevj = add( difidx[0], OFFSET_NORM ); FOR( i = 1; i < num_sfm; i++ ) { j = difidx[i]; move16(); - IF( GT_16(prevj, HTH_NORM)) + IF( GT_16( prevj, HTH_NORM ) ) { /* above */ - r = huffsizn_n[sub(31,j)]; + r = huffsizn_n[sub( 31, j )]; move16(); - m = huffnorm_n[sub(31,j)]; + m = huffnorm_n[sub( 31, j )]; move16(); } ELSE { - IF( LT_16(prevj, LTH_NORM)) + IF( LT_16( prevj, LTH_NORM ) ) { /* less */ r = huffsizn_n[j]; @@ -419,9 +418,9 @@ Word16 encode_envelope_indices_fx( /* o : Number of bits if flag_pack=0,0 if f } } - IF( EQ_16(flag_HQ2, LOW_RATE_HQ_CORE)) + IF( EQ_16( flag_HQ2, LOW_RATE_HQ_CORE ) ) { - push_indice_fx(hBstr, IND_HQ2_DIFF_ENERGY, m, r); + push_indice_fx( hBstr, IND_HQ2_DIFF_ENERGY, m, r ); } ELSE { @@ -432,27 +431,27 @@ Word16 encode_envelope_indices_fx( /* o : Number of bits if flag_pack=0,0 if f move16(); } } - ELSE IF( EQ_16(*LCmode, 1)) + ELSE IF( EQ_16( *LCmode, 1 ) ) { - IF ( EQ_16(flag_HQ2, 1)) + IF( EQ_16( flag_HQ2, 1 ) ) { index_max = 0; move16(); index_min = 31; move16(); - FOR(i = 1; i< num_sfm; i++) + FOR( i = 1; i < num_sfm; i++ ) { difidx_org[i] = difidx[i]; move16(); } - FOR(i = 2; i< num_sfm; i++) + FOR( i = 2; i < num_sfm; i++ ) { - IF(GT_16(difidx_org[i-1], 17)) + IF( GT_16( difidx_org[i - 1], 17 ) ) { - difidx[i] = add(difidx_org[i], s_min(sub(difidx_org[i-1],17),3)); + difidx[i] = add( difidx_org[i], s_min( sub( difidx_org[i - 1], 17 ), 3 ) ); move16(); - IF(GT_16(difidx[i], 31)) + IF( GT_16( difidx[i], 31 ) ) { difidx_flag = 1; move16(); @@ -460,11 +459,11 @@ Word16 encode_envelope_indices_fx( /* o : Number of bits if flag_pack=0,0 if f } } - IF(LT_16(difidx_org[i-1], 13)) + IF( LT_16( difidx_org[i - 1], 13 ) ) { - difidx[i] = add(difidx_org[i], s_max(sub(difidx_org[i-1],13),-3)); + difidx[i] = add( difidx_org[i], s_max( sub( difidx_org[i - 1], 13 ), -3 ) ); move16(); - IF(difidx[i] < 0) + IF( difidx[i] < 0 ) { difidx_flag = 1; move16(); @@ -475,17 +474,17 @@ Word16 encode_envelope_indices_fx( /* o : Number of bits if flag_pack=0,0 if f IF( difidx_flag == 0 ) { - FOR(i = 1; i< num_sfm; i++) + FOR( i = 1; i < num_sfm; i++ ) { - index_max = s_max(index_max, difidx[i]); - index_min = s_min(index_min, difidx[i]); + index_max = s_max( index_max, difidx[i] ); + index_min = s_min( index_min, difidx[i] ); } - index_rad = s_max(sub(15, index_min),sub(index_max, 15)); + index_rad = s_max( sub( 15, index_min ), sub( index_max, 15 ) ); - IF(LE_16(index_rad, HUFF_THR)) + IF( LE_16( index_rad, HUFF_THR ) ) { - FOR (i = 1; i < num_sfm; i++) + FOR( i = 1; i < num_sfm; i++ ) { j = difidx[i]; move16(); @@ -510,22 +509,22 @@ Word16 encode_envelope_indices_fx( /* o : Number of bits if flag_pack=0,0 if f /* Bit reverse */ FOR( k = 0; k < r; k++ ) { - v = lshl(v, 1); - v = s_or(v,s_and(m, 1)); - m = lshr(m, 1); + v = lshl( v, 1 ); + v = s_or( v, s_and( m, 1 ) ); + m = lshr( m, 1 ); } - IF ( flag_HQ2 == 0 ) + IF( flag_HQ2 == 0 ) { push_indice_fx( hBstr, IND_YNRM, v, r ); } ELSE { - push_indice_fx( hBstr, IND_HQ2_DIFF_ENERGY, v, r); + push_indice_fx( hBstr, IND_HQ2_DIFF_ENERGY, v, r ); } } } - ELSE IF( EQ_16(*LCmode, 2)) + ELSE IF( EQ_16( *LCmode, 2 ) ) { /* LC mode 1 -> LC mode 2 */ FOR( i = 1; i < num_sfm; i++ ) @@ -589,7 +588,7 @@ void diff_envelope_coding_fx( difidx[0] = ynrm[start_norm]; move16(); - tmp = add(start_norm, num_env_bands); + tmp = add( start_norm, num_env_bands ); FOR( i = start_norm; i < tmp; i++ ) { normqlg2[i] = dicnlg2[ynrm[i]]; diff --git a/lib_enc/hq_hr_enc_fx.c b/lib_enc/hq_hr_enc_fx.c index af7df7e62..3049e6c21 100644 --- a/lib_enc/hq_hr_enc_fx.c +++ b/lib_enc/hq_hr_enc_fx.c @@ -2,14 +2,14 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ //#include "prot_fx.h" /* Function prototypes */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "rom_com_fx.h" /* Static table prototypes */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*--------------------------------------------------------------------------* * hq_hr_enc_fx() @@ -17,39 +17,39 @@ * HQ High rate encoding routine *--------------------------------------------------------------------------*/ void hq_hr_enc_fx( - Encoder_State *st_fx, /* i/o: encoder state structure fx */ - Word32 *t_audio, /* i/o: transform-domain coefficients Q12 */ - const Word16 length, /* i : length of spectrum Q0 */ - Word16 *num_bits, /* i : number of available bits Q0 */ - const Word16 is_transient, /* i : transient flag Q0 */ - const Word16 vad_hover_flag /* i : VAD hangover flag */ + Encoder_State *st_fx, /* i/o: encoder state structure fx */ + Word32 *t_audio, /* i/o: transform-domain coefficients Q12 */ + const Word16 length, /* i : length of spectrum Q0 */ + Word16 *num_bits, /* i : number of available bits Q0 */ + const Word16 is_transient, /* i : transient flag Q0 */ + const Word16 vad_hover_flag /* i : VAD hangover flag */ ) { - Word16 nb_sfm; /* Q0 */ - Word16 sum, hcode_l; /* Q0 */ - Word16 difidx[NB_SFM]; /* Q0 */ - Word16 normqlg2[NB_SFM], ynrm[NB_SFM]; /* Q0 */ - Word16 nf_idx; /* Q0 */ - Word16 bits; /* */ - Word16 LCmode; /* Q0 */ - Word16 shape_bits, num_sfm, numnrmibits; /* Q0 */ - Word16 hqswb_clas; /* Q0 */ - Word16 num_env_bands; /* Q0 */ - Word16 Npeaks, start_norm; /* Q0 */ - Word16 difidx_org[NB_SFM]; /* Q0 */ - Word16 R[NB_SFM]; /* Q0 */ - Word16 peaks[HVQ_MAX_PEAKS]; /* Q0 */ - Word16 sfmsize[NB_SFM], sfm_start[NB_SFM], sfm_end[NB_SFM]; /* Q0 */ - Word16 npulses[NB_SFM], maxpulse[NB_SFM]; /* Q0 */ - Word16 Rsubband[NB_SFM]; /* Q3 */ - Word32 t_audio_q[L_SPEC48k_EXT]; /* Q12 */ - Word32 nf_gains[HVQ_NF_GROUPS]; /* Q12 */ - Word32 pe_gains[HVQ_NF_GROUPS]; /* Q12 */ - Word16 noise_level[HVQ_BWE_NOISE_BANDS]; /* Q15 */ - Word16 hq_generic_offset; /* Q0 */ - Word16 hq_generic_fenv[HQ_FB_FENV]; /* Q1 */ - Word16 hq_generic_exc_clas = 0; /* Q0 */ - Word16 core_sfm; /* Q0 */ + Word16 nb_sfm; /* Q0 */ + Word16 sum, hcode_l; /* Q0 */ + Word16 difidx[NB_SFM]; /* Q0 */ + Word16 normqlg2[NB_SFM], ynrm[NB_SFM]; /* Q0 */ + Word16 nf_idx; /* Q0 */ + Word16 bits; /* */ + Word16 LCmode; /* Q0 */ + Word16 shape_bits, num_sfm, numnrmibits; /* Q0 */ + Word16 hqswb_clas; /* Q0 */ + Word16 num_env_bands; /* Q0 */ + Word16 Npeaks, start_norm; /* Q0 */ + Word16 difidx_org[NB_SFM]; /* Q0 */ + Word16 R[NB_SFM]; /* Q0 */ + Word16 peaks[HVQ_MAX_PEAKS]; /* Q0 */ + Word16 sfmsize[NB_SFM], sfm_start[NB_SFM], sfm_end[NB_SFM]; /* Q0 */ + Word16 npulses[NB_SFM], maxpulse[NB_SFM]; /* Q0 */ + Word16 Rsubband[NB_SFM]; /* Q3 */ + Word32 t_audio_q[L_SPEC48k_EXT]; /* Q12 */ + Word32 nf_gains[HVQ_NF_GROUPS]; /* Q12 */ + Word32 pe_gains[HVQ_NF_GROUPS]; /* Q12 */ + Word16 noise_level[HVQ_BWE_NOISE_BANDS]; /* Q15 */ + Word16 hq_generic_offset; /* Q0 */ + Word16 hq_generic_fenv[HQ_FB_FENV]; /* Q1 */ + Word16 hq_generic_exc_clas = 0; /* Q0 */ + Word16 core_sfm; /* Q0 */ Word16 har_freq_est1, har_freq_est2; Word16 flag_dis; const Word16 *subband_search_offset; @@ -69,7 +69,7 @@ void hq_hr_enc_fx( *------------------------------------------------------------------*/ Npeaks = 0; - Q_audio = 0; /* to avoid compilation warnings */ + Q_audio = 0; /* to avoid compilation warnings */ set16_fx( npulses, 0, NB_SFM ); set16_fx( maxpulse, 0, NB_SFM ); @@ -90,30 +90,30 @@ void hq_hr_enc_fx( bits = hq_classifier_enc_fx( st_fx, length, t_audio, is_transient, &Npeaks, peaks, pe_gains, nf_gains, &hqswb_clas ); - *num_bits = sub(*num_bits, bits); + *num_bits = sub( *num_bits, bits ); /*------------------------------------------------------------------* * set quantization parameters *------------------------------------------------------------------*/ hq_configure_evs_fx( length, hqswb_clas, st_fx->core_brate, &num_sfm, &nb_sfm, &start_norm, &num_env_bands, &numnrmibits, &hq_generic_offset, - sfmsize, sfm_start, sfm_end ); + sfmsize, sfm_start, sfm_end ); /*------------------------------------------------------------------* * Transient frame handling *------------------------------------------------------------------*/ /* Interleave MLT coefficients of 4 sub-vectors in case of transient */ - IF( EQ_16( is_transient, 1 )) + IF( EQ_16( is_transient, 1 ) ) { interleave_spectrum_fx( t_audio, length ); } test(); - IF (EQ_16(st_fx->element_mode, IVAS_CPE_DFT) || EQ_16(st_fx->element_mode, IVAS_CPE_TD)) + IF( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) { - calculate_hangover_attenuation_gain_fx(st_fx, &att, vad_hover_flag); - v_multc_att32(t_audio, att, t_audio, sfm_end[sub(num_sfm, 1)]); + calculate_hangover_attenuation_gain_fx( st_fx, &att, vad_hover_flag ); + v_multc_att32( t_audio, att, t_audio, sfm_end[sub( num_sfm, 1 )] ); } /*------------------------------------------------------------------* * Scalar quantization of norms @@ -124,26 +124,26 @@ void hq_hr_enc_fx( calc_norm_fx( t_audio, 12, ynrm, normqlg2, start_norm, num_env_bands, sfmsize, sfm_start ); /* create differential code of quantized norm indices */ - diff_envelope_coding_fx(is_transient, num_env_bands, start_norm, ynrm, normqlg2, difidx); + diff_envelope_coding_fx( is_transient, num_env_bands, start_norm, ynrm, normqlg2, difidx ); /* Find coding mode and calculate bit rate */ hcode_l = encode_envelope_indices_fx( st_fx->hBstr, num_env_bands, numnrmibits, difidx, &LCmode, 0, NORMAL_HQ_CORE, is_transient ); - *num_bits = sub(*num_bits, add( hcode_l, NORM0_BITS + FLAGS_BITS ) ); + *num_bits = sub( *num_bits, add( hcode_l, NORM0_BITS + FLAGS_BITS ) ); /* Encode norm indices */ encode_envelope_indices_fx( st_fx->hBstr, num_env_bands, numnrmibits, difidx, &LCmode, 1, NORMAL_HQ_CORE, is_transient ); /*------------------------------------------------------------------* - * HQ Generic HF encoding - *------------------------------------------------------------------*/ + * HQ Generic HF encoding + *------------------------------------------------------------------*/ test(); - IF ( EQ_16( hqswb_clas, HQ_GEN_SWB )||EQ_16(hqswb_clas,HQ_GEN_FB)) + IF( EQ_16( hqswb_clas, HQ_GEN_SWB ) || EQ_16( hqswb_clas, HQ_GEN_FB ) ) { - hq_generic_encoding_fx(t_audio, hq_generic_fenv, hq_generic_offset, st_fx, &hq_generic_exc_clas/*, length*/); - IF (EQ_16(hq_generic_exc_clas , HQ_GENERIC_SP_EXC)) + hq_generic_encoding_fx( t_audio, hq_generic_fenv, hq_generic_offset, st_fx, &hq_generic_exc_clas /*, length*/ ); + IF( EQ_16( hq_generic_exc_clas, HQ_GENERIC_SP_EXC ) ) { - *num_bits = add(*num_bits,1); /* conditional 1 bit saving for representing FD3 BWE excitation class */ + *num_bits = add( *num_bits, 1 ); /* conditional 1 bit saving for representing FD3 BWE excitation class */ } map_hq_generic_fenv_norm_fx( hqswb_clas, hq_generic_fenv, ynrm, normqlg2, num_env_bands, nb_sfm, hq_generic_offset ); } @@ -161,7 +161,7 @@ void hq_hr_enc_fx( IF( hqswb_clas != HQ_HVQ ) { test(); - IF (hqswb_clas == HQ_GEN_SWB || hqswb_clas == HQ_GEN_FB) + IF( hqswb_clas == HQ_GEN_SWB || hqswb_clas == HQ_GEN_FB ) { b_delta_env = calc_nor_delta_hf_fx( st_fx->hBstr, t_audio, ynrm, Rsubband, num_env_bands, nb_sfm, sfmsize, sfm_start, core_sfm ); sum -= b_delta_env; @@ -173,20 +173,20 @@ void hq_hr_enc_fx( /*------------------------------------------------------------------* * Quantize/code spectral fine structure using PVQ or HVQ *------------------------------------------------------------------*/ - IF( EQ_16( hqswb_clas, HQ_HVQ)) + IF( EQ_16( hqswb_clas, HQ_HVQ ) ) { sum = hvq_enc_fx( st_fx, st_fx->core_brate, *num_bits, Npeaks, ynrm, R, peaks, nf_gains, noise_level, pe_gains, t_audio, t_audio_q ); - *num_bits = sub(*num_bits, sum); + *num_bits = sub( *num_bits, sum ); } ELSE { shape_bits = pvq_core_enc_fx( st_fx->hBstr, t_audio_norm, t_audio_q_norm, &Q_audio, sum, nb_sfm, sfm_start, sfm_end, sfmsize, Rsubband, R, - npulses, maxpulse, HQ_CORE ); - *num_bits = add( *num_bits, sub( sum, shape_bits) ); + npulses, maxpulse, HQ_CORE ); + *num_bits = add( *num_bits, sub( sum, shape_bits ) ); } test(); - IF ( EQ_16(hqswb_clas, HQ_HVQ)||EQ_16(hqswb_clas,HQ_HARMONIC)) + IF( EQ_16( hqswb_clas, HQ_HVQ ) || EQ_16( hqswb_clas, HQ_HARMONIC ) ) { subband_search_offset = subband_search_offsets_13p2kbps_Har; wBands[0] = SWB_SB_BW_LEN0_16KBPS_HAR; @@ -194,12 +194,12 @@ void hq_hr_enc_fx( wBands[1] = SWB_SB_BW_LEN1_16KBPS_HAR; move16(); - IF (EQ_16(hqswb_clas, HQ_HARMONIC)) + IF( EQ_16( hqswb_clas, HQ_HARMONIC ) ) { - Q_shift = sub(SWB_BWE_LR_Qs, Q_audio); - FOR (i = 0; i < 300; i++) + Q_shift = sub( SWB_BWE_LR_Qs, Q_audio ); + FOR( i = 0; i < 300; i++ ) { - t_audio_q[i] = L_shl(L_deposit_l(t_audio_q_norm[i]), Q_shift); /* Q12 */ + t_audio_q[i] = L_shl( L_deposit_l( t_audio_q_norm[i] ), Q_shift ); /* Q12 */ } } @@ -211,20 +211,22 @@ void hq_hr_enc_fx( test(); test(); - hHQ_core->prev_frm_hfe2 = 0; /*reset*/ move16(); - hHQ_core->prev_stab_hfe2 = 0; /*reset*/ move16(); + hHQ_core->prev_frm_hfe2 = 0; /*reset*/ + move16(); + hHQ_core->prev_stab_hfe2 = 0; /*reset*/ + move16(); nf_idx = 0; move16(); test(); test(); test(); - IF ( NE_16(is_transient,1 ) && NE_16(hqswb_clas,HQ_HVQ) && !(EQ_16(length,L_FRAME16k) && LE_32(st_fx->core_brate,HQ_32k))) + IF( NE_16( is_transient, 1 ) && NE_16( hqswb_clas, HQ_HVQ ) && !( EQ_16( length, L_FRAME16k ) && LE_32( st_fx->core_brate, HQ_32k ) ) ) { test(); - IF (EQ_16(hqswb_clas, HQ_GEN_SWB)||EQ_16(hqswb_clas,HQ_GEN_FB)) + IF( EQ_16( hqswb_clas, HQ_GEN_SWB ) || EQ_16( hqswb_clas, HQ_GEN_FB ) ) { - nf_idx = noise_adjust_fx( t_audio_norm, 12, R, sfm_start, sfm_end, s_max(core_sfm,sub(num_env_bands,1))); + nf_idx = noise_adjust_fx( t_audio_norm, 12, R, sfm_start, sfm_end, s_max( core_sfm, sub( num_env_bands, 1 ) ) ); push_indice_fx( st_fx->hBstr, IND_NF_IDX, nf_idx, 2 ); } ELSE @@ -239,19 +241,18 @@ void hq_hr_enc_fx( /* Prepare synthesis for LB generation in case of switch to ACELP */ #ifdef ADD_IVAS_HQ_CODE - IF (NE_16(hqswb_clas, HQ_HVQ)) + IF( NE_16( hqswb_clas, HQ_HVQ ) ) { - apply_envelope_enc(t_audio_q, ynrm, num_sfm, sfm_start, sfm_end); + apply_envelope_enc( t_audio_q, ynrm, num_sfm, sfm_start, sfm_end ); } - IF (is_transient) + IF( is_transient ) { - de_interleave_spectrum(t_audio_q, length); + de_interleave_spectrum( t_audio_q, length ); } - Copy32(t_audio_q, t_audio, length); + Copy32( t_audio_q, t_audio, length ); #endif return; } - diff --git a/lib_enc/hq_lr_enc_fx.c b/lib_enc/hq_lr_enc_fx.c index d080107ee..d1f352057 100644 --- a/lib_enc/hq_lr_enc_fx.c +++ b/lib_enc/hq_lr_enc_fx.c @@ -9,23 +9,20 @@ #include "rom_enc.h" //#include "basop_mpy.h" #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ -#include "basop_util.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ +#include "basop_util.h" /* Function prototypes */ /*--------------------------------------------------------------------------* * Local function prototypes *--------------------------------------------------------------------------*/ -static Word16 band_energy_quant_fx(BSTR_ENC_HANDLE hBstr, const Word32 *L_t_audio, const Word16 band_start_fx[], const Word16 band_end_fx[], Word32 L_band_energy[], - const Word16 bands_fx, const Word32 L_qint, const Word16 eref_fx, const Word16 is_transient_fx ); +static Word16 band_energy_quant_fx( BSTR_ENC_HANDLE hBstr, const Word32 *L_t_audio, const Word16 band_start_fx[], const Word16 band_end_fx[], Word32 L_band_energy[], const Word16 bands_fx, const Word32 L_qint, const Word16 eref_fx, const Word16 is_transient_fx ); -static Word16 p2a_threshold_quant_fx(BSTR_ENC_HANDLE hBstr, const Word32 *L_t_audio, const Word16 band_start[], const Word16 band_end[], const Word16 band_width[], - const Word16 bands, const Word16 p2a_bands, const Word16 p2a_th, Word16 *p2a_flags ); +static Word16 p2a_threshold_quant_fx( BSTR_ENC_HANDLE hBstr, const Word32 *L_t_audio, const Word16 band_start[], const Word16 band_end[], const Word16 band_width[], const Word16 bands, const Word16 p2a_bands, const Word16 p2a_th, Word16 *p2a_flags ); -static void mdct_spectrum_fine_gain_enc_fx( Encoder_State *st_fx, const Word32 L_ybuf[], Word32 L_y2[], const Word16 band_start[], const Word16 band_end[], - const Word16 k_sort[], const Word16 bands, const Word32 L_qint, const Word16 Ngq, const Word16 gqlevs, const Word16 gqbits ); +static void mdct_spectrum_fine_gain_enc_fx( Encoder_State *st_fx, const Word32 L_ybuf[], Word32 L_y2[], const Word16 band_start[], const Word16 band_end[], const Word16 k_sort[], const Word16 bands, const Word32 L_qint, const Word16 Ngq, const Word16 gqlevs, const Word16 gqbits ); /*--------------------------------------------------------------------------* * spt_shorten_domain_set() @@ -33,18 +30,18 @@ static void mdct_spectrum_fine_gain_enc_fx( Encoder_State *st_fx, const Word32 * Track the spectral peak based on peak -avg analysis *--------------------------------------------------------------------------*/ -static void spt_shorten_domain_set_fx( - Encoder_State *st_fx, /* i: encoder state structure */ - const Word32 L_t_audio[], /* i: input spectrum */ - const Word16 p2a_flags[], /* i: p2a anlysis information */ - const Word16 new_band_start[], /* i: new band start position */ - const Word16 new_band_end[], /* i: new band end position */ - const Word16 new_band_width[], /* i: new subband band width */ - const Word16 bands, /* i: total number of subbands */ - Word16 band_start[], /* i/o: band start position */ - Word16 band_end[], /* i/o: band end position */ - Word16 band_width[], /* i: sub band band width */ - Word16 *bit_budget /* i/o: bit budget */ +static void spt_shorten_domain_set_fx( + Encoder_State *st_fx, /* i: encoder state structure */ + const Word32 L_t_audio[], /* i: input spectrum */ + const Word16 p2a_flags[], /* i: p2a anlysis information */ + const Word16 new_band_start[], /* i: new band start position */ + const Word16 new_band_end[], /* i: new band end position */ + const Word16 new_band_width[], /* i: new subband band width */ + const Word16 bands, /* i: total number of subbands */ + Word16 band_start[], /* i/o: band start position */ + Word16 band_end[], /* i/o: band end position */ + Word16 band_width[], /* i: sub band band width */ + Word16 *bit_budget /* i/o: bit budget */ ) { Word16 i, j, k; @@ -57,32 +54,32 @@ static void spt_shorten_domain_set_fx( kpos = 0; j = 0; move16(); - FOR(k=sub(bands,SPT_SHORTEN_SBNUM); kprev_SWB_peak_pos[kpos] != 0) + IF( hHQ_core->prev_SWB_peak_pos[kpos] != 0 ) { - L_max_y2 = L_deposit_l(0); + L_max_y2 = L_deposit_l( 0 ); max_y2_pos = 0; move16(); - FOR(i=band_start[k]; i<=band_end[k]; i++) + FOR( i = band_start[k]; i <= band_end[k]; i++ ) { - IF( LT_32( L_max_y2, L_abs(L_t_audio[i]))) + IF( LT_32( L_max_y2, L_abs( L_t_audio[i] ) ) ) { - L_max_y2 = L_abs(L_t_audio[i]); + L_max_y2 = L_abs( L_t_audio[i] ); max_y2_pos = i; move16(); } } test(); - IF( GE_16(max_y2_pos, new_band_start[j])&&LE_16(max_y2_pos,new_band_end[j])) + IF( GE_16( max_y2_pos, new_band_start[j] ) && LE_16( max_y2_pos, new_band_end[j] ) ) { band_start[k] = new_band_start[j]; move16(); - band_end[k] = new_band_end[j]; + band_end[k] = new_band_end[j]; move16(); band_width[k] = new_band_width[j]; move16(); @@ -90,12 +87,12 @@ static void spt_shorten_domain_set_fx( move16(); } } - push_indice_fx(st_fx->hBstr, IND_HQ2_SPT_SHORTEN, spt_shorten_flag[j], 1); - *bit_budget = sub(*bit_budget, 1); + push_indice_fx( st_fx->hBstr, IND_HQ2_SPT_SHORTEN, spt_shorten_flag[j], 1 ); + *bit_budget = sub( *bit_budget, 1 ); } - kpos = add(kpos, 1); - j = add(j, 1); + kpos = add( kpos, 1 ); + j = add( j, 1 ); } return; @@ -108,11 +105,11 @@ static void spt_shorten_domain_set_fx( *--------------------------------------------------------------------------*/ void hq_lr_enc_fx( - Encoder_State *st_fx, /* i/o: : encoder state structure */ - Word32 L_t_audio[], /* i/o: Q12 : transform-domain coefs. */ - const Word16 inner_frame_fx,/* i : Q0 : inner frame length */ - Word16 *num_bits_fx, /* i/o: Q0 : number of available bits */ - const Word16 is_transient_fx/* i : Q0 : transient flag */ + Encoder_State *st_fx, /* i/o: : encoder state structure */ + Word32 L_t_audio[], /* i/o: Q12 : transform-domain coefs. */ + const Word16 inner_frame_fx, /* i : Q0 : inner frame length */ + Word16 *num_bits_fx, /* i/o: Q0 : number of available bits */ + const Word16 is_transient_fx /* i : Q0 : transient flag */ ) { Word16 i, k1_fx, k2_fx; @@ -125,12 +122,12 @@ void hq_lr_enc_fx( Word32 L_qint; /*Word16 Qqint=29;*/ - Word16 eref_fx/*, Qeref=10*/; - Word16 bit_alloc_weight_fx/*, Qbaw=13*/; - Word16 ld_slope_fx/*, Qldslope=15*/; - Word16 p2a_th_fx/*, Qp2ath=11*/; - Word16 pd_thresh_fx/*, Qpdth=15*/; - Word16 ni_coef_fx/*, Qnicoef=14*/; + Word16 eref_fx /*, Qeref=10*/; + Word16 bit_alloc_weight_fx /*, Qbaw=13*/; + Word16 ld_slope_fx /*, Qldslope=15*/; + Word16 p2a_th_fx /*, Qp2ath=11*/; + Word16 pd_thresh_fx /*, Qpdth=15*/; + Word16 ni_coef_fx /*, Qnicoef=14*/; Word16 k_sort_fx[BANDS_MAX]; Word16 npulses_fx[BANDS_MAX]; @@ -148,7 +145,7 @@ void hq_lr_enc_fx( Word16 trans_bit; Word16 adjustFlag; Word16 prev_SWB_peak_pos_tmp_fx[SPT_SHORTEN_SBNUM]; - Word16 k,j; + Word16 k, j; Word16 flag_spt_fx; Word16 org_band_start[SPT_SHORTEN_SBNUM]; Word16 org_band_end[SPT_SHORTEN_SBNUM]; @@ -160,9 +157,9 @@ void hq_lr_enc_fx( Word16 k1_step_fx, k2_step_fx; Word16 exp_norm; - Word16 lowband,highband,p2a_flags_tmp[BANDS_MAX]; - Word32 L_tmp,L_tmp2,L_tmp3; - Word16 exp,exp2,tmp,tmp1,tmp2,tmp3,frac1,alpha_fx,Q_band_energy; + Word16 lowband, highband, p2a_flags_tmp[BANDS_MAX]; + Word32 L_tmp, L_tmp2, L_tmp3; + Word16 exp, exp2, tmp, tmp1, tmp2, tmp3, frac1, alpha_fx, Q_band_energy; Word32 enerH_fx; Word32 enerL_fx; Word32 Ep_fx[BANDS_MAX]; @@ -170,8 +167,8 @@ void hq_lr_enc_fx( Word32 Ep_avrgL_fx; Word32 Ep_peak_fx; Word32 Ep_tmp_fx[BANDS_MAX]; - Word16 gama_fx;/*Q15 0.85f;// */ - Word16 beta_fx;/*Q14 1.05f; */ + Word16 gama_fx; /*Q15 0.85f;// */ + Word16 beta_fx; /*Q14 1.05f; */ HQ_ENC_HANDLE hHQ_core = st_fx->hHQ_core; BSTR_ENC_HANDLE hBstr = st_fx->hBstr; #ifdef BASOP_NOGLOB_DECLARE_LOCAL @@ -183,26 +180,26 @@ void hq_lr_enc_fx( set16_fx( inp_vector_fx, 0, inner_frame_fx ); flag_spt_fx = 0; move16(); - set16_fx(prev_SWB_peak_pos_tmp_fx, 0, SPT_SHORTEN_SBNUM); + set16_fx( prev_SWB_peak_pos_tmp_fx, 0, SPT_SHORTEN_SBNUM ); adjustFlag = 0; move16(); bw_low = 0; move16(); bw_high = 20; move16(); - enerL_fx = L_deposit_l(0); - enerH_fx = L_deposit_l(0); + enerL_fx = L_deposit_l( 0 ); + enerH_fx = L_deposit_l( 0 ); - tmp2 = 0; /* to avoid compilation warnings */ + tmp2 = 0; /* to avoid compilation warnings */ - L_bwe_br = L_add(st_fx->core_brate, 0); + L_bwe_br = L_add( st_fx->core_brate, 0 ); hqswb_clas_fx = HQ_NORMAL; move16(); test(); test(); - IF( EQ_16(st_fx->bwidth, SWB)&&(EQ_32(L_bwe_br,HQ_16k40)||EQ_32(L_bwe_br,HQ_13k20))) + IF( EQ_16( st_fx->bwidth, SWB ) && ( EQ_32( L_bwe_br, HQ_16k40 ) || EQ_32( L_bwe_br, HQ_13k20 ) ) ) { - IF ( EQ_16(is_transient_fx, 1)) + IF( EQ_16( is_transient_fx, 1 ) ) { hqswb_clas_fx = HQ_TRANSIENT; move16(); @@ -214,8 +211,8 @@ void hq_lr_enc_fx( /* write the classification information into the bitstream */ push_indice_fx( hBstr, IND_HQ2_SWB_CLAS, hqswb_clas_fx, 2 ); - (*num_bits_fx) = sub(*num_bits_fx, 2); - if( EQ_16(hqswb_clas_fx, HQ_NORMAL)) + ( *num_bits_fx ) = sub( *num_bits_fx, 2 ); + if ( EQ_16( hqswb_clas_fx, HQ_NORMAL ) ) { flag_spt_fx = 1; move16(); @@ -227,14 +224,13 @@ void hq_lr_enc_fx( push_indice_fx( st_fx->hBstr, IND_HQ2_SWB_CLAS, is_transient_fx, 1 ); /* subtract one bit for the transient flag */ - (*num_bits_fx)--; + ( *num_bits_fx )--; } hq2_core_configure_fx( inner_frame_fx, *num_bits_fx, is_transient_fx, &bands_fx, &length_fx, band_width, band_start, band_end, - &L_qint, &eref_fx, &bit_alloc_weight_fx, &gqlevs_fx, &Ngq_fx, &p2a_bands_fx, &p2a_th_fx, &pd_thresh_fx, &ld_slope_fx, &ni_coef_fx - ,L_bwe_br); + &L_qint, &eref_fx, &bit_alloc_weight_fx, &gqlevs_fx, &Ngq_fx, &p2a_bands_fx, &p2a_th_fx, &pd_thresh_fx, &ld_slope_fx, &ni_coef_fx, L_bwe_br ); - highlength_fx = band_end[sub(bands_fx, 1)]; + highlength_fx = band_end[sub( bands_fx, 1 )]; move16(); har_bands_fx = bands_fx; move16(); @@ -242,52 +238,52 @@ void hq_lr_enc_fx( test(); test(); test(); - IF( EQ_16(st_fx->bwidth, SWB)&&is_transient_fx==0&&(EQ_32(L_bwe_br,HQ_16k40)||EQ_32(L_bwe_br,HQ_13k20))) + IF( EQ_16( st_fx->bwidth, SWB ) && is_transient_fx == 0 && ( EQ_32( L_bwe_br, HQ_16k40 ) || EQ_32( L_bwe_br, HQ_13k20 ) ) ) { /* reserve bits for HQ_NORMAL2 and HQ_HARMONIC modes */ test(); - IF( EQ_16(hqswb_clas_fx, HQ_NORMAL)||EQ_16(hqswb_clas_fx,HQ_HARMONIC)) + IF( EQ_16( hqswb_clas_fx, HQ_NORMAL ) || EQ_16( hqswb_clas_fx, HQ_HARMONIC ) ) { - (*num_bits_fx) = sub(*num_bits_fx, get_usebit_npswb_fx(hqswb_clas_fx)); + ( *num_bits_fx ) = sub( *num_bits_fx, get_usebit_npswb_fx( hqswb_clas_fx ) ); } } test(); test(); - IF(( EQ_32(L_bwe_br, HQ_16k40)||EQ_32(L_bwe_br,HQ_13k20))&&EQ_16(st_fx->bwidth,SWB)) + IF( ( EQ_32( L_bwe_br, HQ_16k40 ) || EQ_32( L_bwe_br, HQ_13k20 ) ) && EQ_16( st_fx->bwidth, SWB ) ) { - IF( NE_16(hHQ_core->prev_hqswb_clas, HQ_NORMAL)) + IF( NE_16( hHQ_core->prev_hqswb_clas, HQ_NORMAL ) ) { j = 0; move16(); - FOR(k=sub(bands_fx,SPT_SHORTEN_SBNUM); kprev_SWB_peak_pos[j] = 0; move16(); - j = add(j, 1); + j = add( j, 1 ); } } } /* Check if input frame is larger than coded bandwidth */ test(); - IF ( GT_16(inner_frame_fx, length_fx)&&is_transient_fx) + IF( GT_16( inner_frame_fx, length_fx ) && is_transient_fx ) { /* If so, collapse transient frame (4 short transforms) to remove uncoded coefficients */ - k1_step_fx = shr(length_fx, 2); /* k1 = length/NUM_TIME_SWITCHING_BLOCKS */ - k2_step_fx = shr(inner_frame_fx, 2); /* k2 = inner_frame/NUM_TIME_SWITCHING_BLOCKS */ + k1_step_fx = shr( length_fx, 2 ); /* k1 = length/NUM_TIME_SWITCHING_BLOCKS */ + k2_step_fx = shr( inner_frame_fx, 2 ); /* k2 = inner_frame/NUM_TIME_SWITCHING_BLOCKS */ k1_fx = k1_step_fx; k2_fx = k2_step_fx; - FOR (i = 1; i < NUM_TIME_SWITCHING_BLOCKS; i++) + FOR( i = 1; i < NUM_TIME_SWITCHING_BLOCKS; i++ ) { /*k1 = i*length/NUM_TIME_SWITCHING_BLOCKS; */ /*k2 = i*inner_frame/NUM_TIME_SWITCHING_BLOCKS; */ Copy32( &L_t_audio[k2_fx], &L_t_audio[k1_fx], k1_step_fx ); - k1_fx = add(k1_fx, k1_step_fx); - k2_fx = add(k2_fx, k2_step_fx); + k1_fx = add( k1_fx, k1_step_fx ); + k2_fx = add( k2_fx, k2_step_fx ); } } @@ -296,10 +292,10 @@ void hq_lr_enc_fx( L_qint, eref_fx, is_transient_fx ); /* First pass bit budget for TCQ of spectral band information */ - exp_norm = norm_s(gqlevs_fx); /* gqbits_fx = (short int) log2_f ((float) gqlevs_fx); */ - gqbits_fx = sub(14, exp_norm); + exp_norm = norm_s( gqlevs_fx ); /* gqbits_fx = (short int) log2_f ((float) gqlevs_fx); */ + gqbits_fx = sub( 14, exp_norm ); - bit_budget_fx = sub(sub(*num_bits_fx, ebits_fx), round_fx(L_shl(L_mult(Ngq_fx, gqbits_fx), 15))); /* (*num_bits) - (short) ceil (ebits) - Ngq * gqbits; */ + bit_budget_fx = sub( sub( *num_bits_fx, ebits_fx ), round_fx( L_shl( L_mult( Ngq_fx, gqbits_fx ), 15 ) ) ); /* (*num_bits) - (short) ceil (ebits) - Ngq * gqbits; */ pbits_fx = 0; @@ -307,19 +303,19 @@ void hq_lr_enc_fx( test(); test(); - IF( EQ_16(st_fx->bwidth, SWB)&&(EQ_32(L_bwe_br,HQ_16k40)||EQ_32(L_bwe_br,HQ_13k20))) + IF( EQ_16( st_fx->bwidth, SWB ) && ( EQ_32( L_bwe_br, HQ_16k40 ) || EQ_32( L_bwe_br, HQ_13k20 ) ) ) { - IF( EQ_16(hqswb_clas_fx, HQ_HARMONIC)) + IF( EQ_16( hqswb_clas_fx, HQ_HARMONIC ) ) { set16_fx( p2a_flags_fx, 1, har_bands_fx ); } ELSE { /* High band tonality detector based on per band peak-to-average ratio */ - pbits_fx = p2a_threshold_quant_fx(hBstr, L_t_audio, band_start, band_end, band_width, bands_fx, p2a_bands_fx, p2a_th_fx, p2a_flags_fx ); - bit_budget_fx = sub(bit_budget_fx, pbits_fx); + pbits_fx = p2a_threshold_quant_fx( hBstr, L_t_audio, band_start, band_end, band_width, bands_fx, p2a_bands_fx, p2a_th_fx, p2a_flags_fx ); + bit_budget_fx = sub( bit_budget_fx, pbits_fx ); - IF( EQ_16(hqswb_clas_fx, HQ_NORMAL)) + IF( EQ_16( hqswb_clas_fx, HQ_NORMAL ) ) { return_bits_normal2_fx( &bit_budget_fx, p2a_flags_fx, bands_fx, bits_lagIndices_modeNormal ); } @@ -328,60 +324,60 @@ void hq_lr_enc_fx( ELSE { /* High band tonality detector based on per band peak-to-average ratio */ - pbits_fx = p2a_threshold_quant_fx(hBstr, L_t_audio, band_start, band_end, band_width, bands_fx, p2a_bands_fx, p2a_th_fx, p2a_flags_fx ); - bit_budget_fx = sub(bit_budget_fx, pbits_fx); + pbits_fx = p2a_threshold_quant_fx( hBstr, L_t_audio, band_start, band_end, band_width, bands_fx, p2a_bands_fx, p2a_th_fx, p2a_flags_fx ); + bit_budget_fx = sub( bit_budget_fx, pbits_fx ); } - IF(EQ_16(flag_spt_fx, 1)) + IF( EQ_16( flag_spt_fx, 1 ) ) { - spt_shorten_domain_band_save_fx(bands_fx, band_start, band_end, band_width, org_band_start, org_band_end, org_band_width); - spt_shorten_domain_pre_fx(band_start, band_end, hHQ_core->prev_SWB_peak_pos, bands_fx, L_bwe_br, new_band_start, new_band_end, new_band_width); - spt_shorten_domain_set_fx(st_fx, L_t_audio, p2a_flags_fx, new_band_start, new_band_end, new_band_width, bands_fx, band_start, band_end, band_width, &bit_budget_fx); + spt_shorten_domain_band_save_fx( bands_fx, band_start, band_end, band_width, org_band_start, org_band_end, org_band_width ); + spt_shorten_domain_pre_fx( band_start, band_end, hHQ_core->prev_SWB_peak_pos, bands_fx, L_bwe_br, new_band_start, new_band_end, new_band_width ); + spt_shorten_domain_set_fx( st_fx, L_t_audio, p2a_flags_fx, new_band_start, new_band_end, new_band_width, bands_fx, band_start, band_end, band_width, &bit_budget_fx ); } /* Estimate number of bits per band */ Q_band_energy = SWB_BWE_LR_Qbe; - FOR(i = 0; i < bands_fx; i++) + FOR( i = 0; i < bands_fx; i++ ) { - L_tmp = L_shl(L_band_energy[i],sub(16,Q_band_energy));/*Q16 */ + L_tmp = L_shl( L_band_energy[i], sub( 16, Q_band_energy ) ); /*Q16 */ - frac1 = L_Extract_lc(L_tmp, &exp); /* Extract exponent of L_tmp */ - L_tmp = Pow2(30, frac1); - exp = sub(exp, 30); + frac1 = L_Extract_lc( L_tmp, &exp ); /* Extract exponent of L_tmp */ + L_tmp = Pow2( 30, frac1 ); + exp = sub( exp, 30 ); #ifdef BASOP_NOGLOB Ep_fx[i] = L_shl_sat( L_tmp, s_max( sub( exp, 6 ), -31 ) ); /* Q -6 */ #else - Ep_fx[i] = L_shl(L_tmp , s_max(sub(exp,6), -31)); /* Q -6 */ + Ep_fx[i] = L_shl( L_tmp, s_max( sub( exp, 6 ), -31 ) ); /* Q -6 */ #endif } FOR( i = 0; i < bands_fx; i++ ) { L_tmp2 = Ep_fx[i]; - L_tmp = L_max(1, L_tmp2); - exp = norm_l(L_tmp); - tmp = extract_h(L_shl(L_tmp, exp)); + L_tmp = L_max( 1, L_tmp2 ); + exp = norm_l( L_tmp ); + tmp = extract_h( L_shl( L_tmp, exp ) ); - L_tmp3 = (Word32)band_width[i]; - exp2 = norm_l(L_tmp3); - tmp2 = extract_h(L_shl(L_tmp3, exp2)); + L_tmp3 = (Word32) band_width[i]; + exp2 = norm_l( L_tmp3 ); + tmp2 = extract_h( L_shl( L_tmp3, exp2 ) ); - exp2 = sub(exp, exp2); /* Denormalize and substract */ + exp2 = sub( exp, exp2 ); /* Denormalize and substract */ - tmp3 = sub(tmp2, tmp); - if (tmp3 > 0) + tmp3 = sub( tmp2, tmp ); + if ( tmp3 > 0 ) { - tmp2 = shr(tmp2, 1); + tmp2 = shr( tmp2, 1 ); } - if (tmp3 > 0) + if ( tmp3 > 0 ) { - exp2 = add(exp2, 1); + exp2 = add( exp2, 1 ); } - tmp = div_s(tmp2, tmp); - L_tmp = L_deposit_h(tmp); - L_tmp = Isqrt_lc(L_tmp, &exp2);/*Q(31-exp2) */ - Ep_tmp_fx[i] = L_shr(L_tmp,sub(15,exp2));/*Q13 */ + tmp = div_s( tmp2, tmp ); + L_tmp = L_deposit_h( tmp ); + L_tmp = Isqrt_lc( L_tmp, &exp2 ); /*Q(31-exp2) */ + Ep_tmp_fx[i] = L_shr( L_tmp, sub( 15, exp2 ) ); /*Q13 */ } test(); @@ -390,84 +386,83 @@ void hq_lr_enc_fx( test(); test(); test(); - IF ( is_transient_fx == 0 && EQ_16(inner_frame_fx, L_FRAME8k)&&LE_32(st_fx->core_brate,ACELP_13k20)) + IF( is_transient_fx == 0 && EQ_16( inner_frame_fx, L_FRAME8k ) && LE_32( st_fx->core_brate, ACELP_13k20 ) ) { lowband = 6; move16(); trans_bit = 2; move16(); - bit_budget_fx =sub(bit_budget_fx,trans_bit); + bit_budget_fx = sub( bit_budget_fx, trans_bit ); gama_fx = 27852; /*Q15 0.85f;// */ beta_fx = 17203; - move16();/*Q14 1.05f; */ + move16(); /*Q14 1.05f; */ - set16_fx( &p2a_flags_tmp[sub(bands_fx,trans_bit)], 0, 2 ); + set16_fx( &p2a_flags_tmp[sub( bands_fx, trans_bit )], 0, 2 ); - IF( EQ_32(st_fx->core_brate, ACELP_13k20)) + IF( EQ_32( st_fx->core_brate, ACELP_13k20 ) ) { beta_fx = 13107; - move16();/*14 1.25f; */ + move16(); /*14 1.25f; */ gama_fx = 31130; - move16();/*0.95f; */ - Copy(&p2a_flags_fx[sub(bands_fx,trans_bit)], &p2a_flags_tmp[sub(bands_fx,trans_bit)], trans_bit); + move16(); /*0.95f; */ + Copy( &p2a_flags_fx[sub( bands_fx, trans_bit )], &p2a_flags_tmp[sub( bands_fx, trans_bit )], trans_bit ); } /* calculate the the low band/high band energy and the variance/avrage of the envelopes */ - Ep_vari_fx = L_deposit_l(0); - Ep_avrg_fx = L_deposit_l(0); - Ep_avrgL_fx = L_deposit_l(0); - Ep_peak_fx = L_deposit_l(0); + Ep_vari_fx = L_deposit_l( 0 ); + Ep_avrg_fx = L_deposit_l( 0 ); + Ep_avrgL_fx = L_deposit_l( 0 ); + Ep_peak_fx = L_deposit_l( 0 ); FOR( i = 0; i < bands_fx; i++ ) { - IF( GE_16(i,lowband)) + IF( GE_16( i, lowband ) ) { #ifdef BASOP_NOGLOB Ep_vari_fx = L_add_sat( Ep_vari_fx, L_abs( L_sub( Ep_tmp_fx[i], Ep_tmp_fx[sub( i, 1 )] ) ) ); /*Q15 */ - Ep_avrg_fx = L_add_sat( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ + Ep_avrg_fx = L_add_sat( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ #else - Ep_vari_fx = L_add(Ep_vari_fx,L_abs(L_sub(Ep_tmp_fx[i],Ep_tmp_fx[sub(i,1)])));/*Q15 */ - Ep_avrg_fx = L_add(Ep_avrg_fx,Ep_tmp_fx[i]);/*Q15 */ + Ep_vari_fx = L_add( Ep_vari_fx, L_abs( L_sub( Ep_tmp_fx[i], Ep_tmp_fx[sub( i, 1 )] ) ) ); /*Q15 */ + Ep_avrg_fx = L_add( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ #endif - } ELSE { #ifdef BASOP_NOGLOB Ep_avrgL_fx = L_add_sat( Ep_avrgL_fx, Ep_tmp_fx[i] ); /*Q15 */ #else - Ep_avrgL_fx = L_add(Ep_avrgL_fx,Ep_tmp_fx[i]);/*Q15 */ + Ep_avrgL_fx = L_add( Ep_avrgL_fx, Ep_tmp_fx[i] ); /*Q15 */ #endif - IF(GT_32(Ep_tmp_fx[i],Ep_peak_fx)) + IF( GT_32( Ep_tmp_fx[i], Ep_peak_fx ) ) { - Ep_peak_fx = L_add(Ep_tmp_fx[i], 0); /*Q15 */ + Ep_peak_fx = L_add( Ep_tmp_fx[i], 0 ); /*Q15 */ } } } /* modify the last p2a_bands subbands band_energies */ - Copy32( L_band_energy,L_band_energy_tmp,bands_fx ); /*Q_band_energy */ - L_tmp = Mult_32_16(Ep_peak_fx,24576);/*Q(13+14-15 = 12) 1.5 lowband = 6; */ - L_tmp2 =Mult_32_16(Ep_peak_fx,shl(sub(bands_fx,lowband),9));/*Q(13+9-15 = 7) */ - L_tmp3 =Mult_32_16(Ep_avrg_fx,1126);/*Q(13+9-15 = 7) */ + Copy32( L_band_energy, L_band_energy_tmp, bands_fx ); /*Q_band_energy */ + L_tmp = Mult_32_16( Ep_peak_fx, 24576 ); /*Q(13+14-15 = 12) 1.5 lowband = 6; */ + L_tmp2 = Mult_32_16( Ep_peak_fx, shl( sub( bands_fx, lowband ), 9 ) ); /*Q(13+9-15 = 7) */ + L_tmp3 = Mult_32_16( Ep_avrg_fx, 1126 ); /*Q(13+9-15 = 7) */ test(); test(); test(); test(); - IF(( (LT_32(L_tmp, L_shr(Ep_avrgL_fx,1))&&EQ_32(st_fx->core_brate,ACELP_13k20))||LT_32(st_fx->core_brate,ACELP_13k20))&& - LT_32(L_tmp2, L_tmp3) && GT_32(L_tmp2, L_shr(Ep_avrg_fx,7)) ) + IF( ( ( LT_32( L_tmp, L_shr( Ep_avrgL_fx, 1 ) ) && EQ_32( st_fx->core_brate, ACELP_13k20 ) ) || LT_32( st_fx->core_brate, ACELP_13k20 ) ) && + LT_32( L_tmp2, L_tmp3 ) && GT_32( L_tmp2, L_shr( Ep_avrg_fx, 7 ) ) ) { - FOR(i = lowband; i < bands_fx; i++) + FOR( i = lowband; i < bands_fx; i++ ) { - L_tmp = Mult_32_16(Ep_avrg_fx,24576);/*Q(13+14-15 = 12) 1.5 */ - IF(LT_32(L_shr(Ep_tmp_fx[i],1), L_tmp)) + L_tmp = Mult_32_16( Ep_avrg_fx, 24576 ); /*Q(13+14-15 = 12) 1.5 */ + IF( LT_32( L_shr( Ep_tmp_fx[i], 1 ), L_tmp ) ) { - L_tmp = Mult_32_16(Ep_peak_fx,sub(bands_fx,lowband));/*Q(13+0-15 = -2) */ - tmp = extract_h(L_shl(L_tmp,14));/*Q-4 */ - IF(tmp != 0) + L_tmp = Mult_32_16( Ep_peak_fx, sub( bands_fx, lowband ) ); /*Q(13+0-15 = -2) */ + tmp = extract_h( L_shl( L_tmp, 14 ) ); /*Q-4 */ + IF( tmp != 0 ) { - exp = norm_s(tmp); - tmp = shl(tmp,exp);/*Q(exp) */ - tmp = div_s(16384,tmp);/*Q(15+14-exp=29-exp) */ - exp = sub(29,exp); + exp = norm_s( tmp ); + tmp = shl( tmp, exp ); /*Q(exp) */ + tmp = div_s( 16384, tmp ); /*Q(15+14-exp=29-exp) */ + exp = sub( 29, exp ); } ELSE { @@ -477,30 +472,30 @@ void hq_lr_enc_fx( exp = 0; move16(); } - L_tmp = L_shl(Mult_32_16(Ep_avrg_fx,tmp),sub(13,exp));/*Q(13+exp-15 +13-exp +4 = 15) */ - L_tmp2 = L_add(L_tmp,13107); /*15 */ - tmp2 = extract_l(L_min(L_max(L_tmp2,16384),gama_fx)); /*15 = 15 */ - L_band_energy_tmp[i] = Mult_32_16(L_band_energy_tmp[i],tmp2);/*Q(Q_band_energy+15-15 = Q_band_energy) */ + L_tmp = L_shl( Mult_32_16( Ep_avrg_fx, tmp ), sub( 13, exp ) ); /*Q(13+exp-15 +13-exp +4 = 15) */ + L_tmp2 = L_add( L_tmp, 13107 ); /*15 */ + tmp2 = extract_l( L_min( L_max( L_tmp2, 16384 ), gama_fx ) ); /*15 = 15 */ + L_band_energy_tmp[i] = Mult_32_16( L_band_energy_tmp[i], tmp2 ); /*Q(Q_band_energy+15-15 = Q_band_energy) */ } } } ELSE { j = 0; - FOR(i = sub(bands_fx,trans_bit); i < bands_fx; i++) + FOR( i = sub( bands_fx, trans_bit ); i < bands_fx; i++ ) { alpha_fx = 16384; - move16();/*Q14 */ - IF( EQ_16(p2a_flags_tmp[i],1)) + move16(); /*Q14 */ + IF( EQ_16( p2a_flags_tmp[i], 1 ) ) { - L_tmp = Mult_32_16(Ep_tmp_fx[i],sub(bands_fx,lowband));/*Q(13+0-15 = -2) */ - tmp = extract_h(L_shl(L_tmp,14));/*Q-4 */ - IF(tmp != 0) + L_tmp = Mult_32_16( Ep_tmp_fx[i], sub( bands_fx, lowband ) ); /*Q(13+0-15 = -2) */ + tmp = extract_h( L_shl( L_tmp, 14 ) ); /*Q-4 */ + IF( tmp != 0 ) { - exp = norm_s(tmp); - tmp = shl(tmp,exp);/*Q(exp) */ - tmp = div_s(16384,tmp);/*Q(15+14-exp=29-exp) */ - exp = sub(29,exp); + exp = norm_s( tmp ); + tmp = shl( tmp, exp ); /*Q(exp) */ + tmp = div_s( 16384, tmp ); /*Q(15+14-exp=29-exp) */ + exp = sub( 29, exp ); } ELSE { @@ -510,19 +505,19 @@ void hq_lr_enc_fx( exp = 0; move16(); } - L_tmp =Mult_32_16(Ep_vari_fx,3277);/*13+15-15=13 */ + L_tmp = Mult_32_16( Ep_vari_fx, 3277 ); /*13+15-15=13 */ #ifdef BASOP_NOGLOB - L_tmp = L_shl_o(Mult_32_16(L_tmp,tmp),sub(12,exp), &Overflow);/*Q(13+exp-15 +12-exp +4 = 14) */ + L_tmp = L_shl_o( Mult_32_16( L_tmp, tmp ), sub( 12, exp ), &Overflow ); /*Q(13+exp-15 +12-exp +4 = 14) */ #else - L_tmp = L_shl(Mult_32_16(L_tmp,tmp),sub(12,exp));/*Q(13+exp-15 +12-exp +4 = 14) */ + L_tmp = L_shl( Mult_32_16( L_tmp, tmp ), sub( 12, exp ) ); /*Q(13+exp-15 +12-exp +4 = 14) */ #endif - tmp2 = extract_h(Ep_avrg_fx);/*Q13-16=-3 */ - IF(tmp2 != 0) + tmp2 = extract_h( Ep_avrg_fx ); /*Q13-16=-3 */ + IF( tmp2 != 0 ) { - exp = norm_s(tmp2); - tmp2 = shl(tmp2,exp);/*Q(exp) */ - tmp2 = div_s(16384,tmp2);/*Q(15+14-exp=29-exp) */ - exp = sub(29,exp); + exp = norm_s( tmp2 ); + tmp2 = shl( tmp2, exp ); /*Q(exp) */ + tmp2 = div_s( 16384, tmp2 ); /*Q(15+14-exp=29-exp) */ + exp = sub( 29, exp ); } ELSE { @@ -531,31 +526,30 @@ void hq_lr_enc_fx( exp = 0; move16(); } - L_tmp2 =Mult_32_16(Ep_vari_fx,6554);/*13+15-15=13 */ + L_tmp2 = Mult_32_16( Ep_vari_fx, 6554 ); /*13+15-15=13 */ #ifdef BASOP_NOGLOB - L_tmp2 = L_shl_o(Mult_32_16(L_tmp2,tmp2),sub(13,exp), &Overflow);/*Q(13+exp-15 +13-exp +3 = 14) */ + L_tmp2 = L_shl_o( Mult_32_16( L_tmp2, tmp2 ), sub( 13, exp ), &Overflow ); /*Q(13+exp-15 +13-exp +3 = 14) */ #else - L_tmp2 = L_shl(Mult_32_16(L_tmp2,tmp2),sub(13,exp));/*Q(13+exp-15 +13-exp +3 = 14) */ + L_tmp2 = L_shl( Mult_32_16( L_tmp2, tmp2 ), sub( 13, exp ) ); /*Q(13+exp-15 +13-exp +3 = 14) */ #endif - L_tmp=L_min(L_tmp,L_tmp2);/*14 */ - tmp=extract_l(L_min(L_tmp,13107));/*14 */ - alpha_fx =add(16384,tmp); - + L_tmp = L_min( L_tmp, L_tmp2 ); /*14 */ + tmp = extract_l( L_min( L_tmp, 13107 ) ); /*14 */ + alpha_fx = add( 16384, tmp ); } - IF(EQ_16(hHQ_core->last_bitalloc_max_band[j++], 1)) + IF( EQ_16( hHQ_core->last_bitalloc_max_band[j++], 1 ) ) { - L_tmp = Mult_32_16(Ep_tmp_fx[i],sub(bands_fx,lowband));/*Q(13+0-15 = -2) */ + L_tmp = Mult_32_16( Ep_tmp_fx[i], sub( bands_fx, lowband ) ); /*Q(13+0-15 = -2) */ #ifdef BASOP_NOGLOB tmp = extract_h( L_shl_sat( L_tmp, 14 ) ); /*Q-2 */ #else - tmp = extract_h(L_shl(L_tmp,14));/*Q-2 */ + tmp = extract_h( L_shl( L_tmp, 14 ) ); /*Q-2 */ #endif - IF(tmp != 0) + IF( tmp != 0 ) { - exp = norm_s(tmp); - tmp = shl(tmp,exp);/*Q(exp) */ - tmp = div_s(16384,tmp);/*Q(15+14-exp=29-exp) */ - exp = sub(29,exp); + exp = norm_s( tmp ); + tmp = shl( tmp, exp ); /*Q(exp) */ + tmp = div_s( 16384, tmp ); /*Q(15+14-exp=29-exp) */ + exp = sub( 29, exp ); } ELSE { @@ -565,23 +559,23 @@ void hq_lr_enc_fx( move16(); } #ifdef BASOP_NOGLOB - L_tmp = L_shl_o(Mult_32_16(Ep_avrg_fx,tmp),sub(14,exp), &Overflow);/*Q(13+exp-15 +14-exp+2 = 14) */ + L_tmp = L_shl_o( Mult_32_16( Ep_avrg_fx, tmp ), sub( 14, exp ), &Overflow ); /*Q(13+exp-15 +14-exp+2 = 14) */ #else - L_tmp = L_shl(Mult_32_16(Ep_avrg_fx,tmp),sub(14,exp));/*Q(13+exp-15 +14-exp+2 = 14) */ + L_tmp = L_shl( Mult_32_16( Ep_avrg_fx, tmp ), sub( 14, exp ) ); /*Q(13+exp-15 +14-exp+2 = 14) */ #endif - L_tmp =L_max(L_tmp,16384); /*14 */ - tmp=extract_l(L_min(L_tmp,beta_fx)); /*14 */ - alpha_fx=shl(mult(alpha_fx,tmp),1);/*14+14-15 +1=14 */ + L_tmp = L_max( L_tmp, 16384 ); /*14 */ + tmp = extract_l( L_min( L_tmp, beta_fx ) ); /*14 */ + alpha_fx = shl( mult( alpha_fx, tmp ), 1 ); /*14+14-15 +1=14 */ } ELSE { - tmp2 = extract_h(Ep_avrg_fx);/*13 -16 =-3 */ - IF(tmp2 != 0) + tmp2 = extract_h( Ep_avrg_fx ); /*13 -16 =-3 */ + IF( tmp2 != 0 ) { - exp = norm_s(tmp2); - tmp2 = shl(tmp2,exp);/*Q(exp) */ - tmp2 = div_s(16384,tmp2);/*Q(15+14-exp=29-exp) */ - exp = sub(29,exp); + exp = norm_s( tmp2 ); + tmp2 = shl( tmp2, exp ); /*Q(exp) */ + tmp2 = div_s( 16384, tmp2 ); /*Q(15+14-exp=29-exp) */ + exp = sub( 29, exp ); } ELSE { @@ -592,31 +586,31 @@ void hq_lr_enc_fx( move16(); } #ifdef BASOP_NOGLOB - L_tmp = L_shl_o(Mult_32_16(Ep_tmp_fx[i],tmp2),sub(19,exp), &Overflow);/*Q(13+exp-15 +19-exp +3 = 20) */ + L_tmp = L_shl_o( Mult_32_16( Ep_tmp_fx[i], tmp2 ), sub( 19, exp ), &Overflow ); /*Q(13+exp-15 +19-exp +3 = 20) */ #else - L_tmp = L_shl(Mult_32_16(Ep_tmp_fx[i],tmp2),sub(19,exp));/*Q(13+exp-15 +19-exp +3 = 20) */ + L_tmp = L_shl( Mult_32_16( Ep_tmp_fx[i], tmp2 ), sub( 19, exp ) ); /*Q(13+exp-15 +19-exp +3 = 20) */ #endif - L_tmp = Mult_32_16(L_tmp,shl(sub(bands_fx,lowband),9));/*20 +9 -15 =14 */ - L_tmp =L_max(L_tmp,13926); /*14 */ - tmp2 =extract_l(L_min(L_tmp,16384)); /*14 */ - alpha_fx=shl(mult(alpha_fx,tmp2),1);/*14+14-15+1 =14 */ + L_tmp = Mult_32_16( L_tmp, shl( sub( bands_fx, lowband ), 9 ) ); /*20 +9 -15 =14 */ + L_tmp = L_max( L_tmp, 13926 ); /*14 */ + tmp2 = extract_l( L_min( L_tmp, 16384 ) ); /*14 */ + alpha_fx = shl( mult( alpha_fx, tmp2 ), 1 ); /*14+14-15+1 =14 */ } - L_band_energy_tmp[i] = L_shl(Mult_32_16(L_band_energy_tmp[i],alpha_fx),1);/*Q(Q_band_energy+14-15 +1= Q_band_energy) */ + L_band_energy_tmp[i] = L_shl( Mult_32_16( L_band_energy_tmp[i], alpha_fx ), 1 ); /*Q(Q_band_energy+14-15 +1= Q_band_energy) */ } } lowband = 3; move16(); - Ep_avrg_fx = L_deposit_l(0); - Ep_avrgL_fx = L_deposit_l(0); - Ep_peak_fx = L_deposit_l(0); - FOR(i = 0; i < bands_fx; i++) + Ep_avrg_fx = L_deposit_l( 0 ); + Ep_avrgL_fx = L_deposit_l( 0 ); + Ep_peak_fx = L_deposit_l( 0 ); + FOR( i = 0; i < bands_fx; i++ ) { - IF(GE_16(i,lowband)) + IF( GE_16( i, lowband ) ) { #ifdef BASOP_NOGLOB Ep_avrg_fx = L_add_sat( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ #else - Ep_avrg_fx = L_add(Ep_avrg_fx,Ep_tmp_fx[i]);/*Q15 */ + Ep_avrg_fx = L_add( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ #endif } ELSE @@ -624,31 +618,31 @@ void hq_lr_enc_fx( #ifdef BASOP_NOGLOB Ep_avrgL_fx = L_add_sat( Ep_avrgL_fx, L_shr( Ep_tmp_fx[i], 1 ) ); /*Q12 */ #else - Ep_avrgL_fx = L_add(Ep_avrgL_fx,L_shr(Ep_tmp_fx[i],1));/*Q12 */ + Ep_avrgL_fx = L_add( Ep_avrgL_fx, L_shr( Ep_tmp_fx[i], 1 ) ); /*Q12 */ #endif - IF(GT_32(Ep_tmp_fx[i],Ep_peak_fx)) + IF( GT_32( Ep_tmp_fx[i], Ep_peak_fx ) ) { - Ep_peak_fx = L_add(Ep_tmp_fx[i], 0); /*Q13 */ + Ep_peak_fx = L_add( Ep_tmp_fx[i], 0 ); /*Q13 */ } } } - L_tmp = Mult_32_16(Ep_peak_fx,28262);/*Q(13+14-15 = 12) 1.725 lowband = 3; */ - L_tmp2 =Mult_32_16(Ep_avrgL_fx,24576);/*Q(12+14-15 = 11) */ + L_tmp = Mult_32_16( Ep_peak_fx, 28262 ); /*Q(13+14-15 = 12) 1.725 lowband = 3; */ + L_tmp2 = Mult_32_16( Ep_avrgL_fx, 24576 ); /*Q(12+14-15 = 11) */ test(); test(); - IF( GT_32(L_shr(Ep_avrg_fx,2), L_tmp2)&<_32(L_shr(Ep_avrg_fx,4),L_tmp2)&>_32(L_tmp,Ep_avrgL_fx)) + IF( GT_32( L_shr( Ep_avrg_fx, 2 ), L_tmp2 ) && LT_32( L_shr( Ep_avrg_fx, 4 ), L_tmp2 ) && GT_32( L_tmp, Ep_avrgL_fx ) ) { adjustFlag = 1; move16(); - FOR (i = 0; i < lowband; i++) + FOR( i = 0; i < lowband; i++ ) { - tmp = extract_h(Ep_avrgL_fx);/*Q-4 */ - IF(tmp != 0) + tmp = extract_h( Ep_avrgL_fx ); /*Q-4 */ + IF( tmp != 0 ) { - exp = norm_s(tmp); - tmp = shl(tmp,exp);/*Q(exp) */ - tmp = div_s(16384,tmp);/*Q(15+14-exp=29-exp) */ - exp = sub(29,exp); + exp = norm_s( tmp ); + tmp = shl( tmp, exp ); /*Q(exp) */ + tmp = div_s( 16384, tmp ); /*Q(15+14-exp=29-exp) */ + exp = sub( 29, exp ); } ELSE { @@ -658,43 +652,43 @@ void hq_lr_enc_fx( exp = 0; move16(); } - L_tmp = Mult_32_16(Ep_peak_fx,tmp);/*Q(13+exp-15+4 = exp+2) */ - L_tmp = Mult_32_16(L_tmp,lowband);/*Q(exp+2+0-15 = exp-13) */ - L_tmp = Mult_32_16(L_tmp,18842);/*Q(exp-13+16-16 = exp-13) */ - L_tmp = L_shl(L_tmp,sub(27,exp));/*Q14 0.5 */ - tmp2=extract_l(L_min(L_tmp,19661));/*14 */ - L_tmp = Mult_32_16(L_band_energy_tmp[i],tmp2);/*Q(Q_band_energy+14-15 = Q_band_energy-1) */ - L_band_energy_tmp[i] = L_shl(L_tmp,1); /*Q_band_energy */ + L_tmp = Mult_32_16( Ep_peak_fx, tmp ); /*Q(13+exp-15+4 = exp+2) */ + L_tmp = Mult_32_16( L_tmp, lowband ); /*Q(exp+2+0-15 = exp-13) */ + L_tmp = Mult_32_16( L_tmp, 18842 ); /*Q(exp-13+16-16 = exp-13) */ + L_tmp = L_shl( L_tmp, sub( 27, exp ) ); /*Q14 0.5 */ + tmp2 = extract_l( L_min( L_tmp, 19661 ) ); /*14 */ + L_tmp = Mult_32_16( L_band_energy_tmp[i], tmp2 ); /*Q(Q_band_energy+14-15 = Q_band_energy-1) */ + L_band_energy_tmp[i] = L_shl( L_tmp, 1 ); /*Q_band_energy */ } } hq2_bit_alloc_fx( L_band_energy_tmp, bands_fx, L_Rk, &bit_budget_fx, p2a_flags_fx, bit_alloc_weight_fx, band_width, *num_bits_fx, hqswb_clas_fx, st_fx->bwidth, is_transient_fx ); /* encode the last p2a_bands-1 subbands bit-allocation index of the previous frame */ - FOR(i = 0; i < 2; i++) + FOR( i = 0; i < 2; i++ ) { - push_indice_fx ( st_fx->hBstr, IND_HQ2_LAST_BA_MAX_BAND, hHQ_core->last_bitalloc_max_band[i], 1 ); + push_indice_fx( st_fx->hBstr, IND_HQ2_LAST_BA_MAX_BAND, hHQ_core->last_bitalloc_max_band[i], 1 ); } } - ELSE IF( is_transient_fx == 0 && EQ_16(inner_frame_fx, L_FRAME16k)) + ELSE IF( is_transient_fx == 0 && EQ_16( inner_frame_fx, L_FRAME16k ) ) { - bit_budget_fx = sub(bit_budget_fx,2);/* bits in high bands to indicate the last 2 subbands is allocated bits or not */ + bit_budget_fx = sub( bit_budget_fx, 2 ); /* bits in high bands to indicate the last 2 subbands is allocated bits or not */ FOR( i = 0; i < bands_fx; i++ ) { #ifdef BASOP_NOGLOB - Ep_tmp_fx[i] = L_shl_o(Ep_tmp_fx[i],2, &Overflow); -#else /* BASOP_NOGLOB */ - Ep_tmp_fx[i] = L_shl(Ep_tmp_fx[i],2); + Ep_tmp_fx[i] = L_shl_o( Ep_tmp_fx[i], 2, &Overflow ); +#else /* BASOP_NOGLOB */ + Ep_tmp_fx[i] = L_shl( Ep_tmp_fx[i], 2 ); #endif /* BASOP_NOGLOB */ } - IF( EQ_32( st_fx->core_brate, ACELP_13k20 )) + IF( EQ_32( st_fx->core_brate, ACELP_13k20 ) ) { lowband = 8; move16(); highband = 15; move16(); - bw_low = sub(band_start[highband],band_start[lowband]); - bw_high = sub(add(band_end[sub(bands_fx,1)],1),band_start[highband]); + bw_low = sub( band_start[highband], band_start[lowband] ); + bw_high = sub( add( band_end[sub( bands_fx, 1 )], 1 ), band_start[highband] ); } ELSE { @@ -702,77 +696,77 @@ void hq_lr_enc_fx( move16(); highband = 16; move16(); - bw_low = sub(band_start[highband],band_start[lowband]); - bw_high = sub(add(band_end[sub(bands_fx,1)],1),band_start[highband]); + bw_low = sub( band_start[highband], band_start[lowband] ); + bw_high = sub( add( band_end[sub( bands_fx, 1 )], 1 ), band_start[highband] ); } /* calculate the the low band/high band energy and the variance/avrage of the envelopes */ - enerL_fx = L_deposit_l(0); - enerH_fx = L_deposit_l(0); - Ep_vari_fx = L_deposit_l(0); - Ep_avrg_fx = L_deposit_l(0); + enerL_fx = L_deposit_l( 0 ); + enerH_fx = L_deposit_l( 0 ); + Ep_vari_fx = L_deposit_l( 0 ); + Ep_avrg_fx = L_deposit_l( 0 ); FOR( i = 0; i < bands_fx; i++ ) { test(); - IF( GE_16(i,lowband)&&add(sub(i,bands_fx),p2a_bands_fx)<0) + IF( GE_16( i, lowband ) && add( sub( i, bands_fx ), p2a_bands_fx ) < 0 ) { #ifdef BASOP_NOGLOB Ep_vari_fx = L_add_sat( Ep_vari_fx, L_abs( L_sub_sat( Ep_tmp_fx[i], Ep_tmp_fx[sub( i, 1 )] ) ) ); /*Q15 */ #else - Ep_vari_fx = L_add(Ep_vari_fx,L_abs(L_sub(Ep_tmp_fx[i],Ep_tmp_fx[sub(i,1)])));/*Q15 */ + Ep_vari_fx = L_add( Ep_vari_fx, L_abs( L_sub( Ep_tmp_fx[i], Ep_tmp_fx[sub( i, 1 )] ) ) ); /*Q15 */ #endif #ifdef BASOP_NOGLOB - Ep_avrg_fx = L_add_o(Ep_avrg_fx,Ep_tmp_fx[i], &Overflow);/*Q15 */ -#else /* BASOP_NOGLOB */ - Ep_avrg_fx = L_add(Ep_avrg_fx,Ep_tmp_fx[i]);/*Q15 */ -#endif /* BASOP_NOGLOB */ + Ep_avrg_fx = L_add_o( Ep_avrg_fx, Ep_tmp_fx[i], &Overflow ); /*Q15 */ +#else /* BASOP_NOGLOB */ + Ep_avrg_fx = L_add( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ +#endif /* BASOP_NOGLOB */ } - IF(GE_16(i,highband)) + IF( GE_16( i, highband ) ) { #ifdef BASOP_NOGLOB enerH_fx = L_add_sat( enerH_fx, L_shl_sat( Ep_fx[i], 2 ) ); /*Q0 */ #else - enerH_fx = L_add(enerH_fx,L_shl(Ep_fx[i],2));/*Q0 */ + enerH_fx = L_add( enerH_fx, L_shl( Ep_fx[i], 2 ) ); /*Q0 */ #endif } - ELSE IF(GE_16(i,lowband)) + ELSE IF( GE_16( i, lowband ) ) { #ifdef BASOP_NOGLOB enerL_fx = L_add_sat( enerL_fx, L_shl_sat( Ep_fx[i], 2 ) ); /*Q0 */ #else - enerL_fx = L_add(enerL_fx,L_shl(Ep_fx[i],2));/*Q0 */ + enerL_fx = L_add( enerL_fx, L_shl( Ep_fx[i], 2 ) ); /*Q0 */ #endif } } /* modify the last p2a_bands subbands band_energies */ - Copy32( L_band_energy,L_band_energy_tmp,bands_fx ); /*Q_band_energy */ - L_tmp = L_max(enerH_fx,enerL_fx); - tmp = s_max(bw_low,bw_high); - i = norm_l(L_tmp); - j = norm_s(tmp); - L_tmp = Mult_32_16(L_shl(enerH_fx,i), shl(bw_low,j)); /* i + j -15 */ - L_tmp2 = Mult_32_16(L_shl(enerL_fx,i), shl(bw_high,j)); /*i + j -15 */ - L_tmp2 = L_sub(L_tmp,L_tmp2); - FOR( i = sub(bands_fx,p2a_bands_fx); i < bands_fx; i++ ) + Copy32( L_band_energy, L_band_energy_tmp, bands_fx ); /*Q_band_energy */ + L_tmp = L_max( enerH_fx, enerL_fx ); + tmp = s_max( bw_low, bw_high ); + i = norm_l( L_tmp ); + j = norm_s( tmp ); + L_tmp = Mult_32_16( L_shl( enerH_fx, i ), shl( bw_low, j ) ); /* i + j -15 */ + L_tmp2 = Mult_32_16( L_shl( enerL_fx, i ), shl( bw_high, j ) ); /*i + j -15 */ + L_tmp2 = L_sub( L_tmp, L_tmp2 ); + FOR( i = sub( bands_fx, p2a_bands_fx ); i < bands_fx; i++ ) { test(); - IF( EQ_16(p2a_flags_fx[i],1)||L_tmp2>0) + IF( EQ_16( p2a_flags_fx[i], 1 ) || L_tmp2 > 0 ) { - tmp = sub(bands_fx,p2a_bands_fx); - tmp = sub(tmp,lowband);/*Q0 */ + tmp = sub( bands_fx, p2a_bands_fx ); + tmp = sub( tmp, lowband ); /*Q0 */ #ifdef BASOP_NOGLOB tmp1 = extract_h( L_shl_sat( Ep_avrg_fx, 1 ) ); /*Q0 */ #else - tmp1 = extract_h( L_shl( Ep_avrg_fx, 1 ) ); /*Q0 */ + tmp1 = extract_h( L_shl( Ep_avrg_fx, 1 ) ); /*Q0 */ #endif - IF(tmp1 != 0) + IF( tmp1 != 0 ) { - exp = norm_s(tmp1); - tmp1 = shl(tmp1,exp);/*Q(exp) */ - tmp1 = div_s(16384,tmp1);/*Q(15+14-exp = 29-exp) */ - exp = sub(29,exp); + exp = norm_s( tmp1 ); + tmp1 = shl( tmp1, exp ); /*Q(exp) */ + tmp1 = div_s( 16384, tmp1 ); /*Q(15+14-exp = 29-exp) */ + exp = sub( 29, exp ); } ELSE { @@ -781,41 +775,41 @@ void hq_lr_enc_fx( exp = 0; move16(); } - L_tmp = Mult_32_16(Ep_tmp_fx[i],tmp1);/*Q(15+exp-15 = exp) */ - L_tmp = Mult_32_16(L_tmp,tmp);/*Q(exp+0-15 = exp-15) */ - L_tmp = Mult_32_16(L_tmp,16384);/*Q(exp-15+13-15 = exp-17) */ - L_tmp = L_shl(L_tmp,sub(32,exp));/*Q15 */ - tmp = extract_l(L_min(L_tmp,6554));/*Q15 */ - L_tmp = Mult_32_16(Ep_vari_fx,tmp1);/*Q(15+exp-15 = exp) */ - L_tmp = Mult_32_16(L_tmp,tmp);/*Q(exp+15-15 = exp) */ - L_tmp = L_shl(L_tmp,sub(15,exp));/*Q15 */ - tmp = extract_l(L_shr(L_min(L_tmp,13107),1));/*Q14 */ - alpha_fx = add(tmp,16384);/*Q14 */ + L_tmp = Mult_32_16( Ep_tmp_fx[i], tmp1 ); /*Q(15+exp-15 = exp) */ + L_tmp = Mult_32_16( L_tmp, tmp ); /*Q(exp+0-15 = exp-15) */ + L_tmp = Mult_32_16( L_tmp, 16384 ); /*Q(exp-15+13-15 = exp-17) */ + L_tmp = L_shl( L_tmp, sub( 32, exp ) ); /*Q15 */ + tmp = extract_l( L_min( L_tmp, 6554 ) ); /*Q15 */ + L_tmp = Mult_32_16( Ep_vari_fx, tmp1 ); /*Q(15+exp-15 = exp) */ + L_tmp = Mult_32_16( L_tmp, tmp ); /*Q(exp+15-15 = exp) */ + L_tmp = L_shl( L_tmp, sub( 15, exp ) ); /*Q15 */ + tmp = extract_l( L_shr( L_min( L_tmp, 13107 ), 1 ) ); /*Q14 */ + alpha_fx = add( tmp, 16384 ); /*Q14 */ } ELSE { alpha_fx = 16384; - move16();/*Q14 */ + move16(); /*Q14 */ } - IF(add(sub(i,bands_fx),p2a_bands_fx) > 0) + IF( add( sub( i, bands_fx ), p2a_bands_fx ) > 0 ) { - tmp = sub(bands_fx,p2a_bands_fx); - IF(EQ_16(hHQ_core->last_bitalloc_max_band[sub(i, add(tmp, 1))], 1)) + tmp = sub( bands_fx, p2a_bands_fx ); + IF( EQ_16( hHQ_core->last_bitalloc_max_band[sub( i, add( tmp, 1 ) )], 1 ) ) { - tmp = sub(tmp,lowband); - L_tmp = Mult_32_16(Ep_tmp_fx[i],tmp);/*Q(15+0-15 = 0) */ + tmp = sub( tmp, lowband ); + L_tmp = Mult_32_16( Ep_tmp_fx[i], tmp ); /*Q(15+0-15 = 0) */ #ifdef BASOP_NOGLOB - tmp = extract_h(L_shl_o(L_tmp,16, &Overflow));/*Q0 */ -#else /* BASOP_NOGLOB */ - tmp = extract_h(L_shl(L_tmp,16));/*Q0 */ -#endif /* BASOP_NOGLOB */ - IF(tmp != 0) + tmp = extract_h( L_shl_o( L_tmp, 16, &Overflow ) ); /*Q0 */ +#else /* BASOP_NOGLOB */ + tmp = extract_h( L_shl( L_tmp, 16 ) ); /*Q0 */ +#endif /* BASOP_NOGLOB */ + IF( tmp != 0 ) { - exp = norm_s(tmp); - tmp = shl(tmp,exp);/*Q(exp) */ - tmp = div_s(16384,tmp);/*Q(15+14-exp=29-exp) */ - exp = sub(29,exp); + exp = norm_s( tmp ); + tmp = shl( tmp, exp ); /*Q(exp) */ + tmp = div_s( 16384, tmp ); /*Q(15+14-exp=29-exp) */ + exp = sub( 29, exp ); } ELSE { @@ -824,27 +818,27 @@ void hq_lr_enc_fx( exp = 0; move16(); } - L_tmp = Mult_32_16(Ep_avrg_fx,tmp);/*Q(15+exp-15 = exp) */ - L_tmp = L_shl(L_tmp,sub(14,exp));/*Q14 */ - tmp = extract_l(L_min(L_max(L_tmp,16384),20480));/*Q14 */ - L_tmp = L_mult(alpha_fx,tmp);/*Q(14+14+1=29) */ - alpha_fx = extract_l(L_shr(L_tmp,15)); /*Q14 */ + L_tmp = Mult_32_16( Ep_avrg_fx, tmp ); /*Q(15+exp-15 = exp) */ + L_tmp = L_shl( L_tmp, sub( 14, exp ) ); /*Q14 */ + tmp = extract_l( L_min( L_max( L_tmp, 16384 ), 20480 ) ); /*Q14 */ + L_tmp = L_mult( alpha_fx, tmp ); /*Q(14+14+1=29) */ + alpha_fx = extract_l( L_shr( L_tmp, 15 ) ); /*Q14 */ } ELSE { - tmp = sub(tmp,lowband); + tmp = sub( tmp, lowband ); #ifdef BASOP_NOGLOB tmp1 = extract_h( L_shl_sat( Ep_avrg_fx, 1 ) ); /*Q0 */ #else - tmp1 = extract_h( L_shl( Ep_avrg_fx, 1 ) ); /*Q0 */ + tmp1 = extract_h( L_shl( Ep_avrg_fx, 1 ) ); /*Q0 */ #endif - IF(tmp1 != 0) + IF( tmp1 != 0 ) { - exp = norm_s(tmp1); - tmp1 = shl(tmp1,exp);/*Q(exp) */ - tmp1 = div_s(16384,tmp1);/*Q(15+14-exp=29-exp) */ - exp = sub(29,exp); + exp = norm_s( tmp1 ); + tmp1 = shl( tmp1, exp ); /*Q(exp) */ + tmp1 = div_s( 16384, tmp1 ); /*Q(15+14-exp=29-exp) */ + exp = sub( 29, exp ); } ELSE { @@ -853,73 +847,73 @@ void hq_lr_enc_fx( exp = 0; move16(); } - L_tmp = Mult_32_16(Ep_tmp_fx[i],tmp1);/*Q(15+exp-15 = exp) */ - L_tmp = Mult_32_16(L_tmp,tmp);/*Q(exp+0-15 = exp-15) */ - L_tmp = L_shl(L_tmp,sub(29,exp));/*Q14 */ - tmp = extract_l(L_min(L_max(L_tmp,13926),16384));/*Q14 */ - L_tmp = L_mult(alpha_fx,tmp);/*Q(14+14+1=29) */ - alpha_fx = extract_l(L_shr(L_tmp,15)); /*Q14 */ + L_tmp = Mult_32_16( Ep_tmp_fx[i], tmp1 ); /*Q(15+exp-15 = exp) */ + L_tmp = Mult_32_16( L_tmp, tmp ); /*Q(exp+0-15 = exp-15) */ + L_tmp = L_shl( L_tmp, sub( 29, exp ) ); /*Q14 */ + tmp = extract_l( L_min( L_max( L_tmp, 13926 ), 16384 ) ); /*Q14 */ + L_tmp = L_mult( alpha_fx, tmp ); /*Q(14+14+1=29) */ + alpha_fx = extract_l( L_shr( L_tmp, 15 ) ); /*Q14 */ } } - L_tmp = Mult_32_16(L_band_energy_tmp[i],alpha_fx);/*Q(Q_band_energy+14-15=Q_band_energy-1) */ - L_band_energy_tmp[i] = L_shl(L_tmp,1);/*Q Q_band_energy */ + L_tmp = Mult_32_16( L_band_energy_tmp[i], alpha_fx ); /*Q(Q_band_energy+14-15=Q_band_energy-1) */ + L_band_energy_tmp[i] = L_shl( L_tmp, 1 ); /*Q Q_band_energy */ } lowband = 6; move16(); - Ep_avrg_fx = L_deposit_l(0); - Ep_avrgL_fx = L_deposit_l(0); - Ep_peak_fx = L_deposit_l(0); - FOR(i = 0; i < bands_fx; i++) + Ep_avrg_fx = L_deposit_l( 0 ); + Ep_avrgL_fx = L_deposit_l( 0 ); + Ep_peak_fx = L_deposit_l( 0 ); + FOR( i = 0; i < bands_fx; i++ ) { - IF(GE_16(i,lowband)) + IF( GE_16( i, lowband ) ) { #ifdef BASOP_NOGLOB - Ep_avrg_fx = L_add_o(Ep_avrg_fx,Ep_tmp_fx[i], &Overflow);/*Q15 */ -#else /* BASOP_NOGLOB */ - Ep_avrg_fx = L_add(Ep_avrg_fx,Ep_tmp_fx[i]);/*Q15 */ -#endif /* BASOP_NOGLOB */ + Ep_avrg_fx = L_add_o( Ep_avrg_fx, Ep_tmp_fx[i], &Overflow ); /*Q15 */ +#else /* BASOP_NOGLOB */ + Ep_avrg_fx = L_add( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ +#endif /* BASOP_NOGLOB */ } ELSE { #ifdef BASOP_NOGLOB - Ep_avrgL_fx = L_add_o(Ep_avrgL_fx,Ep_tmp_fx[i], &Overflow);/*Q15 */ -#else /* BASOP_NOGLOB */ - Ep_avrgL_fx = L_add(Ep_avrgL_fx,Ep_tmp_fx[i]);/*Q15 */ + Ep_avrgL_fx = L_add_o( Ep_avrgL_fx, Ep_tmp_fx[i], &Overflow ); /*Q15 */ +#else /* BASOP_NOGLOB */ + Ep_avrgL_fx = L_add( Ep_avrgL_fx, Ep_tmp_fx[i] ); /*Q15 */ #endif - IF(GT_32(Ep_tmp_fx[i],Ep_peak_fx)) + IF( GT_32( Ep_tmp_fx[i], Ep_peak_fx ) ) { - Ep_peak_fx = L_add(Ep_tmp_fx[i], 0); /*Q15 */ + Ep_peak_fx = L_add( Ep_tmp_fx[i], 0 ); /*Q15 */ } } } - L_tmp = Mult_32_16(Ep_peak_fx,24576);/*Q(15+12-15 = 12) lowband = 6; */ - L_tmp2 =Mult_32_16(Ep_peak_fx,19661);/*Q(15+14-15 = 14) */ - L_tmp3 =Mult_32_16(Ep_avrgL_fx,24576);/*Q(15+12-15 = 12) */ + L_tmp = Mult_32_16( Ep_peak_fx, 24576 ); /*Q(15+12-15 = 12) lowband = 6; */ + L_tmp2 = Mult_32_16( Ep_peak_fx, 19661 ); /*Q(15+14-15 = 14) */ + L_tmp3 = Mult_32_16( Ep_avrgL_fx, 24576 ); /*Q(15+12-15 = 12) */ test(); test(); test(); test(); test(); - IF( (GT_32(L_shr(Ep_avrgL_fx,1), Ep_avrg_fx)&>_32(L_tmp,L_shr(Ep_avrgL_fx,2))&<_32(L_shr(Ep_avrgL_fx,1),L_tmp2))|| - (GT_32(L_shr(Ep_avrg_fx,1), Ep_avrgL_fx) && LT_32(L_shr(Ep_avrg_fx,3),L_tmp3) && GT_32(L_tmp,L_shr(Ep_avrgL_fx,2)) ) ) + IF( ( GT_32( L_shr( Ep_avrgL_fx, 1 ), Ep_avrg_fx ) && GT_32( L_tmp, L_shr( Ep_avrgL_fx, 2 ) ) && LT_32( L_shr( Ep_avrgL_fx, 1 ), L_tmp2 ) ) || + ( GT_32( L_shr( Ep_avrg_fx, 1 ), Ep_avrgL_fx ) && LT_32( L_shr( Ep_avrg_fx, 3 ), L_tmp3 ) && GT_32( L_tmp, L_shr( Ep_avrgL_fx, 2 ) ) ) ) { adjustFlag = 1; move16(); - FOR (i = 0; i < lowband; i++) + FOR( i = 0; i < lowband; i++ ) { #ifdef BASOP_NOGLOB tmp = extract_h( L_shl_sat( Ep_avrgL_fx, 1 ) ); /*Q0 */ #else - tmp = extract_h( L_shl( Ep_avrgL_fx, 1 ) ); /*Q0 */ + tmp = extract_h( L_shl( Ep_avrgL_fx, 1 ) ); /*Q0 */ #endif - IF(tmp != 0) + IF( tmp != 0 ) { - exp = norm_s(tmp); - tmp = shl(tmp,exp);/*Q(exp) */ - tmp = div_s(16384,tmp);/*Q(15+14-exp=29-exp) */ - exp = sub(29,exp); + exp = norm_s( tmp ); + tmp = shl( tmp, exp ); /*Q(exp) */ + tmp = div_s( 16384, tmp ); /*Q(15+14-exp=29-exp) */ + exp = sub( 29, exp ); } ELSE { @@ -928,12 +922,12 @@ void hq_lr_enc_fx( exp = 0; move16(); } - L_tmp = Mult_32_16(Ep_peak_fx,tmp);/*Q(15+exp-15 = exp) */ - L_tmp = Mult_32_16(L_tmp,lowband);/*Q(exp+0-15 = exp-15) */ - L_tmp = L_shl(L_tmp,sub(28,exp));/*Q14 0.5 */ - tmp = extract_l(L_min(L_tmp,19661));/*//Q14 */ - L_tmp = Mult_32_16(L_band_energy_tmp[i],tmp);/*Q(Q_band_energy+14-15 = Q_band_energy-1) */ - L_band_energy_tmp[i] = L_shl(L_tmp,1); /*Q_band_energy */ + L_tmp = Mult_32_16( Ep_peak_fx, tmp ); /*Q(15+exp-15 = exp) */ + L_tmp = Mult_32_16( L_tmp, lowband ); /*Q(exp+0-15 = exp-15) */ + L_tmp = L_shl( L_tmp, sub( 28, exp ) ); /*Q14 0.5 */ + tmp = extract_l( L_min( L_tmp, 19661 ) ); /*//Q14 */ + L_tmp = Mult_32_16( L_band_energy_tmp[i], tmp ); /*Q(Q_band_energy+14-15 = Q_band_energy-1) */ + L_band_energy_tmp[i] = L_shl( L_tmp, 1 ); /*Q_band_energy */ } } @@ -941,12 +935,12 @@ void hq_lr_enc_fx( *num_bits_fx, hqswb_clas_fx, st_fx->bwidth, is_transient_fx ); /* encode the last p2a_bands-1 subbands bit-allocation index of the previous frame */ - FOR(i = 0; i < 2; i++) + FOR( i = 0; i < 2; i++ ) { push_indice_fx( st_fx->hBstr, IND_HQ2_LAST_BA_MAX_BAND, hHQ_core->last_bitalloc_max_band[i], 1 ); } } - ELSE IF( EQ_16(st_fx->bwidth, SWB)&&EQ_16(hqswb_clas_fx,HQ_HARMONIC)&&(EQ_32(L_bwe_br,HQ_16k40)||EQ_32(L_bwe_br,HQ_13k20))) + ELSE IF( EQ_16( st_fx->bwidth, SWB ) && EQ_16( hqswb_clas_fx, HQ_HARMONIC ) && ( EQ_32( L_bwe_br, HQ_16k40 ) || EQ_32( L_bwe_br, HQ_13k20 ) ) ) { /* bit allocation for harmonic mode */ hq2_bit_alloc_har_fx( L_band_energy, bit_budget_fx, bands_fx, L_Rk, p2a_bands_fx, L_bwe_br, p2a_flags_fx, band_width ); @@ -960,15 +954,15 @@ void hq_lr_enc_fx( *num_bits_fx, hqswb_clas_fx, st_fx->bwidth, is_transient_fx ); } - tcq_core_LR_enc_fx( hBstr, /*st_fx->idchan, */inp_vector_fx, /*t_audio, */L_t_audio, /*y2, */L_y2, bit_budget_fx, bands_fx, band_start, band_end, band_width, /*Rk*/L_Rk, npulses_fx, k_sort_fx, + tcq_core_LR_enc_fx( hBstr, /*st_fx->idchan, */ inp_vector_fx, /*t_audio, */ L_t_audio, /*y2, */ L_y2, bit_budget_fx, bands_fx, band_start, band_end, band_width, /*Rk*/ L_Rk, npulses_fx, k_sort_fx, p2a_flags_fx, p2a_bands_fx, hHQ_core->last_bitalloc_max_band, inner_frame_fx, adjustFlag, is_transient_fx ); - IF((EQ_16(inner_frame_fx, L_FRAME8k)&&LE_32(st_fx->core_brate,ACELP_13k20))||EQ_16(inner_frame_fx,L_FRAME16k)) + IF( ( EQ_16( inner_frame_fx, L_FRAME8k ) && LE_32( st_fx->core_brate, ACELP_13k20 ) ) || EQ_16( inner_frame_fx, L_FRAME16k ) ) { j = 0; - FOR(i = 2; i > 0; i--) + FOR( i = 2; i > 0; i-- ) { - IF(npulses_fx[bands_fx-i] > 0) + IF( npulses_fx[bands_fx - i] > 0 ) { hHQ_core->last_bitalloc_max_band[j] = 1; } @@ -989,59 +983,59 @@ void hq_lr_enc_fx( /* Restore the band information */ - IF( EQ_16(flag_spt_fx, 1)) + IF( EQ_16( flag_spt_fx, 1 ) ) { - spt_shorten_domain_band_restore_fx(bands_fx, band_start, band_end, band_width, org_band_start, org_band_end, org_band_width); + spt_shorten_domain_band_restore_fx( bands_fx, band_start, band_end, band_width, org_band_start, org_band_end, org_band_width ); } /* Inject noise into components having relatively low pulse energy per band */ - ni_seed_fx = add(add(add(npulses_fx[0], npulses_fx[1]), npulses_fx[2]), npulses_fx[3]); + ni_seed_fx = add( add( add( npulses_fx[0], npulses_fx[1] ), npulses_fx[2] ), npulses_fx[3] ); - Copy32(L_y2, L_y2_ni, band_end[bands_fx-1]+1); + Copy32( L_y2, L_y2_ni, band_end[bands_fx - 1] + 1 ); hq2_noise_inject_fx( L_y2_ni, band_start, band_end, band_width, Ep_fx, L_Rk, npulses_fx, ni_seed_fx, bands_fx, 0, bw_low, bw_high, enerL_fx, enerH_fx, - hHQ_core->last_ni_gain_fx, hHQ_core->last_env_fx, &hHQ_core->last_max_pos_pulse, p2a_flags_fx, p2a_bands_fx, + hHQ_core->last_ni_gain_fx, hHQ_core->last_env_fx, &hHQ_core->last_max_pos_pulse, p2a_flags_fx, p2a_bands_fx, hqswb_clas_fx, st_fx->bwidth, L_bwe_br ); test(); test(); - IF( EQ_16(st_fx->bwidth, SWB)&&(EQ_32(L_bwe_br,HQ_16k40)||EQ_32(L_bwe_br,HQ_13k20))) + IF( EQ_16( st_fx->bwidth, SWB ) && ( EQ_32( L_bwe_br, HQ_16k40 ) || EQ_32( L_bwe_br, HQ_13k20 ) ) ) { test(); - IF( EQ_16(hqswb_clas_fx, HQ_NORMAL)||EQ_16(hqswb_clas_fx,HQ_HARMONIC)) + IF( EQ_16( hqswb_clas_fx, HQ_NORMAL ) || EQ_16( hqswb_clas_fx, HQ_HARMONIC ) ) { - preset_hq2_swb_fx( hqswb_clas_fx, band_end, &har_bands_fx, p2a_bands_fx,length_fx, bands_fx, &lowlength_fx, &highlength_fx, L_m ); + preset_hq2_swb_fx( hqswb_clas_fx, band_end, &har_bands_fx, p2a_bands_fx, length_fx, bands_fx, &lowlength_fx, &highlength_fx, L_m ); swb_bwe_enc_lr_fx( st_fx, L_y2, SWB_BWE_LR_Qs, L_t_audio, L_m, L_bwe_br, - bands_fx, band_start, band_end, L_band_energy, SWB_BWE_LR_Qbe, p2a_flags_fx, hqswb_clas_fx, lowlength_fx, highlength_fx, - hHQ_core->prev_frm_index, har_bands_fx, &hHQ_core->prev_frm_hfe2, &hHQ_core->prev_stab_hfe2, band_width, L_y2_ni, &ni_seed_fx); + bands_fx, band_start, band_end, L_band_energy, SWB_BWE_LR_Qbe, p2a_flags_fx, hqswb_clas_fx, lowlength_fx, highlength_fx, + hHQ_core->prev_frm_index, har_bands_fx, &hHQ_core->prev_frm_hfe2, &hHQ_core->prev_stab_hfe2, band_width, L_y2_ni, &ni_seed_fx ); post_hq2_swb_fx( L_m, lowlength_fx, highlength_fx, hqswb_clas_fx, har_bands_fx, bands_fx, p2a_flags_fx, band_start, band_end, L_y2, npulses_fx ); - IF( EQ_16(hqswb_clas_fx, HQ_NORMAL)) + IF( EQ_16( hqswb_clas_fx, HQ_NORMAL ) ) { - spt_swb_peakpos_tmp_save_fx(L_y2, bands_fx, band_start, band_end, prev_SWB_peak_pos_tmp_fx); - FOR( k=0; kbwidth, is_transient_fx, hqswb_clas_fx, &hHQ_core->prev_hqswb_clas, hHQ_core->prev_SWB_peak_pos, prev_SWB_peak_pos_tmp_fx, &hHQ_core->prev_frm_hfe2, &hHQ_core->prev_stab_hfe2, 0 ); - IF( NE_16(st_fx->bwidth, SWB)) + IF( NE_16( st_fx->bwidth, SWB ) ) { /* reset HQ classifier memories */ hHQ_core->mode_count = 0; @@ -1053,7 +1047,7 @@ void hq_lr_enc_fx( test(); test(); test(); - IF( NE_16(hqswb_clas_fx, HQ_HARMONIC)&&(EQ_32(L_bwe_br,HQ_16k40)||EQ_32(L_bwe_br,HQ_13k20))&&EQ_16(st_fx->bwidth,SWB)) + IF( NE_16( hqswb_clas_fx, HQ_HARMONIC ) && ( EQ_32( L_bwe_br, HQ_16k40 ) || EQ_32( L_bwe_br, HQ_13k20 ) ) && EQ_16( st_fx->bwidth, SWB ) ) { hHQ_core->prev_frm_index[0] = -1; move16(); @@ -1079,28 +1073,27 @@ void hq_lr_enc_fx( * if flag_pack = 0, estimatng else packing bits *--------------------------------------------------------------------------*/ -static Word16 small_symbol_enc_tran_fx( /* o : bits */ - BSTR_ENC_HANDLE hBstr, /* i : handle to the bitstream */ - const Word16 *qbidx, /* i : input of dequantized differential energy */ - const Word16 BANDS, /* i : number of bands */ - Word16 *hLCmode, /* i/o: LC mode info */ - const Word16 flag_pack, /* i : indicator of packing or estimating bits */ - const Word16 is_transient -) +static Word16 small_symbol_enc_tran_fx( /* o : bits */ + BSTR_ENC_HANDLE hBstr, /* i : handle to the bitstream */ + const Word16 *qbidx, /* i : input of dequantized differential energy */ + const Word16 BANDS, /* i : number of bands */ + Word16 *hLCmode, /* i/o: LC mode info */ + const Word16 flag_pack, /* i : indicator of packing or estimating bits */ + const Word16 is_transient ) { Word16 i, bits; Word16 difidx[BANDS_MAX]; - FOR( i=0; i= -(2<<(i+1))) */ test(); - IF ( LE_16(max_q, sub(shl(2, add(i,1)), 1))&& GE_16(min_q,-shl(2,add(i,1)))) + IF( LE_16( max_q, sub( shl( 2, add( i, 1 ) ), 1 ) ) && GE_16( min_q, -shl( 2, add( i, 1 ) ) ) ) { BREAK; } @@ -1375,21 +1368,21 @@ static Word16 large_symbol_enc_fx( /* o : bits move16(); min_bits_pos = basic_shift; move16(); - tmp = add(basic_shift, 3); - FOR( offset0=basic_shift; offset0 0 ) + IF( lsbdepth1 > 0 ) { - FOR( i=0; i QE) */ - FOR (i = band_start[k]; i <= band_end[k]; i++) + QE = add( shl( sub( add( SWB_BWE_LR_Qs, exp_norm ), 16 ), 1 ), 1 ); + L_E = L_shl( 590L, sub( QE, 15 ) ); /* 590 0.018f(Q15 -> QE) */ + FOR( i = band_start[k]; i <= band_end[k]; i++ ) { /*E += yos[i] * yos[i]; */ - temp_fx = round_fx(L_shl(L_t_audio[i], exp_norm)); - L_E = L_mac(L_E, temp_fx, temp_fx); /* (Qs+exp_norm-16)*2+1 */ + temp_fx = round_fx( L_shl( L_t_audio[i], exp_norm ) ); + L_E = L_mac( L_E, temp_fx, temp_fx ); /* (Qs+exp_norm-16)*2+1 */ } /*band_energy[k] = (float) log2_f (E + 1.0e-1f); */ - exp_norm2 = norm_l(L_E); - exp = add(add(shl(sub(add(SWB_BWE_LR_Qs, exp_norm), 16), 1), 1), exp_norm2); - L_E = L_shl(L_E, exp_norm2); - frac = Log2_norm_lc(L_E); - exp = sub(30, exp); - L_tmp = L_Comp(exp, frac); - L_band_energy[k] = L_shr(L_tmp, 2); /* Q16->Qbe(Q14) */ + exp_norm2 = norm_l( L_E ); + exp = add( add( shl( sub( add( SWB_BWE_LR_Qs, exp_norm ), 16 ), 1 ), 1 ), exp_norm2 ); + L_E = L_shl( L_E, exp_norm2 ); + frac = Log2_norm_lc( L_E ); + exp = sub( 30, exp ); + L_tmp = L_Comp( exp, frac ); + L_band_energy[k] = L_shr( L_tmp, 2 ); /* Q16->Qbe(Q14) */ } - IF (is_transient_fx) + IF( is_transient_fx ) { reverse_transient_frame_energies_fx( L_band_energy, bands_fx ); } /* Quantize the reference and band energies */ - exp_normd = norm_l(L_qint); - rev_qint_fx = div_s(0x4000, round_fx(L_shl(L_qint, exp_normd))); /* Q14-(29+exp_normd-16)+15 */ - Qrev_qint = sub(14-(29-16)+15, exp_normd); + exp_normd = norm_l( L_qint ); + rev_qint_fx = div_s( 0x4000, round_fx( L_shl( L_qint, exp_normd ) ) ); /* Q14-(29+exp_normd-16)+15 */ + Qrev_qint = sub( 14 - ( 29 - 16 ) + 15, exp_normd ); - bq0_fx = round_fx(L_shl(L_mult(eref_fx, rev_qint_fx), sub(5, Qrev_qint))); /* 16-(10+Qrev_qint+1) */ - FOR (k = 0; k < bands_fx; k++) + bq0_fx = round_fx( L_shl( L_mult( eref_fx, rev_qint_fx ), sub( 5, Qrev_qint ) ) ); /* 16-(10+Qrev_qint+1) */ + FOR( k = 0; k < bands_fx; k++ ) { /*bq1[k] = round_f (band_energy[k] / qint); */ - L_tmp = Mpy_32_16_1(L_band_energy[k], rev_qint_fx); /* Q14+Qrev_qint-15 */ - bq1_fx[k] = round_fx( L_shl(L_tmp, sub(17, Qrev_qint)) ); /* 16-(14+Qrev_qint-15) */ + L_tmp = Mpy_32_16_1( L_band_energy[k], rev_qint_fx ); /* Q14+Qrev_qint-15 */ + bq1_fx[k] = round_fx( L_shl( L_tmp, sub( 17, Qrev_qint ) ) ); /* 16-(14+Qrev_qint-15) */ } - IF(is_transient_fx) + IF( is_transient_fx ) { - Copy(bq1_fx, bq1_temp_fx, bands_fx); + Copy( bq1_fx, bq1_temp_fx, bands_fx ); /* Calculate the differential energies */ - diffcod_lrmdct_fx(bands_fx, bq0_fx, bq1_temp_fx, bq2_temp_fx, is_transient_fx); + diffcod_lrmdct_fx( bands_fx, bq0_fx, bq1_temp_fx, bq2_temp_fx, is_transient_fx ); } /* Calculate the differential energies */ - bq2_fx[0] = sub(bq1_fx[0], bq0_fx); - FOR (k = 1; k < bands_fx; k++) + bq2_fx[0] = sub( bq1_fx[0], bq0_fx ); + FOR( k = 1; k < bands_fx; k++ ) { - bq2_fx[k] = sub(bq1_fx[k], bq1_fx[k - 1]); + bq2_fx[k] = sub( bq1_fx[k], bq1_fx[k - 1] ); move16(); } /* Modifying qbidx to be located in the range -256~255 */ - FOR( i=0; i Qbe(Q14) */ + L_band_energy[k] = Mpy_32_16_1( L_qint, bq1_fx[k] ); /* 29+0-15 -> Qbe(Q14) */ } - IF (is_transient_fx) + IF( is_transient_fx ) { reverse_transient_frame_energies_fx( L_band_energy, bands_fx ); } - return( deng_bits ); + return ( deng_bits ); } @@ -1737,15 +1730,15 @@ static Word16 band_energy_quant_fx( *-------------------------------------------------------------------*/ static Word16 p2a_threshold_quant_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: : bit stream */ - const Word32 *L_t_audio, /* i : Q12 : input spectrum */ - const Word16 band_start[], /* i : Q0 : table of start freq for every subband */ - const Word16 band_end[], /* i : Q0 : table of end freq for every subband */ - const Word16 band_width[], /* i : Q0 : table of bandwidth for every subband */ - const Word16 bands, /* i : Q0 : number of subbands */ - const Word16 p2a_bands, /* i : Q0 : tonality indicator */ - const Word16 p2a_th_fx, /* i : Q11 : threshold tonal or not */ - Word16 *p2a_flags_fx /* i/o: Q0 : tonality flag */ + BSTR_ENC_HANDLE hBstr, /* i/o: : bit stream */ + const Word32 *L_t_audio, /* i : Q12 : input spectrum */ + const Word16 band_start[], /* i : Q0 : table of start freq for every subband */ + const Word16 band_end[], /* i : Q0 : table of end freq for every subband */ + const Word16 band_width[], /* i : Q0 : table of bandwidth for every subband */ + const Word16 bands, /* i : Q0 : number of subbands */ + const Word16 p2a_bands, /* i : Q0 : tonality indicator */ + const Word16 p2a_th_fx, /* i : Q11 : threshold tonal or not */ + Word16 *p2a_flags_fx /* i/o: Q0 : tonality flag */ ) { Word16 i, j, k; @@ -1757,7 +1750,7 @@ static Word16 p2a_threshold_quant_fx( Word16 exp_safe; Word16 exp_normn, exp_normd; - Word16 norm_a_fx,Qnorm_a; + Word16 norm_a_fx, Qnorm_a; Word16 pa_fx, Qpa; Word16 exp, frac; @@ -1768,77 +1761,77 @@ static Word16 p2a_threshold_quant_fx( Flag Overflow = 0; #endif - exp_safe=4; /* never happen overflow. */ + exp_safe = 4; /* never happen overflow. */ - set16_fx(p2a_flags_fx, 1, bands); + set16_fx( p2a_flags_fx, 1, bands ); j = 0; move16(); - FOR (k = sub(bands, p2a_bands); k < bands; k++) + FOR( k = sub( bands, p2a_bands ); k < bands; k++ ) { - L_a = L_deposit_l(0); - L_p = L_deposit_l(0); + L_a = L_deposit_l( 0 ); + L_p = L_deposit_l( 0 ); - L_tmp = L_deposit_l(0); - FOR (i = band_start[k]; i <= band_end[k]; i++) + L_tmp = L_deposit_l( 0 ); + FOR( i = band_start[k]; i <= band_end[k]; i++ ) { - L_tmp = L_or(L_tmp, L_abs(L_t_audio[i])); + L_tmp = L_or( L_tmp, L_abs( L_t_audio[i] ) ); } - exp_norm = norm_l(L_tmp); - exp_norm = sub(exp_norm, exp_safe); + exp_norm = norm_l( L_tmp ); + exp_norm = sub( exp_norm, exp_safe ); - FOR (i = band_start[k]; i <= band_end[k]; i++) + FOR( i = band_start[k]; i <= band_end[k]; i++ ) { - temp_fx = round_fx(L_shl(L_t_audio[i], exp_norm)); /* Q12+exp_norm-16 -> exp_norm-4 */ - L_e = L_mult(temp_fx, temp_fx); + temp_fx = round_fx( L_shl( L_t_audio[i], exp_norm ) ); /* Q12+exp_norm-16 -> exp_norm-4 */ + L_e = L_mult( temp_fx, temp_fx ); - if ( GT_32(L_e, L_p)) + if ( GT_32( L_e, L_p ) ) { - L_p = L_add(L_e, 0); + L_p = L_add( L_e, 0 ); } - L_a = L_add(L_a, L_e); + L_a = L_add( L_a, L_e ); } - Qa = sub(shl(exp_norm, 1), 7); /* (exp_norm-4)*2+1 */ + Qa = sub( shl( exp_norm, 1 ), 7 ); /* (exp_norm-4)*2+1 */ - IF ( L_a > 0x0L ) + IF( L_a > 0x0L ) { /* a /= band_width[k]; */ - exp_normn = norm_l(L_a); - exp_normn = sub(exp_normn, 1); - exp_normd = norm_s(band_width[k]); - norm_a_fx = div_l(L_shl(L_a, exp_normn), shl(band_width[k], exp_normd)); - Qnorm_a = sub(sub(add(Qa, exp_normn), exp_normd), 1); /* (Qa+exp_normn)-exp_normd-1); */ + exp_normn = norm_l( L_a ); + exp_normn = sub( exp_normn, 1 ); + exp_normd = norm_s( band_width[k] ); + norm_a_fx = div_l( L_shl( L_a, exp_normn ), shl( band_width[k], exp_normd ) ); + Qnorm_a = sub( sub( add( Qa, exp_normn ), exp_normd ), 1 ); /* (Qa+exp_normn)-exp_normd-1); */ /*p2a = 10.0f * (float) log10 (p / a); */ p2a_fx = 0; move16(); - IF ( norm_a_fx > 0 ) + IF( norm_a_fx > 0 ) { - exp_normn = norm_l(L_p); - exp_normn = sub(exp_normn, 1); - exp_normd = norm_s(norm_a_fx); - pa_fx = div_l(L_shl(L_p, exp_normn), shl(norm_a_fx, exp_normd)); - Qpa = sub(sub(add(Qa, exp_normn), add(Qnorm_a, exp_normd)), 1); - - L_tmp = L_deposit_h(pa_fx); - Qpa = add(Qpa, 16); - exp = norm_l(L_tmp); - frac = Log2_norm_lc(L_shl(L_tmp, exp)); - exp = sub(30, exp); - exp = sub(exp, Qpa); - L_tmp = L_Comp(exp, frac); + exp_normn = norm_l( L_p ); + exp_normn = sub( exp_normn, 1 ); + exp_normd = norm_s( norm_a_fx ); + pa_fx = div_l( L_shl( L_p, exp_normn ), shl( norm_a_fx, exp_normd ) ); + Qpa = sub( sub( add( Qa, exp_normn ), add( Qnorm_a, exp_normd ) ), 1 ); + + L_tmp = L_deposit_h( pa_fx ); + Qpa = add( Qpa, 16 ); + exp = norm_l( L_tmp ); + frac = Log2_norm_lc( L_shl( L_tmp, exp ) ); + exp = sub( 30, exp ); + exp = sub( exp, Qpa ); + L_tmp = L_Comp( exp, frac ); /* 10/( log(10)/log(2) ) = 3.01029995663981195211 24660(Q13) */ - L_p2a = Mpy_32_16_1(L_tmp, 24660); /* 16+13-15 -> Q14 */ + L_p2a = Mpy_32_16_1( L_tmp, 24660 ); /* 16+13-15 -> Q14 */ #ifdef BASOP_NOGLOB - p2a_fx = round_fx_o(L_shl_o(L_p2a, 13, &Overflow), &Overflow); /* 27 -16 -> 11 */ + p2a_fx = round_fx_o( L_shl_o( L_p2a, 13, &Overflow ), &Overflow ); /* 27 -16 -> 11 */ #else - p2a_fx = round_fx(L_shl(L_p2a, 13)); /* 27 -16 -> 11 */ + p2a_fx = round_fx( L_shl( L_p2a, 13 ) ); /* 27 -16 -> 11 */ #endif } - if ( LE_16(p2a_fx, p2a_th_fx)) + if ( LE_16( p2a_fx, p2a_th_fx ) ) { p2a_flags_fx[k] = 0; move16(); @@ -1851,10 +1844,10 @@ static Word16 p2a_threshold_quant_fx( } push_indice_fx( hBstr, IND_HQ2_P2A_FLAGS, p2a_flags_fx[k], 1 ); - j = add(j, 1); + j = add( j, 1 ); } - return( j ); + return ( j ); } /*-------------------------------------------------------------------* @@ -1864,17 +1857,17 @@ static Word16 p2a_threshold_quant_fx( *-------------------------------------------------------------------*/ static void mdct_spectrum_fine_gain_enc_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word32 L_ybuf[], /* i : Q12 : input spectrum */ - Word32 L_y2[], /* i/o: Q12 : decoded spectrum */ - const Word16 band_start[], /* i : Q0 : table of start freq for every subband */ - const Word16 band_end[], /* i : Q0 : table of end freq for every subband */ - const Word16 k_sort[], /* i : Q0 : sort table by band_energy */ - const Word16 bands, /* i : Q0 : nubmber of subbands */ - const Word32 L_qint, /* i : Q29 : */ - const Word16 Ngq, /* i : Q0 : */ - const Word16 gqlevs, /* i : Q0 : quantized level */ - const Word16 gqbits /* i : Q0 : quantized bits */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word32 L_ybuf[], /* i : Q12 : input spectrum */ + Word32 L_y2[], /* i/o: Q12 : decoded spectrum */ + const Word16 band_start[], /* i : Q0 : table of start freq for every subband */ + const Word16 band_end[], /* i : Q0 : table of end freq for every subband */ + const Word16 k_sort[], /* i : Q0 : sort table by band_energy */ + const Word16 bands, /* i : Q0 : nubmber of subbands */ + const Word32 L_qint, /* i : Q29 : */ + const Word16 Ngq, /* i : Q0 : */ + const Word16 gqlevs, /* i : Q0 : quantized level */ + const Word16 gqbits /* i : Q0 : quantized bits */ ) { Word16 i, k; @@ -1908,29 +1901,29 @@ static void mdct_spectrum_fine_gain_enc_fx( /* Fine gain quantization on only the most significant energy bands */ /*delta = qint / gqlevs; */ - exp_normn = norm_l(L_qint); - exp_normn = sub(exp_normn, 1); - exp_normd = norm_s(gqlevs); - delta_fx = div_l(L_shl(L_qint, exp_normn), shl(gqlevs, exp_normd)); - Qdelta = add(sub(exp_normn, exp_normd), 28); /* 29+exp_normn-(exp_normd)-1; */ - L_delta = L_shl(L_deposit_h(delta_fx), sub(13, Qdelta)); + exp_normn = norm_l( L_qint ); + exp_normn = sub( exp_normn, 1 ); + exp_normd = norm_s( gqlevs ); + delta_fx = div_l( L_shl( L_qint, exp_normn ), shl( gqlevs, exp_normd ) ); + Qdelta = add( sub( exp_normn, exp_normd ), 28 ); /* 29+exp_normn-(exp_normd)-1; */ + L_delta = L_shl( L_deposit_h( delta_fx ), sub( 13, Qdelta ) ); /*q = (-qint + delta) / 2.0f; */ - L_q = L_shr(L_sub(L_delta, L_qint), 1); + L_q = L_shr( L_sub( L_delta, L_qint ), 1 ); - FOR (i = 0; i < gqlevs; i++) + FOR( i = 0; i < gqlevs; i++ ) { /*gain_table[i] = (float) pow (2.0f, q * 0.5f); */ - L_temp = L_shr(L_shr(L_q, 1), sub(29, 16)); - temp_lo_fx = L_Extract_lc(L_temp, &temp_hi_fx); - Qgt = sub(14, temp_hi_fx); - gain_table_fx[i] = extract_l(Pow2(14, temp_lo_fx)); /* Qgt */ + L_temp = L_shr( L_shr( L_q, 1 ), sub( 29, 16 ) ); + temp_lo_fx = L_Extract_lc( L_temp, &temp_hi_fx ); + Qgt = sub( 14, temp_hi_fx ); + gain_table_fx[i] = extract_l( Pow2( 14, temp_lo_fx ) ); /* Qgt */ /*q += delta; */ - L_q = L_add(L_q, L_delta); - gain_table_fx[i] = shl(gain_table_fx[i], sub(14, Qgt)); /* Qgt -> Q14 */ + L_q = L_add( L_q, L_delta ); + gain_table_fx[i] = shl( gain_table_fx[i], sub( 14, Qgt ) ); /* Qgt -> Q14 */ } - FOR (k = sub(bands, Ngq); k < bands; k++) + FOR( k = sub( bands, Ngq ); k < bands; k++ ) { /*Eyy = 0.0f; */ /*Exy = 0.0f; */ @@ -1940,53 +1933,53 @@ static void mdct_spectrum_fine_gain_enc_fx( /* Exy += ybuf[i] * y2[i]; */ /*} */ exp_safe = 4; - move16(); /* 4 is too large. but never happen overflow */ - L_temp = L_deposit_l(0); - FOR (i = band_start[k_sort[k]]; i <= band_end[k_sort[k]]; i++) + move16(); /* 4 is too large. but never happen overflow */ + L_temp = L_deposit_l( 0 ); + FOR( i = band_start[k_sort[k]]; i <= band_end[k_sort[k]]; i++ ) { - L_temp = L_or(L_temp, L_abs(L_y2[i])); - L_temp = L_or(L_temp, L_abs(L_ybuf[i])); + L_temp = L_or( L_temp, L_abs( L_y2[i] ) ); + L_temp = L_or( L_temp, L_abs( L_ybuf[i] ) ); } - exp_norm = norm_l(L_temp); - exp_norm = sub(exp_norm, exp_safe); /* safe_shift */ + exp_norm = norm_l( L_temp ); + exp_norm = sub( exp_norm, exp_safe ); /* safe_shift */ - L_Eyy = L_deposit_l(0); - L_Exy = L_deposit_l(0); + L_Eyy = L_deposit_l( 0 ); + L_Exy = L_deposit_l( 0 ); /*QE = add(shl(add(Qs-16, exp_norm), 1), 1); //(Qs+exp_norm-16)*2+1; */ - FOR (i = band_start[k_sort[k]]; i <= band_end[k_sort[k]]; i++) + FOR( i = band_start[k_sort[k]]; i <= band_end[k_sort[k]]; i++ ) { /*Eyy += y2[i] * y2[i]; */ - temp_fx = round_fx(L_shl(L_y2[i], exp_norm)); - L_Eyy = L_mac(L_Eyy, temp_fx, temp_fx); + temp_fx = round_fx( L_shl( L_y2[i], exp_norm ) ); + L_Eyy = L_mac( L_Eyy, temp_fx, temp_fx ); /*Exy += ybuf[i] * y2[i]; */ - temp2_fx = round_fx(L_shl(L_ybuf[i], exp_norm)); - L_Exy = L_mac(L_Exy, temp2_fx, temp_fx); + temp2_fx = round_fx( L_shl( L_ybuf[i], exp_norm ) ); + L_Exy = L_mac( L_Exy, temp2_fx, temp_fx ); } test(); - IF ( L_Eyy > 0x0L && L_Exy > 0x0L ) + IF( L_Eyy > 0x0L && L_Exy > 0x0L ) { /*gamma = Exy / Eyy; */ - exp_normn = norm_l(L_Exy); - exp_normn = sub(exp_normn, 1); - exp_normd = norm_l(L_Eyy); + exp_normn = norm_l( L_Exy ); + exp_normn = sub( exp_normn, 1 ); + exp_normd = norm_l( L_Eyy ); #ifdef BASOP_NOGLOB - gamma_fx = div_l(L_shl_o(L_Exy, exp_normn, &Overflow), round_fx_o(L_shl_o(L_Eyy, exp_normd, &Overflow), &Overflow)); + gamma_fx = div_l( L_shl_o( L_Exy, exp_normn, &Overflow ), round_fx_o( L_shl_o( L_Eyy, exp_normd, &Overflow ), &Overflow ) ); #else - gamma_fx = div_l(L_shl(L_Exy, exp_normn), round_fx(L_shl(L_Eyy, exp_normd))); + gamma_fx = div_l( L_shl( L_Exy, exp_normn ), round_fx( L_shl( L_Eyy, exp_normd ) ) ); #endif - Qgamma = add(sub(exp_normn, exp_normd), 15); /* exp_normn - (exp_normd-16) - 1; */ - gamma_fx = shl(gamma_fx, sub(14, Qgamma)); /* Qgamma -> Q14 */ + Qgamma = add( sub( exp_normn, exp_normd ), 15 ); /* exp_normn - (exp_normd-16) - 1; */ + gamma_fx = shl( gamma_fx, sub( 14, Qgamma ) ); /* Qgamma -> Q14 */ dmin_fx = 32767; move16(); imin_fx = -1; move16(); - FOR (i = 0; i < gqlevs; i++) + FOR( i = 0; i < gqlevs; i++ ) { - d_fx = abs_s (sub(gamma_fx, gain_table_fx[i])); - IF ( LT_16(d_fx, dmin_fx)) + d_fx = abs_s( sub( gamma_fx, gain_table_fx[i] ) ); + IF( LT_16( d_fx, dmin_fx ) ) { dmin_fx = d_fx; move16(); @@ -1998,17 +1991,17 @@ static void mdct_spectrum_fine_gain_enc_fx( gamma_fx = gain_table_fx[imin_fx]; move16(); /* Q14 */ - FOR (i = band_start[k_sort[k]]; i <= band_end[k_sort[k]]; i++) + FOR( i = band_start[k_sort[k]]; i <= band_end[k_sort[k]]; i++ ) { /*y2[i] *= gamma; */ /* This IF statement for keeping same mantissa evenif y2 is plus or minus */ - IF ( L_y2[i] >= 0x0 ) + IF( L_y2[i] >= 0x0 ) { - L_y2[i] = L_shl(Mpy_32_16_1(L_y2[i], gamma_fx), 1); + L_y2[i] = L_shl( Mpy_32_16_1( L_y2[i], gamma_fx ), 1 ); } ELSE { - L_y2[i] = L_negate(L_shl(Mpy_32_16_1(L_abs(L_y2[i]), gamma_fx), 1)); + L_y2[i] = L_negate( L_shl( Mpy_32_16_1( L_abs( L_y2[i] ), gamma_fx ), 1 ) ); } } } diff --git a/lib_enc/hvq_enc.c b/lib_enc/hvq_enc.c index 3e5b7c65b..5d3ab93bc 100644 --- a/lib_enc/hvq_enc.c +++ b/lib_enc/hvq_enc.c @@ -51,8 +51,8 @@ /*! r: Consumed bits */ int16_t hvq_enc( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const int16_t bwidth, /* i : audio bandwidth */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const int16_t bwidth, /* i : audio bandwidth */ const int32_t core_brate, /* i : core bitrate */ const int16_t hvq_bits, /* i : HVQ bit budget */ const int16_t Npeaks, /* i : Number of peaks */ diff --git a/lib_enc/hvq_enc_fx.c b/lib_enc/hvq_enc_fx.c index 74e0a4cce..107905ccb 100644 --- a/lib_enc/hvq_enc_fx.c +++ b/lib_enc/hvq_enc_fx.c @@ -3,17 +3,17 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ +#include "options.h" /* Compilation switches */ #include "cnst.h" //#include "prot_fx.h" #include "rom_com.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ -#define HVQ_ENC_NOISE_DELTA ((Word16)3277) /* 0.1 in Q15 */ +#define HVQ_ENC_NOISE_DELTA ( (Word16) 3277 ) /* 0.1 in Q15 */ -static Word16 quant_lc(const Word16, Word16 *); +static Word16 quant_lc( const Word16, Word16 * ); /*--------------------------------------------------------------------------* @@ -22,23 +22,23 @@ static Word16 quant_lc(const Word16, Word16 *); * Harmonic VQ encoder *--------------------------------------------------------------------------*/ -Word16 hvq_enc_fx( /*o : Consumed bits */ - Encoder_State *st_fx, /*i/o: encoder state structure */ - const Word32 core_brate, /*i : Total bit rate */ - const Word16 hvq_bits, /*i : HVQ bit budget */ - const Word16 Npeaks, /*i : Number of peaks */ - const Word16 *ynrm, /* i : Envelope coefficients */ - Word16 *R, /* i/o: Bit allocation/updated bit allocation */ - Word16 *peaks, /* i : Peak pos. / Encoded peak pos. */ - Word32 *nf_gains, /* i/o: Noise fill gains / Quant. nf gains */ - Word16 *noise_level, /* o : Quantized noise level */ - const Word32 *pe_gains, /* i : Peak gains */ - const Word32 *coefs, /* i : spectrum coefficients in Q12 */ - Word32 *coefs_out /* o : encoded spectrum coefficients in Q12 */ +Word16 hvq_enc_fx( /*o : Consumed bits */ + Encoder_State *st_fx, /*i/o: encoder state structure */ + const Word32 core_brate, /*i : Total bit rate */ + const Word16 hvq_bits, /*i : HVQ bit budget */ + const Word16 Npeaks, /*i : Number of peaks */ + const Word16 *ynrm, /* i : Envelope coefficients */ + Word16 *R, /* i/o: Bit allocation/updated bit allocation */ + Word16 *peaks, /* i : Peak pos. / Encoded peak pos. */ + Word32 *nf_gains, /* i/o: Noise fill gains / Quant. nf gains */ + Word16 *noise_level, /* o : Quantized noise level */ + const Word32 *pe_gains, /* i : Peak gains */ + const Word32 *coefs, /* i : spectrum coefficients in Q12 */ + Word32 *coefs_out /* o : encoded spectrum coefficients in Q12 */ ) { const Word32 *pCoefs; - Word16 bin_th,j,i,n; + Word16 bin_th, j, i, n; Word16 nf_cnt; Word16 q_noise_level_idx[HVQ_BWE_NOISE_BANDS]; Word16 q_noise_level[HVQ_BWE_NOISE_BANDS]; @@ -53,27 +53,29 @@ Word16 hvq_enc_fx( /*o : Consumed bits Word16 tmp16, adjust; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; -#endif +#endif bits_used = 0; move16(); - IF ( LT_32(core_brate, HQ_BWE_CROSSOVER_BRATE)) + IF( LT_32( core_brate, HQ_BWE_CROSSOVER_BRATE ) ) { bin_th = HVQ_THRES_BIN_24k; move16(); - n = (L_FRAME32k - HVQ_THRES_BIN_24k)/HVQ_BWE_NOISE_BANDS; + n = ( L_FRAME32k - HVQ_THRES_BIN_24k ) / HVQ_BWE_NOISE_BANDS; move16(); } ELSE { bin_th = HVQ_THRES_BIN_32k; move16(); - n = (L_FRAME32k - HVQ_THRES_BIN_32k)/HVQ_BWE_NOISE_BANDS; + n = ( L_FRAME32k - HVQ_THRES_BIN_32k ) / HVQ_BWE_NOISE_BANDS; move16(); } - nf = 800*4096L; /* Q12 */ move32(); - pe = 800*4096L; /* Q12 */ move32(); + nf = 800 * 4096L; /* Q12 */ + move32(); + pe = 800 * 4096L; /* Q12 */ + move32(); pCoefs = &coefs[bin_th]; /* Find HB noise level */ @@ -81,78 +83,78 @@ Word16 hvq_enc_fx( /*o : Consumed bits { nf_cnt = 0; move16(); - nf_mean = L_deposit_l(0); - pe_mean = L_deposit_l(0); - FOR( j = 0; j < n; j++) + nf_mean = L_deposit_l( 0 ); + pe_mean = L_deposit_l( 0 ); + FOR( j = 0; j < n; j++ ) { - d = L_abs(*pCoefs++); /* Q12 */ + d = L_abs( *pCoefs++ ); /* Q12 */ - IF( GT_32(d, pe)) + IF( GT_32( d, pe ) ) { /* W*pe + (1 - W)*d = (pe - d)*W + d */ - acc = L_sub(pe, d); - Mpy_32_16_ss(acc, HVQ_BWE_WEIGHT2_FX, &acc, &dontCare); - pe = L_add(acc, d); /* in Q12 and always positive */ + acc = L_sub( pe, d ); + Mpy_32_16_ss( acc, HVQ_BWE_WEIGHT2_FX, &acc, &dontCare ); + pe = L_add( acc, d ); /* in Q12 and always positive */ } ELSE { /* W*pe + (1 - W)*d = (pe - d)*W + d */ - acc = L_sub(pe, d); - Mpy_32_16_ss(acc, HVQ_BWE_WEIGHT1_FX, &acc, &dontCare); - pe = L_add(acc, d); /* in Q12 and always positive */ + acc = L_sub( pe, d ); + Mpy_32_16_ss( acc, HVQ_BWE_WEIGHT1_FX, &acc, &dontCare ); + pe = L_add( acc, d ); /* in Q12 and always positive */ - IF( GT_32(d, nf)) + IF( GT_32( d, nf ) ) { - acc = L_sub(nf, d); - Mpy_32_16_ss(acc, HVQ_BWE_WEIGHT1_FX, &acc, &dontCare); - nf = L_add(acc, d); /* in Q12 and always positive */ + acc = L_sub( nf, d ); + Mpy_32_16_ss( acc, HVQ_BWE_WEIGHT1_FX, &acc, &dontCare ); + nf = L_add( acc, d ); /* in Q12 and always positive */ } ELSE { - acc = L_sub(nf, d); - Mpy_32_16_ss(acc, HVQ_BWE_WEIGHT2_FX, &acc, &dontCare); - nf = L_add(acc, d); /* in Q12 always positive */ + acc = L_sub( nf, d ); + Mpy_32_16_ss( acc, HVQ_BWE_WEIGHT2_FX, &acc, &dontCare ); + nf = L_add( acc, d ); /* in Q12 always positive */ } - nf_mean = L_add(nf_mean, nf); /* in Q12 and always positive */ - nf_cnt = add(nf_cnt, 1); /* Q0 */ + nf_mean = L_add( nf_mean, nf ); /* in Q12 and always positive */ + nf_cnt = add( nf_cnt, 1 ); /* Q0 */ } #ifdef BASOP_NOGLOB - pe_mean = L_add_o(pe_mean, pe, &Overflow); /* in Q12 and always positive */ + pe_mean = L_add_o( pe_mean, pe, &Overflow ); /* in Q12 and always positive */ #else - pe_mean = L_add(pe_mean, pe); /* in Q12 and always positive */ + pe_mean = L_add( pe_mean, pe ); /* in Q12 and always positive */ #endif } - IF (pe_mean > 0) + IF( pe_mean > 0 ) { - expPeMean = norm_l(pe_mean); /* exponent */ - manPeMean = extract_h(L_shl(pe_mean, expPeMean)); /* mantissa */ - expNfMean = norm_l(nf_mean); /* exponent */ - manNfMean = extract_h(L_shl(nf_mean, expNfMean)); /* mantissa */ + expPeMean = norm_l( pe_mean ); /* exponent */ + manPeMean = extract_h( L_shl( pe_mean, expPeMean ) ); /* mantissa */ + expNfMean = norm_l( nf_mean ); /* exponent */ + manNfMean = extract_h( L_shl( nf_mean, expNfMean ) ); /* mantissa */ - numerator = L_mult0(manNfMean, n); - IF ( nf_cnt > 0 ) + numerator = L_mult0( manNfMean, n ); + IF( nf_cnt > 0 ) { - denominator = L_mult0(manPeMean, nf_cnt); /* in Q15 */ + denominator = L_mult0( manPeMean, nf_cnt ); /* in Q15 */ } ELSE { - denominator = L_mult0(manPeMean, 1); /* in Q15 */ + denominator = L_mult0( manPeMean, 1 ); /* in Q15 */ } - manNfpe = ratio(numerator, denominator, &expo); /* manNfpe in Q14 */ - expNfpe = add(sub(expNfMean, expPeMean), expo); + manNfpe = ratio( numerator, denominator, &expo ); /* manNfpe in Q14 */ + expNfpe = add( sub( expNfMean, expPeMean ), expo ); - tmp16 = mult_r(manNfpe, manNfpe); /* in Q(14+14+1-16) = Q13 */ - tmp16 = mult_r(tmp16, manNfpe); /* in Q(13+14+1-16) = Q12 */ - acc = L_mult(tmp16, HVQ_NFPE_FACTOR_CUBE_FX); /* in Q(12+6+1) = Q19 */ - expNfpe3 = extract_l(L_mult0(expNfpe, 3)); /* Cube operation */ + tmp16 = mult_r( manNfpe, manNfpe ); /* in Q(14+14+1-16) = Q13 */ + tmp16 = mult_r( tmp16, manNfpe ); /* in Q(13+14+1-16) = Q12 */ + acc = L_mult( tmp16, HVQ_NFPE_FACTOR_CUBE_FX ); /* in Q(12+6+1) = Q19 */ + expNfpe3 = extract_l( L_mult0( expNfpe, 3 ) ); /* Cube operation */ /* Number of bits required to adjust to Q15 */ - adjust = add(19 - (15 + 16), expNfpe3); /* +16 is due to the following extract_h(). */ + adjust = add( 19 - ( 15 + 16 ), expNfpe3 ); /* +16 is due to the following extract_h(). */ #ifdef BASOP_NOGLOB - noise_level[i] = extract_h(L_shr_o(acc, adjust, &Overflow)); /* noise_level[] in Q15 */ + noise_level[i] = extract_h( L_shr_o( acc, adjust, &Overflow ) ); /* noise_level[] in Q15 */ #else - noise_level[i] = extract_h(L_shr(acc, adjust)); /* noise_level[] in Q15 */ + noise_level[i] = extract_h( L_shr( acc, adjust ) ); /* noise_level[] in Q15 */ #endif q_noise_level_idx[i] = quant_lc( noise_level[i], &q_noise_level[i] ); } @@ -163,28 +165,28 @@ Word16 hvq_enc_fx( /*o : Consumed bits q_noise_level[i] = 0; move16(); } - push_indice_fx(st_fx->hBstr, IND_HVQ_BWE_NL, q_noise_level_idx[i], 2 ); - bits_used = add(bits_used, 2); + push_indice_fx( st_fx->hBstr, IND_HVQ_BWE_NL, q_noise_level_idx[i], 2 ); + bits_used = add( bits_used, 2 ); - noise_level[i] = q_noise_level[i]; /* in Q15 */ + noise_level[i] = q_noise_level[i]; /* in Q15 */ } - FOR( i = 0; i < HVQ_NF_GROUPS; i ++ ) + FOR( i = 0; i < HVQ_NF_GROUPS; i++ ) { - IF (pe_gains[i] != 0) + IF( pe_gains[i] != 0 ) { /* Neither pe_gains[] nor nf_gains[] is zero. */ - man = ratio(nf_gains[i], pe_gains[i], &expo); /* man in Q14 */ - tmp16 = mult_r(man, man); /* in Q(14+14+1-16) = Q13 */ - tmp16 = mult_r(tmp16, man); /* in Q(13+14+1-16) = Q12 */ - acc = L_mult(tmp16, HVQ_LB_NFPE_FACTOR_CUBE_FX); /* in Q(12+9+1) = Q22 */ - expo3 = extract_l(L_mult0(expo, 3)); /* Cube operation. */ + man = ratio( nf_gains[i], pe_gains[i], &expo ); /* man in Q14 */ + tmp16 = mult_r( man, man ); /* in Q(14+14+1-16) = Q13 */ + tmp16 = mult_r( tmp16, man ); /* in Q(13+14+1-16) = Q12 */ + acc = L_mult( tmp16, HVQ_LB_NFPE_FACTOR_CUBE_FX ); /* in Q(12+9+1) = Q22 */ + expo3 = extract_l( L_mult0( expo, 3 ) ); /* Cube operation. */ /* Number of bits required to adjust to Q15 */ - adjust = add(22 - (15 + 16), expo3); /* +16 is due to the following extract_h(). */ + adjust = add( 22 - ( 15 + 16 ), expo3 ); /* +16 is due to the following extract_h(). */ #ifdef BASOP_NOGLOB - lb_nfpe = extract_h(L_shr_o(acc, adjust, &Overflow)); /* noise_level[] in Q15 */ + lb_nfpe = extract_h( L_shr_o( acc, adjust, &Overflow ) ); /* noise_level[] in Q15 */ #else - lb_nfpe = extract_h(L_shr(acc, adjust)); /* noise_level[] in Q15 */ + lb_nfpe = extract_h( L_shr( acc, adjust ) ); /* noise_level[] in Q15 */ #endif IF( lb_nfpe > 16384 ) /* in Q15 */ { @@ -192,9 +194,9 @@ Word16 hvq_enc_fx( /*o : Consumed bits move16(); } #ifdef BASOP_NOGLOB - Mpy_32_16_ss(nf_gains[i], shl_o(lb_nfpe, 1, &Overflow), &nf_gains[i], &dontCare); /* nf_gains[] in Q12 */ + Mpy_32_16_ss( nf_gains[i], shl_o( lb_nfpe, 1, &Overflow ), &nf_gains[i], &dontCare ); /* nf_gains[] in Q12 */ #else - Mpy_32_16_ss(nf_gains[i], shl(lb_nfpe, 1), &nf_gains[i], &dontCare); /* nf_gains[] in Q12 */ + Mpy_32_16_ss( nf_gains[i], shl( lb_nfpe, 1 ), &nf_gains[i], &dontCare ); /* nf_gains[] in Q12 */ #endif } ELSE @@ -203,9 +205,9 @@ Word16 hvq_enc_fx( /*o : Consumed bits move16(); } } - nBits = peak_vq_enc_fx( st_fx->hBstr, st_fx->bwidth, coefs, coefs_out, core_brate, sub(hvq_bits, bits_used), + nBits = peak_vq_enc_fx( st_fx->hBstr, st_fx->bwidth, coefs, coefs_out, core_brate, sub( hvq_bits, bits_used ), Npeaks, ynrm, R, peaks, &nf_gains[0] ); - bits_used = add(bits_used, nBits); + bits_used = add( bits_used, nBits ); return bits_used; } @@ -214,39 +216,38 @@ Word16 hvq_enc_fx( /*o : Consumed bits * * Quantize the noise to one of the levels in {0, 0.1, 0.2, 0.3} *----------------------------------------------------------------------------*/ -static Word16 quant_lc(const Word16 x, Word16 *qx) +static Word16 quant_lc( const Word16 x, Word16 *qx ) { Word16 indx; - IF (LT_16(x, HVQ_ENC_NOISE_DELTA/2)) + IF( LT_16( x, HVQ_ENC_NOISE_DELTA / 2 ) ) { indx = 0; move16(); *qx = 0; move16(); } - ELSE IF (LT_16(x, 3*HVQ_ENC_NOISE_DELTA/2)) + ELSE IF( LT_16( x, 3 * HVQ_ENC_NOISE_DELTA / 2 ) ) { indx = 1; move16(); *qx = HVQ_ENC_NOISE_DELTA; move16(); } - ELSE IF (LT_16(x, 5*HVQ_ENC_NOISE_DELTA/2)) + ELSE IF( LT_16( x, 5 * HVQ_ENC_NOISE_DELTA / 2 ) ) { indx = 2; move16(); - *qx = 2*HVQ_ENC_NOISE_DELTA; + *qx = 2 * HVQ_ENC_NOISE_DELTA; move16(); } ELSE { indx = 3; move16(); - *qx = 3*HVQ_ENC_NOISE_DELTA; + *qx = 3 * HVQ_ENC_NOISE_DELTA; move16(); } return indx; } - diff --git a/lib_enc/igf_enc.c b/lib_enc/igf_enc.c index 0ef46f380..230df0248 100644 --- a/lib_enc/igf_enc.c +++ b/lib_enc/igf_enc.c @@ -1670,7 +1670,7 @@ void IGFEncSetMode( set_f( hPrivateData->SFM_sb, 0.f, IGF_MAX_SFB ); set_f( hPrivateData->SFM_tb, 0.f, IGF_MAX_SFB ); - if (IGFCommonFuncsIGFConfiguration_flt( total_brate, bwidth, element_mode, &hPrivateData->igfInfo, rf_mode ) ) + if ( IGFCommonFuncsIGFConfiguration_flt( total_brate, bwidth, element_mode, &hPrivateData->igfInfo, rf_mode ) ) { IGFSCFEncoderOpen( &hPrivateData->hIGFSCFArithEnc, &hPrivateData->igfInfo, total_brate, bwidth, element_mode, rf_mode ); diff --git a/lib_enc/igf_enc_fx.c b/lib_enc/igf_enc_fx.c index 109f85ff0..1841bd93a 100644 --- a/lib_enc/igf_enc_fx.c +++ b/lib_enc/igf_enc_fx.c @@ -9,9 +9,9 @@ #include "cnst.h" #include "stl.h" //#include "prot_fx.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ #include "stat_enc.h" #include "basop_util.h" @@ -19,38 +19,37 @@ write single bit to stream **************************************************************************/ static void IGF_write_bit( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - Word16 *bitCount, /**< in/out: | bit counter */ - Word16 bit /**< in: | value of bit */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 *bitCount, /**< in/out: | bit counter */ + Word16 bit /**< in: | value of bit */ ) { - IGFCommonFuncsWriteSerialBit(hBstr, bitCount, bit); - + IGFCommonFuncsWriteSerialBit( hBstr, bitCount, bit ); } /**********************************************************************/ /* write bits to stream **************************************************************************/ static void IGF_write_bits( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - Word16 *bitCount, /**< in/out: | bit counter */ - Word16 value, /**< in: | value to be written */ - Word16 bits /**< in: Q0 | number of bits */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 *bitCount, /**< in/out: | bit counter */ + Word16 value, /**< in: | value to be written */ + Word16 bits /**< in: Q0 | number of bits */ ) { Word16 tmp; - WHILE (bits) + WHILE( bits ) { - bits = sub(bits, 1); - tmp = s_and(value, shl(1, bits)); - IF (tmp == 0) + bits = sub( bits, 1 ); + tmp = s_and( value, shl( 1, bits ) ); + IF( tmp == 0 ) { - IGF_write_bit(hBstr, bitCount, 0); + IGF_write_bit( hBstr, bitCount, 0 ); } ELSE { - IGF_write_bit(hBstr, bitCount, 1); + IGF_write_bit( hBstr, bitCount, 1 ); } } @@ -58,241 +57,237 @@ static void IGF_write_bits( } -/**********************************************************************/ /* -envelope estimation -**************************************************************************/ -static void IGF_CalculateEnvelope(const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ - Word32 *pMDCTSpectrum, /**< in: Q31 | MDCT spectrum */ - Word16 MDCTSpectrum_e, /**< in: | exponent of MDCT spectrum */ - Word32 *pPowerSpectrum, /**< in: Q31 | MDCT^2 + MDST^2 spectrum, or estimate */ - Word16 PowerSpectrum_e, /**< in: | exponent of MDCT^2 + MDST^2 spectrum, or estimate */ - const Word16 igfGridIdx /**< in: Q0 | IGF grid index */ - - ) +/**********************************************************************/ /* + envelope estimation + **************************************************************************/ +static void IGF_CalculateEnvelope( const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ + Word32 *pMDCTSpectrum, /**< in: Q31 | MDCT spectrum */ + Word16 MDCTSpectrum_e, /**< in: | exponent of MDCT spectrum */ + Word32 *pPowerSpectrum, /**< in: Q31 | MDCT^2 + MDST^2 spectrum, or estimate */ + Word16 PowerSpectrum_e, /**< in: | exponent of MDCT^2 + MDST^2 spectrum, or estimate */ + const Word16 igfGridIdx /**< in: Q0 | IGF grid index */ + +) { IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; H_IGF_GRID hGrid; - Word16 *swb_offset; - Word16 sfb; /* this is the actual scalefactor band */ - Word16 width; /* this is width in subbands of the actual scalefactor band */ - Word16 tile_idx; - Word16 strt_cpy; - Word16 gain; /* the gain which has to be applied to the source tile to get the destination energy */ - Word16 gain_exp; - Word16 tb; - Word16 zeroNrg; /* Q0 | flag indicating if the signal contains almost no energy */ - Word32 sfbEnergyR[IGF_MAX_SFB]; - Word16 sfbEnergyR_exp[IGF_MAX_SFB]; - Word32 sfbEnergyC[IGF_MAX_SFB]; /* the energy of the destination region of the tile */ - Word16 sfbEnergyC_exp[IGF_MAX_SFB]; - Word32 sfbEnergyTileR[IGF_MAX_SFB]; - Word16 sfbEnergyTileR_exp[IGF_MAX_SFB]; - Word32 sfbEnergyTileC[IGF_MAX_SFB]; /* the energy of the destination region of the tile */ - Word16 sfbEnergyTileC_exp[IGF_MAX_SFB]; - Word32 LFMDCTSpectrum[N_MAX]; - Word16 LFMDCTSpectrum_exp; - Word32 LFPowerSpectrum[N_MAX]; - Word16 tmp; - Word16 tmp_exp; - Word32 L_tmp; - Word16 shift; + Word16 *swb_offset; + Word16 sfb; /* this is the actual scalefactor band */ + Word16 width; /* this is width in subbands of the actual scalefactor band */ + Word16 tile_idx; + Word16 strt_cpy; + Word16 gain; /* the gain which has to be applied to the source tile to get the destination energy */ + Word16 gain_exp; + Word16 tb; + Word16 zeroNrg; /* Q0 | flag indicating if the signal contains almost no energy */ + Word32 sfbEnergyR[IGF_MAX_SFB]; + Word16 sfbEnergyR_exp[IGF_MAX_SFB]; + Word32 sfbEnergyC[IGF_MAX_SFB]; /* the energy of the destination region of the tile */ + Word16 sfbEnergyC_exp[IGF_MAX_SFB]; + Word32 sfbEnergyTileR[IGF_MAX_SFB]; + Word16 sfbEnergyTileR_exp[IGF_MAX_SFB]; + Word32 sfbEnergyTileC[IGF_MAX_SFB]; /* the energy of the destination region of the tile */ + Word16 sfbEnergyTileC_exp[IGF_MAX_SFB]; + Word32 LFMDCTSpectrum[N_MAX]; + Word16 LFMDCTSpectrum_exp; + Word32 LFPowerSpectrum[N_MAX]; + Word16 tmp; + Word16 tmp_exp; + Word32 L_tmp; + Word16 shift; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; -#endif +#endif /* initialize variables */ - Copy32(pMDCTSpectrum + IGF_START_MN, hInstance->spec_be_igf, hInstance->infoStopLine-IGF_START_MN); - hPrivateData = &hInstance->igfData; - hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; - swb_offset = hGrid->swb_offset; + Copy32( pMDCTSpectrum + IGF_START_MN, hInstance->spec_be_igf, hInstance->infoStopLine - IGF_START_MN ); + hPrivateData = &hInstance->igfData; + hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; + swb_offset = hGrid->swb_offset; move16(); hInstance->spec_be_igf_e = MDCTSpectrum_e; move16(); - zeroNrg = 0; + zeroNrg = 0; move16(); - IF (pPowerSpectrum != NULL) + IF( pPowerSpectrum != NULL ) { - FOR (tile_idx = 0; tile_idx < hGrid->nTiles; tile_idx++) + FOR( tile_idx = 0; tile_idx < hGrid->nTiles; tile_idx++ ) { strt_cpy = hGrid->sbWrap[tile_idx]; move16(); - FOR (sfb = hGrid->sfbWrap[tile_idx]; sfb < hGrid->sfbWrap[tile_idx + 1]; sfb++) + FOR( sfb = hGrid->sfbWrap[tile_idx]; sfb < hGrid->sfbWrap[tile_idx + 1]; sfb++ ) { - FOR (tb = swb_offset[ sfb ]; tb < swb_offset[ sfb+1 ]; tb++) + FOR( tb = swb_offset[sfb]; tb < swb_offset[sfb + 1]; tb++ ) { - LFMDCTSpectrum[tb] = pMDCTSpectrum[strt_cpy]; + LFMDCTSpectrum[tb] = pMDCTSpectrum[strt_cpy]; move32(); LFPowerSpectrum[tb] = pPowerSpectrum[strt_cpy]; move32(); - strt_cpy = add(strt_cpy, 1); + strt_cpy = add( strt_cpy, 1 ); } } } - IGFCommonFuncsCalcSfbEnergyPowerSpec(hGrid->startSfb, - hGrid->stopSfb, - hGrid->swb_offset, - pPowerSpectrum, - &PowerSpectrum_e, - sfbEnergyC, - sfbEnergyC_exp); - IGFCommonFuncsCalcSfbEnergyPowerSpec(hGrid->startSfb, - hGrid->stopSfb, - hGrid->swb_offset, - LFPowerSpectrum, - &PowerSpectrum_e, - sfbEnergyTileC, - sfbEnergyTileC_exp); - IGFCommonFuncsMDCTSquareSpec(hGrid->startLine, - hGrid->stopLine, - LFMDCTSpectrum, - MDCTSpectrum_e, - LFMDCTSpectrum, - &LFMDCTSpectrum_exp, - 0); - IGFCommonFuncsCalcSfbEnergyPowerSpec(hGrid->startSfb, - hGrid->stopSfb, - hGrid->swb_offset, - LFMDCTSpectrum, - &LFMDCTSpectrum_exp, - sfbEnergyTileR, - sfbEnergyTileR_exp); + IGFCommonFuncsCalcSfbEnergyPowerSpec( hGrid->startSfb, + hGrid->stopSfb, + hGrid->swb_offset, + pPowerSpectrum, + &PowerSpectrum_e, + sfbEnergyC, + sfbEnergyC_exp ); + IGFCommonFuncsCalcSfbEnergyPowerSpec( hGrid->startSfb, + hGrid->stopSfb, + hGrid->swb_offset, + LFPowerSpectrum, + &PowerSpectrum_e, + sfbEnergyTileC, + sfbEnergyTileC_exp ); + IGFCommonFuncsMDCTSquareSpec( hGrid->startLine, + hGrid->stopLine, + LFMDCTSpectrum, + MDCTSpectrum_e, + LFMDCTSpectrum, + &LFMDCTSpectrum_exp, + 0 ); + IGFCommonFuncsCalcSfbEnergyPowerSpec( hGrid->startSfb, + hGrid->stopSfb, + hGrid->swb_offset, + LFMDCTSpectrum, + &LFMDCTSpectrum_exp, + sfbEnergyTileR, + sfbEnergyTileR_exp ); } ELSE { - IGFCommonFuncsMDCTSquareSpec(hGrid->startLine, - hGrid->stopLine, - pMDCTSpectrum, - MDCTSpectrum_e, - LFMDCTSpectrum, - &LFMDCTSpectrum_exp, - 0); - IGFCommonFuncsCalcSfbEnergyPowerSpec(hGrid->startSfb, - hGrid->stopSfb, - hGrid->swb_offset, - LFMDCTSpectrum, - &LFMDCTSpectrum_exp, - sfbEnergyR, - sfbEnergyR_exp); + IGFCommonFuncsMDCTSquareSpec( hGrid->startLine, + hGrid->stopLine, + pMDCTSpectrum, + MDCTSpectrum_e, + LFMDCTSpectrum, + &LFMDCTSpectrum_exp, + 0 ); + IGFCommonFuncsCalcSfbEnergyPowerSpec( hGrid->startSfb, + hGrid->stopSfb, + hGrid->swb_offset, + LFMDCTSpectrum, + &LFMDCTSpectrum_exp, + sfbEnergyR, + sfbEnergyR_exp ); } - FOR (tile_idx = 0; tile_idx < hGrid->nTiles; tile_idx++) + FOR( tile_idx = 0; tile_idx < hGrid->nTiles; tile_idx++ ) { - FOR(sfb = hGrid->sfbWrap[tile_idx]; sfb < hGrid->sfbWrap[tile_idx + 1]; sfb++) + FOR( sfb = hGrid->sfbWrap[tile_idx]; sfb < hGrid->sfbWrap[tile_idx + 1]; sfb++ ) { - width = sub(swb_offset[sfb + 1], swb_offset[sfb]); - L_tmp = 0; + width = sub( swb_offset[sfb + 1], swb_offset[sfb] ); + L_tmp = 0; move16(); gain_exp = 0; move16(); - IF (pPowerSpectrum) + IF( pPowerSpectrum ) { - IF (sfbEnergyTileR[sfb] == 0) + IF( sfbEnergyTileR[sfb] == 0 ) { - sfbEnergyTileR[sfb] = 0x00010000; + sfbEnergyTileR[sfb] = 0x00010000; move32(); - sfbEnergyTileR_exp[sfb] = 0; + sfbEnergyTileR_exp[sfb] = 0; move16(); - zeroNrg = 1; + zeroNrg = 1; move16(); } - IF (sfbEnergyTileC[sfb] == 0) + IF( sfbEnergyTileC[sfb] == 0 ) { - sfbEnergyTileC[sfb] = 0x00010000; + sfbEnergyTileC[sfb] = 0x00010000; move32(); - sfbEnergyTileC_exp[sfb] = 0; + sfbEnergyTileC_exp[sfb] = 0; move16(); - zeroNrg = 1; + zeroNrg = 1; move16(); } - IF (sfbEnergyC[sfb] == 0) + IF( sfbEnergyC[sfb] == 0 ) { - sfbEnergyC[sfb] = 0x00010000; + sfbEnergyC[sfb] = 0x00010000; move32(); - sfbEnergyC_exp[sfb] = 0; + sfbEnergyC_exp[sfb] = 0; move16(); - zeroNrg = 1; + zeroNrg = 1; move16(); } #ifdef BASOP_NOGLOB - BASOP_Util_Divide_MantExp(round_fx_o(sfbEnergyTileR[sfb], &Overflow),sfbEnergyTileR_exp[sfb], width, 15, &gain, &gain_exp); - BASOP_Util_Divide_MantExp(round_fx_o(sfbEnergyC[sfb], &Overflow), sfbEnergyC_exp[sfb], round_fx_o(sfbEnergyTileC[sfb], &Overflow), sfbEnergyTileC_exp[sfb], &tmp, &tmp_exp); + BASOP_Util_Divide_MantExp( round_fx_o( sfbEnergyTileR[sfb], &Overflow ), sfbEnergyTileR_exp[sfb], width, 15, &gain, &gain_exp ); + BASOP_Util_Divide_MantExp( round_fx_o( sfbEnergyC[sfb], &Overflow ), sfbEnergyC_exp[sfb], round_fx_o( sfbEnergyTileC[sfb], &Overflow ), sfbEnergyTileC_exp[sfb], &tmp, &tmp_exp ); #else - BASOP_Util_Divide_MantExp(round_fx(sfbEnergyTileR[sfb]), - sfbEnergyTileR_exp[sfb], - width, - 15, - &gain, - &gain_exp); - BASOP_Util_Divide_MantExp(round_fx(sfbEnergyC[sfb]), - sfbEnergyC_exp[sfb], - round_fx(sfbEnergyTileC[sfb]), - sfbEnergyTileC_exp[sfb], - &tmp, - &tmp_exp); + BASOP_Util_Divide_MantExp( round_fx( sfbEnergyTileR[sfb] ), + sfbEnergyTileR_exp[sfb], + width, + 15, + &gain, + &gain_exp ); + BASOP_Util_Divide_MantExp( round_fx( sfbEnergyC[sfb] ), + sfbEnergyC_exp[sfb], + round_fx( sfbEnergyTileC[sfb] ), + sfbEnergyTileC_exp[sfb], + &tmp, + &tmp_exp ); #endif - L_tmp = L_mult(gain, tmp); - gain_exp = add(gain_exp, tmp_exp); - - + L_tmp = L_mult( gain, tmp ); + gain_exp = add( gain_exp, tmp_exp ); } ELSE { - IF(sfbEnergyR[sfb] == 0) + IF( sfbEnergyR[sfb] == 0 ) { - sfbEnergyR[sfb] = 0x00010000; + sfbEnergyR[sfb] = 0x00010000; move32(); - sfbEnergyR_exp[sfb] = 0; + sfbEnergyR_exp[sfb] = 0; move16(); - zeroNrg = 1; + zeroNrg = 1; move16(); } #ifdef BASOP_NOGLOB BASOP_Util_Divide_MantExp( round_fx_sat( sfbEnergyR[sfb] ), #else - BASOP_Util_Divide_MantExp(round_fx(sfbEnergyR[sfb]), + BASOP_Util_Divide_MantExp( round_fx( sfbEnergyR[sfb] ), #endif - sfbEnergyR_exp[sfb], - width, - 15, - &gain, - &gain_exp); - L_tmp = L_deposit_h(gain); - - + sfbEnergyR_exp[sfb], + width, + 15, + &gain, + &gain_exp ); + L_tmp = L_deposit_h( gain ); } /* gain = 0.5f + (float)((2.885390081777927f * log(gain) + 16.f)); */ - L_tmp = BASOP_Util_Log2(L_tmp); - L_tmp = L_add(L_tmp, L_deposit_h(shl(gain_exp, 15-6))); - shift = norm_l(L_tmp); + L_tmp = BASOP_Util_Log2( L_tmp ); + L_tmp = L_add( L_tmp, L_deposit_h( shl( gain_exp, 15 - 6 ) ) ); + shift = norm_l( L_tmp ); #ifdef BASOP_NOGLOB - gain = round_fx_o(L_shl_o(L_tmp, shift, &Overflow), &Overflow); + gain = round_fx_o( L_shl_o( L_tmp, shift, &Overflow ), &Overflow ); #else - gain = round_fx(L_shl(L_tmp, shift)); + gain = round_fx( L_shl( L_tmp, shift ) ); #endif - gain_exp = sub(7, shift); - gain_exp = BASOP_Util_Add_MantExp(gain, gain_exp, 32767/*16 Q11*/, 4, &gain); - gain_exp = BASOP_Util_Add_MantExp(gain, gain_exp, 0x4000, 0, &gain); - gain = shr(gain, s_min(sub(15, gain_exp), 15)); + gain_exp = sub( 7, shift ); + gain_exp = BASOP_Util_Add_MantExp( gain, gain_exp, 32767 /*16 Q11*/, 4, &gain ); + gain_exp = BASOP_Util_Add_MantExp( gain, gain_exp, 0x4000, 0, &gain ); + gain = shr( gain, s_min( sub( 15, gain_exp ), 15 ) ); - if (gain > 91) + if ( gain > 91 ) { - gain = s_min(gain, 91); /* 13+15+63, see arithocde encode residual */ + gain = s_min( gain, 91 ); /* 13+15+63, see arithocde encode residual */ } - if (gain < 0) + if ( gain < 0 ) { - gain = s_max(gain, 0); + gain = s_max( gain, 0 ); } /* set gain to zero if the signal contains too less energy */ - if (zeroNrg != 0) + if ( zeroNrg != 0 ) { gain = 0; move16(); @@ -309,27 +304,27 @@ static void IGF_CalculateEnvelope(const IGF_ENC_INSTANCE_HANDLE hInstanc /**********************************************************************/ /* writes IGF SCF values **************************************************************************/ -static void IGF_WriteEnvelope( /**< out: Q0 | number of bits writen */ - const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - Word16 *pBitOffset, /**< in: | ptr to bitOffset counter */ - const Word16 igfGridIdx, /**< in: Q0 | igf grid index see declaration of IGF_GRID_IDX for details */ - const Word16 isIndepFlag, /**< in: Q0 | if 1 frame is independent, 0 = frame is coded with data from previous frame */ - Word16 *igfAllZero /**< in: Q0 | returns 1 if all IGF scfs are zero, else 0 */ +static void IGF_WriteEnvelope( /**< out: Q0 | number of bits writen */ + const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 *pBitOffset, /**< in: | ptr to bitOffset counter */ + const Word16 igfGridIdx, /**< in: Q0 | igf grid index see declaration of IGF_GRID_IDX for details */ + const Word16 isIndepFlag, /**< in: Q0 | if 1 frame is independent, 0 = frame is coded with data from previous frame */ + Word16 *igfAllZero /**< in: Q0 | returns 1 if all IGF scfs are zero, else 0 */ ) { IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; H_IGF_GRID hGrid; Word16 sfb; - *igfAllZero = 1; + *igfAllZero = 1; move16(); - hPrivateData = &hInstance->igfData; - hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; + hPrivateData = &hInstance->igfData; + hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; - FOR (sfb = hGrid->startSfb; sfb < hGrid->stopSfb; sfb++) + FOR( sfb = hGrid->startSfb; sfb < hGrid->stopSfb; sfb++ ) { - IF (hPrivateData->igfScfQuantized[sfb] != 0) + IF( hPrivateData->igfScfQuantized[sfb] != 0 ) { *igfAllZero = 0; move16(); @@ -337,55 +332,54 @@ static void IGF_WriteEnvelope( } } - IF (*igfAllZero != 0) + IF( *igfAllZero != 0 ) { - IGF_write_bit(hBstr, pBitOffset, 1); - IF (NULL == hBstr) + IGF_write_bit( hBstr, pBitOffset, 1 ); + IF( NULL == hBstr ) { - IGFSCFEncoderSaveContextState_fx(&hPrivateData->hIGFSCFArithEnc, igfGridIdx); + IGFSCFEncoderSaveContextState_fx( &hPrivateData->hIGFSCFArithEnc, igfGridIdx ); } - IGFSCFEncoderReset_fx(&hPrivateData->hIGFSCFArithEnc); - IF (NULL == hBstr) + IGFSCFEncoderReset_fx( &hPrivateData->hIGFSCFArithEnc ); + IF( NULL == hBstr ) { - IGFSCFEncoderRestoreContextState_fx(&hPrivateData->hIGFSCFArithEnc, igfGridIdx); + IGFSCFEncoderRestoreContextState_fx( &hPrivateData->hIGFSCFArithEnc, igfGridIdx ); } } ELSE { - IGF_write_bit(hBstr, pBitOffset, 0); - IF (NULL == hBstr) + IGF_write_bit( hBstr, pBitOffset, 0 ); + IF( NULL == hBstr ) { - IGFSCFEncoderSaveContextState_fx(&hPrivateData->hIGFSCFArithEnc, igfGridIdx); + IGFSCFEncoderSaveContextState_fx( &hPrivateData->hIGFSCFArithEnc, igfGridIdx ); } - *pBitOffset = IGFSCFEncoderEncode_fx(&hPrivateData->hIGFSCFArithEnc, hBstr, *pBitOffset, &hPrivateData->igfScfQuantized[hGrid->startSfb], igfGridIdx, isIndepFlag); + *pBitOffset = IGFSCFEncoderEncode_fx( &hPrivateData->hIGFSCFArithEnc, hBstr, *pBitOffset, &hPrivateData->igfScfQuantized[hGrid->startSfb], igfGridIdx, isIndepFlag ); move16(); - IF (NULL == hBstr) + IF( NULL == hBstr ) { - IGFSCFEncoderRestoreContextState_fx(&hPrivateData->hIGFSCFArithEnc, igfGridIdx); + IGFSCFEncoderRestoreContextState_fx( &hPrivateData->hIGFSCFArithEnc, igfGridIdx ); } } - } /**********************************************************************/ /* identifies significant spectral content **************************************************************************/ -static void IGF_ErodeSpectrum(Word16 *highPassEner_exp, /**< out: | exponent of highPassEner */ - const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ - Word32 *pSpectrum, /**< in/out: | MDCT spectrum */ - Word32 *pPowerSpectrum, /**< in/out: | power spectrum */ - Word16 pPowerSpectrum_exp, /**< in: | exponent of power spectrum */ - const Word16 igfGridIdx /**< in: Q0 | IGF grid index */ - ) +static void IGF_ErodeSpectrum( Word16 *highPassEner_exp, /**< out: | exponent of highPassEner */ + const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ + Word32 *pSpectrum, /**< in/out: | MDCT spectrum */ + Word32 *pPowerSpectrum, /**< in/out: | power spectrum */ + Word16 pPowerSpectrum_exp, /**< in: | exponent of power spectrum */ + const Word16 igfGridIdx /**< in: Q0 | IGF grid index */ +) { IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; H_IGF_GRID hGrid; Word16 i; Word16 igfBgn; Word16 igfEnd; - Word32 highPassEner; /* Q31 */ + Word32 highPassEner; /* Q31 */ Word32 lastLine; Word32 nextLine; Word32 L_c; @@ -407,117 +401,118 @@ static void IGF_ErodeSpectrum(Word16 *highPassEner_e Flag Carry = 0; #endif - hPrivateData = &hInstance->igfData; - hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; - igfBgn = hGrid->startLine; + hPrivateData = &hInstance->igfData; + hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; + igfBgn = hGrid->startLine; move16(); - igfEnd = hGrid->stopLine; + igfEnd = hGrid->stopLine; move16(); - swb_offset = hGrid->swb_offset; + swb_offset = hGrid->swb_offset; move16(); - startSfb = hGrid->startSfb; + startSfb = hGrid->startSfb; move16(); - stopSfb = hGrid->stopSfb; + stopSfb = hGrid->stopSfb; move16(); - igfScaleF = hPrivateData->igfScfQuantized; + igfScaleF = hPrivateData->igfScfQuantized; move16(); *highPassEner_exp = 0; move16(); - highPassEner = 0; - move32(); + highPassEner = 0; + move32(); - IF (NULL == pPowerSpectrum) + IF( NULL == pPowerSpectrum ) { - FOR (i = igfBgn; i< hGrid->infoGranuleLen; i++) + FOR( i = igfBgn; i < hGrid->infoGranuleLen; i++ ) { - pSpectrum[i] = L_deposit_l(0); + pSpectrum[i] = L_deposit_l( 0 ); } return; } - IF (igfBgn > 0) + IF( igfBgn > 0 ) { - L_c = 0; move32(); - FOR (i = 0; i < igfBgn; i++) + L_c = 0; + move32(); + FOR( i = 0; i < igfBgn; i++ ) { - Carry = 0; + Carry = 0; #ifdef BASOP_NOGLOB - highPassEner = L_add_co(highPassEner, Mpy_32_16_1(pPowerSpectrum[i], shl(i,4)/*Q4*/)/*Q20, pPowerSpectrum_exp*/, &Carry, &Overflow); -#else /* BASOP_NOGLOB */ - highPassEner = L_add_c(highPassEner, Mpy_32_16_1(pPowerSpectrum[i], shl(i,4)/*Q4*/)/*Q20, pPowerSpectrum_exp*/); + highPassEner = L_add_co( highPassEner, Mpy_32_16_1( pPowerSpectrum[i], shl( i, 4 ) /*Q4*/ ) /*Q20, pPowerSpectrum_exp*/, &Carry, &Overflow ); +#else /* BASOP_NOGLOB */ + highPassEner = L_add_c( highPassEner, Mpy_32_16_1( pPowerSpectrum[i], shl( i, 4 ) /*Q4*/ ) /*Q20, pPowerSpectrum_exp*/ ); #endif /* BASOP_NOGLOB */ - Overflow = 0; + Overflow = 0; #ifdef BASOP_NOGLOB - L_c = L_macNs_co(L_c, 0, 0, &Carry, &Overflow); -#else /* BASOP_NOGLOB */ - L_c = L_macNs(L_c, 0, 0); + L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); +#else /* BASOP_NOGLOB */ + L_c = L_macNs( L_c, 0, 0 ); #endif /* BASOP_NOGLOB */ } - highPassEner = norm_llQ31(L_c, highPassEner, highPassEner_exp); /*Q20, highPassEner_exp*/ - *highPassEner_exp = add(*highPassEner_exp, pPowerSpectrum_exp); + highPassEner = norm_llQ31( L_c, highPassEner, highPassEner_exp ); /*Q20, highPassEner_exp*/ + *highPassEner_exp = add( *highPassEner_exp, pPowerSpectrum_exp ); test(); test(); - if ( NE_16(hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_9600)&& - NE_16(hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_RF_SWB_13200) && - NE_16(hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_13200 ) ) + if ( NE_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_9600 ) && + NE_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_RF_SWB_13200 ) && + NE_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_13200 ) ) { - igfBgn = shl(igfBgn, 1); + igfBgn = shl( igfBgn, 1 ); } - highPassEner = L_deposit_l(BASOP_Util_Divide3216_Scale(highPassEner/*Q20, highPassEner_exp*/, igfBgn /*Q0*/,&s)); /*Q15, highPassEner_exp+11-16+s*/ - *highPassEner_exp = add(add(*highPassEner_exp,s),12 - 16 + (31 - 15)); /*Q15->Q31,highPassEner_exp*/ - lastLine = pSpectrum[i - 1]; + highPassEner = L_deposit_l( BASOP_Util_Divide3216_Scale( highPassEner /*Q20, highPassEner_exp*/, igfBgn /*Q0*/, &s ) ); /*Q15, highPassEner_exp+11-16+s*/ + *highPassEner_exp = add( add( *highPassEner_exp, s ), 12 - 16 + ( 31 - 15 ) ); /*Q15->Q31,highPassEner_exp*/ + lastLine = pSpectrum[i - 1]; + move32(); + nextLine = 0; move32(); - nextLine = 0; - move32(); /* May overflow - just for threshold comparison */ /* negate because the negated may be 1 larger in abs, */ /* so whenever compared to the negation of a maximum possible pPowerspectrum, it is still larger */ #ifdef BASOP_NOGLOB - highPassEner_Ovfl = L_shl_o(L_negate(highPassEner), sub(*highPassEner_exp, pPowerSpectrum_exp), &Overflow); - L_tmp = L_add_o(pPowerSpectrum[i - 1], highPassEner_Ovfl, &Overflow); + highPassEner_Ovfl = L_shl_o( L_negate( highPassEner ), sub( *highPassEner_exp, pPowerSpectrum_exp ), &Overflow ); + L_tmp = L_add_o( pPowerSpectrum[i - 1], highPassEner_Ovfl, &Overflow ); #else BASOP_SATURATE_WARNING_OFF_EVS - highPassEner_Ovfl = L_shl(L_negate(highPassEner), sub(*highPassEner_exp, pPowerSpectrum_exp)); - L_tmp = L_add(pPowerSpectrum[i - 1], highPassEner_Ovfl); + highPassEner_Ovfl = L_shl( L_negate( highPassEner ), sub( *highPassEner_exp, pPowerSpectrum_exp ) ); + L_tmp = L_add( pPowerSpectrum[i - 1], highPassEner_Ovfl ); BASOP_SATURATE_WARNING_ON_EVS #endif - if (L_tmp >= 0) + if ( L_tmp >= 0 ) { nextLine = pSpectrum[i]; - move32(); + move32(); } - tmploop = sub(igfEnd,1); - FOR (/*i*/; i < tmploop; i++) + tmploop = sub( igfEnd, 1 ); + FOR( /*i*/; i < tmploop; i++ ) { /* May overflow - just for threshold comparison */ BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB L_tmp = L_add_sat( pPowerSpectrum[i], highPassEner_Ovfl ); #else - L_tmp = L_add(pPowerSpectrum[i], highPassEner_Ovfl); + L_tmp = L_add( pPowerSpectrum[i], highPassEner_Ovfl ); #endif BASOP_SATURATE_WARNING_ON_EVS - IF (L_tmp < 0) + IF( L_tmp < 0 ) { - lastLine = pSpectrum[i]; - move32(); - pSpectrum[i] = nextLine; + lastLine = pSpectrum[i]; + move32(); + pSpectrum[i] = nextLine; + move32(); + nextLine = 0; move32(); - nextLine = 0; - move32(); } ELSE { - pSpectrum[i-1] = lastLine; + pSpectrum[i - 1] = lastLine; + move32(); + lastLine = pSpectrum[i]; + move32(); + nextLine = pSpectrum[i + 1]; move32(); - lastLine = pSpectrum[i]; - move32(); - nextLine = pSpectrum[i+1]; - move32(); } } @@ -526,29 +521,29 @@ static void IGF_ErodeSpectrum(Word16 *highPassEner_e #ifdef BASOP_NOGLOB L_tmp = L_add_sat( pPowerSpectrum[i], highPassEner_Ovfl ); #else - L_tmp = L_add(pPowerSpectrum[i], highPassEner_Ovfl); + L_tmp = L_add( pPowerSpectrum[i], highPassEner_Ovfl ); #endif BASOP_SATURATE_WARNING_ON_EVS - IF (L_tmp < 0) + IF( L_tmp < 0 ) { - pSpectrum[i] = L_deposit_l(0); + pSpectrum[i] = L_deposit_l( 0 ); } } /* delete spectrum above igfEnd: */ - FOR (i = igfEnd; i < hGrid->infoGranuleLen; i++) + FOR( i = igfEnd; i < hGrid->infoGranuleLen; i++ ) { - pSpectrum[i] = L_deposit_l(0); - pPowerSpectrum[i] = L_deposit_l(0); + pSpectrum[i] = L_deposit_l( 0 ); + pPowerSpectrum[i] = L_deposit_l( 0 ); } - FOR (sfb = startSfb; sfb < stopSfb; sfb++) + FOR( sfb = startSfb; sfb < stopSfb; sfb++ ) { flag = 0; move16(); - FOR (line = swb_offset[sfb]; line < swb_offset[sfb+1]; line++) + FOR( line = swb_offset[sfb]; line < swb_offset[sfb + 1]; line++ ) { - if (pSpectrum[line] != 0) + if ( pSpectrum[line] != 0 ) { flag = 1; move16(); @@ -556,28 +551,27 @@ static void IGF_ErodeSpectrum(Word16 *highPassEner_e } tmp = igfScaleF[sfb]; move16(); - if(flag) + if ( flag ) { - tmp = sub(igfScaleF[sfb], 1); + tmp = sub( igfScaleF[sfb], 1 ); } - if (igfScaleF[sfb]) + if ( igfScaleF[sfb] ) { igfScaleF[sfb] = tmp; move16(); } } - } /**********************************************************************/ /* crest factor calculation **************************************************************************/ -static Word16 IGF_getCrest( /**< out: Q15| crest factor */ - Word16 *crest_exp, /**< out: | exponent of crest factor */ - const Word32 *powerSpectrum, /**< in: Q31 | power spectrum */ - const Word16 powerSpectrum_exp, /**< in: | exponent of power spectrum */ - const Word16 start, /**< in: Q0 | start subband index */ - const Word16 stop /**< in: Q0 | stop subband index */ +static Word16 IGF_getCrest( /**< out: Q15| crest factor */ + Word16 *crest_exp, /**< out: | exponent of crest factor */ + const Word32 *powerSpectrum, /**< in: Q31 | power spectrum */ + const Word16 powerSpectrum_exp, /**< in: | exponent of power spectrum */ + const Word16 start, /**< in: Q0 | start subband index */ + const Word16 stop /**< in: Q0 | stop subband index */ ) { Word16 i; @@ -589,48 +583,49 @@ static Word16 IGF_getCrest( Word16 tmp; Word32 tmp32; - x_eff32 = 0; move32(); - x_max = 0; + x_eff32 = 0; + move32(); + x_max = 0; move16(); - crest = 16384/*.5f Q15*/; + crest = 16384 /*.5f Q15*/; move16(); *crest_exp = 1; move16(); - FOR (i = start; i < stop; i++) + FOR( i = start; i < stop; i++ ) { /*x = max(0, (int)(log(powerSpectrum[i]) * INV_LOG_2));*/ /*see IGF_getSFM for more comment */ - x = sub(sub(powerSpectrum_exp, norm_l(powerSpectrum[i])), 1); /*Q0*/ - if (powerSpectrum[i] == 0) /*special case: energy is zero*/ + x = sub( sub( powerSpectrum_exp, norm_l( powerSpectrum[i] ) ), 1 ); /*Q0*/ + if ( powerSpectrum[i] == 0 ) /*special case: energy is zero*/ { x = 0; move16(); } - x = s_max(0, x); - x_eff32 = L_mac0(x_eff32, x ,x); /*Q0*/ - x_max = s_max(x_max, x); /*Q0*/ + x = s_max( 0, x ); + x_eff32 = L_mac0( x_eff32, x, x ); /*Q0*/ + x_max = s_max( x_max, x ); /*Q0*/ } /*x_eff /= (stop - start);*/ - x_eff32 = BASOP_Util_Divide3216_Scale(x_eff32, sub(stop,start), &s); /*Q-1, s*/ - s = add(s, 32); /*make x_eff Q31*/ + x_eff32 = BASOP_Util_Divide3216_Scale( x_eff32, sub( stop, start ), &s ); /*Q-1, s*/ + s = add( s, 32 ); /*make x_eff Q31*/ /*trunkate to int*/ - x_eff32 = L_shr(x_eff32, sub(31, s)); - x_eff32 = L_shl(x_eff32, sub(31, s)); + x_eff32 = L_shr( x_eff32, sub( 31, s ) ); + x_eff32 = L_shl( x_eff32, sub( 31, s ) ); test(); - IF (x_eff32 > 0 && x_max > 0) + IF( x_eff32 > 0 && x_max > 0 ) { /*crest = max(1.f, (float)x_max/sqrt(x_eff));*/ - tmp32 = ISqrt32(x_eff32, &s); /*Q31, s*/ - tmp32 = Mpy_32_16_1(tmp32/*Q31, s*/, x_max/*Q0*/); /*Q16, s*/ - i = norm_l(tmp32); - tmp32 = L_shl(tmp32, i); /*Q31, s-i+15*/ - crest = extract_h(tmp32); - *crest_exp = add(sub(s, i), 15); + tmp32 = ISqrt32( x_eff32, &s ); /*Q31, s*/ + tmp32 = Mpy_32_16_1( tmp32 /*Q31, s*/, x_max /*Q0*/ ); /*Q16, s*/ + i = norm_l( tmp32 ); + tmp32 = L_shl( tmp32, i ); /*Q31, s-i+15*/ + crest = extract_h( tmp32 ); + *crest_exp = add( sub( s, i ), 15 ); /* limit crest factor to a lower bound of 1, may overflow */ BASOP_SATURATE_WARNING_OFF_EVS @@ -638,16 +633,16 @@ static Word16 IGF_getCrest( tmp = shl_sat( -1, sub( 15, *crest_exp ) ); /* build negative threshold */ tmp = add_sat( crest, tmp ); #else - tmp = shl(-1, sub(15, *crest_exp)); /* build negative threshold */ - tmp = add(crest, tmp); + tmp = shl( -1, sub( 15, *crest_exp ) ); /* build negative threshold */ + tmp = add( crest, tmp ); #endif BASOP_SATURATE_WARNING_ON_EVS - if (tmp < 0) + if ( tmp < 0 ) { - crest = 1; + crest = 1; move16(); } - if (tmp < 0) + if ( tmp < 0 ) { *crest_exp = 15; move16(); @@ -660,15 +655,15 @@ static Word16 IGF_getCrest( /************************************************************************* calculates spectral flatness measurment **************************************************************************/ -static Word16 IGF_getSFM( /**< out: Q15| SFM value */ - Word16 *SFM_exp, /**< out: | exponent of SFM Factor */ - const Word32 *energy, /**< in: Q31| energies */ - const Word16 *energy_exp, /**< in: | exponent of energies */ - const Word16 start, /**< in: Q0 | start subband index */ - const Word16 stop /**< in: Q0 | stop subband index */ +static Word16 IGF_getSFM( /**< out: Q15| SFM value */ + Word16 *SFM_exp, /**< out: | exponent of SFM Factor */ + const Word32 *energy, /**< in: Q31| energies */ + const Word16 *energy_exp, /**< in: | exponent of energies */ + const Word16 start, /**< in: Q0 | start subband index */ + const Word16 stop /**< in: Q0 | stop subband index */ ) { - Word16 n,i, s; + Word16 n, i, s; Word32 num; Word32 denom; Word16 denom_exp; @@ -682,95 +677,97 @@ static Word16 IGF_getSFM( Flag Carry = 0; #endif - L_c = 0; move32(); - num = 0; move32(); - denom = L_shr(2147483 /*0,001 in Q31 - float is "1", here*/,s_min(*energy_exp, 31)); - denom = L_max(denom, 1); + L_c = 0; + move32(); + num = 0; + move32(); + denom = L_shr( 2147483 /*0,001 in Q31 - float is "1", here*/, s_min( *energy_exp, 31 ) ); + denom = L_max( denom, 1 ); *SFM_exp = 0; move16(); - SFM = 32767/*1.0f Q15*/; + SFM = 32767 /*1.0f Q15*/; move16(); - FOR (i = start; i < stop; i++) + FOR( i = start; i < stop; i++ ) { /*ln(x * 2^-Qx * 2^xExp) = ln(x) - Qx + xExp*/ - /* n = sub(sub(31,norm_l(tmp32)),1); */ /*<- ld */ - /* n = sub(n,31); */ /*<- -Qx */ - /* n = add(n,*energy_exp); */ /*<- +xExp */ + /* n = sub(sub(31,norm_l(tmp32)),1); */ /*<- ld */ + /* n = sub(n,31); */ /*<- -Qx */ + /* n = add(n,*energy_exp); */ /*<- +xExp */ - n = sub(sub(*energy_exp, norm_l(energy[i])), 1); /*<-- short form*/ + n = sub( sub( *energy_exp, norm_l( energy[i] ) ), 1 ); /*<-- short form*/ - if (energy[i] == 0) /*special case: energy is zero*/ + if ( energy[i] == 0 ) /*special case: energy is zero*/ { n = 0; move16(); } - n = s_max(0, n); - num = L_add(num, L_deposit_l(n)); /*Q0*/ + n = s_max( 0, n ); + num = L_add( num, L_deposit_l( n ) ); /*Q0*/ - Carry = 0; + Carry = 0; #ifdef BASOP_NOGLOB - denom = L_add_co(energy[i], denom, &Carry, &Overflow); -#else /* BASOP_NOGLOB */ - denom = L_add_c(energy[i], denom); + denom = L_add_co( energy[i], denom, &Carry, &Overflow ); +#else /* BASOP_NOGLOB */ + denom = L_add_c( energy[i], denom ); #endif /* BASOP_NOGLOB */ Overflow = 0; #ifdef BASOP_NOGLOB - L_c = L_macNs_co(L_c, 0, 0, &Carry, &Overflow); + L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); #else /* BASOP_NOGLOB */ - L_c = L_macNs(L_c, 0, 0); + L_c = L_macNs( L_c, 0, 0 ); #endif } - denom = norm_llQ31(L_c, denom, &denom_exp); /*Q31*/ - denom_exp = add(denom_exp, *energy_exp); + denom = norm_llQ31( L_c, denom, &denom_exp ); /*Q31*/ + denom_exp = add( denom_exp, *energy_exp ); /* calculate SFM only if signal is present */ - IF (denom != 0) + IF( denom != 0 ) { /*numf = (float)num / (float)(stop - start);*/ - numf = BASOP_Util_Divide3216_Scale(num, /*Q0*/ - sub(stop,start), /*Q0*/ - &s); /*Q-1 s*/ - numf_exp = add(s,16); /*-> numf Q15 numf_exp*/ + numf = BASOP_Util_Divide3216_Scale( num, /*Q0*/ + sub( stop, start ), /*Q0*/ + &s ); /*Q-1 s*/ + numf_exp = add( s, 16 ); /*-> numf Q15 numf_exp*/ /*denom /= (float)(stop - start);*/ /*return ((float)pow(2.0, numf + 0.5f) / denom);*/ /*SFM= ((float)pow(2.0, numf + 0.5f) * invDenom);*/ - invDenom = BASOP_Util_Divide3232_uu_1616_Scale(L_deposit_l(sub(stop, start)) /*Q0*/, - denom /*Q31, denom_exp*/, - &s); /*Q-16, s-denom_exp*/ - invDenom_exp = add(sub(s, denom_exp), 31); /*invDenom: Q15, invDenom_exp*/ + invDenom = BASOP_Util_Divide3232_uu_1616_Scale( L_deposit_l( sub( stop, start ) ) /*Q0*/, + denom /*Q31, denom_exp*/, + &s ); /*Q-16, s-denom_exp*/ + invDenom_exp = add( sub( s, denom_exp ), 31 ); /*invDenom: Q15, invDenom_exp*/ /*add .5f to numf*/ - SFM32 = L_add(L_shl(L_deposit_l(numf), numf_exp) /*16Q15*/,16384l/*.5f Q15*/); /*16Q15*/ - s = norm_l(SFM32); - SFM32 = L_shl(SFM32, s); - s = sub(16, s); /*SFM32(numf) is Q31 now*/ + SFM32 = L_add( L_shl( L_deposit_l( numf ), numf_exp ) /*16Q15*/, 16384l /*.5f Q15*/ ); /*16Q15*/ + s = norm_l( SFM32 ); + SFM32 = L_shl( SFM32, s ); + s = sub( 16, s ); /*SFM32(numf) is Q31 now*/ /*do the pow2 and the mult*/ - SFM32 = BASOP_util_Pow2(SFM32, s, &s); - SFM32 = Mpy_32_16_1(SFM32, invDenom); - *SFM_exp = add(s, invDenom_exp); + SFM32 = BASOP_util_Pow2( SFM32, s, &s ); + SFM32 = Mpy_32_16_1( SFM32, invDenom ); + *SFM_exp = add( s, invDenom_exp ); /*Transform to Q15*/ - s = norm_l(SFM32); + s = norm_l( SFM32 ); #ifdef BASOP_NOGLOB SFM = round_fx_sat( L_shl_sat( SFM32, s ) ); #else SFM = round_fx( L_shl( SFM32, s ) ); #endif - *SFM_exp = sub(*SFM_exp, s); + *SFM_exp = sub( *SFM_exp, s ); /**SFM_exp = s_min(*SFM_exp, 0);*/ - IF (*SFM_exp > 0) + IF( *SFM_exp > 0 ) { *SFM_exp = 0; move16(); - SFM = 32767/*1.0f Q15*/; + SFM = 32767 /*1.0f Q15*/; move16(); } } @@ -781,17 +778,17 @@ static Word16 IGF_getSFM( /**********************************************************************/ /* calculates the IGF whitening levels by SFM and crest **************************************************************************/ -static void IGF_Whitening(const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ - Word32 *powerSpectrum, /**< in: Q31 | MDCT/MDST power spectrum */ - const Word16 powerSpectrum_exp, /**< in: | exponent of powerspectrum */ - const Word16 igfGridIdx, /**< in: Q0 | IGF grid index */ - Word16 isTransient, /**< in: Q0 | boolean, indicating if transient is detected */ - Word16 last_core_acelp /**< in: Q0 | indictaor if last frame was acelp coded */ - ) +static void IGF_Whitening( const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ + Word32 *powerSpectrum, /**< in: Q31 | MDCT/MDST power spectrum */ + const Word16 powerSpectrum_exp, /**< in: | exponent of powerspectrum */ + const Word16 igfGridIdx, /**< in: Q0 | IGF grid index */ + Word16 isTransient, /**< in: Q0 | boolean, indicating if transient is detected */ + Word16 last_core_acelp /**< in: Q0 | indictaor if last frame was acelp coded */ +) { IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; H_IGF_GRID hGrid; - Word16 p; /*Q0*/ + Word16 p; /*Q0*/ Word16 tmp; Word16 SFM; Word16 crest; @@ -802,14 +799,14 @@ static void IGF_Whitening(const IGF_ENC_INSTANCE_HANDLE hInstanc Word32 SFM32; hPrivateData = &hInstance->igfData; - hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; + hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; - IF (igfGridIdx != IGF_GRID_LB_NORM) + IF( igfGridIdx != IGF_GRID_LB_NORM ) { - FOR (p = 0; p < hGrid->nTiles; p++) + FOR( p = 0; p < hGrid->nTiles; p++ ) { /* reset filter */ - hPrivateData->prevSFM_FIR[p] = L_deposit_l(0); + hPrivateData->prevSFM_FIR[p] = L_deposit_l( 0 ); hPrivateData->prevSFM_IIR[p] = 0; move16(); @@ -818,7 +815,7 @@ static void IGF_Whitening(const IGF_ENC_INSTANCE_HANDLE hInstanc move16(); } } - FOR (p = 0; p < IGF_MAX_TILES; p++) + FOR( p = 0; p < IGF_MAX_TILES; p++ ) { /* update prev data: */ hPrivateData->igfPrevWhiteningLevel[p] = hPrivateData->igfCurrWhiteningLevel[p]; @@ -828,46 +825,48 @@ static void IGF_Whitening(const IGF_ENC_INSTANCE_HANDLE hInstanc move16(); } - IF (!s_or(isTransient, hPrivateData->wasTransient)) + IF( !s_or( isTransient, hPrivateData->wasTransient ) ) { - IF (powerSpectrum) + IF( powerSpectrum ) { Word16 nT = hGrid->nTiles; - SWITCH (hPrivateData->igfInfo.bitRateIndex) + SWITCH( hPrivateData->igfInfo.bitRateIndex ) { - case IGF_BITRATE_WB_9600: - case IGF_BITRATE_SWB_9600: - case IGF_BITRATE_SWB_16400: - case IGF_BITRATE_SWB_24400: - case IGF_BITRATE_SWB_32000: - case IGF_BITRATE_FB_16400: - case IGF_BITRATE_FB_24400: - case IGF_BITRATE_FB_32000: - nT = sub(nT, 1); - BREAK; - default: - BREAK; + case IGF_BITRATE_WB_9600: + case IGF_BITRATE_SWB_9600: + case IGF_BITRATE_SWB_16400: + case IGF_BITRATE_SWB_24400: + case IGF_BITRATE_SWB_32000: + case IGF_BITRATE_FB_16400: + case IGF_BITRATE_FB_24400: + case IGF_BITRATE_FB_32000: + nT = sub( nT, 1 ); + BREAK; + default: + BREAK; } - FOR (p = 0; p < nT; p++) + FOR( p = 0; p < nT; p++ ) { /*tmp = IGF_getSFM(powerSpectrum, hGrid->tile[p], hGrid->tile[p+1]) / IGF_getCrest(powerSpectrum, hGrid->tile[p], hGrid->tile[p+1]);*/ - SFM = IGF_getSFM(&SFM_exp, powerSpectrum, &powerSpectrum_exp, hGrid->tile[p], hGrid->tile[p + 1]); - crest = IGF_getCrest(&crest_exp, powerSpectrum, powerSpectrum_exp, hGrid->tile[p], hGrid->tile[p + 1]); + SFM = IGF_getSFM( &SFM_exp, powerSpectrum, &powerSpectrum_exp, hGrid->tile[p], hGrid->tile[p + 1] ); + crest = IGF_getCrest( &crest_exp, powerSpectrum, powerSpectrum_exp, hGrid->tile[p], hGrid->tile[p + 1] ); - tmp = BASOP_Util_Divide1616_Scale(SFM, crest, &s); /* Q15 */ - s = add(s, sub(SFM_exp, crest_exp)); - tmp32 = L_shl(L_deposit_l(tmp)/*16Q15, s*/,add(s,1)); /* 15Q16 */ + tmp = BASOP_Util_Divide1616_Scale( SFM, crest, &s ); /* Q15 */ + s = add( s, sub( SFM_exp, crest_exp ) ); + tmp32 = L_shl( L_deposit_l( tmp ) /*16Q15, s*/, add( s, 1 ) ); /* 15Q16 */ test(); - IF (last_core_acelp || hPrivateData->wasTransient) + IF( last_core_acelp || hPrivateData->wasTransient ) { - hPrivateData->prevSFM_FIR[p] = tmp32; /* 15Q16 */ move32(); - hPrivateData->prevSFM_IIR[p] = shr(tmp, 2); /* 2Q13 */ move16(); + hPrivateData->prevSFM_FIR[p] = tmp32; /* 15Q16 */ + move32(); + hPrivateData->prevSFM_IIR[p] = shr( tmp, 2 ); /* 2Q13 */ + move16(); } /*SFM = tmp + hPrivateData->prevSFM_FIR[p] + 0.5f * hPrivateData->prevSFM_IIR[p];*/ - SFM32 = L_add(tmp32,hPrivateData->prevSFM_FIR[p]); - SFM32 = L_mac0(SFM32,hPrivateData->prevSFM_IIR[p]/*Q13*/,4/*.5f Q3*/);/*15Q16*/ + SFM32 = L_add( tmp32, hPrivateData->prevSFM_FIR[p] ); + SFM32 = L_mac0( SFM32, hPrivateData->prevSFM_IIR[p] /*Q13*/, 4 /*.5f Q3*/ ); /*15Q16*/ BASOP_SATURATE_WARNING_OFF_EVS /*SFM = min(2.7f, SFM);*/ @@ -877,47 +876,48 @@ static void IGF_Whitening(const IGF_ENC_INSTANCE_HANDLE hInstanc SFM = s_min( 22118 /*2.7f Q13*/, extract_h( L_shr_sat( SFM32, 16 - 29 ) /*->Q29*/ ) /*->Q13*/ ); #else tmp = add( crest, tmp ); - SFM = s_min(22118/*2.7f Q13*/,extract_h(L_shr(SFM32,16-29)/*->Q29*/)/*->Q13*/ ); + SFM = s_min( 22118 /*2.7f Q13*/, extract_h( L_shr( SFM32, 16 - 29 ) /*->Q29*/ ) /*->Q13*/ ); #endif BASOP_SATURATE_WARNING_ON_EVS - hPrivateData->prevSFM_FIR[p] = tmp32; /*15Q16*/ move32(); + hPrivateData->prevSFM_FIR[p] = tmp32; /*15Q16*/ + move32(); hPrivateData->prevSFM_IIR[p] = SFM; move16(); - IF (GT_16(SFM , hGrid->whiteningThreshold[1][p])) + IF( GT_16( SFM, hGrid->whiteningThreshold[1][p] ) ) { hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_STRONG; move16(); } - ELSE IF (GT_16(SFM , hGrid->whiteningThreshold[0][p])) + ELSE IF( GT_16( SFM, hGrid->whiteningThreshold[0][p] ) ) { hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_MID; move16(); } } - SWITCH (hPrivateData->igfInfo.bitRateIndex) + SWITCH( hPrivateData->igfInfo.bitRateIndex ) { - case IGF_BITRATE_WB_9600: - case IGF_BITRATE_RF_WB_13200: - case IGF_BITRATE_RF_SWB_13200: - case IGF_BITRATE_SWB_9600: - case IGF_BITRATE_SWB_16400: - case IGF_BITRATE_SWB_24400: - case IGF_BITRATE_SWB_32000: - case IGF_BITRATE_FB_16400: - case IGF_BITRATE_FB_24400: - case IGF_BITRATE_FB_32000: - move16(); - hPrivateData->igfCurrWhiteningLevel[hGrid->nTiles - 1] = hPrivateData->igfCurrWhiteningLevel[hGrid->nTiles - 2]; - BREAK; - default: - BREAK; + case IGF_BITRATE_WB_9600: + case IGF_BITRATE_RF_WB_13200: + case IGF_BITRATE_RF_SWB_13200: + case IGF_BITRATE_SWB_9600: + case IGF_BITRATE_SWB_16400: + case IGF_BITRATE_SWB_24400: + case IGF_BITRATE_SWB_32000: + case IGF_BITRATE_FB_16400: + case IGF_BITRATE_FB_24400: + case IGF_BITRATE_FB_32000: + move16(); + hPrivateData->igfCurrWhiteningLevel[hGrid->nTiles - 1] = hPrivateData->igfCurrWhiteningLevel[hGrid->nTiles - 2]; + BREAK; + default: + BREAK; } } ELSE { - FOR (p = 0; p < hGrid->nTiles; p++) + FOR( p = 0; p < hGrid->nTiles; p++ ) { hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_MID; move16(); @@ -927,54 +927,53 @@ static void IGF_Whitening(const IGF_ENC_INSTANCE_HANDLE hInstanc ELSE { /* reset filter */ - FOR (p = 0; p < IGF_MAX_TILES; p++) + FOR( p = 0; p < IGF_MAX_TILES; p++ ) { - hPrivateData->prevSFM_FIR[p] = L_deposit_l(0); + hPrivateData->prevSFM_FIR[p] = L_deposit_l( 0 ); hPrivateData->prevSFM_IIR[p] = 0; move16(); } } hPrivateData->wasTransient = isTransient; move16(); - } /**********************************************************************/ /* write whitening levels into bitstream **************************************************************************/ -static void IGF_WriteWhiteningTile( /**< out: Q0 | number of bits written */ - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - Word16 *pBitOffset, /**< in: | ptr to bitOffset counter */ - Word16 whiteningLevel /**< in: Q0 | whitening levels to write */ +static void IGF_WriteWhiteningTile( /**< out: Q0 | number of bits written */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 *pBitOffset, /**< in: | ptr to bitOffset counter */ + Word16 whiteningLevel /**< in: Q0 | whitening levels to write */ ) { - IF (EQ_32(whiteningLevel, IGF_WHITENING_MID)) + IF( EQ_32( whiteningLevel, IGF_WHITENING_MID ) ) { - IGF_write_bits(hBstr, pBitOffset, 0, 1); + IGF_write_bits( hBstr, pBitOffset, 0, 1 ); } ELSE { - IGF_write_bits(hBstr, pBitOffset, 1, 1); - IF (EQ_32(whiteningLevel , IGF_WHITENING_OFF)) + IGF_write_bits( hBstr, pBitOffset, 1, 1 ); + IF( EQ_32( whiteningLevel, IGF_WHITENING_OFF ) ) { - IGF_write_bits(hBstr, pBitOffset, 0, 1); + IGF_write_bits( hBstr, pBitOffset, 0, 1 ); } ELSE { - IGF_write_bits(hBstr, pBitOffset, 1, 1); + IGF_write_bits( hBstr, pBitOffset, 1, 1 ); } } } -/**********************************************************************/ /* -writes the whitening levels -**************************************************************************/ -static void IGF_WriteWhiteningLevels( /**< out: Q0 | total number of bits written */ - const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF encoder */ - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - Word16 *pBitOffset, /**< in: | ptr to bitOffset counter */ - const Word16 igfGridIdx, /**< in: Q0 | igf grid index see declaration of IGF_GRID_IDX for details */ - const Word16 isIndepFlag /**< in: Q0 | if 1 frame is independent, 0 = frame is coded with data from previous frame */ +/**********************************************************************/ /* + writes the whitening levels + **************************************************************************/ +static void IGF_WriteWhiteningLevels( /**< out: Q0 | total number of bits written */ + const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF encoder */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 *pBitOffset, /**< in: | ptr to bitOffset counter */ + const Word16 igfGridIdx, /**< in: Q0 | igf grid index see declaration of IGF_GRID_IDX for details */ + const Word16 isIndepFlag /**< in: Q0 | if 1 frame is independent, 0 = frame is coded with data from previous frame */ ) { IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; @@ -985,30 +984,30 @@ static void IGF_WriteWhiteningLevels( Word32 tmp32; - isSame = 1; + isSame = 1; move16(); - hPrivateData = &hInstance->igfData; - hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; - nTiles = hGrid->nTiles; + hPrivateData = &hInstance->igfData; + hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; + nTiles = hGrid->nTiles; move16(); - IF (isIndepFlag) + IF( isIndepFlag ) { isSame = 0; move16(); } ELSE { - p = 0; + p = 0; move16(); - tmp32 = 0; - move32(); + tmp32 = 0; + move32(); - WHILE ((LT_16(p, nTiles))&&(tmp32==0)) + WHILE( ( LT_16( p, nTiles ) ) && ( tmp32 == 0 ) ) { test(); - tmp32 = L_sub(hPrivateData->igfCurrWhiteningLevel[p] , hPrivateData->igfPrevWhiteningLevel[p]); - if (tmp32 != 0) + tmp32 = L_sub( hPrivateData->igfCurrWhiteningLevel[p], hPrivateData->igfPrevWhiteningLevel[p] ); + if ( tmp32 != 0 ) { isSame = 0; move16(); @@ -1016,32 +1015,32 @@ static void IGF_WriteWhiteningLevels( p++; } } - IF (isSame) + IF( isSame ) { - IGF_write_bits(hBstr, pBitOffset, 1, 1); + IGF_write_bits( hBstr, pBitOffset, 1, 1 ); } ELSE { - IF (!isIndepFlag) + IF( !isIndepFlag ) { - IGF_write_bits(hBstr, pBitOffset, 0, 1); + IGF_write_bits( hBstr, pBitOffset, 0, 1 ); } - IGF_WriteWhiteningTile(hBstr, pBitOffset, hPrivateData->igfCurrWhiteningLevel[0]); - p = 1; + IGF_WriteWhiteningTile( hBstr, pBitOffset, hPrivateData->igfCurrWhiteningLevel[0] ); + p = 1; move16(); - tmp32 = 0; - move32(); - if (LT_16(p, nTiles)) + tmp32 = 0; + move32(); + if ( LT_16( p, nTiles ) ) { isSame = 1; move16(); } - WHILE ((LT_16(p, nTiles))&&(tmp32==0)) + WHILE( ( LT_16( p, nTiles ) ) && ( tmp32 == 0 ) ) { test(); - tmp32 = L_sub(hPrivateData->igfCurrWhiteningLevel[p] , hPrivateData->igfCurrWhiteningLevel[p - 1]); - if (tmp32 != 0) + tmp32 = L_sub( hPrivateData->igfCurrWhiteningLevel[p], hPrivateData->igfCurrWhiteningLevel[p - 1] ); + if ( tmp32 != 0 ) { isSame = 0; move16(); @@ -1049,29 +1048,28 @@ static void IGF_WriteWhiteningLevels( p++; } - IF (!isSame) + IF( !isSame ) { - IGF_write_bits(hBstr, pBitOffset, 1, 1); - FOR (p = 1; p < nTiles; p++) + IGF_write_bits( hBstr, pBitOffset, 1, 1 ); + FOR( p = 1; p < nTiles; p++ ) { - IGF_WriteWhiteningTile(hBstr, pBitOffset, hPrivateData->igfCurrWhiteningLevel[p]); + IGF_WriteWhiteningTile( hBstr, pBitOffset, hPrivateData->igfCurrWhiteningLevel[p] ); } } ELSE { - IGF_write_bits(hBstr, pBitOffset, 0, 1); + IGF_write_bits( hBstr, pBitOffset, 0, 1 ); } } - } -/**********************************************************************/ /* -write flattening trigger -**************************************************************************/ -static void IGF_WriteFlatteningTrigger( /**< out: | number of bits written */ - const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - Word16 *pBitOffset /**< in: | ptr to bitOffset counter */ +/**********************************************************************/ /* + write flattening trigger + **************************************************************************/ +static void IGF_WriteFlatteningTrigger( /**< out: | number of bits written */ + const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 *pBitOffset /**< in: | ptr to bitOffset counter */ ) { Word16 flatteningTrigger; @@ -1080,30 +1078,29 @@ static void IGF_WriteFlatteningTrigger( flatteningTrigger = hInstance->flatteningTrigger; move16(); - IGF_write_bits(hBstr, pBitOffset, flatteningTrigger, 1); - + IGF_write_bits( hBstr, pBitOffset, flatteningTrigger, 1 ); } /**********************************************************************/ /* updates the start/stop frequency of IGF according to igfGridIdx **************************************************************************/ -static void IGF_UpdateInfo(const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ - const Word16 igfGridIdx /**< in: Q0 | IGF grid index */ - ) +static void IGF_UpdateInfo( const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ + const Word16 igfGridIdx /**< in: Q0 | IGF grid index */ +) { IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; H_IGF_GRID hGrid; - hPrivateData = &hInstance->igfData; - hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; + hPrivateData = &hInstance->igfData; + hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; hInstance->infoStartFrequency = hGrid->startFrequency; move16(); - hInstance->infoStopFrequency = hGrid->stopFrequency; + hInstance->infoStopFrequency = hGrid->stopFrequency; move16(); - hInstance->infoStartLine = hGrid->startLine; + hInstance->infoStartLine = hGrid->startLine; move16(); - hInstance->infoStopLine = hGrid->stopLine; + hInstance->infoStopLine = hGrid->stopLine; move16(); return; @@ -1112,48 +1109,48 @@ static void IGF_UpdateInfo(const IGF_ENC_INSTANCE_HANDLE hInstanc /**********************************************************************/ /* IGF bitsream writer **************************************************************************/ -Word16 IGFEncWriteBitstream_fx( /**< out: | number of bits written per frame */ - const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - Word16 *pBitOffset, /**< in: | ptr to bitOffset counter */ - const Word16 igfGridIdx, /**< in: Q0 | igf grid index see declaration of IGF_GRID_IDX for details */ - const Word16 isIndepFlag /**< in: Q0 | if 1 frame is independent, 0 = frame is coded with data from previous frame */ +Word16 IGFEncWriteBitstream_fx( /**< out: | number of bits written per frame */ + const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 *pBitOffset, /**< in: | ptr to bitOffset counter */ + const Word16 igfGridIdx, /**< in: Q0 | igf grid index see declaration of IGF_GRID_IDX for details */ + const Word16 isIndepFlag /**< in: Q0 | if 1 frame is independent, 0 = frame is coded with data from previous frame */ ) { Word16 igfAllZero; Word16 startBitCount; - startBitCount = *pBitOffset; + startBitCount = *pBitOffset; move16(); hInstance->infoTotalBitsPerFrameWritten = 0; move16(); - if (isIndepFlag) + if ( isIndepFlag ) { hInstance->infoTotalBitsWritten = 0; move16(); } - IGF_WriteEnvelope(hInstance, /* i: instance handle of IGF Encoder */ - hBstr, /* i: encoder state */ - pBitOffset, /* i: ptr to bitOffset counter */ - igfGridIdx, /* i: igf grid index see definition of IGF_GRID_IDX for details */ - isIndepFlag, /* i: if 1 frame is independent, 0 = frame is coded with data from previous frame */ - &igfAllZero); /* o: *igfAllZero */ + IGF_WriteEnvelope( hInstance, /* i: instance handle of IGF Encoder */ + hBstr, /* i: encoder state */ + pBitOffset, /* i: ptr to bitOffset counter */ + igfGridIdx, /* i: igf grid index see definition of IGF_GRID_IDX for details */ + isIndepFlag, /* i: if 1 frame is independent, 0 = frame is coded with data from previous frame */ + &igfAllZero ); /* o: *igfAllZero */ - IGF_WriteWhiteningLevels(hInstance, /* i: instance handle of IGF Encoder */ - hBstr, /* i: encoder state */ - pBitOffset, /* i: ptr to bitOffset counter */ - igfGridIdx, /* i: igf grid index see definition of IGF_GRID_IDX for details */ - isIndepFlag); /* i: if 1 frame is independent, 0 = frame is coded with data from previous frame */ + IGF_WriteWhiteningLevels( hInstance, /* i: instance handle of IGF Encoder */ + hBstr, /* i: encoder state */ + pBitOffset, /* i: ptr to bitOffset counter */ + igfGridIdx, /* i: igf grid index see definition of IGF_GRID_IDX for details */ + isIndepFlag ); /* i: if 1 frame is independent, 0 = frame is coded with data from previous frame */ - IGF_WriteFlatteningTrigger(hInstance, /* i: instance handle of IGF Encoder */ - hBstr, /* i: encoder state */ - pBitOffset); /* i: ptr to bitOffset counter */ + IGF_WriteFlatteningTrigger( hInstance, /* i: instance handle of IGF Encoder */ + hBstr, /* i: encoder state */ + pBitOffset ); /* i: ptr to bitOffset counter */ - hInstance->infoTotalBitsPerFrameWritten = sub(*pBitOffset, startBitCount); - hInstance->infoTotalBitsWritten = add(hInstance->infoTotalBitsWritten, hInstance->infoTotalBitsPerFrameWritten); + hInstance->infoTotalBitsPerFrameWritten = sub( *pBitOffset, startBitCount ); + hInstance->infoTotalBitsWritten = add( hInstance->infoTotalBitsWritten, hInstance->infoTotalBitsPerFrameWritten ); return hInstance->infoTotalBitsPerFrameWritten; } @@ -1163,10 +1160,10 @@ sets the IGF mode according to given bitrate **************************************************************************/ void IGFEncSetMode_fx( const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i/o: instance handle of IGF Encoder */ - const Word32 total_brate, /* i : encoder total bitrate */ - const Word16 bwidth, /* i : encoder audio bandwidth */ - const Word16 element_mode, /* i : IVAS element mode */ - const Word16 rf_mode /* i : flag to signal the RF mode */ + const Word32 total_brate, /* i : encoder total bitrate */ + const Word16 bwidth, /* i : encoder audio bandwidth */ + const Word16 element_mode, /* i : IVAS element mode */ + const Word16 rf_mode /* i : flag to signal the RF mode */ ) { IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; @@ -1175,62 +1172,62 @@ void IGFEncSetMode_fx( hPrivateData = &hIGFEnc->igfData; hPrivateData->igfBitstreamBits = 0; move16(); - set16_fx(hPrivateData->igfScfQuantized, 0, IGF_MAX_SFB); - set16_fx(hPrivateData->igfCurrWhiteningLevel, 0, IGF_MAX_TILES); - set16_fx(hPrivateData->igfPrevWhiteningLevel, 0, IGF_MAX_TILES); - FOR( i = 0; i < IGF_BITBUFSIZE /8; i++) + set16_fx( hPrivateData->igfScfQuantized, 0, IGF_MAX_SFB ); + set16_fx( hPrivateData->igfCurrWhiteningLevel, 0, IGF_MAX_TILES ); + set16_fx( hPrivateData->igfPrevWhiteningLevel, 0, IGF_MAX_TILES ); + FOR( i = 0; i < IGF_BITBUFSIZE / 8; i++ ) { hPrivateData->igfBitstream[i] = 0; move16(); } - hPrivateData->wasTransient = 0; + hPrivateData->wasTransient = 0; move16(); - set32_fx(hPrivateData->prevSFM_FIR, 0, IGF_MAX_TILES); - set16_fx(hPrivateData->prevSFM_IIR, 0, IGF_MAX_TILES); + set32_fx( hPrivateData->prevSFM_FIR, 0, IGF_MAX_TILES ); + set16_fx( hPrivateData->prevSFM_IIR, 0, IGF_MAX_TILES ); - IF (IGFCommonFuncsIGFConfiguration(total_brate, bwidth, element_mode, &hPrivateData->igfInfo, rf_mode) != 0) + IF( IGFCommonFuncsIGFConfiguration( total_brate, bwidth, element_mode, &hPrivateData->igfInfo, rf_mode ) != 0 ) { - IGFSCFEncoderOpen_fx(&hPrivateData->hIGFSCFArithEnc, &hPrivateData->igfInfo, total_brate, bwidth, element_mode, rf_mode); + IGFSCFEncoderOpen_fx( &hPrivateData->hIGFSCFArithEnc, &hPrivateData->igfInfo, total_brate, bwidth, element_mode, rf_mode ); - hIGFEnc->infoSamplingRate = hPrivateData->igfInfo.sampleRate; + hIGFEnc->infoSamplingRate = hPrivateData->igfInfo.sampleRate; move32(); hIGFEnc->infoStartFrequency = hPrivateData->igfInfo.grid[0].startFrequency; move16(); - hIGFEnc->infoStopFrequency = hPrivateData->igfInfo.grid[0].stopFrequency; + hIGFEnc->infoStopFrequency = hPrivateData->igfInfo.grid[0].stopFrequency; move16(); - hIGFEnc->infoStartLine = hPrivateData->igfInfo.grid[0].startLine; + hIGFEnc->infoStartLine = hPrivateData->igfInfo.grid[0].startLine; move16(); - hIGFEnc->infoStopLine = hPrivateData->igfInfo.grid[0].stopLine; + hIGFEnc->infoStopLine = hPrivateData->igfInfo.grid[0].stopLine; move16(); } ELSE { /* IGF configuration failed -> error! */ - hIGFEnc->infoSamplingRate = 0; + hIGFEnc->infoSamplingRate = 0; move32(); hIGFEnc->infoStartFrequency = -1; move16(); - hIGFEnc->infoStopFrequency = -1; + hIGFEnc->infoStopFrequency = -1; move16(); - hIGFEnc->infoStartLine = -1; + hIGFEnc->infoStartLine = -1; move16(); - hIGFEnc->infoStopLine = -1; + hIGFEnc->infoStopLine = -1; move16(); - fprintf(stderr,"IGFEncSetMode_fx: initialization error!\n"); + fprintf( stderr, "IGFEncSetMode_fx: initialization error!\n" ); } /* reset remaining variables */ - hIGFEnc->infoTotalBitsWritten = 0; + hIGFEnc->infoTotalBitsWritten = 0; move16(); hIGFEnc->infoTotalBitsPerFrameWritten = 0; move16(); - hIGFEnc->flatteningTrigger = 0; + hIGFEnc->flatteningTrigger = 0; move16(); - hIGFEnc->spec_be_igf_e = 0; + hIGFEnc->spec_be_igf_e = 0; move16(); - hIGFEnc->tns_predictionGain = 0; + hIGFEnc->tns_predictionGain = 0; move16(); - set32_fx(hIGFEnc->spec_be_igf, 0, N_MAX_TCX-IGF_START_MN); + set32_fx( hIGFEnc->spec_be_igf, 0, N_MAX_TCX - IGF_START_MN ); return; } #ifdef IVAS_CODE_BITSTREAM @@ -1243,25 +1240,25 @@ void IGFEncSetMode_fx( static void pack_bit( const int16_t bit, /* i : bit to be packed */ - uint8_t** pt, /* i/o: pointer to octet array into which bit will be placed */ - uint8_t* omask /* i/o: output mask to indicate where in the octet the bit is to be written */ + uint8_t **pt, /* i/o: pointer to octet array into which bit will be placed */ + uint8_t *omask /* i/o: output mask to indicate where in the octet the bit is to be written */ ) { - if (*omask == 0x80) + if ( *omask == 0x80 ) { **pt = 0; } - if (bit != 0) + if ( bit != 0 ) { **pt = **pt | *omask; } *omask >>= 1; - if (*omask == 0) + if ( *omask == 0 ) { *omask = 0x80; - (*pt)++; + ( *pt )++; } return; @@ -1280,9 +1277,9 @@ void IGFEncConcatenateBitstream_fx( { int16_t i; IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; - Indice* ind_list; - uint8_t* pFrame; /* byte array with bit packet and byte aligned coded speech data */ - int16_t* pFrame_size; /* number of bits in the binary encoded access unit [bits] */ + Indice *ind_list; + uint8_t *pFrame; /* byte array with bit packet and byte aligned coded speech data */ + int16_t *pFrame_size; /* number of bits in the binary encoded access unit [bits] */ int16_t k, nb_bits_written; int32_t imask; uint8_t omask; @@ -1294,21 +1291,21 @@ void IGFEncConcatenateBitstream_fx( pFrame_size = &hPrivateData->igfBitstreamBits; nb_bits_written = 0; - omask = (0x80 >> (*pFrame_size & 0x7)); + omask = ( 0x80 >> ( *pFrame_size & 0x7 ) ); pFrame += *pFrame_size >> 3; /* bitstream packing (conversion of individual indices into a serial stream) */ - for (i = 0; i < bsBits; i++) + for ( i = 0; i < bsBits; i++ ) { - if (ind_list[i].nb_bits > 0) + if ( ind_list[i].nb_bits > 0 ) { /* mask from MSB to LSB */ - imask = 1 << (ind_list[i].nb_bits - 1); + imask = 1 << ( ind_list[i].nb_bits - 1 ); /* write bit by bit */ - for (k = 0; k < ind_list[i].nb_bits; k++) + for ( k = 0; k < ind_list[i].nb_bits; k++ ) { - pack_bit(ind_list[i].value & imask, &pFrame, &omask); + pack_bit( ind_list[i].value & imask, &pFrame, &omask ); imask >>= 1; } nb_bits_written += ind_list[i].nb_bits; @@ -1327,15 +1324,15 @@ void IGFEncConcatenateBitstream_fx( return; } #else -/**********************************************************************/ /* -IGF bitsream concatenation for TCX10 modes -**************************************************************************/ -void IGFEncConcatenateBitstream_fx(const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ - Word16 bsBits, /**< in: Q0 | number of IGF bits written to list of indices */ - Word16 *next_ind, /**< in/out: | pointer to actual bit indice */ - Word16 *nb_bits, /**< in/out: | total number of bits already written */ - Indice *ind_list_fx /**< in: | pointer to list of indices */ - ) +/**********************************************************************/ /* + IGF bitsream concatenation for TCX10 modes + **************************************************************************/ +void IGFEncConcatenateBitstream_fx( const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ + Word16 bsBits, /**< in: Q0 | number of IGF bits written to list of indices */ + Word16 *next_ind, /**< in/out: | pointer to actual bit indice */ + Word16 *nb_bits, /**< in/out: | total number of bits already written */ + Indice *ind_list_fx /**< in: | pointer to list of indices */ +) { IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; @@ -1346,24 +1343,23 @@ void IGFEncConcatenateBitstream_fx(const IGF_ENC_INSTANCE_HANDLE hInstanc &ind_list_fx[*next_ind], bsBits, hPrivateData->igfBitstream, - &hPrivateData->igfBitstreamBits - ); + &hPrivateData->igfBitstreamBits ); - *nb_bits = sub(*nb_bits, bsBits); + *nb_bits = sub( *nb_bits, bsBits ); return; } #endif -/**********************************************************************/ /* -IGF reset bitsream bit counter for TCX10 modes -**************************************************************************/ -void IGFEncResetTCX10BitCounter_fx(const IGF_ENC_INSTANCE_HANDLE hInstance /**< in: | instance handle of IGF Encoder */ - ) +/**********************************************************************/ /* + IGF reset bitsream bit counter for TCX10 modes + **************************************************************************/ +void IGFEncResetTCX10BitCounter_fx( const IGF_ENC_INSTANCE_HANDLE hInstance /**< in: | instance handle of IGF Encoder */ +) { IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; - hPrivateData = &hInstance->igfData; - hPrivateData->igfBitstreamBits = 0; + hPrivateData = &hInstance->igfData; + hPrivateData->igfBitstreamBits = 0; move16(); hInstance->infoTotalBitsWritten = 0; move16(); @@ -1371,13 +1367,13 @@ void IGFEncResetTCX10BitCounter_fx(const IGF_ENC_INSTANCE_HANDLE hInstanc return; } -/**********************************************************************/ /* -IGF write concatenated bitsream for TCX10 modes -**************************************************************************/ -Word16 IGFEncWriteConcatenatedBitstream_fx( /**< out: Q0 | total number of bits written */ - const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ - BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle */ - ) +/**********************************************************************/ /* + IGF write concatenated bitsream for TCX10 modes + **************************************************************************/ +Word16 IGFEncWriteConcatenatedBitstream_fx( /**< out: Q0 | total number of bits written */ + const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ + BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle */ +) { IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; Word16 i; @@ -1386,18 +1382,18 @@ Word16 IGFEncWriteConcatenatedBitstream_fx( UWord8 *pBitstream; hPrivateData = &hInstance->igfData; - pBitstream = &hPrivateData->igfBitstream[0]; + pBitstream = &hPrivateData->igfBitstream[0]; - tmp = shr(hPrivateData->igfBitstreamBits, 3); - FOR (i = 0; i < tmp; i++) + tmp = shr( hPrivateData->igfBitstreamBits, 3 ); + FOR( i = 0; i < tmp; i++ ) { - push_next_indice_fx(hBstr, pBitstream[i], 8); + push_next_indice_fx( hBstr, pBitstream[i], 8 ); } - bitsLeft = s_and(hPrivateData->igfBitstreamBits, 0x7); - IF(bitsLeft > 0) + bitsLeft = s_and( hPrivateData->igfBitstreamBits, 0x7 ); + IF( bitsLeft > 0 ) { - push_next_indice_fx(hBstr, shr(pBitstream[i], sub(8, bitsLeft)), bitsLeft); + push_next_indice_fx( hBstr, shr( pBitstream[i], sub( 8, bitsLeft ) ), bitsLeft ); } return hInstance->infoTotalBitsWritten; @@ -1406,68 +1402,65 @@ Word16 IGFEncWriteConcatenatedBitstream_fx( /**********************************************************************/ /* apply the IGF encoder, main encoder interface **************************************************************************/ -void IGFEncApplyMono_fx(const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ - const Word16 igfGridIdx, /**< in: Q0 | IGF grid index */ - Encoder_State *st, /**< in: | Encoder state */ - Word32 *pMDCTSpectrum, /**< in: Q31 | MDCT spectrum */ - Word16 MDCTSpectrum_e, /**< in: | exponent of MDCT spectrum */ - Word32 *pPowerSpectrum, /**< in: Q31 | MDCT^2 + MDST^2 spectrum, or estimate */ - Word16 PowerSpectrum_e, /**< in: | exponent of pPowerSpectrum */ - Word16 isTCX20, /**< in: Q0 | flag indicating if the input is TCX20 or TCX10/2xTCX5 */ - Word16 isTNSActive, /**< in: Q0 | flag indicating if the TNS is active */ - Word16 last_core_acelp /**< in: Q0 | indicator if last frame was acelp coded */ - ) +void IGFEncApplyMono_fx( const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ + const Word16 igfGridIdx, /**< in: Q0 | IGF grid index */ + Encoder_State *st, /**< in: | Encoder state */ + Word32 *pMDCTSpectrum, /**< in: Q31 | MDCT spectrum */ + Word16 MDCTSpectrum_e, /**< in: | exponent of MDCT spectrum */ + Word32 *pPowerSpectrum, /**< in: Q31 | MDCT^2 + MDST^2 spectrum, or estimate */ + Word16 PowerSpectrum_e, /**< in: | exponent of pPowerSpectrum */ + Word16 isTCX20, /**< in: Q0 | flag indicating if the input is TCX20 or TCX10/2xTCX5 */ + Word16 isTNSActive, /**< in: Q0 | flag indicating if the TNS is active */ + Word16 last_core_acelp /**< in: Q0 | indicator if last frame was acelp coded */ +) { - Word32 *pPowerSpectrumParameter; /* If it is NULL it informs a function that specific handling is needed */ - Word32 *pPowerSpectrumParameterWhitening; /* If it is NULL it informs a function that specific handling is needed */ - Word16 highPassEner_exp; /*exponent of highpass energy - maybe not needed*/ + Word32 *pPowerSpectrumParameter; /* If it is NULL it informs a function that specific handling is needed */ + Word32 *pPowerSpectrumParameterWhitening; /* If it is NULL it informs a function that specific handling is needed */ + Word16 highPassEner_exp; /*exponent of highpass energy - maybe not needed*/ pPowerSpectrumParameter = NULL; test(); - if ((isTNSActive == 0) && (isTCX20 != 0)) + if ( ( isTNSActive == 0 ) && ( isTCX20 != 0 ) ) { pPowerSpectrumParameter = pPowerSpectrum; } pPowerSpectrumParameterWhitening = NULL; - if (isTCX20 != 0) + if ( isTCX20 != 0 ) { pPowerSpectrumParameterWhitening = pPowerSpectrum; } - IGF_UpdateInfo(hInstance, /* i: instance handle of IGF Encoder */ - igfGridIdx); /* i: IGF grid index */ + IGF_UpdateInfo( hInstance, /* i: instance handle of IGF Encoder */ + igfGridIdx ); /* i: IGF grid index */ - IGF_CalculateEnvelope(hInstance, /* i: instance handle of IGF Encoder */ - pMDCTSpectrum, /* i: MDCT spectrum */ - MDCTSpectrum_e, /* i: exponent of MDCT spectrum */ - pPowerSpectrumParameter, /* i: MDCT^2 + MDST^2 spectrum, or estimate */ - PowerSpectrum_e, /* i: exponent of pPowerSpectrum */ - igfGridIdx /* i: IGF grid index */ - ); + IGF_CalculateEnvelope( hInstance, /* i: instance handle of IGF Encoder */ + pMDCTSpectrum, /* i: MDCT spectrum */ + MDCTSpectrum_e, /* i: exponent of MDCT spectrum */ + pPowerSpectrumParameter, /* i: MDCT^2 + MDST^2 spectrum, or estimate */ + PowerSpectrum_e, /* i: exponent of pPowerSpectrum */ + igfGridIdx /* i: IGF grid index */ + ); - IGF_Whitening(hInstance, /* i: instance handle of IGF Encoder */ - pPowerSpectrumParameterWhitening, /* i: MDCT^2 + MDST^2 spectrum, or estimate */ - PowerSpectrum_e, /* i: exponent of powerSpectrum */ - igfGridIdx, /* i: IGF grid index */ - (st->transientDetection.transientDetector.bIsAttackPresent == 1), - last_core_acelp); /* i: last frame was acelp indicator */ + IGF_Whitening( hInstance, /* i: instance handle of IGF Encoder */ + pPowerSpectrumParameterWhitening, /* i: MDCT^2 + MDST^2 spectrum, or estimate */ + PowerSpectrum_e, /* i: exponent of powerSpectrum */ + igfGridIdx, /* i: IGF grid index */ + ( st->transientDetection.transientDetector.bIsAttackPresent == 1 ), + last_core_acelp ); /* i: last frame was acelp indicator */ pPowerSpectrumParameter = NULL; - if (isTCX20 != 0) + if ( isTCX20 != 0 ) { pPowerSpectrumParameter = pPowerSpectrum; } - IGF_ErodeSpectrum( /* o: highpass energy */ - &highPassEner_exp, /* o: exponent of highPassEner */ - hInstance, /* i: instance handle of IGF Encoder */ - pMDCTSpectrum, /* i: MDCT spectrum */ - pPowerSpectrumParameter, /* i: MDCT^2 + MDST^2 spectrum, or estimate */ - PowerSpectrum_e, /* i: exponent of pPowerSpectrum */ - igfGridIdx); /* i: IGF grid index */ - + IGF_ErodeSpectrum( /* o: highpass energy */ + &highPassEner_exp, /* o: exponent of highPassEner */ + hInstance, /* i: instance handle of IGF Encoder */ + pMDCTSpectrum, /* i: MDCT spectrum */ + pPowerSpectrumParameter, /* i: MDCT^2 + MDST^2 spectrum, or estimate */ + PowerSpectrum_e, /* i: exponent of pPowerSpectrum */ + igfGridIdx ); /* i: IGF grid index */ } - - diff --git a/lib_enc/igf_scf_enc_fx.c b/lib_enc/igf_scf_enc_fx.c index 866bae043..b5a74687a 100644 --- a/lib_enc/igf_scf_enc_fx.c +++ b/lib_enc/igf_scf_enc_fx.c @@ -9,9 +9,9 @@ #include "stat_enc.h" #include "stat_com.h" #include "basop_util.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /**********************************************************************/ /** @@ -28,38 +28,39 @@ void IGFSCFEncoderOpen_fx( { - hPublicData->ptrBitIndex = 0; + hPublicData->ptrBitIndex = 0; move16(); - hPublicData->bitCount = 0; + hPublicData->bitCount = 0; move16(); - hPublicData->Tsave = 0; + hPublicData->Tsave = 0; move16(); - hPublicData->contex_saved = 0; + hPublicData->contex_saved = 0; move16(); - hPublicData->acState.low = 0; + hPublicData->acState.low = 0; move32(); - hPublicData->acState.high = 0; + hPublicData->acState.high = 0; move32(); - hPublicData->acState.value = 0; + hPublicData->acState.value = 0; move16(); - set16_fx(hPublicData->prev, 0, 64); - set16_fx(hPublicData->prevSave, 0, 64); + set16_fx( hPublicData->prev, 0, 64 ); + set16_fx( hPublicData->prevSave, 0, 64 ); hPublicData->scfCountLongBlock[0] = hIgfInfo->grid[0].swb_offset_len - 1; hPublicData->scfCountLongBlock[1] = hIgfInfo->grid[1].swb_offset_len - 1; hPublicData->scfCountLongBlock[2] = hIgfInfo->grid[2].swb_offset_len - 1; - move16();move16();move16(); + move16(); + move16(); + move16(); - hPublicData->t = 0; + hPublicData->t = 0; move16(); /* protect against the invalid request of starting encoding with a dependent block */ - IGFCommonFuncsIGFGetCFTables(total_brate, bwidth, element_mode, rf_mode, &hPublicData->cf_se00, &hPublicData->cf_se01, &hPublicData->cf_off_se01, &hPublicData->cf_se02, &hPublicData->cf_off_se02, &hPublicData->cf_se10, &hPublicData->cf_off_se10, &hPublicData->cf_se11, &hPublicData->cf_off_se11); - + IGFCommonFuncsIGFGetCFTables( total_brate, bwidth, element_mode, rf_mode, &hPublicData->cf_se00, &hPublicData->cf_se01, &hPublicData->cf_off_se01, &hPublicData->cf_se02, &hPublicData->cf_off_se02, &hPublicData->cf_se10, &hPublicData->cf_off_se10, &hPublicData->cf_se11, &hPublicData->cf_off_se11 ); } static Word16 quant_ctx( - Word16 ctx /* i: the context value to be quantized */ + Word16 ctx /* i: the context value to be quantized */ ) { /* @@ -69,46 +70,43 @@ static Word16 quant_ctx( Word16 result; - result = s_min(abs_s(ctx), IGF_CTX_OFFSET); /* limit the absolute value to IGF_CTX_OFFSET */ - if (ctx < 0) /* add the sign back, if needed */ + result = s_min( abs_s( ctx ), IGF_CTX_OFFSET ); /* limit the absolute value to IGF_CTX_OFFSET */ + if ( ctx < 0 ) /* add the sign back, if needed */ { - result = negate(result); + result = negate( result ); } return result; } - static void arith_encode_bits( - IGFSCFENC_INSTANCE_HANDLE hPrivateData, /* i/o: instance handle */ - Word16 *ptr, /* i/o: pointer to expanded bit buffer, one bit in each Word16 */ - Word16 x, /* i: value to encode */ - Word16 nBits /* i: number of bits to encode */ + IGFSCFENC_INSTANCE_HANDLE hPrivateData, /* i/o: instance handle */ + Word16 *ptr, /* i/o: pointer to expanded bit buffer, one bit in each Word16 */ + Word16 x, /* i: value to encode */ + Word16 nBits /* i: number of bits to encode */ ) { Word16 i; Word16 bit; - FOR (i = nBits - 1; i >= 0; --i) /* nBits > 0 */ + FOR( i = nBits - 1; i >= 0; --i ) /* nBits > 0 */ { - bit = s_and(shr(x, i), 1); - hPrivateData->ptrBitIndex = ari_encode_14bits_sign_fx(ptr, - hPrivateData->ptrBitIndex, - 32767, /* disable the bit count limitation */ - &hPrivateData->acState_fx, - bit - ); + bit = s_and( shr( x, i ), 1 ); + hPrivateData->ptrBitIndex = ari_encode_14bits_sign_fx( ptr, + hPrivateData->ptrBitIndex, + 32767, /* disable the bit count limitation */ + &hPrivateData->acState_fx, + bit ); } - } static void arith_encode_residual( IGFSCFENC_INSTANCE_HANDLE hPrivateData, /* i/o: instance handle */ Word16 *ptr, /* i/o: pointer to expanded bit buffer, one bit in each Word16 */ Word16 x, /* i: residual value to encode */ - const UWord16 *cumulativeFrequencyTable, /* i: cumulative frequency table to be used */ + const UWord16 *cumulativeFrequencyTable, /* i: cumulative frequency table to be used */ Word16 tableOffset /* i: offset used to align the table */ ) { @@ -117,80 +115,77 @@ static void arith_encode_residual( Word16 extra_safety; - x = add(x, tableOffset); + x = add( x, tableOffset ); test(); - IF ((GE_16(x, IGF_MIN_ENC_SEPARATE))&&(LE_16(x,IGF_MAX_ENC_SEPARATE))) + IF( ( GE_16( x, IGF_MIN_ENC_SEPARATE ) ) && ( LE_16( x, IGF_MAX_ENC_SEPARATE ) ) ) { - x = sub(x, IGF_MIN_ENC_SEPARATE - 1); /* (x - IGF_MIN_ENC_SEPARATE) + 1 */ + x = sub( x, IGF_MIN_ENC_SEPARATE - 1 ); /* (x - IGF_MIN_ENC_SEPARATE) + 1 */ /* encode one of the IGF_SYMBOLS_IN_TABLE == 27 alphabet symbols using the new raw AC function */ - hPrivateData->ptrBitIndex = ari_encode_14bits_ext_fx(ptr, - hPrivateData->ptrBitIndex, - &hPrivateData->acState_fx, - x, - cumulativeFrequencyTable - ); + hPrivateData->ptrBitIndex = ari_encode_14bits_ext_fx( ptr, + hPrivateData->ptrBitIndex, + &hPrivateData->acState_fx, + x, + cumulativeFrequencyTable ); return; } - IF (LT_16(x, IGF_MIN_ENC_SEPARATE)) + IF( LT_16( x, IGF_MIN_ENC_SEPARATE ) ) { /* send escape code 0 to indicate x <= IGF_MIN_ENC_SEPARATE - 1 */ - extra = sub(IGF_MIN_ENC_SEPARATE - 1, x); - hPrivateData->ptrBitIndex = ari_encode_14bits_ext_fx(ptr, - hPrivateData->ptrBitIndex, - &hPrivateData->acState_fx, - 0, - cumulativeFrequencyTable - ); + extra = sub( IGF_MIN_ENC_SEPARATE - 1, x ); + hPrivateData->ptrBitIndex = ari_encode_14bits_ext_fx( ptr, + hPrivateData->ptrBitIndex, + &hPrivateData->acState_fx, + 0, + cumulativeFrequencyTable ); } - ELSE /* x > IGF_MAX_ENC_SEPARATE */ + ELSE /* x > IGF_MAX_ENC_SEPARATE */ { /* send escape code (IGF_SYMBOLS_IN_TABLE - 1) to indicate x >= IGF_MAX_ENC_SEPARATE + 1 */ - extra = sub(x, IGF_MAX_ENC_SEPARATE + 1); - hPrivateData->ptrBitIndex = ari_encode_14bits_ext_fx(ptr, - hPrivateData->ptrBitIndex, - &hPrivateData->acState_fx, - IGF_SYMBOLS_IN_TABLE - 1, - cumulativeFrequencyTable - ); + extra = sub( x, IGF_MAX_ENC_SEPARATE + 1 ); + hPrivateData->ptrBitIndex = ari_encode_14bits_ext_fx( ptr, + hPrivateData->ptrBitIndex, + &hPrivateData->acState_fx, + IGF_SYMBOLS_IN_TABLE - 1, + cumulativeFrequencyTable ); } /* encode one of the tails of the distribution */ - extra_tmp = sub(extra, 15); - IF (extra_tmp < 0) + extra_tmp = sub( extra, 15 ); + IF( extra_tmp < 0 ) { /* encode extra with 4 bits if extra < 15 */ - arith_encode_bits(hPrivateData, ptr, extra, 4); + arith_encode_bits( hPrivateData, ptr, extra, 4 ); } - ELSE /* extra >= 15 */ + ELSE /* extra >= 15 */ { /* send escape code 15 to indicate extra >= 15 */ - arith_encode_bits(hPrivateData, ptr, 15, 4); + arith_encode_bits( hPrivateData, ptr, 15, 4 ); - extra_safety = sub(extra_tmp, 63); - IF (extra_safety < 0) + extra_safety = sub( extra_tmp, 63 ); + IF( extra_safety < 0 ) { /* encode additional extra with 6 bits */ - arith_encode_bits(hPrivateData, ptr, extra_tmp, 6); + arith_encode_bits( hPrivateData, ptr, extra_tmp, 6 ); } - ELSE { /* extra_tmp >= 63 */ + ELSE + { /* extra_tmp >= 63 */ /* encode safety extra with 7 bits */ - arith_encode_bits(hPrivateData, ptr, extra_safety, 7); + arith_encode_bits( hPrivateData, ptr, extra_safety, 7 ); } } - } static void encode_sfe_vector( IGFSCFENC_INSTANCE_HANDLE hPrivateData, /* i/o: instance handle */ - Word16 * ptr, /* i : pointer to expanded bit buffer, one bit in each short */ - const Word16 t, /* i : frame counter reset to 0 at each independent frame */ - Word16* prev_x, /* i : previous vector */ - Word16* x, /* i : current vector to encode */ - const Word16 length /* i : number of elements to encode */ + Word16 *ptr, /* i : pointer to expanded bit buffer, one bit in each short */ + const Word16 t, /* i : frame counter reset to 0 at each independent frame */ + Word16 *prev_x, /* i : previous vector */ + Word16 *x, /* i : current vector to encode */ + const Word16 length /* i : number of elements to encode */ ) { /* @@ -211,92 +206,89 @@ static void encode_sfe_vector( Word32 index2; - - FOR (f = 0; f < length; ++f) + FOR( f = 0; f < length; ++f ) { - IF (t == 0) + IF( t == 0 ) { - IF (f == 0) + IF( f == 0 ) { /* (t == 0) && (f == 0) */ /* encode one of the IGF_SYMBOLS_IN_TABLE == 27 alphabet symbols using the new raw AC function */ - hPrivateData->ptrBitIndex = ari_encode_14bits_ext_fx(ptr, - hPrivateData->ptrBitIndex, - &hPrivateData->acState_fx, - shr(x[f], 2), - (const UWord16*) hPrivateData->cf_se00 - ); - arith_encode_bits(hPrivateData, ptr, s_and(x[f], 3), 2); /* LSBs as 2 bit raw */ + hPrivateData->ptrBitIndex = ari_encode_14bits_ext_fx( ptr, + hPrivateData->ptrBitIndex, + &hPrivateData->acState_fx, + shr( x[f], 2 ), + (const UWord16 *) hPrivateData->cf_se00 ); + arith_encode_bits( hPrivateData, ptr, s_and( x[f], 3 ), 2 ); /* LSBs as 2 bit raw */ } - ELSE IF (EQ_16(f, 1)) + ELSE IF( EQ_16( f, 1 ) ) { /* (t == 0) && (f == 1) */ - res = sub(x[f], x[0]); /* pred = b */ - arith_encode_residual(hPrivateData, - ptr, - res, - hPrivateData->cf_se01, - hPrivateData->cf_off_se01); + res = sub( x[f], x[0] ); /* pred = b */ + arith_encode_residual( hPrivateData, + ptr, + res, + hPrivateData->cf_se01, + hPrivateData->cf_off_se01 ); } ELSE { /* (t == 0) && (f >= 2) */ - prev_offset = sub(f, 1); - res = sub(x[f], x[prev_offset]); - move16(); /* pred = b */ - ctx = quant_ctx(sub(x[prev_offset], x[sub(prev_offset, 1)])); /* Q(b - e) */ + prev_offset = sub( f, 1 ); + res = sub( x[f], x[prev_offset] ); + move16(); /* pred = b */ + ctx = quant_ctx( sub( x[prev_offset], x[sub( prev_offset, 1 )] ) ); /* Q(b - e) */ /* index1 is (IGF_SYMBOLS_IN_TABLE + 1) * (CTX_OFFSET + ctx) */ - index1 = L_mac0((IGF_SYMBOLS_IN_TABLE + 1) * IGF_CTX_OFFSET, (IGF_SYMBOLS_IN_TABLE + 1), ctx); + index1 = L_mac0( ( IGF_SYMBOLS_IN_TABLE + 1 ) * IGF_CTX_OFFSET, ( IGF_SYMBOLS_IN_TABLE + 1 ), ctx ); /* index2 is IGF_CTX_OFFSET + ctx */ - index2 = L_mac0(IGF_CTX_OFFSET, 1, ctx); - arith_encode_residual(hPrivateData, - ptr, - res, - hPrivateData->cf_se02 + index1, - hPrivateData->cf_off_se02[index2]); + index2 = L_mac0( IGF_CTX_OFFSET, 1, ctx ); + arith_encode_residual( hPrivateData, + ptr, + res, + hPrivateData->cf_se02 + index1, + hPrivateData->cf_off_se02[index2] ); } } ELSE { /* t == 1 */ - IF (f == 0) + IF( f == 0 ) { /* (t == 1) && (f == 0) */ - res = sub(x[f], prev_x[f]); + res = sub( x[f], prev_x[f] ); move16(); /* pred = a */ - arith_encode_residual(hPrivateData, - ptr, - res, - hPrivateData->cf_se10, - hPrivateData->cf_off_se10); + arith_encode_residual( hPrivateData, + ptr, + res, + hPrivateData->cf_se10, + hPrivateData->cf_off_se10 ); } ELSE { /* (t == 1) && (f >= 1) */ - prev_offset = sub(f, 1); - pred = add(prev_x[f], x[prev_offset]); - pred = sub(pred, prev_x[prev_offset]); /* pred = a + b - c */ - res = sub(x[f], pred); - ctx_f = quant_ctx(sub(prev_x[f], prev_x[prev_offset])); /* Q(a - c) */ - ctx_t = quant_ctx(sub(x[prev_offset], prev_x[prev_offset])); /* Q(b - c) */ + prev_offset = sub( f, 1 ); + pred = add( prev_x[f], x[prev_offset] ); + pred = sub( pred, prev_x[prev_offset] ); /* pred = a + b - c */ + res = sub( x[f], pred ); + ctx_f = quant_ctx( sub( prev_x[f], prev_x[prev_offset] ) ); /* Q(a - c) */ + ctx_t = quant_ctx( sub( x[prev_offset], prev_x[prev_offset] ) ); /* Q(b - c) */ /* index1 is (IGF_SYMBOLS_IN_TABLE + 1) * IGF_CTX_COUNT * (IGF_CTX_OFFSET + ctx_t) + (IGF_SYMBOLS_IN_TABLE + 1) * (IGF_CTX_OFFSET + ctx_f) */ index1 = L_mac0( - ((IGF_SYMBOLS_IN_TABLE + 1) * IGF_CTX_COUNT + (IGF_SYMBOLS_IN_TABLE + 1)) * IGF_CTX_OFFSET, - (IGF_SYMBOLS_IN_TABLE + 1) * IGF_CTX_COUNT, ctx_t); - index1 = L_mac0(index1, (IGF_SYMBOLS_IN_TABLE + 1), ctx_f); + ( ( IGF_SYMBOLS_IN_TABLE + 1 ) * IGF_CTX_COUNT + ( IGF_SYMBOLS_IN_TABLE + 1 ) ) * IGF_CTX_OFFSET, + ( IGF_SYMBOLS_IN_TABLE + 1 ) * IGF_CTX_COUNT, ctx_t ); + index1 = L_mac0( index1, ( IGF_SYMBOLS_IN_TABLE + 1 ), ctx_f ); /* index2 is IGF_CTX_COUNT * (IGF_CTX_OFFSET + ctx_t) + (IGF_CTX_OFFSET + ctx_f) */ - index2 = L_mac0((IGF_CTX_COUNT + 1) * IGF_CTX_OFFSET, IGF_CTX_COUNT, ctx_t); - index2 = L_mac0(index2, 1, ctx_f); - arith_encode_residual(hPrivateData, - ptr, - res, - hPrivateData->cf_se11 + index1, - hPrivateData->cf_off_se11[index2]); + index2 = L_mac0( ( IGF_CTX_COUNT + 1 ) * IGF_CTX_OFFSET, IGF_CTX_COUNT, ctx_t ); + index2 = L_mac0( index2, 1, ctx_f ); + arith_encode_residual( hPrivateData, + ptr, + res, + hPrivateData->cf_se11 + index1, + hPrivateData->cf_off_se11[index2] ); } } } - } @@ -304,7 +296,7 @@ static void encode_sfe_vector( resets the internal encoder memory (context memory) **************************************************************************/ void IGFSCFEncoderReset_fx( - IGFSCFENC_INSTANCE_HANDLE hPublicData /* i/o: handle to public data */ + IGFSCFENC_INSTANCE_HANDLE hPublicData /* i/o: handle to public data */ ) { @@ -313,7 +305,6 @@ void IGFSCFEncoderReset_fx( hPublicData->t = 0; move16(); /* indicate that an independent block follows */ /* we do not need to fill hPublicData->prev with zeros, because when t = 0 no previous information is used */ - } /**********************************************************************/ /** @@ -322,51 +313,49 @@ main encoder function Word16 IGFSCFEncoderEncode_fx( IGFSCFENC_INSTANCE_HANDLE hPublicData, /* i : handle to public data or NULL in case there was no instance created */ BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 bitCount, /* i : offset to the first bit in bitbuffer which should be readed by iisArithDecoderDecode function */ - Word16* sfe, /* i : ptr to an array which contain quantized scalefactor energies */ - const Word16 igfGridIdx, /* i : igf grid index see declaration of IGF_GRID_IDX for details */ - const Word16 indepFlag /* i : if 1 frame is independent, 0 = frame is coded with data from previous frame */ + const Word16 bitCount, /* i : offset to the first bit in bitbuffer which should be readed by iisArithDecoderDecode function */ + Word16 *sfe, /* i : ptr to an array which contain quantized scalefactor energies */ + const Word16 igfGridIdx, /* i : igf grid index see declaration of IGF_GRID_IDX for details */ + const Word16 indepFlag /* i : if 1 frame is independent, 0 = frame is coded with data from previous frame */ ) { Word16 ptr[IGF_BITBUFSIZE]; /* temporary expanded bit buffer, one bit in each Word16 */ Word16 i; - /* insert data: */ hPublicData->ptrBitIndex = 0; move16(); hPublicData->bitCount = bitCount; move16(); - ari_start_encoding_14bits_fx(&hPublicData->acState_fx); /* start AC encoding */ + ari_start_encoding_14bits_fx( &hPublicData->acState_fx ); /* start AC encoding */ /* check if coder needs a reset and do it if necessary */ - IF (indepFlag != 0) + IF( indepFlag != 0 ) { /* reset of coder */ - IGFSCFEncoderReset_fx(hPublicData); + IGFSCFEncoderReset_fx( hPublicData ); } - encode_sfe_vector(hPublicData, ptr, hPublicData->t, hPublicData->prev, sfe, hPublicData->scfCountLongBlock[igfGridIdx]); + encode_sfe_vector( hPublicData, ptr, hPublicData->t, hPublicData->prev, sfe, hPublicData->scfCountLongBlock[igfGridIdx] ); - hPublicData->ptrBitIndex = ari_done_encoding_14bits_fx(ptr, - hPublicData->ptrBitIndex, - &hPublicData->acState_fx - ); /* finish AC encoding */ - hPublicData->bitCount = add(hPublicData->bitCount, hPublicData->ptrBitIndex); + hPublicData->ptrBitIndex = ari_done_encoding_14bits_fx( ptr, + hPublicData->ptrBitIndex, + &hPublicData->acState_fx ); /* finish AC encoding */ + hPublicData->bitCount = add( hPublicData->bitCount, hPublicData->ptrBitIndex ); /* advance history */ - Copy(sfe, hPublicData->prev, hPublicData->scfCountLongBlock[igfGridIdx]); - hPublicData->t = add(hPublicData->t, 1); + Copy( sfe, hPublicData->prev, hPublicData->scfCountLongBlock[igfGridIdx] ); + hPublicData->t = add( hPublicData->t, 1 ); /* copy the bits from the temporary bit buffer, if doRealEncoding is enabled */ - IF (hBstr) + IF( hBstr ) { - FOR (i = 0; i < hPublicData->ptrBitIndex; ++i) + FOR( i = 0; i < hPublicData->ptrBitIndex; ++i ) { - push_next_indice_fx(hBstr, ptr[i], 1); + push_next_indice_fx( hBstr, ptr[i], 1 ); } } @@ -378,21 +367,21 @@ Word16 IGFSCFEncoderEncode_fx( for a closed loop encoder, the SCF encoder needs to memorize the context **************************************************************************/ void IGFSCFEncoderSaveContextState_fx( - IGFSCFENC_INSTANCE_HANDLE hPublicData, /* i/o: handle to public data */ - const Word16 igfGridIdx /* i : igf grid index see declaration of IGF_GRID_IDX for details */ + IGFSCFENC_INSTANCE_HANDLE hPublicData, /* i/o: handle to public data */ + const Word16 igfGridIdx /* i : igf grid index see declaration of IGF_GRID_IDX for details */ ) { hPublicData->Tsave = hPublicData->t; move16(); - Copy(hPublicData->prev, hPublicData->prevSave, hPublicData->scfCountLongBlock[igfGridIdx]); + Copy( hPublicData->prev, hPublicData->prevSave, hPublicData->scfCountLongBlock[igfGridIdx] ); } /**********************************************************************/ /** for a closed loop encoder, the SCF encoder needs to memorize the context **************************************************************************/ void IGFSCFEncoderRestoreContextState_fx( - IGFSCFENC_INSTANCE_HANDLE hPublicData, /* i/o: handle to public data */ - const Word16 igfGridIdx /* i : igf grid index see declaration of IGF_GRID_IDX for details */ + IGFSCFENC_INSTANCE_HANDLE hPublicData, /* i/o: handle to public data */ + const Word16 igfGridIdx /* i : igf grid index see declaration of IGF_GRID_IDX for details */ ) { @@ -400,7 +389,5 @@ void IGFSCFEncoderRestoreContextState_fx( hPublicData->t = hPublicData->Tsave; move16(); - Copy(hPublicData->prevSave, hPublicData->prev, hPublicData->scfCountLongBlock[igfGridIdx]); - - + Copy( hPublicData->prevSave, hPublicData->prev, hPublicData->scfCountLongBlock[igfGridIdx] ); } diff --git a/lib_enc/init_enc.c b/lib_enc/init_enc.c index a5ac653ee..c76392ff9 100644 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -840,7 +840,7 @@ ivas_error init_encoder( return error; } - initFdCngEnc( st->hFdCngEnc, st->input_Fs, st->cldfbAnaEnc->scale_flt); + initFdCngEnc( st->hFdCngEnc, st->input_Fs, st->cldfbAnaEnc->scale_flt ); /* initialization for IVAS modes happens in first frame pre-processing */ if ( st->element_mode == EVS_MONO ) @@ -884,839 +884,839 @@ ivas_error init_encoder( } #ifdef IVAS_FLOAT_FIXED ivas_error init_encoder_ivas_fx( - Encoder_State *st, /* i/o: state structure */ - Encoder_Struct *st_ivas, /* i/o: encoder state structure */ - const Word16 idchan, /* i : channel ID */ - const Word16 var_SID_rate_flag, /* i : flag for variable SID update rate */ - const Word16 interval_SID, /* i : interval for SID update */ - const Word16 vad_only_flag, /* i : flag to indicate front-VAD structure */ - const ISM_MODE ism_mode, /* i : ISM mode */ - const Word32 element_brate /* i : element bitrate */ + Encoder_State *st, /* i/o: state structure */ + Encoder_Struct *st_ivas, /* i/o: encoder state structure */ + const Word16 idchan, /* i : channel ID */ + const Word16 var_SID_rate_flag, /* i : flag for variable SID update rate */ + const Word16 interval_SID, /* i : interval for SID update */ + const Word16 vad_only_flag, /* i : flag to indicate front-VAD structure */ + const ISM_MODE ism_mode, /* i : ISM mode */ + const Word32 element_brate /* i : element bitrate */ ) { - Word16 i; - ivas_error error; - Word32 igf_brate; - - error = IVAS_ERR_OK; - - /*-----------------------------------------------------------------* - * General parameters - *-----------------------------------------------------------------*/ - - IF (st->Opt_AMR_WB) - { - st->last_core = AMR_WB_CORE; - } - ELSE - { - st->last_core = -1; - } - - st->L_frame = L_FRAME; - st->last_coder_type = GENERIC; - st->coder_type = GENERIC; - st->last_total_brate = st->total_brate; - st->last_bits_frame_nominal = -1; - st->last_total_brate_cng = -1; - st->last_core_brate = st->total_brate; - st->dtx_sce_sba = 0; - st->extl = -1; - st->last_extl = -1; - st->last_L_frame = L_FRAME; - st->rate_switching_reset = 0; - st->rate_switching_reset_16kHz = 0; - st->clas = UNVOICED_CLAS; - st->low_rate_mode = 0; - st->ini_frame = 0; - st->inactive_coder_type_flag = 0; - st->sba_br_sw_while_no_data = 0; - - st->coder_type_raw = VOICED; - st->last_coder_type_raw = st->coder_type_raw; - - st->flag_ACELP16k = set_ACELP_flag_IVAS(st->element_mode, st->total_brate, st->total_brate, idchan, 0, -1, -1); - - st->is_ism_format = 0; - IF (ism_mode != ISM_MODE_NONE) - { - st->is_ism_format = 1; - } - - /*-----------------------------------------------------------------* - * Bitstream - *-----------------------------------------------------------------*/ - - IF (!vad_only_flag) - { - IF ((st->hBstr = (BSTR_ENC_HANDLE)malloc(sizeof(BSTR_ENC_DATA))) == NULL) - { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Bitstream structure\n")); - } - - /* set pointer to the buffer of indices */ - st->hBstr->ind_list = st_ivas->ind_list; - st->hBstr->ivas_ind_list_zero = &st_ivas->ind_list; - st->hBstr->ivas_max_num_indices = &st_ivas->ivas_max_num_indices; - st->hBstr->nb_ind_tot = 0; - st->hBstr->nb_bits_tot = 0; - st->hBstr->st_ivas = st_ivas; - } - ELSE - { - st->hBstr = NULL; - } - - /*-----------------------------------------------------------------* - * Pre-processing and ACELP core parameters - *-----------------------------------------------------------------*/ - - Copy(GEWB_Ave_fx, st->mem_AR_fx, M); - Copy(GEWB_Ave_fx, st->lsfoldbfi0_fx, M); - Copy(GEWB_Ave_fx, st->lsfoldbfi1_fx, M); - Copy(GEWB_Ave_fx, st->lsf_adaptive_mean_fx, M); - - st->next_force_safety_net = 0; - - st->pstreaklen = 0; - st->streaklimit_fx = MAX_WORD16; - set16_fx(st->mem_MA_fx, 0, M); - - init_gp_clip_fx(st->clip_var_fx); - pitch_ol_init_fx(&st->old_thres_fx, &st->old_pitch, &st->delta_pit, &st->old_corr_fx); - set16_fx(st->old_wsp_fx, 0, L_WSP_MEM); - set16_fx(st->old_wsp2_fx, 0, (L_WSP_MEM - L_INTERPOL) / OPL_DECIM); //Needs to change depending on usage. - - st->mem_preemph_fx = 0; - st->mem_preemph16k_fx = 0; - st->mem_preemph_enc = 0; - - /* AVQ pre-quantizer memory */ - st->mem_preemp_preQ_fx = 0; - st->mem_deemp_preQ_fx = 0; - st->last_nq_preQ = 0; - st->last_code_preq = 0; - st->use_acelp_preq = 0; - st->last_harm_flag_acelp = 0; - - /* (Decimated) Weighted Speech Memory */ - st->mem_wsp_enc = 0; - st->mem_wsp_fx = 0; - - set16_fx(st->mem_decim2_fx, 0, 3); - set32_fx(st->Bin_E_fx, 0, L_FFT); - - st->ee_old_fx = 640;/*chk //10 in Q6 */ - st->Nb_ACELP_frames = 0; - st->audio_frame_cnt = AUDIO_COUNTER_INI; /* Initialization of the audio frame counter mildly into the audio mode */ - - /* adaptive lag window memory */ - st->old_pitch_la = 0; - - IF (EQ_32(st->input_Fs, 8000)) - { - st->min_band = 1; - st->max_band = 16; - } - ELSE - { - st->min_band = 0; - st->max_band = 19; - } - - IF (st->Opt_AMR_WB) - { - Copy(mean_isf_amr_wb_fx, st->lsf_old_fx, M); - E_LPC_isf_isp_conversion(st->lsf_old_fx, st->lsp_old1_fx, M); - } - ELSE - { - Copy(GEWB_Ave_fx, st->lsf_old_fx, M); - lsf2lsp_fx(st->lsf_old_fx, st->lsp_old1_fx, M, INT_FS_12k8); - } - - Copy(st->lsf_old_fx, st->lsf_old1_fx, M); - Copy(st->lsp_old1_fx, st->lsp_old_fx, M); - Copy(st->lsp_old_fx, st->lsp_old16k_fx, M); - Copy(st->lsp_old_fx, st->lspold_enc_fx, M); - - st->stab_fac_fx = 0; - - /* Bass post-filter memories - encoder side of MODE2 */ - st->bpf_off = 0; - st->pst_mem_deemp_err_fx = 0; - st->pst_lp_ener_fx = 0; - - /* TC coder type */ - st->tc_cnt = 0; - - /* find_uv() parameters */ - st->old_dE1_fx = 0; - st->old_ind_deltaMax = 0; - set32_fx(st->old_enr_ssf_fx, 0, shl(NB_SSF, 1)); - st->spike_hyst = -1; - - /* stereo switching memories */ - st->mem_preemph_DFT_fx = 0; - set32_fx(st->inp_12k8_mem_stereo_sw_fx, 0, sub(sub(STEREO_DFT_OVL_12k8, L_MEM_RECALC_12K8), L_FILT)); - st->mem_preemph16k_DFT_fx = 0; - set32_fx(st->inp_16k_mem_stereo_sw_fx, 0, sub(sub(STEREO_DFT_OVL_16k, L_MEM_RECALC_16K), L_FILT16k)); - - st->sharpFlag = 0; - - /* Stationary noise UV modification */ - st->ge_sm_fx = 10;/*chk //10 in Q6 */ - st->uv_count = 0; - st->act_count = 3; - Copy(st->lsp_old_fx, st->lspold_s_fx, M); - st->noimix_seed = RANDOM_INITSEED; - st->min_alpha_fx = 1; - st->exc_pe = 0; - - /* FEC */ - st->last_clas = UNVOICED_CLAS; - st->prev_fmerit = 0; - st->fmerit_dt = 0; - st->Last_pulse_pos = 0; - - FOR (i = 0; i < shl(NB_SUBFR16k, 1); i++) - { - st->old_pitch_buf[i] = L_SUBFR; - } - - /* mode1 core switching */ - st->old_Es_pred = 0; - set16_fx(st->old_Aq_12_8_fx + 1, 0, M); - st->old_Aq_12_8_fx[0] = 1; - - /* stable short pitch detection */ - st->voicing0_sm_fx = 0; - st->voicing_sm_fx = 0; - st->LF_EnergyRatio_sm_fx = 1; - st->predecision_flag = 0; - st->diff_sm_fx = 0; - st->energy_sm_fx = 0; - - set16_fx(st->pitch, L_SUBFR, 3); - set16_fx(st->voicing_fx, 0, 3); - - /*-----------------------------------------------------------------* - * General signal buffers - *-----------------------------------------------------------------*/ - - IF (!vad_only_flag) - { - IF ((st->hSignalBuf = (SIGNAL_BUFFERS_ENC_HANDLE)malloc(sizeof(SIGNAL_BUFFERS_ENC_DATA))) == NULL) - { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Signal buffers\n")); - } - - st->Bin_E_old_fx = st->hSignalBuf->Bin_E_old_fx; - st->mem_decim_fx = st->hSignalBuf->mem_decim_fx; - st->mem_decim16k_fx = st->hSignalBuf->mem_decim16k_fx; - st->old_inp_12k8_fx = st->hSignalBuf->old_inp_12k8_fx; - st->old_inp_16k_fx = st->hSignalBuf->old_inp_16k_fx; - st->buf_speech_enc_pe = st->hSignalBuf->buf_speech_enc_pe; - st->buf_synth = st->hSignalBuf->buf_synth; - st->buf_speech_enc = st->hSignalBuf->buf_speech_enc; - st->buf_wspeech_enc = st->hSignalBuf->buf_wspeech_enc; - - /* initializations */ - set32_fx(st->Bin_E_old_fx, 0, shr(L_FFT, 2)); - set16_fx(st->mem_decim_fx, 0, shl(L_FILT_MAX, 1)); - set16_fx(st->mem_decim16k_fx, 0, shl(L_FILT_MAX, 1)); - set16_fx(st->old_inp_12k8_fx, 0, L_INP_MEM); - set16_fx(st->old_inp_16k_fx, 0, L_INP_MEM); - - st->input_buff_fx = st->hSignalBuf->input_buff; - set16_fx(st->input_buff_fx, 0, add(L_FRAME48k, add( L_FRAME48k , NS2SA(48000, DELAY_FIR_RESAMPL_NS)))); - st->old_input_signal_fx = st->input_buff_fx; - Word16 temp; - Word16 frame_length = BASOP_Util_Divide3232_Scale(st->input_Fs, FRAMES_PER_SEC, &temp); + Word16 i; + ivas_error error; + Word32 igf_brate; + + error = IVAS_ERR_OK; + + /*-----------------------------------------------------------------* + * General parameters + *-----------------------------------------------------------------*/ + + IF( st->Opt_AMR_WB ) + { + st->last_core = AMR_WB_CORE; + } + ELSE + { + st->last_core = -1; + } + + st->L_frame = L_FRAME; + st->last_coder_type = GENERIC; + st->coder_type = GENERIC; + st->last_total_brate = st->total_brate; + st->last_bits_frame_nominal = -1; + st->last_total_brate_cng = -1; + st->last_core_brate = st->total_brate; + st->dtx_sce_sba = 0; + st->extl = -1; + st->last_extl = -1; + st->last_L_frame = L_FRAME; + st->rate_switching_reset = 0; + st->rate_switching_reset_16kHz = 0; + st->clas = UNVOICED_CLAS; + st->low_rate_mode = 0; + st->ini_frame = 0; + st->inactive_coder_type_flag = 0; + st->sba_br_sw_while_no_data = 0; + + st->coder_type_raw = VOICED; + st->last_coder_type_raw = st->coder_type_raw; + + st->flag_ACELP16k = set_ACELP_flag_IVAS( st->element_mode, st->total_brate, st->total_brate, idchan, 0, -1, -1 ); + + st->is_ism_format = 0; + IF( ism_mode != ISM_MODE_NONE ) + { + st->is_ism_format = 1; + } + + /*-----------------------------------------------------------------* + * Bitstream + *-----------------------------------------------------------------*/ + + IF( !vad_only_flag ) + { + IF( ( st->hBstr = (BSTR_ENC_HANDLE) malloc( sizeof( BSTR_ENC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Bitstream structure\n" ) ); + } + + /* set pointer to the buffer of indices */ + st->hBstr->ind_list = st_ivas->ind_list; + st->hBstr->ivas_ind_list_zero = &st_ivas->ind_list; + st->hBstr->ivas_max_num_indices = &st_ivas->ivas_max_num_indices; + st->hBstr->nb_ind_tot = 0; + st->hBstr->nb_bits_tot = 0; + st->hBstr->st_ivas = st_ivas; + } + ELSE + { + st->hBstr = NULL; + } + + /*-----------------------------------------------------------------* + * Pre-processing and ACELP core parameters + *-----------------------------------------------------------------*/ + + Copy( GEWB_Ave_fx, st->mem_AR_fx, M ); + Copy( GEWB_Ave_fx, st->lsfoldbfi0_fx, M ); + Copy( GEWB_Ave_fx, st->lsfoldbfi1_fx, M ); + Copy( GEWB_Ave_fx, st->lsf_adaptive_mean_fx, M ); + + st->next_force_safety_net = 0; + + st->pstreaklen = 0; + st->streaklimit_fx = MAX_WORD16; + set16_fx( st->mem_MA_fx, 0, M ); + + init_gp_clip_fx( st->clip_var_fx ); + pitch_ol_init_fx( &st->old_thres_fx, &st->old_pitch, &st->delta_pit, &st->old_corr_fx ); + set16_fx( st->old_wsp_fx, 0, L_WSP_MEM ); + set16_fx( st->old_wsp2_fx, 0, ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ); // Needs to change depending on usage. + + st->mem_preemph_fx = 0; + st->mem_preemph16k_fx = 0; + st->mem_preemph_enc = 0; + + /* AVQ pre-quantizer memory */ + st->mem_preemp_preQ_fx = 0; + st->mem_deemp_preQ_fx = 0; + st->last_nq_preQ = 0; + st->last_code_preq = 0; + st->use_acelp_preq = 0; + st->last_harm_flag_acelp = 0; + + /* (Decimated) Weighted Speech Memory */ + st->mem_wsp_enc = 0; + st->mem_wsp_fx = 0; + + set16_fx( st->mem_decim2_fx, 0, 3 ); + set32_fx( st->Bin_E_fx, 0, L_FFT ); + + st->ee_old_fx = 640; /*chk //10 in Q6 */ + st->Nb_ACELP_frames = 0; + st->audio_frame_cnt = AUDIO_COUNTER_INI; /* Initialization of the audio frame counter mildly into the audio mode */ + + /* adaptive lag window memory */ + st->old_pitch_la = 0; + + IF( EQ_32( st->input_Fs, 8000 ) ) + { + st->min_band = 1; + st->max_band = 16; + } + ELSE + { + st->min_band = 0; + st->max_band = 19; + } + + IF( st->Opt_AMR_WB ) + { + Copy( mean_isf_amr_wb_fx, st->lsf_old_fx, M ); + E_LPC_isf_isp_conversion( st->lsf_old_fx, st->lsp_old1_fx, M ); + } + ELSE + { + Copy( GEWB_Ave_fx, st->lsf_old_fx, M ); + lsf2lsp_fx( st->lsf_old_fx, st->lsp_old1_fx, M, INT_FS_12k8 ); + } + + Copy( st->lsf_old_fx, st->lsf_old1_fx, M ); + Copy( st->lsp_old1_fx, st->lsp_old_fx, M ); + Copy( st->lsp_old_fx, st->lsp_old16k_fx, M ); + Copy( st->lsp_old_fx, st->lspold_enc_fx, M ); + + st->stab_fac_fx = 0; + + /* Bass post-filter memories - encoder side of MODE2 */ + st->bpf_off = 0; + st->pst_mem_deemp_err_fx = 0; + st->pst_lp_ener_fx = 0; + + /* TC coder type */ + st->tc_cnt = 0; + + /* find_uv() parameters */ + st->old_dE1_fx = 0; + st->old_ind_deltaMax = 0; + set32_fx( st->old_enr_ssf_fx, 0, shl( NB_SSF, 1 ) ); + st->spike_hyst = -1; + + /* stereo switching memories */ + st->mem_preemph_DFT_fx = 0; + set32_fx( st->inp_12k8_mem_stereo_sw_fx, 0, sub( sub( STEREO_DFT_OVL_12k8, L_MEM_RECALC_12K8 ), L_FILT ) ); + st->mem_preemph16k_DFT_fx = 0; + set32_fx( st->inp_16k_mem_stereo_sw_fx, 0, sub( sub( STEREO_DFT_OVL_16k, L_MEM_RECALC_16K ), L_FILT16k ) ); + + st->sharpFlag = 0; + + /* Stationary noise UV modification */ + st->ge_sm_fx = 10; /*chk //10 in Q6 */ + st->uv_count = 0; + st->act_count = 3; + Copy( st->lsp_old_fx, st->lspold_s_fx, M ); + st->noimix_seed = RANDOM_INITSEED; + st->min_alpha_fx = 1; + st->exc_pe = 0; + + /* FEC */ + st->last_clas = UNVOICED_CLAS; + st->prev_fmerit = 0; + st->fmerit_dt = 0; + st->Last_pulse_pos = 0; + + FOR( i = 0; i < shl( NB_SUBFR16k, 1 ); i++ ) + { + st->old_pitch_buf[i] = L_SUBFR; + } + + /* mode1 core switching */ + st->old_Es_pred = 0; + set16_fx( st->old_Aq_12_8_fx + 1, 0, M ); + st->old_Aq_12_8_fx[0] = 1; + + /* stable short pitch detection */ + st->voicing0_sm_fx = 0; + st->voicing_sm_fx = 0; + st->LF_EnergyRatio_sm_fx = 1; + st->predecision_flag = 0; + st->diff_sm_fx = 0; + st->energy_sm_fx = 0; + + set16_fx( st->pitch, L_SUBFR, 3 ); + set16_fx( st->voicing_fx, 0, 3 ); + + /*-----------------------------------------------------------------* + * General signal buffers + *-----------------------------------------------------------------*/ + + IF( !vad_only_flag ) + { + IF( ( st->hSignalBuf = (SIGNAL_BUFFERS_ENC_HANDLE) malloc( sizeof( SIGNAL_BUFFERS_ENC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Signal buffers\n" ) ); + } + + st->Bin_E_old_fx = st->hSignalBuf->Bin_E_old_fx; + st->mem_decim_fx = st->hSignalBuf->mem_decim_fx; + st->mem_decim16k_fx = st->hSignalBuf->mem_decim16k_fx; + st->old_inp_12k8_fx = st->hSignalBuf->old_inp_12k8_fx; + st->old_inp_16k_fx = st->hSignalBuf->old_inp_16k_fx; + st->buf_speech_enc_pe = st->hSignalBuf->buf_speech_enc_pe; + st->buf_synth = st->hSignalBuf->buf_synth; + st->buf_speech_enc = st->hSignalBuf->buf_speech_enc; + st->buf_wspeech_enc = st->hSignalBuf->buf_wspeech_enc; + + /* initializations */ + set32_fx( st->Bin_E_old_fx, 0, shr( L_FFT, 2 ) ); + set16_fx( st->mem_decim_fx, 0, shl( L_FILT_MAX, 1 ) ); + set16_fx( st->mem_decim16k_fx, 0, shl( L_FILT_MAX, 1 ) ); + set16_fx( st->old_inp_12k8_fx, 0, L_INP_MEM ); + set16_fx( st->old_inp_16k_fx, 0, L_INP_MEM ); + + st->input_buff_fx = st->hSignalBuf->input_buff; + set16_fx( st->input_buff_fx, 0, add( L_FRAME48k, add( L_FRAME48k, NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ) ) ); + st->old_input_signal_fx = st->input_buff_fx; + Word16 temp; + Word16 frame_length = BASOP_Util_Divide3232_Scale( st->input_Fs, FRAMES_PER_SEC, &temp ); + + IF( EQ_16( st->element_mode, EVS_MONO ) ) + { + st->input_fx = st->input_buff_fx + add( frame_length, (Word16) NS2SA( st->input_Fs, DELAY_FIR_RESAMPL_NS ) ); + } + ELSE + { + st->input_fx = st->input_buff_fx + frame_length; + } + } + ELSE + { + st->hSignalBuf = NULL; + st->Bin_E_old_fx = NULL; + st->mem_decim_fx = NULL; + st->mem_decim16k_fx = NULL; + st->old_inp_12k8_fx = NULL; + st->old_inp_16k_fx = NULL; + st->buf_speech_enc_pe = NULL; + st->buf_synth = NULL; + st->buf_speech_enc = NULL; + st->buf_wspeech_enc = NULL; + st->input_buff_fx = NULL; + } + + /*-----------------------------------------------------------------* + * Noise estimator + *-----------------------------------------------------------------*/ + + IF( EQ_16( st->element_mode, IVAS_CPE_TD ) || EQ_16( st->element_mode, IVAS_CPE_MDCT ) || EQ_16( st->element_mode, EVS_MONO ) ) + { + IF( ( st->hNoiseEst = (NOISE_EST_HANDLE) malloc( sizeof( NOISE_EST_DATA ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Noise estimation\n" ); + } + + noise_est_init_fx( st->hNoiseEst ); + } + ELSE + { + st->hNoiseEst = NULL; + } + + /*-----------------------------------------------------------------* + * VAD + *-----------------------------------------------------------------*/ + + st->vad_flag = 1; + st->localVAD = 0; + + IF( ( EQ_16( idchan, 0 ) || EQ_16( st->element_mode, IVAS_CPE_TD ) || EQ_16( st->element_mode, IVAS_CPE_MDCT ) || EQ_16( st->element_mode, EVS_MONO ) ) && ( !vad_only_flag ) ) + { + IF( ( st->hVAD = (VAD_HANDLE) malloc( sizeof( VAD_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VAD\n" ) ); + } + + wb_vad_init_ivas_fx( st->hVAD ); + } + ELSE + { + st->hVAD = NULL; + } + st->Pos_relE_cnt = 20; + + /* CLDFB-based VAD */ + IF( st->element_mode == EVS_MONO ) + { + IF( ( st->hVAD_CLDFB = (VAD_CLDFB_HANDLE) malloc( sizeof( T_CldfbVadState ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CLDFB VAD\n" ) ); + } + + vad_init_ivas_fx( st->hVAD_CLDFB ); + } + ELSE + { + st->hVAD_CLDFB = NULL; + } + + /*-----------------------------------------------------------------* + * Speech/music classifier + *-----------------------------------------------------------------*/ + + IF( EQ_16( idchan, 0 ) || EQ_16( st->element_mode, IVAS_CPE_TD ) || EQ_16( st->element_mode, IVAS_CPE_MDCT ) || EQ_16( st->element_mode, EVS_MONO ) ) + { + IF( ( st->hSpMusClas = (SP_MUS_CLAS_HANDLE) malloc( sizeof( SP_MUS_CLAS_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Speech/music classifier\n" ) ); + } + + speech_music_clas_init_fx( st->hSpMusClas ); + + st->sp_aud_decision0 = 0; + st->sp_aud_decision1 = 0; + st->sp_aud_decision2 = 0; + } + ELSE + { + st->hSpMusClas = NULL; + } + + + /*-----------------------------------------------------------------* + * WB, SWB and FB bandwidth detector + *-----------------------------------------------------------------*/ + + st->lt_mean_NB_fx = 0; + st->lt_mean_WB_fx = 0; + st->lt_mean_SWB_fx = 0; + st->count_WB = BWD_COUNT_MAX; + st->count_SWB = BWD_COUNT_MAX; + st->count_FB = BWD_COUNT_MAX; + st->bwidth = st->max_bwidth; + st->last_input_bwidth = st->bwidth; + st->last_bwidth = st->bwidth; + st->last_bwidth_cng = st->bwidth; + st->bwidth_sw_cnt = 0; + + + /*-----------------------------------------------------------------* + * DTX + *-----------------------------------------------------------------*/ + + st->lp_speech_fx = 11520; /*Q8 (45.0) */ /* Initialize the long-term active speech level in dB */ + st->lp_noise_fx = 0; + st->flag_noisy_speech_snr = 0; + st->fd_cng_reset_flag = 0; + st->cng_type = -1; + st->bckr_tilt_lt = 0; + st->active_cnt = 0; + + IF( ( ( EQ_16( idchan, 0 ) && st->Opt_DTX_ON ) || EQ_16( st->element_mode, EVS_MONO ) ) || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && st->Opt_DTX_ON ) ) + { + IF( ( st->hDtxEnc = (DTX_ENC_HANDLE) malloc( sizeof( DTX_ENC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX variables\n" ) ); + } + dtx_enc_init_fx( st, var_SID_rate_flag, interval_SID ); + } + ELSE + { + st->hDtxEnc = NULL; + } + + /*-----------------------------------------------------------------* + * No other handles needed to be allocated for front-VAD structure + *-----------------------------------------------------------------*/ + + IF( vad_only_flag ) + { + st->hTdCngEnc = NULL; + st->cldfbAnaEnc = NULL; + st->hFdCngEnc = NULL; + st->hSC_VBR = NULL; + st->hAmrwb_IO = NULL; + st->hLPDmem = NULL; + st->hGSCEnc = NULL; + st->hBWE_TD = NULL; + st->cldfbSynTd = NULL; + st->hBWE_FD = NULL; + st->hHQ_core = NULL; + st->hRF = NULL; + st->hTECEnc = NULL; + st->hTcxEnc = NULL; + st->hTcxCfg = NULL; + st->hIGFEnc = NULL; + st->hPlcExt = NULL; + st->hTranDet = NULL; + + st->element_mode = IVAS_SCE; + st->idchan = 100; /* indicates hCoreCoderVAD */ + st->core = -1; + st->rf_mode = 0; + + return error; + } - IF (EQ_16(st->element_mode, EVS_MONO)) + /*-----------------------------------------------------------------* + * LP-CNG + *-----------------------------------------------------------------*/ + + IF( ( ( EQ_16( idchan, 0 ) && st->Opt_DTX_ON && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st->element_mode, EVS_MONO ) ) && !( EQ_16( ism_mode, ISM_MODE_PARAM ) || EQ_16( ism_mode, ISM_MODE_DISC ) ) ) { - st->input_fx = st->input_buff_fx + add(frame_length, (Word16)NS2SA(st->input_Fs, DELAY_FIR_RESAMPL_NS)); + IF( ( st->hTdCngEnc = (TD_CNG_ENC_HANDLE) malloc( sizeof( TD_CNG_ENC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX/TD CNG\n" ) ); + } + + td_cng_enc_init_fx( st->hTdCngEnc, st->Opt_DTX_ON, st->max_bwidth ); } ELSE { - st->input_fx = st->input_buff_fx + frame_length; + st->hTdCngEnc = NULL; } - } - ELSE - { - st->hSignalBuf = NULL; - st->Bin_E_old_fx = NULL; - st->mem_decim_fx = NULL; - st->mem_decim16k_fx = NULL; - st->old_inp_12k8_fx = NULL; - st->old_inp_16k_fx = NULL; - st->buf_speech_enc_pe = NULL; - st->buf_synth = NULL; - st->buf_speech_enc = NULL; - st->buf_wspeech_enc = NULL; - st->input_buff_fx = NULL; - } - - /*-----------------------------------------------------------------* - * Noise estimator - *-----------------------------------------------------------------*/ - - IF (EQ_16(st->element_mode, IVAS_CPE_TD) || EQ_16(st->element_mode, IVAS_CPE_MDCT) || EQ_16(st->element_mode, EVS_MONO)) - { - IF ((st->hNoiseEst = (NOISE_EST_HANDLE)malloc(sizeof(NOISE_EST_DATA))) == NULL) - { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Noise estimation\n"); - } - - noise_est_init_fx(st->hNoiseEst); - } - ELSE - { - st->hNoiseEst = NULL; - } - - /*-----------------------------------------------------------------* - * VAD - *-----------------------------------------------------------------*/ - - st->vad_flag = 1; - st->localVAD = 0; - - IF ((EQ_16(idchan, 0) || EQ_16(st->element_mode, IVAS_CPE_TD) || EQ_16(st->element_mode, IVAS_CPE_MDCT) || EQ_16(st->element_mode, EVS_MONO)) && (!vad_only_flag)) - { - IF ((st->hVAD = (VAD_HANDLE)malloc(sizeof(VAD_DATA))) == NULL) - { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VAD\n")); - } - - wb_vad_init_ivas_fx(st->hVAD); - } - ELSE - { - st->hVAD = NULL; - } - st->Pos_relE_cnt = 20; - - /* CLDFB-based VAD */ - IF (st->element_mode == EVS_MONO) - { - IF ((st->hVAD_CLDFB = (VAD_CLDFB_HANDLE)malloc(sizeof(T_CldfbVadState))) == NULL) - { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CLDFB VAD\n")); - } - - vad_init_ivas_fx(st->hVAD_CLDFB); - } - ELSE - { - st->hVAD_CLDFB = NULL; - } - - /*-----------------------------------------------------------------* - * Speech/music classifier - *-----------------------------------------------------------------*/ - - IF (EQ_16(idchan, 0) || EQ_16(st->element_mode, IVAS_CPE_TD) || EQ_16(st->element_mode, IVAS_CPE_MDCT) || EQ_16(st->element_mode, EVS_MONO)) - { - IF ((st->hSpMusClas = (SP_MUS_CLAS_HANDLE)malloc(sizeof(SP_MUS_CLAS_DATA))) == NULL) - { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Speech/music classifier\n")); - } - - speech_music_clas_init_fx(st->hSpMusClas); - - st->sp_aud_decision0 = 0; - st->sp_aud_decision1 = 0; - st->sp_aud_decision2 = 0; - } - ELSE - { - st->hSpMusClas = NULL; - } - - - /*-----------------------------------------------------------------* - * WB, SWB and FB bandwidth detector - *-----------------------------------------------------------------*/ - - st->lt_mean_NB_fx = 0; - st->lt_mean_WB_fx = 0; - st->lt_mean_SWB_fx = 0; - st->count_WB = BWD_COUNT_MAX; - st->count_SWB = BWD_COUNT_MAX; - st->count_FB = BWD_COUNT_MAX; - st->bwidth = st->max_bwidth; - st->last_input_bwidth = st->bwidth; - st->last_bwidth = st->bwidth; - st->last_bwidth_cng = st->bwidth; - st->bwidth_sw_cnt = 0; - - - /*-----------------------------------------------------------------* - * DTX - *-----------------------------------------------------------------*/ - - st->lp_speech_fx = 11520; /*Q8 (45.0) */ /* Initialize the long-term active speech level in dB */ - st->lp_noise_fx = 0; - st->flag_noisy_speech_snr = 0; - st->fd_cng_reset_flag = 0; - st->cng_type = -1; - st->bckr_tilt_lt = 0; - st->active_cnt = 0; - - IF (((EQ_16(idchan, 0) && st->Opt_DTX_ON) || EQ_16(st->element_mode, EVS_MONO)) || (EQ_16(st->element_mode, IVAS_CPE_MDCT) && st->Opt_DTX_ON)) - { - IF ((st->hDtxEnc = (DTX_ENC_HANDLE)malloc(sizeof(DTX_ENC_DATA))) == NULL) - { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX variables\n")); - } - dtx_enc_init_fx(st, var_SID_rate_flag, interval_SID); - } - ELSE - { - st->hDtxEnc = NULL; - } - - /*-----------------------------------------------------------------* - * No other handles needed to be allocated for front-VAD structure - *-----------------------------------------------------------------*/ - - IF (vad_only_flag) - { - st->hTdCngEnc = NULL; - st->cldfbAnaEnc = NULL; - st->hFdCngEnc = NULL; - st->hSC_VBR = NULL; - st->hAmrwb_IO = NULL; - st->hLPDmem = NULL; - st->hGSCEnc = NULL; - st->hBWE_TD = NULL; - st->cldfbSynTd = NULL; - st->hBWE_FD = NULL; - st->hHQ_core = NULL; - st->hRF = NULL; - st->hTECEnc = NULL; - st->hTcxEnc = NULL; - st->hTcxCfg = NULL; - st->hIGFEnc = NULL; - st->hPlcExt = NULL; - st->hTranDet = NULL; - - st->element_mode = IVAS_SCE; - st->idchan = 100; /* indicates hCoreCoderVAD */ - st->core = -1; - st->rf_mode = 0; - - return error; - } - /*-----------------------------------------------------------------* - * LP-CNG - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * CLDFB & resampling tools parameters + *-----------------------------------------------------------------*/ - IF (((EQ_16(idchan, 0) && st->Opt_DTX_ON && NE_16(st->element_mode, IVAS_CPE_MDCT)) || EQ_16(st->element_mode, EVS_MONO)) && !(EQ_16(ism_mode, ISM_MODE_PARAM) || EQ_16(ism_mode, ISM_MODE_DISC))) - { - IF ((st->hTdCngEnc = (TD_CNG_ENC_HANDLE)malloc(sizeof(TD_CNG_ENC_DATA))) == NULL) + IF( ( NE_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( idchan, 0 ) ) || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && st->Opt_DTX_ON ) ) + { + IF( ( error = openCldfb_ivas( &st->cldfbAnaEnc, CLDFB_ANALYSIS, st->input_Fs, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) + { + return error; + } + } + ELSE { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX/TD CNG\n")); + st->cldfbAnaEnc = NULL; } - td_cng_enc_init_fx(st->hTdCngEnc, st->Opt_DTX_ON, st->max_bwidth); - } - ELSE - { - st->hTdCngEnc = NULL; - } + st->currEnergyLookAhead = 130996; /* 6.1e-5f in Q31 */ - /*-----------------------------------------------------------------* - * CLDFB & resampling tools parameters - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * SC-VBR parameters + *-----------------------------------------------------------------*/ - IF ((NE_16(st->element_mode, IVAS_CPE_MDCT) && EQ_16(idchan, 0)) || (EQ_16(st->element_mode, IVAS_CPE_MDCT) && st->Opt_DTX_ON)) - { - IF ((error = openCldfb_ivas(&st->cldfbAnaEnc, CLDFB_ANALYSIS, st->input_Fs, CLDFB_PROTOTYPE_1_25MS)) != IVAS_ERR_OK) + IF( st->Opt_SC_VBR || EQ_16( st->element_mode, EVS_MONO ) ) { - return error; - } - } - ELSE - { - st->cldfbAnaEnc = NULL; - } - - st->currEnergyLookAhead = 130996; /* 6.1e-5f in Q31 */ - - /*-----------------------------------------------------------------* - * SC-VBR parameters - *-----------------------------------------------------------------*/ + IF( ( st->hSC_VBR = (SC_VBR_ENC_HANDLE) malloc( sizeof( SC_VBR_ENC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SC-VBR\n" ) ); + } - IF (st->Opt_SC_VBR || EQ_16(st->element_mode, EVS_MONO)) - { - IF ((st->hSC_VBR = (SC_VBR_ENC_HANDLE)malloc(sizeof(SC_VBR_ENC_DATA))) == NULL) + sc_vbr_enc_init_fx( st->hSC_VBR ); + } + ELSE { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SC-VBR\n")); + st->hSC_VBR = NULL; } - sc_vbr_enc_init_fx(st->hSC_VBR); - } - ELSE - { - st->hSC_VBR = NULL; - } + st->last_Opt_SC_VBR = 0; - st->last_Opt_SC_VBR = 0; + /*-----------------------------------------------------------------* + * AMR-WB IO initialization + *-----------------------------------------------------------------*/ - /*-----------------------------------------------------------------* - * AMR-WB IO initialization - *-----------------------------------------------------------------*/ + IF( st->Opt_AMR_WB || EQ_16( st->element_mode, EVS_MONO ) ) + { + IF( ( st->hAmrwb_IO = (AMRWB_IO_ENC_HANDLE) malloc( sizeof( AMRWB_IO_ENC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for AMR-WB IO\n" ) ); + } - IF (st->Opt_AMR_WB || EQ_16(st->element_mode, EVS_MONO)) - { - IF ((st->hAmrwb_IO = (AMRWB_IO_ENC_HANDLE)malloc(sizeof(AMRWB_IO_ENC_DATA))) == NULL) + amr_wb_enc_init_fx( st->hAmrwb_IO ); + } + ELSE { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for AMR-WB IO\n")); + st->hAmrwb_IO = NULL; } - amr_wb_enc_init_fx(st->hAmrwb_IO); - } - ELSE - { - st->hAmrwb_IO = NULL; - } + /*-----------------------------------------------------------------* + * ACELP LPDmem + *-----------------------------------------------------------------*/ - /*-----------------------------------------------------------------* - * ACELP LPDmem - *-----------------------------------------------------------------*/ + IF( ( EQ_16( idchan, 0 ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) + { + IF( ( st->hLPDmem = (LPD_state_HANDLE) malloc( sizeof( LPD_state ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LPDmem\n" ) ); + } - IF ((EQ_16(idchan, 0) && NE_16(st->element_mode, IVAS_CPE_MDCT)) || EQ_16(st->element_mode, IVAS_CPE_TD)) - { - IF ((st->hLPDmem = (LPD_state_HANDLE)malloc(sizeof(LPD_state))) == NULL) + LPDmem_enc_init_fx( st->hLPDmem ); + } + ELSE { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LPDmem\n")); + st->hLPDmem = NULL; } - LPDmem_enc_init_fx(st->hLPDmem); - } - ELSE - { - st->hLPDmem = NULL; - } + /*-----------------------------------------------------------------* + * parameters for AC coder type (GSC) + *-----------------------------------------------------------------*/ - /*-----------------------------------------------------------------* - * parameters for AC coder type (GSC) - *-----------------------------------------------------------------*/ + st->GSC_noisy_speech = 0; + st->GSC_IVAS_mode = 0; - st->GSC_noisy_speech = 0; - st->GSC_IVAS_mode = 0; + IF( ( EQ_16( idchan, 0 ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) + { + IF( ( st->hGSCEnc = (GSC_ENC_HANDLE) malloc( sizeof( GSC_ENC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for GSC\n" ) ); + } - IF ((EQ_16(idchan, 0) && NE_16(st->element_mode, IVAS_CPE_MDCT)) || EQ_16(st->element_mode, IVAS_CPE_TD)) - { - IF ((st->hGSCEnc = (GSC_ENC_HANDLE)malloc(sizeof(GSC_ENC_DATA))) == NULL) + GSC_enc_init_fx( st->hGSCEnc ); + } + ELSE { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for GSC\n")); + st->hGSCEnc = NULL; } - GSC_enc_init_fx(st->hGSCEnc); - } - ELSE - { - st->hGSCEnc = NULL; - } - - /*-----------------------------------------------------------------* - * TBE parameters - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * TBE parameters + *-----------------------------------------------------------------*/ - IF (EQ_16(idchan, 0) && NE_16(st->element_mode, IVAS_CPE_MDCT)) - { - IF ((st->hBWE_TD = (TD_BWE_ENC_HANDLE)malloc(sizeof(TD_BWE_ENC_DATA))) == NULL) + IF( EQ_16( idchan, 0 ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD BWE\n")); - } + IF( ( st->hBWE_TD = (TD_BWE_ENC_HANDLE) malloc( sizeof( TD_BWE_ENC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD BWE\n" ) ); + } + + IF( ( error = openCldfb_ivas( &st->cldfbSynTd, CLDFB_SYNTHESIS, 16000, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) + { + return error; + } - IF ((error = openCldfb_ivas(&st->cldfbSynTd, CLDFB_SYNTHESIS, 16000, CLDFB_PROTOTYPE_1_25MS)) != IVAS_ERR_OK) + InitSWBencBuffer_fx( st ); + ResetSHBbuffer_Enc_fx( st ); + } + ELSE { - return error; + st->hBWE_TD = NULL; + st->cldfbSynTd = NULL; } - InitSWBencBuffer_fx(st); - ResetSHBbuffer_Enc_fx(st); - } - ELSE - { - st->hBWE_TD = NULL; - st->cldfbSynTd = NULL; - } + /*-----------------------------------------------------------------* + * SWB BWE parameters + *-----------------------------------------------------------------*/ - /*-----------------------------------------------------------------* - * SWB BWE parameters - *-----------------------------------------------------------------*/ + IF( EQ_16( idchan, 0 ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) + { + IF( ( st->hBWE_FD = (FD_BWE_ENC_HANDLE) malloc( sizeof( FD_BWE_ENC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FD BWE\n" ) ); + } - IF (EQ_16(idchan, 0) && NE_16(st->element_mode, IVAS_CPE_MDCT)) - { - IF ((st->hBWE_FD = (FD_BWE_ENC_HANDLE)malloc(sizeof(FD_BWE_ENC_DATA))) == NULL) + fd_bwe_enc_init_fx( st->hBWE_FD ); + } + ELSE { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FD BWE\n")); + st->hBWE_FD = NULL; } - fd_bwe_enc_init_fx(st->hBWE_FD); - } - ELSE - { - st->hBWE_FD = NULL; - } + /*-----------------------------------------------------------------* + * HQ core parameters + *-----------------------------------------------------------------*/ - /*-----------------------------------------------------------------* - * HQ core parameters - *-----------------------------------------------------------------*/ + IF( NE_16( st->element_mode, IVAS_CPE_TD ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( idchan, 0 ) ) + { + IF( ( st->hHQ_core = (HQ_ENC_HANDLE) malloc( sizeof( HQ_ENC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HQ core\n" ) ); + } - IF (NE_16(st->element_mode, IVAS_CPE_TD) && NE_16(st->element_mode, IVAS_CPE_MDCT) && EQ_16(idchan, 0)) - { - IF ((st->hHQ_core = (HQ_ENC_HANDLE)malloc(sizeof(HQ_ENC_DATA))) == NULL) + HQ_core_enc_init_fx( st->hHQ_core ); + } + ELSE { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HQ core\n")); + st->hHQ_core = NULL; } - HQ_core_enc_init_fx(st->hHQ_core); - } - ELSE - { - st->hHQ_core = NULL; - } + /* init memory for detect_transient(), used by HQ core and swb_bwe_enc */ + st->old_hpfilt_in_fx = 0; + st->old_hpfilt_out_fx = 0; + st->EnergyLT_fx = 0; + st->Energy_Old_fx = 0; + st->TransientHangOver = 0; - /* init memory for detect_transient(), used by HQ core and swb_bwe_enc */ - st->old_hpfilt_in_fx = 0; - st->old_hpfilt_out_fx = 0; - st->EnergyLT_fx = 0; - st->Energy_Old_fx = 0; - st->TransientHangOver = 0; + /*-----------------------------------------------------------------* + * Channel-aware mode + *-----------------------------------------------------------------*/ - /*-----------------------------------------------------------------* - * Channel-aware mode - *-----------------------------------------------------------------*/ + IF( !st->Opt_RF_ON || ( NE_16( st->bwidth, WB ) && NE_16( st->bwidth, SWB ) ) || NE_32( st->total_brate, ACELP_13k20 ) ) + { + st->rf_mode = 0; + } + ELSE + { + st->rf_mode = st->Opt_RF_ON; + } - IF (!st->Opt_RF_ON || (NE_16(st->bwidth, WB) && NE_16(st->bwidth, SWB)) || NE_32(st->total_brate, ACELP_13k20)) - { - st->rf_mode = 0; - } - ELSE - { - st->rf_mode = st->Opt_RF_ON; - } + st->rf_mode_last = st->rf_mode; - st->rf_mode_last = st->rf_mode; + IF( st->Opt_RF_ON || EQ_16( st->element_mode, EVS_MONO ) ) + { + IF( ( st->hRF = (RF_ENC_HANDLE) malloc( sizeof( RF_ENC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for RF\n" ) ); + } - IF (st->Opt_RF_ON || EQ_16(st->element_mode, EVS_MONO)) - { - IF ((st->hRF = (RF_ENC_HANDLE)malloc(sizeof(RF_ENC_DATA))) == NULL) + /* initialize RF indice buffers */ + reset_rf_indices_fx( st ); + } + ELSE { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for RF\n")); + st->hRF = NULL; } - /* initialize RF indice buffers */ - reset_rf_indices_fx(st); - } - ELSE - { - st->hRF = NULL; - } - - /*-----------------------------------------------------------------* - * Temporal Envelope Coding - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * Temporal Envelope Coding + *-----------------------------------------------------------------*/ - IF (EQ_16(st->element_mode, EVS_MONO)) - { - IF ((st->hTECEnc = (TEC_ENC_HANDLE)malloc(sizeof(TEC_ENC_DATA))) == NULL) + IF( EQ_16( st->element_mode, EVS_MONO ) ) + { + IF( ( st->hTECEnc = (TEC_ENC_HANDLE) malloc( sizeof( TEC_ENC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TEC\n" ) ); + } + } + ELSE { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TEC\n")); + st->hTECEnc = NULL; } - } - ELSE - { - st->hTECEnc = NULL; - } - /* note: initialization done later in init_coder_ace_plus() */ + /* note: initialization done later in init_coder_ace_plus() */ - /*-----------------------------------------------------------------* - * TCX core - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * TCX core + *-----------------------------------------------------------------*/ - // ToDo: reduction possible for MCT_CHAN_MODE_LFE channel - IF (EQ_16(idchan, 0) || EQ_16(st->element_mode, IVAS_CPE_MDCT)) - { - IF ((st->hTcxEnc = (TCX_ENC_HANDLE)malloc(sizeof(TCX_ENC_DATA))) == NULL) + // ToDo: reduction possible for MCT_CHAN_MODE_LFE channel + IF( EQ_16( idchan, 0 ) || EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxEnc\n")); - } + IF( ( st->hTcxEnc = (TCX_ENC_HANDLE) malloc( sizeof( TCX_ENC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxEnc\n" ) ); + } - /* Share the memories for 2xTCX10/4xTCX5 and for TCX20 */ - st->hTcxEnc->spectrum_fx[0] = st->hTcxEnc->spectrum_long_fx; - st->hTcxEnc->spectrum_fx[1] = st->hTcxEnc->spectrum_long_fx + N_TCX10_MAX; + /* Share the memories for 2xTCX10/4xTCX5 and for TCX20 */ + st->hTcxEnc->spectrum_fx[0] = st->hTcxEnc->spectrum_long_fx; + st->hTcxEnc->spectrum_fx[1] = st->hTcxEnc->spectrum_long_fx + N_TCX10_MAX; - set16_fx(st->hTcxEnc->old_out_fx, 0, L_FRAME32k); + set16_fx( st->hTcxEnc->old_out_fx, 0, L_FRAME32k ); - /* MDCT selector */ - MDCT_selector_reset_fx(st->hTcxEnc); + /* MDCT selector */ + MDCT_selector_reset_fx( st->hTcxEnc ); - /* MDCT classifier */ - MDCT_classifier_reset_fx(st->hTcxEnc); + /* MDCT classifier */ + MDCT_classifier_reset_fx( st->hTcxEnc ); - IF ((st->hTcxCfg = (TCX_CONFIG_HANDLE)malloc(sizeof(TCX_config))) == NULL) + IF( ( st->hTcxCfg = (TCX_CONFIG_HANDLE) malloc( sizeof( TCX_config ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxCfg\n" ) ); + } + } + ELSE { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxCfg\n")); + st->hTcxEnc = NULL; + st->hTcxCfg = NULL; } - } - ELSE - { - st->hTcxEnc = NULL; - st->hTcxCfg = NULL; - } - /*-----------------------------------------------------------------* - * IGF - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * IGF + *-----------------------------------------------------------------*/ - igf_brate = st->total_brate; - IF (EQ_16(st->element_mode, IVAS_SCE) && (EQ_16(st_ivas->hEncoderConfig->ivas_format, ISM_FORMAT) || EQ_16(st_ivas->hEncoderConfig->ivas_format, MASA_ISM_FORMAT))) - { - igf_brate = L_sub(st->total_brate, i_mult(ISM_NB_BITS_METADATA_NOMINAL, FRAMES_PER_SEC)); - } - ELSE IF (EQ_16(st->element_mode, IVAS_CPE_DFT) || (EQ_16(st->element_mode, IVAS_SCE) && (EQ_16(st_ivas->hEncoderConfig->ivas_format, SBA_FORMAT) || - EQ_16(st_ivas->hEncoderConfig->ivas_format, SBA_ISM_FORMAT) || - EQ_16(st_ivas->hEncoderConfig->ivas_format, MC_FORMAT) || - EQ_16(st_ivas->hEncoderConfig->ivas_format, MASA_FORMAT)))) - { - /* use nominal bitrates for DFT Stereo and (O)SBA, same as in stereo_dft_config()/ivas_spar_config() */ - IF (EQ_32(element_brate, IVAS_13k2)) + igf_brate = st->total_brate; + IF( EQ_16( st->element_mode, IVAS_SCE ) && ( EQ_16( st_ivas->hEncoderConfig->ivas_format, ISM_FORMAT ) || EQ_16( st_ivas->hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) ) ) { - igf_brate = ACELP_9k60; + igf_brate = L_sub( st->total_brate, i_mult( ISM_NB_BITS_METADATA_NOMINAL, FRAMES_PER_SEC ) ); } - ELSE IF (EQ_32(element_brate, IVAS_16k4)) + ELSE IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) || ( EQ_16( st->element_mode, IVAS_SCE ) && ( EQ_16( st_ivas->hEncoderConfig->ivas_format, SBA_FORMAT ) || + EQ_16( st_ivas->hEncoderConfig->ivas_format, SBA_ISM_FORMAT ) || + EQ_16( st_ivas->hEncoderConfig->ivas_format, MC_FORMAT ) || + EQ_16( st_ivas->hEncoderConfig->ivas_format, MASA_FORMAT ) ) ) ) { - igf_brate = ACELP_13k20; + /* use nominal bitrates for DFT Stereo and (O)SBA, same as in stereo_dft_config()/ivas_spar_config() */ + IF( EQ_32( element_brate, IVAS_13k2 ) ) + { + igf_brate = ACELP_9k60; + } + ELSE IF( EQ_32( element_brate, IVAS_16k4 ) ) + { + igf_brate = ACELP_13k20; + } + ELSE IF( EQ_32( element_brate, IVAS_24k4 ) ) + { + igf_brate = ACELP_16k40; + } + ELSE IF( EQ_32( element_brate, IVAS_32k ) ) + { + igf_brate = ACELP_24k40; + } } - ELSE IF (EQ_32(element_brate, IVAS_24k4)) + ELSE IF( st->element_mode == IVAS_CPE_MDCT ) { - igf_brate = ACELP_16k40; + igf_brate = element_brate; } - ELSE IF (EQ_32(element_brate, IVAS_32k)) + + IF( EQ_16( st->codec_mode, MODE2 ) || GT_16( st->element_mode, EVS_MONO ) ) { - igf_brate = ACELP_24k40; + st->igf = getIgfPresent_fx( st->element_mode, igf_brate, st->max_bwidth, st->rf_mode ); + } + ELSE + { + st->igf = 0; } - } - ELSE IF (st->element_mode == IVAS_CPE_MDCT) - { - igf_brate = element_brate; - } - - IF (EQ_16(st->codec_mode, MODE2) || GT_16(st->element_mode, EVS_MONO)) - { - st->igf = getIgfPresent_fx(st->element_mode, igf_brate, st->max_bwidth, st->rf_mode); - } - ELSE - { - st->igf = 0; - } - IF ((EQ_16(idchan, 0) || EQ_16(st->element_mode, IVAS_CPE_MDCT)) && (st->igf || EQ_16(st->element_mode, EVS_MONO))) - { - IF ((st->hIGFEnc = (IGF_ENC_INSTANCE_HANDLE)malloc(sizeof(IGF_ENC_INSTANCE))) == NULL) + IF( ( EQ_16( idchan, 0 ) || EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) && ( st->igf || EQ_16( st->element_mode, EVS_MONO ) ) ) + { + IF( ( st->hIGFEnc = (IGF_ENC_INSTANCE_HANDLE) malloc( sizeof( IGF_ENC_INSTANCE ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hIGFEnc\n" ) ); + } + } + ELSE { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hIGFEnc\n")); + st->hIGFEnc = NULL; } - } - ELSE - { - st->hIGFEnc = NULL; - } - /*-----------------------------------------------------------------* - * Mode 2 initialization - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * Mode 2 initialization + *-----------------------------------------------------------------*/ - st->last_sr_core = L_mult(st->last_L_frame, FRAMES_PER_SEC); + st->last_sr_core = L_mult( st->last_L_frame, FRAMES_PER_SEC ); - /* PLC encoder */ - IF (EQ_16(st->element_mode, EVS_MONO)) - { - IF ((st->hPlcExt = (PLC_ENC_EVS_HANDLE)malloc(sizeof(PLC_ENC_EVS))) == NULL) + /* PLC encoder */ + IF( EQ_16( st->element_mode, EVS_MONO ) ) + { + IF( ( st->hPlcExt = (PLC_ENC_EVS_HANDLE) malloc( sizeof( PLC_ENC_EVS ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hPlcExt\n" ) ); + } + } + ELSE { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hPlcExt\n")); + st->hPlcExt = NULL; } - } - ELSE - { - st->hPlcExt = NULL; - } - /* Init Mode 2 core coder */ - st->last_totalNoise_fx = 0; - set16_fx(st->totalNoise_increase_hist_fx, 0, TOTALNOISE_HIST_SIZE); - st->totalNoise_increase_len = 0; + /* Init Mode 2 core coder */ + st->last_totalNoise_fx = 0; + set16_fx( st->totalNoise_increase_hist_fx, 0, TOTALNOISE_HIST_SIZE ); + st->totalNoise_increase_len = 0; - init_coder_ace_plus_fx(st, st->last_total_brate, 0, -10 /* initialization value */); + init_coder_ace_plus_fx( st, st->last_total_brate, 0, -10 /* initialization value */ ); - /*-----------------------------------------------------------------* - * FD-CNG encoder - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * FD-CNG encoder + *-----------------------------------------------------------------*/ - IF ((EQ_16(idchan, 0) && st->Opt_DTX_ON) || EQ_16(st->element_mode, EVS_MONO) || (EQ_16(st->element_mode, IVAS_CPE_MDCT) && st->Opt_DTX_ON)) - { + IF( ( EQ_16( idchan, 0 ) && st->Opt_DTX_ON ) || EQ_16( st->element_mode, EVS_MONO ) || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && st->Opt_DTX_ON ) ) + { #if 0 IF ((error = createFdCngEnc_fx(&st->hFdCngEnc)) != IVAS_ERR_OK) { return error; } #endif - createFdCngEnc_fx(&st->hFdCngEnc); - initFdCngEnc_fx(st->hFdCngEnc, st->input_Fs, st->cldfbAnaEnc->scale); - - /* initialization for IVAS modes happens in first frame pre-processing */ - IF (EQ_16(st->element_mode, EVS_MONO)) - { - configureFdCngEnc_fx(st->hFdCngEnc, st->bwidth, st->rf_mode && st->total_brate == ACELP_13k20 ? ACELP_9k60 : st->total_brate); - } - } - ELSE - { - st->hFdCngEnc = NULL; - } - - /*-----------------------------------------------------------------* - * Transient detector - *-----------------------------------------------------------------*/ - - IF ((st->hTranDet = (TRAN_DET_HANDLE)malloc(sizeof(TRAN_DET_DATA))) == NULL) - { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Transient Detection\n")); - } - Word16 temp; - Word16 frame_length = BASOP_Util_Divide3232_Scale(st->input_Fs, FRAMES_PER_SEC, &temp); - frame_length = shr(frame_length, sub(15, temp)); - - IF (GT_16(st->element_mode, EVS_MONO)) - { - InitTransientDetection_ivas_fx(frame_length, 0, st->hTranDet, 1); - } - ELSE - { - InitTransientDetection_ivas_fx(frame_length, NS2SA(st->input_Fs, DELAY_FIR_RESAMPL_NS), st->hTranDet, 0); - } - - /*-----------------------------------------------------------------* - * IVAS parameters - *-----------------------------------------------------------------*/ - - st->tdm_LRTD_flag = 0; - st->cng_sba_flag = 0; - st->bits_frame_channel = 0; - st->side_bits_frame_channel = 0; - - return error; + createFdCngEnc_fx( &st->hFdCngEnc ); + initFdCngEnc_fx( st->hFdCngEnc, st->input_Fs, st->cldfbAnaEnc->scale ); + + /* initialization for IVAS modes happens in first frame pre-processing */ + IF( EQ_16( st->element_mode, EVS_MONO ) ) + { + configureFdCngEnc_fx( st->hFdCngEnc, st->bwidth, st->rf_mode && st->total_brate == ACELP_13k20 ? ACELP_9k60 : st->total_brate ); + } + } + ELSE + { + st->hFdCngEnc = NULL; + } + + /*-----------------------------------------------------------------* + * Transient detector + *-----------------------------------------------------------------*/ + + IF( ( st->hTranDet = (TRAN_DET_HANDLE) malloc( sizeof( TRAN_DET_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Transient Detection\n" ) ); + } + Word16 temp; + Word16 frame_length = BASOP_Util_Divide3232_Scale( st->input_Fs, FRAMES_PER_SEC, &temp ); + frame_length = shr( frame_length, sub( 15, temp ) ); + + IF( GT_16( st->element_mode, EVS_MONO ) ) + { + InitTransientDetection_ivas_fx( frame_length, 0, st->hTranDet, 1 ); + } + ELSE + { + InitTransientDetection_ivas_fx( frame_length, NS2SA( st->input_Fs, DELAY_FIR_RESAMPL_NS ), st->hTranDet, 0 ); + } + + /*-----------------------------------------------------------------* + * IVAS parameters + *-----------------------------------------------------------------*/ + + st->tdm_LRTD_flag = 0; + st->cng_sba_flag = 0; + st->bits_frame_channel = 0; + st->side_bits_frame_channel = 0; + + return error; } #endif /*-----------------------------------------------------------------------* @@ -1763,4 +1763,4 @@ void destroy_cldfb_encoder( deleteFdCngEnc( &st->hFdCngEnc ); return; -} \ No newline at end of file +} diff --git a/lib_enc/init_enc_fx.c b/lib_enc/init_enc_fx.c index 4a6116d77..2607c50a5 100644 --- a/lib_enc/init_enc_fx.c +++ b/lib_enc/init_enc_fx.c @@ -2,17 +2,17 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "rom_com.h" /* Static table prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com_fx.h" /* Static table prototypes */ +#include "rom_com.h" /* Static table prototypes */ //#include "prot_fx.h" /* Function prototypes */ #include "stl.h" #include "ivas_cnst.h" #include "ivas_error.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*-----------------------------------------------------------------------* @@ -21,29 +21,29 @@ * Initialization of state variables *-----------------------------------------------------------------------*/ ivas_error init_encoder_fx( - Encoder_State *st_fx /* i/o: Encoder static variables structure */ + Encoder_State *st_fx /* i/o: Encoder static variables structure */ ) { Word16 i; Word32 L_tmp; -Word16 idchan = 0; /* i : channel ID */ -Word16 vad_only_flag = 0; /* i : channel ID */ -ISM_MODE ism_mode = ISM_MODE_NONE; + Word16 idchan = 0; /* i : channel ID */ + Word16 vad_only_flag = 0; /* i : channel ID */ + ISM_MODE ism_mode = ISM_MODE_NONE; ivas_error error; -//PMT("ism_mode, idchan, vad_only_flag to be move to function header") + // PMT("ism_mode, idchan, vad_only_flag to be move to function header") error = IVAS_ERR_OK; /*-----------------------------------------------------------------* - * General signal buffers - *-----------------------------------------------------------------*/ - IF (!vad_only_flag) + * General signal buffers + *-----------------------------------------------------------------*/ + IF( !vad_only_flag ) { - IF ((st_fx->hSignalBuf = (SIGNAL_BUFFERS_ENC_HANDLE)count_malloc(sizeof(SIGNAL_BUFFERS_ENC_DATA))) == NULL) + IF( ( st_fx->hSignalBuf = (SIGNAL_BUFFERS_ENC_HANDLE) count_malloc( sizeof( SIGNAL_BUFFERS_ENC_DATA ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Signal buffers\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Signal buffers\n" ) ); } st_fx->Bin_E_old_fx = st_fx->hSignalBuf->Bin_E_old_fx; @@ -57,19 +57,19 @@ ISM_MODE ism_mode = ISM_MODE_NONE; st_fx->buf_wspeech_enc = st_fx->hSignalBuf->buf_wspeech_enc; /* initializations */ - set16_fx(st_fx->old_inp_12k8_fx, 0, L_INP_MEM); /* memory of input signal at 12.8kHz */ - set16_fx(st_fx->old_inp_16k_fx, 0, L_INP_MEM); - set16_fx(st_fx->mem_decim16k_fx, 0, 2 * L_FILT_MAX); - set16_fx(st_fx->mem_decim_fx, 0, 2 * L_FILT_MAX); - set32_fx(st_fx->Bin_E_old_fx, 0, L_FFT/2); + set16_fx( st_fx->old_inp_12k8_fx, 0, L_INP_MEM ); /* memory of input signal at 12.8kHz */ + set16_fx( st_fx->old_inp_16k_fx, 0, L_INP_MEM ); + set16_fx( st_fx->mem_decim16k_fx, 0, 2 * L_FILT_MAX ); + set16_fx( st_fx->mem_decim_fx, 0, 2 * L_FILT_MAX ); + set32_fx( st_fx->Bin_E_old_fx, 0, L_FFT / 2 ); st_fx->input_buff_fx = st_fx->hSignalBuf->input_buff; - set16_fx(st_fx->input_buff_fx, 0, L_FRAME48k + L_FRAME48k + NS2SA(48000, DELAY_FIR_RESAMPL_NS)); + set16_fx( st_fx->input_buff_fx, 0, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); st_fx->old_input_signal_fx = st_fx->input_buff_fx; - IF (EQ_16(st_fx->element_mode, EVS_MONO)) + IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) { - st_fx->input_fx = st_fx->input_buff_fx + st_fx->input_Fs / FRAMES_PER_SEC + NS2SA(st_fx->input_Fs, DELAY_FIR_RESAMPL_NS); + st_fx->input_fx = st_fx->input_buff_fx + st_fx->input_Fs / FRAMES_PER_SEC + NS2SA( st_fx->input_Fs, DELAY_FIR_RESAMPL_NS ); } ELSE { @@ -97,7 +97,7 @@ ISM_MODE ism_mode = ISM_MODE_NONE; st_fx->last_core = -1; move16(); - IF ( st_fx->Opt_AMR_WB ) + IF( st_fx->Opt_AMR_WB ) { st_fx->last_core = AMR_WB_CORE; move16(); @@ -124,15 +124,15 @@ ISM_MODE ism_mode = ISM_MODE_NONE; st_fx->rate_switching_reset_16kHz = 0; move16(); - /*-----------------------------------------------------------------* - * Bitstream - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * Bitstream + *-----------------------------------------------------------------*/ - IF (!vad_only_flag) + IF( !vad_only_flag ) { - IF ((st_fx->hBstr = (BSTR_ENC_HANDLE)count_malloc(sizeof(BSTR_ENC_DATA))) == NULL) + IF( ( st_fx->hBstr = (BSTR_ENC_HANDLE) count_malloc( sizeof( BSTR_ENC_DATA ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Bitstream structure\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Bitstream structure\n" ) ); } #ifdef IVAS_CODE_BITSTREAM @@ -163,24 +163,24 @@ ISM_MODE ism_mode = ISM_MODE_NONE; st_fx->pstreaklen_fx = 0; move16(); st_fx->streaklimit_fx = 32767; - move16(); /*1;//Q15 */ + move16(); /*1;//Q15 */ set16_fx( st_fx->mem_MA_fx, 0, M ); init_gp_clip_fx( st_fx->clip_var_fx ); - pitch_ol_init_fx( &st_fx->old_thres_fx, &st_fx->old_pitch, &st_fx->delta_pit, &st_fx->old_corr_fx ) ; + pitch_ol_init_fx( &st_fx->old_thres_fx, &st_fx->old_pitch, &st_fx->delta_pit, &st_fx->old_corr_fx ); /*-----------------------------------------------------------------* * AMR-WB IO initialization *-----------------------------------------------------------------*/ test(); - IF (st_fx->Opt_AMR_WB || EQ_16(st_fx->element_mode, EVS_MONO)) + IF( st_fx->Opt_AMR_WB || EQ_16( st_fx->element_mode, EVS_MONO ) ) { - IF ((st_fx->hAmrwb_IO = (AMRWB_IO_ENC_HANDLE)count_malloc(sizeof(AMRWB_IO_ENC_DATA))) == NULL) + IF( ( st_fx->hAmrwb_IO = (AMRWB_IO_ENC_HANDLE) count_malloc( sizeof( AMRWB_IO_ENC_DATA ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for AMR-WB IO\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for AMR-WB IO\n" ) ); } - amr_wb_enc_init_fx(st_fx->hAmrwb_IO); + amr_wb_enc_init_fx( st_fx->hAmrwb_IO ); } ELSE { @@ -188,7 +188,7 @@ ISM_MODE ism_mode = ISM_MODE_NONE; } st_fx->clas = UNVOICED_CLAS; move16(); - set16_fx( st_fx->old_wsp2_fx, 0, (L_WSP_MEM - L_INTERPOL)/OPL_DECIM ); + set16_fx( st_fx->old_wsp2_fx, 0, ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ); set16_fx( st_fx->old_wsp_fx, 0, L_WSP_MEM ); st_fx->mem_deemph_fx = 0; move16(); @@ -217,16 +217,16 @@ ISM_MODE ism_mode = ISM_MODE_NONE; move16(); set32_fx( st_fx->Bin_E_fx, 0, L_FFT ); set16_fx( st_fx->mem_decim2_fx, 0, 3 ); - set16_fx( st_fx->lgBin_E_fx, 0, L_FFT/2 ); + set16_fx( st_fx->lgBin_E_fx, 0, L_FFT / 2 ); st_fx->ini_frame = 0; move16(); st_fx->ee_old_fx = 640; - move32();/*chk //10 in Q6 */ + move32(); /*chk //10 in Q6 */ st_fx->Nb_ACELP_frames = 0; move16(); st_fx->audio_frame_cnt = AUDIO_COUNTER_INI; - move16();/* Initializatin of the audio frame counter mildly into the audio mode */ + move16(); /* Initializatin of the audio frame counter mildly into the audio mode */ /* adaptive lag window memory */ st_fx->old_pitch_la = 0; @@ -245,7 +245,7 @@ ISM_MODE ism_mode = ISM_MODE_NONE; move16(); - IF( EQ_32(st_fx->input_Fs,8000)) + IF( EQ_32( st_fx->input_Fs, 8000 ) ) { st_fx->min_band = 1; move16(); @@ -259,15 +259,15 @@ ISM_MODE ism_mode = ISM_MODE_NONE; st_fx->max_band = 19; move16(); } - IF ( st_fx->Opt_AMR_WB ) + IF( st_fx->Opt_AMR_WB ) { Copy( mean_isf_amr_wb_fx, st_fx->lsf_old_fx, M ); - E_LPC_isf_isp_conversion( st_fx->lsf_old_fx, st_fx->lsp_old1_fx, M); + E_LPC_isf_isp_conversion( st_fx->lsf_old_fx, st_fx->lsp_old1_fx, M ); } ELSE { Copy( GEWB_Ave_fx, st_fx->lsf_old_fx, M ); - lsf2lsp_fx( st_fx->lsf_old_fx, st_fx->lsp_old1_fx, M, INT_FS_FX); + lsf2lsp_fx( st_fx->lsf_old_fx, st_fx->lsp_old1_fx, M, INT_FS_FX ); } Copy( st_fx->lsf_old_fx, st_fx->lsf_old1_fx, M ); @@ -293,18 +293,19 @@ ISM_MODE ism_mode = ISM_MODE_NONE; * parameters for AC coder type (GSC) *-----------------------------------------------------------------*/ - //st_fx->GSC_noisy_speech = 0; + // st_fx->GSC_noisy_speech = 0; st_fx->GSC_IVAS_mode = 0; - test();test(); - IF ((idchan == 0 && NE_16(st_fx->element_mode, IVAS_CPE_MDCT)) || EQ_16(st_fx->element_mode, IVAS_CPE_TD)) + test(); + test(); + IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) { - IF ((st_fx->hGSCEnc = (GSC_ENC_HANDLE)count_malloc(sizeof(GSC_ENC_DATA))) == NULL) + IF( ( st_fx->hGSCEnc = (GSC_ENC_HANDLE) count_malloc( sizeof( GSC_ENC_DATA ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for GSC\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for GSC\n" ) ); } - GSC_enc_init_fx(st_fx->hGSCEnc); + GSC_enc_init_fx( st_fx->hGSCEnc ); } ELSE { @@ -318,11 +319,11 @@ ISM_MODE ism_mode = ISM_MODE_NONE; move16(); st_fx->old_ind_deltaMax = 0; move32(); - set32_fx( st_fx->old_enr_ssf_fx, 0, 2*NB_SSF ); + set32_fx( st_fx->old_enr_ssf_fx, 0, 2 * NB_SSF ); st_fx->spike_hyst = -1; move16(); st_fx->music_hysteresis_fx = 0; - move16(); /* Counter of frames after AUDIO frame to prevent UC */ + move16(); /* Counter of frames after AUDIO frame to prevent UC */ st_fx->last_harm_flag_acelp = 0; move16(); st_fx->GSC_noisy_speech = 0; @@ -335,22 +336,26 @@ ISM_MODE ism_mode = ISM_MODE_NONE; st_fx->last_vad_spa_fx = 0; move16(); - /*-----------------------------------------------------------------* - * VAD - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * VAD + *-----------------------------------------------------------------*/ st_fx->vad_flag = 1; st_fx->localVAD = 0; - move16();move16(); - test();test();test();test(); - IF ((idchan == 0 || EQ_16(st_fx->element_mode, IVAS_CPE_TD) || EQ_16(st_fx->element_mode, IVAS_CPE_MDCT) || EQ_16(st_fx->element_mode, EVS_MONO)) && (!vad_only_flag)) + move16(); + move16(); + test(); + test(); + test(); + test(); + IF( ( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) || EQ_16( st_fx->element_mode, EVS_MONO ) ) && ( !vad_only_flag ) ) { - if ((st_fx->hVAD = (VAD_HANDLE)count_malloc(sizeof(VAD_DATA))) == NULL) + if ( ( st_fx->hVAD = (VAD_HANDLE) count_malloc( sizeof( VAD_DATA ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VAD\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VAD\n" ) ); } - wb_vad_init_fx(st_fx->hVAD); + wb_vad_init_fx( st_fx->hVAD ); st_fx->hVAD->prim_act_quick_fx = 0; move16(); st_fx->hVAD->prim_act_slow_fx = 0; @@ -384,23 +389,26 @@ ISM_MODE ism_mode = ISM_MODE_NONE; st_fx->hVAD = NULL; } - st_fx->Pos_relE_cnt = 5120; move16(); /*20.0f*/ - st_fx->nb_active_frames_HE_SAD_fx = 0;move16(); - st_fx->lp_speech_fx = 11520;move16(); /*Q8 (45.0) */ /* Initialize the long-term active speech level in dB */ + st_fx->Pos_relE_cnt = 5120; + move16(); /*20.0f*/ + st_fx->nb_active_frames_HE_SAD_fx = 0; + move16(); + st_fx->lp_speech_fx = 11520; + move16(); /*Q8 (45.0) */ /* Initialize the long-term active speech level in dB */ /* avoid uninitialized memory access */ /*-----------------------------------------------------------------* * Noise estimator *-----------------------------------------------------------------*/ - //PMT("deal with idchan ") - IF (/*idchan == 0 ||*/ EQ_16(st_fx->element_mode, IVAS_CPE_TD) || EQ_16(st_fx->element_mode, IVAS_CPE_MDCT) || EQ_16(st_fx->element_mode, EVS_MONO) ) + // PMT("deal with idchan ") + IF( /*idchan == 0 ||*/ EQ_16( st_fx->element_mode, IVAS_CPE_TD ) || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) || EQ_16( st_fx->element_mode, EVS_MONO ) ) { - if ((st_fx->hNoiseEst = (NOISE_EST_HANDLE)count_malloc(sizeof(NOISE_EST_DATA))) == NULL) + if ( ( st_fx->hNoiseEst = (NOISE_EST_HANDLE) count_malloc( sizeof( NOISE_EST_DATA ) ) ) == NULL ) { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Noise estimation\n"); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Noise estimation\n" ); } - noise_est_init_fx(st_fx->hNoiseEst); + noise_est_init_fx( st_fx->hNoiseEst ); } ELSE { @@ -410,41 +418,44 @@ ISM_MODE ism_mode = ISM_MODE_NONE; /*-----------------------------------------------------------------* * Speech/music classifier *-----------------------------------------------------------------*/ - test();test(); - IF (idchan == 0 || EQ_16(st_fx->element_mode, IVAS_CPE_TD) || EQ_16(st_fx->element_mode, IVAS_CPE_MDCT) || EQ_16(st_fx->element_mode, EVS_MONO) ) + test(); + test(); + IF( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) || EQ_16( st_fx->element_mode, EVS_MONO ) ) { - IF ((st_fx->hSpMusClas = (SP_MUS_CLAS_HANDLE)count_malloc(sizeof(SP_MUS_CLAS_DATA))) == NULL) + IF( ( st_fx->hSpMusClas = (SP_MUS_CLAS_HANDLE) count_malloc( sizeof( SP_MUS_CLAS_DATA ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Speech/music classifier\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Speech/music classifier\n" ) ); } - speech_music_clas_init_fx(st_fx->hSpMusClas); + speech_music_clas_init_fx( st_fx->hSpMusClas ); st_fx->sp_aud_decision0 = 0; st_fx->sp_aud_decision1 = 0; st_fx->sp_aud_decision2 = 0; - move16();move16();move16(); + move16(); + move16(); + move16(); } ELSE { st_fx->hSpMusClas = NULL; } - st_fx->bckr_tilt_lt=0; + st_fx->bckr_tilt_lt = 0; move32(); /* WB, SWB and FB bandwidth detector */ - st_fx->lt_mean_NB_fx = 0; + st_fx->lt_mean_NB_fx = 0; move16(); - st_fx->lt_mean_WB_fx = 0; + st_fx->lt_mean_WB_fx = 0; move16(); st_fx->lt_mean_SWB_fx = 0; move16(); - st_fx->count_WB = BWD_COUNT_MAX; + st_fx->count_WB = BWD_COUNT_MAX; move16(); st_fx->count_SWB = BWD_COUNT_MAX; move16(); - st_fx->count_FB = BWD_COUNT_MAX; + st_fx->count_FB = BWD_COUNT_MAX; move16(); st_fx->bwidth = st_fx->max_bwidth; move16(); @@ -459,20 +470,22 @@ ISM_MODE ism_mode = ISM_MODE_NONE; move16(); st_fx->coder_type_raw = VOICED; st_fx->last_coder_type_raw = st_fx->coder_type_raw; - - st_fx->is_ism_format = 0; move16(); - if (NE_16(ism_mode, ISM_MODE_NONE) ) + + st_fx->is_ism_format = 0; + move16(); + if ( NE_16( ism_mode, ISM_MODE_NONE ) ) { - st_fx->is_ism_format = 1; move16(); + st_fx->is_ism_format = 1; + move16(); } /* Stationary noise UV modification */ st_fx->ge_sm_fx = 640; - move32();/*Q(GE_SHIFT) */ + move32(); /*Q(GE_SHIFT) */ st_fx->uv_count = 0; move16(); st_fx->act_count = 3; move16(); - Copy(st_fx->lsp_old_fx, st_fx->lspold_s_fx, M); + Copy( st_fx->lsp_old_fx, st_fx->lspold_s_fx, M ); st_fx->noimix_seed = RANDOM_INITSEED; move16(); st_fx->min_alpha_fx = 1; @@ -484,15 +497,15 @@ ISM_MODE ism_mode = ISM_MODE_NONE; st_fx->lp_noise_fx = 0; move16(); - test();test(); - IF (((idchan == 0 && st_fx->Opt_DTX_ON) || EQ_16(st_fx->element_mode, EVS_MONO)) || (EQ_16(st_fx->element_mode, IVAS_CPE_MDCT) && st_fx->Opt_DTX_ON)) + test(); + test(); + IF( ( ( idchan == 0 && st_fx->Opt_DTX_ON ) || EQ_16( st_fx->element_mode, EVS_MONO ) ) || ( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) && st_fx->Opt_DTX_ON ) ) { - if ((st_fx->hDtxEnc = (DTX_ENC_HANDLE)count_malloc(sizeof(DTX_ENC_DATA))) == NULL) + if ( ( st_fx->hDtxEnc = (DTX_ENC_HANDLE) count_malloc( sizeof( DTX_ENC_DATA ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX variables\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX variables\n" ) ); } - dtx_enc_init_fx(st_fx, st_fx->var_SID_rate_flag_fx, st_fx->interval_SID_fx); - + dtx_enc_init_fx( st_fx, st_fx->var_SID_rate_flag_fx, st_fx->interval_SID_fx ); } ELSE { @@ -512,19 +525,21 @@ ISM_MODE ism_mode = ISM_MODE_NONE; move16(); - /*-----------------------------------------------------------------* - * LP-CNG - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * LP-CNG + *-----------------------------------------------------------------*/ - test();test();test(); - IF (((idchan == 0 && st_fx->Opt_DTX_ON && NE_16(st_fx->element_mode, IVAS_CPE_MDCT)) || EQ_16(st_fx->element_mode, EVS_MONO)) && !(EQ_16(ism_mode, ISM_MODE_PARAM) || EQ_16(ism_mode, ISM_MODE_DISC))) + test(); + test(); + test(); + IF( ( ( idchan == 0 && st_fx->Opt_DTX_ON && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, EVS_MONO ) ) && !( EQ_16( ism_mode, ISM_MODE_PARAM ) || EQ_16( ism_mode, ISM_MODE_DISC ) ) ) { - IF ((st_fx->hTdCngEnc = (TD_CNG_ENC_HANDLE)count_malloc(sizeof(TD_CNG_ENC_DATA))) == NULL) + IF( ( st_fx->hTdCngEnc = (TD_CNG_ENC_HANDLE) count_malloc( sizeof( TD_CNG_ENC_DATA ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX/TD CNG\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX/TD CNG\n" ) ); } - td_cng_enc_init_fx(st_fx->hTdCngEnc, st_fx->Opt_DTX_ON, st_fx->max_bwidth); + td_cng_enc_init_fx( st_fx->hTdCngEnc, st_fx->Opt_DTX_ON, st_fx->max_bwidth ); } ELSE { @@ -536,33 +551,34 @@ ISM_MODE ism_mode = ISM_MODE_NONE; * ACELP LPDmem *-----------------------------------------------------------------*/ - test();test(); - IF ((idchan == 0 && NE_16(st_fx->element_mode, IVAS_CPE_MDCT)) || EQ_16(st_fx->element_mode, IVAS_CPE_TD)) + test(); + test(); + IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) { - IF ((st_fx->hLPDmem = (LPD_state_HANDLE)count_malloc(sizeof(LPD_state))) == NULL) + IF( ( st_fx->hLPDmem = (LPD_state_HANDLE) count_malloc( sizeof( LPD_state ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LPDmem\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LPDmem\n" ) ); } - LPDmem_enc_init_fx(st_fx->hLPDmem); + LPDmem_enc_init_fx( st_fx->hLPDmem ); } ELSE { st_fx->hLPDmem = NULL; } - /* FEC */ + /* FEC */ st_fx->last_clas = UNVOICED_CLAS; move16(); - FOR (i=0; i<2*NB_SUBFR16k; i++) + FOR( i = 0; i < 2 * NB_SUBFR16k; i++ ) { st_fx->old_pitch_buf_fx[i] = L_SUBFR_Q6; move16(); } st_fx->old_Es_pred_fx = 0; move16(); - set16_fx(st_fx->old_Aq_12_8_fx + 1, 0, M ); + set16_fx( st_fx->old_Aq_12_8_fx + 1, 0, M ); st_fx->old_Aq_12_8_fx[0] = 4096; move16(); @@ -571,12 +587,12 @@ ISM_MODE ism_mode = ISM_MODE_NONE; *-----------------------------------------------------------------*/ /* open analysis for input SR */ - if ((error = openCldfb ( &st_fx->cldfbAnaEnc, CLDFB_ANALYSIS, CLDFB_getNumChannels(st_fx->input_Fs), st_fx->input_frame_fx)) != IVAS_ERR_OK) + if ( ( error = openCldfb( &st_fx->cldfbAnaEnc, CLDFB_ANALYSIS, CLDFB_getNumChannels( st_fx->input_Fs ), st_fx->input_frame_fx ) ) != IVAS_ERR_OK ) { return error; } - if ((error = openCldfb ( &st_fx->cldfbSynTd, CLDFB_SYNTHESIS, CLDFB_getNumChannels(16000), L_FRAME16k)) != IVAS_ERR_OK) + if ( ( error = openCldfb( &st_fx->cldfbSynTd, CLDFB_SYNTHESIS, CLDFB_getNumChannels( 16000 ), L_FRAME16k ) ) != IVAS_ERR_OK ) { return error; } @@ -600,29 +616,29 @@ ISM_MODE ism_mode = ISM_MODE_NONE; st_fx->energy_sm_fx = 0; move32(); - /*-----------------------------------------------------------------* - * SC-VBR parameters - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * SC-VBR parameters + *-----------------------------------------------------------------*/ test(); - IF (st_fx->Opt_SC_VBR || EQ_16(st_fx->element_mode, EVS_MONO)) + IF( st_fx->Opt_SC_VBR || EQ_16( st_fx->element_mode, EVS_MONO ) ) { - IF ((st_fx->hSC_VBR = (SC_VBR_ENC_HANDLE)count_malloc(sizeof(SC_VBR_ENC_DATA))) == NULL) + IF( ( st_fx->hSC_VBR = (SC_VBR_ENC_HANDLE) count_malloc( sizeof( SC_VBR_ENC_DATA ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SC-VBR\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SC-VBR\n" ) ); } - sc_vbr_enc_init_fx(st_fx->hSC_VBR); + sc_vbr_enc_init_fx( st_fx->hSC_VBR ); } ELSE { st_fx->hSC_VBR = NULL; } /* PLC encoder */ - IF (EQ_16(st_fx->element_mode, EVS_MONO)) + IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) { - IF ((st_fx->hPlcExt = (PLC_ENC_EVS_HANDLE)count_malloc(sizeof(PLC_ENC_EVS))) == NULL) + IF( ( st_fx->hPlcExt = (PLC_ENC_EVS_HANDLE) count_malloc( sizeof( PLC_ENC_EVS ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hPlcExt\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hPlcExt\n" ) ); } } ELSE @@ -630,14 +646,14 @@ ISM_MODE ism_mode = ISM_MODE_NONE; st_fx->hPlcExt = NULL; } /*-----------------------------------------------------------------* - * Temporal Envelope Coding - *-----------------------------------------------------------------*/ + * Temporal Envelope Coding + *-----------------------------------------------------------------*/ - IF (st_fx->element_mode == EVS_MONO) + IF( st_fx->element_mode == EVS_MONO ) { - IF ((st_fx->hTECEnc = (TEC_ENC_HANDLE)count_malloc(sizeof(TEC_ENC_DATA))) == NULL) + IF( ( st_fx->hTECEnc = (TEC_ENC_HANDLE) count_malloc( sizeof( TEC_ENC_DATA ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TEC\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TEC\n" ) ); } } ELSE @@ -649,11 +665,11 @@ ISM_MODE ism_mode = ISM_MODE_NONE; * Bitstream *-----------------------------------------------------------------*/ - IF (!vad_only_flag) + IF( !vad_only_flag ) { - IF ((st_fx->hBstr = (BSTR_ENC_HANDLE)count_malloc(sizeof(BSTR_ENC_DATA))) == NULL) + IF( ( st_fx->hBstr = (BSTR_ENC_HANDLE) count_malloc( sizeof( BSTR_ENC_DATA ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Bitstream structure\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Bitstream structure\n" ) ); } } ELSE @@ -661,17 +677,17 @@ ISM_MODE ism_mode = ISM_MODE_NONE; st_fx->hBstr = NULL; } - /*-----------------------------------------------------------------* + /*-----------------------------------------------------------------* * SWB BWE parameters *-----------------------------------------------------------------*/ - IF (idchan == 0 && NE_16(st_fx->element_mode, IVAS_CPE_MDCT)) + IF( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) { - IF ((st_fx->hBWE_FD = (FD_BWE_ENC_HANDLE)count_malloc(sizeof(FD_BWE_ENC_DATA))) == NULL) + IF( ( st_fx->hBWE_FD = (FD_BWE_ENC_HANDLE) count_malloc( sizeof( FD_BWE_ENC_DATA ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FD BWE\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FD BWE\n" ) ); } - fd_bwe_enc_init_fx(st_fx->hBWE_FD); + fd_bwe_enc_init_fx( st_fx->hBWE_FD ); } ELSE { @@ -687,37 +703,37 @@ ISM_MODE ism_mode = ISM_MODE_NONE; * TBE parameters *-----------------------------------------------------------------*/ - IF (idchan == 0 && NE_16(st_fx->element_mode, IVAS_CPE_MDCT)) + IF( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) { - IF ((st_fx->hBWE_TD = (TD_BWE_ENC_HANDLE)count_malloc(sizeof(TD_BWE_ENC_DATA))) == NULL) + IF( ( st_fx->hBWE_TD = (TD_BWE_ENC_HANDLE) count_malloc( sizeof( TD_BWE_ENC_DATA ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD BWE\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD BWE\n" ) ); } - //IF ((error = openCldfb(&st_fx->cldfbSynTd, CLDFB_SYNTHESIS, 16000, CLDFB_PROTOTYPE_1_25MS)) != IVAS_ERR_OK) + // IF ((error = openCldfb(&st_fx->cldfbSynTd, CLDFB_SYNTHESIS, 16000, CLDFB_PROTOTYPE_1_25MS)) != IVAS_ERR_OK) //{ - // return error; - //} + // return error; + // } - InitSWBencBuffer_fx(st_fx/*st_fx->hBWE_TD*/); - ResetSHBbuffer_Enc_fx(st_fx/*st_fx->hBWE_TD*/); + InitSWBencBuffer_fx( st_fx /*st_fx->hBWE_TD*/ ); + ResetSHBbuffer_Enc_fx( st_fx /*st_fx->hBWE_TD*/ ); } ELSE { st_fx->hBWE_TD = NULL; - //st_fx->cldfbSynTd = NULL; + // st_fx->cldfbSynTd = NULL; } - IF (st_fx->Opt_RF_ON || EQ_16(st_fx->element_mode, EVS_MONO)) + IF( st_fx->Opt_RF_ON || EQ_16( st_fx->element_mode, EVS_MONO ) ) { - IF ((st_fx->hRF = (RF_ENC_HANDLE)count_malloc(sizeof(RF_ENC_DATA))) == NULL) + IF( ( st_fx->hRF = (RF_ENC_HANDLE) count_malloc( sizeof( RF_ENC_DATA ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for RF\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for RF\n" ) ); } /* initialize RF indice buffers */ - reset_rf_indices_fx(st_fx/*->hRF, st_fx->L_frame, &st->rf_target_bits_write*/); + reset_rf_indices_fx( st_fx /*->hRF, st_fx->L_frame, &st->rf_target_bits_write*/ ); } ELSE { @@ -729,14 +745,14 @@ ISM_MODE ism_mode = ISM_MODE_NONE; * HQ core parameters *-----------------------------------------------------------------*/ - st_fx->input_fx = st_fx->input_buff_fx +L_FRAME48k+NS2SA(48000, DELAY_FIR_RESAMPL_NS); - set16_fx( st_fx->input_buff_fx +L_FRAME48k, 0, L_FRAME48k+NS2SA(48000, DELAY_FIR_RESAMPL_NS) ); - st_fx->old_input_signal_fx = st_fx->input_fx - add(NS2SA_fx2(st_fx->input_Fs, DELAY_FIR_RESAMPL_NS), st_fx->input_frame_fx); + st_fx->input_fx = st_fx->input_buff_fx + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ); + set16_fx( st_fx->input_buff_fx + L_FRAME48k, 0, L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); + st_fx->old_input_signal_fx = st_fx->input_fx - add( NS2SA_fx2( st_fx->input_Fs, DELAY_FIR_RESAMPL_NS ), st_fx->input_frame_fx ); st_fx->Energy_Old_fx = 0; move16(); - st_fx->Q_old_wtda=15; + st_fx->Q_old_wtda = 15; move16(); st_fx->EnergyLT_fx = 1; move32(); @@ -749,51 +765,52 @@ ISM_MODE ism_mode = ISM_MODE_NONE; * TCX core *-----------------------------------------------------------------*/ - // VE: reduction possible for MCT_CHAN_MODE_LFE channel - see I1-172 - IF (idchan == 0 || EQ_16(st_fx->element_mode, IVAS_CPE_MDCT)) + // VE: reduction possible for MCT_CHAN_MODE_LFE channel - see I1-172 + IF( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) { - IF ((st_fx->hTcxEnc = (TCX_ENC_HANDLE)count_malloc(sizeof(TCX_ENC_DATA))) == NULL) + IF( ( st_fx->hTcxEnc = (TCX_ENC_HANDLE) count_malloc( sizeof( TCX_ENC_DATA ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxEnc\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxEnc\n" ) ); } /* Share the memories for 2xTCX10/4xTCX5 and for TCX20 */ /*st_fx->hTcxEnc->spectrum[0] = st_fx->hTcxEnc->spectrum_long; st_fx->hTcxEnc->spectrum[1] = st_fx->hTcxEnc->spectrum_long + N_TCX10_MAX;*/ - set16_fx(st_fx->hTcxEnc->old_out_fx, 0, L_FRAME32k); + set16_fx( st_fx->hTcxEnc->old_out_fx, 0, L_FRAME32k ); /* MDCT selector */ - MDCT_selector_reset_fx(st_fx->hTcxEnc); + MDCT_selector_reset_fx( st_fx->hTcxEnc ); st_fx->hTcxEnc->Q_old_out = 0; move16(); /* MDCT classifier */ - MDCT_classifier_reset_fx(st_fx->hTcxEnc); + MDCT_classifier_reset_fx( st_fx->hTcxEnc ); - IF ((st_fx->hTcxCfg = (TCX_CONFIG_HANDLE)count_malloc(sizeof(TCX_config))) == NULL) + IF( ( st_fx->hTcxCfg = (TCX_CONFIG_HANDLE) count_malloc( sizeof( TCX_config ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxCfg\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxCfg\n" ) ); } } else { st_fx->hTcxEnc = NULL; - //st_fx->hTcxCfg = NULL; + // st_fx->hTcxCfg = NULL; } - /*-----------------------------------------------------------------* - * HQ core parameters - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * HQ core parameters + *-----------------------------------------------------------------*/ - test();test(); - IF (NE_16(st_fx->element_mode, IVAS_CPE_TD) && NE_16(st_fx->element_mode, IVAS_CPE_MDCT) && idchan == 0) + test(); + test(); + IF( NE_16( st_fx->element_mode, IVAS_CPE_TD ) && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) && idchan == 0 ) { - IF ((st_fx->hHQ_core = (HQ_ENC_HANDLE)count_malloc(sizeof(HQ_ENC_DATA))) == NULL) + IF( ( st_fx->hHQ_core = (HQ_ENC_HANDLE) count_malloc( sizeof( HQ_ENC_DATA ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HQ core\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HQ core\n" ) ); } - HQ_core_enc_init_fx(st_fx->hHQ_core); + HQ_core_enc_init_fx( st_fx->hHQ_core ); } ELSE { @@ -811,12 +828,12 @@ ISM_MODE ism_mode = ISM_MODE_NONE; test(); test(); test(); - IF( st_fx->Opt_RF_ON == 0 || (NE_16(st_fx->bwidth,WB)&&NE_16(st_fx->bwidth,SWB))||NE_32(st_fx->total_brate,ACELP_13k20)) + IF( st_fx->Opt_RF_ON == 0 || ( NE_16( st_fx->bwidth, WB ) && NE_16( st_fx->bwidth, SWB ) ) || NE_32( st_fx->total_brate, ACELP_13k20 ) ) { - IF (EQ_16(st_fx->Opt_RF_ON,1)) + IF( EQ_16( st_fx->Opt_RF_ON, 1 ) ) { - printf("\nWarning: Channel-aware mode only available for 13.2 kbps WB/SWB\n"); - printf(" Switched to normal mode!\n"); + printf( "\nWarning: Channel-aware mode only available for 13.2 kbps WB/SWB\n" ); + printf( " Switched to normal mode!\n" ); st_fx->Opt_RF_ON = 0; move16(); st_fx->rf_fec_offset = 0; @@ -839,18 +856,19 @@ ISM_MODE ism_mode = ISM_MODE_NONE; * MODE2 initialization *-----------------------------------------------------------------*/ - st_fx->last_sr_core = i_mult2 (st_fx->last_L_frame, 50); + st_fx->last_sr_core = i_mult2( st_fx->last_L_frame, 50 ); /*-----------------------------------------------------------------* * IGF *-----------------------------------------------------------------*/ - test();test(); - IF (idchan == 0 || EQ_16(st_fx->element_mode, IVAS_CPE_MDCT)) + test(); + test(); + IF( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) { - IF ((st_fx->hIGFEnc = (IGF_ENC_INSTANCE_HANDLE)count_malloc(sizeof(IGF_ENC_INSTANCE))) == NULL) + IF( ( st_fx->hIGFEnc = (IGF_ENC_INSTANCE_HANDLE) count_malloc( sizeof( IGF_ENC_INSTANCE ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hIGFEnc\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hIGFEnc\n" ) ); } } ELSE @@ -859,9 +877,9 @@ ISM_MODE ism_mode = ISM_MODE_NONE; move16(); } - IF( EQ_16(st_fx->codec_mode, MODE2)) + IF( EQ_16( st_fx->codec_mode, MODE2 ) ) { - st_fx->igf = getIgfPresent_fx(st_fx->element_mode, st_fx->total_brate, st_fx->bwidth, st_fx->rf_mode); + st_fx->igf = getIgfPresent_fx( st_fx->element_mode, st_fx->total_brate, st_fx->bwidth, st_fx->rf_mode ); } ELSE { @@ -870,12 +888,12 @@ ISM_MODE ism_mode = ISM_MODE_NONE; } /* FD-CNG encoder */ - createFdCngEnc_fx(&st_fx->hFdCngEnc); - initFdCngEnc_fx(st_fx->hFdCngEnc, st_fx->input_Fs, st_fx->cldfbAnaEnc->scale); + createFdCngEnc_fx( &st_fx->hFdCngEnc ); + initFdCngEnc_fx( st_fx->hFdCngEnc, st_fx->input_Fs, st_fx->cldfbAnaEnc->scale ); L_tmp = st_fx->total_brate; move32(); test(); - if( st_fx->rf_mode && EQ_32(st_fx->total_brate,ACELP_13k20)) + if ( st_fx->rf_mode && EQ_32( st_fx->total_brate, ACELP_13k20 ) ) { L_tmp = ACELP_9k60; move32(); @@ -887,21 +905,21 @@ ISM_MODE ism_mode = ISM_MODE_NONE; set16_fx( st_fx->totalNoise_increase_hist_fx, 0, TOTALNOISE_HIST_SIZE ); st_fx->totalNoise_increase_len = 0; move16(); - init_coder_ace_plus_fx( st_fx, st_fx->last_total_brate, 0, -10 /*hack*/); -//PMT("Transient detector init needs review, handle hTranDet is missing") - InitTransientDetection_fx( extract_l(Mult_32_16(st_fx->input_Fs, 0x0290)), - NS2SA_fx2(st_fx->input_Fs, DELAY_FIR_RESAMPL_NS), - &st_fx->transientDetection ); + init_coder_ace_plus_fx( st_fx, st_fx->last_total_brate, 0, -10 /*hack*/ ); + // PMT("Transient detector init needs review, handle hTranDet is missing") + InitTransientDetection_fx( extract_l( Mult_32_16( st_fx->input_Fs, 0x0290 ) ), + NS2SA_fx2( st_fx->input_Fs, DELAY_FIR_RESAMPL_NS ), + &st_fx->transientDetection ); - //reset_indices_enc_fx( st_fx->hBstr); + // reset_indices_enc_fx( st_fx->hBstr); st_fx->Q_syn2 = 0; move16(); st_fx->Q_syn = 0; move16(); - set16_fx(st_fx->Q_max, Q_MAX, L_Q_MEM); - set16_fx(st_fx->Q_max_16k, Q_MAX, L_Q_MEM); + set16_fx( st_fx->Q_max, Q_MAX, L_Q_MEM ); + set16_fx( st_fx->Q_max_16k, Q_MAX, L_Q_MEM ); st_fx->Q_old = 15; move16(); st_fx->old_wsp_max = 0; @@ -911,26 +929,26 @@ ISM_MODE ism_mode = ISM_MODE_NONE; st_fx->sharpFlag = 0; move16(); - st_fx->tdm_LRTD_flag = 0; /* LRTD stereo mode flag */ - st_fx->cna_dirac_flag = 0; /* CNA in DirAC flag */ - st_fx->cng_sba_flag = 0; /* CNG in SBA flag */ - st_fx->GSC_IVAS_mode = 0; /* CNG in SBA flag */ - st_fx->element_mode = EVS_MONO; /* element mode */ + st_fx->tdm_LRTD_flag = 0; /* LRTD stereo mode flag */ + st_fx->cna_dirac_flag = 0; /* CNA in DirAC flag */ + st_fx->cng_sba_flag = 0; /* CNG in SBA flag */ + st_fx->GSC_IVAS_mode = 0; /* CNG in SBA flag */ + st_fx->element_mode = EVS_MONO; /* element mode */ st_fx->last_element_mode = st_fx->element_mode; /* element mode */ - st_fx->element_brate = -1; /* element bitrate */ - //PMT("element_mode and element_brate should be initialized at a proper place in ivas_dec_init eventually") - st_fx->low_rate_mode = 0; /* low-rate mode flag */ - //st_fx->coder_type = GENERIC; /* low-rate mode flag */ + st_fx->element_brate = -1; /* element bitrate */ + // PMT("element_mode and element_brate should be initialized at a proper place in ivas_dec_init eventually") + st_fx->low_rate_mode = 0; /* low-rate mode flag */ + // st_fx->coder_type = GENERIC; /* low-rate mode flag */ - set16_fx(st_fx->pitch_fx, L_SUBFR, 3); - set16_fx(st_fx->voicing_fx, 0, 3); + set16_fx( st_fx->pitch_fx, L_SUBFR, 3 ); + set16_fx( st_fx->voicing_fx, 0, 3 ); #ifdef DEBUGGING st_fx->id_element = -1; /* element ID */ #endif - st_fx->extl_orig = -1; /* extension layer */ - st_fx->extl_brate_orig = 0; /* extension layer bitrate */ + st_fx->extl_orig = -1; /* extension layer */ + st_fx->extl_brate_orig = 0; /* extension layer bitrate */ return error; } @@ -946,26 +964,29 @@ void LPDmem_enc_init_fx( { Word16 i; - set16_fx(hLPDmem->syn, 0, 1 + M); - set16_fx(hLPDmem->old_exc, 0, L_EXC_MEM); - set16_fx(hLPDmem->mem_syn, 0, M); - set16_fx(hLPDmem->mem_syn1_fx, 0, M); - set16_fx(hLPDmem->mem_syn2, 0, M); - set16_fx(hLPDmem->mem_syn_r, 0, L_SYN_MEM); - set16_fx(hLPDmem->mem_syn3, 0, M); - - hLPDmem->mem_w0 = 0; move16(); - hLPDmem->tilt_code = 0; move16(); - hLPDmem->gc_threshold = 0; move32(); + set16_fx( hLPDmem->syn, 0, 1 + M ); + set16_fx( hLPDmem->old_exc, 0, L_EXC_MEM ); + set16_fx( hLPDmem->mem_syn, 0, M ); + set16_fx( hLPDmem->mem_syn1_fx, 0, M ); + set16_fx( hLPDmem->mem_syn2, 0, M ); + set16_fx( hLPDmem->mem_syn_r, 0, L_SYN_MEM ); + set16_fx( hLPDmem->mem_syn3, 0, M ); + + hLPDmem->mem_w0 = 0; + move16(); + hLPDmem->tilt_code = 0; + move16(); + hLPDmem->gc_threshold = 0; + move32(); #if 0 //set16_fx(hLPDmem->dispMem, 0, 8); #else hLPDmem->dm_fx.prev_state = 0; - move16(); /* This corresponds to st_fx->dispMem in FLP */ + move16(); /* This corresponds to st_fx->dispMem in FLP */ hLPDmem->dm_fx.prev_gain_code = 0; move32(); - FOR(i = 2; i < 8; i++) + FOR( i = 2; i < 8; i++ ) { hLPDmem->dm_fx.prev_gain_pit[i - 2] = 0; move16(); @@ -980,7 +1001,7 @@ void LPDmem_enc_init_fx( *-----------------------------------------------------------------------*/ void destroy_encoder_fx( - Encoder_State *st_fx /* i/o: Encoder static variables structure */ + Encoder_State *st_fx /* i/o: Encoder static variables structure */ ) { deleteCldfb( &st_fx->cldfbAnaEnc ); diff --git a/lib_enc/inov_enc_fx.c b/lib_enc/inov_enc_fx.c index ca2d20f07..3b21cb7e7 100644 --- a/lib_enc/inov_enc_fx.c +++ b/lib_enc/inov_enc_fx.c @@ -2,15 +2,15 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ //#include "prot_fx.h" /* Function prototypes */ #include "basop_util.h" -#include "rom_com_fx.h" /* Static table prototypes */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "rom_com_fx.h" /* Static table prototypes */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*==============================================================================*/ @@ -58,32 +58,31 @@ /*==============================================================================*/ Word16 inov_encode_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 last_L_frame, /* i : length of the last frame */ - const Word16 coder_type, /* i : coding type */ - const Word16 bwidth, /* i : input signal bandwidth */ - const Word16 sharpFlag, /* i : formant sharpening flag */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 tc_subfr, /* i : TC subframe index */ - const Word16 *p_Aq, /* i : LP filter coefficients Q12*/ - const Word16 gain_pit, /* i : adaptive excitation gain Q14*/ - Word16 *cn, /* i/o: target vector in residual domain Q_new*/ - const Word16 *exc, /* i : pointer to excitation signal frame Q_new*/ - Word16 *h2, /* i/o: weighted filter input response Q12*/ - const Word16 tilt_code, /* i : tilt of the excitation of previous subframe Q15*/ - const Word16 pt_pitch, /* i : pointer to current subframe fractional pitch Q6*/ - const Word16 *xn2, /* i : target vector for innovation search Q_new-1+shift*/ - Word16 *code, /* o : algebraic excitation Q9*/ - Word16 *y2, /* o : zero-memory filtered algebraic excitation Q9*/ - Word16 *unbits, /* o : number of unused bits for PI */ - const Word16 L_subfr, /* i : subframe length */ - Word16 shift -) + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const Word16 L_frame, /* i : length of the frame */ + const Word16 last_L_frame, /* i : length of the last frame */ + const Word16 coder_type, /* i : coding type */ + const Word16 bwidth, /* i : input signal bandwidth */ + const Word16 sharpFlag, /* i : formant sharpening flag */ + const Word16 i_subfr, /* i : subframe index */ + const Word16 tc_subfr, /* i : TC subframe index */ + const Word16 *p_Aq, /* i : LP filter coefficients Q12*/ + const Word16 gain_pit, /* i : adaptive excitation gain Q14*/ + Word16 *cn, /* i/o: target vector in residual domain Q_new*/ + const Word16 *exc, /* i : pointer to excitation signal frame Q_new*/ + Word16 *h2, /* i/o: weighted filter input response Q12*/ + const Word16 tilt_code, /* i : tilt of the excitation of previous subframe Q15*/ + const Word16 pt_pitch, /* i : pointer to current subframe fractional pitch Q6*/ + const Word16 *xn2, /* i : target vector for innovation search Q_new-1+shift*/ + Word16 *code, /* o : algebraic excitation Q9*/ + Word16 *y2, /* o : zero-memory filtered algebraic excitation Q9*/ + Word16 *unbits, /* o : number of unused bits for PI */ + const Word16 L_subfr, /* i : subframe length */ + Word16 shift ) { - Word16 dn[2*L_SUBFR]; + Word16 dn[2 * L_SUBFR]; Word16 nBits, cmpl_flag; Word16 stack_pulses; Word16 g1, g2; @@ -91,12 +90,12 @@ Word16 inov_encode_fx( Word16 acelpautoc; BSTR_ENC_HANDLE hBstr = st_fx->hBstr; #ifdef REMOVE_IVAS_UNUSED_PARAMETERS_WARNING - (void)last_L_frame; + (void) last_L_frame; #endif stack_pulses = 0; move16(); - IF( EQ_16(L_frame,L_FRAME)) + IF( EQ_16( L_frame, L_FRAME ) ) { g1 = FORMANT_SHARPENING_G1; move16(); @@ -119,16 +118,16 @@ Word16 inov_encode_fx( test(); test(); - IF (GT_32(core_brate, ACELP_13k20) && !Opt_AMR_WB && EQ_16(L_subfr, L_SUBFR)) + IF( GT_32( core_brate, ACELP_13k20 ) && !Opt_AMR_WB && EQ_16( L_subfr, L_SUBFR ) ) { acelpautoc = 1; move16(); - cb_shape_fx( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, h2, tilt_code, shr(add(pt_pitch,26),6), 0 , L_SUBFR); + cb_shape_fx( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, h2, tilt_code, shr( add( pt_pitch, 26 ), 6 ), 0, L_SUBFR ); /* h2: Q11, Rw: (Rw_e)Q */ - /* Rw_e = */ E_ACELP_hh_corr(h2, Rw, L_SUBFR, 3); + /* Rw_e = */ E_ACELP_hh_corr( h2, Rw, L_SUBFR, 3 ); - E_ACELP_conv(xn2, h2, cn); + E_ACELP_conv( xn2, h2, cn ); /* dn_e -> Rw_e*Q_xn */ /*dn_e = */ E_ACELP_toeplitz_mul_fx( Rw, cn, dn, L_SUBFR, 1 ); @@ -139,9 +138,9 @@ Word16 inov_encode_fx( move16(); updt_tar_fx( cn, cn, &exc[i_subfr], gain_pit, L_subfr ); /* scaling of cn[] to limit dynamic at 12 bits */ - Scale_sig(cn, L_subfr, shift); + Scale_sig( cn, L_subfr, shift ); - cb_shape_fx( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, h2, tilt_code, shr(add(pt_pitch,26),6), 0 , L_subfr); + cb_shape_fx( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, h2, tilt_code, shr( add( pt_pitch, 26 ), 6 ), 0, L_subfr ); corr_xh_fx( xn2, dn, h2 ); } @@ -152,71 +151,79 @@ Word16 inov_encode_fx( cmpl_flag = 0; move16(); test(); - IF (st_fx->acelp_cfg.fcb_mode) + IF( st_fx->acelp_cfg.fcb_mode ) { /* set number of iterations in TD stereo, secondary channel */ - if (EQ_16(st_fx->element_mode, IVAS_CPE_TD) && EQ_16(st_fx->idchan, 1)) + if ( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && EQ_16( st_fx->idchan, 1 ) ) { cmpl_flag = 1; move16(); } } - ELSE IF( EQ_16(L_frame,L_FRAME) && EQ_16(coder_type,TRANSITION)) + ELSE IF( EQ_16( L_frame, L_FRAME ) && EQ_16( coder_type, TRANSITION ) ) { - test();test(); - if( EQ_32(core_brate,ACELP_8k00) && i_subfr==0 && LT_16(tc_subfr,L_SUBFR)) + test(); + test(); + if ( EQ_32( core_brate, ACELP_8k00 ) && i_subfr == 0 && LT_16( tc_subfr, L_SUBFR ) ) { cmpl_flag = 3; move16(); } - test();test();test();test();test(); - if( EQ_32(core_brate,ACELP_11k60) && ((i_subfr==0 && LT_16(tc_subfr,L_SUBFR)) || EQ_16(tc_subfr,TC_0_0) || (EQ_16(i_subfr,3*L_SUBFR) && EQ_16(tc_subfr,TC_0_64)))) + test(); + test(); + test(); + test(); + test(); + if ( EQ_32( core_brate, ACELP_11k60 ) && ( ( i_subfr == 0 && LT_16( tc_subfr, L_SUBFR ) ) || EQ_16( tc_subfr, TC_0_0 ) || ( EQ_16( i_subfr, 3 * L_SUBFR ) && EQ_16( tc_subfr, TC_0_64 ) ) ) ) { cmpl_flag = 3; move16(); } - test();test();test();test(); - if( (EQ_32(core_brate,ACELP_13k20) || EQ_32(core_brate,ACELP_12k15)) && ((i_subfr==0 && LT_16(tc_subfr,L_SUBFR)) || LE_16(tc_subfr,TC_0_64))) + test(); + test(); + test(); + test(); + if ( ( EQ_32( core_brate, ACELP_13k20 ) || EQ_32( core_brate, ACELP_12k15 ) ) && ( ( i_subfr == 0 && LT_16( tc_subfr, L_SUBFR ) ) || LE_16( tc_subfr, TC_0_64 ) ) ) { cmpl_flag = 3; move16(); } } - IF( EQ_16(L_frame,L_FRAME16k)) + IF( EQ_16( L_frame, L_FRAME16k ) ) { - IF( LE_32(core_brate,ACELP_32k)) + IF( LE_32( core_brate, ACELP_32k ) ) { cmpl_flag = 4; move16(); test(); - IF( EQ_16(coder_type,TRANSITION)&>_16(bwidth,WB)) + IF( EQ_16( coder_type, TRANSITION ) && GT_16( bwidth, WB ) ) { - IF( LE_16(i_subfr,L_SUBFR)) + IF( LE_16( i_subfr, L_SUBFR ) ) { - cmpl_flag = sub(cmpl_flag,1); + cmpl_flag = sub( cmpl_flag, 1 ); } ELSE { - cmpl_flag = sub(cmpl_flag,2); + cmpl_flag = sub( cmpl_flag, 2 ); } } } - ELSE IF( LE_32(core_brate,ACELP_48k)) + ELSE IF( LE_32( core_brate, ACELP_48k ) ) { cmpl_flag = 3; move16(); - IF( EQ_16(coder_type,TRANSITION)) + IF( EQ_16( coder_type, TRANSITION ) ) { - IF( LE_16(i_subfr,L_SUBFR)) + IF( LE_16( i_subfr, L_SUBFR ) ) { - cmpl_flag = sub(cmpl_flag,1); + cmpl_flag = sub( cmpl_flag, 1 ); } ELSE { - cmpl_flag = sub(cmpl_flag,2); + cmpl_flag = sub( cmpl_flag, 2 ); } } } @@ -225,19 +232,19 @@ Word16 inov_encode_fx( cmpl_flag = 4; move16(); - IF( EQ_16(coder_type,TRANSITION)) + IF( EQ_16( coder_type, TRANSITION ) ) { - IF( LE_16(i_subfr,L_SUBFR)) + IF( LE_16( i_subfr, L_SUBFR ) ) { - cmpl_flag = sub(cmpl_flag,1); + cmpl_flag = sub( cmpl_flag, 1 ); } ELSE { - cmpl_flag = sub(cmpl_flag,2); + cmpl_flag = sub( cmpl_flag, 2 ); } } - if( EQ_16(coder_type,INACTIVE)) + if ( EQ_16( coder_type, INACTIVE ) ) { cmpl_flag = 4; move16(); @@ -248,11 +255,11 @@ Word16 inov_encode_fx( test(); test(); test(); - IF( NE_16(L_frame,st_fx->last_L_frame)&>_32(core_brate,ACELP_13k20)&&(LT_32(core_brate,ACELP_32k)||EQ_16(bwidth,WB))) + IF( NE_16( L_frame, st_fx->last_L_frame ) && GT_32( core_brate, ACELP_13k20 ) && ( LT_32( core_brate, ACELP_32k ) || EQ_16( bwidth, WB ) ) ) { - if( GT_16(cmpl_flag,1)) + if ( GT_16( cmpl_flag, 1 ) ) { - cmpl_flag = sub(cmpl_flag,1); + cmpl_flag = sub( cmpl_flag, 1 ); } } @@ -262,66 +269,66 @@ Word16 inov_encode_fx( set16_fx( y2, 0, L_SUBFR ); - IF ( !Opt_AMR_WB ) + IF( !Opt_AMR_WB ) { - IF (st_fx->acelp_cfg.fcb_mode) - { //PMTE() + IF( st_fx->acelp_cfg.fcb_mode ) + { // PMTE() #ifdef IVAS_CODE - if (st->acelp_cfg.fixed_cdk_index[i_subfr / L_subfr] < ACELP_FIXED_CDK_NB) + if ( st->acelp_cfg.fixed_cdk_index[i_subfr / L_subfr] < ACELP_FIXED_CDK_NB ) { int16_t wordcnt, bitcnt; int16_t prm[8]; - if (st->acelp_cfg.fixed_cdk_index[i_subfr / L_subfr] >= 0) + if ( st->acelp_cfg.fixed_cdk_index[i_subfr / L_subfr] >= 0 ) { - if (L_subfr == 2 * L_SUBFR) + if ( L_subfr == 2 * L_SUBFR ) { nBits = st->acelp_cfg.fixed_cdk_index[i_subfr / L_subfr]; - if (nBits == 8) + if ( nBits == 8 ) { - acelp_1t64(hBstr, dn, h1, code, y2, L_subfr); + acelp_1t64( hBstr, dn, h1, code, y2, L_subfr ); } else { - acelp_fast(hBstr, nBits, dn, cn, h1, code, y2, L_subfr); + acelp_fast( hBstr, nBits, dn, cn, h1, code, y2, L_subfr ); } } - else if ((st->idchan == 1 && st->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] <= 7) || (st->idchan == 0 && st->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] <= 3)) + else if ( ( st->idchan == 1 && st->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] <= 7 ) || ( st->idchan == 0 && st->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] <= 3 ) ) { - if (st->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] == 0) + if ( st->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] == 0 ) { - acelp_1t64(hBstr, dn, h1, code, y2, L_subfr); + acelp_1t64( hBstr, dn, h1, code, y2, L_subfr ); } else { - acelp_fast(hBstr, st->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR], dn, cn, h1, code, y2, L_SUBFR); + acelp_fast( hBstr, st->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR], dn, cn, h1, code, y2, L_SUBFR ); } } else { - E_ACELP_4t(dn, cn, h1, Rw, acelpautoc, code, st->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR], prm, L_frame, last_L_frame, st->total_brate, i_subfr, cmpl_flag); + E_ACELP_4t( dn, cn, h1, Rw, acelpautoc, code, st->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR], prm, L_frame, last_L_frame, st->total_brate, i_subfr, cmpl_flag ); - wordcnt = ACELP_FIXED_CDK_BITS(st->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR]) >> 4; - bitcnt = ACELP_FIXED_CDK_BITS(st->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR]) & 15; + wordcnt = ACELP_FIXED_CDK_BITS( st->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] ) >> 4; + bitcnt = ACELP_FIXED_CDK_BITS( st->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] ) & 15; - for (i = 0; i < wordcnt; i++) + for ( i = 0; i < wordcnt; i++ ) { - push_indice(hBstr, IND_ALG_CDBK_4T64, prm[i], 16); + push_indice( hBstr, IND_ALG_CDBK_4T64, prm[i], 16 ); } - if (bitcnt) + if ( bitcnt ) { - push_indice(hBstr, IND_ALG_CDBK_4T64, prm[i], bitcnt); + push_indice( hBstr, IND_ALG_CDBK_4T64, prm[i], bitcnt ); } /* Generate weighted code */ - set_f(y2, 0.0f, L_SUBFR); - for (i = 0; i < L_SUBFR; i++) + set_f( y2, 0.0f, L_SUBFR ); + for ( i = 0; i < L_SUBFR; i++ ) { /* Code is sparse, so check which samples are non-zero */ - if (code[i] != 0) + if ( code[i] != 0 ) { - for (k = 0; k < L_SUBFR - i; k++) + for ( k = 0; k < L_SUBFR - i; k++ ) { y2[i + k] += code[i] * h1[k]; } @@ -331,76 +338,76 @@ Word16 inov_encode_fx( } else { - set_f(code, 0.0f, L_SUBFR); - set_f(y2, 0.0f, L_SUBFR); + set_f( code, 0.0f, L_SUBFR ); + set_f( y2, 0.0f, L_SUBFR ); } } #ifdef DEBUGGING else { - IVAS_ERROR(IVAS_ERR_INTERNAL_FATAL, "invalid mode for acelp frame!\n"); + IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "invalid mode for acelp frame!\n" ); } #endif #endif } ELSE { - nBits = st_fx->acelp_cfg.fixed_cdk_index[shr(i_subfr, 6)]; + nBits = st_fx->acelp_cfg.fixed_cdk_index[shr( i_subfr, 6 )]; move16(); - IF(EQ_16(nBits, 7)) + IF( EQ_16( nBits, 7 ) ) { - acelp_1t64_fx(hBstr, dn, h2, code, y2, L_SUBFR); + acelp_1t64_fx( hBstr, dn, h2, code, y2, L_SUBFR ); } - ELSE IF(EQ_16(nBits, 12)) + ELSE IF( EQ_16( nBits, 12 ) ) { - acelp_2t32_fx(hBstr, dn, h2, code, y2); + acelp_2t32_fx( hBstr, dn, h2, code, y2 ); } ELSE { - *unbits = add(*unbits, acelp_4t64_fx(hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, nBits, cmpl_flag, Opt_AMR_WB)); + *unbits = add( *unbits, acelp_4t64_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, nBits, cmpl_flag, Opt_AMR_WB ) ); move16(); } } } ELSE { - IF (EQ_32(core_brate,ACELP_6k60)) + IF( EQ_32( core_brate, ACELP_6k60 ) ) { - acelp_2t32_fx(hBstr, dn, h2, code, y2 ); + acelp_2t32_fx( hBstr, dn, h2, code, y2 ); } - ELSE IF( (EQ_32(core_brate,ACELP_8k85))) + ELSE IF( ( EQ_32( core_brate, ACELP_8k85 ) ) ) { - acelp_4t64_fx(hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 20, cmpl_flag, Opt_AMR_WB ); + acelp_4t64_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 20, cmpl_flag, Opt_AMR_WB ); } - ELSE IF( EQ_32(core_brate,ACELP_12k65)) + ELSE IF( EQ_32( core_brate, ACELP_12k65 ) ) { - acelp_4t64_fx(hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 36, cmpl_flag, Opt_AMR_WB ); + acelp_4t64_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 36, cmpl_flag, Opt_AMR_WB ); } - ELSE IF( EQ_32(core_brate,ACELP_14k25)) + ELSE IF( EQ_32( core_brate, ACELP_14k25 ) ) { - acelp_4t64_fx(hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 44, cmpl_flag, Opt_AMR_WB ); + acelp_4t64_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 44, cmpl_flag, Opt_AMR_WB ); } - ELSE IF( EQ_32(core_brate,ACELP_15k85)) + ELSE IF( EQ_32( core_brate, ACELP_15k85 ) ) { - acelp_4t64_fx(hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 52, cmpl_flag, Opt_AMR_WB ); + acelp_4t64_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 52, cmpl_flag, Opt_AMR_WB ); } - ELSE IF( EQ_32(core_brate,ACELP_18k25)) + ELSE IF( EQ_32( core_brate, ACELP_18k25 ) ) { - acelp_4t64_fx(hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 64, cmpl_flag, Opt_AMR_WB ); + acelp_4t64_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 64, cmpl_flag, Opt_AMR_WB ); } - ELSE IF( EQ_32(core_brate,ACELP_19k85)) + ELSE IF( EQ_32( core_brate, ACELP_19k85 ) ) { - acelp_4t64_fx(hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 72, cmpl_flag, Opt_AMR_WB ); + acelp_4t64_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 72, cmpl_flag, Opt_AMR_WB ); } - ELSE IF( EQ_32(core_brate,ACELP_23k05)) + ELSE IF( EQ_32( core_brate, ACELP_23k05 ) ) { - acelp_4t64_fx(hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 88, cmpl_flag, Opt_AMR_WB ); + acelp_4t64_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 88, cmpl_flag, Opt_AMR_WB ); } - ELSE IF( EQ_32(core_brate,ACELP_23k85)) + ELSE IF( EQ_32( core_brate, ACELP_23k85 ) ) { - acelp_4t64_fx(hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 88, 1, Opt_AMR_WB); + acelp_4t64_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 88, 1, Opt_AMR_WB ); } } @@ -409,8 +416,7 @@ Word16 inov_encode_fx( * Pitch sharpening *----------------------------------------------------------------*/ - cb_shape_fx( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, code, tilt_code, shr(add(pt_pitch,26),6), 0 , L_subfr); + cb_shape_fx( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, code, tilt_code, shr( add( pt_pitch, 26 ), 6 ), 0, L_subfr ); return stack_pulses; - } diff --git a/lib_enc/isf_enc_amr_wb_fx.c b/lib_enc/isf_enc_amr_wb_fx.c index d626734f6..8d19855a4 100644 --- a/lib_enc/isf_enc_amr_wb_fx.c +++ b/lib_enc/isf_enc_amr_wb_fx.c @@ -31,41 +31,41 @@ *******************************************************************************************************/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ - - - /*-----------------------------------------------------------------* - * Local constants - *-----------------------------------------------------------------*/ - -#define DICO1_NS_19b 16 /* codebook dimensions for SID ISF quantizers */ -#define DICO2_NS_19b 16 -#define DICO3_NS_19b 16 -#define DICO4_NS_19b 8 -#define DICO5_NS_19b 16 - -#define DICO1_NS_28b 64 -#define DICO2_NS_28b 64 -#define DICO3_NS_28b 64 -#define DICO4_NS_28b 32 -#define DICO5_NS_28b 32 - -#define N_SURV_MAX 4 /* maximum number of survivors */ - - /*---------------------------------------------------------------------* - * Local function prototypes - *---------------------------------------------------------------------*/ - -static void qisf_ns_28b_fx(BSTR_ENC_HANDLE hBstr, Word16 *isf); -static void qisf_2s_46b_fx(BSTR_ENC_HANDLE hBstr, Word16 *isf, Word16 nb_surv, Word16 *mem_AR, Word16 *mem_MA); -static void qisf_2s_36b_fx(BSTR_ENC_HANDLE hBstr, Word16 *isf, Word16 nb_surv, Word16 *mem_AR, Word16 *mem_MA); -static void VQ_stage1_fx(const Word16 *x, const Word16 *dico, const Word16 dim, const Word16 dico_size, Word16 *index, const Word16 surv); -static Word16 sub_VQ_fx(Word16 *x, const Word16 *dico, const Word16 dim, const Word16 dico_size, Word32 *distance); +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ + + +/*-----------------------------------------------------------------* + * Local constants + *-----------------------------------------------------------------*/ + +#define DICO1_NS_19b 16 /* codebook dimensions for SID ISF quantizers */ +#define DICO2_NS_19b 16 +#define DICO3_NS_19b 16 +#define DICO4_NS_19b 8 +#define DICO5_NS_19b 16 + +#define DICO1_NS_28b 64 +#define DICO2_NS_28b 64 +#define DICO3_NS_28b 64 +#define DICO4_NS_28b 32 +#define DICO5_NS_28b 32 + +#define N_SURV_MAX 4 /* maximum number of survivors */ + +/*---------------------------------------------------------------------* + * Local function prototypes + *---------------------------------------------------------------------*/ + +static void qisf_ns_28b_fx( BSTR_ENC_HANDLE hBstr, Word16 *isf ); +static void qisf_2s_46b_fx( BSTR_ENC_HANDLE hBstr, Word16 *isf, Word16 nb_surv, Word16 *mem_AR, Word16 *mem_MA ); +static void qisf_2s_36b_fx( BSTR_ENC_HANDLE hBstr, Word16 *isf, Word16 nb_surv, Word16 *mem_AR, Word16 *mem_MA ); +static void VQ_stage1_fx( const Word16 *x, const Word16 *dico, const Word16 dim, const Word16 dico_size, Word16 *index, const Word16 surv ); +static Word16 sub_VQ_fx( Word16 *x, const Word16 *dico, const Word16 dim, const Word16 dico_size, Word32 *distance ); /*-------------------------------------------------------------------* * isf_enc_amr_wb() @@ -74,116 +74,116 @@ static Word16 sub_VQ_fx(Word16 *x, const Word16 *dico, const Word16 dim, const W *-------------------------------------------------------------------*/ void isf_enc_amr_wb_fx( - Encoder_State *st, /* i/o: state structure */ - Word16 *isf_new, /* i/o: quantized ISF vector */ - Word16 *isp_new, /* i/o: ISP vector to quantize/quantized */ - Word16 *Aq /* o : quantized A(z) for 4 subframes */ + Encoder_State *st, /* i/o: state structure */ + Word16 *isf_new, /* i/o: quantized ISF vector */ + Word16 *isp_new, /* i/o: ISP vector to quantize/quantized */ + Word16 *Aq /* o : quantized A(z) for 4 subframes */ ) { - BSTR_ENC_HANDLE hBstr = st->hBstr; - - /*---------------------------------* - * ISF quantization of SID frames - *---------------------------------*/ - - IF(EQ_32(st->core_brate, SID_1k75)) - { - qisf_ns_28b_fx(hBstr, isf_new); - - reorder_isf_fx(isf_new, ISF_GAP_FX, M, Fs_2); - - E_LPC_isf_isp_conversion(isf_new, isp_new, M); - - /* return if SID frame (conversion to A(z) done in the calling function) */ - return; - } - - /* check resonance for pitch clipping algorithm */ - gp_clip_test_isf_fx(st->element_mode, st->core_brate, isf_new, st->clip_var_fx, 1); - - /*---------------------------------------* - * ISF quantization of all other frames - *---------------------------------------*/ - - IF(EQ_32(st->core_brate, ACELP_6k60)) - { - qisf_2s_36b_fx(hBstr, isf_new, 4, st->mem_AR_fx, st->mem_MA_fx); - } - ELSE IF(GE_32(st->core_brate, ACELP_8k85)) - { - qisf_2s_46b_fx(hBstr, isf_new, 4, st->mem_AR_fx, st->mem_MA_fx); - } - - reorder_isf_fx(isf_new, ISF_GAP_FX, M, Fs_2); - /* convert quantized ISFs back to ISPs */ - E_LPC_isf_isp_conversion(isf_new, isp_new, M); - - /*-------------------------------------------------------------------------------------* - * ISP interpolation - * A(z) calculation - *-------------------------------------------------------------------------------------*/ - - if (st->rate_switching_reset) - { - Copy(isf_new, st->lsf_old_fx, M); - Copy(isp_new, st->lsp_old_fx, M); - } - - int_lsp_fx(L_FRAME, st->lsp_old_fx, isp_new, Aq, M, interpol_isp_amr_wb_fx, 1); - - /*------------------------------------------------------------------* - * Calculate ISF stability (distance between old ISF and current ISF) - *------------------------------------------------------------------*/ - IF(NE_32(st->last_core_brate, SID_1k75)) - { - st->stab_fac_fx = lsf_stab_fx(isf_new, st->lsf_old_fx, 1, L_FRAME); - } - - return; + BSTR_ENC_HANDLE hBstr = st->hBstr; + + /*---------------------------------* + * ISF quantization of SID frames + *---------------------------------*/ + + IF( EQ_32( st->core_brate, SID_1k75 ) ) + { + qisf_ns_28b_fx( hBstr, isf_new ); + + reorder_isf_fx( isf_new, ISF_GAP_FX, M, Fs_2 ); + + E_LPC_isf_isp_conversion( isf_new, isp_new, M ); + + /* return if SID frame (conversion to A(z) done in the calling function) */ + return; + } + + /* check resonance for pitch clipping algorithm */ + gp_clip_test_isf_fx( st->element_mode, st->core_brate, isf_new, st->clip_var_fx, 1 ); + + /*---------------------------------------* + * ISF quantization of all other frames + *---------------------------------------*/ + + IF( EQ_32( st->core_brate, ACELP_6k60 ) ) + { + qisf_2s_36b_fx( hBstr, isf_new, 4, st->mem_AR_fx, st->mem_MA_fx ); + } + ELSE IF( GE_32( st->core_brate, ACELP_8k85 ) ) + { + qisf_2s_46b_fx( hBstr, isf_new, 4, st->mem_AR_fx, st->mem_MA_fx ); + } + + reorder_isf_fx( isf_new, ISF_GAP_FX, M, Fs_2 ); + /* convert quantized ISFs back to ISPs */ + E_LPC_isf_isp_conversion( isf_new, isp_new, M ); + + /*-------------------------------------------------------------------------------------* + * ISP interpolation + * A(z) calculation + *-------------------------------------------------------------------------------------*/ + + if ( st->rate_switching_reset ) + { + Copy( isf_new, st->lsf_old_fx, M ); + Copy( isp_new, st->lsp_old_fx, M ); + } + + int_lsp_fx( L_FRAME, st->lsp_old_fx, isp_new, Aq, M, interpol_isp_amr_wb_fx, 1 ); + + /*------------------------------------------------------------------* + * Calculate ISF stability (distance between old ISF and current ISF) + *------------------------------------------------------------------*/ + IF( NE_32( st->last_core_brate, SID_1k75 ) ) + { + st->stab_fac_fx = lsf_stab_fx( isf_new, st->lsf_old_fx, 1, L_FRAME ); + } + + return; } /*-------------------------------------------------------------------* -* qisf_ns_28b() -* -* ISF quantizer for SID frames (only in AMR-WB IO mode) -*-------------------------------------------------------------------*/ + * qisf_ns_28b() + * + * ISF quantizer for SID frames (only in AMR-WB IO mode) + *-------------------------------------------------------------------*/ static void qisf_ns_28b_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder state structure */ - Word16 *isf /* i/o: unquantized/quantized ISF vector */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder state structure */ + Word16 *isf /* i/o: unquantized/quantized ISF vector */ ) { - Word16 i, indice[5]; - Word32 tmp; - - FOR(i = 0; i < M; i++) - { - /*isf[i] -= mean_isf_noise_amr_wb[i];*/ - isf[i] = sub(isf[i], mean_isf_noise_amr_wb_fx[i]); - move16(); - } - - indice[0] = sub_VQ_fx(&isf[0], dico1_ns_28b_fx, 2, DICO1_NS_28b, &tmp); - move16(); - indice[1] = sub_VQ_fx(&isf[2], dico2_ns_28b_fx, 3, DICO2_NS_28b, &tmp); - move16(); - indice[2] = sub_VQ_fx(&isf[5], dico3_ns_28b_fx, 3, DICO3_NS_28b, &tmp); - move16(); - indice[3] = sub_VQ_fx(&isf[8], dico4_ns_28b_fx, 4, DICO4_NS_28b, &tmp); - move16(); - indice[4] = add(sub_VQ_fx(&isf[12], dico5_ns_28b_fx + 4, 4, DICO5_NS_28b - 1, &tmp), 1); /* First vector has a problem -> do not allow */ - - /* write indices to array */ - push_indice_fx(hBstr, IND_ISF_0_0, indice[0], 6); - push_indice_fx(hBstr, IND_ISF_0_1, indice[1], 6); - push_indice_fx(hBstr, IND_ISF_0_2, indice[2], 6); - push_indice_fx(hBstr, IND_ISF_0_3, indice[3], 5); - push_indice_fx(hBstr, IND_ISF_0_4, indice[4], 5); - - /* decoding the ISFs */ - disf_ns_28b_fx(indice, isf); - - return; + Word16 i, indice[5]; + Word32 tmp; + + FOR( i = 0; i < M; i++ ) + { + /*isf[i] -= mean_isf_noise_amr_wb[i];*/ + isf[i] = sub( isf[i], mean_isf_noise_amr_wb_fx[i] ); + move16(); + } + + indice[0] = sub_VQ_fx( &isf[0], dico1_ns_28b_fx, 2, DICO1_NS_28b, &tmp ); + move16(); + indice[1] = sub_VQ_fx( &isf[2], dico2_ns_28b_fx, 3, DICO2_NS_28b, &tmp ); + move16(); + indice[2] = sub_VQ_fx( &isf[5], dico3_ns_28b_fx, 3, DICO3_NS_28b, &tmp ); + move16(); + indice[3] = sub_VQ_fx( &isf[8], dico4_ns_28b_fx, 4, DICO4_NS_28b, &tmp ); + move16(); + indice[4] = add( sub_VQ_fx( &isf[12], dico5_ns_28b_fx + 4, 4, DICO5_NS_28b - 1, &tmp ), 1 ); /* First vector has a problem -> do not allow */ + + /* write indices to array */ + push_indice_fx( hBstr, IND_ISF_0_0, indice[0], 6 ); + push_indice_fx( hBstr, IND_ISF_0_1, indice[1], 6 ); + push_indice_fx( hBstr, IND_ISF_0_2, indice[2], 6 ); + push_indice_fx( hBstr, IND_ISF_0_3, indice[3], 5 ); + push_indice_fx( hBstr, IND_ISF_0_4, indice[4], 5 ); + + /* decoding the ISFs */ + disf_ns_28b_fx( indice, isf ); + + return; } @@ -197,121 +197,120 @@ static void qisf_ns_28b_fx( *---------------------------------------------------------------------*/ static void qisf_2s_36b_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder state structure */ - Word16 *isf, /* i/o: unquantized/quantized ISF vector */ - Word16 nb_surv, /* i : number of survivors (1, 2, 3 or 4) */ - Word16 *mem_AR, /* o : quantizer memory for AR model */ - Word16 *mem_MA /* i/o: quantizer memory for MA model */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder state structure */ + Word16 *isf, /* i/o: unquantized/quantized ISF vector */ + Word16 nb_surv, /* i : number of survivors (1, 2, 3 or 4) */ + Word16 *mem_AR, /* o : quantizer memory for AR model */ + Word16 *mem_MA /* i/o: quantizer memory for MA model */ ) { - Word16 i, k, indice[5], tmp_ind[2]; - Word16 surv1[N_SURV_MAX], tmp16; /* indices of survivors from 1st stage */ - Word32 temp, min_err, distance; - Word16 isf2[M]; - - /*------------------------------------------------------------------------* - * Subtract mean - *------------------------------------------------------------------------*/ - - FOR(i = 0; i < M; i++) - { - /*isf[i] -= mean_isf_amr_wb[i] + MU_MA * mem_MA[i];*/ - tmp16 = sub(isf[i], mean_isf_amr_wb_fx[i]); - isf[i] = sub(tmp16, mult(MU_MA_FX, mem_MA[i])); - move16(); - - } - - /*------------------------------------------------------------------------* - * Quantize ISFs 0 - 8 - *------------------------------------------------------------------------*/ - - VQ_stage1_fx(&isf[0], dico1_isf_fx, 9, SIZE_BK1, surv1, nb_surv); - - distance = MAX_32; - move32(); - nb_surv = s_min(nb_surv, N_SURV_MAX); - - FOR(k = 0; k < nb_surv; k++) - { - tmp16 = i_mult2(surv1[k], 9); - FOR(i = 0; i < 9; i++) - { - /*isf2[i] = isf[i] - dico1_isf[i+surv1[k]*9];*/ - isf2[i] = sub(isf[i], dico1_isf_fx[i + tmp16]); - move16(); - } - - tmp_ind[0] = sub_VQ_fx(&isf2[0], dico21_isf_36b_fx, 5, SIZE_BK21_36b, &min_err); - temp = L_add(min_err, 0); - - tmp_ind[1] = sub_VQ_fx(&isf2[5], dico22_isf_36b_fx, 4, SIZE_BK22_36b, &min_err); - temp = L_add(temp, min_err); - - IF(LT_32(temp, distance)) - { - distance = L_add(temp, 0); - indice[0] = surv1[k]; - move16(); - FOR(i = 0; i < 2; i++) - { - indice[i + 2] = tmp_ind[i]; - move16(); - } - } - } - - /*------------------------------------------------------------------------* - * Quantize ISFs 9 - 15 - *------------------------------------------------------------------------*/ - - VQ_stage1_fx(&isf[9], dico2_isf_fx, 7, SIZE_BK2, surv1, nb_surv); - - distance = MAX_32; - move32(); - FOR(k = 0; k < nb_surv; k++) - { - tmp16 = i_mult2(surv1[k], 7); - FOR(i = 0; i < 7; i++) - { - /*isf2[9+i] = isf[9+i] - dico2_isf[i+surv1[k]*7];*/ - isf2[i + 9] = sub(isf[9 + i], dico2_isf_fx[i + tmp16]); - move16(); - } - - tmp_ind[0] = sub_VQ_fx(&isf2[9], dico23_isf_36b_fx, 3, SIZE_BK23_36b, &min_err); - move16(); - temp = L_add(min_err, 0); - IF(LT_32(temp, distance)) - { - distance = L_add(temp, 0); - indice[1] = surv1[k]; - move16(); - indice[4] = tmp_ind[0]; - move16(); - } - } - - /*------------------------------------------------------------------------* - * decoding the ISFs - *------------------------------------------------------------------------*/ - - disf_2s_36b_fx(indice, isf, mem_AR, mem_MA, 0); - - /*------------------------------------------------------------------------* - * write indices to array - *------------------------------------------------------------------------*/ - - indice[0] = Indirect_dico1[indice[0]]; - move16(); /* Make interoperable with G722.2 */ - - push_indice_fx(hBstr, IND_ISF_0_0, indice[0], 8); - push_indice_fx(hBstr, IND_ISF_0_1, indice[1], 8); - push_indice_fx(hBstr, IND_ISF_1_0, indice[2], 7); - push_indice_fx(hBstr, IND_ISF_1_1, indice[3], 7); - push_indice_fx(hBstr, IND_ISF_1_2, indice[4], 6); - - return; + Word16 i, k, indice[5], tmp_ind[2]; + Word16 surv1[N_SURV_MAX], tmp16; /* indices of survivors from 1st stage */ + Word32 temp, min_err, distance; + Word16 isf2[M]; + + /*------------------------------------------------------------------------* + * Subtract mean + *------------------------------------------------------------------------*/ + + FOR( i = 0; i < M; i++ ) + { + /*isf[i] -= mean_isf_amr_wb[i] + MU_MA * mem_MA[i];*/ + tmp16 = sub( isf[i], mean_isf_amr_wb_fx[i] ); + isf[i] = sub( tmp16, mult( MU_MA_FX, mem_MA[i] ) ); + move16(); + } + + /*------------------------------------------------------------------------* + * Quantize ISFs 0 - 8 + *------------------------------------------------------------------------*/ + + VQ_stage1_fx( &isf[0], dico1_isf_fx, 9, SIZE_BK1, surv1, nb_surv ); + + distance = MAX_32; + move32(); + nb_surv = s_min( nb_surv, N_SURV_MAX ); + + FOR( k = 0; k < nb_surv; k++ ) + { + tmp16 = i_mult2( surv1[k], 9 ); + FOR( i = 0; i < 9; i++ ) + { + /*isf2[i] = isf[i] - dico1_isf[i+surv1[k]*9];*/ + isf2[i] = sub( isf[i], dico1_isf_fx[i + tmp16] ); + move16(); + } + + tmp_ind[0] = sub_VQ_fx( &isf2[0], dico21_isf_36b_fx, 5, SIZE_BK21_36b, &min_err ); + temp = L_add( min_err, 0 ); + + tmp_ind[1] = sub_VQ_fx( &isf2[5], dico22_isf_36b_fx, 4, SIZE_BK22_36b, &min_err ); + temp = L_add( temp, min_err ); + + IF( LT_32( temp, distance ) ) + { + distance = L_add( temp, 0 ); + indice[0] = surv1[k]; + move16(); + FOR( i = 0; i < 2; i++ ) + { + indice[i + 2] = tmp_ind[i]; + move16(); + } + } + } + + /*------------------------------------------------------------------------* + * Quantize ISFs 9 - 15 + *------------------------------------------------------------------------*/ + + VQ_stage1_fx( &isf[9], dico2_isf_fx, 7, SIZE_BK2, surv1, nb_surv ); + + distance = MAX_32; + move32(); + FOR( k = 0; k < nb_surv; k++ ) + { + tmp16 = i_mult2( surv1[k], 7 ); + FOR( i = 0; i < 7; i++ ) + { + /*isf2[9+i] = isf[9+i] - dico2_isf[i+surv1[k]*7];*/ + isf2[i + 9] = sub( isf[9 + i], dico2_isf_fx[i + tmp16] ); + move16(); + } + + tmp_ind[0] = sub_VQ_fx( &isf2[9], dico23_isf_36b_fx, 3, SIZE_BK23_36b, &min_err ); + move16(); + temp = L_add( min_err, 0 ); + IF( LT_32( temp, distance ) ) + { + distance = L_add( temp, 0 ); + indice[1] = surv1[k]; + move16(); + indice[4] = tmp_ind[0]; + move16(); + } + } + + /*------------------------------------------------------------------------* + * decoding the ISFs + *------------------------------------------------------------------------*/ + + disf_2s_36b_fx( indice, isf, mem_AR, mem_MA, 0 ); + + /*------------------------------------------------------------------------* + * write indices to array + *------------------------------------------------------------------------*/ + + indice[0] = Indirect_dico1[indice[0]]; + move16(); /* Make interoperable with G722.2 */ + + push_indice_fx( hBstr, IND_ISF_0_0, indice[0], 8 ); + push_indice_fx( hBstr, IND_ISF_0_1, indice[1], 8 ); + push_indice_fx( hBstr, IND_ISF_1_0, indice[2], 7 ); + push_indice_fx( hBstr, IND_ISF_1_1, indice[3], 7 ); + push_indice_fx( hBstr, IND_ISF_1_2, indice[4], 6 ); + + return; } @@ -325,129 +324,129 @@ static void qisf_2s_36b_fx( *-------------------------------------------------------------------*/ static void qisf_2s_46b_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder state structure */ - Word16 *isf, /* i/o: unquantized/quantized ISF vector */ - Word16 nb_surv, /* i : number of survivors (1, 2, 3 or 4) */ - Word16 *mem_AR, /* o : quantizer memory for AR model */ - Word16 *mem_MA /* i/o: quantizer memory for MA model */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder state structure */ + Word16 *isf, /* i/o: unquantized/quantized ISF vector */ + Word16 nb_surv, /* i : number of survivors (1, 2, 3 or 4) */ + Word16 *mem_AR, /* o : quantizer memory for AR model */ + Word16 *mem_MA /* i/o: quantizer memory for MA model */ ) { - Word16 i, k, indice[7], tmp_ind[5]; - Word16 surv1[N_SURV_MAX]; /* indices of survivors from 1st stage */ - Word32 temp, min_err, distance; - Word16 tmp16, isf2[M]; - - - /*------------------------------------------------------------------------* - * Subtract mean - *------------------------------------------------------------------------*/ - - FOR(i = 0; i < M; i++) - { - /*isf[i] -= mean_isf_amr_wb[i] + MU_MA * mem_MA[i];*/ - tmp16 = sub(isf[i], mean_isf_amr_wb_fx[i]); - isf[i] = sub(tmp16, mult(MU_MA_FX, mem_MA[i])); - move16(); - } - - /*------------------------------------------------------------------------* - * Quantize ISFs 0 - 8 - *------------------------------------------------------------------------*/ - - VQ_stage1_fx(&isf[0], dico1_isf_fx, 9, SIZE_BK1, surv1, nb_surv); - - distance = MAX_32; - move32(); - nb_surv = s_min(nb_surv, N_SURV_MAX); - - FOR(k = 0; k < nb_surv; k++) - { - tmp16 = i_mult2(surv1[k], 9); - FOR(i = 0; i < 9; i++) - { - /*isf2[i] = isf[i] - dico1_isf[i+surv1[k]*9];*/ - isf2[i] = sub(isf[i], dico1_isf_fx[i + tmp16]); - move16(); - } - - tmp_ind[0] = sub_VQ_fx(&isf2[0], dico21_isf_46b_fx, 3, SIZE_BK21, &min_err); - temp = L_add(min_err, 0); - tmp_ind[1] = sub_VQ_fx(&isf2[3], dico22_isf_46b_fx, 3, SIZE_BK22, &min_err); - temp = L_add(temp, min_err); - tmp_ind[2] = sub_VQ_fx(&isf2[6], dico23_isf_46b_fx, 3, SIZE_BK23, &min_err); - temp = L_add(temp, min_err); - IF(LT_32(temp, distance)) - { - distance = L_add(temp, 0); - indice[0] = surv1[k]; - move16(); - FOR(i = 0; i < 3; i++) - { - indice[i + 2] = tmp_ind[i]; - move16(); - } - } - } - - /*------------------------------------------------------------------------* - * Quantize ISFs 9 - 15 - *------------------------------------------------------------------------*/ - - VQ_stage1_fx(&isf[9], dico2_isf_fx, 7, SIZE_BK2, surv1, nb_surv); - - distance = MAX_32; - move32(); - FOR(k = 0; k < nb_surv; k++) - { - tmp16 = i_mult2(surv1[k], 7); - FOR(i = 0; i < 7; i++) - { - /*isf2[9+i] = isf[9+i] - dico2_isf[i+surv1[k]*7];*/ - isf2[i + 9] = sub(isf[9 + i], dico2_isf_fx[i + tmp16]); - move16(); - } - tmp_ind[0] = sub_VQ_fx(&isf2[9], dico24_isf_46b_fx, 3, SIZE_BK24, &min_err); - move16(); - temp = L_add(min_err, 0); - - tmp_ind[1] = sub_VQ_fx(&isf2[12], dico25_isf_46b_fx, 4, SIZE_BK25, &min_err); - move16(); - temp = L_add(temp, min_err); - - IF(LT_32(temp, distance)) - { - distance = L_add(temp, 0); - indice[1] = surv1[k]; - move16(); - FOR(i = 0; i < 2; i++) - { - indice[i + 5] = tmp_ind[i]; - move16(); - } - } - } - - /*------------------------------------------------------------------------* - * decoding the ISFs - *------------------------------------------------------------------------*/ - - disf_2s_46b_fx(indice, isf, mem_AR, mem_MA, 0); - - /*------------------------------------------------------------------------* - * write indices to array - *------------------------------------------------------------------------*/ - indice[0] = Indirect_dico1[indice[0]]; - move16(); /* Make interoperable with G722.2 */ - - push_indice_fx(hBstr, IND_ISF_0_0, indice[0], 8); - push_indice_fx(hBstr, IND_ISF_0_1, indice[1], 8); - push_indice_fx(hBstr, IND_ISF_1_0, indice[2], 6); - push_indice_fx(hBstr, IND_ISF_1_1, indice[3], 7); - push_indice_fx(hBstr, IND_ISF_1_2, indice[4], 7); - push_indice_fx(hBstr, IND_ISF_1_3, indice[5], 5); - push_indice_fx(hBstr, IND_ISF_1_4, indice[6], 5); - - return; + Word16 i, k, indice[7], tmp_ind[5]; + Word16 surv1[N_SURV_MAX]; /* indices of survivors from 1st stage */ + Word32 temp, min_err, distance; + Word16 tmp16, isf2[M]; + + + /*------------------------------------------------------------------------* + * Subtract mean + *------------------------------------------------------------------------*/ + + FOR( i = 0; i < M; i++ ) + { + /*isf[i] -= mean_isf_amr_wb[i] + MU_MA * mem_MA[i];*/ + tmp16 = sub( isf[i], mean_isf_amr_wb_fx[i] ); + isf[i] = sub( tmp16, mult( MU_MA_FX, mem_MA[i] ) ); + move16(); + } + + /*------------------------------------------------------------------------* + * Quantize ISFs 0 - 8 + *------------------------------------------------------------------------*/ + + VQ_stage1_fx( &isf[0], dico1_isf_fx, 9, SIZE_BK1, surv1, nb_surv ); + + distance = MAX_32; + move32(); + nb_surv = s_min( nb_surv, N_SURV_MAX ); + + FOR( k = 0; k < nb_surv; k++ ) + { + tmp16 = i_mult2( surv1[k], 9 ); + FOR( i = 0; i < 9; i++ ) + { + /*isf2[i] = isf[i] - dico1_isf[i+surv1[k]*9];*/ + isf2[i] = sub( isf[i], dico1_isf_fx[i + tmp16] ); + move16(); + } + + tmp_ind[0] = sub_VQ_fx( &isf2[0], dico21_isf_46b_fx, 3, SIZE_BK21, &min_err ); + temp = L_add( min_err, 0 ); + tmp_ind[1] = sub_VQ_fx( &isf2[3], dico22_isf_46b_fx, 3, SIZE_BK22, &min_err ); + temp = L_add( temp, min_err ); + tmp_ind[2] = sub_VQ_fx( &isf2[6], dico23_isf_46b_fx, 3, SIZE_BK23, &min_err ); + temp = L_add( temp, min_err ); + IF( LT_32( temp, distance ) ) + { + distance = L_add( temp, 0 ); + indice[0] = surv1[k]; + move16(); + FOR( i = 0; i < 3; i++ ) + { + indice[i + 2] = tmp_ind[i]; + move16(); + } + } + } + + /*------------------------------------------------------------------------* + * Quantize ISFs 9 - 15 + *------------------------------------------------------------------------*/ + + VQ_stage1_fx( &isf[9], dico2_isf_fx, 7, SIZE_BK2, surv1, nb_surv ); + + distance = MAX_32; + move32(); + FOR( k = 0; k < nb_surv; k++ ) + { + tmp16 = i_mult2( surv1[k], 7 ); + FOR( i = 0; i < 7; i++ ) + { + /*isf2[9+i] = isf[9+i] - dico2_isf[i+surv1[k]*7];*/ + isf2[i + 9] = sub( isf[9 + i], dico2_isf_fx[i + tmp16] ); + move16(); + } + tmp_ind[0] = sub_VQ_fx( &isf2[9], dico24_isf_46b_fx, 3, SIZE_BK24, &min_err ); + move16(); + temp = L_add( min_err, 0 ); + + tmp_ind[1] = sub_VQ_fx( &isf2[12], dico25_isf_46b_fx, 4, SIZE_BK25, &min_err ); + move16(); + temp = L_add( temp, min_err ); + + IF( LT_32( temp, distance ) ) + { + distance = L_add( temp, 0 ); + indice[1] = surv1[k]; + move16(); + FOR( i = 0; i < 2; i++ ) + { + indice[i + 5] = tmp_ind[i]; + move16(); + } + } + } + + /*------------------------------------------------------------------------* + * decoding the ISFs + *------------------------------------------------------------------------*/ + + disf_2s_46b_fx( indice, isf, mem_AR, mem_MA, 0 ); + + /*------------------------------------------------------------------------* + * write indices to array + *------------------------------------------------------------------------*/ + indice[0] = Indirect_dico1[indice[0]]; + move16(); /* Make interoperable with G722.2 */ + + push_indice_fx( hBstr, IND_ISF_0_0, indice[0], 8 ); + push_indice_fx( hBstr, IND_ISF_0_1, indice[1], 8 ); + push_indice_fx( hBstr, IND_ISF_1_0, indice[2], 6 ); + push_indice_fx( hBstr, IND_ISF_1_1, indice[3], 7 ); + push_indice_fx( hBstr, IND_ISF_1_2, indice[4], 7 ); + push_indice_fx( hBstr, IND_ISF_1_3, indice[5], 5 ); + push_indice_fx( hBstr, IND_ISF_1_4, indice[6], 5 ); + + return; } /*-------------------------------------------------------------------* @@ -457,61 +456,61 @@ static void qisf_2s_46b_fx( *-------------------------------------------------------------------*/ static void VQ_stage1_fx( - const Word16 *x, /* i : ISF vector */ - const Word16 *dico, /* i : ISF codebook */ - const Word16 dim, /* i : codebook dimension */ - const Word16 dico_size, /* i : codebook size */ - Word16 *index, /* o : indices of best vector candidates */ - const Word16 surv /* i : nb of surviving best candidates */ + const Word16 *x, /* i : ISF vector */ + const Word16 *dico, /* i : ISF codebook */ + const Word16 dim, /* i : codebook dimension */ + const Word16 dico_size, /* i : codebook size */ + Word16 *index, /* o : indices of best vector candidates */ + const Word16 surv /* i : nb of surviving best candidates */ ) { - Word32 dist_min[N_SURV_MAX]; - Word32 dist; - const Word16 *p_dico; - Word16 i, j, k, l, temp; - - - FOR(i = 0; i < surv; i++) - { - dist_min[i] = MAX_32; - move32(); - index[i] = i; - move16(); - } - - p_dico = dico; - - FOR(i = 0; i < dico_size; i++) - { - dist = L_deposit_l(0); - FOR(j = 0; j < dim; j++) - { - /*temp = x[j] - *p_dico++;*/ - temp = sub(x[j], *p_dico++); - /*dist += temp * temp;*/ - dist = L_mac(dist, temp, temp); - } - - FOR(k = 0; k < surv; k++) - { - IF(LT_32(dist, dist_min[k])) - { - FOR(l = sub(surv, 1); l > k; l--) - { - dist_min[l] = dist_min[l - 1]; - move32(); - index[l] = index[l - 1]; - move16(); - } - dist_min[k] = dist; - move32(); - index[k] = i; - move16(); - BREAK; - } - } - } - return; + Word32 dist_min[N_SURV_MAX]; + Word32 dist; + const Word16 *p_dico; + Word16 i, j, k, l, temp; + + + FOR( i = 0; i < surv; i++ ) + { + dist_min[i] = MAX_32; + move32(); + index[i] = i; + move16(); + } + + p_dico = dico; + + FOR( i = 0; i < dico_size; i++ ) + { + dist = L_deposit_l( 0 ); + FOR( j = 0; j < dim; j++ ) + { + /*temp = x[j] - *p_dico++;*/ + temp = sub( x[j], *p_dico++ ); + /*dist += temp * temp;*/ + dist = L_mac( dist, temp, temp ); + } + + FOR( k = 0; k < surv; k++ ) + { + IF( LT_32( dist, dist_min[k] ) ) + { + FOR( l = sub( surv, 1 ); l > k; l-- ) + { + dist_min[l] = dist_min[l - 1]; + move32(); + index[l] = index[l - 1]; + move16(); + } + dist_min[k] = dist; + move32(); + index[k] = i; + move16(); + BREAK; + } + } + } + return; } /*-------------------------------------------------------------------* @@ -520,54 +519,54 @@ static void VQ_stage1_fx( * Quantization of a subvector in Split-VQ of ISFs *-------------------------------------------------------------------*/ -static Word16 sub_VQ_fx( /* o : selected codebook vector index */ - Word16 *x, /* i/o: ISF vector */ - const Word16 *dico, /* i : ISF codebook */ - const Word16 dim, /* i : codebook dimension */ - const Word16 dico_size, /* i : codebook size */ - Word32 *distance /* o : quantization error (min. distance) */ +static Word16 sub_VQ_fx( /* o : selected codebook vector index */ + Word16 *x, /* i/o: ISF vector */ + const Word16 *dico, /* i : ISF codebook */ + const Word16 dim, /* i : codebook dimension */ + const Word16 dico_size, /* i : codebook size */ + Word32 *distance /* o : quantization error (min. distance) */ ) { - Word32 dist_min, dist; - const Word16 *p_dico; - Word16 i, j, index, temp; - - - dist_min = MAX_32; - move32(); - p_dico = dico; - move16(); - - index = 0; - move16(); - FOR(i = 0; i < dico_size; i++) - { - dist = L_deposit_l(0); - FOR(j = 0; j < dim; j++) - { - /*temp = x[j] - *p_dico++;*/ - temp = sub(x[j], *p_dico++); - /*dist += temp * temp;*/ - dist = L_mac(dist, temp, temp); - } - - IF(LT_32(dist, dist_min)) - { - dist_min = L_add(dist, 0); - index = i; - move16(); - } - } - - *distance = dist_min; - move32(); - - /* Reading the selected vector */ - p_dico = &dico[i_mult2(index, dim)]; - FOR(j = 0; j < dim; j++) - { - x[j] = *p_dico++; - move16(); - } - return index; + Word32 dist_min, dist; + const Word16 *p_dico; + Word16 i, j, index, temp; + + + dist_min = MAX_32; + move32(); + p_dico = dico; + move16(); + + index = 0; + move16(); + FOR( i = 0; i < dico_size; i++ ) + { + dist = L_deposit_l( 0 ); + FOR( j = 0; j < dim; j++ ) + { + /*temp = x[j] - *p_dico++;*/ + temp = sub( x[j], *p_dico++ ); + /*dist += temp * temp;*/ + dist = L_mac( dist, temp, temp ); + } + + IF( LT_32( dist, dist_min ) ) + { + dist_min = L_add( dist, 0 ); + index = i; + move16(); + } + } + + *distance = dist_min; + move32(); + + /* Reading the selected vector */ + p_dico = &dico[i_mult2( index, dim )]; + FOR( j = 0; j < dim; j++ ) + { + x[j] = *p_dico++; + move16(); + } + return index; } diff --git a/lib_enc/ivas_agc_enc.c b/lib_enc/ivas_agc_enc.c index aaab62ab6..acfd266eb 100644 --- a/lib_enc/ivas_agc_enc.c +++ b/lib_enc/ivas_agc_enc.c @@ -51,15 +51,15 @@ #define AGC_MIN_DELTA ( 4.656612873077393e-10f ) /*2^-31*/ #ifdef IVAS_FLOAT_FIXED -#define AGC_MIN_DELTA_FX 1 //q31 -#define TWO_IN_Q29 1073741824 -#define ONE_MINUS_M_DELTA_PROD_FLT_FC 1073741824 //Q15 +#define AGC_MIN_DELTA_FX 1 // q31 +#define TWO_IN_Q29 1073741824 +#define ONE_MINUS_M_DELTA_PROD_FLT_FC 1073741824 // Q15 #endif #ifdef IVAS_FLOAT_FIXED static Word16 ceil_fx( Word16 inp, Word16 Q ); -static Word32 pow32_fx(Word16 inp, Word16 indx); -static Word16 BASOP_Util_Cmp_Mant32Exp_sat(Word32 a_m, Word16 a_e, Word32 b_m, Word16 b_e); +static Word32 pow32_fx( Word16 inp, Word16 indx ); +static Word16 BASOP_Util_Cmp_Mant32Exp_sat( Word32 a_m, Word16 a_e, Word32 b_m, Word16 b_e ); static Word16 ceil_fx( Word16 inp, Word16 Q ) { Word16 ret; @@ -73,9 +73,9 @@ static Word16 ceil_fx( Word16 inp, Word16 Q ) } ELSE { - ret_32 = L_add( inp , sub( shl( 1, Q ), 1 ) ); //(inp+(pow(2,q)-1))/pow(2,q)// - ret_32 = L_shr(ret_32, Q ); - return (Word16)( ret_32 ); + ret_32 = L_add( inp, sub( shl( 1, Q ), 1 ) ); //(inp+(pow(2,q)-1))/pow(2,q)// + ret_32 = L_shr( ret_32, Q ); + return (Word16) ( ret_32 ); } } ELSE @@ -181,10 +181,10 @@ Word16 BASOP_Util_Cmp_Mant32Exp_sat /*!< o: flag: result of comparison */ Word32 pow32_fx( Word16 inp, Word16 indx ) { - Word32 temp_1, temp_2; + Word32 temp_1, temp_2; IF( EQ_16( indx, 1 ) ) { - return L_deposit_h(inp); + return L_deposit_h( inp ); } ELSE IF( EQ_16( indx, 0 ) ) { @@ -222,7 +222,7 @@ Word16 ivas_agc_enc_get_flag( Word16 agc_flag; /* AGC is enabled only if there is one transport channel. */ - agc_flag = (Word16) ( EQ_16(nchan_transport, 1 )); + agc_flag = (Word16) ( EQ_16( nchan_transport, 1 ) ); return agc_flag; @@ -310,7 +310,7 @@ static void ivas_agc_enc_init_fx( ivas_agc_initWindowFunc_fx( hAgcEnc->agc_com.winFunc_fx, input_frame - hAgcEnc->agc_com.in_delay ); hAgcEnc->minDelta_fx = AGC_MIN_DELTA_FX; - hAgcEnc->smFact_fx = 214748368;//q31 + hAgcEnc->smFact_fx = 214748368; // q31 for ( i = 0; i < nchan_inp; i++ ) { @@ -919,7 +919,7 @@ void ivas_agc_enc_process_fx( temp_16 = BASOP_Util_Divide3232_Scale( temp1, temp2, &div_e ); IF( LT_16( div_e, 0 ) ) { - temp_16 = shr( temp_16, (Word16)abs( div_e ) ); + temp_16 = shr( temp_16, (Word16) abs( div_e ) ); div_e = 0; } temp_16 = ceil_fx( temp_16, 15 - div_e ); @@ -1173,4 +1173,4 @@ void ivas_agc_enc_process_fx( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index 9a73eb2ed..db7f5d9d1 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -41,7 +41,6 @@ #include - /*-------------------------------------------------------------------* * ivas_core_enc() * diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index 011d5df52..25f6959b7 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -684,7 +684,7 @@ ivas_error pre_proc_front_ivas( * UC and VC frame selection *-----------------------------------------------------------------*/ - find_tilt( fr_bands, st->hNoiseEst->bckr, ee, st->pitch, st->voicing, lf_E, corr_shift, st->input_bwidth, st->max_band, hp_E, MODE1, &( st->bckr_tilt_lt_flt), st->Opt_SC_VBR ); + find_tilt( fr_bands, st->hNoiseEst->bckr, ee, st->pitch, st->voicing, lf_E, corr_shift, st->input_bwidth, st->max_band, hp_E, MODE1, &( st->bckr_tilt_lt_flt ), st->Opt_SC_VBR ); st->coder_type = find_uv( st, pitch_fr, voicing_fr, inp_12k8, ee, &dE1X, corr_shift, *relE, Etot, hp_E, &flag_spitch, last_core_orig, hStereoClassif ); diff --git a/lib_enc/ivas_corecoder_enc_reconfig.c b/lib_enc/ivas_corecoder_enc_reconfig.c index 8080cd5c4..21eedf230 100644 --- a/lib_enc/ivas_corecoder_enc_reconfig.c +++ b/lib_enc/ivas_corecoder_enc_reconfig.c @@ -384,7 +384,6 @@ ivas_error ivas_corecoder_enc_reconfig( } - if ( last_mc_mode == MC_MODE_MCMASA && st_ivas->mc_mode == MC_MODE_MCMASA ) { /* restore modified transport signal */ diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index e5d92d6fd..5e9f49ba7 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -973,260 +973,260 @@ ivas_error create_cpe_enc( } #ifdef IVAS_FLOAT_FIXED ivas_error create_cpe_enc_fx( - Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ - const Word16 cpe_id, /* i : CPE # identifier */ - const Word32 element_brate /* i : element bitrate */ + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const Word16 cpe_id, /* i : CPE # identifier */ + const Word32 element_brate /* i : element bitrate */ ) { - Word16 n; - Word16 ivas_format, element_mode_init, max_bwidth; - Word32 input_Fs; - CPE_ENC_HANDLE hCPE; - Encoder_State *st; - ENCODER_CONFIG_HANDLE hEncoderConfig; - ivas_error error; - - error = IVAS_ERR_OK; - - hEncoderConfig = st_ivas->hEncoderConfig; - - ivas_format = hEncoderConfig->ivas_format; - element_mode_init = hEncoderConfig->element_mode_init; - input_Fs = hEncoderConfig->input_Fs; - max_bwidth = hEncoderConfig->max_bwidth; - - /*-----------------------------------------------------------------* - * Allocate CPE handle - *-----------------------------------------------------------------*/ - - IF ((hCPE = (CPE_ENC_HANDLE)malloc(sizeof(CPE_ENC_DATA))) == NULL) - { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CPE\n")); - } - - /*-----------------------------------------------------------------* - * Initialization - general parameters - *-----------------------------------------------------------------*/ - - hCPE->cpe_id = cpe_id; - hCPE->element_brate = element_brate; - hCPE->last_element_brate = hCPE->element_brate; - hCPE->element_mode = element_mode_init; - hCPE->last_element_mode = element_mode_init; - - hCPE->hStereoDft = NULL; - hCPE->hStereoTD = NULL; - hCPE->hStereoMdct = NULL; - hCPE->hStereoTCA = NULL; - hCPE->hStereoICBWE = NULL; - hCPE->hMetaData = NULL; - - hCPE->hStereoCng = NULL; - hCPE->hFrontVad[0] = NULL; - hCPE->hFrontVad[1] = NULL; - - hCPE->brate_surplus = 0; - - /*-----------------------------------------------------------------* - * Input memory buffer: allocate and initialize - *-----------------------------------------------------------------*/ - - FOR (n = 0; n < CPE_CHANNELS; n++) - { - IF (EQ_16(ivas_format, STEREO_FORMAT) || EQ_16(ivas_format, MASA_FORMAT) || (EQ_16(ivas_format, MC_FORMAT) && EQ_16(st_ivas->mc_mode, MC_MODE_MCMASA)) || EQ_16(ivas_format, MASA_ISM_FORMAT)) - { - IF((hCPE->input_mem_fx[n] = (Word32 *)malloc(sizeof(Word32) * NS2SA(input_Fs, STEREO_DFT_OVL_NS))) == NULL) - { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DFT stereo memory\n")); - } - - set_zero_fx(hCPE->input_mem_fx[n], NS2SA(input_Fs, STEREO_DFT_OVL_NS)); - } - ELSE - { - hCPE->input_mem[n] = NULL; - hCPE->input_mem_fx[n] = NULL; - } - } + Word16 n; + Word16 ivas_format, element_mode_init, max_bwidth; + Word32 input_Fs; + CPE_ENC_HANDLE hCPE; + Encoder_State *st; + ENCODER_CONFIG_HANDLE hEncoderConfig; + ivas_error error; - /*-----------------------------------------------------------------* - * stereo classifier: allocate and initialize - *-----------------------------------------------------------------*/ + error = IVAS_ERR_OK; - IF ((hCPE->hStereoClassif = (STEREO_CLASSIF_HANDLE)malloc(sizeof(STEREO_CLASSIF_DATA))) == NULL) - { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for stereo classifier structure\n")); - } + hEncoderConfig = st_ivas->hEncoderConfig; - stereo_classifier_init_fx(hCPE->hStereoClassif); + ivas_format = hEncoderConfig->ivas_format; + element_mode_init = hEncoderConfig->element_mode_init; + input_Fs = hEncoderConfig->input_Fs; + max_bwidth = hEncoderConfig->max_bwidth; - /*-----------------------------------------------------------------* - * Metadata: allocate and initialize - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * Allocate CPE handle + *-----------------------------------------------------------------*/ - IF (EQ_16( cpe_id, sub(st_ivas->nCPE, 1))) - { - IF ((error = ivas_initialize_MD_bstr_enc(&(hCPE->hMetaData), st_ivas)) != IVAS_ERR_OK) + IF( ( hCPE = (CPE_ENC_HANDLE) malloc( sizeof( CPE_ENC_DATA ) ) ) == NULL ) { - return error; + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CPE\n" ) ); } - } - /*-----------------------------------------------------------------* - * CoreCoder, 2 instances: allocate and initialize - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * Initialization - general parameters + *-----------------------------------------------------------------*/ - FOR (n = 0; n < CPE_CHANNELS; n++) - { - IF ((st = (ENC_CORE_HANDLE)malloc(sizeof(Encoder_State))) == NULL) - { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CoreCoder structure\n")); - } + hCPE->cpe_id = cpe_id; + hCPE->element_brate = element_brate; + hCPE->last_element_brate = hCPE->element_brate; + hCPE->element_mode = element_mode_init; + hCPE->last_element_mode = element_mode_init; + + hCPE->hStereoDft = NULL; + hCPE->hStereoTD = NULL; + hCPE->hStereoMdct = NULL; + hCPE->hStereoTCA = NULL; + hCPE->hStereoICBWE = NULL; + hCPE->hMetaData = NULL; + + hCPE->hStereoCng = NULL; + hCPE->hFrontVad[0] = NULL; + hCPE->hFrontVad[1] = NULL; + + hCPE->brate_surplus = 0; - copy_encoder_config_fx(st_ivas, st, 1); + /*-----------------------------------------------------------------* + * Input memory buffer: allocate and initialize + *-----------------------------------------------------------------*/ - IF(GT_16(st_ivas->nCPE, 1)) + FOR( n = 0; n < CPE_CHANNELS; n++ ) { - st->total_brate = hCPE->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + IF( EQ_16( ivas_format, STEREO_FORMAT ) || EQ_16( ivas_format, MASA_FORMAT ) || ( EQ_16( ivas_format, MC_FORMAT ) && EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) || EQ_16( ivas_format, MASA_ISM_FORMAT ) ) + { + IF( ( hCPE->input_mem_fx[n] = (Word32 *) malloc( sizeof( Word32 ) * NS2SA( input_Fs, STEREO_DFT_OVL_NS ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DFT stereo memory\n" ) ); + } + + set_zero_fx( hCPE->input_mem_fx[n], NS2SA( input_Fs, STEREO_DFT_OVL_NS ) ); + } + ELSE + { + hCPE->input_mem[n] = NULL; + hCPE->input_mem_fx[n] = NULL; + } } - ELSE + + /*-----------------------------------------------------------------* + * stereo classifier: allocate and initialize + *-----------------------------------------------------------------*/ + + IF( ( hCPE->hStereoClassif = (STEREO_CLASSIF_HANDLE) malloc( sizeof( STEREO_CLASSIF_DATA ) ) ) == NULL ) { - st->total_brate = L_shr(hCPE->element_brate, CPE_CHANNELS); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for stereo classifier structure\n" ) ); } - st->mct_chan_mode = MCT_CHAN_MODE_REGULAR; - IF ((error = init_encoder_ivas_fx(st, st_ivas, n, hEncoderConfig->var_SID_rate_flag, hEncoderConfig->interval_SID, 0, ISM_MODE_NONE, hCPE->element_brate)) != IVAS_ERR_OK) + stereo_classifier_init_fx( hCPE->hStereoClassif ); + + /*-----------------------------------------------------------------* + * Metadata: allocate and initialize + *-----------------------------------------------------------------*/ + + IF( EQ_16( cpe_id, sub( st_ivas->nCPE, 1 ) ) ) { - return error; + IF( ( error = ivas_initialize_MD_bstr_enc( &( hCPE->hMetaData ), st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } } - IF (st->hFdCngEnc != NULL) + /*-----------------------------------------------------------------* + * CoreCoder, 2 instances: allocate and initialize + *-----------------------------------------------------------------*/ + + FOR( n = 0; n < CPE_CHANNELS; n++ ) { - st->hFdCngEnc->hFdCngCom->CngBitrate = L_sub(hCPE->element_brate, 1); - } + IF( ( st = (ENC_CORE_HANDLE) malloc( sizeof( Encoder_State ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CoreCoder structure\n" ) ); + } - hCPE->hCoreCoder[n] = st; - } + copy_encoder_config_fx( st_ivas, st, 1 ); - /*-----------------------------------------------------------------* - * LR VAD initialization - *-----------------------------------------------------------------*/ + IF( GT_16( st_ivas->nCPE, 1 ) ) + { + st->total_brate = hCPE->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + } + ELSE + { + st->total_brate = L_shr( hCPE->element_brate, CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + } + st->mct_chan_mode = MCT_CHAN_MODE_REGULAR; - IF (hEncoderConfig->Opt_DTX_ON) - { - IF (EQ_16(hCPE->element_mode, IVAS_CPE_TD) || EQ_16(hCPE->element_mode, IVAS_CPE_DFT)) - { - IF ((hCPE->hStereoCng = (STEREO_CNG_ENC_HANDLE)malloc(sizeof(STEREO_CNG_ENC))) == NULL) - { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo Cng for Unified/TD \n")); - } + IF( ( error = init_encoder_ivas_fx( st, st_ivas, n, hEncoderConfig->var_SID_rate_flag, hEncoderConfig->interval_SID, 0, ISM_MODE_NONE, hCPE->element_brate ) ) != IVAS_ERR_OK ) + { + return error; + } - stereo_enc_cng_init(hCPE->hStereoCng); + IF( st->hFdCngEnc != NULL ) + { + st->hFdCngEnc->hFdCngCom->CngBitrate = L_sub( hCPE->element_brate, 1 ); + } + + hCPE->hCoreCoder[n] = st; } - } - ELSE - { - hCPE->hStereoCng = NULL; - } - IF (hEncoderConfig->Opt_DTX_ON && EQ_16(element_mode_init, IVAS_CPE_MDCT)) - { - FOR (n = 0; n < CPE_CHANNELS; n++) + /*-----------------------------------------------------------------* + * LR VAD initialization + *-----------------------------------------------------------------*/ + + IF( hEncoderConfig->Opt_DTX_ON ) { - IF ((error = front_vad_create_fx(&(hCPE->hFrontVad[n]), hEncoderConfig)) != IVAS_ERR_OK) - { - return error; - } + IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) || EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) + { + IF( ( hCPE->hStereoCng = (STEREO_CNG_ENC_HANDLE) malloc( sizeof( STEREO_CNG_ENC ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo Cng for Unified/TD \n" ) ); + } + + stereo_enc_cng_init( hCPE->hStereoCng ); + } } - } - ELSE - { - FOR (n = 0; n < CPE_CHANNELS; n++) + ELSE { - hCPE->hFrontVad[n] = NULL; + hCPE->hStereoCng = NULL; } - } - - /*-----------------------------------------------------------------* - * DFT stereo initialization - *-----------------------------------------------------------------*/ - IF (EQ_16(hCPE->element_mode, IVAS_CPE_DFT)) - { - IF ((error = stereo_dft_enc_create_fx(&(hCPE->hStereoDft), input_Fs, max_bwidth)) != IVAS_ERR_OK) + IF( hEncoderConfig->Opt_DTX_ON && EQ_16( element_mode_init, IVAS_CPE_MDCT ) ) + { + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + IF( ( error = front_vad_create_fx( &( hCPE->hFrontVad[n] ), hEncoderConfig ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + ELSE { - return error; + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + hCPE->hFrontVad[n] = NULL; + } } - } - /*-----------------------------------------------------------------* - * Temporal inter-channel alignment initialization - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * DFT stereo initialization + *-----------------------------------------------------------------*/ - IF (NE_16(hCPE->element_mode, IVAS_CPE_MDCT)) - { - IF ((hCPE->hStereoTCA = (STEREO_TCA_ENC_HANDLE)malloc(sizeof(STEREO_TCA_ENC_DATA))) == NULL) + IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo TCA\n")); + IF( ( error = stereo_dft_enc_create_fx( &( hCPE->hStereoDft ), input_Fs, max_bwidth ) ) != IVAS_ERR_OK ) + { + return error; + } } - stereo_tca_init_enc_fx(hCPE->hStereoTCA, input_Fs); - } - - /*-----------------------------------------------------------------* - * Stereo IC BWE initialization - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * Temporal inter-channel alignment initialization + *-----------------------------------------------------------------*/ - IF (NE_16(hCPE->element_mode, IVAS_CPE_MDCT)) - { - IF ((hCPE->hStereoICBWE = (STEREO_ICBWE_ENC_HANDLE)malloc(sizeof(STEREO_ICBWE_ENC_DATA))) == NULL) + IF( NE_16( hCPE->element_mode, IVAS_CPE_MDCT ) ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo ICBWE \n")); - } + IF( ( hCPE->hStereoTCA = (STEREO_TCA_ENC_HANDLE) malloc( sizeof( STEREO_TCA_ENC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo TCA\n" ) ); + } - stereo_icBWE_init_enc_fx(hCPE->hStereoICBWE); - } + stereo_tca_init_enc_fx( hCPE->hStereoTCA, input_Fs ); + } - /*-----------------------------------------------------------------* - * TD stereo initialization - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * Stereo IC BWE initialization + *-----------------------------------------------------------------*/ - IF (hCPE->element_mode == IVAS_CPE_TD) - { - IF ((hCPE->hStereoTD = (STEREO_TD_ENC_DATA_HANDLE)malloc(sizeof(STEREO_TD_ENC_DATA))) == NULL) + IF( NE_16( hCPE->element_mode, IVAS_CPE_MDCT ) ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD Stereo\n")); - } + IF( ( hCPE->hStereoICBWE = (STEREO_ICBWE_ENC_HANDLE) malloc( sizeof( STEREO_ICBWE_ENC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo ICBWE \n" ) ); + } - stereo_td_init_enc_fx(hCPE->hStereoTD, hCPE->last_element_mode); - } + stereo_icBWE_init_enc_fx( hCPE->hStereoICBWE ); + } - /*-----------------------------------------------------------------* - * MDCT stereo initialization - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * TD stereo initialization + *-----------------------------------------------------------------*/ - IF (EQ_16(hCPE->element_mode, IVAS_CPE_MDCT) && EQ_16(st_ivas->nCPE, 1)) - { - IF ((hCPE->hStereoMdct = (STEREO_MDCT_ENC_DATA_HANDLE)malloc(sizeof(STEREO_MDCT_ENC_DATA))) == NULL) + IF( hCPE->element_mode == IVAS_CPE_TD ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n")); + IF( ( hCPE->hStereoTD = (STEREO_TD_ENC_DATA_HANDLE) malloc( sizeof( STEREO_TD_ENC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD Stereo\n" ) ); + } + + stereo_td_init_enc_fx( hCPE->hStereoTD, hCPE->last_element_mode ); } - initMdctStereoEncData_fx(hCPE->hStereoMdct, ivas_format, hCPE->element_mode, hCPE->element_brate, max_bwidth, 0, NULL, 1); - hCPE->hStereoMdct->isSBAStereoMode = ((EQ_16(ivas_format, SBA_FORMAT) || EQ_16(ivas_format, SBA_ISM_FORMAT)) && EQ_16(st_ivas->nchan_transport, 2)); + /*-----------------------------------------------------------------* + * MDCT stereo initialization + *-----------------------------------------------------------------*/ - IF (EQ_16(hCPE->element_mode, IVAS_CPE_MDCT) && LE_32(element_brate, MAX_MDCT_ITD_BRATE) && EQ_16(ivas_format, STEREO_FORMAT)) + IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) && EQ_16( st_ivas->nCPE, 1 ) ) { - IF ((error = initMdctItdHandling_fx(hCPE->hStereoMdct, input_Fs)) != IVAS_ERR_OK) - { - return error; - } + IF( ( hCPE->hStereoMdct = (STEREO_MDCT_ENC_DATA_HANDLE) malloc( sizeof( STEREO_MDCT_ENC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n" ) ); + } + + initMdctStereoEncData_fx( hCPE->hStereoMdct, ivas_format, hCPE->element_mode, hCPE->element_brate, max_bwidth, 0, NULL, 1 ); + hCPE->hStereoMdct->isSBAStereoMode = ( ( EQ_16( ivas_format, SBA_FORMAT ) || EQ_16( ivas_format, SBA_ISM_FORMAT ) ) && EQ_16( st_ivas->nchan_transport, 2 ) ); + + IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) && LE_32( element_brate, MAX_MDCT_ITD_BRATE ) && EQ_16( ivas_format, STEREO_FORMAT ) ) + { + IF( ( error = initMdctItdHandling_fx( hCPE->hStereoMdct, input_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } + } } - } - st_ivas->hCPE[cpe_id] = hCPE; + st_ivas->hCPE[cpe_id] = hCPE; - return error; + return error; } #endif /*------------------------------------------------------------------------- @@ -1242,15 +1242,15 @@ void destroy_cpe_enc( Word16 n; Encoder_State *st; - IF ( hCPE->hStereoClassif != NULL ) + IF( hCPE->hStereoClassif != NULL ) { free( hCPE->hStereoClassif ); hCPE->hStereoClassif = NULL; } - FOR ( n = 0; n < CPE_CHANNELS; n++ ) + FOR( n = 0; n < CPE_CHANNELS; n++ ) { - IF ( hCPE->input_mem[n] != NULL ) + IF( hCPE->input_mem[n] != NULL ) { free( hCPE->input_mem[n] ); hCPE->input_mem[n] = NULL; @@ -1259,56 +1259,56 @@ void destroy_cpe_enc( ivas_destroy_MD_bstr_enc( &( hCPE->hMetaData ) ); - FOR ( n = 0; n < CPE_CHANNELS; n++ ) + FOR( n = 0; n < CPE_CHANNELS; n++ ) { st = hCPE->hCoreCoder[n]; - IF ( st != NULL ) + IF( st != NULL ) { destroy_core_enc( st ); st = NULL; } } - IF ( hCPE->hStereoDft != NULL ) + IF( hCPE->hStereoDft != NULL ) { stereo_dft_enc_destroy( &hCPE->hStereoDft ); hCPE->hStereoDft = NULL; } - IF ( hCPE->hStereoTD != NULL ) + IF( hCPE->hStereoTD != NULL ) { free( hCPE->hStereoTD ); hCPE->hStereoTD = NULL; } - IF ( hCPE->hStereoMdct != NULL ) + IF( hCPE->hStereoMdct != NULL ) { stereo_mdct_enc_destroy( &hCPE->hStereoMdct ); hCPE->hStereoMdct = NULL; } - IF ( hCPE->hStereoTCA != NULL ) + IF( hCPE->hStereoTCA != NULL ) { free( hCPE->hStereoTCA ); hCPE->hStereoTCA = NULL; } - IF ( hCPE->hStereoICBWE != NULL ) + IF( hCPE->hStereoICBWE != NULL ) { free( hCPE->hStereoICBWE ); hCPE->hStereoICBWE = NULL; } - IF ( hCPE->hStereoCng != NULL ) + IF( hCPE->hStereoCng != NULL ) { free( hCPE->hStereoCng ); hCPE->hStereoCng = NULL; } - IF ( hCPE->hFrontVad[0] != NULL ) + IF( hCPE->hFrontVad[0] != NULL ) { - FOR ( n = 0; n < CPE_CHANNELS; n++ ) + FOR( n = 0; n < CPE_CHANNELS; n++ ) { front_vad_destroy( &hCPE->hFrontVad[n] ); hCPE->hFrontVad[n] = NULL; diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 464d7b570..23dee7bc6 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -136,11 +136,11 @@ ivas_error ivas_enc( { if ( ( ivas_format == SBA_FORMAT ) && !( st_ivas->sba_analysis_order > 1 ) ) { - hp20_flt( data_f[HOA_keep_ind[st_ivas->hSpar->hMdEnc->HOA_md_ind[i]]], input_frame, st_ivas->mem_hp20_in[i], input_Fs ); + hp20_flt( data_f[HOA_keep_ind[st_ivas->hSpar->hMdEnc->HOA_md_ind[i]]], input_frame, st_ivas->mem_hp20_in[i], input_Fs ); } else if ( !( ivas_format == MC_FORMAT && i == LFE_CHANNEL ) ) { - hp20_flt( data_f[i], input_frame, st_ivas->mem_hp20_in[i], input_Fs ); + hp20_flt( data_f[i], input_frame, st_ivas->mem_hp20_in[i], input_Fs ); } } @@ -434,30 +434,31 @@ ivas_error ivas_enc( st_ivas->hLFE->hBstr = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0]->hBstr : st_ivas->hCPE[0]->hCoreCoder[0]->hBstr; #ifdef IVAS_FLOAT_FIXED - Word16 q_data_lfe_ch; - Word32 data_lfe_ch_fx[L_FRAME48k]; - float max_val = 0; + Word16 q_data_lfe_ch; + Word32 data_lfe_ch_fx[L_FRAME48k]; + float max_val = 0; - for (int ii = 0; ii < input_frame; ii++) { - if (max_val < (float)fabs(data_f[LFE_CHANNEL][ii])) - max_val = (float)fabs(data_f[LFE_CHANNEL][ii]); - } + for ( int ii = 0; ii < input_frame; ii++ ) + { + if ( max_val < (float) fabs( data_f[LFE_CHANNEL][ii] ) ) + max_val = (float) fabs( data_f[LFE_CHANNEL][ii] ); + } - if ((Word32)max_val == 0) - q_data_lfe_ch = 31; - else - q_data_lfe_ch = norm_l((Word32)max_val); + if ( (Word32) max_val == 0 ) + q_data_lfe_ch = 31; + else + q_data_lfe_ch = norm_l( (Word32) max_val ); - for (int ii = 0; ii < input_frame; ii++) { - data_lfe_ch_fx[ii] = (Word32)(data_f[LFE_CHANNEL][ii] * (1 << q_data_lfe_ch)); - } + for ( int ii = 0; ii < input_frame; ii++ ) + { + data_lfe_ch_fx[ii] = (Word32) ( data_f[LFE_CHANNEL][ii] * ( 1 << q_data_lfe_ch ) ); + } ivas_lfe_enc_fx( st_ivas->hLFE, data_lfe_ch_fx, q_data_lfe_ch, input_frame, st_ivas->hLFE->hBstr ); #else ivas_lfe_enc( st_ivas->hLFE, data_f[LFE_CHANNEL], input_frame, st_ivas->hLFE->hBstr ); #endif // IVAS_FLOAT_FIXED - } if ( st_ivas->mc_mode == MC_MODE_MCT ) @@ -473,30 +474,32 @@ ivas_error ivas_enc( ivas_mc_paramupmix_enc( st_ivas, hMetaData, data_f, input_frame ); st_ivas->hLFE->hBstr = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0]->hBstr : st_ivas->hCPE[0]->hCoreCoder[0]->hBstr; - + #ifdef IVAS_FLOAT_FIXED - Word16 q_data_lfe_ch; - Word32 data_lfe_ch_fx[L_FRAME48k]; - float max_val = 0; + Word16 q_data_lfe_ch; + Word32 data_lfe_ch_fx[L_FRAME48k]; + float max_val = 0; - for (int ii = 0; ii < input_frame; ii++) { - if (max_val < (float)fabs(data_f[LFE_CHANNEL][ii])) - max_val = (float)fabs(data_f[LFE_CHANNEL][ii]); - } + for ( int ii = 0; ii < input_frame; ii++ ) + { + if ( max_val < (float) fabs( data_f[LFE_CHANNEL][ii] ) ) + max_val = (float) fabs( data_f[LFE_CHANNEL][ii] ); + } - if ((Word32)max_val == 0) - q_data_lfe_ch = 31; - else - q_data_lfe_ch = norm_l((Word32)max_val); + if ( (Word32) max_val == 0 ) + q_data_lfe_ch = 31; + else + q_data_lfe_ch = norm_l( (Word32) max_val ); - for (int ii = 0; ii < input_frame; ii++) { - data_lfe_ch_fx[ii] = (Word32)(data_f[LFE_CHANNEL][ii] * (1 << q_data_lfe_ch)); - } + for ( int ii = 0; ii < input_frame; ii++ ) + { + data_lfe_ch_fx[ii] = (Word32) ( data_f[LFE_CHANNEL][ii] * ( 1 << q_data_lfe_ch ) ); + } - ivas_lfe_enc_fx(st_ivas->hLFE, data_lfe_ch_fx, q_data_lfe_ch, input_frame, st_ivas->hLFE->hBstr); + ivas_lfe_enc_fx( st_ivas->hLFE, data_lfe_ch_fx, q_data_lfe_ch, input_frame, st_ivas->hLFE->hBstr ); #else - ivas_lfe_enc( st_ivas->hLFE, data_f[LFE_CHANNEL], input_frame, st_ivas->hLFE->hBstr ); + ivas_lfe_enc( st_ivas->hLFE, data_f[LFE_CHANNEL], input_frame, st_ivas->hLFE->hBstr ); #endif // IVAS_FLOAT_FIXED if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) diff --git a/lib_enc/ivas_entropy_coder.c b/lib_enc/ivas_entropy_coder.c index f245fe738..757378034 100644 --- a/lib_enc/ivas_entropy_coder.c +++ b/lib_enc/ivas_entropy_coder.c @@ -81,7 +81,7 @@ static ivas_error ivas_get_dyn_freq_model( } curr_bps_min = curr_bps; #ifdef DUMPS_ENABLED - dbgwrite_txt(&curr_bps_min, 1, "float_curr_bps_min.txt", NULL); + dbgwrite_txt( &curr_bps_min, 1, "float_curr_bps_min.txt", NULL ); #endif model_idx = 0; @@ -93,7 +93,7 @@ static ivas_error ivas_get_dyn_freq_model( curr_bps_new -= ( curr_dist[i] * pArith->saved_dist_arr[m + 1][i] ); } #ifdef DUMPS_ENABLED - dbgwrite_txt(&curr_bps_new, 1, "float_curr_bps_new.txt", NULL); + dbgwrite_txt( &curr_bps_new, 1, "float_curr_bps_new.txt", NULL ); #endif if ( curr_bps_new < curr_bps_min ) { @@ -139,55 +139,55 @@ static ivas_error ivas_get_dyn_freq_model_fx( ivas_error error; error = IVAS_ERR_OK; -FOR(i=0;isaved_dist_arr[0][i]); + curr_dist[i] = (Word32) n[i]; + curr_bps = L_sub( curr_bps, curr_dist[i] * pArith->saved_dist_arr[0][i] ); } curr_bps_min = curr_bps; #ifdef DUMPS_ENABLED { - float a = curr_bps_min/32768.0f; - dbgwrite_txt(&a, 1, "fixed_curr_bps_min.txt", NULL); + float a = curr_bps_min / 32768.0f; + dbgwrite_txt( &a, 1, "fixed_curr_bps_min.txt", NULL ); } #endif model_idx = 0; - FOR ( m = 0; m < pArith->num_models - 1; m++ ) + FOR( m = 0; m < pArith->num_models - 1; m++ ) { curr_bps_new = 0; - FOR ( i = 0; i < range; i++ ) + FOR( i = 0; i < range; i++ ) { - curr_bps_new = L_sub(curr_bps_new, (curr_dist[i] * pArith->saved_dist_arr[m + 1][i] )); + curr_bps_new = L_sub( curr_bps_new, ( curr_dist[i] * pArith->saved_dist_arr[m + 1][i] ) ); } #ifdef DUMPS_ENABLED { - float a = curr_bps_new/32768.0f; - dbgwrite_txt(&a, 1, "fixed_curr_bps_new.txt", NULL); + float a = curr_bps_new / 32768.0f; + dbgwrite_txt( &a, 1, "fixed_curr_bps_new.txt", NULL ); } #endif - IF ( LT_32(curr_bps_new, curr_bps_min) ) + IF( LT_32( curr_bps_new, curr_bps_min ) ) { model_idx = m; curr_bps_min = curr_bps_new; } } - IF ( LT_32(curr_bps_min, curr_bps) ) + IF( LT_32( curr_bps_min, curr_bps ) ) { *ppCum_freq = pArith->cum_freq[model_idx + 1]; - model_idx = add(model_idx, 1); + model_idx = add( model_idx, 1 ); } ELSE { @@ -217,16 +217,16 @@ static Word16 ivas_arith_encode_array( Word16 *pCum_freq = NULL; Tastat as; - IF ( GT_16(in_len, 0) && GT_16(pArith->range, 1) ) + IF( GT_16( in_len, 0 ) && GT_16( pArith->range, 1 ) ) { - IF ( GT_16(pArith->dyn_model_bits, 0) ) + IF( GT_16( pArith->dyn_model_bits, 0 ) ) { #ifdef IVAS_FLOAT_FIXED ivas_get_dyn_freq_model_fx( pInput, in_len, &model_index, pArith, &pCum_freq ); #else ivas_get_dyn_freq_model( pInput, in_len, &model_index, pArith, &pCum_freq ); #endif - IF ( GT_16(add( hMetaData->nb_bits_tot, pArith->dyn_model_bits ), wc_strat_arith )) + IF( GT_16( add( hMetaData->nb_bits_tot, pArith->dyn_model_bits ), wc_strat_arith ) ) { return -1; } @@ -240,19 +240,19 @@ static Word16 ivas_arith_encode_array( ari_start_encoding_14bits( &as ); - FOR ( i = 0; i < in_len; i++ ) + FOR( i = 0; i < in_len; i++ ) { - ind = sub(pInput[i], pArith->vals[0]); + ind = sub( pInput[i], pArith->vals[0] ); ivas_ari_encode_14bits_ext( hMetaData, &as, ind, (const UWord16 *) pCum_freq ); - IF ( GT_16(hMetaData->nb_bits_tot, wc_strat_arith )) + IF( GT_16( hMetaData->nb_bits_tot, wc_strat_arith ) ) { return -1; } } ivas_ari_done_encoding_14bits( hMetaData, &as ); - IF ( GT_16(hMetaData->nb_bits_tot, wc_strat_arith )) + IF( GT_16( hMetaData->nb_bits_tot, wc_strat_arith ) ) { return -1; } @@ -279,17 +279,17 @@ static Word16 ivas_arithCoder_encode_array_diff( Word16 n; Word16 arith_result; - IF ( GT_16(length, 0 )) + IF( GT_16( length, 0 ) ) { - FOR ( n = 0; n < length; n++ ) + FOR( n = 0; n < length; n++ ) { - pIn_old_scratch[n] = sub(pIn_new[n], pIn_old_scratch[n]); + pIn_old_scratch[n] = sub( pIn_new[n], pIn_old_scratch[n] ); } ivas_wrap_arround( pIn_old_scratch, pArith_diff->vals[0], pArith_diff->vals[pArith_diff->range - 1], length ); arith_result = ivas_arith_encode_array( pIn_old_scratch, pArith_diff, hMetaData, length, wc_strat_arith ); - IF ( LT_16(arith_result, 0 )) + IF( LT_16( arith_result, 0 ) ) { return -1; } @@ -342,19 +342,19 @@ static Word16 arith_encode_cell_array( Word16 i; Word16 arith_result; - FOR ( i = 0; i < nB; i++ ) + FOR( i = 0; i < nB; i++ ) { total_symbol_len += ( pCell_dims[i].dim1 * pCell_dims[i].dim2 ); } - assert( LE_16(total_symbol_len, ( IVAS_MAX_INPUT_LEN ) )); + assert( LE_16( total_symbol_len, ( IVAS_MAX_INPUT_LEN ) ) ); - IF ( GT_16(total_symbol_len, 0 )) + IF( GT_16( total_symbol_len, 0 ) ) { - IF ( GT_16(pArith->range, 1 )) + IF( GT_16( pArith->range, 1 ) ) { arith_result = ivas_arith_encode_array( pSymbol, pArith, hMetaData, total_symbol_len, wc_strat_arith ); - IF ( LT_16(arith_result, 0 )) + IF( LT_16( arith_result, 0 ) ) { return -1; } @@ -384,19 +384,19 @@ static Word16 arith_encode_cell_array_diff( Word16 arith_result; total_symbol_len = 0; - FOR ( i = 0; i < nB; i++ ) + FOR( i = 0; i < nB; i++ ) { total_symbol_len += ( pCell_dims[i].dim1 * pCell_dims[i].dim2 ); } - assert( LE_16(total_symbol_len, ( IVAS_MAX_INPUT_LEN )) ); + assert( LE_16( total_symbol_len, ( IVAS_MAX_INPUT_LEN ) ) ); - IF ( GT_16(total_symbol_len, 0 )) + IF( GT_16( total_symbol_len, 0 ) ) { - IF ( GT_16(pArith_diff->range, 1 )) + IF( GT_16( pArith_diff->range, 1 ) ) { arith_result = ivas_arithCoder_encode_array_diff( pArith_diff, pSymbol, pSymbol_old, total_symbol_len, hMetaData, wc_strat_arith ); - IF ( LT_16(arith_result, 0 )) + IF( LT_16( arith_result, 0 ) ) { return -1; } @@ -434,16 +434,16 @@ Word16 ivas_arith_encode_cmplx_cell_array( Word16 arith_result; idx1 = 0; - IF ( EQ_16(any_diff, 1 )) + IF( EQ_16( any_diff, 1 ) ) { idx = 0; total_len = 0; - FOR ( i = 0; i < nB; i++ ) + FOR( i = 0; i < nB; i++ ) { len = ( pCell_dims[i].dim1 * pCell_dims[i].dim2 ); - IF ( NE_16(pDo_diff[i] , 0 )) + IF( NE_16( pDo_diff[i], 0 ) ) { - FOR ( j = 0; j < len; j++ ) + FOR( j = 0; j < len; j++ ) { input_old[idx] = pSymbol_old_re[total_len + j]; input_new[idx++] = pSymbol_re[total_len + j]; @@ -455,7 +455,7 @@ Word16 ivas_arith_encode_cmplx_cell_array( } ELSE { - FOR ( j = 0; j < len; j++ ) + FOR( j = 0; j < len; j++ ) { input[idx1++] = pSymbol_re[total_len + j]; } @@ -464,17 +464,17 @@ Word16 ivas_arith_encode_cmplx_cell_array( cell_dim[i].dim1 = pCell_dims[i].dim1; cell_dim[i].dim2 = pCell_dims[i].dim2; } - total_len = add(total_len, len); + total_len = add( total_len, len ); } arith_result = arith_encode_cell_array( cell_dim, hMetaData, nB, pArith_re, input, wc_strat_arith ); - IF ( LT_16(arith_result, 0 )) + IF( LT_16( arith_result, 0 ) ) { return -1; } arith_result = arith_encode_cell_array_diff( cell_dim_diff, hMetaData, nB, pArith_re_diff, input_old, input_new, wc_strat_arith ); - IF ( LT_16(arith_result, 0 )) + IF( LT_16( arith_result, 0 ) ) { return -1; } @@ -482,7 +482,7 @@ Word16 ivas_arith_encode_cmplx_cell_array( ELSE { arith_result = arith_encode_cell_array( pCell_dims, hMetaData, nB, pArith_re, pSymbol_re, wc_strat_arith ); - IF ( LT_16(arith_result, 0 )) + IF( LT_16( arith_result, 0 ) ) { return -1; } diff --git a/lib_enc/ivas_front_vad.c b/lib_enc/ivas_front_vad.c index 7e0b163f0..65748bfba 100644 --- a/lib_enc/ivas_front_vad.c +++ b/lib_enc/ivas_front_vad.c @@ -298,52 +298,52 @@ ivas_error front_vad_create( } #ifdef IVAS_FLOAT_FIXED ivas_error front_vad_create_fx( - FRONT_VAD_ENC_HANDLE *hFrontVad_out, /* i/o: front-VAD handle */ - const ENCODER_CONFIG_HANDLE hEncoderConfig /* i : configuration structure */ + FRONT_VAD_ENC_HANDLE *hFrontVad_out, /* i/o: front-VAD handle */ + const ENCODER_CONFIG_HANDLE hEncoderConfig /* i : configuration structure */ ) { - FRONT_VAD_ENC_HANDLE hFrontVad; - - IF ((hFrontVad = (FRONT_VAD_ENC_HANDLE)malloc(sizeof(FRONT_VAD_ENC))) == NULL) - { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for front-VAD structure \n")); - } - - IF ((hFrontVad->hNoiseEst = (NOISE_EST_HANDLE)malloc(sizeof(NOISE_EST_DATA))) == NULL) - { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Noise estimation\n")); - } - noise_est_init_fx(hFrontVad->hNoiseEst); - - IF ((hFrontVad->hVAD = (VAD_HANDLE)malloc(sizeof(VAD_DATA))) == NULL) - { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VAD\n")); - } - wb_vad_init_ivas_fx(hFrontVad->hVAD); - - hFrontVad->lp_speech_fx = 23040; /* Initialize the long-term active speech level in dB */ - hFrontVad->lp_noise_fx = 0; /* Initialize the long-term noise level in dB */ - set32_fx(hFrontVad->mem_decim_fx, 0, shl(L_FILT_MAX, 1)); - set32_fx(hFrontVad->buffer_12k8_fx, 0, i_mult(3, shr(L_FRAME, 1))); - hFrontVad->mem_preemph_fx = 0; - hFrontVad->ini_frame = 0; - hFrontVad->hVAD->vad_flag = 1; - - /* allocate delay buffer to compensate for filterbank delay */ - hFrontVad->delay_samples = NS2SA(hEncoderConfig->input_Fs, IVAS_FB_ENC_DELAY_NS); - hFrontVad->delay_buf_fx = NULL; - IF (GT_16(hFrontVad->delay_samples, 0)) - { - IF ((hFrontVad->delay_buf_fx = (Word16 *)malloc(hFrontVad->delay_samples * sizeof(Word16))) == NULL) + FRONT_VAD_ENC_HANDLE hFrontVad; + + IF( ( hFrontVad = (FRONT_VAD_ENC_HANDLE) malloc( sizeof( FRONT_VAD_ENC ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for front-VAD structure \n" ) ); + } + + IF( ( hFrontVad->hNoiseEst = (NOISE_EST_HANDLE) malloc( sizeof( NOISE_EST_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Noise estimation\n" ) ); + } + noise_est_init_fx( hFrontVad->hNoiseEst ); + + IF( ( hFrontVad->hVAD = (VAD_HANDLE) malloc( sizeof( VAD_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VAD\n" ) ); + } + wb_vad_init_ivas_fx( hFrontVad->hVAD ); + + hFrontVad->lp_speech_fx = 23040; /* Initialize the long-term active speech level in dB */ + hFrontVad->lp_noise_fx = 0; /* Initialize the long-term noise level in dB */ + set32_fx( hFrontVad->mem_decim_fx, 0, shl( L_FILT_MAX, 1 ) ); + set32_fx( hFrontVad->buffer_12k8_fx, 0, i_mult( 3, shr( L_FRAME, 1 ) ) ); + hFrontVad->mem_preemph_fx = 0; + hFrontVad->ini_frame = 0; + hFrontVad->hVAD->vad_flag = 1; + + /* allocate delay buffer to compensate for filterbank delay */ + hFrontVad->delay_samples = NS2SA( hEncoderConfig->input_Fs, IVAS_FB_ENC_DELAY_NS ); + hFrontVad->delay_buf_fx = NULL; + IF( GT_16( hFrontVad->delay_samples, 0 ) ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VAD delay buffer\n")); + IF( ( hFrontVad->delay_buf_fx = (Word16 *) malloc( hFrontVad->delay_samples * sizeof( Word16 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VAD delay buffer\n" ) ); + } + set16_fx( hFrontVad->delay_buf_fx, 0, hFrontVad->delay_samples ); } - set16_fx(hFrontVad->delay_buf_fx, 0, hFrontVad->delay_samples); - } - *hFrontVad_out = hFrontVad; + *hFrontVad_out = hFrontVad; - return IVAS_ERR_OK; + return IVAS_ERR_OK; } #endif @@ -357,7 +357,7 @@ void front_vad_destroy( FRONT_VAD_ENC_HANDLE *hFrontVad /* i/o: front-VAD handle */ ) { - IF ( *hFrontVad != NULL ) + IF( *hFrontVad != NULL ) { free( ( *hFrontVad )->hNoiseEst ); ( *hFrontVad )->hNoiseEst = NULL; @@ -365,7 +365,7 @@ void front_vad_destroy( free( ( *hFrontVad )->hVAD ); ( *hFrontVad )->hVAD = NULL; - IF ( ( *hFrontVad )->delay_buf != NULL ) + IF( ( *hFrontVad )->delay_buf != NULL ) { free( ( *hFrontVad )->delay_buf ); ( *hFrontVad )->delay_buf = NULL; diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 0ef9e6065..6137f0114 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -282,11 +282,11 @@ void copy_encoder_config( #ifdef IVAS_FLOAT_FIXED void copy_encoder_config_fx( Encoder_Struct *st_ivas, /* i : IVAS encoder structure */ - Encoder_State *st_fx, /* o : encoder state structure */ - const Word16 flag_all /* i : flag 1==update all, 0=partial update*/ + Encoder_State *st_fx, /* o : encoder state structure */ + const Word16 flag_all /* i : flag 1==update all, 0=partial update*/ ) { - IF ( flag_all ) + IF( flag_all ) { st_fx->input_Fs = st_ivas->hEncoderConfig->input_Fs; @@ -326,12 +326,12 @@ void ivas_initialize_handles_enc( { Word16 i; - FOR ( i = 0; i < MAX_SCE; i++ ) + FOR( i = 0; i < MAX_SCE; i++ ) { st_ivas->hSCE[i] = NULL; } - FOR ( i = 0; i < MAX_CPE; i++ ) + FOR( i = 0; i < MAX_CPE; i++ ) { st_ivas->hCPE[i] = NULL; } @@ -339,7 +339,7 @@ void ivas_initialize_handles_enc( st_ivas->mem_hp20_in = NULL; /* ISM metadata handles */ - FOR ( i = 0; i < MAX_NUM_OBJECTS; i++ ) + FOR( i = 0; i < MAX_NUM_OBJECTS; i++ ) { st_ivas->hIsmMetaData[i] = NULL; } @@ -519,7 +519,7 @@ ivas_error ivas_init_encoder( return error; } #else - if ( ( error = create_evs_sce_enc( st_ivas, sce_id, ivas_total_brate) ) != IVAS_ERR_OK ) + if ( ( error = create_evs_sce_enc( st_ivas, sce_id, ivas_total_brate ) ) != IVAS_ERR_OK ) { return error; } @@ -952,556 +952,556 @@ ivas_error ivas_init_encoder( } #ifdef IVAS_FLOAT_FIXED ivas_error ivas_init_encoder_fx( - Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ) { - Word16 i, n; - Word16 nchan_inp_buff; - Word16 sce_id, cpe_id; - IVAS_FORMAT ivas_format; - Word32 input_Fs, ivas_total_brate; - Word32 element_brate_tmp[MAX_NUM_OBJECTS]; - ENCODER_CONFIG_HANDLE hEncoderConfig; - ivas_error error; - - error = IVAS_ERR_OK; - - hEncoderConfig = st_ivas->hEncoderConfig; - ivas_format = hEncoderConfig->ivas_format; - input_Fs = hEncoderConfig->input_Fs; - ivas_total_brate = hEncoderConfig->ivas_total_brate; - - hEncoderConfig->last_ivas_total_brate = ivas_total_brate; - - IF (NE_16(ivas_format, MONO_FORMAT)) - { - /* In IVAS, ensure that minimum coded bandwidth is WB */ - hEncoderConfig->max_bwidth = extract_l(L_max(hEncoderConfig->max_bwidth, WB)); - } - st_ivas->ism_mode = ISM_MODE_NONE; - st_ivas->mc_mode = MC_MODE_NONE; - - st_ivas->nchan_transport = -1; - - /*-----------------------------------------------------------------* - * Allocate floating-point input audio buffers - *-----------------------------------------------------------------*/ - - nchan_inp_buff = hEncoderConfig->nchan_inp; - IF (EQ_16(ivas_format, MONO_FORMAT)) - { - nchan_inp_buff = 0; - } - ELSE IF (EQ_16(ivas_format, MASA_ISM_FORMAT)) - { - IF (EQ_16(sub(hEncoderConfig->nchan_inp, hEncoderConfig->nchan_ism), 1)) /* mono is duplicated in monoMASA */ - { - nchan_inp_buff++; - } - - nchan_inp_buff++; /* for *data_separated_object */ - } - - FOR (n = 0; n < nchan_inp_buff; n++) - { - /* note: these are intra-frame heap memories */ - IF ((st_ivas->p_data_f[n] = (float *)malloc((input_Fs / FRAMES_PER_SEC) * sizeof(float))) == NULL) - { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for floating-point input audio buffer!\n")); - } - } - FOR (; n < MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS; n++) - { - st_ivas->p_data_f[n] = NULL; - } - - /*-----------------------------------------------------------------* - * Allocate and initialize buffer of indices - *-----------------------------------------------------------------*/ - - /* set the maximum allowed number of indices in the list */ - st_ivas->ivas_max_num_indices = get_ivas_max_num_indices_fx(ivas_format, ivas_total_brate); - - /* allocate buffer of indices */ - IF ((st_ivas->ind_list = (INDICE_HANDLE)malloc(st_ivas->ivas_max_num_indices * sizeof(Indice))) == NULL) - { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for buffer of indices!\n")); - } - - /* reset the list of indices */ - FOR (i = 0; i < st_ivas->ivas_max_num_indices; i++) - { - st_ivas->ind_list[i].nb_bits = -1; - } - - /* set the maximum allowed number of metadata indices in the list */ - st_ivas->ivas_max_num_indices_metadata = get_ivas_max_num_indices_metadata_fx(st_ivas->hEncoderConfig->ivas_format, st_ivas->hEncoderConfig->ivas_total_brate); - - /* allocate buffer of metadata indices */ - IF (st_ivas->ivas_max_num_indices_metadata > 0) - { - IF ((st_ivas->ind_list_metadata = (INDICE_HANDLE)malloc(st_ivas->ivas_max_num_indices_metadata * sizeof(Indice))) == NULL) - { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for buffer of metadata indices!\n")); - } - - /* reset the list of metadata indices */ - FOR (i = 0; i < st_ivas->ivas_max_num_indices_metadata; i++) - { - st_ivas->ind_list_metadata[i].nb_bits = -1; - } - } - ELSE - { - st_ivas->ind_list_metadata = NULL; - } - - /*-----------------------------------------------------------------* - * Allocate and initialize SCE/CPE and other handles - *-----------------------------------------------------------------*/ + Word16 i, n; + Word16 nchan_inp_buff; + Word16 sce_id, cpe_id; + IVAS_FORMAT ivas_format; + Word32 input_Fs, ivas_total_brate; + Word32 element_brate_tmp[MAX_NUM_OBJECTS]; + ENCODER_CONFIG_HANDLE hEncoderConfig; + ivas_error error; - IF (EQ_16(ivas_format, MONO_FORMAT)) - { - st_ivas->nSCE = 1; /* in mono, there is always only one SCE */ - st_ivas->nCPE = 0; - st_ivas->nchan_transport = 1; - sce_id = 0; -#ifndef EVS_FLOAT_ENC - if ( ( error = create_evs_sce_enc( st_ivas, sce_id, ivas_total_brate ) ) != IVAS_ERR_OK ) - { - return error; - } -#else - IF( ( error = create_sce_enc_fx( st_ivas, sce_id, ivas_total_brate ) ) != IVAS_ERR_OK ) - { - return error; - } -#endif + error = IVAS_ERR_OK; - /* prepare stereo downmix for EVS */ - IF (hEncoderConfig->stereo_dmx_evs == 1) - { - IF ((error = stereo_dmx_evs_init_encoder(&(st_ivas->hStereoDmxEVS), input_Fs)) != IVAS_ERR_OK) - { - return error; - } - } - } - ELSE IF (ivas_format == STEREO_FORMAT) - { - st_ivas->nSCE = 0; - st_ivas->nCPE = 1; /* in stereo, there is always only one CPE */ - st_ivas->nchan_transport = CPE_CHANNELS; - cpe_id = 0; + hEncoderConfig = st_ivas->hEncoderConfig; + ivas_format = hEncoderConfig->ivas_format; + input_Fs = hEncoderConfig->input_Fs; + ivas_total_brate = hEncoderConfig->ivas_total_brate; - IF ((error = create_cpe_enc(st_ivas, cpe_id, ivas_total_brate)) != IVAS_ERR_OK) - { - return error; - } - } - ELSE IF (ivas_format == ISM_FORMAT) - { - st_ivas->ism_mode = ivas_ism_mode_select(hEncoderConfig->nchan_inp, ivas_total_brate); + hEncoderConfig->last_ivas_total_brate = ivas_total_brate; - IF ((error = ivas_ism_metadata_enc_create(st_ivas, hEncoderConfig->nchan_inp, element_brate_tmp)) != IVAS_ERR_OK) + IF( NE_16( ivas_format, MONO_FORMAT ) ) { - return error; + /* In IVAS, ensure that minimum coded bandwidth is WB */ + hEncoderConfig->max_bwidth = extract_l( L_max( hEncoderConfig->max_bwidth, WB ) ); } + st_ivas->ism_mode = ISM_MODE_NONE; + st_ivas->mc_mode = MC_MODE_NONE; - FOR (sce_id = 0; sce_id < st_ivas->nSCE; sce_id++) + st_ivas->nchan_transport = -1; + + /*-----------------------------------------------------------------* + * Allocate floating-point input audio buffers + *-----------------------------------------------------------------*/ + + nchan_inp_buff = hEncoderConfig->nchan_inp; + IF( EQ_16( ivas_format, MONO_FORMAT ) ) { - IF ((error = create_sce_enc_fx(st_ivas, sce_id, element_brate_tmp[sce_id])) != IVAS_ERR_OK) - { - return error; - } + nchan_inp_buff = 0; } - - IF (st_ivas->ism_mode == ISM_MODE_PARAM) + ELSE IF( EQ_16( ivas_format, MASA_ISM_FORMAT ) ) { - IF ((error = ivas_param_ism_enc_open(st_ivas)) != IVAS_ERR_OK) - { - return error; - } + IF( EQ_16( sub( hEncoderConfig->nchan_inp, hEncoderConfig->nchan_ism ), 1 ) ) /* mono is duplicated in monoMASA */ + { + nchan_inp_buff++; + } + + nchan_inp_buff++; /* for *data_separated_object */ } - IF (st_ivas->hEncoderConfig->Opt_DTX_ON) + FOR( n = 0; n < nchan_inp_buff; n++ ) { - IF ((error = ivas_ism_dtx_open(st_ivas)) != IVAS_ERR_OK) - { - return error; - } + /* note: these are intra-frame heap memories */ + IF( ( st_ivas->p_data_f[n] = (float *) malloc( ( input_Fs / FRAMES_PER_SEC ) * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for floating-point input audio buffer!\n" ) ); + } } - } - ELSE IF (ivas_format == SBA_FORMAT || ivas_format == MASA_FORMAT) - { - IF ((error = ivas_qmetadata_open(&(st_ivas->hQMetaData))) != IVAS_ERR_OK) + FOR( ; n < MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS; n++ ) { - return error; + st_ivas->p_data_f[n] = NULL; } - IF (ivas_format == SBA_FORMAT) - { - st_ivas->sba_analysis_order = ivas_sba_get_analysis_order(ivas_total_brate, st_ivas->hEncoderConfig->sba_order); + /*-----------------------------------------------------------------* + * Allocate and initialize buffer of indices + *-----------------------------------------------------------------*/ - IF ((error = ivas_spar_enc_open_fx(st_ivas, 0)) != IVAS_ERR_OK) - { - return error; - } + /* set the maximum allowed number of indices in the list */ + st_ivas->ivas_max_num_indices = get_ivas_max_num_indices_fx( ivas_format, ivas_total_brate ); - IF ((error = ivas_dirac_enc_open(st_ivas)) != IVAS_ERR_OK) - { - return error; - } - } - ELSE + /* allocate buffer of indices */ + IF( ( st_ivas->ind_list = (INDICE_HANDLE) malloc( st_ivas->ivas_max_num_indices * sizeof( Indice ) ) ) == NULL ) { - st_ivas->nchan_transport = hEncoderConfig->nchan_inp; - - IF ((error = ivas_masa_enc_open(st_ivas)) != IVAS_ERR_OK) - { - return error; - } + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for buffer of indices!\n" ) ); } - FOR (sce_id = 0; sce_id < st_ivas->nSCE; sce_id++) + /* reset the list of indices */ + FOR( i = 0; i < st_ivas->ivas_max_num_indices; i++ ) { - IF ((error = create_sce_enc_fx(st_ivas, sce_id, ivas_total_brate / st_ivas->nchan_transport)) != IVAS_ERR_OK) - { - return error; - } - - IF (EQ_16(ivas_format, SBA_FORMAT) && st_ivas->hEncoderConfig->Opt_DTX_ON) - { - st_ivas->hSCE[sce_id]->hCoreCoder[0]->dtx_sce_sba = 1; - } + st_ivas->ind_list[i].nb_bits = -1; } - FOR (cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++) + /* set the maximum allowed number of metadata indices in the list */ + st_ivas->ivas_max_num_indices_metadata = get_ivas_max_num_indices_metadata_fx( st_ivas->hEncoderConfig->ivas_format, st_ivas->hEncoderConfig->ivas_total_brate ); + + /* allocate buffer of metadata indices */ + IF( st_ivas->ivas_max_num_indices_metadata > 0 ) { - IF ((error = create_cpe_enc_fx(st_ivas, cpe_id, (ivas_total_brate / st_ivas->nchan_transport) * CPE_CHANNELS)) != IVAS_ERR_OK) - { - return error; - } + IF( ( st_ivas->ind_list_metadata = (INDICE_HANDLE) malloc( st_ivas->ivas_max_num_indices_metadata * sizeof( Indice ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for buffer of metadata indices!\n" ) ); + } - FOR (n = 0; n < CPE_CHANNELS; n++) - { - IF (hEncoderConfig->Opt_DTX_ON) + /* reset the list of metadata indices */ + FOR( i = 0; i < st_ivas->ivas_max_num_indices_metadata; i++ ) { - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cng_sba_flag = 1; + st_ivas->ind_list_metadata[i].nb_bits = -1; } - } } - - if (st_ivas->nCPE > 1) + ELSE { - if ((error = create_mct_enc(st_ivas)) != IVAS_ERR_OK) - { - return error; - } + st_ivas->ind_list_metadata = NULL; } - } - else if (ivas_format == MASA_ISM_FORMAT) - { - int32_t ism_total_brate; - int16_t k; - st_ivas->ism_mode = ivas_omasa_ism_mode_select(ivas_total_brate, hEncoderConfig->nchan_ism); - st_ivas->nchan_transport = 2; + /*-----------------------------------------------------------------* + * Allocate and initialize SCE/CPE and other handles + *-----------------------------------------------------------------*/ - if ((error = ivas_ism_metadata_enc_create(st_ivas, hEncoderConfig->nchan_ism, element_brate_tmp)) != IVAS_ERR_OK) + IF( EQ_16( ivas_format, MONO_FORMAT ) ) { - return error; - } + st_ivas->nSCE = 1; /* in mono, there is always only one SCE */ + st_ivas->nCPE = 0; + st_ivas->nchan_transport = 1; + sce_id = 0; +#ifndef EVS_FLOAT_ENC + if ( ( error = create_evs_sce_enc( st_ivas, sce_id, ivas_total_brate ) ) != IVAS_ERR_OK ) + { + return error; + } +#else + IF( ( error = create_sce_enc_fx( st_ivas, sce_id, ivas_total_brate ) ) != IVAS_ERR_OK ) + { + return error; + } +#endif - k = 0; - while (k < SIZE_IVAS_BRATE_TBL && ivas_total_brate != ivas_brate_tbl[k]) - { - k++; + /* prepare stereo downmix for EVS */ + IF( hEncoderConfig->stereo_dmx_evs == 1 ) + { + IF( ( error = stereo_dmx_evs_init_encoder( &( st_ivas->hStereoDmxEVS ), input_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } + } } - - ism_total_brate = 0; - for (sce_id = 0; sce_id < st_ivas->nSCE; sce_id++) + ELSE IF( ivas_format == STEREO_FORMAT ) { - ism_total_brate += sep_object_brate[k - 2][st_ivas->nSCE - 1]; - if ((error = create_sce_enc_fx(st_ivas, sce_id, sep_object_brate[k - 2][st_ivas->nSCE - 1])) != IVAS_ERR_OK) - { - return error; - } - } + st_ivas->nSCE = 0; + st_ivas->nCPE = 1; /* in stereo, there is always only one CPE */ + st_ivas->nchan_transport = CPE_CHANNELS; + cpe_id = 0; - if ((error = ivas_qmetadata_open(&(st_ivas->hQMetaData))) != IVAS_ERR_OK) - { - return error; + IF( ( error = create_cpe_enc( st_ivas, cpe_id, ivas_total_brate ) ) != IVAS_ERR_OK ) + { + return error; + } } - if ((error = ivas_masa_enc_open(st_ivas)) != IVAS_ERR_OK) + ELSE IF( ivas_format == ISM_FORMAT ) { - return error; - } + st_ivas->ism_mode = ivas_ism_mode_select( hEncoderConfig->nchan_inp, ivas_total_brate ); - if (st_ivas->ism_mode != ISM_MASA_MODE_DISC) - { - if ((error = ivas_omasa_enc_open(st_ivas)) != IVAS_ERR_OK) - { - return error; - } - } + IF( ( error = ivas_ism_metadata_enc_create( st_ivas, hEncoderConfig->nchan_inp, element_brate_tmp ) ) != IVAS_ERR_OK ) + { + return error; + } - if (ivas_total_brate - ism_total_brate >= MIN_BRATE_MDCT_STEREO) - { - st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; - } - else - { - st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_DFT; - } + FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + { + IF( ( error = create_sce_enc_fx( st_ivas, sce_id, element_brate_tmp[sce_id] ) ) != IVAS_ERR_OK ) + { + return error; + } + } - if ((error = create_cpe_enc(st_ivas, 0, ivas_total_brate - ism_total_brate)) != IVAS_ERR_OK) - { - return error; - } - } - else if (ivas_format == SBA_ISM_FORMAT) - { - st_ivas->ism_mode = ISM_MODE_NONE; + IF( st_ivas->ism_mode == ISM_MODE_PARAM ) + { + IF( ( error = ivas_param_ism_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } - if (ivas_total_brate >= IVAS_256k) - { - st_ivas->ism_mode = ISM_SBA_MODE_DISC; + IF( st_ivas->hEncoderConfig->Opt_DTX_ON ) + { + IF( ( error = ivas_ism_dtx_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } } - - if ((error = ivas_ism_metadata_enc_create(st_ivas, hEncoderConfig->nchan_ism, element_brate_tmp)) != IVAS_ERR_OK) + ELSE IF( ivas_format == SBA_FORMAT || ivas_format == MASA_FORMAT ) { - return error; - } + IF( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) + { + return error; + } - /* allocate and initialize SBA handles */ - if ((error = ivas_qmetadata_open(&(st_ivas->hQMetaData))) != IVAS_ERR_OK) - { - return error; - } + IF( ivas_format == SBA_FORMAT ) + { + st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->hEncoderConfig->sba_order ); - st_ivas->sba_analysis_order = ivas_sba_get_analysis_order(ivas_total_brate, st_ivas->hEncoderConfig->sba_order); + IF( ( error = ivas_spar_enc_open_fx( st_ivas, 0 ) ) != IVAS_ERR_OK ) + { + return error; + } - if ((error = ivas_spar_enc_open_fx(st_ivas, 0)) != IVAS_ERR_OK) - { - return error; - } + IF( ( error = ivas_dirac_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + ELSE + { + st_ivas->nchan_transport = hEncoderConfig->nchan_inp; - if ((error = ivas_dirac_enc_open(st_ivas)) != IVAS_ERR_OK) - { - return error; - } + IF( ( error = ivas_masa_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } - if (st_ivas->ism_mode == ISM_MODE_NONE) - { - /* allocate and initialize SBA core-coders */ - if (st_ivas->nchan_transport == 1) - { - if ((error = create_sce_enc_fx(st_ivas, 0, ivas_total_brate)) != IVAS_ERR_OK) + FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { - return error; + IF( ( error = create_sce_enc_fx( st_ivas, sce_id, ivas_total_brate / st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) + { + return error; + } + + IF( EQ_16( ivas_format, SBA_FORMAT ) && st_ivas->hEncoderConfig->Opt_DTX_ON ) + { + st_ivas->hSCE[sce_id]->hCoreCoder[0]->dtx_sce_sba = 1; + } } - } - for (cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++) - { - if ((error = create_cpe_enc(st_ivas, cpe_id, (ivas_total_brate / st_ivas->nchan_transport) * CPE_CHANNELS)) != IVAS_ERR_OK) + FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - return error; + IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) + { + return error; + } + + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + IF( hEncoderConfig->Opt_DTX_ON ) + { + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cng_sba_flag = 1; + } + } } - } - if (st_ivas->nCPE > 1) - { - if ((error = create_mct_enc(st_ivas)) != IVAS_ERR_OK) + if ( st_ivas->nCPE > 1 ) { - return error; + if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } } - } } - else + else if ( ivas_format == MASA_ISM_FORMAT ) { - /* allocate and initialize MCT core coder */ - st_ivas->nCPE += (st_ivas->hEncoderConfig->nchan_ism + 1) >> 1; + int32_t ism_total_brate; + int16_t k; + + st_ivas->ism_mode = ivas_omasa_ism_mode_select( ivas_total_brate, hEncoderConfig->nchan_ism ); + st_ivas->nchan_transport = 2; - for (cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++) - { - if ((error = create_cpe_enc(st_ivas, cpe_id, (ivas_total_brate / st_ivas->nchan_transport) * CPE_CHANNELS)) != IVAS_ERR_OK) + if ( ( error = ivas_ism_metadata_enc_create( st_ivas, hEncoderConfig->nchan_ism, element_brate_tmp ) ) != IVAS_ERR_OK ) { - return error; + return error; } - } - if ((error = create_mct_enc(st_ivas)) != IVAS_ERR_OK) - { - return error; - } - } + k = 0; + while ( k < SIZE_IVAS_BRATE_TBL && ivas_total_brate != ivas_brate_tbl[k] ) + { + k++; + } - if ((error = ivas_osba_enc_open(st_ivas)) != IVAS_ERR_OK) - { - return error; - } - } - else if (ivas_format == MC_FORMAT) - { - st_ivas->mc_mode = ivas_mc_mode_select(hEncoderConfig->mc_input_setup, ivas_total_brate); + ism_total_brate = 0; + for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + { + ism_total_brate += sep_object_brate[k - 2][st_ivas->nSCE - 1]; + if ( ( error = create_sce_enc_fx( st_ivas, sce_id, sep_object_brate[k - 2][st_ivas->nSCE - 1] ) ) != IVAS_ERR_OK ) + { + return error; + } + } - if ((error = ivas_create_lfe_lpf_enc(&st_ivas->hLfeLpf, hEncoderConfig->input_Fs)) != IVAS_ERR_OK) - { - return error; - } + if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) + { + return error; + } + if ( ( error = ivas_masa_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } - if (st_ivas->mc_mode == MC_MODE_MCT) + if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) + { + if ( ( error = ivas_omasa_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + if ( ivas_total_brate - ism_total_brate >= MIN_BRATE_MDCT_STEREO ) + { + st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + } + else + { + st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_DFT; + } + + if ( ( error = create_cpe_enc( st_ivas, 0, ivas_total_brate - ism_total_brate ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( ivas_format == SBA_ISM_FORMAT ) { - st_ivas->nSCE = 0; - st_ivas->nCPE = hEncoderConfig->nchan_inp / CPE_CHANNELS; + st_ivas->ism_mode = ISM_MODE_NONE; - for (cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++) - { - if ((error = create_cpe_enc(st_ivas, cpe_id, (ivas_total_brate / (hEncoderConfig->nchan_inp - 1) * CPE_CHANNELS))) != IVAS_ERR_OK) + if ( ivas_total_brate >= IVAS_256k ) { - return error; + st_ivas->ism_mode = ISM_SBA_MODE_DISC; } - } - if ((error = create_mct_enc(st_ivas)) != IVAS_ERR_OK) - { - return error; - } + if ( ( error = ivas_ism_metadata_enc_create( st_ivas, hEncoderConfig->nchan_ism, element_brate_tmp ) ) != IVAS_ERR_OK ) + { + return error; + } - if ((error = ivas_create_lfe_enc(&st_ivas->hLFE, input_Fs)) != IVAS_ERR_OK) - { - return error; - } + /* allocate and initialize SBA handles */ + if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) + { + return error; + } - st_ivas->nchan_transport = ivas_mc_ls_setup_get_num_channels(st_ivas->hEncoderConfig->mc_input_setup); - } - else if (st_ivas->mc_mode == MC_MODE_PARAMUPMIX) - { - st_ivas->nSCE = 0; - st_ivas->nCPE = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS / 2; - st_ivas->nchan_transport = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS; + st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->hEncoderConfig->sba_order ); - if ((error = ivas_mc_paramupmix_enc_open(st_ivas)) != IVAS_ERR_OK) - { - return error; - } + if ( ( error = ivas_spar_enc_open_fx( st_ivas, 0 ) ) != IVAS_ERR_OK ) + { + return error; + } - for (cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++) - { - if ((error = create_cpe_enc(st_ivas, cpe_id, (ivas_total_brate / st_ivas->nCPE))) != IVAS_ERR_OK) + if ( ( error = ivas_dirac_enc_open( st_ivas ) ) != IVAS_ERR_OK ) { - return error; + return error; } - } - if ((error = create_mct_enc(st_ivas)) != IVAS_ERR_OK) - { - return error; - } + if ( st_ivas->ism_mode == ISM_MODE_NONE ) + { + /* allocate and initialize SBA core-coders */ + if ( st_ivas->nchan_transport == 1 ) + { + if ( ( error = create_sce_enc_fx( st_ivas, 0, ivas_total_brate ) ) != IVAS_ERR_OK ) + { + return error; + } + } - if ((error = ivas_create_lfe_enc(&st_ivas->hLFE, input_Fs)) != IVAS_ERR_OK) - { - return error; - } - } - else if (st_ivas->mc_mode == MC_MODE_PARAMMC) - { - if ((error = ivas_param_mc_enc_open(st_ivas)) != IVAS_ERR_OK) - { - return error; - } + for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + if ( ( error = create_cpe_enc( st_ivas, cpe_id, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) + { + return error; + } + } - for (cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++) - { - if ((error = create_cpe_enc(st_ivas, cpe_id, ivas_total_brate / (st_ivas->nCPE + st_ivas->nSCE))) != IVAS_ERR_OK) + if ( st_ivas->nCPE > 1 ) + { + if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + else { - return error; + /* allocate and initialize MCT core coder */ + st_ivas->nCPE += ( st_ivas->hEncoderConfig->nchan_ism + 1 ) >> 1; + + for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + if ( ( error = create_cpe_enc( st_ivas, cpe_id, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } } - } - if (st_ivas->nCPE > 1) - { - if ((error = create_mct_enc(st_ivas)) != IVAS_ERR_OK) + if ( ( error = ivas_osba_enc_open( st_ivas ) ) != IVAS_ERR_OK ) { - return error; + return error; } - } } - else if (st_ivas->mc_mode == MC_MODE_MCMASA) + else if ( ivas_format == MC_FORMAT ) { - int32_t brate_sce, brate_cpe; + st_ivas->mc_mode = ivas_mc_mode_select( hEncoderConfig->mc_input_setup, ivas_total_brate ); - ivas_mcmasa_setNumTransportChannels(&(st_ivas->nchan_transport), &(hEncoderConfig->element_mode_init), ivas_total_brate); + if ( ( error = ivas_create_lfe_lpf_enc( &st_ivas->hLfeLpf, hEncoderConfig->input_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } - if ((error = ivas_qmetadata_open(&(st_ivas->hQMetaData))) != IVAS_ERR_OK) - { - return error; - } + if ( st_ivas->mc_mode == MC_MODE_MCT ) + { + st_ivas->nSCE = 0; + st_ivas->nCPE = hEncoderConfig->nchan_inp / CPE_CHANNELS; - if ((error = ivas_masa_enc_open(st_ivas)) != IVAS_ERR_OK) - { - return error; - } + for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + if ( ( error = create_cpe_enc( st_ivas, cpe_id, ( ivas_total_brate / ( hEncoderConfig->nchan_inp - 1 ) * CPE_CHANNELS ) ) ) != IVAS_ERR_OK ) + { + return error; + } + } - if ((error = ivas_mcmasa_enc_open(st_ivas)) != IVAS_ERR_OK) - { - return error; - } + if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } - ivas_mcmasa_split_brate(st_ivas->hMcMasa->separateChannelEnabled, ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &brate_sce, &brate_cpe); + if ( ( error = ivas_create_lfe_enc( &st_ivas->hLFE, input_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } - for (sce_id = 0; sce_id < st_ivas->nSCE; sce_id++) - { - if ((error = create_sce_enc_fx(st_ivas, sce_id, brate_sce)) != IVAS_ERR_OK) + st_ivas->nchan_transport = ivas_mc_ls_setup_get_num_channels( st_ivas->hEncoderConfig->mc_input_setup ); + } + else if ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) { - return error; + st_ivas->nSCE = 0; + st_ivas->nCPE = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS / 2; + st_ivas->nchan_transport = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS; + + if ( ( error = ivas_mc_paramupmix_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + + for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + if ( ( error = create_cpe_enc( st_ivas, cpe_id, ( ivas_total_brate / st_ivas->nCPE ) ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( ( error = ivas_create_lfe_enc( &st_ivas->hLFE, input_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } } - } + else if ( st_ivas->mc_mode == MC_MODE_PARAMMC ) + { + if ( ( error = ivas_param_mc_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } - for (cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++) - { - hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + if ( ( error = create_cpe_enc( st_ivas, cpe_id, ivas_total_brate / ( st_ivas->nCPE + st_ivas->nSCE ) ) ) != IVAS_ERR_OK ) + { + return error; + } + } - if ((error = create_cpe_enc(st_ivas, cpe_id, brate_cpe)) != IVAS_ERR_OK) + if ( st_ivas->nCPE > 1 ) + { + if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + else if ( st_ivas->mc_mode == MC_MODE_MCMASA ) { - return error; + int32_t brate_sce, brate_cpe; + + ivas_mcmasa_setNumTransportChannels( &( st_ivas->nchan_transport ), &( hEncoderConfig->element_mode_init ), ivas_total_brate ); + + if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( ( error = ivas_masa_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( ( error = ivas_mcmasa_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + + ivas_mcmasa_split_brate( st_ivas->hMcMasa->separateChannelEnabled, ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &brate_sce, &brate_cpe ); + + for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + { + if ( ( error = create_sce_enc_fx( st_ivas, sce_id, brate_sce ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + + if ( ( error = create_cpe_enc( st_ivas, cpe_id, brate_cpe ) ) != IVAS_ERR_OK ) + { + return error; + } + } } - } } - } - /*-----------------------------------------------------------------* - * Allocate and initialize HP20 filter memories - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * Allocate and initialize HP20 filter memories + *-----------------------------------------------------------------*/ - /* set number of input channels used for analysis/coding */ - n = getNumChanAnalysis(st_ivas); + /* set number of input channels used for analysis/coding */ + n = getNumChanAnalysis( st_ivas ); - if (n > 0) - { - if ((st_ivas->mem_hp20_in = (float **)malloc(n * sizeof(float *))) == NULL) + if ( n > 0 ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n")); + if ( ( st_ivas->mem_hp20_in = (float **) malloc( n * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + } } - } - else - { - st_ivas->mem_hp20_in = NULL; - } - - for (i = 0; i < n; i++) - { - if ((st_ivas->mem_hp20_in[i] = (float *)malloc(L_HP20_MEM * sizeof(float))) == NULL) + else { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n")); + st_ivas->mem_hp20_in = NULL; } - set_f(st_ivas->mem_hp20_in[i], 0.0f, L_HP20_MEM); - } + for ( i = 0; i < n; i++ ) + { + if ( ( st_ivas->mem_hp20_in[i] = (float *) malloc( L_HP20_MEM * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + } + + set_f( st_ivas->mem_hp20_in[i], 0.0f, L_HP20_MEM ); + } - return error; + return error; } #endif /*------------------------------------------------------------------------- @@ -1518,16 +1518,16 @@ void destroy_core_enc( destroy_cldfb_encoder( hCoreCoder ); - IF ( hCoreCoder->hSignalBuf != NULL ) + IF( hCoreCoder->hSignalBuf != NULL ) { free( hCoreCoder->hSignalBuf ); hCoreCoder->hSignalBuf = NULL; } - IF ( hCoreCoder->hBstr != NULL ) + IF( hCoreCoder->hBstr != NULL ) { /* reset buffer of indices */ - FOR ( i = 0; i < hCoreCoder->hBstr->nb_ind_tot; i++ ) + FOR( i = 0; i < hCoreCoder->hBstr->nb_ind_tot; i++ ) { hCoreCoder->hBstr->ind_list[i].nb_bits = -1; } @@ -1535,121 +1535,121 @@ void destroy_core_enc( hCoreCoder->hBstr = NULL; } - IF ( hCoreCoder->hLPDmem != NULL ) + IF( hCoreCoder->hLPDmem != NULL ) { free( hCoreCoder->hLPDmem ); hCoreCoder->hLPDmem = NULL; } - IF ( hCoreCoder->hTranDet != NULL ) + IF( hCoreCoder->hTranDet != NULL ) { free( hCoreCoder->hTranDet ); hCoreCoder->hTranDet = NULL; } - IF ( hCoreCoder->hNoiseEst != NULL ) + IF( hCoreCoder->hNoiseEst != NULL ) { free( hCoreCoder->hNoiseEst ); hCoreCoder->hNoiseEst = NULL; } - IF ( hCoreCoder->hVAD != NULL ) + IF( hCoreCoder->hVAD != NULL ) { free( hCoreCoder->hVAD ); hCoreCoder->hVAD = NULL; } - IF ( hCoreCoder->hVAD_CLDFB != NULL ) + IF( hCoreCoder->hVAD_CLDFB != NULL ) { free( hCoreCoder->hVAD_CLDFB ); hCoreCoder->hVAD_CLDFB = NULL; } - IF ( hCoreCoder->hTdCngEnc != NULL ) + IF( hCoreCoder->hTdCngEnc != NULL ) { free( hCoreCoder->hTdCngEnc ); hCoreCoder->hTdCngEnc = NULL; } - IF ( hCoreCoder->hDtxEnc != NULL ) + IF( hCoreCoder->hDtxEnc != NULL ) { free( hCoreCoder->hDtxEnc ); hCoreCoder->hDtxEnc = NULL; } - IF ( hCoreCoder->hSpMusClas != NULL ) + IF( hCoreCoder->hSpMusClas != NULL ) { free( hCoreCoder->hSpMusClas ); hCoreCoder->hSpMusClas = NULL; } - IF ( hCoreCoder->hGSCEnc != NULL ) + IF( hCoreCoder->hGSCEnc != NULL ) { free( hCoreCoder->hGSCEnc ); hCoreCoder->hGSCEnc = NULL; } - IF ( hCoreCoder->hSC_VBR != NULL ) + IF( hCoreCoder->hSC_VBR != NULL ) { free( hCoreCoder->hSC_VBR ); hCoreCoder->hSC_VBR = NULL; } - IF ( hCoreCoder->hAmrwb_IO != NULL ) + IF( hCoreCoder->hAmrwb_IO != NULL ) { free( hCoreCoder->hAmrwb_IO ); hCoreCoder->hAmrwb_IO = NULL; } - IF ( hCoreCoder->hBWE_TD != NULL ) + IF( hCoreCoder->hBWE_TD != NULL ) { free( hCoreCoder->hBWE_TD ); hCoreCoder->hBWE_TD = NULL; } - IF ( hCoreCoder->hBWE_FD != NULL ) + IF( hCoreCoder->hBWE_FD != NULL ) { free( hCoreCoder->hBWE_FD ); hCoreCoder->hBWE_FD = NULL; } - IF ( hCoreCoder->hRF != NULL ) + IF( hCoreCoder->hRF != NULL ) { free( hCoreCoder->hRF ); hCoreCoder->hRF = NULL; } - IF ( hCoreCoder->hTECEnc != NULL ) + IF( hCoreCoder->hTECEnc != NULL ) { free( hCoreCoder->hTECEnc ); hCoreCoder->hTECEnc = NULL; } - IF ( hCoreCoder->hTcxEnc != NULL ) + IF( hCoreCoder->hTcxEnc != NULL ) { free( hCoreCoder->hTcxEnc ); hCoreCoder->hTcxEnc = NULL; } - IF ( hCoreCoder->hTcxCfg != NULL ) + IF( hCoreCoder->hTcxCfg != NULL ) { free( hCoreCoder->hTcxCfg ); hCoreCoder->hTcxCfg = NULL; } - IF ( hCoreCoder->hIGFEnc != NULL ) + IF( hCoreCoder->hIGFEnc != NULL ) { free( hCoreCoder->hIGFEnc ); hCoreCoder->hIGFEnc = NULL; } - IF ( hCoreCoder->hPlcExt != NULL ) + IF( hCoreCoder->hPlcExt != NULL ) { free( hCoreCoder->hPlcExt ); hCoreCoder->hPlcExt = NULL; } - IF ( hCoreCoder->hHQ_core != NULL ) + IF( hCoreCoder->hHQ_core != NULL ) { free( hCoreCoder->hHQ_core ); hCoreCoder->hHQ_core = NULL; @@ -1806,7 +1806,7 @@ ivas_error ivas_initialize_MD_bstr_enc( { BSTR_ENC_HANDLE hMetaData; - IF ( ( hMetaData = (BSTR_ENC_HANDLE) malloc( sizeof( BSTR_ENC_DATA ) ) ) == NULL ) + IF( ( hMetaData = (BSTR_ENC_HANDLE) malloc( sizeof( BSTR_ENC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MetaData structure\n" ) ); } @@ -1835,7 +1835,7 @@ void ivas_destroy_MD_bstr_enc( BSTR_ENC_HANDLE *hMetaData /* i/o: encoder MD bitstream handle */ ) { - IF ( hMetaData == NULL || *hMetaData == NULL ) + IF( hMetaData == NULL || *hMetaData == NULL ) { return; } diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index 9d7ee9dbd..296323cf9 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -204,7 +204,6 @@ ivas_error ivas_ism_enc( /* estimate coherence between objects */ ivas_ism_coh_estim_dtx_enc( st_ivas->hISMDTX, st_ivas->hSCE, st_ivas->nchan_transport, input_frame ); } - } /*------------------------------------------------------------------* diff --git a/lib_enc/ivas_lfe_enc.c b/lib_enc/ivas_lfe_enc.c index d248f6266..26829a6d7 100644 --- a/lib_enc/ivas_lfe_enc.c +++ b/lib_enc/ivas_lfe_enc.c @@ -46,7 +46,6 @@ #endif // IVAS_FLOAT_FIXED - /*-----------------------------------------------------------------------------------------* * Function ivas_lfe_arith_coding() * @@ -819,13 +818,13 @@ ivas_error ivas_create_lfe_enc( set_zero( hLFE->old_wtda_audio, NS2SA( input_Fs, IVAS_LFE_FADE_NS ) ); #ifdef IVAS_FLOAT_FIXED - if ((hLFE->old_wtda_audio_fx = (Word32 *)malloc(sizeof(hLFE->old_wtda_audio_fx[0]) * NS2SA(input_Fs, IVAS_LFE_FADE_NS))) == NULL) - { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LFE memory\n")); - } + if ( ( hLFE->old_wtda_audio_fx = (Word32 *) malloc( sizeof( hLFE->old_wtda_audio_fx[0] ) * NS2SA( input_Fs, IVAS_LFE_FADE_NS ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LFE memory\n" ) ); + } - set32_fx(hLFE->old_wtda_audio_fx, 0, NS2SA(input_Fs, IVAS_LFE_FADE_NS)); - hLFE->q_old_wtda_audio = 31; + set32_fx( hLFE->old_wtda_audio_fx, 0, NS2SA( input_Fs, IVAS_LFE_FADE_NS ) ); + hLFE->q_old_wtda_audio = 31; #endif // IVAS_FLOAT_FIXED @@ -891,11 +890,11 @@ void ivas_lfe_enc_close( } #ifdef IVAS_FLOAT_FIXED - if ((*hLFE)->old_wtda_audio_fx != NULL) - { - free((*hLFE)->old_wtda_audio_fx); - (*hLFE)->old_wtda_audio_fx = NULL; - } + if ( ( *hLFE )->old_wtda_audio_fx != NULL ) + { + free( ( *hLFE )->old_wtda_audio_fx ); + ( *hLFE )->old_wtda_audio_fx = NULL; + } #endif // IVAS_FLOAT_FIXED if ( ( *hLFE )->pWindow_state ) diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index fd1c8f33b..2ff2e226d 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -3153,7 +3153,6 @@ static int16_t encode_ratio_ism_subframe( nbits = nbits0 + 1; } } - } else { @@ -3321,7 +3320,6 @@ static int16_t encode_ratio_ism_subframe( } } } - } } diff --git a/lib_enc/ivas_mct_core_enc.c b/lib_enc/ivas_mct_core_enc.c index 36a5f3df5..e09f42e78 100644 --- a/lib_enc/ivas_mct_core_enc.c +++ b/lib_enc/ivas_mct_core_enc.c @@ -532,7 +532,6 @@ void ivas_mct_core_enc( continue; } st->total_brate = ( st->bits_frame_channel + st->side_bits_frame_channel ) * FRAMES_PER_SEC; - } } diff --git a/lib_enc/ivas_mct_enc_mct.c b/lib_enc/ivas_mct_enc_mct.c index 86ddc2641..554b16008 100644 --- a/lib_enc/ivas_mct_enc_mct.c +++ b/lib_enc/ivas_mct_enc_mct.c @@ -199,7 +199,6 @@ static void getCorrelationMatrix( { xCorrMatrix[ch1][ch2] = 0.f; } - } } diff --git a/lib_enc/ivas_mdct_core_enc.c b/lib_enc/ivas_mdct_core_enc.c index 793da9f0d..f2e712596 100644 --- a/lib_enc/ivas_mdct_core_enc.c +++ b/lib_enc/ivas_mdct_core_enc.c @@ -635,7 +635,7 @@ void ivas_mdct_core_whitening_enc( if ( mct_on ) { sts[0]->hTcxEnc->tfm_mem = sts[1]->hTcxEnc->tfm_mem = sqrtf( 0.5f * ( sts[0]->hTcxEnc->tfm_mem * sts[0]->hTcxEnc->tfm_mem + sts[1]->hTcxEnc->tfm_mem * sts[1]->hTcxEnc->tfm_mem ) ); /* RMS */ - sts[0]->hTcxEnc->tcxltp_norm_corr_past_flt = sts[1]->hTcxEnc->tcxltp_norm_corr_past_flt = 0.5f * ( sts[0]->hTcxEnc->tcxltp_norm_corr_past_flt + sts[1]->hTcxEnc->tcxltp_norm_corr_past_flt); + sts[0]->hTcxEnc->tcxltp_norm_corr_past_flt = sts[1]->hTcxEnc->tcxltp_norm_corr_past_flt = 0.5f * ( sts[0]->hTcxEnc->tcxltp_norm_corr_past_flt + sts[1]->hTcxEnc->tcxltp_norm_corr_past_flt ); for ( ch = 0; ch < CPE_CHANNELS; ch++ ) { st = sts[ch]; @@ -712,7 +712,7 @@ void ivas_mdct_core_whitening_enc( } nrg = 0.25f * ( hTcxEnc0->tcxltp_norm_corr_past_flt + hTcxEnc0->tcxltp_norm_corr_mem_flt + /* tcxltp_norm_corr_past already contains the */ - hTcxEnc1->tcxltp_norm_corr_past_flt + hTcxEnc1->tcxltp_norm_corr_mem_flt); /* normalized correlation of the current frame */ + hTcxEnc1->tcxltp_norm_corr_past_flt + hTcxEnc1->tcxltp_norm_corr_mem_flt ); /* normalized correlation of the current frame */ L_subframe = max( 512, L_subframe ); nSubframes = ( hTcxEnc0->tcxMode == TCX_20 ) ? 1 : NB_DIV; diff --git a/lib_enc/ivas_qmetadata_enc.c b/lib_enc/ivas_qmetadata_enc.c index 5ca49dbbf..84ff09dd8 100644 --- a/lib_enc/ivas_qmetadata_enc.c +++ b/lib_enc/ivas_qmetadata_enc.c @@ -168,7 +168,6 @@ ivas_error ivas_qmetadata_enc_encode( error = IVAS_ERR_OK; - /* Save initial position in bitstream */ bit_pos_0 = hMetaData->nb_bits_tot; bit_pos_start = bit_pos_0; @@ -445,8 +444,6 @@ ivas_error ivas_qmetadata_enc_encode( } extra_bits = hQMetaData->metadata_max_bits - ( hMetaData->nb_bits_tot - bit_pos_0 ); - - } /* Requantized directions */ @@ -573,7 +570,7 @@ ivas_error ivas_qmetadata_enc_encode_hr_384_512( /* encode 2 direction subbands position */ if ( ndirections == 2 && bits_sph_idx == 11 ) { - write_2dir_info( hMetaData, hQMetaData->twoDirBands, hQMetaData->q_direction[0].cfg.nbands, hQMetaData->numTwoDirBands ); + write_2dir_info( hMetaData, hQMetaData->twoDirBands, hQMetaData->q_direction[0].cfg.nbands, hQMetaData->numTwoDirBands ); d = 0; for ( i = hQMetaData->q_direction[1].cfg.start_band; i < hQMetaData->q_direction[1].cfg.nbands; i++ ) { @@ -2664,7 +2661,6 @@ static int16_t ivas_qmetadata_reorder_azimuth_index( { /* for North and South poles, a single azimuth direction exists */ azimuth_index_reordered = 0; - } return azimuth_index_reordered; @@ -5285,7 +5281,6 @@ static void transform_azimuth_dir2( } - static int16_t divide_GR_orders( const int16_t *q_idx, const int16_t GR1, diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index ea6320eb8..ba36a7a2b 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -365,7 +365,7 @@ ivas_error create_sce_enc( } #ifdef IVAS_FLOAT_FIXED ivas_error create_sce_enc_fx( - Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ const Word16 sce_id, /* i : SCE # identifier */ const Word32 element_brate /* i : element bitrate */ ) @@ -381,7 +381,7 @@ ivas_error create_sce_enc_fx( * Allocate SCE handle *-----------------------------------------------------------------*/ - IF ( ( hSCE = (SCE_ENC_HANDLE) malloc( sizeof( SCE_ENC_DATA ) ) ) == NULL ) + IF( ( hSCE = (SCE_ENC_HANDLE) malloc( sizeof( SCE_ENC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SCE\n" ) ); } @@ -398,9 +398,9 @@ ivas_error create_sce_enc_fx( * Metadata: allocate and initialize *-----------------------------------------------------------------*/ - IF ( NE_16(st_ivas->hEncoderConfig->ivas_format, MONO_FORMAT) && EQ_16(sce_id, sub( st_ivas->nSCE, 1 ) )) + IF( NE_16( st_ivas->hEncoderConfig->ivas_format, MONO_FORMAT ) && EQ_16( sce_id, sub( st_ivas->nSCE, 1 ) ) ) { - IF ( ( error = ivas_initialize_MD_bstr_enc( &( hSCE->hMetaData ), st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_initialize_MD_bstr_enc( &( hSCE->hMetaData ), st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -414,14 +414,14 @@ ivas_error create_sce_enc_fx( * Core Coder, 1 instance: allocate and initialize *-----------------------------------------------------------------*/ - IF ( ( st = (ENC_CORE_HANDLE) malloc( sizeof( Encoder_State ) ) ) == NULL ) + IF( ( st = (ENC_CORE_HANDLE) malloc( sizeof( Encoder_State ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CoreCoder structure\n" ) ); } copy_encoder_config_fx( st_ivas, st, 1 ); - IF ( EQ_16(st_ivas->hEncoderConfig->ivas_format, MASA_ISM_FORMAT) && ( EQ_16(st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ) || EQ_16(st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ) || EQ_16(st_ivas->ism_mode, ISM_MASA_MODE_DISC )) ) + IF( EQ_16( st_ivas->hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) && ( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) ) { st->element_mode = IVAS_SCE; } @@ -429,7 +429,7 @@ ivas_error create_sce_enc_fx( st->total_brate = hSCE->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ st->mct_chan_mode = MCT_CHAN_MODE_REGULAR; - IF ( ( error = init_encoder_ivas_fx( st, st_ivas, 0, st_ivas->hEncoderConfig->var_SID_rate_flag, st_ivas->hEncoderConfig->interval_SID, 0, st_ivas->ism_mode, hSCE->element_brate ) ) != IVAS_ERR_OK ) + IF( ( error = init_encoder_ivas_fx( st, st_ivas, 0, st_ivas->hEncoderConfig->var_SID_rate_flag, st_ivas->hEncoderConfig->interval_SID, 0, st_ivas->ism_mode, hSCE->element_brate ) ) != IVAS_ERR_OK ) { return error; } @@ -464,9 +464,9 @@ ivas_error create_evs_sce_enc( * Allocate SCE handle *-----------------------------------------------------------------*/ - if ((hSCE = (SCE_ENC_HANDLE)malloc(sizeof(SCE_ENC_DATA))) == NULL) + if ( ( hSCE = (SCE_ENC_HANDLE) malloc( sizeof( SCE_ENC_DATA ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SCE\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SCE\n" ) ); } /*-----------------------------------------------------------------* @@ -481,9 +481,9 @@ ivas_error create_evs_sce_enc( * Metadata: allocate and initialize *-----------------------------------------------------------------*/ - if (st_ivas->hEncoderConfig->ivas_format != MONO_FORMAT && sce_id == (st_ivas->nSCE - 1)) + if ( st_ivas->hEncoderConfig->ivas_format != MONO_FORMAT && sce_id == ( st_ivas->nSCE - 1 ) ) { - if ((error = ivas_initialize_MD_bstr_enc(&(hSCE->hMetaData), st_ivas)) != IVAS_ERR_OK) + if ( ( error = ivas_initialize_MD_bstr_enc( &( hSCE->hMetaData ), st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -563,14 +563,14 @@ void destroy_sce_enc( st = hSCE->hCoreCoder[0]; #ifndef EVS_FLOAT_ENC - if (st != NULL && hSCE->hCoreCoder[0]->element_mode == EVS_MONO) + if ( st != NULL && hSCE->hCoreCoder[0]->element_mode == EVS_MONO ) { - destroy_encoder_fx(hSCE->hCoreCoder[0]); + destroy_encoder_fx( hSCE->hCoreCoder[0] ); st = NULL; } else #endif - if ( st != NULL ) + if ( st != NULL ) { destroy_core_enc( st ); st = NULL; diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index fab245c3d..b304ea80f 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -171,17 +171,17 @@ ivas_error ivas_spar_enc_open( #ifdef IVAS_FLOAT_FIXED hSpar->AGC_Enable = ivas_agc_enc_get_flag_fx( nchan_transport ); #else - hSpar->AGC_Enable = ivas_agc_enc_get_flag(nchan_transport); + hSpar->AGC_Enable = ivas_agc_enc_get_flag( nchan_transport ); #endif hSpar->hAgcEnc = NULL; if ( hSpar->AGC_Enable ) { #ifdef IVAS_FLOAT_FIXED - if ((error = ivas_spar_agc_enc_open_fx(&hSpar->hAgcEnc, input_Fs, nchan_inp)) != IVAS_ERR_OK) - { - return error; - } + if ( ( error = ivas_spar_agc_enc_open_fx( &hSpar->hAgcEnc, input_Fs, nchan_inp ) ) != IVAS_ERR_OK ) + { + return error; + } #else if ( ( error = ivas_spar_agc_enc_open( &hSpar->hAgcEnc, input_Fs, nchan_inp ) ) != IVAS_ERR_OK ) { @@ -268,186 +268,186 @@ ivas_error ivas_spar_enc_open( } #ifdef IVAS_FLOAT_FIXED ivas_error ivas_spar_enc_open_fx( - Encoder_Struct *st_ivas, /* i/o: IVAS encoder handle */ - const Word16 spar_reconfig_flag /* i : SPAR reconfiguration flag */ + Encoder_Struct *st_ivas, /* i/o: IVAS encoder handle */ + const Word16 spar_reconfig_flag /* i : SPAR reconfiguration flag */ ) { - SPAR_ENC_HANDLE hSpar; - ENCODER_CONFIG_HANDLE hEncoderConfig; - IVAS_FB_CFG *fb_cfg; - Word16 nchan_inp, nchan_transport, sba_order_internal; - Word16 nchan_fb_in; - Word16 table_idx, active_w_mixing; - Word32 input_Fs, ivas_total_brate; - ivas_error error; - - hEncoderConfig = st_ivas->hEncoderConfig; - error = IVAS_ERR_OK; - hSpar = st_ivas->hSpar; - - IF (!spar_reconfig_flag) - { - /* SPAR encoder handle */ - IF ((hSpar = (SPAR_ENC_HANDLE)malloc(sizeof(SPAR_ENC_DATA))) == NULL) - { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR encoder"); - } - } - - hSpar->spar_reconfig_flag = 0; - input_Fs = hEncoderConfig->input_Fs; - sba_order_internal = extract_l(L_min(st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER)); - nchan_inp = ivas_sba_get_nchan_metadata(sba_order_internal, hEncoderConfig->ivas_total_brate); - assert(nchan_inp <= hEncoderConfig->nchan_inp); - ivas_total_brate = hEncoderConfig->ivas_total_brate; - - nchan_fb_in = 0; - IF (EQ_16(st_ivas->sba_analysis_order, 1)) - { - nchan_fb_in = FOA_CHANNELS; - } - ELSE IF (EQ_16(st_ivas->sba_analysis_order, 2)) - { - nchan_fb_in = 9; - } - ELSE IF (EQ_16(st_ivas->sba_analysis_order, 3)) - { - nchan_fb_in = 11; - } - ELSE - { - assert(0 && "sba_order must be 1,2, or 3!"); - } - - nchan_transport = ivas_get_sba_num_TCs_fx(hEncoderConfig->ivas_total_brate, sba_order_internal); - - table_idx = ivas_get_spar_table_idx_fx(ivas_total_brate, sba_order_internal, SPAR_CONFIG_BW, NULL, NULL); - - /* MD handle */ - IF ((error = ivas_spar_md_enc_open_fx(&(hSpar->hMdEnc), hEncoderConfig, sba_order_internal)) != IVAS_ERR_OK) - { - return error; - } + SPAR_ENC_HANDLE hSpar; + ENCODER_CONFIG_HANDLE hEncoderConfig; + IVAS_FB_CFG *fb_cfg; + Word16 nchan_inp, nchan_transport, sba_order_internal; + Word16 nchan_fb_in; + Word16 table_idx, active_w_mixing; + Word32 input_Fs, ivas_total_brate; + ivas_error error; - /* set FB config. */ - active_w_mixing = ivas_spar_br_table_consts[table_idx].active_w; - IF ((error = ivas_fb_set_cfg(&fb_cfg, SBA_FORMAT, nchan_inp, nchan_transport, active_w_mixing, input_Fs, nchan_fb_in)) != IVAS_ERR_OK) - { - return error; - } - fb_cfg->remix_order = remix_order_set[hSpar->hMdEnc->spar_md_cfg.remix_unmix_order]; + hEncoderConfig = st_ivas->hEncoderConfig; + error = IVAS_ERR_OK; + hSpar = st_ivas->hSpar; - /* FB mixer handle */ - IF ((error = ivas_FB_mixer_open(&(hSpar->hFbMixer), input_Fs, fb_cfg, spar_reconfig_flag)) != IVAS_ERR_OK) - { - return error; - } + IF( !spar_reconfig_flag ) + { + /* SPAR encoder handle */ + IF( ( hSpar = (SPAR_ENC_HANDLE) malloc( sizeof( SPAR_ENC_DATA ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR encoder" ); + } + } - /* Covariance handle */ - IF ((error = ivas_spar_covar_enc_open(&(hSpar->hCovEnc), hSpar->hFbMixer->pFb, input_Fs, nchan_inp, COV_SMOOTH_SPAR, hEncoderConfig->ivas_total_brate)) != IVAS_ERR_OK) - { - return error; - } + hSpar->spar_reconfig_flag = 0; + input_Fs = hEncoderConfig->input_Fs; + sba_order_internal = extract_l( L_min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ) ); + nchan_inp = ivas_sba_get_nchan_metadata( sba_order_internal, hEncoderConfig->ivas_total_brate ); + assert( nchan_inp <= hEncoderConfig->nchan_inp ); + ivas_total_brate = hEncoderConfig->ivas_total_brate; - IF (!spar_reconfig_flag) - { - /* Transient Detector handle */ - IF ((error = ivas_transient_det_open(&(hSpar->hTranDet), input_Fs)) != IVAS_ERR_OK) + nchan_fb_in = 0; + IF( EQ_16( st_ivas->sba_analysis_order, 1 ) ) + { + nchan_fb_in = FOA_CHANNELS; + } + ELSE IF( EQ_16( st_ivas->sba_analysis_order, 2 ) ) { - return error; + nchan_fb_in = 9; + } + ELSE IF( EQ_16( st_ivas->sba_analysis_order, 3 ) ) + { + nchan_fb_in = 11; + } + ELSE + { + assert( 0 && "sba_order must be 1,2, or 3!" ); } - } - /* initialization */ - hSpar->hMdEnc->table_idx = -1; + nchan_transport = ivas_get_sba_num_TCs_fx( hEncoderConfig->ivas_total_brate, sba_order_internal ); - /* AGC handle */ - hSpar->AGC_Enable = ivas_agc_enc_get_flag(nchan_transport); + table_idx = ivas_get_spar_table_idx_fx( ivas_total_brate, sba_order_internal, SPAR_CONFIG_BW, NULL, NULL ); - hSpar->hAgcEnc = NULL; - IF (hSpar->AGC_Enable) - { - IF ((error = ivas_spar_agc_enc_open(&hSpar->hAgcEnc, input_Fs, nchan_inp)) != IVAS_ERR_OK) + /* MD handle */ + IF( ( error = ivas_spar_md_enc_open_fx( &( hSpar->hMdEnc ), hEncoderConfig, sba_order_internal ) ) != IVAS_ERR_OK ) { - return error; + return error; } - } - /* PCA handle */ - hSpar->hPCA = NULL; - IF (hEncoderConfig->Opt_PCA_ON) - { - IF ((hSpar->hPCA = (PCA_ENC_STATE *)malloc(sizeof(PCA_ENC_STATE))) == NULL) + /* set FB config. */ + active_w_mixing = ivas_spar_br_table_consts[table_idx].active_w; + IF( ( error = ivas_fb_set_cfg( &fb_cfg, SBA_FORMAT, nchan_inp, nchan_transport, active_w_mixing, input_Fs, nchan_fb_in ) ) != IVAS_ERR_OK ) { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR PCA encoder"); + return error; } - ivas_pca_enc_init(hSpar->hPCA); - } + fb_cfg->remix_order = remix_order_set[hSpar->hMdEnc->spar_md_cfg.remix_unmix_order]; - /* initialization */ - hSpar->hMdEnc->table_idx = -1; + /* FB mixer handle */ + IF( ( error = ivas_FB_mixer_open( &( hSpar->hFbMixer ), input_Fs, fb_cfg, spar_reconfig_flag ) ) != IVAS_ERR_OK ) + { + return error; + } - /*-----------------------------------------------------------------* - * Configuration - set SPAR high-level parameters - *-----------------------------------------------------------------*/ + /* Covariance handle */ + IF( ( error = ivas_spar_covar_enc_open( &( hSpar->hCovEnc ), hSpar->hFbMixer->pFb, input_Fs, nchan_inp, COV_SMOOTH_SPAR, hEncoderConfig->ivas_total_brate ) ) != IVAS_ERR_OK ) + { + return error; + } - ivas_spar_config(hEncoderConfig->ivas_total_brate, min(st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER), &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &hSpar->core_nominal_brate, -1); + IF( !spar_reconfig_flag ) + { + /* Transient Detector handle */ + IF( ( error = ivas_transient_det_open( &( hSpar->hTranDet ), input_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } + } - IF (EQ_16(st_ivas->nchan_transport, 1)) - { - hEncoderConfig->element_mode_init = IVAS_SCE; - } - ELSE - { - hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; - } + /* initialization */ + hSpar->hMdEnc->table_idx = -1; - /*-----------------------------------------------------------------* - * Allocate and initialize Front-VAD handle - *-----------------------------------------------------------------*/ + /* AGC handle */ + hSpar->AGC_Enable = ivas_agc_enc_get_flag( nchan_transport ); - IF (!spar_reconfig_flag) - { - hSpar->front_vad_flag = 0; - hSpar->front_vad_dtx_flag = 0; - hSpar->force_front_vad = 0; + hSpar->hAgcEnc = NULL; + IF( hSpar->AGC_Enable ) + { + IF( ( error = ivas_spar_agc_enc_open( &hSpar->hAgcEnc, input_Fs, nchan_inp ) ) != IVAS_ERR_OK ) + { + return error; + } + } - IF (hEncoderConfig->Opt_DTX_ON) + /* PCA handle */ + hSpar->hPCA = NULL; + IF( hEncoderConfig->Opt_PCA_ON ) { - IF ((error = front_vad_create_fx(&(hSpar->hFrontVad), hEncoderConfig)) != IVAS_ERR_OK) - { - return error; - } + IF( ( hSpar->hPCA = (PCA_ENC_STATE *) malloc( sizeof( PCA_ENC_STATE ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR PCA encoder" ); + } + ivas_pca_enc_init( hSpar->hPCA ); + } - IF ((hSpar->hCoreCoderVAD = (ENC_CORE_HANDLE)malloc(sizeof(Encoder_State))) == NULL) - { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CoreCoder structure\n")); - } + /* initialization */ + hSpar->hMdEnc->table_idx = -1; - copy_encoder_config_fx(st_ivas, hSpar->hCoreCoderVAD, 1); + /*-----------------------------------------------------------------* + * Configuration - set SPAR high-level parameters + *-----------------------------------------------------------------*/ - hSpar->hCoreCoderVAD->total_brate = hEncoderConfig->ivas_total_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ - hSpar->hCoreCoderVAD->mct_chan_mode = MCT_CHAN_MODE_IGNORE; + ivas_spar_config( hEncoderConfig->ivas_total_brate, min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ), &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &hSpar->core_nominal_brate, -1 ); - IF ((error = init_encoder_ivas_fx(hSpar->hCoreCoderVAD, st_ivas, 0, hEncoderConfig->var_SID_rate_flag, hEncoderConfig->interval_SID, 1, st_ivas->ism_mode, hSpar->hCoreCoderVAD->total_brate)) != IVAS_ERR_OK) - { - return error; - } + IF( EQ_16( st_ivas->nchan_transport, 1 ) ) + { + hEncoderConfig->element_mode_init = IVAS_SCE; } ELSE { - hSpar->hCoreCoderVAD = NULL; - hSpar->hFrontVad = NULL; + hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + } + + /*-----------------------------------------------------------------* + * Allocate and initialize Front-VAD handle + *-----------------------------------------------------------------*/ + + IF( !spar_reconfig_flag ) + { + hSpar->front_vad_flag = 0; + hSpar->front_vad_dtx_flag = 0; + hSpar->force_front_vad = 0; + + IF( hEncoderConfig->Opt_DTX_ON ) + { + IF( ( error = front_vad_create_fx( &( hSpar->hFrontVad ), hEncoderConfig ) ) != IVAS_ERR_OK ) + { + return error; + } + + IF( ( hSpar->hCoreCoderVAD = (ENC_CORE_HANDLE) malloc( sizeof( Encoder_State ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CoreCoder structure\n" ) ); + } + + copy_encoder_config_fx( st_ivas, hSpar->hCoreCoderVAD, 1 ); + + hSpar->hCoreCoderVAD->total_brate = hEncoderConfig->ivas_total_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + hSpar->hCoreCoderVAD->mct_chan_mode = MCT_CHAN_MODE_IGNORE; + + IF( ( error = init_encoder_ivas_fx( hSpar->hCoreCoderVAD, st_ivas, 0, hEncoderConfig->var_SID_rate_flag, hEncoderConfig->interval_SID, 1, st_ivas->ism_mode, hSpar->hCoreCoderVAD->total_brate ) ) != IVAS_ERR_OK ) + { + return error; + } + } + ELSE + { + hSpar->hCoreCoderVAD = NULL; + hSpar->hFrontVad = NULL; + } } - } - /*-----------------------------------------------------------------* - * Final assignment - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * Final assignment + *-----------------------------------------------------------------*/ - st_ivas->hSpar = hSpar; + st_ivas->hSpar = hSpar; - return error; + return error; } #endif /*------------------------------------------------------------------------- @@ -784,8 +784,8 @@ static ivas_error ivas_spar_enc_process( #ifdef IVAS_FLOAT_FIXED Word32 pcm_tmp_fx[DIRAC_MAX_ANA_CHANS][L_FRAME48k * 2]; Word32 *p_pcm_tmp_fx[DIRAC_MAX_ANA_CHANS]; - //Word16 q_pcm_tmp_fx[DIRAC_MAX_ANA_CHANS][L_FRAME48k * 2]; - //Word16 *q_p_pcm_tmp_fx[DIRAC_MAX_ANA_CHANS]; + // Word16 q_pcm_tmp_fx[DIRAC_MAX_ANA_CHANS][L_FRAME48k * 2]; + // Word16 *q_p_pcm_tmp_fx[DIRAC_MAX_ANA_CHANS]; Word16 q_pcm_fx[DIRAC_MAX_ANA_CHANS]; #endif int16_t i, j, input_frame, dtx_vad; @@ -1041,26 +1041,26 @@ static ivas_error ivas_spar_enc_process( { if ( hSpar->AGC_Enable != 0 ) { -#ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED FOR( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) { p_pcm_tmp_fx[i] = &pcm_tmp_fx[i][0]; - q_pcm_fx[i] = Q_factor_arrL(&p_pcm_tmp[i][0], input_frame); + q_pcm_fx[i] = Q_factor_arrL( &p_pcm_tmp[i][0], input_frame ); FOR( j = 0; j < input_frame; j++ ) { - p_pcm_tmp_fx[i][j] = float_to_fix( p_pcm_tmp[i][j], q_pcm_fx[i]); + p_pcm_tmp_fx[i][j] = float_to_fix( p_pcm_tmp[i][j], q_pcm_fx[i] ); } } - ivas_agc_enc_process_fx(hSpar->hAgcEnc, hMetaData, p_pcm_tmp_fx, p_pcm_tmp_fx, hSpar->hFbMixer->fb_cfg->num_out_chans, hEncoderConfig, q_pcm_fx); + ivas_agc_enc_process_fx( hSpar->hAgcEnc, hMetaData, p_pcm_tmp_fx, p_pcm_tmp_fx, hSpar->hFbMixer->fb_cfg->num_out_chans, hEncoderConfig, q_pcm_fx ); - FOR(i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++) - { - FOR( j = 0; j < input_frame; j++ ) - { - p_pcm_tmp[i][j] = fix_to_float( p_pcm_tmp_fx[i][j], q_pcm_fx[i]); - } - } + FOR( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) + { + FOR( j = 0; j < input_frame; j++ ) + { + p_pcm_tmp[i][j] = fix_to_float( p_pcm_tmp_fx[i][j], q_pcm_fx[i] ); + } + } #else ivas_agc_enc_process( hSpar->hAgcEnc, hMetaData, p_pcm_tmp, p_pcm_tmp, hSpar->hFbMixer->fb_cfg->num_out_chans, hEncoderConfig ); #endif diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index 20fa21c9c..11c013dd1 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -171,69 +171,69 @@ ivas_error ivas_spar_md_enc_open( } #ifdef IVAS_FLOAT_FIXED ivas_error ivas_spar_md_enc_open_fx( - ivas_spar_md_enc_state_t **hMdEnc_in, /* i/o: SPAR MD encoder handle */ - const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ - const Word16 sba_order /* i : Ambisonic (SBA) order */ + ivas_spar_md_enc_state_t **hMdEnc_in, /* i/o: SPAR MD encoder handle */ + const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ + const Word16 sba_order /* i : Ambisonic (SBA) order */ ) { - ivas_spar_md_enc_state_t *hMdEnc; - ivas_error error; - Word16 num_channels, i, j; - error = IVAS_ERR_OK; + ivas_spar_md_enc_state_t *hMdEnc; + ivas_error error; + Word16 num_channels, i, j; + error = IVAS_ERR_OK; - IF ((hMdEnc = (ivas_spar_md_enc_state_t *)malloc(sizeof(ivas_spar_md_enc_state_t))) == NULL) - { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD encoder"); - } + IF( ( hMdEnc = (ivas_spar_md_enc_state_t *) malloc( sizeof( ivas_spar_md_enc_state_t ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD encoder" ); + } - num_channels = ivas_sba_get_nchan_metadata(sba_order, hEncoderConfig->ivas_total_brate); + num_channels = ivas_sba_get_nchan_metadata( sba_order, hEncoderConfig->ivas_total_brate ); - IF((hMdEnc->mixer_mat_local_fx = (Word32 ***)malloc(num_channels * sizeof(Word32 **))) == NULL) - { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix"); - } - FOR(i = 0; i < num_channels; i++) - { - IF((hMdEnc->mixer_mat_local_fx[i] = (Word32 **)malloc(num_channels * sizeof(Word32 *))) == NULL) + IF( ( hMdEnc->mixer_mat_local_fx = (Word32 ***) malloc( num_channels * sizeof( Word32 ** ) ) ) == NULL ) { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix"); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - FOR(j = 0; j < num_channels; j++) + FOR( i = 0; i < num_channels; i++ ) { - IF((hMdEnc->mixer_mat_local_fx[i][j] = (Word32 *)malloc(IVAS_MAX_NUM_BANDS * sizeof(Word32))) == NULL) - { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix"); - } + IF( ( hMdEnc->mixer_mat_local_fx[i] = (Word32 **) malloc( num_channels * sizeof( Word32 * ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); + } + FOR( j = 0; j < num_channels; j++ ) + { + IF( ( hMdEnc->mixer_mat_local_fx[i][j] = (Word32 *) malloc( IVAS_MAX_NUM_BANDS * sizeof( Word32 ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); + } + } } - } - IF((hMdEnc->mixer_mat_fx = (Word32 ***)malloc(num_channels * sizeof(Word32 **))) == NULL) - { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix"); - } - FOR(i = 0; i < num_channels; i++) - { - IF((hMdEnc->mixer_mat_fx[i] = (Word32 **)malloc(num_channels * sizeof(Word32 *))) == NULL) + IF( ( hMdEnc->mixer_mat_fx = (Word32 ***) malloc( num_channels * sizeof( Word32 ** ) ) ) == NULL ) { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix"); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - FOR(j = 0; j < num_channels; j++) + FOR( i = 0; i < num_channels; i++ ) { - IF((hMdEnc->mixer_mat_fx[i][j] = (Word32 *)malloc(IVAS_MAX_NUM_BANDS * sizeof(Word32))) == NULL) - { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix"); - } + IF( ( hMdEnc->mixer_mat_fx[i] = (Word32 **) malloc( num_channels * sizeof( Word32 * ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); + } + FOR( j = 0; j < num_channels; j++ ) + { + IF( ( hMdEnc->mixer_mat_fx[i][j] = (Word32 *) malloc( IVAS_MAX_NUM_BANDS * sizeof( Word32 ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); + } + } } - } - IF ((error = ivas_spar_md_enc_init_fx(hMdEnc, hEncoderConfig, sba_order)) != IVAS_ERR_OK) - { - return error; - } + IF( ( error = ivas_spar_md_enc_init_fx( hMdEnc, hEncoderConfig, sba_order ) ) != IVAS_ERR_OK ) + { + return error; + } - *hMdEnc_in = hMdEnc; + *hMdEnc_in = hMdEnc; - return error; + return error; } #endif /*------------------------------------------------------------------------- @@ -370,41 +370,41 @@ ivas_error ivas_spar_md_enc_init( } #ifdef IVAS_FLOAT_FIXED ivas_error ivas_spar_md_enc_init_fx( - ivas_spar_md_enc_state_t *hMdEnc, /* o : MD encoder handle */ - const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ - const Word16 sba_order /* i : Ambisonic (SBA) order */ + ivas_spar_md_enc_state_t *hMdEnc, /* o : MD encoder handle */ + const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ + const Word16 sba_order /* i : Ambisonic (SBA) order */ ) { - Word32 pFC[IVAS_MAX_NUM_BANDS]; - Word16 table_idx; - Word16 num_channels, i, j, k; + Word32 pFC[IVAS_MAX_NUM_BANDS]; + Word16 table_idx; + Word16 num_channels, i, j, k; - ivas_sba_get_spar_hoa_md_flag(sba_order, hEncoderConfig->ivas_total_brate, &hMdEnc->spar_hoa_md_flag, &hMdEnc->spar_hoa_dirac2spar_md_flag); - num_channels = ivas_sba_get_nchan_metadata(sba_order, hEncoderConfig->ivas_total_brate); - ivas_sba_get_spar_hoa_ch_ind(num_channels, hEncoderConfig->ivas_total_brate, hMdEnc->HOA_md_ind); - table_idx = ivas_get_spar_table_idx_fx(hEncoderConfig->ivas_total_brate, sba_order, SPAR_CONFIG_BW, NULL, NULL); + ivas_sba_get_spar_hoa_md_flag( sba_order, hEncoderConfig->ivas_total_brate, &hMdEnc->spar_hoa_md_flag, &hMdEnc->spar_hoa_dirac2spar_md_flag ); + num_channels = ivas_sba_get_nchan_metadata( sba_order, hEncoderConfig->ivas_total_brate ); + ivas_sba_get_spar_hoa_ch_ind( num_channels, hEncoderConfig->ivas_total_brate, hMdEnc->HOA_md_ind ); + table_idx = ivas_get_spar_table_idx_fx( hEncoderConfig->ivas_total_brate, sba_order, SPAR_CONFIG_BW, NULL, NULL ); - hMdEnc->spar_md.prior_dyn_active_w_flag = 0; + hMdEnc->spar_md.prior_dyn_active_w_flag = 0; - ivas_spar_set_bitrate_config_fx(&hMdEnc->spar_md_cfg, table_idx, (hMdEnc->spar_hoa_md_flag) ? IVAS_MAX_NUM_BANDS : SPAR_DIRAC_SPLIT_START_BAND, - hMdEnc->spar_hoa_dirac2spar_md_flag, 1, hEncoderConfig->Opt_PCA_ON, ivas_agc_enc_get_flag(ivas_spar_br_table_consts[table_idx].nchan_transport));//TODO: some log operations pending. + ivas_spar_set_bitrate_config_fx( &hMdEnc->spar_md_cfg, table_idx, ( hMdEnc->spar_hoa_md_flag ) ? IVAS_MAX_NUM_BANDS : SPAR_DIRAC_SPLIT_START_BAND, + hMdEnc->spar_hoa_dirac2spar_md_flag, 1, hEncoderConfig->Opt_PCA_ON, ivas_agc_enc_get_flag( ivas_spar_br_table_consts[table_idx].nchan_transport ) ); // TODO: some log operations pending. - /* get FB coefficients */ - FOR (i = 0; i < IVAS_MAX_NUM_BANDS; i++) - { - pFC[i] = L_shr(Mpy_32_32(ivas_fb_fcs_12band_1ms_fx[i], hEncoderConfig->input_Fs), 1); //Q0 - } + /* get FB coefficients */ + FOR( i = 0; i < IVAS_MAX_NUM_BANDS; i++ ) + { + pFC[i] = L_shr( Mpy_32_32( ivas_fb_fcs_12band_1ms_fx[i], hEncoderConfig->input_Fs ), 1 ); // Q0 + } - ivas_spar_set_enc_config_fx(hMdEnc, hMdEnc->spar_md_cfg.max_freq_per_chan, hMdEnc->spar_md_cfg.nchan_transport, pFC, num_channels); + ivas_spar_set_enc_config_fx( hMdEnc, hMdEnc->spar_md_cfg.max_freq_per_chan, hMdEnc->spar_md_cfg.nchan_transport, pFC, num_channels ); - IF (NE_16(hMdEnc->spar_md_cfg.nchan_transport, 2) && (EQ_16(hMdEnc->spar_md_cfg.remix_unmix_order, 1) || EQ_16(hMdEnc->spar_md_cfg.remix_unmix_order, 2))) - { - return IVAS_ERR_INTERNAL; - } + IF( NE_16( hMdEnc->spar_md_cfg.nchan_transport, 2 ) && ( EQ_16( hMdEnc->spar_md_cfg.remix_unmix_order, 1 ) || EQ_16( hMdEnc->spar_md_cfg.remix_unmix_order, 2 ) ) ) + { + return IVAS_ERR_INTERNAL; + } - ivas_spar_arith_coeffs_com_init(&hMdEnc->arith_coeffs, &hMdEnc->spar_md_cfg, table_idx, ENC); - ivas_spar_huff_coeffs_com_init(&hMdEnc->huff_coeffs, NULL, table_idx, ENC); -#if 0 //Some issues + ivas_spar_arith_coeffs_com_init( &hMdEnc->arith_coeffs, &hMdEnc->spar_md_cfg, table_idx, ENC ); + ivas_spar_huff_coeffs_com_init( &hMdEnc->huff_coeffs, NULL, table_idx, ENC ); +#if 0 // Some issues IF (EQ_16(hEncoderConfig->Opt_DTX_ON, 1)) { /* DTX quant init */ @@ -413,27 +413,27 @@ ivas_error ivas_spar_md_enc_init_fx( ivas_spar_quant_dtx_init_fx(&hMdEnc->spar_md, PR_minmax_fx); } #endif - hMdEnc->spar_md_cfg.prior_strat = START; - hMdEnc->spar_md_cfg.prev_quant_idx = -1; + hMdEnc->spar_md_cfg.prior_strat = START; + hMdEnc->spar_md_cfg.prev_quant_idx = -1; - FOR (i = 0; i < num_channels; i++) - { - FOR (j = 0; j < num_channels; j++) + FOR( i = 0; i < num_channels; i++ ) { - FOR (k = 0; k < IVAS_MAX_NUM_BANDS; k++) - { - hMdEnc->mixer_mat_fx[i][j][k] = 0; - } + FOR( j = 0; j < num_channels; j++ ) + { + FOR( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) + { + hMdEnc->mixer_mat_fx[i][j][k] = 0; + } + } } - } -#if 0 //Some issue +#if 0 // Some issue ivas_clear_band_coeffs_fx(hMdEnc->spar_md.band_coeffs, IVAS_MAX_NUM_BANDS); #endif - ivas_clear_band_coeff_idx(hMdEnc->spar_md.band_coeffs_idx, IVAS_MAX_NUM_BANDS); - ivas_clear_band_coeff_idx(hMdEnc->spar_md_prior.band_coeffs_idx, IVAS_MAX_NUM_BANDS); - ivas_clear_band_coeff_idx(hMdEnc->spar_md_prior.band_coeffs_idx_mapped, IVAS_MAX_NUM_BANDS); + ivas_clear_band_coeff_idx( hMdEnc->spar_md.band_coeffs_idx, IVAS_MAX_NUM_BANDS ); + ivas_clear_band_coeff_idx( hMdEnc->spar_md_prior.band_coeffs_idx, IVAS_MAX_NUM_BANDS ); + ivas_clear_band_coeff_idx( hMdEnc->spar_md_prior.band_coeffs_idx_mapped, IVAS_MAX_NUM_BANDS ); - return IVAS_ERR_OK; + return IVAS_ERR_OK; } #endif /*-----------------------------------------------------------------------------------------* @@ -485,45 +485,45 @@ static void ivas_spar_set_enc_config( } #ifdef IVAS_FLOAT_FIXED static void ivas_spar_set_enc_config_fx( - ivas_spar_md_enc_state_t *hMdEnc, - Word16 *max_freq_per_chan, - const Word16 nchan_transport, - Word32 *pFC, //Input Q0 - const Word16 nchan_inp) + ivas_spar_md_enc_state_t *hMdEnc, + Word16 *max_freq_per_chan, + const Word16 nchan_transport, + Word32 *pFC, // Input Q0 + const Word16 nchan_inp ) { - Word16 i, j; - Word16 tmp_dmx_ch; + Word16 i, j; + Word16 tmp_dmx_ch; - FOR(i = 0; i < nchan_transport; i++) - { - IF(max_freq_per_chan != NULL) + FOR( i = 0; i < nchan_transport; i++ ) { - hMdEnc->spar_md_cfg.max_freq_per_chan[i] = (max_freq_per_chan[i] != 0) ? max_freq_per_chan[i] : max_freq_per_chan[0]; - } - ELSE - { - hMdEnc->spar_md_cfg.max_freq_per_chan[i] = IVAS_SPAR_FOA_DFLT_FREQ_PER_CHAN; + IF( max_freq_per_chan != NULL ) + { + hMdEnc->spar_md_cfg.max_freq_per_chan[i] = ( max_freq_per_chan[i] != 0 ) ? max_freq_per_chan[i] : max_freq_per_chan[0]; + } + ELSE + { + hMdEnc->spar_md_cfg.max_freq_per_chan[i] = IVAS_SPAR_FOA_DFLT_FREQ_PER_CHAN; + } } - } - hMdEnc->num_umx_ch = nchan_inp; - hMdEnc->num_decorr = sub(nchan_inp, 1); + hMdEnc->num_umx_ch = nchan_inp; + hMdEnc->num_decorr = sub( nchan_inp, 1 ); - FOR(i = 0; i < IVAS_MAX_NUM_BANDS; i++) - { - tmp_dmx_ch = 0; - FOR(j = 0; j < nchan_transport; j++) + FOR( i = 0; i < IVAS_MAX_NUM_BANDS; i++ ) { - IF(LT_32(pFC[i], hMdEnc->spar_md_cfg.max_freq_per_chan[j])) - { - tmp_dmx_ch = add(tmp_dmx_ch, 1); - } - } + tmp_dmx_ch = 0; + FOR( j = 0; j < nchan_transport; j++ ) + { + IF( LT_32( pFC[i], hMdEnc->spar_md_cfg.max_freq_per_chan[j] ) ) + { + tmp_dmx_ch = add( tmp_dmx_ch, 1 ); + } + } - hMdEnc->spar_md_cfg.num_dmx_chans_per_band[i] = tmp_dmx_ch; - hMdEnc->spar_md_cfg.num_decorr_per_band[i] = sub(hMdEnc->num_umx_ch, tmp_dmx_ch); - } + hMdEnc->spar_md_cfg.num_dmx_chans_per_band[i] = tmp_dmx_ch; + hMdEnc->spar_md_cfg.num_decorr_per_band[i] = sub( hMdEnc->num_umx_ch, tmp_dmx_ch ); + } - return; + return; } #endif /*-----------------------------------------------------------------------------------------* diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index c52fcf51e..3342895be 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -95,9 +95,9 @@ typedef struct stereo_itd_data_struct Word16 itd_thres_fx; Word32 prev_sum_nrg_L_lb_fx; Word32 prev_xcorr_lb_fx[STEREO_DFT_XCORR_LB_MAX]; - Word32 E_band_n_fx[STEREO_DFT_ITD_VAD_BAND_NUM];/*Q0*/ + Word32 E_band_n_fx[STEREO_DFT_ITD_VAD_BAND_NUM]; /*Q0*/ Word32 xcorr_smooth_fx[STEREO_DFT_N_32k_ENC]; - Word32 lp_phat_peak_fx; /* low-pass GCC PHAT peak value */ + Word32 lp_phat_peak_fx; /* low-pass GCC PHAT peak value */ Word32 itd_fx[STEREO_DFT_ENC_DFT_NB]; Word32 deltaItd_fx[STEREO_DFT_ENC_DFT_NB]; @@ -218,7 +218,7 @@ typedef struct stereo_dft_enc_data_struct /* Stereo CNG */ float sidSideGain[STEREO_DFT_ERB4_BANDS]; float win_ana_energy; - Word16 win_ana_energy_fx; //Q15 + Word16 win_ana_energy_fx; // Q15 float xspec_smooth[STEREO_DFT_N_32k_ENC]; float Spd_L_smooth[STEREO_DFT_N_32k_ENC / 2]; float Spd_R_smooth[STEREO_DFT_N_32k_ENC / 2]; @@ -279,7 +279,7 @@ typedef struct stereo_dft_enc_data_struct float diff_l_h_sm; float diff_r_h_sm; float prev_fac2; - + /*Residual coding*/ int16_t res_cod_mode[STEREO_DFT_ENC_DFT_NB]; /* mode from 0 (off) to 3 */ int16_t res_cod_band_max; /* Band max for coding of residual */ @@ -291,10 +291,10 @@ typedef struct stereo_dft_enc_data_struct int16_t first_frm_flag; /* ADAP first frame flag */ /* flags and data for adaptive wideband residual coding */ - float res_dmx_ratio_lt; /* long term energy ratio between RES and DMX */ - int16_t hangover_cnt0; /* counter 0 for hangover */ - int16_t hangover_cnt1; /* counter 1 for hangover */ - float dmx_res_all_prev; /* energy of the previous frame */ + float res_dmx_ratio_lt; /* long term energy ratio between RES and DMX */ + int16_t hangover_cnt0; /* counter 0 for hangover */ + int16_t hangover_cnt1; /* counter 1 for hangover */ + float dmx_res_all_prev; /* energy of the previous frame */ int16_t last_res_cod_mode_modify_flag; /* a flag to indicate whether the res_cod_mode_flag has been modified for the switching frame in which res_cod_mode_flag should be swithced from 1 to 0 */ int16_t res_cod_sw_flag; /* a flag to indicate whether it is a switching frame */ @@ -304,19 +304,19 @@ typedef struct stereo_dft_enc_data_struct float icbweRefEner; float lbEner; int16_t flip_sign; - Word32 dmx_res_all_prev_fx; /* energy of the previous frame Q31*/ - Word16 switch_fade_factor_fx; /* Adaptive fade factor for switch frame Q15*/ - Word32 res_dmx_ratio_lt_fx; /* long term energy ratio between RES and DMX Q31*/ - Word32 pre_sub_nrg_DMX_fx[STEREO_DFT_BAND_MAX]; + Word32 dmx_res_all_prev_fx; /* energy of the previous frame Q31*/ + Word16 switch_fade_factor_fx; /* Adaptive fade factor for switch frame Q15*/ + Word32 res_dmx_ratio_lt_fx; /* long term energy ratio between RES and DMX Q31*/ + Word32 pre_sub_nrg_DMX_fx[STEREO_DFT_BAND_MAX]; Word32 diff_l_h_sm_fx; Word32 diff_r_h_sm_fx; - Word32 prev_fac2_fx; //initilizae in Q31 + Word32 prev_fac2_fx; // initilizae in Q31 Word32 res_pred_gain_f_fx[STEREO_DFT_BAND_MAX]; Word32 nrg_L_fx[2]; Word32 nrg_R_fx[2]; Word32 nrg_DMX_fx[2]; Word32 res_pred_gain_fx[STEREO_DFT_ENC_DFT_NB * STEREO_DFT_BAND_MAX]; /*prediction gain for the residual HFs */ - Word32 gainIPD_sm_fx; /* long-term gain IPD for NIPD detection */////initilizae in Q31 + Word32 gainIPD_sm_fx; /* long-term gain IPD for NIPD detection */ ////initilizae in Q31 Word32 sfm_fx; Word32 sum_dot_prod_real_fx; Word32 sum_dot_prod_img_fx; @@ -382,8 +382,8 @@ typedef struct stereo_mdct_enc_data_structure /* only intraframe */ int16_t mdct_stereo_mode[2]; /* mdct stereo mode: LR, MS, band-wise MS */ - int16_t global_ild[2]; /* Quantized ILD for the whole spectrum */ - int16_t split_ratio; /* Ratio of bitrate (1 to 7), split_ratio = 8 * 1st chn bitrate / (1st + 2nd chn bitrate) */ + int16_t global_ild[2]; /* Quantized ILD for the whole spectrum */ + int16_t split_ratio; /* Ratio of bitrate (1 to 7), split_ratio = 8 * 1st chn bitrate / (1st + 2nd chn bitrate) */ int16_t IGFStereoMode[2]; /* MDCT stereo mode for IGF */ @@ -405,7 +405,7 @@ typedef struct stereo_td_enc_data_structure { BSTR_ENC_DATA tdm_hBstr_tmp; /* temporary bitstream structure holding TD stereo spatial parameters */ Indice tdm_ind_list_tmp[MAX_IND_TDM_TMP]; /* temporary list of indices holding TD stereo spatial parameters */ - Word16 max_ind_tdm_tmp; /* maximum number of indices in the temporary list of indices holding TD stereo spatial parameters */ + Word16 max_ind_tdm_tmp; /* maximum number of indices in the temporary list of indices holding TD stereo spatial parameters */ Word16 tdm_lp_reuse_flag; /* Flag that indicate if it is possible to reuse the LP coefficient from the primary channel or not */ Word16 tdm_low_rate_mode; /* secondary channel low rate mode flag */ @@ -426,10 +426,10 @@ typedef struct stereo_td_enc_data_structure Word32 tdm_lt_corr_LM_fx; /* Long term left-mono correlation */ Word32 tdm_last_diff_lt_corr_fx; /* long term correlation difference mem */ Word32 tdm_last_ratio_fx; /* Last TDM ratio */ - Word32 tdm_lt_rms_L_fx; /* Left channel long term rms */ - Word32 tdm_lt_rms_R_fx; /* Right channel long term rms */ - Word32 tdm_last_ener_lt_R_fx; /* Right channel long term energy */ - Word32 tdm_last_ener_lt_L_fx; /* Left channel long term energy */ + Word32 tdm_lt_rms_L_fx; /* Left channel long term rms */ + Word32 tdm_lt_rms_R_fx; /* Right channel long term rms */ + Word32 tdm_last_ener_lt_R_fx; /* Right channel long term energy */ + Word32 tdm_last_ener_lt_L_fx; /* Left channel long term energy */ Word16 tdm_last_ratio_idx; /* last TDM ratio index */ Word16 tdm_last_SM_flag; /* Flag to signal a SM encoding scheme -> better for some music item */ @@ -438,8 +438,8 @@ typedef struct stereo_td_enc_data_structure Word16 tdm_hyst_cnt; /* Counter */ Word16 tdm_prev_stable_idx; /* Previous Transmitted ratio index*/ Word16 tdm_prev_desired_idx; /* Previous Transmitted ratio index*/ - float tdm_LT_es_em; /* Long term evoluation of the side to mono energy ratio */ - Word32 tdm_LT_es_em_fx; /* Long term evoluation of the side to mono energy ratio */ + float tdm_LT_es_em; /* Long term evoluation of the side to mono energy ratio */ + Word32 tdm_LT_es_em_fx; /* Long term evoluation of the side to mono energy ratio */ Word16 tdm_use_IAWB_Ave_lpc; /* Flag to indicate the usage of mean inactive LP coefficients */ /* NOOP parameters */ @@ -457,10 +457,10 @@ typedef struct stereo_td_enc_data_structure Word32 tdm_lt_corr_LM_SM_fx; /* Long term left-mono correlation in SM mode*/ Word32 tdm_last_diff_lt_corr_SM_fx; /* long term correlation difference mem in SM mode*/ Word32 tdm_last_ratio_SM_fx; /* Last TDM ratio in SM mode*/ - Word32 tdm_lt_rms_L_SM_fx; /* Left channel long term rms in SM mode*/ - Word32 tdm_lt_rms_R_SM_fx; /* Right channel long term rms in SM mode*/ - Word32 tdm_last_ener_lt_R_SM_fx; /* Right channel long term energy in SM mode*/ - Word32 tdm_last_ener_lt_L_SM_fx; /* Left channel long term energy in SM mode*/ + Word32 tdm_lt_rms_L_SM_fx; /* Left channel long term rms in SM mode*/ + Word32 tdm_lt_rms_R_SM_fx; /* Right channel long term rms in SM mode*/ + Word32 tdm_last_ener_lt_R_SM_fx; /* Right channel long term energy in SM mode*/ + Word32 tdm_last_ener_lt_L_SM_fx; /* Left channel long term energy in SM mode*/ Word16 tdm_last_ratio_idx_SM; /* last TDM ratio index in SM mode*/ Word16 tdm_last_SM_flag_noop; /* Flag to signal a SM encoding scheme -> better for some music item in SM mode*/ @@ -469,8 +469,8 @@ typedef struct stereo_td_enc_data_structure Word16 tdm_hyst_cnt_SM; /* Counter in SM mode*/ Word16 tdm_prev_stable_idx_SM; /* Previous Transmitted ratio index in SM mode*/ Word16 tdm_prev_desired_idx_SM; /* Previous Transmitted ratio index in SM mode*/ - float tdm_LT_es_em_SM; /* Long term evoluation of the side to mono energy ratio in SM mode*/ - Word32 tdm_LT_es_em_SM_fx; /* Long term evoluation of the side to mono energy ratio in SM mode*/ + float tdm_LT_es_em_SM; /* Long term evoluation of the side to mono energy ratio in SM mode*/ + Word32 tdm_LT_es_em_SM_fx; /* Long term evoluation of the side to mono energy ratio in SM mode*/ Word16 tdm_NOOP_cnt; /* Counter for channel combination scheme */ Word16 tdm_SM_flag; /* Flag for channel combination scheme */ Word16 tdm_SM_last2_clas[2]; /* Class of the frame immediately prior to the previous frame */ @@ -498,10 +498,10 @@ typedef struct stereo_td_enc_data_structure typedef struct stereo_tca_enc_data_structure { - Word16 refChanIndx; /* reference channel index in current frame */ - Word16 prevRefChanIndx; /* reference channel index in previous frame */ - Word16 indx_ica_NCShift; /* ICA target channel inter-channel corrstats */ - Word16 indx_ica_gD; /* ICA target gain */ + Word16 refChanIndx; /* reference channel index in current frame */ + Word16 prevRefChanIndx; /* reference channel index in previous frame */ + Word16 indx_ica_NCShift; /* ICA target channel inter-channel corrstats */ + Word16 indx_ica_gD; /* ICA target gain */ float targetGain; /* gain norm applied on target (or right) channel in current frame */ float instTargetGain; /* instantaneous gain norm applied on target (or right) channel in current frame */ float prevTargetGain; /* gain norm applied on target (or right) channel in previous frame */ @@ -537,15 +537,15 @@ typedef struct stereo_tca_enc_data_structure Word32 memChanL_fx[L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH]; /* left channel input to correct at the cross-over */ Word32 memChanR_fx[L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH]; /* right channel input to correct at the cross-over */ - + Word32 memChanL_DS_fx[ADDED_MEM_DS]; /* left channel input speech memory for downmix */ Word32 memChanR_DS_fx[ADDED_MEM_DS]; /* right channel input speech memory for downmix */ Word32 mem_tempF_fx; Word32 memdecim_fx[12]; /* memory for pre-rmphasis filter for resampling */ Word32 corrEstPrev_fx[3][2 * L_NCSHIFT_DS + 1]; /* Prev correlation vector */ Word32 corrEstLT_fx[2 * L_NCSHIFT_DS + 1]; /* Long term correlation vector smoothed */ - - Word32 ica_envVarLT_fx; //Q20 + + Word32 ica_envVarLT_fx; // Q20 Word32 C_mem_fx[2 * L_NCSHIFT_DS + 1]; Word32 E1_mem_fx, E2_mem_fx; Word32 delay_0_mem_fx[MAX_DELAYREGLEN]; @@ -612,18 +612,18 @@ typedef struct stereo_icbwe_enc_data_structure Word32 memShbSpecMapping_fx; Word32 memShbSpecXcorr_fx[6]; Word32 prevgsMapping_fx; - Word32 prevRefEner_fx; //Q31 - Word32 prevNonRefEner_fx; //Q31 - Word32 memGsEnerMap_fx[2]; //Q31 + Word32 prevRefEner_fx; // Q31 + Word32 prevNonRefEner_fx; // Q31 + Word32 memGsEnerMap_fx[2]; // Q31 Word32 dec_2over3_mem_fx[L_FILT_2OVER3]; Word32 dec_2over3_mem_lp_fx[L_FILT_2OVER3_LP]; - Word32 icbwe_inp_mem_fx[CPE_CHANNELS][NS2SA(48000, L_MEM_RECALC_TBE_NS)]; + Word32 icbwe_inp_mem_fx[CPE_CHANNELS][NS2SA( 48000, L_MEM_RECALC_TBE_NS )]; Word32 *dataChan_fx[CPE_CHANNELS]; Word32 memModifyFs_icbwe_fx[CPE_CHANNELS][2 * L_FILT32k]; Word32 mem_nrg_L_fx[CPE_CHANNELS]; Word32 mem_nrg_R_fx[CPE_CHANNELS]; Word32 mem_nrg_DMX_fx[CPE_CHANNELS]; - Word32 gDes_pastFrame_fx; //Q31 + Word32 gDes_pastFrame_fx; // Q31 Word32 icbweRefEner_fx; Word32 shbSynthRef_fx[L_FRAME16k]; Word32 nlExc16k_fx[L_FRAME16k]; @@ -662,25 +662,25 @@ typedef struct ivas_stereo_classifier_data_structure Word16 vad_relE; Word16 aEn_raw[CPE_CHANNELS]; /* raw aEn for local relative energy estimation */ - float ave_ener_L; /* average energy of the L channel */ - float ave_ener_R; /* average energy of the R channel */ - float Etot_dn; /* average energy in dB - lower bound */ - float Etot_up; /* average energy in dB - upper bound */ - float relE_buf[UNCLR_L_RELE]; /* running buffer for relative energy */ - float Etot_buf[UNCLR_L_ETOT]; /* running buffer for average energy in dB */ - float relE_0_1; /* relative energy in the current frame normalized to (0,1) */ + float ave_ener_L; /* average energy of the L channel */ + float ave_ener_R; /* average energy of the R channel */ + float Etot_dn; /* average energy in dB - lower bound */ + float Etot_up; /* average energy in dB - upper bound */ + float relE_buf[UNCLR_L_RELE]; /* running buffer for relative energy */ + float Etot_buf[UNCLR_L_ETOT]; /* running buffer for average energy in dB */ + float relE_0_1; /* relative energy in the current frame normalized to (0,1) */ float relE_0_1_LT; Word16 unclr_sw_enable_cnt[CPE_CHANNELS]; /* UNCLR classifier - counter of frames suitable for UNCLR switching */ float unclr_relE_0_1_LT[UNCLR_RC_ORDER]; float unclr_wscore; - Word16 unclr_decision; /* UNCLR stereo classifier decision (0/1) */ + Word16 unclr_decision; /* UNCLR stereo classifier decision (0/1) */ float unclr_fv[SSC_MAX_NFEA]; /* UNCLR - feature vector */ Word16 unclr_corrLagMax_prev; float xtalk_score_buf[XTALK_SCORE_BUF_LEN]; - Word16 xtalk_decision; /* xtalk stereo classifier decision (0/1) */ + Word16 xtalk_decision; /* xtalk stereo classifier decision (0/1) */ float xtalk_fv[SSC_MAX_NFEA]; /* xtalk - feature vector */ float xtalk_wscore; float xtalk_score; @@ -693,7 +693,7 @@ typedef struct ivas_stereo_classifier_data_structure Word16 silence_flag; - //Above needs to remove once everything done + // Above needs to remove once everything done Word32 voicing_ch1_fx[3]; Word32 cor_map_sum_ch1_fx; Word32 lsf_ch1_fx[M]; @@ -708,13 +708,13 @@ typedef struct ivas_stereo_classifier_data_structure Word32 prev_IPD_fx; Word32 prev_ratio_m1_m2_fx; Word32 ratio_L_fx; - Word32 ave_ener_L_fx; /* average energy of the L channel */ - Word32 ave_ener_R_fx; /* average energy of the R channel */ - Word32 Etot_dn_fx; /* average energy in dB - lower bound */ - Word32 Etot_up_fx; /* average energy in dB - upper bound */ - Word32 relE_buf_fx[UNCLR_L_RELE]; /* running buffer for relative energy */ - Word32 Etot_buf_fx[UNCLR_L_ETOT]; /* running buffer for average energy in dB */ - Word32 relE_0_1_fx; /* relative energy in the current frame normalized to (0,1) */ + Word32 ave_ener_L_fx; /* average energy of the L channel */ + Word32 ave_ener_R_fx; /* average energy of the R channel */ + Word32 Etot_dn_fx; /* average energy in dB - lower bound */ + Word32 Etot_up_fx; /* average energy in dB - upper bound */ + Word32 relE_buf_fx[UNCLR_L_RELE]; /* running buffer for relative energy */ + Word32 Etot_buf_fx[UNCLR_L_ETOT]; /* running buffer for average energy in dB */ + Word32 relE_0_1_fx; /* relative energy in the current frame normalized to (0,1) */ Word32 relE_0_1_LT_fx; Word32 unclr_relE_0_1_LT_fx[UNCLR_RC_ORDER]; Word32 unclr_wscore_fx; @@ -759,13 +759,13 @@ typedef struct front_vad_enc float mem_decim[2 * L_FILT_MAX]; /* decimation filter memory */ float buffer_12k8[3 * L_FRAME / 2]; /* 12k8 signal buffer */ float mem_preemph; /* preemph filter memory */ - Word16 mem_preemph_fx; /* preemph filter memory */ + Word16 mem_preemph_fx; /* preemph filter memory */ NOISE_EST_HANDLE hNoiseEst; /* Noise estimation handle */ VAD_HANDLE hVAD; /* VAD handle */ float *delay_buf; Word16 *delay_buf_fx; int16_t delay_samples; - int16_t rem_dtx_ho; /* Remaining hangover frames */ + int16_t rem_dtx_ho; /* Remaining hangover frames */ Word32 mem_decim_fx[2 * L_FILT_MAX]; /* decimation filter memory */ Word32 buffer_12k8_fx[3 * L_FRAME / 2]; /* 12k8 signal buffer */ } FRONT_VAD_ENC, *FRONT_VAD_ENC_HANDLE; @@ -911,7 +911,7 @@ typedef struct ivas_spar_enc_lib_t FRONT_VAD_ENC_HANDLE hFrontVad; /* front-VAD handle */ ENC_CORE_HANDLE hCoreCoderVAD; /* core-coder handle for front-VAD module */ #ifndef EVS_FLOAT_ENC - //ENC_CORE_HANDLE_FX hCoreCoderVAD_fx; /* core coder handle */ + // ENC_CORE_HANDLE_FX hCoreCoderVAD_fx; /* core coder handle */ #endif int16_t spar_reconfig_flag; @@ -1153,21 +1153,21 @@ typedef struct ivas_osba_enc_data_structure typedef struct stereo_cng_enc { - Word16 prev_sg_average_counter; /* Counter for sidegain averaging */ - Word16 sg_active_cnt; /* Counter for sidegain averaging */ - Word16 sg_average_counter; /* Counter for sidegain averaging */ - float sg_average[STEREO_DFT_ERB4_BANDS]; /* Sidegain average */ - float prev_sg_average[STEREO_DFT_ERB4_BANDS]; /* Previous sidegain average */ - float mem_cohBand[STEREO_DFT_BAND_MAX / 2]; /* Coherence memory */ - float prev_cohBand[2 * ( STEREO_DFT_BAND_MAX / 2 )]; /* Previous coherence */ - Word16 cng_counter; /* Counter for cng period length */ - Word16 td_active; /* TD-stereo indication */ - Word16 first_SID_after_TD; /* Set if first SID frame after TD stereo */ - Word16 first_SID; /* Set if first SID frame since codec start */ + Word16 prev_sg_average_counter; /* Counter for sidegain averaging */ + Word16 sg_active_cnt; /* Counter for sidegain averaging */ + Word16 sg_average_counter; /* Counter for sidegain averaging */ + float sg_average[STEREO_DFT_ERB4_BANDS]; /* Sidegain average */ + float prev_sg_average[STEREO_DFT_ERB4_BANDS]; /* Previous sidegain average */ + float mem_cohBand[STEREO_DFT_BAND_MAX / 2]; /* Coherence memory */ + float prev_cohBand[2 * ( STEREO_DFT_BAND_MAX / 2 )]; /* Previous coherence */ + Word16 cng_counter; /* Counter for cng period length */ + Word16 td_active; /* TD-stereo indication */ + Word16 first_SID_after_TD; /* Set if first SID frame after TD stereo */ + Word16 first_SID; /* Set if first SID frame since codec start */ Word32 sg_average_fx[STEREO_DFT_ERB4_BANDS]; /* Sidegain average */ Word32 prev_sg_average_fx[STEREO_DFT_ERB4_BANDS]; /* Previous sidegain average */ Word32 mem_cohBand_fx[STEREO_DFT_BAND_MAX / 2]; /* Coherence memory */ - Word32 prev_cohBand_fx[2 * (STEREO_DFT_BAND_MAX / 2)]; /* Previous coherence */ + Word32 prev_cohBand_fx[2 * ( STEREO_DFT_BAND_MAX / 2 )]; /* Previous coherence */ } STEREO_CNG_ENC, *STEREO_CNG_ENC_HANDLE; @@ -1216,7 +1216,7 @@ typedef struct cpe_enc_data_structure float *input_mem[CPE_CHANNELS]; /* input channels buffers memory; needed to be up-to-date for TD->DFT stereo switching */ - Word32 brate_surplus; /* bitrate surplus for bitrate adaptation in combined format coding */ + Word32 brate_surplus; /* bitrate surplus for bitrate adaptation in combined format coding */ Word32 *input_mem_fx[CPE_CHANNELS]; /* input channels buffers memory; needed to be up-to-date for TD->DFT stereo switching */ } CPE_ENC_DATA, *CPE_ENC_HANDLE; diff --git a/lib_enc/ivas_stereo_classifier.c b/lib_enc/ivas_stereo_classifier.c index da68c4fe5..a755906d8 100644 --- a/lib_enc/ivas_stereo_classifier.c +++ b/lib_enc/ivas_stereo_classifier.c @@ -109,8 +109,7 @@ int16_t select_stereo_mode( stereo_switching_flag = 1; - if ( hCPE->element_brate >= MIN_BRATE_MDCT_STEREO || ( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) && hCPE->element_brate < MASA_STEREO_MIN_BITRATE ) - ) + if ( hCPE->element_brate >= MIN_BRATE_MDCT_STEREO || ( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) && hCPE->element_brate < MASA_STEREO_MIN_BITRATE ) ) { stereo_switching_flag = 0; } @@ -283,68 +282,68 @@ void stereo_classifier_init( } #ifdef IVAS_FLOAT_FIXED void stereo_classifier_init_fx( - STEREO_CLASSIF_HANDLE hStereoClassif /* i/o: stereo classifier structure */ + STEREO_CLASSIF_HANDLE hStereoClassif /* i/o: stereo classifier structure */ ) { - /* initialization of features for xtalk classifier and UNCLR classifier */ - hStereoClassif->clas_ch1 = 0; - set16_fx(hStereoClassif->pitch_ch1, 0, 3); - set_zero_fx(hStereoClassif->voicing_ch1_fx, 3); - hStereoClassif->cor_map_sum_ch1_fx = 0; - set_zero_fx(hStereoClassif->lsf_ch1_fx, M); - hStereoClassif->lepsP_ch1_fx = 0; - hStereoClassif->dE1_ch1_fx = 0; - hStereoClassif->dE1_ch2_fx = 0; - hStereoClassif->nchar_ch1_fx = 0; - hStereoClassif->nchar_ch2_fx = 0; - hStereoClassif->non_sta_ch1_fx = 0; - hStereoClassif->sp_div_ch1_fx = 0; - hStereoClassif->ps_diff_ch1_fx = 0; - hStereoClassif->ps_diff_ch2_fx = 0; - hStereoClassif->ps_sta_ch1_fx = 0; - hStereoClassif->ps_sta_ch2_fx = 0; - hStereoClassif->prev_g_IPD_fx = 1073741824; //Q31 - hStereoClassif->prev_IPD_fx = 0; - hStereoClassif->prev_ratio_m1_m2_fx = 0; - set_zero_fx(hStereoClassif->xtalk_score_buf_fx, XTALK_SCORE_BUF_LEN); - hStereoClassif->ratio_L_fx = 1073741824; //Q31 - hStereoClassif->vad_flag_glob = 0; //Q31 - hStereoClassif->vad_relE = 0; //Q31 - hStereoClassif->is_speech_fx = 0; //Q31 - - set16_fx(hStereoClassif->aEn_raw, 0, CPE_CHANNELS); - - hStereoClassif->Etot_dn_fx = 0; - hStereoClassif->Etot_up_fx = 0; - - set_zero_fx(hStereoClassif->relE_buf_fx, UNCLR_L_RELE); - set_zero_fx(hStereoClassif->Etot_buf_fx, UNCLR_L_ETOT); - set_zero_fx(hStereoClassif->unclr_relE_0_1_LT_fx, UNCLR_RC_ORDER); - - hStereoClassif->unclr_sw_enable_cnt[0] = 0; - hStereoClassif->unclr_sw_enable_cnt[1] = 0; - - hStereoClassif->unclr_decision = 0; - hStereoClassif->unclr_wscore_fx = 0; - - set32_fx(hStereoClassif->unclr_fv_fx, -2147483647 - 1, SSC_MAX_NFEA);//Q31 - hStereoClassif->unclr_corrLagMax_prev = 0; - hStereoClassif->ave_ener_L = 0; - hStereoClassif->ave_ener_R = 0; - hStereoClassif->relE_0_1_fx = 21474836; //Q31 - hStereoClassif->relE_0_1_LT_fx = 21474836; //Q31 - - set32_fx(hStereoClassif->xtalk_fv_fx, -2147483647 - 1, SSC_MAX_NFEA);//Q31 - hStereoClassif->xtalk_wscore_fx = 0; - hStereoClassif->xtalk_decision = 0; - hStereoClassif->xtalk_score_wrelE_fx = 0; - - hStereoClassif->lrtd_mode = 0; - hStereoClassif->prev_lrtd_mode = 0; - - hStereoClassif->silence_flag = 0; - - return; + /* initialization of features for xtalk classifier and UNCLR classifier */ + hStereoClassif->clas_ch1 = 0; + set16_fx( hStereoClassif->pitch_ch1, 0, 3 ); + set_zero_fx( hStereoClassif->voicing_ch1_fx, 3 ); + hStereoClassif->cor_map_sum_ch1_fx = 0; + set_zero_fx( hStereoClassif->lsf_ch1_fx, M ); + hStereoClassif->lepsP_ch1_fx = 0; + hStereoClassif->dE1_ch1_fx = 0; + hStereoClassif->dE1_ch2_fx = 0; + hStereoClassif->nchar_ch1_fx = 0; + hStereoClassif->nchar_ch2_fx = 0; + hStereoClassif->non_sta_ch1_fx = 0; + hStereoClassif->sp_div_ch1_fx = 0; + hStereoClassif->ps_diff_ch1_fx = 0; + hStereoClassif->ps_diff_ch2_fx = 0; + hStereoClassif->ps_sta_ch1_fx = 0; + hStereoClassif->ps_sta_ch2_fx = 0; + hStereoClassif->prev_g_IPD_fx = 1073741824; // Q31 + hStereoClassif->prev_IPD_fx = 0; + hStereoClassif->prev_ratio_m1_m2_fx = 0; + set_zero_fx( hStereoClassif->xtalk_score_buf_fx, XTALK_SCORE_BUF_LEN ); + hStereoClassif->ratio_L_fx = 1073741824; // Q31 + hStereoClassif->vad_flag_glob = 0; // Q31 + hStereoClassif->vad_relE = 0; // Q31 + hStereoClassif->is_speech_fx = 0; // Q31 + + set16_fx( hStereoClassif->aEn_raw, 0, CPE_CHANNELS ); + + hStereoClassif->Etot_dn_fx = 0; + hStereoClassif->Etot_up_fx = 0; + + set_zero_fx( hStereoClassif->relE_buf_fx, UNCLR_L_RELE ); + set_zero_fx( hStereoClassif->Etot_buf_fx, UNCLR_L_ETOT ); + set_zero_fx( hStereoClassif->unclr_relE_0_1_LT_fx, UNCLR_RC_ORDER ); + + hStereoClassif->unclr_sw_enable_cnt[0] = 0; + hStereoClassif->unclr_sw_enable_cnt[1] = 0; + + hStereoClassif->unclr_decision = 0; + hStereoClassif->unclr_wscore_fx = 0; + + set32_fx( hStereoClassif->unclr_fv_fx, -2147483647 - 1, SSC_MAX_NFEA ); // Q31 + hStereoClassif->unclr_corrLagMax_prev = 0; + hStereoClassif->ave_ener_L = 0; + hStereoClassif->ave_ener_R = 0; + hStereoClassif->relE_0_1_fx = 21474836; // Q31 + hStereoClassif->relE_0_1_LT_fx = 21474836; // Q31 + + set32_fx( hStereoClassif->xtalk_fv_fx, -2147483647 - 1, SSC_MAX_NFEA ); // Q31 + hStereoClassif->xtalk_wscore_fx = 0; + hStereoClassif->xtalk_decision = 0; + hStereoClassif->xtalk_score_wrelE_fx = 0; + + hStereoClassif->lrtd_mode = 0; + hStereoClassif->prev_lrtd_mode = 0; + + hStereoClassif->silence_flag = 0; + + return; } #endif /*-----------------------------------------------------------------* @@ -970,7 +969,6 @@ void xtalk_classifier_dft( } - /* rising edge detector on raw score -> yields 1 if strong rising edge is detected in the given buffer */ mvr2r( &hStereoClassif->xtalk_score_buf[0], &hStereoClassif->xtalk_score_buf[1], XTALK_SCORE_BUF_LEN - 1 ); hStereoClassif->xtalk_score_buf[0] = score; diff --git a/lib_enc/ivas_stereo_cng_enc.c b/lib_enc/ivas_stereo_cng_enc.c index 33c087e77..3763c8761 100644 --- a/lib_enc/ivas_stereo_cng_enc.c +++ b/lib_enc/ivas_stereo_cng_enc.c @@ -463,20 +463,20 @@ void stereo_enc_cng_init( hStereoCng->sg_average_counter = 0; set_zero( hStereoCng->sg_average, STEREO_DFT_BAND_MAX ); #ifdef IVAS_FLOAT_FIXED - set32_fx(hStereoCng->sg_average_fx, 0, STEREO_DFT_BAND_MAX); + set32_fx( hStereoCng->sg_average_fx, 0, STEREO_DFT_BAND_MAX ); #endif hStereoCng->prev_sg_average_counter = 0; set_zero( hStereoCng->prev_sg_average, STEREO_DFT_BAND_MAX ); #ifdef IVAS_FLOAT_FIXED - set32_fx(hStereoCng->prev_sg_average_fx, 0, STEREO_DFT_BAND_MAX); + set32_fx( hStereoCng->prev_sg_average_fx, 0, STEREO_DFT_BAND_MAX ); #endif hStereoCng->sg_active_cnt = 0; hStereoCng->first_SID = 1; set_f( hStereoCng->mem_cohBand, 0.5f, STEREO_DFT_BAND_MAX / 2 ); /*Q31*/ set_zero( hStereoCng->prev_cohBand, 2 * ( STEREO_DFT_BAND_MAX / 2 ) ); #ifdef IVAS_FLOAT_FIXED - set32_fx(hStereoCng->mem_cohBand_fx, ONE_IN_Q30, STEREO_DFT_BAND_MAX / 2); - set32_fx(hStereoCng->prev_cohBand_fx, 0, 2 * (STEREO_DFT_BAND_MAX / 2)); + set32_fx( hStereoCng->mem_cohBand_fx, ONE_IN_Q30, STEREO_DFT_BAND_MAX / 2 ); + set32_fx( hStereoCng->prev_cohBand_fx, 0, 2 * ( STEREO_DFT_BAND_MAX / 2 ) ); #endif hStereoCng->td_active = 0; hStereoCng->first_SID_after_TD = 1; diff --git a/lib_enc/ivas_stereo_dft_enc.c b/lib_enc/ivas_stereo_dft_enc.c index 0b919e3b0..e25bc7d5e 100644 --- a/lib_enc/ivas_stereo_dft_enc.c +++ b/lib_enc/ivas_stereo_dft_enc.c @@ -294,46 +294,46 @@ ivas_error stereo_dft_enc_create( } #ifdef IVAS_FLOAT_FIXED ivas_error stereo_dft_enc_create_fx( - STEREO_DFT_ENC_DATA_HANDLE *hStereoDft, /* i/o: encoder DFT stereo handle */ - const Word32 input_Fs, /* i : input sampling rate */ - const Word16 max_bwidth /* i : maximum encoded bandwidth */ + STEREO_DFT_ENC_DATA_HANDLE *hStereoDft, /* i/o: encoder DFT stereo handle */ + const Word32 input_Fs, /* i : input sampling rate */ + const Word16 max_bwidth /* i : maximum encoded bandwidth */ ) { - STEREO_DFT_ENC_DATA_HANDLE hStereoDft_loc; - Word16 tmpS; + STEREO_DFT_ENC_DATA_HANDLE hStereoDft_loc; + Word16 tmpS; - IF (*hStereoDft != NULL) - { - return IVAS_ERROR(IVAS_ERR_INTERNAL_FATAL, "Error: DFT Stereo memory already allocated\n"); - } + IF( *hStereoDft != NULL ) + { + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error: DFT Stereo memory already allocated\n" ); + } - IF ((hStereoDft_loc = (STEREO_DFT_ENC_DATA_HANDLE)malloc(sizeof(STEREO_DFT_ENC_DATA))) == NULL) - { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DFT Stereo\n")); - } + IF( ( hStereoDft_loc = (STEREO_DFT_ENC_DATA_HANDLE) malloc( sizeof( STEREO_DFT_ENC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DFT Stereo\n" ) ); + } - IF ((hStereoDft_loc->hConfig = (STEREO_DFT_CONFIG_DATA_HANDLE)malloc(sizeof(STEREO_DFT_CONFIG_DATA))) == NULL) - { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DFT Stereo Config\n")); - } + IF( ( hStereoDft_loc->hConfig = (STEREO_DFT_CONFIG_DATA_HANDLE) malloc( sizeof( STEREO_DFT_CONFIG_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DFT Stereo Config\n" ) ); + } - IF ((hStereoDft_loc->hItd = (ITD_DATA_HANDLE)malloc(sizeof(ITD_DATA))) == NULL) - { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ITD data\n")); - } + IF( ( hStereoDft_loc->hItd = (ITD_DATA_HANDLE) malloc( sizeof( ITD_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ITD data\n" ) ); + } - hStereoDft_loc->hConfig->force_mono_transmission = 0; + hStereoDft_loc->hConfig->force_mono_transmission = 0; - stereo_dft_config_fx(hStereoDft_loc->hConfig, IVAS_24k4, &tmpS, &tmpS); + stereo_dft_config_fx( hStereoDft_loc->hConfig, IVAS_24k4, &tmpS, &tmpS ); - stereo_dft_enc_open_fx(hStereoDft_loc, input_Fs, max_bwidth); + stereo_dft_enc_open_fx( hStereoDft_loc, input_Fs, max_bwidth ); - stereo_dft_hybrid_ITD_flag(hStereoDft_loc->hConfig, input_Fs, - hStereoDft_loc->hItd->hybrid_itd_max); + stereo_dft_hybrid_ITD_flag( hStereoDft_loc->hConfig, input_Fs, + hStereoDft_loc->hItd->hybrid_itd_max ); - *hStereoDft = hStereoDft_loc; + *hStereoDft = hStereoDft_loc; - return IVAS_ERR_OK; + return IVAS_ERR_OK; } #endif /*------------------------------------------------------------------------- @@ -439,117 +439,117 @@ static void stereo_dft_enc_open( } #ifdef IVAS_FLOAT_FIXED static void stereo_dft_enc_open_fx( - STEREO_DFT_ENC_DATA_HANDLE hStereoDft, /* i/o: encoder DFT stereo handle */ - const Word32 input_Fs, /* i : input sampling rate */ - const Word16 max_bwidth /* i : maximum encoded bandwidth */ + STEREO_DFT_ENC_DATA_HANDLE hStereoDft, /* i/o: encoder DFT stereo handle */ + const Word32 input_Fs, /* i : input sampling rate */ + const Word16 max_bwidth /* i : maximum encoded bandwidth */ ) { - Word16 NFFT_inner; - PWord16 win_p[STEREO_DFT_OVL_MAX]; - Word16 win[STEREO_DFT_OVL_MAX]; - - /*Sizes*/ - Word16 div_e; - Word16 input_Fs_48k = BASOP_Util_Divide3232_Scale(input_Fs, 48000, &div_e); - - //input_Fs_48k = shr(input_Fs_48k, sub(15, div_e)); - - hStereoDft->N = i_mult(STEREO_DFT_HOP_MAX_ENC, input_Fs_48k);//e = div_e - assert(((input_Fs / FRAMES_PER_SEC) / hStereoDft->N) == 1); - - /*Init. DFT sizes*/ - hStereoDft->NFFT = i_mult(STEREO_DFT_N_MAX_ENC, input_Fs_48k);//e = div_e - hStereoDft->dft_ovl = i_mult(STEREO_DFT_OVL_MAX, input_Fs_48k);//e = div_e - mdct_window_sine_IVAS_updated(win_p, input_Fs, hStereoDft->dft_ovl, FULL_OVERLAP, IVAS_CPE_DFT);//win_e = 15 - FOR (Word16 i = 0; i < shr(STEREO_DFT_OVL_MAX, 1); i++) - { - win[STEREO_DFT_OVL_MAX - 1 - i] = win_p[i].v.re; - win[i] = win_p[i].v.im; - } - hStereoDft->win_ana_energy_fx = sub(hStereoDft->N, hStereoDft->dft_ovl); //e = div_e - hStereoDft->win_ana_energy_fx = shr(hStereoDft->win_ana_energy_fx, sub(15, div_e));//Q = 15 - - hStereoDft->win_ana_energy_fx = add(hStereoDft->win_ana_energy_fx, shl(sum_s(win, hStereoDft->dft_ovl), 1));//Q = 15 - hStereoDft->win_ana_energy_fx = shr(hStereoDft->win_ana_energy_fx, 15); - hStereoDft->win_ana_energy_fx = div_s(hStereoDft->win_ana_energy_fx, hStereoDft->NFFT);//Q = 15 - - set32_fx(hStereoDft->output_mem_dmx_32k_fx, 0, STEREO_DFT_OVL_32k); - - hStereoDft->dft_zp = (int16_t)(STEREO_DFT_ZP_MAX_ENC * input_Fs / 48000); - - hStereoDft->dft_trigo_8k_fx = dft_trigo_32k_fx; - hStereoDft->dft_trigo_12k8_fx = dft_trigo_12k8_fx; - hStereoDft->dft_trigo_16k_fx = dft_trigo_32k_fx; - hStereoDft->dft_trigo_32k_fx = dft_trigo_32k_fx; - - hStereoDft->win_ana_8k_fx = win_ana_8k_fx; - hStereoDft->win_ana_12k8_fx = win_ana_12k8_fx; - hStereoDft->win_ana_16k_fx = win_ana_16k_fx; - hStereoDft->win_ana_32k_fx = win_ana_32k_fx; - - hStereoDft->win_8k_fx = win_syn_8k_fx; - hStereoDft->win_12k8_fx = win_syn_12k8_fx; - hStereoDft->win_16k_fx = win_syn_16k_fx; - hStereoDft->win_32k_fx = win_syn_32k_fx; - - IF (EQ_32(input_Fs, 16000)) - { - hStereoDft->dft_trigo_fx = dft_trigo_32k_fx; - hStereoDft->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_16k_STEP; - hStereoDft->win_ana_fx = win_ana_16k_fx; - hStereoDft->win_fx = win_syn_16k_fx; - } - ELSE IF (EQ_32(input_Fs, 32000)) - { - hStereoDft->dft_trigo_fx = dft_trigo_32k_fx; - hStereoDft->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_32k_STEP; - hStereoDft->win_ana_fx = win_ana_32k_fx; - hStereoDft->win_fx = win_syn_32k_fx; - } - ELSE - { - assert(EQ_32(input_Fs, 48000)); - hStereoDft->dft_trigo_fx = dft_trigo_48k_fx; - hStereoDft->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_48k_STEP; - hStereoDft->win_ana_fx = win_ana_48k_fx; - hStereoDft->win_fx = win_syn_48k_fx; - } - - hStereoDft->win_mdct_8k_fx = win_mdct_8k_fx; - - /*I/O Buffers*/ - set_zero_fx(hStereoDft->output_mem_dmx_fx, STEREO_DFT_OVL_MAX); - set_zero_fx(hStereoDft->output_mem_dmx_12k8_fx, STEREO_DFT_OVL_12k8); - set_zero_fx(hStereoDft->output_mem_dmx_16k_fx, STEREO_DFT_OVL_16k); - set_zero_fx(hStereoDft->output_mem_dmx_16k_shb_fx, STEREO_DFT_OVL_16k); - set_zero_fx(hStereoDft->output_mem_res_8k_fx, STEREO_DFT_OVL_8k); - - /*Bands: find the number of bands, Nyquist freq. is not taken into account*/ - - Word16 inner_frame_tbl_L_frame = BASOP_Util_Divide1616_Scale(inner_frame_tbl[max_bwidth], L_FRAME48k, &div_e); - inner_frame_tbl_L_frame = shr(inner_frame_tbl_L_frame, sub(15, div_e)); - - NFFT_inner = i_mult(STEREO_DFT_N_MAX_ENC, inner_frame_tbl_L_frame); - hStereoDft->nbands = stereo_dft_band_config_fx(hStereoDft->band_limits, hStereoDft->hConfig->band_res, NFFT_inner, ENC); - hStereoDft->nbands_dmx = stereo_dft_band_config_fx(hStereoDft->band_limits_dmx, 1, NFFT_inner, ENC); - - /*Set configuration*/ - set16_fx(hStereoDft->band_res, hStereoDft->hConfig->band_res, STEREO_DFT_ENC_DFT_NB); - IF (hStereoDft->hConfig->ada_wb_res_cod_mode && EQ_16(hStereoDft->NFFT, STEREO_DFT_N_16k_ENC)) - { - /* residual coding is only applied for 16 kHz sampling rate */ - set16_fx(hStereoDft->res_cod_mode, hStereoDft->hConfig->ada_wb_res_cod_mode, STEREO_DFT_ENC_DFT_NB); - } - ELSE - { - set16_fx(hStereoDft->res_cod_mode, hStereoDft->hConfig->res_cod_mode, STEREO_DFT_ENC_DFT_NB); - } - set16_fx(hStereoDft->res_pred_mode, hStereoDft->hConfig->res_pred_mode, STEREO_DFT_ENC_DFT_NB); - - /* reset DFT stereo memories */ - stereo_dft_enc_reset_fx(hStereoDft); - - return; + Word16 NFFT_inner; + PWord16 win_p[STEREO_DFT_OVL_MAX]; + Word16 win[STEREO_DFT_OVL_MAX]; + + /*Sizes*/ + Word16 div_e; + Word16 input_Fs_48k = BASOP_Util_Divide3232_Scale( input_Fs, 48000, &div_e ); + + // input_Fs_48k = shr(input_Fs_48k, sub(15, div_e)); + + hStereoDft->N = i_mult( STEREO_DFT_HOP_MAX_ENC, input_Fs_48k ); // e = div_e + assert( ( ( input_Fs / FRAMES_PER_SEC ) / hStereoDft->N ) == 1 ); + + /*Init. DFT sizes*/ + hStereoDft->NFFT = i_mult( STEREO_DFT_N_MAX_ENC, input_Fs_48k ); // e = div_e + hStereoDft->dft_ovl = i_mult( STEREO_DFT_OVL_MAX, input_Fs_48k ); // e = div_e + mdct_window_sine_IVAS_updated( win_p, input_Fs, hStereoDft->dft_ovl, FULL_OVERLAP, IVAS_CPE_DFT ); // win_e = 15 + FOR( Word16 i = 0; i < shr( STEREO_DFT_OVL_MAX, 1 ); i++ ) + { + win[STEREO_DFT_OVL_MAX - 1 - i] = win_p[i].v.re; + win[i] = win_p[i].v.im; + } + hStereoDft->win_ana_energy_fx = sub( hStereoDft->N, hStereoDft->dft_ovl ); // e = div_e + hStereoDft->win_ana_energy_fx = shr( hStereoDft->win_ana_energy_fx, sub( 15, div_e ) ); // Q = 15 + + hStereoDft->win_ana_energy_fx = add( hStereoDft->win_ana_energy_fx, shl( sum_s( win, hStereoDft->dft_ovl ), 1 ) ); // Q = 15 + hStereoDft->win_ana_energy_fx = shr( hStereoDft->win_ana_energy_fx, 15 ); + hStereoDft->win_ana_energy_fx = div_s( hStereoDft->win_ana_energy_fx, hStereoDft->NFFT ); // Q = 15 + + set32_fx( hStereoDft->output_mem_dmx_32k_fx, 0, STEREO_DFT_OVL_32k ); + + hStereoDft->dft_zp = (int16_t) ( STEREO_DFT_ZP_MAX_ENC * input_Fs / 48000 ); + + hStereoDft->dft_trigo_8k_fx = dft_trigo_32k_fx; + hStereoDft->dft_trigo_12k8_fx = dft_trigo_12k8_fx; + hStereoDft->dft_trigo_16k_fx = dft_trigo_32k_fx; + hStereoDft->dft_trigo_32k_fx = dft_trigo_32k_fx; + + hStereoDft->win_ana_8k_fx = win_ana_8k_fx; + hStereoDft->win_ana_12k8_fx = win_ana_12k8_fx; + hStereoDft->win_ana_16k_fx = win_ana_16k_fx; + hStereoDft->win_ana_32k_fx = win_ana_32k_fx; + + hStereoDft->win_8k_fx = win_syn_8k_fx; + hStereoDft->win_12k8_fx = win_syn_12k8_fx; + hStereoDft->win_16k_fx = win_syn_16k_fx; + hStereoDft->win_32k_fx = win_syn_32k_fx; + + IF( EQ_32( input_Fs, 16000 ) ) + { + hStereoDft->dft_trigo_fx = dft_trigo_32k_fx; + hStereoDft->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_16k_STEP; + hStereoDft->win_ana_fx = win_ana_16k_fx; + hStereoDft->win_fx = win_syn_16k_fx; + } + ELSE IF( EQ_32( input_Fs, 32000 ) ) + { + hStereoDft->dft_trigo_fx = dft_trigo_32k_fx; + hStereoDft->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_32k_STEP; + hStereoDft->win_ana_fx = win_ana_32k_fx; + hStereoDft->win_fx = win_syn_32k_fx; + } + ELSE + { + assert( EQ_32( input_Fs, 48000 ) ); + hStereoDft->dft_trigo_fx = dft_trigo_48k_fx; + hStereoDft->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_48k_STEP; + hStereoDft->win_ana_fx = win_ana_48k_fx; + hStereoDft->win_fx = win_syn_48k_fx; + } + + hStereoDft->win_mdct_8k_fx = win_mdct_8k_fx; + + /*I/O Buffers*/ + set_zero_fx( hStereoDft->output_mem_dmx_fx, STEREO_DFT_OVL_MAX ); + set_zero_fx( hStereoDft->output_mem_dmx_12k8_fx, STEREO_DFT_OVL_12k8 ); + set_zero_fx( hStereoDft->output_mem_dmx_16k_fx, STEREO_DFT_OVL_16k ); + set_zero_fx( hStereoDft->output_mem_dmx_16k_shb_fx, STEREO_DFT_OVL_16k ); + set_zero_fx( hStereoDft->output_mem_res_8k_fx, STEREO_DFT_OVL_8k ); + + /*Bands: find the number of bands, Nyquist freq. is not taken into account*/ + + Word16 inner_frame_tbl_L_frame = BASOP_Util_Divide1616_Scale( inner_frame_tbl[max_bwidth], L_FRAME48k, &div_e ); + inner_frame_tbl_L_frame = shr( inner_frame_tbl_L_frame, sub( 15, div_e ) ); + + NFFT_inner = i_mult( STEREO_DFT_N_MAX_ENC, inner_frame_tbl_L_frame ); + hStereoDft->nbands = stereo_dft_band_config_fx( hStereoDft->band_limits, hStereoDft->hConfig->band_res, NFFT_inner, ENC ); + hStereoDft->nbands_dmx = stereo_dft_band_config_fx( hStereoDft->band_limits_dmx, 1, NFFT_inner, ENC ); + + /*Set configuration*/ + set16_fx( hStereoDft->band_res, hStereoDft->hConfig->band_res, STEREO_DFT_ENC_DFT_NB ); + IF( hStereoDft->hConfig->ada_wb_res_cod_mode && EQ_16( hStereoDft->NFFT, STEREO_DFT_N_16k_ENC ) ) + { + /* residual coding is only applied for 16 kHz sampling rate */ + set16_fx( hStereoDft->res_cod_mode, hStereoDft->hConfig->ada_wb_res_cod_mode, STEREO_DFT_ENC_DFT_NB ); + } + ELSE + { + set16_fx( hStereoDft->res_cod_mode, hStereoDft->hConfig->res_cod_mode, STEREO_DFT_ENC_DFT_NB ); + } + set16_fx( hStereoDft->res_pred_mode, hStereoDft->hConfig->res_pred_mode, STEREO_DFT_ENC_DFT_NB ); + + /* reset DFT stereo memories */ + stereo_dft_enc_reset_fx( hStereoDft ); + + return; } #endif /*------------------------------------------------------------------------- @@ -661,105 +661,105 @@ void stereo_dft_enc_reset( } #ifdef IVAS_FLOAT_FIXED void stereo_dft_enc_reset_fx( - STEREO_DFT_ENC_DATA_HANDLE hStereoDft /* i/o: encoder stereo handle */ + STEREO_DFT_ENC_DATA_HANDLE hStereoDft /* i/o: encoder stereo handle */ ) { - Word16 i; - /*reset parameters*/ - set_zero_fx(hStereoDft->side_gain_fx, i_mult(STEREO_DFT_ENC_DFT_NB, STEREO_DFT_BAND_MAX)); - set16_fx(hStereoDft->side_gain_index_EC, 15, STEREO_DFT_BAND_MAX); - set16_fx(hStereoDft->side_gain_index_ECDiff, 0, STEREO_DFT_BAND_MAX); - set16_fx(hStereoDft->side_gain_index_ECprevious, 15, STEREO_DFT_BAND_MAX); - hStereoDft->side_gain_counter = 0; - hStereoDft->side_gain_bitdiff_lp_fx = STEREO_DFT_BITDIFF_INIT_FX; - set_zero_fx(hStereoDft->gipd_fx, STEREO_DFT_ENC_DFT_NB); - set_zero_fx(hStereoDft->dot_prod_real_smooth_fx, STEREO_DFT_BAND_MAX); - set_zero_fx(hStereoDft->dot_prod_img_smooth_fx, STEREO_DFT_BAND_MAX); - for (i = 0; i < STEREO_DFT_BAND_MAX; i++) - { - set_zero_fx(hStereoDft->ipd_buf_fx[i], STEREO_DFT_IPD_BUF_LEN); - } - hStereoDft->prev_gipd_fx = 0; - hStereoDft->gipd_index = 0; - set_zero_fx(hStereoDft->res_pred_gain_fx, i_mult(STEREO_DFT_ENC_DFT_NB, STEREO_DFT_BAND_MAX)); - set16_fx(hStereoDft->res_pred_index_EC, 0, STEREO_DFT_BAND_MAX); - set16_fx(hStereoDft->res_pred_index_ECDiff, 0, STEREO_DFT_BAND_MAX); - set16_fx(hStereoDft->res_pred_index_ECprevious, 0, STEREO_DFT_BAND_MAX); - hStereoDft->res_pred_counter = 0; - set_zero_fx(hStereoDft->past_nrgL_fx, i_mult(STEREO_DFT_NRG_PAST_LEN, STEREO_DFT_BAND_MAX)); - set_zero_fx(hStereoDft->past_nrgR_fx, i_mult(STEREO_DFT_NRG_PAST_LEN, STEREO_DFT_BAND_MAX)); - set_zero_fx(hStereoDft->past_dot_prod_real_fx, i_mult(STEREO_DFT_NRG_PAST_LEN, STEREO_DFT_BAND_MAX)); - set_zero_fx(hStereoDft->past_dot_prod_imag_fx, i_mult(STEREO_DFT_NRG_PAST_LEN, STEREO_DFT_BAND_MAX)); - hStereoDft->nrg_past_pos = 0; - - hStereoDft->res_dmx_ratio_lt_fx = MAX_32; - hStereoDft->hangover_cnt0 = 0; - hStereoDft->hangover_cnt1 = 0; - hStereoDft->dmx_res_all_prev_fx = 1; - hStereoDft->last_res_cod_mode_modify_flag = 0; - hStereoDft->res_cod_sw_flag = 0; - hStereoDft->switch_fade_factor_fx = ONE_IN_Q14; //Q15/2 - hStereoDft->res_cod_mode[STEREO_DFT_OFFSET - 1] = STEREO_DFT_RES_COD_1kHz; - FOR (i = 0; i < STEREO_DFT_BAND_MAX; i++) - { - hStereoDft->res_cod_NRG_M_fx[i] = 0; - hStereoDft->res_cod_NRG_S_fx[i] = 0; - } - hStereoDft->old_snr_fx = 0; - - - hStereoDft->reverb_flag = 0; - set_zero_fx(hStereoDft->pre_sub_nrg_DMX_fx, STEREO_DFT_BAND_MAX); - hStereoDft->diff_l_h_sm_fx = 0; - hStereoDft->diff_r_h_sm_fx = 0; - hStereoDft->prev_fac2_fx = MAX_32; - - set_zero_fx(hStereoDft->res_pred_gain_f_fx, STEREO_DFT_BAND_MAX); - - /*misc*/ - hStereoDft->no_ipd_flag = 1; /* Initialization of the no IPD variables */ - hStereoDft->prev_no_ipd_flag = 1; - hStereoDft->no_ipd_cnt = 0; - hStereoDft->no_ipd_cnt1 = 0; - hStereoDft->attackPresent = 0; - hStereoDft->wasTransient = 0; - hStereoDft->gainIPD_sm_fx = MAX_32; - - - hStereoDft->voicing_lt_fx = 0; - - hStereoDft->flip_sign = 1; - - hStereoDft->sfm_fx = 0; - hStereoDft->sum_dot_prod_real_fx = 0; - hStereoDft->sum_dot_prod_img_fx = 0; - - /*Coherence*/ - set32_fx(hStereoDft->xspec_smooth_fx, MAX_32, STEREO_DFT_N_32k_ENC); - set32_fx(hStereoDft->Spd_L_smooth_fx, MAX_32, shr(STEREO_DFT_N_32k_ENC, 1)); - set32_fx(hStereoDft->Spd_R_smooth_fx, MAX_32, shr(STEREO_DFT_N_32k_ENC, 1)); - - hStereoDft->currentNumUpdates = 0; - hStereoDft->expectedNumUpdates = FIXED_SID_RATE; - hStereoDft->resetFrames = 0; - hStereoDft->sid_gipd_fx = 0; - hStereoDft->prev_sid_gipd_fx = 0; - hStereoDft->prev_sid_no_ipd_flag = 1; - - hStereoDft->coh_fade_counter = 0; - - /* Xtalk classifier */ - hStereoDft->hItd->prev_m1_fx = 0; - hStereoDft->hItd->prev_m2_fx = 0; - hStereoDft->hItd->prev_itd1 = 0; - hStereoDft->hItd->prev_itd2 = 0; - - hStereoDft->first_frm_flag = 1; - - - stereo_enc_itd_init_fx(hStereoDft->hItd); - - return; + Word16 i; + /*reset parameters*/ + set_zero_fx( hStereoDft->side_gain_fx, i_mult( STEREO_DFT_ENC_DFT_NB, STEREO_DFT_BAND_MAX ) ); + set16_fx( hStereoDft->side_gain_index_EC, 15, STEREO_DFT_BAND_MAX ); + set16_fx( hStereoDft->side_gain_index_ECDiff, 0, STEREO_DFT_BAND_MAX ); + set16_fx( hStereoDft->side_gain_index_ECprevious, 15, STEREO_DFT_BAND_MAX ); + hStereoDft->side_gain_counter = 0; + hStereoDft->side_gain_bitdiff_lp_fx = STEREO_DFT_BITDIFF_INIT_FX; + set_zero_fx( hStereoDft->gipd_fx, STEREO_DFT_ENC_DFT_NB ); + set_zero_fx( hStereoDft->dot_prod_real_smooth_fx, STEREO_DFT_BAND_MAX ); + set_zero_fx( hStereoDft->dot_prod_img_smooth_fx, STEREO_DFT_BAND_MAX ); + for ( i = 0; i < STEREO_DFT_BAND_MAX; i++ ) + { + set_zero_fx( hStereoDft->ipd_buf_fx[i], STEREO_DFT_IPD_BUF_LEN ); + } + hStereoDft->prev_gipd_fx = 0; + hStereoDft->gipd_index = 0; + set_zero_fx( hStereoDft->res_pred_gain_fx, i_mult( STEREO_DFT_ENC_DFT_NB, STEREO_DFT_BAND_MAX ) ); + set16_fx( hStereoDft->res_pred_index_EC, 0, STEREO_DFT_BAND_MAX ); + set16_fx( hStereoDft->res_pred_index_ECDiff, 0, STEREO_DFT_BAND_MAX ); + set16_fx( hStereoDft->res_pred_index_ECprevious, 0, STEREO_DFT_BAND_MAX ); + hStereoDft->res_pred_counter = 0; + set_zero_fx( hStereoDft->past_nrgL_fx, i_mult( STEREO_DFT_NRG_PAST_LEN, STEREO_DFT_BAND_MAX ) ); + set_zero_fx( hStereoDft->past_nrgR_fx, i_mult( STEREO_DFT_NRG_PAST_LEN, STEREO_DFT_BAND_MAX ) ); + set_zero_fx( hStereoDft->past_dot_prod_real_fx, i_mult( STEREO_DFT_NRG_PAST_LEN, STEREO_DFT_BAND_MAX ) ); + set_zero_fx( hStereoDft->past_dot_prod_imag_fx, i_mult( STEREO_DFT_NRG_PAST_LEN, STEREO_DFT_BAND_MAX ) ); + hStereoDft->nrg_past_pos = 0; + + hStereoDft->res_dmx_ratio_lt_fx = MAX_32; + hStereoDft->hangover_cnt0 = 0; + hStereoDft->hangover_cnt1 = 0; + hStereoDft->dmx_res_all_prev_fx = 1; + hStereoDft->last_res_cod_mode_modify_flag = 0; + hStereoDft->res_cod_sw_flag = 0; + hStereoDft->switch_fade_factor_fx = ONE_IN_Q14; // Q15/2 + hStereoDft->res_cod_mode[STEREO_DFT_OFFSET - 1] = STEREO_DFT_RES_COD_1kHz; + FOR( i = 0; i < STEREO_DFT_BAND_MAX; i++ ) + { + hStereoDft->res_cod_NRG_M_fx[i] = 0; + hStereoDft->res_cod_NRG_S_fx[i] = 0; + } + hStereoDft->old_snr_fx = 0; + + + hStereoDft->reverb_flag = 0; + set_zero_fx( hStereoDft->pre_sub_nrg_DMX_fx, STEREO_DFT_BAND_MAX ); + hStereoDft->diff_l_h_sm_fx = 0; + hStereoDft->diff_r_h_sm_fx = 0; + hStereoDft->prev_fac2_fx = MAX_32; + + set_zero_fx( hStereoDft->res_pred_gain_f_fx, STEREO_DFT_BAND_MAX ); + + /*misc*/ + hStereoDft->no_ipd_flag = 1; /* Initialization of the no IPD variables */ + hStereoDft->prev_no_ipd_flag = 1; + hStereoDft->no_ipd_cnt = 0; + hStereoDft->no_ipd_cnt1 = 0; + hStereoDft->attackPresent = 0; + hStereoDft->wasTransient = 0; + hStereoDft->gainIPD_sm_fx = MAX_32; + + + hStereoDft->voicing_lt_fx = 0; + + hStereoDft->flip_sign = 1; + + hStereoDft->sfm_fx = 0; + hStereoDft->sum_dot_prod_real_fx = 0; + hStereoDft->sum_dot_prod_img_fx = 0; + + /*Coherence*/ + set32_fx( hStereoDft->xspec_smooth_fx, MAX_32, STEREO_DFT_N_32k_ENC ); + set32_fx( hStereoDft->Spd_L_smooth_fx, MAX_32, shr( STEREO_DFT_N_32k_ENC, 1 ) ); + set32_fx( hStereoDft->Spd_R_smooth_fx, MAX_32, shr( STEREO_DFT_N_32k_ENC, 1 ) ); + + hStereoDft->currentNumUpdates = 0; + hStereoDft->expectedNumUpdates = FIXED_SID_RATE; + hStereoDft->resetFrames = 0; + hStereoDft->sid_gipd_fx = 0; + hStereoDft->prev_sid_gipd_fx = 0; + hStereoDft->prev_sid_no_ipd_flag = 1; + + hStereoDft->coh_fade_counter = 0; + + /* Xtalk classifier */ + hStereoDft->hItd->prev_m1_fx = 0; + hStereoDft->hItd->prev_m2_fx = 0; + hStereoDft->hItd->prev_itd1 = 0; + hStereoDft->hItd->prev_itd2 = 0; + + hStereoDft->first_frm_flag = 1; + + + stereo_enc_itd_init_fx( hStereoDft->hItd ); + + return; } #endif /*------------------------------------------------------------------------- @@ -812,46 +812,46 @@ void stereo_enc_itd_init( } void stereo_enc_itd_init_fx( - ITD_DATA_HANDLE hItd /* i/o: encoder ITD handle */ + ITD_DATA_HANDLE hItd /* i/o: encoder ITD handle */ ) { - hItd->prev_itd = 0; - set32_fx(hItd->itd_fx, 0, STEREO_DFT_ENC_DFT_NB); - set32_fx(hItd->deltaItd_fx, 0,STEREO_DFT_ENC_DFT_NB); - set16_fx(hItd->td_itd, 0, STEREO_DFT_ENC_DFT_NB); - set16_fx(hItd->td_itd_32k, 0, STEREO_DFT_ENC_DFT_NB); - set16_fx(hItd->itd_index, 0, STEREO_DFT_ENC_DFT_NB); - set32_fx(hItd->xcorr_smooth_fx, 0, STEREO_DFT_N_32k_ENC); - hItd->lp_phat_peak_fx = 0; - hItd->itd_hangover = 0; - hItd->itd_cnt = 0; - hItd->prev_sum_nrg_L_lb_fx = 0; - set32_fx(hItd->prev_xcorr_lb_fx, 0, STEREO_DFT_XCORR_LB_MAX); - set32_fx(hItd->E_band_n_fx, ITD_VAD_E_BAND_N_INIT, STEREO_DFT_ITD_VAD_BAND_NUM); - hItd->vad_frm_cnt = 0; - hItd->pre_vad = 0; - hItd->itd_nonzero_cnt = 0; - set32_fx(hItd->acorr_L_fx, 0, STEREO_DFT_BAND_MAX); - set32_fx(hItd->acorr_R_fx, 0, STEREO_DFT_BAND_MAX); - hItd->cohSNR_fx = 30720; /*Q11*/ - hItd->itd_thres_fx = 0; - hItd->valid_itd_cnt = 0; - - hItd->detected_itd_flag = 0; - hItd->itd_tracking = 0; - hItd->prev_max_fx = 0; - hItd->prev_index = 0; - hItd->prev_avg_max_fx = 0; - hItd->currFlatness_fx = 0; - - /* Xtalk classifier */ - hItd->prev_m1_fx = 0; - hItd->prev_m2_fx = 0; - hItd->prev_itd1 = 0; - hItd->prev_itd2 = 0; - - hItd->hybrid_itd_max = 0; - return; + hItd->prev_itd = 0; + set32_fx( hItd->itd_fx, 0, STEREO_DFT_ENC_DFT_NB ); + set32_fx( hItd->deltaItd_fx, 0, STEREO_DFT_ENC_DFT_NB ); + set16_fx( hItd->td_itd, 0, STEREO_DFT_ENC_DFT_NB ); + set16_fx( hItd->td_itd_32k, 0, STEREO_DFT_ENC_DFT_NB ); + set16_fx( hItd->itd_index, 0, STEREO_DFT_ENC_DFT_NB ); + set32_fx( hItd->xcorr_smooth_fx, 0, STEREO_DFT_N_32k_ENC ); + hItd->lp_phat_peak_fx = 0; + hItd->itd_hangover = 0; + hItd->itd_cnt = 0; + hItd->prev_sum_nrg_L_lb_fx = 0; + set32_fx( hItd->prev_xcorr_lb_fx, 0, STEREO_DFT_XCORR_LB_MAX ); + set32_fx( hItd->E_band_n_fx, ITD_VAD_E_BAND_N_INIT, STEREO_DFT_ITD_VAD_BAND_NUM ); + hItd->vad_frm_cnt = 0; + hItd->pre_vad = 0; + hItd->itd_nonzero_cnt = 0; + set32_fx( hItd->acorr_L_fx, 0, STEREO_DFT_BAND_MAX ); + set32_fx( hItd->acorr_R_fx, 0, STEREO_DFT_BAND_MAX ); + hItd->cohSNR_fx = 30720; /*Q11*/ + hItd->itd_thres_fx = 0; + hItd->valid_itd_cnt = 0; + + hItd->detected_itd_flag = 0; + hItd->itd_tracking = 0; + hItd->prev_max_fx = 0; + hItd->prev_index = 0; + hItd->prev_avg_max_fx = 0; + hItd->currFlatness_fx = 0; + + /* Xtalk classifier */ + hItd->prev_m1_fx = 0; + hItd->prev_m2_fx = 0; + hItd->prev_itd1 = 0; + hItd->prev_itd2 = 0; + + hItd->hybrid_itd_max = 0; + return; } /*-------------------------------------------------------------------------- @@ -936,13 +936,13 @@ void stereo_dft_enc_destroy( STEREO_DFT_ENC_DATA_HANDLE *hStereoDft /* i/o: encoder DFT stereo handle */ ) { - IF ( ( *hStereoDft )->hConfig != NULL ) + IF( ( *hStereoDft )->hConfig != NULL ) { free( ( *hStereoDft )->hConfig ); ( *hStereoDft )->hConfig = NULL; } - IF ( ( *hStereoDft )->hItd != NULL ) + IF( ( *hStereoDft )->hItd != NULL ) { free( ( *hStereoDft )->hItd ); ( *hStereoDft )->hItd = NULL; @@ -2356,7 +2356,6 @@ void stereo_dft_enc_write_BS( push_indice( hBstr, IND_STEREO_DFT_ITD_COD, itd, STEREO_DFT_SID_ITD_NBITS ); ( *nb_bits ) += STEREO_DFT_SID_ITD_NBITS + 1; } - } } } @@ -2458,7 +2457,6 @@ void stereo_dft_enc_write_BS( } } } - } else { diff --git a/lib_enc/ivas_stereo_dft_enc_itd.c b/lib_enc/ivas_stereo_dft_enc_itd.c index 77b46951e..e01e9b5ba 100644 --- a/lib_enc/ivas_stereo_dft_enc_itd.c +++ b/lib_enc/ivas_stereo_dft_enc_itd.c @@ -111,13 +111,13 @@ static void set_band_limits( void stereo_dft_hybrid_ITD_flag( STEREO_DFT_CONFIG_DATA_HANDLE hConfig, /* o : DFT stereo configuration */ - const Word32 input_Fs, /* i : CPE element sampling rate */ - const Word16 hybrid_itd_max /* i : flag for hybrid ITD for very large ITDs */ + const Word32 input_Fs, /* i : CPE element sampling rate */ + const Word16 hybrid_itd_max /* i : flag for hybrid ITD for very large ITDs */ ) { - IF ( hConfig != NULL ) + IF( hConfig != NULL ) { - IF ( hConfig->res_cod_mode || ( hConfig->ada_wb_res_cod_mode && EQ_32(input_Fs, 16000) ) || EQ_16( hybrid_itd_max, 1 ) ) + IF( hConfig->res_cod_mode || ( hConfig->ada_wb_res_cod_mode && EQ_32( input_Fs, 16000 ) ) || EQ_16( hybrid_itd_max, 1 ) ) { hConfig->hybrid_itd_flag = 1; } @@ -1059,7 +1059,6 @@ void stereo_dft_enc_compute_itd( hStereoClassif->unclr_fv[E_sum_xcorr] = sum_xcorr; hStereoClassif->xtalk_fv[E_sum_xcorr] = sum_xcorr; - } /* reset estimates when silence is detected*/ diff --git a/lib_enc/ivas_stereo_dft_td_itd.c b/lib_enc/ivas_stereo_dft_td_itd.c index 914d9771b..068883104 100644 --- a/lib_enc/ivas_stereo_dft_td_itd.c +++ b/lib_enc/ivas_stereo_dft_td_itd.c @@ -229,10 +229,10 @@ void stereo_td_itd( ITD_DATA *hITD, /* i/o: ITD data structure */ float input_mem_itd[CPE_CHANNELS][STEREO_DFT_OVL_MAX], /* o : ITD memory (only used in DFT Stereo) */ const int16_t hybrid_itd_flag, /* i : flag for hybrid TD/FD ITD processing */ - const int16_t dft_ovl, /* i : size of DFT overlap */ - Encoder_State **sts, /* i/o: Encoder state structure */ - const int16_t input_frame, /* i : input frame length */ - float *input_mem[CPE_CHANNELS] /* i/o: input buffer memory */ + const int16_t dft_ovl, /* i : size of DFT overlap */ + Encoder_State **sts, /* i/o: Encoder state structure */ + const int16_t input_frame, /* i : input frame length */ + float *input_mem[CPE_CHANNELS] /* i/o: input buffer memory */ ) { int16_t i, ch, n; @@ -274,7 +274,7 @@ void stereo_td_itd( } stereo_td_get_td_itd( &( hITD->td_itd[k_offset] ), &( hITD->td_itd_32k[k_offset] ), hITD->itd[k_offset], sts[0]->input_Fs ); -/* initializations*/ + /* initializations*/ { size_ovl = dft_ovl; diff --git a/lib_enc/ivas_stereo_dmx_evs.c b/lib_enc/ivas_stereo_dmx_evs.c index 9c7c0df66..4e21a5c5f 100644 --- a/lib_enc/ivas_stereo_dmx_evs.c +++ b/lib_enc/ivas_stereo_dmx_evs.c @@ -740,7 +740,7 @@ static float find_poc_peak( STEREO_DMX_EVS_POC_HANDLE hPOC, /* i/o: phase only correlation structure */ float itd[], /* o : estimated itd */ const int16_t input_frame, /* i : input frame length per channel */ - const float ratio_float /* i : adapting ratio */ + const float ratio_float /* i : adapting ratio */ ) { int16_t itd_cand[CPE_CHANNELS], i, n, cnt[CPE_CHANNELS], Lh, peak_range, *on, *itdLR, prev_off[CPE_CHANNELS]; @@ -977,7 +977,7 @@ static void calc_energy( const float src2[], /* i : Rch input signal */ float energy[], /* o : calculated energy */ const int16_t input_frame, /* i : input frame length per channel */ - const float ratio_float /* i : adapting ratio */ + const float ratio_float /* i : adapting ratio */ ) { float E, wnd, wnd_diff; diff --git a/lib_enc/ivas_stereo_ica_enc.c b/lib_enc/ivas_stereo_ica_enc.c index 3403edd73..428489882 100644 --- a/lib_enc/ivas_stereo_ica_enc.c +++ b/lib_enc/ivas_stereo_ica_enc.c @@ -1282,51 +1282,51 @@ void stereo_tca_init_enc( } void stereo_tca_init_enc_fx( - STEREO_TCA_ENC_HANDLE hStereoTCA, /* i/o: Stereo ICA handle */ - const Word32 input_Fs /* i : input sampling frequency */ + STEREO_TCA_ENC_HANDLE hStereoTCA, /* i/o: Stereo ICA handle */ + const Word32 input_Fs /* i : input sampling frequency */ ) { - Word16 div1; - Word16 div_e; - hStereoTCA->lMemRecalc = NS2SA(input_Fs, L_MEM_RECALC_NS); - div1 = BASOP_Util_Divide3232_Scale(L_mult(hStereoTCA->lMemRecalc, INT_FS_12k8), input_Fs, &div_e); - hStereoTCA->lMemRecalc_12k8 = shr(div1, sub(15, div_e)); - - div1 = BASOP_Util_Divide3232_Scale(L_mult(hStereoTCA->lMemRecalc, INT_FS_16k), input_Fs, &div_e); - hStereoTCA->lMemRecalc_16k = shr(div1, sub(15, div_e)); - - hStereoTCA->refChanIndx = L_CH_INDX; - hStereoTCA->prevRefChanIndx = L_CH_INDX; - - hStereoTCA->targetGain = MAX16B; //Q15 - hStereoTCA->prevTargetGain_fx = MAX16B;//Q15 - hStereoTCA->instTargetGain_fx = MAX16B;//Q15 - hStereoTCA->corrStatsSmoothFac_fx = 22937;//Q15 - - set16_fx(hStereoTCA->corrLagStats, 0, 3); - set16_fx(hStereoTCA->prevCorrLagStats, 0, 3); - - set32_fx(hStereoTCA->memChanL_fx, 0, add(L_MEM_RECALC_48K, L_MEM_RECALC_48k_SCH)); - set32_fx(hStereoTCA->memChanR_fx, 0, add(L_MEM_RECALC_48K, L_MEM_RECALC_48k_SCH)); - set32_fx(hStereoTCA->memChanL_DS_fx, 0, ADDED_MEM_DS); - set32_fx(hStereoTCA->memChanR_DS_fx, 0, ADDED_MEM_DS); - hStereoTCA->mem_tempF_fx = 0; - set32_fx(hStereoTCA->corrEstPrev_fx[0], 0, add(shl(L_NCSHIFT_DS, 1), 1)); - set32_fx(hStereoTCA->corrEstPrev_fx[1], 0, add(shl(L_NCSHIFT_DS, 1), 1)); - set32_fx(hStereoTCA->corrEstPrev_fx[2], 0, add(shl(L_NCSHIFT_DS, 1), 1)); - - set32_fx(hStereoTCA->corrEstLT_fx, 0, add(shl(L_NCSHIFT_DS, 1), 1)); - set32_fx(hStereoTCA->memdecim_fx, 0, 12); - hStereoTCA->ica_envVarLT_fx = 2097152000; //2000 in Q20 - - set32_fx(hStereoTCA->C_mem_fx, 0, add(shl(L_NCSHIFT_DS, 1), 1)); - hStereoTCA->E1_mem_fx = 0; - hStereoTCA->E2_mem_fx = 0; - set32_fx(hStereoTCA->delay_0_mem_fx, 0, MAX_DELAYREGLEN); - hStereoTCA->smooth_dist_reg_prv_corr_fx = MAX16B; //Q15 - hStereoTCA->LRTD_G_ATT_cnt = 1; - - return; + Word16 div1; + Word16 div_e; + hStereoTCA->lMemRecalc = NS2SA( input_Fs, L_MEM_RECALC_NS ); + div1 = BASOP_Util_Divide3232_Scale( L_mult( hStereoTCA->lMemRecalc, INT_FS_12k8 ), input_Fs, &div_e ); + hStereoTCA->lMemRecalc_12k8 = shr( div1, sub( 15, div_e ) ); + + div1 = BASOP_Util_Divide3232_Scale( L_mult( hStereoTCA->lMemRecalc, INT_FS_16k ), input_Fs, &div_e ); + hStereoTCA->lMemRecalc_16k = shr( div1, sub( 15, div_e ) ); + + hStereoTCA->refChanIndx = L_CH_INDX; + hStereoTCA->prevRefChanIndx = L_CH_INDX; + + hStereoTCA->targetGain = MAX16B; // Q15 + hStereoTCA->prevTargetGain_fx = MAX16B; // Q15 + hStereoTCA->instTargetGain_fx = MAX16B; // Q15 + hStereoTCA->corrStatsSmoothFac_fx = 22937; // Q15 + + set16_fx( hStereoTCA->corrLagStats, 0, 3 ); + set16_fx( hStereoTCA->prevCorrLagStats, 0, 3 ); + + set32_fx( hStereoTCA->memChanL_fx, 0, add( L_MEM_RECALC_48K, L_MEM_RECALC_48k_SCH ) ); + set32_fx( hStereoTCA->memChanR_fx, 0, add( L_MEM_RECALC_48K, L_MEM_RECALC_48k_SCH ) ); + set32_fx( hStereoTCA->memChanL_DS_fx, 0, ADDED_MEM_DS ); + set32_fx( hStereoTCA->memChanR_DS_fx, 0, ADDED_MEM_DS ); + hStereoTCA->mem_tempF_fx = 0; + set32_fx( hStereoTCA->corrEstPrev_fx[0], 0, add( shl( L_NCSHIFT_DS, 1 ), 1 ) ); + set32_fx( hStereoTCA->corrEstPrev_fx[1], 0, add( shl( L_NCSHIFT_DS, 1 ), 1 ) ); + set32_fx( hStereoTCA->corrEstPrev_fx[2], 0, add( shl( L_NCSHIFT_DS, 1 ), 1 ) ); + + set32_fx( hStereoTCA->corrEstLT_fx, 0, add( shl( L_NCSHIFT_DS, 1 ), 1 ) ); + set32_fx( hStereoTCA->memdecim_fx, 0, 12 ); + hStereoTCA->ica_envVarLT_fx = 2097152000; // 2000 in Q20 + + set32_fx( hStereoTCA->C_mem_fx, 0, add( shl( L_NCSHIFT_DS, 1 ), 1 ) ); + hStereoTCA->E1_mem_fx = 0; + hStereoTCA->E2_mem_fx = 0; + set32_fx( hStereoTCA->delay_0_mem_fx, 0, MAX_DELAYREGLEN ); + hStereoTCA->smooth_dist_reg_prv_corr_fx = MAX16B; // Q15 + hStereoTCA->LRTD_G_ATT_cnt = 1; + + return; } /*-------------------------------------------------------------------* * Function unclr_calc_corr_features() diff --git a/lib_enc/ivas_stereo_icbwe_enc.c b/lib_enc/ivas_stereo_icbwe_enc.c index 5563c3765..d762468aa 100644 --- a/lib_enc/ivas_stereo_icbwe_enc.c +++ b/lib_enc/ivas_stereo_icbwe_enc.c @@ -622,52 +622,52 @@ void stereo_icBWE_init_enc( } void stereo_icBWE_init_enc_fx( - STEREO_ICBWE_ENC_HANDLE hStereoICBWE /* i/o: Stereo inter-channel BWE handle */ + STEREO_ICBWE_ENC_HANDLE hStereoICBWE /* i/o: Stereo inter-channel BWE handle */ ) { - /* SHB speech resampler memory */ - set32_fx(hStereoICBWE->mem_decim_shb_ch0_fx, 0, shl(L_FILT_MAX, 1)); + /* SHB speech resampler memory */ + set32_fx( hStereoICBWE->mem_decim_shb_ch0_fx, 0, shl( L_FILT_MAX, 1 ) ); - /* SHB ref channel */ - set32_fx(hStereoICBWE->mem_shb_speech_ref_fx, 0, L_LOOK_16k); + /* SHB ref channel */ + set32_fx( hStereoICBWE->mem_shb_speech_ref_fx, 0, L_LOOK_16k ); - /* SHB non-ref channel */ - set32_fx(hStereoICBWE->mem_shb_speech_nonref_fx, 0, L_LOOK_16k); + /* SHB non-ref channel */ + set32_fx( hStereoICBWE->mem_shb_speech_nonref_fx, 0, L_LOOK_16k ); - /* unscaled & scaled SHB synthesis memory */ - set32_fx(hStereoICBWE->mem_lpc_shbsynth_nonref_fx, 0, LPC_SHB_ORDER); + /* unscaled & scaled SHB synthesis memory */ + set32_fx( hStereoICBWE->mem_lpc_shbsynth_nonref_fx, 0, LPC_SHB_ORDER ); - /* inter-channel BWE spectral shape adj. */ - hStereoICBWE->prevSpecMapping_fx = 0; - hStereoICBWE->prevgsMapping_fx = MAX_32; //Q31 - set32_fx(&(hStereoICBWE->memShbSpecMapping_fx), 0, 1); - set32_fx(hStereoICBWE->memShbSpecXcorr_fx, 0, 6); + /* inter-channel BWE spectral shape adj. */ + hStereoICBWE->prevSpecMapping_fx = 0; + hStereoICBWE->prevgsMapping_fx = MAX_32; // Q31 + set32_fx( &( hStereoICBWE->memShbSpecMapping_fx ), 0, 1 ); + set32_fx( hStereoICBWE->memShbSpecXcorr_fx, 0, 6 ); - hStereoICBWE->prevNonRefEner_fx = MAX_32; //Q31 - hStereoICBWE->prevRefEner_fx = MAX_32; //Q31 + hStereoICBWE->prevNonRefEner_fx = MAX_32; // Q31 + hStereoICBWE->prevRefEner_fx = MAX_32; // Q31 - set32_fx(hStereoICBWE->memGsEnerMap_fx, MAX_32, 2); //Q31 + set32_fx( hStereoICBWE->memGsEnerMap_fx, MAX_32, 2 ); // Q31 - set32_fx(hStereoICBWE->dec_2over3_mem_fx, 0, L_FILT_2OVER3); - set32_fx(hStereoICBWE->dec_2over3_mem_lp_fx, 0, L_FILT_2OVER3_LP); - set32_fx(hStereoICBWE->memHPF_fx, 0, 8); + set32_fx( hStereoICBWE->dec_2over3_mem_fx, 0, L_FILT_2OVER3 ); + set32_fx( hStereoICBWE->dec_2over3_mem_lp_fx, 0, L_FILT_2OVER3_LP ); + set32_fx( hStereoICBWE->memHPF_fx, 0, 8 ); - /* BWE ref channel */ - hStereoICBWE->refChanIndx_bwe = L_CH_INDX; - hStereoICBWE->prev_refChanIndx_bwe = L_CH_INDX; + /* BWE ref channel */ + hStereoICBWE->refChanIndx_bwe = L_CH_INDX; + hStereoICBWE->prev_refChanIndx_bwe = L_CH_INDX; - set32_fx(hStereoICBWE->memModifyFs_icbwe_fx[0], 0, shl(L_FILT32k, 1)); - set32_fx(hStereoICBWE->memModifyFs_icbwe_fx[1], 0, shl(L_FILT32k, 1)); + set32_fx( hStereoICBWE->memModifyFs_icbwe_fx[0], 0, shl( L_FILT32k, 1 ) ); + set32_fx( hStereoICBWE->memModifyFs_icbwe_fx[1], 0, shl( L_FILT32k, 1 ) ); - set32_fx(hStereoICBWE->mem_nrg_L_fx, 0, 2); - set32_fx(hStereoICBWE->mem_nrg_R_fx, 0, 2); - set32_fx(hStereoICBWE->mem_nrg_DMX_fx, 0, 2); - hStereoICBWE->gDes_pastFrame_fx = MAX_32; //Q31 - hStereoICBWE->icbweRefEner_fx = 0; + set32_fx( hStereoICBWE->mem_nrg_L_fx, 0, 2 ); + set32_fx( hStereoICBWE->mem_nrg_R_fx, 0, 2 ); + set32_fx( hStereoICBWE->mem_nrg_DMX_fx, 0, 2 ); + hStereoICBWE->gDes_pastFrame_fx = MAX_32; // Q31 + hStereoICBWE->icbweRefEner_fx = 0; - hStereoICBWE->MSFlag = 0; + hStereoICBWE->MSFlag = 0; - return; + return; } /*-------------------------------------------------------------------* * findRefChanBWE() diff --git a/lib_enc/ivas_stereo_mdct_core_enc.c b/lib_enc/ivas_stereo_mdct_core_enc.c index ef4ddbb91..3c4b324c4 100644 --- a/lib_enc/ivas_stereo_mdct_core_enc.c +++ b/lib_enc/ivas_stereo_mdct_core_enc.c @@ -168,7 +168,7 @@ void stereo_mdct_core_enc( *---------------------------------------------------------------*/ sts[0]->hTcxEnc->tfm_mem = sts[1]->hTcxEnc->tfm_mem = sqrtf( 0.5f * ( sts[0]->hTcxEnc->tfm_mem * sts[0]->hTcxEnc->tfm_mem + sts[1]->hTcxEnc->tfm_mem * sts[1]->hTcxEnc->tfm_mem ) ); /* RMS */ - sts[0]->hTcxEnc->tcxltp_norm_corr_past_flt = sts[1]->hTcxEnc->tcxltp_norm_corr_past_flt = 0.5f * ( sts[0]->hTcxEnc->tcxltp_norm_corr_past_flt + sts[1]->hTcxEnc->tcxltp_norm_corr_past_flt); + sts[0]->hTcxEnc->tcxltp_norm_corr_past_flt = sts[1]->hTcxEnc->tcxltp_norm_corr_past_flt = 0.5f * ( sts[0]->hTcxEnc->tcxltp_norm_corr_past_flt + sts[1]->hTcxEnc->tcxltp_norm_corr_past_flt ); for ( ch = 0; ch < CPE_CHANNELS; ch++ ) { diff --git a/lib_enc/ivas_stereo_mdct_stereo_enc.c b/lib_enc/ivas_stereo_mdct_stereo_enc.c index d1196f445..9ea4b937a 100644 --- a/lib_enc/ivas_stereo_mdct_stereo_enc.c +++ b/lib_enc/ivas_stereo_mdct_stereo_enc.c @@ -110,43 +110,43 @@ static void dft_ana_init( } static void dft_ana_init_fx( - DFT_ANA_HANDLE hDft_ana, /*i : DFT analysis handle */ - const Word32 input_Fs /*i : Input sampling frequency */ + DFT_ANA_HANDLE hDft_ana, /*i : DFT analysis handle */ + const Word32 input_Fs /*i : Input sampling frequency */ ) { - Word16 div1; - Word16 div_e; - div1 = BASOP_Util_Divide3232_Scale(input_Fs, 48000, &div_e); - div1 = shr(div1, sub(15, div_e)); - - hDft_ana->N = i_mult(STEREO_DFT_HOP_MAX_ENC, div1); - hDft_ana->NFFT = i_mult(STEREO_DFT_N_MAX_ENC, div1); - hDft_ana->dft_ovl = i_mult(STEREO_DFT_OVL_MAX, div1); - hDft_ana->dft_zp = i_mult(STEREO_DFT_ZP_MAX_ENC, div1); - - hDft_ana->dft_trigo_32k_fx = dft_trigo_32k_fx; - - IF (EQ_32(input_Fs, 16000)) - { - hDft_ana->dft_trigo_fx = dft_trigo_32k_fx; - hDft_ana->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_16k_STEP; - hDft_ana->win_ana_fx = win_ana_16k_fx; - } - ELSE IF (EQ_32(input_Fs, 32000)) - { - hDft_ana->dft_trigo_fx = dft_trigo_32k_fx; - hDft_ana->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_32k_STEP; - hDft_ana->win_ana_fx = win_ana_32k_fx; - } - ELSE - { - assert(EQ_32(input_Fs, 48000)); - hDft_ana->dft_trigo_fx = dft_trigo_48k_fx; - hDft_ana->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_48k_STEP; - hDft_ana->win_ana_fx = win_ana_48k_fx; - } - - return; + Word16 div1; + Word16 div_e; + div1 = BASOP_Util_Divide3232_Scale( input_Fs, 48000, &div_e ); + div1 = shr( div1, sub( 15, div_e ) ); + + hDft_ana->N = i_mult( STEREO_DFT_HOP_MAX_ENC, div1 ); + hDft_ana->NFFT = i_mult( STEREO_DFT_N_MAX_ENC, div1 ); + hDft_ana->dft_ovl = i_mult( STEREO_DFT_OVL_MAX, div1 ); + hDft_ana->dft_zp = i_mult( STEREO_DFT_ZP_MAX_ENC, div1 ); + + hDft_ana->dft_trigo_32k_fx = dft_trigo_32k_fx; + + IF( EQ_32( input_Fs, 16000 ) ) + { + hDft_ana->dft_trigo_fx = dft_trigo_32k_fx; + hDft_ana->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_16k_STEP; + hDft_ana->win_ana_fx = win_ana_16k_fx; + } + ELSE IF( EQ_32( input_Fs, 32000 ) ) + { + hDft_ana->dft_trigo_fx = dft_trigo_32k_fx; + hDft_ana->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_32k_STEP; + hDft_ana->win_ana_fx = win_ana_32k_fx; + } + ELSE + { + assert( EQ_32( input_Fs, 48000 ) ); + hDft_ana->dft_trigo_fx = dft_trigo_48k_fx; + hDft_ana->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_48k_STEP; + hDft_ana->win_ana_fx = win_ana_48k_fx; + } + + return; } /*-------------------------------------------------------------------* @@ -392,7 +392,6 @@ void stereo_coder_tcx( } } } /* for k */ - } /* for bitrate switching determine correlation depending on m/s decision */ { @@ -1093,62 +1092,62 @@ void initMdctStereoEncData( } #ifdef IVAS_FLOAT_FIXED void initMdctStereoEncData_fx( - STEREO_MDCT_ENC_DATA *hStereoMdct, /* i/o: mdct stereo parameters structure */ - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const Word16 element_mode, /* i : element mode */ - const Word32 element_brate, /* i : element bitrate */ - const Word16 bwidth, /* i : bandwidth */ - const Word16 igf, /* i : flag indicating IGF activity */ - const H_IGF_GRID hIgfGrid, /* i : IGF grid setup */ - const Word16 mem_init /* i : initialize memory after malloc */ + STEREO_MDCT_ENC_DATA *hStereoMdct, /* i/o: mdct stereo parameters structure */ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const Word16 element_mode, /* i : element mode */ + const Word32 element_brate, /* i : element bitrate */ + const Word16 bwidth, /* i : bandwidth */ + const Word16 igf, /* i : flag indicating IGF activity */ + const H_IGF_GRID hIgfGrid, /* i : IGF grid setup */ + const Word16 mem_init /* i : initialize memory after malloc */ ) { - Word16 tcx_coded_lines; + Word16 tcx_coded_lines; - tcx_coded_lines = getNumTcxCodedLines(bwidth); - - /*initialize mdct stereo mode*/ - set16_fx(hStereoMdct->mdct_stereo_mode, -1, 2); + tcx_coded_lines = getNumTcxCodedLines( bwidth ); - /*Initialize sfb parameteres for TCX20 */ - stereo_mdct_init_bands_fx(tcx_coded_lines, TCX_20_CORE, element_brate, igf, igf ? &hIgfGrid[IGF_GRID_LB_NORM] : NULL, &hStereoMdct->stbParamsTCX20.sfbOffset[0], &hStereoMdct->stbParamsTCX20.sfbCnt); + /*initialize mdct stereo mode*/ + set16_fx( hStereoMdct->mdct_stereo_mode, -1, 2 ); - /*Initialize sfb parameteres for TCX10 */ - stereo_mdct_init_bands_fx(tcx_coded_lines, TCX_10_CORE, element_brate, igf, igf ? &hIgfGrid[IGF_GRID_LB_SHORT] : NULL, - &hStereoMdct->stbParamsTCX10.sfbOffset[0], &hStereoMdct->stbParamsTCX10.sfbCnt); + /*Initialize sfb parameteres for TCX20 */ + stereo_mdct_init_bands_fx( tcx_coded_lines, TCX_20_CORE, element_brate, igf, igf ? &hIgfGrid[IGF_GRID_LB_NORM] : NULL, &hStereoMdct->stbParamsTCX20.sfbOffset[0], &hStereoMdct->stbParamsTCX20.sfbCnt ); - /*Initialize sfb parameteres for transitions */ - stereo_mdct_init_bands_fx(tcx_coded_lines, -1, element_brate, igf, igf ? &hIgfGrid[IGF_GRID_LB_TRAN] : NULL, - &hStereoMdct->stbParamsTCX20afterACELP.sfbOffset[0], &hStereoMdct->stbParamsTCX20afterACELP.sfbCnt); + /*Initialize sfb parameteres for TCX10 */ + stereo_mdct_init_bands_fx( tcx_coded_lines, TCX_10_CORE, element_brate, igf, igf ? &hIgfGrid[IGF_GRID_LB_SHORT] : NULL, + &hStereoMdct->stbParamsTCX10.sfbOffset[0], &hStereoMdct->stbParamsTCX10.sfbCnt ); - set16_fx(hStereoMdct->IGFStereoMode, -1, 2); + /*Initialize sfb parameteres for transitions */ + stereo_mdct_init_bands_fx( tcx_coded_lines, -1, element_brate, igf, igf ? &hIgfGrid[IGF_GRID_LB_TRAN] : NULL, + &hStereoMdct->stbParamsTCX20afterACELP.sfbOffset[0], &hStereoMdct->stbParamsTCX20afterACELP.sfbCnt ); + set16_fx( hStereoMdct->IGFStereoMode, -1, 2 ); - hStereoMdct->split_ratio = SMDCT_EQUAL_RATIO_RANGE; - set16_fx(hStereoMdct->global_ild, shr(SMDCT_ILD_RANGE, 1), 2); - IF (mem_init) - { - hStereoMdct->hItd = NULL; - hStereoMdct->hDft_ana = NULL; - } + hStereoMdct->split_ratio = SMDCT_EQUAL_RATIO_RANGE; + set16_fx( hStereoMdct->global_ild, shr( SMDCT_ILD_RANGE, 1 ), 2 ); - IF (!(element_mode == IVAS_CPE_MDCT && element_brate <= MAX_MDCT_ITD_BRATE && ivas_format == STEREO_FORMAT)) - { - IF (hStereoMdct->hDft_ana != NULL) + IF( mem_init ) { - free(hStereoMdct->hDft_ana); - hStereoMdct->hDft_ana = NULL; + hStereoMdct->hItd = NULL; + hStereoMdct->hDft_ana = NULL; } - IF (hStereoMdct->hItd != NULL) + IF( !( element_mode == IVAS_CPE_MDCT && element_brate <= MAX_MDCT_ITD_BRATE && ivas_format == STEREO_FORMAT ) ) { - free(hStereoMdct->hItd); - hStereoMdct->hItd = NULL; + IF( hStereoMdct->hDft_ana != NULL ) + { + free( hStereoMdct->hDft_ana ); + hStereoMdct->hDft_ana = NULL; + } + + IF( hStereoMdct->hItd != NULL ) + { + free( hStereoMdct->hItd ); + hStereoMdct->hItd = NULL; + } } - } - return; + return; } #endif /*-----------------------------------------------------------------------* @@ -1189,20 +1188,20 @@ ivas_error initMdctItdHandling( ivas_error initMdctItdHandling_fx( STEREO_MDCT_ENC_DATA *hStereoMdct, /* i/o: mdct stereo parameters structure */ - const Word32 input_Fs /* i : input sampling rate */ + const Word32 input_Fs /* i : input sampling rate */ ) { - IF ( hStereoMdct->hItd == NULL ) + IF( hStereoMdct->hItd == NULL ) { - IF ( ( hStereoMdct->hItd = (ITD_DATA_HANDLE) malloc( sizeof( ITD_DATA ) ) ) == NULL ) + IF( ( hStereoMdct->hItd = (ITD_DATA_HANDLE) malloc( sizeof( ITD_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ITD data\n" ) ); } } - IF ( hStereoMdct->hDft_ana == NULL ) + IF( hStereoMdct->hDft_ana == NULL ) { - IF ( ( hStereoMdct->hDft_ana = (DFT_ANA_HANDLE) malloc( sizeof( DFT_ANA ) ) ) == NULL ) + IF( ( hStereoMdct->hDft_ana = (DFT_ANA_HANDLE) malloc( sizeof( DFT_ANA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ITD data\n" ) ); } diff --git a/lib_enc/ivas_stereo_switching_enc.c b/lib_enc/ivas_stereo_switching_enc.c index a2f713bd6..87e692f3b 100644 --- a/lib_enc/ivas_stereo_switching_enc.c +++ b/lib_enc/ivas_stereo_switching_enc.c @@ -578,7 +578,7 @@ ivas_error stereo_memory_enc( return error; } - initFdCngEnc( st->hFdCngEnc, st->input_Fs, st->cldfbAnaEnc->scale_flt); + initFdCngEnc( st->hFdCngEnc, st->input_Fs, st->cldfbAnaEnc->scale_flt ); configureFdCngEnc( st->hFdCngEnc, st->bwidth, st->rf_mode && st->total_brate == ACELP_13k20 ? ACELP_9k60 : st->total_brate ); } } diff --git a/lib_enc/ivas_stereo_td_enc.c b/lib_enc/ivas_stereo_td_enc.c index 66c8612e5..8a388ca92 100644 --- a/lib_enc/ivas_stereo_td_enc.c +++ b/lib_enc/ivas_stereo_td_enc.c @@ -131,86 +131,86 @@ void stereo_td_init_enc( } void stereo_td_init_enc_fx( - STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ - const Word16 last_element_mode /* i : last element mode */ + STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ + const Word16 last_element_mode /* i : last element mode */ ) { - hStereoTD->tdm_lt_corr_RM_fx = 21474836; //Q31 - hStereoTD->tdm_lt_corr_LM_fx = 21474836; - hStereoTD->tdm_last_ratio_fx = 1073741824; //Q31 - hStereoTD->tdm_last_ratio_idx = LRTD_STEREO_MID_IS_PRIM; - hStereoTD->tdm_lt_rms_L_fx = 671088640; //Q24 - hStereoTD->tdm_lt_rms_R_fx = 671088640; //Q24 - hStereoTD->tdm_last_diff_lt_corr_fx = 0; - hStereoTD->tdm_last_ener_lt_R_fx = 0; - hStereoTD->tdm_last_ener_lt_L_fx = 0; - - hStereoTD->tdm_ratio_transition_mov_flag = 0; - hStereoTD->tdm_ratio_transition_cnt = 0; - hStereoTD->tdm_noop_mov_flag = 0; - hStereoTD->tdm_noop_cnt = 0; - hStereoTD->tdm_last_SM_flag = 0; - - hStereoTD->tdm_last_ratio_idx = LRTD_STEREO_MID_IS_PRIM; - hStereoTD->tdm_prev_stable_idx = LRTD_STEREO_MID_IS_PRIM; - hStereoTD->tdm_prev_desired_idx = LRTD_STEREO_MID_IS_PRIM; - hStereoTD->tdm_FD2LRTD_SW_cnt = 0; - hStereoTD->tdm_LT_es_em_fx = 214748364; //Q31 - hStereoTD->tdm_hyst_cnt = 0; - /* NOOP parameters */ - hStereoTD->tdm_lt_corr_RM_SM_fx = 21474836; //Q31 - hStereoTD->tdm_lt_corr_LM_SM_fx = 21474836; //Q31 - hStereoTD->tdm_last_ratio_SM_fx = 1073741824; //Q31 - hStereoTD->tdm_last_ratio_idx_SM = 0; - hStereoTD->tdm_lt_rms_L_SM_fx = 671088640; //Q24 - hStereoTD->tdm_lt_rms_R_SM_fx = 671088640; //Q24 - hStereoTD->tdm_last_diff_lt_corr_SM_fx = 0; - hStereoTD->tdm_last_ener_lt_R_SM_fx = 0; - hStereoTD->tdm_last_ener_lt_L_SM_fx = 0; - hStereoTD->tdm_noop_mov_flag = 0; - hStereoTD->tdm_NOOP_cnt = 0; - hStereoTD->tdm_last_SM_flag_noop = 0; - hStereoTD->tdm_last_ratio_idx_SM = LRTD_STEREO_MID_IS_PRIM; - hStereoTD->tdm_prev_stable_idx_SM = LRTD_STEREO_MID_IS_PRIM; - hStereoTD->tdm_prev_desired_idx_SM = LRTD_STEREO_MID_IS_PRIM; - hStereoTD->tdm_LT_es_em_SM_fx = 214748364; //Q31 - hStereoTD->tdm_hyst_cnt_SM = 0; - hStereoTD->tdm_noop_cnt = 0; - hStereoTD->tdm_SM_flag = 0; - hStereoTD->tdm_SM_last_clas[0] = VOICED_CLAS; - hStereoTD->tdm_SM_last_clas[1] = VOICED_CLAS; - hStereoTD->tdm_SM_last2_clas[0] = VOICED_CLAS; - hStereoTD->tdm_SM_last2_clas[1] = VOICED_CLAS; - hStereoTD->tdm_SM_modi_flag = 0; - hStereoTD->tdm_SM_reset_flag = 0; - hStereoTD->prev_fr_LRTD_TD_dec = 0; - hStereoTD->tdm_LRTD_flag = 0; - hStereoTD->tdm_inst_ratio_idx = LRTD_STEREO_RIGHT_IS_PRIM; - hStereoTD->tdm_last_inst_ratio_idx = LRTD_STEREO_MID_IS_PRIM; - hStereoTD->tdm_last_LRTD_frame_cnt = 0; - hStereoTD->tdm_vad_hangover_cnt = 0; - hStereoTD->tdm_ini_frame_cnt = 0; - hStereoTD->tdm_last_LRTD_PriCh_cnt = 0; - - hStereoTD->flag_skip_DMX = 0; - IF (EQ_16(last_element_mode, IVAS_CPE_MDCT)) - { - hStereoTD->flag_skip_DMX = 1; - hStereoTD->prev_fr_LRTD_TD_dec = 1; - hStereoTD->tdm_last_ratio_fx = MAX_32; //Q31 - hStereoTD->tdm_last_ratio_idx = LRTD_STEREO_LEFT_IS_PRIM; - hStereoTD->tdm_prev_stable_idx = LRTD_STEREO_LEFT_IS_PRIM; - hStereoTD->tdm_prev_desired_idx = LRTD_STEREO_LEFT_IS_PRIM; - } - - hStereoTD->tdm_hBstr_tmp.ind_list = hStereoTD->tdm_ind_list_tmp; - hStereoTD->tdm_hBstr_tmp.ivas_ind_list_zero = (Indice **)(&hStereoTD->tdm_hBstr_tmp.ind_list); - hStereoTD->max_ind_tdm_tmp = MAX_IND_TDM_TMP; - hStereoTD->tdm_hBstr_tmp.ivas_max_num_indices = &hStereoTD->max_ind_tdm_tmp; - hStereoTD->tdm_hBstr_tmp.st_ivas = NULL; - reset_indices_enc(&hStereoTD->tdm_hBstr_tmp, MAX_IND_TDM_TMP); - - return; + hStereoTD->tdm_lt_corr_RM_fx = 21474836; // Q31 + hStereoTD->tdm_lt_corr_LM_fx = 21474836; + hStereoTD->tdm_last_ratio_fx = 1073741824; // Q31 + hStereoTD->tdm_last_ratio_idx = LRTD_STEREO_MID_IS_PRIM; + hStereoTD->tdm_lt_rms_L_fx = 671088640; // Q24 + hStereoTD->tdm_lt_rms_R_fx = 671088640; // Q24 + hStereoTD->tdm_last_diff_lt_corr_fx = 0; + hStereoTD->tdm_last_ener_lt_R_fx = 0; + hStereoTD->tdm_last_ener_lt_L_fx = 0; + + hStereoTD->tdm_ratio_transition_mov_flag = 0; + hStereoTD->tdm_ratio_transition_cnt = 0; + hStereoTD->tdm_noop_mov_flag = 0; + hStereoTD->tdm_noop_cnt = 0; + hStereoTD->tdm_last_SM_flag = 0; + + hStereoTD->tdm_last_ratio_idx = LRTD_STEREO_MID_IS_PRIM; + hStereoTD->tdm_prev_stable_idx = LRTD_STEREO_MID_IS_PRIM; + hStereoTD->tdm_prev_desired_idx = LRTD_STEREO_MID_IS_PRIM; + hStereoTD->tdm_FD2LRTD_SW_cnt = 0; + hStereoTD->tdm_LT_es_em_fx = 214748364; // Q31 + hStereoTD->tdm_hyst_cnt = 0; + /* NOOP parameters */ + hStereoTD->tdm_lt_corr_RM_SM_fx = 21474836; // Q31 + hStereoTD->tdm_lt_corr_LM_SM_fx = 21474836; // Q31 + hStereoTD->tdm_last_ratio_SM_fx = 1073741824; // Q31 + hStereoTD->tdm_last_ratio_idx_SM = 0; + hStereoTD->tdm_lt_rms_L_SM_fx = 671088640; // Q24 + hStereoTD->tdm_lt_rms_R_SM_fx = 671088640; // Q24 + hStereoTD->tdm_last_diff_lt_corr_SM_fx = 0; + hStereoTD->tdm_last_ener_lt_R_SM_fx = 0; + hStereoTD->tdm_last_ener_lt_L_SM_fx = 0; + hStereoTD->tdm_noop_mov_flag = 0; + hStereoTD->tdm_NOOP_cnt = 0; + hStereoTD->tdm_last_SM_flag_noop = 0; + hStereoTD->tdm_last_ratio_idx_SM = LRTD_STEREO_MID_IS_PRIM; + hStereoTD->tdm_prev_stable_idx_SM = LRTD_STEREO_MID_IS_PRIM; + hStereoTD->tdm_prev_desired_idx_SM = LRTD_STEREO_MID_IS_PRIM; + hStereoTD->tdm_LT_es_em_SM_fx = 214748364; // Q31 + hStereoTD->tdm_hyst_cnt_SM = 0; + hStereoTD->tdm_noop_cnt = 0; + hStereoTD->tdm_SM_flag = 0; + hStereoTD->tdm_SM_last_clas[0] = VOICED_CLAS; + hStereoTD->tdm_SM_last_clas[1] = VOICED_CLAS; + hStereoTD->tdm_SM_last2_clas[0] = VOICED_CLAS; + hStereoTD->tdm_SM_last2_clas[1] = VOICED_CLAS; + hStereoTD->tdm_SM_modi_flag = 0; + hStereoTD->tdm_SM_reset_flag = 0; + hStereoTD->prev_fr_LRTD_TD_dec = 0; + hStereoTD->tdm_LRTD_flag = 0; + hStereoTD->tdm_inst_ratio_idx = LRTD_STEREO_RIGHT_IS_PRIM; + hStereoTD->tdm_last_inst_ratio_idx = LRTD_STEREO_MID_IS_PRIM; + hStereoTD->tdm_last_LRTD_frame_cnt = 0; + hStereoTD->tdm_vad_hangover_cnt = 0; + hStereoTD->tdm_ini_frame_cnt = 0; + hStereoTD->tdm_last_LRTD_PriCh_cnt = 0; + + hStereoTD->flag_skip_DMX = 0; + IF( EQ_16( last_element_mode, IVAS_CPE_MDCT ) ) + { + hStereoTD->flag_skip_DMX = 1; + hStereoTD->prev_fr_LRTD_TD_dec = 1; + hStereoTD->tdm_last_ratio_fx = MAX_32; // Q31 + hStereoTD->tdm_last_ratio_idx = LRTD_STEREO_LEFT_IS_PRIM; + hStereoTD->tdm_prev_stable_idx = LRTD_STEREO_LEFT_IS_PRIM; + hStereoTD->tdm_prev_desired_idx = LRTD_STEREO_LEFT_IS_PRIM; + } + + hStereoTD->tdm_hBstr_tmp.ind_list = hStereoTD->tdm_ind_list_tmp; + hStereoTD->tdm_hBstr_tmp.ivas_ind_list_zero = (Indice **) ( &hStereoTD->tdm_hBstr_tmp.ind_list ); + hStereoTD->max_ind_tdm_tmp = MAX_IND_TDM_TMP; + hStereoTD->tdm_hBstr_tmp.ivas_max_num_indices = &hStereoTD->max_ind_tdm_tmp; + hStereoTD->tdm_hBstr_tmp.st_ivas = NULL; + reset_indices_enc( &hStereoTD->tdm_hBstr_tmp, MAX_IND_TDM_TMP ); + + return; } /*-------------------------------------------------------------------* diff --git a/lib_enc/ivas_tcx_core_enc.c b/lib_enc/ivas_tcx_core_enc.c index 6457261dc..836abd67d 100644 --- a/lib_enc/ivas_tcx_core_enc.c +++ b/lib_enc/ivas_tcx_core_enc.c @@ -303,7 +303,7 @@ void stereo_tcx_core_enc( if ( st->envWeighted ) { /* Unweight the envelope */ - E_LPC_lsp_unweight_float( st->lsp_old, st->lsp_old, st->lsf_old, 1.0f / st->gamma_flt); + E_LPC_lsp_unweight_float( st->lsp_old, st->lsp_old, st->lsf_old, 1.0f / st->gamma_flt ); st->envWeighted = 0; } @@ -419,7 +419,7 @@ void stereo_tcx_core_enc( if ( st->enableTcxLpc ) { - E_LPC_lsp_unweight_float( lsp_tcx_q, lsp_q, lsf_q, 1.0f / st->gamma_flt); /* Update lsf_q for encoderSideLossSimulation() */ + E_LPC_lsp_unweight_float( lsp_tcx_q, lsp_q, lsf_q, 1.0f / st->gamma_flt ); /* Update lsf_q for encoderSideLossSimulation() */ } /* Update lsp/lsf memory */ diff --git a/lib_enc/lead_indexing_fx.c b/lib_enc/lead_indexing_fx.c index 1a3b74ac7..b3ceeda43 100644 --- a/lib_enc/lead_indexing_fx.c +++ b/lib_enc/lead_indexing_fx.c @@ -2,20 +2,19 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ +#include "options.h" /* Compilation switches */ #include "cnst.h" //#include "prot_fx.h" #include "rom_com_fx.h" #include "rom_com.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* * Local function prototypes *-------------------------------------------------------------------*/ -static Word16 fcb_encode_pos_fx(const Word16 pos_vector[], const Word16 pulse_num, - const Word16 pos_num); +static Word16 fcb_encode_pos_fx( const Word16 pos_vector[], const Word16 pulse_num, const Word16 pos_num ); /*-------------------------------------------------------------------* * re8_compute_base_index_fx: @@ -23,17 +22,17 @@ static Word16 fcb_encode_pos_fx(const Word16 pos_vector[], const Word16 pulse_nu * Compute base index for RE8 *-------------------------------------------------------------------*/ void re8_compute_base_index_fx( - const Word16 *x, /* i : Elemen of Q2, Q3 or Q4 */ - const Word16 ka, /* i : Identifier of the absolute leader related to x */ - UWord16 *I /* o : index */ + const Word16 *x, /* i : Elemen of Q2, Q3 or Q4 */ + const Word16 ka, /* i : Identifier of the absolute leader related to x */ + UWord16 *I /* o : index */ ) { - Word16 i, j, k1 ,m; + Word16 i, j, k1, m; Word16 setor_8p[8], setor_8p_temp[8]; Word16 sign_8p; Word16 code_level, code_area; - const Word16 *a1,*a2; + const Word16 *a1, *a2; Word16 code_index; UWord16 offset; @@ -55,101 +54,101 @@ void re8_compute_base_index_fx( test(); test(); - IF (EQ_16(a2[1], 2)&&s_xor(a1[0],1)&&sub(ka,5)) + IF( EQ_16( a2[1], 2 ) && s_xor( a1[0], 1 ) && sub( ka, 5 ) ) { - FOR (i=0; i<8; i++) + FOR( i = 0; i < 8; i++ ) { - IF (x[i] != 0) + IF( x[i] != 0 ) { - sign_8p = shl(sign_8p, 1); + sign_8p = shl( sign_8p, 1 ); setor_8p_temp[m] = i; move16(); - m = add(m, 1); + m = add( m, 1 ); } - IF (x[i] < 0) + IF( x[i] < 0 ) { - sign_8p = add(sign_8p, 1); + sign_8p = add( sign_8p, 1 ); } } - code_index = fcb_encode_pos_fx(setor_8p_temp,8,m); - code_index = add(shl(code_index,k1),sign_8p); + code_index = fcb_encode_pos_fx( setor_8p_temp, 8, m ); + code_index = add( shl( code_index, k1 ), sign_8p ); offset = Is[ka]; move16(); - *I = extract_l(L_add(offset, (Word32) code_index)); + *I = extract_l( L_add( offset, (Word32) code_index ) ); } ELSE { - FOR (i=0; i<8; i++) + FOR( i = 0; i < 8; i++ ) { - setor_8p[i] = abs_s(x[i]); + setor_8p[i] = abs_s( x[i] ); - IF (x[i] != 0) + IF( x[i] != 0 ) { - sign_8p = shl(sign_8p, 1); - m = add(m, 1); + sign_8p = shl( sign_8p, 1 ); + m = add( m, 1 ); } - IF (x[i] < 0) + IF( x[i] < 0 ) { - sign_8p = add(sign_8p, 1); + sign_8p = add( sign_8p, 1 ); } } - IF (NE_16(k1, m)) + IF( NE_16( k1, m ) ) { - sign_8p = shr(sign_8p, 1); + sign_8p = shr( sign_8p, 1 ); } /* code level by level */ - code_level = sub(a2[1], 1); + code_level = sub( a2[1], 1 ); code_area = 8; move16(); - IF (NE_16(a2[2], 1)) + IF( NE_16( a2[2], 1 ) ) { - FOR (j=0; jhCoreCoder = NULL; - (*phIvasEnc)->isConfigured = false; - (*phIvasEnc)->switchingActive = false; - (*phIvasEnc)->maxBandwidthUser = false; - resetIsmMetadataProvidedFlags(*phIvasEnc); + ( *phIvasEnc )->hCoreCoder = NULL; + ( *phIvasEnc )->isConfigured = false; + ( *phIvasEnc )->switchingActive = false; + ( *phIvasEnc )->maxBandwidthUser = false; + resetIsmMetadataProvidedFlags( *phIvasEnc ); - /*-----------------------------------------------------------------* - * Allocate IVAS-codec encoder state - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * Allocate IVAS-codec encoder state + *-----------------------------------------------------------------*/ - IF (((*phIvasEnc)->st_ivas = (Encoder_Struct *)malloc(sizeof(Encoder_Struct))) == NULL) - { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for IVAS encoder structure"); - } + IF( ( ( *phIvasEnc )->st_ivas = (Encoder_Struct *) malloc( sizeof( Encoder_Struct ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for IVAS encoder structure" ); + } - IF (((*phIvasEnc)->st_ivas->hEncoderConfig = (ENCODER_CONFIG_HANDLE)malloc(sizeof(ENCODER_CONFIG))) == NULL) - { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for Encoder config structure"); - } + IF( ( ( *phIvasEnc )->st_ivas->hEncoderConfig = (ENCODER_CONFIG_HANDLE) malloc( sizeof( ENCODER_CONFIG ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for Encoder config structure" ); + } - /*-----------------------------------------------------------------* - * Initialize IVAS-codec encoder state - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * Initialize IVAS-codec encoder state + *-----------------------------------------------------------------*/ - st_ivas = (*phIvasEnc)->st_ivas; + st_ivas = ( *phIvasEnc )->st_ivas; - /* initialize encoder Config. handle */ - init_encoder_config(st_ivas->hEncoderConfig); + /* initialize encoder Config. handle */ + init_encoder_config( st_ivas->hEncoderConfig ); - /* initialize pointers to handles to NULL */ - ivas_initialize_handles_enc(st_ivas); + /* initialize pointers to handles to NULL */ + ivas_initialize_handles_enc( st_ivas ); - st_ivas->ind_list = NULL; - st_ivas->ind_list_metadata = NULL; + st_ivas->ind_list = NULL; + st_ivas->ind_list_metadata = NULL; - /* set high-level parameters */ - st_ivas->mc_mode = MC_MODE_NONE; - st_ivas->ism_mode = ISM_MODE_NONE; - st_ivas->sba_analysis_order = 0; + /* set high-level parameters */ + st_ivas->mc_mode = MC_MODE_NONE; + st_ivas->ism_mode = ISM_MODE_NONE; + st_ivas->sba_analysis_order = 0; - return IVAS_ERR_OK; + return IVAS_ERR_OK; } /*---------------------------------------------------------------------* * IVAS_ENC_Close() @@ -534,44 +534,44 @@ ivas_error IVAS_ENC_ConfigureForAmbisonics( } #ifdef IVAS_FLOAT_FIXED ivas_error IVAS_ENC_ConfigureForAmbisonics_fx( - IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ - const Word32 inputFs, /* i : input sampling frequency */ - const Word32 bitrate, /* i : requested bitrate of the output bitstream */ - const bool max_bwidth_user, /* i : shows if bandwidth limitation was set by the user (true) or if default bandwidth was used (false) */ - const IVAS_ENC_BANDWIDTH maxBandwidth, /* i : bandwidth limitation */ - const IVAS_ENC_DTX_CONFIG dtxConfig, /* i : configuration of DTX, can by set to default by using IVAS_ENC_GetDefaultDtxConfig() */ - const IVAS_ENC_SBA_ORDER order, /* i : order of the Ambisonics input */ - const bool isPlanar, /* i : if true, input is treated as planar Ambisonics */ - const bool Opt_PCA_ON /* i : PCA option flag */ + IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ + const Word32 inputFs, /* i : input sampling frequency */ + const Word32 bitrate, /* i : requested bitrate of the output bitstream */ + const bool max_bwidth_user, /* i : shows if bandwidth limitation was set by the user (true) or if default bandwidth was used (false) */ + const IVAS_ENC_BANDWIDTH maxBandwidth, /* i : bandwidth limitation */ + const IVAS_ENC_DTX_CONFIG dtxConfig, /* i : configuration of DTX, can by set to default by using IVAS_ENC_GetDefaultDtxConfig() */ + const IVAS_ENC_SBA_ORDER order, /* i : order of the Ambisonics input */ + const bool isPlanar, /* i : if true, input is treated as planar Ambisonics */ + const bool Opt_PCA_ON /* i : PCA option flag */ ) { - ENCODER_CONFIG_HANDLE hEncoderConfig; - ivas_error error; + ENCODER_CONFIG_HANDLE hEncoderConfig; + ivas_error error; - IF ((error = doCommonConfigureChecks(hIvasEnc)) != IVAS_ERR_OK) - { - return error; - } + IF( ( error = doCommonConfigureChecks( hIvasEnc ) ) != IVAS_ERR_OK ) + { + return error; + } - hEncoderConfig = hIvasEnc->st_ivas->hEncoderConfig; + hEncoderConfig = hIvasEnc->st_ivas->hEncoderConfig; - hEncoderConfig->ivas_format = SBA_FORMAT; - hEncoderConfig->element_mode_init = IVAS_SCE; /* Just needs to be something not mono, will be set later */ - hEncoderConfig->sba_planar = isPlanar; - hEncoderConfig->sba_order = order; + hEncoderConfig->ivas_format = SBA_FORMAT; + hEncoderConfig->element_mode_init = IVAS_SCE; /* Just needs to be something not mono, will be set later */ + hEncoderConfig->sba_planar = isPlanar; + hEncoderConfig->sba_order = order; - /* Input in ACN/SN3D in all cases (3D and planar): get number of channels */ - hEncoderConfig->nchan_inp = ivas_sba_get_nchan_fx(hEncoderConfig->sba_order, 0); /*planar input arg. deliberately set to zero since input always in ACN/SN3D*/ + /* Input in ACN/SN3D in all cases (3D and planar): get number of channels */ + hEncoderConfig->nchan_inp = ivas_sba_get_nchan_fx( hEncoderConfig->sba_order, 0 ); /*planar input arg. deliberately set to zero since input always in ACN/SN3D*/ - hEncoderConfig->Opt_PCA_ON = (Word16)Opt_PCA_ON; + hEncoderConfig->Opt_PCA_ON = (Word16) Opt_PCA_ON; - hIvasEnc->maxBandwidthUser = max_bwidth_user; + hIvasEnc->maxBandwidthUser = max_bwidth_user; - error = configureEncoder_fx(hIvasEnc, inputFs, bitrate, maxBandwidth, dtxConfig, IVAS_ENC_GetDefaultChannelAwareConfig()); + error = configureEncoder_fx( hIvasEnc, inputFs, bitrate, maxBandwidth, dtxConfig, IVAS_ENC_GetDefaultChannelAwareConfig() ); - return error; + return error; } #endif /*---------------------------------------------------------------------* @@ -1056,291 +1056,291 @@ static ivas_error configureEncoder( } #ifdef IVAS_FLOAT_FIXED static ivas_error configureEncoder_fx( - IVAS_ENC_HANDLE hIvasEnc, - const Word32 inputFs, - const Word32 initBitrate, - const IVAS_ENC_BANDWIDTH initBandwidth, - const IVAS_ENC_DTX_CONFIG dtxConfig, - const IVAS_ENC_CHANNEL_AWARE_CONFIG caConfig) + IVAS_ENC_HANDLE hIvasEnc, + const Word32 inputFs, + const Word32 initBitrate, + const IVAS_ENC_BANDWIDTH initBandwidth, + const IVAS_ENC_DTX_CONFIG dtxConfig, + const IVAS_ENC_CHANNEL_AWARE_CONFIG caConfig ) { - Encoder_Struct *st_ivas; - ENCODER_CONFIG_HANDLE hEncoderConfig; - ivas_error error; - Word32 cpe_brate; - - error = IVAS_ERR_OK; + Encoder_Struct *st_ivas; + ENCODER_CONFIG_HANDLE hEncoderConfig; + ivas_error error; + Word32 cpe_brate; - st_ivas = hIvasEnc->st_ivas; - hEncoderConfig = st_ivas->hEncoderConfig; + error = IVAS_ERR_OK; - /*-----------------------------------------------------------------* - * Bandwidth limitation - *-----------------------------------------------------------------*/ + st_ivas = hIvasEnc->st_ivas; + hEncoderConfig = st_ivas->hEncoderConfig; - IF ((error = setBandwidth_fx(hIvasEnc, initBandwidth)) != IVAS_ERR_OK) - { - return error; - } + /*-----------------------------------------------------------------* + * Bandwidth limitation + *-----------------------------------------------------------------*/ - /*-----------------------------------------------------------------* - * DTX/CNG - *-----------------------------------------------------------------*/ + IF( ( error = setBandwidth_fx( hIvasEnc, initBandwidth ) ) != IVAS_ERR_OK ) + { + return error; + } - IF (dtxConfig.enabled) - { - hEncoderConfig->Opt_DTX_ON = 1; + /*-----------------------------------------------------------------* + * DTX/CNG + *-----------------------------------------------------------------*/ - IF (dtxConfig.variable_SID_rate) + IF( dtxConfig.enabled ) { - hEncoderConfig->var_SID_rate_flag = 1; - hEncoderConfig->interval_SID = 0; + hEncoderConfig->Opt_DTX_ON = 1; + + IF( dtxConfig.variable_SID_rate ) + { + hEncoderConfig->var_SID_rate_flag = 1; + hEncoderConfig->interval_SID = 0; + } + ELSE + { + hEncoderConfig->var_SID_rate_flag = 0; + + IF( GE_16( dtxConfig.SID_interval, 3 ) && LE_16( dtxConfig.SID_interval, 100 ) ) + { + hEncoderConfig->interval_SID = dtxConfig.SID_interval; + } + ELSE + { + return IVAS_ERR_INVALID_DTX_UPDATE_RATE; + } + } } ELSE { - hEncoderConfig->var_SID_rate_flag = 0; - - IF (GE_16(dtxConfig.SID_interval, 3) && LE_16(dtxConfig.SID_interval, 100)) - { - hEncoderConfig->interval_SID = dtxConfig.SID_interval; - } - ELSE - { - return IVAS_ERR_INVALID_DTX_UPDATE_RATE; - } + hEncoderConfig->Opt_DTX_ON = 0; } - } - ELSE - { - hEncoderConfig->Opt_DTX_ON = 0; - } - /*-----------------------------------------------------------------* - * Bitrate - *-----------------------------------------------------------------*/ - - hEncoderConfig->ivas_total_brate = initBitrate; + /*-----------------------------------------------------------------* + * Bitrate + *-----------------------------------------------------------------*/ - /* SC-VBR at 5.90 kbps */ - IF (hEncoderConfig->ivas_total_brate == ACELP_5k90) - { - hEncoderConfig->ivas_total_brate = ACELP_7k20; - hEncoderConfig->Opt_SC_VBR = 1; - hEncoderConfig->last_Opt_SC_VBR = hEncoderConfig->Opt_SC_VBR; + hEncoderConfig->ivas_total_brate = initBitrate; - IF (NE_16(hEncoderConfig->max_bwidth, NB)) + /* SC-VBR at 5.90 kbps */ + IF( hEncoderConfig->ivas_total_brate == ACELP_5k90 ) { - hEncoderConfig->max_bwidth = WB; - } - } + hEncoderConfig->ivas_total_brate = ACELP_7k20; + hEncoderConfig->Opt_SC_VBR = 1; + hEncoderConfig->last_Opt_SC_VBR = hEncoderConfig->Opt_SC_VBR; - /* check if the entered bitrate is supported */ - IF (NE_16(hEncoderConfig->ivas_format, UNDEFINED_FORMAT) && NE_16(hEncoderConfig->ivas_format, MONO_FORMAT)) /* IVAS */ - { - IF (!is_IVAS_bitrate_fx(hEncoderConfig->ivas_total_brate)) - { - IF (hEncoderConfig->Opt_SC_VBR) - { - return IVAS_ERROR(IVAS_ERR_INVALID_BITRATE, "Incorrect bitrate specification in IVAS [bps]: %d", ACELP_5k90); - } - ELSE - { - return IVAS_ERROR(IVAS_ERR_INVALID_BITRATE, "Incorrect bitrate specification in IVAS [bps]: %d", hEncoderConfig->ivas_total_brate); - } + IF( NE_16( hEncoderConfig->max_bwidth, NB ) ) + { + hEncoderConfig->max_bwidth = WB; + } } - IF (hEncoderConfig->ivas_format == STEREO_FORMAT) + /* check if the entered bitrate is supported */ + IF( NE_16( hEncoderConfig->ivas_format, UNDEFINED_FORMAT ) && NE_16( hEncoderConfig->ivas_format, MONO_FORMAT ) ) /* IVAS */ { - { - hEncoderConfig->element_mode_init = IVAS_CPE_DFT; - IF (hEncoderConfig->ivas_total_brate >= MIN_BRATE_MDCT_STEREO) + IF( !is_IVAS_bitrate_fx( hEncoderConfig->ivas_total_brate ) ) { - hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + IF( hEncoderConfig->Opt_SC_VBR ) + { + return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Incorrect bitrate specification in IVAS [bps]: %d", ACELP_5k90 ); + } + ELSE + { + return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Incorrect bitrate specification in IVAS [bps]: %d", hEncoderConfig->ivas_total_brate ); + } } - } - IF ((EQ_16(hEncoderConfig->element_mode_init, IVAS_CPE_TD) || EQ_32(hEncoderConfig->element_mode_init, IVAS_CPE_DFT)) && GT_32(hEncoderConfig->ivas_total_brate, IVAS_48k)) - { - return IVAS_ERROR(IVAS_ERR_INVALID_BITRATE, "Too high bitrate for TD/DFT Stereo specified in IVAS: %d", hEncoderConfig->ivas_total_brate); - } + IF( hEncoderConfig->ivas_format == STEREO_FORMAT ) + { + { + hEncoderConfig->element_mode_init = IVAS_CPE_DFT; + IF( hEncoderConfig->ivas_total_brate >= MIN_BRATE_MDCT_STEREO ) + { + hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + } + } - IF (EQ_16(hEncoderConfig->element_mode_init, IVAS_CPE_MDCT) && LT_32(hEncoderConfig->ivas_total_brate, IVAS_48k)) - { - return IVAS_ERROR(IVAS_ERR_INVALID_BITRATE, "Too low bitrate for MDCT Stereo specified in IVAS: %d", hEncoderConfig->ivas_total_brate); - } + IF( ( EQ_16( hEncoderConfig->element_mode_init, IVAS_CPE_TD ) || EQ_32( hEncoderConfig->element_mode_init, IVAS_CPE_DFT ) ) && GT_32( hEncoderConfig->ivas_total_brate, IVAS_48k ) ) + { + return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too high bitrate for TD/DFT Stereo specified in IVAS: %d", hEncoderConfig->ivas_total_brate ); + } - IF (LT_32(hEncoderConfig->ivas_total_brate, IVAS_256k)) - { - return IVAS_ERROR(IVAS_ERR_INVALID_BITRATE, "Too high bitrate for Stereo specified in IVAS: %d", hEncoderConfig->ivas_total_brate); - } - } - ELSE IF (EQ_16(hEncoderConfig->ivas_format, ISM_FORMAT)) - { - IF ((error = sanitizeBitrateISM_fx(hEncoderConfig, hIvasEnc->extMetadataApi)) != IVAS_ERR_OK) - { - return error; - } - } - ELSE IF (EQ_16(hEncoderConfig->ivas_format, SBA_FORMAT)) - { - /* nothing */ - } - ELSE IF (EQ_16(hEncoderConfig->ivas_format, MASA_FORMAT)) - { - /* adapt element_mode according to the bitrate */ - IF (EQ_16(hEncoderConfig->nchan_inp, 2) && NE_16(hEncoderConfig->element_mode_init, IVAS_SCE)) - { - IF (GE_32(hEncoderConfig->ivas_total_brate, IVAS_48k)) + IF( EQ_16( hEncoderConfig->element_mode_init, IVAS_CPE_MDCT ) && LT_32( hEncoderConfig->ivas_total_brate, IVAS_48k ) ) + { + return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too low bitrate for MDCT Stereo specified in IVAS: %d", hEncoderConfig->ivas_total_brate ); + } + + IF( LT_32( hEncoderConfig->ivas_total_brate, IVAS_256k ) ) + { + return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too high bitrate for Stereo specified in IVAS: %d", hEncoderConfig->ivas_total_brate ); + } + } + ELSE IF( EQ_16( hEncoderConfig->ivas_format, ISM_FORMAT ) ) { - hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + IF( ( error = sanitizeBitrateISM_fx( hEncoderConfig, hIvasEnc->extMetadataApi ) ) != IVAS_ERR_OK ) + { + return error; + } } - ELSE IF (LT_32(hEncoderConfig->ivas_total_brate, MASA_STEREO_MIN_BITRATE)) + ELSE IF( EQ_16( hEncoderConfig->ivas_format, SBA_FORMAT ) ) { - hEncoderConfig->element_mode_init = IVAS_CPE_DFT; + /* nothing */ } - } - } - ELSE IF (EQ_32(hEncoderConfig->ivas_format, MASA_ISM_FORMAT)) - { - st_ivas->ism_mode = ivas_omasa_ism_mode_select(st_ivas->hEncoderConfig->ivas_total_brate, hEncoderConfig->nchan_ism); + ELSE IF( EQ_16( hEncoderConfig->ivas_format, MASA_FORMAT ) ) + { + /* adapt element_mode according to the bitrate */ + IF( EQ_16( hEncoderConfig->nchan_inp, 2 ) && NE_16( hEncoderConfig->element_mode_init, IVAS_SCE ) ) + { + IF( GE_32( hEncoderConfig->ivas_total_brate, IVAS_48k ) ) + { + hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + } + ELSE IF( LT_32( hEncoderConfig->ivas_total_brate, MASA_STEREO_MIN_BITRATE ) ) + { + hEncoderConfig->element_mode_init = IVAS_CPE_DFT; + } + } + } + ELSE IF( EQ_32( hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) ) + { + st_ivas->ism_mode = ivas_omasa_ism_mode_select( st_ivas->hEncoderConfig->ivas_total_brate, hEncoderConfig->nchan_ism ); - cpe_brate = calculate_cpe_brate_MASA_ISM_fx(st_ivas->ism_mode, st_ivas->hEncoderConfig->ivas_total_brate, hEncoderConfig->nchan_ism); + cpe_brate = calculate_cpe_brate_MASA_ISM_fx( st_ivas->ism_mode, st_ivas->hEncoderConfig->ivas_total_brate, hEncoderConfig->nchan_ism ); - /*adapt element_mode according to the bit-rate*/ - IF (NE_16(hEncoderConfig->element_mode_init, IVAS_SCE)) - { - IF (GE_32(cpe_brate, IVAS_48k)) + /*adapt element_mode according to the bit-rate*/ + IF( NE_16( hEncoderConfig->element_mode_init, IVAS_SCE ) ) + { + IF( GE_32( cpe_brate, IVAS_48k ) ) + { + hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + } + } + } + ELSE IF( EQ_16( hEncoderConfig->ivas_format, SBA_ISM_FORMAT ) ) { - hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + st_ivas->ism_mode = ISM_MODE_NONE; } - } } - ELSE IF (EQ_16(hEncoderConfig->ivas_format, SBA_ISM_FORMAT)) + ELSE /* EVS mono */ { - st_ivas->ism_mode = ISM_MODE_NONE; + hEncoderConfig->ivas_format = MONO_FORMAT; + hEncoderConfig->element_mode_init = EVS_MONO; + + IF( !is_EVS_bitrate( hEncoderConfig->ivas_total_brate, &hEncoderConfig->Opt_AMR_WB ) ) + { + return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Incorrect bitrate specification in EVS mono: %d", hEncoderConfig->ivas_total_brate ); + } + + IF( EQ_16( hEncoderConfig->stereo_dmx_evs, 1 ) ) + { + hEncoderConfig->nchan_inp = 2; + } } - } - ELSE /* EVS mono */ - { - hEncoderConfig->ivas_format = MONO_FORMAT; - hEncoderConfig->element_mode_init = EVS_MONO; - IF (!is_EVS_bitrate(hEncoderConfig->ivas_total_brate, &hEncoderConfig->Opt_AMR_WB)) + /*-----------------------------------------------------------------* + * Input sampling frequency + *-----------------------------------------------------------------*/ + + IF( NE_32( inputFs, 8000 ) && NE_32( inputFs, 16000 ) && NE_32( inputFs, 32000 ) && NE_32( inputFs, 48000 ) ) { - return IVAS_ERROR(IVAS_ERR_INVALID_BITRATE, "Incorrect bitrate specification in EVS mono: %d", hEncoderConfig->ivas_total_brate); + return IVAS_ERR_INVALID_SAMPLING_RATE; } - IF (EQ_16(hEncoderConfig->stereo_dmx_evs, 1)) + hEncoderConfig->input_Fs = inputFs; + + /*-----------------------------------------------------------------* + * Channel-aware mode + *-----------------------------------------------------------------*/ + + IF( ( error = setChannelAwareConfig_fx( hIvasEnc, caConfig ) ) != IVAS_ERR_OK ) { - hEncoderConfig->nchan_inp = 2; + return error; } - } - /*-----------------------------------------------------------------* - * Input sampling frequency - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * Set codec mode + *-----------------------------------------------------------------*/ - IF (NE_32(inputFs, 8000) && NE_32(inputFs, 16000) && NE_32(inputFs, 32000) && NE_32(inputFs, 48000)) - { - return IVAS_ERR_INVALID_SAMPLING_RATE; - } + st_ivas->codec_mode = MODE1; /* Note: in IVAS, set MODE1 */ - hEncoderConfig->input_Fs = inputFs; + IF( EQ_16( hEncoderConfig->ivas_format, MONO_FORMAT ) ) + { + IF( hEncoderConfig->Opt_AMR_WB ) + { + st_ivas->codec_mode = MODE1; + } + ELSE + { + st_ivas->codec_mode = get_codec_mode( hEncoderConfig->ivas_total_brate ); + } + } - /*-----------------------------------------------------------------* - * Channel-aware mode - *-----------------------------------------------------------------*/ + IF( hEncoderConfig->ivas_total_brate == IVAS_13k2 && hEncoderConfig->Opt_RF_ON == 1 ) + { + st_ivas->codec_mode = MODE2; + } - IF ((error = setChannelAwareConfig_fx(hIvasEnc, caConfig)) != IVAS_ERR_OK) - { - return error; - } + st_ivas->last_codec_mode = st_ivas->codec_mode; - /*-----------------------------------------------------------------* - * Set codec mode - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * Sanity checks + *-----------------------------------------------------------------*/ - st_ivas->codec_mode = MODE1; /* Note: in IVAS, set MODE1 */ + assert( hEncoderConfig->ivas_format != UNDEFINED_FORMAT && "\n IVAS format undefined" ); - IF (EQ_16(hEncoderConfig->ivas_format, MONO_FORMAT)) - { - IF (hEncoderConfig->Opt_AMR_WB) + IF( ( NE_16( hEncoderConfig->ivas_format, MONO_FORMAT ) || hEncoderConfig->stereo_dmx_evs ) && EQ_32( hEncoderConfig->input_Fs, 8000 ) ) { - st_ivas->codec_mode = MODE1; + return IVAS_ERROR( IVAS_ERR_INVALID_SAMPLING_RATE, "8kHz input sampling rate is not supported in IVAS." ); } - ELSE + + IF( hEncoderConfig->Opt_DTX_ON && NE_16( hEncoderConfig->ivas_format, MONO_FORMAT ) && + ( ( EQ_16( hEncoderConfig->ivas_format, SBA_FORMAT ) && GT_32( ivas_get_sba_num_TCs( hEncoderConfig->ivas_total_brate, 1 ), 2 ) ) || + EQ_16( hEncoderConfig->ivas_format, MC_FORMAT ) || EQ_16( hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) || EQ_16( hEncoderConfig->ivas_format, SBA_ISM_FORMAT ) ) ) { - st_ivas->codec_mode = get_codec_mode(hEncoderConfig->ivas_total_brate); + return IVAS_ERROR( IVAS_ERR_DTX_NOT_SUPPORTED, "DTX is not supported in this IVAS format and element mode." ); } - } - - IF (hEncoderConfig->ivas_total_brate == IVAS_13k2 && hEncoderConfig->Opt_RF_ON == 1) - { - st_ivas->codec_mode = MODE2; - } - - st_ivas->last_codec_mode = st_ivas->codec_mode; - /*-----------------------------------------------------------------* - * Sanity checks - *-----------------------------------------------------------------*/ - assert(hEncoderConfig->ivas_format != UNDEFINED_FORMAT && "\n IVAS format undefined"); + IF( hEncoderConfig->Opt_PCA_ON && !( EQ_16( hEncoderConfig->ivas_format, SBA_FORMAT ) && EQ_32( hEncoderConfig->ivas_total_brate, PCA_BRATE ) && EQ_16( hEncoderConfig->sba_order, SBA_FOA_ORDER ) ) ) + { + return IVAS_ERROR( IVAS_ERR_NOT_SUPPORTED_OPTION, "PCA supported at SBA FOA 256 kbps only." ); + } - IF ((NE_16(hEncoderConfig->ivas_format, MONO_FORMAT) || hEncoderConfig->stereo_dmx_evs) && EQ_32(hEncoderConfig->input_Fs, 8000)) - { - return IVAS_ERROR(IVAS_ERR_INVALID_SAMPLING_RATE, "8kHz input sampling rate is not supported in IVAS."); - } + IF( ( error = sanitizeBandwidth_fx( hIvasEnc ) ) != IVAS_ERR_OK ) + { + return error; + } - IF (hEncoderConfig->Opt_DTX_ON && NE_16(hEncoderConfig->ivas_format, MONO_FORMAT) && - ((EQ_16(hEncoderConfig->ivas_format, SBA_FORMAT) && GT_32(ivas_get_sba_num_TCs(hEncoderConfig->ivas_total_brate, 1), 2)) || - EQ_16(hEncoderConfig->ivas_format, MC_FORMAT) || EQ_16(hEncoderConfig->ivas_format, MASA_ISM_FORMAT) || EQ_16(hEncoderConfig->ivas_format, SBA_ISM_FORMAT))) - { - return IVAS_ERROR(IVAS_ERR_DTX_NOT_SUPPORTED, "DTX is not supported in this IVAS format and element mode."); - } + IF( hEncoderConfig->is_binaural && !( ( EQ_16( hEncoderConfig->ivas_format, MONO_FORMAT ) && hEncoderConfig->stereo_dmx_evs ) || EQ_16( hEncoderConfig->ivas_format, STEREO_FORMAT ) ) ) + { + return IVAS_ERROR( IVAS_ERR_NOT_SUPPORTED_OPTION, "'-binaural' option is supported only with '-stereo' or '-stereo_dmx_evs'" ); + } + /*-----------------------------------------------------------------* + * Finalize initialization + *-----------------------------------------------------------------*/ - IF (hEncoderConfig->Opt_PCA_ON && !(EQ_16(hEncoderConfig->ivas_format, SBA_FORMAT) && EQ_32(hEncoderConfig->ivas_total_brate, PCA_BRATE) && EQ_16(hEncoderConfig->sba_order, SBA_FOA_ORDER))) - { - return IVAS_ERROR(IVAS_ERR_NOT_SUPPORTED_OPTION, "PCA supported at SBA FOA 256 kbps only."); - } + IF( ( error = ivas_init_encoder_fx( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } - IF ((error = sanitizeBandwidth_fx(hIvasEnc)) != IVAS_ERR_OK) - { - return error; - } + IF( EQ_16( hEncoderConfig->ivas_format, MONO_FORMAT ) ) + { + hIvasEnc->hCoreCoder = st_ivas->hSCE[0]->hCoreCoder[0]; /* Note: this is needed for switching in EVS mono */ + //#ifndef EVS_FLOAT_ENC + // hIvasEnc->hCoreCoder_fx = st_ivas->hSCE[0]->hCoreCoder_fx[0]; + //#endif + } + ELSE + { + hIvasEnc->hCoreCoder = NULL; + } - IF (hEncoderConfig->is_binaural && !((EQ_16(hEncoderConfig->ivas_format, MONO_FORMAT) && hEncoderConfig->stereo_dmx_evs) || EQ_16(hEncoderConfig->ivas_format, STEREO_FORMAT))) - { - return IVAS_ERROR(IVAS_ERR_NOT_SUPPORTED_OPTION, "'-binaural' option is supported only with '-stereo' or '-stereo_dmx_evs'"); - } + hIvasEnc->Opt_RF_ON_loc = hEncoderConfig->Opt_RF_ON; + hIvasEnc->rf_fec_offset_loc = hEncoderConfig->rf_fec_offset; - /*-----------------------------------------------------------------* - * Finalize initialization - *-----------------------------------------------------------------*/ + hIvasEnc->isConfigured = true; - IF ((error = ivas_init_encoder_fx(st_ivas)) != IVAS_ERR_OK) - { return error; - } - - IF (EQ_16(hEncoderConfig->ivas_format, MONO_FORMAT)) - { - hIvasEnc->hCoreCoder = st_ivas->hSCE[0]->hCoreCoder[0]; /* Note: this is needed for switching in EVS mono */ -//#ifndef EVS_FLOAT_ENC -// hIvasEnc->hCoreCoder_fx = st_ivas->hSCE[0]->hCoreCoder_fx[0]; -//#endif - } - ELSE - { - hIvasEnc->hCoreCoder = NULL; - } - - hIvasEnc->Opt_RF_ON_loc = hEncoderConfig->Opt_RF_ON; - hIvasEnc->rf_fec_offset_loc = hEncoderConfig->rf_fec_offset; - - hIvasEnc->isConfigured = true; - - return error; } #endif /*---------------------------------------------------------------------* @@ -1622,9 +1622,9 @@ ivas_error IVAS_ENC_EncodeFrameToSerial( if ( hIvasEnc->switchingActive && hEncoderConfig->ivas_format == MONO_FORMAT ) { #ifdef EVS_FLOAT_ENC - copy_encoder_config(st_ivas, hCoreCoder, 0); + copy_encoder_config( st_ivas, hCoreCoder, 0 ); #else - copy_encoder_config_fx(st_ivas, hCoreCoder, 0); + copy_encoder_config_fx( st_ivas, hCoreCoder, 0 ); #endif hEncoderConfig->last_ivas_total_brate = hEncoderConfig->ivas_total_brate; } @@ -1657,7 +1657,7 @@ ivas_error IVAS_ENC_EncodeFrameToSerial( } #else hCoreCoder->input_frame_fx = inputBufferSize; - if ( ( error = evs_enc_fx(hCoreCoder, inputBuffer, hCoreCoder->mem_hp20_in_fx, inputBufferSize ) ) != IVAS_ERR_OK ) + if ( ( error = evs_enc_fx( hCoreCoder, inputBuffer, hCoreCoder->mem_hp20_in_fx, inputBufferSize ) ) != IVAS_ERR_OK ) { return error; } @@ -1674,12 +1674,12 @@ ivas_error IVAS_ENC_EncodeFrameToSerial( /* write indices into bitstream buffer */ #ifndef EVS_FLOAT_ENC - if ( hEncoderConfig->ivas_format == MONO_FORMAT && hCoreCoder->element_mode == EVS_MONO) + if ( hEncoderConfig->ivas_format == MONO_FORMAT && hCoreCoder->element_mode == EVS_MONO ) { /* write indices into bitstream file */ UWord8 pFrame[( MAX_BITS_PER_FRAME + 7 ) >> 3]; Word16 pFrame_size = 0; - write_indices_buf_fx(hCoreCoder, hCoreCoder->hBstr, outputBitStream, pFrame, pFrame_size, numOutBits ); + write_indices_buf_fx( hCoreCoder, hCoreCoder->hBstr, outputBitStream, pFrame, pFrame_size, numOutBits ); } else #endif @@ -1794,8 +1794,6 @@ ivas_error IVAS_ENC_SetChannelAwareConfig( } - - /*---------------------------------------------------------------------* * IVAS_ENC_GetDefaultBandwidth() * @@ -2227,62 +2225,62 @@ static ivas_error setChannelAwareConfig( } #ifdef IVAS_FLOAT_FIXED static ivas_error setChannelAwareConfig_fx( - IVAS_ENC_HANDLE hIvasEnc, - const IVAS_ENC_CHANNEL_AWARE_CONFIG caConfig) + IVAS_ENC_HANDLE hIvasEnc, + const IVAS_ENC_CHANNEL_AWARE_CONFIG caConfig ) { - Word16 newFecIndicator; - ivas_error error; - Encoder_Struct *st_ivas; - ENCODER_CONFIG_HANDLE hEncoderConfig; - - st_ivas = hIvasEnc->st_ivas; - hEncoderConfig = st_ivas->hEncoderConfig; - - /* channel-aware mode is supported only at 13.20 kbps and with WB or SWB bandwidth */ - IF ((caConfig.channelAwareModeEnabled && NE_32(st_ivas->hEncoderConfig->ivas_total_brate, ACELP_13k20)) || (hEncoderConfig->Opt_RF_ON && EQ_32(hEncoderConfig->input_Fs, 8000))) - { - hEncoderConfig->Opt_RF_ON = 0; - hEncoderConfig->rf_fec_offset = 0; - return IVAS_ERR_OK; - } + Word16 newFecIndicator; + ivas_error error; + Encoder_Struct *st_ivas; + ENCODER_CONFIG_HANDLE hEncoderConfig; - IF (caConfig.channelAwareModeEnabled) - { - hEncoderConfig->Opt_RF_ON = 1; + st_ivas = hIvasEnc->st_ivas; + hEncoderConfig = st_ivas->hEncoderConfig; - /* Convert FEC indicator from API type */ - IF ((error = fecIndicatorApiToInternal(caConfig.fec_indicator, &newFecIndicator)) != IVAS_ERR_OK) + /* channel-aware mode is supported only at 13.20 kbps and with WB or SWB bandwidth */ + IF( ( caConfig.channelAwareModeEnabled && NE_32( st_ivas->hEncoderConfig->ivas_total_brate, ACELP_13k20 ) ) || ( hEncoderConfig->Opt_RF_ON && EQ_32( hEncoderConfig->input_Fs, 8000 ) ) ) { - return error; + hEncoderConfig->Opt_RF_ON = 0; + hEncoderConfig->rf_fec_offset = 0; + return IVAS_ERR_OK; } - /* Set new values only if they differ from current values */ - IF ((NE_16(newFecIndicator, hEncoderConfig->rf_fec_indicator) || NE_16(caConfig.fec_offset, hEncoderConfig->rf_fec_offset))) + IF( caConfig.channelAwareModeEnabled ) { - hEncoderConfig->rf_fec_indicator = newFecIndicator; + hEncoderConfig->Opt_RF_ON = 1; - /* Check if new FEC offset has a valid value */ - IF (EQ_16(caConfig.fec_offset, 0) || EQ_16(caConfig.fec_offset, 2) || EQ_16(caConfig.fec_offset, 3) || EQ_16(caConfig.fec_offset, 5) || EQ_16(caConfig.fec_offset, 7)) - { - hEncoderConfig->rf_fec_offset = caConfig.fec_offset; - } - ELSE - { - return IVAS_ERR_INVALID_FEC_OFFSET; - } + /* Convert FEC indicator from API type */ + IF( ( error = fecIndicatorApiToInternal( caConfig.fec_indicator, &newFecIndicator ) ) != IVAS_ERR_OK ) + { + return error; + } - hIvasEnc->switchingActive = true; - } + /* Set new values only if they differ from current values */ + IF( ( NE_16( newFecIndicator, hEncoderConfig->rf_fec_indicator ) || NE_16( caConfig.fec_offset, hEncoderConfig->rf_fec_offset ) ) ) + { + hEncoderConfig->rf_fec_indicator = newFecIndicator; - /* Save a copy of FEC offset value - needed during encoding */ - hIvasEnc->rf_fec_offset_loc = hEncoderConfig->rf_fec_offset; - } - ELSE - { - hEncoderConfig->Opt_RF_ON = 0; - } + /* Check if new FEC offset has a valid value */ + IF( EQ_16( caConfig.fec_offset, 0 ) || EQ_16( caConfig.fec_offset, 2 ) || EQ_16( caConfig.fec_offset, 3 ) || EQ_16( caConfig.fec_offset, 5 ) || EQ_16( caConfig.fec_offset, 7 ) ) + { + hEncoderConfig->rf_fec_offset = caConfig.fec_offset; + } + ELSE + { + return IVAS_ERR_INVALID_FEC_OFFSET; + } - return IVAS_ERR_OK; + hIvasEnc->switchingActive = true; + } + + /* Save a copy of FEC offset value - needed during encoding */ + hIvasEnc->rf_fec_offset_loc = hEncoderConfig->rf_fec_offset; + } + ELSE + { + hEncoderConfig->Opt_RF_ON = 0; + } + + return IVAS_ERR_OK; } #endif /*---------------------------------------------------------------------* @@ -2294,12 +2292,12 @@ static ivas_error setChannelAwareConfig_fx( static ivas_error doCommonConfigureChecks( IVAS_ENC_HANDLE hIvasEnc ) { - IF ( hIvasEnc == NULL || hIvasEnc->st_ivas == NULL ) + IF( hIvasEnc == NULL || hIvasEnc->st_ivas == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } - IF ( hIvasEnc->isConfigured ) + IF( hIvasEnc->isConfigured ) { return IVAS_ERR_RECONFIGURE_NOT_SUPPORTED; } @@ -2428,44 +2426,44 @@ static ivas_error sanitizeBandwidth( } #ifdef IVAS_FLOAT_FIXED static ivas_error sanitizeBandwidth_fx( - const IVAS_ENC_HANDLE hIvasEnc) + const IVAS_ENC_HANDLE hIvasEnc ) { - ENCODER_CONFIG_HANDLE hEncoderConfig; - Word16 max_bwidth_tmp; - - hEncoderConfig = hIvasEnc->st_ivas->hEncoderConfig; - - max_bwidth_tmp = hIvasEnc->newBandwidthApi; - - /* Prevent st_ivas->max_bwidth from being higher than Fs/2 */ - IF (EQ_32(hEncoderConfig->input_Fs, 8000) && GT_16(max_bwidth_tmp, NB)) - { - max_bwidth_tmp = NB; - } - ELSE IF (EQ_32(hEncoderConfig->input_Fs, 16000) && GT_16(max_bwidth_tmp, WB)) - { - max_bwidth_tmp = WB; - } - ELSE IF (EQ_32(hEncoderConfig->input_Fs, 32000) && GT_16(max_bwidth_tmp, SWB)) - { - max_bwidth_tmp = SWB; - } - - /* NB coding not supported in IVAS. Switching to WB. */ - IF (EQ_16(max_bwidth_tmp, NB) && NE_16(hEncoderConfig->ivas_format, UNDEFINED_FORMAT) && NE_16(hEncoderConfig->ivas_format, MONO_FORMAT)) - { - IF (GE_32(hEncoderConfig->input_Fs, 16000)) + ENCODER_CONFIG_HANDLE hEncoderConfig; + Word16 max_bwidth_tmp; + + hEncoderConfig = hIvasEnc->st_ivas->hEncoderConfig; + + max_bwidth_tmp = hIvasEnc->newBandwidthApi; + + /* Prevent st_ivas->max_bwidth from being higher than Fs/2 */ + IF( EQ_32( hEncoderConfig->input_Fs, 8000 ) && GT_16( max_bwidth_tmp, NB ) ) { - max_bwidth_tmp = WB; + max_bwidth_tmp = NB; } - ELSE + ELSE IF( EQ_32( hEncoderConfig->input_Fs, 16000 ) && GT_16( max_bwidth_tmp, WB ) ) + { + max_bwidth_tmp = WB; + } + ELSE IF( EQ_32( hEncoderConfig->input_Fs, 32000 ) && GT_16( max_bwidth_tmp, SWB ) ) + { + max_bwidth_tmp = SWB; + } + + /* NB coding not supported in IVAS. Switching to WB. */ + IF( EQ_16( max_bwidth_tmp, NB ) && NE_16( hEncoderConfig->ivas_format, UNDEFINED_FORMAT ) && NE_16( hEncoderConfig->ivas_format, MONO_FORMAT ) ) { - return IVAS_ERR_INVALID_BITRATE; + IF( GE_32( hEncoderConfig->input_Fs, 16000 ) ) + { + max_bwidth_tmp = WB; + } + ELSE + { + return IVAS_ERR_INVALID_BITRATE; + } } - } - IF (EQ_16(hEncoderConfig->ivas_format, MONO_FORMAT)) - { + IF( EQ_16( hEncoderConfig->ivas_format, MONO_FORMAT ) ) + { #if 0 // IVAS_fmToDo: temporary disabled to keep EVS bit-exactness -> to be verified if (max_bwidth_tmp == FB && hEncoderConfig->ivas_total_brate < ACELP_16k40) { @@ -2497,23 +2495,23 @@ static ivas_error sanitizeBandwidth_fx( } } #endif - } - ELSE - { - IF (EQ_16(max_bwidth_tmp, FB) && ((NE_16(hEncoderConfig->ivas_format, ISM_FORMAT) && LT_32(hEncoderConfig->ivas_total_brate, MIN_BRATE_FB_STEREO)) || - (EQ_16(hEncoderConfig->ivas_format, ISM_FORMAT) && LT_32(div_l(hEncoderConfig->ivas_total_brate, hEncoderConfig->nchan_ism), MIN_BRATE_FB_ISM)))) + } + ELSE { - max_bwidth_tmp = SWB; + IF( EQ_16( max_bwidth_tmp, FB ) && ( ( NE_16( hEncoderConfig->ivas_format, ISM_FORMAT ) && LT_32( hEncoderConfig->ivas_total_brate, MIN_BRATE_FB_STEREO ) ) || + ( EQ_16( hEncoderConfig->ivas_format, ISM_FORMAT ) && LT_32( div_l( hEncoderConfig->ivas_total_brate, hEncoderConfig->nchan_ism ), MIN_BRATE_FB_ISM ) ) ) ) + { + max_bwidth_tmp = SWB; + } } - } - IF (NE_16(hEncoderConfig->max_bwidth, max_bwidth_tmp)) - { - hEncoderConfig->max_bwidth = max_bwidth_tmp; - hIvasEnc->switchingActive = true; - } + IF( NE_16( hEncoderConfig->max_bwidth, max_bwidth_tmp ) ) + { + hEncoderConfig->max_bwidth = max_bwidth_tmp; + hIvasEnc->switchingActive = true; + } - return IVAS_ERR_OK; + return IVAS_ERR_OK; } #endif /*---------------------------------------------------------------------* @@ -2569,49 +2567,49 @@ static ivas_error sanitizeBitrateISM( } #ifdef IVAS_FLOAT_FIXED static ivas_error sanitizeBitrateISM_fx( - const ENCODER_CONFIG_HANDLE hEncoderConfig, - const bool extMetadataApi) + const ENCODER_CONFIG_HANDLE hEncoderConfig, + const bool extMetadataApi ) { - IF (GT_32(hEncoderConfig->ivas_total_brate, IVAS_128k) && EQ_16(hEncoderConfig->nchan_inp, 1)) - { - return IVAS_ERROR(IVAS_ERR_INVALID_BITRATE, "Too high bitrate for 1 ISM specified in IVAS: %d", hEncoderConfig->ivas_total_brate); - } - - IF (GT_32(hEncoderConfig->ivas_total_brate, IVAS_256k) && EQ_16(hEncoderConfig->nchan_inp, 2)) - { - return IVAS_ERROR(IVAS_ERR_INVALID_BITRATE, "Too high bitrate for 2 ISM specified in IVAS: %d", hEncoderConfig->ivas_total_brate); - } - - IF (GT_32(hEncoderConfig->ivas_total_brate, IVAS_384k) && EQ_16(hEncoderConfig->nchan_inp, 3)) - { - return IVAS_ERROR(IVAS_ERR_INVALID_BITRATE, "Too high bitrate for 3 ISM specified in IVAS: %d", hEncoderConfig->ivas_total_brate); - } - - IF (GT_32(hEncoderConfig->ivas_total_brate, IVAS_16k4) && EQ_16(hEncoderConfig->nchan_inp, 2)) - { - return IVAS_ERROR(IVAS_ERR_INVALID_BITRATE, "Too low bitrate for 2 ISM specified in IVAS: %d", hEncoderConfig->ivas_total_brate); - } - - IF (GT_32(hEncoderConfig->ivas_total_brate, IVAS_24k4) && EQ_16(hEncoderConfig->nchan_inp, 3)) - { - return IVAS_ERROR(IVAS_ERR_INVALID_BITRATE, "Too low bitrate for 3 ISM specified in IVAS: %d", hEncoderConfig->ivas_total_brate); - } - - IF (GT_32(hEncoderConfig->ivas_total_brate, IVAS_24k4) && EQ_16(hEncoderConfig->nchan_inp, 4)) - { - return IVAS_ERROR(IVAS_ERR_INVALID_BITRATE, "Too low bitrate for 4 ISM specified in IVAS: %d", hEncoderConfig->ivas_total_brate); - } - - IF (extMetadataApi) - { - hEncoderConfig->ism_extended_metadata_flag = (Word16)GE_32(hEncoderConfig->ivas_total_brate, ISM_EXTENDED_METADATA_BRATE); - } - ELSE - { - hEncoderConfig->ism_extended_metadata_flag = 0; - } + IF( GT_32( hEncoderConfig->ivas_total_brate, IVAS_128k ) && EQ_16( hEncoderConfig->nchan_inp, 1 ) ) + { + return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too high bitrate for 1 ISM specified in IVAS: %d", hEncoderConfig->ivas_total_brate ); + } + + IF( GT_32( hEncoderConfig->ivas_total_brate, IVAS_256k ) && EQ_16( hEncoderConfig->nchan_inp, 2 ) ) + { + return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too high bitrate for 2 ISM specified in IVAS: %d", hEncoderConfig->ivas_total_brate ); + } + + IF( GT_32( hEncoderConfig->ivas_total_brate, IVAS_384k ) && EQ_16( hEncoderConfig->nchan_inp, 3 ) ) + { + return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too high bitrate for 3 ISM specified in IVAS: %d", hEncoderConfig->ivas_total_brate ); + } + + IF( GT_32( hEncoderConfig->ivas_total_brate, IVAS_16k4 ) && EQ_16( hEncoderConfig->nchan_inp, 2 ) ) + { + return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too low bitrate for 2 ISM specified in IVAS: %d", hEncoderConfig->ivas_total_brate ); + } + + IF( GT_32( hEncoderConfig->ivas_total_brate, IVAS_24k4 ) && EQ_16( hEncoderConfig->nchan_inp, 3 ) ) + { + return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too low bitrate for 3 ISM specified in IVAS: %d", hEncoderConfig->ivas_total_brate ); + } + + IF( GT_32( hEncoderConfig->ivas_total_brate, IVAS_24k4 ) && EQ_16( hEncoderConfig->nchan_inp, 4 ) ) + { + return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too low bitrate for 4 ISM specified in IVAS: %d", hEncoderConfig->ivas_total_brate ); + } + + IF( extMetadataApi ) + { + hEncoderConfig->ism_extended_metadata_flag = (Word16) GE_32( hEncoderConfig->ivas_total_brate, ISM_EXTENDED_METADATA_BRATE ); + } + ELSE + { + hEncoderConfig->ism_extended_metadata_flag = 0; + } - return IVAS_ERR_OK; + return IVAS_ERR_OK; } #endif /*---------------------------------------------------------------------* @@ -2654,36 +2652,36 @@ static ivas_error setBandwidth( } #ifdef IVAS_FLOAT_FIXED static ivas_error setBandwidth_fx( - IVAS_ENC_HANDLE hIvasEnc, - const IVAS_ENC_BANDWIDTH maxBandwidth) + IVAS_ENC_HANDLE hIvasEnc, + const IVAS_ENC_BANDWIDTH maxBandwidth ) { - ivas_error error; - Word16 newBandwidth; - ENCODER_CONFIG_HANDLE hEncoderConfig; + ivas_error error; + Word16 newBandwidth; + ENCODER_CONFIG_HANDLE hEncoderConfig; - hEncoderConfig = hIvasEnc->st_ivas->hEncoderConfig; + hEncoderConfig = hIvasEnc->st_ivas->hEncoderConfig; - /* Convert bandwidth from API type */ - IF ((error = bandwidthApiToInternal(maxBandwidth, &newBandwidth)) != IVAS_ERR_OK) - { - return error; - } + /* Convert bandwidth from API type */ + IF( ( error = bandwidthApiToInternal( maxBandwidth, &newBandwidth ) ) != IVAS_ERR_OK ) + { + return error; + } - hIvasEnc->newBandwidthApi = newBandwidth; + hIvasEnc->newBandwidthApi = newBandwidth; - /* NB coding not supported in IVAS. Switching to WB. */ - IF (newBandwidth == NB && hEncoderConfig->ivas_format != UNDEFINED_FORMAT && hEncoderConfig->ivas_format != MONO_FORMAT) - { - newBandwidth = WB; - } + /* NB coding not supported in IVAS. Switching to WB. */ + IF( newBandwidth == NB && hEncoderConfig->ivas_format != UNDEFINED_FORMAT && hEncoderConfig->ivas_format != MONO_FORMAT ) + { + newBandwidth = WB; + } - IF (hEncoderConfig->max_bwidth != newBandwidth) - { - hEncoderConfig->max_bwidth = newBandwidth; - hIvasEnc->switchingActive = true; - } + IF( hEncoderConfig->max_bwidth != newBandwidth ) + { + hEncoderConfig->max_bwidth = newBandwidth; + hIvasEnc->switchingActive = true; + } - return IVAS_ERR_OK; + return IVAS_ERR_OK; } #endif @@ -2698,7 +2696,7 @@ static void resetIsmMetadataProvidedFlags( { Word16 i; - FOR ( i = 0; i < MAX_NUM_OBJECTS; ++i ) + FOR( i = 0; i < MAX_NUM_OBJECTS; ++i ) { hIvasEnc->ismMetadataProvided[i] = false; } @@ -2717,7 +2715,7 @@ static ivas_error bandwidthApiToInternal( const IVAS_ENC_BANDWIDTH maxBandwidth, Word16 *internalMaxBandwidth ) { - SWITCH ( maxBandwidth ) + SWITCH( maxBandwidth ) { case IVAS_ENC_BANDWIDTH_NB: *internalMaxBandwidth = NB; @@ -2741,7 +2739,6 @@ static ivas_error bandwidthApiToInternal( } - /*---------------------------------------------------------------------* * fecIndicatorApiToInternal() * @@ -2752,7 +2749,7 @@ static ivas_error fecIndicatorApiToInternal( const IVAS_ENC_FEC_INDICATOR fecIndicator, Word16 *fecIndicatorInternal ) { - SWITCH ( fecIndicator ) + SWITCH( fecIndicator ) { case IVAS_ENC_FEC_LO: *fecIndicatorInternal = 0; @@ -2769,7 +2766,6 @@ static ivas_error fecIndicatorApiToInternal( } - /*---------------------------------------------------------------------* * IVAS_ENC_PrintConfig() * diff --git a/lib_enc/long_enr_fx.c b/lib_enc/long_enr_fx.c index d86f25d39..e7f141b5f 100644 --- a/lib_enc/long_enr_fx.c +++ b/lib_enc/long_enr_fx.c @@ -2,14 +2,14 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ //#include "prot_fx.h" /* Function prototypes */ #include "rom_com.h" #include "stl.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* @@ -18,12 +18,13 @@ * Compute relative energy, long-term average total noise energy and total active speech energy *-------------------------------------------------------------------*/ void long_enr_fx( - Encoder_State *st_fx, /* i/o: state structure */ - const Word16 Etot, /* i : total channel E (see lib_enc\analy_sp.c) */ - const Word16 localVAD_HE_SAD, /* i : HE-SAD flag without hangover */ - Word16 high_lpn_flag /* i : sp/mus LPN flag */ + Encoder_State *st_fx, /* i/o: state structure */ + const Word16 Etot, /* i : total channel E (see lib_enc\analy_sp.c) */ + const Word16 localVAD_HE_SAD, /* i : HE-SAD flag without hangover */ + Word16 high_lpn_flag /* i : sp/mus LPN flag */ #ifdef IVAS_CODE - ,FRONT_VAD_ENC_HANDLE hFrontVad[CPE_CHANNELS], /* i/o: front-VAD handles */ + , + FRONT_VAD_ENC_HANDLE hFrontVad[CPE_CHANNELS], /* i/o: front-VAD handles */ const int16_t n_chan, /* i : number of channels */ const int16_t localVAD_HE_SAD_LR[CPE_CHANNELS], /* i : HE-SAD flag without hangover LR channels */ const float Etot_LR[CPE_CHANNELS] /* i : total channel energy LR channels */ @@ -32,24 +33,24 @@ void long_enr_fx( { Word16 tmp; Word16 alpha; - NOISE_EST_HANDLE hNoiseEst = st_fx->hNoiseEst; + NOISE_EST_HANDLE hNoiseEst = st_fx->hNoiseEst; /*-----------------------------------------------------------------* - * Compute long term estimate of total noise energy - * and total active speech energy - *-----------------------------------------------------------------*/ + * Compute long term estimate of total noise energy + * and total active speech energy + *-----------------------------------------------------------------*/ #ifdef IVAS_CODE Word16 n; - if (hFrontVad != NULL) + if ( hFrontVad != NULL ) { - if (hFrontVad[0]->ini_frame < 4) + if ( hFrontVad[0]->ini_frame < 4 ) { - for (n = 0; n < n_chan; n++) + for ( n = 0; n < n_chan; n++ ) { hFrontVad[n]->lp_noise = hFrontVad[n]->hNoiseEst->totalNoise; tmp = hFrontVad[n]->lp_noise + 10.0f; - if (hFrontVad[n]->lp_speech < tmp) + if ( hFrontVad[n]->lp_speech < tmp ) { hFrontVad[n]->lp_speech = tmp; } @@ -59,7 +60,7 @@ void long_enr_fx( { float smooth_prev, smooth_curr; - if (hFrontVad[0]->ini_frame < 150) + if ( hFrontVad[0]->ini_frame < 150 ) { smooth_prev = 0.95f; smooth_curr = 0.05f; @@ -70,13 +71,13 @@ void long_enr_fx( smooth_curr = 0.02f; } - for (n = 0; n < n_chan; n++) + for ( n = 0; n < n_chan; n++ ) { hFrontVad[n]->lp_noise = smooth_prev * hFrontVad[n]->lp_noise + smooth_curr * hFrontVad[n]->hNoiseEst->totalNoise; - if (localVAD_HE_SAD_LR[n] && !high_lpn_flag) + if ( localVAD_HE_SAD_LR[n] && !high_lpn_flag ) { - if ((hFrontVad[n]->lp_speech - Etot_LR[n]) < 10.0f) + if ( ( hFrontVad[n]->lp_speech - Etot_LR[n] ) < 10.0f ) { hFrontVad[n]->lp_speech = 0.98f * hFrontVad[n]->lp_speech + 0.02f * Etot_LR[n]; } @@ -91,12 +92,12 @@ void long_enr_fx( else #endif { - IF(LT_16(st_fx->ini_frame, 4)) + IF( LT_16( st_fx->ini_frame, 4 ) ) { st_fx->lp_noise_fx = hNoiseEst->totalNoise_fx; move16(); - tmp = add(st_fx->lp_noise_fx, 2560); /*10.0 in Q8*/ - st_fx->lp_speech_fx = s_max(st_fx->lp_speech_fx, tmp); + tmp = add( st_fx->lp_noise_fx, 2560 ); /*10.0 in Q8*/ + st_fx->lp_speech_fx = s_max( st_fx->lp_speech_fx, tmp ); } ELSE { @@ -106,29 +107,27 @@ void long_enr_fx( st->lp_noise = 0.98f * st->lp_noise + 0.02f * st->totalNoise; } */ alpha = 655; - move16();/* 0.02 Q15 */ - if (LT_16(st_fx->ini_frame, 150)) /* should match HE_LT_CNT_INIT_FX */ + move16(); /* 0.02 Q15 */ + if ( LT_16( st_fx->ini_frame, 150 ) ) /* should match HE_LT_CNT_INIT_FX */ { alpha = 1638; move16(); /* 0.05 Q15 */ } - st_fx->lp_noise_fx = noise_est_AR1_Qx(hNoiseEst->totalNoise_fx, st_fx->lp_noise_fx , alpha); /* Q8 state, alpha in Q15 */ + st_fx->lp_noise_fx = noise_est_AR1_Qx( hNoiseEst->totalNoise_fx, st_fx->lp_noise_fx, alpha ); /* Q8 state, alpha in Q15 */ test(); - IF((localVAD_HE_SAD != 0) - && (high_lpn_flag == 0)) + IF( ( localVAD_HE_SAD != 0 ) && ( high_lpn_flag == 0 ) ) { - IF(LT_16(sub(st_fx->lp_speech_fx, Etot), 10 * 256)) /* 10.0 in Q8 */ + IF( LT_16( sub( st_fx->lp_speech_fx, Etot ), 10 * 256 ) ) /* 10.0 in Q8 */ { /* st->lp_speech = 0.98f * st->lp_speech + 0.02f * Etot; */ - st_fx->lp_speech_fx = noise_est_AR1_Qx(Etot, st_fx->lp_speech_fx, 655); /* Q8 state, 0.02 in Q15 */ + st_fx->lp_speech_fx = noise_est_AR1_Qx( Etot, st_fx->lp_speech_fx, 655 ); /* Q8 state, 0.02 in Q15 */ } ELSE { - st_fx->lp_speech_fx = sub(st_fx->lp_speech_fx, 13); /* st->lp_speech = st->lp_speech - 0.05f; linear decay*/ + st_fx->lp_speech_fx = sub( st_fx->lp_speech_fx, 13 ); /* st->lp_speech = st->lp_speech - 0.05f; linear decay*/ } } - } } diff --git a/lib_enc/lp_exc_e_fx.c b/lib_enc/lp_exc_e_fx.c index 5d36d4b4d..a8a6abc33 100644 --- a/lib_enc/lp_exc_e_fx.c +++ b/lib_enc/lp_exc_e_fx.c @@ -2,29 +2,27 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ //#include "prot_fx.h" /* Function prototypes */ #include "basop_util.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* * Local constants *-------------------------------------------------------------------*/ -#define GAIN_PIT_MAX 19661 -#define HIGH_LTP_LIMIT 1.0f -#define LOW_LTP_LIMIT 0.55f +#define GAIN_PIT_MAX 19661 +#define HIGH_LTP_LIMIT 1.0f +#define LOW_LTP_LIMIT 0.55f /*-------------------------------------------------------------------* * Local function prototypes *-------------------------------------------------------------------*/ -static Word16 adpt_enr_fx(const Word16 codec_mode, const Word16 *exc, const Word16 *h1, Word16 *y1, const Word16 L_subfr, - Word16 *gain, Word16 *g_corr, const Word16 clip_gain, const Word16 *xn, Word16 *xn2, Word16 *exp_ener - ,Word16 use_prev_sf_pit_gain); +static Word16 adpt_enr_fx( const Word16 codec_mode, const Word16 *exc, const Word16 *h1, Word16 *y1, const Word16 L_subfr, Word16 *gain, Word16 *g_corr, const Word16 clip_gain, const Word16 *xn, Word16 *xn2, Word16 *exp_ener, Word16 use_prev_sf_pit_gain ); /*-------------------------------------------------------------------* * function lp_filt_exc_enc_fx() @@ -35,24 +33,24 @@ static Word16 adpt_enr_fx(const Word16 codec_mode, const Word16 *exc, const Word *-------------------------------------------------------------------*/ Word16 lp_filt_exc_enc_fx( - const Word16 codec_mode, /* i : MODE1 or MODE2 Q0 */ - const Word16 coder_type, /* i : coding type Q0 */ - const Word16 i_subfr, /* i : subframe index Q0 */ - Word16 *exc, /* i/o: pointer to excitation signal frame Q_new */ - const Word16 *h1, /* i : weighted filter input response Q(14+shift) */ - const Word16 *xn, /* i : target vector Q_new-1+shift */ - Word16 *y1, /* o : zero-memory filtered adaptive excitation Q_new-1+shift */ - Word16 *xn2, /* o : target vector for innovation search Q_new-1+shift */ - const Word16 L_subfr, /* i : length of vectors for gain quantization Q0 */ - const Word16 L_frame, /* i : frame size Q0 */ - Word16 *g_corr, /* o : ACELP correlation values mant/exp */ - const Word16 clip_gain, /* i : adaptive gain clipping flag Q0 */ - Word16 *gain_pit, /* o : adaptive excitation gain Q14 */ - Word16 *lp_flag /* i/o: mode selection Q0 */ + const Word16 codec_mode, /* i : MODE1 or MODE2 Q0 */ + const Word16 coder_type, /* i : coding type Q0 */ + const Word16 i_subfr, /* i : subframe index Q0 */ + Word16 *exc, /* i/o: pointer to excitation signal frame Q_new */ + const Word16 *h1, /* i : weighted filter input response Q(14+shift) */ + const Word16 *xn, /* i : target vector Q_new-1+shift */ + Word16 *y1, /* o : zero-memory filtered adaptive excitation Q_new-1+shift */ + Word16 *xn2, /* o : target vector for innovation search Q_new-1+shift */ + const Word16 L_subfr, /* i : length of vectors for gain quantization Q0 */ + const Word16 L_frame, /* i : frame size Q0 */ + Word16 *g_corr, /* o : ACELP correlation values mant/exp */ + const Word16 clip_gain, /* i : adaptive gain clipping flag Q0 */ + Word16 *gain_pit, /* o : adaptive excitation gain Q14 */ + Word16 *lp_flag /* i/o: mode selection Q0 */ ) { - Word16 gain1, gain2, g_corr2[4], exc_tmp[5*L_SUBFR], xn2_tmp[5*L_SUBFR]; - Word16 y1_tmp[5*L_SUBFR]; + Word16 gain1, gain2, g_corr2[4], exc_tmp[5 * L_SUBFR], xn2_tmp[5 * L_SUBFR]; + Word16 y1_tmp[5 * L_SUBFR]; Word16 select, i, exp_ener, exp_ener1; Word16 wtmp, wtmp1; Word32 Ltmp; @@ -68,7 +66,7 @@ Word16 lp_filt_exc_enc_fx( * Find the target energy if the adaptive exc. is not filtered *----------------------------------------------------------------*/ test(); - IF( EQ_16(codec_mode,MODE2)&&EQ_16(coder_type,100)) + IF( EQ_16( codec_mode, MODE2 ) && EQ_16( coder_type, 100 ) ) { use_prev_sf_pit_gain = 1; } @@ -77,11 +75,10 @@ Word16 lp_filt_exc_enc_fx( wtmp = 0; move16(); test(); - IF( EQ_16(*lp_flag,FULL_BAND)||EQ_16(*lp_flag,NORMAL_OPERATION)) + IF( EQ_16( *lp_flag, FULL_BAND ) || EQ_16( *lp_flag, NORMAL_OPERATION ) ) { - wtmp = adpt_enr_fx( codec_mode, &exc[i_subfr], h1, y1, L_subfr, &gain1, g_corr, clip_gain, xn, xn2, &exp_ener, use_prev_sf_pit_gain); + wtmp = adpt_enr_fx( codec_mode, &exc[i_subfr], h1, y1, L_subfr, &gain1, g_corr, clip_gain, xn, xn2, &exp_ener, use_prev_sf_pit_gain ); move16(); - } /*----------------------------------------------------------------* @@ -94,42 +91,41 @@ Word16 lp_filt_exc_enc_fx( wtmp1 = 0; move16(); test(); - IF( (EQ_16(*lp_flag,LOW_PASS))||(EQ_16(*lp_flag,NORMAL_OPERATION))) + IF( ( EQ_16( *lp_flag, LOW_PASS ) ) || ( EQ_16( *lp_flag, NORMAL_OPERATION ) ) ) { test(); - IF( EQ_16(codec_mode,MODE2)&&EQ_16(L_frame,L_FRAME16k)) + IF( EQ_16( codec_mode, MODE2 ) && EQ_16( L_frame, L_FRAME16k ) ) { - FOR ( i=0; i and -2 ) *-------------------------------------------------------------------*/ -Word16 corr_xy1_fx( /* o : pitch gain (0..GAIN_PIT_MAX) */ - const Word16 xn_1[], /* i : target signal */ - const Word16 y1_1[], /* i : filtered adaptive codebook excitation */ - Word16 g_corr[], /* o : correlations and -2 */ - const Word16 L_subfr, /* i : vector length */ - const Word16 norm_flag /* i : flag for constraining pitch contribution */ +Word16 corr_xy1_fx( /* o : pitch gain (0..GAIN_PIT_MAX) */ + const Word16 xn_1[], /* i : target signal */ + const Word16 y1_1[], /* i : filtered adaptive codebook excitation */ + Word16 g_corr[], /* o : correlations and -2 */ + const Word16 L_subfr, /* i : vector length */ + const Word16 norm_flag /* i : flag for constraining pitch contribution */ #ifdef BASOP_NOGLOB - ,Flag *Overflow_out /* o : propagating the Overflow flag to upper level */ + , + Flag *Overflow_out /* o : propagating the Overflow flag to upper level */ #endif ) { @@ -310,35 +308,35 @@ Word16 corr_xy1_fx( /* o : pitch gain (0..GAIN_PIT_MAX) */ *----------------------------------------------------------------*/ /* Compute scalar product */ - Copy(xn_1, xn, L_subfr); - Copy(y1_1, y1, L_subfr); - Overflow = 0; + Copy( xn_1, xn, L_subfr ); + Copy( y1_1, y1, L_subfr ); + Overflow = 0; move16(); -#ifdef BASOP_NOGLOB /* Critical Overflow */ - Ltmp1 = Dot_product12_o(y1, y1, L_subfr, &exp_yy, &Overflow); +#ifdef BASOP_NOGLOB /* Critical Overflow */ + Ltmp1 = Dot_product12_o( y1, y1, L_subfr, &exp_yy, &Overflow ); *Overflow_out |= Overflow; move16(); #else - Ltmp1 = Dot_product12(y1, y1, L_subfr, &exp_yy); + Ltmp1 = Dot_product12( y1, y1, L_subfr, &exp_yy ); #endif IF( Overflow ) { - FOR(i = 0; i < L_subfr; i++) + FOR( i = 0; i < L_subfr; i++ ) { - xn[i] = mult_r(xn_1[i], 4096); + xn[i] = mult_r( xn_1[i], 4096 ); move16(); - y1[i] = mult_r(y1_1[i], 4096); + y1[i] = mult_r( y1_1[i], 4096 ); move16(); } - Ltmp1 = Dot_product12(y1, y1, L_subfr, &exp_yy); - exp_yy = add(exp_yy, 6); - yy = extract_h(Ltmp1); + Ltmp1 = Dot_product12( y1, y1, L_subfr, &exp_yy ); + exp_yy = add( exp_yy, 6 ); + yy = extract_h( Ltmp1 ); /* Compute scalar product */ - Ltmp2 = Dot_product12(xn, y1, L_subfr, &exp_xy); - xy = extract_h(Ltmp2); - exp_xy = add(exp_xy, 6); + Ltmp2 = Dot_product12( xn, y1, L_subfr, &exp_xy ); + xy = extract_h( Ltmp2 ); + exp_xy = add( exp_xy, 6 ); g_corr[0] = yy; move16(); @@ -352,18 +350,18 @@ Word16 corr_xy1_fx( /* o : pitch gain (0..GAIN_PIT_MAX) */ } ELSE { - yy = extract_h(Ltmp1); + yy = extract_h( Ltmp1 ); /* Ltmp1 = L_shr(Ltmp1, sub(30, exp_yy));*/ /* Compute scalar product */ #ifdef BASOP_NOGLOB - Ltmp2 = Dot_product12_o(xn, y1, L_subfr, &exp_xy, &Overflow); + Ltmp2 = Dot_product12_o( xn, y1, L_subfr, &exp_xy, &Overflow ); *Overflow_out |= Overflow; move16(); #else - Ltmp2 = Dot_product12(xn, y1, L_subfr, &exp_xy); + Ltmp2 = Dot_product12( xn, y1, L_subfr, &exp_xy ); #endif - xy = extract_h(Ltmp2); + xy = extract_h( Ltmp2 ); /* Ltmp2 = L_shr(Ltmp2, sub(30, exp_xy));*/ g_corr[0] = yy; @@ -379,22 +377,22 @@ Word16 corr_xy1_fx( /* o : pitch gain (0..GAIN_PIT_MAX) */ /* find pitch gain and bound it by [0,GAIN_PIT_MAX] */ test(); - IF ( xy >= 0 && NE_16(s_or(yy, xy), 16384)) + IF( xy >= 0 && NE_16( s_or( yy, xy ), 16384 ) ) { /* compute gain = xy/yy */ - xy = shr(xy, 1); /* be sure that xy < yy */ - gain = div_s(xy, yy); - i = sub(exp_xy, exp_yy); + xy = shr( xy, 1 ); /* be sure that xy < yy */ + gain = div_s( xy, yy ); + i = sub( exp_xy, exp_yy ); #ifdef BASOP_NOGLOB - gain = shl_o(gain, i, &Overflow); /* saturation can occur here */ + gain = shl_o( gain, i, &Overflow ); /* saturation can occur here */ *Overflow_out |= Overflow; move16(); #else /* BASOP_NOGLOB */ - gain = shl(gain, i); /* saturation can occur here */ + gain = shl( gain, i ); /* saturation can occur here */ #endif - gain = s_max(gain, 0); - gain = s_min(gain, GAIN_PIT_MAX); /* 1.2 in Q14 */ + gain = s_max( gain, 0 ); + gain = s_min( gain, GAIN_PIT_MAX ); /* 1.2 in Q14 */ } ELSE { @@ -403,30 +401,30 @@ Word16 corr_xy1_fx( /* o : pitch gain (0..GAIN_PIT_MAX) */ } /* Limit the energy of pitch contribution */ - IF (norm_flag) + IF( norm_flag ) { #ifdef BASOP_NOGLOB /*that part of code seems never used*/ #endif /* Compute scalar product */ - xx = round_fx(Dot_product12_offs(xn, xn, L_subfr, &exp_xx, 1)); + xx = round_fx( Dot_product12_offs( xn, xn, L_subfr, &exp_xx, 1 ) ); /* gain_p_snr = sqrt(/) */ - tmp = BASOP_Util_Divide1616_Scale(xx, yy, &exp_div); - exp_xx = add(sub(exp_xx, exp_yy), exp_div); - tmp = Sqrt16(tmp, &exp_xx); + tmp = BASOP_Util_Divide1616_Scale( xx, yy, &exp_div ); + exp_xx = add( sub( exp_xx, exp_yy ), exp_div ); + tmp = Sqrt16( tmp, &exp_xx ); /* Note: shl works as shl or shr. */ - exp_xx = sub(exp_xx,1); + exp_xx = sub( exp_xx, 1 ); BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB gain_p_snr = round_fx_sat( L_shl_sat( Mpy_32_16_1( 1717986944l /*ACELP_GAINS_CONST Q31*/, tmp ), exp_xx ) ); #else - gain_p_snr = round_fx(L_shl(Mpy_32_16_1( 1717986944l/*ACELP_GAINS_CONST Q31*/, tmp), exp_xx)); + gain_p_snr = round_fx( L_shl( Mpy_32_16_1( 1717986944l /*ACELP_GAINS_CONST Q31*/, tmp ), exp_xx ) ); #endif BASOP_SATURATE_WARNING_ON_EVS - gain = s_min(gain, gain_p_snr); + gain = s_min( gain, gain_p_snr ); } return gain; diff --git a/lib_enc/lsf_enc.c b/lib_enc/lsf_enc.c index 46949eab5..ea07e8a1e 100644 --- a/lib_enc/lsf_enc.c +++ b/lib_enc/lsf_enc.c @@ -557,17 +557,17 @@ void lsf_end_enc( #ifdef IVAS_FLOAT_FIXED Word16 tdm_lsfQ_PCh_fx[M]; Word16 pred3_fx[M]; - for (int ii = 0; ii < M; ii++) + for ( int ii = 0; ii < M; ii++ ) { - tdm_lsfQ_PCh_fx[ii] = (Word16)((tdm_lsfQ_PCh[ii]) * 2.56f); - pred3_fx[ii] = (Word16)((pred3[ii]) * 2.56f); + tdm_lsfQ_PCh_fx[ii] = (Word16) ( ( tdm_lsfQ_PCh[ii] ) * 2.56f ); + pred3_fx[ii] = (Word16) ( ( pred3[ii] ) * 2.56f ); } - tdm_SCh_LSF_intra_pred_fx(st->element_brate, tdm_lsfQ_PCh_fx, pred3_fx); + tdm_SCh_LSF_intra_pred_fx( st->element_brate, tdm_lsfQ_PCh_fx, pred3_fx ); - for (int ii = 0; ii < M; ii++) + for ( int ii = 0; ii < M; ii++ ) { - pred3[ii] = (pred3_fx[ii]) / 2.56f; + pred3[ii] = ( pred3_fx[ii] ) / 2.56f; } #else tdm_SCh_LSF_intra_pred( st->element_brate, tdm_lsfQ_PCh, pred3 ); @@ -627,7 +627,7 @@ void lsf_end_enc( if ( st->sr_core == INT_FS_16k && coder_type == VOICED && flag_1bit_gran == 0 ) { /* select safety_net or predictive in open loop*/ - safety_net = qlsf_Mode_Select( lsf, wghts, pred2, st->streaklimit, OP_LOOP_THR_HVO_FLT); + safety_net = qlsf_Mode_Select( lsf, wghts, pred2, st->streaklimit, OP_LOOP_THR_HVO_FLT ); if ( force_sf == 1 ) { diff --git a/lib_enc/lsf_enc_fx.c b/lib_enc/lsf_enc_fx.c index 96cbde993..3926f4a2b 100644 --- a/lib_enc/lsf_enc_fx.c +++ b/lib_enc/lsf_enc_fx.c @@ -3,38 +3,33 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ +#include "options.h" /* Compilation switches */ #include "rom_enc.h" -#include "rom_com_fx.h" /* Static table prototypes */ +#include "rom_com_fx.h" /* Static table prototypes */ #include "rom_com.h" /* Static table prototypes */ //#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ - +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*-----------------------------------------------------------------* -* Local constants -*-----------------------------------------------------------------*/ -#define MIN_LOG_FX 0 -#define MIN_LOG_VAL_FX -15360 /* -60.0f in Q8 */ -#define MSVQ_MAXCNT 3000 -#define MAXINT32 MAX_32 + * Local constants + *-----------------------------------------------------------------*/ +#define MIN_LOG_FX 0 +#define MIN_LOG_VAL_FX -15360 /* -60.0f in Q8 */ +#define MSVQ_MAXCNT 3000 +#define MAXINT32 MAX_32 /*---------------------------------------------------------------------* -* Local function prototypes -*---------------------------------------------------------------------*/ + * Local function prototypes + *---------------------------------------------------------------------*/ -static void lsfq_CNG_fx(BSTR_ENC_HANDLE hBstr, const Word16 *lsf, const Word16 *wghts, Word16 *qlsf, Word32 *p_offset_scale1, Word32 * p_offset_scale2, - Word16 * p_no_scales ); +static void lsfq_CNG_fx( BSTR_ENC_HANDLE hBstr, const Word16 *lsf, const Word16 *wghts, Word16 *qlsf, Word32 *p_offset_scale1, Word32 *p_offset_scale2, Word16 *p_no_scales ); -static Word32 vq_lvq_lsf_enc( Word16 pred_flag, Word16 mode, Word16 u[], Word16 * levels, Word16 stages, Word16 w[], Word16 Idx[], const Word16 * lsf, - const Word16 * pred, Word32 p_offset_scale1[][MAX_NO_SCALES+1], Word32 p_offset_scale2[][MAX_NO_SCALES+1], - Word16 p_no_scales[][2], Word16 *resq, Word16 * lsfq ); +static Word32 vq_lvq_lsf_enc( Word16 pred_flag, Word16 mode, Word16 u[], Word16 *levels, Word16 stages, Word16 w[], Word16 Idx[], const Word16 *lsf, const Word16 *pred, Word32 p_offset_scale1[][MAX_NO_SCALES + 1], Word32 p_offset_scale2[][MAX_NO_SCALES + 1], Word16 p_no_scales[][2], Word16 *resq, Word16 *lsfq ); -static void lsf_mid_enc_fx(BSTR_ENC_HANDLE hBstr, int16_t nb_bits, const Word16 int_fs, const Word16 qlsp0[], const Word16 qlsp1[], Word16 lsp[], - const Word16 coder_type, const Word16 bwidth, Word32 Bin_Ener_old[], Word32 Bin_Ener[], Word16 Q_ener, Word16 ppp_mode, Word16 nelp_mode); +static void lsf_mid_enc_fx( BSTR_ENC_HANDLE hBstr, int16_t nb_bits, const Word16 int_fs, const Word16 qlsp0[], const Word16 qlsp1[], Word16 lsp[], const Word16 coder_type, const Word16 bwidth, Word32 Bin_Ener_old[], Word32 Bin_Ener[], Word16 Q_ener, Word16 ppp_mode, Word16 nelp_mode ); /*===========================================================================*/ /* FUNCTION : lsf_enc_fx() */ @@ -64,19 +59,18 @@ static void lsf_mid_enc_fx(BSTR_ENC_HANDLE hBstr, int16_t nb_bits, const Word16 /* _ None */ /*===========================================================================*/ void lsf_enc_fx( - Encoder_State *st_fx, /* i/o: state structure */ - Word16 *lsf_new, /* o : quantized LSF vector */ - Word16 *lsp_new, /* i/o: LSP vector to quantize/quantized */ - Word16 *lsp_mid, /* i/o : mid-frame LSP vector */ - Word16 *Aq, /* o : quantized A(z) for 4 subframes */ + Encoder_State *st_fx, /* i/o: state structure */ + Word16 *lsf_new, /* o : quantized LSF vector */ + Word16 *lsp_new, /* i/o: LSP vector to quantize/quantized */ + Word16 *lsp_mid, /* i/o : mid-frame LSP vector */ + Word16 *Aq, /* o : quantized A(z) for 4 subframes */ const Word16 Nb_ACELP_frames, const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag */ - const Word16 GSC_IVAS_mode, /* i : GSC IVAS mode */ + const Word16 GSC_IVAS_mode, /* i : GSC IVAS mode */ #ifdef LSF_RE_USE_SECONDARY_CHANNEL - const float tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */ + const float tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */ #endif - const Word16 Q_new -) + const Word16 Q_new ) { Word16 nBits = 0; Word16 int_fs; @@ -86,7 +80,7 @@ void lsf_enc_fx( Word16 no_param_lpc; #endif #ifdef REMOVE_IVAS_UNUSED_PARAMETERS_WARNING - (void)tdm_low_rate_mode; + (void) tdm_low_rate_mode; #endif #ifdef IVAS_CODE Word16 param_lpc[NPRM_LPC_NEW]; @@ -95,7 +89,7 @@ void lsf_enc_fx( Word16 coder_type, ppp_mode, nelp_mode; test(); - IF (EQ_32(st_fx->core_brate, SID_2k40) || EQ_32(st_fx->core_brate, SID_1k75)) + IF( EQ_32( st_fx->core_brate, SID_2k40 ) || EQ_32( st_fx->core_brate, SID_1k75 ) ) { coder_type = INACTIVE; move16(); @@ -104,11 +98,10 @@ void lsf_enc_fx( { coder_type = st_fx->coder_type; move16(); - } test(); - if (EQ_16(coder_type, AUDIO) && GSC_IVAS_mode > 0) + if ( EQ_16( coder_type, AUDIO ) && GSC_IVAS_mode > 0 ) { coder_type = GENERIC; move16(); @@ -119,17 +112,19 @@ void lsf_enc_fx( #endif move16(); - IF (st_fx->Opt_SC_VBR) + IF( st_fx->Opt_SC_VBR ) { ppp_mode = st_fx->hSC_VBR->ppp_mode; nelp_mode = st_fx->hSC_VBR->nelp_mode; - move16();move16(); + move16(); + move16(); } ELSE { ppp_mode = 0; nelp_mode = 0; - move16(); move16(); + move16(); + move16(); } /* initialize */ @@ -142,19 +137,20 @@ void lsf_enc_fx( move16(); } #else - assert(st_fx->sr_core <= 32000); - int_fs = extract_l(st_fx->sr_core); + assert( st_fx->sr_core <= 32000 ); + int_fs = extract_l( st_fx->sr_core ); move32(); #endif /* convert LSPs to LSFs */ - lsp2lsf_fx( lsp_new, lsf_new, M, int_fs); + lsp2lsf_fx( lsp_new, lsf_new, M, int_fs ); /* check resonance for pitch clipping algorithm */ - gp_clip_test_lsf_fx(st_fx->element_mode, lsf_new, st_fx->clip_var_fx, 0 ); + gp_clip_test_lsf_fx( st_fx->element_mode, lsf_new, st_fx->clip_var_fx, 0 ); /* Find the number of bits for LSF quantization */ - nBits = 0; move16(); - IF ( EQ_32(st_fx->core_brate, SID_2k40)) + nBits = 0; + move16(); + IF( EQ_32( st_fx->core_brate, SID_2k40 ) ) { nBits = LSF_BITS_CNG; move16(); @@ -162,39 +158,40 @@ void lsf_enc_fx( ELSE { test(); - IF ( (nelp_mode == 0) && (ppp_mode == 0) ) + IF( ( nelp_mode == 0 ) && ( ppp_mode == 0 ) ) { nBits = st_fx->acelp_cfg.lsf_bits; move16(); } - ELSE IF ( EQ_16(nelp_mode, 1)) + ELSE IF( EQ_16( nelp_mode, 1 ) ) { nBits = 30; move16(); - if ( EQ_16(st_fx->bwidth,NB)) + if ( EQ_16( st_fx->bwidth, NB ) ) { nBits = 32; move16(); } } - ELSE IF ( EQ_16(ppp_mode, 1)) + ELSE IF( EQ_16( ppp_mode, 1 ) ) { nBits = 26; move16(); } } - force_sf = 0; move16(); + force_sf = 0; + move16(); /* first three ACELP frames after an HQ frame shall be processed only with safety-net quantizer */ test(); - if( LT_16(Nb_ACELP_frames, 3) && NE_32(st_fx->core_brate, SID_2k40) ) + if ( LT_16( Nb_ACELP_frames, 3 ) && NE_32( st_fx->core_brate, SID_2k40 ) ) { force_sf = 1; move16(); } /* in case of unstable filter in decoder FEC, choose safety-net to help FEC */ - IF ( EQ_16(st_fx->next_force_safety_net_fx ,1)) + IF( EQ_16( st_fx->next_force_safety_net_fx, 1 ) ) { force_sf = 1; move16(); @@ -203,20 +200,20 @@ void lsf_enc_fx( } /*-------------------------------------------------------------------------------------* - * Frame end LSF quantization - *-------------------------------------------------------------------------------------*/ + * Frame end LSF quantization + *-------------------------------------------------------------------------------------*/ #ifdef LSF_RE_USE_SECONDARY_CHANNEL - lsf_end_enc_fx(st_fx, lsf_new, lsf_new, nBits, coder_type, Q_new + QSCALE - 2, - force_sf, NULL, NULL, NULL, st_fx->coder_type_raw_fxtdm_lsfQ_PCh); + lsf_end_enc_fx( st_fx, lsf_new, lsf_new, nBits, coder_type, Q_new + QSCALE - 2, + force_sf, NULL, NULL, NULL, st_fx->coder_type_raw_fxtdm_lsfQ_PCh ); #else - lsf_end_enc_fx( st_fx, lsf_new, lsf_new, nBits, coder_type, Q_new+QSCALE-2, - force_sf, NULL, NULL, NULL, st_fx->coder_type_raw); + lsf_end_enc_fx( st_fx, lsf_new, lsf_new, nBits, coder_type, Q_new + QSCALE - 2, + force_sf, NULL, NULL, NULL, st_fx->coder_type_raw ); #endif /* convert quantized LSFs back to LSPs */ - lsf2lsp_fx( lsf_new, lsp_new, M, int_fs); + lsf2lsp_fx( lsf_new, lsp_new, M, int_fs ); test(); - IF ( EQ_16(st_fx->last_core, HQ_CORE)&&EQ_16(st_fx->core,ACELP_CORE)) + IF( EQ_16( st_fx->last_core, HQ_CORE ) && EQ_16( st_fx->core, ACELP_CORE ) ) { /* don't use old LSF values if this is the first ACELP frame after HQ frames */ Copy( lsf_new, st_fx->lsf_old_fx, M ); @@ -224,27 +221,28 @@ void lsf_enc_fx( /* set seed_acelp used in UC mode */ #ifdef IVAS_CODE test(); - IF (EQ_16(coder_type, UNVOICED) && GT_16(st_fx->element_mode, EVS_MONO)) + IF( EQ_16( coder_type, UNVOICED ) && GT_16( st_fx->element_mode, EVS_MONO ) ) { - st_fx->seed_acelp = 0; move16(); - FOR (i = no_param_lpc - 1; i >= 0; i--) + st_fx->seed_acelp = 0; + move16(); + FOR( i = no_param_lpc - 1; i >= 0; i-- ) { /* rightshift before *seed_acelp+param_lpc[i] to avoid overflows*/ - st->seed_acelp = (int16_t)((((st->seed_acelp) >> 1) + param_lpc[i]) * 31821L + 13849L); + st->seed_acelp = (int16_t) ( ( ( ( st->seed_acelp ) >> 1 ) + param_lpc[i] ) * 31821L + 13849L ); } } #endif - IF ( EQ_32(st_fx->core_brate, SID_2k40)) + IF( EQ_32( st_fx->core_brate, SID_2k40 ) ) { /* return if SID frame (conversion to A(z) done in the calling function) */ return; } /*-------------------------------------------------------------------------------------* - * FEC - enforce safety-net in the next frame in case of unstable filter - *-------------------------------------------------------------------------------------*/ + * FEC - enforce safety-net in the next frame in case of unstable filter + *-------------------------------------------------------------------------------------*/ - IF( NE_16(st_fx->last_L_frame, st_fx->L_frame)) + IF( NE_16( st_fx->last_L_frame, st_fx->L_frame ) ) { /* FEC - in case of core switching, use old LSFs */ Copy( st_fx->lsf_old_fx, st_fx->lsfoldbfi1_fx, M ); @@ -261,12 +259,12 @@ void lsf_enc_fx( test(); test(); /* If decoder FEC frame may be unstable force safety-net usage */ - IF ( (EQ_16(st_fx->L_frame, L_FRAME16k))&&(LT_16(stab,STAB_FAC_LIMIT_FX))&&(EQ_16(coder_type,GENERIC))) + IF( ( EQ_16( st_fx->L_frame, L_FRAME16k ) ) && ( LT_16( stab, STAB_FAC_LIMIT_FX ) ) && ( EQ_16( coder_type, GENERIC ) ) ) { st_fx->next_force_safety_net_fx = 1; move16(); } - ELSE IF((LT_16(stab, STAB_FAC_LIMIT_FX))&&(EQ_16(st_fx->clas,VOICED_CLAS)||(LT_16(st_fx->clas,VOICED_CLAS)&&EQ_16(coder_type,AUDIO)))) + ELSE IF( ( LT_16( stab, STAB_FAC_LIMIT_FX ) ) && ( EQ_16( st_fx->clas, VOICED_CLAS ) || ( LT_16( st_fx->clas, VOICED_CLAS ) && EQ_16( coder_type, AUDIO ) ) ) ) { st_fx->next_force_safety_net_fx = 1; move16(); @@ -274,12 +272,12 @@ void lsf_enc_fx( /* FEC - update adaptive LSF mean vector */ - FOR (i=0; ilsfoldbfi1_fx[i], 10922); /*Q(x2.56+16)*/ - L_tmp = L_mac(L_tmp, st_fx->lsfoldbfi0_fx[i], 10922); /*Q(x2.56+16)*/ - st_fx->lsf_adaptive_mean_fx[i] = round_fx(L_tmp); /*Q(x2.56)*/ + L_tmp = L_mult( lsf_new[i], 10922 ); /*Q(x2.56+16)*/ + L_tmp = L_mac( L_tmp, st_fx->lsfoldbfi1_fx[i], 10922 ); /*Q(x2.56+16)*/ + L_tmp = L_mac( L_tmp, st_fx->lsfoldbfi0_fx[i], 10922 ); /*Q(x2.56+16)*/ + st_fx->lsf_adaptive_mean_fx[i] = round_fx( L_tmp ); /*Q(x2.56)*/ } /* FEC - update LSF memories */ @@ -288,20 +286,20 @@ void lsf_enc_fx( /*-------------------------------------------------------------------------------------* - * Mid-frame LSF encoding - * LSP interpolation and conversion of LSPs to A(z) - *-------------------------------------------------------------------------------------*/ - if(st_fx->rate_switching_reset) + * Mid-frame LSF encoding + * LSP interpolation and conversion of LSPs to A(z) + *-------------------------------------------------------------------------------------*/ + if ( st_fx->rate_switching_reset ) { /*extrapolation in case of unstable LSF convert*/ Copy( lsp_new, st_fx->lsp_old_fx, M ); Copy( lsf_new, st_fx->lsf_old_fx, M ); } /* Mid-frame LSF encoding */ - lsf_mid_enc_fx(st_fx->hBstr, st_fx->acelp_cfg.mid_lsf_bits, int_fs, st_fx->lsp_old_fx, lsp_new, lsp_mid, coder_type, st_fx->bwidth, st_fx->Bin_E_old_fx, st_fx->Bin_E_fx, Q_new+QSCALE-2, ppp_mode, nelp_mode); + lsf_mid_enc_fx( st_fx->hBstr, st_fx->acelp_cfg.mid_lsf_bits, int_fs, st_fx->lsp_old_fx, lsp_new, lsp_mid, coder_type, st_fx->bwidth, st_fx->Bin_E_old_fx, st_fx->Bin_E_fx, Q_new + QSCALE - 2, ppp_mode, nelp_mode ); test(); - IF ( EQ_16(st_fx->last_core,HQ_CORE)&&EQ_16(st_fx->core,ACELP_CORE)) + IF( EQ_16( st_fx->last_core, HQ_CORE ) && EQ_16( st_fx->core, ACELP_CORE ) ) { /* don't use old LSP/LSF values if this is the first ACELP frame after HQ frames */ Copy( lsp_mid, st_fx->lsp_old_fx, M ); @@ -311,54 +309,53 @@ void lsf_enc_fx( /* LSP interpolation and conversion of LSPs to A(z) */ #ifdef ADD_LRTD test(); - IF (EQ_16(tdm_low_rate_mode, 1) && GT_16(coder_type, UNVOICED)) + IF( EQ_16( tdm_low_rate_mode, 1 ) && GT_16( coder_type, UNVOICED ) ) { - IF (EQ_16(st_fx->active_cnt_fx, 1)) + IF( EQ_16( st_fx->active_cnt_fx, 1 ) ) { - Copy(lsp_mid, st_fx->lsp_old_fx, M); - lsp2lsf_fx(lsp_mid, st_fx->lsf_old_fx, M, int_fs); - Copy(lsp_new, lsp_mid, M); + Copy( lsp_mid, st_fx->lsp_old_fx, M ); + lsp2lsf_fx( lsp_mid, st_fx->lsf_old_fx, M, int_fs ); + Copy( lsp_new, lsp_mid, M ); } /* LSP interpolation and conversion of LSPs to A(z) - two-subframe mode */ - int_lsp4_fx(st_fx->L_frame, st_fx->lsp_old_fx, lsp_mid, lsp_new, Aq, M, -2); + int_lsp4_fx( st_fx->L_frame, st_fx->lsp_old_fx, lsp_mid, lsp_new, Aq, M, -2 ); } ELSE #endif { - int_lsp4_fx(st_fx->L_frame, st_fx->lsp_old_fx, lsp_mid, lsp_new, Aq, M, 0); + int_lsp4_fx( st_fx->L_frame, st_fx->lsp_old_fx, lsp_mid, lsp_new, Aq, M, 0 ); } /*------------------------------------------------------------------* - * Check LSF stability (distance between old LSFs and current LSFs) - *------------------------------------------------------------------*/ - IF (NE_32(st_fx->core_brate, SID_2k40)) + * Check LSF stability (distance between old LSFs and current LSFs) + *------------------------------------------------------------------*/ + IF( NE_32( st_fx->core_brate, SID_2k40 ) ) { - st_fx->stab_fac_fx = lsf_stab_fx(lsf_new, st_fx->lsf_old_fx, 0, st_fx->L_frame); + st_fx->stab_fac_fx = lsf_stab_fx( lsf_new, st_fx->lsf_old_fx, 0, st_fx->L_frame ); } return; } /*-------------------------------------------------------------------* -* lsfq_CNG_fx() -* -* LSF quantizer for SID frames (uses 29 bits, 4 for VQ, 25 for LVQ) -* Note: -* The sampling frequency of the LP-CNG frame can be determined by checking the value of the highest order LSF -* coefficient (last coefficient of lsf). If the last LSF coefficient (lsf[M-1]) is larger than 6350 -* the decoded frame is WB2 with sampling rate of 16 kHz, otherwise it is sampled at 12.8kHz and contains -* either NB or WB LSF data. -*-------------------------------------------------------------------*/ + * lsfq_CNG_fx() + * + * LSF quantizer for SID frames (uses 29 bits, 4 for VQ, 25 for LVQ) + * Note: + * The sampling frequency of the LP-CNG frame can be determined by checking the value of the highest order LSF + * coefficient (last coefficient of lsf). If the last LSF coefficient (lsf[M-1]) is larger than 6350 + * the decoded frame is WB2 with sampling rate of 16 kHz, otherwise it is sampled at 12.8kHz and contains + * either NB or WB LSF data. + *-------------------------------------------------------------------*/ static void lsfq_CNG_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 *lsf, /*x2.56 unquantized LSF vector */ - const Word16 *wghts, /*Q10 LSF weights */ - Word16 *qlsf, /*x2.56 quantized LSF vecotor */ + const Word16 *lsf, /*x2.56 unquantized LSF vector */ + const Word16 *wghts, /*Q10 LSF weights */ + Word16 *qlsf, /*x2.56 quantized LSF vecotor */ Word32 *p_offset_scale1, Word32 *p_offset_scale2, - Word16 *p_no_scales -) + Word16 *p_no_scales ) { Word16 i, j, idx_cv, idx_lvq[3]; Word32 min_dist, dist; @@ -376,7 +373,7 @@ static void lsfq_CNG_fx( coefficient (last coefficient of lsf). If the last LSF coefficient (lsf[M-1]) is larger than 6350 the decoded frame is WB2 with sampling rate of 16 kHz, otherwise it is sampled at 12.8kHz and contains either NB or WB LSF data. */ - IF(GT_16(lsf[M - 1], WB_LIMIT_LSF_FX)) /* 16kHz sampled LSF vector*/ + IF( GT_16( lsf[M - 1], WB_LIMIT_LSF_FX ) ) /* 16kHz sampled LSF vector*/ { p_cb = &CNG_SN1_fx[0]; move16(); @@ -387,7 +384,7 @@ static void lsfq_CNG_fx( } ELSE /* 12.8kHz sampled LSF vector*/ { - p_cb = &CNG_SN1_fx[6*M]; + p_cb = &CNG_SN1_fx[6 * M]; move16(); first_cb = 6; move16(); @@ -396,24 +393,24 @@ static void lsfq_CNG_fx( } - min_dist = L_add(MAXINT32, 0); - FOR ( i = first_cb; i < last_cb; i++ ) + min_dist = L_add( MAXINT32, 0 ); + FOR( i = first_cb; i < last_cb; i++ ) { - tmp = sub(*p_cb,shl(lsf[0],1)); /*x2.56 */ - dist = Mult_32_16(L_mult0(wghts[0], *p_cb),tmp); /*Q8 + x2.56 -Q15 + x2.56 = Q-7 + x2.56+x.256 */ + tmp = sub( *p_cb, shl( lsf[0], 1 ) ); /*x2.56 */ + dist = Mult_32_16( L_mult0( wghts[0], *p_cb ), tmp ); /*Q8 + x2.56 -Q15 + x2.56 = Q-7 + x2.56+x.256 */ p_cb++; - FOR (j=1; jhBstr; #ifdef LSF_RE_USE_SECONDARY_CHANNEL - Word16 pred3[M]; + Word16 pred3[M]; Word16 dummy, dummy_v[5]; #endif - flag_1bit_gran = (Word16)GT_16(st->element_mode, EVS_MONO); + flag_1bit_gran = (Word16) GT_16( st->element_mode, EVS_MONO ); nBits = nBits_in; move16(); @@ -611,23 +610,23 @@ void lsf_end_enc_fx( test(); test(); #ifdef LSF_RE_USE_SECONDARY_CHANNEL - IF(EQ_16(coder_type_org, GENERIC) && EQ_32(st->sr_core,INT_FS_16k) && EQ_16(st->codec_mode, MODE1) && (st->idchan == 0)) /* this bit is used only for primary channel or mono */ + IF( EQ_16( coder_type_org, GENERIC ) && EQ_32( st->sr_core, INT_FS_16k ) && EQ_16( st->codec_mode, MODE1 ) && ( st->idchan == 0 ) ) /* this bit is used only for primary channel or mono */ #else - IF(EQ_16(coder_type_org, GENERIC) && EQ_32(st->sr_core, INT_FS_16k) && EQ_16(st->codec_mode, MODE1)) + IF( EQ_16( coder_type_org, GENERIC ) && EQ_32( st->sr_core, INT_FS_16k ) && EQ_16( st->codec_mode, MODE1 ) ) #endif { - IF (EQ_16(coder_type_raw, VOICED)) + IF( EQ_16( coder_type_raw, VOICED ) ) { coder_type = VOICED; move16(); /* Reflect Inactive mode */ - if (EQ_16(flag_1bit_gran, 1)) + if ( EQ_16( flag_1bit_gran, 1 ) ) { - nBits = sub(nBits, 1); /* This is for real Generic*/ + nBits = sub( nBits, 1 ); /* This is for real Generic*/ } } ELSE { - nBits = sub(nBits,1); /* This is for real Generic*/ + nBits = sub( nBits, 1 ); /* This is for real Generic*/ coder_type = coder_type_org; move16(); } @@ -639,94 +638,94 @@ void lsf_end_enc_fx( } /*----------------------------------------------------------------------------------- -* - * Calculate the number of stages and levels for each stage based on allowed bit budget - * Set absolute threshold for codebook-type decision logic depending on signal bandwidth - *------------------------------------------------------------------------------------ -*/ - IF ( EQ_16(st->bwidth, NB)) + * Calculate the number of stages and levels for each stage based on allowed bit budget + * Set absolute threshold for codebook-type decision logic depending on signal bandwidth + *------------------------------------------------------------------------------------ -*/ + IF( EQ_16( st->bwidth, NB ) ) { - abs_threshold = L_add(SFNETLOWLIMIT_NB, 0); + abs_threshold = L_add( SFNETLOWLIMIT_NB, 0 ); } ELSE { - abs_threshold = L_add(SFNETLOWLIMIT_WB, 0); + abs_threshold = L_add( SFNETLOWLIMIT_WB, 0 ); } /* Calculate LSF weighting coefficients */ - Unified_weighting_fx(&st->Bin_E_fx[L_FFT/2], Q_ener, lsf, wghts, (Word16)EQ_16(st->bwidth, NB), (Word16)EQ_16(coder_type,UNVOICED),st->sr_core,M); + Unified_weighting_fx( &st->Bin_E_fx[L_FFT / 2], Q_ener, lsf, wghts, (Word16) EQ_16( st->bwidth, NB ), (Word16) EQ_16( coder_type, UNVOICED ), st->sr_core, M ); /*--------------------------------------------------------------------------------* - * LSF quantization of SID frames - *--------------------------------------------------------------------------------*/ - IF ( EQ_32(st->core_brate, SID_2k40)) + * LSF quantization of SID frames + *--------------------------------------------------------------------------------*/ + IF( EQ_32( st->core_brate, SID_2k40 ) ) { - lsfq_CNG_fx(hBstr, lsf, wghts, qlsf, &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->no_scales_fx[0][0] ); - sort_fx( qlsf, 0, M-1 ); + lsfq_CNG_fx( hBstr, lsf, wghts, qlsf, &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->no_scales_fx[0][0] ); + sort_fx( qlsf, 0, M - 1 ); reorder_lsf_fx( qlsf, MODE1_LSF_GAP_FX, M, st->sr_core ); return; } /* Find allowed predictor mode for current coder_type. (SN only (0), SN/AR switched (2) or MA predictive (1) */ - find_pred_mode(&predmode, coder_type, st->bwidth, st->sr_core, &mode_lvq, &mode_lvq_p,st->total_brate); + find_pred_mode( &predmode, coder_type, st->bwidth, st->sr_core, &mode_lvq, &mode_lvq_p, st->total_brate ); /*----------------------------------------------------------------* - * Calculate number of stages and levels for each stage based on the allowed bit allocation - * (subtract one bit for LSF predictor selection) - *----------------------------------------------------------------*/ - lsf_allocate_fx( sub(nBits, shr(predmode,1)), mode_lvq, mode_lvq_p, &stages0, &stages1, levels0, levels1, bits0, bits1); + * Calculate number of stages and levels for each stage based on the allowed bit allocation + * (subtract one bit for LSF predictor selection) + *----------------------------------------------------------------*/ + lsf_allocate_fx( sub( nBits, shr( predmode, 1 ) ), mode_lvq, mode_lvq_p, &stages0, &stages1, levels0, levels1, bits0, bits1 ); /*--------------------------------------------------------------------------------* - * LSF quantization of all other frames but SID frames - * Select safety-net or predictive mode - *--------------------------------------------------------------------------------*/ + * LSF quantization of all other frames but SID frames + * Select safety-net or predictive mode + *--------------------------------------------------------------------------------*/ Err[0] = MAXINT32; move32(); Err[1] = MAXINT32; move32(); /* for mem_MA update */ - FOR (i=0; imem_MA_fx[i])); + pred1[i] = add( ModeMeans_fx[mode_lvq][i], mult_r( MU_MA_FX, st->mem_MA_fx[i] ) ); move16(); } #ifdef LSF_RE_USE_SECONDARY_CHANNEL /* TD stereo SCh: perform intra-frame prediction with pulling-to-mean */ - if (st->tdm_LRTD_flag == 0 && st->idchan == 1 && tdm_lsfQ_PCh != NULL) + if ( st->tdm_LRTD_flag == 0 && st->idchan == 1 && tdm_lsfQ_PCh != NULL ) { /* if secondary channel predmode is set to be > 2 */ predmode += 3; - tdm_SCh_LSF_intra_pred(st->element_brate, tdm_lsfQ_PCh, pred3); + tdm_SCh_LSF_intra_pred( st->element_brate, tdm_lsfQ_PCh, pred3 ); } #endif - IF ( predmode == 0 ) + IF( predmode == 0 ) { /* Subtract only mean */ - Copy(ModeMeans_fx[mode_lvq], pred0, M); - Vr_subt(lsf, pred0, Tmp, M); + Copy( ModeMeans_fx[mode_lvq], pred0, M ); + Vr_subt( lsf, pred0, Tmp, M ); /* LVQ quantization (safety-net only) */ - Err[0] = vq_lvq_lsf_enc(0, mode_lvq, Tmp, levels0, stages0,wghts, Idx0, lsf, pred0, - st->offset_scale1_fx,st->offset_scale2_fx, st->no_scales_fx, resq, lsfq); + Err[0] = vq_lvq_lsf_enc( 0, mode_lvq, Tmp, levels0, stages0, wghts, Idx0, lsf, pred0, + st->offset_scale1_fx, st->offset_scale2_fx, st->no_scales_fx, resq, lsfq ); safety_net = 1; move16(); st->pstreaklen_fx = 0; - move16();/* predictive LSF quantizer streak is ended with safety-net */ + move16(); /* predictive LSF quantizer streak is ended with safety-net */ } - ELSE IF (EQ_16(predmode, 1)) /* only MA prediction */ + ELSE IF( EQ_16( predmode, 1 ) ) /* only MA prediction */ { - Vr_subt(lsf, pred1, Tmp1, M); - Err[1] = vq_lvq_lsf_enc(2, mode_lvq_p, Tmp1, levels1, stages1, wghts, Idx1, lsf, pred1, - st->offset_scale1_p_fx,st->offset_scale2_p_fx,st->no_scales_p_fx,resq, lsfq ); + Vr_subt( lsf, pred1, Tmp1, M ); + Err[1] = vq_lvq_lsf_enc( 2, mode_lvq_p, Tmp1, levels1, stages1, wghts, Idx1, lsf, pred1, + st->offset_scale1_p_fx, st->offset_scale2_p_fx, st->no_scales_p_fx, resq, lsfq ); safety_net = 0; move16(); } ELSE #ifdef LSF_RE_USE_SECONDARY_CHANNEL - PMT("LSF_RE_USE_SECONDARY_CHANNEL CODE IS MISSING ") - { - if (predmode == 2) + PMT( "LSF_RE_USE_SECONDARY_CHANNEL CODE IS MISSING " ) + { + if ( predmode == 2 ) #endif { /* Adaptive scaling factor (multiplier) is updated in order to reduce the amount of consecutive predictive frames in @@ -734,56 +733,57 @@ void lsf_end_enc_fx( test(); test(); test(); - IF ( ((GT_16(st->pstreaklen_fx, (STREAKLEN+3))) && (EQ_16(coder_type,VOICED))) || ((GT_16(st->pstreaklen_fx,(STREAKLEN))) && (NE_16(coder_type,VOICED)))) + IF( ( ( GT_16( st->pstreaklen_fx, ( STREAKLEN + 3 ) ) ) && ( EQ_16( coder_type, VOICED ) ) ) || ( ( GT_16( st->pstreaklen_fx, ( STREAKLEN ) ) ) && ( NE_16( coder_type, VOICED ) ) ) ) { /* update the adaptive scaling factor to become smaller with increasing number of concecutive predictive frames. */ - st->streaklimit_fx = mult(st->streaklimit_fx,STREAKMULT_FX); + st->streaklimit_fx = mult( st->streaklimit_fx, STREAKMULT_FX ); move16(); } - IF (st->pstreaklen_fx == 0 ) + IF( st->pstreaklen_fx == 0 ) { /* reset the consecutive AR-predictor multiplier */ - st->streaklimit_fx = 32767; /*1.0 in Q15 */ move16(); + st->streaklimit_fx = 32767; /*1.0 in Q15 */ + move16(); } /* VOICED_WB@16kHz */ test(); - IF ( EQ_32(st->sr_core, INT_FS_16k)&&EQ_16(coder_type,VOICED) && flag_1bit_gran == 0) + IF( EQ_32( st->sr_core, INT_FS_16k ) && EQ_16( coder_type, VOICED ) && flag_1bit_gran == 0 ) { /* Subtract mean and AR prediction */ Copy( ModeMeans_fx[mode_lvq], pred0, M ); /* subtract only mean */ - Vr_subt(lsf, pred0, Tmp, M); + Vr_subt( lsf, pred0, Tmp, M ); - FOR (i = 0; i < M; i++) + FOR( i = 0; i < M; i++ ) { /* subtract mean and AR prediction */ - pred2[i] = mult(Predictors_fx[mode_lvq_p][i],sub(st->mem_AR_fx[i],pred0[i])); - Tmp2[i] = sub(Tmp[i], pred2[i]); - pred2[i] = add(pred2[i], pred0[i]); + pred2[i] = mult( Predictors_fx[mode_lvq_p][i], sub( st->mem_AR_fx[i], pred0[i] ) ); + Tmp2[i] = sub( Tmp[i], pred2[i] ); + pred2[i] = add( pred2[i], pred0[i] ); } /* select safety_net or predictive */ safety_net = qlsf_Mode_Select_fx( wghts, Tmp2, st->streaklimit_fx, OP_LOOP_THR_HVO ); - IF ( EQ_16(force_sf, 1)) + IF( EQ_16( force_sf, 1 ) ) { safety_net = 1; move16(); } - IF ( safety_net ) + IF( safety_net ) { /* Safety-net - BC-TCQ quantization : SN */ - Err[0] = qlsf_ARSN_tcvq_Enc_16k_fx( Tmp, lsfq, TCQIdx0, wghts, sub(nBits,1), safety_net); + Err[0] = qlsf_ARSN_tcvq_Enc_16k_fx( Tmp, lsfq, TCQIdx0, wghts, sub( nBits, 1 ), safety_net ); st->pstreaklen_fx = 0; move16(); } ELSE { /* predictive - BC-TCQ quantization : AR */ - Err[1] = qlsf_ARSN_tcvq_Enc_16k_fx( Tmp2, lsfq, TCQIdx0, wghts, sub(nBits,1), safety_net); - st->pstreaklen_fx =add(st->pstreaklen_fx,1); + Err[1] = qlsf_ARSN_tcvq_Enc_16k_fx( Tmp2, lsfq, TCQIdx0, wghts, sub( nBits, 1 ), safety_net ); + st->pstreaklen_fx = add( st->pstreaklen_fx, 1 ); } } /* all other frames (not VOICED@16kHz) */ @@ -792,24 +792,23 @@ void lsf_end_enc_fx( /* Subtract mean and AR prediction */ Copy( ModeMeans_fx[mode_lvq], pred0, M ); /* subtract only mean */ - Vr_subt(lsf, pred0, Tmp, M); + Vr_subt( lsf, pred0, Tmp, M ); - FOR (i = 0; i < M; i++) + FOR( i = 0; i < M; i++ ) { /* subtract mean and AR prediction */ - pred2[i] = add(pred0[i],mult(Predictors_fx[mode_lvq_p][i],sub(st->mem_AR_fx[i],pred0[i]))); - Tmp2[i] = sub(lsf[i], pred2[i]); + pred2[i] = add( pred0[i], mult( Predictors_fx[mode_lvq_p][i], sub( st->mem_AR_fx[i], pred0[i] ) ) ); + Tmp2[i] = sub( lsf[i], pred2[i] ); } /* safety-net */ - Err[0] = vq_lvq_lsf_enc(0, mode_lvq, Tmp, levels0, stages0, wghts, Idx0, lsf, pred0, st->offset_scale1_fx,st->offset_scale2_fx,st->no_scales_fx, resq, lsfq); + Err[0] = vq_lvq_lsf_enc( 0, mode_lvq, Tmp, levels0, stages0, wghts, Idx0, lsf, pred0, st->offset_scale1_fx, st->offset_scale2_fx, st->no_scales_fx, resq, lsfq ); /* Predictive quantizer is calculated only if it can be selected */ test(); - IF (!force_sf || GT_32(Err[0],abs_threshold)) + IF( !force_sf || GT_32( Err[0], abs_threshold ) ) { - Err[1] = vq_lvq_lsf_enc(2, mode_lvq_p, Tmp2, levels1, stages1, wghts, Idx1, lsf, pred2, - st->offset_scale1_p_fx, st->offset_scale2_p_fx, st->no_scales_p_fx, &resq[M], &lsfq[M]); - + Err[1] = vq_lvq_lsf_enc( 2, mode_lvq_p, Tmp2, levels1, stages1, wghts, Idx1, lsf, pred2, + st->offset_scale1_p_fx, st->offset_scale2_p_fx, st->no_scales_p_fx, &resq[M], &lsfq[M] ); } test(); test(); @@ -817,7 +816,7 @@ void lsf_end_enc_fx( if the non-predictive (safety-net) quantization error (Err[0]) is low enough (spectral distortion is low) it is selected or if the predictively quantized error (Err[1]) is by at least adaptive margin smaller than non-predictive quantizer. or if the in case of frame erasure the resulting concealed predictive LSF would be unstable safety-net is selected */ - IF ( force_sf || LT_32(Mult_32_16(Err[0],(st->streaklimit_fx)),L_add(Err[1],Mult_32_16(Err[1],PREFERSFNET_FX))) || LT_32(Err[0],abs_threshold)) + IF( force_sf || LT_32( Mult_32_16( Err[0], ( st->streaklimit_fx ) ), L_add( Err[1], Mult_32_16( Err[1], PREFERSFNET_FX ) ) ) || LT_32( Err[0], abs_threshold ) ) { safety_net = 1; move16(); @@ -828,38 +827,38 @@ void lsf_end_enc_fx( { safety_net = 0; move16(); /* Increase the consecutive predictive frame counter by one */ - st->pstreaklen_fx = add(st->pstreaklen_fx,1); + st->pstreaklen_fx = add( st->pstreaklen_fx, 1 ); } } } #ifdef LSF_RE_USE_SECONDARY_CHANNEL - PMT("LSF_RE_USE_SECONDARY_CHANNEL CODE IS MISSING ") + PMT( "LSF_RE_USE_SECONDARY_CHANNEL CODE IS MISSING " ) else /* of "if (predmode==2)" */ { - mvr2r(ModeMeans[mode_lvq], pred0, M); + mvr2r( ModeMeans[mode_lvq], pred0, M ); - if (predmode == 4) + if ( predmode == 4 ) { mode_lvq_p = 9; /* force to Generic WB with AR*/ } - for (i = 0; i < M; i++) + for ( i = 0; i < M; i++ ) { /* subtract mean and AR prediction */ - pred2[i] = pred0[i] + Predictors[mode_lvq_p][i] * (st->mem_AR[i] - pred0[i]); + pred2[i] = pred0[i] + Predictors[mode_lvq_p][i] * ( st->mem_AR[i] - pred0[i] ); Tmp[i] = lsf[i] - pred2[i]; Tmp2[i] = lsf[i] - pred3[i]; } /* Adaptive scaling factor (multiplier) is updated in order to reduce the amount of consecutive predictive frames in case of possible frame erasure. AR-predictive usage for VOICED mode is allowed to be higher than other modes. */ - if (st->pstreaklen > (STREAKLEN)) + if ( st->pstreaklen > ( STREAKLEN ) ) { /* update the adaptive scaling factor to become smaller with increasing number of concecutive predictive frames. */ st->streaklimit *= STREAKMULT; } - if (st->pstreaklen == 0) + if ( st->pstreaklen == 0 ) { /* reset the adaptive scaling factor */ st->streaklimit = 1.0f; @@ -868,11 +867,11 @@ void lsf_end_enc_fx( /* intra pred */ /* use G AR pred for the intra mode (as a safety mode, this is why the indexes 0/1 are interchanged)*/ - lsf_allocate(nBits - 1, mode_lvq, 9, &stages1, &stages0, levels1, levels0, bits1, bits0); + lsf_allocate( nBits - 1, mode_lvq, 9, &stages1, &stages0, levels1, levels0, bits1, bits0 ); - Err[0] = vq_lvq_lsf_enc(2, 9, Tmp2, levels0, stages0, wghts, Idx0, lsf, pred3, &resq[M], &lsfq[M]); + Err[0] = vq_lvq_lsf_enc( 2, 9, Tmp2, levels0, stages0, wghts, Idx0, lsf, pred3, &resq[M], &lsfq[M] ); - if (force_sf) + if ( force_sf ) { safety_net = 1; /* intra-frame prediction */ st->pstreaklen = 0; /* Reset the consecutive predictive frame counter */ @@ -881,12 +880,12 @@ void lsf_end_enc_fx( { /* try also the inter frame prediction */ /* AR inter-frame prediction */ - lsf_allocate(nBits - 1, mode_lvq, mode_lvq_p, &dummy, &stages1, dummy_v, levels1, dummy_v, bits1); + lsf_allocate( nBits - 1, mode_lvq, mode_lvq_p, &dummy, &stages1, dummy_v, levels1, dummy_v, bits1 ); - Err[1] = vq_lvq_lsf_enc(2, mode_lvq_p, Tmp, levels1, stages1, wghts, Idx1, lsf, pred2, resq, lsfq); + Err[1] = vq_lvq_lsf_enc( 2, mode_lvq_p, Tmp, levels1, stages1, wghts, Idx1, lsf, pred2, resq, lsfq ); - if (Err[0] * (st->streaklimit) < PREFERSFNET * Err[1]) + if ( Err[0] * ( st->streaklimit ) < PREFERSFNET * Err[1] ) { safety_net = 1; st->pstreaklen = 0; /* Reset the consecutive predictive frame counter */ @@ -894,48 +893,48 @@ void lsf_end_enc_fx( else { safety_net = 0; - (st->pstreaklen)++; /* Increase the consecutive predictive frame counter by one */ + ( st->pstreaklen )++; /* Increase the consecutive predictive frame counter by one */ } } } } -#endif /*--------------------------------------------------------------------------* - * Write indices to array - *--------------------------------------------------------------------------*/ +#endif /*--------------------------------------------------------------------------* \ + * Write indices to array \ + *--------------------------------------------------------------------------*/ - IF (EQ_16(st->codec_mode, MODE1) && EQ_16(st->core, ACELP_CORE)) + IF( EQ_16( st->codec_mode, MODE1 ) && EQ_16( st->core, ACELP_CORE ) ) { /* write coder_type bit for VOICED@16kHz or GENERIC@16kHz */ test(); #ifdef LSF_RE_USE_SECONDARY_CHANNEL - IF(EQ_16(coder_type_org, GENERIC)&&EQ_32(st->sr_core,INT_FS_16k) && (st->idchan == 0)) + IF( EQ_16( coder_type_org, GENERIC ) && EQ_32( st->sr_core, INT_FS_16k ) && ( st->idchan == 0 ) ) #else - IF(EQ_16(coder_type_org, GENERIC) && EQ_32(st->sr_core, INT_FS_16k) ) + IF( EQ_16( coder_type_org, GENERIC ) && EQ_32( st->sr_core, INT_FS_16k ) ) #endif { /* VOICED =2 and GENERIC=3, so "coder_type-2" means VOICED =0 and GENERIC=1*/ - push_indice_fx( hBstr, IND_LSF_PREDICTOR_SELECT_BIT, sub(coder_type,2), 1 ); + push_indice_fx( hBstr, IND_LSF_PREDICTOR_SELECT_BIT, sub( coder_type, 2 ), 1 ); } /* write predictor selection bit */ #ifdef LSF_RE_USE_SECONDARY_CHANNEL - IF(GE(predmode, 2)) + IF( GE( predmode, 2 ) ) #else - IF ( EQ_16(predmode, 2)) + IF( EQ_16( predmode, 2 ) ) #endif { push_indice_fx( st->hBstr, IND_LSF_PREDICTOR_SELECT_BIT, safety_net, 1 ); } test(); - IF ( EQ_16(coder_type, VOICED) && EQ_32(st->sr_core,INT_FS_16k) && flag_1bit_gran == 0) + IF( EQ_16( coder_type, VOICED ) && EQ_32( st->sr_core, INT_FS_16k ) && flag_1bit_gran == 0 ) { /* BC-TCVQ (only for VOICED@16kHz) */ TCQIdx = &TCQIdx0[1]; Bit_alloc1 = &BC_TCVQ_BIT_ALLOC_40B[1]; - FOR( i=0; i<(M/2)+3; i++ ) + FOR( i = 0; i < ( M / 2 ) + 3; i++ ) { - push_indice_fx( hBstr, IND_LSF, TCQIdx[i], Bit_alloc1[i]); + push_indice_fx( hBstr, IND_LSF, TCQIdx[i], Bit_alloc1[i] ); } } ELSE @@ -943,16 +942,16 @@ void lsf_end_enc_fx( cumleft = nBits; move16(); #ifdef LSF_RE_USE_SECONDARY_CHANNEL - IF(GE(predmode, 2)) + IF( GE( predmode, 2 ) ) #else - IF (EQ_16( predmode, 2 )) + IF( EQ_16( predmode, 2 ) ) #endif { /* subtract predictor selection bit */ - cumleft = sub(nBits, 1); + cumleft = sub( nBits, 1 ); } - IF ( safety_net ) + IF( safety_net ) { stages = stages0; move16(); @@ -971,8 +970,8 @@ void lsf_end_enc_fx( move16(); } - tmp = sub(stages,1); - FOR ( i=0; i 0 ) + WHILE( cumleft > 0 ) { indice[i] = Idx[i]; move16(); - IF ( GT_16(cumleft, LEN_INDICE)) + IF( GT_16( cumleft, LEN_INDICE ) ) { num_bits = LEN_INDICE; move16(); @@ -999,22 +998,22 @@ void lsf_end_enc_fx( move16(); } - cumleft = sub(cumleft, num_bits); + cumleft = sub( cumleft, num_bits ); push_indice_fx( hBstr, IND_LSF, indice[i], num_bits ); - i=add(i,1); + i = add( i, 1 ); } } } ELSE { test(); - IF ( EQ_16(coder_type, VOICED)&&EQ_32(st->sr_core,INT_FS_16k)) + IF( EQ_16( coder_type, VOICED ) && EQ_32( st->sr_core, INT_FS_16k ) ) { /* BC-TCVQ (only for VOICED@16kHz) */ /* Number of quantization indices */ *no_indices = 10; move16(); - FOR(i=0; i<*no_indices; i++) + FOR( i = 0; i < *no_indices; i++ ) { lpc_param[i] = TCQIdx0[i]; move16(); @@ -1027,12 +1026,12 @@ void lsf_end_enc_fx( /* Number of quantization indices */ /* there are 31 bits */ - IF (EQ_16(safety_net, 1)) + IF( EQ_16( safety_net, 1 ) ) { Idx = Idx0; move16(); - *no_indices = add(stages0 ,1); - FOR( i=0; i0; i--) + FOR( i = *no_indices; i > 0; i-- ) { - tmp = sub(i,1); + tmp = sub( i, 1 ); lpc_param[i] = lpc_param[tmp]; move16(); bits_param_lpc[i] = bits_param_lpc[tmp]; move16(); } lpc_param[0] = safety_net; - move16();/* put the safety net info on the last param */ + move16(); /* put the safety net info on the last param */ bits_param_lpc[0] = 1; move16(); - *no_indices = add(*no_indices,1); + *no_indices = add( *no_indices, 1 ); } } } /*--------------------------------------------------------------------------* - * De-quantize encoded LSF vector - *--------------------------------------------------------------------------*/ + * De-quantize encoded LSF vector + *--------------------------------------------------------------------------*/ - IF ( safety_net ) + IF( safety_net ) { /* Safety-net */ test(); - IF ( EQ_16(coder_type, VOICED) && EQ_32(st->sr_core,INT_FS_16k) && flag_1bit_gran == 0) + IF( EQ_16( coder_type, VOICED ) && EQ_32( st->sr_core, INT_FS_16k ) && flag_1bit_gran == 0 ) { /* BC-TCQ */ Copy( lsfq, st->mem_MA_fx, M ); @@ -1111,28 +1109,28 @@ void lsf_end_enc_fx( ELSE { #ifdef LSF_RE_USE_SECONDARY_CHANNEL - if (st->tdm_LRTD_flag == 0 && st->idchan == 1 && tdm_lsfQ_PCh != NULL) + if ( st->tdm_LRTD_flag == 0 && st->idchan == 1 && tdm_lsfQ_PCh != NULL ) { /* intra mode*/ - vq_dec_lvq(0, qlsf, &indice[0], stages0, M, 9, /*mode_lvq_p,*/ levels0[stages0 - 1]); - v_add(qlsf, pred3, qlsf, M); - v_sub(qlsf, pred1, st->mem_MA, M); + vq_dec_lvq( 0, qlsf, &indice[0], stages0, M, 9, /*mode_lvq_p,*/ levels0[stages0 - 1] ); + v_add( qlsf, pred3, qlsf, M ); + v_sub( qlsf, pred1, st->mem_MA, M ); } else #endif { - vq_dec_lvq_fx(1, qlsf, &indice[0], stages0, M, mode_lvq, levels0[stages0 - 1], - &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->offset_scale1_p_fx[0][0], &st->offset_scale2_p_fx[0][0], - &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0]); - Vr_add(qlsf, pred0, qlsf, M); - Vr_subt(qlsf, pred1, st->mem_MA_fx, M); + vq_dec_lvq_fx( 1, qlsf, &indice[0], stages0, M, mode_lvq, levels0[stages0 - 1], + &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->offset_scale1_p_fx[0][0], &st->offset_scale2_p_fx[0][0], + &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0] ); + Vr_add( qlsf, pred0, qlsf, M ); + Vr_subt( qlsf, pred1, st->mem_MA_fx, M ); } } } ELSE { test(); - IF ( EQ_16(coder_type, VOICED) && EQ_32(st->sr_core,INT_FS_16k) && flag_1bit_gran == 0) + IF( EQ_16( coder_type, VOICED ) && EQ_32( st->sr_core, INT_FS_16k ) && flag_1bit_gran == 0 ) { /* BC-TCVQ */ Copy( lsfq, st->mem_MA_fx, M ); @@ -1141,24 +1139,24 @@ void lsf_end_enc_fx( ELSE { /* LVQ */ - vq_dec_lvq_fx( 0, qlsf, &indice[0], stages1, M, mode_lvq_p, levels1[stages1-1], - &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->offset_scale1_p_fx[0][0], - &st->offset_scale2_p_fx[0][0], &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0] ); - IF (EQ_16(predmode,1)) + vq_dec_lvq_fx( 0, qlsf, &indice[0], stages1, M, mode_lvq_p, levels1[stages1 - 1], + &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->offset_scale1_p_fx[0][0], + &st->offset_scale2_p_fx[0][0], &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0] ); + IF( EQ_16( predmode, 1 ) ) { - Copy(qlsf, st->mem_MA_fx, M); + Copy( qlsf, st->mem_MA_fx, M ); Vr_add( qlsf, pred1, qlsf, M ); } ELSE { Vr_add( qlsf, pred2, qlsf, M ); - Vr_subt(qlsf, pred1, st->mem_MA_fx, M); + Vr_subt( qlsf, pred1, st->mem_MA_fx, M ); } } } /* Sort the quantized vector to ascending order */ - sort_fx( qlsf, 0, M-1 ); + sort_fx( qlsf, 0, M - 1 ); /* Verify stability by adding minimum separation */ reorder_lsf_fx( qlsf, MODE1_LSF_GAP_FX, M, st->sr_core ); @@ -1169,31 +1167,28 @@ void lsf_end_enc_fx( } - - /*-------------------------------------------------------------------* -* first_VQstages() -* -* -*-------------------------------------------------------------------*/ + * first_VQstages() + * + * + *-------------------------------------------------------------------*/ static void first_VQstages( - const Word16 * const *cb, - Word16 u[], /* i : vector to be encoded (prediction and mean removed) */ - Word16 *levels, /* i : number of levels in each stage */ - Word16 stagesVQ, /* i : number of stages */ - Word16 w[], /* i : weights */ - Word16 N, /* i : vector dimension */ - Word16 max_inner, /* i : maximum number of swaps in inner loop */ - Word16 indices_VQstage[] -) + const Word16 *const *cb, + Word16 u[], /* i : vector to be encoded (prediction and mean removed) */ + Word16 *levels, /* i : number of levels in each stage */ + Word16 stagesVQ, /* i : number of stages */ + Word16 w[], /* i : weights */ + Word16 N, /* i : vector dimension */ + Word16 max_inner, /* i : maximum number of swaps in inner loop */ + Word16 indices_VQstage[] ) { - Word16 resid_buf[2*LSFMBEST*M], *resid[2]; - Word32 dist_buf[2*LSFMBEST], *dist[2], en; + Word16 resid_buf[2 * LSFMBEST * M], *resid[2]; + Word32 dist_buf[2 * LSFMBEST], *dist[2], en; Word32 f_tmp, L_tmp, L_tmp1, *pTmp32; Word16 Tmp[M], *pTmp, cs; - Word16 *pTmp_short, idx_buf[2*LSFMBEST*MAX_VQ_STAGES], parents[LSFMBEST], counter=0, j, - m, s,c, c2, p_max, *indices[2]; + Word16 *pTmp_short, idx_buf[2 * LSFMBEST * MAX_VQ_STAGES], parents[LSFMBEST], counter = 0, j, + m, s, c, c2, p_max, *indices[2]; Word16 maxC = LSFMBEST; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; @@ -1205,33 +1200,33 @@ static void first_VQstages( /* Set pointers to previous (parent) and current node (parent node is indexed [0], current node is indexed [1]) */ indices[0] = idx_buf; move16(); - indices[1] = idx_buf + maxC*stagesVQ; + indices[1] = idx_buf + maxC * stagesVQ; move16(); resid[0] = resid_buf; move16(); - resid[1] = resid_buf + maxC*N; + resid[1] = resid_buf + maxC * N; move16(); dist[0] = dist_buf; move16(); dist[1] = dist_buf + maxC; move16(); - set16_fx( idx_buf, 0, (const Word16)(2*stagesVQ*maxC) ); - set16_fx( parents, 0, maxC ) ; + set16_fx( idx_buf, 0, ( const Word16 )( 2 * stagesVQ * maxC ) ); + set16_fx( parents, 0, maxC ); /* Set up inital distance vector */ - L_tmp = L_deposit_l(0); - FOR( j=0; j0) + mode_glb = add( offset_lvq_modes_pred_fx[mode], offset_in_lvq_mode_pred_fx[mode][sub( levels[stagesVQ], min_lat_bits_pred_fx[mode] )] ); + } + IF( stagesVQ > 0 ) { /* first VQ stages */ first_VQstages( cb, u, levels, stagesVQ, w, M, MSVQ_MAXCNT, indices_firstVQ ); } - FOR ( i=0; i= 0; stage --) + FOR( stage = N_STAGE_VQ - 5; stage >= 0; stage-- ) { bestCodeword[stage] = codeWord[stage][prev_state]; move16(); - bestState[stage] = preState[stage][prev_state]; + bestState[stage] = preState[stage][prev_state]; move16(); - prev_state = bestState[stage]; + prev_state = bestState[stage]; move16(); } - FOR (stage = 0; stage < 4; stage ++) + FOR( stage = 0; stage < 4; stage++ ) { bestCodeword[stage + 4] = blockCodeword[fBlock][stage]; move16(); @@ -1933,63 +1925,62 @@ static void quantEnc_fx( const Word16 CB_SUB1_fx[][128][2], const Word16 CB_SUB2_fx[][64][2], const Word16 CB_SUB3_fx[][32][2], - const Word16 itc_fx[][2][2] -) + const Word16 itc_fx[][2][2] ) { - Word16 i,j; + Word16 i, j; Word16 stage; Word16 pred_fx[N_DIM], Y_fx[8][2]; /* stage #1 */ - Y_fx[0][0] = CB_SUB1_fx[0][c[0]][0]; + Y_fx[0][0] = CB_SUB1_fx[0][c[0]][0]; move16(); - Y_fx[0][1] = CB_SUB1_fx[0][c[0]][1]; + Y_fx[0][1] = CB_SUB1_fx[0][c[0]][1]; move16(); /* stage #2 */ - pred_fx[0] = add(mult_r(itc_fx[0][0][0], Y_fx[0][0]), mult_r(itc_fx[0][0][1], Y_fx[0][1])); + pred_fx[0] = add( mult_r( itc_fx[0][0][0], Y_fx[0][0] ), mult_r( itc_fx[0][0][1], Y_fx[0][1] ) ); move16(); - pred_fx[1] = add(mult_r(itc_fx[0][1][0], Y_fx[0][0]), mult_r(itc_fx[0][1][1], Y_fx[0][1])); + pred_fx[1] = add( mult_r( itc_fx[0][1][0], Y_fx[0][0] ), mult_r( itc_fx[0][1][1], Y_fx[0][1] ) ); move16(); - Y_fx[1][0] = add(CB_SUB1_fx[1][c[1]][0], pred_fx[0]); + Y_fx[1][0] = add( CB_SUB1_fx[1][c[1]][0], pred_fx[0] ); move16(); - Y_fx[1][1] = add(CB_SUB1_fx[1][c[1]][1], pred_fx[1]); + Y_fx[1][1] = add( CB_SUB1_fx[1][c[1]][1], pred_fx[1] ); move16(); /* stage #3 - #4 */ - FOR (stage = 2; stage < N_STAGE_VQ-4; stage ++) + FOR( stage = 2; stage < N_STAGE_VQ - 4; stage++ ) { - pred_fx[0] = add(mult_r(itc_fx[stage-1][0][0], Y_fx[stage-1][0]), mult_r(itc_fx[stage-1][0][1], Y_fx[stage-1][1])); + pred_fx[0] = add( mult_r( itc_fx[stage - 1][0][0], Y_fx[stage - 1][0] ), mult_r( itc_fx[stage - 1][0][1], Y_fx[stage - 1][1] ) ); move16(); - pred_fx[1] = add(mult_r(itc_fx[stage-1][1][0], Y_fx[stage-1][0]), mult_r(itc_fx[stage-1][1][1], Y_fx[stage-1][1])); + pred_fx[1] = add( mult_r( itc_fx[stage - 1][1][0], Y_fx[stage - 1][0] ), mult_r( itc_fx[stage - 1][1][1], Y_fx[stage - 1][1] ) ); move16(); - Y_fx[stage][0] = add(CB_SUB2_fx[stage-2][c[stage]][0], pred_fx[0]); + Y_fx[stage][0] = add( CB_SUB2_fx[stage - 2][c[stage]][0], pred_fx[0] ); move16(); - Y_fx[stage][1] = add(CB_SUB2_fx[stage-2][c[stage]][1], pred_fx[1]); + Y_fx[stage][1] = add( CB_SUB2_fx[stage - 2][c[stage]][1], pred_fx[1] ); move16(); } /* stage #5 - #8 */ - FOR (stage = N_STAGE_VQ-4; stage < N_STAGE_VQ; stage ++) + FOR( stage = N_STAGE_VQ - 4; stage < N_STAGE_VQ; stage++ ) { - pred_fx[0] = add(mult_r(itc_fx[stage-1][0][0], Y_fx[stage-1][0]), mult_r(itc_fx[stage-1][0][1], Y_fx[stage-1][1])); + pred_fx[0] = add( mult_r( itc_fx[stage - 1][0][0], Y_fx[stage - 1][0] ), mult_r( itc_fx[stage - 1][0][1], Y_fx[stage - 1][1] ) ); move16(); - pred_fx[1] = add(mult_r(itc_fx[stage-1][1][0], Y_fx[stage-1][0]), mult_r(itc_fx[stage-1][1][1], Y_fx[stage-1][1])); + pred_fx[1] = add( mult_r( itc_fx[stage - 1][1][0], Y_fx[stage - 1][0] ), mult_r( itc_fx[stage - 1][1][1], Y_fx[stage - 1][1] ) ); move16(); - Y_fx[stage][0] = add(CB_SUB3_fx[stage-4][c[stage]][0], pred_fx[0]); + Y_fx[stage][0] = add( CB_SUB3_fx[stage - 4][c[stage]][0], pred_fx[0] ); move16(); - Y_fx[stage][1] = add(CB_SUB3_fx[stage-4][c[stage]][1], pred_fx[1]); + Y_fx[stage][1] = add( CB_SUB3_fx[stage - 4][c[stage]][1], pred_fx[1] ); move16(); } /* Transform Vector to Scalar */ - FOR (i = 0; i < N_STAGE_VQ; i++) + FOR( i = 0; i < N_STAGE_VQ; i++ ) { - FOR (j = 0; j < N_DIM; j++) + FOR( j = 0; j < N_DIM; j++ ) { - y_fx[i*N_DIM+j] = Y_fx[i][j]; + y_fx[i * N_DIM + j] = Y_fx[i][j]; move16(); } } @@ -2001,20 +1992,19 @@ static void buildCode_fx( Word16 *ind, Word16 fins, Word16 c[], - Word16 s[] -) + Word16 s[] ) { Word16 stage; Word16 BrIndex[4]; - set16_fx(BrIndex, 0, (N_STAGE_VQ - 4)); + set16_fx( BrIndex, 0, ( N_STAGE_VQ - 4 ) ); - FOR (stage = N_STAGE_VQ - 4; stage >= 1; stage--) + FOR( stage = N_STAGE_VQ - 4; stage >= 1; stage-- ) { - if(GT_16(s[stage], 7)) + if ( GT_16( s[stage], 7 ) ) { - BrIndex[stage-1] =1; + BrIndex[stage - 1] = 1; move16(); } } @@ -2022,27 +2012,27 @@ static void buildCode_fx( move16(); /* stage #1 - #2 */ - FOR (stage = 0; stage < 2; stage++) + FOR( stage = 0; stage < 2; stage++ ) { - ind[stage+1] = shl(BrIndex[stage], 4); + ind[stage + 1] = shl( BrIndex[stage], 4 ); move16(); - ind[stage+1] = add(ind[stage+1], shr(c[stage], 3)); + ind[stage + 1] = add( ind[stage + 1], shr( c[stage], 3 ) ); move16(); } /* stage #3 - #4 */ - FOR (stage = 2; stage < N_STAGE_VQ - 4; stage++) + FOR( stage = 2; stage < N_STAGE_VQ - 4; stage++ ) { - ind[stage+1] = shl(BrIndex[stage], 3); + ind[stage + 1] = shl( BrIndex[stage], 3 ); move16(); - ind[stage+1] = add(ind[stage+1], shr(c[stage], 3)); + ind[stage + 1] = add( ind[stage + 1], shr( c[stage], 3 ) ); move16(); } /* Stage #5 - #8 */ - FOR (stage = N_STAGE_VQ-4; stage < N_STAGE_VQ; stage++) + FOR( stage = N_STAGE_VQ - 4; stage < N_STAGE_VQ; stage++ ) { - ind[stage+1] = shr(c[stage], 3); + ind[stage + 1] = shr( c[stage], 3 ); move16(); } @@ -2053,19 +2043,18 @@ static void BcTcvq_fx( const Word16 *x_fx, Word16 *y_fx, const Word16 *weight_fx, - Word16 *ind -) + Word16 *ind ) { Word16 X_fx[N_STAGE_VQ][N_DIM], W_fx[N_STAGE_VQ][N_DIM]; /* Count Variable */ - Word16 i,j; + Word16 i, j; /* TCVQ Structure */ Word16 stage, state, prev_state; Word16 preState[N_STAGE_VQ][NUM_STATE]; Word16 codeWord[N_STAGE_VQ][NUM_STATE]; - Word32 acumDist_fx[N_STAGE_VQ-4][NUM_STATE]; + Word32 acumDist_fx[N_STAGE_VQ - 4][NUM_STATE]; Word16 inis, fins, ptr_fins; Word16 fBlock; Word16 fState[NUM_STATE]; @@ -2086,66 +2075,66 @@ static void BcTcvq_fx( Word16 bestState[N_STAGE_VQ]; /* Code Share variable */ - const Word16 (*TCVQ_CB_SUB1_fx)[128][2], (*TCVQ_CB_SUB2_fx)[64][2], (*TCVQ_CB_SUB3_fx)[32][2]/**/; - const Word16 (*IntraCoeff_fx)[2][2]; + const Word16( *TCVQ_CB_SUB1_fx )[128][2], ( *TCVQ_CB_SUB2_fx )[64][2], ( *TCVQ_CB_SUB3_fx )[32][2] /**/; + const Word16( *IntraCoeff_fx )[2][2]; /* Memoryless Module */ - IF (snFlag) + IF( snFlag ) { TCVQ_CB_SUB1_fx = SN_TCVQ_CB_SUB1_fx; TCVQ_CB_SUB2_fx = SN_TCVQ_CB_SUB2_fx; TCVQ_CB_SUB3_fx = SN_TCVQ_CB_SUB3_fx; - IntraCoeff_fx = SN_IntraCoeff_fx; + IntraCoeff_fx = SN_IntraCoeff_fx; } ELSE /* Memory Module */ { TCVQ_CB_SUB1_fx = AR_TCVQ_CB_SUB1_fx; TCVQ_CB_SUB2_fx = AR_TCVQ_CB_SUB2_fx; TCVQ_CB_SUB3_fx = AR_TCVQ_CB_SUB3_fx; - IntraCoeff_fx = AR_IntraCoeff_fx; + IntraCoeff_fx = AR_IntraCoeff_fx; } /* Transform Scalar to Vector */ - FOR (i = 0; i < N_STAGE_VQ; i++) + FOR( i = 0; i < N_STAGE_VQ; i++ ) { - FOR(j = 0; j < N_DIM; j++) + FOR( j = 0; j < N_DIM; j++ ) { - X_fx[i][j] = x_fx[(N_DIM*i) + j]; + X_fx[i][j] = x_fx[( N_DIM * i ) + j]; move16(); - W_fx[i][j] = weight_fx[(N_DIM*i) + j]; + W_fx[i][j] = weight_fx[( N_DIM * i ) + j]; move16(); } } /* Initialzie */ - FOR (i=0; i= 0; stage--) + FOR( stage = N_STAGE_VQ - 5; stage >= 0; stage-- ) { prev_state = preState[stage][prev_state]; move16(); @@ -2155,31 +2144,31 @@ static void BcTcvq_fx( } /* stage #5 - #8 */ - FOR (state = 0; state < NUM_STATE; state++) + FOR( state = 0; state < NUM_STATE; state++ ) { - inis = iniBlock[state]; + inis = iniBlock[state]; move16(); - ptr_fins = shr(inis, 2); - minDist_fx = L_add(MAX_32, 0); + ptr_fins = shr( inis, 2 ); + minDist_fx = L_add( MAX_32, 0 ); - FOR (i = 0; i < 4; i++) + FOR( i = 0; i < 4; i++ ) { - fins = add(shl(ptr_fins, 2), i); + fins = add( shl( ptr_fins, 2 ), i ); prev_state = state; move16(); - fDist_fx = BcTcvq_FixSearch_fx(X_fx, TCVQ_CB_SUB3_fx, fCodeword, quant_fx, FixBranch_tbl, N_STAGE_VQ-4, inis, i, &prev_state, W_fx, IntraCoeff_fx); + fDist_fx = BcTcvq_FixSearch_fx( X_fx, TCVQ_CB_SUB3_fx, fCodeword, quant_fx, FixBranch_tbl, N_STAGE_VQ - 4, inis, i, &prev_state, W_fx, IntraCoeff_fx ); - FOR (stage = N_STAGE_VQ-3; stage < N_STAGE_VQ; stage++) + FOR( stage = N_STAGE_VQ - 3; stage < N_STAGE_VQ; stage++ ) { - fDist_fx = L_add(fDist_fx, BcTcvq_FixSearch_fx(X_fx, TCVQ_CB_SUB3_fx, fCodeword, quant_fx, FixBranch_tbl, stage, inis, i, &prev_state, W_fx, IntraCoeff_fx)); + fDist_fx = L_add( fDist_fx, BcTcvq_FixSearch_fx( X_fx, TCVQ_CB_SUB3_fx, fCodeword, quant_fx, FixBranch_tbl, stage, inis, i, &prev_state, W_fx, IntraCoeff_fx ) ); } - IF (LT_32(fDist_fx, minDist_fx)) + IF( LT_32( fDist_fx, minDist_fx ) ) { - minDist_fx = L_add(fDist_fx, 0); + minDist_fx = L_add( fDist_fx, 0 ); blockDist_fx[state] = minDist_fx; move32(); - fState[state] = fins; + fState[state] = fins; move16(); blockCodeword[state][0] = fCodeword[i][0]; @@ -2195,13 +2184,13 @@ static void BcTcvq_fx( } /* Select optimal path */ - fBlock = optimalPath_fx(acumDist_fx, blockDist_fx, blockCodeword, bestCodeword, codeWord, bestState, preState); + fBlock = optimalPath_fx( acumDist_fx, blockDist_fx, blockCodeword, bestCodeword, codeWord, bestState, preState ); /* Select Quantized Value */ - quantEnc_fx(y_fx, bestCodeword, TCVQ_CB_SUB1_fx, TCVQ_CB_SUB2_fx, TCVQ_CB_SUB3_fx, IntraCoeff_fx); + quantEnc_fx( y_fx, bestCodeword, TCVQ_CB_SUB1_fx, TCVQ_CB_SUB2_fx, TCVQ_CB_SUB3_fx, IntraCoeff_fx ); /* Buid Code for Decoder */ - buildCode_fx(ind, fState[fBlock], bestCodeword, bestState); + buildCode_fx( ind, fState[fBlock], bestCodeword, bestState ); return; } @@ -2211,8 +2200,7 @@ static Word16 SVQ_2d_fx( Word16 *y_fx, const Word16 *W_fx, const Word16 CB_fx[][8], - Word16 Size -) + Word16 Size ) { Word16 i, j; Word16 index = 0; @@ -2220,27 +2208,27 @@ static Word16 SVQ_2d_fx( Word32 temp_fx; Word16 temp16_fx; - temp_fx = L_add(MAX_32, 0); + temp_fx = L_add( MAX_32, 0 ); - FOR (i = 0; i < Size; i++) + FOR( i = 0; i < Size; i++ ) { - distortion_fx = L_deposit_l(0); - FOR (j = 0; j < 8; j++) + distortion_fx = L_deposit_l( 0 ); + FOR( j = 0; j < 8; j++ ) { - temp16_fx = sub(x_fx[j], CB_fx[i][j]); - distortion_fx = L_add(distortion_fx, - L_shr(Mult_32_16(L_mult(temp16_fx, temp16_fx), W_fx[j]), 1)); + temp16_fx = sub( x_fx[j], CB_fx[i][j] ); + distortion_fx = L_add( distortion_fx, + L_shr( Mult_32_16( L_mult( temp16_fx, temp16_fx ), W_fx[j] ), 1 ) ); } - IF (LT_32(distortion_fx, temp_fx)) + IF( LT_32( distortion_fx, temp_fx ) ) { - temp_fx = L_add(distortion_fx, 0); + temp_fx = L_add( distortion_fx, 0 ); index = i; move16(); } } - FOR (i = 0; i < M/2; i++) + FOR( i = 0; i < M / 2; i++ ) { y_fx[i] = CB_fx[index][i]; move16(); @@ -2250,13 +2238,13 @@ static Word16 SVQ_2d_fx( } -Word32 qlsf_ARSN_tcvq_Enc_16k_fx ( - const Word16 *x_fx, /* i : Vector to be encoded x2.65 */ - Word16 *y_fx, /* o : Quantized LSF vector x2.65 */ - Word16 *indice, /* o : Indices */ - const Word16 *w_fx, /* i : LSF Weights Q8 */ - const Word16 nBits, /* i : number of bits */ - Word16 safety_net /* i : safety_net flag */ +Word32 qlsf_ARSN_tcvq_Enc_16k_fx( + const Word16 *x_fx, /* i : Vector to be encoded x2.65 */ + Word16 *y_fx, /* o : Quantized LSF vector x2.65 */ + Word16 *indice, /* o : Indices */ + const Word16 *w_fx, /* i : LSF Weights Q8 */ + const Word16 nBits, /* i : number of bits */ + Word16 safety_net /* i : safety_net flag */ ) { Word16 i; @@ -2268,29 +2256,29 @@ Word32 qlsf_ARSN_tcvq_Enc_16k_fx ( #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - IF (EQ_16(safety_net, 1)) + IF( EQ_16( safety_net, 1 ) ) { indice[0] = 1; move16(); - BcTcvq_fx(1, /*x, x_q, w, */x_fx, x_q_fx, w_fx, &indice[1]); + BcTcvq_fx( 1, /*x, x_q, w, */ x_fx, x_q_fx, w_fx, &indice[1] ); - IF (GT_16(nBits, 30)) + IF( GT_16( nBits, 30 ) ) { /* SVQ */ - FOR (i = 0; i < M; i++) + FOR( i = 0; i < M; i++ ) { - error_svq_fx[i] = mult_r(sub(x_fx[i], x_q_fx[i]), scale_inv_ARSN_fx[i]); + error_svq_fx[i] = mult_r( sub( x_fx[i], x_q_fx[i] ), scale_inv_ARSN_fx[i] ); move16(); } /* 5bits 1st Split VQ for Residual*/ - indice[10] = SVQ_2d_fx(error_svq_fx, error_svq_q_fx, w_fx, AR_SVQ_CB1_fx, 32); + indice[10] = SVQ_2d_fx( error_svq_fx, error_svq_q_fx, w_fx, AR_SVQ_CB1_fx, 32 ); /* 4bits 2nd Split VQ for Residual*/ - indice[11] = SVQ_2d_fx(&error_svq_fx[8], &error_svq_q_fx[8], &w_fx[8], AR_SVQ_CB2_fx, 16 ); + indice[11] = SVQ_2d_fx( &error_svq_fx[8], &error_svq_q_fx[8], &w_fx[8], AR_SVQ_CB2_fx, 16 ); - FOR (i = 0; i < M; i++) + FOR( i = 0; i < M; i++ ) { - x_q_fx[i] = add(x_q_fx[i], extract_h(L_shl(L_mult0(error_svq_q_fx[i], scale_ARSN_fx[i]), 2))); + x_q_fx[i] = add( x_q_fx[i], extract_h( L_shl( L_mult0( error_svq_q_fx[i], scale_ARSN_fx[i] ), 2 ) ) ); move16(); } } @@ -2299,25 +2287,25 @@ Word32 qlsf_ARSN_tcvq_Enc_16k_fx ( { indice[0] = 0; move16(); - BcTcvq_fx(0, /*x, x_q, w, */x_fx, x_q_fx, w_fx, &indice[1]); + BcTcvq_fx( 0, /*x, x_q, w, */ x_fx, x_q_fx, w_fx, &indice[1] ); - IF (GT_16(nBits, 30)) + IF( GT_16( nBits, 30 ) ) { /* SVQ */ - FOR (i = 0; i < M; i++) + FOR( i = 0; i < M; i++ ) { - error_svq_fx[i] = sub(x_fx[i], x_q_fx[i]); + error_svq_fx[i] = sub( x_fx[i], x_q_fx[i] ); move16(); } /* 5bits 1st Split VQ for Residual*/ - indice[10] = SVQ_2d_fx(error_svq_fx, error_svq_q_fx, w_fx, AR_SVQ_CB1_fx, 32); + indice[10] = SVQ_2d_fx( error_svq_fx, error_svq_q_fx, w_fx, AR_SVQ_CB1_fx, 32 ); /* 4bits 2nd Split VQ for Residual*/ - indice[11] = SVQ_2d_fx(&error_svq_fx[8], &error_svq_q_fx[8], &w_fx[8], AR_SVQ_CB2_fx, 16 ); + indice[11] = SVQ_2d_fx( &error_svq_fx[8], &error_svq_q_fx[8], &w_fx[8], AR_SVQ_CB2_fx, 16 ); - FOR (i = 0; i < M; i++) + FOR( i = 0; i < M; i++ ) { - x_q_fx[i] = add(x_q_fx[i], error_svq_q_fx[i]); + x_q_fx[i] = add( x_q_fx[i], error_svq_q_fx[i] ); move16(); } } @@ -2325,40 +2313,40 @@ Word32 qlsf_ARSN_tcvq_Enc_16k_fx ( cl = 0; move16(); - FOR (i = 0; i < M; i ++) + FOR( i = 0; i < M; i++ ) { - yy_fx[i] = sub(x_fx[i], x_q_fx[i]); + yy_fx[i] = sub( x_fx[i], x_q_fx[i] ); move16(); - cl = s_max(cl, abs_s(yy_fx[i])); + cl = s_max( cl, abs_s( yy_fx[i] ) ); } - cs = norm_s(cl); + cs = norm_s( cl ); temp_l = 0; move16(); - FOR (i = 0; i < M; i ++) + FOR( i = 0; i < M; i++ ) { - yy_fx[i] = shl(yy_fx[i], cs); + yy_fx[i] = shl( yy_fx[i], cs ); move16(); #ifdef BASOP_NOGLOB - temp_l = L_mac_o(temp_l, mult(yy_fx[i], shl_o(w_fx[i],2, &Overflow) ), yy_fx[i], &Overflow); -#else /* BASOP_NOGLOB */ - temp_l = L_mac(temp_l, mult(yy_fx[i], shl(w_fx[i],2) ), yy_fx[i]); + temp_l = L_mac_o( temp_l, mult( yy_fx[i], shl_o( w_fx[i], 2, &Overflow ) ), yy_fx[i], &Overflow ); +#else /* BASOP_NOGLOB */ + temp_l = L_mac( temp_l, mult( yy_fx[i], shl( w_fx[i], 2 ) ), yy_fx[i] ); #endif /* BASOP_NOGLOB */ } - cs = shl(cs, 1); - temp_l = L_shr(temp_l, cs); - temp_l = Mult_32_16(temp_l, LSF_1_OVER_256SQ); /* Q-4 */ + cs = shl( cs, 1 ); + temp_l = L_shr( temp_l, cs ); + temp_l = Mult_32_16( temp_l, LSF_1_OVER_256SQ ); /* Q-4 */ /* Recover the quantized LSF */ - Copy(x_q_fx, y_fx, M); + Copy( x_q_fx, y_fx, M ); return temp_l; } static void FFT_Mid_Interpol_16k_fx( - Word32 Bin_Ener_old[], /* i/o: Old 2nd FFT Bin energy (128) */ - Word32 Bin_Ener[], /* i : Current 2nd FFT Bin energy (128) */ - Word32 Bin_Ener_mid[] /* o : LP weighting filter (numerator) */ + Word32 Bin_Ener_old[], /* i/o: Old 2nd FFT Bin energy (128) */ + Word32 Bin_Ener[], /* i : Current 2nd FFT Bin energy (128) */ + Word32 Bin_Ener_mid[] /* o : LP weighting filter (numerator) */ ) { Word16 i; @@ -2366,13 +2354,13 @@ static void FFT_Mid_Interpol_16k_fx( Flag Overflow = 0; #endif - FOR( i=0; i 0 && LT_16(j, M)&<_16(qlsf[j],add(qlsf[j-1],LSF_GAP_MID_FX))) + IF( j > 0 && LT_16( j, M ) && LT_16( qlsf[j], add( qlsf[j - 1], LSF_GAP_MID_FX ) ) ) { - qlsf[j] = add(qlsf[j-1], LSF_GAP_MID_FX); + qlsf[j] = add( qlsf[j - 1], LSF_GAP_MID_FX ); move16(); } - tmp = sub(lsf[j],qlsf[j]); + tmp = sub( lsf[j], qlsf[j] ); /* err += wghts[j] * ftemp * ftemp; */ /* tmp is usually very small, we can have some extra precision with very rare saturation */ #ifdef BASOP_NOGLOB - tmp = shl_o(tmp, 4, &Overflow); - tmp = mult_ro(tmp, tmp, &Overflow); - err = L_mac_o(err, tmp, shl_o(wghts[j],2, &Overflow), &Overflow); + tmp = shl_o( tmp, 4, &Overflow ); + tmp = mult_ro( tmp, tmp, &Overflow ); + err = L_mac_o( err, tmp, shl_o( wghts[j], 2, &Overflow ), &Overflow ); #else /* BASOP_NOGLOB */ - tmp = shl(tmp, 4); - tmp = mult_r(tmp, tmp); - err = L_mac(err, tmp, shl(wghts[j],2) ); + tmp = shl( tmp, 4 ); + tmp = mult_r( tmp, tmp ); + err = L_mac( err, tmp, shl( wghts[j], 2 ) ); #endif } /* err = L_shl(err,Wscale); */ - err = Mult_32_16(err,LSF_1_OVER_256SQ); + err = Mult_32_16( err, LSF_1_OVER_256SQ ); /* err = Mult_32_16(err,Wmult); */ - IF ( LT_32(err,err_min)) + IF( LT_32( err, err_min ) ) { - err_min = L_add(err, 0); + err_min = L_add( err, 0 ); idx = k; move16(); } - k1+=M; + k1 += M; move16(); } /* calculate the quantized LSF vector */ - FOR ( j = 0; j < M; j++ ) + FOR( j = 0; j < M; j++ ) { /* qlsf[j] = (1.0f - ratio[idx*M+j]) * qlsf0[j] + ratio[idx*M+j] * qlsf1[j]; */ - L_tmp = L_mult(sub(0x2000, ratio[idx*M+j]), qlsf0[j]); - L_tmp = L_mac(L_tmp,ratio[idx*M+j],qlsf1[j]); - qlsf[j] = round_fx(L_shl(L_tmp,2)); + L_tmp = L_mult( sub( 0x2000, ratio[idx * M + j] ), qlsf0[j] ); + L_tmp = L_mac( L_tmp, ratio[idx * M + j], qlsf1[j] ); + qlsf[j] = round_fx( L_shl( L_tmp, 2 ) ); test(); test(); - IF ( j > 0 && LT_16(j, M)&<_16(qlsf[j],add(qlsf[j-1],LSF_GAP_MID_FX))) + IF( j > 0 && LT_16( j, M ) && LT_16( qlsf[j], add( qlsf[j - 1], LSF_GAP_MID_FX ) ) ) { - qlsf[j] = add(qlsf[j-1], LSF_GAP_MID_FX); + qlsf[j] = add( qlsf[j - 1], LSF_GAP_MID_FX ); move16(); } } @@ -2612,9 +2599,8 @@ static void lsf_mid_enc_fx( reorder_lsf_fx( qlsf, LSF_GAP_MID_FX, M, int_fs ); /* convert LSFs back to LSPs */ - lsf2lsp_fx( qlsf, lsp, M, int_fs); + lsf2lsp_fx( qlsf, lsp, M, int_fs ); push_indice_fx( hBstr, IND_MID_FRAME_LSF_INDEX, idx, nb_bits ); return; } - diff --git a/lib_enc/lsf_msvq_ma_enc.c b/lib_enc/lsf_msvq_ma_enc.c index ccdfc54a1..c1ce3812c 100644 --- a/lib_enc/lsf_msvq_ma_enc.c +++ b/lib_enc/lsf_msvq_ma_enc.c @@ -743,8 +743,8 @@ int16_t Q_lsf_tcxlpc( } - msvq_enc(lsf_codebook_flt[narrowband][cdk], lsf_dims_ivas, lsf_offs_ivas, lsf, lsf_numlevels, kMaxC, TCXLPC_NUMSTAGES, weights, M, M, 0, NULL, indices + NumIndices ); - msvq_dec_float(lsf_codebook_flt[narrowband][cdk], lsf_dims_ivas, lsf_offs_ivas, TCXLPC_NUMSTAGES, M, M, indices + NumIndices, 0, NULL, lsf_q, lsf_q_ind ); + msvq_enc( lsf_codebook_flt[narrowband][cdk], lsf_dims_ivas, lsf_offs_ivas, lsf, lsf_numlevels, kMaxC, TCXLPC_NUMSTAGES, weights, M, M, 0, NULL, indices + NumIndices ); + msvq_dec_float( lsf_codebook_flt[narrowband][cdk], lsf_dims_ivas, lsf_offs_ivas, TCXLPC_NUMSTAGES, M, M, indices + NumIndices, 0, NULL, lsf_q, lsf_q_ind ); NumIndices += TCXLPC_NUMSTAGES; @@ -787,7 +787,7 @@ int16_t Q_lsf_tcxlpc( move16(); } - basop_reorder_lsf( lsf_q_ind, LSF_GAP_VAL(TCXLPC_LSF_GAP_FLT), M, INT_FS_FX ); + basop_reorder_lsf( lsf_q_ind, LSF_GAP_VAL( TCXLPC_LSF_GAP_FLT ), M, INT_FS_FX ); if ( lsp_q_ind ) { basop_lsf2lsp( lsf_q_ind, lsp_q_ind ); diff --git a/lib_enc/lsf_msvq_ma_enc_fx.c b/lib_enc/lsf_msvq_ma_enc_fx.c index 296e3b8af..bf58e5040 100644 --- a/lib_enc/lsf_msvq_ma_enc_fx.c +++ b/lib_enc/lsf_msvq_ma_enc_fx.c @@ -11,41 +11,47 @@ #include "rom_com.h" #include "rom_enc.h" #include "basop_util.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* * Local constants *-------------------------------------------------------------------*/ -#define MAXINT32 2147483647 +#define MAXINT32 2147483647 #ifndef swap - #define swap(x,y,type) {type u__p; u__p=x; x=y; y=u__p;} +#define swap( x, y, type ) \ + { \ + type u__p; \ + u__p = x; \ + x = y; \ + y = u__p; \ + } #endif -#define depack_4_values(cbp, val0, val1, val2, val3) \ - val0 = shr((cbp)[0], 4); \ - val1 = shr((cbp)[1], 4); \ - val2 = shr((cbp)[2], 4); \ - val3 = add(add(shr(lshl((cbp)[2],12),4),lshr(lshl((cbp)[1],12),8)),s_and((cbp)[0],0xF)); +#define depack_4_values( cbp, val0, val1, val2, val3 ) \ + val0 = shr( ( cbp )[0], 4 ); \ + val1 = shr( ( cbp )[1], 4 ); \ + val2 = shr( ( cbp )[2], 4 ); \ + val3 = add( add( shr( lshl( ( cbp )[2], 12 ), 4 ), lshr( lshl( ( cbp )[1], 12 ), 8 ) ), s_and( ( cbp )[0], 0xF ) ); /*--------------------------------------------------------------------------* * depack_mul_values() * *--------------------------------------------------------------------------*/ - static Word32 depack_mul_values(Word16 *Tmp, const Word16 *w, const Word16 *cbp, const Word16 N) +static Word32 depack_mul_values( Word16 *Tmp, const Word16 *w, const Word16 *cbp, const Word16 N ) { Word16 i, val0, val1, val2, val3; Word32 en; en = 0; - move32(); - FOR (i = 0; i < N; i+=4) + move32(); + FOR( i = 0; i < N; i += 4 ) { - depack_4_values(cbp+i_mult(shr(i,2),3), val0, val1, val2, val3) + depack_4_values( cbp + i_mult( shr( i, 2 ), 3 ), val0, val1, val2, val3 ) #ifdef BASOP_NOGLOB - Tmp[i + 0] = mult_r( shl_sat( w[i + 0], 2 ), val0 ); + Tmp[i + 0] = mult_r( shl_sat( w[i + 0], 2 ), val0 ); move16(); en = L_mac_sat( en, val0, Tmp[i + 0] ); Tmp[i + 1] = mult_r( shl_sat( w[i + 1], 2 ), val1 ); @@ -58,18 +64,18 @@ move16(); en = L_mac_sat( en, val3, Tmp[i + 3] ); #else - Tmp[i+0] = mult_r(shl(w[i+0],2),val0); + Tmp[i + 0] = mult_r( shl( w[i + 0], 2 ), val0 ); move16(); - en = L_mac(en, val0, Tmp[i+0]); - Tmp[i+1] = mult_r(shl(w[i+1],2),val1); + en = L_mac( en, val0, Tmp[i + 0] ); + Tmp[i + 1] = mult_r( shl( w[i + 1], 2 ), val1 ); move16(); - en = L_mac(en, val1, Tmp[i+1]); - Tmp[i+2] = mult_r(shl(w[i+2],2),val2); + en = L_mac( en, val1, Tmp[i + 1] ); + Tmp[i + 2] = mult_r( shl( w[i + 2], 2 ), val2 ); move16(); - en = L_mac(en, val2, Tmp[i+2]); - Tmp[i+3] = mult_r(shl(w[i+3],2),val3); + en = L_mac( en, val2, Tmp[i + 2] ); + Tmp[i + 3] = mult_r( shl( w[i + 3], 2 ), val3 ); move16(); - en = L_mac(en, val3, Tmp[i+3]); + en = L_mac( en, val3, Tmp[i + 3] ); #endif } @@ -79,32 +85,31 @@ * depack_sub_values() * *--------------------------------------------------------------------------*/ -static void depack_sub_values(Word16 *pTmp, const Word16 *p1, const Word16 *cbp, const Word16 N) +static void depack_sub_values( Word16 *pTmp, const Word16 *p1, const Word16 *cbp, const Word16 N ) { Word16 j, val0, val1, val2, val3; - FOR (j=0; j> 16 => Qwnorm-15/16 * Q0/16 << 1 => Qwnorm-14/32 * 6.5536 */ - ss2 = L_mult(mult(u[0], shl( w[0], 2 )), u[0]); + ss2 = L_mult( mult( u[0], shl( w[0], 2 ) ), u[0] ); move16(); - FOR (j=1; j 0 && LT_16(j, M)&<_16(qlsf[j],add(qlsf[j-1],LSF_GAP_MID_FX))) + IF( j > 0 && LT_16( j, M ) && LT_16( qlsf[j], add( qlsf[j - 1], LSF_GAP_MID_FX ) ) ) { - qlsf[j] = add(qlsf[j-1], LSF_GAP_MID_FX); + qlsf[j] = add( qlsf[j - 1], LSF_GAP_MID_FX ); } - tmp = sub(lsf[j],qlsf[j]); + tmp = sub( lsf[j], qlsf[j] ); /* err += wghts[j] * ftemp * ftemp; */ /* tmp is usually very small, we can have some extra precision with very rare saturation */ #ifdef BASOP_NOGLOB - tmp = shl_o(tmp, 4, &Overflow); - tmp = mult_ro(tmp, tmp, &Overflow); -#else /* BASOP_NOGLOB */ - tmp = shl(tmp, 4); - tmp = mult_r(tmp, tmp); + tmp = shl_o( tmp, 4, &Overflow ); + tmp = mult_ro( tmp, tmp, &Overflow ); +#else /* BASOP_NOGLOB */ + tmp = shl( tmp, 4 ); + tmp = mult_r( tmp, tmp ); #endif /* BASOP_NOGLOB */ - err = L_mac(err, tmp, wghts[j]); + err = L_mac( err, tmp, wghts[j] ); } #ifdef BASOP_NOGLOB - err = L_shl_o( err, 2 , &Overflow); + err = L_shl_o( err, 2, &Overflow ); #else /* BASOP_NOGLOB */ err = L_shl( err, 2 ); #endif /* err = L_shl(err,Wscale); */ - err = Mult_32_16(err,LSF_1_OVER_256SQ); + err = Mult_32_16( err, LSF_1_OVER_256SQ ); /* err = Mult_32_16(err,Wmult); */ - IF ( LT_32(err,err_min)) + IF( LT_32( err, err_min ) ) { - err_min = L_add(err, 0); + err_min = L_add( err, 0 ); *idx = k; move16(); } - k1+=M; + k1 += M; move16(); } @@ -529,23 +533,22 @@ void midlsf_enc_fx( /*--------------------------------------------------------------------------* * Q_lsf_tcxlpc_fx() * - * Returns: number of indices + * Returns: number of indices *--------------------------------------------------------------------------*/ Word16 Q_lsf_tcxlpc_fx( - /* const */ Word16 lsf[], /* i : original lsf */ - Word16 lsf_q[], /* o : quantized lsf */ - Word16 lsp_q_ind[], /* o : quantized lsp (w/o MA prediction) */ - Word16 indices[], /* o : VQ indices */ - const Word16 lpcorder, /* i : LPC order */ - const Word16 narrowband, /* i : narrowband flag */ - const Word16 cdk, /* i : codebook selector */ - const Word16 mem_MA[], /* i : MA memory */ + /* const */ Word16 lsf[], /* i : original lsf */ + Word16 lsf_q[], /* o : quantized lsf */ + Word16 lsp_q_ind[], /* o : quantized lsp (w/o MA prediction) */ + Word16 indices[], /* o : VQ indices */ + const Word16 lpcorder, /* i : LPC order */ + const Word16 narrowband, /* i : narrowband flag */ + const Word16 cdk, /* i : codebook selector */ + const Word16 mem_MA[], /* i : MA memory */ const Word16 coder_type, - const Word32 * Bin_Ener, - const Word16 Q_ener -) + const Word32 *Bin_Ener, + const Word16 Q_ener ) { - Word16 weights[M+1]; + Word16 weights[M + 1]; Word16 pred[M16k]; Word16 i; Word16 NumIndices; @@ -554,7 +557,7 @@ Word16 Q_lsf_tcxlpc_fx( Word16 lsf_rem[M]; Word16 lsf_rem_q_ind[M]; - Unified_weighting_fx( Bin_Ener, Q_ener, lsf, weights, narrowband,(Word16)EQ_16(coder_type,UNVOICED),12800,M); + Unified_weighting_fx( Bin_Ener, Q_ener, lsf, weights, narrowband, (Word16) EQ_16( coder_type, UNVOICED ), 12800, M ); move16(); NumIndices = 0; @@ -562,22 +565,22 @@ Word16 Q_lsf_tcxlpc_fx( /* Put disabled flag */ indices[NumIndices] = 0; move16(); - NumIndices = add(NumIndices, 1); + NumIndices = add( NumIndices, 1 ); /* Inter-frame prediction */ means = lsf_means[narrowband]; /* 14Q1 * 1.28 */ - FOR (i=0; i0; i--) + FOR( i = 55; i > 0; i-- ) { - frames_power_32[i] = frames_power_32[i-1]; + frames_power_32[i] = frames_power_32[i - 1]; move32(); } hVAD_CLDFB->Q_frames_power_32 = Q_frames_power32; move16(); - } diff --git a/lib_enc/mdct_classifier.c b/lib_enc/mdct_classifier.c index 19710b6c6..415792510 100644 --- a/lib_enc/mdct_classifier.c +++ b/lib_enc/mdct_classifier.c @@ -304,7 +304,7 @@ int16_t mdct_classifier( } /* Smooth decision from instantaneous decision*/ - clas_sec = ( SMOOTH_FILT_COEFF * hTcxEnc->clas_sec_old_flt) + ( ( 1 - SMOOTH_FILT_COEFF ) * c ); + clas_sec = ( SMOOTH_FILT_COEFF * hTcxEnc->clas_sec_old_flt ) + ( ( 1 - SMOOTH_FILT_COEFF ) * c ); /* Do thresholding with hysteresis */ if ( ( hTcxEnc->clas_final_old == HQ_CORE || hTcxEnc->clas_final_old == TCX_20_CORE ) && ( ( hTcxEnc->last_gain1_flt > 0.5f * gain1 && hTcxEnc->last_gain1_flt < 2.0f * gain1 ) && ( hTcxEnc->last_gain2_flt > 0.5f * gain2 && hTcxEnc->last_gain2_flt < 2.0f * gain2 ) ) ) diff --git a/lib_enc/mdct_classifier_fx.c b/lib_enc/mdct_classifier_fx.c index d6f4d2c88..63f9c78be 100644 --- a/lib_enc/mdct_classifier_fx.c +++ b/lib_enc/mdct_classifier_fx.c @@ -7,26 +7,26 @@ #include "cnst.h" //#include "prot_fx.h" #include "rom_com.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*--------------------------------------------------------------------------* * Local constants *--------------------------------------------------------------------------*/ -#define MDCT_CLASSIFER_SMOOTH_FILT_COEFF 26214 /* 0.8 in Q15 */ -#define MDCT_CLASSIFER_THRESH_UP 13107 /* 1.6 in Q13 */ -#define MDCT_CLASSIFER_THRESH_DOWN 9011 /* 1.1 in Q13 */ -#define MDCT_CLASSIFER_HQ_LOCAL (3 << 13) /* Q13, Define those local to make the filtering operation robust in case classes numbers are changed */ -#define MDCT_CLASSIFER_TCX_LOCAL (1 << 13) /* Q13 */ -//IVAS_CODE -#define GAIN2_START_WB 6 -#define GAIN3_START_WB 12 -#define GAIN4_START_WB 9 -#define H1_START_WB 17 -#define H2_START_WB 14 -#define H_LENGTH_WB 3 +#define MDCT_CLASSIFER_SMOOTH_FILT_COEFF 26214 /* 0.8 in Q15 */ +#define MDCT_CLASSIFER_THRESH_UP 13107 /* 1.6 in Q13 */ +#define MDCT_CLASSIFER_THRESH_DOWN 9011 /* 1.1 in Q13 */ +#define MDCT_CLASSIFER_HQ_LOCAL ( 3 << 13 ) /* Q13, Define those local to make the filtering operation robust in case classes numbers are changed */ +#define MDCT_CLASSIFER_TCX_LOCAL ( 1 << 13 ) /* Q13 */ +// IVAS_CODE +#define GAIN2_START_WB 6 +#define GAIN3_START_WB 12 +#define GAIN4_START_WB 9 +#define H1_START_WB 17 +#define H2_START_WB 14 +#define H_LENGTH_WB 3 #define GAIN2_START_SWB 8 #define GAIN3_START_SWB 16 @@ -45,9 +45,9 @@ * Square magnitude of fft spectrum *----------------------------------------------------------------------------*/ static void dft_mag_square_fx( - const Word16 x[], /* i : Input vector: re[0], re[1], ..., re[n/2], im[n/2 - 1], im[n/2 - 2], ..., im[1] */ - Word32 magSq[], /* o : Magnitude square spectrum */ - const Word16 n /* i : Input vector length */ + const Word16 x[], /* i : Input vector: re[0], re[1], ..., re[n/2], im[n/2 - 1], im[n/2 - 2], ..., im[1] */ + Word32 magSq[], /* o : Magnitude square spectrum */ + const Word16 n /* i : Input vector length */ ) { Word16 i, l; @@ -57,25 +57,25 @@ static void dft_mag_square_fx( /* Magnitude square at 0. */ pMagSq = &magSq[0]; pRe = &x[0]; - *pMagSq++ = L_mult0(*pRe, *pRe); + *pMagSq++ = L_mult0( *pRe, *pRe ); pRe++; move32(); /* From 1 to (N/2 - 1). */ - l = sub(shr(n, 1), 1); /* N/2 - 1. */ + l = sub( shr( n, 1 ), 1 ); /* N/2 - 1. */ pIm = &x[n]; pIm--; - FOR (i = 0; i < l; i++) + FOR( i = 0; i < l; i++ ) { - acc = L_mult0(*pRe, *pRe); + acc = L_mult0( *pRe, *pRe ); pRe++; - *pMagSq++ = L_mac0(acc, *pIm, *pIm); + *pMagSq++ = L_mac0( acc, *pIm, *pIm ); pIm--; move32(); } /* The magnitude square at N/2 */ - *pMagSq = L_mult0(*pRe, *pRe); + *pMagSq = L_mult0( *pRe, *pRe ); move32(); return; } @@ -85,12 +85,12 @@ static void dft_mag_square_fx( * MDCT signal classifier for HQ_CORE/TCX_20_CORE *-------------------------------------------------------------------*/ -Word16 mdct_classifier_fx( /* o: MDCT A/B decision */ - const Word16 * fft_buff, /* i: re[0], re[1], ..., re[n/2], im[n/2 - 1], im[n/2 - 2], ..., im[1] */ - Encoder_State *st_fx, /* i/o: Encoder state variable */ - Word32 *cldfbBuf_Ener, - Word16 enerBuffer_exp, - const Word32 brate /* i : current brate, IVAS: nominal bitrate, EVS: st->total_brate */ +Word16 mdct_classifier_fx( /* o: MDCT A/B decision */ + const Word16 *fft_buff, /* i: re[0], re[1], ..., re[n/2], im[n/2 - 1], im[n/2 - 2], ..., im[1] */ + Encoder_State *st_fx, /* i/o: Encoder state variable */ + Word32 *cldfbBuf_Ener, + Word16 enerBuffer_exp, + const Word32 brate /* i : current brate, IVAS: nominal bitrate, EVS: st->total_brate */ ) { Word16 c; @@ -123,23 +123,28 @@ Word16 mdct_classifier_fx( /* o: MDCT A/B decision TCX_ENC_HANDLE hTcxEnc = st_fx->hTcxEnc; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; -#endif +#endif test(); #ifdef IVAS_CODE - IF (EQ_32(st_fx->input_Fs, 32000) || EQ_32(st_fx->input_Fs, 48000)) + IF( EQ_32( st_fx->input_Fs, 32000 ) || EQ_32( st_fx->input_Fs, 48000 ) ) { gain2_start = GAIN2_START_SWB; gain2_start_rs = GAIN2_START_SWB_RS; gain3_start = GAIN3_START_SWB; gain3_start_rs = GAIN3_START_SWB_RS; gain4_start = GAIN4_START_SWB; - //gain4_start_rs = GAIN4_START_SWB_RS; + // gain4_start_rs = GAIN4_START_SWB_RS; H1_start = H1_START_SWB; H2_start = H2_START_SWB; H_length = H_LENGTH_SWB; - move16();move16();move16();move16();move16();move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); } - ELSE IF (EQ_32(st_fx->input_Fs, 16000)) + ELSE IF( EQ_32( st_fx->input_Fs, 16000 ) ) { gain2_start = GAIN2_START_WB; gain2_start_rs = GAIN2_START_SWB_RS; @@ -149,50 +154,59 @@ Word16 mdct_classifier_fx( /* o: MDCT A/B decision H1_start = H1_START_WB; H2_start = H2_START_WB; H_length = H_LENGTH_WB; - move16(); move16(); move16(); move16(); move16(); move16(); - + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); } ELSE { - assert(!"Unknown sampling frequency in MDCT_classifier"); + assert( !"Unknown sampling frequency in MDCT_classifier" ); H1_start = -1; /* to avoid compilation warning */ H2_start = -1; /* to avoid compilation warning */ H_length = -1; /* to avoid compilation warning */ gain2_start = -1; /* to avoid compilation warning */ gain3_start = -1; /* to avoid compilation warning */ gain4_start = -1; /* to avoid compilation warning */ - move16(); move16(); move16(); move16(); move16(); move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); } #endif #ifdef IVAS_CODE - if (NE_16(st_fx->element_mode, IVAS_CPE_DFT)) + if ( NE_16( st_fx->element_mode, IVAS_CPE_DFT ) ) #endif { - dft_mag_square_fx(fft_buff, magSq, 256); + dft_mag_square_fx( fft_buff, magSq, 256 ); } #ifdef IVAS_CODE ELSE { float norm_val; - norm_val = (L_FFT * L_FFT) / 4.f; - for (k = 0; k < 128; k++) + norm_val = ( L_FFT * L_FFT ) / 4.f; + for ( k = 0; k < 128; k++ ) { X[k + 1] = st->Bin_E_old[k] * norm_val; } X[0] = X[1]; } #endif - nf = L_add(magSq[0], 0); - pe = L_add(magSq[0], 0); + nf = L_add( magSq[0], 0 ); + pe = L_add( magSq[0], 0 ); np = 0; move16(); - max_cand = L_negate(1); + max_cand = L_negate( 1 ); max_i = 0; move16(); - p_energy_man = L_deposit_l(0); - n_energy_man = L_deposit_l(0); + p_energy_man = L_deposit_l( 0 ); + n_energy_man = L_deposit_l( 0 ); p_energy_exp = n_energy_exp = 32; move16(); move16(); @@ -202,178 +216,182 @@ Word16 mdct_classifier_fx( /* o: MDCT A/B decision move16(); pMagSq = magSq; - FOR (k = 0; k < 128; k++) + FOR( k = 0; k < 128; k++ ) { /* NB: a*f + b*(1 - f) needs two multiplies * = (a - b)*f + b saves one multiply */ - IF (GT_32(*(++pMagSq), nf)) + IF( GT_32( *( ++pMagSq ), nf ) ) { factor = 31385; - move16();/* 0.9578 in Q15 */ + move16(); /* 0.9578 in Q15 */ } ELSE { factor = 21207; - move16();/* 0.6472 in Q15 */ + move16(); /* 0.6472 in Q15 */ } - acc = L_sub(nf, *pMagSq); - Mpy_32_16_ss(acc, factor, &acc, &lsb16); - nf = L_add(acc, *pMagSq); - IF (GT_32(*pMagSq, pe)) + acc = L_sub( nf, *pMagSq ); + Mpy_32_16_ss( acc, factor, &acc, &lsb16 ); + nf = L_add( acc, *pMagSq ); + IF( GT_32( *pMagSq, pe ) ) { factor = 13840; - move16();/* 0.42237 in Q15 */ + move16(); /* 0.42237 in Q15 */ } ELSE { factor = 26308; - move16();/* 0.80285 in Q15 */ + move16(); /* 0.80285 in Q15 */ } - acc = L_sub(pe, *pMagSq); - Mpy_32_16_ss(acc, factor, &acc, &lsb16); - pe = L_add(acc, *pMagSq); - Mpy_32_16_ss(pe, 20972, &acc, &lsb16); /* 0.64 in Q15 */ - IF (GT_32(*pMagSq, acc)) + acc = L_sub( pe, *pMagSq ); + Mpy_32_16_ss( acc, factor, &acc, &lsb16 ); + pe = L_add( acc, *pMagSq ); + Mpy_32_16_ss( pe, 20972, &acc, &lsb16 ); /* 0.64 in Q15 */ + IF( GT_32( *pMagSq, acc ) ) { - IF (GT_32(*pMagSq, max_cand)) + IF( GT_32( *pMagSq, max_cand ) ) { - max_cand = L_add(*pMagSq, 0); - max_i = add(2, k); + max_cand = L_add( *pMagSq, 0 ); + max_i = add( 2, k ); } } ELSE { - IF (max_i > 0) + IF( max_i > 0 ) { - IF (GT_16(np, 0)) + IF( GT_16( np, 0 ) ) { - d_acc = sub(add(d_acc, max_i), pos_last); + d_acc = sub( add( d_acc, max_i ), pos_last ); } - np = add(np, 1); + np = add( np, 1 ); pos_last = max_i; move16(); } - max_cand = L_negate(1); + max_cand = L_negate( 1 ); max_i = 0; move16(); } - IF (pe != 0) + IF( pe != 0 ) { - expo = norm_l(pe); - man = L_shl(pe, expo); - Mpy_32_32_ss(man, man, &man, &lsb32); /* pe square */ - expo = shl(expo, 1); /* Multiply by 2 due to squaring. */ - floating_point_add(&p_energy_man, &p_energy_exp, man, expo); + expo = norm_l( pe ); + man = L_shl( pe, expo ); + Mpy_32_32_ss( man, man, &man, &lsb32 ); /* pe square */ + expo = shl( expo, 1 ); /* Multiply by 2 due to squaring. */ + floating_point_add( &p_energy_man, &p_energy_exp, man, expo ); } - IF (nf != 0) + IF( nf != 0 ) { - expo = norm_l(nf); - man = L_shl(nf, expo); - Mpy_32_32_ss(man, man, &man, &lsb32); /* nf square */ - expo = shl(expo, 1); /* Multiply by 2 due to squaring. */ - floating_point_add(&n_energy_man, &n_energy_exp, man, expo); + expo = norm_l( nf ); + man = L_shl( nf, expo ); + Mpy_32_32_ss( man, man, &man, &lsb32 ); /* nf square */ + expo = shl( expo, 1 ); /* Multiply by 2 due to squaring. */ + floating_point_add( &n_energy_man, &n_energy_exp, man, expo ); } } - gain1 = L_deposit_l(0); - gain2 = L_deposit_l(0); - gain3 = L_deposit_l(0); + gain1 = L_deposit_l( 0 ); + gain2 = L_deposit_l( 0 ); + gain3 = L_deposit_l( 0 ); #ifdef IVAS_CODE - PMT("MDCT_classifier needs review for different sampling rate") + PMT( "MDCT_classifier needs review for different sampling rate" ) #endif -//IVAS_CODE to adapt - FOR (k = 0; k < 8; k++) + // IVAS_CODE to adapt + FOR( k = 0; k < 8; k++ ) { - gain1 = L_add(gain1, L_shr(cldfbBuf_Ener[k], 3)); - gain2 = L_add(gain2, L_shr(cldfbBuf_Ener[k + 8], 3)); - gain3 = L_add(gain3, L_shr(cldfbBuf_Ener[k + 16], 3)); + gain1 = L_add( gain1, L_shr( cldfbBuf_Ener[k], 3 ) ); + gain2 = L_add( gain2, L_shr( cldfbBuf_Ener[k + 8], 3 ) ); + gain3 = L_add( gain3, L_shr( cldfbBuf_Ener[k + 16], 3 ) ); } /* gain11 = 8*(gain1 - cldfbBuf_Ener[0]/8)/7; */ - acc = L_shr(cldfbBuf_Ener[0], 3); - acc = L_sub(gain1, acc); - acc = Mult_32_16(acc, 4681); - gain11 = L_shl(acc, 3); - gain4 = L_deposit_l(0); - FOR (k = 0; k < 12; k++) + acc = L_shr( cldfbBuf_Ener[0], 3 ); + acc = L_sub( gain1, acc ); + acc = Mult_32_16( acc, 4681 ); + gain11 = L_shl( acc, 3 ); + gain4 = L_deposit_l( 0 ); + FOR( k = 0; k < 12; k++ ) { - gain4 = L_add(gain4, Mult_32_16(cldfbBuf_Ener[k + 12], 2731)); + gain4 = L_add( gain4, Mult_32_16( cldfbBuf_Ener[k + 12], 2731 ) ); } - peak_H1 = L_add(cldfbBuf_Ener[25], 0); - Mpy_32_16_ss(cldfbBuf_Ener[25], 6554, &avrg_H1, &lsb16); - FOR (k = 1; k < 5; k++) + peak_H1 = L_add( cldfbBuf_Ener[25], 0 ); + Mpy_32_16_ss( cldfbBuf_Ener[25], 6554, &avrg_H1, &lsb16 ); + FOR( k = 1; k < 5; k++ ) { - IF(GT_32(cldfbBuf_Ener[k + 25], peak_H1)) + IF( GT_32( cldfbBuf_Ener[k + 25], peak_H1 ) ) { - peak_H1 = L_add(cldfbBuf_Ener[k + 25], 0); + peak_H1 = L_add( cldfbBuf_Ener[k + 25], 0 ); } - avrg_H1 = L_add(avrg_H1, Mult_32_16(cldfbBuf_Ener[k + 25], 6554)); + avrg_H1 = L_add( avrg_H1, Mult_32_16( cldfbBuf_Ener[k + 25], 6554 ) ); } - peak_H2 = L_add(cldfbBuf_Ener[20], 0); - Mpy_32_16_ss(cldfbBuf_Ener[20], 6554, &avrg_H2, &lsb16); - FOR (k = 1; k < 5; k++) + peak_H2 = L_add( cldfbBuf_Ener[20], 0 ); + Mpy_32_16_ss( cldfbBuf_Ener[20], 6554, &avrg_H2, &lsb16 ); + FOR( k = 1; k < 5; k++ ) { - IF (GT_32(cldfbBuf_Ener[k + 20], peak_H2)) + IF( GT_32( cldfbBuf_Ener[k + 20], peak_H2 ) ) { - peak_H2 = L_add(cldfbBuf_Ener[k + 20], 0); + peak_H2 = L_add( cldfbBuf_Ener[k + 20], 0 ); } - avrg_H2 = L_add(avrg_H2, Mult_32_16(cldfbBuf_Ener[k + 20], 6554)); - } -//End - peak_l = L_deposit_l(0); - avrg_l = L_deposit_l(0); - peak_h = L_deposit_l(0); - avrg_h = L_deposit_l(0); - FOR (k = 0; k < 32; k++) - { - avrg_l = L_add(avrg_l, L_shr(magSq[k + 20], 5)); - avrg_h = L_add(avrg_h, L_shr(magSq[k + 96], 5)); - IF (GT_32(magSq[k + 20], peak_l)) + avrg_H2 = L_add( avrg_H2, Mult_32_16( cldfbBuf_Ener[k + 20], 6554 ) ); + } + // End + peak_l = L_deposit_l( 0 ); + avrg_l = L_deposit_l( 0 ); + peak_h = L_deposit_l( 0 ); + avrg_h = L_deposit_l( 0 ); + FOR( k = 0; k < 32; k++ ) + { + avrg_l = L_add( avrg_l, L_shr( magSq[k + 20], 5 ) ); + avrg_h = L_add( avrg_h, L_shr( magSq[k + 96], 5 ) ); + IF( GT_32( magSq[k + 20], peak_l ) ) { - peak_l = L_add(magSq[k + 20], 0); + peak_l = L_add( magSq[k + 20], 0 ); } - IF (GT_32(magSq[k + 96], peak_h)) + IF( GT_32( magSq[k + 96], peak_h ) ) { - peak_h = L_add(magSq[k + 96], 0); + peak_h = L_add( magSq[k + 96], 0 ); } } /* Compute: d_acc - 12*(np -1). */ - acc = L_deposit_l(d_acc); - IF (L_msu(acc, 12/2, sub(np, 1)) > 0) /* 12/2 is to compensate the fractional mode multiply */ + acc = L_deposit_l( d_acc ); + IF( L_msu( acc, 12 / 2, sub( np, 1 ) ) > 0 ) /* 12/2 is to compensate the fractional mode multiply */ { - condition1 = 1; /* Signifies: d_acc/(np - 1) > 12 */ move16(); + condition1 = 1; /* Signifies: d_acc/(np - 1) > 12 */ + move16(); } ELSE { - condition1 = 0; /* Signifies: d_acc/(np - 1) <= 12 */ move16(); + condition1 = 0; /* Signifies: d_acc/(np - 1) <= 12 */ + move16(); /* NB: For np = 0 or 1, it fits this condition. */ } /* Compute: p_energy - 147.87276*n_energy. */ - IF (n_energy_man != 0) + IF( n_energy_man != 0 ) { - Mpy_32_16_ss(n_energy_man, 18928, &acc, &lsb16); /* 147.87276 in Q7 */ - expo = sub(n_energy_exp, 15 - 7); /* Due to 18928 in Q7 */ - acc = L_negate(acc); /* To facilitate the following floating_point_add() to perform subtraction. */ - floating_point_add(&acc, &expo, p_energy_man, p_energy_exp); + Mpy_32_16_ss( n_energy_man, 18928, &acc, &lsb16 ); /* 147.87276 in Q7 */ + expo = sub( n_energy_exp, 15 - 7 ); /* Due to 18928 in Q7 */ + acc = L_negate( acc ); /* To facilitate the following floating_point_add() to perform subtraction. */ + floating_point_add( &acc, &expo, p_energy_man, p_energy_exp ); } ELSE { - acc = L_deposit_l(0); + acc = L_deposit_l( 0 ); } - IF (acc > 0) + IF( acc > 0 ) { - condition2 = 1; /* Signifies: p_energy / n_energy > 147.87276 */ move16(); + condition2 = 1; /* Signifies: p_energy / n_energy > 147.87276 */ + move16(); } ELSE { - condition2 = 0; /* Signifies: p_energy / n_energy <= 147.87276 */ move16(); + condition2 = 0; /* Signifies: p_energy / n_energy <= 147.87276 */ + move16(); } condition3 = 0; @@ -381,32 +399,32 @@ Word16 mdct_classifier_fx( /* o: MDCT A/B decision condition4 = 0; move16(); - L_tmp = Mult_32_16(peak_h, 12603); - IF(GT_32(peak_l, L_tmp)) + L_tmp = Mult_32_16( peak_h, 12603 ); + IF( GT_32( peak_l, L_tmp ) ) { - exp = norm_l(peak_l); + exp = norm_l( peak_l ); } ELSE { - exp = norm_l(L_tmp); + exp = norm_l( L_tmp ); } - IF(GT_32(avrg_h, avrg_l)) + IF( GT_32( avrg_h, avrg_l ) ) { - exp1 = norm_l(avrg_h); + exp1 = norm_l( avrg_h ); } ELSE { - exp1 = norm_l(avrg_l); + exp1 = norm_l( avrg_l ); } - L_tmp1 = Mult_32_16(peak_l, 12603); - IF(GT_32(peak_h, L_tmp1)) + L_tmp1 = Mult_32_16( peak_l, 12603 ); + IF( GT_32( peak_h, L_tmp1 ) ) { - exp2 = norm_l(peak_h); + exp2 = norm_l( peak_h ); } ELSE { - exp2 = norm_l(L_tmp1); + exp2 = norm_l( L_tmp1 ); } test(); @@ -414,46 +432,42 @@ Word16 mdct_classifier_fx( /* o: MDCT A/B decision test(); test(); #ifdef BASOP_NOGLOB - IF (GT_32(Mult_32_16(gain3, 27307), gain2)||(GE_32(gain3,Mult_32_16(gain2,26214))&>_32(peak_H1,L_shl_o(avrg_H1,1, &Overflow))) - || (LT_32(Mult_32_32(L_shl_o(peak_l, exp, &Overflow), L_shl_o(avrg_h, exp1, &Overflow)), Mult_32_32(L_shl_o(L_tmp, exp, &Overflow), L_shl_o(avrg_l, exp1, &Overflow))) - || GT_32(Mult_32_32(L_shl_o(L_tmp1, exp2, &Overflow), L_shl_o(avrg_h, exp1, &Overflow)), Mult_32_32(L_shl_o(peak_h, exp2, &Overflow), L_shl_o(avrg_l, exp1, &Overflow))))) + IF( GT_32( Mult_32_16( gain3, 27307 ), gain2 ) || ( GE_32( gain3, Mult_32_16( gain2, 26214 ) ) && GT_32( peak_H1, L_shl_o( avrg_H1, 1, &Overflow ) ) ) || ( LT_32( Mult_32_32( L_shl_o( peak_l, exp, &Overflow ), L_shl_o( avrg_h, exp1, &Overflow ) ), Mult_32_32( L_shl_o( L_tmp, exp, &Overflow ), L_shl_o( avrg_l, exp1, &Overflow ) ) ) || GT_32( Mult_32_32( L_shl_o( L_tmp1, exp2, &Overflow ), L_shl_o( avrg_h, exp1, &Overflow ) ), Mult_32_32( L_shl_o( peak_h, exp2, &Overflow ), L_shl_o( avrg_l, exp1, &Overflow ) ) ) ) ) #else - IF (GT_32(Mult_32_16(gain3, 27307), gain2)||(GE_32(gain3,Mult_32_16(gain2,26214))&>_32(peak_H1,L_shl(avrg_H1,1))) - || (LT_32(Mult_32_32(L_shl(peak_l, exp), L_shl(avrg_h, exp1)), Mult_32_32(L_shl(L_tmp, exp), L_shl(avrg_l, exp1))) - || GT_32(Mult_32_32(L_shl(L_tmp1, exp2), L_shl(avrg_h, exp1)), Mult_32_32(L_shl(peak_h, exp2), L_shl(avrg_l, exp1))))) + IF( GT_32( Mult_32_16( gain3, 27307 ), gain2 ) || ( GE_32( gain3, Mult_32_16( gain2, 26214 ) ) && GT_32( peak_H1, L_shl( avrg_H1, 1 ) ) ) || ( LT_32( Mult_32_32( L_shl( peak_l, exp ), L_shl( avrg_h, exp1 ) ), Mult_32_32( L_shl( L_tmp, exp ), L_shl( avrg_l, exp1 ) ) ) || GT_32( Mult_32_32( L_shl( L_tmp1, exp2 ), L_shl( avrg_h, exp1 ) ), Mult_32_32( L_shl( peak_h, exp2 ), L_shl( avrg_l, exp1 ) ) ) ) ) #endif { condition3 = 1; move16(); } - L_tmp = Mult_32_16(peak_h, 12800); - IF(GT_32(peak_l, L_tmp)) + L_tmp = Mult_32_16( peak_h, 12800 ); + IF( GT_32( peak_l, L_tmp ) ) { - exp = norm_l(peak_l); + exp = norm_l( peak_l ); } ELSE { - exp = norm_l(L_tmp); + exp = norm_l( L_tmp ); } - L_tmp1 = Mult_32_16(peak_l, 6400); - IF(GT_32(peak_h, L_tmp1)) + L_tmp1 = Mult_32_16( peak_l, 6400 ); + IF( GT_32( peak_h, L_tmp1 ) ) { - exp2 = norm_l(peak_h); + exp2 = norm_l( peak_h ); } ELSE { - exp2 = norm_l(L_tmp1); + exp2 = norm_l( L_tmp1 ); } - IF(GT_32(peak_h, L_shl(L_tmp1, 1))) + IF( GT_32( peak_h, L_shl( L_tmp1, 1 ) ) ) { - exp3 = norm_l(peak_h); + exp3 = norm_l( peak_h ); } ELSE { - exp3 = sub(norm_l(L_tmp1), 1); + exp3 = sub( norm_l( L_tmp1 ), 1 ); } test(); @@ -465,11 +479,7 @@ Word16 mdct_classifier_fx( /* o: MDCT A/B decision test(); test(); test(); - IF ((GT_32(gain4, Mult_32_16(gain11, 26214))&>_32(Mult_32_32(L_shl(peak_l,exp),L_shl(avrg_h,exp1)),Mult_32_32(L_shl(Mult_32_16(peak_h,12800),exp),L_shl(avrg_l,exp1))) - && LT_32(Mult_32_32(L_shl(Mult_32_16(peak_l, 6400), exp2), L_shl(avrg_h, exp1)), Mult_32_32(L_shl(peak_h, exp2), L_shl(avrg_l, exp1)))) - || (GT_32(gain4, Mult_32_16(gain11, 9830))&& LT_32(Mult_32_16(peak_h, 21845), avrg_h)&& LT_32(Mult_32_16(peak_H2, 21845), avrg_H2)) - || (LT_32(Mult_32_32(L_shl(peak_l, exp), L_shl(avrg_h, exp1)), Mult_32_32(L_shl(Mult_32_16(peak_h, 12800), exp), L_shl(avrg_l, exp1))) && GT_32(Mult_32_16(peak_h, 21845), avrg_h)) - || (GT_32(Mult_32_32(L_shl(Mult_32_16(peak_l, 12800), exp3), L_shl(avrg_h, exp1)), Mult_32_32(L_shl(peak_h, exp3), L_shl(avrg_l, exp1))) > 0 && LT_32(Mult_32_16(peak_h, 21845), avrg_h))) + IF( ( GT_32( gain4, Mult_32_16( gain11, 26214 ) ) && GT_32( Mult_32_32( L_shl( peak_l, exp ), L_shl( avrg_h, exp1 ) ), Mult_32_32( L_shl( Mult_32_16( peak_h, 12800 ), exp ), L_shl( avrg_l, exp1 ) ) ) && LT_32( Mult_32_32( L_shl( Mult_32_16( peak_l, 6400 ), exp2 ), L_shl( avrg_h, exp1 ) ), Mult_32_32( L_shl( peak_h, exp2 ), L_shl( avrg_l, exp1 ) ) ) ) || ( GT_32( gain4, Mult_32_16( gain11, 9830 ) ) && LT_32( Mult_32_16( peak_h, 21845 ), avrg_h ) && LT_32( Mult_32_16( peak_H2, 21845 ), avrg_H2 ) ) || ( LT_32( Mult_32_32( L_shl( peak_l, exp ), L_shl( avrg_h, exp1 ) ), Mult_32_32( L_shl( Mult_32_16( peak_h, 12800 ), exp ), L_shl( avrg_l, exp1 ) ) ) && GT_32( Mult_32_16( peak_h, 21845 ), avrg_h ) ) || ( GT_32( Mult_32_32( L_shl( Mult_32_16( peak_l, 12800 ), exp3 ), L_shl( avrg_h, exp1 ) ), Mult_32_32( L_shl( peak_h, exp3 ), L_shl( avrg_l, exp1 ) ) ) > 0 && LT_32( Mult_32_16( peak_h, 21845 ), avrg_h ) ) ) { condition4 = 1; move16(); @@ -479,32 +489,33 @@ Word16 mdct_classifier_fx( /* o: MDCT A/B decision test(); test(); test(); - IF ((GE_32(brate, HQ_MDCTCLASS_CROSSOVER_BRATE) && GT_32(st_fx->input_Fs, 16000) && (s_xor(condition1,condition2)!=0||condition3)) - || ((LT_32(brate, HQ_MDCTCLASS_CROSSOVER_BRATE) || EQ_32(st_fx->input_Fs,16000) ) && condition4)) + IF( ( GE_32( brate, HQ_MDCTCLASS_CROSSOVER_BRATE ) && GT_32( st_fx->input_Fs, 16000 ) && ( s_xor( condition1, condition2 ) != 0 || condition3 ) ) || ( ( LT_32( brate, HQ_MDCTCLASS_CROSSOVER_BRATE ) || EQ_32( st_fx->input_Fs, 16000 ) ) && condition4 ) ) { - c = MDCT_CLASSIFER_HQ_LOCAL; /* Q13 */ move16(); + c = MDCT_CLASSIFER_HQ_LOCAL; /* Q13 */ + move16(); } ELSE { - c = MDCT_CLASSIFER_TCX_LOCAL; /* Q13 */ move16(); + c = MDCT_CLASSIFER_TCX_LOCAL; /* Q13 */ + move16(); } /* Smooth decision from instantaneous decision*/ - acc = L_mult(hTcxEnc->clas_sec_old_fx, MDCT_CLASSIFER_SMOOTH_FILT_COEFF); /* st_fx->clas_sec_old_fx in Q13 */ - clas_sec = mac_r(acc, c, 0x7fff - MDCT_CLASSIFER_SMOOTH_FILT_COEFF); /* clas_sec and c are in Q13 */ + acc = L_mult( hTcxEnc->clas_sec_old_fx, MDCT_CLASSIFER_SMOOTH_FILT_COEFF ); /* st_fx->clas_sec_old_fx in Q13 */ + clas_sec = mac_r( acc, c, 0x7fff - MDCT_CLASSIFER_SMOOTH_FILT_COEFF ); /* clas_sec and c are in Q13 */ /* Do thresholding with hysteresis */ - IF(GT_16(st_fx->last_enerBuffer_exp, enerBuffer_exp)) + IF( GT_16( st_fx->last_enerBuffer_exp, enerBuffer_exp ) ) { - gain1_tmp = L_shr(gain1, sub(st_fx->last_enerBuffer_exp, enerBuffer_exp)); + gain1_tmp = L_shr( gain1, sub( st_fx->last_enerBuffer_exp, enerBuffer_exp ) ); move32(); - gain2_tmp = L_shr(gain2, sub(st_fx->last_enerBuffer_exp, enerBuffer_exp)); + gain2_tmp = L_shr( gain2, sub( st_fx->last_enerBuffer_exp, enerBuffer_exp ) ); move32(); } ELSE { - hTcxEnc->last_gain1 = L_shr(hTcxEnc->last_gain1, sub(enerBuffer_exp, st_fx->last_enerBuffer_exp)); + hTcxEnc->last_gain1 = L_shr( hTcxEnc->last_gain1, sub( enerBuffer_exp, st_fx->last_enerBuffer_exp ) ); move32(); - hTcxEnc->last_gain2 = L_shr(hTcxEnc->last_gain2, sub(enerBuffer_exp, st_fx->last_enerBuffer_exp)); + hTcxEnc->last_gain2 = L_shr( hTcxEnc->last_gain2, sub( enerBuffer_exp, st_fx->last_enerBuffer_exp ) ); move32(); gain1_tmp = gain1; move32(); @@ -519,23 +530,20 @@ Word16 mdct_classifier_fx( /* o: MDCT A/B decision test(); test(); #ifdef BASOP_NOGLOB - IF ((EQ_16(hTcxEnc->clas_final_old, HQ_CORE) || EQ_16(hTcxEnc->clas_final_old,TCX_20_CORE)) - && ((GT_32(hTcxEnc->last_gain1, L_shr(gain1_tmp, 1)) && LT_32(hTcxEnc->last_gain1, L_shl_o(gain1_tmp, 1, &Overflow))) - && (GT_32(hTcxEnc->last_gain2, L_shr(gain2_tmp, 1)) && LT_32(hTcxEnc->last_gain2, L_shl_o(gain2_tmp, 1, &Overflow))))) + IF( ( EQ_16( hTcxEnc->clas_final_old, HQ_CORE ) || EQ_16( hTcxEnc->clas_final_old, TCX_20_CORE ) ) && ( ( GT_32( hTcxEnc->last_gain1, L_shr( gain1_tmp, 1 ) ) && LT_32( hTcxEnc->last_gain1, L_shl_o( gain1_tmp, 1, &Overflow ) ) ) && ( GT_32( hTcxEnc->last_gain2, L_shr( gain2_tmp, 1 ) ) && LT_32( hTcxEnc->last_gain2, L_shl_o( gain2_tmp, 1, &Overflow ) ) ) ) ) #else - IF ((EQ_16(hTcxEnc->clas_final_old, HQ_CORE) || EQ_16(hTcxEnc->clas_final_old,TCX_20_CORE)) - && ((GT_32(hTcxEnc->last_gain1, L_shr(gain1_tmp, 1)) && LT_32(hTcxEnc->last_gain1, L_shl(gain1_tmp, 1))) - && (GT_32(hTcxEnc->last_gain2, L_shr(gain2_tmp, 1)) && LT_32(hTcxEnc->last_gain2, L_shl(gain2_tmp, 1))))) + IF( ( EQ_16( hTcxEnc->clas_final_old, HQ_CORE ) || EQ_16( hTcxEnc->clas_final_old, TCX_20_CORE ) ) && ( ( GT_32( hTcxEnc->last_gain1, L_shr( gain1_tmp, 1 ) ) && LT_32( hTcxEnc->last_gain1, L_shl( gain1_tmp, 1 ) ) ) && ( GT_32( hTcxEnc->last_gain2, L_shr( gain2_tmp, 1 ) ) && LT_32( hTcxEnc->last_gain2, L_shl( gain2_tmp, 1 ) ) ) ) ) #endif { clas_final = hTcxEnc->clas_final_old; move16(); } - ELSE IF (GT_16(clas_sec, hTcxEnc->clas_sec_old_fx) && GT_16(clas_sec,MDCT_CLASSIFER_THRESH_UP)) /* Going up? */ + ELSE IF( GT_16( clas_sec, hTcxEnc->clas_sec_old_fx ) && GT_16( clas_sec, MDCT_CLASSIFER_THRESH_UP ) ) /* Going up? */ { - clas_final = HQ_CORE; /* Q0 */ move16(); + clas_final = HQ_CORE; /* Q0 */ + move16(); } - ELSE IF (LT_16(clas_sec, MDCT_CLASSIFER_THRESH_DOWN))/* Going down */ + ELSE IF( LT_16( clas_sec, MDCT_CLASSIFER_THRESH_DOWN ) ) /* Going down */ { clas_final = TCX_20_CORE; move16(); @@ -550,7 +558,7 @@ Word16 mdct_classifier_fx( /* o: MDCT A/B decision test(); test(); /* Prevent the usage of MDCTA on noisy-speech or inactive */ - if ( EQ_16(st_fx->mdct_sw_enable, MODE2) && (EQ_16(st_fx->flag_noisy_speech_snr_fx,1) || st_fx->vad_flag==0) && EQ_16(clas_final,HQ_CORE)) + if ( EQ_16( st_fx->mdct_sw_enable, MODE2 ) && ( EQ_16( st_fx->flag_noisy_speech_snr_fx, 1 ) || st_fx->vad_flag == 0 ) && EQ_16( clas_final, HQ_CORE ) ) { clas_final = TCX_20_CORE; move16(); @@ -558,8 +566,10 @@ Word16 mdct_classifier_fx( /* o: MDCT A/B decision /* Restrict usage of HQ_core to supported operating range */ /* EVS: brate == st->total_brate */ /* IVAS: brate is the nominal bitrate while st->total_brate may fluctuate. This sets a hard limit for HQ at HQ_16k40 */ - test();test();test(); - if (LE_32(st_fx->total_brate, HQ_16k40) || LT_32(brate, HQ_16k40) || EQ_16(st_fx->bwidth, NB) || GT_32(brate, IVAS_48k)) + test(); + test(); + test(); + if ( LE_32( st_fx->total_brate, HQ_16k40 ) || LT_32( brate, HQ_16k40 ) || EQ_16( st_fx->bwidth, NB ) || GT_32( brate, IVAS_48k ) ) { clas_final = TCX_20_CORE; move16(); @@ -569,7 +579,7 @@ Word16 mdct_classifier_fx( /* o: MDCT A/B decision hTcxEnc->clas_sec_old_fx = clas_sec; move16(); /* Q13 */ hTcxEnc->clas_final_old = clas_final; - move16(); /* Q0 */ + move16(); /* Q0 */ hTcxEnc->last_gain1 = gain1; move32(); hTcxEnc->last_gain2 = gain2; @@ -577,7 +587,5 @@ Word16 mdct_classifier_fx( /* o: MDCT A/B decision st_fx->last_enerBuffer_exp = enerBuffer_exp; move16(); - return clas_final; /* Q0 */ + return clas_final; /* Q0 */ } - - diff --git a/lib_enc/mdct_selector.c b/lib_enc/mdct_selector.c index 1f30534a9..af660e2f8 100644 --- a/lib_enc/mdct_selector.c +++ b/lib_enc/mdct_selector.c @@ -191,7 +191,7 @@ void MDCT_selector( /* Allowed switching point? */ switching_point = ( last_core != HQ_CORE && last_core != TCX_20_CORE ) || /* previous core was non-MDCT */ - ( hTcxEnc->prev_hi_ener_flt <= MDCT_SW_HI_ENER_LO_THR || hi_ener <= MDCT_SW_HI_ENER_LO_THR ) || /* hi band is close to silent */ + ( hTcxEnc->prev_hi_ener_flt <= MDCT_SW_HI_ENER_LO_THR || hi_ener <= MDCT_SW_HI_ENER_LO_THR ) || /* hi band is close to silent */ ( last_core == HQ_CORE && ( st->mdct_sw_enable == MODE1 || ( hi_sparse > 0 && hTcxEnc->prev_hi_sparse >= 0 && hTcxEnc->prev_hi_sparse <= 1 ) ) ) || /* HQ_CORE and hi band became sparse */ ( last_core == TCX_20_CORE && ( hi_sparse == 0 && hTcxEnc->prev_hi_sparse > 0 ) ); /* TCX and hi band became dense */ diff --git a/lib_enc/mdct_selector_fx.c b/lib_enc/mdct_selector_fx.c index 20bc21392..d2e0b980c 100644 --- a/lib_enc/mdct_selector_fx.c +++ b/lib_enc/mdct_selector_fx.c @@ -7,38 +7,38 @@ #include "cnst.h" //#include "prot_fx.h" #include "rom_com.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*-----------------------------------------------------------------* * Local constants *-----------------------------------------------------------------*/ -# define MDCT_SW_SIG_LINE_THR 840 /* 2.85f*LOG_10 in Q7 */ /* Significant spectral line threshold above Etot (dB) */ -# define MDCT_SW_SIG_PEAK_THR 9216 /* 36.0f in Q8 */ /* Significant peak threshold below Etot (dB) */ -# define MDCT_SW_HI_SPARSE_THR 8192 /* 0.25f in Q15*/ /* Max. ratio of significant spectral lines for the spectrum to be considered sparse */ -# define MDCT_SW_HI_ENER_LO_THR 1920 /* 7.5f in Q8 */ /* Hi band low energy threshold (dB) */ -# define MDCT_SW_SPARSE_THR 6554 /* 0.25f*0.8f in Q15*/ -# define MDCT_SW_1_VOICING_THR 29491 /* 0.9f in Q15*/ /* Voicing threshold */ -# define MDCT_SW_1_VOICING_THR2 23593 /* 0.9f*0.8f in Q15*/ -# define MDCT_SW_1_HI_ENER_LO_THR 3200 /* 12.5f in Q8 */ /* Hi band high energy threshold (dB) */ -# define MDCT_SW_1_SIG_HI_LEVEL_THR 7168 /* 28.0f in Q8 */ /* High signal level threshold above noise floor (dB) */ -# define MDCT_SW_1_SIG_LO_LEVEL_THR 5760 /* 22.5f in Q8 */ /* Low signal level threshold above noise floor (dB) */ -# define MDCT_SW_1_COR_THR 20480 /* 80.0f in Q8 */ /* Threshold on cor_map_sum to indicate strongly tonal signal */ -# define MDCT_SW_1_COR_THR2 16384 /* 80.0f*0.8f in Q8 */ -# define MDCT_SW_1_SPARSENESS_THR 21299 /* 0.65f in Q15*/ /* Threshold on spectrum sparseness */ -# define MDCT_SW_1_SPARSENESS_THR2 17039 /* 0.65f*0.8f in Q15*/ - -# define MDCT_SW_2_VOICING_THR 19661 /* 0.6f in Q15*/ /* Voicing threshold */ -# define MDCT_SW_2_VOICING_THR2 15729 /* 0.6f*0.8f in Q15*/ -# define MDCT_SW_2_HI_ENER_LO_THR 2432 /* 9.5f in Q8 */ /* Hi band low energy threshold (dB) */ -# define MDCT_SW_2_SIG_HI_LEVEL_THR 4864 /* 19.0f in Q8 */ /* High signal level threshold above noise floor (dB) */ -# define MDCT_SW_2_SIG_LO_LEVEL_THR 6016 /* 23.5f in Q8 */ /* Low signal level threshold above noise floor (dB) */ -# define MDCT_SW_2_COR_THR 16000 /* 62.5f in Q8 */ /* Threshold on cor_map_sum to indicate strongly tonal signal */ -# define MDCT_SW_2_COR_THR2 12800 /* 62.5f*0.8f in Q8 */ -# define MDCT_SW_2_SPARSENESS_THR 13107 /* 0.4f in Q15*/ /* Threshold on spectrum sparseness */ -# define MDCT_SW_2_SPARSENESS_THR2 10486 /* 0.4f*0.8f in Q15*/ +#define MDCT_SW_SIG_LINE_THR 840 /* 2.85f*LOG_10 in Q7 */ /* Significant spectral line threshold above Etot (dB) */ +#define MDCT_SW_SIG_PEAK_THR 9216 /* 36.0f in Q8 */ /* Significant peak threshold below Etot (dB) */ +#define MDCT_SW_HI_SPARSE_THR 8192 /* 0.25f in Q15*/ /* Max. ratio of significant spectral lines for the spectrum to be considered sparse */ +#define MDCT_SW_HI_ENER_LO_THR 1920 /* 7.5f in Q8 */ /* Hi band low energy threshold (dB) */ +#define MDCT_SW_SPARSE_THR 6554 /* 0.25f*0.8f in Q15*/ +#define MDCT_SW_1_VOICING_THR 29491 /* 0.9f in Q15*/ /* Voicing threshold */ +#define MDCT_SW_1_VOICING_THR2 23593 /* 0.9f*0.8f in Q15*/ +#define MDCT_SW_1_HI_ENER_LO_THR 3200 /* 12.5f in Q8 */ /* Hi band high energy threshold (dB) */ +#define MDCT_SW_1_SIG_HI_LEVEL_THR 7168 /* 28.0f in Q8 */ /* High signal level threshold above noise floor (dB) */ +#define MDCT_SW_1_SIG_LO_LEVEL_THR 5760 /* 22.5f in Q8 */ /* Low signal level threshold above noise floor (dB) */ +#define MDCT_SW_1_COR_THR 20480 /* 80.0f in Q8 */ /* Threshold on cor_map_sum to indicate strongly tonal signal */ +#define MDCT_SW_1_COR_THR2 16384 /* 80.0f*0.8f in Q8 */ +#define MDCT_SW_1_SPARSENESS_THR 21299 /* 0.65f in Q15*/ /* Threshold on spectrum sparseness */ +#define MDCT_SW_1_SPARSENESS_THR2 17039 /* 0.65f*0.8f in Q15*/ + +#define MDCT_SW_2_VOICING_THR 19661 /* 0.6f in Q15*/ /* Voicing threshold */ +#define MDCT_SW_2_VOICING_THR2 15729 /* 0.6f*0.8f in Q15*/ +#define MDCT_SW_2_HI_ENER_LO_THR 2432 /* 9.5f in Q8 */ /* Hi band low energy threshold (dB) */ +#define MDCT_SW_2_SIG_HI_LEVEL_THR 4864 /* 19.0f in Q8 */ /* High signal level threshold above noise floor (dB) */ +#define MDCT_SW_2_SIG_LO_LEVEL_THR 6016 /* 23.5f in Q8 */ /* Low signal level threshold above noise floor (dB) */ +#define MDCT_SW_2_COR_THR 16000 /* 62.5f in Q8 */ /* Threshold on cor_map_sum to indicate strongly tonal signal */ +#define MDCT_SW_2_COR_THR2 12800 /* 62.5f*0.8f in Q8 */ +#define MDCT_SW_2_SPARSENESS_THR 13107 /* 0.4f in Q15*/ /* Threshold on spectrum sparseness */ +#define MDCT_SW_2_SPARSENESS_THR2 10486 /* 0.4f*0.8f in Q15*/ /*--------------------------------------------------------------------------* * get_sparseness() @@ -46,31 +46,31 @@ * *--------------------------------------------------------------------------*/ -static Word16 get_sparseness( /* Returns sparseness measure (Q15) */ - const Word16 Bin_E[], /* i : per bin energy dB Q7 */ - Word16 n, /* i : number of bins Q0 */ - Word16 thr /* i : peak threshold Q8 */ +static Word16 get_sparseness( /* Returns sparseness measure (Q15) */ + const Word16 Bin_E[], /* i : per bin energy dB Q7 */ + Word16 n, /* i : number of bins Q0 */ + Word16 thr /* i : peak threshold Q8 */ ) { Word16 num_max, i; - thr = add(thr, mult(thr, 4958)); /* Convert to 10*log() domain from 10*log10() domain, and also to Q7 */ + thr = add( thr, mult( thr, 4958 ) ); /* Convert to 10*log() domain from 10*log10() domain, and also to Q7 */ - thr = s_max(thr, 384); /* 3.0 in Q7 */ /* Set an absolute minimum for close to silent signals */ + thr = s_max( thr, 384 ); /* 3.0 in Q7 */ /* Set an absolute minimum for close to silent signals */ num_max = 0; move16(); - FOR (i=1; ihTcxEnc; test(); - IF (EQ_16(st->mdct_sw_enable, MODE1)||EQ_16(st->mdct_sw_enable,MODE2)) + IF( EQ_16( st->mdct_sw_enable, MODE1 ) || EQ_16( st->mdct_sw_enable, MODE2 ) ) { Word16 hi_ener, frame_voicing, sparseness; Word16 peak_count; @@ -133,80 +134,87 @@ void MDCT_selector_fx( Word16 sig_lo_level_thr, sig_hi_level_thr, cor_thr, cor_thr2, voicing_thr, voicing_thr2, sparseness_thr, sparseness_thr2, hi_ener_lo_thr; Word16 last_core; - sp_floor = shl(sp_floor, 1); /* convert to Q8 */ + sp_floor = shl( sp_floor, 1 ); /* convert to Q8 */ - IF (EQ_16(st->bwidth, NB)) + IF( EQ_16( st->bwidth, NB ) ) { - lob_cldfb = 3200/400; + lob_cldfb = 3200 / 400; move16(); - hib_cldfb = 4000/400; + hib_cldfb = 4000 / 400; + move16(); + lob_fft = ( L_FFT / 2 ) / 2; /* 3.2 KHz */ + move16(); + hib_fft = ( 40 * ( L_FFT / 2 ) ) / 64; /* 4.0 KHz */ move16(); - lob_fft = (L_FFT/2)/2; /* 3.2 KHz */ move16(); - hib_fft = (40*(L_FFT/2))/64; /* 4.0 KHz */ move16(); } - ELSE IF (EQ_16(st->bwidth, WB)) + ELSE IF( EQ_16( st->bwidth, WB ) ) { - lob_cldfb = 4800/400; + lob_cldfb = 4800 / 400; + move16(); + hib_cldfb = 8000 / 400; + move16(); + lob_fft = 3 * L_FFT / 2 / 4; /* 4.8 KHz */ move16(); - hib_cldfb = 8000/400; + hib_fft = L_FFT / 2; /* 6.4 KHz (should be 8 KHz) */ move16(); - lob_fft = 3*L_FFT/2/4; /* 4.8 KHz */ move16(); - hib_fft = L_FFT/2; /* 6.4 KHz (should be 8 KHz) */ move16(); } ELSE { - lob_cldfb = 6400/400; + lob_cldfb = 6400 / 400; move16(); - hib_cldfb = 16000/400; + hib_cldfb = 16000 / 400; move16(); - if (EQ_16(st->bwidth, FB)) + if ( EQ_16( st->bwidth, FB ) ) { - hib_cldfb = 24000/400; + hib_cldfb = 24000 / 400; move16(); } - lob_fft = L_FFT/2; /* 6.4 KHz */ move16(); - hib_fft = L_FFT/2; /* 6.4 KHz (should be 8 KHz) */ move16(); + lob_fft = L_FFT / 2; /* 6.4 KHz */ + move16(); + hib_fft = L_FFT / 2; /* 6.4 KHz (should be 8 KHz) */ + move16(); } /* st->last_core is reset to TCX_20_CORE in init_acelp() => fix it here */ last_core = st->last_core; move16(); test(); - if (EQ_16(st->last_codec_mode, MODE1)&&EQ_16(last_core,TCX_20_CORE)) + if ( EQ_16( st->last_codec_mode, MODE1 ) && EQ_16( last_core, TCX_20_CORE ) ) { last_core = HQ_CORE; move16(); } /* Voicing */ - frame_voicing = add(shr(st->voicing_fx[0], 1), shr(st->voicing_fx[1], 1)); + frame_voicing = add( shr( st->voicing_fx[0], 1 ), shr( st->voicing_fx[1], 1 ) ); /* Spectral sparseness */ - sparseness = get_sparseness(st->lgBin_E_fx, lob_fft, sub(Etot, MDCT_SW_SIG_PEAK_THR)); + sparseness = get_sparseness( st->lgBin_E_fx, lob_fft, sub( Etot, MDCT_SW_SIG_PEAK_THR ) ); /* Hi band energy */ - hi_ener = get_mean_ener(&enerBuffer[lob_cldfb], enerBuffer_exp, sub(hib_cldfb, lob_cldfb)); + hi_ener = get_mean_ener( &enerBuffer[lob_cldfb], enerBuffer_exp, sub( hib_cldfb, lob_cldfb ) ); /* Hi band sparseness */ - IF (GE_16(st->bwidth, SWB)) + IF( GE_16( st->bwidth, SWB ) ) { /* For SWB, assume hi band sparseness based on 4.8 KHz-6.4 KHz band */ - lob_fft = 3*L_FFT/2/4; /* 4.8 KHz */ move16(); + lob_fft = 3 * L_FFT / 2 / 4; /* 4.8 KHz */ + move16(); } peak_count = 0; move16(); - tmp = add(MDCT_SW_SIG_LINE_THR, shr(Etot, 1)); /* Q7 */ - FOR (i=lob_fft; ilgBin_E_fx[i], tmp)) + if ( GE_16( st->lgBin_E_fx[i], tmp ) ) { - peak_count = add(peak_count, 1); + peak_count = add( peak_count, 1 ); } } hi_sparse = 0; move16(); - if (LE_16(peak_count, mult_r(sub(hib_fft, lob_fft), MDCT_SW_HI_SPARSE_THR))) + if ( LE_16( peak_count, mult_r( sub( hib_fft, lob_fft ), MDCT_SW_HI_SPARSE_THR ) ) ) { hi_sparse = 1; move16(); @@ -214,7 +222,7 @@ void MDCT_selector_fx( sparse = 0; move16(); - if (LE_16(peak_count, mult_r(sub(hib_fft, lob_fft), MDCT_SW_SPARSE_THR))) + if ( LE_16( peak_count, mult_r( sub( hib_fft, lob_fft ), MDCT_SW_SPARSE_THR ) ) ) { sparse = 1; move16(); @@ -223,7 +231,7 @@ void MDCT_selector_fx( /* Hysteresis */ test(); test(); - if (hTcxEnc->prev_hi_sparse > 0 && sparse > 0 && GE_16(s_min(s_min(st->voicing_fx[0], st->voicing_fx[1]), st->voicing_fx[2]), MDCT_SW_1_VOICING_THR)) + if ( hTcxEnc->prev_hi_sparse > 0 && sparse > 0 && GE_16( s_min( s_min( st->voicing_fx[0], st->voicing_fx[1] ), st->voicing_fx[2] ), MDCT_SW_1_VOICING_THR ) ) { hi_sparse = 1; move16(); @@ -241,51 +249,51 @@ void MDCT_selector_fx( test(); test(); test(); - switching_point = (NE_16(last_core, HQ_CORE) && NE_16(last_core, TCX_20_CORE) ) || /* previous core was non-MDCT */ - (LE_16(hTcxEnc->prev_hi_ener, MDCT_SW_HI_ENER_LO_THR) || LE_16(hi_ener, MDCT_SW_HI_ENER_LO_THR) ) || /* hi band is close to silent */ - (EQ_16(last_core, HQ_CORE) && (EQ_16(st->mdct_sw_enable, MODE1) || (hi_sparse > 0 && hTcxEnc->prev_hi_sparse >= 0 && LE_16(hTcxEnc->prev_hi_sparse, 1) ))) || /* HQ_CORE and hi band became sparse */ - (EQ_16(last_core, TCX_20_CORE) && (hi_sparse == 0 && hTcxEnc->prev_hi_sparse > 0)); /* TCX and hi band became dense */ + switching_point = ( NE_16( last_core, HQ_CORE ) && NE_16( last_core, TCX_20_CORE ) ) || /* previous core was non-MDCT */ + ( LE_16( hTcxEnc->prev_hi_ener, MDCT_SW_HI_ENER_LO_THR ) || LE_16( hi_ener, MDCT_SW_HI_ENER_LO_THR ) ) || /* hi band is close to silent */ + ( EQ_16( last_core, HQ_CORE ) && ( EQ_16( st->mdct_sw_enable, MODE1 ) || ( hi_sparse > 0 && hTcxEnc->prev_hi_sparse >= 0 && LE_16( hTcxEnc->prev_hi_sparse, 1 ) ) ) ) || /* HQ_CORE and hi band became sparse */ + ( EQ_16( last_core, TCX_20_CORE ) && ( hi_sparse == 0 && hTcxEnc->prev_hi_sparse > 0 ) ); /* TCX and hi band became dense */ - IF (EQ_16(st->mdct_sw_enable, MODE1)) + IF( EQ_16( st->mdct_sw_enable, MODE1 ) ) { sig_lo_level_thr = MDCT_SW_1_SIG_LO_LEVEL_THR; move16(); sig_hi_level_thr = MDCT_SW_1_SIG_HI_LEVEL_THR; move16(); - cor_thr = MDCT_SW_1_COR_THR; + cor_thr = MDCT_SW_1_COR_THR; move16(); - cor_thr2 = MDCT_SW_1_COR_THR2; + cor_thr2 = MDCT_SW_1_COR_THR2; move16(); - voicing_thr = MDCT_SW_1_VOICING_THR; + voicing_thr = MDCT_SW_1_VOICING_THR; move16(); - voicing_thr2 = MDCT_SW_1_VOICING_THR2; + voicing_thr2 = MDCT_SW_1_VOICING_THR2; move16(); - sparseness_thr = MDCT_SW_1_SPARSENESS_THR; + sparseness_thr = MDCT_SW_1_SPARSENESS_THR; move16(); - sparseness_thr2 = MDCT_SW_1_SPARSENESS_THR2; + sparseness_thr2 = MDCT_SW_1_SPARSENESS_THR2; move16(); - hi_ener_lo_thr = MDCT_SW_1_HI_ENER_LO_THR; + hi_ener_lo_thr = MDCT_SW_1_HI_ENER_LO_THR; move16(); } - ELSE /* st->mdct_sw_enable == MODE2 */ + ELSE /* st->mdct_sw_enable == MODE2 */ { sig_lo_level_thr = MDCT_SW_2_SIG_LO_LEVEL_THR; move16(); sig_hi_level_thr = MDCT_SW_2_SIG_HI_LEVEL_THR; move16(); - cor_thr = MDCT_SW_2_COR_THR; + cor_thr = MDCT_SW_2_COR_THR; move16(); - cor_thr2 = MDCT_SW_2_COR_THR2; + cor_thr2 = MDCT_SW_2_COR_THR2; move16(); - voicing_thr = MDCT_SW_2_VOICING_THR; + voicing_thr = MDCT_SW_2_VOICING_THR; move16(); - voicing_thr2 = MDCT_SW_2_VOICING_THR2; + voicing_thr2 = MDCT_SW_2_VOICING_THR2; move16(); - sparseness_thr = MDCT_SW_2_SPARSENESS_THR; + sparseness_thr = MDCT_SW_2_SPARSENESS_THR; move16(); - sparseness_thr2 = MDCT_SW_2_SPARSENESS_THR2; + sparseness_thr2 = MDCT_SW_2_SPARSENESS_THR2; move16(); - hi_ener_lo_thr = MDCT_SW_2_HI_ENER_LO_THR; + hi_ener_lo_thr = MDCT_SW_2_HI_ENER_LO_THR; move16(); } @@ -294,9 +302,9 @@ void MDCT_selector_fx( test(); test(); test(); - prefer_tcx = (GE_16(sub(Etot, sp_floor), sig_hi_level_thr)) && /* noise floor is low */ - (GE_16(cor_map_sum, cor_thr) || GE_16(frame_voicing, voicing_thr) || GE_16(sparseness, sparseness_thr) ) && /* strong tonal components */ - (LE_16(hi_ener, hi_ener_lo_thr) || hi_sparse > 0); /* high freqs have low energy or are sparse */ + prefer_tcx = ( GE_16( sub( Etot, sp_floor ), sig_hi_level_thr ) ) && /* noise floor is low */ + ( GE_16( cor_map_sum, cor_thr ) || GE_16( frame_voicing, voicing_thr ) || GE_16( sparseness, sparseness_thr ) ) && /* strong tonal components */ + ( LE_16( hi_ener, hi_ener_lo_thr ) || hi_sparse > 0 ); /* high freqs have low energy or are sparse */ test(); test(); @@ -304,13 +312,13 @@ void MDCT_selector_fx( test(); test(); test(); - prefer_hq_core = (LT_16(sub(Etot, sp_floor), sig_lo_level_thr) ) || /* noise floor is very high */ - (LT_16(cor_map_sum, cor_thr2) && LT_16(frame_voicing, voicing_thr2) && LT_16(sparseness, sparseness_thr2) ) || /* too weak tonal components */ - (EQ_16(st->mdct_sw_enable, MODE1) && prefer_tcx == 0 && EQ_16(st->transientDetection.transientDetector.bIsAttackPresent, 1) ); + prefer_hq_core = ( LT_16( sub( Etot, sp_floor ), sig_lo_level_thr ) ) || /* noise floor is very high */ + ( LT_16( cor_map_sum, cor_thr2 ) && LT_16( frame_voicing, voicing_thr2 ) && LT_16( sparseness, sparseness_thr2 ) ) || /* too weak tonal components */ + ( EQ_16( st->mdct_sw_enable, MODE1 ) && prefer_tcx == 0 && EQ_16( st->transientDetection.transientDetector.bIsAttackPresent, 1 ) ); /* Prefer HQ_CORE on transients */ test(); - IF ( EQ_16(st->mdct_sw_enable, MODE2)&&EQ_16(st->transientDetection.transientDetector.bIsAttackPresent,1)) + IF( EQ_16( st->mdct_sw_enable, MODE2 ) && EQ_16( st->transientDetection.transientDetector.bIsAttackPresent, 1 ) ) { prefer_tcx = 0; move16(); @@ -321,9 +329,9 @@ void MDCT_selector_fx( test(); test(); test(); - IF (switching_point && (prefer_tcx || prefer_hq_core)) + IF( switching_point && ( prefer_tcx || prefer_hq_core ) ) { - IF (prefer_tcx) + IF( prefer_tcx ) { st->core = TCX_20_CORE; move16(); @@ -334,7 +342,7 @@ void MDCT_selector_fx( move16(); } } - ELSE IF (EQ_16(last_core, HQ_CORE)||EQ_16(last_core,TCX_20_CORE)) + ELSE IF( EQ_16( last_core, HQ_CORE ) || EQ_16( last_core, TCX_20_CORE ) ) { st->core = last_core; move16(); @@ -344,21 +352,21 @@ void MDCT_selector_fx( test(); test(); /* Prevent the usage of HQ_CORE on noisy-speech or inactive */ - IF (EQ_16(st->mdct_sw_enable, MODE2)&&EQ_16(st->core,HQ_CORE)&&(EQ_16(st->flag_noisy_speech_snr_fx,1)||st->vad_flag==0)) + IF( EQ_16( st->mdct_sw_enable, MODE2 ) && EQ_16( st->core, HQ_CORE ) && ( EQ_16( st->flag_noisy_speech_snr_fx, 1 ) || st->vad_flag == 0 ) ) { st->core = TCX_20_CORE; move16(); } /* Update memories */ - hTcxEnc->prev_hi_sparse = add(hTcxEnc->prev_hi_sparse, hi_sparse); + hTcxEnc->prev_hi_sparse = add( hTcxEnc->prev_hi_sparse, hi_sparse ); move16(); - if (hi_sparse <= 0) + if ( hi_sparse <= 0 ) { hTcxEnc->prev_hi_sparse = hi_sparse; move16(); } - hTcxEnc->prev_hi_sparse = s_min(hTcxEnc->prev_hi_sparse, 2); + hTcxEnc->prev_hi_sparse = s_min( hTcxEnc->prev_hi_sparse, 2 ); hTcxEnc->prev_hi_ener = hi_ener; move16(); } @@ -369,8 +377,7 @@ void MDCT_selector_fx( * reset MDCT selector memories *--------------------------------------------------------------------------*/ void MDCT_selector_reset_fx( - TCX_ENC_HANDLE hTcxEnc -) + TCX_ENC_HANDLE hTcxEnc ) { hTcxEnc->prev_hi_ener = 0; move16(); @@ -386,8 +393,9 @@ void MDCT_classifier_reset_fx( TCX_ENC_HANDLE hTcxEnc /* i/o: TCX Encoder Handle */ ) { - hTcxEnc->clas_sec_old_fx = 8192; /* 1.0f in Q13 */; - hTcxEnc->clas_final_old = 1; /* Q0 */ + hTcxEnc->clas_sec_old_fx = 8192; /* 1.0f in Q13 */ + ; + hTcxEnc->clas_final_old = 1; /* Q0 */ hTcxEnc->last_gain1 = 0; move32(); hTcxEnc->last_gain2 = 0; diff --git a/lib_enc/mslvq_enc_fx.c b/lib_enc/mslvq_enc_fx.c index 45fb0729a..b68315506 100644 --- a/lib_enc/mslvq_enc_fx.c +++ b/lib_enc/mslvq_enc_fx.c @@ -7,29 +7,24 @@ #include "rom_com_fx.h" #include "rom_com.h" #include "stl.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*-----------------------------------------------------------------* * Local functions *-----------------------------------------------------------------*/ -static Word32 quantize_data_fx( Word16 *data, const Word16 *w_in, Word16 *qin, Word16 *cv_out, Word16 *idx_lead, Word16 *idx_scale, const Word16 *sigma, const Word16 *inv_sigma, - const Word16 *scales, Word16 no_scales, const Word16 *no_lead ); -static Word32 q_data_fx(Word16 *pTmp1, const Word16 *w1, Word16 *quant, Word16 *cv_out, Word16 *idx_lead, Word16 *idx_scale, - const Word16 *p_sigma, const Word16 *p_inv_sigma, const Word16 *p_scales, Word16 *p_no_scales, - const Word16 *p_no_lead); -static void prepare_data_fx( Word16 *xsort, Word16 *sign, Word16 *data, Word32 *w, const Word16 *w_in, - const Word16 *sigma, const Word16 * inv_sigma, Word16 *p_sig ); -static Word32 calculate_min_dist_fx(Word16 cv_pot[LATTICE_DIM],Word16 no_scales, const Word16 *scale, - const Word32 *w, Word16 *p_best_scale, Word16 *p_best_idx, const Word16 *no_leaders, Word16 sig,Word16 *indx); -static Word16 find_pos_fx( Word16 *c, Word16 len, Word16 arg, Word16 *p ); +static Word32 quantize_data_fx( Word16 *data, const Word16 *w_in, Word16 *qin, Word16 *cv_out, Word16 *idx_lead, Word16 *idx_scale, const Word16 *sigma, const Word16 *inv_sigma, const Word16 *scales, Word16 no_scales, const Word16 *no_lead ); +static Word32 q_data_fx( Word16 *pTmp1, const Word16 *w1, Word16 *quant, Word16 *cv_out, Word16 *idx_lead, Word16 *idx_scale, const Word16 *p_sigma, const Word16 *p_inv_sigma, const Word16 *p_scales, Word16 *p_no_scales, const Word16 *p_no_lead ); +static void prepare_data_fx( Word16 *xsort, Word16 *sign, Word16 *data, Word32 *w, const Word16 *w_in, const Word16 *sigma, const Word16 *inv_sigma, Word16 *p_sig ); +static Word32 calculate_min_dist_fx( Word16 cv_pot[LATTICE_DIM], Word16 no_scales, const Word16 *scale, const Word32 *w, Word16 *p_best_scale, Word16 *p_best_idx, const Word16 *no_leaders, Word16 sig, Word16 *indx ); +static Word16 find_pos_fx( Word16 *c, Word16 len, Word16 arg, Word16 *p ); static void take_out_val_fx( Word16 *v, Word16 *v_out, Word16 val, Word16 len ); static Word16 index_leaders_fx( Word16 *cv, Word16 idx_lead, Word16 dim ); static Word16 c2idx_fx( Word16 n, Word16 *p, Word16 k ); -static Word16 encode_sign_pc1_fx( Word16 parity, Word16 *cv); +static Word16 encode_sign_pc1_fx( Word16 parity, Word16 *cv ); static Word32 encode_comb_fx( Word16 *cv, Word16 idx_lead ); static void sort_desc_ind_fx( Word16 *s, Word16 len, Word16 *ind ); @@ -39,30 +34,29 @@ static void sort_desc_ind_fx( Word16 *s, Word16 len, Word16 *ind ); * * Encodes the LSF residual *-----------------------------------------------------------------*/ -Word32 mslvq_fx ( - Word16 *pTmp, /* i : M-dimensional input vector x2.56*/ - Word16 *quant, /* o : quantized vector x2.56*/ - Word16 *cv_out, /* o : corresponding 8-dim lattice codevectors (without the scaling) Q13*/ - Word16 *idx_lead, /* o : leader index for each 8-dim subvector */ - Word16 *idx_scale, /* o : scale index for each subvector */ - Word16 *w, /* i : weights for LSF quantization Q10*/ - Word16 mode, /* i : number indicating the coding type (V/UV/G...)*/ - Word16 mode_glb, /* i : LVQ coding mode */ - Word16 pred_flag, /* i : prediction flag (0: safety net, 1,2 - predictive )*/ - Word16 no_scales[][2] -) +Word32 mslvq_fx( + Word16 *pTmp, /* i : M-dimensional input vector x2.56*/ + Word16 *quant, /* o : quantized vector x2.56*/ + Word16 *cv_out, /* o : corresponding 8-dim lattice codevectors (without the scaling) Q13*/ + Word16 *idx_lead, /* o : leader index for each 8-dim subvector */ + Word16 *idx_scale, /* o : scale index for each subvector */ + Word16 *w, /* i : weights for LSF quantization Q10*/ + Word16 mode, /* i : number indicating the coding type (V/UV/G...)*/ + Word16 mode_glb, /* i : LVQ coding mode */ + Word16 pred_flag, /* i : prediction flag (0: safety net, 1,2 - predictive )*/ + Word16 no_scales[][2] ) { Word32 dist, L_tmp; - const Word16 * p_scales, *p_sigma, *p_inv_sigma; - const Word16 *p_no_lead; - Word16 * p_no_scales; + const Word16 *p_scales, *p_sigma, *p_inv_sigma; + const Word16 *p_no_lead; + Word16 *p_no_scales; - dist = L_deposit_l(0); + dist = L_deposit_l( 0 ); p_no_scales = no_scales[mode_glb]; move16(); - IF ( pred_flag == 0 ) + IF( pred_flag == 0 ) { p_sigma = sigma_MSLVQ_fx[mode]; /* inverse sigma is precomputed to save complexity */ @@ -72,10 +66,10 @@ Word32 mslvq_fx ( } ELSE { - p_sigma = sigma_p_fx[mode]; - /* inverse sigma is precomputed to save complexity */ - p_inv_sigma = inv_sigma_p_fx[mode]; - p_scales = scales_p_fx[mode_glb]; + p_sigma = sigma_p_fx[mode]; + /* inverse sigma is precomputed to save complexity */ + p_inv_sigma = inv_sigma_p_fx[mode]; + p_scales = scales_p_fx[mode_glb]; p_no_lead = no_lead_p_fx[mode_glb]; } @@ -83,12 +77,12 @@ Word32 mslvq_fx ( dist = quantize_data_fx( pTmp, w, quant, cv_out, idx_lead, idx_scale, p_sigma, p_inv_sigma, p_scales, p_no_scales[0], p_no_lead ); /* second subvector */ - L_tmp = quantize_data_fx(pTmp + LATTICE_DIM, w + LATTICE_DIM, quant + LATTICE_DIM, - cv_out + LATTICE_DIM, &idx_lead[1], &idx_scale[1], - p_sigma + LATTICE_DIM, p_inv_sigma + LATTICE_DIM, p_scales + MAX_NO_SCALES, - p_no_scales[1], p_no_lead+MAX_NO_SCALES ); + L_tmp = quantize_data_fx( pTmp + LATTICE_DIM, w + LATTICE_DIM, quant + LATTICE_DIM, + cv_out + LATTICE_DIM, &idx_lead[1], &idx_scale[1], + p_sigma + LATTICE_DIM, p_inv_sigma + LATTICE_DIM, p_scales + MAX_NO_SCALES, + p_no_scales[1], p_no_lead + MAX_NO_SCALES ); - dist = L_add(dist, L_tmp); + dist = L_add( dist, L_tmp ); return dist; } @@ -103,8 +97,8 @@ static Word32 q_data_fx( const Word16 *w1, /* i: M-dimensional weight vector Q8 */ Word16 *quant, /* o: quantized vector x2.56 */ Word16 *cv_out, /* o: non-scaled lattice codevector x2.56 */ - Word16 *idx_lead, /* o: leader indexes for each subvector */ - Word16 *idx_scale, /* o: scale indexes for each subvector */ + Word16 *idx_lead, /* o: leader indexes for each subvector */ + Word16 *idx_scale, /* o: scale indexes for each subvector */ const Word16 *p_sigma, /* i: standard deviation x2.56 */ const Word16 *p_inv_sigma, /* i: inverse standard deviation Q15 */ const Word16 *p_scales, /* i: scale values Q11 */ @@ -117,12 +111,12 @@ static Word32 q_data_fx( dist = quantize_data_fx( pTmp1, w1, quant, cv_out, idx_lead, idx_scale, p_sigma, p_inv_sigma, p_scales, p_no_scales[0], p_no_lead ); /* second subvector */ - L_tmp = quantize_data_fx( pTmp1+LATTICE_DIM, w1+LATTICE_DIM, - quant+LATTICE_DIM, cv_out+LATTICE_DIM, &idx_lead[1], &idx_scale[1], - p_sigma+LATTICE_DIM, p_inv_sigma+LATTICE_DIM, p_scales+MAX_NO_SCALES, - p_no_scales[1], p_no_lead+MAX_NO_SCALES ); + L_tmp = quantize_data_fx( pTmp1 + LATTICE_DIM, w1 + LATTICE_DIM, + quant + LATTICE_DIM, cv_out + LATTICE_DIM, &idx_lead[1], &idx_scale[1], + p_sigma + LATTICE_DIM, p_inv_sigma + LATTICE_DIM, p_scales + MAX_NO_SCALES, + p_no_scales[1], p_no_lead + MAX_NO_SCALES ); - dist = L_add(dist,L_tmp); + dist = L_add( dist, L_tmp ); return dist; } @@ -135,31 +129,30 @@ static Word32 q_data_fx( *-----------------------------------------------------------------*/ -Word32 mslvq_cng_fx ( - Word16 idx_cv, /* i : index of cv from previous stage */ - Word16 *pTmp, /* i : 16 dimensional input vector x2.56*/ - Word16 *quant, /* o : quantized vector x2.56*/ - Word16 *cv_out, /* o : corresponding 8-dim lattice codevectors (without the scaling) Q13*/ - Word16 *idx_lead, /* o : leader index for each 8-dim subvector */ - Word16 *idx_scale, /* o : scale index for each subvector */ - const Word16 *w, /* i : weights for LSF quantization Q10*/ - Word16 * no_scales -) +Word32 mslvq_cng_fx( + Word16 idx_cv, /* i : index of cv from previous stage */ + Word16 *pTmp, /* i : 16 dimensional input vector x2.56*/ + Word16 *quant, /* o : quantized vector x2.56*/ + Word16 *cv_out, /* o : corresponding 8-dim lattice codevectors (without the scaling) Q13*/ + Word16 *idx_lead, /* o : leader index for each 8-dim subvector */ + Word16 *idx_scale, /* o : scale index for each subvector */ + const Word16 *w, /* i : weights for LSF quantization Q10*/ + Word16 *no_scales ) { Word32 dist; const Word16 *p_scales, *p_sigma, *p_inv_sigma; const Word16 *p_no_lead; - Word16 *p_no_scales; + Word16 *p_no_scales; Word16 mode_glb, mode, i; Word16 pTmp1[M], w1[M]; - dist = L_deposit_l(0); - mode = add(LVQ_COD_MODES, idx_cv); + dist = L_deposit_l( 0 ); + mode = add( LVQ_COD_MODES, idx_cv ); move16(); /* for CNG there is only one bitrate but several lattice quantizer structures, depending on the previous VQ stage */ - mode_glb = add(START_CNG, idx_cv); + mode_glb = add( START_CNG, idx_cv ); move16(); p_sigma = sigma_MSLVQ_fx[mode]; @@ -170,13 +163,13 @@ Word32 mslvq_cng_fx ( move16(); p_no_lead = no_lead_fx[mode_glb]; move16(); - p_no_scales = &no_scales[shl(mode_glb,1)]; + p_no_scales = &no_scales[shl( mode_glb, 1 )]; move16(); /* check if LSF component permutation is needed or not */ - IF ( cng_sort[idx_cv] ) + IF( cng_sort[idx_cv] ) { - FOR( i=0; i 0 ) + IF( no_scales > 0 ) { prepare_data_fx( cv_pot, sign, data, w, w_in, sigma, inv_sigma, &sig ); move16(); /* sorting of the input vector based on its absolute values; indx: permutation corresponding to the sorting */ sort_desc_ind_fx( cv_pot, LATTICE_DIM, indx ); - smallest = indx[LATTICE_DIM-1]; + smallest = indx[LATTICE_DIM - 1]; move16(); - min_dist = calculate_min_dist_fx( cv_pot, no_scales, scale, w, &best_scale, &best_idx ,no_leaders, sig, indx); + min_dist = calculate_min_dist_fx( cv_pot, no_scales, scale, w, &best_scale, &best_idx, no_leaders, sig, indx ); - IF ( GT_16(best_scale,-1) ) + IF( GT_16( best_scale, -1 ) ) { - FOR(j=0; j 0 ; k-- ) + FOR( k = sub( len, 1 ); k > 0; k-- ) { - IF (sorted) + IF( sorted ) { BREAK; } sorted = 1; move16(); - FOR ( i=0 ; i < k ; i++ ) + FOR( i = 0; i < k; i++ ) { - IF ( LT_16(s[i],s[i+1])) + IF( LT_16( s[i], s[i + 1] ) ) { sorted = 0; move16(); t = s[i]; move16(); - s[i] = s[i+1]; + s[i] = s[i + 1]; move16(); - s[i+1] = t; + s[i + 1] = t; move16(); a = ind[i]; move16(); - ind[i] = ind[i+1]; + ind[i] = ind[i + 1]; move16(); - ind[i+1] = a; + ind[i + 1] = a; move16(); } } @@ -616,52 +606,51 @@ static void sort_desc_ind_fx( * * sorts in descending order and computes indices in the sorted vector *-----------------------------------------------------------------*/ -void index_lvq_fx ( - Word16 *quant, /* i : codevector to be indexed (2 8-dim subvectors) Q13*/ - Word16 *idx_lead, /* i : leader class index for each subvector */ - Word16 *idx_scale, /* i :scale index for each subvector */ - Word16 mode, /* i : integer signalling the quantizer structure for the current bitrate */ - Word16 *index, /* o : encoded index (represented on 3 short each with 15 bits ) */ - Word32 * p_offset_scale1, /* i : scales for first subvector */ - Word32 * p_offset_scale2, /* i : scales for second subvector */ - Word16 * p_no_scales /* i : number of scales for each subvector */ +void index_lvq_fx( + Word16 *quant, /* i : codevector to be indexed (2 8-dim subvectors) Q13*/ + Word16 *idx_lead, /* i : leader class index for each subvector */ + Word16 *idx_scale, /* i :scale index for each subvector */ + Word16 mode, /* i : integer signalling the quantizer structure for the current bitrate */ + Word16 *index, /* o : encoded index (represented on 3 short each with 15 bits ) */ + Word32 *p_offset_scale1, /* i : scales for first subvector */ + Word32 *p_offset_scale2, /* i : scales for second subvector */ + Word16 *p_no_scales /* i : number of scales for each subvector */ ) { - Word32 index1, index2 - ; + Word32 index1, index2; Word16 len_offset; Word64 idx64; Word64 index2_64; - len_offset = add(MAX_NO_SCALES,1); + len_offset = add( MAX_NO_SCALES, 1 ); move16(); index1 = 0; move16(); /* for first subvector */ - IF ( GT_16(idx_scale[0],-1) ) + IF( GT_16( idx_scale[0], -1 ) ) { - index1 = L_add(encode_comb_fx(quant, idx_lead[0]), L_add(table_no_cv_fx[idx_lead[0]] , p_offset_scale1[i_mult2(mode,len_offset) +idx_scale[0]])); + index1 = L_add( encode_comb_fx( quant, idx_lead[0] ), L_add( table_no_cv_fx[idx_lead[0]], p_offset_scale1[i_mult2( mode, len_offset ) + idx_scale[0]] ) ); } /* for second subvector */ - index2 = L_deposit_l(0); + index2 = L_deposit_l( 0 ); - IF ( GT_16(idx_scale[1], -1) ) + IF( GT_16( idx_scale[1], -1 ) ) { - index2 = L_add(encode_comb_fx(&quant[LATTICE_DIM], idx_lead[1]), L_add(table_no_cv_fx[idx_lead[1]], p_offset_scale2[i_mult2(mode,len_offset)+idx_scale[1]])); + index2 = L_add( encode_comb_fx( &quant[LATTICE_DIM], idx_lead[1] ), L_add( table_no_cv_fx[idx_lead[1]], p_offset_scale2[i_mult2( mode, len_offset ) + idx_scale[1]] ) ); } - idx64 = W_mult0_32_32(index1, p_offset_scale2[mode*len_offset+p_no_scales[mode*2+1]]); - index2_64 = W_deposit32_l (index2); - idx64 = W_add_nosat(idx64, index2_64); + idx64 = W_mult0_32_32( index1, p_offset_scale2[mode * len_offset + p_no_scales[mode * 2 + 1]] ); + index2_64 = W_deposit32_l( index2 ); + idx64 = W_add_nosat( idx64, index2_64 ); /* convert to 3 short */ - index[0] = ((idx64)&(0x7fff)); + index[0] = ( ( idx64 ) & ( 0x7fff ) ); move16(); - index[1] = (idx64>>15)&(0x7fff); + index[1] = ( idx64 >> 15 ) & ( 0x7fff ); move16(); - index[2] = (idx64>>30)&(0x7fff); + index[2] = ( idx64 >> 30 ) & ( 0x7fff ); move16(); return; } @@ -673,9 +662,9 @@ void index_lvq_fx ( * creates an index for the lattice codevector *-----------------------------------------------------------------*/ -static Word32 encode_comb_fx( /* o : index of the absolute valued codevector*/ - Word16 *cv, /* i : codevector to be indexed Q13*/ - Word16 idx_lead /* i : leader class index, to know the values */ +static Word32 encode_comb_fx( /* o : index of the absolute valued codevector*/ + Word16 *cv, /* i : codevector to be indexed Q13*/ + Word16 idx_lead /* i : leader class index, to know the values */ ) { Word16 idx_sign, idx_ld_class; @@ -683,10 +672,10 @@ static Word32 encode_comb_fx( /* o : index of the absolute valued codeve idx_sign = encode_sign_pc1_fx( pl_par[idx_lead], cv ); move16(); - idx_ld_class = index_leaders_fx( cv, idx_lead, LATTICE_DIM ); + idx_ld_class = index_leaders_fx( cv, idx_lead, LATTICE_DIM ); move16(); - L_tmp = L_mac0(idx_ld_class, idx_sign,pi0[idx_lead]); + L_tmp = L_mac0( idx_ld_class, idx_sign, pi0[idx_lead] ); return L_tmp; } @@ -697,10 +686,10 @@ static Word32 encode_comb_fx( /* o : index of the absolute valued codeve * gives the index in a class of leaders without considering the sign yet *-----------------------------------------------------------------*/ -static Word16 index_leaders_fx( /* o : index */ - Word16 *cv, /* i : codevector to be indexed Q13*/ - Word16 idx_lead, /* i : leader class index */ - Word16 dim /* i : vector dimension */ +static Word16 index_leaders_fx( /* o : index */ + Word16 *cv, /* i : codevector to be indexed Q13*/ + Word16 idx_lead, /* i : leader class index */ + Word16 dim /* i : vector dimension */ ) { Word16 index; @@ -710,52 +699,52 @@ static Word16 index_leaders_fx( /* o : index */ no_vals_loc = no_vals[idx_lead]; move16(); - IF ( EQ_16(no_vals_loc, 1)) + IF( EQ_16( no_vals_loc, 1 ) ) { return 0; } - FOR( i=0; i 0 ) { - cnt = add(cnt, 1); + cnt = add( cnt, 1 ); } } @@ -838,10 +827,10 @@ static Word16 encode_sign_pc1_fx( /* o : index of signs *-----------------------------------------------------------------*/ static void take_out_val_fx( - Word16 *v, /* i : input vector x2.56*/ - Word16 *v_out, /* o : output vector without the value val */ - Word16 val, /* i : value to be removed x2.56*/ - Word16 len /* i : input vector length */ + Word16 *v, /* i : input vector x2.56*/ + Word16 *v_out, /* o : output vector without the value val */ + Word16 val, /* i : value to be removed x2.56*/ + Word16 len /* i : input vector length */ ) { Word16 i, cnt; @@ -849,9 +838,9 @@ static void take_out_val_fx( cnt = 0; move16(); - FOR( i=0; i -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ //#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ -#include "basop_util.h" +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ +#include "basop_util.h" -#define THR_CORR_FX (56<<15) /* 56 in Q15 starting threshold of multi-harm. correlation */ -#define THR_CORR_MAX_FX 30720 /* 60 in Q9 upper threshold of multi-harm. correlation */ -#define THR_CORR_MIN_FX 25088 /* 49 in Q9 lower threshold of multi-harm. correlation */ -#define THR_CORR_STEP_FX 102 /* 0.2 in Q9 step for the threshold of multi-harm. correlation */ +#define THR_CORR_FX ( 56 << 15 ) /* 56 in Q15 starting threshold of multi-harm. correlation */ +#define THR_CORR_MAX_FX 30720 /* 60 in Q9 upper threshold of multi-harm. correlation */ +#define THR_CORR_MIN_FX 25088 /* 49 in Q9 lower threshold of multi-harm. correlation */ +#define THR_CORR_STEP_FX 102 /* 0.2 in Q9 step for the threshold of multi-harm. correlation */ /*---------------------------------------------------------------------* * multi_harm() @@ -21,24 +21,24 @@ * Perform multi-harmonic analysis, information used for UV and VAD decision *---------------------------------------------------------------------*/ -Word16 multi_harm_fx( /* o : frame multi-harmonicity (1-harmonic, 0-not) */ - const Word16 Bin_E[], /* i : log-energy spectrum of the current frame Q7 */ - Word16 old_S[], /* i/o: prev. log-energy spectrum w. subtracted floor Q7 */ - Word16 cor_map_LT[], /* i/o: LT correlation map Q15 */ - Word16 *multi_harm_limit, /* i/o: multi harminic threshold Q9 */ - const Word32 total_brate, /* i : total bitrate Q0 */ - const Word16 bwidth, /* i : input signal bandwidth Q0 */ - Word16 *cor_strong_limit, /* i/o: HF correlation indicator Q0 */ - Word16 *st_mean_avr_dyn, /* i/o: long term average dynamic Q7 */ - Word16 *st_last_sw_dyn, /* i/o: last dynamic Q7 */ - Word16 *cor_map_sum, /* i : sum of correlation map Q8 */ - Word16 *sp_floor, /* o: noise floor estimate Q7 */ - Word16 S_map[] /* o : short-term correlation map Q7 */ +Word16 multi_harm_fx( /* o : frame multi-harmonicity (1-harmonic, 0-not) */ + const Word16 Bin_E[], /* i : log-energy spectrum of the current frame Q7 */ + Word16 old_S[], /* i/o: prev. log-energy spectrum w. subtracted floor Q7 */ + Word16 cor_map_LT[], /* i/o: LT correlation map Q15 */ + Word16 *multi_harm_limit, /* i/o: multi harminic threshold Q9 */ + const Word32 total_brate, /* i : total bitrate Q0 */ + const Word16 bwidth, /* i : input signal bandwidth Q0 */ + Word16 *cor_strong_limit, /* i/o: HF correlation indicator Q0 */ + Word16 *st_mean_avr_dyn, /* i/o: long term average dynamic Q7 */ + Word16 *st_last_sw_dyn, /* i/o: last dynamic Q7 */ + Word16 *cor_map_sum, /* i : sum of correlation map Q8 */ + Word16 *sp_floor, /* o: noise floor estimate Q7 */ + Word16 S_map[] /* o : short-term correlation map Q7 */ ) { - Word16 i, j, k, L, stemp, N_mins, ind_mins[L_FFT/4], *pt_mins, harm; - Word16 S[L_FFT/2], flor, step, sign_fx, tmp16, tmp2, ExpInd, tmpdB, ExpdB, Expx2, Expy2; - Word16 corx2, cory2, corxy, cor, cor_map[L_FFT/2], *pt1, *pt2, cor_strong; + Word16 i, j, k, L, stemp, N_mins, ind_mins[L_FFT / 4], *pt_mins, harm; + Word16 S[L_FFT / 2], flor, step, sign_fx, tmp16, tmp2, ExpInd, tmpdB, ExpdB, Expx2, Expy2; + Word16 corx2, cory2, corxy, cor, cor_map[L_FFT / 2], *pt1, *pt2, cor_strong; Word32 L_acc; Word32 Lcorx2, Lcory2, Lcorxy, Lcor_map_LT_sum; Word16 mean_dyn; @@ -51,16 +51,16 @@ Word16 multi_harm_fx( /* o : frame multi-harmonicity (1-harmonic, 0-not) *------------------------------------------------------------------*/ /* length of the useful part of the spectrum (up to 6.4kHz) */ - L = L_FFT/2; + L = L_FFT / 2; move16(); - if ( EQ_16(bwidth,NB)) + if ( EQ_16( bwidth, NB ) ) { /* length of the useful part of the spectrum (up to 3.6kHz) */ L = 76; move16(); } - Copy(Bin_E, S, L); + Copy( Bin_E, S, L ); /*------------------------------------------------------------------* * searching of spectral maxima and minima @@ -70,17 +70,17 @@ Word16 multi_harm_fx( /* o : frame multi-harmonicity (1-harmonic, 0-not) move16(); /* index of the first minimum */ - if (LT_16(Bin_E[0],Bin_E[1])) + if ( LT_16( Bin_E[0], Bin_E[1] ) ) { *pt_mins++ = 0; move16(); } - FOR (i=1; i 0) + IF( N_mins > 0 ) { - L_acc = L_deposit_l(0); - FOR (i=0; i 0) + set16_fx( cor_map, 0, L ); + IF( N_mins > 0 ) { - Lcorx2 = L_deposit_l(0); - Lcorxy = L_deposit_l(0); + Lcorx2 = L_deposit_l( 0 ); + Lcorxy = L_deposit_l( 0 ); stemp = ind_mins[0]; move16(); - Lcory2 = L_mult(old_S[stemp],old_S[stemp]); + Lcory2 = L_mult( old_S[stemp], old_S[stemp] ); k = 1; move16(); - FOR (i = add(stemp,1); i <= ind_mins[N_mins]; i++) + FOR( i = add( stemp, 1 ); i <= ind_mins[N_mins]; i++ ) { - IF (EQ_16(i,ind_mins[k])) + IF( EQ_16( i, ind_mins[k] ) ) { /* include the last peak point (new minimum) to the corr. sum */ #ifdef BASOP_NOGLOB - Lcory2 = L_mac_o(Lcory2, old_S[i], old_S[i], &Overflow); -#else /* BASOP_NOGLOB */ - Lcory2 = L_mac(Lcory2, old_S[i], old_S[i]); + Lcory2 = L_mac_o( Lcory2, old_S[i], old_S[i], &Overflow ); +#else /* BASOP_NOGLOB */ + Lcory2 = L_mac( Lcory2, old_S[i], old_S[i] ); #endif /* BASOP_NOGLOB */ /* calculation of the norm. peak correlation */ test(); - IF (Lcorx2 != 0 && Lcory2 != 0) + IF( Lcorx2 != 0 && Lcory2 != 0 ) { /* corxy * corxy*/ - tmp16 = sub(norm_l(Lcorxy),1); - corxy = extract_h(L_shl(Lcorxy, tmp16)); - corxy = mult_r(corxy, corxy); + tmp16 = sub( norm_l( Lcorxy ), 1 ); + corxy = extract_h( L_shl( Lcorxy, tmp16 ) ); + corxy = mult_r( corxy, corxy ); /* (corx2 * cory2) */ - Expx2 = norm_l(Lcorx2); - Expy2 = norm_l(Lcory2); - corx2 = extract_h(L_shl(Lcorx2, Expx2)); - cory2 = extract_h(L_shl(Lcory2, Expy2)); - corx2 = mult_r(corx2, cory2); - Expx2 = add(Expy2, Expx2); + Expx2 = norm_l( Lcorx2 ); + Expy2 = norm_l( Lcory2 ); + corx2 = extract_h( L_shl( Lcorx2, Expx2 ) ); + cory2 = extract_h( L_shl( Lcory2, Expy2 ) ); + corx2 = mult_r( corx2, cory2 ); + Expx2 = add( Expy2, Expx2 ); /* Validate num < den */ - cor = sub(corx2, corxy); - cor = shr(cor, 15); + cor = sub( corx2, corxy ); + cor = shr( cor, 15 ); /* Add 1 to tmp16 & shr by 2 if corxy > corx2 */ - tmp16 = sub(tmp16, cor); - corxy = shl(corxy, cor); - corxy = shl(corxy, cor); + tmp16 = sub( tmp16, cor ); + corxy = shl( corxy, cor ); + corxy = shl( corxy, cor ); /* cor = corxy * corxy / (corx2 * cory2) */ - corxy = div_s(corxy, corx2); + corxy = div_s( corxy, corx2 ); #ifdef BASOP_NOGLOB - cor = shr_o(corxy, sub(shl(tmp16, 1), Expx2), &Overflow); /* Q15 */ -#else /* BASOP_NOGLOB */ - cor = shr(corxy, sub(shl(tmp16, 1), Expx2)); /* Q15 */ -#endif /* BASOP_NOGLOB */ + cor = shr_o( corxy, sub( shl( tmp16, 1 ), Expx2 ), &Overflow ); /* Q15 */ +#else /* BASOP_NOGLOB */ + cor = shr( corxy, sub( shl( tmp16, 1 ), Expx2 ) ); /* Q15 */ +#endif /* BASOP_NOGLOB */ } ELSE { @@ -256,42 +256,42 @@ Word16 multi_harm_fx( /* o : frame multi-harmonicity (1-harmonic, 0-not) } /* save the norm. peak correlation in the correlation map */ - FOR (j=ind_mins[k-1]; j 0) || (cor_strong != 0) ) + if ( ( L_msu0( Lcor_map_LT_sum, *multi_harm_limit, 64 ) > 0 ) || ( cor_strong != 0 ) ) { harm = 1; move16(); @@ -355,24 +355,24 @@ Word16 multi_harm_fx( /* o : frame multi-harmonicity (1-harmonic, 0-not) * updating of the decision threshold *------------------------------------------------------------------*/ - stemp = add(*multi_harm_limit, THR_CORR_STEP_FX); - if (GT_32(Lcor_map_LT_sum, THR_CORR_FX)) /* Q15 */ + stemp = add( *multi_harm_limit, THR_CORR_STEP_FX ); + if ( GT_32( Lcor_map_LT_sum, THR_CORR_FX ) ) /* Q15 */ { /* *multi_harm_limit -= THR_CORR_STEP_FX */ - stemp = sub(*multi_harm_limit, THR_CORR_STEP_FX); + stemp = sub( *multi_harm_limit, THR_CORR_STEP_FX ); } - stemp = s_min(stemp, THR_CORR_MAX_FX); - *multi_harm_limit = s_max(stemp, THR_CORR_MIN_FX); + stemp = s_min( stemp, THR_CORR_MAX_FX ); + *multi_harm_limit = s_max( stemp, THR_CORR_MIN_FX ); move16(); - IF (N_mins <= 0) + IF( N_mins <= 0 ) { - set16_fx(old_S, 0, L); + set16_fx( old_S, 0, L ); } - IF (S_map != NULL) + IF( S_map != NULL ) { - Copy(S, S_map, L); + Copy( S, S_map, L ); } return harm; } diff --git a/lib_enc/nelp_enc_fx.c b/lib_enc/nelp_enc_fx.c index 0c2b0caa1..a0b228c1e 100644 --- a/lib_enc/nelp_enc_fx.c +++ b/lib_enc/nelp_enc_fx.c @@ -32,11 +32,11 @@ #include #include "control.h" -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ #include "prot_fx1.h" -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ #include "rom_com.h" /*===================================================================*/ @@ -61,172 +61,169 @@ input unquantized gain vector */ /* _ None. */ /*===================================================================*/ -void quantize_uvg_fx(Word16 *G, Word16 *iG1, Word16 *iG2, Word16 *quantG, Word16 bwidth_fx) +void quantize_uvg_fx( Word16 *G, Word16 *iG1, Word16 *iG2, Word16 *quantG, Word16 bwidth_fx ) { - Word16 G1[2], G2[10], L16, L16_1; - Word16 i, j, k, ind, temp; - Word32 mmse; - Word16 exp, tmp, frac; - Word32 Lacc, Lexp[2], L_tmp; - const Word16(*UVG1CB_fx)[2] = NULL; - const Word16(*UVG2CB1_fx)[5] = NULL; - const Word16(*UVG2CB2_fx)[5] = NULL; - test(); - IF(EQ_16(bwidth_fx, NB)) - { - UVG1CB_fx = UVG1CB_NB_FX; - move16();/*Q13 */ - UVG2CB1_fx = UVG2CB1_NB_FX; - move16();/*Q12 */ - UVG2CB2_fx = UVG2CB2_NB_FX; - move16();/*Q12 */ - } - ELSE IF(EQ_16(bwidth_fx, WB) || EQ_16(bwidth_fx, SWB)) - { - UVG1CB_fx = UVG1CB_WB_FX; - move16();/*Q13 */ - UVG2CB1_fx = UVG2CB1_WB_FX; - move16();/*Q12 */ - UVG2CB2_fx = UVG2CB2_WB_FX; - move16();/*Q12 */ - } - - - FOR(i = 0; i < 2; i++) - { - Lacc = L_deposit_l(0); - FOR(j = 0; j < 5; j++) - { - ind = add(shr(extract_l(L_mult(i, 5)), 1), j); - Lacc = L_mac0(Lacc, G[ind], G[ind]); /*Q0 */ - } - - IF(Lacc == 0) - { - Lacc = L_deposit_l(1); /* to avoid log10(0) */ - } - - /*G1[i] = (float) log10(sqrt(G1[i]/5)); */ - L_tmp = Mult_32_16(Lacc, 13108); - IF(L_tmp) - { - exp = norm_l(L_tmp); - frac = Log2_norm_lc(L_shl(L_tmp, exp)); - exp = (30 - exp - 1); - move16();/*(+1)=/2 in log */ - L_tmp = Mpy_32_16(exp, frac, 4932); /*Q16 ; 0.5*log10(2) in Q15 */ - G1[i] = round_fx(L_shl(L_tmp, 13)); /*Q13 */ - } - ELSE - { - G1[i] = 0; - move16(); - } - - } - - - mmse = L_add(MAX_32, 0); - *iG1 = 0; - move16(); - FOR(i = 0; i < UVG1_CBSIZE; i++) - { + Word16 G1[2], G2[10], L16, L16_1; + Word16 i, j, k, ind, temp; + Word32 mmse; + Word16 exp, tmp, frac; + Word32 Lacc, Lexp[2], L_tmp; + const Word16( *UVG1CB_fx )[2] = NULL; + const Word16( *UVG2CB1_fx )[5] = NULL; + const Word16( *UVG2CB2_fx )[5] = NULL; + test(); + IF( EQ_16( bwidth_fx, NB ) ) + { + UVG1CB_fx = UVG1CB_NB_FX; + move16(); /*Q13 */ + UVG2CB1_fx = UVG2CB1_NB_FX; + move16(); /*Q12 */ + UVG2CB2_fx = UVG2CB2_NB_FX; + move16(); /*Q12 */ + } + ELSE IF( EQ_16( bwidth_fx, WB ) || EQ_16( bwidth_fx, SWB ) ) + { + UVG1CB_fx = UVG1CB_WB_FX; + move16(); /*Q13 */ + UVG2CB1_fx = UVG2CB1_WB_FX; + move16(); /*Q12 */ + UVG2CB2_fx = UVG2CB2_WB_FX; + move16(); /*Q12 */ + } + + + FOR( i = 0; i < 2; i++ ) + { + Lacc = L_deposit_l( 0 ); + FOR( j = 0; j < 5; j++ ) + { + ind = add( shr( extract_l( L_mult( i, 5 ) ), 1 ), j ); + Lacc = L_mac0( Lacc, G[ind], G[ind] ); /*Q0 */ + } + + IF( Lacc == 0 ) + { + Lacc = L_deposit_l( 1 ); /* to avoid log10(0) */ + } + + /*G1[i] = (float) log10(sqrt(G1[i]/5)); */ + L_tmp = Mult_32_16( Lacc, 13108 ); + IF( L_tmp ) + { + exp = norm_l( L_tmp ); + frac = Log2_norm_lc( L_shl( L_tmp, exp ) ); + exp = ( 30 - exp - 1 ); + move16(); /*(+1)=/2 in log */ + L_tmp = Mpy_32_16( exp, frac, 4932 ); /*Q16 ; 0.5*log10(2) in Q15 */ + G1[i] = round_fx( L_shl( L_tmp, 13 ) ); /*Q13 */ + } + ELSE + { + G1[i] = 0; + move16(); + } + } + + + mmse = L_add( MAX_32, 0 ); + *iG1 = 0; + move16(); + FOR( i = 0; i < UVG1_CBSIZE; i++ ) + { #ifdef BASOP_NOGLOB - L16 = shr( sub_sat( G1[0], UVG1CB_fx[i][0] ), 1 ); /* Q12 */ + L16 = shr( sub_sat( G1[0], UVG1CB_fx[i][0] ), 1 ); /* Q12 */ L16_1 = shr( sub_sat( G1[1], UVG1CB_fx[i][1] ), 1 ); /* Q12 */ #else - L16 = shr(sub(G1[0], UVG1CB_fx[i][0]), 1); /* Q12 */ - L16_1 = shr(sub(G1[1], UVG1CB_fx[i][1]), 1); /* Q12 */ + L16 = shr( sub( G1[0], UVG1CB_fx[i][0] ), 1 ); /* Q12 */ + L16_1 = shr( sub( G1[1], UVG1CB_fx[i][1] ), 1 ); /* Q12 */ #endif - Lacc = 0; - Lacc = L_mac0(Lacc, L16, L16); /*Q24 */ - Lacc = L_mac0(Lacc, L16_1, L16_1);/*Q24 */ - - IF(LT_32(Lacc, mmse)) - { - *iG1 = i; - move16(); - mmse = Lacc; - } - - } - - L_tmp = L_mult0(UVG1CB_fx[*iG1][0], 27213);/*Q26 */ - L_tmp = L_shr(L_tmp, 10); /* From Q26 to Q16 */ - frac = L_Extract_lc(L_tmp, &exp); /* Extract exponent of L_tmp */ - L_tmp = Pow2(30, frac); - exp = exp - 30; /*move16(); */ - Lexp[0] = L_shl(L_tmp, exp + 15); - - - L_tmp = L_mult0(UVG1CB_fx[*iG1][1], 27213);/*Q26 */ - L_tmp = L_shr(L_tmp, 10); /* From Q26 to Q16 */ - frac = L_Extract_lc(L_tmp, &exp); /* Extract exponent of L_tmp */ - L_tmp = Pow2(30, frac); - exp = exp - 30; /*move16(); */ - Lexp[1] = L_shl(L_tmp, exp + 15); - - - FOR(i = 0; i < 2; i++) - { - FOR(j = 0; j < 5; j++) - { - exp = norm_l(Lexp[i]); - tmp = extract_h(L_shl(Lexp[i], exp)); - exp = sub(sub(30, exp), 15); - tmp = div_s(16384, tmp); /*Q(15+exp) */ - L_tmp = L_shr(L_mult0(G[i * 5 + j], tmp), exp + 3); /*Q12 */ - G2[i * 5 + j] = extract_l(L_tmp); /*Q12 */ - } - } - - - FOR(i = 0; i < 2; i++) - { - mmse = MAX_32; - iG2[i] = 0; - FOR(j = 0; j < UVG2_CBSIZE; j++) - { - Lacc = L_deposit_l(0); - FOR(k = 0; k < 5; k++) - { - IF(i == 0) - { - /*mse += SQR(G2[i*5+k]-UVG2CB1[j][k]); */ - ind = add(shr(extract_l(L_mult(i, 5)), 1), k); + Lacc = 0; + Lacc = L_mac0( Lacc, L16, L16 ); /*Q24 */ + Lacc = L_mac0( Lacc, L16_1, L16_1 ); /*Q24 */ + + IF( LT_32( Lacc, mmse ) ) + { + *iG1 = i; + move16(); + mmse = Lacc; + } + } + + L_tmp = L_mult0( UVG1CB_fx[*iG1][0], 27213 ); /*Q26 */ + L_tmp = L_shr( L_tmp, 10 ); /* From Q26 to Q16 */ + frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent of L_tmp */ + L_tmp = Pow2( 30, frac ); + exp = exp - 30; /*move16(); */ + Lexp[0] = L_shl( L_tmp, exp + 15 ); + + + L_tmp = L_mult0( UVG1CB_fx[*iG1][1], 27213 ); /*Q26 */ + L_tmp = L_shr( L_tmp, 10 ); /* From Q26 to Q16 */ + frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent of L_tmp */ + L_tmp = Pow2( 30, frac ); + exp = exp - 30; /*move16(); */ + Lexp[1] = L_shl( L_tmp, exp + 15 ); + + + FOR( i = 0; i < 2; i++ ) + { + FOR( j = 0; j < 5; j++ ) + { + exp = norm_l( Lexp[i] ); + tmp = extract_h( L_shl( Lexp[i], exp ) ); + exp = sub( sub( 30, exp ), 15 ); + tmp = div_s( 16384, tmp ); /*Q(15+exp) */ + L_tmp = L_shr( L_mult0( G[i * 5 + j], tmp ), exp + 3 ); /*Q12 */ + G2[i * 5 + j] = extract_l( L_tmp ); /*Q12 */ + } + } + + + FOR( i = 0; i < 2; i++ ) + { + mmse = MAX_32; + iG2[i] = 0; + FOR( j = 0; j < UVG2_CBSIZE; j++ ) + { + Lacc = L_deposit_l( 0 ); + FOR( k = 0; k < 5; k++ ) + { + IF( i == 0 ) + { + /*mse += SQR(G2[i*5+k]-UVG2CB1[j][k]); */ + ind = add( shr( extract_l( L_mult( i, 5 ) ), 1 ), k ); #ifdef BASOP_NOGLOB temp = sub_sat( G2[ind], UVG2CB1_fx[j][k] ); - Lacc = L_mac0_sat(Lacc, temp, temp); /*Q24 */ + Lacc = L_mac0_sat( Lacc, temp, temp ); /*Q24 */ #else - temp = sub(G2[ind], UVG2CB1_fx[j][k]); - Lacc = L_mac0(Lacc, temp, temp); /*Q24 */ + temp = sub( G2[ind], UVG2CB1_fx[j][k] ); + Lacc = L_mac0( Lacc, temp, temp ); /*Q24 */ #endif - } - ELSE IF(i == 1) - { - /*mse += SQR(G2[i*5+k]-UVG2CB2[j][k]); */ - ind = add(shr(extract_l(L_mult(i, 5)), 1), k); + } + ELSE IF( i == 1 ) + { + /*mse += SQR(G2[i*5+k]-UVG2CB2[j][k]); */ + ind = add( shr( extract_l( L_mult( i, 5 ) ), 1 ), k ); #ifdef BASOP_NOGLOB temp = sub_sat( G2[ind], UVG2CB2_fx[j][k] ); - Lacc = L_mac0_sat(Lacc, temp, temp); /*Q24 */ + Lacc = L_mac0_sat( Lacc, temp, temp ); /*Q24 */ #else - temp = sub(G2[ind], UVG2CB2_fx[j][k]); - Lacc = L_mac0(Lacc, temp, temp); /*Q24 */ + temp = sub( G2[ind], UVG2CB2_fx[j][k] ); + Lacc = L_mac0( Lacc, temp, temp ); /*Q24 */ #endif - } - } - - IF(LT_32(Lacc, mmse)) - { - mmse = Lacc; - iG2[i] = j; - move16(); - } - } - } - - dequantize_uvg_fx(*iG1, iG2, quantG, bwidth_fx, 0); - + } + } + + IF( LT_32( Lacc, mmse ) ) + { + mmse = Lacc; + iG2[i] = j; + move16(); + } + } + } + + dequantize_uvg_fx( *iG1, iG2, quantG, bwidth_fx, 0 ); } /*===================================================================*/ @@ -249,33 +246,33 @@ void quantize_uvg_fx(Word16 *G, Word16 *iG1, Word16 *iG2, Word16 *quantG, Word16 /* RETURN ARGUMENTS : */ /* _ None */ /*===================================================================*/ -static void normalize_arr(Word16 *arr, Word16 *qf, Word16 size, Word16 hdr) +static void normalize_arr( Word16 *arr, Word16 *qf, Word16 size, Word16 hdr ) { - Word16 i; - Word16 max_s = 0; - - FOR(i = 0; i < size; i++) - { - max_s = s_max(max_s, abs_s(arr[i])); - } - - *qf = norm_s((Word16)max_s); - test(); - IF((*qf == 0) && (((Word16)max_s) == 0)) - { - *qf = 15; - move16(); - } - - *qf = *qf - hdr; - - FOR(i = 0; i < size; i++) - { - arr[i] = shl(arr[i], *qf); - move16(); /* saturation can occur here */ - } - - return; + Word16 i; + Word16 max_s = 0; + + FOR( i = 0; i < size; i++ ) + { + max_s = s_max( max_s, abs_s( arr[i] ) ); + } + + *qf = norm_s( (Word16) max_s ); + test(); + IF( ( *qf == 0 ) && ( ( (Word16) max_s ) == 0 ) ) + { + *qf = 15; + move16(); + } + + *qf = *qf - hdr; + + FOR( i = 0; i < size; i++ ) + { + arr[i] = shl( arr[i], *qf ); + move16(); /* saturation can occur here */ + } + + return; } @@ -310,795 +307,792 @@ static void normalize_arr(Word16 *arr, Word16 *qf, Word16 size, Word16 hdr) /*===================================================================*/ void nelp_encoder_fx( - Encoder_State *st_fx,/* i/o: encoder state */ - Word16 *in_fx, /* i : residual signal */ - Word16 *exc_fx, /* o : NELP quantized excitation signal */ - Word16 *qIn1, - Word16 reduce_gains -) + Encoder_State *st_fx, /* i/o: encoder state */ + Word16 *in_fx, /* i : residual signal */ + Word16 *exc_fx, /* o : NELP quantized excitation signal */ + Word16 *qIn1, + Word16 reduce_gains ) { - Word16 i, j; - Word16 *ptr_fx = exc_fx; - Word16 lag = 25; /* to cover 25*9 + 31 */ - Word16 sqrt_inv_lag = 6554; /* sqrt(1/lag) in Q15 */ - Word16 sqrt_inv_lframe_lag = 5885; /* sqrt(1/(L_FRAME-lag*9)) */ - Word16 Gains_fx[10], gain_fac_fx; - Word16 iG1_fx, iG2_fx[2]; - Word16 fid; - Word16 fdbck_fx; - Word32 var_dB_fx; - Word32 E1_fx = 0, EL1_fx = 0, EH1_fx = 0, E2_fx = 0, E3_fx = 0, EL2_fx = 0, EH2_fx = 0; - Word32 RL_fx = 0, RH_fx = 0; - Word16 R_fx = 0; - Word16 filtRes_fx[L_FRAME]; - Word16 ptr_tmp_fx[L_FRAME]; - - Word16 qE1 = 0, qE2 = 0, qE3 = 0, qEL1 = 0, qEL2 = 0, qEH1 = 0, qEH2 = 0; - Word16 qIn = 0, qGain = 0, qf = 0, qf1 = 0, qNelpGain = 0; - Word16 exp1, exp2, tmp1, tmp2; - Word16 f_Noise, etmp, e_Noise; - Word16 max1 = 0; - Word32 l_nelp_gain_mem; - Word32 Ltemp = 0, Ltemp1 = 0, L_tmp = 0, L_const_1; - Word16 BP1_ORDER; - Word16 rf_flag; + Word16 i, j; + Word16 *ptr_fx = exc_fx; + Word16 lag = 25; /* to cover 25*9 + 31 */ + Word16 sqrt_inv_lag = 6554; /* sqrt(1/lag) in Q15 */ + Word16 sqrt_inv_lframe_lag = 5885; /* sqrt(1/(L_FRAME-lag*9)) */ + Word16 Gains_fx[10], gain_fac_fx; + Word16 iG1_fx, iG2_fx[2]; + Word16 fid; + Word16 fdbck_fx; + Word32 var_dB_fx; + Word32 E1_fx = 0, EL1_fx = 0, EH1_fx = 0, E2_fx = 0, E3_fx = 0, EL2_fx = 0, EH2_fx = 0; + Word32 RL_fx = 0, RH_fx = 0; + Word16 R_fx = 0; + Word16 filtRes_fx[L_FRAME]; + Word16 ptr_tmp_fx[L_FRAME]; + + Word16 qE1 = 0, qE2 = 0, qE3 = 0, qEL1 = 0, qEL2 = 0, qEH1 = 0, qEH2 = 0; + Word16 qIn = 0, qGain = 0, qf = 0, qf1 = 0, qNelpGain = 0; + Word16 exp1, exp2, tmp1, tmp2; + Word16 f_Noise, etmp, e_Noise; + Word16 max1 = 0; + Word32 l_nelp_gain_mem; + Word32 Ltemp = 0, Ltemp1 = 0, L_tmp = 0, L_const_1; + Word16 BP1_ORDER; + Word16 rf_flag; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; + Flag Overflow = 0; #endif - SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; - BSTR_ENC_HANDLE hBstr = st_fx->hBstr; - RF_ENC_HANDLE hRF = st_fx->hRF; - - rf_flag = st_fx->rf_mode; - - if (EQ_16(hSC_VBR->last_nelp_mode, 1) && NE_16(st_fx->bwidth, st_fx->last_bwidth)) - { - hSC_VBR->last_nelp_mode = 0; - } - - qIn = *qIn1; - move16(); - test(); - IF(EQ_16(st_fx->bwidth, NB)) - { - IF(hSC_VBR->last_nelp_mode != 1) - { - BP1_ORDER = 7; - move16(); - set32_fx(hSC_VBR->bp1_filt_mem_nb_fx, 0, BP1_ORDER * 2); - hSC_VBR->qprevGain_fx = 0; - move16(); - } - } - ELSE IF(EQ_16(st_fx->bwidth, WB) || EQ_16(st_fx->bwidth, SWB)) - { - IF(hSC_VBR->last_nelp_mode != 1) - { - BP1_ORDER = 4; - move16(); - set16_fx(hSC_VBR->bp1_filt_mem_wb_fx, 0, BP1_ORDER * 2); - } - } - - IF(hSC_VBR->last_nelp_mode != 1) - { - test(); - IF(st_fx->bwidth == WB || EQ_16(st_fx->bwidth, SWB)) - { - set16_fx(hSC_VBR->shape1_filt_mem_fx, 0, 10); - set16_fx(hSC_VBR->shape2_filt_mem_fx, 0, 10); - set16_fx(hSC_VBR->shape3_filt_mem_fx, 0, 10); - set16_fx(hSC_VBR->txlpf1_filt1_mem_fx, 0, 10); - set16_fx(hSC_VBR->txlpf1_filt2_mem_fx, 0, 10); - set16_fx(hSC_VBR->txhpf1_filt1_mem_fx, 0, 10); - set16_fx(hSC_VBR->txhpf1_filt2_mem_fx, 0, 10); - hSC_VBR->qprevIn_fx = 0; - move16(); - hSC_VBR->qprevGain_fx = 0; - move16(); - } - } - - /* Start Unvoiced/NELP Processing */ - test(); - IF(EQ_16(st_fx->bwidth, WB) || EQ_16(st_fx->bwidth, SWB)) - { - qE1 = qIn; - move16(); - E1_fx = L_deposit_l(0); - FOR(i = 0; i < L_FRAME; i++) - { + SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; + BSTR_ENC_HANDLE hBstr = st_fx->hBstr; + RF_ENC_HANDLE hRF = st_fx->hRF; + + rf_flag = st_fx->rf_mode; + + if ( EQ_16( hSC_VBR->last_nelp_mode, 1 ) && NE_16( st_fx->bwidth, st_fx->last_bwidth ) ) + { + hSC_VBR->last_nelp_mode = 0; + } + + qIn = *qIn1; + move16(); + test(); + IF( EQ_16( st_fx->bwidth, NB ) ) + { + IF( hSC_VBR->last_nelp_mode != 1 ) + { + BP1_ORDER = 7; + move16(); + set32_fx( hSC_VBR->bp1_filt_mem_nb_fx, 0, BP1_ORDER * 2 ); + hSC_VBR->qprevGain_fx = 0; + move16(); + } + } + ELSE IF( EQ_16( st_fx->bwidth, WB ) || EQ_16( st_fx->bwidth, SWB ) ) + { + IF( hSC_VBR->last_nelp_mode != 1 ) + { + BP1_ORDER = 4; + move16(); + set16_fx( hSC_VBR->bp1_filt_mem_wb_fx, 0, BP1_ORDER * 2 ); + } + } + + IF( hSC_VBR->last_nelp_mode != 1 ) + { + test(); + IF( st_fx->bwidth == WB || EQ_16( st_fx->bwidth, SWB ) ) + { + set16_fx( hSC_VBR->shape1_filt_mem_fx, 0, 10 ); + set16_fx( hSC_VBR->shape2_filt_mem_fx, 0, 10 ); + set16_fx( hSC_VBR->shape3_filt_mem_fx, 0, 10 ); + set16_fx( hSC_VBR->txlpf1_filt1_mem_fx, 0, 10 ); + set16_fx( hSC_VBR->txlpf1_filt2_mem_fx, 0, 10 ); + set16_fx( hSC_VBR->txhpf1_filt1_mem_fx, 0, 10 ); + set16_fx( hSC_VBR->txhpf1_filt2_mem_fx, 0, 10 ); + hSC_VBR->qprevIn_fx = 0; + move16(); + hSC_VBR->qprevGain_fx = 0; + move16(); + } + } + + /* Start Unvoiced/NELP Processing */ + test(); + IF( EQ_16( st_fx->bwidth, WB ) || EQ_16( st_fx->bwidth, SWB ) ) + { + qE1 = qIn; + move16(); + E1_fx = L_deposit_l( 0 ); + FOR( i = 0; i < L_FRAME; i++ ) + { #ifdef BASOP_NOGLOB - E1_fx = L_mac0_o(E1_fx, in_fx[i], in_fx[i], &Overflow); /*Q(qE1+qE1) */ + E1_fx = L_mac0_o( E1_fx, in_fx[i], in_fx[i], &Overflow ); /*Q(qE1+qE1) */ #else - E1_fx = L_mac0(E1_fx, in_fx[i], in_fx[i]); /*Q(qE1+qE1) */ + E1_fx = L_mac0( E1_fx, in_fx[i], in_fx[i] ); /*Q(qE1+qE1) */ #endif - } + } - qE1 = shl(qE1, 1);; + qE1 = shl( qE1, 1 ); + ; - qf = qIn; - move16(); - Scale_sig(hSC_VBR->txlpf1_filt1_mem_fx, 10, (qf - hSC_VBR->qprevIn_fx)); - pz_filter_sp_fx(txlpf1_num_coef_fx, txlpf1_den_coef_fx, in_fx, filtRes_fx, hSC_VBR->txlpf1_filt1_mem_fx, 10, 10, L_FRAME, 3);/*1 = (16-qformat of shape1 cofficient) */ + qf = qIn; + move16(); + Scale_sig( hSC_VBR->txlpf1_filt1_mem_fx, 10, ( qf - hSC_VBR->qprevIn_fx ) ); + pz_filter_sp_fx( txlpf1_num_coef_fx, txlpf1_den_coef_fx, in_fx, filtRes_fx, hSC_VBR->txlpf1_filt1_mem_fx, 10, 10, L_FRAME, 3 ); /*1 = (16-qformat of shape1 cofficient) */ - qEL1 = qf; - move16(); - EL1_fx = L_deposit_l(0); - FOR(i = 0; i < L_FRAME; i++) - { + qEL1 = qf; + move16(); + EL1_fx = L_deposit_l( 0 ); + FOR( i = 0; i < L_FRAME; i++ ) + { #ifdef BASOP_NOGLOB - EL1_fx = L_mac0_o(EL1_fx, filtRes_fx[i], filtRes_fx[i], &Overflow); /*Q(2*qIn) */ + EL1_fx = L_mac0_o( EL1_fx, filtRes_fx[i], filtRes_fx[i], &Overflow ); /*Q(2*qIn) */ #else - EL1_fx = L_mac0(EL1_fx, filtRes_fx[i], filtRes_fx[i]); /*Q(2*qIn) */ + EL1_fx = L_mac0( EL1_fx, filtRes_fx[i], filtRes_fx[i] ); /*Q(2*qIn) */ #endif - } - qEL1 = shl(qEL1, 1); - - qf = qIn; - move16(); - Scale_sig(hSC_VBR->txhpf1_filt1_mem_fx, 10, qf - hSC_VBR->qprevIn_fx); - pz_filter_sp_fx(txhpf1_num_coef_fx, txhpf1_den_coef_fx, in_fx, filtRes_fx, hSC_VBR->txhpf1_filt1_mem_fx, 10, 10, L_FRAME, 3);/*1 = (16-qformat of shape1 cofficient) */ - hSC_VBR->qprevIn_fx = qf; - move16(); - - qEH1 = qf; - move16(); - EH1_fx = L_deposit_l(0); - FOR(i = 0; i < L_FRAME; i++) - { + } + qEL1 = shl( qEL1, 1 ); + + qf = qIn; + move16(); + Scale_sig( hSC_VBR->txhpf1_filt1_mem_fx, 10, qf - hSC_VBR->qprevIn_fx ); + pz_filter_sp_fx( txhpf1_num_coef_fx, txhpf1_den_coef_fx, in_fx, filtRes_fx, hSC_VBR->txhpf1_filt1_mem_fx, 10, 10, L_FRAME, 3 ); /*1 = (16-qformat of shape1 cofficient) */ + hSC_VBR->qprevIn_fx = qf; + move16(); + + qEH1 = qf; + move16(); + EH1_fx = L_deposit_l( 0 ); + FOR( i = 0; i < L_FRAME; i++ ) + { #ifdef BASOP_NOGLOB - EH1_fx = L_mac0_o(EH1_fx, filtRes_fx[i], filtRes_fx[i], &Overflow); /*Q(2*qEH1) */ + EH1_fx = L_mac0_o( EH1_fx, filtRes_fx[i], filtRes_fx[i], &Overflow ); /*Q(2*qEH1) */ #else - EH1_fx = L_mac0(EH1_fx, filtRes_fx[i], filtRes_fx[i]); /*Q(2*qEH1) */ + EH1_fx = L_mac0( EH1_fx, filtRes_fx[i], filtRes_fx[i] ); /*Q(2*qEH1) */ #endif - } - qEH1 = 2 * qEH1; - move16(); - - } - - qGain = qIn; - move16(); - qGain = 2 * qGain; - move16(); - - FOR(i = 0; i < 9; i++) - { - Ltemp = L_deposit_l(0); - FOR(j = (Word16)(i*lag); j < (Word16)((i + 1)*lag); j++) - { + } + qEH1 = 2 * qEH1; + move16(); + } + + qGain = qIn; + move16(); + qGain = 2 * qGain; + move16(); + + FOR( i = 0; i < 9; i++ ) + { + Ltemp = L_deposit_l( 0 ); + FOR( j = (Word16) ( i * lag ); j < (Word16) ( ( i + 1 ) * lag ); j++ ) + { #ifdef BASOP_NOGLOB - Ltemp = L_mac0_o(Ltemp, in_fx[j], in_fx[j], &Overflow); /*Q(2*qGain) */ + Ltemp = L_mac0_o( Ltemp, in_fx[j], in_fx[j], &Overflow ); /*Q(2*qGain) */ #else - Ltemp = L_mac0(Ltemp, in_fx[j], in_fx[j]); /*Q(2*qGain) */ + Ltemp = L_mac0( Ltemp, in_fx[j], in_fx[j] ); /*Q(2*qGain) */ #endif - } - - /*Gains[i] = (float) sqrt(Gains[i]/lag); */ - IF(Ltemp != 0) - { - exp1 = norm_l(Ltemp); - tmp1 = extract_h(L_shl(Ltemp, exp1));/*2*qGain+exp1-16 */ - exp1 = sub(exp1, 30 - qGain); /* */ - - tmp1 = div_s(16384, tmp1);/*14-2*qGain-exp1+16 */ - L_tmp = L_deposit_h(tmp1); - L_tmp = Isqrt_lc(L_tmp, &exp1); - L_tmp = Mult_32_16(L_tmp, sqrt_inv_lag); + } + + /*Gains[i] = (float) sqrt(Gains[i]/lag); */ + IF( Ltemp != 0 ) + { + exp1 = norm_l( Ltemp ); + tmp1 = extract_h( L_shl( Ltemp, exp1 ) ); /*2*qGain+exp1-16 */ + exp1 = sub( exp1, 30 - qGain ); /* */ + + tmp1 = div_s( 16384, tmp1 ); /*14-2*qGain-exp1+16 */ + L_tmp = L_deposit_h( tmp1 ); + L_tmp = Isqrt_lc( L_tmp, &exp1 ); + L_tmp = Mult_32_16( L_tmp, sqrt_inv_lag ); #ifdef BASOP_NOGLOB Ltemp = L_shl_sat( L_tmp, sub( exp1, 12 ) ); /*Q3 */ #else - Ltemp = L_shl(L_tmp, sub(exp1, 12));/*Q3 */ + Ltemp = L_shl( L_tmp, sub( exp1, 12 ) ); /*Q3 */ #endif - } + } #ifdef BASOP_NOGLOB Gains_fx[i] = round_fx_sat( Ltemp ); #else - Gains_fx[i] = round_fx(Ltemp); + Gains_fx[i] = round_fx( Ltemp ); #endif - } + } - Ltemp = L_deposit_l(0); - FOR(j = (Word16)(i*lag); j < L_FRAME; j++) - { + Ltemp = L_deposit_l( 0 ); + FOR( j = (Word16) ( i * lag ); j < L_FRAME; j++ ) + { #ifdef BASOP_NOGLOB - Ltemp = L_mac0_o(Ltemp, in_fx[j], in_fx[j], &Overflow); /*Q(2*qGain) */ + Ltemp = L_mac0_o( Ltemp, in_fx[j], in_fx[j], &Overflow ); /*Q(2*qGain) */ #else - Ltemp = L_mac0(Ltemp, in_fx[j], in_fx[j]); /*Q(2*qGain) */ + Ltemp = L_mac0( Ltemp, in_fx[j], in_fx[j] ); /*Q(2*qGain) */ #endif - } - - /*Gains[i] = (float) sqrt(Gains[i]/(L_FRAME-(lag*i))); */ - IF(Ltemp != 0) - { - exp1 = norm_l(Ltemp); - tmp1 = extract_h(L_shl(Ltemp, exp1)); - exp1 = sub(exp1, 30 - qGain); /* */ - - tmp1 = div_s(16384, tmp1); - L_tmp = L_deposit_h(tmp1); - L_tmp = Isqrt_lc(L_tmp, &exp1); - L_tmp = Mult_32_16(L_tmp, sqrt_inv_lframe_lag); + } + + /*Gains[i] = (float) sqrt(Gains[i]/(L_FRAME-(lag*i))); */ + IF( Ltemp != 0 ) + { + exp1 = norm_l( Ltemp ); + tmp1 = extract_h( L_shl( Ltemp, exp1 ) ); + exp1 = sub( exp1, 30 - qGain ); /* */ + + tmp1 = div_s( 16384, tmp1 ); + L_tmp = L_deposit_h( tmp1 ); + L_tmp = Isqrt_lc( L_tmp, &exp1 ); + L_tmp = Mult_32_16( L_tmp, sqrt_inv_lframe_lag ); #ifdef BASOP_NOGLOB Ltemp = L_shl_sat( L_tmp, sub( exp1, 12 ) ); #else Ltemp = L_shl( L_tmp, sub( exp1, 12 ) ); #endif - } + } #ifdef BASOP_NOGLOB Gains_fx[i] = round_fx_sat( Ltemp ); #else Gains_fx[i] = round_fx( Ltemp ); #endif - IF(EQ_16(reduce_gains, 1)) - { - FOR(i = 0; i < 10; i++) - { - Gains_fx[i] = mult(Gains_fx[i], 19661); - } - } - - - qGain = 3; - move16(); - IF(hSC_VBR->last_nelp_mode != 1) /* if prev frame was not NELP then init mem*/ - { - hSC_VBR->nelp_gain_mem_fx = Gains_fx[0]; - move16(); - qNelpGain = qGain; - move16(); - } - - /* tmp = (float) (20.0 * (log10 (Gains[0]) - log10 (st->nelp_gain_mem) ) ); */ - /* var_dB = tmp * tmp; */ - L_tmp = L_deposit_l(Gains_fx[0]); - L_tmp = L_max(L_tmp, 1); - exp2 = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, exp2);/*15+qEL1-qEL2-exp1+exp2 */ - exp2 = 30 - exp2 - qGain; - move16(); - tmp1 = Log2_norm_lc(L_tmp); - Ltemp = Mpy_32_16(exp2, tmp1, 9864); /*log(2) in Q13 format = Q0 format */ - /*tmp1 = round_fx(L_shl(Ltemp,12)); Q12 */ - - L_tmp = L_deposit_l(hSC_VBR->nelp_gain_mem_fx); /*Q0 */ - L_tmp = L_max(L_tmp, 1); - exp2 = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, exp2);/*15+qEL1-qEL2-exp1+exp2 */ - exp2 = 30 - exp2 - qNelpGain; - move16(); - tmp2 = Log2_norm_lc(L_tmp); - Ltemp1 = Mpy_32_16(exp2, tmp2, 9864); /*log(2) in Q13 format = Q0 format */ - Ltemp1 = L_sub(Ltemp, Ltemp1);/*Q16 */ - Ltemp = Mult_32_16(Ltemp1, 20480);/*Q11 (20 in Q10) */ - L_tmp = L_shl(Ltemp, 12);/*Q23 */ - var_dB_fx = Mult_32_32(L_tmp, L_tmp);/*Q15 */ - - FOR(i = 1; i < 10; i++) - { - L_tmp = L_deposit_l(Gains_fx[i]); - L_tmp = L_max(L_tmp, 1); - exp2 = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, exp2);/*15+qEL1-qEL2-exp1+exp2 */ - exp2 = 30 - exp2 - qGain; - move16(); - tmp1 = Log2_norm_lc(L_tmp); - Ltemp = Mpy_32_16(exp2, tmp1, 9864); /*log(2) in Q13 format = Q0 format */ - - L_tmp = L_deposit_l(Gains_fx[i - 1]); /*Q0 */ - L_tmp = L_max(L_tmp, 1); - exp2 = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, exp2);/*15+qEL1-qEL2-exp1+exp2 */ - exp2 = 30 - exp2 - qGain; - move16(); - tmp2 = Log2_norm_lc(L_tmp); - Ltemp1 = Mpy_32_16(exp2, tmp2, 9864); /*log(2) in Q13 format = Q0 format */ - Ltemp1 = L_sub(Ltemp, Ltemp1);/*Q16 */ - Ltemp = Mult_32_16(Ltemp1, 20480);/*Q11 (20 in Q10) */ - L_tmp = L_shl(Ltemp, 12);/*Q23 */ - L_tmp = Mult_32_32(L_tmp, L_tmp);/*Q15 */ - var_dB_fx = L_add(L_tmp, var_dB_fx);/*Q15 */ - } - - IF(hSC_VBR->last_nelp_mode != 1) - { - /*var_dB *= 0.111f; */ - var_dB_fx = Mult_32_16(var_dB_fx, 3637); /*0.111 in Q15 */ - } - ELSE - { - /*var_dB *= 0.1f; */ - var_dB_fx = Mult_32_16(var_dB_fx, 3277); /*0.1 in Q15 */ - } - - max1 = 0; - move16(); - FOR(i = 0; i < 10; i++) - { - max1 = s_max(max1, abs_s(Gains_fx[i])); - } - - qf = norm_s((Word16)max1); - test(); - IF((qf == 0) && (((Word16)max1) == 0)) - { - qf = 15; - move16(); - } - qf = sub(qf, 1); - qGain = add(qGain, qf); - - Scale_sig(Gains_fx, 10, qf); - - L_tmp = L_sub(var_dB_fx, 655360); /* 20 in Q15 */ - Ltemp = L_shr_r(L_tmp, 2);/*Q15 */ - { - /*exp = pow(2, x*log2(e)) */ - L_tmp = Mult_32_16(Ltemp, 23637); /*15 + 14 -15 ->Q14 */ - L_tmp = L_shl(L_tmp, 2); /*Q16 */ - f_Noise = L_Extract_lc(L_tmp, &e_Noise); /*Q16 */ - etmp = extract_l(Pow2(14, f_Noise)); /* Put 14 as exponent */ - e_Noise = sub(e_Noise, 14); /* Retreive exponent of etmp */ - - - IF(e_Noise > 0) - { + IF( EQ_16( reduce_gains, 1 ) ) + { + FOR( i = 0; i < 10; i++ ) + { + Gains_fx[i] = mult( Gains_fx[i], 19661 ); + } + } + + + qGain = 3; + move16(); + IF( hSC_VBR->last_nelp_mode != 1 ) /* if prev frame was not NELP then init mem*/ + { + hSC_VBR->nelp_gain_mem_fx = Gains_fx[0]; + move16(); + qNelpGain = qGain; + move16(); + } + + /* tmp = (float) (20.0 * (log10 (Gains[0]) - log10 (st->nelp_gain_mem) ) ); */ + /* var_dB = tmp * tmp; */ + L_tmp = L_deposit_l( Gains_fx[0] ); + L_tmp = L_max( L_tmp, 1 ); + exp2 = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, exp2 ); /*15+qEL1-qEL2-exp1+exp2 */ + exp2 = 30 - exp2 - qGain; + move16(); + tmp1 = Log2_norm_lc( L_tmp ); + Ltemp = Mpy_32_16( exp2, tmp1, 9864 ); /*log(2) in Q13 format = Q0 format */ + /*tmp1 = round_fx(L_shl(Ltemp,12)); Q12 */ + + L_tmp = L_deposit_l( hSC_VBR->nelp_gain_mem_fx ); /*Q0 */ + L_tmp = L_max( L_tmp, 1 ); + exp2 = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, exp2 ); /*15+qEL1-qEL2-exp1+exp2 */ + exp2 = 30 - exp2 - qNelpGain; + move16(); + tmp2 = Log2_norm_lc( L_tmp ); + Ltemp1 = Mpy_32_16( exp2, tmp2, 9864 ); /*log(2) in Q13 format = Q0 format */ + Ltemp1 = L_sub( Ltemp, Ltemp1 ); /*Q16 */ + Ltemp = Mult_32_16( Ltemp1, 20480 ); /*Q11 (20 in Q10) */ + L_tmp = L_shl( Ltemp, 12 ); /*Q23 */ + var_dB_fx = Mult_32_32( L_tmp, L_tmp ); /*Q15 */ + + FOR( i = 1; i < 10; i++ ) + { + L_tmp = L_deposit_l( Gains_fx[i] ); + L_tmp = L_max( L_tmp, 1 ); + exp2 = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, exp2 ); /*15+qEL1-qEL2-exp1+exp2 */ + exp2 = 30 - exp2 - qGain; + move16(); + tmp1 = Log2_norm_lc( L_tmp ); + Ltemp = Mpy_32_16( exp2, tmp1, 9864 ); /*log(2) in Q13 format = Q0 format */ + + L_tmp = L_deposit_l( Gains_fx[i - 1] ); /*Q0 */ + L_tmp = L_max( L_tmp, 1 ); + exp2 = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, exp2 ); /*15+qEL1-qEL2-exp1+exp2 */ + exp2 = 30 - exp2 - qGain; + move16(); + tmp2 = Log2_norm_lc( L_tmp ); + Ltemp1 = Mpy_32_16( exp2, tmp2, 9864 ); /*log(2) in Q13 format = Q0 format */ + Ltemp1 = L_sub( Ltemp, Ltemp1 ); /*Q16 */ + Ltemp = Mult_32_16( Ltemp1, 20480 ); /*Q11 (20 in Q10) */ + L_tmp = L_shl( Ltemp, 12 ); /*Q23 */ + L_tmp = Mult_32_32( L_tmp, L_tmp ); /*Q15 */ + var_dB_fx = L_add( L_tmp, var_dB_fx ); /*Q15 */ + } + + IF( hSC_VBR->last_nelp_mode != 1 ) + { + /*var_dB *= 0.111f; */ + var_dB_fx = Mult_32_16( var_dB_fx, 3637 ); /*0.111 in Q15 */ + } + ELSE + { + /*var_dB *= 0.1f; */ + var_dB_fx = Mult_32_16( var_dB_fx, 3277 ); /*0.1 in Q15 */ + } + + max1 = 0; + move16(); + FOR( i = 0; i < 10; i++ ) + { + max1 = s_max( max1, abs_s( Gains_fx[i] ) ); + } + + qf = norm_s( (Word16) max1 ); + test(); + IF( ( qf == 0 ) && ( ( (Word16) max1 ) == 0 ) ) + { + qf = 15; + move16(); + } + qf = sub( qf, 1 ); + qGain = add( qGain, qf ); + + Scale_sig( Gains_fx, 10, qf ); + + L_tmp = L_sub( var_dB_fx, 655360 ); /* 20 in Q15 */ + Ltemp = L_shr_r( L_tmp, 2 ); /*Q15 */ + { + /*exp = pow(2, x*log2(e)) */ + L_tmp = Mult_32_16( Ltemp, 23637 ); /*15 + 14 -15 ->Q14 */ + L_tmp = L_shl( L_tmp, 2 ); /*Q16 */ + f_Noise = L_Extract_lc( L_tmp, &e_Noise ); /*Q16 */ + etmp = extract_l( Pow2( 14, f_Noise ) ); /* Put 14 as exponent */ + e_Noise = sub( e_Noise, 14 ); /* Retreive exponent of etmp */ + + + IF( e_Noise > 0 ) + { #ifdef BASOP_NOGLOB - L_tmp = L_shl_sat( etmp, e_Noise ); /* Result in Q30 */ + L_tmp = L_shl_sat( etmp, e_Noise ); /* Result in Q30 */ L_tmp = L_add_sat( 1, L_tmp ); #else - L_tmp = L_shl( etmp, e_Noise ); /* Result in Q30 */ + L_tmp = L_shl( etmp, e_Noise ); /* Result in Q30 */ L_tmp = L_add( 1, L_tmp ); #endif - exp1 = norm_l(L_tmp); - tmp1 = extract_h(L_shl(L_tmp, exp1));/*exp1-16 */ - tmp1 = div_s(16384, tmp1);/*14-(exp1-16)-> 30+15-exp1 */ - fdbck_fx = mult(26870, tmp1);/*45-exp1+15-15=>45-exp1 */ - fdbck_fx = shr_r(fdbck_fx, 14); - exp1 = sub(31, exp1); - } - ELSE - { - L_tmp = L_shl(etmp,add(e_Noise, 14)); /* Result in Q30 */ - L_tmp = L_add(16384, L_tmp); - - exp1 = norm_l(L_tmp); - tmp1 = extract_h(L_shl(L_tmp, exp1));/*14+exp1-16 */ - tmp1 = div_s(16384, tmp1);/*14-(14+exp1-16)-> 16+15-exp1 */ - fdbck_fx = mult(26870, tmp1);/*31-exp1+15-15=>31-exp1 */ - exp1 = sub(31,exp1); - } - } - - IF(exp1 == 31) - { - L_const_1 = 0x7fffffff; - move32(); - } - ELSE - { - L_const_1 = L_shl(1, exp1); - } - - l_nelp_gain_mem = L_deposit_l(hSC_VBR->nelp_gain_mem_fx); - IF(NE_16(qNelpGain, qGain)) - { - l_nelp_gain_mem = L_shl(l_nelp_gain_mem, sub(qGain, qNelpGain)); - } - - FOR(i = 0; i < 10; i++) - { - /*Gains[i] = (float)((1.0f - fdbck) * Gains[i] + fdbck * st->nelp_gain_mem); */ - L_tmp = L_sub(L_const_1, L_deposit_l(fdbck_fx));/*31-exp1 */ - L_tmp = Mult_32_16(L_tmp, Gains_fx[i]);/*exp1+qGain-15=>exp1-15+qGain */ - Ltemp1 = Mult_32_16(l_nelp_gain_mem, fdbck_fx);/*exp1+qGain-15 */ - L_tmp = L_add(L_tmp, Ltemp1); - L_tmp = L_shr_r(L_tmp, (exp1 - 15)); + exp1 = norm_l( L_tmp ); + tmp1 = extract_h( L_shl( L_tmp, exp1 ) ); /*exp1-16 */ + tmp1 = div_s( 16384, tmp1 ); /*14-(exp1-16)-> 30+15-exp1 */ + fdbck_fx = mult( 26870, tmp1 ); /*45-exp1+15-15=>45-exp1 */ + fdbck_fx = shr_r( fdbck_fx, 14 ); + exp1 = sub( 31, exp1 ); + } + ELSE + { + L_tmp = L_shl( etmp, add( e_Noise, 14 ) ); /* Result in Q30 */ + L_tmp = L_add( 16384, L_tmp ); + + exp1 = norm_l( L_tmp ); + tmp1 = extract_h( L_shl( L_tmp, exp1 ) ); /*14+exp1-16 */ + tmp1 = div_s( 16384, tmp1 ); /*14-(14+exp1-16)-> 16+15-exp1 */ + fdbck_fx = mult( 26870, tmp1 ); /*31-exp1+15-15=>31-exp1 */ + exp1 = sub( 31, exp1 ); + } + } + + IF( exp1 == 31 ) + { + L_const_1 = 0x7fffffff; + move32(); + } + ELSE + { + L_const_1 = L_shl( 1, exp1 ); + } + + l_nelp_gain_mem = L_deposit_l( hSC_VBR->nelp_gain_mem_fx ); + IF( NE_16( qNelpGain, qGain ) ) + { + l_nelp_gain_mem = L_shl( l_nelp_gain_mem, sub( qGain, qNelpGain ) ); + } + + FOR( i = 0; i < 10; i++ ) + { + /*Gains[i] = (float)((1.0f - fdbck) * Gains[i] + fdbck * st->nelp_gain_mem); */ + L_tmp = L_sub( L_const_1, L_deposit_l( fdbck_fx ) ); /*31-exp1 */ + L_tmp = Mult_32_16( L_tmp, Gains_fx[i] ); /*exp1+qGain-15=>exp1-15+qGain */ + Ltemp1 = Mult_32_16( l_nelp_gain_mem, fdbck_fx ); /*exp1+qGain-15 */ + L_tmp = L_add( L_tmp, Ltemp1 ); + L_tmp = L_shr_r( L_tmp, ( exp1 - 15 ) ); #ifdef BASOP_NOGLOB Gains_fx[i] = round_fx_sat( L_shl_sat( L_tmp, 16 ) ); #else - Gains_fx[i] = round_fx(L_shl(L_tmp, 16)); + Gains_fx[i] = round_fx( L_shl( L_tmp, 16 ) ); #endif - move16(); - l_nelp_gain_mem = L_tmp; - } - - hSC_VBR->nelp_gain_mem_fx = round_fx(L_shl(l_nelp_gain_mem, 16)); - - Scale_sig(&hSC_VBR->nelp_gain_mem_fx, 1, -qGain); - Scale_sig(Gains_fx, 10, -qGain); - qGain = 0; - move16(); - - quantize_uvg_fx(Gains_fx, &iG1_fx, iG2_fx, Gains_fx, st_fx->bwidth); - - IF(EQ_16(rf_flag, 1)) - { - hRF->rf_indx_nelp_iG1[0] = iG1_fx; - hRF->rf_indx_nelp_iG2[0][0] = iG2_fx[0]; - hRF->rf_indx_nelp_iG2[0][1] = iG2_fx[1]; - } - ELSE - { - push_indice_fx(hBstr, IND_IG1, iG1_fx, 5); - push_indice_fx(hBstr, IND_IG2A, iG2_fx[0], 6); - push_indice_fx(hBstr, IND_IG2B, iG2_fx[1], 6); - } - - test(); - IF(EQ_16(st_fx->bwidth, WB) || EQ_16(st_fx->bwidth, SWB)) - { - gain_fac_fx = 19005; - move16();/* 1.16f in Q14 */ - } - ELSE - { - gain_fac_fx = 22446; - move16(); /* 1.37f in Q14 */ - } - - /* Normalize Gains_fx[10] with headroom 4 */ - /* This fills up qGain with some new value */ - normalize_arr(Gains_fx, &qGain, 10, 4); - - generate_nelp_excitation_fx(&(hSC_VBR->nelp_enc_seed), Gains_fx, ptr_fx, gain_fac_fx); - test(); - IF(EQ_16(st_fx->bwidth, WB) || EQ_16(st_fx->bwidth, SWB)) - { - BP1_ORDER = 4; - Scale_sig(hSC_VBR->bp1_filt_mem_wb_fx, BP1_ORDER * 2, qGain - hSC_VBR->qprevGain_fx);/*qf-qAdj */ - pz_filter_sp_fx(bp1_num_coef_wb_fx, bp1_den_coef_wb_fx, ptr_fx, ptr_tmp_fx, hSC_VBR->bp1_filt_mem_wb_fx, BP1_ORDER, BP1_ORDER, L_FRAME, 2); - Copy(ptr_tmp_fx, ptr_fx, L_FRAME); - } - ELSE IF(EQ_16(st_fx->bwidth, NB)) - { - BP1_ORDER = 7; - move16(); - Scale_sig32(hSC_VBR->bp1_filt_mem_nb_fx, BP1_ORDER * 2, (qGain - hSC_VBR->qprevGain_fx)); - pz_filter_dp_fx(bp1_num_coef_nb_fx_order7, bp1_den_coef_nb_fx_order7, ptr_fx, ptr_tmp_fx, hSC_VBR->bp1_filt_mem_nb_fx, BP1_ORDER, BP1_ORDER, L_FRAME, (sub(16, BP1_COEF_NB_QF_ORDER7))); - Copy(ptr_tmp_fx, ptr_fx, L_FRAME); - - Scale_sig(ptr_fx, L_FRAME, -1); /* bring exc to qgain-1 */ - *qIn1 = qGain - 1; /* use this temp only in the parent */ - } - - E3_fx = L_deposit_l(0); - FOR(i = 0; i < L_FRAME; i++) - { + move16(); + l_nelp_gain_mem = L_tmp; + } + + hSC_VBR->nelp_gain_mem_fx = round_fx( L_shl( l_nelp_gain_mem, 16 ) ); + + Scale_sig( &hSC_VBR->nelp_gain_mem_fx, 1, -qGain ); + Scale_sig( Gains_fx, 10, -qGain ); + qGain = 0; + move16(); + + quantize_uvg_fx( Gains_fx, &iG1_fx, iG2_fx, Gains_fx, st_fx->bwidth ); + + IF( EQ_16( rf_flag, 1 ) ) + { + hRF->rf_indx_nelp_iG1[0] = iG1_fx; + hRF->rf_indx_nelp_iG2[0][0] = iG2_fx[0]; + hRF->rf_indx_nelp_iG2[0][1] = iG2_fx[1]; + } + ELSE + { + push_indice_fx( hBstr, IND_IG1, iG1_fx, 5 ); + push_indice_fx( hBstr, IND_IG2A, iG2_fx[0], 6 ); + push_indice_fx( hBstr, IND_IG2B, iG2_fx[1], 6 ); + } + + test(); + IF( EQ_16( st_fx->bwidth, WB ) || EQ_16( st_fx->bwidth, SWB ) ) + { + gain_fac_fx = 19005; + move16(); /* 1.16f in Q14 */ + } + ELSE + { + gain_fac_fx = 22446; + move16(); /* 1.37f in Q14 */ + } + + /* Normalize Gains_fx[10] with headroom 4 */ + /* This fills up qGain with some new value */ + normalize_arr( Gains_fx, &qGain, 10, 4 ); + + generate_nelp_excitation_fx( &( hSC_VBR->nelp_enc_seed ), Gains_fx, ptr_fx, gain_fac_fx ); + test(); + IF( EQ_16( st_fx->bwidth, WB ) || EQ_16( st_fx->bwidth, SWB ) ) + { + BP1_ORDER = 4; + Scale_sig( hSC_VBR->bp1_filt_mem_wb_fx, BP1_ORDER * 2, qGain - hSC_VBR->qprevGain_fx ); /*qf-qAdj */ + pz_filter_sp_fx( bp1_num_coef_wb_fx, bp1_den_coef_wb_fx, ptr_fx, ptr_tmp_fx, hSC_VBR->bp1_filt_mem_wb_fx, BP1_ORDER, BP1_ORDER, L_FRAME, 2 ); + Copy( ptr_tmp_fx, ptr_fx, L_FRAME ); + } + ELSE IF( EQ_16( st_fx->bwidth, NB ) ) + { + BP1_ORDER = 7; + move16(); + Scale_sig32( hSC_VBR->bp1_filt_mem_nb_fx, BP1_ORDER * 2, ( qGain - hSC_VBR->qprevGain_fx ) ); + pz_filter_dp_fx( bp1_num_coef_nb_fx_order7, bp1_den_coef_nb_fx_order7, ptr_fx, ptr_tmp_fx, hSC_VBR->bp1_filt_mem_nb_fx, BP1_ORDER, BP1_ORDER, L_FRAME, ( sub( 16, BP1_COEF_NB_QF_ORDER7 ) ) ); + Copy( ptr_tmp_fx, ptr_fx, L_FRAME ); + + Scale_sig( ptr_fx, L_FRAME, -1 ); /* bring exc to qgain-1 */ + *qIn1 = qGain - 1; /* use this temp only in the parent */ + } + + E3_fx = L_deposit_l( 0 ); + FOR( i = 0; i < L_FRAME; i++ ) + { #ifdef BASOP_NOGLOB E3_fx = L_mac_sat( E3_fx, ptr_fx[i], ptr_fx[i] ); /*Q1 */ #else - E3_fx = L_mac(E3_fx, ptr_fx[i], ptr_fx[i]); /*Q1 */ + E3_fx = L_mac( E3_fx, ptr_fx[i], ptr_fx[i] ); /*Q1 */ #endif - } - qE3 = 2 * qGain + 1; - move16(); - test(); - IF(st_fx->bwidth == WB || EQ_16(st_fx->bwidth, SWB)) - { - Scale_sig(hSC_VBR->shape1_filt_mem_fx, 10, (qGain - hSC_VBR->qprevGain_fx)); - pz_filter_sp_fx(shape1_num_coef_fx, shape1_den_coef_fx, ptr_fx, ptr_tmp_fx, hSC_VBR->shape1_filt_mem_fx, 10, 10, L_FRAME, 1);/*1 = (16-qformat of shape1 cofficient) */ - Copy(ptr_tmp_fx, ptr_fx, L_FRAME); - - qf = qGain; - move16(); - E2_fx = L_deposit_l(0); - FOR(i = 0; i < L_FRAME; i++) - { - Ltemp = L_mult0(ptr_fx[i], ptr_fx[i]); /*Q(2*qE2+1) */ - Ltemp = L_shr_r(Ltemp, 4); - E2_fx = L_add(E2_fx, Ltemp); - } - qE2 = 2 * qf - 4; - move16(); - - test(); - IF(E1_fx == 0) - { - R_fx = 0; - move16(); - } - ELSE IF((E2_fx == 0) && (E1_fx != 0)) - { - exp1 = norm_l(E1_fx); - tmp1 = extract_h(L_shl(E1_fx, exp1));/*qE1+exp1-16 */ - tmp1 = div_s(16384, tmp1);/*14-(qE1+exp1-16)-> 30-qE1-exp1 */ - exp1 = sub(exp1, 30 - qE1); - - L_tmp = L_deposit_h(tmp1); - L_tmp = Isqrt_lc(L_tmp, &exp1); - Ltemp = L_shl(L_tmp, sub(exp1, 12)); - R_fx = round_fx(Ltemp); - } - ELSE - { - exp1 = norm_l(E1_fx); - tmp1 = extract_h(L_shl(E1_fx, exp1));/*qE1+exp1-16 */ - tmp1 = div_s(16384, tmp1);/*14-(qE1+exp1-16)-> 30-qE1-exp1 */ - L_tmp = Mult_32_16(E2_fx, tmp1);/*qE2+30-qE1-exp1-15=>15+qE2-qE1-exp1 */ - - exp2 = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, exp2);/*15+qE2-qE1-exp1+exp2 */ - exp2 = 30 - (15 + qE2 - qE1 - exp1 + exp2); - move16(); - L_tmp = Isqrt_lc(L_tmp, &exp2);/*Q(31+exp2) */ - R_fx = round_fx(L_tmp); - exp1 = 31 - exp2 - 16 - 7; - move16(); - } - - FOR(i = 0; i < L_FRAME; i++) - { - Ltemp = L_mult0(R_fx, ptr_fx[i]); - Ltemp = L_shr_r(Ltemp, exp1); + } + qE3 = 2 * qGain + 1; + move16(); + test(); + IF( st_fx->bwidth == WB || EQ_16( st_fx->bwidth, SWB ) ) + { + Scale_sig( hSC_VBR->shape1_filt_mem_fx, 10, ( qGain - hSC_VBR->qprevGain_fx ) ); + pz_filter_sp_fx( shape1_num_coef_fx, shape1_den_coef_fx, ptr_fx, ptr_tmp_fx, hSC_VBR->shape1_filt_mem_fx, 10, 10, L_FRAME, 1 ); /*1 = (16-qformat of shape1 cofficient) */ + Copy( ptr_tmp_fx, ptr_fx, L_FRAME ); + + qf = qGain; + move16(); + E2_fx = L_deposit_l( 0 ); + FOR( i = 0; i < L_FRAME; i++ ) + { + Ltemp = L_mult0( ptr_fx[i], ptr_fx[i] ); /*Q(2*qE2+1) */ + Ltemp = L_shr_r( Ltemp, 4 ); + E2_fx = L_add( E2_fx, Ltemp ); + } + qE2 = 2 * qf - 4; + move16(); + + test(); + IF( E1_fx == 0 ) + { + R_fx = 0; + move16(); + } + ELSE IF( ( E2_fx == 0 ) && ( E1_fx != 0 ) ) + { + exp1 = norm_l( E1_fx ); + tmp1 = extract_h( L_shl( E1_fx, exp1 ) ); /*qE1+exp1-16 */ + tmp1 = div_s( 16384, tmp1 ); /*14-(qE1+exp1-16)-> 30-qE1-exp1 */ + exp1 = sub( exp1, 30 - qE1 ); + + L_tmp = L_deposit_h( tmp1 ); + L_tmp = Isqrt_lc( L_tmp, &exp1 ); + Ltemp = L_shl( L_tmp, sub( exp1, 12 ) ); + R_fx = round_fx( Ltemp ); + } + ELSE + { + exp1 = norm_l( E1_fx ); + tmp1 = extract_h( L_shl( E1_fx, exp1 ) ); /*qE1+exp1-16 */ + tmp1 = div_s( 16384, tmp1 ); /*14-(qE1+exp1-16)-> 30-qE1-exp1 */ + L_tmp = Mult_32_16( E2_fx, tmp1 ); /*qE2+30-qE1-exp1-15=>15+qE2-qE1-exp1 */ + + exp2 = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, exp2 ); /*15+qE2-qE1-exp1+exp2 */ + exp2 = 30 - ( 15 + qE2 - qE1 - exp1 + exp2 ); + move16(); + L_tmp = Isqrt_lc( L_tmp, &exp2 ); /*Q(31+exp2) */ + R_fx = round_fx( L_tmp ); + exp1 = 31 - exp2 - 16 - 7; + move16(); + } + + FOR( i = 0; i < L_FRAME; i++ ) + { + Ltemp = L_mult0( R_fx, ptr_fx[i] ); + Ltemp = L_shr_r( Ltemp, exp1 ); #ifdef BASOP_NOGLOB filtRes_fx[i] = round_fx_sat( L_shl_sat( Ltemp, 16 ) ); #else - filtRes_fx[i] = round_fx(L_shl(Ltemp, 16)); + filtRes_fx[i] = round_fx( L_shl( Ltemp, 16 ) ); #endif - } + } - qf1 = qGain; - move16(); - Scale_sig(hSC_VBR->txlpf1_filt2_mem_fx, 10, (qf1 - hSC_VBR->qprevGain_fx)); + qf1 = qGain; + move16(); + Scale_sig( hSC_VBR->txlpf1_filt2_mem_fx, 10, ( qf1 - hSC_VBR->qprevGain_fx ) ); - pz_filter_sp_fx(txlpf1_num_coef_fx, txlpf1_den_coef_fx, filtRes_fx, ptr_tmp_fx, hSC_VBR->txlpf1_filt2_mem_fx, 10, 10, L_FRAME, 3);/*1 = (16-qformat of shape1 cofficient) */ - Copy(ptr_tmp_fx, filtRes_fx, L_FRAME); + pz_filter_sp_fx( txlpf1_num_coef_fx, txlpf1_den_coef_fx, filtRes_fx, ptr_tmp_fx, hSC_VBR->txlpf1_filt2_mem_fx, 10, 10, L_FRAME, 3 ); /*1 = (16-qformat of shape1 cofficient) */ + Copy( ptr_tmp_fx, filtRes_fx, L_FRAME ); - qEL2 = qf1; - move16(); - EL2_fx = L_deposit_l(0); - FOR(i = 0; i < L_FRAME; i++) - { + qEL2 = qf1; + move16(); + EL2_fx = L_deposit_l( 0 ); + FOR( i = 0; i < L_FRAME; i++ ) + { #ifdef BASOP_NOGLOB EL2_fx = L_mac0_sat( EL2_fx, filtRes_fx[i], filtRes_fx[i] ); /*Q(2*qEL2) */ #else - EL2_fx = L_mac0(EL2_fx, filtRes_fx[i], filtRes_fx[i]); /*Q(2*qEL2) */ + EL2_fx = L_mac0( EL2_fx, filtRes_fx[i], filtRes_fx[i] ); /*Q(2*qEL2) */ #endif - } - qEL2 = 2 * qEL2; - move16(); - - FOR(i = 0; i < L_FRAME; i++) - { - Ltemp = L_mult0(R_fx, ptr_fx[i]); - Ltemp = L_shr_r(Ltemp, exp1); + } + qEL2 = 2 * qEL2; + move16(); + + FOR( i = 0; i < L_FRAME; i++ ) + { + Ltemp = L_mult0( R_fx, ptr_fx[i] ); + Ltemp = L_shr_r( Ltemp, exp1 ); #ifdef BASOP_NOGLOB filtRes_fx[i] = round_fx_sat( L_shl_sat( Ltemp, 16 ) ); #else - filtRes_fx[i] = round_fx(L_shl(Ltemp, 16)); + filtRes_fx[i] = round_fx( L_shl( Ltemp, 16 ) ); #endif - } + } - qf = qGain; - move16(); - Scale_sig(hSC_VBR->txhpf1_filt2_mem_fx, 10, (qf - hSC_VBR->qprevGain_fx)); - pz_filter_sp_fx(txhpf1_num_coef_fx, txhpf1_den_coef_fx, filtRes_fx, ptr_tmp_fx, hSC_VBR->txhpf1_filt2_mem_fx, 10, 10, L_FRAME, 3);/*1 = (16-qformat of shape1 cofficient) */ + qf = qGain; + move16(); + Scale_sig( hSC_VBR->txhpf1_filt2_mem_fx, 10, ( qf - hSC_VBR->qprevGain_fx ) ); + pz_filter_sp_fx( txhpf1_num_coef_fx, txhpf1_den_coef_fx, filtRes_fx, ptr_tmp_fx, hSC_VBR->txhpf1_filt2_mem_fx, 10, 10, L_FRAME, 3 ); /*1 = (16-qformat of shape1 cofficient) */ - Copy(ptr_tmp_fx, filtRes_fx, L_FRAME); + Copy( ptr_tmp_fx, filtRes_fx, L_FRAME ); - qEH2 = qf; - move16(); - EH2_fx = L_deposit_l(0); - FOR(i = 0; i < L_FRAME; i++) - { + qEH2 = qf; + move16(); + EH2_fx = L_deposit_l( 0 ); + FOR( i = 0; i < L_FRAME; i++ ) + { #ifdef BASOP_NOGLOB - EH2_fx = L_mac0_sat( EH2_fx, filtRes_fx[i], filtRes_fx[i] ); /*Q(2*qEH2) */ + EH2_fx = L_mac0_sat( EH2_fx, filtRes_fx[i], filtRes_fx[i] ); /*Q(2*qEH2) */ #else - EH2_fx = L_mac0(EH2_fx, filtRes_fx[i], filtRes_fx[i]); /*Q(2*qEH2) */ + EH2_fx = L_mac0( EH2_fx, filtRes_fx[i], filtRes_fx[i] ); /*Q(2*qEH2) */ #endif - } - qEH2 = 2 * qEH2; - move16(); - IF(EL2_fx == 0) - { - exp2 = norm_l(EL1_fx); - L_tmp = L_shl(EL1_fx, exp2); - exp2 = 30 - exp2 - qEL1; - move16(); - tmp1 = Log2_norm_lc(L_tmp); - Ltemp = Mpy_32_16(exp2, tmp1, 9864); /*10*log(2) in Q15 format = Q0 format */ + } + qEH2 = 2 * qEH2; + move16(); + IF( EL2_fx == 0 ) + { + exp2 = norm_l( EL1_fx ); + L_tmp = L_shl( EL1_fx, exp2 ); + exp2 = 30 - exp2 - qEL1; + move16(); + tmp1 = Log2_norm_lc( L_tmp ); + Ltemp = Mpy_32_16( exp2, tmp1, 9864 ); /*10*log(2) in Q15 format = Q0 format */ #ifdef BASOP_NOGLOB tmp1 = round_fx_sat( L_shl_sat( Ltemp, 12 ) ); /* Q12 */ #else - tmp1 = round_fx(L_shl(Ltemp, 12));/* Q12 */ + tmp1 = round_fx( L_shl( Ltemp, 12 ) ); /* Q12 */ #endif - RL_fx = L_mult0(tmp1, 10); - } - ELSE - { - exp1 = norm_l(EL2_fx); - tmp1 = extract_h(L_shl(EL2_fx, exp1));/*qEL2+exp1-16 */ - tmp1 = div_s(16384, tmp1);/*14-(qEL2+exp1-16)-> 30-qEL2-exp1 */ - L_tmp = Mult_32_16(EL1_fx, tmp1);/*qEL1+30-qEL2-exp1-15=>15+qE1-qEL2-exp1 */ - - exp2 = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, exp2);/*15+qEL1-qEL2-exp1+exp2 */ - exp2 = 30 - (30 + qEL1 - qEL2 - exp1 + exp2); - move16(); - tmp1 = Log2_norm_lc(L_tmp); - Ltemp = Mpy_32_16(exp2, tmp1,9864); /*10*log(2) in Q15 format = Q0 format */ + RL_fx = L_mult0( tmp1, 10 ); + } + ELSE + { + exp1 = norm_l( EL2_fx ); + tmp1 = extract_h( L_shl( EL2_fx, exp1 ) ); /*qEL2+exp1-16 */ + tmp1 = div_s( 16384, tmp1 ); /*14-(qEL2+exp1-16)-> 30-qEL2-exp1 */ + L_tmp = Mult_32_16( EL1_fx, tmp1 ); /*qEL1+30-qEL2-exp1-15=>15+qE1-qEL2-exp1 */ + + exp2 = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, exp2 ); /*15+qEL1-qEL2-exp1+exp2 */ + exp2 = 30 - ( 30 + qEL1 - qEL2 - exp1 + exp2 ); + move16(); + tmp1 = Log2_norm_lc( L_tmp ); + Ltemp = Mpy_32_16( exp2, tmp1, 9864 ); /*10*log(2) in Q15 format = Q0 format */ #ifdef BASOP_NOGLOB tmp1 = round_fx_sat( L_shl_sat( Ltemp, 12 ) ); /* Q12 */ #else - tmp1 = round_fx(L_shl(Ltemp,12));/* Q12 */ + tmp1 = round_fx( L_shl( Ltemp, 12 ) ); /* Q12 */ #endif - RL_fx = L_mult0(tmp1, 10); - } - - IF(EH2_fx == 0) - { - exp2 = norm_l(EH2_fx); - L_tmp = L_shl(EH2_fx, exp2); - exp2 = 30 - exp2 - qEH2; - move16(); - tmp1 = Log2_norm_lc(L_tmp); - Ltemp = Mpy_32_16(exp2, tmp1, 9864); /*10*log(2) in Q13 format = Q0 format */ + RL_fx = L_mult0( tmp1, 10 ); + } + + IF( EH2_fx == 0 ) + { + exp2 = norm_l( EH2_fx ); + L_tmp = L_shl( EH2_fx, exp2 ); + exp2 = 30 - exp2 - qEH2; + move16(); + tmp1 = Log2_norm_lc( L_tmp ); + Ltemp = Mpy_32_16( exp2, tmp1, 9864 ); /*10*log(2) in Q13 format = Q0 format */ #ifdef BASOP_NOGLOB tmp1 = round_fx_sat( L_shl_sat( Ltemp, 12 ) ); /* Q12 */ #else - tmp1 = round_fx(L_shl(Ltemp, 12));/* Q12 */ + tmp1 = round_fx( L_shl( Ltemp, 12 ) ); /* Q12 */ #endif - RH_fx = L_mult0(tmp1, 10); - } - ELSE - { - exp1 = norm_l(EH2_fx); - tmp1 = extract_h(L_shl(EH2_fx, exp1));/*qEH2+exp1-16 */ - tmp1 = div_s(16384, tmp1);/*14-(qEH2+exp1-16)-> 30-qEH2-exp1 */ - L_tmp = Mult_32_16(EH1_fx, tmp1);/*15+qEH1-qEH2-exp1 */ - - exp2 = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, exp2);/*15+qEH1-qEH2-exp1+exp2 */ - exp2 = 30 - (30 + qEH1 - qEH2 - exp1 + exp2); - move16(); - tmp1 = Log2_norm_lc(L_tmp); - Ltemp = Mpy_32_16(exp2, tmp1,9864); /*10*log(2) in Q13 format = Q0 format */ + RH_fx = L_mult0( tmp1, 10 ); + } + ELSE + { + exp1 = norm_l( EH2_fx ); + tmp1 = extract_h( L_shl( EH2_fx, exp1 ) ); /*qEH2+exp1-16 */ + tmp1 = div_s( 16384, tmp1 ); /*14-(qEH2+exp1-16)-> 30-qEH2-exp1 */ + L_tmp = Mult_32_16( EH1_fx, tmp1 ); /*15+qEH1-qEH2-exp1 */ + + exp2 = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, exp2 ); /*15+qEH1-qEH2-exp1+exp2 */ + exp2 = 30 - ( 30 + qEH1 - qEH2 - exp1 + exp2 ); + move16(); + tmp1 = Log2_norm_lc( L_tmp ); + Ltemp = Mpy_32_16( exp2, tmp1, 9864 ); /*10*log(2) in Q13 format = Q0 format */ #ifdef BASOP_NOGLOB tmp1 = round_fx_sat( L_shl_sat( Ltemp, 12 ) ); /* Q12 */ #else - tmp1 = round_fx(L_shl(Ltemp,12));/* Q12 */ + tmp1 = round_fx( L_shl( Ltemp, 12 ) ); /* Q12 */ #endif - RH_fx = L_mult0(tmp1, 10); - } - - fid = 0; - move16(); - IF(LT_32(RL_fx, -12288)) /* -3 in Q12 */ - { - fid = 1; - move16(); - } - ELSE IF(LT_32(RH_fx, -12288)) /* -3 in Q12 */ - { - fid = 2; - move16(); - } - - IF(rf_flag == 0) - { - - SWITCH(fid) - { - case 1: - /* Update other filter memory */ - Scale_sig(hSC_VBR->shape3_filt_mem_fx, 10, (qGain - hSC_VBR->qprevGain_fx)); - pz_filter_sp_fx(shape3_num_coef_fx, shape3_den_coef_fx, ptr_fx, filtRes_fx, hSC_VBR->shape3_filt_mem_fx, 10, 10, L_FRAME, 1);/*1 = (16-qformat of shape1 cofficient) */ - - /* filter the residual to desired shape */ - Scale_sig(hSC_VBR->shape2_filt_mem_fx, 10, (qGain - hSC_VBR->qprevGain_fx)); - pz_filter_sp_fx(shape2_num_coef_fx, shape2_den_coef_fx, ptr_fx, ptr_tmp_fx, hSC_VBR->shape2_filt_mem_fx, 10, 10, L_FRAME, 1);/*1 = (16-qformat of shape1 cofficient) */ - Copy(ptr_tmp_fx, ptr_fx, L_FRAME); - - BREAK; - case 2: - /* Update other filter memory */ - Scale_sig(hSC_VBR->shape2_filt_mem_fx, 10, (qGain - hSC_VBR->qprevGain_fx)); - pz_filter_sp_fx(shape2_num_coef_fx, shape2_den_coef_fx, ptr_fx, filtRes_fx, hSC_VBR->shape2_filt_mem_fx, 10, 10, L_FRAME, 1);/*1 = (16-qformat of shape1 cofficient) */ - - /* filter the residual to desired shape */ - Scale_sig(hSC_VBR->shape3_filt_mem_fx, 10, (qGain - hSC_VBR->qprevGain_fx)); - pz_filter_sp_fx(shape3_num_coef_fx, shape3_den_coef_fx, ptr_fx, ptr_tmp_fx, hSC_VBR->shape3_filt_mem_fx, 10, 10, L_FRAME, 1);/*1 = (16-qformat of shape1 cofficient) */ - - Copy(ptr_tmp_fx, ptr_fx, L_FRAME); - - BREAK; - default: - Scale_sig(hSC_VBR->shape2_filt_mem_fx, 10, (qGain - hSC_VBR->qprevGain_fx)); - pz_filter_sp_fx(shape2_num_coef_fx, shape2_den_coef_fx, ptr_fx, filtRes_fx, hSC_VBR->shape2_filt_mem_fx, 10, 10, L_FRAME, 1);/*1 = (16-qformat of shape1 cofficient) */ - - Scale_sig(hSC_VBR->shape3_filt_mem_fx, 10, (qGain - hSC_VBR->qprevGain_fx)); - pz_filter_sp_fx(shape3_num_coef_fx, shape3_den_coef_fx, ptr_fx, filtRes_fx, hSC_VBR->shape3_filt_mem_fx, 10, 10, L_FRAME, 1);/*1 = (16-qformat of shape1 cofficient) */ - - BREAK; - } - - qE2 = qGain; - move16(); - - E2_fx = L_deposit_l(0); - FOR(i = 0; i < L_FRAME; i++) - { - Ltemp = L_mult0(ptr_fx[i], ptr_fx[i]); /*Q(2*qE2+1) */ - Ltemp = L_shr_r(Ltemp, 4); - E2_fx = L_add(E2_fx, Ltemp); - } - qE2 = (2 * qE2) - 4; - move16(); - test(); - IF(E3_fx == 0) - { - R_fx = 0; - move16(); - } - ELSE IF((E2_fx == 0) && (E3_fx != 0)) - { - exp1 = norm_l(E3_fx); - tmp1 = extract_h(L_shl(E3_fx, exp1));/*qE3+exp1-16 */ - tmp1 = div_s(16384, tmp1);/*14-(qE3+exp1-16)-> 30-qE3-exp1 */ - exp1 = sub(exp1, 30 - qE3); - - L_tmp = L_deposit_h(tmp1); - L_tmp = Isqrt_lc(L_tmp, &exp1); - Ltemp = L_shl(L_tmp, sub(exp1, 12)); - R_fx = round_fx(Ltemp); - } - ELSE - { - exp1 = norm_l(E3_fx); - tmp1 = extract_h(L_shl(E3_fx, exp1));/*qE3+exp1-16 */ - tmp1 = div_s(16384, tmp1);/*14-(qE3+exp1-16)-> 30-qE3-exp1 */ - L_tmp = Mult_32_16(E2_fx, tmp1);/*qE2+30-qE3-exp1-15=>15+qE2-qE3-exp1 */ - - exp2 = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, exp2);/*15+qE2-qE3-exp1+exp2 */ - exp2 = 30 - (15 + qE2 - qE3 - exp1 + exp2); - move16(); - L_tmp = Isqrt_lc(L_tmp, &exp2);/*Q(31+exp2) */ - R_fx = round_fx(L_tmp); - exp1 = 31 - exp2 - 16 - 7; - move16(); - } - - FOR(i = 0; i < L_FRAME; i++) - { - L_tmp = L_mult0(R_fx, ptr_fx[i]); - L_tmp = L_shr_r(L_tmp, exp1 + 1); - ptr_fx[i] = round_fx(L_shl(L_tmp, 16)); - } - *qIn1 = qGain - 1; - move16(); - } - - IF(EQ_16(rf_flag, 1)) - { - hRF->rf_indx_nelp_fid[0] = fid; - move16(); - } - ELSE - { - push_indice_fx(hBstr, IND_NELP_FID, fid, 2); - } - } - - hSC_VBR->qprevGain_fx = qGain; - move16(); - - IF(rf_flag == 0) - { - FOR(i = 0; i < L_FRAME; i++) - { - exc_fx[i] = ptr_fx[i]; - move16(); - } - } - - return; + RH_fx = L_mult0( tmp1, 10 ); + } + + fid = 0; + move16(); + IF( LT_32( RL_fx, -12288 ) ) /* -3 in Q12 */ + { + fid = 1; + move16(); + } + ELSE IF( LT_32( RH_fx, -12288 ) ) /* -3 in Q12 */ + { + fid = 2; + move16(); + } + + IF( rf_flag == 0 ) + { + + SWITCH( fid ) + { + case 1: + /* Update other filter memory */ + Scale_sig( hSC_VBR->shape3_filt_mem_fx, 10, ( qGain - hSC_VBR->qprevGain_fx ) ); + pz_filter_sp_fx( shape3_num_coef_fx, shape3_den_coef_fx, ptr_fx, filtRes_fx, hSC_VBR->shape3_filt_mem_fx, 10, 10, L_FRAME, 1 ); /*1 = (16-qformat of shape1 cofficient) */ + + /* filter the residual to desired shape */ + Scale_sig( hSC_VBR->shape2_filt_mem_fx, 10, ( qGain - hSC_VBR->qprevGain_fx ) ); + pz_filter_sp_fx( shape2_num_coef_fx, shape2_den_coef_fx, ptr_fx, ptr_tmp_fx, hSC_VBR->shape2_filt_mem_fx, 10, 10, L_FRAME, 1 ); /*1 = (16-qformat of shape1 cofficient) */ + Copy( ptr_tmp_fx, ptr_fx, L_FRAME ); + + BREAK; + case 2: + /* Update other filter memory */ + Scale_sig( hSC_VBR->shape2_filt_mem_fx, 10, ( qGain - hSC_VBR->qprevGain_fx ) ); + pz_filter_sp_fx( shape2_num_coef_fx, shape2_den_coef_fx, ptr_fx, filtRes_fx, hSC_VBR->shape2_filt_mem_fx, 10, 10, L_FRAME, 1 ); /*1 = (16-qformat of shape1 cofficient) */ + + /* filter the residual to desired shape */ + Scale_sig( hSC_VBR->shape3_filt_mem_fx, 10, ( qGain - hSC_VBR->qprevGain_fx ) ); + pz_filter_sp_fx( shape3_num_coef_fx, shape3_den_coef_fx, ptr_fx, ptr_tmp_fx, hSC_VBR->shape3_filt_mem_fx, 10, 10, L_FRAME, 1 ); /*1 = (16-qformat of shape1 cofficient) */ + + Copy( ptr_tmp_fx, ptr_fx, L_FRAME ); + + BREAK; + default: + Scale_sig( hSC_VBR->shape2_filt_mem_fx, 10, ( qGain - hSC_VBR->qprevGain_fx ) ); + pz_filter_sp_fx( shape2_num_coef_fx, shape2_den_coef_fx, ptr_fx, filtRes_fx, hSC_VBR->shape2_filt_mem_fx, 10, 10, L_FRAME, 1 ); /*1 = (16-qformat of shape1 cofficient) */ + + Scale_sig( hSC_VBR->shape3_filt_mem_fx, 10, ( qGain - hSC_VBR->qprevGain_fx ) ); + pz_filter_sp_fx( shape3_num_coef_fx, shape3_den_coef_fx, ptr_fx, filtRes_fx, hSC_VBR->shape3_filt_mem_fx, 10, 10, L_FRAME, 1 ); /*1 = (16-qformat of shape1 cofficient) */ + + BREAK; + } + + qE2 = qGain; + move16(); + + E2_fx = L_deposit_l( 0 ); + FOR( i = 0; i < L_FRAME; i++ ) + { + Ltemp = L_mult0( ptr_fx[i], ptr_fx[i] ); /*Q(2*qE2+1) */ + Ltemp = L_shr_r( Ltemp, 4 ); + E2_fx = L_add( E2_fx, Ltemp ); + } + qE2 = ( 2 * qE2 ) - 4; + move16(); + test(); + IF( E3_fx == 0 ) + { + R_fx = 0; + move16(); + } + ELSE IF( ( E2_fx == 0 ) && ( E3_fx != 0 ) ) + { + exp1 = norm_l( E3_fx ); + tmp1 = extract_h( L_shl( E3_fx, exp1 ) ); /*qE3+exp1-16 */ + tmp1 = div_s( 16384, tmp1 ); /*14-(qE3+exp1-16)-> 30-qE3-exp1 */ + exp1 = sub( exp1, 30 - qE3 ); + + L_tmp = L_deposit_h( tmp1 ); + L_tmp = Isqrt_lc( L_tmp, &exp1 ); + Ltemp = L_shl( L_tmp, sub( exp1, 12 ) ); + R_fx = round_fx( Ltemp ); + } + ELSE + { + exp1 = norm_l( E3_fx ); + tmp1 = extract_h( L_shl( E3_fx, exp1 ) ); /*qE3+exp1-16 */ + tmp1 = div_s( 16384, tmp1 ); /*14-(qE3+exp1-16)-> 30-qE3-exp1 */ + L_tmp = Mult_32_16( E2_fx, tmp1 ); /*qE2+30-qE3-exp1-15=>15+qE2-qE3-exp1 */ + + exp2 = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, exp2 ); /*15+qE2-qE3-exp1+exp2 */ + exp2 = 30 - ( 15 + qE2 - qE3 - exp1 + exp2 ); + move16(); + L_tmp = Isqrt_lc( L_tmp, &exp2 ); /*Q(31+exp2) */ + R_fx = round_fx( L_tmp ); + exp1 = 31 - exp2 - 16 - 7; + move16(); + } + + FOR( i = 0; i < L_FRAME; i++ ) + { + L_tmp = L_mult0( R_fx, ptr_fx[i] ); + L_tmp = L_shr_r( L_tmp, exp1 + 1 ); + ptr_fx[i] = round_fx( L_shl( L_tmp, 16 ) ); + } + *qIn1 = qGain - 1; + move16(); + } + + IF( EQ_16( rf_flag, 1 ) ) + { + hRF->rf_indx_nelp_fid[0] = fid; + move16(); + } + ELSE + { + push_indice_fx( hBstr, IND_NELP_FID, fid, 2 ); + } + } + + hSC_VBR->qprevGain_fx = qGain; + move16(); + + IF( rf_flag == 0 ) + { + FOR( i = 0; i < L_FRAME; i++ ) + { + exc_fx[i] = ptr_fx[i]; + move16(); + } + } + + return; } - - diff --git a/lib_enc/nois_est_fx.c b/lib_enc/nois_est_fx.c index 14f8468c8..da9e0f0d3 100644 --- a/lib_enc/nois_est_fx.c +++ b/lib_enc/nois_est_fx.c @@ -8,52 +8,52 @@ #include "cnst.h" #include "rom_com.h" //#include "prot_fx.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" /*-----------------------------------------------------------------* * Local constants *-----------------------------------------------------------------*/ -#define ALPHA_FX 3277 /*.1 Q15*/ -#define ALPHAM1_FX 29491 /*.9 Q15*/ +#define ALPHA_FX 3277 /*.1 Q15*/ +#define ALPHAM1_FX 29491 /*.9 Q15*/ -#define TH_PC_FX 12 /* max sum of pitch differencies */ +#define TH_PC_FX 12 /* max sum of pitch differencies */ #define BCKR_SLOW_UPDATE_SCALE_FX 3277 /*Q15 Step size for slow bckr update */ -#define COR_MIN16_FX 17039 /*.52 Q15 */ -#define COR_MAX16_FX 27853 /*.85 Q15 */ +#define COR_MIN16_FX 17039 /*.52 Q15 */ +#define COR_MAX16_FX 27853 /*.85 Q15 */ /* 10.0e5f causes problems with music - as the noise estimate starts to track the music */ -#define TH_STA16_FX (350000<<10) /* MODE1: 3.5e5f */ +#define TH_STA16_FX ( 350000 << 10 ) /* MODE1: 3.5e5f */ -#define TH_EPS16_FX 3277 /* Q11 (1.6) tuned for speech only, not for music */ -#define K_16_FX 25690 /* Q20 (0.0245f) */ -#define C_16_FX -1925 /* Q13 (-0.235f) */ -#define ALPHA_MAX16_FX 32440 /* Q15 (0.99) */ +#define TH_EPS16_FX 3277 /* Q11 (1.6) tuned for speech only, not for music */ +#define K_16_FX 25690 /* Q20 (0.0245f) */ +#define C_16_FX -1925 /* Q13 (-0.235f) */ +#define ALPHA_MAX16_FX 32440 /* Q15 (0.99) */ -#define COR_MIN8_FX 21299 /*.65 Q15 */ -#define COR_MAX8_FX 22938 /*.70 Q15 */ -#define TH_EPS8_FX 21299 /* 10.4 in Q11 Thresholds for NB processing - ... */ -#define TH_STA8_FX (500000<<10) -#define K_8_FX 9452 /* Q20 (0.0091f) */ -#define C_8_FX 2609 /* Q13 (0.0091f) */ -#define ALPHA_MAX8_FX 32735 /* Q15 (0.999) */ +#define COR_MIN8_FX 21299 /*.65 Q15 */ +#define COR_MAX8_FX 22938 /*.70 Q15 */ +#define TH_EPS8_FX 21299 /* 10.4 in Q11 Thresholds for NB processing - ... */ +#define TH_STA8_FX ( 500000 << 10 ) +#define K_8_FX 9452 /* Q20 (0.0091f) */ +#define C_8_FX 2609 /* Q13 (0.0091f) */ +#define ALPHA_MAX8_FX 32735 /* Q15 (0.999) */ -#define HC_CNT_SLOW_FX 80 /* limit for harm corr count slow */ +#define HC_CNT_SLOW_FX 80 /* limit for harm corr count slow */ #define HE_LT_CNT_PRE_FX 50 #define HE_LT_CNT_INIT_FX 150 #define HE_LT_CNT_PRE_SHORT_FX 250 #define HE_LT_CNT_FX 30 -#define LN_E_MIN_PLUS_ONE_FX 1 /* max(1, ln(E_MIN+1.0)) = max(1,ln(0.0035f+1f)) in Q8 */ -#define COR_MAX_NNE_FX 27853 /* 0.85 Q15 */ +#define LN_E_MIN_PLUS_ONE_FX 1 /* max(1, ln(E_MIN+1.0)) = max(1,ln(0.0035f+1f)) in Q8 */ +#define COR_MAX_NNE_FX 27853 /* 0.85 Q15 */ -#define HE_LT_THR1_FX 2560 /*10.0 Q8*/ -#define HE_LT_THR2_FX 7680 /*30.0 Q8*/ +#define HE_LT_THR1_FX 2560 /*10.0 Q8*/ +#define HE_LT_THR2_FX 7680 /*30.0 Q8*/ /*-----------------------------------------------------------------* * noise_est_AR1_Qx() @@ -61,17 +61,17 @@ * y(n)(Qx) = alpha(Q15) * x(Qx) + (1.0f-alpha)* y(n-1) (Qx) *-----------------------------------------------------------------*/ -Word16 noise_est_AR1_Qx( /* o : Qx y(n) */ - Word16 x, /* i : Qx x(n) */ - Word16 y, /* i : Qx y(n-1) */ - Word16 alpha /*i : Q15 scaling of driving x(n) */ +Word16 noise_est_AR1_Qx( /* o : Qx y(n) */ + Word16 x, /* i : Qx x(n) */ + Word16 y, /* i : Qx y(n-1) */ + Word16 alpha /*i : Q15 scaling of driving x(n) */ ) { Word16 alpham1; /*alpham1 = negate(add((Word16)-32768, alpha)); */ - alpham1 = sub(32767, alpha); /* one cycle less */ + alpham1 = sub( 32767, alpha ); /* one cycle less */ - return mac_r(L_mult(y, alpham1), x, alpha); + return mac_r( L_mult( y, alpham1 ), x, alpha ); } /*-----------------------------------------------------------------* @@ -80,9 +80,9 @@ Word16 noise_est_AR1_Qx( /* o : Qx y(n) */ * q8 = (float)log( L_enr[i] + add1po*1.0 ); *-----------------------------------------------------------------*/ -static Word16 noise_est_ln_q8_fx( +static Word16 noise_est_ln_q8_fx( Word32 L_enr, - Word16 flag_add1p0, /* flag to add 1.0 */ + Word16 flag_add1p0, /* flag to add 1.0 */ Word16 q_new_plus_q_scale ) { Word16 e_ener, f_ener; @@ -92,22 +92,22 @@ static Word16 noise_est_ln_q8_fx( #endif #ifdef BASOP_NOGLOB - L_tmp = L_add_o(L_enr, L_shl((Word32)1L, q_new_plus_q_scale), &Overflow); /* +1.0f */ -#else /* BASOP_NOGLOB */ - L_tmp = L_add(L_enr, L_shl((Word32)1L, q_new_plus_q_scale)); /* +1.0f */ -#endif /* BASOP_NOGLOB */ - if( flag_add1p0 == 0 ) + L_tmp = L_add_o( L_enr, L_shl( (Word32) 1L, q_new_plus_q_scale ), &Overflow ); /* +1.0f */ +#else /* BASOP_NOGLOB */ + L_tmp = L_add( L_enr, L_shl( (Word32) 1L, q_new_plus_q_scale ) ); /* +1.0f */ +#endif /* BASOP_NOGLOB */ + if ( flag_add1p0 == 0 ) { - L_tmp = L_add(L_enr, 0); /* +0 , no offset */ + L_tmp = L_add( L_enr, 0 ); /* +0 , no offset */ } - L_tmp = L_max(L_tmp,(Word32)1L); /* make sure log2_norm_lc does not cause table reading out of bounds */ + L_tmp = L_max( L_tmp, (Word32) 1L ); /* make sure log2_norm_lc does not cause table reading out of bounds */ - e_ener = norm_l(L_tmp); - f_ener = Log2_norm_lc(L_shl(L_tmp, e_ener)); - e_ener = sub(sub(30,e_ener),q_new_plus_q_scale); - L_tmp = Mpy_32_16(e_ener, f_ener, 22713); /* Q16 (22713 = Ln(2) in Q15)*/ - return round_fx(L_shl(L_tmp, 8)); /* Q8 */ + e_ener = norm_l( L_tmp ); + f_ener = Log2_norm_lc( L_shl( L_tmp, e_ener ) ); + e_ener = sub( sub( 30, e_ener ), q_new_plus_q_scale ); + L_tmp = Mpy_32_16( e_ener, f_ener, 22713 ); /* Q16 (22713 = Ln(2) in Q15)*/ + return round_fx( L_shl( L_tmp, 8 ) ); /* Q8 */ } /*-----------------------------------------------------------------* @@ -116,12 +116,12 @@ static Word16 noise_est_ln_q8_fx( * *-----------------------------------------------------------------*/ -static Word32 eps_quota_fx( /* o: eps_num/eps_den in q_out */ - Word16 eps_num_h, /* num high ,*/ - Word16 eps_num_l, /* num low (signed) ,*/ - Word16 eps_den_h, /* den low */ - Word16 eps_den_l, /* den low (signed),*/ - Word16 q_out /* range 15...0 , tested with 11 and 12 */ +static Word32 eps_quota_fx( /* o: eps_num/eps_den in q_out */ + Word16 eps_num_h, /* num high ,*/ + Word16 eps_num_l, /* num low (signed) ,*/ + Word16 eps_den_h, /* den low */ + Word16 eps_den_l, /* den low (signed),*/ + Word16 q_out /* range 15...0 , tested with 11 and 12 */ ) { Word32 L_tmp_num, L_tmp_den; @@ -130,30 +130,30 @@ static Word32 eps_quota_fx( /* o: eps_num/eps_den in q_out */ Word16 num_shift; - L_tmp_num = L_Comp(eps_num_h, eps_num_l); - L_tmp_den = L_Comp(eps_den_h, eps_den_l); + L_tmp_num = L_Comp( eps_num_h, eps_num_l ); + L_tmp_den = L_Comp( eps_den_h, eps_den_l ); - exp_num = sub(norm_l(L_tmp_num), 1); /* make sure m_ num is lower than m_den */ - m_num = extract_h(L_shl(L_tmp_num, exp_num)); - exp_den = norm_l(L_tmp_den); - m_den = extract_h(L_shl(L_tmp_den, exp_den)); + exp_num = sub( norm_l( L_tmp_num ), 1 ); /* make sure m_ num is lower than m_den */ + m_num = extract_h( L_shl( L_tmp_num, exp_num ) ); + exp_den = norm_l( L_tmp_den ); + m_den = extract_h( L_shl( L_tmp_den, exp_den ) ); - exp_num = sub(exp_num, exp_den); - if (m_den != 0) + exp_num = sub( exp_num, exp_den ); + if ( m_den != 0 ) { - assert(m_den >= m_num); - m_num = div_s(m_num, m_den); /* single basop */ + assert( m_den >= m_num ); + m_num = div_s( m_num, m_den ); /* single basop */ } - num_shift = add(15-q_out, exp_num); - if (m_den == 0) + num_shift = add( 15 - q_out, exp_num ); + if ( m_den == 0 ) { /* no division made due to zero denominator */ m_num = 0; move16(); } - return L_shr(m_num, num_shift); + return L_shr( m_num, num_shift ); } /*-----------------------------------------------------------------* @@ -167,12 +167,12 @@ void noise_est_init_fx( { Word16 i; - FOR(i = 0; i < NB_BANDS; i++) + FOR( i = 0; i < NB_BANDS; i++ ) { hNoiseEst->fr_bands1_fx[i] = 1; - move32();/*1e-5f; */ + move32(); /*1e-5f; */ hNoiseEst->fr_bands2_fx[i] = 1; - move32();/*1e-5f; */ + move32(); /*1e-5f; */ hNoiseEst->ave_enr2_fx[i] = E_MIN_FX; move32(); /*Q7//E_MIN; */ hNoiseEst->enrO_fx[i] = E_MIN_FX; @@ -186,11 +186,11 @@ void noise_est_init_fx( hNoiseEst->totalNoise_fx = 0; move16(); hNoiseEst->first_noise_updt = 0; - //hNoiseEst->first_noise_updt_cnt_fx = 0; IVAS_CODE ?? + // hNoiseEst->first_noise_updt_cnt_fx = 0; IVAS_CODE ?? move16(); hNoiseEst->aEn = 6; - //hNoiseEst->aEn_inac_cnt = 0; IVAS_CODE + // hNoiseEst->aEn_inac_cnt = 0; IVAS_CODE move16(); hNoiseEst->harm_cor_cnt = 0; @@ -198,20 +198,23 @@ void noise_est_init_fx( hNoiseEst->bg_cnt = 0; move16(); - hNoiseEst->lt_tn_track_fx = 6554; /*.20 in Q15*/ move16(); + hNoiseEst->lt_tn_track_fx = 6554; /*.20 in Q15*/ + move16(); hNoiseEst->lt_tn_dist_fx = 0; move16(); hNoiseEst->lt_Ellp_dist_fx = 0; move16(); - hNoiseEst->lt_haco_ev_fx = 13107; /*.40 in Q15*/ move16(); + hNoiseEst->lt_haco_ev_fx = 13107; /*.40 in Q15*/ + move16(); hNoiseEst->low_tn_track_cnt = 0; move16(); - hNoiseEst->Etot_st_est_fx = 5120; /* 20.0f in Q8 */ - hNoiseEst->Etot_sq_st_est_fx = 1600; /* 400 in Q2 */ -//### + hNoiseEst->Etot_st_est_fx = 5120; /* 20.0f in Q8 */ + hNoiseEst->Etot_sq_st_est_fx = 1600; /* 400 in Q2 */ + //### - hNoiseEst->epsP_0_2_lp_fx = 4096; /*1.0 Q12*/ move16(); + hNoiseEst->epsP_0_2_lp_fx = 4096; /*1.0 Q12*/ + move16(); hNoiseEst->epsP_0_2_ad_lp_fx = 0; move16(); hNoiseEst->epsP_2_16_lp_fx = 4096; @@ -224,12 +227,12 @@ void noise_est_init_fx( move16(); /* Tonal detector */ - FOR(i = 0; i < L_FFT / 2; i++) + FOR( i = 0; i < L_FFT / 2; i++ ) { hNoiseEst->old_S_fx[i] = 1; move16(); } - set16_fx(hNoiseEst->cor_map_fx, 0, L_FFT / 2); + set16_fx( hNoiseEst->cor_map_fx, 0, L_FFT / 2 ); hNoiseEst->act_pred_fx = 32767; move16(); hNoiseEst->noise_char_fx = 0; @@ -243,11 +246,15 @@ void noise_est_init_fx( hNoiseEst->Etot_last_fx = 0; hNoiseEst->Etot_v_h2_fx = 0; hNoiseEst->sign_dyn_lp_fx = 0; - move16(); move16(); move16();move16(); - move16();move16();move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); return; - } /*-----------------------------------------------------------------* * noise_est_pre_fx() @@ -266,7 +273,7 @@ void noise_est_pre_fx( { Word16 tmp; - IF(LE_16(ini_frame_fx, 1) || (EQ_16(idchan, 1) && EQ_16(element_mode, IVAS_CPE_TD) && EQ_16(last_element_mode, IVAS_CPE_DFT))) + IF( LE_16( ini_frame_fx, 1 ) || ( EQ_16( idchan, 1 ) && EQ_16( element_mode, IVAS_CPE_TD ) && EQ_16( last_element_mode, IVAS_CPE_DFT ) ) ) { hNoiseEst->Etot_h_fx = Etot; move16(); @@ -286,56 +293,53 @@ void noise_est_pre_fx( ELSE { /* *Etot_lp = 0.20f*Etot + 0.80f* *Etot_lp; */ - hNoiseEst->Etot_lp_fx = mac_r(L_mult(6554, Etot), 26214, hNoiseEst->Etot_lp_fx); + hNoiseEst->Etot_lp_fx = mac_r( L_mult( 6554, Etot ), 26214, hNoiseEst->Etot_lp_fx ); move16(); - hNoiseEst->Etot_h_fx = sub(hNoiseEst->Etot_h_fx, 10); - move16(); /* 10=0.04 in Q8 */ - hNoiseEst->Etot_h_fx = s_max(hNoiseEst->Etot_h_fx, Etot); + hNoiseEst->Etot_h_fx = sub( hNoiseEst->Etot_h_fx, 10 ); + move16(); /* 10=0.04 in Q8 */ + hNoiseEst->Etot_h_fx = s_max( hNoiseEst->Etot_h_fx, Etot ); move16(); - hNoiseEst->Etot_l_fx = add(hNoiseEst->Etot_l_fx, 20); + hNoiseEst->Etot_l_fx = add( hNoiseEst->Etot_l_fx, 20 ); move16(); /* 20 = .08 in Q8 */ /* Could even be higher but it also delays first entry to DTX */ - IF(GT_16(hNoiseEst->harm_cor_cnt,HE_LT_CNT_PRE_FX)) + IF( GT_16( hNoiseEst->harm_cor_cnt, HE_LT_CNT_PRE_FX ) ) { test(); - IF((LT_16(ini_frame_fx , s_min(HE_LT_CNT_INIT_FX ,MAX_FRAME_COUNTER - 1))) - && (LT_16(sub(hNoiseEst->Etot_h_fx, hNoiseEst->Etot_lp_fx),(Word16)3 * 256)) /* 3.0 Q8 */ - ) + IF( ( LT_16( ini_frame_fx, s_min( HE_LT_CNT_INIT_FX, MAX_FRAME_COUNTER - 1 ) ) ) && ( LT_16( sub( hNoiseEst->Etot_h_fx, hNoiseEst->Etot_lp_fx ), (Word16) 3 * 256 ) ) /* 3.0 Q8 */ + ) { /* *Etot_l += min(2,(*Etot_last-*Etot_l)*0.1f); */ - tmp = mult_r(sub(hNoiseEst->Etot_last_fx, hNoiseEst->Etot_l_fx), 3277); /* factor in Q15 3277 .1*32768 */ - tmp = s_min(512, tmp); /* 2.0 in Q8 is 512*/ - hNoiseEst->Etot_l_fx = add(hNoiseEst->Etot_l_fx, tmp); - move16();/* Q8 */ + tmp = mult_r( sub( hNoiseEst->Etot_last_fx, hNoiseEst->Etot_l_fx ), 3277 ); /* factor in Q15 3277 .1*32768 */ + tmp = s_min( 512, tmp ); /* 2.0 in Q8 is 512*/ + hNoiseEst->Etot_l_fx = add( hNoiseEst->Etot_l_fx, tmp ); + move16(); /* Q8 */ } /* Avoids large steps in short active segments */ test(); - IF((GT_16(sub(hNoiseEst->Etot_last_fx, hNoiseEst->Etot_l_fx), HE_LT_THR2_FX)) /* 30.0f*Q8 */ - && (GT_16(hNoiseEst->harm_cor_cnt,HE_LT_CNT_PRE_SHORT_FX)) - ) + IF( ( GT_16( sub( hNoiseEst->Etot_last_fx, hNoiseEst->Etot_l_fx ), HE_LT_THR2_FX ) ) /* 30.0f*Q8 */ + && ( GT_16( hNoiseEst->harm_cor_cnt, HE_LT_CNT_PRE_SHORT_FX ) ) ) { /* *Etot_l += (*Etot_last-*Etot_l)*0.02f; */ - hNoiseEst->Etot_l_fx = add(hNoiseEst->Etot_l_fx, mult_r(sub(hNoiseEst->Etot_last_fx, hNoiseEst->Etot_l_fx), 655)); - move16();/* 0.02 = 655 Q8*/ + hNoiseEst->Etot_l_fx = add( hNoiseEst->Etot_l_fx, mult_r( sub( hNoiseEst->Etot_last_fx, hNoiseEst->Etot_l_fx ), 655 ) ); + move16(); /* 0.02 = 655 Q8*/ } - ELSE IF(GT_16(sub(hNoiseEst->Etot_last_fx, hNoiseEst->Etot_l_fx), HE_LT_THR1_FX)) /* 10.0 in Q8*/ + ELSE IF( GT_16( sub( hNoiseEst->Etot_last_fx, hNoiseEst->Etot_l_fx ), HE_LT_THR1_FX ) ) /* 10.0 in Q8*/ { - hNoiseEst->Etot_l_fx = add(hNoiseEst->Etot_l_fx, 20); - move16();/* 0.08 is 20 in Q8*/ + hNoiseEst->Etot_l_fx = add( hNoiseEst->Etot_l_fx, 20 ); + move16(); /* 0.08 is 20 in Q8*/ } - } - hNoiseEst->Etot_l_fx = s_min(hNoiseEst->Etot_l_fx, Etot); + hNoiseEst->Etot_l_fx = s_min( hNoiseEst->Etot_l_fx, Etot ); - IF(LT_16(ini_frame_fx,100) && LT_16(hNoiseEst->Etot_l_fx,hNoiseEst->Etot_l_lp_fx)) + IF( LT_16( ini_frame_fx, 100 ) && LT_16( hNoiseEst->Etot_l_fx, hNoiseEst->Etot_l_lp_fx ) ) { /**Etot_l_lp = 0.1f * *Etot_l + (1.0f - 0.1) * *Etot_l_lp; */ - hNoiseEst->Etot_l_lp_fx = mac_r(L_mult(3277, hNoiseEst->Etot_l_fx), 29491, hNoiseEst->Etot_l_lp_fx); + hNoiseEst->Etot_l_lp_fx = mac_r( L_mult( 3277, hNoiseEst->Etot_l_fx ), 29491, hNoiseEst->Etot_l_lp_fx ); move16(); } ELSE @@ -344,26 +348,20 @@ void noise_est_pre_fx( test(); test(); test(); - IF(((GT_16(hNoiseEst->harm_cor_cnt, HE_LT_CNT_FX)) - && (GT_16(sub(hNoiseEst->Etot_last_fx, hNoiseEst->Etot_l_fx), HE_LT_THR2_FX)) - ) - || ((sub(hNoiseEst->harm_cor_cnt, HE_LT_CNT_FX) > 0) && (LT_16(ini_frame_fx, HE_LT_CNT_INIT_FX))) - || (GT_16(sub(hNoiseEst->Etot_l_lp_fx, hNoiseEst->Etot_l_fx), HE_LT_THR2_FX)) - ) + IF( ( ( GT_16( hNoiseEst->harm_cor_cnt, HE_LT_CNT_FX ) ) && ( GT_16( sub( hNoiseEst->Etot_last_fx, hNoiseEst->Etot_l_fx ), HE_LT_THR2_FX ) ) ) || ( ( sub( hNoiseEst->harm_cor_cnt, HE_LT_CNT_FX ) > 0 ) && ( LT_16( ini_frame_fx, HE_LT_CNT_INIT_FX ) ) ) || ( GT_16( sub( hNoiseEst->Etot_l_lp_fx, hNoiseEst->Etot_l_fx ), HE_LT_THR2_FX ) ) ) { /**Etot_l_lp = 0.03f * *Etot_l + (1.0f - 0.03f) * *Etot_l_lp; */ - hNoiseEst->Etot_l_lp_fx = mac_r(L_mult(983, hNoiseEst->Etot_l_fx), 31785, hNoiseEst->Etot_l_lp_fx); + hNoiseEst->Etot_l_lp_fx = mac_r( L_mult( 983, hNoiseEst->Etot_l_fx ), 31785, hNoiseEst->Etot_l_lp_fx ); move16(); - } ELSE { /* *Etot_l_lp = 0.02f * *Etot_l + (1.0f - 0.02f) * *Etot_l_lp; */ - hNoiseEst->Etot_l_lp_fx = round_fx(L_mac(L_mult(655 , hNoiseEst->Etot_l_fx), 32113 , hNoiseEst->Etot_l_lp_fx)); + hNoiseEst->Etot_l_lp_fx = round_fx( L_mac( L_mult( 655, hNoiseEst->Etot_l_fx ), 32113, hNoiseEst->Etot_l_lp_fx ) ); } } - /**sign_dyn_lp = 0.1f * (*Etot_h - *Etot_l) + (1.0f - 0.1f) * *sign_dyn_lp;*/ - hNoiseEst->sign_dyn_lp_fx = round_fx(L_mac(L_mult(3277, sub(hNoiseEst->Etot_h_fx, hNoiseEst->Etot_l_fx)), 29491, hNoiseEst->sign_dyn_lp_fx)); + /**sign_dyn_lp = 0.1f * (*Etot_h - *Etot_l) + (1.0f - 0.1f) * *sign_dyn_lp;*/ + hNoiseEst->sign_dyn_lp_fx = round_fx( L_mac( L_mult( 3277, sub( hNoiseEst->Etot_h_fx, hNoiseEst->Etot_l_fx ) ), 29491, hNoiseEst->sign_dyn_lp_fx ) ); } return; @@ -399,22 +397,22 @@ void noise_est_pre_fx( void noise_est_down_fx( - const Word32 fr_bands[], /* i : per band input energy (contains 2 vectors) */ - Word32 bckr[], /* i/o: per band background noise energy estimate */ - Word32 tmpN[], /* o : temporary noise update */ - Word32 enr[], /* o : averaged energy over both subframes */ - const Word16 min_band, /* i : minimum critical band */ - const Word16 max_band, /* i : maximum critical band */ - Word16 *totalNoise, /* o : noise estimate over all critical bands */ - Word16 Etot, /* i : Energy of current frame */ - Word16 *Etot_last, /* i/o: Energy of last frame Q8 */ - Word16 *Etot_v_h2, /* i/o: Energy variations of noise frames Q8 */ + const Word32 fr_bands[], /* i : per band input energy (contains 2 vectors) */ + Word32 bckr[], /* i/o: per band background noise energy estimate */ + Word32 tmpN[], /* o : temporary noise update */ + Word32 enr[], /* o : averaged energy over both subframes */ + const Word16 min_band, /* i : minimum critical band */ + const Word16 max_band, /* i : maximum critical band */ + Word16 *totalNoise, /* o : noise estimate over all critical bands */ + Word16 Etot, /* i : Energy of current frame */ + Word16 *Etot_last, /* i/o: Energy of last frame Q8 */ + Word16 *Etot_v_h2, /* i/o: Energy variations of noise frames Q8 */ Word16 Q_new, - const Word32 e_min /* i : minimum energy scaled Q_new + QSCALE */ + const Word32 e_min /* i : minimum energy scaled Q_new + QSCALE */ ) { - Word32 Ltmp, L_tmp; + Word32 Ltmp, L_tmp; const Word32 *pt1, *pt2; Word16 i; Word16 e_Noise, f_Noise; @@ -425,55 +423,55 @@ void noise_est_down_fx( Flag Overflow = 0; #endif - L_Etot = L_shl(Etot, 16); /*Q24 for later AR1 computations*/ - L_Etot_last = L_shl(*Etot_last, 16); - L_Etot_v_h2 = L_shl(*Etot_v_h2, 16); - scale = add(Q_new,QSCALE); + L_Etot = L_shl( Etot, 16 ); /*Q24 for later AR1 computations*/ + L_Etot_last = L_shl( *Etot_last, 16 ); + L_Etot_v_h2 = L_shl( *Etot_v_h2, 16 ); + scale = add( Q_new, QSCALE ); move16(); /*-----------------------------------------------------------------* * Estimate total noise energy *-----------------------------------------------------------------*/ - totalNoise_temp = L_deposit_l(0); - FOR (i = min_band; i <= max_band; i++) + totalNoise_temp = L_deposit_l( 0 ); + FOR( i = min_band; i <= max_band; i++ ) { #ifdef BASOP_NOGLOB - totalNoise_temp = L_add_o(totalNoise_temp, bckr[i], &Overflow); /*Q_new+QSCALE*/ + totalNoise_temp = L_add_o( totalNoise_temp, bckr[i], &Overflow ); /*Q_new+QSCALE*/ #else - totalNoise_temp = L_add(totalNoise_temp, bckr[i]); /*Q_new+QSCALE*/ + totalNoise_temp = L_add( totalNoise_temp, bckr[i] ); /*Q_new+QSCALE*/ #endif } - totalNoise_temp = L_max(totalNoise_temp,L_shl(e_min,4)); + totalNoise_temp = L_max( totalNoise_temp, L_shl( e_min, 4 ) ); - totalNoise_temp = L_max(totalNoise_temp,(Word32)1L); /* make sure log2_norm_lc does not cause table reading out of bounds */ + totalNoise_temp = L_max( totalNoise_temp, (Word32) 1L ); /* make sure log2_norm_lc does not cause table reading out of bounds */ /*totalNoise = 10.0f * (float)log10( *totalNoise );*/ - e_Noise = norm_l(totalNoise_temp); - f_Noise = Log2_norm_lc(L_shl(totalNoise_temp, e_Noise)); - e_Noise = sub(30, e_Noise); - e_Noise = sub(e_Noise, scale); - Ltmp = Mpy_32_16(e_Noise, f_Noise, LG10); - *totalNoise = round_fx(L_shl(Ltmp, 10)); /*Q8*/ + e_Noise = norm_l( totalNoise_temp ); + f_Noise = Log2_norm_lc( L_shl( totalNoise_temp, e_Noise ) ); + e_Noise = sub( 30, e_Noise ); + e_Noise = sub( e_Noise, scale ); + Ltmp = Mpy_32_16( e_Noise, f_Noise, LG10 ); + *totalNoise = round_fx( L_shl( Ltmp, 10 ) ); /*Q8*/ /*-----------------------------------------------------------------* * Average energy per frame for each frequency band *-----------------------------------------------------------------*/ - pt1 = fr_bands; /*Q_new+QSCALE*/ + pt1 = fr_bands; /*Q_new+QSCALE*/ pt2 = fr_bands + NB_BANDS; - FOR( i=0 ; i < NB_BANDS; i++ ) + FOR( i = 0; i < NB_BANDS; i++ ) { #ifdef BASOP_NOGLOB - Ltmp = L_add_o(L_shr_r(*pt1,1),L_shr_r(*pt2,1), &Overflow); -#else /* BASOP_NOGLOB */ - Ltmp = L_add(L_shr_r(*pt1,1),L_shr_r(*pt2,1)); + Ltmp = L_add_o( L_shr_r( *pt1, 1 ), L_shr_r( *pt2, 1 ), &Overflow ); +#else /* BASOP_NOGLOB */ + Ltmp = L_add( L_shr_r( *pt1, 1 ), L_shr_r( *pt2, 1 ) ); #endif /* BASOP_NOGLOB */ /*Ltmp = L_shr_r(L_add(*pt1,*pt2),1);*/ enr[i] = Ltmp; - move32();/*Q_new+QSCALE*/ + move32(); /*Q_new+QSCALE*/ pt1++; pt2++; } @@ -482,123 +480,123 @@ void noise_est_down_fx( * Background noise energy update *-----------------------------------------------------------------*/ - FOR( i=0; i< NB_BANDS; i++ ) + FOR( i = 0; i < NB_BANDS; i++ ) { /* tmpN[i] = (1-ALPHA) * bckr[i] + ALPHA * enr[i]; */ - L_tmp = Mult_32_16(enr[i], ALPHA_FX); /*ALPHA * enr2*/ - tmpN[i] = Madd_32_16(L_tmp, bckr[i], ALPHAM1_FX); - move32();/*Q_new+QSCALE*/ - tmpN[i] =L_max( tmpN[i] , e_min); /* handle div by zero in find_tilt_fx */ + L_tmp = Mult_32_16( enr[i], ALPHA_FX ); /*ALPHA * enr2*/ + tmpN[i] = Madd_32_16( L_tmp, bckr[i], ALPHAM1_FX ); + move32(); /*Q_new+QSCALE*/ + tmpN[i] = L_max( tmpN[i], e_min ); /* handle div by zero in find_tilt_fx */ /* if( tmpN[i] < bckr[i] ) { bckr[i] = tmpN[i]; }*/ /* Defend to increase noise estimate: keep as it is or decrease */ - bckr[i] = L_max(L_min(bckr[i], tmpN[i]), e_min); - move32();/*Q_new+QSCALE*/ + bckr[i] = L_max( L_min( bckr[i], tmpN[i] ), e_min ); + move32(); /*Q_new+QSCALE*/ } /*------------------------------------------------------------------* * Energy variation update *------------------------------------------------------------------*/ /*Etot_v = (float) fabs(*Etot_last - Etot);*/ - L_Etot_v = L_abs(L_sub(L_Etot_last, L_Etot)); /* Q24 */ + L_Etot_v = L_abs( L_sub( L_Etot_last, L_Etot ) ); /* Q24 */ /* *Etot_v_h2 = (1.0f-0.02f) * *Etot_v_h2 + 0.02f * min(3.0f, Etot_v); */ - L_Etot_v_h2 = Mult_32_16(L_Etot_v_h2, 32113); /*.98 in Q15 , Q24+Q15+1 -16 => Q24 */ - L_Etot_v = L_min((Word32)(3*(1<<24)), L_Etot_v); - L_tmp = Mult_32_16(L_Etot_v, 655); /*.02 in Q15 , Q24+Q15+1 -16 ==> Q24 ) */ + L_Etot_v_h2 = Mult_32_16( L_Etot_v_h2, 32113 ); /*.98 in Q15 , Q24+Q15+1 -16 => Q24 */ + L_Etot_v = L_min( (Word32) ( 3 * ( 1 << 24 ) ), L_Etot_v ); + L_tmp = Mult_32_16( L_Etot_v, 655 ); /*.02 in Q15 , Q24+Q15+1 -16 ==> Q24 ) */ - *Etot_v_h2 = round_fx(L_add(L_Etot_v_h2, L_tmp)); /*Q24->Q8*/ + *Etot_v_h2 = round_fx( L_add( L_Etot_v_h2, L_tmp ) ); /*Q24->Q8*/ /* if (*Etot_v_h2 < 0.1f) { *Etot_v_h2 = 0.1f; } */ - *Etot_v_h2 = s_max(*Etot_v_h2, 26 ); /* 0.1 in Q8*/ + *Etot_v_h2 = s_max( *Etot_v_h2, 26 ); /* 0.1 in Q8*/ return; } /*-----------------------------------------------------------------* -* noise_est_fx() -* -* Noise energy estimation (noise energy is updated in case of noise-only frame) -*-----------------------------------------------------------------*/ -void noise_est_fx( - Encoder_State *st_fx, /* i/o: state structure */ - const Word16 old_pitch1, /* i : previous frame OL pitch[1] */ - const Word32 tmpN[], /* i : temporary noise update Q_new + QSCALE */ - const Word16 epsP_h[], /* i : msb prediction error energies Q_r-1 */ - const Word16 epsP_l[], /* i : msb prediction error energies Q_r-1 */ - const Word16 Etot, /* i : total channel E (see find_enr_fx.c) Q8 */ - const Word16 relE, /* i : (VA_CHECK addition) relative frame energy Q8? */ - const Word16 corr_shift, /* i : normalized correlation correction Q15 */ - const Word32 enr[], /* i : averaged energy over both subframes Q_new + Q_SCALE */ - Word32 fr_bands[], /* i : spectrum per critical bands of the current frame Q_new + Q_SCALE */ - Word16 *cor_map_sum, /* o : Q8 */ - Word16* ncharX, /* o : IVAS_CODE -> size of ncharX needs validation noise character for sp/mus classifier Qx? */ - Word16 *sp_div, /* o : Q_sp_div */ - Word16 *Q_sp_div, /* o : Q factor for sp_div */ - Word16 *non_staX, /* o : non-stationarity for sp/mus classifier */ - Word16 *loc_harm , /* o : multi-harmonicity flag for UV classifier */ - const Word32 *lf_E, /* i : per bin energy for low frequencies Q_new + Q_SCALE -2 */ - Word16 *st_harm_cor_cnt, /* i/o : 1st harm correlation timer Q0 */ - const Word16 Etot_l_lp, /* i : Smoothed low energy Q8 */ - const Word16 Etot_v_h2, /* i : Energy variations Q8 */ - Word16 *bg_cnt, /* i : Background burst length timer Q0 */ - Word16 EspecdB[], /* i/o: log E spectrum (with f=0) of the current frame Q7 for multi harm */ - Word16 Q_new, /* i : SCaling of current frame */ - const Word32 Le_min_scaled, /*i : Minimum energy value in Q_new + Q_SCALE */ - Word16 *sp_floor, /* o : noise floor estimate Q7 */ - Word16 S_map[], /* o : short-term correlation map Q7 */ + * noise_est_fx() + * + * Noise energy estimation (noise energy is updated in case of noise-only frame) + *-----------------------------------------------------------------*/ +void noise_est_fx( + Encoder_State *st_fx, /* i/o: state structure */ + const Word16 old_pitch1, /* i : previous frame OL pitch[1] */ + const Word32 tmpN[], /* i : temporary noise update Q_new + QSCALE */ + const Word16 epsP_h[], /* i : msb prediction error energies Q_r-1 */ + const Word16 epsP_l[], /* i : msb prediction error energies Q_r-1 */ + const Word16 Etot, /* i : total channel E (see find_enr_fx.c) Q8 */ + const Word16 relE, /* i : (VA_CHECK addition) relative frame energy Q8? */ + const Word16 corr_shift, /* i : normalized correlation correction Q15 */ + const Word32 enr[], /* i : averaged energy over both subframes Q_new + Q_SCALE */ + Word32 fr_bands[], /* i : spectrum per critical bands of the current frame Q_new + Q_SCALE */ + Word16 *cor_map_sum, /* o : Q8 */ + Word16 *ncharX, /* o : IVAS_CODE -> size of ncharX needs validation noise character for sp/mus classifier Qx? */ + Word16 *sp_div, /* o : Q_sp_div */ + Word16 *Q_sp_div, /* o : Q factor for sp_div */ + Word16 *non_staX, /* o : non-stationarity for sp/mus classifier */ + Word16 *loc_harm, /* o : multi-harmonicity flag for UV classifier */ + const Word32 *lf_E, /* i : per bin energy for low frequencies Q_new + Q_SCALE -2 */ + Word16 *st_harm_cor_cnt, /* i/o : 1st harm correlation timer Q0 */ + const Word16 Etot_l_lp, /* i : Smoothed low energy Q8 */ + const Word16 Etot_v_h2, /* i : Energy variations Q8 */ + Word16 *bg_cnt, /* i : Background burst length timer Q0 */ + Word16 EspecdB[], /* i/o: log E spectrum (with f=0) of the current frame Q7 for multi harm */ + Word16 Q_new, /* i : SCaling of current frame */ + const Word32 Le_min_scaled, /*i : Minimum energy value in Q_new + Q_SCALE */ + Word16 *sp_floor, /* o : noise floor estimate Q7 */ + Word16 S_map[], /* o : short-term correlation map Q7 */ #ifdef IVAS_CODE STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure */ FRONT_VAD_ENC_HANDLE hFrontVad, /* i/o: front-VAD handle */ #endif - const Word16 ini_frame /* i : Frame number (init) */ + const Word16 ini_frame /* i : Frame number (init) */ ) { - Word16 alpha, alpha2, alpha2m1, alpham1; + Word16 alpha, alpha2, alpha2m1, alpham1; Word16 cor_min, cor_max, num, den, ExpNum, ExpDen, noise_chartmp; - Word16 wtmp1,wtmp, ExpLmax, ExpLmax2, tmpExp, nchar_thr, cor_tmp; - Word16 i, tmp_pc, pc,th_eps; + Word16 wtmp1, wtmp, ExpLmax, ExpLmax2, tmpExp, nchar_thr, cor_tmp; + Word16 i, tmp_pc, pc, th_eps; Word32 th_sta, Lnum, Lden, non_sta, LepsP, Ltmpden; Word16 e_ener, f_ener; - Word32 Ltmp, Ltmp1,Lsum_num, Lsum_den, *pt1, *pt2,Ltmp2, Lnon_sta2; + Word32 Ltmp, Ltmp1, Lsum_num, Lsum_den, *pt1, *pt2, Ltmp2, Lnon_sta2; Word16 spec_div, noise_char; Word16 log_enr16; - Word16 updt_step ; /* Q15 */ - Word16 aE_bgd,sd1_bgd,bg_bgd2; + Word16 updt_step; /* Q15 */ + Word16 aE_bgd, sd1_bgd, bg_bgd2; Word16 tn_ini; - Word16 epsP_0_2,epsP_0_2_ad,epsP_0_2_ad_lp_max; - Word16 epsP_2_16,epsP_2_16_dlp,epsP_2_16_dlp_max; + Word16 epsP_0_2, epsP_0_2_ad, epsP_0_2_ad_lp_max; + Word16 epsP_2_16, epsP_2_16_dlp, epsP_2_16_dlp_max; Word16 PAU, BG_1, NEW_POS_BG; Word16 haco_ev_max; Word16 Etot_l_lp_thr; Word16 comb_ahc_epsP, comb_hcm_epsP; - Word16 enr_bgd,cns_bgd,lp_bgd,ns_mask; + Word16 enr_bgd, cns_bgd, lp_bgd, ns_mask; Word16 lt_haco_mask, bg_haco_mask; - Word16 SD_1,SD_1_inv, bg_bgd3,PD_1,PD_2,PD_3,PD_4,PD_5; + Word16 SD_1, SD_1_inv, bg_bgd3, PD_1, PD_2, PD_3, PD_4, PD_5; Word16 non_staB; /* Q8 */ Word32 L_tmp_enr, L_tmp_ave_enr, L_tmp_ave_enr2; Word16 tmp_Q; - Word16 tmp, tmp2; /* general temp registers */ - Word16 tmp_enr, tmp_floor ; /* constants in Q8 */ - Word16 vad_bwidth_fx; /* vad ns control variabel for input bwidth from teh BWD */ + Word16 tmp, tmp2; /* general temp registers */ + Word16 tmp_enr, tmp_floor; /* constants in Q8 */ + Word16 vad_bwidth_fx; /* vad ns control variabel for input bwidth from teh BWD */ /* for DTX operation */ - Word16 vad_2nd_stage_fx; + Word16 vad_2nd_stage_fx; - Word16 lim_Etot_fx; /* Q8 */ - Word16 lim_Etot_sq_fx; /* Q2 */ + Word16 lim_Etot_fx; /* Q8 */ + Word16 lim_Etot_sq_fx; /* Q2 */ Word16 st_E_var_est_fx; /* Q2 */ NOISE_EST_HANDLE hNoiseEst; SP_MUS_CLAS_HANDLE hSpMusClas; hSpMusClas = st_fx->hSpMusClas; #ifdef REMOVE_IVAS_UNUSED_PARAMETERS_WARNING - (void)(ncharX); + (void) ( ncharX ); #endif /* Check if LR-VAD */ #ifdef IVAS_CODE - IF (hFrontVad != NULL) + IF( hFrontVad != NULL ) { hNoiseEst = hFrontVad->hNoiseEst; } @@ -621,43 +619,43 @@ void noise_est_fx( /*st_fx->ener_RAT = 10.0f * (float)log10( mean(lf_E, 8));*/ #ifdef IVAS_CODE - IF(hFrontVad == NULL) + IF( hFrontVad == NULL ) #endif { - if (hSpMusClas != NULL) + if ( hSpMusClas != NULL ) { - Ltmp = L_shr(lf_E[0], 3); - FOR(i = 1; i < 8; i++) + Ltmp = L_shr( lf_E[0], 3 ); + FOR( i = 1; i < 8; i++ ) { - Ltmp = L_add(Ltmp, L_shr(lf_E[i], 3)); + Ltmp = L_add( Ltmp, L_shr( lf_E[i], 3 ) ); } - IF (LT_32(Ltmp, L_shl(1, add(Q_new, Q_SCALE - 2)))) + IF( LT_32( Ltmp, L_shl( 1, add( Q_new, Q_SCALE - 2 ) ) ) ) { hSpMusClas->ener_RAT_fx = 0; - //PMT("hSpMusClas->ener_RAT_fx = 0, that should be validated") + // PMT("hSpMusClas->ener_RAT_fx = 0, that should be validated") } ELSE { - Ltmp = L_max(Ltmp, (Word32)1L); /* make sure log2_norm_lc does not cause table reading out of bounds */ - e_ener = norm_l(Ltmp); - f_ener = Log2_norm_lc(L_shl(Ltmp, e_ener)); - e_ener = sub(30, e_ener); - e_ener = sub(e_ener, sub(add(Q_new, QSCALE), 2)); - Ltmp = Mpy_32_16(e_ener, f_ener, LG10); - wtmp = round_fx(L_shl(Ltmp, 10));/*Q8*/ + Ltmp = L_max( Ltmp, (Word32) 1L ); /* make sure log2_norm_lc does not cause table reading out of bounds */ + e_ener = norm_l( Ltmp ); + f_ener = Log2_norm_lc( L_shl( Ltmp, e_ener ) ); + e_ener = sub( 30, e_ener ); + e_ener = sub( e_ener, sub( add( Q_new, QSCALE ), 2 ) ); + Ltmp = Mpy_32_16( e_ener, f_ener, LG10 ); + wtmp = round_fx( L_shl( Ltmp, 10 ) ); /*Q8*/ /* st_fx->ener_RAT /= (Etot + 0.01f); */ - wtmp1 = add(Etot, 3);/*3 is 0.01 in Q8 */ + wtmp1 = add( Etot, 3 ); /*3 is 0.01 in Q8 */ /* st_fx->ener_RAT_fx = wtmp/wtmp1 */ hSpMusClas->ener_RAT_fx = 0; move16(); - IF(wtmp > 0) + IF( wtmp > 0 ) { hSpMusClas->ener_RAT_fx = 32767; move16(); /*Q15*/ - if (GE_16(wtmp1, wtmp)) + if ( GE_16( wtmp1, wtmp ) ) { - hSpMusClas->ener_RAT_fx = div_s(wtmp, wtmp1); /*Q15*//* wtmp1 gte than wtmp */ + hSpMusClas->ener_RAT_fx = div_s( wtmp, wtmp1 ); /*Q15*/ /* wtmp1 gte than wtmp */ } } } @@ -671,21 +669,21 @@ void noise_est_fx( * order" spectral envelope => the epsP ratio is much less effective. *-----------------------------------------------------------------*/ - IF (NE_16(vad_bwidth_fx,NB)) /* WB input */ + IF( NE_16( vad_bwidth_fx, NB ) ) /* WB input */ { th_eps = TH_EPS16_FX; - move16();/*Q11*/ + move16(); /*Q11*/ th_sta = TH_STA16_FX; - move16();/*Q10 */ + move16(); /*Q10 */ cor_min = COR_MIN16_FX; - move16();/*Q15*/ + move16(); /*Q15*/ cor_max = COR_MAX16_FX; - move16();/*Q15*/ + move16(); /*Q15*/ } - ELSE /* NB input */ + ELSE /* NB input */ { th_eps = TH_EPS8_FX; - move16();/* Q11 */ + move16(); /* Q11 */ th_sta = TH_STA8_FX; move16(); /* Q10 */ cor_min = COR_MIN8_FX; @@ -700,43 +698,44 @@ void noise_est_fx( *-----------------------------------------------------------------*/ /* pc = abs(pit[0] - pitO) + abs(pit[1] - pit[0]) */ /* needed in signal_clas() */ - wtmp = abs_s(sub(st_fx->pitch_fx[0], old_pitch1)); - wtmp1 = abs_s(sub(st_fx->pitch_fx[1], st_fx->pitch_fx[0])); - pc = add(wtmp, wtmp1); + wtmp = abs_s( sub( st_fx->pitch_fx[0], old_pitch1 ) ); + wtmp1 = abs_s( sub( st_fx->pitch_fx[1], st_fx->pitch_fx[0] ) ); + pc = add( wtmp, wtmp1 ); - Ltmp = L_deposit_h(corr_shift); - Ltmp = L_mac(Ltmp, st_fx->voicing_fx[0], 10923); + Ltmp = L_deposit_h( corr_shift ); + Ltmp = L_mac( Ltmp, st_fx->voicing_fx[0], 10923 ); #ifdef BASOP_NOGLOB - Ltmp = L_mac_o(Ltmp, st_fx->voicing_fx[1], 10923, &Overflow); - wtmp = mac_ro(Ltmp, st_fx->voicing_fx[2], 10923, &Overflow); -#else /* BASOP_NOGLOB */ - Ltmp = L_mac(Ltmp, st_fx->voicing_fx[1], 10923); - wtmp = mac_r(Ltmp, st_fx->voicing_fx[2], 10923); + Ltmp = L_mac_o( Ltmp, st_fx->voicing_fx[1], 10923, &Overflow ); + wtmp = mac_ro( Ltmp, st_fx->voicing_fx[2], 10923, &Overflow ); +#else /* BASOP_NOGLOB */ + Ltmp = L_mac( Ltmp, st_fx->voicing_fx[1], 10923 ); + wtmp = mac_r( Ltmp, st_fx->voicing_fx[2], 10923 ); #endif /* BASOP_NOGLOB */ tmp_pc = pc; move16(); - if (LT_16(wtmp, cor_min)) + if ( LT_16( wtmp, cor_min ) ) { tmp_pc = TH_PC_FX; - move16(); /* low correlation -> probably inactive signal */ + move16(); /* low correlation -> probably inactive signal */ } - move16(); /* Update */ + move16(); /* Update */ /*-----------------------------------------------------------------* * Multi-harmonic analysis *-----------------------------------------------------------------*/ #ifdef IVAS_CODE - IF (hFrontVad == NULL) + IF( hFrontVad == NULL ) #endif { - IF (st_fx->hSpMusClas != NULL) + IF( st_fx->hSpMusClas != NULL ) { - i = 0; move16(); - *loc_harm = multi_harm_fx(EspecdB, hNoiseEst->old_S_fx, hNoiseEst->cor_map_fx, &hNoiseEst->multi_harm_limit_fx, st_fx->total_brate, - st_fx->bwidth, (st_fx->hGSCEnc != NULL) ? &hGSCEnc->cor_strong_limit : &i, &hSpMusClas->mean_avr_dyn_fx, &hSpMusClas->last_sw_dyn_fx, cor_map_sum, sp_floor, S_map); + i = 0; + move16(); + *loc_harm = multi_harm_fx( EspecdB, hNoiseEst->old_S_fx, hNoiseEst->cor_map_fx, &hNoiseEst->multi_harm_limit_fx, st_fx->total_brate, + st_fx->bwidth, ( st_fx->hGSCEnc != NULL ) ? &hGSCEnc->cor_strong_limit : &i, &hSpMusClas->mean_avr_dyn_fx, &hSpMusClas->last_sw_dyn_fx, cor_map_sum, sp_floor, S_map ); } } /*-----------------------------------------------------------------* @@ -744,76 +743,76 @@ void noise_est_fx( *-----------------------------------------------------------------*/ /* weighted sum of spectral changes per critical bands */ - Lsum_num = L_deposit_l(0); - Lsum_den = L_deposit_l(0); + Lsum_num = L_deposit_l( 0 ); + Lsum_den = L_deposit_l( 0 ); /* Find a proper scaling to prevent overflow, but acheiving good computation on low level signals */ tmpExp = 0; move16(); - ExpLmax = sub(30, norm_l(fr_bands[10])); - ExpLmax2 = sub(30, norm_l(hNoiseEst->fr_bands2_fx[10])); - tmpExp = s_max(tmpExp, sub(shl(s_max(ExpLmax,ExpLmax2), 1), s_min(ExpLmax, ExpLmax2))); - FOR (i = 11; i<= st_fx->max_band; i++) + ExpLmax = sub( 30, norm_l( fr_bands[10] ) ); + ExpLmax2 = sub( 30, norm_l( hNoiseEst->fr_bands2_fx[10] ) ); + tmpExp = s_max( tmpExp, sub( shl( s_max( ExpLmax, ExpLmax2 ), 1 ), s_min( ExpLmax, ExpLmax2 ) ) ); + FOR( i = 11; i <= st_fx->max_band; i++ ) { - ExpLmax = sub(30, norm_l(fr_bands[i])); - ExpLmax2 = sub(30, norm_l(hNoiseEst->fr_bands2_fx[i])); - tmpExp = s_max(tmpExp, sub(shl(s_max(ExpLmax,ExpLmax2), 1), s_min(ExpLmax, ExpLmax2))); + ExpLmax = sub( 30, norm_l( fr_bands[i] ) ); + ExpLmax2 = sub( 30, norm_l( hNoiseEst->fr_bands2_fx[i] ) ); + tmpExp = s_max( tmpExp, sub( shl( s_max( ExpLmax, ExpLmax2 ), 1 ), s_min( ExpLmax, ExpLmax2 ) ) ); } - tmpExp = sub(tmpExp, 30-4-4); /* 4bits for internal summation and 4 bits for comparaison */ + tmpExp = sub( tmpExp, 30 - 4 - 4 ); /* 4bits for internal summation and 4 bits for comparaison */ pt1 = fr_bands + 10; pt2 = hNoiseEst->fr_bands2_fx + 10; - FOR (i=10; i<=st_fx->max_band; i++) + FOR( i = 10; i <= st_fx->max_band; i++ ) { - Lnum = L_max(*pt1, *pt2); /* Don't need if anymore */ + Lnum = L_max( *pt1, *pt2 ); /* Don't need if anymore */ #ifdef BASOP_NOGLOB - Lsum_den = L_add_o(Lsum_den, Lnum, &Overflow); -#else /* BASOP_NOGLOB */ - Lsum_den = L_add(Lsum_den, Lnum); + Lsum_den = L_add_o( Lsum_den, Lnum, &Overflow ); +#else /* BASOP_NOGLOB */ + Lsum_den = L_add( Lsum_den, Lnum ); #endif /* BASOP_NOGLOB */ - Ltmpden = L_min(*pt1, *pt2); - if( Ltmpden == 0 ) + Ltmpden = L_min( *pt1, *pt2 ); + if ( Ltmpden == 0 ) { - Ltmpden = L_add(Ltmpden,1); + Ltmpden = L_add( Ltmpden, 1 ); } - ExpNum = sub(norm_l(Lnum), 1); - num = extract_h(L_shl(Lnum, ExpNum)); - num = mult_r(num, num); - ExpDen = norm_l(Ltmpden); - den = extract_h(L_shl(Ltmpden, ExpDen)); - num = div_s(num, den); - Ltmp = L_shr(num, add(sub(sub(shl(ExpNum, 1), ExpDen), 15+1), tmpExp)); - Lsum_num = L_add(Lsum_num, Ltmp); + ExpNum = sub( norm_l( Lnum ), 1 ); + num = extract_h( L_shl( Lnum, ExpNum ) ); + num = mult_r( num, num ); + ExpDen = norm_l( Ltmpden ); + den = extract_h( L_shl( Ltmpden, ExpDen ) ); + num = div_s( num, den ); + Ltmp = L_shr( num, add( sub( sub( shl( ExpNum, 1 ), ExpDen ), 15 + 1 ), tmpExp ) ); + Lsum_num = L_add( Lsum_num, Ltmp ); pt1++; pt2++; } - Lsum_den = L_shr(Lsum_den, tmpExp); + Lsum_den = L_shr( Lsum_den, tmpExp ); /* calculation of spectral diversity */ /* THR_SPDIV_FX = 5 , 1/5 Q15 = 6554 */ spec_div = 0; move16(); - if (GT_32(Mult_32_16(Lsum_num, 6554), Lsum_den)) /* Qx+Q15+1-16 ==> Qx */ + if ( GT_32( Mult_32_16( Lsum_num, 6554 ), Lsum_den ) ) /* Qx+Q15+1-16 ==> Qx */ { spec_div = 1; move16(); } /* *sp_div = Lsum_num / (Lsum_den + 1e-5f); */ - ExpNum = sub(norm_l(Lsum_num), 1); - num = extract_h(L_shl(Lsum_num, ExpNum)); + ExpNum = sub( norm_l( Lsum_num ), 1 ); + num = extract_h( L_shl( Lsum_num, ExpNum ) ); - Lsum_den = L_add(Lsum_den,1); + Lsum_den = L_add( Lsum_den, 1 ); - ExpDen = norm_l(Lsum_den); - den = extract_h(L_shl(Lsum_den, ExpDen)); + ExpDen = norm_l( Lsum_den ); + den = extract_h( L_shl( Lsum_den, ExpDen ) ); - *sp_div = div_s(num, den); + *sp_div = div_s( num, den ); move16(); - *Q_sp_div = add(15,sub(ExpNum ,ExpDen)); + *Q_sp_div = add( 15, sub( ExpNum, ExpDen ) ); move16(); /*-----------------------------------------------------------------* @@ -821,24 +820,24 @@ void noise_est_fx( *-----------------------------------------------------------------*/ /* calculation of energy in first 10 critical bands */ - Ltmp = sum32_fx( &fr_bands[st_fx->min_band], sub(10, st_fx->min_band) ); + Ltmp = sum32_fx( &fr_bands[st_fx->min_band], sub( 10, st_fx->min_band ) ); /* calculation of energy in the rest of bands */ - Ltmp2 = sum32_fx( &fr_bands[10], sub(st_fx->max_band,9) ); + Ltmp2 = sum32_fx( &fr_bands[10], sub( st_fx->max_band, 9 ) ); #ifdef BASOP_NOGLOB - wtmp = shl_o(1, sub(add(Q_new, QSCALE), 1), &Overflow); -#else /* BASOP_NOGLOB */ - wtmp = shl(1, sub(add(Q_new, QSCALE), 1)); + wtmp = shl_o( 1, sub( add( Q_new, QSCALE ), 1 ), &Overflow ); +#else /* BASOP_NOGLOB */ + wtmp = shl( 1, sub( add( Q_new, QSCALE ), 1 ) ); #endif /* BASOP_NOGLOB */ #ifdef IVAS_CODE - IF (ncharX != NULL) + IF( ncharX != NULL ) { - *ncharX = ftemp2 / (ftemp + 1e-5f); + *ncharX = ftemp2 / ( ftemp + 1e-5f ); } #endif test(); - IF (L_msu(Ltmp, 100, wtmp) < 0 || L_msu(Ltmp2, 100, wtmp) < 0) + IF( L_msu( Ltmp, 100, wtmp ) < 0 || L_msu( Ltmp2, 100, wtmp ) < 0 ) { noise_chartmp = 0; move16(); @@ -846,29 +845,29 @@ void noise_est_fx( ELSE { /* ftemp2 /= ftemp */ - ExpNum = sub(norm_l(Ltmp2), 1); - num = extract_h(L_shl(Ltmp2, ExpNum)); + ExpNum = sub( norm_l( Ltmp2 ), 1 ); + num = extract_h( L_shl( Ltmp2, ExpNum ) ); - ExpDen = norm_l(Ltmp); - den = extract_h(L_shl(Ltmp, ExpDen)); - num = div_s(num, den); + ExpDen = norm_l( Ltmp ); + den = extract_h( L_shl( Ltmp, ExpDen ) ); + num = div_s( num, den ); #ifdef BASOP_NOGLOB - noise_chartmp = extract_h(L_shr_o(num, add(sub(ExpNum, ExpDen), 4-16), &Overflow)); /* Q11 */ -#else /* BASOP_NOGLOB */ - noise_chartmp = extract_h(L_shr(num, add(sub(ExpNum, ExpDen), 4-16))); /* Q11 */ -#endif /* BASOP_NOGLOB */ + noise_chartmp = extract_h( L_shr_o( num, add( sub( ExpNum, ExpDen ), 4 - 16 ), &Overflow ) ); /* Q11 */ +#else /* BASOP_NOGLOB */ + noise_chartmp = extract_h( L_shr( num, add( sub( ExpNum, ExpDen ), 4 - 16 ) ) ); /* Q11 */ +#endif /* BASOP_NOGLOB */ } - noise_chartmp = s_min(noise_chartmp, (Word16)10<<11); /* Q11 */ + noise_chartmp = s_min( noise_chartmp, (Word16) 10 << 11 ); /* Q11 */ /* update LT value of the final parameter */ /* *st_noise_char = M_ALPHA * *st_noise_char + (1-M_ALPHA) * noise_chartmp */ - hNoiseEst->noise_char_fx = mac_r(L_mult(M_ALPHA_FX, hNoiseEst->noise_char_fx), ONE_MINUS_M_ALPHA, noise_chartmp); + hNoiseEst->noise_char_fx = mac_r( L_mult( M_ALPHA_FX, hNoiseEst->noise_char_fx ), ONE_MINUS_M_ALPHA, noise_chartmp ); nchar_thr = THR_NCHAR_WB_FX; - move16(); /* 1.0 Q11 */ - if( EQ_16(vad_bwidth_fx,NB)) + move16(); /* 1.0 Q11 */ + if ( EQ_16( vad_bwidth_fx, NB ) ) { nchar_thr = THR_NCHAR_NB_FX; move16(); /* 1.0 Q11 */ @@ -876,15 +875,15 @@ void noise_est_fx( noise_char = 0; move16(); - if (GT_16(hNoiseEst->noise_char_fx, nchar_thr)) + if ( GT_16( hNoiseEst->noise_char_fx, nchar_thr ) ) { noise_char = 1; move16(); } /* save the 2 last spectra per crit. bands for the future */ - Copy32(hNoiseEst->fr_bands1_fx, hNoiseEst->fr_bands2_fx, NB_BANDS); - Copy32(fr_bands+NB_BANDS, hNoiseEst->fr_bands1_fx, NB_BANDS); + Copy32( hNoiseEst->fr_bands1_fx, hNoiseEst->fr_bands2_fx, NB_BANDS ); + Copy32( fr_bands + NB_BANDS, hNoiseEst->fr_bands1_fx, NB_BANDS ); /*-----------------------------------------------------------------* * Non-stationarity estimation for each band @@ -894,40 +893,40 @@ void noise_est_fx( /* set averaging factor */ /* ftemp = relE; */ /* if( ftemp < 0.0f ) { ftemp = 0.0f; } */ - tmp = s_max(relE,0); /* Q8 */ + tmp = s_max( relE, 0 ); /* Q8 */ /* alpha = 0.064f * ftemp + 0.75f; */ - Ltmp = Mult_32_16((Word32)137438953L, tmp); /* Q31(.064)+Q8+1-16 --> Q24 */ - Ltmp = L_mac(Ltmp,256,24576) ; /* Q8+Q15(.75)+1 --> Q24 */ + Ltmp = Mult_32_16( (Word32) 137438953L, tmp ); /* Q31(.064)+Q8+1-16 --> Q24 */ + Ltmp = L_mac( Ltmp, 256, 24576 ); /* Q8+Q15(.75)+1 --> Q24 */ #ifdef BASOP_NOGLOB - alpha = round_fx_o(L_shl_o(Ltmp,7, &Overflow), &Overflow); /*Q24 +7 --> Q31 Q15*/ -#else /* BASOP_NOGLOB */ - alpha = round_fx(L_shl(Ltmp,7)); /*Q24 +7 --> Q31 Q15*/ -#endif /* BASOP_NOGLOB */ + alpha = round_fx_o( L_shl_o( Ltmp, 7, &Overflow ), &Overflow ); /*Q24 +7 --> Q31 Q15*/ +#else /* BASOP_NOGLOB */ + alpha = round_fx( L_shl( Ltmp, 7 ) ); /*Q24 +7 --> Q31 Q15*/ +#endif /* BASOP_NOGLOB */ /*if( alpha > 0.999f { alpha = 0.999f;} */ - alpha = s_min(alpha, 32735 ); /*.999 in Q15*/ - alpham1 = negate(add(-32768, alpha)); /* 1.0 - alpha */ + alpha = s_min( alpha, 32735 ); /*.999 in Q15*/ + alpham1 = negate( add( -32768, alpha ) ); /* 1.0 - alpha */ /*--------------------------------------------------------------* * during significant attacks, replace the LT energy by the * current energy this will cause non_sta2 failures to occur in * different frames than non_sta failures *--------------------------------------------------------------*/ - alpha2 = alpha; + alpha2 = alpha; move16(); alpha2m1 = alpham1; move16(); - IF (spec_div > 0) + IF( spec_div > 0 ) { alpha2 = 0; move16(); alpha2m1 = 32767; move16(); } - Lnon_sta2 = L_deposit_l(1<<10); + Lnon_sta2 = L_deposit_l( 1 << 10 ); - non_sta = L_deposit_l(1<<10); + non_sta = L_deposit_l( 1 << 10 ); *non_staX = 0; move16(); non_staB = 0; @@ -937,44 +936,44 @@ void noise_est_fx( { /* + 1.0f added to reduce sensitivity to non stationarity in low energies */ /* tmp_enr = enr[i] + 1.0f; */ - tmp_Q = add(Q_new, Q_SCALE); - Ltmp = L_shl((Word32)1L, tmp_Q); /* 1.0 added in the right dynamic domain */ + tmp_Q = add( Q_new, Q_SCALE ); + Ltmp = L_shl( (Word32) 1L, tmp_Q ); /* 1.0 added in the right dynamic domain */ #ifdef BASOP_NOGLOB - L_tmp_enr = L_add_o(enr[i] , Ltmp , &Overflow); /* enr scale dynamic */ - L_tmp_ave_enr = L_add_o(hNoiseEst->ave_enr_fx[i], Ltmp, &Overflow); /* ave__enr scale dynamic */ -#else /* BASOP_NOGLOB */ - L_tmp_enr = L_add(enr[i] , Ltmp ); /* enr scale dynamic */ - L_tmp_ave_enr = L_add(hNoiseEst->ave_enr_fx[i], Ltmp); /* ave__enr scale dynamic */ -#endif /* BASOP_NOGLOB */ - - IF (LE_32(non_sta, th_sta)) /* Just to limit the saturation */ + L_tmp_enr = L_add_o( enr[i], Ltmp, &Overflow ); /* enr scale dynamic */ + L_tmp_ave_enr = L_add_o( hNoiseEst->ave_enr_fx[i], Ltmp, &Overflow ); /* ave__enr scale dynamic */ +#else /* BASOP_NOGLOB */ + L_tmp_enr = L_add( enr[i], Ltmp ); /* enr scale dynamic */ + L_tmp_ave_enr = L_add( hNoiseEst->ave_enr_fx[i], Ltmp ); /* ave__enr scale dynamic */ +#endif /* BASOP_NOGLOB */ + + IF( LE_32( non_sta, th_sta ) ) /* Just to limit the saturation */ { /* if( enr[i] > st_ave_enr2[i] ) */ /* non_sta2 = non_sta2 * ((enr[i]+1) / (st_ave_enr2[i]+1)) */ - Lnum = L_max(L_tmp_enr, L_tmp_ave_enr); + Lnum = L_max( L_tmp_enr, L_tmp_ave_enr ); /* else */ /* non_sta2 = non_sta2 * ((st_ave_enr2[i]+1) / (enr[i]+1)) */ - Lden = L_min(L_tmp_enr, L_tmp_ave_enr); - - ExpNum = sub(norm_l(Lnum), 1); - num = extract_h(L_shl(Lnum, ExpNum)); - Lnum = L_shl(Lnum, ExpNum); - ExpDen = norm_l(Lden); - den = extract_h(L_shl(Lden, ExpDen)); - num = div_s(num, den); - Ltmp = Mult_32_16(non_sta, num); + Lden = L_min( L_tmp_enr, L_tmp_ave_enr ); + + ExpNum = sub( norm_l( Lnum ), 1 ); + num = extract_h( L_shl( Lnum, ExpNum ) ); + Lnum = L_shl( Lnum, ExpNum ); + ExpDen = norm_l( Lden ); + den = extract_h( L_shl( Lden, ExpDen ) ); + num = div_s( num, den ); + Ltmp = Mult_32_16( non_sta, num ); #ifdef BASOP_NOGLOB - non_sta = L_shr_o(Ltmp, sub(ExpNum, ExpDen), &Overflow); /* Q10 */ -#else /* BASOP_NOGLOB */ - non_sta = L_shr(Ltmp, sub(ExpNum, ExpDen)); /* Q10 */ -#endif /* BASOP_NOGLOB */ + non_sta = L_shr_o( Ltmp, sub( ExpNum, ExpDen ), &Overflow ); /* Q10 */ +#else /* BASOP_NOGLOB */ + non_sta = L_shr( Ltmp, sub( ExpNum, ExpDen ) ); /* Q10 */ +#endif /* BASOP_NOGLOB */ } - /* st->ave_enr[i] = alpha * st->ave_enr[i] + (1-alpha) * enr[i];*/ /* update long-term average */ - Ltmp = Mult_32_16(hNoiseEst->ave_enr_fx[i], alpha); - Ltmp = L_add(Ltmp, Mult_32_16(enr[i], alpham1)); - hNoiseEst->ave_enr_fx[i] = L_max(Le_min_scaled, Ltmp); + /* st->ave_enr[i] = alpha * st->ave_enr[i] + (1-alpha) * enr[i];*/ /* update long-term average */ + Ltmp = Mult_32_16( hNoiseEst->ave_enr_fx[i], alpha ); + Ltmp = L_add( Ltmp, Mult_32_16( enr[i], alpham1 ) ); + hNoiseEst->ave_enr_fx[i] = L_max( Le_min_scaled, Ltmp ); move32(); /* calculation of another non-stationarity measure (following attacks) */ @@ -988,157 +987,157 @@ void noise_est_fx( } */ /* ave_enr2:: calculation of another non-stationarity measure (following attacks) */ - Ltmp = L_shl((Word32)1L, tmp_Q ); /* 1.0 added in the right dynamic domain */ - /*L_tmp_enr = L_add(enr[i] , Ltmp );*/ /* enr scale dynamic , done above */ + Ltmp = L_shl( (Word32) 1L, tmp_Q ); /* 1.0 added in the right dynamic domain */ + /*L_tmp_enr = L_add(enr[i] , Ltmp );*/ /* enr scale dynamic , done above */ #ifdef BASOP_NOGLOB - L_tmp_ave_enr2 = L_add_o(hNoiseEst->ave_enr2_fx[i], Ltmp, &Overflow); /* ave__enr scale dynamic */ + L_tmp_ave_enr2 = L_add_o( hNoiseEst->ave_enr2_fx[i], Ltmp, &Overflow ); /* ave__enr scale dynamic */ #else - L_tmp_ave_enr2 = L_add(hNoiseEst->ave_enr2_fx[i], Ltmp); /* ave__enr scale dynamic */ + L_tmp_ave_enr2 = L_add( hNoiseEst->ave_enr2_fx[i], Ltmp ); /* ave__enr scale dynamic */ #endif - IF (LE_32(Lnon_sta2, th_sta )) /* Just to limit the saturation */ + IF( LE_32( Lnon_sta2, th_sta ) ) /* Just to limit the saturation */ { - Lnum = L_max(L_tmp_enr, L_tmp_ave_enr2 ); - Lden = L_min(L_tmp_enr, L_tmp_ave_enr2 ); - - ExpNum = sub(norm_l(Lnum), 1); - num = extract_h(L_shl(Lnum, ExpNum)); - Lnum = L_shl(Lnum, ExpNum); - ExpDen = norm_l(Lden); - den = extract_h(L_shl(Lden, ExpDen)); - num = div_s(num, den); - Ltmp1 = Mult_32_16(Lnon_sta2, num); + Lnum = L_max( L_tmp_enr, L_tmp_ave_enr2 ); + Lden = L_min( L_tmp_enr, L_tmp_ave_enr2 ); + + ExpNum = sub( norm_l( Lnum ), 1 ); + num = extract_h( L_shl( Lnum, ExpNum ) ); + Lnum = L_shl( Lnum, ExpNum ); + ExpDen = norm_l( Lden ); + den = extract_h( L_shl( Lden, ExpDen ) ); + num = div_s( num, den ); + Ltmp1 = Mult_32_16( Lnon_sta2, num ); #ifdef BASOP_NOGLOB - Lnon_sta2 = L_shr_o(Ltmp1, sub(ExpNum, ExpDen), &Overflow); /* Q10 */ -#else /* BASOP_NOGLOB */ - Lnon_sta2 = L_shr(Ltmp1, sub(ExpNum, ExpDen)); /* Q10 */ -#endif /* BASOP_NOGLOB */ + Lnon_sta2 = L_shr_o( Ltmp1, sub( ExpNum, ExpDen ), &Overflow ); /* Q10 */ +#else /* BASOP_NOGLOB */ + Lnon_sta2 = L_shr( Ltmp1, sub( ExpNum, ExpDen ) ); /* Q10 */ +#endif /* BASOP_NOGLOB */ } /* st_ave_enr2[i] = (float)alpha2 * st_ave_enr2[i] + (1.0f - alpha2) * (enr[i]) */ - Ltmp1 = Mult_32_16(hNoiseEst->ave_enr2_fx[i], alpha2); - Ltmp1 = L_add(Ltmp1, Mult_32_16(enr[i], alpha2m1)); - hNoiseEst->ave_enr2_fx[i] = L_max(Le_min_scaled, Ltmp1); + Ltmp1 = Mult_32_16( hNoiseEst->ave_enr2_fx[i], alpha2 ); + Ltmp1 = L_add( Ltmp1, Mult_32_16( enr[i], alpha2m1 ) ); + hNoiseEst->ave_enr2_fx[i] = L_max( Le_min_scaled, Ltmp1 ); move32(); /* calculation of non-stationarity measure for speech/music classification */ #ifdef IVAS_CODE - IF(hFrontVad == NULL) + IF( hFrontVad == NULL ) #endif { - test();test(); - IF(GE_16(i, START_BAND_SPMUS) && LT_16(i, NB_BANDS_SPMUS + START_BAND_SPMUS) && st_fx->hSpMusClas != NULL) + test(); + test(); + IF( GE_16( i, START_BAND_SPMUS ) && LT_16( i, NB_BANDS_SPMUS + START_BAND_SPMUS ) && st_fx->hSpMusClas != NULL ) { /* log_enr = (float)ln_fx(enr[i]); */ - log_enr16 = noise_est_ln_q8_fx(enr[i], 0, tmp_Q); - wtmp = abs_s(sub(log_enr16, hSpMusClas->past_log_enr_fx[i - START_BAND_SPMUS])); + log_enr16 = noise_est_ln_q8_fx( enr[i], 0, tmp_Q ); + wtmp = abs_s( sub( log_enr16, hSpMusClas->past_log_enr_fx[i - START_BAND_SPMUS] ) ); #ifdef BASOP_NOGLOB - *non_staX = add_o(*non_staX, wtmp, &Overflow); -#else /* BASOP_NOGLOB */ - *non_staX = add(*non_staX, wtmp); -#endif /* BASOP_NOGLOB */ - move16(); /* Q8 */ + *non_staX = add_o( *non_staX, wtmp, &Overflow ); +#else /* BASOP_NOGLOB */ + *non_staX = add( *non_staX, wtmp ); +#endif /* BASOP_NOGLOB */ + move16(); /* Q8 */ hSpMusClas->past_log_enr_fx[i - START_BAND_SPMUS] = log_enr16; move16(); } } - IF(GE_16(i, 2) && LE_16(i, 16)) + IF( GE_16( i, 2 ) && LE_16( i, 16 ) ) { - IF(GE_16(ini_frame , 100)) + IF( GE_16( ini_frame, 100 ) ) { /* calculate non-stationarity feature relative background */ - tmp_enr = noise_est_ln_q8_fx(enr[i], 1, tmp_Q); /* 1.0f added */ + tmp_enr = noise_est_ln_q8_fx( enr[i], 1, tmp_Q ); /* 1.0f added */ tmp_floor = LN_E_MIN_PLUS_ONE_FX; - move16(); /* non dynamic init constant in Q8 */ - tmp_floor = noise_est_ln_q8_fx(hNoiseEst->bckr_fx[i], 1, tmp_Q); + move16(); /* non dynamic init constant in Q8 */ + tmp_floor = noise_est_ln_q8_fx( hNoiseEst->bckr_fx[i], 1, tmp_Q ); #ifdef BASOP_NOGLOB - non_staB = add_o(non_staB, abs_s(sub(tmp_enr, tmp_floor)), &Overflow); /* Q8 */ -#else /* BASOP_NOGLOB */ - non_staB = add(non_staB, abs_s(sub(tmp_enr, tmp_floor))); /* Q8 */ -#endif /* BASOP_NOGLOB */ + non_staB = add_o( non_staB, abs_s( sub( tmp_enr, tmp_floor ) ), &Overflow ); /* Q8 */ +#else /* BASOP_NOGLOB */ + non_staB = add( non_staB, abs_s( sub( tmp_enr, tmp_floor ) ) ); /* Q8 */ +#endif /* BASOP_NOGLOB */ } ELSE /*ini_frame < 100*/ { /* calculate non-stationarity feature relative background */ - tmp_enr = noise_est_ln_q8_fx(enr[i], 1, tmp_Q); /* 1.0f added */ + tmp_enr = noise_est_ln_q8_fx( enr[i], 1, tmp_Q ); /* 1.0f added */ tmp_floor = LN_E_MIN_PLUS_ONE_FX; - move16(); /* non dynamic init constant in Q8 */ - tmp_floor = noise_est_ln_q8_fx(E_MIN_FX, 1, tmp_Q); + move16(); /* non dynamic init constant in Q8 */ + tmp_floor = noise_est_ln_q8_fx( E_MIN_FX, 1, tmp_Q ); #ifdef BASOP_NOGLOB - non_staB = add_o(non_staB, abs_s(sub(tmp_enr, tmp_floor)), &Overflow); /* Q8 */ -#else /* BASOP_NOGLOB */ - non_staB = add(non_staB, abs_s(sub(tmp_enr, tmp_floor))); /* Q8 */ -#endif /* BASOP_NOGLOB */ + non_staB = add_o( non_staB, abs_s( sub( tmp_enr, tmp_floor ) ), &Overflow ); /* Q8 */ +#else /* BASOP_NOGLOB */ + non_staB = add( non_staB, abs_s( sub( tmp_enr, tmp_floor ) ) ); /* Q8 */ +#endif /* BASOP_NOGLOB */ } } } /* end of band loop FOR( i = st_fx->min_band; i <= st_fx->max_band; i++ ) */ - IF (LT_16(Etot,-1280)) + IF( LT_16( Etot, -1280 ) ) { - non_sta = L_deposit_l(1024); /* 1.0 in Q10 */ - Lnon_sta2 = L_deposit_l(1024); /* 1.0 in Q10 */ + non_sta = L_deposit_l( 1024 ); /* 1.0 in Q10 */ + Lnon_sta2 = L_deposit_l( 1024 ); /* 1.0 in Q10 */ } - lim_Etot_fx = s_max(5120,Etot); /* 20.0f Q8 */ - lim_Etot_sq_fx = extract_h(L_shl_r(L_mult(lim_Etot_fx,lim_Etot_fx),1)); /* Q2 */ + lim_Etot_fx = s_max( 5120, Etot ); /* 20.0f Q8 */ + lim_Etot_sq_fx = extract_h( L_shl_r( L_mult( lim_Etot_fx, lim_Etot_fx ), 1 ) ); /* Q2 */ if ( st_fx->ini_frame < 150 ) { /* Allow use of quicker filter during init - if needed */ /* st->Etot_st_est = 0.25f * lim_Etot + (1.0f-0.25F) * st->Etot_st_est; */ - hNoiseEst->Etot_st_est_fx = mac_r(L_mult(8192, lim_Etot_fx), 24576, hNoiseEst->Etot_st_est_fx); + hNoiseEst->Etot_st_est_fx = mac_r( L_mult( 8192, lim_Etot_fx ), 24576, hNoiseEst->Etot_st_est_fx ); move16(); /* st->Etot_sq_st_est = 0.25f * lim_Etot * lim_Etot + (1.0f-0.25f) * st->Etot_sq_st_est; */ - hNoiseEst->Etot_sq_st_est_fx = mac_r(L_mult(8192, lim_Etot_sq_fx), 24576, hNoiseEst->Etot_sq_st_est_fx); + hNoiseEst->Etot_sq_st_est_fx = mac_r( L_mult( 8192, lim_Etot_sq_fx ), 24576, hNoiseEst->Etot_sq_st_est_fx ); move16(); } else { /* st->Etot_st_est = 0.25f * lim_Etot + (1.0f-0.25F) * st->Etot_st_est; */ - hNoiseEst->Etot_st_est_fx = mac_r(L_mult(8192, lim_Etot_fx), 24576, hNoiseEst->Etot_st_est_fx); + hNoiseEst->Etot_st_est_fx = mac_r( L_mult( 8192, lim_Etot_fx ), 24576, hNoiseEst->Etot_st_est_fx ); move16(); /* st->Etot_sq_st_est = 0.25f * lim_Etot * lim_Etot + (1.0f-0.25f) * st->Etot_sq_st_est; */ - hNoiseEst->Etot_sq_st_est_fx = mac_r(L_mult(8192, lim_Etot_sq_fx), 24576, hNoiseEst->Etot_sq_st_est_fx); + hNoiseEst->Etot_sq_st_est_fx = mac_r( L_mult( 8192, lim_Etot_sq_fx ), 24576, hNoiseEst->Etot_sq_st_est_fx ); move16(); } - st_E_var_est_fx = sub(hNoiseEst->Etot_sq_st_est_fx,extract_h(L_shl_r(L_mult(hNoiseEst->Etot_st_est_fx,hNoiseEst->Etot_st_est_fx),1))); - + st_E_var_est_fx = sub( hNoiseEst->Etot_sq_st_est_fx, extract_h( L_shl_r( L_mult( hNoiseEst->Etot_st_est_fx, hNoiseEst->Etot_st_est_fx ), 1 ) ) ); /*-----------------------------------------------------------------* * Count frames since last correlation or harmonic event *-----------------------------------------------------------------*/ - Ltmp = L_mult(st_fx->voicing_fx[0], 16384); - Ltmp = L_mac(Ltmp, st_fx->voicing_fx[1], 16384); + Ltmp = L_mult( st_fx->voicing_fx[0], 16384 ); + Ltmp = L_mac( Ltmp, st_fx->voicing_fx[1], 16384 ); test(); test(); - *st_harm_cor_cnt = add(*st_harm_cor_cnt , 1); - if( (Etot > 0) && ( (*loc_harm > 0 ) || (GT_16(round_fx(Ltmp), COR_MAX_NNE_FX )))) + *st_harm_cor_cnt = add( *st_harm_cor_cnt, 1 ); + if ( ( Etot > 0 ) && ( ( *loc_harm > 0 ) || ( GT_16( round_fx( Ltmp ), COR_MAX_NNE_FX ) ) ) ) { *st_harm_cor_cnt = 0; move16(); } - IF( (GT_16(*st_harm_cor_cnt,1))&&((LT_16(Etot,3840))||/* 15 in Q8 */ - ( GT_16(st_fx->ini_frame,10) && - GT_16(sub(Etot, hNoiseEst->Etot_lp_fx),1792) )) /* 7 in Q8 */ - ) + IF( ( GT_16( *st_harm_cor_cnt, 1 ) ) && ( ( LT_16( Etot, 3840 ) ) || /* 15 in Q8 */ + ( GT_16( st_fx->ini_frame, 10 ) && + GT_16( sub( Etot, hNoiseEst->Etot_lp_fx ), 1792 ) ) ) /* 7 in Q8 */ + ) { *st_harm_cor_cnt = 1; } - if ( GT_16(*st_harm_cor_cnt,1)&& - GT_16(Etot,7680) && /* 30.0f in Q8 */ - GT_16(st_E_var_est_fx,32 ) /* 8.0f in Q2 */ - ) + if ( GT_16( *st_harm_cor_cnt, 1 ) && + GT_16( Etot, 7680 ) && /* 30.0f in Q8 */ + GT_16( st_E_var_est_fx, 32 ) /* 8.0f in Q2 */ + ) { /* st->harm_cor_cnt = max(1, (short) round_f( (float) st->harm_cor_cnt / 4.0f )) ; */ - *st_harm_cor_cnt = s_max(1, shr(add(*st_harm_cor_cnt,2),1)); + *st_harm_cor_cnt = s_max( 1, shr( add( *st_harm_cor_cnt, 2 ), 1 ) ); } @@ -1146,7 +1145,7 @@ void noise_est_fx( * Energy based pause length counter *-----------------------------------------------------------------*/ test(); - IF( (*bg_cnt >= 0) && (GT_16(sub(Etot , Etot_l_lp),1280)/*5.0 in Q8*/)) + IF( ( *bg_cnt >= 0 ) && ( GT_16( sub( Etot, Etot_l_lp ), 1280 ) /*5.0 in Q8*/ ) ) { /* Possible speech burst */ *bg_cnt = -1; @@ -1155,16 +1154,16 @@ void noise_est_fx( ELSE { test(); - if( EQ_16(*bg_cnt,-1)&&(LT_16(sub(Etot,Etot_l_lp),1280))/*5 in Q8*/) + if ( EQ_16( *bg_cnt, -1 ) && ( LT_16( sub( Etot, Etot_l_lp ), 1280 ) ) /*5 in Q8*/ ) { /* Possible start of speech pause */ *bg_cnt = 0; move16(); } } - if (*bg_cnt >= 0) + if ( *bg_cnt >= 0 ) { - *bg_cnt = add(*bg_cnt,1); + *bg_cnt = add( *bg_cnt, 1 ); move16(); } @@ -1173,42 +1172,42 @@ void noise_est_fx( *-----------------------------------------------------------------*/ /*epsP_0_2 = max(0 , min(8, epsP[0] / epsP[2])); */ - Ltmp = eps_quota_fx(epsP_h[0], epsP_l[0], - epsP_h[2], epsP_l[2] , 12 ); /* Word32 Q12 */ - BASOP_SATURATE_WARNING_OFF_EVS /* may saturate*/ + Ltmp = eps_quota_fx( epsP_h[0], epsP_l[0], + epsP_h[2], epsP_l[2], 12 ); /* Word32 Q12 */ + BASOP_SATURATE_WARNING_OFF_EVS /* may saturate*/ #ifdef BASOP_NOGLOB - epsP_0_2 = round_fx_o(L_shl_o(Ltmp,16, &Overflow), &Overflow); /* Q12+16 -16 -> Q12 , NB saturation in Q12 sets max value to 7,999 */ -#else /* BASOP_NOGLOB */ - epsP_0_2 = round_fx(L_shl(Ltmp,16)); /* Q12+16 -16 -> Q12 , NB saturation in Q12 sets max value to 7,999 */ -#endif /* BASOP_NOGLOB */ + epsP_0_2 = round_fx_o( L_shl_o( Ltmp, 16, &Overflow ), &Overflow ); /* Q12+16 -16 -> Q12 , NB saturation in Q12 sets max value to 7,999 */ +#else /* BASOP_NOGLOB */ + epsP_0_2 = round_fx( L_shl( Ltmp, 16 ) ); /* Q12+16 -16 -> Q12 , NB saturation in Q12 sets max value to 7,999 */ +#endif /* BASOP_NOGLOB */ BASOP_SATURATE_WARNING_ON_EVS - epsP_0_2 = s_max(0, epsP_0_2); /* min value is 0 , Q12 */ + epsP_0_2 = s_max( 0, epsP_0_2 ); /* min value is 0 , Q12 */ /* st->epsP_0_2_lp = 0.15f * epsP_0_2 + (1.0f-0.15f) * st->epsP_0_2_lp; */ - alpha = 4915; - move16(); /*0.15 in Q15 */ - hNoiseEst->epsP_0_2_lp_fx = noise_est_AR1_Qx(epsP_0_2, hNoiseEst->epsP_0_2_lp_fx ,alpha); + alpha = 4915; + move16(); /*0.15 in Q15 */ + hNoiseEst->epsP_0_2_lp_fx = noise_est_AR1_Qx( epsP_0_2, hNoiseEst->epsP_0_2_lp_fx, alpha ); /* epsP_0_2_ad = (float) fabs(epsP_0_2 - st->epsP_0_2_lp ); */ - epsP_0_2_ad = abs_s(sub(epsP_0_2, hNoiseEst->epsP_0_2_lp_fx)); /* Q12 */ + epsP_0_2_ad = abs_s( sub( epsP_0_2, hNoiseEst->epsP_0_2_lp_fx ) ); /* Q12 */ /*if (epsP_0_2_ad < st->epsP_0_2_ad_lp) { st->epsP_0_2_ad_lp = 0.1f * epsP_0_2_ad + (1.0f - 0.1f) * st->epsP_0_2_ad_lp; } else { st->epsP_0_2_ad_lp = 0.2f * epsP_0_2_ad + (1.0f - 0.2f) * st->epsP_0_2_ad_lp; } */ - alpha = 6554; - move16();/* 0.2 Q15 */ - if (LT_16(epsP_0_2_ad, hNoiseEst->epsP_0_2_ad_lp_fx)) + alpha = 6554; + move16(); /* 0.2 Q15 */ + if ( LT_16( epsP_0_2_ad, hNoiseEst->epsP_0_2_ad_lp_fx ) ) { - alpha = shr(alpha,1); /* 0.1 Q15 */ + alpha = shr( alpha, 1 ); /* 0.1 Q15 */ } - hNoiseEst->epsP_0_2_ad_lp_fx = noise_est_AR1_Qx(epsP_0_2_ad, hNoiseEst->epsP_0_2_ad_lp_fx ,alpha); + hNoiseEst->epsP_0_2_ad_lp_fx = noise_est_AR1_Qx( epsP_0_2_ad, hNoiseEst->epsP_0_2_ad_lp_fx, alpha ); /* epsP_0_2_ad_lp_max = max(epsP_0_2_ad,st->epsP_0_2_ad_lp);*/ - epsP_0_2_ad_lp_max = s_max(epsP_0_2_ad, hNoiseEst->epsP_0_2_ad_lp_fx); /* Q12 */ + epsP_0_2_ad_lp_max = s_max( epsP_0_2_ad, hNoiseEst->epsP_0_2_ad_lp_fx ); /* Q12 */ /*-----------------------------------------------------------------* @@ -1216,19 +1215,19 @@ void noise_est_fx( *-----------------------------------------------------------------*/ /* epsP_2_16 = max(0 , min(8, epsP[2] / epsP[16])); */ - Ltmp = eps_quota_fx(epsP_h[2], epsP_l[2], - epsP_h[16], epsP_l[16] , 12 ); /* Word32 Q12 */ - BASOP_SATURATE_WARNING_OFF_EVS /* may saturate*/ + Ltmp = eps_quota_fx( epsP_h[2], epsP_l[2], + epsP_h[16], epsP_l[16], 12 ); /* Word32 Q12 */ + BASOP_SATURATE_WARNING_OFF_EVS /* may saturate*/ #ifdef BASOP_NOGLOB - epsP_2_16 = round_fx_o(L_shl_o(Ltmp,16, &Overflow), &Overflow); /* Q12+16 -16 -> Q12 , - NB saturation in Q12 sets max value to 7,999 */ -#else /* BASOP_NOGLOB */ - epsP_2_16 = round_fx(L_shl(Ltmp,16)); /* Q12+16 -16 -> Q12 , - NB saturation in Q12 sets max value to 7,999 */ -#endif /* BASOP_NOGLOB */ + epsP_2_16 = round_fx_o( L_shl_o( Ltmp, 16, &Overflow ), &Overflow ); /* Q12+16 -16 -> Q12 , + NB saturation in Q12 sets max value to 7,999 */ +#else /* BASOP_NOGLOB */ + epsP_2_16 = round_fx( L_shl( Ltmp, 16 ) ); /* Q12+16 -16 -> Q12 , + NB saturation in Q12 sets max value to 7,999 */ +#endif /* BASOP_NOGLOB */ BASOP_SATURATE_WARNING_ON_EVS - epsP_2_16 = s_max(0, epsP_2_16); /* min value is 0 , Q12 */ + epsP_2_16 = s_max( 0, epsP_2_16 ); /* min value is 0 , Q12 */ /* if (epsP_2_16 > st->epsP_2_16_lp){ @@ -1239,18 +1238,18 @@ void noise_est_fx( st->epsP_2_16_lp2 = 0.02f * epsP_2_16 + (1.0f-0.02f) * st->epsP_2_16_lp2; */ - alpha = 983 ; - move16();/* 0.03 Q15 */ - if (GT_16(epsP_2_16 , hNoiseEst->epsP_2_16_lp_fx)) + alpha = 983; + move16(); /* 0.03 Q15 */ + if ( GT_16( epsP_2_16, hNoiseEst->epsP_2_16_lp_fx ) ) { alpha = 6554; - move16();/* 0.2 Q15 */ + move16(); /* 0.2 Q15 */ } - hNoiseEst->epsP_2_16_lp_fx = noise_est_AR1_Qx(epsP_2_16, hNoiseEst->epsP_2_16_lp_fx , alpha); + hNoiseEst->epsP_2_16_lp_fx = noise_est_AR1_Qx( epsP_2_16, hNoiseEst->epsP_2_16_lp_fx, alpha ); - hNoiseEst->epsP_2_16_lp2_fx = noise_est_AR1_Qx(epsP_2_16, hNoiseEst->epsP_2_16_lp2_fx , 655); /* 0.02 */ + hNoiseEst->epsP_2_16_lp2_fx = noise_est_AR1_Qx( epsP_2_16, hNoiseEst->epsP_2_16_lp2_fx, 655 ); /* 0.02 */ - epsP_2_16_dlp = sub(hNoiseEst->epsP_2_16_lp_fx, hNoiseEst->epsP_2_16_lp2_fx); + epsP_2_16_dlp = sub( hNoiseEst->epsP_2_16_lp_fx, hNoiseEst->epsP_2_16_lp2_fx ); /* if (epsP_2_16_dlp < st->epsP_2_16_dlp_lp2 ) { @@ -1258,40 +1257,39 @@ void noise_est_fx( } else { st->epsP_2_16_dlp_lp2 = 0.05f * epsP_2_16_dlp + (1.0f-0.05f) * st->epsP_2_16_dlp_lp2; }*/ - alpha = 1638; - move16();/* 0.05 Q15 */ - if (LT_16(epsP_2_16_dlp , hNoiseEst->epsP_2_16_dlp_lp2_fx)) + alpha = 1638; + move16(); /* 0.05 Q15 */ + if ( LT_16( epsP_2_16_dlp, hNoiseEst->epsP_2_16_dlp_lp2_fx ) ) { alpha = 655; - move16();/* 0.02 Q15 */ + move16(); /* 0.02 Q15 */ } - hNoiseEst->epsP_2_16_dlp_lp2_fx = noise_est_AR1_Qx(epsP_2_16_dlp, hNoiseEst->epsP_2_16_dlp_lp2_fx , alpha); + hNoiseEst->epsP_2_16_dlp_lp2_fx = noise_est_AR1_Qx( epsP_2_16_dlp, hNoiseEst->epsP_2_16_dlp_lp2_fx, alpha ); /* epsP_2_16_dlp_max = max(epsP_2_16_dlp,st->epsP_2_16_dlp_lp2); */ - epsP_2_16_dlp_max = s_max(epsP_2_16_dlp, hNoiseEst->epsP_2_16_dlp_lp2_fx); + epsP_2_16_dlp_max = s_max( epsP_2_16_dlp, hNoiseEst->epsP_2_16_dlp_lp2_fx ); /*-----------------------------------------------------------------* * long term extensions of frame features *-----------------------------------------------------------------*/ - tmp = sub(Etot, hNoiseEst->totalNoise_fx ); /* Q8 */ + tmp = sub( Etot, hNoiseEst->totalNoise_fx ); /* Q8 */ /* st->lt_tn_track = 0.03f* (Etot - st->totalNoise < 10) + 0.97f*st->lt_tn_track; */ tmp2 = 0; move16(); - if( LT_16(tmp, 2560 )) /*10 in Q8 */ + if ( LT_16( tmp, 2560 ) ) /*10 in Q8 */ { - tmp2=32767; + tmp2 = 32767; move16(); } - hNoiseEst->lt_tn_track_fx = noise_est_AR1_Qx(tmp2, hNoiseEst->lt_tn_track_fx , 983); /*0.03 in Q15 ,Q15 state*/ + hNoiseEst->lt_tn_track_fx = noise_est_AR1_Qx( tmp2, hNoiseEst->lt_tn_track_fx, 983 ); /*0.03 in Q15 ,Q15 state*/ /* st->lt_tn_dist = 0.03f* (Etot - st->totalNoise) + 0.97f*st->lt_tn_dist; */ - hNoiseEst->lt_tn_dist_fx = noise_est_AR1_Qx(tmp, hNoiseEst->lt_tn_dist_fx , 983); /*0.03 in Q15 ,Q8 state*/ + hNoiseEst->lt_tn_dist_fx = noise_est_AR1_Qx( tmp, hNoiseEst->lt_tn_dist_fx, 983 ); /*0.03 in Q15 ,Q8 state*/ /* st->lt_Ellp_dist = 0.03f* (Etot - st->Etot_l_lp) + 0.97f*st->lt_Ellp_dist;*/ - tmp = sub(Etot, hNoiseEst->Etot_l_lp_fx); /* Q8 */ - hNoiseEst->lt_Ellp_dist_fx = noise_est_AR1_Qx(tmp, hNoiseEst->lt_Ellp_dist_fx, 983); /*0.03 in Q15 ,Q8 state*/ - + tmp = sub( Etot, hNoiseEst->Etot_l_lp_fx ); /* Q8 */ + hNoiseEst->lt_Ellp_dist_fx = noise_est_AR1_Qx( tmp, hNoiseEst->lt_Ellp_dist_fx, 983 ); /*0.03 in Q15 ,Q8 state*/ /* if (st->harm_cor_cnt == 0) { @@ -1299,13 +1297,13 @@ void noise_est_fx( } else { st->lt_haco_ev = 0.99f*st->lt_haco_ev; } */ - IF ( *st_harm_cor_cnt == 0) + IF( *st_harm_cor_cnt == 0 ) { - hNoiseEst->lt_haco_ev_fx = noise_est_AR1_Qx((Word16)32767, hNoiseEst->lt_haco_ev_fx, 983); /*.03 in Q15 , Q15 state */ + hNoiseEst->lt_haco_ev_fx = noise_est_AR1_Qx( (Word16) 32767, hNoiseEst->lt_haco_ev_fx, 983 ); /*.03 in Q15 , Q15 state */ } ELSE { - hNoiseEst->lt_haco_ev_fx = mult_r(32440, hNoiseEst->lt_haco_ev_fx); /*.99 in Q15 , Q15 state */ + hNoiseEst->lt_haco_ev_fx = mult_r( 32440, hNoiseEst->lt_haco_ev_fx ); /*.99 in Q15 , Q15 state */ } @@ -1317,9 +1315,9 @@ void noise_est_fx( tmp = 0; move16(); move16(); - if( LT_16(hNoiseEst->lt_tn_track_fx , 1638 )) /* 0.05 in Q15*/ + if ( LT_16( hNoiseEst->lt_tn_track_fx, 1638 ) ) /* 0.05 in Q15*/ { - tmp = add(hNoiseEst->low_tn_track_cnt, 1); + tmp = add( hNoiseEst->low_tn_track_cnt, 1 ); } hNoiseEst->low_tn_track_cnt = tmp; move16(); @@ -1331,37 +1329,35 @@ void noise_est_fx( } else { st->act_pred = M_GAMMA * st->act_pred + (1-M_GAMMA) * 0; }*/ - Ltmp = L_mult(M_GAMMA_FX, hNoiseEst->act_pred_fx); /*Q15*Q15+1 --> Q31 , 32440= .99 Q15 */ - tmp = round_fx(Ltmp); /* Q15 */ + Ltmp = L_mult( M_GAMMA_FX, hNoiseEst->act_pred_fx ); /*Q15*Q15+1 --> Q31 , 32440= .99 Q15 */ + tmp = round_fx( Ltmp ); /* Q15 */ test(); - if ( ( GT_32(non_sta, th_sta)) /* float th_sta NB 5e10 , WB 3.5e10*/ - || (*loc_harm > 0) - ) + if ( ( GT_32( non_sta, th_sta ) ) /* float th_sta NB 5e10 , WB 3.5e10*/ + || ( *loc_harm > 0 ) ) { - tmp = mac_r(Ltmp, (-32768+M_GAMMA_FX), -32768); /* (-0.01)*(-1.0) */ + tmp = mac_r( Ltmp, ( -32768 + M_GAMMA_FX ), -32768 ); /* (-0.01)*(-1.0) */ } - hNoiseEst->act_pred_fx = tmp ; + hNoiseEst->act_pred_fx = tmp; move16(); - /*-----------------------------------------------------------------* * Background noise adaptation enable flag *-----------------------------------------------------------------*/ - Ltmp = L_mult(st_fx->voicing_fx[0], 16384); - Ltmp = L_mac(Ltmp, st_fx->voicing_fx[1], 16384); + Ltmp = L_mult( st_fx->voicing_fx[0], 16384 ); + Ltmp = L_mac( Ltmp, st_fx->voicing_fx[1], 16384 ); #ifdef BASOP_NOGLOB - cor_tmp = mac_ro(Ltmp, corr_shift,MAX_16, &Overflow); + cor_tmp = mac_ro( Ltmp, corr_shift, MAX_16, &Overflow ); #else /* BASOP_NOGLOB */ - cor_tmp = mac_r(Ltmp, corr_shift,MAX_16); + cor_tmp = mac_r( Ltmp, corr_shift, MAX_16 ); #endif - LepsP = eps_quota_fx(epsP_h[2] , epsP_l[2], - epsP_h[16], epsP_l[16] , 11 ); /* L_epsP in Q11 */ + LepsP = eps_quota_fx( epsP_h[2], epsP_l[2], + epsP_h[16], epsP_l[16], 11 ); /* L_epsP in Q11 */ /* note this epsP2/eps16 is not limited to 8 as, epsP_2_16 is !! */ - vad_2nd_stage_fx = 0; - move16(); /* background noise present - decrement counter */ + vad_2nd_stage_fx = 0; + move16(); /* background noise present - decrement counter */ /* if( ( (*st_harm_cor_cnt < 3*HC_CNT_SLOW ) && ( ( non_sta > th_sta ) || @@ -1376,8 +1372,8 @@ void noise_est_fx( ((st->act_pred > 0.8f) && (non_sta2 > th_sta)) ) */ - Ltmp = L_mult(st_fx->voicing_fx[0], 16384); /* Q15 + Q15(.5)) + 1 -> Q31 */ - cor_tmp = mac_r(Ltmp, st_fx->voicing_fx[1], 16384 ); /* Q31 -16 -> Q15 */ + Ltmp = L_mult( st_fx->voicing_fx[0], 16384 ); /* Q15 + Q15(.5)) + 1 -> Q31 */ + cor_tmp = mac_r( Ltmp, st_fx->voicing_fx[1], 16384 ); /* Q31 -16 -> Q15 */ if ( Etot < 0 ) { cor_tmp = 0; @@ -1395,44 +1391,42 @@ void noise_est_fx( test(); test(); - if( ( ( LT_16(*st_harm_cor_cnt, (3*HC_CNT_SLOW_FX) )) - && ( ( GT_32(non_sta, th_sta) ) || (LT_16(tmp_pc, TH_PC_FX) ) || ( GT_16(noise_char ,0)) ) ) - || - ( (GT_16(st_fx->ini_frame, HE_LT_CNT_INIT_FX ) ) && ( GT_16(sub(Etot, Etot_l_lp), 2560) ) ) || - ( GT_16(cor_tmp, cor_max) ) || /* Q15 */ - ( GT_32(LepsP, th_eps) ) || /* Q11 */ - ( GT_16(*loc_harm,0)) || - ((GT_16(hNoiseEst->act_pred_fx, 26214) ) && (GT_32(Lnon_sta2, th_sta) ) ) /*act_pred in Q15 , th_sta in Q10 */ - ) + if ( ( ( LT_16( *st_harm_cor_cnt, ( 3 * HC_CNT_SLOW_FX ) ) ) && ( ( GT_32( non_sta, th_sta ) ) || ( LT_16( tmp_pc, TH_PC_FX ) ) || ( GT_16( noise_char, 0 ) ) ) ) || + ( ( GT_16( st_fx->ini_frame, HE_LT_CNT_INIT_FX ) ) && ( GT_16( sub( Etot, Etot_l_lp ), 2560 ) ) ) || + ( GT_16( cor_tmp, cor_max ) ) || /* Q15 */ + ( GT_32( LepsP, th_eps ) ) || /* Q11 */ + ( GT_16( *loc_harm, 0 ) ) || + ( ( GT_16( hNoiseEst->act_pred_fx, 26214 ) ) && ( GT_32( Lnon_sta2, th_sta ) ) ) /*act_pred in Q15 , th_sta in Q10 */ + ) { vad_2nd_stage_fx = 1; - move16(); /* active signal present - increment counter */ + move16(); /* active signal present - increment counter */ } - tmp = 2; - move16(); /* Signal present */ - if(vad_2nd_stage_fx == 0 ) + tmp = 2; + move16(); /* Signal present */ + if ( vad_2nd_stage_fx == 0 ) { tmp = -1; - move16(); /* Background present */ + move16(); /* Background present */ } - hNoiseEst->aEn = add(hNoiseEst->aEn, tmp); + hNoiseEst->aEn = add( hNoiseEst->aEn, tmp ); - hNoiseEst->aEn = s_min(hNoiseEst->aEn,6); - hNoiseEst->aEn = s_max(hNoiseEst->aEn,0); + hNoiseEst->aEn = s_min( hNoiseEst->aEn, 6 ); + hNoiseEst->aEn = s_max( hNoiseEst->aEn, 0 ); #ifdef IVAS_CODE /*-----------------------------------------------------------------* * Stereo classifier - save raw aEn *-----------------------------------------------------------------*/ - if (hStereoClassif != NULL) + if ( hStereoClassif != NULL ) { - if ((non_sta > th_sta) || - (tmp_pc < TH_PC) || - (0.5f * (st->voicing[0] + st->voicing[1]) > cor_max) || - (epsP[2] / epsP[16] > th_eps) || - ((hNoiseEst->act_pred > 0.8f) && (non_sta2 > th_sta))) + if ( ( non_sta > th_sta ) || + ( tmp_pc < TH_PC ) || + ( 0.5f * ( st->voicing[0] + st->voicing[1] ) > cor_max ) || + ( epsP[2] / epsP[16] > th_eps ) || + ( ( hNoiseEst->act_pred > 0.8f ) && ( non_sta2 > th_sta ) ) ) { /* active signal present - increment counter */ hStereoClassif->aEn_raw[st->idchan] = hStereoClassif->aEn_raw[st->idchan] + 2; @@ -1443,11 +1437,11 @@ void noise_est_fx( hStereoClassif->aEn_raw[st->idchan] = hStereoClassif->aEn_raw[st->idchan] - 1; } - if (hStereoClassif->aEn_raw[st->idchan] > 6) + if ( hStereoClassif->aEn_raw[st->idchan] > 6 ) { hStereoClassif->aEn_raw[st->idchan] = 6; } - else if (hStereoClassif->aEn_raw[st->idchan] < 0) + else if ( hStereoClassif->aEn_raw[st->idchan] < 0 ) { hStereoClassif->aEn_raw[st->idchan] = 0; } @@ -1459,48 +1453,48 @@ void noise_est_fx( /* comb_ahc_epsP = max(max(st->act_pred, st->lt_haco_ev), epsP_2_16_dlp); */ /* Q15 Q15 Q12 */ - comb_ahc_epsP = s_max(s_max(shr(hNoiseEst->act_pred_fx,15-12), shr(hNoiseEst->lt_haco_ev_fx, 15-12)), epsP_2_16_dlp); /* Q12 */ + comb_ahc_epsP = s_max( s_max( shr( hNoiseEst->act_pred_fx, 15 - 12 ), shr( hNoiseEst->lt_haco_ev_fx, 15 - 12 ) ), epsP_2_16_dlp ); /* Q12 */ /* comb_hcm_epsP = max(max(st->lt_haco_ev,epsP_2_16_dlp_max),epsP_0_2_ad_lp_max); */ /* Q15 Q12 Q12 */ - comb_hcm_epsP = s_max(s_max(shr(hNoiseEst->lt_haco_ev_fx,15-12), epsP_2_16_dlp_max), epsP_0_2_ad_lp_max); /* Q12 */ + comb_hcm_epsP = s_max( s_max( shr( hNoiseEst->lt_haco_ev_fx, 15 - 12 ), epsP_2_16_dlp_max ), epsP_0_2_ad_lp_max ); /* Q12 */ /*haco_ev_max = max(*st_harm_cor_cnt==0,st->lt_haco_ev); */ tmp = 0; move16(); if ( *st_harm_cor_cnt == 0 ) { - tmp = (Word16)32767; + tmp = (Word16) 32767; move16(); } - haco_ev_max = s_max(tmp, hNoiseEst->lt_haco_ev_fx); /* Q15 */ + haco_ev_max = s_max( tmp, hNoiseEst->lt_haco_ev_fx ); /* Q15 */ /* Etot_l_lp_thr = st->Etot_l_lp + (1.5f + 1.5f * (st->Etot_lp<50.0f))*st->Etot_v_h2; */ tmp = 12288; - move16();/* 1.5 Q13 */ - if( LT_16(hNoiseEst->Etot_lp_fx, 12800 )) /* 50.0 in Q8 */ + move16(); /* 1.5 Q13 */ + if ( LT_16( hNoiseEst->Etot_lp_fx, 12800 ) ) /* 50.0 in Q8 */ { - tmp =shl(tmp,1); /*1.5 + 1.5 Q13 */ + tmp = shl( tmp, 1 ); /*1.5 + 1.5 Q13 */ } - Ltmp = L_deposit_h(hNoiseEst->Etot_l_lp_fx); - Etot_l_lp_thr = round_fx(L_add(Ltmp, L_shl(L_mult(tmp, Etot_v_h2),2))); /* Q13+Q8+1 +2 = Q24 -> Q8*/ + Ltmp = L_deposit_h( hNoiseEst->Etot_l_lp_fx ); + Etot_l_lp_thr = round_fx( L_add( Ltmp, L_shl( L_mult( tmp, Etot_v_h2 ), 2 ) ) ); /* Q13+Q8+1 +2 = Q24 -> Q8*/ /* enr_bgd = Etot < Etot_l_lp_thr; */ - enr_bgd = 0; + enr_bgd = 0; move16(); - if(LT_16(Etot, Etot_l_lp_thr )) /* Q8 */ + if ( LT_16( Etot, Etot_l_lp_thr ) ) /* Q8 */ { enr_bgd = 1; - move16();/* Q0 */ + move16(); /* Q0 */ } /* cns_bgd = (epsP_0_2 > 7.95f) && (non_sta< 1e3f); */ - cns_bgd = 0 ; + cns_bgd = 0; move16(); test(); - if( (GT_16(epsP_0_2, 32563)) /* 7.95 in Q12 */ - && (LT_32(non_sta, 1024000L) ) ) /* 1e3f in Q10 ? */ + if ( ( GT_16( epsP_0_2, 32563 ) ) /* 7.95 in Q12 */ + && ( LT_32( non_sta, 1024000L ) ) ) /* 1e3f in Q10 ? */ { cns_bgd = 1; move16(); /* Q0 */ @@ -1509,7 +1503,7 @@ void noise_est_fx( /*lp_bgd = epsP_2_16_dlp_max < 0.10f; */ lp_bgd = 0; move16(); - if( LT_16(epsP_2_16_dlp_max, 410)) /*0.10 Q12 */ + if ( LT_16( epsP_2_16_dlp_max, 410 ) ) /*0.10 Q12 */ { lp_bgd = 1; move16(); /* Q0 */ @@ -1519,7 +1513,7 @@ void noise_est_fx( /* ns_mask = non_sta < 1e5f; */ ns_mask = 0; move16(); - if( LT_32(non_sta, (Word32)102400000L )) /* (1e5f in Q10)*/ + if ( LT_32( non_sta, (Word32) 102400000L ) ) /* (1e5f in Q10)*/ { ns_mask = 1; move16(); /* Q0 */ @@ -1529,7 +1523,7 @@ void noise_est_fx( /* lt_haco_mask = st->lt_haco_ev < 0.5f; */ lt_haco_mask = 0; move16(); - if( LT_16(hNoiseEst->lt_haco_ev_fx, 16384 )) /* ( .5 in Q15)*/ + if ( LT_16( hNoiseEst->lt_haco_ev_fx, 16384 ) ) /* ( .5 in Q15)*/ { lt_haco_mask = 1; move16(); /* Q0 */ @@ -1538,7 +1532,7 @@ void noise_est_fx( /* bg_haco_mask = haco_ev_max < 0.4f; */ bg_haco_mask = 0; move16(); - if( LT_16(haco_ev_max, 13107)) /* ( 0.4 in Q15)*/ + if ( LT_16( haco_ev_max, 13107 ) ) /* ( 0.4 in Q15)*/ { bg_haco_mask = 1; move16(); /* Q0 */ @@ -1549,25 +1543,25 @@ void noise_est_fx( SD_1 = 0; move16(); test(); - if( (GT_16(epsP_0_2_ad,2048)) /* 0.5 in Q12 */ - && (GT_16(epsP_0_2, 32563) )) /* 7.95 in Q12 */ + if ( ( GT_16( epsP_0_2_ad, 2048 ) ) /* 0.5 in Q12 */ + && ( GT_16( epsP_0_2, 32563 ) ) ) /* 7.95 in Q12 */ { SD_1 = 1; move16(); /* Q0 */ } - SD_1_inv = sub(1, SD_1); /* Q0 */ + SD_1_inv = sub( 1, SD_1 ); /* Q0 */ /* NB "STL::test()"; has a cost of 2, using bitwise "s_and" , "s_or" at a cost of 1 */ /* NB only lowest bit position is used, result is always 0 or 1 */ /* bg_bgd3 = enr_bgd || ( ( cns_bgd || lp_bgd ) && ns_mask && lt_haco_mask && SD_1==0 ); */ - tmp = s_and(s_and(s_and(s_or(cns_bgd, lp_bgd), ns_mask), lt_haco_mask ), SD_1_inv); - bg_bgd3 = s_or(enr_bgd, tmp); + tmp = s_and( s_and( s_and( s_or( cns_bgd, lp_bgd ), ns_mask ), lt_haco_mask ), SD_1_inv ); + bg_bgd3 = s_or( enr_bgd, tmp ); /*PD_1 = (epsP_2_16_dlp_max < 0.10f ) ; */ PD_1 = 0; move16(); - if( (LT_16( epsP_2_16_dlp_max, 410))) /* 0.10 in Q12 */ + if ( ( LT_16( epsP_2_16_dlp_max, 410 ) ) ) /* 0.10 in Q12 */ { PD_1 = 1; move16(); /* Q0 */ @@ -1576,7 +1570,7 @@ void noise_est_fx( /*PD_2 = (epsP_0_2_ad_lp_max < 0.10f ) ; */ PD_2 = 0; move16(); - if( (LT_16( epsP_0_2_ad_lp_max, 410))) /* 0.10 in Q12 */ + if ( ( LT_16( epsP_0_2_ad_lp_max, 410 ) ) ) /* 0.10 in Q12 */ { PD_2 = 1; move16(); /* Q0 */ @@ -1585,7 +1579,7 @@ void noise_est_fx( /*PD_3 = (comb_ahc_epsP < 0.85f ); */ PD_3 = 0; move16(); - if( (LT_16(comb_ahc_epsP, 3482 ))) /* 0.85 in Q12 */ + if ( ( LT_16( comb_ahc_epsP, 3482 ) ) ) /* 0.85 in Q12 */ { PD_3 = 1; move16(); /* Q0 */ @@ -1594,7 +1588,7 @@ void noise_est_fx( /* PD_4 = comb_ahc_epsP < 0.15f; */ PD_4 = 0; move16(); - if( (LT_16(comb_ahc_epsP, 614))) /* 0.15 in Q12 */ + if ( ( LT_16( comb_ahc_epsP, 614 ) ) ) /* 0.15 in Q12 */ { PD_4 = 1; move16(); /* Q0 */ @@ -1603,7 +1597,7 @@ void noise_est_fx( /*PD_5 = comb_hcm_epsP < 0.30f; */ PD_5 = 0; move16(); - if( (LT_16(comb_hcm_epsP, 1229))) /* 0.30 in Q12 */ + if ( ( LT_16( comb_hcm_epsP, 1229 ) ) ) /* 0.30 in Q12 */ { PD_5 = 1; move16(); /* Q0 */ @@ -1617,9 +1611,8 @@ void noise_est_fx( test(); test(); test(); - if( ( (SD_1 == 0) || (LT_16(Etot, Etot_l_lp_thr))) - && (bg_haco_mask != 0) && ( LT_16(hNoiseEst->act_pred_fx, 27853 ) ) /* 0.85f in Q15 */ - && (LT_16(hNoiseEst->Etot_lp_fx, 50*256) )) /* 50.0 in Q8 */ + if ( ( ( SD_1 == 0 ) || ( LT_16( Etot, Etot_l_lp_thr ) ) ) && ( bg_haco_mask != 0 ) && ( LT_16( hNoiseEst->act_pred_fx, 27853 ) ) /* 0.85f in Q15 */ + && ( LT_16( hNoiseEst->Etot_lp_fx, 50 * 256 ) ) ) /* 50.0 in Q8 */ { BG_1 = 1; move16(); @@ -1628,50 +1621,49 @@ void noise_est_fx( /* PAU = (st->aEn==0) || ( (Etot < 55.0f) && (SD_1==0) && ( ( PD_3 && (PD_1 || PD_2 ) ) || ( PD_4 || PD_5 ) ) ); */ - PAU=0; - move16();/*Q0*/ - if(hNoiseEst->aEn == 0) + PAU = 0; + move16(); /*Q0*/ + if ( hNoiseEst->aEn == 0 ) { PAU = 1; - move16();/*Q0*/ + move16(); /*Q0*/ } tmp = 0; - move16();/*Q0*/ - if( LT_16(Etot, 55*256)) /*55.0 in Q8 */ + move16(); /*Q0*/ + if ( LT_16( Etot, 55 * 256 ) ) /*55.0 in Q8 */ { tmp = 1; - move16();/*Q0*/ + move16(); /*Q0*/ } - tmp = s_and(tmp, SD_1_inv); - PAU = s_or(PAU, s_and(tmp, s_or(s_and(PD_3, s_or(PD_1, PD_2 )) , s_or( PD_4, PD_5 )))) ; + tmp = s_and( tmp, SD_1_inv ); + PAU = s_or( PAU, s_and( tmp, s_or( s_and( PD_3, s_or( PD_1, PD_2 ) ), s_or( PD_4, PD_5 ) ) ) ); /* NEW_POS_BG = (PAU | BG_1) & bg_bgd3; note bitwise logic in float */ - NEW_POS_BG = s_and(s_or(PAU, BG_1),bg_bgd3); + NEW_POS_BG = s_and( s_or( PAU, BG_1 ), bg_bgd3 ); /* Original silence detector works in most cases */ /* aE_bgd = (st->aEn == 0);*/ aE_bgd = 0; move16(); - if(hNoiseEst->aEn == 0) + if ( hNoiseEst->aEn == 0 ) { aE_bgd = 1; move16(); } - /* When the signal dynamics is high and the energy is close to the background estimate */ /* sd1_bgd = (st->sign_dyn_lp > 15) && (Etot - st->Etot_l_lp ) < 2*st->Etot_v_h2 && st->harm_cor_cnt > 20; */ - sd1_bgd = 0; + sd1_bgd = 0; move16(); test(); test(); - if ( ( GT_16(hNoiseEst->sign_dyn_lp_fx, 15*256)) /* 15 in Q8 */ - && ( LT_16(sub(Etot, hNoiseEst->Etot_l_lp_fx ), shl(Etot_v_h2, 1) ) ) /* Q8 , Etot_v_h2 has limited dynmics can be upscaled*/ - && (GT_16(*st_harm_cor_cnt, 20) ) ) + if ( ( GT_16( hNoiseEst->sign_dyn_lp_fx, 15 * 256 ) ) /* 15 in Q8 */ + && ( LT_16( sub( Etot, hNoiseEst->Etot_l_lp_fx ), shl( Etot_v_h2, 1 ) ) ) /* Q8 , Etot_v_h2 has limited dynmics can be upscaled*/ + && ( GT_16( *st_harm_cor_cnt, 20 ) ) ) { sd1_bgd = 1; move16(); @@ -1691,17 +1683,14 @@ void noise_est_fx( test(); test(); test(); - if ( ( (LT_16(hNoiseEst->act_pred_fx, 19333))&&(LT_16(hNoiseEst->lt_haco_ev_fx,7537))) /* .59 in Q15 .23 in Q15 */ - || (LT_16(hNoiseEst->act_pred_fx, 12452) ) /* .38 in Q15 */ - || ((EQ_16(st_fx->element_mode, EVS_MONO) && LT_16(hNoiseEst->lt_haco_ev_fx, 4915)) || (GT_16(st_fx->element_mode, EVS_MONO) && LT_16(hNoiseEst->lt_haco_ev_fx, 2621)) ) /* .15 in Q15 || 0.08 */ - || (LT_16(non_staB, 50*256 ) ) /* 50.0 in Q8 */ - || aE_bgd != 0 - || ( (LT_16(Etot,10752)) /* 42 in Q8 */ - && (GT_16(hNoiseEst->harm_cor_cnt, 10) ) - && ( LT_16(hNoiseEst->lt_haco_ev_fx, 11469) ) /* 0.35 in Q15 */ - && ( LT_16(hNoiseEst->act_pred_fx, 26214) ) /* 0.80 in Q15 */ - ) - ) + if ( ( ( LT_16( hNoiseEst->act_pred_fx, 19333 ) ) && ( LT_16( hNoiseEst->lt_haco_ev_fx, 7537 ) ) ) /* .59 in Q15 .23 in Q15 */ + || ( LT_16( hNoiseEst->act_pred_fx, 12452 ) ) /* .38 in Q15 */ + || ( ( EQ_16( st_fx->element_mode, EVS_MONO ) && LT_16( hNoiseEst->lt_haco_ev_fx, 4915 ) ) || ( GT_16( st_fx->element_mode, EVS_MONO ) && LT_16( hNoiseEst->lt_haco_ev_fx, 2621 ) ) ) /* .15 in Q15 || 0.08 */ + || ( LT_16( non_staB, 50 * 256 ) ) /* 50.0 in Q8 */ + || aE_bgd != 0 || ( ( LT_16( Etot, 10752 ) ) /* 42 in Q8 */ + && ( GT_16( hNoiseEst->harm_cor_cnt, 10 ) ) && ( LT_16( hNoiseEst->lt_haco_ev_fx, 11469 ) ) /* 0.35 in Q15 */ + && ( LT_16( hNoiseEst->act_pred_fx, 26214 ) ) /* 0.80 in Q15 */ + ) ) { tmp = 1; move16(); @@ -1711,10 +1700,9 @@ void noise_est_fx( move16(); test(); test(); - if ( ( LT_16(st_fx->ini_frame, HE_LT_CNT_INIT_FX )) - && ( GT_16(hNoiseEst->harm_cor_cnt,5)) /* > 5 Q0 */ - && ( LT_16(sub(Etot, hNoiseEst->Etot_lp_fx),1792 )) /* 7 in Q8 */ - && ( NE_16(tmp, 0)) ) + if ( ( LT_16( st_fx->ini_frame, HE_LT_CNT_INIT_FX ) ) && ( GT_16( hNoiseEst->harm_cor_cnt, 5 ) ) /* > 5 Q0 */ + && ( LT_16( sub( Etot, hNoiseEst->Etot_lp_fx ), 1792 ) ) /* 7 in Q8 */ + && ( NE_16( tmp, 0 ) ) ) { tn_ini = 1; move16(); @@ -1725,8 +1713,7 @@ void noise_est_fx( bg_bgd2 = 0; move16(); test(); - if ( ( LT_16(Etot, Etot_l_lp_thr)) - || (tn_ini != 0 ) ) + if ( ( LT_16( Etot, Etot_l_lp_thr ) ) || ( tn_ini != 0 ) ) { bg_bgd2 = 1; move16(); /* Q0 */ @@ -1738,13 +1725,13 @@ void noise_est_fx( || tn_ini ) */ tmp = 0; move16(); - if( GT_16(hNoiseEst->lt_tn_track_fx, 29491 )) /* .90 in Q15 */ + if ( GT_16( hNoiseEst->lt_tn_track_fx, 29491 ) ) /* .90 in Q15 */ { tmp = 1; move16(); } - IF ( s_or(s_and(bg_bgd2 , s_or(aE_bgd, s_or(sd1_bgd, s_or(tmp, NEW_POS_BG)))), tn_ini) ) + IF( s_or( s_and( bg_bgd2, s_or( aE_bgd, s_or( sd1_bgd, s_or( tmp, NEW_POS_BG ) ) ) ), tn_ini ) ) { /*if( ( ( st->act_pred < 0.85f ) && (aE_bgd !=0) @@ -1762,13 +1749,13 @@ void noise_est_fx( test(); test(); test(); - test(); /* for the ELSE IF below*/ + test(); /* for the ELSE IF below*/ test(); test(); test(); test(); test(); - test(); /* for the ELSE IF below*/ + test(); /* for the ELSE IF below*/ test(); test(); @@ -1787,24 +1774,21 @@ void noise_est_fx( test(); test(); test(); - IF( ( ( LT_16(hNoiseEst->act_pred_fx, 27853)) /* 0.85 in Q15 */ - && ( NE_16(aE_bgd ,0) ) - && ( (LT_16(hNoiseEst->lt_Ellp_dist_fx, 10*256) ) || ( NE_16(sd1_bgd, 0) ) ) /* 10.0 in Q8*/ - && ( LT_16(hNoiseEst->lt_tn_dist_fx, 40*256 ) ) /* 40.0 in Q8*/ - && ( LT_16(sub(Etot, hNoiseEst->totalNoise_fx), 10*256) ) /* 10.0 in Q8*/ - ) - || ( (hNoiseEst->first_noise_updt == 0) && (GT_16(hNoiseEst->harm_cor_cnt,80) ) - && ( aE_bgd != 0 ) && (GT_16(hNoiseEst->lt_aEn_zero_fx, 16384) ) /*.5 in Q15*/ - ) - || ( (tn_ini != 0 ) && ( ( aE_bgd != 0 ) || ( LT_16(non_staB, 10*256) ) || (GT_16(hNoiseEst->harm_cor_cnt, 80) ) ) /* 10.0 in Q8*/ - ) - ) + IF( ( ( LT_16( hNoiseEst->act_pred_fx, 27853 ) ) /* 0.85 in Q15 */ + && ( NE_16( aE_bgd, 0 ) ) && ( ( LT_16( hNoiseEst->lt_Ellp_dist_fx, 10 * 256 ) ) || ( NE_16( sd1_bgd, 0 ) ) ) /* 10.0 in Q8*/ + && ( LT_16( hNoiseEst->lt_tn_dist_fx, 40 * 256 ) ) /* 40.0 in Q8*/ + && ( LT_16( sub( Etot, hNoiseEst->totalNoise_fx ), 10 * 256 ) ) /* 10.0 in Q8*/ + ) || + ( ( hNoiseEst->first_noise_updt == 0 ) && ( GT_16( hNoiseEst->harm_cor_cnt, 80 ) ) && ( aE_bgd != 0 ) && ( GT_16( hNoiseEst->lt_aEn_zero_fx, 16384 ) ) /*.5 in Q15*/ + ) || + ( ( tn_ini != 0 ) && ( ( aE_bgd != 0 ) || ( LT_16( non_staB, 10 * 256 ) ) || ( GT_16( hNoiseEst->harm_cor_cnt, 80 ) ) ) /* 10.0 in Q8*/ + ) ) { updt_step = 32767; move16(); hNoiseEst->first_noise_updt = 1; - FOR( i=0; i< NB_BANDS; i++ ) + FOR( i = 0; i < NB_BANDS; i++ ) { hNoiseEst->bckr_fx[i] = tmpN[i]; move32(); @@ -1817,21 +1801,17 @@ void noise_est_fx( ( st->harm_cor_cnt > 50 && st->first_noise_updt > 30 && aE_bgd && st->lt_aEn_zero>0.5f ) || tn_ini ) */ - ELSE IF ( ( ( LT_16(hNoiseEst->act_pred_fx, 26214)) /* .8 in Q15*/ - && ( ( aE_bgd != 0 ) || ( PAU != 0 ) ) - && (LT_16(hNoiseEst->lt_haco_ev_fx, 3277) ) ) /* .10 in q15*/ - || ( ( LT_16(hNoiseEst->act_pred_fx, 22938 ) ) /* 0.70 in Q15 */ - && ( (aE_bgd!=0 ) || ( LT_16(non_staB, 17*256 ) ) )/* 17.0 in Q8 */ - && ( PAU != 0 ) - && ( LT_16(hNoiseEst->lt_haco_ev_fx,4915) ) /* 0.15 in Q15 */ - ) - || ( (GT_16(hNoiseEst->harm_cor_cnt, 80) ) && (GT_16(hNoiseEst->totalNoise_fx, 5*256) ) /* 5.0 in Q8 */ - && ( LT_16(Etot, s_max((Word16)1*256, add(Etot_l_lp, add(hNoiseEst->Etot_v_h2_fx,shr(hNoiseEst->Etot_v_h2_fx,1))))) ) /* 1.5= 1.0+.5 */ - ) - || ( (GT_16(hNoiseEst->harm_cor_cnt,50) ) && (GT_16(hNoiseEst->first_noise_updt, 30) ) - && (aE_bgd != 0) && (GT_16(hNoiseEst->lt_aEn_zero_fx, 16384) ) ) /*.5 in Q15*/ - || ( tn_ini != 0 ) - ) + ELSE IF( ( ( LT_16( hNoiseEst->act_pred_fx, 26214 ) ) /* .8 in Q15*/ + && ( ( aE_bgd != 0 ) || ( PAU != 0 ) ) && ( LT_16( hNoiseEst->lt_haco_ev_fx, 3277 ) ) ) /* .10 in q15*/ + || ( ( LT_16( hNoiseEst->act_pred_fx, 22938 ) ) /* 0.70 in Q15 */ + && ( ( aE_bgd != 0 ) || ( LT_16( non_staB, 17 * 256 ) ) ) /* 17.0 in Q8 */ + && ( PAU != 0 ) && ( LT_16( hNoiseEst->lt_haco_ev_fx, 4915 ) ) /* 0.15 in Q15 */ + ) || + ( ( GT_16( hNoiseEst->harm_cor_cnt, 80 ) ) && ( GT_16( hNoiseEst->totalNoise_fx, 5 * 256 ) ) /* 5.0 in Q8 */ + && ( LT_16( Etot, s_max( (Word16) 1 * 256, add( Etot_l_lp, add( hNoiseEst->Etot_v_h2_fx, shr( hNoiseEst->Etot_v_h2_fx, 1 ) ) ) ) ) ) /* 1.5= 1.0+.5 */ + ) || + ( ( GT_16( hNoiseEst->harm_cor_cnt, 50 ) ) && ( GT_16( hNoiseEst->first_noise_updt, 30 ) ) && ( aE_bgd != 0 ) && ( GT_16( hNoiseEst->lt_aEn_zero_fx, 16384 ) ) ) /*.5 in Q15*/ + || ( tn_ini != 0 ) ) { updt_step = 3277; @@ -1847,15 +1827,10 @@ void noise_est_fx( test(); test(); test(); - IF ( ( aE_bgd==0 ) - && ( LT_16(hNoiseEst->harm_cor_cnt, 50) ) - && ( ( GT_16(hNoiseEst->act_pred_fx, 19661) ) /* 0.6 in Q15*/ - || ( ( tn_ini==0 ) - && (LT_16(sub(Etot_l_lp, hNoiseEst->totalNoise_fx),10*256) ) /* 10.0 in Q8 */ - && (GT_16(non_staB, 8*256) ) /* 8.0 in in Q8*/ - ) - ) - ) + IF( ( aE_bgd == 0 ) && ( LT_16( hNoiseEst->harm_cor_cnt, 50 ) ) && ( ( GT_16( hNoiseEst->act_pred_fx, 19661 ) ) /* 0.6 in Q15*/ + || ( ( tn_ini == 0 ) && ( LT_16( sub( Etot_l_lp, hNoiseEst->totalNoise_fx ), 10 * 256 ) ) /* 10.0 in Q8 */ + && ( GT_16( non_staB, 8 * 256 ) ) /* 8.0 in in Q8*/ + ) ) ) { updt_step = 328; move16(); /* 0.01 Q15 */ @@ -1864,24 +1839,24 @@ void noise_est_fx( IF (updt_step > 0 ) { */ - hNoiseEst->first_noise_updt = 1; + hNoiseEst->first_noise_updt = 1; move16(); - FOR( i=0; i< NB_BANDS; i++ ) + FOR( i = 0; i < NB_BANDS; i++ ) { /* st->bckr[i] = st->bckr[i] + updt_step * (tmpN[i]-st->bckr[i]);*/ /* 32 bit state update */ - Ltmp = L_sub(tmpN[i], hNoiseEst->bckr_fx[i]); /*Q_new+Q_SCALE*/ - Ltmp = Mult_32_16(Ltmp, updt_step ); /* Q_new+Q_SCALE+15+1 -16*/ - hNoiseEst->bckr_fx[i] = L_add(Ltmp, hNoiseEst->bckr_fx[i]); + Ltmp = L_sub( tmpN[i], hNoiseEst->bckr_fx[i] ); /*Q_new+Q_SCALE*/ + Ltmp = Mult_32_16( Ltmp, updt_step ); /* Q_new+Q_SCALE+15+1 -16*/ + hNoiseEst->bckr_fx[i] = L_add( Ltmp, hNoiseEst->bckr_fx[i] ); move32(); } /* } */ } /*else if (aE_bgd || st->harm_cor_cnt > 100 )*/ - ELSE IF ( (aE_bgd !=0) || (GT_16(hNoiseEst->harm_cor_cnt, 100))) + ELSE IF( ( aE_bgd != 0 ) || ( GT_16( hNoiseEst->harm_cor_cnt, 100 ) ) ) { - hNoiseEst->first_noise_updt = add(hNoiseEst->first_noise_updt,1); + hNoiseEst->first_noise_updt = add( hNoiseEst->first_noise_updt, 1 ); } } ELSE @@ -1889,47 +1864,43 @@ void noise_est_fx( /* If in music lower bckr to drop further */ test(); test(); - IF ( (GT_16(hNoiseEst->low_tn_track_cnt, 300)) - && (GT_16(hNoiseEst->lt_haco_ev_fx, 29491 ) ) /*.9 in Q15 */ - && (hNoiseEst->totalNoise_fx > 0 ) ) + IF( ( GT_16( hNoiseEst->low_tn_track_cnt, 300 ) ) && ( GT_16( hNoiseEst->lt_haco_ev_fx, 29491 ) ) /*.9 in Q15 */ + && ( hNoiseEst->totalNoise_fx > 0 ) ) { updt_step = -655; - move16(); /* for debug purposes */ - FOR( i=0; i< NB_BANDS; i++ ) + move16(); /* for debug purposes */ + FOR( i = 0; i < NB_BANDS; i++ ) { - IF( GT_32(hNoiseEst->bckr_fx[i], L_shl(Le_min_scaled, 1L) )) /* 2*E_MIN(float) in float, here we use 2*Le_min_scaled Q_new+Q_SCALE */ + IF( GT_32( hNoiseEst->bckr_fx[i], L_shl( Le_min_scaled, 1L ) ) ) /* 2*E_MIN(float) in float, here we use 2*Le_min_scaled Q_new+Q_SCALE */ { /* st->bckr[i] = 0.98f*st->bckr[i]; */ - hNoiseEst->bckr_fx[i] = Mult_32_16(hNoiseEst->bckr_fx[i], 32113); /* .98 in Q15 */ - move32(); /* move to array */ + hNoiseEst->bckr_fx[i] = Mult_32_16( hNoiseEst->bckr_fx[i], 32113 ); /* .98 in Q15 */ + move32(); /* move to array */ } } } /*st->lt_aEn_zero = 0.2f * (st->aEn==0) + (1-0.2f) *st->lt_aEn_zero;*/ /* y(n+1)= alpha*tmp + (1-alpha)*y(n) */ - tmp=0; + tmp = 0; move16(); - if(hNoiseEst->aEn == 0 ) + if ( hNoiseEst->aEn == 0 ) { - tmp=32767; + tmp = 32767; move16(); } - hNoiseEst->lt_aEn_zero_fx = noise_est_AR1_Qx(tmp, hNoiseEst->lt_aEn_zero_fx, 6554); /* alpha=0.2 , Q15 */ - + hNoiseEst->lt_aEn_zero_fx = noise_est_AR1_Qx( tmp, hNoiseEst->lt_aEn_zero_fx, 6554 ); /* alpha=0.2 , Q15 */ } #ifdef IVAS_CODE - IF (GT_16(st_fx->element_mode, EVS_MONO)) + IF( GT_16( st_fx->element_mode, EVS_MONO ) ) { test(); - if (hNoiseEst->first_noise_updt_cnt_fx > 0 && LT_16(hNoiseEst->first_noise_updt_cnt_fx, 100)) + if ( hNoiseEst->first_noise_updt_cnt_fx > 0 && LT_16( hNoiseEst->first_noise_updt_cnt_fx, 100 ) ) { - hNoiseEst->first_noise_updt_cnt_fx = add(hNoiseEst->first_noise_updt_cnt_fx, 1); + hNoiseEst->first_noise_updt_cnt_fx = add( hNoiseEst->first_noise_updt_cnt_fx, 1 ); } } #endif return; } - - diff --git a/lib_enc/noise_adjust_fx.c b/lib_enc/noise_adjust_fx.c index e2d506c05..1e149ad14 100644 --- a/lib_enc/noise_adjust_fx.c +++ b/lib_enc/noise_adjust_fx.c @@ -2,13 +2,13 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com_fx.h" /* Static table prototypes */ //#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*--------------------------------------------------------------------------* * noise_adjust_fx() @@ -16,13 +16,13 @@ * Calculate attenuation *--------------------------------------------------------------------------*/ -Word16 noise_adjust_fx( /* o : index of noise attenuation Q0 */ - const Word16 *coeffs_norm, /* i : normalized coefficients Qx */ - const Word16 qx, /* i : Q value of coeffs_norm */ - const Word16 *bitalloc, /* i : bit allocation Q0 */ - const Word16 *sfm_start, /* i : band start Q0 */ - const Word16 *sfm_end, /* i : band end Q0 */ - const Word16 core_sfm /* i : index of the end band for core Q0 */ +Word16 noise_adjust_fx( /* o : index of noise attenuation Q0 */ + const Word16 *coeffs_norm, /* i : normalized coefficients Qx */ + const Word16 qx, /* i : Q value of coeffs_norm */ + const Word16 *bitalloc, /* i : bit allocation Q0 */ + const Word16 *sfm_start, /* i : band start Q0 */ + const Word16 *sfm_end, /* i : band end Q0 */ + const Word16 core_sfm /* i : index of the end band for core Q0 */ ) { Word16 nf_idx, sfm, bin, num_coeffs; @@ -33,29 +33,29 @@ Word16 noise_adjust_fx( /* o : index of noise attenuation num_coeffs = 0; move16(); - FOR (sfm = 0; sfm <= core_sfm; sfm++) + FOR( sfm = 0; sfm <= core_sfm; sfm++ ) { - IF (bitalloc[sfm] == 0) + IF( bitalloc[sfm] == 0 ) { - FOR (bin = sfm_start[sfm]; bin < sfm_end[sfm]; bin++) + FOR( bin = sfm_start[sfm]; bin < sfm_end[sfm]; bin++ ) { - IF (coeffs_norm[bin] == 0) + IF( coeffs_norm[bin] == 0 ) { - E = sub(E, 1); + E = sub( E, 1 ); } ELSE { - E = add(E, sub(15+8,add(qx,norm_s(coeffs_norm[bin])))); + E = add( E, sub( 15 + 8, add( qx, norm_s( coeffs_norm[bin] ) ) ) ); } - num_coeffs = add(num_coeffs, 1); + num_coeffs = add( num_coeffs, 1 ); } } } - IF (num_coeffs != 0) + IF( num_coeffs != 0 ) { - inv_num_coeffs = div_s(1,num_coeffs); /* Q15 */ - E = mult(E,inv_num_coeffs); /* Q0 (0+15-15) */ + inv_num_coeffs = div_s( 1, num_coeffs ); /* Q15 */ + E = mult( E, inv_num_coeffs ); /* Q0 (0+15-15) */ } ELSE { @@ -63,8 +63,8 @@ Word16 noise_adjust_fx( /* o : index of noise attenuation move16(); } - diff = sub(7, E); - nf_idx = s_min(s_max(diff,0),3); + diff = sub( 7, E ); + nf_idx = s_min( s_max( diff, 0 ), 3 ); return nf_idx; } diff --git a/lib_enc/normalizecoefs_fx.c b/lib_enc/normalizecoefs_fx.c index 5797032ca..816f8531d 100644 --- a/lib_enc/normalizecoefs_fx.c +++ b/lib_enc/normalizecoefs_fx.c @@ -2,13 +2,13 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ +#include "options.h" /* Compilation switches */ #include "cnst.h" /* Common constants */ //#include "basop_mpy.h" //#include "prot_fx.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------------- @@ -18,12 +18,12 @@ *--------------------------------------------------------------------------*/ void normalizecoefs_fx( - Word32 *coefs, /* i : Input vector (Q12) */ - const Word16 *ynrm, /* i : quantization indices for norms */ - const Word16 num_bands, /* i : Number of bands */ - const Word16 *band_start, /* i : Start of bands */ - const Word16 *band_end, /* i : End of bands */ - Word16 *coefs_norm /* o : Normalized output vector */ + Word32 *coefs, /* i : Input vector (Q12) */ + const Word16 *ynrm, /* i : quantization indices for norms */ + const Word16 num_bands, /* i : Number of bands */ + const Word16 *band_start, /* i : Start of bands */ + const Word16 *band_end, /* i : End of bands */ + Word16 *coefs_norm /* o : Normalized output vector */ ) { Word16 band, j, k, r, v; @@ -33,33 +33,33 @@ void normalizecoefs_fx( #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - pcoefs = coefs; + pcoefs = coefs; pcoefs16 = coefs_norm; - FOR (band = 0; band < num_bands; band++) + FOR( band = 0; band < num_bands; band++ ) { - r = s_and(ynrm[band], 1); - v = shr(ynrm[band], 1); - k = sub(sub(17, r), v); + r = s_and( ynrm[band], 1 ); + v = shr( ynrm[band], 1 ); + k = sub( sub( 17, r ), v ); subvec_start = band_start[band]; move16(); - subvec_end = band_end[band]; + subvec_end = band_end[band]; move16(); - num_coefs = sub(subvec_end, subvec_start); + num_coefs = sub( subvec_end, subvec_start ); - FOR (j = 0; j < num_coefs; j++) + FOR( j = 0; j < num_coefs; j++ ) { - IF (r!=0) + IF( r != 0 ) { - *pcoefs = Mpy_32_16_1(*pcoefs, INV2POWHALF); + *pcoefs = Mpy_32_16_1( *pcoefs, INV2POWHALF ); move32(); } #ifdef BASOP_NOGLOB - * pcoefs16++ = round_fx_o(L_shl_o(*pcoefs++, 16 - k, &Overflow), &Overflow); /* Q12 */ + *pcoefs16++ = round_fx_o( L_shl_o( *pcoefs++, 16 - k, &Overflow ), &Overflow ); /* Q12 */ #else - BASOP_SATURATE_WARNING_OFF_EVS /* May saturate for strong peaks in a high band, in which case saturation is desirable */ - *pcoefs16++ = round_fx( L_shl(*pcoefs++, 16-k) ); /* Q12 */ + BASOP_SATURATE_WARNING_OFF_EVS /* May saturate for strong peaks in a high band, in which case saturation is desirable */ + *pcoefs16++ = round_fx( L_shl( *pcoefs++, 16 - k ) ); /* Q12 */ BASOP_SATURATE_WARNING_ON_EVS #endif } @@ -67,4 +67,3 @@ void normalizecoefs_fx( return; } - diff --git a/lib_enc/peak_vq_enc.c b/lib_enc/peak_vq_enc.c index 13ed6a6fe..c75b073a9 100644 --- a/lib_enc/peak_vq_enc.c +++ b/lib_enc/peak_vq_enc.c @@ -61,8 +61,8 @@ static int16_t sparse_code_pos( const int16_t *inp, const int16_t length, int16_ *--------------------------------------------------------------------------*/ int16_t peak_vq_enc( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const int16_t bwidth, /* i : audio bandwidth */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const int16_t bwidth, /* i : audio bandwidth */ const float *coefs, /* i : Input coefficient vector */ float *coefs_out, /* o : Quantized output vector */ const int32_t core_brate, /* i : Core bitrate */ diff --git a/lib_enc/peak_vq_enc_fx.c b/lib_enc/peak_vq_enc_fx.c index 084609b99..5b3848706 100644 --- a/lib_enc/peak_vq_enc_fx.c +++ b/lib_enc/peak_vq_enc_fx.c @@ -4,24 +4,23 @@ #include #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ //#include "prot_fx.h" #include "rom_enc.h" #include "rom_com_fx.h" #include "rom_com.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------------- * Local function prototypes *--------------------------------------------------------------------------*/ -static void quant_peaks_fx(BSTR_ENC_HANDLE hBstr, const Word32*, Word32*, const Word32*, - Word16*, const Word16, const Word32, const Word16); -static Word16 hvq_code_pos_fx(BSTR_ENC_HANDLE hBstr, const Word16 *inp, const Word16 length, const Word16 num_peaks); -static Word16 sparse_code_pos_fx(const Word16 *inp, const Word16 length, Word16 *result); +static void quant_peaks_fx( BSTR_ENC_HANDLE hBstr, const Word32 *, Word32 *, const Word32 *, Word16 *, const Word16, const Word32, const Word16 ); +static Word16 hvq_code_pos_fx( BSTR_ENC_HANDLE hBstr, const Word16 *inp, const Word16 length, const Word16 num_peaks ); +static Word16 sparse_code_pos_fx( const Word16 *inp, const Word16 length, Word16 *result ); /*-------------------------------------------------------------------------- * peak_vq_enc_fx() @@ -30,17 +29,17 @@ static Word16 sparse_code_pos_fx(const Word16 *inp, const Word16 length, Word16 *--------------------------------------------------------------------------*/ Word16 peak_vq_enc_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 bwidth, /* i : audio bandwidth */ - const Word32 *coefs, /* i : Input coefficient vector Q12 */ - Word32 *coefs_out, /* o : Quantized output vector Q12 */ - const Word32 core_brate, /* i : Core bitrate */ - const Word16 num_bits, /* i : Number of bits for HVQ */ - const Word16 vq_peaks, /* i : Number of identified peaks */ - const Word16 *ynrm, /* i : Envelope coefficients */ - Word16 *R, /* i/o: Bit allocation/updated bit allocation */ - Word16 *vq_peak_idx, /* i : Peak index vector */ - Word32 *nf_gains /* i : Estimated noise floor gains Q12 */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 bwidth, /* i : audio bandwidth */ + const Word32 *coefs, /* i : Input coefficient vector Q12 */ + Word32 *coefs_out, /* o : Quantized output vector Q12 */ + const Word32 core_brate, /* i : Core bitrate */ + const Word16 num_bits, /* i : Number of bits for HVQ */ + const Word16 vq_peaks, /* i : Number of identified peaks */ + const Word16 *ynrm, /* i : Envelope coefficients */ + Word16 *R, /* i/o: Bit allocation/updated bit allocation */ + Word16 *vq_peak_idx, /* i : Peak index vector */ + Word32 *nf_gains /* i : Estimated noise floor gains Q12 */ ) { Word16 pos_bits; @@ -75,7 +74,7 @@ Word16 peak_vq_enc_fx( const Word32 *pCoefs; Word32 acc; UWord16 dontCare16; - Word32 manE_peak, manPeakGains, manPkEnrg; /* Due to very wide dynamic range, use floating point format, i.e., (man, exp) */ + Word32 manE_peak, manPeakGains, manPkEnrg; /* Due to very wide dynamic range, use floating point format, i.e., (man, exp) */ Word16 expE_peak, expPeakGains, expPkEnrg; Word16 *pSelBnds; Word16 sel_bnds[HVQ_NUM_SFM_24k]; @@ -85,10 +84,10 @@ Word16 peak_vq_enc_fx( Word16 n_sel_bnds; UWord32 lsb; - assert((core_brate > HQ_16k40 && core_brate <= HQ_48k) && "HVQ rate not supported"); + assert( ( core_brate > HQ_16k40 && core_brate <= HQ_48k ) && "HVQ rate not supported" ); - //PMT("max_peaks equation needs to be converted") - max_peaks = (Word16)((core_brate * HVQ_PEAKS_PER_DELTA + HVQ_PEAKS_PER_DELTA_OFFS) / HVQ_PEAKS_BPS_DELTA); + // PMT("max_peaks equation needs to be converted") + max_peaks = (Word16) ( ( core_brate * HVQ_PEAKS_PER_DELTA + HVQ_PEAKS_PER_DELTA_OFFS ) / HVQ_PEAKS_BPS_DELTA ); bits = 0; @@ -97,67 +96,69 @@ Word16 peak_vq_enc_fx( move16(); - set16_fx(coefs_pvq, 0, HVQ_PVQ_BUF_LEN ); - set32_fx(pvq_vector, 0, HVQ_PVQ_BUF_LEN ); - set16_fx(pvq_vector_norm, 0, HVQ_PVQ_BUF_LEN ); - set16_fx(npulses, 0, MAX_PVQ_BANDS ); + set16_fx( coefs_pvq, 0, HVQ_PVQ_BUF_LEN ); + set32_fx( pvq_vector, 0, HVQ_PVQ_BUF_LEN ); + set16_fx( pvq_vector_norm, 0, HVQ_PVQ_BUF_LEN ); + set16_fx( npulses, 0, MAX_PVQ_BANDS ); bin_th = HVQ_THRES_BIN_32k; move16(); - bin_th2 = HVQ_THRES_BIN_32k/HVQ_NF_GROUPS; + bin_th2 = HVQ_THRES_BIN_32k / HVQ_NF_GROUPS; move16(); /* Set bit-rate dependent variables */ - IF (LT_32(core_brate, HQ_BWE_CROSSOVER_BRATE)) + IF( LT_32( core_brate, HQ_BWE_CROSSOVER_BRATE ) ) { bin_th = HVQ_THRES_BIN_24k; move16(); - bin_th2 = HVQ_THRES_BIN_24k/HVQ_NF_GROUPS; + bin_th2 = HVQ_THRES_BIN_24k / HVQ_NF_GROUPS; move16(); } - FOR (i = 0; i < bin_th; i++) + FOR( i = 0; i < bin_th; i++ ) { pos_vec[i] = 0; move16(); } /* Quantize noise floor gains */ - FOR (i = 0; i < HVQ_NF_GROUPS; i++) + FOR( i = 0; i < HVQ_NF_GROUPS; i++ ) { - logqnorm_fx(&nf_gains[i], 12, &indx, 32, 1, 0); + logqnorm_fx( &nf_gains[i], 12, &indx, 32, 1, 0 ); /* De-quantization */ - acc = L_add(dicn_fx[indx], 0); /* Q14 */ - nf_gains[i] = L_shr(acc, 1 + 2); /* nf_gains in Q12. dicn_fx is in Q14. Need extra shift +2. */ - push_indice_fx( hBstr, IND_HVQ_NF_GAIN , (int)indx, 5); - bits = add(bits, 5); + acc = L_add( dicn_fx[indx], 0 ); /* Q14 */ + nf_gains[i] = L_shr( acc, 1 + 2 ); /* nf_gains in Q12. dicn_fx is in Q14. Need extra shift +2. */ + push_indice_fx( hBstr, IND_HVQ_NF_GAIN, (int) indx, 5 ); + bits = add( bits, 5 ); } /* Signal number of peaks */ - i = sub(max_peaks, vq_peaks); - push_indice_fx( hBstr, IND_NUM_PEAKS, (int)i, 5); - bits = add(bits, 5); + i = sub( max_peaks, vq_peaks ); + push_indice_fx( hBstr, IND_NUM_PEAKS, (int) i, 5 ); + bits = add( bits, 5 ); /* Identify position of first peak and arrange peak gains by position */ pVqPeakIdx = &vq_peak_idx[0]; low_peak_bin = bin_th; - FOR (i = 0; i < vq_peaks; i++) + FOR( i = 0; i < vq_peaks; i++ ) { indx = *pVqPeakIdx++; move16(); - IF (LT_16(indx, low_peak_bin)) + IF( LT_16( indx, low_peak_bin ) ) { low_peak_bin = indx; move16(); } /* Store the sign information. */ - IF ( coefs[indx] < 0) + IF( coefs[indx] < 0 ) { - pos_vec[indx] = -1; /* Negative. */ move16(); + pos_vec[indx] = -1; /* Negative. */ + move16(); } ELSE { - pos_vec[indx] = 1; /* Positive */ move16(); + pos_vec[indx] = 1; /* Positive */ + move16(); } } @@ -165,12 +166,13 @@ Word16 peak_vq_enc_fx( pVqPeakIdx = &vq_peak_idx[0]; pPosVec = &pos_vec[0]; pCoefs = &coefs[0]; - FOR (i = 0; i < bin_th; i++) + FOR( i = 0; i < bin_th; i++ ) { acc = *pCoefs++; - IF(*pPosVec++ != 0) + IF( *pPosVec++ != 0 ) { - *pPeakGains++ = L_abs(acc); /* in Q12 */ move32(); + *pPeakGains++ = L_abs( acc ); /* in Q12 */ + move32(); *pVqPeakIdx++ = i; move16(); } @@ -184,38 +186,39 @@ Word16 peak_vq_enc_fx( /* Quantize peak gains */ pPeakGains = &peak_gains[0]; pPgainCbIdx = &pgain_cb_idx[0]; - logqnorm_fx(pPeakGains++, 14, pPgainCbIdx++, 32, 1, 1); - vqPeaksMinus1 = sub(vq_peaks, 1); - FOR (i = 0; i < vqPeaksMinus1; i++) + logqnorm_fx( pPeakGains++, 14, pPgainCbIdx++, 32, 1, 1 ); + vqPeaksMinus1 = sub( vq_peaks, 1 ); + FOR( i = 0; i < vqPeaksMinus1; i++ ) { - logqnorm_fx(pPeakGains++, 14, pPgainCbIdx++, 45, 1, 1); + logqnorm_fx( pPeakGains++, 14, pPgainCbIdx++, 45, 1, 1 ); } /* Code quantized peak gain indices * and also scale up peak gains. */ - diffcod_fx(vq_peaks, pgain_cb_idx, &pgain_difidx[1]); + diffcod_fx( vq_peaks, pgain_cb_idx, &pgain_difidx[1] ); /* Accumulate peak energy. */ - manE_peak = L_deposit_l(0); + manE_peak = L_deposit_l( 0 ); expE_peak = 32; move16(); - FOR (i = 0; i < vq_peaks; i++) + FOR( i = 0; i < vq_peaks; i++ ) { indx = pgain_cb_idx[i]; move16(); /* Scale up peak gains */ - pgain_q[i] = L_shl(dicn_pg_fx[indx], 2); /* pgain_q in Q12 */ move32(); + pgain_q[i] = L_shl( dicn_pg_fx[indx], 2 ); /* pgain_q in Q12 */ + move32(); /* Use floating point operation to deal with wide dynamic range.l * 32-bit mantissa is used here. It should be even more accurate than * the floating-point reference code with 24-bit mantissa! */ - expPeakGains = norm_l(pgain_q[i]); - manPeakGains = L_shl(pgain_q[i], expPeakGains); - Mpy_32_32_ss(manPeakGains, manPeakGains, &manPkEnrg, &lsb); /* peak_gains square */ - expPkEnrg = shl(expPeakGains, 1); /* Multiply by 2 due to squaring. */ + expPeakGains = norm_l( pgain_q[i] ); + manPeakGains = L_shl( pgain_q[i], expPeakGains ); + Mpy_32_32_ss( manPeakGains, manPeakGains, &manPkEnrg, &lsb ); /* peak_gains square */ + expPkEnrg = shl( expPeakGains, 1 ); /* Multiply by 2 due to squaring. */ /* True floating value = manPkEng x 2^(32 - 1 - expPkEnrg - 2*12). * In this context, the 32-bit manPkEng is in Q0. * 32 is due to Mpy_32_32() only providing the 32 MSBs of the 64 bits product. * -1 is due fractional mode Multiply. 2*12 is due to square of Q12. */ - floating_point_add(&manE_peak, &expE_peak, manPkEnrg, expPkEnrg); + floating_point_add( &manE_peak, &expE_peak, manPkEnrg, expPkEnrg ); } pgain_difidx[0] = pgain_cb_idx[0]; move16(); @@ -223,18 +226,18 @@ Word16 peak_vq_enc_fx( /* Huffman coding */ hcode_l = 0; pPgainDifIdx = &pgain_difidx[1]; - FOR (i = 0; i < vqPeaksMinus1; i++) + FOR( i = 0; i < vqPeaksMinus1; i++ ) { indx = *pPgainDifIdx++; move16(); - hcode_l = add(hcode_l, pgain_huffsizn[indx]); + hcode_l = add( hcode_l, pgain_huffsizn[indx] ); } FlagN = HUFCODE; move16(); - tmp16 = extract_l(L_mult0(GAINI_BITS, vqPeaksMinus1)); - IF ( GE_16(hcode_l, tmp16)) + tmp16 = extract_l( L_mult0( GAINI_BITS, vqPeaksMinus1 ) ); + IF( GE_16( hcode_l, tmp16 ) ) { hcode_l = tmp16; move16(); @@ -242,13 +245,13 @@ Word16 peak_vq_enc_fx( move16(); } - push_indice_fx( hBstr, IND_FLAGN, (int)FlagN, 1); - push_indice_fx( hBstr, IND_PG_IDX, (int)pgain_difidx[0], GAIN0_BITS); + push_indice_fx( hBstr, IND_FLAGN, (int) FlagN, 1 ); + push_indice_fx( hBstr, IND_PG_IDX, (int) pgain_difidx[0], GAIN0_BITS ); - IF (FlagN) + IF( FlagN ) { pPgainDifIdx = &pgain_difidx[1]; - FOR (i = 0; i < vqPeaksMinus1; i++) + FOR( i = 0; i < vqPeaksMinus1; i++ ) { j = *pPgainDifIdx++; move16(); @@ -257,59 +260,60 @@ Word16 peak_vq_enc_fx( r = pgain_huffsizn[j]; move16(); - push_indice_fx( hBstr, IND_PG_IDX, (int)m, r ); + push_indice_fx( hBstr, IND_PG_IDX, (int) m, r ); } } ELSE { pPgainDifIdx = &pgain_difidx[1]; - FOR (i = 0; i < vqPeaksMinus1; i++) + FOR( i = 0; i < vqPeaksMinus1; i++ ) { - push_indice_fx( hBstr, IND_PG_IDX, (int)(*pPgainDifIdx++), GAINI_BITS ); + push_indice_fx( hBstr, IND_PG_IDX, (int) ( *pPgainDifIdx++ ), GAINI_BITS ); } } /* Number of bits used for peak gain quantization */ - bits = add(bits, add(FLAGN_BITS + GAIN0_BITS, hcode_l)); + bits = add( bits, add( FLAGN_BITS + GAIN0_BITS, hcode_l ) ); /* Add sign for peak shape normalization */ - FOR (i = 0; i < vq_peaks; i++) + FOR( i = 0; i < vq_peaks; i++ ) { indx = vq_peak_idx[i]; move16(); - peak_gains[i] = pgain_q[i]; /* Q12 */ move32(); - IF (pos_vec[indx] < 0) + peak_gains[i] = pgain_q[i]; /* Q12 */ + move32(); + IF( pos_vec[indx] < 0 ) { - peak_gains[i] = L_negate(peak_gains[i]); /* Q12 */ + peak_gains[i] = L_negate( peak_gains[i] ); /* Q12 */ } } /* Quantize peak shapes */ - FOR (i = 0; i < vqPeaksMinus1; i++) + FOR( i = 0; i < vqPeaksMinus1; i++ ) { - num_overlap_bins = sub(5, sub(vq_peak_idx[i+1], vq_peak_idx[i])); - indx = sub(vq_peak_idx[i], 2); - quant_peaks_fx(hBstr, &coefs[indx], &coefs_out[indx], &peak_gains[i], &vq_cb_idx, num_overlap_bins, core_brate, vq_peaks); - push_indice_fx( hBstr, IND_HVQ_PEAKS, (UWord16)vq_cb_idx, 8 ); - bits = add(bits, 9); + num_overlap_bins = sub( 5, sub( vq_peak_idx[i + 1], vq_peak_idx[i] ) ); + indx = sub( vq_peak_idx[i], 2 ); + quant_peaks_fx( hBstr, &coefs[indx], &coefs_out[indx], &peak_gains[i], &vq_cb_idx, num_overlap_bins, core_brate, vq_peaks ); + push_indice_fx( hBstr, IND_HVQ_PEAKS, (UWord16) vq_cb_idx, 8 ); + bits = add( bits, 9 ); } - indx = sub(vq_peak_idx[i], 2); - quant_peaks_fx(hBstr, &coefs[indx], &coefs_out[indx], &peak_gains[i], &vq_cb_idx, 0, core_brate, vq_peaks); - push_indice_fx( hBstr, IND_HVQ_PEAKS, (UWord16)vq_cb_idx, 8 ); - bits = add(bits, 9); + indx = sub( vq_peak_idx[i], 2 ); + quant_peaks_fx( hBstr, &coefs[indx], &coefs_out[indx], &peak_gains[i], &vq_cb_idx, 0, core_brate, vq_peaks ); + push_indice_fx( hBstr, IND_HVQ_PEAKS, (UWord16) vq_cb_idx, 8 ); + bits = add( bits, 9 ); /* Quantize peak positions and sign with HVQ */ pos_bits = hvq_code_pos_fx( hBstr, pos_vec, bin_th, vq_peaks ); - bits = add(bits, pos_bits); - bit_budget = sub(num_bits, bits); + bits = add( bits, pos_bits ); + bit_budget = sub( num_bits, bits ); /* Calculate number of PVQ bands to code and assign bits */ - pvq_bands = hvq_pvq_bitalloc_fx(bit_budget, core_brate, bwidth, ynrm, manE_peak, expE_peak, Rk, R, sel_bnds, &n_sel_bnds); + pvq_bands = hvq_pvq_bitalloc_fx( bit_budget, core_brate, bwidth, ynrm, manE_peak, expE_peak, Rk, R, sel_bnds, &n_sel_bnds ); /* Get band limits for concatenated PVQ target */ - hvq_concat_bands_fx(pvq_bands, sel_bnds, n_sel_bnds, hvq_band_start, hvq_band_width, hvq_band_end); + hvq_concat_bands_fx( pvq_bands, sel_bnds, n_sel_bnds, hvq_band_start, hvq_band_width, hvq_band_end ); /* Quantize PVQ bands */ pCoefsOut = coefs_out; @@ -318,9 +322,9 @@ Word16 peak_vq_enc_fx( pSelBnds = sel_bnds; m = bin_th; move16(); - FOR (k = 0; k < pvq_bands; k++) + FOR( k = 0; k < pvq_bands; k++ ) { - IF (GE_16(k, sub(pvq_bands, n_sel_bnds))) + IF( GE_16( k, sub( pvq_bands, n_sel_bnds ) ) ) { i = band_start_harm[*pSelBnds++]; move16(); @@ -331,17 +335,17 @@ Word16 peak_vq_enc_fx( j = 0; move16(); pPvqVectorBandStart = pPvqVector; - WHILE (LT_16(j, hvq_band_width[k])) + WHILE( LT_16( j, hvq_band_width[k] ) ) { - IF (*pCoefsOut++ == 0) + IF( *pCoefsOut++ == 0 ) { - *pPvqVector++ = *pCoefs; /* Q12 */ move32(); - j = add(j, 1); + *pPvqVector++ = *pCoefs; /* Q12 */ + move32(); + j = add( j, 1 ); } pCoefs++; } logqnorm_fx( pPvqVectorBandStart, 12, &pvq_norm[k], 40, hvq_band_width[k], 0 ); - } /* Normalize coefficients */ @@ -349,16 +353,16 @@ Word16 peak_vq_enc_fx( Q_coefs = 12; move16(); - bit_budget = sub(bit_budget, i_mult2(HVQ_PVQ_GAIN_BITS, pvq_bands)); + bit_budget = sub( bit_budget, i_mult2( HVQ_PVQ_GAIN_BITS, pvq_bands ) ); pvq_bits = bit_budget; move16(); set16_fx( npulses, 0, MAX_PVQ_BANDS ); - pvq_encode_frame_fx(hBstr, pvq_vector_norm, Q_coefs, coefs_pvq, gopt, npulses, pvq_inp_vector, hvq_band_start, hvq_band_end, hvq_band_width, pvq_bands, - Rk, pvq_bits, HQ_CORE ); + pvq_encode_frame_fx( hBstr, pvq_vector_norm, Q_coefs, coefs_pvq, gopt, npulses, pvq_inp_vector, hvq_band_start, hvq_band_end, hvq_band_width, pvq_bands, + Rk, pvq_bits, HQ_CORE ); - FOR (i = 0; i < pvq_bands; i++) + FOR( i = 0; i < pvq_bands; i++ ) { k_sort[i] = i; move16(); @@ -371,62 +375,62 @@ Word16 peak_vq_enc_fx( pCoefsOut = &coefs_out[0]; pSelBnds = &sel_bnds[0]; pCoefsPvq = &coefs_pvq[0]; - FOR (k = 0; k < pvq_bands; k++) + FOR( k = 0; k < pvq_bands; k++ ) { indx = pvq_norm[k]; - tmp1 = ratio(gopt[k], fg_pred[k], &exp1); - tmp1 = shr(tmp1, sub(1, exp1)); /* Q13 */ - Mpy_32_16_ss(dicn_fx[indx], tmp1, &normq, &dontCare16); /* dicn_fx in Q14, sorted_pvq_gain_pred_err_fx in Q13. */ + tmp1 = ratio( gopt[k], fg_pred[k], &exp1 ); + tmp1 = shr( tmp1, sub( 1, exp1 ) ); /* Q13 */ + Mpy_32_16_ss( dicn_fx[indx], tmp1, &normq, &dontCare16 ); /* dicn_fx in Q14, sorted_pvq_gain_pred_err_fx in Q13. */ - logqnorm_fx(&normq, 12, &pvq_norm[k], 40, 1, 0); /* normq in Q(14+(16+13)+1-32)=Q12 */ - pvq_norm[k] = sub(pvq_norm[k], 8); - IF (pvq_norm[k] < 0) + logqnorm_fx( &normq, 12, &pvq_norm[k], 40, 1, 0 ); /* normq in Q(14+(16+13)+1-32)=Q12 */ + pvq_norm[k] = sub( pvq_norm[k], 8 ); + IF( pvq_norm[k] < 0 ) { pvq_norm[k] = 0; move16(); } - push_indice_fx( hBstr, IND_HVQ_PVQ_GAIN, pvq_norm[k], HVQ_PVQ_GAIN_BITS); - pvq_bits = add(pvq_bits, HVQ_PVQ_GAIN_BITS); + push_indice_fx( hBstr, IND_HVQ_PVQ_GAIN, pvq_norm[k], HVQ_PVQ_GAIN_BITS ); + pvq_bits = add( pvq_bits, HVQ_PVQ_GAIN_BITS ); - pvq_norm[k] = add(pvq_norm[k], 8); + pvq_norm[k] = add( pvq_norm[k], 8 ); indx = pvq_norm[k]; move16(); - normq = L_add(dicn_fx[indx], 0); /* in Q14 */ + normq = L_add( dicn_fx[indx], 0 ); /* in Q14 */ j = 0; move16(); - IF (GE_16(k, sub(pvq_bands, n_sel_bnds))) + IF( GE_16( k, sub( pvq_bands, n_sel_bnds ) ) ) { i = band_start_harm[*pSelBnds++]; move16(); pCoefsOut = coefs_out + i; } - WHILE (LT_16(j, hvq_band_width[k])) + WHILE( LT_16( j, hvq_band_width[k] ) ) { - IF (EQ_32(*pCoefsOut, 0)) + IF( EQ_32( *pCoefsOut, 0 ) ) { - acc = L_mult(*pCoefsPvq++, fg_pred[k]); /* in Q(15 + 1 + 12 = 28) */ - tmp16 = extract_h(acc); /* in Q(28 - 16 = 12) */ - Mpy_32_16_ss(normq, tmp16, &acc, &dontCare16); /* acc(Q11), normq(Q14), tmp16(Q12) */ - *pCoefsOut = L_shl(acc, 12 - 11); /* Q12 */ - j = add(j, 1); + acc = L_mult( *pCoefsPvq++, fg_pred[k] ); /* in Q(15 + 1 + 12 = 28) */ + tmp16 = extract_h( acc ); /* in Q(28 - 16 = 12) */ + Mpy_32_16_ss( normq, tmp16, &acc, &dontCare16 ); /* acc(Q11), normq(Q14), tmp16(Q12) */ + *pCoefsOut = L_shl( acc, 12 - 11 ); /* Q12 */ + j = add( j, 1 ); } pCoefsOut++; } } - bits = add(bits, pvq_bits); + bits = add( bits, pvq_bits ); /* Noise fill unqantized coeffs with one gain per group */ pCoefsOut = &coefs_out[-1]; - FOR (i = 0; i < HVQ_NF_GROUPS; i++) + FOR( i = 0; i < HVQ_NF_GROUPS; i++ ) { - FOR (j = 0; j < bin_th2; j++) + FOR( j = 0; j < bin_th2; j++ ) { - IF (*(++pCoefsOut) == 0) + IF( *( ++pCoefsOut ) == 0 ) { - whiteNoise = Random(&nf_seed); /* Q15 */ - Mpy_32_16_ss(nf_gains[i], whiteNoise, pCoefsOut, &dontCare16); /* nf_gains in Q12. *pCoefsOut in Q12 */ + whiteNoise = Random( &nf_seed ); /* Q15 */ + Mpy_32_16_ss( nf_gains[i], whiteNoise, pCoefsOut, &dontCare16 ); /* nf_gains in Q12. *pCoefsOut in Q12 */ } } } @@ -441,19 +445,19 @@ Word16 peak_vq_enc_fx( *--------------------------------------------------------------------------*/ static void quant_peaks_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word32 *vect_in, /* i : Target vector in Q12 */ - Word32 *vect_out, /* i/o: Quantized vector in Q12 */ - const Word32 *peak_gain,/* i : Peak gain vector in Q12 */ - Word16 *vq_idx, /* o : Codebook index */ - const Word16 overlap, /* i : Overlap indicator */ - const Word32 core_brate,/* i : Core bitrate */ - const Word16 Npeaks /* i : Number of peaks */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word32 *vect_in, /* i : Target vector in Q12 */ + Word32 *vect_out, /* i/o: Quantized vector in Q12 */ + const Word32 *peak_gain, /* i : Peak gain vector in Q12 */ + Word16 *vq_idx, /* o : Codebook index */ + const Word16 overlap, /* i : Overlap indicator */ + const Word32 core_brate, /* i : Core bitrate */ + const Word16 Npeaks /* i : Number of peaks */ ) { - Word16 x[4]; /* Qx */ - Word16 xq[4]; /* Q15 */ - Word16 weights[4]; /* Q0 */ + Word16 x[4]; /* Qx */ + Word16 xq[4]; /* Q15 */ + Word16 weights[4]; /* Q0 */ Word16 *pWeights; Word16 i, cb_class, search_overlap, indx, cbSize; Word16 expPeakGain, manPeakGain, expIn, manIn; @@ -462,64 +466,64 @@ static void quant_peaks_fx( Word16 Qx_vec[4]; Word16 Qx = 15; - set16_fx(weights,1,4); + set16_fx( weights, 1, 4 ); /* Divide vect_in[] by peak_gain to yield x[]. */ - expPeakGain = norm_l(*peak_gain); /* exponent */ - manPeakGain = extract_h(L_shl(*peak_gain, expPeakGain)); /* mantissa */ - manPeakGain = abs_s(manPeakGain); /* Prepare for div_s() only accepting +ve. */ - FOR (i = 0; i < 4; i++) + expPeakGain = norm_l( *peak_gain ); /* exponent */ + manPeakGain = extract_h( L_shl( *peak_gain, expPeakGain ) ); /* mantissa */ + manPeakGain = abs_s( manPeakGain ); /* Prepare for div_s() only accepting +ve. */ + FOR( i = 0; i < 4; i++ ) { indx = hvq_index_mapping_fx[i]; move16(); - vectIn = L_add(vect_in[indx], 0); - expIn = norm_l(vectIn); /* exponent */ - expIn = sub(expIn, 1); - expIn = s_min(expIn, expPeakGain); /* highest Q is Q15 */ - manIn = extract_h(L_shl(vectIn, expIn)); /* mantissa */ - manIn = abs_s(manIn); /* Prepare for div_s() only accepting +ve. */ + vectIn = L_add( vect_in[indx], 0 ); + expIn = norm_l( vectIn ); /* exponent */ + expIn = sub( expIn, 1 ); + expIn = s_min( expIn, expPeakGain ); /* highest Q is Q15 */ + manIn = extract_h( L_shl( vectIn, expIn ) ); /* mantissa */ + manIn = abs_s( manIn ); /* Prepare for div_s() only accepting +ve. */ - x[i] = div_s(manIn, manPeakGain); /* in Q(15+expIn-expPeakGain) */ + x[i] = div_s( manIn, manPeakGain ); /* in Q(15+expIn-expPeakGain) */ - Qx_vec[i] = add(15, sub(expIn, expPeakGain)); - Qx = s_min(Qx, Qx_vec[i]); + Qx_vec[i] = add( 15, sub( expIn, expPeakGain ) ); + Qx = s_min( Qx, Qx_vec[i] ); /* Restore the sign destroyed by abs operations. */ - if (L_xor(vectIn, *peak_gain) < 0) /* Check the sign bits (MSB). */ + if ( L_xor( vectIn, *peak_gain ) < 0 ) /* Check the sign bits (MSB). */ { - x[i] = negate(x[i]); + x[i] = negate( x[i] ); } } - FOR (i = 0; i < 4; i++) + FOR( i = 0; i < 4; i++ ) { - IF (NE_16(Qx_vec[i], Qx)) + IF( NE_16( Qx_vec[i], Qx ) ) { - x[i] = shr(x[i], sub(Qx_vec[i], Qx)); /* Qx */ + x[i] = shr( x[i], sub( Qx_vec[i], Qx ) ); /* Qx */ } } - absPeakGain = L_abs(peak_gain[0]); - IF (vect_out[0] != 0) + absPeakGain = L_abs( peak_gain[0] ); + IF( vect_out[0] != 0 ) { - absPeakGain1 = L_abs(peak_gain[-1]); - IF (GT_32(absPeakGain1, absPeakGain)) + absPeakGain1 = L_abs( peak_gain[-1] ); + IF( GT_32( absPeakGain1, absPeakGain ) ) { weights[0] = 0; move16(); - if (vect_out[1] != 0) + if ( vect_out[1] != 0 ) { weights[1] = 0; move16(); } } } - IF (overlap > 0) + IF( overlap > 0 ) { - absPeakGain1 = L_abs(peak_gain[1]); - IF (GT_32(absPeakGain1, absPeakGain)) + absPeakGain1 = L_abs( peak_gain[1] ); + IF( GT_32( absPeakGain1, absPeakGain ) ) { - indx = sub(4, overlap); + indx = sub( 4, overlap ); pWeights = &weights[indx]; - FOR (i = 0; i < overlap; i++) + FOR( i = 0; i < overlap; i++ ) { *pWeights++ = 0; move16(); @@ -531,59 +535,59 @@ static void quant_peaks_fx( #if HVQ_VQ_DIM != 5 #error w_vquant_fx() is hard-wired to dim = 4 = (HVQ_VQ_DIM - 1). #endif - cb_class = w_vquant_fx(x, Qx, weights, 0, hvq_class_c_fx, HVQ_NUM_CLASS, 0); - IF (LT_32(core_brate, HQ_BWE_CROSSOVER_BRATE)) + cb_class = w_vquant_fx( x, Qx, weights, 0, hvq_class_c_fx, HVQ_NUM_CLASS, 0 ); + IF( LT_32( core_brate, HQ_BWE_CROSSOVER_BRATE ) ) { - indx = sub(HVQ_MAX_PEAKS_24k, Npeaks); + indx = sub( HVQ_MAX_PEAKS_24k, Npeaks ); search_overlap = hvq_cb_search_overlap24k[indx]; move16(); } ELSE { - indx = sub(HVQ_MAX_PEAKS_32k, Npeaks); + indx = sub( HVQ_MAX_PEAKS_32k, Npeaks ); search_overlap = hvq_cb_search_overlap32k[indx]; move16(); } /* Quantize */ - cbSize = add(HVQ_CB_SIZE/2, search_overlap); - IF ( cb_class == 0 ) + cbSize = add( HVQ_CB_SIZE / 2, search_overlap ); + IF( cb_class == 0 ) { - *vq_idx = w_vquant_fx(x, Qx, weights, xq, hvq_peak_cb_fx, cbSize, 0); + *vq_idx = w_vquant_fx( x, Qx, weights, xq, hvq_peak_cb_fx, cbSize, 0 ); push_indice_fx( hBstr, IND_HVQ_PEAKS, 0, 1 ); } - ELSE IF( EQ_16(cb_class, 1)) + ELSE IF( EQ_16( cb_class, 1 ) ) { - indx = sub(HVQ_CB_SIZE*2, shl(search_overlap,2)); - *vq_idx = w_vquant_fx(x, Qx, weights, xq, &hvq_peak_cb_fx[indx], cbSize, 0); - *vq_idx = add(*vq_idx, sub(HVQ_CB_SIZE/2, search_overlap)); + indx = sub( HVQ_CB_SIZE * 2, shl( search_overlap, 2 ) ); + *vq_idx = w_vquant_fx( x, Qx, weights, xq, &hvq_peak_cb_fx[indx], cbSize, 0 ); + *vq_idx = add( *vq_idx, sub( HVQ_CB_SIZE / 2, search_overlap ) ); push_indice_fx( hBstr, IND_HVQ_PEAKS, 0, 1 ); } - ELSE IF( EQ_16(cb_class, 2)) + ELSE IF( EQ_16( cb_class, 2 ) ) { - indx = sub(HVQ_CB_SIZE*2, shl(search_overlap,2)); - *vq_idx = w_vquant_fx(x, Qx, weights, xq, &hvq_peak_cb_fx[indx], cbSize, 1); - *vq_idx = add(*vq_idx, sub(HVQ_CB_SIZE/2, search_overlap)); + indx = sub( HVQ_CB_SIZE * 2, shl( search_overlap, 2 ) ); + *vq_idx = w_vquant_fx( x, Qx, weights, xq, &hvq_peak_cb_fx[indx], cbSize, 1 ); + *vq_idx = add( *vq_idx, sub( HVQ_CB_SIZE / 2, search_overlap ) ); push_indice_fx( hBstr, IND_HVQ_PEAKS, 1, 1 ); } ELSE { - *vq_idx = w_vquant_fx(x, Qx, weights, xq, hvq_peak_cb_fx, cbSize, 1); + *vq_idx = w_vquant_fx( x, Qx, weights, xq, hvq_peak_cb_fx, cbSize, 1 ); push_indice_fx( hBstr, IND_HVQ_PEAKS, 1, 1 ); } - FOR (i = 0; i < 4; i++) + FOR( i = 0; i < 4; i++ ) { indx = hvq_index_mapping_fx[i]; move16(); - IF (weights[i] != 0) + IF( weights[i] != 0 ) { - Mpy_32_16_ss(*peak_gain, xq[i], &vect_out[indx], &dontCare); /* peak_gains in Q12, xq in Q15 -> Q12. */ + Mpy_32_16_ss( *peak_gain, xq[i], &vect_out[indx], &dontCare ); /* peak_gains in Q12, xq in Q15 -> Q12. */ move32(); } } vect_out[2] = *peak_gain; - move32(); /* vect_out in Q12 */ + move32(); /* vect_out in Q12 */ return; } @@ -597,27 +601,26 @@ static void quant_peaks_fx( static Word16 sparse_code_pos_fx( const Word16 *inp, const Word16 length, - Word16 *result -) + Word16 *result ) { Word16 layer2[HVQ_CP_L2_MAX]; Word16 layer_length; - Word16 i,j,tmp; + Word16 i, j, tmp; Word16 val, idx; Word16 bits = 0; Word16 mask; - set16_fx(layer2, 0, HVQ_CP_L2_MAX); + set16_fx( layer2, 0, HVQ_CP_L2_MAX ); /*layer_length = (short)((float)length/HVQ_CP_L1_LEN + 0.5); */ - layer_length = round_fx(L_mult0(length, 13107)); /* 0+16-16, 13107 is 1/5 in Q16 */ + layer_length = round_fx( L_mult0( length, 13107 ) ); /* 0+16-16, 13107 is 1/5 in Q16 */ - FOR (j = 0; j < layer_length; j++) + FOR( j = 0; j < layer_length; j++ ) { - tmp = s_min(i_mult2(add(j,1),HVQ_CP_L1_LEN), length); - FOR (i = i_mult2(j, HVQ_CP_L1_LEN); i < tmp; i++) + tmp = s_min( i_mult2( add( j, 1 ), HVQ_CP_L1_LEN ), length ); + FOR( i = i_mult2( j, HVQ_CP_L1_LEN ); i < tmp; i++ ) { - IF (inp[i] != 0) + IF( inp[i] != 0 ) { layer2[j] = 1; move16(); @@ -626,38 +629,38 @@ static Word16 sparse_code_pos_fx( } } - FOR (i = 0; i < layer_length; i++) + FOR( i = 0; i < layer_length; i++ ) { result[i] = layer2[i]; move16(); } - bits = add(bits, layer_length); + bits = add( bits, layer_length ); - FOR (j = 0; j < layer_length; j++) + FOR( j = 0; j < layer_length; j++ ) { - IF (layer2[j] != 0) + IF( layer2[j] != 0 ) { val = 0; move16(); - tmp = s_min(i_mult2(add(j,1),HVQ_CP_L1_LEN), length); - FOR (i = i_mult2(j, HVQ_CP_L1_LEN); i < tmp; i++) + tmp = s_min( i_mult2( add( j, 1 ), HVQ_CP_L1_LEN ), length ); + FOR( i = i_mult2( j, HVQ_CP_L1_LEN ); i < tmp; i++ ) { - val = shl(val, 1); - val = s_or(val, inp[i]); + val = shl( val, 1 ); + val = s_or( val, inp[i] ); } - FOR (idx = 0; idx < HVQ_CP_MAP_LEN; idx++) + FOR( idx = 0; idx < HVQ_CP_MAP_LEN; idx++ ) { - IF (EQ_16(hvq_cp_layer1_map5[idx], val)) + IF( EQ_16( hvq_cp_layer1_map5[idx], val ) ) { BREAK; } } - mask = shl(1, HVQ_CP_MAP_IDX_LEN - 1); - FOR (i = 0; i < HVQ_CP_MAP_IDX_LEN; i++) + mask = shl( 1, HVQ_CP_MAP_IDX_LEN - 1 ); + FOR( i = 0; i < HVQ_CP_MAP_IDX_LEN; i++ ) { - result[bits++] = shr(s_and(idx, mask), sub(HVQ_CP_MAP_IDX_LEN - 1, i)); + result[bits++] = shr( s_and( idx, mask ), sub( HVQ_CP_MAP_IDX_LEN - 1, i ) ); mask >>= 1; } } @@ -673,13 +676,12 @@ static Word16 sparse_code_pos_fx( *--------------------------------------------------------------------------*/ static Word16 hvq_code_pos_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word16 *inp, const Word16 length, - const Word16 num_peaks -) + const Word16 num_peaks ) { - Word16 sparse_result[4*HVQ_THRES_BIN_32k/HVQ_CP_L1_LEN]; + Word16 sparse_result[4 * HVQ_THRES_BIN_32k / HVQ_CP_L1_LEN]; Word16 delta[HVQ_MAX_PEAKS]; Word16 peak_idx[HVQ_MAX_PEAKS]; Word16 inp_abs[HVQ_THRES_BIN_32k]; @@ -697,28 +699,28 @@ static Word16 hvq_code_pos_fx( /* Extract sorted peak index vector and sign vector */ j = 0; move16(); - FOR(i = 0; i < length; i++) + FOR( i = 0; i < length; i++ ) { - inp_abs[i] = abs_s(inp[i]); - IF (inp[i] != 0) + inp_abs[i] = abs_s( inp[i] ); + IF( inp[i] != 0 ) { peak_idx[j] = i; move16(); inp_sign[j] = inp[i]; move16(); - j = add(j, 1); + j = add( j, 1 ); } } /* Calculate delta */ - delta[0] = add(peak_idx[0], HVQ_CP_HUFF_OFFSET); + delta[0] = add( peak_idx[0], HVQ_CP_HUFF_OFFSET ); move16(); delta_max = delta[0]; move16(); - FOR (i = 1; i < num_peaks; i++) + FOR( i = 1; i < num_peaks; i++ ) { - delta[i] = sub(sub(peak_idx[i], peak_idx[i-1]), HVQ_CP_HUFF_OFFSET); - if (LT_16(delta_max, delta[i])) + delta[i] = sub( sub( peak_idx[i], peak_idx[i - 1] ), HVQ_CP_HUFF_OFFSET ); + if ( LT_16( delta_max, delta[i] ) ) { delta_max = delta[i]; move16(); @@ -728,58 +730,57 @@ static Word16 hvq_code_pos_fx( /* Calculate bits needed for huffman coding of deltas */ delta_bits = -1; move16(); - IF (LE_16(delta_max, HVQ_CP_HUFF_MAX)) + IF( LE_16( delta_max, HVQ_CP_HUFF_MAX ) ) { delta_bits = 0; move16(); - FOR (i = 0; i < num_peaks; i++) + FOR( i = 0; i < num_peaks; i++ ) { - delta_bits = add(delta_bits, hvq_cp_huff_len[delta[i]]); + delta_bits = add( delta_bits, hvq_cp_huff_len[delta[i]] ); } } /* Calculate bits neeed for sparse coding */ - sparse_bits = sparse_code_pos_fx(inp_abs, length, sparse_result); + sparse_bits = sparse_code_pos_fx( inp_abs, length, sparse_result ); /* Decide which coding mode to use */ test(); - IF (GT_16(delta_bits, sparse_bits)||delta_bits<0) + IF( GT_16( delta_bits, sparse_bits ) || delta_bits < 0 ) { - push_indice_fx( hBstr, IND_POS_IDX, HVQ_CP_SPARSE, 1); + push_indice_fx( hBstr, IND_POS_IDX, HVQ_CP_SPARSE, 1 ); - FOR (i = 0; i < sparse_bits; i++) + FOR( i = 0; i < sparse_bits; i++ ) { - push_indice_fx( hBstr, IND_POS_IDX, sparse_result[i], 1); + push_indice_fx( hBstr, IND_POS_IDX, sparse_result[i], 1 ); } - bits = add(add(bits, sparse_bits), 1); + bits = add( add( bits, sparse_bits ), 1 ); } ELSE { - push_indice_fx( hBstr, IND_POS_IDX, HVQ_CP_DELTA, 1); + push_indice_fx( hBstr, IND_POS_IDX, HVQ_CP_DELTA, 1 ); - FOR (i = 0; i < num_peaks; i++) + FOR( i = 0; i < num_peaks; i++ ) { j = delta[i]; move16(); - push_indice_fx( hBstr, IND_POS_IDX, hvq_cp_huff_val[j], hvq_cp_huff_len[j]); + push_indice_fx( hBstr, IND_POS_IDX, hvq_cp_huff_val[j], hvq_cp_huff_len[j] ); } - bits = add(add(bits, delta_bits), 1); + bits = add( add( bits, delta_bits ), 1 ); } /* Send sign */ - FOR (i = 0; i < num_peaks; i++) + FOR( i = 0; i < num_peaks; i++ ) { tmp = 1; move16(); - if (inp_sign[i] < 0) + if ( inp_sign[i] < 0 ) { tmp = 0; move16(); } - push_indice_fx( hBstr, IND_POS_IDX, tmp, 1); + push_indice_fx( hBstr, IND_POS_IDX, tmp, 1 ); } - bits = add(bits, num_peaks); + bits = add( bits, num_peaks ); return bits; } - diff --git a/lib_enc/pit_enc_fx.c b/lib_enc/pit_enc_fx.c index 93cfc2872..86343944b 100644 --- a/lib_enc/pit_enc_fx.c +++ b/lib_enc/pit_enc_fx.c @@ -3,21 +3,20 @@ ====================================================================================*/ #include #include -#include "options.h" /* Compilation switches */ +#include "options.h" /* Compilation switches */ #include "cnst.h" /* Common constants */ #include "rom_enc.h" /* Encoder static table prototypes */ -#include "rom_com_fx.h" /* Static table prototypes */ +#include "rom_com_fx.h" /* Static table prototypes */ #include "rom_com.h" /* Static table prototypes */ //#include "prot_fx.h" /* Function prototypes */ #include "rom_basop_util.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ #define inv_T0_res InvIntTable -static void limit_T0_voiced2( Word16 res, const Word16 *T_op, Word16 *T0_min, Word16 *T0_min_frac, - Word16 *T0_max, Word16 *T0_max_frac, Word16 pit_min, Word16 pit_max, Word16 i_subfr ); +static void limit_T0_voiced2( Word16 res, const Word16 *T_op, Word16 *T0_min, Word16 *T0_min_frac, Word16 *T0_max, Word16 *T0_max_frac, Word16 pit_min, Word16 pit_max, Word16 i_subfr ); /*==============================================================================*/ /* FUNCTION : pit_encode_fx() */ @@ -55,26 +54,26 @@ static void limit_T0_voiced2( Word16 res, const Word16 *T_op, Word16 *T0_min, Wo /* _ None */ /*==============================================================================*/ -Word16 pit_encode_fx( /* o : Fractional pitch for each subframe */ - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 pitch_bits[], /* i : pitch bits */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 coder_type, /* i : coding type */ - Word16 *limit_flag, /* i/o: restrained(0) or extended(1) Q limits */ - const Word16 i_subfr, /* i : subframe index */ - Word16 *exc, /* i/o: pointer to excitation signal frame */ - const Word16 L_subfr, /* i : subframe length */ - const Word16 * pitch, /* i : open loop pitch estimates in current frame */ - Word16 *T0_min, /* i/o: lower limit for close-loop search */ - Word16 *T0_max, /* i/o: higher limit for close-loop search */ - Word16 *T0, /* i/o: close loop integer pitch */ - Word16 *T0_frac, /* i/o: close loop fractional part of the pitch */ - const Word16 *h1, /* i : weighted filter input response */ - const Word16 *xn, /* i : target vector */ - const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ - const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ +Word16 pit_encode_fx( /* o : Fractional pitch for each subframe */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 pitch_bits[], /* i : pitch bits */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const Word16 L_frame, /* i : length of the frame */ + const Word16 coder_type, /* i : coding type */ + Word16 *limit_flag, /* i/o: restrained(0) or extended(1) Q limits */ + const Word16 i_subfr, /* i : subframe index */ + Word16 *exc, /* i/o: pointer to excitation signal frame */ + const Word16 L_subfr, /* i : subframe length */ + const Word16 *pitch, /* i : open loop pitch estimates in current frame */ + Word16 *T0_min, /* i/o: lower limit for close-loop search */ + Word16 *T0_max, /* i/o: higher limit for close-loop search */ + Word16 *T0, /* i/o: close loop integer pitch */ + Word16 *T0_frac, /* i/o: close loop fractional part of the pitch */ + const Word16 *h1, /* i : weighted filter input response */ + const Word16 *xn, /* i : target vector */ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ ) { Word16 pitch_cl; @@ -82,12 +81,12 @@ Word16 pit_encode_fx( /* o : Fractional pitch for each subframe Word16 L_sufr_sft; Word16 T_op[2]; /* values for two half-frames */ #ifdef REMOVE_IVAS_UNUSED_PARAMETERS_WARNING - (void)tdm_Pitch_reuse_flag; + (void) tdm_Pitch_reuse_flag; #endif L_sufr_sft = 6; move16(); - if (EQ_16(L_subfr, 2*L_SUBFR)) + if ( EQ_16( L_subfr, 2 * L_SUBFR ) ) { L_sufr_sft = 7; } @@ -95,16 +94,18 @@ Word16 pit_encode_fx( /* o : Fractional pitch for each subframe /*----------------------------------------------------------------* * convert pitch values to 16kHz domain *----------------------------------------------------------------*/ - IF (EQ_16(L_frame, L_FRAME) || (tdm_Pri_pitch_buf != NULL && tdm_Pri_pitch_buf[0] < 0)) + IF( EQ_16( L_frame, L_FRAME ) || ( tdm_Pri_pitch_buf != NULL && tdm_Pri_pitch_buf[0] < 0 ) ) { - Copy(pitch, T_op, 2); + Copy( pitch, T_op, 2 ); } ELSE /* L_frame == L_FRAME16k */ { /*T_op[0] = (int16_t)(pitch[0] * 1.25f + 0.5f); T_op[1] = (int16_t)(pitch[1] * 1.25f + 0.5f);*/ - T_op[0] = shr(add(round_fx(L_shl(L_mult(20480, pitch[0]), 2)), 1), 1); move16(); - T_op[1] = shr(add(round_fx(L_shl(L_mult(20480, pitch[1]), 2)), 1), 1); move16(); + T_op[0] = shr( add( round_fx( L_shl( L_mult( 20480, pitch[0] ), 2 ) ), 1 ), 1 ); + move16(); + T_op[1] = shr( add( round_fx( L_shl( L_mult( 20480, pitch[1] ), 2 ) ), 1 ), 1 ); + move16(); } /*----------------------------------------------------------------* @@ -112,7 +113,7 @@ Word16 pit_encode_fx( /* o : Fractional pitch for each subframe *----------------------------------------------------------------*/ pit_flag = i_subfr; move16(); - if (EQ_16(i_subfr,2*L_SUBFR)) + if ( EQ_16( i_subfr, 2 * L_SUBFR ) ) { pit_flag = 0; move16(); @@ -137,22 +138,22 @@ Word16 pit_encode_fx( /* o : Fractional pitch for each subframe { *limit_flag = 1; move16(); - if( EQ_16(coder_type,VOICED)) + if ( EQ_16( coder_type, VOICED ) ) { *limit_flag = 2; - move16(); /* double-extended limits */ + move16(); /* double-extended limits */ } test(); - if( EQ_16(coder_type,GENERIC)&&EQ_32(core_brate,ACELP_7k20)) + if ( EQ_16( coder_type, GENERIC ) && EQ_32( core_brate, ACELP_7k20 ) ) { *limit_flag = 0; move16(); } } - ELSE IF( EQ_16(i_subfr,2*L_SUBFR)&&EQ_16(coder_type,GENERIC)&&LE_32(core_brate,ACELP_13k20)) + ELSE IF( EQ_16( i_subfr, 2 * L_SUBFR ) && EQ_16( coder_type, GENERIC ) && LE_32( core_brate, ACELP_13k20 ) ) { /*if( *T0 > (PIT_FR1_EXTEND_8b + PIT_MIN)>>1 )*/ - if( GT_16(*T0,shr(add(PIT_FR1_EXTEND_8b , PIT_MIN), 1))) + if ( GT_16( *T0, shr( add( PIT_FR1_EXTEND_8b, PIT_MIN ), 1 ) ) ) { *limit_flag = 0; move16(); @@ -163,12 +164,12 @@ Word16 pit_encode_fx( /* o : Fractional pitch for each subframe { test(); test(); - IF( i_subfr == 0 && LT_16(T_op[0],PIT_MIN)) + IF( i_subfr == 0 && LT_16( T_op[0], PIT_MIN ) ) { mult_Top = 2; move16(); } - ELSE IF( EQ_16(i_subfr,2*L_SUBFR)&<_16(T_op[1],PIT_MIN)) + ELSE IF( EQ_16( i_subfr, 2 * L_SUBFR ) && LT_16( T_op[1], PIT_MIN ) ) { mult_Top = 2; move16(); @@ -179,11 +180,11 @@ Word16 pit_encode_fx( /* o : Fractional pitch for each subframe *-------------------------------------------------------*/ nBits = 0; move16(); - IF( NE_16(coder_type,AUDIO)) + IF( NE_16( coder_type, AUDIO ) ) { - nBits = pitch_bits[shr(i_subfr, L_sufr_sft)]; + nBits = pitch_bits[shr( i_subfr, L_sufr_sft )]; } - IF( EQ_16(coder_type,AUDIO)) + IF( EQ_16( coder_type, AUDIO ) ) { /*-------------------------------------------------------* * Pitch encoding in AUDIO coder type @@ -194,12 +195,12 @@ Word16 pit_encode_fx( /* o : Fractional pitch for each subframe move16(); test(); test(); - if ( EQ_16(L_subfr,L_frame/2)&&i_subfr!=0&&EQ_16(L_frame,L_FRAME)) + if ( EQ_16( L_subfr, L_frame / 2 ) && i_subfr != 0 && EQ_16( L_frame, L_FRAME ) ) { pit_flag = L_SUBFR; move16(); } - IF ( pit_flag == 0 ) + IF( pit_flag == 0 ) { nBits = 10; move16(); @@ -214,19 +215,19 @@ Word16 pit_encode_fx( /* o : Fractional pitch for each subframe test(); IF( i_subfr == 0 ) { - limit_T0_fx( L_frame, delta, pit_flag, *limit_flag, mult_Top*T_op[0], 0, T0_min, T0_max ); + limit_T0_fx( L_frame, delta, pit_flag, *limit_flag, mult_Top * T_op[0], 0, T0_min, T0_max ); } - ELSE IF( EQ_16(i_subfr,2*L_SUBFR)&& pit_flag == 0 ) + ELSE IF( EQ_16( i_subfr, 2 * L_SUBFR ) && pit_flag == 0 ) { - limit_T0_fx( L_frame, delta, pit_flag, *limit_flag, mult_Top*T_op[1], 0, T0_min, T0_max ); + limit_T0_fx( L_frame, delta, pit_flag, *limit_flag, mult_Top * T_op[1], 0, T0_min, T0_max ); } /* search and encode the closed loop pitch period */ *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MAX, PIT_MAX, L_FRAME, L_subfr ); - pit_Q_enc_fx(hBstr, 0, nBits, delta, pit_flag, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); + pit_Q_enc_fx( hBstr, 0, nBits, delta, pit_flag, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); } - ELSE IF( EQ_16(coder_type,VOICED)) + ELSE IF( EQ_16( coder_type, VOICED ) ) { /*-------------------------------------------------------* * Pitch encoding in VOICED code type (ACELP@12k8 core only) @@ -234,68 +235,68 @@ Word16 pit_encode_fx( /* o : Fractional pitch for each subframe delta = 4; move16(); - if ( EQ_16(i_subfr,2*L_SUBFR)) + if ( EQ_16( i_subfr, 2 * L_SUBFR ) ) { pit_flag = i_subfr; move16(); } /* pitch lag search limitation */ - IF (i_subfr == 0) + IF( i_subfr == 0 ) { - limit_T0_fx( L_FRAME, delta, pit_flag, *limit_flag, mult_Top*T_op[0], 0, T0_min, T0_max ); + limit_T0_fx( L_FRAME, delta, pit_flag, *limit_flag, mult_Top * T_op[0], 0, T0_min, T0_max ); } /* search and encode the closed loop pitch period */ test(); test(); - IF( EQ_16(nBits,9)||EQ_16(nBits,5)) + IF( EQ_16( nBits, 9 ) || EQ_16( nBits, 5 ) ) { *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_FR2_DOUBLEEXTEND_9b, PIT_FR1_DOUBLEEXTEND_9b, L_FRAME, L_SUBFR ); move16(); } - ELSE IF( EQ_16(nBits,10)) + ELSE IF( EQ_16( nBits, 10 ) ) { *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MAX, PIT_MAX, L_FRAME, L_SUBFR ); move16(); } - pit_Q_enc_fx(hBstr, 0, nBits, delta, pit_flag, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); + pit_Q_enc_fx( hBstr, 0, nBits, delta, pit_flag, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); } #ifdef ADD_LRTD - else if (tdm_Pitch_reuse_flag == 1 || nBits == 4) + else if ( tdm_Pitch_reuse_flag == 1 || nBits == 4 ) { - /*-------------------------------------------------------* - * Pitch encoding with reusing primary channel information - *-------------------------------------------------------*/ + /*-------------------------------------------------------* + * Pitch encoding with reusing primary channel information + *-------------------------------------------------------*/ int16_t loc_T0, loc_frac; delta = 4; pit_flag = L_SUBFR; - if (L_subfr == 2 * L_SUBFR) + if ( L_subfr == 2 * L_SUBFR ) { - loc_T0 = (int16_t)(0.5f * tdm_Pri_pitch_buf[i_subfr / L_SUBFR] + 0.5f * tdm_Pri_pitch_buf[(i_subfr + L_SUBFR) / L_SUBFR]); - loc_frac = (int16_t)(((0.5f * tdm_Pri_pitch_buf[i_subfr / L_SUBFR] + 0.5f * tdm_Pri_pitch_buf[(i_subfr + L_SUBFR) / L_SUBFR]) - loc_T0) * 4.0f); + loc_T0 = (int16_t) ( 0.5f * tdm_Pri_pitch_buf[i_subfr / L_SUBFR] + 0.5f * tdm_Pri_pitch_buf[( i_subfr + L_SUBFR ) / L_SUBFR] ); + loc_frac = (int16_t) ( ( ( 0.5f * tdm_Pri_pitch_buf[i_subfr / L_SUBFR] + 0.5f * tdm_Pri_pitch_buf[( i_subfr + L_SUBFR ) / L_SUBFR] ) - loc_T0 ) * 4.0f ); } else { - loc_T0 = (int16_t)tdm_Pri_pitch_buf[i_subfr / L_SUBFR]; - loc_frac = (int16_t)((tdm_Pri_pitch_buf[i_subfr / L_SUBFR] - loc_T0) * 4.0f); + loc_T0 = (int16_t) tdm_Pri_pitch_buf[i_subfr / L_SUBFR]; + loc_frac = (int16_t) ( ( tdm_Pri_pitch_buf[i_subfr / L_SUBFR] - loc_T0 ) * 4.0f ); } /* pitch lag search limitation */ - limit_T0(L_FRAME, delta, pit_flag, *limit_flag, loc_T0, loc_frac, T0_min, T0_max); - if (nBits > 0) + limit_T0( L_FRAME, delta, pit_flag, *limit_flag, loc_T0, loc_frac, T0_min, T0_max ); + if ( nBits > 0 ) { /* search and encode the closed loop pitch period */ - *T0 = pitch_fr4(&exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MIN, PIT_FR1_8b, L_FRAME, L_SUBFR); - if (delta == 8) + *T0 = pitch_fr4( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MIN, PIT_FR1_8b, L_FRAME, L_SUBFR ); + if ( delta == 8 ) { *T0_frac = 0; } - pit_Q_enc(hBstr, 0, nBits, delta, pit_flag, *limit_flag, *T0, *T0_frac, T0_min, T0_max); + pit_Q_enc( hBstr, 0, nBits, delta, pit_flag, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); } else { @@ -317,19 +318,19 @@ Word16 pit_encode_fx( /* o : Fractional pitch for each subframe /* pitch lag search limitation */ IF( i_subfr == 0 ) { - limit_T0_fx( L_frame, delta, pit_flag, *limit_flag, mult_Top*T_op[0], 0, T0_min, T0_max ); + limit_T0_fx( L_frame, delta, pit_flag, *limit_flag, mult_Top * T_op[0], 0, T0_min, T0_max ); } - ELSE IF( EQ_16(i_subfr,2*L_SUBFR)) + ELSE IF( EQ_16( i_subfr, 2 * L_SUBFR ) ) { - limit_T0_fx( L_frame, delta, pit_flag, *limit_flag, mult_Top*T_op[1], 0, T0_min, T0_max ); + limit_T0_fx( L_frame, delta, pit_flag, *limit_flag, mult_Top * T_op[1], 0, T0_min, T0_max ); } /* search and encode the closed loop pitch period */ - IF( EQ_16(L_frame,L_FRAME)) + IF( EQ_16( L_frame, L_FRAME ) ) { test(); test(); - IF( EQ_16(nBits,8)||EQ_16(nBits,5)) + IF( EQ_16( nBits, 8 ) || EQ_16( nBits, 5 ) ) { IF( *limit_flag == 0 ) { @@ -340,7 +341,7 @@ Word16 pit_encode_fx( /* o : Fractional pitch for each subframe *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MIN_EXTEND, PIT_FR1_EXTEND_8b, L_FRAME, L_SUBFR ); } } - ELSE IF( EQ_16(nBits,9)||EQ_16(nBits,6)) + ELSE IF( EQ_16( nBits, 9 ) || EQ_16( nBits, 6 ) ) { IF( *limit_flag == 0 ) { @@ -351,17 +352,17 @@ Word16 pit_encode_fx( /* o : Fractional pitch for each subframe *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_FR2_EXTEND_9b, PIT_FR1_EXTEND_9b, L_FRAME, L_SUBFR ); } } - ELSE IF( EQ_16(nBits,10)) + ELSE IF( EQ_16( nBits, 10 ) ) { *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MAX, PIT_MAX, L_FRAME, L_SUBFR ); } - pit_Q_enc_fx(hBstr, 0, nBits, delta, pit_flag, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); + pit_Q_enc_fx( hBstr, 0, nBits, delta, pit_flag, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); } - ELSE /* L_frame == L_FRAME16k */ + ELSE /* L_frame == L_FRAME16k */ { test(); - IF( EQ_16(nBits,9)||EQ_16(nBits,6)) + IF( EQ_16( nBits, 9 ) || EQ_16( nBits, 6 ) ) { *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT16k_FR2_EXTEND_9b, PIT16k_FR1_EXTEND_9b, L_FRAME16k, L_SUBFR ); } @@ -370,7 +371,7 @@ Word16 pit_encode_fx( /* o : Fractional pitch for each subframe *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT16k_FR2_EXTEND_10b, PIT16k_MAX, L_FRAME16k, L_SUBFR ); } - pit16k_Q_enc_fx(hBstr, nBits, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); + pit16k_Q_enc_fx( hBstr, nBits, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); } } } @@ -386,7 +387,7 @@ Word16 pit_encode_fx( /* o : Fractional pitch for each subframe *limit_flag = 0; move16(); - IF( EQ_32(core_brate,ACELP_6k60)) + IF( EQ_32( core_brate, ACELP_6k60 ) ) { nBits = 5; move16(); @@ -394,12 +395,12 @@ Word16 pit_encode_fx( /* o : Fractional pitch for each subframe /* pitch lag search limitation */ IF( i_subfr == 0 ) { - limit_T0_fx( L_FRAME, delta, pit_flag, *limit_flag, i_mult2(mult_Top,T_op[0]), 0, T0_min, T0_max ); + limit_T0_fx( L_FRAME, delta, pit_flag, *limit_flag, i_mult2( mult_Top, T_op[0] ), 0, T0_min, T0_max ); nBits = 8; move16(); } - if( EQ_16(i_subfr,2*L_SUBFR)) + if ( EQ_16( i_subfr, 2 * L_SUBFR ) ) { /* rewrite pit_flag - it must not be zero */ pit_flag = i_subfr; @@ -409,7 +410,7 @@ Word16 pit_encode_fx( /* o : Fractional pitch for each subframe /* search and encode the closed loop pitch period */ *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MIN, PIT_FR1_8b, L_FRAME, L_SUBFR ); } - ELSE IF( EQ_32(core_brate,ACELP_8k85)) + ELSE IF( EQ_32( core_brate, ACELP_8k85 ) ) { nBits = 5; move16(); @@ -417,13 +418,13 @@ Word16 pit_encode_fx( /* o : Fractional pitch for each subframe /* pitch lag search limitation */ IF( i_subfr == 0 ) { - limit_T0_fx( L_FRAME, delta, pit_flag, *limit_flag, i_mult2(mult_Top,T_op[0]), 0, T0_min, T0_max ); + limit_T0_fx( L_FRAME, delta, pit_flag, *limit_flag, i_mult2( mult_Top, T_op[0] ), 0, T0_min, T0_max ); nBits = 8; move16(); } - ELSE IF( EQ_16(i_subfr,2*L_SUBFR)) + ELSE IF( EQ_16( i_subfr, 2 * L_SUBFR ) ) { - limit_T0_fx( L_FRAME, delta, pit_flag, *limit_flag, i_mult2(mult_Top,T_op[1]), 0, T0_min, T0_max ); + limit_T0_fx( L_FRAME, delta, pit_flag, *limit_flag, i_mult2( mult_Top, T_op[1] ), 0, T0_min, T0_max ); nBits = 8; move16(); } @@ -439,26 +440,26 @@ Word16 pit_encode_fx( /* o : Fractional pitch for each subframe /* pitch lag search limitation */ IF( i_subfr == 0 ) { - limit_T0_fx( L_FRAME, delta, pit_flag, *limit_flag, i_mult2(mult_Top,T_op[0]), 0, T0_min, T0_max ); + limit_T0_fx( L_FRAME, delta, pit_flag, *limit_flag, i_mult2( mult_Top, T_op[0] ), 0, T0_min, T0_max ); nBits = 9; move16(); } - ELSE IF( EQ_16(i_subfr,2*L_SUBFR)) + ELSE IF( EQ_16( i_subfr, 2 * L_SUBFR ) ) { - limit_T0_fx( L_FRAME, delta, pit_flag, *limit_flag, i_mult2(mult_Top,T_op[1]), 0, T0_min, T0_max ); + limit_T0_fx( L_FRAME, delta, pit_flag, *limit_flag, i_mult2( mult_Top, T_op[1] ), 0, T0_min, T0_max ); nBits = 9; move16(); } ELSE { - limit_T0_fx( L_FRAME, delta, pit_flag, 0, *T0, 0, T0_min, T0_max ); /* T0_frac==0 to keep IO with AMR-WB */ + limit_T0_fx( L_FRAME, delta, pit_flag, 0, *T0, 0, T0_min, T0_max ); /* T0_frac==0 to keep IO with AMR-WB */ } /* search and encode the closed loop pitch period */ *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_FR2_9b, PIT_FR1_9b, L_FRAME, L_SUBFR ); } - pit_Q_enc_fx(hBstr, 1, nBits, delta, pit_flag, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); + pit_Q_enc_fx( hBstr, 1, nBits, delta, pit_flag, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); } /*-------------------------------------------------------* @@ -466,10 +467,9 @@ Word16 pit_encode_fx( /* o : Fractional pitch for each subframe *-------------------------------------------------------*/ /*pitch = (float)(*T0) + (float)(*T0_frac)/4.0f;*/ /* save subframe pitch values */ - pitch_cl = shl(add(shl(*T0,2),*T0_frac),4); /* save subframe pitch values Q6 */ + pitch_cl = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); /* save subframe pitch values Q6 */ return pitch_cl; - } /*-------------------------------------------------------------------* @@ -481,18 +481,18 @@ Word16 pit_encode_fx( /* o : Fractional pitch for each subframe * fr_step = 4: pitch range encoded with 8 bits *-------------------------------------------------------------------*/ -Word16 abs_pit_enc_fx( /* o : pitch index */ - const Word16 fr_steps, /* i : fractional resolution steps (2 or 4) for shortest pitches*/ - const Word16 limit_flag, /* i : restrained(0) or extended(1) limits */ - const Word16 T0, /* i : integer pitch lag */ - const Word16 T0_frac /* i : pitch fraction */ +Word16 abs_pit_enc_fx( /* o : pitch index */ + const Word16 fr_steps, /* i : fractional resolution steps (2 or 4) for shortest pitches*/ + const Word16 limit_flag, /* i : restrained(0) or extended(1) limits */ + const Word16 T0, /* i : integer pitch lag */ + const Word16 T0_frac /* i : pitch fraction */ ) { Word16 pitch_index = 0; IF( limit_flag == 0 ) { - IF( EQ_16(fr_steps,2)) + IF( EQ_16( fr_steps, 2 ) ) { /*-----------------------------------------------------------------* * The pitch range is encoded absolutely with 8 bits @@ -501,53 +501,53 @@ Word16 abs_pit_enc_fx( /* o : pitch index * PIT_FR1_8b to PIT_MAX resolution 1 (frac = 0) *-----------------------------------------------------------------*/ - IF (LT_16(T0,PIT_FR1_8b)) + IF( LT_16( T0, PIT_FR1_8b ) ) { /*pitch_index = T0*2 + (T0_frac>>1) - (PIT_MIN*2);*/ - pitch_index = sub(add(shl(T0,1),shr(T0_frac,1)),(PIT_MIN*2)); + pitch_index = sub( add( shl( T0, 1 ), shr( T0_frac, 1 ) ), ( PIT_MIN * 2 ) ); } ELSE { /*pitch_index = T0 - PIT_FR1_8b + ((PIT_FR1_8b-PIT_MIN)*2);*/ - pitch_index = add(sub(T0,PIT_FR1_8b),((PIT_FR1_8b-PIT_MIN)*2)); + pitch_index = add( sub( T0, PIT_FR1_8b ), ( ( PIT_FR1_8b - PIT_MIN ) * 2 ) ); } } - ELSE IF( EQ_16(fr_steps,4)) + ELSE IF( EQ_16( fr_steps, 4 ) ) { /*-------------------------------------------------------------------* - * The pitch range is encoded absolutely with 9 bits - * and is divided as follows: - * PIT_MIN to PIT_FR2_9b-1 resolution 1/4 (frac = 0,1,2 or 3) - * PIT_FR2_9b to PIT_FR1_9b-1 resolution 1/2 (frac = 0 or 2) - * PIT_FR1_9b to PIT_MAX resolution 1 (frac = 0) - *-------------------------------------------------------------------*/ - - IF (LT_16(T0,PIT_FR2_9b)) + * The pitch range is encoded absolutely with 9 bits + * and is divided as follows: + * PIT_MIN to PIT_FR2_9b-1 resolution 1/4 (frac = 0,1,2 or 3) + * PIT_FR2_9b to PIT_FR1_9b-1 resolution 1/2 (frac = 0 or 2) + * PIT_FR1_9b to PIT_MAX resolution 1 (frac = 0) + *-------------------------------------------------------------------*/ + + IF( LT_16( T0, PIT_FR2_9b ) ) { /*pitch_index = T0*4 + T0_frac - (PIT_MIN*4);*/ - pitch_index = add(shl(T0,2),sub(T0_frac,(PIT_MIN*4))); + pitch_index = add( shl( T0, 2 ), sub( T0_frac, ( PIT_MIN * 4 ) ) ); } - ELSE IF (LT_16(T0,PIT_FR1_9b)) + ELSE IF( LT_16( T0, PIT_FR1_9b ) ) { /* pitch_index = T0*2 + (T0_frac>>1) - (PIT_FR2_9b*2) + ((PIT_FR2_9b-PIT_MIN)*4);*/ - pitch_index = add(sub(add(shl(T0,1),shr(T0_frac,1)),(PIT_FR2_9b*2)),((PIT_FR2_9b-PIT_MIN)*4)); + pitch_index = add( sub( add( shl( T0, 1 ), shr( T0_frac, 1 ) ), ( PIT_FR2_9b * 2 ) ), ( ( PIT_FR2_9b - PIT_MIN ) * 4 ) ); } ELSE { /* pitch_index = T0 - PIT_FR1_9b + ((PIT_FR2_9b-PIT_MIN)*4) + ((PIT_FR1_9b-PIT_FR2_9b)*2);*/ - pitch_index = add(add(sub(T0,PIT_FR1_9b),((PIT_FR2_9b-PIT_MIN)*4)),((PIT_FR1_9b-PIT_FR2_9b)*2)); + pitch_index = add( add( sub( T0, PIT_FR1_9b ), ( ( PIT_FR2_9b - PIT_MIN ) * 4 ) ), ( ( PIT_FR1_9b - PIT_FR2_9b ) * 2 ) ); } } - ELSE /* fr_step == 0 */ + ELSE /* fr_step == 0 */ { /* not used in the codec */ pitch_index = 0; move16(); } } - ELSE IF( EQ_16(limit_flag,1)) /* extended Q range */ + ELSE IF( EQ_16( limit_flag, 1 ) ) /* extended Q range */ { - IF( EQ_16(fr_steps,2)) + IF( EQ_16( fr_steps, 2 ) ) { /*-----------------------------------------------------------------* * The pitch range is encoded absolutely with 8 bits @@ -556,18 +556,18 @@ Word16 abs_pit_enc_fx( /* o : pitch index * PIT_FR1_EXTEND_8b to PIT_MAX_EXTEND resolution 1 (frac = 0) *-----------------------------------------------------------------*/ - IF( LT_16(T0,PIT_FR1_EXTEND_8b)) + IF( LT_16( T0, PIT_FR1_EXTEND_8b ) ) { /*pitch_index = T0*2 + (T0_frac>>1) - (PIT_MIN_EXTEND*2);*/ - pitch_index = sub(add(shl(T0,1),shr(T0_frac,1)),(PIT_MIN_EXTEND*2)); + pitch_index = sub( add( shl( T0, 1 ), shr( T0_frac, 1 ) ), ( PIT_MIN_EXTEND * 2 ) ); } ELSE { /*pitch_index = T0 - PIT_FR1_EXTEND_8b + ((PIT_FR1_EXTEND_8b-PIT_MIN_EXTEND)*2);*/ - pitch_index = add(sub(T0,PIT_FR1_EXTEND_8b),((PIT_FR1_EXTEND_8b-PIT_MIN_EXTEND)*2)); + pitch_index = add( sub( T0, PIT_FR1_EXTEND_8b ), ( ( PIT_FR1_EXTEND_8b - PIT_MIN_EXTEND ) * 2 ) ); } } - ELSE IF( EQ_16(fr_steps,4)) + ELSE IF( EQ_16( fr_steps, 4 ) ) { /*-------------------------------------------------------------------* * The pitch range is encoded absolutely with 9 bits @@ -577,33 +577,32 @@ Word16 abs_pit_enc_fx( /* o : pitch index * PIT_FR1_EXTEND_9b to PIT_MAX_EXTEND resolution 1 (frac = 0) *-------------------------------------------------------------------*/ - IF( LT_16(T0,PIT_FR2_EXTEND_9b)) + IF( LT_16( T0, PIT_FR2_EXTEND_9b ) ) { /*pitch_index = T0*4 + T0_frac - (PIT_MIN_EXTEND*4);*/ - pitch_index = add(shl(T0,2),sub(T0_frac,(PIT_MIN_EXTEND*4))); + pitch_index = add( shl( T0, 2 ), sub( T0_frac, ( PIT_MIN_EXTEND * 4 ) ) ); } ELSE IF( T0 < PIT_FR1_EXTEND_9b ) { /*pitch_index = T0*2 + (T0_frac>>1) - (PIT_FR2_EXTEND_9b*2) + ((PIT_FR2_EXTEND_9b-PIT_MIN_EXTEND)*4);*/ - pitch_index = add(sub(add(shl(T0,1),shr(T0_frac,1)),(PIT_FR2_EXTEND_9b*2)),((PIT_FR2_EXTEND_9b-PIT_MIN_EXTEND)*4)); + pitch_index = add( sub( add( shl( T0, 1 ), shr( T0_frac, 1 ) ), ( PIT_FR2_EXTEND_9b * 2 ) ), ( ( PIT_FR2_EXTEND_9b - PIT_MIN_EXTEND ) * 4 ) ); } ELSE { /*pitch_index = T0 - PIT_FR1_EXTEND_9b + ((PIT_FR2_EXTEND_9b-PIT_MIN_EXTEND)*4) + ((PIT_FR1_EXTEND_9b-PIT_FR2_EXTEND_9b)*2);*/ - pitch_index = add(add(sub(T0,PIT_FR1_EXTEND_9b),((PIT_FR2_EXTEND_9b-PIT_MIN_EXTEND)*4)),((PIT_FR1_EXTEND_9b-PIT_FR2_EXTEND_9b)*2)); + pitch_index = add( add( sub( T0, PIT_FR1_EXTEND_9b ), ( ( PIT_FR2_EXTEND_9b - PIT_MIN_EXTEND ) * 4 ) ), ( ( PIT_FR1_EXTEND_9b - PIT_FR2_EXTEND_9b ) * 2 ) ); } - } - ELSE /* fr_step == 0 */ + ELSE /* fr_step == 0 */ { /* not used in the codec */ pitch_index = 0; move16(); } } - ELSE /* double-extended Q range */ + ELSE /* double-extended Q range */ { - IF( EQ_16(fr_steps,2)) + IF( EQ_16( fr_steps, 2 ) ) { /*-----------------------------------------------------------------* * The pitch range is encoded absolutely with 8 bits @@ -612,18 +611,18 @@ Word16 abs_pit_enc_fx( /* o : pitch index * PIT_FR1_DOUBLEEXTEND_8b to PIT_MAX_EXTEND resolution 1 (frac = 0) *-----------------------------------------------------------------*/ - IF( LT_16(T0,PIT_FR1_DOUBLEEXTEND_8b)) + IF( LT_16( T0, PIT_FR1_DOUBLEEXTEND_8b ) ) { /*pitch_index = T0*2 + (T0_frac>>1) - (PIT_MIN_DOUBLEEXTEND*2);*/ - pitch_index = sub(add(shl(T0,1),shr(T0_frac,1)),(PIT_MIN_DOUBLEEXTEND*2)); + pitch_index = sub( add( shl( T0, 1 ), shr( T0_frac, 1 ) ), ( PIT_MIN_DOUBLEEXTEND * 2 ) ); } ELSE { /*pitch_index = T0 - PIT_FR1_DOUBLEEXTEND_8b + ((PIT_FR1_DOUBLEEXTEND_8b-PIT_MIN_DOUBLEEXTEND)*2); */ - pitch_index = add(sub(T0,PIT_FR1_DOUBLEEXTEND_8b),((PIT_FR1_DOUBLEEXTEND_8b-PIT_MIN_DOUBLEEXTEND)*2)); + pitch_index = add( sub( T0, PIT_FR1_DOUBLEEXTEND_8b ), ( ( PIT_FR1_DOUBLEEXTEND_8b - PIT_MIN_DOUBLEEXTEND ) * 2 ) ); } } - ELSE IF( EQ_16(fr_steps,4)) + ELSE IF( EQ_16( fr_steps, 4 ) ) { /*-------------------------------------------------------------------* * The pitch range is encoded absolutely with 9 bits @@ -633,23 +632,23 @@ Word16 abs_pit_enc_fx( /* o : pitch index * PIT_FR1_DOUBLEEXTEND_9b to PIT_MAX_EXTEND resolution 1 (frac = 0) *-------------------------------------------------------------------*/ - IF(LT_16(T0,PIT_FR2_DOUBLEEXTEND_9b)) + IF( LT_16( T0, PIT_FR2_DOUBLEEXTEND_9b ) ) { /*pitch_index = T0*4 + T0_frac - (PIT_MIN_DOUBLEEXTEND*4);*/ - pitch_index = add(shl(T0,2),sub(T0_frac,(PIT_MIN_DOUBLEEXTEND*4))); + pitch_index = add( shl( T0, 2 ), sub( T0_frac, ( PIT_MIN_DOUBLEEXTEND * 4 ) ) ); } - ELSE IF( LT_16(T0,PIT_FR1_DOUBLEEXTEND_9b)) + ELSE IF( LT_16( T0, PIT_FR1_DOUBLEEXTEND_9b ) ) { /*pitch_index = T0*2 + (T0_frac>>1) - (PIT_FR2_DOUBLEEXTEND_9b*2) + ((PIT_FR2_DOUBLEEXTEND_9b-PIT_MIN_DOUBLEEXTEND)*4);*/ - pitch_index = add(sub(add(shl(T0,1),shr(T0_frac,1)),(PIT_FR2_DOUBLEEXTEND_9b*2)),((PIT_FR2_DOUBLEEXTEND_9b-PIT_MIN_DOUBLEEXTEND)*4)); + pitch_index = add( sub( add( shl( T0, 1 ), shr( T0_frac, 1 ) ), ( PIT_FR2_DOUBLEEXTEND_9b * 2 ) ), ( ( PIT_FR2_DOUBLEEXTEND_9b - PIT_MIN_DOUBLEEXTEND ) * 4 ) ); } ELSE { /*pitch_index = T0 - PIT_FR1_DOUBLEEXTEND_9b + ((PIT_FR2_DOUBLEEXTEND_9b-PIT_MIN_DOUBLEEXTEND)*4) + ((PIT_FR1_DOUBLEEXTEND_9b-PIT_FR2_DOUBLEEXTEND_9b)*2);*/ - pitch_index = add(add(sub(T0,PIT_FR1_DOUBLEEXTEND_9b),((PIT_FR2_DOUBLEEXTEND_9b-PIT_MIN_DOUBLEEXTEND)*4)),((PIT_FR1_DOUBLEEXTEND_9b-PIT_FR2_DOUBLEEXTEND_9b)*2)); + pitch_index = add( add( sub( T0, PIT_FR1_DOUBLEEXTEND_9b ), ( ( PIT_FR2_DOUBLEEXTEND_9b - PIT_MIN_DOUBLEEXTEND ) * 4 ) ), ( ( PIT_FR1_DOUBLEEXTEND_9b - PIT_FR2_DOUBLEEXTEND_9b ) * 2 ) ); } } - ELSE /* fr_step == 0 */ + ELSE /* fr_step == 0 */ { /* not used in the codec */ pitch_index = 0; @@ -671,28 +670,28 @@ Word16 abs_pit_enc_fx( /* o : pitch index * fr_step = 4: resolution 1/4 (frac = 0, 1, 2, or 3) *-------------------------------------------------------------------*/ -Word16 delta_pit_enc_fx( /* o : pitch index */ - const Word16 fr_steps, /* i : fractional resolution steps (2 or 4)*/ - const Word16 T0, /* i : integer pitch lag */ - const Word16 T0_frac, /* i : pitch fraction */ - const Word16 T0_min /* i : delta search min */ +Word16 delta_pit_enc_fx( /* o : pitch index */ + const Word16 fr_steps, /* i : fractional resolution steps (2 or 4)*/ + const Word16 T0, /* i : integer pitch lag */ + const Word16 T0_frac, /* i : pitch fraction */ + const Word16 T0_min /* i : delta search min */ ) { Word16 pitch_index = 0; IF( fr_steps == 0 ) { - pitch_index = sub(T0,T0_min); + pitch_index = sub( T0, T0_min ); } - ELSE IF( EQ_16(fr_steps,2)) + ELSE IF( EQ_16( fr_steps, 2 ) ) { /* pitch_index = (T0 - T0_min) * 2 + (T0_frac>>1);*/ - pitch_index = add(shl(sub(T0,T0_min),1),shr(T0_frac,1)); + pitch_index = add( shl( sub( T0, T0_min ), 1 ), shr( T0_frac, 1 ) ); } - ELSE IF( EQ_16(fr_steps,4)) + ELSE IF( EQ_16( fr_steps, 4 ) ) { /*pitch_index = (T0 - T0_min) * 4 + T0_frac;*/ - pitch_index = add(shl(sub(T0,T0_min),2),T0_frac); + pitch_index = add( shl( sub( T0, T0_min ), 2 ), T0_frac ); } return pitch_index; @@ -704,33 +703,33 @@ Word16 delta_pit_enc_fx( /* o : pitch index */ * Find the closed loop pitch period with 1/4 subsample resolution. *-------------------------------------------------------------------*/ -Word16 pitch_fr4_fx( /* o : chosen integer pitch lag */ - const Word16 exc[], /* i : excitation buffer Q_new*/ - const Word16 xn[], /* i : target signal Q_new-1+shift*/ - const Word16 h[], /* i : weighted synthesis filter impulse response Q(14+shift)*/ - const Word16 t0_min, /* i : minimum value in the searched range. Q0*/ - const Word16 t0_max, /* i : maximum value in the searched range. Q0*/ - Word16 *pit_frac, /* o : chosen fraction (0, 1, 2 or 3) */ - const Word16 i_subfr, /* i : flag to first subframe */ - const Word16 limit_flag, /* i : flag for limits (0=restrained, 1=extended) */ - const Word16 t0_fr2, /* i : minimum value for resolution 1/2 */ - const Word16 t0_fr1, /* i : minimum value for resolution 1 */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 L_subfr /* i : size of subframe */ +Word16 pitch_fr4_fx( /* o : chosen integer pitch lag */ + const Word16 exc[], /* i : excitation buffer Q_new*/ + const Word16 xn[], /* i : target signal Q_new-1+shift*/ + const Word16 h[], /* i : weighted synthesis filter impulse response Q(14+shift)*/ + const Word16 t0_min, /* i : minimum value in the searched range. Q0*/ + const Word16 t0_max, /* i : maximum value in the searched range. Q0*/ + Word16 *pit_frac, /* o : chosen fraction (0, 1, 2 or 3) */ + const Word16 i_subfr, /* i : flag to first subframe */ + const Word16 limit_flag, /* i : flag for limits (0=restrained, 1=extended) */ + const Word16 t0_fr2, /* i : minimum value for resolution 1/2 */ + const Word16 t0_fr1, /* i : minimum value for resolution 1 */ + const Word16 L_frame, /* i : length of the frame */ + const Word16 L_subfr /* i : size of subframe */ ) { Word16 i; Word16 t_min, t_max; Word16 max_val, t0, t1, fraction, step, temp; Word16 *corr; - Word16 corr_v[15+2*L_INTERPOL1+1]; /* Total length = t0_max-t0_min+1+2*L_inter */ + Word16 corr_v[15 + 2 * L_INTERPOL1 + 1]; /* Total length = t0_max-t0_min+1+2*L_inter */ Word16 pit_min; Word16 cor_max; /* initialization */ IF( limit_flag == 0 ) { - IF( EQ_16(L_frame,L_FRAME)) + IF( EQ_16( L_frame, L_FRAME ) ) { pit_min = PIT_MIN; move16(); @@ -743,11 +742,11 @@ Word16 pitch_fr4_fx( /* o : chosen integer pitch lag */ } ELSE { - IF( EQ_16(L_frame,L_FRAME)) + IF( EQ_16( L_frame, L_FRAME ) ) { pit_min = PIT_MIN_EXTEND; move16(); - IF( EQ_16(limit_flag,2)) + IF( EQ_16( limit_flag, 2 ) ) { pit_min = PIT_MIN_DOUBLEEXTEND; move16(); @@ -767,11 +766,11 @@ Word16 pitch_fr4_fx( /* o : chosen integer pitch lag */ * excitation *-----------------------------------------------------------------*/ - t_min = sub(t0_min, L_INTERPOL1); - t_max = add(t0_max, L_INTERPOL1); + t_min = sub( t0_min, L_INTERPOL1 ); + t_max = add( t0_max, L_INTERPOL1 ); corr = &corr_v[-t_min]; move16(); - move16(); /* corr[t_min..t_max] */ + move16(); /* corr[t_min..t_max] */ norm_corr_fx( exc, xn, h, t_min, t_max, corr, L_subfr ); @@ -784,50 +783,50 @@ Word16 pitch_fr4_fx( /* o : chosen integer pitch lag */ t0 = t0_min; move16(); - FOR (i = add(t0_min, 1); i <= t0_max; i++) + FOR( i = add( t0_min, 1 ); i <= t0_max; i++ ) { - if (corr[i] >= max_val) + if ( corr[i] >= max_val ) { t0 = i; move16(); } - max_val = s_max(corr[i], max_val); + max_val = s_max( corr[i], max_val ); } - IF( EQ_16(t0_fr1,pit_min)) + IF( EQ_16( t0_fr1, pit_min ) ) { /* don't search fraction (for 7b/4b quant) */ test(); - IF((i_subfr == 0) && (GE_16(t0,t0_fr2))) + IF( ( i_subfr == 0 ) && ( GE_16( t0, t0_fr2 ) ) ) { - i = shl(shr(t0,1),1); /* 2 samples resolution */ - if (GT_16(add(i,2),PIT_MAX)) + i = shl( shr( t0, 1 ), 1 ); /* 2 samples resolution */ + if ( GT_16( add( i, 2 ), PIT_MAX ) ) { - i = sub(i,2); + i = sub( i, 2 ); } - IF (GT_16(corr[i],corr[i+2])) + IF( GT_16( corr[i], corr[i + 2] ) ) { t0 = i; move16(); } ELSE { - t0 = add(i,2); + t0 = add( i, 2 ); } } *pit_frac = 0; move16(); - return(t0); + return ( t0 ); } test(); - IF( (i_subfr == 0) && (GE_16(t0,t0_fr1))) + IF( ( i_subfr == 0 ) && ( GE_16( t0, t0_fr1 ) ) ) { *pit_frac = 0; move16(); - return(t0); + return ( t0 ); } /*------------------------------------------------------------------* @@ -839,33 +838,33 @@ Word16 pitch_fr4_fx( /* o : chosen integer pitch lag */ t1 = t0; move16(); step = 1; - move16(); /* 1/4 subsample resolution */ + move16(); /* 1/4 subsample resolution */ fraction = 1; move16(); test(); test(); - IF (((i_subfr == 0) && (GE_16(t0,t0_fr2)))||(EQ_16(t0_fr2,pit_min))) + IF( ( ( i_subfr == 0 ) && ( GE_16( t0, t0_fr2 ) ) ) || ( EQ_16( t0_fr2, pit_min ) ) ) { step = 2; - move16(); /* 1/2 subsample resolution */ + move16(); /* 1/2 subsample resolution */ fraction = 2; move16(); } - IF (EQ_16(t0,t0_min)) /* Limit case */ + IF( EQ_16( t0, t0_min ) ) /* Limit case */ { fraction = 0; move16(); - cor_max = Interpol_4( &corr[t0], fraction); + cor_max = Interpol_4( &corr[t0], fraction ); } ELSE { - t0 = sub(t0, 1); - cor_max = Interpol_4( &corr[t0], fraction); - FOR(i = add(fraction, step); i <= 3; i = (Word16) (i + step)) + t0 = sub( t0, 1 ); + cor_max = Interpol_4( &corr[t0], fraction ); + FOR( i = add( fraction, step ); i <= 3; i = (Word16) ( i + step ) ) { - temp = Interpol_4( &corr[t0], i); - IF (GT_16(temp,cor_max)) + temp = Interpol_4( &corr[t0], i ); + IF( GT_16( temp, cor_max ) ) { cor_max = temp; move16(); @@ -875,10 +874,10 @@ Word16 pitch_fr4_fx( /* o : chosen integer pitch lag */ } } - FOR (i = 0; i <= 3; i = (Word16) (i + step)) + FOR( i = 0; i <= 3; i = (Word16) ( i + step ) ) { - temp = Interpol_4( &corr[t1], i); - IF (GT_16(temp,cor_max)) + temp = Interpol_4( &corr[t1], i ); + IF( GT_16( temp, cor_max ) ) { cor_max = temp; move16(); @@ -892,8 +891,7 @@ Word16 pitch_fr4_fx( /* o : chosen integer pitch lag */ *pit_frac = fraction; move16(); - return (t0); - + return ( t0 ); } /*-------------------------------------------------------------------* @@ -906,13 +904,13 @@ Word16 pitch_fr4_fx( /* o : chosen integer pitch lag */ *---------------------------------------------------------------------*/ void norm_corr_fx( - const Word16 exc[], /* i : excitation buffer Q_new*/ - const Word16 xn[], /* i : target signal Q_new-1+shift*/ - const Word16 h[], /* i : weighted synthesis filter impulse response Q(14+shift)*/ - const Word16 t_min, /* i : minimum value of searched range */ - const Word16 t_max, /* i : maximum value of searched range */ - Word16 ncorr[], /* o : normalized correlation Q15 */ - const Word16 L_subfr /* i : subframe size */ + const Word16 exc[], /* i : excitation buffer Q_new*/ + const Word16 xn[], /* i : target signal Q_new-1+shift*/ + const Word16 h[], /* i : weighted synthesis filter impulse response Q(14+shift)*/ + const Word16 t_min, /* i : minimum value of searched range */ + const Word16 t_max, /* i : maximum value of searched range */ + Word16 ncorr[], /* o : normalized correlation Q15 */ + const Word16 L_subfr /* i : subframe size */ ) { Word16 i, k, t; @@ -923,7 +921,7 @@ void norm_corr_fx( Flag Overflow = 0; #endif - k = negate(t_min); + k = negate( t_min ); /*-----------------------------------------------------------------* * compute the filtered excitation for the first delay t_min @@ -933,66 +931,66 @@ void norm_corr_fx( /* Compute rounded down 1/sqrt(energy of xn[]) */ #ifdef BASOP_NOGLOB - L_tmp = L_mac_o(1, xn[0], xn[0], &Overflow); + L_tmp = L_mac_o( 1, xn[0], xn[0], &Overflow ); #else - L_tmp = L_mac(1, xn[0], xn[0]); + L_tmp = L_mac( 1, xn[0], xn[0] ); #endif - FOR (i = 1; i < L_subfr; i++) + FOR( i = 1; i < L_subfr; i++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_mac_o(L_tmp, xn[i], xn[i], &Overflow); + L_tmp = L_mac_o( L_tmp, xn[i], xn[i], &Overflow ); #else /* BASOP_NOGLOB */ - L_tmp = L_mac(L_tmp, xn[i], xn[i]); + L_tmp = L_mac( L_tmp, xn[i], xn[i] ); #endif } - exp = norm_l(L_tmp); - exp = sub(30, exp); + exp = norm_l( L_tmp ); + exp = sub( 30, exp ); - exp = add(exp, 2); /* energy of xn[] x 2 + rounded up */ - scale = negate(shr(exp, 1)); /* (1< 0; i--) + FOR( i = (Word16) ( L_subfr - 1 ); i > 0; i-- ) { /* saturation can occur in add() */ /*excf[i] = add(mult(exc[k], h[i]), excf[i - 1]); move16(); */ #ifdef BASOP_NOGLOB excf[i] = round_fx_sat( L_mac_sat( L_mult( excf[i - 1], 32767 ), exc[k], h[i] ) ); #else - excf[i] = round_fx(L_mac(L_mult(excf[i - 1], 32767), exc[k], h[i])); + excf[i] = round_fx( L_mac( L_mult( excf[i - 1], 32767 ), exc[k], h[i] ) ); #endif } - excf[0] = mult_r(exc[k], h[0]); + excf[0] = mult_r( exc[k], h[0] ); move16(); } } @@ -1030,80 +1028,80 @@ void norm_corr_fx( *-------------------------------------------------------------------*/ void pit_Q_enc_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 nBits, /* i : # of Q bits */ - const Word16 delta, /* i : Half the CL searched interval */ - const Word16 pit_flag, /* i : absolute(0) or delta(1) pitch Q */ - const Word16 limit_flag, /* i : restrained(0) or extended(1) Q limits */ - const Word16 T0, /* i : integer pitch lag */ - const Word16 T0_frac, /* i : pitch fraction */ - Word16 *T0_min, /* i/o: delta search min */ - Word16 *T0_max /* o : delta search max_val */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const Word16 nBits, /* i : # of Q bits */ + const Word16 delta, /* i : Half the CL searched interval */ + const Word16 pit_flag, /* i : absolute(0) or delta(1) pitch Q */ + const Word16 limit_flag, /* i : restrained(0) or extended(1) Q limits */ + const Word16 T0, /* i : integer pitch lag */ + const Word16 T0_frac, /* i : pitch fraction */ + Word16 *T0_min, /* i/o: delta search min */ + Word16 *T0_max /* o : delta search max_val */ ) { Word16 pitch_index; - IF( EQ_16(nBits,10)) /* absolute encoding with 10 bits */ + IF( EQ_16( nBits, 10 ) ) /* absolute encoding with 10 bits */ { IF( limit_flag == 0 ) { /* pitch_index = T0*4 + T0_frac - (PIT_MIN*4);*/ - pitch_index = sub(add(shl(T0 , 2), T0_frac), (PIT_MIN*4)); + pitch_index = sub( add( shl( T0, 2 ), T0_frac ), ( PIT_MIN * 4 ) ); } - ELSE IF( EQ_16(limit_flag,1)) + ELSE IF( EQ_16( limit_flag, 1 ) ) { /*pitch_index = T0*4 + T0_frac - (PIT_MIN_EXTEND*4);*/ - pitch_index = sub(add(shl(T0 , 2),T0_frac),(PIT_MIN_EXTEND*4)); + pitch_index = sub( add( shl( T0, 2 ), T0_frac ), ( PIT_MIN_EXTEND * 4 ) ); } - ELSE /* limit_flag == 2 */ + ELSE /* limit_flag == 2 */ { /*pitch_index = T0*4 + T0_frac - (PIT_MIN_DOUBLEEXTEND*4);*/ - pitch_index = sub(add(shl(T0 , 2) ,T0_frac) , (PIT_MIN_DOUBLEEXTEND*4)); + pitch_index = sub( add( shl( T0, 2 ), T0_frac ), ( PIT_MIN_DOUBLEEXTEND * 4 ) ); } } - ELSE IF( EQ_16(nBits,9)) /* absolute encoding with 9 bits */ + ELSE IF( EQ_16( nBits, 9 ) ) /* absolute encoding with 9 bits */ { pitch_index = abs_pit_enc_fx( 4, limit_flag, T0, T0_frac ); /* find T0_min and T0_max for delta search */ IF( Opt_AMR_WB ) { - limit_T0_fx( L_FRAME, delta, pit_flag, 0, T0, 0, T0_min, T0_max ); /* T0_frac==0 to keep IO with AMR-WB */ + limit_T0_fx( L_FRAME, delta, pit_flag, 0, T0, 0, T0_min, T0_max ); /* T0_frac==0 to keep IO with AMR-WB */ } } - ELSE IF( EQ_16(nBits,8)) /* absolute encoding with 8 bits */ + ELSE IF( EQ_16( nBits, 8 ) ) /* absolute encoding with 8 bits */ { pitch_index = abs_pit_enc_fx( 2, limit_flag, T0, T0_frac ); /* find T0_min and T0_max for delta search */ IF( Opt_AMR_WB ) { - limit_T0_fx( L_FRAME, delta, pit_flag, 0, T0, 0, T0_min, T0_max ); /* T0_frac==0 to keep IO with AMR-WB */ + limit_T0_fx( L_FRAME, delta, pit_flag, 0, T0, 0, T0_min, T0_max ); /* T0_frac==0 to keep IO with AMR-WB */ } } - ELSE IF( EQ_16(nBits,6)) /* relative encoding with 6 bits */ + ELSE IF( EQ_16( nBits, 6 ) ) /* relative encoding with 6 bits */ { pitch_index = delta_pit_enc_fx( 4, T0, T0_frac, *T0_min ); } - ELSE IF( EQ_16(nBits,5)) /* relative encoding with 5 bits */ + ELSE IF( EQ_16( nBits, 5 ) ) /* relative encoding with 5 bits */ { - IF( EQ_16(delta,8)) + IF( EQ_16( delta, 8 ) ) { pitch_index = delta_pit_enc_fx( 2, T0, T0_frac, *T0_min ); } - ELSE /* delta == 4 */ + ELSE /* delta == 4 */ { pitch_index = delta_pit_enc_fx( 4, T0, T0_frac, *T0_min ); } } - ELSE /* nBits == 4 ) */ /* relative encoding with 4 bits */ + ELSE /* nBits == 4 ) */ /* relative encoding with 4 bits */ { - IF( EQ_16(delta,8)) + IF( EQ_16( delta, 8 ) ) { pitch_index = delta_pit_enc_fx( 0, T0, T0_frac, *T0_min ); } - ELSE /* delta == 4 */ + ELSE /* delta == 4 */ { pitch_index = delta_pit_enc_fx( 2, T0, T0_frac, *T0_min ); } @@ -1116,7 +1114,7 @@ void pit_Q_enc_fx( } { - push_indice_fx(hBstr, IND_PITCH, pitch_index, nBits ); + push_indice_fx( hBstr, IND_PITCH, pitch_index, nBits ); } return; @@ -1129,35 +1127,35 @@ void pit_Q_enc_fx( *-------------------------------------------------------------------*/ void pit16k_Q_enc_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 nBits, /* i : # of Q bits */ - const Word16 limit_flag, /* i : restrained(0) or extended(1) Q limits */ - const Word16 T0, /* i : integer pitch lag */ - const Word16 T0_frac, /* i : pitch fraction */ - Word16 *T0_min, /* i/o: delta search min */ - Word16 *T0_max /* o : delta search max_val */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 nBits, /* i : # of Q bits */ + const Word16 limit_flag, /* i : restrained(0) or extended(1) Q limits */ + const Word16 T0, /* i : integer pitch lag */ + const Word16 T0_frac, /* i : pitch fraction */ + Word16 *T0_min, /* i/o: delta search min */ + Word16 *T0_max /* o : delta search max_val */ ) { Word16 pitch_index; - IF( EQ_16(nBits,10)) /* absolute encoding with 10 bits */ + IF( EQ_16( nBits, 10 ) ) /* absolute encoding with 10 bits */ { { - IF( LT_16(T0,PIT16k_FR2_EXTEND_10b)) + IF( LT_16( T0, PIT16k_FR2_EXTEND_10b ) ) { /*pitch_index = T0*4 + T0_frac - (PIT16k_MIN_EXTEND*4);*/ - pitch_index = add(shl(T0 , 2) , sub(T0_frac , (PIT16k_MIN_EXTEND*4))); + pitch_index = add( shl( T0, 2 ), sub( T0_frac, ( PIT16k_MIN_EXTEND * 4 ) ) ); } ELSE { /*pitch_index = T0*2 + (T0_frac>>1) - (PIT16k_FR2_EXTEND_10b*2) + ((PIT16k_FR2_EXTEND_10b-PIT16k_MIN_EXTEND)*4);*/ - pitch_index = add(sub(add(shl(T0,1),shr(T0_frac,1)),(PIT16k_FR2_EXTEND_10b*2)),((PIT16k_FR2_EXTEND_10b-PIT16k_MIN_EXTEND)*4)); + pitch_index = add( sub( add( shl( T0, 1 ), shr( T0_frac, 1 ) ), ( PIT16k_FR2_EXTEND_10b * 2 ) ), ( ( PIT16k_FR2_EXTEND_10b - PIT16k_MIN_EXTEND ) * 4 ) ); } } - push_indice_fx(hBstr, IND_PITCH, pitch_index, nBits ); + push_indice_fx( hBstr, IND_PITCH, pitch_index, nBits ); } - ELSE IF( EQ_16(nBits,9)) /* absolute encoding with 9 bits */ + ELSE IF( EQ_16( nBits, 9 ) ) /* absolute encoding with 9 bits */ { { /*-------------------------------------------------------------------* @@ -1168,31 +1166,31 @@ void pit16k_Q_enc_fx( * PIT16k_FR1_EXTEND_9b to PIT16k_MAX_EXTEND resolution 1 (frac = 0) *-------------------------------------------------------------------*/ - IF( LT_16(T0,PIT16k_FR2_EXTEND_9b)) + IF( LT_16( T0, PIT16k_FR2_EXTEND_9b ) ) { /*pitch_index = T0*4 + T0_frac - (PIT16k_MIN_EXTEND*4);*/ - pitch_index = add(shl(T0 , 2) , sub(T0_frac , (PIT16k_MIN_EXTEND*4))); + pitch_index = add( shl( T0, 2 ), sub( T0_frac, ( PIT16k_MIN_EXTEND * 4 ) ) ); } - ELSE IF( LT_16(T0,PIT16k_FR1_EXTEND_9b)) + ELSE IF( LT_16( T0, PIT16k_FR1_EXTEND_9b ) ) { /*pitch_index = T0*2 + (T0_frac>>1) - (PIT16k_FR2_EXTEND_9b*2) + ((PIT16k_FR2_EXTEND_9b-PIT16k_MIN_EXTEND)*4);*/ - pitch_index = add(sub(add(shl(T0,1),shr(T0_frac,1)),(PIT16k_FR2_EXTEND_9b*2)),((PIT16k_FR2_EXTEND_9b-PIT16k_MIN_EXTEND)*4)); + pitch_index = add( sub( add( shl( T0, 1 ), shr( T0_frac, 1 ) ), ( PIT16k_FR2_EXTEND_9b * 2 ) ), ( ( PIT16k_FR2_EXTEND_9b - PIT16k_MIN_EXTEND ) * 4 ) ); } ELSE { /*pitch_index = T0 - PIT16k_FR1_EXTEND_9b + ((PIT16k_FR2_EXTEND_9b-PIT16k_MIN_EXTEND)*4) + ((PIT16k_FR1_EXTEND_9b-PIT16k_FR2_EXTEND_9b)*2);*/ - pitch_index = add(add(sub(T0, PIT16k_FR1_EXTEND_9b) , ((PIT16k_FR2_EXTEND_9b-PIT16k_MIN_EXTEND)*4)), ((PIT16k_FR1_EXTEND_9b-PIT16k_FR2_EXTEND_9b)*2)); + pitch_index = add( add( sub( T0, PIT16k_FR1_EXTEND_9b ), ( ( PIT16k_FR2_EXTEND_9b - PIT16k_MIN_EXTEND ) * 4 ) ), ( ( PIT16k_FR1_EXTEND_9b - PIT16k_FR2_EXTEND_9b ) * 2 ) ); } } - push_indice_fx(hBstr, IND_PITCH, pitch_index, 9 ); + push_indice_fx( hBstr, IND_PITCH, pitch_index, 9 ); } - ELSE /* nBits == 6 */ /* relative encoding with 6 bits */ + ELSE /* nBits == 6 */ /* relative encoding with 6 bits */ { /*pitch_index = (T0 - *T0_min) * 4 + T0_frac;*/ - pitch_index = add(shl(sub(T0,*T0_min),2),T0_frac); + pitch_index = add( shl( sub( T0, *T0_min ), 2 ), T0_frac ); - push_indice_fx(hBstr, IND_PITCH, pitch_index, nBits ); + push_indice_fx( hBstr, IND_PITCH, pitch_index, nBits ); } limit_T0_fx( L_FRAME16k, 8, L_SUBFR, limit_flag, T0, T0_frac, T0_min, T0_max ); @@ -1208,27 +1206,26 @@ void pit16k_Q_enc_fx( * Adaptive excitation construction *------------------------------------------------------------------*/ void Mode2_pit_encode_fx( - const Word16 coder_type, /* i : coding model */ - const Word16 i_subfr, /* i : subframe index */ - Word16 **pt_indice, /* i/o: quantization indices pointer */ - Word16 *exc, /* i/o: pointer to excitation signal frame */ - const Word16 *T_op, /* i : open loop pitch estimates in current frame */ - Word16 *T0_min, /* i/o: lower limit for close-loop search */ - Word16 *T0_min_frac, /* i/o: lower limit for close-loop search */ - Word16 *T0_max, /* i/o: higher limit for close-loop search */ - Word16 *T0_max_frac, /* i/o: higher limit for close-loop search */ - Word16 *T0, /* i/o: close loop integer pitch */ - Word16 *T0_frac, /* i/o: close loop fractional part of the pitch */ - Word16 *T0_res, /* i/o: close loop pitch resolution */ - Word16 *h1, /* i : weighted filter impulse response 1Q14+shift*/ - Word16 *xn, /* i : target vector */ + const Word16 coder_type, /* i : coding model */ + const Word16 i_subfr, /* i : subframe index */ + Word16 **pt_indice, /* i/o: quantization indices pointer */ + Word16 *exc, /* i/o: pointer to excitation signal frame */ + const Word16 *T_op, /* i : open loop pitch estimates in current frame */ + Word16 *T0_min, /* i/o: lower limit for close-loop search */ + Word16 *T0_min_frac, /* i/o: lower limit for close-loop search */ + Word16 *T0_max, /* i/o: higher limit for close-loop search */ + Word16 *T0_max_frac, /* i/o: higher limit for close-loop search */ + Word16 *T0, /* i/o: close loop integer pitch */ + Word16 *T0_frac, /* i/o: close loop fractional part of the pitch */ + Word16 *T0_res, /* i/o: close loop pitch resolution */ + Word16 *h1, /* i : weighted filter impulse response 1Q14+shift*/ + Word16 *xn, /* i : target vector */ Word16 pit_min, Word16 pit_fr1, Word16 pit_fr1b, Word16 pit_fr2, Word16 pit_max, - Word16 pit_res_max -) + Word16 pit_res_max ) { Word16 pit_flag; @@ -1237,7 +1234,7 @@ void Mode2_pit_encode_fx( /* Pitch flag */ pit_flag = i_subfr; move16(); - if ( EQ_16(i_subfr,(2*L_SUBFR))) + if ( EQ_16( i_subfr, ( 2 * L_SUBFR ) ) ) { pit_flag = 0; move16(); @@ -1248,7 +1245,7 @@ void Mode2_pit_encode_fx( * - Fractional pitch search * - Pitch quantization *-----------------------------------------------------------------*/ - IF(coder_type == 0) /*Unvoiced Coding do nothing*/ + IF( coder_type == 0 ) /*Unvoiced Coding do nothing*/ { *T0 = L_SUBFR; move16(); @@ -1256,81 +1253,79 @@ void Mode2_pit_encode_fx( move16(); *T0_res = 1; move16(); - } - ELSE IF(EQ_16(coder_type,1)) /* 8/4/4/4 (EVS) */ + ELSE IF( EQ_16( coder_type, 1 ) ) /* 8/4/4/4 (EVS) */ { - IF (i_subfr == 0) + IF( i_subfr == 0 ) { - limit_T0_voiced( 4, shr(pit_res_max,1), T_op[0], 0, 1, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); + limit_T0_voiced( 4, shr( pit_res_max, 1 ), T_op[0], 0, 1, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); } ELSE { - limit_T0_voiced( 4, shr(pit_res_max,1), *T0, *T0_frac, *T0_res, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); + limit_T0_voiced( 4, shr( pit_res_max, 1 ), *T0, *T0_frac, *T0_res, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); } - *T0 = E_GAIN_closed_loop_search_fx(exc, xn, h1, *T0_min, *T0_min_frac, *T0_max, *T0_max_frac, shr(pit_res_max,1), T0_frac, T0_res, pit_res_max, - i_subfr, pit_min, pit_min, pit_fr1b, L_SUBFR); + *T0 = E_GAIN_closed_loop_search_fx( exc, xn, h1, *T0_min, *T0_min_frac, *T0_max, *T0_max_frac, shr( pit_res_max, 1 ), T0_frac, T0_res, pit_res_max, + i_subfr, pit_min, pit_min, pit_fr1b, L_SUBFR ); move16(); - IF (i_subfr == 0) + IF( i_subfr == 0 ) { Mode2_abs_pit_enc_fx( *T0, *T0_frac, pt_indice, pit_min, pit_fr1b, pit_min, pit_res_max ); } ELSE { - Mode2_delta_pit_enc_fx( *T0, *T0_frac, shr(pit_res_max,1), *T0_min, *T0_min_frac, pt_indice ); + Mode2_delta_pit_enc_fx( *T0, *T0_frac, shr( pit_res_max, 1 ), *T0_min, *T0_min_frac, pt_indice ); } - } - ELSE IF(EQ_16(coder_type,2)) /* 8/5/8/5 (EVS) */ + ELSE IF( EQ_16( coder_type, 2 ) ) /* 8/5/8/5 (EVS) */ { - IF (i_subfr == 0) + IF( i_subfr == 0 ) { - limit_T0_voiced( 5, shr(pit_res_max,1), T_op[0], 0, 1, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); + limit_T0_voiced( 5, shr( pit_res_max, 1 ), T_op[0], 0, 1, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); } - ELSE IF(i_subfr == 2*L_SUBFR) + ELSE IF( i_subfr == 2 * L_SUBFR ) { - limit_T0_voiced( 5, shr(pit_res_max,1), T_op[1], 0, 1, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); + limit_T0_voiced( 5, shr( pit_res_max, 1 ), T_op[1], 0, 1, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); } ELSE { - limit_T0_voiced( 5, shr(pit_res_max,1), *T0, *T0_frac, *T0_res, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); + limit_T0_voiced( 5, shr( pit_res_max, 1 ), *T0, *T0_frac, *T0_res, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); } - *T0 = E_GAIN_closed_loop_search_fx(exc, xn, h1, *T0_min, *T0_min_frac, *T0_max, *T0_max_frac, shr(pit_res_max,1), T0_frac, T0_res, pit_res_max, - pit_flag, pit_min, pit_min, pit_fr1b, L_SUBFR); + *T0 = E_GAIN_closed_loop_search_fx( exc, xn, h1, *T0_min, *T0_min_frac, *T0_max, *T0_max_frac, shr( pit_res_max, 1 ), T0_frac, T0_res, pit_res_max, + pit_flag, pit_min, pit_min, pit_fr1b, L_SUBFR ); move16(); - IF (pit_flag == 0) + IF( pit_flag == 0 ) { Mode2_abs_pit_enc_fx( *T0, *T0_frac, pt_indice, pit_min, pit_fr1b, pit_min, pit_res_max ); } ELSE { - Mode2_delta_pit_enc_fx( *T0, *T0_frac, shr(pit_res_max,1), *T0_min, *T0_min_frac, pt_indice ); + Mode2_delta_pit_enc_fx( *T0, *T0_frac, shr( pit_res_max, 1 ), *T0_min, *T0_min_frac, pt_indice ); } } - ELSE IF(EQ_16(coder_type,3)) /* 9/6/6/6 (HRs- VC) */ + ELSE IF( EQ_16( coder_type, 3 ) ) /* 9/6/6/6 (HRs- VC) */ { Word16 pit_res_max2 = pit_res_max; - if ( EQ_16(pit_min,PIT_MIN_16k)) + if ( EQ_16( pit_min, PIT_MIN_16k ) ) { - pit_res_max2 = shr(pit_res_max, 1); + pit_res_max2 = shr( pit_res_max, 1 ); } - IF ( (i_subfr == 0) ) + IF( ( i_subfr == 0 ) ) { limit_T0_voiced2( pit_res_max2, T_op, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max, i_subfr ); } ELSE { - limit_T0_voiced( 6, pit_res_max2, *T0, 0, 1, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max); + limit_T0_voiced( 6, pit_res_max2, *T0, 0, 1, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); } - *T0 = E_GAIN_closed_loop_search_fx(exc, xn, h1, *T0_min, *T0_min_frac, *T0_max, *T0_max_frac, pit_res_max2, T0_frac, T0_res, pit_res_max, - i_subfr, pit_min, pit_fr2, pit_fr1, L_SUBFR); + *T0 = E_GAIN_closed_loop_search_fx( exc, xn, h1, *T0_min, *T0_min_frac, *T0_max, *T0_max_frac, pit_res_max2, T0_frac, T0_res, pit_res_max, + i_subfr, pit_min, pit_fr2, pit_fr1, L_SUBFR ); move16(); - IF (i_subfr == 0) /* if 1st subframe */ + IF( i_subfr == 0 ) /* if 1st subframe */ { Mode2_abs_pit_enc_fx( *T0, *T0_frac, pt_indice, pit_min, pit_fr1, pit_fr2, pit_res_max ); } @@ -1339,25 +1334,25 @@ void Mode2_pit_encode_fx( Mode2_delta_pit_enc_fx( *T0, *T0_frac, pit_res_max2, *T0_min, *T0_min_frac, pt_indice ); } } - ELSE IF(coder_type == 4) /* 9/6/9/6 (AMRWB) */ + ELSE IF( coder_type == 4 ) /* 9/6/9/6 (AMRWB) */ { Word16 pit_res_max2 = pit_res_max; - if ( EQ_16(pit_min,PIT_MIN_16k)) + if ( EQ_16( pit_min, PIT_MIN_16k ) ) { - pit_res_max2 = shr(pit_res_max,1); + pit_res_max2 = shr( pit_res_max, 1 ); } test(); - IF ( (i_subfr == 0) || EQ_16(i_subfr,shl(L_SUBFR,1))) + IF( ( i_subfr == 0 ) || EQ_16( i_subfr, shl( L_SUBFR, 1 ) ) ) { limit_T0_voiced2( pit_res_max2, T_op, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max, i_subfr ); } ELSE { - limit_T0_voiced( 6, pit_res_max2, *T0, 0, 1, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max); + limit_T0_voiced( 6, pit_res_max2, *T0, 0, 1, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); } - *T0 = E_GAIN_closed_loop_search_fx(exc, xn, h1, *T0_min, *T0_min_frac, *T0_max, *T0_max_frac, pit_res_max2, T0_frac, T0_res, pit_res_max, - pit_flag, pit_min, pit_fr2, pit_fr1, L_SUBFR); - IF (pit_flag == 0) /* if 1st/3rd/5th subframe */ + *T0 = E_GAIN_closed_loop_search_fx( exc, xn, h1, *T0_min, *T0_min_frac, *T0_max, *T0_max_frac, pit_res_max2, T0_frac, T0_res, pit_res_max, + pit_flag, pit_min, pit_fr2, pit_fr1, L_SUBFR ); + IF( pit_flag == 0 ) /* if 1st/3rd/5th subframe */ { Mode2_abs_pit_enc_fx( *T0, *T0_frac, pt_indice, pit_min, pit_fr1, pit_fr2, pit_res_max ); } @@ -1366,48 +1361,48 @@ void Mode2_pit_encode_fx( Mode2_delta_pit_enc_fx( *T0, *T0_frac, pit_res_max2, *T0_min, *T0_min_frac, pt_indice ); } } - ELSE IF(EQ_16(coder_type,8)) /* 8/5/5/5 (RF all pred mode) */ + ELSE IF( EQ_16( coder_type, 8 ) ) /* 8/5/5/5 (RF all pred mode) */ { - IF (i_subfr == 0) + IF( i_subfr == 0 ) { - limit_T0_voiced( 5, shr(pit_res_max,1), T_op[0], 0, 1, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); + limit_T0_voiced( 5, shr( pit_res_max, 1 ), T_op[0], 0, 1, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); } ELSE { - limit_T0_voiced( 5, shr(pit_res_max,1), *T0, *T0_frac, *T0_res, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); + limit_T0_voiced( 5, shr( pit_res_max, 1 ), *T0, *T0_frac, *T0_res, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); } - *T0 = E_GAIN_closed_loop_search_fx( exc, xn, h1, *T0_min, *T0_min_frac, *T0_max, *T0_max_frac, shr(pit_res_max,1), T0_frac, T0_res, pit_res_max, - i_subfr, pit_min, pit_min, pit_fr1b, L_SUBFR ); + *T0 = E_GAIN_closed_loop_search_fx( exc, xn, h1, *T0_min, *T0_min_frac, *T0_max, *T0_max_frac, shr( pit_res_max, 1 ), T0_frac, T0_res, pit_res_max, + i_subfr, pit_min, pit_min, pit_fr1b, L_SUBFR ); - IF (i_subfr == 0) + IF( i_subfr == 0 ) { Mode2_abs_pit_enc_fx( *T0, *T0_frac, pt_indice, pit_min, pit_fr1b, pit_min, pit_res_max ); } ELSE { - Mode2_delta_pit_enc_fx( *T0, *T0_frac, shr(pit_res_max,1), *T0_min, *T0_min_frac, pt_indice ); + Mode2_delta_pit_enc_fx( *T0, *T0_frac, shr( pit_res_max, 1 ), *T0_min, *T0_min_frac, pt_indice ); } } - ELSE IF(EQ_16(coder_type,9)) /* 8/0/8/0 (RF mode Gen pred) */ + ELSE IF( EQ_16( coder_type, 9 ) ) /* 8/0/8/0 (RF mode Gen pred) */ { - IF (i_subfr == 0) + IF( i_subfr == 0 ) { - limit_T0_voiced( 4, shr(pit_res_max,1), T_op[0], 0, 1, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); + limit_T0_voiced( 4, shr( pit_res_max, 1 ), T_op[0], 0, 1, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); } ELSE { - limit_T0_voiced( 4, shr(pit_res_max,1), *T0, *T0_frac, *T0_res, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); + limit_T0_voiced( 4, shr( pit_res_max, 1 ), *T0, *T0_frac, *T0_res, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); } - *T0 = E_GAIN_closed_loop_search_fx( exc, xn, h1, *T0_min, *T0_min_frac, *T0_max, *T0_max_frac, shr(pit_res_max,1), T0_frac, T0_res, pit_res_max, - i_subfr, pit_min, pit_min, pit_fr1b, L_SUBFR ); + *T0 = E_GAIN_closed_loop_search_fx( exc, xn, h1, *T0_min, *T0_min_frac, *T0_max, *T0_max_frac, shr( pit_res_max, 1 ), T0_frac, T0_res, pit_res_max, + i_subfr, pit_min, pit_min, pit_fr1b, L_SUBFR ); - IF (i_subfr == 0) + IF( i_subfr == 0 ) { Mode2_abs_pit_enc_fx( *T0, *T0_frac, pt_indice, pit_min, pit_fr1b, pit_min, pit_res_max ); } ELSE { - Mode2_delta_pit_enc_fx( *T0, *T0_frac, shr(pit_res_max,1), *T0_min, *T0_min_frac, pt_indice ); + Mode2_delta_pit_enc_fx( *T0, *T0_frac, shr( pit_res_max, 1 ), *T0_min, *T0_min_frac, pt_indice ); } } @@ -1425,57 +1420,56 @@ static void limit_T0_voiced2( Word16 *T0_max_frac, Word16 pit_min, Word16 pit_max, - Word16 i_subfr -) + Word16 i_subfr ) { Word16 t, temp1, temp2, res2; - assert(res > 1 && res<=6); + assert( res > 1 && res <= 6 ); res2 = res; move16(); - if(EQ_16(res,6)) + if ( EQ_16( res, 6 ) ) { - res2 =shr(res2,1); + res2 = shr( res2, 1 ); } /* Lower-bound */ - IF (i_subfr == 0) + IF( i_subfr == 0 ) { - temp1 = sub(i_mult2(T_op[0],res),32); + temp1 = sub( i_mult2( T_op[0], res ), 32 ); } ELSE { - temp1 = sub(i_mult2(T_op[1],res),32); + temp1 = sub( i_mult2( T_op[1], res ), 32 ); } - IF (LT_16(T_op[0],T_op[1])) + IF( LT_16( T_op[0], T_op[1] ) ) { - t = sub(i_mult2(T_op[0],res),16); + t = sub( i_mult2( T_op[0], res ), 16 ); } ELSE { - t = sub(i_mult2(T_op[1],res),16); + t = sub( i_mult2( T_op[1], res ), 16 ); } - if (LT_16(temp1,t)) + if ( LT_16( temp1, t ) ) { temp1 = t; } - temp2 = mult(temp1,inv_T0_res[res2]); - if(EQ_16(res,6)) + temp2 = mult( temp1, inv_T0_res[res2] ); + if ( EQ_16( res, 6 ) ) { - temp2 = shr(temp2,1); + temp2 = shr( temp2, 1 ); } *T0_min = temp2; move16(); - *T0_min_frac = sub(temp1,i_mult2(temp2,res)); + *T0_min_frac = sub( temp1, i_mult2( temp2, res ) ); move16(); - IF ( LT_16(*T0_min,pit_min)) + IF( LT_16( *T0_min, pit_min ) ) { *T0_min = pit_min; move16(); @@ -1484,50 +1478,49 @@ static void limit_T0_voiced2( } /* Higher-bound */ - temp1 = add(i_mult2(*T0_min,res),add(*T0_min_frac,63)); + temp1 = add( i_mult2( *T0_min, res ), add( *T0_min_frac, 63 ) ); - IF (T_op[0] -#include "options.h" /* Compilation switches */ +#include "options.h" /* Compilation switches */ #include "cnst.h" /* Common constants */ #include "rom_enc.h" /* Encoder static table prototypes */ -#include "rom_com_fx.h" /* Encoder static table prototypes */ +#include "rom_com_fx.h" /* Encoder static table prototypes */ #include "rom_com.h" /* Encoder static table prototypes */ #include "rom_dec.h" //#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* * Local constants *-------------------------------------------------------------------*/ -#define MAX_DELTA 16 /* half-length of the delta search */ -#define COR_BUF_LEN (L_INTERPOL1*2 + MAX_DELTA*2 + 1) +#define MAX_DELTA 16 /* half-length of the delta search */ +#define COR_BUF_LEN ( L_INTERPOL1 * 2 + MAX_DELTA * 2 + 1 ) /*-------------------------------------------------------------------* * pitch_ol2() @@ -28,13 +28,16 @@ * i.e. the value pitch_ol + delta is not a part of the interval *-------------------------------------------------------------------*/ void pitch_ol2_fx( - const Word16 pit_min, /* i : minimum pitch value (20 or 29) */ - const Word16 pitch_ol, /* i : pitch to be improved */ - Word16 *pitch_fr_fx, /* o : adjusted 1/4 fractional pitch */ /*Q7*/ - Word16 *voicing_fr_fx, /* o : adjusted 1/4 fractional voicing */ /*Q15*/ - const Word16 pos, /* i : position in frame where to calculate the improv. */ - const Word16 *wsp_fx, /* i : weighted speech for current frame and look-ahead */ /*Q_new-1+shift*/ - const Word16 delta /* i : delta for pitch search (2 or 7) */ + const Word16 pit_min, /* i : minimum pitch value (20 or 29) */ + const Word16 pitch_ol, /* i : pitch to be improved */ + Word16 *pitch_fr_fx, + /* o : adjusted 1/4 fractional pitch */ /*Q7*/ + Word16 *voicing_fr_fx, + /* o : adjusted 1/4 fractional voicing */ /*Q15*/ + const Word16 pos, /* i : position in frame where to calculate the improv. */ + const Word16 *wsp_fx, + /* i : weighted speech for current frame and look-ahead */ /*Q_new-1+shift*/ + const Word16 delta /* i : delta for pitch search (2 or 7) */ ) { Word16 i, t, step, fraction, t0_min, t0_max, t_min, t_max; @@ -54,36 +57,36 @@ void pitch_ol2_fx( /* initialization */ pit_max = PIT_MAX; move16(); - t0_min = sub(pitch_ol, delta); - t0_max = add(pitch_ol, sub(delta, 1)); - t0_min = s_max(t0_min, pit_min); - t_min = sub(t0_min, L_INTERPOL1); + t0_min = sub( pitch_ol, delta ); + t0_max = add( pitch_ol, sub( delta, 1 ) ); + t0_min = s_max( t0_min, pit_min ); + t_min = sub( t0_min, L_INTERPOL1 ); - t0_max = s_min(t0_max, pit_max); - t_max = add(t0_max, L_INTERPOL1); + t0_max = s_min( t0_max, pit_max ); + t_max = add( t0_max, L_INTERPOL1 ); pt_wsp_fx = wsp_fx + pos; pt_cor_32 = cor_32; - t1 = L_deposit_l(0); - FOR (t=t_min; t<=t_max; t++) + t1 = L_deposit_l( 0 ); + FOR( t = t_min; t <= t_max; t++ ) { - t0 = Dot_product(pt_wsp_fx, pt_wsp_fx-t, L_SUBFR); + t0 = Dot_product( pt_wsp_fx, pt_wsp_fx - t, L_SUBFR ); *pt_cor_32++ = t0; move32(); - t0 = L_abs(t0); - t1 = L_max(t1, t0); + t0 = L_abs( t0 ); + t1 = L_max( t1, t0 ); } - exp3 = norm_l(t1); + exp3 = norm_l( t1 ); pt_cor_32 = cor_32; pt_cor_fx = cor_fx; - FOR ( t=t_min; t<=t_max; t++ ) + FOR( t = t_min; t <= t_max; t++ ) { #ifdef BASOP_NOGLOB - t0 = L_shl_o(*pt_cor_32++, exp3, &Overflow); - *pt_cor_fx++ = round_fx_o(t0, &Overflow); + t0 = L_shl_o( *pt_cor_32++, exp3, &Overflow ); + *pt_cor_fx++ = round_fx_o( t0, &Overflow ); #else - t0 = L_shl(*pt_cor_32++, exp3); - *pt_cor_fx++ = round_fx(t0); + t0 = L_shl( *pt_cor_32++, exp3 ); + *pt_cor_fx++ = round_fx( t0 ); #endif } @@ -92,14 +95,14 @@ void pitch_ol2_fx( move16(); t1s = t0_min; move16(); - FOR (t=add(t0_min, 1); t<=t0_max; t++) + FOR( t = add( t0_min, 1 ); t <= t0_max; t++ ) { - if (GT_16(*pt_cor_fx, cor_max_fx)) + if ( GT_16( *pt_cor_fx, cor_max_fx ) ) { t1s = t; move16(); } - cor_max_fx = s_max(cor_max_fx, *pt_cor_fx); + cor_max_fx = s_max( cor_max_fx, *pt_cor_fx ); pt_cor_fx++; } @@ -108,44 +111,44 @@ void pitch_ol2_fx( * search the fractions around t0 and choose the one which maximizes * the interpolated normalized correlation. *----------------------------------------------------------------*/ - pt_cor_fx = cor_fx + sub(L_INTERPOL1, t0_min); + pt_cor_fx = cor_fx + sub( L_INTERPOL1, t0_min ); t0s = t1s; move16(); step = 1; - move16(); /* 1/4 subsample resolution */ + move16(); /* 1/4 subsample resolution */ fraction = 1; move16(); - IF (NE_16(t0s, t0_min)) /* Process negative fractions */ + IF( NE_16( t0s, t0_min ) ) /* Process negative fractions */ { - t0s = sub(t0s,1); - cor_max_fx = Interpol_4(&pt_cor_fx[t0s], fraction); + t0s = sub( t0s, 1 ); + cor_max_fx = Interpol_4( &pt_cor_fx[t0s], fraction ); move16(); - FOR (i=add(fraction, step); i<=3; i+=step) + FOR( i = add( fraction, step ); i <= 3; i += step ) { - temp_fx = Interpol_4(&pt_cor_fx[t0s], i); - if (GT_16(temp_fx, cor_max_fx)) + temp_fx = Interpol_4( &pt_cor_fx[t0s], i ); + if ( GT_16( temp_fx, cor_max_fx ) ) { fraction = i; move16(); } - cor_max_fx = s_max(temp_fx, cor_max_fx); + cor_max_fx = s_max( temp_fx, cor_max_fx ); } } ELSE /* Limit case */ { fraction = 0; move16(); - cor_max_fx = Interpol_4(&pt_cor_fx[t0s], fraction); + cor_max_fx = Interpol_4( &pt_cor_fx[t0s], fraction ); move16(); } - FOR (i = 0; i<=3; i+=step) /* Process positive fractions */ + FOR( i = 0; i <= 3; i += step ) /* Process positive fractions */ { - temp_fx = Interpol_4(&pt_cor_fx[t1s], i); + temp_fx = Interpol_4( &pt_cor_fx[t1s], i ); move16(); - IF (GT_16(temp_fx,cor_max_fx)) + IF( GT_16( temp_fx, cor_max_fx ) ) { cor_max_fx = temp_fx; move16(); @@ -156,66 +159,66 @@ void pitch_ol2_fx( } } - *pitch_fr_fx = shl(add(shl(t0s, 2), fraction), 4); - move16(); /*Q7*/ + *pitch_fr_fx = shl( add( shl( t0s, 2 ), fraction ), 4 ); + move16(); /*Q7*/ - IF( NE_32(t1, 1L)) + IF( NE_32( t1, 1L ) ) { - pred_lt4(pt_wsp_fx, wsp_fr_fx, t0s, fraction, L_SUBFR, pitch_inter4_1, 4, PIT_UP_SAMP); + pred_lt4( pt_wsp_fx, wsp_fr_fx, t0s, fraction, L_SUBFR, pitch_inter4_1, 4, PIT_UP_SAMP ); R0 = cor_max_fx; move16(); - R1 = L_mult(pt_wsp_fx[0], pt_wsp_fx[0]); - R2 = L_mult(wsp_fr_fx[0], wsp_fr_fx[0]); - FOR (j = 1; j < L_SUBFR; j++) + R1 = L_mult( pt_wsp_fx[0], pt_wsp_fx[0] ); + R2 = L_mult( wsp_fr_fx[0], wsp_fr_fx[0] ); + FOR( j = 1; j < L_SUBFR; j++ ) { #ifdef BASOP_NOGLOB R1 = L_mac_sat( R1, pt_wsp_fx[j], pt_wsp_fx[j] ); - R2 = L_mac_sat(R2, wsp_fr_fx[j], wsp_fr_fx[j]); + R2 = L_mac_sat( R2, wsp_fr_fx[j], wsp_fr_fx[j] ); #else - R1 = L_mac(R1, pt_wsp_fx[j], pt_wsp_fx[j]); - R2 = L_mac(R2, wsp_fr_fx[j], wsp_fr_fx[j]); + R1 = L_mac( R1, pt_wsp_fx[j], pt_wsp_fx[j] ); + R2 = L_mac( R2, wsp_fr_fx[j], wsp_fr_fx[j] ); #endif } /* *voicing_fr = cor_max * inv_sqrt(enr_wsp * enr_old) */ /* *voicing_fr = R0 * inv_sqrt(R1 * R2) */ - exp_R0 = norm_s(R0); - R0 = shl(R0, exp_R0); + exp_R0 = norm_s( R0 ); + R0 = shl( R0, exp_R0 ); - exp_R1 = norm_l(R1); - R1 = L_shl(R1, exp_R1); + exp_R1 = norm_l( R1 ); + R1 = L_shl( R1, exp_R1 ); - exp_R2 = norm_l(R2); - R2 = L_shl(R2, exp_R2); + exp_R2 = norm_l( R2 ); + R2 = L_shl( R2, exp_R2 ); #ifdef BASOP_NOGLOB - R1 = L_mult_o(round_fx_o(R1, &Overflow) , round_fx_o(R2, &Overflow), &Overflow); + R1 = L_mult_o( round_fx_o( R1, &Overflow ), round_fx_o( R2, &Overflow ), &Overflow ); #else - R1 = L_mult(round_fx(R1), round_fx(R2)); + R1 = L_mult( round_fx( R1 ), round_fx( R2 ) ); #endif - i = norm_l(R1); - R1 = L_shl(R1, i); + i = norm_l( R1 ); + R1 = L_shl( R1, i ); - exp_R1 = add(exp_R1, exp_R2); - exp_R1 = add(exp_R1, i); - exp_R1 = sub(62, exp_R1); + exp_R1 = add( exp_R1, exp_R2 ); + exp_R1 = add( exp_R1, i ); + exp_R1 = sub( 62, exp_R1 ); - R1 = Isqrt_lc(R1, &exp_R1); + R1 = Isqrt_lc( R1, &exp_R1 ); #ifdef BASOP_NOGLOB - R1 = L_mult(R0, round_fx_o(R1, &Overflow)); + R1 = L_mult( R0, round_fx_o( R1, &Overflow ) ); #else - R1 = L_mult(R0, round_fx(R1)); + R1 = L_mult( R0, round_fx( R1 ) ); #endif - exp_R0 = sub(31, exp_R0); - exp_R0 = sub(add(exp_R0, exp_R1),exp3); + exp_R0 = sub( 31, exp_R0 ); + exp_R0 = sub( add( exp_R0, exp_R1 ), exp3 ); #ifdef BASOP_NOGLOB - *voicing_fr_fx = round_fx_o(L_shl_o(R1, exp_R0, &Overflow), &Overflow); /*Q15*/ -#else /* BASOP_NOGLOB */ - *voicing_fr_fx = round_fx(L_shl(R1, exp_R0)); /*Q15*/ -#endif /* BASOP_NOGLOB */ + *voicing_fr_fx = round_fx_o( L_shl_o( R1, exp_R0, &Overflow ), &Overflow ); /*Q15*/ +#else /* BASOP_NOGLOB */ + *voicing_fr_fx = round_fx( L_shl( R1, exp_R0 ) ); /*Q15*/ +#endif /* BASOP_NOGLOB */ } ELSE { @@ -243,143 +246,142 @@ void StableHighPitchDetect_fx( Word32 *diff_sm, /* i/o: smoothed pitch frequency difference */ Word32 *energy_sm, /* i/o: smoothed energy around pitch frequency */ Word16 Q_new, - Word16 EspecdB[] -) + Word16 EspecdB[] ) { Word16 i, pitch_freq_point; Word16 T, Tp, pit_min; - Word16 energy0_16, energy1_16,ratio, voicing_m; + Word16 energy0_16, energy1_16, ratio, voicing_m; Word32 energy0, energy1, cor_max, diff, sum_energy; const Word16 *pt_wsp; - Word16 tmp,tmp1,exp , diff16,cor_max16 ,exp1,exp2,pit_min_up; - Word32 L_tmp,L_tmp1; + Word16 tmp, tmp1, exp, diff16, cor_max16, exp1, exp2, pit_min_up; + Word32 L_tmp, L_tmp1; Word16 Top; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif /*voicing = (voicing[0] + voicing[1] + voicing[2] )/3;*/ - L_tmp = L_mult(voicing[0],10923); - L_tmp = L_mac(L_tmp, voicing[1],10923); - L_tmp = L_mac(L_tmp, voicing[2],10923); -#ifdef BASOP_NOGLOB + L_tmp = L_mult( voicing[0], 10923 ); + L_tmp = L_mac( L_tmp, voicing[1], 10923 ); + L_tmp = L_mac( L_tmp, voicing[2], 10923 ); +#ifdef BASOP_NOGLOB voicing_m = round_fx_sat( L_tmp ); #else - voicing_m = round_fx(L_tmp); + voicing_m = round_fx( L_tmp ); #endif /**voicing_sm = 0.75f*(*voicing_sm) + 0.25f*voicing;*/ - *voicing_sm = round_fx(L_mac(L_mult(*voicing_sm , 24576), voicing_m , 8192)); + *voicing_sm = round_fx( L_mac( L_mult( *voicing_sm, 24576 ), voicing_m, 8192 ) ); /* pitch_freq_point = (short)(L_FFT/(mult_fact*T_op[1])+0.5f);*/ Top = pitch[1]; - exp = norm_s(Top); - tmp = div_s(shl(1,sub(14,exp)), Top);/*Q(29 - exp)*/ - L_tmp = L_mult0(tmp ,L_FFT);/*Q(29 - exp)*/ - pitch_freq_point = extract_h(L_add (L_shl(L_tmp , sub(exp, 13)),32768)) ; /* Q0*/ - diff = L_deposit_l(0); - sum_energy = L_deposit_l(0); - FOR( i=1; i<2*pitch_freq_point; i++ ) + exp = norm_s( Top ); + tmp = div_s( shl( 1, sub( 14, exp ) ), Top ); /*Q(29 - exp)*/ + L_tmp = L_mult0( tmp, L_FFT ); /*Q(29 - exp)*/ + pitch_freq_point = extract_h( L_add( L_shl( L_tmp, sub( exp, 13 ) ), 32768 ) ); /* Q0*/ + diff = L_deposit_l( 0 ); + sum_energy = L_deposit_l( 0 ); + FOR( i = 1; i < 2 * pitch_freq_point; i++ ) { - diff = L_add(diff ,sub(EspecdB[pitch_freq_point], EspecdB[i])); - sum_energy = L_add(sum_energy, EspecdB[i]); + diff = L_add( diff, sub( EspecdB[pitch_freq_point], EspecdB[i] ) ); + sum_energy = L_add( sum_energy, EspecdB[i] ); } /*sum_energy /= (2*pitch_freq_point-1);*/ - tmp = sub(shl(pitch_freq_point,1) ,1); - exp = norm_s(tmp); - tmp1 = div_s(shl(1,sub(14,exp)),tmp);/*Q(29-exp)*/ - L_tmp = Mult_32_16(sum_energy ,tmp1); - sum_energy = L_shl(L_tmp, sub(exp,14)); + tmp = sub( shl( pitch_freq_point, 1 ), 1 ); + exp = norm_s( tmp ); + tmp1 = div_s( shl( 1, sub( 14, exp ) ), tmp ); /*Q(29-exp)*/ + L_tmp = Mult_32_16( sum_energy, tmp1 ); + sum_energy = L_shl( L_tmp, sub( exp, 14 ) ); /**diff_sm = 0.2f * diff + 0.8f * *diff_sm;*/ - *diff_sm = L_add(Mult_32_16(diff,6554),Mult_32_16(*diff_sm,26214)); + *diff_sm = L_add( Mult_32_16( diff, 6554 ), Mult_32_16( *diff_sm, 26214 ) ); move32(); /**energy_sm = 0.2f * sum_energy + 0.8f * *energy_sm;*/ - *energy_sm = L_add(Mult_32_16(sum_energy,6554),Mult_32_16(*energy_sm,26214)); + *energy_sm = L_add( Mult_32_16( sum_energy, 6554 ), Mult_32_16( *energy_sm, 26214 ) ); move32(); /*diff /= sum_energy;*/ - IF(sum_energy) + IF( sum_energy ) { - exp = norm_l(sum_energy); - tmp = extract_h(L_shl(sum_energy,exp)); - exp = sub(sub(30,exp),7); - IF(tmp < 0) + exp = norm_l( sum_energy ); + tmp = extract_h( L_shl( sum_energy, exp ) ); + exp = sub( sub( 30, exp ), 7 ); + IF( tmp < 0 ) { - tmp = abs_s(tmp); - tmp = div_s(16384,tmp); /*Q(15+exp)*/ + tmp = abs_s( tmp ); + tmp = div_s( 16384, tmp ); /*Q(15+exp)*/ BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB - diff = L_negate( L_shr_o(Mult_32_16(diff,tmp),sub(exp+7 ,31) , &Overflow)); -#else /* BASOP_NOGLOB */ - diff = L_negate( L_shr(Mult_32_16(diff,tmp),sub(exp+7 ,31) )); + diff = L_negate( L_shr_o( Mult_32_16( diff, tmp ), sub( exp + 7, 31 ), &Overflow ) ); +#else /* BASOP_NOGLOB */ + diff = L_negate( L_shr( Mult_32_16( diff, tmp ), sub( exp + 7, 31 ) ) ); #endif /* BASOP_NOGLOB */ BASOP_SATURATE_WARNING_ON_EVS #ifdef BASOP_NOGLOB - diff16 = round_fx_o(diff, &Overflow); -#else /* BASOP_NOGLOB */ - diff16 = round_fx(diff); + diff16 = round_fx_o( diff, &Overflow ); +#else /* BASOP_NOGLOB */ + diff16 = round_fx( diff ); #endif /* BASOP_NOGLOB */ } ELSE { - tmp = div_s(16384,tmp); /*Q(15+exp)*/ + tmp = div_s( 16384, tmp ); /*Q(15+exp)*/ BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB - diff = L_shr_o(Mult_32_16(diff,tmp),sub(exp+7 ,31), &Overflow); -#else /* BASOP_NOGLOB */ - diff = L_shr(Mult_32_16(diff,tmp),sub(exp+7 ,31)); + diff = L_shr_o( Mult_32_16( diff, tmp ), sub( exp + 7, 31 ), &Overflow ); +#else /* BASOP_NOGLOB */ + diff = L_shr( Mult_32_16( diff, tmp ), sub( exp + 7, 31 ) ); #endif /* BASOP_NOGLOB */ BASOP_SATURATE_WARNING_ON_EVS #ifdef BASOP_NOGLOB - diff16 = round_fx_o(diff, &Overflow); -#else /* BASOP_NOGLOB */ - diff16 = round_fx(diff); + diff16 = round_fx_o( diff, &Overflow ); +#else /* BASOP_NOGLOB */ + diff16 = round_fx( diff ); #endif /* BASOP_NOGLOB */ } } ELSE { #ifdef BASOP_NOGLOB - diff16 = round_fx_o(L_shl_o(diff , 25, &Overflow), &Overflow); + diff16 = round_fx_o( L_shl_o( diff, 25, &Overflow ), &Overflow ); #else - diff16 = round_fx(L_shl(diff , 25)); + diff16 = round_fx( L_shl( diff, 25 ) ); #endif } test(); test(); - IF( LT_32(*diff_sm , -1280)&<_32(*energy_sm,4928)&<_16(diff16,-26214)) + IF( LT_32( *diff_sm, -1280 ) && LT_32( *energy_sm, 4928 ) && LT_16( diff16, -26214 ) ) { *predecision_flag = 1; move16(); } test(); test(); - if( GT_32(*diff_sm ,1280)&>_32(*energy_sm,10624)&>_16(diff16,16384)) + if ( GT_32( *diff_sm, 1280 ) && GT_32( *energy_sm, 10624 ) && GT_16( diff16, 16384 ) ) { *predecision_flag = 0; move16(); } /* short pitch possiblity pre-decision */ - maximum_fx(EspecdB, 7, &energy0_16); - maximum_fx(EspecdB+8, 7, &energy1_16); - ratio = s_max(sub(energy1_16,energy0_16),0); /*Q7 */ + maximum_fx( EspecdB, 7, &energy0_16 ); + maximum_fx( EspecdB + 8, 7, &energy1_16 ); + ratio = s_max( sub( energy1_16, energy0_16 ), 0 ); /*Q7 */ /*ratio *= max(voicing,0);*/ - tmp = s_max(voicing_m,0); - ratio = mult_r(ratio,tmp);/*Q7*/ + tmp = s_max( voicing_m, 0 ); + ratio = mult_r( ratio, tmp ); /*Q7*/ /**LF_EnergyRatio_sm = (15*(*LF_EnergyRatio_sm) + ratio)/16;*/ - L_tmp = L_mult(ratio,2048); - L_tmp = L_mac(L_tmp, *LF_EnergyRatio_sm,30720); - *LF_EnergyRatio_sm = round_fx(L_tmp); + L_tmp = L_mult( ratio, 2048 ); + L_tmp = L_mac( L_tmp, *LF_EnergyRatio_sm, 30720 ); + *LF_EnergyRatio_sm = round_fx( L_tmp ); test(); - if( GT_16(*LF_EnergyRatio_sm , 4480)||GT_16(ratio,6400)) + if ( GT_16( *LF_EnergyRatio_sm, 4480 ) || GT_16( ratio, 6400 ) ) { - *predecision_flag=1; + *predecision_flag = 1; move16(); } - if( LT_16(*LF_EnergyRatio_sm , 2048)) + if ( LT_16( *LF_EnergyRatio_sm, 2048 ) ) { - *predecision_flag=0; + *predecision_flag = 0; move16(); } @@ -388,43 +390,43 @@ void StableHighPitchDetect_fx( move16(); cor_max = 0; move16(); - pt_wsp = wsp + 3*L_SUBFR; + pt_wsp = wsp + 3 * L_SUBFR; pit_min = PIT_MIN_DOUBLEEXTEND; move16(); pit_min_up = PIT_MIN; move16(); - FOR( T=pit_min; T<=pit_min_up; T++ ) + FOR( T = pit_min; T <= pit_min_up; T++ ) { - energy1 = Dot_product( pt_wsp, pt_wsp-T, L_SUBFR ); + energy1 = Dot_product( pt_wsp, pt_wsp - T, L_SUBFR ); test(); - IF( (GT_32(energy1,cor_max))||(EQ_16(T,pit_min))) + IF( ( GT_32( energy1, cor_max ) ) || ( EQ_16( T, pit_min ) ) ) { - cor_max = L_add(energy1, 0); + cor_max = L_add( energy1, 0 ); Tp = T; move16(); } } - energy0 = Dot_product12( pt_wsp, pt_wsp, L_SUBFR , &exp1 ) ; - exp1 = sub(exp1 ,shl(Q_new,1)); - energy1 = Dot_product12( pt_wsp-Tp, pt_wsp-Tp, L_SUBFR ,&exp2) ; - exp2 = sub(exp2 ,shl(Q_new,1)); + energy0 = Dot_product12( pt_wsp, pt_wsp, L_SUBFR, &exp1 ); + exp1 = sub( exp1, shl( Q_new, 1 ) ); + energy1 = Dot_product12( pt_wsp - Tp, pt_wsp - Tp, L_SUBFR, &exp2 ); + exp2 = sub( exp2, shl( Q_new, 1 ) ); /* cor_max *= inv_sqrt( energy0*energy1 );*/ - L_tmp = Mult_32_32(energy0,energy1); - exp = norm_l(L_tmp); - L_tmp1 = L_shl(L_tmp,exp); + L_tmp = Mult_32_32( energy0, energy1 ); + exp = norm_l( L_tmp ); + L_tmp1 = L_shl( L_tmp, exp ); - exp = 31-exp-(31-exp1 -exp2); + exp = 31 - exp - ( 31 - exp1 - exp2 ); move16(); - L_tmp1 = Isqrt_lc(L_tmp1, &exp); /*Q(31-exp)*/ - cor_max = Mult_32_32(cor_max, L_tmp1); - exp = 31 - (shl(Q_new,1)+1) - (31-exp) +31; + L_tmp1 = Isqrt_lc( L_tmp1, &exp ); /*Q(31-exp)*/ + cor_max = Mult_32_32( cor_max, L_tmp1 ); + exp = 31 - ( shl( Q_new, 1 ) + 1 ) - ( 31 - exp ) + 31; #ifdef BASOP_NOGLOB - cor_max16 = round_fx_o(L_shl_o(cor_max, exp, &Overflow), &Overflow); /*Q15*/ -#else /* BASOP_NOGLOB */ - cor_max16 = round_fx(L_shl(cor_max, exp)); /*Q15*/ + cor_max16 = round_fx_o( L_shl_o( cor_max, exp, &Overflow ), &Overflow ); /*Q15*/ +#else /* BASOP_NOGLOB */ + cor_max16 = round_fx( L_shl( cor_max, exp ) ); /*Q15*/ #endif /**voicing0_sm = add(mult_r(24576 ,(*voicing0_sm)) , mult_r(8192 , cor_max16));*/ - *voicing0_sm = round_fx(L_mac(L_mult(24576 ,*voicing0_sm), 8192 , cor_max16)); + *voicing0_sm = round_fx( L_mac( L_mult( 24576, *voicing0_sm ), 8192, cor_max16 ) ); /* final short pitch detection */ test(); @@ -432,8 +434,8 @@ void StableHighPitchDetect_fx( test(); *flag_spitch = 0; move16(); - IF( (EQ_16(localVAD,1))&&(EQ_16(*predecision_flag,1))&& - (GT_16(*voicing0_sm,16384)) && (GT_16(*voicing0_sm, mult_r(*voicing_sm,21299)) )) + IF( ( EQ_16( localVAD, 1 ) ) && ( EQ_16( *predecision_flag, 1 ) ) && + ( GT_16( *voicing0_sm, 16384 ) ) && ( GT_16( *voicing0_sm, mult_r( *voicing_sm, 21299 ) ) ) ) { *flag_spitch = 1; move16(); diff --git a/lib_enc/pitch_ol_fx.c b/lib_enc/pitch_ol_fx.c index 8c7e0dbc8..deb99d727 100644 --- a/lib_enc/pitch_ol_fx.c +++ b/lib_enc/pitch_ol_fx.c @@ -10,54 +10,54 @@ #include "rom_com_fx.h" #include "rom_com.h" #include "rom_enc.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*-----------------------------------------------------------------* * Local Constants *-----------------------------------------------------------------*/ -#define PIT_MIN2 20 /* pit_min for pitch tracking */ -#define PIT_MIN_1 44 /* for second pitch track */ -#define PIT_MIN2_1 24 +#define PIT_MIN2 20 /* pit_min for pitch tracking */ +#define PIT_MIN_1 44 /* for second pitch track */ +#define PIT_MIN2_1 24 -#define THR_relE -2816 /* -11 (Q8) */ +#define THR_relE -2816 /* -11 (Q8) */ -#define THRES0 4792 /* Threshold to favor smaller pitch lags; 1.17 (Q12) */ -#define DELTA0 2 /* multiples' search range initial */ -#define STEP 1 /* multiples' search range increment */ +#define THRES0 4792 /* Threshold to favor smaller pitch lags; 1.17 (Q12) */ +#define DELTA0 2 /* multiples' search range initial */ +#define STEP 1 /* multiples' search range increment */ -#define THRES1 13107 /* Threshold to favor pitch lags coherence for neighbours; 0.4 (Q15) */ -#define DELTA_COH 14 /* Maximum pitch lags difference for neighbours to be considered as coherent */ -#define THRES3 22938 /* Threshold to favor pitch lags coherence with previous frames; 0.7 (Q15) */ +#define THRES1 13107 /* Threshold to favor pitch lags coherence for neighbours; 0.4 (Q15) */ +#define DELTA_COH 14 /* Maximum pitch lags difference for neighbours to be considered as coherent */ +#define THRES3 22938 /* Threshold to favor pitch lags coherence with previous frames; 0.7 (Q15) */ -#define CORR_TH0 13107 /* Noise threshold for past frame correlations; 0.4 (Q15) */ -#define CORR_TH1 16384 /* Noise threshold for past frame correlations; 0.5 (Q15) */ +#define CORR_TH0 13107 /* Noise threshold for past frame correlations; 0.4 (Q15) */ +#define CORR_TH1 16384 /* Noise threshold for past frame correlations; 0.5 (Q15) */ -#define LEN_X ((PIT_MAX/OPL_DECIM)-(PIT_MIN2/OPL_DECIM)+1) /* Correlation buffer length */ -#define COH_FAC 5734 /* Factor for measuring the pitch coherence; 1.4 (Q12) */ +#define LEN_X ( ( PIT_MAX / OPL_DECIM ) - ( PIT_MIN2 / OPL_DECIM ) + 1 ) /* Correlation buffer length */ +#define COH_FAC 5734 /* Factor for measuring the pitch coherence; 1.4 (Q12) */ #define NSUBSECT 7 -#define NSECT 4 -#define NHFR 3 -#define L_FIR_PO 5 -#define L_MEM (L_FIR_PO-2) +#define NSECT 4 +#define NHFR 3 +#define L_FIR_PO 5 +#define L_MEM ( L_FIR_PO - 2 ) /*-----------------------------------------------------------------* * Local function prototypes *-----------------------------------------------------------------*/ -static void LP_Decim2_Copy(const Word16 x[], Word16 y[], Word16 l, Word16 mem[] ); +static void LP_Decim2_Copy( const Word16 x[], Word16 y[], Word16 l, Word16 mem[] ); -static void pitch_neighbour_fx(Word16 sect0, Word16 pitch_tmp[],Word16 pitch[3][2*NSECT],Word16 corr_tmp[],Word16 corr[3][2*NSECT],Word16 thres1[2*NHFR],Word16 ind_tmp[2*NHFR]); +static void pitch_neighbour_fx( Word16 sect0, Word16 pitch_tmp[], Word16 pitch[3][2 * NSECT], Word16 corr_tmp[], Word16 corr[3][2 * NSECT], Word16 thres1[2 * NHFR], Word16 ind_tmp[2 * NHFR] ); -static void find_mult_fx(Word16 *fac,Word16 pitch0,Word16 pitch1,Word16 pit_max0,Word16 *corr,Word16 *old_pitch,Word16 *old_corr,Word16 delta,Word16 step); +static void find_mult_fx( Word16 *fac, Word16 pitch0, Word16 pitch1, Word16 pit_max0, Word16 *corr, Word16 *old_pitch, Word16 *old_corr, Word16 delta, Word16 step ); -static Word16 pitch_coherence_fx(Word16 pitch0,Word16 pitch1,Word16 fac_max,Word16 diff_max); +static Word16 pitch_coherence_fx( Word16 pitch0, Word16 pitch1, Word16 fac_max, Word16 diff_max ); -static Word32 Dot_product12_OL(Word16 *sum1,const Word16 x[],const Word16 y[],const Word16 lg,const Word16 lg2,Word16 *exp,Word16 *exp2); +static Word32 Dot_product12_OL( Word16 *sum1, const Word16 x[], const Word16 y[], const Word16 lg, const Word16 lg2, Word16 *exp, Word16 *exp2 ); -static Word32 Dot_product12_OL_back(Word16 *sum1,const Word16 x[],const Word16 y[],const Word16 lg,const Word16 lg2,Word16 *exp,Word16 *exp2); +static Word32 Dot_product12_OL_back( Word16 *sum1, const Word16 x[], const Word16 y[], const Word16 lg, const Word16 lg2, Word16 *exp, Word16 *exp2 ); /*-----------------------------------------------------------------* @@ -66,10 +66,10 @@ static Word32 Dot_product12_OL_back(Word16 *sum1,const Word16 x[],const Word16 y * Open loop pitch variable initialization *-----------------------------------------------------------------*/ void pitch_ol_init_fx( - Word16 *old_thres, /* o : threshold for reinforcement of past pitch influence */ - Word16 *old_pitch, /* o : pitch of the 2nd half-frame of previous frame */ - Word16 *delta_pit, /* o : pitch evolution extrapolation */ - Word16 *old_corr /* o : correlation */ + Word16 *old_thres, /* o : threshold for reinforcement of past pitch influence */ + Word16 *old_pitch, /* o : pitch of the 2nd half-frame of previous frame */ + Word16 *delta_pit, /* o : pitch evolution extrapolation */ + Word16 *old_corr /* o : correlation */ ) { *old_thres = 0; @@ -78,7 +78,7 @@ void pitch_ol_init_fx( move16(); *delta_pit = 0; move16(); - *old_corr = 0; + *old_corr = 0; move16(); } @@ -142,29 +142,29 @@ void pitch_ol_init_fx( /*==================================================================================*/ void pitch_ol_fx( - Word16 pitch[3], /* o : open loop pitch lag for each half-frame in range [29,231] Q0 */ - Word16 voicing[3], /* o : maximum normalized correlation for each half-frame in [0,1.0[ Q15 */ - Word16 *old_pitch, /* i/o: pitch of the 2nd half-frame of previous frame (i.e. pitch[1]) Q0 */ - Word16 *old_corr, /* i/o: correlation of old_pitch (i.e. voicing[1] or corr_mean) Q15 */ - Word16 corr_shift, /* i : normalized correlation correction Q15 */ - Word16 *old_thres, /* i/o: maximum correlation weighting with respect to past frame pitch Q15 */ - Word16 *delta_pit, /* i/o: old pitch extrapolation correction in range [-14,+14] Q0 */ - Word16 *st_old_wsp2, /* i/o: weighted speech memory qwsp */ - const Word16 *wsp, /* i : weighted speech for current frame and look-ahead qwsp */ - Word16 mem_decim2[3], /* i/o: wsp decimation filter memory qwsp */ - const Word16 relE, /* i : relative frame energy Q8 */ - const Word16 last_class,/* i : frame classification of last frame */ - const Word16 bwidth, /* i : bandwidth */ - const Word16 Opt_SC_VBR /* i : SC-VBR flag */ + Word16 pitch[3], /* o : open loop pitch lag for each half-frame in range [29,231] Q0 */ + Word16 voicing[3], /* o : maximum normalized correlation for each half-frame in [0,1.0[ Q15 */ + Word16 *old_pitch, /* i/o: pitch of the 2nd half-frame of previous frame (i.e. pitch[1]) Q0 */ + Word16 *old_corr, /* i/o: correlation of old_pitch (i.e. voicing[1] or corr_mean) Q15 */ + Word16 corr_shift, /* i : normalized correlation correction Q15 */ + Word16 *old_thres, /* i/o: maximum correlation weighting with respect to past frame pitch Q15 */ + Word16 *delta_pit, /* i/o: old pitch extrapolation correction in range [-14,+14] Q0 */ + Word16 *st_old_wsp2, /* i/o: weighted speech memory qwsp */ + const Word16 *wsp, /* i : weighted speech for current frame and look-ahead qwsp */ + Word16 mem_decim2[3], /* i/o: wsp decimation filter memory qwsp */ + const Word16 relE, /* i : relative frame energy Q8 */ + const Word16 last_class, /* i : frame classification of last frame */ + const Word16 bwidth, /* i : bandwidth */ + const Word16 Opt_SC_VBR /* i : SC-VBR flag */ ) { - Word16 ftmp, old_wsp2[(L_WSP-L_INTERPOL)/OPL_DECIM], *wsp2; + Word16 ftmp, old_wsp2[( L_WSP - L_INTERPOL ) / OPL_DECIM], *wsp2; Word16 tmp_mem[3]; - Word16 scale1[2*DELTA_COH-1]; - Word16 scaled_buf[2*LEN_X + 3*(DELTA_COH-1)]; - Word16 scaled_buf_exp[2*LEN_X + 3*(DELTA_COH-1)], exp_sect[8], exp_sect1[8], exp_sect0; - Word16 cor_buf[2*LEN_X]; + Word16 scale1[2 * DELTA_COH - 1]; + Word16 scaled_buf[2 * LEN_X + 3 * ( DELTA_COH - 1 )]; + Word16 scaled_buf_exp[2 * LEN_X + 3 * ( DELTA_COH - 1 )], exp_sect[8], exp_sect1[8], exp_sect0; + Word16 cor_buf[2 * LEN_X]; Word16 *pt_exp1, *pt_exp2, *pt_exp3, *pt_exp4; Word16 *pt1, *pt2, *pt3, *pt4, *pt5, *pt6; Word16 *pt_cor0, *pt_cor1, *pt_cor2, *pt_cor3, *pt_cor4, *pt_cor5, *pt_cor6; @@ -174,13 +174,13 @@ void pitch_ol_fx( Word16 i, j, k, m, pit_min, pit_min1, sect0, subsect0, add_sect0, sub_sect0, old_tmp, old_tmp1, len_x, len_x1; Word16 len_temp; - Word16 pitchX[NHFR][2*NSECT], pitch_tmp[2*NHFR], ind_tmp[2*NHFR], tmp_buf[NHFR+1]; + Word16 pitchX[NHFR][2 * NSECT], pitch_tmp[2 * NHFR], ind_tmp[2 * NHFR], tmp_buf[NHFR + 1]; Word16 enr0[NSECT], enr0_exp[NSECT], enr0_1[NSECT], enr0_1_exp[NSECT], enr1, enr1_exp, enr2_exp; Word32 enr, enr2, Ltmp; Word16 fac, tmp16, tmp16_2; Word16 qCorX, qScaledX; - Word16 scaledX[NHFR][2*NSECT], corX[NHFR][2*NSECT], cor_tmp[2*NHFR], cor_mean; + Word16 scaledX[NHFR][2 * NSECT], corX[NHFR][2 * NSECT], cor_tmp[2 * NHFR], cor_mean; const Word16 *len, *len1, *sublen, *sublen1, *pit_max, *sec_length, *sec_length1; Word16 pit_min_coding; @@ -193,14 +193,14 @@ void pitch_ol_fx( *--------------------------------------------------------------*/ len = len_12k8; len1 = len1_12k8; - sublen = sublen_12k8; + sublen = sublen_12k8; sublen1 = sublen1_12k8; pit_max = pit_max_12k8; sec_length = sec_length_12k8; sec_length1 = sec_length1_12k8; test(); - if ((LT_16(last_class,VOICED_TRANSITION))&&(NE_16(bwidth,NB))) + if ( ( LT_16( last_class, VOICED_TRANSITION ) ) && ( NE_16( bwidth, NB ) ) ) { /*reset last pitch reinforcement in case of unvoiced or transitions: it avoids some pitch doublings*/ *old_thres = 0; @@ -213,12 +213,12 @@ void pitch_ol_fx( test(); test(); test(); - IF ( ( (NE_16(bwidth,NB))&&(GT_16(*old_pitch,PIT_MIN)))|| - ( (EQ_16(bwidth,NB) ) && ( (GT_16(*old_pitch,PIT_MIN2_1) ) || (LT_16(*old_thres,3277) ) ) ) ) /* 0.1 inQ15*/ + IF( ( ( NE_16( bwidth, NB ) ) && ( GT_16( *old_pitch, PIT_MIN ) ) ) || + ( ( EQ_16( bwidth, NB ) ) && ( ( GT_16( *old_pitch, PIT_MIN2_1 ) ) || ( LT_16( *old_thres, 3277 ) ) ) ) ) /* 0.1 inQ15*/ { - pit_min = PIT_MIN/OPL_DECIM; + pit_min = PIT_MIN / OPL_DECIM; move16(); - pit_min1= PIT_MIN_1/OPL_DECIM; + pit_min1 = PIT_MIN_1 / OPL_DECIM; move16(); subsect0 = 2; move16(); @@ -227,9 +227,9 @@ void pitch_ol_fx( } ELSE { - pit_min = PIT_MIN2/OPL_DECIM; + pit_min = PIT_MIN2 / OPL_DECIM; move16(); - pit_min1= PIT_MIN2_1/OPL_DECIM; + pit_min1 = PIT_MIN2_1 / OPL_DECIM; move16(); subsect0 = 0; move16(); @@ -237,9 +237,9 @@ void pitch_ol_fx( move16(); } - len_x = (PIT_MAX/OPL_DECIM - pit_min + 1); + len_x = ( PIT_MAX / OPL_DECIM - pit_min + 1 ); move16(); - len_x1= (PIT_MAX/OPL_DECIM - pit_min1 + 1); + len_x1 = ( PIT_MAX / OPL_DECIM - pit_min1 + 1 ); move16(); /*--------------------------------------------------------------* @@ -249,13 +249,13 @@ void pitch_ol_fx( * Extend the decimation of wsp to the end of the speech buffer * Update wsp memory *--------------------------------------------------------------*/ - Copy(st_old_wsp2, old_wsp2, (L_WSP_MEM-L_INTERPOL)/OPL_DECIM); - wsp2 = old_wsp2 + ((L_WSP_MEM-L_INTERPOL)/OPL_DECIM); + Copy( st_old_wsp2, old_wsp2, ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ); + wsp2 = old_wsp2 + ( ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ); - LP_Decim2_Copy(wsp, wsp2, L_FRAME, mem_decim2); + LP_Decim2_Copy( wsp, wsp2, L_FRAME, mem_decim2 ); /* Avoid uninitialized memory access */ - set16_fx(wsp2 + L_FRAME/2, 0, sizeof(old_wsp2)/sizeof(Word16)-((L_WSP_MEM-L_INTERPOL)/OPL_DECIM)-L_FRAME/2); + set16_fx( wsp2 + L_FRAME / 2, 0, sizeof( old_wsp2 ) / sizeof( Word16 ) - ( ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ) - L_FRAME / 2 ); tmp_mem[0] = mem_decim2[0]; move16(); tmp_mem[1] = mem_decim2[1]; @@ -263,9 +263,9 @@ void pitch_ol_fx( tmp_mem[2] = mem_decim2[2]; move16(); - LP_Decim2_Copy(&wsp[L_FRAME], &wsp2[shr(L_FRAME,1)], L_LOOK_12k8, tmp_mem); /* shr() used instead of division by OPL_DECIM*/ + LP_Decim2_Copy( &wsp[L_FRAME], &wsp2[shr( L_FRAME, 1 )], L_LOOK_12k8, tmp_mem ); /* shr() used instead of division by OPL_DECIM*/ - Copy(&old_wsp2[shr(L_FRAME,1)], st_old_wsp2, (L_WSP_MEM-L_INTERPOL)/OPL_DECIM); + Copy( &old_wsp2[shr( L_FRAME, 1 )], st_old_wsp2, ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ); /*-----------------------------------------------------------------* * Attenuate the correlation correction factor due to noise. @@ -274,19 +274,19 @@ void pitch_ol_fx( * further ones. *-----------------------------------------------------------------*/ - corr_shift = shr(corr_shift, 1); + corr_shift = shr( corr_shift, 1 ); - set16_fx( scaled_buf, 0, DELTA_COH-1 ); - set16_fx( scaled_buf + (DELTA_COH-1) + len_x, 0, DELTA_COH-1 ); - set16_fx( scaled_buf + 2*(DELTA_COH-1) + len_x + len_x1, 0, DELTA_COH-1 ); - set16_fx( scaled_buf_exp, 0, len_x + len_x1 + 3*(DELTA_COH-1)); + set16_fx( scaled_buf, 0, DELTA_COH - 1 ); + set16_fx( scaled_buf + ( DELTA_COH - 1 ) + len_x, 0, DELTA_COH - 1 ); + set16_fx( scaled_buf + 2 * ( DELTA_COH - 1 ) + len_x + len_x1, 0, DELTA_COH - 1 ); + set16_fx( scaled_buf_exp, 0, len_x + len_x1 + 3 * ( DELTA_COH - 1 ) ); - pt1 = scale1 + DELTA_COH-1; + pt1 = scale1 + DELTA_COH - 1; pt2 = pt1; - tmp16 = mult(negate(*old_thres), MAX_16/DELTA_COH); + tmp16 = mult( negate( *old_thres ), MAX_16 / DELTA_COH ); k = *old_thres; move16(); - FOR (i=0; i < DELTA_COH; i++) + FOR( i = 0; i < DELTA_COH; i++ ) { /* * *pt1 = ( -(*old_thres)/DELTA_COH * i + *old_thres+1.0f ); @@ -295,7 +295,7 @@ void pitch_ol_fx( */ *pt1 = k; move16(); - k = add(k, tmp16); + k = add( k, tmp16 ); *pt2-- = *pt1++; move16(); } @@ -303,80 +303,80 @@ void pitch_ol_fx( /*-----------------------------------------------------------------------------* * Estimate the new pitch by extrapolating the old pitch value for 2 half-frames *-----------------------------------------------------------------------------*/ - old_tmp = add(*old_pitch, *delta_pit); - old_tmp = s_min(old_tmp, PIT_MAX/OPL_DECIM); - old_tmp = s_max(old_tmp, pit_min); - old_tmp1 = add(old_tmp, *delta_pit); - old_tmp1 = s_min(old_tmp1, PIT_MAX/OPL_DECIM); - old_tmp1 = s_max(old_tmp1, pit_min); + old_tmp = add( *old_pitch, *delta_pit ); + old_tmp = s_min( old_tmp, PIT_MAX / OPL_DECIM ); + old_tmp = s_max( old_tmp, pit_min ); + old_tmp1 = add( old_tmp, *delta_pit ); + old_tmp1 = s_min( old_tmp1, PIT_MAX / OPL_DECIM ); + old_tmp1 = s_max( old_tmp1, pit_min ); /*-----------------------------------------------------------------* * Loop for all three half-frames (current frame + look-ahead) *-----------------------------------------------------------------*/ - pt_cor0 = scaled_buf + DELTA_COH-1; + pt_cor0 = scaled_buf + DELTA_COH - 1; pt_cor2 = pt_cor0 - pit_min + old_tmp; - pt_cor4 = pt_cor0 - pit_min1 + old_tmp + (DELTA_COH-1) + len_x; + pt_cor4 = pt_cor0 - pit_min1 + old_tmp + ( DELTA_COH - 1 ) + len_x; - FOR( i=0; i Q12 */ - pt2 = pt1 - pit_min; /* *pt2 -> Q12 */ - pt4 = pt1 - pit_min1; /* *pt4 -> Q12 */ + pt1 = wsp2 + i * 2 * ( L_SUBFR / OPL_DECIM ); /* *pt1 -> Q12 */ + pt2 = pt1 - pit_min; /* *pt2 -> Q12 */ + pt4 = pt1 - pit_min1; /* *pt4 -> Q12 */ - enr = L_deposit_l(1); + enr = L_deposit_l( 1 ); pt_cor1 = pt_cor0; - pt_cor3 = pt_cor0 + (DELTA_COH-1) + len_x; + pt_cor3 = pt_cor0 + ( DELTA_COH - 1 ) + len_x; - pt_exp1 = scaled_buf_exp + DELTA_COH-1; + pt_exp1 = scaled_buf_exp + DELTA_COH - 1; pt_exp2 = pt_exp1; - pt_exp3 = scaled_buf_exp + 2*(DELTA_COH-1) + len_x; + pt_exp3 = scaled_buf_exp + 2 * ( DELTA_COH - 1 ) + len_x; pt_exp4 = pt_exp3; - IF( LT_16(i,NHFR-1)) /* First two half-frames (current frame) */ + IF( LT_16( i, NHFR - 1 ) ) /* First two half-frames (current frame) */ { pt3 = pt1; pt5 = pt1; - FOR( j = sect0; j < NSECT; j++ ) /* loop for each section */ + FOR( j = sect0; j < NSECT; j++ ) /* loop for each section */ { /*-----------------------------------------------------------------* * Find fixed vector energy *-----------------------------------------------------------------*/ /* 1st set */ - k = (Word16)(pt1 - pt3); + k = (Word16) ( pt1 - pt3 ); move16(); - FOR (k = add(k, len[j]); k > 0; k--) + FOR( k = add( k, len[j] ); k > 0; k-- ) { - enr = L_mac0(enr, *pt3, *pt3); + enr = L_mac0( enr, *pt3, *pt3 ); pt3++; } /* keep Q15 normalized result */ - cnt = norm_l(enr); - enr0[j] = extract_h(L_shl(enr, cnt)); - enr0_exp[j] = sub(30, cnt); + cnt = norm_l( enr ); + enr0[j] = extract_h( L_shl( enr, cnt ) ); + enr0_exp[j] = sub( 30, cnt ); move16(); /* Reduce complexity (length of 'enr2' section is equal or larger than 'enr') */ pt5 = pt3; enr2 = enr; /* sets to 'enr' in 1 clock */ - move32(); + move32(); /* 2nd set */ - k = (Word16)(pt1 - pt5); + k = (Word16) ( pt1 - pt5 ); move16(); - FOR (k = add(k, len1[j]); k > 0; k--) + FOR( k = add( k, len1[j] ); k > 0; k-- ) { - enr2 = L_mac0(enr2, *pt5, *pt5); + enr2 = L_mac0( enr2, *pt5, *pt5 ); pt5++; } - cnt = norm_l(enr2); - enr0_1[j] = extract_h(L_shl(enr2, cnt)); - enr0_1_exp[j] = sub(30, cnt); + cnt = norm_l( enr2 ); + enr0_1[j] = extract_h( L_shl( enr2, cnt ) ); + enr0_1_exp[j] = sub( 30, cnt ); move16(); } @@ -391,22 +391,22 @@ void pitch_ol_fx( tmp16 = exp_sect[subsect0]; move16(); - k = (Word16)(pt2 - pt1 + pit_max[subsect0]); + k = (Word16) ( pt2 - pt1 + pit_max[subsect0] ); - IF (k >= 0) + IF( k >= 0 ) { len_temp = sublen[0]; move16(); - FOR (; k >= 0; k--) + FOR( ; k >= 0; k-- ) { /* Keep Q15 normalized result */ /* shr by 1 to make room for scaling in the neighbourhood of the extrapolated pitch */ /* Update exponent to reflect shr by 1 */ - *pt_cor1 = extract_h(L_shr(Dot_product12(pt1, pt2--, len_temp, pt_exp1), 1)); + *pt_cor1 = extract_h( L_shr( Dot_product12( pt1, pt2--, len_temp, pt_exp1 ), 1 ) ); /* save the biggest exponent */ - tmp16 = s_max(tmp16, *pt_exp1); + tmp16 = s_max( tmp16, *pt_exp1 ); pt_cor1++; pt_exp1++; @@ -418,56 +418,56 @@ void pitch_ol_fx( /*----------------------------------------------------------* * For each subsection, find the correlation *----------------------------------------------------------*/ - FOR (j = subsect0; j < NSUBSECT; j++) + FOR( j = subsect0; j < NSUBSECT; j++ ) { - len_temp = sublen[j]; + len_temp = sublen[j]; move16(); - k = (Word16)(pt2 - pt1); + k = (Word16) ( pt2 - pt1 ); move16(); - k = add(k,pit_max[j+1]); - exp_sect[j+1] = 0; + k = add( k, pit_max[j + 1] ); + exp_sect[j + 1] = 0; move16(); - exp_sect1[j] = 0; + exp_sect1[j] = 0; move16(); - IF (k >= 0) + IF( k >= 0 ) { - ind = exp_sect[j+1]; + ind = exp_sect[j + 1]; move16(); ind1 = exp_sect1[j]; move16(); - FOR (; k >= 0; k--) + FOR( ; k >= 0; k-- ) { /* Keep Q15 normalized result */ /* shr by 1 to make room for scaling in the neighbourhood of the extrapolated pitch */ /* Update exponent to reflect shr by 1 (done in Dot_product12_OL() for pt_cor3/pt_exp3) */ - *pt_cor1 = extract_h(L_shr(Dot_product12_OL(pt_cor3, pt1, pt2--, sublen[j], sublen1[j], pt_exp1, pt_exp3), 1)); + *pt_cor1 = extract_h( L_shr( Dot_product12_OL( pt_cor3, pt1, pt2--, sublen[j], sublen1[j], pt_exp1, pt_exp3 ), 1 ) ); /* The line above replaces: * *pt_cor1 = shr(extract_h(Dot_product12(pt1, pt2, Sublen[j], pt_exp1)),1); move16(); * *pt_cor3 = shr(extract_h(Dot_product12(pt1, pt2--, Sublen1[j+i*7], pt_exp3)),1); move16(); */ /* save the biggest exponent */ - ind = s_max(ind, *pt_exp1); - ind1 = s_max(ind1, *pt_exp3); + ind = s_max( ind, *pt_exp1 ); + ind1 = s_max( ind1, *pt_exp3 ); pt_cor1++; pt_exp1++; pt_cor3++; pt_exp3++; } - exp_sect[j+1] = ind; + exp_sect[j + 1] = ind; move16(); - exp_sect1[j] = ind1; + exp_sect1[j] = ind1; move16(); - } /* IF (k >= 0) */ - } /* FOR (j = subsect0; ... */ + } /* IF (k >= 0) */ + } /* FOR (j = subsect0; ... */ } - ELSE /* 3rd half-frame (look-ahead) */ + ELSE /* 3rd half-frame (look-ahead) */ { - pt6 = pt1 + L_LOOK_12k8/OPL_DECIM - 1; + pt6 = pt1 + L_LOOK_12k8 / OPL_DECIM - 1; pt3 = pt6; pt5 = pt6; @@ -475,21 +475,21 @@ void pitch_ol_fx( * For each section in both sets, find fixed vector energy *-----------------------------------------------------------------*/ - FOR( j = sect0; j < NSECT; j++ ) /* loop for each section */ + FOR( j = sect0; j < NSECT; j++ ) /* loop for each section */ { /* 1st set */ - k = (Word16)(pt3 - pt6); + k = (Word16) ( pt3 - pt6 ); move16(); - FOR (k = add(k, len[j]); k > 0; k--) + FOR( k = add( k, len[j] ); k > 0; k-- ) { - enr = L_mac0(enr, *pt3, *pt3); + enr = L_mac0( enr, *pt3, *pt3 ); pt3--; } - cnt = norm_l(enr); - enr0[j] = extract_h(L_shl(enr, cnt)); /*qwsp+cnt-16*/ - enr0_exp[j] = sub(30, cnt); + cnt = norm_l( enr ); + enr0[j] = extract_h( L_shl( enr, cnt ) ); /*qwsp+cnt-16*/ + enr0_exp[j] = sub( 30, cnt ); move16(); /* Reduce complexity (length of 'enr2' section is equal or larger than 'enr') */ @@ -498,26 +498,26 @@ void pitch_ol_fx( move16(); /* 2nd set */ - k = (Word16)(pt5 - pt6); + k = (Word16) ( pt5 - pt6 ); move16(); - FOR (k = add(k, len1[j]); k > 0; k--) + FOR( k = add( k, len1[j] ); k > 0; k-- ) { - enr2 = L_mac0(enr2, *pt5, *pt5); + enr2 = L_mac0( enr2, *pt5, *pt5 ); pt5--; } - cnt = norm_l(enr2); - enr0_1[j] = extract_h(L_shl(enr2, cnt)); /*qwsp+cnt-16*/ - enr0_1_exp[j] = sub(30, cnt); + cnt = norm_l( enr2 ); + enr0_1[j] = extract_h( L_shl( enr2, cnt ) ); /*qwsp+cnt-16*/ + enr0_1_exp[j] = sub( 30, cnt ); move16(); } /* Set pointers */ IF( sect0 != 0 ) { - pt2 = pt6 - add(pit_max[1],1); - k = sub(pit_max[2],pit_max[1]); + pt2 = pt6 - add( pit_max[1], 1 ); + k = sub( pit_max[2], pit_max[1] ); move16(); } ELSE @@ -538,31 +538,31 @@ void pitch_ol_fx( tmp16 = exp_sect[subsect0]; move16(); - IF (k > 0) + IF( k > 0 ) { len_temp = sublen[0]; move16(); - FOR ( ; k > 0; k-- ) + FOR( ; k > 0; k-- ) { /* Following lines are equivalent of Dot_product12() but with a backward incrementing */ - Ltmp = L_deposit_l(1); + Ltmp = L_deposit_l( 1 ); FOR( m = 0; m < len_temp; m++ ) { - Ltmp = L_mac(Ltmp, pt6[-m], pt2[-m]); + Ltmp = L_mac( Ltmp, pt6[-m], pt2[-m] ); } /* Normalize acc in Q31 */ - tmp16_2 = norm_l(Ltmp); - Ltmp = L_shl(Ltmp, tmp16_2); - *pt_exp1 = sub(30, tmp16_2); - move16(); /* exponent = 0..30 */ + tmp16_2 = norm_l( Ltmp ); + Ltmp = L_shl( Ltmp, tmp16_2 ); + *pt_exp1 = sub( 30, tmp16_2 ); + move16(); /* exponent = 0..30 */ /* Save result */ - *pt_cor1 = extract_h(L_shr(Ltmp,1)); + *pt_cor1 = extract_h( L_shr( Ltmp, 1 ) ); /* Save the biggest exponent */ - tmp16 = s_max(tmp16, *pt_exp1); + tmp16 = s_max( tmp16, *pt_exp1 ); pt_cor1++; pt_exp1++; @@ -578,115 +578,116 @@ void pitch_ol_fx( FOR( j = subsect0; j < NSUBSECT; j++ ) { - exp_sect[j+1] = 0; + exp_sect[j + 1] = 0; move16(); exp_sect1[j] = 0; move16(); - ind = exp_sect[j+1]; + ind = exp_sect[j + 1]; move16(); ind1 = exp_sect1[j]; move16(); - k = sub(pit_max[j+1], pit_max[j]); + k = sub( pit_max[j + 1], pit_max[j] ); FOR( ; k > 0; k-- ) { - *pt_cor1 = extract_h(L_shr(Dot_product12_OL_back(pt_cor3, pt6, pt2--, sublen[j], sublen1[j], pt_exp1, pt_exp3), 1)); + *pt_cor1 = extract_h( L_shr( Dot_product12_OL_back( pt_cor3, pt6, pt2--, sublen[j], sublen1[j], pt_exp1, pt_exp3 ), 1 ) ); /* Save the biggest exponent */ - ind = s_max(ind, *pt_exp1); - ind1 = s_max(ind1, *pt_exp3); + ind = s_max( ind, *pt_exp1 ); + ind1 = s_max( ind1, *pt_exp3 ); pt_cor1++; pt_exp1++; pt_cor3++; pt_exp3++; } - exp_sect[j+1] = ind; + exp_sect[j + 1] = ind; move16(); - exp_sect1[j] = ind1; + exp_sect1[j] = ind1; move16(); } - } /* 3rd half-frame (look-ahead) */ + } /* 3rd half-frame (look-ahead) */ /* Scale all values in each section to the same exponent for upcoming Find_max() */ - offset = 0; + offset = 0; move16(); offset1 = 0; move16(); - exp_sect1[7] = 0; /* padding */ move16(); - FOR (j = sect0; j < NSECT; j++) + exp_sect1[7] = 0; /* padding */ + move16(); + FOR( j = sect0; j < NSECT; j++ ) { - exp_sect0 = s_max(exp_sect[j*2], exp_sect[j*2+1]); + exp_sect0 = s_max( exp_sect[j * 2], exp_sect[j * 2 + 1] ); /* scaling of exp for track 1 */ - offset = add(offset, sec_length[j]); - k = (Word16)(pt_cor0 - pt_cor5); + offset = add( offset, sec_length[j] ); + k = (Word16) ( pt_cor0 - pt_cor5 ); move16(); - FOR (k = add(k, offset); k > 0; k--) + FOR( k = add( k, offset ); k > 0; k-- ) { - cnt = sub(exp_sect0, *pt_exp2); - tmp16 = s_min(15, cnt); - if (cnt > 0) + cnt = sub( exp_sect0, *pt_exp2 ); + tmp16 = s_min( 15, cnt ); + if ( cnt > 0 ) { - tmp16 = shr(*pt_cor5, tmp16); + tmp16 = shr( *pt_cor5, tmp16 ); } - if (cnt > 0) + if ( cnt > 0 ) { *pt_cor5 = tmp16; move16(); } - *pt_exp2 = s_max(*pt_exp2, exp_sect0); + *pt_exp2 = s_max( *pt_exp2, exp_sect0 ); move16(); pt_cor5++; pt_exp2++; } - exp_sect0 = s_max(exp_sect1[j*2], exp_sect1[j*2+1]); + exp_sect0 = s_max( exp_sect1[j * 2], exp_sect1[j * 2 + 1] ); /* scaling of exp for track 2 */ - offset1 = add(offset1, sec_length1[j]); - k = (Word16)(pt_cor0 - pt_cor6 + (DELTA_COH-1)); + offset1 = add( offset1, sec_length1[j] ); + k = (Word16) ( pt_cor0 - pt_cor6 + ( DELTA_COH - 1 ) ); move16(); - k = add(k, len_x); - FOR (k = add(k, offset1); k > 0; k--) + k = add( k, len_x ); + FOR( k = add( k, offset1 ); k > 0; k-- ) { - cnt = sub(exp_sect0, *pt_exp4); - tmp16 = s_min(15, cnt); - if (cnt > 0) + cnt = sub( exp_sect0, *pt_exp4 ); + tmp16 = s_min( 15, cnt ); + if ( cnt > 0 ) { - tmp16 = shr(*pt_cor6, tmp16); + tmp16 = shr( *pt_cor6, tmp16 ); } - if (cnt > 0) + if ( cnt > 0 ) { *pt_cor6 = tmp16; move16(); } - *pt_exp4 = s_max(*pt_exp4, exp_sect0); + *pt_exp4 = s_max( *pt_exp4, exp_sect0 ); move16(); pt_cor6++; pt_exp4++; } - } /* FOR (j = sect0; ... */ + } /* FOR (j = sect0; ... */ Copy( pt_cor0, cor_buf, len_x ); /* Save unscaled correlation vector */ - Copy( pt_cor0+(DELTA_COH-1)+len_x, cor_buf+len_x, len_x1 ) ; + Copy( pt_cor0 + ( DELTA_COH - 1 ) + len_x, cor_buf + len_x, len_x1 ); /*-----------------------------------------------------------------* * Scale correlation function in the neighbourhood of * the extrapolated pitch *-----------------------------------------------------------------*/ - pt_cor1 = pt_cor2 - (DELTA_COH-1); - pt_cor3 = pt_cor4 - (DELTA_COH-1); + pt_cor1 = pt_cor2 - ( DELTA_COH - 1 ); + pt_cor3 = pt_cor4 - ( DELTA_COH - 1 ); pt2 = scale1; - FOR( k=0 ; k < 2*DELTA_COH-1 ; k++ ) + FOR( k = 0; k < 2 * DELTA_COH - 1; k++ ) { /* all Q15 here */ - *pt_cor1 = add(*pt_cor1, mult(*pt_cor1, *pt2)); + *pt_cor1 = add( *pt_cor1, mult( *pt_cor1, *pt2 ) ); move16(); - *pt_cor3 = add(*pt_cor3, mult(*pt_cor3, *pt2++)); + *pt_cor3 = add( *pt_cor3, mult( *pt_cor3, *pt2++ ) ); move16(); pt_cor1++; @@ -695,7 +696,7 @@ void pitch_ol_fx( /* Update for next half-frame & look-ahead */ pt_cor2 = pt_cor0 - pit_min + old_tmp1; - pt_cor4 = pt_cor0 - pit_min1 + old_tmp1 + (DELTA_COH-1) + len_x; + pt_cor4 = pt_cor0 - pit_min1 + old_tmp1 + ( DELTA_COH - 1 ) + len_x; /*-----------------------------------------------------------------* * For each section, find maximum correlation and compute @@ -703,169 +704,169 @@ void pitch_ol_fx( *-----------------------------------------------------------------*/ pt_cor1 = pt_cor0; - pt_exp1 = scaled_buf_exp + DELTA_COH-1; + pt_exp1 = scaled_buf_exp + DELTA_COH - 1; offset = 0; move16(); - pt_cor3 = pt_cor0 + (DELTA_COH-1) + len_x; - pt_exp3 = scaled_buf_exp + 2*(DELTA_COH-1) + len_x; + pt_cor3 = pt_cor0 + ( DELTA_COH - 1 ) + len_x; + pt_exp3 = scaled_buf_exp + 2 * ( DELTA_COH - 1 ) + len_x; offset1 = 0; move16(); - FOR( j=sect0; j < NSECT; j++ ) /* loop for each section */ + FOR( j = sect0; j < NSECT; j++ ) /* loop for each section */ { /* 1st set */ offset_la = 0; move16(); - if( EQ_16(i,2)) + if ( EQ_16( i, 2 ) ) { - offset_la = sub(L_LOOK_12k8/OPL_DECIM,len[j]); + offset_la = sub( L_LOOK_12k8 / OPL_DECIM, len[j] ); } /* 2nd set */ offset_la1 = 0; move16(); - if( EQ_16(i,2)) + if ( EQ_16( i, 2 ) ) { - offset_la1 = sub(L_LOOK_12k8/OPL_DECIM,len1[j]); + offset_la1 = sub( L_LOOK_12k8 / OPL_DECIM, len1[j] ); } /* 1st set of candidates */ - ind = add(maximum_fx( pt_cor1, sec_length[j], &ftmp ), offset); - pitchX[i][j] = add(ind, pit_min); + ind = add( maximum_fx( pt_cor1, sec_length[j], &ftmp ), offset ); + pitchX[i][j] = add( ind, pit_min ); move16(); - pt2 = pt1 - pitchX[i][j] +/*-*/ offset_la; /* selected moving vector */ + pt2 = pt1 - pitchX[i][j] + /*-*/ offset_la; /* selected moving vector */ enr1_exp = 0; move16(); #ifdef BASOP_NOGLOB - enr1 = add_o(extract_h(dotp_fx( pt2, pt2, len[j], &enr1_exp)), 1, &Overflow); + enr1 = add_o( extract_h( dotp_fx( pt2, pt2, len[j], &enr1_exp ) ), 1, &Overflow ); #else - enr1 = add(extract_h(dotp_fx( pt2, pt2, len[j], &enr1_exp)), 1); + enr1 = add( extract_h( dotp_fx( pt2, pt2, len[j], &enr1_exp ) ), 1 ); #endif - enr2 = L_mult(enr0[j], enr1); - enr2_exp = norm_l(enr2); - enr2 = L_shl(enr2, enr2_exp); - enr2_exp = sub(31,add(sub(28,add(enr0_exp[j],enr1_exp)),add(enr2_exp,1))); + enr2 = L_mult( enr0[j], enr1 ); + enr2_exp = norm_l( enr2 ); + enr2 = L_shl( enr2, enr2_exp ); + enr2_exp = sub( 31, add( sub( 28, add( enr0_exp[j], enr1_exp ) ), add( enr2_exp, 1 ) ) ); - enr2 = Isqrt_lc(enr2, &enr2_exp); /* 1/sqrt(energy) */ /*31-enr2_exp*/ - enr1_exp = norm_l(enr2); - enr1 = extract_h(L_shl(enr2, enr1_exp)); /*31-enr2_exp+enr1_exp-16*/ - enr1_exp = sub(enr2_exp, enr1_exp); /*15-enr1_exp*/ + enr2 = Isqrt_lc( enr2, &enr2_exp ); /* 1/sqrt(energy) */ /*31-enr2_exp*/ + enr1_exp = norm_l( enr2 ); + enr1 = extract_h( L_shl( enr2, enr1_exp ) ); /*31-enr2_exp+enr1_exp-16*/ + enr1_exp = sub( enr2_exp, enr1_exp ); /*15-enr1_exp*/ - Ltmp = L_mult0(cor_buf[ind], enr1); - qCorX = add(sub(15,enr1_exp), sub(14,pt_exp1[ind])); + Ltmp = L_mult0( cor_buf[ind], enr1 ); + qCorX = add( sub( 15, enr1_exp ), sub( 14, pt_exp1[ind] ) ); #ifdef BASOP_NOGLOB - corX[i][j] = extract_h(L_shr_o(Ltmp, sub(qCorX,31), &Overflow)); -#else /* BASOP_NOGLOB */ - corX[i][j] = extract_h(L_shr(Ltmp, sub(qCorX,31))); + corX[i][j] = extract_h( L_shr_o( Ltmp, sub( qCorX, 31 ), &Overflow ) ); +#else /* BASOP_NOGLOB */ + corX[i][j] = extract_h( L_shr( Ltmp, sub( qCorX, 31 ) ) ); #endif /* BASOP_NOGLOB */ qCorX = 31; move16(); - Ltmp = L_mult0(pt_cor0[ind], enr1); - qScaledX = add(sub(15,enr1_exp),sub(14,pt_exp1[ind])); - scaledX[i][j] = round_fx(L_shl(Ltmp, sub(16+12,qScaledX))); - qScaledX =12; + Ltmp = L_mult0( pt_cor0[ind], enr1 ); + qScaledX = add( sub( 15, enr1_exp ), sub( 14, pt_exp1[ind] ) ); + scaledX[i][j] = round_fx( L_shl( Ltmp, sub( 16 + 12, qScaledX ) ) ); + qScaledX = 12; move16(); pt_cor1 += sec_length[j]; move16(); - offset = add(offset,sec_length[j]); + offset = add( offset, sec_length[j] ); /* 2nd set of candidates */ - ind1 = add(maximum_fx( pt_cor3, sec_length1[j], &ftmp ), offset1); - pitchX[i][j+NSECT] = add(ind1, pit_min1); + ind1 = add( maximum_fx( pt_cor3, sec_length1[j], &ftmp ), offset1 ); + pitchX[i][j + NSECT] = add( ind1, pit_min1 ); move16(); - pt4 = pt1 - pitchX[i][j+NSECT] +/*-*/ offset_la1; - move16(); /* selected moving vector */ + pt4 = pt1 - pitchX[i][j + NSECT] + /*-*/ offset_la1; + move16(); /* selected moving vector */ enr1_exp = 0; move16(); #ifdef BASOP_NOGLOB - enr1 = add_o(extract_h(dotp_fx( pt4, pt4, len1[j], &enr1_exp)), 1, &Overflow); + enr1 = add_o( extract_h( dotp_fx( pt4, pt4, len1[j], &enr1_exp ) ), 1, &Overflow ); #else - enr1 = add(extract_h(dotp_fx( pt4, pt4, len1[j], &enr1_exp)), 1); + enr1 = add( extract_h( dotp_fx( pt4, pt4, len1[j], &enr1_exp ) ), 1 ); #endif - enr2 = L_mult(enr0_1[j], enr1); - enr2_exp = norm_l(enr2); - enr2 = L_shl(enr2, enr2_exp); + enr2 = L_mult( enr0_1[j], enr1 ); + enr2_exp = norm_l( enr2 ); + enr2 = L_shl( enr2, enr2_exp ); - enr2_exp = sub(31,add(sub(28,add(enr0_1_exp[j],enr1_exp)),add(enr2_exp,1))); - enr2 = Isqrt_lc(enr2, &enr2_exp); /* 1/sqrt(energy) */ /*31-enr2_exp*/ - enr1_exp = norm_l(enr2); - enr1 = extract_h(L_shl(enr2, enr1_exp)); /*31-enr2_exp+enr1_exp-16*/ - enr1_exp = sub(enr2_exp, enr1_exp); /*15-enr1_exp*/ + enr2_exp = sub( 31, add( sub( 28, add( enr0_1_exp[j], enr1_exp ) ), add( enr2_exp, 1 ) ) ); + enr2 = Isqrt_lc( enr2, &enr2_exp ); /* 1/sqrt(energy) */ /*31-enr2_exp*/ + enr1_exp = norm_l( enr2 ); + enr1 = extract_h( L_shl( enr2, enr1_exp ) ); /*31-enr2_exp+enr1_exp-16*/ + enr1_exp = sub( enr2_exp, enr1_exp ); /*15-enr1_exp*/ - Ltmp = L_mult0(cor_buf[ind1+len_x], enr1); + Ltmp = L_mult0( cor_buf[ind1 + len_x], enr1 ); - qCorX = add(sub(15,enr1_exp),sub(14,pt_exp3[ind1])); + qCorX = add( sub( 15, enr1_exp ), sub( 14, pt_exp3[ind1] ) ); #ifdef BASOP_NOGLOB - corX[i][j+NSECT] = extract_h(L_shr_o(Ltmp, qCorX-31, &Overflow)); -#else /* BASOP_NOGLOB */ - corX[i][j+NSECT] = extract_h(L_shr(Ltmp, qCorX-31)); + corX[i][j + NSECT] = extract_h( L_shr_o( Ltmp, qCorX - 31, &Overflow ) ); +#else /* BASOP_NOGLOB */ + corX[i][j + NSECT] = extract_h( L_shr( Ltmp, qCorX - 31 ) ); #endif /* BASOP_NOGLOB */ qCorX = 31; move16(); - Ltmp = L_mult0(pt_cor0[ind1+(DELTA_COH-1)+len_x], enr1); - qScaledX = add(sub(15,enr1_exp),sub(14,pt_exp3[ind1])); - scaledX[i][j+NSECT] = round_fx(L_shl(Ltmp, sub(16+12,qScaledX))); + Ltmp = L_mult0( pt_cor0[ind1 + ( DELTA_COH - 1 ) + len_x], enr1 ); + qScaledX = add( sub( 15, enr1_exp ), sub( 14, pt_exp3[ind1] ) ); + scaledX[i][j + NSECT] = round_fx( L_shl( Ltmp, sub( 16 + 12, qScaledX ) ) ); /*scaledX[i][j+NSECT] = saturate(L_shr(Ltmp, qScaledX-12));*/ - qScaledX =12; + qScaledX = 12; move16(); pt_cor3 += sec_length1[j]; move16(); - offset1 = add(offset1, sec_length1[j]); + offset1 = add( offset1, sec_length1[j] ); } /* FOR j < NSECT */ - } /* FOR i < NHFR */ + } /* FOR i < NHFR */ /*-----------------------------------------------------------------* * Favor a smaller delay if it happens that it has its multiple * in the longer-delay sections (harmonics check) *-----------------------------------------------------------------*/ - FOR( i=0; i < 2; i++ ) /* loop for the 2 half-frames */ + FOR( i = 0; i < 2; i++ ) /* loop for the 2 half-frames */ { fac = THRES0; move16(); - find_mult_fx(&fac, pitchX[i][2], pitchX[i][3], pit_max[7], &scaledX[i][2], old_pitch, old_corr, DELTA0, STEP); /* Multiples in 3rd section */ - find_mult_fx(&fac, pitchX[i][1], pitchX[i][2], pit_max[5], &scaledX[i][1], old_pitch, old_corr, DELTA0, STEP); /* Multiples in 2nd section */ + find_mult_fx( &fac, pitchX[i][2], pitchX[i][3], pit_max[7], &scaledX[i][2], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 3rd section */ + find_mult_fx( &fac, pitchX[i][1], pitchX[i][2], pit_max[5], &scaledX[i][1], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ test(); - IF((sect0==0) && GE_16(shl(pitchX[i][0],1),pit_min_coding)) + IF( ( sect0 == 0 ) && GE_16( shl( pitchX[i][0], 1 ), pit_min_coding ) ) { - find_mult_fx( &fac, pitchX[i][0], pitchX[i][1], pit_max[3], &scaledX[i][0], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ + find_mult_fx( &fac, pitchX[i][0], pitchX[i][1], pit_max[3], &scaledX[i][0], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ } fac = THRES0; move16(); - find_mult_fx(&fac, pitchX[i][NSECT+2], pitchX[i][NSECT+3], pit_max[7], &scaledX[i][NSECT+2], old_pitch, old_corr, DELTA0, STEP); /* Multiples in 3rd section */ - find_mult_fx(&fac, pitchX[i][NSECT+1], pitchX[i][NSECT+2], pit_max[6], &scaledX[i][NSECT+1], old_pitch, old_corr, DELTA0, STEP); /* Multiples in 2nd section */ + find_mult_fx( &fac, pitchX[i][NSECT + 2], pitchX[i][NSECT + 3], pit_max[7], &scaledX[i][NSECT + 2], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 3rd section */ + find_mult_fx( &fac, pitchX[i][NSECT + 1], pitchX[i][NSECT + 2], pit_max[6], &scaledX[i][NSECT + 1], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ test(); - IF((sect0==0) && GE_16(shl(pitchX[i][NSECT+0],1),pit_min_coding)) + IF( ( sect0 == 0 ) && GE_16( shl( pitchX[i][NSECT + 0], 1 ), pit_min_coding ) ) { - find_mult_fx( &fac, pitchX[i][NSECT+0], pitchX[i][NSECT+1], pit_max[4], &scaledX[i][NSECT+0], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ + find_mult_fx( &fac, pitchX[i][NSECT + 0], pitchX[i][NSECT + 1], pit_max[4], &scaledX[i][NSECT + 0], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ } } fac = THRES0; - move16(); /* the look-ahead */ - find_mult_fx(&fac, pitchX[i][2], pitchX[i][3], pit_max[7], &scaledX[i][2], old_pitch, old_corr, 2, 2); /* Multiples in 3rd section */ - find_mult_fx(&fac, pitchX[i][1], pitchX[i][2], pit_max[5], &scaledX[i][1], old_pitch, old_corr, DELTA0, STEP); /* Multiples in 2nd section */ + move16(); /* the look-ahead */ + find_mult_fx( &fac, pitchX[i][2], pitchX[i][3], pit_max[7], &scaledX[i][2], old_pitch, old_corr, 2, 2 ); /* Multiples in 3rd section */ + find_mult_fx( &fac, pitchX[i][1], pitchX[i][2], pit_max[5], &scaledX[i][1], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ test(); - IF((sect0==0) && GE_16(shl(pitchX[i][0],1),pit_min_coding)) + IF( ( sect0 == 0 ) && GE_16( shl( pitchX[i][0], 1 ), pit_min_coding ) ) { - find_mult_fx( &fac, pitchX[i][0], pitchX[i][1], pit_max[3], &scaledX[i][0], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ + find_mult_fx( &fac, pitchX[i][0], pitchX[i][1], pit_max[3], &scaledX[i][0], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ } fac = THRES0; move16(); - find_mult_fx(&fac, pitchX[i][NSECT+2], pitchX[i][NSECT+3], pit_max[7], &scaledX[i][NSECT+2], old_pitch, old_corr, 2, 2); /* Multiples in 3rd section */ - find_mult_fx(&fac, pitchX[i][NSECT+1], pitchX[i][NSECT+2], pit_max[6], &scaledX[i][NSECT+1], old_pitch, old_corr, DELTA0, STEP); /* Multiples in 2nd section */ + find_mult_fx( &fac, pitchX[i][NSECT + 2], pitchX[i][NSECT + 3], pit_max[7], &scaledX[i][NSECT + 2], old_pitch, old_corr, 2, 2 ); /* Multiples in 3rd section */ + find_mult_fx( &fac, pitchX[i][NSECT + 1], pitchX[i][NSECT + 2], pit_max[6], &scaledX[i][NSECT + 1], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ test(); - IF((sect0==0) && GE_16(shl(pitchX[i][NSECT+0],1),pit_min_coding)) + IF( ( sect0 == 0 ) && GE_16( shl( pitchX[i][NSECT + 0], 1 ), pit_min_coding ) ) { - find_mult_fx( &fac, pitchX[i][NSECT+0], pitchX[i][NSECT+1], pit_max[4], &scaledX[i][NSECT+0], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ /* Multiples in 2nd section */ + find_mult_fx( &fac, pitchX[i][NSECT + 0], pitchX[i][NSECT + 1], pit_max[4], &scaledX[i][NSECT + 0], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ /* Multiples in 2nd section */ } /*-----------------------------------------------------------------* @@ -874,44 +875,44 @@ void pitch_ol_fx( * Compute the maximum scaling for the neighbour correlation * reinforcement *-----------------------------------------------------------------*/ - add_sect0 = add(NSECT,sect0); - sub_sect0 = sub(NSECT,sect0); - FOR (i=0; i < NHFR; i++) + add_sect0 = add( NSECT, sect0 ); + sub_sect0 = sub( NSECT, sect0 ); + FOR( i = 0; i < NHFR; i++ ) { /* 1st set of pitch candidates */ - ind = add(maximum_fx(scaledX[i]+sect0, sub_sect0, &ftmp), sect0); + ind = add( maximum_fx( scaledX[i] + sect0, sub_sect0, &ftmp ), sect0 ); ind_tmp[i] = ind; move16(); pitch_tmp[i] = pitchX[i][ind]; move16(); #ifdef BASOP_NOGLOB - cor_tmp[i] = add_o(corX[i][ind], corr_shift, &Overflow); -#else /* BASOP_NOGLOB */ - cor_tmp[i] = add(corX[i][ind], corr_shift); + cor_tmp[i] = add_o( corX[i][ind], corr_shift, &Overflow ); +#else /* BASOP_NOGLOB */ + cor_tmp[i] = add( corX[i][ind], corr_shift ); #endif /* BASOP_NOGLOB */ move16(); /* Higher is the neighbour's correlation, higher is the weighting */ /* operands are Q15, result is Q15 */ - thres1[i] = mult(THRES1, cor_tmp[i]); + thres1[i] = mult( THRES1, cor_tmp[i] ); move16(); /* 2nd set of pitch candidates */ - ind1 = add(maximum_fx(scaledX[i]+add_sect0, sub_sect0, &ftmp), add_sect0); - ind_tmp[i+NHFR] = ind1; + ind1 = add( maximum_fx( scaledX[i] + add_sect0, sub_sect0, &ftmp ), add_sect0 ); + ind_tmp[i + NHFR] = ind1; move16(); - pitch_tmp[i+NHFR] = pitchX[i][ind1]; + pitch_tmp[i + NHFR] = pitchX[i][ind1]; move16(); #ifdef BASOP_NOGLOB - cor_tmp[i+NHFR] = add_o(corX[i][ind1], corr_shift, &Overflow); + cor_tmp[i + NHFR] = add_o( corX[i][ind1], corr_shift, &Overflow ); #else /* BASOP_NOGLOB */ - cor_tmp[i+NHFR] = add(corX[i][ind1], corr_shift); + cor_tmp[i + NHFR] = add( corX[i][ind1], corr_shift ); #endif move16(); /* Higher is the neighbour's correlation, higher is the weighting */ /* operands are Q15, result is Q15 */ - thres1[i+NHFR] = mult(THRES1, cor_tmp[i+NHFR]); + thres1[i + NHFR] = mult( THRES1, cor_tmp[i + NHFR] ); move16(); } /*-----------------------------------------------------------------* @@ -920,22 +921,22 @@ void pitch_ol_fx( * correlations for each half-frame & look-ahead *-----------------------------------------------------------------*/ - pitch_neighbour_fx(sect0, pitch_tmp, pitchX, cor_tmp, scaledX, thres1, ind_tmp); + pitch_neighbour_fx( sect0, pitch_tmp, pitchX, cor_tmp, scaledX, thres1, ind_tmp ); FOR( i = 0; i < NHFR; i++ ) { - ind = add(maximum_fx(scaledX[i]+sect0, sub_sect0, &ftmp), sect0); - ind_corX = add(maximum_fx(corX[i]+sect0, sub_sect0, &ftmp), sect0); + ind = add( maximum_fx( scaledX[i] + sect0, sub_sect0, &ftmp ), sect0 ); + ind_corX = add( maximum_fx( corX[i] + sect0, sub_sect0, &ftmp ), sect0 ); - ind1 = add(maximum_fx(scaledX[i]+add_sect0, sub_sect0, &ftmp), add_sect0); - ind1_corX = add(maximum_fx(corX[i]+add_sect0, sub_sect0, &ftmp), add_sect0); + ind1 = add( maximum_fx( scaledX[i] + add_sect0, sub_sect0, &ftmp ), add_sect0 ); + ind1_corX = add( maximum_fx( corX[i] + add_sect0, sub_sect0, &ftmp ), add_sect0 ); - if ( GT_16(scaledX[i][ind1],scaledX[i][ind])) + if ( GT_16( scaledX[i][ind1], scaledX[i][ind] ) ) { ind = ind1; move16(); } test(); - if ( Opt_SC_VBR && GT_16(corX[i][ind1_corX],corX[i][ind_corX])) + if ( Opt_SC_VBR && GT_16( corX[i][ind1_corX], corX[i][ind_corX] ) ) { ind_corX = ind1_corX; move16(); @@ -943,9 +944,9 @@ void pitch_ol_fx( test(); test(); test(); - IF (Opt_SC_VBR && (LT_16(mult(pitchX[i][ind], 13107 /*0.4 in Q15*/),pitchX[i][ind_corX]))&& - (GT_16(mult(pitchX[i][ind], 19661 /*0.6 in Q15*/),pitchX[i][ind_corX]) ) && - (GE_16(corX[i][ind_corX],29491/*0.9 in Q15*/))) + IF( Opt_SC_VBR && ( LT_16( mult( pitchX[i][ind], 13107 /*0.4 in Q15*/ ), pitchX[i][ind_corX] ) ) && + ( GT_16( mult( pitchX[i][ind], 19661 /*0.6 in Q15*/ ), pitchX[i][ind_corX] ) ) && + ( GE_16( corX[i][ind_corX], 29491 /*0.9 in Q15*/ ) ) ) { pitch[i] = pitchX[i][ind_corX]; move16(); @@ -968,20 +969,20 @@ void pitch_ol_fx( /* all Q15 here */ /* cor_mean = 0.5f * (voicing[0] + voicing[1]) + corr_shift; */ - Ltmp = L_mult(voicing[0], 16384); - Ltmp = L_mac(Ltmp, voicing[1], 16384); - cor_mean = round_fx(L_add(Ltmp, corr_shift)); + Ltmp = L_mult( voicing[0], 16384 ); + Ltmp = L_mac( Ltmp, voicing[1], 16384 ); + cor_mean = round_fx( L_add( Ltmp, corr_shift ) ); /* pitch unstable in present frame or from previous frame or normalized correlation too low */ - coh_flag = pitch_coherence_fx(pitch[0], pitch[1], COH_FAC, DELTA_COH); + coh_flag = pitch_coherence_fx( pitch[0], pitch[1], COH_FAC, DELTA_COH ); move16(); - coh_flag1 = pitch_coherence_fx(pitch[0], *old_pitch, COH_FAC, DELTA_COH); + coh_flag1 = pitch_coherence_fx( pitch[0], *old_pitch, COH_FAC, DELTA_COH ); move16(); test(); test(); test(); - IF ((coh_flag == 0) || (coh_flag1 == 0) || (LT_16(cor_mean, CORR_TH0))||(LT_16(relE,THR_relE))) + IF( ( coh_flag == 0 ) || ( coh_flag1 == 0 ) || ( LT_16( cor_mean, CORR_TH0 ) ) || ( LT_16( relE, THR_relE ) ) ) { /* Reset the threshold */ *old_thres = 0; @@ -991,13 +992,13 @@ void pitch_ol_fx( { /* The threshold increase is directly dependent on normalized correlation */ /* *old_thres += (0.16f * cor_mean); */ - *old_thres = round_fx(L_mac(L_deposit_h(*old_thres), 5243, cor_mean)); + *old_thres = round_fx( L_mac( L_deposit_h( *old_thres ), 5243, cor_mean ) ); } - *old_thres = s_min(*old_thres, THRES3); + *old_thres = s_min( *old_thres, THRES3 ); move16(); - IF (GT_16(voicing[1], voicing[0])) + IF( GT_16( voicing[1], voicing[0] ) ) { *old_corr = voicing[1]; move16(); @@ -1018,7 +1019,7 @@ void pitch_ol_fx( move16(); FOR( i = 0; i < NHFR; i++ ) { - tmp_buf[i+1] = pitch[i]; + tmp_buf[i + 1] = pitch[i]; move16(); } @@ -1027,39 +1028,39 @@ void pitch_ol_fx( cnt = 0; move16(); - FOR ( i = 0; i < NHFR; i++ ) + FOR( i = 0; i < NHFR; i++ ) { - diff = sub(tmp_buf[i+1], tmp_buf[i]); + diff = sub( tmp_buf[i + 1], tmp_buf[i] ); move16(); - coh_flag = pitch_coherence_fx(tmp_buf[i], tmp_buf[i+1], COH_FAC, DELTA_COH); + coh_flag = pitch_coherence_fx( tmp_buf[i], tmp_buf[i + 1], COH_FAC, DELTA_COH ); - if (coh_flag != 0) + if ( coh_flag != 0 ) { - *delta_pit = add(*delta_pit, diff); + *delta_pit = add( *delta_pit, diff ); move16(); } - cnt = add(cnt, coh_flag); + cnt = add( cnt, coh_flag ); } - if (EQ_16(cnt, 2)) + if ( EQ_16( cnt, 2 ) ) { /* *delta_pit /= 2; */ - *delta_pit = shr(*delta_pit, 1); + *delta_pit = shr( *delta_pit, 1 ); move16(); } - IF (EQ_16(cnt, 3)) + IF( EQ_16( cnt, 3 ) ) { k = *delta_pit; move16(); /* *delta_pit /= 3; */ - if (k < 0) + if ( k < 0 ) { - *delta_pit = mult(*delta_pit, -32768); + *delta_pit = mult( *delta_pit, -32768 ); move16(); } - tmp16 = mult(*delta_pit, 10923); - if (k < 0) + tmp16 = mult( *delta_pit, 10923 ); + if ( k < 0 ) { - tmp16 = mult(tmp16, -32768); + tmp16 = mult( tmp16, -32768 ); } *delta_pit = tmp16; move16(); @@ -1072,10 +1073,10 @@ void pitch_ol_fx( *old_pitch = pitch[1]; move16(); - FOR ( i = 0; i < NHFR; i++ ) + FOR( i = 0; i < NHFR; i++ ) { /* compensate decimation */ - pitch[i] = i_mult2(pitch[i], OPL_DECIM); + pitch[i] = i_mult2( pitch[i], OPL_DECIM ); move16(); } @@ -1090,40 +1091,40 @@ void pitch_ol_fx( * in lower sections *-----------------------------------------------------------------*/ static void find_mult_fx( - Word16 *fac, /* i/o: correlation scaling factor Q12 */ - Word16 pitch0, /* i : pitch of max correlation in the c section */ - Word16 pitch1, /* i : pitch of max correlation in the longer-delay section*/ - Word16 pit_max0, /* i : max pitch delay in the longer-delay section */ - Word16 *corr, /* i/o: max correlation in the shorter-delay section Q12 */ - Word16 *old_pitch, /* i : pitch from previous frame */ - Word16 *old_corr, /* i : max correlation from previous frame */ - Word16 delta, /* i : initial multiples search range */ - Word16 step /* i : increment in range of multiples search */ + Word16 *fac, /* i/o: correlation scaling factor Q12 */ + Word16 pitch0, /* i : pitch of max correlation in the c section */ + Word16 pitch1, /* i : pitch of max correlation in the longer-delay section*/ + Word16 pit_max0, /* i : max pitch delay in the longer-delay section */ + Word16 *corr, /* i/o: max correlation in the shorter-delay section Q12 */ + Word16 *old_pitch, /* i : pitch from previous frame */ + Word16 *old_corr, /* i : max correlation from previous frame */ + Word16 delta, /* i : initial multiples search range */ + Word16 step /* i : increment in range of multiples search */ ) { Word16 pit_min; Word32 L_tmp; - pit_min = shl(pitch0, 1); /* double the higher section pitch */ + pit_min = shl( pitch0, 1 ); /* double the higher section pitch */ - WHILE (LE_16(pit_min, add(pit_max0, delta))) /* check for section boundary */ + WHILE( LE_16( pit_min, add( pit_max0, delta ) ) ) /* check for section boundary */ { - IF (LE_16(abs_s(sub(pit_min, pitch1)), delta)) /* if multiple in the allowed range */ + IF( LE_16( abs_s( sub( pit_min, pitch1 ) ), delta ) ) /* if multiple in the allowed range */ { - L_tmp = L_shl(L_mult(*corr, *fac), 3); + L_tmp = L_shl( L_mult( *corr, *fac ), 3 ); /* if ( *old_corr < 0.6f || (float)pitch0 > (float)*old_pitch * 0.4f ) */ - IF (s_max(sub(19660, *old_corr), sub(pitch0, mult(*old_pitch, 13107))) > 0) + IF( s_max( sub( 19660, *old_corr ), sub( pitch0, mult( *old_pitch, 13107 ) ) ) > 0 ) { /* reinforce the normalized correlation */ /* operands are Q12, result is Q12 */ - *corr = extract_h(L_tmp); + *corr = extract_h( L_tmp ); } /* operands are Q12, result is Q12 */ - *fac = extract_h(L_shl(L_mult(*fac, THRES0), 3)); + *fac = extract_h( L_shl( L_mult( *fac, THRES0 ), 3 ) ); } - pit_min = add(pit_min, pitch0); /* next multiple */ - delta = add(delta, step); /* the incertitude to the allowed range */ + pit_min = add( pit_min, pitch0 ); /* next multiple */ + delta = add( delta, step ); /* the incertitude to the allowed range */ } } @@ -1136,11 +1137,11 @@ static void find_mult_fx( static void pitch_neighbour_fx( Word16 sect0, /* i : indicates whether section 0 (below PIT_MIN) is used */ Word16 pitch_tmp[], /* i : estimated pitch values for each half-frame & look-ahead */ - Word16 pitch[3][2*NSECT], /* i : tested pitch values for each half-frame & look-ahead */ + Word16 pitch[3][2 * NSECT], /* i : tested pitch values for each half-frame & look-ahead */ Word16 corr_tmp[], /* i : raw normalized correlation (before different scalings) Q15*/ - Word16 corr[3][2*NSECT], /* i/o: normalized correlation for each half-frame & look-ahead Q12 */ - Word16 thres1[2*NHFR], /* i : maximum scaling for the immediate neighbours Q15 */ - Word16 ind_tmp[2*NHFR] /* i : best section index for each half-frame & look-ahead */ + Word16 corr[3][2 * NSECT], /* i/o: normalized correlation for each half-frame & look-ahead Q12 */ + Word16 thres1[2 * NHFR], /* i : maximum scaling for the immediate neighbours Q15 */ + Word16 ind_tmp[2 * NHFR] /* i : best section index for each half-frame & look-ahead */ ) { Word16 delta, i, j, k, K, coh_flag, fac; @@ -1148,45 +1149,45 @@ static void pitch_neighbour_fx( /*--------------------- * 1st set of sections ---------------------*/ - FOR ( k = sect0; k < NSECT; k++ ) /* loop for each section */ + FOR( k = sect0; k < NSECT; k++ ) /* loop for each section */ { K = 3; move16(); - if (EQ_16(k, (NSECT-1))) /* the number of tests depends on the section */ + if ( EQ_16( k, ( NSECT - 1 ) ) ) /* the number of tests depends on the section */ { K = 2; move16(); } /*pt = &pitch[i][k] and pt = &corr[i][k]*/ - FOR (i=0; i < K; i++) /* for the 2 half-frames and look-ahead */ + FOR( i = 0; i < K; i++ ) /* for the 2 half-frames and look-ahead */ { /* Compare pitch values of the present frame */ - FOR (j=0; j < K; j++) /* Verify pitch coherence with neighbours (including past pitch) */ + FOR( j = 0; j < K; j++ ) /* Verify pitch coherence with neighbours (including past pitch) */ { - IF (NE_16(j, i)) /* Exclude itself, of course */ + IF( NE_16( j, i ) ) /* Exclude itself, of course */ { - IF (GE_16(corr_tmp[j], CORR_TH1)) /* reinforcement can happen only if the correlation is high enough */ + IF( GE_16( corr_tmp[j], CORR_TH1 ) ) /* reinforcement can happen only if the correlation is high enough */ { - delta = abs_s(sub(pitch[i][k], pitch_tmp[j])); /* Find difference of pitch values */ - coh_flag = pitch_coherence_fx(pitch[i][k], pitch_tmp[j], COH_FAC, DELTA_COH); + delta = abs_s( sub( pitch[i][k], pitch_tmp[j] ) ); /* Find difference of pitch values */ + coh_flag = pitch_coherence_fx( pitch[i][k], pitch_tmp[j], COH_FAC, DELTA_COH ); - IF (coh_flag != 0) + IF( coh_flag != 0 ) { /* Favour stability across sections, favour closer values */ - IF (EQ_16(ind_tmp[j], k)) + IF( EQ_16( ind_tmp[j], k ) ) { /* corr[i][k] *= ( -thres1[j]/DELTA1 * delta + thres1[j]+1 ); */ /* operands are Q15, except corr[i][k] which is Q12 */ - fac = mult(negate(thres1[j]), MAX_16/DELTA_COH); - fac = add(i_mult2(fac, delta), thres1[j]); + fac = mult( negate( thres1[j] ), MAX_16 / DELTA_COH ); + fac = add( i_mult2( fac, delta ), thres1[j] ); } ELSE { /* corr[i][k] *= ( -thres1[j]/DELTA1 * 0.625f * delta + 0.625f * thres1[j] +1.0f ); */ - fac = mult(negate(thres1[j]), 20479/DELTA_COH); - fac = add(i_mult2(fac,delta), mult(20479, thres1[j])); + fac = mult( negate( thres1[j] ), 20479 / DELTA_COH ); + fac = add( i_mult2( fac, delta ), mult( 20479, thres1[j] ) ); } - corr[i][k] = add(corr[i][k], mult(fac, corr[i][k])); + corr[i][k] = add( corr[i][k], mult( fac, corr[i][k] ) ); move16(); } } @@ -1198,46 +1199,46 @@ static void pitch_neighbour_fx( /*--------------------- * 2nd set of sections ---------------------*/ - FOR ( k = sect0; k < NSECT; k++ ) /* loop for each section */ + FOR( k = sect0; k < NSECT; k++ ) /* loop for each section */ { K = 3; move16(); - if (EQ_16(k, (NSECT-1))) /* the number of tests depends on the section */ + if ( EQ_16( k, ( NSECT - 1 ) ) ) /* the number of tests depends on the section */ { K = 2; move16(); } /*pt = &pitch[i][k] and pt = &corr[i][k]*/ - FOR (i=0; i < K; i++)/* BRANCH(1); for the 2 half-frames and look-ahead */ + FOR( i = 0; i < K; i++ ) /* BRANCH(1); for the 2 half-frames and look-ahead */ { /* Compare pitch values of the present frame */ - FOR (j=0; j < K; j++)/* Verify pitch coherence with neighbours (including past pitch) */ + FOR( j = 0; j < K; j++ ) /* Verify pitch coherence with neighbours (including past pitch) */ { - IF (NE_16(j, i))/* Exclude itself, of course */ + IF( NE_16( j, i ) ) /* Exclude itself, of course */ { - IF (GE_16(corr_tmp[j+NHFR], CORR_TH1))/* reinforcement can happen only if the correlation is high enough */ + IF( GE_16( corr_tmp[j + NHFR], CORR_TH1 ) ) /* reinforcement can happen only if the correlation is high enough */ { - delta = abs_s(sub(pitch[i][NSECT+k], pitch_tmp[j+NHFR])); /* Find difference of pitch values */ - coh_flag = pitch_coherence_fx(pitch[i][NSECT+k], pitch_tmp[j+NHFR], COH_FAC, DELTA_COH); + delta = abs_s( sub( pitch[i][NSECT + k], pitch_tmp[j + NHFR] ) ); /* Find difference of pitch values */ + coh_flag = pitch_coherence_fx( pitch[i][NSECT + k], pitch_tmp[j + NHFR], COH_FAC, DELTA_COH ); - IF (coh_flag != 0) + IF( coh_flag != 0 ) { /* Favour stability across sections, favour closer values */ - IF (EQ_16(ind_tmp[j+NHFR], add(NSECT, k))) + IF( EQ_16( ind_tmp[j + NHFR], add( NSECT, k ) ) ) { /* corr[i][k] *= ( -thres1[j+NHFR]/DELTA1 * delta + thres1[j+NHFR]+1 ); */ /* operands are Q15, except corr[i][NSECT+k] which is Q12 */ - fac = mult(negate(thres1[j+NHFR]), MAX_16/DELTA_COH); - fac = add(extract_l(L_shr(L_mult(fac, delta), 1)), thres1[j+NHFR]); - corr[i][NSECT+k] = add(corr[i][NSECT+k], mult(fac, corr[i][NSECT+k])); + fac = mult( negate( thres1[j + NHFR] ), MAX_16 / DELTA_COH ); + fac = add( extract_l( L_shr( L_mult( fac, delta ), 1 ) ), thres1[j + NHFR] ); + corr[i][NSECT + k] = add( corr[i][NSECT + k], mult( fac, corr[i][NSECT + k] ) ); move16(); } ELSE { /* corr[i][k] *= ( -thres1[j+NHFR]/DELTA1 * 0.625f * delta + 0.625f * thres1[j+NHFR] +1.0f ); */ - fac = mult(negate(thres1[j+NHFR]), 20479/DELTA_COH); - fac = add(extract_l(L_shr(L_mult(fac,delta), 1)), mult(20479, thres1[j+NHFR])); - corr[i][NSECT+k] = add(corr[i][NSECT+k], mult(fac, corr[i][NSECT+k])); + fac = mult( negate( thres1[j + NHFR] ), 20479 / DELTA_COH ); + fac = add( extract_l( L_shr( L_mult( fac, delta ), 1 ) ), mult( 20479, thres1[j + NHFR] ) ); + corr[i][NSECT + k] = add( corr[i][NSECT + k], mult( fac, corr[i][NSECT + k] ) ); move16(); } } @@ -1254,23 +1255,23 @@ static void pitch_neighbour_fx( * Verify if pitch evolution is smooth *-----------------------------------------------------------------*/ static Word16 pitch_coherence_fx( - Word16 pitch0, /* i : first pitch to compare */ - Word16 pitch1, /* i : 2nd pitch to compare */ - Word16 fac_max, /* i : max ratio of both values Q12 */ - Word16 diff_max /* i : max difference of both values */ + Word16 pitch0, /* i : first pitch to compare */ + Word16 pitch1, /* i : 2nd pitch to compare */ + Word16 fac_max, /* i : max ratio of both values Q12 */ + Word16 diff_max /* i : max difference of both values */ ) { Word16 smaller, larger; Word16 pc; - smaller = s_min(pitch0, pitch1); - larger = s_max(pitch0, pitch1); + smaller = s_min( pitch0, pitch1 ); + larger = s_max( pitch0, pitch1 ); pc = 0; move16(); test(); - if( (LE_16(larger, extract_h(L_shl(L_mult(fac_max, smaller), 3))))&& /* Changed to <= to keep BE */ - (LT_16(sub(larger, smaller), diff_max))) + if ( ( LE_16( larger, extract_h( L_shl( L_mult( fac_max, smaller ), 3 ) ) ) ) && /* Changed to <= to keep BE */ + ( LT_16( sub( larger, smaller ), diff_max ) ) ) { pc = 1; move16(); @@ -1285,10 +1286,10 @@ static Word16 pitch_coherence_fx( * Decimate a vector by 2 with 2nd order fir filter. *-----------------------------------------------------------------*/ static void LP_Decim2_Copy( - const Word16 x[], /* i: signal to process */ - Word16 y[], /* o: signal to process */ - Word16 l, /* i : size of filtering */ - Word16 mem[] /* i/o: memory (size=3) */ + const Word16 x[], /* i: signal to process */ + Word16 y[], /* o: signal to process */ + Word16 l, /* i : size of filtering */ + Word16 mem[] /* i/o: memory (size=3) */ ) { Word16 *p_x, x_buf[L_FRAME + L_MEM]; @@ -1297,23 +1298,23 @@ static void LP_Decim2_Copy( /* copy initial filter states into buffer */ p_x = x_buf; - FOR (i = 0; i < L_MEM; i++) + FOR( i = 0; i < L_MEM; i++ ) { *p_x++ = mem[i]; move16(); } - FOR (i = 0; i < l; i++) + FOR( i = 0; i < l; i++ ) { *p_x++ = x[i]; move16(); } - if (l & 1) /* Fix for valgrind error in case l is odd. Anyway this function will be removed. */ + if ( l & 1 ) /* Fix for valgrind error in case l is odd. Anyway this function will be removed. */ { - *p_x = *(p_x-1); + *p_x = *( p_x - 1 ); move16(); } - FOR (i = 0; i < L_MEM; i++) + FOR( i = 0; i < L_MEM; i++ ) { mem[i] = x[l - L_MEM + i]; move16(); @@ -1321,16 +1322,16 @@ static void LP_Decim2_Copy( p_x = x_buf; j = 0; move16(); - FOR (i = 0; i < l; i += 2) + FOR( i = 0; i < l; i += 2 ) { - L_tmp = L_mult(*p_x, H_fir[0]); - FOR (k = 1; k < L_FIR_PO; k++) + L_tmp = L_mult( *p_x, H_fir[0] ); + FOR( k = 1; k < L_FIR_PO; k++ ) { - L_tmp = L_mac(L_tmp, p_x[k], H_fir[k]); + L_tmp = L_mac( L_tmp, p_x[k], H_fir[k] ); } - p_x+=2; + p_x += 2; - y[j++] = round_fx(L_tmp); + y[j++] = round_fx( L_tmp ); } } /*---------------------------------------------------------------------* @@ -1338,59 +1339,61 @@ static void LP_Decim2_Copy( * * two different length dot products of x and y *---------------------------------------------------------------------*/ -static Word32 Dot_product12_OL( /* o : Q31: normalized result (1 < val <= -1) */ - Word16 *sum1, /* o : Q31: normalized result 2 */ - const Word16 x[], /* i : 12bits: x vector */ - const Word16 y[], /* i : 12bits: y vector */ - const Word16 lg, /* i : vector length */ - const Word16 lg2, /* i : vector length 2 */ - Word16 *exp, /* o : exponent of result (0..+30) */ - Word16 *exp2 /* o : exponent of result 2 (0..+30) */ +static Word32 Dot_product12_OL( /* o : Q31: normalized result (1 < val <= -1) */ + Word16 *sum1, /* o : Q31: normalized result 2 */ + const Word16 x[], /* i : 12bits: x vector */ + const Word16 y[], /* i : 12bits: y vector */ + const Word16 lg, /* i : vector length */ + const Word16 lg2, /* i : vector length 2 */ + Word16 *exp, /* o : exponent of result (0..+30) */ + Word16 *exp2 /* o : exponent of result 2 (0..+30) */ ) { Word16 i, sft; Word32 L_sum, L_sum2; - L_sum = L_mac(1, x[0], y[0]); - IF (LE_16(lg, lg2)) + L_sum = L_mac( 1, x[0], y[0] ); + IF( LE_16( lg, lg2 ) ) { - FOR (i = 1; i < lg; i++) + FOR( i = 1; i < lg; i++ ) { - L_sum = L_mac(L_sum, x[i], y[i]); + L_sum = L_mac( L_sum, x[i], y[i] ); } /* sets to 'L_sum' in 1 clock */ - L_sum2 = L_sum; move32(); - FOR (; i < lg2; i++) + L_sum2 = L_sum; + move32(); + FOR( ; i < lg2; i++ ) { - L_sum2 = L_mac(L_sum2, x[i], y[i]); + L_sum2 = L_mac( L_sum2, x[i], y[i] ); } } ELSE { - FOR (i = 1; i < lg2; i++) + FOR( i = 1; i < lg2; i++ ) { - L_sum = L_mac(L_sum, x[i], y[i]); + L_sum = L_mac( L_sum, x[i], y[i] ); } /* sets to 'L_sum' in 1 clock */ - L_sum2 = L_sum; move32(); - FOR (; i < lg; i++) + L_sum2 = L_sum; + move32(); + FOR( ; i < lg; i++ ) { - L_sum = L_mac(L_sum, x[i], y[i]); + L_sum = L_mac( L_sum, x[i], y[i] ); } } /* Q31 */ - sft = norm_l(L_sum); - L_sum = L_shl(L_sum, sft); - *exp = sub(30, sft); + sft = norm_l( L_sum ); + L_sum = L_shl( L_sum, sft ); + *exp = sub( 30, sft ); move16(); /* exponent = 0..30 */ - sft = norm_l(L_sum2); - L_sum2 = L_shl(L_sum2, sft); - *exp2 = sub(30, sft); + sft = norm_l( L_sum2 ); + L_sum2 = L_shl( L_sum2, sft ); + *exp2 = sub( 30, sft ); move16(); /* exponent = 0..30 */ - *sum1 = extract_h(L_shr(L_sum2, 1)); + *sum1 = extract_h( L_shr( L_sum2, 1 ) ); return L_sum; } @@ -1400,59 +1403,61 @@ static Word32 Dot_product12_OL( /* o : Q31: normalized result (1 < val <= -1) * * * two different length dot products of x and y, computed backward *---------------------------------------------------------------------*/ -static Word32 Dot_product12_OL_back(/* o : Q31: normalized result (1 < val <= -1) */ - Word16 *sum1, /* o : Q31: normalized result 2 */ - const Word16 x[], /* i : 12bits: x vector */ - const Word16 y[], /* i : 12bits: y vector */ - const Word16 lg, /* i : vector length */ - const Word16 lg2, /* i : vector length 2 */ - Word16 *exp, /* o : exponent of result (0..+30) */ - Word16 *exp2 /* o : exponent of result 2 (0..+30) */ +static Word32 Dot_product12_OL_back( /* o : Q31: normalized result (1 < val <= -1) */ + Word16 *sum1, /* o : Q31: normalized result 2 */ + const Word16 x[], /* i : 12bits: x vector */ + const Word16 y[], /* i : 12bits: y vector */ + const Word16 lg, /* i : vector length */ + const Word16 lg2, /* i : vector length 2 */ + Word16 *exp, /* o : exponent of result (0..+30) */ + Word16 *exp2 /* o : exponent of result 2 (0..+30) */ ) { Word16 i, sft; Word32 L_sum, L_sum2; - L_sum = L_mac(1, x[0], y[0]); - IF (LE_16(lg, lg2)) + L_sum = L_mac( 1, x[0], y[0] ); + IF( LE_16( lg, lg2 ) ) { - FOR (i = 1; i < lg; i++) + FOR( i = 1; i < lg; i++ ) { - L_sum = L_mac(L_sum, x[-i], y[-i]); + L_sum = L_mac( L_sum, x[-i], y[-i] ); } /* sets to 'L_sum' in 1 clock */ - L_sum2 = L_sum; move32(); - FOR (; i < lg2; i++) + L_sum2 = L_sum; + move32(); + FOR( ; i < lg2; i++ ) { - L_sum2 = L_mac(L_sum2, x[-i], y[-i]); + L_sum2 = L_mac( L_sum2, x[-i], y[-i] ); } } ELSE { - FOR (i = 1; i < lg2; i++) + FOR( i = 1; i < lg2; i++ ) { - L_sum = L_mac(L_sum, x[-i], y[-i]); + L_sum = L_mac( L_sum, x[-i], y[-i] ); } /* sets to 'L_sum' in 1 clock */ - L_sum2 = L_sum; move32(); - FOR (; i < lg; i++) + L_sum2 = L_sum; + move32(); + FOR( ; i < lg; i++ ) { - L_sum = L_mac(L_sum, x[-i], y[-i]); + L_sum = L_mac( L_sum, x[-i], y[-i] ); } } /* Q31 */ - sft = norm_l(L_sum); - L_sum = L_shl(L_sum, sft); - *exp = sub(30, sft); + sft = norm_l( L_sum ); + L_sum = L_shl( L_sum, sft ); + *exp = sub( 30, sft ); move16(); /* exponent = 0..30 */ - sft = norm_l(L_sum2); - L_sum2 = L_shl(L_sum2, sft); - *exp2 = sub(30, sft); + sft = norm_l( L_sum2 ); + L_sum2 = L_shl( L_sum2, sft ); + *exp2 = sub( 30, sft ); move16(); /* exponent = 0..30 */ - *sum1 = extract_h(L_shr(L_sum2, 1)); + *sum1 = extract_h( L_shr( L_sum2, 1 ) ); return L_sum; } @@ -1462,8 +1467,7 @@ void pitchDoubling_det_fx( Word16 *wspeech, Word16 *pitch_ol, Word16 *T_op_fr, - Word16 *voicing_fr -) + Word16 *voicing_fr ) { Word16 new_op_fr[2]; Word16 new_voicing[2]; @@ -1473,64 +1477,64 @@ void pitchDoubling_det_fx( /*save initial values*/ - new_Top[0]=pitch_ol[0]; + new_Top[0] = pitch_ol[0]; move16(); - new_Top[1]=pitch_ol[1]; + new_Top[1] = pitch_ol[1]; move16(); - FOR(m=2; m<5; m++) + FOR( m = 2; m < 5; m++ ) { /* T= pitch_ol[0]/m; */ - T = mult(pitch_ol[0],One_div_fx[m-1]); + T = mult( pitch_ol[0], One_div_fx[m - 1] ); - IF(GE_16(T,PIT_MIN_12k8)) + IF( GE_16( T, PIT_MIN_12k8 ) ) { - pitch_ol2_fx( PIT_MIN_SHORTER, T, &(new_op_fr[0]), &new_voicing[0], 0, wspeech, 2 ); - pitch_ol2_fx( PIT_MIN_SHORTER, T, &(new_op_fr[1]), &new_voicing[1], L_SUBFR, wspeech, 2 ); + pitch_ol2_fx( PIT_MIN_SHORTER, T, &( new_op_fr[0] ), &new_voicing[0], 0, wspeech, 2 ); + pitch_ol2_fx( PIT_MIN_SHORTER, T, &( new_op_fr[1] ), &new_voicing[1], L_SUBFR, wspeech, 2 ); /* IF(sub(add(new_voicing[0],new_voicing[1]),add(voicing_fr[0],voicing_fr[1]))>0 */ - IF( L_msu(L_msu(L_mac(L_mult(new_voicing[0], 8192),new_voicing[1], 8192), voicing_fr[0], 8192), voicing_fr[1], 8192) > 0 ) + IF( L_msu( L_msu( L_mac( L_mult( new_voicing[0], 8192 ), new_voicing[1], 8192 ), voicing_fr[0], 8192 ), voicing_fr[1], 8192 ) > 0 ) { - new_Top[0]=T; + new_Top[0] = T; move16(); - T_op_fr[0]=new_op_fr[0]; + T_op_fr[0] = new_op_fr[0]; move16(); - T_op_fr[1]=new_op_fr[1]; + T_op_fr[1] = new_op_fr[1]; move16(); - voicing_fr[0]=new_voicing[0]; + voicing_fr[0] = new_voicing[0]; move16(); - voicing_fr[1]=new_voicing[1]; + voicing_fr[1] = new_voicing[1]; move16(); } } /* T= pitch_ol[1]/m; */ - T = mult(pitch_ol[1],One_div_fx[m-1]); + T = mult( pitch_ol[1], One_div_fx[m - 1] ); - IF(GE_16(T,PIT_MIN_12k8)) + IF( GE_16( T, PIT_MIN_12k8 ) ) { - pitch_ol2_fx( PIT_MIN_SHORTER, T, &(new_op_fr[0]), &new_voicing[0], 2*L_SUBFR, wspeech, 2 ); - pitch_ol2_fx( PIT_MIN_SHORTER, T, &(new_op_fr[1]), &new_voicing[1], 3*L_SUBFR, wspeech, 2 ); + pitch_ol2_fx( PIT_MIN_SHORTER, T, &( new_op_fr[0] ), &new_voicing[0], 2 * L_SUBFR, wspeech, 2 ); + pitch_ol2_fx( PIT_MIN_SHORTER, T, &( new_op_fr[1] ), &new_voicing[1], 3 * L_SUBFR, wspeech, 2 ); /* IF(sub(add(new_voicing[0],new_voicing[1]),add(voicing_fr[2],voicing_fr[3]))>0) */ - IF( L_msu(L_msu(L_mac(L_mult(new_voicing[0], 8192),new_voicing[1], 8192), voicing_fr[2], 8192), voicing_fr[3], 8192) > 0 ) + IF( L_msu( L_msu( L_mac( L_mult( new_voicing[0], 8192 ), new_voicing[1], 8192 ), voicing_fr[2], 8192 ), voicing_fr[3], 8192 ) > 0 ) { - new_Top[1]=T; + new_Top[1] = T; move16(); - T_op_fr[2]=new_op_fr[0]; + T_op_fr[2] = new_op_fr[0]; move16(); - T_op_fr[3]=new_op_fr[1]; + T_op_fr[3] = new_op_fr[1]; move16(); - voicing_fr[2]=new_voicing[0]; + voicing_fr[2] = new_voicing[0]; move16(); - voicing_fr[3]=new_voicing[1]; + voicing_fr[3] = new_voicing[1]; move16(); } } } - pitch_ol[0]=new_Top[0]; + pitch_ol[0] = new_Top[0]; move16(); - pitch_ol[1]=new_Top[1]; + pitch_ol[1] = new_Top[1]; move16(); -}/*end of pitch doubling detection*/ +} /*end of pitch doubling detection*/ diff --git a/lib_enc/plc_enc_ext_fx.c b/lib_enc/plc_enc_ext_fx.c index da531a56e..5c6af38f3 100644 --- a/lib_enc/plc_enc_ext_fx.c +++ b/lib_enc/plc_enc_ext_fx.c @@ -9,14 +9,14 @@ #include "stat_enc.h" //#include "prot_fx.h" #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ -#include "basop_util.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ +#include "basop_util.h" /* Function prototypes */ #define NBITS_GACELP 5 -//extern const Word16 lsf_init_fx[16]; +// extern const Word16 lsf_init_fx[16]; /*-------------------------------------------------------------------* * init_PLC_enc_fx() @@ -26,7 +26,7 @@ void init_PLC_enc_fx( PLC_ENC_EVS_HANDLE hPlcExt, - Word32 sampleRate /* core coder SR */ + Word32 sampleRate /* core coder SR */ ) { Word16 itr; @@ -44,25 +44,25 @@ void init_PLC_enc_fx( hPlcExt->Q_new = 0; move16(); - set16_fx(hPlcExt->mem_MA_14Q1,0,M); - set16_fx(hPlcExt->mem_AR,0,M); - set16_fx(hPlcExt->lsfold_14Q1,0,M); - set16_fx(hPlcExt->lspold_Q15,0,M); + set16_fx( hPlcExt->mem_MA_14Q1, 0, M ); + set16_fx( hPlcExt->mem_AR, 0, M ); + set16_fx( hPlcExt->lsfold_14Q1, 0, M ); + set16_fx( hPlcExt->lspold_Q15, 0, M ); - set16_fx(hPlcExt->old_exc_Qold,0,8); + set16_fx( hPlcExt->old_exc_Qold, 0, 8 ); - set16_fx(hPlcExt->lsfoldbfi0_14Q1,0,M); - set16_fx(hPlcExt->lsfoldbfi1_14Q1,0,M); - set16_fx(hPlcExt->lsf_adaptive_mean_14Q1,0,M); + set16_fx( hPlcExt->lsfoldbfi0_14Q1, 0, M ); + set16_fx( hPlcExt->lsfoldbfi1_14Q1, 0, M ); + set16_fx( hPlcExt->lsf_adaptive_mean_14Q1, 0, M ); hPlcExt->stab_fac_Q15 = 0; move16(); - IF( EQ_32(sampleRate, INT_FS_12k8)) + IF( EQ_32( sampleRate, INT_FS_12k8 ) ) { hPlcExt->T0_4th = L_SUBFR; move16(); hPlcExt->T0 = L_SUBFR; move16(); - FOR( itr=0; itrlsf_con[itr] = lsf_init_fx[itr]; move16(); @@ -78,11 +78,11 @@ void init_PLC_enc_fx( move16(); hPlcExt->T0 = L_SUBFR; move16(); - FOR( itr=0; itrlsf_con[itr] = add(lsf_init_fx[itr],shr(lsf_init_fx[itr],2)); - hPlcExt->last_lsf_ref[itr] = add(lsf_init_fx[itr],shr(lsf_init_fx[itr],2)); - hPlcExt->last_lsf_con[itr] = add(lsf_init_fx[itr],shr(lsf_init_fx[itr],2)); + hPlcExt->lsf_con[itr] = add( lsf_init_fx[itr], shr( lsf_init_fx[itr], 2 ) ); + hPlcExt->last_lsf_ref[itr] = add( lsf_init_fx[itr], shr( lsf_init_fx[itr], 2 ) ); + hPlcExt->last_lsf_con[itr] = add( lsf_init_fx[itr], shr( lsf_init_fx[itr], 2 ) ); } } @@ -99,17 +99,16 @@ void gPLC_encInfo_fx( const Word32 total_brate, const Word16 bwidth, const Word16 last_clas, - const Word16 coder_type -) + const Word16 coder_type ) { - IF (hPlcExt) + IF( hPlcExt ) { hPlcExt->calcOnlylsf = 1; move16(); test(); - IF ( ( GE_16(bwidth, WB) && EQ_32(total_brate, ACELP_24k40))) + IF( ( GE_16( bwidth, WB ) && EQ_32( total_brate, ACELP_24k40 ) ) ) { hPlcExt->enableGplc = 1; move16(); @@ -118,8 +117,8 @@ void gPLC_encInfo_fx( test(); test(); test(); - IF ( (EQ_16(last_clas, VOICED_CLAS)||EQ_16(last_clas,ONSET))&& - (EQ_16(coder_type, VOICED) || EQ_16(coder_type, GENERIC) ) ) + IF( ( EQ_16( last_clas, VOICED_CLAS ) || EQ_16( last_clas, ONSET ) ) && + ( EQ_16( coder_type, VOICED ) || EQ_16( coder_type, GENERIC ) ) ) { hPlcExt->nBits = NBITS_GACELP; move16(); @@ -134,8 +133,5 @@ void gPLC_encInfo_fx( hPlcExt->nBits = NBITS_GACELP; move16(); } - } - } - diff --git a/lib_enc/ppp_enc_fx.c b/lib_enc/ppp_enc_fx.c index f509b0dd9..8353659ee 100644 --- a/lib_enc/ppp_enc_fx.c +++ b/lib_enc/ppp_enc_fx.c @@ -8,26 +8,24 @@ //#include "prot_fx.h" #include "rom_com_fx.h" #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ -#include "basop_util.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ +#include "basop_util.h" /* Function prototypes */ /*-------------------------------------------------------------------* * Local constants *-------------------------------------------------------------------*/ #define ERB_CBSIZE1 64 #define ERB_CBSIZE2 64 -#define P_CBSIZE 64 +#define P_CBSIZE 64 /*-------------------------------------------------------------------* * Local functions *--------------------------------------------------------------------*/ -static Word16 DTFS_quant_cw_fx(DTFS_STRUCTURE* X_fx, Word16 pl, const Word16* curr_lpc_fx, Word16* POWER_IDX, - Word16* AMP_IDX, Word16* lastLgainE_fx, Word16* lastHgainE_fx, Word16* lasterbE_fx, Word16* sin_tab, Word16* cos_tab); -static Word16 DTFS_alignment_fine_new_fx(DTFS_STRUCTURE X1_fx, DTFS_STRUCTURE X2_fx, Word16* S_fx, Word16* C_fx); -static void erb_diff_fx(const Word16* prev_erb, Word16 pl, const Word16* curr_erb, Word16 l, const Word16* curr_lsp, Word16* index, Word16 num_erb); - +static Word16 DTFS_quant_cw_fx( DTFS_STRUCTURE *X_fx, Word16 pl, const Word16 *curr_lpc_fx, Word16 *POWER_IDX, Word16 *AMP_IDX, Word16 *lastLgainE_fx, Word16 *lastHgainE_fx, Word16 *lasterbE_fx, Word16 *sin_tab, Word16 *cos_tab ); +static Word16 DTFS_alignment_fine_new_fx( DTFS_STRUCTURE X1_fx, DTFS_STRUCTURE X2_fx, Word16 *S_fx, Word16 *C_fx ); +static void erb_diff_fx( const Word16 *prev_erb, Word16 pl, const Word16 *curr_erb, Word16 l, const Word16 *curr_lsp, Word16 *index, Word16 num_erb ); /*=======================================================================================*/ @@ -78,47 +76,48 @@ static void erb_diff_fx(const Word16* prev_erb, Word16 pl, const Word16* curr_ /*=======================================================================================*/ ivas_error ppp_quarter_encoder_fx( - Word16* returnFlag, /* o : return value */ - DTFS_STRUCTURE *CURRCW_Q_FX, /* o : Quantized (amp/phase) DTFS */ - DTFS_STRUCTURE *TARGETCW_FX, /* o : DTFS with quant phase but unquant Amp */ - Word16 prevCW_lag, /* i : previous lag */ - DTFS_STRUCTURE vCURRCW_NQ_FX, /* i : Unquantized DTFS */ - const Word16 *curr_lpc_fx, /* i : LPCS */ - Word16 *lastLgainE_fx, /* i/o: last low band gain */ - Word16 *lastHgainE_fx, /* i/o: last high band gain */ - Word16 *lasterbE_fx, /* i/o: last ERB vector */ - DTFS_STRUCTURE PREV_CW_E_FX, /* i : past DTFS */ - Word16 *S_fx, /* i : sin table, Q15 */ - Word16 *C_fx, /* i : cos table, Q15 */ - BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle */ + Word16 *returnFlag, /* o : return value */ + DTFS_STRUCTURE *CURRCW_Q_FX, /* o : Quantized (amp/phase) DTFS */ + DTFS_STRUCTURE *TARGETCW_FX, /* o : DTFS with quant phase but unquant Amp */ + Word16 prevCW_lag, /* i : previous lag */ + DTFS_STRUCTURE vCURRCW_NQ_FX, /* i : Unquantized DTFS */ + const Word16 *curr_lpc_fx, /* i : LPCS */ + Word16 *lastLgainE_fx, /* i/o: last low band gain */ + Word16 *lastHgainE_fx, /* i/o: last high band gain */ + Word16 *lasterbE_fx, /* i/o: last ERB vector */ + DTFS_STRUCTURE PREV_CW_E_FX, /* i : past DTFS */ + Word16 *S_fx, /* i : sin table, Q15 */ + Word16 *C_fx, /* i : cos table, Q15 */ + BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle */ ) { DTFS_STRUCTURE *PREVDTFS_FX; Word16 tmp_fx, temp_pl_fx, temp_l_fx; Word16 temp; Word16 l; - Word16 POWER_IDX_FX; /* Codebook index for the power quantization for PPP */ - Word16 AMP_IDX_fx[2]; /* Codebook index for the Amplitude quantization for PPP */ + Word16 POWER_IDX_FX; /* Codebook index for the power quantization for PPP */ + Word16 AMP_IDX_fx[2]; /* Codebook index for the Amplitude quantization for PPP */ Word16 Erot_fx = 0; /* Word16 S_fx[PIT_MAX*4+1], C_fx[PIT_MAX*4+1];*/ - Word32 Ltempd,Ltempn; + Word32 Ltempd, Ltempn; Word32 L_tmp, L_tmp1; Word16 tmp, exp; ivas_error error; error = IVAS_ERR_OK; *returnFlag = 1; - move16();move16(); - IF((error = DTFS_new_fx(&PREVDTFS_FX)) != IVAS_ERR_OK) + move16(); + move16(); + IF( ( error = DTFS_new_fx( &PREVDTFS_FX ) ) != IVAS_ERR_OK ) { - IVAS_ERROR(error, "Error creating DTFS structure"); + IVAS_ERROR( error, "Error creating DTFS structure" ); } DTFS_copy_fx( CURRCW_Q_FX, vCURRCW_NQ_FX ); DTFS_copy_fx( PREVDTFS_FX, PREV_CW_E_FX ); l = CURRCW_Q_FX->lag_fx; move16(); - temp_l_fx = CURRCW_Q_FX->lag_fx; + temp_l_fx = CURRCW_Q_FX->lag_fx; move16(); temp_pl_fx = prevCW_lag; move16(); @@ -128,68 +127,68 @@ ivas_error ppp_quarter_encoder_fx( /* z = ((L_FRAME-temp_l)*(temp_l+temp_pl))/(2*temp_l*temp_pl); */ /* Erot = (float) (temp_l - rint_new(temp_l*(z - floor(z)))); */ - temp = sub(L_FRAME,temp_l_fx); /*Q0 */ - exp = norm_s(temp_pl_fx); - tmp = div_s(shl(1,sub(14,exp)),temp_pl_fx); /*Q(29-exp) */ - L_tmp = L_mult(temp,tmp); /*Q(31-exp); +1 due to /2 */ - L_tmp = L_shl(L_tmp,sub(exp,15)); /*Q16 */ + temp = sub( L_FRAME, temp_l_fx ); /*Q0 */ + exp = norm_s( temp_pl_fx ); + tmp = div_s( shl( 1, sub( 14, exp ) ), temp_pl_fx ); /*Q(29-exp) */ + L_tmp = L_mult( temp, tmp ); /*Q(31-exp); +1 due to /2 */ + L_tmp = L_shl( L_tmp, sub( exp, 15 ) ); /*Q16 */ - exp = norm_s(temp_l_fx); - tmp = div_s(shl(1,sub(14,exp)),temp_l_fx); /*Q(29-exp) */ - L_tmp1 = L_mult(temp,tmp); /*Q(31-exp); +1 due to /2 */ - L_tmp1 = L_shl(L_tmp1,sub(exp,15)); /*Q16 */ + exp = norm_s( temp_l_fx ); + tmp = div_s( shl( 1, sub( 14, exp ) ), temp_l_fx ); /*Q(29-exp) */ + L_tmp1 = L_mult( temp, tmp ); /*Q(31-exp); +1 due to /2 */ + L_tmp1 = L_shl( L_tmp1, sub( exp, 15 ) ); /*Q16 */ - L_tmp = L_add(L_tmp,L_tmp1); /*Q16 */ + L_tmp = L_add( L_tmp, L_tmp1 ); /*Q16 */ - tmp = lshr(extract_l(L_tmp),1); /*Q15 */ - L_tmp = L_mult(temp_l_fx,tmp); /*Q16 */ - temp = rint_new_fx(L_tmp); - Erot_fx = sub(temp_l_fx,temp); /*Q0 */ + tmp = lshr( extract_l( L_tmp ), 1 ); /*Q15 */ + L_tmp = L_mult( temp_l_fx, tmp ); /*Q16 */ + temp = rint_new_fx( L_tmp ); + Erot_fx = sub( temp_l_fx, temp ); /*Q0 */ - GetSinCosTab_fx(CURRCW_Q_FX->lag_fx,S_fx,C_fx);/*get cos and sin tables for lag */ - Q2phaseShift_fx(PREVDTFS_FX,shl(Erot_fx,2),CURRCW_Q_FX->lag_fx,S_fx,C_fx); + GetSinCosTab_fx( CURRCW_Q_FX->lag_fx, S_fx, C_fx ); /*get cos and sin tables for lag */ + Q2phaseShift_fx( PREVDTFS_FX, shl( Erot_fx, 2 ), CURRCW_Q_FX->lag_fx, S_fx, C_fx ); - DTFS_copy_fx(TARGETCW_FX,*CURRCW_Q_FX); + DTFS_copy_fx( TARGETCW_FX, *CURRCW_Q_FX ); /* Amplitude Quantization */ - DTFS_car2pol_fx(CURRCW_Q_FX); /* at this point currCW_q=curr_nq */ + DTFS_car2pol_fx( CURRCW_Q_FX ); /* at this point currCW_q=curr_nq */ /*As the upper cut of freqencies are normalized to 12800, we have to multiply upper cut off freq by 2.56(1/12800 in Q15) */ - Ltempn = L_mult(CURRCW_Q_FX->upper_cut_off_freq_fx,10486);/* Q0+Q27 = Q28 */ - CURRCW_Q_FX->upper_cut_off_freq_fx = (Word16)L_shr(Ltempn,13);/*Q15 */ - Ltempn = L_mult(CURRCW_Q_FX->upper_cut_off_freq_of_interest_fx,10486);/* Q0+Q27 = Q28 */ - CURRCW_Q_FX->upper_cut_off_freq_of_interest_fx = (Word16)L_shr(Ltempn,13);/*Q15 */ + Ltempn = L_mult( CURRCW_Q_FX->upper_cut_off_freq_fx, 10486 ); /* Q0+Q27 = Q28 */ + CURRCW_Q_FX->upper_cut_off_freq_fx = (Word16) L_shr( Ltempn, 13 ); /*Q15 */ + Ltempn = L_mult( CURRCW_Q_FX->upper_cut_off_freq_of_interest_fx, 10486 ); /* Q0+Q27 = Q28 */ + CURRCW_Q_FX->upper_cut_off_freq_of_interest_fx = (Word16) L_shr( Ltempn, 13 ); /*Q15 */ - *returnFlag = DTFS_quant_cw_fx(CURRCW_Q_FX,prevCW_lag,curr_lpc_fx,&POWER_IDX_FX, - AMP_IDX_fx,lastLgainE_fx,lastHgainE_fx,lasterbE_fx,S_fx,C_fx); + *returnFlag = DTFS_quant_cw_fx( CURRCW_Q_FX, prevCW_lag, curr_lpc_fx, &POWER_IDX_FX, + AMP_IDX_fx, lastLgainE_fx, lastHgainE_fx, lasterbE_fx, S_fx, C_fx ); move16(); /*De-normalize cut off frequencies */ - Ltempn = L_shl((Word32)CURRCW_Q_FX->upper_cut_off_freq_fx,13);/*Q28 */ - CURRCW_Q_FX->upper_cut_off_freq_fx = (Word16)find_remd(Ltempn, 20971,&Ltempd); + Ltempn = L_shl( (Word32) CURRCW_Q_FX->upper_cut_off_freq_fx, 13 ); /*Q28 */ + CURRCW_Q_FX->upper_cut_off_freq_fx = (Word16) find_remd( Ltempn, 20971, &Ltempd ); move16(); - Ltempn = L_shl((Word32)CURRCW_Q_FX->upper_cut_off_freq_of_interest_fx,13);/*Q28 */ - CURRCW_Q_FX->upper_cut_off_freq_of_interest_fx = (Word16)find_remd(Ltempn, 20971,&Ltempd); + Ltempn = L_shl( (Word32) CURRCW_Q_FX->upper_cut_off_freq_of_interest_fx, 13 ); /*Q28 */ + CURRCW_Q_FX->upper_cut_off_freq_of_interest_fx = (Word16) find_remd( Ltempn, 20971, &Ltempd ); - push_indice_fx(hBstr, IND_AMP0, AMP_IDX_fx[0], 6 ); + push_indice_fx( hBstr, IND_AMP0, AMP_IDX_fx[0], 6 ); push_indice_fx( hBstr, IND_AMP1, AMP_IDX_fx[1], 6 ); - push_indice_fx( hBstr, IND_POWER, POWER_IDX_FX, 6); + push_indice_fx( hBstr, IND_POWER, POWER_IDX_FX, 6 ); /*Phase copying is done through copy_phase instead of car2pol and pol2car */ - copy_phase_fx(TARGETCW_FX,*CURRCW_Q_FX,TARGETCW_FX); + copy_phase_fx( TARGETCW_FX, *CURRCW_Q_FX, TARGETCW_FX ); /*Phase copying is done through copy_phase instead of car2pol and pol2car */ - copy_phase_fx(PREVDTFS_FX,*CURRCW_Q_FX,CURRCW_Q_FX); + copy_phase_fx( PREVDTFS_FX, *CURRCW_Q_FX, CURRCW_Q_FX ); /* Copying phase spectrum over */ /*mvr2r(PREVDTFS->b, CURRCW_Q->b, (short)(CURRCW_Q->lag>>1)+1 ); */ /*DTFS_pol2car(CURRCW_Q); */ /*DTFS_pol2car(TARGETCW); */ - tmp_fx = DTFS_alignment_fine_new_fx(*TARGETCW_FX,*CURRCW_Q_FX,S_fx,C_fx); + tmp_fx = DTFS_alignment_fine_new_fx( *TARGETCW_FX, *CURRCW_Q_FX, S_fx, C_fx ); move16(); test(); - IF (GT_16(add(tmp_fx,12),28)||LT_16(tmp_fx,-12)) + IF( GT_16( add( tmp_fx, 12 ), 28 ) || LT_16( tmp_fx, -12 ) ) { tmp_fx = 0; move16(); @@ -198,30 +197,30 @@ ivas_error ppp_quarter_encoder_fx( } /*DTFS_phaseShift( CURRCW_Q,(float)(PI2*tmp/CURRCW_Q->lag) ); */ - Q2phaseShift_fx(CURRCW_Q_FX,tmp_fx,CURRCW_Q_FX->lag_fx,S_fx,C_fx); + Q2phaseShift_fx( CURRCW_Q_FX, tmp_fx, CURRCW_Q_FX->lag_fx, S_fx, C_fx ); - push_indice_fx( hBstr, IND_GLOBAL_ALIGNMENT, shr(add(tmp_fx,12),2), 3 ); + push_indice_fx( hBstr, IND_GLOBAL_ALIGNMENT, shr( add( tmp_fx, 12 ), 2 ), 3 ); - count_free(PREVDTFS_FX); + count_free( PREVDTFS_FX ); return error; } /*-------------------------------------------------------------------* -* set_ppp_mode_fx() + * set_ppp_mode_fx() * * Determine if the current frame should be coded by PPP or not * Impose PPP - CELP - CELP pattern *-------------------------------------------------------------------*/ void set_ppp_mode_fx( - Encoder_State *st_fx, /* i/o: state structure */ - const Word16 noisy_speech_HO, /* i : SC-VBR noisy speech HO flag */ - const Word16 clean_speech_HO, /* i : SC-VBR clean speech HO flag */ - const Word16 NB_speech_HO, /* i : SC-VBR NB speech HO flag */ - const Word16 localVAD_he /* i : HE-SAD flag without hangover */ + Encoder_State *st_fx, /* i/o: state structure */ + const Word16 noisy_speech_HO, /* i : SC-VBR noisy speech HO flag */ + const Word16 clean_speech_HO, /* i : SC-VBR clean speech HO flag */ + const Word16 NB_speech_HO, /* i : SC-VBR NB speech HO flag */ + const Word16 localVAD_he /* i : HE-SAD flag without hangover */ ) { - SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; + SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; test(); test(); @@ -229,9 +228,9 @@ void set_ppp_mode_fx( test(); test(); - IF ( EQ_16( st_fx->vad_flag, 1)&& - ( EQ_16( noisy_speech_HO , 1 ) || EQ_16( clean_speech_HO, 1 ) || EQ_16( NB_speech_HO, 1) ) && - ( st_fx->localVAD == 0 || localVAD_he == 0 ) ) + IF( EQ_16( st_fx->vad_flag, 1 ) && + ( EQ_16( noisy_speech_HO, 1 ) || EQ_16( clean_speech_HO, 1 ) || EQ_16( NB_speech_HO, 1 ) ) && + ( st_fx->localVAD == 0 || localVAD_he == 0 ) ) { st_fx->coder_type = UNVOICED; @@ -240,7 +239,7 @@ void set_ppp_mode_fx( test(); test(); - IF ( EQ_16( st_fx->coder_type , INACTIVE ) && (st_fx->vad_flag==0) && EQ_16(hSC_VBR->last_nelp_mode,1)) /* avoid HO frame go to GSC */ + IF( EQ_16( st_fx->coder_type, INACTIVE ) && ( st_fx->vad_flag == 0 ) && EQ_16( hSC_VBR->last_nelp_mode, 1 ) ) /* avoid HO frame go to GSC */ { st_fx->coder_type = UNVOICED; move16(); @@ -249,7 +248,7 @@ void set_ppp_mode_fx( /* force the coder to NELP mode during the first five frames */ /* this will indicate the decoder that the coder is operating in the VBR mode */ - IF ( LT_16( st_fx->ini_frame, 5)) + IF( LT_16( st_fx->ini_frame, 5 ) ) { st_fx->coder_type = UNVOICED; move16(); @@ -258,7 +257,7 @@ void set_ppp_mode_fx( } /* Pattern PPP-CELP-CELP (pppcountE holds number of consecutive PPP frames) */ test(); - IF ( NE_16( st_fx->coder_type, VOICED )||EQ_16(st_fx->last_coder_type,TRANSITION)) + IF( NE_16( st_fx->coder_type, VOICED ) || EQ_16( st_fx->last_coder_type, TRANSITION ) ) { /* ensure no transient to PPP transition */ hSC_VBR->pppcountE = 0; @@ -267,23 +266,23 @@ void set_ppp_mode_fx( ELSE { /* current mode is voiced */ - hSC_VBR->pppcountE = add( hSC_VBR->pppcountE, 1); + hSC_VBR->pppcountE = add( hSC_VBR->pppcountE, 1 ); test(); test(); test(); test(); - IF ( ( EQ_16( hSC_VBR->pppcountE, 1 )&&NE_16(hSC_VBR->last_last_ppp_mode,1)&& hSC_VBR->rate_control==0)|| - ( EQ_16( hSC_VBR->pppcountE, 1 ) && hSC_VBR->mode_QQF != 0) ) + IF( ( EQ_16( hSC_VBR->pppcountE, 1 ) && NE_16( hSC_VBR->last_last_ppp_mode, 1 ) && hSC_VBR->rate_control == 0 ) || + ( EQ_16( hSC_VBR->pppcountE, 1 ) && hSC_VBR->mode_QQF != 0 ) ) { hSC_VBR->ppp_mode = 1; move16(); st_fx->core_brate = PPP_NELP_2k80; move32(); } - ELSE IF ( EQ_16(hSC_VBR->pppcountE, 2 )) + ELSE IF( EQ_16( hSC_VBR->pppcountE, 2 ) ) { test(); - IF (hSC_VBR->last_ppp_mode != 0 && hSC_VBR->mode_QQF == 0 ) + IF( hSC_VBR->last_ppp_mode != 0 && hSC_VBR->mode_QQF == 0 ) { /* QFF mode */ hSC_VBR->ppp_mode = 0; @@ -309,7 +308,7 @@ void set_ppp_mode_fx( test(); - IF (hSC_VBR->ppp_mode == 0 && EQ_16(hSC_VBR->set_ppp_generic, 1)) + IF( hSC_VBR->ppp_mode == 0 && EQ_16( hSC_VBR->set_ppp_generic, 1 ) ) { hSC_VBR->set_ppp_generic = 0; move16(); @@ -317,7 +316,7 @@ void set_ppp_mode_fx( move16(); } - IF ( st_fx->last_core == HQ_CORE ) + IF( st_fx->last_core == HQ_CORE ) { hSC_VBR->ppp_mode = 0; move16(); @@ -331,8 +330,7 @@ void set_ppp_mode_fx( test(); test(); test(); - IF ( (hSC_VBR->last_ppp_mode != 0 ) && (hSC_VBR->ppp_mode == 0 ) && ( st_fx->sp_aud_decision1 != 0) - && EQ_16(st_fx->bwidth, NB)&&st_fx->Opt_SC_VBR!=0) /*if it were about to go from ppp->HQ*/ + IF( ( hSC_VBR->last_ppp_mode != 0 ) && ( hSC_VBR->ppp_mode == 0 ) && ( st_fx->sp_aud_decision1 != 0 ) && EQ_16( st_fx->bwidth, NB ) && st_fx->Opt_SC_VBR != 0 ) /*if it were about to go from ppp->HQ*/ { hSC_VBR->avoid_HQ_VBR_NB = 1; move16(); @@ -343,7 +341,7 @@ void set_ppp_mode_fx( test(); test(); test(); - IF ( (hSC_VBR->last_nelp_mode != 0) && ( st_fx->sp_aud_decision1 != 0) && EQ_16( st_fx->bwidth, NB)&&(st_fx->Opt_SC_VBR!=0)) /*if it were about to go from nelp->HQ*/ + IF( ( hSC_VBR->last_nelp_mode != 0 ) && ( st_fx->sp_aud_decision1 != 0 ) && EQ_16( st_fx->bwidth, NB ) && ( st_fx->Opt_SC_VBR != 0 ) ) /*if it were about to go from nelp->HQ*/ { hSC_VBR->avoid_HQ_VBR_NB = 1; move16(); @@ -355,11 +353,11 @@ void set_ppp_mode_fx( test(); test(); test(); - if( ( GT_16(st_fx->old_pitch_buf_fx[(2*NB_SUBFR)-1], PPP_LAG_THRLD_Q6)|| - GT_16(st_fx->pitch_fx[1], PPP_LAG_THRLD) || !st_fx->last_Opt_SC_VBR ) && - EQ_16(hSC_VBR->ppp_mode,1) ) + if ( ( GT_16( st_fx->old_pitch_buf_fx[( 2 * NB_SUBFR ) - 1], PPP_LAG_THRLD_Q6 ) || + GT_16( st_fx->pitch_fx[1], PPP_LAG_THRLD ) || !st_fx->last_Opt_SC_VBR ) && + EQ_16( hSC_VBR->ppp_mode, 1 ) ) { - hSC_VBR->ppp_mode=0; + hSC_VBR->ppp_mode = 0; move16(); st_fx->core_brate = ACELP_7k20; move32(); @@ -402,21 +400,20 @@ void set_ppp_mode_fx( /* NOTE: Frequencies is normalized by 12800, i.e. 1=12800Hz */ /*===================================================================*/ static Word16 DTFS_quant_cw_fx( - DTFS_STRUCTURE* X_fx, /* i/o: DTFS unquant inp, quant out */ - Word16 pl, /* i : Previous lag */ - const Word16* curr_lpc_fx, /* i : LPC */ - Word16* POWER_IDX, /* o : Power index */ - Word16* AMP_IDX, /* o : Amplitude index */ - Word16* lastLgainE_fx, /* i/o: last frame lowband gain */ - Word16* lastHgainE_fx, /* i/o: last frame highband gain */ - Word16* lasterbE_fx, /* i/o: last frame ERB vector */ - Word16* sin_tab, - Word16* cos_tab -) + DTFS_STRUCTURE *X_fx, /* i/o: DTFS unquant inp, quant out */ + Word16 pl, /* i : Previous lag */ + const Word16 *curr_lpc_fx, /* i : LPC */ + Word16 *POWER_IDX, /* o : Power index */ + Word16 *AMP_IDX, /* o : Amplitude index */ + Word16 *lastLgainE_fx, /* i/o: last frame lowband gain */ + Word16 *lastHgainE_fx, /* i/o: last frame highband gain */ + Word16 *lasterbE_fx, /* i/o: last frame ERB vector */ + Word16 *sin_tab, + Word16 *cos_tab ) { Word16 num_erb = 0; - const Word16* PowerCB_fx = NULL; + const Word16 *PowerCB_fx = NULL; Word16 tmp, w[2], target[2], j, slot[NUM_ERB_WB], flag; Word16 n, d1, d2, exp; Word32 minerror, Ltemp, logLag_fx, L_tmp; @@ -431,14 +428,14 @@ static Word16 DTFS_quant_cw_fx( /* upper_cute_off_freq are normalized to 12800 */ - IF(EQ_16(X_fx->upper_cut_off_freq_fx, 0x2800))/* 4000 hz normalized to 12800 in Q15 */ + IF( EQ_16( X_fx->upper_cut_off_freq_fx, 0x2800 ) ) /* 4000 hz normalized to 12800 in Q15 */ { num_erb = NUM_ERB_NB; move16(); PowerCB_fx = PowerCB_NB_fx; move16(); } - ELSE IF(EQ_16(X_fx->upper_cut_off_freq_fx, 0x4000))/* 6400 hz normalized to 12800 in Q15 */ + ELSE IF( EQ_16( X_fx->upper_cut_off_freq_fx, 0x4000 ) ) /* 6400 hz normalized to 12800 in Q15 */ { num_erb = NUM_ERB_WB; move16(); @@ -447,53 +444,53 @@ static Word16 DTFS_quant_cw_fx( } /* Get weighting and target */ - quant_target_fx(X_fx, curr_lpc_fx, w, target, sin_tab, cos_tab); + quant_target_fx( X_fx, curr_lpc_fx, w, target, sin_tab, cos_tab ); /* Power Quantization in log domain */ - target[0] = sub(target[0], *lastLgainE_fx); + target[0] = sub( target[0], *lastLgainE_fx ); move16(); - target[1] = sub(target[1], *lastHgainE_fx); + target[1] = sub( target[1], *lastHgainE_fx ); move16(); - minerror = L_add(EVS_LW_MAX, 0); + minerror = L_add( EVS_LW_MAX, 0 ); *POWER_IDX = 0; move16(); j = 0; move16(); - FOR(n = 0; n < P_CBSIZE * 2; n += 2) + FOR( n = 0; n < P_CBSIZE * 2; n += 2 ) { /* n=shl(j,1); n=offset to current codebook entry */ - d1 = sub(target[0], PowerCB_fx[n]); - d2 = sub(target[1], PowerCB_fx[n + 1]); - Ltemp = L_mult(w[0], abs_s(d1)); - Ltemp = L_mac(Ltemp, w[1], abs_s(d2)); /* Ltemp=error */ + d1 = sub( target[0], PowerCB_fx[n] ); + d2 = sub( target[1], PowerCB_fx[n + 1] ); + Ltemp = L_mult( w[0], abs_s( d1 ) ); + Ltemp = L_mac( Ltemp, w[1], abs_s( d2 ) ); /* Ltemp=error */ test(); - IF(d1 >= 0 && d2 >= 0) + IF( d1 >= 0 && d2 >= 0 ) { - Ltemp = Mult_32_16(Ltemp, 0x6666); /* *=0.8 */ + Ltemp = Mult_32_16( Ltemp, 0x6666 ); /* *=0.8 */ } - IF(LT_32(Ltemp, minerror)) + IF( LT_32( Ltemp, minerror ) ) { - minerror = L_add(Ltemp, 0); + minerror = L_add( Ltemp, 0 ); *POWER_IDX = j; move16(); } - j = add(j, 1); + j = add( j, 1 ); } - DTFS_to_erb_fx(*X_fx, curr_erb_fx); + DTFS_to_erb_fx( *X_fx, curr_erb_fx ); - FOR(j = 0; j < num_erb; j++) + FOR( j = 0; j < num_erb; j++ ) { erb_uq[j] = curr_erb_fx[j]; move16(); } - erb_slot_fx(X_fx->lag_fx, slot, mfreq, num_erb); + erb_slot_fx( X_fx->lag_fx, slot, mfreq, num_erb ); /* Amplitude Quantization */ - erb_diff_fx(lasterbE_fx, pl, curr_erb_fx, X_fx->lag_fx, curr_lpc_fx, AMP_IDX, num_erb); + erb_diff_fx( lasterbE_fx, pl, curr_erb_fx, X_fx->lag_fx, curr_lpc_fx, AMP_IDX, num_erb ); /* Dequantization of prototype */ @@ -501,96 +498,97 @@ static Word16 DTFS_quant_cw_fx( /* DTFS_dequant_cw_fx(pl, *POWER_IDX, AMP_IDX,lastLgainE_fx,lastHgainE_fx, lasterbE_fx,X_fx,num_erb,curr_erb_fx); */ /* Determine IF the amplitude quantization is good enough */ - erb_add_fx(curr_erb_fx, X_fx->lag_fx, lasterbE_fx, pl, AMP_IDX, num_erb); + erb_add_fx( curr_erb_fx, X_fx->lag_fx, lasterbE_fx, pl, AMP_IDX, num_erb ); - curr_erb_fx[0] = mult_r(curr_erb_fx[1], 9830); - move16(); /* 0.3 inQ15 leaves curr_erb in Q13 */ - curr_erb_fx[sub(num_erb, 2)] = mult_r(curr_erb_fx[sub(num_erb, 3)], 9830);/* Q13 */ + curr_erb_fx[0] = mult_r( curr_erb_fx[1], 9830 ); + move16(); /* 0.3 inQ15 leaves curr_erb in Q13 */ + curr_erb_fx[sub( num_erb, 2 )] = mult_r( curr_erb_fx[sub( num_erb, 3 )], 9830 ); /* Q13 */ - curr_erb_fx[sub(num_erb, 1)] = 0; + curr_erb_fx[sub( num_erb, 1 )] = 0; move16(); flag = 1; move16(); - Ltemp = L_deposit_l(0); + Ltemp = L_deposit_l( 0 ); n = 0; move16(); - FOR(j = 1; j < 10; j++) + FOR( j = 1; j < 10; j++ ) { - IF(slot[j] != 0) + IF( slot[j] != 0 ) { - Ltemp = L_add(Ltemp, abs_s(sub(erb_uq[j], curr_erb_fx[j]))); /* Q13 */ - n = add(n, 1); /* n++ */ + Ltemp = L_add( Ltemp, abs_s( sub( erb_uq[j], curr_erb_fx[j] ) ) ); /* Q13 */ + n = add( n, 1 ); /* n++ */ } } - exp = norm_s(n); - tmp = div_s(shl(1, sub(14, exp)), n);/* 29 - exp */ - Lacc = L_shl(Mult_32_16(Ltemp, tmp), exp + 4); + exp = norm_s( n ); + tmp = div_s( shl( 1, sub( 14, exp ) ), n ); /* 29 - exp */ + Lacc = L_shl( Mult_32_16( Ltemp, tmp ), exp + 4 ); - tmp = round_fx(Lacc); /* tmp in Q15 */ + tmp = round_fx( Lacc ); /* tmp in Q15 */ test(); - if (GT_16(tmp, 0x3C29) && GT_16(target[0], -819)) + if ( GT_16( tmp, 0x3C29 ) && GT_16( target[0], -819 ) ) { - flag = 0; /* Bumping up */ move16(); + flag = 0; /* Bumping up */ + move16(); } /* mfreq normalized (2.56) in Q15 */ - DTFS_erb_inv_fx(curr_erb_fx, slot, mfreq, X_fx, num_erb); + DTFS_erb_inv_fx( curr_erb_fx, slot, mfreq, X_fx, num_erb ); /* Back up the lasterbD memory after power normalization */ - DTFS_setEngyHarm_fx(236, 2828, 0, 2828, 1, 0, &Ql, X_fx); - DTFS_setEngyHarm_fx(2828, X_fx->upper_cut_off_freq_of_interest_fx, 2828, X_fx->upper_cut_off_freq_fx, 1, 0, &Qh, X_fx); + DTFS_setEngyHarm_fx( 236, 2828, 0, 2828, 1, 0, &Ql, X_fx ); + DTFS_setEngyHarm_fx( 2828, X_fx->upper_cut_off_freq_of_interest_fx, 2828, X_fx->upper_cut_off_freq_fx, 1, 0, &Qh, X_fx ); /* Need to unify the Q factors of both bands */ - X_fx->Q = s_min(Ql, Qh); /* set Q factor to be the smaller one */ - n = sub(Ql, Qh); /* compare band Q factors */ + X_fx->Q = s_min( Ql, Qh ); /* set Q factor to be the smaller one */ + n = sub( Ql, Qh ); /* compare band Q factors */ /* This logic adjusts difference between Q formats of both bands */ - IF(n < 0) - rshiftHarmBand_fx(X_fx, 2828, X_fx->upper_cut_off_freq_fx, n); - ELSE IF(n > 0) - rshiftHarmBand_fx(X_fx, 0, 2828, sub(Qh, Ql)); + IF( n < 0 ) + rshiftHarmBand_fx( X_fx, 2828, X_fx->upper_cut_off_freq_fx, n ); + ELSE IF( n > 0 ) + rshiftHarmBand_fx( X_fx, 0, 2828, sub( Qh, Ql ) ); - tmp = shl(*POWER_IDX, 1); /* tmp=2*POWER_IDX */ - *lastLgainE_fx = add(*lastLgainE_fx, PowerCB_fx[tmp]); /* Q11 */ - *lastHgainE_fx = add(*lastHgainE_fx, PowerCB_fx[tmp + 1]); /* Q11 */ + tmp = shl( *POWER_IDX, 1 ); /* tmp=2*POWER_IDX */ + *lastLgainE_fx = add( *lastLgainE_fx, PowerCB_fx[tmp] ); /* Q11 */ + *lastHgainE_fx = add( *lastHgainE_fx, PowerCB_fx[tmp + 1] ); /* Q11 */ - Ltemp = log10_fx(X_fx->lag_fx); /* Ltemp=10*log10(lag), Q23 */ - logLag_fx = Mult_32_16(Ltemp, 0x6666); /* logLag=log10(lag), Q26 */ + Ltemp = log10_fx( X_fx->lag_fx ); /* Ltemp=10*log10(lag), Q23 */ + logLag_fx = Mult_32_16( Ltemp, 0x6666 ); /* logLag=log10(lag), Q26 */ - Ltemp = L_sub(L_shr(L_deposit_h(*lastLgainE_fx), 1), logLag_fx); /* Ltemp=Lgain-log10(lag), Q26 */ + Ltemp = L_sub( L_shr( L_deposit_h( *lastLgainE_fx ), 1 ), logLag_fx ); /* Ltemp=Lgain-log10(lag), Q26 */ - L_tmp = pow_10(Ltemp, &Q); /* Lacc=10^Lgain/lag, Q15 */ - n = norm_l(L_tmp); - Ltemp = (Word32)L_shl(L_tmp, n); /* Ltemp in Q(15+n) */ + L_tmp = pow_10( Ltemp, &Q ); /* Lacc=10^Lgain/lag, Q15 */ + n = norm_l( L_tmp ); + Ltemp = (Word32) L_shl( L_tmp, n ); /* Ltemp in Q(15+n) */ - DTFS_setEngyHarm_fx(236, 2828, 0, 2828, Ltemp, add(Q, n), &Ql, X_fx); + DTFS_setEngyHarm_fx( 236, 2828, 0, 2828, Ltemp, add( Q, n ), &Ql, X_fx ); - Ltemp = L_sub(L_shr(L_deposit_h(*lastHgainE_fx), 1), logLag_fx); /* Ltemp=Hgain-log10(lag), Q26 */ + Ltemp = L_sub( L_shr( L_deposit_h( *lastHgainE_fx ), 1 ), logLag_fx ); /* Ltemp=Hgain-log10(lag), Q26 */ /* Ltemp = L_shr(Ltemp,1); */ - L_tmp = pow_10(Ltemp, &Q); /* Lacc=10^Lgain/lag, Q15 */ - n = norm_l(L_tmp); - Ltemp = (Word32)L_shl(L_tmp, n); /* Ltemp in Q(15+n) */ + L_tmp = pow_10( Ltemp, &Q ); /* Lacc=10^Lgain/lag, Q15 */ + n = norm_l( L_tmp ); + Ltemp = (Word32) L_shl( L_tmp, n ); /* Ltemp in Q(15+n) */ - DTFS_setEngyHarm_fx(2828, X_fx->upper_cut_off_freq_of_interest_fx, 2828, X_fx->upper_cut_off_freq_fx, Ltemp, add(Q, n), &Qh, X_fx); + DTFS_setEngyHarm_fx( 2828, X_fx->upper_cut_off_freq_of_interest_fx, 2828, X_fx->upper_cut_off_freq_fx, Ltemp, add( Q, n ), &Qh, X_fx ); /* Need to unify the Q factors of both bands */ - X_fx->Q = s_min(Ql, Qh); /* set Q factor to be the smaller one */ - n = sub(Ql, Qh); /* compare band Q factors */ + X_fx->Q = s_min( Ql, Qh ); /* set Q factor to be the smaller one */ + n = sub( Ql, Qh ); /* compare band Q factors */ - IF(n < 0) + IF( n < 0 ) { - rshiftHarmBand_fx(X_fx, 2828, X_fx->upper_cut_off_freq_fx, n); + rshiftHarmBand_fx( X_fx, 2828, X_fx->upper_cut_off_freq_fx, n ); } - ELSE IF(n > 0) + ELSE IF( n > 0 ) { - rshiftHarmBand_fx(X_fx, 0, 2828, sub(Qh, Ql)); + rshiftHarmBand_fx( X_fx, 0, 2828, sub( Qh, Ql ) ); } return flag; } @@ -616,7 +614,7 @@ static Word16 DTFS_quant_cw_fx( /* CALLED FROM : TX */ /*===================================================================*/ -static Word16 DTFS_alignment_fine_new_fx(DTFS_STRUCTURE X1_fx, DTFS_STRUCTURE X2_fx, Word16* S_fx, Word16* C_fx) +static Word16 DTFS_alignment_fine_new_fx( DTFS_STRUCTURE X1_fx, DTFS_STRUCTURE X2_fx, Word16 *S_fx, Word16 *C_fx ) { Word16 temp, temp1, k, Qcorr, Qmaxcorr; Word16 n, fshift_fx, HalfLag, ab1[MAXLAG_WI], ab2[MAXLAG_WI]; @@ -625,96 +623,96 @@ static Word16 DTFS_alignment_fine_new_fx(DTFS_STRUCTURE X1_fx, DTFS_STRUCTURE X2 #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - IF(LT_16(X1_fx.lag_fx, X2_fx.lag_fx)) + IF( LT_16( X1_fx.lag_fx, X2_fx.lag_fx ) ) { - DTFS_zeroPadd_fx(X2_fx.lag_fx, &X1_fx); + DTFS_zeroPadd_fx( X2_fx.lag_fx, &X1_fx ); } - maxcorr_fx = L_add(MIN_32, 0); + maxcorr_fx = L_add( MIN_32, 0 ); Qmaxcorr = 0; move16(); - HalfLag = s_min(shr(X2_fx.lag_fx, 1), X2_fx.nH_fx); + HalfLag = s_min( shr( X2_fx.lag_fx, 1 ), X2_fx.nH_fx ); - FOR(k = 0; k <= HalfLag; k++) + FOR( k = 0; k <= HalfLag; k++ ) { - ab1[k] = round_fx(L_mac(L_mult(X1_fx.a_fx[k], X2_fx.a_fx[k]), X1_fx.b_fx[k], X2_fx.b_fx[k])); - ab2[k] = round_fx(L_msu(L_mult(X1_fx.b_fx[k], X2_fx.a_fx[k]), X1_fx.a_fx[k], X2_fx.b_fx[k])); + ab1[k] = round_fx( L_mac( L_mult( X1_fx.a_fx[k], X2_fx.a_fx[k] ), X1_fx.b_fx[k], X2_fx.b_fx[k] ) ); + ab2[k] = round_fx( L_msu( L_mult( X1_fx.b_fx[k], X2_fx.a_fx[k] ), X1_fx.a_fx[k], X2_fx.b_fx[k] ) ); } fshift_fx = 0; move16(); - FOR(n = -76; n <= 80; n += 4) + FOR( n = -76; n <= 80; n += 4 ) { /* n is Q2 */ - corr_fx = L_deposit_l(0); + corr_fx = L_deposit_l( 0 ); temp = 0; move16(); temp1 = n; move16(); - IF(n < 0) + IF( n < 0 ) { - temp1 = add(temp1, shl(X2_fx.lag_fx, 2)); /* avoid negative */ + temp1 = add( temp1, shl( X2_fx.lag_fx, 2 ) ); /* avoid negative */ } - FOR(k = 0; k <= HalfLag; k++) + FOR( k = 0; k <= HalfLag; k++ ) { #ifdef BASOP_NOGLOB - corr_fx = L_mac_o(corr_fx, ab1[k], C_fx[temp % (4 * X2_fx.lag_fx)], &Overflow); - corr_fx = L_mac_o(corr_fx, ab2[k], S_fx[temp % (4 * X2_fx.lag_fx)], &Overflow); - temp = add_o(temp, temp1, &Overflow); + corr_fx = L_mac_o( corr_fx, ab1[k], C_fx[temp % ( 4 * X2_fx.lag_fx )], &Overflow ); + corr_fx = L_mac_o( corr_fx, ab2[k], S_fx[temp % ( 4 * X2_fx.lag_fx )], &Overflow ); + temp = add_o( temp, temp1, &Overflow ); #else - corr_fx = L_mac(corr_fx, ab1[k], C_fx[temp % (4 * X2_fx.lag_fx)]); - corr_fx = L_mac(corr_fx, ab2[k], S_fx[temp % (4 * X2_fx.lag_fx)]); - temp = add(temp, temp1); + corr_fx = L_mac( corr_fx, ab1[k], C_fx[temp % ( 4 * X2_fx.lag_fx )] ); + corr_fx = L_mac( corr_fx, ab2[k], S_fx[temp % ( 4 * X2_fx.lag_fx )] ); + temp = add( temp, temp1 ); #endif } - temp = sub(32767, extract_l(L_shr(L_mult(82, abs_s(n)), 1))); /* Q15 */ - Qcorr = norm_l(corr_fx); - if (corr_fx == 0) + temp = sub( 32767, extract_l( L_shr( L_mult( 82, abs_s( n ) ), 1 ) ) ); /* Q15 */ + Qcorr = norm_l( corr_fx ); + if ( corr_fx == 0 ) { Qcorr = 31; move16(); } #ifdef BASOP_NOGLOB - temp1 = round_fx_o((Word32)L_shl_o(corr_fx, Qcorr, &Overflow), &Overflow); /* Q(Qcorr-16) */ - wcorr_fx = L_mult_o(temp1, temp, &Overflow); /* Q(Qcorr-16+15+1)=Q(Qcorr) */ + temp1 = round_fx_o( (Word32) L_shl_o( corr_fx, Qcorr, &Overflow ), &Overflow ); /* Q(Qcorr-16) */ + wcorr_fx = L_mult_o( temp1, temp, &Overflow ); /* Q(Qcorr-16+15+1)=Q(Qcorr) */ #else - temp1 = round_fx((Word32)L_shl(corr_fx, Qcorr)); /* Q(Qcorr-16) */ - wcorr_fx = L_mult(temp1, temp); /* Q(Qcorr-16+15+1)=Q(Qcorr) */ + temp1 = round_fx( (Word32) L_shl( corr_fx, Qcorr ) ); /* Q(Qcorr-16) */ + wcorr_fx = L_mult( temp1, temp ); /* Q(Qcorr-16+15+1)=Q(Qcorr) */ #endif - IF(GE_16(Qmaxcorr, Qcorr)) + IF( GE_16( Qmaxcorr, Qcorr ) ) { #ifdef BASOP_NOGLOB - diff_corr = L_sub_o(wcorr_fx, L_shl_o(maxcorr_fx, sub(Qcorr, Qmaxcorr), &Overflow), &Overflow); /* Qcorr */ + diff_corr = L_sub_o( wcorr_fx, L_shl_o( maxcorr_fx, sub( Qcorr, Qmaxcorr ), &Overflow ), &Overflow ); /* Qcorr */ #else - diff_corr = L_sub(wcorr_fx, L_shl(maxcorr_fx, sub(Qcorr, Qmaxcorr))); /* Qcorr */ + diff_corr = L_sub( wcorr_fx, L_shl( maxcorr_fx, sub( Qcorr, Qmaxcorr ) ) ); /* Qcorr */ #endif } ELSE { #ifdef BASOP_NOGLOB - diff_corr = L_sub_o(L_shl_o(wcorr_fx, sub(Qmaxcorr, Qcorr), &Overflow), maxcorr_fx, &Overflow); /* Qmaxcorr */ + diff_corr = L_sub_o( L_shl_o( wcorr_fx, sub( Qmaxcorr, Qcorr ), &Overflow ), maxcorr_fx, &Overflow ); /* Qmaxcorr */ #else - diff_corr = L_sub(L_shl(wcorr_fx, sub(Qmaxcorr, Qcorr)), maxcorr_fx); /* Qmaxcorr */ + diff_corr = L_sub( L_shl( wcorr_fx, sub( Qmaxcorr, Qcorr ) ), maxcorr_fx ); /* Qmaxcorr */ #endif } - if (diff_corr > 0) - { - fshift_fx = n; - move16(); + if ( diff_corr > 0 ) + { + fshift_fx = n; + move16(); #ifdef BASOP_NOGLOB - maxcorr_fx = (Word32)L_shl_o(corr_fx, Qcorr, &Overflow); /* Qcorr */ + maxcorr_fx = (Word32) L_shl_o( corr_fx, Qcorr, &Overflow ); /* Qcorr */ #else - maxcorr_fx = (Word32)L_shl(corr_fx, Qcorr); /* Qcorr */ + maxcorr_fx = (Word32) L_shl( corr_fx, Qcorr ); /* Qcorr */ #endif - Qmaxcorr = Qcorr; - move16(); - } + Qmaxcorr = Qcorr; + move16(); + } } return fshift_fx; @@ -743,11 +741,11 @@ static Word16 DTFS_alignment_fine_new_fx(DTFS_STRUCTURE X1_fx, DTFS_STRUCTURE X2 /* NOTE: Frequency is normalized by 12800, i.e. 1=12800Hz */ /*===================================================================*/ static void LPCPowSpect_fx( - const Word16* freq, /* i : ERB frequencies */ - const Word16 Nf, /* i : Number of ERBs */ - const Word16* LPC, /* i : LPC coefficients */ - const Word16 Np, /* i : Number of LPCs */ - Word16* out /* o : LPC power spectrum */ + const Word16 *freq, /* i : ERB frequencies */ + const Word16 Nf, /* i : Number of ERBs */ + const Word16 *LPC, /* i : LPC coefficients */ + const Word16 Np, /* i : Number of LPCs */ + Word16 *out /* o : LPC power spectrum */ ) { Word16 i, k; @@ -755,137 +753,136 @@ static void LPCPowSpect_fx( Word16 t1, dt; /*Word16 t2; */ Word16 dh, dl; - Word32 Re, Im; /* Q27 */ + Word32 Re, Im; /* Q27 */ Word32 Ltemp, Lw; Word32 Lacc; Word16 tmp, exp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - FOR(k = 0; k < Nf; k++) + FOR( k = 0; k < Nf; k++ ) { - Re = L_add(0x8000000, 0); /* Re=1.0, Q27 */ - Im = L_deposit_l(0); - Lw = L_deposit_l(freq[k]);/* Q15 */ - FOR(i = 0; i < Np; i++) + Re = L_add( 0x8000000, 0 ); /* Re=1.0, Q27 */ + Im = L_deposit_l( 0 ); + Lw = L_deposit_l( freq[k] ); /* Q15 */ + FOR( i = 0; i < Np; i++ ) { - Ltemp = L_shl(Lw, 10); /* Ltemp in Q25 */ - w = extract_h(Ltemp); /* w in Q9 */ - dl = extract_l(Ltemp); /* dl has 6 bits left-over */ - w = s_and(w, 511); + Ltemp = L_shl( Lw, 10 ); /* Ltemp in Q25 */ + w = extract_h( Ltemp ); /* w in Q9 */ + dl = extract_l( Ltemp ); /* dl has 6 bits left-over */ + w = s_and( w, 511 ); t1 = cos_table[w]; /* t2=cos_table[s_and(add(w,1),511)]; */ /*dt=sub(t2,t1); */ /* dt=t2-t1, Q15 */ dt = cos_diff_table[w]; - IF(dl < 0) + IF( dl < 0 ) { - Ltemp = L_shl(L_add(65536, dl), 14);/* */ - Ltemp = Mult_32_16(Ltemp, dt); - Ltemp = L_shl(Ltemp, 1); + Ltemp = L_shl( L_add( 65536, dl ), 14 ); /* */ + Ltemp = Mult_32_16( Ltemp, dt ); + Ltemp = L_shl( Ltemp, 1 ); } ELSE { - Ltemp = (Word32)L_mult0(dt,dl); /* Ltemp in Q31 */ + Ltemp = (Word32) L_mult0( dt, dl ); /* Ltemp in Q31 */ } - t1 = add(t1, (Word16)L_shr(Ltemp, 16)); /* t1 is interpolated cos(w) */ - Ltemp = L_shr(L_mult(LPC[i], t1), 1); /* Ltemp in Q27 */ + t1 = add( t1, (Word16) L_shr( Ltemp, 16 ) ); /* t1 is interpolated cos(w) */ + Ltemp = L_shr( L_mult( LPC[i], t1 ), 1 ); /* Ltemp in Q27 */ #ifdef BASOP_NOGLOB - Re = L_add_o(Re, Ltemp, &Overflow); /* Re=1-sum(LPC[i]*cos(Lw)); */ - Ltemp = L_add_o(Lw, 0x6000, &Overflow); /* add 0.75, which is 3pi/2 to convert sin to cos */ - Ltemp = L_shl_o(Ltemp, 10, &Overflow); /* Q25 */ + Re = L_add_o( Re, Ltemp, &Overflow ); /* Re=1-sum(LPC[i]*cos(Lw)); */ + Ltemp = L_add_o( Lw, 0x6000, &Overflow ); /* add 0.75, which is 3pi/2 to convert sin to cos */ + Ltemp = L_shl_o( Ltemp, 10, &Overflow ); /* Q25 */ #else - Re = L_add(Re, Ltemp); /* Re=1-sum(LPC[i]*cos(Lw)); */ - Ltemp = L_add(Lw, 0x6000); /* add 0.75, which is 3pi/2 to convert sin to cos */ - Ltemp = L_shl(Ltemp, 10); /* Q25 */ + Re = L_add( Re, Ltemp ); /* Re=1-sum(LPC[i]*cos(Lw)); */ + Ltemp = L_add( Lw, 0x6000 ); /* add 0.75, which is 3pi/2 to convert sin to cos */ + Ltemp = L_shl( Ltemp, 10 ); /* Q25 */ #endif - w = extract_h(Ltemp); /* w is equivalent cos index */ - dl = extract_l(Ltemp); /* dl is 6 bit left-over for interpolation */ - w = s_and(w, 511); + w = extract_h( Ltemp ); /* w is equivalent cos index */ + dl = extract_l( Ltemp ); /* dl is 6 bit left-over for interpolation */ + w = s_and( w, 511 ); t1 = cos_table[w]; /*t2=cos_table[s_and(add(w,1),511)]; */ /*dt=sub(t2,t1); */ /* dt=t2-t1, Q15 */ dt = cos_diff_table[w]; - IF(dl < 0) + IF( dl < 0 ) { - Ltemp = L_shl(L_add(65536, dl), 14);/* */ - Ltemp = Mult_32_16(Ltemp, dt); - Ltemp = L_shl(Ltemp, 1); + Ltemp = L_shl( L_add( 65536, dl ), 14 ); /* */ + Ltemp = Mult_32_16( Ltemp, dt ); + Ltemp = L_shl( Ltemp, 1 ); } ELSE { - Ltemp = (Word32)L_mult0(dt,dl); /* Ltemp in Q31 */ + Ltemp = (Word32) L_mult0( dt, dl ); /* Ltemp in Q31 */ } - t1 = add(t1, (Word16)L_shr(Ltemp, 16)); /* t1 is interpolated cos(w) */ - Ltemp = L_shr(L_mult(LPC[i], t1), 1); /* Ltemp in Q27 */ + t1 = add( t1, (Word16) L_shr( Ltemp, 16 ) ); /* t1 is interpolated cos(w) */ + Ltemp = L_shr( L_mult( LPC[i], t1 ), 1 ); /* Ltemp in Q27 */ #ifdef BASOP_NOGLOB - Im = L_sub_o(Im, Ltemp, &Overflow); /* Im=sum(LPC[i]*sin(Lw)) */ - Lw = L_add_o(Lw, freq[k], &Overflow); /* Lw=(i+1)*freq[k] */ + Im = L_sub_o( Im, Ltemp, &Overflow ); /* Im=sum(LPC[i]*sin(Lw)) */ + Lw = L_add_o( Lw, freq[k], &Overflow ); /* Lw=(i+1)*freq[k] */ #else - Im = L_sub(Im, Ltemp); /* Im=sum(LPC[i]*sin(Lw)) */ - Lw = L_add(Lw, freq[k]); /* Lw=(i+1)*freq[k] */ + Im = L_sub( Im, Ltemp ); /* Im=sum(LPC[i]*sin(Lw)) */ + Lw = L_add( Lw, freq[k] ); /* Lw=(i+1)*freq[k] */ #endif } /* If necessary, we can block-normalize Re and Im to improve precision */ - dh = extract_h(Re); - dl = extract_l(Re); + dh = extract_h( Re ); + dl = extract_l( Re ); - IF(dl < 0) + IF( dl < 0 ) { - Ltemp = L_shl(L_add(65536, dl), 14);/* */ - Ltemp = Mult_32_16(Ltemp, dh); - Lacc = L_shl(Ltemp, 1); + Ltemp = L_shl( L_add( 65536, dl ), 14 ); /* */ + Ltemp = Mult_32_16( Ltemp, dh ); + Lacc = L_shl( Ltemp, 1 ); } ELSE - Lacc = L_mult0(dh, dl); + Lacc = L_mult0( dh, dl ); #ifdef BASOP_NOGLOB - Lacc = L_add_o(L_shr(Lacc, 15), L_shr(L_mult_o(dh, dh, &Overflow), 1), &Overflow); /* Lacc=Re*Re */ + Lacc = L_add_o( L_shr( Lacc, 15 ), L_shr( L_mult_o( dh, dh, &Overflow ), 1 ), &Overflow ); /* Lacc=Re*Re */ #else - Lacc = L_add(L_shr(Lacc, 15), L_shr(L_mult(dh, dh), 1)); /* Lacc=Re*Re */ + Lacc = L_add( L_shr( Lacc, 15 ), L_shr( L_mult( dh, dh ), 1 ) ); /* Lacc=Re*Re */ #endif - dh = extract_h(Im); - dl = extract_l(Im); + dh = extract_h( Im ); + dl = extract_l( Im ); - IF(dl < 0) + IF( dl < 0 ) { - Ltemp = L_shl(L_add(65536, dl), 14);/* */ - Ltemp = Mult_32_16(Ltemp, dh); - Ltemp = L_shl(Ltemp, 1); + Ltemp = L_shl( L_add( 65536, dl ), 14 ); /* */ + Ltemp = Mult_32_16( Ltemp, dh ); + Ltemp = L_shl( Ltemp, 1 ); } ELSE - Ltemp = (Word32)L_mult0(dh, dl); + Ltemp = (Word32) L_mult0( dh, dl ); - Lacc = L_add(Lacc, L_shr(Ltemp, 15)); - Lacc = L_add(Lacc, L_shr(L_mult(dh, dh), 1)); /* Lacc=Re^2+Im^2, Q22 */ + Lacc = L_add( Lacc, L_shr( Ltemp, 15 ) ); + Lacc = L_add( Lacc, L_shr( L_mult( dh, dh ), 1 ) ); /* Lacc=Re^2+Im^2, Q22 */ - exp = norm_l(Lacc); - tmp = round_fx(L_shl(Lacc, exp)); - exp = sub(sub(30, exp), 22); + exp = norm_l( Lacc ); + tmp = round_fx( L_shl( Lacc, exp ) ); + exp = sub( sub( 30, exp ), 22 ); /* tmp may potentially become negative, when Lacc is a very large value */ - IF(tmp > 0) + IF( tmp > 0 ) { - tmp = div_s(16384, tmp); /* 15+exp1 */ + tmp = div_s( 16384, tmp ); /* 15+exp1 */ } ELSE { tmp = 0; move16(); } - Ltemp = L_deposit_h(tmp); + Ltemp = L_deposit_h( tmp ); #ifdef BASOP_NOGLOB - out[k] = round_fx_o(L_shl_o(Ltemp, negate(add(exp, 8)), &Overflow), &Overflow); + out[k] = round_fx_o( L_shl_o( Ltemp, negate( add( exp, 8 ) ), &Overflow ), &Overflow ); #else - out[k] = round_fx(L_shl(Ltemp, negate(add(exp, 8)))); + out[k] = round_fx( L_shl( Ltemp, negate( add( exp, 8 ) ) ) ); #endif /* out[k] = shl(tmp,-exp-8); in Q7 */ - } return; } @@ -914,62 +911,61 @@ static void LPCPowSpect_fx( /* CALLED FROM : TX */ /*===================================================================*/ static void erb_diff_fx( - const Word16* prev_erb, /* i : previous ERB */ - Word16 pl, /* i : previous lag */ - const Word16* curr_erb, /* i : current ERB */ - Word16 l, /* i : current lag */ - const Word16* curr_lsp, /* i : current LSP coefficients */ - Word16* index, /* 0 : ERB index */ - Word16 num_erb /* i : Number of ERBs */ + const Word16 *prev_erb, /* i : previous ERB */ + Word16 pl, /* i : previous lag */ + const Word16 *curr_erb, /* i : current ERB */ + Word16 l, /* i : current lag */ + const Word16 *curr_lsp, /* i : current LSP coefficients */ + Word16 *index, /* 0 : ERB index */ + Word16 num_erb /* i : Number of ERBs */ ) { Word16 i; Word16 pslot[NUM_ERB_WB], cslot[NUM_ERB_WB]; Word16 tmp, t_prev_erb[NUM_ERB_WB], LPC[M + 1], mfreq[NUM_ERB_WB], PowSpect[NUM_ERB_WB], dif_erb[NUM_ERB_WB]; - const Word16* AmpCB1_fx = NULL; + const Word16 *AmpCB1_fx = NULL; - IF(EQ_16(num_erb, NUM_ERB_NB)) + IF( EQ_16( num_erb, NUM_ERB_NB ) ) { AmpCB1_fx = AmpCB1_NB_fx; move16(); } - ELSE IF(EQ_16(num_erb, NUM_ERB_WB)) + ELSE IF( EQ_16( num_erb, NUM_ERB_WB ) ) { AmpCB1_fx = AmpCB1_WB_fx; move16(); - } - erb_slot_fx(l, cslot, mfreq, num_erb);/* cslot in Qo and mfreq in Q15 */ - erb_slot_fx(pl, pslot, t_prev_erb, num_erb); + erb_slot_fx( l, cslot, mfreq, num_erb ); /* cslot in Qo and mfreq in Q15 */ + erb_slot_fx( pl, pslot, t_prev_erb, num_erb ); - FOR(i = 0; i < M + 1; i++) + FOR( i = 0; i < M + 1; i++ ) { - LPC[i] = mult_r(curr_lsp[i], pwf78_fx[i]); + LPC[i] = mult_r( curr_lsp[i], pwf78_fx[i] ); move16(); } - LPCPowSpect_fx(mfreq, num_erb, LPC, M + 1, PowSpect);/* Powspect in Q7 */ + LPCPowSpect_fx( mfreq, num_erb, LPC, M + 1, PowSpect ); /* Powspect in Q7 */ - FOR(i = 0; i < num_erb; i++) + FOR( i = 0; i < num_erb; i++ ) { - if (cslot[i] == 0) + if ( cslot[i] == 0 ) { PowSpect[i] = 0; move16(); } } - FOR(i = 0; i < num_erb; i++) + FOR( i = 0; i < num_erb; i++ ) { t_prev_erb[i] = prev_erb[i]; move16(); } - IF(GT_16(pl, l)) + IF( GT_16( pl, l ) ) { tmp = t_prev_erb[0]; move16(); - FOR(i = 0; i < num_erb; i++) + FOR( i = 0; i < num_erb; i++ ) { - IF(pslot[i] != 0) + IF( pslot[i] != 0 ) { tmp = t_prev_erb[i]; move16(); @@ -981,14 +977,14 @@ static void erb_diff_fx( } } } - ELSE IF(GT_16(l, pl)) + ELSE IF( GT_16( l, pl ) ) { tmp = t_prev_erb[num_erb - 1]; move16(); - FOR(i = sub(num_erb, 1); i >= 0; i--) + FOR( i = sub( num_erb, 1 ); i >= 0; i-- ) { - IF(pslot[i] != 0) + IF( pslot[i] != 0 ) { tmp = t_prev_erb[i]; move16(); @@ -1000,32 +996,31 @@ static void erb_diff_fx( } } } - FOR(i = 0; i < num_erb; i++) + FOR( i = 0; i < num_erb; i++ ) { - dif_erb[i] = sub(curr_erb[i], t_prev_erb[i]); + dif_erb[i] = sub( curr_erb[i], t_prev_erb[i] ); move16(); } /* First Band Amplitude Search */ - index[0] = erb_diff_search_fx(t_prev_erb, curr_erb, dif_erb, - PowSpect, AmpCB1_fx, - ERB_CBSIZE1, 10, 1); + index[0] = erb_diff_search_fx( t_prev_erb, curr_erb, dif_erb, + PowSpect, AmpCB1_fx, + ERB_CBSIZE1, 10, 1 ); move16(); - IF(EQ_16(num_erb, NUM_ERB_NB)) + IF( EQ_16( num_erb, NUM_ERB_NB ) ) { /* Second Band Amplitude Search */ - index[1] = erb_diff_search_fx(t_prev_erb, curr_erb, dif_erb, - PowSpect, AmpCB2_NB_fx, - ERB_CBSIZE2, 9, 11); + index[1] = erb_diff_search_fx( t_prev_erb, curr_erb, dif_erb, + PowSpect, AmpCB2_NB_fx, + ERB_CBSIZE2, 9, 11 ); move16(); } - ELSE IF(EQ_16(num_erb, NUM_ERB_WB)) + ELSE IF( EQ_16( num_erb, NUM_ERB_WB ) ) { /* Second Band Amplitude Search */ - index[1] = erb_diff_search_fx(t_prev_erb, curr_erb, dif_erb, - PowSpect, AmpCB2_WB_fx, - ERB_CBSIZE2, 11, 11); + index[1] = erb_diff_search_fx( t_prev_erb, curr_erb, dif_erb, + PowSpect, AmpCB2_WB_fx, + ERB_CBSIZE2, 11, 11 ); move16(); } - } diff --git a/lib_enc/pre_proc.c b/lib_enc/pre_proc.c index 1725207b7..065fb2a45 100644 --- a/lib_enc/pre_proc.c +++ b/lib_enc/pre_proc.c @@ -50,14 +50,14 @@ *--------------------------------------------------------------------*/ void pre_proc( - Encoder_State *st, /* i/o: encoder state structure */ - const int16_t input_frame, /* i : frame length */ - float old_inp_12k8[], /* i/o: buffer of old input signal */ - float old_inp_16k[], /* i/o: buffer of old input signal @ 16kHz */ - float **inp, /* o : ptr. to inp. signal in the current frame*/ - float fr_bands[2 * NB_BANDS], /* i : energy in frequency bands */ - float *ener, /* o : residual energy from Levinson-Durbin */ - int16_t pitch_orig[3], /* o : open-loop pitch values for quantization */ + Encoder_State *st, /* i/o: encoder state structure */ + const int16_t input_frame, /* i : frame length */ + float old_inp_12k8[], /* i/o: buffer of old input signal */ + float old_inp_16k[], /* i/o: buffer of old input signal @ 16kHz */ + float **inp, /* o : ptr. to inp. signal in the current frame*/ + float fr_bands[2 * NB_BANDS], /* i : energy in frequency bands */ + float *ener, /* o : residual energy from Levinson-Durbin */ + int16_t pitch_orig[3], /* o : open-loop pitch values for quantization */ float A[NB_SUBFR16k * ( M + 1 )], /* i/o: A(z) unquantized for the 4 subframes */ float Aw[NB_SUBFR16k * ( M + 1 )], /* i/o: weighted A(z) unquantized for subframes */ float epsP[M + 1], /* i/o: LP prediction errors */ @@ -361,7 +361,7 @@ void pre_proc( * UC and VC frame selection *-----------------------------------------------------------------*/ - find_tilt( fr_bands, st->hNoiseEst->bckr, ee, st->pitch, st->voicing, lf_E, corr_shift, st->input_bwidth, st->max_band, hp_E, st->codec_mode, &( st->bckr_tilt_lt_flt), st->Opt_SC_VBR ); + find_tilt( fr_bands, st->hNoiseEst->bckr, ee, st->pitch, st->voicing, lf_E, corr_shift, st->input_bwidth, st->max_band, hp_E, st->codec_mode, &( st->bckr_tilt_lt_flt ), st->Opt_SC_VBR ); st->coder_type = find_uv( st, pitch_fr, voicing_fr, inp_12k8, ee, NULL, corr_shift, relE, Etot, hp_E, &flag_spitch, last_core_orig, NULL ); diff --git a/lib_enc/pre_proc_fx.c b/lib_enc/pre_proc_fx.c index c4991420c..f76dd3e08 100644 --- a/lib_enc/pre_proc_fx.c +++ b/lib_enc/pre_proc_fx.c @@ -8,10 +8,10 @@ #include "rom_com_fx.h" //#include "prot_fx.h" #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ -#include "basop_util.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ +#include "basop_util.h" /* Function prototypes */ /*-------------------------------------------------------------------* * pre_proc() @@ -21,69 +21,68 @@ *--------------------------------------------------------------------*/ void pre_proc_fx( - Encoder_State* st, /* i/o: encoder state structure */ - const Word16 input_frame, /* i : frame length */ - Word16 old_inp_12k8[], /* i/o: buffer of old input signal */ - Word16 old_inp_16k[], /* i/o: buffer of old input signal @ 16kHz */ - Word16** inp, /* o : ptr. to inp. signal in the current frame */ - Word32 fr_bands[2 * NB_BANDS], /* o : energy in frequency bands */ - Word16* Etot, /* o : total energy */ - Word32* ener, /* o : residual energy from Levinson-Durbin */ + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 input_frame, /* i : frame length */ + Word16 old_inp_12k8[], /* i/o: buffer of old input signal */ + Word16 old_inp_16k[], /* i/o: buffer of old input signal @ 16kHz */ + Word16 **inp, /* o : ptr. to inp. signal in the current frame */ + Word32 fr_bands[2 * NB_BANDS], /* o : energy in frequency bands */ + Word16 *Etot, /* o : total energy */ + Word32 *ener, /* o : residual energy from Levinson-Durbin */ #ifndef FIX_I4_OL_PITCH - Word16 pitch_orig[3], /* o : open-loop pitch values for quantization */ + Word16 pitch_orig[3], /* o : open-loop pitch values for quantization */ #endif - Word16 A[NB_SUBFR16k * (M + 1)], /* o : A(z) unquantized for the 4 subframes */ - Word16 Aw[NB_SUBFR16k * (M + 1)], /* o : weighted A(z) unquantized for subframes */ - Word16 epsP_h[M + 1], /* o : LP prediction errors */ - Word16 epsP_l[M + 1], /* o : LP prediction errors */ - Word32 epsP[M + 1], /* o : LP prediction errors */ - Word16 lsp_new[M], /* o : LSPs at the end of the frame */ - Word16 lsp_mid[M], /* o : LSPs in the middle of the frame */ - Word16* vad_hover_flag, - Word16* attack_flag, /* o : flag signalling attack encoded by AC mode (GSC) */ - Word16* new_inp_resamp16k, /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ - Word16* Voicing_flag, /* o : voicing flag for HQ FEC */ + Word16 A[NB_SUBFR16k * ( M + 1 )], /* o : A(z) unquantized for the 4 subframes */ + Word16 Aw[NB_SUBFR16k * ( M + 1 )], /* o : weighted A(z) unquantized for subframes */ + Word16 epsP_h[M + 1], /* o : LP prediction errors */ + Word16 epsP_l[M + 1], /* o : LP prediction errors */ + Word32 epsP[M + 1], /* o : LP prediction errors */ + Word16 lsp_new[M], /* o : LSPs at the end of the frame */ + Word16 lsp_mid[M], /* o : LSPs in the middle of the frame */ + Word16 *vad_hover_flag, + Word16 *attack_flag, /* o : flag signalling attack encoded by AC mode (GSC) */ + Word16 *new_inp_resamp16k, /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ + Word16 *Voicing_flag, /* o : voicing flag for HQ FEC */ Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o : cldfb real buffer */ Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o : cldfb imag buffer */ - CLDFB_SCALE_FACTOR* cldfbScale, /* o : cldfb scale */ - Word16* old_exc, /* i/o: static excitation memory */ - Word16* hq_core_type, /* o : HQ core type */ - Word16* Q_new, - Word16* shift, - Word16* Q_r -) + CLDFB_SCALE_FACTOR *cldfbScale, /* o : cldfb scale */ + Word16 *old_exc, /* i/o: static excitation memory */ + Word16 *hq_core_type, /* o : HQ core type */ + Word16 *Q_new, + Word16 *shift, + Word16 *Q_r ) { Word16 delay; - const Word16* signal_in; + const Word16 *signal_in; Word16 i; - Word16 *inp_12k8, *new_inp_12k8, *inp_16k, *new_inp_16k; /* pointers to current frame and new data */ - Word16 old_wsp[L_WSP], *wsp; /* weighted input signal buffer */ - Word16 pitch_fr[NB_SUBFR]; /* fractional pitch values */ - Word16 voicing_fr[NB_SUBFR]; /* fractional pitch gains */ - Word32 lf_E[2*VOIC_BINS]; /* per bin spectrum energy in lf */ - Word32 tmpN[NB_BANDS]; /* Temporary noise update */ - Word32 tmpE[NB_BANDS]; /* Temporary averaged energy of 2 sf. */ - Word32 ee[2]; /* Spectral tilt */ - Word16 corr_shift; /* correlation shift */ - Word16 relE; /* frame relative energy */ - Word16 loc_harm; /* harmonicity flag */ - Word16 cor_map_sum, sp_div; /* speech/music clasif. parameters */ + Word16 *inp_12k8, *new_inp_12k8, *inp_16k, *new_inp_16k; /* pointers to current frame and new data */ + Word16 old_wsp[L_WSP], *wsp; /* weighted input signal buffer */ + Word16 pitch_fr[NB_SUBFR]; /* fractional pitch values */ + Word16 voicing_fr[NB_SUBFR]; /* fractional pitch gains */ + Word32 lf_E[2 * VOIC_BINS]; /* per bin spectrum energy in lf */ + Word32 tmpN[NB_BANDS]; /* Temporary noise update */ + Word32 tmpE[NB_BANDS]; /* Temporary averaged energy of 2 sf. */ + Word32 ee[2]; /* Spectral tilt */ + Word16 corr_shift; /* correlation shift */ + Word16 relE; /* frame relative energy */ + Word16 loc_harm; /* harmonicity flag */ + Word16 cor_map_sum, sp_div; /* speech/music clasif. parameters */ Word32 PS[128]; - Word16 L_look; /* length of look-ahead */ + Word16 L_look; /* length of look-ahead */ Word16 Q_sp_div, Q_esp; - Word16 localVAD_HE_SAD; /* HE SAD parameters */ - Word16 snr_sum_he; /* HE SAD parameters */ + Word16 localVAD_HE_SAD; /* HE SAD parameters */ + Word16 snr_sum_he; /* HE SAD parameters */ Word16 vad_flag_cldfb; Word16 vad_flag_dtx; Word16 old_cor; - Word32 hp_E[2]; /* Energy in HF */ - Word16 noisy_speech_HO, clean_speech_HO, NB_speech_HO; /* SC-VBR HO flags */ - Word16 non_staX; /* unbound non-stationarity for sp/mus clas. */ + Word32 hp_E[2]; /* Energy in HF */ + Word16 noisy_speech_HO, clean_speech_HO, NB_speech_HO; /* SC-VBR HO flags */ + Word16 non_staX; /* unbound non-stationarity for sp/mus clas. */ Word32 sr_core_tmp; Word16 L_frame_tmp; Word16 Q_exp, Q_wsp_exp, Q_new_16k; @@ -105,21 +104,22 @@ void pre_proc_fx( Word16 sf_energySum[CLDFB_NO_CHANNELS_MAX]; Word32 L_tmp; UWord16 lsb; - Word16 fft_buff[2*L_FFT]; + Word16 fft_buff[2 * L_FFT]; Word16 sp_floor; Word16 freqTable_local[2] = { 20, 40 }; Word16 last_core_orig; Word16 headroom; - Word16 cldfb_addition = 0; move16(); + Word16 cldfb_addition = 0; + move16(); Word16 old_pitch1; Word16 clas_mod; - SC_VBR_ENC_HANDLE hSC_VBR = st->hSC_VBR; + SC_VBR_ENC_HANDLE hSC_VBR = st->hSC_VBR; GSC_ENC_HANDLE hGSCEnc = st->hGSCEnc; - NOISE_EST_HANDLE hNoiseEst = st->hNoiseEst; + NOISE_EST_HANDLE hNoiseEst = st->hNoiseEst; VAD_HANDLE hVAD = st->hVAD; - TD_CNG_ENC_HANDLE hTdCngEnc = st->hTdCngEnc; + TD_CNG_ENC_HANDLE hTdCngEnc = st->hTdCngEnc; - DTX_ENC_HANDLE hDtxEnc = st->hDtxEnc; + DTX_ENC_HANDLE hDtxEnc = st->hDtxEnc; TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; TD_BWE_ENC_HANDLE hBWE_TD = st->hBWE_TD; RF_ENC_HANDLE hRF = st->hRF; @@ -166,7 +166,7 @@ void pre_proc_fx( *attack_flag = 0; move16(); - IF (hSC_VBR != NULL) + IF( hSC_VBR != NULL ) { hSC_VBR->bump_up = 0; move16(); @@ -178,17 +178,17 @@ void pre_proc_fx( move16(); } L_look = L_LOOK_12k8; - move16(); /* lookahead at 12.8kHz */ + move16(); /* lookahead at 12.8kHz */ - new_inp_12k8 = old_inp_12k8 + L_INP_MEM; /* pointer to new samples of the input signal in 12.8kHz core */ - inp_12k8 = new_inp_12k8 - L_look; /* pointer to the current frame of input signal in 12.8kHz core */ + new_inp_12k8 = old_inp_12k8 + L_INP_MEM; /* pointer to new samples of the input signal in 12.8kHz core */ + inp_12k8 = new_inp_12k8 - L_look; /* pointer to the current frame of input signal in 12.8kHz core */ Copy( st->old_inp_12k8_fx, old_inp_12k8, L_INP_MEM ); Copy( st->old_wsp_fx, old_wsp, L_WSP_MEM ); - wsp = old_wsp + L_WSP_MEM; /* pointer to the current frame of weighted signal in 12.8kHz core */ + wsp = old_wsp + L_WSP_MEM; /* pointer to the current frame of weighted signal in 12.8kHz core */ old_cor = st->old_corr_fx; - move16(); /* save old_cor for speech/music classifier */ + move16(); /* save old_cor for speech/music classifier */ st->rf_mode = st->Opt_RF_ON; move16(); @@ -205,16 +205,16 @@ void pre_proc_fx( st->prevEnergyHF_fx = st->currEnergyHF_fx; tmp_e = st->currEnergyHF_e_fx; - analysisCldfbEncoder_fx( st, signal_in, realBuffer, imagBuffer, realBuffer16, imagBuffer16, enerBuffer, &enerBuffer_exp, cldfbScale); + analysisCldfbEncoder_fx( st, signal_in, realBuffer, imagBuffer, realBuffer16, imagBuffer16, enerBuffer, &enerBuffer_exp, cldfbScale ); cldfbScale->hb_scale = cldfbScale->lb_scale; /*----------------------------------------------------------------* * Change the sampling frequency to 12.8 kHz *----------------------------------------------------------------*/ - modify_Fs_fx( signal_in, input_frame, st->input_Fs, new_inp_12k8, INT_FS_12k8, st->mem_decim_fx, (const Word16)(EQ_16(st->max_bwidth,NB))); - Copy( new_inp_12k8, st->buf_speech_enc+L_FRAME32k, L_FRAME ); - Scale_sig( st->buf_speech_enc+L_FRAME32k, L_FRAME, 1 ); + modify_Fs_fx( signal_in, input_frame, st->input_Fs, new_inp_12k8, INT_FS_12k8, st->mem_decim_fx, ( const Word16 )( EQ_16( st->max_bwidth, NB ) ) ); + Copy( new_inp_12k8, st->buf_speech_enc + L_FRAME32k, L_FRAME ); + Scale_sig( st->buf_speech_enc + L_FRAME32k, L_FRAME, 1 ); /*------------------------------------------------------------------* * Perform fixed preemphasis (12.8 kHz signal) through 1 - g*z^-1 *-----------------------------------------------------------------*/ @@ -228,15 +228,15 @@ void pre_proc_fx( test(); /* reserve an extra bit of headroom in case of NB coding and if there is a chance of energy above 4 kHz */ /* st->bwidth refers to the coded bandwidth of the previous frame */ - if( ((EQ_16(st->bwidth, NB))||(EQ_16(st->max_bwidth,NB)))&&(GT_32(st->input_Fs,8000))) + if ( ( ( EQ_16( st->bwidth, NB ) ) || ( EQ_16( st->max_bwidth, NB ) ) ) && ( GT_32( st->input_Fs, 8000 ) ) ) { - headroom = add(headroom, 1); + headroom = add( headroom, 1 ); } Preemph_scaled( new_inp_12k8, Q_new, &st->mem_preemph_fx, st->Q_max, PREEMPH_FAC, 0, headroom, L_Q_MEM, L_FRAME, st->last_coder_type, 1 ); - Q_exp = sub(*Q_new, st->Q_old); - st->prev_Q_old=st->Q_old; + Q_exp = sub( *Q_new, st->Q_old ); + st->prev_Q_old = st->Q_old; move16(); st->Q_old = *Q_new; move16(); @@ -245,41 +245,40 @@ void pre_proc_fx( * Scaling of memories *-----------------------------------------------------------------*/ - Le_min_scaled = Scale_mem_pre_proc( st->ini_frame, Q_exp, Q_new, old_inp_12k8, &(st->mem_wsp_fx), hNoiseEst->enrO_fx, hNoiseEst->bckr_fx, - hNoiseEst->ave_enr_fx, hNoiseEst->ave_enr2_fx, hNoiseEst->fr_bands1_fx, hNoiseEst->fr_bands2_fx, st->Bin_E_old_fx ); + Le_min_scaled = Scale_mem_pre_proc( st->ini_frame, Q_exp, Q_new, old_inp_12k8, &( st->mem_wsp_fx ), hNoiseEst->enrO_fx, hNoiseEst->bckr_fx, + hNoiseEst->ave_enr_fx, hNoiseEst->ave_enr2_fx, hNoiseEst->fr_bands1_fx, hNoiseEst->fr_bands2_fx, st->Bin_E_old_fx ); /*-------------------------------------------------------------------------* * Spectral analysis *--------------------------------------------------------------------------*/ - analy_sp_fx(-1, + analy_sp_fx( -1, #ifdef IVAS_CODE_CPE - NULL, + NULL, #endif - st->input_Fs, inp_12k8, *Q_new, fr_bands, lf_E, Etot, st->min_band, st->max_band, Le_min_scaled, Scale_fac, st->Bin_E_fx, st->Bin_E_old_fx, - PS, st->lgBin_E_fx, st->band_energies, fft_buff ); + st->input_Fs, inp_12k8, *Q_new, fr_bands, lf_E, Etot, st->min_band, st->max_band, Le_min_scaled, Scale_fac, st->Bin_E_fx, st->Bin_E_old_fx, + PS, st->lgBin_E_fx, st->band_energies, fft_buff ); - st->band_energies_exp = sub(sub(WORD32_BITS-1,*Q_new),QSCALE); + st->band_energies_exp = sub( sub( WORD32_BITS - 1, *Q_new ), QSCALE ); move16(); /*----------------------------------------------------------------* * SAD (1-signal, 0-noise) *----------------------------------------------------------------*/ - noise_est_pre_fx( *Etot, st->ini_frame, hNoiseEst, 0, EVS_MONO, EVS_MONO); + noise_est_pre_fx( *Etot, st->ini_frame, hNoiseEst, 0, EVS_MONO, EVS_MONO ); st->vad_flag = wb_vad_fx( st, fr_bands, &noisy_speech_HO, &clean_speech_HO, &NB_speech_HO, - &snr_sum_he, &localVAD_HE_SAD, &(st->flag_noisy_speech_snr_fx), *Q_new - , hVAD, hNoiseEst, st->lp_speech_fx, st->lp_noise_fx); + &snr_sum_he, &localVAD_HE_SAD, &( st->flag_noisy_speech_snr_fx ), *Q_new, hVAD, hNoiseEst, st->lp_speech_fx, st->lp_noise_fx ); - vad_flag_cldfb = vad_proc_fx(&(st->vad_st), realBuffer, imagBuffer, cldfbScale->lb_scale, &cldfb_addition, - enerBuffer, enerBuffer_exp, st->cldfbAnaEnc->no_channels, st->vad_flag); + vad_flag_cldfb = vad_proc_fx( &( st->vad_st ), realBuffer, imagBuffer, cldfbScale->lb_scale, &cldfb_addition, + enerBuffer, enerBuffer_exp, st->cldfbAnaEnc->no_channels, st->vad_flag ); - IF ( LT_16( st->Pos_relE_cnt, 20) ) /* Ensure the level is high enough and cldfb decision is reliable */ + IF( LT_16( st->Pos_relE_cnt, 20 ) ) /* Ensure the level is high enough and cldfb decision is reliable */ { /* Combine decisions from SADS */ test(); - IF (EQ_16(st->vad_flag, 1) && vad_flag_cldfb == 0) + IF( EQ_16( st->vad_flag, 1 ) && vad_flag_cldfb == 0 ) { st->localVAD = 0; move16(); @@ -290,19 +289,19 @@ void pre_proc_fx( } /* apply DTX hangover for CNG analysis */ - vad_flag_dtx = dtx_hangover_addition_fx( st, st->vad_flag, sub(st->lp_speech_fx,st->lp_noise_fx), cldfb_addition, vad_hover_flag, hVAD, hNoiseEst ); + vad_flag_dtx = dtx_hangover_addition_fx( st, st->vad_flag, sub( st->lp_speech_fx, st->lp_noise_fx ), cldfb_addition, vad_hover_flag, hVAD, hNoiseEst ); /*----------------------------------------------------------------* * NB/WB/SWB/FB bandwidth detector *----------------------------------------------------------------*/ - FOR( i=0; i< CLDFB_NO_CHANNELS_MAX; i++ ) + FOR( i = 0; i < CLDFB_NO_CHANNELS_MAX; i++ ) { sf_energySum[i] = enerBuffer_exp; move16(); } - bw_detect_fx( st, signal_in, NULL, enerBuffer, sf_energySum, MONO_FORMAT, 0); + bw_detect_fx( st, signal_in, NULL, enerBuffer, sf_energySum, MONO_FORMAT, 0 ); /*----------------------------------------------------------------* * Noise energy down-ward update and total noise energy estimation @@ -310,23 +309,23 @@ void pre_proc_fx( * Correlation correction as a function of total noise level *----------------------------------------------------------------*/ - noise_est_down_fx( fr_bands, hNoiseEst->bckr_fx, tmpN, tmpE, st->min_band, st->max_band, &hNoiseEst->totalNoise_fx, - *Etot, &hNoiseEst->Etot_last_fx, &hNoiseEst->Etot_v_h2_fx, *Q_new , Le_min_scaled ); + noise_est_down_fx( fr_bands, hNoiseEst->bckr_fx, tmpN, tmpE, st->min_band, st->max_band, &hNoiseEst->totalNoise_fx, + *Etot, &hNoiseEst->Etot_last_fx, &hNoiseEst->Etot_v_h2_fx, *Q_new, Le_min_scaled ); - relE = sub(*Etot, st->lp_speech_fx); /* Q8 */ /* relE = *Etot - st->lp_speech;*/ + relE = sub( *Etot, st->lp_speech_fx ); /* Q8 */ /* relE = *Etot - st->lp_speech;*/ test(); - IF ( GT_16(relE, 384) ) /*relE > 1.5 */ + IF( GT_16( relE, 384 ) ) /*relE > 1.5 */ { st->Pos_relE_cnt = 0; move16(); } - ELSE IF (relE < 0 && EQ_16(st->vad_flag, 1)) + ELSE IF( relE < 0 && EQ_16( st->vad_flag, 1 ) ) { - st->Pos_relE_cnt = add(st->Pos_relE_cnt, 1); + st->Pos_relE_cnt = add( st->Pos_relE_cnt, 1 ); } - corr_shift = correlation_shift_fx(hNoiseEst->totalNoise_fx ); + corr_shift = correlation_shift_fx( hNoiseEst->totalNoise_fx ); /*----------------------------------------------------------------* * FD-CNG Noise Estimator @@ -339,18 +338,18 @@ void pre_proc_fx( * Select SID or FRAME_NO_DATA frame if DTX enabled *-----------------------------------------------------------------*/ - dtx_fx(st, vad_flag_dtx, inp_12k8, *Q_new); + dtx_fx( st, vad_flag_dtx, inp_12k8, *Q_new ); /*----------------------------------------------------------------* * Adjust FD-CNG Noise Estimator *----------------------------------------------------------------*/ test(); - IF( (NE_32(st->last_total_brate,st->total_brate))||(NE_16(st->last_bwidth,st->bwidth))) + IF( ( NE_32( st->last_total_brate, st->total_brate ) ) || ( NE_16( st->last_bwidth, st->bwidth ) ) ) { L_tmp = st->total_brate; move32(); test(); - if( st->rf_mode && EQ_32(st->total_brate,ACELP_13k20)) + if ( st->rf_mode && EQ_32( st->total_brate, ACELP_13k20 ) ) { L_tmp = ACELP_9k60; move32(); @@ -358,38 +357,38 @@ void pre_proc_fx( configureFdCngEnc_fx( st->hFdCngEnc, st->bwidth, L_tmp ); } test(); - IF ( st->hFdCngEnc!=NULL && st->Opt_DTX_ON ) + IF( st->hFdCngEnc != NULL && st->Opt_DTX_ON ) { AdjustFirstSID_fx( st->hFdCngEnc->hFdCngCom->npart, st->hFdCngEnc->msPeriodog_fx, st->hFdCngEnc->msPeriodog_fx_exp, st->hFdCngEnc->energy_ho_fx, - &st->hFdCngEnc->energy_ho_fx_exp,st->hFdCngEnc->msNoiseEst_fx, &st->hFdCngEnc->msNoiseEst_fx_exp, st->hFdCngEnc->msNoiseEst_old_fx, - &st->hFdCngEnc->msNoiseEst_old_fx_exp, &(st->hFdCngEnc->hFdCngCom->active_frame_counter), st ); + &st->hFdCngEnc->energy_ho_fx_exp, st->hFdCngEnc->msNoiseEst_fx, &st->hFdCngEnc->msNoiseEst_fx_exp, st->hFdCngEnc->msNoiseEst_old_fx, + &st->hFdCngEnc->msNoiseEst_old_fx_exp, &( st->hFdCngEnc->hFdCngCom->active_frame_counter ), st ); } /*----------------------------------------------------------------* - * Reconfigure MODE2 - *----------------------------------------------------------------*/ + * Reconfigure MODE2 + *----------------------------------------------------------------*/ - IF ( EQ_16(st->codec_mode,MODE2)) + IF( EQ_16( st->codec_mode, MODE2 ) ) { - SetModeIndex_fx( st, st->last_total_brate, EVS_MONO, 0, *shift); + SetModeIndex_fx( st, st->last_total_brate, EVS_MONO, 0, *shift ); } calcLoEnvCheckCorrHiLo_Fix( st->cldfbAnaEnc->no_col, freqTable_local, st->hTECEnc->loBuffer, st->hTECEnc->loTempEnv, - st->hTECEnc->loTempEnv_ns, st->hTECEnc->hiTempEnv, &(st->hTECEnc->corrFlag) ); + st->hTECEnc->loTempEnv_ns, st->hTECEnc->hiTempEnv, &( st->hTECEnc->corrFlag ) ); /*---------------------------------------------------------------* * Time-domain transient detector *---------------------------------------------------------------*/ /* Adjust prevEnergyHF and currEnergyHF to same exponent */ - i = sub(st->currEnergyHF_e_fx, tmp_e); + i = sub( st->currEnergyHF_e_fx, tmp_e ); /* If i > 0: currEnergyHF is higher => shr prevEnergyHF, exponent remains as is */ - st->prevEnergyHF_fx = L_shr(st->prevEnergyHF_fx, s_max(0, i)); + st->prevEnergyHF_fx = L_shr( st->prevEnergyHF_fx, s_max( 0, i ) ); move32(); /* If i < 0: currEnergyHF is lower => shr currEnergyHF, exponent changes to previous */ - st->currEnergyHF_fx = L_shl(st->currEnergyHF_fx, s_min(0, i)); + st->currEnergyHF_fx = L_shl( st->currEnergyHF_fx, s_min( 0, i ) ); move32(); if ( i < 0 ) @@ -401,7 +400,7 @@ void pre_proc_fx( test(); IF( st->tcx10Enabled || st->tcx20Enabled ) { - RunTransientDetection_fx( signal_in, input_frame, &st->transientDetection); + RunTransientDetection_fx( signal_in, input_frame, &st->transientDetection ); currFlatness = GetTCXAvgTemporalFlatnessMeasure_fx( &st->transientDetection, NSUBBLOCKS, 0 ); } @@ -418,9 +417,9 @@ void pre_proc_fx( alw_voicing[1] = st->voicing_fx[2]; move16(); - analy_lp_fx( inp_12k8, L_FRAME, L_look, ener, A, epsP_h, epsP_l, lsp_new, lsp_mid, st->lsp_old1_fx, alw_pitch_lag_12k8, alw_voicing, INT_FS_12k8, -1/*IVAS_CODE !! LowRateFlag*/,*Q_new, Q_r ); + analy_lp_fx( inp_12k8, L_FRAME, L_look, ener, A, epsP_h, epsP_l, lsp_new, lsp_mid, st->lsp_old1_fx, alw_pitch_lag_12k8, alw_voicing, INT_FS_12k8, -1 /*IVAS_CODE !! LowRateFlag*/, *Q_new, Q_r ); - lsp2lsf_fx( lsp_new, lsf_new, M, INT_FS_12k8); + lsp2lsf_fx( lsp_new, lsf_new, M, INT_FS_12k8 ); stab_fac = lsf_stab_fx( lsf_new, st->lsf_old1_fx, 0, L_FRAME ); Copy( lsf_new, st->lsf_old1_fx, M ); @@ -434,14 +433,14 @@ void pre_proc_fx( Q_wsp_exp = Q_exp; move16(); - Scale_wsp( wsp, &(st->old_wsp_max), shift, &Q_wsp_exp, &(st->old_wsp_shift), st->old_wsp2_fx, - st->mem_decim2_fx, old_wsp, add(L_FRAME, L_look) ); - shift_exp=sub(Q_wsp_exp, Q_exp); + Scale_wsp( wsp, &( st->old_wsp_max ), shift, &Q_wsp_exp, &( st->old_wsp_shift ), st->old_wsp2_fx, + st->mem_decim2_fx, old_wsp, add( L_FRAME, L_look ) ); + shift_exp = sub( Q_wsp_exp, Q_exp ); IF( st->vad_flag == 0 ) { /* reset the OL pitch tracker memories during inactive frames */ - pitch_ol_init_fx( &st->old_thres_fx, &st->old_pitch, &st->delta_pit, &st->old_corr_fx) ; + pitch_ol_init_fx( &st->old_thres_fx, &st->old_pitch, &st->delta_pit, &st->old_corr_fx ); } old_pitch1 = st->pitch_fx[1]; @@ -456,16 +455,16 @@ void pre_proc_fx( /* Detection of very short stable st->pitch_fx period (MODE1 bit-rates) */ StableHighPitchDetect_fx( &flag_spitch, st->pitch_fx, st->voicing_fx, wsp, st->localVAD, &st->voicing_sm_fx, &st->voicing0_sm_fx, - &st->LF_EnergyRatio_sm_fx, &st->predecision_flag, &st->diff_sm_fx, &st->energy_sm_fx,*Q_new,st->lgBin_E_fx); + &st->LF_EnergyRatio_sm_fx, &st->predecision_flag, &st->diff_sm_fx, &st->energy_sm_fx, *Q_new, st->lgBin_E_fx ); /* 1/4 pitch precision improvement */ - IF( LE_32(st->total_brate,ACELP_24k40)) + IF( LE_32( st->total_brate, ACELP_24k40 ) ) { /* 1/4 pitch precision improvement */ pitch_ol2_fx( PIT_MIN_EXTEND, st->pitch_fx[0], &pitch_fr[0], &voicing_fr[0], 0, wsp, 7 ); pitch_ol2_fx( PIT_MIN_EXTEND, st->pitch_fx[0], &pitch_fr[1], &voicing_fr[1], L_SUBFR, wsp, 7 ); - pitch_ol2_fx( PIT_MIN_EXTEND, st->pitch_fx[1], &pitch_fr[2], &voicing_fr[2], 2*L_SUBFR, wsp, 7 ); - pitch_ol2_fx( PIT_MIN_EXTEND, st->pitch_fx[1], &pitch_fr[3], &voicing_fr[3], 3*L_SUBFR, wsp, 7 ); + pitch_ol2_fx( PIT_MIN_EXTEND, st->pitch_fx[1], &pitch_fr[2], &voicing_fr[2], 2 * L_SUBFR, wsp, 7 ); + pitch_ol2_fx( PIT_MIN_EXTEND, st->pitch_fx[1], &pitch_fr[3], &voicing_fr[3], 3 * L_SUBFR, wsp, 7 ); } ELSE { @@ -494,18 +493,18 @@ void pre_proc_fx( * Update estimated noise energy and voicing cut-off frequency *-----------------------------------------------------------------*/ - noise_est_fx( st, old_pitch1, tmpN, epsP_h,epsP_l, *Etot, relE, corr_shift, tmpE, fr_bands, &cor_map_sum, - NULL, &sp_div, &Q_sp_div, &non_staX , &loc_harm, lf_E, &hNoiseEst->harm_cor_cnt , hNoiseEst->Etot_l_lp_fx, - hNoiseEst->Etot_v_h2_fx ,&hNoiseEst->bg_cnt, st->lgBin_E_fx,*Q_new, Le_min_scaled, &sp_floor, NULL, + noise_est_fx( st, old_pitch1, tmpN, epsP_h, epsP_l, *Etot, relE, corr_shift, tmpE, fr_bands, &cor_map_sum, + NULL, &sp_div, &Q_sp_div, &non_staX, &loc_harm, lf_E, &hNoiseEst->harm_cor_cnt, hNoiseEst->Etot_l_lp_fx, + hNoiseEst->Etot_v_h2_fx, &hNoiseEst->bg_cnt, st->lgBin_E_fx, *Q_new, Le_min_scaled, &sp_floor, NULL, #ifdef IVAS_CODE - NULL, NULL, + NULL, NULL, #endif - st->ini_frame); + st->ini_frame ); /*------------------------------------------------------------------* * Update parameters used in the VAD and DTX *-----------------------------------------------------------------*/ - vad_param_updt_fx( st, old_pitch1, corr_shift, corr_shift, A, NULL, 1); + vad_param_updt_fx( st, old_pitch1, corr_shift, corr_shift, A, NULL, 1 ); /*-----------------------------------------------------------------* * Find spectral tilt @@ -513,30 +512,31 @@ void pre_proc_fx( *-----------------------------------------------------------------*/ find_tilt_fx( fr_bands, hNoiseEst->bckr_fx, ee, st->pitch_fx, st->voicing_fx, lf_E, corr_shift, st->input_bwidth, - st->max_band, hp_E, st->codec_mode, *Q_new, &(st->bckr_tilt_lt), st->Opt_SC_VBR ); + st->max_band, hp_E, st->codec_mode, *Q_new, &( st->bckr_tilt_lt ), st->Opt_SC_VBR ); - st->coder_type = find_uv_fx( st, pitch_fr, voicing_fr, inp_12k8, ee, + st->coder_type = find_uv_fx( st, pitch_fr, voicing_fr, inp_12k8, ee, #ifdef IVAS_CODE - NULL, + NULL, #endif - corr_shift, relE, *Etot, hp_E, *Q_new, &flag_spitch, *shift, last_core_orig + corr_shift, relE, *Etot, hp_E, *Q_new, &flag_spitch, *shift, last_core_orig #ifdef IVAS_CODE - , NULL + , + NULL #endif - ); + ); /*----------------------------------------------------------------* - * channel aware mode configuration * - *-----------------------------------------------------------------*/ + * channel aware mode configuration * + *-----------------------------------------------------------------*/ test(); test(); test(); - IF( !st->Opt_RF_ON) + IF( !st->Opt_RF_ON ) { st->rf_mode = 0; st->rf_target_bits_write = 0; } - ELSE IF( st->rf_mode && NE_32(st->core_brate,FRAME_NO_DATA)&&NE_32(st->core_brate,SID_2k40)) + ELSE IF( st->rf_mode && NE_32( st->core_brate, FRAME_NO_DATA ) && NE_32( st->core_brate, SID_2k40 ) ) { /* the RF config is for (n- fec_offset)th frame that will be packed along with the n-th frame bitstream */ st->rf_mode = 1; @@ -548,10 +548,10 @@ void pre_proc_fx( { st->rf_mode = 0; st->codec_mode = MODE1; - IF (st->Opt_RF_ON) + IF( st->Opt_RF_ON ) { hRF->rf_indx_frametype[0] = RF_NO_DATA; - hRF->rf_targetbits_buff[0] = 6; /* rf_mode: 1, rf_frame_type: 3, and fec_offset: 2 */ + hRF->rf_targetbits_buff[0] = 6; /* rf_mode: 1, rf_frame_type: 3, and fec_offset: 2 */ } } @@ -560,15 +560,15 @@ void pre_proc_fx( * TC frame selection *-----------------------------------------------------------------*/ - st->clas = signal_clas_fx( st, inp_12k8, ee, relE, L_look, &clas_mod); + st->clas = signal_clas_fx( st, inp_12k8, ee, relE, L_look, &clas_mod ); - select_TC_fx(st->codec_mode, st->tc_cnt, &st->coder_type, st->localVAD); + select_TC_fx( st->codec_mode, st->tc_cnt, &st->coder_type, st->localVAD ); /* limit coder_type depending on the bitrate */ - coder_type_modif_fx(st, relE); + coder_type_modif_fx( st, relE ); - if (st->Opt_SC_VBR) + if ( st->Opt_SC_VBR ) { hSC_VBR->Local_VAD = st->localVAD; move16(); @@ -578,55 +578,68 @@ void pre_proc_fx( * AC frame selection *----------------------------------------------------------------*/ - FOR( i=0; iOpt_DTX_ON ) + if ( st->Opt_DTX_ON ) { st->vad_flag = vad_flag_dtx; - move16(); /* flag now with the DTX-HO for use in further high rate encoding below */ + move16(); /* flag now with the DTX-HO for use in further high rate encoding below */ } /*----------------------------------------------------------------* * Selection of internal ACELP Fs (12.8 kHz or 16 kHz) *----------------------------------------------------------------*/ - IF( EQ_16(st->codec_mode,MODE1)) + IF( EQ_16( st->codec_mode, MODE1 ) ) { - test();test();test();test(); - test();test();test();test();test();test();test();test();test();test(); - IF( EQ_32(st->core_brate,FRAME_NO_DATA)) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( EQ_32( st->core_brate, FRAME_NO_DATA ) ) { /* prevent "L_frame" changes in CNG segments */ st->L_frame = st->last_L_frame; move16(); } - ELSE IF ( EQ_32(st->core_brate,SID_2k40) && GE_16(st->bwidth,WB) && hDtxEnc->first_CNG && (hTdCngEnc != NULL && LT_16(hTdCngEnc->act_cnt2,MIN_ACT_CNG_UPD))) + ELSE IF( EQ_32( st->core_brate, SID_2k40 ) && GE_16( st->bwidth, WB ) && hDtxEnc->first_CNG && ( hTdCngEnc != NULL && LT_16( hTdCngEnc->act_cnt2, MIN_ACT_CNG_UPD ) ) ) { /* prevent "L_frame" changes in SID frame after short segment of active frames */ st->L_frame = hDtxEnc->last_CNG_L_frame; move16(); } - ELSE IF ( ( EQ_32(st->core_brate,SID_2k40)&&GE_32(st->total_brate,ACELP_9k60)&&((EQ_16(st->bwidth,WB)&&!(EQ_32(st->total_brate,ACELP_13k20)&&EQ_16(st->cng_type,FD_CNG)))||(EQ_16(st->cng_type,LP_CNG)&>_16(st->bwidth,WB)&&GE_32(st->total_brate,ACELP_16k40))))|| - ( GT_32(st->total_brate,ACELP_24k40) && LT_32(st->total_brate,HQ_96k) ) || ( EQ_32(st->total_brate,ACELP_24k40) && GE_16(st->bwidth,WB) ) ) + ELSE IF( ( EQ_32( st->core_brate, SID_2k40 ) && GE_32( st->total_brate, ACELP_9k60 ) && ( ( EQ_16( st->bwidth, WB ) && !( EQ_32( st->total_brate, ACELP_13k20 ) && EQ_16( st->cng_type, FD_CNG ) ) ) || ( EQ_16( st->cng_type, LP_CNG ) && GT_16( st->bwidth, WB ) && GE_32( st->total_brate, ACELP_16k40 ) ) ) ) || + ( GT_32( st->total_brate, ACELP_24k40 ) && LT_32( st->total_brate, HQ_96k ) ) || ( EQ_32( st->total_brate, ACELP_24k40 ) && GE_16( st->bwidth, WB ) ) ) { st->L_frame = L_FRAME16k; move16(); @@ -637,14 +650,14 @@ void pre_proc_fx( move16(); } - if( st->ini_frame == 0 ) + if ( st->ini_frame == 0 ) { /* avoid switching of internal ACELP Fs in the very first frame */ st->last_L_frame = st->L_frame; move16(); } - IF( EQ_16(st->L_frame,L_FRAME)) + IF( EQ_16( st->L_frame, L_FRAME ) ) { st->gamma = GAMMA1; move16(); @@ -659,10 +672,10 @@ void pre_proc_fx( move16(); } - st->sr_core = L_mult0(FRAMES_PER_SEC,st->L_frame); - st->encoderLookahead_enc = NS2SA_fx2(st->sr_core, ACELP_LOOK_NS); + st->sr_core = L_mult0( FRAMES_PER_SEC, st->L_frame ); + st->encoderLookahead_enc = NS2SA_fx2( st->sr_core, ACELP_LOOK_NS ); move16(); - st->encoderPastSamples_enc = shr(imult1616(st->L_frame, 9), 4); + st->encoderPastSamples_enc = shr( imult1616( st->L_frame, 9 ), 4 ); } /*-----------------------------------------------------------------* @@ -671,24 +684,35 @@ void pre_proc_fx( * enforce TC frames in case of switching *-----------------------------------------------------------------*/ - IF( EQ_16(st->codec_mode,MODE1)) + IF( EQ_16( st->codec_mode, MODE1 ) ) { /* enforce TRANSITION frames */ - test();test();test();test();test();test();test();test(); - test();test();test();test();test(); - IF( NE_16(st->last_L_frame,st->L_frame) && NE_32(st->core_brate,FRAME_NO_DATA) && NE_32(st->core_brate,SID_2k40) && (NE_16(st->coder_type_raw,VOICED))) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( NE_16( st->last_L_frame, st->L_frame ) && NE_32( st->core_brate, FRAME_NO_DATA ) && NE_32( st->core_brate, SID_2k40 ) && ( NE_16( st->coder_type_raw, VOICED ) ) ) { /* enforce TC frame in case of ACELP@12k8 <-> ACELP@16k core switching */ st->coder_type = TRANSITION; move16(); } - ELSE IF( EQ_16(st->last_core,HQ_CORE) || EQ_16(st->last_core,TCX_10_CORE) || EQ_16(st->last_core,TCX_20_CORE)) + ELSE IF( EQ_16( st->last_core, HQ_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) || EQ_16( st->last_core, TCX_20_CORE ) ) { /* enforce TC frame in case of HQ/TCX -> ACELP core switching */ st->coder_type = TRANSITION; move16(); } - ELSE IF( LE_32(st->last_core_brate,SID_2k40) && EQ_16(st->cng_type,FD_CNG)) + ELSE IF( LE_32( st->last_core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) ) { /* enforce TC frame in case of FD_CNG -> ACELP switching (past excitation not available) */ st->coder_type = TRANSITION; @@ -696,12 +720,12 @@ void pre_proc_fx( } /* select INACTIVE frames */ - ELSE IF( LE_32(st->total_brate,ACELP_24k40) && st->vad_flag==0) + ELSE IF( LE_32( st->total_brate, ACELP_24k40 ) && st->vad_flag == 0 ) { /* inactive frames will be coded by GSC technology */ /* except for the VBR mode. VBR mode uses NELP for that */ test(); - IF ( !( EQ_16(st->Opt_SC_VBR, 1) && EQ_16(vad_flag_dtx,1))) + IF( !( EQ_16( st->Opt_SC_VBR, 1 ) && EQ_16( vad_flag_dtx, 1 ) ) ) { st->coder_type = INACTIVE; move16(); @@ -709,9 +733,8 @@ void pre_proc_fx( move16(); } } - ELSE IF( GT_32(st->total_brate,ACELP_24k40)&& - ( (st->vad_flag == 0 && GE_16(st->bwidth,SWB) && GE_16(st->max_bwidth,SWB) ) || (st->localVAD == 0 && (LE_16(st->bwidth,WB) || LE_16(st->max_bwidth,WB))) ) - ) + ELSE IF( GT_32( st->total_brate, ACELP_24k40 ) && + ( ( st->vad_flag == 0 && GE_16( st->bwidth, SWB ) && GE_16( st->max_bwidth, SWB ) ) || ( st->localVAD == 0 && ( LE_16( st->bwidth, WB ) || LE_16( st->max_bwidth, WB ) ) ) ) ) { /* inactive frames will be coded by AVQ technology */ st->coder_type = INACTIVE; @@ -720,12 +743,12 @@ void pre_proc_fx( } ELSE { - IF( !(st->vad_flag) ) + IF( !( st->vad_flag ) ) { st->coder_type = INACTIVE; move16(); } - ELSE IF( GT_16(st->coder_type,GENERIC)) + ELSE IF( GT_16( st->coder_type, GENERIC ) ) { st->coder_type = GENERIC; move16(); @@ -738,19 +761,19 @@ void pre_proc_fx( IF( st->Opt_SC_VBR ) { - set_ppp_mode_fx( st, noisy_speech_HO, clean_speech_HO, NB_speech_HO, localVAD_HE_SAD); + set_ppp_mode_fx( st, noisy_speech_HO, clean_speech_HO, NB_speech_HO, localVAD_HE_SAD ); } test(); - IF ( !st->Opt_AMR_WB && !st->rf_mode ) + IF( !st->Opt_AMR_WB && !st->rf_mode ) { test(); test(); - IF ( EQ_32(st->total_brate,ACELP_13k20)||EQ_32(st->total_brate,ACELP_32k)) + IF( EQ_32( st->total_brate, ACELP_13k20 ) || EQ_32( st->total_brate, ACELP_32k ) ) { st->mdct_sw_enable = MODE1; move16(); } - ELSE IF ( LE_32(ACELP_16k40,st->total_brate)&&LE_32(st->total_brate,ACELP_24k40)) + ELSE IF( LE_32( ACELP_16k40, st->total_brate ) && LE_32( st->total_brate, ACELP_24k40 ) ) { st->mdct_sw_enable = MODE2; move16(); @@ -760,40 +783,40 @@ void pre_proc_fx( /*---------------------------------------------------------------------* * Decision matrix (selection of technologies) *---------------------------------------------------------------------*/ - IF( EQ_16(st->codec_mode,MODE1)) + IF( EQ_16( st->codec_mode, MODE1 ) ) { decision_matrix_enc_fx( st, hq_core_type ); /* HQ_CORE/TCX_20_CORE decision */ - IF ( EQ_16(st->core,HQ_CORE)) /* Decision matrix decided for MDCT coding */ + IF( EQ_16( st->core, HQ_CORE ) ) /* Decision matrix decided for MDCT coding */ { test(); test(); - IF( (EQ_16(st->bwidth,SWB) || EQ_16(st->bwidth,FB)) && EQ_32(st->total_brate, ACELP_32k)) + IF( ( EQ_16( st->bwidth, SWB ) || EQ_16( st->bwidth, FB ) ) && EQ_32( st->total_brate, ACELP_32k ) ) { /* Select MDCT Core */ - st->core = mdct_classifier_fx(fft_buff,st, enerBuffer,sub(enerBuffer_exp, 31), st->total_brate); + st->core = mdct_classifier_fx( fft_buff, st, enerBuffer, sub( enerBuffer_exp, 31 ), st->total_brate ); } test(); - IF( (EQ_32(st->total_brate, ACELP_13k20)) && (NE_16(st->bwidth,FB))) + IF( ( EQ_32( st->total_brate, ACELP_13k20 ) ) && ( NE_16( st->bwidth, FB ) ) ) { - MDCT_selector_fx( st, sp_floor, *Etot, cor_map_sum, enerBuffer, enerBuffer_exp); + MDCT_selector_fx( st, sp_floor, *Etot, cor_map_sum, enerBuffer, enerBuffer_exp ); } } ELSE { - MDCT_selector_reset_fx(hTcxEnc); + MDCT_selector_reset_fx( hTcxEnc ); } /* Switch to MODE2 if TCX_20_CORE */ - IF( EQ_16(st->core,TCX_20_CORE)) + IF( EQ_16( st->core, TCX_20_CORE ) ) { st->codec_mode = MODE2; move16(); - IF( EQ_16(st->last_codec_mode,MODE1)) + IF( EQ_16( st->last_codec_mode, MODE1 ) ) { - Word32 last_total_brate = L_add(st->last_total_brate, 0); + Word32 last_total_brate = L_add( st->last_total_brate, 0 ); st->last_total_brate = -1; move32(); SetModeIndex_fx( st, st->last_total_brate, EVS_MONO, 0, *shift ); @@ -802,17 +825,17 @@ void pre_proc_fx( } ELSE { - SetModeIndex_fx( st, st->last_total_brate, EVS_MONO, 0, *shift); - st->sr_core = getCoreSamplerateMode2(st->element_mode, st->total_brate, st->bwidth, st->flag_ACELP16k, st->rf_mode, 0 ); + SetModeIndex_fx( st, st->last_total_brate, EVS_MONO, 0, *shift ); + st->sr_core = getCoreSamplerateMode2( st->element_mode, st->total_brate, st->bwidth, st->flag_ACELP16k, st->rf_mode, 0 ); - Mpy_32_16_ss(st->sr_core, 5243, &L_tmp, &lsb); /* 5243 is 1/50 in Q18. (0+18-15=3) */ - st->L_frame = extract_l(L_shr(L_tmp, 3)); /* Q0 */ - st->encoderLookahead_enc = NS2SA_fx2(st->sr_core, ACELP_LOOK_NS); + Mpy_32_16_ss( st->sr_core, 5243, &L_tmp, &lsb ); /* 5243 is 1/50 in Q18. (0+18-15=3) */ + st->L_frame = extract_l( L_shr( L_tmp, 3 ) ); /* Q0 */ + st->encoderLookahead_enc = NS2SA_fx2( st->sr_core, ACELP_LOOK_NS ); move16(); - st->encoderPastSamples_enc = shr(imult1616(st->L_frame, 9), 4); - assert(st->L_frame == st->sr_core / 50); + st->encoderPastSamples_enc = shr( imult1616( st->L_frame, 9 ), 4 ); + assert( st->L_frame == st->sr_core / 50 ); - IF ( EQ_32(st->sr_core, INT_FS_12k8)) + IF( EQ_32( st->sr_core, INT_FS_12k8 ) ) { st->preemph_fac = PREEMPH_FAC; move16(); @@ -827,7 +850,7 @@ void pre_proc_fx( move16(); } - st->igf = getIgfPresent_fx(st->element_mode, st->total_brate, st->bwidth, st->rf_mode); + st->igf = getIgfPresent_fx( st->element_mode, st->total_brate, st->bwidth, st->rf_mode ); } st->coder_type = st->coder_type_raw; @@ -838,7 +861,7 @@ void pre_proc_fx( st->coder_type = INACTIVE; move16(); } - ELSE IF( GT_16((st->coder_type),GENERIC)) + ELSE IF( GT_16( ( st->coder_type ), GENERIC ) ) { st->coder_type = GENERIC; move16(); @@ -853,13 +876,14 @@ void pre_proc_fx( * Update of ACELP harmonicity counter (used in ACELP transform codebook @32kbps) *-----------------------------------------------------------------*/ - test();test(); - test();test(); - IF( EQ_32(st->total_brate, ACELP_32k)&&EQ_16(loc_harm,1)&>_16(cor_map_sum,50<<8) - && EQ_16(st->clas, VOICED_CLAS) && EQ_16(st->coder_type,GENERIC) ) + test(); + test(); + test(); + test(); + IF( EQ_32( st->total_brate, ACELP_32k ) && EQ_16( loc_harm, 1 ) && GT_16( cor_map_sum, 50 << 8 ) && EQ_16( st->clas, VOICED_CLAS ) && EQ_16( st->coder_type, GENERIC ) ) { - st->last_harm_flag_acelp = add(st->last_harm_flag_acelp,1); - st->last_harm_flag_acelp = s_min(st->last_harm_flag_acelp,10); + st->last_harm_flag_acelp = add( st->last_harm_flag_acelp, 1 ); + st->last_harm_flag_acelp = s_min( st->last_harm_flag_acelp, 10 ); } ELSE { @@ -871,17 +895,17 @@ void pre_proc_fx( * Update audio frames counter (used for UV decision) *-----------------------------------------------------------------*/ - IF( EQ_16(st->coder_type,AUDIO)) + IF( EQ_16( st->coder_type, AUDIO ) ) { - st->audio_frame_cnt = add(st->audio_frame_cnt,AUDIO_COUNTER_STEP); + st->audio_frame_cnt = add( st->audio_frame_cnt, AUDIO_COUNTER_STEP ); } - ELSE IF (NE_16(st->coder_type,INACTIVE)) + ELSE IF( NE_16( st->coder_type, INACTIVE ) ) { - st->audio_frame_cnt = sub(st->audio_frame_cnt,1); + st->audio_frame_cnt = sub( st->audio_frame_cnt, 1 ); } - st->audio_frame_cnt = s_min(st->audio_frame_cnt,AUDIO_COUNTER_MAX); - st->audio_frame_cnt = s_max(st->audio_frame_cnt,0); + st->audio_frame_cnt = s_min( st->audio_frame_cnt, AUDIO_COUNTER_MAX ); + st->audio_frame_cnt = s_max( st->audio_frame_cnt, 0 ); /*-----------------------------------------------------------------* * Set formant sharpening flag @@ -889,31 +913,39 @@ void pre_proc_fx( st->sharpFlag = 0; move16(); - IF( EQ_16(st->coder_type,TRANSITION)) + IF( EQ_16( st->coder_type, TRANSITION ) ) { - test();test();test();test();test(); - IF( ( GT_32(st->total_brate,ACELP_48k)&<_16(st->bwidth,SWB))|| /* Deactivate for core bitrates higher than 48.0 kb/s */ - ( GE_32(st->total_brate,ACELP_13k20) && LE_32(st->total_brate,ACELP_16k40) ) || /* Deactivate for bitrates <13.2, 16.4> kb/s (this is basically due to lack of signaling configurations */ - ( GT_32(st->total_brate,ACELP_16k40)&>_16(st->lp_noise_fx,FORMANT_SHARPENING_NOISE_THRESHOLD_FX))) /* Deactivate for bitrates >= 24.4 kb/s if the long-term noise level exceeds 34 dB */ + test(); + test(); + test(); + test(); + test(); + IF( ( GT_32( st->total_brate, ACELP_48k ) && LT_16( st->bwidth, SWB ) ) || /* Deactivate for core bitrates higher than 48.0 kb/s */ + ( GE_32( st->total_brate, ACELP_13k20 ) && LE_32( st->total_brate, ACELP_16k40 ) ) || /* Deactivate for bitrates <13.2, 16.4> kb/s (this is basically due to lack of signaling configurations */ + ( GT_32( st->total_brate, ACELP_16k40 ) && GT_16( st->lp_noise_fx, FORMANT_SHARPENING_NOISE_THRESHOLD_FX ) ) ) /* Deactivate for bitrates >= 24.4 kb/s if the long-term noise level exceeds 34 dB */ { - st->sharpFlag= 0; + st->sharpFlag = 0; move16(); } ELSE { - st->sharpFlag= 1; + st->sharpFlag = 1; move16(); } } test(); - IF( EQ_16(st->coder_type,GENERIC)||EQ_16(st->coder_type,VOICED)) + IF( EQ_16( st->coder_type, GENERIC ) || EQ_16( st->coder_type, VOICED ) ) { - test();test();test();test();test(); + test(); + test(); + test(); + test(); + test(); IF( *vad_hover_flag || - ( GT_32(st->total_brate,ACELP_48k) && LT_16(st->bwidth,SWB) ) || /* Deactivate for core bitrates higher than 48.0 kb/s */ - ( GE_32(st->total_brate,ACELP_13k20)&>_16(st->lp_noise_fx,FORMANT_SHARPENING_NOISE_THRESHOLD_FX) /* Deactivate for bitrates >= 13.2 kb/s if the long-term noise level exceeds 34 dB */ - && GT_32(st->total_brate,CNA_MAX_BRATE) ) ) + ( GT_32( st->total_brate, ACELP_48k ) && LT_16( st->bwidth, SWB ) ) || /* Deactivate for core bitrates higher than 48.0 kb/s */ + ( GE_32( st->total_brate, ACELP_13k20 ) && GT_16( st->lp_noise_fx, FORMANT_SHARPENING_NOISE_THRESHOLD_FX ) /* Deactivate for bitrates >= 13.2 kb/s if the long-term noise level exceeds 34 dB */ + && GT_32( st->total_brate, CNA_MAX_BRATE ) ) ) { st->sharpFlag = 0; move16(); @@ -928,7 +960,7 @@ void pre_proc_fx( /* channel-aware mode - due to lack of signalling bit, sharpFlag is 1 always in RF mode */ test(); test(); - IF( EQ_16(st->rf_mode,1)&&(EQ_16(st->coder_type,VOICED)||EQ_16(st->coder_type,GENERIC))) + IF( EQ_16( st->rf_mode, 1 ) && ( EQ_16( st->coder_type, VOICED ) || EQ_16( st->coder_type, GENERIC ) ) ) { st->sharpFlag = 1; } @@ -941,7 +973,7 @@ void pre_proc_fx( move16(); test(); test(); - if ( st->sp_aud_decision1 == 0 && ( EQ_16(st->coder_type,VOICED)||EQ_16(st->coder_type,GENERIC))) + if ( st->sp_aud_decision1 == 0 && ( EQ_16( st->coder_type, VOICED ) || EQ_16( st->coder_type, GENERIC ) ) ) { *Voicing_flag = 1; move16(); @@ -951,58 +983,58 @@ void pre_proc_fx( * Preprocessing at other sampling frequency rate (16/25.6/32kHz) *----------------------------------------------------------------*/ - sr_core_tmp = L_max(INT_FS_16k_FX,st->sr_core); /* indicates the ACELP sampling rate for MODE2, 16 kHz for MODE1 */ - if( EQ_16(st->codec_mode,MODE1)) + sr_core_tmp = L_max( INT_FS_16k_FX, st->sr_core ); /* indicates the ACELP sampling rate for MODE2, 16 kHz for MODE1 */ + if ( EQ_16( st->codec_mode, MODE1 ) ) { sr_core_tmp = INT_FS_16k_FX; move32(); } - L_frame_tmp = s_max(L_FRAME16k,st->L_frame); - if( EQ_16(st->codec_mode,MODE1)) + L_frame_tmp = s_max( L_FRAME16k, st->L_frame ); + if ( EQ_16( st->codec_mode, MODE1 ) ) { L_frame_tmp = L_FRAME16k; move16(); } - L_look = NS2SA_fx2(sr_core_tmp, ACELP_LOOK_NS); - move16(); /* lookahead at other sampling rate (16kHz, 25.5kHz, 32kHz) */ + L_look = NS2SA_fx2( sr_core_tmp, ACELP_LOOK_NS ); + move16(); /* lookahead at other sampling rate (16kHz, 25.5kHz, 32kHz) */ - new_inp_16k = old_inp_16k + L_INP_MEM; /* pointer to new samples of the input signal in 16kHz core */ - inp_16k = new_inp_16k - L_look; /* pointer to the current frame of input signal in 16kHz core */ - Copy( st->old_inp_16k_fx, old_inp_16k, L_INP_MEM ); /* Note: The merory has been rescaled at the begining of the function*/ + new_inp_16k = old_inp_16k + L_INP_MEM; /* pointer to new samples of the input signal in 16kHz core */ + inp_16k = new_inp_16k - L_look; /* pointer to the current frame of input signal in 16kHz core */ + Copy( st->old_inp_16k_fx, old_inp_16k, L_INP_MEM ); /* Note: The merory has been rescaled at the begining of the function*/ /*---------------------------------------------------------------* * Change the sampling frequency to 16/25.6/32 kHz *----------------------------------------------------------------*/ test(); - IF( EQ_32(st->input_Fs,sr_core_tmp)) + IF( EQ_32( st->input_Fs, sr_core_tmp ) ) { /* no resampling needed, only delay adjustement to account for the FIR resampling delay */ - delay = NS2SA_fx2(st->input_Fs, DELAY_FIR_RESAMPL_NS); - Copy_Scale_sig( st->mem_decim16k_fx + delay, new_inp_16k, delay, -1 ); /* Input in Q0 -> Output in Q-1 to mimic the resampling filter */ - Copy_Scale_sig( signal_in, new_inp_16k + delay, input_frame - delay, -1 ); /* Input in Q0 -> Output in Q-1 to mimic the resampling filter */ - Copy( signal_in + input_frame - shl(delay,1), st->mem_decim16k_fx, shl(delay,1) ); /* memory still in Q0 */ + delay = NS2SA_fx2( st->input_Fs, DELAY_FIR_RESAMPL_NS ); + Copy_Scale_sig( st->mem_decim16k_fx + delay, new_inp_16k, delay, -1 ); /* Input in Q0 -> Output in Q-1 to mimic the resampling filter */ + Copy_Scale_sig( signal_in, new_inp_16k + delay, input_frame - delay, -1 ); /* Input in Q0 -> Output in Q-1 to mimic the resampling filter */ + Copy( signal_in + input_frame - shl( delay, 1 ), st->mem_decim16k_fx, shl( delay, 1 ) ); /* memory still in Q0 */ } - ELSE IF( EQ_32(st->input_Fs,32000)||EQ_32(st->input_Fs,48000)) + ELSE IF( EQ_32( st->input_Fs, 32000 ) || EQ_32( st->input_Fs, 48000 ) ) { modify_Fs_fx( signal_in, input_frame, st->input_Fs, new_inp_16k, sr_core_tmp, st->mem_decim16k_fx, 0 ); } - ELSE /* keep memories up-to-date in case of bitrate switching */ + ELSE /* keep memories up-to-date in case of bitrate switching */ { /* no resampling needed, only delay adjustement to account for the FIR resampling delay */ - delay = NS2SA_fx2(st->input_Fs, DELAY_FIR_RESAMPL_NS); + delay = NS2SA_fx2( st->input_Fs, DELAY_FIR_RESAMPL_NS ); Copy( st->mem_decim16k_fx + delay, new_inp_16k, delay ); - Copy( signal_in, new_inp_16k + delay, sub(input_frame, delay) ); - Copy( signal_in + sub(input_frame, shl(delay,1)), st->mem_decim16k_fx, shl(delay,1) ); + Copy( signal_in, new_inp_16k + delay, sub( input_frame, delay ) ); + Copy( signal_in + sub( input_frame, shl( delay, 1 ) ), st->mem_decim16k_fx, shl( delay, 1 ) ); } - IF( EQ_32(sr_core_tmp, INT_FS_16k)) + IF( EQ_32( sr_core_tmp, INT_FS_16k ) ) { /* save input resampled at 16kHz, non-preemhasised */ Copy( new_inp_16k, new_inp_resamp16k, L_FRAME16k ); } - ELSE IF( GT_32(sr_core_tmp, INT_FS_16k)) + ELSE IF( GT_32( sr_core_tmp, INT_FS_16k ) ) { /* reset the buffer, the signal is needed for WB BWEs */ set16_fx( new_inp_resamp16k, 0, L_FRAME16k ); @@ -1014,23 +1046,23 @@ void pre_proc_fx( test(); test(); - IF( ((st->tcxonly == 0) || (EQ_16(st->codec_mode,MODE1)))&>_32(st->input_Fs,8000)) + IF( ( ( st->tcxonly == 0 ) || ( EQ_16( st->codec_mode, MODE1 ) ) ) && GT_32( st->input_Fs, 8000 ) ) { #ifdef BASOP_NOGLOB - st->mem_preemph_enc = shl_o(new_inp_16k[sub(L_frame_tmp,1)],1, &Overflow); + st->mem_preemph_enc = shl_o( new_inp_16k[sub( L_frame_tmp, 1 )], 1, &Overflow ); #else /* BASOP_NOGLOB */ - st->mem_preemph_enc = shl(new_inp_16k[sub(L_frame_tmp,1)],1); + st->mem_preemph_enc = shl( new_inp_16k[sub( L_frame_tmp, 1 )], 1 ); #endif } test(); - IF( GT_32(st->input_Fs,8000)&&EQ_32(sr_core_tmp, INT_FS_16k)) + IF( GT_32( st->input_Fs, 8000 ) && EQ_32( sr_core_tmp, INT_FS_16k ) ) { - Preemph_scaled( new_inp_16k, &Q_new_16k, &(st->mem_preemph16k_fx), st->Q_max_16k, PREEMPH_FAC_16k, 0, 1, L_Q_MEM, L_FRAME16k, st->last_coder_type, 1); + Preemph_scaled( new_inp_16k, &Q_new_16k, &( st->mem_preemph16k_fx ), st->Q_max_16k, PREEMPH_FAC_16k, 0, 1, L_Q_MEM, L_FRAME16k, st->last_coder_type, 1 ); } - ELSE IF( GT_32(st->input_Fs,8000)) /* keep memory up-to-date in case of bit-rate switching */ + ELSE IF( GT_32( st->input_Fs, 8000 ) ) /* keep memory up-to-date in case of bit-rate switching */ { - st->mem_preemph16k_fx = new_inp_16k[sub(L_frame_tmp,1)]; + st->mem_preemph16k_fx = new_inp_16k[sub( L_frame_tmp, 1 )]; move16(); } @@ -1038,28 +1070,33 @@ void pre_proc_fx( * Core-encoder memories scaling *-----------------------------------------------------------------*/ - test();test();test();test();test();test(); - IF( ( ((st->tcxonly == 0) || !(NE_32(st->core_brate,FRAME_NO_DATA) || NE_32(st->core_brate,SID_2k40))) && EQ_16(st->L_frame,L_FRAME16k) && EQ_16(st->codec_mode,MODE2)) || - ( EQ_16(st->L_frame,L_FRAME16k) && EQ_16(st->codec_mode,MODE1) ) ) + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( ( ( st->tcxonly == 0 ) || !( NE_32( st->core_brate, FRAME_NO_DATA ) || NE_32( st->core_brate, SID_2k40 ) ) ) && EQ_16( st->L_frame, L_FRAME16k ) && EQ_16( st->codec_mode, MODE2 ) ) || + ( EQ_16( st->L_frame, L_FRAME16k ) && EQ_16( st->codec_mode, MODE1 ) ) ) { *Q_new = Q_new_16k; move16(); } ELSE { - IF( GT_32(st->input_Fs,8000)&&EQ_32(sr_core_tmp,16000)) + IF( GT_32( st->input_Fs, 8000 ) && EQ_32( sr_core_tmp, 16000 ) ) { - Scale_sig(new_inp_16k, L_FRAME16k, sub(*Q_new,Q_new_16k)); + Scale_sig( new_inp_16k, L_FRAME16k, sub( *Q_new, Q_new_16k ) ); } } /* Above computed Q_new is used to scale primary copy exc and memory here by (Q_new, st->prev_Q_new) */ - Q_exp = sub(*Q_new, st->prev_Q_new); + Q_exp = sub( *Q_new, st->prev_Q_new ); move16(); - Q_wsp_exp = add(Q_exp,shift_exp); + Q_wsp_exp = add( Q_exp, shift_exp ); - Scale_mem_enc( Q_exp, old_inp_16k, old_exc, hBWE_TD->old_bwe_exc_fx, &(hLPDmem->mem_w0), hLPDmem->mem_syn, + Scale_mem_enc( Q_exp, old_inp_16k, old_exc, hBWE_TD->old_bwe_exc_fx, &( hLPDmem->mem_w0 ), hLPDmem->mem_syn, hLPDmem->mem_syn2, &st->mem_deemp_preQ_fx, hGSCEnc->last_exc_dct_in_fx, hBWE_FD->old_input_lp_fx ); /*-----------------------------------------------------------------* @@ -1073,20 +1110,20 @@ void pre_proc_fx( test(); test(); test(); -#ifndef CR_2109_to_2112_cd0_ce0 - IF((((st->tcxonly == 0) || !(NE_32(st->core_brate, FRAME_NO_DATA) || NE_32(st->core_brate, SID_2k40))) && EQ_16(st->L_frame, L_FRAME16k) && EQ_16(st->codec_mode, MODE2)) || (EQ_16(st->L_frame, L_FRAME16k) && EQ_16(st->codec_mode, MODE1)) ) +#ifndef CR_2109_to_2112_cd0_ce0 + IF( ( ( ( st->tcxonly == 0 ) || !( NE_32( st->core_brate, FRAME_NO_DATA ) || NE_32( st->core_brate, SID_2k40 ) ) ) && EQ_16( st->L_frame, L_FRAME16k ) && EQ_16( st->codec_mode, MODE2 ) ) || ( EQ_16( st->L_frame, L_FRAME16k ) && EQ_16( st->codec_mode, MODE1 ) ) ) #else - IF((((st->tcxonly == 0) || !(NE_32(st->core_brate,FRAME_NO_DATA) && NE_32(st->core_brate,SID_2k40))) && EQ_16(st->L_frame,L_FRAME16k) && EQ_16(st->codec_mode,MODE2)) || ( EQ_16(st->L_frame,L_FRAME16k) && EQ_16(st->codec_mode,MODE1))) + IF( ( ( ( st->tcxonly == 0 ) || !( NE_32( st->core_brate, FRAME_NO_DATA ) && NE_32( st->core_brate, SID_2k40 ) ) ) && EQ_16( st->L_frame, L_FRAME16k ) && EQ_16( st->codec_mode, MODE2 ) ) || ( EQ_16( st->L_frame, L_FRAME16k ) && EQ_16( st->codec_mode, MODE1 ) ) ) #endif { /* update signal buffers */ - Copy( new_inp_resamp16k, st->buf_speech_enc+L_FRAME16k, L_FRAME16k ); - Scale_sig( st->buf_speech_enc+L_FRAME16k, L_FRAME16k, 1 ); - Copy( new_inp_16k, st->buf_speech_enc_pe+L_FRAME16k, L_FRAME16k ); + Copy( new_inp_resamp16k, st->buf_speech_enc + L_FRAME16k, L_FRAME16k ); + Scale_sig( st->buf_speech_enc + L_FRAME16k, L_FRAME16k, 1 ); + Copy( new_inp_16k, st->buf_speech_enc_pe + L_FRAME16k, L_FRAME16k ); IF( Q_exp != 0 ) { - Scale_sig(st->buf_speech_enc_pe, st->encoderPastSamples_enc+st->encoderLookahead_enc, Q_exp); - Scale_sig(&(st->mem_wsp_enc), 1, Q_exp); + Scale_sig( st->buf_speech_enc_pe, st->encoderPastSamples_enc + st->encoderLookahead_enc, Q_exp ); + Scale_sig( &( st->mem_wsp_enc ), 1, Q_exp ); } /*--------------------------------------------------------------* @@ -1094,25 +1131,24 @@ void pre_proc_fx( *---------------------------------------------------------------*/ test(); - IF( EQ_16(st->last_L_frame,L_FRAME)&&EQ_16(st->codec_mode,MODE1)) + IF( EQ_16( st->last_L_frame, L_FRAME ) && EQ_16( st->codec_mode, MODE1 ) ) { /* this is just an approximation, but it is sufficient */ Copy( st->lsp_old1_fx, st->lspold_enc_fx, M ); } - analy_lp_fx( inp_16k, L_FRAME16k, L_look, ener, A, epsP_h, epsP_l, lsp_new, lsp_mid, st->lspold_enc_fx, st->pitch_fx, st->voicing_fx, 16000, -1/*IVAS_CODE !! LowRateFlag*/, *Q_new, Q_r ); + analy_lp_fx( inp_16k, L_FRAME16k, L_look, ener, A, epsP_h, epsP_l, lsp_new, lsp_mid, st->lspold_enc_fx, st->pitch_fx, st->voicing_fx, 16000, -1 /*IVAS_CODE !! LowRateFlag*/, *Q_new, Q_r ); /*--------------------------------------------------------------* - * Compute Weighted Input - *---------------------------------------------------------------*/ + * Compute Weighted Input + *---------------------------------------------------------------*/ - IF( EQ_16(st->codec_mode,MODE2)) + IF( EQ_16( st->codec_mode, MODE2 ) ) { - find_wsp_fx( A, st->speech_enc_pe, st->wspeech_enc, &st->mem_wsp_enc, PREEMPH_FAC_16k, L_FRAME16k, L_LOOK_16k, L_SUBFR, Aw, st->gamma, st->nb_subfr); + find_wsp_fx( A, st->speech_enc_pe, st->wspeech_enc, &st->mem_wsp_enc, PREEMPH_FAC_16k, L_FRAME16k, L_LOOK_16k, L_SUBFR, Aw, st->gamma, st->nb_subfr ); /* This need to be harmonized with MODE2 */ - Scale_sig( st->wspeech_enc, L_FRAME16k+L_LOOK_16k, *shift ); - + Scale_sig( st->wspeech_enc, L_FRAME16k + L_LOOK_16k, *shift ); } ELSE { @@ -1122,19 +1158,19 @@ void pre_proc_fx( ELSE { /* update signal buffers */ - Copy( new_inp_12k8, st->buf_speech_enc_pe+st->L_frame, L_FRAME ); - Copy( st->buf_speech_enc+L_FRAME32k, st->buf_speech_enc+st->L_frame, L_FRAME ); + Copy( new_inp_12k8, st->buf_speech_enc_pe + st->L_frame, L_FRAME ); + Copy( st->buf_speech_enc + L_FRAME32k, st->buf_speech_enc + st->L_frame, L_FRAME ); if ( st->tcxonly == 0 ) { - Copy( wsp, st->buf_wspeech_enc+st->L_frame+L_SUBFR, L_FRAME + L_LOOK_12k8 ); + Copy( wsp, st->buf_wspeech_enc + st->L_frame + L_SUBFR, L_FRAME + L_LOOK_12k8 ); } test(); test(); - IF( EQ_16(st->codec_mode,MODE2)&&st->tcxonly==0&&Q_exp!=0) + IF( EQ_16( st->codec_mode, MODE2 ) && st->tcxonly == 0 && Q_exp != 0 ) { - Scale_sig( st->buf_speech_enc_pe, st->encoderPastSamples_enc+st->encoderLookahead_enc, Q_exp ); - Scale_sig( &(st->mem_wsp_enc), 1, Q_exp ); + Scale_sig( st->buf_speech_enc_pe, st->encoderPastSamples_enc + st->encoderLookahead_enc, Q_exp ); + Scale_sig( &( st->mem_wsp_enc ), 1, Q_exp ); } } @@ -1142,19 +1178,19 @@ void pre_proc_fx( move16(); FOR( i = 0; i < L_EXC_MEM; i++ ) { - excitation_max_test = s_max(abs_s(old_exc[i]),excitation_max_test); + excitation_max_test = s_max( abs_s( old_exc[i] ), excitation_max_test ); } test(); - IF( GT_16(excitation_max_test,8192)&&*shift==0) + IF( GT_16( excitation_max_test, 8192 ) && *shift == 0 ) { excitation_max_test = 1; move16(); *shift = -1; move16(); - st->old_wsp_shift=-1; + st->old_wsp_shift = -1; move16(); - Scale_sig( old_wsp, L_WSP_MEM+L_FRAME+L_LOOK_12k8, -1 ); + Scale_sig( old_wsp, L_WSP_MEM + L_FRAME + L_LOOK_12k8, -1 ); } ELSE { @@ -1163,15 +1199,15 @@ void pre_proc_fx( } test(); - IF ( EQ_16(st->codec_mode,MODE2)&&st->tcxonly==0) + IF( EQ_16( st->codec_mode, MODE2 ) && st->tcxonly == 0 ) { - IF (Q_wsp_exp != 0) + IF( Q_wsp_exp != 0 ) { - Scale_sig(st->buf_wspeech_enc, st->L_frame+L_SUBFR, Q_wsp_exp); + Scale_sig( st->buf_wspeech_enc, st->L_frame + L_SUBFR, Q_wsp_exp ); } - IF( EQ_16(excitation_max_test,1)) + IF( EQ_16( excitation_max_test, 1 ) ) { - Scale_sig( st->buf_wspeech_enc, st->L_frame+L_SUBFR+st->L_frame+st->encoderLookahead_enc, -1 ); + Scale_sig( st->buf_wspeech_enc, st->L_frame + L_SUBFR + st->L_frame + st->encoderLookahead_enc, -1 ); } } @@ -1180,56 +1216,56 @@ void pre_proc_fx( *-----------------------------------------------------------------*/ #ifndef FIX_I4_OL_PITCH - Copy(st->pitch_fx, pitch_orig, 3); + Copy( st->pitch_fx, pitch_orig, 3 ); #endif - IF ( EQ_16(st->codec_mode,MODE2)) + IF( EQ_16( st->codec_mode, MODE2 ) ) { test(); test(); - IF((NE_32(st->core_brate,FRAME_NO_DATA)&&NE_32(st->core_brate,SID_2k40)&&st->tcxonly==0)) + IF( ( NE_32( st->core_brate, FRAME_NO_DATA ) && NE_32( st->core_brate, SID_2k40 ) && st->tcxonly == 0 ) ) { - core_acelp_tcx20_switching_fx( st, non_staX, pitch_fr, voicing_fr, currFlatness, lsp_mid, stab_fac, *Q_new, *shift ); + core_acelp_tcx20_switching_fx( st, non_staX, pitch_fr, voicing_fr, currFlatness, lsp_mid, stab_fac, *Q_new, *shift ); } test(); - IF (EQ_16(st->mdct_sw_enable,MODE2)&&!st->rf_mode) + IF( EQ_16( st->mdct_sw_enable, MODE2 ) && !st->rf_mode ) { - IF (EQ_16(st->core,TCX_20_CORE)) /* Switching only possible from TCX_20 frames, not from TCX_10 frames */ + IF( EQ_16( st->core, TCX_20_CORE ) ) /* Switching only possible from TCX_20 frames, not from TCX_10 frames */ { /* Select MDCT Core */ test(); test(); - IF ((EQ_16(st->bwidth,SWB) || EQ_16(st->bwidth,FB)) && EQ_32(st->total_brate, ACELP_24k40)) + IF( ( EQ_16( st->bwidth, SWB ) || EQ_16( st->bwidth, FB ) ) && EQ_32( st->total_brate, ACELP_24k40 ) ) { - st->core = mdct_classifier_fx(fft_buff,st, enerBuffer, sub(enerBuffer_exp, 31), st->total_brate); + st->core = mdct_classifier_fx( fft_buff, st, enerBuffer, sub( enerBuffer_exp, 31 ), st->total_brate ); } test(); - IF ((EQ_32(st->total_brate, ACELP_16k40)) && (NE_16(st->bwidth,FB))) + IF( ( EQ_32( st->total_brate, ACELP_16k40 ) ) && ( NE_16( st->bwidth, FB ) ) ) { MDCT_selector_fx( st, sp_floor, *Etot, cor_map_sum, enerBuffer, enerBuffer_exp ); } } ELSE { - MDCT_selector_reset_fx(hTcxEnc); + MDCT_selector_reset_fx( hTcxEnc ); } /* Do the switching that was decided in the MDCT selector */ test(); - IF( EQ_16(st->core,HQ_CORE)) + IF( EQ_16( st->core, HQ_CORE ) ) { st->codec_mode = MODE1; move16(); st->mdct_sw = MODE2; move16(); } - ELSE IF( EQ_16(st->last_codec_mode,MODE1)&&EQ_16(st->last_core,HQ_CORE)) + ELSE IF( EQ_16( st->last_codec_mode, MODE1 ) && EQ_16( st->last_core, HQ_CORE ) ) { Word16 L_frame_old = st->last_L_frame; move16(); st->last_L_frame = st->L_frame; move16(); - SetModeIndex_fx( st, st->last_total_brate, EVS_MONO, 0, *shift); + SetModeIndex_fx( st, st->last_total_brate, EVS_MONO, 0, *shift ); st->last_L_frame = L_frame_old; move16(); } @@ -1254,19 +1290,19 @@ void pre_proc_fx( /* update old input signal @16kHz buffer */ test(); - IF( GT_32(st->input_Fs,8000)&&EQ_32(sr_core_tmp, INT_FS_16k)) + IF( GT_32( st->input_Fs, 8000 ) && EQ_32( sr_core_tmp, INT_FS_16k ) ) { Copy( &old_inp_16k[L_frame_tmp], st->old_inp_16k_fx, L_INP_MEM ); } - ELSE IF( GT_32(st->input_Fs,8000)) + ELSE IF( GT_32( st->input_Fs, 8000 ) ) { - lerp( st->old_inp_12k8_fx+L_INP_MEM-L_INP_MEM*4/5, st->old_inp_16k_fx, L_INP_MEM, L_INP_MEM*4/5); - Scale_sig(st->old_inp_16k_fx, L_INP_MEM, sub(*Q_new,st->Q_old)); + lerp( st->old_inp_12k8_fx + L_INP_MEM - L_INP_MEM * 4 / 5, st->old_inp_16k_fx, L_INP_MEM, L_INP_MEM * 4 / 5 ); + Scale_sig( st->old_inp_16k_fx, L_INP_MEM, sub( *Q_new, st->Q_old ) ); } test(); test(); - IF( (EQ_32(sr_core_tmp, INT_FS_16k))&&st->tcxonly&&EQ_16(st->codec_mode,MODE2)) + IF( ( EQ_32( sr_core_tmp, INT_FS_16k ) ) && st->tcxonly && EQ_16( st->codec_mode, MODE2 ) ) { /* copy input resampled at 16kHz, non-preemhasised */ Copy( new_inp_resamp16k, new_inp_16k, L_FRAME16k ); @@ -1277,32 +1313,31 @@ void pre_proc_fx( /* set the pointer of the current frame for the ACELP core */ *inp = inp_16k; - if ( EQ_16(st->L_frame,L_FRAME)) + if ( EQ_16( st->L_frame, L_FRAME ) ) { *inp = inp_12k8; } /* Update vAD hangover frame counter in active frames */ - if ((NE_16(st->core, HQ_CORE) && st->tcxonly == 0) || EQ_16(st->core, ACELP_CORE)) + if ( ( NE_16( st->core, HQ_CORE ) && st->tcxonly == 0 ) || EQ_16( st->core, ACELP_CORE ) ) { - IF(!(EQ_32(st->core_brate, SID_2k40) || EQ_32(st->core_brate, FRAME_NO_DATA))) + IF( !( EQ_32( st->core_brate, SID_2k40 ) || EQ_32( st->core_brate, FRAME_NO_DATA ) ) ) { test(); - IF(st->Opt_DTX_ON != 0 && *vad_hover_flag != 0) + IF( st->Opt_DTX_ON != 0 && *vad_hover_flag != 0 ) { - hTdCngEnc->burst_ho_cnt = add(hTdCngEnc->burst_ho_cnt, 1); - hTdCngEnc->burst_ho_cnt = s_min(hTdCngEnc->burst_ho_cnt, HO_HIST_SIZE); + hTdCngEnc->burst_ho_cnt = add( hTdCngEnc->burst_ho_cnt, 1 ); + hTdCngEnc->burst_ho_cnt = s_min( hTdCngEnc->burst_ho_cnt, HO_HIST_SIZE ); } ELSE { - IF(hTdCngEnc != NULL && vad_flag_dtx != 0) + IF( hTdCngEnc != NULL && vad_flag_dtx != 0 ) { hTdCngEnc->burst_ho_cnt = 0; move16(); } } - } } diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 743fafd61..9ad638274 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -45,600 +45,594 @@ * Prototypes of RAM counting tool macros *----------------------------------------------------------------------------------*/ ivas_error acelp_core_enc_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 inp_fx[], /* i : i signal of the current frame */ - const Word32 ener_fx, /* i : residual energy from Levinson-Durbin*/ - Word16 A_fx[NB_SUBFR16k*(M + 1)], /* i : A(z) unquantized for the 4 subframes*/ - Word16 Aw_fx[NB_SUBFR16k*(M + 1)], /* i : weighted A(z) unquant. for subframes*/ - const Word16 epsP_h_fx[M + 1], /* i : LP prediction errors */ - const Word16 epsP_l_fx[M + 1], /* i : LP prediction errors */ - Word16 lsp_new_fx[M], /* i : LSPs at the end of the frame */ - Word16 lsp_mid_fx[M], /* i : LSPs in the middle of the frame */ - Word16 vad_hover_flag_fx, /* i : VAD hangover flag */ - const Word16 attack_flag, /* i : attack flag (GSC or TC) */ - Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation */ - Word16 *voice_factors_fx, /* o : voicing factors */ - Word16 old_syn_12k8_16k_fx[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE */ - Word16 pitch_buf_fx[NB_SUBFR16k], /* o : floating pitch for each subframe */ - Word16 *unbits_fx, /* o : number of unused bits */ - const Word16 Q_new, - const Word16 shift + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word16 inp_fx[], /* i : i signal of the current frame */ + const Word32 ener_fx, /* i : residual energy from Levinson-Durbin*/ + Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes*/ + Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquant. for subframes*/ + const Word16 epsP_h_fx[M + 1], /* i : LP prediction errors */ + const Word16 epsP_l_fx[M + 1], /* i : LP prediction errors */ + Word16 lsp_new_fx[M], /* i : LSPs at the end of the frame */ + Word16 lsp_mid_fx[M], /* i : LSPs in the middle of the frame */ + Word16 vad_hover_flag_fx, /* i : VAD hangover flag */ + const Word16 attack_flag, /* i : attack flag (GSC or TC) */ + Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation */ + Word16 *voice_factors_fx, /* o : voicing factors */ + Word16 old_syn_12k8_16k_fx[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE */ + Word16 pitch_buf_fx[NB_SUBFR16k], /* o : floating pitch for each subframe */ + Word16 *unbits_fx, /* o : number of unused bits */ + const Word16 Q_new, + const Word16 shift #ifdef ADD_LRTD - , - STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ - const float tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ + , + STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ + const float tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ #endif ); void analy_lp_fx( - const Word16 speech[], /* i : pointer to the speech frame */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 L_look, /* i : look-ahead */ - Word32* ener, /* o : residual energy from Levinson-Durbin */ - Word16 A[], /* o : A(z) filter coefficients */ - Word16 epsP_h[], /* o : LP analysis residual energies for each iteration */ - Word16 epsP_l[], /* o : LP analysis residual energies for each iteration */ - Word16 lsp_new[], /* o : current frame LSPs */ - Word16 lsp_mid[], /* o : current mid-frame LSPs */ - Word16 lsp_old[], /* i/o: previous frame unquantized LSPs */ - const Word16 Top[2], /* i : open loop pitch lag */ - const Word16 Tnc[2], /* i : open loop pitch gain */ - const Word32 Core_sr, /* i : Internal core sampling rate */ - const Word16 sec_chan_low_rate, /* i : flag to signal second channel */ - Word16 Q_new, - Word16* Q_r -); - -void AVQ_cod_fx( /* o: comfort noise gain factor */ - const Word16 xri[], /* i: vector to quantize */ - Word16 xriq[], /* o: quantized normalized vector (assuming the bit budget is enough) */ - const Word16 NB_BITS, /* i: number of allocated bits */ - const Word16 Nsv, /* i: number of subvectors (lg=Nsv*8) */ - const Word16 Q_in_ref /* i: Scaling i */ + const Word16 speech[], /* i : pointer to the speech frame */ + const Word16 L_frame, /* i : length of the frame */ + const Word16 L_look, /* i : look-ahead */ + Word32 *ener, /* o : residual energy from Levinson-Durbin */ + Word16 A[], /* o : A(z) filter coefficients */ + Word16 epsP_h[], /* o : LP analysis residual energies for each iteration */ + Word16 epsP_l[], /* o : LP analysis residual energies for each iteration */ + Word16 lsp_new[], /* o : current frame LSPs */ + Word16 lsp_mid[], /* o : current mid-frame LSPs */ + Word16 lsp_old[], /* i/o: previous frame unquantized LSPs */ + const Word16 Top[2], /* i : open loop pitch lag */ + const Word16 Tnc[2], /* i : open loop pitch gain */ + const Word32 Core_sr, /* i : Internal core sampling rate */ + const Word16 sec_chan_low_rate, /* i : flag to signal second channel */ + Word16 Q_new, + Word16 *Q_r ); + +void AVQ_cod_fx( /* o: comfort noise gain factor */ + const Word16 xri[], /* i: vector to quantize */ + Word16 xriq[], /* o: quantized normalized vector (assuming the bit budget is enough) */ + const Word16 NB_BITS, /* i: number of allocated bits */ + const Word16 Nsv, /* i: number of subvectors (lg=Nsv*8) */ + const Word16 Q_in_ref /* i: Scaling i */ ); void AVQ_encmux_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ - const Word16 extl, /* i : extension layer */ - Word16 xriq[], /* i/o: rounded subvectors [0..8*Nsv-1] followed - by rounded bit allocations [8*Nsv..8*Nsv+Nsv-1] */ - Word16* nb_bits, /* i/o: number of allocated bits */ - const Word16 Nsv, /* i: number of subvectors */ - Word16 nq_out[], /* o : AVQ nq index */ - Word16 avq_bit_sFlag, /* i : flag for AVQ bit saving solution */ - Word16 trgtSvPos /* i : target SV for AVQ bit savings */ + BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ + const Word16 extl, /* i : extension layer */ + Word16 xriq[], /* i/o: rounded subvectors [0..8*Nsv-1] followed + by rounded bit allocations [8*Nsv..8*Nsv+Nsv-1] */ + Word16 *nb_bits, /* i/o: number of allocated bits */ + const Word16 Nsv, /* i: number of subvectors */ + Word16 nq_out[], /* o : AVQ nq index */ + Word16 avq_bit_sFlag, /* i : flag for AVQ bit saving solution */ + Word16 trgtSvPos /* i : target SV for AVQ bit savings */ ); void bw_detect_fx( - Encoder_State* st, /* i/o: Encoder State */ - const Word16 signal_in[], /* i : i signal */ - Word16* spectrum, /* i : MDCT spectrum */ - const Word32* enerBuffer, /* i : CLDFB Energy Q31 */ - const Word16* cldfbBuf_Ener_Exp,/* i : CLDFB Energy Exponent */ - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const int16_t mct_on /* i : flag MCT mode */ -); - -void core_switching_post_enc_fx( /*done */ - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 inp12k8[], /* i : i signal @12.8 kHz */ - const Word16 inp16k[], /* i : i signal @16 kHz */ - const Word16 A[], /* i : unquant. LP filter coefs. (Q12) */ - Word16 Qshift, - Word16 Q_new, - const Word16 Qsp, /* i/o : Q from acelp synthsis */ - Word16 *Qmus /* i/o : Q from mdct synthsis / Q of output synthesis */ + Encoder_State *st, /* i/o: Encoder State */ + const Word16 signal_in[], /* i : i signal */ + Word16 *spectrum, /* i : MDCT spectrum */ + const Word32 *enerBuffer, /* i : CLDFB Energy Q31 */ + const Word16 *cldfbBuf_Ener_Exp, /* i : CLDFB Energy Exponent */ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const int16_t mct_on /* i : flag MCT mode */ +); + +void core_switching_post_enc_fx( /*done */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word16 inp12k8[], /* i : i signal @12.8 kHz */ + const Word16 inp16k[], /* i : i signal @16 kHz */ + const Word16 A[], /* i : unquant. LP filter coefs. (Q12) */ + Word16 Qshift, + Word16 Q_new, + const Word16 Qsp, /* i/o : Q from acelp synthsis */ + Word16 *Qmus /* i/o : Q from mdct synthsis / Q of output synthesis */ ); void core_switching_pre_enc_fx( - Encoder_State* st_fx, /* i/o: encoder state structure */ - const Word16* old_inp_12k8, /* i : old i signal @12.8kHz */ - const Word16* old_inp_16k, /* i : old i signal @16kHz */ - const Word16 active_cnt, /* i : active frame counter */ - const Word16 last_element_mode /* i : last_element_mode */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word16 *old_inp_12k8, /* i : old i signal @12.8kHz */ + const Word16 *old_inp_16k, /* i : old i signal @16kHz */ + const Word16 active_cnt, /* i : active frame counter */ + const Word16 last_element_mode /* i : last_element_mode */ ); -Word16 correlation_shift_fx( /* o : noise dependent voicing correction Q15 */ - const Word16 totalNoise_fx /* i/o: noise estimate over all critical bands Q8 */ +Word16 correlation_shift_fx( /* o : noise dependent voicing correction Q15 */ + const Word16 totalNoise_fx /* i/o: noise estimate over all critical bands Q8 */ ); void dtx_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 vad, /* i : vad flag */ - const Word16 speech[], /* i : Pointer to the speech frame */ - Word16 Q_speech /* i : Q factor for speech */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word16 vad, /* i : vad flag */ + const Word16 speech[], /* i : Pointer to the speech frame */ + Word16 Q_speech /* i : Q factor for speech */ ); Word16 dtx_hangover_addition_fx( - Encoder_State* st_fx, /* i/o: encoder state structure */ - const Word16 vad_flag, /* i Q0 */ - const Word16 lp_snr, /* i Q8 */ - const Word16 cldfb_subtraction, /* i Q0 number of DTX-HO frames CLDFB wants to reduce */ - Word16* vad_hover_flag_ptr, - VAD_HANDLE hVAD, /* i/o: VAD data handle */ - NOISE_EST_HANDLE hNoiseEst /* i : Noise estimation handle */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word16 vad_flag, /* i Q0 */ + const Word16 lp_snr, /* i Q8 */ + const Word16 cldfb_subtraction, /* i Q0 number of DTX-HO frames CLDFB wants to reduce */ + Word16 *vad_hover_flag_ptr, + VAD_HANDLE hVAD, /* i/o: VAD data handle */ + NOISE_EST_HANDLE hNoiseEst /* i : Noise estimation handle */ ); void fb_tbe_enc_fx( - Encoder_State *st, /* i/o: encoder state structure */ - const Word16 new_input[], /* i : i speech at 48 kHz sample rate */ - const Word16 fb_exc[], /* i : FB excitation from the SWB part */ - Word16 Q_fb_exc -); + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 new_input[], /* i : i speech at 48 kHz sample rate */ + const Word16 fb_exc[], /* i : FB excitation from the SWB part */ + Word16 Q_fb_exc ); void fb_tbe_reset_enc_fx( - Word32 elliptic_bpf_2_48k_mem_fx[][4], - Word32 *prev_fb_energy_fx, - Word16 elliptic_bpf_2_48k_mem_fx_Q[], - Word16 *prev_fb_energy_fx_Q -); + Word32 elliptic_bpf_2_48k_mem_fx[][4], + Word32 *prev_fb_energy_fx, + Word16 elliptic_bpf_2_48k_mem_fx_Q[], + Word16 *prev_fb_energy_fx_Q ); Word16 ffr_getSfWord32( - const Word32* vector, /*!< Pointer to i vector */ - const Word16 len /*!< Length of i vector */ + const Word32 *vector, /*!< Pointer to i vector */ + const Word16 len /*!< Length of i vector */ ); void find_tilt_fx( - const Word32 fr_bands[], /* i : energy in frequency bands Q_new + Q_SCALE*/ - const Word32 bckr[], /* i : per band background noise energy estimate Q_new + Q_SCALE*/ - Word32 ee[2], /* o : lf/hf E ration for present frame Q6*/ - const Word16 pitch[3], /* i : open loop pitch values for 3 half-frames Q0*/ - const Word16 voicing[3], /* i : normalized correlation for 3 half-frames Q15*/ - const Word32 *lf_E, /* i : per bin energy for low frequencies Q_new + Q_SCALE - 2*/ - const Word16 corr_shift, /* i : normalized correlation correction Q15*/ - const Word16 bwidth, /* i : i signal bandwidth */ - const Word16 max_band, /* i : maximum critical band */ - Word32 hp_E[], /* o : energy in HF Q_new + Q_SCALE*/ - const Word16 codec_mode, /* i : MODE1 or MODE2 */ - const Word16 Q_new, /* i : scaling factor */ - Word32 *bckr_tilt_lt - , Word16 Opt_vbr_mode -); + const Word32 fr_bands[], /* i : energy in frequency bands Q_new + Q_SCALE*/ + const Word32 bckr[], /* i : per band background noise energy estimate Q_new + Q_SCALE*/ + Word32 ee[2], /* o : lf/hf E ration for present frame Q6*/ + const Word16 pitch[3], /* i : open loop pitch values for 3 half-frames Q0*/ + const Word16 voicing[3], /* i : normalized correlation for 3 half-frames Q15*/ + const Word32 *lf_E, /* i : per bin energy for low frequencies Q_new + Q_SCALE - 2*/ + const Word16 corr_shift, /* i : normalized correlation correction Q15*/ + const Word16 bwidth, /* i : i signal bandwidth */ + const Word16 max_band, /* i : maximum critical band */ + Word32 hp_E[], /* o : energy in HF Q_new + Q_SCALE*/ + const Word16 codec_mode, /* i : MODE1 or MODE2 */ + const Word16 Q_new, /* i : scaling factor */ + Word32 *bckr_tilt_lt, + Word16 Opt_vbr_mode ); Word16 find_uv_fx( /* o : coding type */ - Encoder_State* st_fx, /* i/o: encoder state structure */ - const Word16* T_op_fr, /* i : pointer to adjusted fractional pitch (4 val.) Q6*/ - const Word16* voicing_fr, /* i : refined correlation for each subframes Q15*/ - const Word16* speech, /* i : pointer to speech signal for E computation Q_new*/ - const Word32* ee, /* i : lf/hf Energy ratio for present frame Q6*/ + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word16 *T_op_fr, /* i : pointer to adjusted fractional pitch (4 val.) Q6*/ + const Word16 *voicing_fr, /* i : refined correlation for each subframes Q15*/ + const Word16 *speech, /* i : pointer to speech signal for E computation Q_new*/ + const Word32 *ee, /* i : lf/hf Energy ratio for present frame Q6*/ #ifdef IVAS_CODE - Word32* dE1X, /* o : sudden energy increase for S/M classifier */ + Word32 *dE1X, /* o : sudden energy increase for S/M classifier */ #endif - const Word16 corr_shift, /* i : normalized correlation correction in noise Q15*/ - const Word16 relE, /* i : relative frame energy Q8*/ - const Word16 Etot, /* i : total energy Q8*/ - const Word32 hp_E[], /* i : energy in HF Q_new + Q_SCALE*/ - const Word16 Q_new, - Word16* flag_spitch, /* i/o: flag to indicate very short stable pitch and high correlation */ - const Word16 shift, - const Word16 last_core_orig /* i : original last core */ + const Word16 corr_shift, /* i : normalized correlation correction in noise Q15*/ + const Word16 relE, /* i : relative frame energy Q8*/ + const Word16 Etot, /* i : total energy Q8*/ + const Word32 hp_E[], /* i : energy in HF Q_new + Q_SCALE*/ + const Word16 Q_new, + Word16 *flag_spitch, /* i/o: flag to indicate very short stable pitch and high correlation */ + const Word16 shift, + const Word16 last_core_orig /* i : original last core */ #ifdef IVAS_CODE - , STEREO_CLASSIF_HANDLE hStereoClassif /* i/o: stereo classifier structure */ + , + STEREO_CLASSIF_HANDLE hStereoClassif /* i/o: stereo classifier structure */ #endif ); void fine_gain_quant_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 *ord, /* i : Indices for energy order */ - const Word16 num_sfm, /* i : Number of bands */ - const Word16 *gain_bits, /* i : Gain adjustment bits per sub band */ - Word16 *fg_pred, /* i/o: Predicted gains / Corrected gains Q12 */ - const Word16 *gopt /* i : Optimal gains Q12 */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 *ord, /* i : Indices for energy order */ + const Word16 num_sfm, /* i : Number of bands */ + const Word16 *gain_bits, /* i : Gain adjustment bits per sub band */ + Word16 *fg_pred, /* i/o: Predicted gains / Corrected gains Q12 */ + const Word16 *gopt /* i : Optimal gains Q12 */ ); void hq_core_enc_fx( - Encoder_State* st_fx, - const Word16* audio, /* i : i audio signal Q0 */ - const Word16 input_frame_orig, /* i : frame length */ - const Word16 hq_core_type, /* i : HQ core type */ - const Word16 Voicing_flag, /* i : Voicing flag for FER method selection */ - const Word16 vad_hover_flag /* i : VAD hangover flag */ + Encoder_State *st_fx, + const Word16 *audio, /* i : i audio signal Q0 */ + const Word16 input_frame_orig, /* i : frame length */ + const Word16 hq_core_type, /* i : HQ core type */ + const Word16 Voicing_flag, /* i : Voicing flag for FER method selection */ + const Word16 vad_hover_flag /* i : VAD hangover flag */ ); void long_enr_fx( - Encoder_State *st_fx, /* i/o: state structure */ - const Word16 Etot, /* i : total channel E (see lib_enc\analy_sp.c) */ - const Word16 localVAD_HE_SAD, /* i : HE-SAD flag without hangover */ - Word16 high_lpn_flag -); + Encoder_State *st_fx, /* i/o: state structure */ + const Word16 Etot, /* i : total channel E (see lib_enc\analy_sp.c) */ + const Word16 localVAD_HE_SAD, /* i : HE-SAD flag without hangover */ + Word16 high_lpn_flag ); -Word16 mdct_classifier_fx( /* o: MDCT A/B decision */ - const Word16 *Y, /* i: re[0], re[1], ..., re[n/2], im[n/2 - 1], im[n/2 - 2], ..., im[1] */ - Encoder_State *st_fx, /* i/o: Encoder state variable */ - Word32 *cldfbBuf_Ener, - Word16 enerBuffer_exp, - const Word32 brate /* i : current brate, IVAS: nominal bitrate, EVS: st->total_brate */ +Word16 mdct_classifier_fx( /* o: MDCT A/B decision */ + const Word16 *Y, /* i: re[0], re[1], ..., re[n/2], im[n/2 - 1], im[n/2 - 2], ..., im[1] */ + Encoder_State *st_fx, /* i/o: Encoder state variable */ + Word32 *cldfbBuf_Ener, + Word16 enerBuffer_exp, + const Word32 brate /* i : current brate, IVAS: nominal bitrate, EVS: st->total_brate */ ); void noise_est_down_fx( - const Word32 fr_bands[], /* i : per band i energy (contains 2 vectors) */ - Word32 bckr[], /* i/o: per band background noise energy estimate */ - Word32 tmpN[], /* o : temporary noise update */ - Word32 enr[], /* o : averaged energy over both subframes */ - const Word16 min_band, /* i : minimum critical band */ - const Word16 max_band, /* i : maximum critical band */ - Word16 *totalNoise, /* o : noise estimate over all critical bands */ - Word16 Etot, /* i : Energy of current frame */ - Word16 *Etot_last, /* i/o: Energy of last frame Q8 */ - Word16 *Etot_v_h2, /* i/o: Energy variations of noise frames Q8 */ - Word16 Q_new, - const Word32 e_min /* i : minimum energy scaled Q_new + QSCALE */ -); - -void noise_est_fx( - Encoder_State* st_fx, /* i/o: state structure */ - const Word16 old_pitch1, /* i : previous frame OL pitch[1] */ - const Word32 tmpN[], /* i : temporary noise update Q_new + QSCALE */ - const Word16 epsP_h[], /* i : msb prediction error energies Q_r-1 */ - const Word16 epsP_l[], /* i : msb prediction error energies Q_r-1 */ - const Word16 Etot, /* i : total channel E (see find_enr_fx.c) Q8 */ - const Word16 relE, /* i : (VA_CHECK addition) relative frame energy Q8? */ - const Word16 corr_shift, /* i : normalized correlation correction Q15 */ - const Word32 enr[], /* i : averaged energy over both subframes Q_new + Q_SCALE */ - Word32 fr_bands[], /* i : spectrum per critical bands of the current frame Q_new + Q_SCALE */ - Word16* cor_map_sum, /* o : Q8 */ - Word16* ncharX, /* o : IVAS_CODE -> size of ncharX needs validation noise character for sp/mus classifier Qx? */ - Word16* sp_div, /* o : Q_sp_div */ - Word16* Q_sp_div, /* o : Q factor for sp_div */ - Word16* non_staX, /* o : non-stationarity for sp/mus classifier */ - Word16* loc_harm, /* o : multi-harmonicity flag for UV classifier */ - const Word32* lf_E, /* i : per bin energy for low frequencies Q_new + Q_SCALE -2 */ - Word16* st_harm_cor_cnt, /* i/o : 1st harm correlation timer Q0 */ - const Word16 Etot_l_lp, /* i : Smoothed low energy Q8 */ - const Word16 Etot_v_h2, /* i : Energy variations Q8 */ - Word16* bg_cnt, /* i : Background burst length timer Q0 */ - Word16 EspecdB[], /* i/o: log E spectrum (with f=0) of the current frame Q7 for multi harm */ - Word16 Q_new, /* i : SCaling of current frame */ - const Word32 Le_min_scaled, /*i : Minimum energy value in Q_new + Q_SCALE */ - Word16* sp_floor, /* o : noise floor estimate Q7 */ - Word16 S_map[], /* o : short-term correlation map Q7 */ + const Word32 fr_bands[], /* i : per band i energy (contains 2 vectors) */ + Word32 bckr[], /* i/o: per band background noise energy estimate */ + Word32 tmpN[], /* o : temporary noise update */ + Word32 enr[], /* o : averaged energy over both subframes */ + const Word16 min_band, /* i : minimum critical band */ + const Word16 max_band, /* i : maximum critical band */ + Word16 *totalNoise, /* o : noise estimate over all critical bands */ + Word16 Etot, /* i : Energy of current frame */ + Word16 *Etot_last, /* i/o: Energy of last frame Q8 */ + Word16 *Etot_v_h2, /* i/o: Energy variations of noise frames Q8 */ + Word16 Q_new, + const Word32 e_min /* i : minimum energy scaled Q_new + QSCALE */ +); + +void noise_est_fx( + Encoder_State *st_fx, /* i/o: state structure */ + const Word16 old_pitch1, /* i : previous frame OL pitch[1] */ + const Word32 tmpN[], /* i : temporary noise update Q_new + QSCALE */ + const Word16 epsP_h[], /* i : msb prediction error energies Q_r-1 */ + const Word16 epsP_l[], /* i : msb prediction error energies Q_r-1 */ + const Word16 Etot, /* i : total channel E (see find_enr_fx.c) Q8 */ + const Word16 relE, /* i : (VA_CHECK addition) relative frame energy Q8? */ + const Word16 corr_shift, /* i : normalized correlation correction Q15 */ + const Word32 enr[], /* i : averaged energy over both subframes Q_new + Q_SCALE */ + Word32 fr_bands[], /* i : spectrum per critical bands of the current frame Q_new + Q_SCALE */ + Word16 *cor_map_sum, /* o : Q8 */ + Word16 *ncharX, /* o : IVAS_CODE -> size of ncharX needs validation noise character for sp/mus classifier Qx? */ + Word16 *sp_div, /* o : Q_sp_div */ + Word16 *Q_sp_div, /* o : Q factor for sp_div */ + Word16 *non_staX, /* o : non-stationarity for sp/mus classifier */ + Word16 *loc_harm, /* o : multi-harmonicity flag for UV classifier */ + const Word32 *lf_E, /* i : per bin energy for low frequencies Q_new + Q_SCALE -2 */ + Word16 *st_harm_cor_cnt, /* i/o : 1st harm correlation timer Q0 */ + const Word16 Etot_l_lp, /* i : Smoothed low energy Q8 */ + const Word16 Etot_v_h2, /* i : Energy variations Q8 */ + Word16 *bg_cnt, /* i : Background burst length timer Q0 */ + Word16 EspecdB[], /* i/o: log E spectrum (with f=0) of the current frame Q7 for multi harm */ + Word16 Q_new, /* i : SCaling of current frame */ + const Word32 Le_min_scaled, /*i : Minimum energy value in Q_new + Q_SCALE */ + Word16 *sp_floor, /* o : noise floor estimate Q7 */ + Word16 S_map[], /* o : short-term correlation map Q7 */ #ifdef IVAS_CODE - STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure */ - FRONT_VAD_ENC_HANDLE hFrontVad, /* i/o: front-VAD handle */ + STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure */ + FRONT_VAD_ENC_HANDLE hFrontVad, /* i/o: front-VAD handle */ #endif - const Word16 ini_frame /* i : Frame number (init) */ + const Word16 ini_frame /* i : Frame number (init) */ ); void noise_est_pre_fx( - const Word16 Etot, /* i : Energy of current frame */ - const Word16 ini_frame_fx, /* i : Frame number (init) */ - NOISE_EST_HANDLE hNoiseEst, /* i/o: Noise estimation handle */ - const Word16 idchan, /* i : channel ID */ - const Word16 element_mode, /* i : element mode */ - const Word16 last_element_mode /* i : last element mode */ + const Word16 Etot, /* i : Energy of current frame */ + const Word16 ini_frame_fx, /* i : Frame number (init) */ + NOISE_EST_HANDLE hNoiseEst, /* i/o: Noise estimation handle */ + const Word16 idchan, /* i : channel ID */ + const Word16 element_mode, /* i : element mode */ + const Word16 last_element_mode /* i : last element mode */ ); void pitch_ol2_fx( - const Word16 pit_min, /* i : minimum pitch value (20 or 29) */ - const Word16 pitch_ol, /* i : pitch to be improved */ - Word16 *pitch_fr_fx, /* o : adjusted 1/4 fractional pitch */ /*Q7 */ - Word16 *voicing_fr_fx, /* o : adjusted 1/4 fractional voicing */ /*Q15 */ - const Word16 pos, /* i : position in frame where to calculate the improv. */ - const Word16 *wsp_fx, /* i : weighted speech for current frame and look-ahead */ /*Q_new-1+shift*/ - const Word16 delta /* i : delta for pitch search (2 or 7) */ + const Word16 pit_min, /* i : minimum pitch value (20 or 29) */ + const Word16 pitch_ol, /* i : pitch to be improved */ + Word16 *pitch_fr_fx, + /* o : adjusted 1/4 fractional pitch */ /*Q7 */ + Word16 *voicing_fr_fx, + /* o : adjusted 1/4 fractional voicing */ /*Q15 */ + const Word16 pos, /* i : position in frame where to calculate the improv. */ + const Word16 *wsp_fx, + /* i : weighted speech for current frame and look-ahead */ /*Q_new-1+shift*/ + const Word16 delta /* i : delta for pitch search (2 or 7) */ ); void pitch_ol_fx( - Word16 pitch[3], /* o : open loop pitch lag for each half-frame in range [29,231] Q0 */ - Word16 voicing[3], /* o : maximum normalized correlation for each half-frame in [0,1.0[ Q15 */ - Word16 *old_pitch, /* i/o: pitch of the 2nd half-frame of previous frame (i.e. pitch[1]) Q0 */ - Word16 *old_corr, /* i/o: correlation of old_pitch (i.e. voicing[1] or corr_mean) Q15 */ - Word16 corr_shift, /* i : normalized correlation correction Q15 */ - Word16 *old_thres, /* i/o: maximum correlation weighting with respect to past frame pitch Q15 */ - Word16 *delta_pit, /* i/o: old pitch extrapolation correction in range [-14,+14] Q0 */ - Word16 *st_old_wsp2, /* i/o: weighted speech memory qwsp */ - const Word16 *wsp, /* i : weighted speech for current frame and look-ahead qwsp */ - Word16 mem_decim2[3], /* i/o: wsp decimation filter memory qwsp */ - const Word16 relE, /* i : relative frame energy Q8 */ - const Word16 last_class, /* i : frame classification of last frame */ - const Word16 bwidth, /* i : bandwidth */ - const Word16 Opt_SC_VBR /* i : SC-VBR flag */ + Word16 pitch[3], /* o : open loop pitch lag for each half-frame in range [29,231] Q0 */ + Word16 voicing[3], /* o : maximum normalized correlation for each half-frame in [0,1.0[ Q15 */ + Word16 *old_pitch, /* i/o: pitch of the 2nd half-frame of previous frame (i.e. pitch[1]) Q0 */ + Word16 *old_corr, /* i/o: correlation of old_pitch (i.e. voicing[1] or corr_mean) Q15 */ + Word16 corr_shift, /* i : normalized correlation correction Q15 */ + Word16 *old_thres, /* i/o: maximum correlation weighting with respect to past frame pitch Q15 */ + Word16 *delta_pit, /* i/o: old pitch extrapolation correction in range [-14,+14] Q0 */ + Word16 *st_old_wsp2, /* i/o: weighted speech memory qwsp */ + const Word16 *wsp, /* i : weighted speech for current frame and look-ahead qwsp */ + Word16 mem_decim2[3], /* i/o: wsp decimation filter memory qwsp */ + const Word16 relE, /* i : relative frame energy Q8 */ + const Word16 last_class, /* i : frame classification of last frame */ + const Word16 bwidth, /* i : bandwidth */ + const Word16 Opt_SC_VBR /* i : SC-VBR flag */ ); void pitch_ol_init_fx( - Word16 *old_thres, /* o : threshold for reinforcement of past pitch influence */ - Word16 *old_pitch, /* o : pitch of the 2nd half-frame of previous frame */ - Word16 *delta_pit, /* o : pitch evolution extrapolation */ - Word16 *old_corr /* o : correlation */ + Word16 *old_thres, /* o : threshold for reinforcement of past pitch influence */ + Word16 *old_pitch, /* o : pitch of the 2nd half-frame of previous frame */ + Word16 *delta_pit, /* o : pitch evolution extrapolation */ + Word16 *old_corr /* o : correlation */ ); void Preemph_scaled( - Word16 new_speech[], /* i : Speech to scale already on 14 bits*/ - Word16 *Q_new, /* o : Scaling factor */ - Word16 *mem_preemph, /* i/o: Preemph memory */ - Word16 *Q_max, /* i/o: Q_new limitation */ - const Word16 Preemph_factor, /* i : Preemphasis factor Q15 */ - const Word16 bits, /* i : Bit to remove from the output to (15-bits)*/ - const Word16 bit1, /* i : Limit the output scaling to ((15-bits)-bit1) bits */ - const Word16 L_Q_mem, /* i : Number of old scaling to take into account */ - const Word16 Lframe, /* i : Frame length */ - const Word16 last_coder_type, /* i : coder_type */ - const Word16 Search_scaling /* i : enable the search of a proper scaling factor*/ + Word16 new_speech[], /* i : Speech to scale already on 14 bits*/ + Word16 *Q_new, /* o : Scaling factor */ + Word16 *mem_preemph, /* i/o: Preemph memory */ + Word16 *Q_max, /* i/o: Q_new limitation */ + const Word16 Preemph_factor, /* i : Preemphasis factor Q15 */ + const Word16 bits, /* i : Bit to remove from the output to (15-bits)*/ + const Word16 bit1, /* i : Limit the output scaling to ((15-bits)-bit1) bits */ + const Word16 L_Q_mem, /* i : Number of old scaling to take into account */ + const Word16 Lframe, /* i : Frame length */ + const Word16 last_coder_type, /* i : coder_type */ + const Word16 Search_scaling /* i : enable the search of a proper scaling factor*/ ); void Scale_mem_enc( - Word16 Q_exp, /* i : Diff scaling factor */ - Word16 *old_speech16k, /* i/o: Speech memory */ - Word16 *old_exc, /* i/o: excitation memory */ - Word16 *old_bwe_exc, /* i/o: BWE excitation memory */ - Word16 *mem_w0, /* i/o: target vector memory */ - Word16 *mem_syn, /* i/o: synthesis memory */ - Word16 *mem_syn2, /* i/o: synthesis memory */ - Word16 *mem_deemp_preQ_fx, /*i/o: deemphasis memory for the high rate celp codec */ - Word16 *last_exc_dct_in, - Word16 *old_input_lp -); - -Word32 Scale_mem_pre_proc( /* o : Min energy scaled */ - Word16 ini_frame_fx, /* i : Frame number */ - Word16 Q_exp, /* i : Diff scaling factor */ - Word16 *Q_new, /* i/o: Absolute scaling factor */ - Word16 *old_speech, /* i/o: Speech memory */ - Word16 *mem_wsp, /* i/o: wsp vector memory */ - Word32 *enrO, /* i/o: Enr mem */ - Word32 *bckr, /* i/o: Back ground_fx ener mem */ - Word32 *ave_enr, /* i/o: Ave_enr mem */ - Word32 *ave_enr2, /* i/o: Ave_enr2 mem */ - Word32 *st_fr_bands1, /* i/o: spectrum per critical bands of the previous frame */ - Word32 *st_fr_bands2, /* i/o: spectrum per critical bands 2 frames ago */ - Word32 *st_Bin_E_old -); + Word16 Q_exp, /* i : Diff scaling factor */ + Word16 *old_speech16k, /* i/o: Speech memory */ + Word16 *old_exc, /* i/o: excitation memory */ + Word16 *old_bwe_exc, /* i/o: BWE excitation memory */ + Word16 *mem_w0, /* i/o: target vector memory */ + Word16 *mem_syn, /* i/o: synthesis memory */ + Word16 *mem_syn2, /* i/o: synthesis memory */ + Word16 *mem_deemp_preQ_fx, /*i/o: deemphasis memory for the high rate celp codec */ + Word16 *last_exc_dct_in, + Word16 *old_input_lp ); + +Word32 Scale_mem_pre_proc( /* o : Min energy scaled */ + Word16 ini_frame_fx, /* i : Frame number */ + Word16 Q_exp, /* i : Diff scaling factor */ + Word16 *Q_new, /* i/o: Absolute scaling factor */ + Word16 *old_speech, /* i/o: Speech memory */ + Word16 *mem_wsp, /* i/o: wsp vector memory */ + Word32 *enrO, /* i/o: Enr mem */ + Word32 *bckr, /* i/o: Back ground_fx ener mem */ + Word32 *ave_enr, /* i/o: Ave_enr mem */ + Word32 *ave_enr2, /* i/o: Ave_enr2 mem */ + Word32 *st_fr_bands1, /* i/o: spectrum per critical bands of the previous frame */ + Word32 *st_fr_bands2, /* i/o: spectrum per critical bands 2 frames ago */ + Word32 *st_Bin_E_old ); void Scale_wsp( - Word16 *wsp, /* i : Weigthed speech */ - Word16 *old_wsp_max, /* i : Last weigthed speech maximal valu */ - Word16 *shift, /* i/o: Scaling of current frame */ - Word16 *Q_exp, /* i/o: Differential scaling factor */ - Word16 *old_wsp_shift, /* i/o: Last wsp scaling */ - Word16 *old_wsp, /* i/o: Old weighted speech buffer */ - Word16 *mem_decim2, /* i/o: Decimation buffer */ - Word16 *old_wsp12k8, /* i/o: wsp memory @ 12.8 kHz used in pitol2 */ - const Word16 Len_p_look /* i : L_frame + look ahead */ -); - -Word16 signal_clas_fx( /* o : classification for current frames */ - Encoder_State* st, /* i/o: encoder state structure */ - const Word16* speech, /* i : pointer to speech signal for E computation */ - const Word32* ee, /* i : lf/hf E ration for 2 half-frames */ - const Word16 relE, /* i : frame relative E to the long term average */ - const Word16 L_look, /* i : look-ahead */ - Word16* uc_clas /* o : temporary classification used in music/speech class*/ + Word16 *wsp, /* i : Weigthed speech */ + Word16 *old_wsp_max, /* i : Last weigthed speech maximal valu */ + Word16 *shift, /* i/o: Scaling of current frame */ + Word16 *Q_exp, /* i/o: Differential scaling factor */ + Word16 *old_wsp_shift, /* i/o: Last wsp scaling */ + Word16 *old_wsp, /* i/o: Old weighted speech buffer */ + Word16 *mem_decim2, /* i/o: Decimation buffer */ + Word16 *old_wsp12k8, /* i/o: wsp memory @ 12.8 kHz used in pitol2 */ + const Word16 Len_p_look /* i : L_frame + look ahead */ +); + +Word16 signal_clas_fx( /* o : classification for current frames */ + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 *speech, /* i : pointer to speech signal for E computation */ + const Word32 *ee, /* i : lf/hf E ration for 2 half-frames */ + const Word16 relE, /* i : frame relative E to the long term average */ + const Word16 L_look, /* i : look-ahead */ + Word16 *uc_clas /* o : temporary classification used in music/speech class*/ ); void speech_music_classif_fx( - Encoder_State* st, /* i/o: state structure */ - const Word16* new_inp, /* i : new input signal */ - const Word16* inp, /* i : input signal to locate attach position */ - const Word16 localVAD_HE_SAD, /* i : HE-SAD flag without hangover */ - const Word16 lsp_new[M], /* i : LSPs in current frame Q15 */ - const Word16 cor_map_sum, /* i : correlation map sum (from multi-harmonic anal.)Q8*/ - const Word32 epsP[M + 1], /* i : LP prediciton error Q_esp*/ - const Word32 PS[], /* i : energy spectrum Q_new+QSCALE*/ - const Word16 Etot, /* i : total frame energy Q8 */ - const Word16 old_cor, /* i : max correlation from previous frame Q15 */ - Word16* attack_flag, /* o : flag to indicate if attack is to be treated by TC or GSC */ - Word16 non_sta, /* i : unbound non-stationarity for sp/mus classifier */ - Word16 relE, /* i : relative frame energy */ - Word16 Q_esp, /* i : scaling of esP */ - Word16 Q_inp, /* i : scaling of input */ - Word16* high_lpn_flag_ptr, /* o : noise log prob flag for NOISE_EST */ - Word16 flag_spitch /* i : flag to indicate very short stable pitch */ + Encoder_State *st, /* i/o: state structure */ + const Word16 *new_inp, /* i : new input signal */ + const Word16 *inp, /* i : input signal to locate attach position */ + const Word16 localVAD_HE_SAD, /* i : HE-SAD flag without hangover */ + const Word16 lsp_new[M], /* i : LSPs in current frame Q15 */ + const Word16 cor_map_sum, /* i : correlation map sum (from multi-harmonic anal.)Q8*/ + const Word32 epsP[M + 1], /* i : LP prediciton error Q_esp*/ + const Word32 PS[], /* i : energy spectrum Q_new+QSCALE*/ + const Word16 Etot, /* i : total frame energy Q8 */ + const Word16 old_cor, /* i : max correlation from previous frame Q15 */ + Word16 *attack_flag, /* o : flag to indicate if attack is to be treated by TC or GSC */ + Word16 non_sta, /* i : unbound non-stationarity for sp/mus classifier */ + Word16 relE, /* i : relative frame energy */ + Word16 Q_esp, /* i : scaling of esP */ + Word16 Q_inp, /* i : scaling of input */ + Word16 *high_lpn_flag_ptr, /* o : noise log prob flag for NOISE_EST */ + Word16 flag_spitch /* i : flag to indicate very short stable pitch */ ); void StableHighPitchDetect_fx( - Word16 *flag_spitch, /* o : flag to indicate very short stable pitch */ - Word16 pitch[], /* i/o: OL pitch buffer */ - const Word16 voicing[], /* i : OL pitch gains */ - const Word16 wsp[], /* i : weighted speech */ - const Word16 localVAD, - Word16 *voicing_sm, /* i/o: smoothed open-loop pitch gains */ - Word16 *voicing0_sm, /* i/o: smoothed high pitch gains */ - Word16 *LF_EnergyRatio_sm, /* i/o: smoothed [0, 300Hz] relative peak energy*/ - Word16 *predecision_flag, /* i/o: predecision flag */ - Word32 *diff_sm, /* i/o: smoothed pitch frequency difference */ - Word32 *energy_sm, /* i/o: smoothed energy around pitch frequency */ - Word16 Q_new, - Word16 EspecdB[] -); + Word16 *flag_spitch, /* o : flag to indicate very short stable pitch */ + Word16 pitch[], /* i/o: OL pitch buffer */ + const Word16 voicing[], /* i : OL pitch gains */ + const Word16 wsp[], /* i : weighted speech */ + const Word16 localVAD, + Word16 *voicing_sm, /* i/o: smoothed open-loop pitch gains */ + Word16 *voicing0_sm, /* i/o: smoothed high pitch gains */ + Word16 *LF_EnergyRatio_sm, /* i/o: smoothed [0, 300Hz] relative peak energy*/ + Word16 *predecision_flag, /* i/o: predecision flag */ + Word32 *diff_sm, /* i/o: smoothed pitch frequency difference */ + Word32 *energy_sm, /* i/o: smoothed energy around pitch frequency */ + Word16 Q_new, + Word16 EspecdB[] ); void swb_bwe_enc_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - Word16 *old_input_12k8_fx, /* i : i signal @12.8kHz for SWB BWE */ - Word16 *old_input_16k_fx, /* i : i signal @16kHz for SWB BWE */ - const Word16 *old_syn_12k8_16k_fx, /* i : ACELP core synthesis at 12.8kHz or 16kHz */ - const Word16 *new_swb_speech_fx, /* i : original i signal at 32kHz */ - Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz */ - const Word16 coder_type, /* i : coding type */ - Word16 Q_shb_speech, - Word16 Q_slb_speech -); + Encoder_State *st_fx, /* i/o: encoder state structure */ + Word16 *old_input_12k8_fx, /* i : i signal @12.8kHz for SWB BWE */ + Word16 *old_input_16k_fx, /* i : i signal @16kHz for SWB BWE */ + const Word16 *old_syn_12k8_16k_fx, /* i : ACELP core synthesis at 12.8kHz or 16kHz */ + const Word16 *new_swb_speech_fx, /* i : original i signal at 32kHz */ + Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz */ + const Word16 coder_type, /* i : coding type */ + Word16 Q_shb_speech, + Word16 Q_slb_speech ); void swb_CNG_enc_fx( - Encoder_State *st_fx, /* i/o: State structure */ - const Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz */ - const Word16 *syn_12k8_16k_fx /* i : ACELP core synthesis at 12.8kHz or 16kHz */ + Encoder_State *st_fx, /* i/o: State structure */ + const Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz */ + const Word16 *syn_12k8_16k_fx /* i : ACELP core synthesis at 12.8kHz or 16kHz */ ); void swb_pre_proc_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 *input_fx, /* i : original i signal */ - Word16 *new_swb_speech_fx, /* o : original i signal at 32kHz */ - Word16 *shb_speech_fx, /* o : SHB target signal (6-14kHz) at 16kHz */ - Word16 *Q_shb_spch /* o : shb target signal Q factor */ - , Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX] /* i : real buffer */ - , Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX] /* i : imag buffer */ - , const CLDFB_SCALE_FACTOR *cldfbScale /* i : scale data of real and imag CLDFB buffers */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word16 *input_fx, /* i : original i signal */ + Word16 *new_swb_speech_fx, /* o : original i signal at 32kHz */ + Word16 *shb_speech_fx, /* o : SHB target signal (6-14kHz) at 16kHz */ + Word16 *Q_shb_spch /* o : shb target signal Q factor */ + , + Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX] /* i : real buffer */ + , + Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX] /* i : imag buffer */ + , + const CLDFB_SCALE_FACTOR *cldfbScale /* i : scale data of real and imag CLDFB buffers */ ); void swb_tbe_enc_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 coder_type, /* i : coding type */ - Word16 *new_speech_fx, /* i : original i signal */ - Word32 *bwe_exc_extended_fx, /* i : bandwidth extended excitation */ - const Word16 voice_factors_fx[], /* i : voicing factors */ - Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE */ - Word16 *Q_white_exc, /* o : generated white noise for FB Q factor */ - Word16 Q_bwe_exc, /* i : bandwidth extended excitation Q factor */ - Word16 Q_shb, /* i : SHB target Q factor */ - Word16 *voicing_fx, /* i : OL maximum normalized correlation */ - const Word16 pitch_buf[] /* i : pitch for each subframe */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word16 coder_type, /* i : coding type */ + Word16 *new_speech_fx, /* i : original i signal */ + Word32 *bwe_exc_extended_fx, /* i : bandwidth extended excitation */ + const Word16 voice_factors_fx[], /* i : voicing factors */ + Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE */ + Word16 *Q_white_exc, /* o : generated white noise for FB Q factor */ + Word16 Q_bwe_exc, /* i : bandwidth extended excitation Q factor */ + Word16 Q_shb, /* i : SHB target Q factor */ + Word16 *voicing_fx, /* i : OL maximum normalized correlation */ + const Word16 pitch_buf[] /* i : pitch for each subframe */ ); void tbe_write_bitstream_fx( - Encoder_State *st_fx /* i/o: encoder state structure */ + Encoder_State *st_fx /* i/o: encoder state structure */ ); Word16 tfaEnc_TBE_fx( - const Word32* enr, - const Word16 last_core, - const Word16* voicing, /* Q15 */ - const Word16* pitch_buf, /* Q6 */ - const Word16 Q_enr -); - -Word32 VAD_Log2(Word32 i_s32Val, - Word16 i_s16Q -); - -Word32 VAD_L_ADD(Word32 s32Mantissa1, - Word16 i_tExp1, - Word32 s32Mantissa2, - Word16 i_tExp2, - Word16 *s16Exp -); - -Word32 VAD_L_div(Word32 L_var1, - Word32 L_var2, - Word16 Q_L_var1, - Word16 Q_L_var2, - Word16 *Q_OUT -); + const Word32 *enr, + const Word16 last_core, + const Word16 *voicing, /* Q15 */ + const Word16 *pitch_buf, /* Q6 */ + const Word16 Q_enr ); + +Word32 VAD_Log2( Word32 i_s32Val, + Word16 i_s16Q ); + +Word32 VAD_L_ADD( Word32 s32Mantissa1, + Word16 i_tExp1, + Word32 s32Mantissa2, + Word16 i_tExp2, + Word16 *s16Exp ); + +Word32 VAD_L_div( Word32 L_var1, + Word32 L_var2, + Word16 Q_L_var1, + Word16 Q_L_var2, + Word16 *Q_OUT ); void vad_param_updt_fx( - Encoder_State* st_fx, /* i/o: state structure */ - const Word16 old_pitch1, /* i : OL pitch value from last frame */ - const Word16 corr_shift, /* i : correlation shift Q15*/ - const Word16 corr_shiftR, /* i : correlation shift */ - const Word16 Az[], /* i: a coeffs Q12 */ - FRONT_VAD_ENC_HANDLE hFrontVad[], /* i/o: front-VAD handles */ - const Word16 n_channels /* i : number of channels */ + Encoder_State *st_fx, /* i/o: state structure */ + const Word16 old_pitch1, /* i : OL pitch value from last frame */ + const Word16 corr_shift, /* i : correlation shift Q15*/ + const Word16 corr_shiftR, /* i : correlation shift */ + const Word16 Az[], /* i: a coeffs Q12 */ + FRONT_VAD_ENC_HANDLE hFrontVad[], /* i/o: front-VAD handles */ + const Word16 n_channels /* i : number of channels */ ); void wb_bwe_enc_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 *new_wb_speech_fx, /* i : original i signal at 16kHz */ - Word16 coder_type /* i : coding type */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word16 *new_wb_speech_fx, /* i : original i signal at 16kHz */ + Word16 coder_type /* i : coding type */ ); void wb_pre_proc_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 *new_inp_resamp16k, /* i : original i signal */ - Word16 *hb_speech /* o : HB target signal (6-8kHz) at 16kHz */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word16 *new_inp_resamp16k, /* i : original i signal */ + Word16 *hb_speech /* o : HB target signal (6-8kHz) at 16kHz */ ); void wb_tbe_enc_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 coder_type, /* i : coding type */ - const Word16 *hb_speech, /* i : HB target signal (6-8kHz) at 16kHz */ - const Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation */ - const Word16 Q_new, /* i : i HB speech Q factor */ - const Word16 voice_factors[], /* i : voicing factors */ - const Word16 pitch_buf[], /* i : pitch for each subframe */ - const Word16 voicing[] /* i : OL maximum normalized correlation */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word16 coder_type, /* i : coding type */ + const Word16 *hb_speech, /* i : HB target signal (6-8kHz) at 16kHz */ + const Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation */ + const Word16 Q_new, /* i : i HB speech Q factor */ + const Word16 voice_factors[], /* i : voicing factors */ + const Word16 pitch_buf[], /* i : pitch for each subframe */ + const Word16 voicing[] /* i : OL maximum normalized correlation */ ); Word16 wb_vad_fx( - Encoder_State* st_fx, /* i/o: encoder state structure */ - const Word32 fr_bands[], /* i : per band i energy (contains 2 vectors) Q_new+QSCALE*/ - Word16* noisy_speech_HO, /* o : SC-VBR noisy speech HO flag */ - Word16* clean_speech_HO, /* o : SC-VBR clean speech HO flag */ - Word16* NB_speech_HO, /* o : SC-VBR NB speech HO flag */ - Word16* snr_sum_he, /* o : Output snr_sum as weighted spectral measure*/ - Word16* localVAD_HE_SAD, - Word8* flag_noisy_speech_snr, /* o : */ - const Word16 Q_new, /* i : scaling factor Q0 */ - VAD_HANDLE hVAD, /* i/o: VAD data handle */ - NOISE_EST_HANDLE hNoiseEst, /* i : Noise estimation handle */ - Word16 lp_speech, /* i : long term active speech energy average */ - Word16 lp_noise /* i : long term noise energy */ -); - -Word32 construct_snr_thresh_fx(Word16 sp_center[], /*(i) spectral center*/ - Word32 snr_flux, /*(i) snr flux*/ - Word32 lt_snr, /*(i) long time time domain snr*/ - Word32 l_snr, /*(i) long time frequency domain snr*/ - Word32 continuous_speech_num, /*(i) amount of continuous speech frames*/ - Word16 continuous_noise_num, /*(i) amount of continuous noise frames*/ - Word32 fg_energy_est_start, /*(i) whether if estimated energy*/ - Word16 bw_index /*(i) band width index*/ + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word32 fr_bands[], /* i : per band i energy (contains 2 vectors) Q_new+QSCALE*/ + Word16 *noisy_speech_HO, /* o : SC-VBR noisy speech HO flag */ + Word16 *clean_speech_HO, /* o : SC-VBR clean speech HO flag */ + Word16 *NB_speech_HO, /* o : SC-VBR NB speech HO flag */ + Word16 *snr_sum_he, /* o : Output snr_sum as weighted spectral measure*/ + Word16 *localVAD_HE_SAD, + Word8 *flag_noisy_speech_snr, /* o : */ + const Word16 Q_new, /* i : scaling factor Q0 */ + VAD_HANDLE hVAD, /* i/o: VAD data handle */ + NOISE_EST_HANDLE hNoiseEst, /* i : Noise estimation handle */ + Word16 lp_speech, /* i : long term active speech energy average */ + Word16 lp_noise /* i : long term noise energy */ +); + +Word32 construct_snr_thresh_fx( Word16 sp_center[], /*(i) spectral center*/ + Word32 snr_flux, /*(i) snr flux*/ + Word32 lt_snr, /*(i) long time time domain snr*/ + Word32 l_snr, /*(i) long time frequency domain snr*/ + Word32 continuous_speech_num, /*(i) amount of continuous speech frames*/ + Word16 continuous_noise_num, /*(i) amount of continuous noise frames*/ + Word32 fg_energy_est_start, /*(i) whether if estimated energy*/ + Word16 bw_index /*(i) band width index*/ ); void sc_vbr_enc_init_fx( - SC_VBR_ENC_HANDLE hSC_VBR /* i/o: SC-VBR encoder handle */ + SC_VBR_ENC_HANDLE hSC_VBR /* i/o: SC-VBR encoder handle */ ); void updt_enc_common_fx( - Encoder_State* st, /* i/o: encoder state structure */ - const Word16 Etot, /* i : total energy */ - const Word16 Q_new /* i : CUrrent frame scaling */ + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 Etot, /* i : total energy */ + const Word16 Q_new /* i : CUrrent frame scaling */ ); -void attenuateNbSpectrum_fx(Word16 L_frame, Word32 *spectrum); +void attenuateNbSpectrum_fx( Word16 L_frame, Word32 *spectrum ); -Word16 corr_xy1_fx( /* o : pitch gain (0..GAIN_PIT_MAX) */ - const Word16 xn_1[], /* i : target signal */ - const Word16 y1_1[], /* i : filtered adaptive codebook excitation */ - Word16 g_corr[], /* o : correlations and -2 */ - const Word16 L_subfr, /* i : vector length */ - const Word16 norm_flag /* i : flag for constraining pitch contribution */ +Word16 corr_xy1_fx( /* o : pitch gain (0..GAIN_PIT_MAX) */ + const Word16 xn_1[], /* i : target signal */ + const Word16 y1_1[], /* i : filtered adaptive codebook excitation */ + Word16 g_corr[], /* o : correlations and -2 */ + const Word16 L_subfr, /* i : vector length */ + const Word16 norm_flag /* i : flag for constraining pitch contribution */ #ifdef BASOP_NOGLOB - , Flag* Overflow_out /* o : propagating the Overflow flag to upper level */ + , + Flag *Overflow_out /* o : propagating the Overflow flag to upper level */ #endif ); -Word16 E_ACELP_indexing_fx(const Word16 code[], const PulseConfig *config, Word16 num_tracks, Word16 prm[]); -void fcb_pulse_track_joint_fx(UWord16 *idxs, Word16 wordcnt, UWord32 *index_n, Word16 *pulse_num, Word16 track_num); +Word16 E_ACELP_indexing_fx( const Word16 code[], const PulseConfig *config, Word16 num_tracks, Word16 prm[] ); +void fcb_pulse_track_joint_fx( UWord16 *idxs, Word16 wordcnt, UWord32 *index_n, Word16 *pulse_num, Word16 track_num ); -Word16 gain_quant_fx( /* o: quantization index */ - Word32 *gain, /* i/o: quantized gain */ - Word16 *gain16, - const Word16 c_min, /* i: log10 of lower limit in Q14 */ - const Word16 c_max, /* i: log10 of upper limit in Q13 */ - const Word16 bits, /* i: number of bits to quantize */ - Word16 *expg -); +Word16 gain_quant_fx( /* o: quantization index */ + Word32 *gain, /* i/o: quantized gain */ + Word16 *gain16, + const Word16 c_min, /* i: log10 of lower limit in Q14 */ + const Word16 c_max, /* i: log10 of upper limit in Q13 */ + const Word16 bits, /* i: number of bits to quantize */ + Word16 *expg ); void gsc_enc_fx( - Encoder_State* st_fx, /* i/o: State structure */ - Word16 res_dct_in[], /* i : dct of residual signal */ - Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation */ - const Word16 Diff_len, - const Word16 bits_used, - const Word16 nb_subfr, - Word16* lsf_new, /* i : ISFs at the end of the frame */ - Word16* exc_wo_nf, /* o : excitation (in f domain) without noisefill */ - Word16* tmp_noise, /* o : noise energy */ - Word16 Q_exc -); + Encoder_State *st_fx, /* i/o: State structure */ + Word16 res_dct_in[], /* i : dct of residual signal */ + Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation */ + const Word16 Diff_len, + const Word16 bits_used, + const Word16 nb_subfr, + Word16 *lsf_new, /* i : ISFs at the end of the frame */ + Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill */ + Word16 *tmp_noise, /* o : noise energy */ + Word16 Q_exc ); void LPDmem_enc_init_fx( - LPD_state_HANDLE hLPDmem /* i/o: LP memories */ + LPD_state_HANDLE hLPDmem /* i/o: LP memories */ ); void lsf_end_enc_fx( - Encoder_State* st, /* i/o: encoder state structure */ - const Word16* lsf, /* i : LSF in the frequency domain (0..6400) */ - Word16* qlsf, /* o : quantized LSF */ - const Word16 nBits_in, /* i : number of bits to spend on ISF quantization */ - const Word16 coder_type_org, /* i : coding type */ - Word16 Q_ener, /* i : Q valuen for Bin_Ener */ - Word16 force_sf, /* i : Force safety-net usage if coding type supports */ - Word16* lpc_param, - Word16* no_indices, - Word16* bits_param_lpc, - Word16 coder_type_raw /* i : Coder type (LSF coder_type have some special cases)*/ + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 *lsf, /* i : LSF in the frequency domain (0..6400) */ + Word16 *qlsf, /* o : quantized LSF */ + const Word16 nBits_in, /* i : number of bits to spend on ISF quantization */ + const Word16 coder_type_org, /* i : coding type */ + Word16 Q_ener, /* i : Q valuen for Bin_Ener */ + Word16 force_sf, /* i : Force safety-net usage if coding type supports */ + Word16 *lpc_param, + Word16 *no_indices, + Word16 *bits_param_lpc, + Word16 coder_type_raw /* i : Coder type (LSF coder_type have some special cases)*/ #ifdef LSF_RE_USE_SECONDARY_CHANNEL - , const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ + , + const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ #endif ); @@ -649,8 +643,7 @@ void Mode2_abs_pit_enc_fx( Word16 pit_min, Word16 pit_fr1, Word16 pit_fr2, - Word16 pit_res_max -); + Word16 pit_res_max ); void Mode2_delta_pit_enc_fx( Word16 T0, /* i : integer pitch lag */ @@ -662,84 +655,82 @@ void Mode2_delta_pit_enc_fx( ); void norm_corr_fx( - const Word16 exc[], /* i : excitation buffer Q_new*/ - const Word16 xn[], /* i : target signal Q_new-1+shift*/ - const Word16 h[], /* i : weighted synthesis filter impulse response Q(14+shift)*/ - const Word16 t_min, /* i : minimum value of searched range */ - const Word16 t_max, /* i : maximum value of searched range */ - Word16 ncorr[], /* o : normalized correlation Q15 */ - const Word16 L_subfr /* i : subframe size */ + const Word16 exc[], /* i : excitation buffer Q_new*/ + const Word16 xn[], /* i : target signal Q_new-1+shift*/ + const Word16 h[], /* i : weighted synthesis filter impulse response Q(14+shift)*/ + const Word16 t_min, /* i : minimum value of searched range */ + const Word16 t_max, /* i : maximum value of searched range */ + Word16 ncorr[], /* o : normalized correlation Q15 */ + const Word16 L_subfr /* i : subframe size */ ); Word16 peak_avrg_ratio_fx( const Word32 total_brate, - const Word32 *input_hi_fx, /* i : i signal */ - const Word16 length, /* i : number of coefficients */ - Word16 *mode_count, /* i/o: HQ_HARMONIC mode count */ - Word16 *mode_count1, /* i/o: HQ_NORMAL mode count */ - Word16 Q_coeff -); + const Word32 *input_hi_fx, /* i : i signal */ + const Word16 length, /* i : number of coefficients */ + Word16 *mode_count, /* i/o: HQ_HARMONIC mode count */ + Word16 *mode_count1, /* i/o: HQ_NORMAL mode count */ + Word16 Q_coeff ); void pit16k_Q_enc_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 nBits, /* i : # of Q bits */ - const Word16 limit_flag, /* i : restrained(0) or extended(1) Q limits */ - const Word16 T0, /* i : integer pitch lag */ - const Word16 T0_frac, /* i : pitch fraction */ - Word16 *T0_min, /* i/o: delta search min */ - Word16 *T0_max /* o : delta search max */ -); - -Word16 pitch_fr4_fx( /* o : chosen integer pitch lag */ - const Word16 exc[], /* i : excitation buffer Q_new*/ - const Word16 xn[], /* i : target signal Q_new-1+shift*/ - const Word16 h[], /* i : weighted synthesis filter impulse response Q(14+shift)*/ - const Word16 t0_min, /* i : minimum value in the searched range. Q0*/ - const Word16 t0_max, /* i : maximum value in the searched range. Q0*/ - Word16 *pit_frac, /* o : chosen fraction (0, 1, 2 or 3) */ - const Word16 i_subfr, /* i : flag to first subframe */ - const Word16 limit_flag, /* i : flag for limits (0=restrained, 1=extended) */ - const Word16 t0_fr2, /* i : minimum value for resolution 1/2 */ - const Word16 t0_fr1, /* i : minimum value for resolution 1 */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 L_subfr /* i : size of subframe */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 nBits, /* i : # of Q bits */ + const Word16 limit_flag, /* i : restrained(0) or extended(1) Q limits */ + const Word16 T0, /* i : integer pitch lag */ + const Word16 T0_frac, /* i : pitch fraction */ + Word16 *T0_min, /* i/o: delta search min */ + Word16 *T0_max /* o : delta search max */ +); + +Word16 pitch_fr4_fx( /* o : chosen integer pitch lag */ + const Word16 exc[], /* i : excitation buffer Q_new*/ + const Word16 xn[], /* i : target signal Q_new-1+shift*/ + const Word16 h[], /* i : weighted synthesis filter impulse response Q(14+shift)*/ + const Word16 t0_min, /* i : minimum value in the searched range. Q0*/ + const Word16 t0_max, /* i : maximum value in the searched range. Q0*/ + Word16 *pit_frac, /* o : chosen fraction (0, 1, 2 or 3) */ + const Word16 i_subfr, /* i : flag to first subframe */ + const Word16 limit_flag, /* i : flag for limits (0=restrained, 1=extended) */ + const Word16 t0_fr2, /* i : minimum value for resolution 1/2 */ + const Word16 t0_fr1, /* i : minimum value for resolution 1 */ + const Word16 L_frame, /* i : length of the frame */ + const Word16 L_subfr /* i : size of subframe */ ); void pit_Q_enc_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 nBits, /* i : # of Q bits */ - const Word16 delta, /* i : Half the CL searched interval */ - const Word16 pit_flag, /* i : absolute(0) or delta(1) pitch Q */ - const Word16 limit_flag, /* i : restrained(0) or extended(1) Q limits */ - const Word16 T0, /* i : integer pitch lag */ - const Word16 T0_frac, /* i : pitch fraction */ - Word16 *T0_min, /* i/o: delta search min */ - Word16 *T0_max /* o : delta search max */ -); - -void PsychAdaptLowFreqEmph_fx(Word32 x[], - const Word16 lpcGains[], const Word16 lpcGains_e[] -); + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const Word16 nBits, /* i : # of Q bits */ + const Word16 delta, /* i : Half the CL searched interval */ + const Word16 pit_flag, /* i : absolute(0) or delta(1) pitch Q */ + const Word16 limit_flag, /* i : restrained(0) or extended(1) Q limits */ + const Word16 T0, /* i : integer pitch lag */ + const Word16 T0_frac, /* i : pitch fraction */ + Word16 *T0_min, /* i/o: delta search min */ + Word16 *T0_max /* o : delta search max */ +); + +void PsychAdaptLowFreqEmph_fx( Word32 x[], + const Word16 lpcGains[], + const Word16 lpcGains_e[] ); void set_bw_fx( const Word16 element_mode, /* i : element mode */ const Word32 element_brate, /* i : element bitrate */ - Encoder_State* st, /* i/o: Encoder State */ + Encoder_State *st, /* i/o: Encoder State */ const Word16 codec_mode /* i : codec mode */ ); -Word16 WB_BWE_encoding_fx( /* o : classification of wb signal */ - const Word16 coder_type, /* i : coder type */ - const Word16 *yos_fx, /* i : MDCT coefficients of weighted original */ - Word16 *WB_fenv_fx, /* i/o: energy of WB envelope */ - Encoder_State *st_fx, /* i/o: Encoder structure */ - Word16 Q_synth, - Word16 Q_synth_lf -); +Word16 WB_BWE_encoding_fx( /* o : classification of wb signal */ + const Word16 coder_type, /* i : coder type */ + const Word16 *yos_fx, /* i : MDCT coefficients of weighted original */ + Word16 *WB_fenv_fx, /* i/o: energy of WB envelope */ + Encoder_State *st_fx, /* i/o: Encoder structure */ + Word16 Q_synth, + Word16 Q_synth_lf ); void calculate_hangover_attenuation_gain_fx( - Encoder_State* st, /* i : encoder state structure */ - Word16* att, /* o : attenuation factor */ - const Word16 vad_hover_flag /* i : VAD hangover flag */ + Encoder_State *st, /* i : encoder state structure */ + Word16 *att, /* o : attenuation factor */ + const Word16 vad_hover_flag /* i : VAD hangover flag */ ); /*transient_detection.h*/ @@ -750,15 +741,14 @@ void calculate_hangover_attenuation_gain_fx( * Don't include the delay of the MDCT overlap. * @param pTransientDetection Structure to be initialized. It contains all transient detectors to be used. */ -void InitTransientDetection_fx(Word16 nFrameLength, - Word16 nTCXDelay, - struct TransientDetection * pTransientDetection); +void InitTransientDetection_fx( Word16 nFrameLength, + Word16 nTCXDelay, + struct TransientDetection *pTransientDetection ); -void InitTransientDetection_ivas_fx(Word16 nFrameLength, - Word16 nTCXDelay, - TRAN_DET_HANDLE pTransientDetection, - const Word16 ext_mem_flag -); +void InitTransientDetection_ivas_fx( Word16 nFrameLength, + Word16 nTCXDelay, + TRAN_DET_HANDLE pTransientDetection, + const Word16 ext_mem_flag ); /** Runs transient detection. * Runs all transient detectors defined in pTransientDetection @@ -767,7 +757,7 @@ void InitTransientDetection_ivas_fx(Word16 nFrameLength, * @param nSamplesAvailable Number of new i samples available. * @param pTransientDetection Structure that contains transient detectors to be run. */ -void RunTransientDetection_fx(Word16 const * i, Word16 nSamplesAvailable, struct TransientDetection * pTransientDetection); +void RunTransientDetection_fx( Word16 const *i, Word16 nSamplesAvailable, struct TransientDetection *pTransientDetection ); /** Get the average temporal flatness measure using subblock energies aligned with the TCX. * @param pTransientDetection Structure that contains transient detectors to be run. @@ -776,7 +766,7 @@ void RunTransientDetection_fx(Word16 const * i, Word16 nSamplesAvailable, struct * @param nPrevSubblocks Number of subblocks from the previous frames to use for the calculation. * @return average temporal flatness measure with exponent AVG_FLAT_E */ -Word16 GetTCXAvgTemporalFlatnessMeasure_fx(struct TransientDetection const * pTransientDetection, Word16 nCurrentSubblocks, Word16 nPrevSubblocks); +Word16 GetTCXAvgTemporalFlatnessMeasure_fx( struct TransientDetection const *pTransientDetection, Word16 nCurrentSubblocks, Word16 nPrevSubblocks ); /** Get the maximum energy change using subblock energies aligned with the TCX. * @param pTransientDetection Structure that contains transient detectors to be run. @@ -785,41 +775,42 @@ Word16 GetTCXAvgTemporalFlatnessMeasure_fx(struct TransientDetection const * pTr * @param nPrevSubblocks Number of subblocks from the previous frames to use for the calculation. * @param maximum energy change with exponent NRG_CHANGE_E */ -Word16 GetTCXMaxenergyChange_fx(struct TransientDetection const * pTransientDetection, - const Word8 isTCX10, - const Word16 nCurrentSubblocks, const Word16 nPrevSubblocks); +Word16 GetTCXMaxenergyChange_fx( struct TransientDetection const *pTransientDetection, + const Word8 isTCX10, + const Word16 nCurrentSubblocks, + const Word16 nPrevSubblocks ); /** Set TCX window length and overlap configuration * @param prevEnergyHF previous HF energy. Exponent must be the same as for currEnergyHF. * @param currEnergyHF current HF energy. Exponent must be the same as for prevEnergyHF. */ -void SetTCXModeInfo_fx(Encoder_State *st, - struct TransientDetection const * pTransientDetection, - Word16 * tcxModeOverlap); +void SetTCXModeInfo_fx( Encoder_State *st, + struct TransientDetection const *pTransientDetection, + Word16 *tcxModeOverlap ); void GSC_enc_init_fx( GSC_ENC_HANDLE hGSCEnc /* i/o: GSC data handle */ ); void td_cng_enc_init_fx( TD_CNG_ENC_HANDLE hTdCngEnc, /* i/o: DTX/TD CNG data handle */ - const Word16 Opt_DTX_ON, /* i : flag indicating DTX operation */ - const Word16 max_bwidth /* i : maximum encoded bandwidth */ + const Word16 Opt_DTX_ON, /* i : flag indicating DTX operation */ + const Word16 max_bwidth /* i : maximum encoded bandwidth */ ); void dtx_enc_init_fx( - Encoder_State* st, /* i : Encoder state handle */ + Encoder_State *st, /* i : Encoder state handle */ const Word16 var_SID_rate_flag, /* i : flag for variable SID update rate */ const Word16 interval_SID /* i : interval for SID update */ ); void select_TC_fx( const Word16 codec_mode, /* i : codec mode */ const Word16 tc_cnt, /* i : TC frame counter */ - Word16* coder_type, /* i/o: coder type */ + Word16 *coder_type, /* i/o: coder type */ const Word16 localVAD /* i : VAD without hangover */ ); void coder_type_modif_fx( - Encoder_State* st, /* i/o: encoder state structure */ - const Word16 relE /* i : frame relative E to the long term average */ + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 relE /* i : frame relative E to the long term average */ ); void speech_music_clas_init_fx( @@ -830,8 +821,7 @@ void pitchDoubling_det_fx( Word16 *wspeech, Word16 *pitch_ol, Word16 *T_op_fr, - Word16 *voicing_fr -); + Word16 *voicing_fr ); void fd_bwe_enc_init_fx( FD_BWE_ENC_HANDLE hBWE_FD /* i/o: FD BWE data handle */ ); @@ -847,118 +837,115 @@ void AVQ_cod_lpc_fx( Word16 Nsv /* i : number of subvectors (lg=Nsv*8) */ ); void ProcessIGF_fx( - IGF_ENC_INSTANCE_HANDLE const hInstance, /**< in: instance handle of IGF Encoder */ - Encoder_State *st, /**< in: Encoder state */ - Word32 pMDCTSpectrum[], /**< in: MDCT spectrum */ - Word16 *pMDCTSpectrum_e, - Word32 pPowerSpectrum[], /**< in: MDCT^2 + MDST^2 spectrum, or estimate */ - Word16 *pPowerSpectrum_e, - Word16 isTCX20, /**< in: flag indicating if the i is TCX20 or TCX10/2xTCX5 */ - Word16 isTNSActive, /**< in: flag indicating if the TNS is active */ - Word16 isTransition, /**< in: flag indicating if the i is the transition from from ACELP to TCX20/TCX10 */ - Word16 frameno /**< in: flag indicating index of current subframe */ + IGF_ENC_INSTANCE_HANDLE const hInstance, /**< in: instance handle of IGF Encoder */ + Encoder_State *st, /**< in: Encoder state */ + Word32 pMDCTSpectrum[], /**< in: MDCT spectrum */ + Word16 *pMDCTSpectrum_e, + Word32 pPowerSpectrum[], /**< in: MDCT^2 + MDST^2 spectrum, or estimate */ + Word16 *pPowerSpectrum_e, + Word16 isTCX20, /**< in: flag indicating if the i is TCX20 or TCX10/2xTCX5 */ + Word16 isTNSActive, /**< in: flag indicating if the TNS is active */ + Word16 isTransition, /**< in: flag indicating if the i is the transition from from ACELP to TCX20/TCX10 */ + Word16 frameno /**< in: flag indicating index of current subframe */ ); void AnalyzePowerSpectrum_fx( - Encoder_State *st, /* i/o: encoder states */ - Word16 L_frame, /* i : frame length */ - Word16 L_frameTCX, /* i : full band frame length */ - Word16 left_overlap, /* i : left overlap length */ - Word16 right_overlap, /* i : right overlap length */ - Word32 const mdctSpectrum[], /* i : MDCT spectrum */ + Encoder_State *st, /* i/o: encoder states */ + Word16 L_frame, /* i : frame length */ + Word16 L_frameTCX, /* i : full band frame length */ + Word16 left_overlap, /* i : left overlap length */ + Word16 right_overlap, /* i : right overlap length */ + Word32 const mdctSpectrum[], /* i : MDCT spectrum */ Word16 mdctSpectrum_e, - Word16 const signal[], /* i : windowed signal corresponding to mdctSpectrum */ - Word32 powerSpec[], /* o : Power spectrum. Can point to signal */ - Word16 *powerSpec_e -); -void AdaptLowFreqEmph_fx(Word32 x[], - Word16 x_e, - Word16 xq[], - Word16 invGain, - Word16 invGain_e, - Word16 tcx_lpc_shaped_ari, - Word16 lpcGains[], Word16 lpcGains_e[], - const Word16 lg -); -Word16 SQ_gain_fx( /* o : SQ gain */ - Word32 x[], /* i : vector to quantize */ - Word16 x_e, /* i : exponent */ - Word16 nbitsSQ, /* i : number of bits targeted */ - Word16 lg, /* i : vector size (2048 max) */ - Word16 *gain_e); /* o : SQ gain exponent */ + Word16 const signal[], /* i : windowed signal corresponding to mdctSpectrum */ + Word32 powerSpec[], /* o : Power spectrum. Can point to signal */ + Word16 *powerSpec_e ); +void AdaptLowFreqEmph_fx( Word32 x[], + Word16 x_e, + Word16 xq[], + Word16 invGain, + Word16 invGain_e, + Word16 tcx_lpc_shaped_ari, + Word16 lpcGains[], + Word16 lpcGains_e[], + const Word16 lg ); +Word16 SQ_gain_fx( /* o : SQ gain */ + Word32 x[], /* i : vector to quantize */ + Word16 x_e, /* i : exponent */ + Word16 nbitsSQ, /* i : number of bits targeted */ + Word16 lg, /* i : vector size (2048 max) */ + Word16 *gain_e ); /* o : SQ gain exponent */ void tcx_scalar_quantization_fx( - Word32 *x, /* i: i coefficients */ - Word16 x_e, /* i: exponent */ - Word16 *xq, /* o: quantized coefficients */ - Word16 L_frame, /* i: frame length */ - Word16 gain, /* i: quantization gain */ - Word16 gain_e, /* i: quantization gain exponent */ - Word16 offset, /* i: rounding offset (deadzone) */ + Word32 *x, /* i: i coefficients */ + Word16 x_e, /* i: exponent */ + Word16 *xq, /* o: quantized coefficients */ + Word16 L_frame, /* i: frame length */ + Word16 gain, /* i: quantization gain */ + Word16 gain_e, /* i: quantization gain exponent */ + Word16 offset, /* i: rounding offset (deadzone) */ Word8 const *memQuantZeros, /* i: coefficients to be set to 0 */ - const Word16 alfe_flag -); + const Word16 alfe_flag ); Word16 tcx_scalar_quantization_rateloop_fx( - Word32 *x, /* i : i coefficients */ - Word16 x_e, /* i : exponent */ - Word16 *xq, /* o : quantized coefficients */ - Word16 L_frame, /* i : frame length */ - Word16 *gain, /* i/o: quantization gain */ - Word16 *gain_e, /* i/o: gain exponent */ - Word16 offset, /* i : rounding offset (deadzone) */ - Word8 const *memQuantZeros, /* i : coefficients to be set to 0 */ - Word16 *lastnz_out, /* i/o: last nonzero coeff index */ - Word16 target, /* i : target number of bits */ - Word16 *nEncoded, /* o : number of encoded coeff */ - Word16 *stop, /* i/o: stop param */ - Word16 sqBits_in_noStop, /* i : number of sqBits as determined in prev. quant. stage, w/o using stop mechanism (ie might exceed target bits) */ - Word16 sqBits_in, /* i : number of sqBits as determined in prev. quant. stage, using stop mechanism (ie always <= target bits) */ - Word16 tcxRateLoopOpt, /* i : turns on/off rateloop optimization */ + Word32 *x, /* i : i coefficients */ + Word16 x_e, /* i : exponent */ + Word16 *xq, /* o : quantized coefficients */ + Word16 L_frame, /* i : frame length */ + Word16 *gain, /* i/o: quantization gain */ + Word16 *gain_e, /* i/o: gain exponent */ + Word16 offset, /* i : rounding offset (deadzone) */ + Word8 const *memQuantZeros, /* i : coefficients to be set to 0 */ + Word16 *lastnz_out, /* i/o: last nonzero coeff index */ + Word16 target, /* i : target number of bits */ + Word16 *nEncoded, /* o : number of encoded coeff */ + Word16 *stop, /* i/o: stop param */ + Word16 sqBits_in_noStop, /* i : number of sqBits as determined in prev. quant. stage, w/o using stop mechanism (ie might exceed target bits) */ + Word16 sqBits_in, /* i : number of sqBits as determined in prev. quant. stage, using stop mechanism (ie always <= target bits) */ + Word16 tcxRateLoopOpt, /* i : turns on/off rateloop optimization */ const Word8 tcxonly, - CONTEXT_HM_CONFIG *hm_cfg /* i : configuration of the context-based harmonic model */ + CONTEXT_HM_CONFIG *hm_cfg /* i : configuration of the context-based harmonic model */ ); void tcx_noise_factor_fx( - Word32 *x_orig, /* i: unquantized mdct coefficients */ - Word16 x_orig_e, /* i: exponent */ - Word32 *sqQ, /* i: quantized mdct coefficients */ - Word16 iFirstLine, /* i: first coefficient to be considered */ - Word16 lowpassLine, /* i: last nonzero coefficients after low-pass */ - Word16 nTransWidth, /* i: minimum size of hole to be checked */ - Word16 L_frame, /* i: frame length */ - Word16 gain_tcx, /* i: tcx gain */ - Word16 gain_tcx_e, /* i: gain exponent */ - Word16 tiltCompFactor, /* i: LPC tilt compensation factor */ - Word16 *fac_ns, /* o: noise factor */ - Word16 *quantized_fac_ns/* o: quantized noise factor */ + Word32 *x_orig, /* i: unquantized mdct coefficients */ + Word16 x_orig_e, /* i: exponent */ + Word32 *sqQ, /* i: quantized mdct coefficients */ + Word16 iFirstLine, /* i: first coefficient to be considered */ + Word16 lowpassLine, /* i: last nonzero coefficients after low-pass */ + Word16 nTransWidth, /* i: minimum size of hole to be checked */ + Word16 L_frame, /* i: frame length */ + Word16 gain_tcx, /* i: tcx gain */ + Word16 gain_tcx_e, /* i: gain exponent */ + Word16 tiltCompFactor, /* i: LPC tilt compensation factor */ + Word16 *fac_ns, /* o: noise factor */ + Word16 *quantized_fac_ns /* o: quantized noise factor */ ); void tcx_encoder_memory_update_fx( - Word16 *wsig, /* i: targert weighted signal */ - Word16 *xn_buf, /* i/o: mdct output buffer/TD weigthed synthesis */ - Word16 L_frame_glob, /* i: global frame length */ - const Word16 *Ai, /* i: Unquantized (interpolated) LPC coefficients */ - const Word16 *A, /* i: Quantized LPC coefficients */ - Word16 preemph, /* i: preemphasis factor*/ - LPD_state *LPDmem, /* i/o: coder memory state */ + Word16 *wsig, /* i: targert weighted signal */ + Word16 *xn_buf, /* i/o: mdct output buffer/TD weigthed synthesis */ + Word16 L_frame_glob, /* i: global frame length */ + const Word16 *Ai, /* i: Unquantized (interpolated) LPC coefficients */ + const Word16 *A, /* i: Quantized LPC coefficients */ + Word16 preemph, /* i: preemphasis factor*/ + LPD_state *LPDmem, /* i/o: coder memory state */ Encoder_State *st, - Word16 *synthout, /* o: synthesis signal */ + Word16 *synthout, /* o: synthesis signal */ Word16 Q_new, - Word16 shift -); + Word16 shift ); Word16 tcx_ari_res_Q_spec_fx( - const Word32 x_orig[], /* i: original spectrum Q31-e */ - Word16 x_orig_e, /* i: original spectrum exponent Q0 */ - const Word16 signs[], /* i: signs (x_orig[.]<0) Q0 */ - Word32 x_Q[], /* i/o: quantized spectrum Q31-e */ - Word16 x_Q_e, /* i: quantized spectrum exponent Q0 */ - Word16 L_frame, /* i: number of lines Q0 */ - Word16 gain, /* i: TCX gain Q15-e */ - Word16 gain_e, /* i: TCX gain exponent Q0 */ - Word16 prm[], /* o: bit-stream Q0 */ - Word16 target_bits, /* i: number of bits available Q0 */ - Word16 bits, /* i: number of bits used so far Q0 */ - Word16 deadzone, /* i: quantizer deadzone Q15 */ - const Word16 x_fac[] /* i: spectrum post-quantization factors Q14 */ + const Word32 x_orig[], /* i: original spectrum Q31-e */ + Word16 x_orig_e, /* i: original spectrum exponent Q0 */ + const Word16 signs[], /* i: signs (x_orig[.]<0) Q0 */ + Word32 x_Q[], /* i/o: quantized spectrum Q31-e */ + Word16 x_Q_e, /* i: quantized spectrum exponent Q0 */ + Word16 L_frame, /* i: number of lines Q0 */ + Word16 gain, /* i: TCX gain Q15-e */ + Word16 gain_e, /* i: TCX gain exponent Q0 */ + Word16 prm[], /* o: bit-stream Q0 */ + Word16 target_bits, /* i: number of bits available Q0 */ + Word16 bits, /* i: number of bits used so far Q0 */ + Word16 deadzone, /* i: quantizer deadzone Q15 */ + const Word16 x_fac[] /* i: spectrum post-quantization factors Q14 */ ); Word16 tcx_res_Q_gain_fx( @@ -967,8 +954,7 @@ Word16 tcx_res_Q_gain_fx( Word16 *gain_tcx, Word16 *gain_tcx_e, Word16 *prm, - Word16 sqTargetBits -); + Word16 sqTargetBits ); Word16 tcx_res_Q_spec_fx( Word32 *x_orig, @@ -982,19 +968,18 @@ Word16 tcx_res_Q_spec_fx( Word16 sqTargetBits, Word16 bits, Word16 sq_round, - const Word16 lf_deemph_factors[] -); + const Word16 lf_deemph_factors[] ); /* compute noise-measure flags for spectrum filling and quantization (0: tonal, 1: noise-like) */ -void ComputeSpectrumNoiseMeasure_fx(const Word32 *powerSpec, - Word16 L_frame, - Word16 startLine, - Word8 resetMemory, - Word8 *noiseFlags, - Word16 lowpassLine); +void ComputeSpectrumNoiseMeasure_fx( const Word32 *powerSpec, + Word16 L_frame, + Word16 startLine, + Word8 resetMemory, + Word8 *noiseFlags, + Word16 lowpassLine ); void lpc_quantization_fx( - Encoder_State* st, + Encoder_State *st, const Word16 lsp[], const Word16 lspmid[], Word16 lsp_q[], @@ -1006,69 +991,70 @@ void lpc_quantization_fx( const Word16 acelp_midLpc, Word16 param_lpc[], Word16 nbits_lpc[], - Word16* bits_param_lpc, - Word16* no_param_lpc, - const Word16 Q_ener -); + Word16 *bits_param_lpc, + Word16 *no_param_lpc, + const Word16 Q_ener ); void Mode2_pit_encode_fx( const Word16 coder_type, /* i : coding model */ - const Word16 i_subfr, /* i : subframe index */ - Word16 **pt_indice, /* i/o: quantization indices pointer */ - Word16 *exc, /* i/o: pointer to excitation signal frame */ - const Word16 *T_op, /* i : open loop pitch estimates in current frame */ - Word16 *T0_min, /* i/o: lower limit for close-loop search */ - Word16 *T0_min_frac, /* i/o: lower limit for close-loop search */ - Word16 *T0_max, /* i/o: higher limit for close-loop search */ - Word16 *T0_max_frac, /* i/o: higher limit for close-loop search */ - Word16 *T0, /* i/o: close loop integer pitch */ - Word16 *T0_frac, /* i/o: close loop fractional part of the pitch */ - Word16 *T0_res, /* i/o: close loop pitch resolution */ - Word16 *h1, /* i : weighted filter impulse response */ - Word16 *xn, /* i : target vector */ + const Word16 i_subfr, /* i : subframe index */ + Word16 **pt_indice, /* i/o: quantization indices pointer */ + Word16 *exc, /* i/o: pointer to excitation signal frame */ + const Word16 *T_op, /* i : open loop pitch estimates in current frame */ + Word16 *T0_min, /* i/o: lower limit for close-loop search */ + Word16 *T0_min_frac, /* i/o: lower limit for close-loop search */ + Word16 *T0_max, /* i/o: higher limit for close-loop search */ + Word16 *T0_max_frac, /* i/o: higher limit for close-loop search */ + Word16 *T0, /* i/o: close loop integer pitch */ + Word16 *T0_frac, /* i/o: close loop fractional part of the pitch */ + Word16 *T0_res, /* i/o: close loop pitch resolution */ + Word16 *h1, /* i : weighted filter impulse response */ + Word16 *xn, /* i : target vector */ Word16 pit_min, Word16 pit_fr1, Word16 pit_fr1b, Word16 pit_fr2, Word16 pit_max, - Word16 pit_res_max -); -void E_ACELP_4tsearch_fx(Word16 dn[], const Word16 cn[], const Word16 H[], Word16 code[], const PulseConfig *config, Word16 ind[], Word16 y[]); + Word16 pit_res_max ); +void E_ACELP_4tsearch_fx( Word16 dn[], const Word16 cn[], const Word16 H[], Word16 code[], const PulseConfig *config, Word16 ind[], Word16 y[] ); void E_ACELP_4t_fx( - Word16 dn[], Word16 cn[] /* Q_xn */, Word16 H[], - Word16 R[], Word8 acelpautoc, + Word16 dn[], + Word16 cn[] /* Q_xn */, + Word16 H[], + Word16 R[], + Word8 acelpautoc, Word16 code[], - Word16 cdk_index, Word16 _index[] - , const Word16 L_frame, + Word16 cdk_index, + Word16 _index[], + const Word16 L_frame, const Word16 last_L_frame, const Word32 total_brate, const Word16 i_subfr, - const Word16 cmpl_flag -); + const Word16 cmpl_flag ); void E_ACELP_innovative_codebook_fx( - Word16* exc, /* i : pointer to the excitation frame Q_new */ - Word16 T0, /* i : integer pitch lag Q0 */ - Word16 T0_frac, /* i : fraction of lag Q0 */ - Word16 T0_res, /* i : pitch resolution Q0 */ - Word16 pitch_gain, /* i : adaptive codebook gain 1Q14 */ - Word16 tilt_code, /* i : tilt factor Q15 */ - ACELP_config* acelp_cfg,/* i/o: configuration of the ACELP */ - Word16 i_subfr, /* i : subframe index */ - const Word16* Aq, /* i : quantized LPC coefficients 3Q12 */ - Word16* h1, /* i : impulse response of weighted synthesis filter 1Q14+shift */ - Word16* xn, /* i : Close-loop Pitch search target vector Q_xn */ - Word16* cn, /* i : Innovative codebook search target vector Q_new */ - Word16* y1, /* i : zero-memory filtered adaptive excitation Q_xn */ - Word16* y2, /* o : zero-memory filtered algebraic excitation Q9 */ - Word8 acelpautoc, /* i : autocorrelation mode enabled */ - Word16** pt_indice, /* i/o: quantization indices pointer */ - Word16* code, /* o : innovative codebook Q9 Q9 */ - Word16 shift, /* i : Scaling to get 12 bits */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 last_L_frame,/* i : length of the last frame */ - const Word32 total_brate /* i : ttoal bit-rate */ + Word16 *exc, /* i : pointer to the excitation frame Q_new */ + Word16 T0, /* i : integer pitch lag Q0 */ + Word16 T0_frac, /* i : fraction of lag Q0 */ + Word16 T0_res, /* i : pitch resolution Q0 */ + Word16 pitch_gain, /* i : adaptive codebook gain 1Q14 */ + Word16 tilt_code, /* i : tilt factor Q15 */ + ACELP_config *acelp_cfg, /* i/o: configuration of the ACELP */ + Word16 i_subfr, /* i : subframe index */ + const Word16 *Aq, /* i : quantized LPC coefficients 3Q12 */ + Word16 *h1, /* i : impulse response of weighted synthesis filter 1Q14+shift */ + Word16 *xn, /* i : Close-loop Pitch search target vector Q_xn */ + Word16 *cn, /* i : Innovative codebook search target vector Q_new */ + Word16 *y1, /* i : zero-memory filtered adaptive excitation Q_xn */ + Word16 *y2, /* o : zero-memory filtered algebraic excitation Q9 */ + Word8 acelpautoc, /* i : autocorrelation mode enabled */ + Word16 **pt_indice, /* i/o: quantization indices pointer */ + Word16 *code, /* o : innovative codebook Q9 Q9 */ + Word16 shift, /* i : Scaling to get 12 bits */ + const Word16 L_frame, /* i : length of the frame */ + const Word16 last_L_frame, /* i : length of the last frame */ + const Word32 total_brate /* i : ttoal bit-rate */ ); /** Detect TNS parameters. @@ -1080,10 +1066,10 @@ void E_ACELP_innovative_codebook_fx( * @param pTnsData TNS data is filled with sensible information. * @return Returns 1 if Tns should be used, otherwise 0. */ -Word16 DetectTnsFilt_fx(STnsConfig const * pTnsConfig, - Word32 const pSpectrum[], - STnsData * pTnsData, - Word16 *predictionGain); +Word16 DetectTnsFilt_fx( STnsConfig const *pTnsConfig, + Word32 const pSpectrum[], + STnsData *pTnsData, + Word16 *predictionGain ); /** Write TNS data into a stream of integers. * Writes TNS data into a stream of integers. @@ -1094,11 +1080,11 @@ Word16 DetectTnsFilt_fx(STnsConfig const * pTnsConfig, * @param pnBits Set to the number of required. * @return 0 on success, otherwise 1. */ -Word16 EncodeTnsData_fx(STnsConfig const * pTnsConfig, - STnsData const * pTnsData, - Word16 * stream, - Word16 * pnSize, - Word16 * pnBits); +Word16 EncodeTnsData_fx( STnsConfig const *pTnsConfig, + STnsData const *pTnsData, + Word16 *stream, + Word16 *pnSize, + Word16 *pnBits ); /** Write TNS data into a bitstream. * Writes TNS data into a bitstream. @@ -1109,44 +1095,44 @@ Word16 EncodeTnsData_fx(STnsConfig const * pTnsConfig, * @param pnBits Set to the number of bits written. * @return 0 on success, otherwise 1. */ -Word16 WriteTnsData_fx(STnsConfig const * pTnsConfig, - Word16 const * stream, - Word16 * pnSize, - Encoder_State *st, - Word16 * pnBits); +Word16 WriteTnsData_fx( STnsConfig const *pTnsConfig, + Word16 const *stream, + Word16 *pnSize, + Encoder_State *st, + Word16 *pnBits ); void subband_FFT_fx( - Word32 ** Sr, /*(i) real part of the CLDFB*/ - Word32 ** Si, /*(i) imag part of the CLDFB*/ + Word32 **Sr, /*(i) real part of the CLDFB*/ + Word32 **Si, /*(i) imag part of the CLDFB*/ Word32 *spec_amp, /*(o) spectral amplitude*/ Word32 Offset, /*(i) offset of the CLDFB*/ Word16 *fftoQ /*(o) the Scaling */ ); -Word16 E_ACELP_toeplitz_mul_fx(const Word16 R[], const Word16 c[], Word16 d[], const Word16 L_subfr, const Word16 highrate); -Word16 E_ACELP_code43bit_fx(const Word16 code[], UWord32 *ps, Word16 *p, UWord16 idxs[]); +Word16 E_ACELP_toeplitz_mul_fx( const Word16 R[], const Word16 c[], Word16 d[], const Word16 L_subfr, const Word16 highrate ); +Word16 E_ACELP_code43bit_fx( const Word16 code[], UWord32 *ps, Word16 *p, UWord16 idxs[] ); void tc_classif_enc_fx( const Word16 Q_new, /* i : scaling factor */ const Word16 L_frame, /* i : length of the frame */ - Word16* tc_subfr, /* o : TC subframe index */ - Word16* position, /* o : maximum of residual signal index */ + Word16 *tc_subfr, /* o : TC subframe index */ + Word16 *position, /* o : maximum of residual signal index */ const Word16 attack_flag, /* i : attack flag */ const Word16 pitch, /* i : open loop pitch estimates for first halfframe */ - const Word16* res /* i : pointer to the LP residual signal frame */ + const Word16 *res /* i : pointer to the LP residual signal frame */ ); Word16 gain_enc_uv_fx( - const Word16 *code, /*, -2,, -2 and 2*/ - Word16 mean_ener, /*, -2,, -2 and 2*/ + Word16 mean_ener, /*0=rel */ - const Word32 sr_core/* i : internal sampling rate */ +Word16 vlpc_2st_cod_fx( /* o : number of allocated bits */ + const Word16 *lsf, /* i : normalized vector to quantize */ + Word16 *lsfq, /* i/o: i:1st stage o:1st+2nd stage */ + Word16 *indx, /* o : index[] (4 bits per words) */ + const Word16 mode, /* i : 0=abs, >0=rel */ + const Word32 sr_core /* i : internal sampling rate */ ); Word16 update_decision_fx( VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ const Word32 frame_energy, /* i : current frame energy*/ - Word32 HB_Power, /* i : current frame high frequency energy*/ + Word32 HB_Power, /* i : current frame high frequency energy*/ const Word16 frameloop, /* i : amount of frames*/ const Word16 bw, /* i : band width index*/ const Word16 frame_energy_Q, /* i : the Scaling of current frame energy*/ - const Word16 HB_Power_Q, /* i : the Scaling of current frame high frequency energy*/ + const Word16 HB_Power_Q, /* i : the Scaling of current frame high frequency energy*/ const Word32 snr, /* i : frequency domain SNR */ const Word32 tsnr, /* i : time domain SNR */ const Word16 vad_flag, /* i : VAD flag */ @@ -2155,34 +2101,33 @@ Word16 update_decision_fx( void bg_music_decision_fx( VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ - Word16 *music_backgound_f, /*(i) background music flag*/ - Word32 frame_energy, /*(i) current frame energy 1*/ - Word16 frame_energy_Q /*(i) the Scaling of current frame energy*/ + Word16 *music_backgound_f, /*(i) background music flag*/ + Word32 frame_energy, /*(i) current frame energy 1*/ + Word16 frame_energy_Q /*(i) the Scaling of current frame energy*/ ); void spec_center_fx( - Word32* sb_power, /* i : energy of sub-band divided uniformly*/ - Word16* sp_center, /* o : spectral center*/ - const Word32 bandwith, /* i : band width*/ - const Word16 Q_sb_p /* i : the Scaling of sb_power*/ + Word32 *sb_power, /* i : energy of sub-band divided uniformly*/ + Word16 *sp_center, /* o : spectral center*/ + const Word32 bandwith, /* i : band width*/ + const Word16 Q_sb_p /* i : the Scaling of sb_power*/ ); -void spec_flatness_fx(Word32 *spec_amp, /*(i) spectral amplitude*/ - Word32 smooth_spec_amp[], /*(i) smoothed spectral amplitude*/ - Word16 sSFM[SFM_NUM] /*(o) spectral flatness rate*/ +void spec_flatness_fx( Word32 *spec_amp, /*(i) spectral amplitude*/ + Word32 smooth_spec_amp[], /*(i) smoothed spectral amplitude*/ + Word16 sSFM[SFM_NUM] /*(o) spectral flatness rate*/ ); void SetModeIndex_fx( - Encoder_State* st, + Encoder_State *st, Word32 last_total_brate, const Word16 last_element_mode, const Word16 is_mct, - const Word16 shift -); + const Word16 shift ); void MDCT_selector_fx( - Encoder_State* st, /* i/o: Encoder State */ - Word16 sp_floor, /* i : Noise floor estimate Q7 */ + Encoder_State *st, /* i/o: Encoder State */ + Word16 sp_floor, /* i : Noise floor estimate Q7 */ const Word16 Etot, /* i : Total energy Q8 */ const Word16 cor_map_sum, /* i : harmonicity factor Q8 */ const Word32 enerBuffer[], /* i : CLDFB buffers */ @@ -2190,15 +2135,14 @@ void MDCT_selector_fx( ); void MDCT_selector_reset_fx( - TCX_ENC_HANDLE hTcxEnc -); + TCX_ENC_HANDLE hTcxEnc ); void MDCT_classifier_reset_fx( TCX_ENC_HANDLE hTcxEnc /* i/o: TCX Encoder Handle */ ); void ltd_stable_fx( - VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ - Word16* ltd_stable_rate, /* o : time-domain stable rate*/ + VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ + Word16 *ltd_stable_rate, /* o : time-domain stable rate*/ const Word32 frame_energy, /* i : current frame energy*/ const Word16 frameloop, /* i : amount of frames*/ const Word16 Q_frames_power /* i : the Scaling of frames_power*/ @@ -2207,409 +2151,413 @@ void ltd_stable_fx( void IGFSCFEncoderOpen_fx( IGFSCFENC_INSTANCE_HANDLE hPublicData, /* i/o: handle to public data */ H_IGF_INFO hIgfInfo, /* i : IGF info handle */ - const Word32 total_brate, /* i : total bitrate */ - const Word16 bwidth, /* i : audio bandwidth */ - const Word16 element_mode, /* i : IVAS element mode */ - const Word16 rf_mode /* i : flag to signal the RF mode */ + const Word32 total_brate, /* i : total bitrate */ + const Word16 bwidth, /* i : audio bandwidth */ + const Word16 element_mode, /* i : IVAS element mode */ + const Word16 rf_mode /* i : flag to signal the RF mode */ ); void IGFSCFEncoderReset_fx( - IGFSCFENC_INSTANCE_HANDLE hPublicData /* i/o: handle to public data */ + IGFSCFENC_INSTANCE_HANDLE hPublicData /* i/o: handle to public data */ ); Word16 IGFSCFEncoderEncode_fx( IGFSCFENC_INSTANCE_HANDLE hPublicData, /* i : handle to public data or NULL in case there was no instance created */ BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 bitCount, /* i : offset to the first bit in bitbuffer which should be readed by iisArithDecoderDecode function */ - Word16* sfe, /* i : ptr to an array which contain quantized scalefactor energies */ - const Word16 igfGridIdx, /* i : igf grid index see declaration of IGF_GRID_IDX for details */ - const Word16 indepFlag /* i : if 1 frame is independent, 0 = frame is coded with data from previous frame */ + const Word16 bitCount, /* i : offset to the first bit in bitbuffer which should be readed by iisArithDecoderDecode function */ + Word16 *sfe, /* i : ptr to an array which contain quantized scalefactor energies */ + const Word16 igfGridIdx, /* i : igf grid index see declaration of IGF_GRID_IDX for details */ + const Word16 indepFlag /* i : if 1 frame is independent, 0 = frame is coded with data from previous frame */ ); void IGFSCFEncoderSaveContextState_fx( - IGFSCFENC_INSTANCE_HANDLE hPublicData, /* i/o: handle to public data */ - const Word16 igfGridIdx /* i : igf grid index see declaration of IGF_GRID_IDX for details */ + IGFSCFENC_INSTANCE_HANDLE hPublicData, /* i/o: handle to public data */ + const Word16 igfGridIdx /* i : igf grid index see declaration of IGF_GRID_IDX for details */ ); void IGFSCFEncoderRestoreContextState_fx( - IGFSCFENC_INSTANCE_HANDLE hPublicData, /* i/o: handle to public data */ - const Word16 igfGridIdx /* i : igf grid index see declaration of IGF_GRID_IDX for details */ + IGFSCFENC_INSTANCE_HANDLE hPublicData, /* i/o: handle to public data */ + const Word16 igfGridIdx /* i : igf grid index see declaration of IGF_GRID_IDX for details */ ); void frame_spec_dif_cor_rate_fx( - VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ - Word32* spec_amp, /* i : spectral amplitude*/ + VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ + Word32 *spec_amp, /* i : spectral amplitude*/ Word16 sacle, /* i : the scaling of spec_amp*/ Word16 f_tonality_rate[3] /* o : tonality rate*/ ); void est_energy_fx( - Word32 enerBuffer[CLDFB_NO_CHANNELS_MAX], /* i : energy vector per band */ - Word16 enerBuffer_exp, /* i : exponent of energy vector */ - Word32* frame_sb_energy, /* o : energy of sub-band divided non-uniformly*/ - Word32* frame_energy2_p, /* o : frame energy 2*/ - Word32* HB_Power_p, /* o : high frequency energy*/ - Word32* frame_energy_p, /* o : frame energy 1*/ - Word16* sb_power_Q, /* o : the scaling of sb_power*/ - Word16* frame_energy2_Q, /* o : the scaling of frame_energy*/ - Word16* HB_Power_Q, /* o : the scaling of HB_Power*/ - Word16* frame_energy_Q, /* o : the Scaling of frame_energy*/ - Word16* frame_sb_energy_scale, /* o : the Scaling of frame_sb_energy[]*/ - const Word32 bandwidth /* i : band width*/ + Word32 enerBuffer[CLDFB_NO_CHANNELS_MAX], /* i : energy vector per band */ + Word16 enerBuffer_exp, /* i : exponent of energy vector */ + Word32 *frame_sb_energy, /* o : energy of sub-band divided non-uniformly*/ + Word32 *frame_energy2_p, /* o : frame energy 2*/ + Word32 *HB_Power_p, /* o : high frequency energy*/ + Word32 *frame_energy_p, /* o : frame energy 1*/ + Word16 *sb_power_Q, /* o : the scaling of sb_power*/ + Word16 *frame_energy2_Q, /* o : the scaling of frame_energy*/ + Word16 *HB_Power_Q, /* o : the scaling of HB_Power*/ + Word16 *frame_energy_Q, /* o : the Scaling of frame_energy*/ + Word16 *frame_sb_energy_scale, /* o : the Scaling of frame_sb_energy[]*/ + const Word32 bandwidth /* i : band width*/ ); void background_update_fx( VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ - Word16 scale, /* i : the scaling of frame energy*/ - Word32 frame_energy, /* i : current frame energy*/ - Word32 update_flag, /* i : update flag*/ - Word16 music_backgound_f, /* i : background music flag*/ - Word32 snr -); + Word16 scale, /* i : the scaling of frame energy*/ + Word32 frame_energy, /* i : current frame energy*/ + Word32 update_flag, /* i : update flag*/ + Word16 music_backgound_f, /* i : background music flag*/ + Word32 snr ); /* enc_gain.c */ -Word16 E_GAIN_closed_loop_search_fx(Word16 exc[], - Word16 xn[], Word16 h[], - Word16 t0_min, Word16 t0_min_frac, Word16 t0_max, Word16 t0_max_frac, Word16 t0_min_max_res, Word16 *pit_frac, Word16 *pit_res, Word16 pit_res_max, - Word16 i_subfr, Word16 pit_min, Word16 pit_fr2, Word16 pit_fr1, Word16 L_subfr); +Word16 E_GAIN_closed_loop_search_fx( Word16 exc[], + Word16 xn[], + Word16 h[], + Word16 t0_min, + Word16 t0_min_frac, + Word16 t0_max, + Word16 t0_max_frac, + Word16 t0_min_max_res, + Word16 *pit_frac, + Word16 *pit_res, + Word16 pit_res_max, + Word16 i_subfr, + Word16 pit_min, + Word16 pit_fr2, + Word16 pit_fr1, + Word16 L_subfr ); void core_acelp_tcx20_switching_fx( - Encoder_State *st, /* i/o: encoder state structure */ + Encoder_State *st, /* i/o: encoder state structure */ Word16 non_staX, - Word16 *pitch_fr, /* i/o: fraction pitch values */ - Word16 *voicing_fr, /* i/o: fractional voicing values */ - const Word16 currFlatness, /* i : flatness */ - const Word16 lsp_mid[M], /* i : LSPs at the middle of the frame */ - const Word16 stab_fac, /* i : LP filter stability */ + Word16 *pitch_fr, /* i/o: fraction pitch values */ + Word16 *voicing_fr, /* i/o: fractional voicing values */ + const Word16 currFlatness, /* i : flatness */ + const Word16 lsp_mid[M], /* i : LSPs at the middle of the frame */ + const Word16 stab_fac, /* i : LP filter stability */ Word16 Q_new, - Word16 shift -); + Word16 shift ); Word16 comvad_decision_fx( VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ - const Word32 l_snr, /*(i) long time frequency domain*/ - const Word32 lt_snr_org, /*(i) original long time SNR*/ - const Word32 lt_snr, /*(i) long time SNR calculated by fg_energy and bg_energy*/ - const Word32 snr_flux, /*(i) average tsnr of several frames*/ - const Word32 snr, /*(i) frequency domain SNR */ - Word32 tsnr, /*(i) time domain SNR */ - const Word32 frame_energy, /*(i) current frame energy */ - const Word16 music_backgound_f, /*(i) background music flag*/ - const Word16 frame_energy_Q, /*(i) the Scaling of current frame energy*/ - Word16 *cldfb_addition, /*(o) adjust the harmonized hangover */ - const Word16 vada_flag -); + const Word32 l_snr, /*(i) long time frequency domain*/ + const Word32 lt_snr_org, /*(i) original long time SNR*/ + const Word32 lt_snr, /*(i) long time SNR calculated by fg_energy and bg_energy*/ + const Word32 snr_flux, /*(i) average tsnr of several frames*/ + const Word32 snr, /*(i) frequency domain SNR */ + Word32 tsnr, /*(i) time domain SNR */ + const Word32 frame_energy, /*(i) current frame energy */ + const Word16 music_backgound_f, /*(i) background music flag*/ + const Word16 frame_energy_Q, /*(i) the Scaling of current frame energy*/ + Word16 *cldfb_addition, /*(o) adjust the harmonized hangover */ + const Word16 vada_flag ); void amr_wb_enc_init_fx( AMRWB_IO_ENC_HANDLE hAmrwb_IO /* i/o: AMR-WB IO encoder handle */ ); void snr_calc( - VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ - const Word16 sacle_sbpower, /* i : the Scaling of sbpower*/ - Word32* snr, /* o : frequency domain SNR */ - Word32* tsnr, /* o : time domain SNR */ - const Word32 frame_energy, /* i : current frame energy */ - const Word32 bwidth /* i : audio band width*/ + VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ + const Word16 sacle_sbpower, /* i : the Scaling of sbpower*/ + Word32 *snr, /* o : frequency domain SNR */ + Word32 *tsnr, /* o : time domain SNR */ + const Word32 frame_energy, /* i : current frame energy */ + const Word32 bwidth /* i : audio band width*/ ); void FEC_encode_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const ACELP_config acelp_cfg, /* i/o: configuration of the ACELP */ - const Word16* synth, /* i : pointer to synthesized speech for E computation */ - const Word16 coder_type, /* i : type of coder */ - Word16 clas, /* i : signal clas for current frame */ - const Word16* fpit, /* i : close loop fractional pitch buffer */ - const Word16* res, /* i : LP residual signal frame */ - Word16* last_pulse_pos, /* i/o: Position of the last pulse */ - const Word16 L_frame, /* i : Frame length */ - const Word32 total_brate, /* i : total codec bitrate */ - const Word16 Q_new, /* i : i scaling */ - const Word16 shift /* i : scaling to get 12bits */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const ACELP_config acelp_cfg, /* i/o: configuration of the ACELP */ + const Word16 *synth, /* i : pointer to synthesized speech for E computation */ + const Word16 coder_type, /* i : type of coder */ + Word16 clas, /* i : signal clas for current frame */ + const Word16 *fpit, /* i : close loop fractional pitch buffer */ + const Word16 *res, /* i : LP residual signal frame */ + Word16 *last_pulse_pos, /* i/o: Position of the last pulse */ + const Word16 L_frame, /* i : Frame length */ + const Word32 total_brate, /* i : total codec bitrate */ + const Word16 Q_new, /* i : i scaling */ + const Word16 shift /* i : scaling to get 12bits */ ); void updt_enc_fx( - Encoder_State* st, /* i/o: state structure */ - const Word16* old_exc, /* i : buffer of excitation */ - const Word16* pitch_buf, /* i : floating pitch for each subframe */ - const Word16 Es_pred, /* i : predicited scaled innovation energy */ - const Word16* Aq, /* i : A(z) quantized for all subframes */ - const Word16* lsf_new, /* i : current frame LSF vector */ - const Word16* lsp_new, /* i : current frame LSP vector */ - const Word16* old_bwe_exc /* i : buffer of excitation */ + Encoder_State *st, /* i/o: state structure */ + const Word16 *old_exc, /* i : buffer of excitation */ + const Word16 *pitch_buf, /* i : floating pitch for each subframe */ + const Word16 Es_pred, /* i : predicited scaled innovation energy */ + const Word16 *Aq, /* i : A(z) quantized for all subframes */ + const Word16 *lsf_new, /* i : current frame LSF vector */ + const Word16 *lsp_new, /* i : current frame LSP vector */ + const Word16 *old_bwe_exc /* i : buffer of excitation */ ); void dtx_hangover_control_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 lsp_new_fx[M] /* i : current frame LSPs */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word16 lsp_new_fx[M] /* i : current frame LSPs */ ); void update_average_rate_fx( SC_VBR_ENC_HANDLE hSC_VBR, /* i/o: SC-VBR state structure */ - const Word32 core_brate_fx /* i : core bitrate */ -); -Word16 pit_encode_fx( /* o : Fractional pitch for each subframe */ - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 pitch_bits[], /* i : pitch bits */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 coder_type, /* i : coding type */ - Word16 *limit_flag, /* i/o: restrained(0) or extended(1) Q limits */ - const Word16 i_subfr, /* i : subframe index */ - Word16 *exc, /* i/o: pointer to excitation signal frame */ - const Word16 L_subfr, /* i : subframe length */ - const Word16 *T_op, /* i : open loop pitch estimates in current frame */ - Word16 *T0_min, /* i/o: lower limit for close-loop search */ - Word16 *T0_max, /* i/o: higher limit for close-loop search */ - Word16 *T0, /* i/o: close loop integer pitch */ - Word16 *T0_frac, /* i/o: close loop fractional part of the pitch */ - const Word16 *h1, /* i : weighted filter i response */ - const Word16 *xn, /* i : target vector */ - const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ - const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ + const Word32 core_brate_fx /* i : core bitrate */ +); +Word16 pit_encode_fx( /* o : Fractional pitch for each subframe */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 pitch_bits[], /* i : pitch bits */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const Word16 L_frame, /* i : length of the frame */ + const Word16 coder_type, /* i : coding type */ + Word16 *limit_flag, /* i/o: restrained(0) or extended(1) Q limits */ + const Word16 i_subfr, /* i : subframe index */ + Word16 *exc, /* i/o: pointer to excitation signal frame */ + const Word16 L_subfr, /* i : subframe length */ + const Word16 *T_op, /* i : open loop pitch estimates in current frame */ + Word16 *T0_min, /* i/o: lower limit for close-loop search */ + Word16 *T0_max, /* i/o: higher limit for close-loop search */ + Word16 *T0, /* i/o: close loop integer pitch */ + Word16 *T0_frac, /* i/o: close loop fractional part of the pitch */ + const Word16 *h1, /* i : weighted filter i response */ + const Word16 *xn, /* i : target vector */ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ ); Word16 lp_filt_exc_enc_fx( - const Word16 codec_mode, /* i : MODE1 or MODE2 Q0 */ - const Word16 coder_type, /* i : coding type Q0 */ - const Word16 i_subfr, /* i : subframe index Q0 */ - Word16 *exc, /* i/o: pointer to excitation signal frame Q_new */ - const Word16 *h1, /* i : weighted filter i response Q(14+shift) */ - const Word16 *xn, /* i : target vector Q_new-1+shift */ - Word16 *y1, /* o : zero-memory filtered adaptive excitation Q_new-1+shift */ - Word16 *xn2, /* o : target vector for innovation search Q_new-1+shift */ - const Word16 L_subfr, /* i : length of vectors for gain quantization Q0 */ - const Word16 L_frame, /* i : frame size Q0 */ - Word16 *g_corr, /* o : ACELP correlation values mant/exp */ - const Word16 clip_gain, /* i : adaptive gain clipping flag Q0 */ - Word16 *gain_pit, /* o : adaptive excitation gain Q14 */ - Word16 *lp_flag /* i/o: mode selection Q0 */ + const Word16 codec_mode, /* i : MODE1 or MODE2 Q0 */ + const Word16 coder_type, /* i : coding type Q0 */ + const Word16 i_subfr, /* i : subframe index Q0 */ + Word16 *exc, /* i/o: pointer to excitation signal frame Q_new */ + const Word16 *h1, /* i : weighted filter i response Q(14+shift) */ + const Word16 *xn, /* i : target vector Q_new-1+shift */ + Word16 *y1, /* o : zero-memory filtered adaptive excitation Q_new-1+shift */ + Word16 *xn2, /* o : target vector for innovation search Q_new-1+shift */ + const Word16 L_subfr, /* i : length of vectors for gain quantization Q0 */ + const Word16 L_frame, /* i : frame size Q0 */ + Word16 *g_corr, /* o : ACELP correlation values mant/exp */ + const Word16 clip_gain, /* i : adaptive gain clipping flag Q0 */ + Word16 *gain_pit, /* o : adaptive excitation gain Q14 */ + Word16 *lp_flag /* i/o: mode selection Q0 */ ); Word16 inov_encode_fx( - Encoder_State* st_fx, /* i/o: encoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 last_L_frame, /* i : length of the last frame */ - const Word16 coder_type, /* i : coding type */ - const Word16 bwidth, /* i : i signal bandwidth */ - const Word16 sharpFlag, /* i : formant sharpening flag */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 tc_subfr, /* i : TC subframe index */ - const Word16* p_Aq, /* i : LP filter coefficients Q12*/ - const Word16 gain_pit, /* i : adaptive excitation gain Q14*/ - Word16* cn, /* i/o: target vector in residual domain Q_new*/ - const Word16* exc, /* i : pointer to excitation signal frame Q_new*/ - Word16* h2, /* i/o: weighted filter i response Q12*/ - const Word16 tilt_code, /* i : tilt of the excitation of previous subframe Q15*/ - const Word16 pt_pitch, /* i : pointer to current subframe fractional pitch Q6*/ - const Word16* xn2, /* i : target vector for innovation search Q_new-1+shift*/ - Word16* code, /* o : algebraic excitation Q9*/ - Word16* y2, /* o : zero-memory filtered algebraic excitation Q9*/ - Word16* unbits, /* o : number of unused bits for PI */ - const Word16 L_subfr, /* i : subframe length */ - Word16 shift -); + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const Word16 L_frame, /* i : length of the frame */ + const Word16 last_L_frame, /* i : length of the last frame */ + const Word16 coder_type, /* i : coding type */ + const Word16 bwidth, /* i : i signal bandwidth */ + const Word16 sharpFlag, /* i : formant sharpening flag */ + const Word16 i_subfr, /* i : subframe index */ + const Word16 tc_subfr, /* i : TC subframe index */ + const Word16 *p_Aq, /* i : LP filter coefficients Q12*/ + const Word16 gain_pit, /* i : adaptive excitation gain Q14*/ + Word16 *cn, /* i/o: target vector in residual domain Q_new*/ + const Word16 *exc, /* i : pointer to excitation signal frame Q_new*/ + Word16 *h2, /* i/o: weighted filter i response Q12*/ + const Word16 tilt_code, /* i : tilt of the excitation of previous subframe Q15*/ + const Word16 pt_pitch, /* i : pointer to current subframe fractional pitch Q6*/ + const Word16 *xn2, /* i : target vector for innovation search Q_new-1+shift*/ + Word16 *code, /* o : algebraic excitation Q9*/ + Word16 *y2, /* o : zero-memory filtered algebraic excitation Q9*/ + Word16 *unbits, /* o : number of unused bits for PI */ + const Word16 L_subfr, /* i : subframe length */ + Word16 shift ); void gain_enc_mless_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 gains_mode[], /* i : gain bits */ - const Word16 element_mode, /* i : element mode */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 tc_subfr, /* i : TC subframe index */ - const Word16* xn, /* i : target vector */ - const Word16* y1, /* i : zero-memory filtered adaptive excitation */ - const Word16 Q_xn, /* i : xn and y1 scaling */ - const Word16* y2, /* i : zero-memory filtered algebraic codebook excitation */ - const Word16* code, /* i : algebraic excitation */ - const Word16 Es_pred, /* i : predicted scaled innovation energy */ - Word16* gain_pit, /* o : quantized pitch gain */ - Word32* gain_code, /* o : quantized codebook gain */ - Word16* gain_inov, /* o : gain of the innovation (used for normalization) */ - Word32* norm_gain_code, /* o : norm. gain of the codebook excitation */ - Word16* g_corr, /* i/o: correlations , -2,, -2 and 2 */ - const Word16 clip_gain /* i : gain pitch clipping flag (1 = clipping) */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 gains_mode[], /* i : gain bits */ + const Word16 element_mode, /* i : element mode */ + const Word16 L_frame, /* i : length of the frame */ + const Word16 i_subfr, /* i : subframe index */ + const Word16 tc_subfr, /* i : TC subframe index */ + const Word16 *xn, /* i : target vector */ + const Word16 *y1, /* i : zero-memory filtered adaptive excitation */ + const Word16 Q_xn, /* i : xn and y1 scaling */ + const Word16 *y2, /* i : zero-memory filtered algebraic codebook excitation */ + const Word16 *code, /* i : algebraic excitation */ + const Word16 Es_pred, /* i : predicted scaled innovation energy */ + Word16 *gain_pit, /* o : quantized pitch gain */ + Word32 *gain_code, /* o : quantized codebook gain */ + Word16 *gain_inov, /* o : gain of the innovation (used for normalization) */ + Word32 *norm_gain_code, /* o : norm. gain of the codebook excitation */ + Word16 *g_corr, /* i/o: correlations , -2,, -2 and 2 */ + const Word16 clip_gain /* i : gain pitch clipping flag (1 = clipping) */ ); void updt_IO_switch_enc_fx( - Encoder_State *st, /* i/o: state structure */ - const Word16 input_frame /* i : i frame length */ + Encoder_State *st, /* i/o: state structure */ + const Word16 input_frame /* i : i frame length */ ); void hf_cod_init_fx( - Word16 *mem_hp400_enc, /* o: memory of hp 400 Hz filter */ - Word16 *mem_hf1_enc, /* o: HF band-pass filter memory */ - Word16 *mem_syn_hf_enc, /* o: HF synthesis memory */ - Word16 *mem_hf2_enc, /* o: HF band-pass filter memory */ - Word16 *gain_alpha_fx /* o: smoothing gain for transitions between active and inactive frames */ + Word16 *mem_hp400_enc, /* o: memory of hp 400 Hz filter */ + Word16 *mem_hf1_enc, /* o: HF band-pass filter memory */ + Word16 *mem_syn_hf_enc, /* o: HF synthesis memory */ + Word16 *mem_hf2_enc, /* o: HF band-pass filter memory */ + Word16 *gain_alpha_fx /* o: smoothing gain for transitions between active and inactive frames */ ); void analy_lp_AMR_WB_fx( - const Word16 speech[], /* i : pointer to the speech frame */ - Word32 *ener, /* o : residual energy from Levinson-Durbin */ - Word16 A[], /* o : A(z) filter coefficients */ - Word16 epsP_h[], /* o : LP analysis residual energies for each iteration */ - Word16 epsP_l[], /* o : LP analysis residual energies for each iteration */ - Word16 isp_new[], /* o : current frame ISPs */ - Word16 isp_old[], /* i/o: previous frame unquantized ISPs */ - Word16 isf_new[], /* o : current frame ISPs */ - Word16 Top, /* i : open loop pitch lag */ - Word16 Tnc, /* i : open loop pitch gain */ + const Word16 speech[], /* i : pointer to the speech frame */ + Word32 *ener, /* o : residual energy from Levinson-Durbin */ + Word16 A[], /* o : A(z) filter coefficients */ + Word16 epsP_h[], /* o : LP analysis residual energies for each iteration */ + Word16 epsP_l[], /* o : LP analysis residual energies for each iteration */ + Word16 isp_new[], /* o : current frame ISPs */ + Word16 isp_old[], /* i/o: previous frame unquantized ISPs */ + Word16 isf_new[], /* o : current frame ISPs */ + Word16 Top, /* i : open loop pitch lag */ + Word16 Tnc, /* i : open loop pitch gain */ Word16 Q_new, - Word16 *Q_r -); + Word16 *Q_r ); void encod_amr_wb_fx( - Encoder_State* st, /* i/o: state structure */ - const Word16 speech[], /* i : i speech */ - const Word16 Aw[], /* i : weighted A(z) unquantized for subframes */ - const Word16 Aq[], /* i : 12k8 Lp coefficient */ - const Word16* res, /* i : residual signal */ - Word16* syn, /* i/o: core synthesis */ - Word16* exc, /* i/o: current non-enhanced excitation */ - Word16* exc2, /* i/o: current enhanced excitation */ - Word16* pitch_buf, /* i/o: floating pitch values for each subframe */ - Word16 hf_gain_fx[NB_SUBFR],/* o : decoded HF gain */ - const Word16* speech16k_fx, /* i : i speech @16kHz */ + Encoder_State *st, /* i/o: state structure */ + const Word16 speech[], /* i : i speech */ + const Word16 Aw[], /* i : weighted A(z) unquantized for subframes */ + const Word16 Aq[], /* i : 12k8 Lp coefficient */ + const Word16 *res, /* i : residual signal */ + Word16 *syn, /* i/o: core synthesis */ + Word16 *exc, /* i/o: current non-enhanced excitation */ + Word16 *exc2, /* i/o: current enhanced excitation */ + Word16 *pitch_buf, /* i/o: floating pitch values for each subframe */ + Word16 hf_gain_fx[NB_SUBFR], /* o : decoded HF gain */ + const Word16 *speech16k_fx, /* i : i speech @16kHz */ Word16 shift, - Word16 Q_new -); + Word16 Q_new ); void re8_cod_fx( - Word16 x[], /* i : point in RE8 (8-dimensional integer vector) */ - Word16 *n, /* i : codebook number (*n is an integer defined in {0,2,3,4,..,n_max}) */ - UWord16 *I, /* o : index of c (pointer to unsigned 16-bit word) */ - Word16 k[] /* o : index of v (8-dimensional vector of binary indices) = Voronoi index */ + Word16 x[], /* i : point in RE8 (8-dimensional integer vector) */ + Word16 *n, /* i : codebook number (*n is an integer defined in {0,2,3,4,..,n_max}) */ + UWord16 *I, /* o : index of c (pointer to unsigned 16-bit word) */ + Word16 k[] /* o : index of v (8-dimensional vector of binary indices) = Voronoi index */ ); void TBEreset_enc_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - Word16 bandwidth /* i : bandwidth mode */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + Word16 bandwidth /* i : bandwidth mode */ ); void acelp_core_switch_enc_fx( - Encoder_State* st_fx, /* i/o: encoder state structure */ - const Word16 inp12k8[], /* i : i signal @12.8 kHz Q0 */ - const Word16 inp16k[], /* i : i signal @16 kHz Q0 */ - const Word16 A[NB_SUBFR16k * (M + 1)], /* i : A(z) unquantized for the 4 subframes Q12*/ + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word16 inp12k8[], /* i : i signal @12.8 kHz Q0 */ + const Word16 inp16k[], /* i : i signal @16 kHz Q0 */ + const Word16 A[NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes Q12*/ Word16 shift, - Word16 Q_new -); + Word16 Q_new ); void gain_enc_amr_wb_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 *xn, /* i : target vector */ - const Word16 Q_xn, /* i : xn and yy1 format Q0 */ - const Word16 *yy1, /* i : zero-memory filtered adaptive excitation */ - const Word16 *y2, /* i : zero-memory filtered algebraic codebook excitation */ - const Word16 *code, /* i : algebraic excitation */ - const Word32 core_brate, /* i : core bitrate */ - Word16 *gain_pit, /* i/o: pitch gain / Quantized pitch gain */ - Word32 *gain_code, /* o : quantized codebook gain */ - Word16 *gain_inov, /* o : gain of the innovation (used for normalization) */ - Word32 *norm_gain_code, /* o : norm. gain of the codebook excitation */ - Word16 *g_coeff, /* i/o: correlations , -2,, -2 and 2 */ - const Word16 clip_gain, /* i : gain pitch clipping flag (1 = clipping) */ - Word16 *past_qua_en /* i/o: gain quantization memory (4 words) */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 *xn, /* i : target vector */ + const Word16 Q_xn, /* i : xn and yy1 format Q0 */ + const Word16 *yy1, /* i : zero-memory filtered adaptive excitation */ + const Word16 *y2, /* i : zero-memory filtered algebraic codebook excitation */ + const Word16 *code, /* i : algebraic excitation */ + const Word32 core_brate, /* i : core bitrate */ + Word16 *gain_pit, /* i/o: pitch gain / Quantized pitch gain */ + Word32 *gain_code, /* o : quantized codebook gain */ + Word16 *gain_inov, /* o : gain of the innovation (used for normalization) */ + Word32 *norm_gain_code, /* o : norm. gain of the codebook excitation */ + Word16 *g_coeff, /* i/o: correlations , -2,, -2 and 2 */ + const Word16 clip_gain, /* i : gain pitch clipping flag (1 = clipping) */ + Word16 *past_qua_en /* i/o: gain quantization memory (4 words) */ ); void hf_cod_fx( - const Word32 core_brate_fx, /* i : core bitrate */ - const Word16 *speech16k_fx, /* i : original speech at 16 kHz */ - const Word16 Aq_fx[], /* i : quantized Aq */ - const Word16 exc_fx[], /* i : excitation at 12.8 kHz */ - Word16 synth_fx[], /* i : 12.8kHz synthesis signal */ - Word16 *seed2_enc_fx, /* i/o: random seed for HF noise gen */ - Word16 *mem_hp400_enc_fx, /* i/o: memory of hp 400 Hz filter */ - Word16 *mem_syn_hf_enc_fx, /* i/o: HF synthesis memory */ - Word16 *mem_hf1_enc_fx, /* i/o: HF band-pass filter memory */ - Word16 *mem_hf2_enc_fx, /* i/o: HF band-pass filter memory */ + const Word32 core_brate_fx, /* i : core bitrate */ + const Word16 *speech16k_fx, /* i : original speech at 16 kHz */ + const Word16 Aq_fx[], /* i : quantized Aq */ + const Word16 exc_fx[], /* i : excitation at 12.8 kHz */ + Word16 synth_fx[], /* i : 12.8kHz synthesis signal */ + Word16 *seed2_enc_fx, /* i/o: random seed for HF noise gen */ + Word16 *mem_hp400_enc_fx, /* i/o: memory of hp 400 Hz filter */ + Word16 *mem_syn_hf_enc_fx, /* i/o: HF synthesis memory */ + Word16 *mem_hf1_enc_fx, /* i/o: HF band-pass filter memory */ + Word16 *mem_hf2_enc_fx, /* i/o: HF band-pass filter memory */ const Word16 dtxHangoverCount_fx, - Word16 *gain_alpha_fx, /* i/o: smoothing gain for transitions between active and inactive frames */ - Word16 *hf_gain_fx, /* o : HF gain to be transmitted to decoder */ + Word16 *gain_alpha_fx, /* i/o: smoothing gain for transitions between active and inactive frames */ + Word16 *hf_gain_fx, /* o : HF gain to be transmitted to decoder */ Word16 Q_exc, - Word16 Q_syn -); + Word16 Q_syn ); void transf_cdbk_enc_fx( - Encoder_State* st_fx, /* i/o: encoder state structure */ - const Word16 harm_flag_acelp,/* i : harmonic flag for higher rates ACELP */ - const Word16 i_subfr, /* i : subframe index */ - Word16 cn[], /* i/o: target vector in residual domain */ - Word16 exc[], /* i/o: pointer to excitation signal frame */ - const Word16* p_Aq, /* i : 12k8 Lp coefficient */ - const Word16 Ap[], /* i : weighted LP filter coefficients */ - const Word16 h1[], /* i : weighted filter i response */ - Word16 xn[], /* i/o: target vector */ - Word16 xn2[], /* i/o: target vector for innovation search */ - Word16 y1[], /* i/o: zero-memory filtered adaptive excitation */ - const Word16 y2[], /* i : zero-memory filtered innovative excitation */ - const Word16 Es_pred, /* i : predicited scaled innovation energy */ - Word16* gain_pit, /* i/o: adaptive excitation gain */ - const Word32 gain_code, /* i : innovative excitation gain */ - Word16 g_corr[], /* o : ACELP correlation values */ - const Word16 clip_gain, /* i : adaptive gain clipping flag */ - Word16* gain_preQ, /* o : prequantizer excitation gain */ - Word16 code_preQ[], /* o : prequantizer excitation */ - Word16* unbits, /* o : number of AVQ unused bits */ - const Word16 Q_new, /* i : Current frame scaling */ - const Word16 shift /* i : shifting applied to y1, xn,... */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word16 harm_flag_acelp, /* i : harmonic flag for higher rates ACELP */ + const Word16 i_subfr, /* i : subframe index */ + Word16 cn[], /* i/o: target vector in residual domain */ + Word16 exc[], /* i/o: pointer to excitation signal frame */ + const Word16 *p_Aq, /* i : 12k8 Lp coefficient */ + const Word16 Ap[], /* i : weighted LP filter coefficients */ + const Word16 h1[], /* i : weighted filter i response */ + Word16 xn[], /* i/o: target vector */ + Word16 xn2[], /* i/o: target vector for innovation search */ + Word16 y1[], /* i/o: zero-memory filtered adaptive excitation */ + const Word16 y2[], /* i : zero-memory filtered innovative excitation */ + const Word16 Es_pred, /* i : predicited scaled innovation energy */ + Word16 *gain_pit, /* i/o: adaptive excitation gain */ + const Word32 gain_code, /* i : innovative excitation gain */ + Word16 g_corr[], /* o : ACELP correlation values */ + const Word16 clip_gain, /* i : adaptive gain clipping flag */ + Word16 *gain_preQ, /* o : prequantizer excitation gain */ + Word16 code_preQ[], /* o : prequantizer excitation */ + Word16 *unbits, /* o : number of AVQ unused bits */ + const Word16 Q_new, /* i : Current frame scaling */ + const Word16 shift /* i : shifting applied to y1, xn,... */ ); void gain_enc_lbr_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 gains_mode[], /* i : gain bits */ - const Word16 coder_type, /* i : coding type */ - const Word16 i_subfr, /* i : subframe index */ - const Word16* xn, /* i : target vector Q_xn*/ - const Word16* y1, /* i : zero-memory filtered adaptive excitation Q_xn*/ - const Word16 Q_xn, /* i : xn and y1 format */ - const Word16* y2, /* i : zero-memory filtered algebraic codebook excitation Q9*/ - const Word16* code, /* i : algebraic excitation Q9*/ - Word16* gain_pit, /* o : quantized pitch gain Q14*/ - Word32* gain_code, /* o : quantized codebook gain Q16*/ - Word16* gain_inov, /* o : gain of the innovation (used for normalization) Q12*/ - Word32* norm_gain_code, /* o : norm. gain of the codebook excitation Q16*/ - Word16* g_corr, /* i/o: correlations , -2,, -2 and 2 mant/exp*/ - Word32 gc_mem[], /* i/o: gain_code from previous subframes */ - Word16 gp_mem[], /* i/o: gain_pitch from previous subframes */ - const Word16 clip_gain, /* i : gain pitch clipping flag (1 = clipping) */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 gains_mode[], /* i : gain bits */ + const Word16 coder_type, /* i : coding type */ + const Word16 i_subfr, /* i : subframe index */ + const Word16 *xn, /* i : target vector Q_xn*/ + const Word16 *y1, /* i : zero-memory filtered adaptive excitation Q_xn*/ + const Word16 Q_xn, /* i : xn and y1 format */ + const Word16 *y2, /* i : zero-memory filtered algebraic codebook excitation Q9*/ + const Word16 *code, /* i : algebraic excitation Q9*/ + Word16 *gain_pit, /* o : quantized pitch gain Q14*/ + Word32 *gain_code, /* o : quantized codebook gain Q16*/ + Word16 *gain_inov, /* o : gain of the innovation (used for normalization) Q12*/ + Word32 *norm_gain_code, /* o : norm. gain of the codebook excitation Q16*/ + Word16 *g_corr, /* i/o: correlations , -2,, -2 and 2 mant/exp*/ + Word32 gc_mem[], /* i/o: gain_code from previous subframes */ + Word16 gp_mem[], /* i/o: gain_pitch from previous subframes */ + const Word16 clip_gain, /* i : gain pitch clipping flag (1 = clipping) */ const Word16 L_subfr /* i : subframe length */ ); void gain_enc_SQ_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 gains_mode[], /* i : gain bits */ - const Word16 i_subfr, /* i : subframe index */ - const Word16* xn, /* i : target vector Q_xn */ - const Word16* yy1, /* i : zero-memory filtered adaptive excitation Q_xn */ - const Word16* y2, /* i : zero-memory filtered algebraic codebook excitation Q9 */ - const Word16* code, /* i : algebraic excitation Q9 */ - const Word16 Es_pred, /* i : predicted scaled innovation energy Q8 */ - Word16* gain_pit, /* o : quantized pitch gain Q14 */ - Word32* gain_code, /* o : quantized codebook gain Q16 */ - Word16* gain_inov, /* o : gain of the innovation (used for normalization) Q12 */ - Word32* norm_gain_code, /* o : norm. gain of the codebook excitation Q16 */ - Word16* g_corr, /* i/o: correlations , ,, -2 and 2 */ - const Word16 clip_gain, /* i : gain pitch clipping flag (1 = clipping) */ - const Word16 Q_xn /* i : xn and y1 scaling */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 gains_mode[], /* i : gain bits */ + const Word16 i_subfr, /* i : subframe index */ + const Word16 *xn, /* i : target vector Q_xn */ + const Word16 *yy1, /* i : zero-memory filtered adaptive excitation Q_xn */ + const Word16 *y2, /* i : zero-memory filtered algebraic codebook excitation Q9 */ + const Word16 *code, /* i : algebraic excitation Q9 */ + const Word16 Es_pred, /* i : predicted scaled innovation energy Q8 */ + Word16 *gain_pit, /* o : quantized pitch gain Q14 */ + Word32 *gain_code, /* o : quantized codebook gain Q16 */ + Word16 *gain_inov, /* o : gain of the innovation (used for normalization) Q12 */ + Word32 *norm_gain_code, /* o : norm. gain of the codebook excitation Q16 */ + Word16 *g_corr, /* i/o: correlations , ,, -2 and 2 */ + const Word16 clip_gain, /* i : gain pitch clipping flag (1 = clipping) */ + const Word16 Q_xn /* i : xn and y1 scaling */ ); void updt_tar_fx( - const Word16 *x, /* i : old target (for pitch search) */ - Word16 *x2, /* o : new target (for codebook search) */ - const Word16 *y, /* i : filtered adaptive codebook vector */ - const Word16 gain, /* i : adaptive codebook gain */ - const Word16 L /* i : subframe size */ + const Word16 *x, /* i : old target (for pitch search) */ + Word16 *x2, /* o : new target (for codebook search) */ + const Word16 *y, /* i : filtered adaptive codebook vector */ + const Word16 gain, /* i : adaptive codebook gain */ + const Word16 L /* i : subframe size */ ); void updt_tar_HR_fx( - const Word16 *x, /* i : old target (for pitch search) */ - Word16 *x2, /* o : new target (for codebook search) */ - const Word16 *y, /* i : filtered adaptive codebook vector */ - const Word16 gain, /* i : adaptive codebook gain */ - const Word16 Qx, /* i : Scaling factor to adapt output to i */ - const Word16 L /* i : subframe size */ + const Word16 *x, /* i : old target (for pitch search) */ + Word16 *x2, /* o : new target (for codebook search) */ + const Word16 *y, /* i : filtered adaptive codebook vector */ + const Word16 gain, /* i : adaptive codebook gain */ + const Word16 Qx, /* i : Scaling factor to adapt output to i */ + const Word16 L /* i : subframe size */ ); #ifdef BASOP_NOGLOB @@ -2617,394 +2565,388 @@ Flag conv_fx( #else void conv_fx( #endif - const Word16 x[], /* i : i vector Q_new*/ - const Word16 h[], /* i : impulse response (or second i vector) Q(15)*/ - Word16 y[], /* o : output vetor (result of convolution) 12 bits*/ - const Word16 L /* i : vector size */ + const Word16 x[], /* i : i vector Q_new*/ + const Word16 h[], /* i : impulse response (or second i vector) Q(15)*/ + Word16 y[], /* o : output vetor (result of convolution) 12 bits*/ + const Word16 L /* i : vector size */ ); ivas_error ppp_voiced_encoder_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ SC_VBR_ENC_HANDLE hSC_VBR, const Word16 bwidth, /* i : audio bandwidth */ const Word16 last_coder_type_raw, /* i : raw last_coder_type */ - const Word16 old_pitch_buf[], /* i : buffer of old subframe pitch values */ - Word16* in_fx, /* i : residual signal */ - Word16* out_fx, /* o : Quantized residual signal */ - Word16 delay_fx, /* i : open loop pitch */ - Word16* lpc1_fx, /* i : prev frame de-emphasized LPC */ - Word16* lpc2_fx, /* i : current frame de-emphasized LPC */ - Word16* exc_fx, /* i: previous frame quantized excitation */ - Word16* pitch_fx, /* o: floating pitch values for each subframe */ - Word16 Qres -); + const Word16 old_pitch_buf[], /* i : buffer of old subframe pitch values */ + Word16 *in_fx, /* i : residual signal */ + Word16 *out_fx, /* o : Quantized residual signal */ + Word16 delay_fx, /* i : open loop pitch */ + Word16 *lpc1_fx, /* i : prev frame de-emphasized LPC */ + Word16 *lpc2_fx, /* i : current frame de-emphasized LPC */ + Word16 *exc_fx, /* i: previous frame quantized excitation */ + Word16 *pitch_fx, /* o: floating pitch values for each subframe */ + Word16 Qres ); void signalling_enc_fx( - Encoder_State *st_fx /* i : encoder state structure */ + Encoder_State *st_fx /* i : encoder state structure */ ); void transition_enc_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 i_subfr, /* i : subframe index */ - Word16 *tc_subfr, /* i/o: TC subframe index */ - Word16 *Jopt_flag, /* i : joint optimization flag */ - Word16 *position, /* i/o: maximum of residual signal index */ - Word16 *T0, /* i/o: close loop integer pitch Q0*/ - Word16 *T0_frac, /* i/o: close loop fractional part of the pitch Q0*/ - Word16 *T0_min, /* i/o: lower limit for close-loop search Q0*/ - Word16 *T0_max, /* i/o: higher limit for close-loop search Q0*/ - Word16 *exc_fx, /* i/o: pointer to excitation signal frame Q_new*/ - Word16 *y1_fx, /* o : zero-memory filtered adaptive excitation Q_new-1+shift*/ - const Word16 *h1_fx, /* i : weighted filter i response Q(14+shift)*/ - const Word16 *xn_fx, /* i : target vector Q_new-1+shift*/ - Word16 *xn2_fx, /* o : target vector for innovation search Q_new-1+shift*/ - Word16 *gp_cl_fx, /* i/o: memory of gain of pitch clipping algorithm */ - Word16 *gain_pit_fx, /* o : adaptive excitation gain Q14*/ - Word16 *g_corr_fx, /* o : ACELP correlation values */ - Word16 *clip_gain, /* i/o: adaptive gain clipping flag */ - Word16 **pt_pitch_fx, /* o : floating pitch values */ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE Q_new*/ - Word16* unbits_ACELP, /* i/o: unused bits */ - Word16 Q_new, /* i : Current scaling */ - Word16 shift /* i : downscaling needs for 12 bits convolutions */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word16 i_subfr, /* i : subframe index */ + Word16 *tc_subfr, /* i/o: TC subframe index */ + Word16 *Jopt_flag, /* i : joint optimization flag */ + Word16 *position, /* i/o: maximum of residual signal index */ + Word16 *T0, /* i/o: close loop integer pitch Q0*/ + Word16 *T0_frac, /* i/o: close loop fractional part of the pitch Q0*/ + Word16 *T0_min, /* i/o: lower limit for close-loop search Q0*/ + Word16 *T0_max, /* i/o: higher limit for close-loop search Q0*/ + Word16 *exc_fx, /* i/o: pointer to excitation signal frame Q_new*/ + Word16 *y1_fx, /* o : zero-memory filtered adaptive excitation Q_new-1+shift*/ + const Word16 *h1_fx, /* i : weighted filter i response Q(14+shift)*/ + const Word16 *xn_fx, /* i : target vector Q_new-1+shift*/ + Word16 *xn2_fx, /* o : target vector for innovation search Q_new-1+shift*/ + Word16 *gp_cl_fx, /* i/o: memory of gain of pitch clipping algorithm */ + Word16 *gain_pit_fx, /* o : adaptive excitation gain Q14*/ + Word16 *g_corr_fx, /* o : ACELP correlation values */ + Word16 *clip_gain, /* i/o: adaptive gain clipping flag */ + Word16 **pt_pitch_fx, /* o : floating pitch values */ + Word16 *bwe_exc_fx, /* o : excitation for SWB TBE Q_new*/ + Word16 *unbits_ACELP, /* i/o: unused bits */ + Word16 Q_new, /* i : Current scaling */ + Word16 shift /* i : downscaling needs for 12 bits convolutions */ ); void transf_cdbk_enc_fx( - Encoder_State* st_fx, /* i/o: encoder state structure */ - const Word16 harm_flag_acelp,/* i : harmonic flag for higher rates ACELP */ - const Word16 i_subfr, /* i : subframe index */ - Word16 cn[], /* i/o: target vector in residual domain */ - Word16 exc[], /* i/o: pointer to excitation signal frame */ - const Word16* p_Aq, /* i : 12k8 Lp coefficient */ - const Word16 Ap[], /* i : weighted LP filter coefficients */ - const Word16 h1[], /* i : weighted filter i response */ - Word16 xn[], /* i/o: target vector */ - Word16 xn2[], /* i/o: target vector for innovation search */ - Word16 y1[], /* i/o: zero-memory filtered adaptive excitation */ - const Word16 y2[], /* i : zero-memory filtered innovative excitation */ - const Word16 Es_pred, /* i : predicited scaled innovation energy */ - Word16* gain_pit, /* i/o: adaptive excitation gain */ - const Word32 gain_code, /* i : innovative excitation gain */ - Word16 g_corr[], /* o : ACELP correlation values */ - const Word16 clip_gain, /* i : adaptive gain clipping flag */ - Word16* gain_preQ, /* o : prequantizer excitation gain */ - Word16 code_preQ[], /* o : prequantizer excitation */ - Word16* unbits, /* o : number of AVQ unused bits */ - const Word16 Q_new, /* i : Current frame scaling */ - const Word16 shift /* i : shifting applied to y1, xn,... */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word16 harm_flag_acelp, /* i : harmonic flag for higher rates ACELP */ + const Word16 i_subfr, /* i : subframe index */ + Word16 cn[], /* i/o: target vector in residual domain */ + Word16 exc[], /* i/o: pointer to excitation signal frame */ + const Word16 *p_Aq, /* i : 12k8 Lp coefficient */ + const Word16 Ap[], /* i : weighted LP filter coefficients */ + const Word16 h1[], /* i : weighted filter i response */ + Word16 xn[], /* i/o: target vector */ + Word16 xn2[], /* i/o: target vector for innovation search */ + Word16 y1[], /* i/o: zero-memory filtered adaptive excitation */ + const Word16 y2[], /* i : zero-memory filtered innovative excitation */ + const Word16 Es_pred, /* i : predicited scaled innovation energy */ + Word16 *gain_pit, /* i/o: adaptive excitation gain */ + const Word32 gain_code, /* i : innovative excitation gain */ + Word16 g_corr[], /* o : ACELP correlation values */ + const Word16 clip_gain, /* i : adaptive gain clipping flag */ + Word16 *gain_preQ, /* o : prequantizer excitation gain */ + Word16 code_preQ[], /* o : prequantizer excitation */ + Word16 *unbits, /* o : number of AVQ unused bits */ + const Word16 Q_new, /* i : Current frame scaling */ + const Word16 shift /* i : shifting applied to y1, xn,... */ ); void gain_enc_tc_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 gains_mode[], /* i : gain bits */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 xn_fx[], /* i : target vector */ - const Word16 y2_fx[], /* i : zero-memory filtered algebraic codebook excitation */ - const Word16 code_fx[], /* i : algebraic excitation */ - const Word16 Es_pred_fx, /* i : predicted scaled innovation energy */ - Word16* gain_pit_fx, /* o : Pitch gain / Quantized pitch gain */ - Word32* gain_code_fx, /* o : quantized codebook gain */ - Word16* gain_inov_fx, /* o : innovation gain */ - Word32* norm_gain_code_fx, /* o : norm. gain of the codebook excitation */ - const Word16 Q_xn /* i : xn and y1 scaling Q0 */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 gains_mode[], /* i : gain bits */ + const Word16 i_subfr, /* i : subframe index */ + const Word16 xn_fx[], /* i : target vector */ + const Word16 y2_fx[], /* i : zero-memory filtered algebraic codebook excitation */ + const Word16 code_fx[], /* i : algebraic excitation */ + const Word16 Es_pred_fx, /* i : predicted scaled innovation energy */ + Word16 *gain_pit_fx, /* o : Pitch gain / Quantized pitch gain */ + Word32 *gain_code_fx, /* o : quantized codebook gain */ + Word16 *gain_inov_fx, /* o : innovation gain */ + Word32 *norm_gain_code_fx, /* o : norm. gain of the codebook excitation */ + const Word16 Q_xn /* i : xn and y1 scaling Q0 */ ); Word16 gaus_encode_fx( - Encoder_State* st_fx, /* i/o: encoder state structure */ - const Word16 i_subfr, /* i : subframe index */ - const Word16* h1, /* i : weighted filter i response */ - const Word16* xn, /* i : target vector */ - Word16* exc, /* o : pointer to excitation signal frame */ - Word16* mem_w0, /* o : weighting filter denominator memory */ - Word16* clip_gain, /* o : memory of gain of pitch clipping algorithm */ - Word16* tilt_code, /* o : synthesis excitation spectrum tilt */ - Word16* code, /* o : algebraic excitation Q9 */ - Word32* gain_code, /* o : Code gain. Q16 */ - Word16* y2, /* o : zero-memory filtered adaptive excitation Q9 */ - Word16* gain_inov, /* o : innovation gain Q12 */ - Word16* voice_fac, /* o : voicing factor Q15 */ - Word16* gain_pit, /* o : adaptive excitation gain Q14 */ - const Word16 Q_new, /* i : scaling factor */ - const Word16 shift, /* i : scaling factor */ - Word32* norm_gain_code /* o : normalized innovative cb. gain Q16 */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word16 i_subfr, /* i : subframe index */ + const Word16 *h1, /* i : weighted filter i response */ + const Word16 *xn, /* i : target vector */ + Word16 *exc, /* o : pointer to excitation signal frame */ + Word16 *mem_w0, /* o : weighting filter denominator memory */ + Word16 *clip_gain, /* o : memory of gain of pitch clipping algorithm */ + Word16 *tilt_code, /* o : synthesis excitation spectrum tilt */ + Word16 *code, /* o : algebraic excitation Q9 */ + Word32 *gain_code, /* o : Code gain. Q16 */ + Word16 *y2, /* o : zero-memory filtered adaptive excitation Q9 */ + Word16 *gain_inov, /* o : innovation gain Q12 */ + Word16 *voice_fac, /* o : voicing factor Q15 */ + Word16 *gain_pit, /* o : adaptive excitation gain Q14 */ + const Word16 Q_new, /* i : scaling factor */ + const Word16 shift, /* i : scaling factor */ + Word32 *norm_gain_code /* o : normalized innovative cb. gain Q16 */ ); void pre_proc_fx( - Encoder_State *st, /* i/o: encoder state structure */ - const Word16 input_frame, /* i : frame length */ - Word16 old_inp_12k8[], /* i/o: buffer of old i signal */ - Word16 old_inp_16k[], /* i/o: buffer of old i signal @ 16kHz */ - Word16 **inp, /* o : ptr. to inp. signal in the current frame */ - Word32 fr_bands[2 * NB_BANDS], /* o : energy in frequency bands */ - Word16 *Etot, /* o : total energy */ - Word32 *ener, /* o : residual energy from Levinson-Durbin */ + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 input_frame, /* i : frame length */ + Word16 old_inp_12k8[], /* i/o: buffer of old i signal */ + Word16 old_inp_16k[], /* i/o: buffer of old i signal @ 16kHz */ + Word16 **inp, /* o : ptr. to inp. signal in the current frame */ + Word32 fr_bands[2 * NB_BANDS], /* o : energy in frequency bands */ + Word16 *Etot, /* o : total energy */ + Word32 *ener, /* o : residual energy from Levinson-Durbin */ #ifndef FIX_I4_OL_PITCH - Word16 pitch_orig[3], /* o : open-loop pitch values for quantization */ + Word16 pitch_orig[3], /* o : open-loop pitch values for quantization */ #endif - Word16 A[NB_SUBFR16k*(M + 1)], /* o : A(z) unquantized for the 4 subframes */ - Word16 Aw[NB_SUBFR16k*(M + 1)], /* o : weighted A(z) unquantized for subframes */ - Word16 epsP_h[M + 1], /* o : LP prediction errors */ - Word16 epsP_l[M + 1], /* o : LP prediction errors */ - Word32 epsP[M + 1], /* o : LP prediction errors */ - Word16 lsp_new[M], /* o : LSPs at the end of the frame */ - Word16 lsp_mid[M], /* o : LSPs in the middle of the frame */ + Word16 A[NB_SUBFR16k * ( M + 1 )], /* o : A(z) unquantized for the 4 subframes */ + Word16 Aw[NB_SUBFR16k * ( M + 1 )], /* o : weighted A(z) unquantized for subframes */ + Word16 epsP_h[M + 1], /* o : LP prediction errors */ + Word16 epsP_l[M + 1], /* o : LP prediction errors */ + Word32 epsP[M + 1], /* o : LP prediction errors */ + Word16 lsp_new[M], /* o : LSPs at the end of the frame */ + Word16 lsp_mid[M], /* o : LSPs in the middle of the frame */ Word16 *vad_hover_flag, - Word16 *attack_flag, /* o : flag signalling attack encoded by AC mode (GSC) */ - Word16 *new_inp_resamp16k, /* o : new i signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ - Word16 *Voicing_flag, /* o : voicing flag for HQ FEC */ + Word16 *attack_flag, /* o : flag signalling attack encoded by AC mode (GSC) */ + Word16 *new_inp_resamp16k, /* o : new i signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ + Word16 *Voicing_flag, /* o : voicing flag for HQ FEC */ Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o : cldfb real buffer */ Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o : cldfb imag buffer */ - CLDFB_SCALE_FACTOR *cldfbScale, /* o : cldfb scale */ - Word16 *old_exc, /* i/o: static excitation memory */ - Word16 *hq_core_type, /* o : HQ core type */ + CLDFB_SCALE_FACTOR *cldfbScale, /* o : cldfb scale */ + Word16 *old_exc, /* i/o: static excitation memory */ + Word16 *hq_core_type, /* o : HQ core type */ Word16 *Q_new, Word16 *shift, - Word16 *Q_r -); + Word16 *Q_r ); void swb_bwe_enc_hr_fx( - Encoder_State* st_fx, /* i/o: encoder state structure */ - Word16* new_input_fx, /* i : i signal */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + Word16 *new_input_fx, /* i : i signal */ Word16 new_input_fx_exp, /* i : Exponent of i signal */ - const Word16 input_frame, /* i : frame length */ - const Word16 unbits /* i : number of core unused bits */ + const Word16 input_frame, /* i : frame length */ + const Word16 unbits /* i : number of core unused bits */ ); -Word16 gain_enc_gaus_fx( /* o : Return index of quantization */ - Word32 *gain, /* i/o: Code gain to quantize */ - const Word16 bits, /* i : number of bits to quantize */ - const Word16 lowBound, /* i : lower bound of quantizer (dB) Q8 */ - const Word16 stepSize, /* i : Step size choice Q14 */ - const Word16 inv_stepSize /* i : Step size choice Q15 */ +Word16 gain_enc_gaus_fx( /* o : Return index of quantization */ + Word32 *gain, /* i/o: Code gain to quantize */ + const Word16 bits, /* i : number of bits to quantize */ + const Word16 lowBound, /* i : lower bound of quantizer (dB) Q8 */ + const Word16 stepSize, /* i : Step size choice Q14 */ + const Word16 inv_stepSize /* i : Step size choice Q15 */ ); void enc_pit_exc_fx( - Encoder_State* st_fx, /* i/o: State structure */ - const Word16* speech, /* i : Input speech */ - const Word16 Aw[], /* i : weighted A(z) unquantized for subframes */ - const Word16 Aq[], /* i : 12k8 Lp coefficient */ - const Word16 Es_pred, /* i : predicted scaled innov. energy */ - const Word16* res, /* i : residual signal */ - Word16* synth, /* i/o: core synthesis */ - Word16* exc, /* i/o: current non-enhanced excitation */ - Word16* T0, /* i/o: close loop integer pitch */ - Word16* T0_frac, /* i/o: close-loop pitch period - fractional part */ - Word16* pitch_buf, /* i/o: Fractionnal per subframe pitch */ - const Word16 nb_subfr, /* i : Number of subframe considered */ - Word16* gpit, /* o : pitch mean gpit */ - Word16* saved_bit_pos, /* o : saved position in the bitstream before pitch contribution */ - const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ - const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer */ + Encoder_State *st_fx, /* i/o: State structure */ + const Word16 *speech, /* i : Input speech */ + const Word16 Aw[], /* i : weighted A(z) unquantized for subframes */ + const Word16 Aq[], /* i : 12k8 Lp coefficient */ + const Word16 Es_pred, /* i : predicted scaled innov. energy */ + const Word16 *res, /* i : residual signal */ + Word16 *synth, /* i/o: core synthesis */ + Word16 *exc, /* i/o: current non-enhanced excitation */ + Word16 *T0, /* i/o: close loop integer pitch */ + Word16 *T0_frac, /* i/o: close-loop pitch period - fractional part */ + Word16 *pitch_buf, /* i/o: Fractionnal per subframe pitch */ + const Word16 nb_subfr, /* i : Number of subframe considered */ + Word16 *gpit, /* o : pitch mean gpit */ + Word16 *saved_bit_pos, /* o : saved position in the bitstream before pitch contribution */ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer */ Word16 Q_new, - Word16 shift -); -Word16 Pit_exc_contribution_len_fx( /* o : bin where pitch contribution is significant */ - Encoder_State *st_fx, /* i/o: state structure */ - const Word16 *dct_res, /* i : DCT of residual */ - Word16 *dct_pitex, /* i/o: DCT of pitch contribution */ - Word16 *pitch_buf, /* i/o: Pitch per subframe */ - const Word16 nb_subfr, /* i : Number of subframe considered */ - Word16 *hangover, /* i : hangover for the time contribution switching */ - Word16 Qnew -); + Word16 shift ); +Word16 Pit_exc_contribution_len_fx( /* o : bin where pitch contribution is significant */ + Encoder_State *st_fx, /* i/o: state structure */ + const Word16 *dct_res, /* i : DCT of residual */ + Word16 *dct_pitex, /* i/o: DCT of pitch contribution */ + Word16 *pitch_buf, /* i/o: Pitch per subframe */ + const Word16 nb_subfr, /* i : Number of subframe considered */ + Word16 *hangover, /* i : hangover for the time contribution switching */ + Word16 Qnew ); Word16 pvq_core_enc_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - Word16 coefs_norm[], /* i/o: normalized coefficients to encode */ - Word16 coefs_quant[], /* o : quantized coefficients */ - Word16* Q_coefs, + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 coefs_norm[], /* i/o: normalized coefficients to encode */ + Word16 coefs_quant[], /* o : quantized coefficients */ + Word16 *Q_coefs, const Word16 bits_tot, /* i : total number of bits */ const Word16 nb_sfm, /* i : number of bands */ - const Word16* sfm_start, /* i : Subband start coefficient */ - const Word16* sfm_end, /* i : Subband end coefficient */ - const Word16* sfmsize, /* i : subband width */ - Word16* R, /* i/o: Bit allocation/Adjusted bit alloc. Q3 */ - Word16* Rs, /* i/o: Integer bit allocation */ - Word16* npulses, /* o : number of pulses */ - Word16* maxpulse, /* i : maximum pulse per band */ + const Word16 *sfm_start, /* i : Subband start coefficient */ + const Word16 *sfm_end, /* i : Subband end coefficient */ + const Word16 *sfmsize, /* i : subband width */ + Word16 *R, /* i/o: Bit allocation/Adjusted bit alloc. Q3 */ + Word16 *Rs, /* i/o: Integer bit allocation */ + Word16 *npulses, /* o : number of pulses */ + Word16 *maxpulse, /* i : maximum pulse per band */ const Word16 core /* i : number of bands */ ); void core_switching_hq_prepare_enc_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - Word16 *num_bits, /* i/o: bit budget update */ - const Word16 input_frame, /* i : frame length */ - Word32 *wtda_audio, /* shall be q_audio + 15, audio allready scalled in wtda function */ - const Word16 *audio -); + Encoder_State *st_fx, /* i/o: encoder state structure */ + Word16 *num_bits, /* i/o: bit budget update */ + const Word16 input_frame, /* i : frame length */ + Word32 *wtda_audio, /* shall be q_audio + 15, audio allready scalled in wtda function */ + const Word16 *audio ); void hq_lr_enc_fx( - Encoder_State *st_fx, /* i/o: : encoder state structure */ - Word32 L_t_audio[], /* i/o: Q12 : transform-domain coefs. */ - const Word16 inner_frame_fx, /* i : Q0 : inner frame length */ - Word16 *num_bits_fx, /* i/o: Q0 : number of available bits */ - const Word16 is_transient_fx /* i : Q0 : transient flag */ + Encoder_State *st_fx, /* i/o: : encoder state structure */ + Word32 L_t_audio[], /* i/o: Q12 : transform-domain coefs. */ + const Word16 inner_frame_fx, /* i : Q0 : inner frame length */ + Word16 *num_bits_fx, /* i/o: Q0 : number of available bits */ + const Word16 is_transient_fx /* i : Q0 : transient flag */ ); void hq_hr_enc_fx( - Encoder_State* st_fx, /* i/o: encoder state structure fx */ - Word32* t_audio, /* i/o: transform-domain coefficients Q12 */ - const Word16 length, /* i : length of spectrum Q0 */ - Word16* num_bits, /* i : number of available bits Q0 */ - const Word16 is_transient, /* i : transient flag Q0 */ - const Word16 vad_hover_flag /* i : VAD hangover flag */ + Encoder_State *st_fx, /* i/o: encoder state structure fx */ + Word32 *t_audio, /* i/o: transform-domain coefficients Q12 */ + const Word16 length, /* i : length of spectrum Q0 */ + Word16 *num_bits, /* i : number of available bits Q0 */ + const Word16 is_transient, /* i : transient flag Q0 */ + const Word16 vad_hover_flag /* i : VAD hangover flag */ ); void reordernorm_fx( - const Word16 *ynrm, /* i : quantization indices for norms Q0 */ - const Word16 *normqlg2, /* i : quantized norms Q0 */ - Word16 *idxbuf, /* o : reordered quantization indices Q0 */ - Word16 *normbuf, /* o : reordered quantized norms Q0 */ - const Word16 nb_sfm /* i : number of bands Q0 */ + const Word16 *ynrm, /* i : quantization indices for norms Q0 */ + const Word16 *normqlg2, /* i : quantized norms Q0 */ + Word16 *idxbuf, /* o : reordered quantization indices Q0 */ + Word16 *normbuf, /* o : reordered quantized norms Q0 */ + const Word16 nb_sfm /* i : number of bands Q0 */ ); void diffcod_fx( - const Word16 N, /* (i) number of sub-vectors */ - Word16 *y, /* (i/o) indices of quantized norms */ - Word16 *difidx /* (o) differential code */ + const Word16 N, /* (i) number of sub-vectors */ + Word16 *y, /* (i/o) indices of quantized norms */ + Word16 *difidx /* (o) differential code */ ); -Word16 hq_classifier_enc_fx( /* o : Consumed bits Q0 */ - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 length, /* i : Frame length Q0 */ - const Word32 *coefs, /* i : Spectral coefficients Q12 */ - const Word16 is_transient, /* i : Transient flag Q0 */ - Word16 *Npeaks, /* o : Number of identified peaks Q0 */ - Word16 *peaks, /* o : Peak indices Q0 */ - Word32 *pe_gains, /* o : Peak gains Q12 */ - Word32 *nf_gains, /* o : Noise-fill gains Q12 */ - Word16 *hqswb_clas /* o : HQ class Q0 */ +Word16 hq_classifier_enc_fx( /* o : Consumed bits Q0 */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word16 length, /* i : Frame length Q0 */ + const Word32 *coefs, /* i : Spectral coefficients Q12 */ + const Word16 is_transient, /* i : Transient flag Q0 */ + Word16 *Npeaks, /* o : Number of identified peaks Q0 */ + Word16 *peaks, /* o : Peak indices Q0 */ + Word32 *pe_gains, /* o : Peak gains Q12 */ + Word32 *nf_gains, /* o : Noise-fill gains Q12 */ + Word16 *hqswb_clas /* o : HQ class Q0 */ ); void diff_envelope_coding_fx( - const Word16 is_transient, /* i : transient indicator Q0 */ - const Word16 num_env_bands, /* i : number of envelope bands to code Q0 */ - const Word16 start_norm, /* i : start of envelope coding Q0 */ - Word16 *ynrm, /* i/o: quantization indices for norms Q0 */ - Word16 *normqlg2, /* i/o: quantized norms Q0 */ - Word16 *difidx /* o : differential code Q0 */ -); - -Word16 encode_envelope_indices_fx( /* o : Number of bits if flag_pack=0,0 if flag_pack=1 Q0 */ - BSTR_ENC_HANDLE hBstr, /* i : handle to the bitstream */ - const Word16 num_sfm, /* i : Number of subbands Q0 */ - const Word16 numnrmibits, /* i : Bitrate of fall-back coding mode Q0 */ - Word16 *difidx, /* i/o: Diff indices/encoded diff indices Q0 */ - Word16 *LCmode, /* o : Coding mode if flag_pack=0, i : if flag_pack=1 Q0 */ - const Word16 flag_pack, /* i : indicator of packing or estimating bits Q0 */ - const Word16 flag_HQ2 /* i : indicator of HQ2 core Q0 */ - , - const Word16 is_transient /* i : indicator of HQ_TRANSIENT Q0 */ + const Word16 is_transient, /* i : transient indicator Q0 */ + const Word16 num_env_bands, /* i : number of envelope bands to code Q0 */ + const Word16 start_norm, /* i : start of envelope coding Q0 */ + Word16 *ynrm, /* i/o: quantization indices for norms Q0 */ + Word16 *normqlg2, /* i/o: quantized norms Q0 */ + Word16 *difidx /* o : differential code Q0 */ +); + +Word16 encode_envelope_indices_fx( /* o : Number of bits if flag_pack=0,0 if flag_pack=1 Q0 */ + BSTR_ENC_HANDLE hBstr, /* i : handle to the bitstream */ + const Word16 num_sfm, /* i : Number of subbands Q0 */ + const Word16 numnrmibits, /* i : Bitrate of fall-back coding mode Q0 */ + Word16 *difidx, /* i/o: Diff indices/encoded diff indices Q0 */ + Word16 *LCmode, /* o : Coding mode if flag_pack=0, i : if flag_pack=1 Q0 */ + const Word16 flag_pack, /* i : indicator of packing or estimating bits Q0 */ + const Word16 flag_HQ2 /* i : indicator of HQ2 core Q0 */ + , + const Word16 is_transient /* i : indicator of HQ_TRANSIENT Q0 */ ); void hq_generic_encoding_fx( - const Word32 *coefs_fx, /* i : MDCT coefficients of weighted original */ - Word16 *hq_generic_fenv_fx, /* i/o: energy of SWB envelope */ - const Word16 hq_generic_offset, /* i : frequency offset for extracting energy */ - Encoder_State *st_fx, /* i/o: encoder state structure */ - Word16 *hq_generic_exc_clas /* o : bwe excitation class */ + const Word32 *coefs_fx, /* i : MDCT coefficients of weighted original */ + Word16 *hq_generic_fenv_fx, /* i/o: energy of SWB envelope */ + const Word16 hq_generic_offset, /* i : frequency offset for extracting energy */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + Word16 *hq_generic_exc_clas /* o : bwe excitation class */ ); void normalizecoefs_fx( - Word32 *coefs, /* i : Input vector (Q12) */ - const Word16 *ynrm, /* i : quantization indices for norms */ - const Word16 num_bands, /* i : Number of bands */ - const Word16 *band_start, /* i : Start of bands */ - const Word16 *band_end, /* i : End of bands */ - Word16 *coefs_norm /* o : Normalized output vector (Q12) */ -); - -Word16 hvq_enc_fx( /* o : Consumed bits */ - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word32 brate, /* i : Total bit rate */ - const Word16 hvq_bits, /* i : HVQ bit budget */ - const Word16 Npeaks, /* i : Number of peaks */ - const Word16 *ynrm, /* i : Envelope coefficients */ - Word16 *R, /* i/o: Bit allocation/updated bit allocation */ - Word16 *peaks, /* i : Peak pos. / Encoded peak pos. */ - Word32 *nf_gains, /* i/o: Noise fill gains / Quant. nf gains */ - Word16 *noise_level, /* o : Quantized noise level */ - const Word32 *pe_gains, /* i : Peak gains */ - const Word32 *coefs, /* i : spectrum coefficients in Q14 */ - Word32 *coefs_out /* o : encoded spectrum coefficients in Q14 */ + Word32 *coefs, /* i : Input vector (Q12) */ + const Word16 *ynrm, /* i : quantization indices for norms */ + const Word16 num_bands, /* i : Number of bands */ + const Word16 *band_start, /* i : Start of bands */ + const Word16 *band_end, /* i : End of bands */ + Word16 *coefs_norm /* o : Normalized output vector (Q12) */ +); + +Word16 hvq_enc_fx( /* o : Consumed bits */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word32 brate, /* i : Total bit rate */ + const Word16 hvq_bits, /* i : HVQ bit budget */ + const Word16 Npeaks, /* i : Number of peaks */ + const Word16 *ynrm, /* i : Envelope coefficients */ + Word16 *R, /* i/o: Bit allocation/updated bit allocation */ + Word16 *peaks, /* i : Peak pos. / Encoded peak pos. */ + Word32 *nf_gains, /* i/o: Noise fill gains / Quant. nf gains */ + Word16 *noise_level, /* o : Quantized noise level */ + const Word32 *pe_gains, /* i : Peak gains */ + const Word32 *coefs, /* i : spectrum coefficients in Q14 */ + Word32 *coefs_out /* o : encoded spectrum coefficients in Q14 */ ); Word16 pvq_core_enc_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - Word16 coefs_norm[], /* i/o: normalized coefficients to encode */ - Word16 coefs_quant[], /* o : quantized coefficients */ - Word16* Q_coefs, + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 coefs_norm[], /* i/o: normalized coefficients to encode */ + Word16 coefs_quant[], /* o : quantized coefficients */ + Word16 *Q_coefs, const Word16 bits_tot, /* i : total number of bits */ const Word16 nb_sfm, /* i : number of bands */ - const Word16* sfm_start, /* i : Subband start coefficient */ - const Word16* sfm_end, /* i : Subband end coefficient */ - const Word16* sfmsize, /* i : subband width */ - Word16* R, /* i/o: Bit allocation/Adjusted bit alloc. Q3 */ - Word16* Rs, /* i/o: Integer bit allocation */ - Word16* npulses, /* o : number of pulses */ - Word16* maxpulse, /* i : maximum pulse per band */ + const Word16 *sfm_start, /* i : Subband start coefficient */ + const Word16 *sfm_end, /* i : Subband end coefficient */ + const Word16 *sfmsize, /* i : subband width */ + Word16 *R, /* i/o: Bit allocation/Adjusted bit alloc. Q3 */ + Word16 *Rs, /* i/o: Integer bit allocation */ + Word16 *npulses, /* o : number of pulses */ + Word16 *maxpulse, /* i : maximum pulse per band */ const Word16 core /* i : number of bands */ ); -Word16 noise_adjust_fx( /* o : index of noise attenuation Q0 */ - const Word16 *coeffs_norm, /* i : normalized coefficients Qx */ - const Word16 qx, /* i : Q value of coeffs_norm */ - const Word16 *bitalloc, /* i : bit allocation Q0 */ - const Word16 *sfm_start, /* i : band start Q0 */ - const Word16 *sfm_end, /* i : band end Q0 */ - const Word16 core_sfm /* i : index of the end band for core Q0 */ +Word16 noise_adjust_fx( /* o : index of noise attenuation Q0 */ + const Word16 *coeffs_norm, /* i : normalized coefficients Qx */ + const Word16 qx, /* i : Q value of coeffs_norm */ + const Word16 *bitalloc, /* i : bit allocation Q0 */ + const Word16 *sfm_start, /* i : band start Q0 */ + const Word16 *sfm_end, /* i : band end Q0 */ + const Word16 core_sfm /* i : index of the end band for core Q0 */ ); ivas_error tcq_core_LR_enc_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - Word16 inp_vector_fx[], /* x5 */ - const Word32 coefs_norm_fx[], /* Q12 */ - Word32 coefs_quant_fx[], /* Q12 */ - const Word16 bit_budget, /* number of bits */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 inp_vector_fx[], /* x5 */ + const Word32 coefs_norm_fx[], /* Q12 */ + Word32 coefs_quant_fx[], /* Q12 */ + const Word16 bit_budget, /* number of bits */ const Word16 BANDS, - const Word16* sfm_start, - const Word16* sfm_end, - const Word16* sfmsize, - Word32* R_fx, /* Q16 */ - Word16* npulses, - Word16* k_sort, - const Word16* p2a_flags, + const Word16 *sfm_start, + const Word16 *sfm_end, + const Word16 *sfmsize, + Word32 *R_fx, /* Q16 */ + Word16 *npulses, + Word16 *k_sort, + const Word16 *p2a_flags, const Word16 p2a_bands, - const Word16* last_bitalloc, + const Word16 *last_bitalloc, const Word16 input_frame, const Word16 adjustFlag, - const Word16 is_transient -); - -Word16 encode_envelope_indices_fx( /* o : Number of bits if flag_pack=0,0 if flag_pack=1 Q0 */ - BSTR_ENC_HANDLE hBstr, /* i : handle to the bitstream */ - const Word16 num_sfm, /* i : Number of subbands Q0 */ - const Word16 numnrmibits, /* i : Bitrate of fall-back coding mode Q0 */ - Word16 *difidx, /* i/o: Diff indices/encoded diff indices Q0 */ - Word16 *LCmode, /* o : Coding mode if flag_pack=0, i : if flag_pack=1 Q0 */ - const Word16 flag_pack, /* i : indicator of packing or estimating bits Q0 */ - const Word16 flag_HQ2 /* i : indicator of HQ2 core Q0 */ - , - const Word16 is_transient /* i : indicator of HQ_TRANSIENT Q0 */ + const Word16 is_transient ); + +Word16 encode_envelope_indices_fx( /* o : Number of bits if flag_pack=0,0 if flag_pack=1 Q0 */ + BSTR_ENC_HANDLE hBstr, /* i : handle to the bitstream */ + const Word16 num_sfm, /* i : Number of subbands Q0 */ + const Word16 numnrmibits, /* i : Bitrate of fall-back coding mode Q0 */ + Word16 *difidx, /* i/o: Diff indices/encoded diff indices Q0 */ + Word16 *LCmode, /* o : Coding mode if flag_pack=0, i : if flag_pack=1 Q0 */ + const Word16 flag_pack, /* i : indicator of packing or estimating bits Q0 */ + const Word16 flag_HQ2 /* i : indicator of HQ2 core Q0 */ + , + const Word16 is_transient /* i : indicator of HQ_TRANSIENT Q0 */ ); void diffcod_lrmdct_fx( - const Word16 N, /* i : number of sub-vectors */ - const Word16 be_ref, /* i : band energy reference */ - Word16 *y, /* i/o: indices of quantized norms */ - Word16 *difidx, /* o : differential code */ - const Word16 is_transient /* i : transient flag */ + const Word16 N, /* i : number of sub-vectors */ + const Word16 be_ref, /* i : band energy reference */ + Word16 *y, /* i/o: indices of quantized norms */ + Word16 *difidx, /* o : differential code */ + const Word16 is_transient /* i : transient flag */ ); Word16 peak_vq_enc_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 bwidth, /* i : audio bandwidth */ - const Word32* coefs, /* i : Input coefficient vector Q12 */ - Word32* coefs_out, /* o : Quantized output vector Q12 */ - const Word32 brate, /* i : Core bitrate */ - const Word16 num_bits, /* i : Number of bits for HVQ */ - const Word16 vq_peaks, /* i : Number of identified peaks */ - const Word16* ynrm, /* i : Envelope coefficients */ - Word16* R, /* i/o: Bit allocation/updated bit allocation */ - Word16* vq_peak_idx, /* i : Peak index vector */ - Word32* nf_gains /* i : Estimated noise floor gains Q12 */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 bwidth, /* i : audio bandwidth */ + const Word32 *coefs, /* i : Input coefficient vector Q12 */ + Word32 *coefs_out, /* o : Quantized output vector Q12 */ + const Word32 brate, /* i : Core bitrate */ + const Word16 num_bits, /* i : Number of bits for HVQ */ + const Word16 vq_peaks, /* i : Number of identified peaks */ + const Word16 *ynrm, /* i : Envelope coefficients */ + Word16 *R, /* i/o: Bit allocation/updated bit allocation */ + Word16 *vq_peak_idx, /* i : Peak index vector */ + Word32 *nf_gains /* i : Estimated noise floor gains Q12 */ ); void wb_vad_init_fx( @@ -3020,222 +2962,219 @@ void noise_est_init_fx( ); void InitSWBencBuffer_fx( - Encoder_State* st_fx /* i/o: SHB encoder structure */ + Encoder_State *st_fx /* i/o: SHB encoder structure */ ); void ResetSHBbuffer_Enc_fx( - Encoder_State* st_fx /* i/o: SHB encoder structure */ + Encoder_State *st_fx /* i/o: SHB encoder structure */ ); -Word16 E_ACELP_hh_corr(Word16 *x, Word16 *y, Word16 L_subfr, Word16 bits); +Word16 E_ACELP_hh_corr( Word16 *x, Word16 *y, Word16 L_subfr, Word16 bits ); void acelp_1t64_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 dn[], /* i : corr. between target and h[]. */ - const Word16 h[], /* i : impulse response of weighted synthesis filter */ - Word16 code[], /* o : algebraic (fixed) codebook excitation */ - Word16 y[], /* o : filtered fixed codebook excitation */ - const Word16 L_subfr /* i : subframe length */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 dn[], /* i : corr. between target and h[]. */ + const Word16 h[], /* i : impulse response of weighted synthesis filter */ + Word16 code[], /* o : algebraic (fixed) codebook excitation */ + Word16 y[], /* o : filtered fixed codebook excitation */ + const Word16 L_subfr /* i : subframe length */ ); void acelp_2t32_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 dn[], /* i : corr. between target and h[]. */ - const Word16 h[], /* i : impulse response of weighted synthesis filter */ - Word16 code[], /* o : algebraic (fixed) codebook excitation */ - Word16 y[] /* o : filtered fixed codebook excitation */ + const Word16 dn[], /* i : corr. between target and h[]. */ + const Word16 h[], /* i : impulse response of weighted synthesis filter */ + Word16 code[], /* o : algebraic (fixed) codebook excitation */ + Word16 y[] /* o : filtered fixed codebook excitation */ ); Word16 acelp_4t64_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - Word16 dn[], /* i : corr. between target and h[]. */ - const Word16 cn[], /* i : residual after long term prediction Q_new*/ - const Word16 H[], /* i : impulse response of weighted synthesis filter Q12*/ - Word16 R[], /* i : autocorrelation values */ - const Word16 acelpautoc, /* i : autocorrealtion flag */ - Word16 code[], /* o : algebraic (fixed) codebook excitation Q9*/ - Word16 y[], /* o : filtered fixed codebook excitation Q9*/ - Word16 nbbits, /* i : number of bits per codebook */ - const Word16 cmpl_flag, /* i : coomplexity reduction flag */ - const Word16 Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 dn[], /* i : corr. between target and h[]. */ + const Word16 cn[], /* i : residual after long term prediction Q_new*/ + const Word16 H[], /* i : impulse response of weighted synthesis filter Q12*/ + Word16 R[], /* i : autocorrelation values */ + const Word16 acelpautoc, /* i : autocorrealtion flag */ + Word16 code[], /* o : algebraic (fixed) codebook excitation Q9*/ + Word16 y[], /* o : filtered fixed codebook excitation Q9*/ + Word16 nbbits, /* i : number of bits per codebook */ + const Word16 cmpl_flag, /* i : coomplexity reduction flag */ + const Word16 Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ ); ivas_error evs_enc_fx( - Encoder_State* st, /* i/o: encoder state structure */ - const Word16* data, /* i : i signal */ - Word32* mem_hp20_in_fx, /* i/o: hp20 filter memory */ - const Word16 n_samples /* i : number of i samples */ + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 *data, /* i : i signal */ + Word32 *mem_hp20_in_fx, /* i/o: hp20 filter memory */ + const Word16 n_samples /* i : number of i samples */ ); /* y(n)(Qx) = alpha(Q15) * x(Qx) + (1.0f-alpha)* y(n-1) (Qx) */ -Word16 noise_est_AR1_Qx( /* o: Qx y(n) */ - Word16 x, /* i : Qx x(n) */ - Word16 y, /* i : Qx y(n-1) */ - Word16 alpha /*i : Q15 scaling of driving x(n) */ +Word16 noise_est_AR1_Qx( /* o: Qx y(n) */ + Word16 x, /* i : Qx x(n) */ + Word16 y, /* i : Qx y(n-1) */ + Word16 alpha /*i : Q15 scaling of driving x(n) */ ); void FEC_lsf_estim_enc_fx( - Encoder_State *st_fx, /* i : Encoder static memory */ - Word16 *lsf /* o : estimated LSF vector */ + Encoder_State *st_fx, /* i : Encoder static memory */ + Word16 *lsf /* o : estimated LSF vector */ ); Word32 mslvq_cng_fx( - Word16 idx_cv, /* i : index of cv from previous stage */ - Word16 *pTmp, /* i : 16 dimensional i vector x2.56*/ - Word16 *quant, /* o : quantized vector x2.56*/ - Word16 *cv_out, /* o : corresponding 8-dim lattice codevectors (without the scaling) Q13*/ - Word16 *idx_lead, /* o : leader index for each 8-dim subvector */ - Word16 *idx_scale, /* o : scale index for each subvector */ - const Word16 *w, /* i : weights for LSF quantization Q10*/ - Word16 * no_scales -); + Word16 idx_cv, /* i : index of cv from previous stage */ + Word16 *pTmp, /* i : 16 dimensional i vector x2.56*/ + Word16 *quant, /* o : quantized vector x2.56*/ + Word16 *cv_out, /* o : corresponding 8-dim lattice codevectors (without the scaling) Q13*/ + Word16 *idx_lead, /* o : leader index for each 8-dim subvector */ + Word16 *idx_scale, /* o : scale index for each subvector */ + const Word16 *w, /* i : weights for LSF quantization Q10*/ + Word16 *no_scales ); void Unified_weighting_fx( const Word32 Bin_Ener_128_fx[], /* i : FFT Bin energy 128 bins in two sets Q_ener */ Word16 Q_ener, - const Word16 lsf_fx[], /* i : LSF vector x2.56 */ - Word16 w_fx[], /* o : LP weighting filter (numerator) Q8 */ - const Word16 narrowBand, /* i : flag for Narrowband */ - const Word16 unvoiced, /* i : flag for Unvoiced frame */ - const Word32 sr_core, /* i : sampling rate of core-coder */ - const Word16 order /* i : LP order */ + const Word16 lsf_fx[], /* i : LSF vector x2.56 */ + Word16 w_fx[], /* o : LP weighting filter (numerator) Q8 */ + const Word16 narrowBand, /* i : flag for Narrowband */ + const Word16 unvoiced, /* i : flag for Unvoiced frame */ + const Word32 sr_core, /* i : sampling rate of core-coder */ + const Word16 order /* i : LP order */ ); Word32 qlsf_ARSN_tcvq_Enc_16k_fx( - const Word16 *x_fx, /* i : Vector to be encoded x2.65 */ - Word16 *y_fx, /* o : Quantized LSF vector x2.65 */ - Word16 *indice, /* o : Indices */ - const Word16 *w_fx, /* i : LSF Weights Q10 */ - const Word16 nBits, /* i : number of bits */ - Word16 safety_net /* i : safety_net flag */ + const Word16 *x_fx, /* i : Vector to be encoded x2.65 */ + Word16 *y_fx, /* o : Quantized LSF vector x2.65 */ + Word16 *indice, /* o : Indices */ + const Word16 *w_fx, /* i : LSF Weights Q10 */ + const Word16 nBits, /* i : number of bits */ + Word16 safety_net /* i : safety_net flag */ ); Word32 mslvq_fx( - Word16 *pTmp, /* i : M-dimensional i vector */ - Word16 *quant, /* o : quantized vector */ - Word16 *cv_out, /* o : corresponding 8-dim lattice codevectors (without the scaling) */ - Word16 *idx_lead, /* o : leader index for each 8-dim subvector */ - Word16 *idx_scale, /* o : scale index for each subvector */ - Word16 *w, /* i : weights for LSF quantization */ - Word16 mode, /* i : number indicating the coding type (V/UV/G...)*/ - Word16 mode_glb, /* i : LVQ coding mode */ - Word16 pred_flag, /* i : prediction flag (0: safety net, 1 - predictive )*/ - Word16 no_scales[][2] -); - -Word16 multi_harm_fx( /* o : frame multi-harmonicity (1-harmonic, 0-not) */ - const Word16 Bin_E[], /* i : log-energy spectrum of the current frame Q7 */ - Word16 old_S[], /* i/o: prev. log-energy spectrum w. subtracted floor Q7 */ - Word16 cor_map_LT[], /* i/o: LT correlation map Q15 */ - Word16* multi_harm_limit, /* i/o: multi harminic threshold Q9 */ - const Word32 total_brate, /* i : total bitrate Q0 */ - const Word16 bwidth, /* i : i signal bandwidth Q0 */ - Word16* cor_strong_limit, /* i/o: HF correlation indicator Q0 */ - Word16* st_mean_avr_dyn, /* i/o: long term average dynamic Q7 */ - Word16* st_last_sw_dyn, /* i/o: last dynamic Q7 */ - Word16* cor_map_sum, /* i : sum of correlation map Q8 */ - Word16* sp_floor, /* o: noise floor estimate Q7 */ - Word16 S_map[] /* o : short-term correlation map Q7 */ + Word16 *pTmp, /* i : M-dimensional i vector */ + Word16 *quant, /* o : quantized vector */ + Word16 *cv_out, /* o : corresponding 8-dim lattice codevectors (without the scaling) */ + Word16 *idx_lead, /* o : leader index for each 8-dim subvector */ + Word16 *idx_scale, /* o : scale index for each subvector */ + Word16 *w, /* i : weights for LSF quantization */ + Word16 mode, /* i : number indicating the coding type (V/UV/G...)*/ + Word16 mode_glb, /* i : LVQ coding mode */ + Word16 pred_flag, /* i : prediction flag (0: safety net, 1 - predictive )*/ + Word16 no_scales[][2] ); + +Word16 multi_harm_fx( /* o : frame multi-harmonicity (1-harmonic, 0-not) */ + const Word16 Bin_E[], /* i : log-energy spectrum of the current frame Q7 */ + Word16 old_S[], /* i/o: prev. log-energy spectrum w. subtracted floor Q7 */ + Word16 cor_map_LT[], /* i/o: LT correlation map Q15 */ + Word16 *multi_harm_limit, /* i/o: multi harminic threshold Q9 */ + const Word32 total_brate, /* i : total bitrate Q0 */ + const Word16 bwidth, /* i : i signal bandwidth Q0 */ + Word16 *cor_strong_limit, /* i/o: HF correlation indicator Q0 */ + Word16 *st_mean_avr_dyn, /* i/o: long term average dynamic Q7 */ + Word16 *st_last_sw_dyn, /* i/o: last dynamic Q7 */ + Word16 *cor_map_sum, /* i : sum of correlation map Q8 */ + Word16 *sp_floor, /* o: noise floor estimate Q7 */ + Word16 S_map[] /* o : short-term correlation map Q7 */ ); void pvq_encode_frame_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16* coefs_norm, /* i : normalized coefficients to encode */ - Word16 Q_coefs, /* i : Q-point of coefs_norm[] */ - Word16* coefs_quant, /* o : quantized coefficients */ - Word16* gopt, /* o : optimal shape gains */ - Word16* npulses, /* o : number of pulses per band */ - Word16* pulse_vector, /* o : non-normalized pulse shapes */ - const Word16* sfm_start, /* i : indices of first coefficients in the bands */ - const Word16* sfm_end, /* i : indices of last coefficients in the bands */ - const Word16* sfmsize, /* i : band sizes */ - const Word16 nb_sfm, /* i : total number of bands */ - const Word16* R, /* i : bitallocation per band Q3 */ - const Word16 pvq_bits, /* i : number of bits avaiable */ - const Word16 core /* i : core */ -); - -Word16 Interpol_4( /* o : interpolated value */ - Word16 * x, /* i : i vector */ - Word16 frac /* i : fraction (-4..+3) */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 *coefs_norm, /* i : normalized coefficients to encode */ + Word16 Q_coefs, /* i : Q-point of coefs_norm[] */ + Word16 *coefs_quant, /* o : quantized coefficients */ + Word16 *gopt, /* o : optimal shape gains */ + Word16 *npulses, /* o : number of pulses per band */ + Word16 *pulse_vector, /* o : non-normalized pulse shapes */ + const Word16 *sfm_start, /* i : indices of first coefficients in the bands */ + const Word16 *sfm_end, /* i : indices of last coefficients in the bands */ + const Word16 *sfmsize, /* i : band sizes */ + const Word16 nb_sfm, /* i : total number of bands */ + const Word16 *R, /* i : bitallocation per band Q3 */ + const Word16 pvq_bits, /* i : number of bits avaiable */ + const Word16 core /* i : core */ +); + +Word16 Interpol_4( /* o : interpolated value */ + Word16 *x, /* i : i vector */ + Word16 frac /* i : fraction (-4..+3) */ ); void set_ppp_mode_fx( - Encoder_State* st_fx, /* i/o: state structure */ - const Word16 noisy_speech_HO, /* i : SC-VBR noisy speech HO flag */ - const Word16 clean_speech_HO, /* i : SC-VBR clean speech HO flag */ - const Word16 NB_speech_HO, /* i : SC-VBR NB speech HO flag */ - const Word16 localVAD_he /* i : HE-SAD flag without hangover */ + Encoder_State *st_fx, /* i/o: state structure */ + const Word16 noisy_speech_HO, /* i : SC-VBR noisy speech HO flag */ + const Word16 clean_speech_HO, /* i : SC-VBR clean speech HO flag */ + const Word16 NB_speech_HO, /* i : SC-VBR NB speech HO flag */ + const Word16 localVAD_he /* i : HE-SAD flag without hangover */ ); void decision_matrix_enc_fx( - Encoder_State *st_fx, /* i : encoder state structure */ - Word16 *hq_core_type /* o : HQ core_fx type */ + Encoder_State *st_fx, /* i : encoder state structure */ + Word16 *hq_core_type /* o : HQ core_fx type */ ); void pvq_encode_fx( BSTR_ENC_HANDLE hBstr, - PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ - const Word16 *x, /* i: vector to quantize Q15-3=>Q12 */ - Word16 *y, /* o: raw pulses (non-scaled short) Q0 */ - Word16 *xq, /* o: quantized vector Q15 */ - Word32 *L_xq, /* o: quantized vector Q31 */ - const Word16 pulses, /* i: number of allocated pulses */ - const Word16 dim, /* i: Length of vector */ - const Word16 neg_gain /* i: - Gain use - negative gain in Q15 0 ..1 */ + PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ + const Word16 *x, /* i: vector to quantize Q15-3=>Q12 */ + Word16 *y, /* o: raw pulses (non-scaled short) Q0 */ + Word16 *xq, /* o: quantized vector Q15 */ + Word32 *L_xq, /* o: quantized vector Q31 */ + const Word16 pulses, /* i: number of allocated pulses */ + const Word16 dim, /* i: Length of vector */ + const Word16 neg_gain /* i: - Gain use - negative gain in Q15 0 ..1 */ ); void rc_enc_init_fx( PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ - Word16 tot_bits /* i : Total bit budget */ + Word16 tot_bits /* i : Total bit budget */ ); void rc_enc_finish_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: Encoder state */ - PVQ_ENC_HANDLE hPVQ /* i/o: PVQ encoder handle */ + BSTR_ENC_HANDLE hBstr, /* i/o: Encoder state */ + PVQ_ENC_HANDLE hPVQ /* i/o: PVQ encoder handle */ ); void rc_encode_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ - UWord32 cum_freq, /* i : Cumulative frequency up to symbol */ - UWord32 sym_freq, /* i : Symbol probability */ - UWord32 tot /* i : Total cumulative frequency */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ + UWord32 cum_freq, /* i : Cumulative frequency up to symbol */ + UWord32 sym_freq, /* i : Symbol probability */ + UWord32 tot /* i : Total cumulative frequency */ ); void rc_enc_uniform_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ - UWord32 value, /* i : Value to encode */ - UWord32 tot /* i : Maximum value */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ + UWord32 value, /* i : Value to encode */ + UWord32 tot /* i : Maximum value */ ); void rc_enc_bits_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ - UWord32 value, /* i : Value to encode */ - Word16 bits /* i : Number of bits used */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ + UWord32 value, /* i : Value to encode */ + Word16 bits /* i : Number of bits used */ ); void re8_compute_base_index_fx( - const Word16 *x, /* i : Elemen of Q2, Q3 or Q4 */ - const Word16 ka, /* i : Identifier of the absolute leader related to x */ - UWord16 *I /* o : index */ + const Word16 *x, /* i : Elemen of Q2, Q3 or Q4 */ + const Word16 ka, /* i : Identifier of the absolute leader related to x */ + UWord16 *I /* o : index */ ); void tfaCalcEnv_fx( - const Word16* shb_speech, - Word32* enr -); + const Word16 *shb_speech, + Word32 *enr ); -Word16 delta_pit_enc_fx( /* o : pitch index */ - const Word16 fr_steps, /* i : fractional resolution steps (2 or 4)*/ - const Word16 T0, /* i : integer pitch lag */ - const Word16 T0_frac, /* i : pitch fraction */ - const Word16 T0_min /* i : delta search min */ +Word16 delta_pit_enc_fx( /* o : pitch index */ + const Word16 fr_steps, /* i : fractional resolution steps (2 or 4)*/ + const Word16 T0, /* i : integer pitch lag */ + const Word16 T0_frac, /* i : pitch fraction */ + const Word16 T0_min /* i : delta search min */ ); void set_impulse_fx( - const Word16 xn_fx[], /* i : target signal */ - const Word16 h_orig_fx[], /* i : impulse response of weighted synthesis filter */ + const Word16 xn_fx[], /* i : target signal */ + const Word16 h_orig_fx[], /* i : impulse response of weighted synthesis filter */ Word16 exc_fx[], /* o : adaptive codebook excitation */ Word16 yy1_fx[], /* o : filtered adaptive codebook excitation */ Word16 *imp_shape, /* o : adaptive codebook index */ @@ -3244,48 +3183,47 @@ void set_impulse_fx( Word16 Q_new /* i : Current scaling */ ); -Word16 abs_pit_enc_fx( /* o : pitch index */ - const Word16 fr_steps, /* i : fractional resolution steps (2 or 4) for shortest pitches*/ - const Word16 limit_flag, /* i : restrained(0) or extended(1) limits */ - const Word16 T0, /* i : integer pitch lag */ - const Word16 T0_frac /* i : pitch fraction */ +Word16 abs_pit_enc_fx( /* o : pitch index */ + const Word16 fr_steps, /* i : fractional resolution steps (2 or 4) for shortest pitches*/ + const Word16 limit_flag, /* i : restrained(0) or extended(1) limits */ + const Word16 T0, /* i : integer pitch lag */ + const Word16 T0_frac /* i : pitch fraction */ ); ivas_error ppp_quarter_encoder_fx( - Word16* returnFlag, /* o : return value */ - DTFS_STRUCTURE* CURRCW_Q_FX, /* o : Quantized (amp/phase) DTFS */ - DTFS_STRUCTURE* TARGETCW_FX, /* o : DTFS with quant phase but unquant Amp */ - Word16 prevCW_lag, /* i : previous lag */ - DTFS_STRUCTURE vCURRCW_NQ_FX, /* i : Unquantized DTFS */ - const Word16* curr_lpc_fx, /* i : LPCS */ - Word16* lastLgainE_fx, /* i/o: last low band gain */ - Word16* lastHgainE_fx, /* i/o: last high band gain */ - Word16* lasterbE_fx, /* i/o: last ERB vector */ - DTFS_STRUCTURE PREV_CW_E_FX, /* i : past DTFS */ - Word16* S_fx, /* i : sin table, Q15 */ - Word16* C_fx, /* i : cos table, Q15 */ - BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle */ + Word16 *returnFlag, /* o : return value */ + DTFS_STRUCTURE *CURRCW_Q_FX, /* o : Quantized (amp/phase) DTFS */ + DTFS_STRUCTURE *TARGETCW_FX, /* o : DTFS with quant phase but unquant Amp */ + Word16 prevCW_lag, /* i : previous lag */ + DTFS_STRUCTURE vCURRCW_NQ_FX, /* i : Unquantized DTFS */ + const Word16 *curr_lpc_fx, /* i : LPCS */ + Word16 *lastLgainE_fx, /* i/o: last low band gain */ + Word16 *lastHgainE_fx, /* i/o: last high band gain */ + Word16 *lasterbE_fx, /* i/o: last ERB vector */ + DTFS_STRUCTURE PREV_CW_E_FX, /* i : past DTFS */ + Word16 *S_fx, /* i : sin table, Q15 */ + Word16 *C_fx, /* i : cos table, Q15 */ + BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle */ ); void index_lvq_fx( - Word16 *quant, /* i : codevector to be indexed (2 8-dim subvectors) Q13*/ - Word16 *idx_lead, /* i : leader class index for each subvector */ - Word16 *idx_scale, /* i : scale index for each subvector */ - Word16 mode, /* i : integer signalling the quantizer structure for the current bitrate */ - Word16 *index, /* o : encoded index (represented on 3 short each with 15 bits ) */ - Word32 * p_offset_scale1, - Word32 * p_offset_scale2, - Word16 * p_no_scales -); + Word16 *quant, /* i : codevector to be indexed (2 8-dim subvectors) Q13*/ + Word16 *idx_lead, /* i : leader class index for each subvector */ + Word16 *idx_scale, /* i : scale index for each subvector */ + Word16 mode, /* i : integer signalling the quantizer structure for the current bitrate */ + Word16 *index, /* o : encoded index (represented on 3 short each with 15 bits ) */ + Word32 *p_offset_scale1, + Word32 *p_offset_scale2, + Word16 *p_no_scales ); ivas_error init_encoder_fx( - Encoder_State *st_fx /* i/o: Encoder static variables structure */ + Encoder_State *st_fx /* i/o: Encoder static variables structure */ ); void copy_encoder_config_fx( Encoder_Struct *st_ivas, /* i : IVAS encoder structure */ - Encoder_State *st, /* o : encoder state structure */ - const Word16 flag_all /* i : flag 1==update all, 0=partial update*/ + Encoder_State *st, /* o : encoder state structure */ + const Word16 flag_all /* i : flag 1==update all, 0=partial update*/ ); void destroy_encoder_fx( @@ -3293,8 +3231,8 @@ void destroy_encoder_fx( ); void amr_wb_enc_fx( - Encoder_State *st, /* i/o: encoder state structure */ + Encoder_State *st, /* i/o: encoder state structure */ const Word16 input_sp[], /* i : i signal */ const Word16 n_samples /* i : number of i samples */ ); -#endif \ No newline at end of file +#endif diff --git a/lib_enc/pvq_core_enc_fx.c b/lib_enc/pvq_core_enc_fx.c index 640788830..994a513a9 100644 --- a/lib_enc/pvq_core_enc_fx.c +++ b/lib_enc/pvq_core_enc_fx.c @@ -3,89 +3,87 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ +#include "options.h" /* Compilation switches */ #include "cnst.h" -#include "rom_com_fx.h" /* Static table prototypes */ -#include "rom_com.h" /* Static table prototypes */ +#include "rom_com_fx.h" /* Static table prototypes */ +#include "rom_com.h" /* Static table prototypes */ //#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ - /*-------------------------------------------------------------------* - * Local function prototypes - *--------------------------------------------------------------------*/ +/*-------------------------------------------------------------------* + * Local function prototypes + *--------------------------------------------------------------------*/ -static Word16 calc_pvq_splits_fx(BSTR_ENC_HANDLE hBstr, PVQ_ENC_HANDLE hPVQ, const Word16 band_bits, const Word16 sfmsize, const Word16 *y, const Word16 Q_y, - Word16 *bits); +static Word16 calc_pvq_splits_fx( BSTR_ENC_HANDLE hBstr, PVQ_ENC_HANDLE hPVQ, const Word16 band_bits, const Word16 sfmsize, const Word16 *y, const Word16 Q_y, Word16 *bits ); -static void densityIndexSymbolEncode_fx(BSTR_ENC_HANDLE hBstr, PVQ_ENC_HANDLE hPVQ, const Word16 density , const Word16 r_dim, const Word16 l_dim , const Word16 index_phi ); -static void encode_energies_fx(BSTR_ENC_HANDLE hBstr, PVQ_ENC_HANDLE hPVQ, const Word16* coefs, const Word16 Q_coefs, Word16 Np, - Word16* dim_part, Word32* E_part, Word16* bits_part, Word16* g_part, Word16 qband, Word16* bits_left, Word32 enr, Word16 dim, const Word16 strict_bits); +static void densityIndexSymbolEncode_fx( BSTR_ENC_HANDLE hBstr, PVQ_ENC_HANDLE hPVQ, const Word16 density, const Word16 r_dim, const Word16 l_dim, const Word16 index_phi ); +static void encode_energies_fx( BSTR_ENC_HANDLE hBstr, PVQ_ENC_HANDLE hPVQ, const Word16 *coefs, const Word16 Q_coefs, Word16 Np, Word16 *dim_part, Word32 *E_part, Word16 *bits_part, Word16 *g_part, Word16 qband, Word16 *bits_left, Word32 enr, Word16 dim, const Word16 strict_bits ); /* Encode band with PVQ */ static void pvq_encode_band_fx( BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ - const Word16* coefs_norm, /* i : normalized vector to encode */ + const Word16 *coefs_norm, /* i : normalized vector to encode */ const Word16 Q_coefs, - Word16 *pulse_vector, /* o : quantized vector, integer */ - Word16* npulses, /* o : number of pulses */ - Word16* coefs_quant, /* o : quantized vector */ - const Word16 sfmsize, /* i : length of vector */ - const Word16 band_bits, /* i : assigned bits */ - Word16* bits_left, /* o : bits remaining */ - const Word16 strict_bits /* i : conservative rounding flag */ + Word16 *pulse_vector, /* o : quantized vector, integer */ + Word16 *npulses, /* o : number of pulses */ + Word16 *coefs_quant, /* o : quantized vector */ + const Word16 sfmsize, /* i : length of vector */ + const Word16 band_bits, /* i : assigned bits */ + Word16 *bits_left, /* o : bits remaining */ + const Word16 strict_bits /* i : conservative rounding flag */ ) { Word16 K_val; Word16 j, Np; - Word32 enr, E_part[MAX_SPLITS+1]; - Word16 part_start[MAX_SPLITS+1], dim_part[MAX_SPLITS+1], bits_part[MAX_SPLITS+1]; + Word32 enr, E_part[MAX_SPLITS + 1]; + Word16 part_start[MAX_SPLITS + 1], dim_part[MAX_SPLITS + 1], bits_part[MAX_SPLITS + 1]; Word16 pool_tot, pool_part, dim_parts; Word16 g_part[MAX_SPLITS]; Word16 g_part_neg[MAX_SPLITS]; - Word16 sg_part[MAX_SPLITS+1]; - Word16 idx_sort[MAX_SPLITS+1]; + Word16 sg_part[MAX_SPLITS + 1]; + Word16 idx_sort[MAX_SPLITS + 1]; Word16 js, band_bits_tot, split_bit; Word16 tmp; Word32 L_coefs_quant_fx[PVQ_MAX_BAND_SIZE]; - Np = calc_pvq_splits_fx(hBstr, hPVQ, band_bits, sfmsize, coefs_norm, Q_coefs, &split_bit); - band_bits_tot = sub(band_bits, split_bit); + Np = calc_pvq_splits_fx( hBstr, hPVQ, band_bits, sfmsize, coefs_norm, Q_coefs, &split_bit ); + band_bits_tot = sub( band_bits, split_bit ); - enr = L_deposit_l(0); - FOR (j = 0; j < sfmsize; j++) + enr = L_deposit_l( 0 ); + FOR( j = 0; j < sfmsize; j++ ) { /* This is of paramount importance that the number of bits down-shift here * MUST BE IDENTICAL to that used to compute "l_enr" in encode_energies_fx(). * If the number of bits down-shift is changed here, that in encode_energies_fx() * must be changed to the same amount as well! */ - tmp = shr(coefs_norm[j], 2); - enr = L_mac0(enr, tmp, tmp); + tmp = shr( coefs_norm[j], 2 ); + enr = L_mac0( enr, tmp, tmp ); } - dim_parts = extract_h(L_mult(negate(sfmsize),lim_neg_inv_tbl_fx[Np])); - set16_fx( dim_part, dim_parts, sub(Np, 1) ); - dim_part[Np-1] = sub(sfmsize, i_mult2(dim_parts, sub(Np, 1))); + dim_parts = extract_h( L_mult( negate( sfmsize ), lim_neg_inv_tbl_fx[Np] ) ); + set16_fx( dim_part, dim_parts, sub( Np, 1 ) ); + dim_part[Np - 1] = sub( sfmsize, i_mult2( dim_parts, sub( Np, 1 ) ) ); move16(); part_start[0] = 0; move16(); - FOR (j = 1; j < Np; j++) + FOR( j = 1; j < Np; j++ ) { - part_start[j] = add(part_start[j-1], dim_part[j-1]); + part_start[j] = add( part_start[j - 1], dim_part[j - 1] ); move16(); } /* Encode energies */ - set16_fx(g_part_neg, -32768, Np); /* -1.0 in Q15 */ - IF (GT_16(Np, 1)) + set16_fx( g_part_neg, -32768, Np ); /* -1.0 in Q15 */ + IF( GT_16( Np, 1 ) ) { - encode_energies_fx(hBstr, hPVQ, coefs_norm, Q_coefs, Np, dim_part, E_part, bits_part, g_part_neg, band_bits_tot, bits_left, enr, sfmsize, strict_bits ); + encode_energies_fx( hBstr, hPVQ, coefs_norm, Q_coefs, Np, dim_part, E_part, bits_part, g_part_neg, band_bits_tot, bits_left, enr, sfmsize, strict_bits ); } ELSE { @@ -93,32 +91,32 @@ static void pvq_encode_band_fx( move16(); } - pool_tot = 0; /* Word16 */ - pool_part = 0; /* Word16 */ + pool_tot = 0; /* Word16 */ + pool_part = 0; /* Word16 */ - FOR (j = 0; j < Np; j++) + FOR( j = 0; j < Np; j++ ) { - g_part[j] = negate(g_part_neg[j]); + g_part[j] = negate( g_part_neg[j] ); } - srt_vec_ind16_fx(g_part, sg_part, idx_sort, Np); - FOR(j = 0; j < Np; j++) + srt_vec_ind16_fx( g_part, sg_part, idx_sort, Np ); + FOR( j = 0; j < Np; j++ ) { - js = idx_sort[Np-1-j]; - pool_part = shrtCDivSignedApprox( pool_tot, sub(Np, j) ); - bits_part[js] = s_max(0, s_min(add(bits_part[js], pool_part), 256)); + js = idx_sort[Np - 1 - j]; + pool_part = shrtCDivSignedApprox( pool_tot, sub( Np, j ) ); + bits_part[js] = s_max( 0, s_min( add( bits_part[js], pool_part ), 256 ) ); - conservativeL1Norm_fx(dim_part[js], bits_part[js], strict_bits, *bits_left, pool_tot, *npulses, /* inputs */ - &K_val, bits_left, &pool_tot, npulses); /* outputs */ + conservativeL1Norm_fx( dim_part[js], bits_part[js], strict_bits, *bits_left, pool_tot, *npulses, /* inputs */ + &K_val, bits_left, &pool_tot, npulses ); /* outputs */ - IF( K_val > 0 ) + IF( K_val > 0 ) { - pvq_encode_fx(hBstr, hPVQ, coefs_norm + part_start[js], pulse_vector + part_start[js], - coefs_quant + part_start[js], L_coefs_quant_fx, K_val, dim_part[js], g_part_neg[js]); + pvq_encode_fx( hBstr, hPVQ, coefs_norm + part_start[js], pulse_vector + part_start[js], + coefs_quant + part_start[js], L_coefs_quant_fx, K_val, dim_part[js], g_part_neg[js] ); } ELSE { - set16_fx(coefs_quant + part_start[js], 0, dim_part[js]); - set16_fx(pulse_vector + part_start[js], 0, dim_part[js]); + set16_fx( coefs_quant + part_start[js], 0, dim_part[js] ); + set16_fx( pulse_vector + part_start[js], 0, dim_part[js] ); } } @@ -126,20 +124,20 @@ static void pvq_encode_band_fx( } void pvq_encode_frame_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 *coefs_norm, /* i : normalized coefficients to encode */ - Word16 Q_coefs, /* i : Q-point of coefs_norm[] */ - Word16 *coefs_quant, /* o : quantized coefficients */ - Word16 *gopt, /* o : optimal shape gains */ - Word16 *npulses, /* o : number of pulses per band */ - Word16 *pulse_vector, /* o : non-normalized pulse shapes */ - const Word16 *sfm_start, /* i : indices of first coefficients in the bands */ - const Word16 *sfm_end, /* i : indices of last coefficients in the bands */ - const Word16 *sfmsize, /* i : band sizes */ - const Word16 nb_sfm, /* i : total number of bands */ - const Word16 *R, /* i : bitallocation per band Q3 */ - const Word16 pvq_bits, /* i : number of bits avaiable */ - const Word16 core /* i : core */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 *coefs_norm, /* i : normalized coefficients to encode */ + Word16 Q_coefs, /* i : Q-point of coefs_norm[] */ + Word16 *coefs_quant, /* o : quantized coefficients */ + Word16 *gopt, /* o : optimal shape gains */ + Word16 *npulses, /* o : number of pulses per band */ + Word16 *pulse_vector, /* o : non-normalized pulse shapes */ + const Word16 *sfm_start, /* i : indices of first coefficients in the bands */ + const Word16 *sfm_end, /* i : indices of last coefficients in the bands */ + const Word16 *sfmsize, /* i : band sizes */ + const Word16 nb_sfm, /* i : total number of bands */ + const Word16 *R, /* i : bitallocation per band Q3 */ + const Word16 pvq_bits, /* i : number of bits avaiable */ + const Word16 core /* i : core */ ) { Word16 i, j; @@ -159,31 +157,31 @@ void pvq_encode_frame_fx( Flag Overflow = 0; #endif - rc_enc_init_fx(hPVQ, pvq_bits); + rc_enc_init_fx( hPVQ, pvq_bits ); - bits = shl(sub(pvq_bits, RC_BITS_RESERVED), 3); + bits = shl( sub( pvq_bits, RC_BITS_RESERVED ), 3 ); bands_to_code = 0; move16(); - FOR (i = 0; i < nb_sfm; i++) + FOR( i = 0; i < nb_sfm; i++ ) { - if (R[i] > 0) + if ( R[i] > 0 ) { - bands_to_code = add(bands_to_code, 1); + bands_to_code = add( bands_to_code, 1 ); } } - IF (core == ACELP_CORE) + IF( core == ACELP_CORE ) { strict_bits = 1; move16(); - srt_vec_ind16_fx(R, R_sort, i_sort, nb_sfm); + srt_vec_ind16_fx( R, R_sort, i_sort, nb_sfm ); } ELSE { strict_bits = 0; move16(); - FOR (i = 0; i < nb_sfm; i++) + FOR( i = 0; i < nb_sfm; i++ ) { i_sort[i] = i; move16(); @@ -192,52 +190,52 @@ void pvq_encode_frame_fx( coded_bands = 0; move16(); - FOR (i = 0; i < nb_sfm; i++) + FOR( i = 0; i < nb_sfm; i++ ) { is = i_sort[i]; move16(); gopt[is] = 0; move16(); - IF (R[is] > 0) + IF( R[is] > 0 ) { - bandBitsAdjustment_fx(hPVQ->rc_num_bits, hPVQ->rc_range, bits, bands_to_code, bands_to_code-coded_bands, sfmsize[is] ,R[is], bit_pool, /* inputs */ - &band_bits, &bits_left, &bit_pool); /* outputs */ - pvq_encode_band_fx(hBstr, hPVQ, &coefs_norm[sfm_start[is]], Q_coefs, &pulse_vector[sfm_start[is]], + bandBitsAdjustment_fx( hPVQ->rc_num_bits, hPVQ->rc_range, bits, bands_to_code, bands_to_code - coded_bands, sfmsize[is], R[is], bit_pool, /* inputs */ + &band_bits, &bits_left, &bit_pool ); /* outputs */ + pvq_encode_band_fx( hBstr, hPVQ, &coefs_norm[sfm_start[is]], Q_coefs, &pulse_vector[sfm_start[is]], &npulses[is], &coefs_quant[sfm_start[is]], sfmsize[is], band_bits, - &bits_left, strict_bits); + &bits_left, strict_bits ); - xy_corr = L_deposit_l(0); - yy_corr = L_deposit_l(1); - shift = band_len_ener_shift[ band_len_idx[ shr(sfmsize[is], 3)] ]; + xy_corr = L_deposit_l( 0 ); + yy_corr = L_deposit_l( 1 ); + shift = band_len_ener_shift[band_len_idx[shr( sfmsize[is], 3 )]]; move16(); - FOR (j = 0; j < sfmsize[i]; j++) + FOR( j = 0; j < sfmsize[i]; j++ ) { - tmp = shr(coefs_quant[sfm_start[is]+j], shift); - xy_corr = L_mac0(xy_corr, shr(coefs_norm[sfm_start[is]+j], 1), tmp); /* Q_coefs-1+15-shift */ - yy_corr = L_mac0(yy_corr, tmp, tmp); /* 2*(15-shift) */ + tmp = shr( coefs_quant[sfm_start[is] + j], shift ); + xy_corr = L_mac0( xy_corr, shr( coefs_norm[sfm_start[is] + j], 1 ), tmp ); /* Q_coefs-1+15-shift */ + yy_corr = L_mac0( yy_corr, tmp, tmp ); /* 2*(15-shift) */ } - tmp = ratio(xy_corr, yy_corr, &exp); + tmp = ratio( xy_corr, yy_corr, &exp ); #ifdef BASOP_NOGLOB - gopt[is] = shl_o(tmp, sub(sub(sub(14, Q_coefs), shift), exp), &Overflow); + gopt[is] = shl_o( tmp, sub( sub( sub( 14, Q_coefs ), shift ), exp ), &Overflow ); #else /* BASOP_NOGLOB */ - gopt[is] = shl(tmp, sub(sub(sub(14, Q_coefs), shift), exp)); + gopt[is] = shl( tmp, sub( sub( sub( 14, Q_coefs ), shift ), exp ) ); #endif - if (gopt[is] == 0) + if ( gopt[is] == 0 ) { gopt[is] = 1; move16(); } /* Updates */ - coded_bands = add(coded_bands, 1); + coded_bands = add( coded_bands, 1 ); } ELSE { - FOR (j = sfm_start[is]; j < sfm_end[is]; j++) + FOR( j = sfm_start[is]; j < sfm_end[is]; j++ ) { - coefs_quant[j] = 0; + coefs_quant[j] = 0; move16(); pulse_vector[j] = 0; move16(); @@ -245,7 +243,7 @@ void pvq_encode_frame_fx( } } - rc_enc_finish_fx(hBstr, hPVQ); + rc_enc_finish_fx( hBstr, hPVQ ); return; } @@ -257,24 +255,24 @@ void pvq_encode_frame_fx( *---------------------------------------------------------------------*/ Word16 pvq_core_enc_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - Word16 coefs_norm[], /* i/o: normalized coefficients to encode */ - Word16 coefs_quant[], /* o : quantized coefficients */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 coefs_norm[], /* i/o: normalized coefficients to encode */ + Word16 coefs_quant[], /* o : quantized coefficients */ Word16 *Q_coefs, const Word16 bits_tot, /* i : total number of bits */ const Word16 nb_sfm, /* i : number of bands */ - const Word16* sfm_start, /* i : Subband start coefficient */ - const Word16* sfm_end, /* i : Subband end coefficient */ - const Word16* sfmsize, /* i : subband width */ - Word16* R, /* i/o: Bit allocation/Adjusted bit alloc. Q3 */ - Word16* Rs, /* i/o: Integer bit allocation */ - Word16* npulses, /* o : number of pulses */ - Word16* maxpulse, /* i : maximum pulse per band */ + const Word16 *sfm_start, /* i : Subband start coefficient */ + const Word16 *sfm_end, /* i : Subband end coefficient */ + const Word16 *sfmsize, /* i : subband width */ + Word16 *R, /* i/o: Bit allocation/Adjusted bit alloc. Q3 */ + Word16 *Rs, /* i/o: Integer bit allocation */ + Word16 *npulses, /* o : number of pulses */ + Word16 *maxpulse, /* i : maximum pulse per band */ const Word16 core /* i : number of bands */ ) { Word16 i; - Word16 R_upd; /* Q3 */ + Word16 R_upd; /* Q3 */ Word16 ord[NB_SFM_MAX]; Word16 fg_pred[NB_SFM_MAX]; Word16 pvq_bits; @@ -285,18 +283,18 @@ Word16 pvq_core_enc_fx( Word16 gain_bits_tot; - R_upd = shl(bits_tot, 3); + R_upd = shl( bits_tot, 3 ); gain_bits_tot = assign_gain_bits_fx( core, nb_sfm, sfmsize, R, gain_bits_array, &R_upd ); - pvq_bits = shr(R_upd, 3); + pvq_bits = shr( R_upd, 3 ); pvq_encode_frame_fx( hBstr, coefs_norm, *Q_coefs, coefs_quant, gopt, npulses, pulse_vector, sfm_start, sfm_end, sfmsize, nb_sfm, R, pvq_bits, core ); - + IF( Rs != NULL ) { - FOR (i=0; i < nb_sfm; i++) + FOR( i = 0; i < nb_sfm; i++ ) { - if (npulses[i] <= 0) + if ( npulses[i] <= 0 ) { Rs[i] = 0; move16(); /* Update Rs in case no pulses were assigned */ @@ -304,11 +302,11 @@ Word16 pvq_core_enc_fx( } } - FOR (i=0; i < nb_sfm; i++) + FOR( i = 0; i < nb_sfm; i++ ) { ord[i] = i; move16(); - if (npulses[i] <= 0) + if ( npulses[i] <= 0 ) { R[i] = 0; move16(); /* Update in case no pulses were assigned */ @@ -319,33 +317,34 @@ Word16 pvq_core_enc_fx( /* Fine gain prediction */ fine_gain_pred_fx( sfm_start, sfm_end, sfmsize, ord, npulses, maxpulse, R, nb_sfm, - coefs_quant, pulse_vector, fg_pred, core); + coefs_quant, pulse_vector, fg_pred, core ); - fine_gain_quant_fx(hBstr, ord, nb_sfm, gain_bits_array, fg_pred, gopt); + fine_gain_quant_fx( hBstr, ord, nb_sfm, gain_bits_array, fg_pred, gopt ); - apply_gain_fx(ord, sfm_start, sfm_end, nb_sfm, fg_pred, coefs_quant); + apply_gain_fx( ord, sfm_start, sfm_end, nb_sfm, fg_pred, coefs_quant ); *Q_coefs = 12; - return add(pvq_bits, gain_bits_tot);; + return add( pvq_bits, gain_bits_tot ); + ; } static void encode_energies_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ - const Word16 *coefs, /* In block-floating point format with a common block-exponent - not used in this function. Hence, the block-exponent is - not in the parameter list. */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ + const Word16 *coefs, /* In block-floating point format with a common block-exponent + not used in this function. Hence, the block-exponent is + not in the parameter list. */ const Word16 Q_coefs, - Word16 Np, /* i : number of parts */ - Word16 *dim_part, /* o : sizes of parts */ - Word32 *E_part, /* o : energies of parts 32-bit Q15 */ - Word16 *bits_part, /* o : assigned bits per part */ - Word16 *g_part, /* o : gains Q15 */ - Word16 qband, /* i : assigned quanta per band */ - Word16 *bits_left, /* o : remaining bits */ - Word32 enr, /* i : energy of vector */ - Word16 dim, /* i : size of vector */ - const Word16 strict_bits /* i : conservative rounding flag */ + Word16 Np, /* i : number of parts */ + Word16 *dim_part, /* o : sizes of parts */ + Word32 *E_part, /* o : energies of parts 32-bit Q15 */ + Word16 *bits_part, /* o : assigned bits per part */ + Word16 *g_part, /* o : gains Q15 */ + Word16 qband, /* i : assigned quanta per band */ + Word16 *bits_left, /* o : remaining bits */ + Word32 enr, /* i : energy of vector */ + Word16 dim, /* i : size of vector */ + const Word16 strict_bits /* i : conservative rounding flag */ ) { Word16 i, j, l_Np, r_Np; @@ -353,62 +352,62 @@ static void encode_energies_fx( Word32 l_enr, r_enr; Word16 l_gain, r_gain; Word16 il, ir; - Word16 density; - Word16 phi; + Word16 density; + Word16 phi; Word16 index_phi = -1; - Word16 oppRQ3, qzero ; + Word16 oppRQ3, qzero; Word16 angle; Word32 sqrt_r_enr, sqrt_l_enr; Word16 exp1, exp2, tmp; - l_Np = shr(Np, 1); - r_Np = sub(Np, l_Np); + l_Np = shr( Np, 1 ); + r_Np = sub( Np, l_Np ); - l_enr = L_deposit_l(0); + l_enr = L_deposit_l( 0 ); l_bits = 0; move16(); l_dim = 0; move16(); - FOR (i = 0; i < l_Np; i++) + FOR( i = 0; i < l_Np; i++ ) { - l_dim = add(l_dim, dim_part[i]); + l_dim = add( l_dim, dim_part[i] ); } - FOR (j = 0; j < l_dim; j++) + FOR( j = 0; j < l_dim; j++ ) { /* This is of paramount importance that the number of bits down-shift * must be identical to that used to compute "enr" in pvq_encode_band_fx(). * Otherwise, the subsequent "r_enr" will be computed incorrectly. */ - tmp = shr(coefs[j], 2); - l_enr = L_mac0(l_enr, tmp, tmp); + tmp = shr( coefs[j], 2 ); + l_enr = L_mac0( l_enr, tmp, tmp ); } - r_enr = L_sub(enr, l_enr); - r_dim = sub(dim, l_dim); + r_enr = L_sub( enr, l_enr ); + r_dim = sub( dim, l_dim ); - obtainEnergyQuantizerDensity_fx(dim, qband, &density); - sqrt_r_enr = Sqrt_l(r_enr, &exp1); - sqrt_l_enr = Sqrt_l(l_enr, &exp2); + obtainEnergyQuantizerDensity_fx( dim, qband, &density ); + sqrt_r_enr = Sqrt_l( r_enr, &exp1 ); + sqrt_l_enr = Sqrt_l( l_enr, &exp2 ); - IF (LT_16(exp1, exp2)) + IF( LT_16( exp1, exp2 ) ) { - sqrt_l_enr = L_shr(sqrt_l_enr, shr(sub(exp2, exp1), 1)); + sqrt_l_enr = L_shr( sqrt_l_enr, shr( sub( exp2, exp1 ), 1 ) ); } - ELSE IF (LT_16(exp2, exp1)) + ELSE IF( LT_16( exp2, exp1 ) ) { - sqrt_r_enr = L_shr(sqrt_r_enr, shr(sub(exp1, exp2), 1)); + sqrt_r_enr = L_shr( sqrt_r_enr, shr( sub( exp1, exp2 ), 1 ) ); exp1 = exp2; move16(); } - exp1 = add(shl(sub(Q_coefs, 2), 1), add(31, exp1)); /* 2x exponent */ - IF (EQ_16(s_and(exp1, 1), 1)) + exp1 = add( shl( sub( Q_coefs, 2 ), 1 ), add( 31, exp1 ) ); /* 2x exponent */ + IF( EQ_16( s_and( exp1, 1 ), 1 ) ) { - sqrt_r_enr = Mult_32_16(sqrt_r_enr, 23170); /* Q(exp1/2) */ - sqrt_l_enr = Mult_32_16(sqrt_l_enr, 23170); /* Q(exp1/2) */ + sqrt_r_enr = Mult_32_16( sqrt_r_enr, 23170 ); /* Q(exp1/2) */ + sqrt_l_enr = Mult_32_16( sqrt_l_enr, 23170 ); /* Q(exp1/2) */ } - IF (sqrt_r_enr != 0) + IF( sqrt_r_enr != 0 ) { - angle = atan2_fx(sqrt_r_enr, sqrt_l_enr); /* Q14 */ + angle = atan2_fx( sqrt_r_enr, sqrt_l_enr ); /* Q14 */ } ELSE { @@ -416,35 +415,36 @@ static void encode_energies_fx( move16(); } - phi = mult_r(angle, 20861); - - rangeCoderFinalizationFBits_fx(hPVQ->rc_num_bits, (UWord32)hPVQ->rc_range, &qzero); - densityAngle2RmsProjEnc_fx(density, phi , &index_phi, &ir, &il, &oppRQ3); - densityIndexSymbolEncode_fx( hBstr, hPVQ, density , r_dim, l_dim , index_phi ); + phi = mult_r( angle, 20861 ); + rangeCoderFinalizationFBits_fx( hPVQ->rc_num_bits, (UWord32) hPVQ->rc_range, &qzero ); + densityAngle2RmsProjEnc_fx( density, phi, &index_phi, &ir, &il, &oppRQ3 ); + densityIndexSymbolEncode_fx( hBstr, hPVQ, density, r_dim, l_dim, index_phi ); - l_gain = il; /* Q15 */ move16(); - r_gain = ir; /* Q15 */ move16(); + l_gain = il; /* Q15 */ + move16(); + r_gain = ir; /* Q15 */ + move16(); - FOR (i = 0; i < l_Np; i++) + FOR( i = 0; i < l_Np; i++ ) { - g_part[i] = mult_r(l_gain, g_part[i]); + g_part[i] = mult_r( l_gain, g_part[i] ); } - FOR (i = l_Np; i < Np; i++) + FOR( i = l_Np; i < Np; i++ ) { - g_part[i] = mult_r(r_gain, g_part[i]); + g_part[i] = mult_r( r_gain, g_part[i] ); } - NearOppSplitAdjustment_fx( qband, qzero, hPVQ->rc_num_bits, hPVQ->rc_range, *bits_left, - strict_bits, Np, dim_part[0], dim_part[Np-1], + NearOppSplitAdjustment_fx( qband, qzero, hPVQ->rc_num_bits, hPVQ->rc_range, *bits_left, + strict_bits, Np, dim_part[0], dim_part[Np - 1], l_dim, r_dim, oppRQ3, - &l_bits, &r_bits, bits_left); + &l_bits, &r_bits, bits_left ); - IF (GT_16(l_Np, 1)) + IF( GT_16( l_Np, 1 ) ) { - encode_energies_fx(hBstr, hPVQ, coefs, Q_coefs, l_Np, dim_part, E_part, bits_part, g_part, l_bits, bits_left, l_enr, l_dim, strict_bits ); + encode_energies_fx( hBstr, hPVQ, coefs, Q_coefs, l_Np, dim_part, E_part, bits_part, g_part, l_bits, bits_left, l_enr, l_dim, strict_bits ); } ELSE { @@ -453,9 +453,9 @@ static void encode_energies_fx( bits_part[0] = l_bits; move16(); } - IF (GT_16(r_Np, 1)) + IF( GT_16( r_Np, 1 ) ) { - encode_energies_fx(hBstr, hPVQ, &coefs[l_dim], Q_coefs, r_Np, &dim_part[l_Np], &E_part[l_Np], &bits_part[l_Np], &g_part[l_Np], r_bits, bits_left, r_enr, r_dim, strict_bits ); + encode_energies_fx( hBstr, hPVQ, &coefs[l_dim], Q_coefs, r_Np, &dim_part[l_Np], &E_part[l_Np], &bits_part[l_Np], &g_part[l_Np], r_bits, bits_left, r_enr, r_dim, strict_bits ); } ELSE { @@ -470,12 +470,12 @@ static void encode_energies_fx( static void densityIndexSymbolEncode_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ - const Word16 density, /* i : Current density */ - const Word16 r_dim, /* i : Opposite size */ - const Word16 l_dim, /* i : Near size */ - const Word16 index_phi /* i : Index */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ + const Word16 density, /* i : Current density */ + const Word16 r_dim, /* i : Opposite size */ + const Word16 l_dim, /* i : Near size */ + const Word16 index_phi /* i : Index */ ) { Word16 angle, c, densitySubIndex, densitySubC; @@ -486,64 +486,64 @@ static void densityIndexSymbolEncode_fx( Flag Overflow = 0; #endif - sym_freq = L_deposit_l(1); + sym_freq = L_deposit_l( 1 ); - IF( s_and((Word16)0xFFFE, density) != 0 ) /* even */ + IF( s_and( (Word16) 0xFFFE, density ) != 0 ) /* even */ { - angle = atan2_fx(SQRT_DIM_fx[r_dim], SQRT_DIM_fx[l_dim]); + angle = atan2_fx( SQRT_DIM_fx[r_dim], SQRT_DIM_fx[l_dim] ); #ifdef BASOP_NOGLOB - angle = shl_o(angle, 1, &Overflow); + angle = shl_o( angle, 1, &Overflow ); #else - angle = shl(angle, 1); + angle = shl( angle, 1 ); #endif - angle = mult_r(angle, 20861); - c = mult_r(density, angle); + angle = mult_r( angle, 20861 ); + c = mult_r( density, angle ); - densitySubIndex = sub(density, index_phi); - densitySubC = sub(density, c); + densitySubIndex = sub( density, index_phi ); + densitySubC = sub( density, c ); - IF (c == 0) + IF( c == 0 ) { - tot = L_mac0(1L, density, add(density, 1)); - sym_freq = L_deposit_l(add(shl(sub(density, index_phi), 1), 1)); - cum_freq = L_mac0(L_mult(index_phi, density), index_phi, 1); + tot = L_mac0( 1L, density, add( density, 1 ) ); + sym_freq = L_deposit_l( add( shl( sub( density, index_phi ), 1 ), 1 ) ); + cum_freq = L_mac0( L_mult( index_phi, density ), index_phi, 1 ); } - ELSE IF (EQ_16(c, density)) + ELSE IF( EQ_16( c, density ) ) { - tot = L_mac0(1L, density, add(density, 1)); - sym_freq = L_deposit_l(add(shl(index_phi, 1), 1)); - cum_freq = L_mult0(index_phi, index_phi); + tot = L_mac0( 1L, density, add( density, 1 ) ); + sym_freq = L_deposit_l( add( shl( index_phi, 1 ), 1 ) ); + cum_freq = L_mult0( index_phi, index_phi ); } ELSE { - acc = L_mult0(density, c); /* density*c */ - Mpy_32_16_ss(acc, densitySubC, &acc, &lsb); /* density*c*(density - c) */ - acc = L_or(L_shl(acc, 16), L_and(lsb, 0xffffL)); /* Concatenate acc and lsb forming 48-bit; upshift 16 bits; keep 32 MSB. */ - acc = L_shr(acc, 1); /* Compensate fractional mode multiply (Mpy_32_16_ss) */ - tot = L_add(L_add(acc, (Word32)density), 1L); /* density*c*(density - c) + density + 1 */ - IF (LE_16(index_phi, c)) + acc = L_mult0( density, c ); /* density*c */ + Mpy_32_16_ss( acc, densitySubC, &acc, &lsb ); /* density*c*(density - c) */ + acc = L_or( L_shl( acc, 16 ), L_and( lsb, 0xffffL ) ); /* Concatenate acc and lsb forming 48-bit; upshift 16 bits; keep 32 MSB. */ + acc = L_shr( acc, 1 ); /* Compensate fractional mode multiply (Mpy_32_16_ss) */ + tot = L_add( L_add( acc, (Word32) density ), 1L ); /* density*c*(density - c) + density + 1 */ + IF( LE_16( index_phi, c ) ) { - sym_freq = L_mac(1L, index_phi, densitySubC); - acc = L_mult0(densitySubC, sub(index_phi, 1)); - acc = L_add(acc, 1); - Mpy_32_16_ss(acc, index_phi, &acc, &lsb); - acc = L_or(L_shl(acc, 16), L_and(lsb, 0xffffL)); - cum_freq = L_shr(acc, 1); + sym_freq = L_mac( 1L, index_phi, densitySubC ); + acc = L_mult0( densitySubC, sub( index_phi, 1 ) ); + acc = L_add( acc, 1 ); + Mpy_32_16_ss( acc, index_phi, &acc, &lsb ); + acc = L_or( L_shl( acc, 16 ), L_and( lsb, 0xffffL ) ); + cum_freq = L_shr( acc, 1 ); } ELSE { - sym_freq = L_mac(1L, densitySubIndex, c); - acc = L_mult0(densitySubIndex, add(densitySubIndex, 1)); - Mpy_32_16_ss(acc, c, &acc, &lsb); - acc = L_or(L_shl(acc, 16), L_and(lsb, 0xffffL)); - acc = L_shr(acc, 1); - acc = L_sub(acc, (Word32)index_phi); - acc = L_add(add(density, 1), acc); - cum_freq = L_sub(tot, acc); + sym_freq = L_mac( 1L, densitySubIndex, c ); + acc = L_mult0( densitySubIndex, add( densitySubIndex, 1 ) ); + Mpy_32_16_ss( acc, c, &acc, &lsb ); + acc = L_or( L_shl( acc, 16 ), L_and( lsb, 0xffffL ) ); + acc = L_shr( acc, 1 ); + acc = L_sub( acc, (Word32) index_phi ); + acc = L_add( add( density, 1 ), acc ); + cum_freq = L_sub( tot, acc ); } } - rc_encode_fx(hBstr, hPVQ, cum_freq, sym_freq, tot); + rc_encode_fx( hBstr, hPVQ, cum_freq, sym_freq, tot ); } return; @@ -555,107 +555,105 @@ static void densityIndexSymbolEncode_fx( * Calculate the number of segments needed *--------------------------------------------------------------------------*/ -static Word16 calc_pvq_splits_fx( /* o : Number of segments */ - BSTR_ENC_HANDLE hBstr, /* i/o: Encoder state */ - PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ - const Word16 band_bits, /* i : Band bit rate */ - const Word16 sfmsize, /* i : Band width */ - const Word16 *y, /* i : Target vector */ - const Word16 Q_y, /* i : Q point of y */ - Word16 *bits /* o : Consumed bits */ +static Word16 calc_pvq_splits_fx( /* o : Number of segments */ + BSTR_ENC_HANDLE hBstr, /* i/o: Encoder state */ + PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ + const Word16 band_bits, /* i : Band bit rate */ + const Word16 sfmsize, /* i : Band width */ + const Word16 *y, /* i : Target vector */ + const Word16 Q_y, /* i : Q point of y */ + Word16 *bits /* o : Consumed bits */ ) { Word16 Np; Word16 Npart; - Word16 i,j; + Word16 i, j; Word16 E[MAX_SPLITS]; Word16 Emean, eTotal; Word16 tmp, expo; const Word16 *pY; - Word16 max_dev,qPoint; + Word16 max_dev, qPoint; Word32 acc, acc1; - IF (band_bits == 0) + IF( band_bits == 0 ) { Np = 1; move16(); } ELSE { - acc = L_mult0(band_bits, 0x7a44); - Np = extract_l(L_shr(acc, 23)); /* Get integer part. */ - if (L_and(acc, 0x7fffffL) != 0) /* If fractional part != 0, add 1. */ + acc = L_mult0( band_bits, 0x7a44 ); + Np = extract_l( L_shr( acc, 23 ) ); /* Get integer part. */ + if ( L_and( acc, 0x7fffffL ) != 0 ) /* If fractional part != 0, add 1. */ { - Np = add(Np, 1); /* ceiling operation */ + Np = add( Np, 1 ); /* ceiling operation */ } } *bits = 0; move16(); - IF (LT_16(Np, MAX_SPLITS)) + IF( LT_16( Np, MAX_SPLITS ) ) { - acc = L_mult0(8*THR_ADD_SPLIT, sfmsize); - IF (GT_32(band_bits, acc)) + acc = L_mult0( 8 * THR_ADD_SPLIT, sfmsize ); + IF( GT_32( band_bits, acc ) ) { - Npart = extract_l((Word32)intLimCDivPos_fx(UL_deposit_l((UWord16)sfmsize), Np)); - *bits = 8; + Npart = extract_l( (Word32) intLimCDivPos_fx( UL_deposit_l( (UWord16) sfmsize ), Np ) ); + *bits = 8; move16(); eTotal = 0; move16(); - pY = y; - qPoint = shl(Q_y, 1); /* acc in 2*Q_y */ - FOR (i = 0; i < Np; i++) + pY = y; + qPoint = shl( Q_y, 1 ); /* acc in 2*Q_y */ + FOR( i = 0; i < Np; i++ ) { - acc = L_deposit_l(0); - FOR (j = 0; j < Npart; j++) + acc = L_deposit_l( 0 ); + FOR( j = 0; j < Npart; j++ ) { - acc= L_mac0(acc, *pY, *pY); + acc = L_mac0( acc, *pY, *pY ); pY++; } - acc = L_shr(acc, qPoint); + acc = L_shr( acc, qPoint ); - E[i] = sub(30, norm_l(L_max(1L,acc))); /* L_max needed to handle low subvector levels */ - eTotal = add(eTotal, E[i]); + E[i] = sub( 30, norm_l( L_max( 1L, acc ) ) ); /* L_max needed to handle low subvector levels */ + eTotal = add( eTotal, E[i] ); } - Emean = ratio(eTotal, Np, &expo); - Emean = shr(Emean, add(14 - 8, expo)); /* Emean in Q8 */ + Emean = ratio( eTotal, Np, &expo ); + Emean = shr( Emean, add( 14 - 8, expo ) ); /* Emean in Q8 */ max_dev = -1; move16(); - FOR (i = 0; i < Np; i++) + FOR( i = 0; i < Np; i++ ) { - tmp = abs_s(sub(shl(E[i], 8), Emean)); /* in Q8 */ - max_dev = s_max(tmp, max_dev); + tmp = abs_s( sub( shl( E[i], 8 ), Emean ) ); /* in Q8 */ + max_dev = s_max( tmp, max_dev ); } - acc = L_sub(L_shl(Np, 5 + 3 + 8), L_shl(band_bits, 8)); /* NB: max_dev in Q8 */ - acc1 = L_shl(L_mult0(Np, max_dev), 3); + acc = L_sub( L_shl( Np, 5 + 3 + 8 ), L_shl( band_bits, 8 ) ); /* NB: max_dev in Q8 */ + acc1 = L_shl( L_mult0( Np, max_dev ), 3 ); tmp = 0; - move16() ; - if( GT_32(acc1, acc)) + move16(); + if ( GT_32( acc1, acc ) ) { tmp = 1; move16(); } - rc_enc_bits_fx(hBstr, hPVQ, tmp, 1); - Np = add(Np, tmp); + rc_enc_bits_fx( hBstr, hPVQ, tmp, 1 ); + Np = add( Np, tmp ); } } /* Check constraints for number of splits */ /* The following code assumes that PVQ_MAX_BAND_SIZE is 64 */ - i = shr(sfmsize, 6); /* 6 = log2(64) = log2(PVQ_MAX_BAND_SIZE) */ - if (s_and(sfmsize, 0x3f) != 0) + i = shr( sfmsize, 6 ); /* 6 = log2(64) = log2(PVQ_MAX_BAND_SIZE) */ + if ( s_and( sfmsize, 0x3f ) != 0 ) { - i = add(i, 1); /* ceiling operation */ + i = add( i, 1 ); /* ceiling operation */ } - Np = s_max(i, Np); - Np = s_min(MAX_SPLITS, Np); - Np = s_min(sfmsize, Np); /* The code line assumes that MIN_BAND_SIZE is 1 */ + Np = s_max( i, Np ); + Np = s_min( MAX_SPLITS, Np ); + Np = s_min( sfmsize, Np ); /* The code line assumes that MIN_BAND_SIZE is 1 */ return Np; } - - diff --git a/lib_enc/pvq_encode_fx.c b/lib_enc/pvq_encode_fx.c index cef6bdb71..d5bd9ee48 100644 --- a/lib_enc/pvq_encode_fx.c +++ b/lib_enc/pvq_encode_fx.c @@ -2,12 +2,12 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ +#include "options.h" /* Compilation switches */ #include "cnst.h" //#include "prot_fx.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ #include "rom_com_fx.h" #include "rom_com.h" @@ -17,25 +17,25 @@ active if k>=128 and accumulated energy is high enough, comes at a controlled complexity cost, as dimensions decrease for high k's*/ -static Word16 max_val_fx( /* o : maximum value in the input vector */ - const Word16 *vec, /* i : input vector */ - const Word16 lvec /* i : length of input vector */ +static Word16 max_val_fx( /* o : maximum value in the input vector */ + const Word16 *vec, /* i : input vector */ + const Word16 lvec /* i : length of input vector */ ) { - Word16 j,tmp; + Word16 j, tmp; tmp = vec[0]; move16(); - FOR ( j=1 ; j 0 ); + return ( sub( Ptot, extract_l( L_shr( L_mult0( 8223, (Word32) L ), 14 ) ) ) > 0 ); } @@ -45,32 +45,32 @@ static Word16 pyramidSearchProjInit_fx(Word16 L, Word16 Ptot) returns the index of the best positioned unit pulse in imax */ static Word16 one_pulse_search( - const Word16 dim, /* vector dimension */ - const Word16* x_abs, /* absolute vector values */ - Word16* y, /* output vector */ + const Word16 dim, /* vector dimension */ + const Word16 *x_abs, /* absolute vector values */ + Word16 *y, /* output vector */ Word16 *pulse_tot_ptr, - Word32* L_xy_ptr, /* accumulated correlation */ - Word32* L_yy_ptr, /* accumulated energy */ + Word32 *L_xy_ptr, /* accumulated correlation */ + Word32 *L_yy_ptr, /* accumulated energy */ Word16 high_prec_active, Word16 en_dn_shift, - Word16 max_xabs) /* current accumulated max amplitude for pulses */ + Word16 max_xabs ) /* current accumulated max amplitude for pulses */ { - Word16 i, corr_up_shift, corr_tmp, imax, corr_sq_tmp, en_max_den, cmax_num, en_tmp; - Word32 L_tmp_en_lc, L_tmp_corr ; - Word32 L_tmp_en, L_en_max_den, L_corr_sq_max, L_tmp_corr_sq; - Word32 L_left_h, L_right_h; + Word16 i, corr_up_shift, corr_tmp, imax, corr_sq_tmp, en_max_den, cmax_num, en_tmp; + Word32 L_tmp_en_lc, L_tmp_corr; + Word32 L_tmp_en, L_en_max_den, L_corr_sq_max, L_tmp_corr_sq; + Word32 L_left_h, L_right_h; UWord32 UL_left_l, UL_right_l, UL_dummy; - Word32 L_tmp; + Word32 L_tmp; UWord16 u_sgn; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - en_tmp = en_dn_shift; /* dummy assignment to avoid compiler warning for unused parameter */ + en_tmp = en_dn_shift; /* dummy assignment to avoid compiler warning for unused parameter */ /* maximize correlation precision, prior to every unit pulse addition in the vector */ - corr_up_shift = norm_l(L_mac(*L_xy_ptr, 1, max_xabs)); /* pre analyze worst case L_xy update in the dim loop , 2 ops */ - imax = -1; /* not needed for search, only added to avoid compiler warning */ + corr_up_shift = norm_l( L_mac( *L_xy_ptr, 1, max_xabs ) ); /* pre analyze worst case L_xy update in the dim loop , 2 ops */ + imax = -1; /* not needed for search, only added to avoid compiler warning */ /* clean BE code, with split out low/high precision loops */ /* activate low complexity en/corr search section conditionally if resulting vector energy is within limits */ @@ -78,84 +78,83 @@ static Word16 one_pulse_search( IF( high_prec_active == 0 ) { - en_max_den = 0; /*move16()*/; /* OPT: move saved by using high_prec_active as en_max_den */ /* 1 op */ - cmax_num = -1; - move16(); /* req. to force a 1st update for n==0 */ /* 1 op */ + en_max_den = 0; /*move16()*/ + ; /* OPT: move saved by using high_prec_active as en_max_den */ /* 1 op */ + cmax_num = -1; + move16(); /* req. to force a 1st update for n==0 */ /* 1 op */ - FOR(i = 0; i < dim; i++) /* FOR 3 ops */ + FOR( i = 0; i < dim; i++ ) /* FOR 3 ops */ { #ifdef BASOP_NOGLOB - L_tmp_corr = L_shl_o(L_mac_o(*L_xy_ptr,1,x_abs[i], &Overflow), corr_up_shift, &Overflow); /* actual in-loop target value, 2 ops */ - corr_tmp = round_fx_o(L_tmp_corr, &Overflow); /* 1 op */ + L_tmp_corr = L_shl_o( L_mac_o( *L_xy_ptr, 1, x_abs[i], &Overflow ), corr_up_shift, &Overflow ); /* actual in-loop target value, 2 ops */ + corr_tmp = round_fx_o( L_tmp_corr, &Overflow ); /* 1 op */ #else - L_tmp_corr = L_shl(L_mac(*L_xy_ptr,1,x_abs[i]), corr_up_shift ); /* actual in-loop target value, 2 ops */ - corr_tmp = round_fx(L_tmp_corr); /* 1 op */ + L_tmp_corr = L_shl( L_mac( *L_xy_ptr, 1, x_abs[i] ), corr_up_shift ); /* actual in-loop target value, 2 ops */ + corr_tmp = round_fx( L_tmp_corr ); /* 1 op */ #endif - corr_sq_tmp = mult(corr_tmp, corr_tmp); /* CorrSq, is a 16bit for low compelxity cross multiplication 1 op */ + corr_sq_tmp = mult( corr_tmp, corr_tmp ); /* CorrSq, is a 16bit for low compelxity cross multiplication 1 op */ - L_tmp_en_lc = L_mac(*L_yy_ptr, 1,y[i] ); /*Q1 result , energy may span up to ~14+1(Q1)+1(sign)=16 bits, 1 op */ + L_tmp_en_lc = L_mac( *L_yy_ptr, 1, y[i] ); /*Q1 result , energy may span up to ~14+1(Q1)+1(sign)=16 bits, 1 op */ /* extract_l without shift can always be used for this section as energy is guaranteed to stay in the lower word, 1 op */ - en_tmp = extract_l(L_tmp_en_lc); /* L_shl + round_fx could also be used also but then adds an uphift cost (2-3 ops)*/ + en_tmp = extract_l( L_tmp_en_lc ); /* L_shl + round_fx could also be used also but then adds an uphift cost (2-3 ops)*/ /* 16/32 bit comparison WC (4 +1+1 + (1+1+1) = 9 */ - IF( L_msu(L_mult(corr_sq_tmp, en_max_den),cmax_num , en_tmp) > 0) /* use L_mult and then a L_msu, 2 ops */ + IF( L_msu( L_mult( corr_sq_tmp, en_max_den ), cmax_num, en_tmp ) > 0 ) /* use L_mult and then a L_msu, 2 ops */ { - cmax_num = corr_sq_tmp; - move16(); /* 1 op */ - en_max_den = en_tmp; - move16(); /* 1 op */ - imax = i; - move16(); /* 1 op */ + cmax_num = corr_sq_tmp; + move16(); /* 1 op */ + en_max_den = en_tmp; + move16(); /* 1 op */ + imax = i; + move16(); /* 1 op */ } } /* dim */ - } ELSE { /* High resolution section activated when vector energy is becoming high (peaky or many pulses) */ /* BASOP operator Mpy32_32_ss used to allow higher resolution for both the CorrSq term and the Energy term */ - L_en_max_den = L_deposit_l(0); /* 1 op */ - L_corr_sq_max = L_deposit_l(-1); /* req. to force a 1st update */ /* 1 op */ + L_en_max_den = L_deposit_l( 0 ); /* 1 op */ + L_corr_sq_max = L_deposit_l( -1 ); /* req. to force a 1st update */ /* 1 op */ - FOR(i = 0; i < dim; i++) /* FOR 3 ops */ + FOR( i = 0; i < dim; i++ ) /* FOR 3 ops */ { - L_tmp_corr = L_shl(L_mac(*L_xy_ptr,1,x_abs[i]), corr_up_shift ); /* actual in loop WC value 2 ops */ - Mpy_32_32_ss(L_tmp_corr,L_tmp_corr, &L_tmp_corr_sq, &UL_dummy); /* CorrSq 32 bits, 4 ops */ + L_tmp_corr = L_shl( L_mac( *L_xy_ptr, 1, x_abs[i] ), corr_up_shift ); /* actual in loop WC value 2 ops */ + Mpy_32_32_ss( L_tmp_corr, L_tmp_corr, &L_tmp_corr_sq, &UL_dummy ); /* CorrSq 32 bits, 4 ops */ - L_tmp_en = L_mac(*L_yy_ptr, 1, y[i]); /* Q1,energy may span up to sign+19 bits , 1 op */ + L_tmp_en = L_mac( *L_yy_ptr, 1, y[i] ); /* Q1,energy may span up to sign+19 bits , 1 op */ /* For highest accuracy use pairs of maximum upshifted 32x32 bit signed values */ /* (L_tmp_corr_sq / L_tmp_en) > (L_corr_sq_max/L_en_max_den) */ /* (L_tmp_corr_sq * L_en_max_den) > (L_corr_sq_max * L_tmp_en) */ - Mpy_32_32_ss( L_en_max_den, L_tmp_corr_sq, &L_left_h, &UL_left_l); /* 4 ops */ - Mpy_32_32_ss( L_tmp_en, L_corr_sq_max, &L_right_h, &UL_right_l); /* 4 ops */ + Mpy_32_32_ss( L_en_max_den, L_tmp_corr_sq, &L_left_h, &UL_left_l ); /* 4 ops */ + Mpy_32_32_ss( L_tmp_en, L_corr_sq_max, &L_right_h, &UL_right_l ); /* 4 ops */ /* STL optimized "Lazy evaluation" of: IF( (L_left_h > L_right_h) || ( (L_left_h == L_right_h) && (UL_left_l > UL_right_l) ) */ /* 32/64 bit Lazy eval comparison WC cost is (1+ 1+1+1 + 4 +(2+2+1) = 13 , and average is ~12 */ /* Unoptimized 32/64 bit comparison WC cost is (1+1+ 2x2 + 4 +(2+2+1) = 15 */ - L_tmp = L_sub(L_left_h, L_right_h); /* high signed word check 1 op */ + L_tmp = L_sub( L_left_h, L_right_h ); /* high signed word check 1 op */ u_sgn = 0; - move16(); /* 1 op */ - if(L_tmp == 0) /* L_tmp high Word testing is always needed */ + move16(); /* 1 op */ + if ( L_tmp == 0 ) /* L_tmp high Word testing is always needed */ { /* The returned UL value from UL_subNs is not needed, only u_sgn is needed */ - UL_subNs(UL_right_l, UL_left_l, &u_sgn); /* low unsigned word check, note left/right order switch of ">" due to ">=" inside UL_subNs, 1 op */ + UL_subNs( UL_right_l, UL_left_l, &u_sgn ); /* low unsigned word check, note left/right order switch of ">" due to ">=" inside UL_subNs, 1 op */ } - if( u_sgn != 0) + if ( u_sgn != 0 ) { - L_tmp = L_add(L_tmp, 1); /* 0+1 --> 1 use wrap/sign result of low Word u_sgn check */ /* 1 op */ + L_tmp = L_add( L_tmp, 1 ); /* 0+1 --> 1 use wrap/sign result of low Word u_sgn check */ /* 1 op */ } - IF( L_tmp > 0 ) /* IF 4 ops */ + IF( L_tmp > 0 ) /* IF 4 ops */ { - L_corr_sq_max = L_add(L_tmp_corr_sq, 0); /* 1-2 ops */ - L_en_max_den = L_add(L_tmp_en, 0); /* 1-2 ops */ - imax = i; + L_corr_sq_max = L_add( L_tmp_corr_sq, 0 ); /* 1-2 ops */ + L_en_max_den = L_add( L_tmp_en, 0 ); /* 1-2 ops */ + imax = i; move16(); /* 1 op */ } - } /* dim loop */ - + } /* dim loop */ } /* Complexity comparison per coeff for low precision vs. high precision low precision: pulse_tot <= 127, 16 bit: WC 2+3 +(15)*dim ops, dim=5 --> 5+15*5 = 90 ops, 18 ops/coeff @@ -163,12 +162,12 @@ static Word16 one_pulse_search( */ /* finally add found unit pulse contribution to past L_xy, Lyy, for next pulse loop */ - *L_xy_ptr = L_mac(*L_xy_ptr, x_abs[imax], 1); /* Q12+1 */ - *L_yy_ptr = L_mac(*L_yy_ptr, 1, y[imax]); + *L_xy_ptr = L_mac( *L_xy_ptr, x_abs[imax], 1 ); /* Q12+1 */ + *L_yy_ptr = L_mac( *L_yy_ptr, 1, y[imax] ); - y[imax] = add(y[imax],1); - move16(); /* Q0 added pulse */ - (*pulse_tot_ptr) = add((*pulse_tot_ptr) ,1); /* increment total pulse sum */ + y[imax] = add( y[imax], 1 ); + move16(); /* Q0 added pulse */ + ( *pulse_tot_ptr ) = add( ( *pulse_tot_ptr ), 1 ); /* increment total pulse sum */ return imax; } @@ -178,212 +177,212 @@ static Word16 one_pulse_search( *-----------------------------------------------------------------------*/ void pvq_encode_fx( BSTR_ENC_HANDLE hBstr, - PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ - const Word16 *x, /* i: vector to quantize Q15-3=>Q12 */ - Word16 *y, /* o: raw pulses (non-scaled short) Q0 */ - Word16 *xq, /* o: quantized vector Q15 */ - Word32 *L_xq, /* o: quantized vector Q31 fot eval */ - const Word16 pulses, /* i: number of allocated pulses */ - const Word16 dim, /* i: Length of vector */ - const Word16 neg_gain /* i: - Gain use - negative gain in Q15 0..1 */ + PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ + const Word16 *x, /* i: vector to quantize Q15-3=>Q12 */ + Word16 *y, /* o: raw pulses (non-scaled short) Q0 */ + Word16 *xq, /* o: quantized vector Q15 */ + Word32 *L_xq, /* o: quantized vector Q31 fot eval */ + const Word16 pulses, /* i: number of allocated pulses */ + const Word16 dim, /* i: Length of vector */ + const Word16 neg_gain /* i: - Gain use - negative gain in Q15 0..1 */ ) { - Word16 i; + Word16 i; Word16 pulse_tot; Word16 xabs[PVQ_MAX_BAND_SIZE]; Word16 max_xabs; Word32 L_xsum; Word32 L_proj_fac; Word32 L_yy, L_xy; - Word16 max_amp_y, imax; - Word16 k, en_margin, en_dn_shift, high_prec_active ; + Word16 max_amp_y, imax; + Word16 k, en_margin, en_dn_shift, high_prec_active; Word32 L_num, L_tmp; - Word16 proj_fac, tmp, shift_den,shift_num,shift_delta, num,den; + Word16 proj_fac, tmp, shift_den, shift_num, shift_delta, num, den; UWord16 u16_tmp; Word16 dim_m1; Word32 L_isqrt; Word16 neg_gain_norm, shift_tot; - Word16 high_pulse_density_flag; + Word16 high_pulse_density_flag; PvqEntry entry; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif L_proj_fac = 4096; - L_xsum = L_deposit_h(0); - max_xabs = -1; + L_xsum = L_deposit_h( 0 ); + max_xabs = -1; move16(); - FOR( i = 0; i < dim; i++) + FOR( i = 0; i < dim; i++ ) { - xabs[i] = abs_s(x[i]); - move16(); /* Q12 */ - max_xabs = s_max(max_xabs, xabs[i] ); /* for efficient search correlation scaling */ - L_xsum = L_mac0(L_xsum, 1, xabs[i] ); /* stay in Q12 */ - y[i] = 0; - move16(); /* init, later only non-zero values need to be normalized */ + xabs[i] = abs_s( x[i] ); + move16(); /* Q12 */ + max_xabs = s_max( max_xabs, xabs[i] ); /* for efficient search correlation scaling */ + L_xsum = L_mac0( L_xsum, 1, xabs[i] ); /* stay in Q12 */ + y[i] = 0; + move16(); /* init, later only non-zero values need to be normalized */ } test(); - IF( L_xsum == 0 || neg_gain == 0 ) + IF( L_xsum == 0 || neg_gain == 0 ) { pulse_tot = pulses; move16(); - dim_m1 = sub(dim,1); + dim_m1 = sub( dim, 1 ); y[dim_m1] = 0; move16(); - y[0] = shr(pulses,1); + y[0] = shr( pulses, 1 ); move16(); - y[dim_m1] = add(y[dim_m1], sub(pulses, y[0])); + y[dim_m1] = add( y[dim_m1], sub( pulses, y[0] ) ); move16(); - L_yy = L_mult(y[0],y[0]); /* L_yy needed for normalization */ - if(dim_m1 != 0) + L_yy = L_mult( y[0], y[0] ); /* L_yy needed for normalization */ + if ( dim_m1 != 0 ) { - L_yy = L_mac(L_yy, y[dim_m1],y[dim_m1]); /* (single basop) */ + L_yy = L_mac( L_yy, y[dim_m1], y[dim_m1] ); /* (single basop) */ } } ELSE { - num = sub(pulses, PYR_OFFSET); - high_pulse_density_flag = pyramidSearchProjInit_fx(dim, pulses ); + num = sub( pulses, PYR_OFFSET ); + high_pulse_density_flag = pyramidSearchProjInit_fx( dim, pulses ); test(); - IF( (num > 0) && (high_pulse_density_flag != 0) ) + IF( ( num > 0 ) && ( high_pulse_density_flag != 0 ) ) { - shift_den = norm_l(L_xsum); /* x_sum input Q12 */ - den = extract_h(L_shl(L_xsum, shift_den)); /* now in Q12+shift_den */ + shift_den = norm_l( L_xsum ); /* x_sum input Q12 */ + den = extract_h( L_shl( L_xsum, shift_den ) ); /* now in Q12+shift_den */ - L_num = L_deposit_l(num); - shift_num = sub(norm_l(L_num) ,1); - L_num = L_shl(L_num, shift_num) ; /* now in Q0 +shift_num -1 */ - proj_fac = div_l(L_num, den ); /* L_num always has to be less than den<<16 */ + L_num = L_deposit_l( num ); + shift_num = sub( norm_l( L_num ), 1 ); + L_num = L_shl( L_num, shift_num ); /* now in Q0 +shift_num -1 */ + proj_fac = div_l( L_num, den ); /* L_num always has to be less than den<<16 */ - shift_delta=sub(shift_num,shift_den); + shift_delta = sub( shift_num, shift_den ); #ifdef BASOP_NOGLOB L_proj_fac = L_shl_sat( L_deposit_l( proj_fac ), sub( 9, shift_delta ) ); /* bring to a fixed Q12 */ #else - L_proj_fac = L_shl(L_deposit_l(proj_fac), sub(9, shift_delta)); /* bring to a fixed Q12 */ + L_proj_fac = L_shl( L_deposit_l( proj_fac ), sub( 9, shift_delta ) ); /* bring to a fixed Q12 */ #endif } pulse_tot = 0; move16(); - L_yy = L_deposit_l(0); - L_xy = L_deposit_l(0); + L_yy = L_deposit_l( 0 ); + L_xy = L_deposit_l( 0 ); test(); - IF( (num > 0 ) && (high_pulse_density_flag != 0 ) ) + IF( ( num > 0 ) && ( high_pulse_density_flag != 0 ) ) { - FOR( i = 0; i < dim ; i++) /* max 64 */ + FOR( i = 0; i < dim; i++ ) /* max 64 */ { - Mpy_32_16_ss(L_proj_fac,xabs[i],&L_tmp,&u16_tmp); /*Q12 *Q12 +1 */ - y[i] = extract_l(L_shr( L_tmp, 12+12-16+1 )); - move16();/* Q12 *Q12 -> Q0 */ + Mpy_32_16_ss( L_proj_fac, xabs[i], &L_tmp, &u16_tmp ); /*Q12 *Q12 +1 */ + y[i] = extract_l( L_shr( L_tmp, 12 + 12 - 16 + 1 ) ); + move16(); /* Q12 *Q12 -> Q0 */ - pulse_tot = add(pulse_tot, y[i]); /* Q0 */ - L_yy = L_mac(L_yy, y[i], y[i]); /* Energy, result will scale up by 2 by L_mac */ - L_xy = L_mac(L_xy, xabs[i], y[i]); /* Corr, Q0*Q12 +1 --> Q13 */ + pulse_tot = add( pulse_tot, y[i] ); /* Q0 */ + L_yy = L_mac( L_yy, y[i], y[i] ); /* Energy, result will scale up by 2 by L_mac */ + L_xy = L_mac( L_xy, xabs[i], y[i] ); /* Corr, Q0*Q12 +1 --> Q13 */ } } - L_yy=L_shr(L_yy,1); - IF (LE_16(pulses,127)) + L_yy = L_shr( L_yy, 1 ); + IF( LE_16( pulses, 127 ) ) { /* LC inner loop, enters here always for dimensions 6 and higher, and also sometimes for dimensions 1 .. 5 */ /* ( if high energy precision is inactive, max_amp_y is not needed , no max_amp_y(k-1) update ) */ - FOR (k=pulse_tot; k #include #include "options.h" -#include "cnst.h" /* Common constants */ +#include "cnst.h" /* Common constants */ //#include "prot_fx.h" #include "basop_util.h" #include "rom_com_fx.h" #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ -#include "basop_util.h" /* Function prototypes */ - -static Word16 gain_enc( /* o : quantization pitch index */ - const Word16 *code, /* i : algebraic excitation */ - Word16 lcode, /* i : Subframe size in range: 40,64,80 */ - Word16 *gain_pit, /* o : quantized pitch gain */ - /* i/o : only func=1,coder_type=1 quantized pitch gain */ - Word32 *gain_code, /* o : quantized codebook gain */ - ACELP_CbkCorr *g_coeff, /* i : correlations , -2,, -2 and 2 */ - Word16 mean_ener, /* i : only func=0: mean_ener defined in open-loop (3 bits) */ - const Word16 clip_gain, /* i : only func=0,1: gain pitch clipping flag (1 = clipping) */ - Word32 *past_gcode, /* o : past gain of code */ - Word16 *gain_inov, /* o : Q12 innovation gain */ - const Word16 coder_type, /* i : only func=0,1: coder type */ - const Word16 func_type /* i : algorithm: 0=gain_enc_mless, 1=gain_enc_2 */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ +#include "basop_util.h" /* Function prototypes */ + +static Word16 gain_enc( /* o : quantization pitch index */ + const Word16 *code, /* i : algebraic excitation */ + Word16 lcode, /* i : Subframe size in range: 40,64,80 */ + Word16 *gain_pit, /* o : quantized pitch gain */ + /* i/o : only func=1,coder_type=1 quantized pitch gain */ + Word32 *gain_code, /* o : quantized codebook gain */ + ACELP_CbkCorr *g_coeff, /* i : correlations , -2,, -2 and 2 */ + Word16 mean_ener, /* i : only func=0: mean_ener defined in open-loop (3 bits) */ + const Word16 clip_gain, /* i : only func=0,1: gain pitch clipping flag (1 = clipping) */ + Word32 *past_gcode, /* o : past gain of code */ + Word16 *gain_inov, /* o : Q12 innovation gain */ + const Word16 coder_type, /* i : only func=0,1: coder type */ + const Word16 func_type /* i : algorithm: 0=gain_enc_mless, 1=gain_enc_2 */ ); /*-------------------------------------------------------------------------* @@ -51,7 +51,7 @@ void encode_acelp_gains_fx( Word16 **pt_indice, Word32 *past_gcode, Word16 *gain_inov, - Word16 L_subfr, + Word16 L_subfr, Word16 *code2, Word32 *gain_code2, Word8 noisy_speech_flag /* i : noisy speech flag */ @@ -61,52 +61,52 @@ void encode_acelp_gains_fx( BASOP_SATURATE_ERROR_ON_EVS; - SWITCH(gains_mode) + SWITCH( gains_mode ) { - case 1: - case 2: - case 3: - /* Memory-less gain coding */ - gains_mode = sub(gains_mode, 1); - func_type = FUNC_GAIN_ENC_MLESS; - move16(); - BREAK; - case 4: - case 5: - assert(0); - BREAK; - case 6: - /* UV gains quantizer (6 bits/subfr) */ - gains_mode = sub(gains_mode, 6); - func_type = FUNC_GAIN_ENC_UV; - move16(); - BREAK; - case 7: - gains_mode = sub(gains_mode, 7); - func_type = FUNC_GAIN_ENC_GACELP_UV; - move16(); - BREAK; - default: - IVAS_ERROR(IVAS_ERR_INTERNAL, "invalid gains coding for acelp!"); - func_type = 0; - move16(); /*To avoid compiler warning*/ - BREAK; + case 1: + case 2: + case 3: + /* Memory-less gain coding */ + gains_mode = sub( gains_mode, 1 ); + func_type = FUNC_GAIN_ENC_MLESS; + move16(); + BREAK; + case 4: + case 5: + assert( 0 ); + BREAK; + case 6: + /* UV gains quantizer (6 bits/subfr) */ + gains_mode = sub( gains_mode, 6 ); + func_type = FUNC_GAIN_ENC_UV; + move16(); + BREAK; + case 7: + gains_mode = sub( gains_mode, 7 ); + func_type = FUNC_GAIN_ENC_GACELP_UV; + move16(); + BREAK; + default: + IVAS_ERROR( IVAS_ERR_INTERNAL, "invalid gains coding for acelp!" ); + func_type = 0; + move16(); /*To avoid compiler warning*/ + BREAK; } IF( func_type == FUNC_GAIN_ENC_MLESS ) { - index = gain_enc(code, L_subfr, gain_pit, gain_code, g_corr, mean_ener_code, - clip_gain, past_gcode, gain_inov, gains_mode, func_type); + index = gain_enc( code, L_subfr, gain_pit, gain_code, g_corr, mean_ener_code, + clip_gain, past_gcode, gain_inov, gains_mode, func_type ); } ELSE { - index = gain_enc_uv_fx(code, code2, L_subfr, gain_pit, gain_code, gain_code2, - noisy_speech_flag, g_corr, mean_ener_code, past_gcode, gain_inov, func_type); + index = gain_enc_uv_fx( code, code2, L_subfr, gain_pit, gain_code, gain_code2, + noisy_speech_flag, g_corr, mean_ener_code, past_gcode, gain_inov, func_type ); } move16(); **pt_indice = index; - (*pt_indice)++; + ( *pt_indice )++; BASOP_SATURATE_ERROR_OFF_EVS; } @@ -121,19 +121,19 @@ void encode_acelp_gains_fx( * - the mean-squared weighted error criterion is used for the quantizer search *---------------------------------------------------------------------*/ -static Word16 gain_enc( /* o : quantization pitch index */ - const Word16 *code, /* i : algebraic excitation */ - Word16 lcode, /* i : Subframe size in range: 40,64,80 */ - Word16 *gain_pit, /* o : quantized pitch gain */ - /* i/o : only func=1,coder_type=1 quantized pitch gain */ - Word32 *gain_code, /* o : quantized codebook gain */ - ACELP_CbkCorr *g_coeff, /* i : correlations , -2,, -2 and 2 */ - Word16 mean_ener, /* i : only func=0: mean_ener defined in open-loop (3 bits) */ - const Word16 clip_gain, /* i : only func=0,1: gain pitch clipping flag (1 = clipping) */ - Word32 *past_gcode, /* o : past gain of code */ - Word16 *gain_inov, /* o : Q12 innovation gain */ - const Word16 coder_type, /* i : only func=0,1: coder type */ - const Word16 func_type /* i : algorithm: 0=gain_enc_mless, 1=gain_enc_2 */ +static Word16 gain_enc( /* o : quantization pitch index */ + const Word16 *code, /* i : algebraic excitation */ + Word16 lcode, /* i : Subframe size in range: 40,64,80 */ + Word16 *gain_pit, /* o : quantized pitch gain */ + /* i/o : only func=1,coder_type=1 quantized pitch gain */ + Word32 *gain_code, /* o : quantized codebook gain */ + ACELP_CbkCorr *g_coeff, /* i : correlations , -2,, -2 and 2 */ + Word16 mean_ener, /* i : only func=0: mean_ener defined in open-loop (3 bits) */ + const Word16 clip_gain, /* i : only func=0,1: gain pitch clipping flag (1 = clipping) */ + Word32 *past_gcode, /* o : past gain of code */ + Word16 *gain_inov, /* o : Q12 innovation gain */ + const Word16 coder_type, /* i : only func=0,1: coder type */ + const Word16 func_type /* i : algorithm: 0=gain_enc_mless, 1=gain_enc_2 */ ) { Word16 i, j, index, size, min_index, exp_L_tmp1; @@ -150,8 +150,7 @@ static Word16 gain_enc( /* o : quantization pitch index #endif - - assert((func_type != FUNC_GAIN_ENC_UV) && (func_type != FUNC_GAIN_ENC_GACELP_UV)); + assert( ( func_type != FUNC_GAIN_ENC_UV ) && ( func_type != FUNC_GAIN_ENC_GACELP_UV ) ); /* Debug test value (not instrumented) */ gcode0 = -3000; @@ -163,24 +162,23 @@ static Word16 gain_enc( /* o : quantization pitch index *----------------------------------------------------------------*/ /* gain_inov = 1.0f / sqrt((dot_product(code, code, L_SUBFR) + 0.01) / L_SUBFR) */ - L_tmp = calc_gain_inov(code, lcode, &L_tmp1, &exp_L_tmp1); + L_tmp = calc_gain_inov( code, lcode, &L_tmp1, &exp_L_tmp1 ); move16(); #ifdef BASOP_NOGLOB - *gain_inov = round_fx_o(L_shl_o(L_tmp, 15-3, &Overflow), &Overflow); /* gain_inov in Q12 */ + *gain_inov = round_fx_o( L_shl_o( L_tmp, 15 - 3, &Overflow ), &Overflow ); /* gain_inov in Q12 */ #else - *gain_inov = round_fx(L_shl(L_tmp, 15-3)); /* gain_inov in Q12 */ + *gain_inov = round_fx( L_shl( L_tmp, 15 - 3 ) ); /* gain_inov in Q12 */ #endif /*----------------------------------------------------------------* * calculate the predicted gain code *----------------------------------------------------------------*/ - IF (func_type == FUNC_GAIN_ENC_MLESS) + IF( func_type == FUNC_GAIN_ENC_MLESS ) { /*j = 10 * log10((dot_product(code, code, lcode) + 0.01) / lcode) */ - j = BASOP_Util_lin2dB(L_tmp1, exp_L_tmp1, 1); /* Q8 */ + j = BASOP_Util_lin2dB( L_tmp1, exp_L_tmp1, 1 ); /* Q8 */ /* predicted codebook gain */ - gcode0 = sub(mean_ener, j); /* Q8 */ - + gcode0 = sub( mean_ener, j ); /* Q8 */ } /*----------------------------------------------------------------* @@ -207,13 +205,13 @@ static Word16 gain_enc( /* o : quantization pitch index coeff1 = g_coeff->xy1; move16(); - exp_coeff1 = add(g_coeff->xy1_e, 1); + exp_coeff1 = add( g_coeff->xy1_e, 1 ); coeff3 = g_coeff->xy2; move16(); - exp_coeff3 = add(g_coeff->xy2_e, 1); + exp_coeff3 = add( g_coeff->xy2_e, 1 ); coeff4 = g_coeff->y1y2; move16(); - exp_coeff4 = add(g_coeff->y1y2_e, 1); + exp_coeff4 = add( g_coeff->y1y2_e, 1 ); /*---------------------------------------------------------------* * Decode codebook gain and the adaptive excitation low-pass @@ -229,15 +227,15 @@ static Word16 gain_enc( /* o : quantization pitch index *----------------------------------------------------------------*/ /* Check if gcode0 was uninitialized. */ - assert(gcode0 != -3000); + assert( gcode0 != -3000 ); - L_tmp = L_mult(gcode0, 5443/*0.166096f Q15*/); - exp_gcode0 = add(1,extract_l(L_shr(L_tmp, 24))); - L_tmp = L_lshl(L_tmp, 7); - L_tmp = L_and(0x7FFFFFFF, L_tmp); + L_tmp = L_mult( gcode0, 5443 /*0.166096f Q15*/ ); + exp_gcode0 = add( 1, extract_l( L_shr( L_tmp, 24 ) ) ); + L_tmp = L_lshl( L_tmp, 7 ); + L_tmp = L_and( 0x7FFFFFFF, L_tmp ); - L_tmp = Pow2(30,round_fx(L_tmp)); - gcode0 = round_fx(L_tmp); + L_tmp = Pow2( 30, round_fx( L_tmp ) ); + gcode0 = round_fx( L_tmp ); /* exponent of gcode0 = exp_gcode0 */ /*-----------------------------------------------------------------* @@ -275,30 +273,30 @@ static Word16 gain_enc( /* o : quantization pitch index * g_pitch*g_code * coeff[4] ;exp_max4 = exp_coeff[4] + 1 + exp_code *----------------------------------------------------------------*/ - exp_code = add(exp_gcode0, 4); + exp_code = add( exp_gcode0, 4 ); - exp_coeff0 = add(exp_coeff0, 2); - exp_coeff1 = add(exp_coeff1, 1); - exp_coeff2 = add(exp_coeff2, shl(exp_code, 1)); - exp_coeff3 = add(exp_coeff3, exp_code); - exp_coeff4 = add(exp_coeff4, add(1, exp_code)); + exp_coeff0 = add( exp_coeff0, 2 ); + exp_coeff1 = add( exp_coeff1, 1 ); + exp_coeff2 = add( exp_coeff2, shl( exp_code, 1 ) ); + exp_coeff3 = add( exp_coeff3, exp_code ); + exp_coeff4 = add( exp_coeff4, add( 1, exp_code ) ); /* Find maximum exponent */ - exp_sum = s_max(exp_coeff1, exp_coeff0); - exp_sum = s_max(exp_coeff2, exp_sum); - exp_sum = s_max(exp_coeff3, exp_sum); - exp_sum = s_max(exp_coeff4, exp_sum); - exp_sum = add(exp_sum,2); + exp_sum = s_max( exp_coeff1, exp_coeff0 ); + exp_sum = s_max( exp_coeff2, exp_sum ); + exp_sum = s_max( exp_coeff3, exp_sum ); + exp_sum = s_max( exp_coeff4, exp_sum ); + exp_sum = add( exp_sum, 2 ); /* Align exponents of summands in loop far below. */ - shr_coeff0 = sub(exp_sum, exp_coeff0); - shr_coeff1 = sub(exp_sum, exp_coeff1); - shr_coeff2 = sub(exp_sum, exp_coeff2); - shr_coeff3 = sub(exp_sum, exp_coeff3); - shr_coeff4 = sub(exp_sum, exp_coeff4); + shr_coeff0 = sub( exp_sum, exp_coeff0 ); + shr_coeff1 = sub( exp_sum, exp_coeff1 ); + shr_coeff2 = sub( exp_sum, exp_coeff2 ); + shr_coeff3 = sub( exp_sum, exp_coeff3 ); + shr_coeff4 = sub( exp_sum, exp_coeff4 ); /* Codebook search */ - dist_min = L_deposit_h(MAX_16); + dist_min = L_deposit_h( MAX_16 ); min_index = 0; move16(); @@ -307,35 +305,34 @@ static Word16 gain_enc( /* o : quantization pitch index Word16 size_clip; - IF( coder_type == 0) + IF( coder_type == 0 ) { t_qua_gain = E_ROM_qua_gain5b_const; - size_clip=9; - size=NB_QUA_GAIN5B; + size_clip = 9; + size = NB_QUA_GAIN5B; } - ELSE IF(coder_type == 1) + ELSE IF( coder_type == 1 ) { t_qua_gain = E_ROM_qua_gain6b_const; - size_clip=6; - size = NB_QUA_GAIN6B; /* searching range of the gain quantizer */ + size_clip = 6; + size = NB_QUA_GAIN6B; /* searching range of the gain quantizer */ } ELSE { t_qua_gain = E_ROM_qua_gain7b_const; - size_clip=21; + size_clip = 21; size = NB_QUA_GAIN7B; } - if ( EQ_16(clip_gain,1)) + if ( EQ_16( clip_gain, 1 ) ) { - size = sub(size, size_clip); /* limit pitch gain to 1.0 */ + size = sub( size, size_clip ); /* limit pitch gain to 1.0 */ } gcode0_gi = gcode0; move16(); - } move16(); p = t_qua_gain; @@ -345,14 +342,14 @@ static Word16 gain_enc( /* o : quantization pitch index /* divide all coeff1,2,3,4 by coeff0 */ /* in order to skip multiplication with coeff0 in loop */ - assert(coeff0 >= 0x4000); - coeff0 = div_s(0x4000,coeff0); - coeff1 = mult_r(coeff1,coeff0); - coeff2 = mult_r(coeff2,coeff0); - coeff3 = mult_r(coeff3,coeff0); - coeff4 = mult_r(coeff4,coeff0); - - FOR (i = 0; i < size; i++) + assert( coeff0 >= 0x4000 ); + coeff0 = div_s( 0x4000, coeff0 ); + coeff1 = mult_r( coeff1, coeff0 ); + coeff2 = mult_r( coeff2, coeff0 ); + coeff3 = mult_r( coeff3, coeff0 ); + coeff4 = mult_r( coeff4, coeff0 ); + + FOR( i = 0; i < size; i++ ) { /* Note: gcode0_gi: either gcode0 or gcode0*gain_inov @@ -367,76 +364,76 @@ static Word16 gain_enc( /* o : quantization pitch index */ /* Since g_code has a significant dynamic, we prefer to normalize this 16-bit value */ - g_code_shl = norm_s(p[2*i+1]); - g_code = shl(p[2*i+1],g_code_shl); - g_code = mult_r(g_code, gcode0_gi); - BASOP_SATURATE_WARNING_OFF_EVS /* needed to skip overflow warnings due to exceeding shift values */ - L_tmp = L_shr(Mpy_32_16_1(L_mult(g_code, g_code),coeff2),shr_coeff2); - if (g_code_shl != 0) - L_tmp = L_shr(L_tmp,g_code_shl); - L_tmp = L_sub(L_tmp,L_shr(L_mult(g_code, coeff3),shr_coeff3)); - L_tmp = L_add(L_tmp,L_shr(Mpy_32_16_1(L_mult(g_code, p[2*i+0]), coeff4),shr_coeff4)); - if (g_code_shl != 0) - L_tmp = L_shr(L_tmp,g_code_shl); + g_code_shl = norm_s( p[2 * i + 1] ); + g_code = shl( p[2 * i + 1], g_code_shl ); + g_code = mult_r( g_code, gcode0_gi ); + BASOP_SATURATE_WARNING_OFF_EVS /* needed to skip overflow warnings due to exceeding shift values */ + L_tmp = L_shr( Mpy_32_16_1( L_mult( g_code, g_code ), coeff2 ), shr_coeff2 ); + if ( g_code_shl != 0 ) + L_tmp = L_shr( L_tmp, g_code_shl ); + L_tmp = L_sub( L_tmp, L_shr( L_mult( g_code, coeff3 ), shr_coeff3 ) ); + L_tmp = L_add( L_tmp, L_shr( Mpy_32_16_1( L_mult( g_code, p[2 * i + 0] ), coeff4 ), shr_coeff4 ) ); + if ( g_code_shl != 0 ) + L_tmp = L_shr( L_tmp, g_code_shl ); /* Here, we use L_mult0 to compensate the factor 0.5 applied to coeff[1..4] before */ - L_tmp = L_add(L_tmp,L_shr(L_mult0(p[2*i+0],p[2*i+0]), shr_coeff0)); - L_tmp = L_sub(L_tmp,L_shr(L_mult(p[2*i+0], coeff1),shr_coeff1)); + L_tmp = L_add( L_tmp, L_shr( L_mult0( p[2 * i + 0], p[2 * i + 0] ), shr_coeff0 ) ); + L_tmp = L_sub( L_tmp, L_shr( L_mult( p[2 * i + 0], coeff1 ), shr_coeff1 ) ); #ifdef BASOP_NOGLOB - L_tmp1= L_sub_o(L_tmp, dist_min, &Overflow); + L_tmp1 = L_sub_o( L_tmp, dist_min, &Overflow ); #else /* BASOP_NOGLOB */ - L_tmp1= L_sub(L_tmp, dist_min); + L_tmp1 = L_sub( L_tmp, dist_min ); #endif BASOP_SATURATE_WARNING_ON_EVS - if (L_tmp1 < 0) + if ( L_tmp1 < 0 ) { index = i; move16(); } - if (L_tmp1 < 0) + if ( L_tmp1 < 0 ) { - dist_min = L_min(L_tmp, dist_min); + dist_min = L_min( L_tmp, dist_min ); } } - index = add(index, min_index); - *gain_pit = t_qua_gain[2*index+0]; + index = add( index, min_index ); + *gain_pit = t_qua_gain[2 * index + 0]; move16(); - g_code = t_qua_gain[2*index+1]; + g_code = t_qua_gain[2 * index + 1]; move16(); - L_tmp = L_mult(g_code, gcode0); /* Q11*Q15 -> Q27 */ - exp_gcode0 = add(exp_gcode0,-11); + L_tmp = L_mult( g_code, gcode0 ); /* Q11*Q15 -> Q27 */ + exp_gcode0 = add( exp_gcode0, -11 ); #ifdef BASOP_NOGLOB - L_tmp = L_shl_o(L_tmp, exp_gcode0, &Overflow); /* Q27 -> Q16 */ + L_tmp = L_shl_o( L_tmp, exp_gcode0, &Overflow ); /* Q27 -> Q16 */ #else - L_tmp = L_shl(L_tmp, exp_gcode0); /* Q27 -> Q16 */ + L_tmp = L_shl( L_tmp, exp_gcode0 ); /* Q27 -> Q16 */ #endif *gain_code = L_tmp; move32(); /* Q16/Q12 => Q5 */ - L_tmp = L_deposit_h(BASOP_Util_Divide3216_Scale(L_tmp,*gain_inov,&i)); + L_tmp = L_deposit_h( BASOP_Util_Divide3216_Scale( L_tmp, *gain_inov, &i ) ); #ifdef BASOP_NOGLOB - *past_gcode = L_shl_o(L_tmp,sub(i,15-12), &Overflow); + *past_gcode = L_shl_o( L_tmp, sub( i, 15 - 12 ), &Overflow ); #else - *past_gcode = L_shl(L_tmp,sub(i,15-12)); + *past_gcode = L_shl( L_tmp, sub( i, 15 - 12 ) ); #endif return index; } -Word16 gain_enc_uv_fx( /* o : quantization pitch index */ - const Word16 *code, /* i : algebraic excitation */ - const Word16 *code2, /* i : gaussian excitation */ - Word16 lcode, /* i : Subframe size in range: 40,64,80 */ - Word16 *gain_pit, /* o : quantized pitch gain */ - Word32 *gain_code, /* o : quantized codebook gain */ - Word32 *gain_code2, /* o : quantized codebook gain */ - Word8 noisy_speech_flag, /* i : noisy speech flag */ - ACELP_CbkCorr *g_coeff, /* i : correlations , -2,, -2 and 2 */ - Word16 mean_ener, /* i : only func=0: mean_ener defined in open-loop (3 bits) */ - Word32 *past_gcode, /* o : past gain of code */ - Word16 *gain_inov, /* o : Q12 innovation gain */ - const Word16 func_type /* i : algorithm: 2=gain_enc_uv_fx, 3=gain_enc_gacelp_uv */ +Word16 gain_enc_uv_fx( /* o : quantization pitch index */ + const Word16 *code, /* i : algebraic excitation */ + const Word16 *code2, /* i : gaussian excitation */ + Word16 lcode, /* i : Subframe size in range: 40,64,80 */ + Word16 *gain_pit, /* o : quantized pitch gain */ + Word32 *gain_code, /* o : quantized codebook gain */ + Word32 *gain_code2, /* o : quantized codebook gain */ + Word8 noisy_speech_flag, /* i : noisy speech flag */ + ACELP_CbkCorr *g_coeff, /* i : correlations , -2,, -2 and 2 */ + Word16 mean_ener, /* i : only func=0: mean_ener defined in open-loop (3 bits) */ + Word32 *past_gcode, /* o : past gain of code */ + Word16 *gain_inov, /* o : Q12 innovation gain */ + const Word16 func_type /* i : algorithm: 2=gain_enc_uv_fx, 3=gain_enc_gacelp_uv */ ) { Word16 i, index, exp_L_tmp1, tmp; @@ -449,16 +446,16 @@ Word16 gain_enc_uv_fx( /* o : quantization pitch index Word16 c, c_e, c_index2, c_index2_e, c_first, c_first_e; Word16 s, tmp1, s1; Word16 index2; - const Word16 log2_scale=16; + const Word16 log2_scale = 16; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; -#endif - pred_nrg_frame = 0; /* to suppress compilation warnings */ - g_code2 = 0; /* to suppress compilation warnings */ - exp_gcode2 = 0; /* to suppress compilation warnings */ +#endif + pred_nrg_frame = 0; /* to suppress compilation warnings */ + g_code2 = 0; /* to suppress compilation warnings */ + exp_gcode2 = 0; /* to suppress compilation warnings */ - assert((func_type != FUNC_GAIN_ENC_MLESS) ); + assert( ( func_type != FUNC_GAIN_ENC_MLESS ) ); /* Debug check value (not instrumented) */ index2 = -3000; @@ -466,7 +463,7 @@ Word16 gain_enc_uv_fx( /* o : quantization pitch index gacelp_uv = 0; move16(); - if (EQ_16(func_type, FUNC_GAIN_ENC_GACELP_UV)) + if ( EQ_16( func_type, FUNC_GAIN_ENC_GACELP_UV ) ) { gacelp_uv = 1; move16(); @@ -478,37 +475,37 @@ Word16 gain_enc_uv_fx( /* o : quantization pitch index *----------------------------------------------------------------*/ /* gain_inov = 1.0f / sqrt((dot_product(code, code, L_SUBFR) + 0.01) / L_SUBFR) */ - L_tmp = calc_gain_inov(code, lcode, NULL, NULL); - *gain_inov = round_fx(L_shl(L_tmp, 15-3)); /* gain_inov in Q12 */ + L_tmp = calc_gain_inov( code, lcode, NULL, NULL ); + *gain_inov = round_fx( L_shl( L_tmp, 15 - 3 ) ); /* gain_inov in Q12 */ /*----------------------------------------------------------------* * calculate the predicted gain code *----------------------------------------------------------------*/ - IF (gacelp_uv != 0) + IF( gacelp_uv != 0 ) { /* pred_nrg_frame = (float)pow(10.0,mean_ener/20.0); */ - L_tmp = L_mult(mean_ener, 10885/*0.166096f * 2 Q15*/); /* 6Q25 */ - pred_nrg_frame = BASOP_Util_InvLog2(L_sub(L_tmp, 503316480l/*15.f Q25*/)); /* 15Q16 */ + L_tmp = L_mult( mean_ener, 10885 /*0.166096f * 2 Q15*/ ); /* 6Q25 */ + pred_nrg_frame = BASOP_Util_InvLog2( L_sub( L_tmp, 503316480l /*15.f Q25*/ ) ); /* 15Q16 */ /* gcode = pred_nrg_frame * (*gain_inov); */ - L_tmp = Mpy_32_16_1(pred_nrg_frame, *gain_inov); /* 18Q13 */ - i = norm_l(L_tmp); - g_code = round_fx(L_shl(L_tmp, i)); - exp_gcode = sub(18, i); + L_tmp = Mpy_32_16_1( pred_nrg_frame, *gain_inov ); /* 18Q13 */ + i = norm_l( L_tmp ); + g_code = round_fx( L_shl( L_tmp, i ) ); + exp_gcode = sub( 18, i ); /* norm_code2 = 1.0f / sqrt((dot_product(code2, code2, lcode) + 0.01f) / lcode); */ - L_tmp = calc_gain_inov(code2, lcode, NULL, NULL); - norm_code2 = round_fx(L_shl(L_tmp, 15-3)); /* Q12 */ + L_tmp = calc_gain_inov( code2, lcode, NULL, NULL ); + norm_code2 = round_fx( L_shl( L_tmp, 15 - 3 ) ); /* Q12 */ /* g_code2 = pred_nrg_frame * norm_code2; */ - L_tmp = Mpy_32_16_1(pred_nrg_frame, norm_code2); /* 18Q13 */ - i = norm_l(L_tmp); + L_tmp = Mpy_32_16_1( pred_nrg_frame, norm_code2 ); /* 18Q13 */ + i = norm_l( L_tmp ); #ifdef BASOP_NOGLOB g_code2 = round_fx_sat( L_shl_sat( L_tmp, i ) ); #else g_code2 = round_fx( L_shl( L_tmp, i ) ); #endif - exp_gcode2 = sub(18, i); + exp_gcode2 = sub( 18, i ); } ELSE { @@ -518,32 +515,33 @@ Word16 gain_enc_uv_fx( /* o : quantization pitch index move16(); } - tmp = BASOP_Util_Divide1616_Scale(g_coeff->xy2, mult_r(g_coeff->y2y2, g_code), &i); /*Correlation based*/ - L_tmp = L_shl( L_deposit_h(tmp), add(i, sub(g_coeff->xy2_e, add(g_coeff->y2y2_e, add(exp_gcode, log2_scale)))) ); + tmp = BASOP_Util_Divide1616_Scale( g_coeff->xy2, mult_r( g_coeff->y2y2, g_code ), &i ); /*Correlation based*/ + L_tmp = L_shl( L_deposit_h( tmp ), add( i, sub( g_coeff->xy2_e, add( g_coeff->y2y2_e, add( exp_gcode, log2_scale ) ) ) ) ); /* exponent of L_tmp is 16, accounted below by adding log2(2^16) */ index = 0; move16(); - IF (L_tmp > 0) + IF( L_tmp > 0 ) { /*index = (int)(((20.f*log10(g_code)+30.f)/1.9f)+0.5f))); */ /* Since ((20*log10(x)+30)/1.9)+0.5 = 63 (max index) implies x is between 2^15 and 2^16, L_tmp might saturate at 65535 and above. That is why log2_scale is 16. */ - tmp = BASOP_Util_lin2dB(L_tmp, 16, 0); /* Q8 */ + tmp = BASOP_Util_lin2dB( L_tmp, 16, 0 ); /* Q8 */ - IF (gacelp_uv != 0) + IF( gacelp_uv != 0 ) { - L_tmp = L_mult(add(tmp, 5120/*20.0f Q8*/), 26214/*1.0f/1.25f Q15*/); + L_tmp = L_mult( add( tmp, 5120 /*20.0f Q8*/ ), 26214 /*1.0f/1.25f Q15*/ ); } ELSE { - L_tmp = L_mult(add(tmp, 7680/*30.0f Q8*/), 17246/*1.0f/1.9f Q15*/); + L_tmp = L_mult( add( tmp, 7680 /*30.0f Q8*/ ), 17246 /*1.0f/1.9f Q15*/ ); } - index = round_fx(L_shr(L_tmp, 8)); - index = s_max(0, s_min(63, index)); - if (gacelp_uv != 0) index = s_min(31, index); + index = round_fx( L_shr( L_tmp, 8 ) ); + index = s_max( 0, s_min( 63, index ) ); + if ( gacelp_uv != 0 ) + index = s_min( 31, index ); } /* *gain_code= (float) pow(10.f,(((index*1.9f)-30.f)/20.f)); */ @@ -553,123 +551,125 @@ Word16 gain_enc_uv_fx( /* o : quantization pitch index * = pow(2, 3.321928*gcode0/20) * = pow(2, 0.166096*gcode0) *----------------------------------------------------------------*/ - IF (gacelp_uv != 0) + IF( gacelp_uv != 0 ) { - L_tmp = L_mac(-111465139l/*-0.166096*20.0f Q25*/,shl(index, 16-7), 6803/*0.166096f*1.25f Q15*/); + L_tmp = L_mac( -111465139l /*-0.166096*20.0f Q25*/, shl( index, 16 - 7 ), 6803 /*0.166096f*1.25f Q15*/ ); } ELSE { - L_tmp = L_mac(-167197708l/*-0.166096*30.0f Q25*/,shl(index, 16-7), 10341/*0.166096f*1.9f Q15*/); + L_tmp = L_mac( -167197708l /*-0.166096*30.0f Q25*/, shl( index, 16 - 7 ), 10341 /*0.166096f*1.9f Q15*/ ); } - i = add(1,extract_l(L_shr(L_tmp, 25))); - L_tmp = L_lshl(L_tmp, 6); - L_tmp = L_and(0x7FFFFFFF, L_tmp); + i = add( 1, extract_l( L_shr( L_tmp, 25 ) ) ); + L_tmp = L_lshl( L_tmp, 6 ); + L_tmp = L_and( 0x7FFFFFFF, L_tmp ); - L_tmp = Pow2(30,round_fx(L_tmp)); - L_tmp = L_shl(L_tmp, i-(31-16)); /* Q16 */ + L_tmp = Pow2( 30, round_fx( L_tmp ) ); + L_tmp = L_shl( L_tmp, i - ( 31 - 16 ) ); /* Q16 */ - IF (gacelp_uv != 0) + IF( gacelp_uv != 0 ) { /* *past_gcode = L_tmp * pred_nrg_frame; */ - i = norm_l(L_tmp); - L_tmp1 = L_shl(L_tmp, i); - exp_L_tmp1 = sub(15, i); + i = norm_l( L_tmp ); + L_tmp1 = L_shl( L_tmp, i ); + exp_L_tmp1 = sub( 15, i ); - i = norm_l(pred_nrg_frame); - L_tmp1 = Mpy_32_32(L_tmp1, L_shl(pred_nrg_frame, i)); - exp_L_tmp1 = add(exp_L_tmp1, sub(15, i)); + i = norm_l( pred_nrg_frame ); + L_tmp1 = Mpy_32_32( L_tmp1, L_shl( pred_nrg_frame, i ) ); + exp_L_tmp1 = add( exp_L_tmp1, sub( 15, i ) ); - *past_gcode = L_shl(L_tmp1, sub(exp_L_tmp1, 15)); /* Q16 */ move32(); + *past_gcode = L_shl( L_tmp1, sub( exp_L_tmp1, 15 ) ); /* Q16 */ + move32(); } ELSE { - *past_gcode = L_tmp; /*unscaled gain*/ move32(); + *past_gcode = L_tmp; /*unscaled gain*/ + move32(); } #ifdef BASOP_NOGLOB *gain_code = L_shl_sat( Mpy_32_16_1( *past_gcode, *gain_inov ), 3 ); #else - *gain_code = L_shl(Mpy_32_16_1(*past_gcode, *gain_inov), 3); + *gain_code = L_shl( Mpy_32_16_1( *past_gcode, *gain_inov ), 3 ); #endif move32(); *gain_pit = 0; move16(); - IF (gacelp_uv != 0) + IF( gacelp_uv != 0 ) { /* c_first = 0.8f*g_coeff->xx - (*gain_code) * (*gain_code) * g_coeff->y2y2; */ /* c_first = g_coeff->xx - (*gain_code) * (*gain_code) * g_coeff->y2y2; */ tmp = g_coeff->xx; move16(); - if (noisy_speech_flag != 0) + if ( noisy_speech_flag != 0 ) { - tmp = mult_r(26214/*0.8f Q15*/, tmp); + tmp = mult_r( 26214 /*0.8f Q15*/, tmp ); } - s1 = norm_l(*gain_code); + s1 = norm_l( *gain_code ); #ifdef BASOP_NOGLOB - tmp1 = round_fx_o(L_shl_o(*gain_code, s1, &Overflow), &Overflow); + tmp1 = round_fx_o( L_shl_o( *gain_code, s1, &Overflow ), &Overflow ); #else - tmp1 = round_fx(L_shl(*gain_code, s1)); + tmp1 = round_fx( L_shl( *gain_code, s1 ) ); #endif - s1 = sub(15, s1); - tmp1 = mult_r(mult_r(tmp1, tmp1), g_coeff->y2y2); + s1 = sub( 15, s1 ); + tmp1 = mult_r( mult_r( tmp1, tmp1 ), g_coeff->y2y2 ); - c_first_e = BASOP_Util_Add_MantExp(tmp, g_coeff->xx_e, - negate(tmp1), add(g_coeff->y2y2_e, shl(s1, 1)), - &c_first); + c_first_e = BASOP_Util_Add_MantExp( tmp, g_coeff->xx_e, + negate( tmp1 ), add( g_coeff->y2y2_e, shl( s1, 1 ) ), + &c_first ); - L_tmp = Mpy_32_16_1(*gain_code, BASOP_Util_Divide1616_Scale(g_code2, g_code, &s)); - L_tmp = L_shl(L_tmp, sub(sub(add(s, exp_gcode2), exp_gcode), 2)); /* Q16 */ - L_tmp1 = L_add(L_tmp, 0); + L_tmp = Mpy_32_16_1( *gain_code, BASOP_Util_Divide1616_Scale( g_code2, g_code, &s ) ); + L_tmp = L_shl( L_tmp, sub( sub( add( s, exp_gcode2 ), exp_gcode ), 2 ) ); /* Q16 */ + L_tmp1 = L_add( L_tmp, 0 ); - s1 = norm_l(*gain_code); + s1 = norm_l( *gain_code ); #ifdef BASOP_NOGLOB - tmp1 = round_fx_o(L_shl_o(*gain_code, s1, &Overflow), &Overflow); + tmp1 = round_fx_o( L_shl_o( *gain_code, s1, &Overflow ), &Overflow ); #else - tmp1 = round_fx(L_shl(*gain_code, s1)); + tmp1 = round_fx( L_shl( *gain_code, s1 ) ); #endif - s1 = sub(15, s1); + s1 = sub( 15, s1 ); c_index2 = 0x7FFF; move16(); c_index2_e = 127; move16(); - FOR (i = 0; i < 4; i++) + FOR( i = 0; i < 4; i++ ) { /* c = c_first - L_tmp1 * (L_tmp1 * g_coeff->y1y1 + 2 * (*gain_code) * g_coeff->y1y2); */ - s = norm_l(L_tmp1); + s = norm_l( L_tmp1 ); #ifdef BASOP_NOGLOB tmp = round_fx_sat( L_shl_sat( L_tmp1, s ) ); #else - tmp = round_fx(L_shl(L_tmp1, s)); + tmp = round_fx( L_shl( L_tmp1, s ) ); #endif - s = sub(15, s); + s = sub( 15, s ); - c_e = BASOP_Util_Add_MantExp(mult_r(tmp, g_coeff->y1y1), add(s, g_coeff->y1y1_e), - mult_r(tmp1, g_coeff->y1y2), add(add(s1, g_coeff->y1y2_e), 1), - &c); - c = mult_r(c, tmp); - c_e = add(c_e, s); - c_e = BASOP_Util_Add_MantExp(c_first, c_first_e, negate(c), c_e, &c); + c_e = BASOP_Util_Add_MantExp( mult_r( tmp, g_coeff->y1y1 ), add( s, g_coeff->y1y1_e ), + mult_r( tmp1, g_coeff->y1y2 ), add( add( s1, g_coeff->y1y2_e ), 1 ), + &c ); + c = mult_r( c, tmp ); + c_e = add( c_e, s ); + c_e = BASOP_Util_Add_MantExp( c_first, c_first_e, negate( c ), c_e, &c ); tmp = 0; move16(); - if (LT_16(c_e, c_index2_e)) + if ( LT_16( c_e, c_index2_e ) ) { tmp = 1; move16(); } test(); - if (EQ_16(c_e, c_index2_e)&<_16(abs_s(c),abs_s(c_index2))) + if ( EQ_16( c_e, c_index2_e ) && LT_16( abs_s( c ), abs_s( c_index2 ) ) ) { tmp = 1; move16(); } - IF (tmp != 0) + IF( tmp != 0 ) { index2 = i; move16(); @@ -681,15 +681,14 @@ Word16 gain_enc_uv_fx( /* o : quantization pitch index move32(); } - L_tmp1 = L_add(L_tmp1, L_tmp); + L_tmp1 = L_add( L_tmp1, L_tmp ); } /* check if value was uninitialized */ - assert(index2 != -3000); - index = add(index, shl(index2, 5)); + assert( index2 != -3000 ); + index = add( index, shl( index2, 5 ) ); } return index; } - diff --git a/lib_enc/qlpc_avq_fx.c b/lib_enc/qlpc_avq_fx.c index 1f5507086..892a25eba 100644 --- a/lib_enc/qlpc_avq_fx.c +++ b/lib_enc/qlpc_avq_fx.c @@ -9,9 +9,9 @@ #include "cnst.h" //#include "prot_fx.h" #include "rom_com.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* @@ -19,16 +19,16 @@ * * * --------------------------------------------------------------------*/ - void qlpc_avq_fx( - const Word16 *lsf, /* i : Input LSF vectors (14Q1*1.28) */ - const Word16 *lsfmid, /* i : Input LSF vectors (14Q1*1.28) */ - Word16 *lsf_q, /* o : Quantized LFS vectors (14Q1*1.28) */ - Word16 *lsfmid_q, /* o : Quantized LFS vectors (14Q1*1.28) */ - Word16 *index, /* o : Quantization indices */ - Word16 *nb_indices, /* o : Number of quantization indices */ - Word16 *nbbits, /* o : Number of quantization bits */ - const Word16 core, /* i : TCX10 or TCX20 */ - const Word32 sr_core /* i : internal sampling rate */ +void qlpc_avq_fx( + const Word16 *lsf, /* i : Input LSF vectors (14Q1*1.28) */ + const Word16 *lsfmid, /* i : Input LSF vectors (14Q1*1.28) */ + Word16 *lsf_q, /* o : Quantized LFS vectors (14Q1*1.28) */ + Word16 *lsfmid_q, /* o : Quantized LFS vectors (14Q1*1.28) */ + Word16 *index, /* o : Quantization indices */ + Word16 *nb_indices, /* o : Number of quantization indices */ + Word16 *nbbits, /* o : Number of quantization bits */ + const Word16 core, /* i : TCX10 or TCX20 */ + const Word32 sr_core /* i : internal sampling rate */ ) { Word16 i; @@ -42,27 +42,27 @@ *nb_indices = 0; move16(); - tmp_index[0] = vlpc_1st_cod_fx(lsf, lsf_q, dummy, 0); + tmp_index[0] = vlpc_1st_cod_fx( lsf, lsf_q, dummy, 0 ); - nbt = vlpc_2st_cod_fx(lsf, lsf_q, &tmp_index[1], 0, sr_core); + nbt = vlpc_2st_cod_fx( lsf, lsf_q, &tmp_index[1], 0, sr_core ); /*nit = 1 + 2 + index[1] + index[2]; nit < NPRM_LPC_NEW(=50) */ - nit = add(add(3,index[1]),index[2]); - assert(nit < NPRM_LPC_NEW); + nit = add( add( 3, index[1] ), index[2] ); + assert( nit < NPRM_LPC_NEW ); /*tmp_index += nit;*/ tmp_index = tmp_index + nit; /**nb_indices += nit;*/ - *nb_indices = add(*nb_indices,nit); + *nb_indices = add( *nb_indices, nit ); move16(); /*nbbits[0] = 8 + nbt;*/ - nbbits[0] = add(8,nbt); + nbbits[0] = add( 8, nbt ); move16(); *tmp_index = 0; move16(); - IF (EQ_16(core, TCX_20_CORE)) + IF( EQ_16( core, TCX_20_CORE ) ) { return; @@ -71,42 +71,42 @@ /* Quantize intermediate LPC (512 framing) */ tmp_index++; /**nb_indices +=1;*/ - *nb_indices = add(*nb_indices,1); + *nb_indices = add( *nb_indices, 1 ); move16(); /* LPC2: Abs? */ - tmp_index[0] = vlpc_1st_cod_fx(lsfmid, lsfmid_q, dummy, 0); + tmp_index[0] = vlpc_1st_cod_fx( lsfmid, lsfmid_q, dummy, 0 ); - nbits = vlpc_2st_cod_fx(lsfmid, lsfmid_q, &tmp_index[1], 0, sr_core); + nbits = vlpc_2st_cod_fx( lsfmid, lsfmid_q, &tmp_index[1], 0, sr_core ); /*nbt = 8 + nbits;*/ - nbt = add(8,nbits); + nbt = add( 8, nbits ); /*nit = 1 + 2 + tmp_index[1] + tmp_index[2];*/ - nit = add(add(3,tmp_index[1]),tmp_index[2]); + nit = add( add( 3, tmp_index[1] ), tmp_index[2] ); /* LPC2: RelR? */ - FOR (i=0; i 0; ind--) + FOR( ; ind > 0; ind-- ) { - push_next_indice_fx(hBstr, 1, 1); - nb_bits = add(nb_bits, 1); + push_next_indice_fx( hBstr, 1, 1 ); + nb_bits = add( nb_bits, 1 ); } /* Stop bit */ - push_next_indice_fx(hBstr, 0, 1); + push_next_indice_fx( hBstr, 0, 1 ); - return(nb_bits); + return ( nb_bits ); } /*-------------------------------------------------------------------* * unpack4bits() * * *--------------------------------------------------------------------*/ -static Word16 unpack4bits(Word16 nbits, const Word16 *prm, BSTR_ENC_HANDLE hBstr) +static Word16 unpack4bits( Word16 nbits, const Word16 *prm, BSTR_ENC_HANDLE hBstr ) { Word16 i; - IF (nbits == 0) + IF( nbits == 0 ) { - push_next_indice_fx(hBstr, 0, 0); + push_next_indice_fx( hBstr, 0, 0 ); i = 1; move16(); } ELSE { move16(); - i=0; + i = 0; - FOR ( ; nbits > 4; nbits -= 4) + FOR( ; nbits > 4; nbits -= 4 ) { - push_next_indice_fx(hBstr, prm[i], 4); - i = add(i, 1); + push_next_indice_fx( hBstr, prm[i], 4 ); + i = add( i, 1 ); } - push_next_indice_fx(hBstr, prm[i], nbits); - i = add(i, 1); + push_next_indice_fx( hBstr, prm[i], nbits ); + i = add( i, 1 ); } - return(i); + return ( i ); } /*-------------------------------------------------------------------* * encode_lpc_avq_fx() @@ -189,16 +189,16 @@ static Word16 unpack4bits(Word16 nbits, const Word16 *prm, BSTR_ENC_HANDLE hBstr *--------------------------------------------------------------------*/ Word16 encode_lpc_avq_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ - const Word16 numlpc, /* i : Number of sets of lpc */ - const Word16* param_lpc, /* i : lpc parameters */ - const Word16 core, /* i : core */ - const Word16 element_mode /* i : element mode - decides between SNS and LPC coding */ -) + BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ + const Word16 numlpc, /* i : Number of sets of lpc */ + const Word16 *param_lpc, /* i : lpc parameters */ + const Word16 core, /* i : core */ + const Word16 element_mode /* i : element mode - decides between SNS and LPC coding */ +) { - Word16 k,j; + Word16 k, j; Word16 q_type, nb_ind; - Word16 i,qn1,qn2,nb,avqBits,st1; + Word16 i, qn1, qn2, nb, avqBits, st1; Word16 nb_bits; Word16 stereo_mode, bits_for_abs_quant; @@ -206,44 +206,44 @@ Word16 encode_lpc_avq_fx( move16(); bits_for_abs_quant = LPC_ABS_QUANT_BITS; move16(); - if (EQ_16(element_mode, IVAS_CPE_MDCT)) + if ( EQ_16( element_mode, IVAS_CPE_MDCT ) ) { bits_for_abs_quant = SNS_ABS_QUANT_BITS; move16(); } - + move16(); move16(); move16(); - st1=0; + st1 = 0; j = 0; nb_bits = 0; - FOR (k=0; k 0) + IF( nb > 0 ) { - unary_code(nb, hBstr); + unary_code( nb, hBstr ); } - nb_bits = add(nb_bits, nb); + nb_bits = add( nb_bits, nb ); move16(); nb = qn2; - IF(GT_16(nb, 6)) + IF( GT_16( nb, 6 ) ) { - nb = sub(nb, 3); + nb = sub( nb, 3 ); } - ELSE IF(GT_16(nb, 4)) + ELSE IF( GT_16( nb, 4 ) ) { - nb = sub(nb, 4); + nb = sub( nb, 4 ); } - ELSE IF(nb == 0) + ELSE IF( nb == 0 ) { move16(); nb = 3; @@ -368,29 +371,28 @@ Word16 encode_lpc_avq_fx( nb = 0; } - IF(nb > 0) + IF( nb > 0 ) { - unary_code(nb, hBstr); + unary_code( nb, hBstr ); } - nb_bits = add(nb_bits, nb); + nb_bits = add( nb_bits, nb ); - avqBits = shl(qn1, 2); - unpack4bits(avqBits, ¶m_lpc[j], hBstr); - j = add(j, qn1); - nb_bits = add(nb_bits, avqBits); + avqBits = shl( qn1, 2 ); + unpack4bits( avqBits, ¶m_lpc[j], hBstr ); + j = add( j, qn1 ); + nb_bits = add( nb_bits, avqBits ); - avqBits = shl(qn2, 2); - unpack4bits(avqBits, ¶m_lpc[j], hBstr); - j = add(j, qn2); - nb_bits = add(nb_bits, avqBits); + avqBits = shl( qn2, 2 ); + unpack4bits( avqBits, ¶m_lpc[j], hBstr ); + j = add( j, qn2 ); + nb_bits = add( nb_bits, avqBits ); } } ELSE { - j = add(j, nb_ind); + j = add( j, nb_ind ); } } - return(nb_bits); + return ( nb_bits ); } - diff --git a/lib_enc/qlpc_stoch_fx.c b/lib_enc/qlpc_stoch_fx.c index 7169ffc8b..257693928 100644 --- a/lib_enc/qlpc_stoch_fx.c +++ b/lib_enc/qlpc_stoch_fx.c @@ -11,9 +11,9 @@ #include "rom_com_fx.h" #include "rom_com.h" //#include "prot_fx.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" #include "rom_basop_util.h" @@ -21,8 +21,8 @@ * local constants *--------------------------------------------------------------------*/ -#define MIN_LOG_FX 0 -#define MIN_LOG_VAL_FX -15360 /* -60.0f in Q8 */ +#define MIN_LOG_FX 0 +#define MIN_LOG_VAL_FX -15360 /* -60.0f in Q8 */ /*-------------------------------------------------------------------* * lpc_quantization_fx() @@ -30,7 +30,7 @@ * *--------------------------------------------------------------------*/ void lpc_quantization_fx( - Encoder_State * st, + Encoder_State *st, const Word16 lsp[], const Word16 lspmid[], Word16 lsp_q[], @@ -39,13 +39,12 @@ void lpc_quantization_fx( Word16 lspq_ind[], Word16 clip_var[], const Word16 coder_type, - const Word16 acelp_midLpc, + const Word16 acelp_midLpc, Word16 param_lpc[], Word16 nbits_lpc[], - Word16 * bits_param_lpc, + Word16 *bits_param_lpc, Word16 *no_param_lpc, - const Word16 Q_ener -) + const Word16 Q_ener ) { Word16 nb_indices; Word16 lsfmid_q[M]; /* 14Q1*1.28 */ @@ -59,30 +58,29 @@ void lpc_quantization_fx( /****** High-rate LPC quantizer *******/ - IF (st->lpcQuantization==0) + IF( st->lpcQuantization == 0 ) { - if (st->sr_core != 12800) + if ( st->sr_core != 12800 ) { - //PMT("from the comment in E_LPC_isp_isf_conversion, it seems built for 12.8kHz, current sampling rate is NOT 12800, is it ok?") + // PMT("from the comment in E_LPC_isp_isf_conversion, it seems built for 12.8kHz, current sampling rate is NOT 12800, is it ok?") /*_DIFF_FLOAT_FIX_ E_LPC_lsp_lsf_conversion, does it work for 16kHz as well ?*/ - } - E_LPC_lsp_lsf_conversion(lsp, lsf, M); + E_LPC_lsp_lsf_conversion( lsp, lsf, M ); /* check resonance for pitch clipping algorithm */ - gp_clip_test_lsf_fx(st->element_mode, lsf, clip_var, M ); + gp_clip_test_lsf_fx( st->element_mode, lsf, clip_var, M ); - IF ( (EQ_16(st->core, TCX_10_CORE))) + IF( ( EQ_16( st->core, TCX_10_CORE ) ) ) { - E_LPC_lsp_lsf_conversion(lspmid, lsfmid, M); + E_LPC_lsp_lsf_conversion( lspmid, lsfmid, M ); } /* LPC quantizer */ - qlpc_avq_fx(lsf, lsfmid, lsf_q, lsfmid_q, param_lpc, &nb_indices, nbits_lpc, st->core, st->sr_core); + qlpc_avq_fx( lsf, lsfmid, lsf_q, lsfmid_q, param_lpc, &nb_indices, nbits_lpc, st->core, st->sr_core ); - E_LPC_lsf_lsp_conversion(lsf_q, lsp_q, M); + E_LPC_lsf_lsp_conversion( lsf_q, lsp_q, M ); - IF( EQ_16(st->core, TCX_10_CORE)) + IF( EQ_16( st->core, TCX_10_CORE ) ) { E_LPC_lsf_lsp_conversion( lsfmid_q, lspmid_q, M ); } @@ -92,20 +90,20 @@ void lpc_quantization_fx( /****** Low-rate LPC quantizer *******/ - ELSE IF ( EQ_16(st->lpcQuantization, 1)) + ELSE IF( EQ_16( st->lpcQuantization, 1 ) ) { - assert(st->sr_core <= 32000); + assert( st->sr_core <= 32000 ); - lsp2lsf_fx(lsp, lsf, M, extract_l(st->sr_core)); + lsp2lsf_fx( lsp, lsf, M, extract_l( st->sr_core ) ); - gp_clip_test_lsf_fx(st->element_mode, lsf, clip_var, M ); + gp_clip_test_lsf_fx( st->element_mode, lsf, clip_var, M ); force_sf = 0; move16(); /*Force safety net when possible in case of transitions*/ test(); test(); - IF( st->tc_cnt >= 1 || LE_32(st->last_core_brate,SID_2k40) || (EQ_16(st->next_force_safety_net_fx,1))) + IF( st->tc_cnt >= 1 || LE_32( st->last_core_brate, SID_2k40 ) || ( EQ_16( st->next_force_safety_net_fx, 1 ) ) ) { force_sf = 1; move16(); @@ -114,24 +112,24 @@ void lpc_quantization_fx( } test(); - IF ( EQ_16(st->next_force_safety_net_fx,1) && EQ_16(st->Opt_RF_ON,1)) + IF( EQ_16( st->next_force_safety_net_fx, 1 ) && EQ_16( st->Opt_RF_ON, 1 ) ) { force_sf = 1; st->next_force_safety_net_fx = 0; } test(); - IF ( EQ_32(st->sr_core, INT_FS_16k) && EQ_16(coder_type,UNVOICED)) + IF( EQ_32( st->sr_core, INT_FS_16k ) && EQ_16( coder_type, UNVOICED ) ) { - lsf_end_enc_fx( st, lsf, lsf_q, ENDLSF_NBITS, GENERIC, Q_ener, - force_sf, param_lpc, no_param_lpc, bits_param_lpc, GENERIC ); + lsf_end_enc_fx( st, lsf, lsf_q, ENDLSF_NBITS, GENERIC, Q_ener, + force_sf, param_lpc, no_param_lpc, bits_param_lpc, GENERIC ); nb_indices = *no_param_lpc; } ELSE { - lsf_end_enc_fx( st, lsf, lsf_q, ENDLSF_NBITS, coder_type, Q_ener, - force_sf, param_lpc, no_param_lpc, bits_param_lpc, coder_type ); + lsf_end_enc_fx( st, lsf, lsf_q, ENDLSF_NBITS, coder_type, Q_ener, + force_sf, param_lpc, no_param_lpc, bits_param_lpc, coder_type ); nb_indices = *no_param_lpc; } @@ -140,59 +138,58 @@ void lpc_quantization_fx( FEC_lsf_estim_enc_fx( st, fec_lsf ); /* FEC - calculate LSF stability */ - stab = lsf_stab_fx( lsf_q, fec_lsf, 0, st->L_frame); /*Q15*/ + stab = lsf_stab_fx( lsf_q, fec_lsf, 0, st->L_frame ); /*Q15*/ test(); test(); test(); - IF ( LT_16(stab,add(STAB_FAC_LIMIT_FX, 6553/* =0.2 in Q15*/))&& - ( EQ_16(coder_type,VOICED) || EQ_16(coder_type,GENERIC) ) && EQ_16(st->Opt_RF_ON,1 )) + IF( LT_16( stab, add( STAB_FAC_LIMIT_FX, 6553 /* =0.2 in Q15*/ ) ) && + ( EQ_16( coder_type, VOICED ) || EQ_16( coder_type, GENERIC ) ) && EQ_16( st->Opt_RF_ON, 1 ) ) { st->next_force_safety_net_fx = 1; } - lsf2lsp_fx(lsf_q, lsp_q, M, st->sr_core); + lsf2lsp_fx( lsf_q, lsp_q, M, st->sr_core ); *nbits_lpc = ENDLSF_NBITS; move16(); - } ELSE { - assert(0); + assert( 0 ); } - IF (lspq_ind != NULL) + IF( lspq_ind != NULL ) { E_LPC_lsf_lsp_conversion( lsf_q, lspq_ind, M ); } - st->seed_acelp=0; + st->seed_acelp = 0; move16(); - FOR(i=nb_indices-1; i>=0; i--) + FOR( i = nb_indices - 1; i >= 0; i-- ) { - st->seed_acelp = extract_l(L_mac0(L_mac0(13849, shr(st->seed_acelp, 1), 31821), param_lpc[i], 31821)); + st->seed_acelp = extract_l( L_mac0( L_mac0( 13849, shr( st->seed_acelp, 1 ), 31821 ), param_lpc[i], 31821 ) ); move16(); } /* Mid-frame LPC quantization */ test(); - IF(st->lpcQuantization && acelp_midLpc) + IF( st->lpcQuantization && acelp_midLpc ) { - IF(st->rate_switching_reset==0) + IF( st->rate_switching_reset == 0 ) { - lsp2lsf_fx(lspmid, lsfmid, M, extract_l(st->sr_core)); + lsp2lsf_fx( lspmid, lsfmid, M, extract_l( st->sr_core ) ); - midlsf_enc_fx(st->lsf_old_fx, lsf_q, lsfmid, &lsfmid_idx, M, st->Bin_E_old_fx, Q_ener, (Word8)st->narrowBand, st->sr_core, coder_type ); + midlsf_enc_fx( st->lsf_old_fx, lsf_q, lsfmid, &lsfmid_idx, M, st->Bin_E_old_fx, Q_ener, (Word8) st->narrowBand, st->sr_core, coder_type ); param_lpc[nb_indices++] = lsfmid_idx; move16(); - midlsf_dec (st->lsf_old_fx, lsf_q, lsfmid_idx, lsfmid_q, coder_type ,NULL,0,1 ); + midlsf_dec( st->lsf_old_fx, lsf_q, lsfmid_idx, lsfmid_q, coder_type, NULL, 0, 1 ); reorder_lsf_fx( lsfmid_q, LSF_GAP_MID_FX, M, st->sr_core ); - lsf2lsp_fx(lsfmid_q, lspmid_q, M, st->sr_core); + lsf2lsp_fx( lsfmid_q, lspmid_q, M, st->sr_core ); } ELSE { @@ -202,12 +199,10 @@ void lpc_quantization_fx( } - return; } - /*-------------------------------------------------------------------* * Unified_weighting() * @@ -215,23 +210,23 @@ void lpc_quantization_fx( *-------------------------------------------------------------------*/ void Unified_weighting_fx( - const Word32 Bin_Ener_128_fx[], /* i : FFT Bin energy 128 bins in two sets Q_ener */ + const Word32 Bin_Ener_128_fx[], /* i : FFT Bin energy 128 bins in two sets Q_ener */ Word16 Q_ener, - const Word16 lsf_fx[], /* i : LSF vector x2.56 */ - Word16 w_fx[], /* o : LP weighting filter (numerator) Q8 */ - const Word16 narrowBand, /* i : flag for Narrowband */ - const Word16 unvoiced, /* i : flag for Unvoiced frame */ - const Word32 sr_core, /* i : sampling rate of core-coder */ - const Word16 order /* i : LP order */ + const Word16 lsf_fx[], /* i : LSF vector x2.56 */ + Word16 w_fx[], /* o : LP weighting filter (numerator) Q8 */ + const Word16 narrowBand, /* i : flag for Narrowband */ + const Word16 unvoiced, /* i : flag for Unvoiced frame */ + const Word32 sr_core, /* i : sampling rate of core-coder */ + const Word16 order /* i : LP order */ ) { Word16 i; - const Word16 (*ptr_lsf_fit_model)[M]; + const Word16( *ptr_lsf_fit_model )[M]; Word16 last_bin; /*float compen;*/ Word16 exp, frac; - Word16 w_fft_fx[M]/*, w_fx[M]*/; + Word16 w_fft_fx[M] /*, w_fx[M]*/; Word16 norm_lsf_fx[M]; /* Q0 */ Word16 tmp_fx, min_fx, tmp1_fx, tmp2_fx, s1, s2; Word32 L_tmp; @@ -243,7 +238,7 @@ void Unified_weighting_fx( #endif /*Config. weighting*/ - IF ( narrowBand ) + IF( narrowBand ) { ptr_lsf_fit_model = lsf_unified_fit_model_nb; nf_fx = 16384; @@ -253,7 +248,7 @@ void Unified_weighting_fx( move16(); Bin_Ener_fx = Bin_Ener_128_fx; } - ELSE IF( EQ_32(sr_core, INT_FS_12k8)) + ELSE IF( EQ_32( sr_core, INT_FS_12k8 ) ) { ptr_lsf_fit_model = lsf_unified_fit_model_wb; nf_fx = 16384; @@ -273,21 +268,21 @@ void Unified_weighting_fx( last_bin = 159; move16(); - Copy32(Bin_Ener_128_fx, Bin_Ener_160_fx, L_FFT/2); + Copy32( Bin_Ener_128_fx, Bin_Ener_160_fx, L_FFT / 2 ); /* Find average bin energy (32 Energy) */ - L_tmp = L_deposit_l(0); - FOR ( i=95; i<127; i++ ) + L_tmp = L_deposit_l( 0 ); + FOR( i = 95; i < 127; i++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_add_o(L_tmp, Bin_Ener_160_fx[i], &Overflow); + L_tmp = L_add_o( L_tmp, Bin_Ener_160_fx[i], &Overflow ); #else - L_tmp = L_add(L_tmp, Bin_Ener_160_fx[i]); + L_tmp = L_add( L_tmp, Bin_Ener_160_fx[i] ); #endif } - L_tmp = L_shr(L_tmp, 5); - FOR ( i=127; i<160; i++ ) + L_tmp = L_shr( L_tmp, 5 ); + FOR( i = 127; i < 160; i++ ) { Bin_Ener_160_fx[i] = L_tmp; move32(); @@ -306,58 +301,58 @@ void Unified_weighting_fx( /* Use Envelope */ min_fx = MAX_16; move16(); - FOR ( i=0; i 0) + if ( i > 0 ) { - tmp1_fx = sub(tmp1_fx, lsf_fx[i-1]); + tmp1_fx = sub( tmp1_fx, lsf_fx[i - 1] ); } tmp2_fx = nf_fx; move16(); - if (NE_16(i, order - 1)) + if ( NE_16( i, order - 1 ) ) { - tmp2_fx = lsf_fx[i+1]; + tmp2_fx = lsf_fx[i + 1]; move16(); } - tmp2_fx = sub(tmp2_fx, lsf_fx[i]); + tmp2_fx = sub( tmp2_fx, lsf_fx[i] ); s1 = 15; move16(); s2 = 15; move16(); - if(tmp1_fx == 0) + if ( tmp1_fx == 0 ) { tmp1_fx = 8; } - tmp1_fx = Inv16(tmp1_fx, &s1); - if(tmp2_fx == 0) + tmp1_fx = Inv16( tmp1_fx, &s1 ); + if ( tmp2_fx == 0 ) { tmp2_fx = 8; } - tmp2_fx = Inv16(tmp2_fx, &s2); - s1 = BASOP_Util_Add_MantExp(tmp1_fx, s1, tmp2_fx, s2, &tmp1_fx); /* x * 2.56 / pow(2.0, 15 + |s1|) */ - tmp_fx = mult_r(nf_fx, 10430); - s2 = norm_s(tmp_fx); - tmp_fx = shl(tmp_fx, s2); - s1 = sub(s1, s2); + tmp2_fx = Inv16( tmp2_fx, &s2 ); + s1 = BASOP_Util_Add_MantExp( tmp1_fx, s1, tmp2_fx, s2, &tmp1_fx ); /* x * 2.56 / pow(2.0, 15 + |s1|) */ + tmp_fx = mult_r( nf_fx, 10430 ); + s2 = norm_s( tmp_fx ); + tmp_fx = shl( tmp_fx, s2 ); + s1 = sub( s1, s2 ); - tmp1_fx = mult_r(tmp1_fx, tmp_fx); /* |s1| */ - s1 = abs_s(s1); + tmp1_fx = mult_r( tmp1_fx, tmp_fx ); /* |s1| */ + s1 = abs_s( s1 ); /* 3) Fitting model combining the two weights*/ - L_tmp = L_add(ptr_lsf_fit_model[0][i], 0); /* Q10 */ - L_tmp = L_add(L_tmp, L_shl(L_mult0(ptr_lsf_fit_model[1][i], tmp1_fx), sub(-5, s1))); /* Q10 */ - L_tmp = L_add(L_tmp, L_shl(L_mult0(mult_r(tmp1_fx, tmp1_fx), ptr_lsf_fit_model[2][i]), sub(7, shl(s1, 1)))); - L_tmp = L_add(L_tmp, L_shl(L_mult0(w_fft_fx[i], ptr_lsf_fit_model[3][i]), -12)); + L_tmp = L_add( ptr_lsf_fit_model[0][i], 0 ); /* Q10 */ + L_tmp = L_add( L_tmp, L_shl( L_mult0( ptr_lsf_fit_model[1][i], tmp1_fx ), sub( -5, s1 ) ) ); /* Q10 */ + L_tmp = L_add( L_tmp, L_shl( L_mult0( mult_r( tmp1_fx, tmp1_fx ), ptr_lsf_fit_model[2][i] ), sub( 7, shl( s1, 1 ) ) ) ); + L_tmp = L_add( L_tmp, L_shl( L_mult0( w_fft_fx[i], ptr_lsf_fit_model[3][i] ), -12 ) ); move16(); /* Q10 */ - IF ( LT_32( L_shl( L_tmp, 5), InvIntTable[i+1] )) + IF( LT_32( L_shl( L_tmp, 5 ), InvIntTable[i + 1] ) ) { - w_fx[i] = shr( InvIntTable[i+1], 7); + w_fx[i] = shr( InvIntTable[i + 1], 7 ); move16(); } ELSE diff --git a/lib_enc/range_enc_fx.c b/lib_enc/range_enc_fx.c index 6519b6c0f..81fb76952 100644 --- a/lib_enc/range_enc_fx.c +++ b/lib_enc/range_enc_fx.c @@ -4,18 +4,18 @@ #include #include -#include "options.h" /* Compilation switches */ +#include "options.h" /* Compilation switches */ #include "cnst.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ +#include "rom_com_fx.h" /* Static table prototypes */ #include "rom_com.h" /* Static table prototypes */ //#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ -static void rc_enc_shift_fx(BSTR_ENC_HANDLE hBstr, PVQ_ENC_HANDLE hPVQ); -static void rc_enc_write_fx(BSTR_ENC_HANDLE hBstr, Word16 byte, Word16 bits); +static void rc_enc_shift_fx( BSTR_ENC_HANDLE hBstr, PVQ_ENC_HANDLE hPVQ ); +static void rc_enc_write_fx( BSTR_ENC_HANDLE hBstr, Word16 byte, Word16 bits ); /*-------------------------------------------------------------------* * rc_enc_init() @@ -25,10 +25,10 @@ static void rc_enc_write_fx(BSTR_ENC_HANDLE hBstr, Word16 byte, Word16 bits); void rc_enc_init_fx( PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ - Word16 tot_bits /* i : Total bit budget */ + Word16 tot_bits /* i : Total bit budget */ ) { - hPVQ->rc_low = L_deposit_l(0); + hPVQ->rc_low = L_deposit_l( 0 ); hPVQ->rc_range = 0xffffffff; move32(); hPVQ->rc_cache = -1; @@ -54,37 +54,37 @@ void rc_enc_init_fx( *-------------------------------------------------------------------*/ void rc_encode_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ - UWord32 cum_freq, /* i : Cumulative frequency up to symbol */ - UWord32 sym_freq, /* i : Symbol probability */ - UWord32 tot /* i : Total cumulative frequency */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ + UWord32 cum_freq, /* i : Cumulative frequency up to symbol */ + UWord32 sym_freq, /* i : Symbol probability */ + UWord32 tot /* i : Total cumulative frequency */ ) { UWord32 r, tmp, inv_tot, lsb; Word16 exp; UWord16 carry; - inv_tot = UL_inverse(tot, &exp); - Mpy_32_32_uu(hPVQ->rc_range, inv_tot, &tmp, &lsb); /*0+exp-32 */ - r = UL_lshr(tmp, sub(exp, 32)); /* exp-32-exp3+32 = 0 */ - tmp = UL_Mpy_32_32(r, cum_freq); + inv_tot = UL_inverse( tot, &exp ); + Mpy_32_32_uu( hPVQ->rc_range, inv_tot, &tmp, &lsb ); /*0+exp-32 */ + r = UL_lshr( tmp, sub( exp, 32 ) ); /* exp-32-exp3+32 = 0 */ + tmp = UL_Mpy_32_32( r, cum_freq ); - hPVQ->rc_low = UL_addNs(hPVQ->rc_low, tmp, &carry); - if (carry != 0) + hPVQ->rc_low = UL_addNs( hPVQ->rc_low, tmp, &carry ); + if ( carry != 0 ) { hPVQ->rc_carry = carry; move16(); } - hPVQ->rc_range = UL_Mpy_32_32(r, sym_freq); + hPVQ->rc_range = UL_Mpy_32_32( r, sym_freq ); - WHILE (hPVQ->rc_range < 1<<24) + WHILE( hPVQ->rc_range < 1 << 24 ) { - L_sub(0, 0); /* Comparison in while */ - hPVQ->rc_range = UL_lshl(hPVQ->rc_range, 8); - hPVQ->rc_num_bits = add(hPVQ->rc_num_bits, 8); - rc_enc_shift_fx(hBstr, hPVQ); + L_sub( 0, 0 ); /* Comparison in while */ + hPVQ->rc_range = UL_lshl( hPVQ->rc_range, 8 ); + hPVQ->rc_num_bits = add( hPVQ->rc_num_bits, 8 ); + rc_enc_shift_fx( hBstr, hPVQ ); } return; @@ -98,7 +98,7 @@ void rc_encode_fx( void rc_enc_finish_fx( BSTR_ENC_HANDLE hBstr, - PVQ_ENC_HANDLE hPVQ /* i/o: PVQ encoder handle */ + PVQ_ENC_HANDLE hPVQ /* i/o: PVQ encoder handle */ ) { @@ -106,27 +106,27 @@ void rc_enc_finish_fx( Word16 bits; UWord16 over1, over2; - bits = add(norm_ul(hPVQ->rc_range), 1); - mask = UL_lshr(0xffffffff, bits); + bits = add( norm_ul( hPVQ->rc_range ), 1 ); + mask = UL_lshr( 0xffffffff, bits ); - val = UL_addNs(hPVQ->rc_low, mask, &over1); - high = UL_addNs(hPVQ->rc_low, hPVQ->rc_range, &over2); + val = UL_addNs( hPVQ->rc_low, mask, &over1 ); + high = UL_addNs( hPVQ->rc_low, hPVQ->rc_range, &over2 ); - val = L_and(val, ~mask); - L_xor(0,0); /* For bit not */ + val = L_and( val, ~mask ); + L_xor( 0, 0 ); /* For bit not */ - IF ( (L_xor(over1, over2)) == 0 ) + IF( ( L_xor( over1, over2 ) ) == 0 ) { - L_sub(0, 0); /* For comparision in if */ - IF (UL_addNsD(val, mask) >= high) + L_sub( 0, 0 ); /* For comparision in if */ + IF( UL_addNsD( val, mask ) >= high ) { - bits = add(bits, 1); - mask = UL_lshr(mask, 1); - val = UL_and(UL_addNsD(hPVQ->rc_low, mask), ~mask); - L_xor(0,0); /* For bit not */ + bits = add( bits, 1 ); + mask = UL_lshr( mask, 1 ); + val = UL_and( UL_addNsD( hPVQ->rc_low, mask ), ~mask ); + L_xor( 0, 0 ); /* For bit not */ } - if (val < hPVQ->rc_low) + if ( val < hPVQ->rc_low ) { hPVQ->rc_carry = 1; move16(); @@ -136,46 +136,45 @@ void rc_enc_finish_fx( hPVQ->rc_low = val; move32(); - IF ( GT_16(bits, sub(hPVQ->rc_tot_bits, hPVQ->rc_num_bits))) + IF( GT_16( bits, sub( hPVQ->rc_tot_bits, hPVQ->rc_num_bits ) ) ) { - bits = sub(hPVQ->rc_tot_bits, hPVQ->rc_num_bits); - + bits = sub( hPVQ->rc_tot_bits, hPVQ->rc_num_bits ); } - hPVQ->rc_num_bits = add(hPVQ->rc_num_bits, bits); - FOR ( ; bits > 0; bits -= 8) + hPVQ->rc_num_bits = add( hPVQ->rc_num_bits, bits ); + FOR( ; bits > 0; bits -= 8 ) { - rc_enc_shift_fx(hBstr, hPVQ); + rc_enc_shift_fx( hBstr, hPVQ ); } - bits = add(bits, 8); + bits = add( bits, 8 ); - IF (hPVQ->rc_carry_count > 0 ) + IF( hPVQ->rc_carry_count > 0 ) { - rc_enc_write_fx(hBstr, add(hPVQ->rc_cache, hPVQ->rc_carry), 8); + rc_enc_write_fx( hBstr, add( hPVQ->rc_cache, hPVQ->rc_carry ), 8 ); - FOR ( ; hPVQ->rc_carry_count > 1; hPVQ->rc_carry_count--) + FOR( ; hPVQ->rc_carry_count > 1; hPVQ->rc_carry_count-- ) { - rc_enc_write_fx(hBstr, (hPVQ->rc_carry + 0xff), 8); + rc_enc_write_fx( hBstr, ( hPVQ->rc_carry + 0xff ), 8 ); } - rc_enc_write_fx(hBstr, s_and(add(hPVQ->rc_carry, 0xff), sub(lshl(1, bits), 1)), bits); + rc_enc_write_fx( hBstr, s_and( add( hPVQ->rc_carry, 0xff ), sub( lshl( 1, bits ), 1 ) ), bits ); } ELSE { - rc_enc_write_fx(hBstr, lshr(add(hPVQ->rc_cache, hPVQ->rc_carry), sub(8, bits)), bits); + rc_enc_write_fx( hBstr, lshr( add( hPVQ->rc_cache, hPVQ->rc_carry ), sub( 8, bits ) ), bits ); } bits = hPVQ->rc_num_bits; move16(); - WHILE (LT_16(bits, sub(hPVQ->rc_tot_bits, 16))) + WHILE( LT_16( bits, sub( hPVQ->rc_tot_bits, 16 ) ) ) { - rc_enc_write_fx(hBstr, 0, 16); - bits = add(bits, 16); + rc_enc_write_fx( hBstr, 0, 16 ); + bits = add( bits, 16 ); } - bits = sub(hPVQ->rc_tot_bits, bits); - IF (bits > 0) + bits = sub( hPVQ->rc_tot_bits, bits ); + IF( bits > 0 ) { - rc_enc_write_fx(hBstr, 0, bits); + rc_enc_write_fx( hBstr, 0, bits ); } return; @@ -188,34 +187,34 @@ void rc_enc_finish_fx( *-------------------------------------------------------------------*/ static void rc_enc_shift_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - PVQ_ENC_HANDLE hPVQ /* i/o: PVQ encoder handle */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + PVQ_ENC_HANDLE hPVQ /* i/o: PVQ encoder handle */ ) { test(); - L_sub(0, 0); /* For comparision in if */ - IF (hPVQ->rc_low < (0xff000000UL) || EQ_16(hPVQ->rc_carry, 1)) + L_sub( 0, 0 ); /* For comparision in if */ + IF( hPVQ->rc_low < ( 0xff000000UL ) || EQ_16( hPVQ->rc_carry, 1 ) ) { - IF (hPVQ->rc_cache >= 0) + IF( hPVQ->rc_cache >= 0 ) { - rc_enc_write_fx(hBstr, add(hPVQ->rc_cache, hPVQ->rc_carry), 8); + rc_enc_write_fx( hBstr, add( hPVQ->rc_cache, hPVQ->rc_carry ), 8 ); } - WHILE (hPVQ->rc_carry_count > 0) + WHILE( hPVQ->rc_carry_count > 0 ) { - rc_enc_write_fx(hBstr, s_and(add(hPVQ->rc_carry, 0xff), 255), 8); - hPVQ->rc_carry_count = sub(hPVQ->rc_carry_count, 1); + rc_enc_write_fx( hBstr, s_and( add( hPVQ->rc_carry, 0xff ), 255 ), 8 ); + hPVQ->rc_carry_count = sub( hPVQ->rc_carry_count, 1 ); } - hPVQ->rc_cache = u_extract_l(UL_lshr(hPVQ->rc_low, 24)); + hPVQ->rc_cache = u_extract_l( UL_lshr( hPVQ->rc_low, 24 ) ); hPVQ->rc_carry = 0; move16(); } ELSE { - hPVQ->rc_carry_count = add(hPVQ->rc_carry_count, 1); + hPVQ->rc_carry_count = add( hPVQ->rc_carry_count, 1 ); } - hPVQ->rc_low = UL_lshl(hPVQ->rc_low, 8); + hPVQ->rc_low = UL_lshl( hPVQ->rc_low, 8 ); return; } @@ -227,27 +226,27 @@ static void rc_enc_shift_fx( *-------------------------------------------------------------------*/ void rc_enc_bits_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ - UWord32 value, /* i : Value to encode */ - Word16 bits /* i : Number of bits used */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ + UWord32 value, /* i : Value to encode */ + Word16 bits /* i : Number of bits used */ ) { - IF ( LE_16(add(rc_get_bits2_fx(hPVQ->rc_num_bits, hPVQ->rc_range), bits), hPVQ->rc_tot_bits)) + IF( LE_16( add( rc_get_bits2_fx( hPVQ->rc_num_bits, hPVQ->rc_range ), bits ), hPVQ->rc_tot_bits ) ) { - hPVQ->rc_num_bits = add(hPVQ->rc_num_bits, bits); + hPVQ->rc_num_bits = add( hPVQ->rc_num_bits, bits ); - IF ( GT_16(bits, 16)) + IF( GT_16( bits, 16 ) ) { - push_indice_fx(hBstr, sub(IND_RC_END, hPVQ->rc_offset), u_extract_l(UL_lshr(value, 16)), sub(bits, 16)); - hPVQ->rc_offset = add(hPVQ->rc_offset, 1); - push_indice_fx(hBstr, sub(IND_RC_END, hPVQ->rc_offset), u_extract_l(UL_and(value, 0x0000ffff)), 16); - hPVQ->rc_offset = add(hPVQ->rc_offset, 1); + push_indice_fx( hBstr, sub( IND_RC_END, hPVQ->rc_offset ), u_extract_l( UL_lshr( value, 16 ) ), sub( bits, 16 ) ); + hPVQ->rc_offset = add( hPVQ->rc_offset, 1 ); + push_indice_fx( hBstr, sub( IND_RC_END, hPVQ->rc_offset ), u_extract_l( UL_and( value, 0x0000ffff ) ), 16 ); + hPVQ->rc_offset = add( hPVQ->rc_offset, 1 ); } ELSE { - push_indice_fx(hBstr, sub(IND_RC_END, hPVQ->rc_offset), u_extract_l(value), bits); - hPVQ->rc_offset = add(hPVQ->rc_offset, 1); + push_indice_fx( hBstr, sub( IND_RC_END, hPVQ->rc_offset ), u_extract_l( value ), bits ); + hPVQ->rc_offset = add( hPVQ->rc_offset, 1 ); } } ELSE @@ -264,25 +263,25 @@ void rc_enc_bits_fx( *-------------------------------------------------------------------*/ void rc_enc_uniform_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ - UWord32 value, /* i : Value to encode */ - UWord32 tot /* i : Maximum value */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ + UWord32 value, /* i : Value to encode */ + UWord32 tot /* i : Maximum value */ ) { Word16 n; - n = sub(32, norm_ul(UL_subNsD(tot, 1))); + n = sub( 32, norm_ul( UL_subNsD( tot, 1 ) ) ); - IF (LE_16(n, 8)) + IF( LE_16( n, 8 ) ) { - rc_encode_fx(hBstr, hPVQ, value, 1, tot); + rc_encode_fx( hBstr, hPVQ, value, 1, tot ); } ELSE { - n = sub(n, 8); - rc_encode_fx(hBstr, hPVQ, UL_lshr(value, n), 1, UL_addNsD(UL_lshr(tot, n), 1)); - rc_enc_bits_fx(hBstr, hPVQ, UL_and(value, UL_subNsD(UL_lshl(1, n), 1)), n); + n = sub( n, 8 ); + rc_encode_fx( hBstr, hPVQ, UL_lshr( value, n ), 1, UL_addNsD( UL_lshr( tot, n ), 1 ) ); + rc_enc_bits_fx( hBstr, hPVQ, UL_and( value, UL_subNsD( UL_lshl( 1, n ), 1 ) ), n ); } return; @@ -295,12 +294,12 @@ void rc_enc_uniform_fx( *-------------------------------------------------------------------*/ static void rc_enc_write_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - Word16 byte, /* i : Byte to write */ - Word16 bits /* i : Number of bits */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 byte, /* i : Byte to write */ + Word16 bits /* i : Number of bits */ ) { - push_indice_fx(hBstr, IND_RC_START, byte, bits); + push_indice_fx( hBstr, IND_RC_START, byte, bits ); return; } diff --git a/lib_enc/re8_cod_fx.c b/lib_enc/re8_cod_fx.c index 49b88b8e9..0b14385fe 100644 --- a/lib_enc/re8_cod_fx.c +++ b/lib_enc/re8_cod_fx.c @@ -2,12 +2,12 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ +#include "options.h" /* Compilation switches */ #include "cnst.h" //#include "prot_fx.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*------------------------------------------------------------------------ * RE8_cod: @@ -18,10 +18,10 @@ *--------------------------------------------------------------------------*/ void re8_cod_fx( - Word16 x[], /* i : point in RE8 (8-dimensional integer vector) */ - Word16 *n, /* i : codebook number (*n is an integer defined in {0,2,3,4,..,n_max}) */ - UWord16 *I, /* o : index of c (pointer to unsigned 16-bit word) */ - Word16 k[] /* o : index of v (8-dimensional vector of binary indices) = Voronoi index */ + Word16 x[], /* i : point in RE8 (8-dimensional integer vector) */ + Word16 *n, /* i : codebook number (*n is an integer defined in {0,2,3,4,..,n_max}) */ + UWord16 *I, /* o : index of c (pointer to unsigned 16-bit word) */ + Word16 k[] /* o : index of v (8-dimensional vector of binary indices) = Voronoi index */ ) { Word16 ka_fx, c_fx[8]; @@ -36,10 +36,10 @@ void re8_cod_fx( * - the index I of c * - the index k[] of v ----------------------------------------------------------------------*/ - re8_vor_fx(x, n, k, c_fx, &ka_fx); + re8_vor_fx( x, n, k, c_fx, &ka_fx ); /* safeguard in case that the AVQ subquantizer is not found - might happen for extremely strong onsets at the end of the frame */ - IF( GE_16(ka_fx,NB_LEADER)) + IF( GE_16( ka_fx, NB_LEADER ) ) { *n = 0; move16(); @@ -47,9 +47,9 @@ void re8_cod_fx( } /* compute the index I (only if c is in Q2, Q3 or Q4) */ - IF (*n > 0) + IF( *n > 0 ) { - re8_compute_base_index_fx(c_fx, ka_fx, I); + re8_compute_base_index_fx( c_fx, ka_fx, I ); } return; diff --git a/lib_enc/reordernorm_fx.c b/lib_enc/reordernorm_fx.c index 505cfd693..df30c3084 100644 --- a/lib_enc/reordernorm_fx.c +++ b/lib_enc/reordernorm_fx.c @@ -3,14 +3,14 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ #include "rom_com_fx.h" #include "rom_com.h" //#include "prot_fx.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*--------------------------------------------------------------------------*/ /* Function reordernorm_fx */ @@ -30,23 +30,23 @@ void reordernorm_fx( Word16 i; const Word16 *order = NULL; - SWITCH(nb_sfm) + SWITCH( nb_sfm ) { - case NB_SFM: - order = norm_order_48; - BREAK; - case SFM_N_SWB: - order = norm_order_32; - BREAK; - case SFM_N_WB: - order = norm_order_16; - BREAK; - default: - order = norm_order_48; - BREAK; + case NB_SFM: + order = norm_order_48; + BREAK; + case SFM_N_SWB: + order = norm_order_32; + BREAK; + case SFM_N_WB: + order = norm_order_16; + BREAK; + default: + order = norm_order_48; + BREAK; } - FOR (i = 0; i < nb_sfm; i++) + FOR( i = 0; i < nb_sfm; i++ ) { idxbuf[i] = ynrm[order[i]]; move16(); diff --git a/lib_enc/rom_enc.c b/lib_enc/rom_enc.c index 0266cae22..dea73a1af 100644 --- a/lib_enc/rom_enc.c +++ b/lib_enc/rom_enc.c @@ -1473,84 +1473,90 @@ const Word16 inv_delta_tab[7] = /*Q15*/ }; /* clang-format on */ -const Word16 i_t_1[10] = { 2048,4096,6144,8192,10240,12288,14336,16384,18432,20480 }; -const Word16 i_t_2[23] = { 1024,2048,3072,4096,5120,6144,7168,8192,9216,10240,11264,12288,13312,14336,15360,16384,17408,18432,19456,20480,21504,22528,23552 }; - -const Word16 SF_mult_fx[N_FEATURES] = -{ - 20133, /*Q22*/ - 32767, /*Q15*/ - 20401, /*Q15*/ - 18013, /*Q15*/ - 16263, /*Q15*/ - 16545, /*Q15*/ - 16610, /*Q15*/ - 17197, /*Q22*/ - 18455, /*Q23*/ - 16515, /*Q18*/ - 17931, /*Q18*/ - 30382 /*Q18*/ -}; - -const Word16 SF_8k_mult_fx[N_FEATURES] = -{ - 17197, /*Q22*/ - 28088, /*Q15*/ - 22082, /*Q15*/ - 20503, /*Q15*/ - 18006, /*Q15*/ - 18983, /*Q15*/ - 8199 , /*Q15*/ - 17197, /*Q22*/ - 16777, /*Q23*/ - 16515, /*Q18*/ - 15676, /*Q18*/ - 16541 /*Q18*/ -}; - -const Word32 SF_add_fx[N_FEATURES] = -{ - -798595, /*Q23*/ - 0, /*Q31*/ - -37312528, /*Q29*/ - -67914170, /*Q29*/ - -119722213, /*Q29*/ - -220278135, /*Q29*/ - -306929100, /*Q29*/ - 0, /*Q30*/ +const Word16 i_t_1[10] = { 2048, 4096, 6144, 8192, 10240, 12288, 14336, 16384, 18432, 20480 }; +const Word16 i_t_2[23] = { 1024, 2048, 3072, 4096, 5120, 6144, 7168, 8192, 9216, 10240, 11264, 12288, 13312, 14336, 15360, 16384, 17408, 18432, 19456, 20480, 21504, 22528, 23552 }; + +const Word16 SF_mult_fx[N_FEATURES] = { + 20133, /*Q22*/ + 32767, /*Q15*/ + 20401, /*Q15*/ + 18013, /*Q15*/ + 16263, /*Q15*/ + 16545, /*Q15*/ + 16610, /*Q15*/ + 17197, /*Q22*/ + 18455, /*Q23*/ + 16515, /*Q18*/ + 17931, /*Q18*/ + 30382 /*Q18*/ +}; + +const Word16 SF_8k_mult_fx[N_FEATURES] = { + 17197, /*Q22*/ + 28088, /*Q15*/ + 22082, /*Q15*/ + 20503, /*Q15*/ + 18006, /*Q15*/ + 18983, /*Q15*/ + 8199, /*Q15*/ + 17197, /*Q22*/ + 16777, /*Q23*/ + 16515, /*Q18*/ + 15676, /*Q18*/ + 16541 /*Q18*/ +}; + +const Word32 SF_add_fx[N_FEATURES] = { + -798595, /*Q23*/ + 0, /*Q31*/ + -37312528, /*Q29*/ + -67914170, /*Q29*/ + -119722213, /*Q29*/ + -220278135, /*Q29*/ + -306929100, /*Q29*/ + 0, /*Q30*/ -6227703, /*Q31*/ - 537676218, /*Q29*/ - 488713591, /*Q29*/ - -314713729 /*Q30*/ + 537676218, /*Q29*/ + 488713591, /*Q29*/ + -314713729 /*Q30*/ }; -const Word32 SF_8k_add_fx[N_FEATURES] = -{ - 0, /*Q23*/ - 219043332, /*Q31*/ - -53687091, /*Q29*/ - -90086939, /*Q29*/ +const Word32 SF_8k_add_fx[N_FEATURES] = { + 0, /*Q23*/ + 219043332, /*Q31*/ + -53687091, /*Q29*/ + -90086939, /*Q29*/ -127775277, /*Q29*/ -249430226, /*Q29*/ - 0, /*Q29*/ - 0, /*Q30*/ - 0, /*Q31*/ - 537676218, /*Q29*/ - 481412147, /*Q29*/ - 0 /*Q30*/ + 0, /*Q29*/ + 0, /*Q30*/ + 0, /*Q31*/ + 537676218, /*Q29*/ + 481412147, /*Q29*/ + 0 /*Q30*/ }; /* subband_fft.c */ -const complex_16 wnk_table_16[16] = -{ - {32767, 0}, {30274, 12540}, {23170, 23170}, {12540, 30274}, - {32767, 0}, {23170, 23170}, {0, 32767}, {-23170, 23170}, - {32767, 0}, {12540, 30274}, {-23170, 23170}, {-30274, -12540}, - {32767, 0}, {32767, 0}, {32767, 0}, {0, -32768}, +const complex_16 wnk_table_16[16] = { + { 32767, 0 }, + { 30274, 12540 }, + { 23170, 23170 }, + { 12540, 30274 }, + { 32767, 0 }, + { 23170, 23170 }, + { 0, 32767 }, + { -23170, 23170 }, + { 32767, 0 }, + { 12540, 30274 }, + { -23170, 23170 }, + { -30274, -12540 }, + { 32767, 0 }, + { 32767, 0 }, + { 32767, 0 }, + { 0, -32768 }, }; /* integer square (i*i) */ -const Word16 int_sqr[17] = -{ +const Word16 int_sqr[17] = { 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256 -}; \ No newline at end of file +}; diff --git a/lib_enc/rom_enc.h b/lib_enc/rom_enc.h index 71817ee91..cc009fc7a 100644 --- a/lib_enc/rom_enc.h +++ b/lib_enc/rom_enc.h @@ -46,21 +46,21 @@ * General tables *----------------------------------------------------------------------------------*/ -extern const float sqrt_han_window[]; /* Half of the square root hanning window */ +extern const float sqrt_han_window[]; /* Half of the square root hanning window */ extern const Word16 sqrt_han_window_fx[]; /* Half of the square root hanning window */ -extern const int16_t tipos[]; /* Starting points for pulse position search in Algebraic innovation codebook */ +extern const int16_t tipos[]; /* Starting points for pulse position search in Algebraic innovation codebook */ extern const float E_ROM_inter4_1[PIT_UP_SAMP * L_INTERPOL1 + 1]; extern const float E_ROM_inter6_1[PIT_UP_SAMP6 * L_INTERPOL1 + 1]; extern const float E_ROM_inter4_1[PIT_UP_SAMP * L_INTERPOL1 + 1]; extern const float E_ROM_inter6_1[PIT_UP_SAMP6 * L_INTERPOL1 + 1]; -extern const float W_HIST[DTX_HIST_SIZE]; /* CNG & DTX - table for calculation of average excitation energy */ -extern const Word16 W_HIST_FX[DTX_HIST_SIZE]; /* CNG & DTX - table for calculation of average excitation energy */ +extern const float W_HIST[DTX_HIST_SIZE]; /* CNG & DTX - table for calculation of average excitation energy */ +extern const Word16 W_HIST_FX[DTX_HIST_SIZE]; /* CNG & DTX - table for calculation of average excitation energy */ extern const Word16 W_HIST_S_FX[DTX_HIST_SIZE]; /* CNG & DTX - table for calculation of average excitation energy */ extern const int16_t bwd_start_bin[]; extern const int16_t bwd_end_bin[]; -extern const float h_fir[]; /* 2nd order fir filter for wsp, decimation by 2 */ +extern const float h_fir[]; /* 2nd order fir filter for wsp, decimation by 2 */ extern const Word16 H_fir[]; /* 2nd order fir filter for wsp, decimation by 2 */ extern const float preemphCompensation[]; @@ -227,13 +227,13 @@ extern const Word32 LT_MIN_SILENCE_SNR_FX[4]; extern const int16_t startLineWB[N_TCX_STARTLINE_NOISE_WB]; extern const int16_t startLineSWB[N_TCX_STARTLINE_NOISE_SWB]; -//EVS basop +// EVS basop extern const Word32 LS_MIN_SILENCE_SNR[4]; extern const Word16 SNR_SUB_BAND_NUM[4]; extern const Word16 BAND_MUL[4]; -extern const UWord8 E_ROM_tipos[]; /* ACELP indexing */ +extern const UWord8 E_ROM_tipos[]; /* ACELP indexing */ extern const Word16 Weight[86]; extern const Word16 BAND_SCALE_AJ[5]; diff --git a/lib_enc/rst_enc_fx.c b/lib_enc/rst_enc_fx.c index 62da4c54a..009ba531a 100644 --- a/lib_enc/rst_enc_fx.c +++ b/lib_enc/rst_enc_fx.c @@ -2,14 +2,14 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "rom_com.h" /* Static table prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com_fx.h" /* Static table prototypes */ +#include "rom_com.h" /* Static table prototypes */ //#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ #include "stl.h" /*-------------------------------------------------------------------* @@ -19,14 +19,13 @@ *-------------------------------------------------------------------*/ void CNG_reset_enc_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - LPD_state_HANDLE hLPDmem, /* i/o: acelp memories */ - Word16 *pitch_buf, /* o : floating pitch for each subframe */ - Word16 *voice_factors, /* o : voicing factors */ - Word16 VBR_cng_reset_flag -) + Encoder_State *st_fx, /* i/o: encoder state structure */ + LPD_state_HANDLE hLPDmem, /* i/o: acelp memories */ + Word16 *pitch_buf, /* o : floating pitch for each subframe */ + Word16 *voice_factors, /* o : voicing factors */ + Word16 VBR_cng_reset_flag ) { - TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; + TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; init_gp_clip_fx( st_fx->clip_var_fx ); Copy( UVWB_Ave_fx, st_fx->mem_AR_fx, M ); @@ -37,14 +36,14 @@ void CNG_reset_enc_fx( move16(); hLPDmem->gc_threshold = 0; move16(); - IF( EQ_16(VBR_cng_reset_flag,1)) + IF( EQ_16( VBR_cng_reset_flag, 1 ) ) { set16_fx( hLPDmem->mem_syn, 0, M ); } - set16_fx(hLPDmem->dm_fx.prev_gain_pit, 0, 6); - hLPDmem->dm_fx.prev_gain_code = L_deposit_l(0); + set16_fx( hLPDmem->dm_fx.prev_gain_pit, 0, 6 ); + hLPDmem->dm_fx.prev_gain_code = L_deposit_l( 0 ); hLPDmem->dm_fx.prev_state = 0; - //PMTE() + // PMTE() move16(); /* last good received frame for FEC in ACELP */ @@ -52,11 +51,11 @@ void CNG_reset_enc_fx( move16(); /* reset the pitch buffer in case of FRAME_NO_DATA or SID frames */ - IF( EQ_16(st_fx->L_frame,L_FRAME)) + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { set16_fx( pitch_buf, L_SUBFR, NB_SUBFR ); } - ELSE /* st->L_frame == L_FRAME16k */ + ELSE /* st->L_frame == L_FRAME16k */ { set16_fx( pitch_buf, L_SUBFR16k, NB_SUBFR16k ); } @@ -68,7 +67,7 @@ void CNG_reset_enc_fx( move16(); /* Reset active frame counter */ - if (hTdCngEnc != NULL) + if ( hTdCngEnc != NULL ) { hTdCngEnc->act_cnt2 = 0; move16(); diff --git a/lib_enc/scale_enc_fx.c b/lib_enc/scale_enc_fx.c index a831229ec..dd4f88b00 100644 --- a/lib_enc/scale_enc_fx.c +++ b/lib_enc/scale_enc_fx.c @@ -2,13 +2,13 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include "options.h" /* Compilation switches */ +#include "options.h" /* Compilation switches */ #include "cnst.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ +#include "rom_com_fx.h" /* Static table prototypes */ //#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ #include "stl.h" /*-------------------------------------------------------------------* @@ -17,15 +17,15 @@ * Find scaling factor for weighted speech input *-------------------------------------------------------------------*/ void Scale_wsp( - Word16 *wsp, /* i : Weigthed speech */ - Word16 *old_wsp_max, /* i : Last weigthed speech maximal valu */ - Word16 *shift, /* i/o: Scaling of current frame */ - Word16 *Q_exp, /* i/o: Differential scaling factor */ - Word16 *old_wsp_shift, /* i/o: Last wsp scaling */ - Word16 *old_wsp, /* i/o: Old weighted speech buffer */ - Word16 *mem_decim2, /* i/o: Decimation buffer */ - Word16 *old_wsp12k8, /* i/o: wsp memory @ 12.8 kHz used in pitol2 */ - const Word16 Len_p_look /* i : L_frame + look ahead */ + Word16 *wsp, /* i : Weigthed speech */ + Word16 *old_wsp_max, /* i : Last weigthed speech maximal valu */ + Word16 *shift, /* i/o: Scaling of current frame */ + Word16 *Q_exp, /* i/o: Differential scaling factor */ + Word16 *old_wsp_shift, /* i/o: Last wsp scaling */ + Word16 *old_wsp, /* i/o: Old weighted speech buffer */ + Word16 *mem_decim2, /* i/o: Decimation buffer */ + Word16 *old_wsp12k8, /* i/o: wsp memory @ 12.8 kHz used in pitol2 */ + const Word16 Len_p_look /* i : L_frame + look ahead */ ) { Word16 max, i, tmp; @@ -33,33 +33,33 @@ void Scale_wsp( /* find maximum value on wsp[] for 12 bits scaling */ max = 0; move16(); - FOR (i = 0; i < Len_p_look; i++) + FOR( i = 0; i < Len_p_look; i++ ) { - tmp = abs_s(wsp[i]); - max = s_max(max,tmp); + tmp = abs_s( wsp[i] ); + max = s_max( max, tmp ); } tmp = *old_wsp_max; move16(); - tmp = s_max(max, tmp); + tmp = s_max( max, tmp ); *old_wsp_max = max; move16(); - *shift = sub(norm_s(tmp), 3); + *shift = sub( norm_s( tmp ), 3 ); move16(); - *shift = s_min(*shift, 0); + *shift = s_min( *shift, 0 ); move16(); /* shift = 0..-3 */ - Scale_sig(wsp, Len_p_look, *shift); + Scale_sig( wsp, Len_p_look, *shift ); /* scale old_wsp (warning: exp must be Q_new-Q_old) */ - *Q_exp= add(*Q_exp, sub(*shift, *old_wsp_shift)); + *Q_exp = add( *Q_exp, sub( *shift, *old_wsp_shift ) ); move16(); *old_wsp_shift = *shift; move16(); - Scale_sig(old_wsp12k8, L_WSP_MEM, *Q_exp); /* Already scaled with premphasis */ - Scale_sig(old_wsp, (L_WSP_MEM - L_INTERPOL)/OPL_DECIM, *Q_exp ); - Scale_sig(mem_decim2, 3, *Q_exp); + Scale_sig( old_wsp12k8, L_WSP_MEM, *Q_exp ); /* Already scaled with premphasis */ + Scale_sig( old_wsp, ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM, *Q_exp ); + Scale_sig( mem_decim2, 3, *Q_exp ); Copy( old_wsp12k8, wsp - L_WSP_MEM, L_WSP_MEM ); /* Now memory and wsp vector have the same scaling */ } @@ -70,17 +70,17 @@ void Scale_wsp( * Find scaled preemphasis vector and its scaling factor *-------------------------------------------------------------------*/ void Preemph_scaled( - Word16 new_speech[], /* i : Speech to scale already on 14 bits*/ - Word16 *Q_new, /* o : Scaling factor */ - Word16 *mem_preemph, /* i/o: Preemph memory */ - Word16 *Q_max, /* i/o: Q_new limitation */ - const Word16 Preemph_factor, /* i : Preemphasis factor Q15 */ - const Word16 bits, /* i : Bit to remove from the output to (15-bits)*/ - const Word16 bit1, /* i : Limit the output scaling to ((15-bits)-bit1) bits */ - const Word16 L_Q_mem, /* i : Number of old scaling to take into account */ - const Word16 Lframe, /* i : Frame length */ - const Word16 last_coder_type, /* i : coder_type */ - const Word16 Search_scaling /* i : enable the search of a proper scaling factor*/ + Word16 new_speech[], /* i : Speech to scale already on 14 bits*/ + Word16 *Q_new, /* o : Scaling factor */ + Word16 *mem_preemph, /* i/o: Preemph memory */ + Word16 *Q_max, /* i/o: Q_new limitation */ + const Word16 Preemph_factor, /* i : Preemphasis factor Q15 */ + const Word16 bits, /* i : Bit to remove from the output to (15-bits)*/ + const Word16 bit1, /* i : Limit the output scaling to ((15-bits)-bit1) bits */ + const Word16 L_Q_mem, /* i : Number of old scaling to take into account */ + const Word16 Lframe, /* i : Frame length */ + const Word16 last_coder_type, /* i : coder_type */ + const Word16 Search_scaling /* i : enable the search of a proper scaling factor*/ ) { Word16 i, tmp_fixed; @@ -99,65 +99,65 @@ void Preemph_scaled( BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB Overflow = 0; - QVal = shl_o(1, sub(15,bits), &Overflow); -#else /* BASOP_NOGLOB */ - QVal = shl(1, sub(15,bits)); + QVal = shl_o( 1, sub( 15, bits ), &Overflow ); +#else /* BASOP_NOGLOB */ + QVal = shl( 1, sub( 15, bits ) ); #endif /* BASOP_NOGLOB */ BASOP_SATURATE_WARNING_ON_EVS - mu = shr(Preemph_factor, bits); /* Q15 --> Q(15-bits) */ + mu = shr( Preemph_factor, bits ); /* Q15 --> Q(15-bits) */ - IF(EQ_16(Search_scaling,1)) + IF( EQ_16( Search_scaling, 1 ) ) { /* get max of new preemphased samples (L_FRAME+L_FILT) */ - L_tmp = L_mult(new_speech[0], QVal); + L_tmp = L_mult( new_speech[0], QVal ); #ifdef BASOP_NOGLOB L_tmp = L_msu_sat( L_tmp, *mem_preemph, mu ); #else - L_tmp = L_msu(L_tmp, *mem_preemph, mu); + L_tmp = L_msu( L_tmp, *mem_preemph, mu ); #endif - L_maxloc = L_abs(L_tmp); + L_maxloc = L_abs( L_tmp ); - FOR (i = 1; i < Lframe; i++) + FOR( i = 1; i < Lframe; i++ ) { /* Equivalent to tmp = max((abs(x[i] - mu*x[i-1]),tmp) - * finds the max of preemphasized signal */ - L_tmp = L_mult(new_speech[i], QVal); + * finds the max of preemphasized signal */ + L_tmp = L_mult( new_speech[i], QVal ); #ifdef BASOP_NOGLOB - L_tmp = L_msu_o(L_tmp, new_speech[i - 1], mu, &Overflow); -#else /* BASOP_NOGLOB */ - L_tmp = L_msu(L_tmp, new_speech[i - 1], mu); + L_tmp = L_msu_o( L_tmp, new_speech[i - 1], mu, &Overflow ); +#else /* BASOP_NOGLOB */ + L_tmp = L_msu( L_tmp, new_speech[i - 1], mu ); #endif /* BASOP_NOGLOB */ - L_tmp = L_abs(L_tmp); - L_maxloc = L_max(L_tmp, L_maxloc); + L_tmp = L_abs( L_tmp ); + L_maxloc = L_max( L_tmp, L_maxloc ); } /* get scaling factor for new and previous samples */ /* limit scaling to Q_MAX to keep dynamic for ringing in low signal */ /* limit scaling to Q_MAX also to avoid a[0]<1 in syn_filt_32 */ - tmp_fixed = s_max(extract_h(L_maxloc),1); + tmp_fixed = s_max( extract_h( L_maxloc ), 1 ); /* output on 14 bits: needed unless the resampling itself removes 1 bit*/ - shift = sub(norm_s(tmp_fixed), add(bits,bit1)); - shift = s_max(shift, 0); - shift = s_min(shift, Q_MAX); + shift = sub( norm_s( tmp_fixed ), add( bits, bit1 ) ); + shift = s_max( shift, 0 ); + shift = s_min( shift, Q_MAX ); - minimum_fx(Q_max, L_Q_mem, &Q_min); - *Q_new = s_min(shift, Q_min); + minimum_fx( Q_max, L_Q_mem, &Q_min ); + *Q_new = s_min( shift, Q_min ); move16(); - IF (tmp_fixed == 0) + IF( tmp_fixed == 0 ) { - IF ( NE_16(last_coder_type, UNVOICED)) + IF( NE_16( last_coder_type, UNVOICED ) ) { - *Q_new = s_min(*Q_new, 1); + *Q_new = s_min( *Q_new, 1 ); move16(); } } - FOR(i = L_Q_mem-1; i > 0; i--) + FOR( i = L_Q_mem - 1; i > 0; i-- ) { - Q_max[i] = Q_max[i-1]; + Q_max[i] = Q_max[i - 1]; move16(); } Q_max[i] = shift; @@ -174,31 +174,31 @@ void Preemph_scaled( tmp_fixed = new_speech[Lframe - 1]; move16(); - FOR (i = sub(Lframe,1); i > 0; i--) + FOR( i = sub( Lframe, 1 ); i > 0; i-- ) { - L_tmp = L_mult(new_speech[i], QVal); + L_tmp = L_mult( new_speech[i], QVal ); #ifdef BASOP_NOGLOB - L_tmp = L_msu_o(L_tmp, new_speech[i - 1], mu, &Overflow); -#else /* BASOP_NOGLOB */ - L_tmp = L_msu(L_tmp, new_speech[i - 1], mu); + L_tmp = L_msu_o( L_tmp, new_speech[i - 1], mu, &Overflow ); +#else /* BASOP_NOGLOB */ + L_tmp = L_msu( L_tmp, new_speech[i - 1], mu ); #endif /* BASOP_NOGLOB */ - L_tmp = L_shl(L_tmp, *Q_new); + L_tmp = L_shl( L_tmp, *Q_new ); #ifdef BASOP_NOGLOB new_speech[i] = round_fx_sat( L_tmp ); #else - new_speech[i] = round_fx(L_tmp); + new_speech[i] = round_fx( L_tmp ); #endif } - L_tmp = L_mult(new_speech[0], QVal); + L_tmp = L_mult( new_speech[0], QVal ); #ifdef BASOP_NOGLOB L_tmp = L_msu_sat( L_tmp, *mem_preemph, mu ); - L_tmp = L_shl_sat(L_tmp, *Q_new); - new_speech[0] = round_fx_sat(L_tmp); + L_tmp = L_shl_sat( L_tmp, *Q_new ); + new_speech[0] = round_fx_sat( L_tmp ); #else - L_tmp = L_msu(L_tmp, *mem_preemph, mu); - L_tmp = L_shl(L_tmp, *Q_new); - new_speech[0] = round_fx(L_tmp); + L_tmp = L_msu( L_tmp, *mem_preemph, mu ); + L_tmp = L_shl( L_tmp, *Q_new ); + new_speech[0] = round_fx( L_tmp ); #endif *mem_preemph = tmp_fixed; move16(); @@ -208,20 +208,19 @@ void Preemph_scaled( * * Rescale memories *-------------------------------------------------------------------*/ -Word32 Scale_mem_pre_proc( /* o : Min energy scaled */ - Word16 ini_frame_fx, /* i : Frame number */ - Word16 Q_exp, /* i : Diff scaling factor */ - Word16 *Q_new, /* i/o: Absolute scaling factor */ - Word16 *old_speech, /* i/o: Speech memory */ - Word16 *mem_wsp, /* i/o: wsp vector memory */ - Word32 *enrO, /* i/o: Enr mem */ - Word32 *bckr, /* i/o: Back ground_fx ener mem */ - Word32 *ave_enr, /* i/o: Ave_enr mem */ - Word32 *ave_enr2, /* i/o: Ave_enr2 mem */ - Word32 *st_fr_bands1, /* i/o: spectrum per critical bands of the previous frame */ - Word32 *st_fr_bands2, /* i/o: spectrum per critical bands 2 frames ago */ - Word32 *st_Bin_E_old -) +Word32 Scale_mem_pre_proc( /* o : Min energy scaled */ + Word16 ini_frame_fx, /* i : Frame number */ + Word16 Q_exp, /* i : Diff scaling factor */ + Word16 *Q_new, /* i/o: Absolute scaling factor */ + Word16 *old_speech, /* i/o: Speech memory */ + Word16 *mem_wsp, /* i/o: wsp vector memory */ + Word32 *enrO, /* i/o: Enr mem */ + Word32 *bckr, /* i/o: Back ground_fx ener mem */ + Word32 *ave_enr, /* i/o: Ave_enr mem */ + Word32 *ave_enr2, /* i/o: Ave_enr2 mem */ + Word32 *st_fr_bands1, /* i/o: spectrum per critical bands of the previous frame */ + Word32 *st_fr_bands2, /* i/o: spectrum per critical bands 2 frames ago */ + Word32 *st_Bin_E_old ) { Word16 i; Word32 e_min_scaled; @@ -229,50 +228,50 @@ Word32 Scale_mem_pre_proc( /* o : Min energy scaled * Flag Overflow = 0; #endif - e_min_scaled = L_shr_r(L_add(L_shr(E_MIN_FXQ15,sub(14,add(*Q_new,QSCALE))),1),1); + e_min_scaled = L_shr_r( L_add( L_shr( E_MIN_FXQ15, sub( 14, add( *Q_new, QSCALE ) ) ), 1 ), 1 ); /* scale previous samples and memory (Q_exp - Q_new - Q_old) */ /* Scale( x, y, z ) : shift left vector x of size y by z bits ) */ - IF (Q_exp != 0) + IF( Q_exp != 0 ) { - IF(old_speech != NULL) + IF( old_speech != NULL ) { - Scale_sig(old_speech, L_INP_MEM, Q_exp); + Scale_sig( old_speech, L_INP_MEM, Q_exp ); } - Scale_sig(mem_wsp, 1, Q_exp); - IF( ini_frame_fx ==0 ) + Scale_sig( mem_wsp, 1, Q_exp ); + IF( ini_frame_fx == 0 ) { /* Scaling noise vectors if frame ==1*/ - Scale_sig32(enrO, NB_BANDS,*Q_new); - Scale_sig32(bckr, NB_BANDS, *Q_new); - Scale_sig32(ave_enr, NB_BANDS, *Q_new); - Scale_sig32(ave_enr2, NB_BANDS, *Q_new); - Scale_sig32(st_fr_bands1, NB_BANDS, *Q_new); - Scale_sig32(st_fr_bands2, NB_BANDS, *Q_new); - Scale_sig32(st_Bin_E_old, L_FFT/2, *Q_new); + Scale_sig32( enrO, NB_BANDS, *Q_new ); + Scale_sig32( bckr, NB_BANDS, *Q_new ); + Scale_sig32( ave_enr, NB_BANDS, *Q_new ); + Scale_sig32( ave_enr2, NB_BANDS, *Q_new ); + Scale_sig32( st_fr_bands1, NB_BANDS, *Q_new ); + Scale_sig32( st_fr_bands2, NB_BANDS, *Q_new ); + Scale_sig32( st_Bin_E_old, L_FFT / 2, *Q_new ); } ELSE { /* Do scaling and valide minimum energy value */ - FOR (i = 0; i < NB_BANDS; i++) + FOR( i = 0; i < NB_BANDS; i++ ) { #ifdef BASOP_NOGLOB - enrO[i] = L_max(L_shl_o(enrO[i], Q_exp, &Overflow),e_min_scaled); - bckr[i] = L_max(L_shl_o(bckr[i], Q_exp, &Overflow), e_min_scaled); - ave_enr[i] = L_max(L_shl_o(ave_enr[i], Q_exp, &Overflow), e_min_scaled); - ave_enr2[i] = L_max(L_shl_o(ave_enr2[i], Q_exp, &Overflow), e_min_scaled); - st_fr_bands1[i] = L_max(L_shl_o(st_fr_bands1[i], Q_exp, &Overflow), e_min_scaled); - st_fr_bands2[i] = L_max(L_shl_o(st_fr_bands2[i], Q_exp, &Overflow), e_min_scaled); + enrO[i] = L_max( L_shl_o( enrO[i], Q_exp, &Overflow ), e_min_scaled ); + bckr[i] = L_max( L_shl_o( bckr[i], Q_exp, &Overflow ), e_min_scaled ); + ave_enr[i] = L_max( L_shl_o( ave_enr[i], Q_exp, &Overflow ), e_min_scaled ); + ave_enr2[i] = L_max( L_shl_o( ave_enr2[i], Q_exp, &Overflow ), e_min_scaled ); + st_fr_bands1[i] = L_max( L_shl_o( st_fr_bands1[i], Q_exp, &Overflow ), e_min_scaled ); + st_fr_bands2[i] = L_max( L_shl_o( st_fr_bands2[i], Q_exp, &Overflow ), e_min_scaled ); #else - enrO[i] = L_max(L_shl(enrO[i], Q_exp),e_min_scaled); - bckr[i] = L_max(L_shl(bckr[i], Q_exp), e_min_scaled); - ave_enr[i] = L_max(L_shl(ave_enr[i], Q_exp), e_min_scaled); - ave_enr2[i] = L_max(L_shl(ave_enr2[i], Q_exp), e_min_scaled); - st_fr_bands1[i] = L_max(L_shl(st_fr_bands1[i], Q_exp), e_min_scaled); - st_fr_bands2[i] = L_max(L_shl(st_fr_bands2[i], Q_exp), e_min_scaled); + enrO[i] = L_max( L_shl( enrO[i], Q_exp ), e_min_scaled ); + bckr[i] = L_max( L_shl( bckr[i], Q_exp ), e_min_scaled ); + ave_enr[i] = L_max( L_shl( ave_enr[i], Q_exp ), e_min_scaled ); + ave_enr2[i] = L_max( L_shl( ave_enr2[i], Q_exp ), e_min_scaled ); + st_fr_bands1[i] = L_max( L_shl( st_fr_bands1[i], Q_exp ), e_min_scaled ); + st_fr_bands2[i] = L_max( L_shl( st_fr_bands2[i], Q_exp ), e_min_scaled ); #endif move32(); - move32(); + move32(); move32(); move32(); move32(); @@ -284,34 +283,32 @@ Word32 Scale_mem_pre_proc( /* o : Min energy scaled * } void Scale_mem_enc( - Word16 Q_exp, /* i : Diff scaling factor */ - Word16 *old_speech16k, /* i/o: Speech memory */ - Word16 *old_exc, /* i/o: excitation memory */ - Word16 *old_bwe_exc, /* i/o: BWE excitation memory */ - Word16 *mem_w0, /* i/o: target vector memory */ - Word16 *mem_syn, /* i/o: synthesis memory */ - Word16 *mem_syn2, /* i/o: synthesis memory */ + Word16 Q_exp, /* i : Diff scaling factor */ + Word16 *old_speech16k, /* i/o: Speech memory */ + Word16 *old_exc, /* i/o: excitation memory */ + Word16 *old_bwe_exc, /* i/o: BWE excitation memory */ + Word16 *mem_w0, /* i/o: target vector memory */ + Word16 *mem_syn, /* i/o: synthesis memory */ + Word16 *mem_syn2, /* i/o: synthesis memory */ Word16 *mem_deemp_preQ_fx, /*i/o: deemphasis memory for the high rate celp codec */ Word16 *last_exc_dct_in, - Word16 *old_input_lp -) + Word16 *old_input_lp ) { /* scale previous samples and memory (Q_exp - Q_new - Q_old) */ /* Scale( x, y, z ) : shift left vector x of size y by z bits ) */ - IF (Q_exp != 0) + IF( Q_exp != 0 ) { - Scale_sig(old_speech16k, L_INP_MEM, Q_exp); - Scale_sig(mem_w0, 1, Q_exp); + Scale_sig( old_speech16k, L_INP_MEM, Q_exp ); + Scale_sig( mem_w0, 1, Q_exp ); /* Scaling excitation */ - Scale_sig(old_exc,L_EXC_MEM, Q_exp); - Scale_sig(old_bwe_exc, PIT16k_MAX*2, Q_exp); - Scale_sig(mem_syn, M, Q_exp); - Scale_sig(mem_syn2, M, Q_exp); - Scale_sig(last_exc_dct_in,L_FRAME, Q_exp); - Scale_sig(mem_deemp_preQ_fx, 1, Q_exp); - Scale_sig(old_input_lp, NS2SA(16000, ACELP_LOOK_NS + DELAY_SWB_TBE_16k_NS + DELAY_FIR_RESAMPL_NS), Q_exp); + Scale_sig( old_exc, L_EXC_MEM, Q_exp ); + Scale_sig( old_bwe_exc, PIT16k_MAX * 2, Q_exp ); + Scale_sig( mem_syn, M, Q_exp ); + Scale_sig( mem_syn2, M, Q_exp ); + Scale_sig( last_exc_dct_in, L_FRAME, Q_exp ); + Scale_sig( mem_deemp_preQ_fx, 1, Q_exp ); + Scale_sig( old_input_lp, NS2SA( 16000, ACELP_LOOK_NS + DELAY_SWB_TBE_16k_NS + DELAY_FIR_RESAMPL_NS ), Q_exp ); } return; } - diff --git a/lib_enc/set_impulse_fx.c b/lib_enc/set_impulse_fx.c index fdc92195d..a145e42d6 100644 --- a/lib_enc/set_impulse_fx.c +++ b/lib_enc/set_impulse_fx.c @@ -4,12 +4,12 @@ #include #include "options.h" #include "cnst.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ +#include "rom_com_fx.h" /* Static table prototypes */ #include "rom_com.h" /* Static table prototypes */ //#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*-----------------------------------------------------------------* * Local constant @@ -19,9 +19,9 @@ /*-----------------------------------------------------------------* * Local function prototypes *-----------------------------------------------------------------*/ -static void convolve_tc_fx(const Word16 g[],const Word16 h[],Word16 y[],const Word16 L_1,const Word16 L_2); -static void correlate_tc_fx(const Word16 *x, Word16 *y, const Word16 *h, const Word16 start, const Word16 L_1,const Word16 L_2); -static void convolve_tc2_fx(const Word16 g[],const Word16 h[], Word16 y[], const Word16 pos_max); +static void convolve_tc_fx( const Word16 g[], const Word16 h[], Word16 y[], const Word16 L_1, const Word16 L_2 ); +static void correlate_tc_fx( const Word16 *x, Word16 *y, const Word16 *h, const Word16 start, const Word16 L_1, const Word16 L_2 ); +static void convolve_tc2_fx( const Word16 g[], const Word16 h[], Word16 y[], const Word16 pos_max ); /*---------------------------------------------------------------------------------------* * Function set_impulse() for TC * @@ -48,23 +48,23 @@ static void convolve_tc2_fx(const Word16 g[],const Word16 h[], Word16 y[], const * * *---------------------------------------------------------------------------------------*/ void set_impulse_fx( - const Word16 xn_fx[], /* i : target signal */ - const Word16 h_orig_fx[], /* i : impulse response of weighted synthesis filter */ - Word16 exc_fx[], /* o : adaptive codebook excitation */ - Word16 yy1_fx[], /* o : filtered adaptive codebook excitation */ - Word16 *imp_shape, /* o : adaptive codebook index */ - Word16 *imp_pos, /* o : position of the glottal impulse center index */ - Word32 *gain_trans_fx, /* o : transition gain Q7 */ - Word16 Q_new /* i : Current scaling */ + const Word16 xn_fx[], /* i : target signal */ + const Word16 h_orig_fx[], /* i : impulse response of weighted synthesis filter */ + Word16 exc_fx[], /* o : adaptive codebook excitation */ + Word16 yy1_fx[], /* o : filtered adaptive codebook excitation */ + Word16 *imp_shape, /* o : adaptive codebook index */ + Word16 *imp_pos, /* o : position of the glottal impulse center index */ + Word32 *gain_trans_fx, /* o : transition gain Q7 */ + Word16 Q_new /* i : Current scaling */ ) { Word16 i, j, m; Word16 start1, start2, end1; - Word32 rr_fx[L_SUBFR]; /* criterion: nominator coefficients */ - Word16 dd_fx[L_SUBFR],tmp16; /* criterion: denominator coefficients */ - Word16 gh_fx[L_SUBFR], num, den, exp_num, exp_den; /* convolution of 'g' and 'h' filters */ + Word32 rr_fx[L_SUBFR]; /* criterion: nominator coefficients */ + Word16 dd_fx[L_SUBFR], tmp16; /* criterion: denominator coefficients */ + Word16 gh_fx[L_SUBFR], num, den, exp_num, exp_den; /* convolution of 'g' and 'h' filters */ Word16 krit_fx, krit_max_fx, gain16; - Word32 Lrr, Ldd, Ltmp,Ltmp1; + Word32 Lrr, Ldd, Ltmp, Ltmp1; const Word16 *pt_Glt; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; @@ -74,28 +74,28 @@ void set_impulse_fx( /* main loop */ /* impulse */ - FOR (m = 0; m < NUM_IMPULSE; m++) + FOR( m = 0; m < NUM_IMPULSE; m++ ) { /* set searching ranges */ - IF (LT_16(*imp_pos, L_SUBFR-INPOL)) + IF( LT_16( *imp_pos, L_SUBFR - INPOL ) ) { - end1 = add(*imp_pos, INPOL); + end1 = add( *imp_pos, INPOL ); } ELSE { end1 = L_SUBFR; move16(); } - IF (GT_16(*imp_pos, INPOL)) + IF( GT_16( *imp_pos, INPOL ) ) { - start1 = sub(*imp_pos, INPOL); + start1 = sub( *imp_pos, INPOL ); } ELSE { start1 = 0; move16(); } - IF (GT_16(start1, L_IMPULSE2)) + IF( GT_16( start1, L_IMPULSE2 ) ) { start2 = start1; move16(); @@ -109,130 +109,130 @@ void set_impulse_fx( /*-----------------------------------------------------------* * nominator & DEnominator, gh=convolve(g,h) *-----------------------------------------------------------*/ - IF (LT_16(start1, L_IMPULSE2)) + IF( LT_16( start1, L_IMPULSE2 ) ) { - Lrr = L_deposit_l(0); - Ldd = L_deposit_l(0); - convolve_tc_fx(&Glottal_cdbk_fx[m*L_IMPULSE+L_IMPULSE2-start1], - &h_orig_fx[0], gh_fx, add(L_IMPULSE-L_IMPULSE2, start1), L_SUBFR); + Lrr = L_deposit_l( 0 ); + Ldd = L_deposit_l( 0 ); + convolve_tc_fx( &Glottal_cdbk_fx[m * L_IMPULSE + L_IMPULSE2 - start1], + &h_orig_fx[0], gh_fx, add( L_IMPULSE - L_IMPULSE2, start1 ), L_SUBFR ); /* nominator & DEnominator row <0> */ - FOR (i=0; i < L_SUBFR; i++) + FOR( i = 0; i < L_SUBFR; i++ ) { #ifdef BASOP_NOGLOB - Lrr = L_mac_o(Lrr, gh_fx[i], gh_fx[i], &Overflow); - Ldd = L_mac_o(Ldd, gh_fx[i], xn_fx[i], &Overflow); + Lrr = L_mac_o( Lrr, gh_fx[i], gh_fx[i], &Overflow ); + Ldd = L_mac_o( Ldd, gh_fx[i], xn_fx[i], &Overflow ); #else - Lrr = L_mac(Lrr, gh_fx[i], gh_fx[i]); - Ldd = L_mac(Ldd, gh_fx[i], xn_fx[i]); + Lrr = L_mac( Lrr, gh_fx[i], gh_fx[i] ); + Ldd = L_mac( Ldd, gh_fx[i], xn_fx[i] ); #endif } rr_fx[start1] = Lrr; move32(); #ifdef BASOP_NOGLOB - dd_fx[start1] = round_fx_o(Ldd, &Overflow); + dd_fx[start1] = round_fx_o( Ldd, &Overflow ); #else - dd_fx[start1] = round_fx(Ldd); + dd_fx[start1] = round_fx( Ldd ); #endif - rr_fx[start1] = L_max(rr_fx[start1], 1); + rr_fx[start1] = L_max( rr_fx[start1], 1 ); - FOR (i=add(start1, 1); i */ - FOR (j = L_SUBFR-1; j > 0; j--) + FOR( j = L_SUBFR - 1; j > 0; j-- ) { /* gh_fx[j] = gh_fx[j-1] + glottal_cdbk[m*L_IMPULSE+L_IMPULSE2-i]*h_orig_fx[j] */ - gh_fx[j] = mac_r(L_deposit_h(gh_fx[j-1]), - Glottal_cdbk_fx[m*L_IMPULSE+L_IMPULSE2-i], h_orig_fx[j]); + gh_fx[j] = mac_r( L_deposit_h( gh_fx[j - 1] ), + Glottal_cdbk_fx[m * L_IMPULSE + L_IMPULSE2 - i], h_orig_fx[j] ); move16(); #ifdef BASOP_NOGLOB - Lrr = L_mac_o(Lrr, gh_fx[j], gh_fx[j], &Overflow); - Ldd = L_mac_o(Ldd, gh_fx[j], xn_fx[j], &Overflow); -#else /* BASOP_NOGLOB */ - Lrr = L_mac(Lrr, gh_fx[j], gh_fx[j]); - Ldd = L_mac(Ldd, gh_fx[j], xn_fx[j]); + Lrr = L_mac_o( Lrr, gh_fx[j], gh_fx[j], &Overflow ); + Ldd = L_mac_o( Ldd, gh_fx[j], xn_fx[j], &Overflow ); +#else /* BASOP_NOGLOB */ + Lrr = L_mac( Lrr, gh_fx[j], gh_fx[j] ); + Ldd = L_mac( Ldd, gh_fx[j], xn_fx[j] ); #endif /* BASOP_NOGLOB */ } - gh_fx[0] = mult_r(Glottal_cdbk_fx[m*L_IMPULSE+L_IMPULSE2-i],h_orig_fx[0]); + gh_fx[0] = mult_r( Glottal_cdbk_fx[m * L_IMPULSE + L_IMPULSE2 - i], h_orig_fx[0] ); move16(); #ifdef BASOP_NOGLOB - Lrr = L_mac_o(Lrr, gh_fx[0], gh_fx[0], &Overflow); - Ldd = L_mac_o(Ldd, gh_fx[0], xn_fx[0], &Overflow); + Lrr = L_mac_o( Lrr, gh_fx[0], gh_fx[0], &Overflow ); + Ldd = L_mac_o( Ldd, gh_fx[0], xn_fx[0], &Overflow ); dd_fx[i] = round_fx_sat( Ldd ); #else /* BASOP_NOGLOB */ - Lrr = L_mac(Lrr, gh_fx[0], gh_fx[0]); - Ldd = L_mac(Ldd, gh_fx[0], xn_fx[0]); + Lrr = L_mac( Lrr, gh_fx[0], gh_fx[0] ); + Ldd = L_mac( Ldd, gh_fx[0], xn_fx[0] ); dd_fx[i] = round_fx( Ldd ); #endif - rr_fx[i] = L_max(Lrr, 1); + rr_fx[i] = L_max( Lrr, 1 ); move32(); /* move rr and dd into rr[i] and dd[i] */ } /* complete convolution(excitation,h_orig) */ - FOR (j=L_SUBFR-1; j > 0; j--) + FOR( j = L_SUBFR - 1; j > 0; j-- ) { - gh_fx[j] = mac_r(L_deposit_h(gh_fx[j-1]), - Glottal_cdbk_fx[m*L_IMPULSE], h_orig_fx[j]); + gh_fx[j] = mac_r( L_deposit_h( gh_fx[j - 1] ), + Glottal_cdbk_fx[m * L_IMPULSE], h_orig_fx[j] ); } } ELSE { - convolve_tc_fx(&Glottal_cdbk_fx[m*L_IMPULSE], h_orig_fx, gh_fx, L_IMPULSE, L_SUBFR); + convolve_tc_fx( &Glottal_cdbk_fx[m * L_IMPULSE], h_orig_fx, gh_fx, L_IMPULSE, L_SUBFR ); } - IF (GE_16(end1, start2)) + IF( GE_16( end1, start2 ) ) { /* DEnominator row */ - Lrr = L_mult(gh_fx[0], gh_fx[0]); - FOR (j=1; j <= L_IMPULSE2; j++) + Lrr = L_mult( gh_fx[0], gh_fx[0] ); + FOR( j = 1; j <= L_IMPULSE2; j++ ) { /*rr[L_SUBFR-1] += gh[j]*gh[j];*/ - Lrr = L_mac(Lrr, gh_fx[j], gh_fx[j]); + Lrr = L_mac( Lrr, gh_fx[j], gh_fx[j] ); } - rr_fx[L_SUBFR-1] = Lrr; + rr_fx[L_SUBFR - 1] = Lrr; move32(); /* DEnominator rows */ - FOR (i = L_SUBFR-2; i >= start2; i--) + FOR( i = L_SUBFR - 2; i >= start2; i-- ) { /*rr[i] = rr[i+1] + gh[L_SUBFR+L_IMPULSE2-1-i]*gh[L_SUBFR+L_IMPULSE2-1-i];*/ #ifdef BASOP_NOGLOB - rr_fx[i] = L_mac_o(rr_fx[i+1], gh_fx[L_SUBFR+L_IMPULSE2-1-i], - gh_fx[L_SUBFR+L_IMPULSE2-1-i], &Overflow); + rr_fx[i] = L_mac_o( rr_fx[i + 1], gh_fx[L_SUBFR + L_IMPULSE2 - 1 - i], + gh_fx[L_SUBFR + L_IMPULSE2 - 1 - i], &Overflow ); #else - rr_fx[i] = L_mac(rr_fx[i+1], gh_fx[L_SUBFR+L_IMPULSE2-1-i], - gh_fx[L_SUBFR+L_IMPULSE2-1-i]); + rr_fx[i] = L_mac( rr_fx[i + 1], gh_fx[L_SUBFR + L_IMPULSE2 - 1 - i], + gh_fx[L_SUBFR + L_IMPULSE2 - 1 - i] ); #endif move32(); } /* nominator rows */ - correlate_tc_fx(xn_fx, &dd_fx[L_IMPULSE2], gh_fx, sub(start2, L_IMPULSE2), - L_SUBFR, sub(end1, L_IMPULSE2)); + correlate_tc_fx( xn_fx, &dd_fx[L_IMPULSE2], gh_fx, sub( start2, L_IMPULSE2 ), + L_SUBFR, sub( end1, L_IMPULSE2 ) ); } /*------------------------------------------------------------* * maxim. criterion *------------------------------------------------------------*/ - FOR (i = start1; i < end1; i++) + FOR( i = start1; i < end1; i++ ) { /* krit = (float)(dd[i]*dd[i])/rr[i] */ - exp_num = sub(norm_s(dd_fx[i]), 1); - num = shl(dd_fx[i], exp_num); - num = mult_r(num, num); + exp_num = sub( norm_s( dd_fx[i] ), 1 ); + num = shl( dd_fx[i], exp_num ); + num = mult_r( num, num ); - exp_den = norm_l(rr_fx[i]); - den = extract_h(L_shl(rr_fx[i], exp_den)); + exp_den = norm_l( rr_fx[i] ); + den = extract_h( L_shl( rr_fx[i], exp_den ) ); - num = div_s(num,den); + num = div_s( num, den ); #ifdef BASOP_NOGLOB - krit_fx = shr_o(num, sub(sub(shl_o(exp_num, 1, &Overflow), exp_den), 2), &Overflow); /* Q18 */ + krit_fx = shr_o( num, sub( sub( shl_o( exp_num, 1, &Overflow ), exp_den ), 2 ), &Overflow ); /* Q18 */ #else - krit_fx = shr(num, sub(sub(shl(exp_num, 1), exp_den), 2)); /* Q18 */ + krit_fx = shr( num, sub( sub( shl( exp_num, 1 ), exp_den ), 2 ) ); /* Q18 */ #endif - IF (GT_16(krit_fx, krit_max_fx)) + IF( GT_16( krit_fx, krit_max_fx ) ) { krit_max_fx = krit_fx; move16(); @@ -248,50 +248,49 @@ void set_impulse_fx( * Build the excitation using found codeword *---------------------------------------------------------------*/ - set16_fx(exc_fx, 0, L_SUBFR); - set16_fx(yy1_fx, 0, L_SUBFR); - tmp16 = sub(extract_l(L_mac0(L_IMPULSE2, *imp_shape, L_IMPULSE)), *imp_pos); + set16_fx( exc_fx, 0, L_SUBFR ); + set16_fx( yy1_fx, 0, L_SUBFR ); + tmp16 = sub( extract_l( L_mac0( L_IMPULSE2, *imp_shape, L_IMPULSE ) ), *imp_pos ); pt_Glt = &Glottal_cdbk_fx[tmp16]; move16(); - j = add(*imp_pos, L_IMPULSE2); - FOR (i = sub(*imp_pos, L_IMPULSE2); i <= j; i++) + j = add( *imp_pos, L_IMPULSE2 ); + FOR( i = sub( *imp_pos, L_IMPULSE2 ); i <= j; i++ ) { test(); - if (i >= 0 && LT_16(i, L_SUBFR)) + if ( i >= 0 && LT_16( i, L_SUBFR ) ) { exc_fx[i] = pt_Glt[i]; - move16();/*Q13*/ + move16(); /*Q13*/ } } /*---------------------------------------------------------------* * Form filtered excitation, find gain_trans *---------------------------------------------------------------*/ - convolve_tc2_fx(exc_fx, h_orig_fx, yy1_fx, *imp_pos); + convolve_tc2_fx( exc_fx, h_orig_fx, yy1_fx, *imp_pos ); /* Find the ACELP correlations and the pitch gain (for current subframe) */ /**gain_trans = dot_product( xn, yy1, L_SUBFR )/(dot_product( yy1, yy1, L_SUBFR ) + 0.01f);*/ /* Compute scalar product */ - Ltmp = Dot_product(yy1_fx, yy1_fx, L_SUBFR); - exp_den = norm_l(Ltmp); - den = extract_h(L_shl(Ltmp, exp_den)); + Ltmp = Dot_product( yy1_fx, yy1_fx, L_SUBFR ); + exp_den = norm_l( Ltmp ); + den = extract_h( L_shl( Ltmp, exp_den ) ); /* Compute scalar product */ - Ltmp1 = Dot_product(xn_fx, yy1_fx, L_SUBFR); - exp_num = sub(norm_l(Ltmp1), 1); - num = extract_h(L_shl(Ltmp1, exp_num)); - tmp16 = s_or(shr(num, 16), 1); /* extract sign if num < 0 tmp16 = -1 else tmp16 = 1 */ - num = abs_s(num); + Ltmp1 = Dot_product( xn_fx, yy1_fx, L_SUBFR ); + exp_num = sub( norm_l( Ltmp1 ), 1 ); + num = extract_h( L_shl( Ltmp1, exp_num ) ); + tmp16 = s_or( shr( num, 16 ), 1 ); /* extract sign if num < 0 tmp16 = -1 else tmp16 = 1 */ + num = abs_s( num ); /* compute gain = xy/yy */ - gain16= div_s(num, den); + gain16 = div_s( num, den ); - i = add(exp_num, sub(Q_new, 1+1+3)); - i = sub(i, exp_den); /* Gain_trans in Q7 */ - gain16 = i_mult2(gain16, tmp16);/* apply sign */ - *gain_trans_fx = L_shr(L_deposit_l(gain16), i); + i = add( exp_num, sub( Q_new, 1 + 1 + 3 ) ); + i = sub( i, exp_den ); /* Gain_trans in Q7 */ + gain16 = i_mult2( gain16, tmp16 ); /* apply sign */ + *gain_trans_fx = L_shr( L_deposit_l( gain16 ), i ); move32(); - } /*-------------------------------------------------------------------* * convolve_tc_fx: @@ -299,26 +298,26 @@ void set_impulse_fx( * convolution for different vectors' lengths *-------------------------------------------------------------------*/ static void convolve_tc_fx( - const Word16 g[], /* i : input vector Qx */ - const Word16 h[], /* i : impulse response (or second input vector) Q15 */ - Word16 y[], /* o : output vector (result of convolution) 12 bits */ - const Word16 L_1, /* i : vector h size */ - const Word16 L_2 /* i : vector g size */ + const Word16 g[], /* i : input vector Qx */ + const Word16 h[], /* i : impulse response (or second input vector) Q15 */ + Word16 y[], /* o : output vector (result of convolution) 12 bits */ + const Word16 L_1, /* i : vector h size */ + const Word16 L_2 /* i : vector g size */ ) { Word16 i, n, len; Word32 L_sum; - FOR (n = 0; n < L_2; n++) + FOR( n = 0; n < L_2; n++ ) { - len = s_min(add(n,1), L_1); - L_sum = L_mult(g[0], h[n]); - FOR (i = 1; i < len; i++) + len = s_min( add( n, 1 ), L_1 ); + L_sum = L_mult( g[0], h[n] ); + FOR( i = 1; i < len; i++ ) { - L_sum = L_mac(L_sum, g[i], h[n - i]); + L_sum = L_mac( L_sum, g[i], h[n - i] ); } - y[n] = round_fx(L_sum); /* Q12*/ + y[n] = round_fx( L_sum ); /* Q12*/ } } /*-------------------------------------------------------------------* @@ -327,32 +326,32 @@ static void convolve_tc_fx( * convolution for one vector with only L_IMPULSE nonzero coefficients *-------------------------------------------------------------------*/ static void convolve_tc2_fx( - const Word16 g[], /* i : input vector Qx */ - const Word16 h[], /* i : impulse response (or second input vector) Q15 */ - Word16 y[], /* o : output vector (result of convolution) 12 bits */ - const Word16 pos_max /* o : artificial impulse position */ + const Word16 g[], /* i : input vector Qx */ + const Word16 h[], /* i : impulse response (or second input vector) Q15 */ + Word16 y[], /* o : output vector (result of convolution) 12 bits */ + const Word16 pos_max /* o : artificial impulse position */ ) { Word32 temp; Word16 i, n; Word16 i_start, i_end, i_end2; - i_start = sub(pos_max,L_IMPULSE2); - i_start = s_max(i_start, 0); + i_start = sub( pos_max, L_IMPULSE2 ); + i_start = s_max( i_start, 0 ); - i_end = add(pos_max, L_IMPULSE); - i_end = s_min(i_end, L_SUBFR); + i_end = add( pos_max, L_IMPULSE ); + i_end = s_min( i_end, L_SUBFR ); - FOR (n = i_start; n < L_SUBFR; n++) + FOR( n = i_start; n < L_SUBFR; n++ ) { - temp = L_mult(g[0], h[n]); - i_end2 = s_min(add(n, 1), i_end); + temp = L_mult( g[0], h[n] ); + i_end2 = s_min( add( n, 1 ), i_end ); - FOR (i = 1; i < i_end2; i++) + FOR( i = 1; i < i_end2; i++ ) { - temp = L_mac(temp, g[i], h[n-i]); + temp = L_mac( temp, g[i], h[n - i] ); } - y[n] = round_fx(temp); + y[n] = round_fx( temp ); } } /*-------------------------------------------------------------------* @@ -361,21 +360,21 @@ static void convolve_tc2_fx( * correlation for different vectors' lengths *-------------------------------------------------------------------*/ static void correlate_tc_fx( - const Word16 *x, /* i: target signal */ - Word16 *y, /* o: correlation between x[] and h[] -Q3 */ - const Word16 *h, /* i: impulse response (of weighted synthesis filter) */ - const Word16 start, /* i: index of iterest */ - const Word16 L_1, /* i: vector size */ - const Word16 L_2 /* i: index of interest */ + const Word16 *x, /* i: target signal */ + Word16 *y, /* o: correlation between x[] and h[] -Q3 */ + const Word16 *h, /* i: impulse response (of weighted synthesis filter) */ + const Word16 start, /* i: index of iterest */ + const Word16 L_1, /* i: vector size */ + const Word16 L_2 /* i: index of interest */ ) { Word16 i, j; Word32 s; - FOR (i = start; i < L_2; i++) + FOR( i = start; i < L_2; i++ ) { - s = L_deposit_l(0); - FOR (j = i; j < L_1; j++) + s = L_deposit_l( 0 ); + FOR( j = i; j < L_1; j++ ) { #ifdef BASOP_NOGLOB s = L_mac_sat( s, x[j], h[j - i] ); @@ -389,5 +388,4 @@ static void correlate_tc_fx( y[i] = round_fx( s ); #endif } - } diff --git a/lib_enc/setmodeindex_fx.c b/lib_enc/setmodeindex_fx.c index 48925697b..7920db3e2 100644 --- a/lib_enc/setmodeindex_fx.c +++ b/lib_enc/setmodeindex_fx.c @@ -8,9 +8,9 @@ #include "cnst.h" #include "rom_com_fx.h" #include "rom_enc.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*--------------------------------------------------------------------------- @@ -27,33 +27,33 @@ void SetModeIndex_fx( Word32 last_total_brate, const Word16 last_element_mode, const Word16 is_mct, - const Word16 shift -) + const Word16 shift ) { Word16 ini_frame_loc = st->ini_frame; - test();test(); - if (EQ_16(st->element_mode, IVAS_CPE_MDCT) && EQ_16(last_element_mode, IVAS_CPE_MDCT) && EQ_16(st->idchan, 1)) + test(); + test(); + if ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( last_element_mode, IVAS_CPE_MDCT ) && EQ_16( st->idchan, 1 ) ) { st->ini_frame = 0; move16(); } /* Reconfigure the core coder */ - test();test();test(); + test(); + test(); + test(); IF( - (NE_32(last_total_brate,st->total_brate) ) || - (NE_16(st->last_bwidth,st->bwidth) ) || - (EQ_16(st->last_codec_mode,MODE1) && EQ_16(st->element_mode, EVS_MONO) ) || - ( (NE_16(st->last_core, TCX_20_CORE) && NE_16(st->last_core, TCX_10_CORE)) && GT_16(st->element_mode, EVS_MONO)) || - (NE_16(st->rf_mode_last,st->rf_mode) ) || - (GT_16(st->element_mode, EVS_MONO) && st->ini_frame == 0) - ) + ( NE_32( last_total_brate, st->total_brate ) ) || + ( NE_16( st->last_bwidth, st->bwidth ) ) || + ( EQ_16( st->last_codec_mode, MODE1 ) && EQ_16( st->element_mode, EVS_MONO ) ) || + ( ( NE_16( st->last_core, TCX_20_CORE ) && NE_16( st->last_core, TCX_10_CORE ) ) && GT_16( st->element_mode, EVS_MONO ) ) || + ( NE_16( st->rf_mode_last, st->rf_mode ) ) || + ( GT_16( st->element_mode, EVS_MONO ) && st->ini_frame == 0 ) ) { - core_coder_mode_switch_fx( st, last_total_brate, is_mct, shift); + core_coder_mode_switch_fx( st, last_total_brate, is_mct, shift ); } st->ini_frame = ini_frame_loc; return; } - \ No newline at end of file diff --git a/lib_enc/sig_clas_fx.c b/lib_enc/sig_clas_fx.c index 95ea8bbc5..62f732939 100644 --- a/lib_enc/sig_clas_fx.c +++ b/lib_enc/sig_clas_fx.c @@ -3,38 +3,38 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ //#include "prot_fx.h" /* Function prototypes */ #include "rom_com.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*---------------------------------------------------------------------* * Local constants *---------------------------------------------------------------------*/ -#define K_COR_FX 23405 /* Q13 2.857 */ -#define C_COR_FX -10535 /* Q13 -1.286 */ +#define K_COR_FX 23405 /* Q13 2.857 */ +#define C_COR_FX -10535 /* Q13 -1.286 */ -#define K_EE_FX 1365 /* Q15 0.04167 */ -#define C_EE_FX 0 +#define K_EE_FX 1365 /* Q15 0.04167 */ +#define C_EE_FX 0 -#define K_ZC_FX -1311 /* Q15 -0.04 */ -#define C_ZC_FX 19661 /* Q13 2.4 */ +#define K_ZC_FX -1311 /* Q15 -0.04 */ +#define C_ZC_FX 19661 /* Q13 2.4 */ -#define K_RELE_FX 1638 /* Q15 0.05 */ -#define C_RELE_FX 14746 /* Q15 0.45 */ +#define K_RELE_FX 1638 /* Q15 0.05 */ +#define C_RELE_FX 14746 /* Q15 0.45 */ -#define K_PC_FX -2341 /* Q15 -0.07143*/ -#define C_PC_FX 30425 /* Q1 1.857 */ +#define K_PC_FX -2341 /* Q15 -0.07143*/ +#define C_PC_FX 30425 /* Q1 1.857 */ -#define K_SNR_FX 3541 /* Q15 .1111 */ -#define C_SNR_FX -10921 /* Q15 -0.3333f */ +#define K_SNR_FX 3541 /* Q15 .1111 */ +#define C_SNR_FX -10921 /* Q15 -0.3333f */ -#define THRES_EEN 514206 /* 251.077 => (10^(1/(K_EE*10))) Q11*/ +#define THRES_EEN 514206 /* 251.077 => (10^(1/(K_EE*10))) Q11*/ /*-------------------------------------------------------------------* * signal_clas_fx() @@ -43,20 +43,20 @@ * TC frames selection *-------------------------------------------------------------------*/ -Word16 signal_clas_fx( /* o : classification for current frames */ - Encoder_State* st, /* i/o: encoder state structure */ - const Word16* speech, /* i : pointer to speech signal for E computation */ - const Word32* ee, /* i : lf/hf E ration for 2 half-frames */ - const Word16 relE, /* i : frame relative E to the long term average */ - const Word16 L_look, /* i : look-ahead */ - Word16* clas_mod /* o : class flag for NOOP detection */ +Word16 signal_clas_fx( /* o : classification for current frames */ + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 *speech, /* i : pointer to speech signal for E computation */ + const Word32 *ee, /* i : lf/hf E ration for 2 half-frames */ + const Word16 relE, /* i : frame relative E to the long term average */ + const Word16 L_look, /* i : look-ahead */ + Word16 *clas_mod /* o : class flag for NOOP detection */ ) { Word32 Ltmp; Word16 mean_voi2, een, corn, zcn, relEn, pcn, fmerit1; Word16 i, clas, pc, zc, lo, lo2, hi, hi2, exp_ee, frac_ee; Word16 tmp16, tmpS; - const Word16* pt1; + const Word16 *pt1; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif @@ -68,23 +68,23 @@ Word16 signal_clas_fx( /* o : classification for current frames * Calculate pitch stability *----------------------------------------------------------------*/ - /* average voicing on second half-frame and look-ahead */ - Ltmp = L_mult(st->voicing_fx[1], 16384); - mean_voi2 = mac_r(Ltmp, st->voicing_fx[2], 16384); + /* average voicing on second half-frame and look-ahead */ + Ltmp = L_mult( st->voicing_fx[1], 16384 ); + mean_voi2 = mac_r( Ltmp, st->voicing_fx[2], 16384 ); /* average spectral tilt in dB */ - lo = L_Extract_lc(ee[0], &hi); - lo2 = L_Extract_lc(ee[1], &hi2); - Ltmp = L_mult(lo, lo2); /* Q5*Q5->Q11 */ + lo = L_Extract_lc( ee[0], &hi ); + lo2 = L_Extract_lc( ee[1], &hi2 ); + Ltmp = L_mult( lo, lo2 ); /* Q5*Q5->Q11 */ test(); test(); - IF(LT_32(Ltmp, 2048)) + IF( LT_32( Ltmp, 2048 ) ) { een = 0; move16(); } - ELSE IF(GT_32(Ltmp, THRES_EEN) || hi > 0 || hi2 > 0) + ELSE IF( GT_32( Ltmp, THRES_EEN ) || hi > 0 || hi2 > 0 ) { een = 512; move16(); @@ -93,29 +93,29 @@ Word16 signal_clas_fx( /* o : classification for current frames { /* mean_ee2 = 0.5f * 20.0f * (float)log10( tmp ); */ /* een = K_EE_ENC * mean_ee2 + C_EE_ENC; */ - exp_ee = norm_l(Ltmp); - frac_ee = Log2_norm_lc(L_shl(Ltmp, exp_ee)); - exp_ee = sub(30 - 11, exp_ee); - Ltmp = Mpy_32_16(exp_ee, frac_ee, LG10); /* Ltmp Q14 */ - een = round_fx(L_shl(Ltmp, 16 - 5)); /* Q14 -> Q9 */ - een = mac_r(C_EE_FX, een, K_EE_FX); + exp_ee = norm_l( Ltmp ); + frac_ee = Log2_norm_lc( L_shl( Ltmp, exp_ee ) ); + exp_ee = sub( 30 - 11, exp_ee ); + Ltmp = Mpy_32_16( exp_ee, frac_ee, LG10 ); /* Ltmp Q14 */ + een = round_fx( L_shl( Ltmp, 16 - 5 ) ); /* Q14 -> Q9 */ + een = mac_r( C_EE_FX, een, K_EE_FX ); } - /* compute zero crossing rate */ + /* compute zero crossing rate */ pt1 = speech + L_look - 1; - tmpS = shr(*pt1, 15); /* sets 'tmpS to -1 if *pt1 < 0 */ - Ltmp = L_deposit_l(0); - FOR(i = 0; i < L_FRAME; i++) + tmpS = shr( *pt1, 15 ); /* sets 'tmpS to -1 if *pt1 < 0 */ + Ltmp = L_deposit_l( 0 ); + FOR( i = 0; i < L_FRAME; i++ ) { - tmp16 = add(1, tmpS); + tmp16 = add( 1, tmpS ); pt1++; - tmpS = shr(*pt1, 15); /* pt1 >=0 ---> 0 OTHERWISE -1 */ - Ltmp = L_msu0(Ltmp, tmpS, tmp16); + tmpS = shr( *pt1, 15 ); /* pt1 >=0 ---> 0 OTHERWISE -1 */ + Ltmp = L_msu0( Ltmp, tmpS, tmp16 ); } - zc = extract_l(Ltmp); + zc = extract_l( Ltmp ); /* compute pitch stability */ - pc = add(abs_s(sub(st->pitch_fx[1], st->pitch_fx[0])), abs_s(sub(st->pitch_fx[2], st->pitch_fx[1]))); + pc = add( abs_s( sub( st->pitch_fx[1], st->pitch_fx[0] ) ), abs_s( sub( st->pitch_fx[2], st->pitch_fx[1] ) ) ); st->tdm_pc = pc; /*-----------------------------------------------------------------* @@ -123,55 +123,55 @@ Word16 signal_clas_fx( /* o : classification for current frames * Compute the merit function *-----------------------------------------------------------------*/ - /* corn = K_COR * mean_voi2 + C_COR */ - Ltmp = L_mult(C_COR_FX, 32767); - corn = round_fx(L_shl(L_mac(Ltmp, mean_voi2, K_COR_FX), -4)); /*Q13+Q13*Q15 =>Q13->Q9*/ + /* corn = K_COR * mean_voi2 + C_COR */ + Ltmp = L_mult( C_COR_FX, 32767 ); + corn = round_fx( L_shl( L_mac( Ltmp, mean_voi2, K_COR_FX ), -4 ) ); /*Q13+Q13*Q15 =>Q13->Q9*/ /* Limit [0, 1] */ - corn = s_max(corn, 0); - corn = s_min(corn, 512); + corn = s_max( corn, 0 ); + corn = s_min( corn, 512 ); - Ltmp = L_mult(C_ZC_FX, 4); /*Q13*Q2 -> Q16*/ - zcn = round_fx(L_shl(L_mac(Ltmp, zc, K_ZC_FX), 16 - 7)); /*Q0*Q15 + Q16*/ + Ltmp = L_mult( C_ZC_FX, 4 ); /*Q13*Q2 -> Q16*/ + zcn = round_fx( L_shl( L_mac( Ltmp, zc, K_ZC_FX ), 16 - 7 ) ); /*Q0*Q15 + Q16*/ /* Limit [0, 1] */ - zcn = s_max(zcn, 0); - zcn = s_min(zcn, 512); + zcn = s_max( zcn, 0 ); + zcn = s_min( zcn, 512 ); - Ltmp = L_mult(C_RELE_FX, 256); /*Q15 ->Q24*/ - relEn = round_fx(L_shl(L_mac(Ltmp, relE, K_RELE_FX), 1)); /*relE in Q8 but relEn in Q9*/ + Ltmp = L_mult( C_RELE_FX, 256 ); /*Q15 ->Q24*/ + relEn = round_fx( L_shl( L_mac( Ltmp, relE, K_RELE_FX ), 1 ) ); /*relE in Q8 but relEn in Q9*/ /* Limit [0.5, 1] */ - relEn = s_max(relEn, 256); - relEn = s_min(relEn, 512); + relEn = s_max( relEn, 256 ); + relEn = s_min( relEn, 512 ); - Ltmp = L_mult(C_PC_FX, 2); /*Q14*Q1 -> Q16*/ - pcn = round_fx(L_shl(L_mac(Ltmp, pc, K_PC_FX), 16 - 7)); /*Q16 + Q0*Q15*/ + Ltmp = L_mult( C_PC_FX, 2 ); /*Q14*Q1 -> Q16*/ + pcn = round_fx( L_shl( L_mac( Ltmp, pc, K_PC_FX ), 16 - 7 ) ); /*Q16 + Q0*Q15*/ /* Limit [0, 1] */ - pcn = s_max(pcn, 0); - pcn = s_min(pcn, 512); + pcn = s_max( pcn, 0 ); + pcn = s_min( pcn, 512 ); - Ltmp = L_mult(een, 10923); - Ltmp = L_mac(Ltmp, corn, 21845); - Ltmp = L_mac(Ltmp, zcn, 10923); - Ltmp = L_mac(Ltmp, relEn, 10923); - Ltmp = L_mac(Ltmp, pcn, 10923); + Ltmp = L_mult( een, 10923 ); + Ltmp = L_mac( Ltmp, corn, 21845 ); + Ltmp = L_mac( Ltmp, zcn, 10923 ); + Ltmp = L_mac( Ltmp, relEn, 10923 ); + Ltmp = L_mac( Ltmp, pcn, 10923 ); #ifdef BASOP_NOGLOB - fmerit1 = round_fx_o(L_shl_o(Ltmp, 16 - 10 - 1, &Overflow), &Overflow); /* fmerit1 ->Q15 */ + fmerit1 = round_fx_o( L_shl_o( Ltmp, 16 - 10 - 1, &Overflow ), &Overflow ); /* fmerit1 ->Q15 */ #else - fmerit1 = round_fx(L_shl(Ltmp, 16 - 10 - 1)); /* fmerit1 ->Q15 */ + fmerit1 = round_fx( L_shl( Ltmp, 16 - 10 - 1 ) ); /* fmerit1 ->Q15 */ #endif /*-----------------------------------------------------------------* * FEC classification *-----------------------------------------------------------------*/ - st->fmerit_dt = sub(st->prev_fmerit, fmerit1); + st->fmerit_dt = sub( st->prev_fmerit, fmerit1 ); st->prev_fmerit = fmerit1; move16(); /* FEC classification */ test(); test(); - IF(st->localVAD == 0 || EQ_16(st->coder_type, UNVOICED) || LT_16(relE, -1536)) + IF( st->localVAD == 0 || EQ_16( st->coder_type, UNVOICED ) || LT_16( relE, -1536 ) ) { clas = UNVOICED_CLAS; *clas_mod = clas; @@ -180,72 +180,72 @@ Word16 signal_clas_fx( /* o : classification for current frames } ELSE { - SWITCH(st->last_clas) + SWITCH( st->last_clas ) { - case VOICED_CLAS: - case ONSET: - case VOICED_TRANSITION: - - IF(LT_16(fmerit1, 16056)) /*0.49f*/ - { - clas = UNVOICED_CLAS; - move16(); - } - ELSE IF(LT_16(fmerit1, 21626)) /*0.66*/ - { - clas = VOICED_TRANSITION; - move16(); - } - ELSE - { - clas = VOICED_CLAS; + case VOICED_CLAS: + case ONSET: + case VOICED_TRANSITION: + + IF( LT_16( fmerit1, 16056 ) ) /*0.49f*/ + { + clas = UNVOICED_CLAS; + move16(); + } + ELSE IF( LT_16( fmerit1, 21626 ) ) /*0.66*/ + { + clas = VOICED_TRANSITION; + move16(); + } + ELSE + { + clas = VOICED_CLAS; + move16(); + } + IF( LT_16( fmerit1, 14745 /* 0.45f*/ ) ) + { + *clas_mod = UNVOICED_CLAS; + move16(); + } + ELSE IF( LT_16( fmerit1, 21626 /* 0.66f*/ ) ) + { + *clas_mod = VOICED_TRANSITION; + move16(); + } + ELSE + { + *clas_mod = VOICED_CLAS; + move16(); + } + BREAK; + + case UNVOICED_CLAS: + case UNVOICED_TRANSITION: + IF( GT_16( fmerit1, 20643 ) ) /*0.63*/ + { + clas = ONSET; + move16(); + } + ELSE IF( GT_16( fmerit1, 19169 ) ) /*0.585*/ + { + clas = UNVOICED_TRANSITION; + move16(); + } + ELSE + { + clas = UNVOICED_CLAS; + move16(); + } + *clas_mod = clas; move16(); - } - IF(LT_16(fmerit1, 14745 /* 0.45f*/)) - { - *clas_mod = UNVOICED_CLAS; - move16(); - } - ELSE IF(LT_16(fmerit1, 21626 /* 0.66f*/)) - { - *clas_mod = VOICED_TRANSITION; - move16(); - } - ELSE - { - *clas_mod = VOICED_CLAS; - move16(); - } - BREAK; - case UNVOICED_CLAS: - case UNVOICED_TRANSITION: - IF(GT_16(fmerit1, 20643)) /*0.63*/ - { - clas = ONSET; - move16(); - } - ELSE IF(GT_16(fmerit1, 19169)) /*0.585*/ - { - clas = UNVOICED_TRANSITION; - move16(); - } - ELSE - { + BREAK; + + default: clas = UNVOICED_CLAS; + *clas_mod = clas; move16(); - } - *clas_mod = clas; - move16(); - - BREAK; - - default: - clas = UNVOICED_CLAS; - *clas_mod = clas; - move16(); - move16(); - BREAK; + move16(); + BREAK; } } #if 0 @@ -276,20 +276,20 @@ Word16 signal_clas_fx( /* o : classification for current frames /* tc_cnt == 1: onset/transition frame, coded by GC coder type */ /* tc_cnt == 2: frame after onset/transition frame, coded by TC coder type */ - if (EQ_16(clas, UNVOICED_CLAS)) + if ( EQ_16( clas, UNVOICED_CLAS ) ) { st->tc_cnt = 0; move16(); } test(); - if (GE_16(clas, VOICED_TRANSITION) && st->tc_cnt >= 0) + if ( GE_16( clas, VOICED_TRANSITION ) && st->tc_cnt >= 0 ) { - st->tc_cnt = add(st->tc_cnt, 1); + st->tc_cnt = add( st->tc_cnt, 1 ); move16(); } - if (GT_16(st->tc_cnt, 2)) + if ( GT_16( st->tc_cnt, 2 ) ) { st->tc_cnt = -1; move16(); @@ -306,20 +306,20 @@ Word16 signal_clas_fx( /* o : classification for current frames void select_TC_fx( const Word16 codec_mode, /* i : codec mode */ const Word16 tc_cnt, /* i : TC frame counter */ - Word16* coder_type, /* i/o: coder type */ + Word16 *coder_type, /* i/o: coder type */ const Word16 localVAD /* i : VAD without hangover */ ) { - IF (EQ_16(codec_mode, MODE1)) + IF( EQ_16( codec_mode, MODE1 ) ) { /*---------------------------------------------------------------------* * Select TC coder type for appropriate frames which is in general VOICED_TRANSITION, * VOICED_CLAS or ONSET frames following UNVOICED_CLAS frames *---------------------------------------------------------------------*/ - IF (localVAD != 0 && GE_16(tc_cnt, 1)) + IF( localVAD != 0 && GE_16( tc_cnt, 1 ) ) { - IF (EQ_16(tc_cnt, 1)) + IF( EQ_16( tc_cnt, 1 ) ) { /* onset/transition frame is always coded using GC coder type */ *coder_type = GENERIC; @@ -344,16 +344,16 @@ void select_TC_fx( *-------------------------------------------------------------------*/ void coder_type_modif_fx( - Encoder_State* st, /* i/o: encoder state structure */ - const Word16 relE /* i : frame relative E to the long term average */ + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 relE /* i : frame relative E to the long term average */ ) { Word16 unmod_coder_type, vbr_generic_ho; - SC_VBR_ENC_HANDLE hSC_VBR = st->hSC_VBR; + SC_VBR_ENC_HANDLE hSC_VBR = st->hSC_VBR; - IF (st->Opt_SC_VBR) + IF( st->Opt_SC_VBR ) { vbr_generic_ho = hSC_VBR->vbr_generic_ho; move16(); @@ -364,7 +364,7 @@ void coder_type_modif_fx( move16(); } - IF(EQ_16(st->codec_mode, MODE1)) + IF( EQ_16( st->codec_mode, MODE1 ) ) { /*---------------------------------------------------------------------* * Coder type modification @@ -376,8 +376,8 @@ void coder_type_modif_fx( /* At higher rates, use GC coding instead of UC coding to improve quality */ test(); - if( (EQ_16(st->element_mode, EVS_MONO) && GT_32(st->total_brate,ACELP_9k60) && EQ_16(st->coder_type,UNVOICED)) || - (GT_16(st->element_mode, EVS_MONO) && GT_32(st->total_brate, MAX_UNVOICED_BRATE) && EQ_16(st->coder_type, UNVOICED)) ) + if ( ( EQ_16( st->element_mode, EVS_MONO ) && GT_32( st->total_brate, ACELP_9k60 ) && EQ_16( st->coder_type, UNVOICED ) ) || + ( GT_16( st->element_mode, EVS_MONO ) && GT_32( st->total_brate, MAX_UNVOICED_BRATE ) && EQ_16( st->coder_type, UNVOICED ) ) ) { st->coder_type = GENERIC; move16(); @@ -386,7 +386,7 @@ void coder_type_modif_fx( /* Prevent UC coding on mixed content at 9.6 kb/s */ test(); test(); - if( GE_32(st->total_brate,ACELP_9k60) && EQ_16(st->coder_type,UNVOICED) && st->audio_frame_cnt!=0) + if ( GE_32( st->total_brate, ACELP_9k60 ) && EQ_16( st->coder_type, UNVOICED ) && st->audio_frame_cnt != 0 ) { st->coder_type = GENERIC; move16(); @@ -396,15 +396,18 @@ void coder_type_modif_fx( move16(); /* Enforce GC coder type on inactive signal (this can be later overwritten to INACTIVE) */ - test();test();test();test(); - test();test();test(); - if( st->localVAD == 0 && ( - ( - EQ_16(st->coder_type,UNVOICED) - && ( ( st->Opt_SC_VBR == 0) || ( ( EQ_16(st->Opt_SC_VBR, 1) ) && vbr_generic_ho == 0 && GT_16(st->last_coder_type,UNVOICED) )) ) - || EQ_16(st->coder_type,TRANSITION) || EQ_16(st->coder_type,VOICED) ) - - ) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + if ( st->localVAD == 0 && ( ( + EQ_16( st->coder_type, UNVOICED ) && ( ( st->Opt_SC_VBR == 0 ) || ( ( EQ_16( st->Opt_SC_VBR, 1 ) ) && vbr_generic_ho == 0 && GT_16( st->last_coder_type, UNVOICED ) ) ) ) || + EQ_16( st->coder_type, TRANSITION ) || EQ_16( st->coder_type, VOICED ) ) + + ) { st->coder_type = GENERIC; move16(); @@ -412,37 +415,39 @@ void coder_type_modif_fx( test(); test(); - IF(EQ_16(st->Opt_SC_VBR, 1)) + IF( EQ_16( st->Opt_SC_VBR, 1 ) ) { - if (EQ_16(st->coder_type, GENERIC) && EQ_16(unmod_coder_type, UNVOICED) ) + if ( EQ_16( st->coder_type, GENERIC ) && EQ_16( unmod_coder_type, UNVOICED ) ) { hSC_VBR->vbr_generic_ho = 1; move16(); } test(); - if (GT_16(st->coder_type, UNVOICED) ) + if ( GT_16( st->coder_type, UNVOICED ) ) { hSC_VBR->vbr_generic_ho = 0; move16(); } - }//_DIFF_FLOAT_FIX_ see below -//PMT("Verify if EVS or IVAS is right about last_7k2_coder_type update") + } //_DIFF_FLOAT_FIX_ see below + // PMT("Verify if EVS or IVAS is right about last_7k2_coder_type update") hSC_VBR->last_7k2_coder_type = st->coder_type; move16(); test(); - if (st->localVAD == 0 && EQ_16(st->coder_type, UNVOICED)) + if ( st->localVAD == 0 && EQ_16( st->coder_type, UNVOICED ) ) { hSC_VBR->last_7k2_coder_type = GENERIC; move16(); } //} closing bracket here in IVAS float, but not in EVS float. currently affects BE for switching bitrate on Linux 20220929 _DIFF_FLOAT_FIX_ !! - IF (EQ_16(st->element_mode, EVS_MONO)) + IF( EQ_16( st->element_mode, EVS_MONO ) ) { /* At higher rates and with 16kHz core, allow only GC and TC coder type */ - test(); test(); test(); - if (GT_32(st->total_brate, ACELP_16k40) && NE_16(st->coder_type, GENERIC) && NE_16(st->coder_type, TRANSITION)) + test(); + test(); + test(); + if ( GT_32( st->total_brate, ACELP_16k40 ) && NE_16( st->coder_type, GENERIC ) && NE_16( st->coder_type, TRANSITION ) ) { /* onset/transition frame is always coded using GC mode */ st->coder_type = GENERIC; @@ -452,23 +457,24 @@ void coder_type_modif_fx( ELSE /*IVAS*/ { /* At higher bitrates, disable UC and VC coder type; note that IC coder type is classified later */ - if ((GT_32(st->total_brate, MAX_VOICED_BRATE) && EQ_16(st->coder_type, VOICED)) || - (GT_32(st->total_brate, MAX_UNVOICED_BRATE) && EQ_16(st->coder_type, UNVOICED))) + if ( ( GT_32( st->total_brate, MAX_VOICED_BRATE ) && EQ_16( st->coder_type, VOICED ) ) || + ( GT_32( st->total_brate, MAX_UNVOICED_BRATE ) && EQ_16( st->coder_type, UNVOICED ) ) ) { st->coder_type = GENERIC; move16(); } - } /* Patch for certain low-level signals for which the gain quantizer sometimes goes out of its dynamic range */ - test();test();test(); - if( EQ_16(st->coder_type,VOICED) && EQ_16(st->input_bwidth,NB) && LT_16(relE,-2560) && LE_32(st->total_brate,ACELP_8k00)) + test(); + test(); + test(); + if ( EQ_16( st->coder_type, VOICED ) && EQ_16( st->input_bwidth, NB ) && LT_16( relE, -2560 ) && LE_32( st->total_brate, ACELP_8k00 ) ) { st->coder_type = GENERIC; move16(); } } - return ; + return; } diff --git a/lib_enc/spec_center_fx.c b/lib_enc/spec_center_fx.c index 6b41126b6..a3fb197cb 100644 --- a/lib_enc/spec_center_fx.c +++ b/lib_enc/spec_center_fx.c @@ -8,9 +8,9 @@ #include "vad_basop.h" //#include "prot_fx.h" #include "rom_enc.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* * spec_center_fx() @@ -19,10 +19,10 @@ *-------------------------------------------------------------------*/ void spec_center_fx( - Word32* sb_power, /* i : energy of sub-band divided uniformly*/ - Word16* sp_center, /* o : spectral center*/ - const Word32 bw_index, /* i : band width*/ - const Word16 Q_sb_p /* i : the Scaling of sb_power*/ + Word32 *sb_power, /* i : energy of sub-band divided uniformly*/ + Word16 *sp_center, /* o : spectral center*/ + const Word32 bw_index, /* i : band width*/ + const Word16 Q_sb_p /* i : the Scaling of sb_power*/ ) { Word16 i; @@ -36,239 +36,251 @@ void spec_center_fx( Word16 d_t_sp_center; Word16 Q_t_sp_center, Q_frame_power; - Word16 Q_t_sc,Q_f_p; + Word16 Q_t_sc, Q_f_p; Word16 d_t_sp_center_Qtmp; - zerop1 = 0; move32(); - t_sp_center = 0; move32(); - frame_power = 0; move32(); + zerop1 = 0; + move32(); + t_sp_center = 0; + move32(); + frame_power = 0; + move32(); - FOR (i=0; i<10; i++) + FOR( i = 0; i < 10; i++ ) { - sb_power_shr[i] = L_shr(sb_power[i],5); + sb_power_shr[i] = L_shr( sb_power[i], 5 ); move32(); } - FOR(i=0; i<10; i++) + FOR( i = 0; i < 10; i++ ) { - sb_power_mlt = Mpy_32_16_1(sb_power[i],i_t_1[i]); - t_sp_center = L_add(L_shr(sb_power_mlt,6), t_sp_center); - frame_power = L_add(sb_power_shr[i], frame_power);/*0-9 */ + sb_power_mlt = Mpy_32_16_1( sb_power[i], i_t_1[i] ); + t_sp_center = L_add( L_shr( sb_power_mlt, 6 ), t_sp_center ); + frame_power = L_add( sb_power_shr[i], frame_power ); /*0-9 */ } - t_sp_center_nb = t_sp_center; move32(); - frame_power_nb = frame_power; move32(); + t_sp_center_nb = t_sp_center; + move32(); + frame_power_nb = frame_power; + move32(); /*+0.1 */ - Q_t_sc = sub(Q_sb_p, 10); - IF (GE_16(Q_t_sc,34)) + Q_t_sc = sub( Q_sb_p, 10 ); + IF( GE_16( Q_t_sc, 34 ) ) { - t_sp_center = L_shr(t_sp_center,sub(Q_t_sc, 33)); - zerop1 = L_shr(CNT0P1,1); + t_sp_center = L_shr( t_sp_center, sub( Q_t_sc, 33 ) ); + zerop1 = L_shr( CNT0P1, 1 ); Q_t_sc = 33; move16(); } ELSE { - Q_t_sc = sub(Q_t_sc, 1); - t_sp_center = L_shr(t_sp_center,1); - zerop1 = L_shr(CNT0P1, sub(34, Q_t_sc)); + Q_t_sc = sub( Q_t_sc, 1 ); + t_sp_center = L_shr( t_sp_center, 1 ); + zerop1 = L_shr( CNT0P1, sub( 34, Q_t_sc ) ); } - t_sp_center_num = L_add(t_sp_center, zerop1); + t_sp_center_num = L_add( t_sp_center, zerop1 ); - Q_f_p = sub(Q_sb_p, 5); - IF (GE_16(Q_f_p,34)) + Q_f_p = sub( Q_sb_p, 5 ); + IF( GE_16( Q_f_p, 34 ) ) { - frame_power = L_shr(frame_power,sub(Q_f_p, 33)); - zerop1 = L_shr(CNT0P1,1); + frame_power = L_shr( frame_power, sub( Q_f_p, 33 ) ); + zerop1 = L_shr( CNT0P1, 1 ); Q_f_p = 33; move16(); } ELSE { - Q_f_p = sub(Q_f_p, 1); - frame_power = L_shr(frame_power,1); - zerop1 = L_shr(CNT0P1, sub(34, Q_f_p)); + Q_f_p = sub( Q_f_p, 1 ); + frame_power = L_shr( frame_power, 1 ); + zerop1 = L_shr( CNT0P1, sub( 34, Q_f_p ) ); } - frame_power_den = L_add(frame_power, zerop1); - IF (frame_power == 0) + frame_power_den = L_add( frame_power, zerop1 ); + IF( frame_power == 0 ) { - frame_power_den = CNT0P1; move32(); + frame_power_den = CNT0P1; + move32(); Q_f_p = 34; move16(); } /*div */ - Q_t_sp_center = sub(norm_l(t_sp_center_num), 1); - Q_frame_power = norm_l(frame_power_den); - t_sp_center_num = L_shl(t_sp_center_num,Q_t_sp_center); - frame_power_den = L_shl(frame_power_den,Q_frame_power); + Q_t_sp_center = sub( norm_l( t_sp_center_num ), 1 ); + Q_frame_power = norm_l( frame_power_den ); + t_sp_center_num = L_shl( t_sp_center_num, Q_t_sp_center ); + frame_power_den = L_shl( frame_power_den, Q_frame_power ); - d_t_sp_center = div_l(t_sp_center_num,extract_h(frame_power_den)); + d_t_sp_center = div_l( t_sp_center_num, extract_h( frame_power_den ) ); - d_t_sp_center_Qtmp = add(Q_t_sc,Q_t_sp_center); - d_t_sp_center_Qtmp = sub(d_t_sp_center_Qtmp,Q_frame_power); - d_t_sp_center_Qtmp = sub(d_t_sp_center_Qtmp,Q_f_p); - d_t_sp_center_Qtmp = add(d_t_sp_center_Qtmp,15); - d_t_sp_center_Qtmp = sub(d_t_sp_center_Qtmp,SP_CENTER_Q); + d_t_sp_center_Qtmp = add( Q_t_sc, Q_t_sp_center ); + d_t_sp_center_Qtmp = sub( d_t_sp_center_Qtmp, Q_frame_power ); + d_t_sp_center_Qtmp = sub( d_t_sp_center_Qtmp, Q_f_p ); + d_t_sp_center_Qtmp = add( d_t_sp_center_Qtmp, 15 ); + d_t_sp_center_Qtmp = sub( d_t_sp_center_Qtmp, SP_CENTER_Q ); - d_t_sp_center = shr(d_t_sp_center,d_t_sp_center_Qtmp); - sp_center[0] = add(mult(sp_center[0],0x5999),mult(d_t_sp_center,0x2666)); + d_t_sp_center = shr( d_t_sp_center, d_t_sp_center_Qtmp ); + sp_center[0] = add( mult( sp_center[0], 0x5999 ), mult( d_t_sp_center, 0x2666 ) ); move16(); sp_center[2] = d_t_sp_center; move16(); - t_sp_center = 0; move32(); - frame_power = 0; move32(); - IF(EQ_32(bw_index,CLDFBVAD_WB_ID)) + t_sp_center = 0; + move32(); + frame_power = 0; + move32(); + IF( EQ_32( bw_index, CLDFBVAD_WB_ID ) ) { - FOR (i=10; i<20; i++) + FOR( i = 10; i < 20; i++ ) { - sb_power_shr[i] = L_shr(sb_power[i],5); + sb_power_shr[i] = L_shr( sb_power[i], 5 ); move32(); } - FOR(i=1; i<20; i++) + FOR( i = 1; i < 20; i++ ) { - sb_power_mlt = Mpy_32_16_1(sb_power[i],i_t_2[i-1]); - t_sp_center = L_add(L_shr(sb_power_mlt,8), t_sp_center); - frame_power = L_add(sb_power_shr[i], frame_power);/*1-19 */ + sb_power_mlt = Mpy_32_16_1( sb_power[i], i_t_2[i - 1] ); + t_sp_center = L_add( L_shr( sb_power_mlt, 8 ), t_sp_center ); + frame_power = L_add( sb_power_shr[i], frame_power ); /*1-19 */ } /*+0.1 */ - Q_t_sc = sub(Q_sb_p, 13); + Q_t_sc = sub( Q_sb_p, 13 ); - IF (GE_16(Q_t_sc, 34)) + IF( GE_16( Q_t_sc, 34 ) ) { - t_sp_center = L_shr(t_sp_center,sub(Q_t_sc, 33)); - zerop1 = L_shr(CNT0P1,1); + t_sp_center = L_shr( t_sp_center, sub( Q_t_sc, 33 ) ); + zerop1 = L_shr( CNT0P1, 1 ); Q_t_sc = 33; move16(); } ELSE { - Q_t_sc = sub(Q_t_sc, 1); - t_sp_center = L_shr(t_sp_center,1); - zerop1 = L_shr(CNT0P1, s_min(31, sub(34, Q_t_sc))); + Q_t_sc = sub( Q_t_sc, 1 ); + t_sp_center = L_shr( t_sp_center, 1 ); + zerop1 = L_shr( CNT0P1, s_min( 31, sub( 34, Q_t_sc ) ) ); } - t_sp_center_num = L_add(t_sp_center, zerop1); + t_sp_center_num = L_add( t_sp_center, zerop1 ); - Q_f_p = sub(Q_sb_p, 5); - IF (GE_16(Q_f_p,34)) + Q_f_p = sub( Q_sb_p, 5 ); + IF( GE_16( Q_f_p, 34 ) ) { - frame_power = L_shr(frame_power, sub(Q_f_p, 33)); - zerop1 = L_shr(CNT0P1,1); + frame_power = L_shr( frame_power, sub( Q_f_p, 33 ) ); + zerop1 = L_shr( CNT0P1, 1 ); Q_f_p = 33; move16(); } ELSE { - Q_f_p = sub(Q_f_p, 1); - frame_power = L_shr(frame_power,1); - zerop1 = L_shr(CNT0P1, sub(34, Q_f_p)); + Q_f_p = sub( Q_f_p, 1 ); + frame_power = L_shr( frame_power, 1 ); + zerop1 = L_shr( CNT0P1, sub( 34, Q_f_p ) ); } - frame_power_den = L_add(frame_power, zerop1); - IF (frame_power == 0) + frame_power_den = L_add( frame_power, zerop1 ); + IF( frame_power == 0 ) { - frame_power_den = CNT0P1; move32(); + frame_power_den = CNT0P1; + move32(); Q_f_p = 34; move16(); } /*div */ - Q_t_sp_center = sub(norm_l(t_sp_center_num), 1); - Q_frame_power = norm_l(frame_power_den); - t_sp_center_num = L_shl(t_sp_center_num,Q_t_sp_center); - frame_power_den = L_shl(frame_power_den,Q_frame_power); + Q_t_sp_center = sub( norm_l( t_sp_center_num ), 1 ); + Q_frame_power = norm_l( frame_power_den ); + t_sp_center_num = L_shl( t_sp_center_num, Q_t_sp_center ); + frame_power_den = L_shl( frame_power_den, Q_frame_power ); - d_t_sp_center = div_l(t_sp_center_num,extract_h(frame_power_den)); + d_t_sp_center = div_l( t_sp_center_num, extract_h( frame_power_den ) ); - d_t_sp_center_Qtmp = add(Q_t_sc,Q_t_sp_center); - d_t_sp_center_Qtmp = sub(d_t_sp_center_Qtmp,Q_frame_power); - d_t_sp_center_Qtmp = sub(d_t_sp_center_Qtmp,Q_f_p); - d_t_sp_center_Qtmp = add(d_t_sp_center_Qtmp,15); - d_t_sp_center_Qtmp = sub(d_t_sp_center_Qtmp,SP_CENTER_Q); + d_t_sp_center_Qtmp = add( Q_t_sc, Q_t_sp_center ); + d_t_sp_center_Qtmp = sub( d_t_sp_center_Qtmp, Q_frame_power ); + d_t_sp_center_Qtmp = sub( d_t_sp_center_Qtmp, Q_f_p ); + d_t_sp_center_Qtmp = add( d_t_sp_center_Qtmp, 15 ); + d_t_sp_center_Qtmp = sub( d_t_sp_center_Qtmp, SP_CENTER_Q ); - sp_center[3]= shr(d_t_sp_center,d_t_sp_center_Qtmp); + sp_center[3] = shr( d_t_sp_center, d_t_sp_center_Qtmp ); move16(); } - ELSE IF(EQ_32(bw_index, CLDFBVAD_SWB_ID)) + ELSE IF( EQ_32( bw_index, CLDFBVAD_SWB_ID ) ) { - FOR (i=10; i<24; i++) + FOR( i = 10; i < 24; i++ ) { - sb_power_shr[i] = L_shr(sb_power[i],5); + sb_power_shr[i] = L_shr( sb_power[i], 5 ); move32(); } - FOR(i=1; i<24; i++) + FOR( i = 1; i < 24; i++ ) { - sb_power_mlt = Mpy_32_16_1(sb_power[i],i_t_2[i-1]); - t_sp_center = L_add(L_shr(sb_power_mlt,9), t_sp_center); - frame_power = L_add(sb_power_shr[i], frame_power);/*1-23 */ + sb_power_mlt = Mpy_32_16_1( sb_power[i], i_t_2[i - 1] ); + t_sp_center = L_add( L_shr( sb_power_mlt, 9 ), t_sp_center ); + frame_power = L_add( sb_power_shr[i], frame_power ); /*1-23 */ } /*+0.1 */ - Q_t_sc = sub(Q_sb_p, 14); + Q_t_sc = sub( Q_sb_p, 14 ); - IF (GE_16(Q_t_sc,34)) + IF( GE_16( Q_t_sc, 34 ) ) { - t_sp_center = L_shr(t_sp_center, limitScale32(sub(Q_t_sc, 33))); - zerop1 = L_shr(CNT0P1,1); + t_sp_center = L_shr( t_sp_center, limitScale32( sub( Q_t_sc, 33 ) ) ); + zerop1 = L_shr( CNT0P1, 1 ); Q_t_sc = 33; move16(); } ELSE { - Q_t_sc = sub(Q_t_sc, 1); - t_sp_center = L_shr(t_sp_center,1); - zerop1 = L_shr(CNT0P1, limitScale32(sub(34, Q_t_sc))); + Q_t_sc = sub( Q_t_sc, 1 ); + t_sp_center = L_shr( t_sp_center, 1 ); + zerop1 = L_shr( CNT0P1, limitScale32( sub( 34, Q_t_sc ) ) ); } - t_sp_center_num = L_add(t_sp_center, zerop1); + t_sp_center_num = L_add( t_sp_center, zerop1 ); - Q_f_p = sub(Q_sb_p, 5); - IF (GE_16(Q_f_p,34)) + Q_f_p = sub( Q_sb_p, 5 ); + IF( GE_16( Q_f_p, 34 ) ) { - frame_power = L_shr(frame_power,sub(Q_f_p, 33)); - zerop1 = L_shr(CNT0P1,1); + frame_power = L_shr( frame_power, sub( Q_f_p, 33 ) ); + zerop1 = L_shr( CNT0P1, 1 ); Q_f_p = 33; move16(); } ELSE { - Q_f_p = sub(Q_f_p, 1); - frame_power = L_shr(frame_power,1); - zerop1 = L_shr(CNT0P1, sub(34, Q_f_p)); + Q_f_p = sub( Q_f_p, 1 ); + frame_power = L_shr( frame_power, 1 ); + zerop1 = L_shr( CNT0P1, sub( 34, Q_f_p ) ); } - frame_power_den = L_add(frame_power, zerop1); - IF (frame_power == 0) + frame_power_den = L_add( frame_power, zerop1 ); + IF( frame_power == 0 ) { - frame_power_den = CNT0P1; move32(); + frame_power_den = CNT0P1; + move32(); Q_f_p = 34; move16(); } /*div*/ - Q_t_sp_center=sub(norm_l(t_sp_center_num), 1); - Q_frame_power=norm_l(frame_power_den); - t_sp_center_num = L_shl(t_sp_center_num,Q_t_sp_center); - frame_power_den = L_shl(frame_power_den,Q_frame_power); - - d_t_sp_center = div_l(t_sp_center_num,extract_h(frame_power_den)); - - d_t_sp_center_Qtmp = add(Q_t_sc,Q_t_sp_center); - d_t_sp_center_Qtmp = sub(d_t_sp_center_Qtmp,Q_frame_power); - d_t_sp_center_Qtmp = sub(d_t_sp_center_Qtmp,Q_f_p); - d_t_sp_center_Qtmp = add(d_t_sp_center_Qtmp,15); - d_t_sp_center_Qtmp = sub(d_t_sp_center_Qtmp,SP_CENTER_Q); - sp_center[3]= shr(d_t_sp_center,d_t_sp_center_Qtmp); + Q_t_sp_center = sub( norm_l( t_sp_center_num ), 1 ); + Q_frame_power = norm_l( frame_power_den ); + t_sp_center_num = L_shl( t_sp_center_num, Q_t_sp_center ); + frame_power_den = L_shl( frame_power_den, Q_frame_power ); + + d_t_sp_center = div_l( t_sp_center_num, extract_h( frame_power_den ) ); + + d_t_sp_center_Qtmp = add( Q_t_sc, Q_t_sp_center ); + d_t_sp_center_Qtmp = sub( d_t_sp_center_Qtmp, Q_frame_power ); + d_t_sp_center_Qtmp = sub( d_t_sp_center_Qtmp, Q_f_p ); + d_t_sp_center_Qtmp = add( d_t_sp_center_Qtmp, 15 ); + d_t_sp_center_Qtmp = sub( d_t_sp_center_Qtmp, SP_CENTER_Q ); + sp_center[3] = shr( d_t_sp_center, d_t_sp_center_Qtmp ); move16(); } ELSE { - t_sp_center = t_sp_center_nb; move32(); - frame_power = frame_power_nb; move32(); + t_sp_center = t_sp_center_nb; + move32(); + frame_power = frame_power_nb; + move32(); - IF (frame_power==0) + IF( frame_power == 0 ) { d_t_sp_center = 0; move16(); @@ -276,29 +288,31 @@ void spec_center_fx( ELSE { /*div*/ - Q_t_sp_center = sub(norm_l(t_sp_center), 1); - Q_frame_power = norm_l(frame_power); - t_sp_center_num = L_shl(t_sp_center,Q_t_sp_center); - frame_power_den = L_shl(frame_power,Q_frame_power); + Q_t_sp_center = sub( norm_l( t_sp_center ), 1 ); + Q_frame_power = norm_l( frame_power ); + t_sp_center_num = L_shl( t_sp_center, Q_t_sp_center ); + frame_power_den = L_shl( frame_power, Q_frame_power ); - d_t_sp_center = div_l(t_sp_center_num,extract_h(frame_power_den)); - d_t_sp_center = shr(d_t_sp_center,sub(add(sub(Q_t_sp_center,Q_frame_power),10),SP_CENTER_Q)); + d_t_sp_center = div_l( t_sp_center_num, extract_h( frame_power_den ) ); + d_t_sp_center = shr( d_t_sp_center, sub( add( sub( Q_t_sp_center, Q_frame_power ), 10 ), SP_CENTER_Q ) ); } - sp_center[0] = add(mult(sp_center[0], 0x5999), mult(d_t_sp_center, 0x2666)); + sp_center[0] = add( mult( sp_center[0], 0x5999 ), mult( d_t_sp_center, 0x2666 ) ); sp_center[2] = d_t_sp_center; move16(); move16(); - t_sp_center = 0; move32(); - frame_power = 0; move32(); - FOR(i=1; i<10; i++) + t_sp_center = 0; + move32(); + frame_power = 0; + move32(); + FOR( i = 1; i < 10; i++ ) { - sb_power_mlt = Mpy_32_16_1(sb_power[i],i_t_1[i-1]); - t_sp_center = L_add(L_shr(sb_power_mlt,6), t_sp_center); - frame_power = L_add(sb_power_shr[i], frame_power); /*1-9 */ + sb_power_mlt = Mpy_32_16_1( sb_power[i], i_t_1[i - 1] ); + t_sp_center = L_add( L_shr( sb_power_mlt, 6 ), t_sp_center ); + frame_power = L_add( sb_power_shr[i], frame_power ); /*1-9 */ } - IF (frame_power==0) + IF( frame_power == 0 ) { sp_center[3] = 0; move16(); @@ -306,15 +320,14 @@ void spec_center_fx( ELSE { /*div */ - Q_t_sp_center = sub(norm_l(t_sp_center), 1); - Q_frame_power = norm_l(frame_power); - t_sp_center_num = L_shl(t_sp_center,Q_t_sp_center); - frame_power_den = L_shl(frame_power,Q_frame_power); + Q_t_sp_center = sub( norm_l( t_sp_center ), 1 ); + Q_frame_power = norm_l( frame_power ); + t_sp_center_num = L_shl( t_sp_center, Q_t_sp_center ); + frame_power_den = L_shl( frame_power, Q_frame_power ); - d_t_sp_center = div_l(t_sp_center_num,extract_h(frame_power_den)); - sp_center[3] = shr(d_t_sp_center,sub(add(sub(Q_t_sp_center, Q_frame_power), 10),SP_CENTER_Q)); + d_t_sp_center = div_l( t_sp_center_num, extract_h( frame_power_den ) ); + sp_center[3] = shr( d_t_sp_center, sub( add( sub( Q_t_sp_center, Q_frame_power ), 10 ), SP_CENTER_Q ) ); move16(); } } - } diff --git a/lib_enc/spec_flatness_fx.c b/lib_enc/spec_flatness_fx.c index 03b920107..918faa5e6 100644 --- a/lib_enc/spec_flatness_fx.c +++ b/lib_enc/spec_flatness_fx.c @@ -9,321 +9,302 @@ #include "basop_util.h" #include "vad_basop.h" //#include "prot_fx.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* * spec_flatness_fx() * * *-------------------------------------------------------------------*/ - void spec_flatness_fx( - Word32 *spec_amp, /* i : spectral amplitude*/ - Word32 smooth_spec_amp[], /* i : smoothed spectral amplitude*/ - Word16 sSFM[SFM_NUM] /* o : spectral flatness rate*/ +void spec_flatness_fx( + Word32 *spec_amp, /* i : spectral amplitude*/ + Word32 smooth_spec_amp[], /* i : smoothed spectral amplitude*/ + Word16 sSFM[SFM_NUM] /* o : spectral flatness rate*/ ) { Word32 i; Word32 *smooth_spec_amp32; - Word32 prods,prods_Exp; - Word32 sums,prods_ExpM; + Word32 prods, prods_Exp; + Word32 sums, prods_ExpM; Word32 zerop1; Word16 smooth_spec_amp16; - Word16 Qnorm_prods,Qnorm_sums; + Word16 Qnorm_prods, Qnorm_sums; Word16 SFM; - Word16 prods_s,prods_Exps; - Word16 prods_leadingzero,prods_Expleadingzero; + Word16 prods_s, prods_Exps; + Word16 prods_leadingzero, prods_Expleadingzero; Word16 leadingzero_prod, leadingzero_spec_amp; - Word16 prods_Q_last,prods_ExpQ; + Word16 prods_Q_last, prods_ExpQ; Word16 SFM_Qtmp; Word16 prods_Q; smooth_spec_amp32 = smooth_spec_amp; zerop1 = 0; - move32(); + move32(); prods_Q = 0; move16(); - FOR(i=MIN_AMP_ID; i<=MAX_AMP_ID; i++) + FOR( i = MIN_AMP_ID; i <= MAX_AMP_ID; i++ ) { - smooth_spec_amp32[i-MIN_AMP_ID] = L_add(MUL_F(smooth_spec_amp32[i-MIN_AMP_ID],0x5999),MUL_F(spec_amp[i],0x2666)); + smooth_spec_amp32[i - MIN_AMP_ID] = L_add( MUL_F( smooth_spec_amp32[i - MIN_AMP_ID], 0x5999 ), MUL_F( spec_amp[i], 0x2666 ) ); move32(); } /*sSFM1*/ sums = 0; - move32(); + move32(); prods = 1; - move32(); + move32(); prods_Q = 0; move16(); - FOR(i=(5-MIN_AMP_ID); i<(20-MIN_AMP_ID); i++) + FOR( i = ( 5 - MIN_AMP_ID ); i < ( 20 - MIN_AMP_ID ); i++ ) { - sums = L_add(sums, smooth_spec_amp32[i]); - leadingzero_spec_amp = norm_l(smooth_spec_amp32[i]); - smooth_spec_amp16 = extract_h(L_shl(smooth_spec_amp32[i],leadingzero_spec_amp)); - leadingzero_prod = norm_l(prods); - prods = L_shl(prods,leadingzero_prod); - prods_s = extract_h(prods); - prods = L_mult(prods_s, smooth_spec_amp16); - prods_Q = add(add(prods_Q, leadingzero_spec_amp),leadingzero_prod); + sums = L_add( sums, smooth_spec_amp32[i] ); + leadingzero_spec_amp = norm_l( smooth_spec_amp32[i] ); + smooth_spec_amp16 = extract_h( L_shl( smooth_spec_amp32[i], leadingzero_spec_amp ) ); + leadingzero_prod = norm_l( prods ); + prods = L_shl( prods, leadingzero_prod ); + prods_s = extract_h( prods ); + prods = L_mult( prods_s, smooth_spec_amp16 ); + prods_Q = add( add( prods_Q, leadingzero_spec_amp ), leadingzero_prod ); } - prods_Q = sub(prods_Q, 255); + prods_Q = sub( prods_Q, 255 ); prods_Q_last = prods_Q; move16(); - prods_ExpM = L_mult(prods_Q_last,-2184); + prods_ExpM = L_mult( prods_Q_last, -2184 ); - prods = VAD_Pow(prods,0x08888888,0,31,&prods_Q); - prods_Exp = VAD_Pow2(prods_ExpM,16, &prods_ExpQ); + prods = VAD_Pow( prods, 0x08888888, 0, 31, &prods_Q ); + prods_Exp = VAD_Pow2( prods_ExpM, 16, &prods_ExpQ ); - prods_leadingzero = norm_l(prods); - prods_Expleadingzero = norm_l(prods_Exp); - prods_s = extract_h(L_shl(prods,prods_leadingzero)); - prods_Exps = extract_h(L_shl(prods_Exp,prods_Expleadingzero)); + prods_leadingzero = norm_l( prods ); + prods_Expleadingzero = norm_l( prods_Exp ); + prods_s = extract_h( L_shl( prods, prods_leadingzero ) ); + prods_Exps = extract_h( L_shl( prods_Exp, prods_Expleadingzero ) ); - prods = L_mult(prods_s, prods_Exps); - prods_Q = add(prods_Q, prods_leadingzero); - prods_Q = add(prods_Q, prods_ExpQ); - prods_Q = add(prods_Q, prods_Expleadingzero); - prods_Q = sub(prods_Q, 31); + prods = L_mult( prods_s, prods_Exps ); + prods_Q = add( prods_Q, prods_leadingzero ); + prods_Q = add( prods_Q, prods_ExpQ ); + prods_Q = add( prods_Q, prods_Expleadingzero ); + prods_Q = sub( prods_Q, 31 ); - prods = L_max(prods, 0); + prods = L_max( prods, 0 ); - if(prods <= 0) + if ( prods <= 0 ) { prods_Q = 34; move16(); } - sums = MUL_F(sums, 0x0888); + sums = MUL_F( sums, 0x0888 ); /*+0.1 */ - IF (GE_16(prods_Q, 34)) + IF( GE_16( prods_Q, 34 ) ) { - prods = L_shr(prods, sub(prods_Q, 33)); - zerop1 = L_shr(CNT0P1, 1); + prods = L_shr( prods, sub( prods_Q, 33 ) ); + zerop1 = L_shr( CNT0P1, 1 ); prods_Q = 33; move16(); } ELSE { - prods_Q = sub(prods_Q, 1); - prods = L_shr(prods, 1); - zerop1 = L_shr(CNT0P1, sub(34, prods_Q)); + prods_Q = sub( prods_Q, 1 ); + prods = L_shr( prods, 1 ); + zerop1 = L_shr( CNT0P1, sub( 34, prods_Q ) ); } - prods = L_add(prods, zerop1); + prods = L_add( prods, zerop1 ); - zerop1 = L_shr(CNT0P1, 20); - sums = L_add(sums, zerop1); + zerop1 = L_shr( CNT0P1, 20 ); + sums = L_add( sums, zerop1 ); /*div*/ - Qnorm_prods = sub(norm_l(prods), 1); - Qnorm_sums = norm_l(sums); - prods = L_shl(prods,Qnorm_prods); - sums = L_shl(sums,Qnorm_sums); + Qnorm_prods = sub( norm_l( prods ), 1 ); + Qnorm_sums = norm_l( sums ); + prods = L_shl( prods, Qnorm_prods ); + sums = L_shl( sums, Qnorm_sums ); - SFM = div_l(prods, extract_h(sums)); + SFM = div_l( prods, extract_h( sums ) ); - SFM_Qtmp = add(prods_Q, Qnorm_prods); - SFM_Qtmp = sub(SFM_Qtmp, Qnorm_sums); - SFM_Qtmp = add(SFM_Qtmp, 15); - SFM_Qtmp = sub(SFM_Qtmp, SPEC_AMP_Q); - SFM_Qtmp = sub(SFM_Qtmp, SFM_Q); + SFM_Qtmp = add( prods_Q, Qnorm_prods ); + SFM_Qtmp = sub( SFM_Qtmp, Qnorm_sums ); + SFM_Qtmp = add( SFM_Qtmp, 15 ); + SFM_Qtmp = sub( SFM_Qtmp, SPEC_AMP_Q ); + SFM_Qtmp = sub( SFM_Qtmp, SFM_Q ); - sSFM[0] = add(mult(sSFM[0], 0x6ccc), shr(mult(SFM, 0x1333), SFM_Qtmp)); + sSFM[0] = add( mult( sSFM[0], 0x6ccc ), shr( mult( SFM, 0x1333 ), SFM_Qtmp ) ); move16(); /*sSFM2*/ sums = 0; - move32(); + move32(); prods = 1; - move32(); + move32(); prods_Q = 0; move16(); - FOR(i=(20-MIN_AMP_ID); i<(40-MIN_AMP_ID); i++) + FOR( i = ( 20 - MIN_AMP_ID ); i < ( 40 - MIN_AMP_ID ); i++ ) { - sums = L_add(sums, smooth_spec_amp32[i]); - leadingzero_spec_amp = norm_l(smooth_spec_amp32[i]); - smooth_spec_amp16 = extract_h(L_shl(smooth_spec_amp32[i],leadingzero_spec_amp)); - leadingzero_prod = norm_l(prods); - prods = L_shl(prods,leadingzero_prod); - prods_s = extract_h(prods); - prods = L_mult(prods_s, smooth_spec_amp16); - prods_Q = add(add(prods_Q, leadingzero_spec_amp),leadingzero_prod); + sums = L_add( sums, smooth_spec_amp32[i] ); + leadingzero_spec_amp = norm_l( smooth_spec_amp32[i] ); + smooth_spec_amp16 = extract_h( L_shl( smooth_spec_amp32[i], leadingzero_spec_amp ) ); + leadingzero_prod = norm_l( prods ); + prods = L_shl( prods, leadingzero_prod ); + prods_s = extract_h( prods ); + prods = L_mult( prods_s, smooth_spec_amp16 ); + prods_Q = add( add( prods_Q, leadingzero_spec_amp ), leadingzero_prod ); } - prods_Q = sub(prods_Q, 340); + prods_Q = sub( prods_Q, 340 ); prods_Q_last = prods_Q; move16(); - prods_ExpM = L_mult(prods_Q_last,-1638); + prods_ExpM = L_mult( prods_Q_last, -1638 ); - prods = VAD_Pow(prods,0x06666666,0,31,&prods_Q); - prods_Exp = VAD_Pow2(prods_ExpM,16, &prods_ExpQ); + prods = VAD_Pow( prods, 0x06666666, 0, 31, &prods_Q ); + prods_Exp = VAD_Pow2( prods_ExpM, 16, &prods_ExpQ ); - prods_leadingzero = norm_l(prods); - prods_Expleadingzero = norm_l(prods_Exp); - prods_s = extract_h(L_shl(prods,prods_leadingzero)); - prods_Exps = extract_h(L_shl(prods_Exp,prods_Expleadingzero)); + prods_leadingzero = norm_l( prods ); + prods_Expleadingzero = norm_l( prods_Exp ); + prods_s = extract_h( L_shl( prods, prods_leadingzero ) ); + prods_Exps = extract_h( L_shl( prods_Exp, prods_Expleadingzero ) ); - prods = L_mult(prods_s, prods_Exps); - prods_Q = add(prods_Q, prods_leadingzero); - prods_Q = add(prods_Q, prods_ExpQ); - prods_Q = add(prods_Q, prods_Expleadingzero); - prods_Q = sub(prods_Q, 31); + prods = L_mult( prods_s, prods_Exps ); + prods_Q = add( prods_Q, prods_leadingzero ); + prods_Q = add( prods_Q, prods_ExpQ ); + prods_Q = add( prods_Q, prods_Expleadingzero ); + prods_Q = sub( prods_Q, 31 ); - prods = L_max(prods, 0); + prods = L_max( prods, 0 ); - if(prods<=0) + if ( prods <= 0 ) { prods_Q = 34; move16(); } - sums = MUL_F(sums, 0x0666); + sums = MUL_F( sums, 0x0666 ); /*+0.1 */ - IF (GE_16(prods_Q, 34)) + IF( GE_16( prods_Q, 34 ) ) { - prods = L_shr(prods,sub(prods_Q, 33)); - zerop1 = L_shr(CNT0P1,1); + prods = L_shr( prods, sub( prods_Q, 33 ) ); + zerop1 = L_shr( CNT0P1, 1 ); prods_Q = 33; move16(); } ELSE { - prods_Q = sub(prods_Q,1); - prods = L_shr(prods,1); - zerop1 = L_shr(CNT0P1, sub(34, prods_Q)); + prods_Q = sub( prods_Q, 1 ); + prods = L_shr( prods, 1 ); + zerop1 = L_shr( CNT0P1, sub( 34, prods_Q ) ); } - prods = L_add(prods, zerop1); + prods = L_add( prods, zerop1 ); - zerop1 = L_shr(CNT0P1, 20); - sums = L_add(sums, zerop1); + zerop1 = L_shr( CNT0P1, 20 ); + sums = L_add( sums, zerop1 ); /*div*/ - Qnorm_prods=sub(norm_l(prods), 1); - Qnorm_sums=norm_l(sums); - prods = L_shl(prods, Qnorm_prods); - sums = L_shl(sums, Qnorm_sums); + Qnorm_prods = sub( norm_l( prods ), 1 ); + Qnorm_sums = norm_l( sums ); + prods = L_shl( prods, Qnorm_prods ); + sums = L_shl( sums, Qnorm_sums ); - SFM = div_l(prods, extract_h(sums)); + SFM = div_l( prods, extract_h( sums ) ); - SFM_Qtmp = add(prods_Q, Qnorm_prods); - SFM_Qtmp = sub(SFM_Qtmp, Qnorm_sums); - SFM_Qtmp = add(SFM_Qtmp, 15); - SFM_Qtmp = sub(SFM_Qtmp, SPEC_AMP_Q); - SFM_Qtmp = sub(SFM_Qtmp, SFM_Q); + SFM_Qtmp = add( prods_Q, Qnorm_prods ); + SFM_Qtmp = sub( SFM_Qtmp, Qnorm_sums ); + SFM_Qtmp = add( SFM_Qtmp, 15 ); + SFM_Qtmp = sub( SFM_Qtmp, SPEC_AMP_Q ); + SFM_Qtmp = sub( SFM_Qtmp, SFM_Q ); - sSFM[1] = add(mult(sSFM[1],0x6ccc),shr(mult(SFM,0x1333),SFM_Qtmp)); + sSFM[1] = add( mult( sSFM[1], 0x6ccc ), shr( mult( SFM, 0x1333 ), SFM_Qtmp ) ); move16(); /*sSFM3*/ sums = 0; - move32(); - prods =1; - move32(); + move32(); + prods = 1; + move32(); prods_Q = 0; move16(); - FOR(i=(40-MIN_AMP_ID); i<=(MAX_AMP_ID-MIN_AMP_ID); i++) + FOR( i = ( 40 - MIN_AMP_ID ); i <= ( MAX_AMP_ID - MIN_AMP_ID ); i++ ) { - sums = L_add(sums, smooth_spec_amp32[i]); - leadingzero_spec_amp = norm_l(smooth_spec_amp32[i]); - smooth_spec_amp16 = extract_h(L_shl(smooth_spec_amp32[i],leadingzero_spec_amp)); - leadingzero_prod = norm_l(prods); - prods = L_shl(prods,leadingzero_prod); - prods_s = extract_h(prods); - prods = L_mult(prods_s, smooth_spec_amp16); - prods_Q = add(add(prods_Q, leadingzero_spec_amp),leadingzero_prod); + sums = L_add( sums, smooth_spec_amp32[i] ); + leadingzero_spec_amp = norm_l( smooth_spec_amp32[i] ); + smooth_spec_amp16 = extract_h( L_shl( smooth_spec_amp32[i], leadingzero_spec_amp ) ); + leadingzero_prod = norm_l( prods ); + prods = L_shl( prods, leadingzero_prod ); + prods_s = extract_h( prods ); + prods = L_mult( prods_s, smooth_spec_amp16 ); + prods_Q = add( add( prods_Q, leadingzero_spec_amp ), leadingzero_prod ); } - prods_Q = sub(prods_Q, 425); + prods_Q = sub( prods_Q, 425 ); prods_Q_last = prods_Q; move16(); - prods_ExpM = L_mult(prods_Q_last,-1310); + prods_ExpM = L_mult( prods_Q_last, -1310 ); - prods = VAD_Pow(prods,0x051eb851,0,31,&prods_Q); - prods_Exp = VAD_Pow2(prods_ExpM,16, &prods_ExpQ); + prods = VAD_Pow( prods, 0x051eb851, 0, 31, &prods_Q ); + prods_Exp = VAD_Pow2( prods_ExpM, 16, &prods_ExpQ ); - prods_leadingzero = norm_l(prods); - prods_Expleadingzero = norm_l(prods_Exp); - prods_s = extract_h(L_shl(prods,prods_leadingzero)); - prods_Exps = extract_h(L_shl(prods_Exp,prods_Expleadingzero)); + prods_leadingzero = norm_l( prods ); + prods_Expleadingzero = norm_l( prods_Exp ); + prods_s = extract_h( L_shl( prods, prods_leadingzero ) ); + prods_Exps = extract_h( L_shl( prods_Exp, prods_Expleadingzero ) ); - prods = L_mult(prods_s, prods_Exps); - prods_Q = add(prods_Q, prods_leadingzero); - prods_Q = add(prods_Q, prods_ExpQ); - prods_Q = add(prods_Q, prods_Expleadingzero); - prods_Q = sub(prods_Q, 31); + prods = L_mult( prods_s, prods_Exps ); + prods_Q = add( prods_Q, prods_leadingzero ); + prods_Q = add( prods_Q, prods_ExpQ ); + prods_Q = add( prods_Q, prods_Expleadingzero ); + prods_Q = sub( prods_Q, 31 ); - prods = L_max(prods, 0); - if(prods <= 0) + prods = L_max( prods, 0 ); + if ( prods <= 0 ) { prods_Q = 34; move16(); } - sums = MUL_F(sums, 0x051e); + sums = MUL_F( sums, 0x051e ); /*+0.1 */ - IF (GE_16(prods_Q, 34)) + IF( GE_16( prods_Q, 34 ) ) { - prods = L_shr(prods,sub(prods_Q, 33)); - zerop1 = L_shr(CNT0P1,1); + prods = L_shr( prods, sub( prods_Q, 33 ) ); + zerop1 = L_shr( CNT0P1, 1 ); prods_Q = 33; move16(); } ELSE { - prods_Q = sub(prods_Q, 1); - prods = L_shr(prods,1); - zerop1 = L_shr(CNT0P1, sub(34, prods_Q)); + prods_Q = sub( prods_Q, 1 ); + prods = L_shr( prods, 1 ); + zerop1 = L_shr( CNT0P1, sub( 34, prods_Q ) ); } - prods = L_add(prods, zerop1); + prods = L_add( prods, zerop1 ); - zerop1 = L_shr(CNT0P1, 20); - sums = L_add(sums, zerop1); + zerop1 = L_shr( CNT0P1, 20 ); + sums = L_add( sums, zerop1 ); /*div*/ - Qnorm_prods = sub(norm_l(prods), 1); - Qnorm_sums = norm_l(sums); - prods = L_shl(prods,Qnorm_prods); - sums = L_shl(sums,Qnorm_sums); + Qnorm_prods = sub( norm_l( prods ), 1 ); + Qnorm_sums = norm_l( sums ); + prods = L_shl( prods, Qnorm_prods ); + sums = L_shl( sums, Qnorm_sums ); - SFM = div_l(prods,extract_h(sums)); + SFM = div_l( prods, extract_h( sums ) ); - SFM_Qtmp = add(prods_Q, Qnorm_prods); - SFM_Qtmp = sub(SFM_Qtmp, Qnorm_sums); - SFM_Qtmp = add(SFM_Qtmp, 15); - SFM_Qtmp = sub(SFM_Qtmp, SPEC_AMP_Q); - SFM_Qtmp = sub(SFM_Qtmp, SFM_Q); + SFM_Qtmp = add( prods_Q, Qnorm_prods ); + SFM_Qtmp = sub( SFM_Qtmp, Qnorm_sums ); + SFM_Qtmp = add( SFM_Qtmp, 15 ); + SFM_Qtmp = sub( SFM_Qtmp, SPEC_AMP_Q ); + SFM_Qtmp = sub( SFM_Qtmp, SFM_Q ); #ifdef BASOP_NOGLOB sSFM[2] = add_sat( mult( sSFM[2], 0x6ccc ), shr_sat( mult( SFM, 0x1333 ), SFM_Qtmp ) ); #else - sSFM[2] = add(mult(sSFM[2],0x6ccc),shr(mult(SFM,0x1333),SFM_Qtmp)); + sSFM[2] = add( mult( sSFM[2], 0x6ccc ), shr( mult( SFM, 0x1333 ), SFM_Qtmp ) ); #endif move16(); } - - - - - - - - - - - - - - - - - - - diff --git a/lib_enc/speech_music_classif.c b/lib_enc/speech_music_classif.c index 9d5f836ee..fe0ea5968 100644 --- a/lib_enc/speech_music_classif.c +++ b/lib_enc/speech_music_classif.c @@ -2715,7 +2715,7 @@ static void tonal_context_improv( hSpMusClas->tonality3_buf[HANG_LEN_INIT - 1] = 0.2f * log10f( tonality3 ); t3 = std_dev( hSpMusClas->tonality3_buf, HANG_LEN_INIT ); - tL = 0.2f * log10f( hSpMusClas->lt_tonality_flt); + tL = 0.2f * log10f( hSpMusClas->lt_tonality_flt ); /* calculate standard deviation of residual LP energy */ mvr2r( hSpMusClas->LPCErr_buf + 1, hSpMusClas->LPCErr_buf, HANG_LEN_INIT - 1 ); diff --git a/lib_enc/speech_music_classif_fx.c b/lib_enc/speech_music_classif_fx.c index ae1de1ddb..bba2c502a 100644 --- a/lib_enc/speech_music_classif_fx.c +++ b/lib_enc/speech_music_classif_fx.c @@ -11,44 +11,45 @@ #include "rom_com_fx.h" #include "rom_com.h" #include "stl.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*---------------------------------------------------------------------* * Local constants *---------------------------------------------------------------------*/ -#define ATT_NSEG 32 -#define ATT_SEG_LEN (L_FRAME/ATT_NSEG) -#define ATT_3LSUB_POS (3 * ATT_NSEG / NB_SUBFR) -#define ATT_3LSUB_POS_16k 26 /* (short)((4.0f * ATT_NSEG / (float)NB_SUBFR16k) + 0.5f) */ +#define ATT_NSEG 32 +#define ATT_SEG_LEN ( L_FRAME / ATT_NSEG ) +#define ATT_3LSUB_POS ( 3 * ATT_NSEG / NB_SUBFR ) +#define ATT_3LSUB_POS_16k 26 /* (short)((4.0f * ATT_NSEG / (float)NB_SUBFR16k) + 0.5f) */ -#define LOG_PROB_CONST 11292 /*0.5f * N_FEATURES * LOG_PI2 in Q10 */ +#define LOG_PROB_CONST 11292 /*0.5f * N_FEATURES * LOG_PI2 in Q10 */ /*---------------------------------------------------------------------* * Local functions *---------------------------------------------------------------------*/ -static Word16 sp_mus_classif_gmm_fx( Encoder_State *st_fx, const Word16 localVAD_HE_SAD, const Word16 lsp_new[M], const Word16 cor_map_sum, const Word32 epsP[M+1], const Word32 PS[], - Word16 non_sta, Word16 relE, Word16 *voi_fv, Word16 *cor_map_sum_fv, Word16 *LPCErr, Word16 Q_esp - , Word16 *high_lpn_flag_ptr); +static Word16 sp_mus_classif_gmm_fx( Encoder_State *st_fx, const Word16 localVAD_HE_SAD, const Word16 lsp_new[M], const Word16 cor_map_sum, const Word32 epsP[M + 1], const Word32 PS[], Word16 non_sta, Word16 relE, Word16 *voi_fv, Word16 *cor_map_sum_fv, Word16 *LPCErr, Word16 Q_esp, Word16 *high_lpn_flag_ptr ); +static void sp_mus_classif_2nd_fx( Encoder_State *st, const Word16 Etot, Word16 *attack_flag, const Word16 *inp, const Word16 Qx ); -static void sp_mus_classif_2nd_fx(Encoder_State* st, const Word16 Etot, Word16* attack_flag, const Word16* inp, const Word16 Qx); - -static void music_mixed_classif_improv_fx( Encoder_State *st, const Word16 *new_inp, const Word32 *epsP, Word16 Q_epsP, Word16 etot, Word16 old_cor,Word16 cor_map_sum ); +static void music_mixed_classif_improv_fx( Encoder_State *st, const Word16 *new_inp, const Word32 *epsP, Word16 Q_epsP, Word16 etot, Word16 old_cor, Word16 cor_map_sum ); static void tonal_context_improv_fx( Encoder_State *st_fx, const Word32 PS[], const Word16 voi_fv, const Word16 cor_map_sum_fv, const Word16 LPCErr, const Word16 Qx ); static void var_cor_calc_fx( const Word16 old_corr, Word16 *mold_corr, Word16 var_cor_t[], Word16 *high_stable_cor ); -static Word16 attack_det_fx(const Word16* inp, const Word16 Qx, const Word16 last_clas, const Word16 localVAD, const Word16 coder_type, - const Word32 total_brate +static Word16 attack_det_fx( const Word16 *inp, const Word16 Qx, const Word16 last_clas, const Word16 localVAD, const Word16 coder_type, const Word32 total_brate #ifdef IVAS_CODE - , const Word16 element_mode, const Word16 clas, Word32 finc_prev[], Word32* lt_finc, Word16* last_strong_attack + , + const Word16 element_mode, + const Word16 clas, + Word32 finc_prev[], + Word32 *lt_finc, + Word16 *last_strong_attack #endif - ); +); static void order_spectrum_fx( Word16 *vec, Word16 len ); @@ -68,9 +69,9 @@ void speech_music_clas_init_fx( hSpMusClas->inact_cnt = 0; move16(); - set16_fx(hSpMusClas->past_dec, 0, HANG_LEN - 1); - set16_fx(hSpMusClas->past_dlp_fx, 0, HANG_LEN - 1); - set16_fx(hSpMusClas->past_log_enr_fx, -1448, NB_BANDS_SPMUS); /* log(E_MIN) in Q8 */ + set16_fx( hSpMusClas->past_dec, 0, HANG_LEN - 1 ); + set16_fx( hSpMusClas->past_dlp_fx, 0, HANG_LEN - 1 ); + set16_fx( hSpMusClas->past_log_enr_fx, -1448, NB_BANDS_SPMUS ); /* log(E_MIN) in Q8 */ hSpMusClas->sp_mus_state = -8; move16(); @@ -78,12 +79,12 @@ void speech_music_clas_init_fx( move16(); hSpMusClas->wdlp_0_95_sp_fx = 0; move16(); - set16_fx(hSpMusClas->last_lsp_fx, 0, M_LSP_SPMUS); + set16_fx( hSpMusClas->last_lsp_fx, 0, M_LSP_SPMUS ); hSpMusClas->last_cor_map_sum_fx = 0; move16(); hSpMusClas->last_non_sta_fx = 0; move16(); - set32_fx(hSpMusClas->past_PS_fx, 0, HIGHEST_FBIN - LOWEST_FBIN); + set32_fx( hSpMusClas->past_PS_fx, 0, HIGHEST_FBIN - LOWEST_FBIN ); hSpMusClas->past_ps_diff_fx = 0; move16(); hSpMusClas->past_epsP2_fx = 1024; @@ -98,7 +99,7 @@ void speech_music_clas_init_fx( move16(); hSpMusClas->gsc_thres_fx[3] = TH_3_MIN_FX; move16(); - set16_fx(hSpMusClas->gsc_lt_diff_etot_fx, 0, 40); + set16_fx( hSpMusClas->gsc_lt_diff_etot_fx, 0, 40 ); hSpMusClas->gsc_mem_etot_fx = 0; move16(); hSpMusClas->gsc_last_music_flag = 0; @@ -110,14 +111,14 @@ void speech_music_clas_init_fx( hSpMusClas->mold_corr_fx = 29491; move16(); hSpMusClas->mean_avr_dyn_fx = 64; - move16();/*Q7 */ + move16(); /*Q7 */ hSpMusClas->last_sw_dyn_fx = 2560; move16(); /* speech/music classifier improvement */ - FOR(i = 0; i < BUF_LEN; i++) + FOR( i = 0; i < BUF_LEN; i++ ) { hSpMusClas->buf_flux_fx[i] = -12800; - move16(); /*-100.0 in Q7 */ + move16(); /*-100.0 in Q7 */ hSpMusClas->buf_pkh_fx[i] = 0; move16(); hSpMusClas->buf_epsP_tilt_fx[i] = 0; @@ -132,24 +133,24 @@ void speech_music_clas_init_fx( move16(); } - set16_fx(hSpMusClas->lpe_buf_fx, 0, HANG_LEN_INIT); - set16_fx(hSpMusClas->voicing_buf_fx, 0, HANG_LEN_INIT); + set16_fx( hSpMusClas->lpe_buf_fx, 0, HANG_LEN_INIT ); + set16_fx( hSpMusClas->voicing_buf_fx, 0, HANG_LEN_INIT ); hSpMusClas->gsc_hangover = 0; move16(); - set16_fx(hSpMusClas->sparse_buf_fx, 0, HANG_LEN_INIT); - set16_fx(hSpMusClas->hf_spar_buf_fx, 0, HANG_LEN_INIT); + set16_fx( hSpMusClas->sparse_buf_fx, 0, HANG_LEN_INIT ); + set16_fx( hSpMusClas->hf_spar_buf_fx, 0, HANG_LEN_INIT ); hSpMusClas->LT_sparse_fx = 0; move16(); hSpMusClas->gsc_cnt = 0; move16(); - set16_fx(hSpMusClas->old_Bin_E_fx, 0, 3 * N_OLD_BIN_E); - set16_fx(hSpMusClas->buf_etot_fx, 0, 4); - set16_fx(hSpMusClas->buf_dlp_fx, 0, 10); + set16_fx( hSpMusClas->old_Bin_E_fx, 0, 3 * N_OLD_BIN_E ); + set16_fx( hSpMusClas->buf_etot_fx, 0, 4 ); + set16_fx( hSpMusClas->buf_dlp_fx, 0, 10 ); hSpMusClas->UV_cnt1 = 300; move16(); hSpMusClas->LT_UV_cnt1_fx = 16000; - move16(); /*250.0f in Q6 */ + move16(); /*250.0f in Q6 */ hSpMusClas->onset_cnt = 0; move16(); hSpMusClas->attack_hangover = 0; @@ -159,7 +160,7 @@ void speech_music_clas_init_fx( hSpMusClas->dec_mov1_fx = 0; move16(); hSpMusClas->mov_log_max_spl_fx = 25600; - move16(); /*200.0 in Q7 */ + move16(); /*200.0 in Q7 */ hSpMusClas->old_lt_diff_fx[0] = 0; move16(); hSpMusClas->old_lt_diff_fx[1] = 0; @@ -168,7 +169,7 @@ void speech_music_clas_init_fx( /* GSC - pitch excitation parameters */ hSpMusClas->high_stable_cor = 0; move16(); - set16_fx(hSpMusClas->var_cor_t_fx, 0, VAR_COR_LEN); + set16_fx( hSpMusClas->var_cor_t_fx, 0, VAR_COR_LEN ); hSpMusClas->lps_fx = 0; move16(); @@ -179,12 +180,12 @@ void speech_music_clas_init_fx( hSpMusClas->ener_RAT_fx = 0; /* speech/music classification */ - set16_fx(hSpMusClas->lt_old_mode, 1, 3); - hSpMusClas->lt_voicing = 16384/*0.5f Q15*/; - hSpMusClas->lt_corr = 16384/*0.5f Q15*/; + set16_fx( hSpMusClas->lt_old_mode, 1, 3 ); + hSpMusClas->lt_voicing = 16384 /*0.5f Q15*/; + hSpMusClas->lt_corr = 16384 /*0.5f Q15*/; hSpMusClas->lt_tonality = 0; move32(); - set16_fx(hSpMusClas->lt_corr_pitch, 0, 3); + set16_fx( hSpMusClas->lt_corr_pitch, 0, 3 ); hSpMusClas->lt_hangover = 0; move16(); hSpMusClas->lowrate_pitchGain = 0; @@ -193,9 +194,9 @@ void speech_music_clas_init_fx( hSpMusClas->lt_music_hangover = 0; move16(); - set16_fx(hSpMusClas->tonality2_buf_fx, 0, HANG_LEN_INIT); - set16_fx(hSpMusClas->tonality3_buf_fx, 0, HANG_LEN_INIT); - set16_fx(hSpMusClas->LPCErr_buf_fx, 0, HANG_LEN_INIT); + set16_fx( hSpMusClas->tonality2_buf_fx, 0, HANG_LEN_INIT ); + set16_fx( hSpMusClas->tonality3_buf_fx, 0, HANG_LEN_INIT ); + set16_fx( hSpMusClas->LPCErr_buf_fx, 0, HANG_LEN_INIT ); hSpMusClas->lt_music_state = 0; move16(); hSpMusClas->lt_speech_state = 0; @@ -237,7 +238,7 @@ void speech_music_clas_init_fx( hSpMusClas->tdm_lt_Etot = 0.01f; hSpMusClas->lpn = 0.0f; #endif - + return; } @@ -257,23 +258,23 @@ void speech_music_clas_init_fx( *---------------------------------------------------------------------*/ void speech_music_classif_fx( - Encoder_State *st, /* i/o: state structure */ - const Word16 *new_inp, /* i : new input signal */ - const Word16 *inp, /* i : input signal to locate attach position */ - const Word16 localVAD_HE_SAD, /* i : HE-SAD flag without hangover */ - const Word16 lsp_new[M], /* i : LSPs in current frame Q15 */ - const Word16 cor_map_sum, /* i : correlation map sum (from multi-harmonic anal.)Q8*/ - const Word32 epsP[M+1], /* i : LP prediciton error Q_esp*/ - const Word32 PS[], /* i : energy spectrum Q_new+QSCALE*/ - const Word16 Etot, /* i : total frame energy Q8 */ - const Word16 old_cor, /* i : max correlation from previous frame Q15 */ - Word16 *attack_flag, /* o : flag to indicate if attack is to be treated by TC or GSC */ - Word16 non_sta, /* i : unbound non-stationarity for sp/mus classifier */ - Word16 relE, /* i : relative frame energy */ - Word16 Q_esp, /* i : scaling of esP */ - Word16 Q_inp, /* i : scaling of input */ + Encoder_State *st, /* i/o: state structure */ + const Word16 *new_inp, /* i : new input signal */ + const Word16 *inp, /* i : input signal to locate attach position */ + const Word16 localVAD_HE_SAD, /* i : HE-SAD flag without hangover */ + const Word16 lsp_new[M], /* i : LSPs in current frame Q15 */ + const Word16 cor_map_sum, /* i : correlation map sum (from multi-harmonic anal.)Q8*/ + const Word32 epsP[M + 1], /* i : LP prediciton error Q_esp*/ + const Word32 PS[], /* i : energy spectrum Q_new+QSCALE*/ + const Word16 Etot, /* i : total frame energy Q8 */ + const Word16 old_cor, /* i : max correlation from previous frame Q15 */ + Word16 *attack_flag, /* o : flag to indicate if attack is to be treated by TC or GSC */ + Word16 non_sta, /* i : unbound non-stationarity for sp/mus classifier */ + Word16 relE, /* i : relative frame energy */ + Word16 Q_esp, /* i : scaling of esP */ + Word16 Q_inp, /* i : scaling of input */ Word16 *high_lpn_flag_ptr, /* o : noise log prob flag for NOISE_EST */ - Word16 flag_spitch /* i : flag to indicate very short stable pitch */ + Word16 flag_spitch /* i : flag to indicate very short stable pitch */ ) { Word16 voi_fv, cor_map_sum_fv, LPCErr; @@ -281,16 +282,16 @@ void speech_music_classif_fx( /* 1st stage speech/music classifier based on the GMM model */ st->sp_aud_decision1 = sp_mus_classif_gmm_fx( st, localVAD_HE_SAD, lsp_new, cor_map_sum, - epsP, PS, non_sta, relE, &voi_fv, &cor_map_sum_fv, &LPCErr, Q_esp, high_lpn_flag_ptr ); + epsP, PS, non_sta, relE, &voi_fv, &cor_map_sum_fv, &LPCErr, Q_esp, high_lpn_flag_ptr ); test(); - IF ( EQ_16( st->codec_mode, MODE1) || EQ_32(st->sr_core, INT_FS_12k8)) + IF( EQ_16( st->codec_mode, MODE1 ) || EQ_32( st->sr_core, INT_FS_12k8 ) ) { /* Improvement of the 1st stage decision on mixed/music content */ test(); - IF ( st->Opt_SC_VBR == 0 && NE_32(st->total_brate, ACELP_24k40)) + IF( st->Opt_SC_VBR == 0 && NE_32( st->total_brate, ACELP_24k40 ) ) { music_mixed_classif_improv_fx( st, new_inp, epsP, Q_esp, Etot, old_cor, cor_map_sum ); } @@ -302,15 +303,15 @@ void speech_music_classif_fx( st->sp_aud_decision2 = st->sp_aud_decision1; move16(); - IF ( GT_16(st->bwidth,NB)) + IF( GT_16( st->bwidth, NB ) ) { - sp_mus_classif_2nd_fx( st, Etot, attack_flag, inp, Q_inp-1); + sp_mus_classif_2nd_fx( st, Etot, attack_flag, inp, Q_inp - 1 ); /* avoid switch to AUDIO/MUSIC class for very short stable high st->pitch_fx - and/or stable pitch with high correlation at low bitrates*/ + and/or stable pitch with high correlation at low bitrates*/ test(); test(); - IF ( flag_spitch && EQ_16(st->bwidth,WB) && LT_32(st->total_brate,ACELP_13k20)) + IF( flag_spitch && EQ_16( st->bwidth, WB ) && LT_32( st->total_brate, ACELP_13k20 ) ) { st->sp_aud_decision2 = 0; move16(); @@ -318,12 +319,11 @@ void speech_music_classif_fx( } - /* Context-based improvement of 1st and 2nd stage decision on stable tonal signals */ test(); - IF ( st->Opt_SC_VBR == 0 && NE_32(st->total_brate, ACELP_24k40)) + IF( st->Opt_SC_VBR == 0 && NE_32( st->total_brate, ACELP_24k40 ) ) { - tonal_context_improv_fx( st, PS, voi_fv, cor_map_sum_fv, LPCErr, Q_inp + QSCALE -2 ); + tonal_context_improv_fx( st, PS, voi_fv, cor_map_sum_fv, LPCErr, Q_inp + QSCALE - 2 ); } /* Avoid using LR-MDCT on sparse spectra, use GSC instead at 13.2 kbps (WB/SWB) */ @@ -331,15 +331,15 @@ void speech_music_classif_fx( test(); test(); test(); - IF ( !st->Opt_SC_VBR && EQ_32(st->total_brate, ACELP_13k20) && EQ_16(st->vad_flag,1)&& - ( EQ_16(st->bwidth, WB) || EQ_16(st->bwidth, SWB)) ) + IF( !st->Opt_SC_VBR && EQ_32( st->total_brate, ACELP_13k20 ) && EQ_16( st->vad_flag, 1 ) && + ( EQ_16( st->bwidth, WB ) || EQ_16( st->bwidth, SWB ) ) ) { detect_sparseness_fx( st, localVAD_HE_SAD, voi_fv ); } /* override speech/music classification to ACELP when background noise level reaches certain level */ /* this is a patch against mis-classifications during active noisy speech segments */ - IF ( GT_16(st->lp_noise_fx, 3072)) + IF( GT_16( st->lp_noise_fx, 3072 ) ) { st->sp_aud_decision1 = 0; move16(); @@ -352,26 +352,32 @@ void speech_music_classif_fx( st->GSC_noisy_speech = 0; move16(); - test();test();test();test();test();test(); - IF ( EQ_16(st->vad_flag,1)&&GE_32(st->total_brate,ACELP_13k20)&<_32(st->total_brate,ACELP_24k40)&& - GT_16(st->lp_noise_fx,3072) && st->sp_aud_decision1 == 0 && GE_16(st->bwidth,SWB) && - EQ_16(st->coder_type_raw,UNVOICED)) + test(); + test(); + test(); + test(); + test(); + test(); + IF( EQ_16( st->vad_flag, 1 ) && GE_32( st->total_brate, ACELP_13k20 ) && LT_32( st->total_brate, ACELP_24k40 ) && + GT_16( st->lp_noise_fx, 3072 ) && st->sp_aud_decision1 == 0 && GE_16( st->bwidth, SWB ) && + EQ_16( st->coder_type_raw, UNVOICED ) ) { st->GSC_noisy_speech = 1; move16(); } /* Select AUDIO frames */ - test();test(); - test();test(); - IF ( EQ_16(st->codec_mode,MODE1) && (st->sp_aud_decision2 || st->GSC_noisy_speech)) + test(); + test(); + test(); + test(); + IF( EQ_16( st->codec_mode, MODE1 ) && ( st->sp_aud_decision2 || st->GSC_noisy_speech ) ) { st->coder_type = AUDIO; move16(); hGSCEnc->noise_lev = NOISE_LEVEL_SP0; move16(); } - } ELSE { @@ -388,20 +394,20 @@ void speech_music_classif_fx( * Speech/music classification based on GMM model *---------------------------------------------------------------------*/ -static Word16 sp_mus_classif_gmm_fx( /* o : decision flag (1-music, 0-speech or noise) */ - Encoder_State *st_fx, /* i/o: state structure */ - const Word16 localVAD_HE_SAD, /* i : local VAD HE flag */ - const Word16 lsp_new[M], /* i : LSPs in current frame Q15 */ - const Word16 cor_map_sum, /* i : correlation map sum (from multi-harmonic anal.)Q8 */ - const Word32 epsP[M+1], /* i : LP prediciton error Q_esp */ - const Word32 PS[], /* i : energy spectrum Q_new+Qscale-2 */ - Word16 non_sta, /* i : unbound non-stationarity for sp/mus classifier */ - Word16 relE, /* i : relative frame energy */ - Word16 *voi_fv, /* o : scaled voicing feature */ - Word16 *cor_map_sum_fv, /* o : scaled correlation map feature */ - Word16 *LPCErr, /* o : scaled LP prediction error feature */ - Word16 Q_esp, /* i : scaling of epsP */ - Word16 *high_lpn_flag_ptr /* o : noise log prob flag for NOISE_EST */ +static Word16 sp_mus_classif_gmm_fx( /* o : decision flag (1-music, 0-speech or noise) */ + Encoder_State *st_fx, /* i/o: state structure */ + const Word16 localVAD_HE_SAD, /* i : local VAD HE flag */ + const Word16 lsp_new[M], /* i : LSPs in current frame Q15 */ + const Word16 cor_map_sum, /* i : correlation map sum (from multi-harmonic anal.)Q8 */ + const Word32 epsP[M + 1], /* i : LP prediciton error Q_esp */ + const Word32 PS[], /* i : energy spectrum Q_new+Qscale-2 */ + Word16 non_sta, /* i : unbound non-stationarity for sp/mus classifier */ + Word16 relE, /* i : relative frame energy */ + Word16 *voi_fv, /* o : scaled voicing feature */ + Word16 *cor_map_sum_fv, /* o : scaled correlation map feature */ + Word16 *LPCErr, /* o : scaled LP prediction error feature */ + Word16 Q_esp, /* i : scaling of epsP */ + Word16 *high_lpn_flag_ptr /* o : noise log prob flag for NOISE_EST */ ) { Word16 i, k, p, dec, vad; @@ -414,7 +420,7 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decision flag (1-music, 0-speech Word32 mx; Word32 sum_PS; Word16 ftmp, tmp16; - Word16 xm[N_FEATURES]; + Word16 xm[N_FEATURES]; Word16 lps, lpm; Word16 lpn; Word16 e_tmp, f_tmp; @@ -425,11 +431,11 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decision flag (1-music, 0-speech Word16 ps_diff_16; Word32 dPS[128], PS_norm[128]; Word32 lepsP1; - Word32 max_s=0, max_m=0, py_s, py_m; - Word32 max_n, py_n; /* pyn */ - Word16 ishift[12] = {8,0,2,2,2,2,2,1,0,2,2,1}; + Word32 max_s = 0, max_m = 0, py_s, py_m; + Word32 max_n, py_n; /* pyn */ + Word16 ishift[12] = { 8, 0, 2, 2, 2, 2, 2, 1, 0, 2, 2, 1 }; Word16 tmp; - Word16 tmp1,tmp2,exp2,scale,exp3; + Word16 tmp1, tmp2, exp2, scale, exp3; SP_MUS_CLAS_HANDLE hSpMusClas = st_fx->hSpMusClas; HQ_ENC_HANDLE hHQ_core = st_fx->hHQ_core; #ifdef BASOP_NOGLOB_DECLARE_LOCAL @@ -449,109 +455,109 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decision flag (1-music, 0-speech /* [0] OL pitch Q0 */ /*(float)(pitch[0] + pitch[1] + pitch[2]) / 3.0f;*/ - L_tmp = L_mult(st_fx->pitch_fx[0], 10923); - L_tmp = L_mac(L_tmp, st_fx->pitch_fx[1], 10923); - L_tmp = L_mac(L_tmp, st_fx->pitch_fx[2], 10923); + L_tmp = L_mult( st_fx->pitch_fx[0], 10923 ); + L_tmp = L_mac( L_tmp, st_fx->pitch_fx[1], 10923 ); + L_tmp = L_mac( L_tmp, st_fx->pitch_fx[2], 10923 ); test(); - IF ( EQ_16(st_fx->tc_cnt,1)||EQ_16(st_fx->tc_cnt,2)) + IF( EQ_16( st_fx->tc_cnt, 1 ) || EQ_16( st_fx->tc_cnt, 2 ) ) { *pFV++ = st_fx->pitch_fx[2]; move16(); } ELSE { - *pFV++ = round_fx(L_tmp); + *pFV++ = round_fx( L_tmp ); } /* [1] voicing Q15 */ /*(float)(voicing[0] + voicing[1] + voicing[2]) / 3.0f*/ test(); - IF ( EQ_16(st_fx->tc_cnt,1)||EQ_16(st_fx->tc_cnt,2)) + IF( EQ_16( st_fx->tc_cnt, 1 ) || EQ_16( st_fx->tc_cnt, 2 ) ) { *pFV++ = st_fx->voicing_fx[2]; move16(); } ELSE { - L_tmp = L_mult(st_fx->voicing_fx[0], 10923); - L_tmp = L_mac(L_tmp, st_fx->voicing_fx[1], 10923); - L_tmp = L_mac(L_tmp, st_fx->voicing_fx[2], 10923); -#ifdef BASOP_NOGLOB + L_tmp = L_mult( st_fx->voicing_fx[0], 10923 ); + L_tmp = L_mac( L_tmp, st_fx->voicing_fx[1], 10923 ); + L_tmp = L_mac( L_tmp, st_fx->voicing_fx[2], 10923 ); +#ifdef BASOP_NOGLOB *pFV++ = round_fx_sat( L_tmp ); #else - *pFV++ = round_fx(L_tmp); + *pFV++ = round_fx( L_tmp ); #endif } /* [2,3,4,5,6] LSFs Q15*/ Copy( lsp_new, lsp, M ); lsf2acos_fact = 25735; - move16(); /* PI/6400 -> Q27 */ + move16(); /* PI/6400 -> Q27 */ /*ftmp = (float)acos(lsp[1...5]);*/ /**pFV++ = ftmp + st->last_lsp[1...5];*/ /*st->last_lsp[1...5] = ftmp;*/ - FOR(i= 1; i < M_LSP_SPMUS; i++) + FOR( i = 1; i < M_LSP_SPMUS; i++ ) { - L_tmp = sub_lsp2lsf_fx(lsp[i]); - tmp16 = round_fx(L_shl(L_mult0(extract_l(L_tmp),lsf2acos_fact),2)); - *pFV++ = add(tmp16, hSpMusClas->last_lsp_fx[i]); - move16(); /*Q13*/ + L_tmp = sub_lsp2lsf_fx( lsp[i] ); + tmp16 = round_fx( L_shl( L_mult0( extract_l( L_tmp ), lsf2acos_fact ), 2 ) ); + *pFV++ = add( tmp16, hSpMusClas->last_lsp_fx[i] ); + move16(); /*Q13*/ hSpMusClas->last_lsp_fx[i] = tmp16; move16(); } /* [7] cor_map_sum Q8 */ - *pFV++ = round_fx(L_mac(L_mult(cor_map_sum, 16384), hSpMusClas->last_cor_map_sum_fx, 16384)); /* Q8 ->Q7*/ + *pFV++ = round_fx( L_mac( L_mult( cor_map_sum, 16384 ), hSpMusClas->last_cor_map_sum_fx, 16384 ) ); /* Q8 ->Q7*/ hSpMusClas->last_cor_map_sum_fx = cor_map_sum; move16(); /* [8] non_sta Q8*/ - *pFV++ = round_fx(L_mac(L_mult(non_sta,16384), hSpMusClas->last_non_sta_fx, 16384)); /* Q8 -> Q7 */ + *pFV++ = round_fx( L_mac( L_mult( non_sta, 16384 ), hSpMusClas->last_non_sta_fx, 16384 ) ); /* Q8 -> Q7 */ hSpMusClas->last_non_sta_fx = non_sta; move16(); /* [9] epsP Q10 */ - IF ( EQ_16(st_fx->bwidth,NB)) + IF( EQ_16( st_fx->bwidth, NB ) ) { *pFV++ = -1687; - move16(); /*Q10*/ + move16(); /*Q10*/ } ELSE { /*lepsP1 = (float)log(epsP[1] + 1e-5f);*/ - IF(epsP[1] != 0) + IF( epsP[1] != 0 ) { - e_tmp = norm_l(epsP[1]); - f_tmp = Log2_norm_lc(L_shl(epsP[1],e_tmp)); - e_tmp = sub(30,add(e_tmp,Q_esp)); - lepsP1 = Mpy_32_16(e_tmp, f_tmp, 22713); /* Q16 */ /* 22713 = ln(2) in Q15 */ + e_tmp = norm_l( epsP[1] ); + f_tmp = Log2_norm_lc( L_shl( epsP[1], e_tmp ) ); + e_tmp = sub( 30, add( e_tmp, Q_esp ) ); + lepsP1 = Mpy_32_16( e_tmp, f_tmp, 22713 ); /* Q16 */ /* 22713 = ln(2) in Q15 */ } ELSE { - lepsP1 = L_deposit_l(0); + lepsP1 = L_deposit_l( 0 ); } /*ftmp = (float)log(epsP[13]);*/ - IF(epsP[13] != 0) + IF( epsP[13] != 0 ) { - e_tmp = norm_l(epsP[13]); - f_tmp = Log2_norm_lc(L_shl(epsP[13],e_tmp)); - e_tmp = sub(30,add(e_tmp,Q_esp)); - L_tmp = Mpy_32_16(e_tmp, f_tmp, 22713); /* Q16 */ /* 22713 = ln(2) in Q15 */ + e_tmp = norm_l( epsP[13] ); + f_tmp = Log2_norm_lc( L_shl( epsP[13], e_tmp ) ); + e_tmp = sub( 30, add( e_tmp, Q_esp ) ); + L_tmp = Mpy_32_16( e_tmp, f_tmp, 22713 ); /* Q16 */ /* 22713 = ln(2) in Q15 */ } ELSE { - L_tmp = L_deposit_l(0); + L_tmp = L_deposit_l( 0 ); } /*ftmp = (float)log(epsP[13]) - lepsP1;*/ - L_tmp = L_sub(L_tmp, lepsP1); /*Q16 */ - ftmp = round_fx(L_shl(L_tmp,10)); /*Q10 */ + L_tmp = L_sub( L_tmp, lepsP1 ); /*Q16 */ + ftmp = round_fx( L_shl( L_tmp, 10 ) ); /*Q10 */ /**pFV++ = ftmp + st->past_epsP2;*/ - *pFV++ = add(ftmp, hSpMusClas->past_epsP2_fx); + *pFV++ = add( ftmp, hSpMusClas->past_epsP2_fx ); move16(); /*Q10 */ /*st->past_epsP2 = ftmp;*/ @@ -560,65 +566,65 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decision flag (1-music, 0-speech } /* calculation of differential normalized power spectrum */ - sum_PS = L_deposit_l(0); - FOR ( i = LOWEST_FBIN; i < HIGHEST_FBIN; i++ ) + sum_PS = L_deposit_l( 0 ); + FOR( i = LOWEST_FBIN; i < HIGHEST_FBIN; i++ ) { #ifdef BASOP_NOGLOB - sum_PS = L_add_o(sum_PS,PS[i], &Overflow); -#else /* BASOP_NOGLOB */ - sum_PS = L_add(sum_PS,PS[i]); + sum_PS = L_add_o( sum_PS, PS[i], &Overflow ); +#else /* BASOP_NOGLOB */ + sum_PS = L_add( sum_PS, PS[i] ); #endif /* BASOP_NOGLOB */ } - exp1 = norm_l(sum_PS); + exp1 = norm_l( sum_PS ); #ifdef BASOP_NOGLOB - tmp1 = round_fx_o(L_shl(sum_PS,exp1), &Overflow); -#else /* BASOP_NOGLOB */ - tmp1 = round_fx(L_shl(sum_PS,exp1)); + tmp1 = round_fx_o( L_shl( sum_PS, exp1 ), &Overflow ); +#else /* BASOP_NOGLOB */ + tmp1 = round_fx( L_shl( sum_PS, exp1 ) ); #endif /* BASOP_NOGLOB */ - exp1 = sub(30,exp1); + exp1 = sub( 30, exp1 ); - FOR ( i = LOWEST_FBIN; i < HIGHEST_FBIN; i++ ) + FOR( i = LOWEST_FBIN; i < HIGHEST_FBIN; i++ ) { /*PS_norm[i] = PS[i] / sum_PS;*/ /*dPS[i] = (float)fabs(PS_norm[i] - st->past_PS[i]);*/ - exp2 = norm_l(PS[i]); + exp2 = norm_l( PS[i] ); #ifdef BASOP_NOGLOB - tmp2 = round_fx_o(L_shl(PS[i],exp2), &Overflow); -#else /* BASOP_NOGLOB */ - tmp2 = round_fx(L_shl(PS[i],exp2)); + tmp2 = round_fx_o( L_shl( PS[i], exp2 ), &Overflow ); +#else /* BASOP_NOGLOB */ + tmp2 = round_fx( L_shl( PS[i], exp2 ) ); #endif /* BASOP_NOGLOB */ - exp2 = sub(30,exp2); + exp2 = sub( 30, exp2 ); - scale = shr(sub(tmp1, tmp2), 15); - tmp2 = shl(tmp2, scale); - exp2 = sub(exp2, scale); + scale = shr( sub( tmp1, tmp2 ), 15 ); + tmp2 = shl( tmp2, scale ); + exp2 = sub( exp2, scale ); - exp3 = sub(exp1,exp2); + exp3 = sub( exp1, exp2 ); - tmp = div_s(tmp2, tmp1); /*Q(15+exp3) */ - PS_norm[i] = L_shl(tmp,sub(10,exp3)); + tmp = div_s( tmp2, tmp1 ); /*Q(15+exp3) */ + PS_norm[i] = L_shl( tmp, sub( 10, exp3 ) ); + move32(); /*Q25 */ + dPS[i] = L_abs( L_sub( PS_norm[i], hSpMusClas->past_PS_fx[i - LOWEST_FBIN] ) ); move32(); /*Q25 */ - dPS[i] = L_abs(L_sub(PS_norm[i], hSpMusClas->past_PS_fx[i-LOWEST_FBIN])); - move32(); /*Q25 */ } /* [10] ps_diff (spectral difference) Q10*/ ps_diff = 0; move16(); - FOR ( i = LOWEST_FBIN; i < HIGHEST_FBIN; i++ ) + FOR( i = LOWEST_FBIN; i < HIGHEST_FBIN; i++ ) { /*ps_diff += dPS[i];*/ - ps_diff = L_add(ps_diff,dPS[i]); /*Q25*/ + ps_diff = L_add( ps_diff, dPS[i] ); /*Q25*/ } /*ps_diff = (float)log(ps_diff + 1e-5f);*/ IF( ps_diff != 0 ) { - e_tmp = norm_l(ps_diff); - f_tmp = Log2_norm_lc(L_shl(ps_diff,e_tmp)); - e_tmp = sub(30-25,e_tmp); - ps_diff = Mpy_32_16(e_tmp, f_tmp, 22713);/* Q16 */ /* 22713 = ln(2) in Q15 */ - ps_diff_16 = round_fx(L_shl(ps_diff,10)); /*Q10 */ + e_tmp = norm_l( ps_diff ); + f_tmp = Log2_norm_lc( L_shl( ps_diff, e_tmp ) ); + e_tmp = sub( 30 - 25, e_tmp ); + ps_diff = Mpy_32_16( e_tmp, f_tmp, 22713 ); /* Q16 */ /* 22713 = ln(2) in Q15 */ + ps_diff_16 = round_fx( L_shl( ps_diff, 10 ) ); /*Q10 */ } ELSE { @@ -626,70 +632,70 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decision flag (1-music, 0-speech move16(); /*Q10 */ } - *pFV++ = add(ps_diff_16, hSpMusClas->past_ps_diff_fx); - move16();/*Q10 */ + *pFV++ = add( ps_diff_16, hSpMusClas->past_ps_diff_fx ); + move16(); /*Q10 */ hSpMusClas->past_ps_diff_fx = ps_diff_16; move16(); /*Q10 */ /* [11] ps_sta (spectral stationarity) Q11 */ ps_sta = 0; move16(); - FOR ( i = LOWEST_FBIN; i < HIGHEST_FBIN; i++ ) + FOR( i = LOWEST_FBIN; i < HIGHEST_FBIN; i++ ) { /*mx = PS_norm[i] > st->past_PS[i] ? PS_norm[i] : st->past_PS[i];*/ - IF (GT_32(PS_norm[i], hSpMusClas->past_PS_fx[i-LOWEST_FBIN])) + IF( GT_32( PS_norm[i], hSpMusClas->past_PS_fx[i - LOWEST_FBIN] ) ) { mx = PS_norm[i]; - move16(); /*Q25 */ + move16(); /*Q25 */ } ELSE { - mx = hSpMusClas->past_PS_fx[i-LOWEST_FBIN]; - move16(); /*Q25 */ + mx = hSpMusClas->past_PS_fx[i - LOWEST_FBIN]; + move16(); /*Q25 */ } /*ps_sta += mx / (dPS[i] + 1e-5f);*/ IF( !dPS[i] ) { - ps_sta = L_add(ps_sta,L_shr(mx,9)); /*Q16 */ + ps_sta = L_add( ps_sta, L_shr( mx, 9 ) ); /*Q16 */ } ELSE { - exp1 = norm_l(L_add(dPS[i],336)); + exp1 = norm_l( L_add( dPS[i], 336 ) ); #ifdef BASOP_NOGLOB - tmp1 = round_fx_o(L_shl_o(L_add(dPS[i],336),exp1, &Overflow), &Overflow); + tmp1 = round_fx_o( L_shl_o( L_add( dPS[i], 336 ), exp1, &Overflow ), &Overflow ); #else - tmp1 = round_fx(L_shl(L_add(dPS[i],336),exp1)); + tmp1 = round_fx( L_shl( L_add( dPS[i], 336 ), exp1 ) ); #endif - exp1 = sub(30,exp1); + exp1 = sub( 30, exp1 ); - exp2 = norm_l(mx); - tmp2 = round_fx(L_shl(mx,exp2)); - exp2 = sub(30,exp2); + exp2 = norm_l( mx ); + tmp2 = round_fx( L_shl( mx, exp2 ) ); + exp2 = sub( 30, exp2 ); - scale = shr(sub(tmp1, tmp2), 15); - tmp2 = shl(tmp2, scale); - exp2 = sub(exp2, scale); + scale = shr( sub( tmp1, tmp2 ), 15 ); + tmp2 = shl( tmp2, scale ); + exp2 = sub( exp2, scale ); - exp3 = sub(exp1,exp2); + exp3 = sub( exp1, exp2 ); move16(); - tmp = div_s(tmp2, tmp1); /*Q(15+exp3) */ - L_tmp = L_shl(tmp,sub(1,exp3)); /*Q16 */ - ps_sta = L_add(ps_sta,L_tmp); /*Q16 */ + tmp = div_s( tmp2, tmp1 ); /*Q(15+exp3) */ + L_tmp = L_shl( tmp, sub( 1, exp3 ) ); /*Q16 */ + ps_sta = L_add( ps_sta, L_tmp ); /*Q16 */ } } /**pFV++ = (float)log(ps_sta + 1e-5f);*/ - ps_sta = L_add(ps_sta, 336); - e_tmp = norm_l(ps_sta); - f_tmp = Log2_norm_lc(L_shl(ps_sta,e_tmp)); - e_tmp = sub(30-16,e_tmp); - L_tmp = Mpy_32_16(e_tmp, f_tmp, 22713); /* Q16 */ /* 22713 = ln(2) in Q15 */ - *pFV++ = round_fx(L_shl(L_tmp,11)); /*Q11 */ + ps_sta = L_add( ps_sta, 336 ); + e_tmp = norm_l( ps_sta ); + f_tmp = Log2_norm_lc( L_shl( ps_sta, e_tmp ) ); + e_tmp = sub( 30 - 16, e_tmp ); + L_tmp = Mpy_32_16( e_tmp, f_tmp, 22713 ); /* Q16 */ /* 22713 = ln(2) in Q15 */ + *pFV++ = round_fx( L_shl( L_tmp, 11 ) ); /*Q11 */ /* update PS vector */ - Copy32( &PS_norm[LOWEST_FBIN], hSpMusClas->past_PS_fx, HIGHEST_FBIN-LOWEST_FBIN ); + Copy32( &PS_norm[LOWEST_FBIN], hSpMusClas->past_PS_fx, HIGHEST_FBIN - LOWEST_FBIN ); /*------------------------------------------------------------------* * Scaling of the feature vector @@ -704,7 +710,7 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decision flag (1-music, 0-speech pFV = FV; move16(); - IF ( EQ_16(st_fx->bwidth,NB)) + IF( EQ_16( st_fx->bwidth, NB ) ) { pSF_m = SF_8k_mult_fx; pSF_a = SF_8k_add_fx; @@ -715,13 +721,13 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decision flag (1-music, 0-speech pSF_a = SF_add_fx; } - FOR ( i=0; ilpm_fx = lpm; @@ -852,11 +857,11 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decision flag (1-music, 0-speech move16(); /* determine HQ GENERIC speech class */ - IF (hHQ_core != NULL) + IF( hHQ_core != NULL ) { hHQ_core->hq_generic_speech_class = 0; move16(); - if (GT_16(lps, add(lpm, 256))) + if ( GT_16( lps, add( lpm, 256 ) ) ) { hHQ_core->hq_generic_speech_class = 1; move16(); @@ -867,16 +872,16 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decision flag (1-music, 0-speech * State machine (sp_mus_state < 0 .. inactive, > 0 .. entry, = 0 .. active ) *------------------------------------------------------------------*/ - IF ( vad ) + IF( vad ) { test(); test(); test(); - IF ( LT_16(relE,-20*256)||(LE_16(lps,-5*512)&&LE_16(lpm,-5*512))) + IF( LT_16( relE, -20 * 256 ) || ( LE_16( lps, -5 * 512 ) && LE_16( lpm, -5 * 512 ) ) ) { - IF (hSpMusClas->sp_mus_state > 0 ) + IF( hSpMusClas->sp_mus_state > 0 ) { - if ( LT_16(hSpMusClas->sp_mus_state,HANG_LEN)) + if ( LT_16( hSpMusClas->sp_mus_state, HANG_LEN ) ) { /* energy is too low but we are in entry period -> reset the inactive counter to allow new entry later */ hSpMusClas->inact_cnt = 0; @@ -887,15 +892,15 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decision flag (1-music, 0-speech hSpMusClas->sp_mus_state = 0; move16(); } - ELSE IF ( GT_16(hSpMusClas->sp_mus_state,-HANG_LEN)) + ELSE IF( GT_16( hSpMusClas->sp_mus_state, -HANG_LEN ) ) { /* energy is still too low -> we are still in instable state */ - hSpMusClas->sp_mus_state = sub(hSpMusClas->sp_mus_state,1); + hSpMusClas->sp_mus_state = sub( hSpMusClas->sp_mus_state, 1 ); } } - ELSE IF (hSpMusClas->sp_mus_state <= 0 ) + ELSE IF( hSpMusClas->sp_mus_state <= 0 ) { - IF (hSpMusClas->inact_cnt == 0 ) + IF( hSpMusClas->inact_cnt == 0 ) { hSpMusClas->sp_mus_state = 1; @@ -911,48 +916,48 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decision flag (1-music, 0-speech hSpMusClas->inact_cnt = 12; move16(); } - ELSE IF (hSpMusClas->sp_mus_state > 0 && LT_16(hSpMusClas->sp_mus_state,HANG_LEN)) + ELSE IF( hSpMusClas->sp_mus_state > 0 && LT_16( hSpMusClas->sp_mus_state, HANG_LEN ) ) { /* we are inside an entry period -> increment the counter of entry frames */ - hSpMusClas->sp_mus_state = add(hSpMusClas->sp_mus_state,1); + hSpMusClas->sp_mus_state = add( hSpMusClas->sp_mus_state, 1 ); } test(); - if (hSpMusClas->sp_mus_state < 0 && hSpMusClas->inact_cnt > 0 ) + if ( hSpMusClas->sp_mus_state < 0 && hSpMusClas->inact_cnt > 0 ) { - hSpMusClas->inact_cnt = sub(hSpMusClas->inact_cnt,1); + hSpMusClas->inact_cnt = sub( hSpMusClas->inact_cnt, 1 ); } } ELSE { test(); - IF (hSpMusClas->sp_mus_state > 0 && LT_16(hSpMusClas->sp_mus_state,HANG_LEN)) + IF( hSpMusClas->sp_mus_state > 0 && LT_16( hSpMusClas->sp_mus_state, HANG_LEN ) ) { hSpMusClas->inact_cnt = 0; move16(); } - ELSE IF (hSpMusClas->inact_cnt > 0 ) + ELSE IF( hSpMusClas->inact_cnt > 0 ) { - hSpMusClas->inact_cnt = sub(hSpMusClas->inact_cnt,1); + hSpMusClas->inact_cnt = sub( hSpMusClas->inact_cnt, 1 ); } test(); - IF (hSpMusClas->sp_mus_state > 0 && LT_16(hSpMusClas->sp_mus_state,HANG_LEN)) + IF( hSpMusClas->sp_mus_state > 0 && LT_16( hSpMusClas->sp_mus_state, HANG_LEN ) ) { hSpMusClas->sp_mus_state = -HANG_LEN; move16(); } - ELSE IF (hSpMusClas->sp_mus_state > 0 ) + ELSE IF( hSpMusClas->sp_mus_state > 0 ) { hSpMusClas->sp_mus_state = -1; move16(); } - ELSE IF ( GT_16(hSpMusClas->sp_mus_state,-HANG_LEN)) + ELSE IF( GT_16( hSpMusClas->sp_mus_state, -HANG_LEN ) ) { /* we are in inactive state */ - hSpMusClas->sp_mus_state = sub(hSpMusClas->sp_mus_state,1); + hSpMusClas->sp_mus_state = sub( hSpMusClas->sp_mus_state, 1 ); } } @@ -963,11 +968,11 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decision flag (1-music, 0-speech /* decision without hangover (0 - speech/noise, 1 - music) */ logic16(); - dec = sub(lpm,lps) > 0; + dec = sub( lpm, lps ) > 0; move16(); - dlp = sub(lpm,lps); /*Q9*/ + dlp = sub( lpm, lps ); /*Q9*/ - IF ( !vad ) + IF( !vad ) { dec = 0; move16(); @@ -977,23 +982,23 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decision flag (1-music, 0-speech /* calculate weight based on relE (close to 0.01 in low-E regions, close to 1 in high-E regions) */ /*wrelE = 1.0f + relE/15;*/ - wrelE = add(2048, mult_r(relE,17476)); /* 1/15 in Q18 -> 17476 result in Q11 */ + wrelE = add( 2048, mult_r( relE, 17476 ) ); /* 1/15 in Q18 -> 17476 result in Q11 */ - wrelE = s_min(wrelE, 2048); - wrelE = s_max(wrelE, 20); + wrelE = s_min( wrelE, 2048 ); + wrelE = s_max( wrelE, 20 ); /* calculate weight based on drops of dlp (close to 1 during sudden drops of dlp, close to 0 otherwise) */ test(); - IF ( dlp < 0 && LT_16(dlp, hSpMusClas->past_dlp_fx[0])) + IF( dlp < 0 && LT_16( dlp, hSpMusClas->past_dlp_fx[0] ) ) { - IF (hSpMusClas->past_dlp_fx[0] > 0 ) + IF( hSpMusClas->past_dlp_fx[0] > 0 ) { - hSpMusClas->wdrop_fx = negate(dlp); /*Q9*/ + hSpMusClas->wdrop_fx = negate( dlp ); /*Q9*/ } ELSE { - hSpMusClas->wdrop_fx = add(hSpMusClas->wdrop_fx, sub(hSpMusClas->past_dlp_fx[0], dlp)); /*Q9*/ + hSpMusClas->wdrop_fx = add( hSpMusClas->wdrop_fx, sub( hSpMusClas->past_dlp_fx[0], dlp ) ); /*Q9*/ } } ELSE @@ -1003,22 +1008,22 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decision flag (1-music, 0-speech } /*wdrop = st->wdrop/20;*/ - wdrop = mult_r(hSpMusClas->wdrop_fx, 26214); /*Q9*Q19->Q13*/ - wdrop = s_min(wdrop,8192); /* limitation [0.1,1] Q13 */ - wdrop = s_max(wdrop,819); + wdrop = mult_r( hSpMusClas->wdrop_fx, 26214 ); /*Q9*Q19->Q13*/ + wdrop = s_min( wdrop, 8192 ); /* limitation [0.1,1] Q13 */ + wdrop = s_max( wdrop, 819 ); /* combine weights into one */ /*wght = wrelE * wdrop;*/ - wght = mult_r(wrelE, wdrop); /* Q11*Q13 -> Q9*/ - wght = s_max(wght,5); + wght = mult_r( wrelE, wdrop ); /* Q11*Q13 -> Q9*/ + wght = s_max( wght, 5 ); /* calculate weighted decision */ /*st->wdlp_0_95_sp = wght * dlp + (1 - wght) * st->wdlp_0_95_sp;*/ /* = Q9 * Q9 + (Q9-Q9)*Q9 */ - L_tmp = L_mac(L_mult(wght, dlp), sub(512, wght), hSpMusClas->wdlp_0_95_sp_fx); - hSpMusClas->wdlp_0_95_sp_fx = round_fx(L_shl(L_tmp, 6)); + L_tmp = L_mac( L_mult( wght, dlp ), sub( 512, wght ), hSpMusClas->wdlp_0_95_sp_fx ); + hSpMusClas->wdlp_0_95_sp_fx = round_fx( L_shl( L_tmp, 6 ) ); - if ( EQ_16(hSpMusClas->sp_mus_state,-HANG_LEN)) + if ( EQ_16( hSpMusClas->sp_mus_state, -HANG_LEN ) ) { hSpMusClas->wdlp_0_95_sp_fx = 0; move16(); @@ -1030,30 +1035,30 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decision flag (1-music, 0-speech test(); test(); - IF ( !vad && EQ_16(hSpMusClas->sp_mus_state,-HANG_LEN)) + IF( !vad && EQ_16( hSpMusClas->sp_mus_state, -HANG_LEN ) ) { /* inactive state */ dec = 0; move16(); } - ELSE IF (hSpMusClas->sp_mus_state <= 0 ) + ELSE IF( hSpMusClas->sp_mus_state <= 0 ) { /* transition from active to inactive state or instable state */ dec = hSpMusClas->past_dec[0]; move16(); } - ELSE IF (hSpMusClas->sp_mus_state > 0 && LT_16(hSpMusClas->sp_mus_state,HANG_LEN)) + ELSE IF( hSpMusClas->sp_mus_state > 0 && LT_16( hSpMusClas->sp_mus_state, HANG_LEN ) ) { /* entry state -> final decision is calculated based on weighted average of past non-binary decisions */ - L_tmp = L_mult(w_spmus_fx[hSpMusClas->sp_mus_state-1][0], dlp); /*Q15*Q9 */ + L_tmp = L_mult( w_spmus_fx[hSpMusClas->sp_mus_state - 1][0], dlp ); /*Q15*Q9 */ /*ftmp += dotp( &w[st_fx->sp_mus_state-1][1], st_fx->past_dlp_fx, HANG_LEN-1 );*/ - L_tmp = L_add(L_tmp, Dot_product( &w_spmus_fx[hSpMusClas->sp_mus_state-1][1], hSpMusClas->past_dlp_fx, HANG_LEN-1 )); + L_tmp = L_add( L_tmp, Dot_product( &w_spmus_fx[hSpMusClas->sp_mus_state - 1][1], hSpMusClas->past_dlp_fx, HANG_LEN - 1 ) ); logic16(); move16(); /*dec = ftmp > 2.0f;*/ - dec = L_sub(L_tmp, 2*(1<<25))>0; + dec = L_sub( L_tmp, 2 * ( 1 << 25 ) ) > 0; } ELSE { @@ -1062,13 +1067,13 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decision flag (1-music, 0-speech test(); test(); test(); - IF (hSpMusClas->wdlp_0_95_sp_fx > 0 && hSpMusClas->past_dec[0] == 0 && hSpMusClas->past_dec[1] == 0 && hSpMusClas->past_dec[2] == 0 ) + IF( hSpMusClas->wdlp_0_95_sp_fx > 0 && hSpMusClas->past_dec[0] == 0 && hSpMusClas->past_dec[1] == 0 && hSpMusClas->past_dec[2] == 0 ) { /* switching from speech to music */ dec = 1; move16(); } - ELSE IF (hSpMusClas->past_dec[0] == 1 && hSpMusClas->wdlp_0_95_sp_fx < 0 ) + ELSE IF( hSpMusClas->past_dec[0] == 1 && hSpMusClas->wdlp_0_95_sp_fx < 0 ) { /* switching from music to speech */ dec = 0; @@ -1087,12 +1092,12 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decision flag (1-music, 0-speech *------------------------------------------------------------------*/ /* update the buffer of past non-binary decisions */ - Copy( &hSpMusClas->past_dlp_fx[0], &hSpMusClas->past_dlp_fx[1], HANG_LEN-2 ); + Copy( &hSpMusClas->past_dlp_fx[0], &hSpMusClas->past_dlp_fx[1], HANG_LEN - 2 ); hSpMusClas->past_dlp_fx[0] = dlp; move16(); /* update the buffer of past binary decisions */ - Copy( &hSpMusClas->past_dec[0], &hSpMusClas->past_dec[1], HANG_LEN-2 ); + Copy( &hSpMusClas->past_dec[0], &hSpMusClas->past_dec[1], HANG_LEN - 2 ); hSpMusClas->past_dec[0] = dec; move16(); @@ -1107,12 +1112,11 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decision flag (1-music, 0-speech *---------------------------------------------------------------------*/ static void sp_mus_classif_2nd_fx( - Encoder_State *st, /* i/o: Encoder state structure */ - const Word16 Etot, /* i : total frame energy */ - Word16 *attack_flag, /* i/o: attack flag (GSC or TC) */ - const Word16 *inp, /* i : input signal */ - const Word16 Qx -) + Encoder_State *st, /* i/o: Encoder state structure */ + const Word16 Etot, /* i : total frame energy */ + Word16 *attack_flag, /* i/o: attack flag (GSC or TC) */ + const Word16 *inp, /* i : input signal */ + const Word16 Qx ) { Word16 attack; SP_MUS_CLAS_HANDLE hSpMusClas = st->hSpMusClas; @@ -1122,8 +1126,7 @@ static void sp_mus_classif_2nd_fx( move16(); /* signal stability estimation */ - stab_est_fx( Etot, hSpMusClas->gsc_lt_diff_etot_fx, &hSpMusClas->gsc_mem_etot_fx - , &hSpMusClas->gsc_nb_thr_3, &hSpMusClas->gsc_nb_thr_1, hSpMusClas->gsc_thres_fx, &hSpMusClas->gsc_last_music_flag, st->vad_flag ); + stab_est_fx( Etot, hSpMusClas->gsc_lt_diff_etot_fx, &hSpMusClas->gsc_mem_etot_fx, &hSpMusClas->gsc_nb_thr_3, &hSpMusClas->gsc_nb_thr_1, hSpMusClas->gsc_thres_fx, &hSpMusClas->gsc_last_music_flag, st->vad_flag ); /* calculate variance of correlation */ var_cor_calc_fx( st->old_corr_fx, &hSpMusClas->mold_corr_fx, hSpMusClas->var_cor_t_fx, &hSpMusClas->high_stable_cor ); @@ -1131,7 +1134,8 @@ static void sp_mus_classif_2nd_fx( /* attack detection */ attack = attack_det_fx( inp, Qx, st->clas, st->localVAD, st->coder_type, st->total_brate #ifdef IVAS_CODE - , EVS_MONO, st->clas, hSpMusClas->finc_prev, &hSpMusClas->lt_finc, &hSpMusClas->last_strong_attack + , + EVS_MONO, st->clas, hSpMusClas->finc_prev, &hSpMusClas->lt_finc, &hSpMusClas->last_strong_attack #endif ); @@ -1141,17 +1145,17 @@ static void sp_mus_classif_2nd_fx( test(); test(); test(); - IF( EQ_16(st->sp_aud_decision1,1)) + IF( EQ_16( st->sp_aud_decision1, 1 ) ) { test(); test(); test(); - IF( LT_16(hSpMusClas->ener_RAT_fx,5898) && GT_16(hSpMusClas->lt_dec_thres_fx,7680)) + IF( LT_16( hSpMusClas->ener_RAT_fx, 5898 ) && GT_16( hSpMusClas->lt_dec_thres_fx, 7680 ) ) { st->sp_aud_decision2 = 0; move16(); } - ELSE IF( EQ_16(hSpMusClas->high_stable_cor, 1)&&GE_16(st->pitch_fx[0],130)) + ELSE IF( EQ_16( hSpMusClas->high_stable_cor, 1 ) && GE_16( st->pitch_fx[0], 130 ) ) { /* prevent GSC in highly correlated signal with low energy variation */ /* this is basically a patch against bassoon-type of music */ @@ -1159,21 +1163,21 @@ static void sp_mus_classif_2nd_fx( move16(); test(); - IF( EQ_16(st->codec_mode,MODE1)&&EQ_16(st->coder_type,TRANSITION)) + IF( EQ_16( st->codec_mode, MODE1 ) && EQ_16( st->coder_type, TRANSITION ) ) { st->coder_type = GENERIC; move16(); } } - ELSE IF( GT_16(hSpMusClas->gsc_lt_diff_etot_fx[MAX_LT-1],1152) && - GT_16(sub(hSpMusClas->gsc_lt_diff_etot_fx[MAX_LT-1], hSpMusClas->gsc_lt_diff_etot_fx[MAX_LT-2]),2560)) /* 10.0f in Q8 */ + ELSE IF( GT_16( hSpMusClas->gsc_lt_diff_etot_fx[MAX_LT - 1], 1152 ) && + GT_16( sub( hSpMusClas->gsc_lt_diff_etot_fx[MAX_LT - 1], hSpMusClas->gsc_lt_diff_etot_fx[MAX_LT - 2] ), 2560 ) ) /* 10.0f in Q8 */ { - IF ( EQ_16(st->tc_cnt,1)) + IF( EQ_16( st->tc_cnt, 1 ) ) { st->sp_aud_decision2 = 0; move16(); - IF( EQ_16(st->codec_mode,MODE1)) + IF( EQ_16( st->codec_mode, MODE1 ) ) { st->coder_type = TRANSITION; move16(); @@ -1181,20 +1185,20 @@ static void sp_mus_classif_2nd_fx( } ELSE { - IF( GE_16(attack, ATT_3LSUB_POS)) + IF( GE_16( attack, ATT_3LSUB_POS ) ) { /* do TC coding if attack is located in the last subframe */ st->sp_aud_decision2 = 0; move16(); - *attack_flag = add(attack, 1); + *attack_flag = add( attack, 1 ); move16(); - IF( EQ_16(st->codec_mode,MODE1)) + IF( EQ_16( st->codec_mode, MODE1 ) ) { st->coder_type = TRANSITION; move16(); } } - ELSE IF( GE_16(attack,ATT_SEG_LEN/2)) + ELSE IF( GE_16( attack, ATT_SEG_LEN / 2 ) ) { /* do GSC coding if attack is located after the first quarter of the first subframe */ /* (pre-echo will be treated at the decoder side) */ @@ -1206,15 +1210,14 @@ static void sp_mus_classif_2nd_fx( } } } - ELSE IF( EQ_16(st->localVAD,1)&&EQ_16(st->coder_type,GENERIC)&& - ( (GE_16(attack,ATT_3LSUB_POS) && LT_32(st->total_brate,ACELP_24k40)) || - (GE_16(attack,ATT_3LSUB_POS_16k) && GE_32(st->total_brate,ACELP_24k40) && LT_32(st->total_brate,ACELP_48k)) ) - ) + ELSE IF( EQ_16( st->localVAD, 1 ) && EQ_16( st->coder_type, GENERIC ) && + ( ( GE_16( attack, ATT_3LSUB_POS ) && LT_32( st->total_brate, ACELP_24k40 ) ) || + ( GE_16( attack, ATT_3LSUB_POS_16k ) && GE_32( st->total_brate, ACELP_24k40 ) && LT_32( st->total_brate, ACELP_48k ) ) ) ) { /* do TC coding if attack is located in the last subframe */ - *attack_flag = add(attack, 1); + *attack_flag = add( attack, 1 ); move16(); - IF( EQ_16(st->codec_mode,MODE1)) + IF( EQ_16( st->codec_mode, MODE1 ) ) { st->coder_type = TRANSITION; move16(); @@ -1235,15 +1238,15 @@ static void var_cor_calc_fx( const Word16 old_corr, Word16 *mold_corr, Word16 var_cor_t[], - Word16 *high_stable_cor -) + Word16 *high_stable_cor ) { Word16 i, var_cor; /* update buffer of old correlation values */ - FOR( i = VAR_COR_LEN-1; i > 0; i-- ) + FOR( i = VAR_COR_LEN - 1; i > 0; i-- ) { - var_cor_t[i] = var_cor_t[i-1]; /*Q11*/ move16(); + var_cor_t[i] = var_cor_t[i - 1]; /*Q11*/ + move16(); } var_cor_t[i] = old_corr; move16(); @@ -1254,7 +1257,7 @@ static void var_cor_calc_fx( *high_stable_cor = 0; move16(); test(); - IF( GT_16(*mold_corr,26214)&<_16(var_cor,2)) + IF( GT_16( *mold_corr, 26214 ) && LT_16( var_cor, 2 ) ) { *high_stable_cor = 1; move16(); @@ -1262,7 +1265,7 @@ static void var_cor_calc_fx( /* update average correlation */ /*st->mold_corr = 0.1f * st->old_corr + 0.9f * st->mold_corr;*/ - *mold_corr = mac_r(L_mult(3277,old_corr),29491,*mold_corr); /*Q15 */ + *mold_corr = mac_r( L_mult( 3277, old_corr ), 29491, *mold_corr ); /*Q15 */ return; } @@ -1273,20 +1276,20 @@ static void var_cor_calc_fx( * Attack detection *---------------------------------------------------------------------*/ -static Word16 attack_det_fx( /* o : attack flag */ - const Word16 *inp, /* i : input signal */ - const Word16 Qx, - const Word16 last_clas, /* i : last signal clas */ - const Word16 localVAD, /* i : local VAD flag */ - const Word16 coder_type, /* i : coder type */ - const Word32 total_brate /* i : total bitrate */ +static Word16 attack_det_fx( /* o : attack flag */ + const Word16 *inp, /* i : input signal */ + const Word16 Qx, + const Word16 last_clas, /* i : last signal clas */ + const Word16 localVAD, /* i : local VAD flag */ + const Word16 coder_type, /* i : coder type */ + const Word32 total_brate /* i : total bitrate */ #ifdef IVAS_CODE - , - const Word16 element_mode, /* i : IVAS element mode */ - const Word16 clas, /* i : signal class */ - Word32 finc_prev[], /* i/o: previous finc */ - Word32* lt_finc, /* i/o: long-term mean finc */ - Word16* last_strong_attack /* i/o: last strong attack flag */ + , + const Word16 element_mode, /* i : IVAS element mode */ + const Word16 clas, /* i : signal class */ + Word32 finc_prev[], /* i/o: previous finc */ + Word32 *lt_finc, /* i/o: long-term mean finc */ + Word16 *last_strong_attack /* i/o: last strong attack flag */ #endif ) { @@ -1302,24 +1305,24 @@ static Word16 attack_det_fx( /* o : attack flag att_3lsub_pos = ATT_3LSUB_POS; move16(); - if( GE_32(total_brate,ACELP_24k40)) + if ( GE_32( total_brate, ACELP_24k40 ) ) { att_3lsub_pos = ATT_3LSUB_POS_16k; move16(); } /* compute energy per section */ - FOR( i=0; i 0 ) { - etmp2 = L_add(finc[attack], 0); - etmp = Mult_32_16(etmp2, 16384); /* etmp2 / 2.0 = (etmp2*0.5) */ - FOR( i=2; i 0 ) { - etmp2 = L_add(finc[attack], 0); - etmp = Mult_32_16(etmp2, 25206); /* etmp2 / 1.3 = (etmp2*0.76923) */ - FOR( i=2; i etmp2 ) -> finc[i] > (etmp2*0.76923) */ test(); - IF( NE_16(i,attack)&>_32(finc[i],etmp)) + IF( NE_16( i, attack ) && GT_32( finc[i], etmp ) ) { attack = 0; move16(); @@ -1469,9 +1475,9 @@ static Word16 attack_det_fx( /* o : attack flag * *1st stage of the speech / music classification(based on the GMM model) * -------------------------------------------------------------------- - */ - /*! r: S/M decision (0=speech or noise,1=unclear,2=music) */ +/*! r: S/M decision (0=speech or noise,1=unclear,2=music) */ int16_t ivas_smc_gmm( - Encoder_State * st, /* i/o: state structure */ + Encoder_State *st, /* i/o: state structure */ STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure */ const int16_t localVAD_HE_SAD, /* i : HE-SAD flag without hangover */ const float Etot, /* i : total frame energy */ @@ -1481,7 +1487,7 @@ int16_t ivas_smc_gmm( const float PS[], /* i : energy spectrum */ const float non_sta, /* i : unbound non-stationarity */ const float relE, /* i : relative frame energy */ - int16_t * high_lpn_flag, /* i/o: sp/mus LPN flag */ + int16_t *high_lpn_flag, /* i/o: sp/mus LPN flag */ const int16_t flag_spitch /* i : flag to indicate very short stable pitch */ ) { @@ -1493,15 +1499,15 @@ int16_t ivas_smc_gmm( float dlp, ftmp, sum_PS, ps_diff, ps_sta, wrelE, wdrop, wght; float wrise; float dlp_mean2var; - float FV[N_SMC_FEATURES], * pFV, PS_norm[128], dPS[128]; - const float* pODV; - float* pFV_st, smc_st_mean_fact; + float FV[N_SMC_FEATURES], *pFV, PS_norm[128], dPS[128]; + const float *pODV; + float *pFV_st, smc_st_mean_fact; int16_t relE_attack_flag; int16_t j, len; - const float* pt_mel_fb; + const float *pt_mel_fb; float melS[NB_MEL_BANDS], mfcc[NB_MEL_BANDS]; int16_t odv_cnt; - int16_t i_out[N_SMC_FEATURES], * p_out; + int16_t i_out[N_SMC_FEATURES], *p_out; /*------------------------------------------------------------------* * Initialization @@ -1513,13 +1519,13 @@ int16_t ivas_smc_gmm( * State machine (sp_mus_state: -8 = INACTIVE, -7:-1 = UNSTABLE, 0:7 = ENTRY, 8 = STABLE ) *------------------------------------------------------------------*/ - if (localVAD_HE_SAD) + if ( localVAD_HE_SAD ) { - if (relE < -20) + if ( relE < -20 ) { - if (hSpMusClas->sp_mus_state > 0) + if ( hSpMusClas->sp_mus_state > 0 ) { - if (hSpMusClas->sp_mus_state < HANG_LEN) + if ( hSpMusClas->sp_mus_state < HANG_LEN ) { /* energy is too low but we are in entry period -> reset the inactive counter to allow new entry later */ hSpMusClas->inact_cnt = 0; @@ -1528,15 +1534,15 @@ int16_t ivas_smc_gmm( /* energy is too low -> we are going to instable state */ hSpMusClas->sp_mus_state = 0; } - else if (hSpMusClas->sp_mus_state > -HANG_LEN) + else if ( hSpMusClas->sp_mus_state > -HANG_LEN ) { /* energy is still too low -> we are still in instable state */ hSpMusClas->sp_mus_state--; } } - else if (hSpMusClas->sp_mus_state <= 0) + else if ( hSpMusClas->sp_mus_state <= 0 ) { - if (hSpMusClas->inact_cnt == 0) + if ( hSpMusClas->inact_cnt == 0 ) { hSpMusClas->sp_mus_state = 1; @@ -1549,37 +1555,37 @@ int16_t ivas_smc_gmm( hSpMusClas->inact_cnt = 12; } - else if (hSpMusClas->sp_mus_state > 0 && hSpMusClas->sp_mus_state < HANG_LEN) + else if ( hSpMusClas->sp_mus_state > 0 && hSpMusClas->sp_mus_state < HANG_LEN ) { /* we are inside an entry period -> increment the counter of entry frames */ hSpMusClas->sp_mus_state++; } - if (hSpMusClas->sp_mus_state < 0 && hSpMusClas->inact_cnt > 0) + if ( hSpMusClas->sp_mus_state < 0 && hSpMusClas->inact_cnt > 0 ) { hSpMusClas->inact_cnt--; } } else { - if (hSpMusClas->sp_mus_state > 0 && hSpMusClas->sp_mus_state < HANG_LEN) + if ( hSpMusClas->sp_mus_state > 0 && hSpMusClas->sp_mus_state < HANG_LEN ) { hSpMusClas->inact_cnt = 0; } - else if (hSpMusClas->inact_cnt > 0) + else if ( hSpMusClas->inact_cnt > 0 ) { hSpMusClas->inact_cnt--; } - if (hSpMusClas->sp_mus_state > 0 && hSpMusClas->sp_mus_state < HANG_LEN) + if ( hSpMusClas->sp_mus_state > 0 && hSpMusClas->sp_mus_state < HANG_LEN ) { hSpMusClas->sp_mus_state = -HANG_LEN; } - else if (hSpMusClas->sp_mus_state > 0) + else if ( hSpMusClas->sp_mus_state > 0 ) { hSpMusClas->sp_mus_state = -1; } - else if (hSpMusClas->sp_mus_state > -HANG_LEN) + else if ( hSpMusClas->sp_mus_state > -HANG_LEN ) { /* we are in inactive state */ hSpMusClas->sp_mus_state--; @@ -1587,7 +1593,7 @@ int16_t ivas_smc_gmm( } /* detect attacks based on relE */ - if (relE > hSpMusClas->prev_relE) + if ( relE > hSpMusClas->prev_relE ) { hSpMusClas->relE_attack_sum += relE - hSpMusClas->prev_relE; } @@ -1598,11 +1604,11 @@ int16_t ivas_smc_gmm( hSpMusClas->prev_relE = relE; /* update counter from last VAD 0->1 change */ - if (hSpMusClas->prev_vad == 0 && localVAD_HE_SAD == 1) + if ( hSpMusClas->prev_vad == 0 && localVAD_HE_SAD == 1 ) { hSpMusClas->vad_0_1_cnt = 1; } - else if (localVAD_HE_SAD == 1 && hSpMusClas->vad_0_1_cnt > 0 && hSpMusClas->vad_0_1_cnt < 50) + else if ( localVAD_HE_SAD == 1 && hSpMusClas->vad_0_1_cnt > 0 && hSpMusClas->vad_0_1_cnt < 50 ) { hSpMusClas->vad_0_1_cnt++; } @@ -1612,12 +1618,12 @@ int16_t ivas_smc_gmm( } hSpMusClas->prev_vad = localVAD_HE_SAD; - if (hSpMusClas->sp_mus_state > 0 && hSpMusClas->sp_mus_state < HANG_LEN && hSpMusClas->relE_attack_sum > 5.0f) + if ( hSpMusClas->sp_mus_state > 0 && hSpMusClas->sp_mus_state < HANG_LEN && hSpMusClas->relE_attack_sum > 5.0f ) { hSpMusClas->relE_attack_cnt++; /* set flag only in the first X frames in a series */ - if (hSpMusClas->relE_attack_cnt > 0 && hSpMusClas->relE_attack_cnt < 3) + if ( hSpMusClas->relE_attack_cnt > 0 && hSpMusClas->relE_attack_cnt < 3 ) { relE_attack_flag = 1; } @@ -1641,31 +1647,31 @@ int16_t ivas_smc_gmm( pFV = FV; /* [0] OL pitch */ - if (relE_attack_flag || st->tc_cnt == 1 || st->tc_cnt == 2) + if ( relE_attack_flag || st->tc_cnt == 1 || st->tc_cnt == 2 ) { - *pFV++ = (float)st->pitch[2]; + *pFV++ = (float) st->pitch[2]; } else { - *pFV++ = (float)(st->pitch[0] + st->pitch[1] + st->pitch[2]) / 3.0f; + *pFV++ = (float) ( st->pitch[0] + st->pitch[1] + st->pitch[2] ) / 3.0f; } /* [1] voicing */ - if (relE_attack_flag || st->tc_cnt == 1 || st->tc_cnt == 2) + if ( relE_attack_flag || st->tc_cnt == 1 || st->tc_cnt == 2 ) { *pFV++ = st->voicing[2]; } else { - *pFV++ = (st->voicing[0] + st->voicing[1] + st->voicing[2]) / 3.0f; + *pFV++ = ( st->voicing[0] + st->voicing[1] + st->voicing[2] ) / 3.0f; } /* [2,3,4,5,6] LSFs */ - *pFV++ = acosf(lsp_new[2]); - *pFV++ = acosf(lsp_new[3]); - *pFV++ = acosf(lsp_new[4]); - *pFV++ = acosf(lsp_new[5]); - *pFV++ = acosf(lsp_new[6]); + *pFV++ = acosf( lsp_new[2] ); + *pFV++ = acosf( lsp_new[3] ); + *pFV++ = acosf( lsp_new[4] ); + *pFV++ = acosf( lsp_new[5] ); + *pFV++ = acosf( lsp_new[6] ); /* [7] cor_map_sum */ *pFV++ = cor_map_sum; @@ -1674,20 +1680,20 @@ int16_t ivas_smc_gmm( *pFV++ = non_sta; /* [9] epsP */ - *pFV++ = logf(epsP[14] + 1e-5f) - logf(epsP[0] + 1e-5f); + *pFV++ = logf( epsP[14] + 1e-5f ) - logf( epsP[0] + 1e-5f ); /* [10,11,12] MFCCs */ - set_zero(melS, NB_MEL_BANDS); + set_zero( melS, NB_MEL_BANDS ); pt_mel_fb = mel_fb; - for (i = 0; i < NB_MEL_BANDS; i++) + for ( i = 0; i < NB_MEL_BANDS; i++ ) { j = mel_fb_start[i]; len = mel_fb_len[i]; - melS[i] = logf(dotp(&PS[j], pt_mel_fb, len) + 1e-5f); + melS[i] = logf( dotp( &PS[j], pt_mel_fb, len ) + 1e-5f ); pt_mel_fb += len; } - v_mult_mat(mfcc, melS, dct_mtx, NB_MEL_BANDS, NB_MEL_COEF); + v_mult_mat( mfcc, melS, dct_mtx, NB_MEL_BANDS, NB_MEL_COEF ); *pFV++ = mfcc[2]; *pFV++ = mfcc[6]; @@ -1695,20 +1701,20 @@ int16_t ivas_smc_gmm( /* calculation of differential normalized power spectrum */ sum_PS = 1e-5f; - for (i = LOWEST_FBIN; i < HIGHEST_FBIN; i++) + for ( i = LOWEST_FBIN; i < HIGHEST_FBIN; i++ ) { sum_PS += PS[i]; } - for (i = LOWEST_FBIN; i < HIGHEST_FBIN; i++) + for ( i = LOWEST_FBIN; i < HIGHEST_FBIN; i++ ) { PS_norm[i] = PS[i] / sum_PS; - dPS[i] = fabsf(PS_norm[i] - hSpMusClas->past_PS[i - LOWEST_FBIN]); + dPS[i] = fabsf( PS_norm[i] - hSpMusClas->past_PS[i - LOWEST_FBIN] ); } /* [13] ps_diff (spectral difference) */ ps_diff = 0; - for (i = LOWEST_FBIN; i < HIGHEST_FBIN; i++) + for ( i = LOWEST_FBIN; i < HIGHEST_FBIN; i++ ) { ps_diff += dPS[i]; } @@ -1717,33 +1723,33 @@ int16_t ivas_smc_gmm( /* [14] ps_sta (spectral stationarity) */ ps_sta = 0; - for (i = LOWEST_FBIN; i < HIGHEST_FBIN; i++) + for ( i = LOWEST_FBIN; i < HIGHEST_FBIN; i++ ) { - if (PS_norm[i] > hSpMusClas->past_PS[i - LOWEST_FBIN]) + if ( PS_norm[i] > hSpMusClas->past_PS[i - LOWEST_FBIN] ) { - ps_sta += PS_norm[i] / (dPS[i] + 1e-5f); + ps_sta += PS_norm[i] / ( dPS[i] + 1e-5f ); } else { - ps_sta += hSpMusClas->past_PS[i - LOWEST_FBIN] / (dPS[i] + 1e-5f); + ps_sta += hSpMusClas->past_PS[i - LOWEST_FBIN] / ( dPS[i] + 1e-5f ); } } - *pFV++ = logf(ps_sta + 1e-5f); - mvr2r(&PS_norm[LOWEST_FBIN], hSpMusClas->past_PS, HIGHEST_FBIN - LOWEST_FBIN); + *pFV++ = logf( ps_sta + 1e-5f ); + mvr2r( &PS_norm[LOWEST_FBIN], hSpMusClas->past_PS, HIGHEST_FBIN - LOWEST_FBIN ); /* save ps_diff and ps_sta features for XTALK and UNCLR classifier */ - if (hStereoClassif != NULL) + if ( hStereoClassif != NULL ) { - if (st->idchan == 0) + if ( st->idchan == 0 ) { hStereoClassif->ps_diff_ch1 = ps_diff; - hStereoClassif->ps_sta_ch1 = logf(ps_sta + 1e-5f); + hStereoClassif->ps_sta_ch1 = logf( ps_sta + 1e-5f ); } else { hStereoClassif->ps_diff_ch2 = ps_diff; - hStereoClassif->ps_sta_ch2 = logf(ps_sta + 1e-5f); + hStereoClassif->ps_sta_ch2 = logf( ps_sta + 1e-5f ); } } @@ -1752,15 +1758,15 @@ int16_t ivas_smc_gmm( *------------------------------------------------------------------*/ flag_odv = 0; - if (localVAD_HE_SAD) + if ( localVAD_HE_SAD ) { pFV = FV; pODV = hout_intervals; p_out = i_out; odv_cnt = 0; - for (i = 0; i < N_SMC_FEATURES; i++) + for ( i = 0; i < N_SMC_FEATURES; i++ ) { - if (*pFV < pODV[0] || *pFV > pODV[1]) + if ( *pFV < pODV[0] || *pFV > pODV[1] ) { *p_out++ = i; odv_cnt++; @@ -1771,12 +1777,12 @@ int16_t ivas_smc_gmm( } /* set outlier flag */ - if (odv_cnt >= 2) + if ( odv_cnt >= 2 ) { flag_odv = 1; /* replace outlying features with values from the previous frame */ - for (i = 0; i < odv_cnt; i++) + for ( i = 0; i < odv_cnt; i++ ) { FV[i_out[i]] = hSpMusClas->prev_FV[i_out[i]]; } @@ -1790,18 +1796,18 @@ int16_t ivas_smc_gmm( pFV = FV; pFV_st = hSpMusClas->FV_st; smc_st_mean_fact = SMC_ST_MEAN_FACT; - for (i = 0; i < N_SMC_FEATURES; i++) + for ( i = 0; i < N_SMC_FEATURES; i++ ) { - *pFV_st = smc_st_mean_fact * (*pFV_st) + (1 - smc_st_mean_fact) * (*pFV); + *pFV_st = smc_st_mean_fact * ( *pFV_st ) + ( 1 - smc_st_mean_fact ) * ( *pFV ); - if (hSpMusClas->sp_mus_state > 0 && hSpMusClas->sp_mus_state < HANG_LEN && (relE_attack_flag || flag_odv)) + if ( hSpMusClas->sp_mus_state > 0 && hSpMusClas->sp_mus_state < HANG_LEN && ( relE_attack_flag || flag_odv ) ) { /* strong attack or outlier frame during entry state -> features cannot be trusted but there is also no useful past info -> */ /* -> do whatever you want because dlp will be reset to 0 anyway */ pFV++; pFV_st++; } - else if (hSpMusClas->sp_mus_state == HANG_LEN && (st->tc_cnt == 1 || st->tc_cnt == 2)) + else if ( hSpMusClas->sp_mus_state == HANG_LEN && ( st->tc_cnt == 1 || st->tc_cnt == 2 ) ) { /* energy attack in stable state -> use current features intead of the long-term average */ pFV++; @@ -1814,23 +1820,23 @@ int16_t ivas_smc_gmm( } /* update */ - mvr2r(FV, hSpMusClas->prev_FV, N_SMC_FEATURES); + mvr2r( FV, hSpMusClas->prev_FV, N_SMC_FEATURES ); /*------------------------------------------------------------------* * Non-linear power transformation (boxcox) on certain features *------------------------------------------------------------------*/ pFV = FV; - for (i = 0; i < N_SMC_FEATURES; i++) + for ( i = 0; i < N_SMC_FEATURES; i++ ) { - if (bcox_lmbd[i] != 0) + if ( bcox_lmbd[i] != 0 ) { *pFV -= bcox_add_cnst[i]; - if (*pFV < 1) + if ( *pFV < 1 ) { *pFV = 1; } - *pFV = (powf(*pFV, bcox_lmbd[i]) - 1) / bcox_lmbd[i]; + *pFV = ( powf( *pFV, bcox_lmbd[i] ) - 1 ) / bcox_lmbd[i]; } pFV++; @@ -1842,10 +1848,10 @@ int16_t ivas_smc_gmm( *------------------------------------------------------------------*/ pFV = FV; - for (i = 0; i < N_SMC_FEATURES; i++) + for ( i = 0; i < N_SMC_FEATURES; i++ ) { /* Standard scaler - mean and variance normalization */ - *pFV = (*pFV - sm_means[i]) / sm_scale[i]; + *pFV = ( *pFV - sm_means[i] ) / sm_scale[i]; pFV++; /* MinMax sclaer - mean and variance normalization */ @@ -1854,37 +1860,37 @@ int16_t ivas_smc_gmm( } /* PCA */ - v_sub(FV, pca_mean_, FV, N_SMC_FEATURES); - v_mult_mat(FV, FV, pca_components_, N_SMC_FEATURES, N_PCA_COEF); + v_sub( FV, pca_mean_, FV, N_SMC_FEATURES ); + v_mult_mat( FV, FV, pca_components_, N_SMC_FEATURES, N_PCA_COEF ); /*------------------------------------------------------------------* * Calculation of posterior probability * Log-probability *------------------------------------------------------------------*/ - /* run loop for all mixtures (for each mixture, calculate the probability of speech, music and noise) */ + /* run loop for all mixtures (for each mixture, calculate the probability of speech, music and noise) */ lps = lpm = lpn = 0; - for (m = 0; m < N_SMC_MIXTURES; m++) + for ( m = 0; m < N_SMC_MIXTURES; m++ ) { - v_sub(FV, &means_speech[m * N_PCA_COEF], fvm, N_PCA_COEF); - lprob = dot_product_cholesky(fvm, &prec_chol_speech[m * (N_PCA_COEF * N_PCA_COEF + N_PCA_COEF) / 2], N_PCA_COEF); - ps[m] = logf(weights_speech[m]) + log_det_chol_speech[m] - 0.5f * N_PCA_COEF * logf(PI2) - 0.5f * lprob; + v_sub( FV, &means_speech[m * N_PCA_COEF], fvm, N_PCA_COEF ); + lprob = dot_product_cholesky( fvm, &prec_chol_speech[m * ( N_PCA_COEF * N_PCA_COEF + N_PCA_COEF ) / 2], N_PCA_COEF ); + ps[m] = logf( weights_speech[m] ) + log_det_chol_speech[m] - 0.5f * N_PCA_COEF * logf( PI2 ) - 0.5f * lprob; - v_sub(FV, &means_music[m * N_PCA_COEF], fvm, N_PCA_COEF); - lprob = dot_product_cholesky(fvm, &prec_chol_music[m * (N_PCA_COEF * N_PCA_COEF + N_PCA_COEF) / 2], N_PCA_COEF); - pm[m] = logf(weights_music[m]) + log_det_chol_music[m] - 0.5f * N_PCA_COEF * logf(PI2) - 0.5f * lprob; + v_sub( FV, &means_music[m * N_PCA_COEF], fvm, N_PCA_COEF ); + lprob = dot_product_cholesky( fvm, &prec_chol_music[m * ( N_PCA_COEF * N_PCA_COEF + N_PCA_COEF ) / 2], N_PCA_COEF ); + pm[m] = logf( weights_music[m] ) + log_det_chol_music[m] - 0.5f * N_PCA_COEF * logf( PI2 ) - 0.5f * lprob; - v_sub(FV, &means_noise[m * N_PCA_COEF], fvm, N_PCA_COEF); - lprob = dot_product_cholesky(fvm, &prec_chol_noise[m * (N_PCA_COEF * N_PCA_COEF + N_PCA_COEF) / 2], N_PCA_COEF); - pn[m] = logf(weights_noise[m]) + log_det_chol_noise[m] - 0.5f * N_PCA_COEF * logf(PI2) - 0.5f * lprob; + v_sub( FV, &means_noise[m * N_PCA_COEF], fvm, N_PCA_COEF ); + lprob = dot_product_cholesky( fvm, &prec_chol_noise[m * ( N_PCA_COEF * N_PCA_COEF + N_PCA_COEF ) / 2], N_PCA_COEF ); + pn[m] = logf( weights_noise[m] ) + log_det_chol_noise[m] - 0.5f * N_PCA_COEF * logf( PI2 ) - 0.5f * lprob; } - lps = logsumexp(ps, N_SMC_MIXTURES); - lpm = logsumexp(pm, N_SMC_MIXTURES); - lpn = logsumexp(pn, N_SMC_MIXTURES); + lps = logsumexp( ps, N_SMC_MIXTURES ); + lpm = logsumexp( pm, N_SMC_MIXTURES ); + lpn = logsumexp( pn, N_SMC_MIXTURES ); *high_lpn_flag = 0; - if (lpn > lps && lpn > lpm) + if ( lpn > lps && lpn > lpm ) { *high_lpn_flag = 1; } @@ -1894,9 +1900,9 @@ int16_t ivas_smc_gmm( hSpMusClas->lpn = lpn; /* determine HQ Generic speech class */ - if (st->hHQ_core != NULL) + if ( st->hHQ_core != NULL ) { - if (lps > lpm + 0.5f) + if ( lps > lpm + 0.5f ) { st->hHQ_core->hq_generic_speech_class = 1; } @@ -1911,8 +1917,8 @@ int16_t ivas_smc_gmm( * Weighted decision *------------------------------------------------------------------*/ - /* decision without hangover (0 - speech/noise, 1 - music) */ - if (!localVAD_HE_SAD || Etot < 10 || (hSpMusClas->sp_mus_state > 0 && hSpMusClas->sp_mus_state < HANG_LEN && (relE_attack_flag || flag_odv))) + /* decision without hangover (0 - speech/noise, 1 - music) */ + if ( !localVAD_HE_SAD || Etot < 10 || ( hSpMusClas->sp_mus_state > 0 && hSpMusClas->sp_mus_state < HANG_LEN && ( relE_attack_flag || flag_odv ) ) ) { dlp = 0; } @@ -1920,11 +1926,11 @@ int16_t ivas_smc_gmm( { dlp = lpm - lps + DLP_BIAS; - if (dlp > 30.0f) + if ( dlp > 30.0f ) { dlp = 30.0f; } - else if (dlp < -30.0f) + else if ( dlp < -30.0f ) { dlp = -30.0f; } @@ -1933,19 +1939,19 @@ int16_t ivas_smc_gmm( dec = dlp > 0; /* calculate weight based on relE (higher relE -> lower weight, lower relE -> higher weight) */ - wrelE = lin_interp(relE, 15.0f, 0.9f, -15.0f, 0.99f, 1); + wrelE = lin_interp( relE, 15.0f, 0.9f, -15.0f, 0.99f, 1 ); /* calculate weight based on drops of dlp (close to 1 during sudden drops of dlp, close to 0 otherwise) */ hSpMusClas->dlp_mean_ST = 0.8f * hSpMusClas->dlp_mean_ST + 0.2f * dlp; hSpMusClas->lt_dec_thres = hSpMusClas->dlp_mean_ST; - if (dlp < 0 && dlp < hSpMusClas->dlp_mean_ST) + if ( dlp < 0 && dlp < hSpMusClas->dlp_mean_ST ) { - if (hSpMusClas->dlp_mean_ST > 0) + if ( hSpMusClas->dlp_mean_ST > 0 ) { hSpMusClas->wdrop = -dlp; } - else if (hSpMusClas->wdrop > 0) + else if ( hSpMusClas->wdrop > 0 ) { hSpMusClas->wdrop += hSpMusClas->dlp_mean_ST - dlp; } @@ -1955,16 +1961,16 @@ int16_t ivas_smc_gmm( hSpMusClas->wdrop = 0; } - wdrop = lin_interp(hSpMusClas->wdrop, 15.0f, 0.7f, 0.0f, 1.0f, 1); + wdrop = lin_interp( hSpMusClas->wdrop, 15.0f, 0.7f, 0.0f, 1.0f, 1 ); /* calculate weight based on rises of dlp (close to 1 during sudden rise of dlp, close to 0 otherwise) */ - if (hSpMusClas->sp_mus_state == HANG_LEN && hSpMusClas->dlp_mean_ST > 0 && hSpMusClas->dlp_mean_ST > hSpMusClas->past_dlp_mean_ST[0]) + if ( hSpMusClas->sp_mus_state == HANG_LEN && hSpMusClas->dlp_mean_ST > 0 && hSpMusClas->dlp_mean_ST > hSpMusClas->past_dlp_mean_ST[0] ) { - if (hSpMusClas->past_dlp_mean_ST[0] < 0) + if ( hSpMusClas->past_dlp_mean_ST[0] < 0 ) { hSpMusClas->wrise = hSpMusClas->dlp_mean_ST; } - else if (hSpMusClas->wrise > 0) + else if ( hSpMusClas->wrise > 0 ) { hSpMusClas->wrise += hSpMusClas->dlp_mean_ST - hSpMusClas->past_dlp_mean_ST[0]; } @@ -1974,13 +1980,13 @@ int16_t ivas_smc_gmm( hSpMusClas->wrise = 0; } - wrise = lin_interp(hSpMusClas->wrise, 5.0f, 0.95f, 0.0f, 1.0f, 1); + wrise = lin_interp( hSpMusClas->wrise, 5.0f, 0.95f, 0.0f, 1.0f, 1 ); /* combine weights into one */ wght = wrelE * wdrop * wrise; /* ratio of delta means vs. delta variances */ - if (hSpMusClas->sp_mus_state > 0 && hSpMusClas->sp_mus_state < HANG_LEN) + if ( hSpMusClas->sp_mus_state > 0 && hSpMusClas->sp_mus_state < HANG_LEN ) { hSpMusClas->dlp_mean_LT = dlp; hSpMusClas->dlp_var_LT = 0; @@ -1988,40 +1994,40 @@ int16_t ivas_smc_gmm( hSpMusClas->dlp_mean_LT = 0.9f * hSpMusClas->dlp_mean_LT + 0.1f * dlp; ftmp = dlp - hSpMusClas->dlp_mean_LT; - hSpMusClas->dlp_var_LT = 0.9f * hSpMusClas->dlp_var_LT + 0.1f * (ftmp * ftmp); + hSpMusClas->dlp_var_LT = 0.9f * hSpMusClas->dlp_var_LT + 0.1f * ( ftmp * ftmp ); - if (hSpMusClas->sp_mus_state > 0 && hSpMusClas->sp_mus_state < HANG_LEN) + if ( hSpMusClas->sp_mus_state > 0 && hSpMusClas->sp_mus_state < HANG_LEN ) { dlp_mean2var = 0; } else { - dlp_mean2var = fabsf(hSpMusClas->dlp_mean_LT) / (sqrtf(fabsf(hSpMusClas->dlp_var_LT)) + 1.0f); + dlp_mean2var = fabsf( hSpMusClas->dlp_mean_LT ) / ( sqrtf( fabsf( hSpMusClas->dlp_var_LT ) ) + 1.0f ); } - if (dlp_mean2var > 15.0f) + if ( dlp_mean2var > 15.0f ) { /* decrease the weight little bit when the classifier indicates "strong speech" or "strong music" */ wght *= 0.9f; } - if (wght > 1.0f) + if ( wght > 1.0f ) { wght = 1.0f; } - else if (wght < 0.01f) + else if ( wght < 0.01f ) { wght = 0.01f; } - if (Etot < 10) + if ( Etot < 10 ) { /* silence */ wght = 0.92f; } /* calculate weighted decision */ - hSpMusClas->wdlp_0_95_sp = wght * hSpMusClas->wdlp_0_95_sp + (1 - wght) * dlp; + hSpMusClas->wdlp_0_95_sp = wght * hSpMusClas->wdlp_0_95_sp + ( 1 - wght ) * dlp; /* xtalk classifier: apply long hysteresis to prevent LRTD on music */ hSpMusClas->wdlp_xtalk = 0.995f * hSpMusClas->wdlp_xtalk + 0.005f * dlp; @@ -2030,28 +2036,28 @@ int16_t ivas_smc_gmm( * Final speech/music decision *------------------------------------------------------------------*/ - if (flag_spitch) + if ( flag_spitch ) { hSpMusClas->flag_spitch_cnt = 5; } - else if (hSpMusClas->flag_spitch_cnt > 0) + else if ( hSpMusClas->flag_spitch_cnt > 0 ) { hSpMusClas->flag_spitch_cnt--; } - if (Etot < 10) + if ( Etot < 10 ) { /* silence */ dec = 0; } - else if (hSpMusClas->sp_mus_state > 0 && hSpMusClas->sp_mus_state < HANG_LEN) + else if ( hSpMusClas->sp_mus_state > 0 && hSpMusClas->sp_mus_state < HANG_LEN ) { /* entry state -> final decision is calculated based on weighted average of past non-binary decisions */ ftmp = w_spmus[hSpMusClas->sp_mus_state - 1][0] * dlp; - ftmp += dotp(&w_spmus[hSpMusClas->sp_mus_state - 1][1], hSpMusClas->past_dlp, HANG_LEN - 1); - if (ftmp > 2.0f) + ftmp += dotp( &w_spmus[hSpMusClas->sp_mus_state - 1][1], hSpMusClas->past_dlp, HANG_LEN - 1 ); + if ( ftmp > 2.0f ) { - if (dlp > 2.0f) + if ( dlp > 2.0f ) { dec = 2; } @@ -2068,28 +2074,28 @@ int16_t ivas_smc_gmm( else { /* stable active state */ - if (hSpMusClas->past_dec[0] == 0 && hSpMusClas->past_dec[1] == 0 && hSpMusClas->past_dec[2] == 0 && - ((hSpMusClas->flag_spitch_cnt > 0 && hSpMusClas->wdlp_0_95_sp > 3.4f) || (hSpMusClas->flag_spitch_cnt == 0 && hSpMusClas->wdlp_0_95_sp > 2.1f))) + if ( hSpMusClas->past_dec[0] == 0 && hSpMusClas->past_dec[1] == 0 && hSpMusClas->past_dec[2] == 0 && + ( ( hSpMusClas->flag_spitch_cnt > 0 && hSpMusClas->wdlp_0_95_sp > 3.4f ) || ( hSpMusClas->flag_spitch_cnt == 0 && hSpMusClas->wdlp_0_95_sp > 2.1f ) ) ) { /* switching from speech to unclear */ dec = 1; } - else if (hSpMusClas->past_dec[0] == 0 && hSpMusClas->vad_0_1_cnt < 50 && hSpMusClas->relE_attack_sum == 0.0f && hSpMusClas->wdlp_0_95_sp > 1.0f) + else if ( hSpMusClas->past_dec[0] == 0 && hSpMusClas->vad_0_1_cnt < 50 && hSpMusClas->relE_attack_sum == 0.0f && hSpMusClas->wdlp_0_95_sp > 1.0f ) { /* switch from speech to unclear also during slowly rising weak music onsets */ dec = 1; } - else if (hSpMusClas->past_dec[0] == 1 && hSpMusClas->wdlp_0_95_sp > 2.5f) + else if ( hSpMusClas->past_dec[0] == 1 && hSpMusClas->wdlp_0_95_sp > 2.5f ) { /* switching from unclear to music */ dec = 2; } - else if (hSpMusClas->past_dec[0] == 2 && hSpMusClas->past_dec[1] == 2 && hSpMusClas->past_dec[2] == 2 && hSpMusClas->wdlp_0_95_sp < -1.0f) + else if ( hSpMusClas->past_dec[0] == 2 && hSpMusClas->past_dec[1] == 2 && hSpMusClas->past_dec[2] == 2 && hSpMusClas->wdlp_0_95_sp < -1.0f ) { /* switching from music to unclear */ dec = 1; } - else if (hSpMusClas->past_dec[0] == 1 && hSpMusClas->wdlp_0_95_sp < -2.5f) + else if ( hSpMusClas->past_dec[0] == 1 && hSpMusClas->wdlp_0_95_sp < -2.5f ) { /* switching from unclear to speech */ dec = 0; @@ -2104,7 +2110,7 @@ int16_t ivas_smc_gmm( * raw S/M decision based on smoothed GMM score *------------------------------------------------------------------*/ - if (dec == 0 || st->hSpMusClas->wdlp_0_95_sp <= 0) + if ( dec == 0 || st->hSpMusClas->wdlp_0_95_sp <= 0 ) { st->sp_aud_decision0 = 0; st->sp_aud_decision1 = 0; @@ -2119,19 +2125,19 @@ int16_t ivas_smc_gmm( * Updates *------------------------------------------------------------------*/ - /* update buffer of past non-binary decisions */ - mvr2r(&hSpMusClas->past_dlp[0], &hSpMusClas->past_dlp[1], HANG_LEN - 2); + /* update buffer of past non-binary decisions */ + mvr2r( &hSpMusClas->past_dlp[0], &hSpMusClas->past_dlp[1], HANG_LEN - 2 ); hSpMusClas->past_dlp[0] = dlp; - mvr2r(&hSpMusClas->past_dlp_mean_ST[0], &hSpMusClas->past_dlp_mean_ST[1], HANG_LEN - 2); + mvr2r( &hSpMusClas->past_dlp_mean_ST[0], &hSpMusClas->past_dlp_mean_ST[1], HANG_LEN - 2 ); hSpMusClas->past_dlp_mean_ST[0] = hSpMusClas->dlp_mean_ST; /* update buffer of past binary decisions */ - mvs2s(&hSpMusClas->past_dec[0], &hSpMusClas->past_dec[1], HANG_LEN - 2); + mvs2s( &hSpMusClas->past_dec[0], &hSpMusClas->past_dec[1], HANG_LEN - 2 ); hSpMusClas->past_dec[0] = dec; #ifdef DEBUG_MODE_INFO - dbgwrite(&st->hSpMusClas->wdlp_0_95_sp, sizeof(float), 1, 1, "res/wdlp_0_95_sp.x"); + dbgwrite( &st->hSpMusClas->wdlp_0_95_sp, sizeof( float ), 1, 1, "res/wdlp_0_95_sp.x" ); #endif return dec; @@ -2148,13 +2154,13 @@ int16_t ivas_smc_gmm( *---------------------------------------------------------------------*/ void ivas_smc_mode_selection( - Encoder_State* st, /* i/o: encoder state structure */ + Encoder_State *st, /* i/o: encoder state structure */ const int32_t element_brate, /* i : element bitrate */ int16_t smc_dec, /* i : raw decision of the 1st stage classifier*/ const float relE, /* i : relative frame energy */ const float Etot, /* i : total frame energy */ - int16_t* attack_flag, /* i/o: attack flag (GSC or TC) */ - const float* inp, /* i : input signal */ + int16_t *attack_flag, /* i/o: attack flag (GSC or TC) */ + const float *inp, /* i : input signal */ const float S_map[], /* i : short-term correlation map */ const int16_t flag_spitch /* i : flag to indicate very short stable pitch*/ ) @@ -2172,49 +2178,49 @@ void ivas_smc_mode_selection( st->sp_aud_decision2 = 0; /* signal stability estimation */ - stab_est(Etot, hSpMusClas->gsc_lt_diff_etot, &hSpMusClas->gsc_mem_etot, &hSpMusClas->gsc_nb_thr_3, &hSpMusClas->gsc_nb_thr_1, hSpMusClas->gsc_thres, &hSpMusClas->gsc_last_music_flag, st->vad_flag); + stab_est( Etot, hSpMusClas->gsc_lt_diff_etot, &hSpMusClas->gsc_mem_etot, &hSpMusClas->gsc_nb_thr_3, &hSpMusClas->gsc_nb_thr_1, hSpMusClas->gsc_thres, &hSpMusClas->gsc_last_music_flag, st->vad_flag ); /* calculate variance of correlation */ - var_cor_calc(st->old_corr, &hSpMusClas->mold_corr, hSpMusClas->var_cor_t, &hSpMusClas->high_stable_cor); + var_cor_calc( st->old_corr, &hSpMusClas->mold_corr, hSpMusClas->var_cor_t, &hSpMusClas->high_stable_cor ); /* attack detection */ - attack = attack_det(inp, st->clas, st->localVAD, st->coder_type, 0, st->element_mode, st->clas, hSpMusClas->finc_prev, &hSpMusClas->lt_finc, &hSpMusClas->last_strong_attack); + attack = attack_det( inp, st->clas, st->localVAD, st->coder_type, 0, st->element_mode, st->clas, hSpMusClas->finc_prev, &hSpMusClas->lt_finc, &hSpMusClas->last_strong_attack ); /* tonal detector */ - ton = tonal_det(S_map, st->vad_flag, hSpMusClas->tod_S_map_lt, &hSpMusClas->tod_thr_lt, &hSpMusClas->tod_weight, &hSpMusClas->tod_S_mass_prev, &hSpMusClas->tod_S_mass_lt); + ton = tonal_det( S_map, st->vad_flag, hSpMusClas->tod_S_map_lt, &hSpMusClas->tod_thr_lt, &hSpMusClas->tod_weight, &hSpMusClas->tod_S_mass_prev, &hSpMusClas->tod_S_mass_lt ); /* calculate spectral peak-to-average ratio */ - for (i = 0; i < TOD_NSPEC; i++) + for ( i = 0; i < TOD_NSPEC; i++ ) { - st->hSpMusClas->tod_lt_Bin_E[i] = P2A_FACT * st->hSpMusClas->tod_lt_Bin_E[i] + (1 - P2A_FACT) * st->Bin_E[i]; + st->hSpMusClas->tod_lt_Bin_E[i] = P2A_FACT * st->hSpMusClas->tod_lt_Bin_E[i] + ( 1 - P2A_FACT ) * st->Bin_E[i]; } - maximum(st->hSpMusClas->tod_lt_Bin_E, TOD_NSPEC, &S_max); - S_ave = sum_f(st->hSpMusClas->tod_lt_Bin_E, TOD_NSPEC) / TOD_NSPEC; + maximum( st->hSpMusClas->tod_lt_Bin_E, TOD_NSPEC, &S_max ); + S_ave = sum_f( st->hSpMusClas->tod_lt_Bin_E, TOD_NSPEC ) / TOD_NSPEC; S_p2a = S_max - S_ave; thr_sp2a = THR_P2A; - if (element_brate <= IVAS_16k4) + if ( element_brate <= IVAS_16k4 ) { thr_sp2a = THR_P2A_HIGH; } /* initial 3-way selection of coding modes (ACELP/GSC/TCX) */ - if (relE > -10.0f && (S_p2a > thr_sp2a || ton > hSpMusClas->tod_thr_lt)) + if ( relE > -10.0f && ( S_p2a > thr_sp2a || ton > hSpMusClas->tod_thr_lt ) ) { /* select TCX to encode extremely peaky signals or strongly tonal signals */ st->sp_aud_decision1 = 1; st->sp_aud_decision2 = 1; } - else if (smc_dec == SPEECH) + else if ( smc_dec == SPEECH ) { /* select ACELP to encode speech */ st->sp_aud_decision1 = 0; st->sp_aud_decision2 = 0; } - else if (smc_dec == SPEECH_OR_MUSIC) + else if ( smc_dec == SPEECH_OR_MUSIC ) { /* select GSC to encode "unclear" segments (classifier's score on the borderline) */ st->sp_aud_decision1 = 1; @@ -2228,17 +2234,17 @@ void ivas_smc_mode_selection( } /* change decision from GSC to ACELP/TCX in some special cases */ - if (st->sp_aud_decision1 == 1 && st->sp_aud_decision2 == 0) + if ( st->sp_aud_decision1 == 1 && st->sp_aud_decision2 == 0 ) { - if (hSpMusClas->ener_RAT < 0.18f && hSpMusClas->lt_dec_thres > 15.0f) + if ( hSpMusClas->ener_RAT < 0.18f && hSpMusClas->lt_dec_thres > 15.0f ) { /* prevent GSC on strong music with almost no content below 1kHz */ st->sp_aud_decision2 = 1; } - else if (flag_spitch) + else if ( flag_spitch ) { /* prevent GSC on signals with very short and stable high pitch period */ - if (hSpMusClas->wdlp_0_95_sp < 2.5f) + if ( hSpMusClas->wdlp_0_95_sp < 2.5f ) { /* select ACELP instead */ st->sp_aud_decision1 = 0; @@ -2249,7 +2255,7 @@ void ivas_smc_mode_selection( st->sp_aud_decision2 = 1; } } - else if (hSpMusClas->high_stable_cor && st->pitch[0] >= 130) + else if ( hSpMusClas->high_stable_cor && st->pitch[0] >= 130 ) { /* prevent GSC in highly correlated signal with low energy variation */ /* this is basically a patch against bassoon-type of music */ @@ -2258,12 +2264,12 @@ void ivas_smc_mode_selection( } /* change decision from GSC to ACELP TC during attacks/onsets */ - if (st->sp_aud_decision1 == 1 && st->sp_aud_decision2 == 0) + if ( st->sp_aud_decision1 == 1 && st->sp_aud_decision2 == 0 ) { - if ((hSpMusClas->gsc_lt_diff_etot[MAX_LT - 1] > 4.5f) && - (hSpMusClas->gsc_lt_diff_etot[MAX_LT - 1] - hSpMusClas->gsc_lt_diff_etot[MAX_LT - 2] > 10.0f)) + if ( ( hSpMusClas->gsc_lt_diff_etot[MAX_LT - 1] > 4.5f ) && + ( hSpMusClas->gsc_lt_diff_etot[MAX_LT - 1] - hSpMusClas->gsc_lt_diff_etot[MAX_LT - 2] > 10.0f ) ) { - if (st->tc_cnt == 1) + if ( st->tc_cnt == 1 ) { /* do ACELP TC coding instead of GC/VC if onset has been already declared before */ st->sp_aud_decision1 = 0; @@ -2271,14 +2277,14 @@ void ivas_smc_mode_selection( } else { - if (attack >= ATT_3LSUB_POS) + if ( attack >= ATT_3LSUB_POS ) { /* do ACELP TC coding also if attack is located in the last subframe */ st->sp_aud_decision1 = 0; *attack_flag = attack + 1; st->coder_type = TRANSITION; } - else if (attack >= ATT_SEG_LEN / 2) + else if ( attack >= ATT_SEG_LEN / 2 ) { /* do GSC coding if attack is located after the first quarter of the first subframe */ /* (pre-echo will be treated at the decoder side) */ @@ -2289,7 +2295,7 @@ void ivas_smc_mode_selection( } } - if (st->localVAD == 1 && st->coder_type == GENERIC && attack > 0 /*&& *attack_flag < 32*/ /*&& st->tc_cnt != 2*/ && !(st->sp_aud_decision2 == 1 && ton > 0.65f)) + if ( st->localVAD == 1 && st->coder_type == GENERIC && attack > 0 /*&& *attack_flag < 32*/ /*&& st->tc_cnt != 2*/ && !( st->sp_aud_decision2 == 1 && ton > 0.65f ) ) { /* change ACELP coder_type to TC if attack has been detected */ st->sp_aud_decision1 = 0; @@ -2300,17 +2306,17 @@ void ivas_smc_mode_selection( } #ifdef DEBUGGING - if (st->idchan == 0 && st->coder_type != INACTIVE) + if ( st->idchan == 0 && st->coder_type != INACTIVE ) { - if (st->force == FORCE_GSC && element_brate < IVAS_24k4) + if ( st->force == FORCE_GSC && element_brate < IVAS_24k4 ) { /* enforce GSC */ st->sp_aud_decision1 = 1; st->sp_aud_decision2 = 0; } - else if (st->force == FORCE_SPEECH && (st->sp_aud_decision1 == 1 || st->sp_aud_decision2 == 1)) + else if ( st->force == FORCE_SPEECH && ( st->sp_aud_decision1 == 1 || st->sp_aud_decision2 == 1 ) ) { - if (element_brate < IVAS_24k4) + if ( element_brate < IVAS_24k4 ) { /* convert TCX to GSC */ st->sp_aud_decision1 = 1; @@ -2323,7 +2329,7 @@ void ivas_smc_mode_selection( st->sp_aud_decision2 = 0; } } - else if (st->force == FORCE_MUSIC) + else if ( st->force == FORCE_MUSIC ) { /* enforce TCX */ st->sp_aud_decision1 = 1; @@ -2334,27 +2340,27 @@ void ivas_smc_mode_selection( /* set GSC noisy speech flag on unvoiced SWB segments */ st->GSC_noisy_speech = 0; - if (st->vad_flag == 1 && element_brate <= IVAS_16k4 && st->lp_noise > 30.0f && st->sp_aud_decision1 == 0 && st->bwidth >= SWB && st->coder_type_raw == UNVOICED) + if ( st->vad_flag == 1 && element_brate <= IVAS_16k4 && st->lp_noise > 30.0f && st->sp_aud_decision1 == 0 && st->bwidth >= SWB && st->coder_type_raw == UNVOICED ) { st->GSC_noisy_speech = 1; } /* set GSC submode */ - if (st->element_mode > EVS_MONO && (st->sp_aud_decision1 == 1 && st->sp_aud_decision2 == 0) && st->total_brate > STEREO_GSC_BIT_RATE_ALLOC) /* below STEREO_GSC_BIT_RATE_ALLOC, fall back on normal GSC */ + if ( st->element_mode > EVS_MONO && ( st->sp_aud_decision1 == 1 && st->sp_aud_decision2 == 0 ) && st->total_brate > STEREO_GSC_BIT_RATE_ALLOC ) /* below STEREO_GSC_BIT_RATE_ALLOC, fall back on normal GSC */ { st->GSC_IVAS_mode = 1; - if (st->hSpMusClas->wdlp_0_95_sp > 0.0f) + if ( st->hSpMusClas->wdlp_0_95_sp > 0.0f ) { /* music-like content */ st->GSC_IVAS_mode = 3; } - else if (st->tc_cnt > 0) + else if ( st->tc_cnt > 0 ) { /* likely presence of an onset, GSC bit allocation will be more focused on LF */ st->GSC_IVAS_mode = 2; } - if (st->coder_type_raw == UNVOICED && st->sp_aud_decision0 == 0 /*&& st->GSC_IVAS_mode < 3*/) + if ( st->coder_type_raw == UNVOICED && st->sp_aud_decision0 == 0 /*&& st->GSC_IVAS_mode < 3*/ ) { st->GSC_noisy_speech = 1; } @@ -2365,10 +2371,10 @@ void ivas_smc_mode_selection( } /* set coder_type to AUDIO when GSC is selected (st->core will be set later in the decision matrix) */ - if ((st->sp_aud_decision1 == 1 && st->sp_aud_decision2 == 0) || st->GSC_noisy_speech) + if ( ( st->sp_aud_decision1 == 1 && st->sp_aud_decision2 == 0 ) || st->GSC_noisy_speech ) { st->coder_type = AUDIO; - if (st->hGSCEnc != NULL && st->GSC_noisy_speech == 0) /* In case of GSC_noisy_speech, NOISE_LEVEL should remain at NOISE_LEVEL_SP3 */ + if ( st->hGSCEnc != NULL && st->GSC_noisy_speech == 0 ) /* In case of GSC_noisy_speech, NOISE_LEVEL should remain at NOISE_LEVEL_SP3 */ { st->hGSCEnc->noise_lev = NOISE_LEVEL_SP0; } @@ -2386,17 +2392,17 @@ void ivas_smc_mode_selection( *---------------------------------------------------------------------*/ static Word16 mode_decision_fx( - Encoder_State *st, /* i : endoer state structure */ - Word16 len, /* i : buffering status */ - Word16 *dec_mov, /* i/o: moving average of classifier decision Q15*/ - Word16 *buf_flux, /* i : buffer storing spectral energy fluctuation Q7*/ - Word16 *buf_epsP_tilt, /* i : buffer storing LP prediciton error tilt Q15*/ - Word16 *buf_pkh, /* i : buffer storing highband spectral peakiness Q1*/ - Word16 *buf_cor_map_sum, /* i : buffer storing correlation map sum Q8*/ - Word16 *buf_Ntonal, /* i : buffer storing No.of 1st spectral tone Q0*/ - Word16 *buf_Ntonal2, /* i : buffer storing No.of 2nd spectral tone Q0*/ - Word16 *buf_Ntonal_lf, /* i : buffer storing low band spectral tone ratio Q0*/ - Word16 *buf_dlp /* i : buffer storing log probability diff between speech and music Q9*/ + Encoder_State *st, /* i : endoer state structure */ + Word16 len, /* i : buffering status */ + Word16 *dec_mov, /* i/o: moving average of classifier decision Q15*/ + Word16 *buf_flux, /* i : buffer storing spectral energy fluctuation Q7*/ + Word16 *buf_epsP_tilt, /* i : buffer storing LP prediciton error tilt Q15*/ + Word16 *buf_pkh, /* i : buffer storing highband spectral peakiness Q1*/ + Word16 *buf_cor_map_sum, /* i : buffer storing correlation map sum Q8*/ + Word16 *buf_Ntonal, /* i : buffer storing No.of 1st spectral tone Q0*/ + Word16 *buf_Ntonal2, /* i : buffer storing No.of 2nd spectral tone Q0*/ + Word16 *buf_Ntonal_lf, /* i : buffer storing low band spectral tone ratio Q0*/ + Word16 *buf_dlp /* i : buffer storing log probability diff between speech and music Q9*/ ) { Word16 mode; @@ -2420,49 +2426,49 @@ static Word16 mode_decision_fx( logic16(); move16(); - IF ( LE_16(len,5)) + IF( LE_16( len, 5 ) ) { - return (mode); + return ( mode ); } ELSE { - IF ( LT_16(len,10)) + IF( LT_16( len, 10 ) ) { - inv_len = div_s(1,len); /*Q15 */ + inv_len = div_s( 1, len ); /*Q15 */ - L_tmp = L_deposit_l(0); - FOR(i=0; i3; i-- ) + FOR( i = 9; i > 3; i-- ) { if ( buf_dlp[i] > 0 ) { - voiced_cnt = add(voiced_cnt,1); + voiced_cnt = add( voiced_cnt, 1 ); } } @@ -2470,12 +2476,12 @@ static Word16 mode_decision_fx( test(); test(); test(); - IF ( (GT_16(M_pkh,2200) || LT_32(V_epsP_tilt,171799) || GT_16(M_cor_map_sum,25600)) && LT_16(voiced_cnt, 4) ) + IF( ( GT_16( M_pkh, 2200 ) || LT_32( V_epsP_tilt, 171799 ) || GT_16( M_cor_map_sum, 25600 ) ) && LT_16( voiced_cnt, 4 ) ) { mode = 1; move16(); } - ELSE IF ( GT_16(M_Ntonal,108) && LT_16(voiced_cnt, 4)) /*27 in Q2 */ + ELSE IF( GT_16( M_Ntonal, 108 ) && LT_16( voiced_cnt, 4 ) ) /*27 in Q2 */ { mode = 1; move16(); @@ -2485,49 +2491,49 @@ static Word16 mode_decision_fx( { voiced_cnt = 0; move16(); - FOR ( i=0; i<10; i++ ) + FOR( i = 0; i < 10; i++ ) { if ( buf_dlp[i] > 0 ) { - voiced_cnt = add(voiced_cnt,1); + voiced_cnt = add( voiced_cnt, 1 ); } } inv_len = 3277; /*Q15 */ - L_tmp = L_deposit_l(0); - FOR(i=0; i<10; i++) + L_tmp = L_deposit_l( 0 ); + FOR( i = 0; i < 10; i++ ) { - L_tmp = L_add(L_tmp,L_shl(buf_flux[BUF_LEN-10+i],2)); /*Q9 */ + L_tmp = L_add( L_tmp, L_shl( buf_flux[BUF_LEN - 10 + i], 2 ) ); /*Q9 */ } - L_tmp = Mult_32_16(L_tmp,inv_len); /*Q9 */ - M_flux10 = extract_l(L_tmp); /*Q9 */ + L_tmp = Mult_32_16( L_tmp, inv_len ); /*Q9 */ + M_flux10 = extract_l( L_tmp ); /*Q9 */ - L_tmp = L_deposit_l(0); - FOR(i=0; i<10; i++) + L_tmp = L_deposit_l( 0 ); + FOR( i = 0; i < 10; i++ ) { - L_tmp = L_add(L_tmp,buf_pkh[BUF_LEN-10+i]); /*Q1 */ + L_tmp = L_add( L_tmp, buf_pkh[BUF_LEN - 10 + i] ); /*Q1 */ } - L_tmp = Mult_32_16(L_tmp,inv_len); /*Q1 */ - M_pkh = extract_l(L_tmp); /*Q1 */ + L_tmp = Mult_32_16( L_tmp, inv_len ); /*Q1 */ + M_pkh = extract_l( L_tmp ); /*Q1 */ - L_tmp = L_deposit_l(0); - FOR(i=0; i<10; i++) + L_tmp = L_deposit_l( 0 ); + FOR( i = 0; i < 10; i++ ) { - L_tmp = L_add(L_tmp,buf_cor_map_sum[BUF_LEN-10+i]); /*Q8 */ + L_tmp = L_add( L_tmp, buf_cor_map_sum[BUF_LEN - 10 + i] ); /*Q8 */ } - L_tmp = Mult_32_16(L_tmp,inv_len); /*Q8 */ - M_cor_map_sum = extract_l(L_tmp); /*Q8 */ + L_tmp = Mult_32_16( L_tmp, inv_len ); /*Q8 */ + M_cor_map_sum = extract_l( L_tmp ); /*Q8 */ - V_epsP_tilt = var_fx_32( buf_epsP_tilt+BUF_LEN-10, 15, 10 ); /*Q31 */ + V_epsP_tilt = var_fx_32( buf_epsP_tilt + BUF_LEN - 10, 15, 10 ); /*Q31 */ - L_tmp = L_deposit_l(0); - FOR(i=0; i<5; i++) + L_tmp = L_deposit_l( 0 ); + FOR( i = 0; i < 5; i++ ) { - L_tmp = L_add(L_tmp,L_shl(buf_flux[BUF_LEN-5+i],2)); /*Q9 */ + L_tmp = L_add( L_tmp, L_shl( buf_flux[BUF_LEN - 5 + i], 2 ) ); /*Q9 */ } - L_tmp = Mult_32_16(L_tmp,6554); /*Q9 */ - tmp = extract_l(L_tmp); /*Q9 */ + L_tmp = Mult_32_16( L_tmp, 6554 ); /*Q9 */ + tmp = extract_l( L_tmp ); /*Q9 */ test(); test(); @@ -2535,8 +2541,9 @@ static Word16 mode_decision_fx( test(); test(); test(); - IF ( (LT_16(M_flux10,4352) || (LT_32(V_epsP_tilt,2147484) && LT_16(M_flux10,6144)) || GT_16(M_pkh,2100) || - GT_16(M_cor_map_sum,25600)) && LT_16(voiced_cnt,3) && LT_16(tmp,7680) ) + IF( ( LT_16( M_flux10, 4352 ) || ( LT_32( V_epsP_tilt, 2147484 ) && LT_16( M_flux10, 6144 ) ) || GT_16( M_pkh, 2100 ) || + GT_16( M_cor_map_sum, 25600 ) ) && + LT_16( voiced_cnt, 3 ) && LT_16( tmp, 7680 ) ) { mode = 1; move16(); @@ -2550,8 +2557,8 @@ static Word16 mode_decision_fx( test(); test(); test(); - IF ( GT_16(M_flux10,8192) || (GT_16(M_flux10,7680) && GT_16(voiced_cnt, 2)) || GT_16(tmp,9728) || - (GE_16(buf_flux[59],2560) && GT_16(hSpMusClas->lps_fx, hSpMusClas->lpm_fx))) + IF( GT_16( M_flux10, 8192 ) || ( GT_16( M_flux10, 7680 ) && GT_16( voiced_cnt, 2 ) ) || GT_16( tmp, 9728 ) || + ( GE_16( buf_flux[59], 2560 ) && GT_16( hSpMusClas->lps_fx, hSpMusClas->lpm_fx ) ) ) { mode = 0; move16(); @@ -2560,88 +2567,89 @@ static Word16 mode_decision_fx( return ( mode ); } - FOR ( i=10; i=0; i-- ) + FOR( i = 125; i >= 0; i-- ) { - IF (LE_16(Bin_E[i+1],Bin_E[i])) + IF( LE_16( Bin_E[i + 1], Bin_E[i] ) ) { BREAK; } @@ -2903,16 +2911,16 @@ static void spec_analysis_fx( move16(); } - FOR ( i=1; ivad_flag == 0 || LT_16(sub(st->lp_speech_fx,st->lp_noise_fx),6400)) /* 25 in Q8 */ + IF( st->vad_flag == 0 || LT_16( sub( st->lp_speech_fx, st->lp_noise_fx ), 6400 ) ) /* 25 in Q8 */ { /* st->dec_mov = 0.5f; */ /* st->dec_mov1 = 0.5f; */ @@ -2985,7 +2993,7 @@ static void music_mixed_classif_improv_fx( hSpMusClas->dec_mov1_fx = 16384; move16(); - if (st->vad_flag == 0 ) + if ( st->vad_flag == 0 ) { hSpMusClas->onset_cnt = 0; move16(); @@ -2994,12 +3002,12 @@ static void music_mixed_classif_improv_fx( return; } - hSpMusClas->onset_cnt = add(hSpMusClas->onset_cnt,1); - hSpMusClas->onset_cnt = s_min(hSpMusClas->onset_cnt, 9); + hSpMusClas->onset_cnt = add( hSpMusClas->onset_cnt, 1 ); + hSpMusClas->onset_cnt = s_min( hSpMusClas->onset_cnt, 9 ); - IF ( EQ_16(hSpMusClas->onset_cnt,1)) + IF( EQ_16( hSpMusClas->onset_cnt, 1 ) ) { - set16_fx(hSpMusClas->buf_flux_fx, -12800, BUF_LEN ); /*-100.0 in Q7 */ + set16_fx( hSpMusClas->buf_flux_fx, -12800, BUF_LEN ); /*-100.0 in Q7 */ } /* spectral analysis */ @@ -3008,44 +3016,44 @@ static void music_mixed_classif_improv_fx( /* percussive music detection */ log_max_spl = 0; move16(); - IF ( max_spl ) + IF( max_spl ) { - L_tmp = L_deposit_h(max_spl); /*Q16 */ - exp = norm_l(L_tmp); - frac = Log2_norm_lc(L_shl(L_tmp,exp)); - exp = sub(sub(30,exp),16); - L_tmp = Mpy_32_16(exp,frac,28391); /*Q12 */ - log_max_spl = round_fx(L_shl(L_tmp,11)); /*Q7 */ + L_tmp = L_deposit_h( max_spl ); /*Q16 */ + exp = norm_l( L_tmp ); + frac = Log2_norm_lc( L_shl( L_tmp, exp ) ); + exp = sub( sub( 30, exp ), 16 ); + L_tmp = Mpy_32_16( exp, frac, 28391 ); /*Q12 */ + log_max_spl = round_fx( L_shl( L_tmp, 11 ) ); /*Q7 */ } - lt_diff = sub(log_max_spl, hSpMusClas->mov_log_max_spl_fx); /*Q7 */ + lt_diff = sub( log_max_spl, hSpMusClas->mov_log_max_spl_fx ); /*Q7 */ - FOR ( i=0; i<3; i++ ) + FOR( i = 0; i < 3; i++ ) { - hSpMusClas->buf_etot_fx[i] = hSpMusClas->buf_etot_fx[i+1]; + hSpMusClas->buf_etot_fx[i] = hSpMusClas->buf_etot_fx[i + 1]; move16(); /*Q8 */ } hSpMusClas->buf_etot_fx[i] = etot; - move16();/*Q8 */ + move16(); /*Q8 */ percus_flag = 0; move16(); test(); test(); - IF ( GT_16(sub(hSpMusClas->buf_etot_fx[1], hSpMusClas->buf_etot_fx[0]),1536)&& - LT_16(hSpMusClas->buf_etot_fx[2], hSpMusClas->buf_etot_fx[1]) && - GT_16(sub(hSpMusClas->buf_etot_fx[1], st->lp_speech_fx),768) ) /* 3 in Q8 */ + IF( GT_16( sub( hSpMusClas->buf_etot_fx[1], hSpMusClas->buf_etot_fx[0] ), 1536 ) && + LT_16( hSpMusClas->buf_etot_fx[2], hSpMusClas->buf_etot_fx[1] ) && + GT_16( sub( hSpMusClas->buf_etot_fx[1], st->lp_speech_fx ), 768 ) ) /* 3 in Q8 */ { /*tmp = add(shr(voicing[0],2),shr(voicing[1],2)); //Q15 */ /*tmp = add(tmp,shr(old_cor,1)); //Q15 */ - tmp = mac_r(L_mac(L_mult(st->voicing_fx[0],8192),st->voicing_fx[1],8192),old_cor, 16384); + tmp = mac_r( L_mac( L_mult( st->voicing_fx[0], 8192 ), st->voicing_fx[1], 8192 ), old_cor, 16384 ); test(); test(); - IF ( GT_16(sub(hSpMusClas->buf_etot_fx[1], hSpMusClas->buf_etot_fx[3]),768)&& - LT_16(hSpMusClas->buf_etot_fx[3], hSpMusClas->buf_etot_fx[2]) && - LT_16(tmp,24576)) /* 0.75 in Q15 */ + IF( GT_16( sub( hSpMusClas->buf_etot_fx[1], hSpMusClas->buf_etot_fx[3] ), 768 ) && + LT_16( hSpMusClas->buf_etot_fx[3], hSpMusClas->buf_etot_fx[2] ) && + LT_16( tmp, 24576 ) ) /* 0.75 in Q15 */ { - IF ( GT_16(hSpMusClas->dec_mov_fx,26214)) /* 0.8 in Q15 */ + IF( GT_16( hSpMusClas->dec_mov_fx, 26214 ) ) /* 0.8 in Q15 */ { percus_flag = 1; move16(); @@ -3055,7 +3063,7 @@ static void music_mixed_classif_improv_fx( test(); test(); test(); - IF ( LT_16(old_cor,24576)&<_16(st->voicing_fx[0],24576)&<_16(st->voicing_fx[1],24576)&>_16(hSpMusClas->old_lt_diff_fx[0],1280)) + IF( LT_16( old_cor, 24576 ) && LT_16( st->voicing_fx[0], 24576 ) && LT_16( st->voicing_fx[1], 24576 ) && GT_16( hSpMusClas->old_lt_diff_fx[0], 1280 ) ) { percus_flag = 1; move16(); @@ -3068,58 +3076,55 @@ static void music_mixed_classif_improv_fx( test(); test(); test(); - IF ( GT_16(sub(hSpMusClas->buf_etot_fx[3], hSpMusClas->buf_etot_fx[2]),1536) - && GT_16(hSpMusClas->dec_mov_fx,29491) - && GT_16(sub(etot,st->lp_speech_fx),1280) - && GT_16(hSpMusClas->old_lt_diff_fx[0],640)) + IF( GT_16( sub( hSpMusClas->buf_etot_fx[3], hSpMusClas->buf_etot_fx[2] ), 1536 ) && GT_16( hSpMusClas->dec_mov_fx, 29491 ) && GT_16( sub( etot, st->lp_speech_fx ), 1280 ) && GT_16( hSpMusClas->old_lt_diff_fx[0], 640 ) ) { hSpMusClas->attack_hangover = 3; move16(); } test(); - IF ( GT_16(st->voicing_fx[0],29491)&>_16(st->voicing_fx[1],29491)) + IF( GT_16( st->voicing_fx[0], 29491 ) && GT_16( st->voicing_fx[1], 29491 ) ) { - IF ( GT_16(log_max_spl, hSpMusClas->mov_log_max_spl_fx)) + IF( GT_16( log_max_spl, hSpMusClas->mov_log_max_spl_fx ) ) { /**mov_log_max_spl = add(mult_r(31130,(*mov_log_max_spl)),mult_r(1638,log_max_spl)); //Q7 */ - hSpMusClas->mov_log_max_spl_fx = round_fx(L_mac(L_mult(31130, hSpMusClas->mov_log_max_spl_fx),1638,log_max_spl)); /*Q7 */ + hSpMusClas->mov_log_max_spl_fx = round_fx( L_mac( L_mult( 31130, hSpMusClas->mov_log_max_spl_fx ), 1638, log_max_spl ) ); /*Q7 */ } ELSE { /**mov_log_max_spl = add(mult_r(32604,(*mov_log_max_spl)),mult_r(164,log_max_spl)); //Q7 */ - hSpMusClas->mov_log_max_spl_fx = round_fx(L_mac(L_mult(32604,hSpMusClas->mov_log_max_spl_fx),164,log_max_spl)); /*Q7 */ + hSpMusClas->mov_log_max_spl_fx = round_fx( L_mac( L_mult( 32604, hSpMusClas->mov_log_max_spl_fx ), 164, log_max_spl ) ); /*Q7 */ } } hSpMusClas->old_lt_diff_fx[0] = hSpMusClas->old_lt_diff_fx[1]; - move16(); /*Q7 */ + move16(); /*Q7 */ hSpMusClas->old_lt_diff_fx[1] = lt_diff; - move16(); /*Q7 */ + move16(); /*Q7 */ /* calculate and buffer spectral energy fluctuation */ flux_fx( st->lgBin_E_fx, p2v_map, hSpMusClas->old_Bin_E_fx, hSpMusClas->buf_flux_fx, hSpMusClas->attack_hangover, hSpMusClas->dec_mov_fx ); - hSpMusClas->attack_hangover = sub(hSpMusClas->attack_hangover,1); - hSpMusClas->attack_hangover = s_max(hSpMusClas->attack_hangover,0); + hSpMusClas->attack_hangover = sub( hSpMusClas->attack_hangover, 1 ); + hSpMusClas->attack_hangover = s_max( hSpMusClas->attack_hangover, 0 ); /* identify flux buffer buffering status */ len = 0; move16(); - FOR ( i=BUF_LEN-1; i>=0; i-- ) + FOR( i = BUF_LEN - 1; i >= 0; i-- ) { - IF (hSpMusClas->buf_flux_fx[i] < 0) + IF( hSpMusClas->buf_flux_fx[i] < 0 ) { BREAK; } - len = add(len,1); + len = add( len, 1 ); } /* reset flux buffer if percussive music is detected */ - IF ( EQ_16(percus_flag,1)) + IF( EQ_16( percus_flag, 1 ) ) { - set16_fx( &hSpMusClas->buf_flux_fx[BUF_LEN-len], 640, len ); /* 5 in Q7 */ + set16_fx( &hSpMusClas->buf_flux_fx[BUF_LEN - len], 640, len ); /* 5 in Q7 */ } /* calculate and buffer the tilt of residual LP energies */ @@ -3127,104 +3132,104 @@ static void music_mixed_classif_improv_fx( move16(); ftmp1 = 0; move16(); - FOR( i=1; i<=16; i++ ) + FOR( i = 1; i <= 16; i++ ) { - epsP_max = L_max(epsP_max , epsP[i]); + epsP_max = L_max( epsP_max, epsP[i] ); } - FOR ( i=1; i<16; i++ ) + FOR( i = 1; i < 16; i++ ) { - IF(EQ_32(epsP[i], epsP_max)) + IF( EQ_32( epsP[i], epsP_max ) ) { tmp = -32768; move16(); - L_tmp = Mult_32_16(epsP[i],tmp); /* Q_epsP */ - ftmp = L_sub(ftmp,L_shr(L_tmp,4)); /* Q(Q_epsP-4) */ + L_tmp = Mult_32_16( epsP[i], tmp ); /* Q_epsP */ + ftmp = L_sub( ftmp, L_shr( L_tmp, 4 ) ); /* Q(Q_epsP-4) */ } ELSE { - expn = norm_l(epsP[i]); - fracn = extract_h(L_shl(epsP[i],expn)); - expn = sub(sub(30,expn),Q_epsP); + expn = norm_l( epsP[i] ); + fracn = extract_h( L_shl( epsP[i], expn ) ); + expn = sub( sub( 30, expn ), Q_epsP ); - expd = norm_l(epsP_max); - fracd = extract_h(L_shl(epsP_max,expd)); - expd = sub(sub(30,expd),Q_epsP); + expd = norm_l( epsP_max ); + fracd = extract_h( L_shl( epsP_max, expd ) ); + expd = sub( sub( 30, expd ), Q_epsP ); - scale = shr(sub(fracd,fracn),15); - fracn = shl(fracn,scale); - expn = sub(expn,scale); + scale = shr( sub( fracd, fracn ), 15 ); + fracn = shl( fracn, scale ); + expn = sub( expn, scale ); - tmp = div_s(fracn,fracd); /*Q(15+expd-expn) */ - tmp = shl(tmp,sub(expn,expd)); /*Q15 */ + tmp = div_s( fracn, fracd ); /*Q(15+expd-expn) */ + tmp = shl( tmp, sub( expn, expd ) ); /*Q15 */ - L_tmp = Mult_32_16(epsP[i],tmp); /*Q_epsP */ - ftmp = L_add(ftmp,L_shr(L_tmp,4)); /*Q(Q_epsP-4) */ + L_tmp = Mult_32_16( epsP[i], tmp ); /*Q_epsP */ + ftmp = L_add( ftmp, L_shr( L_tmp, 4 ) ); /*Q(Q_epsP-4) */ } } - FOR ( i=1; i<16; i++ ) + FOR( i = 1; i < 16; i++ ) { - IF(EQ_32(epsP[i], epsP_max)) + IF( EQ_32( epsP[i], epsP_max ) ) { tmp = -32768; move16(); - L_tmp = Mult_32_16(epsP[i+1],tmp); /*Q_epsP */ - ftmp1 = L_sub(ftmp1,L_shr(L_tmp,4)); /*Q(Q_epsP-4) */ + L_tmp = Mult_32_16( epsP[i + 1], tmp ); /*Q_epsP */ + ftmp1 = L_sub( ftmp1, L_shr( L_tmp, 4 ) ); /*Q(Q_epsP-4) */ } - ELSE IF(EQ_32(epsP[i+1],epsP_max)) + ELSE IF( EQ_32( epsP[i + 1], epsP_max ) ) { tmp = -32768; move16(); - L_tmp = Mult_32_16(epsP[i],tmp); /*Q_epsP */ - ftmp1 = L_sub(ftmp1,L_shr(L_tmp,4)); /*Q(Q_epsP-4) */ + L_tmp = Mult_32_16( epsP[i], tmp ); /*Q_epsP */ + ftmp1 = L_sub( ftmp1, L_shr( L_tmp, 4 ) ); /*Q(Q_epsP-4) */ } ELSE { - expn = norm_l(epsP[i]); - fracn = extract_h(L_shl(epsP[i],expn)); - expn = sub(sub(30,expn),Q_epsP); + expn = norm_l( epsP[i] ); + fracn = extract_h( L_shl( epsP[i], expn ) ); + expn = sub( sub( 30, expn ), Q_epsP ); - expd = norm_l(epsP_max); - fracd = extract_h(L_shl(epsP_max,expd)); - expd = sub(sub(30,expd),Q_epsP); + expd = norm_l( epsP_max ); + fracd = extract_h( L_shl( epsP_max, expd ) ); + expd = sub( sub( 30, expd ), Q_epsP ); - scale = shr(sub(fracd,fracn),15); - fracn = shl(fracn,scale); - expn = sub(expn,scale); + scale = shr( sub( fracd, fracn ), 15 ); + fracn = shl( fracn, scale ); + expn = sub( expn, scale ); - tmp = div_s(fracn,fracd); /*Q(15+expd-expn) */ - tmp = shl(tmp,sub(expn,expd)); /*Q15 */ + tmp = div_s( fracn, fracd ); /*Q(15+expd-expn) */ + tmp = shl( tmp, sub( expn, expd ) ); /*Q15 */ - L_tmp = Mult_32_16(epsP[i+1],tmp); /*Q_epsP */ - ftmp1 = L_add(ftmp1,L_shr(L_tmp,4)); /*Q(Q_epsP-4) */ + L_tmp = Mult_32_16( epsP[i + 1], tmp ); /*Q_epsP */ + ftmp1 = L_add( ftmp1, L_shr( L_tmp, 4 ) ); /*Q(Q_epsP-4) */ } } /* epsP_tilt = ftmp1/ftmp; */ - expn = norm_l(ftmp1); - fracn = extract_h(L_shl(ftmp1,expn)); - expn = sub(sub(30,expn),Q_epsP-4); + expn = norm_l( ftmp1 ); + fracn = extract_h( L_shl( ftmp1, expn ) ); + expn = sub( sub( 30, expn ), Q_epsP - 4 ); - expd = norm_l(ftmp); -#ifdef BASOP_NOGLOB - fracd = round_fx_sat(L_shl(ftmp,expd)); + expd = norm_l( ftmp ); +#ifdef BASOP_NOGLOB + fracd = round_fx_sat( L_shl( ftmp, expd ) ); #else - fracd = round_fx(L_shl(ftmp,expd)); + fracd = round_fx( L_shl( ftmp, expd ) ); #endif - expd = sub(sub(30,expd),sub(Q_epsP,4)); + expd = sub( sub( 30, expd ), sub( Q_epsP, 4 ) ); - scale = shr(sub(fracd,fracn),15); - fracn = shl(fracn,scale); - expn = sub(expn,scale); + scale = shr( sub( fracd, fracn ), 15 ); + fracn = shl( fracn, scale ); + expn = sub( expn, scale ); - tmp = div_s(fracn,fracd); /*Q(15+expd-expn) */ + tmp = div_s( fracn, fracd ); /*Q(15+expd-expn) */ - epsP_tilt = shl(tmp,sub(expn,expd)); /*Q15 */ + epsP_tilt = shl( tmp, sub( expn, expd ) ); /*Q15 */ - FOR ( i=0; ibuf_epsP_tilt_fx[i] = hSpMusClas->buf_epsP_tilt_fx[i+1]; + hSpMusClas->buf_epsP_tilt_fx[i] = hSpMusClas->buf_epsP_tilt_fx[i + 1]; move16(); /*Q15 */ } hSpMusClas->buf_epsP_tilt_fx[i] = epsP_tilt; @@ -3234,41 +3239,41 @@ static void music_mixed_classif_improv_fx( tonal_dist_fx( p2v_map, hSpMusClas->buf_pkh_fx, hSpMusClas->buf_Ntonal_fx, hSpMusClas->buf_Ntonal2_fx, hSpMusClas->buf_Ntonal_lf_fx ); /* buffer sum of correlation map */ - FOR ( i=0; ibuf_cor_map_sum_fx[i] = hSpMusClas->buf_cor_map_sum_fx[i+1]; + hSpMusClas->buf_cor_map_sum_fx[i] = hSpMusClas->buf_cor_map_sum_fx[i + 1]; move16(); /*Q8 */ } hSpMusClas->buf_cor_map_sum_fx[i] = cor_map_sum; move16(); /*Q8 */ /* buffer voicing metric */ - FOR ( i=0; i<9; i++ ) + FOR( i = 0; i < 9; i++ ) { - hSpMusClas->buf_dlp_fx[i] = hSpMusClas->buf_dlp_fx[i+1]; + hSpMusClas->buf_dlp_fx[i] = hSpMusClas->buf_dlp_fx[i + 1]; move16(); } - hSpMusClas->buf_dlp_fx[i] = sub(hSpMusClas->lps_fx, hSpMusClas->lpm_fx); - move16();/*Q9 */ + hSpMusClas->buf_dlp_fx[i] = sub( hSpMusClas->lps_fx, hSpMusClas->lpm_fx ); + move16(); /*Q9 */ /* classification */ dec = mode_decision_fx( st, len, &hSpMusClas->dec_mov_fx, hSpMusClas->buf_flux_fx, hSpMusClas->buf_epsP_tilt_fx, hSpMusClas->buf_pkh_fx, - hSpMusClas->buf_cor_map_sum_fx, hSpMusClas->buf_Ntonal_fx, hSpMusClas->buf_Ntonal2_fx, hSpMusClas->buf_Ntonal_lf_fx, - hSpMusClas->buf_dlp_fx ); + hSpMusClas->buf_cor_map_sum_fx, hSpMusClas->buf_Ntonal_fx, hSpMusClas->buf_Ntonal2_fx, hSpMusClas->buf_Ntonal_lf_fx, + hSpMusClas->buf_dlp_fx ); move16(); /* update long term moving average of the classification decisions */ - IF ( GT_16(len,30)) + IF( GT_16( len, 30 ) ) { IF( dec == 0 ) { - hSpMusClas->dec_mov_fx = mult_r(31785, hSpMusClas->dec_mov_fx); /*Q15 */ - hSpMusClas->dec_mov1_fx = mult_r(31785, hSpMusClas->dec_mov1_fx); /*Q15 */ + hSpMusClas->dec_mov_fx = mult_r( 31785, hSpMusClas->dec_mov_fx ); /*Q15 */ + hSpMusClas->dec_mov1_fx = mult_r( 31785, hSpMusClas->dec_mov1_fx ); /*Q15 */ } ELSE { - hSpMusClas->dec_mov_fx = add(mult_r(31785,hSpMusClas->dec_mov_fx),983); /*Q15 */ - hSpMusClas->dec_mov1_fx = add(mult_r(31785, hSpMusClas->dec_mov1_fx),983); /*Q15 */ + hSpMusClas->dec_mov_fx = add( mult_r( 31785, hSpMusClas->dec_mov_fx ), 983 ); /*Q15 */ + hSpMusClas->dec_mov1_fx = add( mult_r( 31785, hSpMusClas->dec_mov1_fx ), 983 ); /*Q15 */ } } @@ -3276,33 +3281,33 @@ static void music_mixed_classif_improv_fx( test(); test(); test(); - IF ( (EQ_16(st->coder_type_raw,UNVOICED)||EQ_16(st->coder_type_raw,INACTIVE))&& - GT_16(etot,384) && LT_16(hSpMusClas->buf_Ntonal2_fx[59],2) ) + IF( ( EQ_16( st->coder_type_raw, UNVOICED ) || EQ_16( st->coder_type_raw, INACTIVE ) ) && + GT_16( etot, 384 ) && LT_16( hSpMusClas->buf_Ntonal2_fx[59], 2 ) ) { - hSpMusClas->UV_cnt1 = sub(hSpMusClas->UV_cnt1,8); + hSpMusClas->UV_cnt1 = sub( hSpMusClas->UV_cnt1, 8 ); } ELSE { - hSpMusClas->UV_cnt1 = add(hSpMusClas->UV_cnt1,1); + hSpMusClas->UV_cnt1 = add( hSpMusClas->UV_cnt1, 1 ); } - hSpMusClas->UV_cnt1 = s_min(hSpMusClas->UV_cnt1,300); - hSpMusClas->UV_cnt1 = s_max(hSpMusClas->UV_cnt1,0); + hSpMusClas->UV_cnt1 = s_min( hSpMusClas->UV_cnt1, 300 ); + hSpMusClas->UV_cnt1 = s_max( hSpMusClas->UV_cnt1, 0 ); - /**LT_UV_cnt1 = add(mult_r(29491,*LT_UV_cnt1),mult_r(3277,shl(*UV_cnt1,6)));*/ /* Q6 */ - hSpMusClas->LT_UV_cnt1_fx = round_fx(L_mac(L_mult(29491, hSpMusClas->LT_UV_cnt1_fx),3277,shl(hSpMusClas->UV_cnt1,6))); /*Q6 */ + /**LT_UV_cnt1 = add(mult_r(29491,*LT_UV_cnt1),mult_r(3277,shl(*UV_cnt1,6)));*/ /* Q6 */ + hSpMusClas->LT_UV_cnt1_fx = round_fx( L_mac( L_mult( 29491, hSpMusClas->LT_UV_cnt1_fx ), 3277, shl( hSpMusClas->UV_cnt1, 6 ) ) ); /*Q6 */ /* revert classification decision due to long-term unvoiced counter */ test(); test(); - IF ( EQ_16(dec,1)&<_16(hSpMusClas->dec_mov1_fx,6554)&<_16(hSpMusClas->LT_UV_cnt1_fx,12800)) + IF( EQ_16( dec, 1 ) && LT_16( hSpMusClas->dec_mov1_fx, 6554 ) && LT_16( hSpMusClas->LT_UV_cnt1_fx, 12800 ) ) { dec = 0; move16(); } /* overwrite 1st stage speech/music decision to music */ - IF (EQ_16(dec,1)) + IF( EQ_16( dec, 1 ) ) { st->sp_aud_decision1 = 1; move16(); @@ -3312,7 +3317,6 @@ static void music_mixed_classif_improv_fx( } - /*----------------------------------------------------------------------------------* * tonal_context_improv_fx() * @@ -3320,13 +3324,12 @@ static void music_mixed_classif_improv_fx( *----------------------------------------------------------------------------------*/ static void tonal_context_improv_fx( - Encoder_State *st_fx, /* i/o: Encoder state structure */ - const Word32 PS[], /* i : energy spectrum */ - const Word16 voi_fv, /* i : scaled voicing feature */ - const Word16 cor_map_sum_fv, /* i : scaled correlation map feature */ - const Word16 LPCErr, /* i : scaled LP prediction error feature */ - const Word16 Qx -) + Encoder_State *st_fx, /* i/o: Encoder state structure */ + const Word32 PS[], /* i : energy spectrum */ + const Word16 voi_fv, /* i : scaled voicing feature */ + const Word16 cor_map_sum_fv, /* i : scaled correlation map feature */ + const Word16 LPCErr, /* i : scaled LP prediction error feature */ + const Word16 Qx ) { Word16 t2_fx, t3_fx, tL_fx, err_fx, cor_fx, dft_fx; Word16 exp, expa, expb, fraca, fracb, scale, exp1, exp2, exp3, tmp; @@ -3338,18 +3341,18 @@ static void tonal_context_improv_fx( Flag Overflow = 0; #endif - IF ( EQ_16(st_fx->last_codec_mode, MODE2)) + IF( EQ_16( st_fx->last_codec_mode, MODE2 ) ) { - set16_fx(hSpMusClas->tonality2_buf_fx,0,HANG_LEN_INIT); - set16_fx(hSpMusClas->tonality3_buf_fx,0,HANG_LEN_INIT); - set16_fx(hSpMusClas->LPCErr_buf_fx,0,HANG_LEN_INIT); + set16_fx( hSpMusClas->tonality2_buf_fx, 0, HANG_LEN_INIT ); + set16_fx( hSpMusClas->tonality3_buf_fx, 0, HANG_LEN_INIT ); + set16_fx( hSpMusClas->LPCErr_buf_fx, 0, HANG_LEN_INIT ); hSpMusClas->lt_music_hangover = 0; move16(); - hSpMusClas->lt_music_state = 0; + hSpMusClas->lt_music_state = 0; move16(); - hSpMusClas->lt_speech_state = 0; + hSpMusClas->lt_speech_state = 0; move16(); - hSpMusClas->lt_speech_hangover= 0; + hSpMusClas->lt_speech_hangover = 0; move16(); } @@ -3357,146 +3360,146 @@ static void tonal_context_improv_fx( Copy32( PS, sort_val, 80 ); /* tonality in band [0-1 kHz] */ - sort_32_fx(sort_val, 0, 19); - sort_max = L_add(sort_val[19], 0); - sort_avg = sum32_fx(&sort_val[0], 10); + sort_32_fx( sort_val, 0, 19 ); + sort_max = L_add( sort_val[19], 0 ); + sort_avg = sum32_fx( &sort_val[0], 10 ); /* tonality1 = sort_max / sort_avg; */ IF( sort_avg ) { - expa = norm_l(sort_max); - fraca = extract_h(L_shl(sort_max,expa)); - expa = sub(30,add(expa, Qx)); + expa = norm_l( sort_max ); + fraca = extract_h( L_shl( sort_max, expa ) ); + expa = sub( 30, add( expa, Qx ) ); - expb = norm_l(sort_avg); - fracb = extract_h(L_shl(sort_avg,expb)); - expb = sub(30,add(expb, Qx)); + expb = norm_l( sort_avg ); + fracb = extract_h( L_shl( sort_avg, expb ) ); + expb = sub( 30, add( expb, Qx ) ); - scale = shr(sub(fracb,fraca),15); - fraca = shl(fraca,scale); - expa = sub(expa,scale); + scale = shr( sub( fracb, fraca ), 15 ); + fraca = shl( fraca, scale ); + expa = sub( expa, scale ); - tmp = div_s(fraca,fracb); - exp1 = sub(expa,expb); + tmp = div_s( fraca, fracb ); + exp1 = sub( expa, expb ); #ifdef BASOP_NOGLOB - tonality1 = L_shl_o(tmp , exp1, &Overflow); + tonality1 = L_shl_o( tmp, exp1, &Overflow ); #else /* BASOP_NOGLOB */ - tonality1 = L_shl(tmp , exp1); + tonality1 = L_shl( tmp, exp1 ); #endif } ELSE { - tonality1 = L_shl(sort_max,sub(15,Qx)); /*Q15 */ + tonality1 = L_shl( sort_max, sub( 15, Qx ) ); /*Q15 */ } /* tonality in band [1-2 kHz] */ - sort_32_fx(sort_val, 20, 39); + sort_32_fx( sort_val, 20, 39 ); sort_max = sort_val[39]; - sort_avg = sum32_fx(&sort_val[20], 10); + sort_avg = sum32_fx( &sort_val[20], 10 ); IF( sort_avg ) { /* tonality2 = sort_max / sort_avg; */ - expa = norm_l(sort_max); - fraca = extract_h(L_shl(sort_max,expa)); - expa = sub(30,add(expa, Qx)); + expa = norm_l( sort_max ); + fraca = extract_h( L_shl( sort_max, expa ) ); + expa = sub( 30, add( expa, Qx ) ); - expb = norm_l(sort_avg); - fracb = extract_h(L_shl(sort_avg,expb)); - expb = sub(30,add(expb, Qx)); + expb = norm_l( sort_avg ); + fracb = extract_h( L_shl( sort_avg, expb ) ); + expb = sub( 30, add( expb, Qx ) ); - scale = shr(sub(fracb,fraca),15); - fraca = shl(fraca,scale); - expa = sub(expa,scale); + scale = shr( sub( fracb, fraca ), 15 ); + fraca = shl( fraca, scale ); + expa = sub( expa, scale ); - tmp = div_s(fraca,fracb); - exp2 = sub(expa,expb); + tmp = div_s( fraca, fracb ); + exp2 = sub( expa, expb ); #ifdef BASOP_NOGLOB - tonality2 = L_shl_o(tmp , exp2, &Overflow); + tonality2 = L_shl_o( tmp, exp2, &Overflow ); #else - tonality2 = L_shl(tmp , exp2); + tonality2 = L_shl( tmp, exp2 ); #endif } ELSE { - tonality2 = L_shl(sort_max,sub(15,Qx)); /*Q15 */ + tonality2 = L_shl( sort_max, sub( 15, Qx ) ); /*Q15 */ } /* tonality in band [2-4 kHz] */ - sort_32_fx(sort_val, 40, 79); + sort_32_fx( sort_val, 40, 79 ); sort_max = sort_val[79]; - sort_avg = sum32_fx(&sort_val[40], 20); + sort_avg = sum32_fx( &sort_val[40], 20 ); IF( sort_avg ) { /* tonality3 = sort_max / sort_avg; */ - expa = norm_l(sort_max); - fraca = extract_h(L_shl(sort_max,expa)); - expa = sub(30,add(expa, Qx)); + expa = norm_l( sort_max ); + fraca = extract_h( L_shl( sort_max, expa ) ); + expa = sub( 30, add( expa, Qx ) ); - expb = norm_l(sort_avg); - fracb = extract_h(L_shl(sort_avg,expb)); - expb = sub(30,add(expb, Qx)); + expb = norm_l( sort_avg ); + fracb = extract_h( L_shl( sort_avg, expb ) ); + expb = sub( 30, add( expb, Qx ) ); - scale = shr(sub(fracb,fraca),15); - fraca = shl(fraca,scale); - expa = sub(expa,scale); + scale = shr( sub( fracb, fraca ), 15 ); + fraca = shl( fraca, scale ); + expa = sub( expa, scale ); - tmp = div_s(fraca,fracb); - exp3 = sub(expa,expb); + tmp = div_s( fraca, fracb ); + exp3 = sub( expa, expb ); #ifdef BASOP_NOGLOB - tonality3 = L_shl_o(tmp , exp3, &Overflow); + tonality3 = L_shl_o( tmp, exp3, &Overflow ); #else - tonality3 = L_shl(tmp , exp3); + tonality3 = L_shl( tmp, exp3 ); #endif } ELSE { - tonality3 = L_shl(sort_max,sub(15,Qx)); /*Q15 */ + tonality3 = L_shl( sort_max, sub( 15, Qx ) ); /*Q15 */ } - tonality = L_max(L_max(tonality1, tonality2), tonality3); + tonality = L_max( L_max( tonality1, tonality2 ), tonality3 ); /* voi_mean = 0.33f * (st->voicing_fx[0] + voicing[1] + voicing[2]); */ - L_tmp = L_mult(st_fx->voicing_fx[0], 10923); - L_tmp = L_mac(L_tmp, st_fx->voicing_fx[1], 10923); + L_tmp = L_mult( st_fx->voicing_fx[0], 10923 ); + L_tmp = L_mac( L_tmp, st_fx->voicing_fx[1], 10923 ); #ifdef BASOP_NOGLOB // -dtx 12650 amrwb\Dtx3.INP voi_mean = mac_r_sat( L_tmp, st_fx->voicing_fx[2], 10923 ); /* Q15 */ #else - voi_mean = mac_r(L_tmp, st_fx->voicing_fx[2], 10923); /* Q15 */ + voi_mean = mac_r( L_tmp, st_fx->voicing_fx[2], 10923 ); /* Q15 */ #endif test(); - IF( EQ_16(hVAD->hangover_cnt,10) && EQ_16(st_fx->vad_flag,1)) + IF( EQ_16( hVAD->hangover_cnt, 10 ) && EQ_16( st_fx->vad_flag, 1 ) ) { /* long-term voicing parameter */ - hSpMusClas->lt_voicing = round_fx(L_mac(L_mult(3277,hSpMusClas->lt_voicing),29491, voi_mean)); + hSpMusClas->lt_voicing = round_fx( L_mac( L_mult( 3277, hSpMusClas->lt_voicing ), 29491, voi_mean ) ); /* long-term correlation value */ - hSpMusClas->lt_corr = round_fx(L_mac(L_mult(3277,hSpMusClas->lt_corr),29491, st_fx->old_corr_fx)); + hSpMusClas->lt_corr = round_fx( L_mac( L_mult( 3277, hSpMusClas->lt_corr ), 29491, st_fx->old_corr_fx ) ); /* long-term tonality measure */ - hSpMusClas->lt_tonality = L_add(Mult_32_16(hSpMusClas->lt_tonality,3277),Mult_32_16(tonality,29491)); + hSpMusClas->lt_tonality = L_add( Mult_32_16( hSpMusClas->lt_tonality, 3277 ), Mult_32_16( tonality, 29491 ) ); } ELSE { /* long-term voicing parameter */ - hSpMusClas->lt_voicing = round_fx(L_mac(L_mult(22938,hSpMusClas->lt_voicing),9830, voi_mean)); + hSpMusClas->lt_voicing = round_fx( L_mac( L_mult( 22938, hSpMusClas->lt_voicing ), 9830, voi_mean ) ); /* long-term correlation value */ - hSpMusClas->lt_corr = round_fx(L_mac(L_mult(22938,hSpMusClas->lt_corr),9830, st_fx->old_corr_fx)); + hSpMusClas->lt_corr = round_fx( L_mac( L_mult( 22938, hSpMusClas->lt_corr ), 9830, st_fx->old_corr_fx ) ); /* long-term tonality measure */ - hSpMusClas->lt_tonality = L_add(Mult_32_16(hSpMusClas->lt_tonality,16384),Mult_32_16(tonality,16384)); + hSpMusClas->lt_tonality = L_add( Mult_32_16( hSpMusClas->lt_tonality, 16384 ), Mult_32_16( tonality, 16384 ) ); } /* Pitch difference w.r.t to past 3 frames */ - lt_pitch_diff = abs_s(sub(hSpMusClas->lt_corr_pitch[0], st_fx->pitch_fx[0])); - lt_pitch_diff = add(lt_pitch_diff , abs_s(sub(hSpMusClas->lt_corr_pitch[1], st_fx->pitch_fx[0]))); - lt_pitch_diff = add(lt_pitch_diff,abs_s(sub(hSpMusClas->lt_corr_pitch[2], st_fx->pitch_fx[0]))); + lt_pitch_diff = abs_s( sub( hSpMusClas->lt_corr_pitch[0], st_fx->pitch_fx[0] ) ); + lt_pitch_diff = add( lt_pitch_diff, abs_s( sub( hSpMusClas->lt_corr_pitch[1], st_fx->pitch_fx[0] ) ) ); + lt_pitch_diff = add( lt_pitch_diff, abs_s( sub( hSpMusClas->lt_corr_pitch[2], st_fx->pitch_fx[0] ) ) ); hSpMusClas->lt_corr_pitch[0] = hSpMusClas->lt_corr_pitch[1]; move16(); @@ -3510,17 +3513,29 @@ static void tonal_context_improv_fx( hSpMusClas->lt_old_mode[1] = hSpMusClas->lt_old_mode[2]; move16(); - test();test();test();test();test();test();test();test();test();test();test();test();test(); - IF (st_fx->sp_aud_decision1 == 1 && - ( GT_32(L_min(L_min(tonality1, tonality2), tonality3),1638400) ) && - ( GT_32(L_add(tonality1, tonality2),6553600) && GT_32(L_add(tonality2, tonality3),6553600) && GT_32(L_add(tonality1, tonality3),6553600)) && - ( LT_32(hSpMusClas->lt_tonality,655360000) ) && - ( ( GT_32(hSpMusClas->lt_tonality,32768000) && GT_16(s_max(hSpMusClas->lt_voicing, voi_mean),32440) ) || - ( GT_32(hSpMusClas->lt_tonality,49152000) && GT_16(hSpMusClas->lt_corr,32440) ) || - ( GT_32(hSpMusClas->lt_tonality,98304000) && GT_16(hSpMusClas->lowrate_pitchGain,15729) ) || - ( lt_pitch_diff == 0 && GT_16(hSpMusClas->lowrate_pitchGain,14582)))) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( st_fx->sp_aud_decision1 == 1 && + ( GT_32( L_min( L_min( tonality1, tonality2 ), tonality3 ), 1638400 ) ) && + ( GT_32( L_add( tonality1, tonality2 ), 6553600 ) && GT_32( L_add( tonality2, tonality3 ), 6553600 ) && GT_32( L_add( tonality1, tonality3 ), 6553600 ) ) && + ( LT_32( hSpMusClas->lt_tonality, 655360000 ) ) && + ( ( GT_32( hSpMusClas->lt_tonality, 32768000 ) && GT_16( s_max( hSpMusClas->lt_voicing, voi_mean ), 32440 ) ) || + ( GT_32( hSpMusClas->lt_tonality, 49152000 ) && GT_16( hSpMusClas->lt_corr, 32440 ) ) || + ( GT_32( hSpMusClas->lt_tonality, 98304000 ) && GT_16( hSpMusClas->lowrate_pitchGain, 15729 ) ) || + ( lt_pitch_diff == 0 && GT_16( hSpMusClas->lowrate_pitchGain, 14582 ) ) ) ) { - IF( LT_16(sum16_fx(hSpMusClas->lt_old_mode, 2),2)) + IF( LT_16( sum16_fx( hSpMusClas->lt_old_mode, 2 ), 2 ) ) { /* probably speech - change the decision to speech */ st_fx->sp_aud_decision1 = 0; @@ -3528,7 +3543,7 @@ static void tonal_context_improv_fx( st_fx->sp_aud_decision2 = 0; move16(); - if( hSpMusClas->lt_hangover == 0 ) + if ( hSpMusClas->lt_hangover == 0 ) { hSpMusClas->lt_hangover = 6; move16(); @@ -3545,59 +3560,70 @@ static void tonal_context_improv_fx( st_fx->sp_aud_decision2 = 0; move16(); - hSpMusClas->lt_hangover = sub(hSpMusClas->lt_hangover,1); + hSpMusClas->lt_hangover = sub( hSpMusClas->lt_hangover, 1 ); } } /* calculate standard deviation of log-tonality */ Copy( hSpMusClas->tonality2_buf_fx + 1, hSpMusClas->tonality2_buf_fx, HANG_LEN_INIT - 1 ); /* st->tonality2_buf[HANG_LEN_INIT - 1] = 0.2f*(float)log10(tonality2); */ - exp = norm_l(tonality2); - tmp = Log2_norm_lc(L_shl(tonality2, exp));/*15 */ - exp = sub(30, add(exp, 16)); - L_tmp = Mpy_32_16(exp, tmp, 15783);/*19 //3945, 0.2*log10(2), Q18 */ - hSpMusClas->tonality2_buf_fx[HANG_LEN_INIT - 1] = round_fx(L_shl(L_tmp, 11));/*14 */ + exp = norm_l( tonality2 ); + tmp = Log2_norm_lc( L_shl( tonality2, exp ) ); /*15 */ + exp = sub( 30, add( exp, 16 ) ); + L_tmp = Mpy_32_16( exp, tmp, 15783 ); /*19 //3945, 0.2*log10(2), Q18 */ + hSpMusClas->tonality2_buf_fx[HANG_LEN_INIT - 1] = round_fx( L_shl( L_tmp, 11 ) ); /*14 */ /* t2 = std( st->tonality2_buf, HANG_LEN_INIT ); */ - t2_fx = std_fx( hSpMusClas->tonality2_buf_fx, HANG_LEN_INIT ); /*14 */ + t2_fx = std_fx( hSpMusClas->tonality2_buf_fx, HANG_LEN_INIT ); /*14 */ Copy( hSpMusClas->tonality3_buf_fx + 1, hSpMusClas->tonality3_buf_fx, HANG_LEN_INIT - 1 ); /* st->tonality3_buf[HANG_LEN_INIT - 1] = 0.2f*(float)log10(tonality3); */ - exp = norm_l(tonality3); - tmp = Log2_norm_lc(L_shl(tonality3, exp));/*15 */ - exp = sub(30, add(exp, 16)); - L_tmp = Mpy_32_16(exp, tmp, 15783);/*19 //3945, 0.2*log10(2), Q18 */ - hSpMusClas->tonality3_buf_fx[HANG_LEN_INIT - 1] = round_fx(L_shl(L_tmp, 11));/*14 */ - t3_fx = std_fx( hSpMusClas->tonality3_buf_fx, HANG_LEN_INIT ); /*14 */ + exp = norm_l( tonality3 ); + tmp = Log2_norm_lc( L_shl( tonality3, exp ) ); /*15 */ + exp = sub( 30, add( exp, 16 ) ); + L_tmp = Mpy_32_16( exp, tmp, 15783 ); /*19 //3945, 0.2*log10(2), Q18 */ + hSpMusClas->tonality3_buf_fx[HANG_LEN_INIT - 1] = round_fx( L_shl( L_tmp, 11 ) ); /*14 */ + t3_fx = std_fx( hSpMusClas->tonality3_buf_fx, HANG_LEN_INIT ); /*14 */ /* tL = 0.2f*(float)log10(st->lt_tonality); */ - exp = norm_l(hSpMusClas->lt_tonality); - tmp = Log2_norm_lc(L_shl(hSpMusClas->lt_tonality, exp));/*15 */ - exp = sub(30, add(exp, 16)); - L_tmp = Mpy_32_16(exp, tmp, 15783);/*19 //3945, 0.2*log10(2), Q18 */ - tL_fx = round_fx(L_shl(L_tmp, 11));/*14 */ + exp = norm_l( hSpMusClas->lt_tonality ); + tmp = Log2_norm_lc( L_shl( hSpMusClas->lt_tonality, exp ) ); /*15 */ + exp = sub( 30, add( exp, 16 ) ); + L_tmp = Mpy_32_16( exp, tmp, 15783 ); /*19 //3945, 0.2*log10(2), Q18 */ + tL_fx = round_fx( L_shl( L_tmp, 11 ) ); /*14 */ /* calculate standard deviation of residual LP energy */ Copy( hSpMusClas->LPCErr_buf_fx + 1, hSpMusClas->LPCErr_buf_fx, HANG_LEN_INIT - 1 ); hSpMusClas->LPCErr_buf_fx[HANG_LEN_INIT - 1] = LPCErr; /* err = std( st->LPCErr_buf, HANG_LEN_INIT ); */ - err_fx = std_fx( hSpMusClas->LPCErr_buf_fx, HANG_LEN_INIT ); + err_fx = std_fx( hSpMusClas->LPCErr_buf_fx, HANG_LEN_INIT ); - cor_fx = s_max(sub(voi_fv, cor_map_sum_fv), 0);/*15 */ - dft_fx = abs_s(sub(hSpMusClas->tonality2_buf_fx[HANG_LEN_INIT - 1], hSpMusClas->tonality3_buf_fx[HANG_LEN_INIT - 1]));/*14 */ + cor_fx = s_max( sub( voi_fv, cor_map_sum_fv ), 0 ); /*15 */ + dft_fx = abs_s( sub( hSpMusClas->tonality2_buf_fx[HANG_LEN_INIT - 1], hSpMusClas->tonality3_buf_fx[HANG_LEN_INIT - 1] ) ); /*14 */ /* state machine for strong music */ - test();test();test();test();test();test();test();test();test();test();test();test(); - IF ( (EQ_16(st_fx->sp_aud_decision1, 1)) && hSpMusClas->lt_music_state==0 && hSpMusClas->lt_music_hangover==0 && - (LT_16(t2_fx, 8847)) && (GT_16(t2_fx, 4260)) && (GT_16(t3_fx, 3604)) && (LT_16(tL_fx, 8847)) && (GT_16(tL_fx, 4260)) && (GT_16(err_fx, 8192)) ) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( EQ_16( st_fx->sp_aud_decision1, 1 ) ) && hSpMusClas->lt_music_state == 0 && hSpMusClas->lt_music_hangover == 0 && + ( LT_16( t2_fx, 8847 ) ) && ( GT_16( t2_fx, 4260 ) ) && ( GT_16( t3_fx, 3604 ) ) && ( LT_16( tL_fx, 8847 ) ) && ( GT_16( tL_fx, 4260 ) ) && ( GT_16( err_fx, 8192 ) ) ) { hSpMusClas->lt_music_state = 1; move16(); hSpMusClas->lt_music_hangover = 6; move16(); } - ELSE IF( EQ_16(hSpMusClas->lt_music_state, 1) && hSpMusClas->lt_music_hangover==0 && - (LT_16(t2_fx, 5571) ) && (LT_16(t3_fx, 4260) ) && (LT_16(tL_fx, 7373) ) ) + ELSE IF( EQ_16( hSpMusClas->lt_music_state, 1 ) && hSpMusClas->lt_music_hangover == 0 && + ( LT_16( t2_fx, 5571 ) ) && ( LT_16( t3_fx, 4260 ) ) && ( LT_16( tL_fx, 7373 ) ) ) { hSpMusClas->lt_music_state = 0; move16(); @@ -3605,24 +3631,36 @@ static void tonal_context_improv_fx( move16(); } - IF ( hSpMusClas->lt_music_hangover > 0 ) + IF( hSpMusClas->lt_music_hangover > 0 ) { - hSpMusClas->lt_music_hangover = sub(hSpMusClas->lt_music_hangover,1); + hSpMusClas->lt_music_hangover = sub( hSpMusClas->lt_music_hangover, 1 ); } /* state machine for strong speech */ - test();test();test();test();test();test();test();test();test();test();test();test();test(); - IF ( (EQ_16(st_fx->sp_aud_decision1, 1)) && hSpMusClas->lt_speech_state==0 && hSpMusClas->lt_speech_hangover==0 && - (GT_16(cor_fx, 13107)) && (LT_16(dft_fx, 1638)) && GT_16(shr(voi_fv,1), add(cor_map_sum_fv, 1966)) && - (LT_16(t2_fx, shr(cor_fx, 1))) && (LT_16(t3_fx, shr(cor_fx, 1))) && (LT_16(tL_fx, shr(cor_fx, 1))) && - (LT_16(cor_map_sum_fv, cor_fx)) && (GT_16(voi_fv, cor_fx)) && (GT_16(voi_fv, 24903) ) ) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( EQ_16( st_fx->sp_aud_decision1, 1 ) ) && hSpMusClas->lt_speech_state == 0 && hSpMusClas->lt_speech_hangover == 0 && + ( GT_16( cor_fx, 13107 ) ) && ( LT_16( dft_fx, 1638 ) ) && GT_16( shr( voi_fv, 1 ), add( cor_map_sum_fv, 1966 ) ) && + ( LT_16( t2_fx, shr( cor_fx, 1 ) ) ) && ( LT_16( t3_fx, shr( cor_fx, 1 ) ) ) && ( LT_16( tL_fx, shr( cor_fx, 1 ) ) ) && + ( LT_16( cor_map_sum_fv, cor_fx ) ) && ( GT_16( voi_fv, cor_fx ) ) && ( GT_16( voi_fv, 24903 ) ) ) { hSpMusClas->lt_speech_state = 1; move16(); hSpMusClas->lt_speech_hangover = 6; move16(); } - ELSE IF ( (EQ_16(hSpMusClas->lt_speech_state, 1)) && hSpMusClas->lt_speech_hangover==0 &&(LT_16(cor_fx,13107))) + ELSE IF( ( EQ_16( hSpMusClas->lt_speech_state, 1 ) ) && hSpMusClas->lt_speech_hangover == 0 && ( LT_16( cor_fx, 13107 ) ) ) { hSpMusClas->lt_speech_state = 0; move16(); @@ -3630,15 +3668,15 @@ static void tonal_context_improv_fx( move16(); } - IF ( hSpMusClas->lt_speech_hangover > 0) + IF( hSpMusClas->lt_speech_hangover > 0 ) { - hSpMusClas->lt_speech_hangover = sub(hSpMusClas->lt_speech_hangover,1); + hSpMusClas->lt_speech_hangover = sub( hSpMusClas->lt_speech_hangover, 1 ); } /* final decision */ test(); test(); - IF ( EQ_16(st_fx->sp_aud_decision1,1) && EQ_16(hSpMusClas->lt_speech_state,1)) + IF( EQ_16( st_fx->sp_aud_decision1, 1 ) && EQ_16( hSpMusClas->lt_speech_state, 1 ) ) { /* strong speech - probably error in speech/music classification */ st_fx->sp_aud_decision1 = 0; @@ -3646,7 +3684,7 @@ static void tonal_context_improv_fx( st_fx->sp_aud_decision2 = 0; move16(); } - ELSE IF (st_fx->sp_aud_decision1 == 0 && EQ_16(hSpMusClas->lt_speech_state,1)) + ELSE IF( st_fx->sp_aud_decision1 == 0 && EQ_16( hSpMusClas->lt_speech_state, 1 ) ) { /* strong music - probably error in speech/music classification */ st_fx->sp_aud_decision1 = 0; @@ -3665,66 +3703,66 @@ static void tonal_context_improv_fx( /*----------------------------------------------------------------------------------* * detect_sparseness_fx() * - * + * *----------------------------------------------------------------------------------*/ static void detect_sparseness_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 localVAD_HE_SAD, /* i : HE-SAD flag without hangover */ - const Word16 voi_fv /* i : scaled voicing feature */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word16 localVAD_HE_SAD, /* i : HE-SAD flag without hangover */ + const Word16 voi_fv /* i : scaled voicing feature */ ) { Word16 sum, sumh; - Word32 L_tmp,L_tmp1; + Word32 L_tmp, L_tmp1; Word16 tmp, tmp1; Word16 S1[128]; - Word16 i,j; + Word16 i, j; Word16 hb_sp_high_flag = 0; Word16 lb_sp_high_flag = 0; Word16 sparse; Word16 tmp_buf[4]; - Word16 Mlpe=0, Mv=0, Msp; + Word16 Mlpe = 0, Mv = 0, Msp; SP_MUS_CLAS_HANDLE hSpMusClas = st_fx->hSpMusClas; - Copy(st_fx->lgBin_E_fx, S1, 128); + Copy( st_fx->lgBin_E_fx, S1, 128 ); - L_tmp = L_deposit_l(0); - FOR (i = 0; i < 80; i++) + L_tmp = L_deposit_l( 0 ); + FOR( i = 0; i < 80; i++ ) { - if (S1[i] < 0) + if ( S1[i] < 0 ) { S1[i] = 0; move16(); /* Q7 */ } - L_tmp = L_add(L_tmp, L_deposit_l(S1[i])); + L_tmp = L_add( L_tmp, L_deposit_l( S1[i] ) ); } - L_tmp1 = L_deposit_l(0); - FOR (i = 80; i < 128; i++) + L_tmp1 = L_deposit_l( 0 ); + FOR( i = 80; i < 128; i++ ) { - if (S1[i] < 0) + if ( S1[i] < 0 ) { S1[i] = 0; move16(); } - L_tmp1 = L_add(L_tmp1, L_deposit_l(S1[i])); + L_tmp1 = L_add( L_tmp1, L_deposit_l( S1[i] ) ); } - sumh = extract_l(L_shr(L_tmp1, 7)); /* Q0 */ - sum = add(extract_l(L_shr(L_tmp, 7)), sumh); /* Q0 */ + sumh = extract_l( L_shr( L_tmp1, 7 ) ); /* Q0 */ + sum = add( extract_l( L_shr( L_tmp, 7 ) ), sumh ); /* Q0 */ /* order spectral from max to min */ - order_spectrum_fx(S1, 128); + order_spectrum_fx( S1, 128 ); /* calculate spectral sparseness in the range 0 - 6.4 kHz */ j = 0; move16(); L_tmp = 0; move16(); - L_tmp1 = L_deposit_l(mult(sum, 24576)); - FOR (i = 0; i < 128; i++) + L_tmp1 = L_deposit_l( mult( sum, 24576 ) ); + FOR( i = 0; i < 128; i++ ) { - L_tmp = L_add(L_tmp, L_deposit_l(S1[i])); - IF (GT_32(L_shr(L_tmp, 7), L_tmp1)) + L_tmp = L_add( L_tmp, L_deposit_l( S1[i] ) ); + IF( GT_32( L_shr( L_tmp, 7 ), L_tmp1 ) ) { j = i; move16(); @@ -3732,9 +3770,9 @@ static void detect_sparseness_fx( } } - FOR (i = 0; i < HANG_LEN_INIT-1; i++) + FOR( i = 0; i < HANG_LEN_INIT - 1; i++ ) { - hSpMusClas->sparse_buf_fx[i] = hSpMusClas->sparse_buf_fx[i+1]; + hSpMusClas->sparse_buf_fx[i] = hSpMusClas->sparse_buf_fx[i + 1]; move16(); } @@ -3743,34 +3781,34 @@ static void detect_sparseness_fx( hSpMusClas->sparse_buf_fx[i] = sparse; move16(); - IF (EQ_16(st_fx->bwidth, WB)) + IF( EQ_16( st_fx->bwidth, WB ) ) { Msp = 0; move16(); - FOR (i = 0; i < 8; i++) + FOR( i = 0; i < 8; i++ ) { - Msp = add(Msp, hSpMusClas->sparse_buf_fx[i]); + Msp = add( Msp, hSpMusClas->sparse_buf_fx[i] ); } - Msp = shl(Msp, 5); /* Q8 */ + Msp = shl( Msp, 5 ); /* Q8 */ /* find long-term smoothed sparseness */ - IF (st_fx->last_vad_spa_fx == 0 ) + IF( st_fx->last_vad_spa_fx == 0 ) { - set16_fx( &hSpMusClas->sparse_buf_fx[0], sparse, HANG_LEN_INIT-1 ); + set16_fx( &hSpMusClas->sparse_buf_fx[0], sparse, HANG_LEN_INIT - 1 ); hSpMusClas->LT_sparse_fx = sparse; move16(); } ELSE { - set16_fx(tmp_buf, 0, 4); + set16_fx( tmp_buf, 0, 4 ); - FOR (i = 0; i < HANG_LEN_INIT; i++) + FOR( i = 0; i < HANG_LEN_INIT; i++ ) { - FOR (j = 0; j < 4; j++) + FOR( j = 0; j < 4; j++ ) { - IF (GT_16(hSpMusClas->sparse_buf_fx[i], tmp_buf[j])) + IF( GT_16( hSpMusClas->sparse_buf_fx[i], tmp_buf[j] ) ) { - Copy(&tmp_buf[j], &tmp_buf[j+1], sub(3, j)); + Copy( &tmp_buf[j], &tmp_buf[j + 1], sub( 3, j ) ); tmp_buf[j] = hSpMusClas->sparse_buf_fx[i]; move16(); BREAK; @@ -3779,94 +3817,94 @@ static void detect_sparseness_fx( } /* ftmp = 0.25f*(HANG_LEN_INIT*Msp - sum_f(tmp_buf, 4)) - st->LT_sparse; */ - tmp = shl(sum16_fx(tmp_buf, 4), 5); - tmp = shl(sub(Msp, tmp), 1); - tmp = sub(tmp, hSpMusClas->LT_sparse_fx); + tmp = shl( sum16_fx( tmp_buf, 4 ), 5 ); + tmp = shl( sub( Msp, tmp ), 1 ); + tmp = sub( tmp, hSpMusClas->LT_sparse_fx ); - hSpMusClas->LT_sparse_fx = add(hSpMusClas->LT_sparse_fx, shr(tmp, 2)); /* Q8 */ + hSpMusClas->LT_sparse_fx = add( hSpMusClas->LT_sparse_fx, shr( tmp, 2 ) ); /* Q8 */ } /* find high-band sparseness */ - Copy(st_fx->lgBin_E_fx+80, S1, 48); + Copy( st_fx->lgBin_E_fx + 80, S1, 48 ); - order_spectrum_fx(S1, 48); + order_spectrum_fx( S1, 48 ); - FOR (i = 0; i < HANG_LEN_INIT-1; i++) + FOR( i = 0; i < HANG_LEN_INIT - 1; i++ ) { - hSpMusClas->hf_spar_buf_fx[i] = hSpMusClas->hf_spar_buf_fx[i+1]; + hSpMusClas->hf_spar_buf_fx[i] = hSpMusClas->hf_spar_buf_fx[i + 1]; move16(); } /* st_fx->hf_spar_buf_fx[i] = sum_f(S1, 5)/sumh; */ - L_tmp = L_deposit_l(0); - FOR (i = 0; i < 5; i++) + L_tmp = L_deposit_l( 0 ); + FOR( i = 0; i < 5; i++ ) { - if (S1[i] < 0) + if ( S1[i] < 0 ) { S1[i] = 0; move16(); } - L_tmp = L_add(L_tmp, S1[i]); + L_tmp = L_add( L_tmp, S1[i] ); } - tmp = extract_l(L_shr(L_tmp, 7)); - IF (tmp == 0) + tmp = extract_l( L_shr( L_tmp, 7 ) ); + IF( tmp == 0 ) { - hSpMusClas->hf_spar_buf_fx[HANG_LEN_INIT-1] = 0; + hSpMusClas->hf_spar_buf_fx[HANG_LEN_INIT - 1] = 0; move16(); } ELSE { - hSpMusClas->hf_spar_buf_fx[HANG_LEN_INIT-1] = div_s(tmp, sumh); + hSpMusClas->hf_spar_buf_fx[HANG_LEN_INIT - 1] = div_s( tmp, sumh ); } tmp = 0; move16(); - FOR (i = 0; i < 8; i++) + FOR( i = 0; i < 8; i++ ) { - tmp = add(tmp, shr(hSpMusClas->hf_spar_buf_fx[i], 3)); + tmp = add( tmp, shr( hSpMusClas->hf_spar_buf_fx[i], 3 ) ); } - IF (GT_16(tmp, 6554)) + IF( GT_16( tmp, 6554 ) ) { hb_sp_high_flag = 1; move16(); } /* find low-band sparseness */ - Copy(st_fx->lgBin_E_fx, S1, 60); + Copy( st_fx->lgBin_E_fx, S1, 60 ); - order_spectrum_fx(S1, 60); - L_tmp = L_deposit_l(0); - L_tmp1 = L_deposit_l(0); - FOR (i = 0; i < 5; i++) + order_spectrum_fx( S1, 60 ); + L_tmp = L_deposit_l( 0 ); + L_tmp1 = L_deposit_l( 0 ); + FOR( i = 0; i < 5; i++ ) { - if (S1[i] < 0) + if ( S1[i] < 0 ) { S1[i] = 0; move16(); } - L_tmp = L_add(L_tmp, S1[i]); + L_tmp = L_add( L_tmp, S1[i] ); } - FOR (; i < 60; i++) + FOR( ; i < 60; i++ ) { - if (S1[i] < 0) + if ( S1[i] < 0 ) { S1[i] = 0; move16(); } - L_tmp1 = L_add(L_tmp1, S1[i]); + L_tmp1 = L_add( L_tmp1, S1[i] ); } /* if ( sum_f(S1, 5)/sum_f(S1,60) > 0.18f ) */ - tmp = extract_l(L_shr(L_tmp, 7)); - IF (tmp != 0) + tmp = extract_l( L_shr( L_tmp, 7 ) ); + IF( tmp != 0 ) { - tmp = div_s(tmp, add(tmp, extract_l(L_shr(L_tmp1, 7)))); - if (GT_16(tmp, 5898)) + tmp = div_s( tmp, add( tmp, extract_l( L_shr( L_tmp1, 7 ) ) ) ); + if ( GT_16( tmp, 5898 ) ) { lb_sp_high_flag = 1; move16(); @@ -3874,9 +3912,9 @@ static void detect_sparseness_fx( } /* find smoothed linear prediction efficiency */ - FOR (i = 0; i < 7; i++) + FOR( i = 0; i < 7; i++ ) { - hSpMusClas->lpe_buf_fx[i] = hSpMusClas->lpe_buf_fx[i+1]; + hSpMusClas->lpe_buf_fx[i] = hSpMusClas->lpe_buf_fx[i + 1]; move16(); } @@ -3884,15 +3922,15 @@ static void detect_sparseness_fx( move16(); Mlpe = 0; move16(); - FOR (i = 0; i < 8; i++) + FOR( i = 0; i < 8; i++ ) { - Mlpe = add(Mlpe, shr(hSpMusClas->lpe_buf_fx[i], 3)); + Mlpe = add( Mlpe, shr( hSpMusClas->lpe_buf_fx[i], 3 ) ); } /* find smoothed voicing */ - FOR (i = 0; i < HANG_LEN_INIT-1; i++) + FOR( i = 0; i < HANG_LEN_INIT - 1; i++ ) { - hSpMusClas->voicing_buf_fx[i] = hSpMusClas->voicing_buf_fx[i+1]; + hSpMusClas->voicing_buf_fx[i] = hSpMusClas->voicing_buf_fx[i + 1]; move16(); } @@ -3900,23 +3938,23 @@ static void detect_sparseness_fx( move16(); Mv = 0; move16(); - FOR (i = 0; i < 8; i++) + FOR( i = 0; i < 8; i++ ) { - Mv = add(Mv, shr(hSpMusClas->voicing_buf_fx[i], 3)); + Mv = add( Mv, shr( hSpMusClas->voicing_buf_fx[i], 3 ) ); } } /* avoid using LR-MDCT on sparse spectra */ - IF (EQ_16(st_fx->sp_aud_decision1, 1)) + IF( EQ_16( st_fx->sp_aud_decision1, 1 ) ) { tmp = 91; move16(); - if (EQ_16(st_fx->bwidth, WB)) + if ( EQ_16( st_fx->bwidth, WB ) ) { tmp = 90; } - IF (GT_16(sparse, tmp)) + IF( GT_16( sparse, tmp ) ) { st_fx->sp_aud_decision1 = 0; move16(); @@ -3925,9 +3963,9 @@ static void detect_sparseness_fx( hSpMusClas->gsc_hangover = 1; move16(); } - ELSE IF (EQ_16(hSpMusClas->gsc_hangover, 1)) + ELSE IF( EQ_16( hSpMusClas->gsc_hangover, 1 ) ) { - IF (GT_16(sparse, 85)) + IF( GT_16( sparse, 85 ) ) { st_fx->sp_aud_decision1 = 0; move16(); @@ -3938,14 +3976,14 @@ static void detect_sparseness_fx( { tmp = 0; move16(); - FOR (i=0; igsc_cnt; i++) + FOR( i = 0; i < hSpMusClas->gsc_cnt; i++ ) { - tmp = add(tmp, hSpMusClas->sparse_buf_fx[HANG_LEN_INIT-1-hSpMusClas->gsc_cnt+i]); + tmp = add( tmp, hSpMusClas->sparse_buf_fx[HANG_LEN_INIT - 1 - hSpMusClas->gsc_cnt + i] ); } - tmp1 = div_s(1, hSpMusClas->gsc_cnt); - tmp = mult(tmp, tmp1); + tmp1 = div_s( 1, hSpMusClas->gsc_cnt ); + tmp = mult( tmp, tmp1 ); - IF (LT_16(abs_s(sub(sparse, tmp)), 7)) + IF( LT_16( abs_s( sub( sparse, tmp ) ), 7 ) ) { st_fx->sp_aud_decision1 = 0; move16(); @@ -3955,11 +3993,19 @@ static void detect_sparseness_fx( } } - IF (EQ_16(st_fx->bwidth, WB)) + IF( EQ_16( st_fx->bwidth, WB ) ) { - test();test();test();test();test();test();test();test();test(); - IF (GT_16(hSpMusClas->LT_sparse_fx, 15360) && GT_16(sparse,50) && LT_16(Mlpe,-1331) && GT_16(Mv,27853) && - lb_sp_high_flag == 0 && ((hb_sp_high_flag == 0 && GT_16(sumh, mult_r(4915, sum))) || LE_16(sumh, mult_r(4915, sum)))) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( GT_16( hSpMusClas->LT_sparse_fx, 15360 ) && GT_16( sparse, 50 ) && LT_16( Mlpe, -1331 ) && GT_16( Mv, 27853 ) && + lb_sp_high_flag == 0 && ( ( hb_sp_high_flag == 0 && GT_16( sumh, mult_r( 4915, sum ) ) ) || LE_16( sumh, mult_r( 4915, sum ) ) ) ) { st_fx->sp_aud_decision1 = 0; move16(); @@ -3968,9 +4014,9 @@ static void detect_sparseness_fx( hSpMusClas->gsc_hangover = 1; move16(); } - ELSE IF (EQ_16(hSpMusClas->gsc_hangover, 1) && !(st_fx->sp_aud_decision1==0 && st_fx->sp_aud_decision2==1)) + ELSE IF( EQ_16( hSpMusClas->gsc_hangover, 1 ) && !( st_fx->sp_aud_decision1 == 0 && st_fx->sp_aud_decision2 == 1 ) ) { - IF (LT_16(abs_s(sub(sparse, mean_fx(&hSpMusClas->sparse_buf_fx[HANG_LEN_INIT-1-hSpMusClas->gsc_cnt], hSpMusClas->gsc_cnt))), 7)) + IF( LT_16( abs_s( sub( sparse, mean_fx( &hSpMusClas->sparse_buf_fx[HANG_LEN_INIT - 1 - hSpMusClas->gsc_cnt], hSpMusClas->gsc_cnt ) ) ), 7 ) ) { st_fx->sp_aud_decision1 = 0; move16(); @@ -3983,10 +4029,10 @@ static void detect_sparseness_fx( /* update the counter of consecutive GSC frames with sparse spectrum */ test(); - IF (st_fx->sp_aud_decision1 == 0 && EQ_16(st_fx->sp_aud_decision2, 1)) + IF( st_fx->sp_aud_decision1 == 0 && EQ_16( st_fx->sp_aud_decision2, 1 ) ) { - hSpMusClas->gsc_cnt = add(hSpMusClas->gsc_cnt, 1); - IF (GT_16(hSpMusClas->gsc_cnt, 7)) + hSpMusClas->gsc_cnt = add( hSpMusClas->gsc_cnt, 1 ); + IF( GT_16( hSpMusClas->gsc_cnt, 7 ) ) { hSpMusClas->gsc_cnt = 7; move16(); @@ -4013,15 +4059,14 @@ static void detect_sparseness_fx( *---------------------------------------------------------------------*/ static void order_spectrum_fx( Word16 *vec, - Word16 len -) + Word16 len ) { Word16 i, j, end, end_1, len_2, tmp; Word16 smax, smin; Word16 imax, imin; - len_2 = shr(len, 1); - FOR(i = 0; i < len_2; i++) + len_2 = shr( len, 1 ); + FOR( i = 0; i < len_2; i++ ) { imax = i; move16(); @@ -4031,10 +4076,10 @@ static void order_spectrum_fx( move16(); smin = vec[i]; move16(); - end = sub(len, i); - FOR(j = i; j < end; j++) + end = sub( len, i ); + FOR( j = i; j < end; j++ ) { - IF(GT_16(vec[j], smax)) + IF( GT_16( vec[j], smax ) ) { smax = vec[j]; move16(); @@ -4043,7 +4088,7 @@ static void order_spectrum_fx( } ELSE { - IF(LT_16(vec[j], smin) ) + IF( LT_16( vec[j], smin ) ) { smin = vec[j]; move16(); @@ -4060,13 +4105,13 @@ static void order_spectrum_fx( vec[imax] = tmp; move16(); - IF(EQ_16(imin, i)) + IF( EQ_16( imin, i ) ) { imin = imax; move16(); } - end_1 = sub(end, 1); + end_1 = sub( end, 1 ); tmp = vec[end_1]; move16(); vec[end_1] = smin; @@ -4075,4 +4120,3 @@ static void order_spectrum_fx( move16(); } } - diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index b53a256e1..6ab6aae6c 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -56,27 +56,27 @@ typedef struct int16_t nb_bits; /* number of bits used for the quantization of the indice */ } Indice, *INDICE_HANDLE; -typedef struct +typedef struct { - Word32 r; - Word32 i; + Word32 r; + Word32 i; } complex_32; typedef struct { - Word16 r; - Word16 i; + Word16 r; + Word16 i; } complex_16; typedef struct { - Word16 s16Exp; - Word32 s32Mantissa; + Word16 s16Exp; + Word32 s32Mantissa; } T_VAD_EXP; typedef struct { - Word32 low, high; - Word16 value; + Word32 low, high; + Word16 value; } TastatEnc; /*----------------------------------------------------------------------------------* * Bitstream structure @@ -90,11 +90,11 @@ typedef struct bitstream_enc_data_structure int16_t *ivas_max_num_indices; /* maximum total number of indices in the list */ Indice **ivas_ind_list_zero; /* beginning of the buffer of indices */ void *st_ivas; /* IVAS encoder structure */ - - Word16 nb_bits_tot_fx; /* total number of bits already written */ - Indice* ind_list_fx; /* list of indices */ - Word16 next_ind_fx; /* pointer to the next empty slot in the list of indices */ - Word16 last_ind_fx; /* last written indice */ + + Word16 nb_bits_tot_fx; /* total number of bits already written */ + Indice *ind_list_fx; /* list of indices */ + Word16 next_ind_fx; /* pointer to the next empty slot in the list of indices */ + Word16 last_ind_fx; /* last written indice */ } BSTR_ENC_DATA, *BSTR_ENC_HANDLE; @@ -115,14 +115,14 @@ typedef struct signal_buffers_enc_data_structure float buf_synth_flt[OLD_SYNTH_SIZE_ENC + L_FRAME32k]; /* can be reduced to PIT_MAX_MAX+L_FRAME_MAX if no rate switching */ float buf_speech_enc_flt[L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k]; float buf_wspeech_enc_flt[L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320]; /* increased by 320 to avoid memory overlap in find_wsp() and also to accomodate for the wspeech_enc */ - //Fixed - Word16 input_buff[L_FRAME48k + L_FRAME48k + NS2SA(48000, DELAY_FIR_RESAMPL_NS)]; + // Fixed + Word16 input_buff[L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS )]; - Word32 Bin_E_old_fx[L_FFT / 2]; /* per bin energy of old 2nd frames */ - Word16 mem_decim_fx[2 * L_FILT_MAX]; /* decimation filter memory */ - Word16 mem_decim16k_fx[2 * L_FILT_MAX]; /* ACELP@16kHz - decimation filter memory @16kHz */ - Word16 old_inp_12k8_fx[L_INP_MEM]; /* memory of input signal at 12.8kHz */ - Word16 old_inp_16k_fx[L_INP_MEM]; /* ACELP@16kHz - memory of input signal @16 kHz */ + Word32 Bin_E_old_fx[L_FFT / 2]; /* per bin energy of old 2nd frames */ + Word16 mem_decim_fx[2 * L_FILT_MAX]; /* decimation filter memory */ + Word16 mem_decim16k_fx[2 * L_FILT_MAX]; /* ACELP@16kHz - decimation filter memory @16kHz */ + Word16 old_inp_12k8_fx[L_INP_MEM]; /* memory of input signal at 12.8kHz */ + Word16 old_inp_16k_fx[L_INP_MEM]; /* ACELP@16kHz - memory of input signal @16 kHz */ Word16 buf_speech_enc_pe[L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k]; Word16 buf_synth[OLD_SYNTH_SIZE_ENC + L_FRAME32k]; @@ -139,27 +139,27 @@ typedef struct signal_buffers_enc_data_structure /* Delay buffer: Used to buffer input samples and to define the subblock size of a transient detector. */ typedef struct { - int16_t nSubblockSize; /* Subblock size of a transient detector that uses this delay buffer. */ + int16_t nSubblockSize; /* Subblock size of a transient detector that uses this delay buffer. */ float buffer_flt[L_FRAME_MAX / NSUBBLOCKS]; /* Delay buffer */ Word16 buffer[L_FRAME48k / NSUBBLOCKS]; - int16_t nDelay; /* Size of the delay buffer in use. Maximum delay from all users of this buffer. */ + int16_t nDelay; /* Size of the delay buffer in use. Maximum delay from all users of this buffer. */ } DelayBuffer; /* Subblock energies: Holds subblock energies and recursively accumulated energies. Also buffers the energies. */ typedef struct { - DelayBuffer *pDelayBuffer; /* Delay buffer. */ - float subblockNrg_flt[NSUBBLOCKS + MAX_TD_DELAY]; /* Subblock energies with a delay buffering. */ + DelayBuffer *pDelayBuffer; /* Delay buffer. */ + float subblockNrg_flt[NSUBBLOCKS + MAX_TD_DELAY]; /* Subblock energies with a delay buffering. */ Word32 subblockNrg[NSUBBLOCKS + MAX_TD_DELAY]; float accSubblockNrg_flt[NSUBBLOCKS + MAX_TD_DELAY + 1]; /* Recursively accumulated subblock energies with a delay buffering. At index i the value corresponds to the accumulated subblock energy up to i-1, including block i-1 and without block i. */ Word32 accSubblockNrg[NSUBBLOCKS + MAX_TD_DELAY + 1]; - float subblockNrgChange_flt[NSUBBLOCKS + MAX_TD_DELAY]; /* subblockNrgChange[i] = max(subblockNrg[i]/subblockNrg[i-1], subblockNrg[i-1]/subblockNrg[i]) */ + float subblockNrgChange_flt[NSUBBLOCKS + MAX_TD_DELAY]; /* subblockNrgChange[i] = max(subblockNrg[i]/subblockNrg[i-1], subblockNrg[i-1]/subblockNrg[i]) */ Word16 subblockNrgChange[NSUBBLOCKS + MAX_TD_DELAY]; - int16_t nDelay; /* Size of the delay buffer in use, as number of subblocks. Maximum delay from all users of this buffer. */ - int16_t nPartialDelay; /* Delay of the input (modulo pDelayBuffer->nSubblockSize), nPartialDelay <= pDelayBuffer->nDelay. */ + int16_t nDelay; /* Size of the delay buffer in use, as number of subblocks. Maximum delay from all users of this buffer. */ + int16_t nPartialDelay; /* Delay of the input (modulo pDelayBuffer->nSubblockSize), nPartialDelay <= pDelayBuffer->nDelay. */ /* Decay factor for the recursive accumulation */ float facAccSubblockNrg_flt; @@ -178,21 +178,21 @@ typedef struct /* Attack detection function. */ typedef void ( *TCheckSubblocksForAttack )( const float *pSubblockNrg, const float *pAccSubblockNrg, int16_t nSubblocks, int16_t nPastSubblocks, float attackRatioThreshold, int16_t *pbIsAttackPresent, int16_t *pAttackIndex ); -typedef void(*TCheckSubblocksForAttack_fx)(Word32 const * pSubblockNrg, Word32 const * pAccSubblockNrg, Word16 nSubblocks, Word16 nPastSubblocks, Word16 attackRatioThreshold, Word16 * pbIsAttackPresent, Word16 * pAttackIndex); +typedef void ( *TCheckSubblocksForAttack_fx )( Word32 const *pSubblockNrg, Word32 const *pAccSubblockNrg, Word16 nSubblocks, Word16 nPastSubblocks, Word16 attackRatioThreshold, Word16 *pbIsAttackPresent, Word16 *pAttackIndex ); /* Transient detector. */ typedef struct TransientDetector { - SubblockEnergies *pSubblockEnergies; /* Subblock energies used in this transient detector. */ - int16_t nDelay; /* Delay of the transient detector in number of subblocks, nDelay <= pSubblockEnergies->nDelay. */ - int16_t nSubblocksToCheck; /* Number of subblocks to check for transients. */ - TCheckSubblocksForAttack CheckSubblocksForAttack; /* Function for checking a presence of an attack. */ + SubblockEnergies *pSubblockEnergies; /* Subblock energies used in this transient detector. */ + int16_t nDelay; /* Delay of the transient detector in number of subblocks, nDelay <= pSubblockEnergies->nDelay. */ + int16_t nSubblocksToCheck; /* Number of subblocks to check for transients. */ + TCheckSubblocksForAttack CheckSubblocksForAttack; /* Function for checking a presence of an attack. */ TCheckSubblocksForAttack_fx CheckSubblocksForAttack_fx; /* Function for checking a presence of an attack. */ - float attackRatioThreshold_flt; /* Attack ratio threshold. */ + float attackRatioThreshold_flt; /* Attack ratio threshold. */ Word16 attackRatioThreshold; - int16_t bIsAttackPresent; /* True when an attack was detected. */ - int16_t prev_bIsAttackPresent; /* True if an attack was detected in the previous frame. */ - int16_t attackIndex; /* The index of an attack. */ + int16_t bIsAttackPresent; /* True when an attack was detected. */ + int16_t prev_bIsAttackPresent; /* True if an attack was detected in the previous frame. */ + int16_t attackIndex; /* The index of an attack. */ } TransientDetector; /* Transient detection: Holds all transient detectors and buffers used by them. */ @@ -233,18 +233,18 @@ typedef struct vad_structure int16_t nb_active_frames_he1; int16_t hangover_cnt_he1; - float prim_act_quick; /* Noise estimator - primary activity quick */ - float prim_act_slow; /* Noise estimator - primary activity slow */ - float prim_act; /* Noise estimator - primary activity slow rise quick fall */ - float prim_act_quick_he; /* Noise estimator - primary activity quick */ - float prim_act_slow_he; /* Noise estimator - primary activity slow */ - float prim_act_he; /* Noise estimator - primary activity slow rise quick fall */ - Word16 prim_act_quick_fx; /* Noise estimator - primary activity quick */ - Word16 prim_act_slow_fx; /* Noise estimator - primary activity slow */ - Word16 prim_act_fx; /* Noise estimator - primary activity slow rise quick fall */ - Word16 prim_act_quick_he_fx; /* Noise estimator - primary activity quick */ - Word16 prim_act_slow_he_fx; /* Noise estimator - primary activity slow */ - Word16 prim_act_he_fx; /* Q15 Noise estimator - primary activity slow rise quick fall */ + float prim_act_quick; /* Noise estimator - primary activity quick */ + float prim_act_slow; /* Noise estimator - primary activity slow */ + float prim_act; /* Noise estimator - primary activity slow rise quick fall */ + float prim_act_quick_he; /* Noise estimator - primary activity quick */ + float prim_act_slow_he; /* Noise estimator - primary activity slow */ + float prim_act_he; /* Noise estimator - primary activity slow rise quick fall */ + Word16 prim_act_quick_fx; /* Noise estimator - primary activity quick */ + Word16 prim_act_slow_fx; /* Noise estimator - primary activity slow */ + Word16 prim_act_fx; /* Noise estimator - primary activity slow rise quick fall */ + Word16 prim_act_quick_he_fx; /* Noise estimator - primary activity quick */ + Word16 prim_act_slow_he_fx; /* Noise estimator - primary activity slow */ + Word16 prim_act_he_fx; /* Q15 Noise estimator - primary activity slow rise quick fall */ int16_t spectral_tilt_reset; int16_t consec_inactive; @@ -254,7 +254,7 @@ typedef struct vad_structure float running_avg; float snr_sum_vad; Word16 snr_sum_vad_fx; - Word16 running_avg_fx; /*Q15 */ + Word16 running_avg_fx; /*Q15 */ Word32 L_snr_sum_vad_fx; /*Q4*/ int16_t hangover_terminate_flag; /* CNG and DTX - flag indicating whether to early terminate DTX hangover */ @@ -267,80 +267,80 @@ typedef struct cldfb_vad_structure int16_t bw_index; /* index of band width */ /* feature */ - float sp_center[SP_CENTER_NUM]; /* spectral center*/ - float ltd_stable_rate[STABLE_NUM]; /* time-domain stable rate*/ + float sp_center[SP_CENTER_NUM]; /* spectral center*/ + float ltd_stable_rate[STABLE_NUM]; /* time-domain stable rate*/ + + float sfm[SFM_NUM]; /* spectral flatness*/ - float sfm[SFM_NUM]; /* spectral flatness*/ + float f_tonality_rate[TONA_NUM]; /* tonality rate*/ + float frame_sb_energy[BG_ENG_NUM]; /* energy of sub-band divided non-uniformly*/ + float frames_power[POWER_NUM]; /* energy of several frames*/ - float f_tonality_rate[TONA_NUM]; /* tonality rate*/ - float frame_sb_energy[BG_ENG_NUM]; /* energy of sub-band divided non-uniformly*/ - float frames_power[POWER_NUM]; /* energy of several frames*/ - float pre_spec_low_dif[PRE_SPEC_DIF_NUM]; /* low frequency spectral different*/ - float t_bg_energy; /* time background energy of several frames*/ - Word32 t_bg_energy_fx; /* time background energy of several frames*/ - float t_bg_energy_sum; /* number of time background energy*/ - Word32 t_bg_energy_sum_fx; /* number of time background energy*/ - int16_t tbg_energy_count; /* sum of time background energy of several frames*/ - int16_t bg_update_count; /* time of background update*/ - float frame_energy_smooth; /* smoothed energy of several frames*/ - Word32 frame_energy_smooth_fx; /* smoothed energy of several frames*/ + float t_bg_energy; /* time background energy of several frames*/ + Word32 t_bg_energy_fx; /* time background energy of several frames*/ + float t_bg_energy_sum; /* number of time background energy*/ + Word32 t_bg_energy_sum_fx; /* number of time background energy*/ + int16_t tbg_energy_count; /* sum of time background energy of several frames*/ + int16_t bg_update_count; /* time of background update*/ + float frame_energy_smooth; /* smoothed energy of several frames*/ + Word32 frame_energy_smooth_fx; /* smoothed energy of several frames*/ /* history parameters */ - float smooth_spec_amp[SPEC_AMP_NUM]; /* smoothed spectral amplitude*/ - float sb_bg_energy[BG_ENG_NUM]; /* sub-band background energy*/ - float pre_snr[PRE_SNR_NUM]; /* previous time SNR*/ - - float lt_snr_org; /* original long time SNR*/ - float lf_snr_smooth; /* smoothed lf_snr*/ - float l_silence_snr; /* sum of snr's of non active frames*/ - float l_speech_snr; /* sum of snr's of active frames*/ - Word32 lt_snr_org_fx; /* original long time SNR*/ - Word32 lf_snr_smooth_fx; /* smoothed lf_snr*/ - Word16 l_silence_snr_fx; /* sum of snr's of non active frames*/ - Word32 l_speech_snr_fx; /* sum of snr's of active frames*/ - int16_t l_silence_snr_count; /* number of non active frames*/ - int16_t l_speech_snr_count; /* number of active frames*/ - float fg_energy; /* foreground energy sum */ - float bg_energy; /* background energy sum */ - Word32 fg_energy_fx; /* foreground energy sum */ - Word32 bg_energy_fx; /* background energy sum */ - int16_t fg_energy_count; /* number of the foreground energy frame */ - int16_t bg_energy_count; /* number of the background energy frame */ - int16_t fg_energy_est_start; /* flag by that indicate whether if estimate energy*/ - int16_t speech_flag; /* residual number of hangover 1 */ - int16_t continuous_noise_num; /* time of continuous noise frames*/ - int16_t continuous_speech_num; /* time of continuous speech frames*/ - int16_t continuous_speech_num2; /* time 2 of continuous speech frames*/ - int16_t frameloop; /* number of frame*/ - float tonality_rate3; /* tonality rate*/ - float music_background_rate; /* music background rate*/ - float lt_noise_sp_center_diff_sum; /* different sum of long time noise sp_center*/ - float lt_noise_sp_center_diff_counter; /* number of the member lt_noise_sp_center_diff_sum*/ - float lt_noise_sp_center0; /* long time noise sp_center0*/ - float lt_noise_sp_center3; /* long time noise sp_center3*/ - float lt_bg_highf_eng; /* average of long time high frequency energy*/ - Word16 f_tonality_rate_fx[TONA_NUM]; /* tonality rate*/ + float smooth_spec_amp[SPEC_AMP_NUM]; /* smoothed spectral amplitude*/ + float sb_bg_energy[BG_ENG_NUM]; /* sub-band background energy*/ + float pre_snr[PRE_SNR_NUM]; /* previous time SNR*/ + + float lt_snr_org; /* original long time SNR*/ + float lf_snr_smooth; /* smoothed lf_snr*/ + float l_silence_snr; /* sum of snr's of non active frames*/ + float l_speech_snr; /* sum of snr's of active frames*/ + Word32 lt_snr_org_fx; /* original long time SNR*/ + Word32 lf_snr_smooth_fx; /* smoothed lf_snr*/ + Word16 l_silence_snr_fx; /* sum of snr's of non active frames*/ + Word32 l_speech_snr_fx; /* sum of snr's of active frames*/ + int16_t l_silence_snr_count; /* number of non active frames*/ + int16_t l_speech_snr_count; /* number of active frames*/ + float fg_energy; /* foreground energy sum */ + float bg_energy; /* background energy sum */ + Word32 fg_energy_fx; /* foreground energy sum */ + Word32 bg_energy_fx; /* background energy sum */ + int16_t fg_energy_count; /* number of the foreground energy frame */ + int16_t bg_energy_count; /* number of the background energy frame */ + int16_t fg_energy_est_start; /* flag by that indicate whether if estimate energy*/ + int16_t speech_flag; /* residual number of hangover 1 */ + int16_t continuous_noise_num; /* time of continuous noise frames*/ + int16_t continuous_speech_num; /* time of continuous speech frames*/ + int16_t continuous_speech_num2; /* time 2 of continuous speech frames*/ + int16_t frameloop; /* number of frame*/ + float tonality_rate3; /* tonality rate*/ + float music_background_rate; /* music background rate*/ + float lt_noise_sp_center_diff_sum; /* different sum of long time noise sp_center*/ + float lt_noise_sp_center_diff_counter; /* number of the member lt_noise_sp_center_diff_sum*/ + float lt_noise_sp_center0; /* long time noise sp_center0*/ + float lt_noise_sp_center3; /* long time noise sp_center3*/ + float lt_bg_highf_eng; /* average of long time high frequency energy*/ + Word16 f_tonality_rate_fx[TONA_NUM]; /* tonality rate*/ Word32 frame_sb_energy_fx[BG_ENG_NUM]; /* energy of sub-band divided non-uniformly*/ Word32 frames_power_fx[POWER_NUM]; /* energy of several frames*/ - Word16 pre_spec_low_dif_fx[PRE_SPEC_DIF_NUM] ; /* low frequency spectral different*/ - Word32 smooth_spec_amp_fx[SPEC_AMP_NUM]; /* smoothed spectral amplitude*/ - Word32 sb_bg_energy_fx[BG_ENG_NUM]; /* sub-band background energy*/ - Word32 pre_snr_fx[PRE_SNR_NUM]; /* previous time SNR*/ + Word16 pre_spec_low_dif_fx[PRE_SPEC_DIF_NUM]; /* low frequency spectral different*/ + Word32 smooth_spec_amp_fx[SPEC_AMP_NUM]; /* smoothed spectral amplitude*/ + Word32 sb_bg_energy_fx[BG_ENG_NUM]; /* sub-band background energy*/ + Word32 pre_snr_fx[PRE_SNR_NUM]; /* previous time SNR*/ Word16 sfm_fx[SFM_NUM]; /* spectral flatness*/ - Word16 sp_center_fx[SP_CENTER_NUM]; /* spectral center*/ + Word16 sp_center_fx[SP_CENTER_NUM]; /* spectral center*/ Word16 ltd_stable_rate_fx[STABLE_NUM]; /* time-domain stable rate*/ - Word16 tonality_rate3_fx; /* tonality rate*/ - Word16 music_background_rate_fx; /* music background rate*/ - Word16 lt_noise_sp_center_diff_sum_fx; /* different sum of long time noise sp_center*/ - Word32 lt_noise_sp_center_diff_counter_fx; /* number of the member lt_noise_sp_center_diff_sum*/ - Word16 lt_noise_sp_center0_fx; /* long time noise sp_center0*/ - Word16 lt_noise_sp_center3_fx; /* long time noise sp_center3*/ - Word32 lt_bg_highf_eng_fx; /* average of long time high frequency energy*/ - int16_t update_num_with_snr_fx; /* the number of the background update with SNR*/ - - int16_t update_num_with_snr; /* the number of the background update with SNR*/ + Word16 tonality_rate3_fx; /* tonality rate*/ + Word16 music_background_rate_fx; /* music background rate*/ + Word16 lt_noise_sp_center_diff_sum_fx; /* different sum of long time noise sp_center*/ + Word32 lt_noise_sp_center_diff_counter_fx; /* number of the member lt_noise_sp_center_diff_sum*/ + Word16 lt_noise_sp_center0_fx; /* long time noise sp_center0*/ + Word16 lt_noise_sp_center3_fx; /* long time noise sp_center3*/ + Word32 lt_bg_highf_eng_fx; /* average of long time high frequency energy*/ + int16_t update_num_with_snr_fx; /* the number of the background update with SNR*/ + + int16_t update_num_with_snr; /* the number of the background update with SNR*/ int16_t update_count; int16_t warm_hang_num; /* the number of hangover for warm up*/ int16_t vad_flag_for_bk_update; @@ -349,63 +349,63 @@ typedef struct cldfb_vad_structure typedef struct { - Word16 bw_index; /* index of band width */ - - /* feature */ - Word16 sp_center[SP_CENTER_NUM]; /* spectral center*/ - Word16 ltd_stable_rate[STABLE_NUM]; /* time-domain stable rate*/ - Word16 sfm[SFM_NUM]; /* spectral flatness*/ - Word16 f_tonality_rate[TONA_NUM]; /* tonality rate*/ - Word16 pre_spec_low_dif[PRE_SPEC_DIF_NUM]; /* low frequency spectral different*/ - Word32 frames_power_32[POWER_NUM]; /* energy of several frames*/ - Word32 frame_sb_energy[BG_ENG_NUM]; /* energy of sub-band divided non-uniformly*/ - Word32 t_bg_energy; /* time background energy of several frames*/ - T_VAD_EXP t_bg_energy_sum; /* number of time background energy*/ - Word16 tbg_energy_count; /* sum of time background energy of several frames*/ - Word16 bg_update_count; /* time of background update*/ - Word32 frame_energy_smooth; /* smoothed energy of several frames*/ - - /************************************************************************/ - /* history parameters */ - /************************************************************************/ - Word32 smooth_spec_amp[SPEC_AMP_NUM]; /* smoothed spectral amplitude*/ - Word32 pre_snr[PRE_SNR_NUM]; /* previous time SNR*/ - Word32 sb_bg_energy[BG_ENG_NUM]; /* sub-band background energy*/ - Word16 continuous_noise_num; /* time of continuous noise frames*/ - Word16 continuous_speech_num; /* time of continuous speech frames*/ - Word16 continuous_speech_num2; /* time 2 of continuous speech frames*/ - Word32 fg_energy_est_start; /* flag by that indicate whether if estimate energy*/ - Word16 speech_flag; /* residual number of hangover 1 */ - Word32 lt_noise_sp_center_diff_counter; /* number of the member lt_noise_sp_center_diff_sum*/ - Word32 fg_energy; /* foreground energy sum */ - Word32 bg_energy; /* background energy sum */ - Word32 lt_bg_highf_eng; /* average of long time high frequency energy*/ - Word32 lt_noise_sp_center_diff_sum; /* different sum of long time noise sp_center*/ - Word32 lt_snr_org; /* original long time SNR*/ - Word32 l_speech_snr; /* sum of snr's of active frames*/ - Word32 l_silence_snr; /* sum of snr's of non active frames*/ - Word32 l_speech_snr_count; /* number of active frames*/ - Word32 l_silence_snr_count; /* number of non active frames*/ - Word32 lf_snr_smooth; /* smoothed lf_snr*/ - Word16 frameloop; /* number of frame*/ - Word16 lt_noise_sp_center0; /* long time noise sp_center0*/ - Word16 lt_noise_sp_center3; /* long time noise sp_center3*/ - Word16 music_background_rate; /* music background rate*/ - Word16 tonality_rate3; /* tonality rate*/ - Word16 bg_energy_count; /* number of the background energy frame */ - Word16 fg_energy_count; /* number of the foreground energy frame */ - Word16 Q_frames_power_32; /* the Scaling of frames_power_fix32*/ - Word16 scale_spec_low_dif; /* the Scaling of spec_low_dif*/ - Word16 sb_bg_energy_scale; /* the Scaling of sb_bg_energy*/ - Word16 frame_sb_energy_scale; /* the Scaling of frame_sb_energy*/ - Word16 scale_t_bg_energy; /* the Scaling of t_bg_energy*/ - Word16 frame_energy_smooth_scale; /* the Scaling of frame_energy_smooth*/ - Word16 bg_energy_scale; /* the Scaling of bg_energy*/ - Word16 fg_energy_scale; /* the Scaling of fg_energy*/ - Word16 updateNumWithSnr; /* the number of the background update with SNR*/ - Word16 update_count; /* the number of the background update*/ - Word16 warm_hang_num; /* the number of hangover for warm up*/ - Word16 vad_flag_for_bk_update; + Word16 bw_index; /* index of band width */ + + /* feature */ + Word16 sp_center[SP_CENTER_NUM]; /* spectral center*/ + Word16 ltd_stable_rate[STABLE_NUM]; /* time-domain stable rate*/ + Word16 sfm[SFM_NUM]; /* spectral flatness*/ + Word16 f_tonality_rate[TONA_NUM]; /* tonality rate*/ + Word16 pre_spec_low_dif[PRE_SPEC_DIF_NUM]; /* low frequency spectral different*/ + Word32 frames_power_32[POWER_NUM]; /* energy of several frames*/ + Word32 frame_sb_energy[BG_ENG_NUM]; /* energy of sub-band divided non-uniformly*/ + Word32 t_bg_energy; /* time background energy of several frames*/ + T_VAD_EXP t_bg_energy_sum; /* number of time background energy*/ + Word16 tbg_energy_count; /* sum of time background energy of several frames*/ + Word16 bg_update_count; /* time of background update*/ + Word32 frame_energy_smooth; /* smoothed energy of several frames*/ + + /************************************************************************/ + /* history parameters */ + /************************************************************************/ + Word32 smooth_spec_amp[SPEC_AMP_NUM]; /* smoothed spectral amplitude*/ + Word32 pre_snr[PRE_SNR_NUM]; /* previous time SNR*/ + Word32 sb_bg_energy[BG_ENG_NUM]; /* sub-band background energy*/ + Word16 continuous_noise_num; /* time of continuous noise frames*/ + Word16 continuous_speech_num; /* time of continuous speech frames*/ + Word16 continuous_speech_num2; /* time 2 of continuous speech frames*/ + Word32 fg_energy_est_start; /* flag by that indicate whether if estimate energy*/ + Word16 speech_flag; /* residual number of hangover 1 */ + Word32 lt_noise_sp_center_diff_counter; /* number of the member lt_noise_sp_center_diff_sum*/ + Word32 fg_energy; /* foreground energy sum */ + Word32 bg_energy; /* background energy sum */ + Word32 lt_bg_highf_eng; /* average of long time high frequency energy*/ + Word32 lt_noise_sp_center_diff_sum; /* different sum of long time noise sp_center*/ + Word32 lt_snr_org; /* original long time SNR*/ + Word32 l_speech_snr; /* sum of snr's of active frames*/ + Word32 l_silence_snr; /* sum of snr's of non active frames*/ + Word32 l_speech_snr_count; /* number of active frames*/ + Word32 l_silence_snr_count; /* number of non active frames*/ + Word32 lf_snr_smooth; /* smoothed lf_snr*/ + Word16 frameloop; /* number of frame*/ + Word16 lt_noise_sp_center0; /* long time noise sp_center0*/ + Word16 lt_noise_sp_center3; /* long time noise sp_center3*/ + Word16 music_background_rate; /* music background rate*/ + Word16 tonality_rate3; /* tonality rate*/ + Word16 bg_energy_count; /* number of the background energy frame */ + Word16 fg_energy_count; /* number of the foreground energy frame */ + Word16 Q_frames_power_32; /* the Scaling of frames_power_fix32*/ + Word16 scale_spec_low_dif; /* the Scaling of spec_low_dif*/ + Word16 sb_bg_energy_scale; /* the Scaling of sb_bg_energy*/ + Word16 frame_sb_energy_scale; /* the Scaling of frame_sb_energy*/ + Word16 scale_t_bg_energy; /* the Scaling of t_bg_energy*/ + Word16 frame_energy_smooth_scale; /* the Scaling of frame_energy_smooth*/ + Word16 bg_energy_scale; /* the Scaling of bg_energy*/ + Word16 fg_energy_scale; /* the Scaling of fg_energy*/ + Word16 updateNumWithSnr; /* the number of the background update with SNR*/ + Word16 update_count; /* the number of the background update*/ + Word16 warm_hang_num; /* the number of hangover for warm up*/ + Word16 vad_flag_for_bk_update; } T_CldfbVadState_fx, *VAD_CLDFB_HANDLE_FX; @@ -417,33 +417,33 @@ typedef struct td_cng_enc_structure { int16_t lp_cng_mode2; - float lp_ener; /* CNG and DTX - low-pass filtered energy for CNG */ - Word32 lp_ener_fx; /* CNG and DTX - low-pass filtered energy for CNG */ - int16_t cng_seed; /* CNG and DTX - seed for white noise random generator */ - int16_t old_enr_index; /* CNG and DTX - index of last encoded CNG energy */ - float Enew; /* CNG and DTX - CNG target residual energy */ - Word32 Enew_fx; /* CNG and DTX - CNG target residual energy */ - int16_t cng_hist_ptr; /* CNG and DTX - pointer for averaging buffers */ - float cng_lsp_hist[DTX_HIST_SIZE * M]; /* CNG and DTX - old LSP buffer for averaging */ - float cng_ener_hist[DTX_HIST_SIZE]; /* CNG and DTX - log energy buffer for averaging */ - Word16 cng_lsp_hist_fx[DTX_HIST_SIZE * M]; /* CNG and DTX - old LSP buffer for averaging */ - Word16 cng_ener_hist_fx[DTX_HIST_SIZE]; /* CNG and DTX - log energy buffer for averaging */ - int16_t cng_ener_seed; /* CNG and DTX - seed for random generator for variation of excitation energy */ + float lp_ener; /* CNG and DTX - low-pass filtered energy for CNG */ + Word32 lp_ener_fx; /* CNG and DTX - low-pass filtered energy for CNG */ + int16_t cng_seed; /* CNG and DTX - seed for white noise random generator */ + int16_t old_enr_index; /* CNG and DTX - index of last encoded CNG energy */ + float Enew; /* CNG and DTX - CNG target residual energy */ + Word32 Enew_fx; /* CNG and DTX - CNG target residual energy */ + int16_t cng_hist_ptr; /* CNG and DTX - pointer for averaging buffers */ + float cng_lsp_hist[DTX_HIST_SIZE * M]; /* CNG and DTX - old LSP buffer for averaging */ + float cng_ener_hist[DTX_HIST_SIZE]; /* CNG and DTX - log energy buffer for averaging */ + Word16 cng_lsp_hist_fx[DTX_HIST_SIZE * M]; /* CNG and DTX - old LSP buffer for averaging */ + Word16 cng_ener_hist_fx[DTX_HIST_SIZE]; /* CNG and DTX - log energy buffer for averaging */ + int16_t cng_ener_seed; /* CNG and DTX - seed for random generator for variation of excitation energy */ int16_t cng_ener_seed1; float lp_sp_enr; - Word16 lp_sp_enr_fx; /*Q8*/ + Word16 lp_sp_enr_fx; /*Q8*/ int16_t last_allow_cn_step; - int16_t ho_hist_size; /* CNG and DTX - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ - int16_t ho_hist_ptr; /* CNG and DTX - pointer for averaging buffers */ - int32_t ho_sid_bw; /* CNG and DTX - SID bandwidth flags */ - Word16 ho_lsp_hist_fx[HO_HIST_SIZE * M]; /* CNG and DTX - old LSP buffer for averaging */ - Word32 ho_ener_hist_fx[HO_HIST_SIZE]; /* CNG and DTX - energy buffer for averaging */ + int16_t ho_hist_size; /* CNG and DTX - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ + int16_t ho_hist_ptr; /* CNG and DTX - pointer for averaging buffers */ + int32_t ho_sid_bw; /* CNG and DTX - SID bandwidth flags */ + Word16 ho_lsp_hist_fx[HO_HIST_SIZE * M]; /* CNG and DTX - old LSP buffer for averaging */ + Word32 ho_ener_hist_fx[HO_HIST_SIZE]; /* CNG and DTX - energy buffer for averaging */ Word32 ho_env_hist_fx[HO_HIST_SIZE * NUM_ENV_CNG]; float ho_lsp_hist[HO_HIST_SIZE * M]; /* CNG and DTX - old LSP buffer for averaging */ float ho_ener_hist[HO_HIST_SIZE]; /* CNG and DTX - energy buffer for averaging */ float ho_env_hist[HO_HIST_SIZE * NUM_ENV_CNG]; - Word16 ho_lsp_circ_fx[HO_HIST_SIZE * M]; /* CNG and DTX - old LSP buffer for averaging */ - Word32 ho_ener_circ_fx[HO_HIST_SIZE]; /* CNG and DTX - energy buffer for averaging */ + Word16 ho_lsp_circ_fx[HO_HIST_SIZE * M]; /* CNG and DTX - old LSP buffer for averaging */ + Word32 ho_ener_circ_fx[HO_HIST_SIZE]; /* CNG and DTX - energy buffer for averaging */ Word32 ho_env_circ_fx[HO_HIST_SIZE * NUM_ENV_CNG]; int16_t act_cnt; /* CNG and DTX - counter of active frames */ int16_t ho_circ_size; /* CNG and DTX - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ @@ -451,18 +451,18 @@ typedef struct td_cng_enc_structure float ho_lsp_circ[HO_HIST_SIZE * M]; /* CNG and DTX - old LSP buffer for averaging */ float ho_ener_circ[HO_HIST_SIZE]; /* CNG and DTX - energy buffer for averaging */ float ho_env_circ[HO_HIST_SIZE * NUM_ENV_CNG]; - int16_t burst_ho_cnt; /* CNG and DTX - counter of hangover frames at end of active burst */ - int16_t cng_buf_cnt; /* CNG and DTX - Counter of buffered CNG parameters */ + int16_t burst_ho_cnt; /* CNG and DTX - counter of hangover frames at end of active burst */ + int16_t cng_buf_cnt; /* CNG and DTX - Counter of buffered CNG parameters */ float cng_exc2_buf_flt[HO_HIST_SIZE * L_FFT]; /* CNG and DTX - exc2 buffer for storing */ - Word16 cng_exc2_buf[HO_HIST_SIZE * L_FFT]; /* CNG and DTX - exc2 buffer for storing */ - Word16 cng_Qexc_buf[HO_HIST_SIZE]; /* CNG and DTX - Q_exc buffer for storing */ - int32_t cng_brate_buf[HO_HIST_SIZE]; /* CNG and DTX - buffer for storing last_active_brate */ - float CNG_att; /* CNG and DTX - attenuation factor for CNG, in dB */ - int16_t ho_16k_lsp[HO_HIST_SIZE]; /* CNG and DTX - 16k LSPs flags */ - int16_t act_cnt2; /* CNG and DTX - counter of active frames for CNG_mode switching */ - float ho_lsp_circ2[HO_HIST_SIZE * M]; /* CNG and DTX - second buffer of LSPs */ - Word16 ho_lsp_circ2_fx[HO_HIST_SIZE * M]; /* CNG and DTX - second buffer of LSPs */ - int16_t num_ho; /* CNG and DTX - number of selected hangover frames */ + Word16 cng_exc2_buf[HO_HIST_SIZE * L_FFT]; /* CNG and DTX - exc2 buffer for storing */ + Word16 cng_Qexc_buf[HO_HIST_SIZE]; /* CNG and DTX - Q_exc buffer for storing */ + int32_t cng_brate_buf[HO_HIST_SIZE]; /* CNG and DTX - buffer for storing last_active_brate */ + float CNG_att; /* CNG and DTX - attenuation factor for CNG, in dB */ + int16_t ho_16k_lsp[HO_HIST_SIZE]; /* CNG and DTX - 16k LSPs flags */ + int16_t act_cnt2; /* CNG and DTX - counter of active frames for CNG_mode switching */ + float ho_lsp_circ2[HO_HIST_SIZE * M]; /* CNG and DTX - second buffer of LSPs */ + Word16 ho_lsp_circ2_fx[HO_HIST_SIZE * M]; /* CNG and DTX - second buffer of LSPs */ + int16_t num_ho; /* CNG and DTX - number of selected hangover frames */ float old_env[NUM_ENV_CNG]; float lp_env[NUM_ENV_CNG]; float cng_res_env[NUM_ENV_CNG * HO_HIST_SIZE]; @@ -511,18 +511,18 @@ typedef struct fd_cng_enc_structure float msCurrentMin[NPART]; float msCurrentMinSubWindow[NPART]; - Word32 msPeriodog_fx[NPART]; /* Periodogram */ - Word16 msPeriodog_fx_exp; /* Common exponent for fft and cldfb energies */ - Word16 msPeriodog_fx_exp_fft; - Word16 msPeriodog_fx_exp_cldfb; - Word32 msBminWin_fx[NPART]; - Word32 msBminSubWin_fx[NPART]; - Word16 msPsd_fx[NPART]; /* Power Spectral Density estimate (i.e., smoothed periodogram) */ - Word32 msAlpha_fx[NPART]; /* Optimal smoothing parameter */ - Word32 msMinBuf_fx[MSNUMSUBFR*NPART]; /* Buffer of minima */ - Word32 msCurrentMinOut_fx[NPART]; - Word32 msCurrentMin_fx[NPART]; - Word32 msCurrentMinSubWindow_fx[NPART]; + Word32 msPeriodog_fx[NPART]; /* Periodogram */ + Word16 msPeriodog_fx_exp; /* Common exponent for fft and cldfb energies */ + Word16 msPeriodog_fx_exp_fft; + Word16 msPeriodog_fx_exp_cldfb; + Word32 msBminWin_fx[NPART]; + Word32 msBminSubWin_fx[NPART]; + Word16 msPsd_fx[NPART]; /* Power Spectral Density estimate (i.e., smoothed periodogram) */ + Word32 msAlpha_fx[NPART]; /* Optimal smoothing parameter */ + Word32 msMinBuf_fx[MSNUMSUBFR * NPART]; /* Buffer of minima */ + Word32 msCurrentMinOut_fx[NPART]; + Word32 msCurrentMin_fx[NPART]; + Word32 msCurrentMinSubWindow_fx[NPART]; int16_t msLocalMinFlag[NPART]; int16_t msNewMinFlag[NPART]; @@ -536,18 +536,18 @@ typedef struct fd_cng_enc_structure float msLogPeriodog[NPART]; /* Periodogram */ float msLogNoiseEst[NPART]; /* Estimated noise level */ - Word16 msPsdFirstMoment_fx[NPART]; - Word32 msPsdSecondMoment_fx[NPART]; - Word16 msNoiseFloor_fx[NPART]; /* Estimated noise floor */ - Word32 msNoiseEst_fx[NPART]; /* Estimated noise level */ - Word16 msNoiseEst_fx_exp; - Word32 energy_ho_fx[NPART]; - Word16 energy_ho_fx_exp; - Word32 msNoiseEst_old_fx[NPART]; - Word16 msNoiseEst_old_fx_exp; + Word16 msPsdFirstMoment_fx[NPART]; + Word32 msPsdSecondMoment_fx[NPART]; + Word16 msNoiseFloor_fx[NPART]; /* Estimated noise floor */ + Word32 msNoiseEst_fx[NPART]; /* Estimated noise level */ + Word16 msNoiseEst_fx_exp; + Word32 energy_ho_fx[NPART]; + Word16 energy_ho_fx_exp; + Word32 msNoiseEst_old_fx[NPART]; + Word16 msNoiseEst_old_fx_exp; float msPeriodogBuf[MSBUFLEN * NPART]; - Word16 msPeriodogBuf_fx[MSBUFLEN*NPART]; + Word16 msPeriodogBuf_fx[MSBUFLEN * NPART]; int16_t msPeriodogBufPtr; int16_t stopFFTbinDec; @@ -558,56 +558,56 @@ typedef struct fd_cng_enc_structure int16_t nFFTpartDec; int16_t partDec[NPART]; - Word16 msLogPeriodog_fx[NPART]; - Word16 msLogNoiseEst_fx[NPART]; + Word16 msLogPeriodog_fx[NPART]; + Word16 msLogNoiseEst_fx[NPART]; float mem_coherence[4]; } FD_CNG_ENC, *HANDLE_FD_CNG_ENC; -//typedef struct +// typedef struct //{ -// HANDLE_FD_CNG_COM hFdCngCom; -// -// Word32 msPeriodog[NPART]; /* Periodogram */ -// Word16 msPeriodog_exp; /* Common exponent for fft and cldfb energies */ -// Word16 msPeriodog_exp_fft; -// Word16 msPeriodog_exp_cldfb; -// Word32 msBminWin[NPART]; -// Word32 msBminSubWin[NPART]; -// Word16 msPsd[NPART]; /* Power Spectral Density estimate (i.e., smoothed periodogram) */ -// Word32 msAlpha[NPART]; /* Optimal smoothing parameter */ -// Word32 msMinBuf[MSNUMSUBFR*NPART]; /* Buffer of minima */ -// Word32 msCurrentMinOut[NPART]; -// Word32 msCurrentMin[NPART]; -// Word32 msCurrentMinSubWindow[NPART]; -// Word16 msLocalMinFlag[NPART]; -// Word16 msNewMinFlag[NPART]; -// Word16 msPsdFirstMoment[NPART]; -// Word32 msPsdSecondMoment[NPART]; -// Word16 msNoiseFloor[NPART]; /* Estimated noise floor */ -// Word32 msNoiseEst[NPART]; /* Estimated noise level */ -// Word16 msNoiseEst_exp; -// Word32 energy_ho[NPART]; -// Word16 energy_ho_exp; -// Word32 msNoiseEst_old[NPART]; -// Word16 msNoiseEst_old_exp; -// -// Word16 msPeriodogBuf[MSBUFLEN*NPART]; -// Word16 msPeriodogBufPtr; -// -// Word16 stopFFTbinDec; -// Word16 startBandDec; -// Word16 stopBandDec; -// Word16 npartDec; -// Word16 midbandDec[NPART]; -// Word16 nFFTpartDec; -// Word16 partDec[NPART]; -// -// Word16 msLogPeriodog[NPART]; -// Word16 msLogNoiseEst[NPART]; -//} -//FD_CNG_ENC_FX; -//typedef FD_CNG_ENC_FX *HANDLE_FD_CNG_ENC_FX; +// HANDLE_FD_CNG_COM hFdCngCom; +// +// Word32 msPeriodog[NPART]; /* Periodogram */ +// Word16 msPeriodog_exp; /* Common exponent for fft and cldfb energies */ +// Word16 msPeriodog_exp_fft; +// Word16 msPeriodog_exp_cldfb; +// Word32 msBminWin[NPART]; +// Word32 msBminSubWin[NPART]; +// Word16 msPsd[NPART]; /* Power Spectral Density estimate (i.e., smoothed periodogram) */ +// Word32 msAlpha[NPART]; /* Optimal smoothing parameter */ +// Word32 msMinBuf[MSNUMSUBFR*NPART]; /* Buffer of minima */ +// Word32 msCurrentMinOut[NPART]; +// Word32 msCurrentMin[NPART]; +// Word32 msCurrentMinSubWindow[NPART]; +// Word16 msLocalMinFlag[NPART]; +// Word16 msNewMinFlag[NPART]; +// Word16 msPsdFirstMoment[NPART]; +// Word32 msPsdSecondMoment[NPART]; +// Word16 msNoiseFloor[NPART]; /* Estimated noise floor */ +// Word32 msNoiseEst[NPART]; /* Estimated noise level */ +// Word16 msNoiseEst_exp; +// Word32 energy_ho[NPART]; +// Word16 energy_ho_exp; +// Word32 msNoiseEst_old[NPART]; +// Word16 msNoiseEst_old_exp; +// +// Word16 msPeriodogBuf[MSBUFLEN*NPART]; +// Word16 msPeriodogBufPtr; +// +// Word16 stopFFTbinDec; +// Word16 startBandDec; +// Word16 stopBandDec; +// Word16 npartDec; +// Word16 midbandDec[NPART]; +// Word16 nFFTpartDec; +// Word16 partDec[NPART]; +// +// Word16 msLogPeriodog[NPART]; +// Word16 msLogNoiseEst[NPART]; +// } +// FD_CNG_ENC_FX; +// typedef FD_CNG_ENC_FX *HANDLE_FD_CNG_ENC_FX; /*------------------------------------------------------------------------------------------* * Structure for DTX-related variables used in both FD- and TD-CNG *------------------------------------------------------------------------------------------*/ @@ -620,22 +620,22 @@ typedef struct dtx_enc_structure int16_t max_SID; /* CNG and DTX - max allowed number of CNG FRAME_NO_DATA frames */ int16_t CNG_mode; /* CNG and DTX - mode for DTX configuration */ float lspCNG[M]; /* CNG and DTX - LP filtered ISPs */ - Word16 lspCNG_fx[M]; /* CNG and DTX - LP filtered lsps */ + Word16 lspCNG_fx[M]; /* CNG and DTX - LP filtered lsps */ int16_t VarDTX_cnt_voiced; /* CNG and DTX - counter for variable DTX activation (speech) */ int16_t VarDTX_cnt_noise; /* CNG and DTX - counter for variable DTX activation (noise) */ float lt_ener_voiced; /* CNG and DTX - long-term energy of signal (measured on voiced parts) */ float lt_ener_noise; /* CNG and DTX - long-term energy of background noise */ float frame_ener; - Word32 lt_ener_voiced_fx; /* CNG and DTX - long-term energy of signal (measured on voiced parts) */ - Word32 lt_ener_noise_fx; /* CNG and DTX - long-term energy of background noise */ + Word32 lt_ener_voiced_fx; /* CNG and DTX - long-term energy of signal (measured on voiced parts) */ + Word32 lt_ener_noise_fx; /* CNG and DTX - long-term energy of background noise */ Word32 frame_ener_fx; - int16_t cng_hist_size; /* CNG and DTX - size of CNG history buffer for averaging, <0,DTX_HIST_SIZE> */ - float lt_ener_last_SID; /* CNG and DTX - long-term energy of last SID frame */ - Word32 lt_ener_last_SID_fx; /* CNG and DTX - long-term energy of last SID frame */ - int16_t last_CNG_L_frame; /* CNG and DTX - last CNG frame length */ - int16_t var_SID_rate_flag; /* CNG and DTX - flag for variable SID rate */ - int16_t interval_SID; /* CNG and DTX - interval of SID update, default 8 */ - int32_t last_active_brate; /* CNG and DTX - last active frame bitrate used for CNG_mode control */ + int16_t cng_hist_size; /* CNG and DTX - size of CNG history buffer for averaging, <0,DTX_HIST_SIZE> */ + float lt_ener_last_SID; /* CNG and DTX - long-term energy of last SID frame */ + Word32 lt_ener_last_SID_fx; /* CNG and DTX - long-term energy of last SID frame */ + int16_t last_CNG_L_frame; /* CNG and DTX - last CNG frame length */ + int16_t var_SID_rate_flag; /* CNG and DTX - flag for variable SID rate */ + int16_t interval_SID; /* CNG and DTX - interval of SID update, default 8 */ + int32_t last_active_brate; /* CNG and DTX - last active frame bitrate used for CNG_mode control */ } DTX_ENC_DATA, *DTX_ENC_HANDLE; @@ -693,8 +693,8 @@ typedef struct igf_enc_private_data_struct float prevSFM_FIR_flt[IGF_MAX_TILES]; float prevSFM_IIR_flt[IGF_MAX_TILES]; - Word32 prevSFM_FIR[IGF_MAX_TILES]; /* 15Q16 */ - Word16 prevSFM_IIR[IGF_MAX_TILES]; + Word32 prevSFM_FIR[IGF_MAX_TILES]; /* 15Q16 */ + Word16 prevSFM_IIR[IGF_MAX_TILES]; int16_t wasTransient; UWord8 igfBitstream[IGF_BITBUFSIZE / 8]; @@ -716,8 +716,8 @@ typedef struct igf_enc_instance_struct int16_t flatteningTrigger; float spec_be_igf_flt[N_MAX_TCX - IGF_START_MN]; float tns_predictionGain_flt; - Word32 spec_be_igf[N_MAX_TCX - IGF_START_MN]; /* copy of MDCT spectrum */ - Word16 spec_be_igf_e; /* exponent of copy of MDCT spectrum */ + Word32 spec_be_igf[N_MAX_TCX - IGF_START_MN]; /* copy of MDCT spectrum */ + Word16 spec_be_igf_e; /* exponent of copy of MDCT spectrum */ Word16 tns_predictionGain; } IGF_ENC_INSTANCE, *IGF_ENC_INSTANCE_HANDLE; @@ -729,10 +729,10 @@ typedef struct igf_enc_instance_struct typedef struct noise_estimation_structure { - float fr_bands1[NB_BANDS]; /* spectrum per critical bands of the previous frame */ - float fr_bands2[NB_BANDS]; /* spectrum per critical bands 2 frames ago */ - Word32 fr_bands1_fx[NB_BANDS]; /* Q_new + Q_SCALE spectrum per critical bands of the previous frame */ - Word32 fr_bands2_fx[NB_BANDS]; /* Q_new + Q_SCALE spectrum per critical bands 2 frames ago */ + float fr_bands1[NB_BANDS]; /* spectrum per critical bands of the previous frame */ + float fr_bands2[NB_BANDS]; /* spectrum per critical bands 2 frames ago */ + Word32 fr_bands1_fx[NB_BANDS]; /* Q_new + Q_SCALE spectrum per critical bands of the previous frame */ + Word32 fr_bands2_fx[NB_BANDS]; /* Q_new + Q_SCALE spectrum per critical bands 2 frames ago */ float old_S[L_FFT / 2]; /* Tonal detector - prev. log-energy spectrum with subtracted floor */ float cor_map[L_FFT / 2]; /* Tonal detector - LT correlation map */ @@ -743,19 +743,19 @@ typedef struct noise_estimation_structure float enrO[NB_BANDS]; /* Noise estimator - previous energy per critical band */ float bckr[NB_BANDS]; /* Noise estimator - background noise estimation per critical band */ float ave_enr[NB_BANDS]; /* Noise estimator - long-term average energy per critical band */ - Word16 old_S_fx[L_FFT / 2]; /* Q7 Tonal detector - prev. log-energy spectrum with subtracted floor */ - Word16 cor_map_fx[L_FFT / 2]; /* Q15 Tonal detector - LT correlation map */ - Word16 noise_char_fx; /* Q11 Tonal detector - LT noise character */ - Word32 ave_enr2_fx[NB_BANDS]; /* Q_new + Q_SCALE Tonal detector - LT average E per crit. band (for non_sta2) */ - Word16 act_pred_fx; /* Q15 Tonal detector - prediction of speech activity from 0 to 1 (0-inactive, 1-active) */ - Word16 multi_harm_limit_fx; /* Q9 Tonal detector - adaptive threshold */ - Word32 enrO_fx[NB_BANDS]; /* Noise estimator - previous energy per critical band */ - Word32 bckr_fx[NB_BANDS]; /* Q_new + Q_SCALE Noise estimator - background noise estimation per critical band */ - Word32 ave_enr_fx[NB_BANDS]; /* Q_new + Q_SCALE Noise estimator - long-term average energy per critical band */ - - int16_t aEn; /* Noise estimator - noise estimator adaptation flag */ - float totalNoise; /* Noise estimator - total noise energy */ - Word16 totalNoise_fx; /* Q8 Noise estimator - total noise energy */ + Word16 old_S_fx[L_FFT / 2]; /* Q7 Tonal detector - prev. log-energy spectrum with subtracted floor */ + Word16 cor_map_fx[L_FFT / 2]; /* Q15 Tonal detector - LT correlation map */ + Word16 noise_char_fx; /* Q11 Tonal detector - LT noise character */ + Word32 ave_enr2_fx[NB_BANDS]; /* Q_new + Q_SCALE Tonal detector - LT average E per crit. band (for non_sta2) */ + Word16 act_pred_fx; /* Q15 Tonal detector - prediction of speech activity from 0 to 1 (0-inactive, 1-active) */ + Word16 multi_harm_limit_fx; /* Q9 Tonal detector - adaptive threshold */ + Word32 enrO_fx[NB_BANDS]; /* Noise estimator - previous energy per critical band */ + Word32 bckr_fx[NB_BANDS]; /* Q_new + Q_SCALE Noise estimator - background noise estimation per critical band */ + Word32 ave_enr_fx[NB_BANDS]; /* Q_new + Q_SCALE Noise estimator - long-term average energy per critical band */ + + int16_t aEn; /* Noise estimator - noise estimator adaptation flag */ + float totalNoise; /* Noise estimator - total noise energy */ + Word16 totalNoise_fx; /* Q8 Noise estimator - total noise energy */ int16_t first_noise_updt; /* Noise estimator - flag used to determine if the first noise update frame */ int16_t first_noise_updt_cnt; /* Noise estimator - counter of frame after first noise update */ @@ -770,15 +770,15 @@ typedef struct noise_estimation_structure float lt_tn_dist; float lt_Ellp_dist; float lt_haco_ev; - Word16 Etot_l_fx; /* Q8 Noise estimator - Track energy from below */ - Word16 Etot_h_fx; /* Q8 Noise estimator - Track energy from above */ - Word16 Etot_l_lp_fx; /* Q8 Noise estimator - Smoothed low energy */ - Word16 Etot_last_fx; /*Q8*/ - Word16 Etot_lp_fx; /* Q8 Noise estimator - Filtered input energy */ - Word16 lt_tn_track_fx; /* Q15 */ - Word16 lt_tn_dist_fx; /* Q8*/ - Word16 lt_Ellp_dist_fx; /* Etot low lp same domain as *Etot_l_lp, Q8 */ - Word16 lt_haco_ev_fx; /* Q15 */ + Word16 Etot_l_fx; /* Q8 Noise estimator - Track energy from below */ + Word16 Etot_h_fx; /* Q8 Noise estimator - Track energy from above */ + Word16 Etot_l_lp_fx; /* Q8 Noise estimator - Smoothed low energy */ + Word16 Etot_last_fx; /*Q8*/ + Word16 Etot_lp_fx; /* Q8 Noise estimator - Filtered input energy */ + Word16 lt_tn_track_fx; /* Q15 */ + Word16 lt_tn_dist_fx; /* Q8*/ + Word16 lt_Ellp_dist_fx; /* Etot low lp same domain as *Etot_l_lp, Q8 */ + Word16 lt_haco_ev_fx; /* Q15 */ int16_t low_tn_track_cnt; float epsP_0_2_lp; float epsP_0_2_ad_lp; @@ -787,21 +787,21 @@ typedef struct noise_estimation_structure float epsP_2_16_dlp_lp; float epsP_2_16_dlp_lp2; float lt_aEn_zero; - Word16 epsP_0_2_lp_fx; /* Q12, all epsP quotas , range ]8.0 ..0]*/ + Word16 epsP_0_2_lp_fx; /* Q12, all epsP quotas , range ]8.0 ..0]*/ Word16 epsP_0_2_ad_lp_fx; Word16 epsP_2_16_lp_fx; Word16 epsP_2_16_lp2_fx; - Word16 epsP_2_16_dlp_lp2_fx; /* Q12 */ - Word16 lt_aEn_zero_fx; /* Q15 */ + Word16 epsP_2_16_dlp_lp2_fx; /* Q12 */ + Word16 lt_aEn_zero_fx; /* Q15 */ float Etot_v_h2; float sign_dyn_lp; float Etot_st_est; /* Noise estimation - short term estimate of E{ Etot } */ float Etot_sq_st_est; /* Noise estimation - short term estimate of E{ Etot^2 } */ Word16 Etot_v_h2_fx; - Word16 sign_dyn_lp_fx; /*Q8*/ - Word16 Etot_st_est_fx; /* Q8 Noise estimation - short term estimate of E{ Etot } */ - Word16 Etot_sq_st_est_fx; /* Q2 Noise estimation - short term estimate of E{ Etot^2 } */ + Word16 sign_dyn_lp_fx; /*Q8*/ + Word16 Etot_st_est_fx; /* Q8 Noise estimation - short term estimate of E{ Etot } */ + Word16 Etot_sq_st_est_fx; /* Q2 Noise estimation - short term estimate of E{ Etot^2 } */ int16_t aEn_inac_cnt; } NOISE_EST_DATA, *NOISE_EST_HANDLE; @@ -830,8 +830,8 @@ typedef struct sp_mus_clas_structure Word16 wdlp_0_95_sp_fx; float wdlp_xtalk; int16_t sp_mus_state; - int16_t past_dec[HANG_LEN - 1]; /* Speech/music classifier - buffer of past binary decisions */ - float past_dlp[HANG_LEN - 1]; /* Speech/music classifier - buffer of past non-binary decisions */ + int16_t past_dec[HANG_LEN - 1]; /* Speech/music classifier - buffer of past binary decisions */ + float past_dlp[HANG_LEN - 1]; /* Speech/music classifier - buffer of past non-binary decisions */ Word16 past_dlp_fx[HANG_LEN - 1]; float past_dlp_mean_ST[HANG_LEN - 1]; /* Speech/music classifier - buffer of past non-binary decisions (with ST smoothing) */ float dlp_mean_ST; @@ -848,24 +848,24 @@ typedef struct sp_mus_clas_structure Word16 last_lsp_fx[M_LSP_SPMUS]; Word16 last_cor_map_sum_fx; Word16 last_non_sta_fx; - Word16 past_log_enr_fx[NB_BANDS_SPMUS]; /* Speech/music classifier - last average per-band log energy used for non_staX */ - Word16 gsc_thres_fx[4]; /* Speech/music classifier - classification threshold */ - Word16 gsc_lt_diff_etot_fx[MAX_LT]; /* Speech/music classifier - long-term total energy variation */ - Word16 gsc_mem_etot_fx; /* Speech/music classifier - total energy memory */ - - int16_t gsc_last_music_flag; /* Speech/music classifier - last music flag */ - int16_t gsc_nb_thr_1; /* Speech/music classifier - number of consecutives frames of level 1 */ - int16_t gsc_nb_thr_3; /* Speech/music classifier - number of consecutives frames of level 3 */ + Word16 past_log_enr_fx[NB_BANDS_SPMUS]; /* Speech/music classifier - last average per-band log energy used for non_staX */ + Word16 gsc_thres_fx[4]; /* Speech/music classifier - classification threshold */ + Word16 gsc_lt_diff_etot_fx[MAX_LT]; /* Speech/music classifier - long-term total energy variation */ + Word16 gsc_mem_etot_fx; /* Speech/music classifier - total energy memory */ + + int16_t gsc_last_music_flag; /* Speech/music classifier - last music flag */ + int16_t gsc_nb_thr_1; /* Speech/music classifier - number of consecutives frames of level 1 */ + int16_t gsc_nb_thr_3; /* Speech/music classifier - number of consecutives frames of level 3 */ float mold_corr; float mean_avr_dyn; /* Speech/music classifier - long term average dynamic */ float last_sw_dyn; /* Speech/music classifier - last dynamic */ float lt_dec_thres; /* Speech/music classifier - Long term speech/music thresold values */ float ener_RAT; /* Speech/music classifier - LF/to total energy ratio */ Word16 mold_corr_fx; - Word16 mean_avr_dyn_fx; /* Q7 Speech/music classifier - long term average dynamic */ - Word16 last_sw_dyn_fx; /* Q7 Speech/music classifier - last dynamic */ - Word16 lt_dec_thres_fx; /* Speech/music classifier - Long term speech/music thresold values */ - Word16 ener_RAT_fx; /* Q15 Speech/music classifier - LF/to total energy ratio */ + Word16 mean_avr_dyn_fx; /* Q7 Speech/music classifier - long term average dynamic */ + Word16 last_sw_dyn_fx; /* Q7 Speech/music classifier - last dynamic */ + Word16 lt_dec_thres_fx; /* Speech/music classifier - Long term speech/music thresold values */ + Word16 ener_RAT_fx; /* Q15 Speech/music classifier - LF/to total energy ratio */ int16_t relE_attack_cnt; float prev_relE; @@ -978,15 +978,15 @@ typedef struct sp_mus_clas_structure typedef struct lpd_state_structure { - Word16 nbits; /* number of bits used by ACELP or TCX */ + Word16 nbits; /* number of bits used by ACELP or TCX */ /* signal memory */ float syn_flt[1 + M]; /* Synthesis memory (non-pe) */ - Word16 syn[1 + M]; /* Synthesis memory (non-pe) */ + Word16 syn[1 + M]; /* Synthesis memory (non-pe) */ /* ACELP memories*/ float old_exc_flt[L_EXC_MEM]; /* ACELP exc memory (Aq) */ - Word16 old_exc[L_EXC_MEM]; /* ACELP exc memory (Aq) */ + Word16 old_exc[L_EXC_MEM]; /* ACELP exc memory (Aq) */ float mem_w0_flt; float mem_syn_flt[M]; /* ACELP synthesis memory (pe) before post-proc */ @@ -994,19 +994,19 @@ typedef struct lpd_state_structure float mem_syn2_flt[M]; /* ACELP synthesis memory (pe) after post-proc */ float mem_syn_r_flt[L_SYN_MEM]; /* ACELP synthesis memory for 1.25ms */ float mem_syn3_flt[M]; - Word16 mem_syn[M]; /* ACELP synthesis memory (pe) before post-proc */ - Word16 mem_syn1_fx[M]; /* synthesis filter memory (for core switching and FD BWE) */ - Word16 mem_syn2[M]; /* ACELP synthesis memory (pe) after post-proc */ - Word16 mem_syn_r[L_SYN_MEM]; /* ACELP synthesis memory for 1.25ms */ + Word16 mem_syn[M]; /* ACELP synthesis memory (pe) before post-proc */ + Word16 mem_syn1_fx[M]; /* synthesis filter memory (for core switching and FD BWE) */ + Word16 mem_syn2[M]; /* ACELP synthesis memory (pe) after post-proc */ + Word16 mem_syn_r[L_SYN_MEM]; /* ACELP synthesis memory for 1.25ms */ Word16 mem_syn3[M]; - Word16 mem_w0; /* weighting filter memory */ + Word16 mem_w0; /* weighting filter memory */ float tilt_code_flt; float gc_threshold_flt; /* Noise enhancer - threshold for gain_code */ float dispMem_flt[8]; /* Noise enhancer - phase dispersion algorithm memory */ Word16 tilt_code; - Word32 gc_threshold; /* exponent = 15, 15Q16 */ - struct dispMem_fx dm_fx; /* Noise enhancer - phase dispersion algorithm memory */ + Word32 gc_threshold; /* exponent = 15, 15Q16 */ + struct dispMem_fx dm_fx; /* Noise enhancer - phase dispersion algorithm memory */ } LPD_state, *LPD_state_HANDLE; @@ -1048,23 +1048,23 @@ typedef struct gsc_enc_structure int16_t mem_last_pit_band; /* AC mode (GSC) - memory of the last band where pitch contribution was significant */ float mem_w0_tmp; float mem_syn_tmp[M]; - float mid_dyn; /* AC mode (GSC) - signal dynamic */ + float mid_dyn; /* AC mode (GSC) - signal dynamic */ Word16 mem_w0_tmp_fx; Word16 mem_syn_tmp_fx[M]; - Word16 mid_dyn_fx; /* AC mode (GSC) - signal dynamic */ - - int16_t noise_lev; /* AC mode (GSC) - noise level */ - int16_t past_dyn_dec; /* AC mode (GSC) - Past noise level decision */ - float Last_frame_ener; /* AC mode (GSC) - Last frame energy */ - Word32 Last_frame_ener_fx; /* AC mode (GSC) - Last frame energy */ - int16_t pit_exc_hangover; /* AC mode (GSC) - Hangover for the time contribution switching */ - float last_exc_dct_in[L_FRAME16k]; /* AC mode (GSC) - previous excitation */ - Word16 last_exc_dct_in_fx[L_FRAME16k]; /* AC mode (GSC) - previous exciation */ - float last_ener; /* AC mode (GSC) - previous energy */ - Word16 last_ener_fx; /* AC mode (GSC) - previous energy */ - int16_t last_bitallocation_band[6]; /* AC mode (GSC) - previous bit allocation of each band */ + Word16 mid_dyn_fx; /* AC mode (GSC) - signal dynamic */ + + int16_t noise_lev; /* AC mode (GSC) - noise level */ + int16_t past_dyn_dec; /* AC mode (GSC) - Past noise level decision */ + float Last_frame_ener; /* AC mode (GSC) - Last frame energy */ + Word32 Last_frame_ener_fx; /* AC mode (GSC) - Last frame energy */ + int16_t pit_exc_hangover; /* AC mode (GSC) - Hangover for the time contribution switching */ + float last_exc_dct_in[L_FRAME16k]; /* AC mode (GSC) - previous excitation */ + Word16 last_exc_dct_in_fx[L_FRAME16k]; /* AC mode (GSC) - previous exciation */ + float last_ener; /* AC mode (GSC) - previous energy */ + Word16 last_ener_fx; /* AC mode (GSC) - previous energy */ + int16_t last_bitallocation_band[6]; /* AC mode (GSC) - previous bit allocation of each band */ float lt_gpitch; - Word16 lt_gpitch_fx; /*Q15 */ + Word16 lt_gpitch_fx; /*Q15 */ } GSC_ENC_DATA, *GSC_ENC_HANDLE; /*----------------------------------------------------------------------------------* @@ -1126,7 +1126,7 @@ typedef struct sc_vbr_enc_structure { float vadsnr; float vadnoise; - Word16 vadsnr_fx; /*Q7*/ + Word16 vadsnr_fx; /*Q7*/ Word16 vadnoise_fx; /* NELP variables */ @@ -1158,8 +1158,8 @@ typedef struct sc_vbr_enc_structure int16_t last_nelp_mode; int16_t nelp_mode; - Word16 qprevIn_fx; - Word16 qprevGain_fx; + Word16 qprevIn_fx; + Word16 qprevGain_fx; /* PPP variables */ int16_t pppcountE; @@ -1169,7 +1169,7 @@ typedef struct sc_vbr_enc_structure int16_t ppp_mode; float prev_ppp_gain_pit; float prev_tilt_code; - Word16 prev_ppp_gain_pit_fx; /*Q14*/ + Word16 prev_ppp_gain_pit_fx; /*Q14*/ Word16 prev_tilt_code_fx; /* voiced encoder variables */ @@ -1178,8 +1178,8 @@ typedef struct sc_vbr_enc_structure /* DTFS variables */ float dtfs_enc_a[MAXLAG_WI]; float dtfs_enc_b[MAXLAG_WI]; - Word16 dtfs_enc_a_fx[MAXLAG_WI]; /*Q0*/ - Word16 dtfs_enc_b_fx[MAXLAG_WI]; /*Q0*/ + Word16 dtfs_enc_a_fx[MAXLAG_WI]; /*Q0*/ + Word16 dtfs_enc_b_fx[MAXLAG_WI]; /*Q0*/ int16_t dtfs_enc_lag; int16_t dtfs_enc_nH; @@ -1192,14 +1192,14 @@ typedef struct sc_vbr_enc_structure float prev_cw_en; float ph_offset_E; - float lastLgainE; /* Previous gain value for the low band */ - float lastHgainE; /* Previous gain value for the high band */ - float lasterbE[NUM_ERB_WB]; /* Previous Amplitude spectrum (ERB) */ - Word32 prev_cw_en_fx; /*Q_prev_cw_en_fx*/ - Word16 ph_offset_E_fx; /*Q15 normalized y 2*Pi */ - Word16 lastLgainE_fx; /*Q11 Previous gain value for the low band */ - Word16 lastHgainE_fx; /*Q11 Previous gain value for the high band */ - Word16 lasterbE_fx[NUM_ERB_WB]; /*Q13 Previous Amplitude spectrum (ERB) */ + float lastLgainE; /* Previous gain value for the low band */ + float lastHgainE; /* Previous gain value for the high band */ + float lasterbE[NUM_ERB_WB]; /* Previous Amplitude spectrum (ERB) */ + Word32 prev_cw_en_fx; /*Q_prev_cw_en_fx*/ + Word16 ph_offset_E_fx; /*Q15 normalized y 2*Pi */ + Word16 lastLgainE_fx; /*Q11 Previous gain value for the low band */ + Word16 lastHgainE_fx; /*Q11 Previous gain value for the high band */ + Word16 lasterbE_fx[NUM_ERB_WB]; /*Q13 Previous Amplitude spectrum (ERB) */ Word16 Q_prev_cw_en_fx; int16_t mode_QQF; @@ -1210,19 +1210,19 @@ typedef struct sc_vbr_enc_structure int16_t pattern_m; int16_t patterncount; int16_t Last_Resort; - int16_t numactive; /* keep the count of the frames inside current 600 frame block */ - float sum_of_rates; /* sum of the rates of past 600 active frames */ - float global_avr_rate; /* global rate up to current time. recorded a (rate in kbps) * 6000 */ - Word32 sum_of_rates_fx; /* sum of the rates of past 600 active frames*/ - Word32 global_avr_rate_fx; /* global rate upto current time. recorded a (rate in kbps) *6000*/ - int16_t global_frame_cnt; /* 600 active frame block count. Used to update the global rate */ + int16_t numactive; /* keep the count of the frames inside current 600 frame block */ + float sum_of_rates; /* sum of the rates of past 600 active frames */ + float global_avr_rate; /* global rate up to current time. recorded a (rate in kbps) * 6000 */ + Word32 sum_of_rates_fx; /* sum of the rates of past 600 active frames*/ + Word32 global_avr_rate_fx; /* global rate upto current time. recorded a (rate in kbps) *6000*/ + int16_t global_frame_cnt; /* 600 active frame block count. Used to update the global rate */ int16_t set_ppp_generic; int16_t avoid_HQ_VBR_NB; int16_t vbr_generic_ho; int16_t Local_VAD; int16_t last_7k2_coder_type; - Word16 frame_cnt_ratewin_fx; /* keep count of how many ratewin (600) windows */ + Word16 frame_cnt_ratewin_fx; /* keep count of how many ratewin (600) windows */ } SC_VBR_ENC_DATA, *SC_VBR_ENC_HANDLE; @@ -1232,7 +1232,7 @@ typedef struct sc_vbr_enc_structure typedef struct amrwb_io_enc_structure { - float past_qua_en[4]; /* gain quantization memory (used also in AMR-WB IO mode) */ + float past_qua_en[4]; /* gain quantization memory (used also in AMR-WB IO mode) */ Word16 past_qua_en_fx[4]; /* gain quantization memory (used also in AMR-WB IO mode) */ /* HF WB BWE for AMR-WB IO mode at 23.85 kbps */ @@ -1259,16 +1259,16 @@ typedef struct td_bwe_enc_structure float old_speech_shb[L_LOOK_16k + L_SUBFR16k]; /* Buffer memories */ float old_speech_wb[( L_LOOK_12k8 + L_SUBFR ) * 5 / 16]; /* Buffer memories */ float old_input_fhb[NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) - L_FRAME48k / 2]; - Word16 old_speech_shb_fx[L_LOOK_16k + L_SUBFR16k]; /* Buffer memories */ - Word16 old_speech_wb_fx[(L_LOOK_12k8 + L_SUBFR) * 5 / 16]; /* Buffer memories */ - Word16 old_input_fhb_fx[NS2SA(48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS) - L_FRAME48k / 2]; + Word16 old_speech_shb_fx[L_LOOK_16k + L_SUBFR16k]; /* Buffer memories */ + Word16 old_speech_wb_fx[( L_LOOK_12k8 + L_SUBFR ) * 5 / 16]; /* Buffer memories */ + Word16 old_input_fhb_fx[NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) - L_FRAME48k / 2]; Word16 old_input_fhb_fx_Q; float prev_lsp_shb[LPC_SHB_ORDER]; Word16 prev_lsp_shb_fx[LPC_SHB_ORDER]; float state_ana_filt_shb[2 * ALLPASSSECTIONS_STEEP + 1]; /* states for the analysis filters */ float cldfbHBLT_flt; - Word16 state_ana_filt_shb_fx[(2 * ALLPASSSECTIONS_STEEP + 1)]; + Word16 state_ana_filt_shb_fx[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; Word16 cldfbHBLT; /* states for the filters used in generating SHB excitation from WB excitation*/ float mem_csfilt[2]; @@ -1288,7 +1288,7 @@ typedef struct td_bwe_enc_structure float old_bwe_exc[PIT16k_MAX * 2]; /* old excitation */ Word16 state_syn_shbexc_fx[L_SHB_LAHEAD]; Word16 state_lpc_syn_fx[LPC_SHB_ORDER]; - Word16 old_bwe_exc_fx[PIT16k_MAX * 2]; /*Q_exc*/ + Word16 old_bwe_exc_fx[PIT16k_MAX * 2]; /*Q_exc*/ int16_t bwe_seed[2]; float bwe_non_lin_prev_scale; float old_bwe_exc_extended[NL_BUFF_OFFSET]; @@ -1298,14 +1298,14 @@ typedef struct td_bwe_enc_structure float mem_genSHBexc_filt_down_wb2[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; float mem_genSHBexc_filt_down_wb3[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; float mem_genSHBexc_filt_down_shb[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; - Word32 bwe_non_lin_prev_scale_fx; /*Q30*/ + Word32 bwe_non_lin_prev_scale_fx; /*Q30*/ Word16 old_bwe_exc_extended_fx[NL_BUFF_OFFSET]; Word16 syn_overlap_fx[L_SHB_LAHEAD]; - Word16 decim_state1_fx[(2 * ALLPASSSECTIONS_STEEP + 1)]; - Word16 decim_state2_fx[(2 * ALLPASSSECTIONS_STEEP + 1)]; - Word16 mem_genSHBexc_filt_down_wb2_fx[(2 * ALLPASSSECTIONS_STEEP + 1)]; - Word16 mem_genSHBexc_filt_down_wb3_fx[(2 * ALLPASSSECTIONS_STEEP + 1)]; - Word16 mem_genSHBexc_filt_down_shb_fx[(2 * ALLPASSSECTIONS_STEEP + 1)]; + Word16 decim_state1_fx[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; + Word16 decim_state2_fx[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; + Word16 mem_genSHBexc_filt_down_wb2_fx[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; + Word16 mem_genSHBexc_filt_down_wb3_fx[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; + Word16 mem_genSHBexc_filt_down_shb_fx[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; float elliptic_bpf_2_48k_mem[4][4]; float prev_fb_energy; @@ -1375,7 +1375,7 @@ typedef struct td_bwe_enc_structure Word16 tbe_demph_fx; Word16 tbe_premph_fx; Word16 mem_stp_swb_fx[LPC_SHB_ORDER]; - Word16* ptr_mem_stp_swb_fx; + Word16 *ptr_mem_stp_swb_fx; Word16 gain_prec_swb_fx; Word16 mem_zero_swb_fx[LPC_SHB_ORDER]; @@ -1395,11 +1395,11 @@ typedef struct fd_bwe_enc_structure float old_syn_12k8_16k[NS2SA( 16000, DELAY_FD_BWE_ENC_NS )]; float old_fdbwe_speech[L_FRAME48k]; float mem_deemph_old_syn; - Word16 new_input_hp_fx[NS2SA(16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS)]; - Word16 old_input_fx[NS2SA(48000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS)]; - Word16 old_input_wb_fx[NS2SA(16000, DELAY_FD_BWE_ENC_NS)]; - Word16 old_input_lp_fx[NS2SA(16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS)]; - Word16 old_syn_12k8_16k_fx[NS2SA(16000, DELAY_FD_BWE_ENC_NS)]; + Word16 new_input_hp_fx[NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS )]; + Word16 old_input_fx[NS2SA( 48000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS )]; + Word16 old_input_wb_fx[NS2SA( 16000, DELAY_FD_BWE_ENC_NS )]; + Word16 old_input_lp_fx[NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS )]; + Word16 old_syn_12k8_16k_fx[NS2SA( 16000, DELAY_FD_BWE_ENC_NS )]; Word16 old_fdbwe_speech_fx[L_FRAME48k]; Word16 mem_deemph_old_syn_fx; int16_t prev_mode; @@ -1494,23 +1494,23 @@ typedef struct plc_enc_evs_structure Word16 mem_MA_14Q1[M]; Word16 mem_AR[M]; - float lsfold[M]; /* old lsf (frequency domain) */ - float lspold[M]; /* old lsp (immittance spectral pairs) */ - Word16 lsfold_14Q1[M]; /* old lsf (frequency domain) */ - Word16 lspold_Q15[M]; /* old lsp (immittance spectral pairs) */ - - float lsfoldbfi0[M]; /* Previous frame lsf */ - float lsfoldbfi1[M]; /* Past previous frame lsf */ - Word16 lsfoldbfi0_14Q1[M]; /* Previous frame LSF */ - Word16 lsfoldbfi1_14Q1[M]; /* Past previous frame LSF */ - float lsf_adaptive_mean[M]; /* Mean lsf for bfi cases */ - Word16 lsf_adaptive_mean_14Q1[M]; /* Mean isf for bfi cases */ + float lsfold[M]; /* old lsf (frequency domain) */ + float lspold[M]; /* old lsp (immittance spectral pairs) */ + Word16 lsfold_14Q1[M]; /* old lsf (frequency domain) */ + Word16 lspold_Q15[M]; /* old lsp (immittance spectral pairs) */ + + float lsfoldbfi0[M]; /* Previous frame lsf */ + float lsfoldbfi1[M]; /* Past previous frame lsf */ + Word16 lsfoldbfi0_14Q1[M]; /* Previous frame LSF */ + Word16 lsfoldbfi1_14Q1[M]; /* Past previous frame LSF */ + float lsf_adaptive_mean[M]; /* Mean lsf for bfi cases */ + Word16 lsf_adaptive_mean_14Q1[M]; /* Mean isf for bfi cases */ float stab_fac; Word16 stab_fac_Q15; LPD_state *LPDmem; - float old_exc[8]; /* ACELP exc memory (Aq) */ - Word16 old_exc_Qold[8]; /* ACELP exc memory (Aq)*/ + float old_exc[8]; /* ACELP exc memory (Aq) */ + Word16 old_exc_Qold[8]; /* ACELP exc memory (Aq)*/ float lsf_con_flt[M]; float last_lsf_ref_flt[M]; @@ -1557,8 +1557,8 @@ typedef struct tcx_enc_structure float *spectrum[2]; /* MDCT output for a short block */ float spectrum_long[N_MAX]; /* MDCT output for a long block. Points to spectrum */ - float noiseTiltFactor_flt; /* compensation for LPC tilt in noise filling */ - Word16 noiseTiltFactor; /* compensation for LPC tilt in noise filling */ + float noiseTiltFactor_flt; /* compensation for LPC tilt in noise filling */ + Word16 noiseTiltFactor; /* compensation for LPC tilt in noise filling */ int16_t noiseLevelMemory_cnt; /* counter of consecutive low TCX noise levels */ float ltpGainMemory[N_LTP_GAIN_MEMS]; /* for smoothing noiseTransWidth */ STnsData tnsData[2]; @@ -1571,8 +1571,8 @@ typedef struct tcx_enc_structure float *speech_TCX_flt; float *new_speech_TCX_flt; - Word16* speech_TCX; - Word16* new_speech_TCX; + Word16 *speech_TCX; + Word16 *new_speech_TCX; int16_t tcxltp; int16_t tcxltp_pitch_int; @@ -1595,21 +1595,21 @@ typedef struct tcx_enc_structure float *speech_ltp_flt; float *new_speech_ltp_flt; Word16 buf_speech_ltp[L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k]; - Word16* speech_ltp; - Word16* new_speech_ltp; + Word16 *speech_ltp; + Word16 *new_speech_ltp; int16_t tcxltp_filt_idx; int16_t tcxltp_bits; int16_t tcxltp_param[LTPSIZE]; int16_t tcxltp_on_mem; float measuredBwRatio_flt; /* measured bw; used for TCX noise-filling */ - Word16 measuredBwRatio; /* measured bw; used for TCX noise-filling. 1Q14 */ - int16_t nmStartLine; /* Starting line for the noise measurement */ + Word16 measuredBwRatio; /* measured bw; used for TCX noise-filling. 1Q14 */ + int16_t nmStartLine; /* Starting line for the noise measurement */ int16_t tcx_lpc_shaped_ari; float old_out[L_FRAME32k]; - Word16 old_out_fx[L_FRAME32k]; /* buffer for OLA; at the encoder, the maximum length is L_FRAME32k (corresponds to maximum internal L_frame length) */ + Word16 old_out_fx[L_FRAME32k]; /* buffer for OLA; at the encoder, the maximum length is L_FRAME32k (corresponds to maximum internal L_frame length) */ Word16 Q_old_out; /* MDCT switching */ @@ -1619,9 +1619,9 @@ typedef struct tcx_enc_structure int16_t clas_final_old; float last_gain1_flt; float last_gain2_flt; - //Fix + // Fix Word16 prev_hi_ener; - Word16 clas_sec_old_fx; /* MDCT classifier secondary decision memory */ + Word16 clas_sec_old_fx; /* MDCT classifier secondary decision memory */ Word32 last_gain1; Word32 last_gain2; @@ -1629,12 +1629,12 @@ typedef struct tcx_enc_structure float Txnq_flt[L_FRAME32k / 2 + 64]; /* Q target (overlap or ACELP+ZIR, use Aq) */ float *acelp_zir_flt; float tcx_target_bits_fac_flt; - Word16 Txnq[L_FRAME32k / 2 + 64]; /* Q target (overlap or ACELP+ZIR, use Aq) */ - Word16* acelp_zir; + Word16 Txnq[L_FRAME32k / 2 + 64]; /* Q target (overlap or ACELP+ZIR, use Aq) */ + Word16 *acelp_zir; Word16 tcx_target_bits_fac; int16_t tns_ms_flag[2]; - Word32 *spectrum_fx[2]; /* MDCT output for a short block */ + Word32 *spectrum_fx[2]; /* MDCT output for a short block */ Word32 spectrum_long_fx[N_MAX]; /* MDCT output for a long block. Points to spectrum */ } TCX_ENC_DATA, *TCX_ENC_HANDLE; @@ -1660,13 +1660,13 @@ typedef struct enc_core_structure * Common parameters *----------------------------------------------------------------------------------*/ - Word16 idchan; /* channel ID (audio channel number) */ - Word16 id_element; /* element ID */ - int16_t element_mode; /* element mode */ - Word16 last_element_mode; /* element mode */ - int32_t element_brate; /* element bitrate */ - Word16 extl_orig; /* extension layer */ - Word32 extl_brate_orig; /* extension layer bitrate */ + Word16 idchan; /* channel ID (audio channel number) */ + Word16 id_element; /* element ID */ + int16_t element_mode; /* element mode */ + Word16 last_element_mode; /* element mode */ + int32_t element_brate; /* element bitrate */ + Word16 extl_orig; /* extension layer */ + Word32 extl_brate_orig; /* extension layer bitrate */ Word16 codec_mode; /* Mode1 or Mode2 */ Word16 last_codec_mode; /* previous frame Mode 1 or 2 */ Word16 last_codec_mode_cng; /* previous inactive frame Mode 1 or 2 */ @@ -1675,11 +1675,11 @@ typedef struct enc_core_structure Word16 mdct_sw_enable; /* MDCT switching enable flag */ Word16 mdct_sw; /* MDCT switching indicator */ - BSTR_ENC_HANDLE hBstr; /* encoder bitstream handle */ + BSTR_ENC_HANDLE hBstr; /* encoder bitstream handle */ Word16 last_enerBuffer_exp; int16_t bitstreamformat; /* Bitstream format flag (G.192/MIME) */ - Word16 next_bit_pos_fx; /* position of the next bit to be written in the bitstream */ + Word16 next_bit_pos_fx; /* position of the next bit to be written in the bitstream */ int32_t input_Fs; /* input signal sampling frequency in Hz */ int32_t total_brate; /* total bitrate in kbps of the codec */ @@ -1710,41 +1710,41 @@ typedef struct enc_core_structure int16_t last_Opt_SC_VBR; /* flag indicating prev frame's SC-VBR mode */ int16_t low_rate_mode; /* low-rate mode flag */ int16_t inactive_coder_type_flag; /* inactive coder type flag (0 = AVQ / 1 = GSC) */ - Word16 nTimeSlots; /* for CLDFB */ + Word16 nTimeSlots; /* for CLDFB */ Word16 ini_frame; /* initialization frames counter */ - //Word32 input_Fs_fx; /* input signal sampling frequency in Hz */ - //Word32 total_brate_fx; /* total bitrate in kbps of the codec */ - //Word32 last_total_brate_fx; /* total bitrate in kbps of the codec */ - //Word32 last_total_brate_cng_fx; /* total bitrate in kbps of the last inactive frame */ - //Word16 core_fx; /* core (ACELP_CORE, TCX_20_CORE, TCX_10_CORE, HQ_CORE, AMR_WB_CORE) */ - //Word32 core_brate_fx; /* core bitrate */ - //Word32 last_core_brate_fx; /* previous frame core bitrate */ - Word16 input_frame_fx; /* Frame lenght (function of input_Fs) */ - //Word16 extl_fx; /* extension layer */ - //Word16 last_extl_fx; /* previous extension layer */ - //Word32 extl_brate_fx; /* extension layer bitrate */ - //Word16 input_bwidth_fx; /* input signal bandwidth */ - //Word16 last_input_bwidth_fx; /* input signal bandwidth in the previous frame */ - //Word16 bwidth_fx; /* encoded bandwidth NB, WB, SWB or FB */ - //Word16 max_bwidth_fx; /* maximum encoded bandwidth */ - //Word16 last_bwidth_fx; /* input signal bandwidth in the previous frame */ - //Word16 last_bwidth_cng_fx; /* input signal bandwidth in the previous inactive frame */ - //Word16 L_frame_fx; /* ACELP core internal frame length */ - //Word16 Opt_AMR_WB; /* flag indicating AMR-WB IO mode */ - //Word16 Opt_DTX_ON_fx; /* flag indicating DTX operation */ - //Word16 cng_type; /* flag indicating LP or CLDFB based SID/CNG */ - Word16 active_fr_cnt_fx; /* counter of active frames */ - //Word16 Opt_SC_VBR_fx; /* flag indicating SC-VBR mode */ - //Word16 last_Opt_SC_VBR_fx; /* flag indicating SC-VBR mode in the last frame */ + // Word32 input_Fs_fx; /* input signal sampling frequency in Hz */ + // Word32 total_brate_fx; /* total bitrate in kbps of the codec */ + // Word32 last_total_brate_fx; /* total bitrate in kbps of the codec */ + // Word32 last_total_brate_cng_fx; /* total bitrate in kbps of the last inactive frame */ + // Word16 core_fx; /* core (ACELP_CORE, TCX_20_CORE, TCX_10_CORE, HQ_CORE, AMR_WB_CORE) */ + // Word32 core_brate_fx; /* core bitrate */ + // Word32 last_core_brate_fx; /* previous frame core bitrate */ + Word16 input_frame_fx; /* Frame lenght (function of input_Fs) */ + // Word16 extl_fx; /* extension layer */ + // Word16 last_extl_fx; /* previous extension layer */ + // Word32 extl_brate_fx; /* extension layer bitrate */ + // Word16 input_bwidth_fx; /* input signal bandwidth */ + // Word16 last_input_bwidth_fx; /* input signal bandwidth in the previous frame */ + // Word16 bwidth_fx; /* encoded bandwidth NB, WB, SWB or FB */ + // Word16 max_bwidth_fx; /* maximum encoded bandwidth */ + // Word16 last_bwidth_fx; /* input signal bandwidth in the previous frame */ + // Word16 last_bwidth_cng_fx; /* input signal bandwidth in the previous inactive frame */ + // Word16 L_frame_fx; /* ACELP core internal frame length */ + // Word16 Opt_AMR_WB; /* flag indicating AMR-WB IO mode */ + // Word16 Opt_DTX_ON_fx; /* flag indicating DTX operation */ + // Word16 cng_type; /* flag indicating LP or CLDFB based SID/CNG */ + Word16 active_fr_cnt_fx; /* counter of active frames */ + // Word16 Opt_SC_VBR_fx; /* flag indicating SC-VBR mode */ + // Word16 last_Opt_SC_VBR_fx; /* flag indicating SC-VBR mode in the last frame */ /*----------------------------------------------------------------------------------* * ACELP core parameters *----------------------------------------------------------------------------------*/ - int16_t clas; /* current frame clas */ - int16_t last_clas; /* previous frame signal classification */ + int16_t clas; /* current frame clas */ + int16_t last_clas; /* previous frame signal classification */ float prev_fmerit_flt; /* previous signal classification score*/ float fmerit_dt_flt; /* signal classification score difference */ Word16 prev_fmerit; @@ -1758,23 +1758,23 @@ typedef struct enc_core_structure LPD_state_HANDLE hLPDmem; /* ACELP LPDmem memories */ - float Bin_E[L_FFT]; /* per bin energy of two frames */ - float lsp_old1[M]; /* old unquantized LSP vector at the end of the frame at 12k8 */ - float lsf_old1[M]; /* old unquantized LSF vector at the end of the frame at 12k8 */ - float lsp_old[M]; /* old LSP vector at the end of the frame */ - float lsf_old[M]; /* old LSF vector at the end of the frame */ - float lsp_old16k[M]; /* old LSP vector at the end of the frame @16kHz */ - float lspold_enc[M]; /* old lsp (immittance spectral pairs) */ - Word32 Bin_E_fx[L_FFT]; /* Q_new + Q_SCALE -2 per bin energy of two frames */ - Word16 lsp_old1_fx[M]; /* old unquantized LSP vector at the end of the frame */ - Word16 lsf_old1_fx[M]; /* old LSF vector at the end of the frame */ - Word16 lsp_old_fx[M]; /* old LSP vector at the end of the frame */ - Word16 lsf_old_fx[M]; /* old LSF vector at the end of the frame */ - Word16 lsp_old16k_fx[M]; /* old LSP vector at the end of the frame @16kHz */ - Word16 lspold_enc_fx[M]; /* old LSP vector at the end of the frame @16kHz */ - - int16_t pstreaklen; /* LSF quantizer */ - + float Bin_E[L_FFT]; /* per bin energy of two frames */ + float lsp_old1[M]; /* old unquantized LSP vector at the end of the frame at 12k8 */ + float lsf_old1[M]; /* old unquantized LSF vector at the end of the frame at 12k8 */ + float lsp_old[M]; /* old LSP vector at the end of the frame */ + float lsf_old[M]; /* old LSF vector at the end of the frame */ + float lsp_old16k[M]; /* old LSP vector at the end of the frame @16kHz */ + float lspold_enc[M]; /* old lsp (immittance spectral pairs) */ + Word32 Bin_E_fx[L_FFT]; /* Q_new + Q_SCALE -2 per bin energy of two frames */ + Word16 lsp_old1_fx[M]; /* old unquantized LSP vector at the end of the frame */ + Word16 lsf_old1_fx[M]; /* old LSF vector at the end of the frame */ + Word16 lsp_old_fx[M]; /* old LSP vector at the end of the frame */ + Word16 lsf_old_fx[M]; /* old LSF vector at the end of the frame */ + Word16 lsp_old16k_fx[M]; /* old LSP vector at the end of the frame @16kHz */ + Word16 lspold_enc_fx[M]; /* old LSP vector at the end of the frame @16kHz */ + + int16_t pstreaklen; /* LSF quantizer */ + float streaklimit; /* LSF quantizer */ float stab_fac; /* LSF stability factor */ float mem_preemph; /* preemphasis filter memory */ @@ -1783,104 +1783,105 @@ typedef struct enc_core_structure float mem_wsp; /* weighted signal vector memory */ float mem_decim2[3]; /* weighted signal decimation filter memory */ - float clip_var[6]; /* pitch gain clipping memory */ - float mem_AR[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean) */ - float mem_MA[M]; /* MA memory of LSF quantizer (past quantized residual) (used also in AMR-WB IO mode) */ - Word16 pstreaklen_fx; /* LSF quantizer */ - Word16 streaklimit_fx; /* LSF quantizer */ - Word32 offset_scale1_fx[MAX_NO_MODES + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure 1st 8-dim subvector*/ - Word32 offset_scale2_fx[MAX_NO_MODES + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure 2nd 8-dim subvector*/ + float clip_var[6]; /* pitch gain clipping memory */ + float mem_AR[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean) */ + float mem_MA[M]; /* MA memory of LSF quantizer (past quantized residual) (used also in AMR-WB IO mode) */ + Word16 pstreaklen_fx; /* LSF quantizer */ + Word16 streaklimit_fx; /* LSF quantizer */ + Word32 offset_scale1_fx[MAX_NO_MODES + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure 1st 8-dim subvector*/ + Word32 offset_scale2_fx[MAX_NO_MODES + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure 2nd 8-dim subvector*/ Word32 offset_scale1_p_fx[MAX_NO_MODES_p + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure, pred. case, 1st 8-dim subvector*/ Word32 offset_scale2_p_fx[MAX_NO_MODES_p + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure, pred. case, 2nd 8-dim subvector*/ - Word16 no_scales_fx[MAX_NO_MODES][2]; /* LSF LVQ structure Q0*/ - Word16 no_scales_p_fx[MAX_NO_MODES_p][2]; /* LSF LVQ structure Q0*/ - Word16 stab_fac_fx; /* LSF stability factor */ - Word16 mem_deemph_fx; /* deemphasis filter memory */ - Word16 mem_preemph_fx; /* preemphasis filter memory */ - Word32 mem_hp20_in_fx[5]; /* HP filter memory for AMR-WB IO */ - Word16 old_wsp_fx[L_WSP_MEM]; /* old weighted signal vector */ - /*Word16 old_exc_fx[L_EXC_MEM];*/ /* old excitation vector */ - Word16 old_wsp2_fx[(L_WSP_MEM - L_INTERPOL) / OPL_DECIM]; /* old decimated weighted signal vector qwsp */ - Word16 mem_wsp_fx; /* weighted signal vector memory */ - Word16 mem_decim2_fx[3]; /* weighted signal decimation filter memory qwsp */ + Word16 no_scales_fx[MAX_NO_MODES][2]; /* LSF LVQ structure Q0*/ + Word16 no_scales_p_fx[MAX_NO_MODES_p][2]; /* LSF LVQ structure Q0*/ + Word16 stab_fac_fx; /* LSF stability factor */ + Word16 mem_deemph_fx; /* deemphasis filter memory */ + Word16 mem_preemph_fx; /* preemphasis filter memory */ + Word32 mem_hp20_in_fx[5]; /* HP filter memory for AMR-WB IO */ + Word16 old_wsp_fx[L_WSP_MEM]; /* old weighted signal vector */ + /*Word16 old_exc_fx[L_EXC_MEM];*/ /* old excitation vector */ + Word16 old_wsp2_fx[( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM]; /* old decimated weighted signal vector qwsp */ + Word16 mem_wsp_fx; /* weighted signal vector memory */ + Word16 mem_decim2_fx[3]; /* weighted signal decimation filter memory qwsp */ Word16 clip_var_fx[6]; - Word16 mem_AR_fx[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean) */ - Word16 mem_MA_fx[M]; /* MA memory of LSF quantizer (past quantized residual) (used also in AMR-WB IO mode) */ - Word16 mCb1_fx; /* LSF quantizer - counter of stationary frames after a transition frame */ + Word16 mem_AR_fx[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean) */ + Word16 mem_MA_fx[M]; /* MA memory of LSF quantizer (past quantized residual) (used also in AMR-WB IO mode) */ + Word16 mCb1_fx; /* LSF quantizer - counter of stationary frames after a transition frame */ int16_t GSC_noisy_speech; /* AC mode (GSC) - flag to indicate GSC on SWB noisy speech */ int16_t GSC_IVAS_mode; GSC_ENC_HANDLE hGSCEnc; - int16_t Last_pulse_pos; /* FEC - last position of the first glottal pulse in the frame */ - float lsfoldbfi0[M]; /* FEC - LSF vector of the previous frame */ - float lsfoldbfi1[M]; /* FEC - LSF vector of the past previous frame */ - float lsf_adaptive_mean[M]; /* FEC - adaptive mean LSF vector for FEC */ - Word16 lsfoldbfi0_fx[M]; /* FEC - LSF vector of the previous frame */ - Word16 lsfoldbfi1_fx[M]; /* FEC - LSF vector of the past previous frame */ - Word16 lsf_adaptive_mean_fx[M]; /* FEC - adaptive mean LSF vector for FEC */ - int16_t next_force_safety_net; /* FEC - flag to force safety net in next frame */ - Word16 next_force_safety_net_fx; /* FEC - flag to force safety net in next frame */ - - int16_t uv_count; /* Stationary noise UV modification - unvoiced counter */ - int16_t act_count; /* Stationary noise UV modification - activation counter */ - float ge_sm; /* Stationary noise UV modification - smoothed excitation gain */ - float lspold_s[M]; /* Stationary noise UV modification - old LSP vector */ - Word32 ge_sm_fx; /* Stationary noise UV modification - smoothed excitation gain */ - Word16 lspold_s_fx[M]; /*Q15*/ /* Stationary noise UV modification - old LSP vector */ - int16_t noimix_seed; /* Stationary noise UV modification - mixture seed */ - float min_alpha; /* Stationary noise UV modification - minimum alpha */ - float exc_pe; /* Stationary noise UV modification - memory of the preemphasis filter */ - Word16 min_alpha_fx; /*Q15*/ /* Stationary noise UV modification - minimum alpha */ - Word16 exc_pe_fx; /* Stationary noise UV modification - memory of the preemphasis filter */ - - int16_t coder_type_raw; /* raw coder_type (before UNVOICED is lost) */ - int16_t last_coder_type_raw; /* raw last_coder_type (coming from the sigal classification) */ - int16_t last_coder_type; /* previous coding type */ - float old_thres; /* normalized correlation weighting in open-loop pitch */ - float old_corr; /* normalized correlation in previous frame (mean value) */ - Word16 old_thres_fx; /* normalized correlation weighting in open-loop pitch Q15 */ - Word16 old_corr_fx; /* normalized correlation in previous frame (mean value) Q15 */ int16_t old_pitch; /* previous pitch for open-loop pitch search */ - int16_t delta_pit; /* open-loop pitch extrapolation correction */ - float ee_old; /* previous frame low/high frequency energy ratio */ + int16_t Last_pulse_pos; /* FEC - last position of the first glottal pulse in the frame */ + float lsfoldbfi0[M]; /* FEC - LSF vector of the previous frame */ + float lsfoldbfi1[M]; /* FEC - LSF vector of the past previous frame */ + float lsf_adaptive_mean[M]; /* FEC - adaptive mean LSF vector for FEC */ + Word16 lsfoldbfi0_fx[M]; /* FEC - LSF vector of the previous frame */ + Word16 lsfoldbfi1_fx[M]; /* FEC - LSF vector of the past previous frame */ + Word16 lsf_adaptive_mean_fx[M]; /* FEC - adaptive mean LSF vector for FEC */ + int16_t next_force_safety_net; /* FEC - flag to force safety net in next frame */ + Word16 next_force_safety_net_fx; /* FEC - flag to force safety net in next frame */ + + int16_t uv_count; /* Stationary noise UV modification - unvoiced counter */ + int16_t act_count; /* Stationary noise UV modification - activation counter */ + float ge_sm; /* Stationary noise UV modification - smoothed excitation gain */ + float lspold_s[M]; /* Stationary noise UV modification - old LSP vector */ + Word32 ge_sm_fx; /* Stationary noise UV modification - smoothed excitation gain */ + Word16 lspold_s_fx[M]; /*Q15*/ /* Stationary noise UV modification - old LSP vector */ + int16_t noimix_seed; /* Stationary noise UV modification - mixture seed */ + float min_alpha; /* Stationary noise UV modification - minimum alpha */ + float exc_pe; /* Stationary noise UV modification - memory of the preemphasis filter */ + Word16 min_alpha_fx; /*Q15*/ /* Stationary noise UV modification - minimum alpha */ + Word16 exc_pe_fx; /* Stationary noise UV modification - memory of the preemphasis filter */ + + int16_t coder_type_raw; /* raw coder_type (before UNVOICED is lost) */ + int16_t last_coder_type_raw; /* raw last_coder_type (coming from the sigal classification) */ + int16_t last_coder_type; /* previous coding type */ + float old_thres; /* normalized correlation weighting in open-loop pitch */ + float old_corr; /* normalized correlation in previous frame (mean value) */ + Word16 old_thres_fx; /* normalized correlation weighting in open-loop pitch Q15 */ + Word16 old_corr_fx; /* normalized correlation in previous frame (mean value) Q15 */ + int16_t old_pitch; /* previous pitch for open-loop pitch search */ + int16_t delta_pit; /* open-loop pitch extrapolation correction */ + float ee_old; /* previous frame low/high frequency energy ratio */ Word32 ee_old_fx; - int16_t min_band; /* minimum critical band of useful bandwidth */ - int16_t max_band; /* maximum critical band of useful bandwidth */ - int16_t tc_cnt; /* TC frame counter */ - int16_t audio_frame_cnt; /* Counter of relative presence of audio frames */ - float old_dE1; /* Maximum energy increase in previous frame */ - Word32 old_dE1_fx; /* Maximum energy increase in previous frame */ - int16_t old_ind_deltaMax; /* Index of the sub-subframe of maximum energy in previous frame */ - float old_enr_ssf[2 * NB_SSF]; /* Maxima of energies per sub-subframes of previous frame */ - Word32 old_enr_ssf_fx[2 * NB_SSF]; /* Maxima of energies per sub-subframes of previous frame */ - int16_t spike_hyst; /* Hysteresis to prevent UC after sharp energy spike */ - int16_t last_harm_flag_acelp; /* harmonicity flag for ACELP @32kbps rate */ - float old_Aq_12_8[M + 1]; /* old Aq[] for core switching */ - float old_Es_pred; /* old Es_pred for core switching */ - Word16 old_Aq_12_8_fx[M + 1]; /* Q12 old Aq[] for core switching */ - Word16 old_Es_pred_fx; /* Q8 old Es_pred for core switching */ - Word16 music_hysteresis_fx; /* Counter of frames after AUDIO coding mode to prevent UC */ + int16_t min_band; /* minimum critical band of useful bandwidth */ + int16_t max_band; /* maximum critical band of useful bandwidth */ + int16_t tc_cnt; /* TC frame counter */ + int16_t audio_frame_cnt; /* Counter of relative presence of audio frames */ + float old_dE1; /* Maximum energy increase in previous frame */ + Word32 old_dE1_fx; /* Maximum energy increase in previous frame */ + int16_t old_ind_deltaMax; /* Index of the sub-subframe of maximum energy in previous frame */ + float old_enr_ssf[2 * NB_SSF]; /* Maxima of energies per sub-subframes of previous frame */ + Word32 old_enr_ssf_fx[2 * NB_SSF]; /* Maxima of energies per sub-subframes of previous frame */ + int16_t spike_hyst; /* Hysteresis to prevent UC after sharp energy spike */ + int16_t last_harm_flag_acelp; /* harmonicity flag for ACELP @32kbps rate */ + float old_Aq_12_8[M + 1]; /* old Aq[] for core switching */ + float old_Es_pred; /* old Es_pred for core switching */ + Word16 old_Aq_12_8_fx[M + 1]; /* Q12 old Aq[] for core switching */ + Word16 old_Es_pred_fx; /* Q8 old Es_pred for core switching */ + Word16 music_hysteresis_fx; /* Counter of frames after AUDIO coding mode to prevent UC */ Word16 last_vad_spa_fx; - Word16 last_L_frame; /* ACELP@16kHz - last L_frame value */ - float mem_preemph16k; /* ACELP@16kHz - preemphasis filter memory @16kHz */ - float mem_deemp_preQ; /* ACELP@16kHz - prequantizer deemhasis memory */ - float mem_preemp_preQ; /* ACELP@16kHz - prequantizer preemhasis memory */ - Word16 mem_preemph16k_fx; /* ACELP@16kHz - preemphasis filter memory @16kHz */ - Word16 mem_deemp_preQ_fx; /* ACELP@16kHz - prequantizer deemhasis memory */ - Word16 mem_preemp_preQ_fx; /* ACELP@16kHz - prequantizer preemhasis memory */ - Word16 last_nq_preQ; /* ACELP@16kHz - AVQ subquantizer number of the last sub-band of the last subframe */ - Word16 last_code_preq; /* ACELP@16kHz - last coefficient of the pre-quantizer contribution */ - Word16 use_acelp_preq; /* ACELP@16kHz - flag of prequantizer usage */ - - Word16 bpf_off; /* Bass post-filter - do not use BPF when this flag is set to 1 */ - float old_pitch_buf[2 * NB_SUBFR16k]; /* Bass post-filter - buffer of old subframe pitch values */ - Word16 old_pitch_buf_fx[2 * NB_SUBFR16k]; /*Q6 Bass post-filter - buffer of old subframe pitch values */ - float pst_mem_deemp_err; /* Bass post-filter - filter memory of noise LP filter */ + Word16 last_L_frame; /* ACELP@16kHz - last L_frame value */ + float mem_preemph16k; /* ACELP@16kHz - preemphasis filter memory @16kHz */ + float mem_deemp_preQ; /* ACELP@16kHz - prequantizer deemhasis memory */ + float mem_preemp_preQ; /* ACELP@16kHz - prequantizer preemhasis memory */ + Word16 mem_preemph16k_fx; /* ACELP@16kHz - preemphasis filter memory @16kHz */ + Word16 mem_deemp_preQ_fx; /* ACELP@16kHz - prequantizer deemhasis memory */ + Word16 mem_preemp_preQ_fx; /* ACELP@16kHz - prequantizer preemhasis memory */ + Word16 last_nq_preQ; /* ACELP@16kHz - AVQ subquantizer number of the last sub-band of the last subframe */ + Word16 last_code_preq; /* ACELP@16kHz - last coefficient of the pre-quantizer contribution */ + Word16 use_acelp_preq; /* ACELP@16kHz - flag of prequantizer usage */ + + Word16 bpf_off; /* Bass post-filter - do not use BPF when this flag is set to 1 */ + float old_pitch_buf[2 * NB_SUBFR16k]; /* Bass post-filter - buffer of old subframe pitch values */ + Word16 old_pitch_buf_fx[2 * NB_SUBFR16k]; /*Q6 Bass post-filter - buffer of old subframe pitch values */ + float pst_mem_deemp_err; /* Bass post-filter - filter memory of noise LP filter */ Word16 pst_mem_deemp_err_fx; /* Bass post-filter - filter memory of noise LP filter */ - float pst_lp_ener; /* Bass post-filter - long-term energy */ + float pst_lp_ener; /* Bass post-filter - long-term energy */ Word16 pst_lp_ener_fx; /* Bass post-filter - long-term energy */ /* stable short pitch detection */ @@ -1897,9 +1898,9 @@ typedef struct enc_core_structure Word32 energy_sm_fx; Word16 finalVAD; - int16_t flag_noisy_speech_snr; /* encoder detector for noisy speech */ - Word8 flag_noisy_speech_snr_fx; /*encoder detector for noisy speech*/ - int16_t Pos_relE_cnt; /* Number of frames between relE */ + int16_t flag_noisy_speech_snr; /* encoder detector for noisy speech */ + Word8 flag_noisy_speech_snr_fx; /*encoder detector for noisy speech*/ + int16_t Pos_relE_cnt; /* Number of frames between relE */ int16_t tdm_pc; /* pitch stability - used in TD stereo */ @@ -1911,9 +1912,9 @@ typedef struct enc_core_structure float *input; float *old_input_signal; - Word16* input_buff_fx; - Word16 * input_fx; - Word16 * old_input_signal_fx; + Word16 *input_buff_fx; + Word16 *input_fx; + Word16 *old_input_signal_fx; Word16 Q_old_wtda; SIGNAL_BUFFERS_ENC_HANDLE hSignalBuf; @@ -1927,16 +1928,16 @@ typedef struct enc_core_structure float *buf_synth_flt; /*can be reduced to PIT_MAX_MAX+L_FRAME_MAX if no rate switching*/ float *buf_speech_enc_flt; float *buf_wspeech_enc_flt; - Word32* Bin_E_old_fx; /* per bin energy of old 2nd frames */ - Word16* mem_decim_fx; /* decimation filter memory */ - Word16* mem_decim16k_fx; /* ACELP@16kHz - decimation filter memory @16kHz */ - Word16* old_inp_12k8_fx; /* memory of input signal at 12.8kHz */ - Word16* old_inp_16k_fx; /* ACELP@16kHz - memory of input signal @16 kHz */ + Word32 *Bin_E_old_fx; /* per bin energy of old 2nd frames */ + Word16 *mem_decim_fx; /* decimation filter memory */ + Word16 *mem_decim16k_fx; /* ACELP@16kHz - decimation filter memory @16kHz */ + Word16 *old_inp_12k8_fx; /* memory of input signal at 12.8kHz */ + Word16 *old_inp_16k_fx; /* ACELP@16kHz - memory of input signal @16 kHz */ - Word16* buf_speech_enc_pe; - Word16* buf_synth; /*can be reduced to PIT_MAX_MAX+L_FRAME_MAX if no rate switching*/ - Word16* buf_speech_enc; - Word16* buf_wspeech_enc; + Word16 *buf_speech_enc_pe; + Word16 *buf_synth; /*can be reduced to PIT_MAX_MAX+L_FRAME_MAX if no rate switching*/ + Word16 *buf_speech_enc; + Word16 *buf_wspeech_enc; /*----------------------------------------------------------------------------------* * Noise estimation @@ -1950,7 +1951,7 @@ typedef struct enc_core_structure SP_MUS_CLAS_HANDLE hSpMusClas; - Word16 lgBin_E_fx[L_FFT / 2]; /* Q8 per bin energy of two frames */ + Word16 lgBin_E_fx[L_FFT / 2]; /* Q8 per bin energy of two frames */ int16_t sp_aud_decision0; /* 1st stage speech/music decision flag */ int16_t sp_aud_decision1; /* 1st stage speech/music classification flag */ @@ -1972,13 +1973,13 @@ typedef struct enc_core_structure float bckr_tilt_lt_flt; float lp_speech; - float lp_noise; /* CNG and DTX - LP filtered total noise estimation */ + float lp_noise; /* CNG and DTX - LP filtered total noise estimation */ Word16 lp_speech_fx; Word16 Opt_HE_SAD_ON_fx; Word16 nb_active_frames_HE_SAD_fx; Word16 voicing_old_fx; - Word16 lp_noise_fx; /* CNG and DTX - LP filtered total noise estimation */ - Word16 var_SID_rate_flag_fx; /* CNG and DTX - flag for variable SID rate */ + Word16 lp_noise_fx; /* CNG and DTX - LP filtered total noise estimation */ + Word16 var_SID_rate_flag_fx; /* CNG and DTX - flag for variable SID rate */ Word16 interval_SID_fx; Word32 bckr_tilt_lt; int16_t active_cnt; /* counter of active frames */ @@ -1999,9 +2000,9 @@ typedef struct enc_core_structure HANDLE_CLDFB_FILTER_BANK cldfbAnaEnc; /* main analysis filter bank handle */ HANDLE_CLDFB_FILTER_BANK cldfbSynTd; /* synthesis filterbank - used for HB signal generation */ - //HANDLE_CLDFB_FILTER_BANK cldfbAna_Fx; + // HANDLE_CLDFB_FILTER_BANK cldfbAna_Fx; - //HANDLE_CLDFB_FILTER_BANK cldfbSyn_Fx; + // HANDLE_CLDFB_FILTER_BANK cldfbSyn_Fx; /*----------------------------------------------------------------------------------* * FD CNG handle @@ -2012,7 +2013,7 @@ typedef struct enc_core_structure float last_totalNoise; float totalNoise_increase_hist[TOTALNOISE_HIST_SIZE]; Word16 last_totalNoise_fx; - Word16 totalNoise_increase_hist_fx[TOTALNOISE_HIST_SIZE]; + Word16 totalNoise_increase_hist_fx[TOTALNOISE_HIST_SIZE]; int16_t totalNoise_increase_len; /*----------------------------------------------------------------------------------* @@ -2104,16 +2105,16 @@ typedef struct enc_core_structure Word32 sr_core; /*ACELP config*/ - ACELP_config acelp_cfg; /*configuration set for each frame*/ + ACELP_config acelp_cfg; /*configuration set for each frame*/ ACELP_config acelp_cfg_rf; /* configuration for RF frame */ - Word16 mode_index; /* Mode Index for LPD core */ + Word16 mode_index; /* Mode Index for LPD core */ /*TCX config*/ TCX_CONFIG_HANDLE hTcxCfg; /* cod_main.c */ float mem_preemph_enc_flt; /* speech preemph filter memory (at encoder-sampling-rate) */ - Word16 mem_preemph_enc; /* speech preemph filter memory (at encoder-sampling-rate) */ + Word16 mem_preemph_enc; /* speech preemph filter memory (at encoder-sampling-rate) */ /* Signal Buffers and Pointers at encoder-sampling-rate */ float *speech_enc_flt; @@ -2137,14 +2138,14 @@ typedef struct enc_core_structure int16_t tcx20Enabled; /* Flag indicating if TCX 20 can be used */ float mem_wsp_enc_flt; /* wsp vector memory */ - Word16 mem_wsp_enc; /* wsp vector memory */ + Word16 mem_wsp_enc; /* wsp vector memory */ int16_t nb_bits_header_ace; /* number of bits for the header */ int16_t nb_bits_header_tcx; /* number of bits for the header */ float preemph_fac_flt; /* Preemphasis factor */ float gamma_flt; - Word16 preemph_fac; /*Preemphasis factor*/ + Word16 preemph_fac; /*Preemphasis factor*/ Word16 gamma; Word16 inv_gamma; @@ -2159,7 +2160,7 @@ typedef struct enc_core_structure float prevEnergyHF; float currEnergyHF; float currEnergyLookAhead; - Word32 currEnergyLookAhead_fx; //Q31 + Word32 currEnergyLookAhead_fx; // Q31 Word32 prevEnergyHF_fx; Word32 currEnergyHF_fx; Word16 currEnergyHF_e_fx; /* exponent of currEnergyHF and prevEnergyHF */ @@ -2171,17 +2172,17 @@ typedef struct enc_core_structure Word16 parcorr_mid[2]; int16_t lpcQuantization; - Word16 numlpc; + Word16 numlpc; int16_t encoderLookahead_enc; int16_t encoderPastSamples_enc; int16_t encoderLookahead_FB; /* pitch_ol for adaptive lag window */ - int16_t old_pitch_la; /* past open loop pitch lag from look-ahead before very short stable pitch detection */ - Word16 old_voicing_la; /* past open loop pitch gain from look-ahead */ + int16_t old_pitch_la; /* past open loop pitch lag from look-ahead before very short stable pitch detection */ + Word16 old_voicing_la; /* past open loop pitch gain from look-ahead */ - Word32 band_energies[2 * NB_BANDS]; /* energy in critical bands without minimum noise floor MODE2_E_MIN */ - Word16 band_energies_exp; /* exponent for energy in critical bands without minimum noise floor MODE2_E_MIN */ + Word32 band_energies[2 * NB_BANDS]; /* energy in critical bands without minimum noise floor MODE2_E_MIN */ + Word16 band_energies_exp; /* exponent for energy in critical bands without minimum noise floor MODE2_E_MIN */ int16_t acelp_autocorr; /* Optimize acelp in 0 covariance or 1 correlation domain */ @@ -2258,7 +2259,7 @@ typedef struct enc_core_structure *---------------------------------------------------------------*/ int16_t tdm_LRTD_flag; /* LRTD stereo mode flag */ - Word16 cna_dirac_flag; /* CNA in DirAC flag */ + Word16 cna_dirac_flag; /* CNA in DirAC flag */ /* stereo switching memories */ float mem_preemph_DFT; @@ -2277,563 +2278,563 @@ typedef struct enc_core_structure Word16 is_ism_format; /* Indication whether the codec operates in ISM format */ Word16 dtx_sce_sba; /* enable use of FD CNG with transform domain cores in SCE SBA */ - /*----------------------------------------------------------------------------------* - * Fixed point only variables - *----------------------------------------------------------------------------------*/ - - Word16 last_ener_fx; /* AC mode (GSC) - previous energy */ - - Word16 prev_Q_bwe_exc; - Word16 prev_Q_bwe_syn; - Word16 Q_stat_noise_ge; - Word16 Q_stat_noise; - Word16 Q_syn2; - Word16 Q_syn; - Word16 Q_max[L_Q_MEM]; - Word16 Q_max_16k[L_Q_MEM]; - Word16 Q_old; - Word16 prev_Q_old; - Word16 old_wsp_max; /* Last weigthed speech maximal value */ - Word16 old_wsp_shift; /* Last wsp scaling */ - Word16 prev_Q_new; - Word16 prev_Q_shb; - Word16 Q_max_enc[2]; - - Word16 EnergyLT_fx_exp; - Word16 prev_lsp_wb_fx[LPC_SHB_ORDER_WB]; - Word16 prev_lpc_wb_fx[LPC_SHB_ORDER_WB]; - Word16 prev_lsp_wb_temp_fx[LPC_SHB_ORDER_WB]; + /*----------------------------------------------------------------------------------* + * Fixed point only variables + *----------------------------------------------------------------------------------*/ + + Word16 last_ener_fx; /* AC mode (GSC) - previous energy */ + + Word16 prev_Q_bwe_exc; + Word16 prev_Q_bwe_syn; + Word16 Q_stat_noise_ge; + Word16 Q_stat_noise; + Word16 Q_syn2; + Word16 Q_syn; + Word16 Q_max[L_Q_MEM]; + Word16 Q_max_16k[L_Q_MEM]; + Word16 Q_old; + Word16 prev_Q_old; + Word16 old_wsp_max; /* Last weigthed speech maximal value */ + Word16 old_wsp_shift; /* Last wsp scaling */ + Word16 prev_Q_new; + Word16 prev_Q_shb; + Word16 Q_max_enc[2]; + + Word16 EnergyLT_fx_exp; + Word16 prev_lsp_wb_fx[LPC_SHB_ORDER_WB]; + Word16 prev_lpc_wb_fx[LPC_SHB_ORDER_WB]; + Word16 prev_lsp_wb_temp_fx[LPC_SHB_ORDER_WB]; int16_t sba_br_sw_while_no_data; /* Indicator for SBA bitrate switch while in FRAME_NO_DATA mode */ } Encoder_State, *ENC_CORE_HANDLE; -//typedef struct Encoder_State_fx +// typedef struct Encoder_State_fx //{ // -// /*----------------------------------------------------------------------------------* -// * Common parameters -// *----------------------------------------------------------------------------------*/ // /*----------------------------------------------------------------------------------* -// * Stereo/IVAS parameters +// * Common parameters // *----------------------------------------------------------------------------------*/ -// Word16 flag_ACELP16k; /* flag indicating use of ACELP core at 16kHz internal sampling rate */ +// /*----------------------------------------------------------------------------------* +// * Stereo/IVAS parameters +// *----------------------------------------------------------------------------------*/ +// Word16 flag_ACELP16k; /* flag indicating use of ACELP core at 16kHz internal sampling rate */ +// +// Word16 tdm_LRTD_flag; /* LRTD stereo mode flag */ +// Word16 cna_dirac_flag; /* CNA in DirAC flag */ +// Word16 cng_sba_flag; /* CNG in SBA flag */ +// Word16 idchan; /* channel ID (audio channel number) */ +// Word16 element_mode; /* element mode */ +// Word16 last_element_mode; /* element mode */ +// Word16 low_rate_mode; /* low-rate mode flag */ +// MCT_CHAN_MODE mct_chan_mode; +// Word16 GSC_IVAS_mode; +// Word16 is_ism_format; /* Indication whether the codec operates in ISM format */ +// Word16 dtx_sce_sba; /* enable use of FD CNG with transform domain cores in SCE SBA */ +// +// +// //#ifdef IVAS_CODE // -// Word16 tdm_LRTD_flag; /* LRTD stereo mode flag */ -// Word16 cna_dirac_flag; /* CNA in DirAC flag */ -// Word16 cng_sba_flag; /* CNG in SBA flag */ -// Word16 idchan; /* channel ID (audio channel number) */ -// Word16 element_mode; /* element mode */ -// Word16 last_element_mode; /* element mode */ -// Word16 low_rate_mode; /* low-rate mode flag */ -// MCT_CHAN_MODE mct_chan_mode; -// Word16 GSC_IVAS_mode; -// Word16 is_ism_format; /* Indication whether the codec operates in ISM format */ -// Word16 dtx_sce_sba; /* enable use of FD CNG with transform domain cores in SCE SBA */ +//#ifdef DEBUGGING +// Word16 id_element; /* element ID */ +//#endif +// Word32 element_brate; /* element bitrate */ +// Word16 extl_orig; /* extension layer */ +// Word32 extl_brate_orig; /* extension layer bitrate */ +// /*----------------------- End of IVAS specific--------------------------------------*/ +// +// +// Word16 codec_mode; /* MODE1 or MODE2 */ +// Word16 last_codec_mode; /* Previous Codec Mode*/ +// Word16 last_codec_mode_cng; /* Codec Mode of the last inactive frame*/ +// Word16 mdct_sw_enable; /* MDCT switching enable flag */ +// Word16 mdct_sw; /* MDCT switching indicator */ +// Word16 last_enerBuffer_exp; +// Word16 next_bit_pos_fx; /* position of the next bit to be written in the bitstream */ +// Word16 bitstreamformat; /* Bitstream format flag (G.192/MIME) */ +// +// BSTR_ENC_HANDLE hBstr; /* encoder bitstream handle */ +// +// +// LPD_state_HANDLE hLPDmem; /* ACELP LPDmem memories */ +// +// +// Word32 input_Fs_fx; /* input signal sampling frequency in Hz */ +// Word32 total_brate_fx; /* total bitrate in kbps of the codec */ +// Word32 last_total_brate_fx; /* total bitrate in kbps of the codec */ +// Word32 last_total_brate_cng_fx; /* total bitrate in kbps of the last inactive frame */ +// Word16 core_fx; /* core (ACELP_CORE, TCX_20_CORE, TCX_10_CORE, HQ_CORE, AMR_WB_CORE) */ +// Word32 core_brate_fx; /* core bitrate */ +// Word32 last_core_brate_fx; /* previous frame core bitrate */ +// Word16 input_frame_fx; /* Frame lenght (function of input_Fs) */ +// Word16 extl_fx; /* extension layer */ +// Word16 last_extl_fx; /* previous extension layer */ +// Word32 extl_brate_fx; /* extension layer bitrate */ +// Word16 input_bwidth_fx; /* input signal bandwidth */ +// Word16 last_input_bwidth_fx; /* input signal bandwidth in the previous frame */ +// Word16 bwidth_fx; /* encoded bandwidth NB, WB, SWB or FB */ +// Word16 max_bwidth_fx; /* maximum encoded bandwidth */ +// Word16 last_bwidth_fx; /* input signal bandwidth in the previous frame */ +// Word16 last_bwidth_cng_fx; /* input signal bandwidth in the previous inactive frame */ +// Word16 L_frame_fx; /* ACELP core internal frame length */ +// Word16 Opt_AMR_WB_fx; /* flag indicating AMR-WB IO mode */ +// Word16 Opt_DTX_ON_fx; /* flag indicating DTX operation */ +// Word16 cng_type_fx; /* flag indicating LP or CLDFB based SID/CNG */ +// Word16 active_fr_cnt_fx; /* counter of active frames */ +// Word16 Opt_SC_VBR_fx; /* flag indicating SC-VBR mode */ +// Word16 last_Opt_SC_VBR_fx; /* flag indicating SC-VBR mode in the last frame */ +// /*----------------------------------------------------------------------------------* +// * ACELP core parameters +// *----------------------------------------------------------------------------------*/ // +// Word16 clas_fx; /* current frame clas */ +// Word16 last_clas_fx; /* previous frame signal classification */ +// Word32 Bin_E_fx[L_FFT]; /* Q_new + Q_SCALE -2 per bin energy of two frames */ // -// //#ifdef IVAS_CODE +// /*----------------------------------------------------------------------------------* +// * General signal buffers +// *----------------------------------------------------------------------------------*/ +// Word16* input_buff; +// /*Word16* input; +// Word16* old_input_signal;*/ +// +// SIGNAL_BUFFERS_ENC_HANDLE hSignalBuf; +// +// Word32* Bin_E_old_fx; /* per bin energy of old 2nd frames */ +// Word16* mem_decim_fx; /* decimation filter memory */ +// Word16* mem_decim16k_fx; /* ACELP@16kHz - decimation filter memory @16kHz */ +// Word16* old_inp_12k8_fx; /* memory of input signal at 12.8kHz */ +// Word16* old_inp_16k_fx; /* ACELP@16kHz - memory of input signal @16 kHz */ +// +// Word16* buf_speech_enc_pe; +// Word16* buf_synth; /*can be reduced to PIT_MAX_MAX+L_FRAME_MAX if no rate switching*/ +// Word16* buf_speech_enc; +// Word16* buf_wspeech_enc; +// +// +// Word16 lsp_old1_fx[M]; /* old unquantized LSP vector at the end of the frame */ +// Word16 lsf_old1_fx[M]; /* old LSF vector at the end of the frame */ +// Word16 lsp_old_fx[M]; /* old LSP vector at the end of the frame */ +// Word16 lsf_old_fx[M]; /* old LSF vector at the end of the frame */ +// Word16 lsp_old16k_fx[M]; /* old LSP vector at the end of the frame @16kHz */ +// Word16 lspold_enc_fx[M]; /* old LSP vector at the end of the frame @16kHz */ +// Word16 pstreaklen_fx; /* LSF quantizer */ +// Word16 streaklimit_fx; /* LSF quantizer */ +// Word32 offset_scale1_fx[MAX_NO_MODES + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure 1st 8-dim subvector*/ +// Word32 offset_scale2_fx[MAX_NO_MODES + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure 2nd 8-dim subvector*/ +// Word32 offset_scale1_p_fx[MAX_NO_MODES_p + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure, pred. case, 1st 8-dim subvector*/ +// Word32 offset_scale2_p_fx[MAX_NO_MODES_p + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure, pred. case, 2nd 8-dim subvector*/ +// Word16 no_scales_fx[MAX_NO_MODES][2]; /* LSF LVQ structure Q0*/ +// Word16 no_scales_p_fx[MAX_NO_MODES_p][2]; /* LSF LVQ structure Q0*/ +// Word16 stab_fac_fx; /* LSF stability factor */ +// Word16 mem_deemph_fx; /* deemphasis filter memory */ +// Word16 mem_preemph_fx; /* preemphasis filter memory */ +// Word32 mem_hp20_in_fx[5]; /* HP filter memory for AMR-WB IO */ +// Word16 old_wsp_fx[L_WSP_MEM]; /* old weighted signal vector */ +// /*Word16 old_exc_fx[L_EXC_MEM];*/ /* old excitation vector */ +// Word16 old_wsp2_fx[(L_WSP_MEM - L_INTERPOL) / OPL_DECIM]; /* old decimated weighted signal vector qwsp */ // -//#ifdef DEBUGGING -// Word16 id_element; /* element ID */ -//#endif -// Word32 element_brate; /* element bitrate */ -// Word16 extl_orig; /* extension layer */ -// Word32 extl_brate_orig; /* extension layer bitrate */ -// /*----------------------- End of IVAS specific--------------------------------------*/ -// -// -// Word16 codec_mode; /* MODE1 or MODE2 */ -// Word16 last_codec_mode; /* Previous Codec Mode*/ -// Word16 last_codec_mode_cng; /* Codec Mode of the last inactive frame*/ -// Word16 mdct_sw_enable; /* MDCT switching enable flag */ -// Word16 mdct_sw; /* MDCT switching indicator */ -// Word16 last_enerBuffer_exp; -// Word16 next_bit_pos_fx; /* position of the next bit to be written in the bitstream */ -// Word16 bitstreamformat; /* Bitstream format flag (G.192/MIME) */ -// -// BSTR_ENC_HANDLE hBstr; /* encoder bitstream handle */ -// -// -// LPD_state_HANDLE hLPDmem; /* ACELP LPDmem memories */ -// -// -// Word32 input_Fs_fx; /* input signal sampling frequency in Hz */ -// Word32 total_brate_fx; /* total bitrate in kbps of the codec */ -// Word32 last_total_brate_fx; /* total bitrate in kbps of the codec */ -// Word32 last_total_brate_cng_fx; /* total bitrate in kbps of the last inactive frame */ -// Word16 core_fx; /* core (ACELP_CORE, TCX_20_CORE, TCX_10_CORE, HQ_CORE, AMR_WB_CORE) */ -// Word32 core_brate_fx; /* core bitrate */ -// Word32 last_core_brate_fx; /* previous frame core bitrate */ -// Word16 input_frame_fx; /* Frame lenght (function of input_Fs) */ -// Word16 extl_fx; /* extension layer */ -// Word16 last_extl_fx; /* previous extension layer */ -// Word32 extl_brate_fx; /* extension layer bitrate */ -// Word16 input_bwidth_fx; /* input signal bandwidth */ -// Word16 last_input_bwidth_fx; /* input signal bandwidth in the previous frame */ -// Word16 bwidth_fx; /* encoded bandwidth NB, WB, SWB or FB */ -// Word16 max_bwidth_fx; /* maximum encoded bandwidth */ -// Word16 last_bwidth_fx; /* input signal bandwidth in the previous frame */ -// Word16 last_bwidth_cng_fx; /* input signal bandwidth in the previous inactive frame */ -// Word16 L_frame_fx; /* ACELP core internal frame length */ -// Word16 Opt_AMR_WB_fx; /* flag indicating AMR-WB IO mode */ -// Word16 Opt_DTX_ON_fx; /* flag indicating DTX operation */ -// Word16 cng_type_fx; /* flag indicating LP or CLDFB based SID/CNG */ -// Word16 active_fr_cnt_fx; /* counter of active frames */ -// Word16 Opt_SC_VBR_fx; /* flag indicating SC-VBR mode */ -// Word16 last_Opt_SC_VBR_fx; /* flag indicating SC-VBR mode in the last frame */ -// /*----------------------------------------------------------------------------------* -// * ACELP core parameters -// *----------------------------------------------------------------------------------*/ +// /*----------------------------------------------------------------------------------* +// * Noise estimation +// *----------------------------------------------------------------------------------*/ // -// Word16 clas_fx; /* current frame clas */ -// Word16 last_clas_fx; /* previous frame signal classification */ -// Word32 Bin_E_fx[L_FFT]; /* Q_new + Q_SCALE -2 per bin energy of two frames */ +// NOISE_EST_HANDLE hNoiseEst; // -// /*----------------------------------------------------------------------------------* -// * General signal buffers -// *----------------------------------------------------------------------------------*/ -// Word16* input_buff; -// /*Word16* input; -// Word16* old_input_signal;*/ -// -// SIGNAL_BUFFERS_ENC_HANDLE hSignalBuf; -// -// Word32* Bin_E_old_fx; /* per bin energy of old 2nd frames */ -// Word16* mem_decim_fx; /* decimation filter memory */ -// Word16* mem_decim16k_fx; /* ACELP@16kHz - decimation filter memory @16kHz */ -// Word16* old_inp_12k8_fx; /* memory of input signal at 12.8kHz */ -// Word16* old_inp_16k_fx; /* ACELP@16kHz - memory of input signal @16 kHz */ -// -// Word16* buf_speech_enc_pe; -// Word16* buf_synth; /*can be reduced to PIT_MAX_MAX+L_FRAME_MAX if no rate switching*/ -// Word16* buf_speech_enc; -// Word16* buf_wspeech_enc; -// -// -// Word16 lsp_old1_fx[M]; /* old unquantized LSP vector at the end of the frame */ -// Word16 lsf_old1_fx[M]; /* old LSF vector at the end of the frame */ -// Word16 lsp_old_fx[M]; /* old LSP vector at the end of the frame */ -// Word16 lsf_old_fx[M]; /* old LSF vector at the end of the frame */ -// Word16 lsp_old16k_fx[M]; /* old LSP vector at the end of the frame @16kHz */ -// Word16 lspold_enc_fx[M]; /* old LSP vector at the end of the frame @16kHz */ -// Word16 pstreaklen_fx; /* LSF quantizer */ -// Word16 streaklimit_fx; /* LSF quantizer */ -// Word32 offset_scale1_fx[MAX_NO_MODES + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure 1st 8-dim subvector*/ -// Word32 offset_scale2_fx[MAX_NO_MODES + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure 2nd 8-dim subvector*/ -// Word32 offset_scale1_p_fx[MAX_NO_MODES_p + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure, pred. case, 1st 8-dim subvector*/ -// Word32 offset_scale2_p_fx[MAX_NO_MODES_p + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure, pred. case, 2nd 8-dim subvector*/ -// Word16 no_scales_fx[MAX_NO_MODES][2]; /* LSF LVQ structure Q0*/ -// Word16 no_scales_p_fx[MAX_NO_MODES_p][2]; /* LSF LVQ structure Q0*/ -// Word16 stab_fac_fx; /* LSF stability factor */ -// Word16 mem_deemph_fx; /* deemphasis filter memory */ -// Word16 mem_preemph_fx; /* preemphasis filter memory */ -// Word32 mem_hp20_in_fx[5]; /* HP filter memory for AMR-WB IO */ -// Word16 old_wsp_fx[L_WSP_MEM]; /* old weighted signal vector */ -// /*Word16 old_exc_fx[L_EXC_MEM];*/ /* old excitation vector */ -// Word16 old_wsp2_fx[(L_WSP_MEM - L_INTERPOL) / OPL_DECIM]; /* old decimated weighted signal vector qwsp */ -// -// /*----------------------------------------------------------------------------------* -// * Noise estimation -// *----------------------------------------------------------------------------------*/ +// Word16 mem_wsp_fx; /* weighted signal vector memory */ +// Word16 mem_decim2_fx[3]; /* weighted signal decimation filter memory qwsp */ +// Word16 clip_var_fx[6]; +// Word16 mem_AR_fx[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean) */ +// Word16 mem_MA_fx[M]; /* MA memory of LSF quantizer (past quantized residual) (used also in AMR-WB IO mode) */ +// Word16 mCb1_fx; /* LSF quantizer - counter of stationary frames after a transition frame */ +// Word16 coder_type_raw_fx; +// Word16 last_coder_type_raw_fx; /* raw last_coder_type (coming from the sigal classification) */ +// Word16 last_coder_type; /*Q0 previous coding type */ +// Word16 ini_frame_fx; /* initialization frames counter */ +// Word16 old_thres_fx; /* normalized correlation weighting in open-loop pitch Q15 */ +// Word16 old_corr_fx; /* normalized correlation in previous frame (mean value) Q15 */ +// Word16 old_pitch; /* previous pitch for open-loop pitch search Q0 */ +// Word16 delta_pit_fx; /* open-loop pitch extrapolation correction Q0 */ +// Word32 ee_old_fx; +// Word16 min_band_fx; /* Q0 minimum critical band of useful bandwidth */ +// Word16 max_band_fx; /* Q0 maximum critical band of useful bandwidth */ +// Word16 tc_cnt_fx; /* TC frame counter */ +// Word16 audio_frame_cnt_fx; /* Counter of relative presence of audio frames */ +// Word32 old_dE1_fx; /* Maximum energy increase in previous frame */ +// Word16 old_ind_deltaMax_fx; /* Index of the sub-subframe of maximum energy in previous frame */ +// Word32 old_enr_ssf_fx[2 * NB_SSF]; /* Maxima of energies per sub-subframes of previous frame */ +// Word16 spike_hyst_fx; /* Hysteresis to prevent UC after sharp energy spike */ +// Word16 music_hysteresis_fx; /* Counter of frames after AUDIO coding mode to prevent UC */ +// Word16 last_harm_flag_acelp_fx; /* harmonicity flag for ACELP @32kbps rate */ +// Word16 old_Aq_12_8_fx[M + 1]; /* Q12 old Aq[] for core switching */ +// Word16 old_Es_pred_fx; /* Q8 old Es_pred for core switching */ // -// NOISE_EST_HANDLE hNoiseEst; -// -// Word16 mem_wsp_fx; /* weighted signal vector memory */ -// Word16 mem_decim2_fx[3]; /* weighted signal decimation filter memory qwsp */ -// Word16 clip_var_fx[6]; -// Word16 mem_AR_fx[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean) */ -// Word16 mem_MA_fx[M]; /* MA memory of LSF quantizer (past quantized residual) (used also in AMR-WB IO mode) */ -// Word16 mCb1_fx; /* LSF quantizer - counter of stationary frames after a transition frame */ -// Word16 coder_type_raw_fx; -// Word16 last_coder_type_raw_fx; /* raw last_coder_type (coming from the sigal classification) */ -// Word16 last_coder_type; /*Q0 previous coding type */ -// Word16 ini_frame_fx; /* initialization frames counter */ -// Word16 old_thres_fx; /* normalized correlation weighting in open-loop pitch Q15 */ -// Word16 old_corr_fx; /* normalized correlation in previous frame (mean value) Q15 */ -// Word16 old_pitch; /* previous pitch for open-loop pitch search Q0 */ -// Word16 delta_pit_fx; /* open-loop pitch extrapolation correction Q0 */ -// Word32 ee_old_fx; -// Word16 min_band_fx; /* Q0 minimum critical band of useful bandwidth */ -// Word16 max_band_fx; /* Q0 maximum critical band of useful bandwidth */ -// Word16 tc_cnt_fx; /* TC frame counter */ -// Word16 audio_frame_cnt_fx; /* Counter of relative presence of audio frames */ -// Word32 old_dE1_fx; /* Maximum energy increase in previous frame */ -// Word16 old_ind_deltaMax_fx; /* Index of the sub-subframe of maximum energy in previous frame */ -// Word32 old_enr_ssf_fx[2 * NB_SSF]; /* Maxima of energies per sub-subframes of previous frame */ -// Word16 spike_hyst_fx; /* Hysteresis to prevent UC after sharp energy spike */ -// Word16 music_hysteresis_fx; /* Counter of frames after AUDIO coding mode to prevent UC */ -// Word16 last_harm_flag_acelp_fx; /* harmonicity flag for ACELP @32kbps rate */ -// Word16 old_Aq_12_8_fx[M + 1]; /* Q12 old Aq[] for core switching */ -// Word16 old_Es_pred_fx; /* Q8 old Es_pred for core switching */ -// -// GSC_ENC_HANDLE hGSCEnc; -// -// -// Word16 GSC_noisy_speech; /* AC mode (GSC) - flag to indicate GSC on SWB noisy speech */ -// -// SP_MUS_CLAS_HANDLE hSpMusClas; -// -// Word16 lgBin_E_fx[L_FFT / 2]; /* Q8 per bin energy of two frames */ -// -// /* speech/music classifier improvement parameters */ -// Word16 last_vad_spa_fx; -// -// -// Word16 Last_pulse_pos_fx; /* FEC - last position of the first glotal pulse in the frame */ -// Word16 lsfoldbfi0_fx[M]; /* FEC - LSF vector of the previous frame */ -// Word16 lsfoldbfi1_fx[M]; /* FEC - LSF vector of the past previous frame */ -// Word16 lsf_adaptive_mean_fx[M]; /* FEC - adaptive mean LSF vector for FEC */ -// Word16 next_force_safety_net_fx; /* FEC - flag to force safety net in next frame */ -// -// -// /*----------------------------------------------------------------------------------* -// * VAD/DTX/CNG -// *----------------------------------------------------------------------------------*/ +// GSC_ENC_HANDLE hGSCEnc; // -// VAD_HANDLE hVAD; // -// VAD_CLDFB_HANDLE_FX hVAD_CLDFB; -// Word16 lp_speech_fx; -// Word16 Opt_HE_SAD_ON_fx; -// Word16 nb_active_frames_HE_SAD_fx; +// Word16 GSC_noisy_speech; /* AC mode (GSC) - flag to indicate GSC on SWB noisy speech */ // +// SP_MUS_CLAS_HANDLE hSpMusClas; // +// Word16 lgBin_E_fx[L_FFT / 2]; /* Q8 per bin energy of two frames */ // +// /* speech/music classifier improvement parameters */ +// Word16 last_vad_spa_fx; // -// Word16 voicing_old_fx; // +// Word16 Last_pulse_pos_fx; /* FEC - last position of the first glotal pulse in the frame */ +// Word16 lsfoldbfi0_fx[M]; /* FEC - LSF vector of the previous frame */ +// Word16 lsfoldbfi1_fx[M]; /* FEC - LSF vector of the past previous frame */ +// Word16 lsf_adaptive_mean_fx[M]; /* FEC - adaptive mean LSF vector for FEC */ +// Word16 next_force_safety_net_fx; /* FEC - flag to force safety net in next frame */ // -// Word32 bckr_tilt_lt; // +// /*----------------------------------------------------------------------------------* +// * VAD/DTX/CNG +// *----------------------------------------------------------------------------------*/ // -// TD_CNG_ENC_HANDLE hTdCngEnc; +// VAD_HANDLE hVAD; // -// DTX_ENC_HANDLE hDtxEnc; -// Word16 var_SID_rate_flag_fx; /* CNG and DTX - flag for variable SID rate */ -// Word16 interval_SID_fx; /* CNG and DTX - interval of SID update, default 8 */ +// VAD_CLDFB_HANDLE_FX hVAD_CLDFB; +// Word16 lp_speech_fx; +// Word16 Opt_HE_SAD_ON_fx; +// Word16 nb_active_frames_HE_SAD_fx; // -// Word16 lp_noise_fx; /* CNG and DTX - LP filtered total noise estimation */ // -// Word16 uv_count; /*Q0*/ /* Stationary noise UV modification - unvoiced counter */ -// Word16 act_count; /*Q0*/ /* Stationary noise UV modification - activation counter */ -// Word32 ge_sm_fx; /* Stationary noise UV modification - smoothed excitation gain */ -// Word16 lspold_s_fx[M]; /*Q15*/ /* Stationary noise UV modification - old LSP vector */ -// Word16 noimix_seed; /*Q0*/ /* Stationary noise UV modification - mixture seed */ -// Word16 min_alpha_fx; /*Q15*/ /* Stationary noise UV modification - minimum alpha */ -// Word16 exc_pe_fx; /* Stationary noise UV modification - memory of the preemphasis filter */ // -// Word16 last_L_frame_fx; /* ACELP@16kHz - last L_frame value */ -// Word16 mem_preemph16k_fx; /* ACELP@16kHz - preemphasis filter memory @16kHz */ -// Word16 mem_deemp_preQ_fx; /* ACELP@16kHz - prequantizer deemhasis memory */ -// Word16 mem_preemp_preQ_fx; /* ACELP@16kHz - prequantizer preemhasis memory */ -// Word16 last_nq_preQ; /* ACELP@16kHz - AVQ subquantizer number of the last sub-band of the last subframe */ -// Word16 use_acelp_preq; /* ACELP@16kHz - flag of prequantizer usage */ // -// Word16 bpf_off_fx; -// Word16 old_pitch_buf_fx[2 * NB_SUBFR16k]; /*Q6 Bass post-filter - buffer of old subframe pitch values */ +// Word16 voicing_old_fx; // // -// /* stable short pitch detection */ -// Word16 voicing0_sm_fx; -// Word16 voicing_sm_fx; -// Word16 LF_EnergyRatio_sm_fx; -// Word16 predecision_flag_fx; -// Word32 diff_sm_fx; -// Word32 energy_sm_fx; +// Word32 bckr_tilt_lt; // -// Word16 last_ener_fx; /* AC mode (GSC) - previous energy */ // -// /*----------------------------------------------------------------------------------* -// * AMR-WB IO handle -// *----------------------------------------------------------------------------------*/ +// TD_CNG_ENC_HANDLE hTdCngEnc; // -// AMRWB_IO_ENC_HANDLE hAmrwb_IO; /* AMR-WB IO encoder handle */ +// DTX_ENC_HANDLE hDtxEnc; +// Word16 var_SID_rate_flag_fx; /* CNG and DTX - flag for variable SID rate */ +// Word16 interval_SID_fx; /* CNG and DTX - interval of SID update, default 8 */ // -// /*----------------------------------------------------------------------------------* -// * CLDFB analysis -// *----------------------------------------------------------------------------------*/ -// HANDLE_CLDFB_FILTER_BANK cldfbAna_Fx; -// -// HANDLE_CLDFB_FILTER_BANK cldfbSyn_Fx; -// -// /*----------------------------------------------------------------------------------* -// * FD CNG handle -// *----------------------------------------------------------------------------------*/ -// HANDLE_FD_CNG_ENC_FX hFdCngEnc_fx; -// Word16 fd_cng_reset_flag; -// Word16 last_totalNoise_fx; -// Word16 totalNoise_increase_hist_fx[TOTALNOISE_HIST_SIZE]; -// Word16 totalNoise_increase_len_fx; -// /*----------------------------------------------------------------------------------* -// * SC-VBR parameters -// *----------------------------------------------------------------------------------*/ +// Word16 lp_noise_fx; /* CNG and DTX - LP filtered total noise estimation */ +// +// Word16 uv_count; /*Q0*/ /* Stationary noise UV modification - unvoiced counter */ +// Word16 act_count; /*Q0*/ /* Stationary noise UV modification - activation counter */ +// Word32 ge_sm_fx; /* Stationary noise UV modification - smoothed excitation gain */ +// Word16 lspold_s_fx[M]; /*Q15*/ /* Stationary noise UV modification - old LSP vector */ +// Word16 noimix_seed; /*Q0*/ /* Stationary noise UV modification - mixture seed */ +// Word16 min_alpha_fx; /*Q15*/ /* Stationary noise UV modification - minimum alpha */ +// Word16 exc_pe_fx; /* Stationary noise UV modification - memory of the preemphasis filter */ +// +// Word16 last_L_frame_fx; /* ACELP@16kHz - last L_frame value */ +// Word16 mem_preemph16k_fx; /* ACELP@16kHz - preemphasis filter memory @16kHz */ +// Word16 mem_deemp_preQ_fx; /* ACELP@16kHz - prequantizer deemhasis memory */ +// Word16 mem_preemp_preQ_fx; /* ACELP@16kHz - prequantizer preemhasis memory */ +// Word16 last_nq_preQ; /* ACELP@16kHz - AVQ subquantizer number of the last sub-band of the last subframe */ +// Word16 use_acelp_preq; /* ACELP@16kHz - flag of prequantizer usage */ +// +// Word16 bpf_off_fx; +// Word16 old_pitch_buf_fx[2 * NB_SUBFR16k]; /*Q6 Bass post-filter - buffer of old subframe pitch values */ +// +// +// /* stable short pitch detection */ +// Word16 voicing0_sm_fx; +// Word16 voicing_sm_fx; +// Word16 LF_EnergyRatio_sm_fx; +// Word16 predecision_flag_fx; +// Word32 diff_sm_fx; +// Word32 energy_sm_fx; +// +// Word16 last_ener_fx; /* AC mode (GSC) - previous energy */ // // /*----------------------------------------------------------------------------------* -// * SC-VBR parameters +// * AMR-WB IO handle // *----------------------------------------------------------------------------------*/ // -// SC_VBR_ENC_HANDLE hSC_VBR; +// AMRWB_IO_ENC_HANDLE hAmrwb_IO; /* AMR-WB IO encoder handle */ // -// /*----------------------------------------------------------------------------------* -// * HQ core parameters +// /*----------------------------------------------------------------------------------* +// * CLDFB analysis +// *----------------------------------------------------------------------------------*/ +// HANDLE_CLDFB_FILTER_BANK cldfbAna_Fx; +// +// HANDLE_CLDFB_FILTER_BANK cldfbSyn_Fx; +// +// /*----------------------------------------------------------------------------------* +// * FD CNG handle // *----------------------------------------------------------------------------------*/ -// Word16 * input; -// Word16 * old_input_signal_fx; -// Word16 Q_old_wtda; -// Word16 old_hpfilt_in_fx; -// Word16 old_hpfilt_out_fx; -// Word32 EnergyLT_fx; -// Word32 Energy_Old_fx; -// Word16 TransientHangOver_fx; -// Word16 last_core_fx; +// HANDLE_FD_CNG_ENC_FX hFdCngEnc_fx; +// Word16 fd_cng_reset_flag; +// Word16 last_totalNoise_fx; +// Word16 totalNoise_increase_hist_fx[TOTALNOISE_HIST_SIZE]; +// Word16 totalNoise_increase_len_fx; +// /*----------------------------------------------------------------------------------* +// * SC-VBR parameters +// *----------------------------------------------------------------------------------*/ // -// HQ_ENC_HANDLE hHQ_core; /* HQ core encoder handle */ +// /*----------------------------------------------------------------------------------* +// * SC-VBR parameters +// *----------------------------------------------------------------------------------*/ // -// Word16 Nb_ACELP_frames_fx; +// SC_VBR_ENC_HANDLE hSC_VBR; // -// PVQ_ENC_HANDLE hPVQ; +// /*----------------------------------------------------------------------------------* +// * HQ core parameters +// *----------------------------------------------------------------------------------*/ +// Word16 * input; +// Word16 * old_input_signal_fx; +// Word16 Q_old_wtda; +// Word16 old_hpfilt_in_fx; +// Word16 old_hpfilt_out_fx; +// Word32 EnergyLT_fx; +// Word32 Energy_Old_fx; +// Word16 TransientHangOver_fx; +// Word16 last_core_fx; // -// /*----------------------------------------------------------------------------------* -// * TD BWE parameters -// *----------------------------------------------------------------------------------*/ +// HQ_ENC_HANDLE hHQ_core; /* HQ core encoder handle */ // -// TD_BWE_ENC_HANDLE hBWE_TD; +// Word16 Nb_ACELP_frames_fx; // -// /*----------------------------------------------------------------------------------* -// * FD BWE parameters -// *----------------------------------------------------------------------------------*/ +// PVQ_ENC_HANDLE hPVQ; // -// FD_BWE_ENC_HANDLE hBWE_FD; +// /*----------------------------------------------------------------------------------* +// * TD BWE parameters +// *----------------------------------------------------------------------------------*/ // -// /*----------------------------------------------------------------------------------* -// * WB, SWB and FB bandwidth detector -// *----------------------------------------------------------------------------------*/ +// TD_BWE_ENC_HANDLE hBWE_TD; // -// Word16 lt_mean_NB_fx; -// Word16 lt_mean_WB_fx; -// Word16 lt_mean_SWB_fx; -// Word16 count_WB_fx; -// Word16 count_SWB_fx; -// Word16 count_FB_fx; -// -// RF_ENC_HANDLE hRF; /* RF encoder handle */ -// -// Word16 rf_mode; -// Word16 rf_target_bits_write; -// Word16 rf_mode_last; -// Word16 last_rf_mode_cng; -// Word16 Opt_RF_ON; -// Word16 rf_fec_offset; -// Word16 rf_fec_indicator; -// -// /*----------------------------------------------------------------------------------* -// * Fixed point only variables -// *----------------------------------------------------------------------------------*/ +// /*----------------------------------------------------------------------------------* +// * FD BWE parameters +// *----------------------------------------------------------------------------------*/ // -// Word16 prev_Q_bwe_exc; -// Word16 prev_Q_bwe_syn; -// Word16 Q_stat_noise_ge; -// Word16 Q_stat_noise; -// Word16 Q_syn2; -// Word16 Q_syn; -// Word16 Q_max[L_Q_MEM]; -// Word16 Q_max_16k[L_Q_MEM]; -// Word16 Q_old; -// Word16 prev_Q_old; -// Word16 old_wsp_max; /* Last weigthed speech maximal value */ -// Word16 old_wsp_shift; /* Last wsp scaling */ -// Word16 prev_Q_new; -// Word16 prev_Q_shb; -// -// /*----------------------------------------------------------------------------------* -// * -// *----------------------------------------------------------------------------------*/ +// FD_BWE_ENC_HANDLE hBWE_FD; // -// Word16 EnergyLT_fx_exp; -// Word16 prev_lsp_wb_fx[LPC_SHB_ORDER_WB]; -// Word16 prev_lpc_wb_fx[LPC_SHB_ORDER_WB]; -// Word16 prev_lsp_wb_temp_fx[LPC_SHB_ORDER_WB]; +// /*----------------------------------------------------------------------------------* +// * WB, SWB and FB bandwidth detector +// *----------------------------------------------------------------------------------*/ // -// Word16 frame_size_index; /* 0-FRAME_SIZE_NB-1: index determining the frame size */ -// Word16 bits_frame_nominal; /* avg bits per frame on active frame */ -// Word16 bits_frame; /* total bits per frame */ -// Word16 bits_frame_core; /* bits per frame for the core */ -// Word8 narrowBand; +// Word16 lt_mean_NB_fx; +// Word16 lt_mean_WB_fx; +// Word16 lt_mean_SWB_fx; +// Word16 count_WB_fx; +// Word16 count_SWB_fx; +// Word16 count_FB_fx; // -// /*ACELP config*/ -// ACELP_config acelp_cfg; /* configuration set for each frame */ +// RF_ENC_HANDLE hRF; /* RF encoder handle */ // -// ACELP_config acelp_cfg_rf; /* configuration for RF frame */ +// Word16 rf_mode; +// Word16 rf_target_bits_write; +// Word16 rf_mode_last; +// Word16 last_rf_mode_cng; +// Word16 Opt_RF_ON; +// Word16 rf_fec_offset; +// Word16 rf_fec_indicator; // -// Word16 mode_index; /* Mode Index for LPD core */ +// /*----------------------------------------------------------------------------------* +// * Fixed point only variables +// *----------------------------------------------------------------------------------*/ // -// /*TCX config*/ -// TCX_CONFIG_HANDLE hTcxCfg; -// /*----------------------------------------------------------------------------------* -// * TCX core encoder handle -// *----------------------------------------------------------------------------------*/ +// Word16 prev_Q_bwe_exc; +// Word16 prev_Q_bwe_syn; +// Word16 Q_stat_noise_ge; +// Word16 Q_stat_noise; +// Word16 Q_syn2; +// Word16 Q_syn; +// Word16 Q_max[L_Q_MEM]; +// Word16 Q_max_16k[L_Q_MEM]; +// Word16 Q_old; +// Word16 prev_Q_old; +// Word16 old_wsp_max; /* Last weigthed speech maximal value */ +// Word16 old_wsp_shift; /* Last wsp scaling */ +// Word16 prev_Q_new; +// Word16 prev_Q_shb; +// +// /*----------------------------------------------------------------------------------* +// * +// *----------------------------------------------------------------------------------*/ +// +// Word16 EnergyLT_fx_exp; +// Word16 prev_lsp_wb_fx[LPC_SHB_ORDER_WB]; +// Word16 prev_lpc_wb_fx[LPC_SHB_ORDER_WB]; +// Word16 prev_lsp_wb_temp_fx[LPC_SHB_ORDER_WB]; +// +// Word16 frame_size_index; /* 0-FRAME_SIZE_NB-1: index determining the frame size */ +// Word16 bits_frame_nominal; /* avg bits per frame on active frame */ +// Word16 bits_frame; /* total bits per frame */ +// Word16 bits_frame_core; /* bits per frame for the core */ +// Word8 narrowBand; +// +// /*ACELP config*/ +// ACELP_config acelp_cfg; /* configuration set for each frame */ +// +// ACELP_config acelp_cfg_rf; /* configuration for RF frame */ +// +// Word16 mode_index; /* Mode Index for LPD core */ +// +// /*TCX config*/ +// TCX_CONFIG_HANDLE hTcxCfg; +// /*----------------------------------------------------------------------------------* +// * TCX core encoder handle +// *----------------------------------------------------------------------------------*/ // -// TCX_ENC_HANDLE hTcxEnc; +// TCX_ENC_HANDLE hTcxEnc; // -// /* cod_main.c */ -// Word16 mem_preemph_enc; /* speech preemph filter memory (at encoder-sampling-rate) */ +// /* cod_main.c */ +// Word16 mem_preemph_enc; /* speech preemph filter memory (at encoder-sampling-rate) */ // // -// Word16 *speech_enc; -// Word16 *speech_enc_pe; -// Word16 *new_speech_enc; -// Word16 *new_speech_enc_pe; -// Word16 *wspeech_enc; -// Word16 *synth; -// /* Core Signal Analysis Outputs */ +// Word16 *speech_enc; +// Word16 *speech_enc_pe; +// Word16 *new_speech_enc; +// Word16 *new_speech_enc_pe; +// Word16 *wspeech_enc; +// Word16 *synth; +// /* Core Signal Analysis Outputs */ // -// Word8 enableTcxLpc; /* global toggle for the TCX LPC quantizer */ -// Word16 envWeighted; /* are is{p,f}_old_q[] weighted or not? */ +// Word8 enableTcxLpc; /* global toggle for the TCX LPC quantizer */ +// Word16 envWeighted; /* are is{p,f}_old_q[] weighted or not? */ // -// Word8 acelpEnabled; /* Flag indicating if ACELP can be used */ -// Word8 tcx10Enabled; /* Flag indicating if TCX 10 can be used */ -// Word8 tcx20Enabled; /* Flag indicating if TCX 20 can be used */ +// Word8 acelpEnabled; /* Flag indicating if ACELP can be used */ +// Word8 tcx10Enabled; /* Flag indicating if TCX 10 can be used */ +// Word8 tcx20Enabled; /* Flag indicating if TCX 20 can be used */ // // -// Word16 mem_wsp_enc; /* wsp vector memory */ +// Word16 mem_wsp_enc; /* wsp vector memory */ // -// Word16 nb_bits_header_ace; /* number of bits for the header */ -// Word16 nb_bits_header_tcx; /* number of bits for the header */ +// Word16 nb_bits_header_ace; /* number of bits for the header */ +// Word16 nb_bits_header_tcx; /* number of bits for the header */ // -// /*Added by fcs : restrict the possible in EVS: 0 base 10 = d.c.b.a base 2*/ -// /* a = 0/1 : ACELP on/off*/ -// /* b = 0/1 : TCX20 on/off*/ -// /* c = 0/1 : TCX40 on/off*/ -// /* d = 0/1 : TCX80 on/off*/ -// Word16 restrictedMode; +// /*Added by fcs : restrict the possible in EVS: 0 base 10 = d.c.b.a base 2*/ +// /* a = 0/1 : ACELP on/off*/ +// /* b = 0/1 : TCX20 on/off*/ +// /* c = 0/1 : TCX40 on/off*/ +// /* d = 0/1 : TCX80 on/off*/ +// Word16 restrictedMode; // -// /* Framing */ -// Word16 nb_subfr; +// /* Framing */ +// Word16 nb_subfr; // -// Word16 preemph_fac; /*Preemphasis factor*/ +// Word16 preemph_fac; /*Preemphasis factor*/ // -// Word16 gamma; -// Word16 inv_gamma; +// Word16 gamma; +// Word16 inv_gamma; // -// TransientDetection transientDetection; -// Word16 transient_info[3]; +// TransientDetection transientDetection; +// Word16 transient_info[3]; // -// Word16 acelpFramesCount; /* Acelp frame counter. Counts upto 50 only !!! */ +// Word16 acelpFramesCount; /* Acelp frame counter. Counts upto 50 only !!! */ // -// Word16 prevTempFlatness_fx; /* exponent is AVG_FLAT_E */ +// Word16 prevTempFlatness_fx; /* exponent is AVG_FLAT_E */ // -// Word32 prevEnergyHF_fx; -// Word32 currEnergyHF_fx; -// Word16 currEnergyHF_e_fx; /* exponent of currEnergyHF and prevEnergyHF */ -// Word32 energyCoreLookahead_Fx; -// Word16 sf_energyCoreLookahead_Fx; +// Word32 prevEnergyHF_fx; +// Word32 currEnergyHF_fx; +// Word16 currEnergyHF_e_fx; /* exponent of currEnergyHF and prevEnergyHF */ +// Word32 energyCoreLookahead_Fx; +// Word16 sf_energyCoreLookahead_Fx; // -// /* lsf quantizer*/ -// Word16 parcorr[2]; -// Word16 parcorr_mid[2]; +// /* lsf quantizer*/ +// Word16 parcorr[2]; +// Word16 parcorr_mid[2]; // -// Word16 lpcQuantization; -// Word16 numlpc; -// Word16 encoderLookahead_enc; -// Word16 encoderPastSamples_enc; -// Word16 encoderLookahead_FB; +// Word16 lpcQuantization; +// Word16 numlpc; +// Word16 encoderLookahead_enc; +// Word16 encoderPastSamples_enc; +// Word16 encoderLookahead_FB; // -// /* pitch_ol for adaptive lag window */ -// Word16 old_pitch_la; /* past open loop pitch lag from look-ahead */ -// Word16 old_voicing_la; /* past open loop pitch gain from look-ahead */ +// /* pitch_ol for adaptive lag window */ +// Word16 old_pitch_la; /* past open loop pitch lag from look-ahead */ +// Word16 old_voicing_la; /* past open loop pitch gain from look-ahead */ // -// Word32 band_energies[2 * NB_BANDS]; /* energy in critical bands without minimum noise floor MODE2_E_MIN */ -// Word16 band_energies_exp; /* exponent for energy in critical bands without minimum noise floor MODE2_E_MIN */ +// Word32 band_energies[2 * NB_BANDS]; /* energy in critical bands without minimum noise floor MODE2_E_MIN */ +// Word16 band_energies_exp; /* exponent for energy in critical bands without minimum noise floor MODE2_E_MIN */ // -// Word8 tcxonly; +// Word8 tcxonly; // -// Word16 Q_max_enc[2]; +// Word16 Q_max_enc[2]; // -// Word16 finalVAD; -// Word8 flag_noisy_speech_snr; /*encoder detector for noisy speech*/ -// Word16 Pos_relE_cnt; /* Number of frames between positive relE */ +// Word16 finalVAD; +// Word8 flag_noisy_speech_snr; /*encoder detector for noisy speech*/ +// Word16 Pos_relE_cnt; /* Number of frames between positive relE */ // -// Word16 fscale; -// Word32 sr_core; -// Word32 last_sr_core; -// Word8 acelp_autocorr; /* Optimize acelp in 0 covariance or 1 correlation domain */ +// Word16 fscale; +// Word32 sr_core; +// Word32 last_sr_core; +// Word8 acelp_autocorr; /* Optimize acelp in 0 covariance or 1 correlation domain */ // -// Word16 pit_min; -// Word16 pit_fr1; -// Word16 pit_fr1b; -// Word16 pit_fr2; -// Word16 pit_max; -// Word16 pit_res_max; /* goes from 1 upto 6 (see core_enc_init.c: init_acelp()) */ +// Word16 pit_min; +// Word16 pit_fr1; +// Word16 pit_fr1b; +// Word16 pit_fr2; +// Word16 pit_max; +// Word16 pit_res_max; /* goes from 1 upto 6 (see core_enc_init.c: init_acelp()) */ // -// /* for FAC */ -// Word16 L_frame_past; +// /* for FAC */ +// Word16 L_frame_past; // -// /*Adaptive BPF*/ -// Word16 bpf_gain_param; -// Word16 bpf_T[NB_SUBFR16k]; -// Word16 bpf_gainT[NB_SUBFR16k]; +// /*Adaptive BPF*/ +// Word16 bpf_gain_param; +// Word16 bpf_T[NB_SUBFR16k]; +// Word16 bpf_gainT[NB_SUBFR16k]; // -// struct MEM_BPF -// { -// Word16 noise_buf[2 * L_FILT16k]; -// Word16 error_buf[L_FILT16k]; -// Word32 lp_error; -// Word32 lp_error_ener; -// Word16 noise_shift_old; -// } mem_bpf; +// struct MEM_BPF +// { +// Word16 noise_buf[2 * L_FILT16k]; +// Word16 error_buf[L_FILT16k]; +// Word32 lp_error; +// Word32 lp_error_ener; +// Word16 noise_shift_old; +// } mem_bpf; // // // -// Word8 glr; -// Word16 glr_idx[2]; -// Word32 gain_code[NB_SUBFR16k]; -// Word32 mean_gc[2]; -// Word16 prev_lsf4_mean; -// Word16 last_stab_fac; -// Word8 glr_reset; +// Word8 glr; +// Word16 glr_idx[2]; +// Word32 gain_code[NB_SUBFR16k]; +// Word32 mean_gc[2]; +// Word16 prev_lsf4_mean; +// Word16 last_stab_fac; +// Word8 glr_reset; // -// /*for rate switching*/ -// Word16 rate_switching_reset; /*Rate switching flag requiring a reset of memories at least partially */ -// Word16 rate_switching_reset_16kHz; +// /*for rate switching*/ +// Word16 rate_switching_reset; /*Rate switching flag requiring a reset of memories at least partially */ +// Word16 rate_switching_reset_16kHz; // -// Word16 enablePlcWaveadjust; -// Word16 Tonal_SideInfo; +// Word16 enablePlcWaveadjust; +// Word16 Tonal_SideInfo; // -// IGF_ENC_INSTANCE_HANDLE hIGFEnc; /* IGF encoder handle */ -// Word16 igf; +// IGF_ENC_INSTANCE_HANDLE hIGFEnc; /* IGF encoder handle */ +// Word16 igf; // -// Word16 seed_acelp; +// Word16 seed_acelp; // -// PLC_ENC_EVS_HANDLE hPlcExt; +// PLC_ENC_EVS_HANDLE hPlcExt; // -// Word16 tec_tfa; -// TEC_ENC_HANDLE hTECEnc; /* TEC encoder handle */ -// Word16 tec_flag; -// Word16 tfa_flag; -// Word32 tfa_enr[N_TEC_TFA_SUBFR]; +// Word16 tec_tfa; +// TEC_ENC_HANDLE hTECEnc; /* TEC encoder handle */ +// Word16 tec_flag; +// Word16 tfa_flag; +// Word32 tfa_enr[N_TEC_TFA_SUBFR]; // -// Word16 nTimeSlots; /* for CLDFB */ +// Word16 nTimeSlots; /* for CLDFB */ // -// T_CldfbVadState_fx vad_st; +// T_CldfbVadState_fx vad_st; // // -// Word16 pitch_fx[3]; -// Word16 voicing_fx[3]; -// Word16 sp_aud_decision0; /* 1st stage speech/music classification */ -// Word16 sp_aud_decision1; /* 1st stage speech/music classification */ -// Word16 sp_aud_decision2; /* 2nd stage speech/music classification */ -// Word16 coder_type; /* coder type */ -// Word16 vad_flag; -// Word16 sharpFlag; /* formant sharpening flag */ -// Word16 localVAD; +// Word16 pitch_fx[3]; +// Word16 voicing_fx[3]; +// Word16 sp_aud_decision0; /* 1st stage speech/music classification */ +// Word16 sp_aud_decision1; /* 1st stage speech/music classification */ +// Word16 sp_aud_decision2; /* 2nd stage speech/music classification */ +// Word16 coder_type; /* coder type */ +// Word16 vad_flag; +// Word16 sharpFlag; /* formant sharpening flag */ +// Word16 localVAD; // -// Word16 tdm_pc; -// Word16 prev_fmerit; -// Word16 fmerit_dt; +// Word16 tdm_pc; +// Word16 prev_fmerit; +// Word16 fmerit_dt; // // -//} Encoder_State, * ENC_CORE_HANDLE_FX; +// } Encoder_State, * ENC_CORE_HANDLE_FX; typedef struct GainItemStr { diff --git a/lib_enc/stat_noise_uv_enc_fx.c b/lib_enc/stat_noise_uv_enc_fx.c index 8bb3c09bc..b72ddf02f 100644 --- a/lib_enc/stat_noise_uv_enc_fx.c +++ b/lib_enc/stat_noise_uv_enc_fx.c @@ -7,12 +7,12 @@ #include "cnst.h" //#include "prot_fx.h" /* Function prototypes */ #include "rom_com_fx.h" /* Static table prototypes */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ - /*======================================================================*/ +/*======================================================================*/ /* FUNCTION : stat_noise_uv_enc_fx */ /*----------------------------------------------------------------------*/ /* PURPOSE : Modifies excitation signal in UC mode */ @@ -38,71 +38,70 @@ /* _ None */ /*=======================================================================*/ void stat_noise_uv_enc_fx( - Encoder_State *st_fx, /* i/o: state structure */ + Encoder_State *st_fx, /* i/o: state structure */ const Word32 *LepsP, /* i : LP prediction errors */ const Word16 *isp_new, /* i : immittance spectral pairs at 4th sfr */ const Word16 *isp_mid, /* i : immittance spectral pairs at 2nd sfr */ Word16 *Aq, /* i : A(z) quantized for the 4 subframes */ Word16 *exc2, /* i/o: excitation buffer */ const Word16 uc_two_stage_flag, /* o : flag undicating two-stage UC */ - Word16 Q_new -) + Word16 Q_new ) { Word16 noisiness = 0; - Word16 num,den,expn,expd; + Word16 num, den, expn, expd; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif test(); test(); - IF ( ( EQ_16(st_fx->coder_type,UNVOICED) && uc_two_stage_flag == 0) || (EQ_16(st_fx->coder_type,INACTIVE) && LE_32(st_fx->core_brate,ACELP_9k60))) + IF( ( EQ_16( st_fx->coder_type, UNVOICED ) && uc_two_stage_flag == 0 ) || ( EQ_16( st_fx->coder_type, INACTIVE ) && LE_32( st_fx->core_brate, ACELP_9k60 ) ) ) { /*-----------------------------------------------------------------* * Calculate and write the noisiness parameter *-----------------------------------------------------------------*/ /* epsP[2] is located in LepsP[0] and epsP[16] in LepsP[1] */ - expn = sub(norm_l(LepsP[0]),1); + expn = sub( norm_l( LepsP[0] ), 1 ); #ifdef BASOP_NOGLOB - num = extract_h(L_shl_o(LepsP[0],expn, &Overflow));/*expn-16*/ + num = extract_h( L_shl_o( LepsP[0], expn, &Overflow ) ); /*expn-16*/ #else - num = extract_h(L_shl(LepsP[0],expn));/*expn-16*/ + num = extract_h( L_shl( LepsP[0], expn ) ); /*expn-16*/ #endif - expd = norm_l(LepsP[1]); + expd = norm_l( LepsP[1] ); #ifdef BASOP_NOGLOB - den = extract_h(L_shl_o(LepsP[1],expd, &Overflow));/*expd-16*/ + den = extract_h( L_shl_o( LepsP[1], expd, &Overflow ) ); /*expd-16*/ #else - den = extract_h(L_shl(LepsP[1],expd));/*expd-16*/ + den = extract_h( L_shl( LepsP[1], expd ) ); /*expd-16*/ #endif - num = div_s(num,den);/*expn-expd+15*/ + num = div_s( num, den ); /*expn-expd+15*/ #ifdef BASOP_NOGLOB - num = shr_o(num,add(sub(expn,expd),5), &Overflow);/*Q10*/ + num = shr_o( num, add( sub( expn, expd ), 5 ), &Overflow ); /*Q10*/ #else - num = shr(num,add(sub(expn,expd),5));/*Q10*/ + num = shr( num, add( sub( expn, expd ), 5 ) ); /*Q10*/ #endif - num = sub(num,1024);/*num - 1*/ + num = sub( num, 1024 ); /*num - 1*/ test(); - IF ( NE_16(st_fx->bwidth,NB)) + IF( NE_16( st_fx->bwidth, NB ) ) { /* WB case */ /* noisiness = (Word16)(((epsP[2] / epsP[16]) - 1)*2 * 32);*/ - noisiness = shr(num,4);/*Q10 x64 -> Q0 */ + noisiness = shr( num, 4 ); /*Q10 x64 -> Q0 */ } - ELSE IF ( EQ_16(st_fx->coder_type,INACTIVE)&&EQ_16(st_fx->bwidth,NB)) + ELSE IF( EQ_16( st_fx->coder_type, INACTIVE ) && EQ_16( st_fx->bwidth, NB ) ) { /* NB GSC case */ /* noisiness = (Word16)(((epsP[2] / epsP[16]) - 1)*.25f * 32);*/ - noisiness = shr(num,4+3);/*Q10 x8 -> Q0 */ + noisiness = shr( num, 4 + 3 ); /*Q10 x8 -> Q0 */ } ELSE { /* NB case */ - noisiness = shr(num,4+2);/*Q16 x16 -> Q0 */ + noisiness = shr( num, 4 + 2 ); /*Q16 x16 -> Q0 */ } - noisiness = s_max(noisiness, 0); - noisiness = s_min(noisiness, 31); + noisiness = s_max( noisiness, 0 ); + noisiness = s_min( noisiness, 31 ); push_indice_fx( st_fx->hBstr, IND_NOISINESS, noisiness, 5 ); } @@ -111,11 +110,10 @@ void stat_noise_uv_enc_fx( * Modify the stationary noise excitation signal *-----------------------------------------------------------------*/ - stat_noise_uv_mod_fx( st_fx->coder_type, noisiness, st_fx->lsp_old_fx, isp_new, isp_mid, Aq - ,exc2, Q_new, 0, &st_fx->ge_sm_fx, &st_fx->uv_count, &st_fx->act_count, + stat_noise_uv_mod_fx( st_fx->coder_type, noisiness, st_fx->lsp_old_fx, isp_new, isp_mid, Aq, exc2, Q_new, 0, &st_fx->ge_sm_fx, &st_fx->uv_count, &st_fx->act_count, st_fx->lspold_s_fx, &st_fx->noimix_seed, &st_fx->min_alpha_fx, &st_fx->exc_pe_fx, st_fx->core_brate, st_fx->bwidth, &st_fx->Q_stat_noise, &st_fx->Q_stat_noise_ge ); - + return; } diff --git a/lib_enc/subband_fft_fx.c b/lib_enc/subband_fft_fx.c index 74c8f84ac..cee91f7ab 100644 --- a/lib_enc/subband_fft_fx.c +++ b/lib_enc/subband_fft_fx.c @@ -9,37 +9,36 @@ #include "vad_basop.h" //#include "prot_fx.h" #include "rom_enc.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*---------------------------------------------------------------------* * Local *---------------------------------------------------------------------*/ -#define RE(A) A.r -#define IM(A) A.i +#define RE( A ) A.r +#define IM( A ) A.i typedef struct { complex_16 work[32]; - complex_16 const* tab; + complex_16 const *tab; } cfft_info_16; /*-------------------------------------------------------------------* * ComplexMult_16() * *-------------------------------------------------------------------*/ static void ComplexMult_16( - Word16 *y1, - Word16 *y2, - const Word16 x1, + Word16 *y1, + Word16 *y2, + const Word16 x1, const Word16 x2, const Word16 c1, - const Word16 c2 -) + const Word16 c2 ) { - *y1 = add(mult(x1, c1) , mult(x2, c2)); + *y1 = add( mult( x1, c1 ), mult( x2, c2 ) ); move16(); - *y2 = sub(mult(x2, c1) , mult(x1, c2)); + *y2 = sub( mult( x2, c1 ), mult( x1, c2 ) ); move16(); } /*-------------------------------------------------------------------* @@ -47,8 +46,8 @@ static void ComplexMult_16( * *-------------------------------------------------------------------*/ Word16 ffr_getSfWord32( - const Word32 *vector, /*!< Pointer to input vector */ - const Word16 len /*!< Length of input vector */ + const Word32 *vector, /*!< Pointer to input vector */ + const Word16 len /*!< Length of input vector */ ) { Word32 maxVal; @@ -57,17 +56,17 @@ Word16 ffr_getSfWord32( maxVal = 0; - move32(); - FOR(i=0; ihBWE_FD; Word16 WB_fenv_fx[SWB_FENV]; - IF( EQ_32(st_fx->total_brate, ACELP_13k20)) + IF( EQ_32( st_fx->total_brate, ACELP_13k20 ) ) { /*---------------------------------------------------------------------* * Delay the original input signal to be synchronized with ACELP core synthesis *---------------------------------------------------------------------*/ - set16_fx( old_input_fx, 0, NS2SA(16000, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS) + L_FRAME16k ); - Sample_Delay_WB_BWE = NS2SA( 16000, DELAY_FD_BWE_ENC_12k8_NS); + set16_fx( old_input_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) + L_FRAME16k ); + Sample_Delay_WB_BWE = NS2SA( 16000, DELAY_FD_BWE_ENC_12k8_NS ); new_input_fx = old_input_fx + Sample_Delay_WB_BWE; - Copy(hBWE_FD->old_input_wb_fx, old_input_fx, Sample_Delay_WB_BWE ); + Copy( hBWE_FD->old_input_wb_fx, old_input_fx, Sample_Delay_WB_BWE ); Copy( new_wb_speech_fx, new_input_fx, L_FRAME16k ); Copy( old_input_fx + L_FRAME16k, hBWE_FD->old_input_wb_fx, Sample_Delay_WB_BWE ); @@ -151,31 +149,30 @@ void wb_bwe_enc_fx( new_input_fx_exp = 0; move16(); - wtda_fx(old_input_fx, &new_input_fx_exp, L_wtda_synth_fx, hBWE_FD->L_old_wtda_swb_fx, - &st_fx->Q_old_wtda,ALDO_WINDOW,ALDO_WINDOW, /* window overlap of current frame (0: full, 2: none, or 3: half) */ - L_FRAME16k ); + wtda_fx( old_input_fx, &new_input_fx_exp, L_wtda_synth_fx, hBWE_FD->L_old_wtda_swb_fx, + &st_fx->Q_old_wtda, ALDO_WINDOW, ALDO_WINDOW, /* window overlap of current frame (0: full, 2: none, or 3: half) */ + L_FRAME16k ); /* DCT of the ACELP core synthesis */ - direct_transform_fx(L_wtda_synth_fx, yorig_32, 0, L_FRAME16k, &new_input_fx_exp - , /*st_fx->element_mode*/EVS_MONO); + direct_transform_fx( L_wtda_synth_fx, yorig_32, 0, L_FRAME16k, &new_input_fx_exp, /*st_fx->element_mode*/ EVS_MONO ); /* Convert to 16 Bits (Calc Shift Required to Stay within MAX_Q_NEW_INPUT) */ - scl = sub(16+8/*MAX_Q_NEW_INPUT*/, new_input_fx_exp); + scl = sub( 16 + 8 /*MAX_Q_NEW_INPUT*/, new_input_fx_exp ); /* Possible to Upscale? */ - IF (scl > 0) + IF( scl > 0 ) { /* Yes */ /* Calc Room to Upscale */ - Q_synth = Find_Max_Norm32(yorig_32, L_FRAME16k); + Q_synth = Find_Max_Norm32( yorig_32, L_FRAME16k ); /* Stay within MAX_Q_NEW_INPUT */ - scl = s_min(Q_synth, scl); + scl = s_min( Q_synth, scl ); } - Copy_Scale_sig32_16(yorig_32, yorig_fx, L_FRAME16k, scl); - Q_synth = add(sub(new_input_fx_exp, 16), scl) - 1; + Copy_Scale_sig32_16( yorig_32, yorig_fx, L_FRAME16k, scl ); + Q_synth = add( sub( new_input_fx_exp, 16 ), scl ) - 1; - mode = WB_BWE_encoding_fx( coder_type, yorig_fx, WB_fenv_fx, st_fx, Q_synth, Q_synth); - push_indice_fx(st_fx->hBstr, IND_WB_CLASS, mode - 2, 1 ); + mode = WB_BWE_encoding_fx( coder_type, yorig_fx, WB_fenv_fx, st_fx, Q_synth, Q_synth ); + push_indice_fx( st_fx->hBstr, IND_WB_CLASS, mode - 2, 1 ); } hBWE_FD->prev_mode = mode; @@ -184,21 +181,20 @@ void wb_bwe_enc_fx( } /*-------------------------------------------------------------------* -* swb_bwe_enc() -* -* SWB BWE encoder (only for 32kHz signals) -*-------------------------------------------------------------------*/ + * swb_bwe_enc() + * + * SWB BWE encoder (only for 32kHz signals) + *-------------------------------------------------------------------*/ void swb_bwe_enc_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - Word16 *old_input_12k8_fx, /* i : input signal @12.8kHz for SWB BWE */ - Word16 *old_input_16k_fx, /* i : input signal @16kHz for SWB BWE */ - const Word16 *old_syn_12k8_16k_fx, /* i : ACELP core synthesis at 12.8kHz or 16kHz */ - const Word16 *new_swb_speech_fx, /* i : original input signal at 32kHz */ - Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz */ - const Word16 coder_type, /* i : coding type */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + Word16 *old_input_12k8_fx, /* i : input signal @12.8kHz for SWB BWE */ + Word16 *old_input_16k_fx, /* i : input signal @16kHz for SWB BWE */ + const Word16 *old_syn_12k8_16k_fx, /* i : ACELP core synthesis at 12.8kHz or 16kHz */ + const Word16 *new_swb_speech_fx, /* i : original input signal at 32kHz */ + Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz */ + const Word16 coder_type, /* i : coding type */ Word16 Q_shb_speech, - Word16 Q_slb_speech -) + Word16 Q_slb_speech ) { Word16 i; Word16 *new_input_fx; @@ -207,9 +203,9 @@ void swb_bwe_enc_fx( Word32 L_tmp; Word16 inner_frame; Word32 inner_Fs; - Word32 L_old_input_fx[2*L_FRAME48k]; + Word32 L_old_input_fx[2 * L_FRAME48k]; Word32 yorig_32[L_FRAME48k]; - Word16 old_input_fx[NS2SA(48000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS) + L_FRAME48k]; + Word16 old_input_fx[NS2SA( 48000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS ) + L_FRAME48k]; Word16 old_input_lp_fx[L_FRAME16k]; Word16 new_input_hp_fx[L_FRAME16k]; Word16 yorig_fx[L_FRAME48k]; @@ -237,7 +233,7 @@ void swb_bwe_enc_fx( /*---------------------------------------------------------------------* * Delay the original input signal to be synchronized with ACELP core synthesis *---------------------------------------------------------------------*/ - IF( EQ_16(st_fx->extl, FB_BWE)) + IF( EQ_16( st_fx->extl, FB_BWE ) ) { inner_frame = L_FRAME48k; inner_Fs = 48000; @@ -248,41 +244,41 @@ void swb_bwe_enc_fx( inner_Fs = 32000; } - set16_fx( old_input_fx, 0, add(NS2SA(inner_Fs, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS), inner_frame) ); + set16_fx( old_input_fx, 0, add( NS2SA( inner_Fs, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ), inner_frame ) ); - IF( EQ_16(st_fx->L_frame, L_FRAME)) + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { - Sample_Delay_SWB_BWE = NS2SA(inner_Fs, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS); - Sample_Delay_HP = NS2SA(16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS); - Sample_Delay_LP = NS2SA(12800, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS); + Sample_Delay_SWB_BWE = NS2SA( inner_Fs, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ); + Sample_Delay_HP = NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS ); + Sample_Delay_LP = NS2SA( 12800, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS ); - delay_input_signal_fx(hBWE_FD->old_input_lp_fx, old_input_lp_fx, &old_input_12k8_fx[L_INP_MEM], Sample_Delay_LP, L_FRAME, &hBWE_FD->prev_Q_input_lp, &Q_slb_speech ); + delay_input_signal_fx( hBWE_FD->old_input_lp_fx, old_input_lp_fx, &old_input_12k8_fx[L_INP_MEM], Sample_Delay_LP, L_FRAME, &hBWE_FD->prev_Q_input_lp, &Q_slb_speech ); } ELSE { - Sample_Delay_SWB_BWE = NS2SA(inner_Fs, DELAY_FD_BWE_ENC_16k_NS + DELAY_FIR_RESAMPL_NS); - Sample_Delay_HP = NS2SA(16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_16k_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS); - Sample_Delay_LP = NS2SA(16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_16k_NS); + Sample_Delay_SWB_BWE = NS2SA( inner_Fs, DELAY_FD_BWE_ENC_16k_NS + DELAY_FIR_RESAMPL_NS ); + Sample_Delay_HP = NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_16k_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS ); + Sample_Delay_LP = NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_16k_NS ); - delay_input_signal_fx(hBWE_FD->old_input_lp_fx, old_input_lp_fx, &old_input_16k_fx[L_INP_MEM], Sample_Delay_LP, L_FRAME16k, &hBWE_FD->prev_Q_input_lp, &Q_slb_speech ); + delay_input_signal_fx( hBWE_FD->old_input_lp_fx, old_input_lp_fx, &old_input_16k_fx[L_INP_MEM], Sample_Delay_LP, L_FRAME16k, &hBWE_FD->prev_Q_input_lp, &Q_slb_speech ); } - Copy(hBWE_FD->new_input_hp_fx, new_input_hp_fx, Sample_Delay_HP); - Copy( shb_speech_fx, &new_input_hp_fx[Sample_Delay_HP], L_FRAME16k-Sample_Delay_HP ); - Copy( shb_speech_fx + L_FRAME16k-Sample_Delay_HP, hBWE_FD->new_input_hp_fx, Sample_Delay_HP ); + Copy( hBWE_FD->new_input_hp_fx, new_input_hp_fx, Sample_Delay_HP ); + Copy( shb_speech_fx, &new_input_hp_fx[Sample_Delay_HP], L_FRAME16k - Sample_Delay_HP ); + Copy( shb_speech_fx + L_FRAME16k - Sample_Delay_HP, hBWE_FD->new_input_hp_fx, Sample_Delay_HP ); new_input_fx = old_input_fx + Sample_Delay_SWB_BWE; - Copy(hBWE_FD->old_input_fx, old_input_fx, Sample_Delay_SWB_BWE ); + Copy( hBWE_FD->old_input_fx, old_input_fx, Sample_Delay_SWB_BWE ); Copy( new_swb_speech_fx, new_input_fx, inner_frame ); Copy( old_input_fx + inner_frame, hBWE_FD->old_input_fx, Sample_Delay_SWB_BWE ); /*----------------------------------------------------------------------* - * Calculate tilt of the input signal and the ACELP core synthesis - *----------------------------------------------------------------------*/ + * Calculate tilt of the input signal and the ACELP core synthesis + *----------------------------------------------------------------------*/ /* tilt returned in Q24 goto to Q11 */ #ifdef BASOP_NOGLOB - tilt_nb_fx = round_fx_o(L_shl_o(calc_tilt_bwe_fx(old_input_lp_fx, Q_slb_speech, st_fx->L_frame), 3, &Overflow), &Overflow); + tilt_nb_fx = round_fx_o( L_shl_o( calc_tilt_bwe_fx( old_input_lp_fx, Q_slb_speech, st_fx->L_frame ), 3, &Overflow ), &Overflow ); #else - tilt_nb_fx = round_fx(L_shl(calc_tilt_bwe_fx(old_input_lp_fx, Q_slb_speech, st_fx->L_frame), 3)); + tilt_nb_fx = round_fx( L_shl( calc_tilt_bwe_fx( old_input_lp_fx, Q_slb_speech, st_fx->L_frame ), 3 ) ); #endif /*---------------------------------------------------------------------* * SWB BWE encoding @@ -290,33 +286,32 @@ void swb_bwe_enc_fx( *---------------------------------------------------------------------*/ new_input_fx_exp = 0; /* MDCT of the core synthesis signal */ - wtda_fx(old_input_fx, &new_input_fx_exp, L_old_input_fx, hBWE_FD->L_old_wtda_swb_fx, - &st_fx->Q_old_wtda, ALDO_WINDOW, ALDO_WINDOW, /* window overlap of current frame (0: full, 2: none, or 3: half) */ - inner_frame ); + wtda_fx( old_input_fx, &new_input_fx_exp, L_old_input_fx, hBWE_FD->L_old_wtda_swb_fx, + &st_fx->Q_old_wtda, ALDO_WINDOW, ALDO_WINDOW, /* window overlap of current frame (0: full, 2: none, or 3: half) */ + inner_frame ); /* DCT of the ACELP core synthesis */ - direct_transform_fx(L_old_input_fx, yorig_32, 0, inner_frame, &new_input_fx_exp - , /*st_fx->element_mode*/EVS_MONO); + direct_transform_fx( L_old_input_fx, yorig_32, 0, inner_frame, &new_input_fx_exp, /*st_fx->element_mode*/ EVS_MONO ); /* Convert to 16 Bits (Calc Shift Required to Stay within MAX_Q_NEW_INPUT) */ - scl = sub(16+8, new_input_fx_exp); + scl = sub( 16 + 8, new_input_fx_exp ); /* Possible to Upscale? */ - IF (scl > 0) + IF( scl > 0 ) { /* Yes */ /* Calc Room to Upscale */ - Q_synth = Find_Max_Norm32(yorig_32, inner_frame); + Q_synth = Find_Max_Norm32( yorig_32, inner_frame ); /* Stay within MAX_Q_NEW_INPUT */ - scl = s_min(Q_synth, scl); + scl = s_min( Q_synth, scl ); } - Copy_Scale_sig32_16(yorig_32, yorig_fx, inner_frame, scl); - Q_synth = add(sub(new_input_fx_exp, 16), scl); + Copy_Scale_sig32_16( yorig_32, yorig_fx, inner_frame, scl ); + Q_synth = add( sub( new_input_fx_exp, 16 ), scl ); max = 0; move16(); Q_synth_hf = 0; move16(); - IF (EQ_16(st_fx->L_frame, L_FRAME16k)) + IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { scl = 300; move16(); @@ -326,90 +321,89 @@ void swb_bwe_enc_fx( scl = 240; move16(); } - FOR(i=scl; ilast_extl, SWB_BWE)||EQ_16(st_fx->last_extl,FB_BWE)) + Copy_Scale_sig( &yorig_fx[scl], &yorig_fx[scl], sub( inner_frame, scl ), exp ); + Q_synth_hf = add( exp, Q_synth ); + IF( EQ_16( st_fx->last_extl, SWB_BWE ) || EQ_16( st_fx->last_extl, FB_BWE ) ) { - exp = norm_l(st_fx->EnergyLT_fx); - IF(add(st_fx->EnergyLT_fx_exp, exp) > shl(sub(Q_synth_hf, 4), 1)) + exp = norm_l( st_fx->EnergyLT_fx ); + IF( add( st_fx->EnergyLT_fx_exp, exp ) > shl( sub( Q_synth_hf, 4 ), 1 ) ) { - Q_shb = sub(Q_synth_hf, 4); - st_fx->EnergyLT_fx = L_shr(st_fx->EnergyLT_fx, sub(st_fx->EnergyLT_fx_exp, shl(Q_shb, 1))); + Q_shb = sub( Q_synth_hf, 4 ); + st_fx->EnergyLT_fx = L_shr( st_fx->EnergyLT_fx, sub( st_fx->EnergyLT_fx_exp, shl( Q_shb, 1 ) ) ); } ELSE { - Q_shb = shr(add(st_fx->EnergyLT_fx_exp, exp), 1); - IF(s_and(exp, 0x0001) == 1) + Q_shb = shr( add( st_fx->EnergyLT_fx_exp, exp ), 1 ); + IF( s_and( exp, 0x0001 ) == 1 ) { - exp = sub(exp, 1); + exp = sub( exp, 1 ); } - st_fx->EnergyLT_fx = L_shl(st_fx->EnergyLT_fx, exp); + st_fx->EnergyLT_fx = L_shl( st_fx->EnergyLT_fx, exp ); } } ELSE { - Q_shb = sub(Q_synth_hf, 4); + Q_shb = sub( Q_synth_hf, 4 ); } - Copy_Scale_sig(new_input_hp_fx, new_input_hp_fx, L_FRAME16k, sub(Q_shb, Q_shb_speech)); + Copy_Scale_sig( new_input_hp_fx, new_input_hp_fx, L_FRAME16k, sub( Q_shb, Q_shb_speech ) ); /* SWB BWE encoding */ - IF (EQ_16(st_fx->L_frame, L_FRAME16k)) + IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { SWB_BWE_encoding_fx( st_fx, old_input_fx, old_input_lp_fx, new_input_hp_fx, old_syn_12k8_16k_fx, yorig_fx, SWB_fenv_fx, tilt_nb_fx, 80, coder_type, Q_slb_speech, Q_shb, Q_synth_hf, Q_synth ); - } ELSE { SWB_BWE_encoding_fx( st_fx, old_input_fx, old_input_lp_fx, new_input_hp_fx, old_syn_12k8_16k_fx, yorig_fx, - SWB_fenv_fx, tilt_nb_fx, 6, coder_type, Q_slb_speech, Q_shb, Q_synth_hf, Q_synth ); + SWB_fenv_fx, tilt_nb_fx, 6, coder_type, Q_slb_speech, Q_shb, Q_synth_hf, Q_synth ); } /* FB BWE encoding */ - IF ( EQ_16(st_fx->extl, FB_BWE)) + IF( EQ_16( st_fx->extl, FB_BWE ) ) { - energy_fbe_fb_fx = L_deposit_l(0); - FOR( i=FB_BAND_BEGIN; i45-(exp+2*(Q_synth_hf-4)) */ - L_tmp = Mult_32_16(ener_low_fx, tmp); /*45-(exp+2*(Q_synth_hf-4)) + 2*(Q_synth_hf-4) - 15 = 30-exp */ - exp1 = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, exp1); - exp = 31-exp1-(30-exp); - L_tmp = Isqrt_lc(L_tmp, &exp); /*31-exp */ + exp = norm_l( energy_fbe_fb_fx ); + frac = extract_h( L_shl( energy_fbe_fb_fx, exp ) ); + tmp = div_s( 16384, frac ); /*15+14-(exp+2*(Q_synth_hf-4)-16) -->45-(exp+2*(Q_synth_hf-4)) */ + L_tmp = Mult_32_16( ener_low_fx, tmp ); /*45-(exp+2*(Q_synth_hf-4)) + 2*(Q_synth_hf-4) - 15 = 30-exp */ + exp1 = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, exp1 ); + exp = 31 - exp1 - ( 30 - exp ); + L_tmp = Isqrt_lc( L_tmp, &exp ); /*31-exp */ #ifdef BASOP_NOGLOB - fb_ener_adjust_fx = round_fx_o(L_shl_o(L_tmp, exp, &Overflow), &Overflow); /*Q15 */ + fb_ener_adjust_fx = round_fx_o( L_shl_o( L_tmp, exp, &Overflow ), &Overflow ); /*Q15 */ #else - fb_ener_adjust_fx = round_fx(L_shl(L_tmp, exp)); /*Q15 */ + fb_ener_adjust_fx = round_fx( L_shl( L_tmp, exp ) ); /*Q15 */ #endif } ELSE @@ -418,14 +412,14 @@ void swb_bwe_enc_fx( move16(); } - fb_ener_adjust_fx = s_min(fb_ener_adjust_fx, 16384); /*Q15 */ - idxGain = usquant_fx( fb_ener_adjust_fx, &ener_adjust_quan_fx, 0, 512, shl(1, NUM_BITS_FB_FRAMEGAIN) ); + fb_ener_adjust_fx = s_min( fb_ener_adjust_fx, 16384 ); /*Q15 */ + idxGain = usquant_fx( fb_ener_adjust_fx, &ener_adjust_quan_fx, 0, 512, shl( 1, NUM_BITS_FB_FRAMEGAIN ) ); } /* write FB BWE frame gain to the bitstream */ - IF( EQ_16(st_fx->extl, FB_BWE)) + IF( EQ_16( st_fx->extl, FB_BWE ) ) { - push_indice_fx(st_fx->hBstr, IND_FB_SLOPE, idxGain, NUM_BITS_FB_FRAMEGAIN ); + push_indice_fx( st_fx->hBstr, IND_FB_SLOPE, idxGain, NUM_BITS_FB_FRAMEGAIN ); } return; @@ -450,65 +444,64 @@ void swb_bwe_enc_fx( /*--------------------------------------------------------------------------*/ /* */ /*==========================================================================*/ -static Word16 WB_BWE_fenv_q_fx( /* o: quantized gain index */ - Word16 *x, /* i/o: energy of WB envelop Q10*/ - const Word16 *cb, /* i: quantizer codebook Q10 */ - const Word16 cb_length, /* i: length of codebook */ - const Word16 cb_dim /* i: dimension of codebook */ +static Word16 WB_BWE_fenv_q_fx( /* o: quantized gain index */ + Word16 *x, /* i/o: energy of WB envelop Q10*/ + const Word16 *cb, /* i: quantizer codebook Q10 */ + const Word16 cb_length, /* i: length of codebook */ + const Word16 cb_dim /* i: dimension of codebook */ ) { Word16 i, j, indx = 0; Word32 dist, min_dist; - const Word16 *pit = cb;/*Q10 */ + const Word16 *pit = cb; /*Q10 */ Word16 tmp; Word32 L_tmp; - min_dist = L_add(MAX_32, 0); - FOR (i=0; iQ20 */ - dist = L_add_sat(dist, L_tmp); + tmp = sub_sat( x[j], *pit ); /*Q10 */ + L_tmp = L_mult0( tmp, tmp ); /*Q(10+10)->Q20 */ + dist = L_add_sat( dist, L_tmp ); #else - tmp = sub(x[j], *pit);/*Q10 */ - L_tmp = L_mult0(tmp, tmp);/*Q(10+10)->Q20 */ - dist = L_add(dist, L_tmp); + tmp = sub( x[j], *pit ); /*Q10 */ + L_tmp = L_mult0( tmp, tmp ); /*Q(10+10)->Q20 */ + dist = L_add( dist, L_tmp ); #endif pit++; } - IF( LT_32(dist,min_dist)) + IF( LT_32( dist, min_dist ) ) { - min_dist = L_add(dist, 0); + min_dist = L_add( dist, 0 ); indx = i; move16(); } } - FOR(j=0; jextl, SWB_BWE)||EQ_16(st_fx->extl,FB_BWE)) + IF( EQ_16( st_fx->extl, SWB_BWE ) || EQ_16( st_fx->extl, FB_BWE ) ) { input_hi = &fSpectrum[256]; move16(); @@ -644,143 +637,143 @@ static Word16 FD_BWE_class_fx( /* o : FD BWE class */ test(); test(); test(); - IF ( ( EQ_16(st_fx->last_extl, SWB_BWE)&&EQ_16(st_fx->extl,SWB_BWE))||(EQ_16(st_fx->last_extl,FB_BWE)&&EQ_16(st_fx->extl,FB_BWE))) + IF( ( EQ_16( st_fx->last_extl, SWB_BWE ) && EQ_16( st_fx->extl, SWB_BWE ) ) || ( EQ_16( st_fx->last_extl, FB_BWE ) && EQ_16( st_fx->extl, FB_BWE ) ) ) { - IF(hBWE_FD->prev_global_gain_fx == 0) + IF( hBWE_FD->prev_global_gain_fx == 0 ) { #ifdef BASOP_NOGLOB - gain_tmp = round_fx_o(L_shl_o(fGain, 30, &Overflow), &Overflow); /*Q14 */ + gain_tmp = round_fx_o( L_shl_o( fGain, 30, &Overflow ), &Overflow ); /*Q14 */ #else - gain_tmp = round_fx(L_shl(fGain, 30)); /*Q14 */ + gain_tmp = round_fx( L_shl( fGain, 30 ) ); /*Q14 */ #endif } ELSE { - expn = norm_l(fGain); + expn = norm_l( fGain ); #ifdef BASOP_NOGLOB - num = extract_h(L_shl_o(fGain, expn, &Overflow)); + num = extract_h( L_shl_o( fGain, expn, &Overflow ) ); #else - num = extract_h(L_shl(fGain, expn)); + num = extract_h( L_shl( fGain, expn ) ); #endif - expn = sub(sub(30, expn), shl(Q_shb,1)); + expn = sub( sub( 30, expn ), shl( Q_shb, 1 ) ); - expd = norm_l(hBWE_FD->prev_global_gain_fx); + expd = norm_l( hBWE_FD->prev_global_gain_fx ); #ifdef BASOP_NOGLOB - den = extract_h(L_shl_o(hBWE_FD->prev_global_gain_fx, expd, &Overflow)); + den = extract_h( L_shl_o( hBWE_FD->prev_global_gain_fx, expd, &Overflow ) ); #else - den = extract_h(L_shl(hBWE_FD->prev_global_gain_fx, expd)); + den = extract_h( L_shl( hBWE_FD->prev_global_gain_fx, expd ) ); #endif - expd = sub(sub(30, expd), shl(st_fx->prev_Q_shb,1)); + expd = sub( sub( 30, expd ), shl( st_fx->prev_Q_shb, 1 ) ); - scale = shr(sub(den, num), 15); + scale = shr( sub( den, num ), 15 ); #ifdef BASOP_NOGLOB - num = shl_o(num, scale, &Overflow); + num = shl_o( num, scale, &Overflow ); #else - num = shl(num, scale); + num = shl( num, scale ); #endif - expn = sub(expn, scale); + expn = sub( expn, scale ); - tmp = div_s(num, den); - expn = sub(expn, expd); + tmp = div_s( num, den ); + expn = sub( expn, expd ); #ifdef BASOP_NOGLOB - gain_tmp = shl_o(tmp, sub(expn,1), &Overflow);/*Q14 */ + gain_tmp = shl_o( tmp, sub( expn, 1 ), &Overflow ); /*Q14 */ #else - gain_tmp = shl(tmp, sub(expn,1));/*Q14 */ + gain_tmp = shl( tmp, sub( expn, 1 ) ); /*Q14 */ #endif } test(); - IF (EQ_16(hBWE_FD->prev_mode,TRANSIENT)) + IF( EQ_16( hBWE_FD->prev_mode, TRANSIENT ) ) { - numharmonic = shl(numharmonic, 1); + numharmonic = shl( numharmonic, 1 ); } - ELSE IF (EQ_16(hBWE_FD->prev_mode, NORMAL)||EQ_16(hBWE_FD->prev_mode,NOISE)) + ELSE IF( EQ_16( hBWE_FD->prev_mode, NORMAL ) || EQ_16( hBWE_FD->prev_mode, NOISE ) ) { - numharmonic = add(shr(numharmonic, 1), numharmonic); + numharmonic = add( shr( numharmonic, 1 ), numharmonic ); } } ELSE { gain_tmp = 16384; move16(); - IF (EQ_16(hBWE_FD->prev_mode, HARMONIC)) + IF( EQ_16( hBWE_FD->prev_mode, HARMONIC ) ) { - numharmonic = shr(numharmonic, 1); - sharplimit = shr(sharplimit, 1); + numharmonic = shr( numharmonic, 1 ); + sharplimit = shr( sharplimit, 1 ); } ELSE { - numharmonic = shl(numharmonic, 1); - sharplimit = shl(sharplimit, 1); + numharmonic = shl( numharmonic, 1 ); + sharplimit = shl( sharplimit, 1 ); } } } - ELSE IF (EQ_16(st_fx->extl, WB_BWE)) + ELSE IF( EQ_16( st_fx->extl, WB_BWE ) ) { input_hi = &fSpectrum[224]; move16(); numsharp = 3; move16(); - IF (EQ_16(hBWE_FD->prev_mode, HARMONIC)) + IF( EQ_16( hBWE_FD->prev_mode, HARMONIC ) ) { - numharmonic = shr(numharmonic, 2); + numharmonic = shr( numharmonic, 2 ); } ELSE { - numharmonic = shr(numharmonic, 1); + numharmonic = shr( numharmonic, 1 ); } - IF (NE_16(st_fx->last_extl, WB_BWE)) + IF( NE_16( st_fx->last_extl, WB_BWE ) ) { - IF (EQ_16(hBWE_FD->prev_mode, HARMONIC)) + IF( EQ_16( hBWE_FD->prev_mode, HARMONIC ) ) { - sharplimit = shr(sharplimit, 1); + sharplimit = shr( sharplimit, 1 ); } ELSE { - sharplimit = shl(sharplimit, 1); + sharplimit = shl( sharplimit, 1 ); } } } - L_meanH = L_deposit_l(0); - FOR(i = 0; i < numsharp; i ++) + L_meanH = L_deposit_l( 0 ); + FOR( i = 0; i < numsharp; i++ ) { peak = 0; move16(); - mean[i] = L_deposit_l(0); + mean[i] = L_deposit_l( 0 ); - FOR(j = 0; j < SHARP_WIDTH; j ++) + FOR( j = 0; j < SHARP_WIDTH; j++ ) { - mag = abs_s(*input_hi); - IF (GT_16(mag, peak)) + mag = abs_s( *input_hi ); + IF( GT_16( mag, peak ) ) { peak = mag; - move16();/*Q_syn */ + move16(); /*Q_syn */ } - mean[i] = L_add(mean[i], mag); - move32();/*Q_syn */ - input_hi ++; + mean[i] = L_add( mean[i], mag ); + move32(); /*Q_syn */ + input_hi++; } - L_meanH = L_add(L_meanH, mean[i]);/*Q_syn */ + L_meanH = L_add( L_meanH, mean[i] ); /*Q_syn */ - IF(NE_32(mean[i], L_deposit_l(peak))) + IF( NE_32( mean[i], L_deposit_l( peak ) ) ) { - L_tmp = L_sub(mean[i], peak);/*Q_syn */ - L_tmp = Mult_32_16(L_tmp, 16913); /* 1/31->Q19 -> Q_syn+19-15 */ - den = extract_l(L_shr(L_tmp, 4)); /*Q_syn */ - IF(den == 0) + L_tmp = L_sub( mean[i], peak ); /*Q_syn */ + L_tmp = Mult_32_16( L_tmp, 16913 ); /* 1/31->Q19 -> Q_syn+19-15 */ + den = extract_l( L_shr( L_tmp, 4 ) ); /*Q_syn */ + IF( den == 0 ) { den = 1; move16(); } - expd = norm_s(den); - tmp = div_s(shl(1,sub(14,expd)), den); /*Q(29-expd-Q_syn) */ - L_tmp = L_mult(tmp, peak); /*Q(30-expd) */ + expd = norm_s( den ); + tmp = div_s( shl( 1, sub( 14, expd ) ), den ); /*Q(29-expd-Q_syn) */ + L_tmp = L_mult( tmp, peak ); /*Q(30-expd) */ #ifdef BASOP_NOGLOB - sharp = round_fx_o(L_shl_o(L_tmp, sub(expd, 4), &Overflow), &Overflow);/*Q10 */ + sharp = round_fx_o( L_shl_o( L_tmp, sub( expd, 4 ), &Overflow ), &Overflow ); /*Q10 */ #else - sharp = round_fx(L_shl(L_tmp, sub(expd, 4)));/*Q10 */ + sharp = round_fx( L_shl( L_tmp, sub( expd, 4 ) ) ); /*Q10 */ #endif } ELSE @@ -791,33 +784,33 @@ static Word16 FD_BWE_class_fx( /* o : FD BWE class */ test(); #ifdef BASOP_NOGLOB - IF (GT_16(sharp, 4608)&>_16(peak,shl_o(1,add(Q_syn,3), &Overflow))) + IF( GT_16( sharp, 4608 ) && GT_16( peak, shl_o( 1, add( Q_syn, 3 ), &Overflow ) ) ) #else - IF (GT_16(sharp, 4608)&>_16(peak,shl(1,add(Q_syn,3)))) + IF( GT_16( sharp, 4608 ) && GT_16( peak, shl( 1, add( Q_syn, 3 ) ) ) ) #endif { - k = add(k, 1); + k = add( k, 1 ); move16(); } - ELSE IF (LT_16(sharp, 3072)) + ELSE IF( LT_16( sharp, 3072 ) ) { - noise = add(noise, 1); + noise = add( noise, 1 ); move16(); } - IF (GT_16(sharp, sharpPeak)) + IF( GT_16( sharp, sharpPeak ) ) { sharpPeak = sharp; move16(); } } test(); - IF ( EQ_16(st_fx->extl, SWB_BWE)||EQ_16(st_fx->extl,FB_BWE)) + IF( EQ_16( st_fx->extl, SWB_BWE ) || EQ_16( st_fx->extl, FB_BWE ) ) { test(); test(); test(); - IF(GE_16(k, numharmonic)&>_16(gain_tmp,8192)&<_16(gain_tmp,29491)&>_16(sharpPeak,shl(sharplimit,10))) + IF( GE_16( k, numharmonic ) && GT_16( gain_tmp, 8192 ) && LT_16( gain_tmp, 29491 ) && GT_16( sharpPeak, shl( sharplimit, 10 ) ) ) { sharpMod = 1; move16(); @@ -828,19 +821,19 @@ static Word16 FD_BWE_class_fx( /* o : FD BWE class */ move16(); } - L_meanH = Mult_32_16(L_meanH, 29127); /*Q_syn+8 */ + L_meanH = Mult_32_16( L_meanH, 29127 ); /*Q_syn+8 */ L_mean_d = 0; move16(); - FOR(i=0; iextl, WB_BWE)) + ELSE IF( EQ_16( st_fx->extl, WB_BWE ) ) { test(); - IF (GE_16(k,numharmonic)&>_16(sharpPeak,shl(sharplimit,10))) + IF( GE_16( k, numharmonic ) && GT_16( sharpPeak, shl( sharplimit, 10 ) ) ) { sharpMod = 1; move16(); @@ -854,52 +847,52 @@ static Word16 FD_BWE_class_fx( /* o : FD BWE class */ test(); test(); - IF (sharpMod && LT_16(hBWE_FD->modeCount, 12)) + IF( sharpMod && LT_16( hBWE_FD->modeCount, 12 ) ) { - hBWE_FD->modeCount = add(hBWE_FD->modeCount, 1); + hBWE_FD->modeCount = add( hBWE_FD->modeCount, 1 ); } - ELSE IF (sharpMod == 0 && hBWE_FD->modeCount > 0) + ELSE IF( sharpMod == 0 && hBWE_FD->modeCount > 0 ) { - hBWE_FD->modeCount = sub(hBWE_FD->modeCount, 1); + hBWE_FD->modeCount = sub( hBWE_FD->modeCount, 1 ); } - IF (GE_16(hBWE_FD->modeCount, 2)) + IF( GE_16( hBWE_FD->modeCount, 2 ) ) { sharpMod = 1; move16(); } test(); - IF (sharpMod) + IF( sharpMod ) { mode = HARMONIC; move16(); } - ELSE IF ( EQ_16(st_fx->extl, SWB_BWE)||EQ_16(st_fx->extl,FB_BWE)) + ELSE IF( EQ_16( st_fx->extl, SWB_BWE ) || EQ_16( st_fx->extl, FB_BWE ) ) { - L_tmp = Mult_32_16(L_mean_d, 6827); /*Q_syn+8 ; 1/4.8 in Q15 */ + L_tmp = Mult_32_16( L_mean_d, 6827 ); /*Q_syn+8 ; 1/4.8 in Q15 */ test(); test(); test(); - IF (GT_16(noise, 4)&&(LT_32(L_tmp,L_meanH)||L_meanH==0)&<_16(tilt_nb,10240)) + IF( GT_16( noise, 4 ) && ( LT_32( L_tmp, L_meanH ) || L_meanH == 0 ) && LT_16( tilt_nb, 10240 ) ) { mode = NOISE; move16(); } } - return (mode); + return ( mode ); } /*-------------------------------------------------------------------* -* freq_weights_fx() -* -*-------------------------------------------------------------------*/ + * freq_weights_fx() + * + *-------------------------------------------------------------------*/ static void freq_weights_fx( - const Word16 Band_Ener[], /* i : Band energy Q8 */ - const Word16 f_weighting[], /* i : weigting coefs. Q15 */ - Word16 w_env[], /* o : Freq. weighting Q13 */ - const Word16 Nbands /* i : Number of bands */ + const Word16 Band_Ener[], /* i : Band energy Q8 */ + const Word16 f_weighting[], /* i : weigting coefs. Q15 */ + Word16 w_env[], /* o : Freq. weighting Q13 */ + const Word16 Nbands /* i : Number of bands */ ) { Word16 i; @@ -913,31 +906,31 @@ static void freq_weights_fx( move16(); max_b = Band_Ener[0]; move16(); - FOR( i=1; i k; l-- ) { @@ -1043,9 +1036,9 @@ static void vqWithCand_w_fx( } ELSE { - set32_fx( dist_min, MAX_32, surv ); /* FLT_MAX */ + set32_fx( dist_min, MAX_32, surv ); /* FLT_MAX */ - FOR (i = 0; i < surv; i++) + FOR( i = 0; i < surv; i++ ) { index[i] = i; move16(); @@ -1061,25 +1054,25 @@ static void vqWithCand_w_fx( #else dist = sub( x[0], *p_E_ROM_dico++ ); /*Q8 */ #endif - L_dist = L_mult(dist,dist);/*Q17 */ - L_dist = L_shr(L_dist,12);/*Q5 */ + L_dist = L_mult( dist, dist ); /*Q17 */ + L_dist = L_shr( L_dist, 12 ); /*Q5 */ FOR( j = 1; j < dim; j++ ) { - temp1 = sub(x[j],*p_E_ROM_dico++);/*Q8 */ - L_tmp = L_mult(temp1,temp1);/*Q17 */ - L_dist = L_add(L_dist,L_shr(L_tmp,12));/*Q5 */ + temp1 = sub( x[j], *p_E_ROM_dico++ ); /*Q8 */ + L_tmp = L_mult( temp1, temp1 ); /*Q17 */ + L_dist = L_add( L_dist, L_shr( L_tmp, 12 ) ); /*Q5 */ } FOR( k = 0; k < surv; k++ ) { - IF( LT_32(L_dist,dist_min[k])) + IF( LT_32( L_dist, dist_min[k] ) ) { FOR( l = surv - 1; l > k; l-- ) { - dist_min[l] = dist_min[l-1]; + dist_min[l] = dist_min[l - 1]; move32(); - index[l] = index[l-1]; + index[l] = index[l - 1]; move16(); } dist_min[k] = L_dist; @@ -1096,28 +1089,28 @@ static void vqWithCand_w_fx( } /*-------------------------------------------------------------------* -* vqSimple_w_fx() -* -*-------------------------------------------------------------------*/ + * vqSimple_w_fx() + * + *-------------------------------------------------------------------*/ static Word16 vqSimple_w_fx( - const Word16 *x, /* i : input for quantizer Q8 */ - Word16 *y, /* i : quantized value Q8 */ - const Word16 *cb, /* i : codebooks Q8 */ - const Word16 *w, /* i : weight Q13 */ - const Word16 dim, /* i : dimension */ - const Word16 l, /* i : number of candidates */ - const Word16 flag /* i : flag indicationg weighted distortion metric */ + const Word16 *x, /* i : input for quantizer Q8 */ + Word16 *y, /* i : quantized value Q8 */ + const Word16 *cb, /* i : codebooks Q8 */ + const Word16 *w, /* i : weight Q13 */ + const Word16 dim, /* i : dimension */ + const Word16 l, /* i : number of candidates */ + const Word16 flag /* i : flag indicationg weighted distortion metric */ ) { Word16 i, j, index; const Word16 *cbP; Word16 dist, temp; - Word32 L_dist,L_tmp,L_dist_min; + Word32 L_dist, L_tmp, L_dist_min; index = 0; move16(); - L_dist_min = L_add(MAX_32, 0); /* FLT_MAX */ + L_dist_min = L_add( MAX_32, 0 ); /* FLT_MAX */ cbP = cb; move16(); IF( flag ) @@ -1126,23 +1119,23 @@ static Word16 vqSimple_w_fx( { /*dist = x[0] - *cbP++; */ /*dist *= (dist * w[0]); */ - dist = sub(x[0],*cbP++);/*Q8 */ - L_dist = L_mult(dist,w[0]);/*Q22 */ - L_dist = Mult_32_16(L_dist,dist);/*Q15 */ - L_dist = L_shr(L_dist,10);/*Q5 */ + dist = sub( x[0], *cbP++ ); /*Q8 */ + L_dist = L_mult( dist, w[0] ); /*Q22 */ + L_dist = Mult_32_16( L_dist, dist ); /*Q15 */ + L_dist = L_shr( L_dist, 10 ); /*Q5 */ FOR( j = 1; j < dim; j++ ) { /*temp = x[j] - *cbP++; */ /*dist += temp * temp * w[j]; */ - temp = sub(x[j],*cbP++); - L_tmp = L_mult(temp,w[j]);/*Q22 */ - L_tmp = Mult_32_16(L_tmp,temp);/*Q15 */ - L_dist = L_add(L_dist,L_shr(L_tmp,10));/*Q5 */ + temp = sub( x[j], *cbP++ ); + L_tmp = L_mult( temp, w[j] ); /*Q22 */ + L_tmp = Mult_32_16( L_tmp, temp ); /*Q15 */ + L_dist = L_add( L_dist, L_shr( L_tmp, 10 ) ); /*Q5 */ } - IF (LT_32(L_dist, L_dist_min)) + IF( LT_32( L_dist, L_dist_min ) ) { - L_dist_min = L_add(L_dist, 0);/*Q5 */ + L_dist_min = L_add( L_dist, 0 ); /*Q5 */ index = i; move16(); } @@ -1153,22 +1146,22 @@ static Word16 vqSimple_w_fx( FOR( i = 0; i < l; i++ ) { /*dist = x[0] - *cbP++; */ - dist = sub(x[0],*cbP++); + dist = sub( x[0], *cbP++ ); /*dist *= dist; */ - L_dist = L_mult(dist,dist);/*Q17 */ - L_dist = L_shr(L_dist,12); + L_dist = L_mult( dist, dist ); /*Q17 */ + L_dist = L_shr( L_dist, 12 ); FOR( j = 1; j < dim; j++ ) { /*temp = x[j] - *cbP++; */ - temp = sub(x[j] , *cbP++); + temp = sub( x[j], *cbP++ ); /*dist += temp * temp; */ - L_tmp = L_mult(temp,temp);/*Q17 */ - L_dist = L_add(L_dist,L_shr(L_tmp,12));/*Q5 */ + L_tmp = L_mult( temp, temp ); /*Q17 */ + L_dist = L_add( L_dist, L_shr( L_tmp, 12 ) ); /*Q5 */ } - IF (LT_32(L_dist, L_dist_min)) + IF( LT_32( L_dist, L_dist_min ) ) { - L_dist_min = L_add(L_dist, 0); + L_dist_min = L_add( L_dist, 0 ); index = i; move16(); } @@ -1179,95 +1172,94 @@ static Word16 vqSimple_w_fx( /* Reading the selected vector */ Copy( &cb[index * dim], y, dim ); - return(index); + return ( index ); } - /*-------------------------------------------------------------------* -* MSVQ_Interpol_Tran_fx() -* -*-------------------------------------------------------------------*/ + * MSVQ_Interpol_Tran_fx() + * + *-------------------------------------------------------------------*/ static void MSVQ_Interpol_Tran_fx( - Word16 *SWB_env_energy, /* i/o : (original/quantized) energy Q8 */ - Word16 *indice /* o : quantized index */ + Word16 *SWB_env_energy, /* i/o : (original/quantized) energy Q8 */ + Word16 *indice /* o : quantized index */ ) { - Word16 k, n_band, candInd[N_CAND_TR], ind_tmp[2],tmp; - Word16 env_temp11[SWB_FENV_TRANS/2], env_temp12[SWB_FENV_TRANS/2]; + Word16 k, n_band, candInd[N_CAND_TR], ind_tmp[2], tmp; + Word16 env_temp11[SWB_FENV_TRANS / 2], env_temp12[SWB_FENV_TRANS / 2]; Word16 tmp_q; Word16 quant_tmp[SWB_FENV_TRANS], quant_tmp2[SWB_FENV_TRANS]; Word16 quant_select[SWB_FENV_TRANS]; - Word32 L_tmp, L_dist, L_minDist,distCand[N_CAND_TR]; + Word32 L_tmp, L_dist, L_minDist, distCand[N_CAND_TR]; /* Extract target vector */ FOR( n_band = 0; n_band < DIM_TR1; n_band++ ) { - env_temp11[n_band] = SWB_env_energy[2*n_band]; - move16();/*Q8 */ - env_temp12[n_band] = SWB_env_energy[2*n_band+1]; - move16();/*Q8 */ + env_temp11[n_band] = SWB_env_energy[2 * n_band]; + move16(); /*Q8 */ + env_temp12[n_band] = SWB_env_energy[2 * n_band + 1]; + move16(); /*Q8 */ } vqWithCand_w_fx( env_temp11, Env_TR_Cdbk1_fx, DIM_TR1, N_CB_TR1, candInd, N_CAND_TR, distCand, NULL, 0 ); - L_minDist = L_add(MAX_32, 0); /* FLT_MAX */ + L_minDist = L_add( MAX_32, 0 ); /* FLT_MAX */ - FOR( k=0; khBWE_FD; - IF ( EQ_16(core,ACELP_CORE)) + IF( EQ_16( core, ACELP_CORE ) ) { gamma_fx = 11469; - move16();/*.35 in Q15 */ + move16(); /*.35 in Q15 */ test(); - IF ( NE_16(coder_type,AUDIO)&<_32(st_fx->total_brate,ACELP_8k85)) + IF( NE_16( coder_type, AUDIO ) && LT_32( st_fx->total_brate, ACELP_8k85 ) ) { core_type = 0; move16(); @@ -1776,9 +1767,9 @@ static void energy_control_fx( core_type = 1; move16(); } - get_normalize_spec_fx(core, st_fx->extl, mode, core_type, org_fx, SWB_signal_fx, &(hBWE_FD->prev_L_swb_norm1), offset, Q_new_lf); + get_normalize_spec_fx( core, st_fx->extl, mode, core_type, org_fx, SWB_signal_fx, &( hBWE_FD->prev_L_swb_norm1 ), offset, Q_new_lf ); - IF ( EQ_16(st_fx->extl,WB_BWE)) + IF( EQ_16( st_fx->extl, WB_BWE ) ) { max_band = 4; move16(); @@ -1793,15 +1784,15 @@ static void energy_control_fx( move16(); } } - ELSE /* HQ core */ + ELSE /* HQ core */ { gamma_fx = 18022; - move16();/*.55 in Q15 */ - get_normalize_spec_fx(core, st_fx->extl, mode, -1, org_fx, SWB_signal_fx, &(hBWE_FD->prev_L_swb_norm1), offset, Q_new_lf); + move16(); /*.55 in Q15 */ + get_normalize_spec_fx( core, st_fx->extl, mode, -1, org_fx, SWB_signal_fx, &( hBWE_FD->prev_L_swb_norm1 ), offset, Q_new_lf ); band_step = 1; move16(); - IF ( EQ_16(offset,HQ_GENERIC_FOFFSET_32K)) + IF( EQ_16( offset, HQ_GENERIC_FOFFSET_32K ) ) { max_band = 12; move16(); @@ -1813,15 +1804,15 @@ static void energy_control_fx( } } - FOR( n_band=0; n_bandhBstr, IND_WB_FENV, index, 5 ); + push_indice_fx( st_fx->hBstr, IND_WB_FENV, index, 5 ); - return (mode); + return ( mode ); } /*-------------------------------------------------------------------* @@ -1913,21 +1903,20 @@ Word16 WB_BWE_encoding_fx( /* o : classification of wb signal */ * SWB BWE encoder *-------------------------------------------------------------------*/ static Word16 SWB_BWE_encoding_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - Word16 *insig_fx, /* i : delayed original input signal at 32kHz */ - const Word16 *insig_lp_fx, /* i : delayed original lowband input signal at 32kHz */ - const Word16 *insig_hp_fx, /* i : delayed original highband input signal at 32kHz */ - const Word16 *synth_fx, /* i : delayed ACELP core synthesis at 12.8kHz */ - const Word16 *yos_fx, /* i : MDCT coefficients of the windowed original input signal at 32kHz */ - Word16 *SWB_fenv_fx, /* o : frequency-domain quantized BWE envelope */ - const Word16 tilt_nb_fx, /* i : SWB tilt */ - const Word16 st_offset, /* i : start frequency offset for BWE envelope */ - const Word16 coder_type, /* i : coding type */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + Word16 *insig_fx, /* i : delayed original input signal at 32kHz */ + const Word16 *insig_lp_fx, /* i : delayed original lowband input signal at 32kHz */ + const Word16 *insig_hp_fx, /* i : delayed original highband input signal at 32kHz */ + const Word16 *synth_fx, /* i : delayed ACELP core synthesis at 12.8kHz */ + const Word16 *yos_fx, /* i : MDCT coefficients of the windowed original input signal at 32kHz */ + Word16 *SWB_fenv_fx, /* o : frequency-domain quantized BWE envelope */ + const Word16 tilt_nb_fx, /* i : SWB tilt */ + const Word16 st_offset, /* i : start frequency offset for BWE envelope */ + const Word16 coder_type, /* i : coding type */ Word16 Q_insig_lp, Word16 Q_shb, Word16 Q_synth, - Word16 Q_synth_lf -) + Word16 Q_synth_lf ) { Word16 IsTransient, mode; Word16 index; @@ -1957,7 +1946,7 @@ static Word16 SWB_BWE_encoding_fx( FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD; BSTR_ENC_HANDLE hBstr = st_fx->hBstr; - IF( EQ_16(st_fx->L_frame, L_FRAME )) + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { L = L_SUBFR; move16(); @@ -1969,22 +1958,22 @@ static Word16 SWB_BWE_encoding_fx( } /* HF transient detect */ - IsTransient = detect_transient_fx( insig_hp_fx, L_FRAME16k, Q_shb, st_fx); - st_fx->EnergyLT_fx_exp = shl(Q_shb, 1); + IsTransient = detect_transient_fx( insig_hp_fx, L_FRAME16k, Q_shb, st_fx ); + st_fx->EnergyLT_fx_exp = shl( Q_shb, 1 ); /* LF transient detect */ IsTransient_LF = 0; move16(); - FOR ( n_band = 0; n_band < 4; n_band++ ) + FOR( n_band = 0; n_band < 4; n_band++ ) { - tmp = i_mult2(n_band, L); - energy_fx = L_deposit_l(0); - FOR(i=0; iEnergyLF_fx)) + IF( GT_32( Mult_32_16( energy_fx, 5958 ), hBWE_FD->EnergyLF_fx ) ) { IsTransient_LF = 1; move16(); @@ -1996,13 +1985,13 @@ static Word16 SWB_BWE_encoding_fx( /* tilt returned in Q24 go to Q11 */ #ifdef BASOP_NOGLOB - tilt_fx = round_fx_o(L_shl_o(calc_tilt_bwe_fx(insig_fx, 0, L_FRAME32k), 3, &Overflow), &Overflow); + tilt_fx = round_fx_o( L_shl_o( calc_tilt_bwe_fx( insig_fx, 0, L_FRAME32k ), 3, &Overflow ), &Overflow ); #else - tilt_fx = round_fx(L_shl(calc_tilt_bwe_fx(insig_fx, 0, L_FRAME32k), 3)); + tilt_fx = round_fx( L_shl( calc_tilt_bwe_fx( insig_fx, 0, L_FRAME32k ), 3 ) ); #endif test(); test(); - IF( EQ_16(IsTransient,1)&&(GT_16(tilt_fx,16384)||GT_16(st_fx->clas,1))) + IF( EQ_16( IsTransient, 1 ) && ( GT_16( tilt_fx, 16384 ) || GT_16( st_fx->clas, 1 ) ) ) { IsTransient = 0; move16(); @@ -2010,111 +1999,111 @@ static Word16 SWB_BWE_encoding_fx( move16(); } - IF( EQ_16(IsTransient,1)) + IF( EQ_16( IsTransient, 1 ) ) { mode = IsTransient; move16(); push_indice_fx( hBstr, IND_SWB_CLASS, mode, 2 ); /* Energy for the different bands and global energies */ - global_gain_fx = L_deposit_l(0); - FOR (n_band = 0; n_band < SWB_FENV_TRANS; n_band++) + global_gain_fx = L_deposit_l( 0 ); + FOR( n_band = 0; n_band < SWB_FENV_TRANS; n_band++ ) { - energy_fx = L_deposit_l(0); - FOR (n_coeff = swb_bwe_trans_subband[n_band]+st_offset; n_coeff < swb_bwe_trans_subband[n_band+1]+st_offset; n_coeff++) + energy_fx = L_deposit_l( 0 ); + FOR( n_coeff = swb_bwe_trans_subband[n_band] + st_offset; n_coeff < swb_bwe_trans_subband[n_band + 1] + st_offset; n_coeff++ ) { - L_tmp = L_shr(L_mult0(yos_fx[n_coeff], yos_fx[n_coeff]), 7); /*2*Q_synth-7 */ - energy_fx = L_add(L_tmp, energy_fx); /*2*Q_synth-7 */ + L_tmp = L_shr( L_mult0( yos_fx[n_coeff], yos_fx[n_coeff] ), 7 ); /*2*Q_synth-7 */ + energy_fx = L_add( L_tmp, energy_fx ); /*2*Q_synth-7 */ } - global_gain_fx = L_add(global_gain_fx, L_shr(energy_fx, sub(sub(shl(Q_synth,1),7), shl(Q_shb,1)))); /*2*Q_shb */ + global_gain_fx = L_add( global_gain_fx, L_shr( energy_fx, sub( sub( shl( Q_synth, 1 ), 7 ), shl( Q_shb, 1 ) ) ) ); /*2*Q_shb */ L_SWB_fenv_fx[n_band] = energy_fx; move32(); } - global_gain_fx = L_shr(global_gain_fx, 1); /*2*Q_shb */ + global_gain_fx = L_shr( global_gain_fx, 1 ); /*2*Q_shb */ - FOR (n_band = 0; n_band < SWB_FENV_TRANS; n_band++) + FOR( n_band = 0; n_band < SWB_FENV_TRANS; n_band++ ) { - expd = norm_s(swb_bwe_trans_subband_width[n_band]); - tmp = div_s(shl(1,sub(14,expd)), swb_bwe_trans_subband_width[n_band]);/*Q(29-expd) */ - L_tmp = Mult_32_16(L_SWB_fenv_fx[n_band], tmp); /*2*Q_synth-7+29-expd - 15 */ - exp = norm_l(L_tmp); - tmp = Log2_norm_lc(L_shl(L_tmp, exp)); + expd = norm_s( swb_bwe_trans_subband_width[n_band] ); + tmp = div_s( shl( 1, sub( 14, expd ) ), swb_bwe_trans_subband_width[n_band] ); /*Q(29-expd) */ + L_tmp = Mult_32_16( L_SWB_fenv_fx[n_band], tmp ); /*2*Q_synth-7+29-expd - 15 */ + exp = norm_l( L_tmp ); + tmp = Log2_norm_lc( L_shl( L_tmp, exp ) ); move16(); - exp = sub(sub(30, exp), sub(add(shl(Q_synth,1),7),expd)); - L_tmp = Mpy_32_16(exp, tmp, 24660); /* Q14 */ /*10log10(2) in Q13 */ - tmp = round_fx(L_shl(L_tmp, 10)); /* Q8 */ + exp = sub( sub( 30, exp ), sub( add( shl( Q_synth, 1 ), 7 ), expd ) ); + L_tmp = Mpy_32_16( exp, tmp, 24660 ); /* Q14 */ /*10log10(2) in Q13 */ + tmp = round_fx( L_shl( L_tmp, 10 ) ); /* Q8 */ - SWB_fenv_fx[n_band] = sub(tmp, Mean_env_tr_fx[n_band]); - move16();/*Q8 */ + SWB_fenv_fx[n_band] = sub( tmp, Mean_env_tr_fx[n_band] ); + move16(); /*Q8 */ } - WB_tenv_orig_fx = L_deposit_l(0); - WB_tenv_syn_fx = L_deposit_l(1); - FOR(n_band = 0; n_band < SWB_TENV; n_band++) + WB_tenv_orig_fx = L_deposit_l( 0 ); + WB_tenv_syn_fx = L_deposit_l( 1 ); + FOR( n_band = 0; n_band < SWB_TENV; n_band++ ) { - tmp = i_mult2(n_band, L_SUBFR16k); - L_SWB_tenv = L_deposit_l(0); - FOR(i = 0; i < L_SUBFR16k; i++) + tmp = i_mult2( n_band, L_SUBFR16k ); + L_SWB_tenv = L_deposit_l( 0 ); + FOR( i = 0; i < L_SUBFR16k; i++ ) { #ifdef BASOP_NOGLOB L_SWB_tenv = L_add_sat( L_SWB_tenv, L_mult0( insig_hp_fx[i + tmp], insig_hp_fx[i + tmp] ) ); /*2*Q_shb */ #else - L_SWB_tenv = L_add(L_SWB_tenv, L_mult0(insig_hp_fx[i + tmp], insig_hp_fx[i + tmp])); /*2*Q_shb */ + L_SWB_tenv = L_add( L_SWB_tenv, L_mult0( insig_hp_fx[i + tmp], insig_hp_fx[i + tmp] ) ); /*2*Q_shb */ #endif } - tmp = i_mult2(n_band, L); - FOR(i=0; iQ_syn2 - 7 */ - WB_tenv_orig_fx = L_add(WB_tenv_orig_fx, L_shr(L_mult0(insig_lp_fx[i + tmp], insig_lp_fx[i + tmp]), 7)); /*2*Q_insig_lp - 7 */ + WB_tenv_syn_fx = L_add( WB_tenv_syn_fx, L_shr( L_mult0( synth_fx[i + tmp], synth_fx[i + tmp] ), 7 ) ); /*2*st_fx->Q_syn2 - 7 */ + WB_tenv_orig_fx = L_add( WB_tenv_orig_fx, L_shr( L_mult0( insig_lp_fx[i + tmp], insig_lp_fx[i + tmp] ), 7 ) ); /*2*Q_insig_lp - 7 */ } - L_tmp = Mult_32_16(L_SWB_tenv, INV_L_SUBFR16k_FX);/*2*Q_shb */ + L_tmp = Mult_32_16( L_SWB_tenv, INV_L_SUBFR16k_FX ); /*2*Q_shb */ SWB_tenv_fx[n_band] = 0; move16(); - IF(L_tmp != 0) + IF( L_tmp != 0 ) { - exp = norm_l(L_tmp); - tmp = extract_h(L_shl(L_tmp, exp)); - exp = sub(exp, sub(30, 2*Q_shb)); + exp = norm_l( L_tmp ); + tmp = extract_h( L_shl( L_tmp, exp ) ); + exp = sub( exp, sub( 30, 2 * Q_shb ) ); - tmp = div_s(16384, tmp); - L_tmp = L_deposit_h(tmp); - L_tmp = Isqrt_lc(L_tmp, &exp); /*Q(31-exp) */ + tmp = div_s( 16384, tmp ); + L_tmp = L_deposit_h( tmp ); + L_tmp = Isqrt_lc( L_tmp, &exp ); /*Q(31-exp) */ #ifdef BASOP_NOGLOB SWB_tenv_fx[n_band] = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 12 ) ) ); /*Q3 */ #else - SWB_tenv_fx[n_band] = round_fx(L_shl(L_tmp, sub(exp, 12))); /*Q3 */ + SWB_tenv_fx[n_band] = round_fx( L_shl( L_tmp, sub( exp, 12 ) ) ); /*Q3 */ #endif } } - IF(WB_tenv_orig_fx != 0) + IF( WB_tenv_orig_fx != 0 ) { - expn = norm_l(WB_tenv_orig_fx); - num = extract_h(L_shl(WB_tenv_orig_fx, expn)); - expn = sub(sub(30, expn), sub(shl(Q_insig_lp,1),7)); + expn = norm_l( WB_tenv_orig_fx ); + num = extract_h( L_shl( WB_tenv_orig_fx, expn ) ); + expn = sub( sub( 30, expn ), sub( shl( Q_insig_lp, 1 ), 7 ) ); - expd = norm_l(WB_tenv_syn_fx); - den = round_fx(L_shl(WB_tenv_syn_fx, expd)); - expd = sub(sub(30, expd), sub(shl(st_fx->Q_syn2, 1), 7)); + expd = norm_l( WB_tenv_syn_fx ); + den = round_fx( L_shl( WB_tenv_syn_fx, expd ) ); + expd = sub( sub( 30, expd ), sub( shl( st_fx->Q_syn2, 1 ), 7 ) ); - scale = shr(sub(den, num), 15); - num = shl(num, scale); - expn = sub(expn, scale); + scale = shr( sub( den, num ), 15 ); + num = shl( num, scale ); + expn = sub( expn, scale ); - tmp = div_s(num, den); - expn = sub(expn, expd); + tmp = div_s( num, den ); + expn = sub( expn, expd ); - L_tmp = L_deposit_h(tmp); - L_tmp = Isqrt_lc(L_tmp, &expn); /*31-expn */ + L_tmp = L_deposit_h( tmp ); + L_tmp = Isqrt_lc( L_tmp, &expn ); /*31-expn */ #ifdef BASOP_NOGLOB - Rat_tenv_fx = round_fx_o(L_shl_o(L_tmp, sub(expn, 1), &Overflow), &Overflow);/*Q14 */ + Rat_tenv_fx = round_fx_o( L_shl_o( L_tmp, sub( expn, 1 ), &Overflow ), &Overflow ); /*Q14 */ #else - Rat_tenv_fx = round_fx(L_shl(L_tmp, sub(expn, 1)));/*Q14 */ + Rat_tenv_fx = round_fx( L_shl( L_tmp, sub( expn, 1 ) ) ); /*Q14 */ #endif } ELSE @@ -2123,34 +2112,34 @@ static Word16 SWB_BWE_encoding_fx( move16(); } - IF(LT_16(Rat_tenv_fx, 8192)) + IF( LT_16( Rat_tenv_fx, 8192 ) ) { - L_tmp = L_mult(Rat_tenv_fx, 19661);/*Q29 */ + L_tmp = L_mult( Rat_tenv_fx, 19661 ); /*Q29 */ #ifdef BASOP_NOGLOB - Rat_tenv_fx = round_fx_o(L_shl_o(L_tmp, 2, &Overflow), &Overflow);/*Q15 */ + Rat_tenv_fx = round_fx_o( L_shl_o( L_tmp, 2, &Overflow ), &Overflow ); /*Q15 */ #else - Rat_tenv_fx = round_fx(L_shl(L_tmp, 2));/*Q15 */ + Rat_tenv_fx = round_fx( L_shl( L_tmp, 2 ) ); /*Q15 */ #endif } - ELSE IF (GT_16(Rat_tenv_fx, 16384)) + ELSE IF( GT_16( Rat_tenv_fx, 16384 ) ) { Rat_tenv_fx = 32767; move16(); } - FOR(n_band = 0; n_band < SWB_TENV; n_band++) + FOR( n_band = 0; n_band < SWB_TENV; n_band++ ) { - SWB_tenv_fx[n_band] = mult_r(SWB_tenv_fx[n_band], Rat_tenv_fx); - move16();/*Q3 */ + SWB_tenv_fx[n_band] = mult_r( SWB_tenv_fx[n_band], Rat_tenv_fx ); + move16(); /*Q3 */ } max_fx = SWB_tenv_fx[0]; move16(); pos = 0; move16(); - FOR(n_band = 1; n_band < SWB_TENV; n_band++) + FOR( n_band = 1; n_band < SWB_TENV; n_band++ ) { - IF(GT_16(SWB_tenv_fx[n_band],max_fx)) + IF( GT_16( SWB_tenv_fx[n_band], max_fx ) ) { max_fx = SWB_tenv_fx[n_band]; move16(); @@ -2161,37 +2150,37 @@ static Word16 SWB_BWE_encoding_fx( max_fx = SWB_tenv_fx[0]; move16(); - FOR(n_band = 1; n_band < SWB_TENV; n_band++) + FOR( n_band = 1; n_band < SWB_TENV; n_band++ ) { - tmp = sub(mult_r(SWB_tenv_fx[n_band], 6554), SWB_tenv_fx[n_band-1]); - IF(tmp > 0) + tmp = sub( mult_r( SWB_tenv_fx[n_band], 6554 ), SWB_tenv_fx[n_band - 1] ); + IF( tmp > 0 ) { BREAK; } } - IF(n_band < SWB_TENV) + IF( n_band < SWB_TENV ) { - energy_fx = L_deposit_l(0); - FOR(n_band = (pos+1); n_band < SWB_TENV; n_band++) + energy_fx = L_deposit_l( 0 ); + FOR( n_band = ( pos + 1 ); n_band < SWB_TENV; n_band++ ) { - energy_fx = L_add(energy_fx, SWB_tenv_fx[n_band]);/*Q3 */ + energy_fx = L_add( energy_fx, SWB_tenv_fx[n_band] ); /*Q3 */ } - IF(pos == sub(SWB_TENV, 1)) + IF( pos == sub( SWB_TENV, 1 ) ) { - energy_fx = L_deposit_l(0); + energy_fx = L_deposit_l( 0 ); } ELSE { - tmp = sub(SWB_TENV, pos+1); - tmp = div_s(1, tmp); /*Q15 */ - energy_fx = Mult_32_16(energy_fx, tmp);/*Q3 */ + tmp = sub( SWB_TENV, pos + 1 ); + tmp = div_s( 1, tmp ); /*Q15 */ + energy_fx = Mult_32_16( energy_fx, tmp ); /*Q3 */ } - FOR(n_band = 0; n_band < pos; n_band++) + FOR( n_band = 0; n_band < pos; n_band++ ) { - SWB_tenv_fx[n_band] = mult_r(SWB_tenv_fx[n_band], 16384); + SWB_tenv_fx[n_band] = mult_r( SWB_tenv_fx[n_band], 16384 ); move16(); } @@ -2199,29 +2188,29 @@ static Word16 SWB_BWE_encoding_fx( #ifdef BASOP_NOGLOB SWB_tenv_fx[pos] = round_fx_sat( L_mac_sat( L_mult_sat( SWB_tenv_fx[pos], 32767 ), SWB_tenv_fx[pos], 164 ) ); /*Q3 */ #else - SWB_tenv_fx[pos] = round_fx(L_mac(L_mult(SWB_tenv_fx[pos],32767), SWB_tenv_fx[pos], 164)); /*Q3 */ + SWB_tenv_fx[pos] = round_fx( L_mac( L_mult( SWB_tenv_fx[pos], 32767 ), SWB_tenv_fx[pos], 164 ) ); /*Q3 */ #endif - IF(LT_32(energy_fx, SWB_tenv_fx[pos])) + IF( LT_32( energy_fx, SWB_tenv_fx[pos] ) ) { - FOR(n_band = pos+1; n_band < SWB_TENV; n_band++) + FOR( n_band = pos + 1; n_band < SWB_TENV; n_band++ ) { - SWB_tenv_fx[n_band] = mult_r(SWB_tenv_fx[n_band], 29491); - move16();/*Q3 */ + SWB_tenv_fx[n_band] = mult_r( SWB_tenv_fx[n_band], 29491 ); + move16(); /*Q3 */ } } } ELSE { - FOR(n_band = 1; n_band < SWB_TENV; n_band++) + FOR( n_band = 1; n_band < SWB_TENV; n_band++ ) { - IF(GT_16(SWB_tenv_fx[n_band-1], SWB_tenv_fx[n_band])) + IF( GT_16( SWB_tenv_fx[n_band - 1], SWB_tenv_fx[n_band] ) ) { /*SWB_tenv_fx[n_band-1] = add(mult_r(SWB_tenv_fx[n_band-1], 16384), mult_r(SWB_tenv_fx[n_band], 16384)); move16();//Q3 */ #ifdef BASOP_NOGLOB SWB_tenv_fx[n_band - 1] = round_fx_sat( L_mac_sat( L_mult( SWB_tenv_fx[n_band - 1], 16384 ), SWB_tenv_fx[n_band], 16384 ) ); /*Q3 */ #else - SWB_tenv_fx[n_band-1] = round_fx(L_mac(L_mult(SWB_tenv_fx[n_band-1], 16384), SWB_tenv_fx[n_band], 16384)); /*Q3 */ + SWB_tenv_fx[n_band - 1] = round_fx( L_mac( L_mult( SWB_tenv_fx[n_band - 1], 16384 ), SWB_tenv_fx[n_band], 16384 ) ); /*Q3 */ #endif } ELSE @@ -2230,77 +2219,77 @@ static Word16 SWB_BWE_encoding_fx( #ifdef BASOP_NOGLOB SWB_tenv_fx[n_band] = round_fx_sat( L_mac_sat( L_mult( SWB_tenv_fx[n_band - 1], 16384 ), SWB_tenv_fx[n_band], 16384 ) ); /*Q3 */ #else - SWB_tenv_fx[n_band] = round_fx(L_mac(L_mult(SWB_tenv_fx[n_band-1], 16384), SWB_tenv_fx[n_band], 16384)); /*Q3 */ + SWB_tenv_fx[n_band] = round_fx( L_mac( L_mult( SWB_tenv_fx[n_band - 1], 16384 ), SWB_tenv_fx[n_band], 16384 ) ); /*Q3 */ #endif } } - FOR(n_band = 0; n_band < SWB_TENV; n_band++) + FOR( n_band = 0; n_band < SWB_TENV; n_band++ ) { - SWB_tenv_fx[n_band] = mult_r(SWB_tenv_fx[n_band], 29491); - move16();/*Q3 */ + SWB_tenv_fx[n_band] = mult_r( SWB_tenv_fx[n_band], 29491 ); + move16(); /*Q3 */ } } test(); test(); - IF(IsTransient_LF == 0 && EQ_16(coder_type,INACTIVE)&&EQ_16(st_fx->TransientHangOver,1)) + IF( IsTransient_LF == 0 && EQ_16( coder_type, INACTIVE ) && EQ_16( st_fx->TransientHangOver, 1 ) ) { - FOR(n_band = 0; n_band < SWB_TENV; n_band++) + FOR( n_band = 0; n_band < SWB_TENV; n_band++ ) { - SWB_tenv_fx[n_band] = mult_r(SWB_tenv_fx[n_band], 16384); + SWB_tenv_fx[n_band] = mult_r( SWB_tenv_fx[n_band], 16384 ); move16(); } - FOR(n_band = 0; n_band < SWB_FENV_TRANS; n_band++) + FOR( n_band = 0; n_band < SWB_FENV_TRANS; n_band++ ) { - SWB_fenv_fx[n_band] = mult_r(SWB_fenv_fx[n_band], 1638); + SWB_fenv_fx[n_band] = mult_r( SWB_fenv_fx[n_band], 1638 ); move16(); } } ELSE { - SWB_fenv_fx[2] = mult_r(SWB_fenv_fx[2], 3277); + SWB_fenv_fx[2] = mult_r( SWB_fenv_fx[2], 3277 ); move16(); - SWB_fenv_fx[3] = mult_r(SWB_fenv_fx[3], 1638); + SWB_fenv_fx[3] = mult_r( SWB_fenv_fx[3], 1638 ); move16(); } - FOR(n_band = 0; n_band < SWB_TENV; n_band++) + FOR( n_band = 0; n_band < SWB_TENV; n_band++ ) { - IF(SWB_tenv_fx[n_band] == 0) + IF( SWB_tenv_fx[n_band] == 0 ) { SWB_tenv_tmp_fx[n_band] = -32768; move16(); /*-16 in Q11 */ } ELSE { - L_tmp = L_deposit_h(SWB_tenv_fx[n_band]); /*Q19 */ - expn = norm_l(L_tmp); - tmp = Log2_norm_lc(L_shl(L_tmp, expn)); - expn = sub(sub(30, expn), 19); - L_tmp = Mpy_32_16(expn, tmp, 32767); /* Q16 */ /*1 in Q15 */ - SWB_tenv_tmp_fx[n_band] = round_fx(L_shl(L_tmp, 11)); /* Q11 */ + L_tmp = L_deposit_h( SWB_tenv_fx[n_band] ); /*Q19 */ + expn = norm_l( L_tmp ); + tmp = Log2_norm_lc( L_shl( L_tmp, expn ) ); + expn = sub( sub( 30, expn ), 19 ); + L_tmp = Mpy_32_16( expn, tmp, 32767 ); /* Q16 */ /*1 in Q15 */ + SWB_tenv_tmp_fx[n_band] = round_fx( L_shl( L_tmp, 11 ) ); /* Q11 */ } - IF (GT_16(SWB_tenv_tmp_fx[n_band], 30720)) + IF( GT_16( SWB_tenv_tmp_fx[n_band], 30720 ) ) { index = 15; move16(); } - ELSE IF (SWB_tenv_tmp_fx[n_band] < 0) + ELSE IF( SWB_tenv_tmp_fx[n_band] < 0 ) { index = 0; move16(); } ELSE { - index = shr(add(SWB_tenv_tmp_fx[n_band], 1024), 11); + index = shr( add( SWB_tenv_tmp_fx[n_band], 1024 ), 11 ); } push_indice_fx( hBstr, IND_SWB_TENV, index, 4 ); } - MSVQ_Interpol_Tran_fx(SWB_fenv_fx, indice); + MSVQ_Interpol_Tran_fx( SWB_fenv_fx, indice ); push_indice_fx( hBstr, IND_SWB_FENV, indice[0], 7 ); push_indice_fx( hBstr, IND_SWB_FENV, indice[1], 6 ); @@ -2308,42 +2297,42 @@ static Word16 SWB_BWE_encoding_fx( ELSE { /* Energy for the different bands and global energies */ - global_gain_fx = L_deposit_l(0); - FOR (n_band = 0; n_band < SWB_FENV; n_band++) + global_gain_fx = L_deposit_l( 0 ); + FOR( n_band = 0; n_band < SWB_FENV; n_band++ ) { - energy_fx = L_deposit_l(0); - FOR (n_coeff = swb_bwe_subband[n_band]+st_offset; n_coeff < swb_bwe_subband[n_band+1]+st_offset; n_coeff++) + energy_fx = L_deposit_l( 0 ); + FOR( n_coeff = swb_bwe_subband[n_band] + st_offset; n_coeff < swb_bwe_subband[n_band + 1] + st_offset; n_coeff++ ) { - L_tmp = L_shr(L_mult0(yos_fx[n_coeff], yos_fx[n_coeff]), 5); /*2*Q_synth-5 */ - energy_fx = L_add(L_tmp, energy_fx); /*2*Q_synth-5 */ + L_tmp = L_shr( L_mult0( yos_fx[n_coeff], yos_fx[n_coeff] ), 5 ); /*2*Q_synth-5 */ + energy_fx = L_add( L_tmp, energy_fx ); /*2*Q_synth-5 */ } - IF (LT_16(n_band, sub(SWB_FENV,2))) + IF( LT_16( n_band, sub( SWB_FENV, 2 ) ) ) { - global_gain_fx = L_add(global_gain_fx, L_shr(energy_fx, sub(2*Q_synth-5, 2*Q_shb))); /*2*Q_shb */ + global_gain_fx = L_add( global_gain_fx, L_shr( energy_fx, sub( 2 * Q_synth - 5, 2 * Q_shb ) ) ); /*2*Q_shb */ } L_SWB_fenv_fx[n_band] = energy_fx; move32(); } - global_gain_fx = L_shr(global_gain_fx, 1); /*2*Q_shb */ - mode = FD_BWE_class_fx(yos_fx, global_gain_fx, tilt_nb_fx, Q_synth, Q_shb, st_fx); + global_gain_fx = L_shr( global_gain_fx, 1 ); /*2*Q_shb */ + mode = FD_BWE_class_fx( yos_fx, global_gain_fx, tilt_nb_fx, Q_synth, Q_shb, st_fx ); push_indice_fx( hBstr, IND_SWB_CLASS, mode, 2 ); energy_control_fx( st_fx, ACELP_CORE, mode, -1, yos_fx, st_offset, energy_factor_fx, Q_synth_lf ); - FOR (n_band = 0; n_band < SWB_FENV; n_band++) + FOR( n_band = 0; n_band < SWB_FENV; n_band++ ) { - L_tmp = Mult_32_16(L_SWB_fenv_fx[n_band],energy_factor_fx[n_band]);/*2*Q_synth-5 */ - L_tmp = Mult_32_16(L_tmp,swb_inv_bwe_subband_width_fx[n_band]);/*2*Q_synth-5 */ + L_tmp = Mult_32_16( L_SWB_fenv_fx[n_band], energy_factor_fx[n_band] ); /*2*Q_synth-5 */ + L_tmp = Mult_32_16( L_tmp, swb_inv_bwe_subband_width_fx[n_band] ); /*2*Q_synth-5 */ - IF(L_tmp != 0) + IF( L_tmp != 0 ) { - expn = norm_l(L_tmp); - tmp = Log2_norm_lc(L_shl(L_tmp,expn)); - expn = sub(30,add(expn,sub(shl(Q_synth,1),5))); - L_tmp = Mpy_32_16(expn, tmp, 24660); /* Q14 */ /*10log10(2) in Q13 */ - SWB_fenv_fx[n_band] = round_fx(L_shl(L_tmp, 10)); /* Q8 */ + expn = norm_l( L_tmp ); + tmp = Log2_norm_lc( L_shl( L_tmp, expn ) ); + expn = sub( 30, add( expn, sub( shl( Q_synth, 1 ), 5 ) ) ); + L_tmp = Mpy_32_16( expn, tmp, 24660 ); /* Q14 */ /*10log10(2) in Q13 */ + SWB_fenv_fx[n_band] = round_fx( L_shl( L_tmp, 10 ) ); /* Q8 */ } ELSE { @@ -2351,23 +2340,22 @@ static Word16 SWB_BWE_encoding_fx( move16(); } } - freq_weights_fx(SWB_fenv_fx, w_NOR_fx, w_env_fx, SWB_FENV); + freq_weights_fx( SWB_fenv_fx, w_NOR_fx, w_env_fx, SWB_FENV ); - FOR (n_band = 0; n_band < SWB_FENV; n_band++) + FOR( n_band = 0; n_band < SWB_FENV; n_band++ ) { - SWB_fenv_fx[n_band] = sub(SWB_fenv_fx[n_band] , Mean_env_fx[n_band]); + SWB_fenv_fx[n_band] = sub( SWB_fenv_fx[n_band], Mean_env_fx[n_band] ); move16(); } /* Energy VQ */ - msvq_interpol_fx(SWB_fenv_fx, w_env_fx, indice); + msvq_interpol_fx( SWB_fenv_fx, w_env_fx, indice ); push_indice_fx( hBstr, IND_SWB_FENV, indice[0], 5 ); push_indice_fx( hBstr, IND_SWB_FENV, indice[1], 7 ); push_indice_fx( hBstr, IND_SWB_FENV, indice[2], 6 ); push_indice_fx( hBstr, IND_SWB_FENV, indice[3], 5 ); push_indice_fx( hBstr, IND_SWB_FENV, indice[4], 6 ); - } hBWE_FD->prev_mode = mode; move16(); @@ -2385,14 +2373,14 @@ static Word16 SWB_BWE_encoding_fx( *-------------------------------------------------------------------*/ static void get_normalize_spec_fx_32( - const Word16 core, /* i : core selected : Q0 */ - const Word16 extl, /* i : extension layer selected: Q0 */ - const Word16 mode, /* i : SHB BWE class : Q0 */ - const Word16 core_type, /* i : coding type : Q0 */ - const Word32 *org_fx, /* i : input spectrum : Q12 */ - Word32 *SWB_signal_fx, /* o : output spectrum : Q20 */ - Word16 *prev_L_swb_norm, /* i : previous norm. len : Q0 */ - const Word16 offset /* i : frequency offset : Q0 */ + const Word16 core, /* i : core selected : Q0 */ + const Word16 extl, /* i : extension layer selected: Q0 */ + const Word16 mode, /* i : SHB BWE class : Q0 */ + const Word16 core_type, /* i : coding type : Q0 */ + const Word32 *org_fx, /* i : input spectrum : Q12 */ + Word32 *SWB_signal_fx, /* o : output spectrum : Q20 */ + Word16 *prev_L_swb_norm, /* i : previous norm. len : Q0 */ + const Word16 offset /* i : frequency offset : Q0 */ ) { Word16 n_freq, L_swb_norm; @@ -2401,69 +2389,69 @@ static void get_normalize_spec_fx_32( Word32 L_tmp; Word32 envelope_fx[L_FRAME32k]; - set32_fx(SWB_signal_fx, 0, HQ_GENERIC_HIGH0+offset); - calc_normal_length_fx_32(core, org_fx, mode, extl, &L_swb_norm, prev_L_swb_norm); + set32_fx( SWB_signal_fx, 0, HQ_GENERIC_HIGH0 + offset ); + calc_normal_length_fx_32( core, org_fx, mode, extl, &L_swb_norm, prev_L_swb_norm ); test(); - IF(EQ_16(extl , SWB_BWE)||EQ_16(extl,FB_BWE)) + IF( EQ_16( extl, SWB_BWE ) || EQ_16( extl, FB_BWE ) ) { - IF ( EQ_16(mode ,HARMONIC)) + IF( EQ_16( mode, HARMONIC ) ) { - Copy32(org_fx, &SWB_signal_fx[add(240,offset)], 240); - Copy32(&org_fx[128], &SWB_signal_fx[add(480,offset)], 80); + Copy32( org_fx, &SWB_signal_fx[add( 240, offset )], 240 ); + Copy32( &org_fx[128], &SWB_signal_fx[add( 480, offset )], 80 ); } ELSE { - Copy32( &org_fx[112], &SWB_signal_fx[add(240,offset)], 128 ); - Copy32( &org_fx[112], &SWB_signal_fx[add(368,offset)], 128 ); - Copy32( &org_fx[176], &SWB_signal_fx[add(496,offset)], 64 ); + Copy32( &org_fx[112], &SWB_signal_fx[add( 240, offset )], 128 ); + Copy32( &org_fx[112], &SWB_signal_fx[add( 368, offset )], 128 ); + Copy32( &org_fx[176], &SWB_signal_fx[add( 496, offset )], 64 ); } - frq_end = 560+offset; + frq_end = 560 + offset; move16(); } - ELSE IF (EQ_16(extl , WB_BWE)) + ELSE IF( EQ_16( extl, WB_BWE ) ) { - IF ( core_type == 0 ) + IF( core_type == 0 ) { - Copy32(&org_fx[160], &SWB_signal_fx[240], 80); + Copy32( &org_fx[160], &SWB_signal_fx[240], 80 ); } ELSE { - Copy32(&org_fx[80], &SWB_signal_fx[240], 80); + Copy32( &org_fx[80], &SWB_signal_fx[240], 80 ); } frq_end = L_FRAME16k; move16(); } ELSE { - Copy32( org_fx+HQ_GENERIC_OFFSET, SWB_signal_fx+HQ_GENERIC_HIGH0+offset, HQ_GENERIC_LEN0 ); - Copy32( org_fx+HQ_GENERIC_OFFSET, SWB_signal_fx+HQ_GENERIC_HIGH1+offset, HQ_GENERIC_LEN0 ); - IF ( EQ_16(offset , HQ_GENERIC_FOFFSET_24K4)) + Copy32( org_fx + HQ_GENERIC_OFFSET, SWB_signal_fx + HQ_GENERIC_HIGH0 + offset, HQ_GENERIC_LEN0 ); + Copy32( org_fx + HQ_GENERIC_OFFSET, SWB_signal_fx + HQ_GENERIC_HIGH1 + offset, HQ_GENERIC_LEN0 ); + IF( EQ_16( offset, HQ_GENERIC_FOFFSET_24K4 ) ) { - Copy32( org_fx+HQ_GENERIC_LOW0, SWB_signal_fx+HQ_GENERIC_HIGH2+offset, HQ_GENERIC_END_FREQ-HQ_GENERIC_HIGH2 ); + Copy32( org_fx + HQ_GENERIC_LOW0, SWB_signal_fx + HQ_GENERIC_HIGH2 + offset, HQ_GENERIC_END_FREQ - HQ_GENERIC_HIGH2 ); } frq_end = L_FRAME32k; move16(); } /* calculate envelope */ - calc_norm_envelop_fx_32(SWB_signal_fx, envelope_fx, L_swb_norm, frq_end - offset, offset); + calc_norm_envelop_fx_32( SWB_signal_fx, envelope_fx, L_swb_norm, frq_end - offset, offset ); /* Normalize with envelope */ - FOR ( n_freq = add(swb_bwe_subband[0],offset); n_freqhBWE_FD; - IF ( core == ACELP_CORE ) + IF( core == ACELP_CORE ) { gamma_fx = 11468; move16(); test(); - IF ( NE_16(coder_type , AUDIO)&&LE_32(st_fx->total_brate,ACELP_8k00)) + IF( NE_16( coder_type, AUDIO ) && LE_32( st_fx->total_brate, ACELP_8k00 ) ) { core_type = 0; move16(); @@ -2643,9 +2631,9 @@ static void energy_control_fx_32( move16(); } - get_normalize_spec_fx_32(core, st_fx->extl, mode, core_type, org_fx, SWB_signal_fx, &(hBWE_FD->prev_L_swb_norm1), offset ); + get_normalize_spec_fx_32( core, st_fx->extl, mode, core_type, org_fx, SWB_signal_fx, &( hBWE_FD->prev_L_swb_norm1 ), offset ); - IF ( EQ_16(st_fx->extl , WB_BWE)) + IF( EQ_16( st_fx->extl, WB_BWE ) ) { max_band = 4; move16(); @@ -2653,36 +2641,36 @@ static void energy_control_fx_32( move16(); } } - ELSE /* HQ core */ + ELSE /* HQ core */ { gamma_fx = 18021; move16(); - get_normalize_spec_fx_32(core, -1, mode, -1, org_fx, SWB_signal_fx, &(hBWE_FD->prev_L_swb_norm1), offset ); + get_normalize_spec_fx_32( core, -1, mode, -1, org_fx, SWB_signal_fx, &( hBWE_FD->prev_L_swb_norm1 ), offset ); - IF ( EQ_16(offset , HQ_GENERIC_FOFFSET_32K)) + IF( EQ_16( offset, HQ_GENERIC_FOFFSET_32K ) ) { max_band = 12; move16(); } } - FOR ( n_band=0; n_band 0) + IF( a_fx > 0 ) { - a_fx = Mult_32_16(a_fx, swb_inv_bwe_subband_width_fx[k]);/*6 */ + a_fx = Mult_32_16( a_fx, swb_inv_bwe_subband_width_fx[k] ); /*6 */ - exp = norm_l(p_fx); - tmp = Log2_norm_lc(L_shl(p_fx, exp));/*15 */ - exp = sub(30, add(exp, 6)); - L_tmp1 = L_add(L_deposit_h(exp), L_shr(L_deposit_h(tmp), 15));/*16 */ + exp = norm_l( p_fx ); + tmp = Log2_norm_lc( L_shl( p_fx, exp ) ); /*15 */ + exp = sub( 30, add( exp, 6 ) ); + L_tmp1 = L_add( L_deposit_h( exp ), L_shr( L_deposit_h( tmp ), 15 ) ); /*16 */ - exp = norm_l(a_fx); - tmp = Log2_norm_lc(L_shl(a_fx, exp)); - exp = sub(30, add(exp, 6)); - L_tmp2 = L_add(L_deposit_h(exp), L_shr(L_deposit_h(tmp), 15));/*16 */ + exp = norm_l( a_fx ); + tmp = Log2_norm_lc( L_shl( a_fx, exp ) ); + exp = sub( 30, add( exp, 6 ) ); + L_tmp2 = L_add( L_deposit_h( exp ), L_shr( L_deposit_h( tmp ), 15 ) ); /*16 */ - p2a_fx = L_sub(L_tmp1, L_tmp2);/*16 */ - avgp2a_fx = L_add(avgp2a_fx, p2a_fx);/*16 */ + p2a_fx = L_sub( L_tmp1, L_tmp2 ); /*16 */ + avgp2a_fx = L_add( avgp2a_fx, p2a_fx ); /*16 */ } } - avgp2a_fx = Mult_32_16(avgp2a_fx, inv_band_fx);/*16 + 15 - 15 */ - IF (GT_32(avgp2a_fx , 187227))/*8.6 / 10log10(2), Q16 */ + avgp2a_fx = Mult_32_16( avgp2a_fx, inv_band_fx ); /*16 + 15 - 15 */ + IF( GT_32( avgp2a_fx, 187227 ) ) /*8.6 / 10log10(2), Q16 */ { return HQ_GENERIC_EXC1; } @@ -2793,18 +2781,18 @@ static Word16 decision_hq_generic_class_fx_32 ( * *-------------------------------------------------------------------*/ void hq_generic_encoding_fx( - const Word32 *coefs_fx, /* i : MDCT coefficients of weighted original : Q12 */ - Word16 *hq_generic_fenv_fx, /* i/o: energy of SWB envelope : Q3 */ - const Word16 hq_generic_offset, /* i : frequency offset for extracting energy : Q0 */ - Encoder_State *st_fx, /* i/o: encoder state structure */ - Word16 *hq_generic_exc_clas /* o : bwe excitation class : Q0 */ + const Word32 *coefs_fx, /* i : MDCT coefficients of weighted original : Q12 */ + Word16 *hq_generic_fenv_fx, /* i/o: energy of SWB envelope : Q3 */ + const Word16 hq_generic_offset, /* i : frequency offset for extracting energy : Q0 */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + Word16 *hq_generic_exc_clas /* o : bwe excitation class : Q0 */ ) { Word16 n_coeff, n_band; Word16 indice[HQ_GENERIC_NVQIDX]; Word16 nenv; - Word16 energy_factor_fx[SWB_FENV] = {0}; + Word16 energy_factor_fx[SWB_FENV] = { 0 }; Word16 cs, exp, tmp, tmp2; Word32 energy_fx; Word32 L_tmp, max_coefs_fx; @@ -2813,21 +2801,21 @@ void hq_generic_encoding_fx( BSTR_ENC_HANDLE hBstr = st_fx->hBstr; - IF ( LE_16(hq_generic_offset , HQ_GENERIC_FOFFSET_24K4)) + IF( LE_16( hq_generic_offset, HQ_GENERIC_FOFFSET_24K4 ) ) { nenv = SWB_FENV; move16(); } ELSE { - nenv = SWB_FENV-2; + nenv = SWB_FENV - 2; move16(); } - energy_control_fx_32(st_fx, HQ_CORE, -1, -1, coefs_fx, hq_generic_offset, energy_factor_fx); + energy_control_fx_32( st_fx, HQ_CORE, -1, -1, coefs_fx, hq_generic_offset, energy_factor_fx ); - IF ( EQ_16(hHQ_core->hq_generic_speech_class , 1)) + IF( EQ_16( hHQ_core->hq_generic_speech_class, 1 ) ) { push_indice_fx( hBstr, IND_HQ_SWB_EXC_SP_CLAS, 1, 1 ); *hq_generic_exc_clas = HQ_GENERIC_SP_EXC; @@ -2835,43 +2823,43 @@ void hq_generic_encoding_fx( } ELSE { - *hq_generic_exc_clas = decision_hq_generic_class_fx_32(coefs_fx, hq_generic_offset); + *hq_generic_exc_clas = decision_hq_generic_class_fx_32( coefs_fx, hq_generic_offset ); push_indice_fx( hBstr, IND_HQ_SWB_EXC_SP_CLAS, 0, 1 ); push_indice_fx( hBstr, IND_HQ_SWB_EXC_CLAS, *hq_generic_exc_clas, 1 ); } - FOR ( n_band = 0; n_band < nenv; n_band++ ) + FOR( n_band = 0; n_band < nenv; n_band++ ) { - energy_fx = L_deposit_l(0); - max_coefs_fx = L_deposit_l(0); - tmp2 = add(swb_bwe_subband[n_band+1] , hq_generic_offset); - FOR ( n_coeff = add(swb_bwe_subband[n_band],hq_generic_offset); n_coeff < tmp2; n_coeff++ ) + energy_fx = L_deposit_l( 0 ); + max_coefs_fx = L_deposit_l( 0 ); + tmp2 = add( swb_bwe_subband[n_band + 1], hq_generic_offset ); + FOR( n_coeff = add( swb_bwe_subband[n_band], hq_generic_offset ); n_coeff < tmp2; n_coeff++ ) { - IF (LT_32(max_coefs_fx , L_abs(coefs_fx[n_coeff]))) + IF( LT_32( max_coefs_fx, L_abs( coefs_fx[n_coeff] ) ) ) { - max_coefs_fx = L_abs(coefs_fx[n_coeff]); + max_coefs_fx = L_abs( coefs_fx[n_coeff] ); } } - cs = norm_l(max_coefs_fx); - tmp2 = add(swb_bwe_subband[n_band+1] , hq_generic_offset); - FOR ( n_coeff = add(swb_bwe_subband[n_band],hq_generic_offset); n_coeff < tmp2; n_coeff++ ) + cs = norm_l( max_coefs_fx ); + tmp2 = add( swb_bwe_subband[n_band + 1], hq_generic_offset ); + FOR( n_coeff = add( swb_bwe_subband[n_band], hq_generic_offset ); n_coeff < tmp2; n_coeff++ ) { - tmp = extract_h(L_shl(coefs_fx[n_coeff], cs));/*12 + cs - 16 */ - L_tmp = L_mult0(tmp, tmp);/*2*cs - 8 */ - energy_fx = L_add(energy_fx, L_shr(L_tmp, 5)); + tmp = extract_h( L_shl( coefs_fx[n_coeff], cs ) ); /*12 + cs - 16 */ + L_tmp = L_mult0( tmp, tmp ); /*2*cs - 8 */ + energy_fx = L_add( energy_fx, L_shr( L_tmp, 5 ) ); } - IF (energy_fx != 0) + IF( energy_fx != 0 ) { - L_tmp = Mult_32_16(energy_fx, energy_factor_fx[n_band]);/*2*cs - 13 */ - L_tmp = Mult_32_16(L_tmp, swb_inv_bwe_subband_width_fx[n_band]);/*2*cs - 13 + 15 - 15 */ + L_tmp = Mult_32_16( energy_fx, energy_factor_fx[n_band] ); /*2*cs - 13 */ + L_tmp = Mult_32_16( L_tmp, swb_inv_bwe_subband_width_fx[n_band] ); /*2*cs - 13 + 15 - 15 */ - exp = norm_l(L_tmp); - tmp = Log2_norm_lc(L_shl(L_tmp, exp)); - exp = sub(30, add(exp, 2*cs-13)); + exp = norm_l( L_tmp ); + tmp = Log2_norm_lc( L_shl( L_tmp, exp ) ); + exp = sub( 30, add( exp, 2 * cs - 13 ) ); - L_tmp = Mpy_32_16(exp, tmp, 24660); /* Q14 */ /*10log10(2) in Q13 */ - hq_generic_fenv_fx[n_band] = round_fx(L_shl(L_tmp, 10));/*Q8 */ + L_tmp = Mpy_32_16( exp, tmp, 24660 ); /* Q14 */ /*10log10(2) in Q13 */ + hq_generic_fenv_fx[n_band] = round_fx( L_shl( L_tmp, 10 ) ); /*Q8 */ } ELSE { @@ -2880,77 +2868,77 @@ void hq_generic_encoding_fx( } } - IF ( EQ_16(st_fx->bwidth , FB)) + IF( EQ_16( st_fx->bwidth, FB ) ) { - FOR ( n_band = 0; n_band < DIM_FB; n_band++ ) + FOR( n_band = 0; n_band < DIM_FB; n_band++ ) { - energy_fx = L_deposit_l(0); - max_coefs_fx = L_deposit_l(0); - tmp2 = fb_bwe_subband[add(n_band,1)]; - FOR ( n_coeff = fb_bwe_subband[n_band]; n_coeff < tmp2; n_coeff++ ) + energy_fx = L_deposit_l( 0 ); + max_coefs_fx = L_deposit_l( 0 ); + tmp2 = fb_bwe_subband[add( n_band, 1 )]; + FOR( n_coeff = fb_bwe_subband[n_band]; n_coeff < tmp2; n_coeff++ ) { - IF (LT_32(max_coefs_fx, L_abs(coefs_fx[n_coeff]))) + IF( LT_32( max_coefs_fx, L_abs( coefs_fx[n_coeff] ) ) ) { - max_coefs_fx = L_abs(coefs_fx[n_coeff]); + max_coefs_fx = L_abs( coefs_fx[n_coeff] ); } } - cs = norm_l(max_coefs_fx); - tmp2 = fb_bwe_subband[add(n_band,1)]; - FOR ( n_coeff = fb_bwe_subband[n_band]; n_coeff < tmp2; n_coeff++ ) + cs = norm_l( max_coefs_fx ); + tmp2 = fb_bwe_subband[add( n_band, 1 )]; + FOR( n_coeff = fb_bwe_subband[n_band]; n_coeff < tmp2; n_coeff++ ) { - tmp = extract_h(L_shl(coefs_fx[n_coeff], cs));/*12 + cs - 16 */ - L_tmp = L_mult0(tmp, tmp);/*2*cs - 8 */ - energy_fx = L_add(energy_fx, L_shr(L_tmp, 5)); + tmp = extract_h( L_shl( coefs_fx[n_coeff], cs ) ); /*12 + cs - 16 */ + L_tmp = L_mult0( tmp, tmp ); /*2*cs - 8 */ + energy_fx = L_add( energy_fx, L_shr( L_tmp, 5 ) ); } - IF (energy_fx != 0) + IF( energy_fx != 0 ) { - L_tmp = Mult_32_16(energy_fx, fb_inv_bwe_subband_width_fx[n_band]);/*2*cs - 13 + 18 - 15 */ + L_tmp = Mult_32_16( energy_fx, fb_inv_bwe_subband_width_fx[n_band] ); /*2*cs - 13 + 18 - 15 */ - exp = norm_l(L_tmp); - tmp = Log2_norm_lc(L_shl(L_tmp, exp)); - exp = sub(30, add(exp, 2*cs-13)); + exp = norm_l( L_tmp ); + tmp = Log2_norm_lc( L_shl( L_tmp, exp ) ); + exp = sub( 30, add( exp, 2 * cs - 13 ) ); - L_tmp = Mpy_32_16(exp, tmp, 24660); /* Q14 */ /*10log10(2) in Q13 */ - hq_generic_fenv_fx[add(n_band,nenv)] = round_fx(L_shl(L_tmp, 10));/*Q8 */ + L_tmp = Mpy_32_16( exp, tmp, 24660 ); /* Q14 */ /*10log10(2) in Q13 */ + hq_generic_fenv_fx[add( n_band, nenv )] = round_fx( L_shl( L_tmp, 10 ) ); /*Q8 */ } ELSE { - hq_generic_fenv_fx[add(n_band,nenv)] = -24576; + hq_generic_fenv_fx[add( n_band, nenv )] = -24576; move16(); } } } - freq_weights_fx(hq_generic_fenv_fx, w_NOR_fx, w_env_fx, nenv); + freq_weights_fx( hq_generic_fenv_fx, w_NOR_fx, w_env_fx, nenv ); - FOR ( n_band = 0; n_band < nenv; n_band++ ) + FOR( n_band = 0; n_band < nenv; n_band++ ) { - hq_generic_fenv_fx[n_band] = sub(hq_generic_fenv_fx[n_band], Mean_env_fx[n_band]); + hq_generic_fenv_fx[n_band] = sub( hq_generic_fenv_fx[n_band], Mean_env_fx[n_band] ); } - IF ( st_fx->bwidth == FB ) + IF( st_fx->bwidth == FB ) { - FOR ( n_band = 0; n_band < DIM_FB; n_band++ ) + FOR( n_band = 0; n_band < DIM_FB; n_band++ ) { - hq_generic_fenv_fx[add(n_band,nenv)] = sub(shr(hq_generic_fenv_fx[add(n_band,nenv)], 1), Mean_env_fb_fx[n_band]); + hq_generic_fenv_fx[add( n_band, nenv )] = sub( shr( hq_generic_fenv_fx[add( n_band, nenv )], 1 ), Mean_env_fb_fx[n_band] ); } } /* Energy VQ */ - IF ( LE_16(hq_generic_offset , HQ_GENERIC_FOFFSET_24K4)) + IF( LE_16( hq_generic_offset, HQ_GENERIC_FOFFSET_24K4 ) ) { msvq_interpol_fx( hq_generic_fenv_fx, w_env_fx, indice ); } ELSE { - msvq_interpol_2_fx(hq_generic_fenv_fx, w_env_fx, indice, nenv); + msvq_interpol_2_fx( hq_generic_fenv_fx, w_env_fx, indice, nenv ); } - IF ( EQ_16(st_fx->bwidth , FB)) + IF( EQ_16( st_fx->bwidth, FB ) ) { - indice[5] = vqSimple_w_fx(hq_generic_fenv_fx+nenv, hq_generic_fenv_fx+nenv, EnvCdbkFB_fx, NULL, DIM_FB, N_CB_FB, 0); + indice[5] = vqSimple_w_fx( hq_generic_fenv_fx + nenv, hq_generic_fenv_fx + nenv, EnvCdbkFB_fx, NULL, DIM_FB, N_CB_FB, 0 ); } push_indice_fx( hBstr, IND_SWB_FENV_HQ, indice[0], 5 ); @@ -2958,7 +2946,7 @@ void hq_generic_encoding_fx( push_indice_fx( hBstr, IND_SWB_FENV_HQ, indice[2], 6 ); push_indice_fx( hBstr, IND_SWB_FENV_HQ, indice[3], 5 ); - IF ( LE_16(hq_generic_offset , HQ_GENERIC_FOFFSET_24K4)) + IF( LE_16( hq_generic_offset, HQ_GENERIC_FOFFSET_24K4 ) ) { push_indice_fx( hBstr, IND_SWB_FENV_HQ, indice[4], 6 ); } @@ -2967,38 +2955,38 @@ void hq_generic_encoding_fx( push_indice_fx( hBstr, IND_SWB_FENV_HQ, indice[4], 5 ); } - IF ( EQ_16(st_fx->bwidth , FB)) + IF( EQ_16( st_fx->bwidth, FB ) ) { push_indice_fx( hBstr, IND_FB_FENV_HQ, indice[5], 5 ); } - FOR ( n_band = 0; n_band < nenv; n_band++ ) + FOR( n_band = 0; n_band < nenv; n_band++ ) { - tmp = add(hq_generic_fenv_fx[n_band], Mean_env_fx[n_band]);/*8 */ - L_tmp = L_mult(tmp, 21771);/*26 */ - L_tmp = L_shr(L_tmp, 10);/*16 */ - L_Extract(L_tmp, &exp, &tmp);/* */ - tmp = extract_l(Pow2(13, tmp)); - exp = sub(exp, 13); + tmp = add( hq_generic_fenv_fx[n_band], Mean_env_fx[n_band] ); /*8 */ + L_tmp = L_mult( tmp, 21771 ); /*26 */ + L_tmp = L_shr( L_tmp, 10 ); /*16 */ + L_Extract( L_tmp, &exp, &tmp ); /* */ + tmp = extract_l( Pow2( 13, tmp ) ); + exp = sub( exp, 13 ); #ifdef BASOP_NOGLOB hq_generic_fenv_fx[n_band] = shl_sat( tmp, add( exp, 1 ) ); /*1 */ #else - hq_generic_fenv_fx[n_band] = shl(tmp, add(exp, 1));/*1 */ + hq_generic_fenv_fx[n_band] = shl( tmp, add( exp, 1 ) ); /*1 */ #endif } - IF ( EQ_16(st_fx->bwidth , FB)) + IF( EQ_16( st_fx->bwidth, FB ) ) { - FOR ( n_band = 0; n_band < DIM_FB; n_band++ ) + FOR( n_band = 0; n_band < DIM_FB; n_band++ ) { - tmp = add(hq_generic_fenv_fx[add(n_band,nenv)], Mean_env_fb_fx[n_band]);/*7 */ - L_tmp = L_mult(tmp, 21771);/*25 */ - L_tmp = L_shr(L_tmp, 9);/*16 */ - L_Extract(L_tmp, &exp, &tmp); - tmp = extract_l(Pow2(13, tmp)); - exp = sub(exp, 13); - hq_generic_fenv_fx[add(n_band,nenv)] = shl(tmp, add(exp, 1));/*2 */ + tmp = add( hq_generic_fenv_fx[add( n_band, nenv )], Mean_env_fb_fx[n_band] ); /*7 */ + L_tmp = L_mult( tmp, 21771 ); /*25 */ + L_tmp = L_shr( L_tmp, 9 ); /*16 */ + L_Extract( L_tmp, &exp, &tmp ); + tmp = extract_l( Pow2( 13, tmp ) ); + exp = sub( exp, 13 ); + hq_generic_fenv_fx[add( n_band, nenv )] = shl( tmp, add( exp, 1 ) ); /*2 */ } } @@ -3015,14 +3003,14 @@ void fd_bwe_enc_init_fx( FD_BWE_ENC_HANDLE hBWE_FD /* i/o: FD BWE data handle */ ) { - set16_fx(hBWE_FD->new_input_hp_fx, 0, NS2SA(16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS)); - set16_fx(hBWE_FD->old_input_fx, 0, NS2SA(48000, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS)); - set16_fx(hBWE_FD->old_input_wb_fx, 0, NS2SA(16000, DELAY_FD_BWE_ENC_12k8_NS)); - set16_fx(hBWE_FD->old_input_lp_fx, 0, NS2SA(16000, ACELP_LOOK_NS + DELAY_SWB_TBE_16k_NS)); - set16_fx(hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA(16000, DELAY_FD_BWE_ENC_NS)); + set16_fx( hBWE_FD->new_input_hp_fx, 0, NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS ) ); + set16_fx( hBWE_FD->old_input_fx, 0, NS2SA( 48000, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) ); + set16_fx( hBWE_FD->old_input_wb_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_12k8_NS ) ); + set16_fx( hBWE_FD->old_input_lp_fx, 0, NS2SA( 16000, ACELP_LOOK_NS + DELAY_SWB_TBE_16k_NS ) ); + set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); hBWE_FD->prev_mode = NORMAL; move16(); - set16_fx(hBWE_FD->L_old_wtda_swb_fx, 0, L_FRAME48k); + set16_fx( hBWE_FD->L_old_wtda_swb_fx, 0, L_FRAME48k ); hBWE_FD->prev_L_swb_norm1 = 8; move16(); hBWE_FD->prev_global_gain_fx = 0; @@ -3034,11 +3022,11 @@ void fd_bwe_enc_init_fx( hBWE_FD->prev_Q_input_lp = 0; move16(); - set16_fx(hBWE_FD->old_fdbwe_speech_fx, 0, L_FRAME48k); + set16_fx( hBWE_FD->old_fdbwe_speech_fx, 0, L_FRAME48k ); hBWE_FD->mem_deemph_old_syn_fx = 0; move16(); - //hBWE_FD->mem_old_wtda_swb = 0.0f; + // hBWE_FD->mem_old_wtda_swb = 0.0f; return; } diff --git a/lib_enc/swb_bwe_enc_hr_fx.c b/lib_enc/swb_bwe_enc_hr_fx.c index 667ed450a..006a6195b 100644 --- a/lib_enc/swb_bwe_enc_hr_fx.c +++ b/lib_enc/swb_bwe_enc_hr_fx.c @@ -4,15 +4,15 @@ #include #include #include "options.h" -#include "cnst.h" /* Common constants */ -#include "rom_enc.h" /* Encoder static table prototypes */ -#include "rom_com_fx.h" /* Static table prototypes */ +#include "cnst.h" /* Common constants */ +#include "rom_enc.h" /* Encoder static table prototypes */ +#include "rom_com_fx.h" /* Static table prototypes */ //#include "prot_fx.h" /* Function prototypes */ #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ -#include "basop_util.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ +#include "basop_util.h" /* Function prototypes */ /*-------------------------------------------------------------------* @@ -22,17 +22,17 @@ /* Values that Allow to Use Left/Right Shifting instead of Division & 'and' (&) instead of 'modulo' (%) which is also a costly division. */ #define NUM_TIME_SW_BLKS_SHIFT 2 -#define NUM_TIME_SW_BLKS_MASK (NUM_TIME_SWITCHING_BLOCKS-1) -#define WIDTH_BAND_SHIFT 3 +#define NUM_TIME_SW_BLKS_MASK ( NUM_TIME_SWITCHING_BLOCKS - 1 ) +#define WIDTH_BAND_SHIFT 3 /* Values for Max Scaling of Different Sub Function */ -#define DETECT_TRANSIENT_MAX_Q (11+2) -#define MAX_Q_NEW_INPUT 8 +#define DETECT_TRANSIENT_MAX_Q ( 11 + 2 ) +#define MAX_Q_NEW_INPUT 8 #define NON_TRANSIENT_RESCALE_Q_GUARD 4 -#define TRANSIENT_RESCALE_Q_GUARD 0 -#define SPECTRUM_RESCALE_Q_GUARD 1 -#define MAX_Q_UPSCALING 6 -#define MAX_AVQ_COD_Q_IN 14 +#define TRANSIENT_RESCALE_Q_GUARD 0 +#define SPECTRUM_RESCALE_Q_GUARD 1 +#define MAX_Q_UPSCALING 6 +#define MAX_AVQ_COD_Q_IN 14 /*-------------------------------------------------------------------* * en_band_quant_fx() @@ -40,10 +40,10 @@ * Quantize the band envelop *-------------------------------------------------------------------*/ -static Word16 en_band_quant_fx(/* o : quantization index */ - Word16 *en_band, /* i/o: (un)quantized envelope value */ - const Word16 *env_code, /* i : envelope codebook */ - const Word16 N /* i : codebook dimension */ +static Word16 en_band_quant_fx( /* o : quantization index */ + Word16 *en_band, /* i/o: (un)quantized envelope value */ + const Word16 *env_code, /* i : envelope codebook */ + const Word16 N /* i : codebook dimension */ ) { Word16 i, ind, tmp16; @@ -57,30 +57,30 @@ static Word16 en_band_quant_fx(/* o : quantization index */ FOR( i = 0; i < N; i++ ) { /* This is More Efficient */ - tmp16 = sub(en_band[0], env_code[i*2]); - L_err = L_mult0(tmp16, tmp16); - tmp16 = sub(en_band[1], env_code[i*2+1]); - L_err = L_mac0(L_err, tmp16, tmp16); + tmp16 = sub( en_band[0], env_code[i * 2] ); + L_err = L_mult0( tmp16, tmp16 ); + tmp16 = sub( en_band[1], env_code[i * 2 + 1] ); + L_err = L_mac0( L_err, tmp16, tmp16 ); /* L_err = 0; move32(); FOR (j = 0; j < 2; j++) { tmp16 = sub(en_band[j], env_code[i*2+j]); L_err = L_mac0(L_err, tmp16, tmp16); } */ - if (LT_32(L_err, L_maxerr)) + if ( LT_32( L_err, L_maxerr ) ) { ind = i; move16(); } - L_maxerr = L_min(L_maxerr, L_err); + L_maxerr = L_min( L_maxerr, L_err ); } - en_band[0] = env_code[2*ind]; + en_band[0] = env_code[2 * ind]; move16(); - en_band[1] = env_code[2*ind+1]; + en_band[1] = env_code[2 * ind + 1]; move16(); - return( ind ); + return ( ind ); } /*-------------------------------------------------------------------* @@ -89,19 +89,19 @@ static Word16 en_band_quant_fx(/* o : quantization index */ * HR SWB BWE encoder *-------------------------------------------------------------------*/ void swb_bwe_enc_hr_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - Word16 *new_input_fx, /* i : input signal */ - Word16 new_input_fx_exp, /* i : Exponent of input signal */ - const Word16 input_frame, /* i : frame length */ - const Word16 unbits /* i : number of core unused bits */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + Word16 *new_input_fx, /* i : input signal */ + Word16 new_input_fx_exp, /* i : Exponent of input signal */ + const Word16 input_frame, /* i : frame length */ + const Word16 unbits /* i : number of core unused bits */ ) { Word16 i, j, k, nBits, nBits_total, nBits_block, Nsv, Nsv2, width_noncoded; Word16 is_transient, pos; - Word16 x_norm_fx[NSV_MAX*(WIDTH_BAND+1)], x_norm1_fx[NSV_MAX*(WIDTH_BAND+1)]; + Word16 x_norm_fx[NSV_MAX * ( WIDTH_BAND + 1 )], x_norm1_fx[NSV_MAX * ( WIDTH_BAND + 1 )]; Word32 t_audio32[L_FRAME48k]; Word16 *t_audio_fx, t_audio_fx_exp; - Word16 *t_audio_tmp_fx; /* same exponent as 't_audio_fx' */ + Word16 *t_audio_tmp_fx; /* same exponent as 't_audio_fx' */ Word16 en_band_fx[N_BANDS_BWE_HR]; /* in Q9 */ Word16 gain1_fx, exp1, gain2_fx, exp2; Word32 L_gain_fx; @@ -114,8 +114,8 @@ void swb_bwe_enc_hr_fx( Word32 L_en_noncoded_fx; /* in Q16 */ Word16 en_noncoded_fx_exp; Word16 scl; -#if (N_BANDS_BWE_HR*WIDTH_NONTRANS_FREQ_COEF) > L_FRAME48k - Word32 L_t_audio_tmp_fx[N_BANDS_BWE_HR*WIDTH_NONTRANS_FREQ_COEF]; +#if ( N_BANDS_BWE_HR * WIDTH_NONTRANS_FREQ_COEF ) > L_FRAME48k + Word32 L_t_audio_tmp_fx[N_BANDS_BWE_HR * WIDTH_NONTRANS_FREQ_COEF]; #else Word32 L_t_audio_tmp_fx[L_FRAME48k]; #endif @@ -132,35 +132,35 @@ void swb_bwe_enc_hr_fx( *---------------------------------------------------------------------*/ /* Use 32 Bits Buffer to Store Two 16 Bits Vectors in Order to Save Stack Space */ - t_audio_fx = (Word16 *)&t_audio32[0]; + t_audio_fx = (Word16 *) &t_audio32[0]; move16(); - t_audio_tmp_fx = (Word16 *)&t_audio32[L_FRAME48k/2]; + t_audio_tmp_fx = (Word16 *) &t_audio32[L_FRAME48k / 2]; move16(); ind2 = 0; - move16();/* only to suppress warnings */ + move16(); /* only to suppress warnings */ Nsv2 = 0; - move16();/* only to suppress warnings */ + move16(); /* only to suppress warnings */ L_en_noncoded_fx = 0; - move16();/* only to suppress warnings */ + move16(); /* only to suppress warnings */ en_noncoded_fx_exp = 0; - move16();/* only to suppress warnings */ + move16(); /* only to suppress warnings */ gain2_fx = 0; move16(); /* reset memories in case that last frame was a different technology */ test(); - IF( EQ_16(st_fx->last_core, HQ_CORE)||NE_16(st_fx->last_extl,st_fx->extl)) + IF( EQ_16( st_fx->last_core, HQ_CORE ) || NE_16( st_fx->last_extl, st_fx->extl ) ) { - set16_fx(hBWE_FD->L_old_wtda_swb_fx, 0, L_FRAME48k ); + set16_fx( hBWE_FD->L_old_wtda_swb_fx, 0, L_FRAME48k ); st_fx->Q_old_wtda = 0; move16(); } /* calculate SWB BWE bit-budget (extension layer bit-rate + AVQ unused bits from the core layer) */ /* nBits = st->extl_brate/50 + unbits */ - assert(SWB_BWE_16k == st_fx->extl_brate); - nBits = add(SWB_BWE_16k/50,unbits); /* st->extl_brate is always 16kbps */ + assert( SWB_BWE_16k == st_fx->extl_brate ); + nBits = add( SWB_BWE_16k / 50, unbits ); /* st->extl_brate is always 16kbps */ nBits_total = nBits; move16(); @@ -168,24 +168,24 @@ void swb_bwe_enc_hr_fx( * detect transient frames *---------------------------------------------------------------------*/ /* Calc Room for Energy */ - temp = norm_l(st_fx->EnergyLT_fx); + temp = norm_l( st_fx->EnergyLT_fx ); /* Calc Max Exponent for 'new_input_fx' */ - temp = shr(temp, 1); - temp = add(temp, st_fx->EnergyLT_fx_exp); - temp = sub(temp, new_input_fx_exp); + temp = shr( temp, 1 ); + temp = add( temp, st_fx->EnergyLT_fx_exp ); + temp = sub( temp, new_input_fx_exp ); /* Do not Upscale */ - temp = s_min(0, temp); + temp = s_min( 0, temp ); /* Limit Input to 'Q_DETECT_TRANSIENT_MAX_Q' (to avoid overflow in 'detect_transient_fx' for Energy Loop)*/ - exp1 = Find_Max_Norm16(new_input_fx, input_frame); - exp1 = sub(exp1, 15-DETECT_TRANSIENT_MAX_Q); + exp1 = Find_Max_Norm16( new_input_fx, input_frame ); + exp1 = sub( exp1, 15 - DETECT_TRANSIENT_MAX_Q ); /* Downscale at Least by 'exp1' */ - temp = s_min(temp, exp1); + temp = s_min( temp, exp1 ); /* Set Exponent of Input */ - exp1 = add(new_input_fx_exp, temp); + exp1 = add( new_input_fx_exp, temp ); - Copy_Scale_sig(new_input_fx, t_audio_fx, input_frame, temp); + Copy_Scale_sig( new_input_fx, t_audio_fx, input_frame, temp ); /* Bring Energy in 2*Q'exp1' */ - st_fx->EnergyLT_fx = L_shl(st_fx->EnergyLT_fx, shl(sub(exp1, st_fx->EnergyLT_fx_exp), 1)); + st_fx->EnergyLT_fx = L_shl( st_fx->EnergyLT_fx, shl( sub( exp1, st_fx->EnergyLT_fx_exp ), 1 ) ); is_transient = detect_transient_fx( t_audio_fx, input_frame, exp1, st_fx ); st_fx->EnergyLT_fx_exp = exp1; @@ -201,74 +201,73 @@ void swb_bwe_enc_hr_fx( /* Save Exponent of Memory (relative to Q15) */ st_fx->Q_old_wtda = new_input_fx_exp; move16(); - new_input_fx_exp=0; + new_input_fx_exp = 0; wtda_fx( new_input_fx, &new_input_fx_exp, L_t_audio_tmp_fx, hBWE_FD->L_old_wtda_swb_fx, &st_fx->Q_old_wtda, ALDO_WINDOW, ALDO_WINDOW, input_frame ); - direct_transform_fx(L_t_audio_tmp_fx, t_audio32, is_transient, input_frame, &new_input_fx_exp - , /*st_fx->element_mode*/EVS_MONO ); + direct_transform_fx( L_t_audio_tmp_fx, t_audio32, is_transient, input_frame, &new_input_fx_exp, /*st_fx->element_mode*/ EVS_MONO ); /* Convert to 16 Bits (Calc Shift Required to Stay within MAX_Q_NEW_INPUT) */ - scl = sub(16+MAX_Q_NEW_INPUT, new_input_fx_exp); + scl = sub( 16 + MAX_Q_NEW_INPUT, new_input_fx_exp ); /* Possible to Upscale? */ - IF (scl > 0) + IF( scl > 0 ) { /* Yes */ /* Calc Room to Upscale */ - t_audio_fx_exp = Find_Max_Norm32(t_audio32, input_frame); + t_audio_fx_exp = Find_Max_Norm32( t_audio32, input_frame ); /* Stay within MAX_Q_NEW_INPUT */ - scl = s_min(t_audio_fx_exp, scl); + scl = s_min( t_audio_fx_exp, scl ); } - Copy_Scale_sig32_16(t_audio32, t_audio_fx, input_frame, scl); - t_audio_fx_exp = add(sub(new_input_fx_exp, 16), scl); + Copy_Scale_sig32_16( t_audio32, t_audio_fx, input_frame, scl ); + t_audio_fx_exp = add( sub( new_input_fx_exp, 16 ), scl ); IF( is_transient ) { nBits = -1; move16(); /* is_transient flag */ /* 'nBits_block = nBits_total / NUM_TIME_SWITCHING_BLOCKS' */ - nBits_block = shr(nBits_total, NUM_TIME_SW_BLKS_SHIFT); + nBits_block = shr( nBits_total, NUM_TIME_SW_BLKS_SHIFT ); /* 'nBits += nBits_total % NUM_TIME_SWITCHING_BLOCKS' */ - nBits = add(nBits, s_and(nBits_total, NUM_TIME_SW_BLKS_MASK)); + nBits = add( nBits, s_and( nBits_total, NUM_TIME_SW_BLKS_MASK ) ); /* set width of noncoded (blind estimated) spectrum */ - IF( EQ_16(st_fx->extl, SWB_BWE_HIGHRATE)) + IF( EQ_16( st_fx->extl, SWB_BWE_HIGHRATE ) ) { - width_noncoded = L_FRAME32k/NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_END_FREQ_COEF; + width_noncoded = L_FRAME32k / NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_END_FREQ_COEF; move16(); } ELSE /* st->extl == FB_BWE_HIGHRATE */ { - width_noncoded = (2*END_FREQ_BWE_FULL_FB/50)/NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_END_FREQ_COEF; + width_noncoded = ( 2 * END_FREQ_BWE_FULL_FB / 50 ) / NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_END_FREQ_COEF; move16(); } /* Find Max Scaling on Remaining Frequencies (after frequencies of non interest are zeroed) */ - temp = shr(input_frame, NUM_TIME_SW_BLKS_SHIFT); + temp = shr( input_frame, NUM_TIME_SW_BLKS_SHIFT ); scl = 99; move16(); ptr16 = &t_audio_fx[NUM_TRANS_START_FREQ_COEF]; move16(); - FOR( k = 0; k < input_frame; k+=temp ) + FOR( k = 0; k < input_frame; k += temp ) { /* from t_audio_fx[k..NUM_TRANS_START_FREQ_COEF+k-1] will be zeroed out */ /* AND */ /* from t_audio_fx[k+L_FRAME32k/NUM_TIME_SWITCHING_BLOCKS..k+switching_block_length-1] will be zeroed out */ /* Find Max Scaling on Remaining Frequencies */ - scl = s_min(Find_Max_Norm16(ptr16+k, L_FRAME32k/NUM_TIME_SWITCHING_BLOCKS-NUM_TRANS_START_FREQ_COEF), scl); - IF (scl == 0) + scl = s_min( Find_Max_Norm16( ptr16 + k, L_FRAME32k / NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_START_FREQ_COEF ), scl ); + IF( scl == 0 ) { BREAK; } } /* Need to Keep at Least some Guard Bits */ - scl = s_max(0, sub(scl, TRANSIENT_RESCALE_Q_GUARD)); + scl = s_max( 0, sub( scl, TRANSIENT_RESCALE_Q_GUARD ) ); /* Reduce if 't_audio_fx_exp' is Q14 or more (AVQ Cod overflow with more than Q14 Input) */ - scl = sub(scl, s_max(0, sub(add(scl, t_audio_fx_exp), MAX_AVQ_COD_Q_IN))); + scl = sub( scl, s_max( 0, sub( add( scl, t_audio_fx_exp ), MAX_AVQ_COD_Q_IN ) ) ); /* Update Exponent of 't_audio_fx' */ /* Here tne Signal is not Upscaled yet and some adjustement to 't_audio_fx_exp' will be used until the signal is indeed upscaled by 'scl'. That Occurs at the 'normalization with global gain'. */ - t_audio_fx_exp = add(t_audio_fx_exp, scl); + t_audio_fx_exp = add( t_audio_fx_exp, scl ); /*---------------------------------------------------------------------* * transient frames: processing in blocks (subframes) @@ -276,25 +275,25 @@ void swb_bwe_enc_hr_fx( FOR( k = 0; k < NUM_TIME_SWITCHING_BLOCKS; k++ ) { - nBits = add(nBits, nBits_block); + nBits = add( nBits, nBits_block ); - temp = i_mult2(k, shr(input_frame, NUM_TIME_SW_BLKS_SHIFT)); + temp = i_mult2( k, shr( input_frame, NUM_TIME_SW_BLKS_SHIFT ) ); /* Calculate Original Exponent (because the part of the signal that is used to Calculate the Energy is not yet Scaled) */ - j = sub(t_audio_fx_exp, scl); + j = sub( t_audio_fx_exp, scl ); /* compute energy of noncoded (14.4-20kHz) spectrum */ - IF( EQ_16(st_fx->extl, FB_BWE_HIGHRATE)) + IF( EQ_16( st_fx->extl, FB_BWE_HIGHRATE ) ) { - L_tmp = Calc_Energy_Autoscaled(t_audio_fx + add(temp, NUM_TRANS_END_FREQ_COEF), j, width_noncoded, &temp2); - L_en_noncoded_fx = Sqrt_Ratio32(L_tmp, temp2, L_deposit_l(width_noncoded), 0, &en_noncoded_fx_exp); - en_noncoded_fx_exp = sub(31, en_noncoded_fx_exp); + L_tmp = Calc_Energy_Autoscaled( t_audio_fx + add( temp, NUM_TRANS_END_FREQ_COEF ), j, width_noncoded, &temp2 ); + L_en_noncoded_fx = Sqrt_Ratio32( L_tmp, temp2, L_deposit_l( width_noncoded ), 0, &en_noncoded_fx_exp ); + en_noncoded_fx_exp = sub( 31, en_noncoded_fx_exp ); } /* keep only frequencies in interest */ set16_fx( t_audio_fx + temp, 0, NUM_TRANS_START_FREQ_COEF ); - set16_fx( t_audio_fx + add(temp, L_FRAME32k/NUM_TIME_SWITCHING_BLOCKS), 0, shr(sub(input_frame, L_FRAME32k), NUM_TIME_SW_BLKS_SHIFT) ); + set16_fx( t_audio_fx + add( temp, L_FRAME32k / NUM_TIME_SWITCHING_BLOCKS ), 0, shr( sub( input_frame, L_FRAME32k ), NUM_TIME_SW_BLKS_SHIFT ) ); /*---------------------------------------------------------------------* * global gain coding @@ -304,35 +303,34 @@ void swb_bwe_enc_hr_fx( /* Original float Code: 'gain = (float)sqrt( gain ) / (WIDTH_TRANS_FREQ_COEF*N_BANDS_TRANS_BWE_HR)' */ /* Put Divisor to Square to Move it Inside the Sqrt */ /* So we can do 'sqrt( gain (WIDTH_TRANS_FREQ_COEF*N_BANDS_TRANS_BWE_HR)^2)' */ - L_temp = L_mult0(WIDTH_TRANS_FREQ_COEF*N_BANDS_TRANS_BWE_HR, WIDTH_TRANS_FREQ_COEF*N_BANDS_TRANS_BWE_HR); - L_tmp = Calc_Energy_Autoscaled(t_audio_fx + add(temp, NUM_TRANS_START_FREQ_COEF), j, WIDTH_TRANS_FREQ_COEF*N_BANDS_TRANS_BWE_HR, &temp2); - L_tmp = Sqrt_Ratio32(L_tmp, temp2, L_temp, /*L_temp is in Q0*/0, &exp2); + L_temp = L_mult0( WIDTH_TRANS_FREQ_COEF * N_BANDS_TRANS_BWE_HR, WIDTH_TRANS_FREQ_COEF * N_BANDS_TRANS_BWE_HR ); + L_tmp = Calc_Energy_Autoscaled( t_audio_fx + add( temp, NUM_TRANS_START_FREQ_COEF ), j, WIDTH_TRANS_FREQ_COEF * N_BANDS_TRANS_BWE_HR, &temp2 ); + L_tmp = Sqrt_Ratio32( L_tmp, temp2, L_temp, /*L_temp is in Q0*/ 0, &exp2 ); /* Put in Q16 */ - L_gain_fx = L_shr(L_tmp, sub(31-16, exp2)); /* 31: 'L_tmp' is already in Q31 */ + L_gain_fx = L_shr( L_tmp, sub( 31 - 16, exp2 ) ); /* 31: 'L_tmp' is already in Q31 */ - ind1 = gain_quant_fx( &L_gain_fx, &gain1_fx, LG10_MIN_GLOB_GAIN_BWE_HR_Q14, LG10_MAX_GLOB_GAIN_BWE_HR_Q13, NBITS_GLOB_GAIN_BWE_HR, &exp1); + ind1 = gain_quant_fx( &L_gain_fx, &gain1_fx, LG10_MIN_GLOB_GAIN_BWE_HR_Q14, LG10_MAX_GLOB_GAIN_BWE_HR_Q13, NBITS_GLOB_GAIN_BWE_HR, &exp1 ); push_indice_fx( hBstr, IND_HR_GAIN, ind1, NBITS_GLOB_GAIN_BWE_HR ); - nBits = sub(nBits, NBITS_GLOB_GAIN_BWE_HR); + nBits = sub( nBits, NBITS_GLOB_GAIN_BWE_HR ); /* normalization with global gain */ - ptr16 = &t_audio_fx[add(NUM_TRANS_START_FREQ_COEF, temp)]; + ptr16 = &t_audio_fx[add( NUM_TRANS_START_FREQ_COEF, temp )]; move16(); - temp2 = negate(exp1); - gain2_fx = Invert16(gain1_fx, &temp2); + temp2 = negate( exp1 ); + gain2_fx = Invert16( gain1_fx, &temp2 ); /* Also Upscale by 'scl' */ - temp2 = sub(temp2, scl); - FOR( i=0; iextl, SWB_BWE_HIGHRATE)) + IF( NE_16( st_fx->extl, SWB_BWE_HIGHRATE ) ) { /* st->extl == FB_BWE_HIGHRATE */ /* 'en_noncoded /= (gain * en_band[N_BANDS_TRANS_BWE_HR-1])' */ /* Normalize 'L_en_noncoded_fx' */ - j = norm_l(L_en_noncoded_fx); - L_en_noncoded_fx = L_shl(L_en_noncoded_fx, j); - en_noncoded_fx_exp = add(en_noncoded_fx_exp, j); + j = norm_l( L_en_noncoded_fx ); + L_en_noncoded_fx = L_shl( L_en_noncoded_fx, j ); + en_noncoded_fx_exp = add( en_noncoded_fx_exp, j ); /* Calc Divisor */ - L_temp = L_mult0(gain1_fx, en_band_fx[N_BANDS_TRANS_BWE_HR-1]); + L_temp = L_mult0( gain1_fx, en_band_fx[N_BANDS_TRANS_BWE_HR - 1] ); /* Normalize Divisor */ - temp2 = norm_l(L_temp); - L_temp = L_shl(L_temp, temp2); - temp2 = sub(add(9, temp2), exp1); /* Q9 for 'en_band_fx' */ - j = Invert16(round_fx(L_temp), &temp2); - L_temp = Mult_32_16(L_en_noncoded_fx, j); - temp2 = add(temp2, en_noncoded_fx_exp); + temp2 = norm_l( L_temp ); + L_temp = L_shl( L_temp, temp2 ); + temp2 = sub( add( 9, temp2 ), exp1 ); /* Q9 for 'en_band_fx' */ + j = Invert16( round_fx( L_temp ), &temp2 ); + L_temp = Mult_32_16( L_en_noncoded_fx, j ); + temp2 = add( temp2, en_noncoded_fx_exp ); /* Put in Q16 */ - L_temp = L_shr(L_temp, temp2); + L_temp = L_shr( L_temp, temp2 ); - IF( L_msu0(L_temp, BWE_HR_TRANS_EN_LIMIT1_FX_Q16, 1) < 0) + IF( L_msu0( L_temp, BWE_HR_TRANS_EN_LIMIT1_FX_Q16, 1 ) < 0 ) { ind1 = 1; move16(); - L_en_noncoded_fx = L_mult0(en_band_fx[N_BANDS_TRANS_BWE_HR-1], BWE_HR_TRANS_EN_LIMIT1_FX_Q16); + L_en_noncoded_fx = L_mult0( en_band_fx[N_BANDS_TRANS_BWE_HR - 1], BWE_HR_TRANS_EN_LIMIT1_FX_Q16 ); } - ELSE IF( L_msu0(L_temp, BWE_HR_TRANS_EN_LIMIT2_FX_Q16, 1) < 0) + ELSE IF( L_msu0( L_temp, BWE_HR_TRANS_EN_LIMIT2_FX_Q16, 1 ) < 0 ) { ind1 = 2; move16(); - L_en_noncoded_fx = L_mult0(en_band_fx[N_BANDS_TRANS_BWE_HR-1], BWE_HR_TRANS_EN_LIMIT2_FX_Q16); + L_en_noncoded_fx = L_mult0( en_band_fx[N_BANDS_TRANS_BWE_HR - 1], BWE_HR_TRANS_EN_LIMIT2_FX_Q16 ); } - ELSE IF( L_msu0(L_temp, BWE_HR_TRANS_EN_LIMIT3_FX_Q16, 1) < 0) + ELSE IF( L_msu0( L_temp, BWE_HR_TRANS_EN_LIMIT3_FX_Q16, 1 ) < 0 ) { ind1 = 3; move16(); - L_en_noncoded_fx = L_mult0(en_band_fx[N_BANDS_TRANS_BWE_HR-1], BWE_HR_TRANS_EN_LIMIT3_FX_Q16); + L_en_noncoded_fx = L_mult0( en_band_fx[N_BANDS_TRANS_BWE_HR - 1], BWE_HR_TRANS_EN_LIMIT3_FX_Q16 ); } ELSE { ind1 = 0; move16(); - L_en_noncoded_fx = L_deposit_h(en_band_fx[N_BANDS_TRANS_BWE_HR-1]); /* to Put in Q16+9 */ + L_en_noncoded_fx = L_deposit_h( en_band_fx[N_BANDS_TRANS_BWE_HR - 1] ); /* to Put in Q16+9 */ } push_indice_fx( hBstr, IND_HR_HF_GAIN, ind1, NBITS_HF_GAIN_BWE_HR ); - nBits = sub(nBits, NBITS_HF_GAIN_BWE_HR); + nBits = sub( nBits, NBITS_HF_GAIN_BWE_HR ); } ELSE { - L_en_noncoded_fx = L_deposit_h(en_band_fx[N_BANDS_TRANS_BWE_HR-1]); + L_en_noncoded_fx = L_deposit_h( en_band_fx[N_BANDS_TRANS_BWE_HR - 1] ); } - en_noncoded_fx_exp = 9+16; + en_noncoded_fx_exp = 9 + 16; move16(); /* 9 for 'en_band_fx', 16 for 'BWE_HR_TRANS_EN_LIMIT...' */ /*---------------------------------------------------------------------* * AVQ coding (quantize normalized spectrum) *---------------------------------------------------------------------*/ - Nsv = (NUM_TRANS_END_FREQ_COEF - NUM_TRANS_START_FREQ_COEF) / WIDTH_BAND; + Nsv = ( NUM_TRANS_END_FREQ_COEF - NUM_TRANS_START_FREQ_COEF ) / WIDTH_BAND; move16(); - AVQ_cod_fx(t_audio_fx + add(temp, NUM_TRANS_START_FREQ_COEF), x_norm_fx, nBits, Nsv, t_audio_fx_exp); - AVQ_encmux_fx(hBstr, st_fx->extl, x_norm_fx, &nBits, Nsv, nq, 0, sub(Nsv, 1)); - + AVQ_cod_fx( t_audio_fx + add( temp, NUM_TRANS_START_FREQ_COEF ), x_norm_fx, nBits, Nsv, t_audio_fx_exp ); + AVQ_encmux_fx( hBstr, st_fx->extl, x_norm_fx, &nBits, Nsv, nq, 0, sub( Nsv, 1 ) ); } } ELSE /* !is_transient */ { /* subtract one bit for is_transient flag */ - nBits = sub(nBits, 1); + nBits = sub( nBits, 1 ); /*---------------------------------------------------------------------* * processing of normal (non-transient) frames *---------------------------------------------------------------------*/ /* set width of noncoded (blind estimated) spectrum */ - IF( EQ_16(st_fx->extl, SWB_BWE_HIGHRATE)) + IF( EQ_16( st_fx->extl, SWB_BWE_HIGHRATE ) ) { width_noncoded = L_FRAME32k - NUM_NONTRANS_END_FREQ_COEF; move16(); } - ELSE /* st->extl == FB_BWE_HIGHRATE */ + ELSE /* st->extl == FB_BWE_HIGHRATE */ { - width_noncoded = 2*END_FREQ_BWE_FULL_FB/50 - NUM_NONTRANS_END_FREQ_COEF; + width_noncoded = 2 * END_FREQ_BWE_FULL_FB / 50 - NUM_NONTRANS_END_FREQ_COEF; move16(); } /* compute energy of noncoded (14.4-20kHz) spectrum */ - IF( EQ_16(st_fx->extl, FB_BWE_HIGHRATE)) + IF( EQ_16( st_fx->extl, FB_BWE_HIGHRATE ) ) { - L_tmp = Calc_Energy_Autoscaled(t_audio_fx + NUM_NONTRANS_END_FREQ_COEF, t_audio_fx_exp, width_noncoded, &temp2); - L_en_noncoded_fx = Sqrt_Ratio32(L_tmp, temp2, L_deposit_l(width_noncoded), 0, &en_noncoded_fx_exp); - en_noncoded_fx_exp = sub(31, en_noncoded_fx_exp); + L_tmp = Calc_Energy_Autoscaled( t_audio_fx + NUM_NONTRANS_END_FREQ_COEF, t_audio_fx_exp, width_noncoded, &temp2 ); + L_en_noncoded_fx = Sqrt_Ratio32( L_tmp, temp2, L_deposit_l( width_noncoded ), 0, &en_noncoded_fx_exp ); + en_noncoded_fx_exp = sub( 31, en_noncoded_fx_exp ); } /* keep only frequencies in interest */ set16_fx( t_audio_fx, 0, NUM_NONTRANS_START_FREQ_COEF ); - set16_fx( t_audio_fx + NUM_NONTRANS_END_FREQ_COEF, 0, sub(input_frame, NUM_NONTRANS_END_FREQ_COEF) ); + set16_fx( t_audio_fx + NUM_NONTRANS_END_FREQ_COEF, 0, sub( input_frame, NUM_NONTRANS_END_FREQ_COEF ) ); /*---------------------------------------------------------------------* * global gain coding *---------------------------------------------------------------------*/ /* compute and quantize global gain */ - L_tmp = Calc_Energy_Autoscaled(t_audio_fx + NUM_NONTRANS_START_FREQ_COEF, t_audio_fx_exp, WIDTH_NONTRANS_FREQ_COEF*N_BANDS_BWE_HR, &temp2); + L_tmp = Calc_Energy_Autoscaled( t_audio_fx + NUM_NONTRANS_START_FREQ_COEF, t_audio_fx_exp, WIDTH_NONTRANS_FREQ_COEF * N_BANDS_BWE_HR, &temp2 ); /* Original float Code: 'gain = (float)sqrt( gain ) / (WIDTH_TRANS_FREQ_COEF*N_BANDS_TRANS_BWE_HR)' */ /* Put Divisor to Square to Move it Inside the Sqrt */ /* So we can do 'sqrt( gain (WIDTH_NONTRANS_FREQ_COEF*N_BANDS_BWE_HR)^2)' */ - L_temp = L_mult0(WIDTH_NONTRANS_FREQ_COEF*N_BANDS_BWE_HR, WIDTH_NONTRANS_FREQ_COEF*N_BANDS_BWE_HR); - L_tmp = Sqrt_Ratio32(L_tmp, temp2, L_temp, /*L_temp is in Q0*/0, &exp2); + L_temp = L_mult0( WIDTH_NONTRANS_FREQ_COEF * N_BANDS_BWE_HR, WIDTH_NONTRANS_FREQ_COEF * N_BANDS_BWE_HR ); + L_tmp = Sqrt_Ratio32( L_tmp, temp2, L_temp, /*L_temp is in Q0*/ 0, &exp2 ); /* Put in Q16 */ - L_gain_fx = L_shr(L_tmp, sub(31-16, exp2)); /* 31: 'L_tmp' is already in Q31 */ - ind1 = gain_quant_fx( &L_gain_fx, &gain1_fx, LG10_MIN_GLOB_GAIN_BWE_HR_Q14, LG10_MAX_GLOB_GAIN_BWE_HR_Q13, NBITS_GLOB_GAIN_BWE_HR, &exp1); + L_gain_fx = L_shr( L_tmp, sub( 31 - 16, exp2 ) ); /* 31: 'L_tmp' is already in Q31 */ + ind1 = gain_quant_fx( &L_gain_fx, &gain1_fx, LG10_MIN_GLOB_GAIN_BWE_HR_Q14, LG10_MAX_GLOB_GAIN_BWE_HR_Q13, NBITS_GLOB_GAIN_BWE_HR, &exp1 ); push_indice_fx( hBstr, IND_HR_GAIN, ind1, NBITS_GLOB_GAIN_BWE_HR ); - nBits = sub(nBits, NBITS_GLOB_GAIN_BWE_HR); + nBits = sub( nBits, NBITS_GLOB_GAIN_BWE_HR ); /* normalization with global gain */ ptr16 = &t_audio_fx[NUM_NONTRANS_START_FREQ_COEF]; move16(); /* Find Max Scaling on Remaining Frequencies */ - temp2 = Find_Max_Norm16(ptr16, NUM_NONTRANS_END_FREQ_COEF-NUM_NONTRANS_START_FREQ_COEF); - temp2 = s_max(0, sub(temp2, NON_TRANSIENT_RESCALE_Q_GUARD)); - temp2 = s_min(temp2, MAX_Q_UPSCALING); - t_audio_fx_exp = add(t_audio_fx_exp, temp2); - temp2 = sub(temp2, exp1); - temp = Invert16(gain1_fx, &temp2); - - FOR( i=0; iextl, SWB_BWE_HIGHRATE)) + IF( NE_16( st_fx->extl, SWB_BWE_HIGHRATE ) ) { /* st->extl == FB_BWE_HIGHRATE */ /* 'en_noncoded /= (gain * min_env)' */ /* Normalize 'L_en_noncoded_fx' */ - temp = norm_l(L_en_noncoded_fx); - L_en_noncoded_fx = L_shl(L_en_noncoded_fx, temp); - en_noncoded_fx_exp = add(en_noncoded_fx_exp, temp); + temp = norm_l( L_en_noncoded_fx ); + L_en_noncoded_fx = L_shl( L_en_noncoded_fx, temp ); + en_noncoded_fx_exp = add( en_noncoded_fx_exp, temp ); /* Calc Divisor */ - L_temp = L_mult0(gain1_fx, min_env_fx); + L_temp = L_mult0( gain1_fx, min_env_fx ); /* Normalize Divisor */ - temp2 = norm_l(L_temp); - L_temp = L_shl(L_temp, temp2); - temp2 = sub(add(9, temp2), exp1); /* Q9 for 'min_env_fx', 'exp1' for 'gain1' */ - j = Invert16(round_fx(L_temp), &temp2); - L_temp = Mult_32_16(L_en_noncoded_fx, j); - temp2 = add(temp2, en_noncoded_fx_exp); + temp2 = norm_l( L_temp ); + L_temp = L_shl( L_temp, temp2 ); + temp2 = sub( add( 9, temp2 ), exp1 ); /* Q9 for 'min_env_fx', 'exp1' for 'gain1' */ + j = Invert16( round_fx( L_temp ), &temp2 ); + L_temp = Mult_32_16( L_en_noncoded_fx, j ); + temp2 = add( temp2, en_noncoded_fx_exp ); /* Put in Q16 */ - L_temp = L_shr(L_temp, temp2); - IF( L_msu(L_temp, BWE_HR_NONTRANS_EN_LIMIT1_FX_Q15, 1) < 0) + L_temp = L_shr( L_temp, temp2 ); + IF( L_msu( L_temp, BWE_HR_NONTRANS_EN_LIMIT1_FX_Q15, 1 ) < 0 ) { ind1 = 1; move16(); /* 'en_noncoded = 0.5f * min_env * BWE_HR_NONTRANS_EN_LIMIT1' */ - L_en_noncoded_fx = L_mult0(min_env_fx, BWE_HR_NONTRANS_EN_LIMIT1_FX_Q15/2); + L_en_noncoded_fx = L_mult0( min_env_fx, BWE_HR_NONTRANS_EN_LIMIT1_FX_Q15 / 2 ); } - ELSE IF( L_msu(L_temp, BWE_HR_NONTRANS_EN_LIMIT2_FX_Q14, 2) > 0) + ELSE IF( L_msu( L_temp, BWE_HR_NONTRANS_EN_LIMIT2_FX_Q14, 2 ) > 0 ) { ind1 = 2; move16(); /* 'min_env * BWE_HR_NONTRANS_EN_LIMIT2' */ - L_en_noncoded_fx = L_mult(min_env_fx, BWE_HR_NONTRANS_EN_LIMIT2_FX_Q14); + L_en_noncoded_fx = L_mult( min_env_fx, BWE_HR_NONTRANS_EN_LIMIT2_FX_Q14 ); } - ELSE IF( L_msu(L_temp, BWE_HR_NONTRANS_EN_LIMIT3_FX_Q15, 1) > 0) + ELSE IF( L_msu( L_temp, BWE_HR_NONTRANS_EN_LIMIT3_FX_Q15, 1 ) > 0 ) { ind1 = 3; move16(); - L_en_noncoded_fx = L_mult0(min_env_fx, BWE_HR_NONTRANS_EN_LIMIT3_FX_Q15); + L_en_noncoded_fx = L_mult0( min_env_fx, BWE_HR_NONTRANS_EN_LIMIT3_FX_Q15 ); } ELSE { ind1 = 0; move16(); - L_en_noncoded_fx = L_mult0(min_env_fx, 16384); + L_en_noncoded_fx = L_mult0( min_env_fx, 16384 ); } push_indice_fx( hBstr, IND_HR_HF_GAIN, ind1, NBITS_HF_GAIN_BWE_HR ); - nBits = sub(nBits, NBITS_HF_GAIN_BWE_HR); + nBits = sub( nBits, NBITS_HF_GAIN_BWE_HR ); } ELSE { - L_en_noncoded_fx = L_mult0(min_env_fx, 16384); + L_en_noncoded_fx = L_mult0( min_env_fx, 16384 ); } - en_noncoded_fx_exp = 9+16-1; + en_noncoded_fx_exp = 9 + 16 - 1; move16(); /* 9 for 'en_band_fx', 16 for 'BWE_HR_TRANS_EN_LIMIT...' & -1 becaues of 'L_mult0' */ /*---------------------------------------------------------------------* * AVQ coding (quantize normalized spectrum) *---------------------------------------------------------------------*/ - Nsv = shr(i, WIDTH_BAND_SHIFT); - AVQ_cod_fx(t_audio_tmp_fx/*same exponent as t_audio_fx*/, x_norm_fx, nBits, Nsv, t_audio_fx_exp); - AVQ_encmux_fx(hBstr, st_fx->extl, x_norm_fx, &nBits, Nsv, nq, 0, sub(Nsv, 1)); + Nsv = shr( i, WIDTH_BAND_SHIFT ); + AVQ_cod_fx( t_audio_tmp_fx /*same exponent as t_audio_fx*/, x_norm_fx, nBits, Nsv, t_audio_fx_exp ); + AVQ_encmux_fx( hBstr, st_fx->extl, x_norm_fx, &nBits, Nsv, nq, 0, sub( Nsv, 1 ) ); /*---------------------------------------------------------------------* * second stage coding *---------------------------------------------------------------------*/ test(); - IF( GE_16(nBits, 9 + NBITS_GLOB_GAIN_BWE_HR)&&sum16_fx(nq,Nsv)>0) + IF( GE_16( nBits, 9 + NBITS_GLOB_GAIN_BWE_HR ) && sum16_fx( nq, Nsv ) > 0 ) { /* select spectrum of the second stage coding */ ptr16 = &t_audio_fx[0]; move16(); - FOR( i=0; iextl, x_norm1_fx, &nBits, Nsv2, nq2, 0, sub(Nsv2, 1)); + AVQ_encmux_fx( hBstr, st_fx->extl, x_norm1_fx, &nBits, Nsv2, nq2, 0, sub( Nsv2, 1 ) ); } } /* 'ELSE' of ' IF( is_transient )' */ @@ -805,8 +802,7 @@ void swb_bwe_enc_hr_fx( { i = s_min( nBits, 16 ); push_indice_fx( hBstr, IND_UNUSED, 0, i ); - nBits = sub(nBits, i); + nBits = sub( nBits, i ); } return; } - diff --git a/lib_enc/swb_bwe_enc_lr_fx.c b/lib_enc/swb_bwe_enc_lr_fx.c index 9c5a3bae5..10df60015 100644 --- a/lib_enc/swb_bwe_enc_lr_fx.c +++ b/lib_enc/swb_bwe_enc_lr_fx.c @@ -32,217 +32,215 @@ #include #include "options.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ #include "rom_com.h" #include "enh32.h" - /*--------------------------------------------------------------------------* - * GetSubbandCorrIndex2_har() - * - * Finds the index of best correlation between highband (*inBuf) and lowband (*predBuf) for current subband of length (fLen) - *--------------------------------------------------------------------------*/ -static -Word16 GetSubbandCorrIndex2_har_fx( /* o : best correlation index */ - const Word32 *L_inBuf, /* i : target buffer (i.e., highband signal) : spectra */ - const Word16 fLen, /* i : window length */ - const Word16 *predBuf_fx, /* i : prediction buffer (i.e., lowband) : sspectra */ - const Word16 predBufLen, /* i : sspectra buffer size */ - const Word16 maxLag_fx, /* i : search length */ - const GainItem_fx *G_item_fx, /* i : */ - const Word16 nZero_fx, /* i : number of nonzero components used in */ - Word16 *prev_frame_bstindx_fx /* i : previous frame best Indices */ +/*--------------------------------------------------------------------------* + * GetSubbandCorrIndex2_har() + * + * Finds the index of best correlation between highband (*inBuf) and lowband (*predBuf) for current subband of length (fLen) + *--------------------------------------------------------------------------*/ +static Word16 GetSubbandCorrIndex2_har_fx( /* o : best correlation index */ + const Word32 *L_inBuf, /* i : target buffer (i.e., highband signal) : spectra */ + const Word16 fLen, /* i : window length */ + const Word16 *predBuf_fx, /* i : prediction buffer (i.e., lowband) : sspectra */ + const Word16 predBufLen, /* i : sspectra buffer size */ + const Word16 maxLag_fx, /* i : search length */ + const GainItem_fx *G_item_fx, /* i : */ + const Word16 nZero_fx, /* i : number of nonzero components used in */ + Word16 *prev_frame_bstindx_fx /* i : previous frame best Indices */ ) { - Word16 i, j; - Word16 bestIdx_fx; - Word32 L_lagCorr_sq; - Word32 L_lagEnergy; + Word16 i, j; + Word16 bestIdx_fx; + Word32 L_lagCorr_sq; + Word32 L_lagEnergy; - Word32 L_energy; - Word32 L_corr; - Word32 L_corr_sq; + Word32 L_energy; + Word32 L_corr; + Word32 L_corr_sq; - Word16 corr_sq_hi_fx; - Word32 L_corr_sq_tmp; - Word32 L_lagCorr_sq_tmp; - Word16 corr_sq_fx; - Word16 lagCorr_sq_fx; - Word32 L_energy_tmp; - Word32 L_lagEnergy_tmp; - Word16 energy_fx; - Word16 lagEnergy_fx; + Word16 corr_sq_hi_fx; + Word32 L_corr_sq_tmp; + Word32 L_lagCorr_sq_tmp; + Word16 corr_sq_fx; + Word16 lagCorr_sq_fx; + Word32 L_energy_tmp; + Word32 L_lagEnergy_tmp; + Word16 energy_fx; + Word16 lagEnergy_fx; - Word16 N1_fx, N2_fx; - Word16 exp_safe_e; + Word16 N1_fx, N2_fx; + Word16 exp_safe_e; - Word16 exp_corr; - Word16 exp_energy; + Word16 exp_corr; + Word16 exp_energy; - Word32 L_buf; + Word32 L_buf; - Word16 ibuf_fx[L_FRAME32k]; - Word16 pbuf_fx[L_FRAME32k]; - Word16 *ptr_pbuf; - Word16 exp_shift; + Word16 ibuf_fx[L_FRAME32k]; + Word16 pbuf_fx[L_FRAME32k]; + Word16 *ptr_pbuf; + Word16 exp_shift; - Word16 exp_norm; + Word16 exp_norm; - Word32 L_tmp; + Word32 L_tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; + Flag Overflow = 0; #endif - exp_safe_e = 4; - - L_tmp = L_deposit_l(0); - FOR(i = 0; i < fLen; i++) - { - L_tmp = L_or(L_tmp, L_abs(L_inBuf[i])); - } - exp_norm = norm_l(L_tmp); - exp_shift = sub(exp_norm, exp_safe_e); - - FOR(i = 0; i < fLen; i++) - { - ibuf_fx[i] = extract_h(L_shl(L_inBuf[i], exp_shift)); /* Qi+exp_shift-16 */ - } - - FOR(i = 0; i < predBufLen; i++) - { - pbuf_fx[i] = shr(predBuf_fx[i], exp_safe_e); - move16(); /* Qss-exp_safe_e */ - } - - bestIdx_fx = 0; - move16(); - L_lagCorr_sq = L_deposit_l(0); - L_lagEnergy = 0x7FFFFFFF; - move32(); - - N1_fx = s_max(0x0, sub(*prev_frame_bstindx_fx, shr(maxLag_fx, 1))); - IF(*prev_frame_bstindx_fx < 0) - { - N2_fx = sub(maxLag_fx, 1); - } - ELSE - { - N2_fx = s_min(sub(maxLag_fx, 1), add(*prev_frame_bstindx_fx, shr(maxLag_fx,1))); - } - predBuf_fx += N1_fx; - ptr_pbuf = pbuf_fx + N1_fx; - - - Overflow = 0; - move16(); - - /* find the best lag */ - FOR(i = N1_fx; i <= N2_fx; i++) - { - L_corr = L_deposit_l(0); - - /* get the energy, remove the old and update with the new energy index */ - - L_energy = L_deposit_l(0); - FOR(j = 0; j < fLen; j++) - { - /*energy += *predBuf * *predBuf; */ -#ifdef BASOP_NOGLOB /* Critical Overflow , as well as those below*/ - L_energy = L_mac_o(L_energy, *ptr_pbuf, *ptr_pbuf, &Overflow); /* Q*2-1; */ + exp_safe_e = 4; + + L_tmp = L_deposit_l( 0 ); + FOR( i = 0; i < fLen; i++ ) + { + L_tmp = L_or( L_tmp, L_abs( L_inBuf[i] ) ); + } + exp_norm = norm_l( L_tmp ); + exp_shift = sub( exp_norm, exp_safe_e ); + + FOR( i = 0; i < fLen; i++ ) + { + ibuf_fx[i] = extract_h( L_shl( L_inBuf[i], exp_shift ) ); /* Qi+exp_shift-16 */ + } + + FOR( i = 0; i < predBufLen; i++ ) + { + pbuf_fx[i] = shr( predBuf_fx[i], exp_safe_e ); + move16(); /* Qss-exp_safe_e */ + } + + bestIdx_fx = 0; + move16(); + L_lagCorr_sq = L_deposit_l( 0 ); + L_lagEnergy = 0x7FFFFFFF; + move32(); + + N1_fx = s_max( 0x0, sub( *prev_frame_bstindx_fx, shr( maxLag_fx, 1 ) ) ); + IF( *prev_frame_bstindx_fx < 0 ) + { + N2_fx = sub( maxLag_fx, 1 ); + } + ELSE + { + N2_fx = s_min( sub( maxLag_fx, 1 ), add( *prev_frame_bstindx_fx, shr( maxLag_fx, 1 ) ) ); + } + predBuf_fx += N1_fx; + ptr_pbuf = pbuf_fx + N1_fx; + + + Overflow = 0; + move16(); + + /* find the best lag */ + FOR( i = N1_fx; i <= N2_fx; i++ ) + { + L_corr = L_deposit_l( 0 ); + + /* get the energy, remove the old and update with the new energy index */ + + L_energy = L_deposit_l( 0 ); + FOR( j = 0; j < fLen; j++ ) + { + /*energy += *predBuf * *predBuf; */ +#ifdef BASOP_NOGLOB /* Critical Overflow , as well as those below*/ + L_energy = L_mac_o( L_energy, *ptr_pbuf, *ptr_pbuf, &Overflow ); /* Q*2-1; */ #else - L_energy = L_mac(L_energy, *ptr_pbuf, *ptr_pbuf); /* Q*2-1; */ + L_energy = L_mac( L_energy, *ptr_pbuf, *ptr_pbuf ); /* Q*2-1; */ #endif - ptr_pbuf++; - } - - ptr_pbuf -= fLen; - - /* get cross-correlation */ - IF(L_energy != 0x0L) - { - L_corr = L_deposit_l(0); - FOR(j = 0; j < nZero_fx; j++) - { - /*corr += inBuf[G_item[j].gainIndex]* predBuf[G_item[j].gainIndex]; */ -#ifdef BASOP_NOGLOB /* Critical Overflow */ - L_corr = L_mac_o(L_corr, ibuf_fx[G_item_fx[j].gainIndex_fx], ptr_pbuf[G_item_fx[j].gainIndex_fx], &Overflow); /* Q*2-1 */ + ptr_pbuf++; + } + + ptr_pbuf -= fLen; + + /* get cross-correlation */ + IF( L_energy != 0x0L ) + { + L_corr = L_deposit_l( 0 ); + FOR( j = 0; j < nZero_fx; j++ ) + { + /*corr += inBuf[G_item[j].gainIndex]* predBuf[G_item[j].gainIndex]; */ +#ifdef BASOP_NOGLOB /* Critical Overflow */ + L_corr = L_mac_o( L_corr, ibuf_fx[G_item_fx[j].gainIndex_fx], ptr_pbuf[G_item_fx[j].gainIndex_fx], &Overflow ); /* Q*2-1 */ #else - L_corr = L_mac(L_corr, ibuf_fx[G_item_fx[j].gainIndex_fx], ptr_pbuf[G_item_fx[j].gainIndex_fx]); /* Q*2-1 */ + L_corr = L_mac( L_corr, ibuf_fx[G_item_fx[j].gainIndex_fx], ptr_pbuf[G_item_fx[j].gainIndex_fx] ); /* Q*2-1 */ #endif - } + } - /*corr_sq = corr*corr; */ - exp_norm = norm_l(L_corr); - exp_norm = sub(exp_norm, 1); /* added for Overflow 0x8000 * 0x8000 -> Overflow */ - L_corr_sq = L_shl(L_corr, exp_norm); - corr_sq_hi_fx = extract_h(L_corr_sq); + /*corr_sq = corr*corr; */ + exp_norm = norm_l( L_corr ); + exp_norm = sub( exp_norm, 1 ); /* added for Overflow 0x8000 * 0x8000 -> Overflow */ + L_corr_sq = L_shl( L_corr, exp_norm ); + corr_sq_hi_fx = extract_h( L_corr_sq ); -#ifdef BASOP_NOGLOB /* Critical Overflow */ - L_corr_sq = L_mult_o(corr_sq_hi_fx, corr_sq_hi_fx, &Overflow); /* (((Qhi:Qsh+exp_norm_hi-16)+Qss+1)+exp_norm-16)*2+1 */ - L_corr_sq = L_shr_o(L_corr_sq, s_min(shl(exp_norm, 1), 31), &Overflow); /* (QCorr-16)*2+1 */ +#ifdef BASOP_NOGLOB /* Critical Overflow */ + L_corr_sq = L_mult_o( corr_sq_hi_fx, corr_sq_hi_fx, &Overflow ); /* (((Qhi:Qsh+exp_norm_hi-16)+Qss+1)+exp_norm-16)*2+1 */ + L_corr_sq = L_shr_o( L_corr_sq, s_min( shl( exp_norm, 1 ), 31 ), &Overflow ); /* (QCorr-16)*2+1 */ #else - L_corr_sq = L_mult(corr_sq_hi_fx, corr_sq_hi_fx); /* (((Qhi:Qsh+exp_norm_hi-16)+Qss+1)+exp_norm-16)*2+1 */ - L_corr_sq = L_shr(L_corr_sq, s_min(shl(exp_norm, 1), 31)); /* (QCorr-16)*2+1 */ + L_corr_sq = L_mult( corr_sq_hi_fx, corr_sq_hi_fx ); /* (((Qhi:Qsh+exp_norm_hi-16)+Qss+1)+exp_norm-16)*2+1 */ + L_corr_sq = L_shr( L_corr_sq, s_min( shl( exp_norm, 1 ), 31 ) ); /* (QCorr-16)*2+1 */ #endif - IF(Overflow != 0) - { - L_corr_sq = 0x0L; - move16(); - Overflow = 0; - move16(); - } - - /* normalize for L_lagCorr_sq and L_corr_sq */ - L_buf = L_or(L_lagCorr_sq, L_corr_sq); - exp_corr = norm_l(L_buf); - L_corr_sq_tmp = L_shl(L_corr_sq, exp_corr); - L_lagCorr_sq_tmp = L_shl(L_lagCorr_sq, exp_corr); - corr_sq_fx = extract_h(L_corr_sq_tmp); - lagCorr_sq_fx = extract_h(L_lagCorr_sq_tmp); - - /* normalize for L_lagEnergy and L_energy */ - L_buf = L_or(L_lagEnergy, L_energy); - exp_energy = norm_l(L_buf); - L_energy_tmp = L_shl(L_energy, exp_energy); - L_lagEnergy_tmp = L_shl(L_lagEnergy, exp_energy); - energy_fx = extract_h(L_energy_tmp); - lagEnergy_fx = extract_h(L_lagEnergy_tmp); - - /*if( (double)lagCorr_sq*(double)energy < (double)corr_sq*(double)lagEnergy ) */ - IF(L_msu(L_mult(lagCorr_sq_fx, energy_fx), corr_sq_fx, lagEnergy_fx) < 0) - { - bestIdx_fx = i; - move16(); - L_lagCorr_sq = L_add(L_corr_sq, 0); - L_lagEnergy = L_add(L_energy, 0); - } - - } - predBuf_fx++; - ptr_pbuf++; - } - - test(); - IF(L_lagCorr_sq == 0x0 && *prev_frame_bstindx_fx < 0) - { - bestIdx_fx = 0x0; - move16(); - } - ELSE - { - if (L_lagCorr_sq == 0x0) - { - bestIdx_fx = *prev_frame_bstindx_fx; - move16(); - } - } - - *prev_frame_bstindx_fx = bestIdx_fx; - move16(); - - return bestIdx_fx; + IF( Overflow != 0 ) + { + L_corr_sq = 0x0L; + move16(); + Overflow = 0; + move16(); + } + + /* normalize for L_lagCorr_sq and L_corr_sq */ + L_buf = L_or( L_lagCorr_sq, L_corr_sq ); + exp_corr = norm_l( L_buf ); + L_corr_sq_tmp = L_shl( L_corr_sq, exp_corr ); + L_lagCorr_sq_tmp = L_shl( L_lagCorr_sq, exp_corr ); + corr_sq_fx = extract_h( L_corr_sq_tmp ); + lagCorr_sq_fx = extract_h( L_lagCorr_sq_tmp ); + + /* normalize for L_lagEnergy and L_energy */ + L_buf = L_or( L_lagEnergy, L_energy ); + exp_energy = norm_l( L_buf ); + L_energy_tmp = L_shl( L_energy, exp_energy ); + L_lagEnergy_tmp = L_shl( L_lagEnergy, exp_energy ); + energy_fx = extract_h( L_energy_tmp ); + lagEnergy_fx = extract_h( L_lagEnergy_tmp ); + + /*if( (double)lagCorr_sq*(double)energy < (double)corr_sq*(double)lagEnergy ) */ + IF( L_msu( L_mult( lagCorr_sq_fx, energy_fx ), corr_sq_fx, lagEnergy_fx ) < 0 ) + { + bestIdx_fx = i; + move16(); + L_lagCorr_sq = L_add( L_corr_sq, 0 ); + L_lagEnergy = L_add( L_energy, 0 ); + } + } + predBuf_fx++; + ptr_pbuf++; + } + + test(); + IF( L_lagCorr_sq == 0x0 && *prev_frame_bstindx_fx < 0 ) + { + bestIdx_fx = 0x0; + move16(); + } + ELSE + { + if ( L_lagCorr_sq == 0x0 ) + { + bestIdx_fx = *prev_frame_bstindx_fx; + move16(); + } + } + + *prev_frame_bstindx_fx = bestIdx_fx; + move16(); + + return bestIdx_fx; } /*--------------------------------------------------------------------------* @@ -252,86 +250,85 @@ Word16 GetSubbandCorrIndex2_har_fx( /* o : best correlation index *--------------------------------------------------------------------------*/ static void getswbindices_har_fx( - const Word32 *L_yos, /* i : original input spectrum */ - Word16 exp_refBuf, /* i : */ - Word16 *y2_fx, /* i : decoded spectrum */ - const Word16 nBands_search_fx, /* i : number of bands */ - Word16 *lagIndices_fx, /* o : pulse index */ - Word16 *prev_frame_bstindx_fx, /* i/o: prev frame index */ - const Word16 swb_lowband_fx, /* i : length of the LF spectrum */ - const Word16 *subband_offsets_fx, /* i : */ - const Word16 *sbWidth_fx, /* i : */ - const Word16 *subband_search_offset_fx /* i : */ + const Word32 *L_yos, /* i : original input spectrum */ + Word16 exp_refBuf, /* i : */ + Word16 *y2_fx, /* i : decoded spectrum */ + const Word16 nBands_search_fx, /* i : number of bands */ + Word16 *lagIndices_fx, /* o : pulse index */ + Word16 *prev_frame_bstindx_fx, /* i/o: prev frame index */ + const Word16 swb_lowband_fx, /* i : length of the LF spectrum */ + const Word16 *subband_offsets_fx, /* i : */ + const Word16 *sbWidth_fx, /* i : */ + const Word16 *subband_search_offset_fx /* i : */ ) { - Word16 i, j, k, sb, tmp; - Word16 *ptr_predBuf; - GainItem_fx Nbiggest_fx[(NB_SWB_SUBBANDS_HAR_SEARCH_SB)*N_NBIGGEST_PULSEARCH]; - Word16 n_nbiggestsearch_fx[NB_SWB_SUBBANDS_HAR]; - - Word16 search_offset_fx[NB_SWB_SUBBANDS_HAR_SEARCH_SB]; - Word16 nlags_fx[NB_SWB_SUBBANDS_HAR_SEARCH_SB]; - - Word16 low_freqsgnl_fx[L_FRAME32k]; /* Qy2 (sspectra) */ - - ptr_predBuf = y2_fx; - - /* Get the number of HF groups for performing Similarity search */ - FOR(sb = 0; sb < nBands_search_fx; sb++) - { - /*nlags[sb] = (short)pow(2, bits_lagIndices_mode0_Har[sb]); */ - nlags_fx[sb] = shl(1, bits_lagIndices_mode0_Har[sb]); - } - - j = 0; - move16(); - FOR(sb = 0; sb < nBands_search_fx; sb++) - { - /* Find NBiggest samples in HF Groups */ - FindNBiggest2_simple_fx_har(L_yos + add(swb_lowband_fx, subband_offsets_fx[sb]), exp_refBuf, Nbiggest_fx + j, - sbWidth_fx[sb], &n_nbiggestsearch_fx[sb], N_NBIGGEST_PULSEARCH); - - search_offset_fx[sb] = subband_search_offset_fx[sb]; - j = add(j, N_NBIGGEST_PULSEARCH); - } - - /* Similarity Search for the HF spectrum */ - FOR(sb = 0; sb < nBands_search_fx; sb++) - { - IF(sb == 0) - { - /* copy SSmoothed LF Spectrum */ - ptr_predBuf = y2_fx + sub(search_offset_fx[sb], shr(nlags_fx[sb], 1)); - tmp = add(sbWidth_fx[sb], nlags_fx[sb]); - FOR(i = 0; i < tmp; i++) - { - low_freqsgnl_fx[i] = *ptr_predBuf++; - move16(); - } - } - ELSE - { - /* copy SSmoothed LF Spectrum */ - k = 0; - move16(); - tmp = sub(search_offset_fx[sb], add(sbWidth_fx[sb], shr(nlags_fx[sb], 1))); - FOR(j = add(search_offset_fx[sb], shr(nlags_fx[sb], 1)); j > tmp; j--) - { - low_freqsgnl_fx[k] = y2_fx[j]; - k = add(k, 1); - } - } - /* correlation b/w HF spectrum Group1 of length sbLen and decoded LF spectrum */ - lagIndices_fx[sb] = (Word16)GetSubbandCorrIndex2_har_fx(L_yos + add(swb_lowband_fx, subband_offsets_fx[sb]), - sbWidth_fx[sb], - low_freqsgnl_fx, - add(sbWidth_fx[sb], nlags_fx[sb]), - nlags_fx[sb], Nbiggest_fx + (sb*N_NBIGGEST_PULSEARCH), - n_nbiggestsearch_fx[sb], &prev_frame_bstindx_fx[sb] - ); - } - - return; + Word16 i, j, k, sb, tmp; + Word16 *ptr_predBuf; + GainItem_fx Nbiggest_fx[(NB_SWB_SUBBANDS_HAR_SEARCH_SB) *N_NBIGGEST_PULSEARCH]; + Word16 n_nbiggestsearch_fx[NB_SWB_SUBBANDS_HAR]; + + Word16 search_offset_fx[NB_SWB_SUBBANDS_HAR_SEARCH_SB]; + Word16 nlags_fx[NB_SWB_SUBBANDS_HAR_SEARCH_SB]; + + Word16 low_freqsgnl_fx[L_FRAME32k]; /* Qy2 (sspectra) */ + + ptr_predBuf = y2_fx; + + /* Get the number of HF groups for performing Similarity search */ + FOR( sb = 0; sb < nBands_search_fx; sb++ ) + { + /*nlags[sb] = (short)pow(2, bits_lagIndices_mode0_Har[sb]); */ + nlags_fx[sb] = shl( 1, bits_lagIndices_mode0_Har[sb] ); + } + + j = 0; + move16(); + FOR( sb = 0; sb < nBands_search_fx; sb++ ) + { + /* Find NBiggest samples in HF Groups */ + FindNBiggest2_simple_fx_har( L_yos + add( swb_lowband_fx, subband_offsets_fx[sb] ), exp_refBuf, Nbiggest_fx + j, + sbWidth_fx[sb], &n_nbiggestsearch_fx[sb], N_NBIGGEST_PULSEARCH ); + + search_offset_fx[sb] = subband_search_offset_fx[sb]; + j = add( j, N_NBIGGEST_PULSEARCH ); + } + + /* Similarity Search for the HF spectrum */ + FOR( sb = 0; sb < nBands_search_fx; sb++ ) + { + IF( sb == 0 ) + { + /* copy SSmoothed LF Spectrum */ + ptr_predBuf = y2_fx + sub( search_offset_fx[sb], shr( nlags_fx[sb], 1 ) ); + tmp = add( sbWidth_fx[sb], nlags_fx[sb] ); + FOR( i = 0; i < tmp; i++ ) + { + low_freqsgnl_fx[i] = *ptr_predBuf++; + move16(); + } + } + ELSE + { + /* copy SSmoothed LF Spectrum */ + k = 0; + move16(); + tmp = sub( search_offset_fx[sb], add( sbWidth_fx[sb], shr( nlags_fx[sb], 1 ) ) ); + FOR( j = add( search_offset_fx[sb], shr( nlags_fx[sb], 1 ) ); j > tmp; j-- ) + { + low_freqsgnl_fx[k] = y2_fx[j]; + k = add( k, 1 ); + } + } + /* correlation b/w HF spectrum Group1 of length sbLen and decoded LF spectrum */ + lagIndices_fx[sb] = (Word16) GetSubbandCorrIndex2_har_fx( L_yos + add( swb_lowband_fx, subband_offsets_fx[sb] ), + sbWidth_fx[sb], + low_freqsgnl_fx, + add( sbWidth_fx[sb], nlags_fx[sb] ), + nlags_fx[sb], Nbiggest_fx + ( sb * N_NBIGGEST_PULSEARCH ), + n_nbiggestsearch_fx[sb], &prev_frame_bstindx_fx[sb] ); + } + + return; } /*--------------------------------------------------------------------------* * GetSubbandCorrIndex2_pulsestep_fx() @@ -339,317 +336,316 @@ static void getswbindices_har_fx( *--------------------------------------------------------------------------*/ static Word16 GetSubbandCorrIndex2_pulsestep_fx( - const Word32 *L_inBuf, /* i: original input vector (highband) */ - const Word16 *predBuf_fx, /* i: spectrum smoothing vector */ - const Word16 *predBufMa_fx, /* i: moving averaged spectrum smoothing vector Q=Qss */ - const Word16 fLen, /* i: subband length of highband */ - const Word16 maxLag, /* i: number of search pulse number */ - const GainItem_fx *gi_fx, /* i: lag gain structure */ - const Word16 nZero, /* i: */ - const Word16 ssearch_buflim, /* i: length of search buffer */ - const Word16 *predBuf_ni_fx /* i: spectrum including noise smoothing vector */ + const Word32 *L_inBuf, /* i: original input vector (highband) */ + const Word16 *predBuf_fx, /* i: spectrum smoothing vector */ + const Word16 *predBufMa_fx, /* i: moving averaged spectrum smoothing vector Q=Qss */ + const Word16 fLen, /* i: subband length of highband */ + const Word16 maxLag, /* i: number of search pulse number */ + const GainItem_fx *gi_fx, /* i: lag gain structure */ + const Word16 nZero, /* i: */ + const Word16 ssearch_buflim, /* i: length of search buffer */ + const Word16 *predBuf_ni_fx /* i: spectrum including noise smoothing vector */ ) { - Word16 i, j; - Word16 absPos_fx; - Word16 bestIdx_fx; - Word32 L_lagCorr_sq; - Word32 L_lagEnergy; - - const Word16 *ptr_predBuf; - const Word16 *ptr_predBuf_ni; - - Word32 L_energy; - Word32 L_corr; - Word16 corr_fx; - - Word32 L_corr_sq; - - - Word16 hiBuf_fx[L_FRAME32k]; - Word16 exp_norm_hi; - - Word16 exp_norm; - Word32 L_corr_sq_tmp; - Word32 L_lagCorr_sq_tmp; - Word16 corr_sq_fx; - Word16 lagCorr_sq_fx; - Word32 L_energy_tmp; - Word32 L_lagEnergy_tmp; - Word16 energy_fx; - Word16 lagEnergy_fx; - - Word16 ib_flag_fx; - - Word32 L_buf; - Word32 L_buf2; - Word32 L_temp; - - Word16 ssBuf_fx[L_FRAME32k]; - Word16 ssBuf_ni_fx[L_FRAME32k]; - Word16 *ptr_ssBuf_ni_fx; - Word16 exp_norm_ss; - - set16_fx(hiBuf_fx, 0x0, L_FRAME32k); - set16_fx(ssBuf_fx, 0x0, L_FRAME32k); - - ib_flag_fx = 0; - move16(); - - absPos_fx = 0; - move16(); - bestIdx_fx = -1; - move16(); - L_lagCorr_sq = L_deposit_l(0); - L_lagEnergy = 0x7FFFFFFFL; - move32(); - - ptr_predBuf = predBuf_fx; - ptr_predBuf_ni = predBuf_ni_fx; - - /* This part must be computed on parent function. */ - exp_norm_ss = 2; - move16(); - - j = add(ssearch_buflim, fLen); - FOR(i = 0; i < j; i++) - { - ssBuf_fx[i] = shr(predBuf_fx[i], exp_norm_ss); - move16(); /* Qss+exp_norm_ss */ - ssBuf_ni_fx[i] = shr(predBuf_ni_fx[i], exp_norm_ss); - move16(); /* Qss+exp_norm_ss */ - } - - L_temp = L_deposit_l(0); - FOR(i = 0; i < fLen; i++) - { - L_temp = L_or(L_temp, L_abs(L_inBuf[i])); - } - exp_norm_hi = norm_l(L_temp); - exp_norm_hi = sub(exp_norm_hi, 3); /* max 109 < 2^7 , sspectrum is sparse, it is't need 4 */ - - FOR(i = 0; i < fLen; i++) - { - hiBuf_fx[i] = extract_h(L_shl(L_inBuf[i], exp_norm_hi)); - move16(); /* Qsh+exp_norm_hi-16 */ - } - - /* Get the initial energy for zero lag */ - WHILE(*ptr_predBuf == 0 && LT_16(absPos_fx, ssearch_buflim)) - { - ptr_predBuf++; - ptr_predBuf_ni++; - absPos_fx = add(absPos_fx, 1); - } - - IF(EQ_16(absPos_fx, ssearch_buflim)) - { - ptr_predBuf--; - ptr_predBuf_ni--; - absPos_fx = sub(absPos_fx, 1); - } - - ptr_ssBuf_ni_fx = ssBuf_ni_fx + absPos_fx; - L_energy = L_deposit_l(0); - FOR(i = 0; i < fLen; i++) - { - L_energy = L_mac(L_energy, *ptr_ssBuf_ni_fx, *ptr_ssBuf_ni_fx); /* (Qss-exp_norm_ss)*2+1 */ - ptr_ssBuf_ni_fx++; - ptr_predBuf_ni++; - } - - ptr_ssBuf_ni_fx -= fLen; - ptr_predBuf_ni -= fLen; - - L_lagEnergy = L_add(L_energy, 0); - - /* Find the best lag */ - FOR(i = 0; i < maxLag; i++) - { - L_corr = L_deposit_l(0); - - /* Get the energy, remove the old and update with the new energy index */ - L_energy = L_deposit_l(0); - FOR(j = 0; j < fLen; j++) - { - L_energy = L_mac(L_energy, *ptr_ssBuf_ni_fx, *ptr_ssBuf_ni_fx); - ptr_ssBuf_ni_fx++; - ptr_predBuf_ni++; - } - ptr_ssBuf_ni_fx -= fLen; - ptr_predBuf_ni -= fLen; - - /* Get cross-correlation */ - IF(L_energy != 0x0L) - { - L_corr = L_deposit_l(0); - FOR(j = 0; j < nZero; j++) - { - /*corr += inBuf[G_item[j].gainIndex]* predBufMa[G_item[j].gainIndex]; */ - L_corr = L_mac(L_corr, hiBuf_fx[gi_fx[j].gainIndex_fx], predBufMa_fx[gi_fx[j].gainIndex_fx]); /* Qsh+Qss+1 */ - } - - /*corr_sq = corr*corr; */ - exp_norm = norm_l(L_corr); - exp_norm = sub(exp_norm, 1); /* added for Overflow 0x8000 * 0x8000 -> Overflow */ - L_corr_sq = L_shl(L_corr, exp_norm); - corr_fx = extract_h(L_corr_sq); - L_corr_sq = L_mult(corr_fx, corr_fx); /* (((Qhi:Qsh+exp_norm_hi-16)+Qss+1)+exp_norm-16)*2+1 */ - L_corr_sq = L_shr(L_corr_sq, s_min(shl(exp_norm, 1), 31)); /* (QCorr-16)*2+1 */ - - /*if( (lagCorr_sq == 0.0f && corr_sq == 0.0f) || (double)lagCorr_sq*(double)energy < (double)corr_sq*(double)lagEnergy ) */ - /*{ */ - /* bestIdx = i; */ - /* bestAbsPos = absPos; */ - /* lagCorr_sq = corr_sq; */ - /* lagCorr = corr; */ - /* lagEnergy = energy; */ - /*} */ - /* normalize for L_lagCorr_sq and L_corr_sq */ - L_buf = L_or(L_lagCorr_sq, L_corr_sq); - exp_norm = norm_l(L_buf); /* overflow allowed */ - L_corr_sq_tmp = L_shl(L_corr_sq, exp_norm); - L_lagCorr_sq_tmp = L_shl(L_lagCorr_sq, exp_norm); - corr_sq_fx = extract_h(L_corr_sq_tmp); - lagCorr_sq_fx = extract_h(L_lagCorr_sq_tmp); - - /* normalize for L_lagEnergy and L_energy */ - L_buf = L_or(L_lagEnergy, L_energy); - exp_norm = norm_l(L_buf); /* overflow allowed */ - L_energy_tmp = L_shl(L_energy, exp_norm); - L_lagEnergy_tmp = L_shl(L_lagEnergy, exp_norm); - energy_fx = extract_h(L_energy_tmp); - lagEnergy_fx = extract_h(L_lagEnergy_tmp); - - L_buf = L_or(L_lagCorr_sq, L_corr_sq); - L_buf2 = L_msu(L_mult(lagCorr_sq_fx, energy_fx), corr_sq_fx, lagEnergy_fx); - test(); - IF(L_buf == 0 || L_buf2 < 0) - { - bestIdx_fx = i; - move16(); - L_lagCorr_sq = L_add(L_corr_sq, 0); - L_lagEnergy = L_add(L_energy, 0); - } - } - ptr_predBuf++; - ptr_ssBuf_ni_fx++; - ptr_predBuf_ni++; - absPos_fx++; - - WHILE(*ptr_predBuf == 0 && LT_16(absPos_fx, ssearch_buflim)) - { - ptr_predBuf++; - ptr_ssBuf_ni_fx++; - ptr_predBuf_ni++; - absPos_fx = add(absPos_fx, 1); - } - - IF(GE_16(absPos_fx, ssearch_buflim)) - { - if (EQ_16(bestIdx_fx, -1)) - { - ib_flag_fx = 1; - move16(); - } - - BREAK; - } - } - - IF(EQ_16(ib_flag_fx, 1)) - { - bestIdx_fx = 0; - move16(); - } - - return bestIdx_fx; + Word16 i, j; + Word16 absPos_fx; + Word16 bestIdx_fx; + Word32 L_lagCorr_sq; + Word32 L_lagEnergy; + + const Word16 *ptr_predBuf; + const Word16 *ptr_predBuf_ni; + + Word32 L_energy; + Word32 L_corr; + Word16 corr_fx; + + Word32 L_corr_sq; + + + Word16 hiBuf_fx[L_FRAME32k]; + Word16 exp_norm_hi; + + Word16 exp_norm; + Word32 L_corr_sq_tmp; + Word32 L_lagCorr_sq_tmp; + Word16 corr_sq_fx; + Word16 lagCorr_sq_fx; + Word32 L_energy_tmp; + Word32 L_lagEnergy_tmp; + Word16 energy_fx; + Word16 lagEnergy_fx; + + Word16 ib_flag_fx; + + Word32 L_buf; + Word32 L_buf2; + Word32 L_temp; + + Word16 ssBuf_fx[L_FRAME32k]; + Word16 ssBuf_ni_fx[L_FRAME32k]; + Word16 *ptr_ssBuf_ni_fx; + Word16 exp_norm_ss; + + set16_fx( hiBuf_fx, 0x0, L_FRAME32k ); + set16_fx( ssBuf_fx, 0x0, L_FRAME32k ); + + ib_flag_fx = 0; + move16(); + + absPos_fx = 0; + move16(); + bestIdx_fx = -1; + move16(); + L_lagCorr_sq = L_deposit_l( 0 ); + L_lagEnergy = 0x7FFFFFFFL; + move32(); + + ptr_predBuf = predBuf_fx; + ptr_predBuf_ni = predBuf_ni_fx; + + /* This part must be computed on parent function. */ + exp_norm_ss = 2; + move16(); + + j = add( ssearch_buflim, fLen ); + FOR( i = 0; i < j; i++ ) + { + ssBuf_fx[i] = shr( predBuf_fx[i], exp_norm_ss ); + move16(); /* Qss+exp_norm_ss */ + ssBuf_ni_fx[i] = shr( predBuf_ni_fx[i], exp_norm_ss ); + move16(); /* Qss+exp_norm_ss */ + } + + L_temp = L_deposit_l( 0 ); + FOR( i = 0; i < fLen; i++ ) + { + L_temp = L_or( L_temp, L_abs( L_inBuf[i] ) ); + } + exp_norm_hi = norm_l( L_temp ); + exp_norm_hi = sub( exp_norm_hi, 3 ); /* max 109 < 2^7 , sspectrum is sparse, it is't need 4 */ + + FOR( i = 0; i < fLen; i++ ) + { + hiBuf_fx[i] = extract_h( L_shl( L_inBuf[i], exp_norm_hi ) ); + move16(); /* Qsh+exp_norm_hi-16 */ + } + + /* Get the initial energy for zero lag */ + WHILE( *ptr_predBuf == 0 && LT_16( absPos_fx, ssearch_buflim ) ) + { + ptr_predBuf++; + ptr_predBuf_ni++; + absPos_fx = add( absPos_fx, 1 ); + } + + IF( EQ_16( absPos_fx, ssearch_buflim ) ) + { + ptr_predBuf--; + ptr_predBuf_ni--; + absPos_fx = sub( absPos_fx, 1 ); + } + + ptr_ssBuf_ni_fx = ssBuf_ni_fx + absPos_fx; + L_energy = L_deposit_l( 0 ); + FOR( i = 0; i < fLen; i++ ) + { + L_energy = L_mac( L_energy, *ptr_ssBuf_ni_fx, *ptr_ssBuf_ni_fx ); /* (Qss-exp_norm_ss)*2+1 */ + ptr_ssBuf_ni_fx++; + ptr_predBuf_ni++; + } + + ptr_ssBuf_ni_fx -= fLen; + ptr_predBuf_ni -= fLen; + + L_lagEnergy = L_add( L_energy, 0 ); + + /* Find the best lag */ + FOR( i = 0; i < maxLag; i++ ) + { + L_corr = L_deposit_l( 0 ); + + /* Get the energy, remove the old and update with the new energy index */ + L_energy = L_deposit_l( 0 ); + FOR( j = 0; j < fLen; j++ ) + { + L_energy = L_mac( L_energy, *ptr_ssBuf_ni_fx, *ptr_ssBuf_ni_fx ); + ptr_ssBuf_ni_fx++; + ptr_predBuf_ni++; + } + ptr_ssBuf_ni_fx -= fLen; + ptr_predBuf_ni -= fLen; + + /* Get cross-correlation */ + IF( L_energy != 0x0L ) + { + L_corr = L_deposit_l( 0 ); + FOR( j = 0; j < nZero; j++ ) + { + /*corr += inBuf[G_item[j].gainIndex]* predBufMa[G_item[j].gainIndex]; */ + L_corr = L_mac( L_corr, hiBuf_fx[gi_fx[j].gainIndex_fx], predBufMa_fx[gi_fx[j].gainIndex_fx] ); /* Qsh+Qss+1 */ + } + + /*corr_sq = corr*corr; */ + exp_norm = norm_l( L_corr ); + exp_norm = sub( exp_norm, 1 ); /* added for Overflow 0x8000 * 0x8000 -> Overflow */ + L_corr_sq = L_shl( L_corr, exp_norm ); + corr_fx = extract_h( L_corr_sq ); + L_corr_sq = L_mult( corr_fx, corr_fx ); /* (((Qhi:Qsh+exp_norm_hi-16)+Qss+1)+exp_norm-16)*2+1 */ + L_corr_sq = L_shr( L_corr_sq, s_min( shl( exp_norm, 1 ), 31 ) ); /* (QCorr-16)*2+1 */ + + /*if( (lagCorr_sq == 0.0f && corr_sq == 0.0f) || (double)lagCorr_sq*(double)energy < (double)corr_sq*(double)lagEnergy ) */ + /*{ */ + /* bestIdx = i; */ + /* bestAbsPos = absPos; */ + /* lagCorr_sq = corr_sq; */ + /* lagCorr = corr; */ + /* lagEnergy = energy; */ + /*} */ + /* normalize for L_lagCorr_sq and L_corr_sq */ + L_buf = L_or( L_lagCorr_sq, L_corr_sq ); + exp_norm = norm_l( L_buf ); /* overflow allowed */ + L_corr_sq_tmp = L_shl( L_corr_sq, exp_norm ); + L_lagCorr_sq_tmp = L_shl( L_lagCorr_sq, exp_norm ); + corr_sq_fx = extract_h( L_corr_sq_tmp ); + lagCorr_sq_fx = extract_h( L_lagCorr_sq_tmp ); + + /* normalize for L_lagEnergy and L_energy */ + L_buf = L_or( L_lagEnergy, L_energy ); + exp_norm = norm_l( L_buf ); /* overflow allowed */ + L_energy_tmp = L_shl( L_energy, exp_norm ); + L_lagEnergy_tmp = L_shl( L_lagEnergy, exp_norm ); + energy_fx = extract_h( L_energy_tmp ); + lagEnergy_fx = extract_h( L_lagEnergy_tmp ); + + L_buf = L_or( L_lagCorr_sq, L_corr_sq ); + L_buf2 = L_msu( L_mult( lagCorr_sq_fx, energy_fx ), corr_sq_fx, lagEnergy_fx ); + test(); + IF( L_buf == 0 || L_buf2 < 0 ) + { + bestIdx_fx = i; + move16(); + L_lagCorr_sq = L_add( L_corr_sq, 0 ); + L_lagEnergy = L_add( L_energy, 0 ); + } + } + ptr_predBuf++; + ptr_ssBuf_ni_fx++; + ptr_predBuf_ni++; + absPos_fx++; + + WHILE( *ptr_predBuf == 0 && LT_16( absPos_fx, ssearch_buflim ) ) + { + ptr_predBuf++; + ptr_ssBuf_ni_fx++; + ptr_predBuf_ni++; + absPos_fx = add( absPos_fx, 1 ); + } + + IF( GE_16( absPos_fx, ssearch_buflim ) ) + { + if ( EQ_16( bestIdx_fx, -1 ) ) + { + ib_flag_fx = 1; + move16(); + } + + BREAK; + } + } + + IF( EQ_16( ib_flag_fx, 1 ) ) + { + bestIdx_fx = 0; + move16(); + } + + return bestIdx_fx; } /*--------------------------------------------------------------------------* * GetSWBIndices_fx() * *--------------------------------------------------------------------------*/ static void GetSWBIndices_fx( - const Word16 *predBuf_fx, /* i : low-frequency band */ - /*const Word16 Qss,*/ /* i : Q value of predBuf_fx */ - const Word32 *L_targetBuf, /* i : SWB MDCT coeff. */ - const Word16 Qsh, /* i : Q value of L_targetBuf */ - const Word16 nBands_search, /* i : number of search subbands */ - const Word16 *sbWidth, /* i : subband lengths */ - Word16 *lagIndices, /* o : selected lags for subband coding */ - const Word16 predBufLen, /* i : low-frequency band length */ - GainItem_fx *gi_fx, /* o : most representative region */ - const Word16 *subband_offsets, /* o : N biggest components */ - Word16 *predBuf_ni_fx /* i : low-frequency band filled noise */ + const Word16 *predBuf_fx, /* i : low-frequency band */ + /*const Word16 Qss,*/ /* i : Q value of predBuf_fx */ + const Word32 *L_targetBuf, /* i : SWB MDCT coeff. */ + const Word16 Qsh, /* i : Q value of L_targetBuf */ + const Word16 nBands_search, /* i : number of search subbands */ + const Word16 *sbWidth, /* i : subband lengths */ + Word16 *lagIndices, /* o : selected lags for subband coding */ + const Word16 predBufLen, /* i : low-frequency band length */ + GainItem_fx *gi_fx, /* o : most representative region */ + const Word16 *subband_offsets, /* o : N biggest components */ + Word16 *predBuf_ni_fx /* i : low-frequency band filled noise */ ) { - Word16 j; - Word16 sb, tmp; - Word16 sbLen; - Word16 n_nbiggestsearch_fx[NB_SWB_SUBBANDS]; - Word16 ssearch_buflim_fx; - Word16 search_offset_fx[NB_SWB_SUBBANDS]; - Word16 nlags_fx[NB_SWB_SUBBANDS]; - - Word16 exp_refBuf; - Word16 sspectra_ma_fx[L_FRAME32k]; - - - Word32 L_temp; - - - /* Initializations */ - exp_refBuf = Qsh; - - j = 0; - move16(); - FOR(sb = 0; sb < nBands_search; sb++) - { - FindNBiggest2_simple_fx_har(L_targetBuf + subband_offsets[sb], exp_refBuf, gi_fx + j, sbWidth[sb], &n_nbiggestsearch_fx[sb], N_NBIGGEST_PULSEARCH); - - j = add(j, N_NBIGGEST_PULSEARCH); - move16(); - } - - /* Selection of most representative subband (full search) */ - FOR(sb = 0; sb < nBands_search; sb++) - { - nlags_fx[sb] = shl(1, bits_lagIndices_modeNormal[sb]); - move16(); - } - - FOR(sb = 0; sb < nBands_search; sb++) - { - search_offset_fx[sb] = subband_search_offsets[sb]; - move16(); - } - - sspectra_ma_fx[0] = add(shr(predBuf_ni_fx[0], 1), shr(predBuf_ni_fx[1], 1)); - tmp = sub(predBufLen, 1); - FOR(sb = 1; sb < tmp; sb++) - { - /*sspectra_ma[sb] = (predBuf[sb-1] + predBuf[sb] + predBuf[sb+1])/3.0f; */ - L_temp = L_mult(predBuf_ni_fx[sb], 10922); /* 10922 = 0.33333 (Q15) */ - L_temp = L_add(L_temp, L_mult(predBuf_ni_fx[sb - 1], 10922)); - L_temp = L_add(L_temp, L_mult(predBuf_ni_fx[sb + 1], 10922)); /* Qss+15+1 */ - sspectra_ma_fx[sb] = round_fx(L_temp); - } - sspectra_ma_fx[sb] = add(shr(predBuf_ni_fx[sb - 1], 1), shr(predBuf_ni_fx[sb], 1)); - - /* Partial search for rest of subbands except the last which is fixed */ - FOR(sb = 0; sb < nBands_search; sb++) - { - sbLen = sbWidth[sb]; - ssearch_buflim_fx = sub(predBufLen, add(sbLen, search_offset_fx[sb])); - lagIndices[sb] = GetSubbandCorrIndex2_pulsestep_fx( - L_targetBuf + subband_offsets[sb], - predBuf_fx + search_offset_fx[sb], - sspectra_ma_fx + search_offset_fx[sb], - sbLen, nlags_fx[sb], gi_fx + (sb*N_NBIGGEST_PULSEARCH), - n_nbiggestsearch_fx[sb], - ssearch_buflim_fx, predBuf_ni_fx + search_offset_fx[sb]); - } - + Word16 j; + Word16 sb, tmp; + Word16 sbLen; + Word16 n_nbiggestsearch_fx[NB_SWB_SUBBANDS]; + Word16 ssearch_buflim_fx; + Word16 search_offset_fx[NB_SWB_SUBBANDS]; + Word16 nlags_fx[NB_SWB_SUBBANDS]; + + Word16 exp_refBuf; + Word16 sspectra_ma_fx[L_FRAME32k]; + + + Word32 L_temp; + + + /* Initializations */ + exp_refBuf = Qsh; + + j = 0; + move16(); + FOR( sb = 0; sb < nBands_search; sb++ ) + { + FindNBiggest2_simple_fx_har( L_targetBuf + subband_offsets[sb], exp_refBuf, gi_fx + j, sbWidth[sb], &n_nbiggestsearch_fx[sb], N_NBIGGEST_PULSEARCH ); + + j = add( j, N_NBIGGEST_PULSEARCH ); + move16(); + } + + /* Selection of most representative subband (full search) */ + FOR( sb = 0; sb < nBands_search; sb++ ) + { + nlags_fx[sb] = shl( 1, bits_lagIndices_modeNormal[sb] ); + move16(); + } + + FOR( sb = 0; sb < nBands_search; sb++ ) + { + search_offset_fx[sb] = subband_search_offsets[sb]; + move16(); + } + + sspectra_ma_fx[0] = add( shr( predBuf_ni_fx[0], 1 ), shr( predBuf_ni_fx[1], 1 ) ); + tmp = sub( predBufLen, 1 ); + FOR( sb = 1; sb < tmp; sb++ ) + { + /*sspectra_ma[sb] = (predBuf[sb-1] + predBuf[sb] + predBuf[sb+1])/3.0f; */ + L_temp = L_mult( predBuf_ni_fx[sb], 10922 ); /* 10922 = 0.33333 (Q15) */ + L_temp = L_add( L_temp, L_mult( predBuf_ni_fx[sb - 1], 10922 ) ); + L_temp = L_add( L_temp, L_mult( predBuf_ni_fx[sb + 1], 10922 ) ); /* Qss+15+1 */ + sspectra_ma_fx[sb] = round_fx( L_temp ); + } + sspectra_ma_fx[sb] = add( shr( predBuf_ni_fx[sb - 1], 1 ), shr( predBuf_ni_fx[sb], 1 ) ); + + /* Partial search for rest of subbands except the last which is fixed */ + FOR( sb = 0; sb < nBands_search; sb++ ) + { + sbLen = sbWidth[sb]; + ssearch_buflim_fx = sub( predBufLen, add( sbLen, search_offset_fx[sb] ) ); + lagIndices[sb] = GetSubbandCorrIndex2_pulsestep_fx( + L_targetBuf + subband_offsets[sb], + predBuf_fx + search_offset_fx[sb], + sspectra_ma_fx + search_offset_fx[sb], + sbLen, nlags_fx[sb], gi_fx + ( sb * N_NBIGGEST_PULSEARCH ), + n_nbiggestsearch_fx[sb], + ssearch_buflim_fx, predBuf_ni_fx + search_offset_fx[sb] ); + } } /*--------------------------------------------------------------------------* * gethar_noisegn_fx() @@ -657,187 +653,186 @@ static void GetSWBIndices_fx( *--------------------------------------------------------------------------*/ static void gethar_noisegn_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ - const Word32 L_spectra[], /* i : Qs input MDCT */ - const Word16 QsL, /* i : Q0 Q value for L_spectra, L_xSynth_har */ - const Word16 noise_flr_fx[], /* i : Qss noise floor */ - const Word16 Qss, /* i : Q0 Q value for noise_flr_fx, sspectra */ - Word32 L_xSynth_har[], /* o : Qs output SWB MDCT */ - const Word16 sbWidth[], /* i : Q0 band width for SWB */ - const Word16 lagIndices[], /* i : Q0 lag Indices */ - const Word16 bands, /* i : Q0 all band number */ - const Word16 har_bands, /* i : Q0 harmonic band number */ - const Word16 fLenLow, /* i : Q0 low frequency band width */ - const Word16 fLenHigh, /* i : Q0 SWB band width */ - const Word16 subband_offsets[], /* i : Q0 offset */ - const Word16 subband_search_offset[], /* i : Q0 offset */ - const Word16 band_start[], /* i : Q0 band start array */ - const Word16 band_end[], /* i : Q0 band end array */ - const Word16 band_width[], /* i : Q0 band width */ - Word32 L_band_energy[], /* i : Qbe band energy (Log scale) */ - const Word16 Qbe, /* i : Q0 Q value for L_band_energy */ - Word32 L_be_tonal[], /* o : QbeL tonal energy */ - Word16 *QbeL, /* o : Q0 Q value for L_be_tonal */ - const Word16 *sspectra_fx, /* i : Qss smoothed spectrum */ - const Word16 har_freq_est2, /* i : Q0 for harmonic structure */ - const Word16 pos_max_hfe2, /* i/o : Q0 for harmonic structure */ - Word16 *pul_res_fx, /* o : Q0 */ - GainItem_fx pk_sf_fx[] /* o : */ + BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ + const Word32 L_spectra[], /* i : Qs input MDCT */ + const Word16 QsL, /* i : Q0 Q value for L_spectra, L_xSynth_har */ + const Word16 noise_flr_fx[], /* i : Qss noise floor */ + const Word16 Qss, /* i : Q0 Q value for noise_flr_fx, sspectra */ + Word32 L_xSynth_har[], /* o : Qs output SWB MDCT */ + const Word16 sbWidth[], /* i : Q0 band width for SWB */ + const Word16 lagIndices[], /* i : Q0 lag Indices */ + const Word16 bands, /* i : Q0 all band number */ + const Word16 har_bands, /* i : Q0 harmonic band number */ + const Word16 fLenLow, /* i : Q0 low frequency band width */ + const Word16 fLenHigh, /* i : Q0 SWB band width */ + const Word16 subband_offsets[], /* i : Q0 offset */ + const Word16 subband_search_offset[], /* i : Q0 offset */ + const Word16 band_start[], /* i : Q0 band start array */ + const Word16 band_end[], /* i : Q0 band end array */ + const Word16 band_width[], /* i : Q0 band width */ + Word32 L_band_energy[], /* i : Qbe band energy (Log scale) */ + const Word16 Qbe, /* i : Q0 Q value for L_band_energy */ + Word32 L_be_tonal[], /* o : QbeL tonal energy */ + Word16 *QbeL, /* o : Q0 Q value for L_be_tonal */ + const Word16 *sspectra_fx, /* i : Qss smoothed spectrum */ + const Word16 har_freq_est2, /* i : Q0 for harmonic structure */ + const Word16 pos_max_hfe2, /* i/o : Q0 for harmonic structure */ + Word16 *pul_res_fx, /* o : Q0 */ + GainItem_fx pk_sf_fx[] /* o : */ ) { - Word16 i; + Word16 i; - Word32 L_xSynth_har_sft[L_FRAME32k]; - Word32 L_hfspec_sft[L_FRAME32k]; + Word32 L_xSynth_har_sft[L_FRAME32k]; + Word32 L_hfspec_sft[L_FRAME32k]; - Word32 L_hfspec[L_FRAME32k]; + Word32 L_hfspec[L_FRAME32k]; - GainItem_fx get_pk_fx[N_NBIGGEST_SEARCH_LRG_B]; - Word16 n_nbiggestsearch_fx, imin_fx, gqlevs_fx; + GainItem_fx get_pk_fx[N_NBIGGEST_SEARCH_LRG_B]; + Word16 n_nbiggestsearch_fx, imin_fx, gqlevs_fx; - Word32 L_g1, L_g2; - Word16 exp_safe; - Word32 L_temp; + Word32 L_g1, L_g2; + Word16 exp_safe; + Word32 L_temp; - Word16 exp_normn, exp_normd; - Word16 temp_fx; - Word16 div_fx; + Word16 exp_normn, exp_normd; + Word16 temp_fx; + Word16 div_fx; - Word16 exp_norm_g1, exp_norm_g2; - Word16 sqrt_fx, Qsqrt; - Word16 g_fx; - Word16 exp, frac; + Word16 exp_norm_g1, exp_norm_g2; + Word16 sqrt_fx, Qsqrt; + Word16 g_fx; + Word16 exp, frac; - Word16 dmin_fx, d_fx; + Word16 dmin_fx, d_fx; - Word16 temp_lo, temp_hi; - Word16 Qg; + Word16 temp_lo, temp_hi; + Word16 Qg; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; -#endif - /*Generate HF noise*/ - genhf_noise_fx(noise_flr_fx, Qss, L_xSynth_har, QsL, sspectra_fx, bands, har_bands, har_freq_est2, pos_max_hfe2, pul_res_fx, pk_sf_fx, fLenLow, - fLenHigh, sbWidth, lagIndices, subband_offsets, subband_search_offset); - - Copy32(&L_spectra[fLenLow], L_hfspec, fLenHigh); - FindNBiggest2_simple_fx_har(L_hfspec, QsL, get_pk_fx, fLenHigh, &n_nbiggestsearch_fx, N_NBIGGEST_SEARCH_LRG_B); - FOR(i = 0; i < n_nbiggestsearch_fx; i++) - { - L_hfspec[get_pk_fx[i].gainIndex_fx] = 0x0; - move16(); - } - - L_temp = 0x0; - FOR(i = 0; i < fLenHigh; i++) - { - L_temp = L_or(L_temp, L_abs(L_hfspec[i])); - } - exp_norm_g1 = norm_l(L_temp); - FOR(i = 0; i < fLenHigh; i++) - { - L_hfspec_sft[i] = L_shl(L_hfspec[i], exp_norm_g1); - } - - L_temp = 0x0; - FOR(i = 0; i < fLenHigh; i++) - { - L_temp = L_or(L_temp, L_abs(L_xSynth_har[i])); - } - exp_norm_g2 = norm_l(L_temp); - FOR(i = 0; i < fLenHigh; i++) - { - L_xSynth_har_sft[i] = L_shl(L_xSynth_har[i], exp_norm_g2); - } - - exp_safe = 4; - move16(); - L_g1 = L_deposit_l(0); - L_g2 = L_deposit_l(0); - FOR(i = 0; i < fLenHigh; i++) - { - temp_fx = round_fx(L_shr(L_hfspec_sft[i], exp_safe)); - L_g1 = L_mac(L_g1, temp_fx, temp_fx); /* 4: safe shift */ - temp_fx = round_fx(L_shr(L_xSynth_har_sft[i], exp_safe)); - L_g2 = L_mac(L_g2, temp_fx, temp_fx); /* 4: safe shift */ - } - - /*g = (float) log10(sqrt(g1/g2));*/ - /* Div Part */ - exp_normn = norm_l(L_g1); - exp_normn = sub(exp_normn, 1); - exp_normd = norm_l(L_g2); - temp_fx = extract_h(L_shl(L_g2, exp_normd)); - exp_normd = sub(exp_normd, 16); - - imin_fx = 0; - move16(); - test(); - IF(L_g1 != 0 && temp_fx != 0x0) - { - div_fx = div_l(L_shl(L_g1, exp_normn), temp_fx); - /* SQRT Part */ - sqrt_32n_16_fx(L_deposit_h(div_fx), add(add(sub(exp_normn, exp_normd), shl(sub(exp_norm_g1, exp_norm_g2), 1)), 15), &sqrt_fx, &Qsqrt); /* (exp_normn-exp_normd+(exp_norm_g1-exp_norm_g2)*2 -1)+16 */ - - /* Log10 Part */ - g_fx = 0x0; - move16(); - IF(sqrt_fx > 0x0) - { - L_temp = L_deposit_l(sqrt_fx); - - exp = norm_l(L_temp); - frac = Log2_norm_lc(L_shl(L_temp, exp)); - exp = sub(30, exp); - exp = sub(exp, Qsqrt); - L_temp = L_Comp(exp, frac); - - L_temp = Mpy_32_16_1(L_temp, 19728); /* log(2)/log(10)=.30102999566398119521 = 19728.3(Q16) Q(0+16+1)=Q17 */ + Flag Overflow = 0; +#endif + /*Generate HF noise*/ + genhf_noise_fx( noise_flr_fx, Qss, L_xSynth_har, QsL, sspectra_fx, bands, har_bands, har_freq_est2, pos_max_hfe2, pul_res_fx, pk_sf_fx, fLenLow, + fLenHigh, sbWidth, lagIndices, subband_offsets, subband_search_offset ); + + Copy32( &L_spectra[fLenLow], L_hfspec, fLenHigh ); + FindNBiggest2_simple_fx_har( L_hfspec, QsL, get_pk_fx, fLenHigh, &n_nbiggestsearch_fx, N_NBIGGEST_SEARCH_LRG_B ); + FOR( i = 0; i < n_nbiggestsearch_fx; i++ ) + { + L_hfspec[get_pk_fx[i].gainIndex_fx] = 0x0; + move16(); + } + + L_temp = 0x0; + FOR( i = 0; i < fLenHigh; i++ ) + { + L_temp = L_or( L_temp, L_abs( L_hfspec[i] ) ); + } + exp_norm_g1 = norm_l( L_temp ); + FOR( i = 0; i < fLenHigh; i++ ) + { + L_hfspec_sft[i] = L_shl( L_hfspec[i], exp_norm_g1 ); + } + + L_temp = 0x0; + FOR( i = 0; i < fLenHigh; i++ ) + { + L_temp = L_or( L_temp, L_abs( L_xSynth_har[i] ) ); + } + exp_norm_g2 = norm_l( L_temp ); + FOR( i = 0; i < fLenHigh; i++ ) + { + L_xSynth_har_sft[i] = L_shl( L_xSynth_har[i], exp_norm_g2 ); + } + + exp_safe = 4; + move16(); + L_g1 = L_deposit_l( 0 ); + L_g2 = L_deposit_l( 0 ); + FOR( i = 0; i < fLenHigh; i++ ) + { + temp_fx = round_fx( L_shr( L_hfspec_sft[i], exp_safe ) ); + L_g1 = L_mac( L_g1, temp_fx, temp_fx ); /* 4: safe shift */ + temp_fx = round_fx( L_shr( L_xSynth_har_sft[i], exp_safe ) ); + L_g2 = L_mac( L_g2, temp_fx, temp_fx ); /* 4: safe shift */ + } + + /*g = (float) log10(sqrt(g1/g2));*/ + /* Div Part */ + exp_normn = norm_l( L_g1 ); + exp_normn = sub( exp_normn, 1 ); + exp_normd = norm_l( L_g2 ); + temp_fx = extract_h( L_shl( L_g2, exp_normd ) ); + exp_normd = sub( exp_normd, 16 ); + + imin_fx = 0; + move16(); + test(); + IF( L_g1 != 0 && temp_fx != 0x0 ) + { + div_fx = div_l( L_shl( L_g1, exp_normn ), temp_fx ); + /* SQRT Part */ + sqrt_32n_16_fx( L_deposit_h( div_fx ), add( add( sub( exp_normn, exp_normd ), shl( sub( exp_norm_g1, exp_norm_g2 ), 1 ) ), 15 ), &sqrt_fx, &Qsqrt ); /* (exp_normn-exp_normd+(exp_norm_g1-exp_norm_g2)*2 -1)+16 */ + + /* Log10 Part */ + g_fx = 0x0; + move16(); + IF( sqrt_fx > 0x0 ) + { + L_temp = L_deposit_l( sqrt_fx ); + + exp = norm_l( L_temp ); + frac = Log2_norm_lc( L_shl( L_temp, exp ) ); + exp = sub( 30, exp ); + exp = sub( exp, Qsqrt ); + L_temp = L_Comp( exp, frac ); + + L_temp = Mpy_32_16_1( L_temp, 19728 ); /* log(2)/log(10)=.30102999566398119521 = 19728.3(Q16) Q(0+16+1)=Q17 */ #ifdef BASOP_NOGLOB - L_temp = L_shl_o(L_temp, 13, &Overflow); /* Q17+13=30 30-16=14 */ - g_fx = round_fx_o(L_temp, &Overflow); + L_temp = L_shl_o( L_temp, 13, &Overflow ); /* Q17+13=30 30-16=14 */ + g_fx = round_fx_o( L_temp, &Overflow ); #else - L_temp = L_shl(L_temp, 13); /* Q17+13=30 30-16=14 */ - g_fx = round_fx(L_temp); + L_temp = L_shl( L_temp, 13 ); /* Q17+13=30 30-16=14 */ + g_fx = round_fx( L_temp ); #endif - } - - gqlevs_fx = 4; - move16(); - dmin_fx = 32767; - move16(); - imin_fx = 0; - move16(); - - FOR(i = 0; i < gqlevs_fx; i++) - { - d_fx = abs_s(g_fx - gain_table_SWB_BWE_fx[i]); - IF(LT_16(d_fx, dmin_fx)) - { - dmin_fx = d_fx; - move16(); - imin_fx = i; - move16(); - } - } - } - - push_indice_fx(hBstr, IND_NOISEG, imin_fx, 2); - - /*g=(float) pow (10.0f,gain_table[imin]);*/ - L_temp = L_mult(gain_table_SWB_BWE_fx[imin_fx], 27213); /* Q14+Q13+1=Q28 log(10)/log(2)=3.3219 27213.23(Q13) */ - L_temp = L_shr(L_temp, 12); /* Q28-Q12 -> Q16 */ - temp_lo = L_Extract_lc(L_temp, &temp_hi); - Qg = sub(14, temp_hi); - g_fx = extract_l(Pow2(14, temp_lo)); - g_fx = shl(g_fx, sub(11, Qg)); - - ton_ene_est_fx( - L_xSynth_har, QsL, L_be_tonal, QbeL, L_band_energy, Qbe, - band_start, band_end, band_width, fLenLow, fLenHigh, bands, har_bands, g_fx, - pk_sf_fx, Qss, pul_res_fx - ); - - return; + } + + gqlevs_fx = 4; + move16(); + dmin_fx = 32767; + move16(); + imin_fx = 0; + move16(); + + FOR( i = 0; i < gqlevs_fx; i++ ) + { + d_fx = abs_s( g_fx - gain_table_SWB_BWE_fx[i] ); + IF( LT_16( d_fx, dmin_fx ) ) + { + dmin_fx = d_fx; + move16(); + imin_fx = i; + move16(); + } + } + } + + push_indice_fx( hBstr, IND_NOISEG, imin_fx, 2 ); + + /*g=(float) pow (10.0f,gain_table[imin]);*/ + L_temp = L_mult( gain_table_SWB_BWE_fx[imin_fx], 27213 ); /* Q14+Q13+1=Q28 log(10)/log(2)=3.3219 27213.23(Q13) */ + L_temp = L_shr( L_temp, 12 ); /* Q28-Q12 -> Q16 */ + temp_lo = L_Extract_lc( L_temp, &temp_hi ); + Qg = sub( 14, temp_hi ); + g_fx = extract_l( Pow2( 14, temp_lo ) ); + g_fx = shl( g_fx, sub( 11, Qg ) ); + + ton_ene_est_fx( + L_xSynth_har, QsL, L_be_tonal, QbeL, L_band_energy, Qbe, + band_start, band_end, band_width, fLenLow, fLenHigh, bands, har_bands, g_fx, + pk_sf_fx, Qss, pul_res_fx ); + + return; } /*--------------------------------------------------------------------------* * EncodeSWBSubbands() @@ -847,198 +842,198 @@ static void gethar_noisegn_fx( * find lowband indices denoting the selected lowband subband. *--------------------------------------------------------------------------*/ static void EncodeSWBSubbands_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - Word32 *L_spectra, /* i/o: MDCT domain spectrum */ - Word16 QsL, /* i : Q value for L_spectra */ - const Word16 fLenLow_fx, /* i : lowband length */ - const Word16 fLenHigh_fx, /* i : highband length */ - const Word16 nBands_fx, /* i : number of subbands */ - const Word16 nBands_search_fx, /* i : number of subbands to be searched for BWE */ - const Word16 *sbWidth_fx, /* i : subband lengths */ - const Word16 *subband_offsets_fx, /* i : Subband offset for BWE */ - Word16 *lagIndices_fx, /* o : lowband index for each subband */ - const Word16 BANDS_fx, /* i : noise estimate from WB part */ - const Word16 *band_start_fx, /* i : Number subbands/Frame */ - const Word16 *band_end_fx, /* i : Band Start of each SB */ - Word32 *L_band_energy, /* i : Band end of each SB, :Qbe */ - Word16 Qbe, /* i : Q value of band energy */ - const Word16 *p2a_flags_fx, /* i : BAnd energy of each SB */ - const Word16 hqswb_clas_fx, /* i : lowband synthesis */ - Word16 *prev_frm_index_fx, /* i : clas information */ - const Word16 har_bands_fx, /* i/o: Index of the previous Frame */ - const Word16 *subband_search_offset_fx, /* i : Number of harmonic LF bands */ - Word16 *prev_frm_hfe2, /* i/o: */ - Word16 *prev_stab_hfe2, /* i/o: */ - const Word16 band_width_fx[], /* i : band width */ - const Word32 L_spectra_ni[], /* i : Qs noise injected spectra */ - Word16 *ni_seed_fx /* i/o: random seed */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + Word32 *L_spectra, /* i/o: MDCT domain spectrum */ + Word16 QsL, /* i : Q value for L_spectra */ + const Word16 fLenLow_fx, /* i : lowband length */ + const Word16 fLenHigh_fx, /* i : highband length */ + const Word16 nBands_fx, /* i : number of subbands */ + const Word16 nBands_search_fx, /* i : number of subbands to be searched for BWE */ + const Word16 *sbWidth_fx, /* i : subband lengths */ + const Word16 *subband_offsets_fx, /* i : Subband offset for BWE */ + Word16 *lagIndices_fx, /* o : lowband index for each subband */ + const Word16 BANDS_fx, /* i : noise estimate from WB part */ + const Word16 *band_start_fx, /* i : Number subbands/Frame */ + const Word16 *band_end_fx, /* i : Band Start of each SB */ + Word32 *L_band_energy, /* i : Band end of each SB, :Qbe */ + Word16 Qbe, /* i : Q value of band energy */ + const Word16 *p2a_flags_fx, /* i : BAnd energy of each SB */ + const Word16 hqswb_clas_fx, /* i : lowband synthesis */ + Word16 *prev_frm_index_fx, /* i : clas information */ + const Word16 har_bands_fx, /* i/o: Index of the previous Frame */ + const Word16 *subband_search_offset_fx, /* i : Number of harmonic LF bands */ + Word16 *prev_frm_hfe2, /* i/o: */ + Word16 *prev_stab_hfe2, /* i/o: */ + const Word16 band_width_fx[], /* i : band width */ + const Word32 L_spectra_ni[], /* i : Qs noise injected spectra */ + Word16 *ni_seed_fx /* i/o: random seed */ ) { - Word16 i, k; - Word16 sspectra_fx[L_FRAME32k]; - Word16 sspectra_ni_fx[L_FRAME32k]; - Word16 sspectra_diff_fx[L_FRAME32k]; - Word16 Qss; /* Q value of Smoothed Spectrum low-subband */ - Word32 L_be_tonal[SWB_HAR_RAN1]; /* Q */ - Word16 ss_min_fx; /* Qss */ - Word32 L_th_g[NB_SWB_SUBBANDS]; - Word16 QbeL; - GainItem_fx pk_sf_fx[(NB_SWB_SUBBANDS) * 8]; - Word16 pul_res_fx[NB_SWB_SUBBANDS]; - - GainItem_fx Nbiggest_fx[NB_SWB_SUBBANDS*N_NBIGGEST_PULSEARCH]; - - Word32 L_xSynth_har[L_FRAME32k]; /* Qs */ - - Word16 lagGains_fx[NB_SWB_SUBBANDS]; - Word16 QlagGains[NB_SWB_SUBBANDS]; - Word16 har_freq_est1, har_freq_est2; - Word16 flag_dis; - Word16 pos_max_hfe2; - HQ_ENC_HANDLE hHQ_core = st_fx->hHQ_core; - - har_freq_est1 = 0; - move16(); - har_freq_est2 = 0; - move16(); - flag_dis = 1; - move16(); - pos_max_hfe2 = 0; - move16(); - - set16_fx(sspectra_fx, 0, fLenLow_fx); - set16_fx(sspectra_ni_fx, 0, fLenLow_fx); - set32_fx(L_xSynth_har, 0, L_FRAME32k); - set16_fx(pul_res_fx, 0, NB_SWB_SUBBANDS); - - - IF(EQ_16(hqswb_clas_fx, HQ_HARMONIC)) - { - pos_max_hfe2 = har_est_fx(L_spectra, fLenLow_fx, &har_freq_est1, &har_freq_est2, &flag_dis, prev_frm_hfe2, subband_search_offset_fx, sbWidth_fx, prev_stab_hfe2); - noise_extr_corcod_fx(L_spectra, L_spectra_ni, sspectra_fx, sspectra_diff_fx, sspectra_ni_fx, fLenLow_fx, hHQ_core->prev_hqswb_clas, &hHQ_core->prev_ni_ratio_fx, &Qss); - /* Find best indices for each group */ - getswbindices_har_fx( - L_spectra, - QsL, sspectra_ni_fx, - nBands_search_fx, lagIndices_fx, prev_frm_index_fx, fLenLow_fx, subband_offsets_fx, sbWidth_fx, subband_search_offset_fx); - - /* Write the indices into the bitstream */ - FOR(k = 0; k < nBands_search_fx; k++) - { - push_indice_fx(st_fx->hBstr, IND_LAGINDICES, lagIndices_fx[k], bits_lagIndices_mode0_Har[k]); - } - - IF(flag_dis == 0) - { - test(); - if (NE_16(har_freq_est2, SWB_HAR_RAN1) || NE_16(har_freq_est2, *prev_frm_hfe2)) - { - har_freq_est2 = add(har_freq_est2, lagIndices_fx[0]); - move16(); - } - } - - gethar_noisegn_fx(st_fx->hBstr, L_spectra, QsL, sspectra_diff_fx, Qss, L_xSynth_har, - sbWidth_fx, lagIndices_fx, BANDS_fx, har_bands_fx, fLenLow_fx, fLenHigh_fx, - subband_offsets_fx, subband_search_offset_fx, band_start_fx, band_end_fx, band_width_fx, - L_band_energy, Qbe, L_be_tonal, &QbeL, sspectra_fx, - har_freq_est2, pos_max_hfe2, pul_res_fx, pk_sf_fx); - - - Gettonl_scalfact_fx(L_xSynth_har, QsL, L_spectra_ni, fLenLow_fx, fLenHigh_fx, har_bands_fx, BANDS_fx, L_band_energy, Qbe, band_start_fx, band_end_fx, - p2a_flags_fx, L_be_tonal, QbeL, pk_sf_fx, Qss, pul_res_fx); - - IF(flag_dis == 0) - { - *prev_frm_hfe2 = 0; - move16(); - } - ELSE - { - *prev_frm_hfe2 = har_freq_est2; - move16(); - } - - FOR(k = BANDS_fx - NB_SWB_SUBBANDS; k < BANDS_fx; k++) - { - FOR(i = band_start_fx[k]; i <= band_end_fx[k]; i++) - { - L_spectra[i] = L_xSynth_har[i - fLenLow_fx]; - move32(); /* QsL */ - } - } - } - ELSE - { - ss_min_fx = spectrumsmooth_noiseton_fx(L_spectra, /*QsL,*/ L_spectra_ni, sspectra_fx, sspectra_diff_fx, sspectra_ni_fx, &Qss, fLenLow_fx, ni_seed_fx); - - /* Get lag indices */ - GetSWBIndices_fx(sspectra_fx, /*Qss,*/ L_spectra + fLenLow_fx, QsL, nBands_fx, sbWidth_fx, lagIndices_fx, fLenLow_fx, - Nbiggest_fx, subband_offsets_fx, sspectra_fx); - - /* Bitstream operations */ - FOR(k = 0; k < nBands_fx; k++) - { - IF(EQ_16(p2a_flags_fx[BANDS_fx - NB_SWB_SUBBANDS + k], 1)) - { - lagIndices_fx[k] = 0; - move16(); - lagGains_fx[k] = 0; - move16(); - QlagGains[k] = 15; - move16(); - } - ELSE - { - push_indice_fx(st_fx->hBstr, IND_LAGINDICES, lagIndices_fx[k], bits_lagIndices_modeNormal[k]); - } - } - - convert_lagIndices_pls2smp_fx(lagIndices_fx, nBands_fx, lagIndices_fx, sspectra_fx, sbWidth_fx, fLenLow_fx); - - GetlagGains_fx(sspectra_ni_fx, Qss, &L_band_energy[BANDS_fx - NB_SWB_SUBBANDS], Qbe, nBands_fx, sbWidth_fx, lagIndices_fx, fLenLow_fx, lagGains_fx, QlagGains); - FOR(k = 0; k < NB_SWB_SUBBANDS; k++) - { - lagGains_fx[k] = mult_r(lagGains_fx[k], 29491); /* lagGains[k]*0.9f; */ - } - - FOR(k = 0; k < NB_SWB_SUBBANDS; k++) - { - L_th_g[k] = L_deposit_l(0); - IF(p2a_flags_fx[BANDS_fx - NB_SWB_SUBBANDS + k] == 0) - { - L_th_g[k] = L_shl(L_mult(lagGains_fx[k], ss_min_fx), sub(QsL, add(add(QlagGains[k], Qss), 1))); /* QlagGain+Qss -> QsL */ - } - } - - GetSynthesizedSpecThinOut_fx(sspectra_ni_fx, Qss, L_xSynth_har, QsL, nBands_fx, sbWidth_fx, lagIndices_fx, lagGains_fx, QlagGains, fLenLow_fx); - - /*Level adjustment for the missing bands*/ - noiseinj_hf_fx(L_xSynth_har, QsL, L_th_g, L_band_energy, Qbe, hHQ_core->prev_En_sb_fx, p2a_flags_fx, BANDS_fx, band_start_fx, band_end_fx, fLenLow_fx, fLenHigh_fx); - - - FOR(k = BANDS_fx - NB_SWB_SUBBANDS; k < BANDS_fx; k++) - { - IF(p2a_flags_fx[k] == 0) - { - FOR(i = band_start_fx[k]; i <= band_end_fx[k]; i++) - { - L_spectra[i] = L_xSynth_har[i - fLenLow_fx]; - move32(); /* Qob */ - } - } - ELSE - { - FOR(i = band_start_fx[k]; i <= band_end_fx[k]; i++) - { - L_spectra[i] = L_spectra_ni[i]; - move32(); - } - } - } - } - - return; + Word16 i, k; + Word16 sspectra_fx[L_FRAME32k]; + Word16 sspectra_ni_fx[L_FRAME32k]; + Word16 sspectra_diff_fx[L_FRAME32k]; + Word16 Qss; /* Q value of Smoothed Spectrum low-subband */ + Word32 L_be_tonal[SWB_HAR_RAN1]; /* Q */ + Word16 ss_min_fx; /* Qss */ + Word32 L_th_g[NB_SWB_SUBBANDS]; + Word16 QbeL; + GainItem_fx pk_sf_fx[(NB_SWB_SUBBANDS) *8]; + Word16 pul_res_fx[NB_SWB_SUBBANDS]; + + GainItem_fx Nbiggest_fx[NB_SWB_SUBBANDS * N_NBIGGEST_PULSEARCH]; + + Word32 L_xSynth_har[L_FRAME32k]; /* Qs */ + + Word16 lagGains_fx[NB_SWB_SUBBANDS]; + Word16 QlagGains[NB_SWB_SUBBANDS]; + Word16 har_freq_est1, har_freq_est2; + Word16 flag_dis; + Word16 pos_max_hfe2; + HQ_ENC_HANDLE hHQ_core = st_fx->hHQ_core; + + har_freq_est1 = 0; + move16(); + har_freq_est2 = 0; + move16(); + flag_dis = 1; + move16(); + pos_max_hfe2 = 0; + move16(); + + set16_fx( sspectra_fx, 0, fLenLow_fx ); + set16_fx( sspectra_ni_fx, 0, fLenLow_fx ); + set32_fx( L_xSynth_har, 0, L_FRAME32k ); + set16_fx( pul_res_fx, 0, NB_SWB_SUBBANDS ); + + + IF( EQ_16( hqswb_clas_fx, HQ_HARMONIC ) ) + { + pos_max_hfe2 = har_est_fx( L_spectra, fLenLow_fx, &har_freq_est1, &har_freq_est2, &flag_dis, prev_frm_hfe2, subband_search_offset_fx, sbWidth_fx, prev_stab_hfe2 ); + noise_extr_corcod_fx( L_spectra, L_spectra_ni, sspectra_fx, sspectra_diff_fx, sspectra_ni_fx, fLenLow_fx, hHQ_core->prev_hqswb_clas, &hHQ_core->prev_ni_ratio_fx, &Qss ); + /* Find best indices for each group */ + getswbindices_har_fx( + L_spectra, + QsL, sspectra_ni_fx, + nBands_search_fx, lagIndices_fx, prev_frm_index_fx, fLenLow_fx, subband_offsets_fx, sbWidth_fx, subband_search_offset_fx ); + + /* Write the indices into the bitstream */ + FOR( k = 0; k < nBands_search_fx; k++ ) + { + push_indice_fx( st_fx->hBstr, IND_LAGINDICES, lagIndices_fx[k], bits_lagIndices_mode0_Har[k] ); + } + + IF( flag_dis == 0 ) + { + test(); + if ( NE_16( har_freq_est2, SWB_HAR_RAN1 ) || NE_16( har_freq_est2, *prev_frm_hfe2 ) ) + { + har_freq_est2 = add( har_freq_est2, lagIndices_fx[0] ); + move16(); + } + } + + gethar_noisegn_fx( st_fx->hBstr, L_spectra, QsL, sspectra_diff_fx, Qss, L_xSynth_har, + sbWidth_fx, lagIndices_fx, BANDS_fx, har_bands_fx, fLenLow_fx, fLenHigh_fx, + subband_offsets_fx, subband_search_offset_fx, band_start_fx, band_end_fx, band_width_fx, + L_band_energy, Qbe, L_be_tonal, &QbeL, sspectra_fx, + har_freq_est2, pos_max_hfe2, pul_res_fx, pk_sf_fx ); + + + Gettonl_scalfact_fx( L_xSynth_har, QsL, L_spectra_ni, fLenLow_fx, fLenHigh_fx, har_bands_fx, BANDS_fx, L_band_energy, Qbe, band_start_fx, band_end_fx, + p2a_flags_fx, L_be_tonal, QbeL, pk_sf_fx, Qss, pul_res_fx ); + + IF( flag_dis == 0 ) + { + *prev_frm_hfe2 = 0; + move16(); + } + ELSE + { + *prev_frm_hfe2 = har_freq_est2; + move16(); + } + + FOR( k = BANDS_fx - NB_SWB_SUBBANDS; k < BANDS_fx; k++ ) + { + FOR( i = band_start_fx[k]; i <= band_end_fx[k]; i++ ) + { + L_spectra[i] = L_xSynth_har[i - fLenLow_fx]; + move32(); /* QsL */ + } + } + } + ELSE + { + ss_min_fx = spectrumsmooth_noiseton_fx( L_spectra, /*QsL,*/ L_spectra_ni, sspectra_fx, sspectra_diff_fx, sspectra_ni_fx, &Qss, fLenLow_fx, ni_seed_fx ); + + /* Get lag indices */ + GetSWBIndices_fx( sspectra_fx, /*Qss,*/ L_spectra + fLenLow_fx, QsL, nBands_fx, sbWidth_fx, lagIndices_fx, fLenLow_fx, + Nbiggest_fx, subband_offsets_fx, sspectra_fx ); + + /* Bitstream operations */ + FOR( k = 0; k < nBands_fx; k++ ) + { + IF( EQ_16( p2a_flags_fx[BANDS_fx - NB_SWB_SUBBANDS + k], 1 ) ) + { + lagIndices_fx[k] = 0; + move16(); + lagGains_fx[k] = 0; + move16(); + QlagGains[k] = 15; + move16(); + } + ELSE + { + push_indice_fx( st_fx->hBstr, IND_LAGINDICES, lagIndices_fx[k], bits_lagIndices_modeNormal[k] ); + } + } + + convert_lagIndices_pls2smp_fx( lagIndices_fx, nBands_fx, lagIndices_fx, sspectra_fx, sbWidth_fx, fLenLow_fx ); + + GetlagGains_fx( sspectra_ni_fx, Qss, &L_band_energy[BANDS_fx - NB_SWB_SUBBANDS], Qbe, nBands_fx, sbWidth_fx, lagIndices_fx, fLenLow_fx, lagGains_fx, QlagGains ); + FOR( k = 0; k < NB_SWB_SUBBANDS; k++ ) + { + lagGains_fx[k] = mult_r( lagGains_fx[k], 29491 ); /* lagGains[k]*0.9f; */ + } + + FOR( k = 0; k < NB_SWB_SUBBANDS; k++ ) + { + L_th_g[k] = L_deposit_l( 0 ); + IF( p2a_flags_fx[BANDS_fx - NB_SWB_SUBBANDS + k] == 0 ) + { + L_th_g[k] = L_shl( L_mult( lagGains_fx[k], ss_min_fx ), sub( QsL, add( add( QlagGains[k], Qss ), 1 ) ) ); /* QlagGain+Qss -> QsL */ + } + } + + GetSynthesizedSpecThinOut_fx( sspectra_ni_fx, Qss, L_xSynth_har, QsL, nBands_fx, sbWidth_fx, lagIndices_fx, lagGains_fx, QlagGains, fLenLow_fx ); + + /*Level adjustment for the missing bands*/ + noiseinj_hf_fx( L_xSynth_har, QsL, L_th_g, L_band_energy, Qbe, hHQ_core->prev_En_sb_fx, p2a_flags_fx, BANDS_fx, band_start_fx, band_end_fx, fLenLow_fx, fLenHigh_fx ); + + + FOR( k = BANDS_fx - NB_SWB_SUBBANDS; k < BANDS_fx; k++ ) + { + IF( p2a_flags_fx[k] == 0 ) + { + FOR( i = band_start_fx[k]; i <= band_end_fx[k]; i++ ) + { + L_spectra[i] = L_xSynth_har[i - fLenLow_fx]; + move32(); /* Qob */ + } + } + ELSE + { + FOR( i = band_start_fx[k]; i <= band_end_fx[k]; i++ ) + { + L_spectra[i] = L_spectra_ni[i]; + move32(); + } + } + } + } + + return; } /*--------------------------------------------------------------------------* * swb_bwe_enc_lr() @@ -1046,85 +1041,84 @@ static void EncodeSWBSubbands_fx( * Main encoding routine of SWB BWE for the LR MDCT core *--------------------------------------------------------------------------*/ void swb_bwe_enc_lr_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word32 L_m_core[], /* i : lowband synthesis */ - Word16 QsL, /* i : Q value */ - const Word32 L_m_orig[], /* i/o: scaled orig signal (MDCT) */ - Word32 L_m[], /* o : highband synthesis with lowband zeroed */ - const Word32 L_total_brate, /* i : total bitrate for selecting subband pattern */ - Word16 BANDS_fx, /* i : Total number of Subbands in a frame */ - Word16 *band_start_fx, /* i : band start of each SB */ - Word16 *band_end_fx, /* i : band end of each SB */ - Word32 *L_band_energy, /* i : band_energy of each SB */ - Word16 Qbe, /* i : Q value of band energy */ - Word16 *p2a_flags_fx, /* i : HF tonal indicator */ - const Word16 hqswb_clas_fx, /* i : HQ_NORMAL2 or HQ_HARMONIC mode */ - Word16 lowlength_fx, /* i : lowband length */ - Word16 highlength_fx, /* i : highband length */ - Word16 *prev_frm_index_fx, /* i/o: previous frame lag index for harmonic mode */ - const Word16 har_bands_fx, /* i : Number of LF harmonic bands */ - Word16 *prev_frm_hfe2, /* i/o: */ - Word16 *prev_stab_hfe2, /* i/o: */ - const Word16 band_width_fx[],/* i : band_width information */ - const Word32 L_y2_ni[], /* i : band_width information */ - Word16 *ni_seed_fx /* i/o: random seed for search buffer NI */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word32 L_m_core[], /* i : lowband synthesis */ + Word16 QsL, /* i : Q value */ + const Word32 L_m_orig[], /* i/o: scaled orig signal (MDCT) */ + Word32 L_m[], /* o : highband synthesis with lowband zeroed */ + const Word32 L_total_brate, /* i : total bitrate for selecting subband pattern */ + Word16 BANDS_fx, /* i : Total number of Subbands in a frame */ + Word16 *band_start_fx, /* i : band start of each SB */ + Word16 *band_end_fx, /* i : band end of each SB */ + Word32 *L_band_energy, /* i : band_energy of each SB */ + Word16 Qbe, /* i : Q value of band energy */ + Word16 *p2a_flags_fx, /* i : HF tonal indicator */ + const Word16 hqswb_clas_fx, /* i : HQ_NORMAL2 or HQ_HARMONIC mode */ + Word16 lowlength_fx, /* i : lowband length */ + Word16 highlength_fx, /* i : highband length */ + Word16 *prev_frm_index_fx, /* i/o: previous frame lag index for harmonic mode */ + const Word16 har_bands_fx, /* i : Number of LF harmonic bands */ + Word16 *prev_frm_hfe2, /* i/o: */ + Word16 *prev_stab_hfe2, /* i/o: */ + const Word16 band_width_fx[], /* i : band_width information */ + const Word32 L_y2_ni[], /* i : band_width information */ + Word16 *ni_seed_fx /* i/o: random seed for search buffer NI */ ) { - Word16 k; - Word16 nBands_fx; - Word16 nBands_search_fx; - Word16 wBands_fx[NB_SWB_SUBBANDS]; - Word16 lagIndices_fx[NB_SWB_SUBBANDS]; - Word16 swb_lowband_fx, swb_highband_fx, allband_fx; - - const Word16 *subband_offsets_fx; - const Word16 *subband_search_offset_fx; - - Word32 *p_L_m; - - subband_search_offset_fx = subband_search_offsets_13p2kbps_Har; - subband_offsets_fx = subband_offsets_sub5_13p2kbps_Har; - - hf_parinitiz_fx(L_total_brate, hqswb_clas_fx, lowlength_fx, highlength_fx, wBands_fx, &subband_search_offset_fx, &subband_offsets_fx, &nBands_fx, &nBands_search_fx, &swb_lowband_fx, &swb_highband_fx); - allband_fx = add(swb_lowband_fx, swb_highband_fx); - move16(); - - /* Prepare m[], low part from WB core, high part from 32k input */ - Copy32(L_m_core, L_m, swb_lowband_fx); - Copy32(&L_m_orig[swb_lowband_fx], &L_m[swb_lowband_fx], swb_highband_fx); - - EncodeSWBSubbands_fx( - st_fx, - L_m, QsL, - swb_lowband_fx, swb_highband_fx, nBands_fx, nBands_search_fx, wBands_fx, subband_offsets_fx, - lagIndices_fx, - BANDS_fx, band_start_fx, band_end_fx, - L_band_energy, Qbe, - p2a_flags_fx, - hqswb_clas_fx, prev_frm_index_fx, har_bands_fx, subband_search_offset_fx, - prev_frm_hfe2, prev_stab_hfe2, - band_width_fx, L_y2_ni, ni_seed_fx - ); - - p_L_m = &L_m[sub(allband_fx, 1)]; - *p_L_m = Mult_32_16(*p_L_m, 2028); - move32(); - p_L_m--; /* 0.0625 = 2028 (Q15) */ - *p_L_m = Mult_32_16(*p_L_m, 4096); - move32(); - p_L_m--; /* 0.125 = 4096 (Q15) */ - *p_L_m = Mult_32_16(*p_L_m, 8192); - move32(); - p_L_m--; /* 0.25 = 8192 (Q15) */ - *p_L_m = Mult_32_16(*p_L_m, 16384); - move32(); - p_L_m--; /* 0.5 = 16384 (Q15) */ - - /* set low frequencies to zero */ - FOR(k = 0; k < swb_lowband_fx; k++) - { - L_m[k] = L_deposit_l(0); - } - - return; + Word16 k; + Word16 nBands_fx; + Word16 nBands_search_fx; + Word16 wBands_fx[NB_SWB_SUBBANDS]; + Word16 lagIndices_fx[NB_SWB_SUBBANDS]; + Word16 swb_lowband_fx, swb_highband_fx, allband_fx; + + const Word16 *subband_offsets_fx; + const Word16 *subband_search_offset_fx; + + Word32 *p_L_m; + + subband_search_offset_fx = subband_search_offsets_13p2kbps_Har; + subband_offsets_fx = subband_offsets_sub5_13p2kbps_Har; + + hf_parinitiz_fx( L_total_brate, hqswb_clas_fx, lowlength_fx, highlength_fx, wBands_fx, &subband_search_offset_fx, &subband_offsets_fx, &nBands_fx, &nBands_search_fx, &swb_lowband_fx, &swb_highband_fx ); + allband_fx = add( swb_lowband_fx, swb_highband_fx ); + move16(); + + /* Prepare m[], low part from WB core, high part from 32k input */ + Copy32( L_m_core, L_m, swb_lowband_fx ); + Copy32( &L_m_orig[swb_lowband_fx], &L_m[swb_lowband_fx], swb_highband_fx ); + + EncodeSWBSubbands_fx( + st_fx, + L_m, QsL, + swb_lowband_fx, swb_highband_fx, nBands_fx, nBands_search_fx, wBands_fx, subband_offsets_fx, + lagIndices_fx, + BANDS_fx, band_start_fx, band_end_fx, + L_band_energy, Qbe, + p2a_flags_fx, + hqswb_clas_fx, prev_frm_index_fx, har_bands_fx, subband_search_offset_fx, + prev_frm_hfe2, prev_stab_hfe2, + band_width_fx, L_y2_ni, ni_seed_fx ); + + p_L_m = &L_m[sub( allband_fx, 1 )]; + *p_L_m = Mult_32_16( *p_L_m, 2028 ); + move32(); + p_L_m--; /* 0.0625 = 2028 (Q15) */ + *p_L_m = Mult_32_16( *p_L_m, 4096 ); + move32(); + p_L_m--; /* 0.125 = 4096 (Q15) */ + *p_L_m = Mult_32_16( *p_L_m, 8192 ); + move32(); + p_L_m--; /* 0.25 = 8192 (Q15) */ + *p_L_m = Mult_32_16( *p_L_m, 16384 ); + move32(); + p_L_m--; /* 0.5 = 16384 (Q15) */ + + /* set low frequencies to zero */ + FOR( k = 0; k < swb_lowband_fx; k++ ) + { + L_m[k] = L_deposit_l( 0 ); + } + + return; } diff --git a/lib_enc/swb_pre_proc_fx.c b/lib_enc/swb_pre_proc_fx.c index 682394a62..1bcef7025 100644 --- a/lib_enc/swb_pre_proc_fx.c +++ b/lib_enc/swb_pre_proc_fx.c @@ -9,9 +9,9 @@ #include "rom_com_fx.h" #include "rom_com.h" #include "stl.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" #include @@ -40,22 +40,22 @@ /*========================================================================*/ void wb_pre_proc_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 *new_inp_resamp16k, /* i : original input signal in Q-1 */ - Word16 *hb_speech /* o : HB target signal (6-8kHz) at 16kHz in Q-1 */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word16 *new_inp_resamp16k, /* i : original input signal in Q-1 */ + Word16 *hb_speech /* o : HB target signal (6-8kHz) at 16kHz in Q-1 */ ) { Word16 Sample_Delay_WB_BWE; Word16 ramp_flag; - Word16 old_input[NS2SA(16000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS) + L_FRAME16k]; + Word16 old_input[NS2SA( 16000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS ) + L_FRAME16k]; Word16 *highband_new_speech; - Word16 highband_old_speech[(L_LOOK_12k8+L_SUBFR+L_FRAME)*5/16]; + Word16 highband_old_speech[( L_LOOK_12k8 + L_SUBFR + L_FRAME ) * 5 / 16]; Word16 temp_buf[320]; Word16 Q_wb_sp, i, max_wb; Word16 fSwitchFromIO = 0; Word32 temp1 = 0; Word32 temp2 = 0; - SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; + SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD; @@ -65,47 +65,47 @@ void wb_pre_proc_fx( test(); test(); test(); - IF ( (EQ_32(st_fx->last_total_brate, ACELP_6k60))|| - (EQ_32(st_fx->last_total_brate, ACELP_8k85)) || - (EQ_32(st_fx->last_total_brate, ACELP_12k65)) || - (EQ_32(st_fx->last_total_brate, ACELP_14k25)) || - (EQ_32(st_fx->last_total_brate, ACELP_15k85)) || - (GE_32(st_fx->last_total_brate, ACELP_18k25) && LE_32(st_fx->last_total_brate, ACELP_23k85)) ) + IF( ( EQ_32( st_fx->last_total_brate, ACELP_6k60 ) ) || + ( EQ_32( st_fx->last_total_brate, ACELP_8k85 ) ) || + ( EQ_32( st_fx->last_total_brate, ACELP_12k65 ) ) || + ( EQ_32( st_fx->last_total_brate, ACELP_14k25 ) ) || + ( EQ_32( st_fx->last_total_brate, ACELP_15k85 ) ) || + ( GE_32( st_fx->last_total_brate, ACELP_18k25 ) && LE_32( st_fx->last_total_brate, ACELP_23k85 ) ) ) { fSwitchFromIO = 1; move16(); } - set16_fx( old_input, 0, NS2SA_fx2(16000, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS) + L_FRAME16k ); + set16_fx( old_input, 0, NS2SA_fx2( 16000, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) + L_FRAME16k ); max_wb = 1; move16(); - FOR (i = 0; i < L_FRAME16k; i++ ) + FOR( i = 0; i < L_FRAME16k; i++ ) { - max_wb = s_max(max_wb, abs_s(new_inp_resamp16k[i])); + max_wb = s_max( max_wb, abs_s( new_inp_resamp16k[i] ) ); } - Q_wb_sp = norm_s(max_wb); + Q_wb_sp = norm_s( max_wb ); - Copy_Scale_sig(new_inp_resamp16k, temp_buf, L_FRAME16k, -3); - temp1 = L_mac0(temp1, temp_buf[0], temp_buf[0]); - FOR (i = 1; i < L_FRAME16k; i++) + Copy_Scale_sig( new_inp_resamp16k, temp_buf, L_FRAME16k, -3 ); + temp1 = L_mac0( temp1, temp_buf[0], temp_buf[0] ); + FOR( i = 1; i < L_FRAME16k; i++ ) { - temp1 = L_mac0(temp1, temp_buf[i], temp_buf[i]); - temp2 = L_mac0(temp2, temp_buf[i-1], temp_buf[i]); + temp1 = L_mac0( temp1, temp_buf[i], temp_buf[i] ); + temp2 = L_mac0( temp2, temp_buf[i - 1], temp_buf[i] ); } - if( temp2 < Mult_32_16(temp1, 31129 /*0.95f*/) ) + if ( temp2 < Mult_32_16( temp1, 31129 /*0.95f*/ ) ) { - Q_wb_sp = sub(Q_wb_sp, 3); /* leave 3 bit headroom */ + Q_wb_sp = sub( Q_wb_sp, 3 ); /* leave 3 bit headroom */ } - Copy_Scale_sig(new_inp_resamp16k, temp_buf, L_FRAME16k, Q_wb_sp); - Scale_sig(hBWE_TD->decim_state1_fx, (2*ALLPASSSECTIONS_STEEP+1), Q_wb_sp); - Scale_sig(hBWE_TD->decim_state2_fx, (2*ALLPASSSECTIONS_STEEP+1), Q_wb_sp); + Copy_Scale_sig( new_inp_resamp16k, temp_buf, L_FRAME16k, Q_wb_sp ); + Scale_sig( hBWE_TD->decim_state1_fx, ( 2 * ALLPASSSECTIONS_STEEP + 1 ), Q_wb_sp ); + Scale_sig( hBWE_TD->decim_state2_fx, ( 2 * ALLPASSSECTIONS_STEEP + 1 ), Q_wb_sp ); /* temp_buf, and the memory states are in Q_wb_sp */ test(); test(); - IF ( EQ_16(st_fx->extl, WB_BWE)||EQ_16(st_fx->extl,WB_TBE)||st_fx->igf!=0) + IF( EQ_16( st_fx->extl, WB_BWE ) || EQ_16( st_fx->extl, WB_TBE ) || st_fx->igf != 0 ) { ramp_flag = 0; @@ -113,27 +113,27 @@ void wb_pre_proc_fx( test(); test(); test(); - IF( (NE_16(st_fx->last_extl, WB_TBE)&&NE_16(st_fx->last_extl,WB_BWE)&&st_fx->igf==0)|| - (st_fx->igf != 0 && fSwitchFromIO != 0) ) + IF( ( NE_16( st_fx->last_extl, WB_TBE ) && NE_16( st_fx->last_extl, WB_BWE ) && st_fx->igf == 0 ) || + ( st_fx->igf != 0 && fSwitchFromIO != 0 ) ) { ramp_flag = 1; } - IF ( !hSC_VBR->ppp_mode) + IF( !hSC_VBR->ppp_mode ) { /* temp_buf is in Q_wb_sp hb_speech and the two decimator memories are in Q_wb_sp */ flip_spectrum_and_decimby4_fx( temp_buf, hb_speech, L_FRAME16k, hBWE_TD->decim_state1_fx, hBWE_TD->decim_state2_fx, ramp_flag ); /* rescale the hb_speech and memories back to Q-1 to keep the downstream BWE coding unaffected */ - Scale_sig(hb_speech, L_FRAME16k/4, -Q_wb_sp); - Scale_sig(hBWE_TD->decim_state1_fx, (2*ALLPASSSECTIONS_STEEP+1), -Q_wb_sp); - Scale_sig(hBWE_TD->decim_state2_fx, (2*ALLPASSSECTIONS_STEEP+1), -Q_wb_sp); + Scale_sig( hb_speech, L_FRAME16k / 4, -Q_wb_sp ); + Scale_sig( hBWE_TD->decim_state1_fx, ( 2 * ALLPASSSECTIONS_STEEP + 1 ), -Q_wb_sp ); + Scale_sig( hBWE_TD->decim_state2_fx, ( 2 * ALLPASSSECTIONS_STEEP + 1 ), -Q_wb_sp ); - IF( NE_16(st_fx->extl, WB_TBE)) + IF( NE_16( st_fx->extl, WB_TBE ) ) { /* Update the previous wideband speech buffer in case of a WB_BWE frame */ - Sample_Delay_WB_BWE = (L_LOOK_12k8 + L_SUBFR) * 5/16; + Sample_Delay_WB_BWE = ( L_LOOK_12k8 + L_SUBFR ) * 5 / 16; highband_new_speech = highband_old_speech + Sample_Delay_WB_BWE; Copy( hb_speech, highband_new_speech, L_FRAME16k / 4 ); @@ -143,21 +143,21 @@ void wb_pre_proc_fx( } ELSE { - set16_fx(hBWE_TD->decim_state1_fx, 0, (2*ALLPASSSECTIONS_STEEP+1) ); - set16_fx(hBWE_TD->decim_state2_fx, 0, (2*ALLPASSSECTIONS_STEEP+1) ); - set16_fx(hBWE_TD->old_speech_wb_fx, 0, (L_LOOK_12k8 + L_SUBFR) * 5/16 ); + set16_fx( hBWE_TD->decim_state1_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); + set16_fx( hBWE_TD->decim_state2_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); + set16_fx( hBWE_TD->old_speech_wb_fx, 0, ( L_LOOK_12k8 + L_SUBFR ) * 5 / 16 ); } /* st->old_input_wb and st->old_wtda_wb must be updated each frame, or there are often some clicks during WB TBE <-> WB BWE switching */ test(); test(); test(); - IF ( (NE_16(st_fx->extl, WB_BWE)||(EQ_16(st_fx->extl,WB_BWE)&&LE_32(st_fx->total_brate,ACELP_8k00)))&&!hSC_VBR->ppp_mode) + IF( ( NE_16( st_fx->extl, WB_BWE ) || ( EQ_16( st_fx->extl, WB_BWE ) && LE_32( st_fx->total_brate, ACELP_8k00 ) ) ) && !hSC_VBR->ppp_mode ) { Sample_Delay_WB_BWE = NS2SA_fx2( 16000, DELAY_FD_BWE_ENC_12k8_NS ); Copy( new_inp_resamp16k, &old_input[Sample_Delay_WB_BWE], L_FRAME16k ); - Copy(hBWE_FD->old_input_wb_fx, old_input, Sample_Delay_WB_BWE ); + Copy( hBWE_FD->old_input_wb_fx, old_input, Sample_Delay_WB_BWE ); Copy( new_inp_resamp16k + L_FRAME16k - Sample_Delay_WB_BWE, hBWE_FD->old_input_wb_fx, Sample_Delay_WB_BWE ); Copy( old_input, hBWE_FD->L_old_wtda_swb_fx, L_FRAME16k ); } @@ -192,20 +192,20 @@ void wb_pre_proc_fx( /*========================================================================*/ void swb_pre_proc_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 *input_fx, /* i : original input signal */ - Word16 *new_swb_speech_fx, /* o : original input signal at 32kHz */ - Word16 *shb_speech_fx, /* o : SHB target signal (6-14kHz) at 16kHz */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word16 *input_fx, /* i : original input signal */ + Word16 *new_swb_speech_fx, /* o : original input signal at 32kHz */ + Word16 *shb_speech_fx, /* o : SHB target signal (6-14kHz) at 16kHz */ Word16 *Q_shb_spch, - Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i : real CLDFB buffer for target synthesis */ - Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i : imag CLDFB buffer for target synthesis */ - const CLDFB_SCALE_FACTOR *cldfbScale /* i : scale data of real and imag CLDFB buffers */ + Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i : real CLDFB buffer for target synthesis */ + Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i : imag CLDFB buffer for target synthesis */ + const CLDFB_SCALE_FACTOR *cldfbScale /* i : scale data of real and imag CLDFB buffers */ ) { Word16 Sample_Delay_SWB_BWE, delay; Word16 inner_frame; UWord16 inner_Fs; - Word16 old_input_fx[NS2SA(48000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS) + L_FRAME48k]; + Word16 old_input_fx[NS2SA( 48000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS ) + L_FRAME48k]; Word16 spchTmp_fx[L_FRAME32k]; Word16 i; Word16 startB, endB; @@ -225,36 +225,36 @@ void swb_pre_proc_fx( TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD; - FOR( j=0; j < CLDFB_NO_COL_MAX; j++ ) + FOR( j = 0; j < CLDFB_NO_COL_MAX; j++ ) { - set32_fx(realBufferTmp[j], 0, 20); - set32_fx(imagBufferTmp[j], 0, 20); + set32_fx( realBufferTmp[j], 0, 20 ); + set32_fx( imagBufferTmp[j], 0, 20 ); realBufferFlipped[j] = realBufferTmp[j]; imagBufferFlipped[j] = imagBufferTmp[j]; } - set16_fx( old_input_fx, 0, NS2SA_fx2(48000, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS) + L_FRAME48k ); + set16_fx( old_input_fx, 0, NS2SA_fx2( 48000, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) + L_FRAME48k ); - IF( EQ_32(st_fx->input_Fs, 32000)) + IF( EQ_32( st_fx->input_Fs, 32000 ) ) { - Copy(input_fx, new_swb_speech_fx, L_FRAME32k); /*Q0 */ + Copy( input_fx, new_swb_speech_fx, L_FRAME32k ); /*Q0 */ test(); test(); - IF( NE_16(st_fx->last_extl, SWB_BWE)&&NE_16(st_fx->last_extl,FB_BWE)&&NE_16(st_fx->extl,SWB_BWE_HIGHRATE)) + IF( NE_16( st_fx->last_extl, SWB_BWE ) && NE_16( st_fx->last_extl, FB_BWE ) && NE_16( st_fx->extl, SWB_BWE_HIGHRATE ) ) { Sample_Delay_SWB_BWE = NS2SA_fx2( 32000, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ); - Copy(hBWE_FD->old_fdbwe_speech_fx, &old_input_fx[Sample_Delay_SWB_BWE], L_FRAME32k ); + Copy( hBWE_FD->old_fdbwe_speech_fx, &old_input_fx[Sample_Delay_SWB_BWE], L_FRAME32k ); set16_fx( old_input_fx, 0, Sample_Delay_SWB_BWE ); - Copy(hBWE_FD->old_fdbwe_speech_fx + L_FRAME32k - Sample_Delay_SWB_BWE, hBWE_FD->old_input_fx, Sample_Delay_SWB_BWE ); + Copy( hBWE_FD->old_fdbwe_speech_fx + L_FRAME32k - Sample_Delay_SWB_BWE, hBWE_FD->old_input_fx, Sample_Delay_SWB_BWE ); - IF( sub(st_fx->extl, WB_BWE) != 0 ) + IF( sub( st_fx->extl, WB_BWE ) != 0 ) { Copy( old_input_fx, hBWE_FD->L_old_wtda_swb_fx, L_FRAME32k ); } } test(); - IF( NE_16(st_fx->extl, SWB_BWE)&&NE_16(st_fx->extl,FB_BWE)) + IF( NE_16( st_fx->extl, SWB_BWE ) && NE_16( st_fx->extl, FB_BWE ) ) { Copy( input_fx, hBWE_FD->old_fdbwe_speech_fx, L_FRAME32k ); } @@ -262,11 +262,11 @@ void swb_pre_proc_fx( ELSE /* 48 kHz */ { /* 48kHz sampled processing needs review of FD2 memory handling/Q-factors */ - IF( EQ_16(st_fx->codec_mode,MODE1)) + IF( EQ_16( st_fx->codec_mode, MODE1 ) ) { test(); test(); - IF( NE_16(st_fx->extl,SWB_BWE)&&NE_16(st_fx->extl,FB_BWE)&&EQ_16(st_fx->core,ACELP_CORE)) + IF( NE_16( st_fx->extl, SWB_BWE ) && NE_16( st_fx->extl, FB_BWE ) && EQ_16( st_fx->core, ACELP_CORE ) ) { /* move the resampling out of the TDBWE path as new_swb_speech is not needed for TDBWE. */ Copy( input_fx, hBWE_FD->old_fdbwe_speech_fx, L_FRAME48k ); @@ -274,21 +274,21 @@ void swb_pre_proc_fx( ELSE { test(); - IF( NE_16(st_fx->last_extl,SWB_BWE)&&NE_16(st_fx->last_extl,FB_BWE)) + IF( NE_16( st_fx->last_extl, SWB_BWE ) && NE_16( st_fx->last_extl, FB_BWE ) ) { /* resample 48 kHz to 32kHz */ - IF( EQ_16(st_fx->last_bwidth,FB)) + IF( EQ_16( st_fx->last_bwidth, FB ) ) { inner_frame = L_FRAME48k; inner_Fs = 48000; - Copy(hBWE_FD->old_fdbwe_speech_fx, new_swb_speech_fx, L_FRAME48k ); + Copy( hBWE_FD->old_fdbwe_speech_fx, new_swb_speech_fx, L_FRAME48k ); } ELSE { inner_frame = L_FRAME32k; inner_Fs = 32000; - decimate_2_over_3_allpass_fx(hBWE_FD->old_fdbwe_speech_fx, L_FRAME48k, new_swb_speech_fx, hBWE_TD->dec_2_over_3_mem_fx, allpass_poles_3_ov_2, - decimate_3_ov_2_lowpass_num_fx, decimate_3_ov_2_lowpass_den_fx, hBWE_TD->dec_2_over_3_mem_lp_fx ); + decimate_2_over_3_allpass_fx( hBWE_FD->old_fdbwe_speech_fx, L_FRAME48k, new_swb_speech_fx, hBWE_TD->dec_2_over_3_mem_fx, allpass_poles_3_ov_2, + decimate_3_ov_2_lowpass_num_fx, decimate_3_ov_2_lowpass_den_fx, hBWE_TD->dec_2_over_3_mem_lp_fx ); } Sample_Delay_SWB_BWE = NS2SA_fx2( inner_Fs, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ); @@ -300,28 +300,28 @@ void swb_pre_proc_fx( move16(); } /* resample 48 kHz to 32kHz */ - IF( EQ_16(st_fx->bwidth,FB)) + IF( EQ_16( st_fx->bwidth, FB ) ) { Copy( input_fx, new_swb_speech_fx, L_FRAME48k ); } ELSE { decimate_2_over_3_allpass_fx( input_fx, L_FRAME48k, new_swb_speech_fx, hBWE_TD->dec_2_over_3_mem_fx, allpass_poles_3_ov_2, - decimate_3_ov_2_lowpass_num_fx, decimate_3_ov_2_lowpass_den_fx, hBWE_TD->dec_2_over_3_mem_lp_fx ); + decimate_3_ov_2_lowpass_num_fx, decimate_3_ov_2_lowpass_den_fx, hBWE_TD->dec_2_over_3_mem_lp_fx ); } } } ELSE { /* resample 48 kHz to 32kHz */ - IF( EQ_16(st_fx->bwidth,FB)) + IF( EQ_16( st_fx->bwidth, FB ) ) { Copy( input_fx, new_swb_speech_fx, L_FRAME48k ); } ELSE { decimate_2_over_3_allpass_fx( input_fx, L_FRAME48k, new_swb_speech_fx, hBWE_TD->dec_2_over_3_mem_fx, allpass_poles_3_ov_2, - decimate_3_ov_2_lowpass_num_fx, decimate_3_ov_2_lowpass_den_fx, hBWE_TD->dec_2_over_3_mem_lp_fx ); + decimate_3_ov_2_lowpass_num_fx, decimate_3_ov_2_lowpass_den_fx, hBWE_TD->dec_2_over_3_mem_lp_fx ); } } } @@ -331,30 +331,29 @@ void swb_pre_proc_fx( test(); test(); test(); - IF( ( EQ_16(st_fx->core, ACELP_CORE)&&NE_16(st_fx->extl,SWB_BWE_HIGHRATE)&&NE_16(st_fx->extl,FB_BWE_HIGHRATE)) - || ( ( EQ_32(st_fx->total_brate, 9600) || st_fx->rf_mode != 0 ) && EQ_16(st_fx->bwidth, SWB) ) ) + IF( ( EQ_16( st_fx->core, ACELP_CORE ) && NE_16( st_fx->extl, SWB_BWE_HIGHRATE ) && NE_16( st_fx->extl, FB_BWE_HIGHRATE ) ) || ( ( EQ_32( st_fx->total_brate, 9600 ) || st_fx->rf_mode != 0 ) && EQ_16( st_fx->bwidth, SWB ) ) ) { - IF( EQ_16(st_fx->L_frame, L_FRAME)) + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { - startB= 34; - endB= 14; + startB = 34; + endB = 14; FOR( ts = 0; ts < CLDFB_NO_COL_MAX; ts++ ) { uB = 0; FOR( nB = startB; nB > endB; nB-- ) { move16(); - realBufferFlipped[ts][uB] = realBuffer[ts][nB]; - if (s_and(ts, 1) != 0) + realBufferFlipped[ts][uB] = realBuffer[ts][nB]; + if ( s_and( ts, 1 ) != 0 ) { - realBufferFlipped[ts][uB] = L_negate(realBufferFlipped[ts][uB]); + realBufferFlipped[ts][uB] = L_negate( realBufferFlipped[ts][uB] ); } - imagBufferFlipped[ts][uB] = imagBuffer[ts][nB]; - if (s_and(ts, 1) == 0) + imagBufferFlipped[ts][uB] = imagBuffer[ts][nB]; + if ( s_and( ts, 1 ) == 0 ) { - imagBufferFlipped[ts][uB] = L_negate(imagBufferFlipped[ts][uB]); + imagBufferFlipped[ts][uB] = L_negate( imagBufferFlipped[ts][uB] ); } - uB = add(uB, 1); /* uB ++ */ + uB = add( uB, 1 ); /* uB ++ */ } } } @@ -367,9 +366,9 @@ void swb_pre_proc_fx( uB = 0; FOR( nB = startB; nB > endB; nB-- ) { - realBufferFlipped[ts][uB] = L_negate(realBuffer[ts][nB]); - imagBufferFlipped[ts][uB] = imagBuffer[ts][nB]; - uB = add(uB, 1); /* uB ++ */ + realBufferFlipped[ts][uB] = L_negate( realBuffer[ts][nB] ); + imagBufferFlipped[ts][uB] = imagBuffer[ts][nB]; + uB = add( uB, 1 ); /* uB ++ */ } } } @@ -377,29 +376,29 @@ void swb_pre_proc_fx( /* Highband energy computation for gain shape control in case of bandwidth switching fix*/ { CldfbHB_ener = 0; - FOR (nB = 0; nB < 10; nB++) + FOR( nB = 0; nB < 10; nB++ ) { - FOR (ts = 0; ts < CLDFB_NO_COL_MAX; ts++) + FOR( ts = 0; ts < CLDFB_NO_COL_MAX; ts++ ) { - realQ_neg1 = extract_l(L_shr(realBufferFlipped[ts][nB], 31-(15+cldfbScale->hb_scale)+1)); - imagQ_neg1 = extract_l(L_shr(imagBufferFlipped[ts][nB], 31-(15+cldfbScale->hb_scale)+1)); /* Q(-1), headroom needed */ + realQ_neg1 = extract_l( L_shr( realBufferFlipped[ts][nB], 31 - ( 15 + cldfbScale->hb_scale ) + 1 ) ); + imagQ_neg1 = extract_l( L_shr( imagBufferFlipped[ts][nB], 31 - ( 15 + cldfbScale->hb_scale ) + 1 ) ); /* Q(-1), headroom needed */ #ifdef BASOP_NOGLOB - CldfbHB_ener = L_mac0_o(CldfbHB_ener, realQ_neg1, realQ_neg1, &Overflow); - CldfbHB_ener = L_mac0_o(CldfbHB_ener, imagQ_neg1, imagQ_neg1, &Overflow); /* Q(-2) */ + CldfbHB_ener = L_mac0_o( CldfbHB_ener, realQ_neg1, realQ_neg1, &Overflow ); + CldfbHB_ener = L_mac0_o( CldfbHB_ener, imagQ_neg1, imagQ_neg1, &Overflow ); /* Q(-2) */ #else - CldfbHB_ener = L_mac0(CldfbHB_ener, realQ_neg1, realQ_neg1); - CldfbHB_ener = L_mac0(CldfbHB_ener, imagQ_neg1, imagQ_neg1); /* Q(-2) */ + CldfbHB_ener = L_mac0( CldfbHB_ener, realQ_neg1, realQ_neg1 ); + CldfbHB_ener = L_mac0( CldfbHB_ener, imagQ_neg1, imagQ_neg1 ); /* Q(-2) */ #endif } } - exp = norm_l(CldfbHB_ener); - CldfbHB_ener = L_shl(CldfbHB_ener, exp); /* CldfbHB_ener = CldfbHB_fl*2^(exp) */ - Cldfbtemp1 = (Log2_norm_lc(CldfbHB_ener)); - Cldfbtemp1 = add(shr(Cldfbtemp1, 6), shl(sub(30, sub(exp, 2)), 9));/* Log2_norm_lc(CldfbHB_ener) = 2^15*(log2(CldfbHB_ener/2^30)) = 2^15*(log2(CldfbHB_fl*(2^-2)*2^exp/2^30)) = 2^15*(log2(CldfbHB_fl) + exp-2-30) => 2^(-6)*l2nc + 2^9(20-(exp-2)) = 2^9*log2(CldfbHB_fl), Q9 */ - CldfbHB_ener = L_mult(sub(Cldfbtemp1, 1741/*3.401 Q9*/), 3495); /* 3495 = Q19 log10(2)*0.1/log10(32768), Q = 19+9+1 = 29 */ - hBWE_TD->cldfbHBLT = mac_r(CldfbHB_ener, 29491/*0.9 Q15*/, hBWE_TD->cldfbHBLT); /* cldfbHBLT is in Q13 */ + exp = norm_l( CldfbHB_ener ); + CldfbHB_ener = L_shl( CldfbHB_ener, exp ); /* CldfbHB_ener = CldfbHB_fl*2^(exp) */ + Cldfbtemp1 = ( Log2_norm_lc( CldfbHB_ener ) ); + Cldfbtemp1 = add( shr( Cldfbtemp1, 6 ), shl( sub( 30, sub( exp, 2 ) ), 9 ) ); /* Log2_norm_lc(CldfbHB_ener) = 2^15*(log2(CldfbHB_ener/2^30)) = 2^15*(log2(CldfbHB_fl*(2^-2)*2^exp/2^30)) = 2^15*(log2(CldfbHB_fl) + exp-2-30) => 2^(-6)*l2nc + 2^9(20-(exp-2)) = 2^9*log2(CldfbHB_fl), Q9 */ + CldfbHB_ener = L_mult( sub( Cldfbtemp1, 1741 /*3.401 Q9*/ ), 3495 ); /* 3495 = Q19 log10(2)*0.1/log10(32768), Q = 19+9+1 = 29 */ + hBWE_TD->cldfbHBLT = mac_r( CldfbHB_ener, 29491 /*0.9 Q15*/, hBWE_TD->cldfbHBLT ); /* cldfbHBLT is in Q13 */ } cldfbSynthesisFiltering( st_fx->cldfbSynTd, realBufferFlipped, imagBufferFlipped, cldfbScale, shb_speech_fx, 0, CLDFB_NO_COL_MAX, cldfbWorkBuffer ); @@ -407,7 +406,7 @@ void swb_pre_proc_fx( test(); test(); - IF( NE_16(st_fx->extl, WB_TBE)&&NE_16(st_fx->extl,SWB_TBE)&&NE_16(st_fx->extl,FB_TBE)) + IF( NE_16( st_fx->extl, WB_TBE ) && NE_16( st_fx->extl, SWB_TBE ) && NE_16( st_fx->extl, FB_TBE ) ) { /* Update the previous superwideband speech buffer in case of a SWB_BWE frame - this code is in swb_tbe_enc */ delay = L_LOOK_16k + L_SUBFR16k; @@ -416,37 +415,36 @@ void swb_pre_proc_fx( } ELSE { - IF( EQ_16(st_fx->bwidth, FB)||EQ_16(st_fx->core,ACELP_CORE)) + IF( EQ_16( st_fx->bwidth, FB ) || EQ_16( st_fx->core, ACELP_CORE ) ) { - set16_fx(hBWE_TD->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k ); - set16_fx( shb_speech_fx, 0, L_FRAME16k ); /* shb_speech for FB/SWB BWE_HIGHRATE is not used at 64kbps */ + set16_fx( hBWE_TD->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k ); + set16_fx( shb_speech_fx, 0, L_FRAME16k ); /* shb_speech for FB/SWB BWE_HIGHRATE is not used at 64kbps */ } ELSE { /* flip the spectrm */ Copy( new_swb_speech_fx, spchTmp_fx, L_FRAME32k ); - FOR( i = 0; i < L_FRAME32k; i = i+2 ) + FOR( i = 0; i < L_FRAME32k; i = i + 2 ) { - spchTmp_fx[i] = negate(spchTmp_fx[i]); + spchTmp_fx[i] = negate( spchTmp_fx[i] ); } Decimate_allpass_steep_fx( spchTmp_fx, hBWE_TD->state_ana_filt_shb_fx, L_FRAME32k, shb_speech_fx ); - Copy( shb_speech_fx + L_FRAME16k - (L_LOOK_16k + L_SUBFR16k), hBWE_TD->old_speech_shb_fx, L_LOOK_16k + L_SUBFR16k ); + Copy( shb_speech_fx + L_FRAME16k - ( L_LOOK_16k + L_SUBFR16k ), hBWE_TD->old_speech_shb_fx, L_LOOK_16k + L_SUBFR16k ); } /* Reset CLDFB synthesis buffer */ - set16_fx( st_fx->cldfbSynTd->FilterStates, 0, st_fx->cldfbSynTd->p_filter_length + st_fx->cldfbSynTd->no_channels*st_fx->cldfbSynTd->no_col ); + set16_fx( st_fx->cldfbSynTd->FilterStates, 0, st_fx->cldfbSynTd->p_filter_length + st_fx->cldfbSynTd->no_channels * st_fx->cldfbSynTd->no_col ); } IF( st_fx->last_extl == -1 ) { - delay = NS2SA(st_fx->input_Fs, DELAY_FIR_RESAMPL_NS); + delay = NS2SA( st_fx->input_Fs, DELAY_FIR_RESAMPL_NS ); FOR( i = 0; i < delay; i++ ) { - shb_speech_fx[i] = mult_r( mult_r(i, 983/*0.03f Q15*/), shb_speech_fx[2*delay-1-i] ); + shb_speech_fx[i] = mult_r( mult_r( i, 983 /*0.03f Q15*/ ), shb_speech_fx[2 * delay - 1 - i] ); } } return; } - diff --git a/lib_enc/swb_tbe_enc.c b/lib_enc/swb_tbe_enc.c index d84c6a310..943fe458b 100644 --- a/lib_enc/swb_tbe_enc.c +++ b/lib_enc/swb_tbe_enc.c @@ -1241,7 +1241,7 @@ void swb_tbe_enc( if ( st->tec_tfa == 1 ) { - tfaCalcEnv( shb_frame, st->tfa_enr_flt); + tfaCalcEnv( shb_frame, st->tfa_enr_flt ); } /* If there's a big difference in the power of gains away from the peak gain */ diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index 2191933d8..b4e93c1d3 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -9,77 +9,81 @@ //#include "prot_fx.h" #include "rom_com_fx.h" #include "rom_com.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ #include "stl.h" /*-----------------------------------------------------------------* -* Local functions -*-----------------------------------------------------------------*/ -static void return_M_Least_fx_GainFrame( const Word32* inp, - const Word32* codebook, const Word16 num_grp, - const Word16 interNum, Word16* least ); + * Local functions + *-----------------------------------------------------------------*/ +static void return_M_Least_fx_GainFrame( const Word32 *inp, + const Word32 *codebook, + const Word16 num_grp, + const Word16 interNum, + Word16 *least ); -static void singlevectortest_gain_fx( const Word32* inp, const Word16 dimen, - const Word16 cb_size, Word16* index, - Word32* recon, const Word32* codebook ); +static void singlevectortest_gain_fx( const Word32 *inp, const Word16 dimen, const Word16 cb_size, Word16 *index, Word32 *recon, const Word32 *codebook ); -static void determine_gain_weights_fx( const Word32* gain, Word16* weights, - const Word16 dims ); +static void determine_gain_weights_fx( const Word32 *gain, Word16 *weights, const Word16 dims ); -static void QuantizeSHBsubgains_fx( Encoder_State* st_fx, Word16* subgains, const Word16 extl ); +static void QuantizeSHBsubgains_fx( Encoder_State *st_fx, Word16 *subgains, const Word16 extl ); -static void QuantizeSHBframegain_fx( Encoder_State* st_fx, Word32* GainFrame, const Word16 extl, Word32 extl_brate - ,Word16 *rf_gainFrame_ind); +static void QuantizeSHBframegain_fx( Encoder_State *st_fx, Word32 *GainFrame, const Word16 extl, Word32 extl_brate, Word16 *rf_gainFrame_ind ); -static Word16 closest_centroid_fx( const Word16* data, const Word16* weights, - const Word16* quantizer, const Word16 centroids, const Word16 length ); +static Word16 closest_centroid_fx( const Word16 *data, const Word16 *weights, const Word16 *quantizer, const Word16 centroids, const Word16 length ); -static Word16 closest_centroid_lc_fx( const Word16* data, const Word16* quantizer, const Word16 centroids ); +static Word16 closest_centroid_lc_fx( const Word16 *data, const Word16 *quantizer, const Word16 centroids ); static void EstimateSHBFrameGain_fx( const Word16 length, - const Word16* oriSHB, const Word16 Q_oriSHB, - const Word16* synSHB, const Word16 Q_synSHB, Word16* subgain, - Word32* GainFrame, const Word16* win_shb, const Word16* subwin_shb, const Word16 n_subfr_saturation ); + const Word16 *oriSHB, + const Word16 Q_oriSHB, + const Word16 *synSHB, + const Word16 Q_synSHB, + Word16 *subgain, + Word32 *GainFrame, + const Word16 *win_shb, + const Word16 *subwin_shb, + const Word16 n_subfr_saturation ); static void EstimateSHBGainShape_fx( const Word16 length, - const Word16* oriSHB, const Word16 Q_oriSHB, - const Word16* synSHB, const Word16 Q_synSHB, - Word16* subgain, const Word16* subwin, Word16* n_subfr_saturation ); + const Word16 *oriSHB, + const Word16 Q_oriSHB, + const Word16 *synSHB, + const Word16 Q_synSHB, + Word16 *subgain, + const Word16 *subwin, + Word16 *n_subfr_saturation ); static Word32 pow_off_pk_fx( Word16 a[], Word16 len, Word16 step ); static void find_max_mem_enc( Encoder_State *st_fx, Word16 *n_mem, Word16 *n_mem2 ); -static void rescale_genSHB_mem_enc( Encoder_State* st_fx, Word16 sf ); -static void find_max_mem_wb_enc( Encoder_State* st_fx, Word16* n_mem ); -static void rescale_genWB_mem_enc( Encoder_State* st_fx, Word16 sf ); +static void rescale_genSHB_mem_enc( Encoder_State *st_fx, Word16 sf ); +static void find_max_mem_wb_enc( Encoder_State *st_fx, Word16 *n_mem ); +static void rescale_genWB_mem_enc( Encoder_State *st_fx, Word16 sf ); static void Quant_lower_LSF_fx( const Word16 lsf[], Word16 lsf_q[], - Word16 lsf_idx[]); - -static Word16 Quant_mirror_point_fx( const Word16 lsf[], const Word16 lsf_q[], - Word16* m ); -static Word16 Find_LSF_grid_fx( const Word16 lsf[], Word16 lsf_q[], - const Word16 m ); -static void Quant_BWE_LSF_fx( Encoder_State* st_fx, const Word16 lsp_shb[], Word16 Q_lsfs[]); -static void Quant_shb_ener_sf_fx(Encoder_State *st_fx, Word32 *shb_ener_sf_fx_32, Word16 Q_shb); -static void Quant_shb_res_gshape_fx(Encoder_State *st_fx, Word16 *shb_res_gshape_fx); - -static void gainFrSmooth_En_fx(Encoder_State *st_fx, - Word16 *shb_frame_fx, - const Word16 *lpc_shb_fx, - const Word16 *lsp_shb_fx, - Word16 *MA_lsp_shb_spacing, - Word16 *frGainAttenuate, - Word16 *frGainSmoothEn - ); + Word16 lsf_idx[] ); + +static Word16 Quant_mirror_point_fx( const Word16 lsf[], const Word16 lsf_q[], Word16 *m ); +static Word16 Find_LSF_grid_fx( const Word16 lsf[], Word16 lsf_q[], const Word16 m ); +static void Quant_BWE_LSF_fx( Encoder_State *st_fx, const Word16 lsp_shb[], Word16 Q_lsfs[] ); +static void Quant_shb_ener_sf_fx( Encoder_State *st_fx, Word32 *shb_ener_sf_fx_32, Word16 Q_shb ); +static void Quant_shb_res_gshape_fx( Encoder_State *st_fx, Word16 *shb_res_gshape_fx ); + +static void gainFrSmooth_En_fx( Encoder_State *st_fx, + Word16 *shb_frame_fx, + const Word16 *lpc_shb_fx, + const Word16 *lsp_shb_fx, + Word16 *MA_lsp_shb_spacing, + Word16 *frGainAttenuate, + Word16 *frGainSmoothEn ); /*-------------------------------------------------------------------* @@ -90,8 +94,7 @@ static void gainFrSmooth_En_fx(Encoder_State *st_fx, void find_max_mem_enc( Encoder_State *st_fx, Word16 *n_mem, - Word16 *n_mem2 -) + Word16 *n_mem2 ) { Word16 i; Word16 n_mem_32; @@ -108,73 +111,74 @@ void find_max_mem_enc( } /* decimate all-pass steep memory */ - FOR ( i = 0; i < (2*ALLPASSSECTIONS_STEEP+1); i++ ) + FOR( i = 0; i < ( 2 * ALLPASSSECTIONS_STEEP + 1 ); i++ ) { tempQ15 = abs_s( hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i] ); - max = s_max(max, tempQ15); + max = s_max( max, tempQ15 ); } /* -- keep norm of state_lpc_syn_fx, state_syn_shbexc_fx, and mem_stp_swb_fx separately for 24.4 and 32kbps ----*/ /* findMaxMem2() inside tbe com */ - FOR ( i = 0; i < LPC_SHB_ORDER; i++ ) + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { tempQ15 = abs_s( hBWE_TD->state_lpc_syn_fx[i] ); - max2 = s_max(max2, tempQ15); + max2 = s_max( max2, tempQ15 ); } /* findMaxMem2() inside tbe com */ - FOR ( i = 0; i < L_SHB_LAHEAD; i++ ) + FOR( i = 0; i < L_SHB_LAHEAD; i++ ) { tempQ15 = abs_s( hBWE_TD->state_syn_shbexc_fx[i] ); - max2 = s_max(max2, tempQ15); + max2 = s_max( max2, tempQ15 ); } /* findMaxMem2() inside tbe com */ - FOR ( i = 0; i < LPC_SHB_ORDER; i++ ) + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { tempQ15 = abs_s( hBWE_TD->mem_stp_swb_fx[i] ); - max2 = s_max(max2, tempQ15); + max2 = s_max( max2, tempQ15 ); } /* for total_brate > 16.4kbps, use n_mem2; else account for the max2 for n_mem calculation */ - *n_mem2 = norm_s(max2); - if(max2 == 0) *n_mem2 = 15; - if(LT_32(st_fx->total_brate, ACELP_24k40)) + *n_mem2 = norm_s( max2 ); + if ( max2 == 0 ) + *n_mem2 = 15; + if ( LT_32( st_fx->total_brate, ACELP_24k40 ) ) { - max = s_max(max, max2); + max = s_max( max, max2 ); } /* de-emph and pre-emph memory */ tempQ15 = abs_s( hBWE_TD->tbe_demph_fx ); - max = s_max(max, tempQ15); + max = s_max( max, tempQ15 ); tempQ15 = abs_s( hBWE_TD->tbe_premph_fx ); - max = s_max(max, tempQ15); + max = s_max( max, tempQ15 ); - IF( EQ_16(st_fx->extl, FB_TBE)) + IF( EQ_16( st_fx->extl, FB_TBE ) ) { - FOR ( i = 0; i < LPC_SHB_ORDER; i++ ) + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { tempQ15 = abs_s( hBWE_TD->fb_state_lpc_syn_fx[i] ); - max = s_max(max, tempQ15); + max = s_max( max, tempQ15 ); } /* FB de-emph memory */ - tempQ15 = abs_s( hBWE_TD->fb_tbe_demph_fx); - max = s_max(max, tempQ15); + tempQ15 = abs_s( hBWE_TD->fb_tbe_demph_fx ); + max = s_max( max, tempQ15 ); } /* estimate the norm for 16-bit memories */ *n_mem = norm_s( max ); - if( max == 0 ) + if ( max == 0 ) { *n_mem = 15; } /* estimate the norm for 32-bit memories */ - Lmax = L_abs( hBWE_TD->mem_csfilt_fx[0] ); /* only element [0] is used in env. shaping */ + Lmax = L_abs( hBWE_TD->mem_csfilt_fx[0] ); /* only element [0] is used in env. shaping */ n_mem_32 = norm_l( Lmax ); - if( Lmax == 0 ) + if ( Lmax == 0 ) { n_mem_32 = 31; } @@ -189,33 +193,33 @@ void find_max_mem_enc( * * Rescale genSHB memories *-------------------------------------------------------------------*/ -void rescale_genSHB_mem_enc( Encoder_State* st_fx, Word16 sf ) +void rescale_genSHB_mem_enc( Encoder_State *st_fx, Word16 sf ) { Word16 i; TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; - FOR( i = 0; i old_bwe_exc_extended_fx[i] = shl( hBWE_TD->old_bwe_exc_extended_fx[i], sf ); move16(); } - FOR ( i = 0; i < 7; i++ ) + FOR( i = 0; i < 7; i++ ) { - hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i] = shl( hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i], sf ); + hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i] = shl( hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i], sf ); move16(); } /* -- Apply memory scaling for 13.2 and 16.4k bps using sf ----*/ - IF(LT_32(st_fx->total_brate, ACELP_24k40)) + IF( LT_32( st_fx->total_brate, ACELP_24k40 ) ) { - FOR ( i = 0; i < LPC_SHB_ORDER; i++ ) + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { hBWE_TD->state_lpc_syn_fx[i] = shl( hBWE_TD->state_lpc_syn_fx[i], sf ); move16(); } - FOR ( i = 0; i < L_SHB_LAHEAD; i++ ) + FOR( i = 0; i < L_SHB_LAHEAD; i++ ) { hBWE_TD->state_syn_shbexc_fx[i] = shl( hBWE_TD->state_syn_shbexc_fx[i], sf ); move16(); @@ -229,51 +233,50 @@ void rescale_genSHB_mem_enc( Encoder_State* st_fx, Word16 sf ) move16(); hBWE_TD->tbe_premph_fx = shl_r( hBWE_TD->tbe_premph_fx, sf ); move16(); - } -void find_max_mem_wb_enc( Encoder_State* st_fx, Word16* n_mem ) +void find_max_mem_wb_enc( Encoder_State *st_fx, Word16 *n_mem ) { Word16 i; Word16 n_mem_32; - Word16 max =0; - Word32 Lmax =0; + Word16 max = 0; + Word32 Lmax = 0; TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; - FOR ( i = 0; i < NL_BUFF_OFFSET; i++ ) + FOR( i = 0; i < NL_BUFF_OFFSET; i++ ) max = s_max( max, abs_s( hBWE_TD->old_bwe_exc_extended_fx[i] ) ); - FOR ( i = 0; i < 7; i++ ) + FOR( i = 0; i < 7; i++ ) { - IF ( abs_s( hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i] ) > max ) + IF( abs_s( hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i] ) > max ) max = abs_s( hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i] ); } - FOR ( i = 0; i < 7; i++ ) + FOR( i = 0; i < 7; i++ ) { - IF ( abs_s( hBWE_TD->mem_genSHBexc_filt_down_wb2_fx[i] ) > max ) + IF( abs_s( hBWE_TD->mem_genSHBexc_filt_down_wb2_fx[i] ) > max ) max = abs_s( hBWE_TD->mem_genSHBexc_filt_down_wb2_fx[i] ); } - FOR ( i = 0; i < 7; i++ ) + FOR( i = 0; i < 7; i++ ) { - IF ( abs_s( hBWE_TD->mem_genSHBexc_filt_down_wb3_fx[i] ) > max ) + IF( abs_s( hBWE_TD->mem_genSHBexc_filt_down_wb3_fx[i] ) > max ) max = abs_s( hBWE_TD->mem_genSHBexc_filt_down_wb3_fx[i] ); } - FOR ( i = 0; i < 10; i++ ) + FOR( i = 0; i < 10; i++ ) { - IF ( abs_s( hBWE_TD->state_lpc_syn_fx[i] ) > max ) + IF( abs_s( hBWE_TD->state_lpc_syn_fx[i] ) > max ) max = abs_s( hBWE_TD->state_lpc_syn_fx[i] ); } - FOR ( i = 0; i < 5; i++ ) + FOR( i = 0; i < 5; i++ ) { - IF ( abs_s( hBWE_TD->state_syn_shbexc_fx[i] ) > max ) + IF( abs_s( hBWE_TD->state_syn_shbexc_fx[i] ) > max ) max = abs_s( hBWE_TD->state_syn_shbexc_fx[i] ); } - IF ( max == 0 ) + IF( max == 0 ) { *n_mem = 15; move16(); @@ -284,14 +287,14 @@ void find_max_mem_wb_enc( Encoder_State* st_fx, Word16* n_mem ) move16(); } - FOR ( i = 0; i < 2; i++ ) + FOR( i = 0; i < 2; i++ ) { - IF ( L_abs( hBWE_TD->mem_csfilt_fx[i] ) > Lmax ) + IF( L_abs( hBWE_TD->mem_csfilt_fx[i] ) > Lmax ) Lmax = L_abs( hBWE_TD->mem_csfilt_fx[i] ); } - IF ( Lmax == 0 ) + IF( Lmax == 0 ) { n_mem_32 = 31; move16(); @@ -306,48 +309,48 @@ void find_max_mem_wb_enc( Encoder_State* st_fx, Word16* n_mem ) *n_mem = s_max( *n_mem, 0 ); } -void rescale_genWB_mem_enc( Encoder_State* st_fx, Word16 sf ) +void rescale_genWB_mem_enc( Encoder_State *st_fx, Word16 sf ) { Word16 i; TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; - FOR ( i = 0; i < NL_BUFF_OFFSET; i++ ) + FOR( i = 0; i < NL_BUFF_OFFSET; i++ ) { hBWE_TD->old_bwe_exc_extended_fx[i] = shl( hBWE_TD->old_bwe_exc_extended_fx[i], sf ); move16(); } - FOR ( i = 0; i < 10; i++ ) + FOR( i = 0; i < 10; i++ ) { hBWE_TD->state_lpc_syn_fx[i] = shl( hBWE_TD->state_lpc_syn_fx[i], sf ); move16(); } - FOR ( i = 0; i < 5; i++ ) + FOR( i = 0; i < 5; i++ ) { hBWE_TD->state_syn_shbexc_fx[i] = shl( hBWE_TD->state_syn_shbexc_fx[i], sf ); move16(); } - FOR ( i = 0; i < 7; i++ ) + FOR( i = 0; i < 7; i++ ) { hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i] = shl( hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i], sf ); move16(); } - FOR ( i = 0; i < 7; i++ ) + FOR( i = 0; i < 7; i++ ) { hBWE_TD->mem_genSHBexc_filt_down_wb2_fx[i] = shl( hBWE_TD->mem_genSHBexc_filt_down_wb2_fx[i], sf ); move16(); } - FOR ( i = 0; i < 7; i++ ) + FOR( i = 0; i < 7; i++ ) { hBWE_TD->mem_genSHBexc_filt_down_wb3_fx[i] = shl( hBWE_TD->mem_genSHBexc_filt_down_wb3_fx[i], sf ); move16(); } - FOR ( i = 0; i < 2; i++ ) + FOR( i = 0; i < 2; i++ ) { hBWE_TD->mem_csfilt_fx[i] = L_shl( hBWE_TD->mem_csfilt_fx[i], sf ); move32(); @@ -361,7 +364,7 @@ void rescale_genWB_mem_enc( Encoder_State* st_fx, Word16 sf ) * Initialize SWB buffers *-------------------------------------------------------------------*/ void InitSWBencBuffer_fx( - Encoder_State* st_fx /* i/o: SHB encoder structure */ + Encoder_State *st_fx /* i/o: SHB encoder structure */ ) { Word16 i; @@ -373,9 +376,9 @@ void InitSWBencBuffer_fx( hBWE_TD->bwe_seed[1] = 59; move16(); set16_fx( hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); - hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l(0); + hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 ); - set16_fx(hBWE_TD->state_ana_filt_shb_fx, 0, (2*ALLPASSSECTIONS_STEEP+1)); + set16_fx( hBWE_TD->state_ana_filt_shb_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); set32_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx[0], 0, 4 ); set32_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx[1], 0, 4 ); set32_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx[2], 0, 4 ); @@ -384,28 +387,28 @@ void InitSWBencBuffer_fx( move16(); set16_fx( hBWE_TD->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k ); - set16_fx(hBWE_TD->old_speech_wb_fx, 0, (L_LOOK_12k8 + L_SUBFR) * 5 / 16); - set16_fx(hBWE_TD->old_input_fhb_fx, 0, NS2SA(48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS) - L_FRAME48k / 2); - - //IVAS_CODE - //set_f(hBWE_TD->mem_shb_res, 0.0f, MAX_LEN_MA_FILTER); - //set_f(hBWE_TD->old_EnvSHBres, 0.0f, L_FRAME4k); - //hBWE_TD->old_mean_EnvSHBres = 0.0f; - //hBWE_TD->prev_enr_EnvSHBres = 1.0f; - //hBWE_TD->prev_shb_env_tilt = 0.0f; - //hBWE_TD->prev_pow_exc16kWhtnd = 1.0f; - //hBWE_TD->prev_mix_factor = 1.0f; - //hBWE_TD->prev_Env_error = 0.0f; - set16_fx(hBWE_TD->prev_lsp_shb_fx, 0, 10 ); - - hBWE_TD->cldfbHBLT = 8192/*1.0f Q13*/; + set16_fx( hBWE_TD->old_speech_wb_fx, 0, ( L_LOOK_12k8 + L_SUBFR ) * 5 / 16 ); + set16_fx( hBWE_TD->old_input_fhb_fx, 0, NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) - L_FRAME48k / 2 ); + + // IVAS_CODE + // set_f(hBWE_TD->mem_shb_res, 0.0f, MAX_LEN_MA_FILTER); + // set_f(hBWE_TD->old_EnvSHBres, 0.0f, L_FRAME4k); + // hBWE_TD->old_mean_EnvSHBres = 0.0f; + // hBWE_TD->prev_enr_EnvSHBres = 1.0f; + // hBWE_TD->prev_shb_env_tilt = 0.0f; + // hBWE_TD->prev_pow_exc16kWhtnd = 1.0f; + // hBWE_TD->prev_mix_factor = 1.0f; + // hBWE_TD->prev_Env_error = 0.0f; + set16_fx( hBWE_TD->prev_lsp_shb_fx, 0, 10 ); + + hBWE_TD->cldfbHBLT = 8192 /*1.0f Q13*/; move16(); hBWE_TD->prev_gainFr_SHB_fx = 0; - set16_fx(hBWE_TD->lsp_shb_slow_interpl_fx, 0, LPC_SHB_ORDER); - set16_fx(hBWE_TD->lsp_shb_fast_interpl_fx, 0, LPC_SHB_ORDER); - set16_fx(hBWE_TD->shb_inv_filt_mem_fx, 0, LPC_SHB_ORDER); - set16_fx(hBWE_TD->lsp_shb_spacing_fx, 3277, 3); - set16_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, 0, 4 ); + set16_fx( hBWE_TD->lsp_shb_slow_interpl_fx, 0, LPC_SHB_ORDER ); + set16_fx( hBWE_TD->lsp_shb_fast_interpl_fx, 0, LPC_SHB_ORDER ); + set16_fx( hBWE_TD->shb_inv_filt_mem_fx, 0, LPC_SHB_ORDER ); + set16_fx( hBWE_TD->lsp_shb_spacing_fx, 3277, 3 ); + set16_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, 0, 4 ); hBWE_TD->prev_swb_GainShape_fx = 0; move16(); @@ -415,7 +418,7 @@ void InitSWBencBuffer_fx( move16(); hBWE_TD->prev_Q_bwe_exc_fb = 51; move16(); - set16_fx(hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER); + set16_fx( hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); hBWE_TD->fb_tbe_demph_fx = 0; move16(); hBWE_TD->tilt_mem_fx = 0; @@ -423,37 +426,36 @@ void InitSWBencBuffer_fx( hBWE_TD->prev_coder_type = GENERIC; move16(); - set16_fx(hBWE_TD->prev_lsf_diff_fx, 16384, LPC_SHB_ORDER - 2); + set16_fx( hBWE_TD->prev_lsf_diff_fx, 16384, LPC_SHB_ORDER - 2 ); hBWE_TD->prev_tilt_para_fx = 0; move16(); - set16_fx(hBWE_TD->cur_sub_Aq_fx, 0, M + 1); + set16_fx( hBWE_TD->cur_sub_Aq_fx, 0, M + 1 ); /* TD BWE post-processing */ hBWE_TD->ptr_mem_stp_swb_fx = hBWE_TD->mem_stp_swb_fx + LPC_SHB_ORDER - 1; - set16_fx(hBWE_TD->mem_zero_swb_fx, 0, LPC_SHB_ORDER); + set16_fx( hBWE_TD->mem_zero_swb_fx, 0, LPC_SHB_ORDER ); - FOR(i = 0; i < LPC_SHB_ORDER; i++) + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { hBWE_TD->swb_lsp_prev_interp_fx[i] = swb_lsp_prev_interp_init[i]; } - set16_fx(hBWE_TD->dec_2_over_3_mem_fx, 0, 12); - set16_fx(hBWE_TD->dec_2_over_3_mem_lp_fx, 0, 6); - + set16_fx( hBWE_TD->dec_2_over_3_mem_fx, 0, 12 ); + set16_fx( hBWE_TD->dec_2_over_3_mem_lp_fx, 0, 6 ); hBWE_TD->prev_fb_energy_fx_Q = 0; move16(); - - + + // TV2TV IVAS_CODE -> To be verify if it has to be moved to hBWE_TD st_fx->prev_Q_bwe_exc = 31; move16(); st_fx->prev_Q_bwe_syn = 31; move16(); - set16_fx(st_fx->prev_lsp_wb_fx, 0, 6 ); - set16_fx(st_fx->prev_lsp_wb_temp_fx, 0, 6 ); - set16_fx(st_fx->prev_lpc_wb_fx, 0, LPC_SHB_ORDER_WB); + set16_fx( st_fx->prev_lsp_wb_fx, 0, 6 ); + set16_fx( st_fx->prev_lsp_wb_temp_fx, 0, 6 ); + set16_fx( st_fx->prev_lpc_wb_fx, 0, LPC_SHB_ORDER_WB ); return; } @@ -463,34 +465,34 @@ void InitSWBencBuffer_fx( * *-------------------------------------------------------------------*/ void ResetSHBbuffer_Enc_fx( - Encoder_State* st_fx /* i/o: SHB encoder structure */ + Encoder_State *st_fx /* i/o: SHB encoder structure */ ) { TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; /* states for the filters used in generating SHB excitation from WB excitation*/ - set16_fx( hBWE_TD->mem_genSHBexc_filt_down_shb_fx, 0, 2*ALLPASSSECTIONS_STEEP+1); + set16_fx( hBWE_TD->mem_genSHBexc_filt_down_shb_fx, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); set32_fx( hBWE_TD->mem_csfilt_fx, 0, 2 ); /* states for the filters used in generating SHB signal from SHB excitation*/ set16_fx( hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD ); set16_fx( hBWE_TD->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); - //IF( EQ_16(st_fx->extl, FB_TBE)) _DIFF_FLOAT_FIX_ + // IF( EQ_16(st_fx->extl, FB_TBE)) _DIFF_FLOAT_FIX_ { set16_fx( hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); hBWE_TD->fb_tbe_demph_fx = 0; move16(); } /* states for the filters used in generating WB signal from WB excitation*/ - set16_fx( hBWE_TD->decim_state1_fx, 0, 2*ALLPASSSECTIONS_STEEP+1 ); - set16_fx( hBWE_TD->decim_state2_fx, 0, 2*ALLPASSSECTIONS_STEEP+1); - set16_fx( hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, 0, 2*ALLPASSSECTIONS_STEEP+1 ); - set16_fx( hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, 0, 2*ALLPASSSECTIONS_STEEP+1 ); + set16_fx( hBWE_TD->decim_state1_fx, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); + set16_fx( hBWE_TD->decim_state2_fx, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); + set16_fx( hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); + set16_fx( hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); /* overlap buffer used to Adjust SHB Frame Gain */ - set16_fx(hBWE_TD->mem_stp_swb_fx, 0, LPC_SHB_ORDER); - hBWE_TD->gain_prec_swb_fx = 16384;/*Q14=1 */ + set16_fx( hBWE_TD->mem_stp_swb_fx, 0, LPC_SHB_ORDER ); + hBWE_TD->gain_prec_swb_fx = 16384; /*Q14=1 */ set16_fx( hBWE_TD->syn_overlap_fx, 0, L_SHB_LAHEAD ); hBWE_TD->tbe_demph_fx = 0; hBWE_TD->tbe_premph_fx = 0; @@ -524,39 +526,39 @@ void ResetSHBbuffer_Enc_fx( /* */ /*==========================================================================*/ -#define WBTBE_LOOK_LSUFBR_5_OVER_16 (L_LOOK_12k8 + L_SUBFR)*5/16 -#define WBTBE_LSUBFR_5_OVER_16 L_SUBFR*5/16 -#define WBTBE_ANA_ALIGNDELAY -(L_SHB_LAHEAD/4 + 5) -#define LFRAME16K_OVER_4 L_FRAME16k/4 -#define WBTBE_LPCWIN_LENGTH (L_LOOK_12k8 + L_SUBFR + L_FRAME) * 5/16 - 1 +#define WBTBE_LOOK_LSUFBR_5_OVER_16 ( L_LOOK_12k8 + L_SUBFR ) * 5 / 16 +#define WBTBE_LSUBFR_5_OVER_16 L_SUBFR * 5 / 16 +#define WBTBE_ANA_ALIGNDELAY -( L_SHB_LAHEAD / 4 + 5 ) +#define LFRAME16K_OVER_4 L_FRAME16k / 4 +#define WBTBE_LPCWIN_LENGTH ( L_LOOK_12k8 + L_SUBFR + L_FRAME ) * 5 / 16 - 1 void wb_tbe_enc_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 coder_type, /* i : coding type */ - const Word16 *hb_speech, /* i : HB target signal (6-8kHz) at 16kHz at Q-1 */ - const Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation */ - const Word16 Q_new, /* i : input HB speech Q factor */ - const Word16 voice_factors[], /* i : voicing factors */ - const Word16 pitch_buf[], /* i : pitch for each subframe */ - const Word16 voicing_fx[] /* i : OL maximum normalized correlation */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word16 coder_type, /* i : coding type */ + const Word16 *hb_speech, /* i : HB target signal (6-8kHz) at 16kHz at Q-1 */ + const Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation */ + const Word16 Q_new, /* i : input HB speech Q factor */ + const Word16 voice_factors[], /* i : voicing factors */ + const Word16 pitch_buf[], /* i : pitch for each subframe */ + const Word16 voicing_fx[] /* i : OL maximum normalized correlation */ ) { Word16 i, j, k; - Word16 hb_old_speech [(L_LOOK_12k8 + L_SUBFR + L_FRAME)*5/16]; - Word16 bwe_exc_extended_16[ L_FRAME32k+NL_BUFF_OFFSET ]; + Word16 hb_old_speech[( L_LOOK_12k8 + L_SUBFR + L_FRAME ) * 5 / 16]; + Word16 bwe_exc_extended_16[L_FRAME32k + NL_BUFF_OFFSET]; - Word16 shaped_wb_excitation[(L_FRAME16k + L_SHB_LAHEAD)/4]; - Word16 exc4kWhtnd[L_FRAME16k/4]; + Word16 shaped_wb_excitation[( L_FRAME16k + L_SHB_LAHEAD ) / 4]; + Word16 exc4kWhtnd[L_FRAME16k / 4]; /*Word16 ana_align_delay = WBTBE_ANA_ALIGNDELAY; */ /* -L_SHB_LAHEAD/4 - 5 */ Word32 GainFrame; Word16 GainShape[NUM_SHB_SUBFR]; - Word16 lpc_wb[LPC_SHB_ORDER_WB+1]; + Word16 lpc_wb[LPC_SHB_ORDER_WB + 1]; Word32 lpc_wb_32_fx[LPC_SHB_ORDER_WB + 1]; - Word16 lsp_wb[LPC_SHB_ORDER_WB], weights_lsp[LPC_SHB_ORDER_WB] = {32767, 32767}; - Word16 *hb_new_speech, *hb_frame/*, hb_speech[ L_FRAME16k ]*/; - Word16 R_h[ LPC_SHB_ORDER_WB + 2 ], R_l[ LPC_SHB_ORDER_WB + 2 ]; + Word16 lsp_wb[LPC_SHB_ORDER_WB], weights_lsp[LPC_SHB_ORDER_WB] = { 32767, 32767 }; + Word16 *hb_new_speech, *hb_frame /*, hb_speech[ L_FRAME16k ]*/; + Word16 R_h[LPC_SHB_ORDER_WB + 2], R_l[LPC_SHB_ORDER_WB + 2]; Word16 Q_R; - Word32 LepsP[LPC_SHB_ORDER_WB+1]; + Word32 LepsP[LPC_SHB_ORDER_WB + 1]; Word32 prev_pow, curr_pow, Lscale; /* Word16 scale; */ @@ -572,11 +574,11 @@ void wb_tbe_enc_fx( Word16 vf_modified_fx[NB_SUBFR16k]; Word16 temp_wb_fac_fx, feedback_fx; Word16 lsp_spacing_fx; - Word16 lsp_wb_temp_fx[ LPC_SHB_ORDER_WB ], lpc_wb_temp_fx[ LPC_SHB_ORDER_WB + 1 ]; + Word16 lsp_wb_temp_fx[LPC_SHB_ORDER_WB], lpc_wb_temp_fx[LPC_SHB_ORDER_WB + 1]; Word32 L_feedback; Word16 frac, exp1; Word16 uv_flag; - Word16 dummy=0; + Word16 dummy = 0; Word16 avg_voice_fac; TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; RF_ENC_HANDLE hRF = st_fx->hRF; @@ -599,9 +601,7 @@ void wb_tbe_enc_fx( test(); test(); test(); - IF ( ( NE_16 (st_fx->last_extl, WB_TBE) && NE_16( st_fx->last_extl, WB_BWE)) - && ( EQ_16( st_fx->clas, UNVOICED_CLAS) || ( LT_16( voicing_fx[0], 16384 ) && LT_16( voicing_fx[1], 16384 ) && LT_16( voicing_fx[2], 16384 ) ) ) - && st_fx->igf == 0 ) + IF( ( NE_16( st_fx->last_extl, WB_TBE ) && NE_16( st_fx->last_extl, WB_BWE ) ) && ( EQ_16( st_fx->clas, UNVOICED_CLAS ) || ( LT_16( voicing_fx[0], 16384 ) && LT_16( voicing_fx[1], 16384 ) && LT_16( voicing_fx[2], 16384 ) ) ) && st_fx->igf == 0 ) { /* In case of unvoiced signals after switching cores, back-propagate the target signal */ Copy( hb_speech, hb_old_speech, WBTBE_LOOK_LSUFBR_5_OVER_16 ); @@ -611,10 +611,10 @@ void wb_tbe_enc_fx( k = 0; move16(); - FOR ( j = 0; j < L_SUBFR16k; j = j + 4 ) + FOR( j = 0; j < L_SUBFR16k; j = j + 4 ) { L_tmp = L_mult( hb_old_speech[i], ola_win_shb_switch_fold_fx[j] ); - hb_old_speech[i] = mac_r( L_tmp, hb_speech[j], ola_win_shb_switch_fold_fx[ L_SUBFR16k - 4 - j ] ); + hb_old_speech[i] = mac_r( L_tmp, hb_speech[j], ola_win_shb_switch_fold_fx[L_SUBFR16k - 4 - j] ); move16(); i--; k++; @@ -623,12 +623,12 @@ void wb_tbe_enc_fx( autocorr_fx( hb_old_speech, LPC_SHB_ORDER_WB + 1, R_h, R_l, &Q_R, WBTBE_LPCWIN_LENGTH, win_lpc_hb_wb_fx, 0, 1 ); - E_LPC_lev_dur(R_h, R_l, lpc_wb_temp_fx, LepsP, LPC_SHB_ORDER_WB, NULL); + E_LPC_lev_dur( R_h, R_l, lpc_wb_temp_fx, LepsP, LPC_SHB_ORDER_WB, NULL ); - Copy_Scale_sig( lpc_wb_temp_fx, lpc_wb_temp_fx, LPC_SHB_ORDER_WB+1, sub(norm_s(lpc_wb_temp_fx[0]),2) ); + Copy_Scale_sig( lpc_wb_temp_fx, lpc_wb_temp_fx, LPC_SHB_ORDER_WB + 1, sub( norm_s( lpc_wb_temp_fx[0] ), 2 ) ); /* convert into lsps and calculate weights */ - FOR ( i = 0; i <= LPC_SHB_ORDER_WB; i++ ) + FOR( i = 0; i <= LPC_SHB_ORDER_WB; i++ ) { lpc_wb_32_fx[i] = L_negate( L_shr( L_deposit_h( lpc_wb_temp_fx[i] ), 1 ) ); move32(); @@ -636,7 +636,7 @@ void wb_tbe_enc_fx( lpc2lsp_fx( &lpc_wb_32_fx[1], lsp_wb_temp_fx, st_fx->prev_lsp_wb_temp_fx, LPC_SHB_ORDER_WB ); - FOR ( i = 0; i < LPC_SHB_ORDER_WB; i++ ) + FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) { st_fx->prev_lsp_wb_temp_fx[i] = lsp_wb_temp_fx[i]; move16(); @@ -645,7 +645,7 @@ void wb_tbe_enc_fx( /* lsp_spacing_fx = 16384; move16(); */ lsp_spacing_fx = lsp_wb_temp_fx[0]; move16(); - FOR ( i = 1; i < LPC_SHB_ORDER_WB; i++ ) + FOR( i = 1; i < LPC_SHB_ORDER_WB; i++ ) { /*if ( i == 0 ) { @@ -660,7 +660,7 @@ void wb_tbe_enc_fx( } /* Spectral smoothing of autocorrelation coefficients */ - FOR ( i = 1; i <= LPC_SHB_ORDER_WB; i++ ) + FOR( i = 1; i <= LPC_SHB_ORDER_WB; i++ ) { L_tmp = Mpy_32( R_h[i], R_l[i], wac_h[i - 1], wac_l[i - 1] ); L_Extract( L_tmp, &R_h[i], &R_l[i] ); @@ -669,27 +669,27 @@ void wb_tbe_enc_fx( move16(); test(); - IF ( EQ_16(st_fx->rf_mode, 1)||EQ_32(st_fx->extl_brate,WB_TBE_0k35)) + IF( EQ_16( st_fx->rf_mode, 1 ) || EQ_32( st_fx->extl_brate, WB_TBE_0k35 ) ) { - E_LPC_lev_dur(R_h, R_l, lpc_wb, LepsP, LPC_SHB_ORDER_LBR_WB, NULL); - Copy_Scale_sig( lpc_wb, lpc_wb, LPC_SHB_ORDER_LBR_WB+1, sub(norm_s(lpc_wb[0]),2) ); + E_LPC_lev_dur( R_h, R_l, lpc_wb, LepsP, LPC_SHB_ORDER_LBR_WB, NULL ); + Copy_Scale_sig( lpc_wb, lpc_wb, LPC_SHB_ORDER_LBR_WB + 1, sub( norm_s( lpc_wb[0] ), 2 ) ); /* Expand bandwidth of the LP coeffs */ - FOR ( i = 0; i <= LPC_SHB_ORDER_LBR_WB; i++ ) + FOR( i = 0; i <= LPC_SHB_ORDER_LBR_WB; i++ ) { lpc_wb[i] = mult_r( lpc_wb[i], lpc_weights_fx[i] ); move16(); } /* convert into lsps and calculate weights */ - FOR ( i = 0; i <= LPC_SHB_ORDER_LBR_WB; i++ ) + FOR( i = 0; i <= LPC_SHB_ORDER_LBR_WB; i++ ) { - lpc_wb_32_fx[i] = L_negate( L_shr( L_deposit_h( lpc_wb[i] ),1 ) ); - move32();/*Q27 */ + lpc_wb_32_fx[i] = L_negate( L_shr( L_deposit_h( lpc_wb[i] ), 1 ) ); + move32(); /*Q27 */ } - lpc2lsp_fx( &lpc_wb_32_fx[1], lsp_wb, st_fx->prev_lsp_wb_fx,LPC_SHB_ORDER_LBR_WB ); + lpc2lsp_fx( &lpc_wb_32_fx[1], lsp_wb, st_fx->prev_lsp_wb_fx, LPC_SHB_ORDER_LBR_WB ); - FOR ( i = 0; i < LPC_SHB_ORDER_LBR_WB; i++ ) + FOR( i = 0; i < LPC_SHB_ORDER_LBR_WB; i++ ) { st_fx->prev_lsp_wb_fx[i] = lsp_wb[i]; move16(); @@ -699,7 +699,7 @@ void wb_tbe_enc_fx( /* Quantization of LSFs */ i = closest_centroid_fx( lsp_wb, weights_lsp, lbr_wb_bwe_lsfvq_cbook_2bit_fx, 4, LPC_SHB_ORDER_LBR_WB ); - IF( EQ_16(st_fx->codec_mode, MODE2)) + IF( EQ_16( st_fx->codec_mode, MODE2 ) ) { hBWE_TD->lsf_WB = i; move16(); @@ -709,18 +709,18 @@ void wb_tbe_enc_fx( push_indice_fx( st_fx->hBstr, IND_SHB_LSF, i, NUM_BITS_LBR_WB_LSF ); } - Copy( lbr_wb_bwe_lsfvq_cbook_2bit_fx + i * LPC_SHB_ORDER_LBR_WB, lsp_wb, LPC_SHB_ORDER_LBR_WB ); + Copy( lbr_wb_bwe_lsfvq_cbook_2bit_fx + i * LPC_SHB_ORDER_LBR_WB, lsp_wb, LPC_SHB_ORDER_LBR_WB ); lsp2lpc_fx( &lpc_wb[1], lsp_wb, st_fx->prev_lpc_wb_fx, LPC_SHB_ORDER_LBR_WB ); - set16_fx( lpc_wb + LPC_SHB_ORDER_LBR_WB + 1, 0, ( LPC_SHB_ORDER_WB - LPC_SHB_ORDER_LBR_WB ) ); - FOR ( i = 0; i < LPC_SHB_ORDER_WB; i++ ) + set16_fx( lpc_wb + LPC_SHB_ORDER_LBR_WB + 1, 0, ( LPC_SHB_ORDER_WB - LPC_SHB_ORDER_LBR_WB ) ); + FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) { st_fx->prev_lpc_wb_fx[i] = lpc_wb[i + 1]; move16(); } - FOR ( i = 1; i < LPC_SHB_ORDER_LBR_WB + 1; i++ ) + FOR( i = 1; i < LPC_SHB_ORDER_LBR_WB + 1; i++ ) { lpc_wb[i] = negate( lpc_wb[i] ); move16(); @@ -730,24 +730,24 @@ void wb_tbe_enc_fx( } ELSE /* 13.2kbps */ { - E_LPC_lev_dur(R_h, R_l, lpc_wb, LepsP, LPC_SHB_ORDER_WB, NULL); - Copy_Scale_sig( lpc_wb, lpc_wb, LPC_SHB_ORDER_WB+1, sub(norm_s(lpc_wb[0]),2) ); + E_LPC_lev_dur( R_h, R_l, lpc_wb, LepsP, LPC_SHB_ORDER_WB, NULL ); + Copy_Scale_sig( lpc_wb, lpc_wb, LPC_SHB_ORDER_WB + 1, sub( norm_s( lpc_wb[0] ), 2 ) ); /* Expand bandwidth of the LP coeffs */ - FOR ( i = 0; i <= LPC_SHB_ORDER_WB; i++ ) + FOR( i = 0; i <= LPC_SHB_ORDER_WB; i++ ) { lpc_wb[i] = mult_r( lpc_wb[i], lpc_weights_fx[i] ); move16(); } /* convert into lsps and calculate weights */ - FOR ( i = 0; i <= LPC_SHB_ORDER_WB; i++ ) + FOR( i = 0; i <= LPC_SHB_ORDER_WB; i++ ) { lpc_wb_32_fx[i] = L_negate( L_shr( L_deposit_h( lpc_wb[i] ), 1 ) ); - move32();/*Q27 */ + move32(); /*Q27 */ } - lpc2lsp_fx( &lpc_wb_32_fx[1], lsp_wb, st_fx->prev_lsp_wb_fx, LPC_SHB_ORDER_WB ); + lpc2lsp_fx( &lpc_wb_32_fx[1], lsp_wb, st_fx->prev_lsp_wb_fx, LPC_SHB_ORDER_WB ); FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) @@ -759,9 +759,9 @@ void wb_tbe_enc_fx( lsp_weights_fx( lsp_wb, weights_lsp, LPC_SHB_ORDER_WB, &Q_out ); /* Quantization of LSFs */ - i = closest_centroid_fx( lsp_wb, weights_lsp, wb_bwe_lsfvq_cbook_8bit_fx, 256, LPC_SHB_ORDER_WB );/*move16(); */ + i = closest_centroid_fx( lsp_wb, weights_lsp, wb_bwe_lsfvq_cbook_8bit_fx, 256, LPC_SHB_ORDER_WB ); /*move16(); */ - IF( EQ_16(st_fx->codec_mode, MODE2)) + IF( EQ_16( st_fx->codec_mode, MODE2 ) ) { hBWE_TD->lsf_WB = i; move16(); @@ -772,7 +772,7 @@ void wb_tbe_enc_fx( } Copy( wb_bwe_lsfvq_cbook_8bit_fx + i * LPC_SHB_ORDER_WB, lsp_wb, LPC_SHB_ORDER_WB ); - lsp2lpc_fx( &lpc_wb[1], lsp_wb, st_fx->prev_lpc_wb_fx, LPC_SHB_ORDER_WB ); + lsp2lpc_fx( &lpc_wb[1], lsp_wb, st_fx->prev_lpc_wb_fx, LPC_SHB_ORDER_WB ); FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) @@ -792,35 +792,35 @@ void wb_tbe_enc_fx( uv_flag = 0; move16(); test(); - if( EQ_32(st_fx->extl_brate, WB_TBE_1k05)&&EQ_16(st_fx->coder_type_raw,UNVOICED)) + if ( EQ_32( st_fx->extl_brate, WB_TBE_1k05 ) && EQ_16( st_fx->coder_type_raw, UNVOICED ) ) { uv_flag = 1; move16(); } Copy( voice_factors, vf_modified_fx, NB_SUBFR16k ); - IF( EQ_16(coder_type,VOICED)) + IF( EQ_16( coder_type, VOICED ) ) { FOR( i = 1; i < NB_SUBFR; i++ ) { /*vf_modified[i] = 0.8f * voice_factors[i] + 0.2f * voice_factors[i-1];*/ vf_modified_fx[i] = add( mult_r( 26214, voice_factors[i] ), mult_r( 6553, voice_factors[i - 1] ) ); } - IF( NE_16(st_fx->L_frame, L_FRAME)) + IF( NE_16( st_fx->L_frame, L_FRAME ) ) { vf_modified_fx[4] = add( mult_r( 26214, voice_factors[4] ), mult_r( 6553, voice_factors[3] ) ); } } /* From low band excitation, generate highband excitation */ - Lmax = L_deposit_l(0); + Lmax = L_deposit_l( 0 ); FOR( i = 0; i < L_FRAME32k; i++ ) { Lmax = L_max( Lmax, L_abs( bwe_exc_extended[i] ) ); } Q_bwe_exc = 31; - if( Lmax != 0 ) + if ( Lmax != 0 ) { Q_bwe_exc = norm_l( Lmax ); } @@ -829,17 +829,17 @@ void wb_tbe_enc_fx( find_max_mem_wb_enc( st_fx, &n_mem ); - if( GT_16(sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ),n_mem)) + if ( GT_16( sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ), n_mem ) ) { Q_bwe_exc = add( st_fx->prev_Q_bwe_exc, n_mem ); } IF( uv_flag ) { - if( GT_16( Q_bwe_exc, 20 )) + if ( GT_16( Q_bwe_exc, 20 ) ) { Q_bwe_exc = 20; - move16();/* restrict this to 20 due to the Q factor requireemnt of the random number generator (keep 1 bit headroom) */ + move16(); /* restrict this to 20 due to the Q factor requireemnt of the random number generator (keep 1 bit headroom) */ } } @@ -854,40 +854,38 @@ void wb_tbe_enc_fx( Copy( hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); sc = sub( Q_bwe_exc, add( Q_new, Q_new ) ); - FOR ( i = 0; i < L_FRAME32k; i++ ) + FOR( i = 0; i < L_FRAME32k; i++ ) { bwe_exc_extended_16[i + NL_BUFF_OFFSET] = round_fx( L_shl( bwe_exc_extended[i], sc ) ); } Copy( bwe_exc_extended_16 + L_FRAME32k, hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET ); - Copy( hBWE_TD->state_syn_shbexc_fx, shaped_wb_excitation, L_SHB_LAHEAD / 4 ); + Copy( hBWE_TD->state_syn_shbexc_fx, shaped_wb_excitation, L_SHB_LAHEAD / 4 ); Q_bwe_exc_ext = sub( Q_bwe_exc, 16 ); GenShapedWBExcitation_fx( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, hBWE_TD->state_lpc_syn_fx, coder_type, bwe_exc_extended_16, Q_bwe_exc_ext, hBWE_TD->bwe_seed, - vf_modified_fx, uv_flag - , st_fx->igf - ); + vf_modified_fx, uv_flag, st_fx->igf ); curr_pow = 0; move16(); - FOR ( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) { - curr_pow = L_mac0( curr_pow, shaped_wb_excitation[i + L_SHB_LAHEAD/4], shaped_wb_excitation[i + L_SHB_LAHEAD / 4] ); /* Q(2*Q_bwe_exc_ext) */ + curr_pow = L_mac0( curr_pow, shaped_wb_excitation[i + L_SHB_LAHEAD / 4], shaped_wb_excitation[i + L_SHB_LAHEAD / 4] ); /* Q(2*Q_bwe_exc_ext) */ } - IF ( GT_16( voice_factors[0], 24576 )) + IF( GT_16( voice_factors[0], 24576 ) ) { curr_pow = L_shr( curr_pow, 2 ); /* Q(2*Q_bwe_exc_ext) */ } - Lscale = root_a_over_b_fx( curr_pow, shl_r( Q_bwe_exc_ext, 1 ), prev_pow, shl_r( sub(st_fx->prev_Q_bwe_exc, 16 ), 1 ), &exp ); + Lscale = root_a_over_b_fx( curr_pow, shl_r( Q_bwe_exc_ext, 1 ), prev_pow, shl_r( sub( st_fx->prev_Q_bwe_exc, 16 ), 1 ), &exp ); - FOR ( i = 0; i < L_SHB_LAHEAD / 4 - 1; i++ ) + FOR( i = 0; i < L_SHB_LAHEAD / 4 - 1; i++ ) { L_tmp = Mult_32_16( Lscale, shaped_wb_excitation[i] ); /* Q(16-exp+Q_bwe_exc_ext) */ #ifdef BASOP_NOGLOB @@ -898,21 +896,21 @@ void wb_tbe_enc_fx( } Lscale = root_a_fx( Lscale, 31 - exp, &exp ); - L_tmp = Mult_32_16( Lscale, shaped_wb_excitation[L_SHB_LAHEAD / 4 - 1] ); /* Q(16-exp+Q_bwe_exc_ext) */ + L_tmp = Mult_32_16( Lscale, shaped_wb_excitation[L_SHB_LAHEAD / 4 - 1] ); /* Q(16-exp+Q_bwe_exc_ext) */ shaped_wb_excitation[L_SHB_LAHEAD / 4 - 1] = round_fx( L_shl( L_tmp, exp ) ); /* Q_bwe_exc_ext */ /* Update WB excitation */ - Copy( shaped_wb_excitation + L_FRAME16k / 4, hBWE_TD->state_syn_shbexc_fx, L_SHB_LAHEAD / 4 ); + Copy( shaped_wb_excitation + L_FRAME16k / 4, hBWE_TD->state_syn_shbexc_fx, L_SHB_LAHEAD / 4 ); EstimateSHBGainShape_fx( SHB_OVERLAP_LEN / 2, hb_frame, Q_ns, - shaped_wb_excitation, Q_bwe_exc_ext, GainShape,subwin_wb_fx, NULL ); + shaped_wb_excitation, Q_bwe_exc_ext, GainShape, subwin_wb_fx, NULL ); /* Gain frame adjustment factor */ test(); IF( GainShape[0] && hBWE_TD->prev_wb_GainShape ) { exp = norm_s( hBWE_TD->prev_wb_GainShape ); - tmp = div_s( shl(1,sub( 14,exp )), hBWE_TD->prev_wb_GainShape ); + tmp = div_s( shl( 1, sub( 14, exp ) ), hBWE_TD->prev_wb_GainShape ); L_tmp = L_mult( GainShape[0], tmp ); /* Q(30 - exp) */ exp1 = norm_l( L_tmp ); @@ -934,8 +932,8 @@ void wb_tbe_enc_fx( IF( GainShape[i] && GainShape[i - 1] ) { exp = norm_s( GainShape[i - 1] ); - tmp = div_s( shl(1,sub( 14,exp )), GainShape[i - 1] ); - L_tmp = L_mult( GainShape[i], tmp );/*Q(30 - exp) */ + tmp = div_s( shl( 1, sub( 14, exp ) ), GainShape[i - 1] ); + L_tmp = L_mult( GainShape[i], tmp ); /*Q(30 - exp) */ exp1 = norm_l( L_tmp ); frac = Log2_norm_lc( L_shl( L_tmp, exp1 ) ); @@ -951,7 +949,6 @@ void wb_tbe_enc_fx( } L_feedback = L_mac( L_feedback, temp_wb_fac_fx, temp_wb_fac_fx ); - } L_tmp = L_add( L_shr( L_feedback, 1 ), 1 << 21 ); /* Q30 */ @@ -960,14 +957,14 @@ void wb_tbe_enc_fx( exp = norm_l( L_tmp ); tmp = extract_h( L_shl( L_tmp, exp ) ); exp = sub( sub( 30, exp ), 21 ); - tmp = div_s( 16384, tmp ); /* Q(15+exp) */ + tmp = div_s( 16384, tmp ); /* Q(15+exp) */ L_tmp = L_shr( L_mult( 13107, tmp ), exp ); /* Q31 */ - feedback_fx = round_fx( L_tmp ); /* Q15 */ + feedback_fx = round_fx( L_tmp ); /* Q15 */ } ELSE { feedback_fx = 8738; - move16();/* Q15 */ + move16(); /* Q15 */ } @@ -981,19 +978,18 @@ void wb_tbe_enc_fx( move16(); } - hBWE_TD->prev_wb_GainShape = GainShape[sub(shr(NUM_SHB_SUBFR,2),1)]; + hBWE_TD->prev_wb_GainShape = GainShape[sub( shr( NUM_SHB_SUBFR, 2 ), 1 )]; move16(); - p2m_in = pow_off_pk_fx( GainShape, shr(NUM_SHB_SUBFR,2), 1 ); + p2m_in = pow_off_pk_fx( GainShape, shr( NUM_SHB_SUBFR, 2 ), 1 ); move16(); - IF( EQ_32(st_fx->extl_brate,WB_TBE_0k35)) + IF( EQ_32( st_fx->extl_brate, WB_TBE_0k35 ) ) { FOR( i = 0; i < 8; i++ ) { GainShape[i] = RECIP_ROOT_EIGHT_FX; move16(); } - } ELSE { @@ -1008,13 +1004,13 @@ void wb_tbe_enc_fx( /* Estimate the gain parameter */ EstimateSHBFrameGain_fx( SHB_OVERLAP_LEN / 2, hb_frame, Q_ns, shaped_wb_excitation, Q_bwe_exc_ext, GainShape, - &GainFrame, window_wb_fx, subwin_wb_fx, 0 ); + &GainFrame, window_wb_fx, subwin_wb_fx, 0 ); /* If there's a big difference in the power of gains away from the peak gain */ /* due to poor quantization then suppress energy of the high band. */ - IF( GT_32( p2m_out, L_shl( p2m_in, 1 ) )) + IF( GT_32( p2m_out, L_shl( p2m_in, 1 ) ) ) { L_tmp = root_a_over_b_fx( L_shl( p2m_in, 1 ), 29, p2m_out, 29, &exp_out ); GainFrame = L_shl( Mult_32_32( GainFrame, L_tmp ), exp_out ); /* Q18 */ @@ -1039,55 +1035,55 @@ void wb_tbe_enc_fx( IF( voicingBufAvg_fx > 0 ) { exp = norm_s( voicingBufAvg_fx ); - tmp = div_s( shl(1,sub( 14,exp )), voicingBufAvg_fx );/* (14-exp) */ - L_tmp = L_mult( pitBufAvg_fx, tmp ); /* (21-exp) */ + tmp = div_s( shl( 1, sub( 14, exp ) ), voicingBufAvg_fx ); /* (14-exp) */ + L_tmp = L_mult( pitBufAvg_fx, tmp ); /* (21-exp) */ #ifdef BASOP_NOGLOB - L_tmp = L_shl_o( L_tmp, add(exp, 10) , &Overflow); - tmp = round_fx_o( L_tmp , &Overflow); /* Q15 */ -#else /* BASOP_NOGLOB */ - L_tmp = L_shl( L_tmp, add(exp, 10) ); + L_tmp = L_shl_o( L_tmp, add( exp, 10 ), &Overflow ); + tmp = round_fx_o( L_tmp, &Overflow ); /* Q15 */ +#else /* BASOP_NOGLOB */ + L_tmp = L_shl( L_tmp, add( exp, 10 ) ); tmp = round_fx( L_tmp ); /* Q15 */ #endif } tmp = s_max( s_min( tmp, 32767 ), 22938 ); /* Q15 */ - GainFrame = Mult_32_16( GainFrame, tmp ); /* Q18 */ + GainFrame = Mult_32_16( GainFrame, tmp ); /* Q18 */ - IF( LT_16( lsp_spacing_fx, 328 )&&lsp_spacing_fx) + IF( LT_16( lsp_spacing_fx, 328 ) && lsp_spacing_fx ) { GainFrame = Mult_32_16( GainFrame, 21299 ); /* Q18 */ } - IF( EQ_16(st_fx->codec_mode, MODE1)) + IF( EQ_16( st_fx->codec_mode, MODE1 ) ) { /*wbbwe_em_factor = add( mult_r( 29491, st_fx->prev_wbbwe_em_factor_fx ), mult_r( 3277, wbbwe_em_factor ) ); */ /* Q15 */ } /*0.25f*sum_f(voice_factors, NB_SUBFR)*/ - L_tmp = L_mult(voice_factors[0], 8192); - FOR (i=1; iigf != 0 && EQ_16(coder_type, VOICED)) + IF( st_fx->igf != 0 && EQ_16( coder_type, VOICED ) ) { /*GainFrame *= 0.5f;*/ GainFrame = Mult_32_16( GainFrame, 16384 ); } - ELSE IF( st_fx->igf != 0 && GT_16( avg_voice_fac, 11469 )) /*Q15 -> 0.35f*/ + ELSE IF( st_fx->igf != 0 && GT_16( avg_voice_fac, 11469 ) ) /*Q15 -> 0.35f*/ { /*GainFrame *= 0.75f;*/ GainFrame = Mult_32_16( GainFrame, 24576 ); } /* Quantization of the frame gain parameter */ - QuantizeSHBframegain_fx( st_fx, &GainFrame, st_fx->extl, st_fx->extl_brate, &hRF->RF_bwe_gainFr_ind); + QuantizeSHBframegain_fx( st_fx, &GainFrame, st_fx->extl, st_fx->extl_brate, &hRF->RF_bwe_gainFr_ind ); /* Adjust the subframe and frame gain of the synthesized SHB signal */ /* Scale the shaped excitation*/ @@ -1103,10 +1099,9 @@ void wb_tbe_enc_fx( void fb_tbe_reset_enc_fx( Word32 elliptic_bpf_2_48k_mem_fx[][4], - Word32 *prev_fb_energy_fx - ,Word16 elliptic_bpf_2_48k_mem_fx_Q[], - Word16 *prev_fb_energy_fx_Q -) + Word32 *prev_fb_energy_fx, + Word16 elliptic_bpf_2_48k_mem_fx_Q[], + Word16 *prev_fb_energy_fx_Q ) { set32_fx( elliptic_bpf_2_48k_mem_fx[0], 0, 4 ); set32_fx( elliptic_bpf_2_48k_mem_fx[1], 0, 4 ); @@ -1114,7 +1109,7 @@ void fb_tbe_reset_enc_fx( set32_fx( elliptic_bpf_2_48k_mem_fx[3], 0, 4 ); *prev_fb_energy_fx = 0; move16(); - set16_fx(elliptic_bpf_2_48k_mem_fx_Q, 0, 4); + set16_fx( elliptic_bpf_2_48k_mem_fx_Q, 0, 4 ); *prev_fb_energy_fx_Q = 0; move16(); @@ -1146,37 +1141,37 @@ void fb_tbe_reset_enc_fx( /*======================================================================================*/ void swb_tbe_enc_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 coder_type, /* i : coding type */ - Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz Q_shb*/ - Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation 2*Q_new*/ - const Word16 voice_factors_fx[], /* i : voicing factors Q15*/ - Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE Q_white_exc*/ + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word16 coder_type, /* i : coding type */ + Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz Q_shb*/ + Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation 2*Q_new*/ + const Word16 voice_factors_fx[], /* i : voicing factors Q15*/ + Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE Q_white_exc*/ Word16 *Q_white_exc, Word16 Q_new, Word16 Q_shb, - Word16 *voicing, /* i : OL maximum normalized correlation */ - const Word16 pitch_buf[] /* i : subframe pitch Q6*/ + Word16 *voicing, /* i : OL maximum normalized correlation */ + const Word16 pitch_buf[] /* i : subframe pitch Q6*/ ) { Word16 i, j; - Word16 shb_old_speech_fx[ L_LOOK_16k + L_SUBFR16k + L_FRAME16k ]; - Word16 bwe_exc_extended_16[ L_FRAME32k+NL_BUFF_OFFSET ]; + Word16 shb_old_speech_fx[L_LOOK_16k + L_SUBFR16k + L_FRAME16k]; + Word16 bwe_exc_extended_16[L_FRAME32k + NL_BUFF_OFFSET]; - Word16 shaped_shb_excitation_fx [ L_FRAME16k + L_SHB_LAHEAD ]; + Word16 shaped_shb_excitation_fx[L_FRAME16k + L_SHB_LAHEAD]; Word32 GainFrame_fx; - Word16 GainShape_fx[ NUM_SHB_SUBFR ]; - Word16 lpc_shb_fx[ LPC_SHB_ORDER + 1 ], lsp_shb_fx[ LPC_SHB_ORDER ], lsf_shb_fx[ LPC_SHB_ORDER ]; + Word16 GainShape_fx[NUM_SHB_SUBFR]; + Word16 lpc_shb_fx[LPC_SHB_ORDER + 1], lsp_shb_fx[LPC_SHB_ORDER], lsf_shb_fx[LPC_SHB_ORDER]; Word16 weights_lsp[LPC_SHB_ORDER]; Word16 Q_out; - Word16* shb_frame_fx, *shb_new_speech_fx; - Word16 R_h[ LPC_SHB_ORDER+ 2 ]; /* Autocorrelations of windowed speech MSB */ - Word16 R_l[ LPC_SHB_ORDER+ 2 ]; /* Autocorrelations of windowed speech LSB */ + Word16 *shb_frame_fx, *shb_new_speech_fx; + Word16 R_h[LPC_SHB_ORDER + 2]; /* Autocorrelations of windowed speech MSB */ + Word16 R_l[LPC_SHB_ORDER + 2]; /* Autocorrelations of windowed speech LSB */ Word16 Q_R; - Word32 LepsP[LPC_SHB_ORDER+1]; + Word32 LepsP[LPC_SHB_ORDER + 1]; - Word16 ana_align_delay[2] = {-L_SHB_LAHEAD - (NL_BUFF_OFFSET/2), -L_SHB_LAHEAD - (NL_BUFF_OFFSET/2)}; + Word16 ana_align_delay[2] = { -L_SHB_LAHEAD - ( NL_BUFF_OFFSET / 2 ), -L_SHB_LAHEAD - ( NL_BUFF_OFFSET / 2 ) }; Word32 prev_pow_fx, curr_pow_fx, Lscale; Word32 p2m_in_fx, p2m_out_fx; @@ -1198,11 +1193,11 @@ void swb_tbe_enc_fx( Word16 pitBufAvg_fx; Word16 voicingBufAvg_fx; Word16 sum1, sum2; - Word16 recip,Q_recip; + Word16 recip, Q_recip; const Word16 *ptr_lsp_interp_coef_fx; Word16 lsp_shb_1_fx[LPC_SHB_ORDER], lsp_shb_2_fx[LPC_SHB_ORDER], lsp_temp_fx[LPC_SHB_ORDER]; - Word16 lpc_shb_sf_fx[4*(LPC_SHB_ORDER+1)]; + Word16 lpc_shb_sf_fx[4 * ( LPC_SHB_ORDER + 1 )]; /*Word32 shb_ener_sf_fx_32[4];*/ Word32 shb_ener_sf_Q31; @@ -1227,7 +1222,7 @@ void swb_tbe_enc_fx( RF_ENC_HANDLE hRF = st_fx->hRF; /* init and buffers set up */ - exp1 = 0; /* to avoid compilation warnings */ + exp1 = 0; /* to avoid compilation warnings */ set16_fx( shaped_shb_excitationTemp_fx, 0, L_FRAME16k ); /* compensate for the delay in target generation and subframe LA */ @@ -1235,19 +1230,19 @@ void swb_tbe_enc_fx( move16(); /* set up the speech buffers for TBE processing*/ - shb_new_speech_fx = shb_old_speech_fx + (L_LOOK_16k + L_SUBFR16k); + shb_new_speech_fx = shb_old_speech_fx + ( L_LOOK_16k + L_SUBFR16k ); move16(); - Copy(hBWE_TD->old_speech_shb_fx, shb_old_speech_fx, (L_LOOK_16k + L_SUBFR16k) ); + Copy( hBWE_TD->old_speech_shb_fx, shb_old_speech_fx, ( L_LOOK_16k + L_SUBFR16k ) ); Copy( shb_speech_fx, shb_new_speech_fx, L_FRAME16k ); - Copy( shb_old_speech_fx + L_FRAME16k, hBWE_TD->old_speech_shb_fx, (L_LOOK_16k + L_SUBFR16k) ); + Copy( shb_old_speech_fx + L_FRAME16k, hBWE_TD->old_speech_shb_fx, ( L_LOOK_16k + L_SUBFR16k ) ); /* autocorrelation of SHB speech for 10-th order LP analysis */ autocorr_fx( shb_old_speech_fx, LPC_SHB_ORDER + 1, - R_h, /* autocorr (msb) Q15 */ - R_l, /* autocorr (lsb) */ + R_h, /* autocorr (msb) Q15 */ + R_l, /* autocorr (lsb) */ &Q_R, - NS2SA(INT_FS_16k, ACELP_LOOK_NS) + L_SUBFR16k + L_FRAME16k, + NS2SA( INT_FS_16k, ACELP_LOOK_NS ) + L_SUBFR16k + L_FRAME16k, win_lpc_shb_fx, 0, 1 ); @@ -1255,7 +1250,7 @@ void swb_tbe_enc_fx( /* Spectral smoothing of autocorrelation coefficients */ test(); - IF( (st_fx->rf_mode != 0) || EQ_32( st_fx->total_brate, ACELP_9k60 )) + IF( ( st_fx->rf_mode != 0 ) || EQ_32( st_fx->total_brate, ACELP_9k60 ) ) { FOR( i = 1; i <= LPC_SHB_ORDER; i++ ) { @@ -1268,41 +1263,41 @@ void swb_tbe_enc_fx( R_l[0] = s_max( R_l[0], 1 ); move16(); - E_LPC_lev_dur(R_h, R_l, lpc_shb_fx, LepsP, LPC_SHB_ORDER, NULL); /* LPC in Q14 */ + E_LPC_lev_dur( R_h, R_l, lpc_shb_fx, LepsP, LPC_SHB_ORDER, NULL ); /* LPC in Q14 */ { - Word16 enerG, lpc_shb1[M+1]; + Word16 enerG, lpc_shb1[M + 1]; /* extend the lpc_shb to a 16th order gain calc */ - set16_fx(lpc_shb1, 0, M+1); - Copy(lpc_shb_fx, lpc_shb1, LPC_SHB_ORDER + 1); + set16_fx( lpc_shb1, 0, M + 1 ); + Copy( lpc_shb_fx, lpc_shb1, LPC_SHB_ORDER + 1 ); /* estimate the LP gain */ - enerG = Enr_1_Az_fx(lpc_shb1, 2*L_SUBFR); /* Q3 */ + enerG = Enr_1_Az_fx( lpc_shb1, 2 * L_SUBFR ); /* Q3 */ /* if the LP gain is greater than a threshold, avoid saturation */ - IF(GT_16(enerG, 256/*32 Q3*/)) + IF( GT_16( enerG, 256 /*32 Q3*/ ) ) { - set16_fx(lpc_shb_fx, 0, LPC_SHB_ORDER+1); - E_LPC_lev_dur(R_h, R_l, lpc_shb_fx, LepsP, 2, NULL); /* LPC in Q14 */ + set16_fx( lpc_shb_fx, 0, LPC_SHB_ORDER + 1 ); + E_LPC_lev_dur( R_h, R_l, lpc_shb_fx, LepsP, 2, NULL ); /* LPC in Q14 */ } } /* this is needed as the E_LPC_lev_dur function outputs lpc in Q14 */ - Copy_Scale_sig( lpc_shb_fx, lpc_shb_fx, LPC_SHB_ORDER+1, sub(norm_s(lpc_shb_fx[0]),2) ); + Copy_Scale_sig( lpc_shb_fx, lpc_shb_fx, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb_fx[0] ), 2 ) ); /* Expand bandwidth of the LP coeffs */ test(); - IF( (st_fx->rf_mode != 0) || EQ_32( st_fx->total_brate, ACELP_9k60 )) + IF( ( st_fx->rf_mode != 0 ) || EQ_32( st_fx->total_brate, ACELP_9k60 ) ) { FOR( i = 1; i <= LPC_SHB_ORDER; i++ ) { - lpc_shb_fx[i] = mult_r(lpc_shb_fx[i], lpc_weights_fx[i]); + lpc_shb_fx[i] = mult_r( lpc_shb_fx[i], lpc_weights_fx[i] ); } } /* LPC to LSP conversion */ /* LPC: Q12, LSP: Q15 */ - E_LPC_a_lsp_conversion(lpc_shb_fx, lsp_shb_fx, hBWE_TD->prev_lsp_shb_fx, LPC_SHB_ORDER ); + E_LPC_a_lsp_conversion( lpc_shb_fx, lsp_shb_fx, hBWE_TD->prev_lsp_shb_fx, LPC_SHB_ORDER ); /* LSP to LSF conversion */ /* LSP: Q15, LSF: Q15 */ @@ -1310,26 +1305,26 @@ void swb_tbe_enc_fx( /* Input signal filtering in case of tonal sounds in the high band gain Frame smoothing and attenuation control */ - gainFrSmooth_En_fx(st_fx, shb_frame_fx, lpc_shb_fx, lsf_shb_fx, &MA_lsp_shb_spacing, &frGainAttenuate, &frGainSmoothEn); + gainFrSmooth_En_fx( st_fx, shb_frame_fx, lpc_shb_fx, lsf_shb_fx, &MA_lsp_shb_spacing, &frGainAttenuate, &frGainSmoothEn ); Copy( lsp_shb_fx, hBWE_TD->prev_lsp_shb_fx, LPC_SHB_ORDER ); Copy( lsf_shb_fx, lsf_shb_orig_fx, LPC_SHB_ORDER ); test(); - IF( (EQ_16(st_fx->rf_mode,1))||EQ_32(st_fx->total_brate,ACELP_9k60)) + IF( ( EQ_16( st_fx->rf_mode, 1 ) ) || EQ_32( st_fx->total_brate, ACELP_9k60 ) ) { lsp_weights_fx( lsf_shb_fx, weights_lsp, LPC_SHB_ORDER, &Q_out ); /* to compensate for the 1.1* weighting done inside the function lsp_weights */ /*weights_lsp[3]*=0.909091f; weights_lsp[4]*=0.909091f; */ - weights_lsp[3] = mult_r( weights_lsp[3], 29789/*0.909091f Q15*/ ); - weights_lsp[4] = mult_r( weights_lsp[4], 29789/*0.909091f Q15*/ ); + weights_lsp[3] = mult_r( weights_lsp[3], 29789 /*0.909091f Q15*/ ); + weights_lsp[4] = mult_r( weights_lsp[4], 29789 /*0.909091f Q15*/ ); /* 8-bit VQ, 10 dimension */ i = closest_centroid_fx( lsf_shb_fx, weights_lsp, swb_tbe_lsfvq_cbook_8b, 256, LPC_SHB_ORDER ); - Copy(swb_tbe_lsfvq_cbook_8b + i*LPC_SHB_ORDER, lsf_shb_fx, LPC_SHB_ORDER); + Copy( swb_tbe_lsfvq_cbook_8b + i * LPC_SHB_ORDER, lsf_shb_fx, LPC_SHB_ORDER ); - set16_fx(hBWE_TD->lsf_idx, 0, NUM_Q_LSF); + set16_fx( hBWE_TD->lsf_idx, 0, NUM_Q_LSF ); hBWE_TD->lsf_idx[0] = i; } ELSE @@ -1343,131 +1338,131 @@ void swb_tbe_enc_fx( /* voice factor adjustment and gainframe attenuation factor */ tmp = sub( lsf_shb_fx[0], lsf_shb_orig_fx[0] ); - L_tmp = L_mult(tmp, tmp); + L_tmp = L_mult( tmp, tmp ); FOR( i = 1; i < LPC_SHB_ORDER; i++ ) { /* Estimate the QD in lsfs between UQ and Q */ tmp = sub( lsf_shb_fx[i], lsf_shb_orig_fx[i] ); L_tmp = L_mac( L_tmp, tmp, tmp ); } - sd_uq_q_fx = round_fx(L_tmp); /* sd_uq_q_fx in Q15 */ + sd_uq_q_fx = round_fx( L_tmp ); /* sd_uq_q_fx in Q15 */ /* voice factor modification to limit any spurious jumps in the middle of voiced subframes*/ /* mean(voice_factors_fx[i], 4); */ - L_tmp = L_mult(voice_factors_fx[0], 8192); - L_tmp = L_mac(L_tmp, voice_factors_fx[1], 8192); - L_tmp = L_mac(L_tmp, voice_factors_fx[2], 8192); - mean_vf = mac_r(L_tmp, voice_factors_fx[3], 8192); + L_tmp = L_mult( voice_factors_fx[0], 8192 ); + L_tmp = L_mac( L_tmp, voice_factors_fx[1], 8192 ); + L_tmp = L_mac( L_tmp, voice_factors_fx[2], 8192 ); + mean_vf = mac_r( L_tmp, voice_factors_fx[3], 8192 ); Copy( voice_factors_fx, vf_modified_fx, NB_SUBFR16k ); test(); - IF( EQ_16(coder_type, VOICED)||GT_16(mean_vf,13107/*0.4f Q15*/)) + IF( EQ_16( coder_type, VOICED ) || GT_16( mean_vf, 13107 /*0.4f Q15*/ ) ) { FOR( i = 1; i < NB_SUBFR; i++ ) { - L_tmp = L_mult(voice_factors_fx[i], 26214); - vf_modified_fx[i] = mac_r(L_tmp, voice_factors_fx[i-1], 6554); + L_tmp = L_mult( voice_factors_fx[i], 26214 ); + vf_modified_fx[i] = mac_r( L_tmp, voice_factors_fx[i - 1], 6554 ); move16(); } - IF( NE_16(st_fx->L_frame, L_FRAME)) + IF( NE_16( st_fx->L_frame, L_FRAME ) ) { - L_tmp = L_mult(voice_factors_fx[4], 26214); - vf_modified_fx[4] = mac_r(L_tmp, voice_factors_fx[3], 6554); + L_tmp = L_mult( voice_factors_fx[4], 26214 ); + vf_modified_fx[4] = mac_r( L_tmp, voice_factors_fx[3], 6554 ); move16(); } } /* convert quantized LSFs to LSPs for interpolation */ - E_LPC_lsf_lsp_conversion(lsf_shb_fx, lsp_shb_2_fx, LPC_SHB_ORDER); + E_LPC_lsf_lsp_conversion( lsf_shb_fx, lsp_shb_2_fx, LPC_SHB_ORDER ); test(); - IF( EQ_16(st_fx->last_extl, SWB_TBE)||EQ_16(st_fx->last_extl,FB_TBE)) + IF( EQ_16( st_fx->last_extl, SWB_TBE ) || EQ_16( st_fx->last_extl, FB_TBE ) ) { /* SHB LSP values from prev. frame for interpolation */ - Copy(hBWE_TD->swb_lsp_prev_interp_fx, lsp_shb_1_fx, LPC_SHB_ORDER); + Copy( hBWE_TD->swb_lsp_prev_interp_fx, lsp_shb_1_fx, LPC_SHB_ORDER ); } ELSE { /* Use current frame's LSPs; in effect no interpolation */ - Copy(lsp_shb_2_fx, lsp_shb_1_fx, LPC_SHB_ORDER); + Copy( lsp_shb_2_fx, lsp_shb_1_fx, LPC_SHB_ORDER ); } - lsf_diff[0] = lsf_diff[sub(LPC_SHB_ORDER,1)] = 16384;/*Q15*/ - FOR(i=1; i < LPC_SHB_ORDER-1; i++) + lsf_diff[0] = lsf_diff[sub( LPC_SHB_ORDER, 1 )] = 16384; /*Q15*/ + FOR( i = 1; i < LPC_SHB_ORDER - 1; i++ ) { - lsf_diff[i] = sub(lsf_shb_fx[i],lsf_shb_fx[sub(i,1)]); + lsf_diff[i] = sub( lsf_shb_fx[i], lsf_shb_fx[sub( i, 1 )] ); } - a2rc_fx (hBWE_TD->cur_sub_Aq_fx+1, refl, M); + a2rc_fx( hBWE_TD->cur_sub_Aq_fx + 1, refl, M ); /* LSP interpolation for 13.2 kbps and 16.4 kbps */ /* tilt_para = 6.6956f * (1.0f + refl[0]) * (1.0f + refl[0]) - 3.8714f * (1.0f + refl[0]) + 1.3041f; */ - tmp = add(16384,shr(refl[0],1));/*Q14*/ - tmp1 = mult(27425 /*Q12*/,tmp);/*Q11*/ - tmp1 = mult(tmp1,tmp); - tmp2 = shr(mult(31715,tmp),2); /* Q11 */ - tilt_para = add(sub(tmp1,tmp2),1335);/*Q10*/ + tmp = add( 16384, shr( refl[0], 1 ) ); /*Q14*/ + tmp1 = mult( 27425 /*Q12*/, tmp ); /*Q11*/ + tmp1 = mult( tmp1, tmp ); + tmp2 = shr( mult( 31715, tmp ), 2 ); /* Q11 */ + tilt_para = add( sub( tmp1, tmp2 ), 1335 ); /*Q10*/ - IF(NE_16(st_fx->last_extl,SWB_TBE)) + IF( NE_16( st_fx->last_extl, SWB_TBE ) ) { - FOR( i=1; iprev_lsf_diff_fx[i-1] = mult(lsf_diff[i],16384);/*Q15*/ + hBWE_TD->prev_lsf_diff_fx[i - 1] = mult( lsf_diff[i], 16384 ); /*Q15*/ } } - IF( LE_32(st_fx->total_brate,ACELP_16k40)) + IF( LE_32( st_fx->total_brate, ACELP_16k40 ) ) { test(); test(); test(); test(); test(); - IF(!(GT_16(hBWE_TD->prev_tilt_para_fx,5120)&&(EQ_16(coder_type,TRANSITION)||LT_16(tilt_para,1024)))&& - !(((LT_16(hBWE_TD->prev_tilt_para_fx,3072) && GE_16(hBWE_TD->prev_coder_type,VOICED) )) && GT_16(tilt_para,5120) )) + IF( !( GT_16( hBWE_TD->prev_tilt_para_fx, 5120 ) && ( EQ_16( coder_type, TRANSITION ) || LT_16( tilt_para, 1024 ) ) ) && + !( ( ( LT_16( hBWE_TD->prev_tilt_para_fx, 3072 ) && GE_16( hBWE_TD->prev_coder_type, VOICED ) ) ) && GT_16( tilt_para, 5120 ) ) ) { - FOR( i = 1; i < LPC_SHB_ORDER-1; i++ ) + FOR( i = 1; i < LPC_SHB_ORDER - 1; i++ ) { - IF(LT_16(lsf_diff[i], hBWE_TD->prev_lsf_diff_fx[i-1])) + IF( LT_16( lsf_diff[i], hBWE_TD->prev_lsf_diff_fx[i - 1] ) ) { - tmp = mult(26214,lsf_diff[i]); - tmp = div_s(tmp, hBWE_TD->prev_lsf_diff_fx[i-1]); - tmp = s_max(tmp,16384); - w[i] = s_min(tmp,32767); + tmp = mult( 26214, lsf_diff[i] ); + tmp = div_s( tmp, hBWE_TD->prev_lsf_diff_fx[i - 1] ); + tmp = s_max( tmp, 16384 ); + w[i] = s_min( tmp, 32767 ); } ELSE { - tmp = mult(26214,hBWE_TD->prev_lsf_diff_fx[i-1]); - tmp = div_s(tmp,lsf_diff[i]); - tmp = s_max(tmp,16384); - w[i] = s_min(tmp,32767); + tmp = mult( 26214, hBWE_TD->prev_lsf_diff_fx[i - 1] ); + tmp = div_s( tmp, lsf_diff[i] ); + tmp = s_max( tmp, 16384 ); + w[i] = s_min( tmp, 32767 ); } } w[0] = w[1]; - w[sub(LPC_SHB_ORDER,1)] = w[sub(LPC_SHB_ORDER,2)]; + w[sub( LPC_SHB_ORDER, 1 )] = w[sub( LPC_SHB_ORDER, 2 )]; FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - tmp1 = mult(lsp_shb_1_fx[i],sub(32767,w[i])); - tmp2 = mult(lsp_shb_2_fx[i],w[i]); - lsp_temp_fx[i] =add(tmp1,tmp2); + tmp1 = mult( lsp_shb_1_fx[i], sub( 32767, w[i] ) ); + tmp2 = mult( lsp_shb_2_fx[i], w[i] ); + lsp_temp_fx[i] = add( tmp1, tmp2 ); } } ELSE { - Copy(lsp_shb_2_fx, lsp_temp_fx, LPC_SHB_ORDER); + Copy( lsp_shb_2_fx, lsp_temp_fx, LPC_SHB_ORDER ); } } - Copy( lsf_diff + 1, hBWE_TD->prev_lsf_diff_fx, LPC_SHB_ORDER-2 ); + Copy( lsf_diff + 1, hBWE_TD->prev_lsf_diff_fx, LPC_SHB_ORDER - 2 ); hBWE_TD->prev_tilt_para_fx = tilt_para; shb_ener_sf_Q31 = 0; move16(); test(); - IF ( EQ_32(st_fx->total_brate, ACELP_24k40 )||EQ_32(st_fx->total_brate,ACELP_32k)) + IF( EQ_32( st_fx->total_brate, ACELP_24k40 ) || EQ_32( st_fx->total_brate, ACELP_32k ) ) { /* ---------- SHB LSP interpolation ---------- */ ptr_lsp_interp_coef_fx = interpol_frac_shb; /* Q15 */ @@ -1477,22 +1472,22 @@ void swb_tbe_enc_fx( { /*lsp_temp_fx[i] = lsp_shb_1_fx[i]*(*ptr_lsp_interp_coef_fx) */ /* + lsp_shb_2_fx[i]*(*(ptr_lsp_interp_coef_fx+1)); */ - L_tmp = L_mult(lsp_shb_1_fx[i], (*ptr_lsp_interp_coef_fx)); - lsp_temp_fx[i] = mac_r(L_tmp, lsp_shb_2_fx[i], (*(ptr_lsp_interp_coef_fx+1))); + L_tmp = L_mult( lsp_shb_1_fx[i], ( *ptr_lsp_interp_coef_fx ) ); + lsp_temp_fx[i] = mac_r( L_tmp, lsp_shb_2_fx[i], ( *( ptr_lsp_interp_coef_fx + 1 ) ) ); move16(); } ptr_lsp_interp_coef_fx += 2; - tmp = i_mult2(j, (LPC_SHB_ORDER+1)); + tmp = i_mult2( j, ( LPC_SHB_ORDER + 1 ) ); /* convert LSPs to LPC coefficients for SHB synthesis*/ - E_LPC_f_lsp_a_conversion(lsp_temp_fx, lpc_shb_sf_fx+tmp, LPC_SHB_ORDER); + E_LPC_f_lsp_a_conversion( lsp_temp_fx, lpc_shb_sf_fx + tmp, LPC_SHB_ORDER ); /* Bring the LPCs to Q12 */ - Copy_Scale_sig( lpc_shb_sf_fx+tmp, lpc_shb_sf_fx+tmp, LPC_SHB_ORDER+1, sub(norm_s(lpc_shb_sf_fx[tmp]),2) ); + Copy_Scale_sig( lpc_shb_sf_fx + tmp, lpc_shb_sf_fx + tmp, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb_sf_fx[tmp] ), 2 ) ); } /* -------- Calculate the SHB Energy -------- */ /*shb_ener_sf[0] = 0.003125f * sum2_f( shb_frame + L_SHB_LAHEAD, 320 );*/ - FOR( i = L_SHB_LAHEAD; i < L_FRAME16k + L_SHB_LAHEAD; i++) + FOR( i = L_SHB_LAHEAD; i < L_FRAME16k + L_SHB_LAHEAD; i++ ) { /* shbEner = shbEner + in[i] * in[i] */ #ifdef BASOP_NOGLOB @@ -1502,27 +1497,27 @@ void swb_tbe_enc_fx( #endif /* o: shb_ener_sf_Q31 in (2*Q_shb) */ } - shb_ener_sf_Q31= Mult_32_16(shb_ener_sf_Q31, 102/*0.003125f Q15*/); - shb_ener_sf_Q31= L_add(1l/*1 Q0*/, shb_ener_sf_Q31); - Quant_shb_ener_sf_fx(st_fx, &shb_ener_sf_Q31, (2*Q_shb)); + shb_ener_sf_Q31 = Mult_32_16( shb_ener_sf_Q31, 102 /*0.003125f Q15*/ ); + shb_ener_sf_Q31 = L_add( 1l /*1 Q0*/, shb_ener_sf_Q31 ); + Quant_shb_ener_sf_fx( st_fx, &shb_ener_sf_Q31, ( 2 * Q_shb ) ); /* -------- calculate the residuals using the FOUR subframe LPCs -------- */ - set16_fx(shb_res_fx, 0, L_FRAME16k); - Residu3_10_fx(lpc_shb_sf_fx, shb_frame_fx + L_SHB_LAHEAD, shb_res_fx, 80, 0); - Residu3_10_fx(lpc_shb_sf_fx + (LPC_SHB_ORDER+1), shb_frame_fx + L_SHB_LAHEAD + 80, shb_res_fx + 80, 80, 0); - Residu3_10_fx(lpc_shb_sf_fx + 2*(LPC_SHB_ORDER+1), shb_frame_fx + L_SHB_LAHEAD + 160, shb_res_fx + 160, 80, 0); - Residu3_10_fx(lpc_shb_sf_fx + 3*(LPC_SHB_ORDER+1), shb_frame_fx + L_SHB_LAHEAD + 240, shb_res_fx + 240, 80, 0); + set16_fx( shb_res_fx, 0, L_FRAME16k ); + Residu3_10_fx( lpc_shb_sf_fx, shb_frame_fx + L_SHB_LAHEAD, shb_res_fx, 80, 0 ); + Residu3_10_fx( lpc_shb_sf_fx + ( LPC_SHB_ORDER + 1 ), shb_frame_fx + L_SHB_LAHEAD + 80, shb_res_fx + 80, 80, 0 ); + Residu3_10_fx( lpc_shb_sf_fx + 2 * ( LPC_SHB_ORDER + 1 ), shb_frame_fx + L_SHB_LAHEAD + 160, shb_res_fx + 160, 80, 0 ); + Residu3_10_fx( lpc_shb_sf_fx + 3 * ( LPC_SHB_ORDER + 1 ), shb_frame_fx + L_SHB_LAHEAD + 240, shb_res_fx + 240, 80, 0 ); /* i: shb_frame_fx in Q_shb */ /* o: shb_res_fx in Q_shb */ - set32_fx(shb_res_gshape_fx_32, 0, NB_SUBFR16k); - FOR(i = 0; i < NB_SUBFR16k; i++) + set32_fx( shb_res_gshape_fx_32, 0, NB_SUBFR16k ); + FOR( i = 0; i < NB_SUBFR16k; i++ ) { - shb_res_gshape_fx_32[i] = sum2_fx(shb_res_fx+i*64, 64); + shb_res_gshape_fx_32[i] = sum2_fx( shb_res_fx + i * 64, 64 ); } /* o: shb_res_gshape_fx_32 in (2*Q_shb+1) */ - maximum_32_fx(shb_res_gshape_fx_32, NB_SUBFR16k, &L_tmp); + maximum_32_fx( shb_res_gshape_fx_32, NB_SUBFR16k, &L_tmp ); /* root_a_over_b_fx(shb_res_gshape_fx_32[i], (2*Q_shb+1), L_tmp, (2*Q_shb+1), &exp);*/ /* First, find 1/L_tmp, L_tmp in QA = (2*Q_shb+1) */ @@ -1531,50 +1526,50 @@ void swb_tbe_enc_fx( recip = 0; /*instead of 32767 to be compatible with previous root_a_over_b_fx() output */ Q_recip = 0; - IF(L_tmp) + IF( L_tmp ) { - exp = norm_l(L_tmp); - tmp = extract_h(L_shl(L_tmp,exp)); - recip = div_s(16384,tmp); - Q_recip = 31-(exp-14); /* = 31-(exp+2*Q_shb+1-14), but adjusted by (2*Q_shb+1) for use at Mult_32_16 below */ + exp = norm_l( L_tmp ); + tmp = extract_h( L_shl( L_tmp, exp ) ); + recip = div_s( 16384, tmp ); + Q_recip = 31 - ( exp - 14 ); /* = 31-(exp+2*Q_shb+1-14), but adjusted by (2*Q_shb+1) for use at Mult_32_16 below */ } - FOR(i = 0; i < NB_SUBFR16k; i++) + FOR( i = 0; i < NB_SUBFR16k; i++ ) { - L_tmp1 = Mult_32_16(shb_res_gshape_fx_32[i], recip); /*Q = Q_recip+1-16*/ - L_tmp = root_a_fx( L_tmp1, Q_recip+1-16, &exp ); - shb_res_gshape_fx[i] = round_fx(L_shl(L_tmp, exp-1)); /* Q14 */ + L_tmp1 = Mult_32_16( shb_res_gshape_fx_32[i], recip ); /*Q = Q_recip+1-16*/ + L_tmp = root_a_fx( L_tmp1, Q_recip + 1 - 16, &exp ); + shb_res_gshape_fx[i] = round_fx( L_shl( L_tmp, exp - 1 ) ); /* Q14 */ } - Quant_shb_res_gshape_fx(st_fx, shb_res_gshape_fx); + Quant_shb_res_gshape_fx( st_fx, shb_res_gshape_fx ); } /* for 13.2 and 16.4kbps */ - E_LPC_f_lsp_a_conversion(lsp_temp_fx, lpc_shb_fx, LPC_SHB_ORDER); - Copy_Scale_sig( lpc_shb_fx, lpc_shb_fx, LPC_SHB_ORDER+1, sub(norm_s(lpc_shb_fx[0]),2) ); /* Q12 */ + E_LPC_f_lsp_a_conversion( lsp_temp_fx, lpc_shb_fx, LPC_SHB_ORDER ); + Copy_Scale_sig( lpc_shb_fx, lpc_shb_fx, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb_fx[0] ), 2 ) ); /* Q12 */ /* Save the SWB LSP values from current frame for interpolation */ - Copy(lsp_shb_2_fx, hBWE_TD->swb_lsp_prev_interp_fx, LPC_SHB_ORDER); /* lsp_shb_2_fx in Q15 */ + Copy( lsp_shb_2_fx, hBWE_TD->swb_lsp_prev_interp_fx, LPC_SHB_ORDER ); /* lsp_shb_2_fx in Q15 */ /* -------- start of memory rescaling -------- */ /* ----- calculate optimum Q_bwe_exc and rescale memories accordingly ----- */ - Lmax = L_deposit_l(0); + Lmax = L_deposit_l( 0 ); FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) { Lmax = L_max( Lmax, L_abs( bwe_exc_extended[cnt] ) ); } Q_bwe_exc = norm_l( Lmax ); - if(Lmax == 0) + if ( Lmax == 0 ) { Q_bwe_exc = 31; } Q_bwe_exc = add( Q_bwe_exc, add( Q_new, Q_new ) ); /* Account for any outliers in the memories from previous frame for rescaling to avoid saturation */ - find_max_mem_enc( st_fx, &n_mem, &n_mem2); + find_max_mem_enc( st_fx, &n_mem, &n_mem2 ); tmp2 = add( st_fx->prev_Q_bwe_exc, n_mem ); - if( GT_16( Q_bwe_exc, tmp2)) + if ( GT_16( Q_bwe_exc, tmp2 ) ) { Q_bwe_exc = tmp2; } @@ -1587,7 +1582,7 @@ void swb_tbe_enc_fx( } /* rescale the bwe_exc_extended and bring it to 16-bit single precision with dynamic norm */ - Copy(hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); + Copy( hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); sc = sub( Q_bwe_exc, add( Q_new, Q_new ) ); FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) @@ -1601,13 +1596,13 @@ void swb_tbe_enc_fx( Copy( bwe_exc_extended_16 + L_FRAME32k, hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET ); /* state_syn_shbexc_fx is kept at (st_fx->prev_Q_bwe_syn) for 24.4/32kbps or is kept at Q_bwe_exc for 13.2/16.4kbps */ - Copy(hBWE_TD->state_syn_shbexc_fx, shaped_shb_excitation_fx, L_SHB_LAHEAD ); + Copy( hBWE_TD->state_syn_shbexc_fx, shaped_shb_excitation_fx, L_SHB_LAHEAD ); /* save the previous Q factor of the buffer */ st_fx->prev_Q_bwe_exc = Q_bwe_exc; move16(); - Q_bwe_exc = sub( Q_bwe_exc, 16 ); /* Q_bwe_exc reflecting the single precision dynamic norm-ed buffers from here */ + Q_bwe_exc = sub( Q_bwe_exc, 16 ); /* Q_bwe_exc reflecting the single precision dynamic norm-ed buffers from here */ /* -------- end of rescaling memories -------- */ Q_bwe_exc_fb = hBWE_TD->prev_Q_bwe_exc_fb; @@ -1623,12 +1618,12 @@ void swb_tbe_enc_fx( GenShapedSHBExcitation_fx( shaped_shb_excitation_fx + L_SHB_LAHEAD, lpc_shb_fx, White_exc16k_fx, hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, coder_type, bwe_exc_extended_16, hBWE_TD->bwe_seed, vf_modified_fx, st_fx->extl, - &(hBWE_TD->tbe_demph_fx ), &(hBWE_TD->tbe_premph_fx ), lpc_shb_sf_fx, shb_ener_sf_Q31, + &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), lpc_shb_sf_fx, shb_ener_sf_Q31, shb_res_gshape_fx, shb_res_fx, &vf_ind_fx, formant_fac_fx, hBWE_TD->fb_state_lpc_syn_fx, - &(hBWE_TD->fb_tbe_demph_fx), &Q_bwe_exc,&Q_bwe_exc_fb, Q_shb, n_mem2, st_fx->prev_Q_bwe_syn, st_fx->total_brate, 0 ); + &( hBWE_TD->fb_tbe_demph_fx ), &Q_bwe_exc, &Q_bwe_exc_fb, Q_shb, n_mem2, st_fx->prev_Q_bwe_syn, st_fx->total_brate, 0 ); *Q_white_exc = Q_bwe_exc_fb; - IF( EQ_16(st_fx->extl, FB_TBE)) + IF( EQ_16( st_fx->extl, FB_TBE ) ) { hBWE_TD->prev_Q_bwe_exc_fb = Q_bwe_exc_fb; } @@ -1641,86 +1636,85 @@ void swb_tbe_enc_fx( } test(); - IF( EQ_32(st_fx->total_brate, ACELP_24k40)||EQ_32(st_fx->total_brate,ACELP_32k)) + IF( EQ_32( st_fx->total_brate, ACELP_24k40 ) || EQ_32( st_fx->total_brate, ACELP_32k ) ) { - IF( EQ_16( st_fx->codec_mode, MODE2 )) + IF( EQ_16( st_fx->codec_mode, MODE2 ) ) { hBWE_TD->idx_mixFac = vf_ind_fx; move16(); } ELSE { - push_indice_fx( st_fx->hBstr, IND_SHB_VF, vf_ind_fx, NUM_BITS_SHB_VF); + push_indice_fx( st_fx->hBstr, IND_SHB_VF, vf_ind_fx, NUM_BITS_SHB_VF ); } } FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - hBWE_TD->mem_stp_swb_fx[i] = shl(hBWE_TD->mem_stp_swb_fx[i], sub(Q_bwe_exc, st_fx->prev_Q_bwe_syn) ); + hBWE_TD->mem_stp_swb_fx[i] = shl( hBWE_TD->mem_stp_swb_fx[i], sub( Q_bwe_exc, st_fx->prev_Q_bwe_syn ) ); } FOR( i = 0; i < L_FRAME16k; i += L_SUBFR16k ) { - PostShortTerm_fx( &shaped_shb_excitation_fx[L_SHB_LAHEAD+i], lpc_shb_fx, &shaped_shb_excitationTemp_fx[i], hBWE_TD->mem_stp_swb_fx, - hBWE_TD->ptr_mem_stp_swb_fx, &(hBWE_TD->gain_prec_swb_fx), hBWE_TD->mem_zero_swb_fx, formant_fac_fx ); + PostShortTerm_fx( &shaped_shb_excitation_fx[L_SHB_LAHEAD + i], lpc_shb_fx, &shaped_shb_excitationTemp_fx[i], hBWE_TD->mem_stp_swb_fx, + hBWE_TD->ptr_mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ), hBWE_TD->mem_zero_swb_fx, formant_fac_fx ); /* i: shaped_shb_excitation_fx in Q_bwe_exc */ /* i: lpc_shb_fx in Q12 */ } Copy( shaped_shb_excitationTemp_fx, &shaped_shb_excitation_fx[L_SHB_LAHEAD], L_FRAME16k ); - - tmp = sub(shl(Q_bwe_exc, 1), 31); - prev_pow_fx = L_shl(21475l/*0.00001f Q31*/, tmp); /* 2*(Q_bwe_exc) */ - curr_pow_fx = L_shl(21475l/*0.00001f Q31*/, tmp); /* 2*(Q_bwe_exc) */ + tmp = sub( shl( Q_bwe_exc, 1 ), 31 ); + prev_pow_fx = L_shl( 21475l /*0.00001f Q31*/, tmp ); /* 2*(Q_bwe_exc) */ + curr_pow_fx = L_shl( 21475l /*0.00001f Q31*/, tmp ); /* 2*(Q_bwe_exc) */ FOR( i = 0; i < L_SHB_LAHEAD + 10; i++ ) { #ifdef BASOP_NOGLOB - prev_pow_fx = L_mac0_o( prev_pow_fx, shaped_shb_excitation_fx[i], shaped_shb_excitation_fx[i], &Overflow ); /* 2*Q_bwe_exc */ - curr_pow_fx = L_mac0_o( curr_pow_fx, shaped_shb_excitation_fx[i + L_SHB_LAHEAD + 10], shaped_shb_excitation_fx[i + L_SHB_LAHEAD + 10], &Overflow); /* 2*Q_bwe_exc */ + prev_pow_fx = L_mac0_o( prev_pow_fx, shaped_shb_excitation_fx[i], shaped_shb_excitation_fx[i], &Overflow ); /* 2*Q_bwe_exc */ + curr_pow_fx = L_mac0_o( curr_pow_fx, shaped_shb_excitation_fx[i + L_SHB_LAHEAD + 10], shaped_shb_excitation_fx[i + L_SHB_LAHEAD + 10], &Overflow ); /* 2*Q_bwe_exc */ #else - prev_pow_fx = L_mac0( prev_pow_fx, shaped_shb_excitation_fx[i], shaped_shb_excitation_fx[i] ); /* 2*Q_bwe_exc */ + prev_pow_fx = L_mac0( prev_pow_fx, shaped_shb_excitation_fx[i], shaped_shb_excitation_fx[i] ); /* 2*Q_bwe_exc */ curr_pow_fx = L_mac0( curr_pow_fx, shaped_shb_excitation_fx[i + L_SHB_LAHEAD + 10], shaped_shb_excitation_fx[i + L_SHB_LAHEAD + 10] ); /* 2*Q_bwe_exc */ #endif } - if( GT_16( voice_factors_fx[0], 24576/*0.75f Q15*/ )) + if ( GT_16( voice_factors_fx[0], 24576 /*0.75f Q15*/ ) ) { /*curr_pow_fx = Mult_32_16( curr_pow_fx, 8192);*/ /* Q(2*Q_bwe_exc) */ - curr_pow_fx = L_shr(curr_pow_fx, 2); /* scale by 0.25 */ + curr_pow_fx = L_shr( curr_pow_fx, 2 ); /* scale by 0.25 */ } Lscale = root_a_over_b_fx( curr_pow_fx, - shl(Q_bwe_exc, 1), + shl( Q_bwe_exc, 1 ), prev_pow_fx, - shl(Q_bwe_exc, 1), + shl( Q_bwe_exc, 1 ), &exp ); FOR( i = 0; i < L_SHB_LAHEAD; i++ ) { - L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q(16-exp+Q_bwe_exc) */ + L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q(16-exp+Q_bwe_exc) */ shaped_shb_excitation_fx[i] = round_fx( L_shl( L_tmp, exp ) ); /* Q_bwe_exc */ } IF( exp < 0 ) { - Lscale = L_shl(Lscale, exp); + Lscale = L_shl( Lscale, exp ); exp = 0; } - FOR( ; i < L_SHB_LAHEAD + 10; i++ ) + FOR( ; i < L_SHB_LAHEAD + 10; i++ ) { #ifdef BASOP_NOGLOB - tmp = i_mult_o(sub(i, 19), 3277/*0.1f Q15*/, &Overflow); /* Q15 */ - L_tmp1 = Mult_32_16(L_shl_o(1, sub(31,exp), &Overflow), tmp); /* Q31-exp */ + tmp = i_mult_o( sub( i, 19 ), 3277 /*0.1f Q15*/, &Overflow ); /* Q15 */ + L_tmp1 = Mult_32_16( L_shl_o( 1, sub( 31, exp ), &Overflow ), tmp ); /* Q31-exp */ #else - tmp = i_mult(sub(i, 19), 3277/*0.1f Q15*/); /* Q15 */ - L_tmp1 = Mult_32_16(L_shl(1, sub(31,exp)), tmp); /* Q31-exp */ + tmp = i_mult( sub( i, 19 ), 3277 /*0.1f Q15*/ ); /* Q15 */ + L_tmp1 = Mult_32_16( L_shl( 1, sub( 31, exp ) ), tmp ); /* Q31-exp */ #endif - tmp = sub(32767/*1.0f Q15*/, tmp); - Lscale = L_add(Mult_32_16(Lscale, tmp), L_tmp1); - L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */ + tmp = sub( 32767 /*1.0f Q15*/, tmp ); + Lscale = L_add( Mult_32_16( Lscale, tmp ), L_tmp1 ); + L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */ #ifdef BASOP_NOGLOB - shaped_shb_excitation_fx[i] = round_fx_o( L_shl_o( L_tmp, exp, &Overflow ), &Overflow); /* Q_bwe_exc */ + shaped_shb_excitation_fx[i] = round_fx_o( L_shl_o( L_tmp, exp, &Overflow ), &Overflow ); /* Q_bwe_exc */ #else - shaped_shb_excitation_fx[i] = round_fx( L_shl( L_tmp, exp ) ); /* Q_bwe_exc */ + shaped_shb_excitation_fx[i] = round_fx( L_shl( L_tmp, exp ) ); /* Q_bwe_exc */ #endif } @@ -1731,17 +1725,17 @@ void swb_tbe_enc_fx( n_subfr_saturation = 0; move16(); EstimateSHBGainShape_fx( SHB_OVERLAP_LEN, shb_frame_fx, Q_shb, shaped_shb_excitation_fx, - Q_bwe_exc, GainShape_fx, subwin_shb_fx, &n_subfr_saturation ); + Q_bwe_exc, GainShape_fx, subwin_shb_fx, &n_subfr_saturation ); /* Gain shape BWS/high band low energy fix */ - IF( LT_16(hBWE_TD->cldfbHBLT, 8192/*1.0f Q13*/)) /* cldfbHBLT in Q13 */ + IF( LT_16( hBWE_TD->cldfbHBLT, 8192 /*1.0f Q13*/ ) ) /* cldfbHBLT in Q13 */ { /* There is not much HB past 10kHz; the temporal resolution is quite coarse, so reduce the dynamic range */ - FOR(i = 0; i < NUM_SHB_SUBGAINS; i++) + FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) { /* 0.35f +/- delta variation; delta = 0.1*(GS-0.35)*/ /* GainShape[i] = 0.315f + 0.1f * GainShape[i]; */ - GainShape_fx[i] = mac_r(676457349l/*0.315 Q31*/, 3277/*0.1 Q15*/, GainShape_fx[i]); + GainShape_fx[i] = mac_r( 676457349l /*0.315 Q31*/, 3277 /*0.1 Q15*/, GainShape_fx[i] ); } } @@ -1750,13 +1744,13 @@ void swb_tbe_enc_fx( test(); IF( GainShape_fx[0] && hBWE_TD->prev_swb_GainShape_fx ) { - exp = norm_s(hBWE_TD->prev_swb_GainShape_fx ); - tmp = div_s( shl(1, sub( 14, exp )), hBWE_TD->prev_swb_GainShape_fx ); - L_tmp = L_mult( GainShape_fx[0], tmp );/*Q(30 - exp) */ + exp = norm_s( hBWE_TD->prev_swb_GainShape_fx ); + tmp = div_s( shl( 1, sub( 14, exp ) ), hBWE_TD->prev_swb_GainShape_fx ); + L_tmp = L_mult( GainShape_fx[0], tmp ); /*Q(30 - exp) */ exp1 = norm_l( L_tmp ); - frac = Log2_norm_lc( L_shl( L_tmp, exp1 ) );/*move16(); */ - exp1 = sub(exp, exp1 ); /*move16(); */ + frac = Log2_norm_lc( L_shl( L_tmp, exp1 ) ); /*move16(); */ + exp1 = sub( exp, exp1 ); /*move16(); */ L_tmp = Mpy_32_16( exp1, frac, 22713 ); temp_swb_fac = round_fx( L_shl( L_tmp, 10 ) ); } @@ -1774,12 +1768,12 @@ void swb_tbe_enc_fx( IF( GainShape_fx[i] && GainShape_fx[i - 1] ) { exp = norm_s( GainShape_fx[i - 1] ); - tmp = div_s( shl(1, sub( 14, exp )), GainShape_fx[i - 1] ); - L_tmp = L_mult( GainShape_fx[i], tmp );/* Q(30 - exp) */ + tmp = div_s( shl( 1, sub( 14, exp ) ), GainShape_fx[i - 1] ); + L_tmp = L_mult( GainShape_fx[i], tmp ); /* Q(30 - exp) */ exp1 = norm_l( L_tmp ); frac = Log2_norm_lc( L_shl( L_tmp, exp1 ) ); - exp1 = sub( exp , exp1 ); + exp1 = sub( exp, exp1 ); L_tmp = Mpy_32_16( exp1, frac, 22713 ); temp_swb_fac = round_fx( L_shl( L_tmp, 10 ) ); } @@ -1793,15 +1787,15 @@ void swb_tbe_enc_fx( } /* feedback = 0.4f / (1 + 0.5f * feedback) */ - L_tmp = L_add( L_shr( L_feedback, 1 ), L_shl(1,21) ); /* Q21 */ + L_tmp = L_add( L_shr( L_feedback, 1 ), L_shl( 1, 21 ) ); /* Q21 */ IF( L_tmp != 0 ) { exp = norm_l( L_tmp ); tmp = extract_h( L_shl( L_tmp, exp ) ); exp = sub( sub( 30, exp ), 21 ); - tmp = div_s( 16384, tmp ); /*Q(15+exp) */ + tmp = div_s( 16384, tmp ); /*Q(15+exp) */ L_tmp = L_shr( L_mult( 13107, tmp ), exp ); /*Q31 */ - feedback = round_fx( L_tmp ); /*Q15 */ + feedback = round_fx( L_tmp ); /*Q15 */ } ELSE { @@ -1810,30 +1804,30 @@ void swb_tbe_enc_fx( } /* voicing in Q15 */ - L_tmp = L_mult(voicing[0],8192); - L_tmp = L_mac(L_tmp, voicing[1],8192); - L_tmp = L_mac(L_tmp, voicing[2],8192); - tmp = sum1 = round_fx(L_tmp); /* sum1 used again below - Q13 */ - tmp = add(tmp,1); /* To ensure change is BE */ + L_tmp = L_mult( voicing[0], 8192 ); + L_tmp = L_mac( L_tmp, voicing[1], 8192 ); + L_tmp = L_mac( L_tmp, voicing[2], 8192 ); + tmp = sum1 = round_fx( L_tmp ); /* sum1 used again below - Q13 */ + tmp = add( tmp, 1 ); /* To ensure change is BE */ /* voice_factors_fx in Q15 */ - L_tmp = L_mult(voice_factors_fx[0],8192); - L_tmp = L_mac(L_tmp, voice_factors_fx[1],8192); - L_tmp = L_mac(L_tmp, voice_factors_fx[2],8192); - L_tmp = L_mac(L_tmp, voice_factors_fx[3],8192); - tmp1 = sum2 = round_fx(L_tmp); /* sum2 used again below - Q13 */ + L_tmp = L_mult( voice_factors_fx[0], 8192 ); + L_tmp = L_mac( L_tmp, voice_factors_fx[1], 8192 ); + L_tmp = L_mac( L_tmp, voice_factors_fx[2], 8192 ); + L_tmp = L_mac( L_tmp, voice_factors_fx[3], 8192 ); + tmp1 = sum2 = round_fx( L_tmp ); /* sum2 used again below - Q13 */ test(); test(); - IF( EQ_16(frGainAttenuate,1)||(GT_16(tmp,19661)&>_16(tmp1,6554))) + IF( EQ_16( frGainAttenuate, 1 ) || ( GT_16( tmp, 19661 ) && GT_16( tmp1, 6554 ) ) ) { temp_swb_fac = hBWE_TD->prev_swb_GainShape_fx; FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) { /*GainShape_fx[i] = (1 - feedback) * GainShape[i] + feedback * temp_swb_fac; */ - GainShape_fx[i] = round_fx(L_mac(L_mult(sub( 32767, feedback ), GainShape_fx[i] ),feedback, temp_swb_fac ) ); + GainShape_fx[i] = round_fx( L_mac( L_mult( sub( 32767, feedback ), GainShape_fx[i] ), feedback, temp_swb_fac ) ); temp_swb_fac = GainShape_fx[i]; move16(); } @@ -1855,37 +1849,37 @@ void swb_tbe_enc_fx( EstimateSHBFrameGain_fx( SHB_OVERLAP_LEN, shb_frame_fx, Q_shb, shaped_shb_excitation_fx, Q_bwe_exc, GainShape_fx, &GainFrame_fx, window_shb_fx, subwin_shb_fx, n_subfr_saturation ); - IF( EQ_16(st_fx->tec_tfa, 1)) + IF( EQ_16( st_fx->tec_tfa, 1 ) ) { tfaCalcEnv_fx( shb_frame_fx, st_fx->tfa_enr ); } /* If there's a big difference in the power of gains away from the peak gain */ /* due to poor quantization then suppress energy of the high band. */ - IF( GT_32( p2m_out_fx, L_shl( p2m_in_fx, 1 ) )) + IF( GT_32( p2m_out_fx, L_shl( p2m_in_fx, 1 ) ) ) { L_tmp = root_a_over_b_fx( p2m_in_fx, 28, p2m_out_fx, 29, &exp_out ); GainFrame_fx = L_shl( Mult_32_32( GainFrame_fx, L_tmp ), exp_out ); /* Q18 */ } test(); - IF( EQ_16(frGainSmoothEn,1)&<_32(hBWE_TD->prev_gainFr_SHB_fx,GainFrame_fx)) + IF( EQ_16( frGainSmoothEn, 1 ) && LT_32( hBWE_TD->prev_gainFr_SHB_fx, GainFrame_fx ) ) { - GainFrame_fx = L_add( L_shr(hBWE_TD->prev_gainFr_SHB_fx, 1), L_shr(GainFrame_fx, 1) ); /* Q18 */ + GainFrame_fx = L_add( L_shr( hBWE_TD->prev_gainFr_SHB_fx, 1 ), L_shr( GainFrame_fx, 1 ) ); /* Q18 */ } test(); - IF( EQ_16(frGainAttenuate, 1)&&LE_16(MA_lsp_shb_spacing,79/*0.0024f Q15*/)) + IF( EQ_16( frGainAttenuate, 1 ) && LE_16( MA_lsp_shb_spacing, 79 /*0.0024f Q15*/ ) ) { exp1 = norm_l( GainFrame_fx ); frac = Log2_norm_lc( L_shl( GainFrame_fx, exp1 ) ); - exp = sub(30, add( exp1, 21 ) ); + exp = sub( 30, add( exp1, 21 ) ); L_tmp = Mpy_32_16( exp, frac, 26214 ); /* Q16 */ frac = L_Extract_lc( L_tmp, &exp ); GainFrame_fx = Pow2( 30, frac ); - exp = sub( exp, 30); + exp = sub( exp, 30 ); GainFrame_fx = L_shl( GainFrame_fx, exp + 18 ); /* Q18 */ } - ELSE IF( EQ_16(hBWE_TD->prev_frGainAtten, 1)&>_32(Mult_32_16(GainFrame_fx,10923), hBWE_TD->prev_gainFr_SHB_fx)) + ELSE IF( EQ_16( hBWE_TD->prev_frGainAtten, 1 ) && GT_32( Mult_32_16( GainFrame_fx, 10923 ), hBWE_TD->prev_gainFr_SHB_fx ) ) { /*GainFrame *= (0.8f + 0.5f*feedback); */ tmp = add( 26214, mult_r( feedback, 16384 ) ); @@ -1898,37 +1892,36 @@ void swb_tbe_enc_fx( /* Gain attenuation when the SWB LSF quantization error is larger than a threshold */ - tmp = mult_r(25600/*400 Q6*/, sd_uq_q_fx); /* Q6 * Q15 => Q6 */ - IF(EQ_16(st_fx->L_frame, L_FRAME)) + tmp = mult_r( 25600 /*400 Q6*/, sd_uq_q_fx ); /* Q6 * Q15 => Q6 */ + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { - tmp1 = mult_r(6554/*0.2f Q15*/, tmp); /* Q15, Q6 => Q6 */ - L_tmp = L_msu(8192l/*1.0f Q13*/, tmp1, tmp); /* Q13 */ + tmp1 = mult_r( 6554 /*0.2f Q15*/, tmp ); /* Q15, Q6 => Q6 */ + L_tmp = L_msu( 8192l /*1.0f Q13*/, tmp1, tmp ); /* Q13 */ } ELSE { - tmp1 = mult_r(3277/*0.1f Q15*/, tmp); /* Q15, Q6 => Q6 */ - L_tmp = L_msu(8192l/*1.0f Q13*/, tmp1, tmp); /* Q13 */ + tmp1 = mult_r( 3277 /*0.1f Q15*/, tmp ); /* Q15, Q6 => Q6 */ + L_tmp = L_msu( 8192l /*1.0f Q13*/, tmp1, tmp ); /* Q13 */ } /* sd_uq_q = max(min(sd_uq_q, 1.0f), 0.5f); */ - L_tmp = L_min(L_tmp, 8192l/*1.0f Q13*/); - L_tmp = L_max(L_tmp, 4096l/*0.5f Q13*/); /* Q13 */ + L_tmp = L_min( L_tmp, 8192l /*1.0f Q13*/ ); + L_tmp = L_max( L_tmp, 4096l /*0.5f Q13*/ ); /* Q13 */ /* keep the L_tmp; dont overwrite */ /* pitBufAvg = 0.0025f * sum_f(pitch_buf, 4); */ /* pitch_buf: Q6 */ - pitBufAvg_fx = mult_r(pitch_buf[0],1311) ; - pitBufAvg_fx = add( pitBufAvg_fx, mult_r(pitch_buf[1],1311) ); - pitBufAvg_fx = add( pitBufAvg_fx, mult_r(pitch_buf[2],1311) ); - pitBufAvg_fx = add( pitBufAvg_fx, mult_r(pitch_buf[3],1311) ); /* Q10 */ + pitBufAvg_fx = mult_r( pitch_buf[0], 1311 ); + pitBufAvg_fx = add( pitBufAvg_fx, mult_r( pitch_buf[1], 1311 ) ); + pitBufAvg_fx = add( pitBufAvg_fx, mult_r( pitch_buf[2], 1311 ) ); + pitBufAvg_fx = add( pitBufAvg_fx, mult_r( pitch_buf[3], 1311 ) ); /* Q10 */ /* voicingBufAvg = (sum_f(voice_factors, 4)=sum2 > 0.6f) ? 0.333f : 0.1667f; */ - tmp2 = 5462/*0.1667f Q15*/; - if(GT_16(sum2, 4915/*0.6f Q13*/)) + tmp2 = 5462 /*0.1667f Q15*/; + if ( GT_16( sum2, 4915 /*0.6f Q13*/ ) ) { - tmp2 = 10912/*0.333f Q15*/; /* Q15 */ + tmp2 = 10912 /*0.333f Q15*/; /* Q15 */ } - voicingBufAvg_fx = shl(mult(tmp2, sum1),2); /* Q15 */ - + voicingBufAvg_fx = shl( mult( tmp2, sum1 ), 2 ); /* Q15 */ /* max(min((float)(sd_uq_q*pitBufAvg/voicingBufAvg), 1.0f), 0.6f) */ @@ -1940,27 +1933,27 @@ void swb_tbe_enc_fx( IF( voicingBufAvg_fx > 0 ) { exp = norm_s( voicingBufAvg_fx ); - tmp = div_s( shl(1, sub( 14, exp )), voicingBufAvg_fx ); /* (14-exp) */ + tmp = div_s( shl( 1, sub( 14, exp ) ), voicingBufAvg_fx ); /* (14-exp) */ /* sd_uq_q*pitBufAvg */ - L_tmp = Mult_32_16(L_tmp, pitBufAvg_fx); /* Q13 * Q10 + 1 -16 => Q8 */ - L_tmp = Mult_32_16(L_tmp, tmp ); /* Q8 + (14 - exp) - 15 => Q7 - exp */ + L_tmp = Mult_32_16( L_tmp, pitBufAvg_fx ); /* Q13 * Q10 + 1 -16 => Q8 */ + L_tmp = Mult_32_16( L_tmp, tmp ); /* Q8 + (14 - exp) - 15 => Q7 - exp */ #ifdef BASOP_NOGLOB - tmp = round_fx_o(L_shl_o(L_tmp, 31-(7-exp), &Overflow), &Overflow); /* Q15 */ + tmp = round_fx_o( L_shl_o( L_tmp, 31 - ( 7 - exp ), &Overflow ), &Overflow ); /* Q15 */ #else - tmp = round_fx(L_shl(L_tmp, 31-(7-exp))); /* Q15 */ + tmp = round_fx( L_shl( L_tmp, 31 - ( 7 - exp ) ) ); /* Q15 */ #endif } - tmp = s_min(tmp, 32767/*1.0f Q15*/); - tmp = s_max(tmp, 19661/*0.6f Q15*/); - GainFrame_fx = Mult_32_16(GainFrame_fx, tmp); /* Q18 + Q15 + 1 - 16 : Q18 */ + tmp = s_min( tmp, 32767 /*1.0f Q15*/ ); + tmp = s_max( tmp, 19661 /*0.6f Q15*/ ); + GainFrame_fx = Mult_32_16( GainFrame_fx, tmp ); /* Q18 + Q15 + 1 - 16 : Q18 */ test(); - IF(EQ_16(st_fx->L_frame, L_FRAME16k)||EQ_16(st_fx->rf_mode,1)) + IF( EQ_16( st_fx->L_frame, L_FRAME16k ) || EQ_16( st_fx->rf_mode, 1 ) ) { /* Compensate for energy increase mismatch due to memory-less synthesis*/ - GainFrame_fx = Mult_32_16(GainFrame_fx, 27853/*0.85f Q15*/ ); /* Q18 */ + GainFrame_fx = Mult_32_16( GainFrame_fx, 27853 /*0.85f Q15*/ ); /* Q18 */ } /* Quantization of the frame gain parameter */ @@ -1968,40 +1961,40 @@ void swb_tbe_enc_fx( /* Adjust the subframe and frame gain of the synthesized SHB signal */ /* Scale the shaped excitation */ - IF( EQ_32(st_fx->extl,FB_TBE)) + IF( EQ_32( st_fx->extl, FB_TBE ) ) { tmp = norm_l( GainFrame_fx ); - if(GainFrame_fx == 0) + if ( GainFrame_fx == 0 ) { tmp = 31; } - L_tmp = L_shl(GainFrame_fx,tmp);/* 18 + tmp */ + L_tmp = L_shl( GainFrame_fx, tmp ); /* 18 + tmp */ - tmp1 =0; + tmp1 = 0; FOR( i = 0; i < L_FRAME16k; i++ ) { L_tmp1 = Mult_32_16( L_tmp, GainShape_fx[NUM_SHB_SUBFR * i / L_FRAME16k] ); /* Q : 18 + tmp +15 -15*/ /*White_exc16k_fx[i] = round_fx( L_shl(Mult_32_16( L_tmp1, White_exc16k_fx[i]),(23 - tmp -*Q_white_exc)) );*/ /*18 + tmp +*Q_white_exc -15 + 23 - tmp -*Q_white_exc -16 = 10*/ - White_exc16k_fx[i] = round_fx( Mult_32_16( L_tmp1, White_exc16k_fx[i] ) );/* 18 + tmp +*Q_white_exc -15 -16 */ + White_exc16k_fx[i] = round_fx( Mult_32_16( L_tmp1, White_exc16k_fx[i] ) ); /* 18 + tmp +*Q_white_exc -15 -16 */ /*Lmax = L_max(Lmax,White_exc16k_fx[i]);*/ - tmp1 = s_max(tmp1,abs_s(White_exc16k_fx[i])); + tmp1 = s_max( tmp1, abs_s( White_exc16k_fx[i] ) ); /*White_exc16k_fx[i] =32767;*/ /*White_exc16k_fx[i] = shr(White_exc16k_fx[i],5);*/ } - *Q_white_exc = sub(add(*Q_white_exc, tmp),13); /* *Q_white_exc + 18 + tmp -15 -16 */ + *Q_white_exc = sub( add( *Q_white_exc, tmp ), 13 ); /* *Q_white_exc + 18 + tmp -15 -16 */ tmp = norm_s( tmp1 ); - if(tmp1 == 0) + if ( tmp1 == 0 ) { tmp = 15; } - FOR(i=0; ihBWE_TD; BSTR_ENC_HANDLE hBstr = st_fx->hBstr; - IF( EQ_16(extl, WB_TBE)) + IF( EQ_16( extl, WB_TBE ) ) { - set16_fx( Unit_weights10, 32767, ( Word16 )NUM_SHB_SUBFR / 4 ); + set16_fx( Unit_weights10, 32767, (Word16) NUM_SHB_SUBFR / 4 ); FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) { - IF( EQ_16(subgains[i] ,0) ) + IF( EQ_16( subgains[i], 0 ) ) { subgains[i + NUM_SHB_SUBFR / 4] = -18432; move16(); /* (-72) in Q8 */ @@ -2787,8 +2780,8 @@ static void QuantizeSHBsubgains_fx( exp = norm_l( L_tmp ); frac = Log2_norm_lc( L_shl( L_tmp, exp ) ); /* move16(); */ /*exp = -1 - exp; */ - exp = sub(-1, exp); - L_tmp = Mpy_32_16( exp, frac, 24660 );/* Q13 ; 20.0 * log10(2) in Q12*/ + exp = sub( -1, exp ); + L_tmp = Mpy_32_16( exp, frac, 24660 ); /* Q13 ; 20.0 * log10(2) in Q12*/ subgains[i + NUM_SHB_SUBFR / 4] = round_fx( L_shl( L_tmp, 11 ) ); /* Q8 */ } } @@ -2800,14 +2793,14 @@ static void QuantizeSHBsubgains_fx( FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) { L_tmp = L_mult( subgains[i], 21771 ); /* *0.166096 in Q17 -> Q26 */ - L_tmp = L_shr( L_tmp, 10 ); /* From Q26 to Q16 */ + L_tmp = L_shr( L_tmp, 10 ); /* From Q26 to Q16 */ frac = L_Extract_lc( L_tmp, &exp ); subgains[i] = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ subgains[i] = shl( subgains[i], exp + 1 ); - move16();/*Q15 */ + move16(); /*Q15 */ } FOR( i = NUM_SHB_SUBFR / 2 - 1; i >= 0; i-- ) @@ -2820,7 +2813,7 @@ static void QuantizeSHBsubgains_fx( { FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) { - IF( EQ_16(subgains[i] ,0) ) + IF( EQ_16( subgains[i], 0 ) ) { subgains[i] = -12288; move16(); /* (-3) in Q12 */ @@ -2831,26 +2824,26 @@ static void QuantizeSHBsubgains_fx( exp = norm_l( L_tmp ); frac = Log2_norm_lc( L_shl( L_tmp, exp ) ); /*exp = -1 - exp; */ - exp = sub(-1, exp); + exp = sub( -1, exp ); - L_tmp = Mpy_32_16( exp, frac, 9864 ); /*move32(); // Q16 ; log10(2) in Q15 */ + L_tmp = Mpy_32_16( exp, frac, 9864 ); /*move32(); // Q16 ; log10(2) in Q15 */ subgains[i] = round_fx( L_shl( L_tmp, 12 ) ); /*Q12 */ } } - idxSubGain = ( Word16 )vquant_fx( subgains, 0, subgains, SHBCB_SubGain5bit_12_fx, NUM_SHB_SUBGAINS, 1 << NUM_BITS_SHB_SUBGAINS ); + idxSubGain = (Word16) vquant_fx( subgains, 0, subgains, SHBCB_SubGain5bit_12_fx, NUM_SHB_SUBGAINS, 1 << NUM_BITS_SHB_SUBGAINS ); FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) { L_tmp = L_mult( subgains[i], 27213 ); /* *3.321928 in Q13 -> Q26 */ - L_tmp = L_shr( L_tmp, 10 ); /* From Q26 to Q16 */ + L_tmp = L_shr( L_tmp, 10 ); /* From Q26 to Q16 */ frac = L_Extract_lc( L_tmp, &exp ); subgains[i] = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ subgains[i] = shl( subgains[i], exp + 1 ); - move16();/*Q15 */ + move16(); /*Q15 */ } FOR( i = NUM_SHB_SUBFR - 1; i >= 0; i-- ) @@ -2861,7 +2854,7 @@ static void QuantizeSHBsubgains_fx( hBWE_TD->idxSubGains = idxSubGain; move16(); - IF( NE_16( st_fx->codec_mode, MODE2 )) + IF( NE_16( st_fx->codec_mode, MODE2 ) ) { push_indice_fx( hBstr, IND_SHB_SUBGAIN, idxSubGain, NUM_BITS_SHB_SUBGAINS ); } @@ -2871,7 +2864,6 @@ static void QuantizeSHBsubgains_fx( } - /*-------------------------------------------------------------------* * Quant_shb_ener_sf_fx_fx() * @@ -2879,14 +2871,13 @@ static void QuantizeSHBsubgains_fx( *-------------------------------------------------------------------*/ static void Quant_shb_ener_sf_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - Word32 *shb_ener_sf_Q31, /* i/o: super highband subframe energies */ - Word16 Q_ener -) + Encoder_State *st_fx, /* i/o: encoder state structure */ + Word32 *shb_ener_sf_Q31, /* i/o: super highband subframe energies */ + Word16 Q_ener ) { Word16 idxSubEner_fx; Word16 temp_shb_ener_sf_fx; - Word16 exp/*, exp2*/,frac; + Word16 exp /*, exp2*/, frac; Word32 L_tmp1, L_tmp; Word32 sum; Word16 tmp; @@ -2895,62 +2886,62 @@ static void Quant_shb_ener_sf_fx( /* shb_ener_sf_fx[0] = log10(0.003125*shb_ener_sf[0:319]); */ sum = *shb_ener_sf_Q31; /* L_tmp in Q_ener = (2*Q_shb+1) */ - exp = norm_l(sum); - frac = Log2_norm_lc(L_shl(sum, exp)); - exp = sub(30, add(exp, Q_ener)); /* 30-(exp+Q_ener ) */ - L_tmp1 = Mpy_32_16(exp, frac, 617); /* 2466=LOG10(2) in Q11, so answer Ltmp in Q12 */ + exp = norm_l( sum ); + frac = Log2_norm_lc( L_shl( sum, exp ) ); + exp = sub( 30, add( exp, Q_ener ) ); /* 30-(exp+Q_ener ) */ + L_tmp1 = Mpy_32_16( exp, frac, 617 ); /* 2466=LOG10(2) in Q11, so answer Ltmp in Q12 */ - tmp = round_fx(L_shl(L_tmp1, 30-14)); /* tmp in Q12 */ + tmp = round_fx( L_shl( L_tmp1, 30 - 14 ) ); /* tmp in Q12 */ temp_shb_ener_sf_fx = 0; move16(); - idxSubEner_fx = usquant_fx(tmp, &temp_shb_ener_sf_fx, 0, 86, shl(1,NUM_BITS_SHB_ENER_SF)); /* 86 = 0.042f in Q11 = Qin-1 */ + idxSubEner_fx = usquant_fx( tmp, &temp_shb_ener_sf_fx, 0, 86, shl( 1, NUM_BITS_SHB_ENER_SF ) ); /* 86 = 0.042f in Q11 = Qin-1 */ /* o: temp_shb_ener_sf_fx in Q12 */ /* shb_ener_sf_fx[0] = pow(10.0, temp_shb_ener_sf_fx ); */ /* = pow(2, 3.321928*temp_shb_ener_sf_fx) */ - L_tmp = L_mult(temp_shb_ener_sf_fx, 27213 ); /* 3.321928 in Q13 -> L_tmp in Q12+Q13+1 = Q26 */ - L_tmp = L_shl( L_tmp, -10 ); /* bring L_tmp from Q26 to Q16 */ - frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent */ - L_tmp = Pow2(14, frac ); - *shb_ener_sf_Q31 = L_shl(L_tmp, exp-14+Q_ener ); /* In Q_ener */ + L_tmp = L_mult( temp_shb_ener_sf_fx, 27213 ); /* 3.321928 in Q13 -> L_tmp in Q12+Q13+1 = Q26 */ + L_tmp = L_shl( L_tmp, -10 ); /* bring L_tmp from Q26 to Q16 */ + frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent */ + L_tmp = Pow2( 14, frac ); + *shb_ener_sf_Q31 = L_shl( L_tmp, exp - 14 + Q_ener ); /* In Q_ener */ hBWE_TD->idx_shb_fr_gain = idxSubEner_fx; move16(); - IF( NE_16( st_fx->codec_mode, MODE2 )) + IF( NE_16( st_fx->codec_mode, MODE2 ) ) { - push_indice_fx( st_fx->hBstr, IND_SHB_ENER_SF, idxSubEner_fx, NUM_BITS_SHB_ENER_SF); + push_indice_fx( st_fx->hBstr, IND_SHB_ENER_SF, idxSubEner_fx, NUM_BITS_SHB_ENER_SF ); } return; } /*-------------------------------------------------------------------* -* Quant_shb_res_gshape_fx() -* -* Quantize SHB gain shapes in residual domain -*-------------------------------------------------------------------*/ + * Quant_shb_res_gshape_fx() + * + * Quantize SHB gain shapes in residual domain + *-------------------------------------------------------------------*/ static void Quant_shb_res_gshape_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - Word16 shb_res_gshape_fx[] /* i/o: super highband gain shapes Q14 */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + Word16 shb_res_gshape_fx[] /* i/o: super highband gain shapes Q14 */ ) { Word16 i, idxSubGain_fx[NB_SUBFR16k]; TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; - FOR(i = 0; i < NB_SUBFR16k; i++) + FOR( i = 0; i < NB_SUBFR16k; i++ ) { - idxSubGain_fx[i] = usquant_fx(shb_res_gshape_fx[i], - &shb_res_gshape_fx[i], - 2048/*0.125f Q14*/, /*2048 = 0.125 in Q14 */ - 1024/*0.125f Q13*/, /*1024 = 0.125 in Q13 */ - shl(1,NUM_BITS_SHB_RES_GS)); + idxSubGain_fx[i] = usquant_fx( shb_res_gshape_fx[i], + &shb_res_gshape_fx[i], + 2048 /*0.125f Q14*/, /*2048 = 0.125 in Q14 */ + 1024 /*0.125f Q13*/, /*1024 = 0.125 in Q13 */ + shl( 1, NUM_BITS_SHB_RES_GS ) ); hBWE_TD->idx_res_gs[i] = idxSubGain_fx[i]; - IF ( NE_16( st_fx->codec_mode, MODE2 )) + IF( NE_16( st_fx->codec_mode, MODE2 ) ) { - push_indice_fx( st_fx->hBstr, IND_SHB_RES_GS1+i, idxSubGain_fx[i], NUM_BITS_SHB_RES_GS); + push_indice_fx( st_fx->hBstr, IND_SHB_RES_GS1 + i, idxSubGain_fx[i], NUM_BITS_SHB_RES_GS ); } } } @@ -2975,12 +2966,12 @@ static void Quant_shb_res_gshape_fx( /* */ /*==========================================================================*/ static void QuantizeSHBframegain_fx( - Encoder_State* st_fx, /* i/o: encoder state structure */ - Word32* GainFrame, /* i/o: Gain Q18 */ - const Word16 extl, /* i : extension layer */ - Word32 extl_brate /* i : extension layer bitrate */ - ,Word16 *rf_gainFrame_ind -) + Encoder_State *st_fx, /* i/o: encoder state structure */ + Word32 *GainFrame, /* i/o: Gain Q18 */ + const Word16 extl, /* i : extension layer */ + Word32 extl_brate /* i : extension layer bitrate */ + , + Word16 *rf_gainFrame_ind ) { Word16 idxFrameGain; Word32 Q_GainFrame; @@ -2991,19 +2982,19 @@ static void QuantizeSHBframegain_fx( TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; RF_ENC_HANDLE hRF = st_fx->hRF; - IF( EQ_16(extl, WB_TBE)) + IF( EQ_16( extl, WB_TBE ) ) { determine_gain_weights_fx( GainFrame, &( Unit_weights1 ), 1 ); - IF( EQ_32(extl_brate,WB_TBE_0k35)) + IF( EQ_32( extl_brate, WB_TBE_0k35 ) ) { singlevectortest_gain_fx( GainFrame, 1, 1 << NUM_BITS_SHB_FrameGain_LBR_WB, &idxFrameGain, &Q_GainFrame, SHBCB_FrameGain16_fx ); test(); - IF( GT_32( Q_GainFrame, L_shl( Mult_32_16( *GainFrame, 17367 ), 1 ) )&&idxFrameGain>0) /* 1.06 = +0.5 dB */ + IF( GT_32( Q_GainFrame, L_shl( Mult_32_16( *GainFrame, 17367 ), 1 ) ) && idxFrameGain > 0 ) /* 1.06 = +0.5 dB */ { idxFrameGain--; - Q_GainFrame = L_add(SHBCB_FrameGain16_fx[idxFrameGain], 0); /* Q18 */ + Q_GainFrame = L_add( SHBCB_FrameGain16_fx[idxFrameGain], 0 ); /* Q18 */ } hBWE_TD->gFrame_WB = idxFrameGain; move16(); @@ -3012,12 +3003,12 @@ static void QuantizeSHBframegain_fx( ELSE { singlevectortest_gain_fx( GainFrame, 1, - 1 << NUM_BITS_SHB_FrameGain, &idxFrameGain, &Q_GainFrame, - SHBCB_FrameGain64_fx ); + 1 << NUM_BITS_SHB_FrameGain, &idxFrameGain, &Q_GainFrame, + SHBCB_FrameGain64_fx ); push_indice_fx( st_fx->hBstr, IND_SHB_FRAMEGAIN, idxFrameGain, NUM_BITS_SHB_FrameGain ); *rf_gainFrame_ind = idxFrameGain; - move16(); /* Q18 */ + move16(); /* Q18 */ } } ELSE @@ -3037,16 +3028,16 @@ static void QuantizeSHBframegain_fx( } exp = norm_s( SHB_GAIN_QDELTA_FX_15 ); - tmp = div_s( shl(1, sub(14, exp)), SHB_GAIN_QDELTA_FX_15 ); + tmp = div_s( shl( 1, sub( 14, exp ) ), SHB_GAIN_QDELTA_FX_15 ); L_tmp = Mult_32_16( L_sub( GainFrameLog, SHB_GAIN_QLOW_FX_16 ), tmp ); - idxFrameGain = extract_l( L_shr( L_add( L_tmp, shl(1, sub(14, exp)) ), sub(15, exp) ) ); /*Q0*/ - IF( GT_16( idxFrameGain, ( 1 << NUM_BITS_SHB_FRAMEGAIN ) - 1 )) + idxFrameGain = extract_l( L_shr( L_add( L_tmp, shl( 1, sub( 14, exp ) ) ), sub( 15, exp ) ) ); /*Q0*/ + IF( GT_16( idxFrameGain, ( 1 << NUM_BITS_SHB_FRAMEGAIN ) - 1 ) ) { idxFrameGain = sub( ( 1 << NUM_BITS_SHB_FRAMEGAIN ), 1 ); } ELSE { - if( idxFrameGain < 0 ) + if ( idxFrameGain < 0 ) { idxFrameGain = 0; move16(); @@ -3056,63 +3047,61 @@ static void QuantizeSHBframegain_fx( L_tmp = SHB_GAIN_QLOW_FX_16; Q_GainFrame = L_mac( L_tmp, idxFrameGain, SHB_GAIN_QDELTA_FX_15 ); - WHILE( GT_32( Q_GainFrame, L_add( GainFrameLog, 4866 ) )&& - idxFrameGain != 0 ) + WHILE( GT_32( Q_GainFrame, L_add( GainFrameLog, 4866 ) ) && + idxFrameGain != 0 ) { - idxFrameGain = sub(idxFrameGain, 1); + idxFrameGain = sub( idxFrameGain, 1 ); Q_GainFrame = L_mac0( SHB_GAIN_QLOW_FX_16, idxFrameGain, SHB_GAIN_QDELTA_FX_16 ); } /* Q_GainFrame = (float) pow(10.0, Q_GainFrame ); */ /* i: Q_GainFrame in Q16 */ L_tmp = Mult_32_16( Q_GainFrame, 27213 ); /* *3.321928 in Q13 -> Q25 */ - L_tmp = L_shr( L_tmp, -2 ); /* From Q26 to Q16 */ + L_tmp = L_shr( L_tmp, -2 ); /* From Q26 to Q16 */ frac = L_Extract_lc( L_tmp, &exp ); Q_GainFrame = Pow2( 30, frac ); - exp = sub ( exp, 30) ; + exp = sub( exp, 30 ); Q_GainFrame = L_shl( Q_GainFrame, exp + 18 ); /* Q18 */ hBWE_TD->idxFrameGain = idxFrameGain; move16(); - IF ( NE_16( st_fx->codec_mode, MODE2 )) + IF( NE_16( st_fx->codec_mode, MODE2 ) ) { push_indice_fx( st_fx->hBstr, IND_SHB_FRAMEGAIN, idxFrameGain, NUM_BITS_SHB_FRAMEGAIN ); } *rf_gainFrame_ind = idxFrameGain; } - IF( EQ_16(st_fx->rf_mode,1)) - { + IF( EQ_16( st_fx->rf_mode, 1 ) ){ /*Currently intended for SWB only. Modify for WB is needed later!*/ - IF( EQ_16(hRF->rf_frame_type,RF_NELP)) - { - *rf_gainFrame_ind = idxFrameGain; /* NELP Frame uses full 5 bits */ - } - ELSE /*RF_ALLPRED, RF_GENPRED, RF_NOPRED modes*/ - { - IF(*GainFrame <= 327680 /*1.25 in Q18*/) /* [0 to 1.25] range --> 0.5*/ - { - *rf_gainFrame_ind = 0; - } - ELSE IF(*GainFrame <= 786432 /*3 in Q18*/) /* (1.25 to 3] --> 2 */ - { - *rf_gainFrame_ind = 1; - } - ELSE IF(*GainFrame <= 1572864 /*6 in Q18*/) /* (3 to 6] --> 4 */ - { - *rf_gainFrame_ind = 2; - } - ELSE /* (6 to Inf) --> 8 */ - { - *rf_gainFrame_ind = 3; - } - } + IF( EQ_16( hRF->rf_frame_type, RF_NELP ) ){ + *rf_gainFrame_ind = idxFrameGain; /* NELP Frame uses full 5 bits */ +} +ELSE /*RF_ALLPRED, RF_GENPRED, RF_NOPRED modes*/ +{ + IF( *GainFrame <= 327680 /*1.25 in Q18*/ ) /* [0 to 1.25] range --> 0.5*/ + { + *rf_gainFrame_ind = 0; + } + ELSE IF( *GainFrame <= 786432 /*3 in Q18*/ ) /* (1.25 to 3] --> 2 */ + { + *rf_gainFrame_ind = 1; + } + ELSE IF( *GainFrame <= 1572864 /*6 in Q18*/ ) /* (3 to 6] --> 4 */ + { + *rf_gainFrame_ind = 2; } + ELSE /* (6 to Inf) --> 8 */ + { + *rf_gainFrame_ind = 3; + } +} +} - *GainFrame = Q_GainFrame; - move32(); /* Q18 */ +*GainFrame = Q_GainFrame; +move32(); /* Q18 */ - return; +return; } @@ -3134,10 +3123,10 @@ static void QuantizeSHBframegain_fx( /* RETURN ARGUMENTS : */ /* _ None */ /*------------------------------------------------------------*/ -static void determine_gain_weights_fx ( - const Word32* gain, /* i : Gain parameter Q18 */ - Word16* weights, /* o : gain weights Q12/Q6*/ - const Word16 dims /* i : number of gains */ ) +static void determine_gain_weights_fx( + const Word32 *gain, /* i : Gain parameter Q18 */ + Word16 *weights, /* o : gain weights Q12/Q6*/ + const Word16 dims /* i : number of gains */ ) { Word16 j; Word16 exp, exp1, frac, tmp, exp2; @@ -3148,7 +3137,7 @@ static void determine_gain_weights_fx ( FOR( j = 0; j < dims; j++ ) { - IF( GT_32(gain[j],8))/* 8 = 0.001 in Q13 */ + IF( GT_32( gain[j], 8 ) ) /* 8 = 0.001 in Q13 */ { /*weights[j] = (float)(pow (fabs (gain[j]), -0.9f)); = pow(2,(-0.9)*log2(gain[j])) */ exp1 = norm_l( gain[j] ); @@ -3160,22 +3149,22 @@ static void determine_gain_weights_fx ( frac = L_Extract_lc( L_tmp, &exp ); tmp = extract_l( Pow2( 14, frac ) ); /* Q14 */ - exp2 = sub(exp,8); - if( LE_16(exp1,21)) + exp2 = sub( exp, 8 ); + if ( LE_16( exp1, 21 ) ) { - exp2 = sub(exp,2); + exp2 = sub( exp, 2 ); } #ifdef BASOP_NOGLOB - weights[j] = shl_o( tmp, exp2, &Overflow); + weights[j] = shl_o( tmp, exp2, &Overflow ); #else - weights[j] = shl( tmp, exp2); + weights[j] = shl( tmp, exp2 ); #endif move16(); /* Q12 */ } ELSE { weights[j] = 32076; - move16();/* (501.187233628f) in Q6*/ + move16(); /* (501.187233628f) in Q6*/ } } @@ -3183,8 +3172,6 @@ static void determine_gain_weights_fx ( } - - /*==============================================================================*/ /* FUNCTION : static singlevectortest_gain_fx () */ /*------------------------------------------------------------------------------*/ @@ -3207,13 +3194,13 @@ static void determine_gain_weights_fx ( /* RETURN ARGUMENTS : */ /* _ None */ /*------------------------------------------------------------------------------*/ -static void singlevectortest_gain_fx ( - const Word32* inp, /* i : input gain vector Q18*/ - const Word16 dimen, /* i : dimension of the input vector */ - const Word16 cb_size, /* i : codebook size */ - Word16* index, /* o : quanitzation index */ - Word32* recon, /* o : Reconstruction Q18 */ - const Word32* codebook +static void singlevectortest_gain_fx( + const Word32 *inp, /* i : input gain vector Q18*/ + const Word16 dimen, /* i : dimension of the input vector */ + const Word16 cb_size, /* i : codebook size */ + Word16 *index, /* o : quanitzation index */ + Word32 *recon, /* o : Reconstruction Q18 */ + const Word32 *codebook /* i : Codebook Q18*/ ) { Word16 k, interNum, flag; @@ -3239,7 +3226,7 @@ static void singlevectortest_gain_fx ( IF( flag == 0 ) { meanQ = sum32_fx( codebook + dimen * least[k], dimen ); /* Q18 */ - IF( LE_32( meanQ, L_tmp )) + IF( LE_32( meanQ, L_tmp ) ) { flag = 1; move16(); @@ -3254,8 +3241,6 @@ static void singlevectortest_gain_fx ( } - - /*==============================================================================*/ /* FUNCTION : return_M_Least_fx_GainFrame () */ /*------------------------------------------------------------------------------*/ @@ -3279,11 +3264,11 @@ static void singlevectortest_gain_fx ( /* _ None */ /*------------------------------------------------------------------------------*/ static void return_M_Least_fx_GainFrame( - const Word32* inp, /* i: input Q18*/ - const Word32* codebook, /* i: codebook Q18*/ - const Word16 num_grp, /* i: number of centroids */ - const Word16 interNum, /* i: number on short list prior to 2nd stage search*/ - Word16* least /* o: return value */ ) + const Word32 *inp, /* i: input Q18*/ + const Word32 *codebook, /* i: codebook Q18*/ + const Word16 num_grp, /* i: number of centroids */ + const Word16 interNum, /* i: number on short list prior to 2nd stage search*/ + Word16 *least /* o: return value */ ) { Word16 i, k; Word32 distance[1024], mindist; @@ -3291,7 +3276,7 @@ static void return_M_Least_fx_GainFrame( Word16 n; Word32 diff[1024]; Word32 max_diff; - mindist = L_add(MAX_32, 0); + mindist = L_add( MAX_32, 0 ); diff[0] = L_sub( *inp, codebook[0] ); move32(); @@ -3300,12 +3285,12 @@ static void return_M_Least_fx_GainFrame( { diff[i] = L_sub( *inp, codebook[i] ); move32(); - max_diff = L_max(max_diff , L_abs( diff[i] )); + max_diff = L_max( max_diff, L_abs( diff[i] ) ); } n = 31; - if( max_diff != 0 ) + if ( max_diff != 0 ) { - n = norm_l(max_diff); + n = norm_l( max_diff ); } FOR( i = 0; i < num_grp; i++ ) @@ -3316,16 +3301,16 @@ static void return_M_Least_fx_GainFrame( FOR( i = 0; i < num_grp; i++ ) { - distance[i] = L_deposit_l(0); + distance[i] = L_deposit_l( 0 ); distance[i] = Mult_32_32( diff[i], diff[i] ); move32(); - if( LT_32( distance[i], mindist )) + if ( LT_32( distance[i], mindist ) ) { least[0] = i; move16(); } - mindist = L_min(mindist,distance[i]); + mindist = L_min( mindist, distance[i] ); } distance[least[0]] = MAX_32; @@ -3333,15 +3318,15 @@ static void return_M_Least_fx_GainFrame( FOR( k = 1; k < interNum; k++ ) { - mindist = L_add(MAX_32, 0); + mindist = L_add( MAX_32, 0 ); FOR( i = 0; i < num_grp; i++ ) { - if( LT_32( distance[i], mindist )) + if ( LT_32( distance[i], mindist ) ) { least[k] = i; move16(); } - mindist = L_min(mindist,distance[i]); + mindist = L_min( mindist, distance[i] ); } distance[least[k]] = MAX_32; @@ -3353,20 +3338,20 @@ static void return_M_Least_fx_GainFrame( /*-------------------------------------------------------------------* -* Quant_lower_LSF_fx() -*-------------------------------------------------------------------*/ + * Quant_lower_LSF_fx() + *-------------------------------------------------------------------*/ static void Quant_lower_LSF_fx( - const Word16 lsf[], /* i : Input LSFs Q15 */ + const Word16 lsf[], /* i : Input LSFs Q15 */ Word16 lsf_q[], /* o : Quantized LSFs Q15 */ Word16 lsf_idx[] /* o : Quantized LSFs indices */ ) { Word16 i; - lsf_idx[0] = ( Word16 )squant_fx( lsf[0], &lsf_q[0], lsf_q_cb_fx[0], lsf_q_cb_size[0] ); + lsf_idx[0] = (Word16) squant_fx( lsf[0], &lsf_q[0], lsf_q_cb_fx[0], lsf_q_cb_size[0] ); FOR( i = 1; i < NUM_Q_LSF; i++ ) { - lsf_idx[i] = ( Word16 )squant_fx( sub( lsf[i], lsf_q[i - 1] ), &lsf_q[i], lsf_q_cb_fx[i], lsf_q_cb_size[i] ); + lsf_idx[i] = (Word16) squant_fx( sub( lsf[i], lsf_q[i - 1] ), &lsf_q[i], lsf_q_cb_fx[i], lsf_q_cb_size[i] ); move16(); lsf_q[i] = add( lsf_q[i - 1], lsf_q[i] ); move16(); @@ -3377,12 +3362,12 @@ static void Quant_lower_LSF_fx( /*-------------------------------------------------------------------* -* Quant_mirror_point_fx() -*-------------------------------------------------------------------*/ + * Quant_mirror_point_fx() + *-------------------------------------------------------------------*/ static Word16 Quant_mirror_point_fx( - const Word16 lsf[], /* i : Input LSFs */ - const Word16 lsf_q[], - Word16* m /* o : Mirror point */ + const Word16 lsf[], /* i : Input LSFs */ + const Word16 lsf_q[], + Word16 *m /* o : Mirror point */ ) { Word16 m_diff; @@ -3390,8 +3375,8 @@ static Word16 Quant_mirror_point_fx( m_diff = mult_r( sub( lsf[NUM_Q_LSF], lsf_q[NUM_Q_LSF - 1] ), 16384 ); - m_idx = ( Word16 )squant_fx( m_diff, m, mirror_point_q_cb_fx, - MIRROR_POINT_Q_CB_SIZE ); /*move16(); */ + m_idx = (Word16) squant_fx( m_diff, m, mirror_point_q_cb_fx, + MIRROR_POINT_Q_CB_SIZE ); /*move16(); */ *m = add( lsf_q[NUM_Q_LSF - 1], *m ); move16(); @@ -3400,15 +3385,15 @@ static Word16 Quant_mirror_point_fx( } /*-------------------------------------------------------------------* -* Find_LSF_grid() -* -* Find the best grid for the LSFs -*-------------------------------------------------------------------*/ + * Find_LSF_grid() + * + * Find the best grid for the LSFs + *-------------------------------------------------------------------*/ static Word16 Find_LSF_grid_fx( - const Word16 lsf[], /* i : Input LSFs */ + const Word16 lsf[], /* i : Input LSFs */ Word16 lsf_q[], /* o : Quantized LSFs */ - const Word16 m /* i : Mirror point */ + const Word16 m /* i : Mirror point */ ) { Word16 lsf_map[NUM_MAP_LSF]; @@ -3426,25 +3411,25 @@ static Word16 Find_LSF_grid_fx( Word32 L_tmp; - tmp = shl(m, 1); - lsf_map[0] = sub( tmp, lsf_q[NUM_MAP_LSF-1-0] ); + tmp = shl( m, 1 ); + lsf_map[0] = sub( tmp, lsf_q[NUM_MAP_LSF - 1 - 0] ); move16(); - lsf_map[1] = sub( tmp, lsf_q[NUM_MAP_LSF-1-1] ); + lsf_map[1] = sub( tmp, lsf_q[NUM_MAP_LSF - 1 - 1] ); move16(); - lsf_map[2] = sub( tmp, lsf_q[NUM_MAP_LSF-1-2] ); + lsf_map[2] = sub( tmp, lsf_q[NUM_MAP_LSF - 1 - 2] ); move16(); - lsf_map[3] = sub( tmp, lsf_q[NUM_MAP_LSF-1-3] ); + lsf_map[3] = sub( tmp, lsf_q[NUM_MAP_LSF - 1 - 3] ); move16(); - lsf_map[4] = sub( tmp, lsf_q[NUM_MAP_LSF-1-4] ); + lsf_map[4] = sub( tmp, lsf_q[NUM_MAP_LSF - 1 - 4] ); move16(); - IF( GT_16( m, MAX_LSF_FX_2 )) + IF( GT_16( m, MAX_LSF_FX_2 ) ) { offset = lsf_map[0]; move16(); exp = norm_s( m ); - tmp = div_s( shl(1, sub(14, exp)), m ); + tmp = div_s( shl( 1, sub( 14, exp ) ), m ); L_tmp = L_mult( sub( MAX_LSF_FX, m ), tmp ); scale = round_fx( L_shl( L_tmp, exp + 1 ) ); @@ -3469,10 +3454,10 @@ static Word16 Find_LSF_grid_fx( } } - D_best = L_add(MAX_32, 0); + D_best = L_add( MAX_32, 0 ); FOR( i = 0; i < NUM_LSF_GRIDS; i++ ) { - D = L_deposit_l(0); + D = L_deposit_l( 0 ); FOR( j = 0; j < NUM_MAP_LSF; j++ ) { /*lsf_t[j] = (1 - grid_smoothing[j])*lsf_map[j] + grid_smoothing[j]*grid[i][j]; */ @@ -3487,10 +3472,10 @@ static Word16 Find_LSF_grid_fx( /* D += (lsf_t[j] - lsf[NUM_Q_LSF + j])*(lsf_t[j] - lsf[NUM_Q_LSF + j]); */ } - IF( LT_32( D, D_best )) + IF( LT_32( D, D_best ) ) { Copy( lsf_t, lsf_smooth, NUM_MAP_LSF ); - D_best = L_add(D, 0); + D_best = L_add( D, 0 ); I_best = i; move16(); } @@ -3506,20 +3491,19 @@ static Word16 Find_LSF_grid_fx( } /*-------------------------------------------------------------------* -* gainFrSmooth_En_fx() -* -* Gain frame smoothing and attenuation control -*-------------------------------------------------------------------*/ -static void gainFrSmooth_En_fx(Encoder_State *st_fx, - Word16 *shb_frame_fx, - const Word16 *lpc_shb_fx, - const Word16 *lsp_shb_fx, - Word16 *MA_lsp_shb_spacing, - Word16 *frGainAttenuate, - Word16 *frGainSmoothEn - ) + * gainFrSmooth_En_fx() + * + * Gain frame smoothing and attenuation control + *-------------------------------------------------------------------*/ +static void gainFrSmooth_En_fx( Encoder_State *st_fx, + Word16 *shb_frame_fx, + const Word16 *lpc_shb_fx, + const Word16 *lsp_shb_fx, + Word16 *MA_lsp_shb_spacing, + Word16 *frGainAttenuate, + Word16 *frGainSmoothEn ) { - Word16 temp_shb_frame[L_FRAME16k+L_SHB_LAHEAD]; + Word16 temp_shb_frame[L_FRAME16k + L_SHB_LAHEAD]; Word32 lsp_slow_evol_rate, lsp_fast_evol_rate; Word16 lsp_spacing; @@ -3541,42 +3525,40 @@ static void gainFrSmooth_En_fx(Encoder_State *st_fx, /* estimate the mean square error in lsps from current frame to past frames */ tempQ15_1 = sub( lsp_shb_fx[0], hBWE_TD->lsp_shb_slow_interpl_fx[0] ); tempQ15_2 = sub( lsp_shb_fx[0], hBWE_TD->lsp_shb_fast_interpl_fx[0] ); - lsp_slow_evol_rate = L_mult(tempQ15_1, tempQ15_1 ); - lsp_fast_evol_rate = L_mult(tempQ15_2, tempQ15_2 ); + lsp_slow_evol_rate = L_mult( tempQ15_1, tempQ15_1 ); + lsp_fast_evol_rate = L_mult( tempQ15_2, tempQ15_2 ); /* update the slow and fast lsp interp for next frame */ - tempQ31 = L_mult(hBWE_TD->lsp_shb_slow_interpl_fx[0], 22937 ); - hBWE_TD->lsp_shb_slow_interpl_fx[0] = mac_r(tempQ31, lsp_shb_fx[0], 9830 ); + tempQ31 = L_mult( hBWE_TD->lsp_shb_slow_interpl_fx[0], 22937 ); + hBWE_TD->lsp_shb_slow_interpl_fx[0] = mac_r( tempQ31, lsp_shb_fx[0], 9830 ); move16(); - tempQ31 = L_mult(hBWE_TD->lsp_shb_fast_interpl_fx[0], 9830 ); - hBWE_TD->lsp_shb_fast_interpl_fx[0] = mac_r(tempQ31, lsp_shb_fx[0], 22937 ); + tempQ31 = L_mult( hBWE_TD->lsp_shb_fast_interpl_fx[0], 9830 ); + hBWE_TD->lsp_shb_fast_interpl_fx[0] = mac_r( tempQ31, lsp_shb_fx[0], 22937 ); move16(); FOR( i = 1; i < LPC_SHB_ORDER; i++ ) { - tempQ15_1 = sub(lsp_shb_fx[i], lsp_shb_fx[i-1]); - lsp_spacing = s_min( lsp_spacing, tempQ15_1); + tempQ15_1 = sub( lsp_shb_fx[i], lsp_shb_fx[i - 1] ); + lsp_spacing = s_min( lsp_spacing, tempQ15_1 ); /* estimate the mean square error in lsps from current frame to past frames */ tempQ15_1 = sub( lsp_shb_fx[i], hBWE_TD->lsp_shb_slow_interpl_fx[i] ); tempQ15_2 = sub( lsp_shb_fx[i], hBWE_TD->lsp_shb_fast_interpl_fx[i] ); - lsp_slow_evol_rate = L_mac(lsp_slow_evol_rate, tempQ15_1, tempQ15_1 ); - lsp_fast_evol_rate = L_mac(lsp_fast_evol_rate , tempQ15_2, tempQ15_2 ); + lsp_slow_evol_rate = L_mac( lsp_slow_evol_rate, tempQ15_1, tempQ15_1 ); + lsp_fast_evol_rate = L_mac( lsp_fast_evol_rate, tempQ15_2, tempQ15_2 ); /* update the slow and fast interpolation lsps for next frame */ - tempQ31 = L_mult(hBWE_TD->lsp_shb_slow_interpl_fx[i], 22937 ); - hBWE_TD->lsp_shb_slow_interpl_fx[i] = mac_r(tempQ31, lsp_shb_fx[i], 9830 ); + tempQ31 = L_mult( hBWE_TD->lsp_shb_slow_interpl_fx[i], 22937 ); + hBWE_TD->lsp_shb_slow_interpl_fx[i] = mac_r( tempQ31, lsp_shb_fx[i], 9830 ); move16(); - tempQ31 = L_mult(hBWE_TD->lsp_shb_fast_interpl_fx[i], 9830 ); - hBWE_TD->lsp_shb_fast_interpl_fx[i] = mac_r(tempQ31, lsp_shb_fx[i], 22937 ); + tempQ31 = L_mult( hBWE_TD->lsp_shb_fast_interpl_fx[i], 9830 ); + hBWE_TD->lsp_shb_fast_interpl_fx[i] = mac_r( tempQ31, lsp_shb_fx[i], 22937 ); move16(); } test(); test(); - IF( NE_16( st_fx->last_extl, SWB_TBE ) - && NE_16(st_fx->last_extl, FB_TBE) - && LT_16( lsp_spacing, 262 ) ) + IF( NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) && LT_16( lsp_spacing, 262 ) ) { hBWE_TD->lsp_shb_spacing_fx[0] = lsp_spacing; move16(); @@ -3586,14 +3568,14 @@ static void gainFrSmooth_En_fx(Encoder_State *st_fx, move16(); hBWE_TD->prev_frGainAtten = 1; move16(); - set16_fx(hBWE_TD->shb_inv_filt_mem_fx, 0, LPC_SHB_ORDER); + set16_fx( hBWE_TD->shb_inv_filt_mem_fx, 0, LPC_SHB_ORDER ); } /* Estimate the moving average LSP spacing */ - tempQ31 = L_mult(hBWE_TD->lsp_shb_spacing_fx[0], 3277); /* 0.1f */ - tempQ31 = L_mac(tempQ31, hBWE_TD->lsp_shb_spacing_fx[1], 6553); /* 0.2f */ - tempQ31 = L_mac(tempQ31, hBWE_TD->lsp_shb_spacing_fx[2], 9830); /* 0.3f */ - *MA_lsp_shb_spacing = mac_r(tempQ31, lsp_spacing, 13107); /* 0.4f */ + tempQ31 = L_mult( hBWE_TD->lsp_shb_spacing_fx[0], 3277 ); /* 0.1f */ + tempQ31 = L_mac( tempQ31, hBWE_TD->lsp_shb_spacing_fx[1], 6553 ); /* 0.2f */ + tempQ31 = L_mac( tempQ31, hBWE_TD->lsp_shb_spacing_fx[2], 9830 ); /* 0.3f */ + *MA_lsp_shb_spacing = mac_r( tempQ31, lsp_spacing, 13107 ); /* 0.4f */ hBWE_TD->lsp_shb_spacing_fx[0] = hBWE_TD->lsp_shb_spacing_fx[1]; move16(); @@ -3605,43 +3587,41 @@ static void gainFrSmooth_En_fx(Encoder_State *st_fx, test(); test(); test(); - IF( ( LT_16( lsp_spacing, 262 )&&(LT_16(*MA_lsp_shb_spacing,164)||EQ_16(hBWE_TD->prev_frGainAtten,1))) - || LE_16( lsp_spacing, 105 ) ) + IF( ( LT_16( lsp_spacing, 262 ) && ( LT_16( *MA_lsp_shb_spacing, 164 ) || EQ_16( hBWE_TD->prev_frGainAtten, 1 ) ) ) || LE_16( lsp_spacing, 105 ) ) { *frGainAttenuate = 1; move16(); - IF( NE_32(st_fx->total_brate , ACELP_24k40)) + IF( NE_32( st_fx->total_brate, ACELP_24k40 ) ) { Copy( shb_frame_fx, temp_shb_frame, L_FRAME16k + L_SHB_LAHEAD ); - fir_fx( temp_shb_frame, lpc_shb_fx, shb_frame_fx, hBWE_TD->shb_inv_filt_mem_fx, L_FRAME16k + L_SHB_LAHEAD, LPC_SHB_ORDER, 1,3); + fir_fx( temp_shb_frame, lpc_shb_fx, shb_frame_fx, hBWE_TD->shb_inv_filt_mem_fx, L_FRAME16k + L_SHB_LAHEAD, LPC_SHB_ORDER, 1, 3 ); } ELSE { - set16_fx(hBWE_TD->shb_inv_filt_mem_fx, 0, LPC_SHB_ORDER); + set16_fx( hBWE_TD->shb_inv_filt_mem_fx, 0, LPC_SHB_ORDER ); } test(); - IF ( LT_32( lsp_slow_evol_rate, 2147484l/*0.001f Q31*/ )&<_32(lsp_fast_evol_rate,2147484l/*0.001f Q31*/)) + IF( LT_32( lsp_slow_evol_rate, 2147484l /*0.001f Q31*/ ) && LT_32( lsp_fast_evol_rate, 2147484l /*0.001f Q31*/ ) ) { *frGainSmoothEn = 1; move16(); } } - } /*-------------------------------------------------------------------* -* Quant_BWE_LSF() -* -* Quantize super highband spectral envolope -*-------------------------------------------------------------------*/ + * Quant_BWE_LSF() + * + * Quantize super highband spectral envolope + *-------------------------------------------------------------------*/ static void Quant_BWE_LSF_fx( - Encoder_State* st_fx, /* i/o: encoder state structure */ - const Word16 lsf_shb[], /* i : unquanitzed LSFs */ - Word16 Q_lsfs[] /* o : quanitzed LSFs */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word16 lsf_shb[], /* i : unquanitzed LSFs */ + Word16 Q_lsfs[] /* o : quanitzed LSFs */ ) { Word16 lsf[LPC_SHB_ORDER]; @@ -3661,7 +3641,7 @@ static void Quant_BWE_LSF_fx( move16(); } - Quant_lower_LSF_fx( lsf, lsf_q, lsf_idx); + Quant_lower_LSF_fx( lsf, lsf_q, lsf_idx ); /* i: lsf in Q15 */ /* o: lsf_q in Q15 */ @@ -3669,9 +3649,9 @@ static void Quant_BWE_LSF_fx( { hBWE_TD->lsf_idx[i] = lsf_idx[i]; move16(); - IF( NE_16( st_fx->codec_mode, MODE2 )) + IF( NE_16( st_fx->codec_mode, MODE2 ) ) { - push_indice_fx(hBstr, IND_SHB_LSF, lsf_idx[i], lsf_q_num_bits[i] ); + push_indice_fx( hBstr, IND_SHB_LSF, lsf_idx[i], lsf_q_num_bits[i] ); } } @@ -3679,17 +3659,17 @@ static void Quant_BWE_LSF_fx( hBWE_TD->m_idx = m_idx; move16(); - IF( NE_16( st_fx->codec_mode, MODE2 )) + IF( NE_16( st_fx->codec_mode, MODE2 ) ) { - push_indice_fx(hBstr, IND_SHB_MIRROR, m_idx, MIRROR_POINT_BITS ); + push_indice_fx( hBstr, IND_SHB_MIRROR, m_idx, MIRROR_POINT_BITS ); } grid_idx = Find_LSF_grid_fx( lsf, lsf_q, m ); hBWE_TD->grid_idx = grid_idx; - IF( NE_16( st_fx->codec_mode, MODE2 )) + IF( NE_16( st_fx->codec_mode, MODE2 ) ) { - push_indice_fx(hBstr, IND_SHB_GRID, grid_idx, NUM_LSF_GRID_BITS ); + push_indice_fx( hBstr, IND_SHB_GRID, grid_idx, NUM_LSF_GRID_BITS ); } FOR( i = 0; i < LPC_SHB_ORDER; i++ ) @@ -3708,11 +3688,10 @@ static void Quant_BWE_LSF_fx( *-------------------------------------------------------------------*/ void fb_tbe_enc_fx( - Encoder_State *st, /* i/o: encoder state structure */ - const Word16 new_input[], /* i : input speech at 48 kHz sample rate */ - const Word16 fb_exc[], /* i : FB excitation from the SWB part */ - Word16 Q_fb_exc -) + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 new_input[], /* i : input speech at 48 kHz sample rate */ + const Word16 fb_exc[], /* i : FB excitation from the SWB part */ + Word16 Q_fb_exc ) { Word16 ratio; Word16 tmp_vec[L_FRAME48k]; @@ -3721,8 +3700,8 @@ void fb_tbe_enc_fx( Word16 Sample_Delay_HP; Word32 fb_exc_energy, temp2; Word32 L_tmp; - Word16 tmp,tmp1,tmp2,exp,exp2,exp_norm; - Word16 s_max_value,exp_temp,i; + Word16 tmp, tmp1, tmp2, exp, exp2, exp_norm; + Word16 s_max_value, exp_temp, i; TD_BWE_ENC_HANDLE hBWE_TD = st->hBWE_TD; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; @@ -3730,92 +3709,92 @@ void fb_tbe_enc_fx( s_max_value = 0; FOR( i = 0; i < L_FRAME48k; i++ ) { - s_max_value = s_max(s_max_value,abs_s(new_input[i])); + s_max_value = s_max( s_max_value, abs_s( new_input[i] ) ); } exp_temp = norm_s( s_max_value ); - if( s_max_value == 0 ) + if ( s_max_value == 0 ) { exp_temp = 15; } - exp_temp = sub(exp_temp,1); + exp_temp = sub( exp_temp, 1 ); Copy_Scale_sig( new_input, input_fhb, L_FRAME48k, exp_temp ); - elliptic_bpf_48k_generic_fx( input_fhb, &exp_temp , tmp_vec, hBWE_TD->elliptic_bpf_2_48k_mem_fx, hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q,full_band_bpf_2_fx ); - Sample_Delay_HP = NS2SA(48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS) - L_FRAME48k/2 ; + elliptic_bpf_48k_generic_fx( input_fhb, &exp_temp, tmp_vec, hBWE_TD->elliptic_bpf_2_48k_mem_fx, hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, full_band_bpf_2_fx ); + Sample_Delay_HP = NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) - L_FRAME48k / 2; - IF( NE_16(st->last_extl,FB_TBE)) + IF( NE_16( st->last_extl, FB_TBE ) ) { set16_fx( hBWE_TD->old_input_fhb_fx, 0, Sample_Delay_HP ); hBWE_TD->old_input_fhb_fx_Q = 0; move16(); set16_fx( tmp_vec, 0, L_FRAME16k ); } - Copy_Scale_sig( hBWE_TD->old_input_fhb_fx, hBWE_TD->old_input_fhb_fx, Sample_Delay_HP, sub(exp_temp,hBWE_TD->old_input_fhb_fx_Q) ); + Copy_Scale_sig( hBWE_TD->old_input_fhb_fx, hBWE_TD->old_input_fhb_fx, Sample_Delay_HP, sub( exp_temp, hBWE_TD->old_input_fhb_fx_Q ) ); hBWE_TD->old_input_fhb_fx_Q = exp_temp; Copy( hBWE_TD->old_input_fhb_fx, input_fhb, Sample_Delay_HP ); - Copy( tmp_vec, input_fhb + Sample_Delay_HP, L_FRAME48k-Sample_Delay_HP ); + Copy( tmp_vec, input_fhb + Sample_Delay_HP, L_FRAME48k - Sample_Delay_HP ); Copy( tmp_vec + L_FRAME48k - Sample_Delay_HP, hBWE_TD->old_input_fhb_fx, Sample_Delay_HP ); - temp2 = sum2_fx_mod( input_fhb, L_FRAME48k/2 );/* Q11 */ + temp2 = sum2_fx_mod( input_fhb, L_FRAME48k / 2 ); /* Q11 */ #ifdef BASOP_NOGLOB - temp2 = L_add_o(temp2,L_shl_o(hBWE_TD->prev_fb_energy_fx,sub(sub(add(exp_temp,exp_temp),6),hBWE_TD->prev_fb_energy_fx_Q), &Overflow), &Overflow);/* Q11 */ + temp2 = L_add_o( temp2, L_shl_o( hBWE_TD->prev_fb_energy_fx, sub( sub( add( exp_temp, exp_temp ), 6 ), hBWE_TD->prev_fb_energy_fx_Q ), &Overflow ), &Overflow ); /* Q11 */ #else - temp2 = L_add(temp2,L_shl(hBWE_TD->prev_fb_energy_fx,sub(sub(add(exp_temp,exp_temp),6),hBWE_TD->prev_fb_energy_fx_Q)));/* Q11 */ + temp2 = L_add( temp2, L_shl( hBWE_TD->prev_fb_energy_fx, sub( sub( add( exp_temp, exp_temp ), 6 ), hBWE_TD->prev_fb_energy_fx_Q ) ) ); /* Q11 */ #endif - hBWE_TD->prev_fb_energy_fx = sum2_fx_mod( input_fhb + L_FRAME48k/2, L_FRAME48k/2 );/*Q11*/ - hBWE_TD->prev_fb_energy_fx_Q = sub(add(exp_temp,exp_temp),6); - fb_exc_energy = sum2_fx_mod( fb_exc, L_FRAME16k );/* Q(2*Q_fb_exc+1 -7) */ + hBWE_TD->prev_fb_energy_fx = sum2_fx_mod( input_fhb + L_FRAME48k / 2, L_FRAME48k / 2 ); /*Q11*/ + hBWE_TD->prev_fb_energy_fx_Q = sub( add( exp_temp, exp_temp ), 6 ); + fb_exc_energy = sum2_fx_mod( fb_exc, L_FRAME16k ); /* Q(2*Q_fb_exc+1 -7) */ /*ratio = (float) sqrt( temp2 / fb_exc_energy );*/ - L_tmp = L_max(1, temp2); /*Q6*/ - exp = norm_l(L_tmp); - tmp = extract_h(L_shl(L_tmp, exp)); - exp = sub(sub(31,sub(add(exp_temp,exp_temp),8)), exp); /* in Q15 (L_tmp in Q6)*/ + L_tmp = L_max( 1, temp2 ); /*Q6*/ + exp = norm_l( L_tmp ); + tmp = extract_h( L_shl( L_tmp, exp ) ); + exp = sub( sub( 31, sub( add( exp_temp, exp_temp ), 8 ) ), exp ); /* in Q15 (L_tmp in Q6)*/ - exp2 = norm_l(fb_exc_energy); - tmp2 = extract_h(L_shl(fb_exc_energy, exp2)); - tmp1 = sub(add(Q_fb_exc,Q_fb_exc), 8);/*1 - 9*/ - exp2 = sub(sub(31,tmp1), exp2); /* in Q15 (L_tmp in Q6)*/ + exp2 = norm_l( fb_exc_energy ); + tmp2 = extract_h( L_shl( fb_exc_energy, exp2 ) ); + tmp1 = sub( add( Q_fb_exc, Q_fb_exc ), 8 ); /*1 - 9*/ + exp2 = sub( sub( 31, tmp1 ), exp2 ); /* in Q15 (L_tmp in Q6)*/ - exp = sub(exp2, exp); /* Denormalize and substract */ - IF (GT_16(tmp2, tmp)) + exp = sub( exp2, exp ); /* Denormalize and substract */ + IF( GT_16( tmp2, tmp ) ) { - tmp2 = shr(tmp2, 1); - exp = add(exp, 1); + tmp2 = shr( tmp2, 1 ); + exp = add( exp, 1 ); } IF( 0 != tmp ) { - tmp = div_s(tmp2, tmp); - L_tmp = L_deposit_h(tmp); - L_tmp = Isqrt_lc(L_tmp, &exp); /*Q(31-exp)*/ + tmp = div_s( tmp2, tmp ); + L_tmp = L_deposit_h( tmp ); + L_tmp = Isqrt_lc( L_tmp, &exp ); /*Q(31-exp)*/ #ifdef BASOP_NOGLOB - L_tmp = L_max(L_shr_o(L_tmp,sub(31,exp), &Overflow),0x1);/* Q0 */ + L_tmp = L_max( L_shr_o( L_tmp, sub( 31, exp ), &Overflow ), 0x1 ); /* Q0 */ #else - L_tmp = L_max(L_shr(L_tmp,sub(31,exp)),0x1);/* Q0 */ + L_tmp = L_max( L_shr( L_tmp, sub( 31, exp ) ), 0x1 ); /* Q0 */ #endif } ELSE { - L_tmp =0; + L_tmp = 0; } /* idxGain = (short)( log2_f ((float)ratio) + 0.5f ); idxGain = max( 0, min(15,idxGain) ); */ ratio = 0; - IF(GE_32(L_tmp,32768)) + IF( GE_32( L_tmp, 32768 ) ) { idxGain = 15; } ELSE { - ratio = extract_l(L_tmp); - exp_norm = norm_s(ratio); - idxGain = sub(14, exp_norm); - idxGain = s_max(0,idxGain); + ratio = extract_l( L_tmp ); + exp_norm = norm_s( ratio ); + idxGain = sub( 14, exp_norm ); + idxGain = s_max( 0, idxGain ); } - IF(GT_16(idxGain,2)&<_16(idxGain,15)&>_16(ratio,add(shl(2,sub(idxGain,1)),shl(2,sub(idxGain,2))))) + IF( GT_16( idxGain, 2 ) && LT_16( idxGain, 15 ) && GT_16( ratio, add( shl( 2, sub( idxGain, 1 ) ), shl( 2, sub( idxGain, 2 ) ) ) ) ) { - idxGain = add(idxGain,1); + idxGain = add( idxGain, 1 ); } /* ratio = (float)(1 << idxGain);*/ @@ -3831,7 +3810,7 @@ void fb_tbe_enc_fx( return; } void tbe_write_bitstream_fx( - Encoder_State *st_fx /* i/o: encoder state structure */ + Encoder_State *st_fx /* i/o: encoder state structure */ ) { Word16 i; @@ -3844,114 +3823,112 @@ void tbe_write_bitstream_fx( test(); test(); test(); - IF ( ( st_fx->rf_mode || EQ_32( st_fx->total_brate, ACELP_9k60 ))&&(EQ_16(st_fx->bwidth,WB))) + IF( ( st_fx->rf_mode || EQ_32( st_fx->total_brate, ACELP_9k60 ) ) && ( EQ_16( st_fx->bwidth, WB ) ) ) { /* WB LSF */ - push_next_indice_fx(hBstr, hBWE_TD->lsf_WB, NUM_BITS_LBR_WB_LSF ); + push_next_indice_fx( hBstr, hBWE_TD->lsf_WB, NUM_BITS_LBR_WB_LSF ); /* WB frame */ - push_next_indice_fx(hBstr, hBWE_TD->gFrame_WB, NUM_BITS_SHB_FrameGain_LBR_WB ); + push_next_indice_fx( hBstr, hBWE_TD->gFrame_WB, NUM_BITS_SHB_FrameGain_LBR_WB ); } - ELSE IF ( ( GE_32( st_fx->total_brate, ACELP_9k60 ))&&(LE_32(st_fx->total_brate,ACELP_32k))&& - ( ( EQ_16( st_fx->bwidth, SWB ) ) || ( EQ_16( st_fx->bwidth, FB ) ) ) ) + ELSE IF( ( GE_32( st_fx->total_brate, ACELP_9k60 ) ) && ( LE_32( st_fx->total_brate, ACELP_32k ) ) && + ( ( EQ_16( st_fx->bwidth, SWB ) ) || ( EQ_16( st_fx->bwidth, FB ) ) ) ) { /* LSF coefficients */ test(); - IF( (EQ_16(st_fx->rf_mode,1))||EQ_32(st_fx->total_brate,ACELP_9k60)) + IF( ( EQ_16( st_fx->rf_mode, 1 ) ) || EQ_32( st_fx->total_brate, ACELP_9k60 ) ) { - push_next_indice_fx(hBstr, hBWE_TD->lsf_idx[0], 8 ); + push_next_indice_fx( hBstr, hBWE_TD->lsf_idx[0], 8 ); } ELSE { - FOR (i = 0; i < NUM_Q_LSF; i++) + FOR( i = 0; i < NUM_Q_LSF; i++ ) { - push_next_indice_fx(hBstr, hBWE_TD->lsf_idx[i], lsf_q_num_bits[i] ); + push_next_indice_fx( hBstr, hBWE_TD->lsf_idx[i], lsf_q_num_bits[i] ); } /* LSF mirror points */ - push_next_indice_fx(hBstr, hBWE_TD->m_idx, MIRROR_POINT_BITS ); + push_next_indice_fx( hBstr, hBWE_TD->m_idx, MIRROR_POINT_BITS ); /* LSF grid points */ - push_next_indice_fx(hBstr, hBWE_TD->grid_idx, NUM_LSF_GRID_BITS ); + push_next_indice_fx( hBstr, hBWE_TD->grid_idx, NUM_LSF_GRID_BITS ); } /* Gain shape */ - push_next_indice_fx(hBstr, hBWE_TD->idxSubGains, NUM_BITS_SHB_SUBGAINS ); + push_next_indice_fx( hBstr, hBWE_TD->idxSubGains, NUM_BITS_SHB_SUBGAINS ); /* frame gain */ - push_next_indice_fx(hBstr, hBWE_TD->idxFrameGain, NUM_BITS_SHB_FRAMEGAIN ); + push_next_indice_fx( hBstr, hBWE_TD->idxFrameGain, NUM_BITS_SHB_FRAMEGAIN ); - IF ( GE_32( st_fx->total_brate, ACELP_24k40 )) + IF( GE_32( st_fx->total_brate, ACELP_24k40 ) ) { /* sub frame energy*/ - push_next_indice_fx(hBstr, hBWE_TD->idx_shb_fr_gain, NUM_BITS_SHB_ENER_SF ); + push_next_indice_fx( hBstr, hBWE_TD->idx_shb_fr_gain, NUM_BITS_SHB_ENER_SF ); /* gain shapes residual */ - FOR (i = 0; i < NB_SUBFR16k; i++) + FOR( i = 0; i < NB_SUBFR16k; i++ ) { - push_next_indice_fx(hBstr, hBWE_TD->idx_res_gs[i], NUM_BITS_SHB_RES_GS ); + push_next_indice_fx( hBstr, hBWE_TD->idx_res_gs[i], NUM_BITS_SHB_RES_GS ); } /* voicing factor */ - push_next_indice_fx(hBstr, hBWE_TD->idx_mixFac, NUM_BITS_SHB_VF ); + push_next_indice_fx( hBstr, hBWE_TD->idx_mixFac, NUM_BITS_SHB_VF ); } - IF( EQ_16(st_fx->tec_tfa, 1)) + IF( EQ_16( st_fx->tec_tfa, 1 ) ) { - push_next_indice_fx(hBstr, st_fx->tec_flag, BITS_TEC ); - push_next_indice_fx(hBstr, st_fx->tfa_flag, BITS_TFA ); + push_next_indice_fx( hBstr, st_fx->tec_flag, BITS_TEC ); + push_next_indice_fx( hBstr, st_fx->tfa_flag, BITS_TFA ); } } - IF ( EQ_16( st_fx->bwidth, FB )) + IF( EQ_16( st_fx->bwidth, FB ) ) { - push_next_indice_fx(hBstr, hBWE_TD->idxGain, 4 ); + push_next_indice_fx( hBstr, hBWE_TD->idxGain, 4 ); } } void TBEreset_enc_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - Word16 bandwidth /* i : bandwidth mode */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + Word16 bandwidth /* i : bandwidth mode */ ) { TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; - IF( NE_16(st_fx->last_core,ACELP_CORE)) + IF( NE_16( st_fx->last_core, ACELP_CORE ) ) { set16_fx( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); - hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l(0); + hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 ); st_fx->prev_Q_bwe_exc = 31; move16(); } test(); - IF( EQ_16( bandwidth, WB )) + IF( EQ_16( bandwidth, WB ) ) { - wb_tbe_extras_reset_fx(hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx ); + wb_tbe_extras_reset_fx( hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx ); set16_fx( hBWE_TD->mem_genSHBexc_filt_down_shb_fx, 0, 7 ); set16_fx( hBWE_TD->state_lpc_syn_fx, 0, 10 ); - set16_fx( hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD/4 ); + set16_fx( hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD / 4 ); set16_fx( hBWE_TD->syn_overlap_fx, 0, L_SHB_LAHEAD ); set32_fx( hBWE_TD->mem_csfilt_fx, 0, 2 ); } - ELSE IF( ( EQ_16( bandwidth, SWB ))||(EQ_16(bandwidth,FB))) + ELSE IF( ( EQ_16( bandwidth, SWB ) ) || ( EQ_16( bandwidth, FB ) ) ) { - set16_fx( hBWE_TD->state_ana_filt_shb_fx, 0, (2*ALLPASSSECTIONS_STEEP+1) ); + set16_fx( hBWE_TD->state_ana_filt_shb_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); swb_tbe_reset_fx( hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, - hBWE_TD->syn_overlap_fx, hBWE_TD->state_syn_shbexc_fx, &(hBWE_TD->tbe_demph_fx), &(hBWE_TD->tbe_premph_fx), - hBWE_TD->mem_stp_swb_fx, &(hBWE_TD->gain_prec_swb_fx) ); + hBWE_TD->syn_overlap_fx, hBWE_TD->state_syn_shbexc_fx, &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), + hBWE_TD->mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ) ); - IF( EQ_16( bandwidth, FB )) + IF( EQ_16( bandwidth, FB ) ) { set16_fx( hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); hBWE_TD->fb_tbe_demph_fx = 0; move16(); - fb_tbe_reset_enc_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx, &hBWE_TD->prev_fb_energy_fx,hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q,&hBWE_TD->prev_fb_energy_fx_Q); + fb_tbe_reset_enc_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx, &hBWE_TD->prev_fb_energy_fx, hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, &hBWE_TD->prev_fb_energy_fx_Q ); } } } - - diff --git a/lib_enc/tcq_core_enc_fx.c b/lib_enc/tcq_core_enc_fx.c index 5a47b1dad..6de4560d5 100644 --- a/lib_enc/tcq_core_enc_fx.c +++ b/lib_enc/tcq_core_enc_fx.c @@ -3,26 +3,26 @@ ====================================================================================*/ #include #include -#include "options.h" /* Compilation switches */ +#include "options.h" /* Compilation switches */ #include "cnst.h" //#include "prot_fx.h" #include "rom_com.h" #include "ivas_error.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ ivas_error tcq_core_LR_enc_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - Word16 inp_vector_fx[], /* x5 */ - const Word32 coefs_norm_fx[], /* Q12 */ - Word32 coefs_quant_fx[], /* Q12 */ - const Word16 bit_budget, /* number of bits */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 inp_vector_fx[], /* x5 */ + const Word32 coefs_norm_fx[], /* Q12 */ + Word32 coefs_quant_fx[], /* Q12 */ + const Word16 bit_budget, /* number of bits */ const Word16 BANDS, const Word16 *sfm_start, const Word16 *sfm_end, const Word16 *sfmsize, - Word32 *R_fx, /* Q16 */ + Word32 *R_fx, /* Q16 */ Word16 *npulses, Word16 *k_sort, const Word16 *p2a_flags, @@ -30,12 +30,11 @@ ivas_error tcq_core_LR_enc_fx( const Word16 *last_bitalloc, const Word16 input_frame, const Word16 adjustFlag, - const Word16 is_transient -) + const Word16 is_transient ) { Word16 i, j, k, size, nb_bytes; - Word16 USQ_TCQ[NB_SFM]; /* TCQ is selected by default*/ + Word16 USQ_TCQ[NB_SFM]; /* TCQ is selected by default*/ Word16 coefs_norm_dec_fx[L_FRAME32k]; /* New output buffer (TCQ+USQ)*/ Word32 savedstates[TCQ_MAX_BAND_SIZE]; ARCODEC arenc_fx, *parenc_fx; @@ -45,7 +44,7 @@ ivas_error tcq_core_LR_enc_fx( Word16 flag_wbnb = 0; Word16 lsbtcq_bits = TCQ_AMP; - Word16 tcq_arbits = 2; + Word16 tcq_arbits = 2; Word16 nzb = 0; Word16 nzbands = 0; Word16 bcount = 0; @@ -69,26 +68,26 @@ ivas_error tcq_core_LR_enc_fx( error = IVAS_ERR_OK; move16(); - set16_fx(dpath, 0, 280); - set32_fx(abuffer_fx, 0, MAX_PULSES); - set32_fx(sbuffer_fx, 0, MAX_PULSES); - set16_fx(mbuffer_fx, 0, MAX_PULSES); + set16_fx( dpath, 0, 280 ); + set32_fx( abuffer_fx, 0, MAX_PULSES ); + set32_fx( sbuffer_fx, 0, MAX_PULSES ); + set16_fx( mbuffer_fx, 0, MAX_PULSES ); /* initialization */ - set32_fx(Rk_sort_fx, 0, NB_SFM); - set16_fx(USQ_TCQ, 0, NB_SFM); - set16_fx(coefs_norm_dec_fx, 0, L_FRAME32k); + set32_fx( Rk_sort_fx, 0, NB_SFM ); + set16_fx( USQ_TCQ, 0, NB_SFM ); + set16_fx( coefs_norm_dec_fx, 0, L_FRAME32k ); - InitLSBTCQ_fx(&bcount); + InitLSBTCQ_fx( &bcount ); test(); test(); - IF( input_frame <= L_FRAME16k && adjustFlag == 0 && is_transient == 0 ) + IF( input_frame <= L_FRAME16k && adjustFlag == 0 && is_transient == 0 ) { flag_wbnb = 1; move16(); lsbtcq_bits = 0; move16(); - tcq_arbits = 0; + tcq_arbits = 0; move16(); } @@ -98,19 +97,19 @@ ivas_error tcq_core_LR_enc_fx( pbs_fx->curPos = 7; move16(); - pbs_fx->numbits = L_deposit_l(0); - pbs_fx->numByte = L_deposit_l(0); - FOR (i = 0; i < MAX_SIZEBUF_PBITSTREAM; i++) + pbs_fx->numbits = L_deposit_l( 0 ); + pbs_fx->numByte = L_deposit_l( 0 ); + FOR( i = 0; i < MAX_SIZEBUF_PBITSTREAM; i++ ) { pbs_fx->buf[i] = 0; move16(); } - ar_encoder_start_fx(parenc_fx, pbs_fx, L_deposit_l(bit_budget)); + ar_encoder_start_fx( parenc_fx, pbs_fx, L_deposit_l( bit_budget ) ); /* Bits distribution analysis */ - FOR ( i = 0; i < BANDS; i++ ) + FOR( i = 0; i < BANDS; i++ ) { - IF ( GE_32(ar_div(R_fx[i], sfmsize[i]), 49152)) + IF( GE_32( ar_div( R_fx[i], sfmsize[i] ), 49152 ) ) { /* USQ used for high importance bands*/ USQ_TCQ[i] = 1; @@ -126,57 +125,57 @@ ivas_error tcq_core_LR_enc_fx( IF( R_fx[i] > 0 ) { /* nzbands++; */ - nzbands = add(nzbands, 1); + nzbands = add( nzbands, 1 ); } } - FOR ( j = 0; j < BANDS; j++ ) + FOR( j = 0; j < BANDS; j++ ) { - IF ( R_fx[j] > 0 ) + IF( R_fx[j] > 0 ) { nzb++; } } - bsub_fx = L_shl(add(tcq_arbits, lsbtcq_bits), 16); /* Q16 */ - IF( bsub_fx > 0) + bsub_fx = L_shl( add( tcq_arbits, lsbtcq_bits ), 16 ); /* Q16 */ + IF( bsub_fx > 0 ) { - bsub_fx = L_add( bsub_fx, 2048); + bsub_fx = L_add( bsub_fx, 2048 ); } - FOR ( j = BANDS - 1; j >= 0; j-- ) + FOR( j = BANDS - 1; j >= 0; j-- ) { IF( R_fx[j] > 0 ) { - R_fx[j] = L_sub(R_fx[j], ar_div(bsub_fx, nzb)); + R_fx[j] = L_sub( R_fx[j], ar_div( bsub_fx, nzb ) ); - IF( R_fx[j] < 0) + IF( R_fx[j] < 0 ) { - bsub_fx = L_sub(bsub_fx, L_add(ar_div(bsub_fx, nzb), R_fx[j])); - R_fx[j] = L_deposit_l(0); + bsub_fx = L_sub( bsub_fx, L_add( ar_div( bsub_fx, nzb ), R_fx[j] ) ); + R_fx[j] = L_deposit_l( 0 ); } ELSE { - bsub_fx = L_sub(bsub_fx, ar_div(bsub_fx, nzb)); + bsub_fx = L_sub( bsub_fx, ar_div( bsub_fx, nzb ) ); } /* nzb--; */ - nzb = sub(nzb, 1); + nzb = sub( nzb, 1 ); } } /* Sort the bit allocation table (R) in ascending order, figure out number of pulses per band */ - srt_vec_ind_fx(R_fx, Rk_sort_fx, k_sort, BANDS); + srt_vec_ind_fx( R_fx, Rk_sort_fx, k_sort, BANDS ); /* Quantize spectral band shapes using TCQ */ /* Select ISC */ - set32_fx(coefs_quant_fx, 0, sfm_end[BANDS - 1]+1); - Copy32( coefs_norm_fx, coefs_quant_fx,sfm_end[BANDS-1]+1); + set32_fx( coefs_quant_fx, 0, sfm_end[BANDS - 1] + 1 ); + Copy32( coefs_norm_fx, coefs_quant_fx, sfm_end[BANDS - 1] + 1 ); - delta_fx = L_deposit_l(0); - est_frame_bits_fx = L_deposit_l(0); + delta_fx = L_deposit_l( 0 ); + est_frame_bits_fx = L_deposit_l( 0 ); test(); test(); - IF ( LE_16(input_frame, L_FRAME16k)&&adjustFlag==0&&is_transient==0) + IF( LE_16( input_frame, L_FRAME16k ) && adjustFlag == 0 && is_transient == 0 ) { surplus_fx = -131072; move32(); @@ -184,31 +183,31 @@ ivas_error tcq_core_LR_enc_fx( nzbands = 0; move16(); - FOR ( j = 0; j < BANDS; j++ ) + FOR( j = 0; j < BANDS; j++ ) { - IF( NE_16(j, k_num[0])&&NE_16(j,k_num[1])) + IF( NE_16( j, k_num[0] ) && NE_16( j, k_num[1] ) ) { - leftbits = L_add( leftbits, R_fx[k_sort[j]]); - if( R_fx[k_sort[j]] > 0 ) + leftbits = L_add( leftbits, R_fx[k_sort[j]] ); + if ( R_fx[k_sort[j]] > 0 ) { - nzbands = add(nzbands, 1); + nzbands = add( nzbands, 1 ); } } ELSE { - sepbits = L_add( sepbits, R_fx[k_sort[j]]); + sepbits = L_add( sepbits, R_fx[k_sort[j]] ); } } /* Separate the position information from the input signal(coefs_norm) */ /* Gather the NZ coefficients*/ - FOR ( k = 0; k < BANDS; k++) /* Loop through non-zero blocks */ + FOR( k = 0; k < BANDS; k++ ) /* Loop through non-zero blocks */ { test(); - IF ( NE_16(k, k_num[0])&&NE_16(k,k_num[1])) + IF( NE_16( k, k_num[0] ) && NE_16( k, k_num[1] ) ) { test(); test(); - IF ( R_fx[k_sort[k]] > 0 && USQ_TCQ[k_sort[k]] == 0 ) /* Then have non-zero block AND WILL BE ENCODED BY TCQ */ + IF( R_fx[k_sort[k]] > 0 && USQ_TCQ[k_sort[k]] == 0 ) /* Then have non-zero block AND WILL BE ENCODED BY TCQ */ { /* Encode Position Info, NZ Info, Signs */ size = sfmsize[k_sort[k]]; @@ -216,50 +215,46 @@ ivas_error tcq_core_LR_enc_fx( /* Determine scale step, ISC and TCQ quantizer */ GetISCScale_fx( &coefs_quant_fx[sfm_start[k_sort[k]]], size, - L_add( R_fx[k_sort[k]], delta_fx), + L_add( R_fx[k_sort[k]], delta_fx ), /* R_fx[k_sort[k]], */ - &coefs_norm_dec_fx[ sfm_start[ k_sort[k]]], &step_scale_fx[k_sort[k]], &surplus_fx, &pulses_fx, savedstates, 0, &nzp_fx - , 0, 0, 0, 0 - ); - leftbits = L_sub( leftbits, L_add( R_fx[k_sort[k]], delta_fx) ); - npulses[ k_sort[k]] = pulses_fx; + &coefs_norm_dec_fx[sfm_start[k_sort[k]]], &step_scale_fx[k_sort[k]], &surplus_fx, &pulses_fx, savedstates, 0, &nzp_fx, 0, 0, 0, 0 ); + leftbits = L_sub( leftbits, L_add( R_fx[k_sort[k]], delta_fx ) ); + npulses[k_sort[k]] = pulses_fx; move16(); - encode_position_ari_fx( parenc_fx, &coefs_norm_dec_fx[ sfm_start[ k_sort[k]]], size, &est_frame_bits_fx ); - encode_magnitude_tcq_fx( parenc_fx, &coefs_norm_dec_fx[ sfm_start[ k_sort[k]]], size, npulses[k_sort[k]], nzp_fx, savedstates, &est_frame_bits_fx ); - encode_signs_fx( parenc_fx, &coefs_norm_dec_fx[ sfm_start[ k_sort[k]]], size, nzp_fx, &est_frame_bits_fx ); + encode_position_ari_fx( parenc_fx, &coefs_norm_dec_fx[sfm_start[k_sort[k]]], size, &est_frame_bits_fx ); + encode_magnitude_tcq_fx( parenc_fx, &coefs_norm_dec_fx[sfm_start[k_sort[k]]], size, npulses[k_sort[k]], nzp_fx, savedstates, &est_frame_bits_fx ); + encode_signs_fx( parenc_fx, &coefs_norm_dec_fx[sfm_start[k_sort[k]]], size, nzp_fx, &est_frame_bits_fx ); nzbands--; } /* Have USQ coded band */ - ELSE IF( R_fx[k_sort[k]] > 0 && EQ_16(USQ_TCQ[k_sort[k]], 1)) + ELSE IF( R_fx[k_sort[k]] > 0 && EQ_16( USQ_TCQ[k_sort[k]], 1 ) ) { size = sfmsize[k_sort[k]]; move16(); - GetISCScale_fx( &coefs_quant_fx[ sfm_start[ k_sort[k]]], size, - L_add( R_fx[k_sort[k]], delta_fx), + GetISCScale_fx( &coefs_quant_fx[sfm_start[k_sort[k]]], size, + L_add( R_fx[k_sort[k]], delta_fx ), /* R_fx[k_sort[k]], */ - &coefs_norm_dec_fx[ sfm_start[ k_sort[k]]], &step_scale_fx[k_sort[k]], &surplus_fx, &pulses_fx, savedstates, 1, &nzp_fx - , 0, 0, 0, 0 - ); - leftbits = L_sub( leftbits, L_add( R_fx[k_sort[k]], delta_fx) ); - npulses[ k_sort[k]] = pulses_fx; + &coefs_norm_dec_fx[sfm_start[k_sort[k]]], &step_scale_fx[k_sort[k]], &surplus_fx, &pulses_fx, savedstates, 1, &nzp_fx, 0, 0, 0, 0 ); + leftbits = L_sub( leftbits, L_add( R_fx[k_sort[k]], delta_fx ) ); + npulses[k_sort[k]] = pulses_fx; move16(); encode_position_ari_fx( parenc_fx, &coefs_norm_dec_fx[sfm_start[k_sort[k]]], size, &est_frame_bits_fx ); encode_magnitude_usq_fx( parenc_fx, &coefs_norm_dec_fx[sfm_start[k_sort[k]]], size, npulses[k_sort[k]], nzp_fx, &est_frame_bits_fx ); - encode_signs_fx( parenc_fx, &coefs_norm_dec_fx[ sfm_start[ k_sort[ k]]], size, nzp_fx, &est_frame_bits_fx ); + encode_signs_fx( parenc_fx, &coefs_norm_dec_fx[sfm_start[k_sort[k]]], size, nzp_fx, &est_frame_bits_fx ); nzbands--; } ELSE /* Then have zero block */ { - npulses[ k_sort[ k]] = 0; + npulses[k_sort[k]] = 0; move16(); size = sfmsize[k_sort[k]]; move16(); } - delta_fx = L_deposit_l(0); + delta_fx = L_deposit_l( 0 ); test(); IF( R_fx[k_sort[k]] > 0 && surplus_fx < 0 ) { @@ -273,16 +268,16 @@ ivas_error tcq_core_LR_enc_fx( divider = 2; } - IF( L_add( L_add( surplus_fx, sepbits), ar_div( leftbits, divider) ) < 0 ) + IF( L_add( L_add( surplus_fx, sepbits ), ar_div( leftbits, divider ) ) < 0 ) { /* Overflow possible => start to distribute negative surplus */ - delta_fx = ar_div( surplus_fx + sepbits, nzbands); + delta_fx = ar_div( surplus_fx + sepbits, nzbands ); } else { delta_fx = 0; } - surplus_fx = L_sub(surplus_fx, delta_fx); + surplus_fx = L_sub( surplus_fx, delta_fx ); } } } @@ -290,66 +285,62 @@ ivas_error tcq_core_LR_enc_fx( test(); test(); test(); - IF (( GT_32(surplus_fx,524288)&&EQ_16(input_frame,L_FRAME8k))||(GT_32(surplus_fx,786432)&&EQ_16(input_frame,L_FRAME16k))) + IF( ( GT_32( surplus_fx, 524288 ) && EQ_16( input_frame, L_FRAME8k ) ) || ( GT_32( surplus_fx, 786432 ) && EQ_16( input_frame, L_FRAME16k ) ) ) { - bit_surplus_fx[0] = Mult_32_16(surplus_fx,24576); /* Q16 */ - bit_surplus_fx[1] = Mult_32_16(surplus_fx,8192); /* Q16 */ + bit_surplus_fx[0] = Mult_32_16( surplus_fx, 24576 ); /* Q16 */ + bit_surplus_fx[1] = Mult_32_16( surplus_fx, 8192 ); /* Q16 */ } ELSE { bit_surplus_fx[0] = surplus_fx; move32(); - bit_surplus_fx[1] = L_deposit_l(0); + bit_surplus_fx[1] = L_deposit_l( 0 ); } - FOR ( k = 0; k < BANDS; k++ ) + FOR( k = 0; k < BANDS; k++ ) { - FOR ( j = 0; j < 2; j++ ) + FOR( j = 0; j < 2; j++ ) { - IF ( EQ_16(k, k_num[j])) + IF( EQ_16( k, k_num[j] ) ) { - R_fx[k_sort[k]] = L_add(R_fx[k_sort[k]],bit_surplus_fx[j]); + R_fx[k_sort[k]] = L_add( R_fx[k_sort[k]], bit_surplus_fx[j] ); test(); test(); - IF ( R_fx[k_sort[k]] > 0 && USQ_TCQ[k_sort[k]] == 0 ) /* Then have non-zero block AND WILL BE ENCODED BY TCQ */ + IF( R_fx[k_sort[k]] > 0 && USQ_TCQ[k_sort[k]] == 0 ) /* Then have non-zero block AND WILL BE ENCODED BY TCQ */ { /* Encode Position Info, NZ Info, Signs */ size = sfmsize[k_sort[k]]; move16(); /* Determine scale step, ISC and TCQ quantizer */ - GetISCScale_fx( &coefs_quant_fx[sfm_start[k_sort[k]]], size, R_fx[k_sort[k]], &coefs_norm_dec_fx[ sfm_start[ k_sort[k]]], &step_scale_fx[k_sort[k]], &surplus_fx, &pulses_fx, savedstates, 0, &nzp_fx - , 0, 0, 0, 0 - ); + GetISCScale_fx( &coefs_quant_fx[sfm_start[k_sort[k]]], size, R_fx[k_sort[k]], &coefs_norm_dec_fx[sfm_start[k_sort[k]]], &step_scale_fx[k_sort[k]], &surplus_fx, &pulses_fx, savedstates, 0, &nzp_fx, 0, 0, 0, 0 ); - npulses[ k_sort[k]] = pulses_fx; + npulses[k_sort[k]] = pulses_fx; move16(); - encode_position_ari_fx( parenc_fx, &coefs_norm_dec_fx[ sfm_start[ k_sort[k]]], size, &est_frame_bits_fx ); - encode_magnitude_tcq_fx( parenc_fx, &coefs_norm_dec_fx[ sfm_start[ k_sort[k]]], size, npulses[k_sort[k]], nzp_fx, savedstates, &est_frame_bits_fx ); - encode_signs_fx( parenc_fx, &coefs_norm_dec_fx[ sfm_start[ k_sort[k]]], size, nzp_fx, &est_frame_bits_fx ); + encode_position_ari_fx( parenc_fx, &coefs_norm_dec_fx[sfm_start[k_sort[k]]], size, &est_frame_bits_fx ); + encode_magnitude_tcq_fx( parenc_fx, &coefs_norm_dec_fx[sfm_start[k_sort[k]]], size, npulses[k_sort[k]], nzp_fx, savedstates, &est_frame_bits_fx ); + encode_signs_fx( parenc_fx, &coefs_norm_dec_fx[sfm_start[k_sort[k]]], size, nzp_fx, &est_frame_bits_fx ); } /* Have USQ coded band */ - ELSE IF( R_fx[k_sort[k]] > 0 && EQ_16(USQ_TCQ[k_sort[k]], 1)) + ELSE IF( R_fx[k_sort[k]] > 0 && EQ_16( USQ_TCQ[k_sort[k]], 1 ) ) { size = sfmsize[k_sort[k]]; move16(); - GetISCScale_fx( &coefs_quant_fx[ sfm_start[ k_sort[k]]], size, R_fx[k_sort[k]], &coefs_norm_dec_fx[ sfm_start[ k_sort[k]]], &step_scale_fx[k_sort[k]], &surplus_fx, &pulses_fx, savedstates, 1, &nzp_fx - , 0, 0, 0, 0 - ); + GetISCScale_fx( &coefs_quant_fx[sfm_start[k_sort[k]]], size, R_fx[k_sort[k]], &coefs_norm_dec_fx[sfm_start[k_sort[k]]], &step_scale_fx[k_sort[k]], &surplus_fx, &pulses_fx, savedstates, 1, &nzp_fx, 0, 0, 0, 0 ); - npulses[ k_sort[k]] = pulses_fx; + npulses[k_sort[k]] = pulses_fx; move16(); encode_position_ari_fx( parenc_fx, &coefs_norm_dec_fx[sfm_start[k_sort[k]]], size, &est_frame_bits_fx ); encode_magnitude_usq_fx( parenc_fx, &coefs_norm_dec_fx[sfm_start[k_sort[k]]], size, npulses[k_sort[k]], nzp_fx, &est_frame_bits_fx ); - encode_signs_fx( parenc_fx, &coefs_norm_dec_fx[ sfm_start[ k_sort[k]]], size, nzp_fx, &est_frame_bits_fx ); + encode_signs_fx( parenc_fx, &coefs_norm_dec_fx[sfm_start[k_sort[k]]], size, nzp_fx, &est_frame_bits_fx ); } ELSE /* Then have zero block */ { - npulses[ k_sort[k]] = 0; + npulses[k_sort[k]] = 0; move16(); size = sfmsize[k_sort[k]]; move16(); @@ -360,30 +351,30 @@ ivas_error tcq_core_LR_enc_fx( } ELSE { - surplus_fx = L_deposit_l(0); + surplus_fx = L_deposit_l( 0 ); /* Separate the position information from the input signal(coefs_norm) */ /* Gather the NZ coefficients*/ - FOR( k = 0; k < BANDS; k++) /* Loop through non-zero blocks */ + FOR( k = 0; k < BANDS; k++ ) /* Loop through non-zero blocks */ { IF( R_fx[k_sort[k]] > 0 ) { size = sfmsize[k_sort[k]]; move16(); - GetISCScale_fx( &coefs_quant_fx[ sfm_start[ k_sort[k]]], size, R_fx[k_sort[k]] + delta_fx, &coefs_norm_dec_fx[ sfm_start[ k_sort[k]]], &step_scale_fx[k_sort[k]], &surplus_fx, &pulses_fx, savedstates, 1, &nzp_fx, &bcount, abuffer_fx, mbuffer_fx, sbuffer_fx); + GetISCScale_fx( &coefs_quant_fx[sfm_start[k_sort[k]]], size, R_fx[k_sort[k]] + delta_fx, &coefs_norm_dec_fx[sfm_start[k_sort[k]]], &step_scale_fx[k_sort[k]], &surplus_fx, &pulses_fx, savedstates, 1, &nzp_fx, &bcount, abuffer_fx, mbuffer_fx, sbuffer_fx ); - npulses[ k_sort[k]] = pulses_fx; + npulses[k_sort[k]] = pulses_fx; move16(); - encode_position_ari_fx(parenc_fx, &coefs_norm_dec_fx[sfm_start[k_sort[k]]], size, &est_frame_bits_fx); - encode_magnitude_usq_fx(parenc_fx, &coefs_norm_dec_fx[sfm_start[k_sort[k]]], size, npulses[k_sort[k]], nzp_fx, &est_frame_bits_fx); - encode_signs_fx(parenc_fx, &coefs_norm_dec_fx[ sfm_start[ k_sort[k]]], size, nzp_fx, &est_frame_bits_fx); + encode_position_ari_fx( parenc_fx, &coefs_norm_dec_fx[sfm_start[k_sort[k]]], size, &est_frame_bits_fx ); + encode_magnitude_usq_fx( parenc_fx, &coefs_norm_dec_fx[sfm_start[k_sort[k]]], size, npulses[k_sort[k]], nzp_fx, &est_frame_bits_fx ); + encode_signs_fx( parenc_fx, &coefs_norm_dec_fx[sfm_start[k_sort[k]]], size, nzp_fx, &est_frame_bits_fx ); /* nzbands--; */ - nzbands = sub(nzbands, 1); + nzbands = sub( nzbands, 1 ); } ELSE /* Then have zero block */ { - npulses[ k_sort[k]] = 0; + npulses[k_sort[k]] = 0; move16(); size = sfmsize[k_sort[k]]; move16(); @@ -397,90 +388,88 @@ ivas_error tcq_core_LR_enc_fx( /* delta = surplus / nzbands; surplus -= delta; */ - delta_fx = ar_div(surplus_fx, nzbands); - surplus_fx = L_sub(surplus_fx, delta_fx); + delta_fx = ar_div( surplus_fx, nzbands ); + surplus_fx = L_sub( surplus_fx, delta_fx ); } } } - TCQLSB_fx(bcount, /*abuffer, */abuffer_fx, /*mbuffer, */mbuffer_fx, /*sbuffer, */sbuffer_fx, dpath); + TCQLSB_fx( bcount, /*abuffer, */ abuffer_fx, /*mbuffer, */ mbuffer_fx, /*sbuffer, */ sbuffer_fx, dpath ); /* Save TCQ path to bitstream */ - SaveTCQdata_fx(parenc_fx, dpath, lsbtcq_bits); + SaveTCQdata_fx( parenc_fx, dpath, lsbtcq_bits ); /* Add tcq sequence to decoding buffer */ - InitLSBTCQ_fx(&bcount); + InitLSBTCQ_fx( &bcount ); - ar_encoder_done_fx(parenc_fx); + ar_encoder_done_fx( parenc_fx ); /* Loop through non-zero blocks */ - FOR (i = 0; i < L_FRAME32k; i++) + FOR( i = 0; i < L_FRAME32k; i++ ) { - coefs_norm_dec_fx[i] = extract_l(L_mult0(coefs_norm_dec_fx[i], 5)); + coefs_norm_dec_fx[i] = extract_l( L_mult0( coefs_norm_dec_fx[i], 5 ) ); } IF( !flag_wbnb ) { - FOR ( k = 0; k < BANDS; k++) + FOR( k = 0; k < BANDS; k++ ) { IF( R_fx[k_sort[k]] > 0 ) { size = sfmsize[k_sort[k]]; move16(); - RestoreTCQ_fx( &coefs_norm_dec_fx[ sfm_start[ k_sort[k]]], size, &bcount, mbuffer_fx ); + RestoreTCQ_fx( &coefs_norm_dec_fx[sfm_start[k_sort[k]]], size, &bcount, mbuffer_fx ); } } } - nb_bytes = shr(bit_budget, 3); - j = sub(bit_budget, shl(nb_bytes, 3)); + nb_bytes = shr( bit_budget, 3 ); + j = sub( bit_budget, shl( nb_bytes, 3 ) ); FOR( i = 0; i < nb_bytes; i++ ) { - push_indice_fx(hBstr, IND_HQ2_SUBBAND_TCQ, pbs_fx->buf[i], 8); + push_indice_fx( hBstr, IND_HQ2_SUBBAND_TCQ, pbs_fx->buf[i], 8 ); } IF( j > 0 ) { - push_indice_fx(hBstr, IND_HQ2_SUBBAND_TCQ, shr(pbs_fx->buf[nb_bytes],(8 - j)), j); + push_indice_fx( hBstr, IND_HQ2_SUBBAND_TCQ, shr( pbs_fx->buf[nb_bytes], ( 8 - j ) ), j ); } /* Clear decoding buffer */ - set32_fx(coefs_quant_fx, 0, sfm_end[BANDS-1]+1); + set32_fx( coefs_quant_fx, 0, sfm_end[BANDS - 1] + 1 ); /* New analysis of decoded frame */ - FOR ( i = 0; i < BANDS; i++ ) + FOR( i = 0; i < BANDS; i++ ) { - IF ( R_fx[ k_sort[i]] > 0 ) + IF( R_fx[k_sort[i]] > 0 ) { - gain_fx = L_deposit_l(0); + gain_fx = L_deposit_l( 0 ); - crosscorr_fx = L_deposit_l(0); - selfcorr_fx = L_deposit_l(0); + crosscorr_fx = L_deposit_l( 0 ); + selfcorr_fx = L_deposit_l( 0 ); - FOR ( j = 0; j < sfmsize[k_sort[i]]; j++ ) + FOR( j = 0; j < sfmsize[k_sort[i]]; j++ ) { - crosscorr_fx = L_add( crosscorr_fx, Mult_32_16( coefs_norm_fx[sfm_start[k_sort[ i]]+j], shl(coefs_norm_dec_fx[sfm_start[k_sort[ i]]+j], 2) ) );/*1 */ - selfcorr_fx = L_mac0(selfcorr_fx, coefs_norm_dec_fx[sfm_start[k_sort[ i]]+j], coefs_norm_dec_fx[sfm_start[k_sort[ i]]+j]); + crosscorr_fx = L_add( crosscorr_fx, Mult_32_16( coefs_norm_fx[sfm_start[k_sort[i]] + j], shl( coefs_norm_dec_fx[sfm_start[k_sort[i]] + j], 2 ) ) ); /*1 */ + selfcorr_fx = L_mac0( selfcorr_fx, coefs_norm_dec_fx[sfm_start[k_sort[i]] + j], coefs_norm_dec_fx[sfm_start[k_sort[i]] + j] ); } - exp =sub(norm_l(crosscorr_fx), 1); - gain_fx = ar_div( L_shl(crosscorr_fx, exp), selfcorr_fx); /* 1 + exp */ + exp = sub( norm_l( crosscorr_fx ), 1 ); + gain_fx = ar_div( L_shl( crosscorr_fx, exp ), selfcorr_fx ); /* 1 + exp */ #ifdef BASOP_NOGLOB gain_fx = L_shl_sat( gain_fx, sub( 16, 1 + exp ) + 2 ); /* 0.2 * Q16 */ #else - gain_fx = L_shl( gain_fx, sub( 16, 1 + exp) + 2);/* 0.2 * Q16 */ + gain_fx = L_shl( gain_fx, sub( 16, 1 + exp ) + 2 ); /* 0.2 * Q16 */ #endif - lo = L_Extract_lc(gain_fx, &hi); + lo = L_Extract_lc( gain_fx, &hi ); /* Use optimal gain */ - FOR ( j = 0; j < sfmsize[k_sort[i]]; j++ ) + FOR( j = 0; j < sfmsize[k_sort[i]]; j++ ) { - inp_vector_fx[sfm_start[k_sort[i]]+j] = coefs_norm_dec_fx[sfm_start[k_sort[i]]+j]; + inp_vector_fx[sfm_start[k_sort[i]] + j] = coefs_norm_dec_fx[sfm_start[k_sort[i]] + j]; move16(); - coefs_quant_fx[sfm_start[k_sort[ i]]+j] = L_add(L_shl(L_mult0(hi, coefs_norm_dec_fx[sfm_start[k_sort[ i]]+j]), 12), - L_shr(L_mult0(lo, coefs_norm_dec_fx[sfm_start[k_sort[ i]]+j]), 3)); /* Q12 */ + coefs_quant_fx[sfm_start[k_sort[i]] + j] = L_add( L_shl( L_mult0( hi, coefs_norm_dec_fx[sfm_start[k_sort[i]] + j] ), 12 ), + L_shr( L_mult0( lo, coefs_norm_dec_fx[sfm_start[k_sort[i]] + j] ), 3 ) ); /* Q12 */ } } } - return error; - } diff --git a/lib_enc/tcx_ltp_enc.c b/lib_enc/tcx_ltp_enc.c index d42b2fd72..a37e3208d 100644 --- a/lib_enc/tcx_ltp_enc.c +++ b/lib_enc/tcx_ltp_enc.c @@ -407,7 +407,7 @@ void tcx_ltp_encode( /* Switch LTP on */ if ( ( tcxOnly == 0 && tcxMode == TCX_20 && norm_corr * hTcxEnc->tcxltp_norm_corr_past_flt > 0.25f && tempFlatness < 3.5f ) || - ( tcxOnly == 1 && tcxMode == TCX_10 && max( norm_corr, hTcxEnc->tcxltp_norm_corr_past_flt) > 0.5f && maxEnergyChange < 3.5f ) || + ( tcxOnly == 1 && tcxMode == TCX_10 && max( norm_corr, hTcxEnc->tcxltp_norm_corr_past_flt ) > 0.5f && maxEnergyChange < 3.5f ) || /* Use LTP for lower correlation when pitch lag is big, L_frame*(1.2f-norm_corr) < hTcxEnc->tcxltp_pitch_int <=> norm_corr > 1.2f-hTcxEnc->/L_frame */ ( tcxOnly == 1 && norm_corr > 0.44f && L_frame * ( 1.2f - norm_corr ) < hTcxEnc->tcxltp_pitch_int ) || ( tcxOnly == 1 && tcxMode == TCX_20 && norm_corr > 0.44f && ( tempFlatness < 6.0f || ( tempFlatness < 7.0f && maxEnergyChange < 22.0f ) ) ) ) diff --git a/lib_enc/tcx_ltp_enc_fx.c b/lib_enc/tcx_ltp_enc_fx.c index 3d4cb58f3..f44fcd203 100644 --- a/lib_enc/tcx_ltp_enc_fx.c +++ b/lib_enc/tcx_ltp_enc_fx.c @@ -10,11 +10,11 @@ #include "basop_util.h" #include "rom_com_fx.h" #include "rom_com.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ -static Word32 dot(const Word16 *X, const Word16 *Y, Word16 n) +static Word32 dot( const Word16 *X, const Word16 *Y, Word16 n ) { Word32 acc; Word16 i; @@ -22,19 +22,19 @@ static Word32 dot(const Word16 *X, const Word16 *Y, Word16 n) Word64 acc_64; acc_64 = 0; move64(); - FOR (i = 0; i < n; i++) + FOR( i = 0; i < n; i++ ) { - acc_64 = W_mac0_16_16(acc_64, X[i], Y[i]); + acc_64 = W_mac0_16_16( acc_64, X[i], Y[i] ); } acc = W_sat_l( acc_64 ); return acc; } -static Word32 interpolate_corr( /* o : interpolated value */ - const Word32 *x, /* i : input vector */ - const Word16 frac, /* i : fraction of lag */ - const Word16 frac_max /* i : max fraction */ +static Word32 interpolate_corr( /* o : interpolated value */ + const Word32 *x, /* i : input vector */ + const Word16 frac, /* i : fraction of lag */ + const Word16 frac_max /* i : max fraction */ ) { Word32 s; @@ -42,28 +42,29 @@ static Word32 interpolate_corr( /* o : interpolated value */ win = E_ROM_inter4_1_fx; - if (EQ_16(frac_max, 6))win=E_ROM_inter6_1_fx; + if ( EQ_16( frac_max, 6 ) ) + win = E_ROM_inter6_1_fx; - s = L_deposit_l(0); + s = L_deposit_l( 0 ); c = &win[frac]; - s = L_add(s, Mpy_32_16_1(x[0], *c)); + s = L_add( s, Mpy_32_16_1( x[0], *c ) ); c += frac_max; - s = L_add(s, Mpy_32_16_1(x[-1], *c)); + s = L_add( s, Mpy_32_16_1( x[-1], *c ) ); c += frac_max; - s = L_add(s, Mpy_32_16_1(x[-2], *c)); + s = L_add( s, Mpy_32_16_1( x[-2], *c ) ); c += frac_max; - s = L_add(s, Mpy_32_16_1(x[-3], *c)); + s = L_add( s, Mpy_32_16_1( x[-3], *c ) ); - c = &win[frac_max-frac]; - s = L_add(s, Mpy_32_16_1(x[1], *c)); + c = &win[frac_max - frac]; + s = L_add( s, Mpy_32_16_1( x[1], *c ) ); c += frac_max; - s = L_add(s, Mpy_32_16_1(x[2], *c)); + s = L_add( s, Mpy_32_16_1( x[2], *c ) ); c += frac_max; - s = L_add(s, Mpy_32_16_1(x[3], *c)); + s = L_add( s, Mpy_32_16_1( x[3], *c ) ); c += frac_max; - s = L_add(s, Mpy_32_16_1(x[4], *c)); + s = L_add( s, Mpy_32_16_1( x[4], *c ) ); return s; @@ -81,73 +82,71 @@ static void tcx_ltp_pitch_search( Word16 pitfr1, Word16 pitfr2, Word16 pitmax, - Word16 pitres -) + Word16 pitres ) { Word16 i, t, t0, t1, step, fraction, t0_min, t0_max, t_min, t_max, delta, temp_m, temp_e, s, s_wsp; Word32 cor_max, cor[256], *pt_cor, temp; - Word16 wsp2[L_FRAME_PLUS+PIT_MAX_MAX+L_INTERPOL1]; + Word16 wsp2[L_FRAME_PLUS + PIT_MAX_MAX + L_INTERPOL1]; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - delta = 16; move16(); - if ( EQ_16(pitres, 6)) + if ( EQ_16( pitres, 6 ) ) { delta = 8; move16(); } - t0_min = sub(pitch_ol, shr(delta, 1)); - t0_max = sub(add(t0_min, delta), 1); + t0_min = sub( pitch_ol, shr( delta, 1 ) ); + t0_max = sub( add( t0_min, delta ), 1 ); - IF ( LT_16(t0_min, pitmin)) + IF( LT_16( t0_min, pitmin ) ) { t0_min = pitmin; move16(); - t0_max = sub(add(t0_min, delta), 1); + t0_max = sub( add( t0_min, delta ), 1 ); } - IF ( GT_16(t0_max, pitmax)) + IF( GT_16( t0_max, pitmax ) ) { t0_max = pitmax; move16(); - t0_min = add(sub(t0_max, delta), 1); + t0_min = add( sub( t0_max, delta ), 1 ); } - t_min = sub(t0_min, L_INTERPOL1); - t_max = add(t0_max, L_INTERPOL1); + t_min = sub( t0_min, L_INTERPOL1 ); + t_max = add( t0_max, L_INTERPOL1 ); /* normalize wsp */ - assert(len+t_max <= L_FRAME_PLUS+PIT_MAX_MAX+L_INTERPOL1); - s_wsp = getScaleFactor16(wsp - t_max, add(len, t_max)); - s_wsp = sub(s_wsp, 4); - FOR (t = negate(t_max); t < len; t++) + assert( len + t_max <= L_FRAME_PLUS + PIT_MAX_MAX + L_INTERPOL1 ); + s_wsp = getScaleFactor16( wsp - t_max, add( len, t_max ) ); + s_wsp = sub( s_wsp, 4 ); + FOR( t = negate( t_max ); t < len; t++ ) { - wsp2[t+t_max] = shl(wsp[t], s_wsp); + wsp2[t + t_max] = shl( wsp[t], s_wsp ); move16(); } wsp = wsp2 + t_max; pt_cor = cor; - FOR ( t=t_min; t<=t_max; t++ ) + FOR( t = t_min; t <= t_max; t++ ) { - *pt_cor = dot(wsp, wsp-t, len); + *pt_cor = dot( wsp, wsp - t, len ); pt_cor++; } pt_cor = cor + L_INTERPOL1; - cor_max = L_add(*pt_cor++, 0); + cor_max = L_add( *pt_cor++, 0 ); t1 = t0_min; move16(); - FOR ( t = add(t0_min, 1); t <= t0_max; t++ ) + FOR( t = add( t0_min, 1 ); t <= t0_max; t++ ) { - IF ( *pt_cor > cor_max ) + IF( *pt_cor > cor_max ) { cor_max = *pt_cor; t1 = t; @@ -155,44 +154,44 @@ static void tcx_ltp_pitch_search( pt_cor++; } - temp = dot(wsp, wsp, len); - s = norm_l(temp); - temp_m = extract_h(L_shl(temp, s)); - temp_e = negate(s); + temp = dot( wsp, wsp, len ); + s = norm_l( temp ); + temp_m = extract_h( L_shl( temp, s ) ); + temp_e = negate( s ); - temp = dot(wsp-t1, wsp-t1, len); - s = norm_l(temp); - temp_m = mult(temp_m, extract_h(L_shl(temp, s))); - temp_e = sub(temp_e, s); + temp = dot( wsp - t1, wsp - t1, len ); + s = norm_l( temp ); + temp_m = mult( temp_m, extract_h( L_shl( temp, s ) ) ); + temp_e = sub( temp_e, s ); - temp_m = Sqrt16(temp_m, &temp_e); + temp_m = Sqrt16( temp_m, &temp_e ); - if (temp_m == 0) + if ( temp_m == 0 ) { temp_m = 1; move16(); } - s = sub(norm_l(cor_max), 1); - temp_m = divide1616(extract_h(L_shl(cor_max, s)), temp_m); - temp_e = sub(negate(s), temp_e); + s = sub( norm_l( cor_max ), 1 ); + temp_m = divide1616( extract_h( L_shl( cor_max, s ) ), temp_m ); + temp_e = sub( negate( s ), temp_e ); #ifdef BASOP_NOGLOB - *norm_corr = shl_o(temp_m, temp_e, &Overflow); + *norm_corr = shl_o( temp_m, temp_e, &Overflow ); #else BASOP_SATURATE_WARNING_OFF_EVS - *norm_corr = shl(temp_m, temp_e); + *norm_corr = shl( temp_m, temp_e ); BASOP_SATURATE_WARNING_ON_EVS #endif - IF ( GE_16(t1, pitfr1)) + IF( GE_16( t1, pitfr1 ) ) { *pitch_int = t1; move16(); *pitch_fr = 0; move16(); - *index = add(sub(t1, pitfr1), extract_l(L_mac0(L_mult0(sub(pitfr2, pitmin), pitres), - sub(pitfr1, pitfr2), shr(pitres,1)))); + *index = add( sub( t1, pitfr1 ), extract_l( L_mac0( L_mult0( sub( pitfr2, pitmin ), pitres ), + sub( pitfr1, pitfr2 ), shr( pitres, 1 ) ) ) ); move16(); return; @@ -204,13 +203,13 @@ static void tcx_ltp_pitch_search( * the interpolated normalized correlation. *-----------------------------------------------------------------*/ - pt_cor = cor + sub(L_INTERPOL1, t0_min); + pt_cor = cor + sub( L_INTERPOL1, t0_min ); t0 = t1; move16(); step = 1; move16(); - if (GE_16(t0, pitfr2)) + if ( GE_16( t0, pitfr2 ) ) { step = 2; move16(); @@ -218,24 +217,24 @@ static void tcx_ltp_pitch_search( fraction = step; move16(); - IF (EQ_16(t0, t0_min)) /* Limit case */ + IF( EQ_16( t0, t0_min ) ) /* Limit case */ { fraction = 0; move16(); cor_max = interpolate_corr( &pt_cor[t0], fraction, pitres ); } - ELSE /* Process negative fractions */ + ELSE /* Process negative fractions */ { - t0 = sub(t0, 1); + t0 = sub( t0, 1 ); cor_max = interpolate_corr( &pt_cor[t0], fraction, pitres ); - FOR ( i = add(fraction, step); i < pitres; i += step ) + FOR( i = add( fraction, step ); i < pitres; i += step ) { temp = interpolate_corr( &pt_cor[t0], i, pitres ); - IF (GT_32(temp, cor_max)) + IF( GT_32( temp, cor_max ) ) { - cor_max = L_add(temp, 0); + cor_max = L_add( temp, 0 ); fraction = i; move16(); } @@ -243,13 +242,13 @@ static void tcx_ltp_pitch_search( } i = 0; - FOR ( i = 0; i < pitres; i += step ) /* Process positive fractions */ + FOR( i = 0; i < pitres; i += step ) /* Process positive fractions */ { temp = interpolate_corr( &pt_cor[t1], i, pitres ); - IF (GT_32(temp, cor_max)) + IF( GT_32( temp, cor_max ) ) { - cor_max = L_add(temp, 0); + cor_max = L_add( temp, 0 ); fraction = i; move16(); t0 = t1; @@ -262,18 +261,18 @@ static void tcx_ltp_pitch_search( *pitch_fr = fraction; move16(); - IF ( GE_16(t0, pitfr2)) + IF( GE_16( t0, pitfr2 ) ) { - *index = add( extract_l(L_mac0(L_mult0(sub(t0, pitfr2), shr(pitres,1)), - sub(pitfr2, pitmin), pitres)), shr(fraction,1) ); + *index = add( extract_l( L_mac0( L_mult0( sub( t0, pitfr2 ), shr( pitres, 1 ) ), + sub( pitfr2, pitmin ), pitres ) ), + shr( fraction, 1 ) ); move16(); } ELSE { - *index = add(imult1616(sub(t0, pitmin), pitres), fraction); + *index = add( imult1616( sub( t0, pitmin ), pitres ), fraction ); move16(); } - } @@ -286,114 +285,109 @@ static void tcx_ltp_find_gain( Word16 *speech, Word16 *pred_speech, Word16 L_fra #endif - - s1 = sub(getScaleFactor16(speech, L_frame), 4); - s2 = sub(getScaleFactor16(pred_speech, L_frame), 4); + s1 = sub( getScaleFactor16( speech, L_frame ), 4 ); + s2 = sub( getScaleFactor16( pred_speech, L_frame ), 4 ); /* Find gain */ - corr = L_deposit_l(0); - ener = L_deposit_l(1); + corr = L_deposit_l( 0 ); + ener = L_deposit_l( 1 ); - FOR (i = 0; i < L_frame; i++) + FOR( i = 0; i < L_frame; i++ ) { #ifdef BASOP_NOGLOB tmp = shl_sat( pred_speech[i], s2 ); - corr = L_mac0_sat(corr, shl(speech[i], s1), tmp); - ener = L_mac0_sat(ener, tmp, tmp); + corr = L_mac0_sat( corr, shl( speech[i], s1 ), tmp ); + ener = L_mac0_sat( ener, tmp, tmp ); #else - tmp = shl(pred_speech[i], s2); - corr = L_mac0(corr, shl(speech[i], s1), tmp); - ener = L_mac0(ener, tmp, tmp); + tmp = shl( pred_speech[i], s2 ); + corr = L_mac0( corr, shl( speech[i], s1 ), tmp ); + ener = L_mac0( ener, tmp, tmp ); #endif } - s1 = sub(1, add(s1, s2)); - s2 = sub(1, shl(s2, 1)); + s1 = sub( 1, add( s1, s2 ) ); + s2 = sub( 1, shl( s2, 1 ) ); - tmp = sub(norm_l(corr), 1); - corr = L_shl(corr, tmp); - s1 = sub(s1, tmp); + tmp = sub( norm_l( corr ), 1 ); + corr = L_shl( corr, tmp ); + s1 = sub( s1, tmp ); - tmp = norm_l(ener); - ener = L_shl(ener, tmp); - s2 = sub(s2, tmp); + tmp = norm_l( ener ); + ener = L_shl( ener, tmp ); + s2 = sub( s2, tmp ); #ifdef BASOP_NOGLOB - g = divide1616(round_fx_o(corr, &Overflow), round_fx_o(ener, &Overflow)); + g = divide1616( round_fx_o( corr, &Overflow ), round_fx_o( ener, &Overflow ) ); #else - g = divide1616(round_fx(corr), round_fx(ener)); + g = divide1616( round_fx( corr ), round_fx( ener ) ); #endif BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB - g = shl_o(g, sub(s1, s2), &Overflow); -#else /* BASOP_NOGLOB */ - g = shl(g, sub(s1, s2)); + g = shl_o( g, sub( s1, s2 ), &Overflow ); +#else /* BASOP_NOGLOB */ + g = shl( g, sub( s1, s2 ) ); #endif /* BASOP_NOGLOB */ BASOP_SATURATE_WARNING_ON_EVS /* Quantize gain */ - g = shr(sub(g, 0x1000), 13); - g = s_max(g, -1); + g = shr( sub( g, 0x1000 ), 13 ); + g = s_max( g, -1 ); *gain_index = g; move16(); /* Dequantize gain */ - *gain = imult1616(add(g, 1), 0x1400); + *gain = imult1616( add( g, 1 ), 0x1400 ); move16(); - - } void tcx_ltp_encode_fx( Word16 tcxltp_on, - Word8 tcxOnly, - Word16 tcxMode, - Word16 L_frame, - Word16 L_subfr, - Word16 *speech, - Word16 *speech_ltp, - Word16 *wsp, - Word16 Top, - Word16 *ltp_param, - Word16 *ltp_bits, - Word16 *pitch_int, - Word16 *pitch_fr, - Word16 *gain, - Word16 *pitch_int_past, - Word16 *pitch_fr_past, - Word16 *gain_past, - Word16 *norm_corr_past, - Word16 last_core, - Word16 pitmin, - Word16 pitfr1, - Word16 pitfr2, - Word16 pitmax, - Word16 pitres, - struct TransientDetection const * pTransientDetection, - Word8 SideInfoOnly, - Word16 *A, - Word16 lpcorder - ) + Word8 tcxOnly, + Word16 tcxMode, + Word16 L_frame, + Word16 L_subfr, + Word16 *speech, + Word16 *speech_ltp, + Word16 *wsp, + Word16 Top, + Word16 *ltp_param, + Word16 *ltp_bits, + Word16 *pitch_int, + Word16 *pitch_fr, + Word16 *gain, + Word16 *pitch_int_past, + Word16 *pitch_fr_past, + Word16 *gain_past, + Word16 *norm_corr_past, + Word16 last_core, + Word16 pitmin, + Word16 pitfr1, + Word16 pitfr2, + Word16 pitmax, + Word16 pitres, + struct TransientDetection const *pTransientDetection, + Word8 SideInfoOnly, + Word16 *A, + Word16 lpcorder ) { Word16 n; Word16 norm_corr; Word16 pred_speech[L_FRAME32k]; Word16 tempFlatness; Word16 maxEnergyChange; - Word16 buf_zir[M+L_SUBFR], *zir; - Word16 Aest[M+1]; + Word16 buf_zir[M + L_SUBFR], *zir; + Word16 Aest[M + 1]; Word16 alpha, step; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - norm_corr = 0; move16(); /* Reset memory if past frame is acelp */ - IF (last_core == ACELP_CORE) + IF( last_core == ACELP_CORE ) { *pitch_int_past = L_frame; move16(); @@ -408,12 +402,12 @@ void tcx_ltp_encode_fx( Word16 tcxltp_on, move16(); test(); - IF (tcxltp_on != 0 || SideInfoOnly != 0) + IF( tcxltp_on != 0 || SideInfoOnly != 0 ) { Word16 nPrevSubblocks; Word8 isTCX10 = 0; - if (EQ_16(tcxMode, TCX_10)) + if ( EQ_16( tcxMode, TCX_10 ) ) { isTCX10 = 1; move16(); @@ -422,14 +416,14 @@ void tcx_ltp_encode_fx( Word16 tcxltp_on, /* Find pitch lag */ tcx_ltp_pitch_search( Top, pitch_int, pitch_fr, <p_param[1], &norm_corr, L_frame, wsp, pitmin, pitfr1, pitfr2, pitmax, pitres ); - nPrevSubblocks = extract_h(L_mac(0x17fff, NSUBBLOCKS, div_s(*pitch_int, L_frame))); - nPrevSubblocks = add(s_min(nPrevSubblocks, NSUBBLOCKS), 1); + nPrevSubblocks = extract_h( L_mac( 0x17fff, NSUBBLOCKS, div_s( *pitch_int, L_frame ) ) ); + nPrevSubblocks = add( s_min( nPrevSubblocks, NSUBBLOCKS ), 1 ); - tempFlatness = GetTCXAvgTemporalFlatnessMeasure_fx(pTransientDetection, NSUBBLOCKS, nPrevSubblocks); + tempFlatness = GetTCXAvgTemporalFlatnessMeasure_fx( pTransientDetection, NSUBBLOCKS, nPrevSubblocks ); - maxEnergyChange = GetTCXMaxenergyChange_fx(pTransientDetection, - (const Word8) isTCX10, - NSUBBLOCKS, nPrevSubblocks); + maxEnergyChange = GetTCXMaxenergyChange_fx( pTransientDetection, + (const Word8) isTCX10, + NSUBBLOCKS, nPrevSubblocks ); /* Switch LTP on */ test(); @@ -450,35 +444,25 @@ void tcx_ltp_encode_fx( Word16 tcxltp_on, test(); BASOP_SATURATE_WARNING_OFF_EVS; if ( ( - tcxOnly == 0 && - EQ_16(tcxMode, TCX_20) && - GT_16(mult(norm_corr, *norm_corr_past), 0x2000) && - LT_16(tempFlatness, 448/*3.5f Q7*/) - ) || - ( - tcxOnly != 0 && - EQ_16(tcxMode, TCX_10) && - GT_16(s_max(norm_corr, *norm_corr_past), 0x4000) && - LT_16(maxEnergyChange, 448/*3.5f Q7*/) - ) || - ( /* Use LTP for lower correlation when pitch lag is big, L_frame*(1.2f-norm_corr) < pitch_int <=> norm_corr > 1.2f-pitch_int/L_frame */ - tcxOnly != 0 && - GT_16(norm_corr, 14418/*0.44f Q15*/) && - L_msu(L_mult(L_frame, sub(19661/*1.2f Q14*/, shr(norm_corr, 1))), *pitch_int, 1<<14) < 0 /* L_frame*(1.2f-norm_corr) < pitch_int */ - ) || - ( - tcxOnly != 0 && - EQ_16(tcxMode, TCX_20) && - GT_16(norm_corr, 14418/*0.44f Q15*/) && - ( - LT_16(tempFlatness, 768/*6.0f Q7*/) || - ( - LT_16(tempFlatness, 896/*7.0f Q7*/) && - LT_16(maxEnergyChange, 2816/*22.0f Q7*/) - ) - ) - ) - ) + tcxOnly == 0 && + EQ_16( tcxMode, TCX_20 ) && + GT_16( mult( norm_corr, *norm_corr_past ), 0x2000 ) && + LT_16( tempFlatness, 448 /*3.5f Q7*/ ) ) || + ( tcxOnly != 0 && + EQ_16( tcxMode, TCX_10 ) && + GT_16( s_max( norm_corr, *norm_corr_past ), 0x4000 ) && + LT_16( maxEnergyChange, 448 /*3.5f Q7*/ ) ) || + ( /* Use LTP for lower correlation when pitch lag is big, L_frame*(1.2f-norm_corr) < pitch_int <=> norm_corr > 1.2f-pitch_int/L_frame */ + tcxOnly != 0 && + GT_16( norm_corr, 14418 /*0.44f Q15*/ ) && + L_msu( L_mult( L_frame, sub( 19661 /*1.2f Q14*/, shr( norm_corr, 1 ) ) ), *pitch_int, 1 << 14 ) < 0 /* L_frame*(1.2f-norm_corr) < pitch_int */ + ) || + ( tcxOnly != 0 && + EQ_16( tcxMode, TCX_20 ) && + GT_16( norm_corr, 14418 /*0.44f Q15*/ ) && + ( LT_16( tempFlatness, 768 /*6.0f Q7*/ ) || + ( LT_16( tempFlatness, 896 /*7.0f Q7*/ ) && + LT_16( maxEnergyChange, 2816 /*22.0f Q7*/ ) ) ) ) ) { ltp_param[0] = 1; move16(); @@ -486,7 +470,7 @@ void tcx_ltp_encode_fx( Word16 tcxltp_on, BASOP_SATURATE_WARNING_ON_EVS; } - IF (ltp_param[0] != 0) + IF( ltp_param[0] != 0 ) { /* Find predicted signal */ predict_signal( speech, pred_speech, *pitch_int, *pitch_fr, pitres, L_frame ); @@ -495,19 +479,19 @@ void tcx_ltp_encode_fx( Word16 tcxltp_on, tcx_ltp_find_gain( speech, pred_speech, L_frame, gain, <p_param[2] ); /* Total number of bits for LTP */ - IF (NE_16(ltp_param[2], -1) ) /* gain > 0 */ + IF( NE_16( ltp_param[2], -1 ) ) /* gain > 0 */ { *ltp_bits = 12; move16(); } - ELSE /* gain <= 0 -> turn off LTP */ + ELSE /* gain <= 0 -> turn off LTP */ { ltp_param[0] = 0; move16(); } } - IF (ltp_param[0] == 0) + IF( ltp_param[0] == 0 ) { /* No LTP -> set everything to zero */ *pitch_int = L_frame; @@ -525,115 +509,116 @@ void tcx_ltp_encode_fx( Word16 tcxltp_on, *ltp_bits = 0; move16(); test(); - if (tcxltp_on != 0 || SideInfoOnly != 0) + if ( tcxltp_on != 0 || SideInfoOnly != 0 ) { *ltp_bits = 1; move16(); } } - if (SideInfoOnly != 0) + if ( SideInfoOnly != 0 ) { *gain = 0; move16(); } test(); - IF (*gain_past == 0 && *gain == 0) + IF( *gain_past == 0 && *gain == 0 ) { - Copy(speech, speech_ltp, L_subfr); + Copy( speech, speech_ltp, L_subfr ); } - ELSE IF (*gain_past == 0) + ELSE IF( *gain_past == 0 ) { alpha = 0; move16(); /* step = 1.f/(float)(L_subfr); */ - step = shl(2, norm_s(L_subfr)); - if (s_and(L_subfr, sub(L_subfr, 1)) != 0) + step = shl( 2, norm_s( L_subfr ) ); + if ( s_and( L_subfr, sub( L_subfr, 1 ) ) != 0 ) { - step = mult_r(step, 26214/*64.f/80.f Q15*/); + step = mult_r( step, 26214 /*64.f/80.f Q15*/ ); } - FOR (n = 0; n < L_subfr; n++) + FOR( n = 0; n < L_subfr; n++ ) { #ifdef BASOP_NOGLOB - speech_ltp[n] = sub_o(speech[n], mult_ro(*gain, mult_ro(alpha, pred_speech[n], &Overflow), &Overflow), &Overflow); + speech_ltp[n] = sub_o( speech[n], mult_ro( *gain, mult_ro( alpha, pred_speech[n], &Overflow ), &Overflow ), &Overflow ); #else - speech_ltp[n] = sub(speech[n], mult_r(*gain, mult_r(alpha, pred_speech[n]))); + speech_ltp[n] = sub( speech[n], mult_r( *gain, mult_r( alpha, pred_speech[n] ) ) ); #endif move16(); BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB - alpha = add_o(alpha, step, &Overflow); + alpha = add_o( alpha, step, &Overflow ); #else /* BASOP_NOGLOB */ - alpha = add(alpha, step); + alpha = add( alpha, step ); #endif BASOP_SATURATE_WARNING_ON_EVS; } } ELSE { - IF (A == NULL) + IF( A == NULL ) { - tcx_ltp_get_lpc(speech-L_frame, L_frame, Aest, lpcorder); + tcx_ltp_get_lpc( speech - L_frame, L_frame, Aest, lpcorder ); A = Aest; } - IF (*gain > 0) + IF( *gain > 0 ) { - predict_signal(speech-lpcorder, buf_zir, *pitch_int, *pitch_fr, pitres, lpcorder); + predict_signal( speech - lpcorder, buf_zir, *pitch_int, *pitch_fr, pitres, lpcorder ); } - ELSE { - set16_fx(buf_zir, 0, lpcorder); + ELSE + { + set16_fx( buf_zir, 0, lpcorder ); } - FOR (n = 0; n < lpcorder; n++) + FOR( n = 0; n < lpcorder; n++ ) { #ifdef BASOP_NOGLOB buf_zir[n] = add_sat( sub_sat( speech_ltp[n - lpcorder], speech[n - lpcorder] ), mult_r( *gain, buf_zir[n] ) ); #else - buf_zir[n] = add(sub(speech_ltp[n-lpcorder], speech[n-lpcorder]), mult_r(*gain, buf_zir[n])); + buf_zir[n] = add( sub( speech_ltp[n - lpcorder], speech[n - lpcorder] ), mult_r( *gain, buf_zir[n] ) ); #endif move16(); } zir = buf_zir + lpcorder; - set16_fx(zir, 0, L_subfr); + set16_fx( zir, 0, L_subfr ); - E_UTIL_synthesis(0, A, zir, zir, L_subfr, buf_zir, 0, lpcorder); + E_UTIL_synthesis( 0, A, zir, zir, L_subfr, buf_zir, 0, lpcorder ); alpha = 0x7FFF; /* step = 1.f/(float)(L_subfr/2); */ - step = shl(4, norm_s(L_subfr)); - if (s_and(L_subfr, sub(L_subfr, 1)) != 0) + step = shl( 4, norm_s( L_subfr ) ); + if ( s_and( L_subfr, sub( L_subfr, 1 ) ) != 0 ) { - step = mult_r(step, 26214/*64.f/80.f Q15*/); + step = mult_r( step, 26214 /*64.f/80.f Q15*/ ); } - FOR (n = shr(L_subfr, 1); n < L_subfr; n++) + FOR( n = shr( L_subfr, 1 ); n < L_subfr; n++ ) { - zir[n] = mult_r(zir[n], alpha); + zir[n] = mult_r( zir[n], alpha ); move16(); - alpha = sub(alpha, step); + alpha = sub( alpha, step ); } - FOR (n = 0; n < L_subfr; n++) + FOR( n = 0; n < L_subfr; n++ ) { #ifdef BASOP_NOGLOB - speech_ltp[n] = add_o(sub_o(speech[n], mult_ro(*gain, pred_speech[n], &Overflow), &Overflow), zir[n], &Overflow); + speech_ltp[n] = add_o( sub_o( speech[n], mult_ro( *gain, pred_speech[n], &Overflow ), &Overflow ), zir[n], &Overflow ); #else - speech_ltp[n] = add(sub(speech[n], mult_r(*gain, pred_speech[n])), zir[n]); + speech_ltp[n] = add( sub( speech[n], mult_r( *gain, pred_speech[n] ) ), zir[n] ); #endif move16(); } } test(); - IF ( SideInfoOnly || *gain == 0) + IF( SideInfoOnly || *gain == 0 ) { - FOR ( n=L_subfr; n= 0) + s = L_add( s, L_shr( powerSpec[i + j], 4 ) ); + } + tmp16 = sub( lowpassLine, 7 ); + FOR( i = add( i, 1 ); i < tmp16; i++ ) + { + c = L_shr( powerSpec[i - 1], 4 ); + c = L_add( c, L_shr( powerSpec[i], 4 ) ); + c = L_add( c, L_shr( powerSpec[i + 1], 4 ) ); + + s = L_sub( s, L_shr( powerSpec[i - 8], 4 ) ); + s = L_add( s, L_shr( powerSpec[i + 7], 4 ) ); + + tmp1 = L_shr( c, 2 ); + if ( noiseFlags[i] == 0 ) + c = L_shl( c, 1 ); + if ( noiseFlags[i] == 0 ) + tmp2 = L_sub( c, tmp1 ); /* 1.75 * c */ + if ( noiseFlags[i] != 0 ) + tmp2 = L_add( c, tmp1 ); /* 1.25 * c */ + + tmp2 = L_sub( s, tmp2 ); + if ( tmp2 >= 0 ) { noiseFlags[i] = 1; move16(); } - if (tmp2 < 0) + if ( tmp2 < 0 ) { noiseFlags[i] = 0; move16(); } - if (tmp2 < 0) + if ( tmp2 < 0 ) { lastTone = i; move16(); @@ -112,44 +116,47 @@ void ComputeSpectrumNoiseMeasure_fx(const Word32 *powerSpec, } /* lower L_frame*startRatio lines are tonal (0), upper 7 lines are processed separately */ - tmp16 = sub(lowpassLine, 1); - FOR (; i < tmp16; i++) + tmp16 = sub( lowpassLine, 1 ); + FOR( ; i < tmp16; i++ ) { - c = L_shr(powerSpec[i-1], 4); - c = L_add(c, L_shr(powerSpec[i], 4)); - c = L_add(c, L_shr(powerSpec[i+1], 4)); - - tmp1 = L_shr(c, 2); - if (noiseFlags[i] == 0) c = L_shl(c, 1); - if (noiseFlags[i] == 0) tmp2 = L_sub(c, tmp1); /* 1.75 * c */ - if (noiseFlags[i] != 0) tmp2 = L_add(c, tmp1); /* 1.25 * c */ + c = L_shr( powerSpec[i - 1], 4 ); + c = L_add( c, L_shr( powerSpec[i], 4 ) ); + c = L_add( c, L_shr( powerSpec[i + 1], 4 ) ); + + tmp1 = L_shr( c, 2 ); + if ( noiseFlags[i] == 0 ) + c = L_shl( c, 1 ); + if ( noiseFlags[i] == 0 ) + tmp2 = L_sub( c, tmp1 ); /* 1.75 * c */ + if ( noiseFlags[i] != 0 ) + tmp2 = L_add( c, tmp1 ); /* 1.25 * c */ /* running sum can't be updated any more, just use the latest one */ - tmp2 = L_sub(s, tmp2); - if (tmp2 >= 0) + tmp2 = L_sub( s, tmp2 ); + if ( tmp2 >= 0 ) { noiseFlags[i] = 1; move16(); } - if (tmp2 < 0) + if ( tmp2 < 0 ) { noiseFlags[i] = 0; move16(); /* lastTone = i; */ } } - noiseFlags[i] = 1; /* uppermost line is defined as noise-like (1) */ move16(); + noiseFlags[i] = 1; /* uppermost line is defined as noise-like (1) */ + move16(); - if (lastTone > 0) /* spread uppermost tonal line one line upward */ + if ( lastTone > 0 ) /* spread uppermost tonal line one line upward */ { - noiseFlags[lastTone+1] = 0; + noiseFlags[lastTone + 1] = 0; move16(); } } - } -static void detectLowpassFac(const Word32 *powerSpec, Word16 powerSpec_e, Word16 L_frame, Word8 rectWin, Word16 *pLpFac, Word16 lowpassLine) +static void detectLowpassFac( const Word32 *powerSpec, Word16 powerSpec_e, Word16 L_frame, Word8 rectWin, Word16 *pLpFac, Word16 lowpassLine ) { Word16 i, tmp; Word32 threshold; @@ -158,40 +165,39 @@ static void detectLowpassFac(const Word32 *powerSpec, Word16 powerSpec_e, Word16 #endif - threshold = 256l/*0.1f * 2*NORM_MDCT_FACTOR Q3*/; /* Q3 */ - BASOP_SATURATE_WARNING_OFF_EVS /* Allow saturation, because threshold is being compared to powerSpec[i] below. */ + threshold = 256l /*0.1f * 2*NORM_MDCT_FACTOR Q3*/; /* Q3 */ + BASOP_SATURATE_WARNING_OFF_EVS /* Allow saturation, because threshold is being compared to powerSpec[i] below. */ #ifdef BASOP_NOGLOB - threshold = L_shl_o(threshold, sub(28, powerSpec_e), &Overflow); -#else /* BASOP_NOGLOB */ - threshold = L_shl(threshold, sub(28, powerSpec_e)); + threshold = L_shl_o( threshold, sub( 28, powerSpec_e ), &Overflow ); +#else /* BASOP_NOGLOB */ + threshold = L_shl( threshold, sub( 28, powerSpec_e ) ); #endif /* BASOP_NOGLOB */ - if (rectWin != 0) + if ( rectWin != 0 ) { /* compensate for bad side-lobe attenuation with asymmetric windows */ #ifdef BASOP_NOGLOB - threshold = L_shl_o(threshold, 1, &Overflow); + threshold = L_shl_o( threshold, 1, &Overflow ); #else - threshold = L_shl(threshold, 1); + threshold = L_shl( threshold, 1 ); #endif } BASOP_SATURATE_WARNING_ON_EVS - tmp = shr(lowpassLine, 1); - FOR (i = sub(lowpassLine, 1); i >= tmp; i--) + tmp = shr( lowpassLine, 1 ); + FOR( i = sub( lowpassLine, 1 ); i >= tmp; i-- ) { - IF (GT_32(powerSpec[i], threshold)) + IF( GT_32( powerSpec[i], threshold ) ) { BREAK; } } - tmp = getInvFrameLen(L_frame); + tmp = getInvFrameLen( L_frame ); - tmp = mult_r(22938/*0.7f Q15*/, round_fx(L_shl(L_mult0(add(i, 1), tmp), 9))); - *pLpFac = add(tmp, mult_r(9830/*0.3f Q15*/, *pLpFac)); + tmp = mult_r( 22938 /*0.7f Q15*/, round_fx( L_shl( L_mult0( add( i, 1 ), tmp ), 9 ) ) ); + *pLpFac = add( tmp, mult_r( 9830 /*0.3f Q15*/, *pLpFac ) ); move16(); - } /*-----------------------------------------------------------* @@ -200,17 +206,16 @@ static void detectLowpassFac(const Word32 *powerSpec, Word16 powerSpec_e, Word16 * Detect low pass if present. * *-----------------------------------------------------------*/ void AnalyzePowerSpectrum_fx( - Encoder_State *st, /* i/o: encoder states */ - Word16 L_frame, /* input: frame length */ - Word16 L_frameTCX, /* input: full band frame length */ - Word16 left_overlap, /* input: left overlap length */ - Word16 right_overlap, /* input: right overlap length */ - Word32 const mdctSpectrum[], /* input: MDCT spectrum */ + Encoder_State *st, /* i/o: encoder states */ + Word16 L_frame, /* input: frame length */ + Word16 L_frameTCX, /* input: full band frame length */ + Word16 left_overlap, /* input: left overlap length */ + Word16 right_overlap, /* input: right overlap length */ + Word32 const mdctSpectrum[], /* input: MDCT spectrum */ Word16 mdctSpectrum_e, - Word16 const signal[], /* input: windowed signal corresponding to mdctSpectrum */ - Word32 powerSpec[], /* output: Power spectrum. Can point to signal */ - Word16 *powerSpec_e -) + Word16 const signal[], /* input: windowed signal corresponding to mdctSpectrum */ + Word32 powerSpec[], /* output: Power spectrum. Can point to signal */ + Word16 *powerSpec_e ) { Word16 i, iStart, iEnd, lowpassLine; Word16 tmp, s1, s2; @@ -223,16 +228,16 @@ void AnalyzePowerSpectrum_fx( *powerSpec_e = 16; move16(); - TCX_MDST(signal, powerSpec, powerSpec_e, left_overlap, sub(L_frameTCX, shr(add(left_overlap, right_overlap), 1)), right_overlap, st->element_mode); + TCX_MDST( signal, powerSpec, powerSpec_e, left_overlap, sub( L_frameTCX, shr( add( left_overlap, right_overlap ), 1 ) ), right_overlap, st->element_mode ); iStart = 0; move16(); iEnd = L_frameTCX; move16(); - IF (st->narrowBand != 0) + IF( st->narrowBand != 0 ) { - attenuateNbSpectrum_fx(L_frameTCX, powerSpec); + attenuateNbSpectrum_fx( L_frameTCX, powerSpec ); } /* get shift to common exponent */ @@ -240,70 +245,69 @@ void AnalyzePowerSpectrum_fx( move16(); s2 = 0; move16(); - tmp = sub(mdctSpectrum_e, *powerSpec_e); - if (tmp > 0) + tmp = sub( mdctSpectrum_e, *powerSpec_e ); + if ( tmp > 0 ) { - s2 = negate(tmp); + s2 = negate( tmp ); } - if (tmp < 0) + if ( tmp < 0 ) { s1 = tmp; move16(); } /* get headroom */ - tmp = sub(getScaleFactor32(mdctSpectrum, L_frameTCX), s1); - tmp = s_min(tmp, sub(getScaleFactor32(powerSpec, L_frameTCX), s2)); - s1 = add(s1, tmp); - s2 = add(s2, tmp); + tmp = sub( getScaleFactor32( mdctSpectrum, L_frameTCX ), s1 ); + tmp = s_min( tmp, sub( getScaleFactor32( powerSpec, L_frameTCX ), s2 ) ); + s1 = add( s1, tmp ); + s2 = add( s2, tmp ); /* power spectrum: MDCT^2 + MDST^2 */ - FOR (i = iStart; i < iEnd; i++) + FOR( i = iStart; i < iEnd; i++ ) { - tmp = round_fx(L_shl(mdctSpectrum[i], s1)); - tmp32 = L_mult0(tmp, tmp); + tmp = round_fx( L_shl( mdctSpectrum[i], s1 ) ); + tmp32 = L_mult0( tmp, tmp ); #ifdef BASOP_NOGLOB tmp = round_fx_sat( L_shl_sat( powerSpec[i], s2 ) ); #else tmp = round_fx( L_shl( powerSpec[i], s2 ) ); #endif - tmp32 = L_mac0(tmp32, tmp, tmp); + tmp32 = L_mac0( tmp32, tmp, tmp ); powerSpec[i] = tmp32; move32(); } - *powerSpec_e = add(shl(sub(mdctSpectrum_e, s1), 1), 1); + *powerSpec_e = add( shl( sub( mdctSpectrum_e, s1 ), 1 ), 1 ); move16(); tmp8 = 0; move16(); test(); - if ( L_msu0(L_mult0(st->L_frame, extract_l(st->last_sr_core)), st->L_frame_past, extract_l(st->sr_core)) != 0 - || NE_16(st->last_core, TCX_20_CORE ) ) + if ( L_msu0( L_mult0( st->L_frame, extract_l( st->last_sr_core ) ), st->L_frame_past, extract_l( st->sr_core ) ) != 0 || NE_16( st->last_core, TCX_20_CORE ) ) { tmp8 = 1; move16(); } - ComputeSpectrumNoiseMeasure_fx(powerSpec, - L_frameTCX, - divide3216(L_mult(hTcxEnc->nmStartLine, L_frame), st->L_frame), - tmp8, - hTcxEnc->memQuantZeros_fx, - lowpassLine); + ComputeSpectrumNoiseMeasure_fx( powerSpec, + L_frameTCX, + divide3216( L_mult( hTcxEnc->nmStartLine, L_frame ), st->L_frame ), + tmp8, + hTcxEnc->memQuantZeros_fx, + lowpassLine ); - IF( LE_32(st->total_brate, ACELP_24k40)) + IF( LE_32( st->total_brate, ACELP_24k40 ) ) { - lowpassLine = shl(mult(st->hTcxCfg->bandwidth, L_frame), 1); + lowpassLine = shl( mult( st->hTcxCfg->bandwidth, L_frame ), 1 ); test(); - detectLowpassFac(powerSpec, *powerSpec_e, - L_frame, - sub(st->last_core, ACELP_CORE) == 0, - &hTcxEnc->measuredBwRatio, - lowpassLine); + detectLowpassFac( powerSpec, *powerSpec_e, + L_frame, + sub( st->last_core, ACELP_CORE ) == 0, + &hTcxEnc->measuredBwRatio, + lowpassLine ); } ELSE { @@ -312,55 +316,55 @@ void AnalyzePowerSpectrum_fx( } } -void AdaptLowFreqEmph_fx(Word32 x[], - Word16 x_e, - Word16 xq[], - Word16 invGain, - Word16 invGain_e, - Word16 tcx_lpc_shaped_ari, - Word16 lpcGains[], Word16 lpcGains_e[], - const Word16 lg - ) +void AdaptLowFreqEmph_fx( Word32 x[], + Word16 x_e, + Word16 xq[], + Word16 invGain, + Word16 invGain_e, + Word16 tcx_lpc_shaped_ari, + Word16 lpcGains[], + Word16 lpcGains_e[], + const Word16 lg ) { Word16 i, i_max, i_max_old, lg_4, tmp16, s; Word32 tmp32; - IF (tcx_lpc_shaped_ari == 0) + IF( tcx_lpc_shaped_ari == 0 ) { - lg_4 = shr(lg, 2); + lg_4 = shr( lg, 2 ); /* 1. find first magnitude maximum in lower quarter of spectrum */ - invGain_e = add(invGain_e, 1); + invGain_e = add( invGain_e, 1 ); i_max = -1; move16(); - FOR (i = 0; i < lg_4; i++) + FOR( i = 0; i < lg_4; i++ ) { - tmp32 = Mpy_32_16_1(L_abs(x[i]), invGain); /* multiply */ - tmp32 = L_shl(tmp32, sub(add(x_e, invGain_e), 15)); /* convert to 15Q16 */ + tmp32 = Mpy_32_16_1( L_abs( x[i] ), invGain ); /* multiply */ + tmp32 = L_shl( tmp32, sub( add( x_e, invGain_e ), 15 ) ); /* convert to 15Q16 */ test(); - IF ((GE_16(abs_s(xq[i]), 2))&&(tmp32>=0x3A000)) /* 0x3A000 -> 3.625 (15Q16) */ + IF( ( GE_16( abs_s( xq[i] ), 2 ) ) && ( tmp32 >= 0x3A000 ) ) /* 0x3A000 -> 3.625 (15Q16) */ { /* Debug initialization to catch illegal cases of xq[i] */ tmp16 = 0; - if (xq[i] > 0) + if ( xq[i] > 0 ) { tmp16 = 2; move16(); } - if (xq[i] < 0) + if ( xq[i] < 0 ) { tmp16 = -2; move16(); } - assert(tmp16 != 0); + assert( tmp16 != 0 ); - xq[i] = add(xq[i], tmp16); + xq[i] = add( xq[i], tmp16 ); move16(); i_max = i; @@ -369,12 +373,12 @@ void AdaptLowFreqEmph_fx(Word32 x[], } } - s = sub(add(x_e, invGain_e), 15); + s = sub( add( x_e, invGain_e ), 15 ); /* 2. compress value range of all xq up to i_max: add two steps */ - FOR (i = 0; i < i_max; i++) + FOR( i = 0; i < i_max; i++ ) { - xq[i] = quantize(x[i], invGain, s, 0x6000); + xq[i] = quantize( x[i], invGain, s, 0x6000 ); move16(); } @@ -382,37 +386,38 @@ void AdaptLowFreqEmph_fx(Word32 x[], i_max_old = i_max; move16(); - IF (i_max_old >= 0) + IF( i_max_old >= 0 ) { - invGain_e = add(invGain_e, 1); - i_max = -1; /* reset first maximum, update inverse gain */ move16(); + invGain_e = add( invGain_e, 1 ); + i_max = -1; /* reset first maximum, update inverse gain */ + move16(); - FOR (i = 0; i < lg_4; i++) + FOR( i = 0; i < lg_4; i++ ) { - tmp32 = Mpy_32_16_1(L_abs(x[i]), invGain); /* multiply */ - tmp32 = L_shl(tmp32, sub(add(x_e, invGain_e), 15)); /* convert to 15Q16 */ + tmp32 = Mpy_32_16_1( L_abs( x[i] ), invGain ); /* multiply */ + tmp32 = L_shl( tmp32, sub( add( x_e, invGain_e ), 15 ) ); /* convert to 15Q16 */ test(); - IF ((GE_16(abs_s(xq[i]), 2))&&(tmp32>=0x3A000)) /* 0x3A000 -> 3.625 (15Q16) */ + IF( ( GE_16( abs_s( xq[i] ), 2 ) ) && ( tmp32 >= 0x3A000 ) ) /* 0x3A000 -> 3.625 (15Q16) */ { /* Debug initialization to catch illegal cases of xq[i] */ tmp16 = 0; - if (xq[i] > 0) + if ( xq[i] > 0 ) { tmp16 = 2; move16(); } - if (xq[i] < 0) + if ( xq[i] < 0 ) { tmp16 = -2; move16(); } - assert(tmp16 != 0); + assert( tmp16 != 0 ); - xq[i] = add(xq[i], tmp16); + xq[i] = add( xq[i], tmp16 ); move16(); i_max = i; @@ -422,110 +427,106 @@ void AdaptLowFreqEmph_fx(Word32 x[], } } - s = sub(add(x_e, invGain_e), 15); + s = sub( add( x_e, invGain_e ), 15 ); /* 4. re-compress and quantize all xq up to half-height i_max+1 */ - FOR (i = 0; i < i_max; i++) + FOR( i = 0; i < i_max; i++ ) { - xq[i] = quantize(x[i], invGain, s, 0x6000); + xq[i] = quantize( x[i], invGain, s, 0x6000 ); move16(); } /* 5. always compress 2 lines; lines could be at index 0 and 1! */ - IF (i_max_old >= 0) + IF( i_max_old >= 0 ) { - invGain_e = sub(invGain_e, 1); /* reset inverse gain */ - if (LT_16(i_max, i_max_old)) + invGain_e = sub( invGain_e, 1 ); /* reset inverse gain */ + if ( LT_16( i_max, i_max_old ) ) { i_max = i_max_old; move16(); } } - i = add(i_max, 1); + i = add( i_max, 1 ); - tmp32 = Mpy_32_16_1(L_abs(x[i]), invGain); /* multiply */ - tmp32 = L_shl(tmp32, sub(add(x_e, invGain_e), 15)); /* convert to 15Q16 */ - IF (GE_32(tmp32, 0x3A000)) + tmp32 = Mpy_32_16_1( L_abs( x[i] ), invGain ); /* multiply */ + tmp32 = L_shl( tmp32, sub( add( x_e, invGain_e ), 15 ) ); /* convert to 15Q16 */ + IF( GE_32( tmp32, 0x3A000 ) ) { /* Debug initialization to catch illegal cases of xq[i] */ tmp16 = 0; - if (xq[i] > 0) + if ( xq[i] > 0 ) { tmp16 = 2; move16(); } - if (xq[i] < 0) + if ( xq[i] < 0 ) { tmp16 = -2; move16(); } - assert(tmp16 != 0); + assert( tmp16 != 0 ); - xq[i] = add(xq[i], tmp16); + xq[i] = add( xq[i], tmp16 ); move16(); } ELSE { - xq[i] = quantize(x[i], invGain, sub(add(x_e, invGain_e), 15), 0x6000); + xq[i] = quantize( x[i], invGain, sub( add( x_e, invGain_e ), 15 ), 0x6000 ); move16(); } - i = add(i, 1); + i = add( i, 1 ); - tmp32 = Mpy_32_16_1(L_abs(x[i]), invGain); /* multiply */ - tmp32 = L_shl(tmp32, sub(add(x_e, invGain_e), 15)); /* convert to 15Q16 */ - IF (GE_32(tmp32, 0x3A000)) + tmp32 = Mpy_32_16_1( L_abs( x[i] ), invGain ); /* multiply */ + tmp32 = L_shl( tmp32, sub( add( x_e, invGain_e ), 15 ) ); /* convert to 15Q16 */ + IF( GE_32( tmp32, 0x3A000 ) ) { /* Debug initialization to catch illegal cases of xq[i] */ tmp16 = 0; - if (xq[i] > 0) + if ( xq[i] > 0 ) { tmp16 = 2; move16(); } - if (xq[i] < 0) + if ( xq[i] < 0 ) { tmp16 = -2; move16(); } - assert(tmp16 != 0); + assert( tmp16 != 0 ); - xq[i] = add(xq[i], tmp16); + xq[i] = add( xq[i], tmp16 ); move16(); } ELSE { - xq[i] = quantize(x[i], invGain, sub(add(x_e, invGain_e), 15), 0x6000); + xq[i] = quantize( x[i], invGain, sub( add( x_e, invGain_e ), 15 ), 0x6000 ); move16(); } - - } - ELSE /*if(!tcx_lpc_shaped_ari)*/ + ELSE /*if(!tcx_lpc_shaped_ari)*/ { - PsychAdaptLowFreqEmph_fx(x, lpcGains, lpcGains_e); - }/*if(!tcx_lpc_shaped_ari)*/ - + PsychAdaptLowFreqEmph_fx( x, lpcGains, lpcGains_e ); + } /*if(!tcx_lpc_shaped_ari)*/ } -void PsychAdaptLowFreqEmph_fx(Word32 x[], - const Word16 lpcGains[], const Word16 lpcGains_e[] - ) +void PsychAdaptLowFreqEmph_fx( Word32 x[], + const Word16 lpcGains[], + const Word16 lpcGains_e[] ) { Word16 i; Word16 max, max_e, fac, min, min_e, tmp, tmp_e; Word32 L_tmp; - - assert(lpcGains[0] >= 0x4000); + assert( lpcGains[0] >= 0x4000 ); max = lpcGains[0]; move16(); @@ -537,9 +538,9 @@ void PsychAdaptLowFreqEmph_fx(Word32 x[], move16(); /* find minimum (min) and maximum (max) of LPC gains in low frequencies */ - FOR (i = 1; i < 9; i++) + FOR( i = 1; i < 9; i++ ) { - IF (compMantExp16Unorm(lpcGains[i], lpcGains_e[i], min, min_e) < 0) + IF( compMantExp16Unorm( lpcGains[i], lpcGains_e[i], min, min_e ) < 0 ) { min = lpcGains[i]; move16(); @@ -547,7 +548,7 @@ void PsychAdaptLowFreqEmph_fx(Word32 x[], move16(); } - IF (compMantExp16Unorm(lpcGains[i], lpcGains_e[i], max, max_e) > 0) + IF( compMantExp16Unorm( lpcGains[i], lpcGains_e[i], max, max_e ) > 0 ) { max = lpcGains[i]; move16(); @@ -556,129 +557,133 @@ void PsychAdaptLowFreqEmph_fx(Word32 x[], } } - min_e = add(min_e, 5); /* min *= 32.0f; */ + min_e = add( min_e, 5 ); /* min *= 32.0f; */ test(); - IF ((compMantExp16Unorm(max, max_e, min, min_e) < 0) && (max > 0)) + IF( ( compMantExp16Unorm( max, max_e, min, min_e ) < 0 ) && ( max > 0 ) ) { /* fac = tmp = (float)pow(min / max, 0.0078125f); */ tmp_e = max_e; move16(); - tmp = Inv16(max, &tmp_e); - L_tmp = L_shl(L_mult(tmp, min), sub(add(tmp_e, min_e), 6)); /* Q25 */ - L_tmp = L_add(BASOP_Util_Log2(L_tmp), 6<<25); /* Q25 */ - L_tmp = L_shr(L_tmp, 7); /* 0.0078125f = 1.f/(1<<7) */ - L_tmp = BASOP_Util_InvLog2(L_sub(L_tmp, 1<<25)); /* Q30 */ - tmp = round_fx(L_tmp); /* Q14 */ - fac = shr(tmp, 1); /* Q13 */ + tmp = Inv16( max, &tmp_e ); + L_tmp = L_shl( L_mult( tmp, min ), sub( add( tmp_e, min_e ), 6 ) ); /* Q25 */ + L_tmp = L_add( BASOP_Util_Log2( L_tmp ), 6 << 25 ); /* Q25 */ + L_tmp = L_shr( L_tmp, 7 ); /* 0.0078125f = 1.f/(1<<7) */ + L_tmp = BASOP_Util_InvLog2( L_sub( L_tmp, 1 << 25 ) ); /* Q30 */ + tmp = round_fx( L_tmp ); /* Q14 */ + fac = shr( tmp, 1 ); /* Q13 */ /* gradual boosting of lowest 32 bins; DC is boosted by (min/max)^1/4 */ - FOR (i = 31; i >= 0; i--) + FOR( i = 31; i >= 0; i-- ) { - x[i] = L_shl(Mpy_32_16_1(x[i], fac), 2); + x[i] = L_shl( Mpy_32_16_1( x[i], fac ), 2 ); move32(); - fac = shl(mult_r(fac, tmp), 1); + fac = shl( mult_r( fac, tmp ), 1 ); } } - } -Word16 SQ_gain_fx( /* output: SQ gain */ - Word32 x[], /* input: vector to quantize */ - Word16 x_e, /* input: exponent */ - Word16 nbitsSQ, /* input: number of bits targeted */ - Word16 lg, /* input: vector size (2048 max) */ - Word16 *gain_e) /* output: SQ gain exponent */ +Word16 SQ_gain_fx( /* output: SQ gain */ + Word32 x[], /* input: vector to quantize */ + Word16 x_e, /* input: exponent */ + Word16 nbitsSQ, /* input: number of bits targeted */ + Word16 lg, /* input: vector size (2048 max) */ + Word16 *gain_e ) /* output: SQ gain exponent */ { Word16 i, iter, lg_4, s, tmp16; Word32 ener, tmp32; Word32 target, fac, offset; - Word32 en[N_MAX/4]; + Word32 en[N_MAX / 4]; - lg_4 = shr(lg, 2); + lg_4 = shr( lg, 2 ); /* energy of quadruples with 9dB offset */ - FOR (i=0; i 0.15*log2(10) */ - fac = L_add(0x2A854B, 0); /* -> 12.8f*log2(10); */ - offset = L_add(fac, 0); + target = L_mult( 0x3FC8, sub( nbitsSQ, shr( lg, 4 ) ) ); /* 0x3FC8 -> 0.15*log2(10) */ + fac = L_add( 0x2A854B, 0 ); /* -> 12.8f*log2(10); */ + offset = L_add( fac, 0 ); /* find offset (0 to 128 dB with step of 0.125dB) */ - FOR (iter=0; iter<10; iter++) + FOR( iter = 0; iter < 10; iter++ ) { - fac = L_shr(fac, 1); - offset = L_sub(offset, fac); - ener = L_deposit_l(0); + fac = L_shr( fac, 1 ); + offset = L_sub( offset, fac ); + ener = L_deposit_l( 0 ); - FOR (i=0; i 0.3*log2(10); */ + if ( GT_32( tmp32, 0xFF20 ) ) /* 0xFF20 -> 0.3*log2(10); */ { - ener = L_add(ener, tmp32); + ener = L_add( ener, tmp32 ); } /* if ener is above target -> break and increase offset */ - IF (GT_32(ener, target)) + IF( GT_32( ener, target ) ) { - offset = L_add(offset, fac); + offset = L_add( offset, fac ); BREAK; } } } - offset = L_add(L_shr(offset, 1), 0x17EB0); /* 0x17EB0 -> 0.45*log2(10) */ + offset = L_add( L_shr( offset, 1 ), 0x17EB0 ); /* 0x17EB0 -> 0.45*log2(10) */ - *gain_e = add(extract_h(offset), 1); + *gain_e = add( extract_h( offset ), 1 ); move16(); - offset = L_sub(L_and(offset, 0xFFFF), 0x10000); - tmp16 = extract_h(BASOP_Util_InvLog2(L_shl(offset, 9))); + offset = L_sub( L_and( offset, 0xFFFF ), 0x10000 ); + tmp16 = extract_h( BASOP_Util_InvLog2( L_shl( offset, 9 ) ) ); /* return gain */ @@ -686,105 +691,103 @@ Word16 SQ_gain_fx( /* output: SQ gain */ } void tcx_scalar_quantization_fx( - Word32 *x, /* i: input coefficients */ - Word16 x_e, /* i: exponent */ - Word16 *xq, /* o: quantized coefficients */ - Word16 L_frame, /* i: frame length */ - Word16 gain, /* i: quantization gain */ - Word16 gain_e, /* i: quantization gain exponent */ - Word16 offset, /* i: rounding offset (deadzone) */ - Word8 const *memQuantZeros_fx, /* i: coefficients to be set to 0 */ - const Word16 alfe_flag -) + Word32 *x, /* i: input coefficients */ + Word16 x_e, /* i: exponent */ + Word16 *xq, /* o: quantized coefficients */ + Word16 L_frame, /* i: frame length */ + Word16 gain, /* i: quantization gain */ + Word16 gain_e, /* i: quantization gain exponent */ + Word16 offset, /* i: rounding offset (deadzone) */ + Word8 const *memQuantZeros_fx, /* i: coefficients to be set to 0 */ + const Word16 alfe_flag ) { Word16 i, tmp16, s; Word32 tmp32, offs32; /* common exponent for x and gain for comparison */ - tmp16 = sub(gain_e, x_e); - tmp32 = L_shl(L_deposit_h(gain), s_max(-31, s_min(tmp16, 0))); - tmp16 = negate(s_max(tmp16, 0)); + tmp16 = sub( gain_e, x_e ); + tmp32 = L_shl( L_deposit_h( gain ), s_max( -31, s_min( tmp16, 0 ) ) ); + tmp16 = negate( s_max( tmp16, 0 ) ); - i = sub(L_frame, 1); - WHILE ((memQuantZeros_fx[i] != 0) && (LT_32(L_abs(L_shl(x[i], tmp16)), tmp32))) + i = sub( L_frame, 1 ); + WHILE( ( memQuantZeros_fx[i] != 0 ) && ( LT_32( L_abs( L_shl( x[i], tmp16 ) ), tmp32 ) ) ) { test(); xq[i] = 0; move16(); - i = sub(i, 1); + i = sub( i, 1 ); } /* invert gain */ - gain = Inv16(gain, &gain_e); + gain = Inv16( gain, &gain_e ); - s = sub(add(x_e, gain_e), 15); + s = sub( add( x_e, gain_e ), 15 ); /*It should almost never happen and if so the quantization will be discarded later on (saturation of gain Quantizer).*/ - IF( GT_16(s,31)) + IF( GT_16( s, 31 ) ) { /* Limit the inverse gain to maximal possible value=sqrtL_spec/NORM_MDCT_FACTOR)*/ gain = 22435; /*sqrt(1200/NORM_MDCT_FACTOR) in 2Q13*/ gain_e = 2; - s = sub(add(x_e, gain_e), 15); + s = sub( add( x_e, gain_e ), 15 ); } /* substract 0x8000 to affect the mac_r in the following loop so it acts like extract_h. the 0x4000 will be multiplied by 2 by the mac_r to get to 0x8000 and disable the round. */ - offset = sub(offset, 0x4000); + offset = sub( offset, 0x4000 ); - FOR (; i >= 0; i--) + FOR( ; i >= 0; i-- ) { - offs32 = Mpy_32_16_1(L_abs(x[i]), gain); /* multiply */ + offs32 = Mpy_32_16_1( L_abs( x[i] ), gain ); /* multiply */ #ifdef BASOP_NOGLOB - offs32 = L_shl_sat( offs32, s ); /* convert to 15Q16 */ - tmp16 = mac_r_sat(offs32, offset, 1); /* add offset and truncate */ + offs32 = L_shl_sat( offs32, s ); /* convert to 15Q16 */ + tmp16 = mac_r_sat( offs32, offset, 1 ); /* add offset and truncate */ #else - offs32 = L_shl(offs32, s); /* convert to 15Q16 */ - tmp16 = mac_r(offs32, offset, 1); /* add offset and truncate */ + offs32 = L_shl( offs32, s ); /* convert to 15Q16 */ + tmp16 = mac_r( offs32, offset, 1 ); /* add offset and truncate */ #endif - if (x[i] < 0) tmp16 = negate(tmp16); /* restore sign */ + if ( x[i] < 0 ) + tmp16 = negate( tmp16 ); /* restore sign */ xq[i] = tmp16; move16(); } - IF (alfe_flag == 0) + IF( alfe_flag == 0 ) { - AdaptLowFreqEmph_fx(x, x_e, xq, gain, gain_e, - 0, NULL, NULL, - L_frame - ); + AdaptLowFreqEmph_fx( x, x_e, xq, gain, gain_e, + 0, NULL, NULL, + L_frame ); } - } Word16 tcx_scalar_quantization_rateloop_fx( - Word32 *x, /* i : input coefficients */ - Word16 x_e, /* i : exponent */ - Word16 *xq, /* o : quantized coefficients */ - Word16 L_frame, /* i : frame length */ - Word16 *gain, /* i/o: quantization gain */ - Word16 *gain_e, /* i/o: gain exponent */ - Word16 offset, /* i : rounding offset (deadzone) */ - Word8 const*memQuantZeros_fx, /* i : coefficients to be set to 0 */ - Word16 *lastnz_out, /* i/o: last nonzero coeff index */ - Word16 target, /* i : target number of bits */ - Word16 *nEncoded, /* o : number of encoded coeff */ - Word16 *stop, /* i/o: stop param */ - Word16 sqBits_in_noStop, /* i : number of sqBits as determined in prev. quant. stage, w/o using stop mechanism (ie might exceed target bits) */ - Word16 sqBits_in, /* i : number of sqBits as determined in prev. quant. stage, using stop mechanism (ie always <= target bits) */ - Word16 tcxRateLoopOpt, /* i : turns on/off rateloop optimization */ + Word32 *x, /* i : input coefficients */ + Word16 x_e, /* i : exponent */ + Word16 *xq, /* o : quantized coefficients */ + Word16 L_frame, /* i : frame length */ + Word16 *gain, /* i/o: quantization gain */ + Word16 *gain_e, /* i/o: gain exponent */ + Word16 offset, /* i : rounding offset (deadzone) */ + Word8 const *memQuantZeros_fx, /* i : coefficients to be set to 0 */ + Word16 *lastnz_out, /* i/o: last nonzero coeff index */ + Word16 target, /* i : target number of bits */ + Word16 *nEncoded, /* o : number of encoded coeff */ + Word16 *stop, /* i/o: stop param */ + Word16 sqBits_in_noStop, /* i : number of sqBits as determined in prev. quant. stage, w/o using stop mechanism (ie might exceed target bits) */ + Word16 sqBits_in, /* i : number of sqBits as determined in prev. quant. stage, using stop mechanism (ie always <= target bits) */ + Word16 tcxRateLoopOpt, /* i : turns on/off rateloop optimization */ const Word8 tcxonly, - CONTEXT_HM_CONFIG *hm_cfg /* i : configuration of the context-based harmonic model */ + CONTEXT_HM_CONFIG *hm_cfg /* i : configuration of the context-based harmonic model */ ) { const Word16 iter_max = 4; Word16 sqBits; Word16 stopFlag; - Word8 ubfound,lbfound; + Word8 ubfound, lbfound; Word16 ub, ub_e, lb, lb_e; Word16 shift, shiftInv; Word16 iter; @@ -796,14 +799,13 @@ Word16 tcx_scalar_quantization_rateloop_fx( Word16 old_sqBits; Word16 mod_adjust0, mod_adjust1; Word16 inv_target, inv_target_e; - const Word16 kMargin = 0x7AE1; /* 0.96 */ + const Word16 kMargin = 0x7AE1; /* 0.96 */ const Word16 kMarginInv = 0x42AB; /* 1/0.96 (1Q14) */ Word16 tmp, fac1, fac2; Word32 tmp32; Word16 lastnz; - /* Init */ sqGain = *gain; move16(); @@ -815,8 +817,10 @@ Word16 tcx_scalar_quantization_rateloop_fx( move16(); lbfound = 0; move16(); - shift = 0x41DE; /* 10^(1/80), 1Q14 */ move16(); - shiftInv = 0x78D7; /* 10^(-1/40) */ move16(); + shift = 0x41DE; /* 10^(1/80), 1Q14 */ + move16(); + shiftInv = 0x78D7; /* 10^(-1/40) */ + move16(); lb = lb_e = 0; move16(); ub = ub_e = 0; @@ -827,33 +831,33 @@ Word16 tcx_scalar_quantization_rateloop_fx( move16(); lastnz = *lastnz_out; move16(); - old_stopFlag = stopFlag; + old_stopFlag = stopFlag; move16(); - old_nEncoded = *nEncoded; + old_nEncoded = *nEncoded; move16(); - old_sqBits = sqBits_in_noStop; + old_sqBits = sqBits_in_noStop; move16(); - sqBits = sqBits_in; + sqBits = sqBits_in; move16(); - mod_adjust0 = extract_l(L_shr(L_max(0x10000, L_sub(0x24CCD, L_mult(0x0052, target))), 3)); /* 2Q13 */ - mod_adjust1 = div_s(0x2000, mod_adjust0); /* 0Q15 */ + mod_adjust0 = extract_l( L_shr( L_max( 0x10000, L_sub( 0x24CCD, L_mult( 0x0052, target ) ) ), 3 ) ); /* 2Q13 */ + mod_adjust1 = div_s( 0x2000, mod_adjust0 ); /* 0Q15 */ inv_target_e = 15; move16(); - inv_target = Inv16(target, &inv_target_e); + inv_target = Inv16( target, &inv_target_e ); - fac1 = shl(mult(mult(kMarginInv, mod_adjust0), inv_target), 1); /* 2Q13 */ - fac2 = mult(mult(kMargin, mod_adjust1), inv_target); + fac1 = shl( mult( mult( kMarginInv, mod_adjust0 ), inv_target ), 1 ); /* 2Q13 */ + fac2 = mult( mult( kMargin, mod_adjust1 ), inv_target ); /* Loop */ - FOR ( iter=0 ; iter 0) + if ( tcxRateLoopOpt > 0 ) { stopFlag = 0; move16(); } sqBits = ACcontextMapping_encode2_estimate_no_mem_s17_LC_fx( xq, L_frame, - &lastnz, - nEncoded, target, &stopFlag, - hm_cfg - ); + &lastnz, + nEncoded, target, &stopFlag, + hm_cfg ); - IF ( tcxRateLoopOpt > 0 ) + IF( tcxRateLoopOpt > 0 ) { test(); test(); @@ -1012,9 +1017,9 @@ Word16 tcx_scalar_quantization_rateloop_fx( test(); test(); test(); - IF ( ((GE_16(*nEncoded, old_nEncoded))&&(GE_16(stopFlag,old_stopFlag)))|| - ((GT_16(*nEncoded, old_nEncoded) ) && ((stopFlag == 0) && (old_stopFlag > 0))) || - ((stopFlag == 0) && (old_stopFlag == 0)) ) + IF( ( ( GE_16( *nEncoded, old_nEncoded ) ) && ( GE_16( stopFlag, old_stopFlag ) ) ) || + ( ( GT_16( *nEncoded, old_nEncoded ) ) && ( ( stopFlag == 0 ) && ( old_stopFlag > 0 ) ) ) || + ( ( stopFlag == 0 ) && ( old_stopFlag == 0 ) ) ) { *gain = sqGain; move16(); @@ -1032,7 +1037,7 @@ Word16 tcx_scalar_quantization_rateloop_fx( } } /* for ( iter=0 ; iter 0 ) + IF( tcxRateLoopOpt > 0 ) { /* Quantize spectrum */ tcx_scalar_quantization_fx( x, x_e, xq, L_frame, *gain, *gain_e, offset, memQuantZeros_fx, tcxonly ); @@ -1042,7 +1047,7 @@ Word16 tcx_scalar_quantization_rateloop_fx( move16(); sqBits = old_sqBits; move16(); - *stop = old_stopFlag; + *stop = old_stopFlag; move16(); } ELSE @@ -1062,7 +1067,7 @@ Word16 tcx_scalar_quantization_rateloop_fx( return sqBits; } -void QuantizeGain(Word16 n, Word16 *pGain, Word16 *pGain_e, Word16 *pQuantizedGain) +void QuantizeGain( Word16 n, Word16 *pGain, Word16 *pGain_e, Word16 *pQuantizedGain ) { Word16 ener, ener_e, enerInv, enerInv_e, gain, gain_e; Word16 quantizedGain; @@ -1072,37 +1077,37 @@ void QuantizeGain(Word16 n, Word16 *pGain, Word16 *pGain_e, Word16 *pQuantizedGa #endif #ifdef BASOP_NOGLOB - ener = mult_r(shl_o(n, 5, &Overflow), 26214/*128.f/NORM_MDCT_FACTOR Q15*/); + ener = mult_r( shl_o( n, 5, &Overflow ), 26214 /*128.f/NORM_MDCT_FACTOR Q15*/ ); #else - ener = mult_r(shl(n, 5), 26214/*128.f/NORM_MDCT_FACTOR Q15*/); + ener = mult_r( shl( n, 5 ), 26214 /*128.f/NORM_MDCT_FACTOR Q15*/ ); #endif - ener_e = 15-5-7; + ener_e = 15 - 5 - 7; move16(); IF( n >= 1024 ) { /*reduce precision for avoiding overflow*/ - ener = mult_r(shl(n, 4), 26214/*128.f/NORM_MDCT_FACTOR Q15*/); - ener_e = 15-4-7; + ener = mult_r( shl( n, 4 ), 26214 /*128.f/NORM_MDCT_FACTOR Q15*/ ); + ener_e = 15 - 4 - 7; } - BASOP_Util_Sqrt_InvSqrt_MantExp(ener, ener_e, &ener, &ener_e, &enerInv, &enerInv_e); + BASOP_Util_Sqrt_InvSqrt_MantExp( ener, ener_e, &ener, &ener_e, &enerInv, &enerInv_e ); - gain = mult(*pGain, ener); + gain = mult( *pGain, ener ); gain_e = *pGain_e + ener_e; - assert(gain > 0); + assert( gain > 0 ); /* quantize gain with step of 0.714 dB */ - quantizedGain = add(round_fx(BASOP_Util_Log2(L_deposit_h(gain))), shl(gain_e, 9)); /* 6Q9 */ - quantizedGain = mult(quantizedGain, 0x436E); /* 10Q5; 0x436E -> 28/log2(10) (4Q11) */ - quantizedGain = shr(add(quantizedGain, 0x10), 5); /* round */ + quantizedGain = add( round_fx( BASOP_Util_Log2( L_deposit_h( gain ) ) ), shl( gain_e, 9 ) ); /* 6Q9 */ + quantizedGain = mult( quantizedGain, 0x436E ); /* 10Q5; 0x436E -> 28/log2(10) (4Q11) */ + quantizedGain = shr( add( quantizedGain, 0x10 ), 5 ); /* round */ - if (quantizedGain < 0) + if ( quantizedGain < 0 ) { quantizedGain = 0; move16(); } - if (quantizedGain > 127) + if ( quantizedGain > 127 ) { quantizedGain = 127; move16(); @@ -1111,30 +1116,29 @@ void QuantizeGain(Word16 n, Word16 *pGain, Word16 *pGain_e, Word16 *pQuantizedGa *pQuantizedGain = quantizedGain; move16(); - tmp32 = L_shl(L_mult0(quantizedGain, 0x797D), 7); /* 6Q25; 0x797D -> log2(10)/28 (Q18) */ - gain_e = add(extract_l(L_shr(tmp32, 25)), 1); /* get exponent */ - gain = round_fx(BASOP_Util_InvLog2(L_or(tmp32, 0xFE000000))); + tmp32 = L_shl( L_mult0( quantizedGain, 0x797D ), 7 ); /* 6Q25; 0x797D -> log2(10)/28 (Q18) */ + gain_e = add( extract_l( L_shr( tmp32, 25 ) ), 1 ); /* get exponent */ + gain = round_fx( BASOP_Util_InvLog2( L_or( tmp32, 0xFE000000 ) ) ); - *pGain = mult(gain, enerInv); + *pGain = mult( gain, enerInv ); move16(); - *pGain_e = add(gain_e, enerInv_e); + *pGain_e = add( gain_e, enerInv_e ); move16(); - } void tcx_noise_factor_fx( - Word32 *x_orig, /* i: unquantized mdct coefficients */ - Word16 x_orig_e, /* i: exponent */ - Word32 *sqQ, /* i: quantized mdct coefficients */ - Word16 iFirstLine, /* i: first coefficient to be considered */ - Word16 lowpassLine, /* i: last nonzero coefficients after low-pass */ - Word16 nTransWidth, /* i: minimum size of hole to be checked */ - Word16 L_frame, /* i: frame length */ - Word16 gain_tcx, /* i: tcx gain */ - Word16 gain_tcx_e, /* i: gain exponent */ - Word16 tiltCompFactor, /* i: LPC tilt compensation factor */ - Word16 *fac_ns, /* o: noise factor */ - Word16 *quantized_fac_ns/* o: quantized noise factor */ + Word32 *x_orig, /* i: unquantized mdct coefficients */ + Word16 x_orig_e, /* i: exponent */ + Word32 *sqQ, /* i: quantized mdct coefficients */ + Word16 iFirstLine, /* i: first coefficient to be considered */ + Word16 lowpassLine, /* i: last nonzero coefficients after low-pass */ + Word16 nTransWidth, /* i: minimum size of hole to be checked */ + Word16 L_frame, /* i: frame length */ + Word16 gain_tcx, /* i: tcx gain */ + Word16 gain_tcx_e, /* i: gain exponent */ + Word16 tiltCompFactor, /* i: LPC tilt compensation factor */ + Word16 *fac_ns, /* o: noise factor */ + Word16 *quantized_fac_ns /* o: quantized noise factor */ ) { Word16 i, k, maxK, segmentOffset; @@ -1143,104 +1147,106 @@ void tcx_noise_factor_fx( Word32 accu1, accu2, tmp32; Word16 tmp1, tmp2, s; Word16 c1, c2; - Word16 att; /* noise level attenuation factor for transient windows */ + Word16 att; /* noise level attenuation factor for transient windows */ Word32 xMax; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - assert(nTransWidth <= 16); + assert( nTransWidth <= 16 ); - c1 = sub(shl(nTransWidth, 1), 4); - c2 = mult(9216/*0.28125f Q15*/, inv_int[nTransWidth]); - nTransWidth_1 = sub(nTransWidth, 1); + c1 = sub( shl( nTransWidth, 1 ), 4 ); + c2 = mult( 9216 /*0.28125f Q15*/, inv_int[nTransWidth] ); + nTransWidth_1 = sub( nTransWidth, 1 ); /*Adjust noise filling level*/ - sqErrorNrg = L_deposit_l(0); - n = L_deposit_l(0); + sqErrorNrg = L_deposit_l( 0 ); + n = L_deposit_l( 0 ); /* get inverse frame length */ - tmp1 = getInvFrameLen(L_frame); + tmp1 = getInvFrameLen( L_frame ); /* tilt_factor = 1.0f /(float)pow(max(0.375f, tiltCompFactor), 1.0f/(float)L_frame); */ - tmp32 = BASOP_Util_Log2(L_deposit_h(s_max(0x3000, tiltCompFactor))); /* 6Q25 */ - tmp32 = L_shr(Mpy_32_16_1(tmp32, negate(tmp1)), 6); - tilt_factor = round_fx(BASOP_Util_InvLog2(L_sub(tmp32, 0x2000000))); /* 1Q14 */ + tmp32 = BASOP_Util_Log2( L_deposit_h( s_max( 0x3000, tiltCompFactor ) ) ); /* 6Q25 */ + tmp32 = L_shr( Mpy_32_16_1( tmp32, negate( tmp1 ) ), 6 ); + tilt_factor = round_fx( BASOP_Util_InvLog2( L_sub( tmp32, 0x2000000 ) ) ); /* 1Q14 */ /* inv_gain2 = 1.0f / ((float)(nTransWidth * nTransWidth) * gain_tcx); */ - tmp32 = L_mult(imult1616(nTransWidth, nTransWidth), gain_tcx); /* 15Q16 */ - tmp1 = norm_l(tmp32); - inv_gain2 = round_fx(L_shl(tmp32, tmp1)); - inv_gain2_e = add(sub(15, tmp1), gain_tcx_e); - inv_gain2 = Inv16(inv_gain2, &inv_gain2_e); - inv_gain2 = shr(inv_gain2, 2); /* 2 bits headroom */ - inv_gain2_e = add(inv_gain2_e, 2); + tmp32 = L_mult( imult1616( nTransWidth, nTransWidth ), gain_tcx ); /* 15Q16 */ + tmp1 = norm_l( tmp32 ); + inv_gain2 = round_fx( L_shl( tmp32, tmp1 ) ); + inv_gain2_e = add( sub( 15, tmp1 ), gain_tcx_e ); + inv_gain2 = Inv16( inv_gain2, &inv_gain2_e ); + inv_gain2 = shr( inv_gain2, 2 ); /* 2 bits headroom */ + inv_gain2_e = add( inv_gain2_e, 2 ); /* find last nonzero line below iFirstLine, use it as start offset */ - tmp1 = shr(iFirstLine, 1); - FOR (i = iFirstLine; i > tmp1; i--) + tmp1 = shr( iFirstLine, 1 ); + FOR( i = iFirstLine; i > tmp1; i-- ) { - IF (sqQ[i] != 0) + IF( sqQ[i] != 0 ) { BREAK; } } /* inv_gain2 *= (float)pow(tilt_factor, (float)i); */ - FOR (k = 0; k < i; k++) + FOR( k = 0; k < i; k++ ) { - inv_gain2 = shl(mult(inv_gain2, tilt_factor), 1); + inv_gain2 = shl( mult( inv_gain2, tilt_factor ), 1 ); } /* initialize left (k) and right (maxK) non-zero neighbor pointers */ k = 0; move16(); - FOR (maxK = 1; maxK < nTransWidth; maxK++) + FOR( maxK = 1; maxK < nTransWidth; maxK++ ) { - IF (sqQ[i+maxK] != 0) + IF( sqQ[i + maxK] != 0 ) { BREAK; } } - i = add(i, 1); + i = add( i, 1 ); segmentOffset = i; move16(); - IF (LE_16(nTransWidth, 3)) + IF( LE_16( nTransWidth, 3 ) ) { - accu1 = L_deposit_l(0); - accu2 = L_deposit_l(0); - xMax = L_deposit_l(0); + accu1 = L_deposit_l( 0 ); + accu2 = L_deposit_l( 0 ); + xMax = L_deposit_l( 0 ); - FOR (k = s_and(i, (Word16)0xFFFE); k < lowpassLine; k++) + FOR( k = s_and( i, (Word16) 0xFFFE ); k < lowpassLine; k++ ) { - xMax = L_max(xMax, L_abs(x_orig[k])); + xMax = L_max( xMax, L_abs( x_orig[k] ) ); } - s = sub(norm_l(xMax), 4); + s = sub( norm_l( xMax ), 4 ); - FOR (k = s_and(i, (Word16)0xFFFE); k < lowpassLine; k += 2) + FOR( k = s_and( i, (Word16) 0xFFFE ); k < lowpassLine; k += 2 ) { /* even-index bins, left sub-win */ - tmp1 = round_fx(L_shl(x_orig[k], s)); - accu1 = L_mac0(accu1, tmp1, tmp1); + tmp1 = round_fx( L_shl( x_orig[k], s ) ); + accu1 = L_mac0( accu1, tmp1, tmp1 ); /* odd-index bins, right sub-win */ - tmp1 = round_fx(L_shl(x_orig[k+1], s)); - accu2 = L_mac0(accu2, tmp1, tmp1); + tmp1 = round_fx( L_shl( x_orig[k + 1], s ) ); + accu2 = L_mac0( accu2, tmp1, tmp1 ); } k = 0; move16(); - if (accu1 == 0) accu1 = L_deposit_l(1); - if (accu2 == 0) accu2 = L_deposit_l(1); + if ( accu1 == 0 ) + accu1 = L_deposit_l( 1 ); + if ( accu2 == 0 ) + accu2 = L_deposit_l( 1 ); - att = BASOP_Util_Divide3232_Scale( L_shl(L_min(accu1, accu2), 1), L_add(accu1, accu2), &s ); - att = Sqrt16(att, &s); + att = BASOP_Util_Divide3232_Scale( L_shl( L_min( accu1, accu2 ), 1 ), L_add( accu1, accu2 ), &s ); + att = Sqrt16( att, &s ); BASOP_SATURATE_WARNING_OFF_EVS; /* att is always <= 1.0 */ #ifdef BASOP_NOGLOB - att = shl_o(att, s, &Overflow); + att = shl_o( att, s, &Overflow ); #else - att = shl(att, s); + att = shl( att, s ); #endif BASOP_SATURATE_WARNING_ON_EVS; } @@ -1250,150 +1256,168 @@ void tcx_noise_factor_fx( move16(); } - accu1 = L_deposit_l(0); + accu1 = L_deposit_l( 0 ); - tmp1 = sub(lowpassLine, nTransWidth); - FOR (; i <= tmp1; i++) + tmp1 = sub( lowpassLine, nTransWidth ); + FOR( ; i <= tmp1; i++ ) { - inv_gain2 = shl(mult(inv_gain2, tilt_factor), 1); + inv_gain2 = shl( mult( inv_gain2, tilt_factor ), 1 ); - IF (EQ_16(maxK, 1)) /* current line is not zero, so reset pointers */ + IF( EQ_16( maxK, 1 ) ) /* current line is not zero, so reset pointers */ { - k = sub(i, segmentOffset); + k = sub( i, segmentOffset ); - IF (k > 0) /* add segment sum to sum of segment magnitudes */ + IF( k > 0 ) /* add segment sum to sum of segment magnitudes */ { - IF (LE_16(nTransWidth, 3)) + IF( LE_16( nTransWidth, 3 ) ) { - tmp2 = sub(k, c1); - if (tmp2 > 0) n = L_msu(n, k, (Word16)0x8000); - if (tmp2 > 0) n = L_mac(n, nTransWidth_1, (Word16)0x8000); - if (tmp2 <= 0) n = L_mac(n, int_sqr[k], c2); + tmp2 = sub( k, c1 ); + if ( tmp2 > 0 ) + n = L_msu( n, k, (Word16) 0x8000 ); + if ( tmp2 > 0 ) + n = L_mac( n, nTransWidth_1, (Word16) 0x8000 ); + if ( tmp2 <= 0 ) + n = L_mac( n, int_sqr[k], c2 ); } ELSE { - tmp2 = sub(k, 12); - if (tmp2 > 0) n = L_msu(n, k, (Word16)0x8000); - if (tmp2 > 0) n = L_sub(n, 0x70000); - if (tmp2 <= 0) n = L_mac(n, int_sqr[k], 1152/*0.03515625f Q15*/); + tmp2 = sub( k, 12 ); + if ( tmp2 > 0 ) + n = L_msu( n, k, (Word16) 0x8000 ); + if ( tmp2 > 0 ) + n = L_sub( n, 0x70000 ); + if ( tmp2 <= 0 ) + n = L_mac( n, int_sqr[k], 1152 /*0.03515625f Q15*/ ); } - sqErrorNrg = L_add(sqErrorNrg, accu1); - accu1 = L_deposit_l(0); /* segment ended here, so reset segment sum */ + sqErrorNrg = L_add( sqErrorNrg, accu1 ); + accu1 = L_deposit_l( 0 ); /* segment ended here, so reset segment sum */ k = 0; move16(); } - FOR (; maxK < nTransWidth; maxK++) + FOR( ; maxK < nTransWidth; maxK++ ) { - IF (sqQ[i+maxK] != 0) + IF( sqQ[i + maxK] != 0 ) { BREAK; } } - segmentOffset = add(i, 1); /* new segment might start at next line */ + segmentOffset = add( i, 1 ); /* new segment might start at next line */ } - ELSE /* current line is zero, so update pointers & segment sum */ + ELSE /* current line is zero, so update pointers & segment sum */ { - if (LT_16(k, nTransWidth)) + if ( LT_16( k, nTransWidth ) ) { - k = add(k, 1); + k = add( k, 1 ); } - tmp2 = sub(maxK, nTransWidth); - if (tmp2 < 0) + tmp2 = sub( maxK, nTransWidth ); + if ( tmp2 < 0 ) { - maxK = sub(maxK, 1); + maxK = sub( maxK, 1 ); } test(); - if ((tmp2 >= 0) && (sqQ[i+sub(nTransWidth, 1)] != 0)) + if ( ( tmp2 >= 0 ) && ( sqQ[i + sub( nTransWidth, 1 )] != 0 ) ) { - maxK = sub(nTransWidth, 1); + maxK = sub( nTransWidth, 1 ); } /* update segment sum: magnitudes scaled by smoothing function */ /*accu1 += (float)fabs(x_orig[i]) * inv_gain2 * (float)(k * maxK);*/ - tmp2 = mult(inv_gain2, shl(imult1616(k, maxK), 8)); - accu1 = L_add(accu1, L_abs(Mpy_32_16_1(x_orig[i], tmp2))); + tmp2 = mult( inv_gain2, shl( imult1616( k, maxK ), 8 ) ); + accu1 = L_add( accu1, L_abs( Mpy_32_16_1( x_orig[i], tmp2 ) ) ); } } - FOR (; i < lowpassLine; i++) + FOR( ; i < lowpassLine; i++ ) { - inv_gain2 = shl(mult(inv_gain2, tilt_factor), 1); + inv_gain2 = shl( mult( inv_gain2, tilt_factor ), 1 ); - IF (EQ_16(maxK, 1)) /* current line is not zero, so reset pointers */ + IF( EQ_16( maxK, 1 ) ) /* current line is not zero, so reset pointers */ { - k = sub(i, segmentOffset); + k = sub( i, segmentOffset ); - IF (k > 0) /* add segment sum to sum of segment magnitudes */ + IF( k > 0 ) /* add segment sum to sum of segment magnitudes */ { - IF (LE_16(nTransWidth, 3)) + IF( LE_16( nTransWidth, 3 ) ) { - tmp2 = sub(k, c1); - if (tmp2 > 0) n = L_msu(n, k, (Word16)0x8000); - if (tmp2 > 0) n = L_mac(n, nTransWidth_1, (Word16)0x8000); - if (tmp2 <= 0) n = L_mac(n, int_sqr[k], c2); + tmp2 = sub( k, c1 ); + if ( tmp2 > 0 ) + n = L_msu( n, k, (Word16) 0x8000 ); + if ( tmp2 > 0 ) + n = L_mac( n, nTransWidth_1, (Word16) 0x8000 ); + if ( tmp2 <= 0 ) + n = L_mac( n, int_sqr[k], c2 ); } ELSE { - tmp2 = sub(k, 12); - if (tmp2 > 0) n = L_msu(n, k, (Word16)0x8000); - if (tmp2 > 0) n = L_sub(n, 0x70000); - if (tmp2 <= 0) n = L_mac(n, int_sqr[k], 1152/*0.03515625f Q15*/); + tmp2 = sub( k, 12 ); + if ( tmp2 > 0 ) + n = L_msu( n, k, (Word16) 0x8000 ); + if ( tmp2 > 0 ) + n = L_sub( n, 0x70000 ); + if ( tmp2 <= 0 ) + n = L_mac( n, int_sqr[k], 1152 /*0.03515625f Q15*/ ); } - sqErrorNrg = L_add(sqErrorNrg, accu1); + sqErrorNrg = L_add( sqErrorNrg, accu1 ); } - segmentOffset = add(i, 1); /* no new segments since maxK remains 1 */ + segmentOffset = add( i, 1 ); /* no new segments since maxK remains 1 */ } - ELSE /* current line is zero, so update pointers & energy sum */ + ELSE /* current line is zero, so update pointers & energy sum */ { - if (LT_16(k, nTransWidth)) + if ( LT_16( k, nTransWidth ) ) { - k = add(k, 1); + k = add( k, 1 ); } - if (LT_16(maxK, nTransWidth)) + if ( LT_16( maxK, nTransWidth ) ) { - maxK = sub(maxK, 1); + maxK = sub( maxK, 1 ); } /* update segment sum: magnitudes scaled by smoothing function */ /*accu1 += (float)fabs(x_orig[i]) * inv_gain2 * (float)(k * maxK);*/ - tmp2 = mult(inv_gain2, shl(imult1616(k, maxK), 8)); - accu1 = L_add(accu1, L_abs(Mpy_32_16_1(x_orig[i], tmp2))); + tmp2 = mult( inv_gain2, shl( imult1616( k, maxK ), 8 ) ); + accu1 = L_add( accu1, L_abs( Mpy_32_16_1( x_orig[i], tmp2 ) ) ); } } - k = sub(i, segmentOffset); - IF (k > 0) /* add last segment sum to sum of segment magnitudes */ + k = sub( i, segmentOffset ); + IF( k > 0 ) /* add last segment sum to sum of segment magnitudes */ { - IF (LE_16(nTransWidth, 3)) + IF( LE_16( nTransWidth, 3 ) ) { - tmp2 = sub(k, c1); - if (tmp2 > 0) n = L_msu(n, k, (Word16)0x8000); - if (tmp2 > 0) n = L_mac(n, nTransWidth_1, (Word16)0x8000); - if (tmp2 <= 0) n = L_mac(n, int_sqr[k], c2); + tmp2 = sub( k, c1 ); + if ( tmp2 > 0 ) + n = L_msu( n, k, (Word16) 0x8000 ); + if ( tmp2 > 0 ) + n = L_mac( n, nTransWidth_1, (Word16) 0x8000 ); + if ( tmp2 <= 0 ) + n = L_mac( n, int_sqr[k], c2 ); } ELSE { - tmp2 = sub(k, 12); - if (tmp2 > 0) n = L_msu(n, k, (Word16)0x8000); - if (tmp2 > 0) n = L_sub(n, 0x70000); - if (tmp2 <= 0) n = L_mac(n, int_sqr[k], 1152/*0.03515625f Q15*/); + tmp2 = sub( k, 12 ); + if ( tmp2 > 0 ) + n = L_msu( n, k, (Word16) 0x8000 ); + if ( tmp2 > 0 ) + n = L_sub( n, 0x70000 ); + if ( tmp2 <= 0 ) + n = L_mac( n, int_sqr[k], 1152 /*0.03515625f Q15*/ ); } - sqErrorNrg = L_add(sqErrorNrg, accu1); + sqErrorNrg = L_add( sqErrorNrg, accu1 ); } /* noise level factor: average of segment magnitudes of noise bins */ - IF (n > 0) + IF( n > 0 ) { - tmp1 = BASOP_Util_Divide3232_Scale(Mpy_32_16_1(sqErrorNrg, att), n, &s); - s = add(add(add(s, x_orig_e), inv_gain2_e), 7 - 15); + tmp1 = BASOP_Util_Divide3232_Scale( Mpy_32_16_1( sqErrorNrg, att ), n, &s ); + s = add( add( add( s, x_orig_e ), inv_gain2_e ), 7 - 15 ); BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB - tmp1 = shl_o(tmp1, s, &Overflow); + tmp1 = shl_o( tmp1, s, &Overflow ); #else /* BASOP_NOGLOB */ - tmp1 = shl(tmp1, s); + tmp1 = shl( tmp1, s ); #endif BASOP_SATURATE_WARNING_ON_EVS; } @@ -1404,90 +1428,87 @@ void tcx_noise_factor_fx( } /* quantize, dequantize noise level factor (range 0.09375 - 0.65625) */ - tmp2 = round_fx(L_shr(L_mult(tmp1, 22016/*1.34375f Q14*/), 14-NBITS_NOISE_FILL_LEVEL)); + tmp2 = round_fx( L_shr( L_mult( tmp1, 22016 /*1.34375f Q14*/ ), 14 - NBITS_NOISE_FILL_LEVEL ) ); - if (GT_16(tmp2, (1<syn, buf, M+1); + synth = buf + M + 1; + Copy( LPDmem->syn, buf, M + 1 ); - Copy(xn_buf, synth, L_frame_glob); - Copy(synth + sub(L_frame_glob, M+1), LPDmem->syn, M+1); + Copy( xn_buf, synth, L_frame_glob ); + Copy( synth + sub( L_frame_glob, M + 1 ), LPDmem->syn, M + 1 ); - IF (st->tcxonly == 0) + IF( st->tcxonly == 0 ) { /* Update weighted synthesis */ - Residu3_fx(Ai+(st->nb_subfr-1)*(M+1), synth + sub(L_frame_glob, 1), &tmp, 1, Q_new+shift-1); - LPDmem->mem_w0 =sub(wsig[sub(L_frame_glob, 1)], tmp); + Residu3_fx( Ai + ( st->nb_subfr - 1 ) * ( M + 1 ), synth + sub( L_frame_glob, 1 ), &tmp, 1, Q_new + shift - 1 ); + LPDmem->mem_w0 = sub( wsig[sub( L_frame_glob, 1 )], tmp ); move16(); #ifdef BASOP_NOGLOB LPDmem->mem_w0 = shr_sat( LPDmem->mem_w0, shift ); /*Qnew-1*/ #else - LPDmem->mem_w0 =shr(LPDmem->mem_w0, shift); /*Qnew-1*/ + LPDmem->mem_w0 = shr( LPDmem->mem_w0, shift ); /*Qnew-1*/ #endif } /* Emphasis of synth -> synth_pe */ - tmp = synth[-(M+1)]; + tmp = synth[-( M + 1 )]; move16(); - E_UTIL_f_preemph2(Q_new-1, synth - M, preemph, add(M, L_frame_glob), &tmp); + E_UTIL_f_preemph2( Q_new - 1, synth - M, preemph, add( M, L_frame_glob ), &tmp ); - Copy(synth + sub(L_frame_glob, M), LPDmem->mem_syn, M); - Copy(synth + sub(L_frame_glob, M), LPDmem->mem_syn2, M); - Copy(synth + sub(L_frame_glob, L_SYN_MEM), LPDmem->mem_syn_r, L_SYN_MEM); + Copy( synth + sub( L_frame_glob, M ), LPDmem->mem_syn, M ); + Copy( synth + sub( L_frame_glob, M ), LPDmem->mem_syn2, M ); + Copy( synth + sub( L_frame_glob, L_SYN_MEM ), LPDmem->mem_syn_r, L_SYN_MEM ); test(); - IF (st->tcxonly == 0 || LE_16(L_frame_glob,L_FRAME16k)) + IF( st->tcxonly == 0 || LE_16( L_frame_glob, L_FRAME16k ) ) { /* Update excitation */ - IF (LT_16(L_frame_glob, L_EXC_MEM)) + IF( LT_16( L_frame_glob, L_EXC_MEM ) ) { - Copy( LPDmem->old_exc + L_frame_glob, LPDmem->old_exc, sub(L_EXC_MEM, L_frame_glob) ); - Residu3_fx(A, synth, LPDmem->old_exc + sub(L_EXC_MEM, L_frame_glob), L_frame_glob, 1); + Copy( LPDmem->old_exc + L_frame_glob, LPDmem->old_exc, sub( L_EXC_MEM, L_frame_glob ) ); + Residu3_fx( A, synth, LPDmem->old_exc + sub( L_EXC_MEM, L_frame_glob ), L_frame_glob, 1 ); } ELSE { - Residu3_fx(A, synth + sub(L_frame_glob, L_EXC_MEM), LPDmem->old_exc, L_EXC_MEM, 1); + Residu3_fx( A, synth + sub( L_frame_glob, L_EXC_MEM ), LPDmem->old_exc, L_EXC_MEM, 1 ); } - } - } @@ -1497,19 +1518,19 @@ void tcx_encoder_memory_update_fx( /* Returns: number of bits used (including "bits") Q0 */ Word16 tcx_ari_res_Q_spec_fx( - const Word32 x_orig[], /* i: original spectrum Q31-e */ - Word16 x_orig_e, /* i: original spectrum exponent Q0 */ - const Word16 signs[], /* i: signs (x_orig[.]<0) Q0 */ - Word32 x_Q[], /* i/o: quantized spectrum Q31-e */ - Word16 x_Q_e, /* i: quantized spectrum exponent Q0 */ - Word16 L_frame, /* i: number of lines Q0 */ - Word16 gain, /* i: TCX gain Q15-e */ - Word16 gain_e, /* i: TCX gain exponent Q0 */ - Word16 prm[], /* o: bit-stream Q0 */ - Word16 target_bits, /* i: number of bits available Q0 */ - Word16 bits, /* i: number of bits used so far Q0 */ - Word16 deadzone, /* i: quantizer deadzone Q15 */ - const Word16 x_fac[] /* i: spectrum post-quantization factors Q14 */ + const Word32 x_orig[], /* i: original spectrum Q31-e */ + Word16 x_orig_e, /* i: original spectrum exponent Q0 */ + const Word16 signs[], /* i: signs (x_orig[.]<0) Q0 */ + Word32 x_Q[], /* i/o: quantized spectrum Q31-e */ + Word16 x_Q_e, /* i: quantized spectrum exponent Q0 */ + Word16 L_frame, /* i: number of lines Q0 */ + Word16 gain, /* i: TCX gain Q15-e */ + Word16 gain_e, /* i: TCX gain exponent Q0 */ + Word16 prm[], /* o: bit-stream Q0 */ + Word16 target_bits, /* i: number of bits available Q0 */ + Word16 bits, /* i: number of bits used so far Q0 */ + Word16 deadzone, /* i: quantizer deadzone Q15 */ + const Word16 x_fac[] /* i: spectrum post-quantization factors Q14 */ ) { Word16 i, j, num_zeros; @@ -1521,7 +1542,7 @@ Word16 tcx_ari_res_Q_spec_fx( /* Limit the number of residual bits */ - target_bits = s_min(target_bits, NPRM_RESQ); + target_bits = s_min( target_bits, NPRM_RESQ ); /* Requantize the spectrum line-by-line */ @@ -1530,66 +1551,67 @@ Word16 tcx_ari_res_Q_spec_fx( num_zeros = 0; move16(); - s = sub(add(gain_e, x_Q_e), x_orig_e); - FOR (i=0; i < L_frame; i++) + s = sub( add( gain_e, x_Q_e ), x_orig_e ); + FOR( i = 0; i < L_frame; i++ ) { - IF (GE_16(bits, target_bits)) /* no bits left */ + IF( GE_16( bits, target_bits ) ) /* no bits left */ { BREAK; } - IF (x_Q[i] != 0) + IF( x_Q[i] != 0 ) { sign = x_fac[i]; move16(); - if (signs[i] != 0) sign = negate(sign); + if ( signs[i] != 0 ) + sign = negate( sign ); /* x_Q_m = x_Q[i] - sign*fac_m; x_Q_p = x_Q[i] + sign*fac_p; */ - L_tmp = L_mult(sign, deadzone); /* sign*deadzone/2 in Q31 */ - x_Q_m = L_sub(x_Q[i], L_shr(L_tmp, x_Q_e)); + L_tmp = L_mult( sign, deadzone ); /* sign*deadzone/2 in Q31 */ + x_Q_m = L_sub( x_Q[i], L_shr( L_tmp, x_Q_e ) ); - L_tmp = L_mac(L_tmp, sign, (Word16)0x8000); /* sign*(deadzone-1)/2 in Q31 */ - x_Q_p = L_sub(x_Q[i], L_shr(L_tmp, x_Q_e)); + L_tmp = L_mac( L_tmp, sign, (Word16) 0x8000 ); /* sign*(deadzone-1)/2 in Q31 */ + x_Q_p = L_sub( x_Q[i], L_shr( L_tmp, x_Q_e ) ); /* if (fabs(x_orig[i] - gain * x_Q_m) < fabs(x_orig[i] - gain * x_Q_p)) */ - L_tmp = L_abs(L_sub(x_orig[i], L_shl(Mpy_32_16_1(x_Q_m, gain), s))); - L_tmp2 = L_abs(L_sub(x_orig[i], L_shl(Mpy_32_16_1(x_Q_p, gain), s))); + L_tmp = L_abs( L_sub( x_orig[i], L_shl( Mpy_32_16_1( x_Q_m, gain ), s ) ) ); + L_tmp2 = L_abs( L_sub( x_orig[i], L_shl( Mpy_32_16_1( x_Q_p, gain ), s ) ) ); - IF (LT_32(L_tmp, L_tmp2)) /* Decrease magnitude */ + IF( LT_32( L_tmp, L_tmp2 ) ) /* Decrease magnitude */ { x_Q[i] = x_Q_m; move32(); prm[bits] = 0; move16(); } - ELSE /* Increase magnitude */ + ELSE /* Increase magnitude */ { x_Q[i] = x_Q_p; move32(); prm[bits] = 1; move16(); } - bits = add(bits, 1); + bits = add( bits, 1 ); } ELSE { zeros[num_zeros] = i; move16(); - num_zeros = add(num_zeros, 1); + num_zeros = add( num_zeros, 1 ); } } /* Requantize zeroed-lines of the spectrum */ - fac_p = msu_r(1417339264l/*2*0.33f Q31*/, deadzone, 21627/*2*0.33f Q15*/); /* Q16 */ - target_bits = sub(target_bits, 1); /* reserve 1 bit for the check below */ + fac_p = msu_r( 1417339264l /*2*0.33f Q31*/, deadzone, 21627 /*2*0.33f Q15*/ ); /* Q16 */ + target_bits = sub( target_bits, 1 ); /* reserve 1 bit for the check below */ - s = sub(gain_e, x_orig_e); - s2 = sub(x_Q_e, 1); - FOR (j = 0; j < num_zeros; j++) + s = sub( gain_e, x_orig_e ); + s2 = sub( x_Q_e, 1 ); + FOR( j = 0; j < num_zeros; j++ ) { - IF (GE_16(bits, target_bits)) /* 1 or 0 bits left */ + IF( GE_16( bits, target_bits ) ) /* 1 or 0 bits left */ { BREAK; } @@ -1597,20 +1619,21 @@ Word16 tcx_ari_res_Q_spec_fx( i = zeros[j]; move16(); - thres = L_mult(fac_p, x_fac[i]); /* Q31 */ + thres = L_mult( fac_p, x_fac[i] ); /* Q31 */ - IF (GT_32(L_abs(x_orig[i]), L_shl(Mpy_32_16_1(thres, gain), s))) + IF( GT_32( L_abs( x_orig[i] ), L_shl( Mpy_32_16_1( thres, gain ), s ) ) ) { prm[bits] = 1; move16(); - bits = add(bits, 1); + bits = add( bits, 1 ); - prm[bits] = sub(1, signs[i]); + prm[bits] = sub( 1, signs[i] ); move16(); - bits = add(bits, 1); + bits = add( bits, 1 ); - L_tmp = L_shr(thres, s2); - if (signs[i]) L_tmp = L_negate(L_tmp); + L_tmp = L_shr( thres, s2 ); + if ( signs[i] ) + L_tmp = L_negate( L_tmp ); x_Q[i] = L_tmp; move32(); } @@ -1618,7 +1641,7 @@ Word16 tcx_ari_res_Q_spec_fx( { prm[bits] = 0; move16(); - bits = add(bits, 1); + bits = add( bits, 1 ); } } @@ -1635,8 +1658,7 @@ Word16 tcx_res_Q_gain_fx( Word16 *gain_tcx, Word16 *gain_tcx_e, Word16 *prm, - Word16 sqTargetBits -) + Word16 sqTargetBits ) { Word16 bits; Word16 gain_reQ, gain_reQ_e; @@ -1649,34 +1671,34 @@ Word16 tcx_res_Q_gain_fx( move16(); /* make sure we have a bit of headroom */ - IF (GT_16(gain_reQ, 0x7000)) + IF( GT_16( gain_reQ, 0x7000 ) ) { - gain_reQ = shr(gain_reQ, 1); - gain_reQ_e = add(gain_reQ_e, 1); + gain_reQ = shr( gain_reQ, 1 ); + gain_reQ_e = add( gain_reQ_e, 1 ); } /* bring sqGain to same exponent */ #ifdef BASOP_NOGLOB sqGain = shr_sat( sqGain, sub( gain_reQ_e, sqGain_e ) ); #else - sqGain = shr(sqGain, sub(gain_reQ_e, sqGain_e)); + sqGain = shr( sqGain, sub( gain_reQ_e, sqGain_e ) ); #endif - FOR (bits=0; bits < TCX_RES_Q_BITS_GAIN; bits++) + FOR( bits = 0; bits < TCX_RES_Q_BITS_GAIN; bits++ ) { - IF (LT_16(sqGain, gain_reQ)) + IF( LT_16( sqGain, gain_reQ ) ) { prm[bits] = 0; move16(); - gain_reQ = mult_r(gain_reQ, gain_corr_inv_fac[bits]); + gain_reQ = mult_r( gain_reQ, gain_corr_inv_fac[bits] ); } ELSE { prm[bits] = 1; move16(); - gain_reQ = shl(mult_r(gain_reQ, gain_corr_fac[bits]), 1); + gain_reQ = shl( mult_r( gain_reQ, gain_corr_fac[bits] ), 1 ); } - IF (LT_16(bits, sqTargetBits)) + IF( LT_16( bits, sqTargetBits ) ) { *gain_tcx = gain_reQ; move16(); @@ -1713,29 +1735,29 @@ Word16 tcx_res_Q_spec_fx( /* Limit the number of residual bits */ - sqTargetBits = s_min(sqTargetBits, NPRM_RESQ); + sqTargetBits = s_min( sqTargetBits, NPRM_RESQ ); /* Requantize the spectrum line-by-line */ - fac_m = shr(sq_round, 1); - fac_p = sub(0x4000, fac_m); + fac_m = shr( sq_round, 1 ); + fac_p = sub( 0x4000, fac_m ); /* exponent difference of x_orig and x_Q * sqGain */ - s = sub(x_orig_e, add(x_Q_e, sqGain_e)); + s = sub( x_orig_e, add( x_Q_e, sqGain_e ) ); lf_deemph_factor = 0x4000; move16(); - s2 = sub(x_Q_e, 1); + s2 = sub( x_Q_e, 1 ); - FOR (i = 0; i < L_frame; i++) + FOR( i = 0; i < L_frame; i++ ) { - IF (GE_16(bits, sub(sqTargetBits, kMaxEstimatorUndershoot))) + IF( GE_16( bits, sub( sqTargetBits, kMaxEstimatorUndershoot ) ) ) { fac_m = 0; move16(); fac_p = 0; move16(); - IF (GE_16(bits, s_min(NPRM_RESQ, add(sqTargetBits, kMaxEstimatorOvershoot)))) + IF( GE_16( bits, s_min( NPRM_RESQ, add( sqTargetBits, kMaxEstimatorOvershoot ) ) ) ) { BREAK; } @@ -1743,104 +1765,110 @@ Word16 tcx_res_Q_spec_fx( test(); test(); - IF ((x_Q[i] != 0) && ((lf_deemph_factors == NULL) || (GT_16(lf_deemph_factors[i], 0x2000)))) + IF( ( x_Q[i] != 0 ) && ( ( lf_deemph_factors == NULL ) || ( GT_16( lf_deemph_factors[i], 0x2000 ) ) ) ) { - tmp1 = L_add(x_orig[i], 0); - tmp2 = Mpy_32_16_1(x_Q[i], sqGain); - if (s > 0) tmp2 = L_shr(tmp2, s); - if (s < 0) tmp1 = L_shl(tmp1, s); - - if (lf_deemph_factors != NULL) + tmp1 = L_add( x_orig[i], 0 ); + tmp2 = Mpy_32_16_1( x_Q[i], sqGain ); + if ( s > 0 ) + tmp2 = L_shr( tmp2, s ); + if ( s < 0 ) + tmp1 = L_shl( tmp1, s ); + + if ( lf_deemph_factors != NULL ) { lf_deemph_factor = lf_deemph_factors[i]; move16(); } - IF (LT_32(tmp1, tmp2)) + IF( LT_32( tmp1, tmp2 ) ) { prm[bits] = 0; move16(); - bits = add(bits, 1); + bits = add( bits, 1 ); - if (x_Q[i] > 0) tmp1 = L_mult(fac_m, lf_deemph_factor); - if (x_Q[i] < 0) tmp1 = L_mult(fac_p, lf_deemph_factor); - x_Q[i] = L_sub(x_Q[i], L_shr(tmp1, s2)); + if ( x_Q[i] > 0 ) + tmp1 = L_mult( fac_m, lf_deemph_factor ); + if ( x_Q[i] < 0 ) + tmp1 = L_mult( fac_p, lf_deemph_factor ); + x_Q[i] = L_sub( x_Q[i], L_shr( tmp1, s2 ) ); move32(); } ELSE { prm[bits] = 1; move16(); - bits = add(bits, 1); + bits = add( bits, 1 ); - if (x_Q[i] > 0) tmp1 = L_mult(fac_p, lf_deemph_factor); - if (x_Q[i] < 0) tmp1 = L_mult(fac_m, lf_deemph_factor); - x_Q[i] = L_add(x_Q[i], L_shr(tmp1, s2)); + if ( x_Q[i] > 0 ) + tmp1 = L_mult( fac_p, lf_deemph_factor ); + if ( x_Q[i] < 0 ) + tmp1 = L_mult( fac_m, lf_deemph_factor ); + x_Q[i] = L_add( x_Q[i], L_shr( tmp1, s2 ) ); move32(); } } } /*Quantize zeroed-line of the spectrum*/ - c = sub(21627/*0.66f Q15*/, mult_r(sq_round, 21627/*0.66f Q15*/)); + c = sub( 21627 /*0.66f Q15*/, mult_r( sq_round, 21627 /*0.66f Q15*/ ) ); - FOR (i = 0; i < L_frame; i++) + FOR( i = 0; i < L_frame; i++ ) { - IF (GE_16(bits, sub(sqTargetBits, 2))) + IF( GE_16( bits, sub( sqTargetBits, 2 ) ) ) { BREAK; } test(); test(); - IF ((x_Q[i] == 0) && ((lf_deemph_factors == NULL) || (GT_16(lf_deemph_factors[i], 0x2000)))) + IF( ( x_Q[i] == 0 ) && ( ( lf_deemph_factors == NULL ) || ( GT_16( lf_deemph_factors[i], 0x2000 ) ) ) ) { - if (lf_deemph_factors != NULL) + if ( lf_deemph_factors != NULL ) { lf_deemph_factor = lf_deemph_factors[i]; move16(); } - thres = L_mult(c, lf_deemph_factor); - tmp1 = L_shl(Mpy_32_16_1(thres, sqGain), sub(sqGain_e, x_orig_e)); + thres = L_mult( c, lf_deemph_factor ); + tmp1 = L_shl( Mpy_32_16_1( thres, sqGain ), sub( sqGain_e, x_orig_e ) ); - IF (GT_32(x_orig[i], tmp1)) + IF( GT_32( x_orig[i], tmp1 ) ) { prm[bits] = 1; move16(); - bits = add(bits, 1); + bits = add( bits, 1 ); prm[bits] = 1; move16(); - bits = add(bits, 1); + bits = add( bits, 1 ); - x_Q[i] = L_shl(thres, sub(1, x_Q_e)); + x_Q[i] = L_shl( thres, sub( 1, x_Q_e ) ); move32(); } - ELSE IF (L_add(x_orig[i], tmp1) < 0) + ELSE IF( L_add( x_orig[i], tmp1 ) < 0 ) { prm[bits] = 1; move16(); - bits = add(bits, 1); + bits = add( bits, 1 ); prm[bits] = 0; move16(); - bits = add(bits, 1); + bits = add( bits, 1 ); - x_Q[i] = L_shl(L_negate(thres), sub(1, x_Q_e)); + x_Q[i] = L_shl( L_negate( thres ), sub( 1, x_Q_e ) ); move32(); } ELSE { prm[bits] = 0; move16(); - bits = add(bits, 1); + bits = add( bits, 1 ); } } } /*Be sure that every possible bits are initialized*/ - FOR (i = bits; i < NPRM_RESQ; i++) + FOR( i = bits; i < NPRM_RESQ; i++ ) { prm[i] = 0; move16(); @@ -1850,16 +1878,16 @@ Word16 tcx_res_Q_spec_fx( return bits; } void ProcessIGF_fx( - IGF_ENC_INSTANCE_HANDLE const hInstance, /**< in: instance handle of IGF Encoder */ - Encoder_State *st, /**< in: Encoder state */ - Word32 pMDCTSpectrum[], /**< in: MDCT spectrum */ - Word16 *pMDCTSpectrum_e, - Word32 pPowerSpectrum[], /**< in: MDCT^2 + MDST^2 spectrum, or estimate */ - Word16 *pPowerSpectrum_e, - Word16 isTCX20, /**< in: flag indicating if the input is TCX20 or TCX10/2xTCX5 */ - Word16 isTNSActive, /**< in: flag indicating if the TNS is active */ - Word16 isTransition, /**< in: flag indicating if the input is the transition from from ACELP to TCX20/TCX10 */ - Word16 frameno /**< in: flag indicating index of current subframe */ + IGF_ENC_INSTANCE_HANDLE const hInstance, /**< in: instance handle of IGF Encoder */ + Encoder_State *st, /**< in: Encoder state */ + Word32 pMDCTSpectrum[], /**< in: MDCT spectrum */ + Word16 *pMDCTSpectrum_e, + Word32 pPowerSpectrum[], /**< in: MDCT^2 + MDST^2 spectrum, or estimate */ + Word16 *pPowerSpectrum_e, + Word16 isTCX20, /**< in: flag indicating if the input is TCX20 or TCX10/2xTCX5 */ + Word16 isTNSActive, /**< in: flag indicating if the TNS is active */ + Word16 isTransition, /**< in: flag indicating if the input is the transition from from ACELP to TCX20/TCX10 */ + Word16 frameno /**< in: flag indicating index of current subframe */ ) { Word16 igfGridIdx; @@ -1872,14 +1900,14 @@ void ProcessIGF_fx( isIndepFlag = 1; move16(); test(); - IF (isTransition && isTCX20) + IF( isTransition && isTCX20 ) { igfGridIdx = IGF_GRID_LB_TRAN; move16(); } ELSE { - IF (isTCX20) + IF( isTCX20 ) { igfGridIdx = IGF_GRID_LB_NORM; move16(); @@ -1889,7 +1917,7 @@ void ProcessIGF_fx( /* It is short block */ igfGridIdx = IGF_GRID_LB_SHORT; move16(); - if (EQ_16(frameno, 1)) + if ( EQ_16( frameno, 1 ) ) { isIndepFlag = 0; move16(); @@ -1898,91 +1926,89 @@ void ProcessIGF_fx( } - IGFEncApplyMono_fx(hInstance, /**< in: instance handle of IGF Encoder */ - igfGridIdx, /**< in: IGF grid index */ - st, /**< in: Encoder state */ - pMDCTSpectrum, /**< in: MDCT spectrum */ - *pMDCTSpectrum_e, - pPowerSpectrum, /**< in: MDCT^2 + MDST^2 spectrum, or estimate */ - *pPowerSpectrum_e, - isTCX20, /**< in: flag indicating if the input is TCX20 or TCX10/2xTCX5 */ - isTNSActive, /**< in: flag indicating if the TNS is active */ - (st->last_core == ACELP_CORE) - ); + IGFEncApplyMono_fx( hInstance, /**< in: instance handle of IGF Encoder */ + igfGridIdx, /**< in: IGF grid index */ + st, /**< in: Encoder state */ + pMDCTSpectrum, /**< in: MDCT spectrum */ + *pMDCTSpectrum_e, + pPowerSpectrum, /**< in: MDCT^2 + MDST^2 spectrum, or estimate */ + *pPowerSpectrum_e, + isTCX20, /**< in: flag indicating if the input is TCX20 or TCX10/2xTCX5 */ + isTNSActive, /**< in: flag indicating if the TNS is active */ + ( st->last_core == ACELP_CORE ) ); + { + const Word32 tns_predictionGain = st->hIGFEnc->tns_predictionGain; + const Word16 startLine = st->hIGFEnc->infoStartLine; + const Word16 endLine = st->hIGFEnc->infoStopLine; + const Word16 maxOrder = 8; + const Word32 *spec_before = st->hIGFEnc->spec_be_igf; + Word16 curr_order = 0; + Word16 A[ITF_MAX_FILTER_ORDER + 1]; + Word16 Q_A; + Word16 predictionGain = 0; + Word16 *flatteningTrigger = &( st->hIGFEnc->flatteningTrigger ); + + ITF_Detect_fx( spec_before, startLine, endLine, maxOrder, A, &Q_A, &predictionGain, &curr_order, shl( st->hIGFEnc->spec_be_igf_e, 1 ) ); + *flatteningTrigger = 0; + test(); + IF( LT_32( tns_predictionGain, 9646899l /*1.15 Q23*/ ) && + LT_16( predictionGain, 147 /*1.15 Q7*/ ) ) { - const Word32 tns_predictionGain = st->hIGFEnc->tns_predictionGain; - const Word16 startLine = st->hIGFEnc->infoStartLine; - const Word16 endLine = st->hIGFEnc->infoStopLine; - const Word16 maxOrder = 8; - const Word32 *spec_before = st->hIGFEnc->spec_be_igf; - Word16 curr_order = 0; - Word16 A[ITF_MAX_FILTER_ORDER+1]; - Word16 Q_A; - Word16 predictionGain = 0; - Word16 *flatteningTrigger = &(st->hIGFEnc->flatteningTrigger); - - ITF_Detect_fx( spec_before, startLine, endLine, maxOrder, A, &Q_A, &predictionGain, &curr_order, shl(st->hIGFEnc->spec_be_igf_e, 1) ); - *flatteningTrigger = 0; - test(); - IF (LT_32(tns_predictionGain, 9646899l/*1.15 Q23*/)&& - LT_16(predictionGain, 147/*1.15 Q7*/)) - { - *flatteningTrigger = 1; - } + *flatteningTrigger = 1; } + } -//IVAS_CODE_BITSTREAM - bsStart = hBstr->next_ind_fx; + // IVAS_CODE_BITSTREAM + bsStart = hBstr->next_ind_fx; move16(); hInstance->infoTotalBitsPerFrameWritten = 0; move16(); - IF (isTCX20) + IF( isTCX20 ) { - IGFEncWriteBitstream_fx(hInstance, NULL, &hInstance->infoTotalBitsPerFrameWritten, igfGridIdx, isIndepFlag); + IGFEncWriteBitstream_fx( hInstance, NULL, &hInstance->infoTotalBitsPerFrameWritten, igfGridIdx, isIndepFlag ); } ELSE { - IGFEncWriteBitstream_fx(hInstance, st->hBstr, &hInstance->infoTotalBitsPerFrameWritten, igfGridIdx, isIndepFlag); + IGFEncWriteBitstream_fx( hInstance, st->hBstr, &hInstance->infoTotalBitsPerFrameWritten, igfGridIdx, isIndepFlag ); } #ifndef IVAS_CODE_BITSTREAM - bsBits = sub(hBstr->next_ind_fx, bsStart); - IF (!isTCX20) + bsBits = sub( hBstr->next_ind_fx, bsStart ); + IF( !isTCX20 ) { - IGFEncConcatenateBitstream_fx(hInstance, bsBits, &hBstr->next_ind_fx, &hBstr->nb_bits_tot_fx, hBstr->ind_list_fx); + IGFEncConcatenateBitstream_fx( hInstance, bsBits, &hBstr->next_ind_fx, &hBstr->nb_bits_tot_fx, hBstr->ind_list_fx ); } #else -PMT("New bit stream implementation to be checked") - bsBits = sub(hBstr->next_ind_fx, bsStart); - IF(!isTCX20) + PMT( "New bit stream implementation to be checked" ) + bsBits = sub( hBstr->next_ind_fx, bsStart ); + IF( !isTCX20 ) { - IGFEncConcatenateBitstream_fx(hInstance, bsBits, &hBstr->next_ind_fx, &hBstr->nb_bits_tot_fx, hBstr->ind_list_fx); + IGFEncConcatenateBitstream_fx( hInstance, bsBits, &hBstr->next_ind_fx, &hBstr->nb_bits_tot_fx, hBstr->ind_list_fx ); } #endif - } -void attenuateNbSpectrum_fx(Word16 L_frame, Word32 *spectrum) +void attenuateNbSpectrum_fx( Word16 L_frame, Word32 *spectrum ) { Word16 i, length, att; - length = idiv1616U(L_frame, 20); + length = idiv1616U( L_frame, 20 ); - att = 21627/*0.66f Q15*/; + att = 21627 /*0.66f Q15*/; move16(); - if (EQ_16(length, 8)) + if ( EQ_16( length, 8 ) ) { - att = 19661/*0.6f Q15*/; + att = 19661 /*0.6f Q15*/; move16(); } - spectrum += sub(L_frame, length); - FOR (i=0; i < length; i++) + spectrum += sub( L_frame, length ); + FOR( i = 0; i < length; i++ ) { - spectrum[i] = Mpy_32_16_1(spectrum[i], att); + spectrum[i] = Mpy_32_16_1( spectrum[i], att ); move32(); - att = mult_r(att, att); + att = mult_r( att, att ); } } diff --git a/lib_enc/tfa_enc_fx.c b/lib_enc/tfa_enc_fx.c index d7ef4fc67..aa633912c 100644 --- a/lib_enc/tfa_enc_fx.c +++ b/lib_enc/tfa_enc_fx.c @@ -7,9 +7,9 @@ #include "basop_util.h" #include "cnst.h" //#include "prot_fx.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* * tfaCalcEnv() @@ -18,37 +18,35 @@ *-------------------------------------------------------------------*/ void tfaCalcEnv_fx( - const Word16* shb_speech, - Word32* enr -) + const Word16 *shb_speech, + Word32 *enr ) { Word16 i, j, k; k = 0; move16(); - FOR (i=0; ipTnsParameters + iFilter; /* TNS decision function */ - if ( ( pFilter->predictionGain_flt > pTnsParameters->minPredictionGain_flt) || ( pFilter->avgSqrCoef_flt > pTnsParameters->minAvgSqrCoef_flt) ) + if ( ( pFilter->predictionGain_flt > pTnsParameters->minPredictionGain_flt ) || ( pFilter->avgSqrCoef_flt > pTnsParameters->minAvgSqrCoef_flt ) ) { if ( pTnsData->nFilters > 0 || isTCX10 || ltp_gain < 0.6f || hTranDet == NULL ) { @@ -458,7 +458,7 @@ static void TnsDecision( else { maxEnergyChange = GetTCXMaxenergyChange( hTranDet, isTCX10, NSUBBLOCKS, 3 ); - if ( maxEnergyChange >= pTnsParameters->minEnergyChange_flt) + if ( maxEnergyChange >= pTnsParameters->minEnergyChange_flt ) { ++pTnsData->nFilters; } diff --git a/lib_enc/tns_base_enc_fx.c b/lib_enc/tns_base_enc_fx.c index 37ae6e8dd..4cb7cefdd 100644 --- a/lib_enc/tns_base_enc_fx.c +++ b/lib_enc/tns_base_enc_fx.c @@ -3,7 +3,6 @@ ====================================================================================*/ - #include "cnst.h" #include "stl.h" //#include "prot_fx.h" @@ -14,36 +13,36 @@ #include "rom_com_fx.h" #include "rom_com.h" #include "prot.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ -#define HLM_MIN_NRG (32768.0f * 2*NORM_MDCT_FACTOR / (640*640)) +#define HLM_MIN_NRG ( 32768.0f * 2 * NORM_MDCT_FACTOR / ( 640 * 640 ) ) /** Get TNS filter parameters from autocorrelation. - * - * @param rxx Autocorrelation function/coefficients. - * @param maxOrder Maximum filter order/number of coefficients. - * @param pTnsFilter Pointer to the output filter. - */ -static void GetFilterParameters(Word32 rxx[], Word16 maxOrder, STnsFilter * pTnsFilter); + * + * @param rxx Autocorrelation function/coefficients. + * @param maxOrder Maximum filter order/number of coefficients. + * @param pTnsFilter Pointer to the output filter. + */ +static void GetFilterParameters( Word32 rxx[], Word16 maxOrder, STnsFilter *pTnsFilter ); /** Quantization for reflection coefficients. - * - * @param parCoeff input reflection coefficients. - * @param index output quantized values. - * @param order number of coefficients/values. - */ -static void Parcor2Index(Word16 const parCoeff[], Word16 index[], Word16 order); + * + * @param parCoeff input reflection coefficients. + * @param index output quantized values. + * @param order number of coefficients/values. + */ +static void Parcor2Index( Word16 const parCoeff[], Word16 index[], Word16 order ); /** Linear prediction analysis/synthesis filter definition. - * @param order filter order. - * @param parCoeff filter (PARCOR) coefficients. - * @param state state of the filter. Must be at least of 'order' size. - * @param x the current input value. - * @return the output of the filter. - */ -typedef Word32 (* TLinearPredictionFilter)(Word16 order, Word16 const parCoeff[], Word32 * state, Word32 x); + * @param order filter order. + * @param parCoeff filter (PARCOR) coefficients. + * @param state state of the filter. Must be at least of 'order' size. + * @param x the current input value. + * @return the output of the filter. + */ +typedef Word32 ( *TLinearPredictionFilter )( Word16 order, Word16 const parCoeff[], Word32 *state, Word32 x ); /********************************/ @@ -52,44 +51,44 @@ typedef Word32 (* TLinearPredictionFilter)(Word16 order, Word16 const parCoeff[] #define MAX_SUBDIVISIONS 3 -Word16 DetectTnsFilt_fx(STnsConfig const * pTnsConfig, - Word32 const pSpectrum[], - STnsData * pTnsData, - Word16 *predictionGain) +Word16 DetectTnsFilt_fx( STnsConfig const *pTnsConfig, + Word32 const pSpectrum[], + STnsData *pTnsData, + Word16 *predictionGain ) { Word16 facs[TNS_MAX_NUM_OF_FILTERS][MAX_SUBDIVISIONS]; Word16 facs_e[TNS_MAX_NUM_OF_FILTERS][MAX_SUBDIVISIONS]; /* exponents of facs[][] */ Word16 shifts[TNS_MAX_NUM_OF_FILTERS][MAX_SUBDIVISIONS]; Word16 iFilter = 0; - ResetTnsData(pTnsData); + ResetTnsData( pTnsData ); - IF (pTnsConfig->maxOrder <= 0) + IF( pTnsConfig->maxOrder <= 0 ) { return 0; } /* Calculate norms for each spectrum part */ - FOR (iFilter = 0; iFilter < pTnsConfig->nMaxFilters; iFilter++) + FOR( iFilter = 0; iFilter < pTnsConfig->nMaxFilters; iFilter++ ) { Word16 idx0; Word16 idx1; Word16 nSubdivisions; Word16 iSubdivisions; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; + Flag Overflow = 0; #endif move16(); move16(); move16(); - idx0 = pTnsConfig->iFilterBorders[iFilter+1]; + idx0 = pTnsConfig->iFilterBorders[iFilter + 1]; idx1 = pTnsConfig->iFilterBorders[iFilter]; nSubdivisions = pTnsConfig->pTnsParameters[iFilter].nSubdivisions; - assert(pTnsConfig->pTnsParameters[iFilter].nSubdivisions <= MAX_SUBDIVISIONS); + assert( pTnsConfig->pTnsParameters[iFilter].nSubdivisions <= MAX_SUBDIVISIONS ); - FOR (iSubdivisions = 0; iSubdivisions < nSubdivisions; iSubdivisions++) + FOR( iSubdivisions = 0; iSubdivisions < nSubdivisions; iSubdivisions++ ) { Word16 iStartLine; Word16 iEndLine; @@ -98,37 +97,39 @@ Word16 DetectTnsFilt_fx(STnsConfig const * pTnsConfig, /* iStartLine = idx0 + (idx1-idx0)*iSubdivisions/nSubdivisions; iEndLine = idx0 + (idx1-idx0)*(iSubdivisions+1)/nSubdivisions; */ - assert((nSubdivisions == 1) || (nSubdivisions == 3)); + assert( ( nSubdivisions == 1 ) || ( nSubdivisions == 3 ) ); - tmp = sub(idx1, idx0); - iStartLine = imult1616(tmp, iSubdivisions); - iEndLine = add(iStartLine, tmp); + tmp = sub( idx1, idx0 ); + iStartLine = imult1616( tmp, iSubdivisions ); + iEndLine = add( iStartLine, tmp ); - if (EQ_16(nSubdivisions, 3))iStartLine=mult(iStartLine,0x2AAB); - iStartLine = add(iStartLine, idx0); + if ( EQ_16( nSubdivisions, 3 ) ) + iStartLine = mult( iStartLine, 0x2AAB ); + iStartLine = add( iStartLine, idx0 ); - if (EQ_16(nSubdivisions, 3))iEndLine=mult(iEndLine,0x2AAB); - iEndLine = add(iEndLine, idx0); + if ( EQ_16( nSubdivisions, 3 ) ) + iEndLine = mult( iEndLine, 0x2AAB ); + iEndLine = add( iEndLine, idx0 ); /*norms[iFilter][iSubdivisions] = norm2FLOAT(pSpectrum+iStartLine, iEndLine-iStartLine);*/ - headroom = getScaleFactor32(&pSpectrum[iStartLine], sub(iEndLine, iStartLine)); + headroom = getScaleFactor32( &pSpectrum[iStartLine], sub( iEndLine, iStartLine ) ); /* Calculate norm of spectrum band */ - L_tmp = Norm32Norm(pSpectrum+iStartLine, headroom, sub(iEndLine, iStartLine), &shift); + L_tmp = Norm32Norm( pSpectrum + iStartLine, headroom, sub( iEndLine, iStartLine ), &shift ); /* Check threshold HLM_MIN_NRG */ BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB - tmp32 = L_sub(L_shl_o(L_tmp, s_min(31, sub(shift, 24-31*2)), &Overflow), 3277l/*HLM_MIN_NRG Q7*/); + tmp32 = L_sub( L_shl_o( L_tmp, s_min( 31, sub( shift, 24 - 31 * 2 ) ), &Overflow ), 3277l /*HLM_MIN_NRG Q7*/ ); #else /* BASOP_NOGLOB */ - tmp32 = L_sub(L_shl(L_tmp, s_min(31, sub(shift, 24-31*2))), 3277l/*HLM_MIN_NRG Q7*/); + tmp32 = L_sub( L_shl( L_tmp, s_min( 31, sub( shift, 24 - 31 * 2 ) ) ), 3277l /*HLM_MIN_NRG Q7*/ ); #endif BASOP_SATURATE_WARNING_ON_EVS; /* get pre-shift for autocorrelation */ - tmp = sub(shift, norm_l(L_tmp)); /* exponent for normalized L_tmp */ - tmp = shr(sub(1, tmp), 1); /* pre-shift to apply before autocorrelation */ - shifts[iFilter][iSubdivisions] = s_min(tmp, headroom); + tmp = sub( shift, norm_l( L_tmp ) ); /* exponent for normalized L_tmp */ + tmp = shr( sub( 1, tmp ), 1 ); /* pre-shift to apply before autocorrelation */ + shifts[iFilter][iSubdivisions] = s_min( tmp, headroom ); move16(); /* calc normalization factor */ @@ -137,70 +138,68 @@ Word16 DetectTnsFilt_fx(STnsConfig const * pTnsConfig, facs_e[iFilter][iSubdivisions] = 0; move16(); - if (tmp32 > 0) + if ( tmp32 > 0 ) { facs[iFilter][iSubdivisions] = 0x7FFF; move16(); /* normalization not needed for one subdivision */ } test(); - IF ((tmp32 > 0) && (GT_16(nSubdivisions, 1))) + IF( ( tmp32 > 0 ) && ( GT_16( nSubdivisions, 1 ) ) ) { move16(); - facs_e[iFilter][iSubdivisions] = shl(sub(tmp, shifts[iFilter][iSubdivisions]), 1); + facs_e[iFilter][iSubdivisions] = shl( sub( tmp, shifts[iFilter][iSubdivisions] ), 1 ); - tmp = sub(1, shl(tmp, 1)); /* exponent of autocorrelation */ + tmp = sub( 1, shl( tmp, 1 ) ); /* exponent of autocorrelation */ #ifdef BASOP_NOGLOB L_tmp = L_shl_sat( L_tmp, sub( shift, tmp ) ); /* shift L_tmp to that exponent */ /* calc factor (with 2 bits headroom for sum of 3 subdivisions) */ move16(); - facs[iFilter][iSubdivisions] = div_s(0x2000, round_fx_sat(L_tmp)); /* L_tmp is >= 0x2000000 */ + facs[iFilter][iSubdivisions] = div_s( 0x2000, round_fx_sat( L_tmp ) ); /* L_tmp is >= 0x2000000 */ #else - L_tmp = L_shl(L_tmp, sub(shift, tmp)); /* shift L_tmp to that exponent */ + L_tmp = L_shl( L_tmp, sub( shift, tmp ) ); /* shift L_tmp to that exponent */ /* calc factor (with 2 bits headroom for sum of 3 subdivisions) */ move16(); - facs[iFilter][iSubdivisions] = div_s(0x2000, round_fx(L_tmp)); /* L_tmp is >= 0x2000000 */ + facs[iFilter][iSubdivisions] = div_s( 0x2000, round_fx( L_tmp ) ); /* L_tmp is >= 0x2000000 */ #endif } - } - } /* Calculate normalized autocorrelation for spectrum subdivision and get TNS filter parameters based on it */ - FOR (iFilter = 0; iFilter < pTnsConfig->nMaxFilters; iFilter++) + FOR( iFilter = 0; iFilter < pTnsConfig->nMaxFilters; iFilter++ ) { -#define RXX_E (3) - Word32 rxx[TNS_MAX_FILTER_ORDER+1]; +#define RXX_E ( 3 ) + Word32 rxx[TNS_MAX_FILTER_ORDER + 1]; Word16 idx0; Word16 idx1; Word16 spectrumLength; - STnsFilter * pFilter; + STnsFilter *pFilter; Word16 nSubdivisions; Word16 iSubdivisions; Word16 tmpbuf[325]; - set32_fx(rxx, 0, TNS_MAX_FILTER_ORDER+1); + set32_fx( rxx, 0, TNS_MAX_FILTER_ORDER + 1 ); move16(); move16(); move16(); - idx0 = pTnsConfig->iFilterBorders[iFilter+1]; + idx0 = pTnsConfig->iFilterBorders[iFilter + 1]; idx1 = pTnsConfig->iFilterBorders[iFilter]; - spectrumLength = sub(idx1, idx0); + spectrumLength = sub( idx1, idx0 ); pFilter = pTnsData->filter + iFilter; nSubdivisions = pTnsConfig->pTnsParameters[iFilter].nSubdivisions; - FOR (iSubdivisions = 0; iSubdivisions < nSubdivisions; iSubdivisions++) + FOR( iSubdivisions = 0; iSubdivisions < nSubdivisions; iSubdivisions++ ) { Word16 iStartLine, n, i; Word16 iEndLine; - const Word16 * pWindow; + const Word16 *pWindow; Word16 lag, shift; Word32 L_tmp; - IF ( facs[iFilter][iSubdivisions] == 0 ) + IF( facs[iFilter][iSubdivisions] == 0 ) { BREAK; } @@ -208,16 +207,18 @@ Word16 DetectTnsFilt_fx(STnsConfig const * pTnsConfig, /* iStartLine = idx0 + (idx1-idx0)*iSubdivisions/nSubdivisions; iEndLine = idx0 + (idx1-idx0)*(iSubdivisions+1)/nSubdivisions; */ - assert((nSubdivisions == 1) || (nSubdivisions == 3)); + assert( ( nSubdivisions == 1 ) || ( nSubdivisions == 3 ) ); - iStartLine = imult1616(spectrumLength, iSubdivisions); - iEndLine = add(iStartLine, spectrumLength); + iStartLine = imult1616( spectrumLength, iSubdivisions ); + iEndLine = add( iStartLine, spectrumLength ); - if (EQ_16(nSubdivisions, 3))iStartLine=mult(iStartLine,0x2AAB); - iStartLine = add(iStartLine, idx0); + if ( EQ_16( nSubdivisions, 3 ) ) + iStartLine = mult( iStartLine, 0x2AAB ); + iStartLine = add( iStartLine, idx0 ); - if (EQ_16(nSubdivisions, 3))iEndLine=mult(iEndLine,0x2AAB); - iEndLine = add(iEndLine, idx0); + if ( EQ_16( nSubdivisions, 3 ) ) + iEndLine = mult( iEndLine, 0x2AAB ); + iEndLine = add( iEndLine, idx0 ); move16(); @@ -226,19 +227,19 @@ Word16 DetectTnsFilt_fx(STnsConfig const * pTnsConfig, move16(); pWindow = tnsAcfWindow_fx; - n = sub(iEndLine, iStartLine); - assert(n < (Word16)(sizeof(tmpbuf)/sizeof(Word16))); - FOR (i = 0; i < n; i++) + n = sub( iEndLine, iStartLine ); + assert( n < (Word16) ( sizeof( tmpbuf ) / sizeof( Word16 ) ) ); + FOR( i = 0; i < n; i++ ) { - tmpbuf[i] = round_fx(L_shl(pSpectrum[iStartLine+i], shift)); + tmpbuf[i] = round_fx( L_shl( pSpectrum[iStartLine + i], shift ) ); } - FOR (lag = 0; lag <= pTnsConfig->maxOrder; lag++) + FOR( lag = 0; lag <= pTnsConfig->maxOrder; lag++ ) { - n = sub(sub(iEndLine,lag), iStartLine); + n = sub( sub( iEndLine, lag ), iStartLine ); - L_tmp = L_deposit_l(0); - FOR (i = 0; i < n; i++) + L_tmp = L_deposit_l( 0 ); + FOR( i = 0; i < n; i++ ) { #ifdef BASOP_NOGLOB L_tmp = L_mac0_sat( L_tmp, tmpbuf[i], tmpbuf[i + lag] ); @@ -247,71 +248,71 @@ Word16 DetectTnsFilt_fx(STnsConfig const * pTnsConfig, #endif } - if (lag != 0) L_tmp = Mpy_32_16_1(L_tmp, *pWindow++); + if ( lag != 0 ) + L_tmp = Mpy_32_16_1( L_tmp, *pWindow++ ); - L_tmp = Mpy_32_16_1(L_tmp, facs[iFilter][iSubdivisions]); - L_tmp = L_shl(L_tmp, facs_e[iFilter][iSubdivisions]); + L_tmp = Mpy_32_16_1( L_tmp, facs[iFilter][iSubdivisions] ); + L_tmp = L_shl( L_tmp, facs_e[iFilter][iSubdivisions] ); - rxx[lag] = L_add(rxx[lag], L_tmp); + rxx[lag] = L_add( rxx[lag], L_tmp ); move32(); } - } - IF ( EQ_16(iSubdivisions,nSubdivisions)) /* meaning there is no subdivision with low energy */ + IF( EQ_16( iSubdivisions, nSubdivisions ) ) /* meaning there is no subdivision with low energy */ { pFilter->spectrumLength = spectrumLength; move16(); /* Limit the maximum order to spectrum length/4 */ - GetFilterParameters(rxx, s_min (pTnsConfig->maxOrder, shr(pFilter->spectrumLength,2)), pFilter); + GetFilterParameters( rxx, s_min( pTnsConfig->maxOrder, shr( pFilter->spectrumLength, 2 ) ), pFilter ); } } - if (predictionGain) + if ( predictionGain ) { - assert(pTnsConfig->nMaxFilters == 1); + assert( pTnsConfig->nMaxFilters == 1 ); move16(); *predictionGain = pTnsData->filter->predictionGain; } /* We check the filter's decisions in the opposite direction */ - FOR (iFilter = sub(pTnsConfig->nMaxFilters,1); iFilter >= 0; iFilter--) + FOR( iFilter = sub( pTnsConfig->nMaxFilters, 1 ); iFilter >= 0; iFilter-- ) { - STnsFilter * pFilter; - struct TnsParameters const * pTnsParameters; + STnsFilter *pFilter; + struct TnsParameters const *pTnsParameters; move16(); move16(); pFilter = pTnsData->filter + iFilter; pTnsParameters = pTnsConfig->pTnsParameters + iFilter; - IF ( s_or((Word16)GT_16(pFilter->predictionGain,pTnsParameters->minPredictionGain), - sub(pFilter->avgSqrCoef,pTnsParameters->minAvgSqrCoef) > 0 ) ) + IF( s_or( (Word16) GT_16( pFilter->predictionGain, pTnsParameters->minPredictionGain ), + sub( pFilter->avgSqrCoef, pTnsParameters->minAvgSqrCoef ) > 0 ) ) { move16(); - pTnsData->nFilters = add(pTnsData->nFilters,1); + pTnsData->nFilters = add( pTnsData->nFilters, 1 ); } - ELSE IF (pTnsData->nFilters > 0) /* If a previous filter is turned on */ + ELSE IF( pTnsData->nFilters > 0 ) /* If a previous filter is turned on */ { /* Since TNS filter of order 0 is not allowed we haved to signal in the stream filter of order 1 with the 0th coefficient equal to 0 */ - ClearTnsFilterCoefficients(pFilter); + ClearTnsFilterCoefficients( pFilter ); move16(); move16(); pFilter->order = 1; - pTnsData->nFilters = add(pTnsData->nFilters,1); + pTnsData->nFilters = add( pTnsData->nFilters, 1 ); } ELSE { - ClearTnsFilterCoefficients(pFilter); + ClearTnsFilterCoefficients( pFilter ); } } test(); - return (pTnsData->nFilters > 0); + return ( pTnsData->nFilters > 0 ); } -Word16 EncodeTnsData_fx(STnsConfig const * pTnsConfig, STnsData const * pTnsData, Word16 * stream, Word16 * pnSize, Word16 * pnBits) +Word16 EncodeTnsData_fx( STnsConfig const *pTnsConfig, STnsData const *pTnsData, Word16 *stream, Word16 *pnSize, Word16 *pnBits ) { move16(); @@ -319,35 +320,35 @@ Word16 EncodeTnsData_fx(STnsConfig const * pTnsConfig, STnsData const * pTnsData *pnSize = 0; *pnBits = 0; - IF ( GT_16(pTnsConfig->nMaxFilters, 1)) + IF( GT_16( pTnsConfig->nMaxFilters, 1 ) ) { - IF ( LT_16(pTnsConfig->iFilterBorders[0],512)) + IF( LT_16( pTnsConfig->iFilterBorders[0], 512 ) ) { - GetParameters(&tnsEnabledSWBTCX10BitMap, 1, pTnsData, &stream, pnSize, pnBits); + GetParameters( &tnsEnabledSWBTCX10BitMap, 1, pTnsData, &stream, pnSize, pnBits ); } ELSE { - GetParameters(&tnsEnabledSWBTCX20BitMap, 1, pTnsData, &stream, pnSize, pnBits); + GetParameters( &tnsEnabledSWBTCX20BitMap, 1, pTnsData, &stream, pnSize, pnBits ); } } ELSE { - GetParameters(&tnsEnabledWBTCX20BitMap, 1, pTnsData, &stream, pnSize, pnBits); + GetParameters( &tnsEnabledWBTCX20BitMap, 1, pTnsData, &stream, pnSize, pnBits ); } return TNS_NO_ERROR; } -Word16 WriteTnsData_fx(STnsConfig const * pTnsConfig, Word16 const * stream, Word16 * pnSize, Encoder_State *st, Word16 * pnBits) +Word16 WriteTnsData_fx( STnsConfig const *pTnsConfig, Word16 const *stream, Word16 *pnSize, Encoder_State *st, Word16 *pnBits ) { - IF ( GT_16(pTnsConfig->nMaxFilters,1)) + IF( GT_16( pTnsConfig->nMaxFilters, 1 ) ) { - IF ( LT_16(pTnsConfig->iFilterBorders[0],512)) + IF( LT_16( pTnsConfig->iFilterBorders[0], 512 ) ) { - WriteToBitstream_fx(&tnsEnabledSWBTCX10BitMap, 1, &stream, pnSize, st->hBstr, pnBits); + WriteToBitstream_fx( &tnsEnabledSWBTCX10BitMap, 1, &stream, pnSize, st->hBstr, pnBits ); } ELSE { @@ -373,66 +374,64 @@ Word16 WriteTnsData_fx(STnsConfig const * pTnsConfig, Word16 const * stream, Wor /* Private functions */ /********************************/ -static void GetFilterParameters(Word32 rxx[], Word16 maxOrder, STnsFilter * pTnsFilter) +static void GetFilterParameters( Word32 rxx[], Word16 maxOrder, STnsFilter *pTnsFilter ) { Word16 i; Word16 parCoeff[TNS_MAX_FILTER_ORDER]; - Word32 epsP[TNS_MAX_FILTER_ORDER+1], L_tmp; + Word32 epsP[TNS_MAX_FILTER_ORDER + 1], L_tmp; #if TNS_COEF_RES == 5 - Word16 const * values = tnsCoeff5; + Word16 const *values = tnsCoeff5; #elif TNS_COEF_RES == 4 - Word16 const * values = tnsCoeff4; + Word16 const *values = tnsCoeff4; #elif TNS_COEF_RES == 3 - Word16 const * values = tnsCoeff3; + Word16 const *values = tnsCoeff3; #endif - Word16 * indexes = pTnsFilter->coefIndex; + Word16 *indexes = pTnsFilter->coefIndex; /* compute TNS filter in lattice (ParCor) form with LeRoux-Gueguen algorithm */ - L_tmp = E_LPC_schur(rxx, parCoeff, epsP, maxOrder); + L_tmp = E_LPC_schur( rxx, parCoeff, epsP, maxOrder ); BASOP_SATURATE_WARNING_OFF_EVS /* Allow saturation, this value is compared against a threshold. */ - pTnsFilter->predictionGain = divide3232(L_shr(epsP[0], PRED_GAIN_E), L_tmp); + pTnsFilter->predictionGain = divide3232( L_shr( epsP[0], PRED_GAIN_E ), L_tmp ); BASOP_SATURATE_WARNING_ON_EVS /* non-linear quantization of TNS lattice coefficients with given resolution */ - Parcor2Index(parCoeff, indexes, maxOrder); + Parcor2Index( parCoeff, indexes, maxOrder ); /* reduce filter order by truncating trailing zeros */ - i = sub(maxOrder,1); + i = sub( maxOrder, 1 ); - WHILE ((i >= 0) && (indexes[i] == 0)) + WHILE( ( i >= 0 ) && ( indexes[i] == 0 ) ) { - i = sub(i, 1); + i = sub( i, 1 ); } move16(); - pTnsFilter->order = add(i, 1); + pTnsFilter->order = add( i, 1 ); /* compute avg(coef*coef) */ - L_tmp = L_deposit_l(0); + L_tmp = L_deposit_l( 0 ); - FOR (i = pTnsFilter->order-1; i >= 0; i--) + FOR( i = pTnsFilter->order - 1; i >= 0; i-- ) { - Word16 value ; + Word16 value; move16(); - value = shr(values[indexes[i]+INDEX_SHIFT], 1); + value = shr( values[indexes[i] + INDEX_SHIFT], 1 ); move16(); - L_tmp = L_mac0(L_tmp, value, value); - + L_tmp = L_mac0( L_tmp, value, value ); } move16(); - pTnsFilter->avgSqrCoef = round_fx(L_tmp); + pTnsFilter->avgSqrCoef = round_fx( L_tmp ); /* assert(maxOrder == 8); pTnsFilter->avgSqrCoef = shr(pTnsFilter->avgSqrCoef, 3); */ - } -static void Parcor2Index(const Word16 parCoeff[] /*Q15*/, Word16 index[], Word16 order) +static void Parcor2Index( const Word16 parCoeff[] /*Q15*/, Word16 index[], Word16 order ) { Word16 nValues; - Word16 const * values; + Word16 const *values; Word16 i; Word16 iIndex; Word16 x; @@ -449,7 +448,7 @@ static void Parcor2Index(const Word16 parCoeff[] /*Q15*/, Word16 index[], Word16 values = tnsCoeff3; #endif - FOR (i = 0; i < order; i++) + FOR( i = 0; i < order; i++ ) { move16(); move16(); @@ -459,13 +458,10 @@ static void Parcor2Index(const Word16 parCoeff[] /*Q15*/, Word16 index[], Word16 /* parCoeff is in the range of -1.0 ... 1.0 by definition */ /* assert((x >= FL2WORD16(-1.0f)) && (x <= FL2WORD16(1.0f))); */ - WHILE ((iIndex < nValues) && (x > add(shr(values[iIndex-1], 1), shr(values[iIndex], 1))) ) + WHILE( ( iIndex < nValues ) && ( x > add( shr( values[iIndex - 1], 1 ), shr( values[iIndex], 1 ) ) ) ) { - iIndex = add(iIndex,1); - + iIndex = add( iIndex, 1 ); } - index[i] = sub(iIndex, 1 + INDEX_SHIFT); + index[i] = sub( iIndex, 1 + INDEX_SHIFT ); } - } - diff --git a/lib_enc/transient_detection.c b/lib_enc/transient_detection.c index 5a070af7d..dea0296ad 100644 --- a/lib_enc/transient_detection.c +++ b/lib_enc/transient_detection.c @@ -633,7 +633,7 @@ static void UpdateDelayBuffer( int16_t i; int16_t nDelay = pDelayBuffer->nDelay; - assert( ( nDelay >= 0 ) && ( nDelay <= (int16_t) sizeof( pDelayBuffer->buffer_flt) / (int16_t) sizeof( pDelayBuffer->buffer_flt[0] ) ) ); + assert( ( nDelay >= 0 ) && ( nDelay <= (int16_t) sizeof( pDelayBuffer->buffer_flt ) / (int16_t) sizeof( pDelayBuffer->buffer_flt[0] ) ) ); assert( nSamplesAvailable <= NSUBBLOCKS * pDelayBuffer->nSubblockSize ); /* If this is not the last frame */ @@ -657,7 +657,7 @@ static void UpdateSubblockEnergies( { int16_t i; - assert( ( pSubblockEnergies->nDelay >= 0 ) && ( pSubblockEnergies->nDelay + NSUBBLOCKS <= (int16_t) sizeof( pSubblockEnergies->subblockNrg_flt) / (int16_t) sizeof( pSubblockEnergies->subblockNrg_flt[0] ) ) ); + assert( ( pSubblockEnergies->nDelay >= 0 ) && ( pSubblockEnergies->nDelay + NSUBBLOCKS <= (int16_t) sizeof( pSubblockEnergies->subblockNrg_flt ) / (int16_t) sizeof( pSubblockEnergies->subblockNrg_flt[0] ) ) ); assert( pSubblockEnergies->nPartialDelay <= pSubblockEnergies->pDelayBuffer->nDelay ); /* At least one block delay is required when subblock energy change is required */ assert( pSubblockEnergies->nDelay >= 1 ); @@ -703,10 +703,10 @@ static void CalculateSubblockEnergies( const int16_t nSamplesAvailable, SubblockEnergies *pSubblockEnergies ) { - DelayBuffer *pDelayBuffer = pSubblockEnergies->pDelayBuffer; /* */ - const int16_t nSubblockSize = pDelayBuffer->nSubblockSize; /* */ - const int16_t nDelay = pSubblockEnergies->nDelay; /* */ - const int16_t nPartialDelay = pSubblockEnergies->nPartialDelay; /* */ + DelayBuffer *pDelayBuffer = pSubblockEnergies->pDelayBuffer; /* */ + const int16_t nSubblockSize = pDelayBuffer->nSubblockSize; /* */ + const int16_t nDelay = pSubblockEnergies->nDelay; /* */ + const int16_t nPartialDelay = pSubblockEnergies->nPartialDelay; /* */ const float *delayBuffer = &pDelayBuffer->buffer_flt[pDelayBuffer->nDelay - nPartialDelay]; /* */ const float facAccSubblockNrg = pSubblockEnergies->facAccSubblockNrg_flt; /* */ float *pSubblockNrg = &pSubblockEnergies->subblockNrg_flt[nDelay]; /* */ diff --git a/lib_enc/transient_detection_fx.c b/lib_enc/transient_detection_fx.c index fc02ea7ec..179e11506 100644 --- a/lib_enc/transient_detection_fx.c +++ b/lib_enc/transient_detection_fx.c @@ -12,20 +12,20 @@ #include #include #include -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /* Exponent of attack threshold. Picked according to current threshold values. */ -#define ATTACKTHRESHOLD_E 4 +#define ATTACKTHRESHOLD_E 4 /* Exponent of subblock energies and accumulated subblock energies. The current value of 2 does not prevent saturations to happen in all cases. */ -#define SUBBLOCK_NRG_E 4 +#define SUBBLOCK_NRG_E 4 /* Exponent of the subblock energy change. This value is coupled to the transient detector API. */ -#define SUBBLOCK_NRG_CHANGE_E NRG_CHANGE_E +#define SUBBLOCK_NRG_CHANGE_E NRG_CHANGE_E -#define MIN_BLOCK_ENERGY ((Word32)1) +#define MIN_BLOCK_ENERGY ( (Word32) 1 ) /************************************************/ @@ -34,16 +34,14 @@ /* */ /************************************************/ -static void InitDelayBuffer(Word16 nFrameLength, Word16 nDelay, DelayBuffer * pDelayBuffer); -static void InitSubblockEnergies(Word16 nFrameLength, Word16 nDelay, DelayBuffer * pDelayBuffer, SubblockEnergies * pSubblockEnergies); -static void InitTransientDetector_fx(SubblockEnergies * pSubblockEnergies, Word16 nDelay, Word16 nSubblocksToCheck, - TCheckSubblocksForAttack_fx pCheckSubblocksForAttack, - Word16 attackRatioThreshold, TransientDetector * pTransientDetector); -static void UpdateDelayBuffer(Word16 const * input, Word16 nSamplesAvailable, DelayBuffer * pDelayBuffer); -static void HighPassFilter(Word16 const * input, Word16 length, Word16 * pFirState1, Word16 * pFirState2, Word16 * output); -static void UpdateSubblockEnergies(Word16 const * input, Word16 nSamplesAvailable, SubblockEnergies * pSubblockEnergies); -static void CalculateSubblockEnergies(Word16 const * input, Word16 nSamplesAvailable, SubblockEnergies * pSubblockEnergies); -static void RunTransientDetector(TransientDetector * pTransientDetector); +static void InitDelayBuffer( Word16 nFrameLength, Word16 nDelay, DelayBuffer *pDelayBuffer ); +static void InitSubblockEnergies( Word16 nFrameLength, Word16 nDelay, DelayBuffer *pDelayBuffer, SubblockEnergies *pSubblockEnergies ); +static void InitTransientDetector_fx( SubblockEnergies *pSubblockEnergies, Word16 nDelay, Word16 nSubblocksToCheck, TCheckSubblocksForAttack_fx pCheckSubblocksForAttack, Word16 attackRatioThreshold, TransientDetector *pTransientDetector ); +static void UpdateDelayBuffer( Word16 const *input, Word16 nSamplesAvailable, DelayBuffer *pDelayBuffer ); +static void HighPassFilter( Word16 const *input, Word16 length, Word16 *pFirState1, Word16 *pFirState2, Word16 *output ); +static void UpdateSubblockEnergies( Word16 const *input, Word16 nSamplesAvailable, SubblockEnergies *pSubblockEnergies ); +static void CalculateSubblockEnergies( Word16 const *input, Word16 nSamplesAvailable, SubblockEnergies *pSubblockEnergies ); +static void RunTransientDetector( TransientDetector *pTransientDetector ); /************************************************/ /* */ @@ -52,59 +50,59 @@ static void RunTransientDetector(TransientDetector * pTransientDetector); /************************************************/ /** TCX decision. - * Check IF there is an attack in a subblock. Version FOR TCX Long/Short decision. - * See TCheckSubblocksForAttack_fx FOR definition of parameters. - * It is assumed that the delay of MDCT overlap was not taken into account, so that the last subblock corresponds to the newest input subblock. - */ -static void GetAttackForTCXDecision(Word32 const * pSubblockNrg, Word32 const * pAccSubblockNrg, Word16 nSubblocks, Word16 nPastSubblocks, Word16 attackRatioThreshold, Word16 * pbIsAttackPresent, Word16 * pAttackIndex) + * Check IF there is an attack in a subblock. Version FOR TCX Long/Short decision. + * See TCheckSubblocksForAttack_fx FOR definition of parameters. + * It is assumed that the delay of MDCT overlap was not taken into account, so that the last subblock corresponds to the newest input subblock. + */ +static void GetAttackForTCXDecision( Word32 const *pSubblockNrg, Word32 const *pAccSubblockNrg, Word16 nSubblocks, Word16 nPastSubblocks, Word16 attackRatioThreshold, Word16 *pbIsAttackPresent, Word16 *pAttackIndex ) { Word16 i; Word16 bIsAttackPresent, attackIndex; Word16 attackRatioThreshold_1_5; - (void)nPastSubblocks; - (void)nSubblocks; - assert(nSubblocks >= NSUBBLOCKS); - assert(nPastSubblocks >= 2); + (void) nPastSubblocks; + (void) nSubblocks; + assert( nSubblocks >= NSUBBLOCKS ); + assert( nPastSubblocks >= 2 ); /* attackRatioThreshold_1_5 = attackRatioThreshold * 1.5, exponent is ATTACKTHRESHOLD_E+1 */ - attackRatioThreshold_1_5 = add(shr(attackRatioThreshold,2),shr(attackRatioThreshold,1)); + attackRatioThreshold_1_5 = add( shr( attackRatioThreshold, 2 ), shr( attackRatioThreshold, 1 ) ); move16(); move16(); bIsAttackPresent = FALSE; attackIndex = 0; /* Search for the last attack in the subblocks */ - if ( s_or((Word16)GT_32(L_shr(pSubblockNrg[-1],ATTACKTHRESHOLD_E), Mpy_32_16_1(pAccSubblockNrg[-1], attackRatioThreshold)), - L_sub(L_shr(pSubblockNrg[-2],ATTACKTHRESHOLD_E), Mpy_32_16_1(pAccSubblockNrg[-2], attackRatioThreshold)) > 0) ) + if ( s_or( (Word16) GT_32( L_shr( pSubblockNrg[-1], ATTACKTHRESHOLD_E ), Mpy_32_16_1( pAccSubblockNrg[-1], attackRatioThreshold ) ), + L_sub( L_shr( pSubblockNrg[-2], ATTACKTHRESHOLD_E ), Mpy_32_16_1( pAccSubblockNrg[-2], attackRatioThreshold ) ) > 0 ) ) { move16(); bIsAttackPresent = TRUE; } - FOR (i = 0; i < NSUBBLOCKS; i++) + FOR( i = 0; i < NSUBBLOCKS; i++ ) { - IF ( GT_32(L_shr(pSubblockNrg[i],ATTACKTHRESHOLD_E), Mpy_32_16_1(pAccSubblockNrg[i], attackRatioThreshold))) + IF( GT_32( L_shr( pSubblockNrg[i], ATTACKTHRESHOLD_E ), Mpy_32_16_1( pAccSubblockNrg[i], attackRatioThreshold ) ) ) { - if (i < 6) + if ( i < 6 ) { move16(); bIsAttackPresent = TRUE; } - if ( s_and((Word16)NE_16(attackIndex,2),(Word16)NE_16(attackIndex,6))) + if ( s_and( (Word16) NE_16( attackIndex, 2 ), (Word16) NE_16( attackIndex, 6 ) ) ) { move16(); attackIndex = i; } } - ELSE /* no attack, but set index anyway in case of strong energy increase */ + ELSE /* no attack, but set index anyway in case of strong energy increase */ { - IF ( s_and(( (Word16)GT_32(L_shr(pSubblockNrg[i],1+ATTACKTHRESHOLD_E), Mpy_32_16_1(pSubblockNrg[sub(i,1)], attackRatioThreshold_1_5))), - ( L_sub(L_shr(pSubblockNrg[i],1+ATTACKTHRESHOLD_E), Mpy_32_16_1(pSubblockNrg[sub(i,2)], attackRatioThreshold_1_5)) > 0 )) ) + IF( s_and( ( (Word16) GT_32( L_shr( pSubblockNrg[i], 1 + ATTACKTHRESHOLD_E ), Mpy_32_16_1( pSubblockNrg[sub( i, 1 )], attackRatioThreshold_1_5 ) ) ), + ( L_sub( L_shr( pSubblockNrg[i], 1 + ATTACKTHRESHOLD_E ), Mpy_32_16_1( pSubblockNrg[sub( i, 2 )], attackRatioThreshold_1_5 ) ) > 0 ) ) ) { - if ( s_and((Word16)NE_16(attackIndex,2),(Word16)NE_16(attackIndex,6))) + if ( s_and( (Word16) NE_16( attackIndex, 2 ), (Word16) NE_16( attackIndex, 6 ) ) ) { move16(); attackIndex = i; @@ -113,12 +111,12 @@ static void GetAttackForTCXDecision(Word32 const * pSubblockNrg, Word32 const * } } /* avoid post-echos on click sounds (very short transients) due to TNS aliasing */ - if ( EQ_16(attackIndex,4)) + if ( EQ_16( attackIndex, 4 ) ) { move16(); attackIndex = 7; } - if ( EQ_16(attackIndex,5)) + if ( EQ_16( attackIndex, 5 ) ) { move16(); attackIndex = 6; @@ -128,16 +126,15 @@ static void GetAttackForTCXDecision(Word32 const * pSubblockNrg, Word32 const * move16(); *pAttackIndex = attackIndex; *pbIsAttackPresent = bIsAttackPresent; - } /** Initialize TCX transient detector. - * See InitTransientDetector_fx for definition of parameters. - */ -static void InitTCXTransientDetector(Word16 nDelay, SubblockEnergies * pSubblockEnergies, TransientDetector * pTransientDetector) + * See InitTransientDetector_fx for definition of parameters. + */ +static void InitTCXTransientDetector( Word16 nDelay, SubblockEnergies *pSubblockEnergies, TransientDetector *pTransientDetector ) { - InitTransientDetector_fx(pSubblockEnergies, nDelay, NSUBBLOCKS, GetAttackForTCXDecision, 17408/*8.5f/(1<delayBuffer); + InitDelayBuffer( nFrameLength, nTCXDelay, &pTransientDetection->delayBuffer ); /* Init a subblock energies buffer used for the TCX Short/Long decision. */ - InitSubblockEnergies(nFrameLength, nTCXDelay, &pTransientDetection->delayBuffer, &pTransientDetection->subblockEnergies); + InitSubblockEnergies( nFrameLength, nTCXDelay, &pTransientDetection->delayBuffer, &pTransientDetection->subblockEnergies ); /* Init the TCX Short/Long transient detector. */ - InitTCXTransientDetector(nTCXDelay, &pTransientDetection->subblockEnergies, &pTransientDetection->transientDetector); + InitTCXTransientDetector( nTCXDelay, &pTransientDetection->subblockEnergies, &pTransientDetection->transientDetector ); /* We need two past subblocks for the TCX TD and NSUBBLOCKS+1 for the temporal flatness measure FOR the TCX LTP. */ pTransientDetection->transientDetector.pSubblockEnergies->nDelay = - add(pTransientDetection->transientDetector.pSubblockEnergies->nDelay, NSUBBLOCKS+1); + add( pTransientDetection->transientDetector.pSubblockEnergies->nDelay, NSUBBLOCKS + 1 ); } -void InitTransientDetection_ivas_fx(Word16 nFrameLength, - Word16 nTCXDelay, - TRAN_DET_HANDLE pTransientDetection, - const Word16 ext_mem_flag - ) +void InitTransientDetection_ivas_fx( Word16 nFrameLength, + Word16 nTCXDelay, + TRAN_DET_HANDLE pTransientDetection, + const Word16 ext_mem_flag ) { - /* Init the delay buffer. */ - InitDelayBuffer(nFrameLength, nTCXDelay, &pTransientDetection->delayBuffer); - /* Init a subblock energies buffer used for the TCX Short/Long decision. */ - InitSubblockEnergies(nFrameLength, nTCXDelay, &pTransientDetection->delayBuffer, &pTransientDetection->subblockEnergies); - /* Init the TCX Short/Long transient detector. */ - InitTCXTransientDetector(nTCXDelay, &pTransientDetection->subblockEnergies, &pTransientDetection->transientDetector); - /* We need two past subblocks for the TCX TD and NSUBBLOCKS+1 for the temporal flatness measure FOR the TCX LTP. */ - IF(ext_mem_flag) - { - pTransientDetection->transientDetector.pSubblockEnergies->nDelay = - add(pTransientDetection->transientDetector.pSubblockEnergies->nDelay, add((NSUBBLOCKS + 1), (NSUBBLOCKS_SHIFT + 1))); - } - ELSE - { - pTransientDetection->transientDetector.pSubblockEnergies->nDelay = - add(pTransientDetection->transientDetector.pSubblockEnergies->nDelay, NSUBBLOCKS + 1); - } + /* Init the delay buffer. */ + InitDelayBuffer( nFrameLength, nTCXDelay, &pTransientDetection->delayBuffer ); + /* Init a subblock energies buffer used for the TCX Short/Long decision. */ + InitSubblockEnergies( nFrameLength, nTCXDelay, &pTransientDetection->delayBuffer, &pTransientDetection->subblockEnergies ); + /* Init the TCX Short/Long transient detector. */ + InitTCXTransientDetector( nTCXDelay, &pTransientDetection->subblockEnergies, &pTransientDetection->transientDetector ); + /* We need two past subblocks for the TCX TD and NSUBBLOCKS+1 for the temporal flatness measure FOR the TCX LTP. */ + IF( ext_mem_flag ) + { + pTransientDetection->transientDetector.pSubblockEnergies->nDelay = + add( pTransientDetection->transientDetector.pSubblockEnergies->nDelay, add( ( NSUBBLOCKS + 1 ), ( NSUBBLOCKS_SHIFT + 1 ) ) ); + } + ELSE + { + pTransientDetection->transientDetector.pSubblockEnergies->nDelay = + add( pTransientDetection->transientDetector.pSubblockEnergies->nDelay, NSUBBLOCKS + 1 ); + } } /** * \brief Calculate average of temporal energy change. * \return average temporal energy change with exponent = 8 */ -Word16 GetTCXAvgTemporalFlatnessMeasure_fx(struct TransientDetection const * pTransientDetection, Word16 nCurrentSubblocks, Word16 nPrevSubblocks) +Word16 GetTCXAvgTemporalFlatnessMeasure_fx( struct TransientDetection const *pTransientDetection, Word16 nCurrentSubblocks, Word16 nPrevSubblocks ) { Word16 i; - TransientDetector const * pTransientDetector; - SubblockEnergies const * pSubblockEnergies; + TransientDetector const *pTransientDetector; + SubblockEnergies const *pSubblockEnergies; Word16 nDelay; Word16 nRelativeDelay; - Word16 const * pSubblockNrgChange; + Word16 const *pSubblockNrgChange; Word32 sumTempFlatness; Word16 nTotBlocks; @@ -208,40 +204,41 @@ Word16 GetTCXAvgTemporalFlatnessMeasure_fx(struct TransientDetection const * pTr pSubblockEnergies = pTransientDetector->pSubblockEnergies; move16(); nDelay = pTransientDetector->nDelay; - nRelativeDelay = sub(pSubblockEnergies->nDelay, nDelay); + nRelativeDelay = sub( pSubblockEnergies->nDelay, nDelay ); pSubblockNrgChange = NULL; - nTotBlocks = add(nCurrentSubblocks,nPrevSubblocks); + nTotBlocks = add( nCurrentSubblocks, nPrevSubblocks ); - assert(nTotBlocks > 0); + assert( nTotBlocks > 0 ); - sumTempFlatness = L_deposit_l(0); + sumTempFlatness = L_deposit_l( 0 ); - assert((nPrevSubblocks <= nRelativeDelay) && (nCurrentSubblocks <= NSUBBLOCKS+nDelay)); + assert( ( nPrevSubblocks <= nRelativeDelay ) && ( nCurrentSubblocks <= NSUBBLOCKS + nDelay ) ); move16(); - pSubblockNrgChange = &pSubblockEnergies->subblockNrgChange[sub(nRelativeDelay,nPrevSubblocks)]; + pSubblockNrgChange = &pSubblockEnergies->subblockNrgChange[sub( nRelativeDelay, nPrevSubblocks )]; - FOR (i = 0; i < nTotBlocks; i++) + FOR( i = 0; i < nTotBlocks; i++ ) { - sumTempFlatness = L_add(sumTempFlatness, L_deposit_l(pSubblockNrgChange[i])); + sumTempFlatness = L_add( sumTempFlatness, L_deposit_l( pSubblockNrgChange[i] ) ); } /* exponent = AVG_FLAT_E */ - i = div_l(L_shl(sumTempFlatness,16-15+SUBBLOCK_NRG_CHANGE_E-AVG_FLAT_E), nTotBlocks); + i = div_l( L_shl( sumTempFlatness, 16 - 15 + SUBBLOCK_NRG_CHANGE_E - AVG_FLAT_E ), nTotBlocks ); return i; } -Word16 GetTCXMaxenergyChange_fx(struct TransientDetection const * pTransientDetection, - const Word8 isTCX10, - const Word16 nCurrentSubblocks, const Word16 nPrevSubblocks) +Word16 GetTCXMaxenergyChange_fx( struct TransientDetection const *pTransientDetection, + const Word8 isTCX10, + const Word16 nCurrentSubblocks, + const Word16 nPrevSubblocks ) { Word16 i; - TransientDetector const * pTransientDetector; - SubblockEnergies const * pSubblockEnergies; + TransientDetector const *pTransientDetector; + SubblockEnergies const *pSubblockEnergies; Word16 nDelay; Word16 nRelativeDelay; - Word16 const * pSubblockNrgChange; + Word16 const *pSubblockNrgChange; Word16 maxEnergyChange; Word16 nTotBlocks; @@ -250,55 +247,55 @@ Word16 GetTCXMaxenergyChange_fx(struct TransientDetection const * pTransientDete pSubblockEnergies = pTransientDetector->pSubblockEnergies; move16(); nDelay = pTransientDetector->nDelay; - nRelativeDelay = sub(pSubblockEnergies->nDelay, nDelay); + nRelativeDelay = sub( pSubblockEnergies->nDelay, nDelay ); pSubblockNrgChange = NULL; - nTotBlocks = nCurrentSubblocks+nPrevSubblocks; + nTotBlocks = nCurrentSubblocks + nPrevSubblocks; - assert(nTotBlocks > 0); - maxEnergyChange = 0/*0.0f Q7*/; + assert( nTotBlocks > 0 ); + maxEnergyChange = 0 /*0.0f Q7*/; - assert((nPrevSubblocks <= nRelativeDelay) && (nCurrentSubblocks <= NSUBBLOCKS+nDelay)); - pSubblockNrgChange = &pSubblockEnergies->subblockNrgChange[nRelativeDelay-nPrevSubblocks]; + assert( ( nPrevSubblocks <= nRelativeDelay ) && ( nCurrentSubblocks <= NSUBBLOCKS + nDelay ) ); + pSubblockNrgChange = &pSubblockEnergies->subblockNrgChange[nRelativeDelay - nPrevSubblocks]; - IF ( s_or(pTransientDetector->bIsAttackPresent, isTCX10) ) /* frame is TCX-10 */ + IF( s_or( pTransientDetector->bIsAttackPresent, isTCX10 ) ) /* frame is TCX-10 */ { - Word32 const * pSubblockNrg = &pSubblockEnergies->subblockNrg[sub(nRelativeDelay,nPrevSubblocks)]; + Word32 const *pSubblockNrg = &pSubblockEnergies->subblockNrg[sub( nRelativeDelay, nPrevSubblocks )]; Word32 nrgMin, nrgMax; Word16 idxMax = 0; move16(); - nrgMax = L_add(pSubblockNrg[0], 0); + nrgMax = L_add( pSubblockNrg[0], 0 ); /* find subblock with maximum energy */ - FOR (i = 1; i < nTotBlocks; i++) + FOR( i = 1; i < nTotBlocks; i++ ) { - if ( LT_32(nrgMax, pSubblockNrg[i])) + if ( LT_32( nrgMax, pSubblockNrg[i] ) ) { idxMax = i; move16(); } - nrgMax = L_max(nrgMax, pSubblockNrg[i]); + nrgMax = L_max( nrgMax, pSubblockNrg[i] ); } - nrgMin = L_add(nrgMax, 0); + nrgMin = L_add( nrgMax, 0 ); /* find minimum energy after maximum */ - FOR (i = idxMax + 1; i < nTotBlocks; i++) + FOR( i = idxMax + 1; i < nTotBlocks; i++ ) { - nrgMin = L_min(nrgMin, pSubblockNrg[i]); + nrgMin = L_min( nrgMin, pSubblockNrg[i] ); } /* lower maxEnergyChange if energy doesn't decrease much after energy peak */ /* if (nrgMin > 0.375f * nrgMax) */ - if ( LT_32(Mpy_32_16_1(nrgMax, 12288/*0.375f Q15*/), nrgMin) ) + if ( LT_32( Mpy_32_16_1( nrgMax, 12288 /*0.375f Q15*/ ), nrgMin ) ) { - nTotBlocks = sub(idxMax, 3); + nTotBlocks = sub( idxMax, 3 ); } } - FOR (i = 0; i < nTotBlocks; i++) + FOR( i = 0; i < nTotBlocks; i++ ) { - maxEnergyChange = s_max(maxEnergyChange, pSubblockNrgChange[i]); + maxEnergyChange = s_max( maxEnergyChange, pSubblockNrgChange[i] ); } move16(); @@ -307,59 +304,57 @@ Word16 GetTCXMaxenergyChange_fx(struct TransientDetection const * pTransientDete return i; } -void RunTransientDetection_fx(Word16 const * input, Word16 nSamplesAvailable, TransientDetection * pTransientDetection) +void RunTransientDetection_fx( Word16 const *input, Word16 nSamplesAvailable, TransientDetection *pTransientDetection ) { Word16 filteredInput[L_FRAME48k]; - SubblockEnergies * pSubblockEnergies = &pTransientDetection->subblockEnergies; - TransientDetector * pTransientDetector = &pTransientDetection->transientDetector; + SubblockEnergies *pSubblockEnergies = &pTransientDetection->subblockEnergies; + TransientDetector *pTransientDetector = &pTransientDetection->transientDetector; - assert((input != NULL) && (pTransientDetection != NULL) && (pSubblockEnergies != NULL) && (pTransientDetector != NULL)); + assert( ( input != NULL ) && ( pTransientDetection != NULL ) && ( pSubblockEnergies != NULL ) && ( pTransientDetector != NULL ) ); - HighPassFilter(input, nSamplesAvailable, &pSubblockEnergies->firState1, &pSubblockEnergies->firState2, filteredInput); + HighPassFilter( input, nSamplesAvailable, &pSubblockEnergies->firState1, &pSubblockEnergies->firState2, filteredInput ); /* Update subblock energies. */ - UpdateSubblockEnergies(filteredInput, nSamplesAvailable, pSubblockEnergies); + UpdateSubblockEnergies( filteredInput, nSamplesAvailable, pSubblockEnergies ); /* Run transient detectors. */ - RunTransientDetector(pTransientDetector); + RunTransientDetector( pTransientDetector ); /* Update the delay buffer. */ - UpdateDelayBuffer(filteredInput, nSamplesAvailable, &pTransientDetection->delayBuffer); + UpdateDelayBuffer( filteredInput, nSamplesAvailable, &pTransientDetection->delayBuffer ); #ifdef IVAS_CODE /* compute ramp up flag */ - pSubblockEnergies->ramp_up_flag = ((pSubblockEnergies->ramp_up_flag << 1) & 0x0003); - e0 = dotp(filteredInput + length / 2, filteredInput + length / 2, pSubblockEnergies->pDelayBuffer->nSubblockSize / 2) + 0.5f * MIN_BLOCK_ENERGY; + pSubblockEnergies->ramp_up_flag = ( ( pSubblockEnergies->ramp_up_flag << 1 ) & 0x0003 ); + e0 = dotp( filteredInput + length / 2, filteredInput + length / 2, pSubblockEnergies->pDelayBuffer->nSubblockSize / 2 ) + 0.5f * MIN_BLOCK_ENERGY; e1 = pSubblockEnergies->subblockNrg[pSubblockEnergies->nDelay + 4] - e0; - if (e1 > e0) + if ( e1 > e0 ) { pSubblockEnergies->ramp_up_flag |= 0x0001; } #endif } -void SetTCXModeInfo_fx(Encoder_State *st, - TransientDetection const * pTransientDetection, - Word16 * tcxModeOverlap) +void SetTCXModeInfo_fx( Encoder_State *st, + TransientDetection const *pTransientDetection, + Word16 *tcxModeOverlap ) { TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; - assert(pTransientDetection != NULL); + assert( pTransientDetection != NULL ); - IF( EQ_16(st->codec_mode,MODE2)) + IF( EQ_16( st->codec_mode, MODE2 ) ) { /* determine window sequence (1 long or 2 short windows) */ test(); - IF ( st->tcx10Enabled != 0 && st->tcx20Enabled != 0 ) + IF( st->tcx10Enabled != 0 && st->tcx20Enabled != 0 ) { /* window switching based on transient detector output */ test(); test(); test(); - IF ( ((pTransientDetection->transientDetector.bIsAttackPresent != 0) - || (GT_32(Mpy_32_16_1(st->currEnergyHF_fx, 840/*1.0f/39.0f Q15*/), st->prevEnergyHF_fx) )) - && ((NE_16(st->last_core, ACELP_CORE) ) && (NE_16(st->last_core, AMR_WB_CORE) )) ) + IF( ( ( pTransientDetection->transientDetector.bIsAttackPresent != 0 ) || ( GT_32( Mpy_32_16_1( st->currEnergyHF_fx, 840 /*1.0f/39.0f Q15*/ ), st->prevEnergyHF_fx ) ) ) && ( ( NE_16( st->last_core, ACELP_CORE ) ) && ( NE_16( st->last_core, AMR_WB_CORE ) ) ) ) { move16(); hTcxEnc->tcxMode = TCX_10; @@ -367,35 +362,36 @@ void SetTCXModeInfo_fx(Encoder_State *st, ELSE { move16(); - hTcxEnc->tcxMode = TCX_20; + hTcxEnc->tcxMode = TCX_20; } } ELSE { /* window selection (non-adaptive) based on flags only */ - IF (st->tcx10Enabled) + IF( st->tcx10Enabled ) { move16(); hTcxEnc->tcxMode = TCX_10; } - ELSE IF (st->tcx20Enabled) + ELSE IF( st->tcx20Enabled ) { move16(); hTcxEnc->tcxMode = TCX_20; } - ELSE { + ELSE + { move16(); - hTcxEnc->tcxMode = NO_TCX; + hTcxEnc->tcxMode = NO_TCX; } } test(); test(); - IF (st->last_core == ACELP_CORE || st->last_core == AMR_WB_CORE) + IF( st->last_core == ACELP_CORE || st->last_core == AMR_WB_CORE ) { move16(); st->hTcxCfg->tcx_last_overlap_mode = TRANSITION_OVERLAP; } - ELSE IF ( (EQ_16(hTcxEnc->tcxMode, TCX_10))&&(EQ_16(st->hTcxCfg->tcx_curr_overlap_mode,ALDO_WINDOW))) + ELSE IF( ( EQ_16( hTcxEnc->tcxMode, TCX_10 ) ) && ( EQ_16( st->hTcxCfg->tcx_curr_overlap_mode, ALDO_WINDOW ) ) ) { move16(); st->hTcxCfg->tcx_last_overlap_mode = FULL_OVERLAP; @@ -408,9 +404,9 @@ void SetTCXModeInfo_fx(Encoder_State *st, /* determine window overlaps (0 full, 2 none, or 3 half) */ - IF ( EQ_16(hTcxEnc->tcxMode, TCX_10)) + IF( EQ_16( hTcxEnc->tcxMode, TCX_10 ) ) { - IF( pTransientDetection->transientDetector.attackIndex < 0) + IF( pTransientDetection->transientDetector.attackIndex < 0 ) { move16(); *tcxModeOverlap = HALF_OVERLAP; @@ -418,22 +414,22 @@ void SetTCXModeInfo_fx(Encoder_State *st, ELSE { move16(); - *tcxModeOverlap = s_and(pTransientDetection->transientDetector.attackIndex, 3); - if ( EQ_16(*tcxModeOverlap,1)) + *tcxModeOverlap = s_and( pTransientDetection->transientDetector.attackIndex, 3 ); + if ( EQ_16( *tcxModeOverlap, 1 ) ) { move16(); *tcxModeOverlap = FULL_OVERLAP; } } } - ELSE IF ( EQ_16(hTcxEnc->tcxMode, TCX_20)) + ELSE IF( EQ_16( hTcxEnc->tcxMode, TCX_20 ) ) { - IF (EQ_16(pTransientDetection->transientDetector.attackIndex, 7)) + IF( EQ_16( pTransientDetection->transientDetector.attackIndex, 7 ) ) { move16(); *tcxModeOverlap = HALF_OVERLAP; } - ELSE IF (EQ_16(pTransientDetection->transientDetector.attackIndex, 6)) + ELSE IF( EQ_16( pTransientDetection->transientDetector.attackIndex, 6 ) ) { move16(); *tcxModeOverlap = MIN_OVERLAP; @@ -444,23 +440,21 @@ void SetTCXModeInfo_fx(Encoder_State *st, *tcxModeOverlap = ALDO_WINDOW; } } - ELSE /* NO_TCX */ + ELSE /* NO_TCX */ { move16(); *tcxModeOverlap = TRANSITION_OVERLAP; } test(); - if ((EQ_16(st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP))&&(EQ_16(*tcxModeOverlap,ALDO_WINDOW))) + if ( ( EQ_16( st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) ) && ( EQ_16( *tcxModeOverlap, ALDO_WINDOW ) ) ) { move16(); *tcxModeOverlap = FULL_OVERLAP; } /* Sanity check */ - assert(*tcxModeOverlap !=1); - + assert( *tcxModeOverlap != 1 ); } - } /************************************************/ @@ -469,71 +463,67 @@ void SetTCXModeInfo_fx(Encoder_State *st, /* */ /************************************************/ -static void InitDelayBuffer(Word16 nFrameLength, Word16 nDelay, DelayBuffer * pDelayBuffer) +static void InitDelayBuffer( Word16 nFrameLength, Word16 nDelay, DelayBuffer *pDelayBuffer ) { - Word16 const nMaxBuffSize = sizeof(pDelayBuffer->buffer)/sizeof(pDelayBuffer->buffer[0]); + Word16 const nMaxBuffSize = sizeof( pDelayBuffer->buffer ) / sizeof( pDelayBuffer->buffer[0] ); move16(); move16(); - assert((nFrameLength > NSUBBLOCKS) && (nFrameLength % NSUBBLOCKS == 0) && (nDelay >= 0) && (pDelayBuffer != NULL)); - pDelayBuffer->nSubblockSize = nFrameLength/NSUBBLOCKS; - assert(pDelayBuffer->nSubblockSize <= nMaxBuffSize); - set16_fx(pDelayBuffer->buffer, 0, nMaxBuffSize); + assert( ( nFrameLength > NSUBBLOCKS ) && ( nFrameLength % NSUBBLOCKS == 0 ) && ( nDelay >= 0 ) && ( pDelayBuffer != NULL ) ); + pDelayBuffer->nSubblockSize = nFrameLength / NSUBBLOCKS; + assert( pDelayBuffer->nSubblockSize <= nMaxBuffSize ); + set16_fx( pDelayBuffer->buffer, 0, nMaxBuffSize ); pDelayBuffer->nDelay = nDelay % pDelayBuffer->nSubblockSize; - assert(pDelayBuffer->nDelay <= nMaxBuffSize); - + assert( pDelayBuffer->nDelay <= nMaxBuffSize ); } -static void InitSubblockEnergies(Word16 nFrameLength, Word16 nDelay, DelayBuffer * pDelayBuffer, SubblockEnergies * pSubblockEnergies) +static void InitSubblockEnergies( Word16 nFrameLength, Word16 nDelay, DelayBuffer *pDelayBuffer, SubblockEnergies *pSubblockEnergies ) { - Word16 const nMaxBuffSize = sizeof(pSubblockEnergies->subblockNrg)/sizeof(pSubblockEnergies->subblockNrg[0]); - (void)nFrameLength; + Word16 const nMaxBuffSize = sizeof( pSubblockEnergies->subblockNrg ) / sizeof( pSubblockEnergies->subblockNrg[0] ); + (void) nFrameLength; - assert((pDelayBuffer != NULL) && (pSubblockEnergies != NULL) && (pDelayBuffer->nSubblockSize * NSUBBLOCKS == nFrameLength) && (pDelayBuffer->nSubblockSize > 0)); + assert( ( pDelayBuffer != NULL ) && ( pSubblockEnergies != NULL ) && ( pDelayBuffer->nSubblockSize * NSUBBLOCKS == nFrameLength ) && ( pDelayBuffer->nSubblockSize > 0 ) ); - set32_fx(pSubblockEnergies->subblockNrg, MIN_BLOCK_ENERGY, nMaxBuffSize); - set32_fx(pSubblockEnergies->accSubblockNrg, MIN_BLOCK_ENERGY, nMaxBuffSize+1); - set16_fx(pSubblockEnergies->subblockNrgChange, 0x7fff, nMaxBuffSize); + set32_fx( pSubblockEnergies->subblockNrg, MIN_BLOCK_ENERGY, nMaxBuffSize ); + set32_fx( pSubblockEnergies->accSubblockNrg, MIN_BLOCK_ENERGY, nMaxBuffSize + 1 ); + set16_fx( pSubblockEnergies->subblockNrgChange, 0x7fff, nMaxBuffSize ); pSubblockEnergies->nDelay = nDelay / pDelayBuffer->nSubblockSize; - assert(pSubblockEnergies->nDelay < nMaxBuffSize); + assert( pSubblockEnergies->nDelay < nMaxBuffSize ); pSubblockEnergies->nPartialDelay = nDelay % pDelayBuffer->nSubblockSize; - pSubblockEnergies->facAccSubblockNrg = 26624/*0.8125f Q15*/; /* Energy accumulation factor */ + pSubblockEnergies->facAccSubblockNrg = 26624 /*0.8125f Q15*/; /* Energy accumulation factor */ pSubblockEnergies->firState1 = 0; pSubblockEnergies->firState2 = 0; pSubblockEnergies->pDelayBuffer = pDelayBuffer; - pDelayBuffer->nDelay = s_max(pDelayBuffer->nDelay, pSubblockEnergies->nPartialDelay); - + pDelayBuffer->nDelay = s_max( pDelayBuffer->nDelay, pSubblockEnergies->nPartialDelay ); } /** Init transient detector. - * Fills TransientDetector structure with sensible content and enable it. - * @param pSubblockEnergies Subblock energies used in this transient detector. - * @param nDelay Delay FOR this transient detector. - * @param nSubblocksToCheck Number of subblocks to check in this transient detector. - * @param pCheckSubblockForAttack Attack detection function FOR this transient detector. - * @param pSetAttackPosition Function FOR finalizing this transient detector. - * @param attackRatioThreshold Attack ratio threshold with exponent ATTACKTHRESHOLD_E. - * @param pTransientDetector Structure to be initialized. - */ -static void InitTransientDetector_fx(SubblockEnergies * pSubblockEnergies, Word16 nDelay, Word16 nSubblocksToCheck, - TCheckSubblocksForAttack_fx pCheckSubblocksForAttack, - Word16 attackRatioThreshold, TransientDetector * pTransientDetector) + * Fills TransientDetector structure with sensible content and enable it. + * @param pSubblockEnergies Subblock energies used in this transient detector. + * @param nDelay Delay FOR this transient detector. + * @param nSubblocksToCheck Number of subblocks to check in this transient detector. + * @param pCheckSubblockForAttack Attack detection function FOR this transient detector. + * @param pSetAttackPosition Function FOR finalizing this transient detector. + * @param attackRatioThreshold Attack ratio threshold with exponent ATTACKTHRESHOLD_E. + * @param pTransientDetector Structure to be initialized. + */ +static void InitTransientDetector_fx( SubblockEnergies *pSubblockEnergies, Word16 nDelay, Word16 nSubblocksToCheck, TCheckSubblocksForAttack_fx pCheckSubblocksForAttack, Word16 attackRatioThreshold, TransientDetector *pTransientDetector ) { Word16 nMaxBuffSize; move16(); - nMaxBuffSize = sizeof(pSubblockEnergies->subblockNrg)/sizeof(pSubblockEnergies->subblockNrg[0]); + nMaxBuffSize = sizeof( pSubblockEnergies->subblockNrg ) / sizeof( pSubblockEnergies->subblockNrg[0] ); - assert((pSubblockEnergies != NULL) && (pSubblockEnergies->pDelayBuffer != NULL) && (pTransientDetector != NULL) && (pSubblockEnergies->pDelayBuffer->nSubblockSize != 0)); + assert( ( pSubblockEnergies != NULL ) && ( pSubblockEnergies->pDelayBuffer != NULL ) && ( pTransientDetector != NULL ) && ( pSubblockEnergies->pDelayBuffer->nSubblockSize != 0 ) ); pTransientDetector->pSubblockEnergies = pSubblockEnergies; - pTransientDetector->nDelay = (nDelay - pSubblockEnergies->nPartialDelay) / pSubblockEnergies->pDelayBuffer->nSubblockSize; - assert(nDelay == pTransientDetector->nDelay * pSubblockEnergies->pDelayBuffer->nSubblockSize + pSubblockEnergies->nPartialDelay); - assert(pTransientDetector->nDelay < nMaxBuffSize); - pSubblockEnergies->nDelay = s_max(pSubblockEnergies->nDelay, pTransientDetector->nDelay); - assert(nSubblocksToCheck <= NSUBBLOCKS + pTransientDetector->nDelay); + pTransientDetector->nDelay = ( nDelay - pSubblockEnergies->nPartialDelay ) / pSubblockEnergies->pDelayBuffer->nSubblockSize; + assert( nDelay == pTransientDetector->nDelay * pSubblockEnergies->pDelayBuffer->nSubblockSize + pSubblockEnergies->nPartialDelay ); + assert( pTransientDetector->nDelay < nMaxBuffSize ); + pSubblockEnergies->nDelay = s_max( pSubblockEnergies->nDelay, pTransientDetector->nDelay ); + assert( nSubblocksToCheck <= NSUBBLOCKS + pTransientDetector->nDelay ); pTransientDetector->nSubblocksToCheck = nSubblocksToCheck; pTransientDetector->CheckSubblocksForAttack_fx = pCheckSubblocksForAttack; pTransientDetector->attackRatioThreshold = attackRatioThreshold; @@ -543,52 +533,50 @@ static void InitTransientDetector_fx(SubblockEnergies * pSubblockEnergies, Word1 } /* This function should be inlined and WMOPS instrumentation takes that into account, meaning that all references are considered as local variables */ -static Word32 InlineFilter(Word16 inValue, Word16 firState1, Word16 firState2) +static Word32 InlineFilter( Word16 inValue, Word16 firState1, Word16 firState2 ) { /* 0.375f * inValue - 0.5f * firState1 + 0.125f * firState2 */ - return L_msu(L_mac(L_mult(firState2, 4096/*0.125f Q15*/), inValue, 12288/*0.375f Q15*/), firState1, 16384/*0.5f Q15*/); + return L_msu( L_mac( L_mult( firState2, 4096 /*0.125f Q15*/ ), inValue, 12288 /*0.375f Q15*/ ), firState1, 16384 /*0.5f Q15*/ ); } -static void HighPassFilter(Word16 const * input, Word16 length, Word16 * pFirState1, Word16 * pFirState2, Word16 * output) +static void HighPassFilter( Word16 const *input, Word16 length, Word16 *pFirState1, Word16 *pFirState2, Word16 *output ) { Word16 i; - output[0] = round_fx(InlineFilter(input[0], *pFirState1, *pFirState2)); - output[1] = round_fx(InlineFilter(input[1], input[0], *pFirState1)); + output[0] = round_fx( InlineFilter( input[0], *pFirState1, *pFirState2 ) ); + output[1] = round_fx( InlineFilter( input[1], input[0], *pFirState1 ) ); - FOR (i = 2; i < length; i++) + FOR( i = 2; i < length; i++ ) { - output[i] = round_fx(InlineFilter(input[i], input[i-1], input[i-2])); + output[i] = round_fx( InlineFilter( input[i], input[i - 1], input[i - 2] ) ); } /* update filter states: shift time samples through delay line */ move16(); move16(); - *pFirState2 = input[length-2]; - *pFirState1 = input[length-1]; - + *pFirState2 = input[length - 2]; + *pFirState1 = input[length - 1]; } -static void RunTransientDetector(TransientDetector * pTransientDetector) +static void RunTransientDetector( TransientDetector *pTransientDetector ) { Word16 const attackRatioThreshold = pTransientDetector->attackRatioThreshold; - SubblockEnergies const * pSubblockEnergies = pTransientDetector->pSubblockEnergies; + SubblockEnergies const *pSubblockEnergies = pTransientDetector->pSubblockEnergies; Word16 const nDelay = pTransientDetector->nDelay; Word16 const nRelativeDelay = pSubblockEnergies->nDelay - nDelay; - Word32 const * pSubblockNrg = &pSubblockEnergies->subblockNrg[nRelativeDelay]; - Word32 const * pAccSubblockNrg = &pSubblockEnergies->accSubblockNrg[nRelativeDelay]; - - assert((pTransientDetector->CheckSubblocksForAttack_fx != NULL)); + Word32 const *pSubblockNrg = &pSubblockEnergies->subblockNrg[nRelativeDelay]; + Word32 const *pAccSubblockNrg = &pSubblockEnergies->accSubblockNrg[nRelativeDelay]; - pTransientDetector->CheckSubblocksForAttack_fx(pSubblockNrg, pAccSubblockNrg, - NSUBBLOCKS+nDelay, nRelativeDelay, - attackRatioThreshold, - &pTransientDetector->bIsAttackPresent, &pTransientDetector->attackIndex); + assert( ( pTransientDetector->CheckSubblocksForAttack_fx != NULL ) ); + pTransientDetector->CheckSubblocksForAttack_fx( pSubblockNrg, pAccSubblockNrg, + NSUBBLOCKS + nDelay, nRelativeDelay, + attackRatioThreshold, + &pTransientDetector->bIsAttackPresent, &pTransientDetector->attackIndex ); } -static void UpdateDelayBuffer(Word16 const * input, Word16 nSamplesAvailable, DelayBuffer * pDelayBuffer) +static void UpdateDelayBuffer( Word16 const *input, Word16 nSamplesAvailable, DelayBuffer *pDelayBuffer ) { Word16 i; Word16 nDelay; @@ -597,75 +585,73 @@ static void UpdateDelayBuffer(Word16 const * input, Word16 nSamplesAvailable, De move16(); nDelay = pDelayBuffer->nDelay; - assert((nDelay >= 0) && (nDelay <= (int)sizeof(pDelayBuffer->buffer)/(int)sizeof(pDelayBuffer->buffer[0]))); - assert(nSamplesAvailable <= NSUBBLOCKS*pDelayBuffer->nSubblockSize); + assert( ( nDelay >= 0 ) && ( nDelay <= (int) sizeof( pDelayBuffer->buffer ) / (int) sizeof( pDelayBuffer->buffer[0] ) ) ); + assert( nSamplesAvailable <= NSUBBLOCKS * pDelayBuffer->nSubblockSize ); /* If this is not the last frame */ - IF (nSamplesAvailable == NSUBBLOCKS*pDelayBuffer->nSubblockSize) + IF( nSamplesAvailable == NSUBBLOCKS * pDelayBuffer->nSubblockSize ) { /* Store the newest samples into the delay buffer */ - FOR (i = 0; i < nDelay; i++) + FOR( i = 0; i < nDelay; i++ ) { move16(); - pDelayBuffer->buffer[i] = input[i+nSamplesAvailable-nDelay]; + pDelayBuffer->buffer[i] = input[i + nSamplesAvailable - nDelay]; } } - } -static void UpdateSubblockEnergies(Word16 const * input, Word16 nSamplesAvailable, SubblockEnergies * pSubblockEnergies) +static void UpdateSubblockEnergies( Word16 const *input, Word16 nSamplesAvailable, SubblockEnergies *pSubblockEnergies ) { Word16 i; - assert((pSubblockEnergies->nDelay >= 0) && (pSubblockEnergies->nDelay+NSUBBLOCKS <= (int)sizeof(pSubblockEnergies->subblockNrg)/(int)sizeof(pSubblockEnergies->subblockNrg[0]))); - assert(pSubblockEnergies->nPartialDelay <= pSubblockEnergies->pDelayBuffer->nDelay); + assert( ( pSubblockEnergies->nDelay >= 0 ) && ( pSubblockEnergies->nDelay + NSUBBLOCKS <= (int) sizeof( pSubblockEnergies->subblockNrg ) / (int) sizeof( pSubblockEnergies->subblockNrg[0] ) ) ); + assert( pSubblockEnergies->nPartialDelay <= pSubblockEnergies->pDelayBuffer->nDelay ); /* At least one block delay is required when subblock energy change is required */ - assert(pSubblockEnergies->nDelay >= 1); + assert( pSubblockEnergies->nDelay >= 1 ); /* Shift old subblock energies */ - FOR (i = 0; i < pSubblockEnergies->nDelay; i++) + FOR( i = 0; i < pSubblockEnergies->nDelay; i++ ) { move32(); move32(); move16(); - pSubblockEnergies->subblockNrg[i] = pSubblockEnergies->subblockNrg[i+NSUBBLOCKS]; - pSubblockEnergies->accSubblockNrg[i] = pSubblockEnergies->accSubblockNrg[i+NSUBBLOCKS]; - pSubblockEnergies->subblockNrgChange[i] = pSubblockEnergies->subblockNrgChange[i+NSUBBLOCKS]; + pSubblockEnergies->subblockNrg[i] = pSubblockEnergies->subblockNrg[i + NSUBBLOCKS]; + pSubblockEnergies->accSubblockNrg[i] = pSubblockEnergies->accSubblockNrg[i + NSUBBLOCKS]; + pSubblockEnergies->subblockNrgChange[i] = pSubblockEnergies->subblockNrgChange[i + NSUBBLOCKS]; } /* Compute filtered subblock energies for the new samples */ - CalculateSubblockEnergies(input, nSamplesAvailable, pSubblockEnergies); - + CalculateSubblockEnergies( input, nSamplesAvailable, pSubblockEnergies ); } /* This function should be inlined and WMOPS instrumentation takes that into account, meaning that all references are considered as local variables */ -static void UpdatedAndStoreAccWindowNrg(Word32 newWindowNrgF, Word32 * pAccSubblockNrg, Word16 facAccSubblockNrg, Word32 * pOutAccWindowNrgF) +static void UpdatedAndStoreAccWindowNrg( Word32 newWindowNrgF, Word32 *pAccSubblockNrg, Word16 facAccSubblockNrg, Word32 *pOutAccWindowNrgF ) { /* Store the accumulated energy */ move32(); *pOutAccWindowNrgF = *pAccSubblockNrg; /* Update the accumulated energy: maximum of the current and the accumulated energy */ - *pAccSubblockNrg = Mpy_32_16_1(*pAccSubblockNrg, facAccSubblockNrg); + *pAccSubblockNrg = Mpy_32_16_1( *pAccSubblockNrg, facAccSubblockNrg ); - if ( GT_32(newWindowNrgF, *pAccSubblockNrg)) + if ( GT_32( newWindowNrgF, *pAccSubblockNrg ) ) { move32(); *pAccSubblockNrg = newWindowNrgF; } } -static void CalculateSubblockEnergies(Word16 const * input, Word16 nSamplesAvailable, SubblockEnergies * pSubblockEnergies) +static void CalculateSubblockEnergies( Word16 const *input, Word16 nSamplesAvailable, SubblockEnergies *pSubblockEnergies ) { - DelayBuffer * pDelayBuffer; + DelayBuffer *pDelayBuffer; Word16 nSubblockSize; Word16 nDelay; Word16 nPartialDelay; - Word16 * delayBuffer; + Word16 *delayBuffer; Word16 facAccSubblockNrg; - Word32 * pSubblockNrg; - Word32 * pAccSubblockNrg; - Word16 * pSubblockNrgChange; - Word32 * pAccSubblockTmp; + Word32 *pSubblockNrg; + Word32 *pAccSubblockNrg; + Word16 *pSubblockNrgChange; + Word32 *pAccSubblockTmp; Word16 nWindows; Word16 w, k, k2, tmp; Word16 firState1, firState2; @@ -683,7 +669,7 @@ static void CalculateSubblockEnergies(Word16 const * input, Word16 nSamplesAvail nDelay = pSubblockEnergies->nDelay; nPartialDelay = pSubblockEnergies->nPartialDelay; - delayBuffer = &pDelayBuffer->buffer[sub(pDelayBuffer->nDelay, nPartialDelay)]; + delayBuffer = &pDelayBuffer->buffer[sub( pDelayBuffer->nDelay, nPartialDelay )]; pSubblockNrg = &pSubblockEnergies->subblockNrg[nDelay]; pAccSubblockNrg = &pSubblockEnergies->accSubblockNrg[nDelay]; pSubblockNrgChange = &pSubblockEnergies->subblockNrgChange[nDelay]; @@ -691,81 +677,81 @@ static void CalculateSubblockEnergies(Word16 const * input, Word16 nSamplesAvail move16(); move16(); /* nWindows = (nSamplesAvailable + nPartialDelay) / nSubblockSize */ - nWindows = shr(div_s( add(nSamplesAvailable,nPartialDelay), shl(nSubblockSize, 7)),8); + nWindows = shr( div_s( add( nSamplesAvailable, nPartialDelay ), shl( nSubblockSize, 7 ) ), 8 ); firState1 = pSubblockEnergies->firState1; firState2 = pSubblockEnergies->firState2; pAccSubblockTmp = &pAccSubblockNrg[nWindows]; - IF (nWindows > 0) + IF( nWindows > 0 ) { /* Process left over samples from the previous frame. */ - accu = L_add(MIN_BLOCK_ENERGY, 0); - assert((SUBBLOCK_NRG_E & 1) == 0); - FOR (k = 0; k < nPartialDelay; k++) + accu = L_add( MIN_BLOCK_ENERGY, 0 ); + assert( ( SUBBLOCK_NRG_E & 1 ) == 0 ); + FOR( k = 0; k < nPartialDelay; k++ ) { - tmp = shr(delayBuffer[k], SUBBLOCK_NRG_E/2); - accu = L_mac0(accu, tmp, tmp); + tmp = shr( delayBuffer[k], SUBBLOCK_NRG_E / 2 ); + accu = L_mac0( accu, tmp, tmp ); } /* Process new samples in the 0. subblock. */ - w = sub(nSubblockSize,nPartialDelay); - assert((SUBBLOCK_NRG_E & 1) == 0); - FOR (k = 0; k < w; k++) + w = sub( nSubblockSize, nPartialDelay ); + assert( ( SUBBLOCK_NRG_E & 1 ) == 0 ); + FOR( k = 0; k < w; k++ ) { - tmp = shr(input[k], SUBBLOCK_NRG_E/2); + tmp = shr( input[k], SUBBLOCK_NRG_E / 2 ); #ifdef BASOP_NOGLOB accu = L_mac0_sat( accu, tmp, tmp ); #else - accu = L_mac0(accu, tmp, tmp); + accu = L_mac0( accu, tmp, tmp ); #endif } move32(); pSubblockNrg[0] = accu; /* Set accumulated subblock energy at this point. */ - UpdatedAndStoreAccWindowNrg(pSubblockNrg[0], pAccSubblockTmp, facAccSubblockNrg, &pAccSubblockNrg[0]); + UpdatedAndStoreAccWindowNrg( pSubblockNrg[0], pAccSubblockTmp, facAccSubblockNrg, &pAccSubblockNrg[0] ); - FOR (w = 1; w < nWindows; w++) + FOR( w = 1; w < nWindows; w++ ) { - accu = L_add(MIN_BLOCK_ENERGY, 0); + accu = L_add( MIN_BLOCK_ENERGY, 0 ); /* Process new samples in the w. subblock. */ - k2 = add(k, nSubblockSize); - assert((SUBBLOCK_NRG_E & 1) == 0); - FOR (; k < k2; k++) + k2 = add( k, nSubblockSize ); + assert( ( SUBBLOCK_NRG_E & 1 ) == 0 ); + FOR( ; k < k2; k++ ) { - tmp = shr(input[k], SUBBLOCK_NRG_E/2); + tmp = shr( input[k], SUBBLOCK_NRG_E / 2 ); #ifdef BASOP_NOGLOB accu = L_mac0_sat( accu, tmp, tmp ); #else - accu = L_mac0(accu, tmp, tmp); + accu = L_mac0( accu, tmp, tmp ); #endif } move32(); pSubblockNrg[w] = accu; /* Set accumulated subblock energy at this point. */ - UpdatedAndStoreAccWindowNrg(pSubblockNrg[w], pAccSubblockTmp, facAccSubblockNrg, &pAccSubblockNrg[w]); + UpdatedAndStoreAccWindowNrg( pSubblockNrg[w], pAccSubblockTmp, facAccSubblockNrg, &pAccSubblockNrg[w] ); } /* Calculate energy change for each block. */ - FOR (w = 0; w < nWindows; w++) + FOR( w = 0; w < nWindows; w++ ) { - w0 = L_add(pSubblockNrg[w], 0); - w1 = L_add(pSubblockNrg[sub(w,1)], 0); + w0 = L_add( pSubblockNrg[w], 0 ); + w1 = L_add( pSubblockNrg[sub( w, 1 )], 0 ); - IF ( GT_32(w0, w1)) + IF( GT_32( w0, w1 ) ) { - k2 = BASOP_Util_Divide3232_uu_1616_Scale(w0, w1, &k); + k2 = BASOP_Util_Divide3232_uu_1616_Scale( w0, w1, &k ); } ELSE { - k2 = BASOP_Util_Divide3232_uu_1616_Scale(w1, w0, &k); + k2 = BASOP_Util_Divide3232_uu_1616_Scale( w1, w0, &k ); } move16(); pSubblockNrgChange[w] = MAX_16; - IF ( LT_16(k,SUBBLOCK_NRG_CHANGE_E)) + IF( LT_16( k, SUBBLOCK_NRG_CHANGE_E ) ) { move16(); - pSubblockNrgChange[w] = shr(k2, sub(SUBBLOCK_NRG_CHANGE_E,k)); + pSubblockNrgChange[w] = shr( k2, sub( SUBBLOCK_NRG_CHANGE_E, k ) ); } } } @@ -789,33 +775,33 @@ void set_transient_stereo( { int16_t n, attackIsPresent; float currFlatnessMax; - Encoder_State** sts; + Encoder_State **sts; sts = hCPE->hCoreCoder; /* for DFT/TD based stereo ,map avg. flatness to individual stereo channels (M/S or X/Y) */ - maximum(currFlatness, CPE_CHANNELS, &currFlatnessMax); + maximum( currFlatness, CPE_CHANNELS, &currFlatnessMax ); attackIsPresent = 0; - for (n = 0; n < CPE_CHANNELS; n++) + for ( n = 0; n < CPE_CHANNELS; n++ ) { - attackIsPresent = max(attackIsPresent, sts[n]->hTranDet->transientDetector.bIsAttackPresent); + attackIsPresent = max( attackIsPresent, sts[n]->hTranDet->transientDetector.bIsAttackPresent ); } - set_f(currFlatness, currFlatnessMax, CPE_CHANNELS); + set_f( currFlatness, currFlatnessMax, CPE_CHANNELS ); - for (n = 0; n < CPE_CHANNELS; n++) + for ( n = 0; n < CPE_CHANNELS; n++ ) { sts[n]->hTranDet->transientDetector.bIsAttackPresent = attackIsPresent; } - if (hCPE->hStereoDft != NULL) + if ( hCPE->hStereoDft != NULL ) { - if (hCPE->hStereoDft->attackPresent) + if ( hCPE->hStereoDft->attackPresent ) { hCPE->hStereoDft->wasTransient = 1; } - else if (hCPE->hStereoDft->wasTransient) + else if ( hCPE->hStereoDft->wasTransient ) { hCPE->hStereoDft->wasTransient = 0; } @@ -823,18 +809,18 @@ void set_transient_stereo( hCPE->hStereoDft->attackPresent = attackIsPresent; hCPE->hStereoDft->hItd->currFlatness = 0; - for (n = 0; n < CPE_CHANNELS; n++) + for ( n = 0; n < CPE_CHANNELS; n++ ) { - hCPE->hStereoDft->hItd->currFlatness = max(hCPE->hStereoDft->hItd->currFlatness, currFlatness[n]); + hCPE->hStereoDft->hItd->currFlatness = max( hCPE->hStereoDft->hItd->currFlatness, currFlatness[n] ); } } - if (hCPE->hStereoMdct != NULL) + if ( hCPE->hStereoMdct != NULL ) { hCPE->hStereoMdct->hItd->currFlatness = 0; - for (n = 0; n < CPE_CHANNELS; n++) + for ( n = 0; n < CPE_CHANNELS; n++ ) { - hCPE->hStereoMdct->hItd->currFlatness = max(hCPE->hStereoMdct->hItd->currFlatness, currFlatness[n]); + hCPE->hStereoMdct->hItd->currFlatness = max( hCPE->hStereoMdct->hItd->currFlatness, currFlatness[n] ); } } @@ -847,16 +833,16 @@ void set_transient_stereo( * *-------------------------------------------------------------------*/ - /*! r: preliminary flag to force ACELP */ +/*! r: preliminary flag to force ACELP */ int16_t transient_analysis( TRAN_DET_HANDLE hTranDet, /* i : handle transient detection */ const float cor_map_LT[], /* i : LT correlation map */ const float multi_harm_limit /* i : multi harminic threshold */ ) { - const float* pSubblockNrg; + const float *pSubblockNrg; float accSubblockNrgRev[NSUBBLOCKS]; /* store acc Nrg in reversed signal */ - float* pTmp; /* point to acc Nrg */ + float *pTmp; /* point to acc Nrg */ int16_t offset; int16_t i; float thr_fwd; @@ -870,36 +856,36 @@ int16_t transient_analysis( prel_force_td = FALSE; /* summation of the LT correlation map */ - cor_map_LT_sum = sum_f(cor_map_LT, L_FFT / 2); /* Note maybe BE optimized by computing inside noise_est */ + cor_map_LT_sum = sum_f( cor_map_LT, L_FFT / 2 ); /* Note maybe BE optimized by computing inside noise_est */ thr_fwd = THR_NORM_HIGH; - if (cor_map_LT_sum > multi_harm_limit * 0.8f) + if ( cor_map_LT_sum > multi_harm_limit * 0.8f ) { thr_fwd = THR_HIGH; } thr_rev = THR_LOW; - if (cor_map_LT_sum > multi_harm_limit * 0.6f) + if ( cor_map_LT_sum > multi_harm_limit * 0.6f ) { thr_rev = THR_NORM_LOW; } /* forward attack analysis */ - for (i = -2; i < 7; i++) + for ( i = -2; i < 7; i++ ) { - if (hTranDet->subblockEnergies.subblockNrg[nRelativeDelay + i] > hTranDet->subblockEnergies.accSubblockNrg[nRelativeDelay + i] * thr_fwd) + if ( hTranDet->subblockEnergies.subblockNrg[nRelativeDelay + i] > hTranDet->subblockEnergies.accSubblockNrg[nRelativeDelay + i] * thr_fwd ) { prel_force_td |= 0x0001; } } - if (prel_force_td == 0 && hTranDet->transientDetector.prev_bIsAttackPresent == 1) + if ( prel_force_td == 0 && hTranDet->transientDetector.prev_bIsAttackPresent == 1 ) { /* release analysis */ pSubblockNrg = hTranDet->transientDetector.pSubblockEnergies->subblockNrg; - set_zero(accSubblockNrgRev, NSUBBLOCKS); + set_zero( accSubblockNrgRev, NSUBBLOCKS ); - for (i = NSUBBLOCKS - 1; i > -1; i--) + for ( i = NSUBBLOCKS - 1; i > -1; i-- ) { - if (i == NSUBBLOCKS - 1) + if ( i == NSUBBLOCKS - 1 ) { accSubblockNrgRev[i] = pSubblockNrg[i + offset]; } @@ -907,7 +893,7 @@ int16_t transient_analysis( { accSubblockNrgRev[i] = *pTmp; *pTmp *= hTranDet->transientDetector.pSubblockEnergies->facAccSubblockNrg; - if (pSubblockNrg[i + offset] > *pTmp) + if ( pSubblockNrg[i + offset] > *pTmp ) { *pTmp = pSubblockNrg[i + offset]; } @@ -915,19 +901,19 @@ int16_t transient_analysis( } /* -3 check */ - if (pSubblockNrg[1 + offset] > accSubblockNrgRev[1] * thr_rev) + if ( pSubblockNrg[1 + offset] > accSubblockNrgRev[1] * thr_rev ) { prel_force_td |= 0x0002; } /* -4 check */ - if (prel_force_td == 0 && pSubblockNrg[offset] > accSubblockNrgRev[0] * thr_rev) + if ( prel_force_td == 0 && pSubblockNrg[offset] > accSubblockNrgRev[0] * thr_rev ) { - if (pSubblockNrg[offset] > accSubblockNrgRev[0] * (thr_rev + THR_LOW_STEP)) + if ( pSubblockNrg[offset] > accSubblockNrgRev[0] * ( thr_rev + THR_LOW_STEP ) ) { prel_force_td |= 0x0004; } - else if ((hTranDet->subblockEnergies.ramp_up_flag & 0x0002) != 0) + else if ( ( hTranDet->subblockEnergies.ramp_up_flag & 0x0002 ) != 0 ) { prel_force_td |= 0x0008; } @@ -938,4 +924,3 @@ int16_t transient_analysis( } #endif - diff --git a/lib_enc/transition_enc_fx.c b/lib_enc/transition_enc_fx.c index 6b78ebc58..bc81a23c6 100644 --- a/lib_enc/transition_enc_fx.c +++ b/lib_enc/transition_enc_fx.c @@ -3,24 +3,22 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ +#include "options.h" /* Compilation switches */ #include "cnst.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ +#include "rom_com_fx.h" /* Static table prototypes */ #include "rom_com.h" /* Static table prototypes */ //#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*-----------------------------------------------------------------* - * Local function prototypes - *-----------------------------------------------------------------*/ + * Local function prototypes + *-----------------------------------------------------------------*/ -static void gain_trans_enc_fx(Word32 gain_trans32, Word16 exc[], Word16 *quant_index, Word16 *quant_sign, Word16 Q_new); +static void gain_trans_enc_fx( Word32 gain_trans32, Word16 exc[], Word16 *quant_index, Word16 *quant_sign, Word16 Q_new ); -static void tc_enc_fx(Encoder_State *st_fx, const Word16 i_subfr, Word16 *tc_subfr, Word16 *position, - const Word16 *h1_fx, const Word16 *xn_fx, Word16 *exc_fx, Word16 *yy1_fx, Word16 *T0_min, Word16 *T0_max, - Word16 *T0, Word16 *T0_frac, Word16 *gain_pit_fx, Word16 g_corr_fx[], Word16 *bwe_exc_fx, Word16 Q_new); +static void tc_enc_fx( Encoder_State *st_fx, const Word16 i_subfr, Word16 *tc_subfr, Word16 *position, const Word16 *h1_fx, const Word16 *xn_fx, Word16 *exc_fx, Word16 *yy1_fx, Word16 *T0_min, Word16 *T0_max, Word16 *T0, Word16 *T0_frac, Word16 *gain_pit_fx, Word16 g_corr_fx[], Word16 *bwe_exc_fx, Word16 Q_new ); /*==========================================================================*/ @@ -61,29 +59,29 @@ static void tc_enc_fx(Encoder_State *st_fx, const Word16 i_subfr, Word16 *tc_sub /*--------------------------------------------------------------------------*/ void transition_enc_fx( - Encoder_State *st_fx,/* i/o: encoder state structure */ - const Word16 i_subfr, /* i : subframe index */ - Word16 *tc_subfr, /* i/o: TC subframe index */ - Word16 *Jopt_flag, /* i : joint optimization flag */ - Word16 *position, /* i/o: maximum of residual signal index */ - Word16 *T0, /* i/o: close loop integer pitch Q0*/ - Word16 *T0_frac, /* i/o: close loop fractional part of the pitch Q0*/ - Word16 *T0_min, /* i/o: lower limit for close-loop search Q0*/ - Word16 *T0_max, /* i/o: higher limit for close-loop search Q0*/ - Word16 *exc_fx, /* i/o: pointer to excitation signal frame Q_new*/ - Word16 *y1_fx, /* o : zero-memory filtered adaptive excitation Q_new-1+shift*/ - const Word16 *h1_fx, /* i : weighted filter input response Q(14+shift)*/ - const Word16 *xn_fx, /* i : target vector Q_new-1+shift*/ - Word16 *xn2_fx, /* o : target vector for innovation search Q_new-1+shift*/ - Word16 *gp_cl_fx, /* i/o: memory of gain of pitch clipping algorithm */ - Word16 *gain_pit_fx, /* o : adaptive excitation gain Q14*/ - Word16 *g_corr_fx, /* o : ACELP correlation values */ - Word16 *clip_gain, /* i/o: adaptive gain clipping flag */ - Word16 **pt_pitch_fx, /* o : floating pitch values */ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE Q_new*/ - Word16* unbits_ACELP, /* i/o: unused bits */ - Word16 Q_new, /* i : Current scaling */ - Word16 shift /* i : downscaling needs for 12 bits convolutions */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word16 i_subfr, /* i : subframe index */ + Word16 *tc_subfr, /* i/o: TC subframe index */ + Word16 *Jopt_flag, /* i : joint optimization flag */ + Word16 *position, /* i/o: maximum of residual signal index */ + Word16 *T0, /* i/o: close loop integer pitch Q0*/ + Word16 *T0_frac, /* i/o: close loop fractional part of the pitch Q0*/ + Word16 *T0_min, /* i/o: lower limit for close-loop search Q0*/ + Word16 *T0_max, /* i/o: higher limit for close-loop search Q0*/ + Word16 *exc_fx, /* i/o: pointer to excitation signal frame Q_new*/ + Word16 *y1_fx, /* o : zero-memory filtered adaptive excitation Q_new-1+shift*/ + const Word16 *h1_fx, /* i : weighted filter input response Q(14+shift)*/ + const Word16 *xn_fx, /* i : target vector Q_new-1+shift*/ + Word16 *xn2_fx, /* o : target vector for innovation search Q_new-1+shift*/ + Word16 *gp_cl_fx, /* i/o: memory of gain of pitch clipping algorithm */ + Word16 *gain_pit_fx, /* o : adaptive excitation gain Q14*/ + Word16 *g_corr_fx, /* o : ACELP correlation values */ + Word16 *clip_gain, /* i/o: adaptive gain clipping flag */ + Word16 **pt_pitch_fx, /* o : floating pitch values */ + Word16 *bwe_exc_fx, /* o : excitation for SWB TBE Q_new*/ + Word16 *unbits_ACELP, /* i/o: unused bits */ + Word16 Q_new, /* i : Current scaling */ + Word16 shift /* i : downscaling needs for 12 bits convolutions */ ) { @@ -105,19 +103,19 @@ void transition_enc_fx( /*----------------------------------------------------------------* * convert pitch values to 16kHz domain *----------------------------------------------------------------*/ - - IF(EQ_16(st_fx->L_frame, L_FRAME) /*|| (tdm_Pri_pitch_buf != NULL && tdm_Pri_pitch_buf[0] < 0)*/) + + IF( EQ_16( st_fx->L_frame, L_FRAME ) /*|| (tdm_Pri_pitch_buf != NULL && tdm_Pri_pitch_buf[0] < 0)*/ ) { - Copy(st_fx->pitch_fx, T_op, 2); + Copy( st_fx->pitch_fx, T_op, 2 ); } ELSE /* L_frame == L_FRAME16k */ { /*T_op[0] = (int16_t)(pitch[0] * 1.25f + 0.5f); T_op[1] = (int16_t)(pitch[1] * 1.25f + 0.5f);*/ - T_op[0] = add(st_fx->pitch_fx[0], mult_r(st_fx->pitch_fx[0], 8192/*0.25f Q15*/)); - T_op[1] = add(st_fx->pitch_fx[1], mult_r(st_fx->pitch_fx[1], 8192/*0.25f Q15*/)); + T_op[0] = add( st_fx->pitch_fx[0], mult_r( st_fx->pitch_fx[0], 8192 /*0.25f Q15*/ ) ); + T_op[1] = add( st_fx->pitch_fx[1], mult_r( st_fx->pitch_fx[1], 8192 /*0.25f Q15*/ ) ); } - shift_wsp = add(Q_new,shift); + shift_wsp = add( Q_new, shift ); lp_flag = st_fx->acelp_cfg.ltf_mode; move16(); @@ -137,26 +135,25 @@ void transition_enc_fx( IF( limit_flag == 0 ) { test(); - IF( EQ_16(st_fx->L_frame,L_FRAME) && LT_16(T_op[1],PIT_MIN) ) + IF( EQ_16( st_fx->L_frame, L_FRAME ) && LT_16( T_op[1], PIT_MIN ) ) { mult_Top = 2; move16(); } test(); - if( EQ_16(st_fx->L_frame,L_FRAME16k) && LT_16(T_op[1],PIT16k_MIN)) + if ( EQ_16( st_fx->L_frame, L_FRAME16k ) && LT_16( T_op[1], PIT16k_MIN ) ) { mult_Top = 2; move16(); } } - limit_T0_fx( st_fx->L_frame, 8, 0, limit_flag, mult_Top*T_op[1], 0, T0_min, T0_max ); - + limit_T0_fx( st_fx->L_frame, 8, 0, limit_flag, mult_Top * T_op[1], 0, T0_min, T0_max ); } /*-----------------------------------------------------------------* * zero adaptive excitation signal construction *-----------------------------------------------------------------*/ - IF ( GT_16(*tc_subfr,i_subfr)) + IF( GT_16( *tc_subfr, i_subfr ) ) { *gain_pit_fx = 0; move16(); @@ -164,64 +161,63 @@ void transition_enc_fx( move16(); g_corr_fx[0] = 16384; move16(); - g_corr_fx[1] = add(shl(sub(shift_wsp,1),1),1); + g_corr_fx[1] = add( shl( sub( shift_wsp, 1 ), 1 ), 1 ); move16(); g_corr_fx[2] = -16384; move16(); - g_corr_fx[3] = shl(sub(shift_wsp,1),1); + g_corr_fx[3] = shl( sub( shift_wsp, 1 ), 1 ); - set16_fx(&exc_fx[i_subfr], 0, L_SUBFR); /* set excitation for current subrame to 0 */ + set16_fx( &exc_fx[i_subfr], 0, L_SUBFR ); /* set excitation for current subrame to 0 */ - IF( EQ_16(st_fx->L_frame,L_FRAME)) + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { - set16_fx(&bwe_exc_fx[i_subfr*HIBND_ACB_L_FAC], 0, (Word16)(L_SUBFR*HIBND_ACB_L_FAC)); /* set past excitation buffer to 0 */ + set16_fx( &bwe_exc_fx[i_subfr * HIBND_ACB_L_FAC], 0, (Word16) ( L_SUBFR * HIBND_ACB_L_FAC ) ); /* set past excitation buffer to 0 */ } ELSE { - set16_fx(&bwe_exc_fx[i_subfr*2], 0, L_SUBFR*2); /* set past excitation buffer to 0 */ + set16_fx( &bwe_exc_fx[i_subfr * 2], 0, L_SUBFR * 2 ); /* set past excitation buffer to 0 */ } - set16_fx(y1_fx, 0, L_SUBFR); /* set filtered adaptive excitation to 0 */ - Copy(xn_fx, xn2_fx, L_SUBFR); /* target vector for codebook search */ + set16_fx( y1_fx, 0, L_SUBFR ); /* set filtered adaptive excitation to 0 */ + Copy( xn_fx, xn2_fx, L_SUBFR ); /* target vector for codebook search */ *T0 = L_SUBFR; move16(); *T0_frac = 0; move16(); - **pt_pitch_fx = shl(add(shl(*T0,2),*T0_frac),4); - move16(); /* save subframe pitch values Q6 */ - + **pt_pitch_fx = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); + move16(); /* save subframe pitch values Q6 */ } /*-----------------------------------------------------------------* * glottal codebook contribution construction *-----------------------------------------------------------------*/ - ELSE IF ( EQ_16(*tc_subfr,i_subfr)) + ELSE IF( EQ_16( *tc_subfr, i_subfr ) ) { - IF( EQ_16(st_fx->L_frame,L_FRAME)) + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { - set16_fx( bwe_exc_fx-PIT_MAX*HIBND_ACB_L_FAC, 0, PIT_MAX*HIBND_ACB_L_FAC); /* set past excitation buffer to 0 */ + set16_fx( bwe_exc_fx - PIT_MAX * HIBND_ACB_L_FAC, 0, PIT_MAX * HIBND_ACB_L_FAC ); /* set past excitation buffer to 0 */ } ELSE { - set16_fx( bwe_exc_fx-PIT16k_MAX*2, 0, PIT16k_MAX*2); /* set past excitation buffer to 0 */ + set16_fx( bwe_exc_fx - PIT16k_MAX * 2, 0, PIT16k_MAX * 2 ); /* set past excitation buffer to 0 */ } tc_enc_fx( st_fx, i_subfr, tc_subfr, position, h1_fx, xn_fx, exc_fx, - y1_fx, T0_min, T0_max, T0, T0_frac, gain_pit_fx, g_corr_fx, bwe_exc_fx,Q_new); + y1_fx, T0_min, T0_max, T0, T0_frac, gain_pit_fx, g_corr_fx, bwe_exc_fx, Q_new ); - IF (EQ_16(*tc_subfr, TC_0_0) ) + IF( EQ_16( *tc_subfr, TC_0_0 ) ) { /* this is called only to compute unused bits */ - config_acelp1(ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, - L_FRAME, -1, &(st_fx->acelp_cfg), hBstr->nb_bits_tot_fx, TRANSITION, TC_0_0, 3, NULL, unbits_ACELP, - st_fx->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st_fx->idchan, st_fx->active_fr_cnt_fx, 0 /*tdm_Pitch_reuse_flag*/, st_fx->tdm_LRTD_flag, 0 /*GSC_IVAS_mode*/ + config_acelp1( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, + L_FRAME, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot_fx, TRANSITION, TC_0_0, 3, NULL, unbits_ACELP, + st_fx->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st_fx->idchan, st_fx->active_fr_cnt_fx, 0 /*tdm_Pitch_reuse_flag*/, st_fx->tdm_LRTD_flag, 0 /*GSC_IVAS_mode*/ ); } - *clip_gain = gp_clip_fx(st_fx->element_mode, st_fx->core_brate, st_fx->voicing_fx, i_subfr, TRANSITION, xn_fx, gp_cl_fx, sub(shift_wsp,1) ); + *clip_gain = gp_clip_fx( st_fx->element_mode, st_fx->core_brate, st_fx->voicing_fx, i_subfr, TRANSITION, xn_fx, gp_cl_fx, sub( shift_wsp, 1 ) ); updt_tar_fx( xn_fx, xn2_fx, y1_fx, *gain_pit_fx, L_SUBFR ); - **pt_pitch_fx = shl(add(shl(*T0,2),*T0_frac),4); + **pt_pitch_fx = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); move16(); *Jopt_flag = 1; move16(); @@ -234,15 +230,15 @@ void transition_enc_fx( * in the 1st subframe and the second one in 2nd subframe * and later *--------------------------------------------------------------*/ - ELSE IF ( LT_16(*tc_subfr,i_subfr)) + ELSE IF( LT_16( *tc_subfr, i_subfr ) ) { - IF( EQ_16(st_fx->L_frame,L_FRAME)) + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { *Jopt_flag = 1; move16(); /* pit_flag for T0 bits number coding determination */ test(); - IF( (EQ_16(sub(i_subfr,*tc_subfr),L_SUBFR))||(EQ_16(sub(i_subfr,*tc_subfr),L_SUBFR-TC_0_0))) + IF( ( EQ_16( sub( i_subfr, *tc_subfr ), L_SUBFR ) ) || ( EQ_16( sub( i_subfr, *tc_subfr ), L_SUBFR - TC_0_0 ) ) ) { pit_flag = 0; move16(); @@ -253,9 +249,9 @@ void transition_enc_fx( move16(); } - IF( EQ_16(*tc_subfr,TC_0_0)) + IF( EQ_16( *tc_subfr, TC_0_0 ) ) { - IF( EQ_16(i_subfr,L_SUBFR)) + IF( EQ_16( i_subfr, L_SUBFR ) ) { limit_T0_fx( L_FRAME, 8, pit_flag, limit_flag, *T0, 0, T0_min, T0_max ); } @@ -268,38 +264,38 @@ void transition_enc_fx( * second glot. impulse position *----------------------------------------------------------*/ test(); - IF( (*tc_subfr == 0) && (EQ_16(i_subfr,L_SUBFR))) + IF( ( *tc_subfr == 0 ) && ( EQ_16( i_subfr, L_SUBFR ) ) ) { - IF( GT_16(PIT_MIN,(*position))) + IF( GT_16( PIT_MIN, ( *position ) ) ) { - pit_start = sub(L_SUBFR, (*position)); + pit_start = sub( L_SUBFR, ( *position ) ); } ELSE { pit_start = PIT_MIN; move16(); } - pit_start = s_max(pit_start, PIT_MIN); + pit_start = s_max( pit_start, PIT_MIN ); - pit_limit = add(shl(pit_start,1), *position); + pit_limit = add( shl( pit_start, 1 ), *position ); /* Find the closed loop pitch period */ *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, pit_start, pit_limit, L_FRAME, L_SUBFR ); - offset = tbe_celp_exc_offset(*T0, *T0_frac, st_fx->L_frame); + offset = tbe_celp_exc_offset( *T0, *T0_frac, st_fx->L_frame ); - FOR (i=0; itotal_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, - st_fx->L_frame, -1, &(st_fx->acelp_cfg), hBstr->nb_bits_tot_fx, TRANSITION, *tc_subfr, 2, NULL, - unbits_ACELP, st_fx->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st_fx->idchan, st_fx->active_fr_cnt_fx, 0 /*tdm_Pitch_reuse_flag*/, st_fx->tdm_LRTD_flag, 0 /*GSC_IVAS_mode*/); + config_acelp1( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, + st_fx->L_frame, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot_fx, TRANSITION, *tc_subfr, 2, NULL, + unbits_ACELP, st_fx->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st_fx->idchan, st_fx->active_fr_cnt_fx, 0 /*tdm_Pitch_reuse_flag*/, st_fx->tdm_LRTD_flag, 0 /*GSC_IVAS_mode*/ ); } /*-----------------------------------------------------------------* * get number of bits for pitch encoding *-----------------------------------------------------------------*/ - nBits = st_fx->acelp_cfg.pitch_bits[shr(i_subfr, 6)]; + nBits = st_fx->acelp_cfg.pitch_bits[shr( i_subfr, 6 )]; move16(); /*-----------------------------------------------------------------* @@ -343,41 +339,40 @@ void transition_enc_fx( test(); test(); /* first glottal impulse is in the 1st subrame */ - IF( (EQ_16(i_subfr,L_SUBFR))&&(GE_16(*tc_subfr,TC_0_128))) + IF( ( EQ_16( i_subfr, L_SUBFR ) ) && ( GE_16( *tc_subfr, TC_0_128 ) ) ) { /*--------------------------------------------------------* * second glottal impulse is in the 3rd or 4th subframe * - build exc[] in 2nd subframe *--------------------------------------------------------*/ - *T0 = 2*L_SUBFR; + *T0 = 2 * L_SUBFR; move16(); *T0_frac = 0; move16(); *Jopt_flag = 0; move16(); - set16_fx( &exc_fx[i_subfr], 0, (Word16)(L_SUBFR+1) ); - set16_fx( &bwe_exc_fx[i_subfr*HIBND_ACB_L_FAC], 0, (Word16)(L_SUBFR*HIBND_ACB_L_FAC) ); - + set16_fx( &exc_fx[i_subfr], 0, (Word16) ( L_SUBFR + 1 ) ); + set16_fx( &bwe_exc_fx[i_subfr * HIBND_ACB_L_FAC], 0, (Word16) ( L_SUBFR * HIBND_ACB_L_FAC ) ); } - ELSE IF( (EQ_16(i_subfr,L_SUBFR))&&(EQ_16(*tc_subfr,TC_0_64))) + ELSE IF( ( EQ_16( i_subfr, L_SUBFR ) ) && ( EQ_16( *tc_subfr, TC_0_64 ) ) ) { /*--------------------------------------------------------* * second glottal impulse is in the 2nd subframe, * - build exc[] in 2nd subframe *--------------------------------------------------------*/ - IF( LT_16(add(*T0,*position), L_SUBFR )) + IF( LT_16( add( *T0, *position ), L_SUBFR ) ) { /* impulse must be in the 2nd subframe (not in 1st) */ - *T0 = sub(L_SUBFR, (*position)); + *T0 = sub( L_SUBFR, ( *position ) ); move16(); *T0_frac = 0; move16(); } - IF( GE_16(add(*T0,*position),2*L_SUBFR)) + IF( GE_16( add( *T0, *position ), 2 * L_SUBFR ) ) { /* impulse must be in the 2nd subframe (not in 3rd) */ - *T0 = sub(2*L_SUBFR-1,(*position)); + *T0 = sub( 2 * L_SUBFR - 1, ( *position ) ); move16(); *T0_frac = 2; move16(); @@ -387,47 +382,46 @@ void transition_enc_fx( /* 7bit ENCODER */ /* index = (*T0-pit_start)*2 + *T0_frac/2;*/ - index = add(shl(sub(*T0,pit_start),1), shr(*T0_frac,1)); + index = add( shl( sub( *T0, pit_start ), 1 ), shr( *T0_frac, 1 ) ); push_indice_fx( hBstr, IND_PITCH, index, nBits ); /* Find the adaptive codebook vector - ACELP long-term prediction */ - pred_lt4(&exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR+1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP); + pred_lt4( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); - offset = tbe_celp_exc_offset(*T0, *T0_frac, st_fx->L_frame); + offset = tbe_celp_exc_offset( *T0, *T0_frac, st_fx->L_frame ); - FOR (i=0; iL_frame); + offset = tbe_celp_exc_offset( *T0, *T0_frac, st_fx->L_frame ); - FOR (i=0; iL_frame); + offset = tbe_celp_exc_offset( *T0, *T0_frac, st_fx->L_frame ); - FOR (i=0; iL_frame); + offset = tbe_celp_exc_offset( *T0, *T0_frac, st_fx->L_frame ); - FOR (i=0; iL_frame); + offset = tbe_celp_exc_offset( *T0, *T0_frac, st_fx->L_frame ); - FOR (i=0; ielement_mode, st_fx->core_brate, st_fx->voicing_fx, i_subfr, TRANSITION, xn_fx, gp_cl_fx, (Q_new+shift-1) ); + *clip_gain = gp_clip_fx( st_fx->element_mode, st_fx->core_brate, st_fx->voicing_fx, i_subfr, TRANSITION, xn_fx, gp_cl_fx, ( Q_new + shift - 1 ) ); lp_select = lp_filt_exc_enc_fx( MODE1, TRANSITION, i_subfr, exc_fx, h1_fx, - xn_fx, y1_fx, xn2_fx, L_SUBFR, st_fx->L_frame, g_corr_fx, *clip_gain, gain_pit_fx, &lp_flag ); + xn_fx, y1_fx, xn2_fx, L_SUBFR, st_fx->L_frame, g_corr_fx, *clip_gain, gain_pit_fx, &lp_flag ); - IF( EQ_16(lp_flag,NORMAL_OPERATION)) + IF( EQ_16( lp_flag, NORMAL_OPERATION ) ) { push_indice_fx( hBstr, IND_LP_FILT_SELECT, lp_select, 1 ); } } - **pt_pitch_fx = shl(add(shl(*T0,2),*T0_frac),4); + **pt_pitch_fx = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); move16(); /*---------------------------------------------------------------------* * fill the pitch buffer - needed for post-processing @@ -614,105 +604,104 @@ void transition_enc_fx( test(); test(); test(); - IF( (*tc_subfr >= 2*L_SUBFR) && (i_subfr == 3*L_SUBFR) ) + IF( ( *tc_subfr >= 2 * L_SUBFR ) && ( i_subfr == 3 * L_SUBFR ) ) { - tmp = shl(add(shl(*T0,2),*T0_frac),4); - (*pt_pitch_fx) -= 3; + tmp = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); + ( *pt_pitch_fx ) -= 3; move16(); **pt_pitch_fx = tmp; move16(); - (*pt_pitch_fx)++; + ( *pt_pitch_fx )++; move16(); **pt_pitch_fx = tmp; move16(); - (*pt_pitch_fx)++; + ( *pt_pitch_fx )++; move16(); **pt_pitch_fx = tmp; move16(); - (*pt_pitch_fx)++; + ( *pt_pitch_fx )++; } - ELSE IF( (*tc_subfr == L_SUBFR) && (i_subfr == 2*L_SUBFR) ) + ELSE IF( ( *tc_subfr == L_SUBFR ) && ( i_subfr == 2 * L_SUBFR ) ) { - tmp = shl(add(shl(*T0,2),*T0_frac),4); - (*pt_pitch_fx) -= 2; + tmp = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); + ( *pt_pitch_fx ) -= 2; move16(); **pt_pitch_fx = tmp; move16(); - (*pt_pitch_fx)++; + ( *pt_pitch_fx )++; move16(); **pt_pitch_fx = tmp; move16(); - (*pt_pitch_fx)++; + ( *pt_pitch_fx )++; move16(); } - ELSE IF( (*tc_subfr == TC_0_64) && (i_subfr == L_SUBFR) ) + ELSE IF( ( *tc_subfr == TC_0_64 ) && ( i_subfr == L_SUBFR ) ) { - tmp = shl(add(shl(*T0,2),*T0_frac),4); - (*pt_pitch_fx) -= 1; + tmp = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); + ( *pt_pitch_fx ) -= 1; move16(); **pt_pitch_fx = tmp; move16(); - (*pt_pitch_fx)++; + ( *pt_pitch_fx )++; move16(); } - ELSE IF( (*tc_subfr == TC_0_128) && (i_subfr == 2*L_SUBFR) ) + ELSE IF( ( *tc_subfr == TC_0_128 ) && ( i_subfr == 2 * L_SUBFR ) ) { - tmp = shl(add(shl(*T0,2),*T0_frac),4); - (*pt_pitch_fx) -= 2; + tmp = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); + ( *pt_pitch_fx ) -= 2; move16(); **pt_pitch_fx = tmp; move16(); - (*pt_pitch_fx)++; + ( *pt_pitch_fx )++; move16(); **pt_pitch_fx = tmp; move16(); - (*pt_pitch_fx)++; + ( *pt_pitch_fx )++; move16(); } - ELSE IF( (*tc_subfr == TC_0_192) && (i_subfr == 3*L_SUBFR) ) + ELSE IF( ( *tc_subfr == TC_0_192 ) && ( i_subfr == 3 * L_SUBFR ) ) { - tmp = shl(add(shl(*T0,2),*T0_frac),4); - (*pt_pitch_fx) -= 3; + tmp = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); + ( *pt_pitch_fx ) -= 3; move16(); **pt_pitch_fx = tmp; move16(); - (*pt_pitch_fx)++; + ( *pt_pitch_fx )++; move16(); **pt_pitch_fx = tmp; move16(); - (*pt_pitch_fx)++; + ( *pt_pitch_fx )++; move16(); **pt_pitch_fx = tmp; move16(); - (*pt_pitch_fx)++; + ( *pt_pitch_fx )++; move16(); } } - ELSE /* L_frame == L_FRAME16k */ + ELSE /* L_frame == L_FRAME16k */ { - if( GE_16(i_subfr,2*L_SUBFR)) + if ( GE_16( i_subfr, 2 * L_SUBFR ) ) { limit_flag = 1; move16(); } - IF( LE_16(i_subfr,2*L_SUBFR)) + IF( LE_16( i_subfr, 2 * L_SUBFR ) ) { - IF( LT_16(i_subfr,2*L_SUBFR)) + IF( LT_16( i_subfr, 2 * L_SUBFR ) ) { mult_Top = 1; move16(); - if( LT_16(T_op[0],PIT16k_MIN)) + if ( LT_16( T_op[0], PIT16k_MIN ) ) { mult_Top = 2; move16(); } - limit_T0_fx( L_FRAME16k, 8, 0, limit_flag, mult_Top*T_op[0], 0, T0_min, T0_max ); /* TC0 second subfr. */ - + limit_T0_fx( L_FRAME16k, 8, 0, limit_flag, mult_Top * T_op[0], 0, T0_min, T0_max ); /* TC0 second subfr. */ } ELSE { - limit_T0_fx( L_FRAME16k, 8, 0, limit_flag, T_op[1], 0, T0_min, T0_max ); /* TC0 third subfr., or TC64 third subfr. */ + limit_T0_fx( L_FRAME16k, 8, 0, limit_flag, T_op[1], 0, T0_min, T0_max ); /* TC0 third subfr., or TC64 third subfr. */ } } @@ -720,48 +709,48 @@ void transition_enc_fx( * get number of bits for pitch encoding *-----------------------------------------------------------------*/ - nBits = st_fx->acelp_cfg.pitch_bits[shr(i_subfr, 6)]; + nBits = st_fx->acelp_cfg.pitch_bits[shr( i_subfr, 6 )]; move16(); /*-----------------------------------------------------------------* * Find adaptive part of excitation, encode pitch period *-----------------------------------------------------------------*/ - IF( EQ_16(nBits,10)) + IF( EQ_16( nBits, 10 ) ) { *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, limit_flag, PIT16k_FR2_EXTEND_10b, PIT16k_MAX, st_fx->L_frame, L_SUBFR ); pit16k_Q_enc_fx( hBstr, nBits, limit_flag, *T0, *T0_frac, T0_min, T0_max ); } - ELSE IF( EQ_16(nBits,8)) /* tc_subfr==0 && i_subfr==L_SUBFR */ + ELSE IF( EQ_16( nBits, 8 ) ) /* tc_subfr==0 && i_subfr==L_SUBFR */ { /*-----------------------------------------------------------------------------* * The pitch range is encoded absolutely with 8 bits and is divided as follows: * PIT16k_MIN to PIT16k_FR2_TC0_2SUBFR-1 resolution 1/4 (frac = 0,1,2 or 3) * PIT16k_FR2_TC0_2SUBFR to 2*L_SUBFR resolution 1/2 (frac = 0 or 2) *-----------------------------------------------------------------------------*/ - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, limit_flag, PIT16k_FR2_TC0_2SUBFR, 2*L_SUBFR, st_fx->L_frame, L_SUBFR ); + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, limit_flag, PIT16k_FR2_TC0_2SUBFR, 2 * L_SUBFR, st_fx->L_frame, L_SUBFR ); - IF( GT_16(*T0_max,2*L_SUBFR)) + IF( GT_16( *T0_max, 2 * L_SUBFR ) ) { - *T0 = 2*L_SUBFR; + *T0 = 2 * L_SUBFR; move16(); *T0_frac = 0; move16(); } - IF( LT_16(*T0,PIT16k_FR2_TC0_2SUBFR )) + IF( LT_16( *T0, PIT16k_FR2_TC0_2SUBFR ) ) { /*index = (*T0)*4 + (*T0_frac) - (PIT16k_MIN*4);*/ - index = add(shl(*T0,2), sub(*T0_frac, PIT16k_MIN*4)); + index = add( shl( *T0, 2 ), sub( *T0_frac, PIT16k_MIN * 4 ) ); } ELSE { /*index = (*T0)*2 + ((*T0_frac)>>1) - (PIT16k_FR2_TC0_2SUBFR*2) + ((PIT16k_FR2_TC0_2SUBFR-PIT16k_MIN)*4);*/ - index = add(sub(add(shl(*T0,1), shr(*T0_frac,1)), (PIT16k_FR2_TC0_2SUBFR*2)), (PIT16k_FR2_TC0_2SUBFR-PIT16k_MIN)*4); + index = add( sub( add( shl( *T0, 1 ), shr( *T0_frac, 1 ) ), ( PIT16k_FR2_TC0_2SUBFR * 2 ) ), ( PIT16k_FR2_TC0_2SUBFR - PIT16k_MIN ) * 4 ); } push_indice_fx( hBstr, IND_PITCH, index, nBits ); } - ELSE IF( EQ_16(nBits,6)) + ELSE IF( EQ_16( nBits, 6 ) ) { /* delta search */ *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, L_SUBFR, limit_flag, PIT16k_FR2_EXTEND_9b, PIT16k_FR1_EXTEND_9b, st_fx->L_frame, L_SUBFR ); @@ -769,7 +758,7 @@ void transition_enc_fx( index = delta_pit_enc_fx( 4, *T0, *T0_frac, *T0_min ); push_indice_fx( hBstr, IND_PITCH, index, nBits ); } - IF( EQ_16(nBits,6)) + IF( EQ_16( nBits, 6 ) ) { limit_T0_fx( L_FRAME16k, 8, L_SUBFR, limit_flag, *T0, *T0_frac, T0_min, T0_max ); } @@ -780,7 +769,7 @@ void transition_enc_fx( * - codebook target computation *-----------------------------------------------------------------*/ test(); - IF( (EQ_16(i_subfr,L_SUBFR))&&(EQ_16(*T0,2*L_SUBFR))) + IF( ( EQ_16( i_subfr, L_SUBFR ) ) && ( EQ_16( *T0, 2 * L_SUBFR ) ) ) { *gain_pit_fx = 0; move16(); @@ -793,39 +782,39 @@ void transition_enc_fx( *Jopt_flag = 0; move16(); - set16_fx( &exc_fx[i_subfr], 0, L_SUBFR+1 ); /* set excitation for current subrame to 0 */ - push_indice_fx( hBstr, IND_LP_FILT_SELECT, 0, 1 ); /* this bit is actually not needed */ + set16_fx( &exc_fx[i_subfr], 0, L_SUBFR + 1 ); /* set excitation for current subrame to 0 */ + push_indice_fx( hBstr, IND_LP_FILT_SELECT, 0, 1 ); /* this bit is actually not needed */ - Copy( xn_fx, xn2_fx, L_SUBFR ); /* target vector for codebook search */ - set16_fx( y1_fx, 0, L_SUBFR ); /* set filtered adaptive excitation to 0 */ + Copy( xn_fx, xn2_fx, L_SUBFR ); /* target vector for codebook search */ + set16_fx( y1_fx, 0, L_SUBFR ); /* set filtered adaptive excitation to 0 */ set16_fx( &bwe_exc_fx[i_subfr * 2], 0, L_SUBFR * 2 ); } ELSE { /* Find the adaptive codebook vector - ACELP long-term prediction */ - pred_lt4(&exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR+1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP); - offset = L_deposit_l(0); + pred_lt4( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + offset = L_deposit_l( 0 ); - tmp = extract_l(L_mult(*T0_frac,32));/*Q8, 0.25 in Q7*/ - tmp = add(512,tmp);/*Q8; 2 in Q8*/ - tmp = mult_r(tmp,256);/*Q16->Q0; 2 in Q7*/ + tmp = extract_l( L_mult( *T0_frac, 32 ) ); /*Q8, 0.25 in Q7*/ + tmp = add( 512, tmp ); /*Q8; 2 in Q8*/ + tmp = mult_r( tmp, 256 ); /*Q16->Q0; 2 in Q7*/ - tmp1 = sub(*T0,2);/*Q0*/ - tmp1 = shl(tmp1,1);/*Q0 */ + tmp1 = sub( *T0, 2 ); /*Q0*/ + tmp1 = shl( tmp1, 1 ); /*Q0 */ - offset = add(tmp,tmp1);/*Q0*/ - FOR (i=0; ielement_mode, st_fx->core_brate, st_fx->voicing_fx, i_subfr, TRANSITION, xn_fx, gp_cl_fx,Q_new ); + *clip_gain = gp_clip_fx( st_fx->element_mode, st_fx->core_brate, st_fx->voicing_fx, i_subfr, TRANSITION, xn_fx, gp_cl_fx, Q_new ); lp_select = lp_filt_exc_enc_fx( MODE1, TRANSITION, i_subfr, exc_fx, h1_fx, - xn_fx, y1_fx, xn2_fx, L_SUBFR, st_fx->L_frame, g_corr_fx, *clip_gain, gain_pit_fx, &lp_flag ); + xn_fx, y1_fx, xn2_fx, L_SUBFR, st_fx->L_frame, g_corr_fx, *clip_gain, gain_pit_fx, &lp_flag ); - IF( EQ_16(lp_flag,NORMAL_OPERATION)) + IF( EQ_16( lp_flag, NORMAL_OPERATION ) ) { push_indice_fx( hBstr, IND_LP_FILT_SELECT, lp_select, 1 ); } @@ -834,9 +823,9 @@ void transition_enc_fx( move16(); } - /***pt_pitch = (float)(*T0) + (float)(*T0_frac)/4.0f;*/ /* save subframe pitch value */ + /***pt_pitch = (float)(*T0) + (float)(*T0_frac)/4.0f;*/ /* save subframe pitch value */ /***pt_pitch_fx = shl(add(*T0,shr(*T0_frac,2)),4); move16();*/ - tmp = shl(add(shl(*T0,2),*T0_frac),4); + tmp = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); **pt_pitch_fx = tmp; move16(); @@ -845,17 +834,17 @@ void transition_enc_fx( *---------------------------------------------------------------------*/ test(); test(); - IF( (EQ_16(sub(i_subfr, *tc_subfr),L_SUBFR))||(*tc_subfr==0&&EQ_16(i_subfr,2*L_SUBFR))) + IF( ( EQ_16( sub( i_subfr, *tc_subfr ), L_SUBFR ) ) || ( *tc_subfr == 0 && EQ_16( i_subfr, 2 * L_SUBFR ) ) ) { - index = shr(i_subfr,6); - (*pt_pitch_fx) -= index; + index = shr( i_subfr, 6 ); + ( *pt_pitch_fx ) -= index; move16(); - FOR( i=0; i|| | imp_shape->| g1 | | - * | | | | g2 | ---- exc |---| y1 ---- | - * | | |-------------| |----|gain|-------| h |------|gain|----(-)---> xn2 - * | || | gn | ---- |---| ---- - * |----| |----| - * codebook excitation gain_trans h_orig gain_pit - * - *-------------------------------------------------------------------------------------------*/ + * tc_enc() + * + * Principal function for transition coding (TC) in encoder. + * Glottal codebook contribution part: + * + * |----| |----| xn + * imp_pos->|| | imp_shape->| g1 | | + * | | | | g2 | ---- exc |---| y1 ---- | + * | | |-------------| |----|gain|-------| h |------|gain|----(-)---> xn2 + * | || | gn | ---- |---| ---- + * |----| |----| + * codebook excitation gain_trans h_orig gain_pit + * + *-------------------------------------------------------------------------------------------*/ static void tc_enc_fx( - Encoder_State *st_fx,/* i/o: encoder state structure */ - const Word16 i_subfr, /* i : subrame index */ - Word16 *tc_subfr, /* i/o: TC subframe index */ - Word16 *position, /* i/o: index of the residual signal maximum */ - const Word16 *h1_fx, /* i : weighted filter input response Q(14+shift)*/ - const Word16 *xn_fx, /* i : target signal Q_new-1+shift*/ - Word16 *exc_fx, /* o : glottal codebook contribution Q_new*/ - Word16 *yy1_fx, /* o : filtered glottal codebook contribution */ - Word16 *T0_min, /* o : lower pitch limit Q0*/ - Word16 *T0_max, /* o : higher pitch limit Q0*/ - Word16 *T0, /* o : close loop integer pitch Q0*/ - Word16 *T0_frac, /* o : close loop fractional part of the pitch Q0*/ - Word16 *gain_pit_fx, /* o : pitch gain (0..GAIN_PIT_MAX) Q14*/ - Word16 g_corr_fx[], /* o : correlations and -2 */ - Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE Q_new*/ - Word16 Q_new /* i : input scaling */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word16 i_subfr, /* i : subrame index */ + Word16 *tc_subfr, /* i/o: TC subframe index */ + Word16 *position, /* i/o: index of the residual signal maximum */ + const Word16 *h1_fx, /* i : weighted filter input response Q(14+shift)*/ + const Word16 *xn_fx, /* i : target signal Q_new-1+shift*/ + Word16 *exc_fx, /* o : glottal codebook contribution Q_new*/ + Word16 *yy1_fx, /* o : filtered glottal codebook contribution */ + Word16 *T0_min, /* o : lower pitch limit Q0*/ + Word16 *T0_max, /* o : higher pitch limit Q0*/ + Word16 *T0, /* o : close loop integer pitch Q0*/ + Word16 *T0_frac, /* o : close loop fractional part of the pitch Q0*/ + Word16 *gain_pit_fx, /* o : pitch gain (0..GAIN_PIT_MAX) Q14*/ + Word16 g_corr_fx[], /* o : correlations and -2 */ + Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE Q_new*/ + Word16 Q_new /* i : input scaling */ ) { - Word16 i,imp_shape, imp_pos, index, nBits, h1_tmp_fx[L_SUBFR]; - Word16 pitch_index,pitch_sign_fx; + Word16 i, imp_shape, imp_pos, index, nBits, h1_tmp_fx[L_SUBFR]; + Word16 pitch_index, pitch_sign_fx; Word32 gain_trans32; BSTR_ENC_HANDLE hBstr = st_fx->hBstr; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - imp_pos = sub(*position, i_subfr); - FOR (i = 0; i < L_SUBFR; i++) + imp_pos = sub( *position, i_subfr ); + FOR( i = 0; i < L_SUBFR; i++ ) { h1_tmp_fx[i] = h1_fx[i]; move16(); @@ -916,7 +905,7 @@ static void tc_enc_fx( * get number of bits for pitch encoding *-----------------------------------------------------------------*/ - nBits = st_fx->acelp_cfg.pitch_bits[shr(i_subfr, 6)]; + nBits = st_fx->acelp_cfg.pitch_bits[shr( i_subfr, 6 )]; /*--------------------------------------------------------------* * Closed loop pitch search @@ -925,16 +914,16 @@ static void tc_enc_fx( *T0_frac = 0; move16(); - IF( EQ_16(st_fx->L_frame,L_FRAME)) + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { test(); - IF( (LE_16(*T0_min,L_SUBFR))||(EQ_16(*tc_subfr,3*L_SUBFR))) + IF( ( LE_16( *T0_min, L_SUBFR ) ) || ( EQ_16( *tc_subfr, 3 * L_SUBFR ) ) ) { - IF( EQ_16(nBits,9)) + IF( EQ_16( nBits, 9 ) ) { *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, 0, PIT_FR2_9b, PIT_FR1_9b, L_FRAME, L_SUBFR ); } - ELSE IF( EQ_16(nBits,6)) + ELSE IF( EQ_16( nBits, 6 ) ) { *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, 0, PIT_MIN, L_SUBFR, L_FRAME, L_SUBFR ); } @@ -949,19 +938,19 @@ static void tc_enc_fx( move16(); } test(); - if( EQ_16(*tc_subfr,L_SUBFR)&<_16(*T0,L_SUBFR)) + if ( EQ_16( *tc_subfr, L_SUBFR ) && LT_16( *T0, L_SUBFR ) ) { *T0 = L_SUBFR; move16(); } } - ELSE /* st_fx->L_frame == L_FRAME16k */ + ELSE /* st_fx->L_frame == L_FRAME16k */ { - IF( EQ_16(nBits,10)) + IF( EQ_16( nBits, 10 ) ) { *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, 1, PIT16k_FR2_EXTEND_10b, PIT16k_MAX, L_FRAME16k, L_SUBFR ); } - ELSE IF( EQ_16(nBits,6)) + ELSE IF( EQ_16( nBits, 6 ) ) { /* T0_frac with 1/2 sample resolution */ *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, 0, PIT16k_MIN, L_SUBFR, L_FRAME16k, L_SUBFR ); @@ -980,7 +969,7 @@ static void tc_enc_fx( test(); test(); test(); - if( i_subfr == 0 && EQ_16(st_fx->L_frame,L_FRAME)&&(LT_16(*T0,L_SUBFR)||EQ_16(*tc_subfr,3*L_SUBFR))) + if ( i_subfr == 0 && EQ_16( st_fx->L_frame, L_FRAME ) && ( LT_16( *T0, L_SUBFR ) || EQ_16( *tc_subfr, 3 * L_SUBFR ) ) ) { *tc_subfr = TC_0_0; move16(); @@ -990,7 +979,7 @@ static void tc_enc_fx( * Builds glottal codebook contribution *--------------------------------------------------------------*/ - set_impulse_fx(xn_fx, h1_tmp_fx, &exc_fx[i_subfr], yy1_fx, &imp_shape, &imp_pos, &gain_trans32, Q_new);/*chk h1_tmp_fx*/ + set_impulse_fx( xn_fx, h1_tmp_fx, &exc_fx[i_subfr], yy1_fx, &imp_shape, &imp_pos, &gain_trans32, Q_new ); /*chk h1_tmp_fx*/ /*--------------------------------------------------------------* * quantize gain_trans and scale glottal codebook contribution @@ -999,22 +988,22 @@ static void tc_enc_fx( gain_trans_enc_fx( gain_trans32, &exc_fx[i_subfr], &pitch_index, &pitch_sign_fx, Q_new ); /* set past excitation buffer to zeros */ - set16_fx( exc_fx-L_EXC_MEM, 0, L_EXC_MEM ); + set16_fx( exc_fx - L_EXC_MEM, 0, L_EXC_MEM ); /*--------------------------------------------------------------* * adapt. search of the second impulse in the same subframe * (when appears) *--------------------------------------------------------------*/ pred_lt4_tc_fx( exc_fx, *T0, *T0_frac, inter4_2_fx, imp_pos, i_subfr ); - IF (st_fx->hBWE_TD != NULL) + IF( st_fx->hBWE_TD != NULL ) { - IF(EQ_16(st_fx->L_frame, L_FRAME)) + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { - interp_code_5over2_fx(&exc_fx[i_subfr], &bwe_exc_fx[i_subfr * HIBND_ACB_L_FAC], L_SUBFR); + interp_code_5over2_fx( &exc_fx[i_subfr], &bwe_exc_fx[i_subfr * HIBND_ACB_L_FAC], L_SUBFR ); } ELSE { - interp_code_4over2_fx(&exc_fx[i_subfr], &bwe_exc_fx[i_subfr * 2], L_SUBFR); + interp_code_4over2_fx( &exc_fx[i_subfr], &bwe_exc_fx[i_subfr * 2], L_SUBFR ); } } /*--------------------------------------------------------------* @@ -1033,22 +1022,21 @@ static void tc_enc_fx( /*--------------------------------------------------------------* * Encode parameters and write indices *--------------------------------------------------------------*/ - IF( EQ_16(st_fx->L_frame,L_FRAME)) + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { test(); test(); - IF( ( (i_subfr != 0) || (EQ_16(*tc_subfr,TC_0_0))) - && (NE_16(*tc_subfr,L_SUBFR) )) + IF( ( ( i_subfr != 0 ) || ( EQ_16( *tc_subfr, TC_0_0 ) ) ) && ( NE_16( *tc_subfr, L_SUBFR ) ) ) { test(); /* write pitch index */ - IF( (GE_16(*T0,L_SUBFR))&&(NE_16(*tc_subfr,3*L_SUBFR))) + IF( ( GE_16( *T0, L_SUBFR ) ) && ( NE_16( *tc_subfr, 3 * L_SUBFR ) ) ) { push_indice_fx( hBstr, IND_PITCH, 0, nBits ); } - ELSE IF( EQ_16(*tc_subfr,3*L_SUBFR)) + ELSE IF( EQ_16( *tc_subfr, 3 * L_SUBFR ) ) { - IF( EQ_16(nBits,9)) + IF( EQ_16( nBits, 9 ) ) { index = abs_pit_enc_fx( 4, 0, *T0, *T0_frac ); } @@ -1062,28 +1050,28 @@ static void tc_enc_fx( } ELSE { - IF( EQ_16(nBits,6)) + IF( EQ_16( nBits, 6 ) ) { - index = delta_pit_enc_fx( 2, *T0, *T0_frac, PIT_MIN-1 ); + index = delta_pit_enc_fx( 2, *T0, *T0_frac, PIT_MIN - 1 ); push_indice_fx( hBstr, IND_PITCH, index, nBits ); } ELSE { - index = delta_pit_enc_fx( 0, *T0, *T0_frac, PIT_MIN-1 ); + index = delta_pit_enc_fx( 0, *T0, *T0_frac, PIT_MIN - 1 ); push_indice_fx( hBstr, IND_PITCH, index, nBits ); } } } } - ELSE /* st_fx->L_frame == L_FRAME16k */ + ELSE /* st_fx->L_frame == L_FRAME16k */ { - IF( EQ_16(nBits,10)) + IF( EQ_16( nBits, 10 ) ) { pit16k_Q_enc_fx( hBstr, nBits, 1, *T0, *T0_frac, T0_min, T0_max ); } - ELSE IF( EQ_16(nBits,6)) + ELSE IF( EQ_16( nBits, 6 ) ) { - index = add(shl(sub(*T0,PIT16k_MIN),1) , shr(*T0_frac,1)); + index = add( shl( sub( *T0, PIT16k_MIN ), 1 ), shr( *T0_frac, 1 ) ); push_indice_fx( hBstr, IND_PITCH, index, nBits ); } } @@ -1092,7 +1080,7 @@ static void tc_enc_fx( push_indice_fx( hBstr, IND_TC_IMP_SIGN, pitch_sign_fx, 1 ); push_indice_fx( hBstr, IND_TC_IMP_GAIN, pitch_index, 3 ); - *position = add(imp_pos, i_subfr); + *position = add( imp_pos, i_subfr ); move16(); return; } @@ -1106,11 +1094,11 @@ static void tc_enc_fx( * - Gains the glottal codebook contibution signal. *-----------------------------------------------------------------*/ static void gain_trans_enc_fx( - Word32 gain_trans32, /* i : gain for mode Tc Q7 */ - Word16 exc[], /* i/o: glottal codebook contribution i:Q13 o:Q_new*gain_trans */ - Word16 *quant_index, /* o : index of quantized gain_trans */ - Word16 *quant_sign, /* o : sign of quantized gain_trans */ - Word16 Q_new /* i : curent scaling */ + Word32 gain_trans32, /* i : gain for mode Tc Q7 */ + Word16 exc[], /* i/o: glottal codebook contribution i:Q13 o:Q_new*gain_trans */ + Word16 *quant_index, /* o : index of quantized gain_trans */ + Word16 *quant_sign, /* o : sign of quantized gain_trans */ + Word16 Q_new /* i : curent scaling */ ) { Word16 i, imax, istart, tmp16, gain_trans, gscale; @@ -1125,38 +1113,38 @@ static void gain_trans_enc_fx( gscale = 7; move16(); #ifdef BASOP_NOGLOB - gain_trans = extract_h(L_shl_o(gain_trans32,16, &Overflow)); /* Q7 */ -#else /* BASOP_NOGLOB */ - gain_trans = extract_h(L_shl(gain_trans32,16)); /* Q7 */ -#endif /* BASOP_NOGLOB */ + gain_trans = extract_h( L_shl_o( gain_trans32, 16, &Overflow ) ); /* Q7 */ +#else /* BASOP_NOGLOB */ + gain_trans = extract_h( L_shl( gain_trans32, 16 ) ); /* Q7 */ +#endif /* BASOP_NOGLOB */ - IF (GT_32(L_abs(gain_trans32), 29862L)) + IF( GT_32( L_abs( gain_trans32 ), 29862L ) ) { #ifdef BASOP_NOGLOB - gain_trans = extract_h(L_shl_o(gain_trans32,16-3, &Overflow)); /* Q4 */ -#else /* BASOP_NOGLOB */ - gain_trans = extract_h(L_shl(gain_trans32,16-3)); /* Q4 */ -#endif /* BASOP_NOGLOB */ + gain_trans = extract_h( L_shl_o( gain_trans32, 16 - 3, &Overflow ) ); /* Q4 */ +#else /* BASOP_NOGLOB */ + gain_trans = extract_h( L_shl( gain_trans32, 16 - 3 ) ); /* Q4 */ +#endif /* BASOP_NOGLOB */ istart = 4; move16(); - imax = N_GAIN_TC-1; + imax = N_GAIN_TC - 1; move16(); gscale = 4; move16(); } /* qsign = 0 if *gain_trans < 0 else qsign = 1*/ - tmp16 = shr(gain_trans,16); - *quant_sign = add(1, tmp16); - move16();/* quantize sign */ - tmp16 = s_or(tmp16, 1); /* Keep sign */ - gain_trans = abs_s(gain_trans); + tmp16 = shr( gain_trans, 16 ); + *quant_sign = add( 1, tmp16 ); + move16(); /* quantize sign */ + tmp16 = s_or( tmp16, 1 ); /* Keep sign */ + gain_trans = abs_s( gain_trans ); - *quant_index = N_GAIN_TC-1; + *quant_index = N_GAIN_TC - 1; move16(); - FOR (i = istart; i < imax; i++) + FOR( i = istart; i < imax; i++ ) { - IF (LE_16(gain_trans,tbl_gain_trans_tc_fx[i])) + IF( LE_16( gain_trans, tbl_gain_trans_tc_fx[i] ) ) { *quant_index = i; move16(); @@ -1164,15 +1152,15 @@ static void gain_trans_enc_fx( } } - gain_trans = i_mult2(tbl_gain_trans_tc_fx[i], tmp16); /* Retreive quantized gain with sign */ - tmp16 = sub(Q_new,add(gscale,13-16+1)); /*remove 16 from rounding */ - FOR (i = 0; i < L_SUBFR; i++) + gain_trans = i_mult2( tbl_gain_trans_tc_fx[i], tmp16 ); /* Retreive quantized gain with sign */ + tmp16 = sub( Q_new, add( gscale, 13 - 16 + 1 ) ); /*remove 16 from rounding */ + FOR( i = 0; i < L_SUBFR; i++ ) { /*exc[i] *= (*gain_trans);*/ #ifdef BASOP_NOGLOB - exc[i] = round_fx_o(L_shl_o(L_mult(exc[i], gain_trans),tmp16, &Overflow), &Overflow); -#else - exc[i] = round_fx(L_shl(L_mult(exc[i], gain_trans),tmp16)); + exc[i] = round_fx_o( L_shl_o( L_mult( exc[i], gain_trans ), tmp16, &Overflow ), &Overflow ); +#else + exc[i] = round_fx( L_shl( L_mult( exc[i], gain_trans ), tmp16 ) ); #endif } } @@ -1186,11 +1174,11 @@ static void gain_trans_enc_fx( void tc_classif_enc_fx( const Word16 Q_new, /* i : scaling factor */ const Word16 L_frame, /* i : length of the frame */ - Word16* tc_subfr, /* o : TC subframe index */ - Word16* position, /* o : maximum of residual signal index */ + Word16 *tc_subfr, /* o : TC subframe index */ + Word16 *position, /* o : maximum of residual signal index */ const Word16 attack_flag, /* i : attack flag */ const Word16 pitch, /* i : open loop pitch estimates for first halfframe */ - const Word16* res /* i : pointer to the LP residual signal frame */ + const Word16 *res /* i : pointer to the LP residual signal frame */ ) { Word32 temp; @@ -1202,39 +1190,39 @@ void tc_classif_enc_fx( T_op = pitch; move16(); - IF ( EQ_16(L_frame, L_FRAME16k) ) + IF( EQ_16( L_frame, L_FRAME16k ) ) { /*T_op = (int16_t)(pitch * 1.25f + 0.5f);*/ - T_op = add(pitch, mult_r(pitch, 8192)); + T_op = add( pitch, mult_r( pitch, 8192 ) ); } *tc_subfr = -1; move16(); - IF (attack_flag) + IF( attack_flag ) { *tc_subfr = 3 * L_SUBFR; move16(); - IF (attack_flag > 0) + IF( attack_flag > 0 ) { - IF (EQ_16(L_frame, L_FRAME)) + IF( EQ_16( L_frame, L_FRAME ) ) { - /* *tc_subfr = NB_SUBFR * (attack_flag - 1) / 32 ; ATT_NSEG == 32*/ - *tc_subfr = mult(i_mult(NB_SUBFR, sub(attack_flag, 1)), 1024) ; /* divide by 32 Q15*/ - move16(); + /* *tc_subfr = NB_SUBFR * (attack_flag - 1) / 32 ; ATT_NSEG == 32*/ + *tc_subfr = mult( i_mult( NB_SUBFR, sub( attack_flag, 1 ) ), 1024 ); /* divide by 32 Q15*/ + move16(); } ELSE { /* *tc_subfr = NB_SUBFR16k * (attack_flag - 1) / 32 ; */ - *tc_subfr = mult(i_mult(NB_SUBFR16k, sub(attack_flag, 1)), 1024); /* divide by 32 Q15*/ + *tc_subfr = mult( i_mult( NB_SUBFR16k, sub( attack_flag, 1 ) ), 1024 ); /* divide by 32 Q15*/ move16(); } /* *tc_subfr *= L_SUBFR; */ - *tc_subfr = i_mult(*tc_subfr, L_SUBFR); + *tc_subfr = i_mult( *tc_subfr, L_SUBFR ); move16(); } } - IF (attack_flag) + IF( attack_flag ) { /*-----------------------------------------------------------------* * TC: subrame determination for glottal shape search @@ -1247,59 +1235,59 @@ void tc_classif_enc_fx( *-----------------------------------------------------------------*/ /** position = emaximum(res + *tc_subfr, min(T_op + 2, L_SUBFR), &temp) + *tc_subfr;*/ - *position = add(emaximum_fx(Q_new, res + *tc_subfr, s_min(add(T_op, 2), L_SUBFR), &temp), *tc_subfr); + *position = add( emaximum_fx( Q_new, res + *tc_subfr, s_min( add( T_op, 2 ), L_SUBFR ), &temp ), *tc_subfr ); move16(); } ELSE { - *position = emaximum_fx(Q_new, res, add(T_op,2), &temp); + *position = emaximum_fx( Q_new, res, add( T_op, 2 ), &temp ); /* correction in case of possibly wrong T_op (double-pitch values) */ test(); test(); test(); - IF((EQ_16(L_frame,L_FRAME) && GT_16(T_op,2 * PIT_MIN)) || (EQ_16(L_frame,L_FRAME16k) && GT_16(T_op,2 * PIT16k_MIN)) ) + IF( ( EQ_16( L_frame, L_FRAME ) && GT_16( T_op, 2 * PIT_MIN ) ) || ( EQ_16( L_frame, L_FRAME16k ) && GT_16( T_op, 2 * PIT16k_MIN ) ) ) { Word16 position_tmp, len, exp_aver = 0, exp = 0, exp2 = 0; Word32 aver, temp2, L_sum, L_temp1, L_temp2; - len = add(shr(T_op,1), 2); - position_tmp = emaximum_fx(Q_new, res, len, &temp2); -#ifdef BASOP_NOGLOB + len = add( shr( T_op, 1 ), 2 ); + position_tmp = emaximum_fx( Q_new, res, len, &temp2 ); +#ifdef BASOP_NOGLOB L_sum = L_mac_sat( 1L, res[0], res[0] ); #else - L_sum = L_mac(1L, res[0], res[0]); + L_sum = L_mac( 1L, res[0], res[0] ); #endif - FOR(i = 1; i < len; i++) + FOR( i = 1; i < len; i++ ) { #ifdef BASOP_NOGLOB - L_sum = L_mac0_o(L_sum, res[i], res[i], &Overflow); -#else /* BASOP_NOGLOB */ - L_sum = L_mac0(L_sum, res[i], res[i]); + L_sum = L_mac0_o( L_sum, res[i], res[i], &Overflow ); +#else /* BASOP_NOGLOB */ + L_sum = L_mac0( L_sum, res[i], res[i] ); #endif /* BASOP_NOGLOB */ } - aver = L_sum; /*Q = 2*Q_new */ - aver = root_a_over_b_fx(aver, 2 * Q_new, L_shl(len,15), 15, &exp_aver); /*Q = 31-exp_aver*/ + aver = L_sum; /*Q = 2*Q_new */ + aver = root_a_over_b_fx( aver, 2 * Q_new, L_shl( len, 15 ), 15, &exp_aver ); /*Q = 31-exp_aver*/ - temp = root_a_fx(temp, 0, &exp); /* Q=31-exp */ - temp2 = root_a_fx(temp2, 0, &exp2); /* Q=31-exp2 */ + temp = root_a_fx( temp, 0, &exp ); /* Q=31-exp */ + temp2 = root_a_fx( temp2, 0, &exp2 ); /* Q=31-exp2 */ - L_temp2 = Mult_32_16(temp, 26214); /* Q=31-exp */ - L_temp1 = Mult_32_16(temp, 8192); /* Q=31-exp */ + L_temp2 = Mult_32_16( temp, 26214 ); /* Q=31-exp */ + L_temp1 = Mult_32_16( temp, 8192 ); /* Q=31-exp */ test(); #ifdef BASOP_NOGLOB - IF(GT_32(temp2, L_shl_o(L_temp2,(31 - exp2) - (31 - exp), &Overflow)) && - LT_32(aver, L_shl_o(L_temp1,(31 - exp_aver) - (31 - exp), &Overflow))) + IF( GT_32( temp2, L_shl_o( L_temp2, ( 31 - exp2 ) - ( 31 - exp ), &Overflow ) ) && + LT_32( aver, L_shl_o( L_temp1, ( 31 - exp_aver ) - ( 31 - exp ), &Overflow ) ) ) #else /* BASOP_NOGLOB */ - IF(GT_32(temp2, L_shl(L_temp2,(31 - exp2) - (31 - exp))) && - LT_32(aver, L_shl(L_temp1,(31 - exp_aver) - (31 - exp)))) + IF( GT_32( temp2, L_shl( L_temp2, ( 31 - exp2 ) - ( 31 - exp ) ) ) && + LT_32( aver, L_shl( L_temp1, ( 31 - exp_aver ) - ( 31 - exp ) ) ) ) #endif { *position = position_tmp; } } - *tc_subfr = s_and(*position, 0x7FC0); + *tc_subfr = s_and( *position, 0x7FC0 ); move16(); } diff --git a/lib_enc/update_decision_fx.c b/lib_enc/update_decision_fx.c index 77f4619c1..935165d37 100644 --- a/lib_enc/update_decision_fx.c +++ b/lib_enc/update_decision_fx.c @@ -8,19 +8,19 @@ #include "basop_util.h" #include "vad_basop.h" //#include "prot_fx.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ -/*-------------------------------------------------------------------* - * bg_music_decision_fx() - * - * - * -------------------------------------------------------------------*/ - void bg_music_decision_fx( - VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ - Word16 *music_backgound_f, /* i : background music flag*/ - Word32 frame_energy, /* i : current frame energy 1*/ - Word16 frame_energy_Q /* i : the Scaling of current frame energy*/ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ + /*-------------------------------------------------------------------* + * bg_music_decision_fx() + * + * + * -------------------------------------------------------------------*/ +void bg_music_decision_fx( + VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ + Word16 *music_backgound_f, /* i : background music flag*/ + Word32 frame_energy, /* i : current frame energy 1*/ + Word16 frame_energy_Q /* i : the Scaling of current frame energy*/ ) { @@ -38,81 +38,73 @@ music_background_frame = 0; - move32(); - tmp1 = L_mult(hVAD_CLDFB->fg_energy_count,18842); - tmp1_Q = norm_l(tmp1); - tmp1 = L_shl(tmp1,tmp1_Q); - tmp_norm = extract_h(tmp1); - frame_energy_Mcount = MUL_F(frame_energy,tmp_norm); + move32(); + tmp1 = L_mult( hVAD_CLDFB->fg_energy_count, 18842 ); + tmp1_Q = norm_l( tmp1 ); + tmp1 = L_shl( tmp1, tmp1_Q ); + tmp_norm = extract_h( tmp1 ); + frame_energy_Mcount = MUL_F( frame_energy, tmp_norm ); - fg_energy_Qtmp = sub(frame_energy_Q, 18); - fg_energy_Qtmp = add(fg_energy_Qtmp, tmp1_Q); + fg_energy_Qtmp = sub( frame_energy_Q, 18 ); + fg_energy_Qtmp = add( fg_energy_Qtmp, tmp1_Q ); - cmp_result = VAD_L_CMP(frame_energy_Mcount,fg_energy_Qtmp,hVAD_CLDFB->fg_energy,hVAD_CLDFB->fg_energy_scale); + cmp_result = VAD_L_CMP( frame_energy_Mcount, fg_energy_Qtmp, hVAD_CLDFB->fg_energy, hVAD_CLDFB->fg_energy_scale ); test(); - IF((GT_16(f_tonality_rate[1],9830/* 0.6 Q14 */)) - ||(GT_16(f_tonality_rate[0],14089/* 0.86 Q14 */))) + IF( ( GT_16( f_tonality_rate[1], 9830 /* 0.6 Q14 */ ) ) || ( GT_16( f_tonality_rate[0], 14089 /* 0.86 Q14 */ ) ) ) { test(); test(); test(); test(); - if((LT_16(ltd_stable_rate[0], 2359/* 0.072 Q15 */)) - &&(GT_16(sp_center[0],1228/* 1.2 Q10 */)) - &&((LT_16(sSFM[0],24903/* 0.76 Q15 */)) - ||(LT_16(sSFM[1],28835/* 0.88 Q15 */)) - ||(LT_16(sSFM[2],31456/* 0.96 Q15 */)))) + if ( ( LT_16( ltd_stable_rate[0], 2359 /* 0.072 Q15 */ ) ) && ( GT_16( sp_center[0], 1228 /* 1.2 Q10 */ ) ) && ( ( LT_16( sSFM[0], 24903 /* 0.76 Q15 */ ) ) || ( LT_16( sSFM[1], 28835 /* 0.88 Q15 */ ) ) || ( LT_16( sSFM[2], 31456 /* 0.96 Q15 */ ) ) ) ) { music_background_frame = 1; - move32(); + move32(); } } test(); test(); - IF(music_background_frame - &&(cmp_result > 0) - &&(EQ_32(hVAD_CLDFB->fg_energy_est_start,1))) + IF( music_background_frame && ( cmp_result > 0 ) && ( EQ_32( hVAD_CLDFB->fg_energy_est_start, 1 ) ) ) { - hVAD_CLDFB->music_background_rate = add(mult(hVAD_CLDFB->music_background_rate,31949), 819); + hVAD_CLDFB->music_background_rate = add( mult( hVAD_CLDFB->music_background_rate, 31949 ), 819 ); move16(); } - ELSE IF(music_background_frame) + ELSE IF( music_background_frame ) { - hVAD_CLDFB->music_background_rate = add(mult(hVAD_CLDFB->music_background_rate,32702), 66); + hVAD_CLDFB->music_background_rate = add( mult( hVAD_CLDFB->music_background_rate, 32702 ), 66 ); move16(); } ELSE { - hVAD_CLDFB->music_background_rate = mult(hVAD_CLDFB->music_background_rate,32670); + hVAD_CLDFB->music_background_rate = mult( hVAD_CLDFB->music_background_rate, 32670 ); move16(); } *music_backgound_f = 0; move16(); - if(GT_16(hVAD_CLDFB->music_background_rate, 16384)) + if ( GT_16( hVAD_CLDFB->music_background_rate, 16384 ) ) { *music_backgound_f = 1; move16(); } - } - /*-------------------------------------------------------------------* - * update_decision_fx() - * - * - *-------------------------------------------------------------------*/ +/*-------------------------------------------------------------------* + * update_decision_fx() + * + * + *-------------------------------------------------------------------*/ Word16 update_decision_fx( - VAD_CLDFB_HANDLE_FX hVAD_CLDFB ,/* i/o: CLDFB VAD state */ + VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ const Word32 frame_energy, /* i : current frame energy*/ - Word32 HB_Power, /* i : current frame high frequency energy*/ + Word32 HB_Power, /* i : current frame high frequency energy*/ const Word16 frameloop, /* i : amount of frames*/ const Word16 bw, /* i : band width index*/ const Word16 frame_energy_Q, /* i : the Scaling of current frame energy*/ - const Word16 HB_Power_Q, /* i : the Scaling of current frame high frequency energy*/ + const Word16 HB_Power_Q, /* i : the Scaling of current frame high frequency energy*/ const Word32 snr, /* i : frequency domain SNR */ const Word32 tsnr, /* i : time domain SNR */ const Word16 vad_flag, /* i : VAD flag */ @@ -139,7 +131,7 @@ Word16 update_decision_fx( Word16 Q_counter; Word16 Q_sum; - Word32 sum_num,counter_den; + Word32 sum_num, counter_den; Word16 div_r; Word16 div_r_Q; @@ -151,47 +143,47 @@ Word16 update_decision_fx( tonality_flag = 0; move16(); - lt_bg_highf_eng_trbl = MUL_F(hVAD_CLDFB->lt_bg_highf_eng,24576); - IF (GT_16(14,HB_Power_Q)) + lt_bg_highf_eng_trbl = MUL_F( hVAD_CLDFB->lt_bg_highf_eng, 24576 ); + IF( GT_16( 14, HB_Power_Q ) ) { - lt_bg_highf_eng_trbl = L_shr(lt_bg_highf_eng_trbl,sub(14,HB_Power_Q)); + lt_bg_highf_eng_trbl = L_shr( lt_bg_highf_eng_trbl, sub( 14, HB_Power_Q ) ); } ELSE { - HB_Power = L_shr(HB_Power, s_min(31, sub(HB_Power_Q, 14))); + HB_Power = L_shr( HB_Power, s_min( 31, sub( HB_Power_Q, 14 ) ) ); } flag_high_eng = 0; move16(); - if (GT_32(HB_Power,lt_bg_highf_eng_trbl)) + if ( GT_32( HB_Power, lt_bg_highf_eng_trbl ) ) { flag_high_eng = 1; move16(); } - sp_center3_diff = sub(sp_center[3], hVAD_CLDFB->lt_noise_sp_center3); + sp_center3_diff = sub( sp_center[3], hVAD_CLDFB->lt_noise_sp_center3 ); - IF(sub(frameloop, 50) > 0) + IF( sub( frameloop, 50 ) > 0 ) { - if(GT_16(ltd_stable_rate[0],3932/* 0.12 Q15 */)) + if ( GT_16( ltd_stable_rate[0], 3932 /* 0.12 Q15 */ ) ) { update_flag = 0; move16(); } - tmpout= VAD_L_CMP(frame_energy, sub(frame_energy_Q,2), hVAD_CLDFB->frame_energy_smooth,hVAD_CLDFB->frame_energy_smooth_scale); + tmpout = VAD_L_CMP( frame_energy, sub( frame_energy_Q, 2 ), hVAD_CLDFB->frame_energy_smooth, hVAD_CLDFB->frame_energy_smooth_scale ); test(); - IF((NE_16(bw, CLDFBVAD_NB_ID))&&tmpout>0) + IF( ( NE_16( bw, CLDFBVAD_NB_ID ) ) && tmpout > 0 ) { test(); - if((flag_high_eng) && (GT_16(sp_center3_diff, 409))) + if ( ( flag_high_eng ) && ( GT_16( sp_center3_diff, 409 ) ) ) { update_flag = 0; move16(); } test(); - if((GT_16(sp_center[3],2864/* 2.8 Q10 */))&&(GT_16(ltd_stable_rate[0],655/* 0.02 Q15 */))) + if ( ( GT_16( sp_center[3], 2864 /* 2.8 Q10 */ ) ) && ( GT_16( ltd_stable_rate[0], 655 /* 0.02 Q15 */ ) ) ) { update_flag = 0; move16(); @@ -200,8 +192,7 @@ Word16 update_decision_fx( } test(); - if((GT_16(f_tonality_rate[1], 8192/* 0.5 Q14 */)) - && (GT_16(ltd_stable_rate[0],3277/* 0.1 Q15 */))) + if ( ( GT_16( f_tonality_rate[1], 8192 /* 0.5 Q14 */ ) ) && ( GT_16( ltd_stable_rate[0], 3277 /* 0.1 Q15 */ ) ) ) { update_flag = 0; move16(); @@ -209,9 +200,7 @@ Word16 update_decision_fx( test(); test(); - IF((LT_16(sSFM[1], 30146/* 0.92 Q15 */)) - && (LT_16(sSFM[0], 30146/* 0.92 Q15 */)) - && (LT_16(sSFM[2], 30146/* 0.92 Q15 */))) + IF( ( LT_16( sSFM[1], 30146 /* 0.92 Q15 */ ) ) && ( LT_16( sSFM[0], 30146 /* 0.92 Q15 */ ) ) && ( LT_16( sSFM[2], 30146 /* 0.92 Q15 */ ) ) ) { update_flag = 0; move16(); @@ -219,48 +208,43 @@ Word16 update_decision_fx( test(); test(); - IF((LT_16(sSFM[0], 26214/* 0.8 Q15 */)) - || (LT_16(sSFM[1],25558/* 0.78 Q15 */) ) - || (LT_16(sSFM[2],26214/* 0.8 Q15 */) )) + IF( ( LT_16( sSFM[0], 26214 /* 0.8 Q15 */ ) ) || ( LT_16( sSFM[1], 25558 /* 0.78 Q15 */ ) ) || ( LT_16( sSFM[2], 26214 /* 0.8 Q15 */ ) ) ) { update_flag = 0; move16(); } /*if(frame_energy > 32*hVAD_CLDFB->frame_energy_smooth)*/ - tmpout= VAD_L_CMP(frame_energy, frame_energy_Q, hVAD_CLDFB->frame_energy_smooth,sub(hVAD_CLDFB->frame_energy_smooth_scale,5)); + tmpout = VAD_L_CMP( frame_energy, frame_energy_Q, hVAD_CLDFB->frame_energy_smooth, sub( hVAD_CLDFB->frame_energy_smooth_scale, 5 ) ); - if(tmpout>0) + if ( tmpout > 0 ) { update_flag = 0; move16(); } - tmp1 = L_mult(hVAD_CLDFB->fg_energy_count,18842); - tmp1_Q = norm_l(tmp1); - tmp1 = L_shl(tmp1,tmp1_Q); - tmp_norm = extract_h(tmp1); - frame_energy_Mcount = MUL_F(frame_energy,tmp_norm); + tmp1 = L_mult( hVAD_CLDFB->fg_energy_count, 18842 ); + tmp1_Q = norm_l( tmp1 ); + tmp1 = L_shl( tmp1, tmp1_Q ); + tmp_norm = extract_h( tmp1 ); + frame_energy_Mcount = MUL_F( frame_energy, tmp_norm ); - fg_energy_Qtmp = sub(frame_energy_Q, 18); - fg_energy_Qtmp = add(fg_energy_Qtmp, tmp1_Q); + fg_energy_Qtmp = sub( frame_energy_Q, 18 ); + fg_energy_Qtmp = add( fg_energy_Qtmp, tmp1_Q ); - cmp_result = VAD_L_CMP(frame_energy_Mcount,fg_energy_Qtmp,hVAD_CLDFB->fg_energy,hVAD_CLDFB->fg_energy_scale); + cmp_result = VAD_L_CMP( frame_energy_Mcount, fg_energy_Qtmp, hVAD_CLDFB->fg_energy, hVAD_CLDFB->fg_energy_scale ); - tmpout = VAD_L_CMP(frame_energy, frame_energy_Q, 3, 0); + tmpout = VAD_L_CMP( frame_energy, frame_energy_Q, 3, 0 ); test(); test(); - if((cmp_result>0) - &&(EQ_32(hVAD_CLDFB->fg_energy_est_start,1)) - &&(tmpout>0)) + if ( ( cmp_result > 0 ) && ( EQ_32( hVAD_CLDFB->fg_energy_est_start, 1 ) ) && ( tmpout > 0 ) ) { update_flag = 0; move16(); } test(); - IF((GT_16(f_tonality_rate[1],9830/* 0.6 Q14 */)) - ||(GT_16(f_tonality_rate[0],14089/* 0.86 Q14 */))) + IF( ( GT_16( f_tonality_rate[1], 9830 /* 0.6 Q14 */ ) ) || ( GT_16( f_tonality_rate[0], 14089 /* 0.86 Q14 */ ) ) ) { update_flag = 0; move16(); @@ -268,23 +252,22 @@ Word16 update_decision_fx( move16(); } - hVAD_CLDFB->tonality_rate3 = mult(hVAD_CLDFB->tonality_rate3, 32211); + hVAD_CLDFB->tonality_rate3 = mult( hVAD_CLDFB->tonality_rate3, 32211 ); move16(); - if(tonality_flag) + if ( tonality_flag ) { - hVAD_CLDFB->tonality_rate3 = add(mult(hVAD_CLDFB->tonality_rate3,32211), 557); + hVAD_CLDFB->tonality_rate3 = add( mult( hVAD_CLDFB->tonality_rate3, 32211 ), 557 ); move16(); } - if(GT_16(hVAD_CLDFB->tonality_rate3, 16384)) + if ( GT_16( hVAD_CLDFB->tonality_rate3, 16384 ) ) { update_flag = 0; move16(); } test(); - if((GT_16(sp_center[0], 4092/* 4.0 Q10 */)) - && (GT_16(ltd_stable_rate[0], 1311/* 0.04 Q15 */))) + if ( ( GT_16( sp_center[0], 4092 /* 4.0 Q10 */ ) ) && ( GT_16( ltd_stable_rate[0], 1311 /* 0.04 Q15 */ ) ) ) { update_flag = 0; move16(); @@ -292,9 +275,7 @@ Word16 update_decision_fx( test(); test(); - IF((GT_16(f_tonality_rate[1], 7536/* 0.46 Q14 */)) - && ((GT_16(sSFM[1],30473/* 0.93 Q15 */) ) - ||(GT_16(ltd_stable_rate[0], 2949/* 0.09 Q15 */)))) + IF( ( GT_16( f_tonality_rate[1], 7536 /* 0.46 Q14 */ ) ) && ( ( GT_16( sSFM[1], 30473 /* 0.93 Q15 */ ) ) || ( GT_16( ltd_stable_rate[0], 2949 /* 0.09 Q15 */ ) ) ) ) { update_flag = 0; @@ -304,10 +285,7 @@ Word16 update_decision_fx( test(); test(); test(); - IF( (LT_16(sSFM[1],30473/* 0.93 Q15 */) - && LT_16(sSFM[0], 30146/* 0.92 Q15 */) - && LT_16(sSFM[2], 31784/* 0.97 Q15 */)) - && (GT_16(f_tonality_rate[1], 8192/* 0.5 Q14 */))) + IF( ( LT_16( sSFM[1], 30473 /* 0.93 Q15 */ ) && LT_16( sSFM[0], 30146 /* 0.92 Q15 */ ) && LT_16( sSFM[2], 31784 /* 0.97 Q15 */ ) ) && ( GT_16( f_tonality_rate[1], 8192 /* 0.5 Q14 */ ) ) ) { update_flag = 0; move16(); @@ -315,42 +293,36 @@ Word16 update_decision_fx( test(); test(); - IF((f_tonality_rate[1] > 7045/* 0.43 Q14 */) - &&(sSFM[0] < 31129/* 0.95 Q15 */) - &&(sp_center[1] > 1985/* 1.94 Q10 */)) + IF( ( f_tonality_rate[1] > 7045 /* 0.43 Q14 */ ) && ( sSFM[0] < 31129 /* 0.95 Q15 */ ) && ( sp_center[1] > 1985 /* 1.94 Q10 */ ) ) { update_flag = 0; move16(); } - IF(EQ_16(update_flag, 1)) + IF( EQ_16( update_flag, 1 ) ) { - if(LT_16(hVAD_CLDFB->update_count, 1000)) + if ( LT_16( hVAD_CLDFB->update_count, 1000 ) ) { - hVAD_CLDFB->update_count = add(hVAD_CLDFB->update_count,1); + hVAD_CLDFB->update_count = add( hVAD_CLDFB->update_count, 1 ); } } - IF(update_flag) + IF( update_flag ) { - hVAD_CLDFB->lt_noise_sp_center3 = add(mult(hVAD_CLDFB->lt_noise_sp_center3,29491),mult(sp_center[3],3277)); + hVAD_CLDFB->lt_noise_sp_center3 = add( mult( hVAD_CLDFB->lt_noise_sp_center3, 29491 ), mult( sp_center[3], 3277 ) ); move16(); } - - tmpout= VAD_L_CMP(frame_energy, frame_energy_Q, hVAD_CLDFB->frame_energy_smooth,sub(hVAD_CLDFB->frame_energy_smooth_scale,2)); + tmpout = VAD_L_CMP( frame_energy, frame_energy_Q, hVAD_CLDFB->frame_energy_smooth, sub( hVAD_CLDFB->frame_energy_smooth_scale, 2 ) ); test(); test(); test(); test(); - if((tmpout>0) - &&(LT_16(frameloop, 100) ) - &&(LT_16(f_tonality_rate[1],9174/* 0.56 Q14 */)) - &&((LT_16(sp_center[0], 1391/* 1.36 Q10 */))||LT_16(ltd_stable_rate[0],983/* 0.03 Q15 */))) + if ( ( tmpout > 0 ) && ( LT_16( frameloop, 100 ) ) && ( LT_16( f_tonality_rate[1], 9174 /* 0.56 Q14 */ ) ) && ( ( LT_16( sp_center[0], 1391 /* 1.36 Q10 */ ) ) || LT_16( ltd_stable_rate[0], 983 /* 0.03 Q15 */ ) ) ) { update_flag = 1; move16(); @@ -362,12 +334,7 @@ Word16 update_decision_fx( test(); test(); test(); - if((LT_32(snr,10066329/* 0.3 Q25 */))&&tmpout<0 - &&(LT_32(L_shr(tsnr,1), 20132659/* 1.2/2.0 Q25 */)) - &&(vad_flag==0) - &&(LT_16(hVAD_CLDFB->f_tonality_rate[1],8192/* 0.5 Q14 */)) - &&(music_backgound_f==0) - &&(LT_16(hVAD_CLDFB->ltd_stable_rate[3],3277/* 0.1 Q15 */))) + if ( ( LT_32( snr, 10066329 /* 0.3 Q25 */ ) ) && tmpout < 0 && ( LT_32( L_shr( tsnr, 1 ), 20132659 /* 1.2/2.0 Q25 */ ) ) && ( vad_flag == 0 ) && ( LT_16( hVAD_CLDFB->f_tonality_rate[1], 8192 /* 0.5 Q14 */ ) ) && ( music_backgound_f == 0 ) && ( LT_16( hVAD_CLDFB->ltd_stable_rate[3], 3277 /* 0.1 Q15 */ ) ) ) { update_flag = 1; move16(); @@ -376,7 +343,7 @@ Word16 update_decision_fx( test(); test(); test(); - IF(vad_flag && GT_32(snr, 33554431/* 1.0 Q25 */)&&EQ_16(bw,CLDFBVAD_SWB_ID)&&tmpout>0) + IF( vad_flag && GT_32( snr, 33554431 /* 1.0 Q25 */ ) && EQ_16( bw, CLDFBVAD_SWB_ID ) && tmpout > 0 ) { update_flag = 0; } @@ -384,13 +351,13 @@ Word16 update_decision_fx( test(); test(); test(); - IF(vad_flag && GT_32(snr, 50331647/* 1.5 Q25 */)&&NE_16(bw,CLDFBVAD_SWB_ID)&&tmpout>0) + IF( vad_flag && GT_32( snr, 50331647 /* 1.5 Q25 */ ) && NE_16( bw, CLDFBVAD_SWB_ID ) && tmpout > 0 ) { update_flag = 0; } - IF(update_flag == 0) + IF( update_flag == 0 ) { hVAD_CLDFB->updateNumWithSnr = 0; } @@ -398,33 +365,34 @@ Word16 update_decision_fx( { test(); test(); - IF(vad_flag && GT_32(snr, 100663293/* 3.0 Q25 */)&<_16(hVAD_CLDFB->updateNumWithSnr,10)) + IF( vad_flag && GT_32( snr, 100663293 /* 3.0 Q25 */ ) && LT_16( hVAD_CLDFB->updateNumWithSnr, 10 ) ) { - update_flag = 0; move16(); - hVAD_CLDFB->updateNumWithSnr = add(hVAD_CLDFB->updateNumWithSnr, 1); + update_flag = 0; + move16(); + hVAD_CLDFB->updateNumWithSnr = add( hVAD_CLDFB->updateNumWithSnr, 1 ); } } test(); - IF(vad_flag==0||EQ_16(update_flag,1)) + IF( vad_flag == 0 || EQ_16( update_flag, 1 ) ) { Word16 tmp_fix; - tmp_fix = sub(hVAD_CLDFB->sp_center[2],hVAD_CLDFB->lt_noise_sp_center0); - tmp_fix = abs_s(tmp_fix); - if (GT_16(tmp_fix, 2558/* 2.5 Q10 */)) + tmp_fix = sub( hVAD_CLDFB->sp_center[2], hVAD_CLDFB->lt_noise_sp_center0 ); + tmp_fix = abs_s( tmp_fix ); + if ( GT_16( tmp_fix, 2558 /* 2.5 Q10 */ ) ) { - tmp_fix = 2558/* 2.5 Q10 */; + tmp_fix = 2558 /* 2.5 Q10 */; move16(); } - hVAD_CLDFB->lt_noise_sp_center_diff_sum = L_add(hVAD_CLDFB->lt_noise_sp_center_diff_sum ,tmp_fix); + hVAD_CLDFB->lt_noise_sp_center_diff_sum = L_add( hVAD_CLDFB->lt_noise_sp_center_diff_sum, tmp_fix ); move32(); - hVAD_CLDFB->lt_noise_sp_center_diff_counter = L_add(hVAD_CLDFB->lt_noise_sp_center_diff_counter,1); + hVAD_CLDFB->lt_noise_sp_center_diff_counter = L_add( hVAD_CLDFB->lt_noise_sp_center_diff_counter, 1 ); move32(); - IF(EQ_32(hVAD_CLDFB->lt_noise_sp_center_diff_counter, 128)) + IF( EQ_32( hVAD_CLDFB->lt_noise_sp_center_diff_counter, 128 ) ) { - hVAD_CLDFB->lt_noise_sp_center_diff_sum = MUL_F(hVAD_CLDFB->lt_noise_sp_center_diff_sum,24576); + hVAD_CLDFB->lt_noise_sp_center_diff_sum = MUL_F( hVAD_CLDFB->lt_noise_sp_center_diff_sum, 24576 ); move32(); hVAD_CLDFB->lt_noise_sp_center_diff_counter = 96; move32(); @@ -432,44 +400,44 @@ Word16 update_decision_fx( move16(); move16(); - IF(GT_16((Word16)abs_s(sub(hVAD_CLDFB->sp_center[0],hVAD_CLDFB->lt_noise_sp_center0)), 2455/* 2.4 Q10 */)) + IF( GT_16( (Word16) abs_s( sub( hVAD_CLDFB->sp_center[0], hVAD_CLDFB->lt_noise_sp_center0 ) ), 2455 /* 2.4 Q10 */ ) ) { - hVAD_CLDFB->lt_noise_sp_center0 = add(mult(hVAD_CLDFB->lt_noise_sp_center0,32637),mult(hVAD_CLDFB->sp_center[0],131)); + hVAD_CLDFB->lt_noise_sp_center0 = add( mult( hVAD_CLDFB->lt_noise_sp_center0, 32637 ), mult( hVAD_CLDFB->sp_center[0], 131 ) ); move16(); } - ELSE IF(GT_16((Word16)abs_s(sub(hVAD_CLDFB->sp_center[0],hVAD_CLDFB->lt_noise_sp_center0)), 1023/* 1.0 Q10 */)) + ELSE IF( GT_16( (Word16) abs_s( sub( hVAD_CLDFB->sp_center[0], hVAD_CLDFB->lt_noise_sp_center0 ) ), 1023 /* 1.0 Q10 */ ) ) { - hVAD_CLDFB->lt_noise_sp_center0 = add(mult(hVAD_CLDFB->lt_noise_sp_center0,32440),mult(hVAD_CLDFB->sp_center[0],328)); + hVAD_CLDFB->lt_noise_sp_center0 = add( mult( hVAD_CLDFB->lt_noise_sp_center0, 32440 ), mult( hVAD_CLDFB->sp_center[0], 328 ) ); move16(); } ELSE { - hVAD_CLDFB->lt_noise_sp_center0 = add(mult(hVAD_CLDFB->lt_noise_sp_center0,31457),mult(hVAD_CLDFB->sp_center[0],1311)); + hVAD_CLDFB->lt_noise_sp_center0 = add( mult( hVAD_CLDFB->lt_noise_sp_center0, 31457 ), mult( hVAD_CLDFB->sp_center[0], 1311 ) ); move16(); } } - Q_sum = sub(norm_l(hVAD_CLDFB->lt_noise_sp_center_diff_sum), 1); - Q_counter = norm_l(hVAD_CLDFB->lt_noise_sp_center_diff_counter); - sum_num = L_shl(hVAD_CLDFB->lt_noise_sp_center_diff_sum,Q_sum); - counter_den = L_shl(hVAD_CLDFB->lt_noise_sp_center_diff_counter,Q_counter); + Q_sum = sub( norm_l( hVAD_CLDFB->lt_noise_sp_center_diff_sum ), 1 ); + Q_counter = norm_l( hVAD_CLDFB->lt_noise_sp_center_diff_counter ); + sum_num = L_shl( hVAD_CLDFB->lt_noise_sp_center_diff_sum, Q_sum ); + counter_den = L_shl( hVAD_CLDFB->lt_noise_sp_center_diff_counter, Q_counter ); - IF(extract_h(counter_den)==0) + IF( extract_h( counter_den ) == 0 ) { div_r = EVS_SW_MAX; move16(); } ELSE { - div_r = div_l(sum_num,extract_h(counter_den)); + div_r = div_l( sum_num, extract_h( counter_den ) ); } - div_r = mult(div_r,24576); - div_r_32 = VAD_L_ADD(L_deposit_l(div_r),add(sub(Q_sum,Q_counter),22), 9830, 15,&div_r_Q); - div_r =extract_l(L_shr(div_r_32, sub(div_r_Q, SP_CENTER_Q))); + div_r = mult( div_r, 24576 ); + div_r_32 = VAD_L_ADD( L_deposit_l( div_r ), add( sub( Q_sum, Q_counter ), 22 ), 9830, 15, &div_r_Q ); + div_r = extract_l( L_shr( div_r_32, sub( div_r_Q, SP_CENTER_Q ) ) ); test(); - if((GT_16(abs_s(sub(hVAD_CLDFB->sp_center[2],hVAD_CLDFB->lt_noise_sp_center0)), div_r))&&(GT_16(frameloop,200))) + if ( ( GT_16( abs_s( sub( hVAD_CLDFB->sp_center[2], hVAD_CLDFB->lt_noise_sp_center0 ) ), div_r ) ) && ( GT_16( frameloop, 200 ) ) ) { update_flag = 0; move16(); diff --git a/lib_enc/updt_enc_fx.c b/lib_enc/updt_enc_fx.c index cebb93d9c..daa7d5d01 100644 --- a/lib_enc/updt_enc_fx.c +++ b/lib_enc/updt_enc_fx.c @@ -2,15 +2,15 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com_fx.h" /* Static table prototypes */ //#include "prot_fx.h" /* Function prototypes */ #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ -#include "basop_util.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ +#include "basop_util.h" /* Function prototypes */ /*-------------------------------------------------------------------* * updt_enc() @@ -19,18 +19,18 @@ *-------------------------------------------------------------------*/ void updt_enc_fx( - Encoder_State *st, /* i/o: state structure */ - const Word16 *old_exc, /* i : buffer of excitation */ - const Word16 *pitch_buf, /* i : floating pitch for each subframe */ - const Word16 Es_pred, /* i : predicited scaled innovation energy */ - const Word16 *Aq, /* i : A(z) quantized for all subframes */ - const Word16 *lsf_new, /* i : current frame LSF vector */ - const Word16 *lsp_new, /* i : current frame LSP vector */ - const Word16 *old_bwe_exc /* i : buffer of excitation */ + Encoder_State *st, /* i/o: state structure */ + const Word16 *old_exc, /* i : buffer of excitation */ + const Word16 *pitch_buf, /* i : floating pitch for each subframe */ + const Word16 Es_pred, /* i : predicited scaled innovation energy */ + const Word16 *Aq, /* i : A(z) quantized for all subframes */ + const Word16 *lsf_new, /* i : current frame LSF vector */ + const Word16 *lsp_new, /* i : current frame LSP vector */ + const Word16 *old_bwe_exc /* i : buffer of excitation */ ) { Word16 i, tmp; - SC_VBR_ENC_HANDLE hSC_VBR = st->hSC_VBR; + SC_VBR_ENC_HANDLE hSC_VBR = st->hSC_VBR; LPD_state_HANDLE hLPDmem = st->hLPDmem; GSC_ENC_HANDLE hGSCEnc = st->hGSCEnc; TD_BWE_ENC_HANDLE hBWE_TD = st->hBWE_TD; @@ -38,7 +38,7 @@ void updt_enc_fx( /* update old excitation buffer */ Copy( &old_exc[st->L_frame], hLPDmem->old_exc, L_EXC_MEM ); test(); - IF( !st->Opt_AMR_WB && st->hBWE_TD != NULL) + IF( !st->Opt_AMR_WB && st->hBWE_TD != NULL ) { Copy( &old_bwe_exc[L_FRAME32k], hBWE_TD->old_bwe_exc_fx, PIT16k_MAX * 2 ); } @@ -53,7 +53,7 @@ void updt_enc_fx( test(); test(); test(); - if( EQ_16(st->coder_type,INACTIVE) || (EQ_16(st->bpf_off,1) && NE_16(st->coder_type,AUDIO) && NE_16(st->coder_type,TRANSITION))) + if ( EQ_16( st->coder_type, INACTIVE ) || ( EQ_16( st->bpf_off, 1 ) && NE_16( st->coder_type, AUDIO ) && NE_16( st->coder_type, TRANSITION ) ) ) { st->last_coder_type = UNVOICED; move16(); @@ -61,7 +61,7 @@ void updt_enc_fx( /* this ensures that st->last_coder_type is never set to INACTIVE in case of AVQ inactive because the FEC does not distinguish between GSC inactive and AVQ inactive */ test(); - if ( EQ_16(st->coder_type,INACTIVE) && GT_32(st->total_brate,ACELP_24k40)) + if ( EQ_16( st->coder_type, INACTIVE ) && GT_32( st->total_brate, ACELP_24k40 ) ) { st->last_coder_type = GENERIC; move16(); @@ -70,7 +70,7 @@ void updt_enc_fx( test(); test(); test(); - IF( st->Opt_AMR_WB && EQ_16(st->coder_type,INACTIVE) && st->core_brate!=SID_1k75 && st->core_brate!=FRAME_NO_DATA) + IF( st->Opt_AMR_WB && EQ_16( st->coder_type, INACTIVE ) && st->core_brate != SID_1k75 && st->core_brate != FRAME_NO_DATA ) { /* overwrite previous coding type to help FEC */ st->last_coder_type = UNVOICED; @@ -78,56 +78,57 @@ void updt_enc_fx( } /* AC mode (GSC) - in speech we can consider that the last pitch band reached the max */ - test();test(); - IF (st->hGSCEnc != NULL && NE_16(st->coder_type,AUDIO) && NE_16(st->coder_type,INACTIVE)) + test(); + test(); + IF( st->hGSCEnc != NULL && NE_16( st->coder_type, AUDIO ) && NE_16( st->coder_type, INACTIVE ) ) { hGSCEnc->mem_last_pit_band = 10 + BAND1k2; move16(); - hGSCEnc->past_dyn_dec = NOISE_LEVEL_SP0-1; - move16(); /* tends to speech */ - hGSCEnc->noise_lev = NOISE_LEVEL_SP0-1; - move16(); /* tends to speech */ + hGSCEnc->past_dyn_dec = NOISE_LEVEL_SP0 - 1; + move16(); /* tends to speech */ + hGSCEnc->noise_lev = NOISE_LEVEL_SP0 - 1; + move16(); /* tends to speech */ /*st->mid_dyn_fx = 40.0f * 0.5f + st->mid_dyn * 0.5f;*/ - hGSCEnc->mid_dyn_fx = add(20*128, mult_r(hGSCEnc->mid_dyn_fx, 16384)); /*Q7*/ + hGSCEnc->mid_dyn_fx = add( 20 * 128, mult_r( hGSCEnc->mid_dyn_fx, 16384 ) ); /*Q7*/ } /* convert old LSP vector from 12kHz domain to 16kHz domain (needed in case of ACELP@12k8 <-> ACELP@16kHz switching) */ - IF( EQ_16(st->L_frame,L_FRAME)) + IF( EQ_16( st->L_frame, L_FRAME ) ) { Copy( st->lsp_old_fx, st->lsp_old16k_fx, M ); - st->rate_switching_reset_16kHz=lsp_convert_poly_fx( st->lsp_old16k_fx, L_FRAME16k, st->Opt_AMR_WB ); + st->rate_switching_reset_16kHz = lsp_convert_poly_fx( st->lsp_old16k_fx, L_FRAME16k, st->Opt_AMR_WB ); } /* update buffer of old subframe pitch values */ - IF( NE_16(st->last_L_frame,st->L_frame)) + IF( NE_16( st->last_L_frame, st->L_frame ) ) { - IF( EQ_16(st->L_frame,L_FRAME)) + IF( EQ_16( st->L_frame, L_FRAME ) ) { - FOR( i=0; iold_pitch_buf_fx[NB_SUBFR+i] = mult_r(26214, st->old_pitch_buf_fx[NB_SUBFR+i+1]); + st->old_pitch_buf_fx[NB_SUBFR + i] = mult_r( 26214, st->old_pitch_buf_fx[NB_SUBFR + i + 1] ); move16(); } } ELSE { - FOR( i=NB_SUBFR; i>0; i-- ) + FOR( i = NB_SUBFR; i > 0; i-- ) { - st->old_pitch_buf_fx[NB_SUBFR+i] = add(mult_r(8192, st->old_pitch_buf_fx[NB_SUBFR+i-1]),st->old_pitch_buf_fx[NB_SUBFR+i-1]); + st->old_pitch_buf_fx[NB_SUBFR + i] = add( mult_r( 8192, st->old_pitch_buf_fx[NB_SUBFR + i - 1] ), st->old_pitch_buf_fx[NB_SUBFR + i - 1] ); move16(); } - st->old_pitch_buf_fx[2*NB_SUBFR16k-1] = st->old_pitch_buf_fx[2*NB_SUBFR16k-2]; + st->old_pitch_buf_fx[2 * NB_SUBFR16k - 1] = st->old_pitch_buf_fx[2 * NB_SUBFR16k - 2]; move16(); } } - tmp = shr(st->L_frame,6); - Copy( &st->old_pitch_buf_fx[tmp], st->old_pitch_buf_fx, tmp); - Copy( pitch_buf, &st->old_pitch_buf_fx[tmp], tmp); + tmp = shr( st->L_frame, 6 ); + Copy( &st->old_pitch_buf_fx[tmp], st->old_pitch_buf_fx, tmp ); + Copy( pitch_buf, &st->old_pitch_buf_fx[tmp], tmp ); /* SC-VBR */ st->last_Opt_SC_VBR = st->Opt_SC_VBR; move16(); - IF(st->hSC_VBR != NULL) + IF( st->hSC_VBR != NULL ) { hSC_VBR->last_last_ppp_mode = hSC_VBR->last_ppp_mode; move16(); @@ -137,33 +138,33 @@ void updt_enc_fx( move16(); } /* core switching updates */ - Copy( &Aq[(st->L_frame/L_SUBFR-1)*(M+1)], st->old_Aq_12_8_fx, M+1 ); + Copy( &Aq[( st->L_frame / L_SUBFR - 1 ) * ( M + 1 )], st->old_Aq_12_8_fx, M + 1 ); st->old_Es_pred_fx = Es_pred; return; } /*-------------------------------------------------------------------* - * updt_IO_switch() - * - * Common updates for AMR-WB IO mode and EVS primary mode switching - *-------------------------------------------------------------------*/ + * updt_IO_switch() + * + * Common updates for AMR-WB IO mode and EVS primary mode switching + *-------------------------------------------------------------------*/ void updt_IO_switch_enc_fx( - Encoder_State *st, /* i/o: state structure */ - const Word16 input_frame /* i : input frame length */ + Encoder_State *st, /* i/o: state structure */ + const Word16 input_frame /* i : input frame length */ ) { Word16 xsp_tmp[M]; - SC_VBR_ENC_HANDLE hSC_VBR = st->hSC_VBR; - DTX_ENC_HANDLE hDtxEnc = st->hDtxEnc; - TD_CNG_ENC_HANDLE hTdCngEnc = st->hTdCngEnc; + SC_VBR_ENC_HANDLE hSC_VBR = st->hSC_VBR; + DTX_ENC_HANDLE hDtxEnc = st->hDtxEnc; + TD_CNG_ENC_HANDLE hTdCngEnc = st->hTdCngEnc; GSC_ENC_HANDLE hGSCEnc = st->hGSCEnc; AMRWB_IO_ENC_HANDLE hAmrwb_IO = st->hAmrwb_IO; TD_BWE_ENC_HANDLE hBWE_TD = st->hBWE_TD; FD_BWE_ENC_HANDLE hBWE_FD = st->hBWE_FD; - IF( EQ_16(st->last_core,AMR_WB_CORE)) /* switching to EVS primary mode */ + IF( EQ_16( st->last_core, AMR_WB_CORE ) ) /* switching to EVS primary mode */ { /* reset onset detection counter */ st->tc_cnt = -1; @@ -174,61 +175,64 @@ void updt_IO_switch_enc_fx( /* AMR-WB IO mode uses ISF(ISP), but EVS primary mode LSF(LSP) */ Copy( stable_LSP_fx, xsp_tmp, M ); - isf2lsf_fx( st->lsf_old_fx, st->lsf_old_fx, xsp_tmp); + isf2lsf_fx( st->lsf_old_fx, st->lsf_old_fx, xsp_tmp ); Copy( stable_LSP_fx, xsp_tmp, M ); - isp2lsp_fx( st->lsp_old_fx, st->lsp_old_fx, xsp_tmp, M); - isp2lsp_fx( st->lsp_old1_fx, st->lsp_old1_fx, xsp_tmp, M); + isp2lsp_fx( st->lsp_old_fx, st->lsp_old_fx, xsp_tmp, M ); + isp2lsp_fx( st->lsp_old1_fx, st->lsp_old1_fx, xsp_tmp, M ); Copy( stable_LSP_fx, xsp_tmp, M ); - isp2lsp_fx(hDtxEnc->lspCNG_fx, hDtxEnc->lspCNG_fx, xsp_tmp, M); + isp2lsp_fx( hDtxEnc->lspCNG_fx, hDtxEnc->lspCNG_fx, xsp_tmp, M ); /*st->old_enr_index = min( (short)((float)st->old_enr_index / STEP_AMR_WB_SID * STEP_SID), 127 );*/ - IF(hTdCngEnc->old_enr_index >=0 ) + IF( hTdCngEnc->old_enr_index >= 0 ) { /* old index is initialized to -1, and may only be updated after it has been calculated properly at least once once */ - hTdCngEnc->old_enr_index = s_min(mult(shl(hTdCngEnc->old_enr_index,1), 32459), 127 ); /*32459 = 2/(STEP_SID/STEP_AMR_WB_SID)*/ + hTdCngEnc->old_enr_index = s_min( mult( shl( hTdCngEnc->old_enr_index, 1 ), 32459 ), 127 ); /*32459 = 2/(STEP_SID/STEP_AMR_WB_SID)*/ } /* Perform preemphasis of the old input signal @16kHz */ st->mem_preemph16k_fx = 0; move16(); - preemph_fx( st->old_inp_16k_fx, PREEMPH_FAC_16k, L_INP_MEM, &(st->mem_preemph16k_fx) ); - Scale_sig(st->old_inp_16k_fx, L_INP_MEM, st->prev_Q_new); + preemph_fx( st->old_inp_16k_fx, PREEMPH_FAC_16k, L_INP_MEM, &( st->mem_preemph16k_fx ) ); + Scale_sig( st->old_inp_16k_fx, L_INP_MEM, st->prev_Q_new ); /* reset TD BWE buffers */ - set16_fx( hBWE_TD->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k ); - set16_fx( hBWE_TD->old_speech_wb_fx, 0, (L_LOOK_12k8 + L_SUBFR) * 5/16 ); + set16_fx( hBWE_TD->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k ); + set16_fx( hBWE_TD->old_speech_wb_fx, 0, ( L_LOOK_12k8 + L_SUBFR ) * 5 / 16 ); set16_fx( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); set16_fx( hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); #ifdef IVAS_CODE - set16_fx(st->hBWE_TD->mem_shb_res, 0, MAX_LEN_MA_FILTER); - set16_fx(st->hBWE_TD->old_EnvSHBres, 0, L_FRAME4k); + set16_fx( st->hBWE_TD->mem_shb_res, 0, MAX_LEN_MA_FILTER ); + set16_fx( st->hBWE_TD->old_EnvSHBres, 0, L_FRAME4k ); st->hBWE_TD->old_mean_EnvSHBres = 0; st->hBWE_TD->prev_enr_EnvSHBres = 32767; st->hBWE_TD->prev_pow_exc16kWhtnd = 32767; st->hBWE_TD->prev_mix_factor = 32767; st->hBWE_TD->prev_Env_error = 0; - move16();move16();move16();move16();move16(); + move16(); + move16(); + move16(); + move16(); + move16(); #endif hBWE_TD->bwe_non_lin_prev_scale_fx = 0; move16(); - set16_fx( hBWE_TD->decim_state1_fx, 0, (2*ALLPASSSECTIONS_STEEP+1) ); - set16_fx( hBWE_TD->decim_state2_fx, 0, (2*ALLPASSSECTIONS_STEEP+1) ); - set16_fx(hBWE_FD->L_old_wtda_swb_fx, 0, L_FRAME16k ); - set16_fx(hBWE_FD->old_input_wb_fx, 0, NS2SA(16000, DELAY_FD_BWE_ENC_NS) ); + set16_fx( hBWE_TD->decim_state1_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); + set16_fx( hBWE_TD->decim_state2_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); + set16_fx( hBWE_FD->L_old_wtda_swb_fx, 0, L_FRAME16k ); + set16_fx( hBWE_FD->old_input_wb_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); wb_tbe_extras_reset_fx( hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx ); - IF( GE_16(input_frame,L_FRAME32k)) + IF( GE_16( input_frame, L_FRAME32k ) ) { swb_tbe_reset_fx( hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, - hBWE_TD->syn_overlap_fx, hBWE_TD->state_syn_shbexc_fx, &(hBWE_TD->tbe_demph_fx),&(hBWE_TD->tbe_premph_fx), hBWE_TD->mem_stp_swb_fx, &(hBWE_TD->gain_prec_swb_fx) ); - + hBWE_TD->syn_overlap_fx, hBWE_TD->state_syn_shbexc_fx, &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), hBWE_TD->mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ) ); } - IF( EQ_16(input_frame,L_FRAME48k)) + IF( EQ_16( input_frame, L_FRAME48k ) ) { - set16_fx(hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER); + set16_fx( hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); hBWE_TD->fb_tbe_demph_fx = 0; move16(); - fb_tbe_reset_enc_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx, &hBWE_TD->prev_fb_energy_fx,hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q,&hBWE_TD->prev_fb_energy_fx_Q); + fb_tbe_reset_enc_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx, &hBWE_TD->prev_fb_energy_fx, hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, &hBWE_TD->prev_fb_energy_fx_Q ); } /* reset FD BWE buffers */ @@ -242,54 +246,58 @@ void updt_IO_switch_enc_fx( st->use_acelp_preq = 0; move16(); #ifdef IVAS_CODE - set16_fx(st->hSpMusClas->finc_prev, 0, ATT_NSEG); - set16_fx(st->hSpMusClas->tod_lt_Bin_E, 0, TOD_NSPEC); - set16_fx(st->hSpMusClas->tod_S_map_lt, 0, TOD_NSPEC); + set16_fx( st->hSpMusClas->finc_prev, 0, ATT_NSEG ); + set16_fx( st->hSpMusClas->tod_lt_Bin_E, 0, TOD_NSPEC ); + set16_fx( st->hSpMusClas->tod_S_map_lt, 0, TOD_NSPEC ); st->hSpMusClas->lt_finc = 0; st->hSpMusClas->last_strong_attack = 0; st->hSpMusClas->tod_thr_lt = TOD_THR_MASS; st->hSpMusClas->tod_weight = 0; st->hSpMusClas->tod_S_mass_prev = TOD_THR_MASS; st->hSpMusClas->tod_S_mass_lt = TOD_THR_MASS; - move16();move16();move16();move16();move16();move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); #endif - } - ELSE /* switching to AMR-WB IO mode */ + ELSE /* switching to AMR-WB IO mode */ { - set16_fx(st->mem_MA_fx, 0, M ); + set16_fx( st->mem_MA_fx, 0, M ); /* AMR-WB IO mode uses ISF(ISP), but EVS primary mode LSF(LSP) */ Copy( stable_ISP_fx, xsp_tmp, M ); - lsf2isf_fx( st->lsf_old_fx, st->lsf_old_fx, xsp_tmp, M); + lsf2isf_fx( st->lsf_old_fx, st->lsf_old_fx, xsp_tmp, M ); Copy( stable_ISP_fx, xsp_tmp, M ); - lsp2isp_fx( st->lsp_old_fx, st->lsp_old_fx, xsp_tmp, M); - lsp2isp_fx( st->lsp_old1_fx, st->lsp_old1_fx, xsp_tmp, M); + lsp2isp_fx( st->lsp_old_fx, st->lsp_old_fx, xsp_tmp, M ); + lsp2isp_fx( st->lsp_old1_fx, st->lsp_old1_fx, xsp_tmp, M ); Copy( stable_ISP_fx, xsp_tmp, M ); - lsp2isp_fx(hDtxEnc->lspCNG_fx, hDtxEnc->lspCNG_fx, xsp_tmp, M); + lsp2isp_fx( hDtxEnc->lspCNG_fx, hDtxEnc->lspCNG_fx, xsp_tmp, M ); - IF(hTdCngEnc->old_enr_index >= 0 ) + IF( hTdCngEnc->old_enr_index >= 0 ) { /* old_enr__index is initialized to -1, and may only be updated this way after it has been calculated properly at least once once */ /*st->old_enr_index = min( (short)((float)st->old_enr_index / STEP_SID * STEP_AMR_WB_SID), 63 );*/ - hTdCngEnc->old_enr_index = s_max(s_min(mult(hTdCngEnc->old_enr_index, 16384), 63 ),0); /*32459 = 2/(STEP_SID/STEP_AMR_WB_SID)*/ + hTdCngEnc->old_enr_index = s_max( s_min( mult( hTdCngEnc->old_enr_index, 16384 ), 63 ), 0 ); /*32459 = 2/(STEP_SID/STEP_AMR_WB_SID)*/ } /* gain quantization memory */ - set16_fx(hAmrwb_IO->past_qua_en_fx, (-14*1024), GAIN_PRED_ORDER ); + set16_fx( hAmrwb_IO->past_qua_en_fx, ( -14 * 1024 ), GAIN_PRED_ORDER ); /* reset VBR signalling */ - IF (st->Opt_SC_VBR) + IF( st->Opt_SC_VBR ) { hSC_VBR->ppp_mode = 0; move16(); hSC_VBR->nelp_mode = 0; move16(); } - st->hGSCEnc->seed_tcx = 15687; /* the re-init here was present only in float _DIFF_FLOAT_FIX_*/ + st->hGSCEnc->seed_tcx = 15687; /* the re-init here was present only in float _DIFF_FLOAT_FIX_*/ move16(); } /* Force SID in case of AMR-WB IO/EVS primary mode switching */ - IF (hTdCngEnc != NULL) + IF( hTdCngEnc != NULL ) { hDtxEnc->cnt_SID = 0; move16(); @@ -320,16 +328,16 @@ void updt_IO_switch_enc_fx( *-------------------------------------------------------------------*/ #if 1 void updt_enc_common_fx( - Encoder_State* st, /* i/o: encoder state structure */ - const Word16 Etot, /* i : total energy */ - const Word16 Q_new /* i : CUrrent frame scaling */ + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 Etot, /* i : total energy */ + const Word16 Q_new /* i : CUrrent frame scaling */ ) { /*---------------------------------------------------------------------* * Updates - main main codec parameters *---------------------------------------------------------------------*/ - - st->last_sr_core = st->sr_core; //## + + st->last_sr_core = st->sr_core; //## move32(); st->last_codec_mode = st->codec_mode; move16(); @@ -349,7 +357,7 @@ void updt_enc_common_fx( move16(); st->last_input_bwidth = st->input_bwidth; //## move16(); - st->last_bwidth = st->bwidth; //## + st->last_bwidth = st->bwidth; //## move16(); st->hNoiseEst->Etot_last_fx = Etot; move16(); @@ -360,157 +368,170 @@ void updt_enc_common_fx( move16(); test(); - if (GT_32(st->core_brate, SID_2k40) && st->hDtxEnc != NULL) + if ( GT_32( st->core_brate, SID_2k40 ) && st->hDtxEnc != NULL ) { st->hDtxEnc->last_active_brate = st->total_brate; move32(); } - IF(st->hBWE_TD != NULL) + IF( st->hBWE_TD != NULL ) { st->hBWE_TD->prev_coder_type = st->coder_type; move16(); - if (EQ_16(st->core, HQ_CORE)) + if ( EQ_16( st->core, HQ_CORE ) ) { /* in the HQ core, coder_type is not used so it could have been set to anything */ st->hBWE_TD->prev_coder_type = GENERIC; move16(); - } } test(); - IF(st->Opt_DTX_ON && st->hTdCngEnc != NULL) + IF( st->Opt_DTX_ON && st->hTdCngEnc != NULL ) { - IF(GT_32(st->core_brate, SID_2k40) ) + IF( GT_32( st->core_brate, SID_2k40 ) ) { - IF(EQ_16(st->hDtxEnc->first_CNG, 1)) + IF( EQ_16( st->hDtxEnc->first_CNG, 1 ) ) { - if (GE_16(st->hTdCngEnc->act_cnt, BUF_DEC_RATE)) + if ( GE_16( st->hTdCngEnc->act_cnt, BUF_DEC_RATE ) ) { st->hTdCngEnc->act_cnt = 0; move16(); } - st->hTdCngEnc->act_cnt = add(st->hTdCngEnc->act_cnt, 1); + st->hTdCngEnc->act_cnt = add( st->hTdCngEnc->act_cnt, 1 ); test(); - if (EQ_16(st->hTdCngEnc->act_cnt, BUF_DEC_RATE) && st->hTdCngEnc->ho_hist_size > 0) + if ( EQ_16( st->hTdCngEnc->act_cnt, BUF_DEC_RATE ) && st->hTdCngEnc->ho_hist_size > 0 ) { - st->hTdCngEnc->ho_hist_size = sub(st->hTdCngEnc->ho_hist_size, 1); + st->hTdCngEnc->ho_hist_size = sub( st->hTdCngEnc->ho_hist_size, 1 ); } } - test(); test(); test(); - IF(EQ_16(st->element_mode, IVAS_SCE) || EQ_16(st->element_mode, IVAS_CPE_DFT) || EQ_16(st->element_mode, IVAS_CPE_TD) || EQ_16(st->hDtxEnc->first_CNG, 1)) + test(); + test(); + test(); + IF( EQ_16( st->element_mode, IVAS_SCE ) || EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) || EQ_16( st->hDtxEnc->first_CNG, 1 ) ) { - st->hTdCngEnc->act_cnt2 = add(st->hTdCngEnc->act_cnt2, 1); - st->hTdCngEnc->act_cnt2 = s_min(st->hTdCngEnc->act_cnt2, MIN_ACT_CNG_UPD); + st->hTdCngEnc->act_cnt2 = add( st->hTdCngEnc->act_cnt2, 1 ); + st->hTdCngEnc->act_cnt2 = s_min( st->hTdCngEnc->act_cnt2, MIN_ACT_CNG_UPD ); #ifdef IVAS_CODE - test(); test(); test(); - IF((EQ_16(st->element_mode, IVAS_SCE) || EQ_16(st->element_mode, IVAS_CPE_DFT) || EQ_16(st->element_mode, IVAS_CPE_TD)) && GE_16(st->hTdCngEnc->act_cnt2, MIN_ACT_CNG_UPD)) + test(); + test(); + test(); + IF( ( EQ_16( st->element_mode, IVAS_SCE ) || EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) && GE_16( st->hTdCngEnc->act_cnt2, MIN_ACT_CNG_UPD ) ) { - st->hTdCngEnc->CNG_att_fx = 0; move16(); + st->hTdCngEnc->CNG_att_fx = 0; + move16(); - apply_scale(&st->hTdCngEnc->CNG_att, st->hFdCngEnc->hFdCngCom->CngBandwidth, st->hFdCngEnc->hFdCngCom->CngBitrate, scaleTableStereo, SIZE_SCALE_TABLE_STEREO); + apply_scale( &st->hTdCngEnc->CNG_att, st->hFdCngEnc->hFdCngCom->CngBandwidth, st->hFdCngEnc->hFdCngCom->CngBitrate, scaleTableStereo, SIZE_SCALE_TABLE_STEREO ); } #endif } } - - test(); test(); test(); - if( (EQ_32(st->core_brate, SID_2k40) || EQ_32(st->core_brate, FRAME_NO_DATA)) && st->hDtxEnc->first_CNG == 0 && EQ_16(st->cng_type, LP_CNG)) + + test(); + test(); + test(); + if ( ( EQ_32( st->core_brate, SID_2k40 ) || EQ_32( st->core_brate, FRAME_NO_DATA ) ) && st->hDtxEnc->first_CNG == 0 && EQ_16( st->cng_type, LP_CNG ) ) { st->hDtxEnc->first_CNG = 1; move16(); } } - + /*-----------------------------------------------------------------* * Increase the counter of initialization frames * Limit the max number of init. frames *-----------------------------------------------------------------*/ - if (LT_16(st->ini_frame, MAX_FRAME_COUNTER)) + if ( LT_16( st->ini_frame, MAX_FRAME_COUNTER ) ) { - st->ini_frame = add(st->ini_frame, 1); + st->ini_frame = add( st->ini_frame, 1 ); } /* synchronisation of CNG seeds */ - test();test();test(); - IF (st->hTdCngEnc != NULL && NE_32(st->core_brate, FRAME_NO_DATA) && NE_32(st->core_brate, SID_2k40) && NE_16(st->core, AMR_WB_CORE)) + test(); + test(); + test(); + IF( st->hTdCngEnc != NULL && NE_32( st->core_brate, FRAME_NO_DATA ) && NE_32( st->core_brate, SID_2k40 ) && NE_16( st->core, AMR_WB_CORE ) ) { - Random(&(st->hTdCngEnc->cng_seed)); - Random(&(st->hTdCngEnc->cng_ener_seed)); + Random( &( st->hTdCngEnc->cng_seed ) ); + Random( &( st->hTdCngEnc->cng_ener_seed ) ); } /*---------------------------------------------------------------------* * Updates - MODE2 *---------------------------------------------------------------------*/ - IF (EQ_16(st->element_mode, EVS_MONO) && EQ_16(st->mdct_sw, MODE2)) + IF( EQ_16( st->element_mode, EVS_MONO ) && EQ_16( st->mdct_sw, MODE2 ) ) { - st->codec_mode = MODE2; + st->codec_mode = MODE2; move16(); - st->sr_core = getCoreSamplerateMode2(EVS_MONO, st->total_brate, st->bwidth, st->flag_ACELP16k, st->rf_mode, 0); + st->sr_core = getCoreSamplerateMode2( EVS_MONO, st->total_brate, st->bwidth, st->flag_ACELP16k, st->rf_mode, 0 ); - //st->L_frame = extract_l(Mult_32_16(st->sr_core, 0x0290)); /*(int16_t)(st->sr_core / FRAMES_PER_SEC);*/ + // st->L_frame = extract_l(Mult_32_16(st->sr_core, 0x0290)); /*(int16_t)(st->sr_core / FRAMES_PER_SEC);*/ - IF (EQ_32(st->sr_core, INT_FS_12k8)) + IF( EQ_32( st->sr_core, INT_FS_12k8 ) ) { st->preemph_fac = PREEMPH_FAC; st->gamma = GAMMA1; st->L_frame = L_FRAME; - move16(); move16(); move16(); + move16(); + move16(); + move16(); } ELSE { st->preemph_fac = PREEMPH_FAC_16k; st->gamma = GAMMA16k; st->L_frame = L_FRAME16k; - move16();move16();move16(); + move16(); + move16(); + move16(); } - st->igf = getIgfPresent_fx(EVS_MONO, st->total_brate, st->bwidth, st->rf_mode); + st->igf = getIgfPresent_fx( EVS_MONO, st->total_brate, st->bwidth, st->rf_mode ); } /* update FER clas */ - if (NE_16(st->core, AMR_WB_CORE)) + if ( NE_16( st->core, AMR_WB_CORE ) ) { st->last_clas = st->clas; move16(); } /* Update Core */ - core_encode_update_fx(st); + core_encode_update_fx( st ); /*---------------------------------------------------------------------* * RF mode updates *---------------------------------------------------------------------*/ - IF (st->rf_mode) + IF( st->rf_mode ) { - IF (st->hSC_VBR != NULL) + IF( st->hSC_VBR != NULL ) { st->hSC_VBR->last_nelp_mode = 0; move16(); - if (EQ_16(st->hRF->rf_frame_type, RF_NELP)) + if ( EQ_16( st->hRF->rf_frame_type, RF_NELP ) ) { st->hSC_VBR->last_nelp_mode = 1; move16(); } - } } - st->rf_mode_last = st->rf_mode; move16(); + st->rf_mode_last = st->rf_mode; + move16(); - IF (st->Opt_RF_ON) + IF( st->Opt_RF_ON ) { st->L_frame = L_FRAME; st->rf_mode = 1; - move16();move16(); + move16(); + move16(); } /*---------------------------------------------------------------------* @@ -518,12 +539,12 @@ void updt_enc_common_fx( *---------------------------------------------------------------------*/ #ifdef IVAS_CODE test(); - if (GT_16(st->element_mode, EVS_MONO) && st->hTcxEnc != NULL) + if ( GT_16( st->element_mode, EVS_MONO ) && st->hTcxEnc != NULL ) { - st->hTcxEnc->tcxltp_norm_corr_mem= st->hTcxEnc->tcxltp_norm_corr_past; + st->hTcxEnc->tcxltp_norm_corr_mem = st->hTcxEnc->tcxltp_norm_corr_past; move16(); } #endif return; } -#endif \ No newline at end of file +#endif diff --git a/lib_enc/updt_tar_fx.c b/lib_enc/updt_tar_fx.c index b6b87b4cf..19d9cbb70 100644 --- a/lib_enc/updt_tar_fx.c +++ b/lib_enc/updt_tar_fx.c @@ -2,12 +2,12 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ +#include "options.h" /* Compilation switches */ #include "cnst.h" //#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*----------------------------------------------------------------------------------* * procedure updt_tar: @@ -15,11 +15,11 @@ * Update the target vector for codebook search. *----------------------------------------------------------------------------------*/ void updt_tar_fx( - const Word16 *x, /* i : old target (for pitch search) */ - Word16 *x2, /* o : new target (for codebook search) */ - const Word16 *y, /* i : filtered adaptive codebook vector */ - const Word16 gain, /* i : adaptive codebook gain */ - const Word16 L /* i : subframe size */ + const Word16 *x, /* i : old target (for pitch search) */ + Word16 *x2, /* o : new target (for codebook search) */ + const Word16 *y, /* i : filtered adaptive codebook vector */ + const Word16 gain, /* i : adaptive codebook gain */ + const Word16 L /* i : subframe size */ ) { Word16 i; @@ -29,16 +29,16 @@ void updt_tar_fx( #endif - FOR (i = 0; i < L; i++) + FOR( i = 0; i < L; i++ ) { /*x2[i] = x[i] - gain*y[i];*/ - L_tmp = L_mult(x[i], 16384); + L_tmp = L_mult( x[i], 16384 ); #ifdef BASOP_NOGLOB L_tmp = L_msu_sat( L_tmp, y[i], gain ); - x2[i] = extract_h(L_shl_o(L_tmp, 1, &Overflow)); + x2[i] = extract_h( L_shl_o( L_tmp, 1, &Overflow ) ); #else /* BASOP_NOGLOB */ L_tmp = L_msu( L_tmp, y[i], gain ); - x2[i] = extract_h(L_shl(L_tmp, 1)); + x2[i] = extract_h( L_shl( L_tmp, 1 ) ); #endif } return; @@ -49,32 +49,32 @@ void updt_tar_fx( * Update the target vector for codebook search. *----------------------------------------------------------------------------------*/ void updt_tar_HR_fx( - const Word16 *x, /* i : old target (for pitch search) */ - Word16 *x2, /* o : new target (for codebook search) */ - const Word16 *y, /* i : filtered adaptive codebook vector */ - const Word16 gain, /* i : adaptive codebook gain Q2 */ - const Word16 Qx, /* i : Scaling factor to adapt output to input */ - const Word16 L /* i : subframe size */ + const Word16 *x, /* i : old target (for pitch search) */ + Word16 *x2, /* o : new target (for codebook search) */ + const Word16 *y, /* i : filtered adaptive codebook vector */ + const Word16 gain, /* i : adaptive codebook gain Q2 */ + const Word16 Qx, /* i : Scaling factor to adapt output to input */ + const Word16 L /* i : subframe size */ ) { Word16 i; Word32 L_tmp, L_tmp1; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; -#endif +#endif - FOR (i = 0; i < L; i++) + FOR( i = 0; i < L; i++ ) { /*x2[i] = x[i] - gain*y[i];*/ - L_tmp = L_mult(x[i], 32767); + L_tmp = L_mult( x[i], 32767 ); #ifdef BASOP_NOGLOB - L_tmp1 = L_shl_o(L_mult_o(y[i], gain, &Overflow), Qx, &Overflow); - L_tmp = L_sub_o(L_tmp, L_tmp1, &Overflow); + L_tmp1 = L_shl_o( L_mult_o( y[i], gain, &Overflow ), Qx, &Overflow ); + L_tmp = L_sub_o( L_tmp, L_tmp1, &Overflow ); #else - L_tmp1 = L_shl(L_mult(y[i], gain), Qx); - L_tmp = L_sub(L_tmp, L_tmp1); + L_tmp1 = L_shl( L_mult( y[i], gain ), Qx ); + L_tmp = L_sub( L_tmp, L_tmp1 ); #endif - x2[i] = extract_h(L_tmp); + x2[i] = extract_h( L_tmp ); } return; } diff --git a/lib_enc/vad_basop.h b/lib_enc/vad_basop.h index 9ffeaf3ad..243731784 100644 --- a/lib_enc/vad_basop.h +++ b/lib_enc/vad_basop.h @@ -10,47 +10,39 @@ #include "stat_enc.h" Word16 vadmin( Word16 a, - Word16 b - ); + Word16 b ); Word32 vad_Sqrt_l( Word32 i_s32Val, - Word16 *io_s16Q - ); + Word16 *io_s16Q ); Word32 fft_vad_Sqrt_l( Word32 i_s32Val, Word16 i_s16Q, - Word16 *o_s16Q - ); + Word16 *o_s16Q ); T_VAD_EXP VAD_AddExp( T_VAD_EXP i_tExp1, - T_VAD_EXP i_tExp2 - ); + T_VAD_EXP i_tExp2 ); Word16 VAD_L_CMP( Word32 s32Mantissa1, Word16 i_tExp1, Word32 s32Mantissa2, - Word16 i_tExp2 - ); + Word16 i_tExp2 ); Word32 VAD_L_ADD( Word32 s32Mantissa1, Word16 i_tExp1, Word32 s32Mantissa2, Word16 i_tExp2, - Word16 *s16Exp - ); + Word16 *s16Exp ); Word32 VAD_L_div( Word32 L_var1, Word32 L_var2, Word16 Q_L_var1, Word16 Q_L_var2, - Word16 *Q_OUT - ); + Word16 *Q_OUT ); Word32 VAD_Log2( Word32 i_s32Val, - Word16 i_s16Q - ); + Word16 i_s16Q ); /*already defined in prot_fx_enc.h -Word16 ffr_getSfWord32( +Word16 ffr_getSfWord32( Word32 *vector, Word16 len );*/ @@ -59,23 +51,19 @@ Word32 VAD_Pow( Word32 i_s32Base, Word32 i_s32Exp, Word16 i_s16BaseQ, Word16 i_s16ExpQ, - Word16 *o_pOuQ - ); + Word16 *o_pOuQ ); Word32 VAD_Pow2( Word32 i_s32X, Word16 i_s16Q, - Word16 *o_pOuQ - ); + Word16 *o_pOuQ ); Word16 FixSqrt( Word32 i_s32Val, - Word16 *io_s16Q - ); + Word16 *io_s16Q ); -void cfftf( Word16* scale, +void cfftf( Word16 *scale, complex_32 *c, complex_32 *ch, - const complex_16 *wa - ); + const complex_16 *wa ); #endif diff --git a/lib_enc/vad_basop_fx.c b/lib_enc/vad_basop_fx.c index bf1d685f7..32f46ce16 100644 --- a/lib_enc/vad_basop_fx.c +++ b/lib_enc/vad_basop_fx.c @@ -5,146 +5,142 @@ #include #include "options.h" //#include "prot_fx.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ #include "vad_basop.h" #include "basop_util.h" -Word32 vad_Sqrt_l( /* o : output value, Q31 */ - Word32 i_s32Val, - Word16 *io_s16Q -) +Word32 vad_Sqrt_l( /* o : output value, Q31 */ + Word32 i_s32Val, + Word16 *io_s16Q ) { Word16 exp; Word32 result; - exp = sub(31,*io_s16Q); - result = Sqrt32(i_s32Val, &exp); - *io_s16Q = sub(31,exp); + exp = sub( 31, *io_s16Q ); + result = Sqrt32( i_s32Val, &exp ); + *io_s16Q = sub( 31, exp ); move16(); - return (result); + return ( result ); } -Word32 fft_vad_Sqrt_l( /* o : output value, Q31 */ - Word32 i_s32Val, - Word16 i_s16Q, - Word16 *o_s16Q -) +Word32 fft_vad_Sqrt_l( /* o : output value, Q31 */ + Word32 i_s32Val, + Word16 i_s16Q, + Word16 *o_s16Q ) { Word16 exp; Word32 result; - exp = sub(31, i_s16Q); - result = Sqrt32(i_s32Val, &exp); - *o_s16Q = sub(31, exp); + exp = sub( 31, i_s16Q ); + result = Sqrt32( i_s32Val, &exp ); + *o_s16Q = sub( 31, exp ); move16(); - return (result); + return ( result ); } -Word32 VAD_L_div(Word32 L_var1, Word32 L_var2,Word16 Q_L_var1,Word16 Q_L_var2,Word16 *Q_OUT ) +Word32 VAD_L_div( Word32 L_var1, Word32 L_var2, Word16 Q_L_var1, Word16 Q_L_var2, Word16 *Q_OUT ) { Word32 result; - result = L_deposit_h(BASOP_Util_Divide3232_Scale(L_var1, L_var2, Q_OUT)); + result = L_deposit_h( BASOP_Util_Divide3232_Scale( L_var1, L_var2, Q_OUT ) ); move16(); - *Q_OUT = add(sub(sub(31, *Q_OUT), Q_L_var2), Q_L_var1); + *Q_OUT = add( sub( sub( 31, *Q_OUT ), Q_L_var2 ), Q_L_var1 ); return result; } -Word32 VAD_Log2(Word32 i_s32Val, Word16 i_s16Q) +Word32 VAD_Log2( Word32 i_s32Val, Word16 i_s16Q ) { Word32 result; /* log10(x) = log2(x) * 1.0/log2(10), exponent LD_DATA_SCALE - 1 */ - result = BASOP_Util_Log2(i_s32Val); + result = BASOP_Util_Log2( i_s32Val ); - result = L_add(result, L_shl(L_deposit_l(sub(31, i_s16Q)), 31-LD_DATA_SCALE)); + result = L_add( result, L_shl( L_deposit_l( sub( 31, i_s16Q ) ), 31 - LD_DATA_SCALE ) ); return result; } -T_VAD_EXP VAD_AddExp(T_VAD_EXP i_tExp1, T_VAD_EXP i_tExp2) +T_VAD_EXP VAD_AddExp( T_VAD_EXP i_tExp1, T_VAD_EXP i_tExp2 ) { Word16 s16Shift; T_VAD_EXP tRtnVal; - if(i_tExp1.s32Mantissa == 0) + if ( i_tExp1.s32Mantissa == 0 ) { return i_tExp2; } - if(i_tExp2.s32Mantissa == 0) + if ( i_tExp2.s32Mantissa == 0 ) { return i_tExp1; } - s16Shift = sub(s_min(i_tExp1.s16Exp,i_tExp2.s16Exp),1); - tRtnVal.s32Mantissa = L_add(L_shr(i_tExp2.s32Mantissa, sub(i_tExp2.s16Exp,s16Shift)), L_shr(i_tExp1.s32Mantissa, sub(i_tExp1.s16Exp,s16Shift))); + s16Shift = sub( s_min( i_tExp1.s16Exp, i_tExp2.s16Exp ), 1 ); + tRtnVal.s32Mantissa = L_add( L_shr( i_tExp2.s32Mantissa, sub( i_tExp2.s16Exp, s16Shift ) ), L_shr( i_tExp1.s32Mantissa, sub( i_tExp1.s16Exp, s16Shift ) ) ); tRtnVal.s16Exp = s16Shift; move16(); - s16Shift = norm_l(tRtnVal.s32Mantissa); - tRtnVal.s32Mantissa = L_shl(tRtnVal.s32Mantissa, s16Shift); - tRtnVal.s16Exp = add(tRtnVal.s16Exp,s16Shift); + s16Shift = norm_l( tRtnVal.s32Mantissa ); + tRtnVal.s32Mantissa = L_shl( tRtnVal.s32Mantissa, s16Shift ); + tRtnVal.s16Exp = add( tRtnVal.s16Exp, s16Shift ); return tRtnVal; - } -Word32 VAD_L_ADD(Word32 s32Mantissa1,Word16 i_tExp1, Word32 s32Mantissa2, Word16 i_tExp2,Word16 *s16Exp) +Word32 VAD_L_ADD( Word32 s32Mantissa1, Word16 i_tExp1, Word32 s32Mantissa2, Word16 i_tExp2, Word16 *s16Exp ) { Word32 result; - result = BASOP_Util_Add_Mant32Exp(s32Mantissa1, sub(31, i_tExp1), s32Mantissa2, sub(31, i_tExp2), s16Exp); + result = BASOP_Util_Add_Mant32Exp( s32Mantissa1, sub( 31, i_tExp1 ), s32Mantissa2, sub( 31, i_tExp2 ), s16Exp ); move16(); - *s16Exp = sub(31, *s16Exp); + *s16Exp = sub( 31, *s16Exp ); return result; } -Word16 VAD_L_CMP(Word32 s32Mantissa1,Word16 i_tExp1, Word32 s32Mantissa2, Word16 i_tExp2) +Word16 VAD_L_CMP( Word32 s32Mantissa1, Word16 i_tExp1, Word32 s32Mantissa2, Word16 i_tExp2 ) { Word16 ret; - ret = BASOP_Util_Cmp_Mant32Exp(s32Mantissa1, sub(31, i_tExp1), s32Mantissa2, sub(31, i_tExp2)); + ret = BASOP_Util_Cmp_Mant32Exp( s32Mantissa1, sub( 31, i_tExp1 ), s32Mantissa2, sub( 31, i_tExp2 ) ); return ret; } -Word16 FixSqrt(Word32 i_s32Val, Word16 *io_s16Q) +Word16 FixSqrt( Word32 i_s32Val, Word16 *io_s16Q ) { Word16 result, exp; - exp = sub(31, *io_s16Q); + exp = sub( 31, *io_s16Q ); #ifdef BASOP_NOGLOB result = round_fx_sat( Sqrt32( i_s32Val, &exp ) ); #else - result = round_fx(Sqrt32(i_s32Val, &exp)); + result = round_fx( Sqrt32( i_s32Val, &exp ) ); #endif move16(); - *io_s16Q = sub(15, exp); + *io_s16Q = sub( 15, exp ); return result; } -Word32 VAD_Pow(Word32 i_s32Base, Word32 i_s32Exp, - Word16 i_s16BaseQ, Word16 i_s16ExpQ, Word16 *o_pOuQ) +Word32 VAD_Pow( Word32 i_s32Base, Word32 i_s32Exp, Word16 i_s16BaseQ, Word16 i_s16ExpQ, Word16 *o_pOuQ ) { Word32 result; - result = BASOP_Util_fPow(i_s32Base, sub(31, i_s16BaseQ), i_s32Exp, sub(31, i_s16ExpQ), o_pOuQ); + result = BASOP_Util_fPow( i_s32Base, sub( 31, i_s16BaseQ ), i_s32Exp, sub( 31, i_s16ExpQ ), o_pOuQ ); move16(); - *o_pOuQ = sub(31, *o_pOuQ); + *o_pOuQ = sub( 31, *o_pOuQ ); return result; } -Word32 VAD_Pow2(Word32 i_s32X, Word16 i_s16Q, Word16 *o_pOuQ) +Word32 VAD_Pow2( Word32 i_s32X, Word16 i_s16Q, Word16 *o_pOuQ ) { Word32 result; - result = BASOP_util_Pow2(i_s32X, sub(31, i_s16Q), o_pOuQ); + result = BASOP_util_Pow2( i_s32X, sub( 31, i_s16Q ), o_pOuQ ); move16(); - *o_pOuQ = sub(31, *o_pOuQ); + *o_pOuQ = sub( 31, *o_pOuQ ); return result; } diff --git a/lib_enc/vad_fx.c b/lib_enc/vad_fx.c index c486f7150..58c70edae 100644 --- a/lib_enc/vad_fx.c +++ b/lib_enc/vad_fx.c @@ -3,92 +3,92 @@ ====================================================================================*/ #include #include "options.h" -#include "cnst.h" /* Common constants */ +#include "cnst.h" /* Common constants */ //#include "prot_fx.h" /* Function prototypes */ #include "rom_enc.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*-----------------------------------------------------------------* * Local constants *-----------------------------------------------------------------*/ /* old fx constants */ -#define HANGOVER_LONG 10 /* Hangover for CNG */ -#define HANGOVER_LONG_HE 20 /* Hangover of CNG */ -#define HANGOVER_LONG_NB 8 /* Hangover for CNG */ -#define ACTIVE_FRAMES 3 /* Number of consecutive active SPEECH frames necessary to trigger HO */ +#define HANGOVER_LONG 10 /* Hangover for CNG */ +#define HANGOVER_LONG_HE 20 /* Hangover of CNG */ +#define HANGOVER_LONG_NB 8 /* Hangover for CNG */ +#define ACTIVE_FRAMES 3 /* Number of consecutive active SPEECH frames necessary to trigger HO */ /* SNR threshold curve constants for WB input */ -#define SK16_2_FX 16930 /* Q14 (1.0333f)-> Linear function for clean speech */ -#define SC16_2_FX -4608 /* Q8 (-18)*/ -#define NK16_2_FX 13529 /* Q15 (.41287)-> Linear function for noisy speech */ -#define NC16_2_FX 3394 /* Q8 (13.259625)*/ +#define SK16_2_FX 16930 /* Q14 (1.0333f)-> Linear function for clean speech */ +#define SC16_2_FX -4608 /* Q8 (-18)*/ +#define NK16_2_FX 13529 /* Q15 (.41287)-> Linear function for noisy speech */ +#define NC16_2_FX 3394 /* Q8 (13.259625)*/ /* SNR threshold curve constants for NB input */ -#define NK8_1_FX 3509 /*Q15 (0.1071f) Linear function for noisy speech */ -#define NC8_1_FX 4224 /*Q8 (16.5f) */ -#define SK8_1_FX 12406 /*Q15 (0.3786f) Linear function for clean speech */ -#define SC8_1_FX 2834 /*Q8 (11.07f) */ -#define SIGN_THR_FX 40 /*Q4 (2.5f) Significanse threshold for per band snr calculation */ -#define MIN_SNR_FX 2 /*Q4 Minimum snr used for per band snr calculation */ +#define NK8_1_FX 3509 /*Q15 (0.1071f) Linear function for noisy speech */ +#define NC8_1_FX 4224 /*Q8 (16.5f) */ +#define SK8_1_FX 12406 /*Q15 (0.3786f) Linear function for clean speech */ +#define SC8_1_FX 2834 /*Q8 (11.07f) */ +#define SIGN_THR_FX 40 /*Q4 (2.5f) Significanse threshold for per band snr calculation */ +#define MIN_SNR_FX 2 /*Q4 Minimum snr used for per band snr calculation */ -#define THR_M0_FX 3379 /* Q8 (13.2) Zero ofset for threshod */ -#define THR_K_BG_FX -8192 /* Q15(-0.25) Coefficient for dependence on background level */ -#define THR_K_BG_OFS_FX 5120 /* Q8 (20.0f) Zero offset for background level */ -#define THR_K_SNR_FX 3277 /* Q15 (0.1f) Coefficient for dependence on SNR */ -#define THR_K_EV_FX 18022 /* Q15 (0.55) Coefficient for dependence on noise variations */ +#define THR_M0_FX 3379 /* Q8 (13.2) Zero ofset for threshod */ +#define THR_K_BG_FX -8192 /* Q15(-0.25) Coefficient for dependence on background level */ +#define THR_K_BG_OFS_FX 5120 /* Q8 (20.0f) Zero offset for background level */ +#define THR_K_SNR_FX 3277 /* Q15 (0.1f) Coefficient for dependence on SNR */ +#define THR_K_EV_FX 18022 /* Q15 (0.55) Coefficient for dependence on noise variations */ -#define HO_DTX_CLEAN 1 /* Hangover for dtx in clean conditions */ -#define HO_DTX_NOISY 10 /* Hangover for dtx in noisy conditions */ -#define HO_DTX_NOISY2 4 /* Hangover for dtx in very noisy conditions */ -#define VAD_THR_MIN_FX 2688 +#define HO_DTX_CLEAN 1 /* Hangover for dtx in clean conditions */ +#define HO_DTX_NOISY 10 /* Hangover for dtx in noisy conditions */ +#define HO_DTX_NOISY2 4 /* Hangover for dtx in very noisy conditions */ +#define VAD_THR_MIN_FX 2688 -#define ONE_LG10 2466 /* 1.0*log10(2) in Q13 */ +#define ONE_LG10 2466 /* 1.0*log10(2) in Q13 */ -#define HANGOVER_LONG_FX 10 /* Hangover for CNG */ -#define HANGOVER_LONG_MUSIC_FX 20 /* Hangover of CNG */ -#define HANGOVER_LONG_HE_FX 20 /* Hangover of CNG */ -#define HANGOVER_LONG_NB_FX 8 /* Hangover for CNG */ -#define ACTIVE_FRAMES_FX 3 /* Number of consecutive active SPEECH frames necessary to trigger HO */ +#define HANGOVER_LONG_FX 10 /* Hangover for CNG */ +#define HANGOVER_LONG_MUSIC_FX 20 /* Hangover of CNG */ +#define HANGOVER_LONG_HE_FX 20 /* Hangover of CNG */ +#define HANGOVER_LONG_NB_FX 8 /* Hangover for CNG */ +#define ACTIVE_FRAMES_FX 3 /* Number of consecutive active SPEECH frames necessary to trigger HO */ /* SNR threshold curve constants for WB input */ -#define TH16_2_FX 8960 /* Q8 (35) -> lp SNR that separates the curves for clean speech and noisy speech */ -#define TH8_1_FX 5120 /*Q8 (20.0f) long-term SNR that separates the curves for clean speech and noisy speech */ +#define TH16_2_FX 8960 /* Q8 (35) -> lp SNR that separates the curves for clean speech and noisy speech */ +#define TH8_1_FX 5120 /*Q8 (20.0f) long-term SNR that separates the curves for clean speech and noisy speech */ -#define TH16_2_NFLAG_FX 8960 /* Q8 (35) */ -#define TH8_1_NFLAG_FX 8960 /* Q8 (35) */ +#define TH16_2_NFLAG_FX 8960 /* Q8 (35) */ +#define TH8_1_NFLAG_FX 8960 /* Q8 (35) */ -#define SNR_OUTLIER_WGHT_1_FX 16384 /* Q14 (1.00)*/ -#define SNR_OUTLIER_WGHT_2_FX 16548 /* Q14 (1.01)*/ -#define SNR_OUTLIER_WGHT_3_FX 16712 /* Q14 (1.02)*/ -#define INV_OUTLIER_THR_1_FX 3277 /* (1/10.0f) in Q15*/ -#define INV_OUTLIER_THR_2_FX 5461 /* (1/6.0f) in Q15 */ +#define SNR_OUTLIER_WGHT_1_FX 16384 /* Q14 (1.00)*/ +#define SNR_OUTLIER_WGHT_2_FX 16548 /* Q14 (1.01)*/ +#define SNR_OUTLIER_WGHT_3_FX 16712 /* Q14 (1.02)*/ +#define INV_OUTLIER_THR_1_FX 3277 /* (1/10.0f) in Q15*/ +#define INV_OUTLIER_THR_2_FX 5461 /* (1/6.0f) in Q15 */ -#define MAX_SNR_OUTLIER_IND_FX 17 /*Q0 */ -#define MAX_SNR_OUTLIER_1_FX 160 /*Q4 (10.0f)*/ -#define MAX_SNR_OUTLIER_2_FX 400 /*Q4 (25.0f)*/ -#define MAX_SNR_OUTLIER_3_FX 800 /*Q4 (50.0f)*/ +#define MAX_SNR_OUTLIER_IND_FX 17 /*Q0 */ +#define MAX_SNR_OUTLIER_1_FX 160 /*Q4 (10.0f)*/ +#define MAX_SNR_OUTLIER_2_FX 400 /*Q4 (25.0f)*/ +#define MAX_SNR_OUTLIER_3_FX 800 /*Q4 (50.0f)*/ /* snr_sum = "scale" * (float)log10( L_snr_sum ) ;*/ -static Word16 vad_snr_log_fx( /* o: Q8 */ - Word32 L_snr, /* i: Q4 */ - Word16 scale/* i: scale Q13 , 10.0*log10(2) or 1.0*log10(2) */ +static Word16 vad_snr_log_fx( /* o: Q8 */ + Word32 L_snr, /* i: Q4 */ + Word16 scale /* i: scale Q13 , 10.0*log10(2) or 1.0*log10(2) */ ) { - Word16 e_snr,f_snr; + Word16 e_snr, f_snr; Word32 L_tmp; - e_snr = norm_l(L_snr); - f_snr = Log2_norm_lc(L_shl(L_snr, e_snr)); - e_snr = sub(30-4, e_snr); - L_tmp=Mpy_32_16(e_snr, f_snr, scale); - return round_fx(L_shl(L_tmp, 10)); /* Q8 */ + e_snr = norm_l( L_snr ); + f_snr = Log2_norm_lc( L_shl( L_snr, e_snr ) ); + e_snr = sub( 30 - 4, e_snr ); + L_tmp = Mpy_32_16( e_snr, f_snr, scale ); + return round_fx( L_shl( L_tmp, 10 ) ); /* Q8 */ } @@ -96,31 +96,31 @@ void wb_vad_init_fx( VAD_HANDLE hVAD /* i/o: VAD data handle */ ) { - hVAD->hangover_cnt = 0; - move16(); /* Hangover counter initialized to 0 */ + hVAD->hangover_cnt = 0; + move16(); /* Hangover counter initialized to 0 */ hVAD->nb_active_frames = ACTIVE_FRAMES_FX; - move16(); /* The counter of SPEECH frames necessary to trigger HO */ + move16(); /* The counter of SPEECH frames necessary to trigger HO */ /* is set to max (-> start with hangover) */ - hVAD->vad_flag_reg_H = L_deposit_l(0); - hVAD->vad_flag_reg_L = L_deposit_l(0); - hVAD->vad_prim_reg = L_deposit_l(0); + hVAD->vad_flag_reg_H = L_deposit_l( 0 ); + hVAD->vad_flag_reg_L = L_deposit_l( 0 ); + hVAD->vad_prim_reg = L_deposit_l( 0 ); hVAD->vad_flag_cnt_50 = 0; move16(); hVAD->vad_prim_cnt_16 = 0; move16(); hVAD->hangover_cnt_dtx = HANGOVER_LONG_FX; - move16(); /* hangover for DTX */ + move16(); /* hangover for DTX */ hVAD->hangover_cnt_music = HANGOVER_LONG_MUSIC_FX; - move16(); /* hangover for MUSIC DTX */ + move16(); /* hangover for MUSIC DTX */ hVAD->hangover_cnt_he = 0; - move16(); /* Hangover counter initialized to 0 */ + move16(); /* Hangover counter initialized to 0 */ hVAD->nb_active_frames_he = ACTIVE_FRAMES_FX; - move16(); /* The counter of SPEECH frames necessary to trigger HO */ + move16(); /* The counter of SPEECH frames necessary to trigger HO */ hVAD->bcg_flux_fx = 1120; - move16(); /*70 in Q4 */ + move16(); /*70 in Q4 */ hVAD->soft_hangover = 0; move16(); hVAD->voiced_burst = 0; @@ -138,31 +138,31 @@ void wb_vad_init_ivas_fx( VAD_HANDLE hVAD /* i/o: VAD data handle */ ) { - hVAD->hangover_cnt = 0; - move16(); /* Hangover counter initialized to 0 */ + hVAD->hangover_cnt = 0; + move16(); /* Hangover counter initialized to 0 */ hVAD->nb_active_frames = ACTIVE_FRAMES_FX; - move16(); /* The counter of SPEECH frames necessary to trigger HO */ + move16(); /* The counter of SPEECH frames necessary to trigger HO */ /* is set to max (-> start with hangover) */ - hVAD->vad_flag_reg_H = L_deposit_l(0); - hVAD->vad_flag_reg_L = L_deposit_l(0); - hVAD->vad_prim_reg = L_deposit_l(0); + hVAD->vad_flag_reg_H = L_deposit_l( 0 ); + hVAD->vad_flag_reg_L = L_deposit_l( 0 ); + hVAD->vad_prim_reg = L_deposit_l( 0 ); hVAD->vad_flag_cnt_50 = 0; move16(); hVAD->vad_prim_cnt_16 = 0; move16(); hVAD->hangover_cnt_dtx = HANGOVER_LONG_FX; - move16(); /* hangover for DTX */ + move16(); /* hangover for DTX */ hVAD->hangover_cnt_music = HANGOVER_LONG_MUSIC_FX; - move16(); /* hangover for MUSIC DTX */ + move16(); /* hangover for MUSIC DTX */ hVAD->hangover_cnt_he = 0; - move16(); /* Hangover counter initialized to 0 */ + move16(); /* Hangover counter initialized to 0 */ hVAD->nb_active_frames_he = ACTIVE_FRAMES_FX; - move16(); /* The counter of SPEECH frames necessary to trigger HO */ + move16(); /* The counter of SPEECH frames necessary to trigger HO */ hVAD->bcg_flux_fx = 1120; - move16(); /*70 in Q4 */ + move16(); /*70 in Q4 */ hVAD->soft_hangover = 0; move16(); hVAD->voiced_burst = 0; @@ -209,10 +209,10 @@ void wb_vad_init_ivas_fx( * accumulate snr_sum with significance thresholds *-----------------------------------------------------------------*/ static void sign_thr_snr_acc_fx( - Word32 *L_snr_sum, /* o: Q4 */ - Word32 L_snr, /* i: Q4 */ - Word16 sign_thr, /* i: Q4 */ - Word16 min_snr /* i: Q4 */ + Word32 *L_snr_sum, /* o: Q4 */ + Word32 L_snr, /* i: Q4 */ + Word16 sign_thr, /* i: Q4 */ + Word16 min_snr /* i: Q4 */ ) { /*if( snr >= sign_thr ) */ @@ -221,17 +221,17 @@ static void sign_thr_snr_acc_fx( Flag Overflow = 0; #endif - L_tmp = L_deposit_l(min_snr); - if( GE_32(L_snr, L_deposit_l(sign_thr))) + L_tmp = L_deposit_l( min_snr ); + if ( GE_32( L_snr, L_deposit_l( sign_thr ) ) ) { - L_tmp = L_add(L_snr, 0); + L_tmp = L_add( L_snr, 0 ); } - BASOP_SATURATE_WARNING_OFF_EVS /* may saturate in BASOP */ + BASOP_SATURATE_WARNING_OFF_EVS /* may saturate in BASOP */ #ifdef BASOP_NOGLOB - *L_snr_sum = L_add_o(*L_snr_sum, L_tmp, &Overflow); /* Q4 */ -#else /* BASOP_NOGLOB */ - *L_snr_sum = L_add(*L_snr_sum, L_tmp); /* Q4 */ -#endif /* BASOP_NOGLOB */ + *L_snr_sum = L_add_o( *L_snr_sum, L_tmp, &Overflow ); /* Q4 */ +#else /* BASOP_NOGLOB */ + *L_snr_sum = L_add( *L_snr_sum, L_tmp ); /* Q4 */ +#endif /* BASOP_NOGLOB */ BASOP_SATURATE_WARNING_ON_EVS } @@ -241,25 +241,25 @@ static void sign_thr_snr_acc_fx( *-----------------------------------------------------------------*/ Word16 dtx_hangover_addition_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 vad_flag, /* i Q0 */ - const Word16 lp_snr, /* i Q8 */ - const Word16 cldfb_subtraction, /* i Q0 number of DTX-HO frames CLDFB wants to reduce */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word16 vad_flag, /* i Q0 */ + const Word16 lp_snr, /* i Q8 */ + const Word16 cldfb_subtraction, /* i Q0 number of DTX-HO frames CLDFB wants to reduce */ Word16 *vad_hover_flag_ptr, - VAD_HANDLE hVAD, /* i/o: VAD data handle */ - NOISE_EST_HANDLE hNoiseEst /* i : Noise estimation handle */ + VAD_HANDLE hVAD, /* i/o: VAD data handle */ + NOISE_EST_HANDLE hNoiseEst /* i : Noise estimation handle */ ) { - Word16 hangover_short_dtx ; - Word16 flag_dtx ; + Word16 hangover_short_dtx; + Word16 flag_dtx; Word16 tmp; - if (hNoiseEst == NULL) + if ( hNoiseEst == NULL ) { hNoiseEst = st_fx->hNoiseEst; move16(); } - if (hVAD == NULL) + if ( hVAD == NULL ) { move16(); hVAD = st_fx->hVAD; @@ -275,67 +275,58 @@ Word16 dtx_hangover_addition_fx( test(); test(); - if ( ( ( LT_16(lp_snr,(16*256))) - && ( NE_16(st_fx->input_bwidth, NB) )) - || ( GT_16(hVAD->prim_act_he_fx, 31130) ) ) /*.95*Q15*/ + if ( ( ( LT_16( lp_snr, ( 16 * 256 ) ) ) && ( NE_16( st_fx->input_bwidth, NB ) ) ) || ( GT_16( hVAD->prim_act_he_fx, 31130 ) ) ) /*.95*Q15*/ { hangover_short_dtx = 3; move16(); } /* Adjust hangover according to activity history */ - if (GT_16(hVAD->vad_prim_cnt_16, 12)) /* 12 requires roughly > 80% primary activity */ + if ( GT_16( hVAD->vad_prim_cnt_16, 12 ) ) /* 12 requires roughly > 80% primary activity */ { - hangover_short_dtx = add(hangover_short_dtx,2); + hangover_short_dtx = add( hangover_short_dtx, 2 ); } - if (GT_16(hVAD->vad_flag_cnt_50, 40)) /* 40 requires roughtly > 80% flag activity */ + if ( GT_16( hVAD->vad_flag_cnt_50, 40 ) ) /* 40 requires roughtly > 80% flag activity */ { - hangover_short_dtx = add(hangover_short_dtx,5); + hangover_short_dtx = add( hangover_short_dtx, 5 ); } /* Keep hangover_short lower than maximum hangover count */ - if (GT_16(hangover_short_dtx, HANGOVER_LONG_FX-1)) + if ( GT_16( hangover_short_dtx, HANGOVER_LONG_FX - 1 ) ) { - hangover_short_dtx = (HANGOVER_LONG_FX-1); + hangover_short_dtx = ( HANGOVER_LONG_FX - 1 ); move16(); } /* Only allow short HO if not sufficient active frames in clean speech*/ tmp = 3; - move16(); /* default for EVS*/ - if (EQ_16(st_fx->core,AMR_WB_CORE)) + move16(); /* default for EVS*/ + if ( EQ_16( st_fx->core, AMR_WB_CORE ) ) { tmp = 2; - move16(); /* default for AMRWBIO*/ + move16(); /* default for AMRWBIO*/ } /* need to be a bit stricter with the DTXHO in very clean WB, SWB cond for EVS12k8VAD section */ test(); test(); - if ( ( NE_16(st_fx->input_bwidth, NB)) /* WB or SWB or FB */ - && ( NE_16(st_fx->core, AMR_WB_CORE) ) - && ( GT_16(lp_snr, 25*256) ) - ) + if ( ( NE_16( st_fx->input_bwidth, NB ) ) /* WB or SWB or FB */ + && ( NE_16( st_fx->core, AMR_WB_CORE ) ) && ( GT_16( lp_snr, 25 * 256 ) ) ) { tmp = 2; move16(); } /* limit dtx hangover addition up to "tmp" frames in clean cond */ - IF ( tmp != 0 ) + IF( tmp != 0 ) { test(); test(); test(); - if ( (GT_16(hangover_short_dtx, tmp)) - && ( (LT_16(hVAD->vad_prim_cnt_16, 7) ) - || ( (GT_16(lp_snr, (16*256)) ) - && (LT_16(hVAD->prim_act_he_fx, 27853) ) /*0.85f*2^15 */ - ) - ) - ) + if ( ( GT_16( hangover_short_dtx, tmp ) ) && ( ( LT_16( hVAD->vad_prim_cnt_16, 7 ) ) || ( ( GT_16( lp_snr, ( 16 * 256 ) ) ) && ( LT_16( hVAD->prim_act_he_fx, 27853 ) ) /*0.85f*2^15 */ + ) ) ) { hangover_short_dtx = tmp; move16(); @@ -344,21 +335,20 @@ Word16 dtx_hangover_addition_fx( /* hangover adjustment from combined FFT+CLDFBVAD */ - IF (NE_16(st_fx->core,AMR_WB_CORE)) + IF( NE_16( st_fx->core, AMR_WB_CORE ) ) { - hangover_short_dtx = sub(hangover_short_dtx, cldfb_subtraction); - hangover_short_dtx = s_max(hangover_short_dtx, 0); + hangover_short_dtx = sub( hangover_short_dtx, cldfb_subtraction ); + hangover_short_dtx = s_max( hangover_short_dtx, 0 ); } - IF ( vad_flag != 0 ) /* Speech present */ + IF( vad_flag != 0 ) /* Speech present */ { flag_dtx = 1; move16(); /* Add hangover after sufficient # of active frames or sufficient activity during last second */ test(); - if ( ( GE_16(hVAD->nb_active_frames, ACTIVE_FRAMES_FX)) - || (GT_16(hVAD->vad_flag_cnt_50,45)) ) /* 45 requires roughly > 90% flag activity */ + if ( ( GE_16( hVAD->nb_active_frames, ACTIVE_FRAMES_FX ) ) || ( GT_16( hVAD->vad_flag_cnt_50, 45 ) ) ) /* 45 requires roughly > 90% flag activity */ { hVAD->hangover_cnt_dtx = 0; move16(); @@ -366,22 +356,18 @@ Word16 dtx_hangover_addition_fx( /* inside HO period */ test(); - if( ( LT_16(hVAD->hangover_cnt_dtx, HANGOVER_LONG_FX)) - && (hVAD->hangover_cnt_dtx != 0) ) + if ( ( LT_16( hVAD->hangover_cnt_dtx, HANGOVER_LONG_FX ) ) && ( hVAD->hangover_cnt_dtx != 0 ) ) { - hVAD->hangover_cnt_dtx = add(hVAD->hangover_cnt_dtx, 1); + hVAD->hangover_cnt_dtx = add( hVAD->hangover_cnt_dtx, 1 ); } hVAD->hangover_terminate_flag = 0; - move16();/* float fix FIX_HO_TERMINATE */ + move16(); /* float fix FIX_HO_TERMINATE */ /* Music hangover when music detected */ test(); test(); test(); - if ( (GT_16(hVAD->prim_act_he_fx,31129)) - && (GT_16(hNoiseEst->Etot_lp_fx,40*256) ) - && (GT_16(hVAD->vad_prim_cnt_16,14) ) - && (GT_16(hVAD->vad_flag_cnt_50,48) ) ) /* 45 requires roughly > 95% flag activity */ + if ( ( GT_16( hVAD->prim_act_he_fx, 31129 ) ) && ( GT_16( hNoiseEst->Etot_lp_fx, 40 * 256 ) ) && ( GT_16( hVAD->vad_prim_cnt_16, 14 ) ) && ( GT_16( hVAD->vad_flag_cnt_50, 48 ) ) ) /* 45 requires roughly > 95% flag activity */ { hVAD->hangover_cnt_music = 0; move16(); @@ -389,26 +375,25 @@ Word16 dtx_hangover_addition_fx( /* inside Music HO period */ test(); - if( ( LT_16(hVAD->hangover_cnt_music, HANGOVER_LONG_MUSIC_FX)) - && (hVAD->hangover_cnt_music != 0) ) + if ( ( LT_16( hVAD->hangover_cnt_music, HANGOVER_LONG_MUSIC_FX ) ) && ( hVAD->hangover_cnt_music != 0 ) ) { - hVAD->hangover_cnt_music = add(hVAD->hangover_cnt_music, 1); + hVAD->hangover_cnt_music = add( hVAD->hangover_cnt_music, 1 ); } } ELSE { /* Reset the counter of speech frames necessary to start hangover algorithm */ - if(LT_16(hVAD->hangover_cnt_dtx,HANGOVER_LONG_FX)) /* inside HO period */ + if ( LT_16( hVAD->hangover_cnt_dtx, HANGOVER_LONG_FX ) ) /* inside HO period */ { - hVAD->hangover_cnt_dtx = add(hVAD->hangover_cnt_dtx,1); + hVAD->hangover_cnt_dtx = add( hVAD->hangover_cnt_dtx, 1 ); } - if(LT_16(hVAD->hangover_cnt_music,HANGOVER_LONG_MUSIC_FX)) /* inside HO period */ + if ( LT_16( hVAD->hangover_cnt_music, HANGOVER_LONG_MUSIC_FX ) ) /* inside HO period */ { - hVAD->hangover_cnt_music = add(hVAD->hangover_cnt_music,1); + hVAD->hangover_cnt_music = add( hVAD->hangover_cnt_music, 1 ); } /* fast terminate DTX hangover if st->hangover_terminate_flag is set */ - IF ( hVAD->hangover_terminate_flag != 0 ) + IF( hVAD->hangover_terminate_flag != 0 ) { hVAD->hangover_cnt = HANGOVER_LONG_FX; move16(); @@ -417,20 +402,20 @@ Word16 dtx_hangover_addition_fx( hVAD->hangover_terminate_flag = 0; move16(); /* Only shorten music hangover when low energy frames */ - if (LT_16(hNoiseEst->Etot_lp_fx,20*256)) + if ( LT_16( hNoiseEst->Etot_lp_fx, 20 * 256 ) ) { - hVAD->hangover_cnt_music = HANGOVER_LONG_MUSIC_FX; + hVAD->hangover_cnt_music = HANGOVER_LONG_MUSIC_FX; move16(); } } - if( LE_16(hVAD->hangover_cnt_dtx, hangover_short_dtx)) /* "hard" hangover */ + if ( LE_16( hVAD->hangover_cnt_dtx, hangover_short_dtx ) ) /* "hard" hangover */ { flag_dtx = 1; move16(); } - if( LE_16(hVAD->hangover_cnt_music, 15)) /* "hard" hangover music */ + if ( LE_16( hVAD->hangover_cnt_music, 15 ) ) /* "hard" hangover music */ { flag_dtx = 1; move16(); @@ -438,7 +423,6 @@ Word16 dtx_hangover_addition_fx( } - test(); if ( flag_dtx != 0 && st_fx->localVAD == 0 ) { @@ -446,7 +430,7 @@ Word16 dtx_hangover_addition_fx( move16(); } - return flag_dtx ; + return flag_dtx; } /*-----------------------------------------------------------------* @@ -456,32 +440,32 @@ Word16 dtx_hangover_addition_fx( *-----------------------------------------------------------------*/ /* new simplified and harmonized code */ Word16 wb_vad_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word32 fr_bands[], /* i : per band input energy (contains 2 vectors) Q_new+QSCALE*/ - Word16 *noisy_speech_HO, /* o : SC-VBR noisy speech HO flag */ - Word16 *clean_speech_HO, /* o : SC-VBR clean speech HO flag */ - Word16 *NB_speech_HO, /* o : SC-VBR NB speech HO flag */ - Word16 *snr_sum_he, /* o : Output snr_sum as weighted spectral measure*/ + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word32 fr_bands[], /* i : per band input energy (contains 2 vectors) Q_new+QSCALE*/ + Word16 *noisy_speech_HO, /* o : SC-VBR noisy speech HO flag */ + Word16 *clean_speech_HO, /* o : SC-VBR clean speech HO flag */ + Word16 *NB_speech_HO, /* o : SC-VBR NB speech HO flag */ + Word16 *snr_sum_he, /* o : Output snr_sum as weighted spectral measure*/ Word16 *localVAD_HE_SAD, - Word8 *flag_noisy_speech_snr , /* o : */ - const Word16 Q_new, /* i : scaling factor Q0 */ - VAD_HANDLE hVAD, /* i/o: VAD data handle */ - NOISE_EST_HANDLE hNoiseEst, /* i : Noise estimation handle */ - Word16 lp_speech_fx, /* i : long term active speech energy average */ - Word16 lp_noise_fx /* i : long term noise energy */ + Word8 *flag_noisy_speech_snr, /* o : */ + const Word16 Q_new, /* i : scaling factor Q0 */ + VAD_HANDLE hVAD, /* i/o: VAD data handle */ + NOISE_EST_HANDLE hNoiseEst, /* i : Noise estimation handle */ + Word16 lp_speech_fx, /* i : long term active speech energy average */ + Word16 lp_noise_fx /* i : long term noise energy */ ) { - Word16 i, flag=0, hangover_short; + Word16 i, flag = 0, hangover_short; - Word16 snr_sum, thr1=0, thr1_nb_mod, thr2=0, nk=0, nc=0, th_clean=0; - Word16 lp_snr; /* Q8 */ + Word16 snr_sum, thr1 = 0, thr1_nb_mod, thr2 = 0, nk = 0, nc = 0, th_clean = 0; + Word16 lp_snr; /* Q8 */ const Word32 *pt1; const Word32 *pt2; const Word32 *pt3; Word16 min_snr, sign_thr; - Word32 L_snr, L_snr_sum ; + Word32 L_snr, L_snr_sum; Word32 ftmp, ftmp1, ftmp2; Word16 m_noise_local, e_noise, e_num, m_num, snr, snr_tmp, shift_snr; @@ -489,28 +473,28 @@ Word16 wb_vad_fx( Word32 L_vad_thr; Word16 hangover_hd; Word16 snr_idx; - Word16 delta1, delta2, delta3,delta4; + Word16 delta1, delta2, delta3, delta4; Word16 flag_he1; Word16 stmp; - Word32 L_msnr, L_mssnr=0, L_mssnr_hov; - Word16 j, tmp, tmp1, tmp2 ; + Word32 L_msnr, L_mssnr = 0, L_mssnr_hov; + Word16 j, tmp, tmp1, tmp2; Word32 L_tmp, L_tmp1, L_tmp2; - Word32 L_snr18, L_snr19; /* Q4 */ - Word32 L_msnr18, L_msnr19; /* Q13 */ - Word16 nb_sig_snr; /* Q0 */ + Word32 L_snr18, L_snr19; /* Q4 */ + Word32 L_msnr18, L_msnr19; /* Q13 */ + Word16 nb_sig_snr; /* Q0 */ Word16 nv; - Word16 nv_ofs; /* Q8 */ + Word16 nv_ofs; /* Q8 */ Word32 L_snr_sum_HE_SAD; /* Q4 */ Word16 snr_sum_HE_SAD; /*Q8 log */ Word16 sign_thr_HE_SAD, min_snr_HE_SAD; - Word16 thr1_ol; - Word32 L_snr_sum_ol; - Word16 snr_sum_ol; /* Q8 log */ + Word16 thr1_ol; + Word32 L_snr_sum_ol; + Word16 snr_sum_ol; /* Q8 log */ Word32 L_snr_outlier; Word16 snr_outlier_index; @@ -522,24 +506,24 @@ Word16 wb_vad_fx( Flag Overflow = 0; #endif - if (hNoiseEst == NULL) + if ( hNoiseEst == NULL ) { hNoiseEst = st_fx->hNoiseEst; move16(); } - if (hVAD == NULL) + if ( hVAD == NULL ) { move16(); hVAD = st_fx->hVAD; } - if ( LT_16(lp_speech_fx , -100*256)) + if ( LT_16( lp_speech_fx, -100 * 256 ) ) { - lp_speech_fx = st_fx->lp_speech_fx; + lp_speech_fx = st_fx->lp_speech_fx; move16(); } - if (LT_16(lp_noise_fx, -100*256)) + if ( LT_16( lp_noise_fx, -100 * 256 ) ) { lp_noise_fx = st_fx->lp_noise_fx; move16(); @@ -548,19 +532,19 @@ Word16 wb_vad_fx( vad_bwidth_fx = st_fx->input_bwidth; move16(); - L_snr_outlier = L_deposit_l(0); + L_snr_outlier = L_deposit_l( 0 ); snr_outlier_index = 0; move16(); - L_accum_ener_L = L_deposit_l(0); - L_accum_ener_H = L_deposit_l(0); + L_accum_ener_L = L_deposit_l( 0 ); + L_accum_ener_H = L_deposit_l( 0 ); - L_snr18 = L_deposit_l(0); /* Q4*/ - L_snr19 = L_deposit_l(0); /* Q4 */ - L_msnr18 = L_deposit_l(8192); /* 1.0 Q13*/ - L_msnr19 = L_deposit_l(8192); /* 1.0 Q13 */ + L_snr18 = L_deposit_l( 0 ); /* Q4*/ + L_snr19 = L_deposit_l( 0 ); /* Q4 */ + L_msnr18 = L_deposit_l( 8192 ); /* 1.0 Q13*/ + L_msnr19 = L_deposit_l( 8192 ); /* 1.0 Q13 */ - IF( EQ_16(vad_bwidth_fx, NB)) + IF( EQ_16( vad_bwidth_fx, NB ) ) { st_fx->min_band = 1; move16(); @@ -574,16 +558,16 @@ Word16 wb_vad_fx( st_fx->max_band = 19; move16(); } - /*_DIFF_FLOAT_FIX_ -> see around Ln1570, inversion in if conditions compared to float*/ - //PMT("Error in EVS fixed point ?") - /*FIXED EVS */ - /* ELSE IF(((LE_16(st_fx->last_coder_type, UNVOICED)) && (LT_32(L_snr_outlier, MAX_SNR_OUTLIER_2_FX)) && (st_fx->Opt_SC_VBR != 0)) || - ((LE_16(last_7k2_coder_type, UNVOICED)) && (LT_32(L_snr_outlier, MAX_SNR_OUTLIER_2_FX)) && (st_fx->Opt_SC_VBR == 0)))*/ - - /*FLOAT both IVAS and EVS */ - /*if ((snr_outlier_index <= 4 && (st->last_coder_type > UNVOICED) && !st->Opt_SC_VBR) || - (snr_outlier_index <= 4 && (last_7k2_coder_type > UNVOICED) && st->Opt_SC_VBR))*/ - IF ( 1)//st_fx->Opt_SC_VBR) + /*_DIFF_FLOAT_FIX_ -> see around Ln1570, inversion in if conditions compared to float*/ + // PMT("Error in EVS fixed point ?") + /*FIXED EVS */ + /* ELSE IF(((LE_16(st_fx->last_coder_type, UNVOICED)) && (LT_32(L_snr_outlier, MAX_SNR_OUTLIER_2_FX)) && (st_fx->Opt_SC_VBR != 0)) || + ((LE_16(last_7k2_coder_type, UNVOICED)) && (LT_32(L_snr_outlier, MAX_SNR_OUTLIER_2_FX)) && (st_fx->Opt_SC_VBR == 0)))*/ + + /*FLOAT both IVAS and EVS */ + /*if ((snr_outlier_index <= 4 && (st->last_coder_type > UNVOICED) && !st->Opt_SC_VBR) || + (snr_outlier_index <= 4 && (last_7k2_coder_type > UNVOICED) && st->Opt_SC_VBR))*/ + IF( 1 ) // st_fx->Opt_SC_VBR) { last_7k2_coder_type = st_fx->hSC_VBR->last_7k2_coder_type; move16(); @@ -596,60 +580,65 @@ Word16 wb_vad_fx( /*---------------------------------------------------------------------* * set SNR thresholds depending on the input bandwitdh *---------------------------------------------------------------------*/ - IF( EQ_16(st_fx->max_band,19)) /* WB input */ /* or SWB input */ + IF( EQ_16( st_fx->max_band, 19 ) ) + /* WB input */ /* or SWB input */ { - nk = 3277; + nk = 3277; move16(); /*0.1 Q15 */ - nc = 4122 ; + nc = 4122; move16(); /*16.1 Q8 */ - nv = 525; - move16();/* 2.05 Q8*/ - nv_ofs = 422; - move16();/* 1.65 Q8*/ - th_clean = TH16_2_FX; - move16();/* 35 Q8 */ - sign_thr = 21; + nv = 525; + move16(); /* 2.05 Q8*/ + nv_ofs = 422; + move16(); /* 1.65 Q8*/ + th_clean = TH16_2_FX; + move16(); /* 35 Q8 */ + sign_thr = 21; move16(); /*1.3 Q4 */ - tmp = sub(vad_bwidth_fx, WB); + tmp = sub( vad_bwidth_fx, WB ); if ( tmp != 0 ) { - sign_thr = 28; - move16();/*1.75f; Q4 SWB */ + sign_thr = 28; + move16(); /*1.75f; Q4 SWB */ } - min_snr = 13; + min_snr = 13; move16(); /*0.8 Q4 WB */ if ( tmp != 0 ) { - min_snr = 4; + min_snr = 4; move16(); /*0.25f; Q4 SWB */ } sign_thr_HE_SAD = 40; - move16();/* 2.5f Q4 */; - min_snr_HE_SAD = 3; - move16(); /* 0.2f Q4 */; + move16(); /* 2.5f Q4 */ + ; + min_snr_HE_SAD = 3; + move16(); /* 0.2f Q4 */ + ; } - ELSE /* NB input */ + ELSE /* NB input */ { move16(); - nk = 3277; + nk = 3277; move16(); /* 0.1 Q15 */ - nc = 4096; + nc = 4096; move16(); /* 16.0 Q8 */ - nv = 1024; + nv = 1024; move16(); /* 4.0 Q8 */ - nv_ofs = 294 ; + nv_ofs = 294; move16(); /*1.15 Q8*/ - th_clean = TH8_1_FX; + th_clean = TH8_1_FX; move16(); /*20 Q8 */ - sign_thr = 28; + sign_thr = 28; move16(); /* 1.75 * Q4 SIGN_THR */ - min_snr = 4; + min_snr = 4; move16(); /* .25 *Q4 MIN_SNR */ sign_thr_HE_SAD = 42; - move16(); /* 2.65f Q4 */; - min_snr_HE_SAD = 1; - move16(); /* 0.05f Q4 */; + move16(); /* 2.65f Q4 */ + ; + min_snr_HE_SAD = 1; + move16(); /* 0.05f Q4 */ + ; } hangover_short = 0; @@ -660,7 +649,7 @@ Word16 wb_vad_fx( move16(); *clean_speech_HO = 0; move16(); - *NB_speech_HO = 0; + *NB_speech_HO = 0; move16(); /* } */ @@ -668,25 +657,25 @@ Word16 wb_vad_fx( * compute SNR for each band & total *---------------------------------------------------------------------*/ - lp_snr = sub(lp_speech_fx, lp_noise_fx); /*Q8 */ + lp_snr = sub( lp_speech_fx, lp_noise_fx ); /*Q8 */ snr_idx = 2; move16(); - if( GT_16(lp_snr,4608)) /*18.0 Q8*/ + if ( GT_16( lp_snr, 4608 ) ) /*18.0 Q8*/ { snr_idx = 1; move16(); } - if ( GT_16(lp_snr,6144)) /*24.0 Q8*/ + if ( GT_16( lp_snr, 6144 ) ) /*24.0 Q8*/ { snr_idx = 0; move16(); } - IF ( snr_idx == 0 ) + IF( snr_idx == 0 ) { - stmp = 6; + stmp = 6; move16(); delta1 = 0; move16(); /*0.0f in Q13 */ @@ -702,13 +691,13 @@ Word16 wb_vad_fx( vad_thr = min(vad_thr, 80 ); */ L_vad_thr = -345702; - move32() ; /* -42.2 Q13*/ - L_vad_thr = L_mac0(L_vad_thr,77,lp_snr) ; /* (2.4)Q5*(lp_snr)Q8 */ - L_vad_thr = L_min(L_vad_thr, 80*(1<<13) ); + move32(); /* -42.2 Q13*/ + L_vad_thr = L_mac0( L_vad_thr, 77, lp_snr ); /* (2.4)Q5*(lp_snr)Q8 */ + L_vad_thr = L_min( L_vad_thr, 80 * ( 1 << 13 ) ); } - ELSE IF ( EQ_16(snr_idx,1)) + ELSE IF( EQ_16( snr_idx, 1 ) ) { - stmp = 6; + stmp = 6; move16(); delta1 = 819; move16(); /*0.1f in Q13 */ @@ -723,13 +712,13 @@ Word16 wb_vad_fx( vad_thr = min(vad_thr, 80); */ L_vad_thr = -329318; - move32() ; /* -40.2 Q13*/ - L_vad_thr = L_mac0(L_vad_thr,77,lp_snr) ; /* (2.4)Q5*(lp_snr)Q8 */ - L_vad_thr = L_min(L_vad_thr, 80*(1<<13) ); + move32(); /* -40.2 Q13*/ + L_vad_thr = L_mac0( L_vad_thr, 77, lp_snr ); /* (2.4)Q5*(lp_snr)Q8 */ + L_vad_thr = L_min( L_vad_thr, 80 * ( 1 << 13 ) ); } ELSE { - stmp = 9; + stmp = 9; move16(); delta1 = 1638; move16(); /*0.2f in Q13 */ @@ -743,9 +732,9 @@ Word16 wb_vad_fx( vad_thr = max(vad_thr, 1); */ L_vad_thr = -81920; - move32() ; /* -10 Q13*/ - L_vad_thr = L_mac0(L_vad_thr,80,lp_snr) ; /* (2.5)Q5*(lp_snr)Q8 */ - L_vad_thr = L_max(L_vad_thr, 1*(1<<13) ); + move32(); /* -10 Q13*/ + L_vad_thr = L_mac0( L_vad_thr, 80, lp_snr ); /* (2.5)Q5*(lp_snr)Q8 */ + L_vad_thr = L_max( L_vad_thr, 1 * ( 1 << 13 ) ); } nb_sig_snr = 20; @@ -755,319 +744,313 @@ Word16 wb_vad_fx( pt2 = fr_bands + NB_BANDS; pt3 = hNoiseEst->bckr_fx; - L_snr_sum = L_deposit_l(0); - L_snr_sum_HE_SAD = L_deposit_l(0); - snr_sumt = 0; + L_snr_sum = L_deposit_l( 0 ); + L_snr_sum_HE_SAD = L_deposit_l( 0 ); + snr_sumt = 0; move16(); - L_mssnr_hov = L_deposit_l(0); - *snr_sum_he = 0; + L_mssnr_hov = L_deposit_l( 0 ); + *snr_sum_he = 0; move16(); - snr_sum_HE_SAD = 0; + snr_sum_HE_SAD = 0; move16(); - FOR( i=st_fx->min_band; i<=st_fx->max_band; i++ ) + FOR( i = st_fx->min_band; i <= st_fx->max_band; i++ ) { - ftmp = L_add(*pt1++, 0); - ftmp1 = L_add(*pt2++, 0); - ftmp2 = L_add(*pt3++, 0); + ftmp = L_add( *pt1++, 0 ); + ftmp1 = L_add( *pt2++, 0 ); + ftmp2 = L_add( *pt3++, 0 ); /*fr_enr = ( 0.2f * st->enrO[i] + 0.4f * ftmp + 0.4f * ftmp1 );*/ - L_tmp = Mult_32_16(hNoiseEst->enrO_fx[i], 13107); /* L_tmp(high word) = Qenr0fx*Q16+1 -16 -> Qener0+1 */ - L_tmp1 = Madd_32_16(L_tmp, ftmp, 26214); /* 26214 = .4 in Q16 */ - L_tmp1 = Madd_32_16(L_tmp1, ftmp1, 26214); /* L_tmp1 re_used a bit later for final snr[i]*/ + L_tmp = Mult_32_16( hNoiseEst->enrO_fx[i], 13107 ); /* L_tmp(high word) = Qenr0fx*Q16+1 -16 -> Qener0+1 */ + L_tmp1 = Madd_32_16( L_tmp, ftmp, 26214 ); /* 26214 = .4 in Q16 */ + L_tmp1 = Madd_32_16( L_tmp1, ftmp1, 26214 ); /* L_tmp1 re_used a bit later for final snr[i]*/ - L_tmp2 = Madd_32_16(L_tmp, ftmp, 19661); /* 19661 = 0.3 in Q16 */ - L_tmp2 = Msub_32_16(L_tmp2, ftmp1, -32768); /* -32768= -0.5 in Q16 */ + L_tmp2 = Madd_32_16( L_tmp, ftmp, 19661 ); /* 19661 = 0.3 in Q16 */ + L_tmp2 = Msub_32_16( L_tmp2, ftmp1, -32768 ); /* -32768= -0.5 in Q16 */ - IF (GT_32(ftmp,ftmp1)) + IF( GT_32( ftmp, ftmp1 ) ) { /*snr[i] = ( 0.2f * st->enrO[i] + 0.4f * ftmp + 0.4f * ftmp1 ) / ftmp2 ;*/ /*snr[i] = L_tmp1/(ftmp2) */ - IF (ftmp2 != 0) + IF( ftmp2 != 0 ) { - e_num = norm_l(L_tmp1); - m_num = extract_h(L_shl(L_tmp1,e_num)); + e_num = norm_l( L_tmp1 ); + m_num = extract_h( L_shl( L_tmp1, e_num ) ); - e_noise = norm_l(ftmp2); + e_noise = norm_l( ftmp2 ); m_noise_local = extract_h( L_shl( ftmp2, e_noise ) ); - m_num = shr(m_num,1); - shift_snr = add(sub(e_num, e_noise),15-4); + m_num = shr( m_num, 1 ); + shift_snr = add( sub( e_num, e_noise ), 15 - 4 ); snr_tmp = div_s( m_num, m_noise_local ); #ifdef BASOP_NOGLOB - L_snr = L_shr_o(snr_tmp, shift_snr, &Overflow); /* L_snr in Q4 */ -#else /* BASOP_NOGLOB */ - L_snr = L_shr(snr_tmp, shift_snr); /* L_snr in Q4 */ -#endif /* BASOP_NOGLOB */ + L_snr = L_shr_o( snr_tmp, shift_snr, &Overflow ); /* L_snr in Q4 */ +#else /* BASOP_NOGLOB */ + L_snr = L_shr( snr_tmp, shift_snr ); /* L_snr in Q4 */ +#endif /* BASOP_NOGLOB */ } ELSE { - e_num = norm_l(L_tmp1); - m_num = extract_h(L_shl(L_tmp1,e_num)); + e_num = norm_l( L_tmp1 ); + m_num = extract_h( L_shl( L_tmp1, e_num ) ); /* if bckr[i] == 0; approx. L_snr */ - e_noise = add(30+1, abs_s(Q_new)); + e_noise = add( 30 + 1, abs_s( Q_new ) ); - m_num = shr(m_num, 1); - shift_snr = add(sub(e_num, e_noise), 15-4); + m_num = shr( m_num, 1 ); + shift_snr = add( sub( e_num, e_noise ), 15 - 4 ); - snr_tmp = div_s(m_num, 32767); - L_snr = L_shr(snr_tmp, shift_snr); /*L_snr in Q4*/ + snr_tmp = div_s( m_num, 32767 ); + L_snr = L_shr( snr_tmp, shift_snr ); /*L_snr in Q4*/ } } ELSE { /*snr[i] = ( 0.2f * st->enrO[i] + 0.3f * ftmp + 0.5f * ftmp1 ) / ftmp2 ;*/ /*snr[i] =L_tmp2/( ftmp2 ) */ - IF (ftmp2 != 0) + IF( ftmp2 != 0 ) { - e_num = norm_l(L_tmp2); - m_num = extract_h(L_shl(L_tmp2,e_num)); + e_num = norm_l( L_tmp2 ); + m_num = extract_h( L_shl( L_tmp2, e_num ) ); - e_noise = norm_l(ftmp2); + e_noise = norm_l( ftmp2 ); m_noise_local = extract_h( L_shl( ftmp2, e_noise ) ); - m_num = shr(m_num,1); - shift_snr = add(sub(e_num, e_noise),15-4); + m_num = shr( m_num, 1 ); + shift_snr = add( sub( e_num, e_noise ), 15 - 4 ); snr_tmp = div_s( m_num, m_noise_local ); #ifdef BASOP_NOGLOB - L_snr = L_shr_o(snr_tmp, shift_snr, &Overflow); /* L_snr in Q4 */ -#else /* BASOP_NOGLOB */ - L_snr = L_shr(snr_tmp, shift_snr); /* L_snr in Q4 */ -#endif /* BASOP_NOGLOB */ + L_snr = L_shr_o( snr_tmp, shift_snr, &Overflow ); /* L_snr in Q4 */ +#else /* BASOP_NOGLOB */ + L_snr = L_shr( snr_tmp, shift_snr ); /* L_snr in Q4 */ +#endif /* BASOP_NOGLOB */ } ELSE { - e_num = norm_l(L_tmp2); - m_num = extract_h(L_shl(L_tmp2,e_num)); + e_num = norm_l( L_tmp2 ); + m_num = extract_h( L_shl( L_tmp2, e_num ) ); /* if bckr[i] == 0; approx. L_snr */ - e_noise = add(30+1, abs_s(Q_new)); + e_noise = add( 30 + 1, abs_s( Q_new ) ); - m_num = shr(m_num, 1); - shift_snr = add(sub(e_num, e_noise), 15-4); + m_num = shr( m_num, 1 ); + shift_snr = add( sub( e_num, e_noise ), 15 - 4 ); - snr_tmp = div_s(m_num, 32767); - L_snr = L_shr(snr_tmp, shift_snr); /*L_snr in Q4*/ + snr_tmp = div_s( m_num, 32767 ); + L_snr = L_shr( snr_tmp, shift_snr ); /*L_snr in Q4*/ } } - if(LT_32(L_snr,2*(1<<4))) + if ( LT_32( L_snr, 2 * ( 1 << 4 ) ) ) { - nb_sig_snr=sub(nb_sig_snr,1); /* nb_sig_snr--; */ + nb_sig_snr = sub( nb_sig_snr, 1 ); /* nb_sig_snr--; */ } - L_snr = L_max(L_snr, 1*(1<<4)); /* if ( snr[i] < 1 ){snr[i] = 1;}*/ + L_snr = L_max( L_snr, 1 * ( 1 << 4 ) ); /* if ( snr[i] < 1 ){snr[i] = 1;}*/ /* snr[i] = (float)log10(snr[i]); */ - snr = vad_snr_log_fx(L_snr, ONE_LG10); + snr = vad_snr_log_fx( L_snr, ONE_LG10 ); /* snr_sumt += snr[i];*/ - snr_sumt = add(snr_sumt,shr(snr,4)); /*Q4 */ + snr_sumt = add( snr_sumt, shr( snr, 4 ) ); /*Q4 */ #ifdef BASOP_NOGLOB - tmp = shl_o(snr,5, &Overflow); /* Q8 -> Q13 */ -#else /* BASOP_NOGLOB */ - tmp = shl(snr,5); /* Q8 -> Q13 */ -#endif /* BASOP_NOGLOB */ - IF (LT_16(i,2)) + tmp = shl_o( snr, 5, &Overflow ); /* Q8 -> Q13 */ +#else /* BASOP_NOGLOB */ + tmp = shl( snr, 5 ); /* Q8 -> Q13 */ +#endif /* BASOP_NOGLOB */ + IF( LT_16( i, 2 ) ) { #ifdef BASOP_NOGLOB - tmp = add_o(tmp,delta1, &Overflow); /*Q13 */ -#else /* BASOP_NOGLOB */ - tmp = add(tmp,delta1); /*Q13 */ -#endif /* BASOP_NOGLOB */ + tmp = add_o( tmp, delta1, &Overflow ); /*Q13 */ +#else /* BASOP_NOGLOB */ + tmp = add( tmp, delta1 ); /*Q13 */ +#endif /* BASOP_NOGLOB */ } - ELSE IF (LT_16(i,7)) + ELSE IF( LT_16( i, 7 ) ) { #ifdef BASOP_NOGLOB - tmp = add_o(tmp,delta2, &Overflow); /*Q13 */ -#else /* BASOP_NOGLOB */ - tmp = add(tmp,delta2); /*Q13 */ -#endif /* BASOP_NOGLOB */ + tmp = add_o( tmp, delta2, &Overflow ); /*Q13 */ +#else /* BASOP_NOGLOB */ + tmp = add( tmp, delta2 ); /*Q13 */ +#endif /* BASOP_NOGLOB */ } - ELSE IF (LT_16(i,18)) + ELSE IF( LT_16( i, 18 ) ) { #ifdef BASOP_NOGLOB - tmp = add_o(tmp,delta3, &Overflow); /*Q13 */ -#else /* BASOP_NOGLOB */ - tmp = add(tmp,delta3); /*Q13 */ -#endif /* BASOP_NOGLOB */ + tmp = add_o( tmp, delta3, &Overflow ); /*Q13 */ +#else /* BASOP_NOGLOB */ + tmp = add( tmp, delta3 ); /*Q13 */ +#endif /* BASOP_NOGLOB */ } ELSE { #ifdef BASOP_NOGLOB - tmp = add_o(tmp,delta4, &Overflow); /*Q13 */ -#else /* BASOP_NOGLOB */ - tmp = add(tmp,delta4); /*Q13 */ -#endif /* BASOP_NOGLOB */ + tmp = add_o( tmp, delta4, &Overflow ); /*Q13 */ +#else /* BASOP_NOGLOB */ + tmp = add( tmp, delta4 ); /*Q13 */ +#endif /* BASOP_NOGLOB */ } - tmp1=tmp; - move16(); /* ftmp1 = ftmp; */ - sub(0,0); + tmp1 = tmp; + move16(); /* ftmp1 = ftmp; */ + sub( 0, 0 ); if ( i < 7 ) { #ifdef BASOP_NOGLOB - tmp1=add_o(tmp,3277, &Overflow); /*.4 in Q13 ftmp1 = ftmp + 0.4f; */ -#else /* BASOP_NOGLOB */ - tmp1=add(tmp,3277); /*.4 in Q13 ftmp1 = ftmp + 0.4f; */ -#endif /* BASOP_NOGLOB */ + tmp1 = add_o( tmp, 3277, &Overflow ); /*.4 in Q13 ftmp1 = ftmp + 0.4f; */ +#else /* BASOP_NOGLOB */ + tmp1 = add( tmp, 3277 ); /*.4 in Q13 ftmp1 = ftmp + 0.4f; */ +#endif /* BASOP_NOGLOB */ } - tmp=s_min(tmp,16384); /* Q13, ftmp = min(ftmp, 2.0f); */ - tmp1=s_min(tmp1,16384); /* Q13, ftmp1 = min(ftmp1, 2.0f); */ + tmp = s_min( tmp, 16384 ); /* Q13, ftmp = min(ftmp, 2.0f); */ + tmp1 = s_min( tmp1, 16384 ); /* Q13, ftmp1 = min(ftmp1, 2.0f); */ - L_msnr = L_deposit_l(tmp); /*msnr = 1*tmp;*/ - FOR (j=1; jbckr[i] = L_tmp1/st->bckr[i];*/ - IF (hNoiseEst->bckr_fx[i] != 0) + IF( hNoiseEst->bckr_fx[i] != 0 ) { - e_num = norm_l(L_tmp1); - m_num = extract_h(L_shl(L_tmp1,e_num)); + e_num = norm_l( L_tmp1 ); + m_num = extract_h( L_shl( L_tmp1, e_num ) ); - e_noise = norm_l(hNoiseEst->bckr_fx[i]); + e_noise = norm_l( hNoiseEst->bckr_fx[i] ); m_noise_local = extract_h( L_shl( hNoiseEst->bckr_fx[i], e_noise ) ); - m_num = shr(m_num,1); - shift_snr = add(sub(e_num, e_noise),15-4); + m_num = shr( m_num, 1 ); + shift_snr = add( sub( e_num, e_noise ), 15 - 4 ); snr_tmp = div_s( m_num, m_noise_local ); #ifdef BASOP_NOGLOB - L_snr = L_shr_o(snr_tmp, shift_snr, &Overflow); /* L_snr in Q4 */ -#else /* BASOP_NOGLOB */ - L_snr = L_shr(snr_tmp, shift_snr); /* L_snr in Q4 */ -#endif /* BASOP_NOGLOB */ + L_snr = L_shr_o( snr_tmp, shift_snr, &Overflow ); /* L_snr in Q4 */ +#else /* BASOP_NOGLOB */ + L_snr = L_shr( snr_tmp, shift_snr ); /* L_snr in Q4 */ +#endif /* BASOP_NOGLOB */ } ELSE { - e_num = norm_l(L_tmp1); - m_num = extract_h(L_shl(L_tmp1,e_num)); + e_num = norm_l( L_tmp1 ); + m_num = extract_h( L_shl( L_tmp1, e_num ) ); /* if bckr[i] == 0; approx. L_snr */ - e_noise = add(30+1, abs_s(Q_new)); + e_noise = add( 30 + 1, abs_s( Q_new ) ); - m_num = shr(m_num, 1); - shift_snr = add(sub(e_num, e_noise), 15-4); + m_num = shr( m_num, 1 ); + shift_snr = add( sub( e_num, e_noise ), 15 - 4 ); - snr_tmp = div_s(m_num, 32767); - L_snr = L_shr(snr_tmp, shift_snr); /*L_snr in Q4*/ + snr_tmp = div_s( m_num, 32767 ); + L_snr = L_shr( snr_tmp, shift_snr ); /*L_snr in Q4*/ } /* conditional snrsum, snr_sum = snr_sum + snr[i];*/ - sign_thr_snr_acc_fx(&L_snr_sum_HE_SAD,L_snr, sign_thr_HE_SAD, min_snr_HE_SAD); - sign_thr_snr_acc_fx(&L_snr_sum, L_snr, sign_thr, min_snr); + sign_thr_snr_acc_fx( &L_snr_sum_HE_SAD, L_snr, sign_thr_HE_SAD, min_snr_HE_SAD ); + sign_thr_snr_acc_fx( &L_snr_sum, L_snr, sign_thr, min_snr ); - L_snr = L_max(L_snr, 16); /*Q4, if( snr[i] < 1.0f ) { snr[i] = 1.0f;} */ + L_snr = L_max( L_snr, 16 ); /*Q4, if( snr[i] < 1.0f ) { snr[i] = 1.0f;} */ /* float saves all snrs in an snr[] vector , in fix we only save two bands */ - if ( EQ_16(i,18)) + if ( EQ_16( i, 18 ) ) { - L_snr18 = L_add(L_snr, 0); /*Q4 */ + L_snr18 = L_add( L_snr, 0 ); /*Q4 */ } - if ( EQ_16(i,19)) + if ( EQ_16( i, 19 ) ) { - L_snr19 = L_add(L_snr, 0); /* Q4 */ + L_snr19 = L_add( L_snr, 0 ); /* Q4 */ } /* accumulate background noise energy in bands [0-2] and in bands [3-19]*/ - IF(LT_16(i,3)) + IF( LT_16( i, 3 ) ) { #ifdef BASOP_NOGLOB - L_accum_ener_L = L_add_o(L_accum_ener_L , hNoiseEst->bckr_fx[i], &Overflow);/*Q_new+QSCALE */ + L_accum_ener_L = L_add_o( L_accum_ener_L, hNoiseEst->bckr_fx[i], &Overflow ); /*Q_new+QSCALE */ #else - L_accum_ener_L = L_add(L_accum_ener_L , hNoiseEst->bckr_fx[i]);/*Q_new+QSCALE */ + L_accum_ener_L = L_add( L_accum_ener_L, hNoiseEst->bckr_fx[i] ); /*Q_new+QSCALE */ #endif } ELSE { #ifdef BASOP_NOGLOB - L_accum_ener_H = L_add_o(L_accum_ener_H , hNoiseEst->bckr_fx[i], &Overflow);/*Q_new+QSCALE */ + L_accum_ener_H = L_add_o( L_accum_ener_H, hNoiseEst->bckr_fx[i], &Overflow ); /*Q_new+QSCALE */ #else - L_accum_ener_H = L_add(L_accum_ener_H , hNoiseEst->bckr_fx[i]);/*Q_new+QSCALE */ + L_accum_ener_H = L_add( L_accum_ener_H, hNoiseEst->bckr_fx[i] ); /*Q_new+QSCALE */ #endif } /* Identify the outlier band */ - IF( GT_32(L_snr, L_snr_outlier)) + IF( GT_32( L_snr, L_snr_outlier ) ) { - L_snr_outlier = L_add(L_snr, 0); /*Q4*/ + L_snr_outlier = L_add( L_snr, 0 ); /*Q4*/ snr_outlier_index = i; move16(); } - } /* end of band loop */ + } /* end of band loop */ test(); test(); test(); /* one additional test for ELSE IF */ - IF ( (EQ_16(st_fx->max_band, 19)) - && ( GT_32(L_snr18, 5*(1<<4)) ) - && ( GT_32(L_snr19, 5*(1<<4)) ) ) + IF( ( EQ_16( st_fx->max_band, 19 ) ) && ( GT_32( L_snr18, 5 * ( 1 << 4 ) ) ) && ( GT_32( L_snr19, 5 * ( 1 << 4 ) ) ) ) { /* mssnr = (mssnr + 3*(msnr18 + msnr19)) * 0.77f; */ /* mssnr = (mssnr*.77f + 2.31f*(msnr18 + msnr19)); */ - L_tmp1 = Mult_32_16(L_mssnr, 25231 ); /* Q13+Q15+1-16 --> Q13 */ - L_tmp = Mult_32_16(L_shl(L_add(L_msnr18, L_msnr19),2),18924 ); /* Q(13+2)+Q(15-2)+1-16 --> Q13 */ - L_tmp = L_add( L_tmp1, L_tmp); - if ( GT_32(L_tmp, L_mssnr)) + L_tmp1 = Mult_32_16( L_mssnr, 25231 ); /* Q13+Q15+1-16 --> Q13 */ + L_tmp = Mult_32_16( L_shl( L_add( L_msnr18, L_msnr19 ), 2 ), 18924 ); /* Q(13+2)+Q(15-2)+1-16 --> Q13 */ + L_tmp = L_add( L_tmp1, L_tmp ); + if ( GT_32( L_tmp, L_mssnr ) ) { L_mssnr = L_tmp; } } - ELSE IF ( (snr_idx != 0) - && GT_16(nb_sig_snr, 13) ) + ELSE IF( ( snr_idx != 0 ) && GT_16( nb_sig_snr, 13 ) ) { L_tmp = -126976; - move32() ; /* -15.5 Q13 */ - L_tmp = L_mac0(L_tmp,80,lp_snr) ; /* 2.5f(Q5)*lp_snr(Q8) - 15.5f */ - if ( L_tmp > 0 ) /* 2.5f*lp_snr - 15.5f > 0 */ + move32(); /* -15.5 Q13 */ + L_tmp = L_mac0( L_tmp, 80, lp_snr ); /* 2.5f(Q5)*lp_snr(Q8) - 15.5f */ + if ( L_tmp > 0 ) /* 2.5f*lp_snr - 15.5f > 0 */ { - L_mssnr = L_add(L_mssnr, L_tmp); /* mssnr += 2.5f*lp_snr - 15.5f; */ + L_mssnr = L_add( L_mssnr, L_tmp ); /* mssnr += 2.5f*lp_snr - 15.5f; */ } } /* Separated SNR_SUM outlier modification */ - L_snr_sum_ol = L_snr_sum; /* snr_sum_ol = snr_sum; */ + L_snr_sum_ol = L_snr_sum; /* snr_sum_ol = snr_sum; */ test(); test(); test(); - IF( ( EQ_16(st_fx->max_band, 19)) - && LT_32(L_snr_outlier , MAX_SNR_OUTLIER_3_FX) - && GT_16(snr_outlier_index, 3) - && LT_16(snr_outlier_index, MAX_SNR_OUTLIER_IND_FX) ) + IF( ( EQ_16( st_fx->max_band, 19 ) ) && LT_32( L_snr_outlier, MAX_SNR_OUTLIER_3_FX ) && GT_16( snr_outlier_index, 3 ) && LT_16( snr_outlier_index, MAX_SNR_OUTLIER_IND_FX ) ) { /* Update the total SNR only for WB signals */ @@ -1089,99 +1072,94 @@ Word16 wb_vad_fx( test(); test(); - IF( LT_32(L_accum_ener_H, Mult_32_16(L_accum_ener_L,INV_OUTLIER_THR_1_FX))/* float:: (accum_ener_L*INV_OUTLIER_THR_1 > accum_ener_H ) !!! */ - || LT_32(L_snr_outlier,MAX_SNR_OUTLIER_1_FX) ) + IF( LT_32( L_accum_ener_H, Mult_32_16( L_accum_ener_L, INV_OUTLIER_THR_1_FX ) ) /* float:: (accum_ener_L*INV_OUTLIER_THR_1 > accum_ener_H ) !!! */ + || LT_32( L_snr_outlier, MAX_SNR_OUTLIER_1_FX ) ) { /* as weight1 is 1.0 we do not need to multiply here , i.e. no need to loose any precisison */ - L_snr_sum_ol = L_sub(L_snr_sum_ol,L_snr_outlier); /*Q4 */ - + L_snr_sum_ol = L_sub( L_snr_sum_ol, L_snr_outlier ); /*Q4 */ } - ELSE IF( LT_32(L_accum_ener_H, Mult_32_16(L_accum_ener_L,INV_OUTLIER_THR_2_FX))/* float:: (accum_ener_L *INV_OUTLIER_THR_2 > accum_ener_H ) !!! */ - || LT_32(L_snr_outlier,MAX_SNR_OUTLIER_2_FX) ) + ELSE IF( LT_32( L_accum_ener_H, Mult_32_16( L_accum_ener_L, INV_OUTLIER_THR_2_FX ) ) /* float:: (accum_ener_L *INV_OUTLIER_THR_2 > accum_ener_H ) !!! */ + || LT_32( L_snr_outlier, MAX_SNR_OUTLIER_2_FX ) ) { /* L_snr_sum = SNR_OUTLIER_WGHT_2 * (snr_sum - snr_outlier); */ /* 1.01*x -> (1*x + 0.01*x) to not drop down to Q3 */ - L_tmp = L_sub(L_snr_sum_ol,L_snr_outlier); - L_tmp2 = Mult_32_16(L_tmp, 20972); /* 0.01(in Q21)= 20972 Q4*Q21+1-16 -> Q10 */ - L_snr_sum_ol = L_add(L_tmp, L_shr(L_tmp2,6)); /* Q4 */ + L_tmp = L_sub( L_snr_sum_ol, L_snr_outlier ); + L_tmp2 = Mult_32_16( L_tmp, 20972 ); /* 0.01(in Q21)= 20972 Q4*Q21+1-16 -> Q10 */ + L_snr_sum_ol = L_add( L_tmp, L_shr( L_tmp2, 6 ) ); /* Q4 */ } ELSE { /* L_snr_sum = SNR_OUTLIER_WGHT_3 * (snr_sum - snr_outlier);*/ /* 1.02*x -> (1*x + 0.02*x) to not drop down to Q3 */ - L_tmp = L_sub(L_snr_sum_ol,L_snr_outlier); - L_tmp2 = Mult_32_16(L_tmp, 20972); /* 0.02(in Q20)= 20972 Q4*Q20+1-16 -> Q9 */ - L_snr_sum_ol = L_add(L_tmp, L_shr(L_tmp2, 5)); /* Q4 */ - + L_tmp = L_sub( L_snr_sum_ol, L_snr_outlier ); + L_tmp2 = Mult_32_16( L_tmp, 20972 ); /* 0.02(in Q20)= 20972 Q4*Q20+1-16 -> Q9 */ + L_snr_sum_ol = L_add( L_tmp, L_shr( L_tmp2, 5 ) ); /* Q4 */ } } /*st_fx->snr_sum_vad_fx = 0.5f * st->snr_sum_vad + 0.5f * snr_sum_ol;*/ #ifdef BASOP_NOGLOB - hVAD->L_snr_sum_vad_fx = L_shr(L_add_o(hVAD->L_snr_sum_vad_fx ,L_snr_sum_ol, &Overflow),1); /*Q4*/ -#else /* BASOP_NOGLOB */ - hVAD->L_snr_sum_vad_fx = L_shr(L_add(hVAD->L_snr_sum_vad_fx ,L_snr_sum_ol ),1); /*Q4*/ -#endif /* BASOP_NOGLOB */ + hVAD->L_snr_sum_vad_fx = L_shr( L_add_o( hVAD->L_snr_sum_vad_fx, L_snr_sum_ol, &Overflow ), 1 ); /*Q4*/ +#else /* BASOP_NOGLOB */ + hVAD->L_snr_sum_vad_fx = L_shr( L_add( hVAD->L_snr_sum_vad_fx, L_snr_sum_ol ), 1 ); /*Q4*/ +#endif /* BASOP_NOGLOB */ /* snr_sum_ol = 10.0f * (float)log10( snr_sum_ol ); */ - snr_sum_ol = vad_snr_log_fx(L_snr_sum_ol, LG10); + snr_sum_ol = vad_snr_log_fx( L_snr_sum_ol, LG10 ); snr_sum = snr_sum_ol; - move16(); /* note for NB no outlier modification */ + move16(); /* note for NB no outlier modification */ /* snr_sum_HE_SAD = 10.0f * (float)log10( snr_sum_HE_SAD ); */ - snr_sum_HE_SAD = vad_snr_log_fx( L_snr_sum_HE_SAD, LG10); + snr_sum_HE_SAD = vad_snr_log_fx( L_snr_sum_HE_SAD, LG10 ); - *snr_sum_he=snr_sum_HE_SAD; - move16(); /* *snr_sum_he=snr_sum_HE_SAD; */ + *snr_sum_he = snr_sum_HE_SAD; + move16(); /* *snr_sum_he=snr_sum_HE_SAD; */ /*---------------------------------------------------------------------* - * compute thr1 for SAD decision - *---------------------------------------------------------------------*/ - lp_snr = sub(lp_speech_fx, lp_noise_fx); /*Q8*/ + * compute thr1 for SAD decision + *---------------------------------------------------------------------*/ + lp_snr = sub( lp_speech_fx, lp_noise_fx ); /*Q8*/ - sub(0,0); - IF ( LT_16(lp_snr, hNoiseEst->sign_dyn_lp_fx)) + sub( 0, 0 ); + IF( LT_16( lp_snr, hNoiseEst->sign_dyn_lp_fx ) ) { - lp_snr = add(lp_snr,1<<8); /* lp_snr += 1; */ + lp_snr = add( lp_snr, 1 << 8 ); /* lp_snr += 1; */ - if (GT_16(lp_snr, hNoiseEst->sign_dyn_lp_fx)) + if ( GT_16( lp_snr, hNoiseEst->sign_dyn_lp_fx ) ) { - lp_snr = hNoiseEst->sign_dyn_lp_fx; + lp_snr = hNoiseEst->sign_dyn_lp_fx; move16(); } } - /*thr1 = nk * lp_snr + nc*1.0 + nv * ( st->Etot_v_h2 - nv_ofs); */ /* Linear function for noisy speech */ + /*thr1 = nk * lp_snr + nc*1.0 + nv * ( st->Etot_v_h2 - nv_ofs); */ /* Linear function for noisy speech */ - L_tmp = L_shl(L_mult(sub(hNoiseEst->Etot_v_h2_fx, nv_ofs), nv ),7); /* Q8+Q8+1 +7 --> Q24 */ - L_tmp = L_mac(L_tmp, nc, (Word16)32767); /* Q8+Q15+1 = Q24 */ - thr1 = mac_r(L_tmp, lp_snr, nk ); /* Q8+Q15+1 - 16 --> Q8 */ + L_tmp = L_shl( L_mult( sub( hNoiseEst->Etot_v_h2_fx, nv_ofs ), nv ), 7 ); /* Q8+Q8+1 +7 --> Q24 */ + L_tmp = L_mac( L_tmp, nc, (Word16) 32767 ); /* Q8+Q15+1 = Q24 */ + thr1 = mac_r( L_tmp, lp_snr, nk ); /* Q8+Q15+1 - 16 --> Q8 */ #ifdef IVAS_CODE - if (st->element_mode > EVS_MONO && hNoiseEst->first_noise_updt_cnt < 100) + if ( st->element_mode > EVS_MONO && hNoiseEst->first_noise_updt_cnt < 100 ) { /* lower threshold during warmup time */ thr1 -= 10.0f; vad_thr = 0.f; } #endif - IF (GT_16(lp_snr, (Word16)20*(1<<8))) /* if (lp_snr > 20.0f )*/ + IF( GT_16( lp_snr, (Word16) 20 * ( 1 << 8 ) ) ) /* if (lp_snr > 20.0f )*/ { #ifdef IVAS_CODE - if (st->element_mode == EVS_MONO || hNoiseEst->first_noise_updt_cnt >= 100) + if ( st->element_mode == EVS_MONO || hNoiseEst->first_noise_updt_cnt >= 100 ) #endif { /* thr1 = thr1 + 0.3f * (lp_snr - 20.0f); */ - thr1 = add(thr1, mult(9830, sub(lp_snr, (Word16)20 * (1 << 8)))); /* Q15*Q8+1 -16 --> Q8 */ + thr1 = add( thr1, mult( 9830, sub( lp_snr, (Word16) 20 * ( 1 << 8 ) ) ) ); /* Q15*Q8+1 -16 --> Q8 */ test(); test(); test(); - if (EQ_16(st_fx->max_band, 16) - && GT_16(lp_snr, 40 * 256) - && GT_16(thr1, 6600) - && LT_16(lp_speech_fx, 11520)) + if ( EQ_16( st_fx->max_band, 16 ) && GT_16( lp_snr, 40 * 256 ) && GT_16( thr1, 6600 ) && LT_16( lp_speech_fx, 11520 ) ) { thr1 = 6600; } @@ -1189,26 +1167,24 @@ Word16 wb_vad_fx( } - - /*---------------------------------------------------------------------* * WB input * SNR threshold computing * Hangover control & final VAD decision *---------------------------------------------------------------------*/ - IF( NE_16(vad_bwidth_fx, NB)) + IF( NE_16( vad_bwidth_fx, NB ) ) { /* Outlier Detection first calculates thr1_ol and snr_sum_ol instead of modyfying thr1 and snr_sum */ - thr1_ol = thr1; + thr1_ol = thr1; move16(); hangover_short = 3; move16(); - IF( LT_16(lp_snr,th_clean)) + IF( LT_16( lp_snr, th_clean ) ) { hangover_short = 4; move16(); @@ -1222,80 +1198,79 @@ Word16 wb_vad_fx( test(); test(); test(); - test(); /*_DIFF_FLOAT_FIX_ -> the conditions around Opt_SC_VBR_fx are invertered compared to float - ### st_fx->Opt_SC_VBR!=0 vs !st_fx->Opt_SC_VBR #####*/ + test(); /*_DIFF_FLOAT_FIX_ -> the conditions around Opt_SC_VBR_fx are invertered compared to float + ### st_fx->Opt_SC_VBR!=0 vs !st_fx->Opt_SC_VBR #####*/ test(); - IF( LE_16(snr_outlier_index, 4) && ( ( GT_16(st_fx->last_coder_type,UNVOICED) && (st_fx->Opt_SC_VBR!=0)) || - ( GT_16(last_7k2_coder_type, UNVOICED) && ( st_fx->Opt_SC_VBR == 0 ) ) ) ) + IF( LE_16( snr_outlier_index, 4 ) && ( ( GT_16( st_fx->last_coder_type, UNVOICED ) && ( st_fx->Opt_SC_VBR != 0 ) ) || + ( GT_16( last_7k2_coder_type, UNVOICED ) && ( st_fx->Opt_SC_VBR == 0 ) ) ) ) { - thr1_ol = sub(thr1_ol,(Word16)(1<<8)); /*thr1_ol = thr1 - 1.0f ; */ + thr1_ol = sub( thr1_ol, (Word16) ( 1 << 8 ) ); /*thr1_ol = thr1 - 1.0f ; */ /*snr_sum_ol = 10.0f * (float)log10( hVAD->L_snr_sum_vad_fx );*/ - snr_sum_ol = vad_snr_log_fx(hVAD->L_snr_sum_vad_fx, LG10); /* snr in Q8 */ - + snr_sum_ol = vad_snr_log_fx( hVAD->L_snr_sum_vad_fx, LG10 ); /* snr in Q8 */ } - ELSE IF ( ((LE_16(st_fx->last_coder_type, UNVOICED)) && (LT_32(L_snr_outlier,MAX_SNR_OUTLIER_2_FX)) && ( st_fx->Opt_SC_VBR != 0)) || - ((LE_16(last_7k2_coder_type, UNVOICED) ) && (LT_32(L_snr_outlier,MAX_SNR_OUTLIER_2_FX)) && ( st_fx->Opt_SC_VBR == 0 ) ) ) + ELSE IF( ( ( LE_16( st_fx->last_coder_type, UNVOICED ) ) && ( LT_32( L_snr_outlier, MAX_SNR_OUTLIER_2_FX ) ) && ( st_fx->Opt_SC_VBR != 0 ) ) || + ( ( LE_16( last_7k2_coder_type, UNVOICED ) ) && ( LT_32( L_snr_outlier, MAX_SNR_OUTLIER_2_FX ) ) && ( st_fx->Opt_SC_VBR == 0 ) ) ) { /* thr1_ol = thr1 + (float)(1.0f - 0.04f * snr_outlier); */ - L_tmp2 = Msub_32_16( (Word32)(1<<(24-16)), L_snr_outlier, 20972 ); /* (1.0)Q24(Q8 in high 32bit word) - Q4*Q19+1 */ - tmp2 = round_fx( L_shl(L_tmp2,16)); /* high word is in Q8 */ - thr1_ol = add(thr1_ol, tmp2 ); /* (Q8 , Q8) */ + L_tmp2 = Msub_32_16( (Word32) ( 1 << ( 24 - 16 ) ), L_snr_outlier, 20972 ); /* (1.0)Q24(Q8 in high 32bit word) - Q4*Q19+1 */ + tmp2 = round_fx( L_shl( L_tmp2, 16 ) ); /* high word is in Q8 */ + thr1_ol = add( thr1_ol, tmp2 ); /* (Q8 , Q8) */ } ELSE { /*thr1_ol = thr1 + max(0, (float)(0.6f - 0.01f * L_snr_outlier)); */ thr1_ol = thr1; move16(); - L_tmp2 = Msub_32_16( (Word32)614 , L_snr_outlier, 20972); /* .6*1024= */ /* 0.6 Q26(Q10 in high word) - Q4*Q21+1 */ + L_tmp2 = Msub_32_16( (Word32) 614, L_snr_outlier, 20972 ); /* .6*1024= */ /* 0.6 Q26(Q10 in high word) - Q4*Q21+1 */ #ifdef BASOP_NOGLOB - tmp2 = round_fx(L_shl_o(L_tmp2,14, &Overflow)); /* Q10(high word)+ 14 -16 --> Q8*/ -#else /* BASOP_NOGLOB */ - tmp2 = round_fx(L_shl(L_tmp2,14)); /* Q10(high word)+ 14 -16 --> Q8*/ + tmp2 = round_fx( L_shl_o( L_tmp2, 14, &Overflow ) ); /* Q10(high word)+ 14 -16 --> Q8*/ +#else /* BASOP_NOGLOB */ + tmp2 = round_fx( L_shl( L_tmp2, 14 ) ); /* Q10(high word)+ 14 -16 --> Q8*/ #endif - if(L_tmp2 > 0) + if ( L_tmp2 > 0 ) { - thr1_ol = add(thr1_ol, tmp2 ); /* Q24 >>16 + Q8 */ + thr1_ol = add( thr1_ol, tmp2 ); /* Q24 >>16 + Q8 */ } } } /* apply outlier modification */ snr_sum = snr_sum_ol; - move16(); /*NB s*/ - thr1 = thr1_ol; + move16(); /*NB s*/ + thr1 = thr1_ol; move16(); /* DTX HANGOVER is in pre_proc_fx() */ - flag_he1 = 0; + flag_he1 = 0; move16(); - IF ( GT_32(L_mssnr, L_vad_thr)) + IF( GT_32( L_mssnr, L_vad_thr ) ) { flag_he1 = 1; - move16(); /* he1 primary decision */ - hVAD->nb_active_frames_he1 = add(hVAD->nb_active_frames_he1,1); /* Counter of consecutive active speech frames */ + move16(); /* he1 primary decision */ + hVAD->nb_active_frames_he1 = add( hVAD->nb_active_frames_he1, 1 ); /* Counter of consecutive active speech frames */ - IF ( GE_16(hVAD->nb_active_frames_he1,ACTIVE_FRAMES_FX)) + IF( GE_16( hVAD->nb_active_frames_he1, ACTIVE_FRAMES_FX ) ) { hVAD->nb_active_frames_he1 = ACTIVE_FRAMES_FX; move16(); - hVAD->hangover_cnt_he1 = 0; - move16(); /* Reset the counter of hangover frames after at least "active_frames" speech frames */ + hVAD->hangover_cnt_he1 = 0; + move16(); /* Reset the counter of hangover frames after at least "active_frames" speech frames */ } /* inside HO period */ test(); - if ( sub(hVAD->hangover_cnt_he1, HANGOVER_LONG_HE_FX) < 0 &&hVAD->hangover_cnt_he1 != 0 ) + if ( sub( hVAD->hangover_cnt_he1, HANGOVER_LONG_HE_FX ) < 0 && hVAD->hangover_cnt_he1 != 0 ) { - hVAD->hangover_cnt_he1 = add(hVAD->hangover_cnt_he1 ,1); + hVAD->hangover_cnt_he1 = add( hVAD->hangover_cnt_he1, 1 ); } if ( hVAD->soft_hangover > 0 ) { - hVAD->soft_hangover = sub(hVAD->soft_hangover ,1); + hVAD->soft_hangover = sub( hVAD->soft_hangover, 1 ); } } ELSE @@ -1306,13 +1281,11 @@ Word16 wb_vad_fx( } - - - IF ( GT_16(hVAD->voiced_burst, 3)) + IF( GT_16( hVAD->voiced_burst, 3 ) ) { - IF ( LT_16(hVAD->bcg_flux_fx, 640)) /* Q4 */ + IF( LT_16( hVAD->bcg_flux_fx, 640 ) ) /* Q4 */ { - hVAD->soft_hangover = hangover_sf_tbl[add(snr_idx,3)]; + hVAD->soft_hangover = hangover_sf_tbl[add( snr_idx, 3 )]; move16(); } ELSE @@ -1326,144 +1299,140 @@ Word16 wb_vad_fx( hangover_hd = hangover_hd_tbl[snr_idx]; move16(); - IF ( LT_16(hVAD->bcg_flux_fx, 640)) + IF( LT_16( hVAD->bcg_flux_fx, 640 ) ) { - hangover_hd = add(shr(hangover_hd,1), 1); + hangover_hd = add( shr( hangover_hd, 1 ), 1 ); move16(); } /* VAD hangover for he1 */ test(); - IF ( flag_he1 == 0 && hVAD->soft_hangover > 0 ) + IF( flag_he1 == 0 && hVAD->soft_hangover > 0 ) { - IF ( GT_32(L_mssnr_hov, L_vad_thr)) + IF( GT_32( L_mssnr_hov, L_vad_thr ) ) { flag_he1 = 1; move16(); - hVAD->soft_hangover=sub(hVAD->soft_hangover,1); + hVAD->soft_hangover = sub( hVAD->soft_hangover, 1 ); } ELSE { - hVAD->soft_hangover=0; + hVAD->soft_hangover = 0; move16(); } - if( hVAD->soft_hangover < 0) + if ( hVAD->soft_hangover < 0 ) { - hVAD->soft_hangover=0; + hVAD->soft_hangover = 0; move16(); } } test(); test(); - IF ( (flag_he1 == 0) - && (LT_16(hVAD->hangover_cnt_he1, hangover_hd) ) - && (hVAD->soft_hangover == 0 ) ) + IF( ( flag_he1 == 0 ) && ( LT_16( hVAD->hangover_cnt_he1, hangover_hd ) ) && ( hVAD->soft_hangover == 0 ) ) { flag_he1 = 1; move16(); - hVAD->hangover_cnt_he1 = add(hVAD->hangover_cnt_he1,1); + hVAD->hangover_cnt_he1 = add( hVAD->hangover_cnt_he1, 1 ); } - /* Calculate background stationarity */ test(); - IF ( flag_he1 == 0 && hNoiseEst->first_noise_updt > 0 ) + IF( flag_he1 == 0 && hNoiseEst->first_noise_updt > 0 ) { - IF ( GT_16(snr_sumt, hVAD->bcg_flux_fx)) + IF( GT_16( snr_sumt, hVAD->bcg_flux_fx ) ) { - IF (hVAD->bcg_flux_init-- > 0 ) + IF( hVAD->bcg_flux_init-- > 0 ) { - IF ( GT_16(snr_sumt,add(hVAD->bcg_flux_fx,800))) + IF( GT_16( snr_sumt, add( hVAD->bcg_flux_fx, 800 ) ) ) { /*st->bcg_flux = 0.9f * st->bcg_flux + (1-0.9f)*(st->bcg_flux+50);*/ - hVAD->bcg_flux_fx = mac_r(L_mult(hVAD->bcg_flux_fx,29491),add(hVAD->bcg_flux_fx,800),3277); /*Q4 */ + hVAD->bcg_flux_fx = mac_r( L_mult( hVAD->bcg_flux_fx, 29491 ), add( hVAD->bcg_flux_fx, 800 ), 3277 ); /*Q4 */ } ELSE { /*st->bcg_flux = 0.9f * st->bcg_flux + (1-0.9f)*snr_sumt*/ - hVAD->bcg_flux_fx = mac_r(L_mult(hVAD->bcg_flux_fx,29491),snr_sumt,3277); /*Q4 */ + hVAD->bcg_flux_fx = mac_r( L_mult( hVAD->bcg_flux_fx, 29491 ), snr_sumt, 3277 ); /*Q4 */ } } ELSE { - IF ( GT_16(snr_sumt,add(hVAD->bcg_flux_fx,160))) + IF( GT_16( snr_sumt, add( hVAD->bcg_flux_fx, 160 ) ) ) { /*st->bcg_flux = 0.99f * st->bcg_flux + (1-0.99f)*(st->bcg_flux+10);*/ - hVAD->bcg_flux_fx = mac_r(L_mult(hVAD->bcg_flux_fx,32440),add(hVAD->bcg_flux_fx,160),328); /*Q4 */ + hVAD->bcg_flux_fx = mac_r( L_mult( hVAD->bcg_flux_fx, 32440 ), add( hVAD->bcg_flux_fx, 160 ), 328 ); /*Q4 */ } ELSE { /*st->bcg_flux = 0.99f * st->bcg_flux + (1-0.99f)*snr_sumt;*/ - hVAD->bcg_flux_fx = mac_r(L_mult(hVAD->bcg_flux_fx,32440),snr_sumt,328); /*Q4 */ + hVAD->bcg_flux_fx = mac_r( L_mult( hVAD->bcg_flux_fx, 32440 ), snr_sumt, 328 ); /*Q4 */ } } } ELSE { - IF (hVAD->bcg_flux_init-- > 0 ) + IF( hVAD->bcg_flux_init-- > 0 ) { - IF ( LT_16(snr_sumt,sub(hVAD->bcg_flux_fx,480))) + IF( LT_16( snr_sumt, sub( hVAD->bcg_flux_fx, 480 ) ) ) { /*st->bcg_flux = 0.95f * st->bcg_flux + (1-0.95f)*(st->bcg_flux-30);*/ - hVAD->bcg_flux_fx = mac_r(L_mult(hVAD->bcg_flux_fx,31130),sub(hVAD->bcg_flux_fx,480),1638); /*Q4 */ + hVAD->bcg_flux_fx = mac_r( L_mult( hVAD->bcg_flux_fx, 31130 ), sub( hVAD->bcg_flux_fx, 480 ), 1638 ); /*Q4 */ } ELSE { /*st->bcg_flux = 0.95f * st->bcg_flux + (1-0.95f)*snr_sumt;*/ - hVAD->bcg_flux_fx = mac_r(L_mult(hVAD->bcg_flux_fx,31130),snr_sumt,1638); /*Q4 */ + hVAD->bcg_flux_fx = mac_r( L_mult( hVAD->bcg_flux_fx, 31130 ), snr_sumt, 1638 ); /*Q4 */ } } ELSE { - IF ( LT_16(snr_sumt,sub(hVAD->bcg_flux_fx,160))) + IF( LT_16( snr_sumt, sub( hVAD->bcg_flux_fx, 160 ) ) ) { /*st->bcg_flux = 0.9992f * st->bcg_flux + (1-0.9992f)*(st->bcg_flux-10);*/ - hVAD->bcg_flux_fx = mac_r(L_mult(hVAD->bcg_flux_fx,32742),sub(hVAD->bcg_flux_fx,160),26); /*Q4 */ + hVAD->bcg_flux_fx = mac_r( L_mult( hVAD->bcg_flux_fx, 32742 ), sub( hVAD->bcg_flux_fx, 160 ), 26 ); /*Q4 */ } ELSE { /*st->bcg_flux = 0.9992f * st->bcg_flux + (1-0.9992f)*snr_sumt;*/ - hVAD->bcg_flux_fx = mac_r(L_mult(hVAD->bcg_flux_fx,32742),snr_sumt,26); /*Q4 */ + hVAD->bcg_flux_fx = mac_r( L_mult( hVAD->bcg_flux_fx, 32742 ), snr_sumt, 26 ); /*Q4 */ } } } - hVAD->bcg_flux_init = s_max(hVAD->bcg_flux_init,0); + hVAD->bcg_flux_init = s_max( hVAD->bcg_flux_init, 0 ); } flag = 0; move16(); st_fx->localVAD = 0; move16(); - /* if ( snr_sum > thr1 && flag_he1 == 1 ) *//* Speech present */ + /* if ( snr_sum > thr1 && flag_he1 == 1 ) */ /* Speech present */ test(); - IF ( (GT_16(snr_sum, thr1))&&(EQ_16(flag_he1,1))) /* Speech present */ + IF( ( GT_16( snr_sum, thr1 ) ) && ( EQ_16( flag_he1, 1 ) ) ) /* Speech present */ { - flag = 1; + flag = 1; move16(); st_fx->localVAD = 1; move16(); - hVAD->nb_active_frames = add(hVAD->nb_active_frames,1); /* Counter of consecutive active speech frames */ + hVAD->nb_active_frames = add( hVAD->nb_active_frames, 1 ); /* Counter of consecutive active speech frames */ - IF ( GE_16(hVAD->nb_active_frames,ACTIVE_FRAMES_FX)) + IF( GE_16( hVAD->nb_active_frames, ACTIVE_FRAMES_FX ) ) { hVAD->nb_active_frames = ACTIVE_FRAMES_FX; move16(); - hVAD->hangover_cnt = 0; + hVAD->hangover_cnt = 0; move16(); /* Reset the counter of hangover frames after at least "active_frames" speech frames */ } /* inside HO period */ test(); - if( LT_16(hVAD->hangover_cnt,HANGOVER_LONG_FX) - &&hVAD->hangover_cnt != 0 ) + if ( LT_16( hVAD->hangover_cnt, HANGOVER_LONG_FX ) && hVAD->hangover_cnt != 0 ) { - hVAD->hangover_cnt = add(hVAD->hangover_cnt,1); + hVAD->hangover_cnt = add( hVAD->hangover_cnt, 1 ); } } ELSE @@ -1472,30 +1441,30 @@ Word16 wb_vad_fx( hVAD->nb_active_frames = 0; move16(); - if( LT_16(hVAD->hangover_cnt,HANGOVER_LONG_FX)) /* inside HO period */ + if ( LT_16( hVAD->hangover_cnt, HANGOVER_LONG_FX ) ) /* inside HO period */ { - hVAD->hangover_cnt = add(hVAD->hangover_cnt,1); + hVAD->hangover_cnt = add( hVAD->hangover_cnt, 1 ); } - IF( LE_16(hVAD->hangover_cnt, hangover_short)) /* "hard" hangover */ + IF( LE_16( hVAD->hangover_cnt, hangover_short ) ) /* "hard" hangover */ { test(); test(); - if (EQ_16(st_fx->element_mode, EVS_MONO) && (LT_16(lp_snr,th_clean)) && (st_fx->Opt_SC_VBR != 0 ) && (GE_16(hVAD->hangover_cnt, 2)) ) + if ( EQ_16( st_fx->element_mode, EVS_MONO ) && ( LT_16( lp_snr, th_clean ) ) && ( st_fx->Opt_SC_VBR != 0 ) && ( GE_16( hVAD->hangover_cnt, 2 ) ) ) { *noisy_speech_HO = 1; move16(); } test(); test(); - if (EQ_16(st_fx->element_mode, EVS_MONO) && (GE_16(lp_snr,th_clean)) && (st_fx->Opt_SC_VBR != 0 ) && (GE_16(hVAD->hangover_cnt, 2) ) ) + if ( EQ_16( st_fx->element_mode, EVS_MONO ) && ( GE_16( lp_snr, th_clean ) ) && ( st_fx->Opt_SC_VBR != 0 ) && ( GE_16( hVAD->hangover_cnt, 2 ) ) ) { *clean_speech_HO = 1; move16(); } flag = 1; - move16(); /*HO*/ + move16(); /*HO*/ } } @@ -1506,8 +1475,7 @@ Word16 wb_vad_fx( move16(); test(); - IF ( (GT_16(snr_sum_HE_SAD, thr1)) - && (EQ_16(flag_he1, 1) ) ) /* Speech present */ + IF( ( GT_16( snr_sum_HE_SAD, thr1 ) ) && ( EQ_16( flag_he1, 1 ) ) ) /* Speech present */ { *localVAD_HE_SAD = 1; @@ -1521,28 +1489,28 @@ Word16 wb_vad_fx( * Hangover control & final VAD decision *---------------------------------------------------------------------*/ - ELSE /* NB input */ + ELSE /* NB input */ { /* Add localVAD_HE_SAD also for NB operation for use with speech music classifier */ *localVAD_HE_SAD = 0; move16(); - if (GT_16(snr_sum_HE_SAD, thr1)) + if ( GT_16( snr_sum_HE_SAD, thr1 ) ) { *localVAD_HE_SAD = 1; move16(); } st_fx->localVAD = 0; - move16(); /* safety inits for fx */ - IF ( GT_16(snr_sum,thr1)) /* Speech present, possibly in hangover */ + move16(); /* safety inits for fx */ + IF( GT_16( snr_sum, thr1 ) ) /* Speech present, possibly in hangover */ { - hVAD->nb_active_frames = add(hVAD->nb_active_frames,1); /* Counter of consecutive active speech frames */ - IF ( GE_16(hVAD->nb_active_frames,ACTIVE_FRAMES_FX)) + hVAD->nb_active_frames = add( hVAD->nb_active_frames, 1 ); /* Counter of consecutive active speech frames */ + IF( GE_16( hVAD->nb_active_frames, ACTIVE_FRAMES_FX ) ) { hVAD->nb_active_frames = ACTIVE_FRAMES_FX; move16(); hVAD->hangover_cnt = 0; - move16();/* Reset the counter of hangover frames after at least "active_frames" speech frames */ + move16(); /* Reset the counter of hangover frames after at least "active_frames" speech frames */ } st_fx->localVAD = 1; @@ -1551,80 +1519,78 @@ Word16 wb_vad_fx( ELSE { hVAD->nb_active_frames = 0; - move16(); /* Reset the counter of speech frames necessary to start hangover algorithm */ - /* st_fx->localVAD = 0; move16(); */ /* set above */ + move16(); /* Reset the counter of speech frames necessary to start hangover algorithm */ + /* st_fx->localVAD = 0; move16(); */ /* set above */ } thr1_nb_mod = thr1; - move16(); /* thr1 may be adjusted after this point */ - IF( LT_16(hVAD->hangover_cnt,HANGOVER_LONG_NB_FX)) + move16(); /* thr1 may be adjusted after this point */ + IF( LT_16( hVAD->hangover_cnt, HANGOVER_LONG_NB_FX ) ) { - hVAD->hangover_cnt = add(hVAD->hangover_cnt,1); + hVAD->hangover_cnt = add( hVAD->hangover_cnt, 1 ); - IF( LT_16(lp_snr, 4864 )) /*19.0f Q8*/ /* very low SNR */ + IF( LT_16( lp_snr, 4864 ) ) + /*19.0f Q8*/ /* very low SNR */ { - thr1_nb_mod = sub(thr1_nb_mod , 1331); /*thr1 -= 5.2f;*/ + thr1_nb_mod = sub( thr1_nb_mod, 1331 ); /*thr1 -= 5.2f;*/ } - ELSE IF( LT_16(lp_snr, 8960)) /*35 in Q8 */ /* low SNR */ + ELSE IF( LT_16( lp_snr, 8960 ) ) /*35 in Q8 */ /* low SNR */ { - thr1_nb_mod = sub(thr1_nb_mod , 512); /*thr1 -= 2.0f;*/ + thr1_nb_mod = sub( thr1_nb_mod, 512 ); /*thr1 -= 2.0f;*/ } } - thr2 = sub(thr1_nb_mod, 384); /*thr2 = thr1 - 1.5f; , clean speech */ + thr2 = sub( thr1_nb_mod, 384 ); /*thr2 = thr1 - 1.5f; , clean speech */ /* -dtx condition dependency in noisy speech */ tmp = 333; - move16(); /* 1.3f; */ + move16(); /* 1.3f; */ if ( st_fx->Opt_DTX_ON == 0 ) { tmp = 282; - move16(); /* 1.10f; */ + move16(); /* 1.10f; */ } - if (LT_16(lp_snr,th_clean)) + if ( LT_16( lp_snr, th_clean ) ) { - thr2 = sub(thr1_nb_mod, tmp); /*thr2 = thr1 - [ 1.10 || 1.3 ];*/ + thr2 = sub( thr1_nb_mod, tmp ); /*thr2 = thr1 - [ 1.10 || 1.3 ];*/ } flag = 0; move16(); - IF ( GT_16(snr_sum, thr1_nb_mod)) /* Speech assumed present, even though lowered thr1 */ + IF( GT_16( snr_sum, thr1_nb_mod ) ) /* Speech assumed present, even though lowered thr1 */ { flag = 1; move16(); } - test(); - IF ( (LT_16(snr_sum, thr1_nb_mod)) - && (GT_16(snr_sum, thr2)) ) /* Speech present */ + IF( ( LT_16( snr_sum, thr1_nb_mod ) ) && ( GT_16( snr_sum, thr2 ) ) ) /* Speech present */ { - flag = 1; + flag = 1; move16(); - st_fx->localVAD = 0; + st_fx->localVAD = 0; move16(); - if (EQ_16(st_fx->element_mode, EVS_MONO)) + if ( EQ_16( st_fx->element_mode, EVS_MONO ) ) { *NB_speech_HO = 1; } move16(); } - thr1 = thr1_nb_mod ; + thr1 = thr1_nb_mod; move16(); /* needed for st_fx->vadnoise_fx update below */ - } /* end of NB */ - + } /* end of NB */ /* *flag_noisy_speech_snr is a Word8 parameter */ - *flag_noisy_speech_snr = 0; /*_DIFF_FLOAT_FIX_ -> this initialisation is not done here in float */ + *flag_noisy_speech_snr = 0; /*_DIFF_FLOAT_FIX_ -> this initialisation is not done here in float */ move16(); IF( vad_bwidth_fx != NB ) { - if(LT_16(lp_snr, TH16_2_NFLAG_FX )) /*now 27, original threshold: 35dB*/ + if ( LT_16( lp_snr, TH16_2_NFLAG_FX ) ) /*now 27, original threshold: 35dB*/ { *flag_noisy_speech_snr = 1; move16(); @@ -1632,110 +1598,105 @@ Word16 wb_vad_fx( } ELSE { - if(LT_16(lp_snr, TH8_1_NFLAG_FX )) /* now 20.0 */ + if ( LT_16( lp_snr, TH8_1_NFLAG_FX ) ) /* now 20.0 */ { *flag_noisy_speech_snr = 1; move16(); } } - if (st_fx->hSC_VBR != NULL) + if ( st_fx->hSC_VBR != NULL ) { - /* SC-VBR */ - st_fx->hSC_VBR->vadsnr_fx = snr_sum; + /* SC-VBR */ + st_fx->hSC_VBR->vadsnr_fx = snr_sum; move16(); /* for ppp, voiced_enc */ st_fx->hSC_VBR->vadnoise_fx = thr1; move16(); /* used in nb for find_uv */ } /* Updates */ - hVAD->prim_act_quick_fx = mult_r(26214,hVAD->prim_act_quick_fx); /*Q15 */ + hVAD->prim_act_quick_fx = mult_r( 26214, hVAD->prim_act_quick_fx ); /*Q15 */ - if(st_fx->localVAD != 0) + if ( st_fx->localVAD != 0 ) { - hVAD->prim_act_quick_fx = add(6554,hVAD->prim_act_quick_fx ); /*Q15 */ + hVAD->prim_act_quick_fx = add( 6554, hVAD->prim_act_quick_fx ); /*Q15 */ } - hVAD->prim_act_slow_fx = mult_r(32440,hVAD->prim_act_slow_fx); /*Q15 */ + hVAD->prim_act_slow_fx = mult_r( 32440, hVAD->prim_act_slow_fx ); /*Q15 */ - if(st_fx->localVAD != 0) + if ( st_fx->localVAD != 0 ) { - hVAD->prim_act_slow_fx = add(328, hVAD->prim_act_slow_fx ); /*Q15 */ + hVAD->prim_act_slow_fx = add( 328, hVAD->prim_act_slow_fx ); /*Q15 */ } tmp = hVAD->prim_act_slow_fx; move16(); - if (LE_16(hVAD->prim_act_quick_fx,hVAD->prim_act_slow_fx)) + if ( LE_16( hVAD->prim_act_quick_fx, hVAD->prim_act_slow_fx ) ) { - tmp=hVAD->prim_act_quick_fx; + tmp = hVAD->prim_act_quick_fx; move16(); } /*st->prim_act = 0.1f * tmp + (1.0f-0.1f)* st->prim_act;*/ - hVAD->prim_act_fx = mac_r(L_mult(3277,tmp),29491,hVAD->prim_act_fx); + hVAD->prim_act_fx = mac_r( L_mult( 3277, tmp ), 29491, hVAD->prim_act_fx ); - - hVAD->prim_act_quick_he_fx = mult_r(26214,hVAD->prim_act_quick_he_fx); /*Q15 */ - if(*localVAD_HE_SAD != 0) + hVAD->prim_act_quick_he_fx = mult_r( 26214, hVAD->prim_act_quick_he_fx ); /*Q15 */ + if ( *localVAD_HE_SAD != 0 ) { - hVAD->prim_act_quick_he_fx = add(6554,hVAD->prim_act_quick_he_fx ); /*Q15 */ + hVAD->prim_act_quick_he_fx = add( 6554, hVAD->prim_act_quick_he_fx ); /*Q15 */ } - hVAD->prim_act_slow_he_fx = mult_r(32440,hVAD->prim_act_slow_he_fx); /*Q15 */ - if(*localVAD_HE_SAD != 0) + hVAD->prim_act_slow_he_fx = mult_r( 32440, hVAD->prim_act_slow_he_fx ); /*Q15 */ + if ( *localVAD_HE_SAD != 0 ) { - hVAD->prim_act_slow_he_fx = add(328, hVAD->prim_act_slow_he_fx ); /*Q15 */ + hVAD->prim_act_slow_he_fx = add( 328, hVAD->prim_act_slow_he_fx ); /*Q15 */ } tmp = hVAD->prim_act_slow_he_fx; move16(); - if (LE_16(hVAD->prim_act_quick_he_fx,hVAD->prim_act_slow_he_fx)) + if ( LE_16( hVAD->prim_act_quick_he_fx, hVAD->prim_act_slow_he_fx ) ) { tmp = hVAD->prim_act_quick_he_fx; move16(); } - hVAD->prim_act_he_fx = mac_r(L_mult(3277,tmp),29491, hVAD->prim_act_he_fx); + hVAD->prim_act_he_fx = mac_r( L_mult( 3277, tmp ), 29491, hVAD->prim_act_he_fx ); - if (L_and(hVAD->vad_flag_reg_H, (Word32) 0x40000L) != 0) /* 0x4000L = 0x01L << 18 */ + if ( L_and( hVAD->vad_flag_reg_H, (Word32) 0x40000L ) != 0 ) /* 0x4000L = 0x01L << 18 */ { - hVAD->vad_flag_cnt_50 = sub(hVAD->vad_flag_cnt_50,1); + hVAD->vad_flag_cnt_50 = sub( hVAD->vad_flag_cnt_50, 1 ); } - hVAD->vad_flag_reg_H = L_shl(L_and(hVAD->vad_flag_reg_H, (Word32) 0x3fffffffL ), 1); + hVAD->vad_flag_reg_H = L_shl( L_and( hVAD->vad_flag_reg_H, (Word32) 0x3fffffffL ), 1 ); - if (L_and(hVAD->vad_flag_reg_L, (Word32) 0x40000000L) != 0) + if ( L_and( hVAD->vad_flag_reg_L, (Word32) 0x40000000L ) != 0 ) { - hVAD->vad_flag_reg_H = L_or(hVAD->vad_flag_reg_H, 0x01L); + hVAD->vad_flag_reg_H = L_or( hVAD->vad_flag_reg_H, 0x01L ); } - hVAD->vad_flag_reg_L = L_shl(L_and(hVAD->vad_flag_reg_L, (Word32) 0x3fffffffL ), 1); + hVAD->vad_flag_reg_L = L_shl( L_and( hVAD->vad_flag_reg_L, (Word32) 0x3fffffffL ), 1 ); - IF ( flag != 0 ) /* should not include the extra DTX hangover */ + IF( flag != 0 ) /* should not include the extra DTX hangover */ { - hVAD->vad_flag_reg_L = L_or(hVAD->vad_flag_reg_L, 0x01L); - hVAD->vad_flag_cnt_50 = add(hVAD->vad_flag_cnt_50, 1); + hVAD->vad_flag_reg_L = L_or( hVAD->vad_flag_reg_L, 0x01L ); + hVAD->vad_flag_cnt_50 = add( hVAD->vad_flag_cnt_50, 1 ); } - if (L_and(hVAD->vad_prim_reg, (Word32) 0x8000L) != 0) /* 0x8000L = 1L << 15 */ + if ( L_and( hVAD->vad_prim_reg, (Word32) 0x8000L ) != 0 ) /* 0x8000L = 1L << 15 */ { - hVAD->vad_prim_cnt_16 = sub(hVAD->vad_prim_cnt_16,1); + hVAD->vad_prim_cnt_16 = sub( hVAD->vad_prim_cnt_16, 1 ); } - hVAD->vad_prim_reg = L_shl(L_and(hVAD->vad_prim_reg, (Word32) 0x3fffffffL ), 1); + hVAD->vad_prim_reg = L_shl( L_and( hVAD->vad_prim_reg, (Word32) 0x3fffffffL ), 1 ); - IF ( st_fx->localVAD != 0 ) + IF( st_fx->localVAD != 0 ) { - hVAD->vad_prim_reg = L_or(hVAD->vad_prim_reg, 0x01L); - hVAD->vad_prim_cnt_16 = add(hVAD->vad_prim_cnt_16,1); + hVAD->vad_prim_reg = L_or( hVAD->vad_prim_reg, 0x01L ); + hVAD->vad_prim_cnt_16 = add( hVAD->vad_prim_cnt_16, 1 ); } return flag; } - - - - diff --git a/lib_enc/vad_param_updt_fx.c b/lib_enc/vad_param_updt_fx.c index 61b4c2230..3012600fa 100644 --- a/lib_enc/vad_param_updt_fx.c +++ b/lib_enc/vad_param_updt_fx.c @@ -3,13 +3,13 @@ ====================================================================================*/ #include #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ //#include "prot_fx.h" /* Function prototypes */ -#include "ivas_stat_enc.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "ivas_stat_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* * vad_param_updt() @@ -18,49 +18,52 @@ *--------------------------------------------------------------------*/ void vad_param_updt_fx( - Encoder_State *st_fx, /* i/o: state structure */ - const Word16 old_pitch1, /* i : OL pitch value from last frame */ - const Word16 corr_shift, /* i : correlation shift Q15*/ - const Word16 corr_shiftR, /* i : correlation shift */ - const Word16 Az[], /* i: a coeffs Q12 */ + Encoder_State *st_fx, /* i/o: state structure */ + const Word16 old_pitch1, /* i : OL pitch value from last frame */ + const Word16 corr_shift, /* i : correlation shift Q15*/ + const Word16 corr_shiftR, /* i : correlation shift */ + const Word16 Az[], /* i: a coeffs Q12 */ FRONT_VAD_ENC_HANDLE hFrontVad[], /* i/o: front-VAD handles */ - const Word16 n_channels /* i : number of channels */ + const Word16 n_channels /* i : number of channels */ ) { Word16 voice_tmp, pitch_tmp; Word32 L_tmp; - Word16 refl[M+1]; - Word16 tmp1,tmp2; + Word16 refl[M + 1]; + Word16 tmp1, tmp2; Word16 tmp_active_flag; Word16 i, ini_frame, corr_shift_temp[2]; VAD_HANDLE hVAD; - DTX_ENC_HANDLE hDtxEnc = st_fx->hDtxEnc; + DTX_ENC_HANDLE hDtxEnc = st_fx->hDtxEnc; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif corr_shift_temp[0] = corr_shift; corr_shift_temp[1] = corr_shiftR; - move16(); move16(); + move16(); + move16(); hVAD = st_fx->hVAD; ini_frame = st_fx->ini_frame; - move16();move16(); + move16(); + move16(); - IF (hFrontVad != NULL) + IF( hFrontVad != NULL ) { hVAD = hFrontVad[0]->hVAD; ini_frame = hFrontVad[0]->ini_frame; - move16(); move16(); + move16(); + move16(); } - FOR(i = 0; i < n_channels; i++) + FOR( i = 0; i < n_channels; i++ ) { - if (EQ_16(i, 1)) + if ( EQ_16( i, 1 ) ) { hVAD = hFrontVad[1]->hVAD; move16(); } - IF(!st_fx->Opt_AMR_WB) + IF( !st_fx->Opt_AMR_WB ) { /* fix explanation , after function dtx_fx, the "vad_flag" parameter can not be used for SID scheduling purposes any longer @@ -70,33 +73,33 @@ void vad_param_updt_fx( tmp_active_flag = 0; move16(); test(); - if ((NE_32(st_fx->core_brate, (Word32)SID_2k40)) && (st_fx->core_brate != 0)) /* Note, core_brate_fx can be -1 */ + if ( ( NE_32( st_fx->core_brate, (Word32) SID_2k40 ) ) && ( st_fx->core_brate != 0 ) ) /* Note, core_brate_fx can be -1 */ { tmp_active_flag = 1; move16(); /* reqires active coding according to dtx_fx logic */ } test(); test(); - IF((st_fx->Opt_DTX_ON != 0) && (tmp_active_flag == 0) && (GT_16(ini_frame, 3))) + IF( ( st_fx->Opt_DTX_ON != 0 ) && ( tmp_active_flag == 0 ) && ( GT_16( ini_frame, 3 ) ) ) { /* update the counter of consecutive inactive frames in DTX */ - hVAD->consec_inactive = add(hVAD->consec_inactive, 1); - IF(GT_16(hVAD->consec_inactive, 5)) + hVAD->consec_inactive = add( hVAD->consec_inactive, 1 ); + IF( GT_16( hVAD->consec_inactive, 5 ) ) { hVAD->consec_inactive = 5; move16(); } - IF(EQ_16(hVAD->consec_inactive, 5)) + IF( EQ_16( hVAD->consec_inactive, 5 ) ) { /* compute spectral tilt parameter */ - a2rc_fx(&Az[1], refl, M); /* cast to kill MSVC warning */ + a2rc_fx( &Az[1], refl, M ); /* cast to kill MSVC warning */ /* i: Az in Q12 */ /* o: refl in Q15 */ - IF(EQ_16(hVAD->spectral_tilt_reset, 1)) + IF( EQ_16( hVAD->spectral_tilt_reset, 1 ) ) { hVAD->spectral_tilt_reset = 0; move16(); @@ -108,16 +111,16 @@ void vad_param_updt_fx( /* st_fx->ra_deltasum_fx += (0.80f * st_fx->running_avg_fx + 0.20f * refl[0]) - st_fx->running_avg_fx; st_fx->running_avg_fx = 0.80f * st_fx->running_avg_fx + 0.20f * refl[0]; */ - tmp1 = mult(6553, hVAD->running_avg_fx); /* = -0.80f * st_fx->running_avg_fx + st_fx->running_avg_fx*/ - tmp2 = mult(6553, refl[0]); - hVAD->ra_deltasum_fx = add(hVAD->ra_deltasum_fx, sub(tmp2, tmp1)); + tmp1 = mult( 6553, hVAD->running_avg_fx ); /* = -0.80f * st_fx->running_avg_fx + st_fx->running_avg_fx*/ + tmp2 = mult( 6553, refl[0] ); + hVAD->ra_deltasum_fx = add( hVAD->ra_deltasum_fx, sub( tmp2, tmp1 ) ); move16(); - tmp1 = mult(26214, hVAD->running_avg_fx); - hVAD->running_avg_fx = add(tmp1, tmp2); + tmp1 = mult( 26214, hVAD->running_avg_fx ); + hVAD->running_avg_fx = add( tmp1, tmp2 ); move16(); - IF(GT_16(abs_s(hVAD->ra_deltasum_fx), 6553)) /*0.2 in Q15*/ + IF( GT_16( abs_s( hVAD->ra_deltasum_fx ), 6553 ) ) /*0.2 in Q15*/ { hVAD->spectral_tilt_reset = 1; move16(); @@ -138,9 +141,9 @@ void vad_param_updt_fx( move16(); } - IF( EQ_16(hVAD->trigger_SID, 1)) + IF( EQ_16( hVAD->trigger_SID, 1 ) ) { - IF(GE_16(hDtxEnc->cng_cnt, 8)) + IF( GE_16( hDtxEnc->cng_cnt, 8 ) ) { /* Declare SID frame due to spectral tilt changes */ hDtxEnc->cnt_SID = 1; @@ -150,7 +153,7 @@ void vad_param_updt_fx( hVAD->trigger_SID = 0; move16(); } - ELSE IF(EQ_32(st_fx->core_brate, SID_2k40)) + ELSE IF( EQ_32( st_fx->core_brate, SID_2k40 ) ) { /* SID fame has already been declared before */ hVAD->trigger_SID = 0; @@ -160,23 +163,22 @@ void vad_param_updt_fx( } - /* (voicing[0] + voicing[1] + voicing[2]) / 3 + corr_shift */ - L_tmp = L_mult(st_fx->voicing_fx[0], 10923); - L_tmp = L_mac(L_tmp, st_fx->voicing_fx[1], 10923); - L_tmp = L_mac(L_tmp, st_fx->voicing_fx[2], 10923); /*Q15 */ + L_tmp = L_mult( st_fx->voicing_fx[0], 10923 ); + L_tmp = L_mac( L_tmp, st_fx->voicing_fx[1], 10923 ); + L_tmp = L_mac( L_tmp, st_fx->voicing_fx[2], 10923 ); /*Q15 */ #ifdef BASOP_NOGLOB - L_tmp = L_mac_o(L_tmp, corr_shift_temp[i], 32767, &Overflow); /*Q15 */ - voice_tmp = round_fx_o(L_tmp, &Overflow); /*Q15 */ -#else /* BASOP_NOGLOB */ - L_tmp = L_mac(L_tmp, corr_shift_temp[i], 32767); /*Q15 */ - voice_tmp = round_fx(L_tmp); /*Q15 */ + L_tmp = L_mac_o( L_tmp, corr_shift_temp[i], 32767, &Overflow ); /*Q15 */ + voice_tmp = round_fx_o( L_tmp, &Overflow ); /*Q15 */ +#else /* BASOP_NOGLOB */ + L_tmp = L_mac( L_tmp, corr_shift_temp[i], 32767 ); /*Q15 */ + voice_tmp = round_fx( L_tmp ); /*Q15 */ #endif /* abs(pitch[0] - *pitO) + abs(pitch[1] - pitch[0]) + abs(pitch[2] - pitch[1]) */ - pitch_tmp = abs_s(sub(st_fx->pitch_fx[0], old_pitch1)); /*Q0 */ - pitch_tmp = add(pitch_tmp, abs_s(sub(st_fx->pitch_fx[1], st_fx->pitch_fx[0]))); /*Q0 */ - pitch_tmp = add(pitch_tmp, abs_s(sub(st_fx->pitch_fx[2], st_fx->pitch_fx[1]))); /*Q0 */ + pitch_tmp = abs_s( sub( st_fx->pitch_fx[0], old_pitch1 ) ); /*Q0 */ + pitch_tmp = add( pitch_tmp, abs_s( sub( st_fx->pitch_fx[1], st_fx->pitch_fx[0] ) ) ); /*Q0 */ + pitch_tmp = add( pitch_tmp, abs_s( sub( st_fx->pitch_fx[2], st_fx->pitch_fx[1] ) ) ); /*Q0 */ /* if( (voicing[0] + voicing[1] + voicing[2]) / 3 + corr_shift > 0.65 && @@ -187,16 +189,15 @@ void vad_param_updt_fx( st->voiced_burst = 0; } */ - hVAD->voiced_burst = add(hVAD->voiced_burst, 1); + hVAD->voiced_burst = add( hVAD->voiced_burst, 1 ); move16(); test(); - if ((LE_16(voice_tmp, 21299)) /* 0.65 in Q15 */ - || (GE_16(pitch_tmp, 42))) /*3*14 = 42 Q0 */ + if ( ( LE_16( voice_tmp, 21299 ) ) /* 0.65 in Q15 */ + || ( GE_16( pitch_tmp, 42 ) ) ) /*3*14 = 42 Q0 */ { hVAD->voiced_burst = 0; move16(); } - } diff --git a/lib_enc/vad_proc_fx.c b/lib_enc/vad_proc_fx.c index d487e924d..add224340 100644 --- a/lib_enc/vad_proc_fx.c +++ b/lib_enc/vad_proc_fx.c @@ -12,10 +12,10 @@ #include "stat_enc.h" #include "rom_enc.h" #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ -#include "basop_util.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ +#include "basop_util.h" /* Function prototypes */ /*-------------------------------------------------------------------* * vad_init_fx() * @@ -27,12 +27,12 @@ Word16 vad_init_fx( { Word16 i = 0; - IF(hVAD_CLDFB == NULL) + IF( hVAD_CLDFB == NULL ) { return -1; } - hVAD_CLDFB->frameloop=0; + hVAD_CLDFB->frameloop = 0; move16(); hVAD_CLDFB->continuous_noise_num = 0; move16(); @@ -40,44 +40,44 @@ Word16 vad_init_fx( move16(); hVAD_CLDFB->continuous_speech_num2 = 0; move16(); - hVAD_CLDFB->fg_energy_est_start = L_deposit_l(0); + hVAD_CLDFB->fg_energy_est_start = L_deposit_l( 0 ); hVAD_CLDFB->speech_flag = 0; move16(); hVAD_CLDFB->frame_sb_energy_scale = 0; move16(); - hVAD_CLDFB->updateNumWithSnr=0; + hVAD_CLDFB->updateNumWithSnr = 0; move16(); hVAD_CLDFB->update_count = 0; move16(); hVAD_CLDFB->warm_hang_num = 0; move16(); - FOR(i = 0; i < SPEC_AMP_NUM; i++) + FOR( i = 0; i < SPEC_AMP_NUM; i++ ) { - hVAD_CLDFB->smooth_spec_amp[i] = L_deposit_l(0); + hVAD_CLDFB->smooth_spec_amp[i] = L_deposit_l( 0 ); } - FOR(i = 0; i < PRE_SNR_NUM; i++) + FOR( i = 0; i < PRE_SNR_NUM; i++ ) { - hVAD_CLDFB->pre_snr[i] = L_deposit_l(0); + hVAD_CLDFB->pre_snr[i] = L_deposit_l( 0 ); } - FOR(i = 0; i < BG_ENG_NUM; i++) + FOR( i = 0; i < BG_ENG_NUM; i++ ) { - hVAD_CLDFB->frame_sb_energy[i] = L_deposit_l(0); + hVAD_CLDFB->frame_sb_energy[i] = L_deposit_l( 0 ); } - hVAD_CLDFB->sfm[0] = 28835/* 0.88 Q15 */; + hVAD_CLDFB->sfm[0] = 28835 /* 0.88 Q15 */; move16(); - hVAD_CLDFB->sfm[1] = 30146/* 0.92 Q15 */; + hVAD_CLDFB->sfm[1] = 30146 /* 0.92 Q15 */; move16(); - hVAD_CLDFB->sfm[2] = 30146/* 0.92 Q15 */; + hVAD_CLDFB->sfm[2] = 30146 /* 0.92 Q15 */; move16(); - hVAD_CLDFB->l_silence_snr_count = L_deposit_l(1); - hVAD_CLDFB->l_speech_snr_count = L_deposit_l(1); + hVAD_CLDFB->l_silence_snr_count = L_deposit_l( 1 ); + hVAD_CLDFB->l_speech_snr_count = L_deposit_l( 1 ); hVAD_CLDFB->lt_snr_org = 33554432; move32(); - hVAD_CLDFB->lf_snr_smooth = 167772155/* 5.0 Q25 */; + hVAD_CLDFB->lf_snr_smooth = 167772155 /* 5.0 Q25 */; move32(); hVAD_CLDFB->fg_energy = 1073741824; move32(); @@ -88,7 +88,7 @@ Word16 vad_init_fx( move32(); hVAD_CLDFB->bg_energy_scale = 57; move16(); - hVAD_CLDFB->lt_noise_sp_center_diff_counter = L_deposit_l(4); + hVAD_CLDFB->lt_noise_sp_center_diff_counter = L_deposit_l( 4 ); hVAD_CLDFB->t_bg_energy = 1374389535; move32(); @@ -114,52 +114,52 @@ Word16 vad_init_fx( move16(); hVAD_CLDFB->Q_frames_power_32 = 31; move16(); - hVAD_CLDFB->lt_bg_highf_eng = 131070/* 2.0 Q16 */; + hVAD_CLDFB->lt_bg_highf_eng = 131070 /* 2.0 Q16 */; move16(); - hVAD_CLDFB->lt_noise_sp_center0 = 1841/* 0.4 Q10 */; + hVAD_CLDFB->lt_noise_sp_center0 = 1841 /* 0.4 Q10 */; move16(); - hVAD_CLDFB->lt_noise_sp_center3 = 2046/* 0.4 Q10 */; + hVAD_CLDFB->lt_noise_sp_center3 = 2046 /* 0.4 Q10 */; move16(); - hVAD_CLDFB->music_background_rate = 15073/* 0.46 Q15 */; + hVAD_CLDFB->music_background_rate = 15073 /* 0.46 Q15 */; move16(); - hVAD_CLDFB->tonality_rate3 = 15073/* 0.46 Q15 */; + hVAD_CLDFB->tonality_rate3 = 15073 /* 0.46 Q15 */; move16(); - hVAD_CLDFB->lt_noise_sp_center_diff_sum = 409/* 0.4 Q10 */; + hVAD_CLDFB->lt_noise_sp_center_diff_sum = 409 /* 0.4 Q10 */; move32(); - hVAD_CLDFB->l_silence_snr = 32768/* 0.5 Q16 */; + hVAD_CLDFB->l_silence_snr = 32768 /* 0.5 Q16 */; move32(); - hVAD_CLDFB->l_speech_snr = 327675/* 5.0 Q16 */; + hVAD_CLDFB->l_speech_snr = 327675 /* 5.0 Q16 */; move32(); - FOR(i = 0; i < SP_CENTER_NUM; i++) + FOR( i = 0; i < SP_CENTER_NUM; i++ ) { - hVAD_CLDFB->sp_center[i] = 1228/* 1.2 Q10 */; + hVAD_CLDFB->sp_center[i] = 1228 /* 1.2 Q10 */; move16(); } - FOR(i = 0; i < STABLE_NUM; i++) + FOR( i = 0; i < STABLE_NUM; i++ ) { - hVAD_CLDFB->ltd_stable_rate[i] = 2294/* 0.07 Q15 */; + hVAD_CLDFB->ltd_stable_rate[i] = 2294 /* 0.07 Q15 */; move16(); } - FOR(i = 0; i < BG_ENG_NUM; i++) + FOR( i = 0; i < BG_ENG_NUM; i++ ) { - hVAD_CLDFB->sb_bg_energy[i] =1374389535; + hVAD_CLDFB->sb_bg_energy[i] = 1374389535; move32(); } hVAD_CLDFB->sb_bg_energy_scale = 37; move16(); - hVAD_CLDFB->f_tonality_rate[0] = 7864/* 0.48 Q14 */; + hVAD_CLDFB->f_tonality_rate[0] = 7864 /* 0.48 Q14 */; move16(); - hVAD_CLDFB->f_tonality_rate[1] = 7864/* 0.48 Q14 */; + hVAD_CLDFB->f_tonality_rate[1] = 7864 /* 0.48 Q14 */; move16(); - hVAD_CLDFB->f_tonality_rate[2] = 7864/* 0.48 Q14 */; + hVAD_CLDFB->f_tonality_rate[2] = 7864 /* 0.48 Q14 */; move16(); - FOR(i = 0; i < PRE_SPEC_DIF_NUM; i++) + FOR( i = 0; i < PRE_SPEC_DIF_NUM; i++ ) { hVAD_CLDFB->pre_spec_low_dif[i] = 4095; move16(); @@ -167,9 +167,9 @@ Word16 vad_init_fx( hVAD_CLDFB->scale_spec_low_dif = 12; move16(); - FOR (i = 0; i < 56; i++) + FOR( i = 0; i < 56; i++ ) { - hVAD_CLDFB->frames_power_32[i] = L_deposit_l(0); + hVAD_CLDFB->frames_power_32[i] = L_deposit_l( 0 ); } @@ -182,29 +182,29 @@ Word16 vad_init_ivas_fx( { Word16 i = 0; - IF(hVAD_CLDFB == NULL) + IF( hVAD_CLDFB == NULL ) { return -1; } hVAD_CLDFB->frameloop = 0; hVAD_CLDFB->lt_snr_org_fx = 33554432; /*Q26 */ - hVAD_CLDFB->lf_snr_smooth_fx = 167772155/* 5.0 Q25 */; - hVAD_CLDFB->l_silence_snr_fx = 32767/* 0.5 Q16 */; - hVAD_CLDFB->l_speech_snr_fx = 327675/* 5.0 Q16 */; + hVAD_CLDFB->lf_snr_smooth_fx = 167772155 /* 5.0 Q25 */; + hVAD_CLDFB->l_silence_snr_fx = 32767 /* 0.5 Q16 */; + hVAD_CLDFB->l_speech_snr_fx = 327675 /* 5.0 Q16 */; hVAD_CLDFB->l_silence_snr_count = 1; hVAD_CLDFB->l_speech_snr_count = 1; hVAD_CLDFB->fg_energy_fx = 1073741824; hVAD_CLDFB->bg_energy_fx = 1073741824; hVAD_CLDFB->fg_energy_count = 16; hVAD_CLDFB->bg_energy_count = 16; - hVAD_CLDFB->tonality_rate3_fx = 15073/* 0.46 Q15 */; - hVAD_CLDFB->music_background_rate_fx = 15073/* 0.46 Q15 */; - hVAD_CLDFB->lt_noise_sp_center_diff_sum_fx = 409/* 0.4 Q10 */; - hVAD_CLDFB->lt_noise_sp_center_diff_counter_fx = L_deposit_l(4); - hVAD_CLDFB->lt_noise_sp_center0_fx = 1841/* 0.4 Q10 */; - hVAD_CLDFB->lt_noise_sp_center3_fx = 2046/* 0.4 Q10 */; - hVAD_CLDFB->lt_bg_highf_eng_fx = 131070/* 2.0 Q16 */; + hVAD_CLDFB->tonality_rate3_fx = 15073 /* 0.46 Q15 */; + hVAD_CLDFB->music_background_rate_fx = 15073 /* 0.46 Q15 */; + hVAD_CLDFB->lt_noise_sp_center_diff_sum_fx = 409 /* 0.4 Q10 */; + hVAD_CLDFB->lt_noise_sp_center_diff_counter_fx = L_deposit_l( 4 ); + hVAD_CLDFB->lt_noise_sp_center0_fx = 1841 /* 0.4 Q10 */; + hVAD_CLDFB->lt_noise_sp_center3_fx = 2046 /* 0.4 Q10 */; + hVAD_CLDFB->lt_bg_highf_eng_fx = 131070 /* 2.0 Q16 */; hVAD_CLDFB->t_bg_energy_fx = 1374389535; hVAD_CLDFB->t_bg_energy_sum_fx = 1374389535; hVAD_CLDFB->tbg_energy_count = 1; @@ -219,60 +219,60 @@ Word16 vad_init_ivas_fx( hVAD_CLDFB->update_count = 0; hVAD_CLDFB->warm_hang_num = 0; - FOR(i = 0; i < PRE_SNR_NUM; i++) + FOR( i = 0; i < PRE_SNR_NUM; i++ ) { - hVAD_CLDFB->pre_snr_fx[i] = L_deposit_l(0); + hVAD_CLDFB->pre_snr_fx[i] = L_deposit_l( 0 ); } - FOR(i = 0; i < POWER_NUM; i++) + FOR( i = 0; i < POWER_NUM; i++ ) { - hVAD_CLDFB->frames_power_fx[i] = L_deposit_l(0); + hVAD_CLDFB->frames_power_fx[i] = L_deposit_l( 0 ); } - FOR(i = 0; i < SPEC_AMP_NUM; i++) + FOR( i = 0; i < SPEC_AMP_NUM; i++ ) { - hVAD_CLDFB->smooth_spec_amp_fx[i] = L_deposit_l(0); + hVAD_CLDFB->smooth_spec_amp_fx[i] = L_deposit_l( 0 ); } - hVAD_CLDFB->sfm_fx[0] = 28835/* 0.88 Q15 */; + hVAD_CLDFB->sfm_fx[0] = 28835 /* 0.88 Q15 */; move16(); - hVAD_CLDFB->sfm_fx[1] = 30146/* 0.92 Q15 */; + hVAD_CLDFB->sfm_fx[1] = 30146 /* 0.92 Q15 */; move16(); - hVAD_CLDFB->sfm_fx[2] = 30146/* 0.92 Q15 */; + hVAD_CLDFB->sfm_fx[2] = 30146 /* 0.92 Q15 */; move16(); - - FOR(i = 0; i < SP_CENTER_NUM; i++) + + FOR( i = 0; i < SP_CENTER_NUM; i++ ) { - hVAD_CLDFB->sp_center_fx[i] = 1228/* 1.2 Q10 */; + hVAD_CLDFB->sp_center_fx[i] = 1228 /* 1.2 Q10 */; move16(); } - FOR(i = 0; i < STABLE_NUM; i++) + FOR( i = 0; i < STABLE_NUM; i++ ) { - hVAD_CLDFB->ltd_stable_rate_fx[i] = 2294/* 0.07 Q15 */; + hVAD_CLDFB->ltd_stable_rate_fx[i] = 2294 /* 0.07 Q15 */; move16(); } - FOR(i = 0; i < BG_ENG_NUM; i++) + FOR( i = 0; i < BG_ENG_NUM; i++ ) { - hVAD_CLDFB->sb_bg_energy_fx[i] =1374389535; + hVAD_CLDFB->sb_bg_energy_fx[i] = 1374389535; move32(); } - FOR(i = 0; i < BG_ENG_NUM; i++) + FOR( i = 0; i < BG_ENG_NUM; i++ ) { - hVAD_CLDFB->frame_sb_energy_fx[i] = L_deposit_l(0); + hVAD_CLDFB->frame_sb_energy_fx[i] = L_deposit_l( 0 ); } - hVAD_CLDFB->f_tonality_rate_fx[0] = 7864/* 0.48 Q14 */; + hVAD_CLDFB->f_tonality_rate_fx[0] = 7864 /* 0.48 Q14 */; move16(); - hVAD_CLDFB->f_tonality_rate_fx[1] = 7864/* 0.48 Q14 */; + hVAD_CLDFB->f_tonality_rate_fx[1] = 7864 /* 0.48 Q14 */; move16(); - hVAD_CLDFB->f_tonality_rate_fx[2] = 7864/* 0.48 Q14 */; + hVAD_CLDFB->f_tonality_rate_fx[2] = 7864 /* 0.48 Q14 */; move16(); - FOR(i = 0; i < PRE_SPEC_DIF_NUM; i++) + FOR( i = 0; i < PRE_SPEC_DIF_NUM; i++ ) { hVAD_CLDFB->pre_spec_low_dif_fx[i] = 4095; move16(); @@ -282,23 +282,22 @@ Word16 vad_init_ivas_fx( } static void UpdateState( VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ - Word16 vad_flag, /* i : VAD flag */ - Word32 frame_energy, /* i : current frame energy */ - Word16 sacle_sbpower, /* i : the Scaling of current frame energy */ - Word32 update_flag, /* i : current frame update flag */ - Word16 music_backgound_f, /* i : background music flag */ - Word32 HB_Power, /* i : current frame high frequency energy */ - Word16 HB_Power_Q, /* i : the Scaling of current frame high frequency energy*/ - Word32 snr -) + Word16 vad_flag, /* i : VAD flag */ + Word32 frame_energy, /* i : current frame energy */ + Word16 sacle_sbpower, /* i : the Scaling of current frame energy */ + Word32 update_flag, /* i : current frame update flag */ + Word16 music_backgound_f, /* i : background music flag */ + Word32 HB_Power, /* i : current frame high frequency energy */ + Word16 HB_Power_Q, /* i : the Scaling of current frame high frequency energy*/ + Word32 snr ) { Word16 lt_bg_energy_scal; - Word32 tmp,tmp2; + Word32 tmp, tmp2; - tmp = MUL_F(hVAD_CLDFB->frame_energy_smooth, 31129/* 0.95 Q15 */); - tmp2 = MUL_F(frame_energy, 26214); - hVAD_CLDFB->frame_energy_smooth = VAD_L_ADD(tmp, hVAD_CLDFB->frame_energy_smooth_scale, tmp2, add(4, sacle_sbpower), <_bg_energy_scal); + tmp = MUL_F( hVAD_CLDFB->frame_energy_smooth, 31129 /* 0.95 Q15 */ ); + tmp2 = MUL_F( frame_energy, 26214 ); + hVAD_CLDFB->frame_energy_smooth = VAD_L_ADD( tmp, hVAD_CLDFB->frame_energy_smooth_scale, tmp2, add( 4, sacle_sbpower ), <_bg_energy_scal ); move32(); hVAD_CLDFB->frame_energy_smooth_scale = lt_bg_energy_scal; move16(); @@ -306,35 +305,35 @@ static void UpdateState( IF( vad_flag == 0 ) { - hVAD_CLDFB->lt_bg_highf_eng = L_add(MUL_F(hVAD_CLDFB->lt_bg_highf_eng, 31130), L_shr(MUL_F(HB_Power, 1638), sub(HB_Power_Q, lt_bg_highf_eng_Q))); + hVAD_CLDFB->lt_bg_highf_eng = L_add( MUL_F( hVAD_CLDFB->lt_bg_highf_eng, 31130 ), L_shr( MUL_F( HB_Power, 1638 ), sub( HB_Power_Q, lt_bg_highf_eng_Q ) ) ); } - if(LT_16(hVAD_CLDFB->frameloop, 1000)) + if ( LT_16( hVAD_CLDFB->frameloop, 1000 ) ) { - hVAD_CLDFB->frameloop = add(hVAD_CLDFB->frameloop, 1); + hVAD_CLDFB->frameloop = add( hVAD_CLDFB->frameloop, 1 ); move16(); } - background_update_fx(hVAD_CLDFB, sacle_sbpower, frame_energy, update_flag, music_backgound_f, snr); + background_update_fx( hVAD_CLDFB, sacle_sbpower, frame_energy, update_flag, music_backgound_f, snr ); - IF( vad_flag== 0) + IF( vad_flag == 0 ) { hVAD_CLDFB->continuous_speech_num2 = 0; move16(); - IF(GT_16(hVAD_CLDFB->continuous_noise_num, 10)) + IF( GT_16( hVAD_CLDFB->continuous_noise_num, 10 ) ) { hVAD_CLDFB->continuous_speech_num = 0; move16(); } - ELSE IF(GT_32(hVAD_CLDFB->continuous_speech_num, 9)) + ELSE IF( GT_32( hVAD_CLDFB->continuous_speech_num, 9 ) ) { hVAD_CLDFB->continuous_speech_num = 9; move16(); } - hVAD_CLDFB->continuous_noise_num = add(hVAD_CLDFB->continuous_noise_num, 1); + hVAD_CLDFB->continuous_noise_num = add( hVAD_CLDFB->continuous_noise_num, 1 ); move16(); - if(GT_16(hVAD_CLDFB->continuous_noise_num, 2048)) + if ( GT_16( hVAD_CLDFB->continuous_noise_num, 2048 ) ) { hVAD_CLDFB->continuous_noise_num = 2048; move16(); @@ -345,26 +344,25 @@ static void UpdateState( hVAD_CLDFB->continuous_noise_num = 0; move16(); - hVAD_CLDFB->continuous_speech_num2 = add(hVAD_CLDFB->continuous_speech_num2, 1); - hVAD_CLDFB->continuous_speech_num = add(hVAD_CLDFB->continuous_speech_num, 1); - if(GT_16(hVAD_CLDFB->continuous_speech_num, 2048)) + hVAD_CLDFB->continuous_speech_num2 = add( hVAD_CLDFB->continuous_speech_num2, 1 ); + hVAD_CLDFB->continuous_speech_num = add( hVAD_CLDFB->continuous_speech_num, 1 ); + if ( GT_16( hVAD_CLDFB->continuous_speech_num, 2048 ) ) { hVAD_CLDFB->continuous_speech_num = 2048; move16(); } - if(GT_16(hVAD_CLDFB->continuous_speech_num2, 2048)) + if ( GT_16( hVAD_CLDFB->continuous_speech_num2, 2048 ) ) { hVAD_CLDFB->continuous_speech_num2 = 2048; move16(); } } - } Word16 vad_proc_fx( - VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ + VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i : real values */ Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i : imag values */ Word16 riBuffer_exp, /* i : exponent of real & imag Buffer */ @@ -380,28 +378,28 @@ Word16 vad_proc_fx( Word16 music_backgound_f; Word16 Q_cldfb; Word16 frame_energy2_Q, HB_Power_Q; - Word16 sb_power_Q,frame_energy_Q; + Word16 sb_power_Q, frame_energy_Q; Word32 frame_energy, frame_energy2, HB_Power; Word32 spec_amp[120]; - Word32 update_flag,snr_flux,lt_snr_org,lt_snr,lf_snr; - Word32 snr,tsnr; + Word32 update_flag, snr_flux, lt_snr_org, lt_snr, lf_snr; + Word32 snr, tsnr; Word16 vad_flag; Word32 *cldfbBufferReal[CLDFB_NO_COL_MAX]; /* dynamic scaling; cldfbBufferReal_float[x][y] = cldfbBufferReal[x][y] * 2^(-Q_cldfb) */ Word32 *cldfbBufferImag[CLDFB_NO_COL_MAX]; /* dynamic scaling; cldfbBufferImag_float[x][y] = cldfbBufferReal[x][y] * 2^(-Q_cldfb) */ music_backgound_f = 0; - move16(); + move16(); frame_energy = 0; - move32(); + move32(); - IF(LT_16(numBands, 20)) + IF( LT_16( numBands, 20 ) ) { bw_index = 1; move16(); } - ELSE IF(LT_16(numBands, 40)) + ELSE IF( LT_16( numBands, 40 ) ) { bw_index = 2; move16(); @@ -414,7 +412,7 @@ Word16 vad_proc_fx( hVAD_CLDFB->bw_index = bw_index; move16(); - FOR (i=0; iframe_sb_energy, &frame_energy2, &HB_Power,&frame_energy, &sb_power_Q, &frame_energy2_Q, &HB_Power_Q, &frame_energy_Q, - &hVAD_CLDFB->frame_sb_energy_scale,bw_index ); + est_energy_fx( enerBuffer, enerBuffer_exp, hVAD_CLDFB->frame_sb_energy, &frame_energy2, &HB_Power, &frame_energy, &sb_power_Q, &frame_energy2_Q, &HB_Power_Q, &frame_energy_Q, + &hVAD_CLDFB->frame_sb_energy_scale, bw_index ); - subband_FFT_fx(cldfbBufferReal, cldfbBufferImag, spec_amp, 0, &Q_cldfb ); + subband_FFT_fx( cldfbBufferReal, cldfbBufferImag, spec_amp, 0, &Q_cldfb ); - frame_spec_dif_cor_rate_fx(hVAD_CLDFB, spec_amp, add(Q_cldfb, 8), hVAD_CLDFB->f_tonality_rate ); + frame_spec_dif_cor_rate_fx( hVAD_CLDFB, spec_amp, add( Q_cldfb, 8 ), hVAD_CLDFB->f_tonality_rate ); - spec_center_fx(enerBuffer, hVAD_CLDFB->sp_center, bw_index, sb_power_Q ); + spec_center_fx( enerBuffer, hVAD_CLDFB->sp_center, bw_index, sb_power_Q ); - ltd_stable_fx(hVAD_CLDFB, hVAD_CLDFB->ltd_stable_rate, frame_energy, hVAD_CLDFB->frameloop, frame_energy_Q ); + ltd_stable_fx( hVAD_CLDFB, hVAD_CLDFB->ltd_stable_rate, frame_energy, hVAD_CLDFB->frameloop, frame_energy_Q ); - spec_flatness_fx(spec_amp, hVAD_CLDFB->smooth_spec_amp, hVAD_CLDFB->sfm ); + spec_flatness_fx( spec_amp, hVAD_CLDFB->smooth_spec_amp, hVAD_CLDFB->sfm ); - bg_music_decision_fx(hVAD_CLDFB, &music_backgound_f, frame_energy, frame_energy_Q); + bg_music_decision_fx( hVAD_CLDFB, &music_backgound_f, frame_energy, frame_energy_Q ); - snr_calc(hVAD_CLDFB, frame_energy2_Q, &snr, &tsnr, frame_energy2, bw_index ); + snr_calc( hVAD_CLDFB, frame_energy2_Q, &snr, &tsnr, frame_energy2, bw_index ); - calc_snr_flux_fx(tsnr, hVAD_CLDFB->pre_snr, &snr_flux); + calc_snr_flux_fx( tsnr, hVAD_CLDFB->pre_snr, &snr_flux ); - calc_lt_snr_fx(hVAD_CLDFB, <_snr_org, <_snr, hVAD_CLDFB->fg_energy, hVAD_CLDFB->fg_energy_count, hVAD_CLDFB->bg_energy, - hVAD_CLDFB->bg_energy_count, bw_index, hVAD_CLDFB->lt_noise_sp_center0); + calc_lt_snr_fx( hVAD_CLDFB, <_snr_org, <_snr, hVAD_CLDFB->fg_energy, hVAD_CLDFB->fg_energy_count, hVAD_CLDFB->bg_energy, + hVAD_CLDFB->bg_energy_count, bw_index, hVAD_CLDFB->lt_noise_sp_center0 ); - calc_lf_snr_fx(&hVAD_CLDFB->lf_snr_smooth, &lf_snr, hVAD_CLDFB->l_speech_snr, hVAD_CLDFB->l_speech_snr_count, hVAD_CLDFB->l_silence_snr, - hVAD_CLDFB->l_silence_snr_count, hVAD_CLDFB->fg_energy_count, hVAD_CLDFB->bg_energy_count, bw_index ); + calc_lf_snr_fx( &hVAD_CLDFB->lf_snr_smooth, &lf_snr, hVAD_CLDFB->l_speech_snr, hVAD_CLDFB->l_speech_snr_count, hVAD_CLDFB->l_silence_snr, + hVAD_CLDFB->l_silence_snr_count, hVAD_CLDFB->fg_energy_count, hVAD_CLDFB->bg_energy_count, bw_index ); - vad_flag = comvad_decision_fx(hVAD_CLDFB, lf_snr, lt_snr_org, lt_snr,snr_flux, snr, tsnr, frame_energy2, music_backgound_f, frame_energy2_Q, - cldfb_addition, vada_flag); + vad_flag = comvad_decision_fx( hVAD_CLDFB, lf_snr, lt_snr_org, lt_snr, snr_flux, snr, tsnr, frame_energy2, music_backgound_f, frame_energy2_Q, + cldfb_addition, vada_flag ); - update_flag = update_decision_fx(hVAD_CLDFB, frame_energy, HB_Power, hVAD_CLDFB->frameloop, bw_index,frame_energy_Q, - HB_Power_Q, snr, tsnr, hVAD_CLDFB->vad_flag_for_bk_update, music_backgound_f); + update_flag = update_decision_fx( hVAD_CLDFB, frame_energy, HB_Power, hVAD_CLDFB->frameloop, bw_index, frame_energy_Q, + HB_Power_Q, snr, tsnr, hVAD_CLDFB->vad_flag_for_bk_update, music_backgound_f ); - UpdateState(hVAD_CLDFB, hVAD_CLDFB->vad_flag_for_bk_update, frame_energy2, frame_energy2_Q, update_flag, music_backgound_f, HB_Power, HB_Power_Q, snr); + UpdateState( hVAD_CLDFB, hVAD_CLDFB->vad_flag_for_bk_update, frame_energy2, frame_energy2_Q, update_flag, music_backgound_f, HB_Power, HB_Power_Q, snr ); return vad_flag; } - - - diff --git a/lib_enc/vbr_average_rate_fx.c b/lib_enc/vbr_average_rate_fx.c index 9d0c6bce8..659eec524 100644 --- a/lib_enc/vbr_average_rate_fx.c +++ b/lib_enc/vbr_average_rate_fx.c @@ -3,19 +3,19 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ //#include "prot_fx.h" /* Function prototypes */ #include "rom_com_fx.h" /* Static table prototypes */ -#include "stat_enc.h" /* Static table prototypes */ +#include "stat_enc.h" /* Static table prototypes */ #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ -#include "basop_util.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ +#include "basop_util.h" /* Function prototypes */ -#define RATEWIN 600 /* length of the rate control window. This is 600 active speech frames. This equals roughly 12s of active speech */ +#define RATEWIN 600 /* length of the rate control window. This is 600 active speech frames. This equals roughly 12s of active speech */ /*=================================================================================*/ /* FUNCTION : update_average_rate_fx */ @@ -42,90 +42,91 @@ /*=================================================================================*/ void update_average_rate_fx( SC_VBR_ENC_HANDLE hSC_VBR, /* i/o: SC-VBR state structure */ - const Word32 core_brate_fx /* i : core bitrate */ + const Word32 core_brate_fx /* i : core bitrate */ ) { - Word32 avratetarg_fx; /* target rate for next RATEWIN active frames */ - Word32 target_fx; /* target set by VBR_ADR_MAX_TARGET*RATEWIN*10 */ + Word32 avratetarg_fx; /* target rate for next RATEWIN active frames */ + Word32 target_fx; /* target set by VBR_ADR_MAX_TARGET*RATEWIN*10 */ Word16 tmp; Word32 L_tmp; - Word32 L_tmp1,L_tmp2; + Word32 L_tmp1, L_tmp2; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif Word16 exp, recip, Qrecip; - IF ( EQ_16(hSC_VBR->numactive,RATEWIN)) /* goes into rate control only the numactive ==RATEWIN. So rate control is triggered after each RATEWIN avtive frames */ + IF( EQ_16( hSC_VBR->numactive, RATEWIN ) ) /* goes into rate control only the numactive ==RATEWIN. So rate control is triggered after each RATEWIN avtive frames */ { /* after 1000 blocks of RATEWIN frames, we change the way we control the average rate by using st->global_avr_rate=0.99*st->global_avr_rate+0.01*st->sum_of_rates. This will avoid veriables growing indefinitely while providing a good long term average rate */ - IF ( LT_32(hSC_VBR->frame_cnt_ratewin_fx,1000)) + IF( LT_32( hSC_VBR->frame_cnt_ratewin_fx, 1000 ) ) { - hSC_VBR->frame_cnt_ratewin_fx = add(hSC_VBR->frame_cnt_ratewin_fx,1); + hSC_VBR->frame_cnt_ratewin_fx = add( hSC_VBR->frame_cnt_ratewin_fx, 1 ); /*st->global_avr_rate = (st->global_avr_rate * (st->global_frame_cnt-1) + st->sum_of_rates) / st->global_frame_cnt; */ - exp = norm_s(hSC_VBR->frame_cnt_ratewin_fx); - tmp = shl(hSC_VBR->frame_cnt_ratewin_fx,exp); - recip = div_s(16384,tmp); - Qrecip = 15-(exp-14); + exp = norm_s( hSC_VBR->frame_cnt_ratewin_fx ); + tmp = shl( hSC_VBR->frame_cnt_ratewin_fx, exp ); + recip = div_s( 16384, tmp ); + Qrecip = 15 - ( exp - 14 ); - IF(GT_32(hSC_VBR->frame_cnt_ratewin_fx,1)) + IF( GT_32( hSC_VBR->frame_cnt_ratewin_fx, 1 ) ) { - tmp = div_s(sub(hSC_VBR->frame_cnt_ratewin_fx,1),hSC_VBR->frame_cnt_ratewin_fx); /*Q15*/ - L_tmp1 = Mult_32_16(hSC_VBR->global_avr_rate_fx, tmp); /* Q13*Q15 = Q13 */ + tmp = div_s( sub( hSC_VBR->frame_cnt_ratewin_fx, 1 ), hSC_VBR->frame_cnt_ratewin_fx ); /*Q15*/ + L_tmp1 = Mult_32_16( hSC_VBR->global_avr_rate_fx, tmp ); /* Q13*Q15 = Q13 */ - L_tmp2 = Mult_32_16(hSC_VBR->sum_of_rates_fx, recip); /*Q13*Qrecip = 13+Qrecip+1-16 = Qrecip-2 */ + L_tmp2 = Mult_32_16( hSC_VBR->sum_of_rates_fx, recip ); /*Q13*Qrecip = 13+Qrecip+1-16 = Qrecip-2 */ - hSC_VBR->global_avr_rate_fx = L_add(L_tmp1, L_shl(L_tmp2,13-(Qrecip-2))); /*Q13 */ + hSC_VBR->global_avr_rate_fx = L_add( L_tmp1, L_shl( L_tmp2, 13 - ( Qrecip - 2 ) ) ); /*Q13 */ } ELSE { - hSC_VBR->global_avr_rate_fx = hSC_VBR->sum_of_rates_fx; /*handle the first frame*/ + hSC_VBR->global_avr_rate_fx = hSC_VBR->sum_of_rates_fx; /*handle the first frame*/ } /* Q13 */ } ELSE { /* st->global_avr_rate = 0.01f * st->sum_of_rates + 0.99f * st->global_avr_rate; */ - hSC_VBR->global_avr_rate_fx = L_add(Mult_32_16(hSC_VBR->sum_of_rates_fx,328),Mult_32_16(hSC_VBR->global_avr_rate_fx,32441) ); /*Q13 */ + hSC_VBR->global_avr_rate_fx = L_add( Mult_32_16( hSC_VBR->sum_of_rates_fx, 328 ), Mult_32_16( hSC_VBR->global_avr_rate_fx, 32441 ) ); /*Q13 */ } - IF ( hSC_VBR->sum_of_rates_fx == 0 ) + IF( hSC_VBR->sum_of_rates_fx == 0 ) { /* st->sum_of_rates = (float) (RATEWIN * VBR_ADR_MAX_TARGET * 10); */ - hSC_VBR->sum_of_rates_fx = L_shl(L_mult0(RATEWIN ,VBR_ADR_MAX_TARGET_x10_Q1 ),12); /*Q13 */ + hSC_VBR->sum_of_rates_fx = L_shl( L_mult0( RATEWIN, VBR_ADR_MAX_TARGET_x10_Q1 ), 12 ); /*Q13 */ } /* target = VBR_ADR_MAX_TARGET * 10 * RATEWIN; */ - target_fx = L_shl(L_mult0(VBR_ADR_MAX_TARGET_x10_Q1,RATEWIN ),12); /*Q13 */ + target_fx = L_shl( L_mult0( VBR_ADR_MAX_TARGET_x10_Q1, RATEWIN ), 12 ); /*Q13 */ - IF ( LT_32(target_fx,hSC_VBR->global_avr_rate_fx)) /* Action is taken to reduce the averge rate. Only initiated if the global rate > target rate */ + IF( LT_32( target_fx, hSC_VBR->global_avr_rate_fx ) ) /* Action is taken to reduce the averge rate. Only initiated if the global rate > target rate */ { /* Check the vad snr values to table the noisey/not noisey decision */ test(); - IF ( LT_16(hSC_VBR->SNR_THLD_fx , 17152)) /*Q8 */ /* Currently in QFF mode. The bumpup thresholds are slightly relaxed for noisy speech. */ + IF( LT_16( hSC_VBR->SNR_THLD_fx, 17152 ) ) + /*Q8 */ /* Currently in QFF mode. The bumpup thresholds are slightly relaxed for noisy speech. */ { /* Increase the threshold so the the bumpup procedure is done using the noisy thresholds. Use 3.5 steps to quickly ramp up the rate control to reduce the settling time */ /* st->SNR_THLD += 3.5f; */ - hSC_VBR->SNR_THLD_fx = add(hSC_VBR->SNR_THLD_fx , 896 ); /*Q8 */ + hSC_VBR->SNR_THLD_fx = add( hSC_VBR->SNR_THLD_fx, 896 ); /*Q8 */ } - ELSE IF ( hSC_VBR->mode_QQF == 0 && GT_32(hSC_VBR->sum_of_rates_fx, target_fx)) /* Now SNR_THLD is in the max allowed. Sill the global average is higher and - last RATEWIN frames have a higher agerage than the target rate. Now slightly - more aggresive rate control is used by changing the mode to QQF. Still the - same strict bumpups (more bumpups,higher rate) are used. */ + ELSE IF( hSC_VBR->mode_QQF == 0 && GT_32( hSC_VBR->sum_of_rates_fx, target_fx ) ) /* Now SNR_THLD is in the max allowed. Sill the global average is higher and + last RATEWIN frames have a higher agerage than the target rate. Now slightly + more aggresive rate control is used by changing the mode to QQF. Still the + same strict bumpups (more bumpups,higher rate) are used. */ { /* Kick in QQF mode */ hSC_VBR->mode_QQF = 1; move16(); } - ELSE IF ( GT_32(hSC_VBR->sum_of_rates_fx , target_fx)) /* Actions (1) and (2) are not sufficient to control the rate. Still the last RATEWIN active + ELSE IF( GT_32( hSC_VBR->sum_of_rates_fx, target_fx ) ) /* Actions (1) and (2) are not sufficient to control the rate. Still the last RATEWIN active frames have a higher average rate than the target rate. More aggresive rate control is needed. At this point the rate_control flag is set. This will enable the more relaxed bump up thresholds (less bump ups->reduced rate)*/ @@ -135,10 +136,10 @@ void update_average_rate_fx( move16(); /* This will be triggered only if the gloabl average rate is considerablly higher than the target rate. Keep a higher threshold to avoid short term rate increases over the target rate. */ - IF ( GT_32(hSC_VBR->global_avr_rate_fx ,L_add(target_fx,3440640))) /* Last resort rate control. This is a safer rate control mechanism by increasing NELPS */ + IF( GT_32( hSC_VBR->global_avr_rate_fx, L_add( target_fx, 3440640 ) ) ) /* Last resort rate control. This is a safer rate control mechanism by increasing NELPS */ { hSC_VBR->Last_Resort = 1; - move16(); /* compute based on a larger window as the last resort */ + move16(); /* compute based on a larger window as the last resort */ } ELSE { @@ -146,9 +147,9 @@ void update_average_rate_fx( move16(); } } - ELSE IF ( LT_32(hSC_VBR->sum_of_rates_fx, target_fx )) /* If the average rate of last RATEWIN frames is controlled by above actions, disable the most - aggresive rate control mechanisms. Still keep QQF mode as the global rate is not under - the target rate*/ + ELSE IF( LT_32( hSC_VBR->sum_of_rates_fx, target_fx ) ) /* If the average rate of last RATEWIN frames is controlled by above actions, disable the most + aggresive rate control mechanisms. Still keep QQF mode as the global rate is not under + the target rate*/ { hSC_VBR->Last_Resort = 0; move16(); @@ -164,21 +165,21 @@ void update_average_rate_fx( hSC_VBR->Last_Resort = 0; move16(); - IF ( EQ_16(hSC_VBR->rate_control,1)) + IF( EQ_16( hSC_VBR->rate_control, 1 ) ) { hSC_VBR->rate_control = 0; move16(); } - ELSE IF ( EQ_16(hSC_VBR->mode_QQF,1)) /* now rate control is not active and still the global rate is below the target. so go to QFF mode */ + ELSE IF( EQ_16( hSC_VBR->mode_QQF, 1 ) ) /* now rate control is not active and still the global rate is below the target. so go to QFF mode */ { hSC_VBR->mode_QQF = 0; move16(); } ELSE { - IF ( GE_16(hSC_VBR->SNR_THLD_fx, 15360)) + IF( GE_16( hSC_VBR->SNR_THLD_fx, 15360 ) ) { - hSC_VBR->SNR_THLD_fx =sub(hSC_VBR->SNR_THLD_fx ,384 ); /*Q8 */ + hSC_VBR->SNR_THLD_fx = sub( hSC_VBR->SNR_THLD_fx, 384 ); /*Q8 */ } ELSE { @@ -188,8 +189,8 @@ void update_average_rate_fx( } } - IF ( LT_32(hSC_VBR->global_avr_rate_fx , L_sub(target_fx,983040))) /* In QFF mode and global rate is less than target rate-0.2kbps. We can send some Q frames - to F frames to improve the quality */ + IF( LT_32( hSC_VBR->global_avr_rate_fx, L_sub( target_fx, 983040 ) ) ) /* In QFF mode and global rate is less than target rate-0.2kbps. We can send some Q frames + to F frames to improve the quality */ { /* kick in bouncing back from Q to F */ hSC_VBR->Q_to_F = 1; @@ -197,7 +198,7 @@ void update_average_rate_fx( /* average rate for next 600ms = global_rate * 2 - rate of the past RATEWIN active frames */ /* avratetarg = (float)((RATEWIN * 10) * 2 * VBR_ADR_MAX_TARGET - st->global_avr_rate); */ - avratetarg_fx = L_sub(L_shl(L_mult0(RATEWIN ,VBR_ADR_MAX_TARGET_x10_Q1 ),13), hSC_VBR->global_avr_rate_fx ); + avratetarg_fx = L_sub( L_shl( L_mult0( RATEWIN, VBR_ADR_MAX_TARGET_x10_Q1 ), 13 ), hSC_VBR->global_avr_rate_fx ); /* Q13 */ @@ -205,23 +206,23 @@ void update_average_rate_fx( st->pattern_m=100 . Later this value is used in voiced.enc to bump up 10% of PPP frames to F frames. */ /* st->pattern_m = (short)(1000 * (avratetarg - 6.15f * RATEWIN * 10)/(10 * RATEWIN * 0.1f) ); */ - L_tmp = L_mult0(RATEWIN ,VBR_ADR_MAX_TARGET_x10_Q1 ); - L_tmp = L_shl(L_tmp , 12); - L_tmp = L_sub(avratetarg_fx , L_tmp); - tmp = extract_h(L_shl(Mult_32_16(L_tmp,27307),4)); - hSC_VBR->pattern_m =tmp; + L_tmp = L_mult0( RATEWIN, VBR_ADR_MAX_TARGET_x10_Q1 ); + L_tmp = L_shl( L_tmp, 12 ); + L_tmp = L_sub( avratetarg_fx, L_tmp ); + tmp = extract_h( L_shl( Mult_32_16( L_tmp, 27307 ), 4 ) ); + hSC_VBR->pattern_m = tmp; move16(); if ( hSC_VBR->pattern_m < 0 ) { hSC_VBR->pattern_m = 0; - move16(); /* no bump up will ever happen */ + move16(); /* no bump up will ever happen */ } - if ( GT_16(hSC_VBR->pattern_m,1000)) + if ( GT_16( hSC_VBR->pattern_m, 1000 ) ) { hSC_VBR->pattern_m = 1000; - move16();/* 10% of bump ups */ + move16(); /* 10% of bump ups */ } hSC_VBR->patterncount = 0; @@ -237,20 +238,18 @@ void update_average_rate_fx( move16(); hSC_VBR->numactive = 0; move16(); - } - hSC_VBR->numactive = add(hSC_VBR->numactive,1); + hSC_VBR->numactive = add( hSC_VBR->numactive, 1 ); /* sum the total number of bits (in kbytes) * 10 here */ /*st->sum_of_rates += (hSC_VBR->core_brate / 1000.0f) * 10; */ - L_tmp = L_shl(Mult_32_16(core_brate_fx ,20972),7); + L_tmp = L_shl( Mult_32_16( core_brate_fx, 20972 ), 7 ); #ifdef BASOP_NOGLOB - hSC_VBR->sum_of_rates_fx = L_add_o(hSC_VBR->sum_of_rates_fx ,L_tmp, &Overflow); + hSC_VBR->sum_of_rates_fx = L_add_o( hSC_VBR->sum_of_rates_fx, L_tmp, &Overflow ); #else - hSC_VBR->sum_of_rates_fx = L_add(hSC_VBR->sum_of_rates_fx ,L_tmp); + hSC_VBR->sum_of_rates_fx = L_add( hSC_VBR->sum_of_rates_fx, L_tmp ); #endif return; } - diff --git a/lib_enc/vlpc_1st_cod_fx.c b/lib_enc/vlpc_1st_cod_fx.c index 691d088cb..561446aa5 100644 --- a/lib_enc/vlpc_1st_cod_fx.c +++ b/lib_enc/vlpc_1st_cod_fx.c @@ -9,11 +9,11 @@ //#include "prot_fx.h" #include "rom_com_fx.h" #include "rom_com.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ -#define ISF_ONE 3/*1.0f*1.28f Q1*/ /*=1.0f in 14Q1*1.28*/ +#define ISF_ONE 3 /*1.0f*1.28f Q1*/ /*=1.0f in 14Q1*1.28*/ /*------------------------------------------------------------------* * lsf_weight() @@ -26,9 +26,8 @@ static void lsf_weight( Word16 *w /* o : lsf weighting vector (0Q15) */ ) { - Word16 i; - Word16 inv_di0, inv_di1; - + Word16 i; + Word16 inv_di0, inv_di1; /* weighting function */ @@ -36,53 +35,53 @@ static void lsf_weight( /*this happens when the ac function is nearly flat*/ i = lsfq[0]; move16(); - if (lsfq[0] == 0) + if ( lsfq[0] == 0 ) { i = lsfq[1]; move16(); } inv_di0 = 0x7fff; move16(); - if (GT_16(i, ISF_ONE)) + if ( GT_16( i, ISF_ONE ) ) { - inv_di0 = div_s(ISF_ONE,i); /*0Q15*/ /*inv_di0 = 1.0f / lsfq[0];*/ + inv_di0 = div_s( ISF_ONE, i ); /*0Q15*/ /*inv_di0 = 1.0f / lsfq[0];*/ } /* Allow saturation during weight calculation, because the values that are weighted later are used for a minimum search and experimental saturation avoidance also showed no improvement. */ BASOP_SATURATE_WARNING_OFF_EVS - FOR (i=1; i<(M-2); i+=2) /*for (i=1; i<(M-2); i+=2)*/ + FOR( i = 1; i < ( M - 2 ); i += 2 ) /*for (i=1; i<(M-2); i+=2)*/ { - inv_di1 = div_s(ISF_ONE,s_max(ISF_ONE, sub(lsfq[i],lsfq[i-1]))); /*0Q15*/ /*inv_di1 = 1.0f / (lsfq[i] - lsfq[i-1]);*/ + inv_di1 = div_s( ISF_ONE, s_max( ISF_ONE, sub( lsfq[i], lsfq[i - 1] ) ) ); /*0Q15*/ /*inv_di1 = 1.0f / (lsfq[i] - lsfq[i-1]);*/ #ifdef BASOP_NOGLOB w[i - 1] = add_sat( inv_di0, inv_di1 ); #else - w[i-1] = add(inv_di0,inv_di1); + w[i - 1] = add( inv_di0, inv_di1 ); #endif - move16(); /*0Q15*/ /*w[i-1] = inv_di0 + inv_di1;*/ - inv_di0 = div_s(ISF_ONE,s_max(ISF_ONE, sub(lsfq[i+1],lsfq[i]))); /*0Q15*/ /*inv_di0 = 1.0f / (lsfq[i+1] - lsfq[i]);*/ + move16(); /*0Q15*/ /*w[i-1] = inv_di0 + inv_di1;*/ + inv_di0 = div_s( ISF_ONE, s_max( ISF_ONE, sub( lsfq[i + 1], lsfq[i] ) ) ); /*0Q15*/ /*inv_di0 = 1.0f / (lsfq[i+1] - lsfq[i]);*/ #ifdef BASOP_NOGLOB w[i] = add_sat( inv_di1, inv_di0 ); #else - w[i] = add(inv_di1,inv_di0); + w[i] = add( inv_di1, inv_di0 ); #endif - move16(); /*0Q15*/ /*w[i] = inv_di1 + inv_di0;*/ + move16(); /*0Q15*/ /*w[i] = inv_di1 + inv_di0;*/ } - inv_di1 = div_s(ISF_ONE, s_max(ISF_ONE, sub(lsfq[i],lsfq[i-1]))); /*inv_di1 = 1.0f / (lsfq[i] - lsfq[i-1]);*/ + inv_di1 = div_s( ISF_ONE, s_max( ISF_ONE, sub( lsfq[i], lsfq[i - 1] ) ) ); /*inv_di1 = 1.0f / (lsfq[i] - lsfq[i-1]);*/ #ifdef BASOP_NOGLOB w[i - 1] = add_sat( inv_di0, inv_di1 ); #else - w[i-1] = add(inv_di0,inv_di1); + w[i - 1] = add( inv_di0, inv_di1 ); #endif - move16(); /*w[i-1] = inv_di0 + inv_di1;*/ - inv_di0 = div_s(ISF_ONE, s_max(ISF_ONE, sub(FREQ_MAX,lsfq[i]))); /*inv_di0 = 1.0f / (FREQ_MAX - lsfq[i]);*/ + move16(); /*w[i-1] = inv_di0 + inv_di1;*/ + inv_di0 = div_s( ISF_ONE, s_max( ISF_ONE, sub( FREQ_MAX, lsfq[i] ) ) ); /*inv_di0 = 1.0f / (FREQ_MAX - lsfq[i]);*/ #ifdef BASOP_NOGLOB w[i] = add_sat( inv_di1, inv_di0 ); #else w[i] = add( inv_di1, inv_di0 ); #endif - move16(); /*w[i] = inv_di1 + inv_di0;*/ + move16(); /*w[i] = inv_di1 + inv_di0;*/ BASOP_SATURATE_WARNING_ON_EVS @@ -90,65 +89,63 @@ static void lsf_weight( return; } /*------------------------------------------------------------------* -* vlpc_1st_cod_fx() -* -* -*------------------------------------------------------------------*/ -Word16 vlpc_1st_cod_fx( /* o : codebook index */ - const Word16 *lsf, /* i : vector to quantize (14Q1*1.28) */ - Word16 *lsfq, /* o : quantized lsf (14Q1*1.28) */ - Word16 *wout, /* o : lsf weights */ - Word16 rf_mode -) + * vlpc_1st_cod_fx() + * + * + *------------------------------------------------------------------*/ +Word16 vlpc_1st_cod_fx( /* o : codebook index */ + const Word16 *lsf, /* i : vector to quantize (14Q1*1.28) */ + Word16 *lsfq, /* o : quantized lsf (14Q1*1.28) */ + Word16 *wout, /* o : lsf weights */ + Word16 rf_mode ) { - Word16 i, j, index, diff, wdiff; - Word16 w[M]; - Word32 dist_min, dist; + Word16 i, j, index, diff, wdiff; + Word16 w[M]; + Word32 dist_min, dist; const Word16 *p_dico; - /* weighting */ - lsf_weight(lsf, w);/*lsf:14Q1*1.28=>w:0Q15*/ - IF(EQ_16(rf_mode, 1)) + lsf_weight( lsf, w ); /*lsf:14Q1*1.28=>w:0Q15*/ + IF( EQ_16( rf_mode, 1 ) ) { Word16 s; - s = Find_Max_Norm16(w, M); - Scale_sig(w, M, s); + s = Find_Max_Norm16( w, M ); + Scale_sig( w, M, s ); } - Copy(w, wout, M); + Copy( w, wout, M ); /* remove lsf prediction/means */ /*dist_min = 1.0e30f;*/ - dist_min = L_add(MAX_32, 0); - p_dico = dico_lsf_abs_8b; /*14Q1*1.28*/ + dist_min = L_add( MAX_32, 0 ); + p_dico = dico_lsf_abs_8b; /*14Q1*1.28*/ index = 0; move16(); - FOR (i = 0; i < 256; i++) + FOR( i = 0; i < 256; i++ ) { dist = 0; - move32(); - FOR (j = 0; j < M; j++) + move32(); + FOR( j = 0; j < M; j++ ) { - diff = sub(lsf[j], p_dico[j]); - wdiff = shr(mult_r(w[j],diff),4); - dist = L_mac(dist,wdiff,diff); + diff = sub( lsf[j], p_dico[j] ); + wdiff = shr( mult_r( w[j], diff ), 4 ); + dist = L_mac( dist, wdiff, diff ); } p_dico += M; - if (LT_32(dist,dist_min)) + if ( LT_32( dist, dist_min ) ) { - index = i; /* store index of new minimum */ + index = i; /* store index of new minimum */ move16(); } - dist_min = L_min(dist,dist_min); + dist_min = L_min( dist, dist_min ); } /* quantized vector */ p_dico = &dico_lsf_abs_8b[index * M]; - FOR (j = 0; j < M; j++) + FOR( j = 0; j < M; j++ ) { /*lsfq[j] += *p_dico++;*/ /* += cause it's differential# -> since isfq[i] is 0, only data move is sufficient*/ @@ -160,6 +157,3 @@ Word16 vlpc_1st_cod_fx( /* o : codebook index */ return index; } - - - diff --git a/lib_enc/vlpc_2st_cod_fx.c b/lib_enc/vlpc_2st_cod_fx.c index 70cfa036f..e0b2c427a 100644 --- a/lib_enc/vlpc_2st_cod_fx.c +++ b/lib_enc/vlpc_2st_cod_fx.c @@ -8,9 +8,9 @@ #include "options.h" //#include "prot_fx.h" #include "control.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" /*------------------------------------------------------------------* @@ -19,53 +19,54 @@ * *------------------------------------------------------------------*/ -Word16 vlpc_2st_cod_fx( /* output: number of allocated bits */ - const Word16 *lsf, /* i : normalized vector to quantize */ - Word16* lsfq, /* i/o: i:1st stage o:1st+2nd stage */ - Word16* indx, /* o : index[] (4 bits per words) */ - const Word16 mode, /* i : 0=abs, >0=rel */ - const Word32 sr_core/* i : internal sampling rate */ +Word16 vlpc_2st_cod_fx( /* output: number of allocated bits */ + const Word16 *lsf, /* i : normalized vector to quantize */ + Word16 *lsfq, /* i/o: i:1st stage o:1st+2nd stage */ + Word16 *indx, /* o : index[] (4 bits per words) */ + const Word16 mode, /* i : 0=abs, >0=rel */ + const Word32 sr_core /* i : internal sampling rate */ ) { - Word16 i, nbits; - Word16 w[M], x[M]; - Word16 nq, xq[M]; - Word32 L_tmp; - Word16 gap; + Word16 i, nbits; + Word16 w[M], x[M]; + Word16 nq, xq[M]; + Word32 L_tmp; + Word16 gap; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - /* 0 bit with true weighting: save 0.5 bit */ - lsf_weight_2st(lsf, w, 1); /*w:0Q15*1.28*/ + lsf_weight_2st( lsf, w, 1 ); /*w:0Q15*1.28*/ - FOR (i=1; i wops) */ - nbits = 6; /* 2*(2+1) */ move16(); + nbits = 6; /* 2*(2+1) */ + move16(); test(); - IF ( (mode == 0) || (EQ_16(mode,3))) + IF( ( mode == 0 ) || ( EQ_16( mode, 3 ) ) ) { - nbits = 10; /* 2*(2+3) */ move16(); + nbits = 10; /* 2*(2+3) */ + move16(); } - ELSE IF (EQ_16(mode,1)) + ELSE IF( EQ_16( mode, 1 ) ) { - nbits = 2; /* 2*1 */ move16(); + nbits = 2; /* 2*1 */ + move16(); } return nbits; } /* weighting from the 1st stage */ - lsf_weight_2st(lsfq, w, mode); + lsf_weight_2st( lsfq, w, mode ); /* find lsf and scale the residual */ - FOR (i=0; ifirstTime_voicedenc) + IF( hSC_VBR->firstTime_voicedenc ) { hSC_VBR->firstTime_voicedenc = 0; move16(); @@ -198,27 +197,27 @@ ivas_error ppp_voiced_encoder_fx( move16(); hSC_VBR->dtfs_enc_upper_cut_off_freq_fx = 4000; move16(); - set16_fx(hSC_VBR->dtfs_enc_a_fx, 0, MAXLAG_WI); - set16_fx(hSC_VBR->dtfs_enc_b_fx, 0, MAXLAG_WI); + set16_fx( hSC_VBR->dtfs_enc_a_fx, 0, MAXLAG_WI ); + set16_fx( hSC_VBR->dtfs_enc_b_fx, 0, MAXLAG_WI ); } test(); /* Figure out the PPP_MODE */ - IF ( EQ_16(hSC_VBR->last_ppp_mode,1)&&!hSC_VBR->mode_QQF) + IF( EQ_16( hSC_VBR->last_ppp_mode, 1 ) && !hSC_VBR->mode_QQF ) { hSC_VBR->bump_up = 1; move16(); - count_free(CURRP_NQ_FX); - count_free(TMPDTFS_FX); - count_free(TMPDTFS2_FX); - count_free(TMPDTFS3_FX); - count_free(CURRP_Q_E_FX); - count_free(dtfs_temp_fx); + count_free( CURRP_NQ_FX ); + count_free( TMPDTFS_FX ); + count_free( TMPDTFS2_FX ); + count_free( TMPDTFS3_FX ); + count_free( CURRP_Q_E_FX ); + count_free( dtfs_temp_fx ); return error; } /* Use the aggresive bumpups if there are two consecutive Q frames */ /* Aggresive bump upsare only used in the second Q frame */ - if (hSC_VBR->last_ppp_mode == 1 ) + if ( hSC_VBR->last_ppp_mode == 1 ) { hSC_VBR->rate_control = 0; } @@ -226,77 +225,77 @@ ivas_error ppp_voiced_encoder_fx( PPP_MODE_E = 'Q'; move16(); - pl = s_min(MAX_LAG_PIT, rint_new_fx(L_shl(old_pitch_buf[(2*NB_SUBFR)-1],10))); + pl = s_min( MAX_LAG_PIT, rint_new_fx( L_shl( old_pitch_buf[( 2 * NB_SUBFR ) - 1], 10 ) ) ); move16(); - l = s_min(MAX_LAG_PIT, rint_new_fx(L_deposit_h(delay_fx))); + l = s_min( MAX_LAG_PIT, rint_new_fx( L_deposit_h( delay_fx ) ) ); move16(); /* old_pitch_buf in Q6*/ /* Bump up if the lag is out_fx of range */ test(); - IF (GT_16(sub(l,pl),13)||LT_16(sub(l,pl),-11)||LT_16(l,19)||LT_16(pl,19)) + IF( GT_16( sub( l, pl ), 13 ) || LT_16( sub( l, pl ), -11 ) || LT_16( l, 19 ) || LT_16( pl, 19 ) ) { hSC_VBR->bump_up = 1; move16(); - count_free(CURRP_NQ_FX); - count_free(TMPDTFS_FX); - count_free(TMPDTFS2_FX); - count_free(TMPDTFS3_FX); - count_free(CURRP_Q_E_FX); - count_free(dtfs_temp_fx); + count_free( CURRP_NQ_FX ); + count_free( TMPDTFS_FX ); + count_free( TMPDTFS2_FX ); + count_free( TMPDTFS3_FX ); + count_free( CURRP_Q_E_FX ); + count_free( dtfs_temp_fx ); return error; } - IF (NE_16(hSC_VBR->last_ppp_mode,1)) + IF( NE_16( hSC_VBR->last_ppp_mode, 1 ) ) { /* Obtain DTFS of last pl values of past excitation */ - GetSinCosTab_fx(pl,S_fx,C_fx); - DTFS_to_fs_fx(exc_fx-pl, pl, dtfs_temp_fx, temp_Fs, 0,S_fx,C_fx); + GetSinCosTab_fx( pl, S_fx, C_fx ); + DTFS_to_fs_fx( exc_fx - pl, pl, dtfs_temp_fx, temp_Fs, 0, S_fx, C_fx ); } - if (EQ_16(last_coder_type_raw,UNVOICED)) + if ( EQ_16( last_coder_type_raw, UNVOICED ) ) { pl = l; move16(); /* if prev frame was sil/uv */ } /* Use the out_fx array as a temp storage for currp */ - spike_near_edge = ppp_extract_pitch_period_fx(in_fx, out_fx, l, &out_of_bound,Qres) ; + spike_near_edge = ppp_extract_pitch_period_fx( in_fx, out_fx, l, &out_of_bound, Qres ); move16(); /* out_fx in Qres */ - IF (out_of_bound == 1) + IF( out_of_bound == 1 ) { hSC_VBR->bump_up = 1; move16(); - count_free(CURRP_NQ_FX); - count_free(TMPDTFS_FX); - count_free(TMPDTFS2_FX); - count_free(TMPDTFS3_FX); - count_free(CURRP_Q_E_FX); - count_free(dtfs_temp_fx); + count_free( CURRP_NQ_FX ); + count_free( TMPDTFS_FX ); + count_free( TMPDTFS2_FX ); + count_free( TMPDTFS3_FX ); + count_free( CURRP_Q_E_FX ); + count_free( dtfs_temp_fx ); return error; } /* Get DTFS of current prototype */ - GetSinCosTab_fx(l,S_fx,C_fx); + GetSinCosTab_fx( l, S_fx, C_fx ); - DTFS_to_fs_fx(out_fx, l, CURRP_NQ_FX, temp_Fs, 0,S_fx,C_fx); + DTFS_to_fs_fx( out_fx, l, CURRP_NQ_FX, temp_Fs, 0, S_fx, C_fx ); /* This requires input out_fx in Q0, but currently in Qres */ /* Ensure the extracted prototype is time-synchronous to the * last l samples of the frame. This proves to eliminate * some of the PPP-CELP transition problems. * Convert last samples into DTFS */ - IF (spike_near_edge != 0) + IF( spike_near_edge != 0 ) { /* These two function calls are combined in one call DTFS_alignment_extract_td_fx() */ /* DTFS_to_fs(in+L_FRAME-l, l, TMPDTFS,(short) st->input_Fs,0); */ /* tmp = DTFS_alignment_extract(*TMPDTFS, *CURRP_NQ, 0.0, lpc2) ; */ - tmp = DTFS_alignment_extract_td_fx(out_fx, in_fx+L_FRAME-l, l) ; - move16(); /*Q0 */ - tmp = negate(shl(tmp,2));/*Q2 */ - Q2phaseShift_fx(CURRP_NQ_FX, tmp, l, S_fx,C_fx) ; + tmp = DTFS_alignment_extract_td_fx( out_fx, in_fx + L_FRAME - l, l ); + move16(); /*Q0 */ + tmp = negate( shl( tmp, 2 ) ); /*Q2 */ + Q2phaseShift_fx( CURRP_NQ_FX, tmp, l, S_fx, C_fx ); /* output CURRP_NQ is correct */ } temp_pl = pl; @@ -304,79 +303,79 @@ ivas_error ppp_voiced_encoder_fx( temp_l = l; move16(); - FOR(i = 0; i < NB_SUBFR; i++) + FOR( i = 0; i < NB_SUBFR; i++ ) { /* do the linear pitch_fx interp to drive the nb_post_filt_fx */ - Interpol_delay_fx(interp_delay, temp_pl, temp_l, i, frac_4sf_fx); /* interp_delay in Q4 */ - pitch_fx[i] = shl(interp_delay[0],2); - move16();/* pitch_fx in Q6 */ + Interpol_delay_fx( interp_delay, temp_pl, temp_l, i, frac_4sf_fx ); /* interp_delay in Q4 */ + pitch_fx[i] = shl( interp_delay[0], 2 ); + move16(); /* pitch_fx in Q6 */ } - curr_Engy=DTFS_getEngy_P2A_fx(CURRP_NQ_FX); /*2Q where Q=CURRP_NQ_FX->Q */ + curr_Engy = DTFS_getEngy_P2A_fx( CURRP_NQ_FX ); /*2Q where Q=CURRP_NQ_FX->Q */ /* Restoring PPP memories when the last frame is non-PPP */ - IF (NE_16(hSC_VBR->last_ppp_mode,1)) + IF( NE_16( hSC_VBR->last_ppp_mode, 1 ) ) { - hSC_VBR->ph_offset_E_fx = 0 ; + hSC_VBR->ph_offset_E_fx = 0; move16(); /* st->prev_cw_en = DTFS_getEngy(*dtfs_temp); */ - Lacc=DTFS_getEngy_P2A_fx(dtfs_temp_fx); /*2Q where Q = dtfs_temp_fx->Q */ + Lacc = DTFS_getEngy_P2A_fx( dtfs_temp_fx ); /*2Q where Q = dtfs_temp_fx->Q */ - prev_Engy = L_add(Lacc, 0); + prev_Engy = L_add( Lacc, 0 ); - hSC_VBR->Q_prev_cw_en_fx=norm_l(Lacc); /* = K = headroom */ + hSC_VBR->Q_prev_cw_en_fx = norm_l( Lacc ); /* = K = headroom */ /*hSC_VBR->Q_prev_cw_en_fx = (Lacc==0)?31: hSC_VBR->Q_prev_cw_en_fx; */ - if (Lacc==0) + if ( Lacc == 0 ) { hSC_VBR->Q_prev_cw_en_fx = 31; move16(); } - hSC_VBR->prev_cw_en_fx=(Word32) L_shl(Lacc, hSC_VBR->Q_prev_cw_en_fx); /*2Q+K */ - hSC_VBR->Q_prev_cw_en_fx = add(hSC_VBR->Q_prev_cw_en_fx,shl(dtfs_temp_fx->Q,1)); + hSC_VBR->prev_cw_en_fx = (Word32) L_shl( Lacc, hSC_VBR->Q_prev_cw_en_fx ); /*2Q+K */ + hSC_VBR->Q_prev_cw_en_fx = add( hSC_VBR->Q_prev_cw_en_fx, shl( dtfs_temp_fx->Q, 1 ) ); /* hSC_VBR->Q_prev_cw_en_fx = 2*(dtfs_temp_fx->Q) + K */ - DTFS_copy_fx(TMPDTFS_FX,*dtfs_temp_fx); /* output = TMPDTFS_FX */ + DTFS_copy_fx( TMPDTFS_FX, *dtfs_temp_fx ); /* output = TMPDTFS_FX */ - DTFS_car2pol_fx(TMPDTFS_FX); + DTFS_car2pol_fx( TMPDTFS_FX ); - logLag=log10_fx(TMPDTFS_FX->lag_fx); /* logLag=10*log10(pl), Q23 */ - Ltemp_q=L_shl(L_mult(shl(TMPDTFS_FX->Q,1),24660),9); /* Ltemp_q=2Q*10log10(2), Q23 */ + logLag = log10_fx( TMPDTFS_FX->lag_fx ); /* logLag=10*log10(pl), Q23 */ + Ltemp_q = L_shl( L_mult( shl( TMPDTFS_FX->Q, 1 ), 24660 ), 9 ); /* Ltemp_q=2Q*10log10(2), Q23 */ /* Process low band */ - Ltemp=DTFS_setEngyHarm_fx(236,2828,0,2828, 1, 0, &Ql,TMPDTFS_FX);/* Q of Ltemp = 2*(TMPDTFS_FX->Q) = Ql ? */ + Ltemp = DTFS_setEngyHarm_fx( 236, 2828, 0, 2828, 1, 0, &Ql, TMPDTFS_FX ); /* Q of Ltemp = 2*(TMPDTFS_FX->Q) = Ql ? */ /* Compensate for Q factor of energy to get log10(lag*eng) */ - Ltemp=log10_fx(Ltemp); /* Ltemp=10log10(eng), Q23 */ - Ltemp=L_add(L_sub(Ltemp,Ltemp_q),logLag); /* Ltemp=10*log10(lag*eng), Q23 */ + Ltemp = log10_fx( Ltemp ); /* Ltemp=10log10(eng), Q23 */ + Ltemp = L_add( L_sub( Ltemp, Ltemp_q ), logLag ); /* Ltemp=10*log10(lag*eng), Q23 */ /*hSC_VBR->lastLgainE_fx=round_fx(L_shl((Word32)Mpy_32_16(extract_h(Ltemp),extract_l(Ltemp),0x6666),1)); // Q11, 0x6666 = 0.1 in Q18 */ - hSC_VBR->lastLgainE_fx=round_fx(L_shl(Mult_32_16(Ltemp,0x6666),1)); /* Q11, 0x6666 = 0.1 in Q18 */ + hSC_VBR->lastLgainE_fx = round_fx( L_shl( Mult_32_16( Ltemp, 0x6666 ), 1 ) ); /* Q11, 0x6666 = 0.1 in Q18 */ /* Process high band */ - Ltemp=DTFS_setEngyHarm_fx(2828,upper_cut_off_freq_of_interest_norm_fx,2828,upper_cut_off_freq_norm_fx, 1, 0, &Qh,TMPDTFS_FX); - Ltemp=log10_fx(Ltemp); - Ltemp=L_add(L_sub(Ltemp,Ltemp_q),logLag); /* Ltemp=10*log10(lag*eng), Q23 */ - hSC_VBR->lastHgainE_fx=round_fx(L_shl(Mult_32_16(Ltemp,0x6666),1)); /* Q11 */ + Ltemp = DTFS_setEngyHarm_fx( 2828, upper_cut_off_freq_of_interest_norm_fx, 2828, upper_cut_off_freq_norm_fx, 1, 0, &Qh, TMPDTFS_FX ); + Ltemp = log10_fx( Ltemp ); + Ltemp = L_add( L_sub( Ltemp, Ltemp_q ), logLag ); /* Ltemp=10*log10(lag*eng), Q23 */ + hSC_VBR->lastHgainE_fx = round_fx( L_shl( Mult_32_16( Ltemp, 0x6666 ), 1 ) ); /* Q11 */ /* Need to unify the Q factors of both bands */ - TMPDTFS_FX->Q=s_min(Ql,Qh); - move16();/* set Q factor to be the smaller one of Ql and Qh */ - n=sub(Ql,Qh); /* compare band Q factors */ + TMPDTFS_FX->Q = s_min( Ql, Qh ); + move16(); /* set Q factor to be the smaller one of Ql and Qh */ + n = sub( Ql, Qh ); /* compare band Q factors */ - IF (n<0) + IF( n < 0 ) { - rshiftHarmBand_fx(TMPDTFS_FX,2828, upper_cut_off_freq_norm_fx,n); + rshiftHarmBand_fx( TMPDTFS_FX, 2828, upper_cut_off_freq_norm_fx, n ); } - ELSE IF (n>0) + ELSE IF( n > 0 ) { - rshiftHarmBand_fx(TMPDTFS_FX,0, 2828, sub(Qh,Ql)); + rshiftHarmBand_fx( TMPDTFS_FX, 0, 2828, sub( Qh, Ql ) ); } - DTFS_to_erb_fx(*TMPDTFS_FX, hSC_VBR->lasterbE_fx); /* output lasterbE_fx in Q13 */ - Lacc1 = L_max(prev_Engy, 1); + DTFS_to_erb_fx( *TMPDTFS_FX, hSC_VBR->lasterbE_fx ); /* output lasterbE_fx in Q13 */ + Lacc1 = L_max( prev_Engy, 1 ); } ELSE { @@ -392,13 +391,13 @@ ivas_error ppp_voiced_encoder_fx( dtfs_temp_fx->upper_cut_off_freq_fx = hSC_VBR->dtfs_enc_upper_cut_off_freq_fx; move16(); - Copy(hSC_VBR->dtfs_enc_a_fx, dtfs_temp_fx->a_fx, MAXLAG_WI); - Copy(hSC_VBR->dtfs_enc_b_fx, dtfs_temp_fx->b_fx, MAXLAG_WI); + Copy( hSC_VBR->dtfs_enc_a_fx, dtfs_temp_fx->a_fx, MAXLAG_WI ); + Copy( hSC_VBR->dtfs_enc_b_fx, dtfs_temp_fx->b_fx, MAXLAG_WI ); dtfs_temp_fx->Q = hSC_VBR->dtfs_enc_Q; move16(); - Lacc1=DTFS_getEngy_P2A_fx(dtfs_temp_fx); - prev_Engy = L_add(Lacc1, 0); + Lacc1 = DTFS_getEngy_P2A_fx( dtfs_temp_fx ); + prev_Engy = L_add( Lacc1, 0 ); } /*-----Open-loop Bump-Up-------- */ @@ -408,76 +407,75 @@ ivas_error ppp_voiced_encoder_fx( /* current prototype */ /* res_enratio = DTFS_getEngy(*CURRP_NQ) / DTFS_getEngy(*dtfs_temp); */ - Lacc = L_add(curr_Engy, 0); + Lacc = L_add( curr_Engy, 0 ); /* Lacc1 has been handled above */ - sft=add(shl(sub(CURRP_NQ_FX->Q,dtfs_temp_fx->Q),1),4); - IF (sft>0) + sft = add( shl( sub( CURRP_NQ_FX->Q, dtfs_temp_fx->Q ), 1 ), 4 ); + IF( sft > 0 ) { - if (LT_32(Lacc1,L_shr(Lacc,sft))) + if ( LT_32( Lacc1, L_shr( Lacc, sft ) ) ) { - res_enratio_fx=0x7FFF; + res_enratio_fx = 0x7FFF; move16(); } } ELSE { - if (LT_32(L_shr(Lacc1,negate(sft)),Lacc)) + if ( LT_32( L_shr( Lacc1, negate( sft ) ), Lacc ) ) { - res_enratio_fx=0x7FFF; + res_enratio_fx = 0x7FFF; move16(); } } /* max value res_enratio compared against is 0x7400 (14.5 in Q11) */ - IF (NE_32(res_enratio_fx,0x7FFF)) + IF( NE_32( res_enratio_fx, 0x7FFF ) ) { - expb = norm_l(Lacc); - fracb = extract_h(L_shl(Lacc,expb)); - expb = sub(30,add(expb, shl(CURRP_NQ_FX->Q, 1))); + expb = norm_l( Lacc ); + fracb = extract_h( L_shl( Lacc, expb ) ); + expb = sub( 30, add( expb, shl( CURRP_NQ_FX->Q, 1 ) ) ); - expa = norm_l(Lacc1); - fraca = extract_h(L_shl(Lacc1,expa)); - expa = sub(30, add(expa, shl(dtfs_temp_fx->Q, 1))); + expa = norm_l( Lacc1 ); + fraca = extract_h( L_shl( Lacc1, expa ) ); + expa = sub( 30, add( expa, shl( dtfs_temp_fx->Q, 1 ) ) ); - scale = shr(sub(fraca,fracb),15); - fracb = shl(fracb,scale); - expb = sub(expb,scale); + scale = shr( sub( fraca, fracb ), 15 ); + fracb = shl( fracb, scale ); + expb = sub( expb, scale ); - tmp = div_s(fracb,fraca); - exp = sub(expb,expa); - res_enratio_fx = shl(tmp,sub(exp,4)); + tmp = div_s( fracb, fraca ); + exp = sub( expb, expa ); + res_enratio_fx = shl( tmp, sub( exp, 4 ) ); } /* res_enratio_fx is Q11 */ /* Copy over CURRP_NQ into TMPDTFS */ - DTFS_copy_fx(TMPDTFS_FX, *CURRP_NQ_FX); /* output = TMPDTFS_FX with Q = CURRP_NQ_FX->Q */ + DTFS_copy_fx( TMPDTFS_FX, *CURRP_NQ_FX ); /* output = TMPDTFS_FX with Q = CURRP_NQ_FX->Q */ /* Copy over dtfs_temp into TMPDTFS2 */ - DTFS_copy_fx(TMPDTFS2_FX, *dtfs_temp_fx); /* output = TMPDTFS2_FX with Q = dtfs_temp_fx->Q */ + DTFS_copy_fx( TMPDTFS2_FX, *dtfs_temp_fx ); /* output = TMPDTFS2_FX with Q = dtfs_temp_fx->Q */ - tmptmp = DTFS_alignment_full_fx(*TMPDTFS2_FX,*TMPDTFS_FX, hSC_VBR->ph_offset_E_fx,S_fx,C_fx, 0); + tmptmp = DTFS_alignment_full_fx( *TMPDTFS2_FX, *TMPDTFS_FX, hSC_VBR->ph_offset_E_fx, S_fx, C_fx, 0 ); - tmptmp1 = sub(shl(TMPDTFS_FX->lag_fx,1), tmptmp);/* (C_l-tmptmp) , Q1 */ + tmptmp1 = sub( shl( TMPDTFS_FX->lag_fx, 1 ), tmptmp ); /* (C_l-tmptmp) , Q1 */ - Q2phaseShift_fx(TMPDTFS_FX, negate(shl(tmptmp1,1)), TMPDTFS_FX->lag_fx,S_fx,C_fx); /* fixed bug , phase shift by tmp computed in_fx TMP.lag domain (above) */ + Q2phaseShift_fx( TMPDTFS_FX, negate( shl( tmptmp1, 1 ) ), TMPDTFS_FX->lag_fx, S_fx, C_fx ); /* fixed bug , phase shift by tmp computed in_fx TMP.lag domain (above) */ /*tmpres = (float)(DTFS_freq_corr(*TMPDTFS, *TMPDTFS2, 100.0f, 3700.0f));*/ - tmpres_fx = DTFS_freq_corr_fx(*TMPDTFS_FX, *TMPDTFS2_FX, 100, 3700, &Qtmpres); /* tmpres_fx has Q factor tmpres */ + tmpres_fx = DTFS_freq_corr_fx( *TMPDTFS_FX, *TMPDTFS2_FX, 100, 3700, &Qtmpres ); /* tmpres_fx has Q factor tmpres */ - - poleFilter_setup_fx(lpc2_fx, M+1, *TMPDTFS_FX, S_fx, C_fx, pf_temp1, pf_temp2, pf_temp, pf_n2); - DTFS_poleFilter_fx_9(TMPDTFS_FX, pf_temp1, pf_temp2, pf_temp, pf_n2); + poleFilter_setup_fx( lpc2_fx, M + 1, *TMPDTFS_FX, S_fx, C_fx, pf_temp1, pf_temp2, pf_temp, pf_n2 ); + DTFS_poleFilter_fx_9( TMPDTFS_FX, pf_temp1, pf_temp2, pf_temp, pf_n2 ); /* lpc2_fx in Q12 */ - DTFS_adjustLag_fx(TMPDTFS2_FX, TMPDTFS_FX->lag_fx); /* operate in_fx CL domain */ + DTFS_adjustLag_fx( TMPDTFS2_FX, TMPDTFS_FX->lag_fx ); /* operate in_fx CL domain */ - DTFS_poleFilter_fx(TMPDTFS2_FX,lpc1_fx,M+1, S_fx, C_fx); /* lpc1_fx in Q12 */ + DTFS_poleFilter_fx( TMPDTFS2_FX, lpc1_fx, M + 1, S_fx, C_fx ); /* lpc1_fx in Q12 */ - tmp_fx = DTFS_freq_corr_fx(*TMPDTFS_FX, *TMPDTFS2_FX, 100, 3700, &Qtmp); + tmp_fx = DTFS_freq_corr_fx( *TMPDTFS_FX, *TMPDTFS2_FX, 100, 3700, &Qtmp ); /* tmp_fx Q = Qtmp */ @@ -491,71 +489,71 @@ ivas_error ppp_voiced_encoder_fx( sp_enratio = 0.0f; } *******************************************************************************/ - Ltmp_32 = (DTFS_getEngy_fx(TMPDTFS2_FX)); /* Output Q=2*(TMPDTFS2_FX->Q) */ - IF ( Ltmp_32 > 0 ) + Ltmp_32 = ( DTFS_getEngy_fx( TMPDTFS2_FX ) ); /* Output Q=2*(TMPDTFS2_FX->Q) */ + IF( Ltmp_32 > 0 ) { /*sp_enratio = DTFS_getEngy(*TMPDTFS)/DTFS_getEngy(*TMPDTFS2); in Q15 */ - Lacc=DTFS_getEngy_P2A_fx(TMPDTFS_FX); - Lacc1=Ltmp_32; + Lacc = DTFS_getEngy_P2A_fx( TMPDTFS_FX ); + Lacc1 = Ltmp_32; /* IF (L_sub(sp_enratio_fx,0x7FFF)!=0) */ { - expb = norm_l(Lacc); - fracb = extract_h(L_shl(Lacc,expb)); + expb = norm_l( Lacc ); + fracb = extract_h( L_shl( Lacc, expb ) ); - expb = sub(30, add(expb, shl(TMPDTFS_FX->Q, 1))); + expb = sub( 30, add( expb, shl( TMPDTFS_FX->Q, 1 ) ) ); - expa = norm_l(Lacc1); - fraca = extract_h(L_shl(Lacc1,expa)); + expa = norm_l( Lacc1 ); + fraca = extract_h( L_shl( Lacc1, expa ) ); - expa = sub(30, add(expa, shl(TMPDTFS2_FX->Q, 1))); + expa = sub( 30, add( expa, shl( TMPDTFS2_FX->Q, 1 ) ) ); - scale = shr(sub(fraca,fracb),15); - fracb = shl(fracb,scale); - expb = sub(expb,scale); + scale = shr( sub( fraca, fracb ), 15 ); + fracb = shl( fracb, scale ); + expb = sub( expb, scale ); - tmp = div_s(fracb,fraca); - exp = sub(expb,expa); + tmp = div_s( fracb, fraca ); + exp = sub( expb, expa ); #ifdef BASOP_NOGLOB sp_enratio_fx = L_shl_sat( tmp, exp ); /* Q15 */ #else - sp_enratio_fx = L_shl(tmp, exp); /* Q15 */ + sp_enratio_fx = L_shl( tmp, exp ); /* Q15 */ #endif } } ELSE { - sp_enratio_fx = L_deposit_l(0);/* Q15 */ + sp_enratio_fx = L_deposit_l( 0 ); /* Q15 */ } /*******************************************************************************/ - IF (EQ_16(PPP_MODE_E,'Q')) + IF( EQ_16( PPP_MODE_E, 'Q' ) ) { /* Bump up if the lag is out_fx of range */ test(); - IF (GT_16(sub(l,pl),13)||LT_16(sub(l,pl),-11)) + IF( GT_16( sub( l, pl ), 13 ) || LT_16( sub( l, pl ), -11 ) ) { - PPP_MODE_E = 'B' ; + PPP_MODE_E = 'B'; move16(); } ELSE { - delta_lag_E= sub(l,pl); + delta_lag_E = sub( l, pl ); } /* Bump up if big change between the previous and the current CWs */ #ifdef BASOP_NOGLOB - IF ( LT_16(shl_o(hSC_VBR->vadsnr_fx,1, &Overflow) ,hSC_VBR->SNR_THLD_fx)) /*Q8 */ + IF( LT_16( shl_o( hSC_VBR->vadsnr_fx, 1, &Overflow ), hSC_VBR->SNR_THLD_fx ) ) /*Q8 */ #else - IF ( LT_16(shl(hSC_VBR->vadsnr_fx,1) ,hSC_VBR->SNR_THLD_fx)) /*Q8 */ + IF( LT_16( shl( hSC_VBR->vadsnr_fx, 1 ), hSC_VBR->SNR_THLD_fx ) ) /*Q8 */ #endif { /*if ( res_enratio > 5.0 && tmp < 0.65 ) */ /* 5 in Q11, 0.65 in Q15 // L_shl(tmp_fx,sub(31,Qtmp)) makes tmp_fx FIXED Q31 */ test(); #ifdef BASOP_NOGLOB - IF ((GT_32(res_enratio_fx,10240))&&(LT_16(extract_h(L_shl_o(tmp_fx,sub(31,Qtmp), &Overflow)),21299))) + IF( ( GT_32( res_enratio_fx, 10240 ) ) && ( LT_16( extract_h( L_shl_o( tmp_fx, sub( 31, Qtmp ), &Overflow ) ), 21299 ) ) ) #else - IF ((GT_32(res_enratio_fx,10240))&&(LT_16(extract_h(L_shl(tmp_fx,sub(31,Qtmp))),21299))) + IF( ( GT_32( res_enratio_fx, 10240 ) ) && ( LT_16( extract_h( L_shl( tmp_fx, sub( 31, Qtmp ) ) ), 21299 ) ) ) #endif { PPP_MODE_E = 'B'; @@ -568,9 +566,9 @@ ivas_error ppp_voiced_encoder_fx( /*3 in Q11, 1.2 in Q14 // L_shl(tmp_fx,sub(31,Qtmp)) makes tmp_fx FIXED Q14 */ test(); #ifdef BASOP_NOGLOB - IF ( (GT_32(res_enratio_fx,6144))&&(LT_16(extract_h(L_shl_o(tmp_fx,sub(30,Qtmp), &Overflow)),19661))) + IF( ( GT_32( res_enratio_fx, 6144 ) ) && ( LT_16( extract_h( L_shl_o( tmp_fx, sub( 30, Qtmp ), &Overflow ) ), 19661 ) ) ) #else - IF ( (GT_32(res_enratio_fx,6144))&&(LT_16(extract_h(L_shl(tmp_fx,sub(30,Qtmp))),19661))) + IF( ( GT_32( res_enratio_fx, 6144 ) ) && ( LT_16( extract_h( L_shl( tmp_fx, sub( 30, Qtmp ) ) ), 19661 ) ) ) #endif { PPP_MODE_E = 'B'; @@ -583,26 +581,26 @@ ivas_error ppp_voiced_encoder_fx( /* Not a suitable PPP frame -> Bump to CELP */ #ifdef BASOP_NOGLOB - IF ( LT_16(shl_o(hSC_VBR->vadsnr_fx,1, &Overflow) ,hSC_VBR->SNR_THLD_fx)) /*Q8 */ + IF( LT_16( shl_o( hSC_VBR->vadsnr_fx, 1, &Overflow ), hSC_VBR->SNR_THLD_fx ) ) /*Q8 */ #else - IF ( LT_16(shl(hSC_VBR->vadsnr_fx,1) ,hSC_VBR->SNR_THLD_fx)) /*Q8 */ + IF( LT_16( shl( hSC_VBR->vadsnr_fx, 1 ), hSC_VBR->SNR_THLD_fx ) ) /*Q8 */ #endif { /* if (res_enratio < 0.025) */ #ifdef BASOP_NOGLOB - IF (LT_32(L_shl_o(res_enratio_fx,4, &Overflow),819)) /*0x0333 = 0.025 in Q15, res_enratio_fx in Q15 after shl 4 */ + IF( LT_32( L_shl_o( res_enratio_fx, 4, &Overflow ), 819 ) ) /*0x0333 = 0.025 in Q15, res_enratio_fx in Q15 after shl 4 */ #else - IF (LT_32(L_shl(res_enratio_fx,4),819)) /*0x0333 = 0.025 in Q15, res_enratio_fx in Q15 after shl 4 */ + IF( LT_32( L_shl( res_enratio_fx, 4 ), 819 ) ) /*0x0333 = 0.025 in Q15, res_enratio_fx in Q15 after shl 4 */ #endif { hSC_VBR->bump_up = 1; move16(); - count_free(CURRP_NQ_FX); - count_free(TMPDTFS_FX); - count_free(TMPDTFS2_FX); - count_free(TMPDTFS3_FX); - count_free(CURRP_Q_E_FX); - count_free(dtfs_temp_fx); + count_free( CURRP_NQ_FX ); + count_free( TMPDTFS_FX ); + count_free( TMPDTFS2_FX ); + count_free( TMPDTFS3_FX ); + count_free( CURRP_Q_E_FX ); + count_free( dtfs_temp_fx ); return error; } } @@ -610,9 +608,9 @@ ivas_error ppp_voiced_encoder_fx( { /* if ( res_enratio < 0.092f) */ #ifdef BASOP_NOGLOB - if ( LT_32(L_shl_o(res_enratio_fx,4, &Overflow), 3015))/*3015 = 0.092 in Q15, res_enratio_fx in Q15 after shl 4 */ + if ( LT_32( L_shl_o( res_enratio_fx, 4, &Overflow ), 3015 ) ) /*3015 = 0.092 in Q15, res_enratio_fx in Q15 after shl 4 */ #else - if ( LT_32(L_shl(res_enratio_fx,4), 3015))/*3015 = 0.092 in Q15, res_enratio_fx in Q15 after shl 4 */ + if ( LT_32( L_shl( res_enratio_fx, 4 ), 3015 ) ) /*3015 = 0.092 in Q15, res_enratio_fx in Q15 after shl 4 */ #endif { hSC_VBR->bump_up = 1; @@ -623,9 +621,9 @@ ivas_error ppp_voiced_encoder_fx( /* if (min(res_enratio, sp_enratio) < 0.075 && tmp < -0.5f)) : 2458 = 0.075 in Q15 */ test(); #ifdef BASOP_NOGLOB - if ( LT_32(L_min(L_shl_o(res_enratio_fx,4, &Overflow), sp_enratio_fx), 2458)&<_32(tmp_fx,shl_o(-1,sub(Qtmp,1), &Overflow))) + if ( LT_32( L_min( L_shl_o( res_enratio_fx, 4, &Overflow ), sp_enratio_fx ), 2458 ) && LT_32( tmp_fx, shl_o( -1, sub( Qtmp, 1 ), &Overflow ) ) ) #else - if ( LT_32(L_min(L_shl(res_enratio_fx,4), sp_enratio_fx), 2458)&<_32(tmp_fx,shl(-1,sub(Qtmp,1)))) + if ( LT_32( L_min( L_shl( res_enratio_fx, 4 ), sp_enratio_fx ), 2458 ) && LT_32( tmp_fx, shl( -1, sub( Qtmp, 1 ) ) ) ) #endif { hSC_VBR->bump_up = 1; @@ -635,90 +633,90 @@ ivas_error ppp_voiced_encoder_fx( /* Rapid rampup frame where time resolution is important */ /* Not a suitable PPP frame -> Bump to CELP */ #ifdef BASOP_NOGLOB - IF ( LT_16(shl_o(hSC_VBR->vadsnr_fx,1, &Overflow) ,hSC_VBR->SNR_THLD_fx)) /*Q8 */ + IF( LT_16( shl_o( hSC_VBR->vadsnr_fx, 1, &Overflow ), hSC_VBR->SNR_THLD_fx ) ) /*Q8 */ #else - IF ( LT_16(shl(hSC_VBR->vadsnr_fx,1) ,hSC_VBR->SNR_THLD_fx)) /*Q8 */ + IF( LT_16( shl( hSC_VBR->vadsnr_fx, 1 ), hSC_VBR->SNR_THLD_fx ) ) /*Q8 */ #endif { - IF (GT_32(res_enratio_fx,29696)) /*14.5 in Q11 */ + IF( GT_32( res_enratio_fx, 29696 ) ) /*14.5 in Q11 */ { hSC_VBR->bump_up = 1; move16(); - count_free(CURRP_NQ_FX); - count_free(TMPDTFS_FX); - count_free(TMPDTFS2_FX); - count_free(TMPDTFS3_FX); - count_free(CURRP_Q_E_FX); - count_free(dtfs_temp_fx); + count_free( CURRP_NQ_FX ); + count_free( TMPDTFS_FX ); + count_free( TMPDTFS2_FX ); + count_free( TMPDTFS3_FX ); + count_free( CURRP_Q_E_FX ); + count_free( dtfs_temp_fx ); return error; } } ELSE { - if (GT_32(res_enratio_fx,14336)) /* 7.0 in Q11 */ + if ( GT_32( res_enratio_fx, 14336 ) ) /* 7.0 in Q11 */ { hSC_VBR->bump_up = 1; move16(); } } - IF ( hSC_VBR->bump_up == 1 ) + IF( hSC_VBR->bump_up == 1 ) { - count_free(CURRP_NQ_FX); - count_free(TMPDTFS_FX); - count_free(TMPDTFS2_FX); - count_free(TMPDTFS3_FX); - count_free(CURRP_Q_E_FX); - count_free(dtfs_temp_fx); + count_free( CURRP_NQ_FX ); + count_free( TMPDTFS_FX ); + count_free( TMPDTFS2_FX ); + count_free( TMPDTFS3_FX ); + count_free( CURRP_Q_E_FX ); + count_free( dtfs_temp_fx ); return error; } /* Bump up when the previous frame is an unvoiced or a silent frame */ - IF (EQ_16(last_coder_type_raw,UNVOICED)) + IF( EQ_16( last_coder_type_raw, UNVOICED ) ) { hSC_VBR->bump_up = 1; move16(); - count_free(CURRP_NQ_FX); - count_free(TMPDTFS_FX); - count_free(TMPDTFS2_FX); - count_free(TMPDTFS3_FX); - count_free(CURRP_Q_E_FX); - count_free(dtfs_temp_fx); + count_free( CURRP_NQ_FX ); + count_free( TMPDTFS_FX ); + count_free( TMPDTFS2_FX ); + count_free( TMPDTFS3_FX ); + count_free( CURRP_Q_E_FX ); + count_free( dtfs_temp_fx ); return error; } /* -----End Open-loop Bump-Up */ /* PPP-WI Quantization */ - IF (EQ_16(PPP_MODE_E,'Q')) + IF( EQ_16( PPP_MODE_E, 'Q' ) ) { flag = 1; move16(); - IF (EQ_16(PPP_MODE_E,'Q')) + IF( EQ_16( PPP_MODE_E, 'Q' ) ) { - if ((error = ppp_quarter_encoder_fx(&flag, CURRP_Q_E_FX, TMPDTFS_FX, dtfs_temp_fx->lag_fx, *CURRP_NQ_FX, lpc2_fx, &hSC_VBR->lastLgainE_fx, &hSC_VBR->lastHgainE_fx, hSC_VBR->lasterbE_fx, *dtfs_temp_fx, S_fx, C_fx, hBstr)) != IVAS_ERR_OK) + if ( ( error = ppp_quarter_encoder_fx( &flag, CURRP_Q_E_FX, TMPDTFS_FX, dtfs_temp_fx->lag_fx, *CURRP_NQ_FX, lpc2_fx, &hSC_VBR->lastLgainE_fx, &hSC_VBR->lastHgainE_fx, hSC_VBR->lasterbE_fx, *dtfs_temp_fx, S_fx, C_fx, hBstr ) ) != IVAS_ERR_OK ) { - count_free(CURRP_NQ_FX); - count_free(TMPDTFS_FX); - count_free(TMPDTFS2_FX); - count_free(TMPDTFS3_FX); - count_free(CURRP_Q_E_FX); - count_free(dtfs_temp_fx); + count_free( CURRP_NQ_FX ); + count_free( TMPDTFS_FX ); + count_free( TMPDTFS2_FX ); + count_free( TMPDTFS3_FX ); + count_free( CURRP_Q_E_FX ); + count_free( dtfs_temp_fx ); return error; } } - IF (flag) + IF( flag ) { /* TMPDTFS : Target prototype: Amp Quantized + Phase Unquantized */ /* TMPDTFS2: Quantized prototype: Amp Quantized + Phase Quantized */ /* TMPDTFS3: Delta prototype: Diff betw. target and quant. in_fx speech dom */ /* ----- Closed-loop Bump-Up ---------- */ - Word32 pos_nq_fx, neg_nq_fx,pos_q_fx,neg_q_fx; - Word16 Qposnq, Qnegnq, Qposq,Qnegq; + Word32 pos_nq_fx, neg_nq_fx, pos_q_fx, neg_q_fx; + Word16 Qposnq, Qnegnq, Qposq, Qnegq; - DTFS_peaktoaverage_fx(*TMPDTFS_FX,&pos_nq_fx,&Qposnq,&neg_nq_fx,&Qnegnq); - DTFS_peaktoaverage_fx(*CURRP_Q_E_FX, &pos_q_fx, &Qposq,&neg_q_fx,&Qnegq); + DTFS_peaktoaverage_fx( *TMPDTFS_FX, &pos_nq_fx, &Qposnq, &neg_nq_fx, &Qnegnq ); + DTFS_peaktoaverage_fx( *CURRP_Q_E_FX, &pos_q_fx, &Qposq, &neg_q_fx, &Qnegq ); /* Before we perform the peak-to-average ratio comparison, we have to */ @@ -728,96 +726,96 @@ ivas_error ppp_voiced_encoder_fx( /* Usually triggers in the slow ramp down frames. Does not fall under the test condition (res_enratio < 0.025) as both frames have little energy and the ratio is not very small. Not suitable for PPP */ - IF ( GT_16(CURRP_Q_E_FX->upper_cut_off_freq_fx , 4000)) + IF( GT_16( CURRP_Q_E_FX->upper_cut_off_freq_fx, 4000 ) ) { - Ltemp2 = DTFS_getEngy_band_wb_fx(*CURRP_Q_E_FX, 0, 2000); + Ltemp2 = DTFS_getEngy_band_wb_fx( *CURRP_Q_E_FX, 0, 2000 ); /* Use this bump-up only for WB signals */ - IF ( Ltemp2 > 0 ) + IF( Ltemp2 > 0 ) { /* sp_hb_enratio = DTFS_getEngy_band_wb(*CURRP_Q_E, 2000.0, 6400.0)/DTFS_getEngy_band_wb(*CURRP_Q_E, 0.0, 2000.0); */ - Ltemp1 = DTFS_getEngy_band_wb_fx(*CURRP_Q_E_FX, 2000, 6400);/*Q13 */ + Ltemp1 = DTFS_getEngy_band_wb_fx( *CURRP_Q_E_FX, 2000, 6400 ); /*Q13 */ /*sp_hb_enratio_fx = divide_dp(Ltemp1,Ltemp2,0, 1);//Q29 */ Qadj = 0; move16(); /*----------------------------------------------------------*/ /* Ltemp_fx = (Word32)divide_dp(Ltemp1, Ltemp2, Qadj,1); Q29*/ /*----------------------------------------------------------*/ - if(Ltemp1<0) + if ( Ltemp1 < 0 ) { - Ltemp1 = L_negate(Ltemp1); + Ltemp1 = L_negate( Ltemp1 ); } - expa = norm_l(Ltemp2); + expa = norm_l( Ltemp2 ); #ifdef BASOP_NOGLOB - fraca = extract_h(L_shl_o(Ltemp2,expa, &Overflow)); + fraca = extract_h( L_shl_o( Ltemp2, expa, &Overflow ) ); #else - fraca = extract_h(L_shl(Ltemp2,expa)); + fraca = extract_h( L_shl( Ltemp2, expa ) ); #endif - expa = sub(30,expa); + expa = sub( 30, expa ); - expb = norm_l(Ltemp1); - fracb = round_fx(L_shl(Ltemp1,expb)); - expb = sub(30, add(expb, Qadj)); + expb = norm_l( Ltemp1 ); + fracb = round_fx( L_shl( Ltemp1, expb ) ); + expb = sub( 30, add( expb, Qadj ) ); - scale = shr(sub(fraca,fracb),15); + scale = shr( sub( fraca, fracb ), 15 ); #ifdef BASOP_NOGLOB - fracb = shl_o(fracb,scale, &Overflow); + fracb = shl_o( fracb, scale, &Overflow ); #else - fracb = shl(fracb,scale); + fracb = shl( fracb, scale ); #endif - expb = sub(expb,scale); + expb = sub( expb, scale ); - tmp = div_s(fracb,fraca); - exp = sub(expb,expa); + tmp = div_s( fracb, fraca ); + exp = sub( expb, expa ); #ifdef BASOP_NOGLOB - Ltemp_fx = L_shl_o(tmp, add(exp,14), &Overflow); + Ltemp_fx = L_shl_o( tmp, add( exp, 14 ), &Overflow ); #else - Ltemp_fx = L_shl(tmp, add(exp,14)); + Ltemp_fx = L_shl( tmp, add( exp, 14 ) ); #endif /*-------------------------------------------*/ - sp_hb_enratio_fx = L_add(Ltemp_fx, 0); /* Q29 */ + sp_hb_enratio_fx = L_add( Ltemp_fx, 0 ); /* Q29 */ } ELSE { - sp_hb_enratio_fx = L_deposit_l(0); + sp_hb_enratio_fx = L_deposit_l( 0 ); } low_band_en_fx = Ltemp2; /*Q13 */ /* if ( low_band_en < 25.0f && sp_hb_enratio < 1.6f ) */ /* 25.0 in Q13 = 204800, 1.6 in Q29 = 858993459 */ test(); - IF ( LT_32(low_band_en_fx , 204800 )&<_32(sp_hb_enratio_fx,858993459)) + IF( LT_32( low_band_en_fx, 204800 ) && LT_32( sp_hb_enratio_fx, 858993459 ) ) { PPP_MODE_E = 'B'; move16(); } } - Ltmp_32=DTFS_getEngy_fx(CURRP_NQ_FX); /*Q = 2*(CURRP_NQ_FX->Q) */ - Qadj = sub(hSC_VBR->Q_prev_cw_en_fx, shl(CURRP_NQ_FX->Q, 1)); + Ltmp_32 = DTFS_getEngy_fx( CURRP_NQ_FX ); /*Q = 2*(CURRP_NQ_FX->Q) */ + Qadj = sub( hSC_VBR->Q_prev_cw_en_fx, shl( CURRP_NQ_FX->Q, 1 ) ); #ifdef BASOP_NOGLOB - Ltmp_32 = L_shl_o(Ltmp_32,Qadj, &Overflow); /* shift left required to adjust Q of CURRP_NQ_FX = Q_prev_cw_en_fx */ + Ltmp_32 = L_shl_o( Ltmp_32, Qadj, &Overflow ); /* shift left required to adjust Q of CURRP_NQ_FX = Q_prev_cw_en_fx */ #else - Ltmp_32 = L_shl(Ltmp_32,Qadj); /* shift left required to adjust Q of CURRP_NQ_FX = Q_prev_cw_en_fx */ + Ltmp_32 = L_shl( Ltmp_32, Qadj ); /* shift left required to adjust Q of CURRP_NQ_FX = Q_prev_cw_en_fx */ #endif /* Ltmp1_32 = 0.8f * st->prev_cw_en */ - Ltmp1_32 = Mult_32_16(hSC_VBR->prev_cw_en_fx,26214); /* Q = (Q_prev_cw_en_fx + Q15+1)-Q16 = Q_prev_cw_en_fx */ + Ltmp1_32 = Mult_32_16( hSC_VBR->prev_cw_en_fx, 26214 ); /* Q = (Q_prev_cw_en_fx + Q15+1)-Q16 = Q_prev_cw_en_fx */ #ifdef BASOP_NOGLOB - IF ( LT_16(shl_o(hSC_VBR->vadsnr_fx,1, &Overflow) ,hSC_VBR->SNR_THLD_fx)) /*Q8 */ + IF( LT_16( shl_o( hSC_VBR->vadsnr_fx, 1, &Overflow ), hSC_VBR->SNR_THLD_fx ) ) /*Q8 */ #else - IF ( LT_16(shl(hSC_VBR->vadsnr_fx,1) ,hSC_VBR->SNR_THLD_fx)) /*Q8 */ + IF( LT_16( shl( hSC_VBR->vadsnr_fx, 1 ), hSC_VBR->SNR_THLD_fx ) ) /*Q8 */ #endif { /* if ( DTFS_getEngy(*CURRP_NQ) > 0.8f * st->prev_cw_en && max(pos_nq, neg_nq) > 3.0f && st->rate_control ) */ /* pos_nq_fx and neg_nq_fx in Q28 ???? */ test(); test(); - IF ( GT_32( Ltmp_32, Ltmp1_32)&>_32(L_max(pos_nq_fx,neg_nq_fx),805306368)&&hSC_VBR->rate_control) + IF( GT_32( Ltmp_32, Ltmp1_32 ) && GT_32( L_max( pos_nq_fx, neg_nq_fx ), 805306368 ) && hSC_VBR->rate_control ) { /*if ( pos_nq > neg_nq && pos_nq > 2.0f * pos_q ) */ test(); - IF ( GT_32(pos_nq_fx , neg_nq_fx)&>_32(Mult_32_16(pos_nq_fx,16384),pos_q_fx)) + IF( GT_32( pos_nq_fx, neg_nq_fx ) && GT_32( Mult_32_16( pos_nq_fx, 16384 ), pos_q_fx ) ) { PPP_MODE_E = 'B'; move16(); @@ -825,7 +823,7 @@ ivas_error ppp_voiced_encoder_fx( test(); /*if ( pos_nq < neg_nq && neg_nq > 2.0f * neg_q ) */ - IF ( LT_32(pos_nq_fx , neg_nq_fx)&>_32(Mult_32_16(neg_nq_fx,16384),neg_q_fx)) + IF( LT_32( pos_nq_fx, neg_nq_fx ) && GT_32( Mult_32_16( neg_nq_fx, 16384 ), neg_q_fx ) ) { PPP_MODE_E = 'B'; move16(); @@ -842,8 +840,8 @@ ivas_error ppp_voiced_encoder_fx( test(); test(); test(); - IF ((((L_sub(Ltmp_32 ,(hSC_VBR->prev_cw_en_fx)>0))&&(GT_32(L_max(pos_nq_fx,neg_nq_fx),939524096)))&&(hSC_VBR->rate_control))|| - (((GT_32( Ltmp_32, Ltmp1_32) ) && (GT_32(L_max(pos_nq_fx,neg_nq_fx),805306368)))&&(!hSC_VBR->rate_control))) + IF( ( ( ( L_sub( Ltmp_32, ( hSC_VBR->prev_cw_en_fx ) > 0 ) ) && ( GT_32( L_max( pos_nq_fx, neg_nq_fx ), 939524096 ) ) ) && ( hSC_VBR->rate_control ) ) || + ( ( ( GT_32( Ltmp_32, Ltmp1_32 ) ) && ( GT_32( L_max( pos_nq_fx, neg_nq_fx ), 805306368 ) ) ) && ( !hSC_VBR->rate_control ) ) ) { /* if (((pos_nq > neg_nq) && (pos_nq > 2.5*pos_q)&&(st->rate_control))|| ((pos_nq > neg_nq) && (pos_nq > 2.0*pos_q)&&(!st->rate_control))) */ @@ -852,10 +850,10 @@ ivas_error ppp_voiced_encoder_fx( test(); test(); test(); - IF ((GT_32(pos_nq_fx , neg_nq_fx)&>_32(Mult_32_16(pos_nq_fx,13107),pos_q_fx)&&(hSC_VBR->rate_control))|| - (GT_32(pos_nq_fx , neg_nq_fx) && GT_32(Mult_32_16(pos_nq_fx,16384),pos_q_fx) && (!hSC_VBR->rate_control))) + IF( ( GT_32( pos_nq_fx, neg_nq_fx ) && GT_32( Mult_32_16( pos_nq_fx, 13107 ), pos_q_fx ) && ( hSC_VBR->rate_control ) ) || + ( GT_32( pos_nq_fx, neg_nq_fx ) && GT_32( Mult_32_16( pos_nq_fx, 16384 ), pos_q_fx ) && ( !hSC_VBR->rate_control ) ) ) { - PPP_MODE_E='B'; + PPP_MODE_E = 'B'; move16(); } @@ -866,203 +864,191 @@ ivas_error ppp_voiced_encoder_fx( test(); test(); test(); - IF ((LT_32(pos_nq_fx , neg_nq_fx)&>_32(Mult_32_16(neg_nq_fx,13107),neg_q_fx)&&(hSC_VBR->rate_control))|| - (LT_32(pos_nq_fx , neg_nq_fx) && GT_32(Mult_32_16(neg_nq_fx,16384),neg_q_fx) && (!hSC_VBR->rate_control))) + IF( ( LT_32( pos_nq_fx, neg_nq_fx ) && GT_32( Mult_32_16( neg_nq_fx, 13107 ), neg_q_fx ) && ( hSC_VBR->rate_control ) ) || + ( LT_32( pos_nq_fx, neg_nq_fx ) && GT_32( Mult_32_16( neg_nq_fx, 16384 ), neg_q_fx ) && ( !hSC_VBR->rate_control ) ) ) { - PPP_MODE_E='B'; + PPP_MODE_E = 'B'; move16(); } } - IF ( hSC_VBR->rate_control ) + IF( hSC_VBR->rate_control ) { - DTFS_peaktoaverage_fx(*CURRP_NQ_FX,&pos_nq0_fx,&Qposnq,&neg_nq0_fx,&Qnegnq); + DTFS_peaktoaverage_fx( *CURRP_NQ_FX, &pos_nq0_fx, &Qposnq, &neg_nq0_fx, &Qnegnq ); - impzi_fx[0]=1; + impzi_fx[0] = 1; move16(); - FOR (x_fx=1; x_fx<160; x_fx++) + FOR( x_fx = 1; x_fx < 160; x_fx++ ) { - impzi_fx[x_fx]=0; + impzi_fx[x_fx] = 0; move16(); } - FOR (x_fx=0; x_fx<160; x_fx++) + FOR( x_fx = 0; x_fx < 160; x_fx++ ) { - impzo_fx[x_fx]=0; + impzo_fx[x_fx] = 0; move16(); } - FOR (x_fx=0; x_fx<10; x_fx++) + FOR( x_fx = 0; x_fx < 10; x_fx++ ) { - mem_fx[x_fx]=0; + mem_fx[x_fx] = 0; move16(); } /* lpc2_fx in Q12, so Qadj is set to 3 toi bring it to Q15 */ - Qadj = 15-12; + Qadj = 15 - 12; move16(); - synthesis_filter_fx(lpc2_fx,&impzi_fx[0],&impzo_fx[0],&mem_fx[0],10,160 ); + synthesis_filter_fx( lpc2_fx, &impzi_fx[0], &impzo_fx[0], &mem_fx[0], 10, 160 ); /* compute energy of impz */ - FOR (x_fx=0; x_fx<160; x_fx++) + FOR( x_fx = 0; x_fx < 160; x_fx++ ) { #ifdef BASOP_NOGLOB - energy_impz_fx = L_add_o(energy_impz_fx , L_mult0(impzo_fx[x_fx],impzo_fx[x_fx]), &Overflow); + energy_impz_fx = L_add_o( energy_impz_fx, L_mult0( impzo_fx[x_fx], impzo_fx[x_fx] ), &Overflow ); #else - energy_impz_fx = L_add(energy_impz_fx , L_mult0(impzo_fx[x_fx],impzo_fx[x_fx])); + energy_impz_fx = L_add( energy_impz_fx, L_mult0( impzo_fx[x_fx], impzo_fx[x_fx] ) ); #endif } /*energy_impz = (float)(10*log10((float)energy_impz)); */ - exp_ee = norm_l(energy_impz_fx); - frac_ee = Log2_norm_lc(L_shl(energy_impz_fx, exp_ee)); - exp_ee = sub(30, exp_ee); /*30-exp-Q0 */ - Ltmp = Mpy_32_16(exp_ee, frac_ee, LG10); /* Ltmp Q14 */ - energy_impz_fx =L_shr(Ltmp, 3); /* 16+11(4bits for 15 no) = 14+x => x= 11 */ + exp_ee = norm_l( energy_impz_fx ); + frac_ee = Log2_norm_lc( L_shl( energy_impz_fx, exp_ee ) ); + exp_ee = sub( 30, exp_ee ); /*30-exp-Q0 */ + Ltmp = Mpy_32_16( exp_ee, frac_ee, LG10 ); /* Ltmp Q14 */ + energy_impz_fx = L_shr( Ltmp, 3 ); /* 16+11(4bits for 15 no) = 14+x => x= 11 */ /* energy_impz_fx is Q11 */ - Ltmp_32 = DTFS_getEngy_fx(CURRP_Q_E_FX); /*Q = 2*(CURRP_Q_E_FX->Q) */ - Qadj = sub(hSC_VBR->Q_prev_cw_en_fx, shl(CURRP_Q_E_FX->Q, 1)); + Ltmp_32 = DTFS_getEngy_fx( CURRP_Q_E_FX ); /*Q = 2*(CURRP_Q_E_FX->Q) */ + Qadj = sub( hSC_VBR->Q_prev_cw_en_fx, shl( CURRP_Q_E_FX->Q, 1 ) ); #ifdef BASOP_NOGLOB - Ltmp_32 = L_shl_o(Ltmp_32,Qadj, &Overflow); /* shift left required to adjust Q of CURRP_Q_E_FX = Q_prev_cw_en_fx */ + Ltmp_32 = L_shl_o( Ltmp_32, Qadj, &Overflow ); /* shift left required to adjust Q of CURRP_Q_E_FX = Q_prev_cw_en_fx */ #else - Ltmp_32 = L_shl(Ltmp_32,Qadj); /* shift left required to adjust Q of CURRP_Q_E_FX = Q_prev_cw_en_fx */ + Ltmp_32 = L_shl( Ltmp_32, Qadj ); /* shift left required to adjust Q of CURRP_Q_E_FX = Q_prev_cw_en_fx */ #endif /* if ((DTFS_getEngy(*CURRP_Q_E) > st->prev_cw_en)&&(max(pos_q,neg_q)>3.5) && energy_impz>15.0 && tmpres>0.7) */ test(); test(); test(); #ifdef BASOP_NOGLOB - IF ((GT_32(Ltmp_32, hSC_VBR->prev_cw_en_fx ))&&(GT_32(L_max(pos_q_fx,neg_q_fx),939524096))&&(GT_32(energy_impz_fx,30720)) - && (GT_32(Mult_32_16(tmpres_fx,23265),shl_o(1,sub(Qtmpres,1), &Overflow))) ) + IF( ( GT_32( Ltmp_32, hSC_VBR->prev_cw_en_fx ) ) && ( GT_32( L_max( pos_q_fx, neg_q_fx ), 939524096 ) ) && ( GT_32( energy_impz_fx, 30720 ) ) && ( GT_32( Mult_32_16( tmpres_fx, 23265 ), shl_o( 1, sub( Qtmpres, 1 ), &Overflow ) ) ) ) #else - IF ((GT_32(Ltmp_32, hSC_VBR->prev_cw_en_fx ))&&(GT_32(L_max(pos_q_fx,neg_q_fx),939524096))&&(GT_32(energy_impz_fx,30720)) - && (GT_32(Mult_32_16(tmpres_fx,23265),shl(1,sub(Qtmpres,1)))) ) + IF( ( GT_32( Ltmp_32, hSC_VBR->prev_cw_en_fx ) ) && ( GT_32( L_max( pos_q_fx, neg_q_fx ), 939524096 ) ) && ( GT_32( energy_impz_fx, 30720 ) ) && ( GT_32( Mult_32_16( tmpres_fx, 23265 ), shl( 1, sub( Qtmpres, 1 ) ) ) ) ) #endif { /* if ((pos_q > neg_q) && ((pos_q>3.0*pos_nq0) || ((pos_q > 1.5*pos_nq0) && (neg_q < 1.5*neg_nq0)))) */ test(); test(); test(); - IF ( (GT_32(pos_q_fx , neg_q_fx)) - && ((GT_32(Mult_32_16(pos_q_fx,10923), L_shr(pos_nq0_fx,sub(Qposnq,28)) )) - || ((GT_32( Mult_32_16(pos_q_fx,21845),L_shr(pos_nq0_fx,sub(Qposnq,28)) )) - && (LT_32(Mult_32_16(neg_q_fx,21846), L_shr(neg_nq0_fx,sub(Qnegnq,28)) )) )) - ) + IF( ( GT_32( pos_q_fx, neg_q_fx ) ) && ( ( GT_32( Mult_32_16( pos_q_fx, 10923 ), L_shr( pos_nq0_fx, sub( Qposnq, 28 ) ) ) ) || ( ( GT_32( Mult_32_16( pos_q_fx, 21845 ), L_shr( pos_nq0_fx, sub( Qposnq, 28 ) ) ) ) && ( LT_32( Mult_32_16( neg_q_fx, 21846 ), L_shr( neg_nq0_fx, sub( Qnegnq, 28 ) ) ) ) ) ) ) /* 10923 = (1/3) oin Q15, pos_q_fx is Q28, so result of Mult_32_16(pos_q_fx,10923) = Q28 */ /* L_shr(pos_nq0_fx,sub(Qposnq,28)) brings pos_nq0_fx with variable Q to fixed Q28 */ { - PPP_MODE_E='B'; + PPP_MODE_E = 'B'; move16(); } test(); test(); test(); /* if ((pos_q <= neg_q) && ((neg_q>3.0*neg_nq0)|| ((neg_q > 1.5*neg_nq0) && (pos_q < 1.5*pos_nq0)))) */ - IF ( (LE_32(pos_q_fx ,neg_q_fx)) - && ((GT_32(Mult_32_16(neg_q_fx,10923), L_shr(neg_nq0_fx,sub(Qnegnq,28)))) - || ((GT_32(Mult_32_16(neg_q_fx,21846), L_shr(neg_nq0_fx,sub(Qnegnq,28)))) - && (LT_32( Mult_32_16( pos_q_fx,21846),L_shr(pos_nq0_fx,sub(Qposnq,28)))))) - ) + IF( ( LE_32( pos_q_fx, neg_q_fx ) ) && ( ( GT_32( Mult_32_16( neg_q_fx, 10923 ), L_shr( neg_nq0_fx, sub( Qnegnq, 28 ) ) ) ) || ( ( GT_32( Mult_32_16( neg_q_fx, 21846 ), L_shr( neg_nq0_fx, sub( Qnegnq, 28 ) ) ) ) && ( LT_32( Mult_32_16( pos_q_fx, 21846 ), L_shr( pos_nq0_fx, sub( Qposnq, 28 ) ) ) ) ) ) ) { - PPP_MODE_E='B'; + PPP_MODE_E = 'B'; move16(); } } } } - DTFS_copy_fx(TMPDTFS2_FX,*CURRP_Q_E_FX); - DTFS_poleFilter_fx_9(TMPDTFS_FX, pf_temp1, pf_temp2, pf_temp, pf_n2); - DTFS_poleFilter_fx_9(TMPDTFS2_FX, pf_temp1, pf_temp2, pf_temp, pf_n2); + DTFS_copy_fx( TMPDTFS2_FX, *CURRP_Q_E_FX ); + DTFS_poleFilter_fx_9( TMPDTFS_FX, pf_temp1, pf_temp2, pf_temp, pf_n2 ); + DTFS_poleFilter_fx_9( TMPDTFS2_FX, pf_temp1, pf_temp2, pf_temp, pf_n2 ); - DTFS_sub_fx(TMPDTFS3_FX, *TMPDTFS_FX,*TMPDTFS2_FX); + DTFS_sub_fx( TMPDTFS3_FX, *TMPDTFS_FX, *TMPDTFS2_FX ); /* operate in ADR mode only the rate control is active. This adds some bumpups to improve the speech quality */ /* if ((DTFS_getEngy_band(*TMPDTFS, 1500.0, upper_cut_off_freq_of_interest)/DTFS_getEngy(*TMPDTFS) > 0.05)&&(!st->rate_control)) */ - Ltemp1 = DTFS_getEngy_band_fx(*TMPDTFS_FX, 1500, upper_cut_off_freq_of_interest_fx); /* Q = 2*TMPDTFS_FX->Q*/ - Ltemp2 = DTFS_getEngy_fx(TMPDTFS_FX); /* Q = 2*TMPDTFS_FX->Q */ + Ltemp1 = DTFS_getEngy_band_fx( *TMPDTFS_FX, 1500, upper_cut_off_freq_of_interest_fx ); /* Q = 2*TMPDTFS_FX->Q*/ + Ltemp2 = DTFS_getEngy_fx( TMPDTFS_FX ); /* Q = 2*TMPDTFS_FX->Q */ - IF (Ltemp2==0) + IF( Ltemp2 == 0 ) { - Ltemp_fx=0; + Ltemp_fx = 0; } ELSE { - expb = norm_l(Ltemp1); - fracb = extract_h(L_shl(Ltemp1,expb)); - expb = sub(30, add(expb,shl(TMPDTFS_FX->Q, 1))); - expa = norm_l(Ltemp2); - fraca = extract_h(L_shl(Ltemp2,expa)); - expa = sub(30, add(expa,shl(TMPDTFS_FX->Q, 1))); - - scale = shr(sub(fraca,fracb),15); - fracb = shl(fracb,scale); - expb = sub(expb,scale); - - tmp = div_s(fracb,fraca); /* tmp in Q15 */ - exp = sub(expb,expa); /* ans = tmp*2^(exp) */ + expb = norm_l( Ltemp1 ); + fracb = extract_h( L_shl( Ltemp1, expb ) ); + expb = sub( 30, add( expb, shl( TMPDTFS_FX->Q, 1 ) ) ); + expa = norm_l( Ltemp2 ); + fraca = extract_h( L_shl( Ltemp2, expa ) ); + expa = sub( 30, add( expa, shl( TMPDTFS_FX->Q, 1 ) ) ); + + scale = shr( sub( fraca, fracb ), 15 ); + fracb = shl( fracb, scale ); + expb = sub( expb, scale ); + + tmp = div_s( fracb, fraca ); /* tmp in Q15 */ + exp = sub( expb, expa ); /* ans = tmp*2^(exp) */ #ifdef BASOP_NOGLOB - Ltemp_fx = L_shl_o(tmp, add(exp,12), &Overflow); /* make tmp Q27 */ + Ltemp_fx = L_shl_o( tmp, add( exp, 12 ), &Overflow ); /* make tmp Q27 */ #else - Ltemp_fx = L_shl(tmp, add(exp,12)); /* make tmp Q27 */ + Ltemp_fx = L_shl( tmp, add( exp, 12 ) ); /* make tmp Q27 */ #endif - } test(); - IF (GT_32(Ltemp_fx , 6710886)&&(!hSC_VBR->rate_control)) /* 0.05 in Q27 = 6710886 */ + IF( GT_32( Ltemp_fx, 6710886 ) && ( !hSC_VBR->rate_control ) ) /* 0.05 in Q27 = 6710886 */ { /*if (10.0*log10(DTFS_getEngy_band(*TMPDTFS,1500.0,upper_cut_off_freq_of_interest)/ */ /*DTFS_getEngy_band(*TMPDTFS3,1500.0,upper_cut_off_freq_of_interest)) < 0.1) */ - Ltemp1 = DTFS_getEngy_band_fx(*TMPDTFS_FX,1500,upper_cut_off_freq_of_interest_fx); - Ltemp2 = DTFS_getEngy_band_fx(*TMPDTFS3_FX,1500,upper_cut_off_freq_of_interest_fx); + Ltemp1 = DTFS_getEngy_band_fx( *TMPDTFS_FX, 1500, upper_cut_off_freq_of_interest_fx ); + Ltemp2 = DTFS_getEngy_band_fx( *TMPDTFS3_FX, 1500, upper_cut_off_freq_of_interest_fx ); /*--------------------------------------------------------------*/ /* Ltemp_fx = (Word32)divide_dp(Ltemp1, Ltemp2, Qadj,1);//Q29+1 */ /*--------------------------------------------------------------*/ - IF (Ltemp2==0) + IF( Ltemp2 == 0 ) { - Ltemp_fx=0; + Ltemp_fx = 0; } ELSE { - expa = norm_l(Ltemp2); - fraca = extract_h(L_shl(Ltemp2,expa)); - expa = sub(30, expa); + expa = norm_l( Ltemp2 ); + fraca = extract_h( L_shl( Ltemp2, expa ) ); + expa = sub( 30, expa ); - expb = norm_l(Ltemp1); - fracb = round_fx(L_shl(Ltemp1,expb)); - expb = sub(30,expb); + expb = norm_l( Ltemp1 ); + fracb = round_fx( L_shl( Ltemp1, expb ) ); + expb = sub( 30, expb ); - scale = shr(sub(fraca,fracb),15); - fracb = shl(fracb,scale); - expb = sub(expb,scale); + scale = shr( sub( fraca, fracb ), 15 ); + fracb = shl( fracb, scale ); + expb = sub( expb, scale ); - tmp = div_s(fracb,fraca); - exp = sub(expb,expa); + tmp = div_s( fracb, fraca ); + exp = sub( expb, expa ); #ifdef BASOP_NOGLOB - Ltemp_fx = L_shl_o(tmp,add(exp,14), &Overflow); /* answer in Q29 */ + Ltemp_fx = L_shl_o( tmp, add( exp, 14 ), &Overflow ); /* answer in Q29 */ #else - Ltemp_fx = L_shl(tmp,add(exp,14)); /* answer in Q29 */ + Ltemp_fx = L_shl( tmp, add( exp, 14 ) ); /* answer in Q29 */ #endif - } /*-------------------------------------------*/ /* 10.0*log10(Ltemp_fx) */ - exp_ee = norm_l(Ltemp_fx); - frac_ee = Log2_norm_lc(L_shl(Ltemp_fx, exp_ee)); - exp_ee = sub(30,add(exp_ee,29)); /* 30 fixed here, 29 is the Q of Ltemp_fx */ - Ltmp = Mpy_32_16(exp_ee, frac_ee, LG10); /* LG10 in Q13, so answer Ltmp in Q14 */ + exp_ee = norm_l( Ltemp_fx ); + frac_ee = Log2_norm_lc( L_shl( Ltemp_fx, exp_ee ) ); + exp_ee = sub( 30, add( exp_ee, 29 ) ); /* 30 fixed here, 29 is the Q of Ltemp_fx */ + Ltmp = Mpy_32_16( exp_ee, frac_ee, LG10 ); /* LG10 in Q13, so answer Ltmp in Q14 */ - IF(LT_32(Ltmp,1638)) /* 1638 = 0.1 in Q14 */ + IF( LT_32( Ltmp, 1638 ) ) /* 1638 = 0.1 in Q14 */ { /* if (res_enratio > 0.8) */ - if (GT_32(res_enratio_fx , 1638)) /* 1638 = 0.8 in Q11, res_enratio_fx in Q11 */ + if ( GT_32( res_enratio_fx, 1638 ) ) /* 1638 = 0.8 in Q11, res_enratio_fx in Q11 */ { PPP_MODE_E = 'B'; move16(); @@ -1072,72 +1058,72 @@ ivas_error ppp_voiced_encoder_fx( /* To increase bump up, raise first threshold, lower second */ /*tmp = (float)(10.0*log10(DTFS_getEngy(*TMPDTFS)/DTFS_getEngy(*TMPDTFS3)));*/ - Lacc = DTFS_getEngy_P2A_fx(TMPDTFS_FX); /* Q = 2*(TMPDTFS_FX->Q) */ - Lacc1= DTFS_getEngy_P2A_fx(TMPDTFS3_FX); /* Q = 2*(TMPDTFS3_FX->Q) */ + Lacc = DTFS_getEngy_P2A_fx( TMPDTFS_FX ); /* Q = 2*(TMPDTFS_FX->Q) */ + Lacc1 = DTFS_getEngy_P2A_fx( TMPDTFS3_FX ); /* Q = 2*(TMPDTFS3_FX->Q) */ - sft=shl(sub(TMPDTFS_FX->Q,TMPDTFS3_FX->Q),1);/* to check if Lacc<=2*Lacc1 */ - flag1=0; + sft = shl( sub( TMPDTFS_FX->Q, TMPDTFS3_FX->Q ), 1 ); /* to check if Lacc<=2*Lacc1 */ + flag1 = 0; move16(); - IF (sft>0) + IF( sft > 0 ) { /*if (L_sub40_40(L_shr40(Lacc,sft),Lacc1)<=0) */ - Lacc = L_shr(Lacc,sft); - flag1=1; + Lacc = L_shr( Lacc, sft ); + flag1 = 1; move16(); /* do the divide */ } ELSE { /*if (L_sub40_40(Lacc,L_shr40(Lacc1,negate(sft)))<=0) */ - Lacc1 = L_shr(Lacc1,negate(sft)); - flag1=1; - move16();/* do the divide */ + Lacc1 = L_shr( Lacc1, negate( sft ) ); + flag1 = 1; + move16(); /* do the divide */ } - IF (EQ_16(flag1,1)) + IF( EQ_16( flag1, 1 ) ) { - expb = norm_l(Lacc); - fracb = extract_h(L_shl(Lacc,expb)); - expb = sub(30,add(expb,shl(TMPDTFS_FX->Q, 1))); - - expa = norm_l(Lacc1); - fraca = extract_h(L_shl(Lacc1,expa)); - expa = sub(30,add(expa,shl(TMPDTFS3_FX->Q, 1))); - - scale = shr(sub(fraca,fracb),15); - fracb = shl(fracb,scale); - expb = sub(expb,scale); - - tmp = div_s(fracb,fraca); /* tmp is always Q15 */ - exp = sub(expb,expa); /* Answer after division Lacc/Lacc1 = (2^exp)*(tmp/2^15) */ - - L_tmp = L_deposit_h(tmp); /* tmp is always Q15, L_tmp is always Q31 */ - expa = norm_l(L_tmp); - L_tmp = L_shl(L_tmp,expa); - exp = sub(30,add(expa,sub(31,exp))); - frac = Log2_norm_lc(L_tmp); - L_tmp = Mpy_32_16(exp,frac,12330); /* L_tmp is always Q13 */ + expb = norm_l( Lacc ); + fracb = extract_h( L_shl( Lacc, expb ) ); + expb = sub( 30, add( expb, shl( TMPDTFS_FX->Q, 1 ) ) ); + + expa = norm_l( Lacc1 ); + fraca = extract_h( L_shl( Lacc1, expa ) ); + expa = sub( 30, add( expa, shl( TMPDTFS3_FX->Q, 1 ) ) ); + + scale = shr( sub( fraca, fracb ), 15 ); + fracb = shl( fracb, scale ); + expb = sub( expb, scale ); + + tmp = div_s( fracb, fraca ); /* tmp is always Q15 */ + exp = sub( expb, expa ); /* Answer after division Lacc/Lacc1 = (2^exp)*(tmp/2^15) */ + + L_tmp = L_deposit_h( tmp ); /* tmp is always Q15, L_tmp is always Q31 */ + expa = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, expa ); + exp = sub( 30, add( expa, sub( 31, exp ) ) ); + frac = Log2_norm_lc( L_tmp ); + L_tmp = Mpy_32_16( exp, frac, 12330 ); /* L_tmp is always Q13 */ #ifdef BASOP_NOGLOB - Ltemp = L_shl_o(L_tmp,10, &Overflow); /* Ltemp is always Q23 */ + Ltemp = L_shl_o( L_tmp, 10, &Overflow ); /* Ltemp is always Q23 */ #else - Ltemp = L_shl(L_tmp,10); /* Ltemp is always Q23 */ + Ltemp = L_shl( L_tmp, 10 ); /* Ltemp is always Q23 */ #endif } ELSE { - Ltemp = L_add(MAX_32, 0); + Ltemp = L_add( MAX_32, 0 ); } test(); - if ((Ltemp <= 0)&&(!hSC_VBR->rate_control)) + if ( ( Ltemp <= 0 ) && ( !hSC_VBR->rate_control ) ) { PPP_MODE_E = 'B'; move16(); } #ifdef BASOP_NOGLOB - IF ( LT_16(shl_o(hSC_VBR->vadsnr_fx,1, &Overflow) ,hSC_VBR->SNR_THLD_fx)) /* Q8 */ + IF( LT_16( shl_o( hSC_VBR->vadsnr_fx, 1, &Overflow ), hSC_VBR->SNR_THLD_fx ) ) /* Q8 */ #else - IF ( LT_16(shl(hSC_VBR->vadsnr_fx,1) ,hSC_VBR->SNR_THLD_fx)) /* Q8 */ + IF( LT_16( shl( hSC_VBR->vadsnr_fx, 1 ), hSC_VBR->SNR_THLD_fx ) ) /* Q8 */ #endif { /* if ((( tmp < 3.05 && max(res_enratio,sp_enratio) > 0.8 ) && (st->rate_control))|| @@ -1148,8 +1134,8 @@ ivas_error ppp_voiced_encoder_fx( test(); test(); test(); - if ((( LT_32(Ltemp, 25585254 )&>_32(L_max(L_shl(res_enratio_fx,4),sp_enratio_fx),6554))&&(hSC_VBR->rate_control))|| - (( LT_32(Ltemp, 23488102 ) && GT_32(L_max(L_shl(res_enratio_fx,4),sp_enratio_fx) , 5325) )&&(!hSC_VBR->rate_control))) + if ( ( ( LT_32( Ltemp, 25585254 ) && GT_32( L_max( L_shl( res_enratio_fx, 4 ), sp_enratio_fx ), 6554 ) ) && ( hSC_VBR->rate_control ) ) || + ( ( LT_32( Ltemp, 23488102 ) && GT_32( L_max( L_shl( res_enratio_fx, 4 ), sp_enratio_fx ), 5325 ) ) && ( !hSC_VBR->rate_control ) ) ) { PPP_MODE_E = 'B'; move16(); @@ -1164,8 +1150,8 @@ ivas_error ppp_voiced_encoder_fx( test(); test(); test(); - if ((( LT_32(Ltemp ,20132659 )&>_32(L_max(L_shl(res_enratio_fx,4),sp_enratio_fx),7700))&&(hSC_VBR->rate_control))|| - (( LT_32(Ltemp, 37748736 ) && GT_32(L_max(L_shl(res_enratio_fx,4),sp_enratio_fx) , 4096) )&&(!hSC_VBR->rate_control))) + if ( ( ( LT_32( Ltemp, 20132659 ) && GT_32( L_max( L_shl( res_enratio_fx, 4 ), sp_enratio_fx ), 7700 ) ) && ( hSC_VBR->rate_control ) ) || + ( ( LT_32( Ltemp, 37748736 ) && GT_32( L_max( L_shl( res_enratio_fx, 4 ), sp_enratio_fx ), 4096 ) ) && ( !hSC_VBR->rate_control ) ) ) { PPP_MODE_E = 'B'; move16(); @@ -1176,73 +1162,72 @@ ivas_error ppp_voiced_encoder_fx( } ELSE { - PPP_MODE_E = 'B' ; - move16();/*Amplitude quantization is failing*/ + PPP_MODE_E = 'B'; + move16(); /*Amplitude quantization is failing*/ } } ELSE { } - if (PPP_MODE_E == 'B') + if ( PPP_MODE_E == 'B' ) { hSC_VBR->bump_up = 1; move16(); - count_free(CURRP_NQ_FX); - count_free(TMPDTFS_FX); - count_free(TMPDTFS2_FX); - count_free(TMPDTFS3_FX); - count_free(CURRP_Q_E_FX); - count_free(dtfs_temp_fx); + count_free( CURRP_NQ_FX ); + count_free( TMPDTFS_FX ); + count_free( TMPDTFS2_FX ); + count_free( TMPDTFS3_FX ); + count_free( CURRP_Q_E_FX ); + count_free( dtfs_temp_fx ); return error; } - IF ( hSC_VBR->Q_to_F ) + IF( hSC_VBR->Q_to_F ) { - hSC_VBR->patterncount = add(hSC_VBR->patterncount ,hSC_VBR->pattern_m); + hSC_VBR->patterncount = add( hSC_VBR->patterncount, hSC_VBR->pattern_m ); - IF (GE_16(hSC_VBR->patterncount , 1000)) + IF( GE_16( hSC_VBR->patterncount, 1000 ) ) { - hSC_VBR->patterncount = sub (hSC_VBR->patterncount , 1000); + hSC_VBR->patterncount = sub( hSC_VBR->patterncount, 1000 ); PPP_MODE_E = 'B'; move16(); hSC_VBR->bump_up = 1; move16(); - count_free(CURRP_NQ_FX); - count_free(TMPDTFS_FX); - count_free(TMPDTFS2_FX); - count_free(TMPDTFS3_FX); - count_free(CURRP_Q_E_FX); - count_free(dtfs_temp_fx); + count_free( CURRP_NQ_FX ); + count_free( TMPDTFS_FX ); + count_free( TMPDTFS2_FX ); + count_free( TMPDTFS3_FX ); + count_free( CURRP_Q_E_FX ); + count_free( dtfs_temp_fx ); return error; } - } /* packetization of the delta lag in_fx PPP */ - IF (EQ_16(PPP_MODE_E,'Q')) + IF( EQ_16( PPP_MODE_E, 'Q' ) ) { - Q_delta_lag = add(delta_lag_E,11); /* to make it positive always */ + Q_delta_lag = add( delta_lag_E, 11 ); /* to make it positive always */ - push_indice_fx(hBstr, IND_DELTALAG, Q_delta_lag, 5 ); + push_indice_fx( hBstr, IND_DELTALAG, Q_delta_lag, 5 ); } - WIsyn_fx(*dtfs_temp_fx, CURRP_Q_E_FX, lpc2_fx, &(hSC_VBR->ph_offset_E_fx), out_fx, L_FRAME,0,S_fx,C_fx, - pf_temp1,pf_temp2,pf_temp,pf_n2); + WIsyn_fx( *dtfs_temp_fx, CURRP_Q_E_FX, lpc2_fx, &( hSC_VBR->ph_offset_E_fx ), out_fx, L_FRAME, 0, S_fx, C_fx, + pf_temp1, pf_temp2, pf_temp, pf_n2 ); /* i/o ph_offset_fx in Q15, out_fx in Q0 */ - DTFS_copy_fx(dtfs_temp_fx, *CURRP_Q_E_FX); - Lacc = DTFS_getEngy_P2A_fx(CURRP_NQ_FX); - hSC_VBR->Q_prev_cw_en_fx=norm_l(Lacc); + DTFS_copy_fx( dtfs_temp_fx, *CURRP_Q_E_FX ); + Lacc = DTFS_getEngy_P2A_fx( CURRP_NQ_FX ); + hSC_VBR->Q_prev_cw_en_fx = norm_l( Lacc ); /* hSC_VBR->Q_prev_cw_en_fx = (Lacc==0)?31: hSC_VBR->Q_prev_cw_en_fx;move16(); */ - if (Lacc==0) + if ( Lacc == 0 ) { hSC_VBR->Q_prev_cw_en_fx = 31; move16(); } - hSC_VBR->prev_cw_en_fx=(Word32) L_shl(Lacc,hSC_VBR->Q_prev_cw_en_fx); /*2Q+Q_prev_cw_en_fx */ - hSC_VBR->Q_prev_cw_en_fx=add(hSC_VBR->Q_prev_cw_en_fx,shl(CURRP_NQ_FX->Q,1)); + hSC_VBR->prev_cw_en_fx = (Word32) L_shl( Lacc, hSC_VBR->Q_prev_cw_en_fx ); /*2Q+Q_prev_cw_en_fx */ + hSC_VBR->Q_prev_cw_en_fx = add( hSC_VBR->Q_prev_cw_en_fx, shl( CURRP_NQ_FX->Q, 1 ) ); /* Copy DTFS related parameters from 'dtfs_temp' to 'st_fx' structure */ hSC_VBR->dtfs_enc_lag = dtfs_temp_fx->lag_fx; move16(); @@ -1254,18 +1239,18 @@ ivas_error ppp_voiced_encoder_fx( move16(); hSC_VBR->dtfs_enc_upper_cut_off_freq_fx = dtfs_temp_fx->upper_cut_off_freq_fx; move16(); - Copy(dtfs_temp_fx->a_fx, hSC_VBR->dtfs_enc_a_fx, MAXLAG_WI); - Copy(dtfs_temp_fx->b_fx, hSC_VBR->dtfs_enc_b_fx, MAXLAG_WI); + Copy( dtfs_temp_fx->a_fx, hSC_VBR->dtfs_enc_a_fx, MAXLAG_WI ); + Copy( dtfs_temp_fx->b_fx, hSC_VBR->dtfs_enc_b_fx, MAXLAG_WI ); hSC_VBR->dtfs_enc_Q = dtfs_temp_fx->Q; move16(); - count_free(CURRP_NQ_FX); - count_free(TMPDTFS_FX); - count_free(TMPDTFS2_FX); - count_free(TMPDTFS3_FX); - count_free(CURRP_Q_E_FX); - count_free(dtfs_temp_fx); + count_free( CURRP_NQ_FX ); + count_free( TMPDTFS_FX ); + count_free( TMPDTFS2_FX ); + count_free( TMPDTFS3_FX ); + count_free( CURRP_Q_E_FX ); + count_free( dtfs_temp_fx ); return error; } @@ -1299,42 +1284,42 @@ ivas_error ppp_voiced_encoder_fx( /* } */ /* +fres(n) */ /*===================================================================*/ -static void synthesis_filter_fx (Word16 b[], Word16 x[], Word16 y[], Word16 buf[], Word16 P, Word16 N ) +static void synthesis_filter_fx( Word16 b[], Word16 x[], Word16 y[], Word16 buf[], Word16 P, Word16 N ) { Word32 acc; Word16 i, j; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - FOR (i = 0; i < N; i++) + FOR( i = 0; i < N; i++ ) { - acc = L_deposit_h(*x++);/*Q16 */ - acc = L_shr(acc, 3);/*Q13 */ + acc = L_deposit_h( *x++ ); /*Q16 */ + acc = L_shr( acc, 3 ); /*Q13 */ - FOR (j = P - 1; j > 0; j--) + FOR( j = P - 1; j > 0; j-- ) { /* acc = L_sub(acc, L_mult(memory[j], coef[j])); */ #ifdef BASOP_NOGLOB - acc = L_msu_o(acc, buf[j], b[j], &Overflow);/*Q13 */ + acc = L_msu_o( acc, buf[j], b[j], &Overflow ); /*Q13 */ #else - acc = L_msu(acc, buf[j], b[j]);/*Q13 */ + acc = L_msu( acc, buf[j], b[j] ); /*Q13 */ #endif buf[j] = buf[j - 1]; move16(); } /* acc = L_sub(acc, L_mult(memory[0], coef[0])); */ #ifdef BASOP_NOGLOB - acc = L_msu_o(acc, buf[0], b[0], &Overflow); - acc = L_shl_o(acc, 3, &Overflow); + acc = L_msu_o( acc, buf[0], b[0], &Overflow ); + acc = L_shl_o( acc, 3, &Overflow ); - *y++ = round_fx_o(acc, &Overflow); - buf[0] = round_fx_o(acc, &Overflow); + *y++ = round_fx_o( acc, &Overflow ); + buf[0] = round_fx_o( acc, &Overflow ); #else - acc = L_msu(acc, buf[0], b[0]); - acc = L_shl(acc, 3); + acc = L_msu( acc, buf[0], b[0] ); + acc = L_shl( acc, 3 ); - *y++ = round_fx(acc); - buf[0] = round_fx(acc); + *y++ = round_fx( acc ); + buf[0] = round_fx( acc ); #endif } } @@ -1366,8 +1351,7 @@ static Word32 DTFS_freq_corr_fx( DTFS_STRUCTURE X2_DTFS_fx, Word16 lband, Word16 hband, - Word16* Qout -) + Word16 *Qout ) { Word16 k, HalfLag, lk, hk; Word32 corr_fx; @@ -1382,31 +1366,31 @@ static Word32 DTFS_freq_corr_fx( #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - IF(LT_16(X1_DTFS_fx.lag_fx, X2_DTFS_fx.lag_fx)) + IF( LT_16( X1_DTFS_fx.lag_fx, X2_DTFS_fx.lag_fx ) ) { - DTFS_zeroPadd_fx(X2_DTFS_fx.lag_fx, &X1_DTFS_fx); + DTFS_zeroPadd_fx( X2_DTFS_fx.lag_fx, &X1_DTFS_fx ); } - corr_fx = L_deposit_l(0); + corr_fx = L_deposit_l( 0 ); - L_lband = L_mult(lband, X2_DTFS_fx.lag_fx); - L_hband = L_mult(hband, X2_DTFS_fx.lag_fx); - HalfLag = s_min(shr(X2_DTFS_fx.lag_fx, 1), X2_DTFS_fx.nH_4kHz_fx); + L_lband = L_mult( lband, X2_DTFS_fx.lag_fx ); + L_hband = L_mult( hband, X2_DTFS_fx.lag_fx ); + HalfLag = s_min( shr( X2_DTFS_fx.lag_fx, 1 ), X2_DTFS_fx.nH_4kHz_fx ); /* get lband and hband */ - FOR(k = 0; k <= HalfLag; k++) + FOR( k = 0; k <= HalfLag; k++ ) { - freq_fx = L_mult(k, 12800); - IF(GE_32(freq_fx, L_lband)) + freq_fx = L_mult( k, 12800 ); + IF( GE_32( freq_fx, L_lband ) ) { BREAK; } } lk = k; - FOR(k = 0; k <= HalfLag; k++) + FOR( k = 0; k <= HalfLag; k++ ) { - freq_fx = L_mult(k, 12800); - IF(GE_32(freq_fx, L_hband)) + freq_fx = L_mult( k, 12800 ); + IF( GE_32( freq_fx, L_hband ) ) { BREAK; } @@ -1414,36 +1398,36 @@ static Word32 DTFS_freq_corr_fx( hk = k; move16(); - FOR(k = lk; k < hk; k++) + FOR( k = lk; k < hk; k++ ) { #ifdef BASOP_NOGLOB - corr_fx = L_mac0_o(corr_fx, X1_DTFS_fx.a_fx[k], X2_DTFS_fx.a_fx[k], &Overflow); /* Q(1) */ - corr_fx = L_mac0_o(corr_fx, X1_DTFS_fx.b_fx[k], X2_DTFS_fx.b_fx[k], &Overflow); /* Q(1) */ + corr_fx = L_mac0_o( corr_fx, X1_DTFS_fx.a_fx[k], X2_DTFS_fx.a_fx[k], &Overflow ); /* Q(1) */ + corr_fx = L_mac0_o( corr_fx, X1_DTFS_fx.b_fx[k], X2_DTFS_fx.b_fx[k], &Overflow ); /* Q(1) */ #else - corr_fx = L_mac0(corr_fx, X1_DTFS_fx.a_fx[k], X2_DTFS_fx.a_fx[k]); /* Q(1) */ - corr_fx = L_mac0(corr_fx, X1_DTFS_fx.b_fx[k], X2_DTFS_fx.b_fx[k]); /* Q(1) */ + corr_fx = L_mac0( corr_fx, X1_DTFS_fx.a_fx[k], X2_DTFS_fx.a_fx[k] ); /* Q(1) */ + corr_fx = L_mac0( corr_fx, X1_DTFS_fx.b_fx[k], X2_DTFS_fx.b_fx[k] ); /* Q(1) */ #endif } - Qr = norm_l(corr_fx); - if (corr_fx == 0) + Qr = norm_l( corr_fx ); + if ( corr_fx == 0 ) { Qr = 31; move16(); } #ifdef BASOP_NOGLOB - E1_fx = round_fx_o(L_shl_o(corr_fx, Qr, &Overflow), &Overflow); /* Q(Qr-16) */ + E1_fx = round_fx_o( L_shl_o( corr_fx, Qr, &Overflow ), &Overflow ); /* Q(Qr-16) */ #else - E1_fx = round_fx(L_shl(corr_fx, Qr)); /* Q(Qr-16) */ + E1_fx = round_fx( L_shl( corr_fx, Qr ) ); /* Q(Qr-16) */ #endif - Num = L_mult0(E1_fx, E1_fx); /* Q(2+2*Qr-32+1) */ - Q_num = sub(shl(add(add(X1_DTFS_fx.Q, X2_DTFS_fx.Q), Qr), 1), 32); + Num = L_mult0( E1_fx, E1_fx ); /* Q(2+2*Qr-32+1) */ + Q_num = sub( shl( add( add( X1_DTFS_fx.Q, X2_DTFS_fx.Q ), Qr ), 1 ), 32 ); /* PORTING: Handling the functions with variable no. of arguments */ - E_fx = DTFS_getEngy_band_fx(X1_DTFS_fx, lband, hband); /* Q(1) */ - q1 = norm_l(E_fx); - if (E_fx == 0) + E_fx = DTFS_getEngy_band_fx( X1_DTFS_fx, lband, hband ); /* Q(1) */ + q1 = norm_l( E_fx ); + if ( E_fx == 0 ) { q1 = 31; move16(); @@ -1452,28 +1436,28 @@ static Word32 DTFS_freq_corr_fx( #ifdef BASOP_NOGLOB E1_fx = round_fx_o( L_shl_o( E_fx, q1, &Overflow ), &Overflow ); /* Q(1+q1-16) */ #else - E1_fx = round_fx( L_shl( E_fx, q1 ) ); /* Q(1+q1-16) */ + E1_fx = round_fx( L_shl( E_fx, q1 ) ); /* Q(1+q1-16) */ #endif /* PORTING: Handling the functions with variable no. of arguments */ - E_fx = DTFS_getEngy_band_fx(X2_DTFS_fx, lband, hband); /* Q(1) */ - q2 = norm_l(E_fx); - if (E_fx == 0) + E_fx = DTFS_getEngy_band_fx( X2_DTFS_fx, lband, hband ); /* Q(1) */ + q2 = norm_l( E_fx ); + if ( E_fx == 0 ) { q2 = 31; move16(); } #ifdef BASOP_NOGLOB - E2_fx = round_fx_o(L_shl_o(E_fx, q2, &Overflow), &Overflow); /* Q(1+q2-16) */ + E2_fx = round_fx_o( L_shl_o( E_fx, q2, &Overflow ), &Overflow ); /* Q(1+q2-16) */ #else - E2_fx = round_fx( L_shl( E_fx, q2 ) ); /* Q(1+q2-16) */ + E2_fx = round_fx( L_shl( E_fx, q2 ) ); /* Q(1+q2-16) */ #endif - Den = L_mult0(E1_fx, E2_fx); /* Q(2+q1+q2-32+1) */ + Den = L_mult0( E1_fx, E2_fx ); /* Q(2+q1+q2-32+1) */ Q_den = sub( add( shl( add( X2_DTFS_fx.Q, X1_DTFS_fx.Q ), 1 ), add( q1, q2 ) ), 32 ); - Num = L_max(Num, 1); + Num = L_max( Num, 1 ); - IF(Num == 0) + IF( Num == 0 ) { Result = 0; *Qout = 31; @@ -1481,46 +1465,45 @@ static Word32 DTFS_freq_corr_fx( ELSE { - expa = norm_l(Num); + expa = norm_l( Num ); #ifdef BASOP_NOGLOB - fraca = extract_h(L_shl_o(Num,expa, &Overflow)); + fraca = extract_h( L_shl_o( Num, expa, &Overflow ) ); #else - fraca = extract_h(L_shl(Num,expa)); + fraca = extract_h( L_shl( Num, expa ) ); #endif - expa = sub(30, add(expa,Q_num)); + expa = sub( 30, add( expa, Q_num ) ); - expb = norm_l(Den); + expb = norm_l( Den ); #ifdef BASOP_NOGLOB - fracb = round_fx_o(L_shl_o(Den,expb, &Overflow), &Overflow); + fracb = round_fx_o( L_shl_o( Den, expb, &Overflow ), &Overflow ); #else - fracb = round_fx(L_shl(Den,expb)); + fracb = round_fx( L_shl( Den, expb ) ); #endif - expb = sub(30, add(expb,Q_den)); + expb = sub( 30, add( expb, Q_den ) ); - scale = shr(sub(fraca,fracb),15); + scale = shr( sub( fraca, fracb ), 15 ); #ifdef BASOP_NOGLOB - fracb = shl_o(fracb,scale, &Overflow); + fracb = shl_o( fracb, scale, &Overflow ); #else - fracb = shl(fracb,scale); + fracb = shl( fracb, scale ); #endif - expb = sub(expb,scale); + expb = sub( expb, scale ); - tmp = div_s(fracb,fraca); - exp = sub(expb,expa); + tmp = div_s( fracb, fraca ); + exp = sub( expb, expa ); - L_tmp = Isqrt_lc(L_deposit_h(tmp),&exp); /* Q(31-exp) */ - IF(corr_fx > 0) + L_tmp = Isqrt_lc( L_deposit_h( tmp ), &exp ); /* Q(31-exp) */ + IF( corr_fx > 0 ) { - Result = L_add(L_tmp, 0); + Result = L_add( L_tmp, 0 ); } ELSE { - Result = L_negate(L_tmp); + Result = L_negate( L_tmp ); } - *Qout = sub(30,exp); - + *Qout = sub( 30, exp ); } return Result; } @@ -1544,34 +1527,34 @@ static Word32 DTFS_freq_corr_fx( /* CALLED FROM : TX */ /*===================================================================*/ -static Word16 DTFS_alignment_extract_td_fx(Word16* x1, Word16* x2, Word16 lag) +static Word16 DTFS_alignment_extract_td_fx( Word16 *x1, Word16 *x2, Word16 lag ) { Word16 j, k, idx, Adiff_fx; Word32 maxcorr, corr; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - maxcorr = L_add(MIN_32, 0); - Adiff_fx = (Word16)(s_max(4, shr(lag, 3))); + maxcorr = L_add( MIN_32, 0 ); + Adiff_fx = (Word16) ( s_max( 4, shr( lag, 3 ) ) ); idx = 0; move16(); - FOR(j = negate(Adiff_fx); j <= Adiff_fx; j++) + FOR( j = negate( Adiff_fx ); j <= Adiff_fx; j++ ) { - corr = L_deposit_l(0); - FOR(k = 0; k < lag; k++) + corr = L_deposit_l( 0 ); + FOR( k = 0; k < lag; k++ ) { #ifdef BASOP_NOGLOB - corr = L_mac_o(corr, x1[k], x2[(k - j + lag) % lag], &Overflow); + corr = L_mac_o( corr, x1[k], x2[( k - j + lag ) % lag], &Overflow ); #else - corr = L_mac(corr, x1[k], x2[(k - j + lag) % lag]); + corr = L_mac( corr, x1[k], x2[( k - j + lag ) % lag] ); #endif } - if (GT_32(corr, maxcorr)) + if ( GT_32( corr, maxcorr ) ) { idx = j; move16(); - maxcorr = L_add(corr, 0); + maxcorr = L_add( corr, 0 ); } } return idx; @@ -1602,8 +1585,7 @@ static Word16 DTFS_alignment_extract_td_fx(Word16* x1, Word16* x2, Word16 lag) static Word32 DTFS_getEngy_band_fx( DTFS_STRUCTURE X_fx, const Word16 lband, - const Word16 hband -) + const Word16 hband ) { Word16 k, lk, hk, HalfLag; Word32 freq_fx, L_lband, L_hband; @@ -1611,24 +1593,24 @@ static Word32 DTFS_getEngy_band_fx( #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif - L_lband = L_mult(lband, X_fx.lag_fx); - L_hband = L_mult(hband, X_fx.lag_fx); - HalfLag = s_min(shr(sub(X_fx.lag_fx, 1), 1), X_fx.nH_4kHz_fx); + L_lband = L_mult( lband, X_fx.lag_fx ); + L_hband = L_mult( hband, X_fx.lag_fx ); + HalfLag = s_min( shr( sub( X_fx.lag_fx, 1 ), 1 ), X_fx.nH_4kHz_fx ); /* get lband and hband */ - FOR(k = 1; k <= HalfLag; k++) + FOR( k = 1; k <= HalfLag; k++ ) { - freq_fx = L_mult(k, 12800); - IF(GE_32(freq_fx, L_lband)) + freq_fx = L_mult( k, 12800 ); + IF( GE_32( freq_fx, L_lband ) ) { BREAK; } } lk = k; move16(); - FOR(k = 1; k <= HalfLag; k++) + FOR( k = 1; k <= HalfLag; k++ ) { - freq_fx = L_mult(k, 12800); - IF(GE_32(freq_fx, L_hband)) + freq_fx = L_mult( k, 12800 ); + IF( GE_32( freq_fx, L_hband ) ) { BREAK; } @@ -1636,36 +1618,36 @@ static Word32 DTFS_getEngy_band_fx( hk = k; move16(); - FOR(k = lk; k < hk; k++) + FOR( k = lk; k < hk; k++ ) { #ifdef BASOP_NOGLOB - en_fx = L_mac0_o(en_fx, X_fx.a_fx[k], X_fx.a_fx[k], &Overflow); /* 2*X1.Q+1 */ - en_fx = L_mac0_o(en_fx, X_fx.b_fx[k], X_fx.b_fx[k], &Overflow); + en_fx = L_mac0_o( en_fx, X_fx.a_fx[k], X_fx.a_fx[k], &Overflow ); /* 2*X1.Q+1 */ + en_fx = L_mac0_o( en_fx, X_fx.b_fx[k], X_fx.b_fx[k], &Overflow ); #else - en_fx = L_mac0(en_fx, X_fx.a_fx[k], X_fx.a_fx[k]); /* 2*X1.Q+1 */ - en_fx = L_mac0(en_fx, X_fx.b_fx[k], X_fx.b_fx[k]); + en_fx = L_mac0( en_fx, X_fx.a_fx[k], X_fx.a_fx[k] ); /* 2*X1.Q+1 */ + en_fx = L_mac0( en_fx, X_fx.b_fx[k], X_fx.b_fx[k] ); #endif } - if (lband == 0) + if ( lband == 0 ) { - en_fx = L_mac0(en_fx, X_fx.a_fx[0], X_fx.a_fx[0]); /* 2*X1.Q+1 */ + en_fx = L_mac0( en_fx, X_fx.a_fx[0], X_fx.a_fx[0] ); /* 2*X1.Q+1 */ } /* IF ((X_fx.lag_fx%2 == 0) && (hband == X_fx.upper_cut_off_freq_fx)) */ test(); - IF((s_and(X_fx.lag_fx, 1) == 0) && (hband == X_fx.upper_cut_off_freq_fx)) + IF( ( s_and( X_fx.lag_fx, 1 ) == 0 ) && ( hband == X_fx.upper_cut_off_freq_fx ) ) { #ifdef BASOP_NOGLOB - en_fx = L_mac0_o(en_fx, X_fx.a_fx[k], X_fx.a_fx[k], &Overflow); - en_fx = L_mac0_o(en_fx, X_fx.b_fx[k], X_fx.b_fx[k], &Overflow); + en_fx = L_mac0_o( en_fx, X_fx.a_fx[k], X_fx.a_fx[k], &Overflow ); + en_fx = L_mac0_o( en_fx, X_fx.b_fx[k], X_fx.b_fx[k], &Overflow ); #else - en_fx = L_mac0(en_fx, X_fx.a_fx[k], X_fx.a_fx[k]); - en_fx = L_mac0(en_fx, X_fx.b_fx[k], X_fx.b_fx[k]); + en_fx = L_mac0( en_fx, X_fx.a_fx[k], X_fx.a_fx[k] ); + en_fx = L_mac0( en_fx, X_fx.b_fx[k], X_fx.b_fx[k] ); #endif } - return en_fx; /* 2*X1.Q */ + return en_fx; /* 2*X1.Q */ } /*---------------------------------------------------------------------* * sc_vbr_enc_init_fx() @@ -1707,10 +1689,10 @@ void sc_vbr_enc_init_fx( hSC_VBR->Q_to_F = 0; move16(); - hSC_VBR->numactive = 0; /* keep the count of the frames inside current 600 frame bloack.*/ - hSC_VBR->sum_of_rates_fx = 0; /* sum of the rates of past 600 active frames*/ - hSC_VBR->global_avr_rate_fx = 0; /* global rate upto current time. recorded a (rate in kbps) *6000*/ - hSC_VBR->frame_cnt_ratewin_fx = 0; /* 600 active frame block count. Used to update the global rate*/ + hSC_VBR->numactive = 0; /* keep the count of the frames inside current 600 frame bloack.*/ + hSC_VBR->sum_of_rates_fx = 0; /* sum of the rates of past 600 active frames*/ + hSC_VBR->global_avr_rate_fx = 0; /* global rate upto current time. recorded a (rate in kbps) *6000*/ + hSC_VBR->frame_cnt_ratewin_fx = 0; /* 600 active frame block count. Used to update the global rate*/ hSC_VBR->rate_control = 0; move16(); hSC_VBR->SNR_THLD_fx = SNR_THLD_FX_Q8; @@ -1728,13 +1710,13 @@ void sc_vbr_enc_init_fx( hSC_VBR->last_7k2_coder_type = GENERIC; move16(); - set16_fx(hSC_VBR->shape1_filt_mem_fx, 0, 10); - set16_fx(hSC_VBR->shape2_filt_mem_fx, 0, 10); - set16_fx(hSC_VBR->shape3_filt_mem_fx, 0, 10); - set16_fx(hSC_VBR->txlpf1_filt1_mem_fx, 0, 10); - set16_fx(hSC_VBR->txlpf1_filt2_mem_fx, 0, 10); - set16_fx(hSC_VBR->txhpf1_filt1_mem_fx, 0, 10); - set16_fx(hSC_VBR->txhpf1_filt2_mem_fx, 0, 10); + set16_fx( hSC_VBR->shape1_filt_mem_fx, 0, 10 ); + set16_fx( hSC_VBR->shape2_filt_mem_fx, 0, 10 ); + set16_fx( hSC_VBR->shape3_filt_mem_fx, 0, 10 ); + set16_fx( hSC_VBR->txlpf1_filt1_mem_fx, 0, 10 ); + set16_fx( hSC_VBR->txlpf1_filt2_mem_fx, 0, 10 ); + set16_fx( hSC_VBR->txhpf1_filt1_mem_fx, 0, 10 ); + set16_fx( hSC_VBR->txhpf1_filt2_mem_fx, 0, 10 ); hSC_VBR->qprevIn_fx = 0; move16(); hSC_VBR->qprevGain_fx = 0; @@ -1742,4 +1724,3 @@ void sc_vbr_enc_init_fx( return; } - diff --git a/lib_enc/waveadjust_fec_cod_fx.c b/lib_enc/waveadjust_fec_cod_fx.c index 364a831f4..a42994223 100644 --- a/lib_enc/waveadjust_fec_cod_fx.c +++ b/lib_enc/waveadjust_fec_cod_fx.c @@ -3,15 +3,15 @@ ====================================================================================*/ #include -#include "options.h" /* for wmc_tool */ +#include "options.h" /* for wmc_tool */ #include "cnst.h" //#include "prot_fx.h" #include "rom_com_fx.h" #include "rom_com.h" #include "stat_com.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* * SFM_Cal_fx() @@ -19,71 +19,71 @@ * *--------------------------------------------------------------------*/ -Word32 SFM_Cal_fx(Word32 magn[], Word16 n) +Word32 SFM_Cal_fx( Word32 magn[], Word16 n ) { /* Counted Dymamic RAM: 16 words */ Word32 logCurFlatness; Word32 magn_abs, frac, logMagn, sumLogMagn, sumMagn; Word16 i, norm_value, logSumMagn, logn; - sumLogMagn = L_deposit_l(0); - sumMagn = L_deposit_l(0); - FOR(i = 0; i < n; i++) + sumLogMagn = L_deposit_l( 0 ); + sumMagn = L_deposit_l( 0 ); + FOR( i = 0; i < n; i++ ) { /* log2(magn(i)) */ - magn_abs = L_abs(magn[i]); - norm_value = norm_l(L_max(magn_abs, 1)); + magn_abs = L_abs( magn[i] ); + norm_value = norm_l( L_max( magn_abs, 1 ) ); /* next two codes lost precision. */ - frac = L_and(L_shr(L_shl(magn_abs, norm_value), 22), 0xFF); - logMagn = L_deposit_l(add(shl(sub(30, norm_value), 8), kLog2TableFrac_x[frac]));; /* Q8 */ + frac = L_and( L_shr( L_shl( magn_abs, norm_value ), 22 ), 0xFF ); + logMagn = L_deposit_l( add( shl( sub( 30, norm_value ), 8 ), kLog2TableFrac_x[frac] ) ); + ; /* Q8 */ /* sum(log2(magn(i))) */ - sumLogMagn =L_add(sumLogMagn, logMagn); /* Q8 */ + sumLogMagn = L_add( sumLogMagn, logMagn ); /* Q8 */ #ifdef BASOP_NOGLOB sumMagn = L_add_sat( sumMagn, magn_abs ); #else - sumMagn =L_add(sumMagn, magn_abs); + sumMagn = L_add( sumMagn, magn_abs ); #endif } - IF(EQ_32(sumMagn,MAX_32)) + IF( EQ_32( sumMagn, MAX_32 ) ) { - sumMagn = L_deposit_l(0); - FOR(i = 0; i < n; i++) + sumMagn = L_deposit_l( 0 ); + FOR( i = 0; i < n; i++ ) { - magn_abs = L_shr(L_abs(magn[i]), 8); - sumMagn = L_add(sumMagn, magn_abs); + magn_abs = L_shr( L_abs( magn[i] ), 8 ); + sumMagn = L_add( sumMagn, magn_abs ); } /* log2(sumMagn) */ - norm_value = norm_l(sumMagn); - frac = L_and(L_shr(L_shl(sumMagn, norm_value), 22), 0xFF); - logSumMagn = add(shl(sub(38,norm_value), 8), kLog2TableFrac_x[frac]); /* Q8 */ + norm_value = norm_l( sumMagn ); + frac = L_and( L_shr( L_shl( sumMagn, norm_value ), 22 ), 0xFF ); + logSumMagn = add( shl( sub( 38, norm_value ), 8 ), kLog2TableFrac_x[frac] ); /* Q8 */ } ELSE { /* log2(sumMagn) */ - norm_value = norm_l(sumMagn); - frac = L_and(L_shr(L_shl(sumMagn, norm_value), 22), 0xFF); - logSumMagn = add(shl(sub(30, norm_value), 8), kLog2TableFrac_x[frac]); /* Q8 */ + norm_value = norm_l( sumMagn ); + frac = L_and( L_shr( L_shl( sumMagn, norm_value ), 22 ), 0xFF ); + logSumMagn = add( shl( sub( 30, norm_value ), 8 ), kLog2TableFrac_x[frac] ); /* Q8 */ } /* log2(n) */ - norm_value = norm_l(n); - frac = L_and(L_shr(L_shl(n, norm_value), 22), 0xFF); - logn = add(shl(sub(30, norm_value), 8), kLog2TableFrac_x[frac]); /* Q8 */ + norm_value = norm_l( n ); + frac = L_and( L_shr( L_shl( n, norm_value ), 22 ), 0xFF ); + logn = add( shl( sub( 30, norm_value ), 8 ), kLog2TableFrac_x[frac] ); /* Q8 */ - logMagn=L_sub(L_mult0(n, sub(logSumMagn, logn)), sumLogMagn); - logMagn = (Word32)L_max(0, logMagn); + logMagn = L_sub( L_mult0( n, sub( logSumMagn, logn ) ), sumLogMagn ); + logMagn = (Word32) L_max( 0, logMagn ); - logCurFlatness = L_deposit_l(div_l(L_shl(logMagn, 1), n)); - frac = L_and(logCurFlatness, 0xFF); - norm_value = (Word16)L_shr(logCurFlatness, 8); + logCurFlatness = L_deposit_l( div_l( L_shl( logMagn, 1 ), n ) ); + frac = L_and( logCurFlatness, 0xFF ); + norm_value = (Word16) L_shr( logCurFlatness, 8 ); move16(); - logCurFlatness = L_sub(kExp2TableFrac_x[frac], 33); - logCurFlatness = L_shl(logCurFlatness, sub(16, norm_value)); /* Q31 */ + logCurFlatness = L_sub( kExp2TableFrac_x[frac], 33 ); + logCurFlatness = L_shl( logCurFlatness, sub( 16, norm_value ) ); /* Q31 */ return logCurFlatness; } - diff --git a/lib_rend/ivas_allrad_dec.c b/lib_rend/ivas_allrad_dec.c index e72dcf82e..62422fb03 100644 --- a/lib_rend/ivas_allrad_dec.c +++ b/lib_rend/ivas_allrad_dec.c @@ -164,7 +164,7 @@ ivas_error ivas_sba_get_hoa_dec_matrix( #define TEMP_VAL 1963413621 // Q37 (1.f / num_td) ivas_error ivas_sba_get_hoa_dec_matrix_fx( const IVAS_OUTPUT_SETUP hOutSetup, /* i : target output setup */ - Word32 **hoa_dec_mtx, /* o : ALLRAD decoder matrix */ + Word32 **hoa_dec_mtx, /* o : ALLRAD decoder matrix */ const Word16 ambisonics_order /* i : Ambisonics order */ ) { @@ -247,9 +247,9 @@ ivas_error ivas_sba_get_hoa_dec_matrix_fx( Word32 dec_mtx_temp = 0; FOR( k = 0; k < num_harm; k++ ) { - dec_mtx_temp = Mpy_32_32( G_td_int[j], Y_td_int[k] ); // Q27 + dec_mtx_temp = Mpy_32_32( G_td_int[j], Y_td_int[k] ); // Q27 *p_dec_mtx = L_add( *p_dec_mtx, L_shr( dec_mtx_temp, 2 ) ); // Q25 - //printf( "\n%f", ((float)*p_dec_mtx)/ ONE_IN_Q25 ); + // printf( "\n%f", ((float)*p_dec_mtx)/ ONE_IN_Q25 ); p_dec_mtx++; } p_dec_mtx += ( SBA_NHARM_HOA3 - num_harm ); @@ -264,7 +264,7 @@ ivas_error ivas_sba_get_hoa_dec_matrix_fx( FOR( j = 0; j < num_harm; j++ ) { dec_mtx_temp_scale = Mpy_32_32( tmp_val, norm_sn3d_hoa3_int[j] ); // Q35 - *p_dec_mtx = Mpy_32_32(*p_dec_mtx, dec_mtx_temp_scale); // Q29 + *p_dec_mtx = Mpy_32_32( *p_dec_mtx, dec_mtx_temp_scale ); // Q29 p_dec_mtx++; } p_dec_mtx += ( SBA_NHARM_HOA3 - num_harm ); @@ -281,4 +281,4 @@ ivas_error ivas_sba_get_hoa_dec_matrix_fx( return error; } -#endif \ No newline at end of file +#endif diff --git a/lib_rend/ivas_crend.c b/lib_rend/ivas_crend.c index ad97eeeae..b678a90f8 100644 --- a/lib_rend/ivas_crend.c +++ b/lib_rend/ivas_crend.c @@ -63,7 +63,7 @@ ivas_error ivas_hrtf_init( { Word16 i, j; - IF ( hHrtf == NULL ) + IF( hHrtf == NULL ) { return IVAS_ERR_WRONG_PARAMS; } @@ -79,11 +79,11 @@ ivas_error ivas_hrtf_init( move16(); move16(); - FOR ( i = 0; i < MAX_INTERN_CHANNELS; i++ ) + FOR( i = 0; i < MAX_INTERN_CHANNELS; i++ ) { hHrtf->inv_diffuse_weight_fx[i] = 0; move16(); - FOR ( j = 0; j < BINAURAL_CHANNELS; j++ ) + FOR( j = 0; j < BINAURAL_CHANNELS; j++ ) { hHrtf->num_iterations[i][j] = 0; move16(); @@ -93,7 +93,7 @@ ivas_error ivas_hrtf_init( } } - FOR ( j = 0; j < BINAURAL_CHANNELS; j++ ) + FOR( j = 0; j < BINAURAL_CHANNELS; j++ ) { hHrtf->num_iterations_diffuse[j] = 0; move16(); @@ -166,14 +166,14 @@ static ivas_error ivas_hrtf_open( HRTFS_HANDLE hHrtf; ivas_error error; - IF ( *hHrtf_out == NULL ) + IF( *hHrtf_out == NULL ) { - IF ( ( hHrtf = (HRTFS_HANDLE) malloc( sizeof( HRTFS_DATA ) ) ) == NULL ) + IF( ( hHrtf = (HRTFS_HANDLE) malloc( sizeof( HRTFS_DATA ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR decoder\n" ); } - IF ( ( error = ivas_hrtf_init( hHrtf ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_hrtf_init( hHrtf ) ) != IVAS_ERR_OK ) { return error; } @@ -273,15 +273,15 @@ static ivas_error ivas_rend_initCrend_fx( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Encountered unsupported output type in Crend" ); } - IF ( hHrtf == NULL ) + IF( hHrtf == NULL ) { - IF ( ivas_hrtf_open( &hHrtf ) != IVAS_ERR_OK ) + IF( ivas_hrtf_open( &hHrtf ) != IVAS_ERR_OK ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for HRTF handle" ); } } - IF ( ( error = getAudioConfigNumChannels( inConfig, &nchan_in ) ) != IVAS_ERR_OK ) + IF( ( error = getAudioConfigNumChannels( inConfig, &nchan_in ) ) != IVAS_ERR_OK ) { return error; } @@ -319,7 +319,7 @@ static ivas_error ivas_rend_initCrend_fx( move16(); move16(); - FOR ( j = 0; j < BINAURAL_CHANNELS; j++ ) + FOR( j = 0; j < BINAURAL_CHANNELS; j++ ) { IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) ) { @@ -659,7 +659,7 @@ static ivas_error ivas_rend_initCrend_fx( move16(); } } - ELSE IF( EQ_32(output_Fs , 16000) ) + ELSE IF( EQ_32( output_Fs, 16000 ) ) { hHrtf->latency_s_fx = CRendBin_HOA3_HRIR_latency_s_fx; hHrtf->max_num_iterations = CRendBin_HOA3_HRIR_max_num_iterations_16kHz; @@ -997,9 +997,9 @@ static ivas_error ivas_rend_initCrend_fx( move16(); move16(); - FOR ( j = 0; j < BINAURAL_CHANNELS; j++ ) + FOR( j = 0; j < BINAURAL_CHANNELS; j++ ) { - IF ( EQ_16(outConfig , IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR) ) + IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) ) { hHrtf->num_iterations_diffuse[j] = hSetOfHRTF->hHRTF_brir_combined->num_iterations_diffuse[j]; hHrtf->pIndex_frequency_max_diffuse[j] = hSetOfHRTF->hHRTF_brir_combined->pIndex_frequency_max_diffuse[j]; @@ -1021,25 +1021,25 @@ static ivas_error ivas_rend_initCrend_fx( move16(); } - FOR ( i = 0; i < hHrtf->max_num_ir; i++ ) + FOR( i = 0; i < hHrtf->max_num_ir; i++ ) { - IF ( EQ_16(inConfig , IVAS_AUDIO_CONFIG_5_1) ) + IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_5_1 ) ) { tmp = channelIndex_CICP6[i]; } - ELSE IF ( EQ_16(inConfig , IVAS_AUDIO_CONFIG_7_1) ) + ELSE IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_7_1 ) ) { tmp = channelIndex_CICP12[i]; } - ELSE IF ( EQ_16(inConfig , IVAS_AUDIO_CONFIG_5_1_2) ) + ELSE IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_5_1_2 ) ) { tmp = channelIndex_CICP14[i]; } - ELSE IF ( EQ_16(inConfig , IVAS_AUDIO_CONFIG_5_1_4) ) + ELSE IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_5_1_4 ) ) { tmp = channelIndex_CICP16[i]; } - ELSE IF ( EQ_16(inConfig , IVAS_AUDIO_CONFIG_7_1_4) ) + ELSE IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_7_1_4 ) ) { tmp = channelIndex_CICP19[i]; } @@ -1049,7 +1049,7 @@ static ivas_error ivas_rend_initCrend_fx( } move16(); - IF ( EQ_16(outConfig , IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR) ) + IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) ) { hHrtf->inv_diffuse_weight_fx[i] = hSetOfHRTF->hHRTF_brir_combined->inv_diffuse_weight_fx[tmp]; } @@ -1059,9 +1059,9 @@ static ivas_error ivas_rend_initCrend_fx( } move16(); - FOR ( j = 0; j < BINAURAL_CHANNELS; j++ ) + FOR( j = 0; j < BINAURAL_CHANNELS; j++ ) { - IF ( EQ_16(outConfig , IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR) ) + IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) ) { hHrtf->num_iterations[i][j] = hSetOfHRTF->hHRTF_brir_combined->num_iterations[tmp][j]; hHrtf->pIndex_frequency_max[i][j] = hSetOfHRTF->hHRTF_brir_combined->pIndex_frequency_max[tmp][j]; @@ -1084,9 +1084,9 @@ static ivas_error ivas_rend_initCrend_fx( } } } - ELSE IF( EQ_16( inConfigType , IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS) ) + ELSE IF( EQ_16( inConfigType, IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS ) ) { - IF ( EQ_16(inConfig , IVAS_AUDIO_CONFIG_HOA3) ) + IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_HOA3 ) ) { hHrtf->latency_s_fx = hSetOfHRTF->hHRTF_hrir_hoa3->latency_s_fx; hHrtf->max_num_iterations = hSetOfHRTF->hHRTF_hrir_hoa3->max_num_iterations; @@ -1095,12 +1095,12 @@ static ivas_error ivas_rend_initCrend_fx( move16(); move16(); - FOR ( i = 0; i < hHrtf->max_num_ir; i++ ) + FOR( i = 0; i < hHrtf->max_num_ir; i++ ) { hHrtf->inv_diffuse_weight_fx[i] = hSetOfHRTF->hHRTF_hrir_hoa3->inv_diffuse_weight_fx[i]; move16(); - FOR ( j = 0; j < BINAURAL_CHANNELS; j++ ) + FOR( j = 0; j < BINAURAL_CHANNELS; j++ ) { hHrtf->num_iterations[i][j] = hSetOfHRTF->hHRTF_hrir_hoa3->num_iterations[i][j]; hHrtf->pIndex_frequency_max[i][j] = hSetOfHRTF->hHRTF_hrir_hoa3->pIndex_frequency_max[i][j]; @@ -1113,7 +1113,7 @@ static ivas_error ivas_rend_initCrend_fx( move16(); } } - FOR ( j = 0; j < BINAURAL_CHANNELS; j++ ) + FOR( j = 0; j < BINAURAL_CHANNELS; j++ ) { hHrtf->num_iterations_diffuse[j] = hSetOfHRTF->hHRTF_hrir_hoa3->num_iterations_diffuse[j]; hHrtf->pIndex_frequency_max_diffuse[j] = hSetOfHRTF->hHRTF_hrir_hoa3->pIndex_frequency_max_diffuse[j]; @@ -1126,7 +1126,7 @@ static ivas_error ivas_rend_initCrend_fx( move16(); } } - ELSE IF ( EQ_16(inConfig , IVAS_AUDIO_CONFIG_HOA2) ) + ELSE IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_HOA2 ) ) { hHrtf->latency_s_fx = hSetOfHRTF->hHRTF_hrir_hoa2->latency_s_fx; hHrtf->max_num_iterations = hSetOfHRTF->hHRTF_hrir_hoa2->max_num_iterations; @@ -1135,12 +1135,12 @@ static ivas_error ivas_rend_initCrend_fx( move16(); move16(); - FOR ( i = 0; i < hHrtf->max_num_ir; i++ ) + FOR( i = 0; i < hHrtf->max_num_ir; i++ ) { hHrtf->inv_diffuse_weight_fx[i] = hSetOfHRTF->hHRTF_hrir_hoa2->inv_diffuse_weight_fx[i]; move16(); - FOR ( j = 0; j < BINAURAL_CHANNELS; j++ ) + FOR( j = 0; j < BINAURAL_CHANNELS; j++ ) { hHrtf->num_iterations[i][j] = hSetOfHRTF->hHRTF_hrir_hoa2->num_iterations[i][j]; hHrtf->pIndex_frequency_max[i][j] = hSetOfHRTF->hHRTF_hrir_hoa2->pIndex_frequency_max[i][j]; @@ -1153,7 +1153,7 @@ static ivas_error ivas_rend_initCrend_fx( move16(); } } - FOR ( j = 0; j < BINAURAL_CHANNELS; j++ ) + FOR( j = 0; j < BINAURAL_CHANNELS; j++ ) { hHrtf->num_iterations_diffuse[j] = hSetOfHRTF->hHRTF_hrir_hoa2->num_iterations_diffuse[j]; hHrtf->pIndex_frequency_max_diffuse[j] = hSetOfHRTF->hHRTF_hrir_hoa2->pIndex_frequency_max_diffuse[j]; @@ -1166,7 +1166,7 @@ static ivas_error ivas_rend_initCrend_fx( move16(); } } - ELSE IF ( EQ_16(inConfig , IVAS_AUDIO_CONFIG_FOA) ) + ELSE IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_FOA ) ) { hHrtf->latency_s_fx = hSetOfHRTF->hHRTF_hrir_foa->latency_s_fx; hHrtf->max_num_iterations = hSetOfHRTF->hHRTF_hrir_foa->max_num_iterations; @@ -1175,12 +1175,12 @@ static ivas_error ivas_rend_initCrend_fx( move16(); move16(); - FOR ( i = 0; i < hHrtf->max_num_ir; i++ ) + FOR( i = 0; i < hHrtf->max_num_ir; i++ ) { hHrtf->inv_diffuse_weight_fx[i] = hSetOfHRTF->hHRTF_hrir_foa->inv_diffuse_weight_fx[i]; move16(); - FOR ( j = 0; j < BINAURAL_CHANNELS; j++ ) + FOR( j = 0; j < BINAURAL_CHANNELS; j++ ) { hHrtf->num_iterations[i][j] = hSetOfHRTF->hHRTF_hrir_foa->num_iterations[i][j]; hHrtf->pIndex_frequency_max[i][j] = hSetOfHRTF->hHRTF_hrir_foa->pIndex_frequency_max[i][j]; @@ -1193,7 +1193,7 @@ static ivas_error ivas_rend_initCrend_fx( move16(); } } - FOR ( j = 0; j < BINAURAL_CHANNELS; j++ ) + FOR( j = 0; j < BINAURAL_CHANNELS; j++ ) { hHrtf->num_iterations_diffuse[j] = hSetOfHRTF->hHRTF_hrir_foa->num_iterations_diffuse[j]; hHrtf->pIndex_frequency_max_diffuse[j] = hSetOfHRTF->hHRTF_hrir_foa->pIndex_frequency_max_diffuse[j]; @@ -1973,17 +1973,17 @@ static ivas_error ivas_shoebox_data_init( { Word16 i; - IF ( hShoeboxData == NULL ) + IF( hShoeboxData == NULL ) { return IVAS_ERR_WRONG_PARAMS; } - FOR ( i = 0; i < 150; i++ ) + FOR( i = 0; i < 150; i++ ) { hShoeboxData->data_fx[i] = 0; move32(); } - FOR ( i = 0; i < 1; i++ ) + FOR( i = 0; i < 1; i++ ) { hShoeboxData->size[i] = 0; move16(); @@ -2028,7 +2028,7 @@ static ivas_error ivas_shoebox_output_init( { ivas_error error; - IF ( hShoeboxOutput == NULL ) + IF( hShoeboxOutput == NULL ) { return IVAS_ERR_WRONG_PARAMS; } @@ -2036,22 +2036,22 @@ static ivas_error ivas_shoebox_output_init( hShoeboxOutput->n_sources = 0; hShoeboxOutput->n_ref = 0; - IF ( ( error = ivas_shoebox_data_init( &hShoeboxOutput->times ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_shoebox_data_init( &hShoeboxOutput->times ) ) != IVAS_ERR_OK ) { return error; } - IF ( ( error = ivas_shoebox_data_init( &hShoeboxOutput->gains ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_shoebox_data_init( &hShoeboxOutput->gains ) ) != IVAS_ERR_OK ) { return error; } - IF ( ( error = ivas_shoebox_data_init( &hShoeboxOutput->az_angle ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_shoebox_data_init( &hShoeboxOutput->az_angle ) ) != IVAS_ERR_OK ) { return error; } - IF ( ( error = ivas_shoebox_data_init( &hShoeboxOutput->el_angle ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_shoebox_data_init( &hShoeboxOutput->el_angle ) ) != IVAS_ERR_OK ) { return error; } @@ -2112,7 +2112,7 @@ static ivas_error ivas_shoebox_config_init_params( { Word16 i; - IF ( hShoeboxConfig == NULL ) + IF( hShoeboxConfig == NULL ) { return IVAS_ERR_WRONG_PARAMS; } @@ -2123,7 +2123,7 @@ static ivas_error ivas_shoebox_config_init_params( move32(); move32(); move32(); - FOR ( i = 0; i < IVAS_ROOM_ABS_COEFF; i++ ) + FOR( i = 0; i < IVAS_ROOM_ABS_COEFF; i++ ) { hShoeboxConfig->abs_coeff_fx[i] = 0; move32(); @@ -2179,7 +2179,7 @@ static ivas_error ivas_shoebox_obj_init( Word16 i; ivas_error error; - IF ( hShoeboxObj == NULL ) + IF( hShoeboxObj == NULL ) { return IVAS_ERR_WRONG_PARAMS; } @@ -2198,12 +2198,12 @@ static ivas_error ivas_shoebox_obj_init( move16(); move16(); move16(); - FOR ( i = 0; i < 75; i++ ) + FOR( i = 0; i < 75; i++ ) { hShoeboxObj->src_pos_fx[i] = 0; move32(); } - FOR ( i = 0; i < 25; i++ ) + FOR( i = 0; i < 25; i++ ) { hShoeboxObj->src_dist_fx[i] = 0; move32(); @@ -2225,7 +2225,7 @@ static ivas_error ivas_shoebox_obj_init( move32(); move32(); - IF ( ( error = ivas_shoebox_config_init_params( &hShoeboxObj->cal ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_shoebox_config_init_params( &hShoeboxObj->cal ) ) != IVAS_ERR_OK ) { return error; } @@ -2295,7 +2295,7 @@ static ivas_error ivas_er_init_handle( { Word16 i; ivas_error error; - IF ( reflections == NULL ) + IF( reflections == NULL ) { return IVAS_ERR_WRONG_PARAMS; } @@ -2317,29 +2317,29 @@ static ivas_error ivas_er_init_handle( move16(); move32(); move32(); - FOR ( i = 0; i < 75; i++ ) + FOR( i = 0; i < 75; i++ ) { reflections->source_positions_fx[i] = 0; move16(); } - FOR ( i = 0; i < 3; i++ ) + FOR( i = 0; i < 3; i++ ) { reflections->user_origin_fx[i] = 0; move16(); - IF ( EQ_16(i , 2) ) + IF( EQ_16( i, 2 ) ) { - reflections->user_origin_fx[i] = (Word32)ER_LIST_HEIGHT_FX; + reflections->user_origin_fx[i] = (Word32) ER_LIST_HEIGHT_FX; move16(); } } reflections->circ_buffers = NULL; reflections->closest_ch_idx = NULL; - IF ( ( error = ivas_shoebox_output_init( &reflections->shoebox_data ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_shoebox_output_init( &reflections->shoebox_data ) ) != IVAS_ERR_OK ) { return error; } - IF ( ( error = ivas_shoebox_obj_init( &reflections->shoebox_lib ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_shoebox_obj_init( &reflections->shoebox_lib ) ) != IVAS_ERR_OK ) { return error; } @@ -2412,12 +2412,12 @@ ivas_error ivas_rend_initCrendWrapper( Word16 i; CREND_HANDLE hCrend; - IF ( pCrend == NULL ) + IF( pCrend == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for renderer handle" ); } - IF ( ( *pCrend = (CREND_WRAPPER_HANDLE) malloc( sizeof( CREND_WRAPPER ) ) ) == NULL ) + IF( ( *pCrend = (CREND_WRAPPER_HANDLE) malloc( sizeof( CREND_WRAPPER ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend Wrapper\n" ); } @@ -2428,20 +2428,20 @@ ivas_error ivas_rend_initCrendWrapper( { hCrend = NULL; - IF ( ( hCrend = (CREND_HANDLE) malloc( sizeof( CREND_DATA ) ) ) == NULL ) + IF( ( hCrend = (CREND_HANDLE) malloc( sizeof( CREND_DATA ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for renderer handle" ); } hCrend->lfe_delay_line_fx = NULL; - FOR ( i = 0; i < MAX_INTERN_CHANNELS; i++ ) + FOR( i = 0; i < MAX_INTERN_CHANNELS; i++ ) { hCrend->freq_buffer_re_fx[i] = NULL; hCrend->freq_buffer_im_fx[i] = NULL; } - FOR ( i = 0; i < BINAURAL_CHANNELS; i++ ) + FOR( i = 0; i < BINAURAL_CHANNELS; i++ ) { hCrend->prev_out_buffer_fx[i] = NULL; } @@ -2556,142 +2556,140 @@ ivas_error ivas_rend_openCrend( error = IVAS_ERR_OK; - IF ( ( error = ivas_rend_initCrendWrapper( pCrend ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_rend_initCrendWrapper( pCrend ) ) != IVAS_ERR_OK ) { return error; } - subframe_length = extract_l(Mult_32_16( output_Fs , 164));/*( output_Fs / FRAMES_PER_SEC ) / MAX_PARAM_SPATIAL_SUBFRAMES(i/o:164=(32768/FRAMES_PER_SEC)/MAX_PARAM_SPATIAL_SUBFRAMES*/ + subframe_length = extract_l( Mult_32_16( output_Fs, 164 ) ); /*( output_Fs / FRAMES_PER_SEC ) / MAX_PARAM_SPATIAL_SUBFRAMES(i/o:164=(32768/FRAMES_PER_SEC)/MAX_PARAM_SPATIAL_SUBFRAMES*/ - IF ( ( *pCrend )->hHrtfCrend == NULL ) - { - IF ( ( error = ivas_rend_initCrend_fx( *pCrend, inConfig, outConfig, hSetOfHRTF, output_Fs ) ) != IVAS_ERR_OK ) - { + IF( ( *pCrend )->hHrtfCrend == NULL ){ + IF( ( error = ivas_rend_initCrend_fx( *pCrend, inConfig, outConfig, hSetOfHRTF, output_Fs ) ) != IVAS_ERR_OK ){ return error; - } - } +} +} + +{ + hCrend = ( *pCrend )->hCrend; + hHrtf = ( *pCrend )->hHrtfCrend; + IF( hHrtf != NULL ) { - hCrend = ( *pCrend )->hCrend; - hHrtf = ( *pCrend )->hHrtfCrend; + max_total_ir_len = imult1616( hHrtf->max_num_iterations, subframe_length ); - IF ( hHrtf != NULL ) + FOR( i = 0; i < hHrtf->max_num_ir; i++ ) { - max_total_ir_len = imult1616(hHrtf->max_num_iterations , subframe_length); - - FOR ( i = 0; i < hHrtf->max_num_ir; i++ ) + IF( ( hCrend->freq_buffer_re_fx[i] = (Word32 *) malloc( sizeof( Word32 ) * max_total_ir_len ) ) == NULL ) { - IF ( ( hCrend->freq_buffer_re_fx[i] = (Word32 *) malloc( sizeof( Word32 ) * max_total_ir_len ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend" ); - } - set_zero_fx( hCrend->freq_buffer_re_fx[i], max_total_ir_len ); - IF ( ( hCrend->freq_buffer_im_fx[i] = (Word32 *) malloc( sizeof( Word32 ) * max_total_ir_len ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend" ); - } - set_zero_fx( hCrend->freq_buffer_im_fx[i], max_total_ir_len ); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend" ); + } + set_zero_fx( hCrend->freq_buffer_re_fx[i], max_total_ir_len ); + IF( ( hCrend->freq_buffer_im_fx[i] = (Word32 *) malloc( sizeof( Word32 ) * max_total_ir_len ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend" ); } + set_zero_fx( hCrend->freq_buffer_im_fx[i], max_total_ir_len ); + } - FOR ( i = 0; i < BINAURAL_CHANNELS; i++ ) + FOR( i = 0; i < BINAURAL_CHANNELS; i++ ) + { + IF( ( hCrend->prev_out_buffer_fx[i] = (Word32 *) malloc( sizeof( Word32 ) * subframe_length ) ) == NULL ) { - IF ( ( hCrend->prev_out_buffer_fx[i] = (Word32 *) malloc( sizeof( Word32 ) * subframe_length ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend" ); - } - set_zero_fx( hCrend->prev_out_buffer_fx[i], subframe_length ); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend" ); } + set_zero_fx( hCrend->prev_out_buffer_fx[i], subframe_length ); + } - max_total_ir_len = imult1616((Word16)hHrtf->num_iterations_diffuse[0] , subframe_length); + max_total_ir_len = imult1616( (Word16) hHrtf->num_iterations_diffuse[0], subframe_length ); - IF ( GT_16(max_total_ir_len , 0) ) + IF( GT_16( max_total_ir_len, 0 ) ) + { + IF( ( hCrend->freq_buffer_re_diffuse_fx = (Word32 *) malloc( sizeof( Word32 ) * max_total_ir_len ) ) == NULL ) { - IF ( ( hCrend->freq_buffer_re_diffuse_fx = (Word32 *) malloc( sizeof( Word32 ) * max_total_ir_len ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend" ); - } - set_zero_fx( hCrend->freq_buffer_re_diffuse_fx,max_total_ir_len ); - IF ( ( hCrend->freq_buffer_im_diffuse_fx = (Word32 *) malloc( sizeof( Word32 ) * max_total_ir_len ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend" ); - } - set_zero_fx( hCrend->freq_buffer_im_diffuse_fx,max_total_ir_len ); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend" ); } - ELSE + set_zero_fx( hCrend->freq_buffer_re_diffuse_fx, max_total_ir_len ); + IF( ( hCrend->freq_buffer_im_diffuse_fx = (Word32 *) malloc( sizeof( Word32 ) * max_total_ir_len ) ) == NULL ) { - hCrend->freq_buffer_re_diffuse_fx = NULL; - hCrend->freq_buffer_im_diffuse_fx = NULL; + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend" ); } + set_zero_fx( hCrend->freq_buffer_im_diffuse_fx, max_total_ir_len ); + } + ELSE + { + hCrend->freq_buffer_re_diffuse_fx = NULL; + hCrend->freq_buffer_im_diffuse_fx = NULL; + } - max_total_ir_len = add(extract_l(L_shr(L_add(L_shl(Mult_32_32(hHrtf->latency_s_fx , output_Fs),1) , 1) ,1)) , subframe_length);/*(int16_t) ( hHrtf->latency_s * output_Fs + 0.5f ) + subframe_length;*/ - IF ( GT_16(max_total_ir_len , 0) ) + max_total_ir_len = add( extract_l( L_shr( L_add( L_shl( Mult_32_32( hHrtf->latency_s_fx, output_Fs ), 1 ), 1 ), 1 ) ), subframe_length ); /*(int16_t) ( hHrtf->latency_s * output_Fs + 0.5f ) + subframe_length;*/ + IF( GT_16( max_total_ir_len, 0 ) ) + { + IF( ( hCrend->lfe_delay_line_fx = (Word32 *) malloc( sizeof( Word32 ) * max_total_ir_len ) ) == NULL ) { - IF ( ( hCrend->lfe_delay_line_fx = (Word32 *) malloc( sizeof(Word32) * max_total_ir_len ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend" ); - } - set_zero_fx( hCrend->lfe_delay_line_fx, max_total_ir_len ); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend" ); } - ELSE + set_zero_fx( hCrend->lfe_delay_line_fx, max_total_ir_len ); + } + ELSE + { + hCrend->lfe_delay_line_fx = NULL; + } + + IF( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) + { + IF( ( error = ivas_reverb_open_fx( &( hCrend->hReverb ), inConfig, ( *pCrend )->hHrtfCrend, NULL, hRendCfg, output_Fs ) ) != IVAS_ERR_OK ) { - hCrend->lfe_delay_line_fx = NULL; + return error; } - IF ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) + IF( EQ_16( hRendCfg->roomAcoustics.use_er, 1 ) ) { - IF ( ( error = ivas_reverb_open_fx( &( hCrend->hReverb ), inConfig, ( *pCrend )->hHrtfCrend,NULL, hRendCfg, output_Fs ) ) != IVAS_ERR_OK ) + + /* Allocate memory for reflections */ + hCrend->reflections = (er_struct_t *) malloc( sizeof( er_struct_t ) ); + IF( !hCrend->reflections ) { - return error; + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Early Reflections" ); } - - IF ( EQ_16(hRendCfg->roomAcoustics.use_er , 1) ) + IF( ( error = ivas_er_init_handle( hCrend->reflections ) ) != IVAS_ERR_OK ) { + return error; + } - /* Allocate memory for reflections */ - hCrend->reflections = (er_struct_t *) malloc( sizeof( er_struct_t ) ); - IF ( !hCrend->reflections ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Early Reflections" ); - } - IF ( ( error = ivas_er_init_handle( hCrend->reflections ) ) != IVAS_ERR_OK ) - { - return error; - } - - hCrend->reflections->use_er = hRendCfg->roomAcoustics.use_er; - hCrend->reflections->lowComplexity = hRendCfg->roomAcoustics.lowComplexity; + hCrend->reflections->use_er = hRendCfg->roomAcoustics.use_er; + hCrend->reflections->lowComplexity = hRendCfg->roomAcoustics.lowComplexity; - /* Set sample rate and frame size */ + /* Set sample rate and frame size */ - hCrend->reflections->output_Fs_fx = (Word32) output_Fs; + hCrend->reflections->output_Fs_fx = (Word32) output_Fs; - hCrend->reflections->max_frame_size = extract_l(Mult_32_16( output_Fs , INV_FRAME_PER_SEC_Q15)); + hCrend->reflections->max_frame_size = extract_l( Mult_32_16( output_Fs, INV_FRAME_PER_SEC_Q15 ) ); - /* Init Shoebox */ - ivas_shoebox_config_init( &hCrend->reflections->shoebox_lib.cal, hRendCfg ); + /* Init Shoebox */ + ivas_shoebox_config_init( &hCrend->reflections->shoebox_lib.cal, hRendCfg ); - /* Init and compute Reflections */ - IF ( ( error = ivas_er_init( hCrend->reflections, inConfig ) ) != IVAS_ERR_OK ) - { - return error; - } - } - ELSE + /* Init and compute Reflections */ + IF( ( error = ivas_er_init( hCrend->reflections, inConfig ) ) != IVAS_ERR_OK ) { - hCrend->reflections = NULL; + return error; } } ELSE { - hCrend->hReverb = NULL; + hCrend->reflections = NULL; } - - ( *pCrend )->binaural_latency_ns = Mult_32_32( ( *pCrend )->hHrtfCrend->latency_s_fx , (Word32)1000000000 ); + } + ELSE + { + hCrend->hReverb = NULL; } - ( *pCrend )->hCrend = hCrend; + ( *pCrend )->binaural_latency_ns = Mult_32_32( ( *pCrend )->hHrtfCrend->latency_s_fx, (Word32) 1000000000 ); } - return IVAS_ERR_OK; + + ( *pCrend )->hCrend = hCrend; +} +return IVAS_ERR_OK; } /*------------------------------------------------------------------------- @@ -2706,37 +2704,37 @@ void ivas_rend_closeCrend( Word16 i; CREND_HANDLE hCrend; - IF ( pCrend == NULL || *pCrend == NULL ) + IF( pCrend == NULL || *pCrend == NULL ) { return; } - IF ( ( *pCrend )->hHrtfCrend != NULL ) + IF( ( *pCrend )->hHrtfCrend != NULL ) { ivas_hrtf_close( &( *pCrend )->hHrtfCrend ); } { hCrend = ( *pCrend )->hCrend; - IF ( hCrend != NULL ) + IF( hCrend != NULL ) { - FOR ( i = 0; i < MAX_INTERN_CHANNELS; i++ ) + FOR( i = 0; i < MAX_INTERN_CHANNELS; i++ ) { - IF ( hCrend->freq_buffer_re_fx[i] != NULL ) + IF( hCrend->freq_buffer_re_fx[i] != NULL ) { free( hCrend->freq_buffer_re_fx[i] ); hCrend->freq_buffer_re_fx[i] = NULL; } - IF ( hCrend->freq_buffer_im_fx[i] != NULL ) + IF( hCrend->freq_buffer_im_fx[i] != NULL ) { free( hCrend->freq_buffer_im_fx[i] ); hCrend->freq_buffer_im_fx[i] = NULL; } } - FOR ( i = 0; i < BINAURAL_CHANNELS; i++ ) + FOR( i = 0; i < BINAURAL_CHANNELS; i++ ) { - IF ( hCrend->prev_out_buffer_fx[i] != NULL ) + IF( hCrend->prev_out_buffer_fx[i] != NULL ) { free( hCrend->prev_out_buffer_fx[i] ); hCrend->prev_out_buffer_fx[i] = NULL; @@ -2744,30 +2742,30 @@ void ivas_rend_closeCrend( } #ifdef IVAS_FLOAT_FIXED_s - IF ( hCrend->lfe_delay_line_fx != NULL ) + IF( hCrend->lfe_delay_line_fx != NULL ) { free( hCrend->lfe_delay_line_fx ); hCrend->lfe_delay_line_fx = NULL; } #endif - IF ( hCrend->lfe_delay_line_fx != NULL ) + IF( hCrend->lfe_delay_line_fx != NULL ) { - free( hCrend->lfe_delay_line_fx); + free( hCrend->lfe_delay_line_fx ); hCrend->lfe_delay_line_fx = NULL; } - IF ( hCrend->freq_buffer_re_diffuse_fx != NULL ) + IF( hCrend->freq_buffer_re_diffuse_fx != NULL ) { free( hCrend->freq_buffer_re_diffuse_fx ); hCrend->freq_buffer_re_diffuse_fx = NULL; } - IF ( hCrend->freq_buffer_im_diffuse_fx != NULL ) + IF( hCrend->freq_buffer_im_diffuse_fx != NULL ) { free( hCrend->freq_buffer_im_diffuse_fx ); hCrend->freq_buffer_im_diffuse_fx = NULL; } - IF ( hCrend->hTrack != NULL ) + IF( hCrend->hTrack != NULL ) { free( hCrend->hTrack ); hCrend->hTrack = NULL; @@ -2775,14 +2773,14 @@ void ivas_rend_closeCrend( ivas_reverb_close( &hCrend->hReverb ); - IF ( hCrend->reflections != NULL ) + IF( hCrend->reflections != NULL ) { - IF ( hCrend->reflections->closest_ch_idx != NULL ) + IF( hCrend->reflections->closest_ch_idx != NULL ) { free( hCrend->reflections->closest_ch_idx ); hCrend->reflections->closest_ch_idx = NULL; } - IF ( hCrend->reflections->circ_buffers != NULL ) + IF( hCrend->reflections->circ_buffers != NULL ) { free( hCrend->reflections->circ_buffers ); hCrend->reflections->circ_buffers = NULL; @@ -3101,24 +3099,24 @@ static ivas_error ivas_rend_crendConvolver( hCrend = pCrend->hCrend; - IF ( NE_32( ( error = getAudioConfigNumChannels( inConfig, &nchan_in ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = getAudioConfigNumChannels( inConfig, &nchan_in ) ), IVAS_ERR_OK ) ) { return error; } - IF ( NE_32( ( error = getAudioConfigNumChannels( outConfig, &nchan_out ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = getAudioConfigNumChannels( outConfig, &nchan_out ) ), IVAS_ERR_OK ) ) { return error; } subframe_length = (Word16) BASOP_Util_Divide3232_Scale( output_Fs, FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES, &scale ); - subframe_length = shr(subframe_length, 15 - scale); + subframe_length = shr( subframe_length, 15 - scale ); lfe_idx_in = -1; move16(); - IF ( EQ_32( getAudioConfigType( inConfig ), IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED ) ) + IF( EQ_32( getAudioConfigType( inConfig ), IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED ) ) { - IF ( NE_32( inConfig, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) + IF( NE_32( inConfig, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) { lfe_idx_in = LFE_CHANNEL; move16(); @@ -3129,10 +3127,10 @@ static ivas_error ivas_rend_crendConvolver( } } - offset = imult1616( hCrend->delay_line_rw_index, subframe_length ); /* subframe_length * ( pCrend->hHrtfCrend->max_num_iterations - 1 ); */ + offset = imult1616( hCrend->delay_line_rw_index, subframe_length ); /* subframe_length * ( pCrend->hHrtfCrend->max_num_iterations - 1 ); */ offset_diffuse = hCrend->diffuse_delay_line_rw_index * subframe_length; /* subframe_length *( pCrend->hHrtfCrend->num_iterations_diffuse[0] - 1 ); */ - IF ( pCrend->hHrtfCrend->num_iterations_diffuse[0] > 0 ) + IF( pCrend->hHrtfCrend->num_iterations_diffuse[0] > 0 ) { set_val_Word32( &hCrend->freq_buffer_re_diffuse_fx[offset_diffuse], 0, subframe_length ); set_val_Word32( &hCrend->freq_buffer_im_diffuse_fx[offset_diffuse], 0, subframe_length ); @@ -3140,19 +3138,19 @@ static ivas_error ivas_rend_crendConvolver( i = 0; move16(); - FOR ( idx_in = 0; idx_in < nchan_in; idx_in++ ) + FOR( idx_in = 0; idx_in < nchan_in; idx_in++ ) { pIn = &pcm_in[idx_in][i_ts * subframe_length]; - IF ( idx_in != lfe_idx_in ) + IF( idx_in != lfe_idx_in ) { - IF ( pCrend->hHrtfCrend->num_iterations_diffuse[0] > 0 ) + IF( pCrend->hHrtfCrend->num_iterations_diffuse[0] > 0 ) { pFreq_buf_re = &hCrend->freq_buffer_re_diffuse_fx[offset_diffuse]; pFreq_buf_im = &hCrend->freq_buffer_im_diffuse_fx[offset_diffuse]; pFreq_filt_re = &hCrend->freq_buffer_re_fx[i][offset]; pFreq_filt_im = &hCrend->freq_buffer_im_fx[i][offset]; - FOR ( k = 0; k < pCrend->hHrtfCrend->index_frequency_max_diffuse; k++ ) + FOR( k = 0; k < pCrend->hHrtfCrend->index_frequency_max_diffuse; k++ ) { pFreq_buf_re[k] = L_add( Mpy_32_16_r( pFreq_filt_re[k], pCrend->hHrtfCrend->inv_diffuse_weight_fx[i] ), pFreq_buf_re[k] ); pFreq_buf_im[k] = L_add( Mpy_32_16_r( pFreq_filt_im[k], pCrend->hHrtfCrend->inv_diffuse_weight_fx[i] ), pFreq_buf_im[k] ); @@ -3171,21 +3169,21 @@ static ivas_error ivas_rend_crendConvolver( } } - FOR ( j = 0; j < nchan_out; j++ ) + FOR( j = 0; j < nchan_out; j++ ) { set_val_Word32( tmp_out_re, 0, subframe_length ); set_val_Word32( tmp_out_im, 0, subframe_length ); i = 0; move16(); - FOR ( idx_in = 0; idx_in < nchan_in; idx_in++ ) + FOR( idx_in = 0; idx_in < nchan_in; idx_in++ ) { - IF ( NE_16( idx_in, lfe_idx_in ) ) + IF( NE_16( idx_in, lfe_idx_in ) ) { offset = 0; move16(); - FOR ( m = 0; m < pCrend->hHrtfCrend->num_iterations[i][j]; m++ ) + FOR( m = 0; m < pCrend->hHrtfCrend->num_iterations[i][j]; m++ ) { - offset_in = add( add( hCrend->delay_line_rw_index, sub( pCrend->hHrtfCrend->max_num_iterations, pCrend->hHrtfCrend->num_iterations[i][j] ) ), add( m, 1 )); + offset_in = add( add( hCrend->delay_line_rw_index, sub( pCrend->hHrtfCrend->max_num_iterations, pCrend->hHrtfCrend->num_iterations[i][j] ) ), add( m, 1 ) ); offset_in = offset_in % ( pCrend->hHrtfCrend->max_num_iterations ); offset_in = imult1616( offset_in, subframe_length ); pFreq_buf_re = &hCrend->freq_buffer_re_fx[i][offset_in]; @@ -3193,7 +3191,7 @@ static ivas_error ivas_rend_crendConvolver( pFreq_filt_re = &pCrend->hHrtfCrend->pOut_to_bin_re_fx[i][j][offset]; pFreq_filt_im = &pCrend->hHrtfCrend->pOut_to_bin_im_fx[i][j][offset]; - FOR ( k = 0; k < pCrend->hHrtfCrend->pIndex_frequency_max[i][j][m]; k++ ) + FOR( k = 0; k < pCrend->hHrtfCrend->pIndex_frequency_max[i][j][m]; k++ ) { tmp_out_re[k] = L_add( Msub_32_32( Mpy_32_32( pFreq_buf_re[k], pFreq_filt_re[k] ), pFreq_buf_im[k], pFreq_filt_im[k] ) << 2, tmp_out_re[k] ); tmp_out_im[k] = L_add( Madd_32_32( Mpy_32_32( pFreq_buf_re[k], pFreq_filt_im[k] ), pFreq_buf_im[k], pFreq_filt_re[k] ) << 2, tmp_out_im[k] ); @@ -3206,7 +3204,7 @@ static ivas_error ivas_rend_crendConvolver( offset = 0; move16(); - FOR ( m = 0; m < pCrend->hHrtfCrend->num_iterations_diffuse[j]; m++ ) + FOR( m = 0; m < pCrend->hHrtfCrend->num_iterations_diffuse[j]; m++ ) { offset_diffuse = add( hCrend->diffuse_delay_line_rw_index, add( m, 1 ) ); offset_diffuse = offset_diffuse % pCrend->hHrtfCrend->num_iterations_diffuse[0]; @@ -3215,7 +3213,7 @@ static ivas_error ivas_rend_crendConvolver( pFreq_buf_im = &hCrend->freq_buffer_im_diffuse_fx[offset_diffuse]; pFreq_filt_re = &pCrend->hHrtfCrend->pOut_to_bin_diffuse_re_fx[j][offset]; pFreq_filt_im = &pCrend->hHrtfCrend->pOut_to_bin_diffuse_im_fx[j][offset]; - FOR ( k = 0; k < pCrend->hHrtfCrend->pIndex_frequency_max_diffuse[j][m]; k++ ) + FOR( k = 0; k < pCrend->hHrtfCrend->pIndex_frequency_max_diffuse[j][m]; k++ ) { tmp_out_re[k] = L_add( Msub_32_32( Mpy_32_32( pFreq_buf_re[k], pFreq_filt_re[k] ), pFreq_buf_im[k], pFreq_filt_im[k] ), tmp_out_re[k] ); tmp_out_im[k] = L_add( Madd_32_32( Mpy_32_32( pFreq_buf_re[k], pFreq_filt_im[k] ), pFreq_buf_im[k], pFreq_filt_re[k] ), tmp_out_im[k] ); @@ -3229,7 +3227,7 @@ static ivas_error ivas_rend_crendConvolver( dbgwrite_txt( pOut, subframe_length << 1, "Fixed_imdft_out.txt", NULL ); #endif pFreq_buf_re = &pcm_out[j][i_ts * subframe_length]; - FOR ( k = 0; k < subframe_length; k++ ) + FOR( k = 0; k < subframe_length; k++ ) { pFreq_buf_re[k] = L_add( pOut[k], hCrend->prev_out_buffer_fx[j][k] ); hCrend->prev_out_buffer_fx[j][k] = pOut[k + subframe_length]; @@ -3238,9 +3236,9 @@ static ivas_error ivas_rend_crendConvolver( hCrend->delay_line_rw_index = add( hCrend->delay_line_rw_index, 1 ); hCrend->delay_line_rw_index = hCrend->delay_line_rw_index % ( pCrend->hHrtfCrend->max_num_iterations ); - IF ( pCrend->hHrtfCrend->num_iterations_diffuse[0] > 0 ) + IF( pCrend->hHrtfCrend->num_iterations_diffuse[0] > 0 ) { - hCrend->diffuse_delay_line_rw_index = add( hCrend->diffuse_delay_line_rw_index, 1); + hCrend->diffuse_delay_line_rw_index = add( hCrend->diffuse_delay_line_rw_index, 1 ); hCrend->diffuse_delay_line_rw_index = hCrend->diffuse_delay_line_rw_index % ( pCrend->hHrtfCrend->num_iterations_diffuse[0] ); } @@ -3433,13 +3431,13 @@ ivas_error ivas_rend_crendProcess( COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, IVAS_OUTPUT_SETUP_HANDLE hIntSetup, EFAP_HANDLE hEFAPdata, - Word32 *output_fx[], /* i/o: input/output audio channels */ + Word32 *output_fx[], /* i/o: input/output audio channels */ const Word32 output_Fs, const Word16 num_subframes /* i : number of subframes to render */ ) { Word16 i, subframe_idx, subframe_len; - Word16 nchan_out; + Word16 nchan_out; Word32 pcm_tmp_fx[BINAURAL_CHANNELS][L_FRAME48k]; Word32 *p_pcm_tmp_fx[BINAURAL_CHANNELS]; IVAS_REND_AudioConfigType inConfigType; @@ -3450,11 +3448,11 @@ ivas_error ivas_rend_crendProcess( hCrend = pCrend->hCrend; combinedOrientationEnabled = 0; - IF ( hCombinedOrientationData != NULL ) + IF( hCombinedOrientationData != NULL ) { - FOR ( subframe_idx = 0; subframe_idx < num_subframes; subframe_idx++ ) + FOR( subframe_idx = 0; subframe_idx < num_subframes; subframe_idx++ ) { - IF( NE_16(hCombinedOrientationData->enableCombinedOrientation[subframe_idx] , 0) ) + IF( NE_16( hCombinedOrientationData->enableCombinedOrientation[subframe_idx], 0 ) ) { combinedOrientationEnabled = 1; BREAK; @@ -3465,7 +3463,7 @@ ivas_error ivas_rend_crendProcess( push_wmops( "ivas_rend_crendProcess" ); inConfigType = getAudioConfigType( inConfig ); - IF ( ( error = getAudioConfigNumChannels( outConfig, &nchan_out ) ) != IVAS_ERR_OK ) + IF( ( error = getAudioConfigNumChannels( outConfig, &nchan_out ) ) != IVAS_ERR_OK ) { return error; } @@ -3489,33 +3487,32 @@ ivas_error ivas_rend_crendProcess( subframe_len = L_SUBFRAME_8k; move16(); BREAK; - default: + default: BREAK; } - FOR ( i = 0; i < BINAURAL_CHANNELS; i++ ) + FOR( i = 0; i < BINAURAL_CHANNELS; i++ ) { p_pcm_tmp_fx[i] = pcm_tmp_fx[i]; move32(); } - + FOR( subframe_idx = 0; subframe_idx < num_subframes; subframe_idx++ ) { /* Early Reflections */ - IF ( hCrend->reflections != NULL ) + IF( hCrend->reflections != NULL ) { test(); - IF( EQ_16( hCrend->reflections->use_er, 1 ) && EQ_16(hCrend->reflections->is_ready , 1) ) + IF( EQ_16( hCrend->reflections->use_er, 1 ) && EQ_16( hCrend->reflections->is_ready, 1 ) ) { - IF ( NE_32( ( error = ivas_er_process( hCrend->reflections, subframe_len, subframe_idx, output_fx, inConfig ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_er_process( hCrend->reflections, subframe_len, subframe_idx, output_fx, inConfig ) ), IVAS_ERR_OK ) ) { return error; } - } } - IF ( hDecoderConfig && combinedOrientationEnabled ) + IF( hDecoderConfig && combinedOrientationEnabled ) { /* Orientation tracking */ @@ -3524,26 +3521,25 @@ ivas_error ivas_rend_crendProcess( SBA SPAR -> BINAURAL or BINAURAL_ROOM */ test(); - IF ( EQ_16(inConfig ,IVAS_AUDIO_CONFIG_FOA) || EQ_16(inConfig , IVAS_AUDIO_CONFIG_HOA2) || EQ_16(inConfig , IVAS_AUDIO_CONFIG_HOA3) ) + IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_FOA ) || EQ_16( inConfig, IVAS_AUDIO_CONFIG_HOA2 ) || EQ_16( inConfig, IVAS_AUDIO_CONFIG_HOA3 ) ) { rotateFrame_shd( hCombinedOrientationData, output_fx, subframe_len, *hIntSetup, subframe_idx ); } /* Rotation in SD for MC -> BINAURAL_ROOM */ - ELSE IF ( ( hIntSetup != NULL ) && hIntSetup->is_loudspeaker_setup ) + ELSE IF( ( hIntSetup != NULL ) && hIntSetup->is_loudspeaker_setup ) { rotateFrame_sd( hCombinedOrientationData, output_fx, subframe_len, *hIntSetup, hEFAPdata, subframe_idx ); - } } test(); - IF ( EQ_16(inConfigType ,IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED) || EQ_16(inConfigType , IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS) ) + IF( EQ_16( inConfigType, IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED ) || EQ_16( inConfigType, IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS ) ) { - IF ( ( error = ivas_rend_crendConvolver( pCrend, inConfig, outConfig, output_fx, p_pcm_tmp_fx, output_Fs, subframe_idx ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_rend_crendConvolver( pCrend, inConfig, outConfig, output_fx, p_pcm_tmp_fx, output_Fs, subframe_idx ) ) != IVAS_ERR_OK ) { return error; } - + IF( hCrend->hReverb != NULL ) { IF( ( error = ivas_reverb_process_fx( pCrend->hCrend->hReverb, inConfig, 1, output_fx, p_pcm_tmp_fx, subframe_idx ) ) != IVAS_ERR_OK ) @@ -3558,11 +3554,11 @@ ivas_error ivas_rend_crendProcess( } } /* move to output */ - FOR ( i = 0; i < nchan_out; i++ ) + FOR( i = 0; i < nchan_out; i++ ) { mvr2r_Word32( pcm_tmp_fx[i], output_fx[i], num_subframes * subframe_len ); } - + pop_wmops(); return IVAS_ERR_OK; } @@ -3582,7 +3578,7 @@ ivas_error ivas_rend_crendProcess( COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, IVAS_OUTPUT_SETUP_HANDLE hIntSetup, EFAP_HANDLE hEFAPdata, - float *output[], /* i/o: input/output audio channels */ + float *output[], /* i/o: input/output audio channels */ const int32_t output_Fs, const int16_t num_subframes /* i : number of subframes to render */ ) @@ -3708,10 +3704,10 @@ ivas_error ivas_rend_crendProcessSubframe( const IVAS_OUTPUT_SETUP_HANDLE hIntSetup, /* i : internal setup handle */ const EFAP_HANDLE hEFAPdata, /* i : EFAP handle */ DECODER_TC_BUFFER_HANDLE hTcBuffer, /* i/o: JBM handle */ - Word32 *input_f[], /* i : transport channels */ + Word32 *input_f[], /* i : transport channels */ Word32 *output[], /* i/o: input/output audio channels */ - const Word16 n_samples_to_render, /* i : output frame length per channel */ - const Word32 output_Fs /* i : output sampling rate */ + const Word16 n_samples_to_render, /* i : output frame length per channel */ + const Word32 output_Fs /* i : output sampling rate */ ) { Word16 subframe_idx, subframe_len; @@ -3726,9 +3722,9 @@ ivas_error ivas_rend_crendProcessSubframe( hCrend = pCrend->hCrend; combinedOrientationEnabled = 0; - IF ( hCombinedOrientationData != NULL ) + IF( hCombinedOrientationData != NULL ) { - IF ( NE_16( hCombinedOrientationData->enableCombinedOrientation[0], 0 ) ) + IF( NE_16( hCombinedOrientationData->enableCombinedOrientation[0], 0 ) ) { combinedOrientationEnabled = 1; } @@ -3737,21 +3733,21 @@ ivas_error ivas_rend_crendProcessSubframe( push_wmops( "ivas_rend_crendProcessSubframe" ); inConfigType = getAudioConfigType( inConfig ); - IF ( NE_32( ( error = getAudioConfigNumChannels( outConfig, &nchan_out ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = getAudioConfigNumChannels( outConfig, &nchan_out ) ), IVAS_ERR_OK ) ) { return error; } - IF ( NE_32( ( error = getAudioConfigNumChannels( inConfig, &nchan_in ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = getAudioConfigNumChannels( inConfig, &nchan_in ) ), IVAS_ERR_OK ) ) { return error; } - FOR ( ch = 0; ch < nchan_in; ch++ ) + FOR( ch = 0; ch < nchan_in; ch++ ) { tc_local_fx[ch] = input_f[ch]; } - FOR ( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) + FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { p_pcm_tmp_fx[ch] = pcm_tmp_fx[ch]; } @@ -3764,63 +3760,60 @@ ivas_error ivas_rend_crendProcessSubframe( last_sf = first_sf; move16(); - WHILE ( slots_to_render > 0 ) + WHILE( slots_to_render > 0 ) { slots_to_render = sub( slots_to_render, hTcBuffer->subframe_nbslots[last_sf] ); - last_sf = add(last_sf, 1); + last_sf = add( last_sf, 1 ); } - FOR ( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ ) + FOR( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ ) { subframe_len = imult1616( hTcBuffer->subframe_nbslots[subframe_idx], hTcBuffer->n_samples_granularity ); /* Early Reflections */ - IF ( hCrend->reflections != NULL ) + IF( hCrend->reflections != NULL ) { - IF ( hCrend->reflections->use_er == 1 && hCrend->reflections->is_ready == 1 ) + IF( hCrend->reflections->use_er == 1 && hCrend->reflections->is_ready == 1 ) { - IF ( NE_32( ( error = ivas_er_process( hCrend->reflections, subframe_len, 0, tc_local_fx, inConfig ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_er_process( hCrend->reflections, subframe_len, 0, tc_local_fx, inConfig ) ), IVAS_ERR_OK ) ) { return error; } - } } - IF ( hDecoderConfig && combinedOrientationEnabled ) + IF( hDecoderConfig && combinedOrientationEnabled ) { /* Rotation in SHD for: MC with elevation (5_1_2 / 5_1_4 / 7_1_4) -> BINAURAL SBA SPAR -> BINAURAL or BINAURAL_ROOM */ - IF ( EQ_32( inConfig, IVAS_AUDIO_CONFIG_FOA ) || EQ_32( inConfig, IVAS_AUDIO_CONFIG_HOA2 ) || EQ_32( inConfig, IVAS_AUDIO_CONFIG_HOA3 ) ) + IF( EQ_32( inConfig, IVAS_AUDIO_CONFIG_FOA ) || EQ_32( inConfig, IVAS_AUDIO_CONFIG_HOA2 ) || EQ_32( inConfig, IVAS_AUDIO_CONFIG_HOA3 ) ) { rotateFrame_shd( hCombinedOrientationData, tc_local_fx, subframe_len, *hIntSetup, 0 ); } /* Rotation in SD for MC -> BINAURAL_ROOM */ - ELSE IF ( ( hIntSetup != NULL ) && hIntSetup->is_loudspeaker_setup ) + ELSE IF( ( hIntSetup != NULL ) && hIntSetup->is_loudspeaker_setup ) { rotateFrame_sd( hCombinedOrientationData, tc_local_fx, subframe_len, *hIntSetup, hEFAPdata, 0 ); - } } IF( EQ_32( inConfigType, IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED ) || EQ_32( inConfigType, IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS ) ) { - - IF ( NE_32( ( error = ivas_rend_crendConvolver( pCrend, inConfig, outConfig, tc_local_fx, p_pcm_tmp_fx, output_Fs, 0 ) ), IVAS_ERR_OK ) ) + + IF( NE_32( ( error = ivas_rend_crendConvolver( pCrend, inConfig, outConfig, tc_local_fx, p_pcm_tmp_fx, output_Fs, 0 ) ), IVAS_ERR_OK ) ) { return error; } - - IF ( pCrend->hCrend->hReverb != NULL ) + + IF( pCrend->hCrend->hReverb != NULL ) { - IF ( NE_32( ( error = ivas_reverb_process_fx( pCrend->hCrend->hReverb, inConfig, 1, tc_local_fx, p_pcm_tmp_fx, 0 ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_reverb_process_fx( pCrend->hCrend->hReverb, inConfig, 1, tc_local_fx, p_pcm_tmp_fx, 0 ) ), IVAS_ERR_OK ) ) { return error; } - } - FOR ( ch = 0; ch < nchan_in; ch++ ) + FOR( ch = 0; ch < nchan_in; ch++ ) { tc_local_fx[ch] += subframe_len; } @@ -3837,19 +3830,19 @@ ivas_error ivas_rend_crendProcessSubframe( /* update combined orientation access index */ ivas_combined_orientation_update_index( hCombinedOrientationData, subframe_len ); } - IF ( pCrend->hCrend->hReverb != NULL ) + IF( pCrend->hCrend->hReverb != NULL ) { *pCrend->p_io_qfactor -= 2; - FOR (Word16 i = nchan_out; i < nchan_in; i++) + FOR( Word16 i = nchan_out; i < nchan_in; i++ ) { - FOR (Word16 j = 0; j < n_samples_to_render; j++) - { - output[i][j] = (Word32)L_shr(output[i][j], 2); - } + FOR( Word16 j = 0; j < n_samples_to_render; j++ ) + { + output[i][j] = (Word32) L_shr( output[i][j], 2 ); + } } } /* move to output */ - FOR ( ch = 0; ch < nchan_out; ch++ ) + FOR( ch = 0; ch < nchan_out; ch++ ) { mvr2r_Word32( pcm_tmp_fx[ch], output[ch], n_samples_to_render ); } diff --git a/lib_rend/ivas_dirac_ana.c b/lib_rend/ivas_dirac_ana.c index 45f561abc..19cbbfe59 100644 --- a/lib_rend/ivas_dirac_ana.c +++ b/lib_rend/ivas_dirac_ana.c @@ -57,7 +57,6 @@ static void ivas_dirac_dmx( float data_in_f[][L_FRAME48k], const int16_t input_f #endif - /*--------------------------------------------------------------------------* * ivas_dirac_ana_open() * @@ -476,7 +475,7 @@ static void ivas_dirac_param_est_ana_fx( Word16 q_factor_intensity, q_factor_intensity_old = 0; Word16 q_factor_energy = 0, q_factor_energy_old = 0; Word16 exp = 0, exp_div = 0; - //Word16 exp2; + // Word16 exp2; num_freq_bands = hDirAC->nbands; Word16 tmp_e; Word16 tmp = BASOP_Util_Divide3216_Scale( input_frame, CLDFB_NO_COL_MAX, &tmp_e ); @@ -557,7 +556,7 @@ static void ivas_dirac_param_est_ana_fx( /* Power estimation for diffuseness */ computeReferencePower_ana_fx( hDirAC->band_grouping, Foa_RealBuffer_fx, Foa_ImagBuffer_fx, reference_power_fx[ts], num_freq_bands ); //( 2 * ( scale_fact - Q1 ) - 31 - 1 ); // computeReferencePower_ana( hDirAC->band_grouping, Foa_RealBuffer, Foa_ImagBuffer, reference_power[ts], num_freq_bands ); - //exp2 = sub( shl( scale_fact, 1 ), 31 ); + // exp2 = sub( shl( scale_fact, 1 ), 31 ); /* Fill buffers of length "averaging_length" time slots for intensity and energy */ hDirAC->index_buffer_intensity = add( ( hDirAC->index_buffer_intensity % DIRAC_NO_COL_AVG_DIFF ), 1 ); /* averaging_length = 32 */ index = hDirAC->index_buffer_intensity; diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index b40d30d80..e22b800d6 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -5,7 +5,7 @@ Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other contributors to this repository. All Rights Reserved. - + This software is protected by copyright law and by international treaties. The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., @@ -14,15 +14,15 @@ contributors to this repository retain full ownership rights in their respective contributions in the software. This notice grants no license of any kind, including but not limited to patent license, nor is any license granted by implication, estoppel or otherwise. - + Contributors are required to enter into the IVAS codec Public Collaboration agreement before making contributions. - + This software is provided "AS IS", without any express or implied warranties. The software is in the development stage. It is intended exclusively for experts who have experience with such software and solely for the purpose of inspection. All implied warranties of non-infringement, merchantability and fitness for a particular purpose are hereby disclaimed and excluded. - + Any dispute, controversy or claim arising under or in relation to providing this software shall be submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and @@ -1138,15 +1138,15 @@ static void ivas_dirac_dec_binaural_internal( IF( abs_s( (Word16) st_ivas->cldfbAnaDec[1]->scale_flt ) != 0 ) st_ivas->cldfbAnaDec[1]->q_scale = norm_s( (Word16) st_ivas->cldfbAnaDec[1]->scale_flt ); st_ivas->cldfbAnaDec[1]->scale = (Word16) ( st_ivas->cldfbAnaDec[1]->scale_flt * ( 1 << st_ivas->cldfbAnaDec[1]->q_scale ) ); - IF(st_ivas->hSCE[0]) + IF( st_ivas->hSCE[0] ) { - Word16 shift = getScaleFactor32(st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN); - IF(LT_16(sub(st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift), 4)) + Word16 shift = getScaleFactor32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN ); + IF( LT_16( sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ), 4 ) ) { - shift = sub(st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4); + shift = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 ); } - scale_sig32(st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift); - st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub(st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift); + scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); + st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ); } Word16 q_cldfb[6][CLDFB_SLOTS_PER_SUBFRAME] = { 0 }; FOR( Word16 ind = 0; ind < 6; ind++ ) @@ -1211,21 +1211,27 @@ static void ivas_dirac_dec_binaural_internal( Rmat_fx[0][0] = ONE_IN_Q30; Rmat_fx[0][1] = 0; Rmat_fx[0][2] = 0; - move32(); move32(); move32(); + move32(); + move32(); + move32(); Rmat_fx[1][0] = 0; Rmat_fx[1][1] = ONE_IN_Q30; Rmat_fx[1][2] = 0; - move32(); move32(); move32(); + move32(); + move32(); + move32(); Rmat_fx[2][0] = 0; Rmat_fx[2][1] = 0; Rmat_fx[2][2] = ONE_IN_Q30; - move32(); move32(); move32(); + move32(); + move32(); + move32(); - FOR ( i = 0; i < 6; i++ ) + FOR( i = 0; i < 6; i++ ) { - FOR ( j = 0; j < 4; j++ ) + FOR( j = 0; j < 4; j++ ) { set32_fx( Cldfb_RealBuffer_in_fx[i][j], 0, 60 ); set32_fx( Cldfb_ImagBuffer_in_fx[i][j], 0, 60 ); @@ -1369,8 +1375,8 @@ static void ivas_dirac_dec_binaural_internal( { FOR( slot = 0; slot < 4; slot++ ) { - scale_sig32(Cldfb_RealBuffer_in_fx[cha][slot], 60, sub(q_inp, q_cldfb[cha][slot])); - scale_sig32(Cldfb_ImagBuffer_in_fx[cha][slot], 60, sub(q_inp, q_cldfb[cha][slot])); + scale_sig32( Cldfb_RealBuffer_in_fx[cha][slot], 60, sub( q_inp, q_cldfb[cha][slot] ) ); + scale_sig32( Cldfb_ImagBuffer_in_fx[cha][slot], 60, sub( q_inp, q_cldfb[cha][slot] ) ); } } @@ -1429,8 +1435,8 @@ static void ivas_dirac_dec_binaural_internal( { FOR( j = 0; j < 4; j++ ) { - shift = s_min(shift, getScaleFactor32(Cldfb_RealBuffer_in_fx[i][j], CLDFB_NO_CHANNELS_MAX)); - shift = s_min(shift, getScaleFactor32(Cldfb_ImagBuffer_in_fx[i][j], CLDFB_NO_CHANNELS_MAX)); + shift = s_min( shift, getScaleFactor32( Cldfb_RealBuffer_in_fx[i][j], CLDFB_NO_CHANNELS_MAX ) ); + shift = s_min( shift, getScaleFactor32( Cldfb_ImagBuffer_in_fx[i][j], CLDFB_NO_CHANNELS_MAX ) ); } } @@ -1449,14 +1455,14 @@ static void ivas_dirac_dec_binaural_internal( } ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matrices_fx( hDiracDecBin, hSpatParamRendCom, &config_data, Cldfb_RealBuffer_inTmp_fx, Cldfb_ImagBuffer_inTmp_fx, Rmat_fx, subframe, - hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[hCombinedOrientationData->subframe_idx] > 0, st_ivas->hMasaIsmData, q ); + hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[hCombinedOrientationData->subframe_idx] > 0, st_ivas->hMasaIsmData, q ); - IF ( config_data.ivas_format == ISM_FORMAT ) + IF( config_data.ivas_format == ISM_FORMAT ) { max_band_decorr = 0; move16(); } - ELSE IF ( hDiracDecBin->useTdDecorr ) + ELSE IF( hDiracDecBin->useTdDecorr ) { max_band_decorr = CLDFB_NO_CHANNELS_MAX; move16(); @@ -1470,12 +1476,12 @@ static void ivas_dirac_dec_binaural_internal( nchanSeparateChannels = 0; move16(); - IF ( config_data.separateCenterChannelRendering || ( st_ivas->ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) ) ) + IF( config_data.separateCenterChannelRendering || ( st_ivas->ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) ) ) { nchanSeparateChannels = 1; move16(); } - ELSE IF ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode == ISM_MASA_MODE_DISC && ( st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) + ELSE IF( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode == ISM_MASA_MODE_DISC && ( st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) { nchanSeparateChannels = (UWord8) st_ivas->nchan_ism; move16(); @@ -1507,11 +1513,11 @@ static void ivas_dirac_dec_binaural_internal( fixedToFloat_arrL( hDiracDecBin->frameMeanDiffuseness_fx, hDiracDecBin->frameMeanDiffuseness, 29, CLDFB_NO_CHANNELS_MAX ); #endif - //TODO: To be removed once below function is fixed + // TODO: To be removed once below function is fixed float Rmat[3][3]; - for(i=0;i<3;i++) + for ( i = 0; i < 3; i++ ) { - fixedToFloat_arrL32(Rmat_fx[i], Rmat[i], Q30, 3); + fixedToFloat_arrL32( Rmat_fx[i], Rmat[i], Q30, 3 ); } ivas_dirac_dec_binaural_determine_processing_matrices( hDiracDecBin, hSpatParamRendCom, &config_data, max_band_decorr, Rmat, subframe, hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[hCombinedOrientationData->subframe_idx] > 0, nchanSeparateChannels, st_ivas->hMasaIsmData ); @@ -1573,14 +1579,14 @@ static void ivas_dirac_dec_binaural_internal( hDiracDecBin->hDiffuseDist = NULL; - hSpatParamRendCom->slots_rendered = add(hSpatParamRendCom->slots_rendered, hSpatParamRendCom->subframe_nbslots[subframe]); - hSpatParamRendCom->subframes_rendered = add(hSpatParamRendCom->subframes_rendered, 1); + hSpatParamRendCom->slots_rendered = add( hSpatParamRendCom->slots_rendered, hSpatParamRendCom->subframe_nbslots[subframe] ); + hSpatParamRendCom->subframes_rendered = add( hSpatParamRendCom->subframes_rendered, 1 ); #if 1 FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { fixedToFloat_arrL32( output_fx[ch], output_f[ch], q_out, imult1616( nBins, hSpatParamRendCom->subframe_nbslots[subframe] ) ); - scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, sub(Q11, st_ivas->cldfbSynDec[ch]->Q_cldfb_state) ); + scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, sub( Q11, st_ivas->cldfbSynDec[ch]->Q_cldfb_state ) ); st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q11; } #endif @@ -2185,7 +2191,7 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric const Word16 subframe, const Word16 isHeadtracked, const MASA_ISM_DATA_HANDLE hMasaIsmData, - Word16 q) + Word16 q ) { Word16 ch, slot, bin; Word16 separateCenterChannelRendering; @@ -2363,7 +2369,7 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric * the early spectrum of the BRIR data, using the spectral correction data in * hBinaural->earlyPartEneCorrection[bin], based on the BRIR set. */ meanEnePerCh_fx = Mpy_32_32( hDiracDecBin->earlyPartEneCorrection_fx[bin], subFrameTotalEne_fx[bin] ); // Q( 2q - 31 ) - q_meanEnePerCh = sub(add(q_earlyPartEneCorrection, q_subFrameTotalEne), 30); + q_meanEnePerCh = sub( add( q_earlyPartEneCorrection, q_subFrameTotalEne ), 30 ); /* Determine direct part target covariance matrix (for 1 or 2 directions) */ FOR( dirIndex = 0; dirIndex < hSpatParamRendCom->numSimultaneousDirections; dirIndex++ ) { @@ -2410,7 +2416,7 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric isIsmDirection = 1; move16(); UWord16 ismDirIndex; - ismDirIndex = sub(dirIndex, hSpatParamRendCom->numParametricDirections); + ismDirIndex = sub( dirIndex, hSpatParamRendCom->numParametricDirections ); assert( hMasaIsmData != NULL && "hMasaIsmData should not be NULL if we use it" ); IF( hMasaIsmData->ism_is_edited[ismDirIndex] ) { @@ -3128,9 +3134,9 @@ static void ivas_dirac_dec_binaural_process_output_fx( // scaling cldfb states to q_result-1// scale_sig32( cldfbSynDec[0]->cldfb_state_fx, cldfbSynDec[0]->p_filter_length, cldfb_state_shift ); - cldfbSynDec[0]->Q_cldfb_state = add(cldfbSynDec[0]->Q_cldfb_state, cldfb_state_shift); + cldfbSynDec[0]->Q_cldfb_state = add( cldfbSynDec[0]->Q_cldfb_state, cldfb_state_shift ); scale_sig32( cldfbSynDec[1]->cldfb_state_fx, cldfbSynDec[1]->p_filter_length, cldfb_state_shift ); - cldfbSynDec[1]->Q_cldfb_state = add(cldfbSynDec[1]->Q_cldfb_state, cldfb_state_shift); + cldfbSynDec[1]->Q_cldfb_state = add( cldfbSynDec[1]->Q_cldfb_state, cldfb_state_shift ); q_inp_mix = add( q_inp_mix, q_input ); @@ -4607,7 +4613,7 @@ static void getDirectPartGains_fx( e_mappedX = 0; mappedX = Sqrt32( L_max( 0, L_sub( ONE_IN_Q31, Mpy_32_32( y, y ) ) ), &e_mappedX ); - aziRadMapped = BASOP_util_atan2( y, mappedX, negate(e_mappedX) ); // Q13 + aziRadMapped = BASOP_util_atan2( y, mappedX, negate( e_mappedX ) ); // Q13 /* Determine the real valued amplitude panning gains */ *lImagp = 0; @@ -4617,7 +4623,7 @@ static void getDirectPartGains_fx( *lRealp = ONE_IN_Q31; *rRealp = 0; } - ELSE IF( LE_16( aziRadMapped, negate(shr( LsAngleRad, 2 )) ) ) + ELSE IF( LE_16( aziRadMapped, negate( shr( LsAngleRad, 2 ) ) ) ) { /* Right side */ *lRealp = 0; *rRealp = ONE_IN_Q31; @@ -5684,7 +5690,6 @@ static void ivas_masa_ext_rend_parambin_internal( max_band_decorr = hDiracDecBin->h_freq_domain_decorr_ap_params->max_band_decorr; - ivas_dirac_dec_binaural_determine_processing_matrices( hDiracDecBin, hSpatParamRendCom, &config_data, max_band_decorr, Rmat, subframe, hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[hCombinedOrientationData->subframe_idx] > 0, 0, NULL ); @@ -5743,10 +5748,10 @@ static void ivas_masa_ext_rend_parambin_internal( floatToFixed_arr32( hDiracDecBin->diffuseFieldCoherenceY, hDiracDecBin->diffuseFieldCoherenceY_fx, 31, 9 ); floatToFixed_arr32( hDiracDecBin->diffuseFieldCoherenceZ, hDiracDecBin->diffuseFieldCoherenceZ_fx, 31, 9 ); } - FOR( ch = 0; ch < 2; ch++) + FOR( ch = 0; ch < 2; ch++ ) { output_fx[ch] = output_fx_buff[ch]; - floatToFixed_arrL32(output_f[ch], output_fx[ch], Q11, L_FRAME48k); + floatToFixed_arrL32( output_f[ch], output_fx[ch], Q11, L_FRAME48k ); } #endif @@ -5785,17 +5790,23 @@ static void ivas_masa_ext_rend_parambin_internal( Rmat_fx[0][0] = ONE_IN_Q30; Rmat_fx[0][1] = 0; Rmat_fx[0][2] = 0; - move32(); move32(); move32(); + move32(); + move32(); + move32(); Rmat_fx[1][0] = 0; Rmat_fx[1][1] = ONE_IN_Q30; Rmat_fx[1][2] = 0; - move32(); move32(); move32(); + move32(); + move32(); + move32(); Rmat_fx[2][0] = 0; Rmat_fx[2][1] = 0; Rmat_fx[2][2] = ONE_IN_Q30; - move32(); move32(); move32(); + move32(); + move32(); + move32(); /* CLDFB Analysis of input */ @@ -5804,32 +5815,32 @@ static void ivas_masa_ext_rend_parambin_internal( { FOR( ch = 0; ch < numInChannels; ch++ ) { - IF( EQ_16(ch, 0) || EQ_16(nchan_transport, 2) ) + IF( EQ_16( ch, 0 ) || EQ_16( nchan_transport, 2 ) ) { cldfbAnalysis_ts_fx_fixed_q( &( output_fx[ch][nBins * slot] ), Cldfb_RealBuffer_in_fx[ch][slot], Cldfb_ImagBuffer_in_fx[ch][slot], - nBins, hMasaExtRend->cldfbAnaRend[ch], &q_cldfb); + nBins, hMasaExtRend->cldfbAnaRend[ch], &q_cldfb ); } ELSE /* when nchan_transport == 1 and ch == 1 */ { /* At mono input duplicate the channel to dual-mono, and apply gain correction to ensure same overall level as in stereo mode */ v_multc_fixed( Cldfb_RealBuffer_in_fx[0][slot], 151800249 /* INV_SQRT_2 in Q31 */, Cldfb_RealBuffer_in_fx[0][slot], nBins ); - v_multc_fixed( Cldfb_ImagBuffer_in_fx[0][slot], 151800249 /* INV_SQRT_2 in Q31 */, Cldfb_ImagBuffer_in_fx[0][slot], nBins ); + v_multc_fixed( Cldfb_ImagBuffer_in_fx[0][slot], 151800249 /* INV_SQRT_2 in Q31 */, Cldfb_ImagBuffer_in_fx[0][slot], nBins ); - mvl2l( Cldfb_RealBuffer_in_fx[0][slot], Cldfb_RealBuffer_in_fx[1][slot], nBins ); - mvl2l( Cldfb_ImagBuffer_in_fx[0][slot], Cldfb_ImagBuffer_in_fx[1][slot], nBins ); + mvl2l( Cldfb_RealBuffer_in_fx[0][slot], Cldfb_RealBuffer_in_fx[1][slot], nBins ); + mvl2l( Cldfb_ImagBuffer_in_fx[0][slot], Cldfb_ImagBuffer_in_fx[1][slot], nBins ); } } } Word16 q_inp = Q6; - IF ( hCombinedOrientationData ) + IF( hCombinedOrientationData ) { - FOR ( i = 0; i < 3; i++ ) + FOR( i = 0; i < 3; i++ ) { - FOR ( j = 0; j < 3; j++ ) + FOR( j = 0; j < 3; j++ ) { Rmat_fx[i][j] = hCombinedOrientationData->Rmat_fx[hCombinedOrientationData->subframe_idx][i][j]; // Q30// } @@ -5848,8 +5859,8 @@ static void ivas_masa_ext_rend_parambin_internal( { FOR( j = 0; j < 4; j++ ) { - shift = s_min(shift, getScaleFactor32(Cldfb_RealBuffer_in_fx[i][j], CLDFB_NO_CHANNELS_MAX)); - shift = s_min(shift, getScaleFactor32(Cldfb_ImagBuffer_in_fx[i][j], CLDFB_NO_CHANNELS_MAX)); + shift = s_min( shift, getScaleFactor32( Cldfb_RealBuffer_in_fx[i][j], CLDFB_NO_CHANNELS_MAX ) ); + shift = s_min( shift, getScaleFactor32( Cldfb_ImagBuffer_in_fx[i][j], CLDFB_NO_CHANNELS_MAX ) ); } } @@ -5868,7 +5879,7 @@ static void ivas_masa_ext_rend_parambin_internal( } ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matrices_fx( hDiracDecBin, hSpatParamRendCom, &config_data, Cldfb_RealBuffer_inTmp_fx, Cldfb_ImagBuffer_inTmp_fx, Rmat_fx, subframe, - hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[hCombinedOrientationData->subframe_idx] > 0, NULL, q ); + hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[hCombinedOrientationData->subframe_idx] > 0, NULL, q ); /* Always using CLDFB decorrelation in MASA EXT renderer */ max_band_decorr = hDiracDecBin->h_freq_domain_decorr_ap_params->max_band_decorr; @@ -5901,13 +5912,13 @@ static void ivas_masa_ext_rend_parambin_internal( float Rmat[3][3]; - for ( i = 0; i < 3; i++) // TODO: To be removed + for ( i = 0; i < 3; i++ ) // TODO: To be removed { - fixedToFloat_arrL32(Rmat_fx[i], Rmat[i], Q30, 3); + fixedToFloat_arrL32( Rmat_fx[i], Rmat[i], Q30, 3 ); } ivas_dirac_dec_binaural_determine_processing_matrices( hDiracDecBin, hSpatParamRendCom, &config_data, max_band_decorr, Rmat, subframe, - hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[hCombinedOrientationData->subframe_idx] > 0, - 0, NULL ); + hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[hCombinedOrientationData->subframe_idx] > 0, + 0, NULL ); #if 1 Word16 q_out; @@ -5958,21 +5969,21 @@ static void ivas_masa_ext_rend_parambin_internal( } hMasaExtRend->cldfbSynRend[ch]->Q_cldfb_state = Q11; } -#endif //Float to fix ends +#endif // Float to fix ends ivas_dirac_dec_binaural_process_output_fx( hDiracDecBin, hSpatParamRendCom, hMasaExtRend->cldfbSynRend, output_fx, &q_out, Cldfb_RealBuffer_in_fx, Cldfb_ImagBuffer_in_fx, q_inp, max_band_decorr, numInChannels, config_data.processReverb, subframe, q_mat ); hDiracDecBin->hDiffuseDist = NULL; - hSpatParamRendCom->slots_rendered = add(hSpatParamRendCom->slots_rendered, hSpatParamRendCom->subframe_nbslots[subframe]); - hSpatParamRendCom->subframes_rendered = add(hSpatParamRendCom->subframes_rendered, 1); + hSpatParamRendCom->slots_rendered = add( hSpatParamRendCom->slots_rendered, hSpatParamRendCom->subframe_nbslots[subframe] ); + hSpatParamRendCom->subframes_rendered = add( hSpatParamRendCom->subframes_rendered, 1 ); -#if 1// Fix to float +#if 1 // Fix to float FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { fixedToFloat_arrL32( output_fx[ch], output_f[ch], q_out, nBins * hSpatParamRendCom->subframe_nbslots[subframe] ); - scale_sig32( hMasaExtRend->cldfbSynRend[ch]->cldfb_state_fx, hMasaExtRend->cldfbSynRend[ch]->cldfb_size, sub(Q11, hMasaExtRend->cldfbSynRend[ch]->Q_cldfb_state) ); + scale_sig32( hMasaExtRend->cldfbSynRend[ch]->cldfb_state_fx, hMasaExtRend->cldfbSynRend[ch]->cldfb_size, sub( Q11, hMasaExtRend->cldfbSynRend[ch]->Q_cldfb_state ) ); hMasaExtRend->cldfbSynRend[ch]->Q_cldfb_state = Q11; } #endif diff --git a/lib_rend/ivas_dirac_decorr_dec.c b/lib_rend/ivas_dirac_decorr_dec.c index 215aaef91..c1830eaed 100644 --- a/lib_rend/ivas_dirac_decorr_dec.c +++ b/lib_rend/ivas_dirac_decorr_dec.c @@ -509,7 +509,7 @@ ivas_error ivas_dirac_dec_decorr_open_fx( freq_domain_decorr_ap_state->reverb_energy_smooth_fx = NULL; #endif - IF ( num_outputs_diff > 0 ) + IF( num_outputs_diff > 0 ) { buffer_size_decorr = ( ap_pre_delay[split_band_index_start] + ap_filter_length[split_band_index_start] ); #if 1 @@ -582,7 +582,7 @@ ivas_error ivas_dirac_dec_decorr_open_fx( freq_domain_decorr_ap_state->q_direct_energy_smooth = freq_domain_decorr_ap_state->q_reverb_energy_smooth = Q31; /* compute filter coefficients */ - FOR ( k = 0; k < freq_domain_decorr_ap_params->num_split_frequency_bands; k++ ) + FOR( k = 0; k < freq_domain_decorr_ap_params->num_split_frequency_bands; k++ ) { k_in = freq_domain_decorr_ap_params->split_frequency_bands[k]; k_out = freq_domain_decorr_ap_params->split_frequency_bands[k + 1]; @@ -591,11 +591,11 @@ ivas_error ivas_dirac_dec_decorr_open_fx( freq_domain_decorr_ap_params->filter_length[k] = add( ap_filter_length[band_table_idx], 1 ); freq_domain_decorr_ap_params->pre_delay[k] = ap_pre_delay[band_table_idx]; - FOR ( l = 0; l < num_outputs_diff; l++ ) + FOR( l = 0; l < num_outputs_diff; l++ ) { - FOR ( m = 0; m < num_bands; m++ ) + FOR( m = 0; m < num_bands; m++ ) { - n = add(k_in , m); + n = add( k_in, m ); Word32 cur_lattice_delta_phi_32_fx = L_mult( ap_lattice_delta_phi_fx[l * DIRAC_MAX_DECORR_FILTER_LEN + ap_filter_length[k] - 1], (Word16) floatToFixed( n, 10 ) ); cur_lattice_delta_phi_fx = extract_h( cur_lattice_delta_phi_32_fx ); // Q10 @@ -1011,19 +1011,19 @@ void ivas_dirac_dec_decorr_process_fx( } q_aux_buffer += q_shift; #else - (void)maximum_abs_32_fx(&input_frame_fx[0], 2 * num_protos_dir * num_freq_bands, &max_abs_val); + (void) maximum_abs_32_fx( &input_frame_fx[0], 2 * num_protos_dir * num_freq_bands, &max_abs_val ); q_shift = getScaleFactor32( &input_frame_fx[0], 2 * num_protos_dir * num_freq_bands ) - guarded_bits; - IF (LT_16(q_shift , sub(0, guarded_bits)) && NE_32(max_abs_val, 0)) + IF( LT_16( q_shift, sub( 0, guarded_bits ) ) && NE_32( max_abs_val, 0 ) ) { - q_shift = sub(0, guarded_bits); + q_shift = sub( 0, guarded_bits ); } - ELSE IF (EQ_32(max_abs_val, 0)) + ELSE IF( EQ_32( max_abs_val, 0 ) ) { q_shift = 0; } - FOR ( ch_idx = 0; ch_idx < num_protos_dir; ch_idx++) + FOR( ch_idx = 0; ch_idx < num_protos_dir; ch_idx++ ) { - v_shr(&input_frame_fx[2 * ch_idx * num_freq_bands], negate(q_shift), &aux_buffer_fx[2 * ch_idx * num_freq_bands], 2 * num_freq_bands); + v_shr( &input_frame_fx[2 * ch_idx * num_freq_bands], negate( q_shift ), &aux_buffer_fx[2 * ch_idx * num_freq_bands], 2 * num_freq_bands ); } FOR( ch_idx = 0; ch_idx < num_protos_dir; ch_idx++ ) { @@ -1299,17 +1299,17 @@ void ivas_dirac_dec_decorr_process_fx( h_freq_domain_decorr_ap_state->q_direct_energy_smooth = sub( 31, e_direct_energy_smooth ); // scaling energy buffers for better precision for higher values// - q_shift = L_norm_arr(h_freq_domain_decorr_ap_state->direct_energy_smooth_fx, imult1616(num_protos_dir, max_band_decorr)); - Scale_sig32(h_freq_domain_decorr_ap_state->direct_energy_smooth_fx, imult1616(num_protos_dir, max_band_decorr), q_shift); + q_shift = L_norm_arr( h_freq_domain_decorr_ap_state->direct_energy_smooth_fx, imult1616( num_protos_dir, max_band_decorr ) ); + Scale_sig32( h_freq_domain_decorr_ap_state->direct_energy_smooth_fx, imult1616( num_protos_dir, max_band_decorr ), q_shift ); h_freq_domain_decorr_ap_state->q_direct_energy_smooth = h_freq_domain_decorr_ap_state->q_direct_energy_smooth + q_shift; - q_shift = L_norm_arr(h_freq_domain_decorr_ap_state->reverb_energy_smooth_fx, imult1616(num_channels, max_band_decorr)); - Scale_sig32(h_freq_domain_decorr_ap_state->reverb_energy_smooth_fx, imult1616(num_channels, max_band_decorr), q_shift); + q_shift = L_norm_arr( h_freq_domain_decorr_ap_state->reverb_energy_smooth_fx, imult1616( num_channels, max_band_decorr ) ); + Scale_sig32( h_freq_domain_decorr_ap_state->reverb_energy_smooth_fx, imult1616( num_channels, max_band_decorr ), q_shift ); h_freq_domain_decorr_ap_state->q_reverb_energy_smooth = h_freq_domain_decorr_ap_state->q_reverb_energy_smooth + q_shift; - e_reverb_energy_smooth = sub(31 , h_freq_domain_decorr_ap_state->q_reverb_energy_smooth); - e_direct_energy_smooth = sub(31 , h_freq_domain_decorr_ap_state->q_direct_energy_smooth); + e_reverb_energy_smooth = sub( 31, h_freq_domain_decorr_ap_state->q_reverb_energy_smooth ); + e_direct_energy_smooth = sub( 31, h_freq_domain_decorr_ap_state->q_direct_energy_smooth ); // this step is b/c we are left shifting frame_dec_fx at the end of below for loop/ #ifdef MSAN_FIX @@ -1444,150 +1444,150 @@ void ivas_dirac_dec_decorr_process_fx( #ifdef IVAS_FLOAT_FIXED void ivas_dirac_dec_decorr_close_fx( - HANDLE_DIRAC_DECORR_PARAMS *ph_freq_domain_decorr_ap_params, - HANDLE_DIRAC_DECORR_STATE *ph_freq_domain_decorr_ap_state) + HANDLE_DIRAC_DECORR_PARAMS *ph_freq_domain_decorr_ap_params, + HANDLE_DIRAC_DECORR_STATE *ph_freq_domain_decorr_ap_state ) { - DIRAC_ONSET_DETECTION_STATE *dirac_onset_detection_state; + DIRAC_ONSET_DETECTION_STATE *dirac_onset_detection_state; - /*-----------------------------------------------------------------* - * check input handles - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * check input handles + *-----------------------------------------------------------------*/ - if (ph_freq_domain_decorr_ap_params == NULL || ph_freq_domain_decorr_ap_state == NULL) - { - return; - } + if ( ph_freq_domain_decorr_ap_params == NULL || ph_freq_domain_decorr_ap_state == NULL ) + { + return; + } - if (*ph_freq_domain_decorr_ap_params == NULL || *ph_freq_domain_decorr_ap_state == NULL) - { - return; - } + if ( *ph_freq_domain_decorr_ap_params == NULL || *ph_freq_domain_decorr_ap_state == NULL ) + { + return; + } - /*-----------------------------------------------------------------* - * free onset filter arrays - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * free onset filter arrays + *-----------------------------------------------------------------*/ - dirac_onset_detection_state = &(*ph_freq_domain_decorr_ap_state)->h_onset_detection_power_state; + dirac_onset_detection_state = &( *ph_freq_domain_decorr_ap_state )->h_onset_detection_power_state; #ifdef IVAS_FLOAT_FIXED - IF(dirac_onset_detection_state->onset_detector_1_fx != NULL) - { - free(dirac_onset_detection_state->onset_detector_1_fx); - dirac_onset_detection_state->onset_detector_1_fx = NULL; - } - - IF(dirac_onset_detection_state->onset_detector_2_fx != NULL) - { - free(dirac_onset_detection_state->onset_detector_2_fx); - dirac_onset_detection_state->onset_detector_2_fx = NULL; - } + IF( dirac_onset_detection_state->onset_detector_1_fx != NULL ) + { + free( dirac_onset_detection_state->onset_detector_1_fx ); + dirac_onset_detection_state->onset_detector_1_fx = NULL; + } + + IF( dirac_onset_detection_state->onset_detector_2_fx != NULL ) + { + free( dirac_onset_detection_state->onset_detector_2_fx ); + dirac_onset_detection_state->onset_detector_2_fx = NULL; + } #endif - /*-----------------------------------------------------------------* - * memory deallocation - *-----------------------------------------------------------------*/ - - /* free decorrelation buffer */ - if ((*ph_freq_domain_decorr_ap_state)->decorr_buffer != NULL) - { - free((*ph_freq_domain_decorr_ap_state)->decorr_buffer); - (*ph_freq_domain_decorr_ap_state)->decorr_buffer = NULL; - } - - /* free ducker smoothed direct energy buffer */ - if ((*ph_freq_domain_decorr_ap_state)->direct_energy_smooth != NULL) - { - free((*ph_freq_domain_decorr_ap_state)->direct_energy_smooth); - (*ph_freq_domain_decorr_ap_state)->direct_energy_smooth = NULL; - } - - /* free ducker smoothed reverb energy buffer */ - if ((*ph_freq_domain_decorr_ap_state)->reverb_energy_smooth != NULL) - { - free((*ph_freq_domain_decorr_ap_state)->reverb_energy_smooth); - (*ph_freq_domain_decorr_ap_state)->reverb_energy_smooth = NULL; - } + /*-----------------------------------------------------------------* + * memory deallocation + *-----------------------------------------------------------------*/ + + /* free decorrelation buffer */ + if ( ( *ph_freq_domain_decorr_ap_state )->decorr_buffer != NULL ) + { + free( ( *ph_freq_domain_decorr_ap_state )->decorr_buffer ); + ( *ph_freq_domain_decorr_ap_state )->decorr_buffer = NULL; + } + + /* free ducker smoothed direct energy buffer */ + if ( ( *ph_freq_domain_decorr_ap_state )->direct_energy_smooth != NULL ) + { + free( ( *ph_freq_domain_decorr_ap_state )->direct_energy_smooth ); + ( *ph_freq_domain_decorr_ap_state )->direct_energy_smooth = NULL; + } + + /* free ducker smoothed reverb energy buffer */ + if ( ( *ph_freq_domain_decorr_ap_state )->reverb_energy_smooth != NULL ) + { + free( ( *ph_freq_domain_decorr_ap_state )->reverb_energy_smooth ); + ( *ph_freq_domain_decorr_ap_state )->reverb_energy_smooth = NULL; + } #ifdef IVAS_FLOAT_FIXED - IF((*ph_freq_domain_decorr_ap_state)->decorr_buffer_fx != NULL) - { - free((*ph_freq_domain_decorr_ap_state)->decorr_buffer_fx); - (*ph_freq_domain_decorr_ap_state)->decorr_buffer_fx = NULL; - } - - /* free ducker smoothed direct energy buffer */ - IF((*ph_freq_domain_decorr_ap_state)->direct_energy_smooth_fx != NULL) - { - free((*ph_freq_domain_decorr_ap_state)->direct_energy_smooth_fx); - (*ph_freq_domain_decorr_ap_state)->direct_energy_smooth_fx = NULL; - } - - /* free ducker smoothed reverb energy buffer */ - IF((*ph_freq_domain_decorr_ap_state)->reverb_energy_smooth_fx != NULL) - { - free((*ph_freq_domain_decorr_ap_state)->reverb_energy_smooth_fx); - (*ph_freq_domain_decorr_ap_state)->reverb_energy_smooth_fx = NULL; - } + IF( ( *ph_freq_domain_decorr_ap_state )->decorr_buffer_fx != NULL ) + { + free( ( *ph_freq_domain_decorr_ap_state )->decorr_buffer_fx ); + ( *ph_freq_domain_decorr_ap_state )->decorr_buffer_fx = NULL; + } + + /* free ducker smoothed direct energy buffer */ + IF( ( *ph_freq_domain_decorr_ap_state )->direct_energy_smooth_fx != NULL ) + { + free( ( *ph_freq_domain_decorr_ap_state )->direct_energy_smooth_fx ); + ( *ph_freq_domain_decorr_ap_state )->direct_energy_smooth_fx = NULL; + } + + /* free ducker smoothed reverb energy buffer */ + IF( ( *ph_freq_domain_decorr_ap_state )->reverb_energy_smooth_fx != NULL ) + { + free( ( *ph_freq_domain_decorr_ap_state )->reverb_energy_smooth_fx ); + ( *ph_freq_domain_decorr_ap_state )->reverb_energy_smooth_fx = NULL; + } #endif - /* free pre-delay param buffer */ - if ((*ph_freq_domain_decorr_ap_params)->pre_delay != NULL) - { - free((*ph_freq_domain_decorr_ap_params)->pre_delay); - (*ph_freq_domain_decorr_ap_params)->pre_delay = NULL; - } - - /* free filter length param buffer */ - if ((*ph_freq_domain_decorr_ap_params)->filter_length != NULL) - { - free((*ph_freq_domain_decorr_ap_params)->filter_length); - (*ph_freq_domain_decorr_ap_params)->filter_length = NULL; - } - - /* free pre-delay param buffer */ - if ((*ph_freq_domain_decorr_ap_params)->split_frequency_bands != NULL) - { - free((*ph_freq_domain_decorr_ap_params)->split_frequency_bands); - (*ph_freq_domain_decorr_ap_params)->split_frequency_bands = NULL; - } + /* free pre-delay param buffer */ + if ( ( *ph_freq_domain_decorr_ap_params )->pre_delay != NULL ) + { + free( ( *ph_freq_domain_decorr_ap_params )->pre_delay ); + ( *ph_freq_domain_decorr_ap_params )->pre_delay = NULL; + } + + /* free filter length param buffer */ + if ( ( *ph_freq_domain_decorr_ap_params )->filter_length != NULL ) + { + free( ( *ph_freq_domain_decorr_ap_params )->filter_length ); + ( *ph_freq_domain_decorr_ap_params )->filter_length = NULL; + } + + /* free pre-delay param buffer */ + if ( ( *ph_freq_domain_decorr_ap_params )->split_frequency_bands != NULL ) + { + free( ( *ph_freq_domain_decorr_ap_params )->split_frequency_bands ); + ( *ph_freq_domain_decorr_ap_params )->split_frequency_bands = NULL; + } #ifdef IVAS_FLOAT_FIXED /* free filter coeff param buffers */ - IF((*ph_freq_domain_decorr_ap_params)->filter_coeff_num_real_fx != NULL) - { - free((*ph_freq_domain_decorr_ap_params)->filter_coeff_num_real_fx); - (*ph_freq_domain_decorr_ap_params)->filter_coeff_num_real_fx = NULL; - } + IF( ( *ph_freq_domain_decorr_ap_params )->filter_coeff_num_real_fx != NULL ) + { + free( ( *ph_freq_domain_decorr_ap_params )->filter_coeff_num_real_fx ); + ( *ph_freq_domain_decorr_ap_params )->filter_coeff_num_real_fx = NULL; + } + + /* free pre-delay param buffer */ + IF( ( *ph_freq_domain_decorr_ap_params )->filter_coeff_den_real_fx != NULL ) + { + free( ( *ph_freq_domain_decorr_ap_params )->filter_coeff_den_real_fx ); + ( *ph_freq_domain_decorr_ap_params )->filter_coeff_den_real_fx = NULL; + } /* free pre-delay param buffer */ - IF((*ph_freq_domain_decorr_ap_params)->filter_coeff_den_real_fx != NULL) - { - free((*ph_freq_domain_decorr_ap_params)->filter_coeff_den_real_fx); - (*ph_freq_domain_decorr_ap_params)->filter_coeff_den_real_fx = NULL; - } - - /* free pre-delay param buffer */ - IF((*ph_freq_domain_decorr_ap_params)->phase_coeff_imag_fx != NULL) - { - free((*ph_freq_domain_decorr_ap_params)->phase_coeff_imag_fx); - (*ph_freq_domain_decorr_ap_params)->phase_coeff_imag_fx = NULL; - } - - /* free pre-delay param buffer */ - IF((*ph_freq_domain_decorr_ap_params)->phase_coeff_real_fx != NULL) - { - free((*ph_freq_domain_decorr_ap_params)->phase_coeff_real_fx); - (*ph_freq_domain_decorr_ap_params)->phase_coeff_real_fx = NULL; - } + IF( ( *ph_freq_domain_decorr_ap_params )->phase_coeff_imag_fx != NULL ) + { + free( ( *ph_freq_domain_decorr_ap_params )->phase_coeff_imag_fx ); + ( *ph_freq_domain_decorr_ap_params )->phase_coeff_imag_fx = NULL; + } + + /* free pre-delay param buffer */ + IF( ( *ph_freq_domain_decorr_ap_params )->phase_coeff_real_fx != NULL ) + { + free( ( *ph_freq_domain_decorr_ap_params )->phase_coeff_real_fx ); + ( *ph_freq_domain_decorr_ap_params )->phase_coeff_real_fx = NULL; + } #endif - /* free pointers to state and parameter structs */ - free(*ph_freq_domain_decorr_ap_params); - *ph_freq_domain_decorr_ap_params = NULL; + /* free pointers to state and parameter structs */ + free( *ph_freq_domain_decorr_ap_params ); + *ph_freq_domain_decorr_ap_params = NULL; - free(*ph_freq_domain_decorr_ap_state); - *ph_freq_domain_decorr_ap_state = NULL; + free( *ph_freq_domain_decorr_ap_state ); + *ph_freq_domain_decorr_ap_state = NULL; - return; + return; } #else void ivas_dirac_dec_decorr_close( @@ -1743,7 +1743,7 @@ static void get_lattice_coeffs_fx( { Word16 k; - FOR ( k = 0; k < ap_filter_length[band_index]; k++ ) + FOR( k = 0; k < ap_filter_length[band_index]; k++ ) { Word16 cur_lattice_coeff = ap_lattice_coeffs_fx[band_index][channel_index * ap_filter_length[band_index] + k]; lattice_coeffs[k] = cur_lattice_coeff; diff --git a/lib_rend/ivas_dirac_onsets_dec.c b/lib_rend/ivas_dirac_onsets_dec.c index ff9c0a573..123c9aec4 100644 --- a/lib_rend/ivas_dirac_onsets_dec.c +++ b/lib_rend/ivas_dirac_onsets_dec.c @@ -45,98 +45,98 @@ #include "prot_fx2.h" #ifdef IVAS_FLOAT_FIXED -static Word16 BASOP_Util_Cmp_Mant32Exp_sat(Word32 a_m, Word16 a_e, Word32 b_m, Word16 b_e); +static Word16 BASOP_Util_Cmp_Mant32Exp_sat( Word32 a_m, Word16 a_e, Word32 b_m, Word16 b_e ); Word16 BASOP_Util_Cmp_Mant32Exp_sat /*!< o: flag: result of comparison */ /* 0, if a == b */ /* 1, if a > b */ /* -1, if a < b */ - (Word32 a_m, /*!< i: Mantissa of 1st operand a */ + ( Word32 a_m, /*!< i: Mantissa of 1st operand a */ Word16 a_e, /*!< i: Exponent of 1st operand a */ Word32 b_m, /*!< i: Mantissa of 2nd operand b */ - Word16 b_e) /*!< i: Exponent of 2nd operand b */ + Word16 b_e ) /*!< i: Exponent of 2nd operand b */ { - Word32 diff_m; - Word16 diff_e, shift, result; - - - /* - This function compares two input parameters, both represented by a 32-bit mantissa and a 16-bit exponent. - If both values are identical, 0 is returned. - If a is greater b, 1 is returned. - If a is less than b, -1 is returned. - */ - - /* Check, if both mantissa and exponents are identical, when normalized: return 0 */ - shift = norm_l(a_m); - if (shift) - a_m = L_shl(a_m, shift); - if (shift) - a_e = sub(a_e, shift); - - shift = norm_l(b_m); - if (shift) - b_m = L_shl(b_m, shift); - if (shift) - b_e = sub(b_e, shift); - - /* align exponent, if any mantissa is zero */ - if (!a_m) - { - a_e = b_e; - move16(); - } - if (!b_m) - { - b_e = a_e; - move16(); - } - - BASOP_SATURATE_WARNING_OFF_EVS - diff_m = L_sub_sat(a_m, b_m); - BASOP_SATURATE_WARNING_ON_EVS - diff_e = sub(a_e, b_e); - - test(); - IF(diff_m == 0 && diff_e == 0) - { - return 0; - } - - /* Check sign, exponent and mantissa to identify, whether a is greater b or not */ - result = sub(0, 1); - - IF(a_m >= 0) - { - /* a is positive */ - if (b_m < 0) + Word32 diff_m; + Word16 diff_e, shift, result; + + + /* + This function compares two input parameters, both represented by a 32-bit mantissa and a 16-bit exponent. + If both values are identical, 0 is returned. + If a is greater b, 1 is returned. + If a is less than b, -1 is returned. + */ + + /* Check, if both mantissa and exponents are identical, when normalized: return 0 */ + shift = norm_l( a_m ); + if ( shift ) + a_m = L_shl( a_m, shift ); + if ( shift ) + a_e = sub( a_e, shift ); + + shift = norm_l( b_m ); + if ( shift ) + b_m = L_shl( b_m, shift ); + if ( shift ) + b_e = sub( b_e, shift ); + + /* align exponent, if any mantissa is zero */ + if ( !a_m ) { - result = 1; - move16(); + a_e = b_e; + move16(); + } + if ( !b_m ) + { + b_e = a_e; + move16(); } + BASOP_SATURATE_WARNING_OFF_EVS + diff_m = L_sub_sat( a_m, b_m ); + BASOP_SATURATE_WARNING_ON_EVS + diff_e = sub( a_e, b_e ); + test(); - test(); - test(); - if ((b_m >= 0) && ((diff_e > 0) || (diff_e == 0 && diff_m > 0))) + IF( diff_m == 0 && diff_e == 0 ) { - result = 1; - move16(); + return 0; } - } - ELSE - { - /* a is negative */ - test(); - test(); - test(); - if ((b_m < 0) && ((diff_e < 0) || (diff_e == 0 && diff_m > 0))) + + /* Check sign, exponent and mantissa to identify, whether a is greater b or not */ + result = sub( 0, 1 ); + + IF( a_m >= 0 ) { - result = 1; - move16(); + /* a is positive */ + if ( b_m < 0 ) + { + result = 1; + move16(); + } + + test(); + test(); + test(); + if ( ( b_m >= 0 ) && ( ( diff_e > 0 ) || ( diff_e == 0 && diff_m > 0 ) ) ) + { + result = 1; + move16(); + } + } + ELSE + { + /* a is negative */ + test(); + test(); + test(); + if ( ( b_m < 0 ) && ( ( diff_e < 0 ) || ( diff_e == 0 && diff_m > 0 ) ) ) + { + result = 1; + move16(); + } } - } - return result; + return result; } #endif @@ -210,8 +210,8 @@ ivas_error ivas_dirac_dec_onset_detection_open_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for onset detection\n" ) ); } /* init to zero */ - set32_fx(dirac_onset_detection_state->onset_detector_1_fx, 0, num_protos_diff * dirac_onset_detection_params->max_band_decorr); - set32_fx(dirac_onset_detection_state->onset_detector_2_fx, 0, num_protos_diff * dirac_onset_detection_params->max_band_decorr); + set32_fx( dirac_onset_detection_state->onset_detector_1_fx, 0, num_protos_diff * dirac_onset_detection_params->max_band_decorr ); + set32_fx( dirac_onset_detection_state->onset_detector_2_fx, 0, num_protos_diff * dirac_onset_detection_params->max_band_decorr ); dirac_onset_detection_state->q_onset_detector = Q31; return IVAS_ERR_OK; diff --git a/lib_rend/ivas_dirac_output_synthesis_dec.c b/lib_rend/ivas_dirac_output_synthesis_dec.c index 5b6d45603..c9148973b 100644 --- a/lib_rend/ivas_dirac_output_synthesis_dec.c +++ b/lib_rend/ivas_dirac_output_synthesis_dec.c @@ -121,7 +121,7 @@ static void normalizePanningGains( float *direct_response, const int16_t num_cha *------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -extern Word16 find_guarded_bits_fx(Word32 n); +extern Word16 find_guarded_bits_fx( Word32 n ); ivas_error ivas_dirac_dec_output_synthesis_open_fx( SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */ @@ -150,7 +150,7 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( assert( hDirACRend->hOutSetup.is_loudspeaker_setup == 0 || hDirACRend->hOutSetup.is_loudspeaker_setup == 1 ); assert( hDirACRend->diffuse_response_function_fx != NULL ); - IF ( hDirACRend->proto_signal_decorr_on ) + IF( hDirACRend->proto_signal_decorr_on ) { dirac_output_synthesis_params->max_band_decorr = hDirACRend->h_freq_domain_decorr_ap_params->max_band_decorr; } @@ -165,14 +165,14 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( dirac_output_synthesis_state->diffuse_responses_square_fx = NULL; - IF ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO ) + IF( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO ) { IF( ( dirac_output_synthesis_state->diffuse_responses_square_fx = (Word32 *) malloc( 2 * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } } - ELSE IF ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) + ELSE IF( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) { IF( ( dirac_output_synthesis_state->diffuse_responses_square_fx = (Word32 *) malloc( hDirACRend->hOutSetup.nchan_out_woLFE * sizeof( Word32 ) ) ) == NULL ) { @@ -184,7 +184,7 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( dirac_output_synthesis_state->proto_power_smooth_prev = NULL; dirac_output_synthesis_state->proto_power_smooth_prev_fx = NULL; - IF ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) + IF( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) { /*TODO : remove float code*/ if ( ( dirac_output_synthesis_state->proto_power_smooth_prev = (float *) malloc( hSpatParamRendCom->num_freq_bands * hDirACRend->num_protos_dir * sizeof( float ) ) ) == NULL ) @@ -197,7 +197,7 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( } dirac_output_synthesis_state->proto_power_smooth_prev_len = hSpatParamRendCom->num_freq_bands * hDirACRend->num_protos_dir; } - IF ( dirac_output_synthesis_params->max_band_decorr > 0 && ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS || hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) ) + IF( dirac_output_synthesis_params->max_band_decorr > 0 && ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS || hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) ) { /*TODO : remove float code*/ if ( ( dirac_output_synthesis_state->proto_power_diff_smooth_prev = (float *) malloc( dirac_output_synthesis_params->max_band_decorr * hDirACRend->hOutSetup.nchan_out_woLFE * sizeof( float ) ) ) == NULL ) @@ -218,13 +218,13 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( } /* buffer length and interpolator */ - IF ((dirac_output_synthesis_params->interpolator_fx = (Word16 *)malloc(JBM_CLDFB_SLOTS_IN_SUBFRAME * sizeof(Word16))) == NULL) + IF( ( dirac_output_synthesis_params->interpolator_fx = (Word16 *) malloc( JBM_CLDFB_SLOTS_IN_SUBFRAME * sizeof( Word16 ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } /* target PSD buffers */ - IF ( hodirac_flag ) + IF( hodirac_flag ) { size = hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir * DIRAC_HO_NUMSECTORS; } @@ -242,7 +242,7 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } dirac_output_synthesis_state->cy_cross_dir_smooth_prev_len = size; - IF ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) + IF( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { /*TODO : remove float code*/ dirac_output_synthesis_state->cy_auto_dir_smooth_prev = NULL; @@ -314,7 +314,7 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } dirac_output_synthesis_state->gains_dir_prev_len = size; - IF ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) + IF( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { /*TODO : remove float code*/ if ( ( dirac_output_synthesis_state->gains_diff_prev = (float *) malloc( dirac_output_synthesis_params->max_band_decorr * hDirACRend->num_outputs_diff * sizeof( float ) ) ) == NULL ) @@ -327,7 +327,7 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( } dirac_output_synthesis_state->gains_diff_prev_len = dirac_output_synthesis_params->max_band_decorr * hDirACRend->num_outputs_diff; } - ELSE IF ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_PSD_SHD && hDirACRend->synthesisConf != DIRAC_SYNTHESIS_MONO ) + ELSE IF( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_PSD_SHD && hDirACRend->synthesisConf != DIRAC_SYNTHESIS_MONO ) { /*TODO : remove float code*/ if ( ( dirac_output_synthesis_state->gains_diff_prev = (float *) malloc( hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff * sizeof( float ) ) ) == NULL ) @@ -359,23 +359,23 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( *-----------------------------------------------------------------*/ /* compute alpha */ - IF ( !( renderer_type == RENDERER_BINAURAL_PARAMETRIC || renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) ) + IF( !( renderer_type == RENDERER_BINAURAL_PARAMETRIC || renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) ) { - computeAlphaSynthesis_fx(temp_alpha_synthesis_fx, DIRAC_AVG_LENGTH_SYNTH_MS, DIRAC_ALPHA_MAX_Q15, &dirac_output_synthesis_params->numAlphas, hSpatParamRendCom->slot_size, hSpatParamRendCom->num_freq_bands, hDirACRend->frequency_axis_fx, output_Fs); + computeAlphaSynthesis_fx( temp_alpha_synthesis_fx, DIRAC_AVG_LENGTH_SYNTH_MS, DIRAC_ALPHA_MAX_Q15, &dirac_output_synthesis_params->numAlphas, hSpatParamRendCom->slot_size, hSpatParamRendCom->num_freq_bands, hDirACRend->frequency_axis_fx, output_Fs ); - IF((dirac_output_synthesis_params->alpha_synthesis_fx = (Word16 *)malloc(dirac_output_synthesis_params->numAlphas * sizeof(Word16))) == NULL) + IF( ( dirac_output_synthesis_params->alpha_synthesis_fx = (Word16 *) malloc( dirac_output_synthesis_params->numAlphas * sizeof( Word16 ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } - Copy(temp_alpha_synthesis_fx, dirac_output_synthesis_params->alpha_synthesis_fx, dirac_output_synthesis_params->numAlphas); + Copy( temp_alpha_synthesis_fx, dirac_output_synthesis_params->alpha_synthesis_fx, dirac_output_synthesis_params->numAlphas ); - computeAlphaSynthesis_fx( temp_alpha_synthesis_fx, DIRAC_AVG_LENGTH_SYNTH_MS_FAST, DIRAC_ALPHA_MAX_FAST_Q15, &dirac_output_synthesis_params->numAlphasFast, hSpatParamRendCom->slot_size, hSpatParamRendCom->num_freq_bands , hDirACRend->frequency_axis_fx, output_Fs); + computeAlphaSynthesis_fx( temp_alpha_synthesis_fx, DIRAC_AVG_LENGTH_SYNTH_MS_FAST, DIRAC_ALPHA_MAX_FAST_Q15, &dirac_output_synthesis_params->numAlphasFast, hSpatParamRendCom->slot_size, hSpatParamRendCom->num_freq_bands, hDirACRend->frequency_axis_fx, output_Fs ); - IF ((dirac_output_synthesis_params->alpha_synthesis_fast_fx = (Word16 *)malloc(dirac_output_synthesis_params->numAlphasFast * sizeof(Word16))) == NULL) + IF( ( dirac_output_synthesis_params->alpha_synthesis_fast_fx = (Word16 *) malloc( dirac_output_synthesis_params->numAlphasFast * sizeof( Word16 ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } - Copy(temp_alpha_synthesis_fx, dirac_output_synthesis_params->alpha_synthesis_fast_fx, dirac_output_synthesis_params->numAlphasFast); + Copy( temp_alpha_synthesis_fx, dirac_output_synthesis_params->alpha_synthesis_fast_fx, dirac_output_synthesis_params->numAlphasFast ); IF( ( dirac_output_synthesis_state->reference_power_smooth_prev_fx = (Word32 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( Word32 ) ) ) == NULL ) { @@ -405,7 +405,7 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( } /* prepare diffuse response function */ - IF ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO ) + IF( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO ) { num_diffuse_responses = 2; } @@ -414,9 +414,9 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( num_diffuse_responses = hDirACRend->hOutSetup.nchan_out_woLFE; } - IF (dirac_output_synthesis_state->diffuse_responses_square_fx != NULL) + IF( dirac_output_synthesis_state->diffuse_responses_square_fx != NULL ) { - FOR (ch_idx = 0; ch_idx < num_diffuse_responses; ++ch_idx) + FOR( ch_idx = 0; ch_idx < num_diffuse_responses; ++ch_idx ) { /*dirac_output_synthesis_state->diffuse_responses_square[ch_idx] = pow(dirac_output_synthesis_params->diffuse_response_function[ch_idx]/max_response, 2.0f);*/ tmp_fx = hDirACRend->diffuse_response_function_fx[ch_idx]; @@ -427,35 +427,35 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( } } - - IF (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD) + + IF( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { Word16 diff_compensation_order; Word32 diff_nrg_total_fx, diff_nrg_fx, diff_nrg_trans_fx, diff_nrg_decorr_fx; diff_compensation_order = nchan_transport >= 3 ? 3 : 2; /* compensate missing diffuseness modelling up order 2, except for HR*/ - diff_compensation_order = s_min(diff_compensation_order, hDirACRend->hOutSetup.ambisonics_order); + diff_compensation_order = s_min( diff_compensation_order, hDirACRend->hOutSetup.ambisonics_order ); diff_nrg_total_fx = 0; diff_nrg_trans_fx = 0; diff_nrg_decorr_fx = 0; - Word16 gaurd_bits = find_guarded_bits_fx((diff_compensation_order + 1) * (diff_compensation_order + 1)); - FOR (ch_idx = 0; ch_idx < (diff_compensation_order + 1) * (diff_compensation_order + 1); ch_idx++) + Word16 gaurd_bits = find_guarded_bits_fx( ( diff_compensation_order + 1 ) * ( diff_compensation_order + 1 ) ); + FOR( ch_idx = 0; ch_idx < ( diff_compensation_order + 1 ) * ( diff_compensation_order + 1 ); ch_idx++ ) { - diff_nrg_fx = L_shr(L_mult0(hDirACRend->diffuse_response_function_fx[ch_idx], hDirACRend->diffuse_response_function_fx[ch_idx]), gaurd_bits);//Q30 - gaurd_bits + diff_nrg_fx = L_shr( L_mult0( hDirACRend->diffuse_response_function_fx[ch_idx], hDirACRend->diffuse_response_function_fx[ch_idx] ), gaurd_bits ); // Q30 - gaurd_bits - diff_nrg_total_fx = L_add(diff_nrg_total_fx, diff_nrg_fx); + diff_nrg_total_fx = L_add( diff_nrg_total_fx, diff_nrg_fx ); /* is it a transport channel?*/ - IF (ch_idx == 0 || hDirACRend->proto_index_dir[ch_idx] != 0) + IF( ch_idx == 0 || hDirACRend->proto_index_dir[ch_idx] != 0 ) { - diff_nrg_trans_fx = L_add(diff_nrg_trans_fx, diff_nrg_fx); + diff_nrg_trans_fx = L_add( diff_nrg_trans_fx, diff_nrg_fx ); } /* is it a decorrelated or transport channel?*/ - IF (ch_idx < hDirACRend->num_outputs_diff) + IF( ch_idx < hDirACRend->num_outputs_diff ) { - diff_nrg_decorr_fx = L_add(diff_nrg_decorr_fx, diff_nrg_fx); + diff_nrg_decorr_fx = L_add( diff_nrg_decorr_fx, diff_nrg_fx ); } } Word16 exp_1 = 0, exp_2 = 0, tmp; @@ -490,18 +490,18 @@ ivas_error ivas_dirac_dec_output_synthesis_open( float temp_alpha_synthesis[CLDFB_NO_CHANNELS_MAX]; /* pointers to structs for allocation */ - DIRAC_OUTPUT_SYNTHESIS_PARAMS *dirac_output_synthesis_params = &(hDirACRend->h_output_synthesis_psd_params); - DIRAC_OUTPUT_SYNTHESIS_STATE *dirac_output_synthesis_state = &(hDirACRend->h_output_synthesis_psd_state); + DIRAC_OUTPUT_SYNTHESIS_PARAMS *dirac_output_synthesis_params = &( hDirACRend->h_output_synthesis_psd_params ); + DIRAC_OUTPUT_SYNTHESIS_STATE *dirac_output_synthesis_state = &( hDirACRend->h_output_synthesis_psd_state ); /* check / set input parameters */ - assert(hSpatParamRendCom->num_freq_bands > 0 && "Error: Number of frequency bands <= 0!"); - assert(hDirACRend->hOutSetup.nchan_out_woLFE > 0 && "Error: Number of output channels > 0!"); - assert(hDirACRend->num_outputs_diff > 0); - assert(hSpatParamRendCom->slot_size > 0); - assert(hDirACRend->hOutSetup.is_loudspeaker_setup == 0 || hDirACRend->hOutSetup.is_loudspeaker_setup == 1); - assert(hDirACRend->diffuse_response_function != NULL); + assert( hSpatParamRendCom->num_freq_bands > 0 && "Error: Number of frequency bands <= 0!" ); + assert( hDirACRend->hOutSetup.nchan_out_woLFE > 0 && "Error: Number of output channels > 0!" ); + assert( hDirACRend->num_outputs_diff > 0 ); + assert( hSpatParamRendCom->slot_size > 0 ); + assert( hDirACRend->hOutSetup.is_loudspeaker_setup == 0 || hDirACRend->hOutSetup.is_loudspeaker_setup == 1 ); + assert( hDirACRend->diffuse_response_function != NULL ); - if (hDirACRend->proto_signal_decorr_on) + if ( hDirACRend->proto_signal_decorr_on ) { dirac_output_synthesis_params->max_band_decorr = hDirACRend->h_freq_domain_decorr_ap_params->max_band_decorr; } @@ -515,35 +515,35 @@ ivas_error ivas_dirac_dec_output_synthesis_open( *-----------------------------------------------------------------*/ dirac_output_synthesis_state->diffuse_responses_square = NULL; - if (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO) + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO ) { - if ((dirac_output_synthesis_state->diffuse_responses_square = (float *)malloc(2 * sizeof(float))) == NULL) + if ( ( dirac_output_synthesis_state->diffuse_responses_square = (float *) malloc( 2 * sizeof( float ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } } - else if (hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD) + else if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) { - if ((dirac_output_synthesis_state->diffuse_responses_square = (float *)malloc(hDirACRend->hOutSetup.nchan_out_woLFE * sizeof(float))) == NULL) + if ( ( dirac_output_synthesis_state->diffuse_responses_square = (float *) malloc( hDirACRend->hOutSetup.nchan_out_woLFE * sizeof( float ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } } /* prototype power buffers */ dirac_output_synthesis_state->proto_power_smooth_prev = NULL; - if (hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD) + if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) { - if ((dirac_output_synthesis_state->proto_power_smooth_prev = (float *)malloc(hSpatParamRendCom->num_freq_bands * hDirACRend->num_protos_dir * sizeof(float))) == NULL) + if ( ( dirac_output_synthesis_state->proto_power_smooth_prev = (float *) malloc( hSpatParamRendCom->num_freq_bands * hDirACRend->num_protos_dir * sizeof( float ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } } - if (dirac_output_synthesis_params->max_band_decorr > 0 && (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS || hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD)) + if ( dirac_output_synthesis_params->max_band_decorr > 0 && ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS || hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) ) { - if ((dirac_output_synthesis_state->proto_power_diff_smooth_prev = (float *)malloc(dirac_output_synthesis_params->max_band_decorr * hDirACRend->hOutSetup.nchan_out_woLFE * sizeof(float))) == NULL) + if ( ( dirac_output_synthesis_state->proto_power_diff_smooth_prev = (float *) malloc( dirac_output_synthesis_params->max_band_decorr * hDirACRend->hOutSetup.nchan_out_woLFE * sizeof( float ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } } else @@ -552,13 +552,13 @@ ivas_error ivas_dirac_dec_output_synthesis_open( } /* buffer length and interpolator */ - if ((dirac_output_synthesis_params->interpolator = (float *)malloc(JBM_CLDFB_SLOTS_IN_SUBFRAME * sizeof(float))) == NULL) + if ( ( dirac_output_synthesis_params->interpolator = (float *) malloc( JBM_CLDFB_SLOTS_IN_SUBFRAME * sizeof( float ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } /* target PSD buffers */ - if (hodirac_flag) + if ( hodirac_flag ) { size = hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir * DIRAC_HO_NUMSECTORS; } @@ -566,67 +566,67 @@ ivas_error ivas_dirac_dec_output_synthesis_open( { size = hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir; } - if ((dirac_output_synthesis_state->cy_cross_dir_smooth_prev = (float *)malloc(size * sizeof(float))) == NULL) + if ( ( dirac_output_synthesis_state->cy_cross_dir_smooth_prev = (float *) malloc( size * sizeof( float ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } - if (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD) + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { dirac_output_synthesis_state->cy_auto_dir_smooth_prev = NULL; - if ((dirac_output_synthesis_state->cy_auto_diff_smooth_prev = (float *)malloc(dirac_output_synthesis_params->max_band_decorr * hDirACRend->num_outputs_diff * sizeof(float))) == NULL) + if ( ( dirac_output_synthesis_state->cy_auto_diff_smooth_prev = (float *) malloc( dirac_output_synthesis_params->max_band_decorr * hDirACRend->num_outputs_diff * sizeof( float ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } } else { - if ((dirac_output_synthesis_state->cy_auto_dir_smooth_prev = (float *)malloc(hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir * sizeof(float))) == NULL) + if ( ( dirac_output_synthesis_state->cy_auto_dir_smooth_prev = (float *) malloc( hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir * sizeof( float ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } - if (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD) + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) { - if ((dirac_output_synthesis_state->cy_auto_diff_smooth_prev = (float *)malloc(hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir * sizeof(float))) == NULL) + if ( ( dirac_output_synthesis_state->cy_auto_diff_smooth_prev = (float *) malloc( hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir * sizeof( float ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } } else { - if ((dirac_output_synthesis_state->cy_auto_diff_smooth_prev = (float *)malloc(hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff * sizeof(float))) == NULL) + if ( ( dirac_output_synthesis_state->cy_auto_diff_smooth_prev = (float *) malloc( hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff * sizeof( float ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } } } /* direct and diffuse gain buffers */ - if ((dirac_output_synthesis_state->gains_dir_prev = (float *)malloc(size * sizeof(float))) == NULL) + if ( ( dirac_output_synthesis_state->gains_dir_prev = (float *) malloc( size * sizeof( float ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } - if (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD) + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { - if ((dirac_output_synthesis_state->gains_diff_prev = (float *)malloc(dirac_output_synthesis_params->max_band_decorr * hDirACRend->num_outputs_diff * sizeof(float))) == NULL) + if ( ( dirac_output_synthesis_state->gains_diff_prev = (float *) malloc( dirac_output_synthesis_params->max_band_decorr * hDirACRend->num_outputs_diff * sizeof( float ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } } - else if (hDirACRend->synthesisConf != DIRAC_SYNTHESIS_PSD_SHD && hDirACRend->synthesisConf != DIRAC_SYNTHESIS_MONO) + else if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_PSD_SHD && hDirACRend->synthesisConf != DIRAC_SYNTHESIS_MONO ) { - if ((dirac_output_synthesis_state->gains_diff_prev = (float *)malloc(hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff * sizeof(float))) == NULL) + if ( ( dirac_output_synthesis_state->gains_diff_prev = (float *) malloc( hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff * sizeof( float ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } } else { - if ((dirac_output_synthesis_state->gains_diff_prev = (float *)malloc(hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir * sizeof(float))) == NULL) + if ( ( dirac_output_synthesis_state->gains_diff_prev = (float *) malloc( hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir * sizeof( float ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } } @@ -634,33 +634,33 @@ ivas_error ivas_dirac_dec_output_synthesis_open( * prepare processing parameters *-----------------------------------------------------------------*/ - /* compute alpha */ - if (!(renderer_type == RENDERER_BINAURAL_PARAMETRIC || renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD)) + /* compute alpha */ + if ( !( renderer_type == RENDERER_BINAURAL_PARAMETRIC || renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) ) { - computeAlphaSynthesis(temp_alpha_synthesis, DIRAC_AVG_LENGTH_SYNTH_MS, DIRAC_ALPHA_MAX, &dirac_output_synthesis_params->numAlphas, hSpatParamRendCom->slot_size, hSpatParamRendCom->num_freq_bands, hDirACRend->frequency_axis, output_Fs); - if ((dirac_output_synthesis_params->alpha_synthesis = (float *)malloc(dirac_output_synthesis_params->numAlphas * sizeof(float))) == NULL) + computeAlphaSynthesis( temp_alpha_synthesis, DIRAC_AVG_LENGTH_SYNTH_MS, DIRAC_ALPHA_MAX, &dirac_output_synthesis_params->numAlphas, hSpatParamRendCom->slot_size, hSpatParamRendCom->num_freq_bands, hDirACRend->frequency_axis, output_Fs ); + if ( ( dirac_output_synthesis_params->alpha_synthesis = (float *) malloc( dirac_output_synthesis_params->numAlphas * sizeof( float ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } - mvr2r(temp_alpha_synthesis, dirac_output_synthesis_params->alpha_synthesis, dirac_output_synthesis_params->numAlphas); + mvr2r( temp_alpha_synthesis, dirac_output_synthesis_params->alpha_synthesis, dirac_output_synthesis_params->numAlphas ); - computeAlphaSynthesis(temp_alpha_synthesis, DIRAC_AVG_LENGTH_SYNTH_MS_FAST, DIRAC_ALPHA_MAX_FAST, &dirac_output_synthesis_params->numAlphasFast, hSpatParamRendCom->slot_size, hSpatParamRendCom->num_freq_bands, hDirACRend->frequency_axis, output_Fs); - if ((dirac_output_synthesis_params->alpha_synthesis_fast = (float *)malloc(dirac_output_synthesis_params->numAlphasFast * sizeof(float))) == NULL) + computeAlphaSynthesis( temp_alpha_synthesis, DIRAC_AVG_LENGTH_SYNTH_MS_FAST, DIRAC_ALPHA_MAX_FAST, &dirac_output_synthesis_params->numAlphasFast, hSpatParamRendCom->slot_size, hSpatParamRendCom->num_freq_bands, hDirACRend->frequency_axis, output_Fs ); + if ( ( dirac_output_synthesis_params->alpha_synthesis_fast = (float *) malloc( dirac_output_synthesis_params->numAlphasFast * sizeof( float ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } - mvr2r(temp_alpha_synthesis, dirac_output_synthesis_params->alpha_synthesis_fast, dirac_output_synthesis_params->numAlphasFast); + mvr2r( temp_alpha_synthesis, dirac_output_synthesis_params->alpha_synthesis_fast, dirac_output_synthesis_params->numAlphasFast ); - if ((dirac_output_synthesis_state->reference_power_smooth_prev = (float *)malloc(hSpatParamRendCom->num_freq_bands * sizeof(float))) == NULL) + if ( ( dirac_output_synthesis_state->reference_power_smooth_prev = (float *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( float ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } - if ((dirac_output_synthesis_state->direction_smoothness_prev = (float *)malloc(hSpatParamRendCom->num_freq_bands * sizeof(float))) == NULL) + if ( ( dirac_output_synthesis_state->direction_smoothness_prev = (float *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( float ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } - set_zero(dirac_output_synthesis_state->reference_power_smooth_prev, hSpatParamRendCom->num_freq_bands); - set_zero(dirac_output_synthesis_state->direction_smoothness_prev, hSpatParamRendCom->num_freq_bands); + set_zero( dirac_output_synthesis_state->reference_power_smooth_prev, hSpatParamRendCom->num_freq_bands ); + set_zero( dirac_output_synthesis_state->direction_smoothness_prev, hSpatParamRendCom->num_freq_bands ); } else { @@ -671,13 +671,13 @@ ivas_error ivas_dirac_dec_output_synthesis_open( } /* compute interpolator */ - for (idx = 1; idx <= JBM_CLDFB_SLOTS_IN_SUBFRAME; ++idx) + for ( idx = 1; idx <= JBM_CLDFB_SLOTS_IN_SUBFRAME; ++idx ) { - dirac_output_synthesis_params->interpolator[idx - 1] = (float)idx / (float)JBM_CLDFB_SLOTS_IN_SUBFRAME; + dirac_output_synthesis_params->interpolator[idx - 1] = (float) idx / (float) JBM_CLDFB_SLOTS_IN_SUBFRAME; } /* prepare diffuse response function */ - if (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO) + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO ) { num_diffuse_responses = 2; } @@ -686,9 +686,9 @@ ivas_error ivas_dirac_dec_output_synthesis_open( num_diffuse_responses = hDirACRend->hOutSetup.nchan_out_woLFE; } - if (dirac_output_synthesis_state->diffuse_responses_square != NULL) + if ( dirac_output_synthesis_state->diffuse_responses_square != NULL ) { - for (ch_idx = 0; ch_idx < num_diffuse_responses; ++ch_idx) + for ( ch_idx = 0; ch_idx < num_diffuse_responses; ++ch_idx ) { /*dirac_output_synthesis_state->diffuse_responses_square[ch_idx] = pow(dirac_output_synthesis_params->diffuse_response_function[ch_idx]/max_response, 2.0f);*/ tmp = hDirACRend->diffuse_response_function[ch_idx]; @@ -697,28 +697,28 @@ ivas_error ivas_dirac_dec_output_synthesis_open( } } - if (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD) + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { int16_t diff_compensation_order; float diff_nrg_total, diff_nrg, diff_nrg_trans, diff_nrg_decorr; diff_compensation_order = nchan_transport >= 3 ? 3 : 2; /* compensate missing diffuseness modelling up order 2, except for HR*/ - diff_compensation_order = min(diff_compensation_order, hDirACRend->hOutSetup.ambisonics_order); + diff_compensation_order = min( diff_compensation_order, hDirACRend->hOutSetup.ambisonics_order ); diff_nrg_total = 0; diff_nrg_trans = 0; diff_nrg_decorr = 0; - for (ch_idx = 0; ch_idx < (diff_compensation_order + 1) * (diff_compensation_order + 1); ch_idx++) + for ( ch_idx = 0; ch_idx < ( diff_compensation_order + 1 ) * ( diff_compensation_order + 1 ); ch_idx++ ) { diff_nrg = hDirACRend->diffuse_response_function[ch_idx] * hDirACRend->diffuse_response_function[ch_idx]; diff_nrg_total += diff_nrg; /* is it a transport channel?*/ - if (ch_idx == 0 || hDirACRend->proto_index_dir[ch_idx] != 0) + if ( ch_idx == 0 || hDirACRend->proto_index_dir[ch_idx] != 0 ) { diff_nrg_trans += diff_nrg; } /* is it a decorrelated or transport channel?*/ - if (ch_idx < hDirACRend->num_outputs_diff) + if ( ch_idx < hDirACRend->num_outputs_diff ) { diff_nrg_decorr += diff_nrg; } @@ -818,8 +818,8 @@ void ivas_dirac_dec_output_synthesis_init( void ivas_dirac_dec_output_synthesis_init_fx( SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */ DIRAC_REND_HANDLE hDirACRend, /* i/o: DirAC renderer handle */ - const Word16 nchan_out_woLFE, /* i : number of output audio channels without LFE */ - const Word16 hodirac_flag /* i : flag to indicate HO-DirAC mode */ + const Word16 nchan_out_woLFE, /* i : number of output audio channels without LFE */ + const Word16 hodirac_flag /* i : flag to indicate HO-DirAC mode */ ) { Word16 size; @@ -827,20 +827,20 @@ void ivas_dirac_dec_output_synthesis_init_fx( DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params; DIRAC_OUTPUT_SYNTHESIS_STATE *h_dirac_output_synthesis_state; - h_dirac_output_synthesis_params = &(hDirACRend->h_output_synthesis_psd_params); - h_dirac_output_synthesis_state = &(hDirACRend->h_output_synthesis_psd_state); + h_dirac_output_synthesis_params = &( hDirACRend->h_output_synthesis_psd_params ); + h_dirac_output_synthesis_state = &( hDirACRend->h_output_synthesis_psd_state ); /*-----------------------------------------------------------------* * init outputSynthesisPSD_Init *-----------------------------------------------------------------*/ - /* initialize buffers */ - if (h_dirac_output_synthesis_state->cy_auto_dir_smooth_prev != NULL) + /* initialize buffers */ + if ( h_dirac_output_synthesis_state->cy_auto_dir_smooth_prev != NULL ) { - set_zero(h_dirac_output_synthesis_state->cy_auto_dir_smooth_prev, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir); + set_zero( h_dirac_output_synthesis_state->cy_auto_dir_smooth_prev, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir ); } - if (hodirac_flag) + if ( hodirac_flag ) { size = hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir * DIRAC_HO_NUMSECTORS; } @@ -848,39 +848,39 @@ void ivas_dirac_dec_output_synthesis_init_fx( { size = hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir; } - set_zero(h_dirac_output_synthesis_state->cy_cross_dir_smooth_prev, size); + set_zero( h_dirac_output_synthesis_state->cy_cross_dir_smooth_prev, size ); - if (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD) + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { - set_zero(h_dirac_output_synthesis_state->cy_auto_diff_smooth_prev, h_dirac_output_synthesis_params->max_band_decorr * hDirACRend->num_outputs_diff); + set_zero( h_dirac_output_synthesis_state->cy_auto_diff_smooth_prev, h_dirac_output_synthesis_params->max_band_decorr * hDirACRend->num_outputs_diff ); } - else if (hDirACRend->synthesisConf != DIRAC_SYNTHESIS_PSD_SHD) + else if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_PSD_SHD ) { - set_zero(h_dirac_output_synthesis_state->cy_auto_diff_smooth_prev, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff); + set_zero( h_dirac_output_synthesis_state->cy_auto_diff_smooth_prev, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff ); } else { - set_zero(h_dirac_output_synthesis_state->cy_auto_diff_smooth_prev, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir); + set_zero( h_dirac_output_synthesis_state->cy_auto_diff_smooth_prev, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir ); } - if (h_dirac_output_synthesis_state->proto_power_smooth_prev != NULL) + if ( h_dirac_output_synthesis_state->proto_power_smooth_prev != NULL ) { - set_zero(h_dirac_output_synthesis_state->proto_power_smooth_prev, hSpatParamRendCom->num_freq_bands * hDirACRend->num_protos_dir); + set_zero( h_dirac_output_synthesis_state->proto_power_smooth_prev, hSpatParamRendCom->num_freq_bands * hDirACRend->num_protos_dir ); } - set_zero(h_dirac_output_synthesis_state->gains_dir_prev, size); + set_zero( h_dirac_output_synthesis_state->gains_dir_prev, size ); - if (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD) + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { - set_zero(h_dirac_output_synthesis_state->gains_diff_prev, h_dirac_output_synthesis_params->max_band_decorr * hDirACRend->num_outputs_diff); + set_zero( h_dirac_output_synthesis_state->gains_diff_prev, h_dirac_output_synthesis_params->max_band_decorr * hDirACRend->num_outputs_diff ); } else { - set_zero(h_dirac_output_synthesis_state->gains_diff_prev, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir); + set_zero( h_dirac_output_synthesis_state->gains_diff_prev, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir ); } - if (h_dirac_output_synthesis_state->proto_power_diff_smooth_prev != NULL) + if ( h_dirac_output_synthesis_state->proto_power_diff_smooth_prev != NULL ) { - set_zero(h_dirac_output_synthesis_state->proto_power_diff_smooth_prev, h_dirac_output_synthesis_params->max_band_decorr * nchan_out_woLFE); + set_zero( h_dirac_output_synthesis_state->proto_power_diff_smooth_prev, h_dirac_output_synthesis_params->max_band_decorr * nchan_out_woLFE ); } #ifdef IVAS_FLOAT_FIXED @@ -1050,133 +1050,133 @@ void ivas_dirac_dec_output_synthesis_close_fx( ) { /* pointers to structs for allocation */ - DIRAC_OUTPUT_SYNTHESIS_PARAMS *dirac_output_synthesis_params = &(hDirACRend->h_output_synthesis_psd_params); - DIRAC_OUTPUT_SYNTHESIS_STATE *dirac_output_synthesis_state = &(hDirACRend->h_output_synthesis_psd_state); + DIRAC_OUTPUT_SYNTHESIS_PARAMS *dirac_output_synthesis_params = &( hDirACRend->h_output_synthesis_psd_params ); + DIRAC_OUTPUT_SYNTHESIS_STATE *dirac_output_synthesis_state = &( hDirACRend->h_output_synthesis_psd_state ); /*-----------------------------------------------------------------* * memory deallocation *-----------------------------------------------------------------*/ /* free power buffers */ - if ((dirac_output_synthesis_state)->proto_power_smooth_prev != NULL) + if ( ( dirac_output_synthesis_state )->proto_power_smooth_prev != NULL ) { - free((dirac_output_synthesis_state)->proto_power_smooth_prev); - (dirac_output_synthesis_state)->proto_power_smooth_prev = NULL; + free( ( dirac_output_synthesis_state )->proto_power_smooth_prev ); + ( dirac_output_synthesis_state )->proto_power_smooth_prev = NULL; } - if ((dirac_output_synthesis_state)->proto_power_diff_smooth_prev != NULL) + if ( ( dirac_output_synthesis_state )->proto_power_diff_smooth_prev != NULL ) { - free((dirac_output_synthesis_state)->proto_power_diff_smooth_prev); - (dirac_output_synthesis_state)->proto_power_diff_smooth_prev = NULL; + free( ( dirac_output_synthesis_state )->proto_power_diff_smooth_prev ); + ( dirac_output_synthesis_state )->proto_power_diff_smooth_prev = NULL; } /* free target power buffers */ - if ((dirac_output_synthesis_state)->cy_auto_dir_smooth_prev != NULL) + if ( ( dirac_output_synthesis_state )->cy_auto_dir_smooth_prev != NULL ) { - free((dirac_output_synthesis_state)->cy_auto_dir_smooth_prev); - (dirac_output_synthesis_state)->cy_auto_dir_smooth_prev = NULL; + free( ( dirac_output_synthesis_state )->cy_auto_dir_smooth_prev ); + ( dirac_output_synthesis_state )->cy_auto_dir_smooth_prev = NULL; } - if ((dirac_output_synthesis_state)->cy_cross_dir_smooth_prev != NULL) + if ( ( dirac_output_synthesis_state )->cy_cross_dir_smooth_prev != NULL ) { - free((dirac_output_synthesis_state)->cy_cross_dir_smooth_prev); - (dirac_output_synthesis_state)->cy_cross_dir_smooth_prev = NULL; + free( ( dirac_output_synthesis_state )->cy_cross_dir_smooth_prev ); + ( dirac_output_synthesis_state )->cy_cross_dir_smooth_prev = NULL; } - if ((dirac_output_synthesis_state)->cy_auto_diff_smooth_prev != NULL) + if ( ( dirac_output_synthesis_state )->cy_auto_diff_smooth_prev != NULL ) { - free((dirac_output_synthesis_state)->cy_auto_diff_smooth_prev); - (dirac_output_synthesis_state)->cy_auto_diff_smooth_prev = NULL; + free( ( dirac_output_synthesis_state )->cy_auto_diff_smooth_prev ); + ( dirac_output_synthesis_state )->cy_auto_diff_smooth_prev = NULL; } /* free gain buffers */ - if ((dirac_output_synthesis_state)->gains_dir_prev != NULL) + if ( ( dirac_output_synthesis_state )->gains_dir_prev != NULL ) { - free((dirac_output_synthesis_state)->gains_dir_prev); - (dirac_output_synthesis_state)->gains_dir_prev = NULL; + free( ( dirac_output_synthesis_state )->gains_dir_prev ); + ( dirac_output_synthesis_state )->gains_dir_prev = NULL; } - if ((dirac_output_synthesis_state)->gains_diff_prev != NULL) + if ( ( dirac_output_synthesis_state )->gains_diff_prev != NULL ) { - free((dirac_output_synthesis_state)->gains_diff_prev); - (dirac_output_synthesis_state)->gains_diff_prev = NULL; + free( ( dirac_output_synthesis_state )->gains_diff_prev ); + ( dirac_output_synthesis_state )->gains_diff_prev = NULL; } #ifdef IVAS_FLOAT_FIXED /* free interpolator */ - IF ((dirac_output_synthesis_params)->interpolator_fx != NULL) + IF( ( dirac_output_synthesis_params )->interpolator_fx != NULL ) { - free((dirac_output_synthesis_params)->interpolator_fx); - (dirac_output_synthesis_params)->interpolator_fx = NULL; + free( ( dirac_output_synthesis_params )->interpolator_fx ); + ( dirac_output_synthesis_params )->interpolator_fx = NULL; } /* free alpha */ - IF ((dirac_output_synthesis_params)->alpha_synthesis_fx != NULL) + IF( ( dirac_output_synthesis_params )->alpha_synthesis_fx != NULL ) { - free((dirac_output_synthesis_params)->alpha_synthesis_fx); - (dirac_output_synthesis_params)->alpha_synthesis_fx = NULL; + free( ( dirac_output_synthesis_params )->alpha_synthesis_fx ); + ( dirac_output_synthesis_params )->alpha_synthesis_fx = NULL; } - IF ((dirac_output_synthesis_params)->alpha_synthesis_fast_fx != NULL) + IF( ( dirac_output_synthesis_params )->alpha_synthesis_fast_fx != NULL ) { - free((dirac_output_synthesis_params)->alpha_synthesis_fast_fx); - (dirac_output_synthesis_params)->alpha_synthesis_fast_fx = NULL; + free( ( dirac_output_synthesis_params )->alpha_synthesis_fast_fx ); + ( dirac_output_synthesis_params )->alpha_synthesis_fast_fx = NULL; } - IF ((dirac_output_synthesis_state)->reference_power_smooth_prev_fx != NULL) + IF( ( dirac_output_synthesis_state )->reference_power_smooth_prev_fx != NULL ) { - free((dirac_output_synthesis_state)->reference_power_smooth_prev_fx); - (dirac_output_synthesis_state)->reference_power_smooth_prev_fx = NULL; + free( ( dirac_output_synthesis_state )->reference_power_smooth_prev_fx ); + ( dirac_output_synthesis_state )->reference_power_smooth_prev_fx = NULL; } - IF ((dirac_output_synthesis_state)->direction_smoothness_prev_fx != NULL) + IF( ( dirac_output_synthesis_state )->direction_smoothness_prev_fx != NULL ) { - free((dirac_output_synthesis_state)->direction_smoothness_prev_fx); - (dirac_output_synthesis_state)->direction_smoothness_prev_fx = NULL; + free( ( dirac_output_synthesis_state )->direction_smoothness_prev_fx ); + ( dirac_output_synthesis_state )->direction_smoothness_prev_fx = NULL; } - IF ((dirac_output_synthesis_state)->diffuse_responses_square_fx != NULL) + IF( ( dirac_output_synthesis_state )->diffuse_responses_square_fx != NULL ) { - free((dirac_output_synthesis_state)->diffuse_responses_square_fx); - (dirac_output_synthesis_state)->diffuse_responses_square_fx = NULL; + free( ( dirac_output_synthesis_state )->diffuse_responses_square_fx ); + ( dirac_output_synthesis_state )->diffuse_responses_square_fx = NULL; } /* free power buffers */ - IF ((dirac_output_synthesis_state)->proto_power_smooth_prev_fx != NULL) + IF( ( dirac_output_synthesis_state )->proto_power_smooth_prev_fx != NULL ) { - free((dirac_output_synthesis_state)->proto_power_smooth_prev_fx); - (dirac_output_synthesis_state)->proto_power_smooth_prev_fx = NULL; + free( ( dirac_output_synthesis_state )->proto_power_smooth_prev_fx ); + ( dirac_output_synthesis_state )->proto_power_smooth_prev_fx = NULL; } - IF ((dirac_output_synthesis_state)->proto_power_diff_smooth_prev_fx != NULL) + IF( ( dirac_output_synthesis_state )->proto_power_diff_smooth_prev_fx != NULL ) { - free((dirac_output_synthesis_state)->proto_power_diff_smooth_prev_fx); - (dirac_output_synthesis_state)->proto_power_diff_smooth_prev_fx = NULL; + free( ( dirac_output_synthesis_state )->proto_power_diff_smooth_prev_fx ); + ( dirac_output_synthesis_state )->proto_power_diff_smooth_prev_fx = NULL; } /* free target power buffers */ - IF ((dirac_output_synthesis_state)->cy_auto_dir_smooth_prev_fx != NULL) + IF( ( dirac_output_synthesis_state )->cy_auto_dir_smooth_prev_fx != NULL ) { - free((dirac_output_synthesis_state)->cy_auto_dir_smooth_prev_fx); - (dirac_output_synthesis_state)->cy_auto_dir_smooth_prev_fx = NULL; + free( ( dirac_output_synthesis_state )->cy_auto_dir_smooth_prev_fx ); + ( dirac_output_synthesis_state )->cy_auto_dir_smooth_prev_fx = NULL; } - IF ((dirac_output_synthesis_state)->cy_cross_dir_smooth_prev_fx != NULL) + IF( ( dirac_output_synthesis_state )->cy_cross_dir_smooth_prev_fx != NULL ) { - free((dirac_output_synthesis_state)->cy_cross_dir_smooth_prev_fx); - (dirac_output_synthesis_state)->cy_cross_dir_smooth_prev_fx = NULL; + free( ( dirac_output_synthesis_state )->cy_cross_dir_smooth_prev_fx ); + ( dirac_output_synthesis_state )->cy_cross_dir_smooth_prev_fx = NULL; } - IF ((dirac_output_synthesis_state)->cy_auto_diff_smooth_prev_fx != NULL) + IF( ( dirac_output_synthesis_state )->cy_auto_diff_smooth_prev_fx != NULL ) { - free((dirac_output_synthesis_state)->cy_auto_diff_smooth_prev_fx); - (dirac_output_synthesis_state)->cy_auto_diff_smooth_prev_fx = NULL; + free( ( dirac_output_synthesis_state )->cy_auto_diff_smooth_prev_fx ); + ( dirac_output_synthesis_state )->cy_auto_diff_smooth_prev_fx = NULL; } /* free gain buffers */ - IF ((dirac_output_synthesis_state)->gains_dir_prev_fx != NULL) + IF( ( dirac_output_synthesis_state )->gains_dir_prev_fx != NULL ) { - free((dirac_output_synthesis_state)->gains_dir_prev_fx); - (dirac_output_synthesis_state)->gains_dir_prev_fx = NULL; + free( ( dirac_output_synthesis_state )->gains_dir_prev_fx ); + ( dirac_output_synthesis_state )->gains_dir_prev_fx = NULL; } - IF ((dirac_output_synthesis_state)->gains_diff_prev_fx != NULL) + IF( ( dirac_output_synthesis_state )->gains_diff_prev_fx != NULL ) { - free((dirac_output_synthesis_state)->gains_diff_prev_fx); - (dirac_output_synthesis_state)->gains_diff_prev_fx = NULL; + free( ( dirac_output_synthesis_state )->gains_diff_prev_fx ); + ( dirac_output_synthesis_state )->gains_diff_prev_fx = NULL; } #endif return; @@ -1424,9 +1424,9 @@ void ivas_dirac_dec_output_synthesis_process_slot( } #else void ivas_dirac_dec_output_synthesis_process_slot_fx( - const Word32 *reference_power, /* i : Estimated power */ + const Word32 *reference_power, /* i : Estimated power */ const Word16 q_reference_power, /* i : Estimated power */ - const Word32 *onset, /* i : onset filter */ + const Word32 *onset, /* i : onset filter */ const Word16 *azimuth, const Word16 *elevation, const Word32 *diffuseness, @@ -1434,10 +1434,10 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */ DIRAC_REND_HANDLE hDirACRend, /* i/o: DirAC renderer handle */ const Word16 sh_rot_max_order, - const Word32 *p_Rmat, /* i : rotation matrix */ + const Word32 *p_Rmat, /* i : rotation matrix */ const VBAP_HANDLE hVBAPdata, /* i : VBAP structure */ const IVAS_OUTPUT_SETUP hOutSetup, /* i : output setup structure */ - const Word16 nchan_transport, /* i : number of transport channels*/ + const Word16 nchan_transport, /* i : number of transport channels*/ const Word16 md_idx, const Word16 hodirac_flag, /* i : flag to indicate HO-DirAC mode */ const Word16 dec_param_estim ) @@ -1465,141 +1465,143 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( num_channels_diff = hDirACRend->num_outputs_diff; num_freq_bands_diff = h_dirac_output_synthesis_params->max_band_decorr; - IF ( EQ_16(hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS )) + IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) ) { - num_channels_dir = hOutSetup.nchan_out_woLFE; move16(); + num_channels_dir = hOutSetup.nchan_out_woLFE; + move16(); } - IF ( EQ_16(hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD) && hodirac_flag ) + IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) && hodirac_flag ) { ivas_dirac_dec_compute_directional_responses_fx( hSpatParamRendCom, - hDirACRend, - hVBAPdata, - NULL, - NULL, - azimuth, - elevation, - md_idx, - NULL, - 0, - 2, - p_Rmat, - hodirac_flag ); + hDirACRend, + hVBAPdata, + NULL, + NULL, + azimuth, + elevation, + md_idx, + NULL, + 0, + 2, + p_Rmat, + hodirac_flag ); + { + + IF( h_dirac_output_synthesis_state->direct_responses_square_fx ) { - - IF(h_dirac_output_synthesis_state->direct_responses_square_fx){ - Scale_sig32(h_dirac_output_synthesis_state->direct_responses_square_fx, num_channels_dir * num_freq_bands, sub(31, h_dirac_output_synthesis_state->direct_responses_square_q)); - h_dirac_output_synthesis_state->direct_responses_square_q = 31; - } - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub(31, h_dirac_output_synthesis_state->direct_responses_q)); - IF( hodirac_flag ) - { - Scale_sig32( &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir )], i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub(31, h_dirac_output_synthesis_state->direct_responses_q)); - } - h_dirac_output_synthesis_state->direct_responses_q = 31; + Scale_sig32( h_dirac_output_synthesis_state->direct_responses_square_fx, num_channels_dir * num_freq_bands, sub( 31, h_dirac_output_synthesis_state->direct_responses_square_q ) ); + h_dirac_output_synthesis_state->direct_responses_square_q = 31; } + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub( 31, h_dirac_output_synthesis_state->direct_responses_q ) ); + IF( hodirac_flag ) + { + Scale_sig32( &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir )], i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub( 31, h_dirac_output_synthesis_state->direct_responses_q ) ); + } + h_dirac_output_synthesis_state->direct_responses_q = 31; + } } - IF ( EQ_16(dec_param_estim, FALSE) && hodirac_flag ) + IF( EQ_16( dec_param_estim, FALSE ) && hodirac_flag ) { - IF ( EQ_16(hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD )) + IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { - v_multc_fixed( hSpatParamRendCom->energy_ratio1_fx[md_idx], L_negate(MAX_32), aux_buf, num_freq_bands ); + v_multc_fixed( hSpatParamRendCom->energy_ratio1_fx[md_idx], L_negate( MAX_32 ), aux_buf, num_freq_bands ); v_addc_fixed( aux_buf, ONE_IN_Q30, aux_buf, num_freq_bands ); Copy32( hSpatParamRendCom->energy_ratio1_fx[md_idx], - h_dirac_output_synthesis_state->direct_power_factor_fx, - num_freq_bands ); + h_dirac_output_synthesis_state->direct_power_factor_fx, + num_freq_bands ); Copy32( aux_buf, - h_dirac_output_synthesis_state->diffuse_power_factor_fx, - num_freq_bands ); - - v_multc_fixed( hSpatParamRendCom->energy_ratio2_fx[md_idx], L_negate(MAX_32), aux_buf, num_freq_bands ); + h_dirac_output_synthesis_state->diffuse_power_factor_fx, + num_freq_bands ); + + v_multc_fixed( hSpatParamRendCom->energy_ratio2_fx[md_idx], L_negate( MAX_32 ), aux_buf, num_freq_bands ); v_addc_fixed( aux_buf, ONE_IN_Q30, aux_buf, num_freq_bands ); Copy32( hSpatParamRendCom->energy_ratio2_fx[md_idx], - &h_dirac_output_synthesis_state->direct_power_factor_fx[hSpatParamRendCom->num_freq_bands], - num_freq_bands ); + &h_dirac_output_synthesis_state->direct_power_factor_fx[hSpatParamRendCom->num_freq_bands], + num_freq_bands ); Copy32( aux_buf, - &h_dirac_output_synthesis_state->diffuse_power_factor_fx[hSpatParamRendCom->num_freq_bands], - num_freq_bands ); + &h_dirac_output_synthesis_state->diffuse_power_factor_fx[hSpatParamRendCom->num_freq_bands], + num_freq_bands ); h_dirac_output_synthesis_state->diffuse_power_factor_q = 30; h_dirac_output_synthesis_state->direct_power_factor_q = 30; - } ELSE { ivas_dirac_dec_compute_gain_factors_fx( num_freq_bands, - hSpatParamRendCom->diffuseness_vector_fx[md_idx], - h_dirac_output_synthesis_state->direct_power_factor_fx, - h_dirac_output_synthesis_state->diffuse_power_factor_fx, - &h_dirac_output_synthesis_state->direct_power_factor_q, - &h_dirac_output_synthesis_state->diffuse_power_factor_q); + hSpatParamRendCom->diffuseness_vector_fx[md_idx], + h_dirac_output_synthesis_state->direct_power_factor_fx, + h_dirac_output_synthesis_state->diffuse_power_factor_fx, + &h_dirac_output_synthesis_state->direct_power_factor_q, + &h_dirac_output_synthesis_state->diffuse_power_factor_q ); } } - ELSE IF ( EQ_16(dec_param_estim, TRUE )) + ELSE IF( EQ_16( dec_param_estim, TRUE ) ) { /* compute direct responses */ ivas_dirac_dec_compute_directional_responses_fx( hSpatParamRendCom, - hDirACRend, - hVBAPdata, - NULL, - NULL, - azimuth, - elevation, - md_idx, - NULL, - 0, - sh_rot_max_order, - p_Rmat, - hodirac_flag ); - + hDirACRend, + hVBAPdata, + NULL, + NULL, + azimuth, + elevation, + md_idx, + NULL, + 0, + sh_rot_max_order, + p_Rmat, + hodirac_flag ); + + { + IF( h_dirac_output_synthesis_state->direct_responses_square_fx ) { - IF(h_dirac_output_synthesis_state->direct_responses_square_fx){ - Scale_sig32(h_dirac_output_synthesis_state->direct_responses_square_fx, num_channels_dir * num_freq_bands, sub(31, h_dirac_output_synthesis_state->direct_responses_square_q)); - h_dirac_output_synthesis_state->direct_responses_square_q = 31; - } - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub(31, h_dirac_output_synthesis_state->direct_responses_q)); - IF( hodirac_flag ) - { - Scale_sig32( &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir )], i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub(31, h_dirac_output_synthesis_state->direct_responses_q)); - } - h_dirac_output_synthesis_state->direct_responses_q = 31; + Scale_sig32( h_dirac_output_synthesis_state->direct_responses_square_fx, num_channels_dir * num_freq_bands, sub( 31, h_dirac_output_synthesis_state->direct_responses_square_q ) ); + h_dirac_output_synthesis_state->direct_responses_square_q = 31; + } + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub( 31, h_dirac_output_synthesis_state->direct_responses_q ) ); + IF( hodirac_flag ) + { + Scale_sig32( &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir )], i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub( 31, h_dirac_output_synthesis_state->direct_responses_q ) ); } + h_dirac_output_synthesis_state->direct_responses_q = 31; + } - IF ( EQ_16(hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD )) + IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { ivas_dirac_dec_compute_gain_factors_fx( num_freq_bands, - diffuseness, - h_dirac_output_synthesis_state->direct_power_factor_fx, - h_dirac_output_synthesis_state->diffuse_power_factor_fx, - &h_dirac_output_synthesis_state->direct_power_factor_q, - &h_dirac_output_synthesis_state->diffuse_power_factor_q - ); - h_dirac_output_synthesis_state->direct_power_factor_q = sub(31, h_dirac_output_synthesis_state->direct_power_factor_q); - h_dirac_output_synthesis_state->diffuse_power_factor_q = sub(31, h_dirac_output_synthesis_state->diffuse_power_factor_q); + diffuseness, + h_dirac_output_synthesis_state->direct_power_factor_fx, + h_dirac_output_synthesis_state->diffuse_power_factor_fx, + &h_dirac_output_synthesis_state->direct_power_factor_q, + &h_dirac_output_synthesis_state->diffuse_power_factor_q ); + h_dirac_output_synthesis_state->direct_power_factor_q = sub( 31, h_dirac_output_synthesis_state->direct_power_factor_q ); + h_dirac_output_synthesis_state->diffuse_power_factor_q = sub( 31, h_dirac_output_synthesis_state->diffuse_power_factor_q ); v_multc_fixed( h_dirac_output_synthesis_state->direct_power_factor_fx, - ONE_IN_Q29, - h_dirac_output_synthesis_state->direct_power_factor_fx, - num_freq_bands ); + ONE_IN_Q29, + h_dirac_output_synthesis_state->direct_power_factor_fx, + num_freq_bands ); v_multc_fixed( h_dirac_output_synthesis_state->diffuse_power_factor_fx, - ONE_IN_Q29, - h_dirac_output_synthesis_state->diffuse_power_factor_fx, - num_freq_bands ); + ONE_IN_Q29, + h_dirac_output_synthesis_state->diffuse_power_factor_fx, + num_freq_bands ); /*Direct gain*/ - Word16 *Q_temp_cy_cross_dir_smooth_fx = (Word16*)malloc(num_freq_bands * num_channels_dir * sizeof(Word16)); + Word16 *Q_temp_cy_cross_dir_smooth_fx = (Word16 *) malloc( num_freq_bands * num_channels_dir * sizeof( Word16 ) ); - FOR(Word16 kk = 0 ; kk < num_freq_bands * num_channels_dir; kk++) + FOR( Word16 kk = 0; kk < num_freq_bands * num_channels_dir; kk++ ) { - Q_temp_cy_cross_dir_smooth_fx[kk] = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth; move16(); + Q_temp_cy_cross_dir_smooth_fx[kk] = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth; + move16(); } - FOR ( ch_idx = 0; ch_idx < s_min( 4, nchan_transport ); ch_idx++ ) + FOR( ch_idx = 0; ch_idx < s_min( 4, nchan_transport ); ch_idx++ ) { Word16 k; - IF ( NE_16(ch_idx, 0 )) + IF( NE_16( ch_idx, 0 ) ) { Word32 a, c; Word16 b, b_exp, sqr_exp, q_diff_aab, q_diff_c; @@ -1607,132 +1609,132 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( Word32 sqr_inp, sqr; /*Directonal sound gain nrg compensation*/ - FOR ( k = 0; k < num_freq_bands_diff; k++ ) + FOR( k = 0; k < num_freq_bands_diff; k++ ) { - a = h_dirac_output_synthesis_state->direct_responses_fx[add(i_mult(ch_idx, num_freq_bands), k)];// Q = h_dirac_output_synthesis_state->q_direct_responses - IF(EQ_32(reference_power[k + num_freq_bands], 0)) + a = h_dirac_output_synthesis_state->direct_responses_fx[add( i_mult( ch_idx, num_freq_bands ), k )]; // Q = h_dirac_output_synthesis_state->q_direct_responses + IF( EQ_32( reference_power[k + num_freq_bands], 0 ) ) { b = 0; b_exp = 0; } ELSE { - b = BASOP_Util_Divide3232_Scale(reference_power[k + num_freq_bands], L_add(reference_power[k + ( ch_idx + 1 ) * num_freq_bands], EPSILON_FX), &b_exp); + b = BASOP_Util_Divide3232_Scale( reference_power[k + num_freq_bands], L_add( reference_power[k + ( ch_idx + 1 ) * num_freq_bands], EPSILON_FX ), &b_exp ); } - c = L_add(ONE_IN_Q29, Mpy_32_16_1( L_sub(h_dirac_output_synthesis_params->diffuse_compensation_factor_decorr_fx, ONE_IN_Q29) , 5461)); /*Diffuseness modellling nrg compensation*/ /* 1.0 / 6.0 = 5461 in Q15*/ + c = L_add( ONE_IN_Q29, Mpy_32_16_1( L_sub( h_dirac_output_synthesis_params->diffuse_compensation_factor_decorr_fx, ONE_IN_Q29 ), 5461 ) ); /*Diffuseness modellling nrg compensation*/ /* 1.0 / 6.0 = 5461 in Q15*/ + + mpy_a_a_b = Mpy_32_32( a, Mpy_32_16_1( a, b ) ); // Q = (h_dirac_output_synthesis_state->q_direct_responses + (31 - b_exp) - 31) + (h_dirac_output_synthesis_state->q_direct_responses) - 31 + mpy_diff_aab = Mpy_32_32( L_sub( L_shl( 1, q_diffuseness ), diffuseness[k] ), mpy_a_a_b ); // Q = 2*(h_dirac_output_synthesis_state->q_direct_responses) - b_exp - 31 + q_diffuseness -31 + mpy_diff_c = Mpy_32_32( diffuseness[k], c ); // Q = q_diffuseness - 2 - mpy_a_a_b = Mpy_32_32(a, Mpy_32_16_1(a, b)); //Q = (h_dirac_output_synthesis_state->q_direct_responses + (31 - b_exp) - 31) + (h_dirac_output_synthesis_state->q_direct_responses) - 31 - mpy_diff_aab = Mpy_32_32(L_sub(L_shl(1, q_diffuseness), diffuseness[k]), mpy_a_a_b); // Q = 2*(h_dirac_output_synthesis_state->q_direct_responses) - b_exp - 31 + q_diffuseness -31 - mpy_diff_c = Mpy_32_32(diffuseness[k], c); // Q = q_diffuseness - 2 + q_diff_aab = ( h_dirac_output_synthesis_state->direct_responses_q + ( 31 - b_exp ) - 31 ) + ( h_dirac_output_synthesis_state->direct_responses_q ) - 31 + q_diffuseness - 31; + q_diff_c = sub( q_diffuseness, 2 ); - q_diff_aab = (h_dirac_output_synthesis_state->direct_responses_q + (31 - b_exp) - 31) + (h_dirac_output_synthesis_state->direct_responses_q) - 31 + q_diffuseness - 31; - q_diff_c = sub(q_diffuseness, 2); - - IF(NE_32(mpy_diff_c, 0) && NE_32(mpy_diff_aab, 0)) + IF( NE_32( mpy_diff_c, 0 ) && NE_32( mpy_diff_aab, 0 ) ) { - sqr_inp = BASOP_Util_Add_Mant32Exp(mpy_diff_c, sub(31, q_diff_c), mpy_diff_aab, sub(31, q_diff_aab), &sqr_exp); + sqr_inp = BASOP_Util_Add_Mant32Exp( mpy_diff_c, sub( 31, q_diff_c ), mpy_diff_aab, sub( 31, q_diff_aab ), &sqr_exp ); } ELSE { - IF(EQ_32(mpy_diff_c, 0)) - { - sqr_inp = mpy_diff_aab; - sqr_exp = sub(31, q_diff_aab); - } - ELSE - { - sqr_inp = mpy_diff_c; - sqr_exp = sub(31, q_diff_c); - } + IF( EQ_32( mpy_diff_c, 0 ) ) + { + sqr_inp = mpy_diff_aab; + sqr_exp = sub( 31, q_diff_aab ); + } + ELSE + { + sqr_inp = mpy_diff_c; + sqr_exp = sub( 31, q_diff_c ); + } } - sqr = Sqrt32(sqr_inp, &sqr_exp); - sqr = L_shr(sqr, 2); - IF(NE_32(h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add(i_mult(ch_idx, num_freq_bands), k)], 0)) + sqr = Sqrt32( sqr_inp, &sqr_exp ); + sqr = L_shr( sqr, 2 ); + IF( NE_32( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], 0 ) ) { - IF(LT_16(sub(31, sqr_exp), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth)) + IF( LT_16( sub( 31, sqr_exp ), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ) { - h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add(i_mult(ch_idx, num_freq_bands), k)] = L_shr(h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add(i_mult(ch_idx, num_freq_bands), k)], sub(h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, sub(31, sqr_exp))); - Q_temp_cy_cross_dir_smooth_fx[L_add(i_mult(ch_idx, num_freq_bands), k)] = sub(31, sqr_exp); + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = L_shr( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], sub( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, sub( 31, sqr_exp ) ) ); + Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = sub( 31, sqr_exp ); } ELSE { - sqr = L_shr(sqr, sub(sub(31, sqr_exp), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth)); - Q_temp_cy_cross_dir_smooth_fx[L_add(i_mult(ch_idx, num_freq_bands), k)] = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth; + sqr = L_shr( sqr, sub( sub( 31, sqr_exp ), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ); + Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth; } - h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add(i_mult(ch_idx, num_freq_bands), k)] = L_add(h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add(i_mult(ch_idx, num_freq_bands), k)], sqr); + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], sqr ); } ELSE { - h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add(i_mult(ch_idx, num_freq_bands), k)] = L_add(h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add(i_mult(ch_idx, num_freq_bands), k)], sqr); - Q_temp_cy_cross_dir_smooth_fx[L_add(i_mult(ch_idx, num_freq_bands), k)] = sub(31 , sqr_exp); + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], sqr ); + Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = sub( 31, sqr_exp ); } } - FOR ( ; k < num_freq_bands; k++ ) + FOR( ; k < num_freq_bands; k++ ) { - a = h_dirac_output_synthesis_state->direct_responses_fx[add(i_mult(ch_idx, num_freq_bands), k)];// Q = h_dirac_output_synthesis_state->q_direct_responses - IF(EQ_32(reference_power[k + num_freq_bands], 0)) + a = h_dirac_output_synthesis_state->direct_responses_fx[add( i_mult( ch_idx, num_freq_bands ), k )]; // Q = h_dirac_output_synthesis_state->q_direct_responses + IF( EQ_32( reference_power[k + num_freq_bands], 0 ) ) { b = 0; b_exp = 0; } ELSE { - IF(EQ_32(reference_power[k + ( ch_idx + 1 ) * num_freq_bands], 0)) + IF( EQ_32( reference_power[k + ( ch_idx + 1 ) * num_freq_bands], 0 ) ) { - b = MAXVAL_WORD16; - b_exp = 40; + b = MAXVAL_WORD16; + b_exp = 40; } ELSE { - b = BASOP_Util_Divide3232_Scale(reference_power[k + num_freq_bands], reference_power[k + ( ch_idx + 1 ) * num_freq_bands], &b_exp); + b = BASOP_Util_Divide3232_Scale( reference_power[k + num_freq_bands], reference_power[k + ( ch_idx + 1 ) * num_freq_bands], &b_exp ); } } - c = L_add(ONE_IN_Q29, Mpy_32_16_1( L_sub(h_dirac_output_synthesis_params->diffuse_compensation_factor_decorr_fx, ONE_IN_Q29) , 5461)); /*Diffuseness modellling nrg compensation*/ /* 1.0 / 6.0 = 5461 in Q15*/ + c = L_add( ONE_IN_Q29, Mpy_32_16_1( L_sub( h_dirac_output_synthesis_params->diffuse_compensation_factor_decorr_fx, ONE_IN_Q29 ), 5461 ) ); /*Diffuseness modellling nrg compensation*/ /* 1.0 / 6.0 = 5461 in Q15*/ + + mpy_a_a_b = Mpy_32_32( a, Mpy_32_16_1( a, b ) ); // Q = (h_dirac_output_synthesis_state->q_direct_responses + (31 - b_exp) - 31) + (h_dirac_output_synthesis_state->q_direct_responses) - 31 + mpy_diff_aab = Mpy_32_32( L_sub( L_shl( 1, q_diffuseness ), diffuseness[k] ), mpy_a_a_b ); // Q = 2*(h_dirac_output_synthesis_state->q_direct_responses) - b_exp - 31 + q_diffuseness -31 + mpy_diff_c = Mpy_32_32( diffuseness[k], c ); // Q = q_diffuseness - 2 - mpy_a_a_b = Mpy_32_32(a, Mpy_32_16_1(a, b)); //Q = (h_dirac_output_synthesis_state->q_direct_responses + (31 - b_exp) - 31) + (h_dirac_output_synthesis_state->q_direct_responses) - 31 - mpy_diff_aab = Mpy_32_32(L_sub(L_shl(1, q_diffuseness), diffuseness[k]), mpy_a_a_b); // Q = 2*(h_dirac_output_synthesis_state->q_direct_responses) - b_exp - 31 + q_diffuseness -31 - mpy_diff_c = Mpy_32_32(diffuseness[k], c); // Q = q_diffuseness - 2 + q_diff_aab = ( h_dirac_output_synthesis_state->direct_responses_q + ( 31 - b_exp ) - 31 ) + ( h_dirac_output_synthesis_state->direct_responses_q ) - 31 + q_diffuseness - 31; + q_diff_c = sub( q_diffuseness, 2 ); - q_diff_aab = (h_dirac_output_synthesis_state->direct_responses_q + (31 - b_exp) - 31) + (h_dirac_output_synthesis_state->direct_responses_q) - 31 + q_diffuseness - 31; - q_diff_c = sub(q_diffuseness, 2); - - IF(NE_32(mpy_diff_c, 0) && NE_32(mpy_diff_aab, 0)) + IF( NE_32( mpy_diff_c, 0 ) && NE_32( mpy_diff_aab, 0 ) ) { - sqr_inp = BASOP_Util_Add_Mant32Exp(mpy_diff_c, sub(31, q_diff_c), mpy_diff_aab, sub(31, q_diff_aab), &sqr_exp); + sqr_inp = BASOP_Util_Add_Mant32Exp( mpy_diff_c, sub( 31, q_diff_c ), mpy_diff_aab, sub( 31, q_diff_aab ), &sqr_exp ); } ELSE { - IF(EQ_32(mpy_diff_c, 0)) - { - sqr_inp = mpy_diff_aab; - sqr_exp = sub(31, q_diff_aab); - } - ELSE - { - sqr_inp = mpy_diff_c; - sqr_exp = sub(31, q_diff_c); - } + IF( EQ_32( mpy_diff_c, 0 ) ) + { + sqr_inp = mpy_diff_aab; + sqr_exp = sub( 31, q_diff_aab ); + } + ELSE + { + sqr_inp = mpy_diff_c; + sqr_exp = sub( 31, q_diff_c ); + } } - sqr = Sqrt32(sqr_inp, &sqr_exp); - sqr = L_shr(sqr, 2); - IF(NE_32(h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add(i_mult(ch_idx, num_freq_bands), k)], 0)) + sqr = Sqrt32( sqr_inp, &sqr_exp ); + sqr = L_shr( sqr, 2 ); + IF( NE_32( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], 0 ) ) { - IF(LT_16(sub(31, sqr_exp), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth)) + IF( LT_16( sub( 31, sqr_exp ), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ) { - h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add(i_mult(ch_idx, num_freq_bands), k)] = L_shr(h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add(i_mult(ch_idx, num_freq_bands), k)], sub(h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, sub(31, sqr_exp))); - Q_temp_cy_cross_dir_smooth_fx[L_add(i_mult(ch_idx, num_freq_bands), k)] = sub(31, sqr_exp); + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = L_shr( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], sub( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, sub( 31, sqr_exp ) ) ); + Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = sub( 31, sqr_exp ); } ELSE { - sqr = L_shr(sqr, sub(sub(31, sqr_exp), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth)); - Q_temp_cy_cross_dir_smooth_fx[L_add(i_mult(ch_idx, num_freq_bands), k)] = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth; + sqr = L_shr( sqr, sub( sub( 31, sqr_exp ), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ); + Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth; } - h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add(i_mult(ch_idx, num_freq_bands), k)] = L_add(h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add(i_mult(ch_idx, num_freq_bands), k)], sqr); + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], sqr ); } ELSE { - h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add(i_mult(ch_idx, num_freq_bands), k)] = L_add(h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add(i_mult(ch_idx, num_freq_bands), k)], sqr); - Q_temp_cy_cross_dir_smooth_fx[L_add(i_mult(ch_idx, num_freq_bands), k)] = sub(31 , sqr_exp); + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], sqr ); + Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = sub( 31, sqr_exp ); } } } @@ -1741,113 +1743,114 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( Word32 sqr_inp, mpy_diff, sqr; Word16 sqr_exp; /*Diffuseness modellling nrg compensation*/ - FOR ( k = 0; k < num_freq_bands_diff; k++ ) + FOR( k = 0; k < num_freq_bands_diff; k++ ) { - mpy_diff = Mpy_32_32(diffuseness[k] ,L_sub(h_dirac_output_synthesis_params->diffuse_compensation_factor_decorr_fx, ONE_IN_Q29));//Q = q_diff - 1 - sqr_inp = L_add(L_shl(1, sub(q_diffuseness, 1)) , mpy_diff); - sqr_exp = sub(31 , sub(q_diffuseness, 1)); - sqr = Sqrt32(sqr_inp, &sqr_exp); - sqr = L_shr(sqr, 2); - IF(NE_32(h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add(i_mult(ch_idx, num_freq_bands), k)], 0)) + mpy_diff = Mpy_32_32( diffuseness[k], L_sub( h_dirac_output_synthesis_params->diffuse_compensation_factor_decorr_fx, ONE_IN_Q29 ) ); // Q = q_diff - 1 + sqr_inp = L_add( L_shl( 1, sub( q_diffuseness, 1 ) ), mpy_diff ); + sqr_exp = sub( 31, sub( q_diffuseness, 1 ) ); + sqr = Sqrt32( sqr_inp, &sqr_exp ); + sqr = L_shr( sqr, 2 ); + IF( NE_32( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], 0 ) ) { - IF(LT_16(sub(31, sqr_exp), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth)) + IF( LT_16( sub( 31, sqr_exp ), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ) { - h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add(i_mult(ch_idx, num_freq_bands), k)] = L_shr(h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add(i_mult(ch_idx, num_freq_bands), k)], sub(h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, sub(31, sqr_exp))); - Q_temp_cy_cross_dir_smooth_fx[L_add(i_mult(ch_idx, num_freq_bands), k)] = sub(31, sqr_exp); + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = L_shr( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], sub( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, sub( 31, sqr_exp ) ) ); + Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = sub( 31, sqr_exp ); } ELSE { - sqr = L_shr(sqr, sub(sub(31, sqr_exp), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth)); - Q_temp_cy_cross_dir_smooth_fx[L_add(i_mult(ch_idx, num_freq_bands), k)] = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth; + sqr = L_shr( sqr, sub( sub( 31, sqr_exp ), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ); + Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth; } - h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add(i_mult(ch_idx, num_freq_bands), k)] = L_add(h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add(i_mult(ch_idx, num_freq_bands), k)], sqr); + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], sqr ); } ELSE { - h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add(i_mult(ch_idx, num_freq_bands), k)] = L_add(h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add(i_mult(ch_idx, num_freq_bands), k)], sqr); - Q_temp_cy_cross_dir_smooth_fx[L_add(i_mult(ch_idx, num_freq_bands), k)] = sub(31 , sqr_exp); + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], sqr ); + Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = sub( 31, sqr_exp ); } } - FOR ( ; k < num_freq_bands; k++ ) + FOR( ; k < num_freq_bands; k++ ) { - mpy_diff = Mpy_32_32(diffuseness[k] ,L_sub(h_dirac_output_synthesis_params->diffuse_compensation_factor_decorr_fx, ONE_IN_Q29));//Q = q_diff - 1 - sqr_inp = L_add(L_shl(1, sub(q_diffuseness, 1)) , mpy_diff); - sqr_exp = sub(31 , sub(q_diffuseness, 1)); - sqr = Sqrt32(sqr_inp, &sqr_exp); - sqr = L_shr(sqr, 2); - IF(NE_32(h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add(i_mult(ch_idx, num_freq_bands), k)], 0)) + mpy_diff = Mpy_32_32( diffuseness[k], L_sub( h_dirac_output_synthesis_params->diffuse_compensation_factor_decorr_fx, ONE_IN_Q29 ) ); // Q = q_diff - 1 + sqr_inp = L_add( L_shl( 1, sub( q_diffuseness, 1 ) ), mpy_diff ); + sqr_exp = sub( 31, sub( q_diffuseness, 1 ) ); + sqr = Sqrt32( sqr_inp, &sqr_exp ); + sqr = L_shr( sqr, 2 ); + IF( NE_32( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], 0 ) ) { - IF(LT_16(sub(31, sqr_exp), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth)) + IF( LT_16( sub( 31, sqr_exp ), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ) { - h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add(i_mult(ch_idx, num_freq_bands), k)] = L_shr(h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add(i_mult(ch_idx, num_freq_bands), k)], sub(h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, sub(31, sqr_exp))); - Q_temp_cy_cross_dir_smooth_fx[L_add(i_mult(ch_idx, num_freq_bands), k)] = sub(31, sqr_exp); + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = L_shr( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], sub( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, sub( 31, sqr_exp ) ) ); + Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = sub( 31, sqr_exp ); } ELSE { - sqr = L_shr(sqr, sub(sub(31, sqr_exp), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth)); - Q_temp_cy_cross_dir_smooth_fx[L_add(i_mult(ch_idx, num_freq_bands), k)] = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth; + sqr = L_shr( sqr, sub( sub( 31, sqr_exp ), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ); + Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth; } - h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add(i_mult(ch_idx, num_freq_bands), k)] = L_add(h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add(i_mult(ch_idx, num_freq_bands), k)], sqr); + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], sqr ); } ELSE { - h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add(i_mult(ch_idx, num_freq_bands), k)] = L_add(h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add(i_mult(ch_idx, num_freq_bands), k)], sqr); - Q_temp_cy_cross_dir_smooth_fx[L_add(i_mult(ch_idx, num_freq_bands), k)] = sub(31 , sqr_exp); + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], sqr ); + Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = sub( 31, sqr_exp ); } } } } Word16 temp = MAX_16; - FOR(Word16 kk = 0 ; kk < num_freq_bands * num_channels_dir; kk++) + FOR( Word16 kk = 0; kk < num_freq_bands * num_channels_dir; kk++ ) { - temp = s_min(Q_temp_cy_cross_dir_smooth_fx[kk], temp); + temp = s_min( Q_temp_cy_cross_dir_smooth_fx[kk], temp ); } - h_dirac_output_synthesis_state->q_cy_cross_dir_smooth = temp; move16(); - FOR(Word16 kk = 0 ; kk < num_freq_bands * num_channels_dir; kk++) + h_dirac_output_synthesis_state->q_cy_cross_dir_smooth = temp; + move16(); + FOR( Word16 kk = 0; kk < num_freq_bands * num_channels_dir; kk++ ) { - h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[kk] = L_shl(h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[kk], sub(temp, Q_temp_cy_cross_dir_smooth_fx[kk])); + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[kk] = L_shl( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[kk], sub( temp, Q_temp_cy_cross_dir_smooth_fx[kk] ) ); } - free(Q_temp_cy_cross_dir_smooth_fx); + free( Q_temp_cy_cross_dir_smooth_fx ); /*Directional gain (panning)*/ - Word16 temp_q = sub(add(h_dirac_output_synthesis_state->direct_power_factor_q, h_dirac_output_synthesis_state->direct_responses_q), 31); - IF(LT_16(temp_q, h_dirac_output_synthesis_state->q_cy_cross_dir_smooth)) + Word16 temp_q = sub( add( h_dirac_output_synthesis_state->direct_power_factor_q, h_dirac_output_synthesis_state->direct_responses_q ), 31 ); + IF( LT_16( temp_q, h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ) { - FOR(Word16 kk = 0 ; kk < num_freq_bands * num_channels_dir; kk++) + FOR( Word16 kk = 0; kk < num_freq_bands * num_channels_dir; kk++ ) { - h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[kk] = L_shl(h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[kk], sub(temp_q, h_dirac_output_synthesis_state->q_cy_cross_dir_smooth)); + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[kk] = L_shl( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[kk], sub( temp_q, h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ); } h_dirac_output_synthesis_state->q_cy_cross_dir_smooth = temp_q; } - FOR ( ch_idx = s_min( 4, nchan_transport ); ch_idx < num_channels_dir; ch_idx++ ) + FOR( ch_idx = s_min( 4, nchan_transport ); ch_idx < num_channels_dir; ch_idx++ ) { v_mult_fixed( h_dirac_output_synthesis_state->direct_power_factor_fx, - &h_dirac_output_synthesis_state->direct_responses_fx[i_mult(ch_idx, num_freq_bands)], - aux_buf, - num_freq_bands ); + &h_dirac_output_synthesis_state->direct_responses_fx[i_mult( ch_idx, num_freq_bands )], + aux_buf, + num_freq_bands ); - IF(NE_16(temp_q, h_dirac_output_synthesis_state->q_cy_cross_dir_smooth)) + IF( NE_16( temp_q, h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ) { - Scale_sig32(aux_buf, num_freq_bands, sub(h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, temp_q)); + Scale_sig32( aux_buf, num_freq_bands, sub( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, temp_q ) ); } v_add_fixed( aux_buf, - &h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], - &h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], - num_freq_bands, 0); // Todo:Hdrm + &h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], + &h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], + num_freq_bands, 0 ); // Todo:Hdrm } /*Diffuse gain*/ - FOR ( ch_idx = s_min( 4, nchan_transport ); ch_idx < num_channels_diff; ch_idx++ ) + FOR( ch_idx = s_min( 4, nchan_transport ); ch_idx < num_channels_diff; ch_idx++ ) { v_multc_fixed( h_dirac_output_synthesis_state->diffuse_power_factor_fx, - hDirACRend->diffuse_response_function_fx[ch_idx], - aux_buf, - num_freq_bands_diff ); + hDirACRend->diffuse_response_function_fx[ch_idx], + aux_buf, + num_freq_bands_diff ); v_add_fixed( aux_buf, - &h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx[ch_idx * num_freq_bands_diff], - &h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx[ch_idx * num_freq_bands_diff], - num_freq_bands_diff, 0); // Todo:Hdrm + &h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx[ch_idx * num_freq_bands_diff], + &h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx[ch_idx * num_freq_bands_diff], + num_freq_bands_diff, 0 ); // Todo:Hdrm } return; @@ -1856,20 +1859,21 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( { /* compute reference and diffuse power factor for this frame */ ivas_dirac_dec_compute_power_factors_fx( num_freq_bands, - diffuseness, - h_dirac_output_synthesis_params->max_band_decorr, - h_dirac_output_synthesis_state->direct_power_factor_fx, - h_dirac_output_synthesis_state->diffuse_power_factor_fx ); - - Scale_sig32(h_dirac_output_synthesis_state->direct_power_factor_fx, num_freq_bands, 2); - Scale_sig32(h_dirac_output_synthesis_state->diffuse_power_factor_fx, num_freq_bands, 2); + diffuseness, + h_dirac_output_synthesis_params->max_band_decorr, + h_dirac_output_synthesis_state->direct_power_factor_fx, + h_dirac_output_synthesis_state->diffuse_power_factor_fx ); + + Scale_sig32( h_dirac_output_synthesis_state->direct_power_factor_fx, num_freq_bands, 2 ); + Scale_sig32( h_dirac_output_synthesis_state->diffuse_power_factor_fx, num_freq_bands, 2 ); h_dirac_output_synthesis_state->diffuse_power_factor_q = 31; h_dirac_output_synthesis_state->direct_power_factor_q = 31; } } - diff_start_band = 0; move16(); - IF ( h_dirac_output_synthesis_params->use_onset_filters ) + diff_start_band = 0; + move16(); + IF( h_dirac_output_synthesis_params->use_onset_filters ) { computeTargetPSDs_diffuse_with_onsets_fx( num_channels_dir, num_freq_bands, h_dirac_output_synthesis_params->max_band_decorr, @@ -1882,11 +1886,12 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, &h_dirac_output_synthesis_state->q_cy_auto_diff_smooth ); - diff_start_band = h_dirac_output_synthesis_params->max_band_decorr; move16(); + diff_start_band = h_dirac_output_synthesis_params->max_band_decorr; + move16(); } /* process other PSDs only slot wise for 4 transport channels */ - IF ( EQ_16(dec_param_estim, TRUE )) + IF( EQ_16( dec_param_estim, TRUE ) ) { computeTargetPSDs_direct_fx( num_channels_dir, num_freq_bands, h_dirac_output_synthesis_state->direct_power_factor_fx, reference_power, &q_reference_power, h_dirac_output_synthesis_state->direct_responses_fx, h_dirac_output_synthesis_state->direct_responses_square_fx, h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, &h_dirac_output_synthesis_state->q_cy_auto_dir_smooth, h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, &h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ); @@ -2425,13 +2430,13 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( // ((p_gains_diff_q, p_proto_diff_q) >> Q1) -> (p_gains_diff_q + p_proto_diff_q - 31) output_real[l * num_channels_dir + hDirACRend->sba_map_tc[ch_idx]] = L_add( output_real[l * num_channels_dir + hDirACRend->sba_map_tc[ch_idx]], - Mpy_32_32( g, ( *( p_proto++ ) ) ) ); + Mpy_32_32( g, ( *( p_proto++ ) ) ) ); move32(); // ((p_gains_diff_q, p_proto_diff_q) >> Q1) -> (p_gains_diff_q + p_proto_diff_q - 31) output_imag[l * num_channels_dir + hDirACRend->sba_map_tc[ch_idx]] = L_add( output_imag[l * num_channels_dir + hDirACRend->sba_map_tc[ch_idx]], - Mpy_32_32( g, ( *( p_proto++ ) ) )); + Mpy_32_32( g, ( *( p_proto++ ) ) ) ); move32(); } } @@ -3123,24 +3128,24 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( exp1 = 0; move16(); tmp32 = BASOP_Util_Divide3232_Scale_cadence( L_shl( p_cy_auto_dir_smooth[num_freq_bands], sub( q_com, h_dirac_output_synthesis_state->q_cy_auto_dir_smooth ) ), - ( L_add( Sqrt32( h_dirac_output_synthesis_state->direct_power_factor_fx[0], &exp ), EPSILON_FX ) ), // (Q31 - exp) - &exp1 ); + ( L_add( Sqrt32( h_dirac_output_synthesis_state->direct_power_factor_fx[0], &exp ), EPSILON_FX ) ), // (Q31 - exp) + &exp1 ); target_power_y = L_shr( tmp32, 1 ); // Q31 + (q_com - (31 - exp)) q_target_power_y = add( Q31 - exp1, sub( q_com, sub( Q31, exp ) ) ); - q_target_power_y = sub(q_target_power_y, 1); + q_target_power_y = sub( q_target_power_y, 1 ); exp = sub( Q31, Q31 ); exp1 = 0; move16(); tmp32 = BASOP_Util_Divide3232_Scale_cadence( L_shl( p_cy_auto_diff_smooth[num_freq_bands], sub( q_com, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth ) ), - ( L_add( Sqrt32( h_dirac_output_synthesis_state->diffuse_power_factor_fx[0], &exp ), EPSILON_FX ) ), // (Q31 - exp) - &exp1 ); + ( L_add( Sqrt32( h_dirac_output_synthesis_state->diffuse_power_factor_fx[0], &exp ), EPSILON_FX ) ), // (Q31 - exp) + &exp1 ); target_power_y1 = L_shr( tmp32, 1 ); // Q31 + (q_com - (31 - exp)) q_target_power_y1 = add( Q31 - exp1, sub( q_com, sub( Q31, exp ) ) ); - q_target_power_y1 = sub(q_target_power_y1, 1); + q_target_power_y1 = sub( q_target_power_y1, 1 ); - target_power_y = L_add( L_shl(target_power_y, sub(s_min(q_target_power_y1, q_target_power_y), q_target_power_y)), L_shl(target_power_y1, sub(s_min(q_target_power_y1, q_target_power_y), q_target_power_y1))); - exp = s_min(q_target_power_y1 - 1, q_target_power_y - 1); + target_power_y = L_add( L_shl( target_power_y, sub( s_min( q_target_power_y1, q_target_power_y ), q_target_power_y ) ), L_shl( target_power_y1, sub( s_min( q_target_power_y1, q_target_power_y ), q_target_power_y1 ) ) ); + exp = s_min( q_target_power_y1 - 1, q_target_power_y - 1 ); move16(); } ELSE @@ -3372,7 +3377,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( FOR( l = 0; l < h_dirac_output_synthesis_params->max_band_decorr; l++ ) { /*Direct*/ - g1 = alpha[l]; // Q31 + g1 = alpha[l]; // Q31 move32(); g2 = L_sub( ONE_IN_Q31, g1 ); // Q31 *( p_cy_auto_dir_smooth_prev ) = L_add( Mpy_32_32( g1, ( *( p_cy_auto_dir_smooth++ ) ) ), @@ -4115,13 +4120,14 @@ static void ivas_dirac_dec_get_response_split_order_fx( tmp = BASOP_util_atan2( dv_r_1, dv_r_0, 0 ); // Q13 index_azimuth = shr( mult( tmp, _180_OVER_PI_Q9 ), 7 ); // Q0; - IF(EQ_16(index_azimuth, -180)) + IF( EQ_16( index_azimuth, -180 ) ) { - tmp = 0; move16(); + tmp = 0; + move16(); } ELSE { - tmp = idiv1616( add( index_azimuth, 180 ), 360 ); + tmp = idiv1616( add( index_azimuth, 180 ), 360 ); } index_azimuth = sub( add( index_azimuth, 180 ), i_mult( tmp, 360 ) ); // index_azimuth = (index_azimuth + 180) % 360 @@ -4551,7 +4557,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( } } - IF( masa_band_mapping == NULL && EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) + IF( masa_band_mapping == NULL && EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { mvr2r_inc_fixed( direct_response_hoa_fx, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); @@ -4710,7 +4716,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( ismDirect_fx = L_add( ismDirect_fx, hMasaIsm->energy_ratio_ism_fx[dir][md_idx][k] ); } - totalDirect_fx = L_add_sat( masaDirect_fx, ismDirect_fx ); // saturating as 1.0 (Q30) + 1.0 (Q30) is observed + totalDirect_fx = L_add_sat( masaDirect_fx, ismDirect_fx ); // saturating as 1.0 (Q30) + 1.0 (Q30) is observed Word16 var_a = 0, var_b = 0; var_a = BASOP_Util_Divide3232_Scale( masaDirect_fx, totalDirect_fx, &exp_1 ); var_b = BASOP_Util_Divide3232_Scale( ismDirect_fx, totalDirect_fx, &exp_2 ); @@ -4958,7 +4964,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( ismDirect_fx = L_add( ismDirect_fx, hMasaIsm->energy_ratio_ism_fx[dir][md_idx][k] ); } - totalDirect_fx = L_add_sat( masaDirect_fx, ismDirect_fx ); // saturating as 1.0 (Q30) + 1.0 (Q30) is observed + totalDirect_fx = L_add_sat( masaDirect_fx, ismDirect_fx ); // saturating as 1.0 (Q30) + 1.0 (Q30) is observed Word16 var_a = 0, var_b = 0; move16(); var_a = BASOP_Util_Divide3232_Scale( masaDirect_fx, totalDirect_fx, &exp_1 ); @@ -5127,7 +5133,7 @@ void ivas_dirac_dec_compute_directional_responses( elevation2 = NULL; transport_signal_type = MASA_STEREO_NOT_DEFINED; - if (hDirACRend->masa_stereo_type_detect != NULL) + if ( hDirACRend->masa_stereo_type_detect != NULL ) { dipole_freq_range[0] = hDirACRend->masa_stereo_type_detect->dipole_freq_range[0]; dipole_freq_range[1] = hDirACRend->masa_stereo_type_detect->dipole_freq_range[1]; @@ -5135,7 +5141,7 @@ void ivas_dirac_dec_compute_directional_responses( } num_channels_dir = hDirACRend->num_outputs_dir; - if (hSpatParamRendCom->numParametricDirections == 2) + if ( hSpatParamRendCom->numParametricDirections == 2 ) { azimuth2 = hSpatParamRendCom->azimuth2[md_idx]; elevation2 = hSpatParamRendCom->elevation2[md_idx]; @@ -5143,89 +5149,89 @@ void ivas_dirac_dec_compute_directional_responses( codingBand = -1; - assert(num_channels_dir <= MAX_OUTPUT_CHANNELS && "Number of channels is too high"); + assert( num_channels_dir <= MAX_OUTPUT_CHANNELS && "Number of channels is too high" ); - for (k = 0; k < hSpatParamRendCom->num_freq_bands; ++k) + for ( k = 0; k < hSpatParamRendCom->num_freq_bands; ++k ) { - if (masa_band_mapping != NULL && k == MASA_band_grouping_24[masa_band_mapping[codingBand + 1]]) + if ( masa_band_mapping != NULL && k == MASA_band_grouping_24[masa_band_mapping[codingBand + 1]] ) { codingBand++; } - if (masa_band_mapping != NULL && k > MASA_band_grouping_24[masa_band_mapping[codingBand]] && - k < MASA_band_grouping_24[masa_band_mapping[codingBand + 1]] && - k != hDirACRend->h_output_synthesis_psd_params.max_band_decorr) + if ( masa_band_mapping != NULL && k > MASA_band_grouping_24[masa_band_mapping[codingBand]] && + k < MASA_band_grouping_24[masa_band_mapping[codingBand + 1]] && + k != hDirACRend->h_output_synthesis_psd_params.max_band_decorr ) { /* Panning gains have to be computed only for the first bin of the coding band in MASA, for other bins the previous values can be used */ - if (hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD) + if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) { - mvr2r_inc(&hDirACRend->h_output_synthesis_psd_state.direct_responses_square[k - 1], - hSpatParamRendCom->num_freq_bands, &hDirACRend->h_output_synthesis_psd_state.direct_responses_square[k], - hSpatParamRendCom->num_freq_bands, num_channels_dir); + mvr2r_inc( &hDirACRend->h_output_synthesis_psd_state.direct_responses_square[k - 1], + hSpatParamRendCom->num_freq_bands, &hDirACRend->h_output_synthesis_psd_state.direct_responses_square[k], + hSpatParamRendCom->num_freq_bands, num_channels_dir ); } - mvr2r_inc(&hDirACRend->h_output_synthesis_psd_state.direct_responses[k - 1], - hSpatParamRendCom->num_freq_bands, - &hDirACRend->h_output_synthesis_psd_state.direct_responses[k], - hSpatParamRendCom->num_freq_bands, num_channels_dir); + mvr2r_inc( &hDirACRend->h_output_synthesis_psd_state.direct_responses[k - 1], + hSpatParamRendCom->num_freq_bands, + &hDirACRend->h_output_synthesis_psd_state.direct_responses[k], + hSpatParamRendCom->num_freq_bands, num_channels_dir ); } else { /* HOA3 PANNING */ - if (hDirACRend->panningConf == DIRAC_PANNING_HOA3) + if ( hDirACRend->panningConf == DIRAC_PANNING_HOA3 ) { - set_f(direct_response_hoa, 1.0f, MAX_OUTPUT_CHANNELS); - set_f(direct_response_dir2, 1.0f, MAX_OUTPUT_CHANNELS); + set_f( direct_response_hoa, 1.0f, MAX_OUTPUT_CHANNELS ); + set_f( direct_response_dir2, 1.0f, MAX_OUTPUT_CHANNELS ); - if (p_Rmat != 0) + if ( p_Rmat != 0 ) { - ivas_dirac_dec_get_response_split_order(azimuth[k], elevation[k], direct_response_hoa, shd_rot_max_order, p_Rmat); + ivas_dirac_dec_get_response_split_order( azimuth[k], elevation[k], direct_response_hoa, shd_rot_max_order, p_Rmat ); - if (hodirac_flag) + if ( hodirac_flag ) { - ivas_dirac_dec_get_response_split_order(azimuth2[k], elevation2[k], direct_response_dir2, shd_rot_max_order, p_Rmat); + ivas_dirac_dec_get_response_split_order( azimuth2[k], elevation2[k], direct_response_dir2, shd_rot_max_order, p_Rmat ); } } else { - ivas_dirac_dec_get_response(azimuth[k], elevation[k], direct_response_hoa, hDirACRend->hOutSetup.ambisonics_order); + ivas_dirac_dec_get_response( azimuth[k], elevation[k], direct_response_hoa, hDirACRend->hOutSetup.ambisonics_order ); - if (hodirac_flag) + if ( hodirac_flag ) { - ivas_dirac_dec_get_response(azimuth2[k], elevation2[k], direct_response_dir2, hDirACRend->hOutSetup.ambisonics_order); + ivas_dirac_dec_get_response( azimuth2[k], elevation2[k], direct_response_dir2, hDirACRend->hOutSetup.ambisonics_order ); } } - if (masa_band_mapping == NULL && hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD) + if ( masa_band_mapping == NULL && hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { - mvr2r_inc(direct_response_hoa, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses[k], hSpatParamRendCom->num_freq_bands, num_channels_dir); + mvr2r_inc( direct_response_hoa, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); - if (hodirac_flag) + if ( hodirac_flag ) { - mvr2r_inc(direct_response_dir2, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses[k + hSpatParamRendCom->num_freq_bands * num_channels_dir], hSpatParamRendCom->num_freq_bands, num_channels_dir); + mvr2r_inc( direct_response_dir2, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses[k + hSpatParamRendCom->num_freq_bands * num_channels_dir], hSpatParamRendCom->num_freq_bands, num_channels_dir ); } } - else if (((hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD) && (masa_band_mapping != NULL)) || - hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD || hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO) + else if ( ( ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) && ( masa_band_mapping != NULL ) ) || + hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD || hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO ) { /* Synthesize the first direction */ - spreadCoherencePanningHoa(azimuth[k], elevation[k], hSpatParamRendCom->spreadCoherence[md_idx][k], direct_response_hoa, num_channels_dir, hDirACRend->hOutSetup.ambisonics_order); + spreadCoherencePanningHoa( azimuth[k], elevation[k], hSpatParamRendCom->spreadCoherence[md_idx][k], direct_response_hoa, num_channels_dir, hDirACRend->hOutSetup.ambisonics_order ); /* Synthesize the second direction and combine the gains */ - if (hSpatParamRendCom->numParametricDirections == 2) + if ( hSpatParamRendCom->numParametricDirections == 2 ) { - spreadCoherencePanningHoa(azimuth2[k], elevation2[k], hSpatParamRendCom->spreadCoherence2[md_idx][k], direct_response_dir2, num_channels_dir, hDirACRend->hOutSetup.ambisonics_order); + spreadCoherencePanningHoa( azimuth2[k], elevation2[k], hSpatParamRendCom->spreadCoherence2[md_idx][k], direct_response_dir2, num_channels_dir, hDirACRend->hOutSetup.ambisonics_order ); /* Combine gains from the two directions */ totalDirect = hSpatParamRendCom->energy_ratio1[md_idx][k] + hSpatParamRendCom->energy_ratio2[md_idx][k] + EPSILON; directRatio[0] = hSpatParamRendCom->energy_ratio1[md_idx][k] / totalDirect; directRatio[1] = hSpatParamRendCom->energy_ratio2[md_idx][k] / totalDirect; - for (l = 0; l < num_channels_dir; l++) + for ( l = 0; l < num_channels_dir; l++ ) { direct_response_hoa[l] *= directRatio[0]; direct_response_hoa[l] += directRatio[1] * direct_response_dir2[l]; } } - if (hSpatParamRendCom->numIsmDirections > 0) + if ( hSpatParamRendCom->numIsmDirections > 0 ) { int16_t dir; float direct_response_temp[MAX_OUTPUT_CHANNELS]; @@ -5233,33 +5239,33 @@ void ivas_dirac_dec_compute_directional_responses( float masaDirect; float ismDirect; - set_zero(direct_response_ism, num_channels_dir); + set_zero( direct_response_ism, num_channels_dir ); - for (dir = 0; dir < hSpatParamRendCom->numIsmDirections; dir++) + for ( dir = 0; dir < hSpatParamRendCom->numIsmDirections; dir++ ) { - if (hMasaIsm->ism_is_edited[dir]) + if ( hMasaIsm->ism_is_edited[dir] ) { - ivas_dirac_dec_get_response(hMasaIsm->azimuth_ism_edited[dir], hMasaIsm->elevation_ism_edited[dir], direct_response_temp, hDirACRend->hOutSetup.ambisonics_order); + ivas_dirac_dec_get_response( hMasaIsm->azimuth_ism_edited[dir], hMasaIsm->elevation_ism_edited[dir], direct_response_temp, hDirACRend->hOutSetup.ambisonics_order ); } else { - ivas_dirac_dec_get_response(hMasaIsm->azimuth_ism[dir][md_idx], hMasaIsm->elevation_ism[dir][md_idx], direct_response_temp, hDirACRend->hOutSetup.ambisonics_order); + ivas_dirac_dec_get_response( hMasaIsm->azimuth_ism[dir][md_idx], hMasaIsm->elevation_ism[dir][md_idx], direct_response_temp, hDirACRend->hOutSetup.ambisonics_order ); } - for (l = 0; l < num_channels_dir; l++) + for ( l = 0; l < num_channels_dir; l++ ) { direct_response_ism[l] += direct_response_temp[l] * hMasaIsm->energy_ratio_ism[dir][md_idx][k]; } } masaDirect = hSpatParamRendCom->energy_ratio1[md_idx][k] + EPSILON; - if (hSpatParamRendCom->numParametricDirections == 2) + if ( hSpatParamRendCom->numParametricDirections == 2 ) { masaDirect += hSpatParamRendCom->energy_ratio2[md_idx][k]; } ismDirect = hMasaIsm->energy_ratio_ism[0][md_idx][k]; - for (dir = 1; dir < hSpatParamRendCom->numIsmDirections; dir++) + for ( dir = 1; dir < hSpatParamRendCom->numIsmDirections; dir++ ) { ismDirect += hMasaIsm->energy_ratio_ism[dir][md_idx][k]; } @@ -5267,7 +5273,7 @@ void ivas_dirac_dec_compute_directional_responses( totalDirect = masaDirect + ismDirect; directRatio[0] = masaDirect / totalDirect; directRatio[1] = ismDirect / totalDirect; - for (l = 0; l < num_channels_dir; l++) + for ( l = 0; l < num_channels_dir; l++ ) { direct_response_hoa[l] *= directRatio[0]; direct_response_hoa[l] += directRatio[1] * direct_response_ism[l]; @@ -5275,122 +5281,122 @@ void ivas_dirac_dec_compute_directional_responses( } /* Synthesize surrounding coherence */ - if (surCohRatio != NULL && surCohRatio[k] > 0.f) + if ( surCohRatio != NULL && surCohRatio[k] > 0.f ) { - for (l = 1; l < num_channels_dir; l++) + for ( l = 1; l < num_channels_dir; l++ ) { - direct_response_hoa[l] *= sqrtf(1.0f - surCohRatio[k]); + direct_response_hoa[l] *= sqrtf( 1.0f - surCohRatio[k] ); } } /* Set computed gains */ direct_response = direct_response_hoa; - if (hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD) + if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) { - v_mult(direct_response, direct_response, direct_response_square, num_channels_dir); - mvr2r_inc(direct_response_square, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_square[k], hSpatParamRendCom->num_freq_bands, num_channels_dir); + v_mult( direct_response, direct_response, direct_response_square, num_channels_dir ); + mvr2r_inc( direct_response_square, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_square[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); - if (transport_signal_type == MASA_STEREO_SPACED_MICS) + if ( transport_signal_type == MASA_STEREO_SPACED_MICS ) { direct_response[0] = 1.0f; - if (k >= dipole_freq_range[0] && k < dipole_freq_range[1]) + if ( k >= dipole_freq_range[0] && k < dipole_freq_range[1] ) { direct_response[1] = 1.0f; } } else { - set_f(direct_response, 1.0f, hDirACRend->num_protos_ambi); + set_f( direct_response, 1.0f, hDirACRend->num_protos_ambi ); } } - mvr2r_inc(direct_response, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses[k], hSpatParamRendCom->num_freq_bands, num_channels_dir); + mvr2r_inc( direct_response, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); } else { - assert(0 && "Not supported synthesis method!"); + assert( 0 && "Not supported synthesis method!" ); } } - else if (hDirACRend->panningConf == DIRAC_PANNING_VBAP) /*VBAP*/ + else if ( hDirACRend->panningConf == DIRAC_PANNING_VBAP ) /*VBAP*/ { /* Synthesize the first direction */ - spreadCoherencePanningVbap(azimuth[k], elevation[k], hSpatParamRendCom->spreadCoherence[md_idx][k], direct_response_ls, num_channels_dir, hVBAPdata); - normalizePanningGains(direct_response_ls, num_channels_dir); + spreadCoherencePanningVbap( azimuth[k], elevation[k], hSpatParamRendCom->spreadCoherence[md_idx][k], direct_response_ls, num_channels_dir, hVBAPdata ); + normalizePanningGains( direct_response_ls, num_channels_dir ); /* Synthesize the second direction and combine the gains */ - if (hSpatParamRendCom->numParametricDirections == 2) + if ( hSpatParamRendCom->numParametricDirections == 2 ) { - spreadCoherencePanningVbap(azimuth2[k], elevation2[k], hSpatParamRendCom->spreadCoherence2[md_idx][k], direct_response_dir2, num_channels_dir, hVBAPdata); - normalizePanningGains(direct_response_dir2, num_channels_dir); + spreadCoherencePanningVbap( azimuth2[k], elevation2[k], hSpatParamRendCom->spreadCoherence2[md_idx][k], direct_response_dir2, num_channels_dir, hVBAPdata ); + normalizePanningGains( direct_response_dir2, num_channels_dir ); /* Combine gains from the two directions */ totalDirect = hSpatParamRendCom->energy_ratio1[md_idx][k] + hSpatParamRendCom->energy_ratio2[md_idx][k] + EPSILON; directRatio[0] = hSpatParamRendCom->energy_ratio1[md_idx][k] / totalDirect; directRatio[1] = hSpatParamRendCom->energy_ratio2[md_idx][k] / totalDirect; - for (l = 0; l < num_channels_dir; l++) + for ( l = 0; l < num_channels_dir; l++ ) { direct_response_ls[l] *= directRatio[0]; direct_response_ls[l] += directRatio[1] * direct_response_dir2[l]; } - normalizePanningGains(direct_response_ls, num_channels_dir); + normalizePanningGains( direct_response_ls, num_channels_dir ); } - if (hSpatParamRendCom->numIsmDirections > 0) + if ( hSpatParamRendCom->numIsmDirections > 0 ) { int16_t dir; float direct_response_temp[MAX_OUTPUT_CHANNELS]; #ifdef IVAS_FLOAT_FIXED Word32 direct_response_temp_fx[MAX_OUTPUT_CHANNELS]; - set32_fx(direct_response_temp_fx, 0, MAX_OUTPUT_CHANNELS); + set32_fx( direct_response_temp_fx, 0, MAX_OUTPUT_CHANNELS ); #endif float direct_response_ism[MAX_OUTPUT_CHANNELS]; float masaDirect; float ismDirect; - set_zero(direct_response_ism, num_channels_dir); + set_zero( direct_response_ism, num_channels_dir ); - for (dir = 0; dir < hSpatParamRendCom->numIsmDirections; dir++) + for ( dir = 0; dir < hSpatParamRendCom->numIsmDirections; dir++ ) { - if (hMasaIsm->ism_is_edited[dir]) + if ( hMasaIsm->ism_is_edited[dir] ) { #ifdef IVAS_FLOAT_FIXED - vbap_determine_gains_fx(hVBAPdata, direct_response_temp_fx, hMasaIsm->azimuth_ism_edited[dir], hMasaIsm->elevation_ism_edited[dir], 1); - FOR(int i = 0; i < MAX_OUTPUT_CHANNELS; i++) + vbap_determine_gains_fx( hVBAPdata, direct_response_temp_fx, hMasaIsm->azimuth_ism_edited[dir], hMasaIsm->elevation_ism_edited[dir], 1 ); + FOR( int i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) { - direct_response_temp[i] = fix_to_float(direct_response_temp_fx[i], Q29); + direct_response_temp[i] = fix_to_float( direct_response_temp_fx[i], Q29 ); } #else - vbap_determine_gains(hVBAPdata, direct_response_temp, hMasaIsm->azimuth_ism_edited[dir], hMasaIsm->elevation_ism_edited[dir], 1); + vbap_determine_gains( hVBAPdata, direct_response_temp, hMasaIsm->azimuth_ism_edited[dir], hMasaIsm->elevation_ism_edited[dir], 1 ); #endif } else { #ifdef IVAS_FLOAT_FIXED - vbap_determine_gains_fx(hVBAPdata, direct_response_temp_fx, hMasaIsm->azimuth_ism[dir][md_idx], hMasaIsm->elevation_ism[dir][md_idx], 1); - FOR(int i = 0; i < MAX_OUTPUT_CHANNELS; i++) + vbap_determine_gains_fx( hVBAPdata, direct_response_temp_fx, hMasaIsm->azimuth_ism[dir][md_idx], hMasaIsm->elevation_ism[dir][md_idx], 1 ); + FOR( int i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) { - direct_response_temp[i] = fix_to_float(direct_response_temp_fx[i], Q29); + direct_response_temp[i] = fix_to_float( direct_response_temp_fx[i], Q29 ); } #else - vbap_determine_gains(hVBAPdata, direct_response_temp, hMasaIsm->azimuth_ism[dir][md_idx], hMasaIsm->elevation_ism[dir][md_idx], 1); + vbap_determine_gains( hVBAPdata, direct_response_temp, hMasaIsm->azimuth_ism[dir][md_idx], hMasaIsm->elevation_ism[dir][md_idx], 1 ); #endif } - for (l = 0; l < num_channels_dir; l++) + for ( l = 0; l < num_channels_dir; l++ ) { direct_response_ism[l] += direct_response_temp[l] * hMasaIsm->energy_ratio_ism[dir][md_idx][k]; } } - normalizePanningGains(direct_response_ism, num_channels_dir); + normalizePanningGains( direct_response_ism, num_channels_dir ); masaDirect = hSpatParamRendCom->energy_ratio1[md_idx][k] + EPSILON; - if (hSpatParamRendCom->numParametricDirections == 2) + if ( hSpatParamRendCom->numParametricDirections == 2 ) { masaDirect += hSpatParamRendCom->energy_ratio2[md_idx][k]; } ismDirect = hMasaIsm->energy_ratio_ism[0][md_idx][k]; - for (dir = 1; dir < hSpatParamRendCom->numIsmDirections; dir++) + for ( dir = 1; dir < hSpatParamRendCom->numIsmDirections; dir++ ) { ismDirect += hMasaIsm->energy_ratio_ism[dir][md_idx][k]; } @@ -5398,43 +5404,43 @@ void ivas_dirac_dec_compute_directional_responses( totalDirect = masaDirect + ismDirect; directRatio[0] = masaDirect / totalDirect; directRatio[1] = ismDirect / totalDirect; - for (l = 0; l < num_channels_dir; l++) + for ( l = 0; l < num_channels_dir; l++ ) { direct_response_ls[l] *= directRatio[0]; direct_response_ls[l] += directRatio[1] * direct_response_ism[l]; } - normalizePanningGains(direct_response_ls, num_channels_dir); + normalizePanningGains( direct_response_ls, num_channels_dir ); } /* Synthesize surrounding coherence */ - if (surCohRatio != NULL && surCohRatio[k] > 0.f) + if ( surCohRatio != NULL && surCohRatio[k] > 0.f ) { int16_t num_channels_surrCoh; num_channels_surrCoh = num_channels_dir; num_channels_surrCoh -= hDirACRend->num_ele_spk_no_diffuse_rendering; - for (l = 0; l < num_channels_dir; l++) + for ( l = 0; l < num_channels_dir; l++ ) { - direct_response_ls[l] *= sqrtf(1.0f - surCohRatio[k]); - if (hDirACRend->diffuse_response_function[l] > 0.f) + direct_response_ls[l] *= sqrtf( 1.0f - surCohRatio[k] ); + if ( hDirACRend->diffuse_response_function[l] > 0.f ) { - direct_response_ls[l] += sqrtf(surCohRatio[k] / (float)num_channels_surrCoh); + direct_response_ls[l] += sqrtf( surCohRatio[k] / (float) num_channels_surrCoh ); } } } - normalizePanningGains(direct_response_ls, num_channels_dir); + normalizePanningGains( direct_response_ls, num_channels_dir ); /* Set computed gains */ direct_response = direct_response_ls; - v_mult(direct_response, direct_response, direct_response_square, num_channels_dir); - mvr2r_inc(direct_response_square, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_square[k], hSpatParamRendCom->num_freq_bands, num_channels_dir); - mvr2r_inc(direct_response, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses[k], hSpatParamRendCom->num_freq_bands, num_channels_dir); + v_mult( direct_response, direct_response, direct_response_square, num_channels_dir ); + mvr2r_inc( direct_response_square, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_square[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); + mvr2r_inc( direct_response, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); } else { - assert(0 && "Not supported panning method!"); + assert( 0 && "Not supported panning method!" ); } } } @@ -5558,14 +5564,13 @@ void ivas_dirac_dec_compute_power_factors_fx( const Word32 *diffuseness_fx, // Q3O const Word16 max_band_decorr, Word32 *direct_power_factor, - Word32 *diffuse_power_factor -) + Word32 *diffuse_power_factor ) { v_multc_fixed( diffuseness_fx, L_negate( ( ONE_IN_Q31 ) ), direct_power_factor, num_freq_bands ); // Q30 - v_addc_fixed( direct_power_factor, ONE_IN_Q30, direct_power_factor, num_freq_bands ); // Q30 + v_addc_fixed( direct_power_factor, ONE_IN_Q30, direct_power_factor, num_freq_bands ); // Q30 - Copy32( diffuseness_fx, diffuse_power_factor, num_freq_bands ); // Q30 + Copy32( diffuseness_fx, diffuse_power_factor, num_freq_bands ); // Q30 v_mult_fixed( &direct_power_factor[max_band_decorr], &direct_power_factor[max_band_decorr], &direct_power_factor[max_band_decorr], num_freq_bands - max_band_decorr ); // Q29 @@ -6281,51 +6286,53 @@ static void computeTargetPSDs_diffuse_with_onsets( } #endif #ifdef IVAS_FLOAT_FIXED -static void computeAlphaSynthesis_fx(Word16 *alpha_synthesis_fx, const Word16 averaging_length_ms, const Word16 maxAlpha_fx, Word16 *numAlphas, const Word16 slot_size, const Word16 num_freq_bands, Word16 *frequency_axis_fx, const Word32 output_Fs) +static void computeAlphaSynthesis_fx( Word16 *alpha_synthesis_fx, const Word16 averaging_length_ms, const Word16 maxAlpha_fx, Word16 *numAlphas, const Word16 slot_size, const Word16 num_freq_bands, Word16 *frequency_axis_fx, const Word32 output_Fs ) { Word16 k; Word16 avg_length_f_ms_fx; /* check input pointer */ - IF (alpha_synthesis_fx == NULL) + IF( alpha_synthesis_fx == NULL ) { return; } - IF (averaging_length_ms == 0) + IF( averaging_length_ms == 0 ) { - set16_fx(alpha_synthesis_fx, MAX16B, num_freq_bands); + set16_fx( alpha_synthesis_fx, MAX16B, num_freq_bands ); } ELSE { - FOR (k = 0; k < num_freq_bands; k++) + FOR( k = 0; k < num_freq_bands; k++ ) { - Word16 faxis_idx = s_max(k, 1); - //avg_length_f_ms = 1000.f * (float)averaging_length_ms / fabsf(frequency_axis[faxis_idx]); + Word16 faxis_idx = s_max( k, 1 ); + // avg_length_f_ms = 1000.f * (float)averaging_length_ms / fabsf(frequency_axis[faxis_idx]); Word16 tmp_exp = 0; - Word16 tmp_1 = BASOP_Util_Divide1616_Scale(averaging_length_ms, frequency_axis_fx[faxis_idx], &tmp_exp); - Word16 tmp_2 = mult(tmp_1, 1000);//15 - tmp_exp + 0 -15 = -tmp_exp (Q-fac) + Word16 tmp_1 = BASOP_Util_Divide1616_Scale( averaging_length_ms, frequency_axis_fx[faxis_idx], &tmp_exp ); + Word16 tmp_2 = mult( tmp_1, 1000 ); // 15 - tmp_exp + 0 -15 = -tmp_exp (Q-fac) avg_length_f_ms_fx = tmp_2; - Word32 tmp_3 = Mpy_32_16_1(output_Fs, avg_length_f_ms_fx);//0 - tmp_exp - 15 (Q-fac) + Word32 tmp_3 = Mpy_32_16_1( output_Fs, avg_length_f_ms_fx ); // 0 - tmp_exp - 15 (Q-fac) Word16 tmp_exp_3 = 0; - Word16 tmp_4 = BASOP_Util_Divide3232_Scale(tmp_3 , 1000, &tmp_exp_3); - Word16 tmp_exp_4 = tmp_exp_3 + (31 + tmp_exp + 15 ) - 31; + Word16 tmp_4 = BASOP_Util_Divide3232_Scale( tmp_3, 1000, &tmp_exp_3 ); + Word16 tmp_exp_4 = tmp_exp_3 + ( 31 + tmp_exp + 15 ) - 31; Word16 tmp_exp_5 = 0; - Word16 tmp_5 = BASOP_Util_Divide1616_Scale(slot_size , tmp_4, &tmp_exp_5); + Word16 tmp_5 = BASOP_Util_Divide1616_Scale( slot_size, tmp_4, &tmp_exp_5 ); Word16 res_exp = tmp_exp_5 + 15 - tmp_exp_4; - - Word16 flag = BASOP_Util_Cmp_Mant32Exp(L_deposit_h(tmp_5), res_exp, 1, 31); - IF (flag == -1) { - alpha_synthesis_fx[k] = shr(tmp_5, negate(res_exp)); //q15 + + Word16 flag = BASOP_Util_Cmp_Mant32Exp( L_deposit_h( tmp_5 ), res_exp, 1, 31 ); + IF( flag == -1 ) + { + alpha_synthesis_fx[k] = shr( tmp_5, negate( res_exp ) ); // q15 } - ELSE { + ELSE + { alpha_synthesis_fx[k] = MAX16B; } - Word16 flag2 = BASOP_Util_Cmp_Mant32Exp(L_deposit_h(alpha_synthesis_fx[k]), 0, L_deposit_h(maxAlpha_fx), 0); - IF (flag2 == 0 || flag2 == 1) + Word16 flag2 = BASOP_Util_Cmp_Mant32Exp( L_deposit_h( alpha_synthesis_fx[k] ), 0, L_deposit_h( maxAlpha_fx ), 0 ); + IF( flag2 == 0 || flag2 == 1 ) { alpha_synthesis_fx[k] = maxAlpha_fx; *numAlphas = k + 1; @@ -6346,29 +6353,29 @@ static void computeAlphaSynthesis( const int16_t slot_size, const int16_t num_freq_bands, const float *frequency_axis, - const int32_t output_Fs) + const int32_t output_Fs ) { int16_t k; float avg_length_f_ms; /* check input pointer */ - if (alpha_synthesis == NULL) + if ( alpha_synthesis == NULL ) { return; } - if (averaging_length_ms == 0) + if ( averaging_length_ms == 0 ) { - set_f(alpha_synthesis, 1.0f, num_freq_bands); + set_f( alpha_synthesis, 1.0f, num_freq_bands ); } else { - for (k = 0; k < num_freq_bands; k++) + for ( k = 0; k < num_freq_bands; k++ ) { - int16_t faxis_idx = max(k, 1); - avg_length_f_ms = 1000.f * (float)averaging_length_ms / fabsf(frequency_axis[faxis_idx]); - alpha_synthesis[k] = min((float)slot_size / (avg_length_f_ms * (float)output_Fs / 1000.f), 1.0f); - if (alpha_synthesis[k] >= maxAlpha) + int16_t faxis_idx = max( k, 1 ); + avg_length_f_ms = 1000.f * (float) averaging_length_ms / fabsf( frequency_axis[faxis_idx] ); + alpha_synthesis[k] = min( (float) slot_size / ( avg_length_f_ms * (float) output_Fs / 1000.f ), 1.0f ); + if ( alpha_synthesis[k] >= maxAlpha ) { alpha_synthesis[k] = maxAlpha; *numAlphas = k + 1; @@ -6384,7 +6391,7 @@ static void computeAlphaSynthesis( static void spreadCoherencePanningHoa_fx( const Word16 azimuth, const Word16 elevation, - const Word16 spreadCoh_fx, /*Q15*/ + const Word16 spreadCoh_fx, /*Q15*/ Word32 *direct_response_fx, /*Q29*/ Word16 *Q_direct_response, /*Q29*/ const Word16 num_channels_dir, @@ -6510,13 +6517,13 @@ static void spreadCoherencePanningVbap_fx( Word32 *direct_response_fx, Word16 *Q_direct_response, const Word16 num_channels_dir, - const VBAP_HANDLE hVBAPdata) + const VBAP_HANDLE hVBAPdata ) { int16_t i; Word32 direct_response_left_fx[MAX_OUTPUT_CHANNELS]; Word32 direct_response_right_fx[MAX_OUTPUT_CHANNELS]; - set32_fx(direct_response_left_fx, 0, MAX_OUTPUT_CHANNELS); - set32_fx(direct_response_right_fx, 0, MAX_OUTPUT_CHANNELS); + set32_fx( direct_response_left_fx, 0, MAX_OUTPUT_CHANNELS ); + set32_fx( direct_response_right_fx, 0, MAX_OUTPUT_CHANNELS ); Word32 gainCenter_fx; Word32 gainSide_fx; diff --git a/lib_rend/ivas_dirac_rend.c b/lib_rend/ivas_dirac_rend.c index 5f526df8e..5079c6d47 100644 --- a/lib_rend/ivas_dirac_rend.c +++ b/lib_rend/ivas_dirac_rend.c @@ -379,9 +379,9 @@ ivas_error ivas_spat_hSpatParamRendCom_config_fx( hSpatParamRendCom->subframes_rendered = 0; hSpatParamRendCom->slots_rendered = 0; hSpatParamRendCom->num_slots = DEFAULT_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME; - var1 = BASOP_Util_Divide3232_Scale(output_Fs, CLDFB_BANDWIDTH, &exp_tmp3); - var2 = shl(1, 15 - exp_tmp3 - 1 ); - hSpatParamRendCom->num_freq_bands = shr(add(var1, var2), 15 - exp_tmp3); + var1 = BASOP_Util_Divide3232_Scale( output_Fs, CLDFB_BANDWIDTH, &exp_tmp3 ); + var2 = shl( 1, 15 - exp_tmp3 - 1 ); + hSpatParamRendCom->num_freq_bands = shr( add( var1, var2 ), 15 - exp_tmp3 ); hSpatParamRendCom->numSimultaneousDirections = 0; hSpatParamRendCom->numParametricDirections = 0; hSpatParamRendCom->numIsmDirections = 0; @@ -479,46 +479,46 @@ ivas_error ivas_spat_hSpatParamRendCom_config( const MC_MODE mc_mode, const int32_t output_Fs, const int16_t hodirac_flag, - const int16_t masa_ext_rend_flag) + const int16_t masa_ext_rend_flag ) { ivas_error error; int16_t map_idx; DIRAC_CONFIG_FLAG flag_config; SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; - flag_config = (flag_config_inp == DIRAC_RECONFIGURE_MODE) ? DIRAC_RECONFIGURE : flag_config_inp; + flag_config = ( flag_config_inp == DIRAC_RECONFIGURE_MODE ) ? DIRAC_RECONFIGURE : flag_config_inp; error = IVAS_ERR_OK; hSpatParamRendCom = NULL; - if (flag_config == DIRAC_RECONFIGURE) + if ( flag_config == DIRAC_RECONFIGURE ) { hSpatParamRendCom = *hSpatParamRendCom_out; } - else if (flag_config == DIRAC_OPEN) + else if ( flag_config == DIRAC_OPEN ) { /*-----------------------------------------------------------------* * prepare library opening *-----------------------------------------------------------------*/ - if ((hSpatParamRendCom = (SPAT_PARAM_REND_COMMON_DATA_HANDLE)malloc(sizeof(SPAT_PARAM_REND_COMMON_DATA))) == NULL) + if ( ( hSpatParamRendCom = (SPAT_PARAM_REND_COMMON_DATA_HANDLE) malloc( sizeof( SPAT_PARAM_REND_COMMON_DATA ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC meta\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC meta\n" ) ); } *hSpatParamRendCom_out = hSpatParamRendCom; } - if (flag_config == DIRAC_OPEN) + if ( flag_config == DIRAC_OPEN ) { - hSpatParamRendCom->slot_size = (int16_t)((output_Fs / FRAMES_PER_SEC) / CLDFB_NO_COL_MAX); - set_s(hSpatParamRendCom->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS); - set_s(hSpatParamRendCom->subframe_nbslots, JBM_CLDFB_SLOTS_IN_SUBFRAME, DEFAULT_JBM_SUBFRAMES_5MS); + hSpatParamRendCom->slot_size = (int16_t) ( ( output_Fs / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX ); + set_s( hSpatParamRendCom->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS ); + set_s( hSpatParamRendCom->subframe_nbslots, JBM_CLDFB_SLOTS_IN_SUBFRAME, DEFAULT_JBM_SUBFRAMES_5MS ); hSpatParamRendCom->nb_subframes = DEFAULT_JBM_SUBFRAMES_5MS; hSpatParamRendCom->subframes_rendered = 0; hSpatParamRendCom->slots_rendered = 0; hSpatParamRendCom->num_slots = DEFAULT_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME; - hSpatParamRendCom->num_freq_bands = (int16_t)(output_Fs * INV_CLDFB_BANDWIDTH + 0.5f); + hSpatParamRendCom->num_freq_bands = (int16_t) ( output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ); hSpatParamRendCom->numSimultaneousDirections = 0; hSpatParamRendCom->numParametricDirections = 0; hSpatParamRendCom->numIsmDirections = 0; @@ -528,43 +528,43 @@ ivas_error ivas_spat_hSpatParamRendCom_config( * set input parameters *-----------------------------------------------------------------*/ - if ((ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT) && flag_config == DIRAC_RECONFIGURE) + if ( ( ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT ) && flag_config == DIRAC_RECONFIGURE ) { - if (hodirac_flag && hSpatParamRendCom->azimuth2 == NULL) + if ( hodirac_flag && hSpatParamRendCom->azimuth2 == NULL ) { - if ((error = ivas_dirac_allocate_parameters(hSpatParamRendCom, 2)) != IVAS_ERR_OK) + if ( ( error = ivas_dirac_allocate_parameters( hSpatParamRendCom, 2 ) ) != IVAS_ERR_OK ) { return error; } } - else if (!hodirac_flag && hSpatParamRendCom->azimuth2 != NULL) + else if ( !hodirac_flag && hSpatParamRendCom->azimuth2 != NULL ) { - ivas_dirac_deallocate_parameters(hSpatParamRendCom, 2); + ivas_dirac_deallocate_parameters( hSpatParamRendCom, 2 ); } } - if (flag_config == DIRAC_OPEN) + if ( flag_config == DIRAC_OPEN ) { hSpatParamRendCom->dirac_md_buffer_length = 0; hSpatParamRendCom->dirac_bs_md_write_idx = 0; hSpatParamRendCom->dirac_read_idx = 0; - if (mc_mode == MC_MODE_MCMASA || masa_ext_rend_flag == 1) + if ( mc_mode == MC_MODE_MCMASA || masa_ext_rend_flag == 1 ) { hSpatParamRendCom->dirac_md_buffer_length = MAX_PARAM_SPATIAL_SUBFRAMES; - set_s(hSpatParamRendCom->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME); - for (map_idx = 0; map_idx < DEFAULT_JBM_SUBFRAMES_5MS; map_idx++) + set_s( hSpatParamRendCom->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME ); + for ( map_idx = 0; map_idx < DEFAULT_JBM_SUBFRAMES_5MS; map_idx++ ) { hSpatParamRendCom->render_to_md_map[map_idx] = map_idx; } } - else if (ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT) + else if ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) { hSpatParamRendCom->dirac_md_buffer_length = MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR; hSpatParamRendCom->dirac_bs_md_write_idx = DELAY_MASA_PARAM_DEC_SFR; - set_s(hSpatParamRendCom->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME); - for (map_idx = 0; map_idx < DEFAULT_JBM_SUBFRAMES_5MS; map_idx++) + set_s( hSpatParamRendCom->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME ); + for ( map_idx = 0; map_idx < DEFAULT_JBM_SUBFRAMES_5MS; map_idx++ ) { hSpatParamRendCom->render_to_md_map[map_idx] = map_idx; } @@ -573,12 +573,12 @@ ivas_error ivas_spat_hSpatParamRendCom_config( { int16_t num_slots_in_subfr; num_slots_in_subfr = dec_param_estim_flag ? CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES : 1; - hSpatParamRendCom->dirac_md_buffer_length = (MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_DIRAC_PARAM_DEC_SFR); + hSpatParamRendCom->dirac_md_buffer_length = ( MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_DIRAC_PARAM_DEC_SFR ); hSpatParamRendCom->dirac_bs_md_write_idx = DELAY_DIRAC_PARAM_DEC_SFR; hSpatParamRendCom->dirac_read_idx = 0; - set_s(hSpatParamRendCom->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME); - for (map_idx = 0; map_idx < DEFAULT_JBM_SUBFRAMES_5MS * num_slots_in_subfr; map_idx++) + set_s( hSpatParamRendCom->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME ); + for ( map_idx = 0; map_idx < DEFAULT_JBM_SUBFRAMES_5MS * num_slots_in_subfr; map_idx++ ) { hSpatParamRendCom->render_to_md_map[map_idx] = hSpatParamRendCom->dirac_read_idx + map_idx / num_slots_in_subfr; } @@ -631,17 +631,17 @@ void ivas_spat_hSpatParamRendCom_close( } #else void ivas_spat_hSpatParamRendCom_close_fx( - SPAT_PARAM_REND_COMMON_DATA_HANDLE *hSpatParamRendCom_out) + SPAT_PARAM_REND_COMMON_DATA_HANDLE *hSpatParamRendCom_out ) { test(); - IF (hSpatParamRendCom_out == NULL || *hSpatParamRendCom_out == NULL) + IF( hSpatParamRendCom_out == NULL || *hSpatParamRendCom_out == NULL ) { return; } - ivas_dirac_deallocate_parameters_fx(*hSpatParamRendCom_out, 1); - ivas_dirac_deallocate_parameters_fx(*hSpatParamRendCom_out, 2); + ivas_dirac_deallocate_parameters_fx( *hSpatParamRendCom_out, 1 ); + ivas_dirac_deallocate_parameters_fx( *hSpatParamRendCom_out, 2 ); - free(*hSpatParamRendCom_out); + free( *hSpatParamRendCom_out ); *hSpatParamRendCom_out = NULL; return; @@ -656,12 +656,12 @@ void ivas_spat_hSpatParamRendCom_close_fx( #ifdef IVAS_FLOAT_FIXED void ivas_dirac_rend_close_fx( - DIRAC_REND_HANDLE *hDirACRend_out) + DIRAC_REND_HANDLE *hDirACRend_out ) { Word16 i, j; DIRAC_REND_HANDLE hDirACRend; - IF (hDirACRend_out == NULL || *hDirACRend_out == NULL) + IF( hDirACRend_out == NULL || *hDirACRend_out == NULL ) { return; } @@ -670,55 +670,55 @@ void ivas_dirac_rend_close_fx( /* close Output synthesis sub-module */ #ifdef IVAS_FLOAT_FIXED - ivas_dirac_dec_output_synthesis_close_fx(hDirACRend); + ivas_dirac_dec_output_synthesis_close_fx( hDirACRend ); #else - ivas_dirac_dec_output_synthesis_close(hDirACRend); + ivas_dirac_dec_output_synthesis_close( hDirACRend ); #endif /* close Decorrelator sub-module */ - IF (hDirACRend->proto_signal_decorr_on) + IF( hDirACRend->proto_signal_decorr_on ) { - ivas_dirac_dec_decorr_close_fx(&hDirACRend->h_freq_domain_decorr_ap_params, &hDirACRend->h_freq_domain_decorr_ap_state); + ivas_dirac_dec_decorr_close_fx( &hDirACRend->h_freq_domain_decorr_ap_params, &hDirACRend->h_freq_domain_decorr_ap_state ); } /* Params */ #ifdef IVAS_FLOAT_FIXED /* free frequency axis buffer */ - IF(hDirACRend->frequency_axis_fx != NULL) + IF( hDirACRend->frequency_axis_fx != NULL ) { - free(hDirACRend->frequency_axis_fx); + free( hDirACRend->frequency_axis_fx ); hDirACRend->frequency_axis_fx = NULL; } - IF(hDirACRend->diffuse_response_function_fx != NULL) + IF( hDirACRend->diffuse_response_function_fx != NULL ) { - free(hDirACRend->diffuse_response_function_fx); + free( hDirACRend->diffuse_response_function_fx ); hDirACRend->diffuse_response_function_fx = NULL; } - IF(hDirACRend->hoa_encoder_fx != NULL) + IF( hDirACRend->hoa_encoder_fx != NULL ) { - free(hDirACRend->hoa_encoder_fx); + free( hDirACRend->hoa_encoder_fx ); hDirACRend->hoa_encoder_fx = NULL; } #endif #ifdef IVAS_FLOAT_FIXED - IF (hDirACRend->hoa_encoder_fx != NULL) + IF( hDirACRend->hoa_encoder_fx != NULL ) { - free(hDirACRend->hoa_encoder_fx); + free( hDirACRend->hoa_encoder_fx ); hDirACRend->hoa_encoder_fx = NULL; } #endif /* prototype indexing */ - IF (hDirACRend->proto_index_dir != NULL) + IF( hDirACRend->proto_index_dir != NULL ) { - free(hDirACRend->proto_index_dir); + free( hDirACRend->proto_index_dir ); hDirACRend->proto_index_dir = NULL; } - IF (hDirACRend->proto_index_diff != NULL) + IF( hDirACRend->proto_index_diff != NULL ) { - free(hDirACRend->proto_index_diff); + free( hDirACRend->proto_index_diff ); hDirACRend->proto_index_dir = NULL; } @@ -726,44 +726,44 @@ void ivas_dirac_rend_close_fx( /* free prototype signal buffers */ #if 1 /* TODO: remove float code */ - IF (hDirACRend->proto_frame_f != NULL) + IF( hDirACRend->proto_frame_f != NULL ) { - free(hDirACRend->proto_frame_f); + free( hDirACRend->proto_frame_f ); hDirACRend->proto_frame_f = NULL; } #endif - IF (hDirACRend->proto_frame_f_fx != NULL) + IF( hDirACRend->proto_frame_f_fx != NULL ) { - free(hDirACRend->proto_frame_f_fx); + free( hDirACRend->proto_frame_f_fx ); hDirACRend->proto_frame_f_fx = NULL; } - FOR (i = 0; i < DIRAC_NUM_DIMS; i++) + FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) { - FOR (j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++) + FOR( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) { - IF (hDirACRend->buffer_intensity_real_fx[i][j] != NULL) + IF( hDirACRend->buffer_intensity_real_fx[i][j] != NULL ) { - free(hDirACRend->buffer_intensity_real_fx[i][j]); + free( hDirACRend->buffer_intensity_real_fx[i][j] ); hDirACRend->buffer_intensity_real_fx[i][j] = NULL; } } } - IF (hDirACRend->buffer_energy_fx != NULL) + IF( hDirACRend->buffer_energy_fx != NULL ) { - free(hDirACRend->buffer_energy_fx); + free( hDirACRend->buffer_energy_fx ); hDirACRend->buffer_energy_fx = NULL; } - IF (hDirACRend->masa_stereo_type_detect != NULL) + IF( hDirACRend->masa_stereo_type_detect != NULL ) { - free(hDirACRend->masa_stereo_type_detect); + free( hDirACRend->masa_stereo_type_detect ); hDirACRend->masa_stereo_type_detect = NULL; } - ivas_dirac_free_mem_fx(&(hDirACRend->stack_mem)); + ivas_dirac_free_mem_fx( &( hDirACRend->stack_mem ) ); - free(*hDirACRend_out); + free( *hDirACRend_out ); *hDirACRend_out = NULL; return; @@ -876,163 +876,163 @@ void ivas_dirac_rend_close( #ifdef IVAS_FLOAT_FIXED void ivas_dirac_deallocate_parameters_fx( SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common data for spatial parametric rendering */ - const Word16 params_flag /* i : set of parameters flag */ + const Word16 params_flag /* i : set of parameters flag */ ) { Word16 i; Word16 md_buffer_length; - if (hSpatParamRendCom == NULL) + if ( hSpatParamRendCom == NULL ) { return; } md_buffer_length = hSpatParamRendCom->dirac_md_buffer_length; - if (params_flag == 1) + if ( params_flag == 1 ) { - if (hSpatParamRendCom->azimuth != NULL) + if ( hSpatParamRendCom->azimuth != NULL ) { - for (i = 0; i < md_buffer_length; i++) + for ( i = 0; i < md_buffer_length; i++ ) { - if (hSpatParamRendCom->azimuth[i] != NULL) + if ( hSpatParamRendCom->azimuth[i] != NULL ) { - free(hSpatParamRendCom->azimuth[i]); + free( hSpatParamRendCom->azimuth[i] ); hSpatParamRendCom->azimuth[i] = NULL; } } - free(hSpatParamRendCom->azimuth); + free( hSpatParamRendCom->azimuth ); hSpatParamRendCom->azimuth = NULL; } - if (hSpatParamRendCom->elevation != NULL) + if ( hSpatParamRendCom->elevation != NULL ) { - for (i = 0; i < md_buffer_length; i++) + for ( i = 0; i < md_buffer_length; i++ ) { - if (hSpatParamRendCom->elevation[i] != NULL) + if ( hSpatParamRendCom->elevation[i] != NULL ) { - free(hSpatParamRendCom->elevation[i]); + free( hSpatParamRendCom->elevation[i] ); hSpatParamRendCom->elevation[i] = NULL; } } - free(hSpatParamRendCom->elevation); + free( hSpatParamRendCom->elevation ); hSpatParamRendCom->elevation = NULL; } - if (hSpatParamRendCom->energy_ratio1_fx != NULL) + if ( hSpatParamRendCom->energy_ratio1_fx != NULL ) { - for (i = 0; i < md_buffer_length; i++) + for ( i = 0; i < md_buffer_length; i++ ) { - if (hSpatParamRendCom->energy_ratio1_fx[i] != NULL) + if ( hSpatParamRendCom->energy_ratio1_fx[i] != NULL ) { - free(hSpatParamRendCom->energy_ratio1_fx[i]); + free( hSpatParamRendCom->energy_ratio1_fx[i] ); hSpatParamRendCom->energy_ratio1_fx[i] = NULL; } } - free(hSpatParamRendCom->energy_ratio1_fx); + free( hSpatParamRendCom->energy_ratio1_fx ); hSpatParamRendCom->energy_ratio1_fx = NULL; } - if (hSpatParamRendCom->diffuseness_vector_fx != NULL) + if ( hSpatParamRendCom->diffuseness_vector_fx != NULL ) { - for (i = 0; i < md_buffer_length; i++) + for ( i = 0; i < md_buffer_length; i++ ) { - if (hSpatParamRendCom->diffuseness_vector_fx[i] != NULL) + if ( hSpatParamRendCom->diffuseness_vector_fx[i] != NULL ) { - free(hSpatParamRendCom->diffuseness_vector_fx[i]); + free( hSpatParamRendCom->diffuseness_vector_fx[i] ); hSpatParamRendCom->diffuseness_vector_fx[i] = NULL; } } - free(hSpatParamRendCom->diffuseness_vector_fx); + free( hSpatParamRendCom->diffuseness_vector_fx ); hSpatParamRendCom->diffuseness_vector_fx = NULL; } - if (hSpatParamRendCom->spreadCoherence_fx != NULL) + if ( hSpatParamRendCom->spreadCoherence_fx != NULL ) { - for (i = 0; i < md_buffer_length; i++) + for ( i = 0; i < md_buffer_length; i++ ) { - if (hSpatParamRendCom->spreadCoherence_fx[i] != NULL) + if ( hSpatParamRendCom->spreadCoherence_fx[i] != NULL ) { - free(hSpatParamRendCom->spreadCoherence_fx[i]); + free( hSpatParamRendCom->spreadCoherence_fx[i] ); hSpatParamRendCom->spreadCoherence_fx[i] = NULL; } } - free(hSpatParamRendCom->spreadCoherence_fx); + free( hSpatParamRendCom->spreadCoherence_fx ); hSpatParamRendCom->spreadCoherence_fx = NULL; } - if (hSpatParamRendCom->surroundingCoherence_fx != NULL) + if ( hSpatParamRendCom->surroundingCoherence_fx != NULL ) { - for (i = 0; i < md_buffer_length; i++) + for ( i = 0; i < md_buffer_length; i++ ) { - if (hSpatParamRendCom->surroundingCoherence_fx[i] != NULL) + if ( hSpatParamRendCom->surroundingCoherence_fx[i] != NULL ) { - free(hSpatParamRendCom->surroundingCoherence_fx[i]); + free( hSpatParamRendCom->surroundingCoherence_fx[i] ); hSpatParamRendCom->surroundingCoherence_fx[i] = NULL; } } - free(hSpatParamRendCom->surroundingCoherence_fx); + free( hSpatParamRendCom->surroundingCoherence_fx ); hSpatParamRendCom->surroundingCoherence_fx = NULL; } } - else if (params_flag == 2) + else if ( params_flag == 2 ) { - if (hSpatParamRendCom->azimuth2 != NULL) + if ( hSpatParamRendCom->azimuth2 != NULL ) { - for (i = 0; i < md_buffer_length; i++) + for ( i = 0; i < md_buffer_length; i++ ) { - if (hSpatParamRendCom->azimuth2[i] != NULL) + if ( hSpatParamRendCom->azimuth2[i] != NULL ) { - free(hSpatParamRendCom->azimuth2[i]); + free( hSpatParamRendCom->azimuth2[i] ); hSpatParamRendCom->azimuth2[i] = NULL; } } - free(hSpatParamRendCom->azimuth2); + free( hSpatParamRendCom->azimuth2 ); hSpatParamRendCom->azimuth2 = NULL; } - if (hSpatParamRendCom->elevation2 != NULL) + if ( hSpatParamRendCom->elevation2 != NULL ) { - for (i = 0; i < md_buffer_length; i++) + for ( i = 0; i < md_buffer_length; i++ ) { - if (hSpatParamRendCom->elevation2[i] != NULL) + if ( hSpatParamRendCom->elevation2[i] != NULL ) { - free(hSpatParamRendCom->elevation2[i]); + free( hSpatParamRendCom->elevation2[i] ); hSpatParamRendCom->elevation2[i] = NULL; } } - free(hSpatParamRendCom->elevation2); + free( hSpatParamRendCom->elevation2 ); hSpatParamRendCom->elevation2 = NULL; } - if (hSpatParamRendCom->energy_ratio2_fx != NULL) + if ( hSpatParamRendCom->energy_ratio2_fx != NULL ) { - for (i = 0; i < md_buffer_length; i++) + for ( i = 0; i < md_buffer_length; i++ ) { - if (hSpatParamRendCom->energy_ratio2_fx[i] != NULL) + if ( hSpatParamRendCom->energy_ratio2_fx[i] != NULL ) { - free(hSpatParamRendCom->energy_ratio2_fx[i]); + free( hSpatParamRendCom->energy_ratio2_fx[i] ); hSpatParamRendCom->energy_ratio2_fx[i] = NULL; } } - free(hSpatParamRendCom->energy_ratio2_fx); + free( hSpatParamRendCom->energy_ratio2_fx ); hSpatParamRendCom->energy_ratio2_fx = NULL; } - if (hSpatParamRendCom->spreadCoherence2_fx != NULL) + if ( hSpatParamRendCom->spreadCoherence2_fx != NULL ) { - for (i = 0; i < md_buffer_length; i++) + for ( i = 0; i < md_buffer_length; i++ ) { - if (hSpatParamRendCom->spreadCoherence2_fx[i] != NULL) + if ( hSpatParamRendCom->spreadCoherence2_fx[i] != NULL ) { - free(hSpatParamRendCom->spreadCoherence2_fx[i]); + free( hSpatParamRendCom->spreadCoherence2_fx[i] ); hSpatParamRendCom->spreadCoherence2_fx[i] = NULL; } } - free(hSpatParamRendCom->spreadCoherence2_fx); + free( hSpatParamRendCom->spreadCoherence2_fx ); hSpatParamRendCom->spreadCoherence2_fx = NULL; } } @@ -1314,11 +1314,11 @@ ivas_error ivas_dirac_alloc_mem( set_zero( hDirAC_mem->direct_responses_square, size ); #ifdef IVAS_FLOAT_FIXED - if ((hDirAC_mem->direct_responses_square_fx = (Word32 *)malloc(sizeof(Word32) * size)) == NULL) + if ( ( hDirAC_mem->direct_responses_square_fx = (Word32 *) malloc( sizeof( Word32 ) * size ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); } - set32_fx(hDirAC_mem->direct_responses_square_fx, 0, size); + set32_fx( hDirAC_mem->direct_responses_square_fx, 0, size ); #endif if ( hDirACRend->proto_signal_decorr_on && ( renderer_type != RENDERER_BINAURAL_PARAMETRIC && renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && renderer_type != RENDERER_STEREO_PARAMETRIC ) ) { @@ -1439,11 +1439,11 @@ ivas_error ivas_dirac_alloc_mem( #ifdef IVAS_FLOAT_FIXED /*Responses (gains/factors)*/ - if ((hDirAC_mem->direct_responses_fx = (Word32 *)malloc(sizeof(Word32) * size_ho)) == NULL) + if ( ( hDirAC_mem->direct_responses_fx = (Word32 *) malloc( sizeof( Word32 ) * size_ho ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); } - set32_fx(hDirAC_mem->direct_responses_fx, 0, size); + set32_fx( hDirAC_mem->direct_responses_fx, 0, size ); hDirACRend->h_output_synthesis_psd_state.direct_responses_fx = hDirAC_mem->direct_responses_fx; @@ -1503,7 +1503,7 @@ ivas_error ivas_dirac_alloc_mem( #endif } #ifdef MSAN_FIX - set_zero_fx(hDirAC_mem->proto_diffuse_buffer_f_fx, hDirAC_mem->proto_diffuse_buffer_f_len); + set_zero_fx( hDirAC_mem->proto_diffuse_buffer_f_fx, hDirAC_mem->proto_diffuse_buffer_f_len ); #endif } } @@ -1535,13 +1535,13 @@ ivas_error ivas_dirac_alloc_mem( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); } #ifdef IVAS_FLOAT_FIXED - IF((hDirAC_mem->direct_power_factor_fx = (Word32 *)malloc(sizeof(Word32) * size_pf)) == NULL) + IF( ( hDirAC_mem->direct_power_factor_fx = (Word32 *) malloc( sizeof( Word32 ) * size_pf ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); } - IF((hDirAC_mem->diffuse_power_factor_fx = (Word32 *)malloc(sizeof(Word32) * size_pf)) == NULL) + IF( ( hDirAC_mem->diffuse_power_factor_fx = (Word32 *) malloc( sizeof( Word32 ) * size_pf ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); } #endif } @@ -1582,7 +1582,7 @@ ivas_error ivas_dirac_alloc_mem( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); } - + hDirAC_mem->reference_power_len = 2 * num_freq_bands; hDirAC_mem->reference_power_q = Q31; hDirAC_mem->reference_power_smooth_q = Q31; @@ -1602,7 +1602,7 @@ ivas_error ivas_dirac_alloc_mem( } #ifdef MSAN_FIX #ifndef IVAS_FLOAT_FIXED - set_zero( hDirAC_mem->onset_filter, num_outputs_diff * num_freq_bands); + set_zero( hDirAC_mem->onset_filter, num_outputs_diff * num_freq_bands ); #endif set_zero_fx( hDirAC_mem->onset_filter_fx, num_outputs_diff * num_freq_bands ); #endif @@ -1663,123 +1663,123 @@ ivas_error ivas_dirac_alloc_mem( #ifdef IVAS_FLOAT_FIXED void ivas_dirac_free_mem_fx( - DIRAC_DEC_STACK_MEM_HANDLE hDirAC_mem) + DIRAC_DEC_STACK_MEM_HANDLE hDirAC_mem ) { - IF (hDirAC_mem->cy_auto_dir_smooth != NULL) + IF( hDirAC_mem->cy_auto_dir_smooth != NULL ) { - free(hDirAC_mem->cy_auto_dir_smooth); + free( hDirAC_mem->cy_auto_dir_smooth ); } IF( hDirAC_mem->cy_auto_dir_smooth_fx != NULL ) { free( hDirAC_mem->cy_auto_dir_smooth_fx ); } - IF (hDirAC_mem->proto_power_smooth != NULL) + IF( hDirAC_mem->proto_power_smooth != NULL ) { - free(hDirAC_mem->proto_power_smooth); + free( hDirAC_mem->proto_power_smooth ); } IF( hDirAC_mem->proto_power_smooth_fx != NULL ) { free( hDirAC_mem->proto_power_smooth_fx ); } #if 1 /* todo: remove float */ - IF (hDirAC_mem->proto_power_diff_smooth != NULL) + IF( hDirAC_mem->proto_power_diff_smooth != NULL ) { - free(hDirAC_mem->proto_power_diff_smooth); + free( hDirAC_mem->proto_power_diff_smooth ); } #endif - IF (hDirAC_mem->proto_power_diff_smooth_fx != NULL) + IF( hDirAC_mem->proto_power_diff_smooth_fx != NULL ) { - free(hDirAC_mem->proto_power_diff_smooth_fx); + free( hDirAC_mem->proto_power_diff_smooth_fx ); } - IF (hDirAC_mem->direct_responses_square != NULL) + IF( hDirAC_mem->direct_responses_square != NULL ) { - free(hDirAC_mem->direct_responses_square); + free( hDirAC_mem->direct_responses_square ); } - IF(hDirAC_mem->direct_responses_square_fx != NULL) + IF( hDirAC_mem->direct_responses_square_fx != NULL ) { - free(hDirAC_mem->direct_responses_square_fx); + free( hDirAC_mem->direct_responses_square_fx ); } - IF (hDirAC_mem->frame_dec_f_fx != NULL) + IF( hDirAC_mem->frame_dec_f_fx != NULL ) { - free(hDirAC_mem->frame_dec_f_fx); + free( hDirAC_mem->frame_dec_f_fx ); } #if 1 /* TODO: remove float free */ - IF (hDirAC_mem->frame_dec_f != NULL) + IF( hDirAC_mem->frame_dec_f != NULL ) { - free(hDirAC_mem->frame_dec_f); + free( hDirAC_mem->frame_dec_f ); } #endif - IF (hDirAC_mem->cy_cross_dir_smooth != NULL) + IF( hDirAC_mem->cy_cross_dir_smooth != NULL ) { - free(hDirAC_mem->cy_cross_dir_smooth); + free( hDirAC_mem->cy_cross_dir_smooth ); } IF( hDirAC_mem->cy_cross_dir_smooth_fx != NULL ) { free( hDirAC_mem->cy_cross_dir_smooth_fx ); } - IF (hDirAC_mem->cy_auto_diff_smooth != NULL) + IF( hDirAC_mem->cy_auto_diff_smooth != NULL ) { - free(hDirAC_mem->cy_auto_diff_smooth); + free( hDirAC_mem->cy_auto_diff_smooth ); } IF( hDirAC_mem->cy_auto_diff_smooth_fx != NULL ) { free( hDirAC_mem->cy_auto_diff_smooth_fx ); } #ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED - IF (hDirAC_mem->direct_responses != NULL) + IF( hDirAC_mem->direct_responses != NULL ) { - free(hDirAC_mem->direct_responses); + free( hDirAC_mem->direct_responses ); } #endif - if (hDirAC_mem->direct_responses_fx != NULL) + if ( hDirAC_mem->direct_responses_fx != NULL ) { - free(hDirAC_mem->direct_responses_fx); + free( hDirAC_mem->direct_responses_fx ); } - IF (hDirAC_mem->proto_direct_buffer_f != NULL) + IF( hDirAC_mem->proto_direct_buffer_f != NULL ) { - free(hDirAC_mem->proto_direct_buffer_f); + free( hDirAC_mem->proto_direct_buffer_f ); } IF( hDirAC_mem->proto_direct_buffer_f_fx != NULL ) { free( hDirAC_mem->proto_direct_buffer_f_fx ); } #if 1 /* TODO: remove float free */ - IF (hDirAC_mem->proto_diffuse_buffer_f != NULL) + IF( hDirAC_mem->proto_diffuse_buffer_f != NULL ) { - free(hDirAC_mem->proto_diffuse_buffer_f); + free( hDirAC_mem->proto_diffuse_buffer_f ); } #endif IF( hDirAC_mem->proto_diffuse_buffer_f_fx != NULL ) { free( hDirAC_mem->proto_diffuse_buffer_f_fx ); } - IF (hDirAC_mem->direct_power_factor != NULL) + IF( hDirAC_mem->direct_power_factor != NULL ) { - free(hDirAC_mem->direct_power_factor); + free( hDirAC_mem->direct_power_factor ); } - IF (hDirAC_mem->diffuse_power_factor != NULL) + IF( hDirAC_mem->diffuse_power_factor != NULL ) { - free(hDirAC_mem->diffuse_power_factor); + free( hDirAC_mem->diffuse_power_factor ); } - IF(hDirAC_mem->direct_power_factor_fx != NULL) + IF( hDirAC_mem->direct_power_factor_fx != NULL ) { - free(hDirAC_mem->direct_power_factor_fx); + free( hDirAC_mem->direct_power_factor_fx ); } - IF(hDirAC_mem->diffuse_power_factor_fx != NULL) + IF( hDirAC_mem->diffuse_power_factor_fx != NULL ) { - free(hDirAC_mem->diffuse_power_factor_fx); + free( hDirAC_mem->diffuse_power_factor_fx ); } - IF (hDirAC_mem->reference_power != NULL) + IF( hDirAC_mem->reference_power != NULL ) { - free(hDirAC_mem->reference_power); + free( hDirAC_mem->reference_power ); } - IF (hDirAC_mem->reference_power_fx != NULL) + IF( hDirAC_mem->reference_power_fx != NULL ) { - free(hDirAC_mem->reference_power_fx); + free( hDirAC_mem->reference_power_fx ); } - IF (hDirAC_mem->onset_filter_fx != NULL) + IF( hDirAC_mem->onset_filter_fx != NULL ) { - free(hDirAC_mem->onset_filter_fx); + free( hDirAC_mem->onset_filter_fx ); } return; @@ -1865,8 +1865,8 @@ void compute_hoa_encoder_mtx_fx( const int16_t ambisonics_order ) { Word16 k, num_sh; - - num_sh = (Word16)ivas_sba_get_nchan_fx( ambisonics_order, 0 ); + + num_sh = (Word16) ivas_sba_get_nchan_fx( ambisonics_order, 0 ); FOR( k = 0; k < num_responses; k++ ) { ivas_dirac_dec_get_response_fixed( shr( extract_h( azimuth[k] ), Q22 - Q16 ), shr( extract_h( elevation[k] ), Q22 - Q16 ), &response_fx[k * num_sh], ambisonics_order ); // Q29 @@ -1881,15 +1881,15 @@ void compute_hoa_encoder_mtx( const float *elevation, float *response, const int16_t num_responses, - const int16_t ambisonics_order) + const int16_t ambisonics_order ) { int16_t k, num_sh; - - num_sh = ivas_sba_get_nchan(ambisonics_order, 0); - for (k = 0; k < num_responses; k++) + num_sh = ivas_sba_get_nchan( ambisonics_order, 0 ); + + for ( k = 0; k < num_responses; k++ ) { - ivas_dirac_dec_get_response((const int16_t)azimuth[k], (const int16_t)elevation[k], &response[k * num_sh], ambisonics_order); + ivas_dirac_dec_get_response( (const int16_t) azimuth[k], (const int16_t) elevation[k], &response[k * num_sh], ambisonics_order ); } return; @@ -1953,55 +1953,55 @@ void initDiffuseResponses( const int16_t ambisonics_order, const IVAS_FORMAT ivas_format, int16_t *num_ele_spk_no_diffuse_rendering, - const AUDIO_CONFIG transport_config) + const AUDIO_CONFIG transport_config ) { int16_t i, l, k, idx, num_horizontal_speakers; *num_ele_spk_no_diffuse_rendering = 0; - if (output_config == IVAS_AUDIO_CONFIG_MONO) + if ( output_config == IVAS_AUDIO_CONFIG_MONO ) { diffuse_response_function[0] = 1.0f; - diffuse_response_function[1] = inv_sqrt(3.0f); + diffuse_response_function[1] = inv_sqrt( 3.0f ); } - else if (!(output_config == IVAS_AUDIO_CONFIG_FOA || output_config == IVAS_AUDIO_CONFIG_HOA2 || output_config == IVAS_AUDIO_CONFIG_HOA3)) + else if ( !( output_config == IVAS_AUDIO_CONFIG_FOA || output_config == IVAS_AUDIO_CONFIG_HOA2 || output_config == IVAS_AUDIO_CONFIG_HOA3 ) ) { /* set diffuse response function */ - if (ivas_format == MC_FORMAT && (transport_config == IVAS_AUDIO_CONFIG_5_1 || transport_config == IVAS_AUDIO_CONFIG_7_1) && output_config == IVAS_AUDIO_CONFIG_5_1_4) + if ( ivas_format == MC_FORMAT && ( transport_config == IVAS_AUDIO_CONFIG_5_1 || transport_config == IVAS_AUDIO_CONFIG_7_1 ) && output_config == IVAS_AUDIO_CONFIG_5_1_4 ) { num_horizontal_speakers = num_channels - NUM_ELEVATED_SPEAKERS; - mvr2r(diffuse_response_CICP6, diffuse_response_function, num_horizontal_speakers); - set_zero(&diffuse_response_function[num_horizontal_speakers], NUM_ELEVATED_SPEAKERS); + mvr2r( diffuse_response_CICP6, diffuse_response_function, num_horizontal_speakers ); + set_zero( &diffuse_response_function[num_horizontal_speakers], NUM_ELEVATED_SPEAKERS ); *num_ele_spk_no_diffuse_rendering = NUM_ELEVATED_SPEAKERS; } - else if (ivas_format == MC_FORMAT && (transport_config == IVAS_AUDIO_CONFIG_5_1 || transport_config == IVAS_AUDIO_CONFIG_7_1) && output_config == IVAS_AUDIO_CONFIG_7_1_4) + else if ( ivas_format == MC_FORMAT && ( transport_config == IVAS_AUDIO_CONFIG_5_1 || transport_config == IVAS_AUDIO_CONFIG_7_1 ) && output_config == IVAS_AUDIO_CONFIG_7_1_4 ) { num_horizontal_speakers = num_channels - NUM_ELEVATED_SPEAKERS; - set_f(diffuse_response_function, sqrtf(1.f / ((float)num_horizontal_speakers)), num_horizontal_speakers); - set_zero(&diffuse_response_function[num_horizontal_speakers], NUM_ELEVATED_SPEAKERS); + set_f( diffuse_response_function, sqrtf( 1.f / ( (float) num_horizontal_speakers ) ), num_horizontal_speakers ); + set_zero( &diffuse_response_function[num_horizontal_speakers], NUM_ELEVATED_SPEAKERS ); *num_ele_spk_no_diffuse_rendering = NUM_ELEVATED_SPEAKERS; } - else if ((ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT || ivas_format == MC_FORMAT) && output_config == IVAS_AUDIO_CONFIG_5_1 && num_channels == 5) + else if ( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT || ivas_format == MC_FORMAT ) && output_config == IVAS_AUDIO_CONFIG_5_1 && num_channels == 5 ) { - mvr2r(diffuse_response_CICP6, diffuse_response_function, num_channels); + mvr2r( diffuse_response_CICP6, diffuse_response_function, num_channels ); } - else if ((ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT || ivas_format == MC_FORMAT) && output_config == IVAS_AUDIO_CONFIG_5_1_2 && num_channels == 7) + else if ( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT || ivas_format == MC_FORMAT ) && output_config == IVAS_AUDIO_CONFIG_5_1_2 && num_channels == 7 ) { - mvr2r(diffuse_response_CICP14, diffuse_response_function, num_channels); + mvr2r( diffuse_response_CICP14, diffuse_response_function, num_channels ); } - else if ((ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT || ivas_format == MC_FORMAT) && (output_config == IVAS_AUDIO_CONFIG_5_1_4) && (num_channels == 9)) + else if ( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT || ivas_format == MC_FORMAT ) && ( output_config == IVAS_AUDIO_CONFIG_5_1_4 ) && ( num_channels == 9 ) ) { - mvr2r(diffuse_response_CICP16, diffuse_response_function, num_channels); + mvr2r( diffuse_response_CICP16, diffuse_response_function, num_channels ); } - else if ((ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT || ivas_format == MC_FORMAT) && (output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM)) + else if ( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT || ivas_format == MC_FORMAT ) && ( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) { - if (transport_config == IVAS_AUDIO_CONFIG_5_1 || transport_config == IVAS_AUDIO_CONFIG_7_1) + if ( transport_config == IVAS_AUDIO_CONFIG_5_1 || transport_config == IVAS_AUDIO_CONFIG_7_1 ) { /* Detect loudspeakers with elevation */ - for (i = 0, num_horizontal_speakers = 0; i < num_channels; i++) + for ( i = 0, num_horizontal_speakers = 0; i < num_channels; i++ ) { - if (fabsf(hOutSetup.ls_elevation[i]) <= 5.f) + if ( fabsf( hOutSetup.ls_elevation[i] ) <= 5.f ) { num_horizontal_speakers++; diffuse_response_function[i] = 1.f; @@ -2013,37 +2013,37 @@ void initDiffuseResponses( } } /* Diffuse only to horizontal plane if enough loudspeakers */ - if (num_horizontal_speakers > 2) + if ( num_horizontal_speakers > 2 ) { - for (i = 0; i < num_channels; i++) + for ( i = 0; i < num_channels; i++ ) { - diffuse_response_function[i] *= sqrtf(1.f / (float)num_horizontal_speakers); + diffuse_response_function[i] *= sqrtf( 1.f / (float) num_horizontal_speakers ); } } else { *num_ele_spk_no_diffuse_rendering = 0; - set_f(diffuse_response_function, sqrtf(1.f / (float)num_channels), num_channels); + set_f( diffuse_response_function, sqrtf( 1.f / (float) num_channels ), num_channels ); } } else { - set_f(diffuse_response_function, sqrtf(1.f / (float)num_channels), num_channels); + set_f( diffuse_response_function, sqrtf( 1.f / (float) num_channels ), num_channels ); } } else { - set_f(diffuse_response_function, sqrtf(1.f / (float)num_channels), num_channels); + set_f( diffuse_response_function, sqrtf( 1.f / (float) num_channels ), num_channels ); } } else { idx = 0; - for (l = 0; l <= ambisonics_order; l++) + for ( l = 0; l <= ambisonics_order; l++ ) { - for (k = 0; k < (2 * l + 1); k++) + for ( k = 0; k < ( 2 * l + 1 ); k++ ) { - diffuse_response_function[idx++] = inv_sqrt(2.0f * l + 1.0f); + diffuse_response_function[idx++] = inv_sqrt( 2.0f * l + 1.0f ); } } } @@ -2804,7 +2804,7 @@ void protoSignalComputation2_fx( min_q_shift = s_min( min_q_shift, q_shift ); #ifdef MSAN_FIX - q_shift = s_min( L_norm_arr( RealBuffer_fx[l][0], s_min(num_freq_bands, MASA_SUM_FREQ_RANGE_BINS)), L_norm_arr( ImagBuffer_fx[l][0], s_min(num_freq_bands, MASA_SUM_FREQ_RANGE_BINS)) ); + q_shift = s_min( L_norm_arr( RealBuffer_fx[l][0], s_min( num_freq_bands, MASA_SUM_FREQ_RANGE_BINS ) ), L_norm_arr( ImagBuffer_fx[l][0], s_min( num_freq_bands, MASA_SUM_FREQ_RANGE_BINS ) ) ); #else q_shift = s_min( L_norm_arr( RealBuffer_fx[l][0], MASA_SUM_FREQ_RANGE_BINS ), L_norm_arr( ImagBuffer_fx[l][0], MASA_SUM_FREQ_RANGE_BINS ) ); #endif // MSAN_FIX @@ -2936,9 +2936,9 @@ void protoSignalComputation2_fx( a_fx = 21474836; /*0.01 in Q31*/ /* Temporal smoothing coefficient */ move32(); b_fx = L_sub( ONE_IN_Q31, a_fx ); /* Temporal smoothing coefficient */ - //a2_fx = 214748365; /*0.1 in Q31*/ /* Temporal smoothing coefficient */ + // a2_fx = 214748365; /*0.1 in Q31*/ /* Temporal smoothing coefficient */ move32(); - //b2_fx = L_sub( ONE_IN_Q31, a2_fx ); /* Temporal smoothing coefficient */ + // b2_fx = L_sub( ONE_IN_Q31, a2_fx ); /* Temporal smoothing coefficient */ IF( GT_16( stereo_type_detect->interpolator, 0 ) ) { @@ -4172,10 +4172,10 @@ void ivas_dirac_dec_compute_diffuse_proto_fx( Scale_sig32( h_dirac_output_synthesis_state->proto_diffuse_buffer_f_fx, diffuse_start, sub( old_diff_e, new_diff_e ) ); #ifdef MSAN_FIX Scale_sig32( h_dirac_output_synthesis_state->proto_diffuse_buffer_f_fx + diffuse_start, - sub(2*num_freq_bands_diff*hDirACRend->hOutSetup.nchan_out_woLFE, diffuse_start ), sub( diff_e, new_diff_e ) ); + sub( 2 * num_freq_bands_diff * hDirACRend->hOutSetup.nchan_out_woLFE, diffuse_start ), sub( diff_e, new_diff_e ) ); #else Scale_sig32( h_dirac_output_synthesis_state->proto_diffuse_buffer_f_fx + diffuse_start, - sub( h_dirac_output_synthesis_state->proto_diffuse_buffer_f_len, diffuse_start ), sub( diff_e, new_diff_e ) ); + sub( h_dirac_output_synthesis_state->proto_diffuse_buffer_f_len, diffuse_start ), sub( diff_e, new_diff_e ) ); #endif h_dirac_output_synthesis_state->proto_diffuse_buffer_f_q = sub( 31, new_diff_e ); @@ -4352,7 +4352,7 @@ void computeDirectionAngles_fx( azimuth[k] = add( s_max( -23040, s_min( 23040, mult( res, _180_OVER_PI_Q9 ) ) ), 64 ) / ONE_IN_Q7; // Q0; move16(); - res = BASOP_util_atan2( z, radius, sub( sub( 31, q_z ), exp ) ); // Q13 + res = BASOP_util_atan2( z, radius, sub( sub( 31, q_z ), exp ) ); // Q13 elevation[k] = add( s_max( -11520, s_min( 23040, mult( res, _180_OVER_PI_Q9 ) ) ), 64 ) / ONE_IN_Q7; // Q0; move16(); } @@ -4418,7 +4418,7 @@ void computeDirectionAngles( #ifdef IVAS_FLOAT_FIXED void ivas_masa_init_stereotype_detection_fx( - MASA_STEREO_TYPE_DETECT *stereo_type_detect) + MASA_STEREO_TYPE_DETECT *stereo_type_detect ) { stereo_type_detect->masa_stereo_type = MASA_STEREO_DOWNMIX; stereo_type_detect->current_stereo_type = MASA_STEREO_DOWNMIX; @@ -4444,8 +4444,8 @@ void ivas_masa_init_stereotype_detection_fx( stereo_type_detect->total_hi_power_fx = 0; stereo_type_detect->q_total_hi_power = Q31; - set32_fx(stereo_type_detect->sum_power_fx, 0,MASA_SUM_FREQ_RANGE_BINS); - set32_fx(stereo_type_detect->total_power_fx, 0, MASA_SUM_FREQ_RANGE_BINS); + set32_fx( stereo_type_detect->sum_power_fx, 0, MASA_SUM_FREQ_RANGE_BINS ); + set32_fx( stereo_type_detect->total_power_fx, 0, MASA_SUM_FREQ_RANGE_BINS ); stereo_type_detect->q_sum_power = Q31; stereo_type_detect->q_total_power = Q31; @@ -5147,9 +5147,9 @@ void rotateAziEle_DirAC_fx( move32(); } - dv_r_0_fx = Madd_32_32( Madd_32_32( Mpy_32_32( L_shr(p_Rmat_fx[0], Q1), dv_0_fx ), L_shr(p_Rmat_fx[1], Q1), dv_1_fx ), L_shr(p_Rmat_fx[2], Q1), dv_2_fx ); // Q29 - dv_r_1_fx = Madd_32_32( Madd_32_32( Mpy_32_32( L_shr(p_Rmat_fx[3], Q1), dv_0_fx ), L_shr(p_Rmat_fx[4], Q1), dv_1_fx ), L_shr(p_Rmat_fx[5], Q1), dv_2_fx ); // Q29 - dv_r_2_fx = Madd_32_32( Madd_32_32( Mpy_32_32( L_shr(p_Rmat_fx[6], Q1), dv_0_fx ), L_shr(p_Rmat_fx[7], Q1), dv_1_fx ), L_shr(p_Rmat_fx[8], Q1), dv_2_fx ); // Q29 + dv_r_0_fx = Madd_32_32( Madd_32_32( Mpy_32_32( L_shr( p_Rmat_fx[0], Q1 ), dv_0_fx ), L_shr( p_Rmat_fx[1], Q1 ), dv_1_fx ), L_shr( p_Rmat_fx[2], Q1 ), dv_2_fx ); // Q29 + dv_r_1_fx = Madd_32_32( Madd_32_32( Mpy_32_32( L_shr( p_Rmat_fx[3], Q1 ), dv_0_fx ), L_shr( p_Rmat_fx[4], Q1 ), dv_1_fx ), L_shr( p_Rmat_fx[5], Q1 ), dv_2_fx ); // Q29 + dv_r_2_fx = Madd_32_32( Madd_32_32( Mpy_32_32( L_shr( p_Rmat_fx[6], Q1 ), dv_0_fx ), L_shr( p_Rmat_fx[7], Q1 ), dv_1_fx ), L_shr( p_Rmat_fx[8], Q1 ), dv_2_fx ); // Q29 /*Conversion spherical to cartesian coordinates*/ temp = BASOP_util_atan2( dv_r_1_fx, dv_r_0_fx, 0 ); // Q13 @@ -5596,7 +5596,7 @@ static void ivas_masa_ext_dirac_render_sf( #else static void ivas_masa_ext_dirac_render_sf_fx( MASA_EXT_REND_HANDLE hMasaExtRend, /* i/o: IVAS decoder structure */ - Word32 *output_f_fx[] /* i/o: synthesized core-coder transport channels/DirAC output */ + Word32 *output_f_fx[] /* i/o: synthesized core-coder transport channels/DirAC output */ ) { Word16 i, ch, idx_in, idx_lfe; @@ -5620,13 +5620,13 @@ static void ivas_masa_ext_dirac_render_sf_fx( Word32 dirEne_fx; Word32 surCohEner_fx; - FOR(Word16 ii = 0; ii < MAX_OUTPUT_CHANNELS; ii++) + FOR( Word16 ii = 0; ii < MAX_OUTPUT_CHANNELS; ii++ ) { - FOR(Word16 jj = 0; jj < MAX_PARAM_SPATIAL_SUBFRAMES; jj++) - { - set_zero_fx( Cldfb_RealBuffer_fx[ii][jj], CLDFB_NO_CHANNELS_MAX ); - set_zero_fx( Cldfb_ImagBuffer_fx[ii][jj], CLDFB_NO_CHANNELS_MAX ); - } + FOR( Word16 jj = 0; jj < MAX_PARAM_SPATIAL_SUBFRAMES; jj++ ) + { + set_zero_fx( Cldfb_RealBuffer_fx[ii][jj], CLDFB_NO_CHANNELS_MAX ); + set_zero_fx( Cldfb_ImagBuffer_fx[ii][jj], CLDFB_NO_CHANNELS_MAX ); + } } DIRAC_DEC_STACK_MEM DirAC_mem; @@ -5641,29 +5641,35 @@ static void ivas_masa_ext_dirac_render_sf_fx( /* Initialize aux buffers */ hDirACRend = hMasaExtRend->hDirACRend; hSpatParamRendCom = hMasaExtRend->hSpatParamRendCom; - nchan_transport = hMasaExtRend->nchan_input; move16(); + nchan_transport = hMasaExtRend->nchan_input; + move16(); DirAC_mem = hDirACRend->stack_mem; onset_filter_fx = DirAC_mem.onset_filter_fx; reference_power_fix = DirAC_mem.reference_power_fx; reference_power_smooth_fx = ( DirAC_mem.reference_power_fx == NULL ) ? NULL : DirAC_mem.reference_power_fx + hSpatParamRendCom->num_freq_bands; - //DirAC_mem.reference_power_smooth_q = DirAC_mem.reference_power_q = Q31; + // DirAC_mem.reference_power_smooth_q = DirAC_mem.reference_power_q = Q31; onset_filter_subframe_fx = ( DirAC_mem.onset_filter_fx == NULL ) ? NULL : DirAC_mem.onset_filter_fx + hSpatParamRendCom->num_freq_bands; coherence_flag = 1; /* There is always coherence assumed for ext rend of MASA */ move16(); /* Construct default MASA band mapping */ - FOR ( i = 0; i < MASA_FREQUENCY_BANDS + 1; i++ ) + FOR( i = 0; i < MASA_FREQUENCY_BANDS + 1; i++ ) { - masa_band_mapping[i] = i; move16(); + masa_band_mapping[i] = i; + move16(); } /* Subframe loop */ - slot_idx_start = hSpatParamRendCom->slots_rendered; move16(); - slot_idx_start_cldfb_synth = 0; move16(); + slot_idx_start = hSpatParamRendCom->slots_rendered; + move16(); + slot_idx_start_cldfb_synth = 0; + move16(); - subframe_idx = hSpatParamRendCom->subframes_rendered; move16(); - md_idx = hSpatParamRendCom->render_to_md_map[subframe_idx]; move16(); + subframe_idx = hSpatParamRendCom->subframes_rendered; + move16(); + md_idx = hSpatParamRendCom->render_to_md_map[subframe_idx]; + move16(); DIRAC_OUTPUT_SYNTHESIS_STATE *h_dirac_output_synthesis_state; h_dirac_output_synthesis_state = &( hDirACRend->h_output_synthesis_psd_state ); @@ -5674,7 +5680,7 @@ static void ivas_masa_ext_dirac_render_sf_fx( Copy( hSpatParamRendCom->elevation[hSpatParamRendCom->render_to_md_map[subframe_idx]], elevation, hSpatParamRendCom->num_freq_bands ); Copy32( hSpatParamRendCom->diffuseness_vector_fx[hSpatParamRendCom->render_to_md_map[subframe_idx]], diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands ); - IF ( NE_16(hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD )) + IF( NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { set32_fx( reference_power_smooth_fx, 0, hSpatParamRendCom->num_freq_bands ); } @@ -5684,106 +5690,116 @@ static void ivas_masa_ext_dirac_render_sf_fx( } /* compute response */ - IF ( NE_16(hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD )) + IF( NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { ivas_dirac_dec_compute_power_factors_fx( hSpatParamRendCom->num_freq_bands, - diffuseness_vector_fx, - hDirACRend->h_output_synthesis_psd_params.max_band_decorr, - hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, - hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx ); + diffuseness_vector_fx, + hDirACRend->h_output_synthesis_psd_params.max_band_decorr, + hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, + hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx ); - hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q = Q29; move16(); - hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q = Q29; move16(); + hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q = Q29; + move16(); + hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q = Q29; + move16(); - IF ( coherence_flag ) + IF( coherence_flag ) { - Word16 temp_exp = MIN_16; move16(); - FOR ( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ ) + Word16 temp_exp = MIN_16; + move16(); + FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ ) { - dirEne_fx = hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i]; move32(); - surCohEner_fx = Mpy_32_16_1(hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx[i], hSpatParamRendCom->surroundingCoherence_fx[md_idx][i]); //Q.29 - hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx[i] = L_sub(hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx[i], surCohEner_fx); - hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i] = L_add(hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i], surCohEner_fx); + dirEne_fx = hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i]; + move32(); + surCohEner_fx = Mpy_32_16_1( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx[i], hSpatParamRendCom->surroundingCoherence_fx[md_idx][i] ); // Q.29 + hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx[i] = L_sub( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx[i], surCohEner_fx ); + hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i] = L_add( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i], surCohEner_fx ); - surCohRatio_fx[i] = L_deposit_h(BASOP_Util_Divide3232_Scale( surCohEner_fx, L_add( L_add(1, dirEne_fx), surCohEner_fx ), &surCohRatio_exp[i])); - temp_exp = s_max(temp_exp, surCohRatio_exp[i]); + surCohRatio_fx[i] = L_deposit_h( BASOP_Util_Divide3232_Scale( surCohEner_fx, L_add( L_add( 1, dirEne_fx ), surCohEner_fx ), &surCohRatio_exp[i] ) ); + temp_exp = s_max( temp_exp, surCohRatio_exp[i] ); } - FOR(i = 0; i < hSpatParamRendCom->num_freq_bands; i++) + FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ ) { - surCohRatio_fx[i] = L_shr(surCohRatio_fx[i], sub(temp_exp, surCohRatio_exp[i])); + surCohRatio_fx[i] = L_shr( surCohRatio_fx[i], sub( temp_exp, surCohRatio_exp[i] ) ); } - Q_surCohRatio = sub(31, temp_exp); + Q_surCohRatio = sub( 31, temp_exp ); } ELSE { set32_fx( surCohRatio_fx, 0, hSpatParamRendCom->num_freq_bands ); - Q_surCohRatio = 31; move16(); + Q_surCohRatio = 31; + move16(); } } ELSE { ivas_dirac_dec_compute_gain_factors_fx( hSpatParamRendCom->num_freq_bands, - hSpatParamRendCom->diffuseness_vector_fx[md_idx], - hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, - hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx, - &hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q, - &hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q - ); - hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q = sub(31, hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q); - hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q = sub(31, hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q); - IF ( coherence_flag ) - { - FOR ( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ ) - { - surCohRatio_fx[i] = L_deposit_h(hSpatParamRendCom->surroundingCoherence_fx[md_idx][i]); move16(); + hSpatParamRendCom->diffuseness_vector_fx[md_idx], + hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, + hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx, + &hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q, + &hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q ); + hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q = sub( 31, hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q ); + hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q = sub( 31, hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q ); + IF( coherence_flag ) + { + FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ ) + { + surCohRatio_fx[i] = L_deposit_h( hSpatParamRendCom->surroundingCoherence_fx[md_idx][i] ); + move16(); } } ELSE { set32_fx( surCohRatio_fx, 0, hSpatParamRendCom->num_freq_bands ); } - - Q_surCohRatio = Q31; move16(); + + Q_surCohRatio = Q31; + move16(); } ivas_dirac_dec_compute_directional_responses_fx( hSpatParamRendCom, - hDirACRend, - hMasaExtRend->hVBAPdata, - masa_band_mapping, - NULL, - azimuth, - elevation, - md_idx, - surCohRatio_fx, - Q_surCohRatio, - 0, - NULL, - 0 ); + hDirACRend, + hMasaExtRend->hVBAPdata, + masa_band_mapping, + NULL, + azimuth, + elevation, + md_idx, + surCohRatio_fx, + Q_surCohRatio, + 0, + NULL, + 0 ); Word16 proto_direct_buffer_f_temp_q[60]; Word16 temp_proto_frame_q; - FOR ( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) + FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) { - index_slot = add(slot_idx_start, slot_idx); - md_idx = hSpatParamRendCom->render_to_md_map[subframe_idx]; move16(); - proto_direct_buffer_f_temp_q[slot_idx] = MAX_16; move16(); + index_slot = add( slot_idx_start, slot_idx ); + md_idx = hSpatParamRendCom->render_to_md_map[subframe_idx]; + move16(); + proto_direct_buffer_f_temp_q[slot_idx] = MAX_16; + move16(); /* CLDFB Analysis*/ - FOR ( ch = 0; ch < nchan_transport; ch++ ) + FOR( ch = 0; ch < nchan_transport; ch++ ) { - q_cldfb = 11; move16(); - hMasaExtRend->cldfbAnaRend[ch]->Q_cldfb_state = q_cldfb; move16(); - cldfbAnalysis_ts_fx_fixed_q( &( output_f_fx[ch][hSpatParamRendCom->num_freq_bands * index_slot] ) , - Cldfb_RealBuffer_fx[ch][0], - Cldfb_ImagBuffer_fx[ch][0], - hSpatParamRendCom->num_freq_bands, - hMasaExtRend->cldfbAnaRend[ch], &q_cldfb ); + q_cldfb = 11; + move16(); + hMasaExtRend->cldfbAnaRend[ch]->Q_cldfb_state = q_cldfb; + move16(); + cldfbAnalysis_ts_fx_fixed_q( &( output_f_fx[ch][hSpatParamRendCom->num_freq_bands * index_slot] ), + Cldfb_RealBuffer_fx[ch][0], + Cldfb_ImagBuffer_fx[ch][0], + hSpatParamRendCom->num_freq_bands, + hMasaExtRend->cldfbAnaRend[ch], &q_cldfb ); } - IF ( EQ_16(nchan_transport, 1 )) + IF( EQ_16( nchan_transport, 1 ) ) { /* Need to set second CLDFB channel to zero as further processing assumes CNA content in it */ set32_fx( Cldfb_RealBuffer_fx[1][0], 0, hSpatParamRendCom->num_freq_bands ); @@ -5793,100 +5809,119 @@ static void ivas_masa_ext_dirac_render_sf_fx( * prototype signal computation *-----------------------------------------------------------------*/ - IF ( EQ_16(hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD )) + IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { - protoSignalComputation_shd_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, + protoSignalComputation_shd_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, + hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx, + &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, + hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx, + &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, + reference_power_fix, &DirAC_mem.reference_power_q, slot_idx, nchan_transport, + hDirACRend->num_outputs_diff, + hSpatParamRendCom->num_freq_bands, + 0, q_cldfb ); + + proto_direct_buffer_f_temp_q[slot_idx] = hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q; + move16(); + } + ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) ) + { + protoSignalComputation2_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hDirACRend->proto_frame_f_fx, &hDirACRend->proto_frame_f_q, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx, &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, - hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx, - &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, - reference_power_fix, &DirAC_mem.reference_power_q, slot_idx, nchan_transport, - hDirACRend->num_outputs_diff, - hSpatParamRendCom->num_freq_bands, - 0, q_cldfb); - - proto_direct_buffer_f_temp_q[slot_idx] = hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q; move16(); - } - ELSE IF ( EQ_16(hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO )) - { - protoSignalComputation2_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hDirACRend->proto_frame_f_fx, &hDirACRend->proto_frame_f_q, - hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx, - &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, - reference_power_fix, &DirAC_mem.reference_power_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, - &hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, - 0, slot_idx, hSpatParamRendCom->num_freq_bands, hDirACRend->masa_stereo_type_detect, q_cldfb); - - proto_direct_buffer_f_temp_q[slot_idx] = hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q; move16(); - IF(LT_16(DirAC_mem.reference_power_q, DirAC_mem.reference_power_smooth_q)){ - Scale_sig32(reference_power_fix + hSpatParamRendCom->num_freq_bands, sub(DirAC_mem.reference_power_len, hSpatParamRendCom->num_freq_bands), sub(DirAC_mem.reference_power_q, DirAC_mem.reference_power_smooth_q)); - DirAC_mem.reference_power_smooth_q = DirAC_mem.reference_power_q; move16(); - } ELSE { - Scale_sig32(reference_power_fix, hSpatParamRendCom->num_freq_bands, sub(DirAC_mem.reference_power_smooth_q, DirAC_mem.reference_power_q)); - DirAC_mem.reference_power_q = DirAC_mem.reference_power_smooth_q; move16(); - } - temp_proto_frame_q = getScaleFactor32(hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_len) - 2; - Scale_sig32(hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_len, temp_proto_frame_q); - hDirACRend->proto_frame_f_q = add(hDirACRend->proto_frame_f_q, temp_proto_frame_q); + reference_power_fix, &DirAC_mem.reference_power_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, + &hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, + 0, slot_idx, hSpatParamRendCom->num_freq_bands, hDirACRend->masa_stereo_type_detect, q_cldfb ); + + proto_direct_buffer_f_temp_q[slot_idx] = hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q; + move16(); + IF( LT_16( DirAC_mem.reference_power_q, DirAC_mem.reference_power_smooth_q ) ) + { + Scale_sig32( reference_power_fix + hSpatParamRendCom->num_freq_bands, sub( DirAC_mem.reference_power_len, hSpatParamRendCom->num_freq_bands ), sub( DirAC_mem.reference_power_q, DirAC_mem.reference_power_smooth_q ) ); + DirAC_mem.reference_power_smooth_q = DirAC_mem.reference_power_q; + move16(); + } + ELSE + { + Scale_sig32( reference_power_fix, hSpatParamRendCom->num_freq_bands, sub( DirAC_mem.reference_power_smooth_q, DirAC_mem.reference_power_q ) ); + DirAC_mem.reference_power_q = DirAC_mem.reference_power_smooth_q; + move16(); + } + temp_proto_frame_q = getScaleFactor32( hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_len ) - 2; + Scale_sig32( hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_len, temp_proto_frame_q ); + hDirACRend->proto_frame_f_q = add( hDirACRend->proto_frame_f_q, temp_proto_frame_q ); } ELSE { - SWITCH ( nchan_transport ) + SWITCH( nchan_transport ) { case 2: - protoSignalComputation2_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, - hDirACRend->proto_frame_f_fx, - &hDirACRend->proto_frame_f_q, - hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx, - &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, - reference_power_fix, &DirAC_mem.reference_power_q, - hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, - &hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, - hDirACRend->hOutSetup.is_loudspeaker_setup, - slot_idx, - hSpatParamRendCom->num_freq_bands, - hDirACRend->masa_stereo_type_detect, q_cldfb); - - proto_direct_buffer_f_temp_q[slot_idx] = hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q; move16(); - IF(LT_16(DirAC_mem.reference_power_q, DirAC_mem.reference_power_smooth_q)){ - Scale_sig32(reference_power_fix + hSpatParamRendCom->num_freq_bands, sub(DirAC_mem.reference_power_len, hSpatParamRendCom->num_freq_bands), sub(DirAC_mem.reference_power_q, DirAC_mem.reference_power_smooth_q)); - DirAC_mem.reference_power_smooth_q = DirAC_mem.reference_power_q; move16(); - } ELSE { - Scale_sig32(reference_power_fix, hSpatParamRendCom->num_freq_bands, sub(DirAC_mem.reference_power_smooth_q, DirAC_mem.reference_power_q)); - DirAC_mem.reference_power_q = DirAC_mem.reference_power_smooth_q; move16(); - } - temp_proto_frame_q = getScaleFactor32(hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_len) -2; - Scale_sig32(hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_len, temp_proto_frame_q); - hDirACRend->proto_frame_f_q = add(hDirACRend->proto_frame_f_q, temp_proto_frame_q); - - BREAK; - case 1: - protoSignalComputation1_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, - hDirACRend->proto_frame_f_fx, - &hDirACRend->proto_frame_f_q, - hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx, - &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, - reference_power_fix, &DirAC_mem.reference_power_q, - hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, - &hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, - slot_idx, - hDirACRend->num_protos_diff, - hSpatParamRendCom->num_freq_bands, q_cldfb); + protoSignalComputation2_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, + hDirACRend->proto_frame_f_fx, + &hDirACRend->proto_frame_f_q, + hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx, + &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, + reference_power_fix, &DirAC_mem.reference_power_q, + hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, + &hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, + hDirACRend->hOutSetup.is_loudspeaker_setup, + slot_idx, + hSpatParamRendCom->num_freq_bands, + hDirACRend->masa_stereo_type_detect, q_cldfb ); + + proto_direct_buffer_f_temp_q[slot_idx] = hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q; + move16(); + IF( LT_16( DirAC_mem.reference_power_q, DirAC_mem.reference_power_smooth_q ) ) + { + Scale_sig32( reference_power_fix + hSpatParamRendCom->num_freq_bands, sub( DirAC_mem.reference_power_len, hSpatParamRendCom->num_freq_bands ), sub( DirAC_mem.reference_power_q, DirAC_mem.reference_power_smooth_q ) ); + DirAC_mem.reference_power_smooth_q = DirAC_mem.reference_power_q; + move16(); + } + ELSE + { + Scale_sig32( reference_power_fix, hSpatParamRendCom->num_freq_bands, sub( DirAC_mem.reference_power_smooth_q, DirAC_mem.reference_power_q ) ); + DirAC_mem.reference_power_q = DirAC_mem.reference_power_smooth_q; + move16(); + } + temp_proto_frame_q = getScaleFactor32( hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_len ) - 2; + Scale_sig32( hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_len, temp_proto_frame_q ); + hDirACRend->proto_frame_f_q = add( hDirACRend->proto_frame_f_q, temp_proto_frame_q ); - proto_direct_buffer_f_temp_q[slot_idx] = hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q; move16(); + BREAK; + case 1: + protoSignalComputation1_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, + hDirACRend->proto_frame_f_fx, + &hDirACRend->proto_frame_f_q, + hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx, + &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, + reference_power_fix, &DirAC_mem.reference_power_q, + hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, + &hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, + slot_idx, + hDirACRend->num_protos_diff, + hSpatParamRendCom->num_freq_bands, q_cldfb ); + + proto_direct_buffer_f_temp_q[slot_idx] = hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q; + move16(); - IF(LT_16(DirAC_mem.reference_power_q, DirAC_mem.reference_power_smooth_q)){ - Scale_sig32(reference_power_fix + hSpatParamRendCom->num_freq_bands, sub(DirAC_mem.reference_power_len, hSpatParamRendCom->num_freq_bands), sub(DirAC_mem.reference_power_q, DirAC_mem.reference_power_smooth_q)); - DirAC_mem.reference_power_smooth_q = DirAC_mem.reference_power_q; move16(); - } ELSE { - Scale_sig32(reference_power_fix, hSpatParamRendCom->num_freq_bands, sub(DirAC_mem.reference_power_smooth_q, DirAC_mem.reference_power_q)); - DirAC_mem.reference_power_q = DirAC_mem.reference_power_smooth_q; move16(); - } + IF( LT_16( DirAC_mem.reference_power_q, DirAC_mem.reference_power_smooth_q ) ) + { + Scale_sig32( reference_power_fix + hSpatParamRendCom->num_freq_bands, sub( DirAC_mem.reference_power_len, hSpatParamRendCom->num_freq_bands ), sub( DirAC_mem.reference_power_q, DirAC_mem.reference_power_smooth_q ) ); + DirAC_mem.reference_power_smooth_q = DirAC_mem.reference_power_q; + move16(); + } + ELSE + { + Scale_sig32( reference_power_fix, hSpatParamRendCom->num_freq_bands, sub( DirAC_mem.reference_power_smooth_q, DirAC_mem.reference_power_q ) ); + DirAC_mem.reference_power_q = DirAC_mem.reference_power_smooth_q; + move16(); + } - temp_proto_frame_q = getScaleFactor32(hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_len) - 2; - Scale_sig32(hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_len, temp_proto_frame_q); - hDirACRend->proto_frame_f_q = add(hDirACRend->proto_frame_f_q, temp_proto_frame_q); + temp_proto_frame_q = getScaleFactor32( hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_len ) - 2; + Scale_sig32( hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_len, temp_proto_frame_q ); + hDirACRend->proto_frame_f_q = add( hDirACRend->proto_frame_f_q, temp_proto_frame_q ); - BREAK; + BREAK; default: return; } @@ -5895,25 +5930,25 @@ static void ivas_masa_ext_dirac_render_sf_fx( /*-----------------------------------------------------------------* * frequency domain decorrelation *-----------------------------------------------------------------*/ - IF ( EQ_16(hDirACRend->proto_signal_decorr_on, 1 )) + IF( EQ_16( hDirACRend->proto_signal_decorr_on, 1 ) ) { /* decorrelate prototype frame */ - IF ( EQ_16(hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD )) + IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { ivas_dirac_dec_decorr_process_fx( hSpatParamRendCom->num_freq_bands, - hDirACRend->num_outputs_diff, - hDirACRend->num_protos_diff, - hDirACRend->synthesisConf, - nchan_transport, - hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx + slot_idx * 2 * hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff, - hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, - hDirACRend->num_protos_diff, - hDirACRend->proto_index_diff, - hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx + slot_idx * 2 * hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff + 2 * hSpatParamRendCom->num_freq_bands * min( 4, nchan_transport ), - &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, - onset_filter_fx, - hDirACRend->h_freq_domain_decorr_ap_params, - hDirACRend->h_freq_domain_decorr_ap_state ); + hDirACRend->num_outputs_diff, + hDirACRend->num_protos_diff, + hDirACRend->synthesisConf, + nchan_transport, + hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx + slot_idx * 2 * hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff, + hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, + hDirACRend->num_protos_diff, + hDirACRend->proto_index_diff, + hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx + slot_idx * 2 * hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff + 2 * hSpatParamRendCom->num_freq_bands * min( 4, nchan_transport ), + &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, + onset_filter_fx, + hDirACRend->h_freq_domain_decorr_ap_params, + hDirACRend->h_freq_domain_decorr_ap_state ); v_multc_fixed( onset_filter_fx, 536870912 /* 0.25f in Q31 */, onset_filter_fx, hSpatParamRendCom->num_freq_bands ); /* Q31 */ v_add_fixed( onset_filter_fx, onset_filter_subframe_fx, onset_filter_subframe_fx, hSpatParamRendCom->num_freq_bands, 0 ); /* Q31 */ @@ -5921,31 +5956,32 @@ static void ivas_masa_ext_dirac_render_sf_fx( } ELSE { - set_zero_fx(DirAC_mem.frame_dec_f_fx, DirAC_mem.frame_dec_f_len); + set_zero_fx( DirAC_mem.frame_dec_f_fx, DirAC_mem.frame_dec_f_len ); ivas_dirac_dec_decorr_process_fx( hSpatParamRendCom->num_freq_bands, - hDirACRend->num_outputs_diff, - hDirACRend->num_protos_diff, - hDirACRend->synthesisConf, - nchan_transport, - hDirACRend->proto_frame_f_fx, - hDirACRend->proto_frame_f_q, - hDirACRend->num_protos_diff, - hDirACRend->proto_index_diff, - DirAC_mem.frame_dec_f_fx, - &DirAC_mem.frame_dec_f_q, - onset_filter_fx, - hDirACRend->h_freq_domain_decorr_ap_params, - hDirACRend->h_freq_domain_decorr_ap_state ); - + hDirACRend->num_outputs_diff, + hDirACRend->num_protos_diff, + hDirACRend->synthesisConf, + nchan_transport, + hDirACRend->proto_frame_f_fx, + hDirACRend->proto_frame_f_q, + hDirACRend->num_protos_diff, + hDirACRend->proto_index_diff, + DirAC_mem.frame_dec_f_fx, + &DirAC_mem.frame_dec_f_q, + onset_filter_fx, + hDirACRend->h_freq_domain_decorr_ap_params, + hDirACRend->h_freq_domain_decorr_ap_state ); + hDirACRend->proto_frame_dec_f_fx = DirAC_mem.frame_dec_f_fx; - hDirACRend->proto_frame_dec_f_q = DirAC_mem.frame_dec_f_q; move16(); + hDirACRend->proto_frame_dec_f_q = DirAC_mem.frame_dec_f_q; + move16(); p_onset_filter_fx = onset_filter_fx; } } ELSE { - IF ( EQ_16(hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD )) + IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { set32_fx( onset_filter_subframe_fx, ONE_IN_Q31, hSpatParamRendCom->num_freq_bands ); p_onset_filter_fx = onset_filter_subframe_fx; @@ -5964,140 +6000,152 @@ static void ivas_masa_ext_dirac_render_sf_fx( *-----------------------------------------------------------------*/ test(); - IF ( EQ_16(hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS) || EQ_16(hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD )) + IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) || EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) ) { /* Compute diffuse prototypes */ ivas_dirac_dec_compute_diffuse_proto_fx( hDirACRend, hSpatParamRendCom->num_freq_bands, slot_idx ); - } - Scale_sig32(h_dirac_output_synthesis_state->diffuse_power_factor_fx, hSpatParamRendCom->num_freq_bands, sub(31, h_dirac_output_synthesis_state->diffuse_power_factor_q)); - h_dirac_output_synthesis_state->diffuse_power_factor_q = Q31; move16(); - - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, hSpatParamRendCom->num_freq_bands, sub(31, hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q)); - hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q = Q31; move16(); - - /*Word16 q_cy_auto_diff_smooth = getScaleFactor32(h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, h_dirac_output_synthesis_state->cy_auto_diff_smooth_len); - Scale_sig32(h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, h_dirac_output_synthesis_state->cy_auto_diff_smooth_len, q_cy_auto_diff_smooth); - h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = add(h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, q_cy_auto_diff_smooth);*/ + Scale_sig32( h_dirac_output_synthesis_state->diffuse_power_factor_fx, hSpatParamRendCom->num_freq_bands, sub( 31, h_dirac_output_synthesis_state->diffuse_power_factor_q ) ); + h_dirac_output_synthesis_state->diffuse_power_factor_q = Q31; + move16(); - ivas_dirac_dec_output_synthesis_process_slot_fx( reference_power_fix, - DirAC_mem.reference_power_q, - p_onset_filter_fx, - azimuth, - elevation, - hSpatParamRendCom->diffuseness_vector_fx[md_idx], - hSpatParamRendCom->q_diffuseness_vector, - hSpatParamRendCom, - hDirACRend, - 0, - 0, - hMasaExtRend->hVBAPdata, - hDirACRend->hOutSetup, - nchan_transport, - md_idx, - 0, - 0 ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, hSpatParamRendCom->num_freq_bands, sub( 31, hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q ) ); + hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q = Q31; + move16(); - IF ( NE_16(hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD )) - { - Scale_sig32(DirAC_mem.reference_power_fx, DirAC_mem.reference_power_len, -1); - DirAC_mem.reference_power_q = sub(DirAC_mem.reference_power_q, 1); + /*Word16 q_cy_auto_diff_smooth = getScaleFactor32(h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, h_dirac_output_synthesis_state->cy_auto_diff_smooth_len); + Scale_sig32(h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, h_dirac_output_synthesis_state->cy_auto_diff_smooth_len, q_cy_auto_diff_smooth); + h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = add(h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, q_cy_auto_diff_smooth);*/ + + ivas_dirac_dec_output_synthesis_process_slot_fx( reference_power_fix, + DirAC_mem.reference_power_q, + p_onset_filter_fx, + azimuth, + elevation, + hSpatParamRendCom->diffuseness_vector_fx[md_idx], + hSpatParamRendCom->q_diffuseness_vector, + hSpatParamRendCom, + hDirACRend, + 0, + 0, + hMasaExtRend->hVBAPdata, + hDirACRend->hOutSetup, + nchan_transport, + md_idx, + 0, + 0 ); + + IF( NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) + { + Scale_sig32( DirAC_mem.reference_power_fx, DirAC_mem.reference_power_len, -1 ); + DirAC_mem.reference_power_q = sub( DirAC_mem.reference_power_q, 1 ); DirAC_mem.reference_power_smooth_q = DirAC_mem.reference_power_q; - v_add_fixed( reference_power_fix, reference_power_smooth_fx, reference_power_smooth_fx, hSpatParamRendCom->num_freq_bands, 0); + v_add_fixed( reference_power_fix, reference_power_smooth_fx, reference_power_smooth_fx, hSpatParamRendCom->num_freq_bands, 0 ); } } /*Rescaling proto_direct_buffer_f*/ Word16 temp = MAX_16; - FOR(slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++) + FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) { - temp = s_min(temp, proto_direct_buffer_f_temp_q[slot_idx]); + temp = s_min( temp, proto_direct_buffer_f_temp_q[slot_idx] ); } - + IF( hDirACRend->hOutSetup.is_loudspeaker_setup ) { - FOR(slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++) + FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) { - Scale_sig32(&hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx[i_mult(slot_idx , idiv1616(hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len , hSpatParamRendCom->subframe_nbslots[subframe_idx]))], idiv1616(hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len , hSpatParamRendCom->subframe_nbslots[subframe_idx]), sub(temp, proto_direct_buffer_f_temp_q[slot_idx])); + Scale_sig32( &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx[i_mult( slot_idx, idiv1616( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len, hSpatParamRendCom->subframe_nbslots[subframe_idx] ) )], idiv1616( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len, hSpatParamRendCom->subframe_nbslots[subframe_idx] ), sub( temp, proto_direct_buffer_f_temp_q[slot_idx] ) ); } } ELSE { - FOR(slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++) + FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) { - Scale_sig32(&hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx[i_mult(slot_idx , idiv1616(hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len , hSpatParamRendCom->subframe_nbslots[subframe_idx]))], idiv1616(hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len , hSpatParamRendCom->subframe_nbslots[subframe_idx]), sub(temp, proto_direct_buffer_f_temp_q[slot_idx])); + Scale_sig32( &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx[i_mult( slot_idx, idiv1616( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len, hSpatParamRendCom->subframe_nbslots[subframe_idx] ) )], idiv1616( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len, hSpatParamRendCom->subframe_nbslots[subframe_idx] ), sub( temp, proto_direct_buffer_f_temp_q[slot_idx] ) ); } - } - hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q = temp; move16(); + hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q = temp; + move16(); ivas_dirac_dec_output_synthesis_get_interpolator_fx( &hDirACRend->h_output_synthesis_psd_params, hSpatParamRendCom->subframe_nbslots[subframe_idx] ); /*Memories Scaling*/ - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, hSpatParamRendCom->num_freq_bands, sub(31, hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q)); - hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q = Q31; move16(); - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx, hSpatParamRendCom->num_freq_bands, sub(31, hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q)); - hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q = Q31; move16(); - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, hDirACRend->num_outputs_dir * hSpatParamRendCom->num_freq_bands, sub(31, hDirACRend->h_output_synthesis_psd_state.direct_responses_q)); - hDirACRend->h_output_synthesis_psd_state.direct_responses_q = Q31; move16(); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, hSpatParamRendCom->num_freq_bands, sub( 31, hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q ) ); + hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q = Q31; + move16(); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx, hSpatParamRendCom->num_freq_bands, sub( 31, hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q ) ); + hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q = Q31; + move16(); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, hDirACRend->num_outputs_dir * hSpatParamRendCom->num_freq_bands, sub( 31, hDirACRend->h_output_synthesis_psd_state.direct_responses_q ) ); + hDirACRend->h_output_synthesis_psd_state.direct_responses_q = Q31; + move16(); - IF ( EQ_16(hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD )) + IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { FOR( ch = 0; ch < hDirACRend->hOutSetup.nchan_out_woLFE; ch++ ) { FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) { - Scale_sig32(Cldfb_RealBuffer_fx[ch][slot_idx], - hSpatParamRendCom->num_freq_bands, sub(6, q_cldfb)); - Scale_sig32(Cldfb_ImagBuffer_fx[ch][slot_idx], - hSpatParamRendCom->num_freq_bands, sub(6, q_cldfb)); + Scale_sig32( Cldfb_RealBuffer_fx[ch][slot_idx], + hSpatParamRendCom->num_freq_bands, sub( 6, q_cldfb ) ); + Scale_sig32( Cldfb_ImagBuffer_fx[ch][slot_idx], + hSpatParamRendCom->num_freq_bands, sub( 6, q_cldfb ) ); } } - q_cldfb = 6; move16(); + q_cldfb = 6; + move16(); - Scale_sig32(hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_len, sub(26, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth)); - hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth = Q26; move16(); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_len, sub( 26, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth ) ); + hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth = Q26; + move16(); - Scale_sig32(hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_len, sub(26, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth)); - hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth = Q26; move16(); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_len, sub( 26, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth ) ); + hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth = Q26; + move16(); - Scale_sig32(hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_len, sub(26, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev)); - hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev = Q26; move16(); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_len, sub( 26, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev ) ); + hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev = Q26; + move16(); - Scale_sig32(hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_len, sub(26, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev)); - hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev = Q26; move16(); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_len, sub( 26, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev ) ); + hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev = Q26; + move16(); ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( Cldfb_RealBuffer_fx, - Cldfb_ImagBuffer_fx, - hSpatParamRendCom, - hDirACRend, - nchan_transport, - hSpatParamRendCom->subframe_nbslots[subframe_idx], - p_onset_filter_fx, - diffuseness_vector_fx, - 0, - 0, - &hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, - &hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev); - q_cldfb = -1; move16(); - hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q = hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev; move16(); - hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q = hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev; move16(); + Cldfb_ImagBuffer_fx, + hSpatParamRendCom, + hDirACRend, + nchan_transport, + hSpatParamRendCom->subframe_nbslots[subframe_idx], + p_onset_filter_fx, + diffuseness_vector_fx, + 0, + 0, + &hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, + &hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev ); + q_cldfb = -1; + move16(); + hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q = hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev; + move16(); + hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q = hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev; + move16(); } ELSE { #if 1 IF( hDirACRend->proto_signal_decorr_on ) { - //hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q = hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q; + // hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q = hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q; - Word16 new_proto_diffuse_buffer_f_q = getScaleFactor32(hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len); - Word16 new_proto_direct_buffer_f_q = getScaleFactor32(hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len); + Word16 new_proto_diffuse_buffer_f_q = getScaleFactor32( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len ); + Word16 new_proto_direct_buffer_f_q = getScaleFactor32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len ); - scale_sig32(hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len, new_proto_diffuse_buffer_f_q); - scale_sig32(hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len, new_proto_direct_buffer_f_q); - hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q = add(hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, new_proto_direct_buffer_f_q); - hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q = add(hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, new_proto_diffuse_buffer_f_q); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len, new_proto_diffuse_buffer_f_q ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len, new_proto_direct_buffer_f_q ); + hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q = add( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, new_proto_direct_buffer_f_q ); + hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q = add( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, new_proto_diffuse_buffer_f_q ); /*scale_sig32(hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len, sub(s_min(hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q), hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q)); scale_sig32(hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len, sub(s_min(hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q), hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q)); @@ -6110,89 +6158,98 @@ static void ivas_masa_ext_dirac_render_sf_fx( { FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) { - Scale_sig32(Cldfb_RealBuffer_fx[ch][slot_idx], - hSpatParamRendCom->num_freq_bands, sub(11, q_cldfb)); - Scale_sig32(Cldfb_ImagBuffer_fx[ch][slot_idx], - hSpatParamRendCom->num_freq_bands, sub(11, q_cldfb)); + Scale_sig32( Cldfb_RealBuffer_fx[ch][slot_idx], + hSpatParamRendCom->num_freq_bands, sub( 11, q_cldfb ) ); + Scale_sig32( Cldfb_ImagBuffer_fx[ch][slot_idx], + hSpatParamRendCom->num_freq_bands, sub( 11, q_cldfb ) ); } } - q_cldfb = 11; move16(); + q_cldfb = 11; + move16(); - - Word16 reference_power_temp_q = getScaleFactor32(DirAC_mem.reference_power_fx, DirAC_mem.reference_power_len); - scale_sig32(DirAC_mem.reference_power_fx, DirAC_mem.reference_power_len, reference_power_temp_q); - DirAC_mem.reference_power_q = add(DirAC_mem.reference_power_q, reference_power_temp_q); - DirAC_mem.reference_power_smooth_q = add(DirAC_mem.reference_power_q, reference_power_temp_q); - Word16 q_cy_auto_diff_smooth = getScaleFactor32(h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, h_dirac_output_synthesis_state->cy_auto_diff_smooth_len); - Scale_sig32(h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, h_dirac_output_synthesis_state->cy_auto_diff_smooth_len, q_cy_auto_diff_smooth); - h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = add(h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, q_cy_auto_diff_smooth); + Word16 reference_power_temp_q = getScaleFactor32( DirAC_mem.reference_power_fx, DirAC_mem.reference_power_len ); + scale_sig32( DirAC_mem.reference_power_fx, DirAC_mem.reference_power_len, reference_power_temp_q ); + DirAC_mem.reference_power_q = add( DirAC_mem.reference_power_q, reference_power_temp_q ); + DirAC_mem.reference_power_smooth_q = add( DirAC_mem.reference_power_q, reference_power_temp_q ); - Scale_sig32(hDirACRend->h_output_synthesis_psd_state.direct_responses_square_fx, hDirACRend->num_outputs_dir * hSpatParamRendCom->num_freq_bands, sub(31, hDirACRend->h_output_synthesis_psd_state.direct_responses_square_q)); - hDirACRend->h_output_synthesis_psd_state.direct_responses_square_q = Q31; move16(); - Scale_sig32(h_dirac_output_synthesis_state->diffuse_power_factor_fx, hSpatParamRendCom->num_freq_bands, sub(31, h_dirac_output_synthesis_state->diffuse_power_factor_q)); - h_dirac_output_synthesis_state->diffuse_power_factor_q = Q31; move16(); - Scale_sig32(h_dirac_output_synthesis_state->direct_responses_fx, hSpatParamRendCom->num_freq_bands, sub(31, h_dirac_output_synthesis_state->direct_responses_q)); - h_dirac_output_synthesis_state->direct_responses_q = Q31; move16(); + Word16 q_cy_auto_diff_smooth = getScaleFactor32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, h_dirac_output_synthesis_state->cy_auto_diff_smooth_len ); + Scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, h_dirac_output_synthesis_state->cy_auto_diff_smooth_len, q_cy_auto_diff_smooth ); + h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, q_cy_auto_diff_smooth ); + + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_square_fx, hDirACRend->num_outputs_dir * hSpatParamRendCom->num_freq_bands, sub( 31, hDirACRend->h_output_synthesis_psd_state.direct_responses_square_q ) ); + hDirACRend->h_output_synthesis_psd_state.direct_responses_square_q = Q31; + move16(); + Scale_sig32( h_dirac_output_synthesis_state->diffuse_power_factor_fx, hSpatParamRendCom->num_freq_bands, sub( 31, h_dirac_output_synthesis_state->diffuse_power_factor_q ) ); + h_dirac_output_synthesis_state->diffuse_power_factor_q = Q31; + move16(); + Scale_sig32( h_dirac_output_synthesis_state->direct_responses_fx, hSpatParamRendCom->num_freq_bands, sub( 31, h_dirac_output_synthesis_state->direct_responses_q ) ); + h_dirac_output_synthesis_state->direct_responses_q = Q31; + move16(); /*Q-adjustment*/ IF( hDirACRend->masa_stereo_type_detect ) { - hDirACRend->masa_stereo_type_detect->subtract_power_y_smooth_fx = L_shl(hDirACRend->masa_stereo_type_detect->subtract_power_y_smooth_fx, sub(s_min(hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth, hDirACRend->masa_stereo_type_detect->q_subtract_power_y),hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth)); - hDirACRend->masa_stereo_type_detect->subtract_power_y_fx = L_shl(hDirACRend->masa_stereo_type_detect->subtract_power_y_fx, sub(s_min(hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth, hDirACRend->masa_stereo_type_detect->q_subtract_power_y),hDirACRend->masa_stereo_type_detect->q_subtract_power_y)); + hDirACRend->masa_stereo_type_detect->subtract_power_y_smooth_fx = L_shl( hDirACRend->masa_stereo_type_detect->subtract_power_y_smooth_fx, sub( s_min( hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth, hDirACRend->masa_stereo_type_detect->q_subtract_power_y ), hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth ) ); + hDirACRend->masa_stereo_type_detect->subtract_power_y_fx = L_shl( hDirACRend->masa_stereo_type_detect->subtract_power_y_fx, sub( s_min( hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth, hDirACRend->masa_stereo_type_detect->q_subtract_power_y ), hDirACRend->masa_stereo_type_detect->q_subtract_power_y ) ); - hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth = s_min(hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth, hDirACRend->masa_stereo_type_detect->q_subtract_power_y); - hDirACRend->masa_stereo_type_detect->q_subtract_power_y = s_min(hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth, hDirACRend->masa_stereo_type_detect->q_subtract_power_y); + hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth = s_min( hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth, hDirACRend->masa_stereo_type_detect->q_subtract_power_y ); + hDirACRend->masa_stereo_type_detect->q_subtract_power_y = s_min( hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth, hDirACRend->masa_stereo_type_detect->q_subtract_power_y ); } - Scale_sig32(hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_len, sub(s_min(hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q),hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q)); - hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q = s_min(hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q); - Scale_sig32(hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_len, sub(s_min(hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q), hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q)); - hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q = s_min(hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_len, sub( s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q ), hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q ) ); + hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q = s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_len, sub( s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q ), hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q ) ); + hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q = s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q ); - Word16 proto_power_diff_smooth_prev_temp_q = getScaleFactor32(hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_len); - Scale_sig32(hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_len, proto_power_diff_smooth_prev_temp_q); - hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q = add(hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q, proto_power_diff_smooth_prev_temp_q); + Word16 proto_power_diff_smooth_prev_temp_q = getScaleFactor32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_len ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_len, proto_power_diff_smooth_prev_temp_q ); + hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q = add( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q, proto_power_diff_smooth_prev_temp_q ); - Word16 proto_power_diff_smooth_temp_q = getScaleFactor32(hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_len); - Scale_sig32(hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_len, proto_power_diff_smooth_temp_q); - hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q = add(hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, proto_power_diff_smooth_temp_q); + Word16 proto_power_diff_smooth_temp_q = getScaleFactor32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_len ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_len, proto_power_diff_smooth_temp_q ); + hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q = add( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, proto_power_diff_smooth_temp_q ); - Scale_sig32(hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_len, sub(s_min(hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q),hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q)); - Scale_sig32(hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_len, sub(s_min(hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q),hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q)); - hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q = s_min(hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q); - hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q = s_min(hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_len, sub( s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q ), hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_len, sub( s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q ), hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q ) ); + hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q = s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q ); + hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q = s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q ); - Scale_sig32(diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands, 1); + Scale_sig32( diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands, 1 ); /*Buffer rescaling*/ - - Scale_sig32(hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_fx, hSpatParamRendCom->num_freq_bands, sub(s_min(hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, DirAC_mem.reference_power_q),hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q)); - Scale_sig32(DirAC_mem.reference_power_fx, DirAC_mem.reference_power_len, sub(s_min(hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, DirAC_mem.reference_power_q),DirAC_mem.reference_power_q)); - - hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q = s_min(hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, DirAC_mem.reference_power_q); - DirAC_mem.reference_power_q = s_min(hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, DirAC_mem.reference_power_q); - DirAC_mem.reference_power_smooth_q = s_min(hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, DirAC_mem.reference_power_q); + + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_fx, hSpatParamRendCom->num_freq_bands, sub( s_min( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, DirAC_mem.reference_power_q ), hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q ) ); + Scale_sig32( DirAC_mem.reference_power_fx, DirAC_mem.reference_power_len, sub( s_min( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, DirAC_mem.reference_power_q ), DirAC_mem.reference_power_q ) ); + + hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q = s_min( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, DirAC_mem.reference_power_q ); + DirAC_mem.reference_power_q = s_min( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, DirAC_mem.reference_power_q ); + DirAC_mem.reference_power_smooth_q = s_min( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, DirAC_mem.reference_power_q ); ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( Cldfb_RealBuffer_fx, - Cldfb_ImagBuffer_fx, - hSpatParamRendCom, - hDirACRend, - hSpatParamRendCom->subframe_nbslots[subframe_idx], - diffuseness_vector_fx, - reference_power_smooth_fx, - &DirAC_mem.reference_power_smooth_q, - ONE_IN_Q31, - 0, &q_cldfb ); + Cldfb_ImagBuffer_fx, + hSpatParamRendCom, + hDirACRend, + hSpatParamRendCom->subframe_nbslots[subframe_idx], + diffuseness_vector_fx, + reference_power_smooth_fx, + &DirAC_mem.reference_power_smooth_q, + ONE_IN_Q31, + 0, &q_cldfb ); hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q = hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q; hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q = DirAC_mem.reference_power_smooth_q; - IF(LT_16(DirAC_mem.reference_power_q, DirAC_mem.reference_power_smooth_q)){ - Scale_sig32(reference_power_fix + hSpatParamRendCom->num_freq_bands, sub(DirAC_mem.reference_power_len, hSpatParamRendCom->num_freq_bands), sub(DirAC_mem.reference_power_q, DirAC_mem.reference_power_smooth_q)); - DirAC_mem.reference_power_smooth_q = DirAC_mem.reference_power_q; move16(); - } ELSE { - Scale_sig32(reference_power_fix, hSpatParamRendCom->num_freq_bands, sub(DirAC_mem.reference_power_smooth_q, DirAC_mem.reference_power_q)); - DirAC_mem.reference_power_q = DirAC_mem.reference_power_smooth_q; move16(); + IF( LT_16( DirAC_mem.reference_power_q, DirAC_mem.reference_power_smooth_q ) ) + { + Scale_sig32( reference_power_fix + hSpatParamRendCom->num_freq_bands, sub( DirAC_mem.reference_power_len, hSpatParamRendCom->num_freq_bands ), sub( DirAC_mem.reference_power_q, DirAC_mem.reference_power_smooth_q ) ); + DirAC_mem.reference_power_smooth_q = DirAC_mem.reference_power_q; + move16(); + } + ELSE + { + Scale_sig32( reference_power_fix, hSpatParamRendCom->num_freq_bands, sub( DirAC_mem.reference_power_smooth_q, DirAC_mem.reference_power_q ) ); + DirAC_mem.reference_power_q = DirAC_mem.reference_power_smooth_q; + move16(); } } @@ -6200,7 +6257,8 @@ static void ivas_masa_ext_dirac_render_sf_fx( * CLDFB synthesis (and binaural rendering) *-----------------------------------------------------------------*/ - index_slot = slot_idx_start_cldfb_synth; move16(); + index_slot = slot_idx_start_cldfb_synth; + move16(); { Word16 outchannels; @@ -6211,29 +6269,33 @@ static void ivas_masa_ext_dirac_render_sf_fx( { FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) { - Scale_sig32(Cldfb_RealBuffer_fx[ch][slot_idx], - hSpatParamRendCom->num_freq_bands, sub(10, q_cldfb)); - Scale_sig32(Cldfb_ImagBuffer_fx[ch][slot_idx], - hSpatParamRendCom->num_freq_bands, sub(10, q_cldfb)); + Scale_sig32( Cldfb_RealBuffer_fx[ch][slot_idx], + hSpatParamRendCom->num_freq_bands, sub( 10, q_cldfb ) ); + Scale_sig32( Cldfb_ImagBuffer_fx[ch][slot_idx], + hSpatParamRendCom->num_freq_bands, sub( 10, q_cldfb ) ); } } - q_cldfb = 10; move16(); - hMasaExtRend->cldfbSynRend[0]->Q_cldfb_state = q_cldfb; move16(); + q_cldfb = 10; + move16(); + hMasaExtRend->cldfbSynRend[0]->Q_cldfb_state = q_cldfb; + move16(); - idx_in = 0; move16(); - idx_lfe = 0; move16(); + idx_in = 0; + move16(); + idx_lfe = 0; + move16(); - outchannels = add(hDirACRend->hOutSetup.nchan_out_woLFE, hDirACRend->hOutSetup.num_lfe); + outchannels = add( hDirACRend->hOutSetup.nchan_out_woLFE, hDirACRend->hOutSetup.num_lfe ); /* Note here that compared to decoder path, there is no separate channel ever for MASA ext rend path */ - FOR ( ch = 0; ch < outchannels; ch++ ) + FOR( ch = 0; ch < outchannels; ch++ ) { - IF ( GT_16( hDirACRend->hOutSetup.num_lfe, 0 ) && ( EQ_16(hDirACRend->hOutSetup.index_lfe[idx_lfe], ch )) ) + IF( GT_16( hDirACRend->hOutSetup.num_lfe, 0 ) && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) { /* No LFE for MASA rendering */ set32_fx( &( output_f_fx[ch][index_slot * hSpatParamRendCom->num_freq_bands] ), 0, hSpatParamRendCom->subframe_nbslots[subframe_idx] * hSpatParamRendCom->num_freq_bands ); - IF ( LT_16(idx_lfe, sub( hDirACRend->hOutSetup.num_lfe, 1 ) )) + IF( LT_16( idx_lfe, sub( hDirACRend->hOutSetup.num_lfe, 1 ) ) ) { idx_lfe++; } @@ -6242,7 +6304,7 @@ static void ivas_masa_ext_dirac_render_sf_fx( { /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */ - FOR ( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ ) + FOR( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ ) { RealBuffer_fx[i] = Cldfb_RealBuffer_fx[idx_in][i]; ImagBuffer_fx[i] = Cldfb_ImagBuffer_fx[idx_in][i]; @@ -6252,9 +6314,9 @@ static void ivas_masa_ext_dirac_render_sf_fx( } } - hMasaExtRend->cldfbSynRend[0]->Q_cldfb_state = sub(q_cldfb, 1); + hMasaExtRend->cldfbSynRend[0]->Q_cldfb_state = sub( q_cldfb, 1 ); } - hSpatParamRendCom->slots_rendered = add(hSpatParamRendCom->subframe_nbslots[subframe_idx], hSpatParamRendCom->slots_rendered); + hSpatParamRendCom->slots_rendered = add( hSpatParamRendCom->subframe_nbslots[subframe_idx], hSpatParamRendCom->slots_rendered ); hSpatParamRendCom->subframes_rendered++; pop_wmops(); @@ -6302,8 +6364,8 @@ void ivas_masa_ext_dirac_render( #else void ivas_masa_ext_dirac_render_fx( MASA_EXT_REND_HANDLE hMasaExtRend, /* i/o: MASA renderer structure */ - Word32 *output_f[], /* i/o: input/output signals in time domain */ - const Word16 num_subframes /* i : number of subframes to render */ + Word32 *output_f[], /* i/o: input/output signals in time domain */ + const Word16 num_subframes /* i : number of subframes to render */ ) { Word16 subframe_idx; @@ -6313,20 +6375,21 @@ void ivas_masa_ext_dirac_render_fx( hSpatParamRendCom = hMasaExtRend->hSpatParamRendCom; - n_samples_sf = i_mult(JBM_CLDFB_SLOTS_IN_SUBFRAME, hSpatParamRendCom->slot_size); + n_samples_sf = i_mult( JBM_CLDFB_SLOTS_IN_SUBFRAME, hSpatParamRendCom->slot_size ); - FOR ( n = 0; n < MAX_OUTPUT_CHANNELS; n++ ) + FOR( n = 0; n < MAX_OUTPUT_CHANNELS; n++ ) { output_f_local[n] = output_f[n]; } hSpatParamRendCom->subframes_rendered = hSpatParamRendCom->dirac_read_idx; - FOR ( subframe_idx = 0; subframe_idx < num_subframes; subframe_idx++ ) + FOR( subframe_idx = 0; subframe_idx < num_subframes; subframe_idx++ ) { - hSpatParamRendCom->slots_rendered = 0; move16(); + hSpatParamRendCom->slots_rendered = 0; + move16(); ivas_masa_ext_dirac_render_sf_fx( hMasaExtRend, output_f_local ); - FOR ( n = 0; n < MAX_OUTPUT_CHANNELS; n++ ) + FOR( n = 0; n < MAX_OUTPUT_CHANNELS; n++ ) { output_f_local[n] += n_samples_sf; } diff --git a/lib_rend/ivas_efap.c b/lib_rend/ivas_efap.c index c712da4b5..37be6a48a 100644 --- a/lib_rend/ivas_efap.c +++ b/lib_rend/ivas_efap.c @@ -70,25 +70,24 @@ #ifndef IVAS_FLOAT_FIXED -static ivas_error poly_init(EFAP *efap, const int16_t efip_flag); +static ivas_error poly_init( EFAP *efap, const int16_t efip_flag ); static ivas_error sphere_triangulation( const int16_t numSpk, EFAP_VERTEX_DATA *vtxData, EFAP_POLYSET_DATA *polyData, float ***dmTranspose, int16_t *numTot, const int16_t efip_flag ); static void initial_polyeder( EFAP_VERTEX_DATA *vtxData, EFAP_LS_TRIANGLE *triArray, int16_t *numTri, int16_t *vtxInHull ); static void add_ghost_speakers( EFAP_VERTEX *vertexArray, int16_t *numVtx, const int16_t efip_flag ); static void add_vertex_to_convex_hull( const EFAP_VERTEX_DATA *vtxData, const int16_t vtxIdx, int16_t *vtxInHull, EFAP_LS_TRIANGLE *triArray, int16_t *szTri ); -static void sort_vertices(const EFAP_VERTEX *vertexArray, const int16_t *numVtx, int16_t *order); -static void visible_edges(const EFAP_LS_TRIANGLE *triArray, const int16_t *visible, const int16_t numSurface, int16_t *numEdges, int16_t *edges); +static void sort_vertices( const EFAP_VERTEX *vertexArray, const int16_t *numVtx, int16_t *order ); +static void visible_edges( const EFAP_LS_TRIANGLE *triArray, const int16_t *visible, const int16_t numSurface, int16_t *numEdges, int16_t *edges ); #else -static ivas_error poly_init_fx(EFAP *efap, const Word16 efip_flag); +static ivas_error poly_init_fx( EFAP *efap, const Word16 efip_flag ); static ivas_error sphere_triangulation_fx( const Word16 numSpk, EFAP_VERTEX_DATA *vtxData, EFAP_POLYSET_DATA *polyData, Word32 ***dmTranspose, Word16 *numTot, const Word16 efip_flag ); static void initial_polyeder_fx( EFAP_VERTEX_DATA *vtxData, EFAP_LS_TRIANGLE *triArray, Word16 *numTri, Word16 *vtxInHull ); static void add_ghost_speakers_fx( EFAP_VERTEX *vertexArray, Word16 *numVtx, const Word16 efip_flag ); static void add_vertex_to_convex_hull_fx( const EFAP_VERTEX_DATA *vtxData, const Word16 vtxIdx, Word16 *vtxInHull, EFAP_LS_TRIANGLE *triArray, Word16 *szTri ); -static void sort_vertices_fx(const EFAP_VERTEX *vertexArray, const Word16 *numVtx, Word16 *order); -static void visible_edges_fx(const EFAP_LS_TRIANGLE *triArray, const Word16 *visible, const Word16 numSurface, Word16 *numEdges, Word16 *edges); +static void sort_vertices_fx( const EFAP_VERTEX *vertexArray, const Word16 *numVtx, Word16 *order ); +static void visible_edges_fx( const EFAP_LS_TRIANGLE *triArray, const Word16 *visible, const Word16 numSurface, Word16 *numEdges, Word16 *edges ); #endif - #ifndef IVAS_FLOAT_FIXED static void flip_plane( const EFAP_VERTEX *vtxArray, int16_t *surface, const float centroid[3] ); static void remap_ghosts( EFAP_VERTEX *vtxArray, EFAP_LS_TRIANGLE *triArray, int16_t numSpk, int16_t *numVertex, int16_t numTri, float **downmixMatrix ); @@ -111,10 +110,10 @@ static Word32 get_tri_gain_fx( const Word32 A[2], const Word32 B[2], const Word3 #ifndef IVAS_FLOAT_FIXED static void add_vertex( EFAP_VERTEX *vtxArray, const float azi, const float ele, const int16_t pos, const EFAP_VTX_DMX_TYPE ); -static void efap_sort_s(int16_t *x, int16_t *idx, const int16_t len); +static void efap_sort_s( int16_t *x, int16_t *idx, const int16_t len ); #else static void add_vertex_fx( EFAP_VERTEX *vtxArray, const Word32 azi, const Word32 ele, const Word16 pos, const EFAP_VTX_DMX_TYPE ); -static void efap_sort_s_fx(Word16 *x, Word16 *idx, const Word16 len); +static void efap_sort_s_fx( Word16 *x, Word16 *idx, const Word16 len ); #endif @@ -123,29 +122,28 @@ static float vertex_distance( const EFAP_VERTEX *vtxArray, const EFAP_LS_TRIANGL static float point_plane_distance( const float P1[3], const float P2[3], const float P3[3], const float X[3] ); static float point_poly_distance( const EFAP_POLYSET poly, const float X[3] ); static void efap_crossp( const float *v1, const float *v2, float *v ); -static int16_t find_int_in_tri(const EFAP_LS_TRIANGLE *tri, const int16_t n, const int16_t r, int16_t *pos); -static void remove_vertex(EFAP_VERTEX *vtxArray, const int16_t idx, const int16_t L); -static int16_t get_neighbours(const EFAP_LS_TRIANGLE *triArray, const int16_t vtxIdx, const int16_t numTri, int16_t *neighbours); +static int16_t find_int_in_tri( const EFAP_LS_TRIANGLE *tri, const int16_t n, const int16_t r, int16_t *pos ); +static void remove_vertex( EFAP_VERTEX *vtxArray, const int16_t idx, const int16_t L ); +static int16_t get_neighbours( const EFAP_LS_TRIANGLE *triArray, const int16_t vtxIdx, const int16_t numTri, int16_t *neighbours ); #else static Word32 vertex_distance_fx( const EFAP_VERTEX *vtxArray, const EFAP_LS_TRIANGLE tri, const Word16 vtxIdx ); static Word32 point_plane_distance_fx( const Word32 P1[3], const Word32 P2[3], const Word32 P3[3], const Word32 X[3] ); static Word32 point_poly_distance_fx( const EFAP_POLYSET poly, const Word32 X[3] ); static void efap_crossp_fx( const Word32 *v1, const Word32 *v2, Word32 *v ); -static Word16 find_int_in_tri_fx(const EFAP_LS_TRIANGLE *tri, const Word16 n, const Word16 r, Word16 *pos); -static void remove_vertex_fx(EFAP_VERTEX *vtxArray, const Word16 idx, const Word16 L); -static Word16 get_neighbours_fx(const EFAP_LS_TRIANGLE *triArray, const Word16 vtxIdx, const Word16 numTri, Word16 *neighbours); +static Word16 find_int_in_tri_fx( const EFAP_LS_TRIANGLE *tri, const Word16 n, const Word16 r, Word16 *pos ); +static void remove_vertex_fx( EFAP_VERTEX *vtxArray, const Word16 idx, const Word16 L ); +static Word16 get_neighbours_fx( const EFAP_LS_TRIANGLE *triArray, const Word16 vtxIdx, const Word16 numTri, Word16 *neighbours ); #endif - #ifndef IVAS_FLOAT_FIXED static void matrix_times_row( float mat[EFAP_MAX_SIZE_TMP_BUFF][EFAP_MAX_SIZE_TMP_BUFF], const float *vec, const int16_t L, float *out ); -static void tri_to_poly(const EFAP_VERTEX *vtxArray, const EFAP_LS_TRIANGLE *triArray, const int16_t numVtx, const int16_t numTri, int16_t sortedChan[EFAP_MAX_POLY_SET][EFAP_MAX_CHAN_NUM], int16_t *outLengthPS, int16_t outLengthSorted[EFAP_MAX_POLY_SET]); -static int16_t compare_poly(int16_t *old, int16_t lenOld, int16_t *new, int16_t lenNew); +static void tri_to_poly( const EFAP_VERTEX *vtxArray, const EFAP_LS_TRIANGLE *triArray, const int16_t numVtx, const int16_t numTri, int16_t sortedChan[EFAP_MAX_POLY_SET][EFAP_MAX_CHAN_NUM], int16_t *outLengthPS, int16_t outLengthSorted[EFAP_MAX_POLY_SET] ); +static int16_t compare_poly( int16_t *old, int16_t lenOld, int16_t *new, int16_t lenNew ); #else static void matrix_times_row_fx( Word32 mat[EFAP_MAX_SIZE_TMP_BUFF][EFAP_MAX_SIZE_TMP_BUFF], const Word32 *vec, const Word16 L, Word32 *out ); -static void tri_to_poly_fx(const EFAP_VERTEX *vtxArray, const EFAP_LS_TRIANGLE *triArray, const Word16 numVtx, const Word16 numTri, Word16 sortedChan[EFAP_MAX_POLY_SET][EFAP_MAX_CHAN_NUM], Word16 *outLengthPS, Word16 outLengthSorted[EFAP_MAX_POLY_SET]); -static Word16 compare_poly_fx(Word16 *old, Word16 lenOld, Word16 *new, Word16 lenNew); +static void tri_to_poly_fx( const EFAP_VERTEX *vtxArray, const EFAP_LS_TRIANGLE *triArray, const Word16 numVtx, const Word16 numTri, Word16 sortedChan[EFAP_MAX_POLY_SET][EFAP_MAX_CHAN_NUM], Word16 *outLengthPS, Word16 outLengthSorted[EFAP_MAX_POLY_SET] ); +static Word16 compare_poly_fx( Word16 *old, Word16 lenOld, Word16 *new, Word16 lenNew ); #endif @@ -177,11 +175,11 @@ static void sph2cart_fx( const Word32 azi, const Word32 ele, Word32 *pos ); *-------------------------------------------------------------------------*/ ivas_error efap_init_data_fx( - EFAP_HANDLE *hEFAPdata, /* i/o: handle for EFAP data structure that will be initialized */ + EFAP_HANDLE *hEFAPdata, /* i/o: handle for EFAP data structure that will be initialized */ const Word32 *speaker_node_azi_deg, /* i : vector of speaker node azimuths (positive left) (Q22) */ const Word32 *speaker_node_ele_deg, /* i : vector of speaker node elevations (positive up) (Q22) */ - const Word16 num_speaker_nodes, /* i : number of speaker nodes in the set */ - const Word16 efap_mode /* i : indicates whether EFAP or EFIP is used */ + const Word16 num_speaker_nodes, /* i : number of speaker nodes in the set */ + const Word16 efap_mode /* i : indicates whether EFAP or EFIP is used */ ) { /* Handle instance declaration */ @@ -234,10 +232,12 @@ ivas_error efap_init_data_fx( * Initialize values *-----------------------------------------------------------------*/ - efap->numSpk = num_speaker_nodes; move16(); + efap->numSpk = num_speaker_nodes; + move16(); /* The number of vertex is first set to the number of LS but will evolve further */ - efap->vtxData.numVtx = num_speaker_nodes; move16(); + efap->vtxData.numVtx = num_speaker_nodes; + move16(); /* Loudspeaker configuration */ mvl2l( speaker_node_azi_deg, efap->aziSpk, num_speaker_nodes ); @@ -262,11 +262,11 @@ ivas_error efap_init_data_fx( return error; } #else - /*-------------------------------------------------------------------------* - * efap_init_data() - * - * Wrap the internal functions to initialize the EFAP data structure - *-------------------------------------------------------------------------*/ +/*-------------------------------------------------------------------------* + * efap_init_data() + * + * Wrap the internal functions to initialize the EFAP data structure + *-------------------------------------------------------------------------*/ ivas_error efap_init_data( EFAP_HANDLE *hEFAPdata, /* i/o: handle for EFAP data structure that will be initialized */ const float *speaker_node_azi_deg, /* i : vector of speaker node azimuths (positive left) */ @@ -389,10 +389,12 @@ void efap_determine_gains_fx( IF( EQ_16( efap_mode, EFAP_MODE_EFAP ) ) { - normBuffer = 0; move16(); + normBuffer = 0; + move16(); FOR( j = 0; j < hEFAPdata->numSpk; ++j ) { - hEFAPdata->bufferShort_fx[j] = 0; move16(); + hEFAPdata->bufferShort_fx[j] = 0; + move16(); /* Multiplying by the downmixMatrix */ FOR( i = 0; i < hEFAPdata->vtxData.numVtx; ++i ) { @@ -400,7 +402,8 @@ void efap_determine_gains_fx( } normBuffer = L_add_sat( normBuffer, Mpy_32_32( hEFAPdata->bufferShort_fx[j], hEFAPdata->bufferShort_fx[j] ) ); // Q29 } - Word16 exp = 2; move16(); + Word16 exp = 2; + move16(); normBuffer = ISqrt32( normBuffer, &exp ); FOR( j = 0; j < hEFAPdata->numSpk; ++j ) @@ -411,10 +414,12 @@ void efap_determine_gains_fx( } ELSE { - normBuffer = 0; move16(); + normBuffer = 0; + move16(); FOR( j = 0; j < hEFAPdata->numSpk; ++j ) { - hEFAPdata->bufferShort_fx[j] = 0; move16(); + hEFAPdata->bufferShort_fx[j] = 0; + move16(); /* Multiplying by the downmixMatrix */ FOR( i = 0; i < hEFAPdata->vtxData.numVtx; ++i ) { @@ -422,12 +427,13 @@ void efap_determine_gains_fx( } normBuffer = L_add_sat( normBuffer, L_shr( hEFAPdata->bufferShort_fx[j], Q1 ) ); // Q29 } - Word16 exp = 2; move16(); + Word16 exp = 2; + move16(); normBuffer = Inv16( (Word16) L_shr( normBuffer, Q16 ), &exp ); FOR( j = 0; j < hEFAPdata->numSpk; ++j ) { - Word16 exp_temp = add(exp, 1); + Word16 exp_temp = add( exp, 1 ); hEFAPdata->bufferShort_fx[j] = Sqrt32( Mpy_32_16_1( hEFAPdata->bufferShort_fx[j], (Word16) normBuffer ), &exp_temp ); hEFAPdata->bufferShort_fx[j] = L_shl( hEFAPdata->bufferShort_fx[j], sub( exp_temp, 1 ) ); // Q30 } @@ -634,7 +640,7 @@ void efap_free_data( *-------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED static ivas_error poly_init_fx( - EFAP *efap, /* i/o: A pointer to a handle to efap instance */ + EFAP *efap, /* i/o: A pointer to a handle to efap instance */ const Word16 efip_flag /* i : flag to indicate whether initialization is for EFIP (used for ALLRAD) */ ) { @@ -667,7 +673,8 @@ static ivas_error poly_init_fx( IF( GT_32( efap->vtxData.vertexArray[n].ele, L_sub( Q22_90_DEG, 4 ) ) || LT_32( efap->vtxData.vertexArray[n].ele, L_sub( 4, Q22_90_DEG ) ) ) { - efap->vtxData.vertexArray[n].isNaN = 1; move16(); + efap->vtxData.vertexArray[n].isNaN = 1; + move16(); } } @@ -675,22 +682,28 @@ static ivas_error poly_init_fx( tri_to_poly_fx( efap->vtxData.vertexArray, efap->polyData.triArray, efap->vtxData.numVtx, efap->polyData.numTri, sortedChan, &lengthTri2PolyPS, lengthTri2PolySorted ); /* Completing the polyData Structure */ - finalLength = -1; move16(); + finalLength = -1; + move16(); FOR( n = 0; n < lengthTri2PolyPS; ++n ) { - m = add(finalLength, 1); + m = add( finalLength, 1 ); /* Complete the fields of the polygon */ FOR( j = 0; j < lengthTri2PolySorted[n]; ++j ) { - efap->polyData.polysetArray[m].chan[j] = sortedChan[n][j]; move16(); - efap->polyData.polysetArray[m].polyAzi[j] = efap->vtxData.vertexArray[sortedChan[n][j]].azi; move32(); - efap->polyData.polysetArray[m].polyEle[j] = efap->vtxData.vertexArray[sortedChan[n][j]].ele; move32(); - efap->polyData.polysetArray[m].isNaN[j] = efap->vtxData.vertexArray[sortedChan[n][j]].isNaN; move16(); + efap->polyData.polysetArray[m].chan[j] = sortedChan[n][j]; + move16(); + efap->polyData.polysetArray[m].polyAzi[j] = efap->vtxData.vertexArray[sortedChan[n][j]].azi; + move32(); + efap->polyData.polysetArray[m].polyEle[j] = efap->vtxData.vertexArray[sortedChan[n][j]].ele; + move32(); + efap->polyData.polysetArray[m].isNaN[j] = efap->vtxData.vertexArray[sortedChan[n][j]].isNaN; + move16(); } - efap->polyData.polysetArray[m].numChan = lengthTri2PolySorted[n]; move16(); + efap->polyData.polysetArray[m].numChan = lengthTri2PolySorted[n]; + move16(); /* In case tmpMax - tmpMin > 180, wrap polygon azimuth */ maximum_l( efap->polyData.polysetArray[m].polyAzi, lengthTri2PolySorted[n], &tmpMax ); @@ -724,7 +737,8 @@ static ivas_error poly_init_fx( finalLength = add( finalLength, 1 ); /* Updating the number of polygons */ - efap->polyData.numPoly = finalLength; move16(); + efap->polyData.numPoly = finalLength; + move16(); return error; @@ -835,12 +849,12 @@ static ivas_error poly_init( *-------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED static ivas_error sphere_triangulation_fx( - const Word16 numSpk, /* i : Number of speakers */ + const Word16 numSpk, /* i : Number of speakers */ EFAP_VERTEX_DATA *vtxData, /* i/o: Vertex data structure */ EFAP_POLYSET_DATA *polyData, /* o : Polygon data structure */ - Word32 ***dmTranspose_fx, /* o : Transpose of the downmix matrix */ - Word16 *numTot, /* o : Number of speakers (real + ghost) */ - const int16_t efip_flag /* i : flag to indicate whether initialization is for EFIP (used for ALLRAD) */ + Word32 ***dmTranspose_fx, /* o : Transpose of the downmix matrix */ + Word16 *numTot, /* o : Number of speakers (real + ghost) */ + const int16_t efip_flag /* i : flag to indicate whether initialization is for EFIP (used for ALLRAD) */ ) { int16_t i; @@ -880,19 +894,17 @@ static ivas_error sphere_triangulation_fx( /* Store the value of numVtx to be used for freeing later (numVtx will change after remap_ghosts() ) */ *numTot = vtxData->numVtx; - FOR( i = 0; i < vtxData->numVtx; i++ ) - { - IF( ( p_dmTranspose[i] = malloc( numSpk * sizeof( Word32 ) ) ) == NULL ) - { + FOR( i = 0; i < vtxData->numVtx; i++ ){ + IF( ( p_dmTranspose[i] = malloc( numSpk * sizeof( Word32 ) ) ) == NULL ){ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "EFAP: can not allocate memory for dmTranspose\n" ) ); - } - } - *dmTranspose_fx = (Word32 **) p_dmTranspose; +} +} +*dmTranspose_fx = (Word32 **) p_dmTranspose; - /* Remap Ghosts */ - remap_ghosts_fx( vtxData->vertexArray, polyData->triArray, numSpk, &vtxData->numVtx, polyData->numTri, *dmTranspose_fx ); +/* Remap Ghosts */ +remap_ghosts_fx( vtxData->vertexArray, polyData->triArray, numSpk, &vtxData->numVtx, polyData->numTri, *dmTranspose_fx ); - return IVAS_ERR_OK; +return IVAS_ERR_OK; } #else static ivas_error sphere_triangulation( @@ -1134,7 +1146,8 @@ static void initial_polyeder_fx( } /* 2. attempt to create a triangle with nonzero area */ - tmp = 0; move16(); + tmp = 0; + move16(); v_sub_fixed( vtxData->vertexArray[tetrahedron[1]].pos, vtxData->vertexArray[tetrahedron[0]].pos, tmp1, 3, 1 ); WHILE( LT_16( tetrahedron[2], numVtx ) ) { @@ -1405,19 +1418,23 @@ static void add_ghost_speakers_fx( vtxDmxType = EFAP_DMX_INTENSITY; numVertex = *numVtx; - maxAngle = 13421773; move32();//(1.f / 160.0f) in Q31 + maxAngle = 13421773; + move32(); //(1.f / 160.0f) in Q31 /* Extracting Azi and Ele for computation purposes */ FOR( i = 0; i < numVertex; ++i ) { - ele[i] = vertexArray[i].ele; move32(); + ele[i] = vertexArray[i].ele; + move32(); } /* ADD VOG IF NECESSERAY (i.e. if the elevation of the highest LS is < 90 deg) */ - a = 0; move16(); + a = 0; + move16(); maximum_l( ele, numVertex, &tmpEle ); - lengthVertGhst = 0; move16(); + lengthVertGhst = 0; + move16(); IF( LT_32( tmpEle, Q22_90_DEG ) ) { IF( efip_flag ) @@ -1459,7 +1476,8 @@ static void add_ghost_speakers_fx( } /* LIST ALL SURROUNDING loudspeakers */ - k = 0; move16(); + k = 0; + move16(); FOR( i = 0; i < numVertex; ++i ) { @@ -1470,21 +1488,22 @@ static void add_ghost_speakers_fx( } } - lengthHorGhst = 0; move16(); + lengthHorGhst = 0; + move16(); IF( EQ_16( k, 0 ) ) /* no speakers found: add a triangle of ghost speakers */ { - add_vertex_fx( vertexArray, 0, 0, add(numVertex, a), EFAP_DMX_INTENSITY ); - add_vertex_fx( vertexArray, Q22_120_DEG, 0, add(add(numVertex, a), 1), EFAP_DMX_INTENSITY ); - add_vertex_fx( vertexArray, Q22_240_DEG, 0, add(add(numVertex, a), 2), EFAP_DMX_INTENSITY ); - a = add(a, 3); - lengthHorGhst = add(lengthHorGhst, 3); + add_vertex_fx( vertexArray, 0, 0, add( numVertex, a ), EFAP_DMX_INTENSITY ); + add_vertex_fx( vertexArray, Q22_120_DEG, 0, add( add( numVertex, a ), 1 ), EFAP_DMX_INTENSITY ); + add_vertex_fx( vertexArray, Q22_240_DEG, 0, add( add( numVertex, a ), 2 ), EFAP_DMX_INTENSITY ); + a = add( a, 3 ); + lengthHorGhst = add( lengthHorGhst, 3 ); } ELSE IF( EQ_16( k, 1 ) ) /* only one speaker found: add two ghost speakers to complete a triangle */ { add_vertex_fx( vertexArray, L_add( tmpAzi[0], Q22_120_DEG ), 0, numVertex + a, EFAP_DMX_INTENSITY ); add_vertex_fx( vertexArray, L_add( tmpAzi[0], Q22_240_DEG ), 0, numVertex + a + 1, EFAP_DMX_INTENSITY ); - a = add(a, 2); - lengthHorGhst = add(lengthHorGhst, 2); + a = add( a, 2 ); + lengthHorGhst = add( lengthHorGhst, 2 ); } ELSE /* fill gaps greater than maxAngle */ { @@ -1549,8 +1568,8 @@ static void add_ghost_speakers_fx( #ifdef IVAS_FLOAT_FIXED static void sort_vertices_fx( const EFAP_VERTEX *vertexArray, /* i : Vertex array */ - const Word16 *numVtx, /* i : Size of vertex array */ - Word16 *order /* o : Original index positions */ + const Word16 *numVtx, /* i : Size of vertex array */ + Word16 *order /* o : Original index positions */ ) { Word16 tmpIdx[EFAP_MAX_SIZE_TMP_BUFF]; @@ -1706,7 +1725,8 @@ static void add_vertex_to_convex_hull_fx( Word16 surface[3]; Word32 numHullVtx; Word32 centroid[3]; - const Word32 threshold = -268; move32();// -1e-6f in Q28 + const Word32 threshold = -268; + move32(); // -1e-6f in Q28 Word32 tmpDist; EFAP_LS_TRIANGLE triArrayNew[EFAP_MAX_POLY_SET]; @@ -1717,7 +1737,8 @@ static void add_vertex_to_convex_hull_fx( } /* Compute the centroid of the current convex hull */ - numHullVtx = 0; move32(); + numHullVtx = 0; + move32(); set32_fx( centroid, 0, 3 ); FOR( i = 0; i < vtxData->numVtx; i++ ) { @@ -1740,15 +1761,18 @@ static void add_vertex_to_convex_hull_fx( centroid[2] = L_shl( centroid[2], 4 ); /* Processing */ - k = 0; move16(); - l = 0; move16(); + k = 0; + move16(); + l = 0; + move16(); FOR( i = 0; i < *szTri; ++i ) { tmpDist = vertex_distance_fx( vtxData->vertexArray, triArray[i], vtxIdx ); // Q28 IF( GT_32( tmpDist, threshold ) ) { - visible[k] = i; move16(); + visible[k] = i; + move16(); ++k; } ELSE @@ -1762,9 +1786,12 @@ static void add_vertex_to_convex_hull_fx( FOR( i = 0; i < numEdges[0]; i += 2 ) { - surface[0] = edges[i]; move16(); - surface[1] = edges[i + 1]; move16(); - surface[2] = vtxIdx; move16(); + surface[0] = edges[i]; + move16(); + surface[1] = edges[i + 1]; + move16(); + surface[2] = vtxIdx; + move16(); flip_plane_fx( vtxData->vertexArray, surface, centroid ); @@ -1780,7 +1807,8 @@ static void add_vertex_to_convex_hull_fx( *szTri = l; /* Flag the vertex as added to the hull */ - vtxInHull[vtxIdx] = 1; move16(); + vtxInHull[vtxIdx] = 1; + move16(); return; } #endif @@ -1817,28 +1845,34 @@ static void visible_edges_fx( /* Finding the max vertex */ FOR( i = 0; i < numSurface; ++i ) { - tmpMax[i] = triArray[visible[i]].LS[0]; move16(); + tmpMax[i] = triArray[visible[i]].LS[0]; + move16(); FOR( j = 1; j < 3; ++j ) { IF( tmpMax[i] < triArray[visible[i]].LS[j] ) { - tmpMax[i] = triArray[visible[i]].LS[j]; move16(); + tmpMax[i] = triArray[visible[i]].LS[j]; + move16(); } } } maxVertex = tmpMax[maximum_s( tmpMax, numSurface, NULL )]; FOR( i = 0; i < numSurface; ++i ) { - tmpSurface[0] = triArray[visible[i]].LS[0]; move16(); - tmpSurface[1] = triArray[visible[i]].LS[1]; move16(); - tmpSurface[2] = triArray[visible[i]].LS[2]; move16(); - tmpSurface[3] = triArray[visible[i]].LS[0]; move16(); + tmpSurface[0] = triArray[visible[i]].LS[0]; + move16(); + tmpSurface[1] = triArray[visible[i]].LS[1]; + move16(); + tmpSurface[2] = triArray[visible[i]].LS[2]; + move16(); + tmpSurface[3] = triArray[visible[i]].LS[0]; + move16(); FOR( j = 0; j < 3; ++j ) { a = tmpSurface[j]; b = tmpSurface[j + 1]; - counter[a][b] = add(counter[a][b], 1); + counter[a][b] = add( counter[a][b], 1 ); counterTranspose[b][a] = counter[a][b]; } } @@ -1847,7 +1881,7 @@ static void visible_edges_fx( { FOR( j = 0; j < maxVertex + 1; ++j ) { - counter[i][j] = add(counterTranspose[i][j], counterTranspose[j][i]); + counter[i][j] = add( counterTranspose[i][j], counterTranspose[j][i] ); } } @@ -1860,15 +1894,18 @@ static void visible_edges_fx( { IF( counter[a][b] == 1 ) { - edges[k] = a; move16(); - edges[k + 1] = b; move16(); - k = add(k, 2); + edges[k] = a; + move16(); + edges[k + 1] = b; + move16(); + k = add( k, 2 ); } } } /* Outputs */ - *numEdges = k; move16(); + *numEdges = k; + move16(); return; } @@ -2201,7 +2238,8 @@ static void remap_ghosts_fx( Word32 tmpMat[EFAP_MAX_SIZE_TMP_BUFF][EFAP_MAX_SIZE_TMP_BUFF]; Word32 tmpNewMat[EFAP_MAX_SIZE_TMP_BUFF][EFAP_MAX_SIZE_TMP_BUFF]; Word32 tmpDist; - const Word32 thresh = 214748; move32();// 1e-4f in Q31 + const Word32 thresh = 214748; + move32(); // 1e-4f in Q31 set32_fx( tmpVec, 0, EFAP_MAX_SIZE_TMP_BUFF ); set32_fx( tmpVec2, 0, EFAP_MAX_SIZE_TMP_BUFF ); @@ -2210,7 +2248,7 @@ static void remap_ghosts_fx( FOR( g = numVtx - 1; g > numSpk - 1; --g ) { /* find(triangle_mat == ghost, 1, 'first') */ - IF( EQ_16(find_int_in_tri_fx( triArray, g, numTri, posFound ), 0 ) ) + IF( EQ_16( find_int_in_tri_fx( triArray, g, numTri, posFound ), 0 ) ) { remove_vertex_fx( vtxArray, g, numVtx ); --numVtx; @@ -2232,7 +2270,7 @@ static void remap_ghosts_fx( } /* Final number of LS (real + ghosts) */ - numTot = add(numSpk, numGhst); + numTot = add( numSpk, numGhst ); /* Initializing tmpMat as the identity matrix */ FOR( i = 0; i < numTot; ++i ) @@ -2301,7 +2339,8 @@ static void remap_ghosts_fx( } ELSE { - Word16 exp = 0; move16(); + Word16 exp = 0; + move16(); Word32 tmp_sqrt = Sqrt32( tmpNewMat[j][i], &exp ); tmp_sqrt = L_shl( tmp_sqrt, exp ); downmixMatrixTranspose[j][i] = tmp_sqrt; @@ -2326,7 +2365,8 @@ static void remap_ghosts_fx( } ELSE { - Word16 exp = 0; move16(); + Word16 exp = 0; + move16(); Word32 tmp_sqrt = Sqrt32( tmpNewMat[j][i], &exp ); tmp_sqrt = L_shl( tmp_sqrt, exp ); downmixMatrixTranspose[j][i] = tmp_sqrt; @@ -2337,7 +2377,8 @@ static void remap_ghosts_fx( } /* Output */ - *numVertex = numTot; move16(); + *numVertex = numTot; + move16(); return; } @@ -2509,7 +2550,8 @@ static void efap_panning_fx( /* Computing the norm of the tmp buffer */ normTmpBuff = dotp_fixed( tmpBuff, tmpBuff, numChan ); - Word16 exp = 0; move16(); + Word16 exp = 0; + move16(); normTmpBuff = ISqrt32( normTmpBuff, &exp ); /* Updating the buffer structure */ @@ -2699,9 +2741,10 @@ static Word32 get_tri_gain_fx( tmpDot1 = dotp_fixed( tmpN, tmpSub1, 2 ); // Q13 - Word16 exp = Q13; move16(); + Word16 exp = Q13; + move16(); Word32 inv_tmpDot2 = L_shl( tmpDot1, norm_l( tmpDot1 ) ); - exp = sub(exp, norm_l( tmpDot1 )); + exp = sub( exp, norm_l( tmpDot1 ) ); Word16 inv_tmpDot1 = Inv16( (Word16) L_shr( inv_tmpDot2, Q16 ), &exp ); v_multc_fixed( tmpN, L_shl( inv_tmpDot1, Q16 + exp ), N, 2 ); @@ -2711,7 +2754,8 @@ static Word32 get_tri_gain_fx( /* Set gains <= -60dB to 0 to avoid problems in SVD */ IF( LT_32( L_abs( gain ), 1 ) ) { - gain = 0; move32(); + gain = 0; + move32(); } return gain; // Q18 } @@ -2808,14 +2852,16 @@ static void add_vertex_fx( /* IdxEleTmp */ tmp = L_abs( vtxArray[pos].ele ); - idxEleTmp = tmp; move16(); + idxEleTmp = tmp; + move16(); idxEleTmp = L_sub( Q22_90_DEG, idxEleTmp ); /* Final Idx */ vtxArray[pos].idx = add( (Word16) idxAziTmp, i_mult( 181, (Word16) L_shr( idxEleTmp, Q22 ) ) ); /* Setting the nan flag to 0 */ - vtxArray[pos].isNaN = 0; move16(); + vtxArray[pos].isNaN = 0; + move16(); /* Set the default downmix type */ vtxArray[pos].dmxType = dmxType; @@ -3043,10 +3089,10 @@ static float point_plane_distance( *-------------------------------------------------------------------------*/ static Word32 point_plane_distance_fx( // returns output in Q28 - const Word32 P1[3], /* i : First point of the triangle that defines the planes */ - const Word32 P2[3], /* i : Second point of the triangle */ - const Word32 P3[3], /* i : Third point of the triangle */ - const Word32 X[3] /* i : The point of interest */ + const Word32 P1[3], /* i : First point of the triangle that defines the planes */ + const Word32 P2[3], /* i : Second point of the triangle */ + const Word32 P3[3], /* i : Third point of the triangle */ + const Word32 X[3] /* i : The point of interest */ ) { Word32 tmpCross1[3], tmpCross2[3]; @@ -3072,7 +3118,8 @@ static Word32 point_plane_distance_fx( // returns output in Q28 /* Dot Product */ tmpNorm = dotp_fixed( resultCross, resultCross, 3 ); // Q27 - Word16 exp = 4; move16(); + Word16 exp = 4; + move16(); tmpNorm = ISqrt32( tmpNorm, &exp ); // Q29 v_sub_fixed( X, P1, tmpDot1, 3, 1 ); // Q30 v_multc_fixed( resultCross, tmpNorm, tmpDot2, 3 ); // Q29 - exp @@ -3129,9 +3176,9 @@ static void efap_crossp_fx( #ifdef IVAS_FLOAT_FIXED static Word16 find_int_in_tri_fx( const EFAP_LS_TRIANGLE *tri, /* i : Triangle array */ - const Word16 n, /* i : The integer to find */ - const Word16 r, /* i : Number of rows */ - Word16 *pos /* o : Position of the integer */ + const Word16 n, /* i : The integer to find */ + const Word16 r, /* i : Number of rows */ + Word16 *pos /* o : Position of the integer */ ) { Word16 i, j; @@ -3189,8 +3236,8 @@ static int16_t find_int_in_tri( #ifdef IVAS_FLOAT_FIXED static void remove_vertex_fx( EFAP_VERTEX *vtxArray, /* i : Vertex array */ - const Word16 idx, /* i : Index of the vertex to remove */ - const Word16 L /* i : Length of the Vertex array */ + const Word16 idx, /* i : Index of the vertex to remove */ + const Word16 L /* i : Length of the Vertex array */ ) { Word16 i; @@ -3240,9 +3287,9 @@ static void remove_vertex( #ifdef IVAS_FLOAT_FIXED static Word16 get_neighbours_fx( const EFAP_LS_TRIANGLE *triArray, /* i : Triangle array */ - const Word16 vtxIdx, /* i : Index of the vertex */ - const Word16 numTri, /* i : Number of Triangles */ - Word16 *neighbours /* o : Output vector */ + const Word16 vtxIdx, /* i : Index of the vertex */ + const Word16 numTri, /* i : Number of Triangles */ + Word16 *neighbours /* o : Output vector */ ) { Word16 i, j, k; @@ -3257,10 +3304,11 @@ static Word16 get_neighbours_fx( mvs2s( triArray[i].LS, tmpTriArray[i].LS, 3 ); } - k = 0; move16(); + k = 0; + move16(); WHILE( 1 ) { - IF( EQ_16(find_int_in_tri_fx( tmpTriArray, vtxIdx, numTri, tmpPos ), 0 ) ) + IF( EQ_16( find_int_in_tri_fx( tmpTriArray, vtxIdx, numTri, tmpPos ), 0 ) ) { BREAK; } @@ -3284,7 +3332,8 @@ static Word16 get_neighbours_fx( /* Creating the output vector, by eliminating redundancies and also deleting the indice == vtxIdx*/ neighbours[0] = tmpNeighbours[0]; - j = 1; move16(); + j = 1; + move16(); FOR( i = 1; i < k; ++i ) { @@ -3424,8 +3473,8 @@ static void matrix_times_row_fx( *-------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED static void tri_to_poly_fx( - const EFAP_VERTEX *vtxArray, /* i : Vertex array */ - const EFAP_LS_TRIANGLE *triArray, /* i : Triangle array */ + const EFAP_VERTEX *vtxArray, /* i : Vertex array */ + const EFAP_LS_TRIANGLE *triArray, /* i : Triangle array */ const Word16 numVtx, /* i : Number of vertices */ const Word16 numTri, /* i : Number of triangles */ Word16 sortedChan[EFAP_MAX_POLY_SET][EFAP_MAX_CHAN_NUM], /* o : The matrix that will contain the sorted channels */ @@ -3446,12 +3495,14 @@ static void tri_to_poly_fx( Word32 dist; - lenPolySet = 0; move16(); + lenPolySet = 0; + move16(); /* Sorting the polygons */ FOR( i = 0; i < numTri; ++i ) { /* search for coplanar vertices and add them to the polygon */ - lenPoly = 0; move16(); + lenPoly = 0; + move16(); FOR( j = 0; j < numVtx; ++j ) { dist = L_abs( point_plane_distance_fx( @@ -3469,8 +3520,10 @@ static void tri_to_poly_fx( } /* search existing polygons to determine whether the new one already exists/is a subset or is a superset */ - found = 0; move16(); - replaceIdx = -1; move16(); + found = 0; + move16(); + replaceIdx = -1; + move16(); FOR( j = 0; j < lenPolySet; ++j ) { found = compare_poly_fx( sortedChan[j], sortedLengths[j], poly, lenPoly ); @@ -3509,7 +3562,8 @@ static void tri_to_poly_fx( } /* Output */ - *outLengthPS = lenPolySet; move16(); + *outLengthPS = lenPolySet; + move16(); mvs2s( sortedLengths, outLengthSorted, EFAP_MAX_POLY_SET ); return; } @@ -3623,7 +3677,8 @@ static Word16 compare_poly_fx( Word16 i, j; Word16 count; - count = 0; move16(); + count = 0; + move16(); FOR( i = 0; i < lenOld; ++i ) { @@ -3830,7 +3885,8 @@ static void sort_channels_vertex_fx( /* First Base Vector */ v_sub_fixed( P2, P1, tmpU, 3, 1 ); // tmpU Q30 - Word16 exp1 = 2; move16(); + Word16 exp1 = 2; + move16(); normU = ISqrt32( dotp_fixed( tmpU, tmpU, 3 ), &exp1 ); // normU = L_shl_sat( normU, exp ); //normU Q31 v_multc_fixed( tmpU, normU, U, 3 ); // U Q30 - exp1 @@ -3845,7 +3901,8 @@ static void sort_channels_vertex_fx( } v_sub_fixed( tmpV1, tmpV2, tmpV3, 3, 0 ); // tmpV3 Q30 - Word16 exp2 = 2; move16(); + Word16 exp2 = 2; + move16(); normV = ISqrt32( dotp_fixed( tmpV3, tmpV3, 3 ), &exp2 ); v_multc_fixed( tmpV3, normV, V, 3 ); // V Q30 - exp2 @@ -4003,7 +4060,8 @@ static Word16 get_poly_num_fx( Word32 dist_tmp; Word32 pos[3]; - num_poly = 0; move16(); + num_poly = 0; + move16(); sph2cart_fx( P[0], P[1], &pos[0] ); @@ -4032,8 +4090,10 @@ static Word16 get_poly_num_fx( } /* select the polygon with the smallest distance */ - found_poly = poly_tmp[0]; move16(); - dist_tmp = poly_dist[0]; move16(); + found_poly = poly_tmp[0]; + move16(); + dist_tmp = poly_dist[0]; + move16(); FOR( i = 1; i < num_poly; i++ ) { IF( LT_32( poly_dist[i], dist_tmp ) ) @@ -4125,8 +4185,8 @@ static int16_t in_poly( *-------------------------------------------------------------------------*/ static Word16 in_poly_fx( /* Angles are in Q22 */ - const Word32 P[2], /* i : Azimuth and elevation of the point */ - const EFAP_POLYSET poly /* i : Polyset struct */ + const Word32 P[2], /* i : Azimuth and elevation of the point */ + const EFAP_POLYSET poly /* i : Polyset struct */ ) { Word16 n; @@ -4147,11 +4207,13 @@ static Word16 in_poly_fx( /* Angles are in Q22 */ IF( poly.isNaN[0] ) { - A[0] = P[0]; move32(); + A[0] = P[0]; + move32(); } ELSE { - A[0] = poly.polyAzi[0]; move32(); + A[0] = poly.polyAzi[0]; + move32(); } A[1] = poly.polyEle[0]; @@ -4306,14 +4368,16 @@ static Word16 in_tri_fx( { FOR( Word32 j = 0; j < 2; j++ ) { - matInv_exp[i][j] = 31; move16(); + matInv_exp[i][j] = 31; + move16(); IF( NE_32( matInv[i][j], 0 ) ) { matInv_exp[i][j] = norm_l( matInv[i][j] ); } } matInv_exp_final[i] = s_min( matInv_exp[i][0], matInv_exp[i][1] ); - P_minus_A_exp[i] = 31; move16(); + P_minus_A_exp[i] = 31; + move16(); IF( NE_32( P_minus_A[i], 0 ) ) { P_minus_A_exp[i] = norm_l( P_minus_A[i] ); @@ -4414,4 +4478,4 @@ static void sph2cart_fx( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_rend/ivas_limiter.c b/lib_rend/ivas_limiter.c index a6dae2fcc..e7b2153dc 100644 --- a/lib_rend/ivas_limiter.c +++ b/lib_rend/ivas_limiter.c @@ -38,56 +38,216 @@ #include "wmc_auto.h" #include #ifdef IVAS_FLOAT_FIXED -#define ATTACK_CNST_48k (2106670080) //Q31 +#define ATTACK_CNST_48k ( 2106670080 ) // Q31 #define ATTACK_CNST_32k ( 2086555136 ) // Q31 #define ATTACK_CNST_16k ( 2027355264 ) // Q31 #define ATTACK_CNST_8k ( 1913946752 ) // Q31 #endif -Word32 release_cnst_table[201] = //Q31 -{ - 2106670080, - 2107727232, 2108757120, 2109760640, 2110738432, 2111691008, - 2112619136, 2113523328, 2114404352, 2115262592, 2116098816, - 2116913408, 2117707136, 2118480256, 2119233536, 2119967360, - 2120682240, 2121378688, 2122057088, 2122717952, 2123361792, - 2123988992, 2124599936, 2125195136, 2125774848, 2126339584, - 2126889728, 2127425536, 2127947520, 2128456064, 2128951296, - 2129433856, 2129903744, 2130361600, 2130807424, 2131241728, - 2131664768, 2132076928, 2132478208, 2132869248, 2133250048, - 2133620992, 2133982208, 2134334080, 2134676864, 2135010688, - 2135335936, 2135652608, 2135961088, 2136261504, 2136554112, - 2136839168, 2137116800, 2137387136, 2137650560, 2137907072, - 2138156928, 2138400256, 2138637184, 2138867968, 2139092864, - 2139311744, 2139524992, 2139732736, 2139934976, 2140131968, - 2140323840, 2140510720, 2140692736, 2140870016, 2141042688, - 2141210752, 2141374592, 2141534080, 2141689344, 2141840640, - 2141987968, 2142131456, 2142271232, 2142407424, 2142539904, - 2142669056, 2142794752, 2142917248, 2143036544, 2143152640, - 2143265792, 2143375872, 2143483264, 2143587712, 2143689472, - 2143788544, 2143885056, 2143979136, 2144070656, 2144159872, - 2144246656, 2144331264, 2144413568, 2144493824, 2144571904, - 2144647936, 2144722048, 2144794240, 2144864512, 2144932864, - 2144999552, 2145064448, 2145127680, 2145189248, 2145249152, - 2145307520, 2145364480, 2145419776, 2145473792, 2145526272, - 2145577472, 2145627264, 2145675776, 2145723008, 2145768960, - 2145813760, 2145857408, 2145899904, 2145941376, 2145981696, - 2146020864, 2146059136, 2146096384, 2146132608, 2146167936, - 2146202368, 2146235776, 2146268416, 2146300160, 2146331136, - 2146361216, 2146390528, 2146419200, 2146446976, 2146474112, - 2146500480, 2146526208, 2146551168, 2146575488, 2146599296, - 2146622464, 2146644864, 2146666880, 2146688128, 2146708992, - 2146729216, 2146748928, 2146768128, 2146786816, 2146805120, - 2146822784, 2146840064, 2146856960, 2146873344, 2146889216, - 2146904832, 2146919936, 2146934656, 2146948992, 2146962944, - 2146976640, 2146989824, 2147002752, 2147015296, 2147027584, - 2147039488, 2147051136, 2147062400, 2147073408, 2147084160, - 2147094528, 2147104768, 2147114624, 2147124352, 2147133696, - 2147142912, 2147151744, 2147160448, 2147168896, 2147177088, - 2147185152, 2147192960, 2147200512, 2147207936, 2147215104, - 2147222144, 2147229056, 2147235712, 2147242112, 2147248384, - 2147254656, 2147260544, 2147266432, 2147272064, 2147277568, - -}; +Word32 release_cnst_table[201] = // Q31 + { + 2106670080, + 2107727232, + 2108757120, + 2109760640, + 2110738432, + 2111691008, + 2112619136, + 2113523328, + 2114404352, + 2115262592, + 2116098816, + 2116913408, + 2117707136, + 2118480256, + 2119233536, + 2119967360, + 2120682240, + 2121378688, + 2122057088, + 2122717952, + 2123361792, + 2123988992, + 2124599936, + 2125195136, + 2125774848, + 2126339584, + 2126889728, + 2127425536, + 2127947520, + 2128456064, + 2128951296, + 2129433856, + 2129903744, + 2130361600, + 2130807424, + 2131241728, + 2131664768, + 2132076928, + 2132478208, + 2132869248, + 2133250048, + 2133620992, + 2133982208, + 2134334080, + 2134676864, + 2135010688, + 2135335936, + 2135652608, + 2135961088, + 2136261504, + 2136554112, + 2136839168, + 2137116800, + 2137387136, + 2137650560, + 2137907072, + 2138156928, + 2138400256, + 2138637184, + 2138867968, + 2139092864, + 2139311744, + 2139524992, + 2139732736, + 2139934976, + 2140131968, + 2140323840, + 2140510720, + 2140692736, + 2140870016, + 2141042688, + 2141210752, + 2141374592, + 2141534080, + 2141689344, + 2141840640, + 2141987968, + 2142131456, + 2142271232, + 2142407424, + 2142539904, + 2142669056, + 2142794752, + 2142917248, + 2143036544, + 2143152640, + 2143265792, + 2143375872, + 2143483264, + 2143587712, + 2143689472, + 2143788544, + 2143885056, + 2143979136, + 2144070656, + 2144159872, + 2144246656, + 2144331264, + 2144413568, + 2144493824, + 2144571904, + 2144647936, + 2144722048, + 2144794240, + 2144864512, + 2144932864, + 2144999552, + 2145064448, + 2145127680, + 2145189248, + 2145249152, + 2145307520, + 2145364480, + 2145419776, + 2145473792, + 2145526272, + 2145577472, + 2145627264, + 2145675776, + 2145723008, + 2145768960, + 2145813760, + 2145857408, + 2145899904, + 2145941376, + 2145981696, + 2146020864, + 2146059136, + 2146096384, + 2146132608, + 2146167936, + 2146202368, + 2146235776, + 2146268416, + 2146300160, + 2146331136, + 2146361216, + 2146390528, + 2146419200, + 2146446976, + 2146474112, + 2146500480, + 2146526208, + 2146551168, + 2146575488, + 2146599296, + 2146622464, + 2146644864, + 2146666880, + 2146688128, + 2146708992, + 2146729216, + 2146748928, + 2146768128, + 2146786816, + 2146805120, + 2146822784, + 2146840064, + 2146856960, + 2146873344, + 2146889216, + 2146904832, + 2146919936, + 2146934656, + 2146948992, + 2146962944, + 2146976640, + 2146989824, + 2147002752, + 2147015296, + 2147027584, + 2147039488, + 2147051136, + 2147062400, + 2147073408, + 2147084160, + 2147094528, + 2147104768, + 2147114624, + 2147124352, + 2147133696, + 2147142912, + 2147151744, + 2147160448, + 2147168896, + 2147177088, + 2147185152, + 2147192960, + 2147200512, + 2147207936, + 2147215104, + 2147222144, + 2147229056, + 2147235712, + 2147242112, + 2147248384, + 2147254656, + 2147260544, + 2147266432, + 2147272064, + 2147277568, + + }; /*-------------------------------------------------------------------* * detect_strong_saturations() * @@ -152,10 +312,10 @@ static int16_t detect_strong_saturations( /*! r: apply_strong_limiting flag */ static Word16 detect_strong_saturations_fx( - const Word16 BER_detect, /* i : BER detect flag */ + const Word16 BER_detect, /* i : BER detect flag */ Word16 *strong_saturation_cnt, /* i/o: counter of strong saturations */ - const Word32 max_val, /* i : maximum absolute value */ - Word32 *frame_gain, /* i/o: frame gain value */ + const Word32 max_val, /* i : maximum absolute value */ + Word32 *frame_gain, /* i/o: frame gain value */ Word16 q_factor /*Q factor of the output samples*/ ) { @@ -163,9 +323,9 @@ static Word16 detect_strong_saturations_fx( Word64 compare_max_value_Mul_3, compare_max_value_Mul_10; apply_strong_limiting = 0; - compare_max_value_Mul_3 = W_shl(98187,q_factor); // 3 * IVAS_LIMITER_THRESHOLD - compare_max_value_Mul_10 = W_shl( 327290, q_factor );//10 * IVAS_LIMITER_THRESHOLD - IF ( BER_detect ) + compare_max_value_Mul_3 = W_shl( 98187, q_factor ); // 3 * IVAS_LIMITER_THRESHOLD + compare_max_value_Mul_10 = W_shl( 327290, q_factor ); // 10 * IVAS_LIMITER_THRESHOLD + IF( BER_detect ) { *strong_saturation_cnt = 50; apply_strong_limiting = 1; @@ -258,7 +418,7 @@ ivas_error ivas_limiter_open( attack_cnst_fx = ATTACK_CNST_8k; BREAK; default: - assert(0); + assert( 0 ); } hLimiter->attack_constant_fx = attack_cnst_fx; @@ -334,12 +494,12 @@ void ivas_limiter_close( IVAS_LIMITER_HANDLE *phLimiter /* i/o: pointer to limiter handle, can be NULL */ ) { - IF ( phLimiter == NULL || *phLimiter == NULL ) + IF( phLimiter == NULL || *phLimiter == NULL ) { return; } - //free( ( *phLimiter )->channel_ptrs ); + // free( ( *phLimiter )->channel_ptrs ); free( ( *phLimiter )->channel_ptrs_fx ); free( *phLimiter ); *phLimiter = NULL; @@ -378,19 +538,18 @@ void ivas_limiter_close( *-------------------------------------------------------------------*/ void ivas_limiter_dec_fx( - IVAS_LIMITER_HANDLE hLimiter, /* i/o: limiter struct handle */ + IVAS_LIMITER_HANDLE hLimiter, /* i/o: limiter struct handle */ Word32 *output[MAX_OUTPUT_CHANNELS], /* i/o: input/output buffer */ - const Word16 num_channels, /* i : number of channels to be processed */ - const Word16 output_frame, /* i : number of samples per channel in the buffer */ + const Word16 num_channels, /* i : number of channels to be processed */ + const Word16 output_frame, /* i : number of samples per channel in the buffer */ const Word16 BER_detect, /* i : BER detect flag */ - Word16 q_factor -) + Word16 q_factor ) { Word16 c; Word32 **channels; /* return early if given bad parameters */ - IF ( hLimiter == NULL || output == NULL || output_frame <= 0 ) + IF( hLimiter == NULL || output == NULL || output_frame <= 0 ) { return; } @@ -400,7 +559,7 @@ void ivas_limiter_dec_fx( hLimiter->num_channels = min( num_channels, hLimiter->max_num_channels ); channels = hLimiter->channel_ptrs_fx; - FOR ( c = 0; c < num_channels; ++c ) + FOR( c = 0; c < num_channels; ++c ) { channels[c] = output[c]; } @@ -461,8 +620,8 @@ void ivas_limiter_dec( void limiter_process_fx( IVAS_LIMITER_HANDLE hLimiter, /* i/o: limiter struct handle */ - const Word16 output_frame, /* i : number of samples to be processed per channel in the I/O buffer */ - const Word32 threshold, /* i : signal amplitude above which limiting starts to be applied */ + const Word16 output_frame, /* i : number of samples to be processed per channel in the I/O buffer */ + const Word32 threshold, /* i : signal amplitude above which limiting starts to be applied */ const Word16 BER_detect, /* i : BER detect flag */ Word16 *strong_saturation_cnt, /* i/o: counter of strong saturations (can be NULL) */ Word16 q_factor /*Q factor of output samples*/ @@ -479,7 +638,7 @@ void limiter_process_fx( Word32 div32, gain, frame_gain, attack_constant; /* return early if given nonsensical values */ - IF ( hLimiter == NULL || output_frame <= 0 ) + IF( hLimiter == NULL || output_frame <= 0 ) { return; } @@ -490,7 +649,7 @@ void limiter_process_fx( gain = hLimiter->gain_fx; output = hLimiter->channel_ptrs_fx; num_channels = hLimiter->num_channels; - //sampling_rate = hLimiter->sampling_rate; + // sampling_rate = hLimiter->sampling_rate; attack_constant = hLimiter->attack_constant_fx; /*-----------------------------------------------------------------* * Find highest absolute peak sample value @@ -498,12 +657,12 @@ void limiter_process_fx( max_val = 0; - FOR ( i = 0; i < output_frame; i++ ) + FOR( i = 0; i < output_frame; i++ ) { FOR( c = 0; c < num_channels; c++ ) { tmp = L_abs( output[c][i] ); - IF ( GT_32(tmp , max_val) ) + IF( GT_32( tmp, max_val ) ) { max_val = tmp; } @@ -540,11 +699,11 @@ void limiter_process_fx( releaseHeuristic = hLimiter->release_heuristic_fx; q_fact_gain = Q30; - IF (GT_32( max_val , threshold) ) + IF( GT_32( max_val, threshold ) ) { - frame_gain = L_shl(divide3232( threshold, max_val ),15);//to q30 - releaseHeuristic = min( ONE_IN_Q30, L_add( releaseHeuristic, releaseHeuristic_cnst ) );// releaseHeuristic_cnst is Q30 of ( 4.f * output_frame / sampling_rate ) - // release_constant = powf( 0.01f, 1.0f / ( 0.005f * powf( 200.f, .08 ) * sampling_rate ) ); + frame_gain = L_shl( divide3232( threshold, max_val ), 15 ); // to q30 + releaseHeuristic = min( ONE_IN_Q30, L_add( releaseHeuristic, releaseHeuristic_cnst ) ); // releaseHeuristic_cnst is Q30 of ( 4.f * output_frame / sampling_rate ) + // release_constant = powf( 0.01f, 1.0f / ( 0.005f * powf( 200.f, .08 ) * sampling_rate ) ); /* Unoptimized code for reference */ /* releaseHeuristic = min( 1.f, releaseHeuristic + ( (float) 2.f * output_frame / sampling_rate / adaptiveReleaseWindowLengthInSeconds ) ); * ^ @@ -553,7 +712,7 @@ void limiter_process_fx( } ELSE { - releaseHeuristic = max( 0, L_sub( releaseHeuristic, releaseHeuristic_cnst_2 ) );//releaseHeuristic_cnst_2 is Q30 of output_frame / sampling_rate ) + releaseHeuristic = max( 0, L_sub( releaseHeuristic, releaseHeuristic_cnst_2 ) ); // releaseHeuristic_cnst_2 is Q30 of output_frame / sampling_rate ) /* Unoptimized code for reference */ /*releaseHeuristic = max( 0.f, releaseHeuristic - ( (float) 0.5f * output_frame / sampling_rate / adaptiveReleaseWindowLengthInSeconds ) ); * ^ @@ -561,14 +720,13 @@ void limiter_process_fx( */ /* No samples above threshold and gain from previous frame is already 1.f, * therefore gain == 1.f for the entire frame. Skip processing. */ - IF ( GE_32(gain , ( L_shl( 1, q_fact_gain ) ))) + IF( GE_32( gain, ( L_shl( 1, q_fact_gain ) ) ) ) { apply_limiting = 0; } /* No samples above threshold but gain from previous frame is not 1.f, * transition to gain == 1.f */ frame_gain = L_shl( 1, q_fact_gain ); - } /* Detection of very strong saturations */ if ( strong_saturation_cnt != NULL ) @@ -578,13 +736,13 @@ void limiter_process_fx( compare_value = 107374182; // Q30 of 0.1f /* Limit gain reduction to 20dB. Any peaks that require gain reduction * higher than this are most likely due to bit errors during decoding */ - IF ( LT_32(frame_gain , compare_value) && !apply_strong_limiting ) + IF( LT_32( frame_gain, compare_value ) && !apply_strong_limiting ) { frame_gain = compare_value; } if ( apply_limiting ) - { + { /* 99% time constants of the gain curve * * The denominator of the second argument determines after how many @@ -603,10 +761,10 @@ void limiter_process_fx( * Apply limiting *-----------------------------------------------------------------*/ - FOR ( i = 0; i < output_frame; i++ ) + FOR( i = 0; i < output_frame; i++ ) { /* Update gain */ - IF( LT_32(frame_gain , gain) ) + IF( LT_32( frame_gain, gain ) ) { gain = L_add( Mpy_32_32( attack_constant, ( L_sub( gain, frame_gain ) ) ), frame_gain ); // q30 } @@ -615,12 +773,12 @@ void limiter_process_fx( gain = L_add( Mpy_32_32( release_constant, ( L_sub( gain, frame_gain ) ) ), frame_gain ); // q30 } - FOR ( c = 0; c < num_channels; c++ ) + FOR( c = 0; c < num_channels; c++ ) { sample = &output[c][i]; /* Apply gain */ - *sample = Mpy_32_32(L_shl_sat( *sample,1 ),gain ) ;//q_factor + *sample = Mpy_32_32( L_shl_sat( *sample, 1 ), gain ); // q_factor } } } @@ -798,4 +956,4 @@ void limiter_process( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_rend/ivas_masa_merge.c b/lib_rend/ivas_masa_merge.c index cbb826842..b9f2b4f8b 100644 --- a/lib_rend/ivas_masa_merge.c +++ b/lib_rend/ivas_masa_merge.c @@ -58,13 +58,13 @@ static void copy_masa_meta_tile( MASA_DECODER_EXT_OUT_META_HANDLE outMeta, MASA_ static void full_stream_merge_fx( MASA_DECODER_EXT_OUT_META_HANDLE outMeta, MASA_DECODER_EXT_OUT_META_HANDLE inMeta1, Word32 inEne1[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], Word16 *inEne1_e, MASA_DECODER_EXT_OUT_META_HANDLE inMeta2, Word32 inEne2[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], Word16 *inEne2_e ); static void diffuse_meta_merge_1x1_fx( - MASA_DECODER_EXT_OUT_META_HANDLE outMeta, /* o : Merged metadata output */ - MASA_DECODER_EXT_OUT_META_HANDLE inMeta, /* i : Input metadata 1 */ - Word32 inEne_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : TF-energy of input 1 */ - Word16 *inEne_e, /* i : TF-energy of input 1 */ - MASA_DECODER_EXT_OUT_META_HANDLE inMetaISM, /* i : Input metadata 2 */ + MASA_DECODER_EXT_OUT_META_HANDLE outMeta, /* o : Merged metadata output */ + MASA_DECODER_EXT_OUT_META_HANDLE inMeta, /* i : Input metadata 1 */ + Word32 inEne_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : TF-energy of input 1 */ + Word16 *inEne_e, /* i : TF-energy of input 1 */ + MASA_DECODER_EXT_OUT_META_HANDLE inMetaISM, /* i : Input metadata 2 */ Word32 inEneISM_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : TF-energy of input 2 */ - Word16 *inEneISM_e /* i : TF-energy of input 2 */ + Word16 *inEneISM_e /* i : TF-energy of input 2 */ ); #else static void full_stream_merge( MASA_DECODER_EXT_OUT_META_HANDLE outMeta, MASA_DECODER_EXT_OUT_META_HANDLE inMeta1, float inEne1[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], MASA_DECODER_EXT_OUT_META_HANDLE inMeta2, float inEne2[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS] ); @@ -83,8 +83,8 @@ static void diffuse_meta_merge_1x1( MASA_DECODER_EXT_OUT_META_HANDLE outMeta, MA void copy_masa_meta_tile_fx( MASA_DECODER_EXT_OUT_META_HANDLE outMeta, /* o : metadata to be written */ MASA_DECODER_EXT_OUT_META_HANDLE inMeta, /* i : input metadata */ - const UWord8 sf, /* i : sub-frame index */ - const UWord8 band /* i : band index */ + const UWord8 sf, /* i : sub-frame index */ + const UWord8 band /* i : band index */ ) { outMeta->directionIndex[0][sf][band] = inMeta->directionIndex[0][sf][band]; @@ -95,7 +95,7 @@ void copy_masa_meta_tile_fx( outMeta->surroundCoherence[sf][band] = inMeta->surroundCoherence[sf][band]; outMeta->diffuseToTotalRatio[sf][band] = inMeta->diffuseToTotalRatio[sf][band]; - IF ( inMeta->descriptiveMeta.numberOfDirections == 1 ) + IF( inMeta->descriptiveMeta.numberOfDirections == 1 ) { outMeta->directionIndex[1][sf][band] = inMeta->directionIndex[1][sf][band]; move16(); @@ -159,7 +159,7 @@ void copy_masa_descriptive_meta( ) { UWord8 char_idx; - FOR ( char_idx = 0; char_idx < 8; char_idx++ ) + FOR( char_idx = 0; char_idx < 8; char_idx++ ) { outMeta->formatDescriptor[char_idx] = inMeta->formatDescriptor[char_idx]; } @@ -280,47 +280,47 @@ void diffuse_meta_merge_1x1( #ifdef IVAS_FLOAT_FIXED void diffuse_meta_merge_1x1_fx( - MASA_DECODER_EXT_OUT_META_HANDLE outMeta, /* o : Merged metadata output */ - MASA_DECODER_EXT_OUT_META_HANDLE inMeta, /* i : Input metadata 1 */ - Word32 inEne_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : TF-energy of input 1 */ - Word16 *inEne_e, /* i : TF-energy of input 1 */ - MASA_DECODER_EXT_OUT_META_HANDLE inMetaISM, /* i : Input metadata 2 */ + MASA_DECODER_EXT_OUT_META_HANDLE outMeta, /* o : Merged metadata output */ + MASA_DECODER_EXT_OUT_META_HANDLE inMeta, /* i : Input metadata 1 */ + Word32 inEne_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : TF-energy of input 1 */ + Word16 *inEne_e, /* i : TF-energy of input 1 */ + MASA_DECODER_EXT_OUT_META_HANDLE inMetaISM, /* i : Input metadata 2 */ Word32 inEneISM_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : TF-energy of input 2 */ - Word16 *inEneISM_e /* i : TF-energy of input 2 */ + Word16 *inEneISM_e /* i : TF-energy of input 2 */ ) { Word8 sf, band; - Word16 max_e, in1_e[MASA_FREQUENCY_BANDS],i; - FOR ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + Word16 max_e, in1_e[MASA_FREQUENCY_BANDS], i; + FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) { - FOR ( band = 0; band < MASA_FREQUENCY_BANDS; band++ ) + FOR( band = 0; band < MASA_FREQUENCY_BANDS; band++ ) { Word32 energyTimesRatio_fx, energyTimesRatioISM_fx, total_diff_nrg_fx = 0, dir_nrg_ratio_fx, total_nrg_fx = 0; - Word32 dir_ratio_ism_fx, L_tmp1,L_tmp2; - Word16 scale, energyTimesRatio_e, tmp, total_nrg_e = 0, total_diff_nrg_e, dir_ratio_ism_e, energyTimesRatioISM_e, dir_nrg_ratio_e ; + Word32 dir_ratio_ism_fx, L_tmp1, L_tmp2; + Word16 scale, energyTimesRatio_e, tmp, total_nrg_e = 0, total_diff_nrg_e, dir_ratio_ism_e, energyTimesRatioISM_e, dir_nrg_ratio_e; - tmp = BASOP_Util_Divide1616_Scale((Word16)inMeta->directToTotalRatio[0][sf][band], (Word16) UINT8_MAX, &scale); - energyTimesRatio_fx = Mpy_32_16_r( inEne_fx[sf][band], tmp); + tmp = BASOP_Util_Divide1616_Scale( (Word16) inMeta->directToTotalRatio[0][sf][band], (Word16) UINT8_MAX, &scale ); + energyTimesRatio_fx = Mpy_32_16_r( inEne_fx[sf][band], tmp ); energyTimesRatio_e = inEne_e[sf] + scale; /* target is original MASA diffuseness */ - tmp = BASOP_Util_Divide1616_Scale((Word16)inMeta->directToTotalRatio[0][sf][band], (Word16)UINT8_MAX, &scale); - total_diff_nrg_fx = Mpy_32_16_r(inEne_fx[sf][band], tmp); + tmp = BASOP_Util_Divide1616_Scale( (Word16) inMeta->directToTotalRatio[0][sf][band], (Word16) UINT8_MAX, &scale ); + total_diff_nrg_fx = Mpy_32_16_r( inEne_fx[sf][band], tmp ); total_diff_nrg_e = inEne_e[sf] + scale; /* criterion is mean of ISM ratio and new ratio */ - dir_ratio_ism_fx = L_deposit_h( BASOP_Util_Divide1616_Scale((Word16)inMeta->directToTotalRatio[0][sf][band], (Word16)UINT8_MAX, &dir_ratio_ism_e) ); - tmp = BASOP_Util_Divide3232_Scale(total_diff_nrg_fx, L_add(total_nrg_fx, EPSILON_FX), &scale); - L_tmp1 = L_deposit_h(tmp); - scale = scale + (total_diff_nrg_e - total_nrg_e); - L_tmp2 = L_sub(L_shl(1, scale), L_tmp1); - - L_tmp1 = BASOP_Util_Add_Mant32Exp(dir_ratio_ism_fx, dir_ratio_ism_e, L_tmp2, scale, &tmp); - L_tmp1 = L_shr(L_tmp1, 1); - energyTimesRatioISM_fx = Mpy_32_32(L_tmp1, inEneISM_fx[sf][band]); + dir_ratio_ism_fx = L_deposit_h( BASOP_Util_Divide1616_Scale( (Word16) inMeta->directToTotalRatio[0][sf][band], (Word16) UINT8_MAX, &dir_ratio_ism_e ) ); + tmp = BASOP_Util_Divide3232_Scale( total_diff_nrg_fx, L_add( total_nrg_fx, EPSILON_FX ), &scale ); + L_tmp1 = L_deposit_h( tmp ); + scale = scale + ( total_diff_nrg_e - total_nrg_e ); + L_tmp2 = L_sub( L_shl( 1, scale ), L_tmp1 ); + + L_tmp1 = BASOP_Util_Add_Mant32Exp( dir_ratio_ism_fx, dir_ratio_ism_e, L_tmp2, scale, &tmp ); + L_tmp1 = L_shr( L_tmp1, 1 ); + energyTimesRatioISM_fx = Mpy_32_32( L_tmp1, inEneISM_fx[sf][band] ); energyTimesRatioISM_e = tmp + inEneISM_e[sf]; - IF ( (BASOP_Util_Cmp_Mant32Exp( energyTimesRatioISM_fx, energyTimesRatioISM_e, energyTimesRatio_fx, energyTimesRatio_e ) > 1 ) ) + IF( ( BASOP_Util_Cmp_Mant32Exp( energyTimesRatioISM_fx, energyTimesRatioISM_e, energyTimesRatio_fx, energyTimesRatio_e ) > 1 ) ) { Word32 new_dir_ratio_fx, new_diff_ratio_fx; Word16 new_dir_ratio_e; @@ -330,23 +330,23 @@ void diffuse_meta_merge_1x1_fx( outMeta->surroundCoherence[sf][band] = inMetaISM->surroundCoherence[sf][band]; - tmp = BASOP_Util_Divide3232_Scale(total_diff_nrg_fx, L_add(EPSILON_FX, total_nrg_fx), &scale); - scale = scale + (total_diff_nrg_e - total_nrg_e); - dir_nrg_ratio_fx = L_sub(L_shl(1, scale), L_deposit_h(tmp)); + tmp = BASOP_Util_Divide3232_Scale( total_diff_nrg_fx, L_add( EPSILON_FX, total_nrg_fx ), &scale ); + scale = scale + ( total_diff_nrg_e - total_nrg_e ); + dir_nrg_ratio_fx = L_sub( L_shl( 1, scale ), L_deposit_h( tmp ) ); dir_nrg_ratio_e = scale; new_dir_ratio_fx = dir_nrg_ratio_fx; new_dir_ratio_e = dir_nrg_ratio_e; - tmp = BASOP_Util_Cmp_Mant32Exp(dir_nrg_ratio_fx, dir_nrg_ratio_e, dir_ratio_ism_fx, dir_ratio_ism_e); - IF (tmp <= 0) + tmp = BASOP_Util_Cmp_Mant32Exp( dir_nrg_ratio_fx, dir_nrg_ratio_e, dir_ratio_ism_fx, dir_ratio_ism_e ); + IF( tmp <= 0 ) { new_dir_ratio_fx = dir_nrg_ratio_fx; new_dir_ratio_e = dir_nrg_ratio_e; } outMeta->directToTotalRatio[0][sf][band] = (uint8_t) ( L_shr( new_dir_ratio_fx, 31 - new_dir_ratio_e ) * UINT8_MAX ); - new_diff_ratio_fx = L_shl( 1, 31 - new_dir_ratio_e ) - new_dir_ratio_fx; - outMeta->diffuseToTotalRatio[sf][band] = (uint8_t) ( L_shr( new_diff_ratio_fx, new_dir_ratio_e) * UINT8_MAX ); + new_diff_ratio_fx = L_shl( 1, 31 - new_dir_ratio_e ) - new_dir_ratio_fx; + outMeta->diffuseToTotalRatio[sf][band] = (uint8_t) ( L_shr( new_diff_ratio_fx, new_dir_ratio_e ) * UINT8_MAX ); } ELSE { @@ -362,23 +362,22 @@ void diffuse_meta_merge_1x1_fx( outMeta->directToTotalRatio[1][sf][band] = 0u; outMeta->spreadCoherence[1][sf][band] = 0u; - inEne_fx[sf][band] = BASOP_Util_Add_Mant32Exp(inEne_fx[sf][band], inEne_e[sf], inEneISM_fx[sf][band], inEneISM_e[sf], &in1_e[band]); /* Update energy for subsequent mergings */ + inEne_fx[sf][band] = BASOP_Util_Add_Mant32Exp( inEne_fx[sf][band], inEne_e[sf], inEneISM_fx[sf][band], inEneISM_e[sf], &in1_e[band] ); /* Update energy for subsequent mergings */ } max_e = in1_e[0]; - FOR( i = 1; i < MASA_FREQUENCY_BANDS; i++) + FOR( i = 1; i < MASA_FREQUENCY_BANDS; i++ ) { - IF(max_e < in1_e[i]) - max_e = in1_e[i]; + IF( max_e < in1_e[i] ) + max_e = in1_e[i]; } - FOR( i = 0; i < MASA_FREQUENCY_BANDS; i++) + FOR( i = 0; i < MASA_FREQUENCY_BANDS; i++ ) { - inEne_fx[sf][i] = L_shr(inEne_fx[sf][i], max_e - in1_e[i]); + inEne_fx[sf][i] = L_shr( inEne_fx[sf][i], max_e - in1_e[i] ); } inEne_e[sf] = max_e; - } /* Set descriptive meta for mixed format */ @@ -470,14 +469,13 @@ void full_stream_merge( #ifdef IVAS_FLOAT_FIXED void full_stream_merge_fx( - MASA_DECODER_EXT_OUT_META_HANDLE outMeta, /* o : Merged metadata output */ - MASA_DECODER_EXT_OUT_META_HANDLE inMeta1, /* i : Input metadata 1 */ + MASA_DECODER_EXT_OUT_META_HANDLE outMeta, /* o : Merged metadata output */ + MASA_DECODER_EXT_OUT_META_HANDLE inMeta1, /* i : Input metadata 1 */ Word32 inEne1_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i/o: TF-energy of input 1. after merge, contains the energy of the merged signal */ Word16 *inEne1_e, - MASA_DECODER_EXT_OUT_META_HANDLE inMeta2, /* i : Input metadata 2 */ - Word32 inEne2_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : TF-energy of input 2 */ - Word16 *inEne2_e -) + MASA_DECODER_EXT_OUT_META_HANDLE inMeta2, /* i : Input metadata 2 */ + Word32 inEne2_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : TF-energy of input 2 */ + Word16 *inEne2_e ) { uint8_t n_dirs_1, n_dirs_2; uint8_t sf, band; @@ -489,38 +487,38 @@ void full_stream_merge_fx( n_dirs_1 = inMeta1->descriptiveMeta.numberOfDirections + 1u; /* to 1-based */ n_dirs_2 = inMeta2->descriptiveMeta.numberOfDirections + 1u; - FOR ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) { - FOR ( band = 0; band < MASA_FREQUENCY_BANDS; band++ ) + FOR( band = 0; band < MASA_FREQUENCY_BANDS; band++ ) { - tmp = BASOP_Util_Divide1616_Scale((Word16)inMeta1->directToTotalRatio[0][sf][band], (Word16)UINT8_MAX, &scale); - dir_nrg_1_fx = Mpy_32_32(L_deposit_h(tmp), inEne1_fx[sf][band]); + tmp = BASOP_Util_Divide1616_Scale( (Word16) inMeta1->directToTotalRatio[0][sf][band], (Word16) UINT8_MAX, &scale ); + dir_nrg_1_fx = Mpy_32_32( L_deposit_h( tmp ), inEne1_fx[sf][band] ); dir_nrg_1_e = scale + inEne1_e[sf]; - tmp = BASOP_Util_Divide1616_Scale((Word16)inMeta1->directToTotalRatio[0][sf][band], (Word16)UINT8_MAX, &scale); - dir_nrg_2_fx = Mpy_32_32(L_deposit_h(tmp), inEne2_fx[sf][band]); + tmp = BASOP_Util_Divide1616_Scale( (Word16) inMeta1->directToTotalRatio[0][sf][band], (Word16) UINT8_MAX, &scale ); + dir_nrg_2_fx = Mpy_32_32( L_deposit_h( tmp ), inEne2_fx[sf][band] ); dir_nrg_2_e = scale + inEne2_e[sf]; - IF ( n_dirs_1 == 2 ) + IF( n_dirs_1 == 2 ) { - tmp = BASOP_Util_Divide1616_Scale((Word16)inMeta1->directToTotalRatio[1][sf][band], (Word16)UINT8_MAX, &scale); - L_tmp = Mpy_32_32(L_deposit_h(tmp), inEne1_fx[sf][band]); + tmp = BASOP_Util_Divide1616_Scale( (Word16) inMeta1->directToTotalRatio[1][sf][band], (Word16) UINT8_MAX, &scale ); + L_tmp = Mpy_32_32( L_deposit_h( tmp ), inEne1_fx[sf][band] ); scale = scale + inEne1_e[sf]; - dir_nrg_1_fx = BASOP_Util_Add_Mant32Exp(L_tmp, scale, dir_nrg_1_fx, dir_nrg_1_e, &dir_nrg_1_e); + dir_nrg_1_fx = BASOP_Util_Add_Mant32Exp( L_tmp, scale, dir_nrg_1_fx, dir_nrg_1_e, &dir_nrg_1_e ); } - IF ( n_dirs_2 == 2 ) + IF( n_dirs_2 == 2 ) { - tmp = BASOP_Util_Divide1616_Scale((Word16)inMeta2->directToTotalRatio[1][sf][band], (Word16)UINT8_MAX, &scale); - L_tmp = Mpy_32_32(L_deposit_h(tmp), inEne2_fx[sf][band]); + tmp = BASOP_Util_Divide1616_Scale( (Word16) inMeta2->directToTotalRatio[1][sf][band], (Word16) UINT8_MAX, &scale ); + L_tmp = Mpy_32_32( L_deposit_h( tmp ), inEne2_fx[sf][band] ); scale = scale + inEne2_e[sf]; - dir_nrg_2_fx = BASOP_Util_Add_Mant32Exp(L_tmp, scale, dir_nrg_2_fx, dir_nrg_2_e, &dir_nrg_2_e); + dir_nrg_2_fx = BASOP_Util_Add_Mant32Exp( L_tmp, scale, dir_nrg_2_fx, dir_nrg_2_e, &dir_nrg_2_e ); } - IF (BASOP_Util_Cmp_Mant32Exp( dir_nrg_1_fx, dir_nrg_1_e, dir_nrg_2_fx, dir_nrg_2_e ) > 1 ) + IF( BASOP_Util_Cmp_Mant32Exp( dir_nrg_1_fx, dir_nrg_1_e, dir_nrg_2_fx, dir_nrg_2_e ) > 1 ) { copy_masa_meta_tile_fx( outMeta, inMeta1, sf, band ); } @@ -529,23 +527,22 @@ void full_stream_merge_fx( copy_masa_meta_tile_fx( outMeta, inMeta2, sf, band ); } - inEne1_fx[sf][band] = BASOP_Util_Add_Mant32Exp(inEne1_fx[sf][band], inEne1_e[sf], inEne2_fx[sf][band], inEne2_e[sf], &in1_e[band]); + inEne1_fx[sf][band] = BASOP_Util_Add_Mant32Exp( inEne1_fx[sf][band], inEne1_e[sf], inEne2_fx[sf][band], inEne2_e[sf], &in1_e[band] ); } max_e = in1_e[0]; - FOR (Word16 i = 1; i < MASA_FREQUENCY_BANDS; i++) + FOR( Word16 i = 1; i < MASA_FREQUENCY_BANDS; i++ ) { - IF (max_e < in1_e[i]) - max_e = in1_e[i]; + IF( max_e < in1_e[i] ) + max_e = in1_e[i]; } - FOR (Word16 i = 0; i < MASA_FREQUENCY_BANDS; i++) + FOR( Word16 i = 0; i < MASA_FREQUENCY_BANDS; i++ ) { - inEne1_fx[sf][i] = L_shr(inEne1_fx[sf][i], max_e - in1_e[i]); + inEne1_fx[sf][i] = L_shr( inEne1_fx[sf][i], max_e - in1_e[i] ); } inEne1_e[sf] = max_e; - } /* Set descriptive meta for mixed format */ @@ -554,7 +551,7 @@ void full_stream_merge_fx( outMeta->descriptiveMeta.channelAngle = 0u; outMeta->descriptiveMeta.channelDistance = 0u; outMeta->descriptiveMeta.channelLayout = 0u; - IF ( n_dirs_1 == 2 || n_dirs_2 == 2 ) + IF( n_dirs_1 == 2 || n_dirs_2 == 2 ) { outMeta->descriptiveMeta.numberOfDirections = 1u; } @@ -609,24 +606,24 @@ void ivas_prerend_merge_masa_metadata( #ifdef IVAS_FLOAT_FIXED void ivas_prerend_merge_masa_metadata_fx( - MASA_DECODER_EXT_OUT_META_HANDLE outMeta, /* o : Merged metadata output */ - MASA_DECODER_EXT_OUT_META_HANDLE inMeta1, /* i : Input metadata 1 */ - IVAS_REND_AudioConfigType inType1, /* i : Type of input 1 */ + MASA_DECODER_EXT_OUT_META_HANDLE outMeta, /* o : Merged metadata output */ + MASA_DECODER_EXT_OUT_META_HANDLE inMeta1, /* i : Input metadata 1 */ + IVAS_REND_AudioConfigType inType1, /* i : Type of input 1 */ Word32 inEne1_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i/o: TF-energy of input 1. after merge, contains the energy of the merged signal */ - Word16 *inEne1_e, - MASA_DECODER_EXT_OUT_META_HANDLE inMeta2, /* i : Input metadata 2 */ - IVAS_REND_AudioConfigType inType2, /* i : Type of input 2 */ - Word32 inEne2_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : TF-energy of input 2 */ - Word16 *inEne2_e /* i : TF-energy of input 2 */ + Word16 *inEne1_e, + MASA_DECODER_EXT_OUT_META_HANDLE inMeta2, /* i : Input metadata 2 */ + IVAS_REND_AudioConfigType inType2, /* i : Type of input 2 */ + Word32 inEne2_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : TF-energy of input 2 */ + Word16 *inEne2_e /* i : TF-energy of input 2 */ ) { /* mixing ISMs with non-ISM use different merge */ - IF ( inType1 == IVAS_REND_AUDIO_CONFIG_TYPE_OBJECT_BASED && inType2 != IVAS_REND_AUDIO_CONFIG_TYPE_OBJECT_BASED && ( inMeta1->descriptiveMeta.numberOfDirections == 0u && inMeta2->descriptiveMeta.numberOfDirections == 0u ) ) + IF( inType1 == IVAS_REND_AUDIO_CONFIG_TYPE_OBJECT_BASED && inType2 != IVAS_REND_AUDIO_CONFIG_TYPE_OBJECT_BASED && ( inMeta1->descriptiveMeta.numberOfDirections == 0u && inMeta2->descriptiveMeta.numberOfDirections == 0u ) ) { /* meta_1 is ISM and both are 1dir */ diffuse_meta_merge_1x1_fx( outMeta, inMeta2, inEne2_fx, inEne2_e, inMeta1, inEne1_fx, inEne1_e ); } - ELSE IF ( inType2 == IVAS_REND_AUDIO_CONFIG_TYPE_OBJECT_BASED && inType1 != IVAS_REND_AUDIO_CONFIG_TYPE_OBJECT_BASED && ( inMeta1->descriptiveMeta.numberOfDirections == 0u && inMeta2->descriptiveMeta.numberOfDirections == 0u ) ) + ELSE IF( inType2 == IVAS_REND_AUDIO_CONFIG_TYPE_OBJECT_BASED && inType1 != IVAS_REND_AUDIO_CONFIG_TYPE_OBJECT_BASED && ( inMeta1->descriptiveMeta.numberOfDirections == 0u && inMeta2->descriptiveMeta.numberOfDirections == 0u ) ) { /* meta_2 is ISM and both are 1dir */ diffuse_meta_merge_1x1_fx( outMeta, inMeta1, inEne1_fx, inEne1_e, inMeta2, inEne2_fx, inEne2_e ); @@ -702,8 +699,8 @@ ivas_error masaPrerendOpen( #else ivas_error masaPrerendOpen_fx( MASA_PREREND_HANDLE *hMasaPrerendPtr, /* o : handle to the opened prerenderer */ - Word16 numTransports, /* i : number of transport channels */ - Word32 input_Fs /* i : signal sampling rate */ + Word16 numTransports, /* i : number of transport channels */ + Word32 input_Fs /* i : signal sampling rate */ ) { MASA_PREREND_HANDLE hMasaPrerend; @@ -713,37 +710,37 @@ ivas_error masaPrerendOpen_fx( error = IVAS_ERR_OK; hMasaPrerend = (MASA_PREREND_HANDLE) malloc( sizeof( MASA_PREREND_DATA ) ); - IF ( hMasaPrerend == NULL ) + IF( hMasaPrerend == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MASA prerenderer\n" ) ); } hMasaPrerend->num_Cldfb_instances = numTransports; move16(); - FOR ( i = 0; i < hMasaPrerend->num_Cldfb_instances; i++ ) + FOR( i = 0; i < hMasaPrerend->num_Cldfb_instances; i++ ) { - IF ( ( error = openCldfb_ivas_fx( &( hMasaPrerend->cldfbAnaEnc[i] ), CLDFB_ANALYSIS, input_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) + IF( ( error = openCldfb_ivas_fx( &( hMasaPrerend->cldfbAnaEnc[i] ), CLDFB_ANALYSIS, input_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) { return error; } } - FOR ( ; i < MASA_MAX_TRANSPORT_CHANNELS; i++ ) + FOR( ; i < MASA_MAX_TRANSPORT_CHANNELS; i++ ) { hMasaPrerend->cldfbAnaEnc[i] = NULL; } - IF ( ( hMasaPrerend->hMasaOut = (MASA_DECODER_EXT_OUT_META_HANDLE) malloc( sizeof( MASA_DECODER_EXT_OUT_META ) ) ) == NULL ) + IF( ( hMasaPrerend->hMasaOut = (MASA_DECODER_EXT_OUT_META_HANDLE) malloc( sizeof( MASA_DECODER_EXT_OUT_META ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MASA prerenderer\n" ) ); } - IF ( ( hMasaPrerend->sph_grid16 = (SPHERICAL_GRID_DATA *) malloc( sizeof( SPHERICAL_GRID_DATA ) ) ) == NULL ) + IF( ( hMasaPrerend->sph_grid16 = (SPHERICAL_GRID_DATA *) malloc( sizeof( SPHERICAL_GRID_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MASA prerenderer\n" ) ); } generate_gridEq_fx( hMasaPrerend->sph_grid16 ); - IF ( error == IVAS_ERR_OK ) + IF( error == IVAS_ERR_OK ) { *hMasaPrerendPtr = hMasaPrerend; } @@ -765,12 +762,12 @@ void masaPrerendClose_fx( { Word16 i; - IF ( hMasaPrerendPtr == NULL || *hMasaPrerendPtr == NULL ) + IF( hMasaPrerendPtr == NULL || *hMasaPrerendPtr == NULL ) { return; } - FOR ( i = 0; i < ( *hMasaPrerendPtr )->num_Cldfb_instances; i++ ) + FOR( i = 0; i < ( *hMasaPrerendPtr )->num_Cldfb_instances; i++ ) { deleteCldfb_ivas( &( ( *hMasaPrerendPtr )->cldfbAnaEnc[i] ) ); } @@ -812,4 +809,4 @@ void masaPrerendClose( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_rend/ivas_mcmasa_ana.c b/lib_rend/ivas_mcmasa_ana.c index a29800683..48d9c50f5 100644 --- a/lib_rend/ivas_mcmasa_ana.c +++ b/lib_rend/ivas_mcmasa_ana.c @@ -52,10 +52,10 @@ * Local constants *------------------------------------------------------------------------*/ -#define NEAR_HORIZONTAL_PLANE_ELEVATION 17.5f -#define NEAR_HORIZONTAL_PLANE_ELEVATION_FX 73400320/*Q22*/ -#define VERTICAL_ENERGY_RATIO_OFFSET 0.15f -#define VERTICAL_ENERGY_RATIO_OFFSET_FX 4915/*Q15*/ +#define NEAR_HORIZONTAL_PLANE_ELEVATION 17.5f +#define NEAR_HORIZONTAL_PLANE_ELEVATION_FX 73400320 /*Q22*/ +#define VERTICAL_ENERGY_RATIO_OFFSET 0.15f +#define VERTICAL_ENERGY_RATIO_OFFSET_FX 4915 /*Q15*/ /*------------------------------------------------------------------------- @@ -70,9 +70,9 @@ typedef struct #ifdef IVAS_FLOAT_FIXED Word32 xr_fx[MCMASA_MAX_ANA_CHANS][MCMASA_MAX_ANA_CHANS]; Word32 xi_fx[MCMASA_MAX_ANA_CHANS][MCMASA_MAX_ANA_CHANS]; - Word16 xr_e[MCMASA_MAX_ANA_CHANS][MCMASA_MAX_ANA_CHANS];/*Stores exponent for xr_fx*/ - Word16 xi_e[MCMASA_MAX_ANA_CHANS][MCMASA_MAX_ANA_CHANS];/*Stores exponent for xi_fx*/ -#endif // IVAS_FLOAT_FIXED + Word16 xr_e[MCMASA_MAX_ANA_CHANS][MCMASA_MAX_ANA_CHANS]; /*Stores exponent for xr_fx*/ + Word16 xi_e[MCMASA_MAX_ANA_CHANS][MCMASA_MAX_ANA_CHANS]; /*Stores exponent for xi_fx*/ +#endif // IVAS_FLOAT_FIXED } CovarianceMatrix; #ifdef IVAS_FLOAT_FIXED void ivas_mcmasa_param_est_ana_fx( @@ -84,8 +84,8 @@ void ivas_mcmasa_param_est_ana_fx( Word32 spreadCoherence_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* o : Estimated spread coherence */ Word32 surroundingCoherence_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* o : Estimated surround coherence */ Word16 q_data, - const Word16 input_frame, /* i : Input frame size */ - const Word16 nchan_inp /* i : Number of input channels */ + const Word16 input_frame, /* i : Input frame size */ + const Word16 nchan_inp /* i : Number of input channels */ ); #else void ivas_mcmasa_param_est_ana( MCMASA_ANA_HANDLE hMcMasa, float data_f[][L_FRAME48k], float elevation_m_values[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], float azimuth_m_values[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], float energyRatio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], float spreadCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], float surroundingCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], const int16_t input_frame, const int16_t nchan_inp ); @@ -116,8 +116,8 @@ static void compute_cov_mtx_fx( Word32 si[MCMASA_MAX_ANA_CHANS][CLDFB_NO_CHANNELS_MAX], /* i : Input matrix, imag, s[ch][freq] */ const Word16 freq, /* i : Freq to process */ const Word16 N, /* i : Number of channels */ - CovarianceMatrix *COVls, /* o : Output matrix, contains upper part of cov mtx */ - Word16 shift); + CovarianceMatrix *COVls, /* o : Output matrix, contains upper part of cov mtx */ + Word16 shift ); static void computeEvenLayout_fx( const Word32 *ls_azimuth, Word32 *ls_azimuth_even, @@ -148,7 +148,7 @@ static void computeEvenLayout( const float *ls_azimuth, float *ls_azimuth_even, ivas_error ivas_mcmasa_ana_open( MCMASA_ANA_HANDLE *hMcMasaPtr, /* i/o: McMASA data handle pointer */ const AUDIO_CONFIG inConfig, /* i : Input config */ - Word32 input_Fs /* i : Sampling frequency */ + Word32 input_Fs /* i : Sampling frequency */ ) { Word32 ls_azimuth_fx[MCMASA_MAX_ANA_CHANS]; @@ -164,12 +164,12 @@ ivas_error ivas_mcmasa_ana_open( error = IVAS_ERR_OK; - IF ( ( hMcMasa = (MCMASA_ANA_HANDLE) malloc( sizeof( MCMASA_ANA_DATA ) ) ) == NULL ) + IF( ( hMcMasa = (MCMASA_ANA_HANDLE) malloc( sizeof( MCMASA_ANA_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for McMasa\n" ) ); } - IF ( EQ_16(inConfig , IVAS_AUDIO_CONFIG_5_1) ) + IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_5_1 ) ) { nchan_inp = 6; Copy32( ls_azimuth_CICP6_fx, ls_azimuth_fx, nchan_inp - 1 ); @@ -177,7 +177,7 @@ ivas_error ivas_mcmasa_ana_open( hMcMasa->numHorizontalChannels = 5; hMcMasa->isHorizontalSetup = 1; } - ELSE IF ( EQ_16(inConfig , IVAS_AUDIO_CONFIG_7_1) ) + ELSE IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_7_1 ) ) { nchan_inp = 8; Copy32( ls_azimuth_CICP12_fx, ls_azimuth_fx, nchan_inp - 1 ); @@ -185,7 +185,7 @@ ivas_error ivas_mcmasa_ana_open( hMcMasa->numHorizontalChannels = 7; hMcMasa->isHorizontalSetup = 1; } - ELSE IF( EQ_16(inConfig , IVAS_AUDIO_CONFIG_5_1_2) ) + ELSE IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_5_1_2 ) ) { nchan_inp = 8; Copy32( ls_azimuth_CICP14_fx, ls_azimuth_fx, nchan_inp - 1 ); @@ -193,7 +193,7 @@ ivas_error ivas_mcmasa_ana_open( hMcMasa->numHorizontalChannels = 5; hMcMasa->isHorizontalSetup = 0; } - ELSE IF ( EQ_16(inConfig , IVAS_AUDIO_CONFIG_5_1_4) ) + ELSE IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_5_1_4 ) ) { nchan_inp = 10; Copy32( ls_azimuth_CICP16_fx, ls_azimuth_fx, nchan_inp - 1 ); @@ -210,7 +210,7 @@ ivas_error ivas_mcmasa_ana_open( hMcMasa->isHorizontalSetup = 0; } - numAnalysisChannels = sub(nchan_inp , 1); + numAnalysisChannels = sub( nchan_inp, 1 ); /* Determine the number of bands */ hMcMasa->nbands = MASA_FREQUENCY_BANDS; @@ -218,10 +218,10 @@ ivas_error ivas_mcmasa_ana_open( /* Determine band grouping */ Copy( MASA_band_grouping_24, hMcMasa->band_grouping, 24 + 1 ); - maxBin = extract_l(W_extract_h(W_add(W_mult_32_32(input_Fs , INV_CLDFB_BANDWIDTH_Q31) , ONE_IN_Q31/*0.5f in Q31*/) )); - FOR ( i = 1; i < hMcMasa->nbands + 1; i++ ) + maxBin = extract_l( W_extract_h( W_add( W_mult_32_32( input_Fs, INV_CLDFB_BANDWIDTH_Q31 ), ONE_IN_Q31 /*0.5f in Q31*/ ) ) ); + FOR( i = 1; i < hMcMasa->nbands + 1; i++ ) { - IF ( GE_16(hMcMasa->band_grouping[i] , maxBin) ) + IF( GE_16( hMcMasa->band_grouping[i], maxBin ) ) { hMcMasa->band_grouping[i] = maxBin; hMcMasa->nbands = i; @@ -234,25 +234,25 @@ ivas_error ivas_mcmasa_ana_open( /* open/initialize CLDFB */ hMcMasa->num_Cldfb_instances = numAnalysisChannels; - FOR ( i = 0; i < hMcMasa->num_Cldfb_instances; i++ ) + FOR( i = 0; i < hMcMasa->num_Cldfb_instances; i++ ) { - IF ( ( error = openCldfb_ivas( &( hMcMasa->cldfbAnaEnc[i] ), CLDFB_ANALYSIS, input_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) + IF( ( error = openCldfb_ivas( &( hMcMasa->cldfbAnaEnc[i] ), CLDFB_ANALYSIS, input_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) { return error; } } /* intensity 3-dim */ - FOR ( i = 0; i < DIRAC_NUM_DIMS; i++ ) + FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) { IF( ( hMcMasa->direction_vector_m_fx[i] = (Word32 **) malloc( MAX_PARAM_SPATIAL_SUBFRAMES * sizeof( Word32 * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for McMasa\n" ) ); } - FOR ( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) + FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) { - IF ( ( hMcMasa->direction_vector_m_fx[i][j] = (Word32 *) malloc( MASA_FREQUENCY_BANDS * sizeof( Word32 ) ) ) == NULL ) + IF( ( hMcMasa->direction_vector_m_fx[i][j] = (Word32 *) malloc( MASA_FREQUENCY_BANDS * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for McMasa\n" ) ); } @@ -269,43 +269,43 @@ ivas_error ivas_mcmasa_ana_open( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for McMasa\n" ) ); } - set16_fx( hMcMasa->direction_vector_e[i][j],0, MASA_FREQUENCY_BANDS ); + set16_fx( hMcMasa->direction_vector_e[i][j], 0, MASA_FREQUENCY_BANDS ); } } - FOR ( i = 0; i < DIRAC_NUM_DIMS; i++ ) + FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) { - FOR ( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) + FOR( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) { - IF ( ( hMcMasa->buffer_intensity_real_fx[i][j] = (Word32 *) malloc( MASA_FREQUENCY_BANDS * sizeof(Word32) ) ) == NULL ) + IF( ( hMcMasa->buffer_intensity_real_fx[i][j] = (Word32 *) malloc( MASA_FREQUENCY_BANDS * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for McMasa\n" ) ); } set_zero_fx( hMcMasa->buffer_intensity_real_fx[i][j], MASA_FREQUENCY_BANDS ); } } - set16_fx( hMcMasa->buffer_intensity_real_q, 31, DIRAC_NO_COL_AVG_DIFF); + set16_fx( hMcMasa->buffer_intensity_real_q, 31, DIRAC_NO_COL_AVG_DIFF ); - FOR ( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) + FOR( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) { - IF ( ( hMcMasa->buffer_intensity_real_vert_fx[j] = (Word32 *) malloc( MASA_FREQUENCY_BANDS * sizeof(Word32) ) ) == NULL ) + IF( ( hMcMasa->buffer_intensity_real_vert_fx[j] = (Word32 *) malloc( MASA_FREQUENCY_BANDS * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for McMasa\n" ) ); } set_zero_fx( hMcMasa->buffer_intensity_real_vert_fx[j], MASA_FREQUENCY_BANDS ); } - set16_fx(hMcMasa->buffer_intensity_real_vert_q, 31, DIRAC_NO_COL_AVG_DIFF ); + set16_fx( hMcMasa->buffer_intensity_real_vert_q, 31, DIRAC_NO_COL_AVG_DIFF ); set_zero_fx( hMcMasa->buffer_energy_fx, DIRAC_NO_COL_AVG_DIFF * MASA_FREQUENCY_BANDS ); - set16_fx(hMcMasa->buffer_energy_q, 31, DIRAC_NO_COL_AVG_DIFF ); + set16_fx( hMcMasa->buffer_energy_q, 31, DIRAC_NO_COL_AVG_DIFF ); computeEvenLayout_fx( ls_azimuth_fx, ls_azimuth_even_fx, hMcMasa->numHorizontalChannels ); - IF ( !hMcMasa->isHorizontalSetup ) + IF( !hMcMasa->isHorizontalSetup ) { - computeEvenLayout_fx( &ls_azimuth_fx[hMcMasa->numHorizontalChannels], &ls_azimuth_even_fx[hMcMasa->numHorizontalChannels], sub(numAnalysisChannels , hMcMasa->numHorizontalChannels) ); + computeEvenLayout_fx( &ls_azimuth_fx[hMcMasa->numHorizontalChannels], &ls_azimuth_even_fx[hMcMasa->numHorizontalChannels], sub( numAnalysisChannels, hMcMasa->numHorizontalChannels ) ); } - FOR ( i = 0; i < numAnalysisChannels; i++ ) + FOR( i = 0; i < numAnalysisChannels; i++ ) { hMcMasa->chnlToFoaMtx_fx[0][i] = ONE_IN_Q31; hMcMasa->chnlToFoaMtx_fx[1][i] = L_mult( getSineWord16R2( extract_l( L_shr( Mult_32_16( ls_azimuth_fx[i], 91 /*32767/360*/ ), 7 ) ) ), getCosWord16R2( extract_l( L_shr( Mult_32_16( ls_elevation_fx[i], 91 ), 7 ) ) ) ); @@ -320,22 +320,22 @@ ivas_error ivas_mcmasa_ana_open( Copy32( ls_azimuth_fx, hMcMasa->ls_azimuth_fx, numAnalysisChannels ); - FOR ( i = 0; i < hMcMasa->numHorizontalChannels; i++ ) + FOR( i = 0; i < hMcMasa->numHorizontalChannels; i++ ) { - left_min_fx = L_shl(360,22); - right_min_fx = L_shl(-360,22); + left_min_fx = L_shl( 360, 22 ); + right_min_fx = L_shl( -360, 22 ); - FOR ( j = 0; j < hMcMasa->numHorizontalChannels; j++ ) + FOR( j = 0; j < hMcMasa->numHorizontalChannels; j++ ) { - azi_diff_fx = L_sub(ls_azimuth_fx[j] , ls_azimuth_fx[i]); + azi_diff_fx = L_sub( ls_azimuth_fx[j], ls_azimuth_fx[i] ); - IF ( GT_32(azi_diff_fx , (180<<22)) ) + IF( GT_32( azi_diff_fx, ( 180 << 22 ) ) ) { - azi_diff_fx = L_sub(azi_diff_fx,360<<22); + azi_diff_fx = L_sub( azi_diff_fx, 360 << 22 ); } - ELSE IF ( LT_32(azi_diff_fx , -(180<<22)) ) + ELSE IF( LT_32( azi_diff_fx, -( 180 << 22 ) ) ) { - azi_diff_fx = L_add(azi_diff_fx,360<<22); + azi_diff_fx = L_add( azi_diff_fx, 360 << 22 ); } IF( LT_32( azi_diff_fx, left_min_fx ) && GT_32( azi_diff_fx, 0 ) ) @@ -344,7 +344,7 @@ ivas_error ivas_mcmasa_ana_open( left_min_fx = azi_diff_fx; } - IF( GT_32( azi_diff_fx, right_min_fx ) && LT_32( azi_diff_fx , 0 ) ) + IF( GT_32( azi_diff_fx, right_min_fx ) && LT_32( azi_diff_fx, 0 ) ) { hMcMasa->rightNearest[i] = j; right_min_fx = azi_diff_fx; @@ -359,19 +359,19 @@ ivas_error ivas_mcmasa_ana_open( hMcMasa->prevEQ_e = 1; hMcMasa->prevEQ_fx = 1073741824; input_frame = (int16_t) ( input_Fs / FRAMES_PER_SEC ); - FOR ( i = 0; i < input_frame; i++ ) + FOR( i = 0; i < input_frame; i++ ) { hMcMasa->interpolator_fx[i] = div_s( i, input_frame ); } hMcMasa->index_buffer_intensity = 0; - IF ( ( hMcMasa->hMasaOut = (MASA_DECODER_EXT_OUT_META_HANDLE) malloc( sizeof( MASA_DECODER_EXT_OUT_META ) ) ) == NULL ) + IF( ( hMcMasa->hMasaOut = (MASA_DECODER_EXT_OUT_META_HANDLE) malloc( sizeof( MASA_DECODER_EXT_OUT_META ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MASA decoder\n" ) ); } - IF ( ( hMcMasa->sph_grid16 = (SPHERICAL_GRID_DATA *) malloc( sizeof( SPHERICAL_GRID_DATA ) ) ) == NULL ) + IF( ( hMcMasa->sph_grid16 = (SPHERICAL_GRID_DATA *) malloc( sizeof( SPHERICAL_GRID_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MASA decoder\n" ) ); } @@ -616,12 +616,12 @@ void ivas_mcmasa_ana_close( { Word16 i, j; - IF ( hMcMasa == NULL || *hMcMasa == NULL ) + IF( hMcMasa == NULL || *hMcMasa == NULL ) { return; } - FOR ( i = 0; i < ( *hMcMasa )->num_Cldfb_instances; i++ ) + FOR( i = 0; i < ( *hMcMasa )->num_Cldfb_instances; i++ ) { deleteCldfb_ivas( &( ( *hMcMasa )->cldfbAnaEnc[i] ) ); } @@ -635,7 +635,7 @@ void ivas_mcmasa_ana_close( ( *hMcMasa )->direction_vector_m_fx[i][j] = NULL; } - FOR ( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) + FOR( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) { free( ( *hMcMasa )->buffer_intensity_real_fx[i][j] ); ( *hMcMasa )->buffer_intensity_real_fx[i][j] = NULL; @@ -645,12 +645,12 @@ void ivas_mcmasa_ana_close( ( *hMcMasa )->direction_vector_m_fx[i] = NULL; } - FOR ( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) + FOR( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) { free( ( *hMcMasa )->buffer_intensity_real_vert_fx[j] ); ( *hMcMasa )->buffer_intensity_real_vert_fx[j] = NULL; } -#if 0/*TODO: To be removed later( freeing float buffer)*/ +#if 0 /*TODO: To be removed later( freeing float buffer)*/ FOR ( i = 0; i < DIRAC_NUM_DIMS; i++ ) { FOR ( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) @@ -749,8 +749,8 @@ void ivas_mcmasa_ana_close( #ifdef IVAS_FLOAT_FIXED void ivas_mcmasa_ana_fx( - MCMASA_ANA_HANDLE hMcMasa, /* i/o: McMASA encoder handle */ - Word32 data[][L_FRAME48k], /* i/o: Input / transport audio signals */ + MCMASA_ANA_HANDLE hMcMasa, /* i/o: McMASA encoder handle */ + Word32 data[][L_FRAME48k], /* i/o: Input / transport audio signals */ Word16 q_data, const Word16 input_frame, /* i : Input frame size */ const Word16 nchan_transport, /* i : Number of transport channels */ @@ -766,7 +766,7 @@ void ivas_mcmasa_ana_fx( Word32 surroundingCoherence_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; /* Sum center and LFE, move surround channels */ v_add_32( data[2], data[3], data[2], input_frame ); - FOR ( i = 4; i < nchan_inp; i++ ) + FOR( i = 4; i < nchan_inp; i++ ) { Copy32( data[i], data[i - 1], input_frame ); } @@ -829,16 +829,16 @@ void ivas_mcmasa_ana( /* Estimate metadata parameters for McMASA */ #ifdef IVAS_FLOAT_FIXED void ivas_mcmasa_param_est_ana_fx( - MCMASA_ANA_HANDLE hMcMasa, /* i : McMASA analyzer structure */ - Word32 data_fx[][L_FRAME48k], /* i : Audio frame in MC-format */ + MCMASA_ANA_HANDLE hMcMasa, /* i : McMASA analyzer structure */ + Word32 data_fx[][L_FRAME48k], /* i : Audio frame in MC-format */ Word32 elevation_m_values_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* o : Estimated elevation */ Word32 azimuth_m_values_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* o : Estimated azimuth */ Word32 energyRatio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* o : Estimated direct-to-total ratio */ Word32 spreadCoherence_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* o : Estimated spread coherence */ Word32 surroundingCoherence_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* o : Estimated surround coherence */ Word16 q_data, - const Word16 input_frame, /* i : Input frame size */ - const Word16 nchan_inp /* i : Number of input channels */ + const Word16 input_frame, /* i : Input frame size */ + const Word16 nchan_inp /* i : Number of input channels */ ) { Word16 cohPanCoh_e; @@ -898,17 +898,17 @@ void ivas_mcmasa_param_est_ana_fx( num_freq_bins = hMcMasa->cldfbAnaEnc[0]->no_channels; num_freq_bands = hMcMasa->nbands; l_ts = input_frame / CLDFB_NO_COL_MAX; - numAnalysisChannels = sub(nchan_inp , 1); + numAnalysisChannels = sub( nchan_inp, 1 ); set16_fx( q_vdv, 31, MASA_FREQUENCY_BANDS ); set16_fx( out_exp, 30, MASA_FREQUENCY_BANDS ); /* do processing over all CLDFB time slots */ - FOR ( block_m_idx = 0; block_m_idx < MAX_PARAM_SPATIAL_SUBFRAMES; block_m_idx++ ) + FOR( block_m_idx = 0; block_m_idx < MAX_PARAM_SPATIAL_SUBFRAMES; block_m_idx++ ) { mrange[0] = hMcMasa->block_grouping[block_m_idx]; mrange[1] = hMcMasa->block_grouping[block_m_idx + 1]; - FOR ( band_m_idx = 0; band_m_idx < hMcMasa->nbands; band_m_idx++ ) + FOR( band_m_idx = 0; band_m_idx < hMcMasa->nbands; band_m_idx++ ) { hMcMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx] = 0; hMcMasa->direction_vector_m_fx[1][block_m_idx][band_m_idx] = 0; @@ -920,89 +920,89 @@ void ivas_mcmasa_param_est_ana_fx( /* Need to initialize renormalization_factors, and variables to be normalized */ set_zero_fx( renormalization_factor_diff_fx, hMcMasa->nbands ); - set16_fx( renormalization_factor_diff_e,0, hMcMasa->nbands ); + set16_fx( renormalization_factor_diff_e, 0, hMcMasa->nbands ); set_zero_fx( diffuseness_m_fx, hMcMasa->nbands ); - set16_fx( diffuseness_e, 0,hMcMasa->nbands ); + set16_fx( diffuseness_e, 0, hMcMasa->nbands ); set_zero_fx( hMcMasa->energy_fx[block_m_idx], MASA_FREQUENCY_BANDS ); - set16_fx( hMcMasa->energy_e[block_m_idx], 0,MASA_FREQUENCY_BANDS ); + set16_fx( hMcMasa->energy_e[block_m_idx], 0, MASA_FREQUENCY_BANDS ); /* Reset variable */ - FOR ( i = 0; i < hMcMasa->nbands; i++ ) + FOR( i = 0; i < hMcMasa->nbands; i++ ) { - FOR ( j = 0; j < numAnalysisChannels; j++ ) + FOR( j = 0; j < numAnalysisChannels; j++ ) { set_zero_fx( COVls[i].xr_fx[j], numAnalysisChannels ); set_zero_fx( COVls[i].xi_fx[j], numAnalysisChannels ); - set16_fx( COVls[i].xr_e[j],0, numAnalysisChannels ); - set16_fx( COVls[i].xi_e[j],0, numAnalysisChannels ); + set16_fx( COVls[i].xr_e[j], 0, numAnalysisChannels ); + set16_fx( COVls[i].xi_e[j], 0, numAnalysisChannels ); } } - FOR ( ts = mrange[0]; ts < mrange[1]; ts++ ) + FOR( ts = mrange[0]; ts < mrange[1]; ts++ ) { - Word16 cr_q=MAX_16, ci_q= MAX_16,sf,c_e; - Word16 inp_q= q_data; - FOR ( i = 0; i < numAnalysisChannels; i++ ) + Word16 cr_q = MAX_16, ci_q = MAX_16, sf, c_e; + Word16 inp_q = q_data; + FOR( i = 0; i < numAnalysisChannels; i++ ) { inp_q = q_data; - cldfbAnalysis_ts_fx_fixed_q( &( data_fx[i][l_ts * ts] ), Chnl_RealBuffer_fx[i], Chnl_ImagBuffer_fx[i], l_ts, hMcMasa->cldfbAnaEnc[i], &inp_q); - cr_q = s_min(cr_q,getScaleFactor32( Chnl_ImagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX )); - ci_q = s_min( ci_q, getScaleFactor32(Chnl_RealBuffer_fx[i], CLDFB_NO_CHANNELS_MAX ) ); + cldfbAnalysis_ts_fx_fixed_q( &( data_fx[i][l_ts * ts] ), Chnl_RealBuffer_fx[i], Chnl_ImagBuffer_fx[i], l_ts, hMcMasa->cldfbAnaEnc[i], &inp_q ); + cr_q = s_min( cr_q, getScaleFactor32( Chnl_ImagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX ) ); + ci_q = s_min( ci_q, getScaleFactor32( Chnl_RealBuffer_fx[i], CLDFB_NO_CHANNELS_MAX ) ); } - sf = sub(s_min( cr_q, ci_q ) , 4); - FOR ( i = 0; i < numAnalysisChannels; i++ ) + sf = sub( s_min( cr_q, ci_q ), 4 ); + FOR( i = 0; i < numAnalysisChannels; i++ ) { - scale_sig32( Chnl_RealBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, sf); - scale_sig32( Chnl_ImagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, sf); + scale_sig32( Chnl_RealBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, sf ); + scale_sig32( Chnl_ImagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, sf ); } - inp_q = add(inp_q, sf ); - c_e = sub(31 , inp_q); + inp_q = add( inp_q, sf ); + c_e = sub( 31, inp_q ); hMcMasa->chnlToFoaMtx_e = c_e; /* Compute channel-based energy for metadata processing */ - FOR ( band_m_idx = 0; band_m_idx < num_freq_bands; band_m_idx++ ) + FOR( band_m_idx = 0; band_m_idx < num_freq_bands; band_m_idx++ ) { brange[0] = hMcMasa->band_grouping[band_m_idx]; brange[1] = hMcMasa->band_grouping[band_m_idx + 1]; - FOR ( j = brange[0]; j < brange[1]; j++ ) + FOR( j = brange[0]; j < brange[1]; j++ ) { - FOR ( i = 0; i < numAnalysisChannels; i++ ) + FOR( i = 0; i < numAnalysisChannels; i++ ) { Word32 temp = L_add( Mult_32_32( Chnl_RealBuffer_fx[i][j], Chnl_RealBuffer_fx[i][j] ), Mult_32_32( Chnl_ImagBuffer_fx[i][j], Chnl_ImagBuffer_fx[i][j] ) ); - hMcMasa->energy_fx[block_m_idx][band_m_idx] = BASOP_Util_Add_Mant32Exp(hMcMasa->energy_fx[block_m_idx][band_m_idx], hMcMasa->energy_e[block_m_idx][band_m_idx], temp, (c_e) * 2, &hMcMasa->energy_e[block_m_idx][band_m_idx]); + hMcMasa->energy_fx[block_m_idx][band_m_idx] = BASOP_Util_Add_Mant32Exp( hMcMasa->energy_fx[block_m_idx][band_m_idx], hMcMasa->energy_e[block_m_idx][band_m_idx], temp, (c_e) *2, &hMcMasa->energy_e[block_m_idx][band_m_idx] ); } } } /* Compute covariance matrix */ - FOR ( i = 0; i < num_freq_bands; i++ ) + FOR( i = 0; i < num_freq_bands; i++ ) { brange[0] = hMcMasa->band_grouping[i]; brange[1] = hMcMasa->band_grouping[i + 1]; - FOR ( j = brange[0]; j < brange[1]; j++ ) + FOR( j = brange[0]; j < brange[1]; j++ ) { - compute_cov_mtx_fx( Chnl_RealBuffer_fx, Chnl_ImagBuffer_fx, j, numAnalysisChannels, &( COVls[i] ), c_e); + compute_cov_mtx_fx( Chnl_RealBuffer_fx, Chnl_ImagBuffer_fx, j, numAnalysisChannels, &( COVls[i] ), c_e ); } } /* Compute standard FOA */ /* W */ - v_add_32( Chnl_RealBuffer_fx[0], Chnl_RealBuffer_fx[1], Foa_RealBuffer_fx[0], num_freq_bins );/*q*/ - v_add_32( Chnl_ImagBuffer_fx[0], Chnl_ImagBuffer_fx[1], Foa_ImagBuffer_fx[0], num_freq_bins );/*q*/ - FOR ( i = 2; i < numAnalysisChannels; i++ ) + v_add_32( Chnl_RealBuffer_fx[0], Chnl_RealBuffer_fx[1], Foa_RealBuffer_fx[0], num_freq_bins ); /*q*/ + v_add_32( Chnl_ImagBuffer_fx[0], Chnl_ImagBuffer_fx[1], Foa_ImagBuffer_fx[0], num_freq_bins ); /*q*/ + FOR( i = 2; i < numAnalysisChannels; i++ ) { - v_add_32( Chnl_RealBuffer_fx[i], Foa_RealBuffer_fx[0], Foa_RealBuffer_fx[0], num_freq_bins );/*q*/ - v_add_32( Chnl_ImagBuffer_fx[i], Foa_ImagBuffer_fx[0], Foa_ImagBuffer_fx[0], num_freq_bins );/*q*/ + v_add_32( Chnl_RealBuffer_fx[i], Foa_RealBuffer_fx[0], Foa_RealBuffer_fx[0], num_freq_bins ); /*q*/ + v_add_32( Chnl_ImagBuffer_fx[i], Foa_ImagBuffer_fx[0], Foa_ImagBuffer_fx[0], num_freq_bins ); /*q*/ } /* Y */ - v_multc_fixed( Chnl_RealBuffer_fx[0], hMcMasa->chnlToFoaMtx_fx[1][0], Foa_RealBuffer_fx[1], num_freq_bins );/*q*/ - v_multc_fixed( Chnl_ImagBuffer_fx[0], hMcMasa->chnlToFoaMtx_fx[1][0], Foa_ImagBuffer_fx[1], num_freq_bins );/*q*/ - FOR ( i = 1; i < numAnalysisChannels; i++ ) + v_multc_fixed( Chnl_RealBuffer_fx[0], hMcMasa->chnlToFoaMtx_fx[1][0], Foa_RealBuffer_fx[1], num_freq_bins ); /*q*/ + v_multc_fixed( Chnl_ImagBuffer_fx[0], hMcMasa->chnlToFoaMtx_fx[1][0], Foa_ImagBuffer_fx[1], num_freq_bins ); /*q*/ + FOR( i = 1; i < numAnalysisChannels; i++ ) { - v_multc_acc_32_32( Chnl_RealBuffer_fx[i], hMcMasa->chnlToFoaMtx_fx[1][i], Foa_RealBuffer_fx[1], num_freq_bins );/*q*/ - v_multc_acc_32_32( Chnl_ImagBuffer_fx[i], hMcMasa->chnlToFoaMtx_fx[1][i], Foa_ImagBuffer_fx[1], num_freq_bins );/*q*/ + v_multc_acc_32_32( Chnl_RealBuffer_fx[i], hMcMasa->chnlToFoaMtx_fx[1][i], Foa_RealBuffer_fx[1], num_freq_bins ); /*q*/ + v_multc_acc_32_32( Chnl_ImagBuffer_fx[i], hMcMasa->chnlToFoaMtx_fx[1][i], Foa_ImagBuffer_fx[1], num_freq_bins ); /*q*/ } /* Z */ - IF ( hMcMasa->isHorizontalSetup ) + IF( hMcMasa->isHorizontalSetup ) { /* Set zero for horizontal setups */ set_zero_fx( Foa_RealBuffer_fx[2], num_freq_bins ); @@ -1010,21 +1010,21 @@ void ivas_mcmasa_param_est_ana_fx( } ELSE { - v_multc_fixed( Chnl_RealBuffer_fx[0], hMcMasa->chnlToFoaMtx_fx[2][0], Foa_RealBuffer_fx[2], num_freq_bins );/*q*/ - v_multc_fixed( Chnl_ImagBuffer_fx[0], hMcMasa->chnlToFoaMtx_fx[2][0], Foa_ImagBuffer_fx[2], num_freq_bins );/*q*/ - FOR ( i = 1; i < numAnalysisChannels; i++ ) + v_multc_fixed( Chnl_RealBuffer_fx[0], hMcMasa->chnlToFoaMtx_fx[2][0], Foa_RealBuffer_fx[2], num_freq_bins ); /*q*/ + v_multc_fixed( Chnl_ImagBuffer_fx[0], hMcMasa->chnlToFoaMtx_fx[2][0], Foa_ImagBuffer_fx[2], num_freq_bins ); /*q*/ + FOR( i = 1; i < numAnalysisChannels; i++ ) { - v_multc_acc_32_32( Chnl_RealBuffer_fx[i], hMcMasa->chnlToFoaMtx_fx[2][i], Foa_RealBuffer_fx[2], num_freq_bins );/*q*/ - v_multc_acc_32_32( Chnl_ImagBuffer_fx[i], hMcMasa->chnlToFoaMtx_fx[2][i], Foa_ImagBuffer_fx[2], num_freq_bins );/*q*/ + v_multc_acc_32_32( Chnl_RealBuffer_fx[i], hMcMasa->chnlToFoaMtx_fx[2][i], Foa_RealBuffer_fx[2], num_freq_bins ); /*q*/ + v_multc_acc_32_32( Chnl_ImagBuffer_fx[i], hMcMasa->chnlToFoaMtx_fx[2][i], Foa_ImagBuffer_fx[2], num_freq_bins ); /*q*/ } } /* X */ - v_multc_fixed( Chnl_RealBuffer_fx[0], hMcMasa->chnlToFoaMtx_fx[3][0], Foa_RealBuffer_fx[3], num_freq_bins );/*q*/ - v_multc_fixed( Chnl_ImagBuffer_fx[0], hMcMasa->chnlToFoaMtx_fx[3][0], Foa_ImagBuffer_fx[3], num_freq_bins );/*q*/ - FOR ( i = 1; i < numAnalysisChannels; i++ ) + v_multc_fixed( Chnl_RealBuffer_fx[0], hMcMasa->chnlToFoaMtx_fx[3][0], Foa_RealBuffer_fx[3], num_freq_bins ); /*q*/ + v_multc_fixed( Chnl_ImagBuffer_fx[0], hMcMasa->chnlToFoaMtx_fx[3][0], Foa_ImagBuffer_fx[3], num_freq_bins ); /*q*/ + FOR( i = 1; i < numAnalysisChannels; i++ ) { - v_multc_acc_32_32( Chnl_RealBuffer_fx[i], hMcMasa->chnlToFoaMtx_fx[3][i], Foa_RealBuffer_fx[3], num_freq_bins );/*q*/ - v_multc_acc_32_32( Chnl_ImagBuffer_fx[i], hMcMasa->chnlToFoaMtx_fx[3][i], Foa_ImagBuffer_fx[3], num_freq_bins );/*q*/ + v_multc_acc_32_32( Chnl_RealBuffer_fx[i], hMcMasa->chnlToFoaMtx_fx[3][i], Foa_RealBuffer_fx[3], num_freq_bins ); /*q*/ + v_multc_acc_32_32( Chnl_ImagBuffer_fx[i], hMcMasa->chnlToFoaMtx_fx[3][i], Foa_ImagBuffer_fx[3], num_freq_bins ); /*q*/ } /* Compute even FOA */ @@ -1033,12 +1033,12 @@ void ivas_mcmasa_param_est_ana_fx( Copy32( Foa_ImagBuffer_fx[0], FoaEven_ImagBuffer_fx[0], num_freq_bins ); /* Y */ - v_multc_fixed( Chnl_RealBuffer_fx[0], hMcMasa->chnlToFoaEvenMtx_fx[1][0], FoaEven_RealBuffer_fx[1], num_freq_bins );/*q*/ - v_multc_fixed( Chnl_ImagBuffer_fx[0], hMcMasa->chnlToFoaEvenMtx_fx[1][0], FoaEven_ImagBuffer_fx[1], num_freq_bins );/*q*/ - FOR ( i = 1; i < numAnalysisChannels; i++ ) + v_multc_fixed( Chnl_RealBuffer_fx[0], hMcMasa->chnlToFoaEvenMtx_fx[1][0], FoaEven_RealBuffer_fx[1], num_freq_bins ); /*q*/ + v_multc_fixed( Chnl_ImagBuffer_fx[0], hMcMasa->chnlToFoaEvenMtx_fx[1][0], FoaEven_ImagBuffer_fx[1], num_freq_bins ); /*q*/ + FOR( i = 1; i < numAnalysisChannels; i++ ) { - v_multc_acc_32_32( Chnl_RealBuffer_fx[i], hMcMasa->chnlToFoaEvenMtx_fx[1][i], FoaEven_RealBuffer_fx[1], num_freq_bins );/*q*/ - v_multc_acc_32_32( Chnl_ImagBuffer_fx[i], hMcMasa->chnlToFoaEvenMtx_fx[1][i], FoaEven_ImagBuffer_fx[1], num_freq_bins );/*q*/ + v_multc_acc_32_32( Chnl_RealBuffer_fx[i], hMcMasa->chnlToFoaEvenMtx_fx[1][i], FoaEven_RealBuffer_fx[1], num_freq_bins ); /*q*/ + v_multc_acc_32_32( Chnl_ImagBuffer_fx[i], hMcMasa->chnlToFoaEvenMtx_fx[1][i], FoaEven_ImagBuffer_fx[1], num_freq_bins ); /*q*/ } /* Z (even setups are handled as horizontal) */ @@ -1048,7 +1048,7 @@ void ivas_mcmasa_param_est_ana_fx( /* X */ v_multc_fixed( Chnl_RealBuffer_fx[0], hMcMasa->chnlToFoaEvenMtx_fx[3][0], FoaEven_RealBuffer_fx[3], num_freq_bins ); v_multc_fixed( Chnl_ImagBuffer_fx[0], hMcMasa->chnlToFoaEvenMtx_fx[3][0], FoaEven_ImagBuffer_fx[3], num_freq_bins ); - FOR ( i = 1; i < numAnalysisChannels; i++ ) + FOR( i = 1; i < numAnalysisChannels; i++ ) { v_multc_acc_32_32( Chnl_RealBuffer_fx[i], hMcMasa->chnlToFoaEvenMtx_fx[3][i], FoaEven_RealBuffer_fx[3], num_freq_bins ); v_multc_acc_32_32( Chnl_ImagBuffer_fx[i], hMcMasa->chnlToFoaEvenMtx_fx[3][i], FoaEven_ImagBuffer_fx[3], num_freq_bins ); @@ -1057,16 +1057,16 @@ void ivas_mcmasa_param_est_ana_fx( /* Direction estimation */ computeIntensityVector_ana_fx( hMcMasa->band_grouping, Foa_RealBuffer_fx, Foa_ImagBuffer_fx, num_freq_bands, intensity_real_fx ); /*2+q-31*/ - computeDirectionVectors_fixed( intensity_real_fx[0], intensity_real_fx[1], intensity_real_fx[2], 0, num_freq_bands, direction_vector_fx[0], direction_vector_fx[1], direction_vector_fx[2],2*c_e );/*Q30*/ + computeDirectionVectors_fixed( intensity_real_fx[0], intensity_real_fx[1], intensity_real_fx[2], 0, num_freq_bands, direction_vector_fx[0], direction_vector_fx[1], direction_vector_fx[2], 2 * c_e ); /*Q30*/ /* Power and intensity estimation for diffuseness */ - computeIntensityVector_ana_fx( hMcMasa->band_grouping, FoaEven_RealBuffer_fx, FoaEven_ImagBuffer_fx, num_freq_bands, intensity_even_real_fx );/*2*(q)-31*/ - computeReferencePower_ana_fx( hMcMasa->band_grouping, FoaEven_RealBuffer_fx, FoaEven_ImagBuffer_fx, reference_power_fx[ts], num_freq_bands );/*2*q-30*/ + computeIntensityVector_ana_fx( hMcMasa->band_grouping, FoaEven_RealBuffer_fx, FoaEven_ImagBuffer_fx, num_freq_bands, intensity_even_real_fx ); /*2*(q)-31*/ + computeReferencePower_ana_fx( hMcMasa->band_grouping, FoaEven_RealBuffer_fx, FoaEven_ImagBuffer_fx, reference_power_fx[ts], num_freq_bands ); /*2*q-30*/ /* Fill buffers of length "averaging_length" time slots for intensity and energy */ hMcMasa->index_buffer_intensity = ( hMcMasa->index_buffer_intensity % DIRAC_NO_COL_AVG_DIFF ) + 1; /* averaging_length = 32 */ index = hMcMasa->index_buffer_intensity; - FOR ( i = 0; i < DIRAC_NUM_DIMS; i++ ) + FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) { /* only real part needed */ Copy32( intensity_even_real_fx[i], &( hMcMasa->buffer_intensity_real_fx[i][index - 1][0] ), num_freq_bands ); @@ -1074,52 +1074,52 @@ void ivas_mcmasa_param_est_ana_fx( hMcMasa->buffer_intensity_real_q[index - 1] = 2 * inp_q - 31; Copy32( reference_power_fx[ts], &( hMcMasa->buffer_energy_fx[( index - 1 ) * num_freq_bands] ), num_freq_bands ); hMcMasa->buffer_energy_q[index - 1] = 2 * inp_q - 30; - computeDiffuseness_fixed( hMcMasa->buffer_intensity_real_fx, hMcMasa->buffer_energy_fx, num_freq_bands, diffuseness_vector_fx ,hMcMasa->buffer_intensity_real_q, hMcMasa->buffer_energy_q,out_exp); + computeDiffuseness_fixed( hMcMasa->buffer_intensity_real_fx, hMcMasa->buffer_energy_fx, num_freq_bands, diffuseness_vector_fx, hMcMasa->buffer_intensity_real_q, hMcMasa->buffer_energy_q, out_exp ); /* Compute vertical diffuseness, and tune original diffuseness if needed */ - IF ( !hMcMasa->isHorizontalSetup ) + IF( !hMcMasa->isHorizontalSetup ) { Copy32( intensity_real_fx[2], &( hMcMasa->buffer_intensity_real_vert_fx[index - 1][0] ), num_freq_bands ); hMcMasa->buffer_intensity_real_vert_q[index - 1] = 2 * inp_q - 31; - computeVerticalDiffuseness_fx( hMcMasa->buffer_intensity_real_vert_fx, hMcMasa->buffer_energy_fx, num_freq_bands, vertical_diffuseness_vector_fx , hMcMasa->buffer_intensity_real_vert_q, hMcMasa->buffer_energy_q); - v_min_fx( diffuseness_vector_fx,out_exp, vertical_diffuseness_vector_fx,q_vdv, diffuseness_vector_fx,out_exp, num_freq_bands ); + computeVerticalDiffuseness_fx( hMcMasa->buffer_intensity_real_vert_fx, hMcMasa->buffer_energy_fx, num_freq_bands, vertical_diffuseness_vector_fx, hMcMasa->buffer_intensity_real_vert_q, hMcMasa->buffer_energy_q ); + v_min_fx( diffuseness_vector_fx, out_exp, vertical_diffuseness_vector_fx, q_vdv, diffuseness_vector_fx, out_exp, num_freq_bands ); } - FOR ( band_m_idx = 0; band_m_idx < hMcMasa->nbands; band_m_idx++ ) + FOR( band_m_idx = 0; band_m_idx < hMcMasa->nbands; band_m_idx++ ) { norm_tmp_fx = L_shl( Mult_32_32( reference_power_fx[ts][band_m_idx], L_sub( ONE_IN_Q30, diffuseness_vector_fx[band_m_idx] ) ), 1 ); /*2q-30*/ hMcMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx] = BASOP_Util_Add_Mant32Exp( hMcMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx], hMcMasa->direction_vector_e[0][block_m_idx][band_m_idx], Mult_32_32( norm_tmp_fx, direction_vector_fx[0][band_m_idx] ), 2 * c_e, &hMcMasa->direction_vector_e[0][block_m_idx][band_m_idx] ); hMcMasa->direction_vector_m_fx[1][block_m_idx][band_m_idx] = BASOP_Util_Add_Mant32Exp( hMcMasa->direction_vector_m_fx[1][block_m_idx][band_m_idx], hMcMasa->direction_vector_e[1][block_m_idx][band_m_idx], Mult_32_32( norm_tmp_fx, direction_vector_fx[1][band_m_idx] ), 2 * c_e, &hMcMasa->direction_vector_e[1][block_m_idx][band_m_idx] ); hMcMasa->direction_vector_m_fx[2][block_m_idx][band_m_idx] = BASOP_Util_Add_Mant32Exp( hMcMasa->direction_vector_m_fx[2][block_m_idx][band_m_idx], hMcMasa->direction_vector_e[2][block_m_idx][band_m_idx], Mult_32_32( norm_tmp_fx, direction_vector_fx[2][band_m_idx] ), 2 * c_e, &hMcMasa->direction_vector_e[2][block_m_idx][band_m_idx] ); - diffuseness_m_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( diffuseness_m_fx[band_m_idx], diffuseness_e[band_m_idx], L_shl( Mult_32_32( reference_power_fx[ts][band_m_idx], diffuseness_vector_fx[band_m_idx] ), 1 ), 2 * c_e - 1, &diffuseness_e[band_m_idx]); - renormalization_factor_diff_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( renormalization_factor_diff_fx[band_m_idx], renormalization_factor_diff_e[band_m_idx], reference_power_fx[ts][band_m_idx], 2 * c_e - 1, &renormalization_factor_diff_e[band_m_idx]); + diffuseness_m_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( diffuseness_m_fx[band_m_idx], diffuseness_e[band_m_idx], L_shl( Mult_32_32( reference_power_fx[ts][band_m_idx], diffuseness_vector_fx[band_m_idx] ), 1 ), 2 * c_e - 1, &diffuseness_e[band_m_idx] ); + renormalization_factor_diff_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( renormalization_factor_diff_fx[band_m_idx], renormalization_factor_diff_e[band_m_idx], reference_power_fx[ts][band_m_idx], 2 * c_e - 1, &renormalization_factor_diff_e[band_m_idx] ); } } - FOR ( band_m_idx = 0; band_m_idx < hMcMasa->nbands; band_m_idx++ ) + FOR( band_m_idx = 0; band_m_idx < hMcMasa->nbands; band_m_idx++ ) { - Word16 max_e=MIN_16; - FOR ( d = 0; d < DIRAC_NUM_DIMS; d++ ) + Word16 max_e = MIN_16; + FOR( d = 0; d < DIRAC_NUM_DIMS; d++ ) { - max_e = s_max( max_e, hMcMasa->direction_vector_e[d][block_m_idx][band_m_idx]); + max_e = s_max( max_e, hMcMasa->direction_vector_e[d][block_m_idx][band_m_idx] ); } - max_e =add(max_e,1);/*1 as guard bit to prevent overflow*/ - FOR ( d = 0; d < DIRAC_NUM_DIMS; d++ ) + max_e = add( max_e, 1 ); /*1 as guard bit to prevent overflow*/ + FOR( d = 0; d < DIRAC_NUM_DIMS; d++ ) { - dir_v_fx[d] = L_shr(hMcMasa->direction_vector_m_fx[d][block_m_idx][band_m_idx], max_e-hMcMasa->direction_vector_e[d][block_m_idx][band_m_idx]); + dir_v_fx[d] = L_shr( hMcMasa->direction_vector_m_fx[d][block_m_idx][band_m_idx], max_e - hMcMasa->direction_vector_e[d][block_m_idx][band_m_idx] ); } - Word16 div_q = sub(31, max_e); - ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( dir_v_fx,div_q, &azimuth_m_values_fx[block_m_idx][band_m_idx], &elevation_m_values_fx[block_m_idx][band_m_idx] ); + Word16 div_q = sub( 31, max_e ); + ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( dir_v_fx, div_q, &azimuth_m_values_fx[block_m_idx][band_m_idx], &elevation_m_values_fx[block_m_idx][band_m_idx] ); elevation_m_values_fx[block_m_idx][band_m_idx] = L_add( elevation_m_values_fx[block_m_idx][band_m_idx], L_shr( elevation_m_values_fx[block_m_idx][band_m_idx], 5 ) ); } /* Coherence processing */ - FOR ( band_m_idx = 0; band_m_idx < hMcMasa->nbands; band_m_idx++ ) + FOR( band_m_idx = 0; band_m_idx < hMcMasa->nbands; band_m_idx++ ) { /* Compute absolute values */ - FOR ( i = 0; i < numAnalysisChannels; i++ ) + FOR( i = 0; i < numAnalysisChannels; i++ ) { - FOR ( j = i; j < numAnalysisChannels; j++ ) + FOR( j = i; j < numAnalysisChannels; j++ ) { - Word32 temp=BASOP_Util_Add_Mant32Exp(Mult_32_32(COVls[band_m_idx].xr_fx[i][j] , COVls[band_m_idx].xr_fx[i][j]), 2*COVls[band_m_idx].xr_e[i][j],Mult_32_32(COVls[band_m_idx].xi_fx[i][j] , COVls[band_m_idx].xi_fx[i][j]),2* COVls[band_m_idx].xi_e[i][j],&absCOVls_e[i][j]); - absCOVls_fx[i][j] = Sqrt32(temp, &absCOVls_e[i][j]); + Word32 temp = BASOP_Util_Add_Mant32Exp( Mult_32_32( COVls[band_m_idx].xr_fx[i][j], COVls[band_m_idx].xr_fx[i][j] ), 2 * COVls[band_m_idx].xr_e[i][j], Mult_32_32( COVls[band_m_idx].xi_fx[i][j], COVls[band_m_idx].xi_fx[i][j] ), 2 * COVls[band_m_idx].xi_e[i][j], &absCOVls_e[i][j] ); + absCOVls_fx[i][j] = Sqrt32( temp, &absCOVls_e[i][j] ); } lsEnergy_fx[i] = absCOVls_fx[i][i]; lsEnergy_e[i] = absCOVls_e[i][i]; @@ -1129,9 +1129,9 @@ void ivas_mcmasa_param_est_ana_fx( maxEne_fx = lsEnergy_fx[0]; maxEne_e = lsEnergy_e[0]; loudestCh = 0; - FOR ( i = 1; i < numAnalysisChannels; i++ ) + FOR( i = 1; i < numAnalysisChannels; i++ ) { - IF (EQ_16(BASOP_Util_Cmp_Mant32Exp( lsEnergy_fx[i] , lsEnergy_e[i] , maxEne_fx, maxEne_e),1) ) + IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( lsEnergy_fx[i], lsEnergy_e[i], maxEne_fx, maxEne_e ), 1 ) ) { maxEne_fx = lsEnergy_fx[i]; maxEne_e = lsEnergy_e[i]; @@ -1142,11 +1142,11 @@ void ivas_mcmasa_param_est_ana_fx( /* Compute surrounding coherence */ surrCoh_fx = ONE_IN_Q31; surrCoh_e = 0; - FOR ( i = 0; i < numAnalysisChannels; i++ ) + FOR( i = 0; i < numAnalysisChannels; i++ ) { - IF ( NE_16(i , loudestCh) ) + IF( NE_16( i, loudestCh ) ) { - IF ( LT_16(i , loudestCh) ) + IF( LT_16( i, loudestCh ) ) { i1 = i; i2 = loudestCh; @@ -1156,12 +1156,12 @@ void ivas_mcmasa_param_est_ana_fx( i1 = loudestCh; i2 = i; } - Word16 temp_exp= lsEnergy_e[i1]+ lsEnergy_e[i2]; - Word32 temp = Sqrt32(L_add(Mult_32_32(lsEnergy_fx[i1] , lsEnergy_fx[i2]), EPSILON_FX),&temp_exp); + Word16 temp_exp = lsEnergy_e[i1] + lsEnergy_e[i2]; + Word32 temp = Sqrt32( L_add( Mult_32_32( lsEnergy_fx[i1], lsEnergy_fx[i2] ), EPSILON_FX ), &temp_exp ); tempCoh_e = 0; - tempCoh_fx = L_shl(BASOP_Util_Divide3232_Scale(absCOVls_fx[i1][i2] , temp,&tempCoh_e),16); + tempCoh_fx = L_shl( BASOP_Util_Divide3232_Scale( absCOVls_fx[i1][i2], temp, &tempCoh_e ), 16 ); tempCoh_e = absCOVls_e[i1][i2] - temp_exp + tempCoh_e; - IF ( NE_16(BASOP_Util_Cmp_Mant32Exp( surrCoh_fx, surrCoh_e, tempCoh_fx, tempCoh_e ) , -1) ) + IF( NE_16( BASOP_Util_Cmp_Mant32Exp( surrCoh_fx, surrCoh_e, tempCoh_fx, tempCoh_e ), -1 ) ) { surrCoh_fx = tempCoh_fx; surrCoh_e = tempCoh_e; @@ -1170,23 +1170,23 @@ void ivas_mcmasa_param_est_ana_fx( } surrCoh_fx = L_shl( surrCoh_fx, surrCoh_e ); surrCoh_e = 0; - surrCoh_fx = Mult_32_32(surrCoh_fx , surrCoh_fx); - surrCoh_fx = ( LT_32(surrCoh_fx , ONE_IN_Q31)) ? surrCoh_fx : ONE_IN_Q31; - surrCoh_fx = ( GT_32(surrCoh_fx , 0) ) ? surrCoh_fx : 0; + surrCoh_fx = Mult_32_32( surrCoh_fx, surrCoh_fx ); + surrCoh_fx = ( LT_32( surrCoh_fx, ONE_IN_Q31 ) ) ? surrCoh_fx : ONE_IN_Q31; + surrCoh_fx = ( GT_32( surrCoh_fx, 0 ) ) ? surrCoh_fx : 0; /* Compute spread coherence */ - IF ( LT_32(elevation_m_values_fx[block_m_idx][band_m_idx] , NEAR_HORIZONTAL_PLANE_ELEVATION_FX) ) /* Computed only near horizontal plane */ + IF( LT_32( elevation_m_values_fx[block_m_idx][band_m_idx], NEAR_HORIZONTAL_PLANE_ELEVATION_FX ) ) /* Computed only near horizontal plane */ { - minAngleDist_fx = 754974720;/*Q22*/ + minAngleDist_fx = 754974720; /*Q22*/ i1 = 0; currentAzi_fx = azimuth_m_values_fx[block_m_idx][band_m_idx]; - FOR ( i = 0; i < hMcMasa->numHorizontalChannels; i++ ) + FOR( i = 0; i < hMcMasa->numHorizontalChannels; i++ ) { - angleDist_fx = L_abs( L_sub(currentAzi_fx , hMcMasa->ls_azimuth_fx[i]) ); - IF ( GT_32(angleDist_fx , 754974720/*180.0f Q.22*/)) + angleDist_fx = L_abs( L_sub( currentAzi_fx, hMcMasa->ls_azimuth_fx[i] ) ); + IF( GT_32( angleDist_fx, 754974720 /*180.0f Q.22*/ ) ) { - angleDist_fx = L_abs( L_sub(angleDist_fx , 1509949440) ); + angleDist_fx = L_abs( L_sub( angleDist_fx, 1509949440 ) ); } - IF ( LT_32(angleDist_fx , minAngleDist_fx) ) + IF( LT_32( angleDist_fx, minAngleDist_fx ) ) { minAngleDist_fx = angleDist_fx; i1 = i; @@ -1194,17 +1194,17 @@ void ivas_mcmasa_param_est_ana_fx( } i2 = hMcMasa->leftNearest[i1]; i3 = hMcMasa->rightNearest[i1]; - Word16 temp_e= add(lsEnergy_e[i2], lsEnergy_e[i3]); - Word32 temp = Sqrt32( Mult_32_32(lsEnergy_fx[i2] , lsEnergy_fx[i3]) + EPSILON_FX ,&temp_e); - IF ( LT_16(i2 , i3 )) + Word16 temp_e = add( lsEnergy_e[i2], lsEnergy_e[i3] ); + Word32 temp = Sqrt32( Mult_32_32( lsEnergy_fx[i2], lsEnergy_fx[i3] ) + EPSILON_FX, &temp_e ); + IF( LT_16( i2, i3 ) ) { - stereoCoh_fx = BASOP_Util_Divide3232_Scale(absCOVls_fx[i2][i3] , temp,&stereoCoh_e); - stereoCoh_e = add(sub(absCOVls_e[i2][i3] , temp_e) , stereoCoh_e); + stereoCoh_fx = BASOP_Util_Divide3232_Scale( absCOVls_fx[i2][i3], temp, &stereoCoh_e ); + stereoCoh_e = add( sub( absCOVls_e[i2][i3], temp_e ), stereoCoh_e ); } ELSE { - stereoCoh_fx = BASOP_Util_Divide3232_Scale(absCOVls_fx[i3][i2], temp, &stereoCoh_e ); - stereoCoh_e = add(sub(absCOVls_e[i3][i2] , temp_e) , stereoCoh_e); + stereoCoh_fx = BASOP_Util_Divide3232_Scale( absCOVls_fx[i3][i2], temp, &stereoCoh_e ); + stereoCoh_e = add( sub( absCOVls_e[i3][i2], temp_e ), stereoCoh_e ); } stereoCoh_fx = L_shl( stereoCoh_fx, 16 ); Word32 temp1, temp2; @@ -1213,37 +1213,37 @@ void ivas_mcmasa_param_est_ana_fx( temp2 = BASOP_Util_Add_Mant32Exp( temp1, temp1_e, lsEnergy_fx[i1], lsEnergy_e[i1], &temp2_e ); temp2 = L_add( temp2, EPSILON_FX ); lsEnergyRelation_fx = BASOP_Util_Divide3232_Scale( temp1, temp2, &lsEnergyRelation_e ); - lsEnergyRelation_e = add(lsEnergyRelation_e,sub(temp1_e , temp2_e)); - lsEnergyRelation_fx = L_shl(lsEnergyRelation_fx, 16+lsEnergyRelation_e ); - stereoness_fx = Mult_32_32(stereoCoh_fx , lsEnergyRelation_fx); + lsEnergyRelation_e = add( lsEnergyRelation_e, sub( temp1_e, temp2_e ) ); + lsEnergyRelation_fx = L_shl( lsEnergyRelation_fx, 16 + lsEnergyRelation_e ); + stereoness_fx = Mult_32_32( stereoCoh_fx, lsEnergyRelation_fx ); stereoness_e = stereoCoh_e; - IF ( LT_16(i1 , i2) ) + IF( LT_16( i1, i2 ) ) { - temp_e = add(lsEnergy_e[i1] , lsEnergy_e[i2]); - tempCoh_fx = BASOP_Util_Divide3232_Scale(absCOVls_fx[i1][i2] , ( Sqrt32( L_add(Mult_32_32(lsEnergy_fx[i1] , lsEnergy_fx[i2]) , EPSILON_FX ),&temp_e) ), &tempCoh_e); - tempCoh_e = add(tempCoh_e,sub(absCOVls_e[i1][i2] , temp_e)); + temp_e = add( lsEnergy_e[i1], lsEnergy_e[i2] ); + tempCoh_fx = BASOP_Util_Divide3232_Scale( absCOVls_fx[i1][i2], ( Sqrt32( L_add( Mult_32_32( lsEnergy_fx[i1], lsEnergy_fx[i2] ), EPSILON_FX ), &temp_e ) ), &tempCoh_e ); + tempCoh_e = add( tempCoh_e, sub( absCOVls_e[i1][i2], temp_e ) ); } ELSE { - temp_e = add(lsEnergy_e[i1] , lsEnergy_e[i2]); + temp_e = add( lsEnergy_e[i1], lsEnergy_e[i2] ); tempCoh_fx = BASOP_Util_Divide3232_Scale( absCOVls_fx[i2][i1], ( Sqrt32( L_add( Mult_32_32( lsEnergy_fx[i1], lsEnergy_fx[i2] ), EPSILON_FX ), &temp_e ) ), &tempCoh_e ); - tempCoh_e = add(tempCoh_e,sub(absCOVls_e[i2][i1] , temp_e)); + tempCoh_e = add( tempCoh_e, sub( absCOVls_e[i2][i1], temp_e ) ); } tempCoh_fx = L_shl( tempCoh_fx, 16 ); - IF ( LT_16(i1 , i3) ) + IF( LT_16( i1, i3 ) ) { temp_e = lsEnergy_e[i1] + lsEnergy_e[i3]; tempCoh2_fx = BASOP_Util_Divide3232_Scale( absCOVls_fx[i1][i3], ( Sqrt32( L_add( Mult_32_32( lsEnergy_fx[i1], lsEnergy_fx[i3] ), EPSILON_FX ), &temp_e ) ), &tempCoh2_e ); - tempCoh2_e = add(tempCoh2_e,sub(absCOVls_e[i1][i3] , temp_e)); + tempCoh2_e = add( tempCoh2_e, sub( absCOVls_e[i1][i3], temp_e ) ); } ELSE { temp_e = lsEnergy_e[i1] + lsEnergy_e[i3]; tempCoh2_fx = BASOP_Util_Divide3232_Scale( absCOVls_fx[i3][i1], ( Sqrt32( L_add( Mult_32_32( lsEnergy_fx[i1], lsEnergy_fx[i3] ), EPSILON_FX ), &temp_e ) ), &tempCoh2_e ); - tempCoh2_e = add(tempCoh2_e,sub(absCOVls_e[i3][i1] , temp_e)); + tempCoh2_e = add( tempCoh2_e, sub( absCOVls_e[i3][i1], temp_e ) ); } tempCoh2_fx = L_shl( tempCoh2_fx, 16 ); - IF ( EQ_16(BASOP_Util_Cmp_Mant32Exp( tempCoh_fx, tempCoh_e, tempCoh2_fx, tempCoh2_e ) , -1) ) + IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( tempCoh_fx, tempCoh_e, tempCoh2_fx, tempCoh2_e ), -1 ) ) { cohPanCoh_fx = tempCoh_fx; cohPanCoh_e = tempCoh_e; @@ -1253,35 +1253,35 @@ void ivas_mcmasa_param_est_ana_fx( cohPanCoh_fx = tempCoh2_fx; cohPanCoh_e = tempCoh2_e; } - cohPanCoh_fx = L_shl( cohPanCoh_fx, cohPanCoh_e );/*Q31*/ + cohPanCoh_fx = L_shl( cohPanCoh_fx, cohPanCoh_e ); /*Q31*/ cohPanCoh_e = 0; - lsEnergyRelation_fx = BASOP_Util_Divide3232_Scale(lsEnergy_fx[i2] , L_add( lsEnergy_fx[i1] , EPSILON_FX ), &lsEnergyRelation_e); + lsEnergyRelation_fx = BASOP_Util_Divide3232_Scale( lsEnergy_fx[i2], L_add( lsEnergy_fx[i1], EPSILON_FX ), &lsEnergyRelation_e ); lsEnergyRelation_e += lsEnergy_e[i2] - lsEnergy_e[i1]; - tempLsEnergyRelation_fx = BASOP_Util_Divide3232_Scale(lsEnergy_fx[i1] , L_add( lsEnergy_fx[i2] , EPSILON_FX ), &tempLsEnergyRelation_e); + tempLsEnergyRelation_fx = BASOP_Util_Divide3232_Scale( lsEnergy_fx[i1], L_add( lsEnergy_fx[i2], EPSILON_FX ), &tempLsEnergyRelation_e ); tempLsEnergyRelation_e += lsEnergy_e[i1] - lsEnergy_e[i2]; - IF ( NE_16(BASOP_Util_Cmp_Mant32Exp( lsEnergyRelation_fx, lsEnergyRelation_e, tempLsEnergyRelation_fx, tempLsEnergyRelation_e ),-1) ) + IF( NE_16( BASOP_Util_Cmp_Mant32Exp( lsEnergyRelation_fx, lsEnergyRelation_e, tempLsEnergyRelation_fx, tempLsEnergyRelation_e ), -1 ) ) { lsEnergyRelation_fx = tempLsEnergyRelation_fx; lsEnergyRelation_e = tempLsEnergyRelation_e; } tempLsEnergyRelation_fx = BASOP_Util_Divide3232_Scale( lsEnergy_fx[i3], L_add( lsEnergy_fx[i1], EPSILON_FX ), &tempLsEnergyRelation_e ); - tempLsEnergyRelation_e = add(tempLsEnergyRelation_e,sub(lsEnergy_e[i3] , lsEnergy_e[i1])); - IF ( NE_16(BASOP_Util_Cmp_Mant32Exp( lsEnergyRelation_fx, lsEnergyRelation_e, tempLsEnergyRelation_fx, tempLsEnergyRelation_e ) , -1) ) + tempLsEnergyRelation_e = add( tempLsEnergyRelation_e, sub( lsEnergy_e[i3], lsEnergy_e[i1] ) ); + IF( NE_16( BASOP_Util_Cmp_Mant32Exp( lsEnergyRelation_fx, lsEnergyRelation_e, tempLsEnergyRelation_fx, tempLsEnergyRelation_e ), -1 ) ) { lsEnergyRelation_fx = tempLsEnergyRelation_fx; lsEnergyRelation_e = tempLsEnergyRelation_e; } - tempLsEnergyRelation_fx = BASOP_Util_Divide3232_Scale(lsEnergy_fx[i1] , ( lsEnergy_fx[i3] + EPSILON_FX ), &tempLsEnergyRelation_e); - tempLsEnergyRelation_e = add(tempLsEnergyRelation_e,sub(lsEnergy_e[i1] , lsEnergy_e[i3])); - IF ( NE_16(BASOP_Util_Cmp_Mant32Exp( lsEnergyRelation_fx, lsEnergyRelation_e, tempLsEnergyRelation_fx, tempLsEnergyRelation_e ) , -1) ) + tempLsEnergyRelation_fx = BASOP_Util_Divide3232_Scale( lsEnergy_fx[i1], ( lsEnergy_fx[i3] + EPSILON_FX ), &tempLsEnergyRelation_e ); + tempLsEnergyRelation_e = add( tempLsEnergyRelation_e, sub( lsEnergy_e[i1], lsEnergy_e[i3] ) ); + IF( NE_16( BASOP_Util_Cmp_Mant32Exp( lsEnergyRelation_fx, lsEnergyRelation_e, tempLsEnergyRelation_fx, tempLsEnergyRelation_e ), -1 ) ) { lsEnergyRelation_fx = tempLsEnergyRelation_fx; lsEnergyRelation_e = tempLsEnergyRelation_e; } - lsEnergyRelation_fx = L_shl( lsEnergyRelation_fx,16+ lsEnergyRelation_e );/*Q31*/ - cohwideness_fx = Mult_32_32(cohPanCoh_fx , lsEnergyRelation_fx);/*cohPanCoh_e*/ + lsEnergyRelation_fx = L_shl( lsEnergyRelation_fx, 16 + lsEnergyRelation_e ); /*Q31*/ + cohwideness_fx = Mult_32_32( cohPanCoh_fx, lsEnergyRelation_fx ); /*cohPanCoh_e*/ - IF (EQ_16(BASOP_Util_Cmp_Mant32Exp( cohwideness_fx , cohPanCoh_e, stereoness_fx, stereoness_e),1) ) + IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( cohwideness_fx, cohPanCoh_e, stereoness_fx, stereoness_e ), 1 ) ) { spreadCoh_fx = cohwideness_fx; spreadCoh_e = cohPanCoh_e; @@ -1291,91 +1291,91 @@ void ivas_mcmasa_param_est_ana_fx( spreadCoh_fx = stereoness_fx; spreadCoh_e = stereoness_e; } - IF ( LT_16(spreadCoh_e , 0) ) + IF( LT_16( spreadCoh_e, 0 ) ) { spreadCoh_fx = L_shl( spreadCoh_fx, spreadCoh_e ); spreadCoh_e = 0; } - IF ( GT_32( spreadCoh_fx, L_shl_sat( 1, 31 - spreadCoh_e - 1 /*0.5f with exp=spreadCoh_e*/) ) ) + IF( GT_32( spreadCoh_fx, L_shl_sat( 1, 31 - spreadCoh_e - 1 /*0.5f with exp=spreadCoh_e*/ ) ) ) { - IF (EQ_16(BASOP_Util_Cmp_Mant32Exp(cohwideness_fx , cohPanCoh_e, stereoness_fx, stereoness_e),1) ) + IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( cohwideness_fx, cohPanCoh_e, stereoness_fx, stereoness_e ), 1 ) ) { - tempCoh_fx = BASOP_Util_Add_Mant32Exp(stereoness_fx , stereoness_e, -L_sub( cohwideness_fx , L_shl(1, 31-cohPanCoh_e-1) ), cohPanCoh_e,&tempCoh_e); - IF ( LT_16(tempCoh_e , 0) ) + tempCoh_fx = BASOP_Util_Add_Mant32Exp( stereoness_fx, stereoness_e, -L_sub( cohwideness_fx, L_shl( 1, 31 - cohPanCoh_e - 1 ) ), cohPanCoh_e, &tempCoh_e ); + IF( LT_16( tempCoh_e, 0 ) ) { tempCoh_fx = L_shl( tempCoh_fx, tempCoh_e ); tempCoh_e = 0; } - spreadCoh_fx = GT_32( tempCoh_fx , L_shl_sat(1,31- tempCoh_e-1) ) ? tempCoh_fx : L_shl_sat(1, 31 - tempCoh_e - 1); + spreadCoh_fx = GT_32( tempCoh_fx, L_shl_sat( 1, 31 - tempCoh_e - 1 ) ) ? tempCoh_fx : L_shl_sat( 1, 31 - tempCoh_e - 1 ); spreadCoh_e = tempCoh_e; } } - IF ( LT_16(spreadCoh_e , 0) ) + IF( LT_16( spreadCoh_e, 0 ) ) { spreadCoh_fx = L_shl( spreadCoh_fx, spreadCoh_e ); spreadCoh_e = 0; } - spreadCoh_fx = ( LT_32(spreadCoh_fx , L_shl_sat(1,31- spreadCoh_e))) ? spreadCoh_fx : L_shl_sat(1,31- spreadCoh_e); + spreadCoh_fx = ( LT_32( spreadCoh_fx, L_shl_sat( 1, 31 - spreadCoh_e ) ) ) ? spreadCoh_fx : L_shl_sat( 1, 31 - spreadCoh_e ); spreadCoh_fx = ( spreadCoh_fx > 0 ) ? spreadCoh_fx : 0; - spreadCoh_fx = L_shl( spreadCoh_fx, spreadCoh_e );/*Q31*/ + spreadCoh_fx = L_shl( spreadCoh_fx, spreadCoh_e ); /*Q31*/ /* Compute energy ratio tuning parameter */ lsEnergySum_fx = 0; lsEnergySum_e = 0; - FOR ( i = 0; i < numAnalysisChannels; i++ ) + FOR( i = 0; i < numAnalysisChannels; i++ ) { - lsEnergySum_fx = BASOP_Util_Add_Mant32Exp(lsEnergy_fx[i],lsEnergy_e[i], lsEnergySum_fx, lsEnergySum_e,&lsEnergySum_e); + lsEnergySum_fx = BASOP_Util_Add_Mant32Exp( lsEnergy_fx[i], lsEnergy_e[i], lsEnergySum_fx, lsEnergySum_e, &lsEnergySum_e ); } - lsEnergySum_fx = L_add_sat(lsEnergySum_fx,EPSILON_FX); - lsEnergyRelation_fx = BASOP_Util_Divide3232_Scale(temp1, lsEnergySum_fx, &lsEnergyRelation_e ); - lsEnergyRelation_e = add(lsEnergyRelation_e,sub(temp1_e , lsEnergySum_e)); - lsEnergyRelation_fx = L_shl(lsEnergyRelation_fx,16+lsEnergyRelation_e ); - stereoRatio_fx = L_sub(Mult_32_32(L_shl_sat(stereoCoh_fx, stereoCoh_e), lsEnergyRelation_fx) ,surrCoh_fx); + lsEnergySum_fx = L_add_sat( lsEnergySum_fx, EPSILON_FX ); + lsEnergyRelation_fx = BASOP_Util_Divide3232_Scale( temp1, lsEnergySum_fx, &lsEnergyRelation_e ); + lsEnergyRelation_e = add( lsEnergyRelation_e, sub( temp1_e, lsEnergySum_e ) ); + lsEnergyRelation_fx = L_shl( lsEnergyRelation_fx, 16 + lsEnergyRelation_e ); + stereoRatio_fx = L_sub( Mult_32_32( L_shl_sat( stereoCoh_fx, stereoCoh_e ), lsEnergyRelation_fx ), surrCoh_fx ); lsEnergyRelation_fx = BASOP_Util_Divide3232_Scale( temp2, lsEnergySum_fx, &lsEnergyRelation_e ); - lsEnergyRelation_e = add(lsEnergyRelation_e,sub(temp2_e , lsEnergySum_e)); + lsEnergyRelation_e = add( lsEnergyRelation_e, sub( temp2_e, lsEnergySum_e ) ); lsEnergyRelation_fx = L_shl( lsEnergyRelation_fx, 16 + lsEnergyRelation_e ); cohPanRatio_fx = L_sub( Mult_32_32( cohPanCoh_fx, lsEnergyRelation_fx ), surrCoh_fx ); - cohRatio_fx = GT_32( stereoRatio_fx , cohPanRatio_fx ) ? stereoRatio_fx : cohPanRatio_fx;/*Q31*/ - cohRatio_fx = ( LT_32(cohRatio_fx , ONE_IN_Q31) ) ? cohRatio_fx : ONE_IN_Q31; - cohRatio_fx = ( GT_32(cohRatio_fx , 0) ) ? cohRatio_fx : 0; + cohRatio_fx = GT_32( stereoRatio_fx, cohPanRatio_fx ) ? stereoRatio_fx : cohPanRatio_fx; /*Q31*/ + cohRatio_fx = ( LT_32( cohRatio_fx, ONE_IN_Q31 ) ) ? cohRatio_fx : ONE_IN_Q31; + cohRatio_fx = ( GT_32( cohRatio_fx, 0 ) ) ? cohRatio_fx : 0; } ELSE /* Otherwise, set spread coherence to zero */ { spreadCoh_fx = 0; cohRatio_fx = 0; lsEnergySum_fx = 0; - FOR ( i = 0; i < numAnalysisChannels; i++ ) + FOR( i = 0; i < numAnalysisChannels; i++ ) { lsEnergySum_fx = BASOP_Util_Add_Mant32Exp( lsEnergy_fx[i], lsEnergy_e[i], lsEnergySum_fx, lsEnergySum_e, &lsEnergySum_e ); } - lsEnergySum_fx =L_add_sat(lsEnergySum_fx, EPSILON_FX); + lsEnergySum_fx = L_add_sat( lsEnergySum_fx, EPSILON_FX ); } /* Store values */ - spreadCoherence_fx[block_m_idx][band_m_idx] = spreadCoh_fx;/*Q31*/ - surroundingCoherence_fx[block_m_idx][band_m_idx] = surrCoh_fx;/*Q31*/ - coherentEnergyRatio_fx[band_m_idx] = cohRatio_fx;/*Q31*/ + spreadCoherence_fx[block_m_idx][band_m_idx] = spreadCoh_fx; /*Q31*/ + surroundingCoherence_fx[block_m_idx][band_m_idx] = surrCoh_fx; /*Q31*/ + coherentEnergyRatio_fx[band_m_idx] = cohRatio_fx; /*Q31*/ } /* Determine energy ratios */ - FOR ( band_m_idx = 0; band_m_idx < hMcMasa->nbands; band_m_idx++ ) + FOR( band_m_idx = 0; band_m_idx < hMcMasa->nbands; band_m_idx++ ) { Word16 diffuseness_m_e; - IF ( GT_32(renormalization_factor_diff_fx[band_m_idx] , EPSILON_FX) ) + IF( GT_32( renormalization_factor_diff_fx[band_m_idx], EPSILON_FX ) ) { - diffuseness_m_fx[band_m_idx] =BASOP_Util_Divide3232_Scale(diffuseness_m_fx[band_m_idx], renormalization_factor_diff_fx[band_m_idx], &diffuseness_m_e); - diffuseness_m_e = add(diffuseness_m_e,sub(diffuseness_e[band_m_idx] , renormalization_factor_diff_e[band_m_idx])); - diffuseness_m_fx[band_m_idx] = L_shl_sat( diffuseness_m_fx[band_m_idx], 16+diffuseness_m_e ); + diffuseness_m_fx[band_m_idx] = BASOP_Util_Divide3232_Scale( diffuseness_m_fx[band_m_idx], renormalization_factor_diff_fx[band_m_idx], &diffuseness_m_e ); + diffuseness_m_e = add( diffuseness_m_e, sub( diffuseness_e[band_m_idx], renormalization_factor_diff_e[band_m_idx] ) ); + diffuseness_m_fx[band_m_idx] = L_shl_sat( diffuseness_m_fx[band_m_idx], 16 + diffuseness_m_e ); } ELSE { diffuseness_m_fx[band_m_idx] = 0; } - energyRatio_fx[block_m_idx][band_m_idx] = L_sub(ONE_IN_Q31 , diffuseness_m_fx[band_m_idx]); - energyRatio_fx[block_m_idx][band_m_idx] = GT_32( energyRatio_fx[block_m_idx][band_m_idx] , coherentEnergyRatio_fx[band_m_idx] ) ? energyRatio_fx[block_m_idx][band_m_idx] : coherentEnergyRatio_fx[band_m_idx]; + energyRatio_fx[block_m_idx][band_m_idx] = L_sub( ONE_IN_Q31, diffuseness_m_fx[band_m_idx] ); + energyRatio_fx[block_m_idx][band_m_idx] = GT_32( energyRatio_fx[block_m_idx][band_m_idx], coherentEnergyRatio_fx[band_m_idx] ) ? energyRatio_fx[block_m_idx][band_m_idx] : coherentEnergyRatio_fx[band_m_idx]; } } return; @@ -1900,50 +1900,48 @@ static void ivas_mcmasa_dmx_fx( multiChEne_fx = 0; multiChEne_e = 0; - FOR ( j = 0; j < numAnalysisChannels; j++ ) + FOR( j = 0; j < numAnalysisChannels; j++ ) { - FOR ( i = 0; i < input_frame; i++ ) + FOR( i = 0; i < input_frame; i++ ) { - L_tmp1 = BASOP_Util_Add_Mant32Exp(data_f_fx[j][i], data_e, 0, 0, &scale); - L_tmp = Mpy_32_32(L_tmp1, L_tmp1); // data_e + data_e - multiChEne_fx = BASOP_Util_Add_Mant32Exp(L_tmp, scale + scale, multiChEne_fx, multiChEne_e, &scale); + L_tmp1 = BASOP_Util_Add_Mant32Exp( data_f_fx[j][i], data_e, 0, 0, &scale ); + L_tmp = Mpy_32_32( L_tmp1, L_tmp1 ); // data_e + data_e + multiChEne_fx = BASOP_Util_Add_Mant32Exp( L_tmp, scale + scale, multiChEne_fx, multiChEne_e, &scale ); multiChEne_e = scale; } } - IF ( nchan_transport == 2 ) + IF( nchan_transport == 2 ) { Word16 numSideChannels; /* Channels other than left, right, center */ Word16 leftIndex, rightIndex; numSideChannels = numAnalysisChannels / 2 - 1; - FOR ( j = 0; j < numSideChannels; j++ ) + FOR( j = 0; j < numSideChannels; j++ ) { leftIndex = j * 2 + 3; rightIndex = j * 2 + 4; - FOR ( i = 0; i < input_frame; i++ ) + FOR( i = 0; i < input_frame; i++ ) { - data_f_fx[0][i] = L_add(data_f_fx[0][i], data_f_fx[leftIndex][i] ); - data_f_fx[1][i] = L_add(data_f_fx[1][i] , data_f_fx[rightIndex][i] ); - + data_f_fx[0][i] = L_add( data_f_fx[0][i], data_f_fx[leftIndex][i] ); + data_f_fx[1][i] = L_add( data_f_fx[1][i], data_f_fx[rightIndex][i] ); } } - FOR ( i = 0; i < input_frame; i++ ) + FOR( i = 0; i < input_frame; i++ ) { - dmx_c_fx = (Word32) W_shr(W_mult_32_32(INV_SQRT2_FX, data_f_fx[2][i]), 32 ); + dmx_c_fx = (Word32) W_shr( W_mult_32_32( INV_SQRT2_FX, data_f_fx[2][i] ), 32 ); data_f_fx[0][i] = L_add( dmx_c_fx, data_f_fx[0][i] ); data_f_fx[1][i] = L_add( dmx_c_fx, data_f_fx[1][i] ); - } } - ELSE IF ( nchan_transport == 1 ) + ELSE IF( nchan_transport == 1 ) { - FOR ( i = 0; i < input_frame; i++ ) + FOR( i = 0; i < input_frame; i++ ) { - FOR ( j = 1; j < numAnalysisChannels; j++ ) + FOR( j = 1; j < numAnalysisChannels; j++ ) { data_f_fx[0][i] = L_add( data_f_fx[0][i], data_f_fx[j][i] ); } @@ -1952,49 +1950,49 @@ static void ivas_mcmasa_dmx_fx( downmixEne_fx = 0; - FOR ( j = 0; j < nchan_transport; j++ ) + FOR( j = 0; j < nchan_transport; j++ ) { - FOR ( i = 0; i < input_frame; i++ ) + FOR( i = 0; i < input_frame; i++ ) { - L_tmp1 = BASOP_Util_Add_Mant32Exp(data_f_fx[j][i], data_e, 0, 0, &scale); - L_tmp = Mpy_32_32(L_tmp1, L_tmp1); // data_e + data_e - downmixEne_fx = BASOP_Util_Add_Mant32Exp(L_tmp, scale + scale, downmixEne_fx, downmixEne_e, &downmixEne_e); + L_tmp1 = BASOP_Util_Add_Mant32Exp( data_f_fx[j][i], data_e, 0, 0, &scale ); + L_tmp = Mpy_32_32( L_tmp1, L_tmp1 ); // data_e + data_e + downmixEne_fx = BASOP_Util_Add_Mant32Exp( L_tmp, scale + scale, downmixEne_fx, downmixEne_e, &downmixEne_e ); } } alpha_fx = 214748364; // Q31 - L_tmp = Mpy_32_32(alpha_fx, multiChEne_fx); + L_tmp = Mpy_32_32( alpha_fx, multiChEne_fx ); L_tmp1 = Mpy_32_32( 1932735284, hMcMasa->prevMultiChEne_fx ); - hMcMasa->prevMultiChEne_fx = BASOP_Util_Add_Mant32Exp(L_tmp, multiChEne_e, L_tmp1, hMcMasa->prevMultiChEne_e, &hMcMasa->prevMultiChEne_e ); + hMcMasa->prevMultiChEne_fx = BASOP_Util_Add_Mant32Exp( L_tmp, multiChEne_e, L_tmp1, hMcMasa->prevMultiChEne_e, &hMcMasa->prevMultiChEne_e ); - L_tmp = Mpy_32_32(alpha_fx, downmixEne_fx); - L_tmp1 = Mpy_32_32(1932735284, hMcMasa->prevDownmixEne_fx); - hMcMasa->prevDownmixEne_fx = BASOP_Util_Add_Mant32Exp(L_tmp, downmixEne_e, L_tmp1, hMcMasa->prevDownmixEne_e, &hMcMasa->prevDownmixEne_e); + L_tmp = Mpy_32_32( alpha_fx, downmixEne_fx ); + L_tmp1 = Mpy_32_32( 1932735284, hMcMasa->prevDownmixEne_fx ); + hMcMasa->prevDownmixEne_fx = BASOP_Util_Add_Mant32Exp( L_tmp, downmixEne_e, L_tmp1, hMcMasa->prevDownmixEne_e, &hMcMasa->prevDownmixEne_e ); prevEQ_fx = hMcMasa->prevEQ_fx; prevEQ_e = hMcMasa->prevEQ_e; - tmp = BASOP_Util_Divide3232_Scale(hMcMasa->prevMultiChEne_fx, L_add(hMcMasa->prevDownmixEne_fx, EPSILON_FX), &scale); - currEQ_e = scale + ( hMcMasa->prevMultiChEne_e - hMcMasa->prevDownmixEne_e); - currEQ_fx = Sqrt32(L_deposit_h(tmp), &currEQ_e); + tmp = BASOP_Util_Divide3232_Scale( hMcMasa->prevMultiChEne_fx, L_add( hMcMasa->prevDownmixEne_fx, EPSILON_FX ), &scale ); + currEQ_e = scale + ( hMcMasa->prevMultiChEne_e - hMcMasa->prevDownmixEne_e ); + currEQ_fx = Sqrt32( L_deposit_h( tmp ), &currEQ_e ); hMcMasa->prevEQ_fx = currEQ_fx; hMcMasa->prevEQ_e = currEQ_e; - FOR ( i = 0; i < input_frame; i++ ) + FOR( i = 0; i < input_frame; i++ ) { - L_tmp = Mpy_32_32(L_deposit_h(hMcMasa->interpolator_fx[i]), currEQ_fx); - L_tmp1 = L_sub(1073741824, L_lshr( L_deposit_h(hMcMasa->interpolator_fx[i]), 1 ) ); + L_tmp = Mpy_32_32( L_deposit_h( hMcMasa->interpolator_fx[i] ), currEQ_fx ); + L_tmp1 = L_sub( 1073741824, L_lshr( L_deposit_h( hMcMasa->interpolator_fx[i] ), 1 ) ); L_tmp1 = Mpy_32_32( L_tmp1, prevEQ_fx ); - instEQ_fx = BASOP_Util_Add_Mant32Exp(L_tmp, currEQ_e, L_tmp1, prevEQ_e + 1, &instEQ_e); + instEQ_fx = BASOP_Util_Add_Mant32Exp( L_tmp, currEQ_e, L_tmp1, prevEQ_e + 1, &instEQ_e ); - FOR ( j = 0; j < nchan_transport; j++ ) + FOR( j = 0; j < nchan_transport; j++ ) { data_f_fx[j][i] = Mpy_32_32( instEQ_fx, data_f_fx[j][i] ); - - data_f_fx[j][i] = L_shl(data_f_fx[j][i], instEQ_e); + + data_f_fx[j][i] = L_shl( data_f_fx[j][i], instEQ_e ); } } @@ -2010,35 +2008,35 @@ static void compute_cov_mtx_fx( Word32 si[MCMASA_MAX_ANA_CHANS][CLDFB_NO_CHANNELS_MAX], /* i : Input matrix, imag, s[ch][freq] */ const Word16 freq, /* i : Freq to process */ const Word16 N, /* i : Number of channels */ - CovarianceMatrix *COVls, /* o : Output matrix, contains upper part of cov mtx */ - Word16 inp_exp/*Stores exponent for temp*/ + CovarianceMatrix *COVls, /* o : Output matrix, contains upper part of cov mtx */ + Word16 inp_exp /*Stores exponent for temp*/ ) { Word16 i, j; Word32 a, b, c, d; Word32 temp; - Word16 norm_a,norm_b,norm_c, norm_d; + Word16 norm_a, norm_b, norm_c, norm_d; Word16 shift; - FOR ( i = 0; i < N; i++ ) + FOR( i = 0; i < N; i++ ) { a = sr[i][freq]; b = si[i][freq]; norm_a = norm_l( a ); norm_b = norm_l( b ); - a = L_shl( a, norm_a);/*inp_exp-norm_a*/ - b = L_shl( b, norm_b);/*inp_exp-norm_b*/ - FOR ( j = i; j < N; j++ ) + a = L_shl( a, norm_a ); /*inp_exp-norm_a*/ + b = L_shl( b, norm_b ); /*inp_exp-norm_b*/ + FOR( j = i; j < N; j++ ) { c = sr[j][freq]; d = si[j][freq]; - norm_c= norm_l( c ); + norm_c = norm_l( c ); norm_d = norm_l( d ); - c = L_shl( c, norm_c );/*inp_exp-norm_c*/ - d = L_shl( d, norm_d );/*inp_exp-norm_d*/ - temp = BASOP_Util_Add_Mant32Exp( Mult_32_32( a, c ), 2*inp_exp - norm_a-norm_c, Mult_32_32( b, d ), 2 * inp_exp - norm_b - norm_d,&shift);/*exp=inp_exp-norm_ab+inp_exp-norm_cd*/ - COVls->xr_fx[i][j] = BASOP_Util_Add_Mant32Exp( COVls->xr_fx[i][j], COVls->xr_e[i][j], temp,shift,&COVls->xr_e[i][j]); - temp = BASOP_Util_Add_Mant32Exp(Mult_32_32( b, c ), 2 * inp_exp - norm_b - norm_c,-Mult_32_32( a, d ), 2 * inp_exp - norm_a - norm_d, &shift); - COVls->xi_fx[i][j] = BASOP_Util_Add_Mant32Exp( COVls->xi_fx[i][j], COVls->xi_e[i][j], temp, shift,&COVls->xi_e[i][j]); + c = L_shl( c, norm_c ); /*inp_exp-norm_c*/ + d = L_shl( d, norm_d ); /*inp_exp-norm_d*/ + temp = BASOP_Util_Add_Mant32Exp( Mult_32_32( a, c ), 2 * inp_exp - norm_a - norm_c, Mult_32_32( b, d ), 2 * inp_exp - norm_b - norm_d, &shift ); /*exp=inp_exp-norm_ab+inp_exp-norm_cd*/ + COVls->xr_fx[i][j] = BASOP_Util_Add_Mant32Exp( COVls->xr_fx[i][j], COVls->xr_e[i][j], temp, shift, &COVls->xr_e[i][j] ); + temp = BASOP_Util_Add_Mant32Exp( Mult_32_32( b, c ), 2 * inp_exp - norm_b - norm_c, -Mult_32_32( a, d ), 2 * inp_exp - norm_a - norm_d, &shift ); + COVls->xi_fx[i][j] = BASOP_Util_Add_Mant32Exp( COVls->xi_fx[i][j], COVls->xi_e[i][j], temp, shift, &COVls->xi_e[i][j] ); } } @@ -2082,13 +2080,12 @@ static void compute_cov_mtx( *------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED static void computeVerticalDiffuseness_fx( - Word32 **buffer_intensity, /* i : Intensity vectors */ - const Word32 *buffer_energy, /* i : Energy */ + Word32 **buffer_intensity, /* i : Intensity vectors */ + const Word32 *buffer_energy, /* i : Energy */ const Word16 num_freq_bands, /* i : Number of frequency bands */ - Word32 *diffuseness , /* o : Estimated diffuseness */ + Word32 *diffuseness, /* o : Estimated diffuseness */ Word16 *buffer_intensity_q, - Word16 *buffer_energy_q -) + Word16 *buffer_energy_q ) { Word32 intensity_slow[MASA_FREQUENCY_BANDS]; Word32 intensity_slow_abs[MASA_FREQUENCY_BANDS]; @@ -2101,37 +2098,37 @@ static void computeVerticalDiffuseness_fx( /* Set variables to zero */ set32_fx( intensity_slow, 0, MASA_FREQUENCY_BANDS ); set32_fx( energy_slow, 0, MASA_FREQUENCY_BANDS ); - set16_fx(intensity_slow_e, 0, MASA_FREQUENCY_BANDS ); - set16_fx(energy_slow_e, 0, MASA_FREQUENCY_BANDS ); + set16_fx( intensity_slow_e, 0, MASA_FREQUENCY_BANDS ); + set16_fx( energy_slow_e, 0, MASA_FREQUENCY_BANDS ); - FOR ( i = 0; i < DIRAC_NO_COL_AVG_DIFF; ++i ) + FOR( i = 0; i < DIRAC_NO_COL_AVG_DIFF; ++i ) { /* Energy slow */ p_tmp_c = buffer_energy + i * num_freq_bands; - FOR ( k = 0; k < num_freq_bands; k++ ) + FOR( k = 0; k < num_freq_bands; k++ ) { - energy_slow[k] = BASOP_Util_Add_Mant32Exp( energy_slow[k], energy_slow_e[k],*( p_tmp_c ), 31-buffer_energy_q[i],&energy_slow_e[k]);/*q=min_q*/ + energy_slow[k] = BASOP_Util_Add_Mant32Exp( energy_slow[k], energy_slow_e[k], *( p_tmp_c ), 31 - buffer_energy_q[i], &energy_slow_e[k] ); /*q=min_q*/ p_tmp_c++; } /* Intensity slow */ - FOR ( k = 0; k < num_freq_bands; k++ ) + FOR( k = 0; k < num_freq_bands; k++ ) { - intensity_slow[k] = BASOP_Util_Add_Mant32Exp(intensity_slow[k], intensity_slow_e[k], buffer_intensity[i][k],31- buffer_intensity_q[i],&intensity_slow_e[k]);/*q=min_q*/ + intensity_slow[k] = BASOP_Util_Add_Mant32Exp( intensity_slow[k], intensity_slow_e[k], buffer_intensity[i][k], 31 - buffer_intensity_q[i], &intensity_slow_e[k] ); /*q=min_q*/ } } /* Compute absolute value */ - FOR ( k = 0; k < num_freq_bands; k++ ) + FOR( k = 0; k < num_freq_bands; k++ ) { - intensity_slow_abs[k] = L_abs( intensity_slow[k] );/*min_q*/ + intensity_slow_abs[k] = L_abs( intensity_slow[k] ); /*min_q*/ } /* Compute Diffuseness */ FOR( i = 0; i < num_freq_bands; ++i ) { Word16 tmp_e1, tmp_e2; - tmp = BASOP_Util_Divide3232_Scale( intensity_slow_abs[i], ( energy_slow[i] + EPSILON_FX_SMALL), &tmp_e1 ); + tmp = BASOP_Util_Divide3232_Scale( intensity_slow_abs[i], ( energy_slow[i] + EPSILON_FX_SMALL ), &tmp_e1 ); tmp_e1 += intensity_slow_e[i] - energy_slow_e[i]; tmp = BASOP_Util_Divide3232_Scale( tmp - L_shr( VERTICAL_ENERGY_RATIO_OFFSET_FX, tmp_e1 ), ONE_IN_Q15 - VERTICAL_ENERGY_RATIO_OFFSET_FX, &tmp_e2 ); /* Tuned to avoid effect due to ambience of vertically un-even setups */ tmp_e2 += tmp_e1; @@ -2227,45 +2224,45 @@ static void computeEvenLayout_fx( Word32 startAzimuth; Word16 numChannelsHalf; - lsSpacing = L_shl(L_mult0(360 , div_s(1,numChannels)),6);/*Q.21*/ + lsSpacing = L_shl( L_mult0( 360, div_s( 1, numChannels ) ), 6 ); /*Q.21*/ oddLayout = numChannels % 2; - numChannelsHalf = shr(numChannels , 1); + numChannelsHalf = shr( numChannels, 1 ); Copy32( ls_azimuth, ls_azimuth_temp, numChannels ); - Scale_sig32( ls_azimuth_temp, numChannels, -1 );/*Q.21*/ - FOR ( i = 0; i < numChannels; i++ ) + Scale_sig32( ls_azimuth_temp, numChannels, -1 ); /*Q.21*/ + FOR( i = 0; i < numChannels; i++ ) { - smallestAzimuth = L_shl(1000,21);/*Q21*/ + smallestAzimuth = L_shl( 1000, 21 ); /*Q21*/ smallestAzimuthIndex = 0; - FOR ( j = 0; j < numChannels; j++ ) + FOR( j = 0; j < numChannels; j++ ) { - IF ( LT_32(ls_azimuth_temp[j] , smallestAzimuth) ) + IF( LT_32( ls_azimuth_temp[j], smallestAzimuth ) ) { smallestAzimuth = ls_azimuth_temp[j]; smallestAzimuthIndex = j; } } ls_azimuth_order[i] = smallestAzimuthIndex; - ls_azimuth_temp[smallestAzimuthIndex] = L_shl(1000, 21); + ls_azimuth_temp[smallestAzimuthIndex] = L_shl( 1000, 21 ); } - IF ( oddLayout ) + IF( oddLayout ) { - startAzimuth = W_extract_l(W_mult0_32_32(-lsSpacing , shl( numChannelsHalf ,1)));/*Q.22*/ + startAzimuth = W_extract_l( W_mult0_32_32( -lsSpacing, shl( numChannelsHalf, 1 ) ) ); /*Q.22*/ } ELSE { - startAzimuth = W_extract_l(W_mult0_32_32(-lsSpacing , sub(shl(numChannelsHalf,1) , 1 )));/*Q.22*/ + startAzimuth = W_extract_l( W_mult0_32_32( -lsSpacing, sub( shl( numChannelsHalf, 1 ), 1 ) ) ); /*Q.22*/ } - FOR ( i = 0; i < numChannels; i++ ) + FOR( i = 0; i < numChannels; i++ ) { - ls_azimuth_even_ordered[i] = W_extract_l(W_add(W_mult_32_16(lsSpacing,i) , startAzimuth));/*Q.22*/ + ls_azimuth_even_ordered[i] = W_extract_l( W_add( W_mult_32_16( lsSpacing, i ), startAzimuth ) ); /*Q.22*/ } - FOR ( i = 0; i < numChannels; i++ ) + FOR( i = 0; i < numChannels; i++ ) { - ls_azimuth_even[ls_azimuth_order[i]] = L_shl(L_shr(L_add(ls_azimuth_even_ordered[i],ONE_IN_Q21),22),22);/*((a+2^21)/2^22)*2^22*/ + ls_azimuth_even[ls_azimuth_order[i]] = L_shl( L_shr( L_add( ls_azimuth_even_ordered[i], ONE_IN_Q21 ), 22 ), 22 ); /*((a+2^21)/2^22)*2^22*/ } return; @@ -2361,7 +2358,7 @@ void ivas_create_masa_out_meta( numFrequencyBands = MASA_FREQUENCY_BANDS; /* Construct descriptive meta */ - FOR ( i = 0; i < 8; i++ ) + FOR( i = 0; i < 8; i++ ) { extOutMeta->descriptiveMeta.formatDescriptor[i] = ivasmasaFormatDescriptor[i]; } @@ -2375,10 +2372,10 @@ void ivas_create_masa_out_meta( extOutMeta->descriptiveMeta.channelLayout = 0x0u; /* Construct spatial metadata from estimated values */ - FOR ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) { /* Spherical index */ - FOR ( band = 0; band < numFrequencyBands; band++ ) + FOR( band = 0; band < numFrequencyBands; band++ ) { spherical_index = index_theta_phi_16( &elevation_m_values[sf][band], &azimuth_m_values[sf][band], Sph_Grid16 ); move16(); @@ -2389,27 +2386,27 @@ void ivas_create_masa_out_meta( } /* Direct-to-total ratio */ - FOR ( band = 0; band < numFrequencyBands; band++ ) + FOR( band = 0; band < numFrequencyBands; band++ ) { extOutMeta->directToTotalRatio[0][sf][band] = (UWord8) floorf( energyRatio[sf][band] * UINT8_MAX ); extOutMeta->directToTotalRatio[1][sf][band] = 0; } /* Spread coherence */ - FOR ( band = 0; band < numFrequencyBands; band++ ) + FOR( band = 0; band < numFrequencyBands; band++ ) { extOutMeta->spreadCoherence[0][sf][band] = (UWord8) floorf( spreadCoherence[sf][band] * UINT8_MAX ); extOutMeta->spreadCoherence[1][sf][band] = 0; } /* Diffuse-to-total ratio = 1 - sum(direct-to-total ratios) */ - FOR ( band = 0; band < numFrequencyBands; band++ ) + FOR( band = 0; band < numFrequencyBands; band++ ) { extOutMeta->diffuseToTotalRatio[sf][band] = UINT8_MAX - (UWord8) floorf( energyRatio[sf][band] * UINT8_MAX ); } /* Surround coherence */ - FOR ( band = 0; band < numFrequencyBands; band++ ) + FOR( band = 0; band < numFrequencyBands; band++ ) { extOutMeta->surroundCoherence[sf][band] = (UWord8) floorf( surroundingCoherence[sf][band] * UINT8_MAX ); } @@ -2503,4 +2500,4 @@ void ivas_create_masa_out_meta_fx( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_rend/ivas_objectRenderer.c b/lib_rend/ivas_objectRenderer.c index 09878f6e4..e244107e8 100644 --- a/lib_rend/ivas_objectRenderer.c +++ b/lib_rend/ivas_objectRenderer.c @@ -59,7 +59,7 @@ static void TDREND_Clear_Update_flags( BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRe #ifdef IVAS_FLOAT_FIXED static void TDREND_Clear_Update_flags_fx( - BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd /* i/o: TD renderer handle */ + BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd /* i/o: TD renderer handle */ ); #endif // IVAS_FLOAT_FIXED @@ -72,7 +72,7 @@ static void angles_to_vec_fx( Word32 *vec /* o : Pos/Dir vector */ ); #else -static void angles_to_vec(const float radius, const float azimuth, const float elevation, float *vec); +static void angles_to_vec( const float radius, const float azimuth, const float elevation, float *vec ); #endif /*---------------------------------------------------------------------* @@ -88,19 +88,18 @@ ivas_error ivas_td_binaural_open_unwrap_fx( const Word16 nchan_transport, /* i : Number of channels */ const IVAS_FORMAT ivas_format, /* i : IVAS format (ISM/MC) */ const AUDIO_CONFIG transport_config, /* i : Transport configuration */ - const Word16 *directivity, /* i : Directivity pattern (used for ISM) */ + const Word16 *directivity, /* i : Directivity pattern (used for ISM) */ const IVAS_OUTPUT_SETUP hTransSetup, /* i : Loudspeaker layout */ BINAURAL_TD_OBJECT_RENDERER_HANDLE *hBinRendererTd, /* o : TD renderer handle */ - Word32 *binaural_latency_ns, /* i : Binauralization delay */ - Word16 *SrcInd -) + Word32 *binaural_latency_ns, /* i : Binauralization delay */ + Word16 *SrcInd ) { BINAURAL_TD_OBJECT_RENDERER_HANDLE pBinRendTd; TDREND_PosType_t PosType; Word16 nS; const Word32 *ls_azimuth_fx, *ls_elevation_fx; - Word32 Pos_fx[3]; // Q25 - Word32 Dir_fx[3]; // Q30 + Word32 Pos_fx[3]; // Q25 + Word32 Dir_fx[3]; // Q30 TDREND_DirAtten_t *DirAtten_p; Word16 nchan_rend; ivas_error error; @@ -216,7 +215,7 @@ ivas_error ivas_td_binaural_open_unwrap_fx( DirAtten_p->ConeOuterGain_fx = ONE_IN_Q30; move32(); - //TDREND_SRC_SPATIAL_t *SrcSpatial_p = pBinRendTd->Sources[nS]->SrcSpatial_p; + // TDREND_SRC_SPATIAL_t *SrcSpatial_p = pBinRendTd->Sources[nS]->SrcSpatial_p; IF( ( error = TDREND_MIX_SRC_SetPos_fx( pBinRendTd, nS, Pos_fx ) ) != IVAS_ERR_OK ) { return error; @@ -229,7 +228,7 @@ ivas_error ivas_td_binaural_open_unwrap_fx( { return error; } - /*TDREND_SRC_SPATIAL_t **/ //SrcSpatial_p = pBinRendTd->Sources[nS]->SrcSpatial_p; + /*TDREND_SRC_SPATIAL_t **/ // SrcSpatial_p = pBinRendTd->Sources[nS]->SrcSpatial_p; IF( ( error = TDREND_MIX_SRC_SetDirAtten_fx( pBinRendTd, nS, DirAtten_p ) ) != IVAS_ERR_OK ) { return error; @@ -251,9 +250,9 @@ ivas_error ivas_td_binaural_open_unwrap_fx( } ELSE { - DirAtten_p->ConeInnerAngle_fx = L_deposit_h(directivity[nS * 3]); // 9Q6 -> 9Q22 - DirAtten_p->ConeOuterAngle_fx = L_deposit_h(directivity[nS * 3 + 1]); // 9Q6 -> 9Q22 - DirAtten_p->ConeOuterGain_fx = L_shr(L_deposit_h(directivity[nS * 3 + 2]),1); // 0Q15 -> 1Q30 + DirAtten_p->ConeInnerAngle_fx = L_deposit_h( directivity[nS * 3] ); // 9Q6 -> 9Q22 + DirAtten_p->ConeOuterAngle_fx = L_deposit_h( directivity[nS * 3 + 1] ); // 9Q6 -> 9Q22 + DirAtten_p->ConeOuterGain_fx = L_shr( L_deposit_h( directivity[nS * 3 + 2] ), 1 ); // 0Q15 -> 1Q30 } move32(); move32(); @@ -411,9 +410,9 @@ ivas_error ivas_td_binaural_open_unwrap( } #ifdef IVAS_FLOAT_FIXED // Can remove this once TDREND_MIX_SRC_SetPos_fx is integrated above. - pBinRendTd->Sources[nS]->SrcSpatial_p->Pos_p_fx[0] = float_to_fix(pBinRendTd->Sources[nS]->SrcSpatial_p->Pos_p[0], Q25); - pBinRendTd->Sources[nS]->SrcSpatial_p->Pos_p_fx[1] = float_to_fix(pBinRendTd->Sources[nS]->SrcSpatial_p->Pos_p[1], Q25); - pBinRendTd->Sources[nS]->SrcSpatial_p->Pos_p_fx[2] = float_to_fix(pBinRendTd->Sources[nS]->SrcSpatial_p->Pos_p[2], Q25); + pBinRendTd->Sources[nS]->SrcSpatial_p->Pos_p_fx[0] = float_to_fix( pBinRendTd->Sources[nS]->SrcSpatial_p->Pos_p[0], Q25 ); + pBinRendTd->Sources[nS]->SrcSpatial_p->Pos_p_fx[1] = float_to_fix( pBinRendTd->Sources[nS]->SrcSpatial_p->Pos_p[1], Q25 ); + pBinRendTd->Sources[nS]->SrcSpatial_p->Pos_p_fx[2] = float_to_fix( pBinRendTd->Sources[nS]->SrcSpatial_p->Pos_p[2], Q25 ); #endif if ( ( error = TDREND_MIX_SRC_SetDir( pBinRendTd, nS, Dir ) ) != IVAS_ERR_OK ) @@ -422,9 +421,9 @@ ivas_error ivas_td_binaural_open_unwrap( } #ifdef IVAS_FLOAT_FIXED // Can remove this once TDREND_MIX_SRC_SetDir_fx is integrated above. - pBinRendTd->Sources[nS]->SrcSpatial_p->Front_p_fx[0] = float_to_fix(pBinRendTd->Sources[nS]->SrcSpatial_p->Front_p[0], Q30); - pBinRendTd->Sources[nS]->SrcSpatial_p->Front_p_fx[1] = float_to_fix(pBinRendTd->Sources[nS]->SrcSpatial_p->Front_p[1], Q30); - pBinRendTd->Sources[nS]->SrcSpatial_p->Front_p_fx[2] = float_to_fix(pBinRendTd->Sources[nS]->SrcSpatial_p->Front_p[2], Q30); + pBinRendTd->Sources[nS]->SrcSpatial_p->Front_p_fx[0] = float_to_fix( pBinRendTd->Sources[nS]->SrcSpatial_p->Front_p[0], Q30 ); + pBinRendTd->Sources[nS]->SrcSpatial_p->Front_p_fx[1] = float_to_fix( pBinRendTd->Sources[nS]->SrcSpatial_p->Front_p[1], Q30 ); + pBinRendTd->Sources[nS]->SrcSpatial_p->Front_p_fx[2] = float_to_fix( pBinRendTd->Sources[nS]->SrcSpatial_p->Front_p[2], Q30 ); #endif if ( ( error = TDREND_MIX_SRC_SetPlayState( pBinRendTd, nS, TDREND_PLAYSTATUS_PLAYING ) ) != IVAS_ERR_OK ) @@ -432,7 +431,7 @@ ivas_error ivas_td_binaural_open_unwrap( return error; } #ifdef IVAS_FLOAT_FIXED - if ((error = TDREND_MIX_SRC_SetDirAtten_fx(pBinRendTd, nS, DirAtten_p)) != IVAS_ERR_OK) + if ( ( error = TDREND_MIX_SRC_SetDirAtten_fx( pBinRendTd, nS, DirAtten_p ) ) != IVAS_ERR_OK ) { return error; } @@ -464,12 +463,12 @@ ivas_error ivas_td_binaural_open_unwrap( DirAtten_p->ConeOuterGain = directivity[nS * 3 + 2]; } #ifdef IVAS_FLOAT_FIXED - DirAtten_p->ConeInnerAngle_fx = float_to_fix(DirAtten_p->ConeInnerAngle, Q22); - DirAtten_p->ConeOuterAngle_fx = float_to_fix(DirAtten_p->ConeOuterAngle, Q22); - DirAtten_p->ConeOuterGain_fx = float_to_fix(DirAtten_p->ConeOuterGain, Q30); + DirAtten_p->ConeInnerAngle_fx = float_to_fix( DirAtten_p->ConeInnerAngle, Q22 ); + DirAtten_p->ConeOuterAngle_fx = float_to_fix( DirAtten_p->ConeOuterAngle, Q22 ); + DirAtten_p->ConeOuterGain_fx = float_to_fix( DirAtten_p->ConeOuterGain, Q30 ); #endif #ifdef IVAS_FLOAT_FIXED - if ((error = TDREND_MIX_SRC_SetDirAtten_fx(pBinRendTd, nS, DirAtten_p)) != IVAS_ERR_OK) + if ( ( error = TDREND_MIX_SRC_SetDirAtten_fx( pBinRendTd, nS, DirAtten_p ) ) != IVAS_ERR_OK ) { return error; } @@ -505,7 +504,7 @@ void ivas_td_binaural_close_fx( BINAURAL_TD_OBJECT_RENDERER_HANDLE *hBinRendererTd /* i/o: TD binaural object renderer handle */ ) { - IF ( hBinRendererTd == NULL || *hBinRendererTd == NULL ) + IF( hBinRendererTd == NULL || *hBinRendererTd == NULL ) { return; } @@ -551,18 +550,18 @@ void ivas_td_binaural_close( #ifdef IVAS_FLOAT_FIXED ivas_error ivas_td_binaural_renderer_unwrap_fx( - const REVERB_HANDLE hReverb, /* i : Reverberator handle */ - const AUDIO_CONFIG transport_config, /* i : Transport configuration */ - BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD binaural object renderer handle */ - const Word16 num_src, /* i : number of sources to render */ - const Word16 lfe_idx, /* i : LFE channel index */ - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - ISM_METADATA_HANDLE *hIsmMetaData, /* i : ISM metadata handle */ + const REVERB_HANDLE hReverb, /* i : Reverberator handle */ + const AUDIO_CONFIG transport_config, /* i : Transport configuration */ + BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD binaural object renderer handle */ + const Word16 num_src, /* i : number of sources to render */ + const Word16 lfe_idx, /* i : LFE channel index */ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + ISM_METADATA_HANDLE *hIsmMetaData, /* i : ISM metadata handle */ COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i/o: combined orientaton data handle */ - const Word16 ism_md_subframe_update, /* i : Number of subframes to delay ism metadata to sync with audio */ - Word32 *output_fx[], /* i/o: SCE channels / Binaural synthesis */ - const Word16 output_frame, /* i : output frame length */ - const Word16 num_subframes /* i : number of subframes to render */ + const Word16 ism_md_subframe_update, /* i : Number of subframes to delay ism metadata to sync with audio */ + Word32 *output_fx[], /* i/o: SCE channels / Binaural synthesis */ + const Word16 output_frame, /* i : output frame length */ + const Word16 num_subframes /* i : number of subframes to render */ ) { Word16 subframe_length; @@ -571,8 +570,8 @@ ivas_error ivas_td_binaural_renderer_unwrap_fx( Word16 c_indx, nS; Word16 ch; Word16 *enableCombinedOrientation; /* i : Combined orientation flag */ - IVAS_QUATERNION *Quaternions; /* i : Head tracking data per subframe */ - IVAS_VECTOR3 *Pos; /* i : Listener position data per subframe */ + IVAS_QUATERNION *Quaternions; /* i : Head tracking data per subframe */ + IVAS_VECTOR3 *Pos; /* i : Listener position data per subframe */ Word32 reverb_signal_fx[BINAURAL_CHANNELS][L_FRAME48k]; @@ -581,37 +580,40 @@ ivas_error ivas_td_binaural_renderer_unwrap_fx( enableCombinedOrientation = NULL; Quaternions = NULL; Pos = NULL; - IF(hCombinedOrientationData != NULL) + IF( hCombinedOrientationData != NULL ) { enableCombinedOrientation = hCombinedOrientationData->enableCombinedOrientation; Quaternions = hCombinedOrientationData->Quaternions; - Pos = hCombinedOrientationData->listenerPos; move16(); + Pos = hCombinedOrientationData->listenerPos; + move16(); } - FOR(ch = 0; ch < BINAURAL_CHANNELS; ch++) + FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { p_reverb_signal_fx[ch] = reverb_signal_fx[ch]; } - subframe_length = idiv1616(output_frame, num_subframes); + subframe_length = idiv1616( output_frame, num_subframes ); - c_indx = 0; move16(); - FOR(nS = 0; nS < num_src; nS++) + c_indx = 0; + move16(); + FOR( nS = 0; nS < num_src; nS++ ) { - IF(!(ivas_format == MC_FORMAT && nS == lfe_idx)) /* Skip LFE for MC */ + IF( !( ivas_format == MC_FORMAT && nS == lfe_idx ) ) /* Skip LFE for MC */ { hBinRendererTd->Sources[c_indx]->InputFrame_p_fx = output_fx[nS]; /* Q11 */ - hBinRendererTd->Sources[c_indx]->SrcRend_p->InputAvailable = TRUE; move16(); - c_indx = add(c_indx, 1); + hBinRendererTd->Sources[c_indx]->SrcRend_p->InputAvailable = TRUE; + move16(); + c_indx = add( c_indx, 1 ); } } - FOR(subframe_idx = 0; subframe_idx < num_subframes; subframe_idx++) + FOR( subframe_idx = 0; subframe_idx < num_subframes; subframe_idx++ ) { - IF(EQ_16(subframe_idx, ism_md_subframe_update)) + IF( EQ_16( subframe_idx, ism_md_subframe_update ) ) { /* Update object position(s) */ - IF((error = TDREND_Update_object_positions_fx(hBinRendererTd, num_src, ivas_format, hIsmMetaData)) != IVAS_ERR_OK) + IF( ( error = TDREND_Update_object_positions_fx( hBinRendererTd, num_src, ivas_format, hIsmMetaData ) ) != IVAS_ERR_OK ) { return error; } @@ -619,87 +621,89 @@ ivas_error ivas_td_binaural_renderer_unwrap_fx( /* Update the listener's location/orientation */ Word16 tmp_headRotEnabled; - tmp_headRotEnabled = 0; move16(); - IF(enableCombinedOrientation != NULL) + tmp_headRotEnabled = 0; + move16(); + IF( enableCombinedOrientation != NULL ) { tmp_headRotEnabled = enableCombinedOrientation[hCombinedOrientationData->subframe_idx]; move16(); } - IF((error = TDREND_Update_listener_orientation_fx(hBinRendererTd, tmp_headRotEnabled, &Quaternions[hCombinedOrientationData->subframe_idx], &Pos[hCombinedOrientationData->subframe_idx])) != IVAS_ERR_OK) + IF( ( error = TDREND_Update_listener_orientation_fx( hBinRendererTd, tmp_headRotEnabled, &Quaternions[hCombinedOrientationData->subframe_idx], &Pos[hCombinedOrientationData->subframe_idx] ) ) != IVAS_ERR_OK ) { return error; } - IF(hReverb != NULL) + IF( hReverb != NULL ) { Word16 i; FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) { - Scale_sig32(output_fx[i], L_FRAME48k, -4); + Scale_sig32( output_fx[i], L_FRAME48k, -4 ); } - IF((error = ivas_reverb_process_fx(hReverb, transport_config, 0, output_fx, p_reverb_signal_fx, subframe_idx)) != IVAS_ERR_OK) + IF( ( error = ivas_reverb_process_fx( hReverb, transport_config, 0, output_fx, p_reverb_signal_fx, subframe_idx ) ) != IVAS_ERR_OK ) { return error; } FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) { - Scale_sig32(output_fx[i], L_FRAME48k, 4); + Scale_sig32( output_fx[i], L_FRAME48k, 4 ); } FOR( i = 0; i < BINAURAL_CHANNELS; ++i ) { - Scale_sig32(p_reverb_signal_fx[i] + subframe_idx * hReverb->full_block_size, hReverb->full_block_size, 2); + Scale_sig32( p_reverb_signal_fx[i] + subframe_idx * hReverb->full_block_size, hReverb->full_block_size, 2 ); } } /* Render subframe */ - IF((error = TDREND_GetMix_fx(hBinRendererTd, output_fx, subframe_length, subframe_idx, ism_md_subframe_update)) != IVAS_ERR_OK) + IF( ( error = TDREND_GetMix_fx( hBinRendererTd, output_fx, subframe_length, subframe_idx, ism_md_subframe_update ) ) != IVAS_ERR_OK ) { return error; } /* Advance subframe pointer */ - c_indx = 0; move16(); - FOR(nS = 0; nS < num_src; nS++) + c_indx = 0; + move16(); + FOR( nS = 0; nS < num_src; nS++ ) { - IF(!(ivas_format == MC_FORMAT && nS == lfe_idx)) /* Skip LFE for MC */ + IF( !( ivas_format == MC_FORMAT && nS == lfe_idx ) ) /* Skip LFE for MC */ { hBinRendererTd->Sources[c_indx]->InputFrame_p_fx += subframe_length; - c_indx = add(c_indx, 1); + c_indx = add( c_indx, 1 ); } } /* update combined orientation access index */ - ivas_combined_orientation_update_index(hCombinedOrientationData, subframe_length); + ivas_combined_orientation_update_index( hCombinedOrientationData, subframe_length ); } - IF(hReverb != NULL) + IF( hReverb != NULL ) { - v_add_32(reverb_signal_fx[0], output_fx[0], output_fx[0], output_frame); - v_add_32(reverb_signal_fx[1], output_fx[1], output_fx[1], output_frame); + v_add_32( reverb_signal_fx[0], output_fx[0], output_fx[0], output_frame ); + v_add_32( reverb_signal_fx[1], output_fx[1], output_fx[1], output_frame ); } return IVAS_ERR_OK; } #else ivas_error ivas_td_binaural_renderer_unwrap( - const REVERB_HANDLE hReverb, /* i : Reverberator handle */ - const AUDIO_CONFIG transport_config, /* i : Transport configuration */ - BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD binaural object renderer handle */ - const int16_t num_src, /* i : number of sources to render */ - const int16_t lfe_idx, /* i : LFE channel index */ - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - ISM_METADATA_HANDLE *hIsmMetaData, /* i : ISM metadata handle */ + const REVERB_HANDLE hReverb, /* i : Reverberator handle */ + const AUDIO_CONFIG transport_config, /* i : Transport configuration */ + BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD binaural object renderer handle */ + const int16_t num_src, /* i : number of sources to render */ + const int16_t lfe_idx, /* i : LFE channel index */ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + ISM_METADATA_HANDLE *hIsmMetaData, /* i : ISM metadata handle */ COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i/o: combined orientaton data handle */ - const int16_t ism_md_subframe_update, /* i : Number of subframes to delay ism metadata to sync with audio */ - float *output[], /* i/o: SCE channels / Binaural synthesis */ - const int16_t output_frame, /* i : output frame length */ - const int16_t num_subframes /* i : number of subframes to render */ + const int16_t ism_md_subframe_update, /* i : Number of subframes to delay ism metadata to sync with audio */ + float *output[], /* i/o: SCE channels / Binaural synthesis */ + const int16_t output_frame, /* i : output frame length */ + const int16_t num_subframes /* i : number of subframes to render */ ) { int16_t subframe_length; @@ -808,10 +812,10 @@ ivas_error ivas_td_binaural_renderer_unwrap( #ifdef IVAS_FLOAT_FIXED ivas_error TDREND_GetMix_fx( BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ - Word32 *output[], /* i/o: ISM object synth / rendered output in 0,1 */ - const Word16 subframe_length, /* i/o: subframe length */ - const Word16 subframe_idx, /* i : Subframe index to 5 ms subframe */ - const Word16 ism_md_subframe_update /* i : Number of subframes to delay ism metadata to sync with audio */ + Word32 *output[], /* i/o: ISM object synth / rendered output in 0,1 */ + const Word16 subframe_length, /* i/o: subframe length */ + const Word16 subframe_idx, /* i : Subframe index to 5 ms subframe */ + const Word16 ism_md_subframe_update /* i : Number of subframes to delay ism metadata to sync with audio */ ) { Word16 i; @@ -826,7 +830,7 @@ ivas_error TDREND_GetMix_fx( Word16 subframe_update_flag; Word16 hrf_left_delta_e = 0, hrf_right_delta_e = 0; - subframe_update_flag = (Word16)EQ_16( subframe_idx, ism_md_subframe_update ); + subframe_update_flag = (Word16) EQ_16( subframe_idx, ism_md_subframe_update ); error = IVAS_ERR_OK; @@ -849,29 +853,30 @@ ivas_error TDREND_GetMix_fx( SrcRend_p = Src_p->SrcRend_p; /* Update rendering params if needed */ - test(); test(); - IF ( ( SrcRend_p->PlayStatus == TDREND_PLAYSTATUS_PLAYING ) && ( hBinRendererTd->Listener_p->PoseUpdated || SrcSpatial_p->Updated ) ) + test(); + test(); + IF( ( SrcRend_p->PlayStatus == TDREND_PLAYSTATUS_PLAYING ) && ( hBinRendererTd->Listener_p->PoseUpdated || SrcSpatial_p->Updated ) ) { TDREND_SRC_REND_UpdateFiltersFromSpatialParams_fx( hBinRendererTd, SrcRend_p, SrcSpatial_p, - Src_p->hrf_left_prev_fx, &Src_p->hrf_left_prev_e, Src_p->hrf_right_prev_fx, &Src_p->hrf_right_prev_e, - hrf_left_delta, &hrf_left_delta_e, hrf_right_delta, &hrf_right_delta_e, - &intp_count, &Src_p->filterlength, &Src_p->itd, - &Src_p->Gain_fx, - Src_p, subframe_update_flag ); + Src_p->hrf_left_prev_fx, &Src_p->hrf_left_prev_e, Src_p->hrf_right_prev_fx, &Src_p->hrf_right_prev_e, + hrf_left_delta, &hrf_left_delta_e, hrf_right_delta, &hrf_right_delta_e, + &intp_count, &Src_p->filterlength, &Src_p->itd, + &Src_p->Gain_fx, + Src_p, subframe_update_flag ); } /* Render source if needed */ - IF ( ( SrcRend_p->InputAvailable == TRUE ) && ( SrcRend_p->PlayStatus == TDREND_PLAYSTATUS_PLAYING ) ) + IF( ( SrcRend_p->InputAvailable == TRUE ) && ( SrcRend_p->PlayStatus == TDREND_PLAYSTATUS_PLAYING ) ) { error = TDREND_REND_RenderSourceHRFilt_fx( Src_p, hrf_left_delta, &hrf_left_delta_e, - hrf_right_delta, &hrf_right_delta_e, intp_count, output_buf, subframe_length ); + hrf_right_delta, &hrf_right_delta_e, intp_count, output_buf, subframe_length ); } } /* Populate output variable */ - Copy32( output_buf[0], output[0] + imult1616(subframe_idx, subframe_length), subframe_length ); /* Left */ - Copy32( output_buf[1], output[1] + imult1616(subframe_idx, subframe_length), subframe_length ); /* Right */ + Copy32( output_buf[0], output[0] + imult1616( subframe_idx, subframe_length ), subframe_length ); /* Left */ + Copy32( output_buf[1], output[1] + imult1616( subframe_idx, subframe_length ), subframe_length ); /* Right */ /* Clear the PoseUpdated and Source position update flags */ TDREND_Clear_Update_flags_fx( hBinRendererTd ); @@ -958,11 +963,13 @@ static void TDREND_Clear_Update_flags_fx( { Word16 i; - hBinRendererTd->Listener_p->PoseUpdated = FALSE;move16(); + hBinRendererTd->Listener_p->PoseUpdated = FALSE; + move16(); for ( i = 0; i < hBinRendererTd->NumOfSrcs; i++ ) { - hBinRendererTd->Sources[i]->SrcSpatial_p->Updated = FALSE;move16(); + hBinRendererTd->Sources[i]->SrcSpatial_p->Updated = FALSE; + move16(); } return; @@ -997,15 +1004,15 @@ static void TDREND_Clear_Update_flags( #ifdef IVAS_FLOAT_FIXED ivas_error TDREND_Update_object_positions_fx( BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD Renderer handle */ - const Word16 num_src, /* i : number of sources to render */ + const Word16 num_src, /* i : number of sources to render */ const IVAS_FORMAT in_format, /* i : Format of input sources */ const ISM_METADATA_HANDLE *hIsmMetaData /* i : Input metadata for ISM objects */ ) { TDREND_DirAtten_t *DirAtten_p; Word16 nS; - Word32 Pos_fx[3]; // Q25 - Word32 Dir_fx[3]; // Q30 + Word32 Pos_fx[3]; // Q25 + Word32 Dir_fx[3]; // Q30 ivas_error error; DirAtten_p = hBinRendererTd->DirAtten_p; @@ -1013,7 +1020,8 @@ ivas_error TDREND_Update_object_positions_fx( /* For each source, write the frame data to the source object*/ FOR( nS = 0; nS < num_src; nS++ ) { - test(); test(); + test(); + test(); IF( in_format == ISM_FORMAT || in_format == MASA_ISM_FORMAT || in_format == SBA_ISM_FORMAT ) { /* Update the source positions */ @@ -1025,12 +1033,12 @@ ivas_error TDREND_Update_object_positions_fx( DirAtten_p->ConeOuterAngle_fx = DEG_360_IN_Q22; DirAtten_p->ConeOuterGain_fx = ONE_IN_Q30; - IF ( ( error = TDREND_MIX_SRC_SetPos_fx( hBinRendererTd, nS, Pos_fx ) ) != IVAS_ERR_OK ) + IF( ( error = TDREND_MIX_SRC_SetPos_fx( hBinRendererTd, nS, Pos_fx ) ) != IVAS_ERR_OK ) { return error; } - IF ( ( error = TDREND_MIX_SRC_SetDirAtten_fx( hBinRendererTd, nS, DirAtten_p ) ) != IVAS_ERR_OK ) + IF( ( error = TDREND_MIX_SRC_SetDirAtten_fx( hBinRendererTd, nS, DirAtten_p ) ) != IVAS_ERR_OK ) { return error; } @@ -1039,8 +1047,8 @@ ivas_error TDREND_Update_object_positions_fx( { Word16 tmp, tmp_e; Pos_fx[0] = 0; - tmp = BASOP_Util_Divide3232_Scale(hIsmMetaData[nS]->azimuth_fx, 377487360 /* 90.f in Q22 */, &tmp_e); - Pos_fx[1] = shr(tmp, sub(6, tmp_e)); // Q25 + tmp = BASOP_Util_Divide3232_Scale( hIsmMetaData[nS]->azimuth_fx, 377487360 /* 90.f in Q22 */, &tmp_e ); + Pos_fx[1] = shr( tmp, sub( 6, tmp_e ) ); // Q25 Pos_fx[2] = 0; IF( ( error = TDREND_MIX_SRC_SetPos_fx( hBinRendererTd, nS, Pos_fx ) ) != IVAS_ERR_OK ) @@ -1054,7 +1062,7 @@ ivas_error TDREND_Update_object_positions_fx( hBinRendererTd->Sources[nS]->SrcSpatial_p->PosType = TDREND_POSTYPE_ABSOLUTE; } - IF ( ( error = TDREND_MIX_SRC_SetDir_fx( hBinRendererTd, nS, Dir_fx, Q30 ) ) != IVAS_ERR_OK ) + IF( ( error = TDREND_MIX_SRC_SetDir_fx( hBinRendererTd, nS, Dir_fx, Q30 ) ) != IVAS_ERR_OK ) { return error; } @@ -1101,7 +1109,7 @@ ivas_error TDREND_Update_object_positions( } #ifdef IVAS_FLOAT_FIXED - if ((error = TDREND_MIX_SRC_SetDirAtten_fx(hBinRendererTd, nS, DirAtten_p)) != IVAS_ERR_OK) + if ( ( error = TDREND_MIX_SRC_SetDirAtten_fx( hBinRendererTd, nS, DirAtten_p ) ) != IVAS_ERR_OK ) { return error; } @@ -1212,8 +1220,8 @@ ivas_error TDREND_Update_listener_orientation( ivas_error TDREND_Update_listener_orientation_fx( BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD Renderer handle */ const Word16 headRotEnabled, /* i : Headrotation flag */ - const IVAS_QUATERNION *headPosition_fx, /* i : Listener orientation Qx */ - const IVAS_VECTOR3 *Pos_fx /* i : Listener Position */ + const IVAS_QUATERNION *headPosition_fx, /* i : Listener orientation Qx */ + const IVAS_VECTOR3 *Pos_fx /* i : Listener Position */ ) { Word32 FrontVec_fx[3]; @@ -1223,7 +1231,7 @@ ivas_error TDREND_Update_listener_orientation_fx( Word32 Pos_p_fx[3]; ivas_error error; - IF ( headRotEnabled ) + IF( headRotEnabled ) { Word16 Rmat_q; @@ -1231,7 +1239,7 @@ ivas_error TDREND_Update_listener_orientation_fx( move16(); /* Obtain head rotation matrix */ - QuatToRotMat_fx( *headPosition_fx, Rmat_fx ); // Rmat_fx Q: 2*Qx-32 + QuatToRotMat_fx( *headPosition_fx, Rmat_fx ); // Rmat_fx Q: 2*Qx-32 Rmat_q = 2 * headPosition_q - 32; /* Apply rotation matrix to looking vector [1;0;0] */ @@ -1246,7 +1254,7 @@ ivas_error TDREND_Update_listener_orientation_fx( orient_q = Rmat_q; - IF ( Pos_fx != NULL ) + IF( Pos_fx != NULL ) { /* Input position */ Pos_p_fx[0] = ( *Pos_fx ).x_fx; @@ -1408,12 +1416,11 @@ ivas_error ivas_td_binaural_renderer_ext_fx( const COMBINED_ORIENTATION_HANDLE *hCombinedOrientationData, /* i : Combined head and external orientations */ const IVAS_ISM_METADATA *currentPos, /* i : Object position */ const REVERB_HANDLE hReverb, /* i : Reverberator handle */ - const Word16 ism_md_subframe_update_ext, /* i : Metadata Delay in subframes to sync with audio delay */ - const Word32 output_Fs, /* i : output sampling rate */ - const Word16 output_frame, /* i : output frame length */ - Word32 output[][L_FRAME48k], /* i/o: SCE channels / Binaural synthesis */ - Word16 *exp -) + const Word16 ism_md_subframe_update_ext, /* i : Metadata Delay in subframes to sync with audio delay */ + const Word32 output_Fs, /* i : output sampling rate */ + const Word16 output_frame, /* i : output frame length */ + Word32 output[][L_FRAME48k], /* i/o: SCE channels / Binaural synthesis */ + Word16 *exp ) { ISM_METADATA_FRAME hIsmMetaDataFrame; ISM_METADATA_HANDLE hIsmMetaData[1]; @@ -1425,26 +1432,30 @@ ivas_error ivas_td_binaural_renderer_ext_fx( ivas_error error; Word32 *p_output_fx[MAX_OUTPUT_CHANNELS]; - FOR(Word16 i = 0; i < MAX_OUTPUT_CHANNELS; i++) + FOR( Word16 i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) { - p_output_fx[i] = output[i]; move32(); + p_output_fx[i] = output[i]; + move32(); } push_wmops( "ivas_td_binaural_renderer_ext" ); inConfigType = getAudioConfigType( inConfig ); - lfe_idx = LFE_CHANNEL; move16(); + lfe_idx = LFE_CHANNEL; + move16(); hIsmMetaData[0] = NULL; - IF ( EQ_32(inConfigType , IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED) ) + IF( EQ_32( inConfigType, IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED ) ) { - ivas_format = MC_FORMAT;move16(); - transport_config = inConfig;move16(); + ivas_format = MC_FORMAT; + move16(); + transport_config = inConfig; + move16(); - IF ( NE_32(inConfig , IVAS_AUDIO_CONFIG_LS_CUSTOM) ) + IF( NE_32( inConfig, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) { - IF ( ( error = getAudioConfigNumChannels( inConfig, &num_src ) ) != IVAS_ERR_OK ) + IF( ( error = getAudioConfigNumChannels( inConfig, &num_src ) ) != IVAS_ERR_OK ) { return error; } @@ -1452,50 +1463,61 @@ ivas_error ivas_td_binaural_renderer_ext_fx( ELSE { lfe_idx = ( customLsInput->num_lfe > 0 ) ? customLsInput->lfe_idx[0] : -1; - num_src = add(customLsInput->num_spk , customLsInput->num_lfe); + num_src = add( customLsInput->num_spk, customLsInput->num_lfe ); } } ELSE { - ivas_format = ISM_FORMAT;move16(); - num_src = 1; move16(); - transport_config = IVAS_AUDIO_CONFIG_ISM1; move16(); - hIsmMetaData[0] = &hIsmMetaDataFrame; move16(); - hIsmMetaData[0]->azimuth_fx = currentPos->azimuth_fx; move32(); - hIsmMetaData[0]->elevation_fx = currentPos->elevation_fx; move32(); - hIsmMetaData[0]->yaw_fx = currentPos->yaw_fx; move32(); - hIsmMetaData[0]->pitch_fx = currentPos->pitch_fx; move32(); - hIsmMetaData[0]->radius_fx = currentPos->radius_fx; move32(); - hIsmMetaData[0]->non_diegetic_flag = currentPos->non_diegetic_flag; move16(); + ivas_format = ISM_FORMAT; + move16(); + num_src = 1; + move16(); + transport_config = IVAS_AUDIO_CONFIG_ISM1; + move16(); + hIsmMetaData[0] = &hIsmMetaDataFrame; + move16(); + hIsmMetaData[0]->azimuth_fx = currentPos->azimuth_fx; + move32(); + hIsmMetaData[0]->elevation_fx = currentPos->elevation_fx; + move32(); + hIsmMetaData[0]->yaw_fx = currentPos->yaw_fx; + move32(); + hIsmMetaData[0]->pitch_fx = currentPos->pitch_fx; + move32(); + hIsmMetaData[0]->radius_fx = currentPos->radius_fx; + move32(); + hIsmMetaData[0]->non_diegetic_flag = currentPos->non_diegetic_flag; + move16(); } - Word16 num_subframes = (int16_t)((output_frame * FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES) / output_Fs); - for (Word16 subframe_idx = 0; subframe_idx < num_subframes; subframe_idx++) + Word16 num_subframes = (int16_t) ( ( output_frame * FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) / output_Fs ); + for ( Word16 subframe_idx = 0; subframe_idx < num_subframes; subframe_idx++ ) { - Word16 idx = subframe_idx; - Word16 pos_q = Q25; - IF((*hCombinedOrientationData)->listenerPos != NULL) - { - (*hCombinedOrientationData)->listenerPos[idx].x_fx = L_shr((*hCombinedOrientationData)->listenerPos[idx].x_fx, (*hCombinedOrientationData)->listenerPos[idx].q_fact - pos_q); - (*hCombinedOrientationData)->listenerPos[idx].y_fx = L_shr((*hCombinedOrientationData)->listenerPos[idx].y_fx, (*hCombinedOrientationData)->listenerPos[idx].q_fact - pos_q); - (*hCombinedOrientationData)->listenerPos[idx].z_fx = L_shr((*hCombinedOrientationData)->listenerPos[idx].z_fx, (*hCombinedOrientationData)->listenerPos[idx].q_fact - pos_q); - (*hCombinedOrientationData)->listenerPos[idx].q_fact = pos_q; - } - FOR(int i = 0; i < 3; i++) - { - pTDRend->hBinRendererTd->Listener_p->Pos_fx[i] = L_shr(pTDRend->hBinRendererTd->Listener_p->Pos_fx[i], pTDRend->hBinRendererTd->Listener_p->Pos_q - pos_q); - pTDRend->hBinRendererTd->Listener_p->Pos_q = pos_q; move16(); - } + Word16 idx = subframe_idx; + Word16 pos_q = Q25; + IF( ( *hCombinedOrientationData )->listenerPos != NULL ) + { + ( *hCombinedOrientationData )->listenerPos[idx].x_fx = L_shr( ( *hCombinedOrientationData )->listenerPos[idx].x_fx, ( *hCombinedOrientationData )->listenerPos[idx].q_fact - pos_q ); + ( *hCombinedOrientationData )->listenerPos[idx].y_fx = L_shr( ( *hCombinedOrientationData )->listenerPos[idx].y_fx, ( *hCombinedOrientationData )->listenerPos[idx].q_fact - pos_q ); + ( *hCombinedOrientationData )->listenerPos[idx].z_fx = L_shr( ( *hCombinedOrientationData )->listenerPos[idx].z_fx, ( *hCombinedOrientationData )->listenerPos[idx].q_fact - pos_q ); + ( *hCombinedOrientationData )->listenerPos[idx].q_fact = pos_q; + } + FOR( int i = 0; i < 3; i++ ) + { + pTDRend->hBinRendererTd->Listener_p->Pos_fx[i] = L_shr( pTDRend->hBinRendererTd->Listener_p->Pos_fx[i], pTDRend->hBinRendererTd->Listener_p->Pos_q - pos_q ); + pTDRend->hBinRendererTd->Listener_p->Pos_q = pos_q; + move16(); + } } - IF ((error = ivas_td_binaural_renderer_unwrap_fx(hReverb, transport_config, pTDRend->hBinRendererTd, num_src, lfe_idx, ivas_format, hIsmMetaData, *hCombinedOrientationData, - ism_md_subframe_update_ext, p_output_fx, output_frame, (Word16)((output_frame * FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES) / output_Fs))) != IVAS_ERR_OK) + IF( ( error = ivas_td_binaural_renderer_unwrap_fx( hReverb, transport_config, pTDRend->hBinRendererTd, num_src, lfe_idx, ivas_format, hIsmMetaData, *hCombinedOrientationData, + ism_md_subframe_update_ext, p_output_fx, output_frame, (Word16) ( ( output_frame * FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) / output_Fs ) ) ) != IVAS_ERR_OK ) { return error; } - -#if 0 //TO-BE-REMOVED + +#if 0 // TO-BE-REMOVED for (Word16 subframe_idx = 0; subframe_idx < (int16_t)((output_frame * FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES) / output_Fs); subframe_idx++) { if (subframe_idx == ism_md_subframe_update_ext) @@ -1513,9 +1535,9 @@ ivas_error ivas_td_binaural_renderer_ext_fx( } } #endif - IF(hReverb != NULL) + IF( hReverb != NULL ) { - *exp = sub(*exp, 2); + *exp = sub( *exp, 2 ); } pop_wmops(); @@ -1624,8 +1646,8 @@ static void angles_to_vec_fx( ) { Word16 elevation_fx, azimuth_fx; - elevation_fx =(Word16)L_shr( Mult_32_16( elevation, 91 ), 7 ); - azimuth_fx = (Word16)L_shr( Mult_32_16( azimuth, 91 ), 7 ); + elevation_fx = (Word16) L_shr( Mult_32_16( elevation, 91 ), 7 ); + azimuth_fx = (Word16) L_shr( Mult_32_16( azimuth, 91 ), 7 ); vec[0] = L_mult( radius, mult( getCosWord16R2( elevation_fx ), getCosWord16R2( azimuth_fx ) ) ); vec[1] = L_mult( radius, mult( getCosWord16R2( elevation_fx ), getSineWord16R2( azimuth_fx ) ) ); vec[2] = L_mult( radius, getSineWord16R2( elevation_fx ) ); @@ -1646,4 +1668,4 @@ static void angles_to_vec( return; } -#endif // IVAS_FLOAT_FIXED \ No newline at end of file +#endif // IVAS_FLOAT_FIXED diff --git a/lib_rend/ivas_objectRenderer_hrFilt.c b/lib_rend/ivas_objectRenderer_hrFilt.c index 0104b3c7d..b0ef34b24 100644 --- a/lib_rend/ivas_objectRenderer_hrFilt.c +++ b/lib_rend/ivas_objectRenderer_hrFilt.c @@ -441,7 +441,7 @@ static void GenerateFilter_fx( FOR( i = 0; i < num_az_idx[p]; i++ ) { modelEval->BM_fx[qp + i] = L_shl( Mpy_32_32( modelEval->elevBfVec_fx[p], modelEval->azimBfVec_fx[p][i] ), Q30 - ( Q30 * 2 - 31 ) ); // Q30 - BM_idx[qp + i] = add(model->azim_start_idx[EvIdx[p]] , AzIdx[p][i]); + BM_idx[qp + i] = add( model->azim_start_idx[EvIdx[p]], AzIdx[p][i] ); } qp = add( qp, num_az_idx[p] ); } @@ -930,7 +930,7 @@ static void getPeriodicBSplineSampVec_fx( FOR( i = 0; i < *num_az_idx; i++ ) { - d = sub(d0 , imult1616(( sub(add(i , nI) , 1) ) , SegSamples)); /* offset of knot_interval */ + d = sub( d0, imult1616( ( sub( add( i, nI ), 1 ) ), SegSamples ) ); /* offset of knot_interval */ d = sub( d0, imult1616( sub( add( i, nI ), 1 ), SegSamples ) ); BfVec_fx[i] = azimBsShape_fx[abs_s( d ) * subSampFactor]; AzIdx[i] = add( nI, i ) % NumBFs; @@ -1135,18 +1135,18 @@ void BSplineModelEvalDealloc_fx( /* Allocated in LoadBSplineBinary() */ Word16 i; - IF ( model->modelROM ) + IF( model->modelROM ) { free( (void *) model->azimBsShape_fx ); /* void* cast needed to please both gcc and Visual studio compilers. Deallocating const float** should be fine and gcc agrees, but Visual studio complains. */ - FOR ( i = 0; i < model->elevDim3; i++ ) + FOR( i = 0; i < model->elevDim3; i++ ) { free( model->azimKSeq_fx[i] ); } - free( model->azimKSeq_fx); - IF ( modelEval != NULL ) + free( model->azimKSeq_fx ); + IF( modelEval != NULL ) { - free( modelEval->hrfModL_fx); - free( modelEval->hrfModR_fx); + free( modelEval->hrfModL_fx ); + free( modelEval->hrfModR_fx ); } } return; diff --git a/lib_rend/ivas_objectRenderer_mix.c b/lib_rend/ivas_objectRenderer_mix.c index 76c146dd2..4d652a0c3 100644 --- a/lib_rend/ivas_objectRenderer_mix.c +++ b/lib_rend/ivas_objectRenderer_mix.c @@ -161,10 +161,11 @@ ivas_error TDREND_MIX_LIST_SetOrient_fx( const Word16 orient_q /* i : Listener's orientation q-factor */ ) { - + TDREND_MIX_Listener_t *List_p; /* Value verification */ - test(); test(); + test(); + test(); IF( ( FrontVec_p_fx[0] == 0 ) && ( FrontVec_p_fx[1] == 0 ) && ( FrontVec_p_fx[2] == 0 ) ) { return ( IVAS_ERROR( IVAS_ERR_INTERNAL, "Zero front vector. Command is ignored!\n" ) ); @@ -200,20 +201,20 @@ void TDREND_MIX_Dealloc_fx( Word16 i; /* Deallocate source list */ - FOR ( i = 0; i < hBinRendererTd->NumOfSrcs; i++ ) + FOR( i = 0; i < hBinRendererTd->NumOfSrcs; i++ ) { TDREND_SRC_Dealloc( hBinRendererTd->Sources[i] ); } /* Deallocate Listener and RendListener */ - IF ( hBinRendererTd->Listener_p != NULL ) + IF( hBinRendererTd->Listener_p != NULL ) { free( hBinRendererTd->Listener_p ); hBinRendererTd->Listener_p = NULL; } /* Dealloc HR filter set */ - IF ( hBinRendererTd->HrFiltSet_p != NULL ) + IF( hBinRendererTd->HrFiltSet_p != NULL ) { - IF ( EQ_16(hBinRendererTd->HrFiltSet_p->FilterMethod , TDREND_HRFILT_Method_BSplineModel) ) + IF( EQ_16( hBinRendererTd->HrFiltSet_p->FilterMethod, TDREND_HRFILT_Method_BSplineModel ) ) { #if 0 /*IVAS_FLOAT_FIXED_TO_BE_REMOVED*/ BSplineModelEvalDealloc( &hBinRendererTd->HrFiltSet_p->ModelParams, &hBinRendererTd->HrFiltSet_p->ModelEval ); @@ -222,19 +223,19 @@ void TDREND_MIX_Dealloc_fx( } ELSE { - IF ( hBinRendererTd->HrFiltSet_p->Elev_p_fx != NULL ) + IF( hBinRendererTd->HrFiltSet_p->Elev_p_fx != NULL ) { - free( hBinRendererTd->HrFiltSet_p->Elev_p_fx); + free( hBinRendererTd->HrFiltSet_p->Elev_p_fx ); hBinRendererTd->HrFiltSet_p->Elev_p_fx = NULL; } - IF ( hBinRendererTd->HrFiltSet_p->Azim_p_fx != NULL ) + IF( hBinRendererTd->HrFiltSet_p->Azim_p_fx != NULL ) { - free( hBinRendererTd->HrFiltSet_p->Azim_p_fx); + free( hBinRendererTd->HrFiltSet_p->Azim_p_fx ); hBinRendererTd->HrFiltSet_p->Azim_p_fx = NULL; } IF( hBinRendererTd->HrFiltSet_p->LeftFiltSet_p_fx != NULL ) { - free( hBinRendererTd->HrFiltSet_p->LeftFiltSet_p_fx); + free( hBinRendererTd->HrFiltSet_p->LeftFiltSet_p_fx ); hBinRendererTd->HrFiltSet_p->LeftFiltSet_p_fx = NULL; } IF( hBinRendererTd->HrFiltSet_p->RightFiltSet_p_fx != NULL ) @@ -317,7 +318,7 @@ ivas_error TDREND_MIX_Init_fx( BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ TDREND_HRFILT_FiltSet_t **hHrtfTD, /* i/o: HRTF data (initialized in case of NULL) */ const TDREND_MixSpatSpec_t *MixSpatSpec_p, /* i : Mixer spatial specification */ - const Word32 output_Fs /* i : Output sampling rate */ + const Word32 output_Fs /* i : Output sampling rate */ ) { ivas_error error; @@ -325,7 +326,7 @@ ivas_error TDREND_MIX_Init_fx( move16(); /* Init source list */ /* Spatial settings */ - IF ( MixSpatSpec_p != NULL ) + IF( MixSpatSpec_p != NULL ) { hBinRendererTd->UseCommonDistAttenModel = MixSpatSpec_p->UseCommonDistAttenModel; hBinRendererTd->DistAttenModel = MixSpatSpec_p->DistAttenModel; @@ -344,14 +345,14 @@ ivas_error TDREND_MIX_Init_fx( TDREND_SPATIAL_VecInit_fx( hBinRendererTd->Listener_p->Up_fx, 0, ONE_IN_Q30, 0 ); TDREND_SPATIAL_VecInit_fx( hBinRendererTd->Listener_p->Right_fx, ONE_IN_Q30, 0, 0 ); /* Init HR filter set */ - IF ( *hHrtfTD == NULL ) + IF( *hHrtfTD == NULL ) { - IF ( ( hBinRendererTd->HrFiltSet_p = (TDREND_HRFILT_FiltSet_t *) malloc( sizeof( TDREND_HRFILT_FiltSet_t ) ) ) == NULL ) + IF( ( hBinRendererTd->HrFiltSet_p = (TDREND_HRFILT_FiltSet_t *) malloc( sizeof( TDREND_HRFILT_FiltSet_t ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) ); } - IF ( ( error = DefaultBSplineModel_fx( hBinRendererTd->HrFiltSet_p, output_Fs ) ) != IVAS_ERR_OK ) + IF( ( error = DefaultBSplineModel_fx( hBinRendererTd->HrFiltSet_p, output_Fs ) ) != IVAS_ERR_OK ) { return error; } @@ -361,7 +362,7 @@ ivas_error TDREND_MIX_Init_fx( { hBinRendererTd->HrFiltSet_p = *hHrtfTD; } - IF ( NE_32(hBinRendererTd->HrFiltSet_p->SampleRate , output_Fs) ) + IF( NE_32( hBinRendererTd->HrFiltSet_p->SampleRate, output_Fs ) ) { return ( IVAS_ERROR( IVAS_ERR_INVALID_SAMPLING_RATE, "The sampling rate for the HR filter set does not match the output sampling rate.\n" ) ); } @@ -427,7 +428,7 @@ ivas_error TDREND_MIX_Init( return error; } #else - if ( ( error = DefaultBSplineModel( hBinRendererTd->HrFiltSet_p, output_Fs ) ) != IVAS_ERR_OK ) + if ( ( error = DefaultBSplineModel( hBinRendererTd->HrFiltSet_p, output_Fs ) ) != IVAS_ERR_OK ) { return error; } @@ -456,12 +457,12 @@ ivas_error TDREND_MIX_Init( #ifdef IVAS_FLOAT_FIXED ivas_error TDREND_MIX_SetDistAttenModel( - BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ + BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ const TDREND_DistAttenModel_t DistAttenModel /* i : Distance attenuation model */ ) { /* Value validation */ - IF ( LT_16( DistAttenModel , TDREND_DIST_ATTEN_MODEL_INV_DIST ) || GT_16( DistAttenModel , TDREND_DIST_ATTEN_MODEL_INV_DIST_CLAMPED ) ) + IF( LT_16( DistAttenModel, TDREND_DIST_ATTEN_MODEL_INV_DIST ) || GT_16( DistAttenModel, TDREND_DIST_ATTEN_MODEL_INV_DIST_CLAMPED ) ) { return ( IVAS_ERROR( IVAS_ERR_INTERNAL, "Invalid distance attenuation model!\n" ) ); } @@ -471,7 +472,7 @@ ivas_error TDREND_MIX_SetDistAttenModel( hBinRendererTd->DistAttenModel = DistAttenModel; /* If using common distance attenuation model, set it. */ - IF ( hBinRendererTd->UseCommonDistAttenModel ) + IF( hBinRendererTd->UseCommonDistAttenModel ) { hBinRendererTd->DistAttenEnabled = TRUE; move16(); @@ -518,7 +519,7 @@ ivas_error TDREND_MIX_SetDistAttenModel( #ifdef IVAS_FLOAT_FIXED ivas_error TDREND_MIX_AddSrc_fx( BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ - Word16 *SrcInd, /* o : Source index */ + Word16 *SrcInd, /* o : Source index */ const TDREND_PosType_t PosType /* i : Position type (absolute/relative) */ ) { @@ -528,24 +529,24 @@ ivas_error TDREND_MIX_AddSrc_fx( error = IVAS_ERR_OK; /* Get unique source index */ - *SrcInd = add(hBinRendererTd->MaxSrcInd , 1); + *SrcInd = add( hBinRendererTd->MaxSrcInd, 1 ); hBinRendererTd->MaxSrcInd++; hBinRendererTd->NumOfSrcs++; - IF ( GT_16(hBinRendererTd->NumOfSrcs , MAX_NUM_TDREND_CHANNELS) ) + IF( GT_16( hBinRendererTd->NumOfSrcs, MAX_NUM_TDREND_CHANNELS ) ) { return ( IVAS_ERROR( IVAS_ERR_INTERNAL, "Maximum number of sources exceeded!\n" ) ); } ELSE { - IF ( LT_16( PosType , TDREND_POSTYPE_ABSOLUTE ) || GT_16( PosType , TDREND_POSTYPE_NON_DIEGETIC ) ) + IF( LT_16( PosType, TDREND_POSTYPE_ABSOLUTE ) || GT_16( PosType, TDREND_POSTYPE_NON_DIEGETIC ) ) { return ( IVAS_ERROR( IVAS_ERR_INTERNAL, "Invalid position type!\n" ) ); } ELSE { /* Alloc and init a complete source: signal+spatial+rend components */ - IF ( ( error = TDREND_SRC_Alloc( &Src_p ) ) != IVAS_ERR_OK ) + IF( ( error = TDREND_SRC_Alloc( &Src_p ) ) != IVAS_ERR_OK ) { return error; } @@ -553,7 +554,7 @@ ivas_error TDREND_MIX_AddSrc_fx( TDREND_SRC_Init_fx( Src_p, PosType ); /* Special OpenAL initialization due to a common distance attenuation model */ - IF ( NE_16(hBinRendererTd->DistAttenModel , 0) ) + IF( NE_16( hBinRendererTd->DistAttenModel, 0 ) ) { Src_p->SrcSpatial_p->DistAttenEnabled = TRUE; move16(); @@ -602,7 +603,7 @@ ivas_error TDREND_MIX_AddSrc( return error; } #ifdef IVAS_FLOAT_FIXED - TDREND_SRC_Init_fx(Src_p, PosType); + TDREND_SRC_Init_fx( Src_p, PosType ); #else TDREND_SRC_Init( Src_p, PosType ); #endif @@ -690,7 +691,7 @@ static ivas_error DefaultBSplineModel_fx( SWITCH( output_Fs ) { case 48000: -#if 0/*To be removed later : floating point pointer initialization*/ +#if 0 /*To be removed later : floating point pointer initialization*/ HrFiltSet_p->lr_energy_and_iac[0] = defaultHRIR_left_avg_power_48kHz; HrFiltSet_p->lr_energy_and_iac[1] = defaultHRIR_right_avg_power_48kHz; HrFiltSet_p->lr_energy_and_iac[2] = defaultHRIR_coherence_48kHz; @@ -700,7 +701,7 @@ static ivas_error DefaultBSplineModel_fx( HrFiltSet_p->lr_energy_and_iac_fx[2] = defaultHRIR_coherence_48kHz_fx; BREAK; case 32000: -#if 0/*To be removed later : floating point pointer initialization*/ +#if 0 /*To be removed later : floating point pointer initialization*/ HrFiltSet_p->lr_energy_and_iac[0] = defaultHRIR_left_avg_power_32kHz; HrFiltSet_p->lr_energy_and_iac[1] = defaultHRIR_right_avg_power_32kHz; HrFiltSet_p->lr_energy_and_iac[2] = defaultHRIR_coherence_32kHz; @@ -710,7 +711,7 @@ static ivas_error DefaultBSplineModel_fx( HrFiltSet_p->lr_energy_and_iac_fx[2] = defaultHRIR_coherence_32kHz_fx; BREAK; case 16000: -#if 0/*To be removed later : floating point pointer initialization*/ +#if 0 /*To be removed later : floating point pointer initialization*/ HrFiltSet_p->lr_energy_and_iac[0] = defaultHRIR_left_avg_power_16kHz; HrFiltSet_p->lr_energy_and_iac[1] = defaultHRIR_right_avg_power_16kHz; HrFiltSet_p->lr_energy_and_iac[2] = defaultHRIR_coherence_16kHz; @@ -765,7 +766,7 @@ static ivas_error DefaultBSplineModel_fx( model->azimShapeSampFactor = defaultHRIR_rom_azimShapeSampFactor; /* float parameters */ -#if 0 /*To be removed later Floating point initializations */ +#if 0 /*To be removed later Floating point initializations */ model->elevKSeq = (const float *) defaultHRIR_rom_elevKSeq; model->elevBsShape = (const float *) defaultHRIR_rom_elevBsShape; #endif // 1 @@ -794,33 +795,33 @@ static ivas_error DefaultBSplineModel_fx( model->azimKSeq[0][1] = 360.0f; model->azimKSeq[model->elevDim3 - 1][1] = 360.0f; #endif - IF ( ( model->azimBsShape_fx = (const Word32 **) malloc( model->num_unique_azim_splines * sizeof(Word32 * ) ) ) == NULL ) + IF( ( model->azimBsShape_fx = (const Word32 **) malloc( model->num_unique_azim_splines * sizeof( Word32 * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) ); } model->azimBsShape_fx[0] = defaultHRIR_rom_azimBsShape_fx; - IF ( ( model->azimKSeq_fx = (Word32 **) malloc( 18 * sizeof( Word32 * ) ) ) == NULL ) + IF( ( model->azimKSeq_fx = (Word32 **) malloc( 18 * sizeof( Word32 * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) ); } - IF ( ( model->azimKSeq_fx[0] = (Word32 *) malloc( 2 * sizeof(Word32 * ) ) ) == NULL ) + IF( ( model->azimKSeq_fx[0] = (Word32 *) malloc( 2 * sizeof( Word32 * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) ); } - IF ( ( model->azimKSeq_fx[model->elevDim3 - 1] = (Word32 *) malloc( 2 * sizeof(Word32 * ) ) ) == NULL ) + IF( ( model->azimKSeq_fx[model->elevDim3 - 1] = (Word32 *) malloc( 2 * sizeof( Word32 * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) ); } model->azimKSeq_fx[0][0] = 0; model->azimKSeq_fx[model->elevDim3 - 1][0] = 0; - model->azimKSeq_fx[0][1] = 360<azimKSeq_fx[model->elevDim3 - 1][1] = 360<azimKSeq_fx[0][1] = 360 << Q22; + model->azimKSeq_fx[model->elevDim3 - 1][1] = 360 << Q22; move32(); move32(); move32(); move32(); - FOR ( i = 1; i < model->elevDim3 - 1; i++ ) + FOR( i = 1; i < model->elevDim3 - 1; i++ ) { #if 0 /*To be removed later : Floating point initialization*/ IF ( ( model->azimKSeq[i] = (float *) malloc( model->azimDim2[i] * sizeof( float * ) ) ) == NULL ) /* azimDim2[i] = 91, i=2..15 */ @@ -838,15 +839,15 @@ static ivas_error DefaultBSplineModel_fx( } FOR( j = 0; j < model->azimDim2[i]; j++ ) { - model->azimKSeq_fx[i][j] = L_shl(L_mult0(defaultHRIR_rom_azimSegSamples[0] , j), Q22); + model->azimKSeq_fx[i][j] = L_shl( L_mult0( defaultHRIR_rom_azimSegSamples[0], j ), Q22 ); } j = j; } - SWITCH ( output_Fs ) + SWITCH( output_Fs ) { case 48000: -#if 0/*To be removed later : floating point pointer initialization*/ +#if 0 /*To be removed later : floating point pointer initialization*/ model->AlphaL = (const float *) defaultHRIR_rom_AlphaL48; model->AlphaR = (const float *) defaultHRIR_rom_AlphaR48; model->EL = (const float *) defaultHRIR_rom_EL48; @@ -856,16 +857,16 @@ static ivas_error DefaultBSplineModel_fx( modelITD->resamp_factor = 1.0f; } #endif - model->AlphaL_fx = (const Word32 *)defaultHRIR_rom_AlphaL48_fx; + model->AlphaL_fx = (const Word32 *) defaultHRIR_rom_AlphaL48_fx; model->AlphaL_e = 1; move16(); - model->AlphaR_fx = (const Word32 *)defaultHRIR_rom_AlphaR48_fx; + model->AlphaR_fx = (const Word32 *) defaultHRIR_rom_AlphaR48_fx; model->AlphaR_e = 1; move16(); - model->EL_fx = (const Word32 *)defaultHRIR_rom_EL48_fx; + model->EL_fx = (const Word32 *) defaultHRIR_rom_EL48_fx; model->EL_e = 3; move16(); - model->ER_fx = (const Word32 *)defaultHRIR_rom_ER48_fx; + model->ER_fx = (const Word32 *) defaultHRIR_rom_ER48_fx; model->ER_e = 3; move16(); model->K = 128; @@ -877,7 +878,7 @@ static ivas_error DefaultBSplineModel_fx( } BREAK; case 32000: -#if 0/*To be removed later : floating point pointer initialization*/ +#if 0 /*To be removed later : floating point pointer initialization*/ model->AlphaL = (const float *) defaultHRIR_rom_AlphaL32; model->AlphaR = (const float *) defaultHRIR_rom_AlphaR32; model->EL = (const float *) defaultHRIR_rom_EL32; @@ -887,16 +888,16 @@ static ivas_error DefaultBSplineModel_fx( modelITD->resamp_factor = RESAMPLE_FACTOR_32_48; } #endif - model->AlphaL_fx = (const Word32 *)defaultHRIR_rom_AlphaL32_fx; + model->AlphaL_fx = (const Word32 *) defaultHRIR_rom_AlphaL32_fx; model->AlphaL_e = 1; move16(); - model->AlphaR_fx = (const Word32 *)defaultHRIR_rom_AlphaR32_fx; + model->AlphaR_fx = (const Word32 *) defaultHRIR_rom_AlphaR32_fx; model->AlphaR_e = 1; move16(); - model->EL_fx = (const Word32 *)defaultHRIR_rom_EL32_fx; + model->EL_fx = (const Word32 *) defaultHRIR_rom_EL32_fx; model->EL_e = 3; move16(); - model->ER_fx = (const Word32 *)defaultHRIR_rom_ER32_fx; + model->ER_fx = (const Word32 *) defaultHRIR_rom_ER32_fx; model->ER_e = 3; move16(); model->K = 86; @@ -908,7 +909,7 @@ static ivas_error DefaultBSplineModel_fx( } BREAK; case 16000: -#if 0/*To be removed later : floating point pointer initialization*/ +#if 0 /*To be removed later : floating point pointer initialization*/ model->AlphaL = (const float *) defaultHRIR_rom_AlphaL16; model->AlphaR = (const float *) defaultHRIR_rom_AlphaR16; model->EL = (const float *) defaultHRIR_rom_EL16; @@ -918,16 +919,16 @@ static ivas_error DefaultBSplineModel_fx( modelITD->resamp_factor = RESAMPLE_FACTOR_16_48; } #endif - model->AlphaL_fx = (const Word32 *)defaultHRIR_rom_AlphaL16_fx; + model->AlphaL_fx = (const Word32 *) defaultHRIR_rom_AlphaL16_fx; model->AlphaL_e = 1; move16(); - model->AlphaR_fx = (const Word32 *)defaultHRIR_rom_AlphaR16_fx; + model->AlphaR_fx = (const Word32 *) defaultHRIR_rom_AlphaR16_fx; model->AlphaR_e = 1; move16(); - model->EL_fx = (const Word32 *)defaultHRIR_rom_EL16_fx; + model->EL_fx = (const Word32 *) defaultHRIR_rom_EL16_fx; model->EL_e = 3; move16(); - model->ER_fx = (const Word32 *)defaultHRIR_rom_ER16_fx; + model->ER_fx = (const Word32 *) defaultHRIR_rom_ER16_fx; model->ER_e = 3; move16(); model->K = 43; @@ -970,7 +971,7 @@ static ivas_error DefaultBSplineModel_fx( move16(); modelITD->elevBsStart[3] = 21; move16(); -#if 0/*To be removed later : floating point pointer initialization*/ +#if 0 /*To be removed later : floating point pointer initialization*/ modelITD->elevKSeq = defaultHRIR_rom_ITD_elevKSeq; #endif modelITD->elevKSeq_fx = defaultHRIR_rom_ITD_elevKSeq_fx; @@ -994,14 +995,14 @@ static ivas_error DefaultBSplineModel_fx( modelITD->azimSegSamples = 10; move16(); -#if 0/*To be removed later : floating point pointer initialization*/ +#if 0 /*To be removed later : floating point pointer initialization*/ modelITD->azimKSeq = defaultHRIR_rom_ITD_azimKSeq; modelITD->W = (const float *) defaultHRIR_rom_ITD_W; modelITD->azimBsShape = (const float *) defaultHRIR_rom_ITD_azimBsShape; modelITD->elevBsShape = (const float *) defaultHRIR_rom_ITD_elevBsShape; #endif modelITD->azimKSeq_fx = defaultHRIR_rom_ITD_azimKSeq_fx; - modelITD->W_fx = (const Word32 *)defaultHRIR_rom_ITD_W_fx;//Q25 + modelITD->W_fx = (const Word32 *) defaultHRIR_rom_ITD_W_fx; // Q25 modelITD->W_e = 6; move16(); modelITD->azimBsShape_fx = defaultHRIR_rom_ITD_azimBsShape_fx; @@ -1016,7 +1017,7 @@ static ivas_error DefaultBSplineModel_fx( HrFiltSet_p->FiltLength = HrFiltSet_p->ModelParams.K; move16(); - IF ( ( error = BSplineModelEvalAlloc_fx( &HrFiltSet_p->ModelParams, &HrFiltSet_p->ModelEval ) ) != IVAS_ERR_OK ) + IF( ( error = BSplineModelEvalAlloc_fx( &HrFiltSet_p->ModelParams, &HrFiltSet_p->ModelEval ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_rend/ivas_objectRenderer_sfx.c b/lib_rend/ivas_objectRenderer_sfx.c index 456e8367c..8289708df 100644 --- a/lib_rend/ivas_objectRenderer_sfx.c +++ b/lib_rend/ivas_objectRenderer_sfx.c @@ -163,13 +163,13 @@ void TDREND_Apply_ITD( #ifdef IVAS_FLOAT_FIXED void TDREND_Apply_ITD_fx( - Word32 *input_fx, /* i : Input subframe to be time adjusted Qx */ - Word32 *out_left_fx, /* o : Output left channel with ITD applied Qx */ - Word32 *out_right_fx, /* o : Output right channel with ITD applied Qx */ - Word16 *previtd, /* i/o: Previous ITD value */ - const Word16 itd, /* i : Current subframe ITD value */ - Word32 *mem_itd_fx, /* i/o: ITD buffer memory Qx */ - const Word16 length /* i : Subframe length */ + Word32 *input_fx, /* i : Input subframe to be time adjusted Qx */ + Word32 *out_left_fx, /* o : Output left channel with ITD applied Qx */ + Word32 *out_right_fx, /* o : Output right channel with ITD applied Qx */ + Word16 *previtd, /* i/o: Previous ITD value */ + const Word16 itd, /* i : Current subframe ITD value */ + Word32 *mem_itd_fx, /* i/o: ITD buffer memory Qx */ + const Word16 length /* i : Subframe length */ ) { Word16 transition_len; @@ -198,7 +198,7 @@ void TDREND_Apply_ITD_fx( tlen3 = s_max( 0, sub( SFX_SPAT_BIN_SINC_M, currShift ) ); /* Make sure there is enough look-ahead for the sinc resampling */ transition_len = sub( length, tlen3 ); - IF ( ( ( *previtd ) * itd ) < 0 ) + IF( ( ( *previtd ) * itd ) < 0 ) { /* ITD sign change - apply shift on both channels */ Word16 tmp1 = imult1616( transition_len, prevShift ); @@ -207,7 +207,7 @@ void TDREND_Apply_ITD_fx( Word16 tmp3 = BASOP_Util_Divide1616_Scale( tmp1, tmp2, &tmp_e ); Word16 tmp4; Word16 tmp_e2 = BASOP_Util_Add_MantExp( tmp3, tmp_e, ONE_IN_Q14, 0, &tmp4 ); - tmp4 = shr( tmp4, sub( 15, tmp_e2 ) ); // Q0 + tmp4 = shr( tmp4, sub( 15, tmp_e2 ) ); // Q0 tlen1 = tmp4; tlen2 = sub( transition_len, tlen1 ); @@ -232,9 +232,9 @@ void TDREND_Apply_ITD_fx( pstart3_fx = pstart2_fx + add( length_in2, currShift ); } - IF ( *previtd == 0 ) + IF( *previtd == 0 ) { - IF ( itd > 0 ) + IF( itd > 0 ) { out_buf_A_fx = out_right_fx; out_buf_B_fx = out_left_fx; @@ -247,7 +247,7 @@ void TDREND_Apply_ITD_fx( } ELSE { - IF ( *previtd > 0 ) + IF( *previtd > 0 ) { out_buf_A_fx = out_right_fx; out_buf_B_fx = out_left_fx; diff --git a/lib_rend/ivas_objectRenderer_sources.c b/lib_rend/ivas_objectRenderer_sources.c index 6c7ef40ef..4fb0b4734 100644 --- a/lib_rend/ivas_objectRenderer_sources.c +++ b/lib_rend/ivas_objectRenderer_sources.c @@ -72,26 +72,26 @@ static void TDREND_SRC_SPATIAL_Dealloc( TDREND_SRC_SPATIAL_t *SrcSpatial_p ); #ifdef IVAS_FLOAT_FIXED ivas_error TDREND_MIX_SRC_SetPos_fx( BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ - const Word16 SrcInd, /* i : Source index */ - const Word32 *Vec_p /* i : Position vector */ + const Word16 SrcInd, /* i : Source index */ + const Word32 *Vec_p /* i : Position vector */ ) - { +{ TDREND_SRC_SPATIAL_t *SrcSpatial_p; - IF(GT_16(SrcInd, hBinRendererTd->MaxSrcInd)) + IF( GT_16( SrcInd, hBinRendererTd->MaxSrcInd ) ) { - return (IVAS_ERROR(IVAS_ERR_INVALID_INDEX, "Index exceeds max index!\n")); + return ( IVAS_ERROR( IVAS_ERR_INVALID_INDEX, "Index exceeds max index!\n" ) ); } ELSE { SrcSpatial_p = hBinRendererTd->Sources[SrcInd]->SrcSpatial_p; - SrcSpatial_p->Pos_p_fx[0] = L_shr(SrcSpatial_p->Pos_p_fx[0], SrcSpatial_p->q_Pos_p - Q25); - SrcSpatial_p->Pos_p_fx[1] = L_shr(SrcSpatial_p->Pos_p_fx[1], SrcSpatial_p->q_Pos_p - Q25); - SrcSpatial_p->Pos_p_fx[2] = L_shr(SrcSpatial_p->Pos_p_fx[2], SrcSpatial_p->q_Pos_p - Q25); + SrcSpatial_p->Pos_p_fx[0] = L_shr( SrcSpatial_p->Pos_p_fx[0], SrcSpatial_p->q_Pos_p - Q25 ); + SrcSpatial_p->Pos_p_fx[1] = L_shr( SrcSpatial_p->Pos_p_fx[1], SrcSpatial_p->q_Pos_p - Q25 ); + SrcSpatial_p->Pos_p_fx[2] = L_shr( SrcSpatial_p->Pos_p_fx[2], SrcSpatial_p->q_Pos_p - Q25 ); SrcSpatial_p->q_Pos_p = Q25; - IF(NE_32(SrcSpatial_p->Pos_p_fx[0] , Vec_p[0]) || NE_32(SrcSpatial_p->Pos_p_fx[1] , Vec_p[1]) || NE_32(SrcSpatial_p->Pos_p_fx[2] , Vec_p[2])) + IF( NE_32( SrcSpatial_p->Pos_p_fx[0], Vec_p[0] ) || NE_32( SrcSpatial_p->Pos_p_fx[1], Vec_p[1] ) || NE_32( SrcSpatial_p->Pos_p_fx[2], Vec_p[2] ) ) { - Copy32(Vec_p, SrcSpatial_p->Pos_p_fx, 3); + Copy32( Vec_p, SrcSpatial_p->Pos_p_fx, 3 ); SrcSpatial_p->Updated = TRUE; move16(); } @@ -143,11 +143,11 @@ ivas_error TDREND_MIX_SRC_SetDir_fx( { TDREND_SRC_SPATIAL_t *SrcSpatial_p; /* Value verification */ - IF ( EQ_32( Vec_p[0] , 0 ) && EQ_32( Vec_p[1] , 0 ) && EQ_32( Vec_p[2] , 0 ) ) + IF( EQ_32( Vec_p[0], 0 ) && EQ_32( Vec_p[1], 0 ) && EQ_32( Vec_p[2], 0 ) ) { return ( IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Zero direction vector. Command is ignored!\n" ) ); } - IF ( GT_16(SrcInd , hBinRendererTd->MaxSrcInd) ) + IF( GT_16( SrcInd, hBinRendererTd->MaxSrcInd ) ) { return ( IVAS_ERROR( IVAS_ERR_INVALID_INDEX, "Index exceeds max index!\n" ) ); } @@ -203,7 +203,7 @@ ivas_error TDREND_MIX_SRC_SetDirAtten_fx( ) { TDREND_SRC_SPATIAL_t *SrcSpatial_p; - IF ( GT_16(SrcInd , hBinRendererTd->MaxSrcInd) ) + IF( GT_16( SrcInd, hBinRendererTd->MaxSrcInd ) ) { return ( IVAS_ERROR( IVAS_ERR_INVALID_INDEX, "Index exceeds max index\n" ) ); } @@ -247,11 +247,11 @@ ivas_error TDREND_MIX_SRC_SetDirAtten( #ifdef IVAS_FLOAT_FIXED ivas_error TDREND_MIX_SRC_SetPlayState( BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ - const Word16 SrcInd, /* i : Source index */ + const Word16 SrcInd, /* i : Source index */ const TDREND_PlayStatus_t PlayStatus /* i : Play state */ ) { - IF ( GT_16(SrcInd , hBinRendererTd->MaxSrcInd) ) + IF( GT_16( SrcInd, hBinRendererTd->MaxSrcInd ) ) { return ( IVAS_ERROR( IVAS_ERR_INVALID_INDEX, "Index exceeds max index\n" ) ); } @@ -296,7 +296,7 @@ static ivas_error TDREND_SRC_REND_Alloc( *SrcRend_pp = NULL; /* Allocate the TDREND_SRC_REND_t variable */ - IF ( ( SrcRend_p = (TDREND_SRC_REND_t *) malloc( sizeof( TDREND_SRC_REND_t ) ) ) == NULL ) + IF( ( SrcRend_p = (TDREND_SRC_REND_t *) malloc( sizeof( TDREND_SRC_REND_t ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "SrcRend_p allocation error\n" ) ); } @@ -325,17 +325,17 @@ static void TDREND_SRC_REND_Init_fx( /* SrcGain */ FOR( nC = 0; nC < SPAT_BIN_MAX_INPUT_CHANNELS; nC++ ) { - SrcRend_p->SrcGainMin_p_fx[nC] = 0;/*Assuming Q15*/ + SrcRend_p->SrcGainMin_p_fx[nC] = 0; /*Assuming Q15*/ move16(); SrcRend_p->SrcGain_p_fx[nC] = ONE_IN_Q14; move16(); - SrcRend_p->SrcGainMax_p_fx[nC] = 32767;/*Assuming Q15*/ + SrcRend_p->SrcGainMax_p_fx[nC] = 32767; /*Assuming Q15*/ move16(); } SrcRend_p->SrcGainUpdated = FALSE; move16(); /* Init directional and distance gains */ - FOR ( nC = 0; nC < SPAT_BIN_MAX_INPUT_CHANNELS; nC++ ) + FOR( nC = 0; nC < SPAT_BIN_MAX_INPUT_CHANNELS; nC++ ) { SrcRend_p->DirGain_p_fx[nC] = ONE_IN_Q14; move16(); @@ -622,133 +622,133 @@ void TDREND_SRC_REND_UpdateFiltersFromSpatialParams_fx( ELSE{ IF( SrcSpatial_p->DistAttenEnabled ){ *SrcRend_p->DistGain_p_fx = TDREND_SRC_SPATIAL_GetDistGain_fx( &SrcSpatial_p->DistAtten, ListRelDist, ListRelDist_e ); - } - } - - /* Update total gains */ - *Gain = extract_h( L_shl( Mpy_32_32( L_shl( L_mult( *SrcRend_p->SrcGain_p_fx, *SrcRend_p->DirGain_p_fx ), 1 ), L_shl( L_mult( *SrcRend_p->DistGain_p_fx, hBinRendererTd->Gain_fx ), 1 ) ), 1 ) ); - - /* Delta for interpolation, in case the angular step exceeds MAX_ANGULAR_STEP */ - Word32 ele_tmp = Src_p->elev_prev_fx; - IF( GT_32( ele_tmp, DEG_180_IN_Q22 ) ) - { - ele_tmp = L_sub( ele_tmp, DEG_360_IN_Q22 ); - } - ELSE IF( LT_32( ele_tmp, -DEG_180_IN_Q22 ) ) - { - ele_tmp = L_add( ele_tmp, DEG_360_IN_Q22 ); - } - elev_delta = L_sub( Elev, ele_tmp ); + } +} - Word32 azi_tmp = Src_p->azim_prev_fx; - IF( GT_32( azi_tmp, DEG_180_IN_Q22 ) ) - { - azi_tmp = L_sub( azi_tmp, DEG_360_IN_Q22 ); - } - ELSE IF( LT_32( azi_tmp, -DEG_180_IN_Q22 ) ) - { - azi_tmp = L_add( azi_tmp, DEG_360_IN_Q22 ); - } - azim_delta = L_sub( Azim, azi_tmp ); +/* Update total gains */ +*Gain = extract_h( L_shl( Mpy_32_32( L_shl( L_mult( *SrcRend_p->SrcGain_p_fx, *SrcRend_p->DirGain_p_fx ), 1 ), L_shl( L_mult( *SrcRend_p->DistGain_p_fx, hBinRendererTd->Gain_fx ), 1 ) ), 1 ) ); - Src_p->elev_prev_fx = Elev; - move32(); - Src_p->azim_prev_fx = Azim; - move32(); - - /* map to -180:180 range */ - IF( GT_32( azim_delta, DEG_180_IN_Q22 ) ) - { - azim_delta = L_sub( azim_delta, DEG_360_IN_Q22 ); - } - ELSE IF( LT_32( azim_delta, -DEG_180_IN_Q22 ) ) - { - azim_delta = L_add( azim_delta, DEG_360_IN_Q22 ); - } - Word16 tmp1 = extract_l( Mpy_32_32( L_abs( azim_delta ), 100 << Q9 ) ); // Q22 + Q9 - Q31 = Q0 - Word16 tmp2 = extract_l( Mpy_32_32( L_abs( elev_delta ), 100 << Q9 ) ); // Q22 + Q9 - Q31 = Q0 - *intp_count = s_min( MAX_INTERPOLATION_STEPS, s_max( tmp1, tmp2 ) ); - } - ELSE /* TDREND_POSTYPE_NON_DIEGETIC */ - { - *itd = 0; - move16(); - *Gain = ONE_IN_Q14; - move16(); - set32_fx( hrf_left, 0, *filterlength ); - set32_fx( hrf_right, 0, *filterlength ); - hrf_left[0] = L_shr( L_add( SrcSpatial_p->Pos_p_fx[1], ONE_IN_Q25 ), 1 ); // Q25 - move32(); - hrf_right[0] = L_sub( ONE_IN_Q25, hrf_left[0] ); // Q25 - move32(); - hrf_left_e = 6; - move16(); - hrf_right_e = 6; - move16(); - *intp_count = MAX_INTERPOLATION_STEPS; - move16(); - Src_p->elev_prev_fx = 0; - move16(); - Src_p->azim_prev_fx = DEG_360_IN_Q22; /* Dummy angle -- sets max interpolation if switching to TDREND_POSTYPE_ABSOLUTE */ - move16(); - } - - test(); - IF( ( *intp_count > 0 ) && subframe_update_flag ) +/* Delta for interpolation, in case the angular step exceeds MAX_ANGULAR_STEP */ +Word32 ele_tmp = Src_p->elev_prev_fx; +IF( GT_32( ele_tmp, DEG_180_IN_Q22 ) ) +{ + ele_tmp = L_sub( ele_tmp, DEG_360_IN_Q22 ); +} +ELSE IF( LT_32( ele_tmp, -DEG_180_IN_Q22 ) ) +{ + ele_tmp = L_add( ele_tmp, DEG_360_IN_Q22 ); +} +elev_delta = L_sub( Elev, ele_tmp ); + +Word32 azi_tmp = Src_p->azim_prev_fx; +IF( GT_32( azi_tmp, DEG_180_IN_Q22 ) ) +{ + azi_tmp = L_sub( azi_tmp, DEG_360_IN_Q22 ); +} +ELSE IF( LT_32( azi_tmp, -DEG_180_IN_Q22 ) ) +{ + azi_tmp = L_add( azi_tmp, DEG_360_IN_Q22 ); +} +azim_delta = L_sub( Azim, azi_tmp ); + +Src_p->elev_prev_fx = Elev; +move32(); +Src_p->azim_prev_fx = Azim; +move32(); + +/* map to -180:180 range */ +IF( GT_32( azim_delta, DEG_180_IN_Q22 ) ) +{ + azim_delta = L_sub( azim_delta, DEG_360_IN_Q22 ); +} +ELSE IF( LT_32( azim_delta, -DEG_180_IN_Q22 ) ) +{ + azim_delta = L_add( azim_delta, DEG_360_IN_Q22 ); +} +Word16 tmp1 = extract_l( Mpy_32_32( L_abs( azim_delta ), 100 << Q9 ) ); // Q22 + Q9 - Q31 = Q0 +Word16 tmp2 = extract_l( Mpy_32_32( L_abs( elev_delta ), 100 << Q9 ) ); // Q22 + Q9 - Q31 = Q0 +*intp_count = s_min( MAX_INTERPOLATION_STEPS, s_max( tmp1, tmp2 ) ); +} +ELSE /* TDREND_POSTYPE_NON_DIEGETIC */ +{ + *itd = 0; + move16(); + *Gain = ONE_IN_Q14; + move16(); + set32_fx( hrf_left, 0, *filterlength ); + set32_fx( hrf_right, 0, *filterlength ); + hrf_left[0] = L_shr( L_add( SrcSpatial_p->Pos_p_fx[1], ONE_IN_Q25 ), 1 ); // Q25 + move32(); + hrf_right[0] = L_sub( ONE_IN_Q25, hrf_left[0] ); // Q25 + move32(); + hrf_left_e = 6; + move16(); + hrf_right_e = 6; + move16(); + *intp_count = MAX_INTERPOLATION_STEPS; + move16(); + Src_p->elev_prev_fx = 0; + move16(); + Src_p->azim_prev_fx = DEG_360_IN_Q22; /* Dummy angle -- sets max interpolation if switching to TDREND_POSTYPE_ABSOLUTE */ + move16(); +} + +test(); +IF( ( *intp_count > 0 ) && subframe_update_flag ) +{ + /* Set deltas for interpolation */ + Word16 tmp_e; + tmp_e = s_max( *hrf_left_prev_e, hrf_left_e ); + FOR( Word16 i = 0; i < *filterlength; i++ ) { - /* Set deltas for interpolation */ - Word16 tmp_e; - tmp_e = s_max( *hrf_left_prev_e, hrf_left_e ); - FOR( Word16 i = 0; i < *filterlength; i++ ) - { - hrf_left[i] = L_shr( hrf_left[i], sub( tmp_e, hrf_left_e ) ); - hrf_left_prev[i] = L_shr( hrf_left_prev[i], sub( tmp_e, *hrf_left_prev_e ) ); - } - *hrf_left_prev_e = tmp_e; - move16(); - hrf_left_e = tmp_e; - move16(); - v_sub_32( hrf_left, hrf_left_prev, hrf_left_delta, *filterlength ); - *hrf_left_delta_e = tmp_e; - move16(); - - Word32 fac = L_deposit_h( div_s( 1, *intp_count ) ); - v_multc_fixed( hrf_left_delta, fac, hrf_left_delta, *filterlength ); - - tmp_e = s_max( *hrf_right_prev_e, hrf_right_e ); - FOR( Word16 i = 0; i < *filterlength; i++ ) - { - hrf_right[i] = L_shr( hrf_right[i], sub( tmp_e, hrf_right_e ) ); - hrf_right_prev[i] = L_shr( hrf_right_prev[i], sub( tmp_e, *hrf_right_prev_e ) ); - } - *hrf_right_prev_e = tmp_e; - move16(); - hrf_right_e = tmp_e; - move16(); - v_sub_32( hrf_right, hrf_right_prev, hrf_right_delta, *filterlength ); - *hrf_right_delta_e = tmp_e; - move16(); - - v_multc_fixed( hrf_right_delta, fac, hrf_right_delta, *filterlength ); + hrf_left[i] = L_shr( hrf_left[i], sub( tmp_e, hrf_left_e ) ); + hrf_left_prev[i] = L_shr( hrf_left_prev[i], sub( tmp_e, *hrf_left_prev_e ) ); } - ELSE + *hrf_left_prev_e = tmp_e; + move16(); + hrf_left_e = tmp_e; + move16(); + v_sub_32( hrf_left, hrf_left_prev, hrf_left_delta, *filterlength ); + *hrf_left_delta_e = tmp_e; + move16(); + + Word32 fac = L_deposit_h( div_s( 1, *intp_count ) ); + v_multc_fixed( hrf_left_delta, fac, hrf_left_delta, *filterlength ); + + tmp_e = s_max( *hrf_right_prev_e, hrf_right_e ); + FOR( Word16 i = 0; i < *filterlength; i++ ) { - /* No interpolation, just set the new filters and reset deltas */ - Copy32( hrf_left, hrf_left_prev, *filterlength ); - *hrf_left_prev_e = hrf_left_e; - move16(); - Copy32( hrf_right, hrf_right_prev, *filterlength ); - *hrf_right_prev_e = hrf_right_e; - move16(); - set32_fx( hrf_left_delta, 0, *filterlength ); - set32_fx( hrf_right_delta, 0, *filterlength ); - *hrf_left_delta_e = 0; - move16(); - *hrf_right_delta_e = 0; - move16(); + hrf_right[i] = L_shr( hrf_right[i], sub( tmp_e, hrf_right_e ) ); + hrf_right_prev[i] = L_shr( hrf_right_prev[i], sub( tmp_e, *hrf_right_prev_e ) ); } - - return; + *hrf_right_prev_e = tmp_e; + move16(); + hrf_right_e = tmp_e; + move16(); + v_sub_32( hrf_right, hrf_right_prev, hrf_right_delta, *filterlength ); + *hrf_right_delta_e = tmp_e; + move16(); + + v_multc_fixed( hrf_right_delta, fac, hrf_right_delta, *filterlength ); +} +ELSE +{ + /* No interpolation, just set the new filters and reset deltas */ + Copy32( hrf_left, hrf_left_prev, *filterlength ); + *hrf_left_prev_e = hrf_left_e; + move16(); + Copy32( hrf_right, hrf_right_prev, *filterlength ); + *hrf_right_prev_e = hrf_right_e; + move16(); + set32_fx( hrf_left_delta, 0, *filterlength ); + set32_fx( hrf_right_delta, 0, *filterlength ); + *hrf_left_delta_e = 0; + move16(); + *hrf_right_delta_e = 0; + move16(); +} + +return; } #endif @@ -767,7 +767,7 @@ static ivas_error TDREND_SRC_SPATIAL_Alloc( *SrcSpatial_pp = NULL; /* Allocate the TDREND_SRC_t variable */ - IF ( ( SrcSpatial_p = (TDREND_SRC_SPATIAL_t *) malloc( sizeof( TDREND_SRC_SPATIAL_t ) ) ) == NULL ) + IF( ( SrcSpatial_p = (TDREND_SRC_SPATIAL_t *) malloc( sizeof( TDREND_SRC_SPATIAL_t ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "TDREND_SRC_SPATIAL_t allocation error\n" ) ); } @@ -838,14 +838,14 @@ static void TDREND_SRC_SPATIAL_Init_fx( FOR( nC = 0; nC < SPAT_BIN_MAX_INPUT_CHANNELS; nC++ ) { /* Source position */ - TDREND_SPATIAL_VecInit_fx( SrcSpatial_p->Pos_p_fx + nC * 3, 0, 0, 0 );/*Assuming Q31*/ + TDREND_SPATIAL_VecInit_fx( SrcSpatial_p->Pos_p_fx + nC * 3, 0, 0, 0 ); /*Assuming Q31*/ /* Source direction */ - TDREND_SPATIAL_VecInit_fx( SrcSpatial_p->Front_p_fx + nC * 3, 0, 0, ONE_IN_Q30);/*Assuming Q30*/ + TDREND_SPATIAL_VecInit_fx( SrcSpatial_p->Front_p_fx + nC * 3, 0, 0, ONE_IN_Q30 ); /*Assuming Q30*/ } #ifdef MSAN_FIX - SrcSpatial_p->q_Pos_p = Q31; + SrcSpatial_p->q_Pos_p = Q31; #endif /* Source directional attenuation */ @@ -1030,14 +1030,14 @@ static float TDREND_SRC_SPATIAL_GetDirGain( return DirGain; } #else -static Word16 TDREND_SRC_SPATIAL_GetDirGain_fx( /* o : Directional Gain Output Q14 */ - const TDREND_DirAtten_t *DirAtten_p, /* i : Directional attenuation specification */ - const Word32 *Front_p_fx, /* i : Front-pointing vector */ - const Word32 *RelPos_p_fx, /* i : Relative position */ - const Word16 RelPos_p_e /* i : Relative position exp */ +static Word16 TDREND_SRC_SPATIAL_GetDirGain_fx( /* o : Directional Gain Output Q14 */ + const TDREND_DirAtten_t *DirAtten_p, /* i : Directional attenuation specification */ + const Word32 *Front_p_fx, /* i : Front-pointing vector */ + const Word32 *RelPos_p_fx, /* i : Relative position */ + const Word16 RelPos_p_e /* i : Relative position exp */ ) { - Word16 DirGain_fx; // Q14 + Word16 DirGain_fx; // Q14 Word32 Vec_fx[3]; Word32 ProjCoef_fx; Word16 ProjCoef_e; @@ -1067,15 +1067,15 @@ static Word16 TDREND_SRC_SPATIAL_GetDirGain_fx( /* o : Directional Gain Output Word32 tmp1, tmp2, tmp3, tmp4; // acos(x/y) = atan( sqrt(1-(x/y)^2) / (x/y) ) - tmp1 = L_deposit_h( BASOP_Util_Divide3232_Scale( ProjCoef_fx, NormRelPos_fx, &tmp_e1 ) ); // x/y + tmp1 = L_deposit_h( BASOP_Util_Divide3232_Scale( ProjCoef_fx, NormRelPos_fx, &tmp_e1 ) ); // x/y tmp_e1 = add( tmp_e1, sub( ProjCoef_e, NormRelPos_e ) ); tmp2 = Mpy_32_32( tmp1, tmp1 ); // (x/y)^2 tmp_e2 = shl( tmp_e1, 1 ); - tmp3 = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, 1, L_negate( tmp2 ), tmp_e2, &tmp_e3 ); // 1 - (x/y)^2 + tmp3 = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, 1, L_negate( tmp2 ), tmp_e2, &tmp_e3 ); // 1 - (x/y)^2 tmp_e4 = tmp_e3; move16(); - tmp3 = L_abs( tmp3 ); // for safety: sometimes it can go negative due to slight precision difference between numerator and denominator. - tmp4 = Sqrt32( tmp3, &tmp_e4 ); // sqrt(1 - (x/y)^2) + tmp3 = L_abs( tmp3 ); // for safety: sometimes it can go negative due to slight precision difference between numerator and denominator. + tmp4 = Sqrt32( tmp3, &tmp_e4 ); // sqrt(1 - (x/y)^2) acosfx = BASOP_util_atan2( tmp4, tmp1, sub( tmp_e4, tmp_e1 ) ); // 2Q13 AngleDeg_fx = L_shr( Mpy_32_16_1( _180_OVER_PI_Q25, acosfx ), 1 ); // Q22 } @@ -1153,10 +1153,10 @@ static float TDREND_SRC_SPATIAL_GetDistGain( return DistGain; } #else -static Word16 TDREND_SRC_SPATIAL_GetDistGain_fx( /* o : Distance gain Q14 */ - const TDREND_DistAtten_t *DistAtten_p, /* i : Distance attenuation parameters */ - const Word32 Dist_fx, /* i : Distance value */ - const Word16 Dist_e /* i : Distance value exp */ +static Word16 TDREND_SRC_SPATIAL_GetDistGain_fx( /* o : Distance gain Q14 */ + const TDREND_DistAtten_t *DistAtten_p, /* i : Distance attenuation parameters */ + const Word32 Dist_fx, /* i : Distance value */ + const Word16 Dist_e /* i : Distance value exp */ ) { Word16 DistGain_fx; @@ -1236,19 +1236,19 @@ ivas_error TDREND_SRC_Alloc( *Src_pp = NULL; /* Allocate the TDREND_SRC_t variable */ - IF ( ( Src_p = (TDREND_SRC_t *) malloc( sizeof( TDREND_SRC_t ) ) ) == NULL ) + IF( ( Src_p = (TDREND_SRC_t *) malloc( sizeof( TDREND_SRC_t ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, " TDREND_SRC_Alloc: Allocation error\n" ) ); } Src_p->SrcSpatial_p = NULL; /* If source type is dynamic alloc the TDREND_SRC_SPATIAL_t variable */ - IF ( ( error = TDREND_SRC_SPATIAL_Alloc( &Src_p->SrcSpatial_p ) ) != IVAS_ERR_OK ) + IF( ( error = TDREND_SRC_SPATIAL_Alloc( &Src_p->SrcSpatial_p ) ) != IVAS_ERR_OK ) { return error; } - IF ( ( error = TDREND_SRC_REND_Alloc( &Src_p->SrcRend_p ) ) != IVAS_ERR_OK ) + IF( ( error = TDREND_SRC_REND_Alloc( &Src_p->SrcRend_p ) ) != IVAS_ERR_OK ) { return error; } @@ -1269,7 +1269,7 @@ ivas_error TDREND_SRC_Alloc( void TDREND_SRC_Dealloc( TDREND_SRC_t *Src_p ) { - IF ( Src_p == NULL ) + IF( Src_p == NULL ) { return; } @@ -1320,7 +1320,7 @@ void TDREND_SRC_Init_fx( ) { /* Init the TDREND_SRC_Spatial_t variable */ - IF ( Src_p->SrcSpatial_p != NULL ) + IF( Src_p->SrcSpatial_p != NULL ) { TDREND_SRC_SPATIAL_Init_fx( Src_p->SrcSpatial_p, PosType ); } @@ -1398,8 +1398,8 @@ void TDREND_SRC_Init( Src_p->prevGain = 1.0f; #endif #ifdef IVAS_FLOAT_FIXED - set32_fx(Src_p->hrf_left_prev_fx, 0, SFX_SPAT_BIN_MAX_FILTER_LENGTH); - set32_fx(Src_p->hrf_right_prev_fx, 0, SFX_SPAT_BIN_MAX_FILTER_LENGTH); + set32_fx( Src_p->hrf_left_prev_fx, 0, SFX_SPAT_BIN_MAX_FILTER_LENGTH ); + set32_fx( Src_p->hrf_right_prev_fx, 0, SFX_SPAT_BIN_MAX_FILTER_LENGTH ); Src_p->hrf_left_prev_fx[0] = ONE_IN_Q30; Src_p->hrf_left_prev_e = 1; Src_p->hrf_right_prev_fx[0] = ONE_IN_Q30; diff --git a/lib_rend/ivas_objectRenderer_vec.c b/lib_rend/ivas_objectRenderer_vec.c index 79efc7156..c1ade6725 100644 --- a/lib_rend/ivas_objectRenderer_vec.c +++ b/lib_rend/ivas_objectRenderer_vec.c @@ -89,15 +89,15 @@ void TDREND_SPATIAL_VecInit( #ifdef IVAS_FLOAT_FIXED Word32 TDREND_SPATIAL_VecNorm_fx( - const Word32 *Vec_p, /* i : Vector for norm calculation */ - const Word16 in_exp, /* i : Input exp */ - Word16 *out_exp /* o : Output exp */ + const Word32 *Vec_p, /* i : Vector for norm calculation */ + const Word16 in_exp, /* i : Input exp */ + Word16 *out_exp /* o : Output exp */ ) { Word32 tmp; Word16 tmp_e; - tmp = L_add(L_add(Mpy_32_32(Vec_p[0], Vec_p[0]), Mpy_32_32(Vec_p[1], Vec_p[1])), Mpy_32_32(Vec_p[2], Vec_p[2])); - tmp_e = shl( in_exp, 1 ); // 2 * in_exp + tmp = L_add( L_add( Mpy_32_32( Vec_p[0], Vec_p[0] ), Mpy_32_32( Vec_p[1], Vec_p[1] ) ), Mpy_32_32( Vec_p[2], Vec_p[2] ) ); + tmp_e = shl( in_exp, 1 ); // 2 * in_exp tmp = Sqrt32( tmp, &tmp_e ); *out_exp = tmp_e; move16(); @@ -160,7 +160,7 @@ void TDREND_SPATIAL_VecNormalize_fx( exp = add( exp, sub( 31, q ) ); // Since vector is normalised, all values will be <= 1. Hence making all values in Q30 - shift = sub(exp , 1); + shift = sub( exp, 1 ); VecNorm_p_fx[0] = L_shl( VecNorm_p_fx[0], shift ); move16(); VecNorm_p_fx[1] = L_shl( VecNorm_p_fx[1], shift ); @@ -181,23 +181,23 @@ void TDREND_SPATIAL_VecNormalize_fx( #ifdef IVAS_FLOAT_FIXED void TDREND_SPATIAL_VecMapToNewCoordSystem_fx( - const Word32 *Vec_p, /* i : Input vector Qx */ - const Word32 *TranslVec_p, /* i : Translation vector Qx */ - const Word32 *DirVec_p, /* i : Direction vector Qy */ - const Word32 *UpVec_p, /* i : Up vector Qy */ - const Word32 *RightVec_p, /* i : Right vector Qy */ - Word32 *MappedVec_p, /* o : Transformed vector Qx+Qy-31 */ - Word32 *LisRelPosAbs /* o : Transformed vector ignoring orientation Qy */ + const Word32 *Vec_p, /* i : Input vector Qx */ + const Word32 *TranslVec_p, /* i : Translation vector Qx */ + const Word32 *DirVec_p, /* i : Direction vector Qy */ + const Word32 *UpVec_p, /* i : Up vector Qy */ + const Word32 *RightVec_p, /* i : Right vector Qy */ + Word32 *MappedVec_p, /* o : Transformed vector Qx+Qy-31 */ + Word32 *LisRelPosAbs /* o : Transformed vector ignoring orientation Qy */ ) { - v_sub_32(Vec_p, TranslVec_p, LisRelPosAbs, 3); + v_sub_32( Vec_p, TranslVec_p, LisRelPosAbs, 3 ); /* Evalute the relative Vec in the coordinates of the Orientation vectors, */ /* which form an orthonormal basis */ - MappedVec_p[0] = dotp_fixed(LisRelPosAbs, DirVec_p, 3); + MappedVec_p[0] = dotp_fixed( LisRelPosAbs, DirVec_p, 3 ); move32(); - MappedVec_p[1] = dotp_fixed(LisRelPosAbs, RightVec_p, 3); + MappedVec_p[1] = dotp_fixed( LisRelPosAbs, RightVec_p, 3 ); move32(); - MappedVec_p[2] = dotp_fixed(LisRelPosAbs, UpVec_p, 3); + MappedVec_p[2] = dotp_fixed( LisRelPosAbs, UpVec_p, 3 ); move32(); return; } @@ -300,23 +300,23 @@ Word16 TDREND_SPATIAL_EvalOrthonormOrient_fx( Copy32( UpVecON_p_fx, tmp_fx + 6, 3 ); /* Evaluate the normalized front vector */ - TDREND_SPATIAL_VecNormalize_fx( FrontVec_p_fx, orient_q, FrontVecON_p_fx ); // FrontVecON_p_fx -> Q30 + TDREND_SPATIAL_VecNormalize_fx( FrontVec_p_fx, orient_q, FrontVecON_p_fx ); // FrontVecON_p_fx -> Q30 /* Evaluate the orthonormal right vector */ /* through the cross product of the front and the up vectors */ - RightVecON_p_fx[0] = L_shl_sat(L_sub(Mpy_32_32(FrontVecON_p_fx[1], UpVec_p_fx[2]), Mpy_32_32(FrontVecON_p_fx[2], UpVec_p_fx[1])),1); - RightVecON_p_fx[1] = L_shl_sat(L_sub(Mpy_32_32(FrontVecON_p_fx[2], UpVec_p_fx[0]), Mpy_32_32(FrontVecON_p_fx[0], UpVec_p_fx[2])),1); - RightVecON_p_fx[2] = L_shl_sat(L_sub(Mpy_32_32(FrontVecON_p_fx[0], UpVec_p_fx[1]), Mpy_32_32(FrontVecON_p_fx[1], UpVec_p_fx[0])),1); + RightVecON_p_fx[0] = L_shl_sat( L_sub( Mpy_32_32( FrontVecON_p_fx[1], UpVec_p_fx[2] ), Mpy_32_32( FrontVecON_p_fx[2], UpVec_p_fx[1] ) ), 1 ); + RightVecON_p_fx[1] = L_shl_sat( L_sub( Mpy_32_32( FrontVecON_p_fx[2], UpVec_p_fx[0] ), Mpy_32_32( FrontVecON_p_fx[0], UpVec_p_fx[2] ) ), 1 ); + RightVecON_p_fx[2] = L_shl_sat( L_sub( Mpy_32_32( FrontVecON_p_fx[0], UpVec_p_fx[1] ), Mpy_32_32( FrontVecON_p_fx[1], UpVec_p_fx[0] ) ), 1 ); - TDREND_SPATIAL_VecNormalize_fx( RightVecON_p_fx, orient_q, RightVecON_p_fx ); // RightVecON_p_fx -> Q30 + TDREND_SPATIAL_VecNormalize_fx( RightVecON_p_fx, orient_q, RightVecON_p_fx ); // RightVecON_p_fx -> Q30 /* Evaluate the orthonormal up vector */ /* through the cross product of the front and the right vectors */ - UpVecON_p_fx[0] = L_shl_sat(L_sub( Mpy_32_32( RightVecON_p_fx[1], FrontVecON_p_fx[2] ), Mpy_32_32( RightVecON_p_fx[2], FrontVecON_p_fx[1] ) ), 1); - UpVecON_p_fx[1] = L_shl_sat(L_sub( Mpy_32_32( RightVecON_p_fx[2], FrontVecON_p_fx[0] ), Mpy_32_32( RightVecON_p_fx[0], FrontVecON_p_fx[2] ) ), 1); - UpVecON_p_fx[2] = L_shl_sat(L_sub( Mpy_32_32( RightVecON_p_fx[0], FrontVecON_p_fx[1] ), Mpy_32_32( RightVecON_p_fx[1], FrontVecON_p_fx[0] ) ), 1); + UpVecON_p_fx[0] = L_shl_sat( L_sub( Mpy_32_32( RightVecON_p_fx[1], FrontVecON_p_fx[2] ), Mpy_32_32( RightVecON_p_fx[2], FrontVecON_p_fx[1] ) ), 1 ); + UpVecON_p_fx[1] = L_shl_sat( L_sub( Mpy_32_32( RightVecON_p_fx[2], FrontVecON_p_fx[0] ), Mpy_32_32( RightVecON_p_fx[0], FrontVecON_p_fx[2] ) ), 1 ); + UpVecON_p_fx[2] = L_shl_sat( L_sub( Mpy_32_32( RightVecON_p_fx[0], FrontVecON_p_fx[1] ), Mpy_32_32( RightVecON_p_fx[1], FrontVecON_p_fx[0] ) ), 1 ); - TDREND_SPATIAL_VecNormalize_fx( UpVecON_p_fx, orient_q, UpVecON_p_fx); // UpVecON_p_fx -> Q30 + TDREND_SPATIAL_VecNormalize_fx( UpVecON_p_fx, orient_q, UpVecON_p_fx ); // UpVecON_p_fx -> Q30 /* Check if vectors have been changed */ IF( NE_32( FrontVecON_p_fx[0], tmp_fx[0] ) || NE_32( FrontVecON_p_fx[1], tmp_fx[1] ) || NE_32( FrontVecON_p_fx[2], tmp_fx[2] ) || diff --git a/lib_rend/ivas_omasa_ana.c b/lib_rend/ivas_omasa_ana.c index 8ddbae1c2..3db75a583 100644 --- a/lib_rend/ivas_omasa_ana.c +++ b/lib_rend/ivas_omasa_ana.c @@ -67,7 +67,7 @@ static void ivas_omasa_dmx_fx( const Word32 ism_azimuth_fx[MAX_NUM_OBJECTS], const Word32 ism_elevation_fx[MAX_NUM_OBJECTS], Word32 prev_gains_fx[][MASA_MAX_TRANSPORT_CHANNELS], - const Word16 interpolator_fx[L_FRAME48k]); + const Word16 interpolator_fx[L_FRAME48k] ); static void ivas_omasa_param_est_ana_fx( @@ -75,7 +75,7 @@ static void ivas_omasa_param_est_ana_fx( Word32 data_f_fx[][L_FRAME48k], Word16 data_f_q, Word32 elevation_m_values_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], // Q22 - Word32 azimuth_m_values_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], // Q22 + Word32 azimuth_m_values_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], // Q22 Word32 energyRatio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], Word16 *energyRatio_q, Word32 spreadCoherence_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], @@ -95,8 +95,8 @@ static void ivas_omasa_param_est_ana_fx( #ifdef IVAS_FLOAT_FIXED ivas_error ivas_omasa_ana_open( OMASA_ANA_HANDLE *hOMasaPtr, /* i/o: OMASA data handle pointer */ - Word32 input_Fs, /* i : Sampling frequency */ - UWord16 total_num_objects /* i : Number of objects */ + Word32 input_Fs, /* i : Sampling frequency */ + UWord16 total_num_objects /* i : Number of objects */ ) { Word16 i, j; @@ -108,7 +108,7 @@ ivas_error ivas_omasa_ana_open( error = IVAS_ERR_OK; - IF ( ( hOMasa = (OMASA_ANA_HANDLE) malloc( sizeof( OMASA_ANA_DATA ) ) ) == NULL ) + IF( ( hOMasa = (OMASA_ANA_HANDLE) malloc( sizeof( OMASA_ANA_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for OMASA\n" ) ); } @@ -126,9 +126,9 @@ ivas_error ivas_omasa_ana_open( maxBin = (Word16) BASOP_Util_Divide3232_Scale( input_Fs, 800, &scale ); maxBin = shr( maxBin, sub( 15, scale ) ); - FOR ( i = 1; i < hOMasa->nbands + 1; i++ ) + FOR( i = 1; i < hOMasa->nbands + 1; i++ ) { - IF ( GE_16( hOMasa->band_grouping[i], maxBin ) ) + IF( GE_16( hOMasa->band_grouping[i], maxBin ) ) { hOMasa->band_grouping[i] = maxBin; move16(); @@ -143,29 +143,29 @@ ivas_error ivas_omasa_ana_open( /* open/initialize CLDFB */ hOMasa->num_Cldfb_instances = numAnalysisChannels; - FOR ( i = 0; i < hOMasa->num_Cldfb_instances; i++ ) + FOR( i = 0; i < hOMasa->num_Cldfb_instances; i++ ) { - IF ( ( error = openCldfb_ivas( &( hOMasa->cldfbAnaEnc[i] ), CLDFB_ANALYSIS, input_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) + IF( ( error = openCldfb_ivas( &( hOMasa->cldfbAnaEnc[i] ), CLDFB_ANALYSIS, input_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) { return error; } } - FOR ( ; i < MAX_NUM_OBJECTS; i++ ) + FOR( ; i < MAX_NUM_OBJECTS; i++ ) { hOMasa->cldfbAnaEnc[i] = NULL; } - FOR ( i = 0; i < DIRAC_NUM_DIMS; i++ ) + FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) { - IF ( ( hOMasa->direction_vector_m_fx[i] = (Word32 **) malloc( MAX_PARAM_SPATIAL_SUBFRAMES * sizeof( Word32 * ) ) ) == NULL ) + IF( ( hOMasa->direction_vector_m_fx[i] = (Word32 **) malloc( MAX_PARAM_SPATIAL_SUBFRAMES * sizeof( Word32 * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for OMASA data\n" ) ); } - FOR ( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) + FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) { - IF ( ( hOMasa->direction_vector_m_fx[i][j] = (Word32 *) malloc( MASA_FREQUENCY_BANDS * sizeof( Word32 ) ) ) == NULL ) + IF( ( hOMasa->direction_vector_m_fx[i][j] = (Word32 *) malloc( MASA_FREQUENCY_BANDS * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for OMASA data\n" ) ); } @@ -173,11 +173,11 @@ ivas_error ivas_omasa_ana_open( } } - FOR ( i = 0; i < DIRAC_NUM_DIMS; i++ ) + FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) { - FOR ( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) + FOR( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) { - IF ( ( hOMasa->buffer_intensity_real_fx[i][j] = (Word32 *) malloc( MASA_FREQUENCY_BANDS * sizeof( Word32 ) ) ) == NULL ) + IF( ( hOMasa->buffer_intensity_real_fx[i][j] = (Word32 *) malloc( MASA_FREQUENCY_BANDS * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for OMASA data\n" ) ); } @@ -187,38 +187,37 @@ ivas_error ivas_omasa_ana_open( set_zero_fx( hOMasa->buffer_energy_fx, DIRAC_NO_COL_AVG_DIFF * MASA_FREQUENCY_BANDS ); - FOR ( i = 0; i < MAX_NUM_OBJECTS; i++ ) + FOR( i = 0; i < MAX_NUM_OBJECTS; i++ ) { set32_fx( hOMasa->prev_object_dm_gains_fx[i], INV_SQRT_2_Q31, MASA_MAX_TRANSPORT_CHANNELS ); } input_frame = BASOP_Util_Divide3232_Scale( input_Fs, FRAMES_PER_SEC, &scale ); - input_frame = shr (input_frame, sub( 15, scale ) ); + input_frame = shr( input_frame, sub( 15, scale ) ); - - FOR ( i = 0; i < input_frame; i++ ) + FOR( i = 0; i < input_frame; i++ ) { - hOMasa->interpolator_fx[i] = BASOP_Util_Divide1616_Scale(i, input_frame, &scale ); + hOMasa->interpolator_fx[i] = BASOP_Util_Divide1616_Scale( i, input_frame, &scale ); hOMasa->interpolator_fx[i] = shl( hOMasa->interpolator_fx[i], scale ); // Q15 } hOMasa->index_buffer_intensity = 0; move16(); - IF ( ( hOMasa->hMasaOut = (MASA_DECODER_EXT_OUT_META_HANDLE) malloc( sizeof( MASA_DECODER_EXT_OUT_META ) ) ) == NULL ) + IF( ( hOMasa->hMasaOut = (MASA_DECODER_EXT_OUT_META_HANDLE) malloc( sizeof( MASA_DECODER_EXT_OUT_META ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MASA decoder\n" ) ); } - IF ( ( hOMasa->sph_grid16 = (SPHERICAL_GRID_DATA *) malloc( sizeof( SPHERICAL_GRID_DATA ) ) ) == NULL ) + IF( ( hOMasa->sph_grid16 = (SPHERICAL_GRID_DATA *) malloc( sizeof( SPHERICAL_GRID_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MASA decoder\n" ) ); } generate_gridEq_fx( hOMasa->sph_grid16 ); - FOR ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { set_zero_fx( hOMasa->energy_fx[i], MASA_FREQUENCY_BANDS ); } @@ -374,25 +373,25 @@ void ivas_omasa_ana_close( { Word16 i, j; - IF ( hOMasa == NULL || *hOMasa == NULL ) + IF( hOMasa == NULL || *hOMasa == NULL ) { return; } - FOR ( i = 0; i < ( *hOMasa )->num_Cldfb_instances; i++ ) + FOR( i = 0; i < ( *hOMasa )->num_Cldfb_instances; i++ ) { deleteCldfb_ivas( &( ( *hOMasa )->cldfbAnaEnc[i] ) ); } - FOR ( i = 0; i < DIRAC_NUM_DIMS; i++ ) + FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) { - FOR ( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) + FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) { free( ( *hOMasa )->direction_vector_m_fx[i][j] ); ( *hOMasa )->direction_vector_m_fx[i][j] = NULL; } - FOR ( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) + FOR( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) { free( ( *hOMasa )->buffer_intensity_real_fx[i][j] ); ( *hOMasa )->buffer_intensity_real_fx[i][j] = NULL; @@ -495,7 +494,7 @@ void ivas_omasa_ana( #ifdef IVAS_FLOAT_FIXED void ivas_omasa_ana_fx( - OMASA_ANA_HANDLE hOMasa, /* i/o: OMASA analysis handle */ + OMASA_ANA_HANDLE hOMasa, /* i/o: OMASA analysis handle */ Word32 data_in_f_fx[][L_FRAME48k], /* i/o: Input / transport audio signals */ Word16 *data_in_q, const Word16 input_frame, /* i : Input frame size */ @@ -511,7 +510,7 @@ void ivas_omasa_ana_fx( Word16 spreadCoherence_q, sorroundingCoherence_q, energyRatio_q; /* Estimate MASA parameters from the objects */ - ivas_omasa_param_est_ana_fx(hOMasa, data_in_f_fx, *data_in_q, elevation_m_values_fx, azimuth_m_values_fx, energyRatio_fx, &energyRatio_q, spreadCoherence_fx, &spreadCoherence_q, surroundingCoherence_fx, &sorroundingCoherence_q, input_frame, nchan_ism); + ivas_omasa_param_est_ana_fx( hOMasa, data_in_f_fx, *data_in_q, elevation_m_values_fx, azimuth_m_values_fx, energyRatio_fx, &energyRatio_q, spreadCoherence_fx, &spreadCoherence_q, surroundingCoherence_fx, &sorroundingCoherence_q, input_frame, nchan_ism ); /* Create MASA metadata buffer from the estimated values */ @@ -726,7 +725,7 @@ static void ivas_omasa_param_est_ana_fx( Word32 data_f_fx[][L_FRAME48k], Word16 data_f_q, Word32 elevation_m_values_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], // Q22 - Word32 azimuth_m_values_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], // Q22 + Word32 azimuth_m_values_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], // Q22 Word32 energyRatio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], Word16 *energyRatio_q, Word32 spreadCoherence_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], @@ -768,7 +767,7 @@ static void ivas_omasa_param_est_ana_fx( int16_t band_m_idx, block_m_idx; - //float norm_tmp; + // float norm_tmp; Word16 mrange[2]; Word16 brange[2]; @@ -782,47 +781,47 @@ static void ivas_omasa_param_est_ana_fx( Word16 direction_q, reference_power_q; /* Compute ISM to FOA matrices */ - FOR ( i = 0; i < nchan_ism; i++ ) + FOR( i = 0; i < nchan_ism; i++ ) { Word16 tmp, tmp1; // 180 in Q22 754974720 hOMasa->chnlToFoaMtx_fx[0][i] = 32767; // 1 in Q15 move16(); - tmp = BASOP_Util_Divide3232_Scale(hOMasa->ism_azimuth_fx[i], 754974720, &scale); + tmp = BASOP_Util_Divide3232_Scale( hOMasa->ism_azimuth_fx[i], 754974720, &scale ); tmp = mult( tmp, EVS_PI_FX ); // Q13 + Q15 - Q15 --> Q13 - tmp = getSinWord16(tmp); // Q15 sine value + tmp = getSinWord16( tmp ); // Q15 sine value - tmp1 = BASOP_Util_Divide3232_Scale(hOMasa->ism_elevation_fx[i], 754974720, &scale); - tmp1 = mult(tmp1, EVS_PI_FX ); - tmp1 = getCosWord16(tmp1); - hOMasa->chnlToFoaMtx_fx[1][i] = shl(mult(tmp, tmp1), 1); // Q14 + Q15 - Q15 + Q1 -> Q15 + tmp1 = BASOP_Util_Divide3232_Scale( hOMasa->ism_elevation_fx[i], 754974720, &scale ); + tmp1 = mult( tmp1, EVS_PI_FX ); + tmp1 = getCosWord16( tmp1 ); + hOMasa->chnlToFoaMtx_fx[1][i] = shl( mult( tmp, tmp1 ), 1 ); // Q14 + Q15 - Q15 + Q1 -> Q15 - tmp = BASOP_Util_Divide3232_Scale(hOMasa->ism_elevation_fx[i], 754974720, &scale); - tmp = mult(tmp, EVS_PI_FX); // Q13 + Q15 - Q15 --> Q13 + tmp = BASOP_Util_Divide3232_Scale( hOMasa->ism_elevation_fx[i], 754974720, &scale ); + tmp = mult( tmp, EVS_PI_FX ); // Q13 + Q15 - Q15 --> Q13 hOMasa->chnlToFoaMtx_fx[2][i] = getSinWord16( tmp ); // Q15 - tmp = BASOP_Util_Divide3232_Scale(hOMasa->ism_azimuth_fx[i], 754974720, &scale); - tmp = mult(tmp, EVS_PI_FX); // Q13 + Q15 - Q15 --> Q13 - tmp= getCosWord16(tmp); // Q14 + tmp = BASOP_Util_Divide3232_Scale( hOMasa->ism_azimuth_fx[i], 754974720, &scale ); + tmp = mult( tmp, EVS_PI_FX ); // Q13 + Q15 - Q15 --> Q13 + tmp = getCosWord16( tmp ); // Q14 - tmp1 = BASOP_Util_Divide3232_Scale(hOMasa->ism_elevation_fx[i], 754974720, &scale); - tmp1 = mult(tmp, EVS_PI_FX); // Q13 + Q15 - Q15 --> Q13 - tmp1 = getCosWord16(tmp); // Q14 + tmp1 = BASOP_Util_Divide3232_Scale( hOMasa->ism_elevation_fx[i], 754974720, &scale ); + tmp1 = mult( tmp, EVS_PI_FX ); // Q13 + Q15 - Q15 --> Q13 + tmp1 = getCosWord16( tmp ); // Q14 - hOMasa->chnlToFoaMtx_fx[3][i] = shl( mult(tmp, tmp1), 2 ); // Q14 + Q14 - Q15 + Q2-> Q13 + Q2 -> Q15 + hOMasa->chnlToFoaMtx_fx[3][i] = shl( mult( tmp, tmp1 ), 2 ); // Q14 + Q14 - Q15 + Q2-> Q13 + Q2 -> Q15 } /* do processing over all CLDFB time slots */ - FOR ( block_m_idx = 0; block_m_idx < MAX_PARAM_SPATIAL_SUBFRAMES; block_m_idx++ ) + FOR( block_m_idx = 0; block_m_idx < MAX_PARAM_SPATIAL_SUBFRAMES; block_m_idx++ ) { mrange[0] = hOMasa->block_grouping[block_m_idx]; move16(); mrange[1] = hOMasa->block_grouping[block_m_idx + 1]; move16(); - FOR ( band_m_idx = 0; band_m_idx < hOMasa->nbands; band_m_idx++ ) + FOR( band_m_idx = 0; band_m_idx < hOMasa->nbands; band_m_idx++ ) { hOMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx] = 0; move32(); @@ -838,42 +837,41 @@ static void ivas_omasa_param_est_ana_fx( set_zero_fx( diffuseness_m_fx, hOMasa->nbands ); set_zero_fx( hOMasa->energy_fx[block_m_idx], MASA_FREQUENCY_BANDS ); - FOR ( ts = mrange[0]; ts < mrange[1]; ts++ ) + FOR( ts = mrange[0]; ts < mrange[1]; ts++ ) { - FOR ( i = 0; i < nchan_ism; i++ ) + FOR( i = 0; i < nchan_ism; i++ ) { Word16 in_q; in_q = data_f_q; move16(); - cldfbAnalysis_ts_fx( &( data_f_fx[i][l_ts * ts] ), Chnl_RealBuffer_fx[i], Chnl_ImagBuffer_fx[i], l_ts, hOMasa->cldfbAnaEnc[i], &in_q); + cldfbAnalysis_ts_fx( &( data_f_fx[i][l_ts * ts] ), Chnl_RealBuffer_fx[i], Chnl_ImagBuffer_fx[i], l_ts, hOMasa->cldfbAnaEnc[i], &in_q ); - FOR (Word16 ind = 0; ind < CLDFB_NO_CHANNELS_MAX; ind++) + FOR( Word16 ind = 0; ind < CLDFB_NO_CHANNELS_MAX; ind++ ) { - Chnl_RealBuffer_fx[i][ind] = Chnl_RealBuffer_fx[i][ind] / (1 << 4); - Chnl_ImagBuffer_fx[i][ind] = Chnl_ImagBuffer_fx[i][ind] / (1 << 4); - + Chnl_RealBuffer_fx[i][ind] = Chnl_RealBuffer_fx[i][ind] / ( 1 << 4 ); + Chnl_ImagBuffer_fx[i][ind] = Chnl_ImagBuffer_fx[i][ind] / ( 1 << 4 ); } - Chnl_RealBuffer_q = sub(in_q, 4); - Chnl_ImagBuffer_q = sub(in_q, 4); + Chnl_RealBuffer_q = sub( in_q, 4 ); + Chnl_ImagBuffer_q = sub( in_q, 4 ); } /* Compute channel-based energy for metadata processing */ - FOR ( band_m_idx = 0; band_m_idx < num_freq_bands; band_m_idx++ ) + FOR( band_m_idx = 0; band_m_idx < num_freq_bands; band_m_idx++ ) { brange[0] = hOMasa->band_grouping[band_m_idx]; move16(); brange[1] = hOMasa->band_grouping[band_m_idx + 1]; move16(); - FOR ( j = brange[0]; j < brange[1]; j++ ) + FOR( j = brange[0]; j < brange[1]; j++ ) { - FOR ( i = 0; i < nchan_ism; i++ ) + FOR( i = 0; i < nchan_ism; i++ ) { - L_tmp1 = Mpy_32_32(Chnl_RealBuffer_fx[i][j], Chnl_RealBuffer_fx[i][j]); - L_tmp2 = Mpy_32_32(Chnl_ImagBuffer_fx[i][j], Chnl_ImagBuffer_fx[i][j]); - hOMasa->energy_fx[block_m_idx][band_m_idx] = L_add(hOMasa->energy_fx[block_m_idx][band_m_idx], L_add(L_tmp1, L_tmp2));// Chnl_RealBuffer_q + Chnl_RealBuffer_q - 31 + L_tmp1 = Mpy_32_32( Chnl_RealBuffer_fx[i][j], Chnl_RealBuffer_fx[i][j] ); + L_tmp2 = Mpy_32_32( Chnl_ImagBuffer_fx[i][j], Chnl_ImagBuffer_fx[i][j] ); + hOMasa->energy_fx[block_m_idx][band_m_idx] = L_add( hOMasa->energy_fx[block_m_idx][band_m_idx], L_add( L_tmp1, L_tmp2 ) ); // Chnl_RealBuffer_q + Chnl_RealBuffer_q - 31 hOMasa->energy_q = sub( add( Chnl_RealBuffer_q, Chnl_RealBuffer_q ), 31 ); } } @@ -885,18 +883,18 @@ static void ivas_omasa_param_est_ana_fx( Copy32( Chnl_RealBuffer_fx[0], Foa_RealBuffer_fx[0], num_freq_bins ); Copy32( Chnl_ImagBuffer_fx[0], Foa_ImagBuffer_fx[0], num_freq_bins ); - FOR ( i = 1; i < nchan_ism; i++ ) + FOR( i = 1; i < nchan_ism; i++ ) { - v_add_fixed(Chnl_RealBuffer_fx[i], Foa_RealBuffer_fx[0], Foa_RealBuffer_fx[0], num_freq_bins, 0); - v_add_fixed(Chnl_ImagBuffer_fx[i], Foa_ImagBuffer_fx[0], Foa_ImagBuffer_fx[0], num_freq_bins, 0); + v_add_fixed( Chnl_RealBuffer_fx[i], Foa_RealBuffer_fx[0], Foa_RealBuffer_fx[0], num_freq_bins, 0 ); + v_add_fixed( Chnl_ImagBuffer_fx[i], Foa_ImagBuffer_fx[0], Foa_ImagBuffer_fx[0], num_freq_bins, 0 ); } /* Y */ - v_multc_fixed(Chnl_RealBuffer_fx[0], L_deposit_h(hOMasa->chnlToFoaMtx_fx[1][0]), Foa_RealBuffer_fx[1], num_freq_bins); - v_multc_fixed(Chnl_ImagBuffer_fx[0], L_deposit_h(hOMasa->chnlToFoaMtx_fx[1][0]), Foa_ImagBuffer_fx[1], num_freq_bins); + v_multc_fixed( Chnl_RealBuffer_fx[0], L_deposit_h( hOMasa->chnlToFoaMtx_fx[1][0] ), Foa_RealBuffer_fx[1], num_freq_bins ); + v_multc_fixed( Chnl_ImagBuffer_fx[0], L_deposit_h( hOMasa->chnlToFoaMtx_fx[1][0] ), Foa_ImagBuffer_fx[1], num_freq_bins ); - FOR ( i = 1; i < nchan_ism; i++ ) + FOR( i = 1; i < nchan_ism; i++ ) { v_multc_acc_32_16( Chnl_RealBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[1][i], Foa_RealBuffer_fx[1], num_freq_bins ); v_multc_acc_32_16( Chnl_ImagBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[1][i], Foa_ImagBuffer_fx[1], num_freq_bins ); @@ -904,37 +902,37 @@ static void ivas_omasa_param_est_ana_fx( /* Z */ - v_multc_fixed( Chnl_RealBuffer_fx[0], L_deposit_h(hOMasa->chnlToFoaMtx_fx[2][0]), Foa_RealBuffer_fx[2], num_freq_bins ); - v_multc_fixed( Chnl_ImagBuffer_fx[0], L_deposit_h(hOMasa->chnlToFoaMtx_fx[2][0]), Foa_ImagBuffer_fx[2], num_freq_bins ); + v_multc_fixed( Chnl_RealBuffer_fx[0], L_deposit_h( hOMasa->chnlToFoaMtx_fx[2][0] ), Foa_RealBuffer_fx[2], num_freq_bins ); + v_multc_fixed( Chnl_ImagBuffer_fx[0], L_deposit_h( hOMasa->chnlToFoaMtx_fx[2][0] ), Foa_ImagBuffer_fx[2], num_freq_bins ); - FOR ( i = 1; i < nchan_ism; i++ ) + FOR( i = 1; i < nchan_ism; i++ ) { v_multc_acc_32_16( Chnl_RealBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[2][i], Foa_RealBuffer_fx[2], num_freq_bins ); v_multc_acc_32_16( Chnl_ImagBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[2][i], Foa_ImagBuffer_fx[2], num_freq_bins ); } - v_multc_fixed( Chnl_RealBuffer_fx[0], L_deposit_h(hOMasa->chnlToFoaMtx_fx[3][0]), Foa_RealBuffer_fx[2], num_freq_bins ); - v_multc_fixed( Chnl_ImagBuffer_fx[0], L_deposit_h(hOMasa->chnlToFoaMtx_fx[3][0]), Foa_ImagBuffer_fx[2], num_freq_bins ); + v_multc_fixed( Chnl_RealBuffer_fx[0], L_deposit_h( hOMasa->chnlToFoaMtx_fx[3][0] ), Foa_RealBuffer_fx[2], num_freq_bins ); + v_multc_fixed( Chnl_ImagBuffer_fx[0], L_deposit_h( hOMasa->chnlToFoaMtx_fx[3][0] ), Foa_ImagBuffer_fx[2], num_freq_bins ); - FOR ( i = 1; i < nchan_ism; i++ ) + FOR( i = 1; i < nchan_ism; i++ ) { - v_multc_acc_32_16(Chnl_RealBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[3][i], Foa_RealBuffer_fx[3], num_freq_bins); - v_multc_acc_32_16(Chnl_ImagBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[3][i], Foa_ImagBuffer_fx[3], num_freq_bins); + v_multc_acc_32_16( Chnl_RealBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[3][i], Foa_RealBuffer_fx[3], num_freq_bins ); + v_multc_acc_32_16( Chnl_ImagBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[3][i], Foa_ImagBuffer_fx[3], num_freq_bins ); } /* Direction estimation */ - FOR (i = 0; i < FOA_CHANNELS; i++) + FOR( i = 0; i < FOA_CHANNELS; i++ ) { - FOR (j = 0; j < CLDFB_NO_CHANNELS_MAX; j++) + FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) { - Foa_RealBuffer_fx[i][j] = L_shr(Foa_RealBuffer_fx[i][j], 5); - Foa_ImagBuffer_fx[i][j] = L_shr(Foa_ImagBuffer_fx[i][j], 5); + Foa_RealBuffer_fx[i][j] = L_shr( Foa_RealBuffer_fx[i][j], 5 ); + Foa_ImagBuffer_fx[i][j] = L_shr( Foa_ImagBuffer_fx[i][j], 5 ); } } foa_q = sub( Chnl_ImagBuffer_q, 5 ); computeIntensityVector_ana_fx( hOMasa->band_grouping, Foa_RealBuffer_fx, Foa_ImagBuffer_fx, num_freq_bands, intensity_real_fx ); - intensity_q = sub( shl( add(foa_q, Q1), 1 ), 31 ); + intensity_q = sub( shl( add( foa_q, Q1 ), 1 ), 31 ); computeDirectionVectors_fx( intensity_real_fx[0], intensity_real_fx[1], intensity_real_fx[2], 0, num_freq_bands, direction_vector_fx[0], direction_vector_fx[1], direction_vector_fx[2], &direction_q ); @@ -947,7 +945,7 @@ static void ivas_omasa_param_est_ana_fx( hOMasa->index_buffer_intensity = ( hOMasa->index_buffer_intensity % DIRAC_NO_COL_AVG_DIFF ) + 1; /* averaging_length = 32 */ index = hOMasa->index_buffer_intensity; - FOR ( i = 0; i < DIRAC_NUM_DIMS; i++ ) + FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) { /* only real part needed */ Copy32( intensity_real_fx[i], &( hOMasa->buffer_intensity_real_fx[i][index - 1][0] ), num_freq_bands ); @@ -958,16 +956,16 @@ static void ivas_omasa_param_est_ana_fx( hOMasa->buffer_energy_q[index - 1] = reference_power_q; move16(); - computeDiffuseness_fixed(hOMasa->buffer_intensity_real_fx, hOMasa->buffer_energy_fx, num_freq_bands, diffuseness_vector_fx, hOMasa->buffer_intensity_real_q, hOMasa->buffer_energy_q, &diffuseness_q); + computeDiffuseness_fixed( hOMasa->buffer_intensity_real_fx, hOMasa->buffer_energy_fx, num_freq_bands, diffuseness_vector_fx, hOMasa->buffer_intensity_real_q, hOMasa->buffer_energy_q, &diffuseness_q ); - FOR ( band_m_idx = 0; band_m_idx < hOMasa->nbands; band_m_idx++ ) + FOR( band_m_idx = 0; band_m_idx < hOMasa->nbands; band_m_idx++ ) { - norm_tmp_fx = Mpy_32_32(reference_power_fx[band_m_idx], L_sub(1073741824, diffuseness_vector_fx[band_m_idx] )); // reference_power_q + 30 - 31 + norm_tmp_fx = Mpy_32_32( reference_power_fx[band_m_idx], L_sub( 1073741824, diffuseness_vector_fx[band_m_idx] ) ); // reference_power_q + 30 - 31 norm_tmp_q = sub( add( reference_power_q, 30 ), 31 ); hOMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx] = L_add( hOMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx], Mpy_32_32( norm_tmp_fx, direction_vector_fx[0][band_m_idx] ) ); - hOMasa->direction_vector_m_fx[1][block_m_idx][band_m_idx] = L_add(hOMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx], Mpy_32_32( norm_tmp_fx, direction_vector_fx[1][band_m_idx] ) ); + hOMasa->direction_vector_m_fx[1][block_m_idx][band_m_idx] = L_add( hOMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx], Mpy_32_32( norm_tmp_fx, direction_vector_fx[1][band_m_idx] ) ); hOMasa->direction_vector_m_fx[2][block_m_idx][band_m_idx] = L_add( hOMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx], Mpy_32_32( norm_tmp_fx, direction_vector_fx[2][band_m_idx] ) ); hOMasa->direction_vector_m_q = sub( add( norm_tmp_q, direction_q ), 31 ); @@ -981,18 +979,18 @@ static void ivas_omasa_param_est_ana_fx( } } - FOR (band_m_idx = 0; band_m_idx < hOMasa->nbands; band_m_idx++) + FOR( band_m_idx = 0; band_m_idx < hOMasa->nbands; band_m_idx++ ) { - FOR (d = 0; d < DIRAC_NUM_DIMS; d++) + FOR( d = 0; d < DIRAC_NUM_DIMS; d++ ) { dir_v_fx[d] = hOMasa->direction_vector_m_fx[d][block_m_idx][band_m_idx]; move32(); } dir_v_q = hOMasa->direction_vector_m_q; - FOR ( i = 0; i < DIRAC_NUM_DIMS; i++) + FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) { - dir_v_fx[i] = L_shr(dir_v_fx[i], 1); + dir_v_fx[i] = L_shr( dir_v_fx[i], 1 ); } dir_v_q = sub( dir_v_q, 1 ); @@ -1000,25 +998,25 @@ static void ivas_omasa_param_est_ana_fx( } /* Determine energy ratios */ - FOR ( band_m_idx = 0; band_m_idx < hOMasa->nbands; band_m_idx++ ) + FOR( band_m_idx = 0; band_m_idx < hOMasa->nbands; band_m_idx++ ) { - IF ( BASOP_Util_Cmp_Mant32Exp( renormalization_factor_diff_fx[band_m_idx], sub( 31, renormalization_factor_diff_q ), L_deposit_h(EPSILON_FX), 2 ) > 0) + IF( BASOP_Util_Cmp_Mant32Exp( renormalization_factor_diff_fx[band_m_idx], sub( 31, renormalization_factor_diff_q ), L_deposit_h( EPSILON_FX ), 2 ) > 0 ) { diffuseness_m_fx[band_m_idx] = BASOP_Util_Divide3232_Scale( diffuseness_m_fx[band_m_idx], renormalization_factor_diff_fx[band_m_idx], &scale ); - scale = add( scale, sub(sub(31, diffuseness_m_q), sub(31, renormalization_factor_diff_q)) ); + scale = add( scale, sub( sub( 31, diffuseness_m_q ), sub( 31, renormalization_factor_diff_q ) ) ); - diffuseness_m_fx[band_m_idx] = L_shr(diffuseness_m_fx[band_m_idx], sub( 31, add( scale, diffuseness_m_q ) ) ); + diffuseness_m_fx[band_m_idx] = L_shr( diffuseness_m_fx[band_m_idx], sub( 31, add( scale, diffuseness_m_q ) ) ); } ELSE { diffuseness_m_fx[band_m_idx] = 0; move32(); } - energyRatio_fx[block_m_idx][band_m_idx] = L_sub( L_shl(1, diffuseness_m_q ), diffuseness_m_fx[band_m_idx] ); + energyRatio_fx[block_m_idx][band_m_idx] = L_sub( L_shl( 1, diffuseness_m_q ), diffuseness_m_fx[band_m_idx] ); } /* Set coherences to zero, as this mode is used at lowest bit rates where the coherences are not transmitted */ - FOR ( band_m_idx = 0; band_m_idx < hOMasa->nbands; band_m_idx++ ) + FOR( band_m_idx = 0; band_m_idx < hOMasa->nbands; band_m_idx++ ) { spreadCoherence_fx[block_m_idx][band_m_idx] = 0; move32(); @@ -1050,7 +1048,7 @@ static void ivas_omasa_dmx_fx( const Word32 ism_azimuth_fx[MAX_NUM_OBJECTS], const Word32 ism_elevation_fx[MAX_NUM_OBJECTS], Word32 prev_gains_fx[][MASA_MAX_TRANSPORT_CHANNELS], - const Word16 interpolator_fx[L_FRAME48k]) + const Word16 interpolator_fx[L_FRAME48k] ) { Word16 i, j, k, l, tmp1, tmp2; @@ -1062,75 +1060,73 @@ static void ivas_omasa_dmx_fx( Word16 in_e[960]; Word16 data_e[4]; - FOR ( i = 0; i < nchan_transport; i++ ) + FOR( i = 0; i < nchan_transport; i++ ) { set_zero_fx( data_out_f_fx[i], input_frame ); } - set_s(data_e, 0, 4); - set_s(in_e, 0, 960); + set_s( data_e, 0, 4 ); + set_s( in_e, 0, 960 ); - FOR ( i = 0; i < nchan_ism; i++ ) + FOR( i = 0; i < nchan_ism; i++ ) { - azimuth_fx = extract_l(L_shr( ism_azimuth_fx[i], Q22)); - elevation_fx = extract_l(L_shr( ism_elevation_fx[i], Q22 )); + azimuth_fx = extract_l( L_shr( ism_azimuth_fx[i], Q22 ) ); + elevation_fx = extract_l( L_shr( ism_elevation_fx[i], Q22 ) ); ivas_ism_get_stereo_gains_fx( azimuth_fx, elevation_fx, &gains_fx[0], &gains_fx[1] ); /* Downmix using the panning gains */ - FOR ( j = 0; j < nchan_transport; j++ ) + FOR( j = 0; j < nchan_transport; j++ ) { - IF ( GT_32( L_abs( L_deposit_h( gains_fx[j] ) ), 0 ) || GT_32( L_abs( prev_gains_fx[i][j] ), 0 ) ) + IF( GT_32( L_abs( L_deposit_h( gains_fx[j] ) ), 0 ) || GT_32( L_abs( prev_gains_fx[i][j] ), 0 ) ) { - FOR ( k = 0; k < input_frame; k++ ) + FOR( k = 0; k < input_frame; k++ ) { g1_fx = interpolator_fx[k]; // Q15 move16(); - scale = BASOP_Util_Add_MantExp(16384, 1, negate(g1_fx), 0, &g2_fx); + scale = BASOP_Util_Add_MantExp( 16384, 1, negate( g1_fx ), 0, &g2_fx ); - tmp1 = mult(g1_fx, gains_fx[j]); - tmp2 = mult(g2_fx, (Word16)L_shr(prev_gains_fx[i][j], 16)); - scale = BASOP_Util_Add_MantExp(tmp1, 0, tmp2, scale, &tmp1); + tmp1 = mult( g1_fx, gains_fx[j] ); + tmp2 = mult( g2_fx, (Word16) L_shr( prev_gains_fx[i][j], 16 ) ); + scale = BASOP_Util_Add_MantExp( tmp1, 0, tmp2, scale, &tmp1 ); L_tmp = data_in_f_fx[i][k]; move32(); tmp_e = sub( 31, *data_in_q ); move16(); - L_tmp = Mpy_32_16_1(L_tmp, tmp1); + L_tmp = Mpy_32_16_1( L_tmp, tmp1 ); scale = add( scale, tmp_e ); - data_out_f_fx[j][k] = BASOP_Util_Add_Mant32Exp(data_out_f_fx[j][k], data_e[j], L_tmp, scale, &in_e[k]); - + data_out_f_fx[j][k] = BASOP_Util_Add_Mant32Exp( data_out_f_fx[j][k], data_e[j], L_tmp, scale, &in_e[k] ); } } max_e = in_e[0]; move16(); - FOR(l = 1; l < L_FRAME48k; l++) + FOR( l = 1; l < L_FRAME48k; l++ ) { - IF(LT_16( max_e, in_e[l] ) ) + IF( LT_16( max_e, in_e[l] ) ) { max_e = in_e[l]; move16(); } } - FOR(l = 0; l < L_FRAME48k; l++) + FOR( l = 0; l < L_FRAME48k; l++ ) { - data_out_f_fx[j][l] = L_shr(data_out_f_fx[j][l], sub( max_e, in_e[l] ) ); + data_out_f_fx[j][l] = L_shr( data_out_f_fx[j][l], sub( max_e, in_e[l] ) ); } data_e[j] = max_e; move16(); prev_gains_fx[i][j] = L_deposit_h( gains_fx[j] ); // Q31 - } } max_e = data_e[0]; move16(); - FOR(i = 1; i < nchan_transport; i++) + FOR( i = 1; i < nchan_transport; i++ ) { IF( LT_16( max_e, data_e[i] ) ) { @@ -1139,17 +1135,17 @@ static void ivas_omasa_dmx_fx( } } - FOR(i = 0; i < nchan_transport; i++) + FOR( i = 0; i < nchan_transport; i++ ) { - FOR(j = 0; j < input_frame; j++) + FOR( j = 0; j < input_frame; j++ ) { - data_out_f_fx[i][j] = L_shr(data_out_f_fx[i][j], max_e - data_e[i]); + data_out_f_fx[i][j] = L_shr( data_out_f_fx[i][j], max_e - data_e[i] ); } } - FOR ( i = 0; i < nchan_transport; i++ ) + FOR( i = 0; i < nchan_transport; i++ ) { - Copy32(data_out_f_fx[i], data_in_f_fx[i], input_frame); + Copy32( data_out_f_fx[i], data_in_f_fx[i], input_frame ); *data_in_q = sub( 31, max_e ); move16(); } @@ -1222,10 +1218,10 @@ static void ivas_omasa_dmx( *--------------------------------------------------------------------------*/ void computeIntensityVector_ana_fx( - const Word16 *band_grouping, /* i : Band grouping for estimation */ + const Word16 *band_grouping, /* i : Band grouping for estimation */ Word32 Cldfb_RealBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Real part of input signal */ Word32 Cldfb_ImagBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Imag part of input signal */ - const Word16 num_frequency_bands, /* i : Number of frequency bands */ + const Word16 num_frequency_bands, /* i : Number of frequency bands */ Word32 intensity_real[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS] /* o : Intensity vector */ ) { @@ -1251,9 +1247,9 @@ void computeIntensityVector_ana_fx( real = Cldfb_RealBuffer[0][j]; img = Cldfb_ImagBuffer[0][j]; /* Intensity is XYZ order, audio is WYZX order. */ - intensity_real[0][i] = L_add( intensity_real[0][i], L_add( Mpy_32_32( Cldfb_RealBuffer[3][j], real ), Mpy_32_32( Cldfb_ImagBuffer[3][j], img ) ) ); //output Q= 2* input_q -31 - intensity_real[1][i] = L_add( intensity_real[1][i], L_add( Mpy_32_32( Cldfb_RealBuffer[1][j], real ), Mpy_32_32( Cldfb_ImagBuffer[1][j], img ) ) );//output Q= 2* input_q -31 - intensity_real[2][i] = L_add( intensity_real[2][i], L_add( Mpy_32_32( Cldfb_RealBuffer[2][j], real ), Mpy_32_32( Cldfb_ImagBuffer[2][j], img ) ) );//output Q= 2* input_q -31 + intensity_real[0][i] = L_add( intensity_real[0][i], L_add( Mpy_32_32( Cldfb_RealBuffer[3][j], real ), Mpy_32_32( Cldfb_ImagBuffer[3][j], img ) ) ); // output Q= 2* input_q -31 + intensity_real[1][i] = L_add( intensity_real[1][i], L_add( Mpy_32_32( Cldfb_RealBuffer[1][j], real ), Mpy_32_32( Cldfb_ImagBuffer[1][j], img ) ) ); // output Q= 2* input_q -31 + intensity_real[2][i] = L_add( intensity_real[2][i], L_add( Mpy_32_32( Cldfb_RealBuffer[2][j], real ), Mpy_32_32( Cldfb_ImagBuffer[2][j], img ) ) ); // output Q= 2* input_q -31 } } @@ -1312,11 +1308,11 @@ void computeIntensityVector_ana( *--------------------------------------------------------------------------*/ void computeReferencePower_ana_fx( - const Word16 *band_grouping, /* i : Band grouping for estimation */ + const Word16 *band_grouping, /* i : Band grouping for estimation */ Word32 Cldfb_RealBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Real part of input signal */ Word32 Cldfb_ImagBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Imag part of input signal */ Word32 *reference_power, /* o : Estimated power */ - const Word16 num_freq_bands /* i : Number of frequency bands */ + const Word16 num_freq_bands /* i : Number of frequency bands */ ) { Word16 brange[2]; @@ -1333,15 +1329,15 @@ void computeReferencePower_ana_fx( /* abs()^2 */ for ( j = brange[0]; j < brange[1]; j++ ) { - //Q = 2*inputq - 31 + // Q = 2*inputq - 31 reference_power[i] = L_add( L_add( Mpy_32_32( Cldfb_RealBuffer[ch_idx][j], Cldfb_RealBuffer[ch_idx][j] ), Mpy_32_32( Cldfb_ImagBuffer[ch_idx][j], Cldfb_ImagBuffer[ch_idx][j] ) ), reference_power[i] ); } } } - // v_multc( reference_power, 0.5f, reference_power, num_freq_bands ); + // v_multc( reference_power, 0.5f, reference_power, num_freq_bands ); - /* Bypassing the v_multc ,so output q = 2*inputq - 30*/ + /* Bypassing the v_multc ,so output q = 2*inputq - 30*/ return; } #endif @@ -1382,4 +1378,4 @@ void computeReferencePower_ana( v_multc( reference_power, 0.5f, reference_power, num_freq_bands ); return; -} \ No newline at end of file +} diff --git a/lib_rend/ivas_orient_trk.c b/lib_rend/ivas_orient_trk.c index d869e2df8..0a6cdbe4d 100644 --- a/lib_rend/ivas_orient_trk.c +++ b/lib_rend/ivas_orient_trk.c @@ -52,7 +52,7 @@ #ifdef NONBE_FIX_738_QUATERNION_SLERP_PRECISION #define COS_ONE_TENTH_DEGREE ( 0.999998476913288f ) #endif -#define COS_ONE_TENTH_DEGREE_FX 2147480320 //Q31 +#define COS_ONE_TENTH_DEGREE_FX 2147480320 // Q31 /*------------------------------------------------------------------------------------------* @@ -120,12 +120,12 @@ void QuaternionProduct_fx( { IVAS_QUATERNION tmp; - //once verify// + // once verify// tmp.w_fx = L_sub( ( L_sub( Mpy_32_32( q1.w_fx, q2.w_fx ), Mpy_32_32( q1.x_fx, q2.x_fx ) ) ), ( L_add( Mpy_32_32( q1.y_fx, q2.y_fx ), Mpy_32_32( q1.z_fx, q2.z_fx ) ) ) ); tmp.x_fx = L_add( ( L_add( Mpy_32_32( q1.w_fx, q2.x_fx ), Mpy_32_32( q1.x_fx, q2.w_fx ) ) ), ( L_sub( Mpy_32_32( q1.y_fx, q2.z_fx ), Mpy_32_32( q1.z_fx, q2.y_fx ) ) ) ); tmp.y_fx = L_add( ( L_sub( Mpy_32_32( q1.w_fx, q2.y_fx ), Mpy_32_32( q1.x_fx, q2.z_fx ) ) ), ( L_add( Mpy_32_32( q1.y_fx, q2.w_fx ), Mpy_32_32( q1.z_fx, q2.x_fx ) ) ) ); tmp.z_fx = L_sub( ( L_add( Mpy_32_32( q1.w_fx, q2.z_fx ), Mpy_32_32( q1.x_fx, q2.y_fx ) ) ), ( L_sub( Mpy_32_32( q1.y_fx, q2.x_fx ), Mpy_32_32( q1.z_fx, q2.w_fx ) ) ) ); - tmp.q_fact = sub(add(q1.q_fact, q2.q_fact), 31); + tmp.q_fact = sub( add( q1.q_fact, q2.q_fact ), 31 ); *r = tmp; return; @@ -206,7 +206,7 @@ static void QuaternionDivision_fx( result_e = scale_e + ( ( 31 - q.q_fact ) - den_e ); z_q = 31 - result_e; - result_q = sub(s_min( s_min( w_q, x_q ), s_min( y_q, z_q ) ), 1); //gaurdbits// + result_q = sub( s_min( s_min( w_q, x_q ), s_min( y_q, z_q ) ), 1 ); // gaurdbits// r->w_fx = L_shr( r->w_fx, sub( w_q, result_q ) ); r->x_fx = L_shr( r->x_fx, sub( x_q, result_q ) ); @@ -595,7 +595,7 @@ static IVAS_VECTOR3 VectorSubtract_fx( result.z_fx = BASOP_Util_Add_Mant32Exp( p1.z_fx, ( 31 - p1.q_fact ), ( L_negate( p2.z_fx ) ), ( 31 - p2.q_fact ), &e_result ); z_qfact = sub( 31, e_result ); - q_result = sub(s_min( s_min( x_qfact, y_qfact ), z_qfact ), 1); //guardbit// + q_result = sub( s_min( s_min( x_qfact, y_qfact ), z_qfact ), 1 ); // guardbit// result.x_fx = L_shr( result.x_fx, sub( x_qfact, q_result ) ); result.y_fx = L_shr( result.y_fx, sub( y_qfact, q_result ) ); result.z_fx = L_shr( result.z_fx, sub( z_qfact, q_result ) ); @@ -634,7 +634,7 @@ static IVAS_VECTOR3 VectorCrossProduct_fx( result_fx.x_fx = L_sub( Mpy_32_32( p1.y_fx, p2.z_fx ), Mpy_32_32( p1.z_fx, p2.y_fx ) ); result_fx.y_fx = L_sub( Mpy_32_32( p1.z_fx, p2.x_fx ), Mpy_32_32( p1.x_fx, p2.z_fx ) ); result_fx.z_fx = L_sub( Mpy_32_32( p1.x_fx, p2.y_fx ), Mpy_32_32( p1.y_fx, p2.x_fx ) ); - result_fx.q_fact = sub(add(p1.q_fact, p2.q_fact), 31); + result_fx.q_fact = sub( add( p1.q_fact, p2.q_fact ), 31 ); return result_fx; } @@ -662,7 +662,7 @@ static Word32 VectorDotProduct_fx( Word32 result_fx = 0; result_fx = L_add( L_add( Mpy_32_32( p1.x_fx, p2.x_fx ), Mpy_32_32( p1.y_fx, p2.y_fx ) ), Mpy_32_32( p1.z_fx, p2.z_fx ) ); - *q_fact = sub(add(p1.q_fact, p2.q_fact), 31); + *q_fact = sub( add( p1.q_fact, p2.q_fact ), 31 ); return result_fx; } @@ -686,9 +686,9 @@ static Word32 VectorLength_fx( Word16 *q_fact ) { Word32 result_fx = 0; - result_fx = L_add(L_add(Mpy_32_32(p.x_fx, p.x_fx), Mpy_32_32(p.y_fx, p.y_fx)), Mpy_32_32(p.z_fx, p.z_fx)); + result_fx = L_add( L_add( Mpy_32_32( p.x_fx, p.x_fx ), Mpy_32_32( p.y_fx, p.y_fx ) ), Mpy_32_32( p.z_fx, p.z_fx ) ); - *q_fact = sub(add(p.q_fact, p.q_fact), 31); + *q_fact = sub( add( p.q_fact, p.q_fact ), 31 ); return result_fx; } #endif @@ -723,18 +723,18 @@ static IVAS_VECTOR3 VectorNormalize_fx( length_fx = VectorLength_fx( p, &q_len ); result_fx.x_fx = BASOP_Util_Divide3232_Scale_cadence( p.x_fx, length_fx, &scale ); - x_qfact = ( 31 - ( scale + ( q_len - p.q_fact) ) ); // e+(e1-e2)// + x_qfact = ( 31 - ( scale + ( q_len - p.q_fact ) ) ); // e+(e1-e2)// result_fx.y_fx = BASOP_Util_Divide3232_Scale_cadence( p.y_fx, length_fx, &scale ); - y_qfact = ( 31 - ( scale + ( q_len - p.q_fact) ) ); + y_qfact = ( 31 - ( scale + ( q_len - p.q_fact ) ) ); result_fx.z_fx = BASOP_Util_Divide3232_Scale_cadence( p.z_fx, length_fx, &scale ); - z_qfact = ( 31 - ( scale + ( q_len - p.q_fact) ) ); + z_qfact = ( 31 - ( scale + ( q_len - p.q_fact ) ) ); - q_result = s_min(s_min(x_qfact, y_qfact), z_qfact); - result_fx.x_fx = L_shr(result_fx.x_fx, sub(x_qfact, q_result)); - result_fx.y_fx = L_shr(result_fx.y_fx, sub(y_qfact, q_result)); - result_fx.z_fx = L_shr(result_fx.z_fx, sub(z_qfact, q_result)); + q_result = s_min( s_min( x_qfact, y_qfact ), z_qfact ); + result_fx.x_fx = L_shr( result_fx.x_fx, sub( x_qfact, q_result ) ); + result_fx.y_fx = L_shr( result_fx.y_fx, sub( y_qfact, q_result ) ); + result_fx.z_fx = L_shr( result_fx.z_fx, sub( z_qfact, q_result ) ); result_fx.q_fact = q_result; return result_fx; @@ -797,7 +797,7 @@ static void VectorRotationToQuaternion_fx( dot_product_fx = VectorDotProduct_fx( p1_normalized_fx, p2_normalized_fx, &q_dot ); // dot & cross product are same q// - Word32 comp_fx = -2147481472;//-0.999999f in Q31 + Word32 comp_fx = -2147481472; //-0.999999f in Q31 Word16 comp_e = 0, check_flag; IF( GT_32( dot_product_fx, 0 ) ) { @@ -822,7 +822,7 @@ static void VectorRotationToQuaternion_fx( r->y_fx = cross_product_fx.y_fx; r->z_fx = cross_product_fx.z_fx; r->w_fx = BASOP_Util_Add_Mant32Exp( dot_product_fx, sub( 31, q_dot ), ONE_IN_Q31, 0, &e_add ); - q_result = sub(s_min( sub( 31, e_add ), q_dot ),1);//gaurd bits// + q_result = sub( s_min( sub( 31, e_add ), q_dot ), 1 ); // gaurd bits// r->x_fx = L_shr( r->x_fx, sub( q_dot, q_result ) ); r->y_fx = L_shr( r->y_fx, sub( q_dot, q_result ) ); r->z_fx = L_shr( r->z_fx, sub( q_dot, q_result ) ); @@ -880,13 +880,17 @@ ivas_error ivas_orient_trk_Init_fx( { IVAS_QUATERNION identity_fx; - IF ( pOTR == NULL ) + IF( pOTR == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } - identity_fx.w_fx = ONE_IN_Q31; move32(); - identity_fx.x_fx = identity_fx.y_fx = identity_fx.z_fx = 0; move32(); move32(); - identity_fx.q_fact = Q31; move16(); + identity_fx.w_fx = ONE_IN_Q31; + move32(); + identity_fx.x_fx = identity_fx.y_fx = identity_fx.z_fx = 0; + move32(); + move32(); + identity_fx.q_fact = Q31; + move16(); /* configuration parameters */ pOTR->centerAdaptationRate_fx = C_ADP_RATE_Q31; @@ -898,8 +902,10 @@ ivas_error ivas_orient_trk_Init_fx( /* initial adaptivity filter coefficient, will be auto-adapted */ // pOTR->alpha = sinf( PI2 * pOTR->offCenterAdaptationRate / OTR_UPDATE_RATE ); /* start adaptation at off-center rate = fastest rate */ - pOTR->alpha_fx = 33731208; move32();// Q31 - pOTR->Q_alpha = Q31; move16(); + pOTR->alpha_fx = 33731208; + move32(); // Q31 + pOTR->Q_alpha = Q31; + move16(); pOTR->trkRot = identity_fx; pOTR->absAvgRot = identity_fx; /* Use frontal and horiontal orientation as reference orientation, unless/until overridden */ @@ -962,7 +968,7 @@ ivas_error ivas_orient_trk_SetReferenceRotation_fx( const IVAS_QUATERNION refRot /* i : reference rotation */ ) { - IF ( pOTR == NULL ) + IF( pOTR == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } @@ -1042,12 +1048,12 @@ ivas_error ivas_orient_trk_GetMainOrientation_fx( IVAS_QUATERNION *pOrientation /* i/o: average/reference orientation */ ) { - IF ( pOTR == NULL || pOrientation == NULL ) + IF( pOTR == NULL || pOrientation == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } - SWITCH ( pOTR->orientation_tracking ) + SWITCH( pOTR->orientation_tracking ) { case IVAS_HEAD_ORIENT_TRK_NONE: *pOrientation = IdentityQuaternion_fx(); @@ -1336,7 +1342,7 @@ ivas_error ivas_orient_trk_Process_fx( Word32 rateRange_fx; Word32 cutoffFrequency_fx, cutoff_prod; Word16 q_cutoff_prod = 0; - Word32 alpha_fx = L_shl( pOTR->alpha_fx, sub(Q30, pOTR->Q_alpha) ); + Word32 alpha_fx = L_shl( pOTR->alpha_fx, sub( Q30, pOTR->Q_alpha ) ); IF( pOTR == NULL || pTrkRot == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; @@ -1359,9 +1365,10 @@ ivas_error ivas_orient_trk_Process_fx( Word32 div; div = L_deposit_h( BASOP_Util_Divide3232_Scale( pOTR->centerAdaptationRate_fx, updateRate_fx, &scale_e ) ); - scale_e = sub(scale_e, 8); // e+e1-e2// + scale_e = sub( scale_e, 8 ); // e+e1-e2// // here div value is less so we can use sandwitch rule of sine// - pOTR->alpha_fx = div; move32(); + pOTR->alpha_fx = div; + move32(); /* Compute relative orientation = (absolute orientation) - (reference orientation) */ QuaternionInverse_fx( pOTR->refRot, &pOTR->trkRot ); QuaternionProduct_fx( pOTR->trkRot, absRot, &pOTR->trkRot ); @@ -1373,16 +1380,20 @@ ivas_error ivas_orient_trk_Process_fx( /* Compute relative orientation = (absolute orientation) - (average absolute orientation) */ QuaternionInverse_fx( pOTR->absAvgRot, &pOTR->trkRot ); - Word32 angle_fx, relativeOrientationRate_fx = 0; move32(); + Word32 angle_fx, relativeOrientationRate_fx = 0; + move32(); QuaternionProduct_fx( pOTR->trkRot, absRot, &pOTR->trkRot ); angle_fx = QuaternionAngle_fx( absRot, pOTR->trkRot ); // Q29 - Word16 result_e = 0; move16(); + Word16 result_e = 0; + move16(); Word16 temp_result = BASOP_Util_Divide3232_Scale( angle_fx, pOTR->adaptationAngle_fx, &result_e ); relativeOrientationRate_fx = L_deposit_h( temp_result ); - Word32 one_fx = 1073741824; move32(); + Word32 one_fx = 1073741824; + move32(); IF( GT_32( relativeOrientationRate_fx, one_fx ) ) { - relativeOrientationRate_fx = 1; move32(); + relativeOrientationRate_fx = 1; + move32(); } /* Compute range of the adaptation rate between center = lower rate and off-center = higher rate */ @@ -1390,29 +1401,32 @@ ivas_error ivas_orient_trk_Process_fx( /* 'if' assumed to perform comparison to 0 */ IF( GT_32( 0, rateRange_fx ) ) { - rateRange_fx = 0;move32(); + rateRange_fx = 0; + move32(); } - IF( EQ_32(relativeOrientationRate_fx, 1 )) + IF( EQ_32( relativeOrientationRate_fx, 1 ) ) { - cutoff_prod = rateRange_fx;move32(); - q_cutoff_prod = Q31; move16(); + cutoff_prod = rateRange_fx; + move32(); + q_cutoff_prod = Q31; + move16(); } ELSE { cutoff_prod = Mpy_32_32( relativeOrientationRate_fx, rateRange_fx ); - q_cutoff_prod = add(Q31, sub(sub( 31, result_e ), 31)); + q_cutoff_prod = add( Q31, sub( sub( 31, result_e ), 31 ) ); } Word16 temp_diff; - temp_diff = sub(31, q_cutoff_prod); + temp_diff = sub( 31, q_cutoff_prod ); cutoff_prod = L_shl( cutoff_prod, temp_diff ); /* Compute adaptivity cutoff frequency: interpolate between minimum (center) and maximum (off-center) values */ cutoffFrequency_fx = L_add( pOTR->centerAdaptationRate_fx, cutoff_prod ); cutoff_prod = Mpy_32_32( cutoffFrequency_fx, PI2_C_Q28 ); - q_cutoff_prod = sub(add(31, 28), 31); + q_cutoff_prod = sub( add( 31, 28 ), 31 ); temp_result = BASOP_Util_Divide3232_Scale( cutoff_prod, updateRate_fx, &result_e ); - result_e = add(result_e, sub( 23, q_cutoff_prod )); + result_e = add( result_e, sub( 23, q_cutoff_prod ) ); pOTR->alpha_fx = L_deposit_h( temp_result ); - pOTR->Q_alpha = sub(Q31, result_e); + pOTR->Q_alpha = sub( Q31, result_e ); BREAK; default: result = IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Non-supported orientation tracking adaptation type" ); diff --git a/lib_rend/ivas_output_init.c b/lib_rend/ivas_output_init.c index bc3fb87dc..6ff205616 100644 --- a/lib_rend/ivas_output_init.c +++ b/lib_rend/ivas_output_init.c @@ -53,7 +53,7 @@ Word16 audioCfg2channels( { Word16 nchan_out; - SWITCH ( output_config ) + SWITCH( output_config ) { case IVAS_AUDIO_CONFIG_MONO: nchan_out = 1; @@ -489,7 +489,7 @@ void ivas_output_init( /*! r: number of decoder buffers */ Word16 ivas_get_nchan_buffers_dec( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const Word16 sba_analysis_order, /* i : SBA order evaluated in SBA decoder */ const Word32 ivas_total_brate /* i : total IVAS bitrate */ ) @@ -503,38 +503,38 @@ Word16 ivas_get_nchan_buffers_dec( nchan_out_buff = MAX_OUTPUT_CHANNELS; move16(); - IF ( EQ_32( st_ivas->ivas_format, MONO_FORMAT ) ) + IF( EQ_32( st_ivas->ivas_format, MONO_FORMAT ) ) { nchan_out_buff = st_ivas->hDecoderConfig->nchan_out; move16(); } - ELSE IF ( EQ_32( st_ivas->ivas_format, STEREO_FORMAT ) ) + ELSE IF( EQ_32( st_ivas->ivas_format, STEREO_FORMAT ) ) { nchan_out_buff = s_max( st_ivas->hDecoderConfig->nchan_out, CPE_CHANNELS ); } - ELSE IF ( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) ) + ELSE IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) ) { nchan_out_buff = st_ivas->nchan_ism; move16(); - IF ( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) + IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) { nchan_out_buff = s_max( nchan_out_buff, add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ) ); } - ELSE IF ( NE_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) + ELSE IF( NE_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) { nchan_out_buff = s_max( audioCfg2channels( st_ivas->transport_config ), audioCfg2channels( st_ivas->intern_config ) ); nchan_out_buff = s_max( nchan_out_buff, audioCfg2channels( output_config ) ); } } - ELSE IF ( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) ) + ELSE IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) ) { Word16 nchan_internal; nchan_internal = ivas_sba_get_nchan_metadata( sba_analysis_order, ivas_total_brate ); nchan_out_buff = st_ivas->hDecoderConfig->nchan_out; move16(); - IF ( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) + IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) { nchan_out_buff = s_max( nchan_out_buff, add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ) ); } @@ -545,62 +545,64 @@ Word16 ivas_get_nchan_buffers_dec( } nchan_out_buff = s_max( nchan_out_buff, nchan_internal ); } - ELSE IF ( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) ) + ELSE IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) ) { nchan_out_buff = CPE_CHANNELS; move16(); - test(); test(); test(); - IF ( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) + test(); + test(); + test(); + IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) { nchan_out_buff = s_max( nchan_out_buff, add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ) ); } - ELSE IF ( EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) + ELSE IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { nchan_out_buff = shl( CPE_CHANNELS, 1 ); } - ELSE IF ( NE_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) + ELSE IF( NE_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) { nchan_out_buff = s_max( nchan_out_buff, audioCfg2channels( st_ivas->intern_config ) ); nchan_out_buff = s_max( nchan_out_buff, audioCfg2channels( output_config ) ); } } - ELSE IF ( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) + ELSE IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) { nchan_out_buff = add( st_ivas->nchan_ism, CPE_CHANNELS ); - IF ( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) + IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) { nchan_out_buff = s_max( nchan_out_buff, add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ) ); } - ELSE IF ( NE_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) + ELSE IF( NE_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) { nchan_out_buff = s_max( nchan_out_buff, audioCfg2channels( st_ivas->intern_config ) ); nchan_out_buff = s_max( nchan_out_buff, audioCfg2channels( output_config ) ); } } - ELSE IF ( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) + ELSE IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { Word16 nchan_internal; nchan_internal = ivas_sba_get_nchan_metadata( sba_analysis_order, ivas_total_brate ); nchan_out_buff = add( st_ivas->nchan_ism, st_ivas->nchan_transport ); - IF ( st_ivas->hMCT != NULL ) + IF( st_ivas->hMCT != NULL ) { nchan_out_buff = shl( shr( add( nchan_out_buff, 1 ), 1 ), 1 ); /* ensure odd number of channels in MCT */ } - IF ( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) + IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) { nchan_out_buff = s_max( nchan_out_buff, add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ) ); } - ELSE IF ( NE_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) + ELSE IF( NE_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) { nchan_out_buff = s_max( nchan_out_buff, audioCfg2channels( st_ivas->intern_config ) ); nchan_out_buff = s_max( nchan_out_buff, audioCfg2channels( output_config ) ); test(); - IF ( EQ_32( st_ivas->renderer_type, RENDERER_OSBA_AMBI ) || EQ_32( st_ivas->renderer_type, RENDERER_OSBA_LS ) ) + IF( EQ_32( st_ivas->renderer_type, RENDERER_OSBA_AMBI ) || EQ_32( st_ivas->renderer_type, RENDERER_OSBA_LS ) ) { nchan_out_buff = s_max( add( nchan_out_buff, st_ivas->nchan_ism ), audioCfg2channels( output_config ) ); /* needed for ivas_sba_upmixer_renderer() */ } @@ -609,23 +611,23 @@ Word16 ivas_get_nchan_buffers_dec( nchan_out_buff = s_max( add( nchan_out_buff, st_ivas->nchan_ism ), audioCfg2channels( output_config ) ); /* needed for ivas_spar_dec_upmixer_sf() which is based on 'nchan_out' */ } } - ELSE IF ( EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) + ELSE IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) { nchan_out_buff = add( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_ism ); /*take into account sba_ch_idx' in ivas_dec() */ } test(); - IF ( !( EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) ) + IF( !( EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) ) { nchan_out_buff = s_max( nchan_out_buff, add( nchan_internal, st_ivas->nchan_ism ) ); } nchan_out_buff = s_min( nchan_out_buff, MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS ); } - ELSE IF ( EQ_32( st_ivas->ivas_format, MC_FORMAT ) ) + ELSE IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) ) { nchan_out_buff = st_ivas->hDecoderConfig->nchan_out; - IF ( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) + IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) { nchan_out_buff = s_max( nchan_out_buff, add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ) ); } @@ -648,18 +650,18 @@ Word16 ivas_get_nchan_buffers_dec( *-------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED ivas_error ivas_output_buff_dec_fx( - Word32 *p_output_f[], /* i/o: output audio buffers */ + Word32 *p_output_f[], /* i/o: output audio buffers */ const Word16 nchan_out_buff_old, /* i : previous frame number of output channels */ const Word16 nchan_out_buff /* i : number of output channels */ ) { Word16 ch; - IF ( GT_16(nchan_out_buff , nchan_out_buff_old) ) + IF( GT_16( nchan_out_buff, nchan_out_buff_old ) ) { - FOR ( ch = nchan_out_buff_old; ch < nchan_out_buff; ch++ ) + FOR( ch = nchan_out_buff_old; ch < nchan_out_buff; ch++ ) { /* note: these are intra-frame heap memories */ - IF ( ( p_output_f[ch] = (Word32 *) malloc( ( 48000 / FRAMES_PER_SEC ) * sizeof(Word32) ) ) == NULL ) /* note: 32000 == max internal sampling rate */ + IF( ( p_output_f[ch] = (Word32 *) malloc( ( 48000 / FRAMES_PER_SEC ) * sizeof( Word32 ) ) ) == NULL ) /* note: 32000 == max internal sampling rate */ { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for floating-point output audio buffer!\n" ) ); } @@ -667,7 +669,7 @@ ivas_error ivas_output_buff_dec_fx( } ELSE { - FOR ( ch = nchan_out_buff; ch < nchan_out_buff_old; ch++ ) + FOR( ch = nchan_out_buff; ch < nchan_out_buff_old; ch++ ) { free( p_output_f[ch] ); p_output_f[ch] = NULL; diff --git a/lib_rend/ivas_output_init_fx.c b/lib_rend/ivas_output_init_fx.c index 477b43002..708c93caf 100644 --- a/lib_rend/ivas_output_init_fx.c +++ b/lib_rend/ivas_output_init_fx.c @@ -64,7 +64,9 @@ Word16 ivas_get_nchan_buffers_dec_ivas_fx( nchan_out_buff = CPE_CHANNELS; move16(); - test(); test(); test(); + test(); + test(); + test(); IF( EQ_16( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) { nchan_out_buff = s_max( nchan_out_buff, add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ) ); diff --git a/lib_rend/ivas_reflections.c b/lib_rend/ivas_reflections.c index 1a33dabc7..ee5596104 100644 --- a/lib_rend/ivas_reflections.c +++ b/lib_rend/ivas_reflections.c @@ -164,7 +164,7 @@ ivas_error ivas_er_init( ivas_shoebox_init( &reflections->shoebox_lib, &reflections->shoebox_lib.cal ); /* Set mode */ - IF( NE_32 ( ( error = ivas_er_set_reflections_mode( reflections, inConfig ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_er_set_reflections_mode( reflections, inConfig ) ), IVAS_ERR_OK ) ) { return error; } @@ -216,7 +216,7 @@ ivas_error ivas_er_set_reflections_mode( UWord16 ch; error = IVAS_ERR_OK; - IF ( EQ_32( reflections->audio_config, inConfig ) ) + IF( EQ_32( reflections->audio_config, inConfig ) ) { return error; } @@ -225,7 +225,7 @@ ivas_error ivas_er_set_reflections_mode( move16(); reflections->audio_config = inConfig; - SWITCH ( reflections->audio_config ) + SWITCH( reflections->audio_config ) { case IVAS_AUDIO_CONFIG_MONO: reflections->shoebox_data.n_sources = 1; @@ -250,7 +250,7 @@ ivas_error ivas_er_set_reflections_mode( move16(); move16(); - FOR ( ch = 0; ch < reflections->shoebox_data.n_sources; ch++ ) + FOR( ch = 0; ch < reflections->shoebox_data.n_sources; ch++ ) { reflections->source_positions_fx[3 * ch] = ls_azimuth_CICP2_idx[ch]; reflections->source_positions_fx[1 + ( 3 * ch )] = ls_elevation_CICP2_idx[ch]; @@ -268,7 +268,7 @@ ivas_error ivas_er_set_reflections_mode( move16(); move16(); - FOR ( ch = 0; ch < reflections->shoebox_data.n_sources; ch++ ) + FOR( ch = 0; ch < reflections->shoebox_data.n_sources; ch++ ) { reflections->source_positions_fx[3 * ch] = ls_azimuth_CICP6_idx[ch]; reflections->source_positions_fx[1 + ( 3 * ch )] = ls_elevation_CICP6_idx[ch]; @@ -285,7 +285,7 @@ ivas_error ivas_er_set_reflections_mode( move16(); move16(); move16(); - FOR ( ch = 0; ch < reflections->shoebox_data.n_sources; ch++ ) + FOR( ch = 0; ch < reflections->shoebox_data.n_sources; ch++ ) { reflections->source_positions_fx[3 * ch] = ls_azimuth_CICP12_idx[ch]; reflections->source_positions_fx[1 + ( 3 * ch )] = ls_elevation_CICP12_idx[ch]; @@ -302,7 +302,7 @@ ivas_error ivas_er_set_reflections_mode( move16(); move16(); move16(); - FOR ( ch = 0; ch < reflections->shoebox_data.n_sources; ch++ ) + FOR( ch = 0; ch < reflections->shoebox_data.n_sources; ch++ ) { reflections->source_positions_fx[3 * ch] = ls_azimuth_CICP14_idx[ch]; reflections->source_positions_fx[1 + ( 3 * ch )] = ls_elevation_CICP14_idx[ch]; @@ -319,7 +319,7 @@ ivas_error ivas_er_set_reflections_mode( move16(); move16(); move16(); - FOR ( ch = 0; ch < reflections->shoebox_data.n_sources; ch++ ) + FOR( ch = 0; ch < reflections->shoebox_data.n_sources; ch++ ) { reflections->source_positions_fx[3 * ch] = ls_azimuth_CICP16_idx[ch]; reflections->source_positions_fx[1 + ( 3 * ch )] = ls_elevation_CICP16_idx[ch]; @@ -336,7 +336,7 @@ ivas_error ivas_er_set_reflections_mode( move16(); move16(); move16(); - FOR ( ch = 0; ch < reflections->shoebox_data.n_sources; ch++ ) + FOR( ch = 0; ch < reflections->shoebox_data.n_sources; ch++ ) { reflections->source_positions_fx[3 * ch] = ls_azimuth_CICP19_idx[ch]; reflections->source_positions_fx[1 + ( 3 * ch )] = ls_elevation_CICP19_idx[ch]; @@ -571,7 +571,6 @@ ivas_error ivas_er_encoder_init( move16(); - IF( reflections == NULL ) { return IVAS_ERR_FAILED_ALLOC; @@ -650,12 +649,12 @@ ivas_error ivas_er_encoder_init( tmp_fx = L_mac( tmp_fx, tmp16, tmp16 ); // Q.27 q_format = Q31 - Q27; dist_fx = Sqrt32( tmp_fx, &q_format ); - IF ( EQ_32( dist_fx, 0 ) ) + IF( EQ_32( dist_fx, 0 ) ) { q_format = 0; move16(); } - IF ( LE_16( q_format, 0 ) ) + IF( LE_16( q_format, 0 ) ) { dist_fx = L_shl( dist_fx, q_format ); // Q31 q_format = 0; @@ -673,11 +672,11 @@ ivas_error ivas_er_encoder_init( } ELSE { - IF ( LE_16( q_format, min_qformat ) ) + IF( LE_16( q_format, min_qformat ) ) { - IF ( EQ_16( q_format, min_qformat ) ) + IF( EQ_16( q_format, min_qformat ) ) { - IF ( LT_32( dist_fx, min_dist_fx ) ) + IF( LT_32( dist_fx, min_dist_fx ) ) { min_dist_fx = dist_fx; min_index_fx = j; @@ -728,7 +727,7 @@ ivas_error ivas_er_compute_reflections( move16(); /* Disabled case */ - IF ( EQ_32( reflections->audio_config, IVAS_AUDIO_CONFIG_INVALID ) ) + IF( EQ_32( reflections->audio_config, IVAS_AUDIO_CONFIG_INVALID ) ) { return error; } @@ -763,13 +762,13 @@ ivas_error ivas_er_compute_reflections( /* If size is different, reallocate circ buffers */ /* Otherwise allocate new circ buffers */ - FOR ( i = 0; i < 150; i++ ) + FOR( i = 0; i < 150; i++ ) { reflections->shoebox_data.gains.data_fx[i] = L_shl( reflections->shoebox_data.gains.data_fx[i], 9 ); } - IF ( reflections->circ_buffers ) + IF( reflections->circ_buffers ) { - IF ( reflections->circ_len == circ_len ) + IF( reflections->circ_len == circ_len ) { /* circ buffers exist and size is the same */ set32_fx( reflections->circ_buffers, 0, reflections->shoebox_data.n_sources * reflections->circ_len ); @@ -780,7 +779,7 @@ ivas_error ivas_er_compute_reflections( reflections->circ_len = circ_len; move16(); free( reflections->circ_buffers ); - IF ( ( reflections->circ_buffers = (Word32 *) malloc( reflections->shoebox_data.n_sources * reflections->circ_len * sizeof( Word32 ) ) ) == NULL ) + IF( ( reflections->circ_buffers = (Word32 *) malloc( reflections->shoebox_data.n_sources * reflections->circ_len * sizeof( Word32 ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Early Reflections buffers" ); } @@ -792,7 +791,7 @@ ivas_error ivas_er_compute_reflections( /* circ buffers do not exist */ reflections->circ_len = circ_len; move16(); - IF ( ( reflections->circ_buffers = (Word32 *) malloc( reflections->shoebox_data.n_sources * reflections->circ_len * sizeof( Word32 ) ) ) == NULL ) + IF( ( reflections->circ_buffers = (Word32 *) malloc( reflections->shoebox_data.n_sources * reflections->circ_len * sizeof( Word32 ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Early Reflections buffers" ); } @@ -806,7 +805,7 @@ ivas_error ivas_er_compute_reflections( reflections->n_total_reflections = reflections->shoebox_data.n_sources * reflections->shoebox_data.n_ref; /* Check that reflection buffers were allocated */ - IF ( NE_32( error, IVAS_ERR_OK ) ) + IF( NE_32( error, IVAS_ERR_OK ) ) { return error; } @@ -816,88 +815,88 @@ ivas_error ivas_er_compute_reflections( #else ivas_error ivas_er_compute_reflections( - er_struct_t *reflections) + er_struct_t *reflections ) { - ivas_error error = IVAS_ERR_OK; - uint16_t circ_len, i, j; - float tmp; + ivas_error error = IVAS_ERR_OK; + uint16_t circ_len, i, j; + float tmp; - reflections->is_ready = 0; + reflections->is_ready = 0; - /* Disabled case */ - if (reflections->audio_config == IVAS_AUDIO_CONFIG_INVALID) - { - return error; - } + /* Disabled case */ + if ( reflections->audio_config == IVAS_AUDIO_CONFIG_INVALID ) + { + return error; + } - /* Run shoebox with current reflection parameters */ - ivas_shoebox_set_scene(&(reflections->shoebox_lib), &(reflections->shoebox_data), reflections->shoebox_lib.cal.list_orig, - reflections->source_positions, reflections->is_cartesian, reflections->is_relative); + /* Run shoebox with current reflection parameters */ + ivas_shoebox_set_scene( &( reflections->shoebox_lib ), &( reflections->shoebox_data ), reflections->shoebox_lib.cal.list_orig, + reflections->source_positions, reflections->is_cartesian, reflections->is_relative ); - /* Convert reflection times in seconds to samples and keep track of max */ - circ_len = 0; - for (i = 0; i < reflections->shoebox_data.n_sources; i++) - { - for (j = 0; j < reflections->shoebox_data.n_ref; j++) + /* Convert reflection times in seconds to samples and keep track of max */ + circ_len = 0; + for ( i = 0; i < reflections->shoebox_data.n_sources; i++ ) { - tmp = reflections->shoebox_data.times.data[j + (i * reflections->shoebox_data.n_ref)]; - tmp = roundf(tmp * reflections->output_Fs); - reflections->shoebox_data.times.data[j + (i * reflections->shoebox_data.n_ref)] = tmp; - circ_len = ((uint16_t)tmp > circ_len) ? (uint16_t)tmp : circ_len; + for ( j = 0; j < reflections->shoebox_data.n_ref; j++ ) + { + tmp = reflections->shoebox_data.times.data[j + ( i * reflections->shoebox_data.n_ref )]; + tmp = roundf( tmp * reflections->output_Fs ); + reflections->shoebox_data.times.data[j + ( i * reflections->shoebox_data.n_ref )] = tmp; + circ_len = ( (uint16_t) tmp > circ_len ) ? (uint16_t) tmp : circ_len; + } } - } - - /* If max delay is less than max frame size, use max frame size to compute circ buffer length */ - circ_len = (circ_len > (uint16_t)reflections->max_frame_size) ? circ_len : (uint16_t)reflections->max_frame_size; - circ_len += (uint16_t)reflections->max_frame_size; - - /* If circ buffers exist and size is the same, reset memory to all zeros */ - /* If size is different, reallocate circ buffers */ - /* Otherwise allocate new circ buffers */ - if (reflections->circ_buffers) - { - if (reflections->circ_len == circ_len) + + /* If max delay is less than max frame size, use max frame size to compute circ buffer length */ + circ_len = ( circ_len > (uint16_t) reflections->max_frame_size ) ? circ_len : (uint16_t) reflections->max_frame_size; + circ_len += (uint16_t) reflections->max_frame_size; + + /* If circ buffers exist and size is the same, reset memory to all zeros */ + /* If size is different, reallocate circ buffers */ + /* Otherwise allocate new circ buffers */ + if ( reflections->circ_buffers ) { - /* circ buffers exist and size is the same */ - set_f(reflections->circ_buffers, 0.0f, reflections->shoebox_data.n_sources * reflections->circ_len); + if ( reflections->circ_len == circ_len ) + { + /* circ buffers exist and size is the same */ + set_f( reflections->circ_buffers, 0.0f, reflections->shoebox_data.n_sources * reflections->circ_len ); + } + else + { + /* circ buffers exist but size is different */ + reflections->circ_len = circ_len; + free( reflections->circ_buffers ); + if ( ( reflections->circ_buffers = (float *) malloc( reflections->shoebox_data.n_sources * reflections->circ_len * sizeof( float ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Early Reflections buffers" ); + } + set_f( reflections->circ_buffers, 0.0f, reflections->shoebox_data.n_sources * reflections->circ_len ); + } } else { - /* circ buffers exist but size is different */ - reflections->circ_len = circ_len; - free(reflections->circ_buffers); - if ((reflections->circ_buffers = (float *)malloc(reflections->shoebox_data.n_sources * reflections->circ_len * sizeof(float))) == NULL) - { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Early Reflections buffers"); - } - set_f(reflections->circ_buffers, 0.0f, reflections->shoebox_data.n_sources * reflections->circ_len); - } - } - else - { - /* circ buffers do not exist */ - reflections->circ_len = circ_len; - if ((reflections->circ_buffers = (float *)malloc(reflections->shoebox_data.n_sources * reflections->circ_len * sizeof(float))) == NULL) - { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Early Reflections buffers"); + /* circ buffers do not exist */ + reflections->circ_len = circ_len; + if ( ( reflections->circ_buffers = (float *) malloc( reflections->shoebox_data.n_sources * reflections->circ_len * sizeof( float ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Early Reflections buffers" ); + } + set_f( reflections->circ_buffers, 0.0f, reflections->shoebox_data.n_sources * reflections->circ_len ); } - set_f(reflections->circ_buffers, 0.0f, reflections->shoebox_data.n_sources * reflections->circ_len); - } - /* Initialize circular buffer insertion point */ - reflections->circ_insert = reflections->circ_len - (uint16_t)reflections->max_frame_size; + /* Initialize circular buffer insertion point */ + reflections->circ_insert = reflections->circ_len - (uint16_t) reflections->max_frame_size; - /* Get total reflections number */ - reflections->n_total_reflections = reflections->shoebox_data.n_sources * reflections->shoebox_data.n_ref; + /* Get total reflections number */ + reflections->n_total_reflections = reflections->shoebox_data.n_sources * reflections->shoebox_data.n_ref; - /* Check that reflection buffers were allocated */ - if (error != IVAS_ERR_OK) - { - return error; - } + /* Check that reflection buffers were allocated */ + if ( error != IVAS_ERR_OK ) + { + return error; + } - return error; + return error; } #endif @@ -928,19 +927,19 @@ ivas_error ivas_er_process( Word32 *buffer_ch; Word32 temp; - IF ( !reflections ) + IF( !reflections ) { return IVAS_ERR_INIT_ERROR; } /* should not arrive here if reflections are disabled but in case it does just do nothing */ - IF ( reflections->use_er != 1 ) + IF( reflections->use_er != 1 ) { return error; } /* Ensure all reflection memory is allocated */ - IF ( !reflections->circ_buffers || !reflections->is_ready ) + IF( !reflections->circ_buffers || !reflections->is_ready ) { return IVAS_ERR_INIT_ERROR; } @@ -950,7 +949,7 @@ ivas_error ivas_er_process( move16(); /* If low complexity ER are requested only compute ER for n_LC_sources */ - IF ( reflections->lowComplexity ) + IF( reflections->lowComplexity ) { n_ref_sources = reflections->n_LC_sources; move16(); @@ -962,10 +961,10 @@ ivas_error ivas_er_process( } /* Channel case, copy input into buffers panning for LC mode and skipping LFE */ - IF ( EQ_32( getAudioConfigType( inConfig ), IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED ) ) + IF( EQ_32( getAudioConfigType( inConfig ), IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED ) ) { /* Loop through all input sources filling circular buffers */ - FOR ( i = 0; i < reflections->shoebox_data.n_sources; i++ ) + FOR( i = 0; i < reflections->shoebox_data.n_sources; i++ ) { /* Pull correct circular buffer depending on complexity mode */ buf_ch_idx = ( reflections->lowComplexity == 1 ) ? reflections->LC_mixing[i] : i; @@ -976,9 +975,9 @@ ivas_error ivas_er_process( samp_idx = reflections->circ_insert; /* If less than number of reflection sources, overwrite buffer */ - IF ( i == buf_ch_idx ) + IF( i == buf_ch_idx ) { - FOR ( j = 0; j < subframe_size; j++ ) + FOR( j = 0; j < subframe_size; j++ ) { buffer_ch[samp_idx++] = io[in_ch_idx][j + subframe_offset]; samp_idx = samp_idx % reflections->circ_len; @@ -987,7 +986,7 @@ ivas_error ivas_er_process( /* Accumulate with buffer for low complexity mixed sources */ ELSE { - FOR ( j = 0; j < subframe_size; j++ ) + FOR( j = 0; j < subframe_size; j++ ) { buffer_ch[samp_idx] = L_add( io[in_ch_idx][j + subframe_offset], buffer_ch[samp_idx] ); samp_idx++; @@ -1002,13 +1001,13 @@ ivas_error ivas_er_process( } /* Loop through sources retrieve reflections from circ buffers */ - FOR ( i = 0; i < n_ref_sources; i++ ) + FOR( i = 0; i < n_ref_sources; i++ ) { /* Access correct row of input circ buffer */ buffer_ch = &( reflections->circ_buffers[i * reflections->circ_len] ); /* Loop through reflections */ - FOR ( j = 0; j < n_ref; j++ ) + FOR( j = 0; j < n_ref; j++ ) { ref_no = j + ( i * n_ref ); ref_gain = (Word32) reflections->shoebox_data.gains.data_fx[ref_no]; @@ -1018,13 +1017,13 @@ ivas_error ivas_er_process( /* Determine start idx of reflection in circ buffer based on current insert idx and reflection delay */ samp_idx = (Word16) reflections->circ_insert - ref_delay; - IF ( LT_16( samp_idx, 0 ) ) + IF( LT_16( samp_idx, 0 ) ) { samp_idx = add( (Word16) reflections->circ_len, samp_idx ); } /* Pull reflection from circ buffer and apply gain */ - FOR ( k = 0; k < subframe_size; k++ ) + FOR( k = 0; k < subframe_size; k++ ) { temp = Mpy_32_32( buffer_ch[samp_idx], ref_gain ); io[ref_out_idx][k + subframe_offset] = L_add( temp, io[ref_out_idx][k + subframe_offset] ); @@ -1169,4 +1168,4 @@ ivas_error ivas_er_process( return error; } -#endif \ No newline at end of file +#endif diff --git a/lib_rend/ivas_render_config.c b/lib_rend/ivas_render_config.c index eb451e6bb..30b00be59 100644 --- a/lib_rend/ivas_render_config.c +++ b/lib_rend/ivas_render_config.c @@ -43,9 +43,9 @@ * Local constants *-----------------------------------------------------------------------*/ -#define IVAS_REVERB_DEFAULT_PRE_DELAY 0.016f +#define IVAS_REVERB_DEFAULT_PRE_DELAY 0.016f #define IVAS_REVERB_DEFAULT_PRE_DELAY_FX 2147484 -#define IVAS_REVERB_DEFAULT_INPUT_DELAY 0.1f +#define IVAS_REVERB_DEFAULT_INPUT_DELAY 0.1f #define IVAS_REVERB_DEFAULT_INPUT_DELAY_FX 13421773 #define IVAS_REVERB_DEFAULT_USE_ER 0 @@ -197,4 +197,4 @@ ivas_error ivas_render_config_init_from_rom( } return IVAS_ERR_OK; -} \ No newline at end of file +} diff --git a/lib_rend/ivas_reverb.c b/lib_rend/ivas_reverb.c index adc92af83..3ee653b70 100644 --- a/lib_rend/ivas_reverb.c +++ b/lib_rend/ivas_reverb.c @@ -61,7 +61,7 @@ static Word16 wrap_rad_fixed( L_tmp = L_add( L_tmp, EVS_2PI_FX ); } - return extract_l(L_tmp); + return extract_l( L_tmp ); } #endif @@ -82,19 +82,19 @@ static Word16 wrap_rad_fixed( #define FFT_FILTER_WND_FLAT_REGION ( 0.40f ) /* flat section (==1) length of FFT filter window, in proportion to overlap */ #define FFT_FILTER_WND_TRANS_REGION ( 0.15f ) /* transition (1->0) length of FFT filter window, in proportion to overlap */ #ifdef IVAS_FLOAT_FIXED -#define FFT_FILTER_WND_FLAT_REGION_FX ( 26214 )/*Q16 flat section (==1) length of FFT filter window, in proportion to overlap */ -#define FFT_FILTER_WND_TRANS_REGION_FX ( 9830 ) /*Q16 transition (1->0) length of FFT filter window, in proportion to overlap */ -#endif // IVAS_FLOAT_FIXED -#define REF_LF_MIN ( 100.0f ) -#define REF_LF_MAX ( 250.0f ) -#define REF_HF_MIN ( 5000.0f ) -#define REF_HF_MAX ( 7950.0f ) - -#define REF_LF_MIN_FX ( 100 ) -#define REF_LF_MAX_FX ( 250 ) -#define REF_HF_MIN_FX ( 5000 ) -#define REF_HF_MAX_FX ( 7950 ) -#define LF_BIAS ( 0.5f ) +#define FFT_FILTER_WND_FLAT_REGION_FX ( 26214 ) /*Q16 flat section (==1) length of FFT filter window, in proportion to overlap */ +#define FFT_FILTER_WND_TRANS_REGION_FX ( 9830 ) /*Q16 transition (1->0) length of FFT filter window, in proportion to overlap */ +#endif // IVAS_FLOAT_FIXED +#define REF_LF_MIN ( 100.0f ) +#define REF_LF_MAX ( 250.0f ) +#define REF_HF_MIN ( 5000.0f ) +#define REF_HF_MAX ( 7950.0f ) + +#define REF_LF_MIN_FX ( 100 ) +#define REF_LF_MAX_FX ( 250 ) +#define REF_HF_MIN_FX ( 5000 ) +#define REF_HF_MAX_FX ( 7950 ) +#define LF_BIAS ( 0.5f ) #define DEFAULT_SRC_DIST ( 1.5f ) /* default source distance [m] for reverb dmx factor computing */ #ifdef IVAS_FLOAT_FIXED @@ -130,21 +130,21 @@ typedef struct ivas_reverb_params_t /* Currently this is fixed to 2. */ /* Mix [S][L] matrix from feedback loops to outputs. */ Word16 pLoop_extract_matrix_fx[MAX_NR_OUTPUTS * IVAS_REV_MAX_NR_BRANCHES]; /* Mix [S][L] matrix from feedback loops to outputs. */ /* In Matlab: [S x L] - Currently S=2, later may be more than 2 for speaker playback. */ Word16 t60_filter_order; /* Filter order (length of vector) */ - //float pT60_filter_coeff[MAX_NR_OUTPUTS * IVAS_REV_MAX_NR_BRANCHES * IVAS_REV_MAX_IIR_FILTER_LENGTH]; /* Filters [][] in feedback loops, controlling T60. */ + // float pT60_filter_coeff[MAX_NR_OUTPUTS * IVAS_REV_MAX_NR_BRANCHES * IVAS_REV_MAX_IIR_FILTER_LENGTH]; /* Filters [][] in feedback loops, controlling T60. */ #ifdef IVAS_FLOAT_FIXED Word16 pT60_filter_coeff_fx[MAX_NR_OUTPUTS * IVAS_REV_MAX_NR_BRANCHES * IVAS_REV_MAX_IIR_FILTER_LENGTH]; #endif - /* In Matlab: IIR: [(2 * L) x ( + 1)] (odd: b-vector, even: a-vector) */ - /* In Matlab: FIR: [L x ] */ - //float *pFc; /* Center frequencies for FFT filter design */ - //float *pRt60; /* RT60 values at these frequencies */ - //float *pDsr; /* DSR values at these frequencies */ + /* In Matlab: IIR: [(2 * L) x ( + 1)] (odd: b-vector, even: a-vector) */ + /* In Matlab: FIR: [L x ] */ + // float *pFc; /* Center frequencies for FFT filter design */ + // float *pRt60; /* RT60 values at these frequencies */ + // float *pDsr; /* DSR values at these frequencies */ #ifdef IVAS_FLOAT_FIXED - Word32 *pFc_fx; /* Center frequencies for FFT filter design */ - Word32 *pRt60_fx; /* RT60 values at these frequencies */ - Word16 *pRt60_e; /* exponents for RT60 values at these frequencies */ - Word32 *pDsr_fx; /* DSR values at these frequencies */ - Word16 *pDsr_e; /* DSR values at these frequencies */ + Word32 *pFc_fx; /* Center frequencies for FFT filter design */ + Word32 *pRt60_fx; /* RT60 values at these frequencies */ + Word16 *pRt60_e; /* exponents for RT60 values at these frequencies */ + Word32 *pDsr_fx; /* DSR values at these frequencies */ + Word16 *pDsr_e; /* DSR values at these frequencies */ #endif // float *pHrtf_avg_pwr_response_l; /* The HRTF set's average left ear power response */ // float *pHrtf_avg_pwr_response_r; /* The HRTF set's average right ear power response */ @@ -154,12 +154,12 @@ typedef struct ivas_reverb_params_t // const float *pHrtf_inter_aural_coherence_const; /* The HRTF set's inter-aural coherence for diffuse sound */ #ifdef IVAS_FLOAT_FIXED - Word32 *pHrtf_avg_pwr_response_l_fx; /* The HRTF set's average left ear power response */ - Word32 *pHrtf_avg_pwr_response_r_fx; /* The HRTF set's average right ear power response */ - Word32 *pHrtf_inter_aural_coherence_fx; /* The HRTF set's inter-aural coherence for diffuse sound */ - const Word32 *pHrtf_avg_pwr_response_l_const_fx; /* The HRTF set's average left ear power response */ - const Word32 *pHrtf_avg_pwr_response_r_const_fx; /* The HRTF set's average right ear power response */ - const Word32 *pHrtf_inter_aural_coherence_const_fx; /* The HRTF set's inter-aural coherence for diffuse sound */ + Word32 *pHrtf_avg_pwr_response_l_fx; /* The HRTF set's average left ear power response */ + Word32 *pHrtf_avg_pwr_response_r_fx; /* The HRTF set's average right ear power response */ + Word32 *pHrtf_inter_aural_coherence_fx; /* The HRTF set's inter-aural coherence for diffuse sound */ + const Word32 *pHrtf_avg_pwr_response_l_const_fx; /* The HRTF set's average left ear power response */ + const Word32 *pHrtf_avg_pwr_response_r_const_fx; /* The HRTF set's average right ear power response */ + const Word32 *pHrtf_inter_aural_coherence_const_fx; /* The HRTF set's inter-aural coherence for diffuse sound */ #endif Word16 do_corr_filter; /* Flag indicating whether correlation filters should be used. */ /* Correlation only supported and needed for binaural playback (i.e. */ @@ -205,7 +205,7 @@ typedef struct ivas_reverb_params_t #ifndef IVAS_FLOAT_FIXED static ivas_error calc_jot_t60_coeffs( float *pH_dB, const uint16_t nrFrequencies, float *pFrequencies, float *pCoeffA, float *pCoeffB, const float fNyquist ); #else -static ivas_error calc_jot_t60_coeffs_fx(Word16 *pH_dB_fx, Word16 pH_dB_exp, const UWord16 nrFrequencies, Word16 *pFrequencies_fx, Word16 *pCoeffA_fx, Word16 *pCoeffB_fx, const Word16 fNyquist_fx); +static ivas_error calc_jot_t60_coeffs_fx( Word16 *pH_dB_fx, Word16 pH_dB_exp, const UWord16 nrFrequencies, Word16 *pFrequencies_fx, Word16 *pCoeffA_fx, Word16 *pCoeffB_fx, const Word16 fNyquist_fx ); #endif /*------------------------------------------------------------------------- @@ -387,9 +387,9 @@ static void ivas_binaural_reverb_setReverbTimes( #ifdef IVAS_FLOAT_FIXED static void ivas_binaural_reverb_setReverbTimes_fx( REVERB_STRUCT_HANDLE hReverb, /* i/o: binaural reverb handle */ - const Word32 output_Fs, /* i : sampling_rate */ - const Word32 *revTimes_fx, /* i : reverberation times T60 for each CLDFB bin in seconds */ - const Word32 *revEnes_fx /* i : spectrum for reverberated sound at each CLDFB bin */ + const Word32 output_Fs, /* i : sampling_rate */ + const Word32 *revTimes_fx, /* i : reverberation times T60 for each CLDFB bin in seconds */ + const Word32 *revEnes_fx /* i : spectrum for reverberated sound at each CLDFB bin */ ) { Word16 bin, ch, tap, sample; @@ -405,48 +405,48 @@ static void ivas_binaural_reverb_setReverbTimes_fx( hReverb->highestBinauralCoherenceBin = 0; move16(); - FOR ( bin = 0; bin < hReverb->numBins; bin++ ) + FOR( bin = 0; bin < hReverb->numBins; bin++ ) { /* Determine the diffuse field binaural coherence */ Word16 exp; - tmp_exp = BASOP_Util_Add_MantExp(bin, 15, 1, 14, &tmp); - tmp = BASOP_Util_Divide3232_Scale(L_deposit_h(tmp), L_deposit_h(hReverb->numBins), &exp); - exp = add( exp, sub( tmp_exp, 15) ); - L_tmp = Mpy_32_16_1(output_Fs, tmp); - binCenterFreq_exp = add(31, exp); - binCenterFreq_fx = L_shr(L_tmp, 1); // divide by 2 - IF ( EQ_16( bin, 0 ) ) + tmp_exp = BASOP_Util_Add_MantExp( bin, 15, 1, 14, &tmp ); + tmp = BASOP_Util_Divide3232_Scale( L_deposit_h( tmp ), L_deposit_h( hReverb->numBins ), &exp ); + exp = add( exp, sub( tmp_exp, 15 ) ); + L_tmp = Mpy_32_16_1( output_Fs, tmp ); + binCenterFreq_exp = add( 31, exp ); + binCenterFreq_fx = L_shr( L_tmp, 1 ); // divide by 2 + IF( EQ_16( bin, 0 ) ) { diffuseFieldICC_fx = 1073741824; // 2 ^ 30, Q30 move32(); diffuseFieldICC_exp = 1; move16(); } - ELSE IF ( BASOP_Util_Cmp_Mant32Exp(binCenterFreq_fx, binCenterFreq_exp, 2700, 31 ) == -1) + ELSE IF( BASOP_Util_Cmp_Mant32Exp( binCenterFreq_fx, binCenterFreq_exp, 2700, 31 ) == -1 ) { - tmp = BASOP_Util_Divide3232_Scale(binCenterFreq_fx, 550, &scale); + tmp = BASOP_Util_Divide3232_Scale( binCenterFreq_fx, 550, &scale ); exp = add( scale, sub( binCenterFreq_exp, 31 ) ); - tmp = add(mult(EVS_PI_FX, tmp), EPSILLON_FX); // to avoid divide by 0 issue + tmp = add( mult( EVS_PI_FX, tmp ), EPSILLON_FX ); // to avoid divide by 0 issue tmp_exp = add( exp, 2 ); - sine_inp = wrap_rad_fixed(L_shl(tmp, sub( tmp_exp, 2))); + sine_inp = wrap_rad_fixed( L_shl( tmp, sub( tmp_exp, 2 ) ) ); - sine = getSinWord16(sine_inp); // Q15 - div1 = BASOP_Util_Divide1616_Scale(sine, tmp, &scale); - div_exp1 = add( scale, sub( 0, tmp_exp)); + sine = getSinWord16( sine_inp ); // Q15 + div1 = BASOP_Util_Divide1616_Scale( sine, tmp, &scale ); + div_exp1 = add( scale, sub( 0, tmp_exp ) ); - tmp = BASOP_Util_Divide3232_Scale(binCenterFreq_fx, 2700, &scale); - scale = add(scale, sub(binCenterFreq_exp, 31)); + tmp = BASOP_Util_Divide3232_Scale( binCenterFreq_fx, 2700, &scale ); + scale = add( scale, sub( binCenterFreq_exp, 31 ) ); - L_tmp = L_sub(L_shl(1, sub(15, scale)), tmp); - norm = norm_l(L_tmp); + L_tmp = L_sub( L_shl( 1, sub( 15, scale ) ), tmp ); + norm = norm_l( L_tmp ); - L_tmp = L_shl(L_tmp, norm); - sub_res = extract_h(L_tmp); - sub_exp = sub(scale, sub(norm, 16)); + L_tmp = L_shl( L_tmp, norm ); + sub_res = extract_h( L_tmp ); + sub_exp = sub( scale, sub( norm, 16 ) ); - diffuseFieldICC_fx = L_deposit_h(mult(sub_res, div1)); - diffuseFieldICC_exp = add(div_exp1, sub_exp); + diffuseFieldICC_fx = L_deposit_h( mult( sub_res, div1 ) ); + diffuseFieldICC_exp = add( div_exp1, sub_exp ); hReverb->highestBinauralCoherenceBin = bin; move16(); @@ -463,45 +463,45 @@ static void ivas_binaural_reverb_setReverbTimes_fx( /* Mixing gains to generate a diffuse-binaural sound based on incoherent sound */ L_tmp = Mpy_32_32( diffuseFieldICC_fx, diffuseFieldICC_fx ); // square - L_tmp = BASOP_Util_Add_Mant32Exp(1073741824, 1, L_negate(L_tmp), diffuseFieldICC_exp + diffuseFieldICC_exp, &scale); - L_tmp = Sqrt32(L_tmp, &scale); - tmpVal_fx = L_shr( BASOP_Util_Add_Mant32Exp(1073741824, 1, L_negate(L_tmp), scale, &tmpVal_exp), 1 ); + L_tmp = BASOP_Util_Add_Mant32Exp( 1073741824, 1, L_negate( L_tmp ), diffuseFieldICC_exp + diffuseFieldICC_exp, &scale ); + L_tmp = Sqrt32( L_tmp, &scale ); + tmpVal_fx = L_shr( BASOP_Util_Add_Mant32Exp( 1073741824, 1, L_negate( L_tmp ), scale, &tmpVal_exp ), 1 ); - IF ( BASOP_Util_Cmp_Mant32Exp(diffuseFieldICC_fx, diffuseFieldICC_exp, 0, 0 ) == 1 ) + IF( BASOP_Util_Cmp_Mant32Exp( diffuseFieldICC_fx, diffuseFieldICC_exp, 0, 0 ) == 1 ) { exp = tmpVal_exp; - L_tmp = Sqrt32( L_abs( tmpVal_fx ), &exp); - hReverb->binauralCoherenceCrossmixGains_fx[bin] = L_shl(L_tmp, exp); // Q31 + L_tmp = Sqrt32( L_abs( tmpVal_fx ), &exp ); + hReverb->binauralCoherenceCrossmixGains_fx[bin] = L_shl( L_tmp, exp ); // Q31 } ELSE { exp = tmpVal_exp; - L_tmp = Sqrt32(L_abs(tmpVal_fx), &exp); - hReverb->binauralCoherenceCrossmixGains_fx[bin] = L_negate(L_shl(L_tmp, exp)); // Q31 + L_tmp = Sqrt32( L_abs( tmpVal_fx ), &exp ); + hReverb->binauralCoherenceCrossmixGains_fx[bin] = L_negate( L_shl( L_tmp, exp ) ); // Q31 } exp = tmpVal_exp; - L_tmp = BASOP_Util_Add_Mant32Exp(1073741824, 1, L_negate(L_abs(tmpVal_fx)), tmpVal_exp, &exp); - L_tmp = Sqrt32(L_abs(L_tmp), &exp); - hReverb->binauralCoherenceDirectGains_fx[bin] = L_shl(L_tmp, exp); //making as Q31 + L_tmp = BASOP_Util_Add_Mant32Exp( 1073741824, 1, L_negate( L_abs( tmpVal_fx ) ), tmpVal_exp, &exp ); + L_tmp = Sqrt32( L_abs( L_tmp ), &exp ); + hReverb->binauralCoherenceDirectGains_fx[bin] = L_shl( L_tmp, exp ); // making as Q31 /* Determine attenuation factor that generates the appropriate energy decay according to reverberation time */ - L_tmp = Mpy_32_32(1677721600, revTimes_fx[bin]); // e10 --> 800 * 2^21, + e0 - tmp = BASOP_Util_Divide3232_Scale(1073741824, L_tmp, &scale); - scale = add(scale, sub( 1, 10 )); - L_tmp = Mpy_32_16_1(-1610612736, tmp); // * -3 + L_tmp = Mpy_32_32( 1677721600, revTimes_fx[bin] ); // e10 --> 800 * 2^21, + e0 + tmp = BASOP_Util_Divide3232_Scale( 1073741824, L_tmp, &scale ); + scale = add( scale, sub( 1, 10 ) ); + L_tmp = Mpy_32_16_1( -1610612736, tmp ); // * -3 scale = add( 2, scale ); - L_tmp = Mpy_32_32(1783446563, L_tmp); // scale + 2 - attenuationFactorPerSample_fx = BASOP_util_Pow2(L_tmp, scale + 2, &attenuationFactorPerSample_exp ); + L_tmp = Mpy_32_32( 1783446563, L_tmp ); // scale + 2 + attenuationFactorPerSample_fx = BASOP_util_Pow2( L_tmp, scale + 2, &attenuationFactorPerSample_exp ); Word32 tmp_mul; - scale = norm_l(hReverb->loopBufLength[bin]); - tmp_mul = L_shl(hReverb->loopBufLength[bin], scale); + scale = norm_l( hReverb->loopBufLength[bin] ); + tmp_mul = L_shl( hReverb->loopBufLength[bin], scale ); L_tmp = BASOP_Util_Log2( attenuationFactorPerSample_fx ); - L_tmp = L_add(L_tmp, L_shl( (Word32)attenuationFactorPerSample_exp, 25)); - L_tmp = Mpy_32_32(L_tmp, tmp_mul); - hReverb->loopAttenuationFactor_fx[bin] = BASOP_util_Pow2(L_tmp, 6 + 31 - scale, &exp); - hReverb->loopAttenuationFactor_fx[bin] = L_shl(hReverb->loopAttenuationFactor_fx[bin], exp); // making as Q31 + L_tmp = L_add( L_tmp, L_shl( (Word32) attenuationFactorPerSample_exp, 25 ) ); + L_tmp = Mpy_32_32( L_tmp, tmp_mul ); + hReverb->loopAttenuationFactor_fx[bin] = BASOP_util_Pow2( L_tmp, 6 + 31 - scale, &exp ); + hReverb->loopAttenuationFactor_fx[bin] = L_shl( hReverb->loopAttenuationFactor_fx[bin], exp ); // making as Q31 attenuationFactorPerSampleSq_fx = Mpy_32_32( attenuationFactorPerSample_fx, attenuationFactorPerSample_fx ); attenuationFactorPerSampleSq_exp = attenuationFactorPerSample_exp + attenuationFactorPerSample_exp; @@ -518,7 +518,7 @@ static void ivas_binaural_reverb_setReverbTimes_fx( actualizedEnergy_exp = 0; move16(); - FOR ( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) + FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { energyBuildup_fx = 0; @@ -533,40 +533,40 @@ static void ivas_binaural_reverb_setReverbTimes_fx( tap = 0; move16(); - FOR ( sample = 0; sample < hReverb->loopBufLength[bin]; sample++ ) + FOR( sample = 0; sample < hReverb->loopBufLength[bin]; sample++ ) { intendedEnergy_fx = BASOP_Util_Add_Mant32Exp( intendedEnergy_fx, intendedEnergy_exp, currentEnergy_fx, currentEnergy_exp, &intendedEnergy_exp ); /* The randomization at the energy build up affects where the sparse taps are located */ - UWord16 ret_binRend = binRend_rand(hReverb); + UWord16 ret_binRend = binRend_rand( hReverb ); - tmp = BASOP_Util_Divide3232_Scale(ret_binRend, PCM16_TO_FLT_FAC_FX, &tmp_exp); - L_tmp = BASOP_Util_Add_Mant32Exp(L_deposit_h(tmp), tmp_exp, L_negate(1073741824), 0, &exp); - L_tmp = Mpy_32_32(L_tmp, 214748364); // exp + 0 - L_tmp = BASOP_Util_Add_Mant32Exp(L_tmp, exp, currentEnergy_fx, currentEnergy_exp, &exp); - energyBuildup_fx = BASOP_Util_Add_Mant32Exp(energyBuildup_fx, energyBuildup_exp, L_tmp, exp, &energyBuildup_exp); - IF(BASOP_Util_Cmp_Mant32Exp(energyBuildup_fx, energyBuildup_exp, 0, 0) >= 0) /* A new filter tap is added at this condition */ + tmp = BASOP_Util_Divide3232_Scale( ret_binRend, PCM16_TO_FLT_FAC_FX, &tmp_exp ); + L_tmp = BASOP_Util_Add_Mant32Exp( L_deposit_h( tmp ), tmp_exp, L_negate( 1073741824 ), 0, &exp ); + L_tmp = Mpy_32_32( L_tmp, 214748364 ); // exp + 0 + L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, exp, currentEnergy_fx, currentEnergy_exp, &exp ); + energyBuildup_fx = BASOP_Util_Add_Mant32Exp( energyBuildup_fx, energyBuildup_exp, L_tmp, exp, &energyBuildup_exp ); + IF( BASOP_Util_Cmp_Mant32Exp( energyBuildup_fx, energyBuildup_exp, 0, 0 ) >= 0 ) /* A new filter tap is added at this condition */ { - IF(BASOP_Util_Cmp_Mant32Exp(energyBuildup_fx, energyBuildup_exp, 1, 31) >= 0) { + IF( BASOP_Util_Cmp_Mant32Exp( energyBuildup_fx, energyBuildup_exp, 1, 31 ) >= 0 ) + { /* Four efficient phase operations: n*pi/2, n=0,1,2,3 */ - hReverb->tapPhaseShiftType[bin][ch][tap] = (Word16)(binRend_rand(hReverb) % 4); + hReverb->tapPhaseShiftType[bin][ch][tap] = (Word16) ( binRend_rand( hReverb ) % 4 ); /* Set the tapPointer to point to the determined sample at the loop buffer */ - hReverb->tapPointersReal_fx[bin][ch][tap] = &(hReverb->loopBufReal_fx[bin][sample]); - hReverb->tapPointersImag_fx[bin][ch][tap] = &(hReverb->loopBufImag_fx[bin][sample]); + hReverb->tapPointersReal_fx[bin][ch][tap] = &( hReverb->loopBufReal_fx[bin][sample] ); + hReverb->tapPointersImag_fx[bin][ch][tap] = &( hReverb->loopBufImag_fx[bin][sample] ); - energyBuildup_fx = BASOP_Util_Add_Mant32Exp(energyBuildup_fx, energyBuildup_exp, L_negate(1073741824), 1, &energyBuildup_exp); /* A tap is added, thus remove its energy from the buildup */ + energyBuildup_fx = BASOP_Util_Add_Mant32Exp( energyBuildup_fx, energyBuildup_exp, L_negate( 1073741824 ), 1, &energyBuildup_exp ); /* A tap is added, thus remove its energy from the buildup */ - tap = add( tap, 1); + tap = add( tap, 1 ); - actualizedEnergy_fx = BASOP_Util_Add_Mant32Exp(actualizedEnergy_fx, actualizedEnergy_exp, 1073741824, 1, &actualizedEnergy_exp); + actualizedEnergy_fx = BASOP_Util_Add_Mant32Exp( actualizedEnergy_fx, actualizedEnergy_exp, 1073741824, 1, &actualizedEnergy_exp ); } } - currentEnergy_fx = BASOP_Util_Add_Mant32Exp(currentEnergy_fx, currentEnergy_exp, 0, 0, ¤tEnergy_exp); - currentEnergy_fx = Mpy_32_32(currentEnergy_fx, attenuationFactorPerSampleSq_fx ); + currentEnergy_fx = BASOP_Util_Add_Mant32Exp( currentEnergy_fx, currentEnergy_exp, 0, 0, ¤tEnergy_exp ); + currentEnergy_fx = Mpy_32_32( currentEnergy_fx, attenuationFactorPerSampleSq_fx ); currentEnergy_exp = currentEnergy_exp + attenuationFactorPerSampleSq_exp; - } hReverb->taps[bin][ch] = tap; /* Number of taps determined at the above random procedure */ move16(); @@ -575,23 +575,23 @@ static void ivas_binaural_reverb_setReverbTimes_fx( /* The decorrelator design and IIR attenuation rate affects the energy of reverb, which is compensated here */ reverb_exp = 0; move16(); - hReverb->reverbEqGains_fx[bin] = Sqrt32(revEnes_fx[bin], &reverb_exp); /* Determined reverb spectrum */ - hReverb->reverbEqGains_fx[bin] = BASOP_Util_Add_Mant32Exp(hReverb->reverbEqGains_fx[bin], reverb_exp, 0, 0, &reverb_exp); - - tmp = BASOP_Util_Divide3232_Scale(intendedEnergy_fx, actualizedEnergy_fx, &tmp_exp); - tmp_exp = add(tmp_exp, sub(intendedEnergy_exp, actualizedEnergy_exp)); - hReverb->reverbEqGains_fx[bin] = BASOP_Util_Add_Mant32Exp(hReverb->reverbEqGains_fx[bin], reverb_exp, 0, 0, &reverb_exp); - L_tmp = Sqrt32(L_deposit_h(tmp), &tmp_exp); - hReverb->reverbEqGains_fx[bin] = Mpy_32_32(hReverb->reverbEqGains_fx[bin], L_tmp); - reverb_exp = add(reverb_exp, tmp_exp); - - L_tmp = BASOP_Util_Add_Mant32Exp(1073741824, 1, L_negate(attenuationFactorPerSampleSq_fx), attenuationFactorPerSampleSq_exp, &tmp_exp); - L_tmp = Mpy_32_32(L_tmp, 1073741824); // tmp_exp + 1 - tmp_exp = add(tmp_exp, 0); - L_tmp = Sqrt32(L_tmp, &tmp_exp); - hReverb->reverbEqGains_fx[bin] = Mpy_32_32(L_tmp, hReverb->reverbEqGains_fx[bin]); + hReverb->reverbEqGains_fx[bin] = Sqrt32( revEnes_fx[bin], &reverb_exp ); /* Determined reverb spectrum */ + hReverb->reverbEqGains_fx[bin] = BASOP_Util_Add_Mant32Exp( hReverb->reverbEqGains_fx[bin], reverb_exp, 0, 0, &reverb_exp ); + + tmp = BASOP_Util_Divide3232_Scale( intendedEnergy_fx, actualizedEnergy_fx, &tmp_exp ); + tmp_exp = add( tmp_exp, sub( intendedEnergy_exp, actualizedEnergy_exp ) ); + hReverb->reverbEqGains_fx[bin] = BASOP_Util_Add_Mant32Exp( hReverb->reverbEqGains_fx[bin], reverb_exp, 0, 0, &reverb_exp ); + L_tmp = Sqrt32( L_deposit_h( tmp ), &tmp_exp ); + hReverb->reverbEqGains_fx[bin] = Mpy_32_32( hReverb->reverbEqGains_fx[bin], L_tmp ); reverb_exp = add( reverb_exp, tmp_exp ); - hReverb->reverbEqGains_fx[bin] = L_shl(hReverb->reverbEqGains_fx[bin], reverb_exp); // making as Q31 + + L_tmp = BASOP_Util_Add_Mant32Exp( 1073741824, 1, L_negate( attenuationFactorPerSampleSq_fx ), attenuationFactorPerSampleSq_exp, &tmp_exp ); + L_tmp = Mpy_32_32( L_tmp, 1073741824 ); // tmp_exp + 1 + tmp_exp = add( tmp_exp, 0 ); + L_tmp = Sqrt32( L_tmp, &tmp_exp ); + hReverb->reverbEqGains_fx[bin] = Mpy_32_32( L_tmp, hReverb->reverbEqGains_fx[bin] ); + reverb_exp = add( reverb_exp, tmp_exp ); + hReverb->reverbEqGains_fx[bin] = L_shl( hReverb->reverbEqGains_fx[bin], reverb_exp ); // making as Q31 } return; } @@ -657,7 +657,7 @@ static void compute_2_out_extract_matrix_fx( move16(); pExtractMatrix[i + n] = ff; move16(); - ff = negate(ff); + ff = negate( ff ); } return; @@ -943,13 +943,13 @@ static void calc_predelay_fx( move16(); predelay = sub( predelay, fbdelay ); - IF ( LT_16(predelay , 0) ) + IF( LT_16( predelay, 0 ) ) { predelay = 0; move16(); } - IF ( LT_16(output_frame , predelay) ) + IF( LT_16( output_frame, predelay ) ) { predelay = output_frame; move16(); @@ -1005,7 +1005,7 @@ static ivas_error compute_t60_coeffs_fx( ivas_error error; Word16 loop_delay_sec_fx, norm_f_e, tmp; - Word32 freq_Nyquist_fx = L_shr(output_Fs, 1); + Word32 freq_Nyquist_fx = L_shr( output_Fs, 1 ); Word16 target_gains_db_fx[RV_LENGTH_NR_FC]; Word16 norm_f_fx[RV_LENGTH_NR_FC]; Word32 *targetT60_fx, *pFc_fx; @@ -1021,28 +1021,29 @@ static ivas_error compute_t60_coeffs_fx( targetT60_e = pParams->pRt60_e; move16(); - FOR (bin_idx = 0; bin_idx < tf_T60_len; bin_idx++) + FOR( bin_idx = 0; bin_idx < tf_T60_len; bin_idx++ ) { - norm_f_fx[bin_idx] = BASOP_Util_Divide3232_Scale(pFc_fx[bin_idx], freq_Nyquist_fx, &norm_f_e); + norm_f_fx[bin_idx] = BASOP_Util_Divide3232_Scale( pFc_fx[bin_idx], freq_Nyquist_fx, &norm_f_e ); norm_f_e = add( norm_f_e, sub( 17, 31 ) ); - norm_f_fx[bin_idx] = shl(norm_f_fx[bin_idx], sub( norm_f_e, 1) ); // making Q14 + norm_f_fx[bin_idx] = shl( norm_f_fx[bin_idx], sub( norm_f_e, 1 ) ); // making Q14 } - FOR ( loop_idx = 0; loop_idx < pParams->nr_loops; loop_idx++ ) + FOR( loop_idx = 0; loop_idx < pParams->nr_loops; loop_idx++ ) { Word16 loop_delay_sec_fx_exp; - loop_delay_sec_fx = BASOP_Util_Divide3232_Scale( pParams->pLoop_delays[loop_idx], output_Fs, &loop_delay_sec_fx_exp); + loop_delay_sec_fx = BASOP_Util_Divide3232_Scale( pParams->pLoop_delays[loop_idx], output_Fs, &loop_delay_sec_fx_exp ); - FOR ( bin_idx = 0; bin_idx < tf_T60_len; bin_idx++ ) + FOR( bin_idx = 0; bin_idx < tf_T60_len; bin_idx++ ) { - tmp = BASOP_Util_Divide3232_Scale(L_deposit_h(loop_delay_sec_fx), targetT60_fx[bin_idx], &target_gains_db_exp[bin_idx]); - target_gains_db_exp[bin_idx] = target_gains_db_exp[bin_idx] + (loop_delay_sec_fx_exp - targetT60_e[bin_idx]); - target_gains_db_fx[bin_idx] = mult( -30720, tmp ); // -60 in Q9 -> -30720 + tmp = BASOP_Util_Divide3232_Scale( L_deposit_h( loop_delay_sec_fx ), targetT60_fx[bin_idx], &target_gains_db_exp[bin_idx] ); + target_gains_db_exp[bin_idx] = target_gains_db_exp[bin_idx] + ( loop_delay_sec_fx_exp - targetT60_e[bin_idx] ); + target_gains_db_fx[bin_idx] = mult( -30720, tmp ); // -60 in Q9 -> -30720 target_gains_db_exp[bin_idx] = add( target_gains_db_exp[bin_idx], 6 ); // Q9 -> e6 - tmp = BASOP_Util_Cmp_Mant32Exp( L_deposit_h(target_gains_db_fx[bin_idx]), target_gains_db_exp[bin_idx], -2013265920, 7); - IF (tmp < 0) { + tmp = BASOP_Util_Cmp_Mant32Exp( L_deposit_h( target_gains_db_fx[bin_idx] ), target_gains_db_exp[bin_idx], -2013265920, 7 ); + IF( tmp < 0 ) + { target_gains_db_fx[bin_idx] = -30720; move16(); target_gains_db_exp[bin_idx] = 7; @@ -1055,23 +1056,25 @@ static ivas_error compute_t60_coeffs_fx( Word16 val = target_gains_db_exp[0]; move16(); - - FOR (Word16 i = 1; i < nr_fc_fft_filter; i++) { - val = s_max(val, target_gains_db_exp[i]); + + FOR( Word16 i = 1; i < nr_fc_fft_filter; i++ ) + { + val = s_max( val, target_gains_db_exp[i] ); } - FOR ( Word16 i = 0; i < nr_fc_fft_filter; i++) { - target_gains_db_fx[i] = shr(target_gains_db_fx[i], sub(val, target_gains_db_exp[i])); + FOR( Word16 i = 0; i < nr_fc_fft_filter; i++ ) + { + target_gains_db_fx[i] = shr( target_gains_db_fx[i], sub( val, target_gains_db_exp[i] ) ); } - IF ( ( error = calc_jot_t60_coeffs_fx(target_gains_db_fx, val, tf_T60_len, norm_f_fx, pCoeffs_a_fx, pCoeffs_b_fx, extract_l(freq_Nyquist_fx )) ) != IVAS_ERR_OK ) + IF( ( error = calc_jot_t60_coeffs_fx( target_gains_db_fx, val, tf_T60_len, norm_f_fx, pCoeffs_a_fx, pCoeffs_b_fx, extract_l( freq_Nyquist_fx ) ) ) != IVAS_ERR_OK ) { return error; } } len = shr( ( add( pParams->t60_filter_order, 1 ) ), 1 ); /* == floor( (order+1) / 2) */ - FOR ( loop_idx = 0; loop_idx < pParams->nr_loops; loop_idx++ ) + FOR( loop_idx = 0; loop_idx < pParams->nr_loops; loop_idx++ ) { pParams->pLoop_delays[loop_idx] = sub( pParams->pLoop_delays[loop_idx], len ); } @@ -1192,105 +1195,105 @@ static void calc_low_shelf_first_order_filter_fx( Word32 L_tmp; tmp = mult( EVS_PI_BY_2_FX, f0 ); - sine_val = getSinWord16(shl(tmp, 1)); // Q15 + sine_val = getSinWord16( shl( tmp, 1 ) ); // Q15 - tmp = mult(EVS_PI_BY_2_FX, f0); - cos_val = getCosWord16(shl(tmp, 1)); // Q14 + tmp = mult( EVS_PI_BY_2_FX, f0 ); + cos_val = getCosWord16( shl( tmp, 1 ) ); // Q14 - tan_val = BASOP_Util_Divide1616_Scale(sine_val, cos_val, &tan_exp); - tan_exp = add( tan_exp, sub(0, 1) ); + tan_val = BASOP_Util_Divide1616_Scale( sine_val, cos_val, &tan_exp ); + tan_exp = add( tan_exp, sub( 0, 1 ) ); Word16 gain_fx; - gain_fx = BASOP_Util_Divide1616_Scale(lin_gain_lf, lin_gain_hf, &gain_exp); + gain_fx = BASOP_Util_Divide1616_Scale( lin_gain_lf, lin_gain_hf, &gain_exp ); IF( LT_16( gain_fx, 16384 ) ) { - tmp = mult(tan_val, gain_fx); + tmp = mult( tan_val, gain_fx ); norm_num0 = add( tan_exp, gain_exp ); - L_tmp = L_add(L_shl(1, sub( 15, norm_num0) ), tmp); - shift = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, shift); - tmp = extract_h(L_tmp); + L_tmp = L_add( L_shl( 1, sub( 15, norm_num0 ) ), tmp ); + shift = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, shift ); + tmp = extract_h( L_tmp ); pNum[0] = tmp; move16(); - norm_num0 = sub( norm_num0, sub(shift, 16) ); + norm_num0 = sub( norm_num0, sub( shift, 16 ) ); - tmp = mult(tan_val, gain_fx); + tmp = mult( tan_val, gain_fx ); norm_num1 = add( tan_exp, gain_exp ); - L_tmp = L_sub(tmp, L_shl(1, sub(15, norm_num1))); - shift = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, shift); - tmp = extract_h(L_tmp); + L_tmp = L_sub( tmp, L_shl( 1, sub( 15, norm_num1 ) ) ); + shift = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, shift ); + tmp = extract_h( L_tmp ); pNum[1] = tmp; move16(); - norm_num1 = sub( norm_num1, sub(shift, 16) ); + norm_num1 = sub( norm_num1, sub( shift, 16 ) ); - L_tmp = L_add(L_shl(1, sub( 15, tan_exp) ), tan_val); - shift = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, shift); - tmp = extract_h(L_tmp); + L_tmp = L_add( L_shl( 1, sub( 15, tan_exp ) ), tan_val ); + shift = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, shift ); + tmp = extract_h( L_tmp ); pDen[0] = tmp; move16(); - norm_den0 = sub( tan_exp, sub(shift, 16 ) ); + norm_den0 = sub( tan_exp, sub( shift, 16 ) ); - L_tmp = L_sub(tan_val, L_shl(1, sub( 15, tan_exp ) ) ); - shift = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, shift); - tmp = extract_h(L_tmp); + L_tmp = L_sub( tan_val, L_shl( 1, sub( 15, tan_exp ) ) ); + shift = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, shift ); + tmp = extract_h( L_tmp ); pDen[1] = tmp; move16(); - norm_den1 = sub(tan_exp, sub(shift, 16)); + norm_den1 = sub( tan_exp, sub( shift, 16 ) ); } ELSE { - L_tmp = L_add( L_shl(1, (sub( 15, tan_exp ) ) ), tan_val ); - shift = norm_l(L_tmp); + L_tmp = L_add( L_shl( 1, ( sub( 15, tan_exp ) ) ), tan_val ); + shift = norm_l( L_tmp ); L_tmp = L_shl( L_tmp, shift ); - tmp = extract_h(L_tmp); + tmp = extract_h( L_tmp ); pNum[0] = tmp; - norm_num0 = sub( tan_exp, sub( shift, 16) ); + norm_num0 = sub( tan_exp, sub( shift, 16 ) ); - L_tmp = L_sub( tan_val, L_shl(1, (sub( 15, tan_exp ) ) ) ); - shift = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, shift); - tmp = extract_h(L_tmp); + L_tmp = L_sub( tan_val, L_shl( 1, ( sub( 15, tan_exp ) ) ) ); + shift = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, shift ); + tmp = extract_h( L_tmp ); pNum[1] = tmp; - norm_num1 = sub(tan_exp, sub(shift, 16)); - - tmp = BASOP_Util_Divide1616_Scale(tan_val, gain_fx, &exp); - exp = add( exp, sub(tan_exp, gain_exp) ); - L_tmp = L_add( L_shl(1, sub(15, exp)), tmp ); - shift = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, shift); - tmp = extract_h(L_tmp); + norm_num1 = sub( tan_exp, sub( shift, 16 ) ); + + tmp = BASOP_Util_Divide1616_Scale( tan_val, gain_fx, &exp ); + exp = add( exp, sub( tan_exp, gain_exp ) ); + L_tmp = L_add( L_shl( 1, sub( 15, exp ) ), tmp ); + shift = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, shift ); + tmp = extract_h( L_tmp ); pDen[0] = tmp; - norm_den0 = sub(exp, sub(shift, 16 )) ; - - tmp = BASOP_Util_Divide1616_Scale(tan_val, gain_fx, &exp); - exp = add( exp, sub(tan_exp, gain_exp)); - L_tmp = L_sub( tmp, 1 * L_shl(1, sub(15, exp)) ); - shift = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, shift); - tmp = extract_h(L_tmp); + norm_den0 = sub( exp, sub( shift, 16 ) ); + + tmp = BASOP_Util_Divide1616_Scale( tan_val, gain_fx, &exp ); + exp = add( exp, sub( tan_exp, gain_exp ) ); + L_tmp = L_sub( tmp, 1 * L_shl( 1, sub( 15, exp ) ) ); + shift = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, shift ); + tmp = extract_h( L_tmp ); pDen[1] = tmp; - norm_den1 = sub(exp, sub(shift, 16)); + norm_den1 = sub( exp, sub( shift, 16 ) ); } /* Normalize and adjust gain to match target amplitudes */ - pNum[0] = mult(BASOP_Util_Divide1616_Scale(pNum[0], pDen[0], &exp), lin_gain_hf); - norm_num0 = add( exp, sub(norm_num0, norm_den0) ); + pNum[0] = mult( BASOP_Util_Divide1616_Scale( pNum[0], pDen[0], &exp ), lin_gain_hf ); + norm_num0 = add( exp, sub( norm_num0, norm_den0 ) ); - pNum[1] = mult(BASOP_Util_Divide1616_Scale(pNum[1], pDen[0], &exp), lin_gain_hf); - norm_num1 = add( exp, sub(norm_num1, norm_den0) ); + pNum[1] = mult( BASOP_Util_Divide1616_Scale( pNum[1], pDen[0], &exp ), lin_gain_hf ); + norm_num1 = add( exp, sub( norm_num1, norm_den0 ) ); - pDen[1] = BASOP_Util_Divide1616_Scale(pDen[1], pDen[0], &exp); - norm_den1 = add( exp, sub(norm_den1, norm_den0) ); + pDen[1] = BASOP_Util_Divide1616_Scale( pDen[1], pDen[0], &exp ); + norm_den1 = add( exp, sub( norm_den1, norm_den0 ) ); - pNum[0] = shr(pNum[0],1 - norm_num0); - pNum[1] = shr(pNum[1],1 - norm_num1); - pDen[1] = shr(pDen[1],1 - norm_den1); - pDen[0] = shl(1, 14); + pNum[0] = shr( pNum[0], 1 - norm_num0 ); + pNum[1] = shr( pNum[1], 1 - norm_num1 ); + pDen[1] = shr( pDen[1], 1 - norm_den1 ); + pDen[0] = shl( 1, 14 ); return; } @@ -1383,21 +1386,21 @@ static ivas_error calc_jot_t60_coeffs_fx( const Word16 fNyquist_fx ) { Word16 scale1, scale2, scale3, scale4; - Word16 ref_lf_min_norm_fx = BASOP_Util_Divide1616_Scale(REF_LF_MIN_FX, fNyquist_fx, &scale1); - Word16 ref_lf_max_norm_fx = BASOP_Util_Divide1616_Scale(REF_LF_MAX_FX, fNyquist_fx, &scale2); - Word16 ref_hf_min_norm_fx = BASOP_Util_Divide1616_Scale(REF_HF_MIN_FX, fNyquist_fx, &scale3); - Word16 ref_hf_max_norm_fx = BASOP_Util_Divide1616_Scale(REF_HF_MAX_FX, fNyquist_fx, &scale4); + Word16 ref_lf_min_norm_fx = BASOP_Util_Divide1616_Scale( REF_LF_MIN_FX, fNyquist_fx, &scale1 ); + Word16 ref_lf_max_norm_fx = BASOP_Util_Divide1616_Scale( REF_LF_MAX_FX, fNyquist_fx, &scale2 ); + Word16 ref_hf_min_norm_fx = BASOP_Util_Divide1616_Scale( REF_HF_MIN_FX, fNyquist_fx, &scale3 ); + Word16 ref_hf_max_norm_fx = BASOP_Util_Divide1616_Scale( REF_HF_MAX_FX, fNyquist_fx, &scale4 ); - ref_lf_min_norm_fx = shl(ref_lf_min_norm_fx, scale1 - 1); // Q14 - ref_lf_max_norm_fx = shl(ref_lf_max_norm_fx, scale2 - 1); - ref_hf_min_norm_fx = shl(ref_hf_min_norm_fx, scale3 - 1); - ref_hf_max_norm_fx = shl(ref_hf_max_norm_fx, scale4 - 1); + ref_lf_min_norm_fx = shl( ref_lf_min_norm_fx, scale1 - 1 ); // Q14 + ref_lf_max_norm_fx = shl( ref_lf_max_norm_fx, scale2 - 1 ); + ref_hf_min_norm_fx = shl( ref_hf_min_norm_fx, scale3 - 1 ); + ref_hf_max_norm_fx = shl( ref_hf_max_norm_fx, scale4 - 1 ); Word32 L_tmp; Word16 f0_fx, tmp_fx, lf_target_gain_dB_fx, hf_target_gain_dB_fx, mid_crossing_gain_dB_fx; Word16 lin_gain_lf_fx, lin_gain_hf_fx, shift, expl, exph; int16_t f_idx, e = pH_dB_exp; - move16(); + move16(); uint16_t n_points_lf, n_points_hf; lf_target_gain_dB_fx = 0; @@ -1418,56 +1421,56 @@ static ivas_error calc_jot_t60_coeffs_fx( move16(); Word16 minidx_fx = sub( nrFrequencies, 1 ); - FOR ( f_idx = 0; f_idx < nrFrequencies; f_idx++ ) + FOR( f_idx = 0; f_idx < nrFrequencies; f_idx++ ) { IF( GE_16( pFrequencies_fx[f_idx], ref_lf_min_norm_fx ) && LE_16( pFrequencies_fx[f_idx], ref_lf_max_norm_fx ) ) { L_tmpl = L_add( L_tmpl, pH_dB_fx[f_idx] ); - n_points_lf = add(n_points_lf, 1); + n_points_lf = add( n_points_lf, 1 ); } IF( GE_16( pFrequencies_fx[f_idx], ref_hf_min_norm_fx ) && LE_16( pFrequencies_fx[f_idx], ref_hf_max_norm_fx ) ) { - L_tmph = L_add(L_tmph, pH_dB_fx[f_idx]); - n_points_hf = add(n_points_hf, 1); + L_tmph = L_add( L_tmph, pH_dB_fx[f_idx] ); + n_points_hf = add( n_points_hf, 1 ); } } - shift = norm_l(L_tmpl); - L_tmpl = L_shl(L_tmpl, shift); - tmp_fx = extract_h(L_tmpl); - expl = sub(e, sub(shift, 16)); + shift = norm_l( L_tmpl ); + L_tmpl = L_shl( L_tmpl, shift ); + tmp_fx = extract_h( L_tmpl ); + expl = sub( e, sub( shift, 16 ) ); lf_target_gain_dB_fx = tmp_fx; - shift = norm_l(L_tmph); - L_tmph = L_shl(L_tmph, shift); - tmp_fx = extract_h(L_tmph); - exph = sub(e, sub(shift, 16)); + shift = norm_l( L_tmph ); + L_tmph = L_shl( L_tmph, shift ); + tmp_fx = extract_h( L_tmph ); + exph = sub( e, sub( shift, 16 ) ); hf_target_gain_dB_fx = tmp_fx; - IF ( ( n_points_lf == 0 ) || ( n_points_hf == 0 ) ) + IF( ( n_points_lf == 0 ) || ( n_points_hf == 0 ) ) { return IVAS_ERR_INTERNAL; } lf_target_gain_dB_fx = BASOP_Util_Divide1616_Scale( lf_target_gain_dB_fx, n_points_lf, &e ); - expl = add( e, sub(expl, 15 )); + expl = add( e, sub( expl, 15 ) ); - hf_target_gain_dB_fx = BASOP_Util_Divide1616_Scale(hf_target_gain_dB_fx, n_points_hf, &e); - exph = add( e, sub( exph, 15 )); + hf_target_gain_dB_fx = BASOP_Util_Divide1616_Scale( hf_target_gain_dB_fx, n_points_hf, &e ); + exph = add( e, sub( exph, 15 ) ); - e = BASOP_Util_Add_MantExp(lf_target_gain_dB_fx, expl, negate( hf_target_gain_dB_fx ), exph, &tmp_fx); - exp = BASOP_Util_Add_MantExp(hf_target_gain_dB_fx, exph, tmp_fx, e - 1, &mid_crossing_gain_dB_fx); + e = BASOP_Util_Add_MantExp( lf_target_gain_dB_fx, expl, negate( hf_target_gain_dB_fx ), exph, &tmp_fx ); + exp = BASOP_Util_Add_MantExp( hf_target_gain_dB_fx, exph, tmp_fx, e - 1, &mid_crossing_gain_dB_fx ); - FOR ( f_idx = 1; f_idx < nrFrequencies - 1; f_idx++ ) + FOR( f_idx = 1; f_idx < nrFrequencies - 1; f_idx++ ) { Word16 tmp1; - e = BASOP_Util_Add_MantExp(pH_dB_fx[f_idx], pH_dB_exp, negate(mid_crossing_gain_dB_fx), exp, &tmp_fx); - tmp1 = abs_s(tmp_fx); + e = BASOP_Util_Add_MantExp( pH_dB_fx[f_idx], pH_dB_exp, negate( mid_crossing_gain_dB_fx ), exp, &tmp_fx ); + tmp1 = abs_s( tmp_fx ); - tmp_fx = BASOP_Util_Cmp_Mant32Exp(L_deposit_h(tmp1), e, minval_fx, minval_e); + tmp_fx = BASOP_Util_Cmp_Mant32Exp( L_deposit_h( tmp1 ), e, minval_fx, minval_e ); IF( EQ_16( tmp_fx, -1 ) ) { - minval_fx = L_deposit_h(tmp1); + minval_fx = L_deposit_h( tmp1 ); minval_e = e; move16(); minidx_fx = f_idx; @@ -1478,13 +1481,13 @@ static ivas_error calc_jot_t60_coeffs_fx( f0_fx = pFrequencies_fx[minidx_fx]; move16(); - tmp_fx = mult(lf_target_gain_dB_fx, 5443); // expl - L_tmp = BASOP_util_Pow2(L_deposit_h(tmp_fx), expl, &e); - lin_gain_lf_fx = (Word16)L_shr(L_tmp, 16 - e); + tmp_fx = mult( lf_target_gain_dB_fx, 5443 ); // expl + L_tmp = BASOP_util_Pow2( L_deposit_h( tmp_fx ), expl, &e ); + lin_gain_lf_fx = (Word16) L_shr( L_tmp, 16 - e ); - tmp_fx = mult(hf_target_gain_dB_fx, 5443); // exph - L_tmp = BASOP_util_Pow2(L_deposit_h(tmp_fx), exph, &e); - lin_gain_hf_fx = (Word16)L_shr(L_tmp, sub(16, e)); + tmp_fx = mult( hf_target_gain_dB_fx, 5443 ); // exph + L_tmp = BASOP_util_Pow2( L_deposit_h( tmp_fx ), exph, &e ); + lin_gain_hf_fx = (Word16) L_shr( L_tmp, sub( 16, e ) ); /* call low-pass iir shelf */ calc_low_shelf_first_order_filter_fx( pCoeffB_fx, pCoeffA_fx, f0_fx, lin_gain_lf_fx, lin_gain_hf_fx ); @@ -1585,12 +1588,12 @@ static ivas_error set_t60_filter( const Word16 coefA[], const Word16 coefB[] ) { - IF ( GE_32(branch , hReverb->nr_of_branches) ) + IF( GE_32( branch, hReverb->nr_of_branches ) ) { return IVAS_ERR_INTERNAL; } - IF ( GT_32(nr_taps , IVAS_REV_MAX_IIR_FILTER_LENGTH) ) + IF( GT_32( nr_taps, IVAS_REV_MAX_IIR_FILTER_LENGTH ) ) { return IVAS_ERR_INTERNAL; } @@ -1702,12 +1705,12 @@ static ivas_error set_correl_fft_filter_fx( const UWord16 channel, rv_fftwf_type_complex_fx *pSpectrum ) { - IF ( GT_32(channel , 1) ) + IF( GT_32( channel, 1 ) ) { return IVAS_ERR_INTERNAL; } - IF ( EQ_32(channel , 0) ) + IF( EQ_32( channel, 0 ) ) { ivas_reverb_fft_filter_ConvertFFTWF_2_FFTR_fx( pSpectrum, hReverb->fft_filter_correl_0.fft_spectrum_fx, hReverb->fft_filter_correl_0.fft_size ); } @@ -1731,12 +1734,12 @@ static ivas_error set_color_fft_filter_fx( const UWord16 channel, rv_fftwf_type_complex_fx *pSpectrum ) { - IF ( GT_32(channel , 1) ) + IF( GT_32( channel, 1 ) ) { return IVAS_ERR_INTERNAL; } - IF ( EQ_32(channel , 0) ) + IF( EQ_32( channel, 0 ) ) { ivas_reverb_fft_filter_ConvertFFTWF_2_FFTR_fx( pSpectrum, hReverb->fft_filter_color_0.fft_spectrum_fx, hReverb->fft_filter_color_0.fft_size ); } @@ -1845,12 +1848,12 @@ static ivas_error set_mixer_level_fx( const Word16 level[] ) { UWord16 branch_idx; - IF ( channel >= BINAURAL_CHANNELS ) + IF( channel >= BINAURAL_CHANNELS ) { return IVAS_ERR_INTERNAL; } - FOR ( branch_idx = 0; branch_idx < hReverb->nr_of_branches; branch_idx++ ) + FOR( branch_idx = 0; branch_idx < hReverb->nr_of_branches; branch_idx++ ) { hReverb->mixer_fx[channel][branch_idx] = level[branch_idx]; } @@ -1870,7 +1873,7 @@ static void clear_buffers_fx( ivas_rev_iir_filter_t *iirFilter; ivas_rev_delay_line_t *delay_line; - FOR ( branch_idx = 0; branch_idx < IVAS_REV_MAX_NR_BRANCHES; branch_idx++ ) + FOR( branch_idx = 0; branch_idx < IVAS_REV_MAX_NR_BRANCHES; branch_idx++ ) { delay_line = &( hReverb->delay_line[branch_idx] ); set_val_Word32( delay_line->pBuffer_fx, 0, delay_line->MaxDelay ); @@ -2042,41 +2045,41 @@ static void set_reverb_acoustic_data_fx( Word16 exp_argument_fx, tmp, tmp_flag, exp_argument_e; Word16 pow_exp; - Word32* pFc_input_fx = pRoomAcoustics->pFc_input_fx; - Word32* pAcoustic_rt60_fx = pRoomAcoustics->pAcoustic_rt60_fx; - Word32* pAcoustic_dsr_fx = pRoomAcoustics->pAcoustic_dsr_fx; + Word32 *pFc_input_fx = pRoomAcoustics->pFc_input_fx; + Word32 *pAcoustic_rt60_fx = pRoomAcoustics->pAcoustic_rt60_fx; + Word32 *pAcoustic_dsr_fx = pRoomAcoustics->pAcoustic_dsr_fx; - Word32* pFc_fx = pParams->pFc_fx; - Word32* pRt60_fx = pParams->pRt60_fx; - Word16* pRt60_e = pParams->pRt60_e; - Word32* pDsr_fx = pParams->pDsr_fx; - Word16* pDsr_e = pParams->pDsr_e; + Word32 *pFc_fx = pParams->pFc_fx; + Word32 *pRt60_fx = pParams->pRt60_fx; + Word16 *pRt60_e = pParams->pRt60_e; + Word32 *pDsr_fx = pParams->pDsr_fx; + Word16 *pDsr_e = pParams->pDsr_e; /* use crend hrtf filters */ - IF ( hHrtf != NULL ) + IF( hHrtf != NULL ) { /* Compute HRTF set properties: average left/right energies, IA coherence */ /* First, find the offset of the frequency-domain data for the 1st frame and assign HRTF pointers */ - FOR ( nr_out_ch = 0; nr_out_ch < BINAURAL_CHANNELS; nr_out_ch++ ) + FOR( nr_out_ch = 0; nr_out_ch < BINAURAL_CHANNELS; nr_out_ch++ ) { - FOR ( hrtf_idx = 0; hrtf_idx < hHrtf->max_num_ir; hrtf_idx++ ) + FOR( hrtf_idx = 0; hrtf_idx < hHrtf->max_num_ir; hrtf_idx++ ) { offset = 0; move16(); - FOR ( iter_idx = 0; iter_idx < hHrtf->num_iterations[hrtf_idx][nr_out_ch] - 1; iter_idx++ ) + FOR( iter_idx = 0; iter_idx < hHrtf->num_iterations[hrtf_idx][nr_out_ch] - 1; iter_idx++ ) { offset = add( offset, hHrtf->pIndex_frequency_max[hrtf_idx][nr_out_ch][iter_idx] ); } - IF ( EQ_16( nr_out_ch, 0 ) ) + IF( EQ_16( nr_out_ch, 0 ) ) { - pHrtf_set_l_re_fx[hrtf_idx] = &hHrtf->pOut_to_bin_re_fx[hrtf_idx][0][offset]; - pHrtf_set_l_im_fx[hrtf_idx] = &hHrtf->pOut_to_bin_im_fx[hrtf_idx][0][offset]; + pHrtf_set_l_re_fx[hrtf_idx] = &hHrtf->pOut_to_bin_re_fx[hrtf_idx][0][offset]; + pHrtf_set_l_im_fx[hrtf_idx] = &hHrtf->pOut_to_bin_im_fx[hrtf_idx][0][offset]; } ELSE { - pHrtf_set_r_re_fx[hrtf_idx] = &hHrtf->pOut_to_bin_re_fx[hrtf_idx][1][offset]; - pHrtf_set_r_im_fx[hrtf_idx] = &hHrtf->pOut_to_bin_im_fx[hrtf_idx][1][offset]; + pHrtf_set_r_re_fx[hrtf_idx] = &hHrtf->pOut_to_bin_re_fx[hrtf_idx][1][offset]; + pHrtf_set_r_im_fx[hrtf_idx] = &hHrtf->pOut_to_bin_im_fx[hrtf_idx][1][offset]; } } } @@ -2085,8 +2088,8 @@ static void set_reverb_acoustic_data_fx( Word32 *pHrtf_avg_pwr_response_l_fx = pParams->pHrtf_avg_pwr_response_l_fx; Word32 *pHrtf_avg_pwr_response_r_fx = pParams->pHrtf_avg_pwr_response_r_fx; Word32 *pHrtf_inter_aural_coherence_fx = pParams->pHrtf_inter_aural_coherence_fx; - ivas_reverb_get_hrtf_set_properties_fx(pHrtf_set_l_re_fx, pHrtf_set_l_im_fx, pHrtf_set_r_re_fx, pHrtf_set_r_im_fx, input_audio_config, hHrtf->max_num_ir, subframe_len, - nr_fc_fft_filter, pHrtf_avg_pwr_response_l_fx, pHrtf_avg_pwr_response_r_fx, pHrtf_inter_aural_coherence_fx); + ivas_reverb_get_hrtf_set_properties_fx( pHrtf_set_l_re_fx, pHrtf_set_l_im_fx, pHrtf_set_r_re_fx, pHrtf_set_r_im_fx, input_audio_config, hHrtf->max_num_ir, subframe_len, + nr_fc_fft_filter, pHrtf_avg_pwr_response_l_fx, pHrtf_avg_pwr_response_r_fx, pHrtf_inter_aural_coherence_fx ); pParams->pHrtf_avg_pwr_response_l_const_fx = (const Word32 *) pParams->pHrtf_avg_pwr_response_l_fx; pParams->pHrtf_avg_pwr_response_r_const_fx = (const Word32 *) pParams->pHrtf_avg_pwr_response_r_fx; @@ -2094,25 +2097,25 @@ static void set_reverb_acoustic_data_fx( } /* interpolate input table data for T60 and DSR to the FFT filter grid */ - ivas_reverb_interpolate_acoustic_data_fx(nr_fc_input, pFc_input_fx, pAcoustic_rt60_fx, pAcoustic_dsr_fx, - nr_fc_fft_filter, pFc_fx, pRt60_fx, pDsr_fx, pRt60_e, pDsr_e); + ivas_reverb_interpolate_acoustic_data_fx( nr_fc_input, pFc_input_fx, pAcoustic_rt60_fx, pAcoustic_dsr_fx, + nr_fc_fft_filter, pFc_fx, pRt60_fx, pDsr_fx, pRt60_e, pDsr_e ); /* adjust DSR for the delay difference */ - delay_diff_fx = L_sub(pRoomAcoustics->inputPreDelay_fx, pRoomAcoustics->acousticPreDelay_fx); + delay_diff_fx = L_sub( pRoomAcoustics->inputPreDelay_fx, pRoomAcoustics->acousticPreDelay_fx ); - ln_1e6_inverted_fx = 155440049; // Q31 /* 1.0f / logf( 1e06f ) */ - move32(); + ln_1e6_inverted_fx = 155440049; // Q31 /* 1.0f / logf( 1e06f ) */ + move32(); - FOR ( bin_idx = 0; bin_idx < nr_fc_fft_filter; bin_idx++ ) + FOR( bin_idx = 0; bin_idx < nr_fc_fft_filter; bin_idx++ ) { - L_tmp = Mpy_32_32(pRt60_fx[bin_idx], ln_1e6_inverted_fx ); // exp = pRt60_e[bin_idx] + 0 - exp_argument_fx = BASOP_Util_Divide3232_Scale(delay_diff_fx, L_tmp, &exp_argument_e); - exp_argument_e = add( exp_argument_e, sub(4, pRt60_e[bin_idx])); // Q27 -> e4 + L_tmp = Mpy_32_32( pRt60_fx[bin_idx], ln_1e6_inverted_fx ); // exp = pRt60_e[bin_idx] + 0 + exp_argument_fx = BASOP_Util_Divide3232_Scale( delay_diff_fx, L_tmp, &exp_argument_e ); + exp_argument_e = add( exp_argument_e, sub( 4, pRt60_e[bin_idx] ) ); // Q27 -> e4 /* Limit exponent to approx +/-100 dB in case of incoherent value of delay_diff, to prevent overflow */ // 23 in Q26 - tmp_flag = BASOP_Util_Cmp_Mant32Exp(L_deposit_h(exp_argument_fx), exp_argument_e, 1543503872, 5 ); + tmp_flag = BASOP_Util_Cmp_Mant32Exp( L_deposit_h( exp_argument_fx ), exp_argument_e, 1543503872, 5 ); IF( GT_16( tmp_flag, 0 ) ) { exp_argument_fx = 23552; @@ -2121,10 +2124,10 @@ static void set_reverb_acoustic_data_fx( move16(); } - tmp_flag = BASOP_Util_Cmp_Mant32Exp(L_deposit_h(exp_argument_fx), exp_argument_e, 0, 31); + tmp_flag = BASOP_Util_Cmp_Mant32Exp( L_deposit_h( exp_argument_fx ), exp_argument_e, 0, 31 ); IF( LT_16( tmp_flag, 0 ) ) { - tmp_flag = BASOP_Util_Cmp_Mant32Exp(L_deposit_h(negate( exp_argument_fx) ), exp_argument_e, 1543503872, 5); + tmp_flag = BASOP_Util_Cmp_Mant32Exp( L_deposit_h( negate( exp_argument_fx ) ), exp_argument_e, 1543503872, 5 ); IF( LT_16( tmp_flag, 0 ) ) { exp_argument_fx = -23552; @@ -2136,9 +2139,9 @@ static void set_reverb_acoustic_data_fx( Word16 tmp_exp; /* expf(exp_argument) -> pow(2, log2(e) * exp_argument) */ - tmp = mult(23637, exp_argument_fx); // exp_argument_e + 1 + tmp = mult( 23637, exp_argument_fx ); // exp_argument_e + 1 tmp_exp = add( exp_argument_e, 1 ); - L_tmp = BASOP_util_Pow2(L_deposit_h(tmp), tmp_exp, &pow_exp); + L_tmp = BASOP_util_Pow2( L_deposit_h( tmp ), tmp_exp, &pow_exp ); L_tmp = Mpy_32_32( L_tmp, pDsr_fx[bin_idx] ); tmp_exp = add( tmp_exp, pDsr_e[bin_idx] ); @@ -2146,7 +2149,6 @@ static void set_reverb_acoustic_data_fx( move32(); pDsr_e[bin_idx] = tmp_exp; move16(); - } return; } @@ -2187,13 +2189,13 @@ static void set_reverb_acoustic_data( if ( nr_out_ch == 0 ) { - pHrtf_set_l_re[hrtf_idx] = &hHrtf->pOut_to_bin_re[hrtf_idx][0][offset]; - pHrtf_set_l_im[hrtf_idx] = &hHrtf->pOut_to_bin_im[hrtf_idx][0][offset]; + pHrtf_set_l_re[hrtf_idx] = &hHrtf->pOut_to_bin_re[hrtf_idx][0][offset]; + pHrtf_set_l_im[hrtf_idx] = &hHrtf->pOut_to_bin_im[hrtf_idx][0][offset]; } else { - pHrtf_set_r_re[hrtf_idx] = &hHrtf->pOut_to_bin_re[hrtf_idx][1][offset]; - pHrtf_set_r_im[hrtf_idx] = &hHrtf->pOut_to_bin_im[hrtf_idx][1][offset]; + pHrtf_set_r_re[hrtf_idx] = &hHrtf->pOut_to_bin_re[hrtf_idx][1][offset]; + pHrtf_set_r_im[hrtf_idx] = &hHrtf->pOut_to_bin_im[hrtf_idx][1][offset]; } } } @@ -2214,7 +2216,7 @@ static void set_reverb_acoustic_data( delay_diff = pRoomAcoustics->inputPreDelay - pRoomAcoustics->acousticPreDelay; - ln_1e6_inverted = 1.0f / logf( 1e06f ); + ln_1e6_inverted = 1.0f / logf( 1e06f ); for ( bin_idx = 0; bin_idx < nr_fc_fft_filter; bin_idx++ ) { @@ -2222,7 +2224,7 @@ static void set_reverb_acoustic_data( /* Limit exponent to approx +/-100 dB in case of incoherent value of delay_diff, to prevent overflow */ exp_argument = min( exp_argument, 23.0f ); - exp_argument = max(exp_argument, -23.0f); + exp_argument = max( exp_argument, -23.0f ); pParams->pDsr[bin_idx] *= expf( exp_argument ); } return; @@ -2246,7 +2248,7 @@ static ivas_error setup_FDN_branches_fx( error = IVAS_ERR_OK; /* initialize feedback branches */ - FOR ( branch_idx = 0; branch_idx < IVAS_REV_MAX_NR_BRANCHES; branch_idx++ ) + FOR( branch_idx = 0; branch_idx < IVAS_REV_MAX_NR_BRANCHES; branch_idx++ ) { ivas_rev_delay_line_init( &( hReverb->delay_line[branch_idx] ), hReverb->loop_delay_buffer_fx[branch_idx], init_loop_delay[branch_idx], pParams->pLoop_delays[branch_idx] ); ivas_reverb_iir_filt_init( &( hReverb->t60[branch_idx] ), IVAS_REV_MAX_IIR_FILTER_LENGTH ); @@ -2256,38 +2258,38 @@ static ivas_error setup_FDN_branches_fx( move16(); } clear_buffers_fx( hReverb ); - nr_coefs = add(pParams->t60_filter_order , 1); + nr_coefs = add( pParams->t60_filter_order, 1 ); - IF ( LT_16(IVAS_REV_MAX_IIR_FILTER_LENGTH , nr_coefs) ) + IF( LT_16( IVAS_REV_MAX_IIR_FILTER_LENGTH, nr_coefs ) ) { return IVAS_ERR_INTERNAL; } ELSE { - FOR ( branch_idx = 0; branch_idx < pParams->nr_loops; branch_idx++ ) + FOR( branch_idx = 0; branch_idx < pParams->nr_loops; branch_idx++ ) { - pCoef_a = &pParams->pT60_filter_coeff_fx[2 * nr_coefs * branch_idx + nr_coefs];/*Q14*/ - pCoef_b = &pParams->pT60_filter_coeff_fx[2 * nr_coefs * branch_idx];/*Q14*/ + pCoef_a = &pParams->pT60_filter_coeff_fx[2 * nr_coefs * branch_idx + nr_coefs]; /*Q14*/ + pCoef_b = &pParams->pT60_filter_coeff_fx[2 * nr_coefs * branch_idx]; /*Q14*/ - IF ( ( error = set_t60_filter( hReverb, branch_idx, nr_coefs, pCoef_a, pCoef_b ) ) != IVAS_ERR_OK ) + IF( ( error = set_t60_filter( hReverb, branch_idx, nr_coefs, pCoef_a, pCoef_b ) ) != IVAS_ERR_OK ) { return error; } - IF ( ( error = set_feedback_delay_fx( hReverb, branch_idx, pParams->pLoop_delays[branch_idx] ) ) != IVAS_ERR_OK ) + IF( ( error = set_feedback_delay_fx( hReverb, branch_idx, pParams->pLoop_delays[branch_idx] ) ) != IVAS_ERR_OK ) { return error; } - IF ( ( error = set_feedback_gain_fx( hReverb, branch_idx, &( pParams->pLoop_feedback_matrix_fx[branch_idx * pParams->nr_loops] ) ) ) != IVAS_ERR_OK ) + IF( ( error = set_feedback_gain_fx( hReverb, branch_idx, &( pParams->pLoop_feedback_matrix_fx[branch_idx * pParams->nr_loops] ) ) ) != IVAS_ERR_OK ) { return error; } } } - FOR ( channel_idx = 0; channel_idx < pParams->nr_outputs; channel_idx++ ) + FOR( channel_idx = 0; channel_idx < pParams->nr_outputs; channel_idx++ ) { - IF ( ( error = set_mixer_level_fx( hReverb, channel_idx, &( pParams->pLoop_extract_matrix_fx[channel_idx * pParams->nr_loops] ) ) ) != IVAS_ERR_OK ) + IF( ( error = set_mixer_level_fx( hReverb, channel_idx, &( pParams->pLoop_extract_matrix_fx[channel_idx * pParams->nr_loops] ) ) ) != IVAS_ERR_OK ) { return error; } @@ -2371,9 +2373,9 @@ ivas_error ivas_reverb_open_fx( REVERB_HANDLE *hReverb, /* i/o: Reverberator handle */ const AUDIO_CONFIG input_audio_config, /* i : reverb. input audio configuration */ const HRTFS_HANDLE hHrtf, /* i : HRTF handle */ - const Word32 *lr_energy_and_iac_fx[], /* i : precomuputed lr energies and iac */ + const Word32 *lr_energy_and_iac_fx[], /* i : precomuputed lr energies and iac */ RENDER_CONFIG_HANDLE hRenderConfig, /* i : Renderer configuration handle */ - const Word32 output_Fs /* i : output sampling rate */ + const Word32 output_Fs /* i : output sampling rate */ ) { ivas_error error; @@ -2390,34 +2392,34 @@ ivas_error ivas_reverb_open_fx( rv_fftwf_type_complex_fx pFft_wf_filter_ch1_fx[RV_LENGTH_NR_FC]; error = IVAS_ERR_OK; - output_frame = extract_l(Mult_32_16( output_Fs , INV_FRAME_PER_SEC_Q15)); - subframe_len = shr(output_frame , 2); /*output_frame / MAX_PARAM_SPATIAL_SUBFRAMES*/ + output_frame = extract_l( Mult_32_16( output_Fs, INV_FRAME_PER_SEC_Q15 ) ); + subframe_len = shr( output_frame, 2 ); /*output_frame / MAX_PARAM_SPATIAL_SUBFRAMES*/ predelay_bf_len = output_frame; move16(); nr_fc_input = hRenderConfig->roomAcoustics.nBands; /* Allocate main reverb. handle */ - IF ( ( pState = (REVERB_HANDLE) malloc( sizeof( REVERB_DATA ) ) ) == NULL ) + IF( ( pState = (REVERB_HANDLE) malloc( sizeof( REVERB_DATA ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend Reverberator " ); } - IF ( ( error = set_base_config_fx( ¶ms, output_Fs ) ) != IVAS_ERR_OK ) + IF( ( error = set_base_config_fx( ¶ms, output_Fs ) ) != IVAS_ERR_OK ) { return error; } /* Allocate memory for feedback delay lines */ - FOR ( loop_idx = 0; loop_idx < IVAS_REV_MAX_NR_BRANCHES; loop_idx++ ) + FOR( loop_idx = 0; loop_idx < IVAS_REV_MAX_NR_BRANCHES; loop_idx++ ) { - IF ( ( pState->loop_delay_buffer_fx[loop_idx] = (Word32 *) malloc( params.pLoop_delays[loop_idx] * sizeof( Word32 ) ) ) == NULL ) + IF( ( pState->loop_delay_buffer_fx[loop_idx] = (Word32 *) malloc( params.pLoop_delays[loop_idx] * sizeof( Word32 ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CREND Reverberator" ); } } /* Allocate memory for the pre-delay delay line */ - IF ( ( pState->pPredelay_buffer_fx = (Word32 *) malloc( output_frame * sizeof(Word32) ) ) == NULL ) + IF( ( pState->pPredelay_buffer_fx = (Word32 *) malloc( output_frame * sizeof( Word32 ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CREND Reverberator" ); } @@ -2440,13 +2442,13 @@ ivas_error ivas_reverb_open_fx( /* before calls to ivas_reverb_calc_correl_filters(...) or to ivas_reverb_calc_color_filters(...) */ /* set the uniform frequency grid for FFT filtering */ - freq_step_fx = L_mult0( extract_l(L_shr(output_Fs,2)), div_s( 1, ( nr_fc_fft_filter - 1 ) ) );/*Q14:0.5f * output_Fs / ( nr_fc_fft_filter - 1 )*/ - FOR ( bin_idx = 0; bin_idx < nr_fc_fft_filter; bin_idx++ ) + freq_step_fx = L_mult0( extract_l( L_shr( output_Fs, 2 ) ), div_s( 1, ( nr_fc_fft_filter - 1 ) ) ); /*Q14:0.5f * output_Fs / ( nr_fc_fft_filter - 1 )*/ + FOR( bin_idx = 0; bin_idx < nr_fc_fft_filter; bin_idx++ ) { - params.pFc_fx[bin_idx] = W_extract_l(W_mult0_32_32(freq_step_fx , bin_idx));/*Q14*/ + params.pFc_fx[bin_idx] = W_extract_l( W_mult0_32_32( freq_step_fx, bin_idx ) ); /*Q14*/ } - IF ( hHrtf == NULL && lr_energy_and_iac_fx != NULL ) + IF( hHrtf == NULL && lr_energy_and_iac_fx != NULL ) { params.pHrtf_avg_pwr_response_l_const_fx = lr_energy_and_iac_fx[0]; params.pHrtf_avg_pwr_response_r_const_fx = lr_energy_and_iac_fx[1]; @@ -2454,25 +2456,25 @@ ivas_error ivas_reverb_open_fx( } /* set up reverb acoustic data on the basis of HRTF data and renderer config */ Scale_sig32( params.pFc_fx, nr_fc_fft_filter, 2 ); - Word16 *pRt60_e = (Word16 *)malloc(sizeof(Word16) * nr_fc_fft_filter); - Word16 *pDsr_e = (Word16 *)malloc(sizeof(Word16) * nr_fc_fft_filter); + Word16 *pRt60_e = (Word16 *) malloc( sizeof( Word16 ) * nr_fc_fft_filter ); + Word16 *pDsr_e = (Word16 *) malloc( sizeof( Word16 ) * nr_fc_fft_filter ); params.pRt60_e = pRt60_e; params.pDsr_e = pDsr_e; set_reverb_acoustic_data_fx( ¶ms, input_audio_config, hHrtf, &hRenderConfig->roomAcoustics, subframe_len, nr_fc_input, nr_fc_fft_filter ); Scale_sig32( params.pFc_fx, nr_fc_fft_filter, -2 ); - FOR ( Word16 i = 0; i < nr_fc_fft_filter; i++ ) + FOR( Word16 i = 0; i < nr_fc_fft_filter; i++ ) { - params.pRt60_fx[i] = L_abs(params.pRt60_fx[i]); - params.pDsr_fx[i] = L_abs(params.pDsr_fx[i]); + params.pRt60_fx[i] = L_abs( params.pRt60_fx[i] ); + params.pDsr_fx[i] = L_abs( params.pDsr_fx[i] ); } /* set reverb acoustic configuration based on renderer config */ pState->pConfig.roomAcoustics.override = hRenderConfig->roomAcoustics.override; pState->pConfig.roomAcoustics.nBands = hRenderConfig->roomAcoustics.nBands; - IF ( hRenderConfig->roomAcoustics.use_er == 1 ) + IF( hRenderConfig->roomAcoustics.use_er == 1 ) { pState->pConfig.roomAcoustics.use_er = hRenderConfig->roomAcoustics.use_er; pState->pConfig.roomAcoustics.lowComplexity = hRenderConfig->roomAcoustics.lowComplexity; @@ -2486,43 +2488,43 @@ ivas_error ivas_reverb_open_fx( /* set up jot reverb 60 filters - must be set up after set_reverb_acoustic_data() */ - IF ( ( error = compute_t60_coeffs_fx( ¶ms, nr_fc_fft_filter, output_Fs ) ) != IVAS_ERR_OK ) + IF( ( error = compute_t60_coeffs_fx( ¶ms, nr_fc_fft_filter, output_Fs ) ) != IVAS_ERR_OK ) { return error; } /* Compute target levels (gains) for the coloration filters */ - Word32 *pHrtf_avg_pwr_response_l_const = (Word32*)malloc(nr_fc_fft_filter * sizeof(Word32*)); - Word32 *pHrtf_avg_pwr_response_r_const = (Word32*)malloc(nr_fc_fft_filter * sizeof(Word32*)); - Word16 lenT60_filter_coeff = add(params.t60_filter_order, 1); - lenT60_filter_coeff = add(i_mult(shl(lenT60_filter_coeff, 1), sub(params.nr_loops, 1)), add(lenT60_filter_coeff, 2)); - Word32 *pT60_filter_coeff = (Word32*)malloc((lenT60_filter_coeff) * sizeof(Word32*)); + Word32 *pHrtf_avg_pwr_response_l_const = (Word32 *) malloc( nr_fc_fft_filter * sizeof( Word32 * ) ); + Word32 *pHrtf_avg_pwr_response_r_const = (Word32 *) malloc( nr_fc_fft_filter * sizeof( Word32 * ) ); + Word16 lenT60_filter_coeff = add( params.t60_filter_order, 1 ); + lenT60_filter_coeff = add( i_mult( shl( lenT60_filter_coeff, 1 ), sub( params.nr_loops, 1 ) ), add( lenT60_filter_coeff, 2 ) ); + Word32 *pT60_filter_coeff = (Word32 *) malloc( ( lenT60_filter_coeff ) * sizeof( Word32 * ) ); - FOR (int i = 0; i < nr_fc_fft_filter; i++) + FOR( int i = 0; i < nr_fc_fft_filter; i++ ) { - params.pDsr_fx[i] = L_shl(params.pDsr_fx[i] , params.pDsr_e[i]); - pHrtf_avg_pwr_response_l_const[i] = L_shl(params.pHrtf_avg_pwr_response_l_const_fx[i] ,5);/*Q23+5*/ - pHrtf_avg_pwr_response_r_const[i] = L_shl(params.pHrtf_avg_pwr_response_r_const_fx[i] ,5);/*Q23+5*/ + params.pDsr_fx[i] = L_shl( params.pDsr_fx[i], params.pDsr_e[i] ); + pHrtf_avg_pwr_response_l_const[i] = L_shl( params.pHrtf_avg_pwr_response_l_const_fx[i], 5 ); /*Q23+5*/ + pHrtf_avg_pwr_response_r_const[i] = L_shl( params.pHrtf_avg_pwr_response_r_const_fx[i], 5 ); /*Q23+5*/ } - FOR (int i = 0; i < lenT60_filter_coeff; i++) + FOR( int i = 0; i < lenT60_filter_coeff; i++ ) { - pT60_filter_coeff[i] = L_shl_sat(params.pT60_filter_coeff_fx[i] ,17); + pT60_filter_coeff[i] = L_shl_sat( params.pT60_filter_coeff_fx[i], 17 ); } - ivas_reverb_calc_color_levels_fx(output_Fs, nr_fc_fft_filter, params.nr_loops, params.pFc_fx, params.pDsr_fx, pHrtf_avg_pwr_response_l_const, pHrtf_avg_pwr_response_r_const, - params.pLoop_delays, pT60_filter_coeff, pColor_target_l_fx, pColor_target_r_fx); + ivas_reverb_calc_color_levels_fx( output_Fs, nr_fc_fft_filter, params.nr_loops, params.pFc_fx, params.pDsr_fx, pHrtf_avg_pwr_response_l_const, pHrtf_avg_pwr_response_r_const, + params.pLoop_delays, pT60_filter_coeff, pColor_target_l_fx, pColor_target_r_fx ); - free(pHrtf_avg_pwr_response_l_const); - free(pHrtf_avg_pwr_response_r_const); - free(pT60_filter_coeff); + free( pHrtf_avg_pwr_response_l_const ); + free( pHrtf_avg_pwr_response_r_const ); + free( pT60_filter_coeff ); /* Defining appropriate windowing parameters for FFT filters to prevent aliasing */ fft_hist_size = pState->fft_size - pState->fft_subblock_size; - transition_start = round_fx(L_mult0( FFT_FILTER_WND_FLAT_REGION_FX , fft_hist_size )); - transition_length = round_fx(L_mult0( FFT_FILTER_WND_TRANS_REGION_FX , fft_hist_size )); + transition_start = round_fx( L_mult0( FFT_FILTER_WND_FLAT_REGION_FX, fft_hist_size ) ); + transition_length = round_fx( L_mult0( FFT_FILTER_WND_TRANS_REGION_FX, fft_hist_size ) ); /* Compute the window used for FFT filters */ - ivas_reverb_define_window_fft_fx(pTime_window_fx, transition_start, transition_length, nr_fc_fft_filter); + ivas_reverb_define_window_fft_fx( pTime_window_fx, transition_start, transition_length, nr_fc_fft_filter ); /* === Now, copy parameters from ivas_reverb_params_t into DSP blocks === */ /* === to be used for subsequent audio signal processing === */ @@ -2530,62 +2532,66 @@ ivas_error ivas_reverb_open_fx( move16(); /* clear & init jot reverb fft filters */ - IF ( ( error = initialize_reverb_filters_fx( pState ) ) != IVAS_ERR_OK ) + IF( ( error = initialize_reverb_filters_fx( pState ) ) != IVAS_ERR_OK ) { return error; } Word16 q_pFft_wf_filter_ch0_fx = 23, q_pFft_wf_filter_ch1_fx = 23; - IF ( pState->do_corr_filter ) + IF( pState->do_corr_filter ) { q_pFft_wf_filter_ch0_fx = 31; move16(); q_pFft_wf_filter_ch1_fx = 31; move16(); /* Computing correlation filters on the basis of target IA coherence */ - FOR (int i = 0; i < nr_fc_fft_filter; i++) { - pFft_wf_filter_ch0_fx[i][0] = L_shl_sat(pFft_wf_filter_ch0_fx[i][0] , 8); - pFft_wf_filter_ch0_fx[i][1] = L_shl_sat(pFft_wf_filter_ch0_fx[i][1] , 8); - } - FOR (int i = 0; i < nr_fc_fft_filter; i++) { - pFft_wf_filter_ch1_fx[i][0] = L_shl_sat(pFft_wf_filter_ch1_fx[i][0] ,8); - pFft_wf_filter_ch1_fx[i][1] = L_shl_sat(pFft_wf_filter_ch1_fx[i][1] ,8); - } + FOR( int i = 0; i < nr_fc_fft_filter; i++ ) + { + pFft_wf_filter_ch0_fx[i][0] = L_shl_sat( pFft_wf_filter_ch0_fx[i][0], 8 ); + pFft_wf_filter_ch0_fx[i][1] = L_shl_sat( pFft_wf_filter_ch0_fx[i][1], 8 ); + } + FOR( int i = 0; i < nr_fc_fft_filter; i++ ) + { + pFft_wf_filter_ch1_fx[i][0] = L_shl_sat( pFft_wf_filter_ch1_fx[i][0], 8 ); + pFft_wf_filter_ch1_fx[i][1] = L_shl_sat( pFft_wf_filter_ch1_fx[i][1], 8 ); + } #ifdef MSAN_FIX - FOR( int i = 0; i < shl(sub(nr_fc_fft_filter, 1), 1); i++ ) - { - pTime_window_fx[i] = L_shr( pTime_window_fx[i], 1 ); /*Scaling signal down to 30*/ - } + FOR( int i = 0; i < shl( sub( nr_fc_fft_filter, 1 ), 1 ); i++ ) + { + pTime_window_fx[i] = L_shr( pTime_window_fx[i], 1 ); /*Scaling signal down to 30*/ + } #else - FOR (int i = 0; i < RV_FILTER_MAX_FFT_SIZE; i++) { - pTime_window_fx[i] = L_shr( pTime_window_fx[i], 1 );/*Scaling signal down to 30*/ - } + FOR( int i = 0; i < RV_FILTER_MAX_FFT_SIZE; i++ ) + { + pTime_window_fx[i] = L_shr( pTime_window_fx[i], 1 ); /*Scaling signal down to 30*/ + } #endif // MSAN_FIX - Word32* pHrtf_inter_aural_coherence_const = (Word32*)malloc(nr_fc_fft_filter * sizeof(Word32)); - FOR (int i = 0; i < nr_fc_fft_filter; i++) { - pHrtf_inter_aural_coherence_const[i] = L_shl(params.pHrtf_inter_aural_coherence_const_fx[i] , 3);/*Scaling up to Q30*/ - } - ivas_reverb_calc_correl_filters_fx(pHrtf_inter_aural_coherence_const, pTime_window_fx, pState->fft_size, 0, pFft_wf_filter_ch0_fx, pFft_wf_filter_ch1_fx, &q_pFft_wf_filter_ch0_fx, &q_pFft_wf_filter_ch1_fx); - - free(pHrtf_inter_aural_coherence_const); - - FOR ( int i = 0; i < nr_fc_fft_filter; i++ ) - { - pFft_wf_filter_ch0_fx[i][0] = L_shl( pFft_wf_filter_ch0_fx[i][0], 31 - q_pFft_wf_filter_ch0_fx ); - pFft_wf_filter_ch0_fx[i][1] = L_shl( pFft_wf_filter_ch0_fx[i][1], 31 - q_pFft_wf_filter_ch0_fx ); - } - FOR ( int i = 0; i < nr_fc_fft_filter; i++ ) - { - pFft_wf_filter_ch1_fx[i][0] = L_shl( pFft_wf_filter_ch1_fx[i][0], 31 - q_pFft_wf_filter_ch1_fx ); - pFft_wf_filter_ch1_fx[i][1] = L_shl( pFft_wf_filter_ch1_fx[i][1], 31 - q_pFft_wf_filter_ch1_fx ); - } + Word32 *pHrtf_inter_aural_coherence_const = (Word32 *) malloc( nr_fc_fft_filter * sizeof( Word32 ) ); + FOR( int i = 0; i < nr_fc_fft_filter; i++ ) + { + pHrtf_inter_aural_coherence_const[i] = L_shl( params.pHrtf_inter_aural_coherence_const_fx[i], 3 ); /*Scaling up to Q30*/ + } + ivas_reverb_calc_correl_filters_fx( pHrtf_inter_aural_coherence_const, pTime_window_fx, pState->fft_size, 0, pFft_wf_filter_ch0_fx, pFft_wf_filter_ch1_fx, &q_pFft_wf_filter_ch0_fx, &q_pFft_wf_filter_ch1_fx ); + + free( pHrtf_inter_aural_coherence_const ); + + FOR( int i = 0; i < nr_fc_fft_filter; i++ ) + { + pFft_wf_filter_ch0_fx[i][0] = L_shl( pFft_wf_filter_ch0_fx[i][0], 31 - q_pFft_wf_filter_ch0_fx ); + pFft_wf_filter_ch0_fx[i][1] = L_shl( pFft_wf_filter_ch0_fx[i][1], 31 - q_pFft_wf_filter_ch0_fx ); + } + FOR( int i = 0; i < nr_fc_fft_filter; i++ ) + { + pFft_wf_filter_ch1_fx[i][0] = L_shl( pFft_wf_filter_ch1_fx[i][0], 31 - q_pFft_wf_filter_ch1_fx ); + pFft_wf_filter_ch1_fx[i][1] = L_shl( pFft_wf_filter_ch1_fx[i][1], 31 - q_pFft_wf_filter_ch1_fx ); + } /* Copying the computed FFT correlation filters to the fft_filter components */ - IF ( ( error = set_correl_fft_filter_fx( pState, 0, pFft_wf_filter_ch0_fx ) ) != IVAS_ERR_OK ) + IF( ( error = set_correl_fft_filter_fx( pState, 0, pFft_wf_filter_ch0_fx ) ) != IVAS_ERR_OK ) { return error; } - IF ( ( error = set_correl_fft_filter_fx( pState, 1, pFft_wf_filter_ch1_fx ) ) != IVAS_ERR_OK ) + IF( ( error = set_correl_fft_filter_fx( pState, 1, pFft_wf_filter_ch1_fx ) ) != IVAS_ERR_OK ) { return error; } @@ -2593,13 +2599,13 @@ ivas_error ivas_reverb_open_fx( /* Computing coloration filters on the basis of target responses */ - ivas_reverb_calc_color_filters_fx(pColor_target_l_fx, pColor_target_r_fx, pTime_window_fx, pState->fft_size, 0, pFft_wf_filter_ch0_fx, pFft_wf_filter_ch1_fx, &q_pFft_wf_filter_ch0_fx, &q_pFft_wf_filter_ch1_fx); - FOR ( int i = 0; i < nr_fc_fft_filter; i++ ) + ivas_reverb_calc_color_filters_fx( pColor_target_l_fx, pColor_target_r_fx, pTime_window_fx, pState->fft_size, 0, pFft_wf_filter_ch0_fx, pFft_wf_filter_ch1_fx, &q_pFft_wf_filter_ch0_fx, &q_pFft_wf_filter_ch1_fx ); + FOR( int i = 0; i < nr_fc_fft_filter; i++ ) { pFft_wf_filter_ch0_fx[i][0] = L_shl( pFft_wf_filter_ch0_fx[i][0], 31 - q_pFft_wf_filter_ch0_fx ); pFft_wf_filter_ch0_fx[i][1] = L_shl( pFft_wf_filter_ch0_fx[i][1], 31 - q_pFft_wf_filter_ch0_fx ); } - FOR ( int i = 0; i < nr_fc_fft_filter; i++ ) + FOR( int i = 0; i < nr_fc_fft_filter; i++ ) { pFft_wf_filter_ch1_fx[i][0] = L_shl( pFft_wf_filter_ch1_fx[i][0], 31 - q_pFft_wf_filter_ch1_fx ); pFft_wf_filter_ch1_fx[i][1] = L_shl( pFft_wf_filter_ch1_fx[i][1], 31 - q_pFft_wf_filter_ch1_fx ); @@ -2609,12 +2615,12 @@ ivas_error ivas_reverb_open_fx( Scale_sig32( params.pFc_fx, nr_fc_fft_filter, 17 ); /*Scaling ( *hReverb )->fft_filter_color_1.fft_spectrum_fx to Q31*/ /* Copying the computed FFT colorations filters to the fft_filter components */ - IF ( ( error = set_color_fft_filter_fx( pState, 0, pFft_wf_filter_ch0_fx ) ) != IVAS_ERR_OK ) + IF( ( error = set_color_fft_filter_fx( pState, 0, pFft_wf_filter_ch0_fx ) ) != IVAS_ERR_OK ) { return error; } - IF ( ( error = set_color_fft_filter_fx( pState, 1, pFft_wf_filter_ch1_fx ) ) != IVAS_ERR_OK ) + IF( ( error = set_color_fft_filter_fx( pState, 1, pFft_wf_filter_ch1_fx ) ) != IVAS_ERR_OK ) { return error; } @@ -2623,7 +2629,7 @@ ivas_error ivas_reverb_open_fx( ivas_rev_delay_line_init( &( pState->predelay_line ), pState->pPredelay_buffer_fx, params.pre_delay, predelay_bf_len ); /* set up feedback delay network */ - IF ( ( error = setup_FDN_branches_fx( pState, ¶ms ) ) != IVAS_ERR_OK ) + IF( ( error = setup_FDN_branches_fx( pState, ¶ms ) ) != IVAS_ERR_OK ) { return error; } @@ -3548,14 +3554,14 @@ void ivas_binaural_reverb_processSubframe( * according to RT60. This procedure generates an IIR decaying response. The response * is decorrelated later on. */ - //loopAttenuationFactor ->Q31 + // loopAttenuationFactor ->Q31 v_multc( hReverb->loopBufReal[bin] + hReverb->loopBufLength[bin], hReverb->loopAttenuationFactor[bin], hReverb->loopBufReal[bin], numSlots ); v_multc( hReverb->loopBufImag[bin] + hReverb->loopBufLength[bin], hReverb->loopAttenuationFactor[bin], hReverb->loopBufImag[bin], numSlots ); } /* 2) Apply the determined pre-delay to the input audio, and add the delayed audio to the loop. */ - //hReverb->reverbEqGains[bin]; ->Q31// + // hReverb->reverbEqGains[bin]; ->Q31// idx = hReverb->preDelayBufferIndex; for ( sample = 0; sample < numSlots; sample++ ) @@ -3689,8 +3695,8 @@ void ivas_binaural_reverb_processSubframe( void ivas_binaural_reverb_processSubframe_fx( REVERB_STRUCT_HANDLE hReverb, /* i/o: binaural reverb handle */ - const Word16 numInChannels, /* i : num inputs to be processed */ - const Word16 numSlots, /* i : number of slots to be processed */ + const Word16 numInChannels, /* i : num inputs to be processed */ + const Word16 numSlots, /* i : number of slots to be processed */ Word32 inReal[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i (Q_in) : input CLDFB data real, Comment: This change swaps two first dimensions as first dimension is not constant. */ Word32 inImag[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i (Q_in) : input CLDFB data imag */ Word32 outReal[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* o : output CLDFB data real */ @@ -3723,18 +3729,18 @@ void ivas_binaural_reverb_processSubframe_fx( idx = hReverb->preDelayBufferIndex; FOR( sample = 0; sample < numSlots; sample++ ) { - invertSampleIndex = sub(sub( numSlots, sample ), 1 ); + invertSampleIndex = sub( sub( numSlots, sample ), 1 ); FOR( bin = 0; bin < hReverb->numBins; bin++ ) { /* Add from pre-delay buffer a sample to the loop buffer, in a time-inverted order. * Also apply the spectral gains determined for the reverberation */ - Word32 temp_1 = Mpy_32_32( hReverb->preDelayBufferReal_fx[idx][bin], hReverb->reverbEqGains_fx[bin] ); - Word32 temp_2 = Mpy_32_32( hReverb->preDelayBufferImag_fx[idx][bin], hReverb->reverbEqGains_fx[bin] ); - hReverb->loopBufReal_fx[bin][invertSampleIndex] = L_add( hReverb->loopBufReal_fx[bin][invertSampleIndex], temp_1 ); - hReverb->loopBufImag_fx[bin][invertSampleIndex] = L_add( hReverb->loopBufImag_fx[bin][invertSampleIndex], temp_2 ); - hReverb->preDelayBufferReal_fx[idx][bin] = 0; - hReverb->preDelayBufferImag_fx[idx][bin] = 0; + Word32 temp_1 = Mpy_32_32( hReverb->preDelayBufferReal_fx[idx][bin], hReverb->reverbEqGains_fx[bin] ); + Word32 temp_2 = Mpy_32_32( hReverb->preDelayBufferImag_fx[idx][bin], hReverb->reverbEqGains_fx[bin] ); + hReverb->loopBufReal_fx[bin][invertSampleIndex] = L_add( hReverb->loopBufReal_fx[bin][invertSampleIndex], temp_1 ); + hReverb->loopBufImag_fx[bin][invertSampleIndex] = L_add( hReverb->loopBufImag_fx[bin][invertSampleIndex], temp_2 ); + hReverb->preDelayBufferReal_fx[idx][bin] = 0; + hReverb->preDelayBufferImag_fx[idx][bin] = 0; } /* Add every second input channel as is to the pre-delay buffer, and every second input channel with @@ -3804,19 +3810,19 @@ void ivas_binaural_reverb_processSubframe_fx( { FOR( sample = 0; sample < numSlots; sample++ ) { - //float leftRe, rightRe, leftIm, rightIm; + // float leftRe, rightRe, leftIm, rightIm; Word32 leftRe_fx, rightRe_fx, leftIm_fx, rightIm_fx; leftRe_fx = L_add( Mpy_32_32( hReverb->binauralCoherenceDirectGains_fx[bin], hReverb->outputBufferReal_fx[bin][0][sample] ), - Mpy_32_32( hReverb->binauralCoherenceCrossmixGains_fx[bin], hReverb->outputBufferReal_fx[bin][1][sample] ) ); + Mpy_32_32( hReverb->binauralCoherenceCrossmixGains_fx[bin], hReverb->outputBufferReal_fx[bin][1][sample] ) ); rightRe_fx = L_add( Mpy_32_32( hReverb->binauralCoherenceDirectGains_fx[bin], hReverb->outputBufferReal_fx[bin][1][sample] ), - Mpy_32_32( hReverb->binauralCoherenceCrossmixGains_fx[bin], hReverb->outputBufferReal_fx[bin][0][sample] ) ); + Mpy_32_32( hReverb->binauralCoherenceCrossmixGains_fx[bin], hReverb->outputBufferReal_fx[bin][0][sample] ) ); leftIm_fx = L_add( Mpy_32_32( hReverb->binauralCoherenceDirectGains_fx[bin], hReverb->outputBufferImag_fx[bin][0][sample] ), - Mpy_32_32( hReverb->binauralCoherenceCrossmixGains_fx[bin], hReverb->outputBufferImag_fx[bin][1][sample] ) ); + Mpy_32_32( hReverb->binauralCoherenceCrossmixGains_fx[bin], hReverb->outputBufferImag_fx[bin][1][sample] ) ); rightIm_fx = L_add( Mpy_32_32( hReverb->binauralCoherenceDirectGains_fx[bin], hReverb->outputBufferImag_fx[bin][1][sample] ), - Mpy_32_32( hReverb->binauralCoherenceCrossmixGains_fx[bin], hReverb->outputBufferImag_fx[bin][0][sample] ) ); + Mpy_32_32( hReverb->binauralCoherenceCrossmixGains_fx[bin], hReverb->outputBufferImag_fx[bin][0][sample] ) ); - hReverb->outputBufferReal_fx[bin][0][sample] = leftRe_fx; // Q_in + hReverb->outputBufferReal_fx[bin][0][sample] = leftRe_fx; // Q_in hReverb->outputBufferReal_fx[bin][1][sample] = rightRe_fx; // Q_in hReverb->outputBufferImag_fx[bin][0][sample] = leftIm_fx; // Q_in hReverb->outputBufferImag_fx[bin][1][sample] = rightIm_fx; // Q_in @@ -3862,19 +3868,19 @@ void ivas_binaural_reverb_processSubframe_fx( *------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED static ivas_error ivas_binaural_reverb_open_fx( - REVERB_STRUCT_HANDLE *hReverbPr, /* i/o: binaural reverb handle */ + REVERB_STRUCT_HANDLE *hReverbPr, /* i/o: binaural reverb handle */ const Word16 numBins, /* i : number of CLDFB bins */ const Word16 numCldfbSlotsPerFrame, /* i : number of CLDFB slots per frame */ const Word32 sampling_rate, /* i : sampling rate */ - const Word32 *revTimes_fx, /* i : reverberation times T60 for each CLDFB bin in seconds */ - const Word32 *revEnes_fx, /* i : spectrum for reverberated sound at each CLDFB bin */ + const Word32 *revTimes_fx, /* i : reverberation times T60 for each CLDFB bin in seconds */ + const Word32 *revEnes_fx, /* i : spectrum for reverberated sound at each CLDFB bin */ const Word16 preDelay /* i : reverb pre-delay in CLDFB slots */ ) { Word16 bin, chIdx, k, len, scale, tmp; REVERB_STRUCT_HANDLE hReverb; - IF ( ( *hReverbPr = (REVERB_STRUCT_HANDLE) malloc( sizeof( REVERB_STRUCT ) ) ) == NULL ) + IF( ( *hReverbPr = (REVERB_STRUCT_HANDLE) malloc( sizeof( REVERB_STRUCT ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural Reverberator\n" ) ); } @@ -3893,24 +3899,24 @@ static ivas_error ivas_binaural_reverb_open_fx( hReverb->blockSize = numCldfbSlotsPerFrame; move16(); - FOR ( k = 0; k < REVERB_PREDELAY_MAX + 1; k++ ) + FOR( k = 0; k < REVERB_PREDELAY_MAX + 1; k++ ) { set32_fx( hReverb->preDelayBufferReal_fx[k], 0, hReverb->numBins ); set32_fx( hReverb->preDelayBufferImag_fx[k], 0, hReverb->numBins ); } - FOR ( bin = 0; bin < hReverb->numBins; bin++ ) + FOR( bin = 0; bin < hReverb->numBins; bin++ ) { /* Loop Buffer */ - tmp = BASOP_Util_Divide1616_Scale(500, add(bin, 1), &scale); - tmp = shr(tmp, sub( 15, scale) ); + tmp = BASOP_Util_Divide1616_Scale( 500, add( bin, 1 ), &scale ); + tmp = shr( tmp, sub( 15, scale ) ); hReverb->loopBufLengthMax[bin] = add( tmp, sub( CLDFB_NO_CHANNELS_MAX, bin ) ); - //hReverb->loopBufLengthMax[bin] = (Word16) ( 500 / ( 1 + bin ) + ( CLDFB_NO_CHANNELS_MAX - bin ) ); + // hReverb->loopBufLengthMax[bin] = (Word16) ( 500 / ( 1 + bin ) + ( CLDFB_NO_CHANNELS_MAX - bin ) ); len = add( hReverb->loopBufLengthMax[bin], hReverb->blockSize ); - IF ( ( hReverb->loopBufReal_fx[bin] = (Word32 *) malloc( len * sizeof( Word32 ) ) ) == NULL ) + IF( ( hReverb->loopBufReal_fx[bin] = (Word32 *) malloc( len * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural Reverberator\n" ) ); } @@ -3925,42 +3931,42 @@ static ivas_error ivas_binaural_reverb_open_fx( /* Determine loop buffer length. The following formula is manually tuned to generate sufficiently long * but not excessively long loops to generate reverberation. */ /* Note: the resulted length is very sensitive to the precision of the constants below (e.g. 1.45 vs. 1.45f) */ - //hReverb->loopBufLength[bin] = (int16_t) ( 1.45 * (int16_t) ( revTimes[bin] * 150.0 ) + 1 ); + // hReverb->loopBufLength[bin] = (int16_t) ( 1.45 * (int16_t) ( revTimes[bin] * 150.0 ) + 1 ); Word32 L_tmp_BufLength = L_shl( L_shr( Mpy_32_32( revTimes_fx[bin], 1258291200 /*150.0 in Q23*/ ), 23 ), 23 ); L_tmp_BufLength = L_add( Mpy_32_32( 1556925645 /*1.45 in Q30*/, L_tmp_BufLength ), ONE_IN_Q22 ); hReverb->loopBufLength[bin] = (Word16) L_shr( L_tmp_BufLength, 22 ); hReverb->loopBufLength[bin] = s_min( hReverb->loopBufLength[bin], hReverb->loopBufLengthMax[bin] ); /* Sparse Filter Tap Locations */ - FOR ( chIdx = 0; chIdx < BINAURAL_CHANNELS; chIdx++ ) + FOR( chIdx = 0; chIdx < BINAURAL_CHANNELS; chIdx++ ) { len = hReverb->loopBufLength[bin]; move16(); - IF ( ( hReverb->tapPhaseShiftType[bin][chIdx] = (Word16 *) malloc( len * sizeof( Word16 ) ) ) == NULL ) + IF( ( hReverb->tapPhaseShiftType[bin][chIdx] = (Word16 *) malloc( len * sizeof( Word16 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural Reverberator\n" ) ); } set_s( hReverb->tapPhaseShiftType[bin][chIdx], 0, len ); - IF ( ( hReverb->tapPointersReal_fx[bin][chIdx] = (Word32 **) malloc( len * sizeof( Word32 * ) ) ) == NULL ) + IF( ( hReverb->tapPointersReal_fx[bin][chIdx] = (Word32 **) malloc( len * sizeof( Word32 * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural Reverberator\n" ) ); } - IF ( ( hReverb->tapPointersImag_fx[bin][chIdx] = (Word32 **) malloc( len * sizeof( Word32 * ) ) ) == NULL ) + IF( ( hReverb->tapPointersImag_fx[bin][chIdx] = (Word32 **) malloc( len * sizeof( Word32 * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural Reverberator\n" ) ); } len = hReverb->blockSize; move16(); - IF ( ( hReverb->outputBufferReal_fx[bin][chIdx] = (Word32 *) malloc( len * sizeof( Word32 ) ) ) == NULL ) + IF( ( hReverb->outputBufferReal_fx[bin][chIdx] = (Word32 *) malloc( len * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural Reverberator\n" ) ); } - IF ( ( hReverb->outputBufferImag_fx[bin][chIdx] = (Word32 *) malloc( len * sizeof( Word32 ) ) ) == NULL ) + IF( ( hReverb->outputBufferImag_fx[bin][chIdx] = (Word32 *) malloc( len * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural Reverberator\n" ) ); } @@ -4120,16 +4126,17 @@ static ivas_error ivas_binaural_reverb_open( } #ifdef IVAS_FLOAT_FIXED - Word32 *revTimes_fx = (Word32 *)malloc(sizeof(Word32) * hReverb->numBins); - Word32 *revEnes_fx = (Word32 *)malloc(sizeof(Word32) * hReverb->numBins); - FOR(int i = 0; i < hReverb->numBins; i++) { - revTimes_fx[i] = (Word32)(revTimes[i] * ONE_IN_Q31); - revEnes_fx[i] = (Word32)(revEnes[i] * ONE_IN_Q31); + Word32 *revTimes_fx = (Word32 *) malloc( sizeof( Word32 ) * hReverb->numBins ); + Word32 *revEnes_fx = (Word32 *) malloc( sizeof( Word32 ) * hReverb->numBins ); + FOR( int i = 0; i < hReverb->numBins; i++ ) + { + revTimes_fx[i] = (Word32) ( revTimes[i] * ONE_IN_Q31 ); + revEnes_fx[i] = (Word32) ( revEnes[i] * ONE_IN_Q31 ); } ivas_binaural_reverb_setReverbTimes_fx( hReverb, sampling_rate, revTimes_fx, revEnes_fx ); - free(revTimes_fx); - free(revEnes_fx); + free( revTimes_fx ); + free( revEnes_fx ); #else ivas_binaural_reverb_setReverbTimes( hReverb, sampling_rate, revTimes, revEnes ); #endif @@ -4152,11 +4159,11 @@ static ivas_error ivas_binaural_reverb_open( #ifdef IVAS_FLOAT_FIXED ivas_error ivas_binaural_reverb_open_fastconv_fx( REVERB_STRUCT_HANDLE *hReverbPr, /* i/o: binaural reverb handle */ - const Word16 numBins, /* i : number of CLDFB bins */ - const Word16 numCldfbSlotsPerFrame, /* i : number of CLDFB slots per frame */ + const Word16 numBins, /* i : number of CLDFB bins */ + const Word16 numCldfbSlotsPerFrame, /* i : number of CLDFB slots per frame */ IVAS_ROOM_ACOUSTICS_CONFIG_DATA *roomAcoustics, /* i/o: room acoustics parameters */ const AUDIO_CONFIG internal_config, /* i : internal audio config for FastConv */ - const Word32 sampling_rate, /* i : sampling rate */ + const Word32 sampling_rate, /* i : sampling rate */ const HRTFS_FASTCONV_HANDLE hHrtfFastConv /* i : FastConv HRTF handle */ ) { @@ -4169,20 +4176,20 @@ ivas_error ivas_binaural_reverb_open_fastconv_fx( error = IVAS_ERR_OK; - IF ( ( roomAcoustics != NULL ) && roomAcoustics->override ) + IF( ( roomAcoustics != NULL ) && roomAcoustics->override ) { /* THIS PART IS YET TO BE CONVERTED AS REVERB_UTILS.C IS NOT INVOKED IN GPROF */ float t60_flt[CLDFB_NO_CHANNELS_MAX]; float ene_flt[CLDFB_NO_CHANNELS_MAX]; revTimes = t60; revEne = ene; - if ( ( error = ivas_reverb_prepare_cldfb_params( roomAcoustics, hHrtfFastConv, internal_config, false, sampling_rate, t60_flt, ene_flt) ) != IVAS_ERR_OK ) + if ( ( error = ivas_reverb_prepare_cldfb_params( roomAcoustics, hHrtfFastConv, internal_config, false, sampling_rate, t60_flt, ene_flt ) ) != IVAS_ERR_OK ) { return error; } preDelay = (Word16) roundf( 48000.0f * roomAcoustics->acousticPreDelay / CLDFB_NO_CHANNELS_MAX ); - floatToFixed_arrL(t60_flt, t60, Q31, CLDFB_NO_CHANNELS_MAX); - floatToFixed_arrL(ene_flt, ene, Q31, CLDFB_NO_CHANNELS_MAX); + floatToFixed_arrL( t60_flt, t60, Q31, CLDFB_NO_CHANNELS_MAX ); + floatToFixed_arrL( ene_flt, ene, Q31, CLDFB_NO_CHANNELS_MAX ); } ELSE { @@ -4247,8 +4254,8 @@ ivas_error ivas_binaural_reverb_open_fastconv( #ifdef IVAS_FLOAT_FIXED ivas_error ivas_binaural_reverb_open_parambin( REVERB_STRUCT_HANDLE *hReverbPr, /* i/o: binaural reverb handle */ - const Word16 numBins, /* i : number of CLDFB bins */ - const Word16 numCldfbSlotsPerFrame, /* i : number of CLDFB slots per frame */ + const Word16 numBins, /* i : number of CLDFB bins */ + const Word16 numCldfbSlotsPerFrame, /* i : number of CLDFB slots per frame */ IVAS_ROOM_ACOUSTICS_CONFIG_DATA *roomAcoustics, /* i/o: room acoustics parameters */ const int32_t sampling_rate, /* i : sampling rate */ const HRTFS_PARAMBIN_HANDLE hHrtfParambin /* i : Parametric binauralizer HRTF handle */ @@ -4263,7 +4270,7 @@ ivas_error ivas_binaural_reverb_open_parambin( error = IVAS_ERR_OK; - IF ( ( roomAcoustics != NULL ) && roomAcoustics->override ) + IF( ( roomAcoustics != NULL ) && roomAcoustics->override ) { revTimes = t60; revEne = ene; @@ -4272,8 +4279,8 @@ ivas_error ivas_binaural_reverb_open_parambin( // { // return error; // } - //preDelay = (int16_t) roundf( 48000.0f * roomAcoustics->acousticPreDelay / CLDFB_NO_CHANNELS_MAX ); - preDelay = (Word16) L_shr_r(Mpy_32_32(1677721600 /*800 in Q21*/, roomAcoustics->acousticPreDelay_fx /*Q27*/ ), Q17); + // preDelay = (int16_t) roundf( 48000.0f * roomAcoustics->acousticPreDelay / CLDFB_NO_CHANNELS_MAX ); + preDelay = (Word16) L_shr_r( Mpy_32_32( 1677721600 /*800 in Q21*/, roomAcoustics->acousticPreDelay_fx /*Q27*/ ), Q17 ); } ELSE { diff --git a/lib_rend/ivas_reverb_delay_line.c b/lib_rend/ivas_reverb_delay_line.c index 929597973..bb55a95ca 100644 --- a/lib_rend/ivas_reverb_delay_line.c +++ b/lib_rend/ivas_reverb_delay_line.c @@ -52,15 +52,15 @@ void ivas_rev_delay_line_init( ivas_rev_delay_line_t *pDelay, /* o : the delay line to initialize */ - Word32 *memory_buffer, /* i : the memory buffer to use for the delay line */ - const UWord16 delay, /* i : the delay */ - const UWord16 maxdelay /* i : maximum delay to be supported */ + Word32 *memory_buffer, /* i : the memory buffer to use for the delay line */ + const UWord16 delay, /* i : the delay */ + const UWord16 maxdelay /* i : maximum delay to be supported */ ) { pDelay->MaxDelay = maxdelay; move16(); - IF ( LE_32(delay , pDelay->MaxDelay) ) + IF( LE_32( delay, pDelay->MaxDelay ) ) { pDelay->Delay = delay; } @@ -89,13 +89,13 @@ void ivas_rev_delay_line_init( void ivas_rev_delay_line_feed_sample_fx( ivas_rev_delay_line_t *pDelay, /* i : the delay line */ - Word32 input /* i : the sample to feed */ + Word32 input /* i : the sample to feed */ ) { pDelay->pBuffer_fx[pDelay->BufferPos++] = input; move32(); - IF ( GE_32(pDelay->BufferPos , pDelay->Delay) ) + IF( GE_32( pDelay->BufferPos, pDelay->Delay ) ) { pDelay->BufferPos = 0; move16(); @@ -226,8 +226,8 @@ void ivas_rev_delay_line_feed_sample_blk( void ivas_rev_delay_line_feed_sample_blk_fx( ivas_rev_delay_line_t *pDelay, /* i/o: the delay line */ - const UWord16 blk_size, /* i : number of samples in the input data block */ - Word32 *input /* i : the samples to feed */ + const UWord16 blk_size, /* i : number of samples in the input data block */ + Word32 *input /* i : the samples to feed */ ) { Word32 *pDst, *pSrc; @@ -236,22 +236,22 @@ void ivas_rev_delay_line_feed_sample_blk_fx( pos = (UWord16) pDelay->BufferPos; move16(); - IF ( GT_32(L_add(pos , blk_size) , pDelay->Delay) ) /* splitting block in 2 if it exceeds buffer end limit */ + IF( GT_32( L_add( pos, blk_size ), pDelay->Delay ) ) /* splitting block in 2 if it exceeds buffer end limit */ { - UWord16 blk_size_1; /* 1st block up to the end of the buffer */ - UWord16 blk_size_2; /* 2nd block at the beginning of the buffer */ + UWord16 blk_size_1; /* 1st block up to the end of the buffer */ + UWord16 blk_size_2; /* 2nd block at the beginning of the buffer */ - blk_size_1 = (UWord16) L_sub(pDelay->Delay , pos); - blk_size_2 = (UWord16) L_sub(blk_size , blk_size_1); + blk_size_1 = (UWord16) L_sub( pDelay->Delay, pos ); + blk_size_2 = (UWord16) L_sub( blk_size, blk_size_1 ); pDst = &pDelay->pBuffer_fx[pos]; - FOR ( i = 0; i < blk_size_1; i++ ) + FOR( i = 0; i < blk_size_1; i++ ) { pDst[i] = input[i]; move32(); } pDst = &pDelay->pBuffer_fx[0]; pSrc = &input[blk_size_1]; - FOR ( i = 0; i < blk_size_2; i++ ) + FOR( i = 0; i < blk_size_2; i++ ) { pDst[i] = pSrc[i]; move32(); @@ -262,17 +262,17 @@ void ivas_rev_delay_line_feed_sample_blk_fx( ELSE /* copy only 1 data block directly if it fits in the buffer */ { pDst = &pDelay->pBuffer_fx[pos]; - FOR ( i = 0; i < blk_size; i++ ) + FOR( i = 0; i < blk_size; i++ ) { pDst[i] = input[i]; move32(); } - pos = (UWord16)L_add(pos,blk_size); + pos = (UWord16) L_add( pos, blk_size ); } pDelay->BufferPos = pos; move16(); - IF ( GE_32(pDelay->BufferPos , pDelay->Delay) ) + IF( GE_32( pDelay->BufferPos, pDelay->Delay ) ) { pDelay->BufferPos = 0; move16(); @@ -292,7 +292,7 @@ Word32 ivas_rev_delay_line_get_sample_fx( ivas_rev_delay_line_t *pDelay /* i/o: the delay line */ ) { - IF ( EQ_16(pDelay->Gain_fx , ONE_IN_Q14) ) + IF( EQ_16( pDelay->Gain_fx, ONE_IN_Q14 ) ) { return pDelay->pBuffer_fx[pDelay->BufferPos]; @@ -300,7 +300,7 @@ Word32 ivas_rev_delay_line_get_sample_fx( ELSE { - return (L_shl(Mpy_32_16_r( pDelay->pBuffer_fx[pDelay->BufferPos], pDelay->Gain_fx) , 1)); + return ( L_shl( Mpy_32_16_r( pDelay->pBuffer_fx[pDelay->BufferPos], pDelay->Gain_fx ), 1 ) ); } } /*-----------------------------------------------------------------------------------------* @@ -311,8 +311,8 @@ Word32 ivas_rev_delay_line_get_sample_fx( void ivas_rev_delay_line_get_sample_blk_fx( ivas_rev_delay_line_t *pDelay, /* i : the delay line */ - const UWord16 blk_size, /* i : number of samples in the data block */ - Word32 *output /* i/o: amples gotten out of delay line, and amplified by set gainin */ + const UWord16 blk_size, /* i : number of samples in the data block */ + Word32 *output /* i/o: amples gotten out of delay line, and amplified by set gainin */ ) { Word32 *pDst, *pSrc; @@ -324,24 +324,24 @@ void ivas_rev_delay_line_get_sample_blk_fx( move16(); move16(); - IF ( GT_32(L_add(pos , blk_size) , pDelay->Delay) ) /* splitting block in 2 if it exceeds buffer end limit */ + IF( GT_32( L_add( pos, blk_size ), pDelay->Delay ) ) /* splitting block in 2 if it exceeds buffer end limit */ { - UWord16 blk_size_1; /* 1st block up to the end of the buffer */ - UWord16 blk_size_2; /* 2nd block at the beginning of the buffer */ + UWord16 blk_size_1; /* 1st block up to the end of the buffer */ + UWord16 blk_size_2; /* 2nd block at the beginning of the buffer */ - blk_size_1 = (UWord16)L_sub(pDelay->Delay , pos); - blk_size_2 = (UWord16)L_sub(blk_size , blk_size_1); + blk_size_1 = (UWord16) L_sub( pDelay->Delay, pos ); + blk_size_2 = (UWord16) L_sub( blk_size, blk_size_1 ); pSrc = &pDelay->pBuffer_fx[pos]; - IF ( EQ_16(gain , ONE_IN_Q14) ) + IF( EQ_16( gain, ONE_IN_Q14 ) ) { - FOR ( i = 0; i < blk_size_1; i++ ) + FOR( i = 0; i < blk_size_1; i++ ) { output[i] = pSrc[i]; move32(); } pSrc = &pDelay->pBuffer_fx[0]; pDst = &output[blk_size_1]; - FOR ( i = 0; i < blk_size_2; i++ ) + FOR( i = 0; i < blk_size_2; i++ ) { pDst[i] = pSrc[i]; move32(); @@ -349,15 +349,15 @@ void ivas_rev_delay_line_get_sample_blk_fx( } ELSE { - FOR ( i = 0; i < blk_size_1; i++ ) + FOR( i = 0; i < blk_size_1; i++ ) { - output[i] = L_shl(Mpy_32_16_r( pSrc[i],gain ) , 1); + output[i] = L_shl( Mpy_32_16_r( pSrc[i], gain ), 1 ); } pSrc = &pDelay->pBuffer_fx[0]; pDst = &output[blk_size_1]; - FOR ( i = 0; i < blk_size_2; i++ ) + FOR( i = 0; i < blk_size_2; i++ ) { - pDst[i] = L_shl(Mpy_32_16_r(pSrc[i],gain ) , 1); + pDst[i] = L_shl( Mpy_32_16_r( pSrc[i], gain ), 1 ); } } } @@ -365,9 +365,9 @@ void ivas_rev_delay_line_get_sample_blk_fx( { pSrc = &pDelay->pBuffer_fx[pos]; - IF ( EQ_16(gain , ONE_IN_Q14) ) + IF( EQ_16( gain, ONE_IN_Q14 ) ) { - FOR ( i = 0; i < blk_size; i++ ) + FOR( i = 0; i < blk_size; i++ ) { output[i] = pSrc[i]; move32(); @@ -375,9 +375,9 @@ void ivas_rev_delay_line_get_sample_blk_fx( } ELSE { - FOR ( i = 0; i < blk_size; i++ ) + FOR( i = 0; i < blk_size; i++ ) { - output[i] = L_shl(Mpy_32_16_r( pSrc[i], gain ) , 1); + output[i] = L_shl( Mpy_32_16_r( pSrc[i], gain ), 1 ); } } } @@ -430,8 +430,8 @@ void ivas_rev_delay_line_get_sample_blk( if ( pos + blk_size > (uint16_t) pDelay->Delay ) /* splitting block in 2 if it exceeds buffer end limit */ { - uint16_t blk_size_1; /* 1st block up to the end of the buffer */ - uint16_t blk_size_2; /* 2nd block at the beginning of the buffer */ + uint16_t blk_size_1; /* 1st block up to the end of the buffer */ + uint16_t blk_size_2; /* 2nd block at the beginning of the buffer */ blk_size_1 = (uint16_t) pDelay->Delay - pos; blk_size_2 = blk_size - blk_size_1; @@ -486,5 +486,3 @@ void ivas_rev_delay_line_get_sample_blk( return; } #endif - - diff --git a/lib_rend/ivas_reverb_fft_filter.c b/lib_rend/ivas_reverb_fft_filter.c index 2d029c04c..5a734186b 100644 --- a/lib_rend/ivas_reverb_fft_filter.c +++ b/lib_rend/ivas_reverb_fft_filter.c @@ -233,14 +233,14 @@ static void ifft_wrapper_2ch_fx( buffer_R_re = buffer_R[k]; buffer_R_im = buffer_R[mirror_k]; - buffer_L[k] = L_add(buffer_L_re , buffer_R_im); - buffer_L[mirror_k] = L_sub(buffer_L_re , buffer_R_im); - buffer_R[k] = L_sub(buffer_R_re , buffer_L_im); - buffer_R[mirror_k] = L_add(buffer_R_re , buffer_L_im); + buffer_L[k] = L_add( buffer_L_re, buffer_R_im ); + buffer_L[mirror_k] = L_sub( buffer_L_re, buffer_R_im ); + buffer_R[k] = L_sub( buffer_R_re, buffer_L_im ); + buffer_R[mirror_k] = L_add( buffer_R_re, buffer_L_im ); } - + DoRTFTn_fx_ivas( buffer_L, buffer_R, fft_size ); - + return; } #else @@ -448,9 +448,8 @@ void ivas_reverb_t2f_f2t_in_fx( pR = &buffer_R[hlen]; for ( i = 0; i < bsiz; i++ ) { - pL[i] = input_L[i] ; - pR[i] = input_R[i] ; - + pL[i] = input_L[i]; + pR[i] = input_R[i]; } /* copy buffer to history */ @@ -641,7 +640,7 @@ void ivas_reverb_fft_filter_ComplexMul_fx( buffer[0] = Mpy_32_32( spec[0], buffer[0] ); /* real multiply f0 DC */ buffer[h] = Mpy_32_32( spec[h], buffer[h] ); /* real multiply f_spec Nyquist */ j = f_spec - 1; - for ( i = 1; i < h; i++ ) /*actual complex multiply in loop */ + for ( i = 1; i < h; i++ ) /*actual complex multiply in loop */ { t = buffer[i]; buffer[i] = L_sub( Mpy_32_32( t, spec[i] ), Mpy_32_32( buffer[j], spec[j] ) ); @@ -670,8 +669,8 @@ void ivas_reverb_fft_filter_ComplexMul( h = f_spec >> 1; spec = fft_filter->fft_spectrum; - buffer[0] *= spec[0]; /* real multiply f0 DC */ - buffer[h] *= spec[h]; /* real multiply f_spec Nyquist */ + buffer[0] *= spec[0]; /* real multiply f0 DC */ + buffer[h] *= spec[h]; /* real multiply f_spec Nyquist */ j = f_spec - 1; for ( i = 1; i < h; i++ ) /*actual complex multiply in loop */ { @@ -697,7 +696,7 @@ void ivas_reverb_fft_filter_ConvertFFTWF_2_FFTR_fx( { Word16 i, h; - h = shr(fft_size , 1); + h = shr( fft_size, 1 ); fft_real[0] = spectrum[0][0]; fft_real[h] = spectrum[h][0]; for ( i = 1; i < h; i++ ) @@ -747,8 +746,8 @@ void ivas_reverb_fft_filter_CrossMix_fx( for ( i = 0; i < fft_size; i++ ) { t = buffer0[i]; - buffer0[i] = L_add(t , buffer1[i]); - buffer1[i] = L_sub(t , buffer1[i]); + buffer0[i] = L_add( t, buffer1[i] ); + buffer1[i] = L_sub( t, buffer1[i] ); } return; @@ -776,4 +775,4 @@ void ivas_reverb_fft_filter_CrossMix( } return; -} \ No newline at end of file +} diff --git a/lib_rend/ivas_reverb_filter_design.c b/lib_rend/ivas_reverb_filter_design.c index a4a09dd4c..dd6f2bb2d 100644 --- a/lib_rend/ivas_reverb_filter_design.c +++ b/lib_rend/ivas_reverb_filter_design.c @@ -46,12 +46,12 @@ * Local constants *------------------------------------------------------------------------------------------*/ -#define STEP_LIMIT_PIVOT_FREQ ( 1000.0f ) /* Pivot (initial reference) frequency for response gradient limit */ -#define RESPONSE_STEP_LIMIT_LF ( 4.0f ) /* Maximum step in dB per bin at low frequencies (< pivot frequency) */ -#define RESPONSE_STEP_LIMIT_LF_FX ( 536870912 ) /* Maximum step in dB per bin at low frequencies (< pivot frequency) */ -#define RESPONSE_STEP_LIMIT_HF ( 1.5f ) /* Maximum step in dB per bin at high frequencies (> pivot frequency) */ -#define RESPONSE_STEP_LIMIT_HF_FX ( 1610612736 ) /* Maximum step in dB per bin at high frequencies (> pivot frequency) */ -#define EPS ( 1e-30f ) +#define STEP_LIMIT_PIVOT_FREQ ( 1000.0f ) /* Pivot (initial reference) frequency for response gradient limit */ +#define RESPONSE_STEP_LIMIT_LF ( 4.0f ) /* Maximum step in dB per bin at low frequencies (< pivot frequency) */ +#define RESPONSE_STEP_LIMIT_LF_FX ( 536870912 ) /* Maximum step in dB per bin at low frequencies (< pivot frequency) */ +#define RESPONSE_STEP_LIMIT_HF ( 1.5f ) /* Maximum step in dB per bin at high frequencies (> pivot frequency) */ +#define RESPONSE_STEP_LIMIT_HF_FX ( 1610612736 ) /* Maximum step in dB per bin at high frequencies (> pivot frequency) */ +#define EPS ( 1e-30f ) /*------------------------------------------------------------------------------------------* @@ -194,101 +194,103 @@ static void calc_min_phase( #endif #ifdef IVAS_FLOAT_FIXED static void calc_min_phase_fx( - rv_fftwf_type_complex_fx *pSpectrum, - const Word16 fft_size, - Word32 *pMinPhase, - Word16 *q_pCepstrum -) + rv_fftwf_type_complex_fx *pSpectrum, + const Word16 fft_size, + Word32 *pMinPhase, + Word16 *q_pCepstrum ) { - Word16 idx; - const Word16 half_fft_size = shr(fft_size, 1); - const Word16 log2_fft_size = int_log2(fft_size); - const Word16 spectrum_size = add(half_fft_size, 1); - const Word16 cepstrum_smoothing_extent = shr(fft_size, 3); - - Word32 pCepstrum[RV_FILTER_MAX_FFT_SIZE]; - Word32 pFolded_cepstrum_re[RV_FILTER_MAX_FFT_SIZE]; - Word32 pFolded_cepstrum_im[RV_FILTER_MAX_FFT_SIZE]; - Word32 pFolded_cepstrum_smoothing_win[RV_FILTER_MAX_FFT_SIZE]; - Word16 angle_increment; - Word16 initial_angle; - Word32 scale_factor; - - IF(EQ_16(fft_size, 512)) - { - scale_factor = 4194304; /* q = 31, 1.0f / (float)512 */ - move32(); - } - ELSE - { - scale_factor = 8388608; /* q = 31, 1.0f / (float)256 */ - move32(); - } - + Word16 idx; + const Word16 half_fft_size = shr( fft_size, 1 ); + const Word16 log2_fft_size = int_log2( fft_size ); + const Word16 spectrum_size = add( half_fft_size, 1 ); + const Word16 cepstrum_smoothing_extent = shr( fft_size, 3 ); + + Word32 pCepstrum[RV_FILTER_MAX_FFT_SIZE]; + Word32 pFolded_cepstrum_re[RV_FILTER_MAX_FFT_SIZE]; + Word32 pFolded_cepstrum_im[RV_FILTER_MAX_FFT_SIZE]; + Word32 pFolded_cepstrum_smoothing_win[RV_FILTER_MAX_FFT_SIZE]; + Word16 angle_increment; + Word16 initial_angle; + Word32 scale_factor; + + IF( EQ_16( fft_size, 512 ) ) + { + scale_factor = 4194304; /* q = 31, 1.0f / (float)512 */ + move32(); + } + ELSE + { + scale_factor = 8388608; /* q = 31, 1.0f / (float)256 */ + move32(); + } - /* Prepare the smoothing window. Portion of the pCepstrum that will be smoothed out by a window to prevent aliasing. */ - /* The first portion of the pCepstrum is kept unchanged */ - FOR(idx = 0; idx < half_fft_size - cepstrum_smoothing_extent; idx++) - { - pFolded_cepstrum_smoothing_win[idx] = ONE_IN_Q31; move32(); - } + /* Prepare the smoothing window. Portion of the pCepstrum that will be smoothed out by a window to prevent aliasing. */ - /* Adding Hann half-window for smooth transition */ + /* The first portion of the pCepstrum is kept unchanged */ + FOR( idx = 0; idx < half_fft_size - cepstrum_smoothing_extent; idx++ ) + { + pFolded_cepstrum_smoothing_win[idx] = ONE_IN_Q31; + move32(); + } - Word16 s1 = sub(norm_s(shr(EVS_PI_FX, 1)), 1); - Word16 s2 = norm_s(sub(shl(cepstrum_smoothing_extent, 1), 1)); - Word16 var1 = shl(EVS_PI_FX, s1); - Word16 var2 = shl(sub(shl(cepstrum_smoothing_extent, 1), 1), s2); - angle_increment = div_s(shr(var1, 5), var2); //q = 15 + /* Adding Hann half-window for smooth transition */ - /* Initial angle set to match Hann window alignment in Matlab */ + Word16 s1 = sub( norm_s( shr( EVS_PI_FX, 1 ) ), 1 ); + Word16 s2 = norm_s( sub( shl( cepstrum_smoothing_extent, 1 ), 1 ) ); + Word16 var1 = shl( EVS_PI_FX, s1 ); + Word16 var2 = shl( sub( shl( cepstrum_smoothing_extent, 1 ), 1 ), s2 ); + angle_increment = div_s( shr( var1, 5 ), var2 ); // q = 15 - initial_angle = shr(add((EVS_PI_FX), shr(angle_increment, 2)), 1); // q = 13 + /* Initial angle set to match Hann window alignment in Matlab */ - FOR(idx = 0; idx < cepstrum_smoothing_extent; idx++) - { - const Word16 sine_value = getSineWord16R2(mult(add(initial_angle, shl(mult(shl(idx, 8), angle_increment), 5)), 20858)); + initial_angle = shr( add( ( EVS_PI_FX ), shr( angle_increment, 2 ) ), 1 ); // q = 13 - pFolded_cepstrum_smoothing_win[idx + half_fft_size - cepstrum_smoothing_extent] = L_mult(sine_value, sine_value); //q31 - } + FOR( idx = 0; idx < cepstrum_smoothing_extent; idx++ ) + { + const Word16 sine_value = getSineWord16R2( mult( add( initial_angle, shl( mult( shl( idx, 8 ), angle_increment ), 5 ) ), 20858 ) ); - /* Padding the rest with zeros */ - FOR(idx = half_fft_size; idx < fft_size; idx++) - { - pFolded_cepstrum_smoothing_win[idx] = 0; move32(); - } + pFolded_cepstrum_smoothing_win[idx + half_fft_size - cepstrum_smoothing_extent] = L_mult( sine_value, sine_value ); // q31 + } - /* Compute the log amplitude spectrum */ - FOR(idx = 0; idx < spectrum_size; idx++) - { - pCepstrum[idx] = Mpy_32_32(L_add(BASOP_Util_Log2(L_add(Mpy_32_32(pSpectrum[idx][0], pSpectrum[idx][0]), Mpy_32_32(pSpectrum[idx][1], pSpectrum[idx][1]))), L_shl(0, 25)), LN_2_Q31); /* log2 = 0.693147, q = 31, value = 1488521848 */ //q =26 - } + /* Padding the rest with zeros */ + FOR( idx = half_fft_size; idx < fft_size; idx++ ) + { + pFolded_cepstrum_smoothing_win[idx] = 0; + move32(); + } - /* Extending one-sided spectrum to double-sided one */ - FOR(idx = spectrum_size; idx < fft_size; idx++) - { - pCepstrum[idx] = pCepstrum[fft_size - idx]; move32(); - } - Word16 guarded_bits; - guarded_bits = find_guarded_bits_fx(fft_size); - *q_pCepstrum = sub(L_norm_arr(pCepstrum, fft_size), guarded_bits); + /* Compute the log amplitude spectrum */ + FOR( idx = 0; idx < spectrum_size; idx++ ) + { + pCepstrum[idx] = Mpy_32_32( L_add( BASOP_Util_Log2( L_add( Mpy_32_32( pSpectrum[idx][0], pSpectrum[idx][0] ), Mpy_32_32( pSpectrum[idx][1], pSpectrum[idx][1] ) ) ), L_shl( 0, 25 ) ), LN_2_Q31 ); /* log2 = 0.693147, q = 31, value = 1488521848 */ // q =26 + } - FOR(Word16 j = 0; j < fft_size; j++) - { - pCepstrum[j] = L_shl(pCepstrum[j], *q_pCepstrum); - } - *q_pCepstrum = add(*q_pCepstrum,26); - /* Compute the real pCepstrum of the log amplitude spectrum */ - fft_rel_fx32(pCepstrum, fft_size, log2_fft_size); + /* Extending one-sided spectrum to double-sided one */ + FOR( idx = spectrum_size; idx < fft_size; idx++ ) + { + pCepstrum[idx] = pCepstrum[fft_size - idx]; + move32(); + } + Word16 guarded_bits; + guarded_bits = find_guarded_bits_fx( fft_size ); + *q_pCepstrum = sub( L_norm_arr( pCepstrum, fft_size ), guarded_bits ); - /* Note: using real-input fft rather than cmplx ifft to ensure support for 1024 size */ - /* Extra scaling is though required on the real/img parts, and img part is later inverted */ + FOR( Word16 j = 0; j < fft_size; j++ ) + { + pCepstrum[j] = L_shl( pCepstrum[j], *q_pCepstrum ); + } + *q_pCepstrum = add( *q_pCepstrum, 26 ); + /* Compute the real pCepstrum of the log amplitude spectrum */ + fft_rel_fx32( pCepstrum, fft_size, log2_fft_size ); - FOR(idx = 0; idx < fft_size; idx++) - { - pCepstrum[idx] = Mpy_32_32(pCepstrum[idx], scale_factor); //q = q_pCepstrum - } + /* Note: using real-input fft rather than cmplx ifft to ensure support for 1024 size */ + /* Extra scaling is though required on the real/img parts, and img part is later inverted */ + + FOR( idx = 0; idx < fft_size; idx++ ) + { + pCepstrum[idx] = Mpy_32_32( pCepstrum[idx], scale_factor ); // q = q_pCepstrum + } #if 0 guarded_bits = L_norm_arr(pCepstrum, fft_size); FOR(Word16 j = 0; j < fft_size; j++) @@ -297,69 +299,76 @@ static void calc_min_phase_fx( } q_pCepstrum += guarded_bits - 3; #endif - /* Fold the pCepstrum to ensure that zeros outside the unit circle move inside it, making it minimum phase. */ - pFolded_cepstrum_re[0] = pCepstrum[0]; move32(); - pFolded_cepstrum_im[0] = 0; move32(); + /* Fold the pCepstrum to ensure that zeros outside the unit circle move inside it, making it minimum phase. */ + pFolded_cepstrum_re[0] = pCepstrum[0]; + move32(); + pFolded_cepstrum_im[0] = 0; + move32(); - FOR(idx = 1; idx < half_fft_size; idx++) - { - pFolded_cepstrum_re[idx] = L_shl(pCepstrum[idx], 1);//q = q_pCepstrum - pFolded_cepstrum_im[idx] = L_negate(L_shl(pCepstrum[fft_size - idx], 1));//q = q_pCepstrum - /* Note: sign inverted because of fft rather than ifft used before */ - } - pFolded_cepstrum_re[half_fft_size] = pCepstrum[half_fft_size]; //q = q_pCepstrum - move32(); - pFolded_cepstrum_im[half_fft_size] = 0; - move32(); + FOR( idx = 1; idx < half_fft_size; idx++ ) + { + pFolded_cepstrum_re[idx] = L_shl( pCepstrum[idx], 1 ); // q = q_pCepstrum + pFolded_cepstrum_im[idx] = L_negate( L_shl( pCepstrum[fft_size - idx], 1 ) ); // q = q_pCepstrum + /* Note: sign inverted because of fft rather than ifft used before */ + } + pFolded_cepstrum_re[half_fft_size] = pCepstrum[half_fft_size]; // q = q_pCepstrum + move32(); + pFolded_cepstrum_im[half_fft_size] = 0; + move32(); - FOR(idx = spectrum_size; idx < fft_size; idx++) - { - pFolded_cepstrum_re[idx] = 0; move32(); - pFolded_cepstrum_im[idx] = 0; move32(); - } + FOR( idx = spectrum_size; idx < fft_size; idx++ ) + { + pFolded_cepstrum_re[idx] = 0; + move32(); + pFolded_cepstrum_im[idx] = 0; + move32(); + } - /* Smoothing out the folded pCepstrum, to remove discontinuity at Ns, - hoping to significantly reduce the secondary response in the minimum-phase IR */ - FOR(idx = 0; idx < fft_size; idx++) - { - pFolded_cepstrum_re[idx] = Mpy_32_32(pFolded_cepstrum_re[idx], pFolded_cepstrum_smoothing_win[idx]); // q = q_pCepstrum - pFolded_cepstrum_im[idx] = Mpy_32_32(pFolded_cepstrum_im[idx], pFolded_cepstrum_smoothing_win[idx]); // q = q_pCepstrum - } + /* Smoothing out the folded pCepstrum, to remove discontinuity at Ns, + hoping to significantly reduce the secondary response in the minimum-phase IR */ + FOR( idx = 0; idx < fft_size; idx++ ) + { + pFolded_cepstrum_re[idx] = Mpy_32_32( pFolded_cepstrum_re[idx], pFolded_cepstrum_smoothing_win[idx] ); // q = q_pCepstrum + pFolded_cepstrum_im[idx] = Mpy_32_32( pFolded_cepstrum_im[idx], pFolded_cepstrum_smoothing_win[idx] ); // q = q_pCepstrum + } - /* Convert back and isolate the phase. */ - IF(LE_16(fft_size, 512)) /* for size <= 512 using complex-value FFT (more effecient, but available only up to 512 size) */ - { - DoRTFTn_fx_ivas(pFolded_cepstrum_re, pFolded_cepstrum_im, fft_size); - //guarded_bits = L_norm_arr(pFolded_cepstrum_im, fft_size); + /* Convert back and isolate the phase. */ + IF( LE_16( fft_size, 512 ) ) /* for size <= 512 using complex-value FFT (more effecient, but available only up to 512 size) */ + { + DoRTFTn_fx_ivas( pFolded_cepstrum_re, pFolded_cepstrum_im, fft_size ); + // guarded_bits = L_norm_arr(pFolded_cepstrum_im, fft_size); #if 0 FOR(Word16 j = 0; j < fft_size; j++) { pFolded_cepstrum_im[j] = L_shl(pFolded_cepstrum_im[j], 30 - *q_pCepstrum); } #endif - /* Copying the img part into the output */ - FOR(idx = 1; idx < half_fft_size; idx++) - { - pMinPhase[idx] = pFolded_cepstrum_im[idx]; move32(); + /* Copying the img part into the output */ + FOR( idx = 1; idx < half_fft_size; idx++ ) + { + pMinPhase[idx] = pFolded_cepstrum_im[idx]; + move32(); + } } - } - ELSE /* for fft_size > 512 using real-values FFT twice (for real + imag parts) */ - { - /* Real part */ - fft_rel_fx32(pFolded_cepstrum_re, fft_size, log2_fft_size); - /* Imag part */ - fft_rel_fx32(pFolded_cepstrum_im, fft_size, log2_fft_size); - - /* Copying the img part into the output */ - FOR(idx = 1; idx < half_fft_size; idx++) + ELSE /* for fft_size > 512 using real-values FFT twice (for real + imag parts) */ { - pMinPhase[idx] = L_add(pFolded_cepstrum_re[fft_size - idx], pFolded_cepstrum_im[idx]); + /* Real part */ + fft_rel_fx32( pFolded_cepstrum_re, fft_size, log2_fft_size ); + /* Imag part */ + fft_rel_fx32( pFolded_cepstrum_im, fft_size, log2_fft_size ); + + /* Copying the img part into the output */ + FOR( idx = 1; idx < half_fft_size; idx++ ) + { + pMinPhase[idx] = L_add( pFolded_cepstrum_re[fft_size - idx], pFolded_cepstrum_im[idx] ); + } } - } - pMinPhase[0] = 0; move32(); - pMinPhase[half_fft_size] = 0; move32(); + pMinPhase[0] = 0; + move32(); + pMinPhase[half_fft_size] = 0; + move32(); - return; + return; } #endif /*-------------------------------------------------------------------* @@ -404,37 +413,37 @@ static void calc_min_phase_filter( #ifdef IVAS_FLOAT_FIXED static void calc_min_phase_filter_fx( - rv_fftwf_type_complex_fx *pH_flt, - const Word16 fft_size, - Word16 delay) + rv_fftwf_type_complex_fx *pH_flt, + const Word16 fft_size, + Word16 delay ) { - const Word16 spectrum_size = add(shr(fft_size, 1), 1); - Word16 idx; - //Word16 phase_increment; - Word32 pMin_phase[RV_FILTER_MAX_FFT_SIZE]; - - //phase_increment = 0; - UNUSED_PARAM(delay); // delay is 0.0, -PI2 * delay / (float)fft_size; - move16(); - Word16 q_pMin_phase; - calc_min_phase_fx(pH_flt, fft_size, pMin_phase, &q_pMin_phase); - - FOR(idx = 0; idx < spectrum_size; idx++) - { - /* Cancel out initial phase by computing amplitude */ - /* Note: slightly different (but mathematically equivalent) approach used for better efficiency */ - Word16 exp = 0; //31-31 + const Word16 spectrum_size = add( shr( fft_size, 1 ), 1 ); + Word16 idx; + // Word16 phase_increment; + Word32 pMin_phase[RV_FILTER_MAX_FFT_SIZE]; + + // phase_increment = 0; + UNUSED_PARAM( delay ); // delay is 0.0, -PI2 * delay / (float)fft_size; move16(); - Word32 current_ampl = Sqrt32(L_add(Mpy_32_32(pH_flt[idx][0], pH_flt[idx][0]), Mpy_32_32(pH_flt[idx][1], pH_flt[idx][1])), &exp); // q = 31 -exp == 31 - current_ampl = L_shl(current_ampl, exp); - /* Using the phase computed by calc_min_phase() + additional delay */ + Word16 q_pMin_phase; + calc_min_phase_fx( pH_flt, fft_size, pMin_phase, &q_pMin_phase ); - /* Apply the computed phase */ - pH_flt[idx][0] = Mpy_32_16_1(current_ampl, getCosWord16R2(mult(abs_s((Word16)L_shr(pMin_phase[idx], sub(q_pMin_phase, 13))), 20858))); //shifting right for next function. - pH_flt[idx][1] = Mpy_32_16_1(current_ampl, getSineWord16R2(mult((Word16)L_shr(pMin_phase[idx], sub(q_pMin_phase, 13)), 20858))); - } + FOR( idx = 0; idx < spectrum_size; idx++ ) + { + /* Cancel out initial phase by computing amplitude */ + /* Note: slightly different (but mathematically equivalent) approach used for better efficiency */ + Word16 exp = 0; // 31-31 + move16(); + Word32 current_ampl = Sqrt32( L_add( Mpy_32_32( pH_flt[idx][0], pH_flt[idx][0] ), Mpy_32_32( pH_flt[idx][1], pH_flt[idx][1] ) ), &exp ); // q = 31 -exp == 31 + current_ampl = L_shl( current_ampl, exp ); + /* Using the phase computed by calc_min_phase() + additional delay */ - return; + /* Apply the computed phase */ + pH_flt[idx][0] = Mpy_32_16_1( current_ampl, getCosWord16R2( mult( abs_s( (Word16) L_shr( pMin_phase[idx], sub( q_pMin_phase, 13 ) ) ), 20858 ) ) ); // shifting right for next function. + pH_flt[idx][1] = Mpy_32_16_1( current_ampl, getSineWord16R2( mult( (Word16) L_shr( pMin_phase[idx], sub( q_pMin_phase, 13 ) ), 20858 ) ) ); + } + + return; } #endif /*-------------------------------------------------------------------* @@ -494,75 +503,82 @@ static void apply_window_fft( #endif #ifdef IVAS_FLOAT_FIXED static void apply_window_fft_fx( - rv_fftwf_type_complex_fx *pH_flt, - const Word32 *pWindow, - const Word16 fft_size, - Word16 *q_pFilter -) + rv_fftwf_type_complex_fx *pH_flt, + const Word32 *pWindow, + const Word16 fft_size, + Word16 *q_pFilter ) { - Word16 idx; - Word32 pFilter[RV_FILTER_MAX_FFT_SIZE]; - const Word16 half_fft_size = shr(fft_size, 1); - const Word16 log2_fft_size = int_log2(fft_size); - - /* Converting pFilter to ifft function input format */ - /* Real parts */ - FOR(idx = 0; idx <= half_fft_size; idx++) - { - pFilter[idx] = pH_flt[idx][0]; move32(); - } - /* Img parts */ - FOR(idx = 1; idx < half_fft_size; idx++) - { - pFilter[fft_size - idx] = pH_flt[idx][1]; move32(); - } - *q_pFilter = 31; - /* Do inverse fft to go to the time domain */ - Word16 guarded_bits, temp; - guarded_bits = find_guarded_bits_fx(fft_size); - temp = sub(L_norm_arr(pFilter, fft_size), guarded_bits); - IF(temp < 0) - { - FOR(Word16 j = 0; j < fft_size; j++) + Word16 idx; + Word32 pFilter[RV_FILTER_MAX_FFT_SIZE]; + const Word16 half_fft_size = shr( fft_size, 1 ); + const Word16 log2_fft_size = int_log2( fft_size ); + + /* Converting pFilter to ifft function input format */ + /* Real parts */ + FOR( idx = 0; idx <= half_fft_size; idx++ ) { - pFilter[j] = L_shl(pFilter[j], temp); + pFilter[idx] = pH_flt[idx][0]; + move32(); + } + /* Img parts */ + FOR( idx = 1; idx < half_fft_size; idx++ ) + { + pFilter[fft_size - idx] = pH_flt[idx][1]; + move32(); + } + *q_pFilter = 31; + /* Do inverse fft to go to the time domain */ + Word16 guarded_bits, temp; + guarded_bits = find_guarded_bits_fx( fft_size ); + temp = sub( L_norm_arr( pFilter, fft_size ), guarded_bits ); + IF( temp < 0 ) + { + FOR( Word16 j = 0; j < fft_size; j++ ) + { + pFilter[j] = L_shl( pFilter[j], temp ); + } + *q_pFilter = add( *q_pFilter, temp ); } - *q_pFilter = add(*q_pFilter, temp); - } - ifft_rel_fx32(pFilter, fft_size, log2_fft_size); + ifft_rel_fx32( pFilter, fft_size, log2_fft_size ); - /* Apply the window in the time domain */ - FOR(idx = 0; idx < fft_size; idx++) - { - pFilter[idx] = Mpy_32_32(pWindow[idx], pFilter[idx]); //q = q_pFilter + 30 - 31 - } - *q_pFilter = add(*q_pFilter, sub(30, 31)); - /* Convert back to the frequency domain */ - temp = sub(L_norm_arr(pFilter, fft_size), guarded_bits); - IF(LT_16(temp, 0)) - { - FOR(Word16 j = 0; j < fft_size; j++) + /* Apply the window in the time domain */ + FOR( idx = 0; idx < fft_size; idx++ ) { - pFilter[j] = L_shl(pFilter[j], temp); + pFilter[idx] = Mpy_32_32( pWindow[idx], pFilter[idx] ); // q = q_pFilter + 30 - 31 + } + *q_pFilter = add( *q_pFilter, sub( 30, 31 ) ); + /* Convert back to the frequency domain */ + temp = sub( L_norm_arr( pFilter, fft_size ), guarded_bits ); + IF( LT_16( temp, 0 ) ) + { + FOR( Word16 j = 0; j < fft_size; j++ ) + { + pFilter[j] = L_shl( pFilter[j], temp ); + } + *q_pFilter = add( *q_pFilter, temp ); } - *q_pFilter = add(*q_pFilter, temp); - } - fft_rel_fx32(pFilter, fft_size, log2_fft_size); //q = q_pFilter + fft_rel_fx32( pFilter, fft_size, log2_fft_size ); // q = q_pFilter - /* Copy data to the output with format conversion */ - pH_flt[0][0] = pFilter[0]; move32(); - pH_flt[half_fft_size][0] = pFilter[half_fft_size]; move32(); - pH_flt[0][1] = 0; move32(); - pH_flt[half_fft_size][1] = 0; move32(); - FOR(idx = 1; idx < half_fft_size; idx++) - { - pH_flt[idx][0] = pFilter[idx]; move32(); - pH_flt[idx][1] = pFilter[fft_size - idx]; move32(); - } + /* Copy data to the output with format conversion */ + pH_flt[0][0] = pFilter[0]; + move32(); + pH_flt[half_fft_size][0] = pFilter[half_fft_size]; + move32(); + pH_flt[0][1] = 0; + move32(); + pH_flt[half_fft_size][1] = 0; + move32(); + FOR( idx = 1; idx < half_fft_size; idx++ ) + { + pH_flt[idx][0] = pFilter[idx]; + move32(); + pH_flt[idx][1] = pFilter[fft_size - idx]; + move32(); + } - return; + return; } #endif /*-------------------------------------------------------------------* @@ -635,90 +651,94 @@ static void response_step_limit( #else static void response_step_limit_fx( - Word32 *X, - const Word16 dim_x, - const Word32 step_limit_lf_dB, - const Word32 step_limit_hf_dB, - const Word16 pivot_bin_idx) + Word32 *X, + const Word16 dim_x, + const Word32 step_limit_lf_dB, + const Word32 step_limit_hf_dB, + const Word16 pivot_bin_idx ) { - Word16 i; - const Word32 positive_step_limit_lf = 1701766107; UNUSED_PARAM(step_limit_lf_dB); //powf(10.0f, 0.05f * step_limit_lf_dB) = 1.5848931924611134852; //q = 30 - const Word32 negative_step_limit_lf = 677485289; // 1.0f / positive_step_limit_lf = 0.63095734448019324;//q = 30 - const Word32 positive_step_limit_hf = 1276144549; UNUSED_PARAM(step_limit_hf_dB); // powf(10.0f, 0.05f * step_limit_hf_dB) = 1.188502227437018437; //q = 30 - const Word32 negative_step_limit_hf = 903441154; // 1.0f / positive_step_limit_hf = 1.26209271246779263; //q = 30 - - /* Go up from pivot frequency and limit the slope to the maximum given by T. */ - FOR(i = pivot_bin_idx + 1; i < dim_x; i++) - { - Word16 div_e; - Word32 desiredChange = L_deposit_h((BASOP_Util_Divide3232_Scale(X[i], X[i - 1], &div_e))); - Word16 desiredChange_q =sub( 31, (div_e)); - Word64 temp; - IF(GT_16(desiredChange_q, 30)) - { - desiredChange = L_shr(desiredChange, desiredChange_q - 30); - desiredChange_q = 30; move16(); - } - Word32 change = L_abs(desiredChange); + Word16 i; + const Word32 positive_step_limit_lf = 1701766107; + UNUSED_PARAM( step_limit_lf_dB ); // powf(10.0f, 0.05f * step_limit_lf_dB) = 1.5848931924611134852; //q = 30 + const Word32 negative_step_limit_lf = 677485289; // 1.0f / positive_step_limit_lf = 0.63095734448019324;//q = 30 + const Word32 positive_step_limit_hf = 1276144549; + UNUSED_PARAM( step_limit_hf_dB ); // powf(10.0f, 0.05f * step_limit_hf_dB) = 1.188502227437018437; //q = 30 + const Word32 negative_step_limit_hf = 903441154; // 1.0f / positive_step_limit_hf = 1.26209271246779263; //q = 30 - IF(GE_32(X[i], X[i - 1])) - { - IF(GT_32(change, L_shr(positive_step_limit_hf, 30 - desiredChange_q))) - { - change = positive_step_limit_hf; // q = 30; - move32(); - temp = W_mult0_32_32(X[i - 1], change); - X[i] = (Word32)W_shr(temp, 30); - } - } - ELSE + /* Go up from pivot frequency and limit the slope to the maximum given by T. */ + FOR( i = pivot_bin_idx + 1; i < dim_x; i++ ) { - IF(LT_32(change, L_shr(negative_step_limit_hf, 30 - desiredChange_q))) + Word16 div_e; + Word32 desiredChange = L_deposit_h( ( BASOP_Util_Divide3232_Scale( X[i], X[i - 1], &div_e ) ) ); + Word16 desiredChange_q = sub( 31, ( div_e ) ); + Word64 temp; + IF( GT_16( desiredChange_q, 30 ) ) { - change = negative_step_limit_hf; // q = 30; - move32(); - temp = W_mult0_32_32(X[i - 1], change); - X[i] = (Word32)W_shr(temp, 30); + desiredChange = L_shr( desiredChange, desiredChange_q - 30 ); + desiredChange_q = 30; + move16(); } - } - } + Word32 change = L_abs( desiredChange ); - /* Go down from pivot frequency and limit the slope to the maximum given by T. */ - FOR(i = pivot_bin_idx - 1; i >= 0; i--) - { - Word16 div_e; - Word32 desiredChange = L_deposit_h((BASOP_Util_Divide3232_Scale(X[i], X[i + 1], &div_e))); - Word16 desiredChange_q = sub(31, (div_e)); - Word64 temp; - IF(GT_16(desiredChange_q, 30)) - { - desiredChange = L_shr(desiredChange, desiredChange_q - 30); - desiredChange_q = 30; move16(); + IF( GE_32( X[i], X[i - 1] ) ) + { + IF( GT_32( change, L_shr( positive_step_limit_hf, 30 - desiredChange_q ) ) ) + { + change = positive_step_limit_hf; // q = 30; + move32(); + temp = W_mult0_32_32( X[i - 1], change ); + X[i] = (Word32) W_shr( temp, 30 ); + } + } + ELSE + { + IF( LT_32( change, L_shr( negative_step_limit_hf, 30 - desiredChange_q ) ) ) + { + change = negative_step_limit_hf; // q = 30; + move32(); + temp = W_mult0_32_32( X[i - 1], change ); + X[i] = (Word32) W_shr( temp, 30 ); + } + } } - Word32 change = L_abs(desiredChange); - IF(GE_32(X[i], X[i + 1])) - { - IF(GT_32(change, L_shr(positive_step_limit_lf, 30 - desiredChange_q))) - { - change = positive_step_limit_lf; // q = 30; - move32(); - temp = W_mult0_32_32(X[i + 1], change); - X[i] = (Word32)W_shr(temp, 30); - } - } - ELSE + /* Go down from pivot frequency and limit the slope to the maximum given by T. */ + FOR( i = pivot_bin_idx - 1; i >= 0; i-- ) { - IF(LT_32(change, L_shr(negative_step_limit_lf, 30 - desiredChange_q))) + Word16 div_e; + Word32 desiredChange = L_deposit_h( ( BASOP_Util_Divide3232_Scale( X[i], X[i + 1], &div_e ) ) ); + Word16 desiredChange_q = sub( 31, ( div_e ) ); + Word64 temp; + IF( GT_16( desiredChange_q, 30 ) ) + { + desiredChange = L_shr( desiredChange, desiredChange_q - 30 ); + desiredChange_q = 30; + move16(); + } + Word32 change = L_abs( desiredChange ); + + IF( GE_32( X[i], X[i + 1] ) ) { - change = negative_step_limit_lf; // q = 30; - move32(); - temp = W_mult0_32_32(X[i + 1], change); - X[i] = (Word32)W_shr(temp, 30); + IF( GT_32( change, L_shr( positive_step_limit_lf, 30 - desiredChange_q ) ) ) + { + change = positive_step_limit_lf; // q = 30; + move32(); + temp = W_mult0_32_32( X[i + 1], change ); + X[i] = (Word32) W_shr( temp, 30 ); + } + } + ELSE + { + IF( LT_32( change, L_shr( negative_step_limit_lf, 30 - desiredChange_q ) ) ) + { + change = negative_step_limit_lf; // q = 30; + move32(); + temp = W_mult0_32_32( X[i + 1], change ); + X[i] = (Word32) W_shr( temp, 30 ); + } } } - } - return; + return; } #endif /*-------------------------------------------------------------------* @@ -769,48 +789,49 @@ void ivas_reverb_define_window_fft( #else void ivas_reverb_define_window_fft_fx( - Word32 *pWindow, //output in Q31 - const Word16 transitionStart, - const Word16 transitionLength, - const Word16 spectrumLength) + Word32 *pWindow, // output in Q31 + const Word16 transitionStart, + const Word16 transitionLength, + const Word16 spectrumLength ) { - Word16 idx, fftLength; - Word16 angle_increment; - Word16 initial_angle; + Word16 idx, fftLength; + Word16 angle_increment; + Word16 initial_angle; - fftLength = shl(sub(spectrumLength, 1), 1); + fftLength = shl( sub( spectrumLength, 1 ), 1 ); - /* The first portion of the sequence is kept unchanged, window == 1 */ - FOR(idx = 0; idx < transitionStart; idx++) - { - pWindow[idx] = ONE_IN_Q31; //q31 - move32(); - } + /* The first portion of the sequence is kept unchanged, window == 1 */ + FOR( idx = 0; idx < transitionStart; idx++ ) + { + pWindow[idx] = ONE_IN_Q31; // q31 + move32(); + } - /* Adding Hann half-window for smooth transition */ - Word16 s1 = sub(norm_s(shr(EVS_PI_FX, 1)), 1); - Word16 s2 = norm_s(sub(shl(transitionLength, 1), 1)); - Word16 var1 = shl(EVS_PI_FX, s1); - Word16 var2 = shl(sub(shl(transitionLength, 1), 1), s2); - angle_increment = div_s(shr(var1, 5), var2); //q = 15 + /* Adding Hann half-window for smooth transition */ + Word16 s1 = sub( norm_s( shr( EVS_PI_FX, 1 ) ), 1 ); + Word16 s2 = norm_s( sub( shl( transitionLength, 1 ), 1 ) ); + Word16 var1 = shl( EVS_PI_FX, s1 ); + Word16 var2 = shl( sub( shl( transitionLength, 1 ), 1 ), s2 ); + angle_increment = div_s( shr( var1, 5 ), var2 ); // q = 15 - /* Initial angle set to match Hann window alignment in Matlab */ - initial_angle = shr(add((EVS_PI_FX), shr(angle_increment, 2)), 1); // q = 13 + /* Initial angle set to match Hann window alignment in Matlab */ + initial_angle = shr( add( ( EVS_PI_FX ), shr( angle_increment, 2 ) ), 1 ); // q = 13 - FOR(idx = 0; idx < transitionLength; idx++) - { - const Word16 sine_value = getSineWord16R2(mult(add(initial_angle, shl(mult(shl(idx, 8), angle_increment), 5)), 20858)); //q31 + FOR( idx = 0; idx < transitionLength; idx++ ) + { + const Word16 sine_value = getSineWord16R2( mult( add( initial_angle, shl( mult( shl( idx, 8 ), angle_increment ), 5 ) ), 20858 ) ); // q31 - pWindow[idx + transitionStart] = L_mult(sine_value, sine_value); - } + pWindow[idx + transitionStart] = L_mult( sine_value, sine_value ); + } - /* Padding the rest with zeros */ - FOR(idx = transitionStart + transitionLength; idx < fftLength; idx++) - { - pWindow[idx] = 0; move32(); - } + /* Padding the rest with zeros */ + FOR( idx = transitionStart + transitionLength; idx < fftLength; idx++ ) + { + pWindow[idx] = 0; + move32(); + } - return; + return; } #endif @@ -863,44 +884,47 @@ int16_t ivas_reverb_calc_color_filters( #endif #ifdef IVAS_FLOAT_FIXED Word16 ivas_reverb_calc_color_filters_fx( - const Word32 *pTargetL, - const Word32 *pTargetR, - const Word32 *pWindow, - const Word16 fft_size, - const Word16 delay, - rv_fftwf_type_complex_fx *pBeqL, - rv_fftwf_type_complex_fx *pBeqR, - Word16 *q_pBeqL, - Word16 *q_pBeqR -) + const Word32 *pTargetL, + const Word32 *pTargetR, + const Word32 *pWindow, + const Word16 fft_size, + const Word16 delay, + rv_fftwf_type_complex_fx *pBeqL, + rv_fftwf_type_complex_fx *pBeqR, + Word16 *q_pBeqL, + Word16 *q_pBeqR ) { - Word16 idx, half_fft_size; + Word16 idx, half_fft_size; - half_fft_size = shr(fft_size, 1); - FOR(idx = 0; idx <= half_fft_size; idx++) - { - pBeqL[idx][0] = L_shl(pTargetL[idx], 1); move32(); - pBeqL[idx][1] = 0; move32(); - pBeqR[idx][0] = L_shl(pTargetR[idx], 1); move32(); - pBeqR[idx][1] = 0; move32(); - } + half_fft_size = shr( fft_size, 1 ); + FOR( idx = 0; idx <= half_fft_size; idx++ ) + { + pBeqL[idx][0] = L_shl( pTargetL[idx], 1 ); + move32(); + pBeqL[idx][1] = 0; + move32(); + pBeqR[idx][0] = L_shl( pTargetR[idx], 1 ); + move32(); + pBeqR[idx][1] = 0; + move32(); + } - /* Make the response minimum phase. Does make the spectrum complex, but - will avoid aliasing when applied in the FFT domain. */ - calc_min_phase_filter_fx(pBeqL, fft_size, delay); - calc_min_phase_filter_fx(pBeqR, fft_size, delay); - apply_window_fft_fx(pBeqL, pWindow, fft_size, q_pBeqL); - apply_window_fft_fx(pBeqR, pWindow, fft_size, q_pBeqR); + /* Make the response minimum phase. Does make the spectrum complex, but + will avoid aliasing when applied in the FFT domain. */ + calc_min_phase_filter_fx( pBeqL, fft_size, delay ); + calc_min_phase_filter_fx( pBeqR, fft_size, delay ); + apply_window_fft_fx( pBeqL, pWindow, fft_size, q_pBeqL ); + apply_window_fft_fx( pBeqR, pWindow, fft_size, q_pBeqR ); - FOR(idx = 0; idx <= half_fft_size; idx++) - { - IF(LT_32(pTargetL[idx], 0) || LT_32(pTargetR[idx], 0)) /* Shouldn't have negative gains. */ + FOR( idx = 0; idx <= half_fft_size; idx++ ) { - return 1; + IF( LT_32( pTargetL[idx], 0 ) || LT_32( pTargetR[idx], 0 ) ) /* Shouldn't have negative gains. */ + { + return 1; + } } - } - return 0; + return 0; } #endif /*-------------------------------------------------------------------* @@ -950,53 +974,57 @@ int16_t ivas_reverb_calc_correl_filters( #endif #ifdef IVAS_FLOAT_FIXED Word16 ivas_reverb_calc_correl_filters_fx( - Word32 *pTargetICC, //input in Q30 - const Word32 *pWindow, //input in Q30 - const Word16 fft_size, - const Word16 delay, - rv_fftwf_type_complex_fx *pU, //input in Q31 - rv_fftwf_type_complex_fx *pV, //input in Q31 - Word16 *q_pU, //Output q - Word16 *q_pV //output q + Word32 *pTargetICC, // input in Q30 + const Word32 *pWindow, // input in Q30 + const Word16 fft_size, + const Word16 delay, + rv_fftwf_type_complex_fx *pU, // input in Q31 + rv_fftwf_type_complex_fx *pV, // input in Q31 + Word16 *q_pU, // Output q + Word16 *q_pV // output q ) { - Word16 idx, half_fft_size; + Word16 idx, half_fft_size; - half_fft_size = shr(fft_size, 1); - FOR(idx = 0; idx <= half_fft_size; idx++) - { - IF(LT_32(pTargetICC[idx], L_negate(ONE_IN_Q30)) || LT_32(ONE_IN_Q30, pTargetICC[idx])) /* Shouldn't have negative gains. */ + half_fft_size = shr( fft_size, 1 ); + FOR( idx = 0; idx <= half_fft_size; idx++ ) { - return 1; - } - } - Word16 temp; - FOR(idx = 0; idx <= half_fft_size; idx++) - { - temp = 1; move32(); - pU[idx][0] = Sqrt32(L_shr(L_add(ONE_IN_Q30, pTargetICC[idx]), 1), &temp); - IF(temp) - { - pU[idx][0] = L_shl(pU[idx][0], temp); + IF( LT_32( pTargetICC[idx], L_negate( ONE_IN_Q30 ) ) || LT_32( ONE_IN_Q30, pTargetICC[idx] ) ) /* Shouldn't have negative gains. */ + { + return 1; + } } - pU[idx][1] = 0; move32(); - temp = 1; move32(); - pV[idx][0] = Sqrt32(L_shr(L_sub(ONE_IN_Q30, pTargetICC[idx]), 1), &temp); - IF(temp) + Word16 temp; + FOR( idx = 0; idx <= half_fft_size; idx++ ) { - pV[idx][0] = L_shl(pV[idx][0], temp); + temp = 1; + move32(); + pU[idx][0] = Sqrt32( L_shr( L_add( ONE_IN_Q30, pTargetICC[idx] ), 1 ), &temp ); + IF( temp ) + { + pU[idx][0] = L_shl( pU[idx][0], temp ); + } + pU[idx][1] = 0; + move32(); + temp = 1; + move32(); + pV[idx][0] = Sqrt32( L_shr( L_sub( ONE_IN_Q30, pTargetICC[idx] ), 1 ), &temp ); + IF( temp ) + { + pV[idx][0] = L_shl( pV[idx][0], temp ); + } + pV[idx][1] = 0; + move32(); } - pV[idx][1] = 0; move32(); - } - /* Make the response minimum phase. Does make the spectrum complex, but - will avoid aliasing when applied in the FFT domain. */ - calc_min_phase_filter_fx(pU, fft_size, delay); - calc_min_phase_filter_fx(pV, fft_size, delay); - apply_window_fft_fx(pU, pWindow, fft_size, q_pU); - apply_window_fft_fx(pV, pWindow, fft_size, q_pV); + /* Make the response minimum phase. Does make the spectrum complex, but + will avoid aliasing when applied in the FFT domain. */ + calc_min_phase_filter_fx( pU, fft_size, delay ); + calc_min_phase_filter_fx( pV, fft_size, delay ); + apply_window_fft_fx( pU, pWindow, fft_size, q_pU ); + apply_window_fft_fx( pV, pWindow, fft_size, q_pV ); - return 0; + return 0; } #endif /*-------------------------------------------------------------------* @@ -1108,143 +1136,155 @@ void ivas_reverb_calc_color_levels( #else void ivas_reverb_calc_color_levels_fx( - const Word32 output_Fs, - const Word16 freq_count, - const Word16 loop_count, - const Word32 *pFc, //input in Q14 - const Word32 *pAcoustic_dsr, //input in Q31 - const Word32 *pHrtf_avg_pwr_L, //input in Q28 - const Word32 *pHrtf_avg_pwr_R, //input in Q28 - const Word16 *pLoop_delays, - const Word32 *pT60_filter_coeff, //input in Q31 - Word32 *pTarget_color_L, //output in Q30 - Word32 *pTarget_color_R) //output in Q30 + const Word32 output_Fs, + const Word16 freq_count, + const Word16 loop_count, + const Word32 *pFc, // input in Q14 + const Word32 *pAcoustic_dsr, // input in Q31 + const Word32 *pHrtf_avg_pwr_L, // input in Q28 + const Word32 *pHrtf_avg_pwr_R, // input in Q28 + const Word16 *pLoop_delays, + const Word32 *pT60_filter_coeff, // input in Q31 + Word32 *pTarget_color_L, // output in Q30 + Word32 *pTarget_color_R ) // output in Q30 { - Word16 i, freq_idx, idx_pivot, nrcoefs, loop_idx; - Word32 t60[RV_LENGTH_NR_FC]; - Word16 t60_e[RV_LENGTH_NR_FC + 1]; + Word16 i, freq_idx, idx_pivot, nrcoefs, loop_idx; + Word32 t60[RV_LENGTH_NR_FC]; + Word16 t60_e[RV_LENGTH_NR_FC + 1]; - /* Pre-computing inverse values for optimisation (to avoid divisions in inner loops) */ - Word16 fs_inverted_q; - const Word32 fs_inverted = BASOP_Util_Divide3232_Scale(ONE_IN_Q11, L_shl(output_Fs, 11), &fs_inverted_q); // q= 15 - fs_inverted_q = 29 - const Word32 loop_count_inverted = divide3232(ONE_IN_Q27, L_shl(loop_count, 27)); // q= 15; + /* Pre-computing inverse values for optimisation (to avoid divisions in inner loops) */ + Word16 fs_inverted_q; + const Word32 fs_inverted = BASOP_Util_Divide3232_Scale( ONE_IN_Q11, L_shl( output_Fs, 11 ), &fs_inverted_q ); // q= 15 - fs_inverted_q = 29 + const Word32 loop_count_inverted = divide3232( ONE_IN_Q27, L_shl( loop_count, 27 ) ); // q= 15; - const Word32 log__0_001 = -1854286438; //logf( 0.001f ) in q28 - move32(); - /* Pre-computed for better efficiency */ + const Word32 log__0_001 = -1854286438; // logf( 0.001f ) in q28 + move32(); + /* Pre-computed for better efficiency */ - /* revEnergyFactor == 1 for IVAS, as the pDsr values are already scaled previously for predelay delta */ + /* revEnergyFactor == 1 for IVAS, as the pDsr values are already scaled previously for predelay delta */ - /* Computing minimum delays in a simpler way, as they are already provided in descending order */ - const Word16 minDelay = pLoop_delays[loop_count - 1]; move32(); - const Word16 minDelayDiff = sub(pLoop_delays[loop_count - 2], pLoop_delays[loop_count - 1]); + /* Computing minimum delays in a simpler way, as they are already provided in descending order */ + const Word16 minDelay = pLoop_delays[loop_count - 1]; + move32(); + const Word16 minDelayDiff = sub( pLoop_delays[loop_count - 2], pLoop_delays[loop_count - 1] ); - FOR(freq_idx = 0; freq_idx < freq_count; freq_idx++) - { - t60[freq_idx] = 0; move32(); - t60_e[freq_idx] = 31; move16(); - } + FOR( freq_idx = 0; freq_idx < freq_count; freq_idx++ ) + { + t60[freq_idx] = 0; + move32(); + t60_e[freq_idx] = 31; + move16(); + } - FOR(loop_idx = 0; loop_idx < loop_count; loop_idx++) - { - Word32 coefA[2]; - Word32 coefB[2]; - - nrcoefs = 2; move16(); - /* for pFilter order == 1 */ - - /* Obtaining T60 filters coefficients for the current loop */ - FOR(i = 0; i < nrcoefs; i++) - { - coefA[i] = pT60_filter_coeff[add(i_mult(shl(nrcoefs, 1), loop_idx), add(i, nrcoefs))]; // q = 31 - coefB[i] = pT60_filter_coeff[add(i_mult(shl(nrcoefs, 1), loop_idx), i)]; // // q = 31 - } - t60_e[freq_count] = -100; move16(); - /* Loop over frequencies */ - FOR(freq_idx = 0; freq_idx < freq_count; freq_idx++) - { - /* Compute T60 pFilter gain at the given frequency */ - Word32 cos_w; - Word32 H_filter; - Word32 T60_est; - Word16 temp = 0, result_e = 0; move16(); move16(); - cos_w = getCosWord16R2((Word16)abs(L_shl(Mpy_32_32(pFc[freq_idx], fs_inverted), 3))); // q = 15 - H_filter = L_add(L_shr(L_add(L_shr(Mpy_32_32(coefB[0], coefB[0]), 1), L_shr(Mpy_32_32(coefB[1], coefB[1]), 1)), 2), L_shr(Mpy_32_32(coefB[0], Mpy_32_32(coefB[1], L_shl(cos_w, 15))), 1)); //q = 28 - H_filter = BASOP_Util_Divide3232_Scale(H_filter, L_add(ONE_IN_Q28, L_shr(L_add(L_shr(Mpy_32_32(coefA[1], coefA[1]), 2), Mpy_32_32(coefA[1], L_shl(cos_w, 15))), 1)), &temp); - H_filter = Sqrt32(L_shl(H_filter, 16), &temp); - T60_est = BASOP_Util_Divide3232_Scale(L_shl(i_mult(-3, pLoop_delays[loop_idx]), 2), Mpy_32_32(Mpy_32_32(L_add(BASOP_Util_Log2(H_filter), L_shl(temp, 25)), LOG10_2_Q31), L_shl(output_Fs, 8)), &temp);//conversion of log2 to log10. - T60_est = L_shl(T60_est, 16); - t60[freq_idx] = BASOP_Util_Add_Mant32Exp(T60_est, temp, t60[freq_idx], t60_e[freq_idx], &result_e); - t60_e[freq_idx] = result_e; - t60_e[freq_count] = max(result_e, t60_e[freq_count]); - } - FOR(freq_idx = 0; freq_idx < freq_count; freq_idx++) - { - t60[freq_idx] = L_shr(t60[freq_idx], t60_e[freq_count] - t60_e[freq_idx]); - t60_e[freq_idx] = t60_e[freq_count]; + FOR( loop_idx = 0; loop_idx < loop_count; loop_idx++ ) + { + Word32 coefA[2]; + Word32 coefB[2]; + + nrcoefs = 2; + move16(); + /* for pFilter order == 1 */ + + /* Obtaining T60 filters coefficients for the current loop */ + FOR( i = 0; i < nrcoefs; i++ ) + { + coefA[i] = pT60_filter_coeff[add( i_mult( shl( nrcoefs, 1 ), loop_idx ), add( i, nrcoefs ) )]; // q = 31 + coefB[i] = pT60_filter_coeff[add( i_mult( shl( nrcoefs, 1 ), loop_idx ), i )]; // // q = 31 + } + t60_e[freq_count] = -100; + move16(); + /* Loop over frequencies */ + FOR( freq_idx = 0; freq_idx < freq_count; freq_idx++ ) + { + /* Compute T60 pFilter gain at the given frequency */ + Word32 cos_w; + Word32 H_filter; + Word32 T60_est; + Word16 temp = 0, result_e = 0; + move16(); + move16(); + cos_w = getCosWord16R2( (Word16) abs( L_shl( Mpy_32_32( pFc[freq_idx], fs_inverted ), 3 ) ) ); // q = 15 + H_filter = L_add( L_shr( L_add( L_shr( Mpy_32_32( coefB[0], coefB[0] ), 1 ), L_shr( Mpy_32_32( coefB[1], coefB[1] ), 1 ) ), 2 ), L_shr( Mpy_32_32( coefB[0], Mpy_32_32( coefB[1], L_shl( cos_w, 15 ) ) ), 1 ) ); // q = 28 + H_filter = BASOP_Util_Divide3232_Scale( H_filter, L_add( ONE_IN_Q28, L_shr( L_add( L_shr( Mpy_32_32( coefA[1], coefA[1] ), 2 ), Mpy_32_32( coefA[1], L_shl( cos_w, 15 ) ) ), 1 ) ), &temp ); + H_filter = Sqrt32( L_shl( H_filter, 16 ), &temp ); + T60_est = BASOP_Util_Divide3232_Scale( L_shl( i_mult( -3, pLoop_delays[loop_idx] ), 2 ), Mpy_32_32( Mpy_32_32( L_add( BASOP_Util_Log2( H_filter ), L_shl( temp, 25 ) ), LOG10_2_Q31 ), L_shl( output_Fs, 8 ) ), &temp ); // conversion of log2 to log10. + T60_est = L_shl( T60_est, 16 ); + t60[freq_idx] = BASOP_Util_Add_Mant32Exp( T60_est, temp, t60[freq_idx], t60_e[freq_idx], &result_e ); + t60_e[freq_idx] = result_e; + t60_e[freq_count] = max( result_e, t60_e[freq_count] ); + } + FOR( freq_idx = 0; freq_idx < freq_count; freq_idx++ ) + { + t60[freq_idx] = L_shr( t60[freq_idx], t60_e[freq_count] - t60_e[freq_idx] ); + t60_e[freq_idx] = t60_e[freq_count]; + } } - } - /* Dividing by the number of loops to compute the average T60 estimate */ - FOR(freq_idx = 0; freq_idx < freq_count; freq_idx++) - { - t60[freq_idx] = Mpy_32_32(t60[freq_idx], L_shl(loop_count_inverted, 16)); - } + /* Dividing by the number of loops to compute the average T60 estimate */ + FOR( freq_idx = 0; freq_idx < freq_count; freq_idx++ ) + { + t60[freq_idx] = Mpy_32_32( t60[freq_idx], L_shl( loop_count_inverted, 16 ) ); + } - Word16 *pTarget_color_L_e = (Word16*)malloc(257 * sizeof(Word16)); - Word16 *pTarget_color_R_e = (Word16*)malloc(257 * sizeof(Word16)); - /* Compute target gains on the basis of the estimated T60 values */ - FOR(freq_idx = 0; freq_idx < freq_count; freq_idx++) - { - Word16 temp, temp1, temp2, temp3 = 0, temp4, temp5; move32(); - Word32 var1 = divide3232((Word32)i_mult(-6, minDelay), L_shr(Mpy_32_32(t60[freq_idx], L_shl(output_Fs, 11)), 11 - t60_e[freq_idx])); - var1 = L_mult((Word16)var1, LOG2_10); // q = 29 - Word32 A0_square_est = BASOP_util_Pow2(var1, 31 - 29, &temp); - Word16 alpha_e; - Word16 alpha = BASOP_Util_Divide3232_Scale(-log__0_001, t60[freq_idx], &alpha_e);//alpha_e = 1 + alpha_e + (3 - t60_e[257]) - - Word16 div11 = BASOP_Util_Divide3216_Scale(A0_square_est, alpha, &temp1); //e = temp1 + (temp - alpha_e) - Word32 div2 = BASOP_Util_Divide3232_Scale(L_shl(output_Fs, 11), L_shr(L_add(Mpy_32_16_1(1884631649, shl(minDelayDiff, 3)), 14037339), 8), &temp2); //e = temp2, 26.7741 in Q19, 0.8776 in Q31 - - const Word32 revPredNormEnergy = Mpy_32_16_1(L_shl(div2, 16), div11);//q = (15 - temp2) + (15 - temp1) - 15 + 1 - //L_max + Word16 *pTarget_color_L_e = (Word16 *) malloc( 257 * sizeof( Word16 ) ); + Word16 *pTarget_color_R_e = (Word16 *) malloc( 257 * sizeof( Word16 ) ); + /* Compute target gains on the basis of the estimated T60 values */ + FOR( freq_idx = 0; freq_idx < freq_count; freq_idx++ ) + { + Word16 temp, temp1, temp2, temp3 = 0, temp4, temp5; + move32(); + Word32 var1 = divide3232( (Word32) i_mult( -6, minDelay ), L_shr( Mpy_32_32( t60[freq_idx], L_shl( output_Fs, 11 ) ), 11 - t60_e[freq_idx] ) ); + var1 = L_mult( (Word16) var1, LOG2_10 ); // q = 29 + Word32 A0_square_est = BASOP_util_Pow2( var1, 31 - 29, &temp ); + Word16 alpha_e; + Word16 alpha = BASOP_Util_Divide3232_Scale( -log__0_001, t60[freq_idx], &alpha_e ); // alpha_e = 1 + alpha_e + (3 - t60_e[257]) + + Word16 div11 = BASOP_Util_Divide3216_Scale( A0_square_est, alpha, &temp1 ); // e = temp1 + (temp - alpha_e) + Word32 div2 = BASOP_Util_Divide3232_Scale( L_shl( output_Fs, 11 ), L_shr( L_add( Mpy_32_16_1( 1884631649, shl( minDelayDiff, 3 ) ), 14037339 ), 8 ), &temp2 ); // e = temp2, 26.7741 in Q19, 0.8776 in Q31 + + const Word32 revPredNormEnergy = Mpy_32_16_1( L_shl( div2, 16 ), div11 ); // q = (15 - temp2) + (15 - temp1) - 15 + 1 + // L_max + Word32 div1; + temp3 = add( add( temp1, sub( temp, add( 1, add( alpha_e, sub( 3, t60_e[freq_count] ) ) ) ) ), temp2 ); + div1 = L_max( Sqrt32( revPredNormEnergy, &temp3 ), 1 ); + temp4 = 3; + div2 = Sqrt32( Mpy_32_32( pAcoustic_dsr[freq_idx], pHrtf_avg_pwr_L[freq_idx] ), &temp4 ); + pTarget_color_L[freq_idx] = (Word32) BASOP_Util_Divide3232_Scale( div2, div1, &temp5 ); + temp5 = add( temp5, sub( temp4, temp3 ) ); + pTarget_color_L_e[freq_idx] = temp5; + move16(); + + temp3 = add( add( temp1, sub( temp, add( 1, add( alpha_e, sub( 3, t60_e[freq_count] ) ) ) ) ), temp2 ); + div1 = L_max( Sqrt32( revPredNormEnergy, &temp3 ), 1 ); + temp4 = 3; + move16(); + div2 = Sqrt32( Mpy_32_32( pAcoustic_dsr[freq_idx], pHrtf_avg_pwr_R[freq_idx] ), &temp4 ); + pTarget_color_R[freq_idx] = BASOP_Util_Divide3232_Scale( div2, div1, &temp5 ); + temp5 = add( temp5, sub( temp4, temp3 ) ); + pTarget_color_R_e[freq_idx] = temp5; + move16(); + } + FOR( freq_idx = 0; freq_idx < freq_count; freq_idx++ ) + { + pTarget_color_R[freq_idx] = L_shr( L_shl( pTarget_color_R[freq_idx], 16 ), sub( 1, pTarget_color_R_e[freq_idx] ) ); // (31 - pTarget_color_R_e[freq_idx]) - 30 + pTarget_color_L[freq_idx] = L_shr( L_shl( pTarget_color_L[freq_idx], 16 ), sub( 1, pTarget_color_L_e[freq_idx] ) ); // (31 - pTarget_color_L_e[freq_idx]) - 30 + } + /* Limiting the frequency response gradients + Find frequency band closest to chosen pivot frequency. */ Word32 div1; - temp3 = add(add(temp1, sub(temp, add(1, add(alpha_e, sub(3, t60_e[freq_count]))))), temp2); - div1 = L_max(Sqrt32(revPredNormEnergy, &temp3), 1); - temp4 = 3; - div2 = Sqrt32(Mpy_32_32(pAcoustic_dsr[freq_idx], pHrtf_avg_pwr_L[freq_idx]), &temp4); - pTarget_color_L[freq_idx] = (Word32)BASOP_Util_Divide3232_Scale(div2, div1, &temp5); - temp5 = add(temp5, sub(temp4, temp3)); - pTarget_color_L_e[freq_idx] = temp5; move16(); - - temp3 = add(add(temp1, sub(temp, add(1, add(alpha_e, sub(3, t60_e[freq_count]))))), temp2); - div1 = L_max(Sqrt32(revPredNormEnergy, &temp3), 1); - temp4 = 3; move16(); - div2 = Sqrt32(Mpy_32_32(pAcoustic_dsr[freq_idx], pHrtf_avg_pwr_R[freq_idx]), &temp4); - pTarget_color_R[freq_idx] = BASOP_Util_Divide3232_Scale(div2, div1, &temp5); - temp5 = add(temp5, sub(temp4, temp3)); - pTarget_color_R_e[freq_idx] = temp5; move16(); - } - FOR(freq_idx = 0; freq_idx < freq_count; freq_idx++) - { - pTarget_color_R[freq_idx] = L_shr(L_shl(pTarget_color_R[freq_idx], 16), sub(1, pTarget_color_R_e[freq_idx]));// (31 - pTarget_color_R_e[freq_idx]) - 30 - pTarget_color_L[freq_idx] = L_shr(L_shl(pTarget_color_L[freq_idx], 16), sub(1, pTarget_color_L_e[freq_idx]));// (31 - pTarget_color_L_e[freq_idx]) - 30 - } - /* Limiting the frequency response gradients - Find frequency band closest to chosen pivot frequency. */ - Word32 div1; - Word16 temp = 0; move16(); - div1 = BASOP_Util_Divide3232_Scale(L_mult0(1000, sub(freq_count, 1)), L_shr(output_Fs, 1), &temp); - div1 = BASOP_Util_Add_Mant32Exp(L_shl(div1, 16), temp, ONE_IN_Q30, 1, &temp); - idx_pivot = (Word16)L_shr(div1, sub(31, temp)); - /* Perform step limiting */ - - response_step_limit_fx(pTarget_color_L, freq_count, RESPONSE_STEP_LIMIT_LF_FX, RESPONSE_STEP_LIMIT_HF_FX, idx_pivot); - response_step_limit_fx(pTarget_color_R, freq_count, RESPONSE_STEP_LIMIT_LF_FX, RESPONSE_STEP_LIMIT_HF_FX, idx_pivot); - - free(pTarget_color_L_e); - free(pTarget_color_R_e); - return; + Word16 temp = 0; + move16(); + div1 = BASOP_Util_Divide3232_Scale( L_mult0( 1000, sub( freq_count, 1 ) ), L_shr( output_Fs, 1 ), &temp ); + div1 = BASOP_Util_Add_Mant32Exp( L_shl( div1, 16 ), temp, ONE_IN_Q30, 1, &temp ); + idx_pivot = (Word16) L_shr( div1, sub( 31, temp ) ); + /* Perform step limiting */ + + response_step_limit_fx( pTarget_color_L, freq_count, RESPONSE_STEP_LIMIT_LF_FX, RESPONSE_STEP_LIMIT_HF_FX, idx_pivot ); + response_step_limit_fx( pTarget_color_R, freq_count, RESPONSE_STEP_LIMIT_LF_FX, RESPONSE_STEP_LIMIT_HF_FX, idx_pivot ); + + free( pTarget_color_L_e ); + free( pTarget_color_R_e ); + return; } #endif @@ -1308,66 +1348,73 @@ void ivas_reverb_interpolate_acoustic_data( #else void ivas_reverb_interpolate_acoustic_data_fx( - const Word16 input_table_size, - const Word32 *pInput_fc, //input in Q16 - const Word32 *pInput_t60, //input in Q26 - const Word32 *pInput_dsr, //input in Q30 - const Word16 output_table_size, - const Word32 *pOutput_fc, - Word32 *pOutput_t60, - Word32 *pOutput_dsr, - Word16 *pOutput_t60_e, //output e - Word16 *pOutput_dsr_e //output e + const Word16 input_table_size, + const Word32 *pInput_fc, // input in Q16 + const Word32 *pInput_t60, // input in Q26 + const Word32 *pInput_dsr, // input in Q30 + const Word16 output_table_size, + const Word32 *pOutput_fc, + Word32 *pOutput_t60, + Word32 *pOutput_dsr, + Word16 *pOutput_t60_e, // output e + Word16 *pOutput_dsr_e // output e ) { - Word16 input_idx, output_idx; - Word32 rel_offset; - Word16 rel_offset_e; - input_idx = 0; + Word16 input_idx, output_idx; + Word32 rel_offset; + Word16 rel_offset_e; + input_idx = 0; - FOR(output_idx = 0; output_idx < output_table_size; output_idx++) - { - /* if the bin frequency is lower than the 1st frequency point in the input table, take this 1st point */ - IF(LT_32(pOutput_fc[output_idx], pInput_fc[0])) + FOR( output_idx = 0; output_idx < output_table_size; output_idx++ ) { - input_idx = 0; move16(); - rel_offset = 0; move32(); - rel_offset_e = 0; move16(); - } - ELSE - { - /* if the bin frequency is higher than the last frequency point in the input table, take this last point */ - IF(GT_32(pOutput_fc[output_idx], pInput_fc[input_table_size - 1])) - { - input_idx = sub(input_table_size, 2); - rel_offset = ONE_IN_Q30; //Q30; - move32(); - rel_offset_e = 1; move16(); - } - /* otherwise use linear interpolation between 2 consecutive points in the input table */ - ELSE - { - WHILE(GT_32(pOutput_fc[output_idx], pInput_fc[input_idx + 1])) + /* if the bin frequency is lower than the 1st frequency point in the input table, take this 1st point */ + IF( LT_32( pOutput_fc[output_idx], pInput_fc[0] ) ) { - input_idx++; + input_idx = 0; + move16(); + rel_offset = 0; + move32(); + rel_offset_e = 0; + move16(); } - rel_offset = BASOP_Util_Divide3232_Scale(L_sub(pOutput_fc[output_idx], pInput_fc[input_idx]), L_sub(pInput_fc[input_idx + 1], pInput_fc[input_idx]), &rel_offset_e); //q15 - rel_offset = L_shl_sat(rel_offset, 16+rel_offset_e); - rel_offset_e = 0; - } - } - Word32 mult1; - Word16 mult_e = 0; move16(); - mult1 = Mpy_32_32(rel_offset, L_sub(pInput_t60[input_idx + 1], pInput_t60[input_idx])); - pOutput_t60[output_idx] = BASOP_Util_Add_Mant32Exp(pInput_t60[input_idx], 5, mult1, add(5, rel_offset_e), &mult_e);//31 - (31 - rel_offset_e + 26 - 31) - pOutput_t60_e[output_idx] = mult_e; move16(); - - mult1 = Mpy_32_32(rel_offset, L_sub(pInput_dsr[input_idx + 1], pInput_dsr[input_idx])); - pOutput_dsr[output_idx] = BASOP_Util_Add_Mant32Exp(pInput_dsr[input_idx], 1, mult1, add(1, rel_offset_e), &mult_e);//31 - (31 - rel_offset_e + 26 - 31) - pOutput_dsr_e[output_idx] = mult_e; move16(); - } + ELSE + { + /* if the bin frequency is higher than the last frequency point in the input table, take this last point */ + IF( GT_32( pOutput_fc[output_idx], pInput_fc[input_table_size - 1] ) ) + { + input_idx = sub( input_table_size, 2 ); + rel_offset = ONE_IN_Q30; // Q30; + move32(); + rel_offset_e = 1; + move16(); + } + /* otherwise use linear interpolation between 2 consecutive points in the input table */ + ELSE + { + WHILE( GT_32( pOutput_fc[output_idx], pInput_fc[input_idx + 1] ) ) + { + input_idx++; + } + rel_offset = BASOP_Util_Divide3232_Scale( L_sub( pOutput_fc[output_idx], pInput_fc[input_idx] ), L_sub( pInput_fc[input_idx + 1], pInput_fc[input_idx] ), &rel_offset_e ); // q15 + rel_offset = L_shl_sat( rel_offset, 16 + rel_offset_e ); + rel_offset_e = 0; + } + } + Word32 mult1; + Word16 mult_e = 0; + move16(); + mult1 = Mpy_32_32( rel_offset, L_sub( pInput_t60[input_idx + 1], pInput_t60[input_idx] ) ); + pOutput_t60[output_idx] = BASOP_Util_Add_Mant32Exp( pInput_t60[input_idx], 5, mult1, add( 5, rel_offset_e ), &mult_e ); // 31 - (31 - rel_offset_e + 26 - 31) + pOutput_t60_e[output_idx] = mult_e; + move16(); + + mult1 = Mpy_32_32( rel_offset, L_sub( pInput_dsr[input_idx + 1], pInput_dsr[input_idx] ) ); + pOutput_dsr[output_idx] = BASOP_Util_Add_Mant32Exp( pInput_dsr[input_idx], 1, mult1, add( 1, rel_offset_e ), &mult_e ); // 31 - (31 - rel_offset_e + 26 - 31) + pOutput_dsr_e[output_idx] = mult_e; + move16(); + } - return; + return; } #endif /*-------------------------------------------------------------------* @@ -1549,193 +1596,215 @@ void ivas_reverb_get_hrtf_set_properties( #else void ivas_reverb_get_hrtf_set_properties_fx( - Word32 **ppHrtf_set_L_re, - Word32 **ppHrtf_set_L_im, - Word32 **ppHrtf_set_R_re, - Word32 **ppHrtf_set_R_im, - const AUDIO_CONFIG input_audio_config, - const Word16 hrtf_count, - const Word16 in_freq_count, - const Word16 out_freq_count, - Word32 *pOut_avg_pwr_L, //output in Q23 - Word32 *pOut_avg_pwr_R, //output in Q23 - Word32 *out_i_a_coherence) //output in Q27 + Word32 **ppHrtf_set_L_re, + Word32 **ppHrtf_set_L_im, + Word32 **ppHrtf_set_R_re, + Word32 **ppHrtf_set_R_im, + const AUDIO_CONFIG input_audio_config, + const Word16 hrtf_count, + const Word16 in_freq_count, + const Word16 out_freq_count, + Word32 *pOut_avg_pwr_L, // output in Q23 + Word32 *pOut_avg_pwr_R, // output in Q23 + Word32 *out_i_a_coherence ) // output in Q27 { - const Word16 foa_sum_coeffs[4][3] = { - { MAX_WORD16, MAX_WORD16, 0 }, - { MAX_WORD16, -MAX_WORD16, 0 }, - { MAX_WORD16, 0, MAX_WORD16 }, - { MAX_WORD16, 0, -MAX_WORD16 } - }; - const Word32 inp_freq_step = divide3232(ONE_IN_Q22, L_shl(in_freq_count, 23)); // q= 15 - const Word32 inp_freq_offset = L_shr(inp_freq_step, 1); // q= 15 - const Word16 out_freq_step = divide3232(ONE_IN_Q21, L_shl(L_sub(out_freq_count, 1), 22)); //q = 15 - - Word16 hrtf_count_inverted, used_hrtf_count, freq_idx, hrtf_idx, out_bin_idx, ch_index, is_ambisonics; - Word32 relative_pos, weight_1st, base_idx; - Word32 avg_pwr_left[2]; - Word32 avg_pwr_right[2]; - Word32 IA_coherence[2]; - - IF(input_audio_config == IVAS_AUDIO_CONFIG_FOA || input_audio_config == IVAS_AUDIO_CONFIG_HOA2 || input_audio_config == IVAS_AUDIO_CONFIG_HOA3) - { - is_ambisonics = 1; move16(); - used_hrtf_count = 4; /* Using only 1st order HRTFs */ - move16(); - } - ELSE - { - is_ambisonics = 0; move16(); - used_hrtf_count = hrtf_count; move16(); - } - - /* Interpolation (linear to a new grid) */ - base_idx = 0; move32(); - relative_pos = 0; move32(); - hrtf_count_inverted = divide1616(ONE_IN_Q11, shl(used_hrtf_count, 11)); //q = 15 - - /* Loop over output frequency bins */ - FOR(out_bin_idx = 0; out_bin_idx < out_freq_count; out_bin_idx++) - { - /* Computing normalized frequency for the current bin (1.0 corresponds to sampling rate) */ + const Word16 foa_sum_coeffs[4][3] = { + { MAX_WORD16, MAX_WORD16, 0 }, + { MAX_WORD16, -MAX_WORD16, 0 }, + { MAX_WORD16, 0, MAX_WORD16 }, + { MAX_WORD16, 0, -MAX_WORD16 } + }; + const Word32 inp_freq_step = divide3232( ONE_IN_Q22, L_shl( in_freq_count, 23 ) ); // q= 15 + const Word32 inp_freq_offset = L_shr( inp_freq_step, 1 ); // q= 15 + const Word16 out_freq_step = divide3232( ONE_IN_Q21, L_shl( L_sub( out_freq_count, 1 ), 22 ) ); // q = 15 - const Word32 norm_freq = L_mult(out_freq_step, shl(out_bin_idx, 5)); //q = 21 + Word16 hrtf_count_inverted, used_hrtf_count, freq_idx, hrtf_idx, out_bin_idx, ch_index, is_ambisonics; + Word32 relative_pos, weight_1st, base_idx; + Word32 avg_pwr_left[2]; + Word32 avg_pwr_right[2]; + Word32 IA_coherence[2]; - /* Computing the bin index in the source data */ - Word16 div_q = 0; move16(); - //Word32 tbl_index = BASOP_Util_Divide3232_Scale(L_sub(norm_freq , L_shl(inp_freq_offset, 6)), L_shl(inp_freq_step, 6), &div_q);//q =15 - div_q - Word32 tbl_index = Mpy_32_32(L_sub(norm_freq, L_shl(inp_freq_offset, 6)), L_shl(in_freq_count, 22)); //q = 11 - IF(LT_16(div_q, 0)) + IF( input_audio_config == IVAS_AUDIO_CONFIG_FOA || input_audio_config == IVAS_AUDIO_CONFIG_HOA2 || input_audio_config == IVAS_AUDIO_CONFIG_HOA3 ) { - tbl_index = L_shl(tbl_index, div_q); - div_q = 0; move16(); + is_ambisonics = 1; + move16(); + used_hrtf_count = 4; /* Using only 1st order HRTFs */ + move16(); } - IF(LE_32(tbl_index, 0)) /* In case of extrapolation (below 1st bin), choose nearest */ + ELSE { - base_idx = 0; move32(); - relative_pos = 0; move32(); + is_ambisonics = 0; + move16(); + used_hrtf_count = hrtf_count; + move16(); } - ELSE + + /* Interpolation (linear to a new grid) */ + base_idx = 0; + move32(); + relative_pos = 0; + move32(); + hrtf_count_inverted = divide1616( ONE_IN_Q11, shl( used_hrtf_count, 11 ) ); // q = 15 + + /* Loop over output frequency bins */ + FOR( out_bin_idx = 0; out_bin_idx < out_freq_count; out_bin_idx++ ) { - base_idx = (tbl_index); //q = 21 - move32(); - relative_pos = L_shl(L_sub(tbl_index, L_shl(L_shr(base_idx, 11), 11)),20); //q = 31 - base_idx = L_shr(base_idx, 11); - IF(GT_32(base_idx, L_sub(in_freq_count, 2))) /* In case of extrapolation (above last bin), choose nearest */ - { - base_idx = L_sub(in_freq_count, 2); - relative_pos = ONE_IN_Q31; move32(); - } - } - - /* Computing 2 bins data for later interpolation */ - - /* Zeroing before accumalation for average value computing */ - avg_pwr_left[0] = 0; move32(); - avg_pwr_left[1] = 0; move32(); - avg_pwr_right[0] = 0; move32(); - avg_pwr_right[1] = 0; move32(); - IA_coherence[0] = 0; move32(); - IA_coherence[1] = 0; move32(); - - /* Get power spectra and cross - correlation between left and right hrtfs */ - /* Loop over all the HRTFs available */ - FOR(hrtf_idx = 0; hrtf_idx < used_hrtf_count; hrtf_idx++) - { - /* Pointers to current HRTF data */ - Word32 *current_base_L_ptr_re, *current_base_L_ptr_im, *current_base_R_ptr_re, *current_base_R_ptr_im; - - /* combined HRTF data used for FOA */ - Word32 combined_channels_L_re[2]; - Word32 combined_channels_L_im[2]; - Word32 combined_channels_R_re[2]; - Word32 combined_channels_R_im[2]; - - /* Process the frequency bins containing both real and img parts */ - /* In case of 5.1 or 7.1 formats, use the available HRTF paires directly*/ - IF(!is_ambisonics) - { - current_base_L_ptr_re = (ppHrtf_set_L_re[hrtf_idx] + base_idx); - current_base_R_ptr_re = (ppHrtf_set_R_re[hrtf_idx] + base_idx); - current_base_L_ptr_im = (ppHrtf_set_L_im[hrtf_idx] + base_idx); - current_base_R_ptr_im = (ppHrtf_set_R_im[hrtf_idx] + base_idx); - } - - /* In case of FOA format, combine the W channel with the X/Y channels */ - ELSE - { - FOR(freq_idx = 0; freq_idx < 2; freq_idx++) + /* Computing normalized frequency for the current bin (1.0 corresponds to sampling rate) */ + + const Word32 norm_freq = L_mult( out_freq_step, shl( out_bin_idx, 5 ) ); // q = 21 + + /* Computing the bin index in the source data */ + Word16 div_q = 0; + move16(); + // Word32 tbl_index = BASOP_Util_Divide3232_Scale(L_sub(norm_freq , L_shl(inp_freq_offset, 6)), L_shl(inp_freq_step, 6), &div_q);//q =15 - div_q + Word32 tbl_index = Mpy_32_32( L_sub( norm_freq, L_shl( inp_freq_offset, 6 ) ), L_shl( in_freq_count, 22 ) ); // q = 11 + IF( LT_16( div_q, 0 ) ) + { + tbl_index = L_shl( tbl_index, div_q ); + div_q = 0; + move16(); + } + IF( LE_32( tbl_index, 0 ) ) /* In case of extrapolation (below 1st bin), choose nearest */ { - combined_channels_L_re[freq_idx] = 0; - combined_channels_R_re[freq_idx] = 0; - combined_channels_L_im[freq_idx] = 0; - combined_channels_R_im[freq_idx] = 0; - - FOR(ch_index = 0; ch_index < 3; ch_index++) - { - combined_channels_L_re[freq_idx] = L_add(combined_channels_L_re[freq_idx], Mpy_32_16_1(ppHrtf_set_L_re[ch_index][base_idx + freq_idx], foa_sum_coeffs[hrtf_idx][ch_index])); - combined_channels_R_re[freq_idx] = L_add(combined_channels_R_re[freq_idx], Mpy_32_16_1(ppHrtf_set_R_re[ch_index][base_idx + freq_idx], foa_sum_coeffs[hrtf_idx][ch_index])); - combined_channels_L_im[freq_idx] = L_add(combined_channels_L_im[freq_idx], Mpy_32_16_1(ppHrtf_set_L_im[ch_index][base_idx + freq_idx], foa_sum_coeffs[hrtf_idx][ch_index])); - combined_channels_R_im[freq_idx] = L_add(combined_channels_R_im[freq_idx], Mpy_32_16_1(ppHrtf_set_R_im[ch_index][base_idx + freq_idx], foa_sum_coeffs[hrtf_idx][ch_index])); - } + base_idx = 0; + move32(); + relative_pos = 0; + move32(); + } + ELSE + { + base_idx = ( tbl_index ); // q = 21 + move32(); + relative_pos = L_shl( L_sub( tbl_index, L_shl( L_shr( base_idx, 11 ), 11 ) ), 20 ); // q = 31 + base_idx = L_shr( base_idx, 11 ); + IF( GT_32( base_idx, L_sub( in_freq_count, 2 ) ) ) /* In case of extrapolation (above last bin), choose nearest */ + { + base_idx = L_sub( in_freq_count, 2 ); + relative_pos = ONE_IN_Q31; + move32(); + } } - current_base_L_ptr_re = &combined_channels_L_re[0]; - current_base_R_ptr_re = &combined_channels_R_re[0]; - current_base_L_ptr_im = &combined_channels_L_im[0]; - current_base_R_ptr_im = &combined_channels_R_im[0]; - } - - FOR(freq_idx = 0; freq_idx < 2; freq_idx++) - { - Word32 L_re, L_im, R_re, R_im, C_re; - - L_re = current_base_L_ptr_re[freq_idx];//q = 29 - R_re = current_base_R_ptr_re[freq_idx];//q = 29 - L_im = current_base_L_ptr_im[freq_idx];//q = 29 - R_im = current_base_R_ptr_im[freq_idx];//q = 29 - move32(); move32(); move32(); move32(); - avg_pwr_left[freq_idx] = L_add(L_shr(L_add(Mpy_32_32(L_re, L_re), Mpy_32_32(L_im, L_im)), 4), avg_pwr_left[freq_idx]);//q = 23 - avg_pwr_right[freq_idx] = L_add(L_shr(L_add(Mpy_32_32(R_re, R_re), Mpy_32_32(R_im, R_im)), 4), avg_pwr_right[freq_idx]);//q = 23 - /* Cross product (Re part) */ - C_re = L_add(Mpy_32_32(L_re, R_re), Mpy_32_32(L_im, R_im));//q = 27 - - IA_coherence[freq_idx] = L_add(C_re, IA_coherence[freq_idx]);//q = 27 - } - } - - /* Compute the averages and the IA coherence */ - FOR(freq_idx = 0; freq_idx < 2; freq_idx++) - { - Word16 sqrt_exp = 0; - Word32 var1; - avg_pwr_left[freq_idx] = Mpy_32_16_1(avg_pwr_left[freq_idx], hrtf_count_inverted); //q = 23 - avg_pwr_right[freq_idx] = Mpy_32_16_1(avg_pwr_right[freq_idx], hrtf_count_inverted); //q = 23 - IF(EQ_32(avg_pwr_left[freq_idx], avg_pwr_right[freq_idx])) - { - var1 = avg_pwr_left[freq_idx]; move32(); - sqrt_exp = 4; move16(); - } - ELSE - { - var1 = Sqrt32(Mpy_32_32(avg_pwr_left[freq_idx], avg_pwr_right[freq_idx]), &sqrt_exp); move32(); - } - Word16 temp; - IA_coherence[freq_idx] = BASOP_Util_Divide3232_Scale(Mpy_32_16_1(IA_coherence[freq_idx], hrtf_count_inverted), L_shl(var1, sqrt_exp), &temp); //q =15 - IA_coherence[freq_idx] = L_shl(IA_coherence[freq_idx], 27 - (15 - temp));//q = 27 - /* Limiting to (0...1) range in case of small numerical errors or negative values */ - IA_coherence[freq_idx] = min(IA_coherence[freq_idx], ONE_IN_Q27); - IA_coherence[freq_idx] = max(IA_coherence[freq_idx], 0); - } - - /* Computing weighted average of 2 nearest values (1 below + 1 above) for linear interpolation */ - weight_1st = L_sub(ONE_IN_Q31, relative_pos); //q = 31 - - pOut_avg_pwr_L[out_bin_idx] = L_add(Mpy_32_32(weight_1st, avg_pwr_left[0]), Mpy_32_32(relative_pos, avg_pwr_left[1])); //q = 23 - pOut_avg_pwr_R[out_bin_idx] = L_add(Mpy_32_32(weight_1st, avg_pwr_right[0]), Mpy_32_32(relative_pos, avg_pwr_right[1])); //q = 23 - out_i_a_coherence[out_bin_idx] = L_add(Mpy_32_32(weight_1st, IA_coherence[0]), Mpy_32_32(relative_pos, IA_coherence[1])); //q = 27 - } + /* Computing 2 bins data for later interpolation */ + + /* Zeroing before accumalation for average value computing */ + avg_pwr_left[0] = 0; + move32(); + avg_pwr_left[1] = 0; + move32(); + avg_pwr_right[0] = 0; + move32(); + avg_pwr_right[1] = 0; + move32(); + IA_coherence[0] = 0; + move32(); + IA_coherence[1] = 0; + move32(); + + /* Get power spectra and cross - correlation between left and right hrtfs */ + /* Loop over all the HRTFs available */ + FOR( hrtf_idx = 0; hrtf_idx < used_hrtf_count; hrtf_idx++ ) + { + /* Pointers to current HRTF data */ + Word32 *current_base_L_ptr_re, *current_base_L_ptr_im, *current_base_R_ptr_re, *current_base_R_ptr_im; + + /* combined HRTF data used for FOA */ + Word32 combined_channels_L_re[2]; + Word32 combined_channels_L_im[2]; + Word32 combined_channels_R_re[2]; + Word32 combined_channels_R_im[2]; + + /* Process the frequency bins containing both real and img parts */ + /* In case of 5.1 or 7.1 formats, use the available HRTF paires directly*/ + IF( !is_ambisonics ) + { + current_base_L_ptr_re = ( ppHrtf_set_L_re[hrtf_idx] + base_idx ); + current_base_R_ptr_re = ( ppHrtf_set_R_re[hrtf_idx] + base_idx ); + current_base_L_ptr_im = ( ppHrtf_set_L_im[hrtf_idx] + base_idx ); + current_base_R_ptr_im = ( ppHrtf_set_R_im[hrtf_idx] + base_idx ); + } + + /* In case of FOA format, combine the W channel with the X/Y channels */ + ELSE + { + FOR( freq_idx = 0; freq_idx < 2; freq_idx++ ) + { + combined_channels_L_re[freq_idx] = 0; + combined_channels_R_re[freq_idx] = 0; + combined_channels_L_im[freq_idx] = 0; + combined_channels_R_im[freq_idx] = 0; + + FOR( ch_index = 0; ch_index < 3; ch_index++ ) + { + combined_channels_L_re[freq_idx] = L_add( combined_channels_L_re[freq_idx], Mpy_32_16_1( ppHrtf_set_L_re[ch_index][base_idx + freq_idx], foa_sum_coeffs[hrtf_idx][ch_index] ) ); + combined_channels_R_re[freq_idx] = L_add( combined_channels_R_re[freq_idx], Mpy_32_16_1( ppHrtf_set_R_re[ch_index][base_idx + freq_idx], foa_sum_coeffs[hrtf_idx][ch_index] ) ); + combined_channels_L_im[freq_idx] = L_add( combined_channels_L_im[freq_idx], Mpy_32_16_1( ppHrtf_set_L_im[ch_index][base_idx + freq_idx], foa_sum_coeffs[hrtf_idx][ch_index] ) ); + combined_channels_R_im[freq_idx] = L_add( combined_channels_R_im[freq_idx], Mpy_32_16_1( ppHrtf_set_R_im[ch_index][base_idx + freq_idx], foa_sum_coeffs[hrtf_idx][ch_index] ) ); + } + } + + current_base_L_ptr_re = &combined_channels_L_re[0]; + current_base_R_ptr_re = &combined_channels_R_re[0]; + current_base_L_ptr_im = &combined_channels_L_im[0]; + current_base_R_ptr_im = &combined_channels_R_im[0]; + } + + FOR( freq_idx = 0; freq_idx < 2; freq_idx++ ) + { + Word32 L_re, L_im, R_re, R_im, C_re; + + L_re = current_base_L_ptr_re[freq_idx]; // q = 29 + R_re = current_base_R_ptr_re[freq_idx]; // q = 29 + L_im = current_base_L_ptr_im[freq_idx]; // q = 29 + R_im = current_base_R_ptr_im[freq_idx]; // q = 29 + move32(); + move32(); + move32(); + move32(); + avg_pwr_left[freq_idx] = L_add( L_shr( L_add( Mpy_32_32( L_re, L_re ), Mpy_32_32( L_im, L_im ) ), 4 ), avg_pwr_left[freq_idx] ); // q = 23 + avg_pwr_right[freq_idx] = L_add( L_shr( L_add( Mpy_32_32( R_re, R_re ), Mpy_32_32( R_im, R_im ) ), 4 ), avg_pwr_right[freq_idx] ); // q = 23 + /* Cross product (Re part) */ + C_re = L_add( Mpy_32_32( L_re, R_re ), Mpy_32_32( L_im, R_im ) ); // q = 27 + + IA_coherence[freq_idx] = L_add( C_re, IA_coherence[freq_idx] ); // q = 27 + } + } + + /* Compute the averages and the IA coherence */ + FOR( freq_idx = 0; freq_idx < 2; freq_idx++ ) + { + Word16 sqrt_exp = 0; + Word32 var1; + avg_pwr_left[freq_idx] = Mpy_32_16_1( avg_pwr_left[freq_idx], hrtf_count_inverted ); // q = 23 + avg_pwr_right[freq_idx] = Mpy_32_16_1( avg_pwr_right[freq_idx], hrtf_count_inverted ); // q = 23 + IF( EQ_32( avg_pwr_left[freq_idx], avg_pwr_right[freq_idx] ) ) + { + var1 = avg_pwr_left[freq_idx]; + move32(); + sqrt_exp = 4; + move16(); + } + ELSE + { + var1 = Sqrt32( Mpy_32_32( avg_pwr_left[freq_idx], avg_pwr_right[freq_idx] ), &sqrt_exp ); + move32(); + } + Word16 temp; + IA_coherence[freq_idx] = BASOP_Util_Divide3232_Scale( Mpy_32_16_1( IA_coherence[freq_idx], hrtf_count_inverted ), L_shl( var1, sqrt_exp ), &temp ); // q =15 + IA_coherence[freq_idx] = L_shl( IA_coherence[freq_idx], 27 - ( 15 - temp ) ); // q = 27 + /* Limiting to (0...1) range in case of small numerical errors or negative values */ + IA_coherence[freq_idx] = min( IA_coherence[freq_idx], ONE_IN_Q27 ); + IA_coherence[freq_idx] = max( IA_coherence[freq_idx], 0 ); + } - return; + /* Computing weighted average of 2 nearest values (1 below + 1 above) for linear interpolation */ + weight_1st = L_sub( ONE_IN_Q31, relative_pos ); // q = 31 + + pOut_avg_pwr_L[out_bin_idx] = L_add( Mpy_32_32( weight_1st, avg_pwr_left[0] ), Mpy_32_32( relative_pos, avg_pwr_left[1] ) ); // q = 23 + pOut_avg_pwr_R[out_bin_idx] = L_add( Mpy_32_32( weight_1st, avg_pwr_right[0] ), Mpy_32_32( relative_pos, avg_pwr_right[1] ) ); // q = 23 + out_i_a_coherence[out_bin_idx] = L_add( Mpy_32_32( weight_1st, IA_coherence[0] ), Mpy_32_32( relative_pos, IA_coherence[1] ) ); // q = 27 + } + + return; } -#endif \ No newline at end of file +#endif diff --git a/lib_rend/ivas_reverb_iir_filter.c b/lib_rend/ivas_reverb_iir_filter.c index faf6f857f..03745f6b8 100644 --- a/lib_rend/ivas_reverb_iir_filter.c +++ b/lib_rend/ivas_reverb_iir_filter.c @@ -58,7 +58,7 @@ void ivas_reverb_iir_filt_init( iirFilter->nr_taps = 0; /* filter is set to PASS i.e. input copy to output */ iirFilter->Output_fx = 0; - FOR ( UWord16 i = 0; i < maxTaps; i++ ) + FOR( UWord16 i = 0; i < maxTaps; i++ ) { iirFilter->CoefA_fx[i] = 0; move32(); @@ -108,13 +108,13 @@ void ivas_reverb_iir_filt_init( void ivas_reverb_iir_filt_set( ivas_rev_iir_filter_t *iirFilter, /* i/o: IIR filter */ UWord16 nr_taps, /* i : number of IIR filter taps */ - const Word16 *coefA, /* i : A filter coefficients to set */ - const Word16 *coefB /* i : the B filter coefficients to set */ + const Word16 *coefA, /* i : A filter coefficients to set */ + const Word16 *coefB /* i : the B filter coefficients to set */ ) { UWord16 i; - IF ( GT_32(nr_taps , iirFilter->MaxTaps) ) + IF( GT_32( nr_taps, iirFilter->MaxTaps ) ) { nr_taps = (UWord16) iirFilter->MaxTaps; } @@ -122,19 +122,19 @@ void ivas_reverb_iir_filt_set( iirFilter->nr_taps = nr_taps; iirFilter->isFIR = ( coefA == NULL ); - IF ( iirFilter->isFIR != 0 ) + IF( iirFilter->isFIR != 0 ) { - FOR ( i = 0; i < iirFilter->nr_taps; i++ ) + FOR( i = 0; i < iirFilter->nr_taps; i++ ) { - iirFilter->CoefB_fx[i] = L_shl(coefB[i],16) ;/*Q30*/ + iirFilter->CoefB_fx[i] = L_shl( coefB[i], 16 ); /*Q30*/ } } ELSE { - FOR ( i = 0; i < iirFilter->nr_taps; i++ ) + FOR( i = 0; i < iirFilter->nr_taps; i++ ) { - iirFilter->CoefA_fx[i] = L_shl(coefA[i],16) ;/*Q30*/ - iirFilter->CoefB_fx[i] = L_shl(coefB[i],16) ;/*Q30*/ + iirFilter->CoefA_fx[i] = L_shl( coefA[i], 16 ); /*Q30*/ + iirFilter->CoefB_fx[i] = L_shl( coefB[i], 16 ); /*Q30*/ } } @@ -192,27 +192,27 @@ void ivas_reverb_iir_filt_set( void ivas_reverb_iir_filt_2taps_feed_blk_fx( ivas_rev_iir_filter_t *iirFilter, /* i/o: IIR filter */ - const UWord16 blk_size, /* i : size */ - const Word32 *input, /* i : input buffer */ - Word32 *output /* i : output buffer */ + const UWord16 blk_size, /* i : size */ + const Word32 *input, /* i : input buffer */ + Word32 *output /* i : output buffer */ ) { UWord16 i; Word32 flt_output_fx = 0; Word32 flt_CoefB_0_fx = iirFilter->CoefB_fx[0]; Word32 flt_CoefB_1_fx = iirFilter->CoefB_fx[1]; - Word32 flt_CoefA_1_fx = iirFilter->CoefA_fx[1] ; + Word32 flt_CoefA_1_fx = iirFilter->CoefA_fx[1]; Word32 flt_pBuffer_0_fx = iirFilter->pBuffer_fx[0]; - Word32 flt_pBuffer_1_fx = iirFilter->pBuffer_fx[1] ; + Word32 flt_pBuffer_1_fx = iirFilter->pBuffer_fx[1]; for ( i = 0; i < blk_size; i++ ) { flt_output_fx = L_add( Mpy_32_32( input[i] << 1, flt_CoefB_0_fx ), flt_pBuffer_0_fx ); flt_pBuffer_0_fx = L_sub( L_add( flt_pBuffer_1_fx, Mpy_32_32( input[i] << 1, flt_CoefB_1_fx ) ), Mpy_32_32( flt_output_fx << 1, flt_CoefA_1_fx ) ); - output[i] = flt_output_fx ; + output[i] = flt_output_fx; } - iirFilter->pBuffer_fx[0] = flt_pBuffer_0_fx ; + iirFilter->pBuffer_fx[0] = flt_pBuffer_0_fx; iirFilter->pBuffer_fx[1] = flt_pBuffer_1_fx; - iirFilter->Output_fx = flt_output_fx ; + iirFilter->Output_fx = flt_output_fx; return; } @@ -251,4 +251,4 @@ void ivas_reverb_iir_filt_2taps_feed_blk( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_rend/ivas_reverb_utils.c b/lib_rend/ivas_reverb_utils.c index 7e6af2b58..c1e22ff1c 100644 --- a/lib_rend/ivas_reverb_utils.c +++ b/lib_rend/ivas_reverb_utils.c @@ -96,34 +96,35 @@ ivas_error ivas_reverb_prepare_cldfb_params( fc[idx] = ( (float) idx + 0.5f ) * ( (float) MAX_SAMPLING_RATE / (float) ( 2 * CLDFB_NO_CHANNELS_MAX ) ); } #ifdef IVAS_FLOAT_FIXED - Word32* fc_fx = (Word32*)malloc(pInput_params->nBands * sizeof(Word32*)); - Word32* pOutput_t60_fx = (Word32*)malloc(pInput_params->nBands * sizeof(Word32*)); - Word16* pOutput_t60_e = (Word16*)malloc(pInput_params->nBands * sizeof(Word16*)); - Word32* pOutput_ene_fx = (Word32*)malloc(pInput_params->nBands * sizeof(Word32*)); - Word16* pOutput_ene_e = (Word16*)malloc(pInput_params->nBands * sizeof(Word16*)); + Word32 *fc_fx = (Word32 *) malloc( pInput_params->nBands * sizeof( Word32 * ) ); + Word32 *pOutput_t60_fx = (Word32 *) malloc( pInput_params->nBands * sizeof( Word32 * ) ); + Word16 *pOutput_t60_e = (Word16 *) malloc( pInput_params->nBands * sizeof( Word16 * ) ); + Word32 *pOutput_ene_fx = (Word32 *) malloc( pInput_params->nBands * sizeof( Word32 * ) ); + Word16 *pOutput_ene_e = (Word16 *) malloc( pInput_params->nBands * sizeof( Word16 * ) ); Word32 delay_diff_fx; - for (int i = 0; i < pInput_params->nBands; i++) + for ( int i = 0; i < pInput_params->nBands; i++ ) { - fc_fx[i] = (Word32)fc[i] * ONE_IN_Q16; + fc_fx[i] = (Word32) fc[i] * ONE_IN_Q16; } - ivas_reverb_interpolate_acoustic_data_fx(pInput_params->nBands, pInput_params->pFc_input_fx, pInput_params->pAcoustic_rt60_fx, pInput_params->pAcoustic_dsr_fx, - CLDFB_NO_CHANNELS_MAX, fc_fx, pOutput_t60_fx, pOutput_ene_fx, pOutput_t60_e, pOutput_ene_e); + ivas_reverb_interpolate_acoustic_data_fx( pInput_params->nBands, pInput_params->pFc_input_fx, pInput_params->pAcoustic_rt60_fx, pInput_params->pAcoustic_dsr_fx, + CLDFB_NO_CHANNELS_MAX, fc_fx, pOutput_t60_fx, pOutput_ene_fx, pOutput_t60_e, pOutput_ene_e ); /* adjust DSR for the delay difference */ - delay_diff_fx = L_sub(pInput_params->inputPreDelay_fx, pInput_params->acousticPreDelay_fx); + delay_diff_fx = L_sub( pInput_params->inputPreDelay_fx, pInput_params->acousticPreDelay_fx ); - delay_diff = (float)delay_diff_fx / ONE_IN_Q27; - for (int i = 0; i < pInput_params->nBands; i++) { - pOutput_t60[i] = (float)fabs(me2f(pOutput_t60_fx[i], pOutput_t60_e[i])); - pOutput_ene[i] = (float)fabs(me2f(pOutput_ene_fx[i], pOutput_ene_e[i])); + delay_diff = (float) delay_diff_fx / ONE_IN_Q27; + for ( int i = 0; i < pInput_params->nBands; i++ ) + { + pOutput_t60[i] = (float) fabs( me2f( pOutput_t60_fx[i], pOutput_t60_e[i] ) ); + pOutput_ene[i] = (float) fabs( me2f( pOutput_ene_fx[i], pOutput_ene_e[i] ) ); } - free(fc_fx); - free(pOutput_t60_fx); - free(pOutput_t60_e); - free(pOutput_ene_fx); - free(pOutput_ene_e); + free( fc_fx ); + free( pOutput_t60_fx ); + free( pOutput_t60_e ); + free( pOutput_ene_fx ); + free( pOutput_ene_e ); #else ivas_reverb_interpolate_acoustic_data( pInput_params->nBands, pInput_params->pFc_input, pInput_params->pAcoustic_rt60, pInput_params->pAcoustic_dsr, CLDFB_NO_CHANNELS_MAX, fc, pOutput_t60, pOutput_ene ); /* adjust DSR for the delay difference */ @@ -543,42 +544,43 @@ static ivas_error ivas_reverb_get_fastconv_hrtf_set_energies( return error; } #ifdef IVAS_FLOAT_FIXED - Word32* input_fc_fx = (Word32*)malloc(60 * sizeof(Word32*)); - Word32* avg_pwr_left_fft_fx = (Word32*)malloc(60 * sizeof(Word32*)); - Word32* avg_pwr_right_fft_fx = (Word32*)malloc(60 * sizeof(Word32*)); + Word32 *input_fc_fx = (Word32 *) malloc( 60 * sizeof( Word32 * ) ); + Word32 *avg_pwr_left_fft_fx = (Word32 *) malloc( 60 * sizeof( Word32 * ) ); + Word32 *avg_pwr_right_fft_fx = (Word32 *) malloc( 60 * sizeof( Word32 * ) ); - Word32* output_fc_fx = (Word32*)malloc(257 * sizeof(Word32*)); - Word32* avg_pwr_left_fx = (Word32*)malloc(257 * sizeof(Word32*)); - Word16* avg_pwr_left_e = (Word16*)malloc(257 * sizeof(Word16*)); - Word32* avg_pwr_right_fx = (Word32*)malloc(257 * sizeof(Word32*)); - Word16* avg_pwr_right_e = (Word16*)malloc(257 * sizeof(Word16*)); + Word32 *output_fc_fx = (Word32 *) malloc( 257 * sizeof( Word32 * ) ); + Word32 *avg_pwr_left_fx = (Word32 *) malloc( 257 * sizeof( Word32 * ) ); + Word16 *avg_pwr_left_e = (Word16 *) malloc( 257 * sizeof( Word16 * ) ); + Word32 *avg_pwr_right_fx = (Word32 *) malloc( 257 * sizeof( Word32 * ) ); + Word16 *avg_pwr_right_e = (Word16 *) malloc( 257 * sizeof( Word16 * ) ); - for (int i = 0; i < 60; i++) + for ( int i = 0; i < 60; i++ ) { - input_fc_fx[i] = (Word32)input_fc[i] * (1 << 16); - avg_pwr_left_fft_fx[i] = (Word32)(avg_pwr_left_fft[i]) * ONE_IN_Q26; - avg_pwr_right_fft_fx[i] = (Word32)avg_pwr_right_fft[i] * ONE_IN_Q30; + input_fc_fx[i] = (Word32) input_fc[i] * ( 1 << 16 ); + avg_pwr_left_fft_fx[i] = (Word32) ( avg_pwr_left_fft[i] ) * ONE_IN_Q26; + avg_pwr_right_fft_fx[i] = (Word32) avg_pwr_right_fft[i] * ONE_IN_Q30; } - for (int i = 0; i < 257; i++) + for ( int i = 0; i < 257; i++ ) { - output_fc_fx[i] = (Word32)input_fc[i] * ONE_IN_Q16; + output_fc_fx[i] = (Word32) input_fc[i] * ONE_IN_Q16; } - ivas_reverb_interpolate_acoustic_data_fx(FFT_SPECTRUM_SIZE, input_fc_fx, avg_pwr_left_fft_fx, avg_pwr_right_fft_fx, - CLDFB_NO_CHANNELS_MAX, output_fc_fx, avg_pwr_left_fx, avg_pwr_right_fx, avg_pwr_left_e, avg_pwr_right_e); - for (int i = 0; i < 257; i++) { - avg_pwr_left[i] = (float)fabs(me2f(avg_pwr_left_fx[i], avg_pwr_left_e[i])); - avg_pwr_right[i] =(float)fabs(me2f(avg_pwr_right_fx[i], avg_pwr_right_e[i])); + ivas_reverb_interpolate_acoustic_data_fx( FFT_SPECTRUM_SIZE, input_fc_fx, avg_pwr_left_fft_fx, avg_pwr_right_fft_fx, + CLDFB_NO_CHANNELS_MAX, output_fc_fx, avg_pwr_left_fx, avg_pwr_right_fx, avg_pwr_left_e, avg_pwr_right_e ); + for ( int i = 0; i < 257; i++ ) + { + avg_pwr_left[i] = (float) fabs( me2f( avg_pwr_left_fx[i], avg_pwr_left_e[i] ) ); + avg_pwr_right[i] = (float) fabs( me2f( avg_pwr_right_fx[i], avg_pwr_right_e[i] ) ); } - free(input_fc_fx); - free(avg_pwr_left_fft_fx); - free(avg_pwr_right_fft_fx); - free(output_fc_fx); - free(avg_pwr_left_fx); - free(avg_pwr_left_e); - free(avg_pwr_right_fx); - free(avg_pwr_right_e); + free( input_fc_fx ); + free( avg_pwr_left_fft_fx ); + free( avg_pwr_right_fft_fx ); + free( output_fc_fx ); + free( avg_pwr_left_fx ); + free( avg_pwr_left_e ); + free( avg_pwr_right_fx ); + free( avg_pwr_right_e ); #else ivas_reverb_interpolate_acoustic_data( FFT_SPECTRUM_SIZE, input_fc, avg_pwr_left_fft, avg_pwr_right_fft, CLDFB_NO_CHANNELS_MAX, output_fc, avg_pwr_left, avg_pwr_right ); #endif diff --git a/lib_rend/ivas_rom_TdBinauralRenderer.h b/lib_rend/ivas_rom_TdBinauralRenderer.h index d34cff1e8..e5fef4121 100644 --- a/lib_rend/ivas_rom_TdBinauralRenderer.h +++ b/lib_rend/ivas_rom_TdBinauralRenderer.h @@ -65,12 +65,12 @@ extern const uint32_t defaultHRIR_rom_EL16[HRTF_MODEL_N_SECTIONS * 470]; extern const uint32_t defaultHRIR_rom_ER16[HRTF_MODEL_N_SECTIONS * 470]; extern const uint32_t defaultHRIR_rom_elevBsShape[36]; #ifdef IVAS_FLOAT_FIXED -extern const UWord32 defaultHRIR_rom_AlphaL48_fx[470 * 128]; /*Q30*/ -extern const UWord32 defaultHRIR_rom_AlphaR48_fx[470 * 128]; /*Q30*/ -extern const UWord32 defaultHRIR_rom_AlphaL32_fx[470 * 86]; /*Q30*/ -extern const UWord32 defaultHRIR_rom_AlphaR32_fx[470 * 86]; /*Q30*/ -extern const UWord32 defaultHRIR_rom_AlphaL16_fx[470 * 43]; /*Q30*/ -extern const UWord32 defaultHRIR_rom_AlphaR16_fx[470 * 43]; /*Q30*/ +extern const UWord32 defaultHRIR_rom_AlphaL48_fx[470 * 128]; /*Q30*/ +extern const UWord32 defaultHRIR_rom_AlphaR48_fx[470 * 128]; /*Q30*/ +extern const UWord32 defaultHRIR_rom_AlphaL32_fx[470 * 86]; /*Q30*/ +extern const UWord32 defaultHRIR_rom_AlphaR32_fx[470 * 86]; /*Q30*/ +extern const UWord32 defaultHRIR_rom_AlphaL16_fx[470 * 43]; /*Q30*/ +extern const UWord32 defaultHRIR_rom_AlphaR16_fx[470 * 43]; /*Q30*/ extern const UWord32 defaultHRIR_rom_EL48_fx[HRTF_MODEL_N_SECTIONS * 470]; /*Q28*/ extern const UWord32 defaultHRIR_rom_ER48_fx[HRTF_MODEL_N_SECTIONS * 470]; /*Q28*/ extern const UWord32 defaultHRIR_rom_EL32_fx[HRTF_MODEL_N_SECTIONS * 470]; /*Q28*/ @@ -79,11 +79,11 @@ extern const UWord32 defaultHRIR_rom_EL16_fx[HRTF_MODEL_N_SECTIONS * 470]; /*Q28 extern const UWord32 defaultHRIR_rom_ER16_fx[HRTF_MODEL_N_SECTIONS * 470]; /*Q28*/ #endif #ifdef IVAS_FLOAT_FIXED -extern const Word32 defaultHRIR_rom_elevBsShape_fx[36];/*Q30*/ +extern const Word32 defaultHRIR_rom_elevBsShape_fx[36]; /*Q30*/ #endif extern const uint32_t defaultHRIR_rom_azimBsShape[21]; #ifdef IVAS_FLOAT_FIXED -extern const Word32 defaultHRIR_rom_azimBsShape_fx[21];/*Q30*/ +extern const Word32 defaultHRIR_rom_azimBsShape_fx[21]; /*Q30*/ #endif extern const uint32_t defaultHRIR_rom_ITD_W[658]; extern const uint32_t defaultHRIR_rom_ITD_azimBsShape[84]; @@ -91,9 +91,9 @@ extern const float defaultHRIR_rom_ITD_azimKSeq[19]; extern const uint32_t defaultHRIR_rom_ITD_elevBsShape[28]; extern const float defaultHRIR_rom_ITD_elevKSeq[16]; #ifdef IVAS_FLOAT_FIXED -extern const UWord32 defaultHRIR_rom_ITD_W_fx[658];/*Q25*/ -extern const Word32 defaultHRIR_rom_ITD_elevKSeq_fx[16];/*Q22*/ -extern const Word32 defaultHRIR_rom_ITD_elevBsShape_fx[28];/*Q30*/ -extern const Word32 defaultHRIR_rom_ITD_azimKSeq_fx[19];/*Q22*/ -extern const Word32 defaultHRIR_rom_ITD_azimBsShape_fx[84];/*Q30*/ -#endif // IVAS_FLOAT_FIXED +extern const UWord32 defaultHRIR_rom_ITD_W_fx[658]; /*Q25*/ +extern const Word32 defaultHRIR_rom_ITD_elevKSeq_fx[16]; /*Q22*/ +extern const Word32 defaultHRIR_rom_ITD_elevBsShape_fx[28]; /*Q30*/ +extern const Word32 defaultHRIR_rom_ITD_azimKSeq_fx[19]; /*Q22*/ +extern const Word32 defaultHRIR_rom_ITD_azimBsShape_fx[84]; /*Q30*/ +#endif // IVAS_FLOAT_FIXED diff --git a/lib_rend/ivas_rom_rend.h b/lib_rend/ivas_rom_rend.h index 04730ad97..3ccdaa007 100644 --- a/lib_rend/ivas_rom_rend.h +++ b/lib_rend/ivas_rom_rend.h @@ -66,7 +66,7 @@ extern const Word16 *const ap_lattice_coeffs_fx[DIRAC_DECORR_NUM_SPLIT_BANDS]; extern const float ap_split_frequencies[DIRAC_DECORR_NUM_SPLIT_BANDS + 1]; #ifdef IVAS_FLOAT_FIXED extern const Word16 ap_split_frequencies_fx[DIRAC_DECORR_NUM_SPLIT_BANDS + 1]; -extern const Word16 ap_lattice_delta_phi_fx[DIRAC_MAX_NUM_DECORR_FILTERS*DIRAC_MAX_DECORR_FILTER_LEN]; +extern const Word16 ap_lattice_delta_phi_fx[DIRAC_MAX_NUM_DECORR_FILTERS * DIRAC_MAX_DECORR_FILTER_LEN]; #endif extern const int16_t sba_map_tc[11]; @@ -136,7 +136,7 @@ extern const Word32 defaultHRIR_right_avg_power_32kHz_fx[LR_IAC_LENGTH_NR_FC]; / extern const Word32 defaultHRIR_coherence_16kHz_fx[LR_IAC_LENGTH_NR_FC]; /*Q-27*/ extern const Word32 defaultHRIR_left_avg_power_16kHz_fx[LR_IAC_LENGTH_NR_FC]; /*Q-23*/ extern const Word32 defaultHRIR_right_avg_power_16kHz_fx[LR_IAC_LENGTH_NR_FC]; /*Q-23*/ -#endif // IVAS_FLOAT_FIXED +#endif // IVAS_FLOAT_FIXED /*----------------------------------------------------------------------------------* * t-design and SN3D normalization table *----------------------------------------------------------------------------------*/ diff --git a/lib_rend/ivas_rotation.c b/lib_rend/ivas_rotation.c index df75987f4..be96d186f 100644 --- a/lib_rend/ivas_rotation.c +++ b/lib_rend/ivas_rotation.c @@ -217,12 +217,12 @@ void ivas_headTrack_close( HEAD_TRACK_DATA_HANDLE *hHeadTrackData /* i/o: head track handle */ ) { - IF ( hHeadTrackData == NULL || *hHeadTrackData == NULL ) + IF( hHeadTrackData == NULL || *hHeadTrackData == NULL ) { return; } - IF ( ( *hHeadTrackData )->OrientationTracker != NULL ) + IF( ( *hHeadTrackData )->OrientationTracker != NULL ) { free( ( *hHeadTrackData )->OrientationTracker ); ( *hHeadTrackData )->OrientationTracker = NULL; @@ -400,13 +400,13 @@ float deg2rad( Word32 deg2rad_fx( Word32 degrees ) { - WHILE ( GE_32(degrees , DEGREE_180 )) + WHILE( GE_32( degrees, DEGREE_180 ) ) { - degrees = L_sub(degrees , DEGREE_360); + degrees = L_sub( degrees, DEGREE_360 ); } - WHILE( LE_32(degrees , -DEGREE_180) ) + WHILE( LE_32( degrees, -DEGREE_180 ) ) { - degrees = L_add(degrees , DEGREE_360); + degrees = L_add( degrees, DEGREE_360 ); } return Mpy_32_32( PI_OVER_180_FX, degrees ); @@ -438,13 +438,13 @@ Word32 rad2deg_fx( Word32 radians ) { - WHILE ( GE_32(radians , EVS_PI_FX) ) + WHILE( GE_32( radians, EVS_PI_FX ) ) { - radians = L_sub(radians, EVS_PI_FX); + radians = L_sub( radians, EVS_PI_FX ); } - WHILE(LE_32( radians , -EVS_PI_FX) ) + WHILE( LE_32( radians, -EVS_PI_FX ) ) { - radians = L_add(radians , EVS_PI_FX); + radians = L_add( radians, EVS_PI_FX ); } return ( radians * _180_OVER_PI_FX ); @@ -597,8 +597,8 @@ void rotateAziEle_fx_frac_az_el( azi_in = GT_32( azi_in, 0 ) ? ( azi_in - _360_IN_Q22 ) : ( azi_in + _360_IN_Q22 ); move32(); } - azi_in_q13 = (Word16)L_shr( Mpy_32_32( azi_in, PI_OVER_180_FX ), Q9 ); - ele_in_q13 = (Word16)L_shr( Mpy_32_32( ele_in, PI_OVER_180_FX ), Q9 ); + azi_in_q13 = (Word16) L_shr( Mpy_32_32( azi_in, PI_OVER_180_FX ), Q9 ); + ele_in_q13 = (Word16) L_shr( Mpy_32_32( ele_in, PI_OVER_180_FX ), Q9 ); w_fx = getCosWord16( ele_in_q13 ); // Q14 dv_fx[0] = L_mult( w_fx, getCosWord16( azi_in_q13 ) ); IF( EQ_32( dv_fx[0], ONE_IN_Q29 ) ) @@ -738,7 +738,7 @@ void rotateAziEle_fixed( move32(); x = dv_r_fx[0]; move32(); - radian = BASOP_util_atan2( y, x, 0 ); // Q13 + radian = BASOP_util_atan2( y, x, 0 ); // Q13 angle = L_shr( Mpy_32_16_1( _180_OVER_PI_Q25, radian ), 1 ); // Q22 @@ -805,10 +805,10 @@ void rotateAziEle( { dv_r[n] = Rmat[n][0] * dv[0] + Rmat[n][1] * dv[1] + Rmat[n][2] * dv[2]; } - //float inter, inter1, inter2; - //inter = atan2f( dv_r[1], dv_r[0] ); - //inter1 = min( 180.0f, atan2f( dv_r[1], dv_r[0] ) * _180_OVER_PI ); - //inter2 = max( -180.0f, min( 180.0f, atan2f( dv_r[1], dv_r[0] ) * _180_OVER_PI ) ); + // float inter, inter1, inter2; + // inter = atan2f( dv_r[1], dv_r[0] ); + // inter1 = min( 180.0f, atan2f( dv_r[1], dv_r[0] ) * _180_OVER_PI ); + // inter2 = max( -180.0f, min( 180.0f, atan2f( dv_r[1], dv_r[0] ) * _180_OVER_PI ) ); /*Conversion cartesian to spherical coordinates*/ *azi = (int16_t) roundf( max( -180.0f, min( 180.0f, atan2f( dv_r[1], dv_r[0] ) * _180_OVER_PI ) ) ); if ( isPlanar == 0 ) @@ -917,7 +917,6 @@ void rotateFrame_shd( m1 = m2; move16(); m2 = add( m2, add( shl( add( l, 1 ), 1 ), 1 ) ); - } /* unoptimized code for reference (full matrix multiplication) @@ -1084,7 +1083,7 @@ void rotateFrame_sd( Word32 output_tmp_fx[MAX_CICP_CHANNELS][L_FRAME48k]; Word32 cross_fade_fx[L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES]; push_wmops( "rotateFrame_sd" ); - nchan = add(hTransSetup.nchan_out_woLFE , hTransSetup.num_lfe); + nchan = add( hTransSetup.nchan_out_woLFE, hTransSetup.num_lfe ); index_lfe = hTransSetup.index_lfe[0]; move16(); SWITCH( subframe_len ) @@ -1131,11 +1130,11 @@ void rotateFrame_sd( ch_in_woLFE = ( ch_in >= index_lfe ) ? sub( ch_in, 1 ) : ch_in; /* gains for previous subframe rotation */ - rotateAziEle_fx((Word16)L_shr(hTransSetup.ls_azimuth_fx[ch_in_woLFE], Q22), (Word16)L_shr(hTransSetup.ls_elevation_fx[ch_in_woLFE], Q22), &azimuth, &elevation, hCombinedOrientationData->Rmat_prev_fx, hTransSetup.is_planar_setup); + rotateAziEle_fx( (Word16) L_shr( hTransSetup.ls_azimuth_fx[ch_in_woLFE], Q22 ), (Word16) L_shr( hTransSetup.ls_elevation_fx[ch_in_woLFE], Q22 ), &azimuth, &elevation, hCombinedOrientationData->Rmat_prev_fx, hTransSetup.is_planar_setup ); test(); test(); - IF( hEFAPdata != NULL && ((Word16)L_shr(hTransSetup.ls_azimuth_fx[ch_in_woLFE], Q22) != azimuth || (Word16)L_shr(hTransSetup.ls_elevation_fx[ch_in_woLFE], Q22) != elevation ) ) + IF( hEFAPdata != NULL && ( (Word16) L_shr( hTransSetup.ls_azimuth_fx[ch_in_woLFE], Q22 ) != azimuth || (Word16) L_shr( hTransSetup.ls_elevation_fx[ch_in_woLFE], Q22 ) != elevation ) ) { azimuth_fx = L_shl( (Word32) azimuth, Q22 ); elevation_fx = L_shl( (Word32) elevation, Q22 ); @@ -1151,15 +1150,15 @@ void rotateFrame_sd( } /* output channel index without LFE */ - ch_out_woLFE = ( ch_out >= index_lfe ) ? sub(ch_out , 1) : ch_out; + ch_out_woLFE = ( ch_out >= index_lfe ) ? sub( ch_out, 1 ) : ch_out; gains_prev_fx[ch_in][ch_out] = tmp_gains_fx[ch_out_woLFE]; // Q30 } } /* gains for current subframe rotation */ - rotateAziEle_fx((Word16)L_shr(hTransSetup.ls_azimuth_fx[ch_in_woLFE], Q22), (Word16)L_shr(hTransSetup.ls_elevation_fx[ch_in_woLFE], Q22), &azimuth, &elevation, hCombinedOrientationData->Rmat_fx[hCombinedOrientationData->subframe_idx], hTransSetup.is_planar_setup); + rotateAziEle_fx( (Word16) L_shr( hTransSetup.ls_azimuth_fx[ch_in_woLFE], Q22 ), (Word16) L_shr( hTransSetup.ls_elevation_fx[ch_in_woLFE], Q22 ), &azimuth, &elevation, hCombinedOrientationData->Rmat_fx[hCombinedOrientationData->subframe_idx], hTransSetup.is_planar_setup ); - IF( hEFAPdata != NULL && ((Word16)L_shr(hTransSetup.ls_azimuth_fx[ch_in_woLFE], Q22) != azimuth || (Word16)L_shr(hTransSetup.ls_elevation_fx[ch_in_woLFE], Q22) != elevation ) ) + IF( hEFAPdata != NULL && ( (Word16) L_shr( hTransSetup.ls_azimuth_fx[ch_in_woLFE], Q22 ) != azimuth || (Word16) L_shr( hTransSetup.ls_elevation_fx[ch_in_woLFE], Q22 ) != elevation ) ) { azimuth_fx = L_shl( (Word32) azimuth, Q22 ); @@ -1175,7 +1174,7 @@ void rotateFrame_sd( } /* output channel index without LFE */ - ch_out_woLFE = ( ch_out >= index_lfe ) ? sub(ch_out, 1) : ch_out; + ch_out_woLFE = ( ch_out >= index_lfe ) ? sub( ch_out, 1 ) : ch_out; gains_fx[ch_in][ch_out] = tmp_gains_fx[ch_out_woLFE]; // Q30 } @@ -1189,12 +1188,12 @@ void rotateFrame_sd( { j = 0; /* crossfade with previous rotation gains */ - FOR( i = subframe_idx * subframe_len; j < subframe_len; i++ ) + FOR( i = subframe_idx * subframe_len; j < subframe_len; i++ ) { out_temp = output[ch_in][i]; move32(); Word32 temp = Mpy_32_32( Mpy_32_32( ( cross_fade_fx[j] ), gains_fx[ch_in][ch_out] ), out_temp ); - Word32 temp1 = Mpy_32_32( Mpy_32_32(L_sub ( ONE_IN_Q31 , cross_fade_fx[j] ), gains_prev_fx[ch_in][ch_out] ), out_temp ); + Word32 temp1 = Mpy_32_32( Mpy_32_32( L_sub( ONE_IN_Q31, cross_fade_fx[j] ), gains_prev_fx[ch_in][ch_out] ), out_temp ); output_tmp_fx[ch_out][i] = L_add( L_shl( L_add( temp, temp1 ), 1 ), output_tmp_fx[ch_out][i] ); j++; } @@ -1707,8 +1706,8 @@ void rotateFrame_sd_cldfb_fixed( /* rotation of Euler angles */ FOR( n = 0; n < nInChannels; n++ ) { - rotateAziEle_fx((Word16)L_shr(hOutputSetup->ls_azimuth_fx[n], Q22), (Word16)L_shr(hOutputSetup->ls_elevation_fx[n], Q22), &azimuth, &elevation, Rmat_fx, isPlanar); - IF( hEFAPdata != NULL && ((Word16)L_shr(hOutputSetup->ls_azimuth_fx[n], Q22) != azimuth || (Word16)L_shr(hOutputSetup->ls_elevation_fx[n], Q22) != elevation ) ) + rotateAziEle_fx( (Word16) L_shr( hOutputSetup->ls_azimuth_fx[n], Q22 ), (Word16) L_shr( hOutputSetup->ls_elevation_fx[n], Q22 ), &azimuth, &elevation, Rmat_fx, isPlanar ); + IF( hEFAPdata != NULL && ( (Word16) L_shr( hOutputSetup->ls_azimuth_fx[n], Q22 ) != azimuth || (Word16) L_shr( hOutputSetup->ls_elevation_fx[n], Q22 ) != elevation ) ) { // efap_determine_gains( hEFAPdata, gains[n], azimuth, elevation, EFAP_MODE_EFAP ); efap_determine_gains_fx( hEFAPdata, gains_fx[n], L_shl( azimuth, Q22 ), L_shl( elevation, Q22 ), EFAP_MODE_EFAP ); @@ -1744,9 +1743,9 @@ void rotateFrame_sd_cldfb_fixed( move32(); FOR( iBand = 0; iBand < nb_band; iBand++ ) { - *( p_realRot_fx ) =L_add( *p_realRot_fx , Mpy_32_32( g1_fx, *( p_real_fx++ ) )); + *( p_realRot_fx ) = L_add( *p_realRot_fx, Mpy_32_32( g1_fx, *( p_real_fx++ ) ) ); move32(); - *( p_imagRot_fx ) =L_add( *p_imagRot_fx , Mpy_32_32( g1_fx, *( p_imag_fx++ ) )); + *( p_imagRot_fx ) = L_add( *p_imagRot_fx, Mpy_32_32( g1_fx, *( p_imag_fx++ ) ) ); move32(); p_realRot_fx++; p_imagRot_fx++; @@ -2968,18 +2967,18 @@ static bool are_orientations_same_fx( move16(); move16(); Word32 w_result = 0, x_result = 0, y_result = 0, z_result = 0; - w_result = L_abs( BASOP_Util_Add_Mant32Exp( orientation1->w_fx, sub(31 , orientation1->q_fact), L_negate( orientation2->w_fx ), sub(31 , orientation2->q_fact), &w_e ) ); - x_result = L_abs( BASOP_Util_Add_Mant32Exp( orientation1->x_fx, sub(31 , orientation1->q_fact), L_negate( orientation2->x_fx ), sub(31 , orientation2->q_fact), &x_e ) ); - y_result = L_abs( BASOP_Util_Add_Mant32Exp( orientation1->y_fx, sub(31 , orientation1->q_fact), L_negate( orientation2->y_fx ), sub(31 , orientation2->q_fact), &y_e ) ); - z_result = L_abs( BASOP_Util_Add_Mant32Exp( orientation1->z_fx, sub(31 , orientation1->q_fact), L_negate( orientation2->z_fx ), sub(31 , orientation2->q_fact), &z_e ) ); + w_result = L_abs( BASOP_Util_Add_Mant32Exp( orientation1->w_fx, sub( 31, orientation1->q_fact ), L_negate( orientation2->w_fx ), sub( 31, orientation2->q_fact ), &w_e ) ); + x_result = L_abs( BASOP_Util_Add_Mant32Exp( orientation1->x_fx, sub( 31, orientation1->q_fact ), L_negate( orientation2->x_fx ), sub( 31, orientation2->q_fact ), &x_e ) ); + y_result = L_abs( BASOP_Util_Add_Mant32Exp( orientation1->y_fx, sub( 31, orientation1->q_fact ), L_negate( orientation2->y_fx ), sub( 31, orientation2->q_fact ), &y_e ) ); + z_result = L_abs( BASOP_Util_Add_Mant32Exp( orientation1->z_fx, sub( 31, orientation1->q_fact ), L_negate( orientation2->z_fx ), sub( 31, orientation2->q_fact ), &z_e ) ); Word16 Flag_1 = BASOP_Util_Cmp_Mant32Exp( w_result, w_e, error_margin_fx, error_margin_e ); Word16 Flag_2 = BASOP_Util_Cmp_Mant32Exp( x_result, x_e, error_margin_fx, error_margin_e ); Word16 Flag_3 = BASOP_Util_Cmp_Mant32Exp( y_result, y_e, error_margin_fx, error_margin_e ); Word16 Flag_4 = BASOP_Util_Cmp_Mant32Exp( z_result, z_e, error_margin_fx, error_margin_e ); - IF( EQ_16( Flag_1 , 1 ) || - EQ_16( Flag_2 , 1 ) || - EQ_16( Flag_3 , 1 ) || - EQ_16( Flag_4 , 1 ) ) + IF( EQ_16( Flag_1, 1 ) || + EQ_16( Flag_2, 1 ) || + EQ_16( Flag_3, 1 ) || + EQ_16( Flag_4, 1 ) ) { orientationsAreSame = false; } @@ -3043,7 +3042,7 @@ static Word32 SHrot_p_fx( ri0 = SHrotmat[i + 1 + 1][0 + 1 + 1]; move16(); - IF ( EQ_16( b, -l ) ) + IF( EQ_16( b, -l ) ) { R_lm1_1 = R_lm1[a + l - 1][0]; move16(); @@ -3053,9 +3052,9 @@ static Word32 SHrot_p_fx( } ELSE { - IF ( EQ_16( b, l ) ) + IF( EQ_16( b, l ) ) { - R_lm1_1 = R_lm1[a + l - 1][sub( shl( l, 1 ), 2 ) ]; + R_lm1_1 = R_lm1[a + l - 1][sub( shl( l, 1 ), 2 )]; R_lm1_2 = R_lm1[a + l - 1][0]; p = L_msu0( L_mult0( ri1, R_lm1_1 ), rim1, R_lm1_2 ); } @@ -3219,15 +3218,15 @@ static Word32 SHrot_v_fx( Word32 p0, p1; Word16 d; - IF ( EQ_16( m, 0 ) ) + IF( EQ_16( m, 0 ) ) { p0 = SHrot_p_fx( 1, l, 1, n, SHrotmat, R_lm1 ); // Q28 p1 = SHrot_p_fx( -1, l, -1, n, SHrotmat, R_lm1 ); // Q28 - result = L_shr( L_add( p0, p1 ), 2 ); // converting to Q27 + result = L_shr( L_add( p0, p1 ), 2 ); // converting to Q27 } ELSE { - IF ( GT_16( m, 0 ) ) + IF( GT_16( m, 0 ) ) { d = ( m == 1 ) ? 1 : 0; p0 = (Word32) SHrot_p_fx( 1, l, m - 1, n, SHrotmat, R_lm1 ); @@ -3254,14 +3253,14 @@ static Word32 SHrot_w_fx( { Word32 result, p0, p1; - IF ( EQ_16( m, 0 ) ) + IF( EQ_16( m, 0 ) ) { printf( "ERROR should not be called\n" ); return 0; } ELSE { - IF ( GT_16( m, 0 ) ) + IF( GT_16( m, 0 ) ) { p0 = SHrot_p_fx( 1, l, m + 1, n, SHrotmat, R_lm1 ); p1 = SHrot_p_fx( -1, l, -m - 1, n, SHrotmat, R_lm1 ); @@ -3317,9 +3316,9 @@ void SHrotmatgen_fx( Word16 R_lm1[HEADROT_SHMAT_DIM][HEADROT_SHMAT_DIM]; #ifdef MSAN_FIX - FOR(i = 0; i < HEADROT_SHMAT_DIM; i++) + FOR( i = 0; i < HEADROT_SHMAT_DIM; i++ ) { - set_s(R_lm1[i], 0, HEADROT_SHMAT_DIM); + set_s( R_lm1[i], 0, HEADROT_SHMAT_DIM ); } #endif Word16 R_l[HEADROT_SHMAT_DIM][HEADROT_SHMAT_DIM]; @@ -3339,9 +3338,9 @@ void SHrotmatgen_fx( SHrotmat[3][2] = extract_h( Rmat[0][2] ); SHrotmat[3][3] = extract_h( Rmat[0][0] ); - FOR ( i = 0; i < 2 * 1 + 1; i++ ) + FOR( i = 0; i < 2 * 1 + 1; i++ ) { - FOR ( j = 0; j < 2 * 1 + 1; j++ ) + FOR( j = 0; j < 2 * 1 + 1; j++ ) { R_lm1[i][j] = SHrotmat[i + 1][j + 1]; move16(); @@ -3349,66 +3348,66 @@ void SHrotmatgen_fx( } band_idx = 4; move16(); - FOR ( l = 2; l <= order; l++ ) + FOR( l = 2; l <= order; l++ ) { set_val_Word16( &R_l[0][0], 0, HEADROT_SHMAT_DIM2 ); - FOR ( m = -l; m <= l; m++ ) + FOR( m = -l; m <= l; m++ ) { d = ( m == 0 ) ? 1 : 0; absm = (Word16) abs( m ); - sql2mm2 = square_root30_q12[sub( imult1616(l, l), imult1616(m, m))]; - sqdabsm = square_root30_q12[imult1616(add(1, d), imult1616(sub(add( l, absm), 1), add(l, absm)))]; + sql2mm2 = square_root30_q12[sub( imult1616( l, l ), imult1616( m, m ) )]; + sqdabsm = square_root30_q12[imult1616( add( 1, d ), imult1616( sub( add( l, absm ), 1 ), add( l, absm ) ) )]; sqlabsm = square_root30_q12[imult1616( sub( l, add( absm, 1 ) ), sub( l, absm ) )]; - FOR ( n = -l; n <= l; n++ ) + FOR( n = -l; n <= l; n++ ) { - IF ( EQ_16( abs_s( n ), l ) ) + IF( EQ_16( abs_s( n ), l ) ) { sqdenom = square_root30_q12[imult1616( shl( l, 1 ), sub( shl( l, 1 ), 1 ) )]; } ELSE { - sqdenom = square_root30_q12[sub(imult1616( l, l ), imult1616( n, n) )]; + sqdenom = square_root30_q12[sub( imult1616( l, l ), imult1616( n, n ) )]; } - u = div_l( L_shl( (Word32) sql2mm2, 15 ), sqdenom ); // Q14 - v = imult1616( div_l( L_shl( (Word32) sqdabsm, 14 ), sqdenom ), sub( 1, shl( d, 1 ) ) ); // Q14 + u = div_l( L_shl( (Word32) sql2mm2, 15 ), sqdenom ); // Q14 + v = imult1616( div_l( L_shl( (Word32) sqdabsm, 14 ), sqdenom ), sub( 1, shl( d, 1 ) ) ); // Q14 w = imult1616( div_l( L_shl( (Word32) sqlabsm, 14 ), sqdenom ), negate( sub( 1, d ) ) ); // Q14 - IF ( NE_16( u, 0 ) ) + IF( NE_16( u, 0 ) ) { result = SHrot_u_fx( l, m, n, SHrotmat, R_lm1 ); // Q28 u32_fx = Mpy_32_16_r( result, u ); // Q27 } - IF ( NE_16( v, 0 ) ) + IF( NE_16( v, 0 ) ) { result = SHrot_v_fx( l, m, n, SHrotmat, R_lm1 ); v32_fx = Mpy_32_16_r( result, v ); // Q26 } - IF ( NE_16( w, 0 ) ) + IF( NE_16( w, 0 ) ) { result = SHrot_w_fx( l, m, n, SHrotmat, R_lm1 ); w32_fx = Mpy_32_16_r( result, w ); // Q27 } // Addind and converting to 16 bit integer of Q14 - R_l[m + l][n + l] = extract_h( L_add( L_add( L_shr( u32_fx, 1 ), v32_fx ), L_shr( w32_fx, 1 ) ) * L_shl( 1, 4 ) ); // Q14 + R_l[m + l][n + l] = extract_h( L_add( L_add( L_shr( u32_fx, 1 ), v32_fx ), L_shr( w32_fx, 1 ) ) * L_shl( 1, 4 ) ); // Q14 } } - FOR ( i = 0; i < 2 * l + 1; i++ ) + FOR( i = 0; i < 2 * l + 1; i++ ) { - FOR ( j = 0; j < 2 * l + 1; j++ ) + FOR( j = 0; j < 2 * l + 1; j++ ) { SHrotmat[band_idx + i][band_idx + j] = R_l[i][j]; move16(); } } - FOR ( i = 0; i < 2 * l + 1; i++ ) + FOR( i = 0; i < 2 * l + 1; i++ ) { - FOR ( j = 0; j < 2 * l + 1; j++ ) + FOR( j = 0; j < 2 * l + 1; j++ ) { R_lm1[i][j] = R_l[i][j]; move16(); @@ -3697,4 +3696,4 @@ void ivas_combined_orientation_update_start_index( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_rend/ivas_sba_rendering.c b/lib_rend/ivas_sba_rendering.c index 4822e544b..6a71233a3 100644 --- a/lib_rend/ivas_sba_rendering.c +++ b/lib_rend/ivas_sba_rendering.c @@ -133,7 +133,7 @@ void ivas_sba_prototype_renderer_fx( /* determine SPAR parameters FOR this time slot */ md_idx = hSpar->render_to_md_map[ts + slot_idx_start]; // delete below - //floatToFixed_arr( hSpar->hFbMixer->cldfb_cross_fade, hSpar->hFbMixer->cldfb_cross_fade_fx, Q15, CLDFB_NO_COL_MAX ); + // floatToFixed_arr( hSpar->hFbMixer->cldfb_cross_fade, hSpar->hFbMixer->cldfb_cross_fade_fx, Q15, CLDFB_NO_COL_MAX ); ivas_spar_get_parameters_fx( hSpar, hDecoderConfig, md_idx, numch_out, numch_in, num_spar_bands, mixer_mat_fx ); @@ -145,7 +145,7 @@ void ivas_sba_prototype_renderer_fx( ivas_fb_bin_to_band_data_t *bin2band = &hSpar->hFbMixer->pFb->fb_bin_to_band; // delete below - //FOR( int idx = 0; idx < CLDFB_NO_CHANNELS_MAX; idx++ ) + // FOR( int idx = 0; idx < CLDFB_NO_CHANNELS_MAX; idx++ ) //{ // floatToFixed_arrL( bin2band->pp_cldfb_weights_per_spar_band[idx], bin2band->pp_cldfb_weights_per_spar_band_fx[idx], Q31, IVAS_MAX_NUM_FB_BANDS ); //} @@ -248,163 +248,163 @@ void ivas_sba_prototype_renderer_fx( return; } -#else +#else void ivas_sba_prototype_renderer( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder struct */ - float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Input audio in CLDFB domain, real */ - float inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Input audio in CLDFB domain, imag */ - const int16_t subframe /* i : Subframe to render */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder struct */ + float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Input audio in CLDFB domain, real */ + float inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Input audio in CLDFB domain, imag */ + const int16_t subframe /* i : Subframe to render */ ) { - float mixer_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; - SPAR_DEC_HANDLE hSpar; - DECODER_CONFIG_HANDLE hDecoderConfig; - int16_t num_spar_bands, spar_band; - int16_t b, ts; - int16_t num_cldfb_bands, numch_in, numch_out; - int16_t cldfb_band; - int16_t out_ch, in_ch; - int16_t firstInCh, inChEnd, firstOutCh, outChEnd; - int16_t slot_idx_start, md_idx; - int16_t num_md_sub_frames; - - num_md_sub_frames = ivas_get_spar_dec_md_num_subframes(st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate); - - push_wmops("ivas_sba_prototype_renderer"); - - hSpar = st_ivas->hSpar; - hDecoderConfig = st_ivas->hDecoderConfig; - num_spar_bands = hSpar->hFbMixer->pFb->filterbank_num_bands; - - num_cldfb_bands = hSpar->hFbMixer->pFb->fb_bin_to_band.num_cldfb_bands; - numch_in = hSpar->hFbMixer->fb_cfg->num_in_chans; - numch_out = hSpar->hFbMixer->fb_cfg->num_out_chans; - slot_idx_start = hSpar->slots_rendered; - - if (st_ivas->nchan_transport == 1) - { - firstInCh = 0; - inChEnd = 1; - firstOutCh = 0; - outChEnd = 1; - } - else /* 2 TC */ - { - firstInCh = 0; - inChEnd = 2; - firstOutCh = 1; - outChEnd = 2; - } - - /* Apply mixing matrix */ - for (ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++) - { - /* determine SPAR parameters for this time slot */ - md_idx = hSpar->render_to_md_map[ts + slot_idx_start]; - ivas_spar_get_parameters(hSpar, hDecoderConfig, md_idx, numch_out, numch_in, num_spar_bands, mixer_mat); - - for (cldfb_band = 0; cldfb_band < num_cldfb_bands; cldfb_band++) + float mixer_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; + SPAR_DEC_HANDLE hSpar; + DECODER_CONFIG_HANDLE hDecoderConfig; + int16_t num_spar_bands, spar_band; + int16_t b, ts; + int16_t num_cldfb_bands, numch_in, numch_out; + int16_t cldfb_band; + int16_t out_ch, in_ch; + int16_t firstInCh, inChEnd, firstOutCh, outChEnd; + int16_t slot_idx_start, md_idx; + int16_t num_md_sub_frames; + + num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ); + + push_wmops( "ivas_sba_prototype_renderer" ); + + hSpar = st_ivas->hSpar; + hDecoderConfig = st_ivas->hDecoderConfig; + num_spar_bands = hSpar->hFbMixer->pFb->filterbank_num_bands; + + num_cldfb_bands = hSpar->hFbMixer->pFb->fb_bin_to_band.num_cldfb_bands; + numch_in = hSpar->hFbMixer->fb_cfg->num_in_chans; + numch_out = hSpar->hFbMixer->fb_cfg->num_out_chans; + slot_idx_start = hSpar->slots_rendered; + + if ( st_ivas->nchan_transport == 1 ) + { + firstInCh = 0; + inChEnd = 1; + firstOutCh = 0; + outChEnd = 1; + } + else /* 2 TC */ { - float out_re[IVAS_SPAR_MAX_CH]; - float out_im[IVAS_SPAR_MAX_CH]; - float cldfb_par; - ivas_fb_bin_to_band_data_t *bin2band = &hSpar->hFbMixer->pFb->fb_bin_to_band; + firstInCh = 0; + inChEnd = 2; + firstOutCh = 1; + outChEnd = 2; + } - for (out_ch = firstOutCh; out_ch < outChEnd; out_ch++) - { - out_re[out_ch] = 0.0f; - out_im[out_ch] = 0.0f; + /* Apply mixing matrix */ + for ( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ ) + { + /* determine SPAR parameters for this time slot */ + md_idx = hSpar->render_to_md_map[ts + slot_idx_start]; + ivas_spar_get_parameters( hSpar, hDecoderConfig, md_idx, numch_out, numch_in, num_spar_bands, mixer_mat ); - for (in_ch = firstInCh; in_ch < inChEnd; in_ch++) + for ( cldfb_band = 0; cldfb_band < num_cldfb_bands; cldfb_band++ ) { - if (cldfb_band < CLDFB_PAR_WEIGHT_START_BAND) /* tuning parameter, depends on how much SPAR Filters overlap for the CLDFB bands */ - { - spar_band = bin2band->p_cldfb_map_to_spar_band[cldfb_band]; - cldfb_par = mixer_mat[out_ch][in_ch][spar_band]; - } - else - { - cldfb_par = 0.0f; - for (spar_band = bin2band->p_spar_start_bands[cldfb_band]; spar_band < num_spar_bands; spar_band++) + float out_re[IVAS_SPAR_MAX_CH]; + float out_im[IVAS_SPAR_MAX_CH]; + float cldfb_par; + ivas_fb_bin_to_band_data_t *bin2band = &hSpar->hFbMixer->pFb->fb_bin_to_band; + + for ( out_ch = firstOutCh; out_ch < outChEnd; out_ch++ ) { - /* accumulate contributions from all SPAR bands */ - cldfb_par += mixer_mat[out_ch][in_ch][spar_band] * bin2band->pp_cldfb_weights_per_spar_band[cldfb_band][spar_band]; + out_re[out_ch] = 0.0f; + out_im[out_ch] = 0.0f; + + for ( in_ch = firstInCh; in_ch < inChEnd; in_ch++ ) + { + if ( cldfb_band < CLDFB_PAR_WEIGHT_START_BAND ) /* tuning parameter, depends on how much SPAR Filters overlap for the CLDFB bands */ + { + spar_band = bin2band->p_cldfb_map_to_spar_band[cldfb_band]; + cldfb_par = mixer_mat[out_ch][in_ch][spar_band]; + } + else + { + cldfb_par = 0.0f; + for ( spar_band = bin2band->p_spar_start_bands[cldfb_band]; spar_band < num_spar_bands; spar_band++ ) + { + /* accumulate contributions from all SPAR bands */ + cldfb_par += mixer_mat[out_ch][in_ch][spar_band] * bin2band->pp_cldfb_weights_per_spar_band[cldfb_band][spar_band]; + } + } + + out_re[out_ch] += inRe[in_ch][ts][cldfb_band] * cldfb_par; + out_im[out_ch] += inIm[in_ch][ts][cldfb_band] * cldfb_par; + } } - } - out_re[out_ch] += inRe[in_ch][ts][cldfb_band] * cldfb_par; - out_im[out_ch] += inIm[in_ch][ts][cldfb_band] * cldfb_par; + /*update CLDFB data with the parameter-modified data*/ + for ( out_ch = firstOutCh; out_ch < outChEnd; out_ch++ ) + { + inRe[out_ch][ts][cldfb_band] = out_re[out_ch]; + inIm[out_ch][ts][cldfb_band] = out_im[out_ch]; + } } - } - - /*update CLDFB data with the parameter-modified data*/ - for (out_ch = firstOutCh; out_ch < outChEnd; out_ch++) - { - inRe[out_ch][ts][cldfb_band] = out_re[out_ch]; - inIm[out_ch][ts][cldfb_band] = out_im[out_ch]; - } - } - /* Update mixing matrices */ - if (((slot_idx_start + ts + 1) == hSpar->num_slots) || ((md_idx / JBM_CLDFB_SLOTS_IN_SUBFRAME) != (hSpar->render_to_md_map[ts + slot_idx_start + 1] / JBM_CLDFB_SLOTS_IN_SUBFRAME))) - { - /* we have crossed an unadapted parameter sf border, update previous mixing matrices */ - int16_t md_sf = md_idx / JBM_CLDFB_SLOTS_IN_SUBFRAME; - md_sf = (num_md_sub_frames == MAX_PARAM_SPATIAL_SUBFRAMES) ? md_sf : 0; - hSpar->i_subframe++; - hSpar->i_subframe = min(hSpar->i_subframe, MAX_PARAM_SPATIAL_SUBFRAMES); - mvr2r(hSpar->hMdDec->mixer_mat_prev[1][0][0], hSpar->hMdDec->mixer_mat_prev[0][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS); - mvr2r(hSpar->hMdDec->mixer_mat_prev[2][0][0], hSpar->hMdDec->mixer_mat_prev[1][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS); - mvr2r(hSpar->hMdDec->mixer_mat_prev[3][0][0], hSpar->hMdDec->mixer_mat_prev[2][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS); - mvr2r(hSpar->hMdDec->mixer_mat_prev[4][0][0], hSpar->hMdDec->mixer_mat_prev[3][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS); - - for (out_ch = 0; out_ch < numch_out; out_ch++) - { - for (in_ch = 0; in_ch < numch_in; in_ch++) + /* Update mixing matrices */ + if ( ( ( slot_idx_start + ts + 1 ) == hSpar->num_slots ) || ( ( md_idx / JBM_CLDFB_SLOTS_IN_SUBFRAME ) != ( hSpar->render_to_md_map[ts + slot_idx_start + 1] / JBM_CLDFB_SLOTS_IN_SUBFRAME ) ) ) { - for (b = 0; b < num_spar_bands; b++) - { - hSpar->hMdDec->mixer_mat_prev[4][out_ch][in_ch][b] = hSpar->hMdDec->mixer_mat[out_ch][in_ch][b + md_sf * IVAS_MAX_NUM_BANDS]; - } + /* we have crossed an unadapted parameter sf border, update previous mixing matrices */ + int16_t md_sf = md_idx / JBM_CLDFB_SLOTS_IN_SUBFRAME; + md_sf = ( num_md_sub_frames == MAX_PARAM_SPATIAL_SUBFRAMES ) ? md_sf : 0; + hSpar->i_subframe++; + hSpar->i_subframe = min( hSpar->i_subframe, MAX_PARAM_SPATIAL_SUBFRAMES ); + mvr2r( hSpar->hMdDec->mixer_mat_prev[1][0][0], hSpar->hMdDec->mixer_mat_prev[0][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); + mvr2r( hSpar->hMdDec->mixer_mat_prev[2][0][0], hSpar->hMdDec->mixer_mat_prev[1][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); + mvr2r( hSpar->hMdDec->mixer_mat_prev[3][0][0], hSpar->hMdDec->mixer_mat_prev[2][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); + mvr2r( hSpar->hMdDec->mixer_mat_prev[4][0][0], hSpar->hMdDec->mixer_mat_prev[3][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); + + for ( out_ch = 0; out_ch < numch_out; out_ch++ ) + { + for ( in_ch = 0; in_ch < numch_in; in_ch++ ) + { + for ( b = 0; b < num_spar_bands; b++ ) + { + hSpar->hMdDec->mixer_mat_prev[4][out_ch][in_ch][b] = hSpar->hMdDec->mixer_mat[out_ch][in_ch][b + md_sf * IVAS_MAX_NUM_BANDS]; + } + } + } } - } } - } - /* Create prototypes */ - if (st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM) - { - for (ts = 0; ts < hSpar->subframe_nbslots[subframe]; ts++) + /* Create prototypes */ + if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) { - if (st_ivas->nchan_transport == 1) /* Dual mono */ - { - mvr2r(inRe[0][ts], inRe[1][ts], CLDFB_NO_CHANNELS_MAX); - mvr2r(inIm[0][ts], inIm[1][ts], CLDFB_NO_CHANNELS_MAX); - } - else if (st_ivas->nchan_transport == 2) /* Opposing cardioids */ - { - float temp_signal[CLDFB_NO_CHANNELS_MAX]; - - v_add(inRe[0][ts], inRe[1][ts], temp_signal, CLDFB_NO_CHANNELS_MAX); - v_sub(inRe[0][ts], inRe[1][ts], inRe[1][ts], CLDFB_NO_CHANNELS_MAX); - mvr2r(temp_signal, inRe[0][ts], CLDFB_NO_CHANNELS_MAX); - v_multc(inRe[0][ts], 0.5f, inRe[0][ts], CLDFB_NO_CHANNELS_MAX); - v_multc(inRe[1][ts], 0.5f, inRe[1][ts], CLDFB_NO_CHANNELS_MAX); - - v_add(inIm[0][ts], inIm[1][ts], temp_signal, CLDFB_NO_CHANNELS_MAX); - v_sub(inIm[0][ts], inIm[1][ts], inIm[1][ts], CLDFB_NO_CHANNELS_MAX); - mvr2r(temp_signal, inIm[0][ts], CLDFB_NO_CHANNELS_MAX); - v_multc(inIm[0][ts], 0.5f, inIm[0][ts], CLDFB_NO_CHANNELS_MAX); - v_multc(inIm[1][ts], 0.5f, inIm[1][ts], CLDFB_NO_CHANNELS_MAX); - } + for ( ts = 0; ts < hSpar->subframe_nbslots[subframe]; ts++ ) + { + if ( st_ivas->nchan_transport == 1 ) /* Dual mono */ + { + mvr2r( inRe[0][ts], inRe[1][ts], CLDFB_NO_CHANNELS_MAX ); + mvr2r( inIm[0][ts], inIm[1][ts], CLDFB_NO_CHANNELS_MAX ); + } + else if ( st_ivas->nchan_transport == 2 ) /* Opposing cardioids */ + { + float temp_signal[CLDFB_NO_CHANNELS_MAX]; + + v_add( inRe[0][ts], inRe[1][ts], temp_signal, CLDFB_NO_CHANNELS_MAX ); + v_sub( inRe[0][ts], inRe[1][ts], inRe[1][ts], CLDFB_NO_CHANNELS_MAX ); + mvr2r( temp_signal, inRe[0][ts], CLDFB_NO_CHANNELS_MAX ); + v_multc( inRe[0][ts], 0.5f, inRe[0][ts], CLDFB_NO_CHANNELS_MAX ); + v_multc( inRe[1][ts], 0.5f, inRe[1][ts], CLDFB_NO_CHANNELS_MAX ); + + v_add( inIm[0][ts], inIm[1][ts], temp_signal, CLDFB_NO_CHANNELS_MAX ); + v_sub( inIm[0][ts], inIm[1][ts], inIm[1][ts], CLDFB_NO_CHANNELS_MAX ); + mvr2r( temp_signal, inIm[0][ts], CLDFB_NO_CHANNELS_MAX ); + v_multc( inIm[0][ts], 0.5f, inIm[0][ts], CLDFB_NO_CHANNELS_MAX ); + v_multc( inIm[1][ts], 0.5f, inIm[1][ts], CLDFB_NO_CHANNELS_MAX ); + } + } } - } - hSpar->subframes_rendered++; - hSpar->slots_rendered += hSpar->subframe_nbslots[subframe]; - pop_wmops(); + hSpar->subframes_rendered++; + hSpar->slots_rendered += hSpar->subframe_nbslots[subframe]; + pop_wmops(); - return; + return; } #endif diff --git a/lib_rend/ivas_shoebox.c b/lib_rend/ivas_shoebox.c index 0e27d6cad..18ff7da30 100644 --- a/lib_rend/ivas_shoebox.c +++ b/lib_rend/ivas_shoebox.c @@ -868,7 +868,7 @@ void ivas_shoebox_set_scene( move16(); move16(); /* ------------- CHECK DIMENSIONS ------------- */ - if ( GE_16(ER_PARAMS->n_sources , obj->MAX_SOURCES) ) + if ( GE_16( ER_PARAMS->n_sources, obj->MAX_SOURCES ) ) { obj->nSrc = obj->MAX_SOURCES; } @@ -876,33 +876,33 @@ void ivas_shoebox_set_scene( { obj->nSrc = ER_PARAMS->n_sources; } - move16(); + move16(); - set_l( &obj->src_pos_fx[0], 0, 75U ); + set_l( &obj->src_pos_fx[0], 0, 75U ); obj->list_pos_fx[0] = list_pos_fx[0]; obj->list_pos_fx[1] = list_pos_fx[1]; obj->list_pos_fx[2] = list_pos_fx[2]; - move32(); - move32(); - move32(); + move32(); + move32(); + move32(); /* ---------- ADJUST LISTENER ------------- */ - IF( NE_16(obj->isZHeight , 0) ) + IF( NE_16( obj->isZHeight, 0 ) ) { - obj->list_pos_fx[2] = L_sub(list_pos_fx[2] , L_shr( obj->cal.room_H_fx , 1 )); // Q.22 + obj->list_pos_fx[2] = L_sub( list_pos_fx[2], L_shr( obj->cal.room_H_fx, 1 ) ); // Q.22 } tmp_pos_fx[1] = obj->list_pos_fx[1]; tmp_pos_fx[2] = obj->list_pos_fx[2]; move32(); - move32(); + move32(); shoebox_bound_fx( obj, obj->list_pos_fx ); /* ---------- SOURCE LOOP ------------- */ i = (Word32) obj->nSrc; - move32(); - FOR ( j = 0; j < i; j++ ) + move32(); + FOR( j = 0; j < i; j++ ) { Word32 fcnOutput_data_fx[3], scale_fx; Word32 rcoselev; @@ -913,10 +913,10 @@ void ivas_shoebox_set_scene( /* GET COORDINATE IN CARTESIAN ABSOLUTE FORMAT */ k = out_tmp; move32(); - n = L_add(out_tmp, 3); - coord = L_add(out_tmp , 1); + n = L_add( out_tmp, 3 ); + coord = L_add( out_tmp, 1 ); - loop_ub =L_sub( n , k); + loop_ub = L_sub( n, k ); FOR( n = 0; n < loop_ub; n++ ) { @@ -930,7 +930,7 @@ void ivas_shoebox_set_scene( scale_fx = ER_EUCLIDEAN_SCALE_FX; move32(); out_tmp_fx = shoebox_get_euclidian_distance_internal_fx( obj, tmp_pos_fx, &scale_fx ); - q_format = sub(Q31, Q22); + q_format = sub( Q31, Q22 ); out_tmp_fx = Sqrt32( out_tmp_fx, &q_format ); out_tmp_fx = Mpy_32_32( scale_fx, out_tmp_fx ); obj->src_dist_fx[j] = L_shl( out_tmp_fx, q_format ); // Q22 @@ -950,7 +950,7 @@ void ivas_shoebox_set_scene( out_tmp_fx = obj->src_dist_fx[j]; move32(); - FOR ( loop_ub = 0; loop_ub < 6; loop_ub++ ) + FOR( loop_ub = 0; loop_ub < 6; loop_ub++ ) { Word32 im_pos_fx[3]; @@ -962,8 +962,8 @@ void ivas_shoebox_set_scene( Word16 q_format_n; /* Retrieve coordinate and surface sign */ - coord = L_shr(loop_ub , 1); // tbl - rcoselev = L_add(L_add( loop_ub , 1 ) , ( ER_PARAMS->n_ref * j )); + coord = L_shr( loop_ub, 1 ); // tbl + rcoselev = L_add( L_add( loop_ub, 1 ), ( ER_PARAMS->n_ref * j ) ); /* Initialize image position coordinates */ im_pos_fx[0] = tmp_pos_fx[0]; // Q:22 @@ -974,12 +974,12 @@ void ivas_shoebox_set_scene( move32(); /* Calculate image projection coordinate based on current surface axis */ - IF( LT_32(L_add( loop_ub , 1 ) , 3) ) + IF( LT_32( L_add( loop_ub, 1 ), 3 ) ) { scale_fx = obj->cal.room_L_fx; // Q:22 move32(); } - ELSE IF( LT_32(L_add( loop_ub , 1 ) , 5 )) + ELSE IF( LT_32( L_add( loop_ub, 1 ), 5 ) ) { scale_fx = obj->cal.room_W_fx; // Q:22 move32(); @@ -996,11 +996,11 @@ void ivas_shoebox_set_scene( ( ( ( ( ( -( 1 - ( ( ( loop_ub + 1 ) & 1 ) << 1 ) ) ) * scale_fx ) >> 1 ) - tmp_pos_fx[coord] ) << 1 ); // Q:22 /* 0. Get euclidean distance from IMAGE SOURCE [N,W] to LIST */ - scale_fx = ER_EUCLIDEAN_SCALE_FX; // Q:22 + scale_fx = ER_EUCLIDEAN_SCALE_FX; // Q:22 move32(); path_dist_fx = shoebox_get_euclidian_distance_internal_fx( obj, im_pos_fx, &scale_fx ); // Uutput :Q:22 - q_format =sub(Q31, Q22); + q_format = sub( Q31, Q22 ); path_dist_fx = Sqrt32( path_dist_fx, &q_format ); // Input: Q:22, Output : Q.30 path_dist_fx = Mpy_32_32( scale_fx, path_dist_fx ); // Q22 * Q = Q @@ -1011,9 +1011,9 @@ void ivas_shoebox_set_scene( ER_PARAMS->times.data_fx[rcoselev - 1] = Mpy_32_32( path_dist_fx, obj->soundspeed_fx ); // Q.22 /* 2./3. DOA */ - sub_im_nd_list_pos_1 = L_sub(im_pos_fx[1] , obj->list_pos_fx[1]); // Q.22 - sub_im_nd_list_pos_0 = L_sub(im_pos_fx[0] , obj->list_pos_fx[0]); // Q.22 - q_format = sub(Q22, Q22); + sub_im_nd_list_pos_1 = L_sub( im_pos_fx[1], obj->list_pos_fx[1] ); // Q.22 + sub_im_nd_list_pos_0 = L_sub( im_pos_fx[0], obj->list_pos_fx[0] ); // Q.22 + q_format = sub( Q22, Q22 ); atan_pos = BASOP_util_atan2( sub_im_nd_list_pos_1, sub_im_nd_list_pos_0, q_format ); // Q.13 az_angle_d = rad2deg_fx( atan_pos ); // Q.23 ER_PARAMS->az_angle.data_fx[rcoselev - 1] = az_angle_d; @@ -1028,13 +1028,13 @@ void ivas_shoebox_set_scene( sub_im_nd_list_div_path_sq = Mpy_32_32( sub_im_nd_list_div_path, sub_im_nd_list_div_path ); sub_im_nd_list_div_path_sq = L_shr( sub_im_nd_list_div_path_sq, 1 ); one_minus_sub_im_nd_list_div_path_sq = L_sub( L_shl( 1, Q30 ), sub_im_nd_list_div_path_sq ); - q_format1 = sub(Q31, Q30); + q_format1 = sub( Q31, Q30 ); one_minus_sub_im_nd_list_div_path_sq_rt = Sqrt32( one_minus_sub_im_nd_list_div_path_sq, &q_format1 ); one_minus_sub_im_nd_list_div_path_sq_rt = L_shl( one_minus_sub_im_nd_list_div_path_sq_rt, q_format1 ); - q_format_n = sub(Q31, Q31); + q_format_n = sub( Q31, Q31 ); asin_val = BASOP_util_atan2( sub_im_nd_list_div_path, one_minus_sub_im_nd_list_div_path_sq_rt, q_format_n ); // Q13 asin_val_deg = rad2deg_fx( asin_val ); // Q.23 @@ -1044,7 +1044,7 @@ void ivas_shoebox_set_scene( /* 4. Compute gain taking into account air and surface absorption */ /* and propagation loss */ - if ( LT_32(path_dist_fx , out_tmp_fx )) + if ( LT_32( path_dist_fx, out_tmp_fx ) ) { path_dist_fx = out_tmp_fx; move32(); @@ -1056,12 +1056,11 @@ void ivas_shoebox_set_scene( out_tmp_div_path_dist = BASOP_Util_Divide3232_Scale( out_tmp_fx, path_dist_fx, &q_format_n ); // Q22/Q.22 product = Mpy_32_32( one_minus_abs_coeff, out_tmp_div_path_dist ); // Q.30 *Q.15 product = L_shl( product, q_format_n ); // Q14 - product = L_shl( product, Q8 ); // Q22 + product = L_shl( product, Q8 ); // Q22 pro_pd_air_coeff = Mpy_32_32( path_dist_fx, obj->air_coeff_fx ); // Q.22 *Q.31 =Q.22 - result_gain =L_sub( product , pro_pd_air_coeff); + result_gain = L_sub( product, pro_pd_air_coeff ); ER_PARAMS->gains.data_fx[rcoselev - 1] = result_gain; - } } return; diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index c6f192f4c..5ff6707a5 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -164,10 +164,10 @@ typedef struct dirac_decorr_params_structure float *phase_coeff_real; float *phase_coeff_imag; #else - Word16 *filter_coeff_num_real_fx; /* Q12 */ - Word16 *filter_coeff_den_real_fx; /* Q12 */ - Word16 *phase_coeff_real_fx; /* Q14 */ - Word16 *phase_coeff_imag_fx; /* Q14 */ + Word16 *filter_coeff_num_real_fx; /* Q12 */ + Word16 *filter_coeff_den_real_fx; /* Q12 */ + Word16 *phase_coeff_real_fx; /* Q14 */ + Word16 *phase_coeff_imag_fx; /* Q14 */ #endif int16_t *split_frequency_bands; int16_t num_split_frequency_bands; @@ -225,8 +225,8 @@ typedef struct ivas_spatial_parametric_rend_common_data_structure #else Word32 **diffuseness_vector_fx; Word16 q_diffuseness_vector; - Word32 **energy_ratio1_fx; /* Q30 */ - Word32 **energy_ratio2_fx; /* Q30 */ + Word32 **energy_ratio1_fx; /* Q30 */ + Word32 **energy_ratio2_fx; /* Q30 */ #endif #ifndef IVAS_FLOAT_FIXED @@ -234,9 +234,9 @@ typedef struct ivas_spatial_parametric_rend_common_data_structure float **spreadCoherence2; float **surroundingCoherence; #else - Word16 **spreadCoherence_fx; /* Q15 */ - Word16 **spreadCoherence2_fx; /* Q15 */ - Word16 **surroundingCoherence_fx; /* Q15 */ + Word16 **spreadCoherence_fx; /* Q15 */ + Word16 **spreadCoherence2_fx; /* Q15 */ + Word16 **surroundingCoherence_fx; /* Q15 */ #endif /* Metadata access indices and buffer size */ @@ -316,7 +316,7 @@ typedef struct dirac_dec_stack_mem Word16 reference_power_q; Word16 reference_power_smooth_q; Word16 reference_power_len; - Word32 *onset_filter_fx; /* Q31 */ + Word32 *onset_filter_fx; /* Q31 */ #endif } DIRAC_DEC_STACK_MEM, *DIRAC_DEC_STACK_MEM_HANDLE; @@ -333,9 +333,9 @@ typedef struct dirac_output_synthesis_params_structure float *alpha_synthesis; float *alpha_synthesis_fast; #else - Word16 *interpolator_fx; /* Q15 */ - Word16 *alpha_synthesis_fx; /* Q15 */ - Word16 *alpha_synthesis_fast_fx; /* Q15 */ + Word16 *interpolator_fx; /* Q15 */ + Word16 *alpha_synthesis_fx; /* Q15 */ + Word16 *alpha_synthesis_fast_fx; /* Q15 */ #endif int16_t numAlphas; int16_t numAlphasFast; @@ -351,8 +351,8 @@ typedef struct dirac_output_synthesis_params_structure float diffuse_compensation_factor; float diffuse_compensation_factor_decorr; #else - Word32 diffuse_compensation_factor_fx; /* Q27 */ - Word32 diffuse_compensation_factor_decorr_fx; /* Q29 */ + Word32 diffuse_compensation_factor_fx; /* Q27 */ + Word32 diffuse_compensation_factor_decorr_fx; /* Q29 */ #endif } DIRAC_OUTPUT_SYNTHESIS_PARAMS; @@ -409,7 +409,7 @@ typedef struct dirac_output_synthesis_state_structure #else Word32 *reference_power_smooth_prev_fx; /* Q(reference_power_smooth_prev_q) */ Word16 reference_power_smooth_prev_q; - Word32 *direction_smoothness_prev_fx; /* Q31 */ + Word32 *direction_smoothness_prev_fx; /* Q31 */ #endif #ifdef IVAS_FLOAT_FIXED @@ -426,13 +426,13 @@ typedef struct dirac_output_synthesis_state_structure Word16 direct_power_factor_q; Word16 diffuse_power_factor_q; - Word32 *proto_power_smooth_fx; /* Smoothed power of the prototype signals. Size: num_freq_bands*num_channels. */ + Word32 *proto_power_smooth_fx; /* Smoothed power of the prototype signals. Size: num_freq_bands*num_channels. */ Word16 proto_power_smooth_q; Word16 proto_power_smooth_len; Word32 *proto_power_smooth_prev_fx; /* Smoothed power of the prototype signals of the previous synthesis block. Size: num_freq_bands*num_channels. */ Word16 proto_power_smooth_prev_q; Word16 proto_power_smooth_prev_len; - + Word32 *proto_power_diff_smooth_fx; Word32 *proto_power_diff_smooth_prev_fx; Word16 proto_power_diff_smooth_prev_len; @@ -441,7 +441,7 @@ typedef struct dirac_output_synthesis_state_structure Word16 proto_power_diff_smooth_len; /* only pointer to local buffers */ - Word32 *proto_direct_buffer_f_fx; /* Buffer for direct sound prototype signals. Size: 2*num_freq_bands*num_channels*buffer_length (complex interleaved). */ + Word32 *proto_direct_buffer_f_fx; /* Buffer for direct sound prototype signals. Size: 2*num_freq_bands*num_channels*buffer_length (complex interleaved). */ Word16 proto_direct_buffer_f_q; Word16 proto_direct_buffer_f_len; Word32 *proto_diffuse_buffer_f_fx; /* Buffer for diffuse sound prototype signals. Size: 2*num_freq_bands*num_channels*buffer_length (complex interleaved). */ @@ -501,7 +501,7 @@ typedef struct float right_bb_power; float total_bb_power; #else - Word32 left_bb_power_fx; /* Q(q_left_bb_power) */ + Word32 left_bb_power_fx; /* Q(q_left_bb_power) */ Word16 q_left_bb_power; Word32 right_bb_power_fx; /* Q(q_right_bb_power) */ Word16 q_right_bb_power; @@ -579,52 +579,52 @@ typedef struct ivas_mcmasa_lfe_synth_struct #else Word32 transportEneSmooth_fx; /* transportEneSmooth_q */ Word16 transportEneSmooth_q; - Word32 protoLfeEneSmooth_fx; /* protoLfeEneSmooth_q */ + Word32 protoLfeEneSmooth_fx; /* protoLfeEneSmooth_q */ Word16 protoLfeEneSmooth_q; - Word32 targetEneLfeSmooth_fx; /* targetEneLfeSmooth_q */ + Word32 targetEneLfeSmooth_fx; /* targetEneLfeSmooth_q */ Word16 targetEneLfeSmooth_q; - Word32 targetEneTransSmooth_fx; /* targetEneTransSmooth_q */ + Word32 targetEneTransSmooth_fx; /* targetEneTransSmooth_q */ Word16 targetEneTransSmooth_q; #endif #ifndef IVAS_FLOAT_FIXED float *lfeSynthRingBuffer; #else - Word32 *lfeSynthRingBuffer_fx; /* Q11 */ + Word32 *lfeSynthRingBuffer_fx; /* Q11 */ #endif int16_t ringBufferLoPointer; int16_t ringBufferHiPointer; #ifndef IVAS_FLOAT_FIXED float lowpassSum; #else - Word32 lowpassSum_fx; /* Q11 */ + Word32 lowpassSum_fx; /* Q11 */ #endif int16_t ringBufferSize; #ifndef IVAS_FLOAT_FIXED float *lfeSynthRingBuffer2; #else - Word32 *lfeSynthRingBuffer2_fx; /* Q11 */ + Word32 *lfeSynthRingBuffer2_fx; /* Q11 */ #endif int16_t ringBufferLoPointer2; #ifndef IVAS_FLOAT_FIXED float lowpassSum2; #else - Word32 lowpassSum2_fx; /* Q11 */ + Word32 lowpassSum2_fx; /* Q11 */ #endif int16_t ringBufferSize2; #ifndef IVAS_FLOAT_FIXED float *delayBuffer_syncLp; #else - Word32 *delayBuffer_syncLp_fx; /* Q11 */ + Word32 *delayBuffer_syncLp_fx; /* Q11 */ #endif int16_t delayBuffer_syncLp_size; #ifndef IVAS_FLOAT_FIXED float *delayBuffer_syncDirAC; #else - Word32 *delayBuffer_syncDirAC_fx; /* Q11 */ + Word32 *delayBuffer_syncDirAC_fx; /* Q11 */ #endif int16_t delayBuffer_syncDirAC_size; @@ -633,9 +633,9 @@ typedef struct ivas_mcmasa_lfe_synth_struct float transportGainPrev; float interpolator[CLDFB_NO_CHANNELS_MAX]; #else - Word16 lfeGainPrev_fx; /* Q15 */ - Word16 transportGainPrev_fx; /* Q15 */ - Word16 interpolator_fx[CLDFB_NO_CHANNELS_MAX]; /* Q15 */ + Word16 lfeGainPrev_fx; /* Q15 */ + Word16 transportGainPrev_fx; /* Q15 */ + Word16 interpolator_fx[CLDFB_NO_CHANNELS_MAX]; /* Q15 */ #endif } MCMASA_LFE_SYNTH_DATA, *MCMASA_LFE_SYNTH_DATA_HANDLE; @@ -653,7 +653,7 @@ typedef struct ivas_dirac_rend_data_structure #else Word32 *buffer_intensity_real_fx[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF]; /* Q(q_buffer_intensity_real[]) */ Word16 q_buffer_intensity_real[DIRAC_NO_COL_AVG_DIFF]; - Word32 *buffer_energy_fx; /* Q(q_buffer_energy[]) */ + Word32 *buffer_energy_fx; /* Q(q_buffer_energy[]) */ Word16 q_buffer_energy[DIRAC_NO_COL_AVG_DIFF]; #endif @@ -882,7 +882,7 @@ typedef struct ivas_dirac_dec_binaural_data_structure float processMtxDecRePrev[BINAURAL_CHANNELS][BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; float processMtxDecImPrev[BINAURAL_CHANNELS][BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; #ifdef IVAS_FLOAT_FIXED - Word32 earlyPartEneCorrection_fx[CLDFB_NO_CHANNELS_MAX]; + Word32 earlyPartEneCorrection_fx[CLDFB_NO_CHANNELS_MAX]; Word16 q_earlyPartEneCorrection; Word16 processMtxRe_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS + MAX_NUM_OBJECTS][CLDFB_NO_CHANNELS_MAX]; Word16 processMtxIm_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS + MAX_NUM_OBJECTS][CLDFB_NO_CHANNELS_MAX]; @@ -893,37 +893,37 @@ typedef struct ivas_dirac_dec_binaural_data_structure Word16 processMtxDecRePrev_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; Word16 processMtxDecImPrev_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; - Word32 ChEnePrev_fx[BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; - Word32 ChCrossRePrev_fx[CLDFB_NO_CHANNELS_MAX]; - Word32 ChCrossImPrev_fx[CLDFB_NO_CHANNELS_MAX]; - Word32 ChEne_fx[BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; - Word32 ChCrossRe_fx[CLDFB_NO_CHANNELS_MAX]; - Word32 ChCrossIm_fx[CLDFB_NO_CHANNELS_MAX]; - Word32 ChCrossReOut_fx[CLDFB_NO_CHANNELS_MAX]; - Word32 ChCrossImOut_fx[CLDFB_NO_CHANNELS_MAX]; - Word32 ChEneOut_fx[BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; - Word32 ChEneOutPrev_fx[BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; - Word32 frameMeanDiffuseness_fx[CLDFB_NO_CHANNELS_MAX]; - Word32 ChCrossReOutPrev_fx[CLDFB_NO_CHANNELS_MAX]; - Word32 ChCrossImOutPrev_fx[CLDFB_NO_CHANNELS_MAX]; - - Word16 ChEnePrev_e[BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; - Word16 ChCrossRePrev_e[CLDFB_NO_CHANNELS_MAX]; - Word16 ChCrossImPrev_e[CLDFB_NO_CHANNELS_MAX]; - Word16 ChEne_e[BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; - Word16 ChCrossRe_e[CLDFB_NO_CHANNELS_MAX]; - Word16 ChCrossIm_e[CLDFB_NO_CHANNELS_MAX]; - Word16 ChCrossReOut_e[CLDFB_NO_CHANNELS_MAX]; - Word16 ChCrossImOut_e[CLDFB_NO_CHANNELS_MAX]; - Word16 ChEneOut_e[BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; - Word16 ChEneOutPrev_e[BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; - Word16 ChCrossReOutPrev_e[CLDFB_NO_CHANNELS_MAX]; - Word16 ChCrossImOutPrev_e[CLDFB_NO_CHANNELS_MAX]; - - Word32 diffuseFieldCoherence_fx[CLDFB_NO_CHANNELS_MAX]; - Word32 diffuseFieldCoherenceX_fx[BINAURAL_COHERENCE_DIFFERENCE_BINS]; - Word32 diffuseFieldCoherenceY_fx[BINAURAL_COHERENCE_DIFFERENCE_BINS]; - Word32 diffuseFieldCoherenceZ_fx[BINAURAL_COHERENCE_DIFFERENCE_BINS]; + Word32 ChEnePrev_fx[BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; + Word32 ChCrossRePrev_fx[CLDFB_NO_CHANNELS_MAX]; + Word32 ChCrossImPrev_fx[CLDFB_NO_CHANNELS_MAX]; + Word32 ChEne_fx[BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; + Word32 ChCrossRe_fx[CLDFB_NO_CHANNELS_MAX]; + Word32 ChCrossIm_fx[CLDFB_NO_CHANNELS_MAX]; + Word32 ChCrossReOut_fx[CLDFB_NO_CHANNELS_MAX]; + Word32 ChCrossImOut_fx[CLDFB_NO_CHANNELS_MAX]; + Word32 ChEneOut_fx[BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; + Word32 ChEneOutPrev_fx[BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; + Word32 frameMeanDiffuseness_fx[CLDFB_NO_CHANNELS_MAX]; + Word32 ChCrossReOutPrev_fx[CLDFB_NO_CHANNELS_MAX]; + Word32 ChCrossImOutPrev_fx[CLDFB_NO_CHANNELS_MAX]; + + Word16 ChEnePrev_e[BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; + Word16 ChCrossRePrev_e[CLDFB_NO_CHANNELS_MAX]; + Word16 ChCrossImPrev_e[CLDFB_NO_CHANNELS_MAX]; + Word16 ChEne_e[BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; + Word16 ChCrossRe_e[CLDFB_NO_CHANNELS_MAX]; + Word16 ChCrossIm_e[CLDFB_NO_CHANNELS_MAX]; + Word16 ChCrossReOut_e[CLDFB_NO_CHANNELS_MAX]; + Word16 ChCrossImOut_e[CLDFB_NO_CHANNELS_MAX]; + Word16 ChEneOut_e[BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; + Word16 ChEneOutPrev_e[BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; + Word16 ChCrossReOutPrev_e[CLDFB_NO_CHANNELS_MAX]; + Word16 ChCrossImOutPrev_e[CLDFB_NO_CHANNELS_MAX]; + + Word32 diffuseFieldCoherence_fx[CLDFB_NO_CHANNELS_MAX]; + Word32 diffuseFieldCoherenceX_fx[BINAURAL_COHERENCE_DIFFERENCE_BINS]; + Word32 diffuseFieldCoherenceY_fx[BINAURAL_COHERENCE_DIFFERENCE_BINS]; + Word32 diffuseFieldCoherenceZ_fx[BINAURAL_COHERENCE_DIFFERENCE_BINS]; #endif uint16_t useTdDecorr; ivas_td_decorr_state_t *hTdDecorr; @@ -1050,21 +1050,21 @@ typedef struct EFAP float *aziSpk; /* Loudspeaker azimuths */ float *eleSpk; /* Loudspeaker elevations */ #else - Word32 *aziSpk; /* Loudspeaker azimuths */ - Word32 *eleSpk; /* Loudspeaker elevations */ + Word32 *aziSpk; /* Loudspeaker azimuths */ + Word32 *eleSpk; /* Loudspeaker elevations */ #endif EFAP_VERTEX_DATA vtxData; /* Vertex Data, contains all the data concerning the vertex */ EFAP_POLYSET_DATA polyData; /* Polygon data */ #ifndef IVAS_FLOAT_FIXED - float **dmTranspose; /* Downmix Matrix used for redistributing the energy of ghosts LS and its transpose */ - float *bufferLong; /* tmp buffer that will be given as a parameter for computing the gain; this is a 1D array of length numVtx */ - float *bufferShort; /* tmp buffer that will be given as a parameter for computing the gain; this is the result of downMixMatrix*bufferLong, length is numSpk */ + float **dmTranspose; /* Downmix Matrix used for redistributing the energy of ghosts LS and its transpose */ + float *bufferLong; /* tmp buffer that will be given as a parameter for computing the gain; this is a 1D array of length numVtx */ + float *bufferShort; /* tmp buffer that will be given as a parameter for computing the gain; this is the result of downMixMatrix*bufferLong, length is numSpk */ #else - Word32 **dmTranspose_fx; /* Downmix Matrix used for redistributing the energy of ghosts LS and its transpose */ - Word32 *bufferLong_fx; /* tmp buffer that will be given as a parameter for computing the gain; this is a 1D array of length numVtx */ - Word32 *bufferShort_fx; /* tmp buffer that will be given as a parameter for computing the gain; this is the result of downMixMatrix*bufferLong, length is numSpk */ + Word32 **dmTranspose_fx; /* Downmix Matrix used for redistributing the energy of ghosts LS and its transpose */ + Word32 *bufferLong_fx; /* tmp buffer that will be given as a parameter for computing the gain; this is a 1D array of length numVtx */ + Word32 *bufferShort_fx; /* tmp buffer that will be given as a parameter for computing the gain; this is the result of downMixMatrix*bufferLong, length is numSpk */ #endif - int16_t numTot; /* Total number of real + ghost loudspeakers, used later for freeing memory */ + int16_t numTot; /* Total number of real + ghost loudspeakers, used later for freeing memory */ } EFAP, *EFAP_HANDLE; @@ -1153,10 +1153,10 @@ typedef struct ivas_binaural_head_track_struct typedef struct ivas_external_orientation_struct { Word8 enableHeadRotation[MAX_PARAM_SPATIAL_SUBFRAMES]; /* 0 - disable, 1 - enable, 2 - freeze to previous rotation */ - Word8 enableExternalOrientation[MAX_PARAM_SPATIAL_SUBFRAMES]; /* 0 - disable, 1 - enable, 2 - freeze to previous orientation */ + Word8 enableExternalOrientation[MAX_PARAM_SPATIAL_SUBFRAMES]; /* 0 - disable, 1 - enable, 2 - freeze to previous orientation */ Word8 enableRotationInterpolation[MAX_PARAM_SPATIAL_SUBFRAMES]; /* 0 - disable, 1 - enable */ Word16 numFramesToTargetOrientation[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Number of frames until target orientation is reached */ - IVAS_QUATERNION Quaternions[MAX_PARAM_SPATIAL_SUBFRAMES]; /* External orientation in quaternions */ + IVAS_QUATERNION Quaternions[MAX_PARAM_SPATIAL_SUBFRAMES]; /* External orientation in quaternions */ Word16 num_subframes; } EXTERNAL_ORIENTATION_DATA, *EXTERNAL_ORIENTATION_HANDLE; @@ -1183,8 +1183,8 @@ typedef struct ivas_combined_orientation_struct float interpolationCoefficient; float interpolationIncrement; #else - Word32 lrSwitchInterpVal_fx; /* Q30 */ - Word32 interpolationCoefficient_fx; /* Q30 */ + Word32 lrSwitchInterpVal_fx; /* Q30 */ + Word32 interpolationCoefficient_fx; /* Q30 */ #endif Word16 maximumFramesToTargetOrientation; UWord8 lrSwitchedNext; @@ -1192,7 +1192,7 @@ typedef struct ivas_combined_orientation_struct #ifndef IVAS_FLOAT_FIXED float lrSwitchInterpVal; #else - Word32 interpolationIncrement_fx; /* Q30 */ + Word32 interpolationIncrement_fx; /* Q30 */ #endif bool isInterpolationOngoing; IVAS_QUATERNION Quaternions[MAX_PARAM_SPATIAL_SUBFRAMES]; @@ -1205,8 +1205,8 @@ typedef struct ivas_combined_orientation_struct float chEneIIR[2][MASA_FREQUENCY_BANDS]; /* independent of the format. MASA bands are suitable for the task and readily available in ROM. */ float procChEneIIR[2][MASA_FREQUENCY_BANDS]; #else - Word32 Rmat_fx[MAX_PARAM_SPATIAL_SUBFRAMES][3][3]; /* Q30 */ - Word32 Rmat_prev_fx[3][3]; /* Q30 */ + Word32 Rmat_fx[MAX_PARAM_SPATIAL_SUBFRAMES][3][3]; /* Q30 */ + Word32 Rmat_prev_fx[3][3]; /* Q30 */ Word32 chEneIIR_fx[2][MASA_FREQUENCY_BANDS]; /* independent of the format. MASA bands are suitable for the task and readily available in ROM. */ /* Q(q_chEneIIR) */ Word16 q_chEneIIR; Word32 procChEneIIR_fx[2][MASA_FREQUENCY_BANDS]; /* Q(q_procChEneIIR) */ @@ -1282,8 +1282,7 @@ typedef struct ivas_rev_delay_line_t #else Word16 Gain_fx; #endif -} -ivas_rev_delay_line_t; +} ivas_rev_delay_line_t; typedef struct ivas_rev_iir_filter_t { @@ -1314,9 +1313,9 @@ typedef struct ivas_reverb_t2f_f2t_t Word16 log2_fft_size; Word16 block_size; Word16 hist_size; /* rv_fft_size - rv_block_size */ - // float fft_history_L[RV_FILTER_MAX_HISTORY]; + // float fft_history_L[RV_FILTER_MAX_HISTORY]; Word32 fft_history_L_fx[RV_FILTER_MAX_HISTORY]; - // float fft_history_R[RV_FILTER_MAX_HISTORY]; + // float fft_history_R[RV_FILTER_MAX_HISTORY]; Word32 fft_history_R_fx[RV_FILTER_MAX_HISTORY]; } ivas_reverb_t2f_f2t_t; @@ -1355,10 +1354,10 @@ typedef struct ivas_reverb_state_t ivas_rev_delay_line_t predelay_line; Word32 *pPredelay_buffer_fx; /* jot reverberator: */ - uint16_t nr_of_branches; /* number of feedback loops */ - ivas_rev_delay_line_t delay_line[IVAS_REV_MAX_NR_BRANCHES]; /* feedback loop delays */ + uint16_t nr_of_branches; /* number of feedback loops */ + ivas_rev_delay_line_t delay_line[IVAS_REV_MAX_NR_BRANCHES]; /* feedback loop delays */ Word32 *loop_delay_buffer_fx[IVAS_REV_MAX_NR_BRANCHES]; /* feedback loop delay sample buffers */ - ivas_rev_iir_filter_t t60[IVAS_REV_MAX_NR_BRANCHES]; /* feedback loop filters */ + ivas_rev_iir_filter_t t60[IVAS_REV_MAX_NR_BRANCHES]; /* feedback loop filters */ Word32 gain_matrix_fx[IVAS_REV_MAX_NR_BRANCHES][IVAS_REV_MAX_NR_BRANCHES]; /* feedback matrix */ Word16 mixer_fx[BINAURAL_CHANNELS][IVAS_REV_MAX_NR_BRANCHES]; /* binauralization filters: */ @@ -1369,9 +1368,9 @@ typedef struct ivas_reverb_state_t ivas_reverb_fft_filter_t fft_filter_color_0; ivas_reverb_fft_filter_t fft_filter_color_1; UWord16 fft_size; /* fft processing size */ - UWord16 fft_subblock_size; /* fft block processing size */ + UWord16 fft_subblock_size; /* fft block processing size */ UWord16 num_fft_subblocks; /* number of fft subblocks */ - UWord16 full_block_size; /* full block processing size */ + UWord16 full_block_size; /* full block processing size */ } REVERB_DATA, *REVERB_HANDLE; #else @@ -1436,7 +1435,7 @@ typedef struct Word32 room_H_fx; Word32 abs_coeff_fx[IVAS_ROOM_ABS_COEFF]; Word32 list_orig_fx[3]; -#endif +#endif } shoebox_config_t; /* Structure to hold the corrected( bounded ) source and listener positions */ @@ -1479,7 +1478,7 @@ typedef struct shoebox_data_t float data[150]; #else Word32 data_fx[150]; -#endif +#endif Word32 size[1]; } shoebox_data_t; @@ -1519,15 +1518,15 @@ typedef struct er_struct_t #ifdef IVAS_FLOAT_FIXED Word32 output_Fs_fx; Word32 source_positions_fx[75]; - Word32 user_origin_fx[3]; //is not needed + Word32 user_origin_fx[3]; // is not needed Word32 *circ_buffers; #else float source_positions[75]; float user_origin[3]; float output_Fs; float *circ_buffers; -#endif - +#endif + UWord16 *closest_ch_idx; shoebox_output_t shoebox_data; @@ -1566,18 +1565,18 @@ typedef struct const Word32 *elevKSeq_fx; /* Array, N x elevDim2 x elevDim3 */ const Word32 *elevBsShape_fx; const Word32 **azimBsShape_fx; - Word32 **azimKSeq_fx; /* Array, length azimDim3+1 */ - const Word32 *AlphaL_fx; /* Array, size AlphaN x K */ + Word32 **azimKSeq_fx; /* Array, length azimDim3+1 */ + const Word32 *AlphaL_fx; /* Array, size AlphaN x K */ Word16 AlphaL_e; - const Word32 *AlphaR_fx; /* Array, size AlphaN x K */ + const Word32 *AlphaR_fx; /* Array, size AlphaN x K */ Word16 AlphaR_e; - const Word32 *EL_fx; /* Array, size (AlphaN*HRTF_MODEL_N_SECTIONS) */ + const Word32 *EL_fx; /* Array, size (AlphaN*HRTF_MODEL_N_SECTIONS) */ Word16 EL_e; - const Word32 *ER_fx; /* Array, size (AlphaN*HRTF_MODEL_N_SECTIONS) */ + const Word32 *ER_fx; /* Array, size (AlphaN*HRTF_MODEL_N_SECTIONS) */ Word16 ER_e; -#endif // IVAS_FLOAT_FIXED - const float *AlphaL; /* Array, size AlphaN x K */ - const float *AlphaR; /* Array, size AlphaN x K */ +#endif // IVAS_FLOAT_FIXED + const float *AlphaL; /* Array, size AlphaN x K */ + const float *AlphaR; /* Array, size AlphaN x K */ const float *elevBsShape; float **azimKSeq; /* Array, length azimDim3+1 */ const float **azimBsShape; @@ -1645,10 +1644,10 @@ typedef struct int16_t elevSegSamples; float resamp_factor; #ifdef IVAS_FLOAT_FIXED - Word16 resamp_factor_fx; /*Q14*/ - const Word32 *elevKSeq_fx; /* Array, length elevDim3-2 */ - const Word32 *azimKSeq_fx; /* Array, length azimDim3-2 */ - const Word32 *W_fx; /* Array, size (elevDim3*azimDim3) x K */ + Word16 resamp_factor_fx; /*Q14*/ + const Word32 *elevKSeq_fx; /* Array, length elevDim3-2 */ + const Word32 *azimKSeq_fx; /* Array, length azimDim3-2 */ + const Word32 *W_fx; /* Array, size (elevDim3*azimDim3) x K */ Word16 W_e; const Word32 *azimBsShape_fx; const Word32 *elevBsShape_fx; @@ -1739,7 +1738,7 @@ typedef struct float Up[3]; float Right[3]; float Vel[3]; -#endif// IVAS_FLOAT_FIXED +#endif // IVAS_FLOAT_FIXED int16_t VelUpdated; @@ -1797,9 +1796,9 @@ typedef struct float MaxDist; float RollOffFactor; #else - Word32 RefDist_fx; /* Q30 */ - Word32 MaxDist_fx; /* Q27 */ - Word32 RollOffFactor_fx; /* Q30 */ + Word32 RefDist_fx; /* Q30 */ + Word32 MaxDist_fx; /* Q27 */ + Word32 RollOffFactor_fx; /* Q30 */ #endif // IVAS_FLOAT_FIXED- } TDREND_DistAtten_t; @@ -1812,9 +1811,9 @@ typedef struct float ConeOuterAngle; float ConeOuterGain; #else - Word32 ConeInnerAngle_fx; // Q22 - Word32 ConeOuterAngle_fx; // Q22 - Word32 ConeOuterGain_fx; // Q30 + Word32 ConeInnerAngle_fx; // Q22 + Word32 ConeOuterAngle_fx; // Q22 + Word32 ConeOuterGain_fx; // Q30 #endif // IVAS_FLOAT_FIXED } TDREND_DirAtten_t; @@ -1835,12 +1834,12 @@ typedef struct TDREND_SRC_REND_s /* Gains */ int16_t SrcGainUpdated; #ifdef IVAS_FLOAT_FIXED - Word16 SrcGain_p_fx[SPAT_BIN_MAX_INPUT_CHANNELS]; // Q14 + Word16 SrcGain_p_fx[SPAT_BIN_MAX_INPUT_CHANNELS]; // Q14 Word16 SrcGainMin_p_fx[SPAT_BIN_MAX_INPUT_CHANNELS]; Word16 SrcGainMax_p_fx[SPAT_BIN_MAX_INPUT_CHANNELS]; - Word16 DirGain_p_fx[SPAT_BIN_MAX_INPUT_CHANNELS]; // Q14 - Word16 DistGain_p_fx[SPAT_BIN_MAX_INPUT_CHANNELS]; // Q14 -#else // IVAS_FLOAT_FIXED + Word16 DirGain_p_fx[SPAT_BIN_MAX_INPUT_CHANNELS]; // Q14 + Word16 DistGain_p_fx[SPAT_BIN_MAX_INPUT_CHANNELS]; // Q14 +#else // IVAS_FLOAT_FIXED float SrcGain_p[SPAT_BIN_MAX_INPUT_CHANNELS]; float SrcGainMin_p[SPAT_BIN_MAX_INPUT_CHANNELS]; float SrcGainMax_p[SPAT_BIN_MAX_INPUT_CHANNELS]; @@ -1859,10 +1858,10 @@ typedef struct float Front_p[3 * SPAT_BIN_MAX_INPUT_CHANNELS]; #endif #ifdef IVAS_FLOAT_FIXED - Word32 Pos_p_fx[3 * SPAT_BIN_MAX_INPUT_CHANNELS]; // Q25 + Word32 Pos_p_fx[3 * SPAT_BIN_MAX_INPUT_CHANNELS]; // Q25 Word16 q_Pos_p; Word32 Front_p_fx[3 * SPAT_BIN_MAX_INPUT_CHANNELS]; // Q30 -#endif // IVAS_FLOAT_FIXED +#endif // IVAS_FLOAT_FIXED int16_t DirAttenEnabled; TDREND_DirAtten_t DirAtten; int16_t DistAttenEnabled; @@ -1920,7 +1919,7 @@ typedef struct ivas_binaural_td_rendering_struct #ifdef IVAS_FLOAT_FIXED Word16 Gain_fx; /* Q14 */ #else - float Gain; /* Mixer gain */ + float Gain; /* Mixer gain */ #endif // IVAS_FLOAT_FIXED TDREND_MIX_Listener_t *Listener_p; /* The virtual listener */ @@ -2180,14 +2179,14 @@ typedef struct { Word16 max_num_channels; Word16 num_channels; - //float **channel_ptrs; + // float **channel_ptrs; Word32 **channel_ptrs_fx; Word32 sampling_rate; - //float gain; + // float gain; Word32 gain_fx; - //float release_heuristic; + // float release_heuristic; Word32 release_heuristic_fx; - //float attack_constant; + // float attack_constant; Word32 attack_constant_fx; Word16 strong_saturation_count; @@ -2272,9 +2271,9 @@ typedef struct ivas_mono_downmix_renderer_struct float protoEnergy; #else Word32 inputEnergy_fx; - Word16 Q_inputEner; + Word16 Q_inputEner; Word32 protoEnergy_fx; - Word16 Q_protoEner; + Word16 Q_protoEner; #endif } MONO_DOWNMIX_RENDERER_STRUCT, *MONO_DOWNMIX_RENDERER_HANDLE; @@ -2286,17 +2285,17 @@ typedef struct ivas_mono_downmix_renderer_struct #ifdef IVAS_FLOAT_FIXED typedef struct ivas_LS_setup_custom { - Word16 is_planar_setup; /* flag to indicate if setup is planar or not */ - Word16 num_spk; /* number of custom loudspeakers */ - float ls_azimuth[MAX_OUTPUT_CHANNELS]; /* custom loudspeaker azimuths */ - float ls_elevation[MAX_OUTPUT_CHANNELS]; /* custom loudspeaker elevations */ - Word32 ls_azimuth_fx[MAX_OUTPUT_CHANNELS]; /* custom loudspeaker azimuths */ - Word32 ls_elevation_fx[MAX_OUTPUT_CHANNELS]; /* custom loudspeaker elevations */ - Word16 num_lfe; /* number of LFE channels */ - Word16 lfe_idx[MAX_OUTPUT_CHANNELS]; /* index for LFE channel insertion */ - Word16 separate_ch_found; /* flag to indicate if a center channel was found */ - - Word16 separate_ch_gains_fx[MAX_OUTPUT_CHANNELS]; /* gains to pan McMASA separateChannel in case no center channel is present */ + Word16 is_planar_setup; /* flag to indicate if setup is planar or not */ + Word16 num_spk; /* number of custom loudspeakers */ + float ls_azimuth[MAX_OUTPUT_CHANNELS]; /* custom loudspeaker azimuths */ + float ls_elevation[MAX_OUTPUT_CHANNELS]; /* custom loudspeaker elevations */ + Word32 ls_azimuth_fx[MAX_OUTPUT_CHANNELS]; /* custom loudspeaker azimuths */ + Word32 ls_elevation_fx[MAX_OUTPUT_CHANNELS]; /* custom loudspeaker elevations */ + Word16 num_lfe; /* number of LFE channels */ + Word16 lfe_idx[MAX_OUTPUT_CHANNELS]; /* index for LFE channel insertion */ + Word16 separate_ch_found; /* flag to indicate if a center channel was found */ + + Word16 separate_ch_gains_fx[MAX_OUTPUT_CHANNELS]; /* gains to pan McMASA separateChannel in case no center channel is present */ } LSSETUP_CUSTOM_STRUCT, *LSSETUP_CUSTOM_HANDLE; #else @@ -2364,9 +2363,9 @@ typedef struct ivas_mcmasa_ana_data_structure /* DirAC parameter estimation */ #ifdef IVAS_FLOAT_FIXED - Word32 **direction_vector_m_fx[DIRAC_NUM_DIMS]; /* Average direction vector */ + Word32 **direction_vector_m_fx[DIRAC_NUM_DIMS]; /* Average direction vector */ Word16 **direction_vector_e[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Average direction vector */ -#endif // IVAS_FLOAT_FIXED +#endif // IVAS_FLOAT_FIXED #ifndef IVAS_FLOAT_FIXED float **direction_vector_m[DIRAC_NUM_DIMS]; /* Average direction vector */ #endif @@ -2474,7 +2473,7 @@ typedef struct ivas_omasa_ana_data_structure #ifdef IVAS_FLOAT_FIXED Word32 **direction_vector_m_fx[DIRAC_NUM_DIMS]; /* Average direction vector */ - Word16 direction_vector_m_q; /* Average direction vector */ + Word16 direction_vector_m_q; /* Average direction vector */ Word32 ism_azimuth_fx[MAX_NUM_OBJECTS]; Word32 ism_elevation_fx[MAX_NUM_OBJECTS]; @@ -2517,12 +2516,12 @@ typedef struct ivas_dirac_ana_data_structure /* diffuseness */ int16_t index_buffer_intensity; -#ifndef IVAS_FLOAT_FIXED +#ifndef IVAS_FLOAT_FIXED float *buffer_intensity_real[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF]; #else Word32 *buffer_intensity_real_fx[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF]; #endif -#ifndef IVAS_FLOAT_FIXED +#ifndef IVAS_FLOAT_FIXED float buffer_energy[DIRAC_NO_COL_AVG_DIFF * MASA_FREQUENCY_BANDS]; #else Word32 buffer_energy_fx[DIRAC_NO_COL_AVG_DIFF * MASA_FREQUENCY_BANDS]; diff --git a/lib_rend/ivas_td_decorr.c b/lib_rend/ivas_td_decorr.c index 4bb8cc49e..a2aa03d69 100644 --- a/lib_rend/ivas_td_decorr.c +++ b/lib_rend/ivas_td_decorr.c @@ -846,7 +846,7 @@ void ivas_td_decorr_process_fx( FOR( j = 0; j < output_frame; j++ ) { - ppOut_pcm[0][j] = L_shl(Mpy_32_32( ppOut_pcm[0][j], in_duck_gain[j] ), 1); + ppOut_pcm[0][j] = L_shl( Mpy_32_32( ppOut_pcm[0][j], in_duck_gain[j] ), 1 ); } *q_format -= 0; } @@ -866,7 +866,7 @@ void ivas_td_decorr_process_fx( { FOR( j = 0; j < output_frame; j++ ) { - ppOut_pcm[i][j] = L_shl(Mpy_32_32( ppOut_pcm[i][j], out_duck_gain[j] ), 1); + ppOut_pcm[i][j] = L_shl( Mpy_32_32( ppOut_pcm[i][j], out_duck_gain[j] ), 1 ); } } *q_format -= 0; diff --git a/lib_rend/ivas_vbap.c b/lib_rend/ivas_vbap.c index c0e60b6e3..3d91b4128 100644 --- a/lib_rend/ivas_vbap.c +++ b/lib_rend/ivas_vbap.c @@ -73,8 +73,8 @@ /* Maximum azimuth gap between speaker nodes for detecting zero elevation horizontal plane */ #define VBAP_MAX_HORIZONTAL_GAP 170u -#define VBAP_SEARCH_SECTOR_SIZE ( 360.0f / ( VBAP_NUM_SEARCH_SECTORS ) ) -#define VBAP_SEARCH_SECTOR_SIZE_Q0 90 +#define VBAP_SEARCH_SECTOR_SIZE ( 360.0f / ( VBAP_NUM_SEARCH_SECTORS ) ) +#define VBAP_SEARCH_SECTOR_SIZE_Q0 90 enum VirtualSpeakerNodeType @@ -163,31 +163,31 @@ static void determine_virtual_speaker_node_division_gains_fx( const Word16 virtu static void reorder_triplets_fx( VBAP_VS_TRIPLET *triplets, const Word16 *target_order, const Word16 num_triplets ); #else -static uint8_t vector_matrix_multiply_3x3(const float *src_vector, float matrix[3][3], float *result); +static uint8_t vector_matrix_multiply_3x3( const float *src_vector, float matrix[3][3], float *result ); -static void init_speaker_node_direction_data(VBAP_SPEAKER_NODE *speaker_node_data, const float *speaker_node_azi_deg, const float *speaker_node_ele_deg, const int16_t num_speaker_nodes); +static void init_speaker_node_direction_data( VBAP_SPEAKER_NODE *speaker_node_data, const float *speaker_node_azi_deg, const float *speaker_node_ele_deg, const int16_t num_speaker_nodes ); -static int16_t determine_virtual_surface_triplets(const int16_t num_speaker_nodes, const VBAP_SPEAKER_NODE *speaker_node_data, int16_t connections[][2], const int16_t max_num_connections, VBAP_VS_TRIPLET *triplets, int16_t initial_search_indices[VBAP_NUM_SEARCH_SECTORS], enum SpeakerNodeGroup allowed_group); +static int16_t determine_virtual_surface_triplets( const int16_t num_speaker_nodes, const VBAP_SPEAKER_NODE *speaker_node_data, int16_t connections[][2], const int16_t max_num_connections, VBAP_VS_TRIPLET *triplets, int16_t initial_search_indices[VBAP_NUM_SEARCH_SECTORS], enum SpeakerNodeGroup allowed_group ); -static void determine_initial_search_indices(const int16_t num_triplets, const float triplet_azidegs[VBAP_MAX_NUM_TRIPLETS], int16_t initial_search_indices[VBAP_NUM_SEARCH_SECTORS]); +static void determine_initial_search_indices( const int16_t num_triplets, const float triplet_azidegs[VBAP_MAX_NUM_TRIPLETS], int16_t initial_search_indices[VBAP_NUM_SEARCH_SECTORS] ); -static ivas_error determine_connections(const int16_t num_speaker_nodes, const VBAP_SPEAKER_NODE *speaker_node_data, int16_t connections[][2], const int16_t max_num_connections, int16_t *group1_count, int16_t *group2_start, int16_t *group2_count); +static ivas_error determine_connections( const int16_t num_speaker_nodes, const VBAP_SPEAKER_NODE *speaker_node_data, int16_t connections[][2], const int16_t max_num_connections, int16_t *group1_count, int16_t *group2_start, int16_t *group2_count ); -static void formulate_horizontal_connections(const VBAP_SPEAKER_NODE *speaker_node_data, const int16_t num_speaker_nodes, int16_t connections[][2], int16_t *connection_write_index); +static void formulate_horizontal_connections( const VBAP_SPEAKER_NODE *speaker_node_data, const int16_t num_speaker_nodes, int16_t connections[][2], int16_t *connection_write_index ); -static ivas_error get_half_sphere_connection_options(const VBAP_SPEAKER_NODE *speaker_node_data, const enum SpeakerNodeGroup group, const int16_t num_speaker_nodes, const int16_t num_non_crossing_planes, const float *non_crossing_plane_elevation_deg, ConnectionOption **connection_options_pr, int16_t *num_connection_options); +static ivas_error get_half_sphere_connection_options( const VBAP_SPEAKER_NODE *speaker_node_data, const enum SpeakerNodeGroup group, const int16_t num_speaker_nodes, const int16_t num_non_crossing_planes, const float *non_crossing_plane_elevation_deg, ConnectionOption **connection_options_pr, int16_t *num_connection_options ); -static ivas_error formulate_half_sphere_connections(const VBAP_SPEAKER_NODE *speaker_node_data, const int16_t num_speaker_nodes, const enum SpeakerNodeGroup group, int16_t connections[][2], int16_t *connection_write_index, const int16_t max_num_connections, const int16_t num_non_crossing_planes, const float *non_crossing_plane_elevation_deg); +static ivas_error formulate_half_sphere_connections( const VBAP_SPEAKER_NODE *speaker_node_data, const int16_t num_speaker_nodes, const enum SpeakerNodeGroup group, int16_t connections[][2], int16_t *connection_write_index, const int16_t max_num_connections, const int16_t num_non_crossing_planes, const float *non_crossing_plane_elevation_deg ); -static int16_t determine_non_crossing_planes(const int16_t num_speaker_nodes, const VBAP_SPEAKER_NODE *node_data, float *non_crossing_plane_elevation_deg); +static int16_t determine_non_crossing_planes( const int16_t num_speaker_nodes, const VBAP_SPEAKER_NODE *node_data, float *non_crossing_plane_elevation_deg ); -static enum VirtualSpeakerNodeType check_need_of_virtual_speaker_node(VBAP_HANDLE hVBAPdata, const float *speaker_node_azi_deg, const float *speaker_node_ele_deg, enum SpeakerNodeGroup group); +static enum VirtualSpeakerNodeType check_need_of_virtual_speaker_node( VBAP_HANDLE hVBAPdata, const float *speaker_node_azi_deg, const float *speaker_node_ele_deg, enum SpeakerNodeGroup group ); -static int16_t determine_best_triplet_and_gains(VBAP_SEARCH_STRUCT *search_struct, const float panning_unit_vec[3], const int16_t azi_deg, float gains[3]); +static int16_t determine_best_triplet_and_gains( VBAP_SEARCH_STRUCT *search_struct, const float panning_unit_vec[3], const int16_t azi_deg, float gains[3] ); -static void determine_virtual_speaker_node_division_gains(const int16_t virtual_speaker_node_index, float *virtual_node_division_gains, int16_t connections[][2], const enum VirtualSpeakerNodeType type, const int16_t max_num_connections, const int16_t num_speaker_nodes, const int16_t use_object_mode); +static void determine_virtual_speaker_node_division_gains( const int16_t virtual_speaker_node_index, float *virtual_node_division_gains, int16_t connections[][2], const enum VirtualSpeakerNodeType type, const int16_t max_num_connections, const int16_t num_speaker_nodes, const int16_t use_object_mode ); -static void reorder_triplets(VBAP_VS_TRIPLET *triplets, const int16_t *target_order, const int16_t num_triplets); +static void reorder_triplets( VBAP_VS_TRIPLET *triplets, const int16_t *target_order, const int16_t num_triplets ); #endif /*-------------------------------------------------------------------------* @@ -493,29 +493,29 @@ ivas_error vbap_init_data( VBAP_DATA *vbap; ivas_error error; - push_wmops("vbap_init"); + push_wmops( "vbap_init" ); /* Basic init checks */ /* If the requested layout is invalid, hVBAPdata is set to NULL and the signal will * be distributed with an equal gain into all output channels. * The surrounding code needs to handle the NULL pointer properly. */ - if (num_speaker_nodes > VBAP_MAX_NUM_SPEAKER_NODES || num_speaker_nodes < 3) + if ( num_speaker_nodes > VBAP_MAX_NUM_SPEAKER_NODES || num_speaker_nodes < 3 ) { hVBAPdata = NULL; pop_wmops(); return IVAS_ERR_OK; } - if (!speaker_node_azi_deg || !speaker_node_ele_deg) + if ( !speaker_node_azi_deg || !speaker_node_ele_deg ) { hVBAPdata = NULL; return IVAS_ERR_OK; } /* Allocate VBAP structure */ - if ((vbap = (VBAP_HANDLE)malloc(sizeof(VBAP_DATA))) == NULL) + if ( ( vbap = (VBAP_HANDLE) malloc( sizeof( VBAP_DATA ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VBAP data\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VBAP data\n" ) ); } is_success = 1; @@ -533,31 +533,31 @@ ivas_error vbap_init_data( /* Check if the speaker node setup needs a virtual top or bottom node (function also increments vbap->num_speaker_nodes_internal when necessary) */ - virtual_bottom_type = check_need_of_virtual_speaker_node(vbap, speaker_node_azi_deg, speaker_node_ele_deg, SPEAKER_NODE_BOTTOM_HALF); - virtual_top_type = check_need_of_virtual_speaker_node(vbap, speaker_node_azi_deg, speaker_node_ele_deg, SPEAKER_NODE_TOP_HALF); - virtual_back_type = check_need_of_virtual_speaker_node(vbap, speaker_node_azi_deg, speaker_node_ele_deg, SPEAKER_NODE_BACK); + virtual_bottom_type = check_need_of_virtual_speaker_node( vbap, speaker_node_azi_deg, speaker_node_ele_deg, SPEAKER_NODE_BOTTOM_HALF ); + virtual_top_type = check_need_of_virtual_speaker_node( vbap, speaker_node_azi_deg, speaker_node_ele_deg, SPEAKER_NODE_TOP_HALF ); + virtual_back_type = check_need_of_virtual_speaker_node( vbap, speaker_node_azi_deg, speaker_node_ele_deg, SPEAKER_NODE_BACK ); /* Init internal speaker node configuration, which is the original configuration potentially appended with virtual top and/or bottom loudspeakers */ - mvr2r(speaker_node_azi_deg, speaker_node_azi_deg_internal, num_speaker_nodes); - mvr2r(speaker_node_ele_deg, speaker_node_ele_deg_internal, num_speaker_nodes); + mvr2r( speaker_node_azi_deg, speaker_node_azi_deg_internal, num_speaker_nodes ); + mvr2r( speaker_node_ele_deg, speaker_node_ele_deg_internal, num_speaker_nodes ); - if (is_success && virtual_bottom_type != NO_VIRTUAL_SPEAKER_NODE) + if ( is_success && virtual_bottom_type != NO_VIRTUAL_SPEAKER_NODE ) { - if ((vbap->bottom_virtual_speaker_node_division_gains = (float *)malloc(num_speaker_nodes * sizeof(float))) == NULL) + if ( ( vbap->bottom_virtual_speaker_node_division_gains = (float *) malloc( num_speaker_nodes * sizeof( float ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VBAP data\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VBAP data\n" ) ); } - set_zero(vbap->bottom_virtual_speaker_node_division_gains, num_speaker_nodes); + set_zero( vbap->bottom_virtual_speaker_node_division_gains, num_speaker_nodes ); is_success &= vbap->bottom_virtual_speaker_node_division_gains != NULL; - if (ivas_format == MASA_ISM_FORMAT) + if ( ivas_format == MASA_ISM_FORMAT ) { - if ((vbap->object_mode_bottom_virtual_speaker_node_division_gains = (float *)malloc(num_speaker_nodes * sizeof(float))) == NULL) + if ( ( vbap->object_mode_bottom_virtual_speaker_node_division_gains = (float *) malloc( num_speaker_nodes * sizeof( float ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VBAP data\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VBAP data\n" ) ); } - set_zero(vbap->object_mode_bottom_virtual_speaker_node_division_gains, num_speaker_nodes); + set_zero( vbap->object_mode_bottom_virtual_speaker_node_division_gains, num_speaker_nodes ); is_success &= vbap->object_mode_bottom_virtual_speaker_node_division_gains != NULL; } @@ -565,22 +565,22 @@ ivas_error vbap_init_data( speaker_node_ele_deg_internal[vbap->bottom_virtual_speaker_node_index] = -90.0f; } - if (is_success && virtual_top_type != NO_VIRTUAL_SPEAKER_NODE) + if ( is_success && virtual_top_type != NO_VIRTUAL_SPEAKER_NODE ) { - if ((vbap->top_virtual_speaker_node_division_gains = (float *)malloc(num_speaker_nodes * sizeof(float))) == NULL) + if ( ( vbap->top_virtual_speaker_node_division_gains = (float *) malloc( num_speaker_nodes * sizeof( float ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VBAP data\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VBAP data\n" ) ); } - set_zero(vbap->top_virtual_speaker_node_division_gains, num_speaker_nodes); + set_zero( vbap->top_virtual_speaker_node_division_gains, num_speaker_nodes ); is_success &= vbap->top_virtual_speaker_node_division_gains != NULL; - if (ivas_format == MASA_ISM_FORMAT) + if ( ivas_format == MASA_ISM_FORMAT ) { - if ((vbap->object_mode_top_virtual_speaker_node_division_gains = (float *)malloc(num_speaker_nodes * sizeof(float))) == NULL) + if ( ( vbap->object_mode_top_virtual_speaker_node_division_gains = (float *) malloc( num_speaker_nodes * sizeof( float ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VBAP data\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VBAP data\n" ) ); } - set_zero(vbap->object_mode_top_virtual_speaker_node_division_gains, num_speaker_nodes); + set_zero( vbap->object_mode_top_virtual_speaker_node_division_gains, num_speaker_nodes ); is_success &= vbap->object_mode_top_virtual_speaker_node_division_gains != NULL; } @@ -588,40 +588,40 @@ ivas_error vbap_init_data( speaker_node_ele_deg_internal[vbap->top_virtual_speaker_node_index] = 90.0f; } - if (is_success && virtual_back_type != NO_VIRTUAL_SPEAKER_NODE) + if ( is_success && virtual_back_type != NO_VIRTUAL_SPEAKER_NODE ) { - if ((vbap->back_virtual_speaker_node_division_gains = (float *)malloc(num_speaker_nodes * sizeof(float))) == NULL) + if ( ( vbap->back_virtual_speaker_node_division_gains = (float *) malloc( num_speaker_nodes * sizeof( float ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VBAP data\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VBAP data\n" ) ); } - set_zero(vbap->back_virtual_speaker_node_division_gains, num_speaker_nodes); + set_zero( vbap->back_virtual_speaker_node_division_gains, num_speaker_nodes ); is_success &= vbap->back_virtual_speaker_node_division_gains != NULL; - if (ivas_format == MASA_ISM_FORMAT) + if ( ivas_format == MASA_ISM_FORMAT ) { - if ((vbap->object_mode_back_virtual_speaker_node_division_gains = (float *)malloc(num_speaker_nodes * sizeof(float))) == NULL) + if ( ( vbap->object_mode_back_virtual_speaker_node_division_gains = (float *) malloc( num_speaker_nodes * sizeof( float ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VBAP data\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VBAP data\n" ) ); } - set_zero(vbap->object_mode_back_virtual_speaker_node_division_gains, num_speaker_nodes); + set_zero( vbap->object_mode_back_virtual_speaker_node_division_gains, num_speaker_nodes ); is_success &= vbap->object_mode_back_virtual_speaker_node_division_gains != NULL; } speaker_node_azi_deg_internal[vbap->back_virtual_speaker_node_index] = 180.0f; speaker_node_ele_deg_internal[vbap->back_virtual_speaker_node_index] = 0.0f; } - init_speaker_node_direction_data(speaker_node_data, speaker_node_azi_deg_internal, speaker_node_ele_deg_internal, vbap->num_speaker_nodes_internal); + init_speaker_node_direction_data( speaker_node_data, speaker_node_azi_deg_internal, speaker_node_ele_deg_internal, vbap->num_speaker_nodes_internal ); /* Allocate and determine node-node connections */ - max_num_connections = (vbap->num_speaker_nodes_internal - 2) * 3; /* Theoretical maximum */ + max_num_connections = ( vbap->num_speaker_nodes_internal - 2 ) * 3; /* Theoretical maximum */ - if ((error = determine_connections(vbap->num_speaker_nodes_internal, speaker_node_data, connections, max_num_connections, &connection_group1_count, &connection_group2_start, &connection_group2_count)) != IVAS_ERR_OK) + if ( ( error = determine_connections( vbap->num_speaker_nodes_internal, speaker_node_data, connections, max_num_connections, &connection_group1_count, &connection_group2_start, &connection_group2_count ) ) != IVAS_ERR_OK ) { return error; } /* Allocate and determine virtual surface speaker node triplets */ - if (is_success) + if ( is_success ) { int16_t ch; int16_t speaker_nodes_group1_internal = 0; @@ -630,43 +630,43 @@ ivas_error vbap_init_data( uint8_t loop_done = 0; /* Count nodes in different groups to reserve correct memory */ - for (ch = 0; ch < vbap->num_speaker_nodes_internal && !loop_done; ch++) + for ( ch = 0; ch < vbap->num_speaker_nodes_internal && !loop_done; ch++ ) { - switch (speaker_node_data[ch].group) + switch ( speaker_node_data[ch].group ) { - case SPEAKER_NODE_ALL: - /* If there is even one speaker belonging to "all" group, then all speakers belong to the "all" group. - * We can skip further counts here. */ - speaker_nodes_group1_internal = vbap->num_speaker_nodes_internal; - loop_done = 1; - break; - case SPEAKER_NODE_BOTTOM_HALF: - speaker_nodes_group1_internal++; - break; - case SPEAKER_NODE_TOP_HALF: - speaker_nodes_group2_internal++; - break; - case SPEAKER_NODE_HORIZONTAL: - case SPEAKER_NODE_BACK: - speaker_nodes_group1_internal++; - speaker_nodes_group2_internal++; - speaker_nodes_horiz_internal++; - break; + case SPEAKER_NODE_ALL: + /* If there is even one speaker belonging to "all" group, then all speakers belong to the "all" group. + * We can skip further counts here. */ + speaker_nodes_group1_internal = vbap->num_speaker_nodes_internal; + loop_done = 1; + break; + case SPEAKER_NODE_BOTTOM_HALF: + speaker_nodes_group1_internal++; + break; + case SPEAKER_NODE_TOP_HALF: + speaker_nodes_group2_internal++; + break; + case SPEAKER_NODE_HORIZONTAL: + case SPEAKER_NODE_BACK: + speaker_nodes_group1_internal++; + speaker_nodes_group2_internal++; + speaker_nodes_horiz_internal++; + break; } } - if ((vbap->search_struct[0].triplets = (VBAP_VS_TRIPLET *)malloc(((speaker_nodes_group1_internal - 2) * 2 - (max(0, (speaker_nodes_horiz_internal - 2)))) * sizeof(VBAP_VS_TRIPLET))) == NULL) + if ( ( vbap->search_struct[0].triplets = (VBAP_VS_TRIPLET *) malloc( ( ( speaker_nodes_group1_internal - 2 ) * 2 - ( max( 0, ( speaker_nodes_horiz_internal - 2 ) ) ) ) * sizeof( VBAP_VS_TRIPLET ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VBAP data\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VBAP data\n" ) ); } is_success &= vbap->search_struct[0].triplets != NULL; - if (speaker_nodes_group2_internal > 0) + if ( speaker_nodes_group2_internal > 0 ) { vbap->num_search_structs = 2; - if ((vbap->search_struct[1].triplets = (VBAP_VS_TRIPLET *)malloc(((speaker_nodes_group2_internal - 2) * 2 - (max(0, (speaker_nodes_horiz_internal - 2)))) * sizeof(VBAP_VS_TRIPLET))) == NULL) + if ( ( vbap->search_struct[1].triplets = (VBAP_VS_TRIPLET *) malloc( ( ( speaker_nodes_group2_internal - 2 ) * 2 - ( max( 0, ( speaker_nodes_horiz_internal - 2 ) ) ) ) * sizeof( VBAP_VS_TRIPLET ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VBAP data\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VBAP data\n" ) ); } is_success &= vbap->search_struct[1].triplets != NULL; } @@ -677,44 +677,44 @@ ivas_error vbap_init_data( } } - if (is_success) + if ( is_success ) { - if (vbap->num_search_structs == 1) + if ( vbap->num_search_structs == 1 ) { /* If all speaker nodes belong to ALL set, then we only create one triplet set and search structure */ - vbap->search_struct[0].num_triplets = determine_virtual_surface_triplets(vbap->num_speaker_nodes_internal, speaker_node_data, connections, max_num_connections, vbap->search_struct[0].triplets, vbap->search_struct[0].initial_search_indices, SPEAKER_NODE_ALL); + vbap->search_struct[0].num_triplets = determine_virtual_surface_triplets( vbap->num_speaker_nodes_internal, speaker_node_data, connections, max_num_connections, vbap->search_struct[0].triplets, vbap->search_struct[0].initial_search_indices, SPEAKER_NODE_ALL ); } else { /* Otherwise, we have two sets and can handle them separately for more opmitized processing. */ - vbap->search_struct[0].num_triplets = determine_virtual_surface_triplets(vbap->num_speaker_nodes_internal, speaker_node_data, connections, connection_group1_count, vbap->search_struct[0].triplets, vbap->search_struct[0].initial_search_indices, SPEAKER_NODE_BOTTOM_HALF); - vbap->search_struct[1].num_triplets = determine_virtual_surface_triplets(vbap->num_speaker_nodes_internal, speaker_node_data, connections + connection_group2_start, connection_group2_count, vbap->search_struct[1].triplets, vbap->search_struct[1].initial_search_indices, SPEAKER_NODE_TOP_HALF); + vbap->search_struct[0].num_triplets = determine_virtual_surface_triplets( vbap->num_speaker_nodes_internal, speaker_node_data, connections, connection_group1_count, vbap->search_struct[0].triplets, vbap->search_struct[0].initial_search_indices, SPEAKER_NODE_BOTTOM_HALF ); + vbap->search_struct[1].num_triplets = determine_virtual_surface_triplets( vbap->num_speaker_nodes_internal, speaker_node_data, connections + connection_group2_start, connection_group2_count, vbap->search_struct[1].triplets, vbap->search_struct[1].initial_search_indices, SPEAKER_NODE_TOP_HALF ); } } /* Determine how the virtual node gains should be distributed to real nodes, if necessary (checked within function). */ - if (is_success) + if ( is_success ) { - determine_virtual_speaker_node_division_gains(vbap->top_virtual_speaker_node_index, vbap->top_virtual_speaker_node_division_gains, connections, virtual_top_type, max_num_connections, num_speaker_nodes, 0); - determine_virtual_speaker_node_division_gains(vbap->bottom_virtual_speaker_node_index, vbap->bottom_virtual_speaker_node_division_gains, connections, virtual_bottom_type, max_num_connections, num_speaker_nodes, 0); - determine_virtual_speaker_node_division_gains(vbap->back_virtual_speaker_node_index, vbap->back_virtual_speaker_node_division_gains, connections, virtual_back_type, max_num_connections, num_speaker_nodes, 0); - if (ivas_format == MASA_ISM_FORMAT) + determine_virtual_speaker_node_division_gains( vbap->top_virtual_speaker_node_index, vbap->top_virtual_speaker_node_division_gains, connections, virtual_top_type, max_num_connections, num_speaker_nodes, 0 ); + determine_virtual_speaker_node_division_gains( vbap->bottom_virtual_speaker_node_index, vbap->bottom_virtual_speaker_node_division_gains, connections, virtual_bottom_type, max_num_connections, num_speaker_nodes, 0 ); + determine_virtual_speaker_node_division_gains( vbap->back_virtual_speaker_node_index, vbap->back_virtual_speaker_node_division_gains, connections, virtual_back_type, max_num_connections, num_speaker_nodes, 0 ); + if ( ivas_format == MASA_ISM_FORMAT ) { - determine_virtual_speaker_node_division_gains(vbap->top_virtual_speaker_node_index, vbap->object_mode_top_virtual_speaker_node_division_gains, connections, virtual_top_type == NO_VIRTUAL_SPEAKER_NODE ? NO_VIRTUAL_SPEAKER_NODE : VIRTUAL_SPEAKER_NODE_DISTRIBUTE_ENERGY, max_num_connections, num_speaker_nodes, 1); - determine_virtual_speaker_node_division_gains(vbap->bottom_virtual_speaker_node_index, vbap->object_mode_bottom_virtual_speaker_node_division_gains, connections, virtual_bottom_type == NO_VIRTUAL_SPEAKER_NODE ? NO_VIRTUAL_SPEAKER_NODE : VIRTUAL_SPEAKER_NODE_DISTRIBUTE_ENERGY, max_num_connections, num_speaker_nodes, 1); - determine_virtual_speaker_node_division_gains(vbap->back_virtual_speaker_node_index, vbap->object_mode_back_virtual_speaker_node_division_gains, connections, virtual_back_type == NO_VIRTUAL_SPEAKER_NODE ? NO_VIRTUAL_SPEAKER_NODE : VIRTUAL_SPEAKER_NODE_DISTRIBUTE_ENERGY, max_num_connections, num_speaker_nodes, 1); + determine_virtual_speaker_node_division_gains( vbap->top_virtual_speaker_node_index, vbap->object_mode_top_virtual_speaker_node_division_gains, connections, virtual_top_type == NO_VIRTUAL_SPEAKER_NODE ? NO_VIRTUAL_SPEAKER_NODE : VIRTUAL_SPEAKER_NODE_DISTRIBUTE_ENERGY, max_num_connections, num_speaker_nodes, 1 ); + determine_virtual_speaker_node_division_gains( vbap->bottom_virtual_speaker_node_index, vbap->object_mode_bottom_virtual_speaker_node_division_gains, connections, virtual_bottom_type == NO_VIRTUAL_SPEAKER_NODE ? NO_VIRTUAL_SPEAKER_NODE : VIRTUAL_SPEAKER_NODE_DISTRIBUTE_ENERGY, max_num_connections, num_speaker_nodes, 1 ); + determine_virtual_speaker_node_division_gains( vbap->back_virtual_speaker_node_index, vbap->object_mode_back_virtual_speaker_node_division_gains, connections, virtual_back_type == NO_VIRTUAL_SPEAKER_NODE ? NO_VIRTUAL_SPEAKER_NODE : VIRTUAL_SPEAKER_NODE_DISTRIBUTE_ENERGY, max_num_connections, num_speaker_nodes, 1 ); } } pop_wmops(); - if (is_success) + if ( is_success ) { *hVBAPdata = vbap; } else { - vbap_free_data(&vbap); + vbap_free_data( &vbap ); } return IVAS_ERR_OK; @@ -791,9 +791,9 @@ void vbap_free_data( { free( ( *hVBAPdata )->top_virtual_speaker_node_division_gains ); } - if ((*hVBAPdata)->back_virtual_speaker_node_division_gains != NULL) + if ( ( *hVBAPdata )->back_virtual_speaker_node_division_gains != NULL ) { - free((*hVBAPdata)->back_virtual_speaker_node_division_gains); + free( ( *hVBAPdata )->back_virtual_speaker_node_division_gains ); } if ( ( *hVBAPdata )->object_mode_bottom_virtual_speaker_node_division_gains != NULL ) { @@ -995,12 +995,12 @@ void vbap_determine_gains( float *back_virtual_speaker_node_division_gains; - push_wmops("vbap_gains"); + push_wmops( "vbap_gains" ); num_speaker_nodes = hVBAPdata->num_speaker_nodes; bottom_virtual_speaker_node_index = hVBAPdata->bottom_virtual_speaker_node_index; top_virtual_speaker_node_index = hVBAPdata->top_virtual_speaker_node_index; back_virtual_speaker_node_index = hVBAPdata->back_virtual_speaker_node_index; - if (use_object_mode) + if ( use_object_mode ) { bottom_virtual_speaker_node_division_gains = hVBAPdata->object_mode_bottom_virtual_speaker_node_division_gains; top_virtual_speaker_node_division_gains = hVBAPdata->object_mode_top_virtual_speaker_node_division_gains; @@ -1013,71 +1013,71 @@ void vbap_determine_gains( back_virtual_speaker_node_division_gains = hVBAPdata->back_virtual_speaker_node_division_gains; } - panning_wrap_angles((float)azi_deg, (float)ele_deg, &azi_temp, &ele_temp); + panning_wrap_angles( (float) azi_deg, (float) ele_deg, &azi_temp, &ele_temp ); azi_rad = azi_temp * PI_OVER_180; ele_rad = ele_temp * PI_OVER_180; - panning_unit_vec[0] = cosf(azi_rad) * cosf(ele_rad); - panning_unit_vec[1] = sinf(azi_rad) * cosf(ele_rad); - panning_unit_vec[2] = sinf(ele_rad); + panning_unit_vec[0] = cosf( azi_rad ) * cosf( ele_rad ); + panning_unit_vec[1] = sinf( azi_rad ) * cosf( ele_rad ); + panning_unit_vec[2] = sinf( ele_rad ); /* Find the best VS triplet and speaker node gains for the panning direction using the prepared search structures. */ - if (hVBAPdata->num_search_structs == 2 && ele_deg > 0) + if ( hVBAPdata->num_search_structs == 2 && ele_deg > 0 ) { - triplet_index = determine_best_triplet_and_gains(&(hVBAPdata->search_struct[1]), panning_unit_vec, azi_deg, gain_triplet); + triplet_index = determine_best_triplet_and_gains( &( hVBAPdata->search_struct[1] ), panning_unit_vec, azi_deg, gain_triplet ); selected_triplet = &hVBAPdata->search_struct[1].triplets[triplet_index]; } else { - triplet_index = determine_best_triplet_and_gains(&(hVBAPdata->search_struct[0]), panning_unit_vec, azi_deg, gain_triplet); + triplet_index = determine_best_triplet_and_gains( &( hVBAPdata->search_struct[0] ), panning_unit_vec, azi_deg, gain_triplet ); selected_triplet = &hVBAPdata->search_struct[0].triplets[triplet_index]; } /* Normalize to unit energy */ gain_ene = 1e-12f; /* Add small value to avoid divide by zero. */ - for (ch = 0; ch < 3; ch++) + for ( ch = 0; ch < 3; ch++ ) { gain_ene += gain_triplet[ch] * gain_triplet[ch]; } - norm_value = inv_sqrt(gain_ene); + norm_value = inv_sqrt( gain_ene ); - for (ch = 0; ch < 3; ch++) + for ( ch = 0; ch < 3; ch++ ) { gain_triplet[ch] *= norm_value; /* Sanity check for rounding issues */ - if (gain_triplet[ch] < 0.0f) + if ( gain_triplet[ch] < 0.0f ) { gain_triplet[ch] = 0.0f; } } /* Flush gain target */ - set_zero(gains, num_speaker_nodes); + set_zero( gains, num_speaker_nodes ); /* Map gain triplet (internal speaker node configuration) to speaker node output (actual speaker node configuration) */ - for (ch = 0; ch < 3; ch++) + for ( ch = 0; ch < 3; ch++ ) { triplet_ch = selected_triplet->speaker_node[ch]; - if (triplet_ch == bottom_virtual_speaker_node_index) + if ( triplet_ch == bottom_virtual_speaker_node_index ) { - for (ch2 = 0; ch2 < num_speaker_nodes; ch2++) + for ( ch2 = 0; ch2 < num_speaker_nodes; ch2++ ) { gains[ch2] += bottom_virtual_speaker_node_division_gains[ch2] * gain_triplet[ch]; } } - else if (triplet_ch == top_virtual_speaker_node_index) + else if ( triplet_ch == top_virtual_speaker_node_index ) { - for (ch2 = 0; ch2 < num_speaker_nodes; ch2++) + for ( ch2 = 0; ch2 < num_speaker_nodes; ch2++ ) { gains[ch2] += top_virtual_speaker_node_division_gains[ch2] * gain_triplet[ch]; } } - else if (triplet_ch == back_virtual_speaker_node_index) + else if ( triplet_ch == back_virtual_speaker_node_index ) { - for (ch2 = 0; ch2 < num_speaker_nodes; ch2++) + for ( ch2 = 0; ch2 < num_speaker_nodes; ch2++ ) { gains[ch2] += back_virtual_speaker_node_division_gains[ch2] * gain_triplet[ch]; } @@ -1215,7 +1215,7 @@ static uint8_t vector_matrix_multiply_3x3_32_fx( return 1; } #else - /*! r: Status result if triplet is usable for panning. Allows early exit. */ +/*! r: Status result if triplet is usable for panning. Allows early exit. */ static uint8_t vector_matrix_multiply_3x3( const float *src_vector, /* i : input vector */ float matrix[3][3], /* i : input matrix */ @@ -1226,7 +1226,7 @@ static uint8_t vector_matrix_multiply_3x3( result[0] += src_vector[1] * matrix[1][0]; result[0] += src_vector[2] * matrix[2][0]; - if (result[0] < -0.01f) + if ( result[0] < -0.01f ) { return 0; } @@ -1235,7 +1235,7 @@ static uint8_t vector_matrix_multiply_3x3( result[1] += src_vector[1] * matrix[1][1]; result[1] += src_vector[2] * matrix[2][1]; - if (result[1] < -0.01f) + if ( result[1] < -0.01f ) { return 0; } @@ -1244,7 +1244,7 @@ static uint8_t vector_matrix_multiply_3x3( result[2] += src_vector[1] * matrix[1][2]; result[2] += src_vector[2] * matrix[2][2]; - if (result[2] < -0.01f) + if ( result[2] < -0.01f ) { return 0; } @@ -1264,10 +1264,10 @@ static uint8_t vector_matrix_multiply_3x3( #ifdef IVAS_FLOAT_FIXED static Word16 determine_best_triplet_and_gains_fx( - VBAP_SEARCH_STRUCT *search_struct, /* i : VBAP search struct */ - const Word16 panning_unit_vec_fx[3], /* i : panning unit vector */ - const Word16 azi_deg, /* i : panning azimuth */ - Word32 gains_fx[3] /* o : panning gains */ + VBAP_SEARCH_STRUCT *search_struct, /* i : VBAP search struct */ + const Word16 panning_unit_vec_fx[3], /* i : panning unit vector */ + const Word16 azi_deg, /* i : panning azimuth */ + Word32 gains_fx[3] /* o : panning gains */ ) { Word16 i, tr, k; @@ -1291,7 +1291,7 @@ static Word16 determine_best_triplet_and_gains_fx( /* Determine the correct search sector for that target panning direction using an optimized algorithm for * the chosen four sectors. */ - IF ( GT_16(abs_s( azi_deg ), 90) ) + IF( GT_16( abs_s( azi_deg ), 90 ) ) { sector = azi_deg < 0 ? 2 : 1; move16(); @@ -1308,45 +1308,45 @@ static Word16 determine_best_triplet_and_gains_fx( move16(); jump = 1; move16(); - FOR ( i = 0; i < num_triplets; i++ ) + FOR( i = 0; i < num_triplets; i++ ) { triplet_ok = vector_matrix_multiply_3x3_fx( panning_unit_vec_fx, search_struct->triplets[tr].inverse_matrix_fx, unnormalized_gains_fx, search_struct->triplets[tr].q_inverse_matrix ); - IF ( triplet_ok ) + IF( triplet_ok ) { min_gain_this_fx = L_min( ( L_min( unnormalized_gains_fx[0], unnormalized_gains_fx[1] ) ), unnormalized_gains_fx[2] ); move32(); - IF ( GT_32(min_gain_this_fx, best_min_gain_fx) ) + IF( GT_32( min_gain_this_fx, best_min_gain_fx ) ) { best_min_gain_fx = min_gain_this_fx; move32(); best_triplet = tr; move16(); - FOR ( k = 0; k < 3; k++ ) + FOR( k = 0; k < 3; k++ ) { gains_fx[k] = unnormalized_gains_fx[k]; move32(); } - IF ( !( best_min_gain_fx < 0 ) ) + IF( !( best_min_gain_fx < 0 ) ) { return best_triplet; } } } - tr = add(first_triplet, jump); - IF ( LT_16(tr, 0) ) + tr = add( first_triplet, jump ); + IF( LT_16( tr, 0 ) ) { - tr = add(tr, num_triplets); + tr = add( tr, num_triplets ); } - ELSE IF ( GE_16(tr, num_triplets) ) + ELSE IF( GE_16( tr, num_triplets ) ) { - tr = sub(tr, num_triplets); + tr = sub( tr, num_triplets ); } - jump = negate(jump); - IF ( GT_16(jump, 0) ) + jump = negate( jump ); + IF( GT_16( jump, 0 ) ) { - jump = add(jump, 1); + jump = add( jump, 1 ); } } @@ -1374,11 +1374,11 @@ static int16_t determine_best_triplet_and_gains( num_triplets = search_struct->num_triplets; best_min_gain = -999.9f; best_triplet = 0; - set_zero(gains, 3); + set_zero( gains, 3 ); /* Determine the correct search sector for that target panning direction using an optimized algorithm for * the chosen four sectors. */ - if (abs(azi_deg) > 90) + if ( abs( azi_deg ) > 90 ) { sector = azi_deg < 0 ? 2 : 1; } @@ -1390,39 +1390,39 @@ static int16_t determine_best_triplet_and_gains( tr = first_triplet; jump = 1; - for (i = 0; i < num_triplets; i++) + for ( i = 0; i < num_triplets; i++ ) { - triplet_ok = vector_matrix_multiply_3x3(panning_unit_vec, search_struct->triplets[tr].inverse_matrix, unnormalized_gains); - if (triplet_ok) + triplet_ok = vector_matrix_multiply_3x3( panning_unit_vec, search_struct->triplets[tr].inverse_matrix, unnormalized_gains ); + if ( triplet_ok ) { - min_gain_this = min((min(unnormalized_gains[0], unnormalized_gains[1])), unnormalized_gains[2]); + min_gain_this = min( ( min( unnormalized_gains[0], unnormalized_gains[1] ) ), unnormalized_gains[2] ); - if (min_gain_this > best_min_gain) + if ( min_gain_this > best_min_gain ) { best_min_gain = min_gain_this; best_triplet = tr; - for (k = 0; k < 3; k++) + for ( k = 0; k < 3; k++ ) { gains[k] = unnormalized_gains[k]; } - if (!(best_min_gain < 0.00f)) + if ( !( best_min_gain < 0.00f ) ) { return best_triplet; } } } tr = first_triplet + jump; - if (tr < 0) + if ( tr < 0 ) { tr += num_triplets; } - else if (tr >= num_triplets) + else if ( tr >= num_triplets ) { tr -= num_triplets; } jump *= -1; - if (jump > 0) + if ( jump > 0 ) { jump += 1; } @@ -1546,7 +1546,7 @@ static void determine_virtual_speaker_node_division_gains_fx( } } - free(exp_virtual_node_division_gains); + free( exp_virtual_node_division_gains ); return; } @@ -1736,15 +1736,15 @@ static enum VirtualSpeakerNodeType check_need_of_virtual_speaker_node( float max_elevation = 0.0f; /* The following considers if SPEAKER_NODE_BACK virtual speaker is needed */ - if (group == SPEAKER_NODE_BACK) + if ( group == SPEAKER_NODE_BACK ) { int16_t virtual_back_needed = 1; const float virtual_back_epsilon = -0.0175f; /* Corresponds to approximately 91 degrees, see code below */ - for (ch = 0; ch < hVBAPdata->num_speaker_nodes; ch++) + for ( ch = 0; ch < hVBAPdata->num_speaker_nodes; ch++ ) { - if (fabsf(speaker_node_ele_deg[ch]) < VBAP_VIRTUAL_BACK_ELE_LIMIT) + if ( fabsf( speaker_node_ele_deg[ch] ) < VBAP_VIRTUAL_BACK_ELE_LIMIT ) { - if (cosf(speaker_node_azi_deg[ch] * PI_OVER_180) < virtual_back_epsilon) + if ( cosf( speaker_node_azi_deg[ch] * PI_OVER_180 ) < virtual_back_epsilon ) { virtual_back_needed = 0; break; @@ -1752,7 +1752,7 @@ static enum VirtualSpeakerNodeType check_need_of_virtual_speaker_node( } } - if (virtual_back_needed) + if ( virtual_back_needed ) { hVBAPdata->back_virtual_speaker_node_index = hVBAPdata->num_speaker_nodes_internal; hVBAPdata->num_speaker_nodes_internal++; @@ -1763,31 +1763,31 @@ static enum VirtualSpeakerNodeType check_need_of_virtual_speaker_node( } /* The following considers if TOP or BOTTOM virtual speaker is needed */ - for (ch = 0; ch < hVBAPdata->num_speaker_nodes; ch++) + for ( ch = 0; ch < hVBAPdata->num_speaker_nodes; ch++ ) { - if (group == SPEAKER_NODE_TOP_HALF) + if ( group == SPEAKER_NODE_TOP_HALF ) { - if (speaker_node_ele_deg[ch] > max_elevation) + if ( speaker_node_ele_deg[ch] > max_elevation ) { max_elevation = speaker_node_ele_deg[ch]; } } else { - if ((-speaker_node_ele_deg[ch]) > max_elevation) + if ( ( -speaker_node_ele_deg[ch] ) > max_elevation ) { max_elevation = -speaker_node_ele_deg[ch]; } } } - if (max_elevation > VBAP_NO_VIRTUAL_SPEAKER_NODE_ELE_LIMIT - VBAP_EPSILON) + if ( max_elevation > VBAP_NO_VIRTUAL_SPEAKER_NODE_ELE_LIMIT - VBAP_EPSILON ) { return NO_VIRTUAL_SPEAKER_NODE; } /* Use virtual node */ - if (group == SPEAKER_NODE_BOTTOM_HALF) + if ( group == SPEAKER_NODE_BOTTOM_HALF ) { hVBAPdata->bottom_virtual_speaker_node_index = hVBAPdata->num_speaker_nodes_internal; } @@ -1797,7 +1797,7 @@ static enum VirtualSpeakerNodeType check_need_of_virtual_speaker_node( } hVBAPdata->num_speaker_nodes_internal++; - if (max_elevation > VBAP_DISTRIBUTE_VIRTUAL_SPEAKER_NODE_ELE_LIMIT - VBAP_EPSILON) + if ( max_elevation > VBAP_DISTRIBUTE_VIRTUAL_SPEAKER_NODE_ELE_LIMIT - VBAP_EPSILON ) { return VIRTUAL_SPEAKER_NODE_DISTRIBUTE_ENERGY; } @@ -1807,7 +1807,6 @@ static enum VirtualSpeakerNodeType check_need_of_virtual_speaker_node( #endif - /*-------------------------------------------------------------------------* * init_speaker_node_direction_data() * @@ -1968,11 +1967,11 @@ static void init_speaker_node_direction_data( int16_t num_horiz = 0; uint8_t in_all_mode = TRUE; - for (ch = 0; ch < num_speaker_nodes; ch++) + for ( ch = 0; ch < num_speaker_nodes; ch++ ) { speaker_node_data[ch].azi_deg = speaker_node_azi_deg[ch]; azi_rad = speaker_node_azi_deg[ch] * PI_OVER_180; - if ((speaker_node_ele_deg[ch] >= -5) && (speaker_node_ele_deg[ch] <= 5)) + if ( ( speaker_node_ele_deg[ch] >= -5 ) && ( speaker_node_ele_deg[ch] <= 5 ) ) { speaker_node_data[ch].ele_deg = 0.0f; ele_rad = 0.0f; @@ -1983,7 +1982,7 @@ static void init_speaker_node_direction_data( { speaker_node_data[ch].ele_deg = speaker_node_ele_deg[ch]; ele_rad = speaker_node_ele_deg[ch] * PI_OVER_180; - if (ele_rad < 0) + if ( ele_rad < 0 ) { speaker_node_data[ch].group = SPEAKER_NODE_BOTTOM_HALF; } @@ -1993,13 +1992,13 @@ static void init_speaker_node_direction_data( } } - speaker_node_data[ch].unit_vec[0] = cosf(azi_rad) * cosf(ele_rad); - speaker_node_data[ch].unit_vec[1] = sinf(azi_rad) * cosf(ele_rad); - speaker_node_data[ch].unit_vec[2] = sinf(ele_rad); + speaker_node_data[ch].unit_vec[0] = cosf( azi_rad ) * cosf( ele_rad ); + speaker_node_data[ch].unit_vec[1] = sinf( azi_rad ) * cosf( ele_rad ); + speaker_node_data[ch].unit_vec[2] = sinf( ele_rad ); } /* Check for largest horizontal gap if there are at least 3 horizontal speaker nodes */ - if (num_horiz >= 3) + if ( num_horiz >= 3 ) { int16_t i; uint16_t horiz_azi[VBAP_MAX_NUM_SPEAKER_NODES]; @@ -2007,25 +2006,25 @@ static void init_speaker_node_direction_data( uint16_t temp; i = 0; - for (ch = 0; ch < num_speaker_nodes && i < num_horiz; ch++) + for ( ch = 0; ch < num_speaker_nodes && i < num_horiz; ch++ ) { - if (speaker_node_data[ch].group == SPEAKER_NODE_HORIZONTAL) + if ( speaker_node_data[ch].group == SPEAKER_NODE_HORIZONTAL ) { - horiz_azi[i] = speaker_node_azi_deg[ch] < 0.0f ? (uint16_t)floorf(speaker_node_azi_deg[ch] + 360.0f) : (uint16_t)floorf(speaker_node_azi_deg[ch]); + horiz_azi[i] = speaker_node_azi_deg[ch] < 0.0f ? (uint16_t) floorf( speaker_node_azi_deg[ch] + 360.0f ) : (uint16_t) floorf( speaker_node_azi_deg[ch] ); i++; } } /* Reorder horizontal azi to increasing order */ - sort(horiz_azi, num_horiz); + sort( horiz_azi, num_horiz ); /* Find largest gap. Initialize with the wrap over gap. */ largest_gap = horiz_azi[0] - horiz_azi[num_horiz - 1] + 360; - for (ch = 0; ch < num_horiz - 1; ch++) + for ( ch = 0; ch < num_horiz - 1; ch++ ) { temp = horiz_azi[ch + 1] - horiz_azi[ch]; - if (temp > largest_gap) + if ( temp > largest_gap ) { largest_gap = temp; } @@ -2033,7 +2032,7 @@ static void init_speaker_node_direction_data( /* If largest gap is small enough, we have definitive zero elevation plane. * Otherwise, we should assign all speaker nodes to one group. */ - if (largest_gap <= VBAP_MAX_HORIZONTAL_GAP) + if ( largest_gap <= VBAP_MAX_HORIZONTAL_GAP ) { in_all_mode = FALSE; } @@ -2041,9 +2040,9 @@ static void init_speaker_node_direction_data( /* Designate all speaker nodes to same group if there was no definitive zero * elevation plane. */ - if (in_all_mode) + if ( in_all_mode ) { - for (ch = 0; ch < num_speaker_nodes; ch++) + for ( ch = 0; ch < num_speaker_nodes; ch++ ) { speaker_node_data[ch].group = SPEAKER_NODE_ALL; } @@ -2137,25 +2136,25 @@ static void matrix_inverse_3x3( float determinant; float cross_vec[3]; - vbap_crossp(input_matrix[1], input_matrix[2], cross_vec); + vbap_crossp( input_matrix[1], input_matrix[2], cross_vec ); - determinant = dotp(input_matrix[0], cross_vec, 3); + determinant = dotp( input_matrix[0], cross_vec, 3 ); - for (k = 0; k < 3; k++) + for ( k = 0; k < 3; k++ ) { inverse_matrix[k][0] = cross_vec[k] / determinant; } - vbap_crossp(input_matrix[2], input_matrix[0], cross_vec); + vbap_crossp( input_matrix[2], input_matrix[0], cross_vec ); - for (k = 0; k < 3; k++) + for ( k = 0; k < 3; k++ ) { inverse_matrix[k][1] = cross_vec[k] / determinant; } - vbap_crossp(input_matrix[0], input_matrix[1], cross_vec); + vbap_crossp( input_matrix[0], input_matrix[1], cross_vec ); - for (k = 0; k < 3; k++) + for ( k = 0; k < 3; k++ ) { inverse_matrix[k][2] = cross_vec[k] / determinant; } @@ -2239,7 +2238,8 @@ static Word16 check_and_store_triplet_fx( /* Get center azimuth for fast search use */ Word32 tmp_a = L_add( L_shr( L_add( speaker_node_data[chA].unit_vec_fx[1], speaker_node_data[chB].unit_vec_fx[1] ), 2 ), L_shr( speaker_node_data[chC].unit_vec_fx[1], 2 ) ); // Q28 /*Condition to make tmp_a 0 to adress precision loss seen*/ - IF (tmp_a == -8193) { + IF( tmp_a == -8193 ) + { tmp_a = 0; } Word32 tmp_b = L_add( L_shr( L_add( speaker_node_data[chA].unit_vec_fx[0], speaker_node_data[chB].unit_vec_fx[0] ), 2 ), L_shr( speaker_node_data[chC].unit_vec_fx[0], 2 ) ); // Q28 @@ -2282,18 +2282,18 @@ static int16_t check_and_store_triplet( speaker_node_triplet_unit_vec_matrix[0] = speaker_node_data[chA].unit_vec; speaker_node_triplet_unit_vec_matrix[1] = speaker_node_data[chB].unit_vec; speaker_node_triplet_unit_vec_matrix[2] = speaker_node_data[chC].unit_vec; - matrix_inverse_3x3(speaker_node_triplet_unit_vec_matrix, inverse_matrix); - + matrix_inverse_3x3( speaker_node_triplet_unit_vec_matrix, inverse_matrix ); + /* Check through all speaker nodes that none of them are within the triplet. * Node within the triplet is identified by that all three panning gains are positive. * Epsilon-condition is for some small rounding issues.*/ speaker_node_found_inside_triplet = 0; - for (ch_check = 0; ch_check < num_speaker_nodes; ch_check++) + for ( ch_check = 0; ch_check < num_speaker_nodes; ch_check++ ) { - if ((ch_check != chA) && (ch_check != chB) && (ch_check != chC)) + if ( ( ch_check != chA ) && ( ch_check != chB ) && ( ch_check != chC ) ) { - triplet_ok = vector_matrix_multiply_3x3(speaker_node_data[ch_check].unit_vec, inverse_matrix, unnormalized_gains); - if (triplet_ok && unnormalized_gains[0] > VBAP_EPSILON && unnormalized_gains[1] > VBAP_EPSILON && unnormalized_gains[2] > VBAP_EPSILON) + triplet_ok = vector_matrix_multiply_3x3( speaker_node_data[ch_check].unit_vec, inverse_matrix, unnormalized_gains ); + if ( triplet_ok && unnormalized_gains[0] > VBAP_EPSILON && unnormalized_gains[1] > VBAP_EPSILON && unnormalized_gains[2] > VBAP_EPSILON ) { speaker_node_found_inside_triplet = 1; break; @@ -2302,25 +2302,25 @@ static int16_t check_and_store_triplet( } /* No speaker node inside triplet -> appropriate triplet found, save data. */ - if (speaker_node_found_inside_triplet == 0) + if ( speaker_node_found_inside_triplet == 0 ) { - triplets[*triplet_index].speaker_node[0] = (uint8_t)chA; - triplets[*triplet_index].speaker_node[1] = (uint8_t)chB; - triplets[*triplet_index].speaker_node[2] = (uint8_t)chC; - for (k = 0; k < 3; k++) + triplets[*triplet_index].speaker_node[0] = (uint8_t) chA; + triplets[*triplet_index].speaker_node[1] = (uint8_t) chB; + triplets[*triplet_index].speaker_node[2] = (uint8_t) chC; + for ( k = 0; k < 3; k++ ) { - mvr2r(inverse_matrix[k], triplets[*triplet_index].inverse_matrix[k], 3); + mvr2r( inverse_matrix[k], triplets[*triplet_index].inverse_matrix[k], 3 ); } /* Get center azimuth for fast search use */ - triplet_azidegs[*triplet_index] = atan2f(speaker_node_data[chA].unit_vec[1] + speaker_node_data[chB].unit_vec[1] + speaker_node_data[chC].unit_vec[1], - speaker_node_data[chA].unit_vec[0] + speaker_node_data[chB].unit_vec[0] + speaker_node_data[chC].unit_vec[0]) * - _180_OVER_PI; + triplet_azidegs[*triplet_index] = atan2f( speaker_node_data[chA].unit_vec[1] + speaker_node_data[chB].unit_vec[1] + speaker_node_data[chC].unit_vec[1], + speaker_node_data[chA].unit_vec[0] + speaker_node_data[chB].unit_vec[0] + speaker_node_data[chC].unit_vec[0] ) * + _180_OVER_PI; /* Store increasing order indices for the later sorting step. */ triplet_order[*triplet_index] = *triplet_index; - (*triplet_index)++; + ( *triplet_index )++; return 1; } @@ -2466,12 +2466,12 @@ static int16_t determine_virtual_surface_triplets( int16_t triplet_order[VBAP_MAX_NUM_TRIPLETS]; /* Each connection can be used exactly by two different virtual surface triplets. */ - set_s(connection_uses_left, 2, VBAP_MAX_NUM_SPEAKER_NODES); + set_s( connection_uses_left, 2, VBAP_MAX_NUM_SPEAKER_NODES ); - for (chA = 0; chA < num_speaker_nodes; chA++) + for ( chA = 0; chA < num_speaker_nodes; chA++ ) { /* Early skip if not in correct group. */ - if (speaker_node_data[chA].group != allowed_group) + if ( speaker_node_data[chA].group != allowed_group ) { continue; } @@ -2479,9 +2479,9 @@ static int16_t determine_virtual_surface_triplets( /* Get all connections connected to current chA that have not been used by * two triplets yet. */ num_connected_to_chA = 0; - for (k = 0; k < max_num_connections; k++) + for ( k = 0; k < max_num_connections; k++ ) { - if ((connections[k][0] == chA || connections[k][1] == chA) && connection_uses_left[k] > 0) + if ( ( connections[k][0] == chA || connections[k][1] == chA ) && connection_uses_left[k] > 0 ) { connected_to_chA[num_connected_to_chA] = k; num_connected_to_chA++; @@ -2490,27 +2490,27 @@ static int16_t determine_virtual_surface_triplets( /* Check that we have enough connections to use. We need at least two available connections to form a triplet. * This can fail in later stages when all connections are already used. */ - if (num_connected_to_chA < 2) + if ( num_connected_to_chA < 2 ) { continue; } /* Try to form triplets from each valid connection. */ - for (k = 0; k < num_connected_to_chA; k++) + for ( k = 0; k < num_connected_to_chA; k++ ) { int16_t connect_index_k = connected_to_chA[k]; chB = connections[connect_index_k][0] == chA ? connections[connect_index_k][1] : connections[connect_index_k][0]; - for (l = k + 1; l < num_connected_to_chA; l++) + for ( l = k + 1; l < num_connected_to_chA; l++ ) { int16_t connect_index_l = connected_to_chA[l]; chC = connections[connect_index_l][0] == chA ? connections[connect_index_l][1] : connections[connect_index_l][0]; /* With chA, chB, and chC selected, we still need to find connection between chB and chC and verify that the triplet is valid */ - for (m = 0; m < max_num_connections; m++) + for ( m = 0; m < max_num_connections; m++ ) { - if ((connections[m][0] == chB && connections[m][1] == chC) || (connections[m][1] == chB && connections[m][0] == chC)) + if ( ( connections[m][0] == chB && connections[m][1] == chC ) || ( connections[m][1] == chB && connections[m][0] == chC ) ) { - if (check_and_store_triplet(chA, chB, chC, num_speaker_nodes, speaker_node_data, triplets, &num_triplets, triplet_azidegs, triplet_order)) + if ( check_and_store_triplet( chA, chB, chC, num_speaker_nodes, speaker_node_data, triplets, &num_triplets, triplet_azidegs, triplet_order ) ) { connection_uses_left[connect_index_k]--; connection_uses_left[connect_index_l]--; @@ -2523,7 +2523,7 @@ static int16_t determine_virtual_surface_triplets( /* Check if chA-chB connection has been used in two triplets already. If yes, then break out of loop * as this connection cannot be used for more triplets and we need to continue with another chA-chB * connection. */ - if (connection_uses_left[connect_index_k] < 1) + if ( connection_uses_left[connect_index_k] < 1 ) { break; } @@ -2533,9 +2533,9 @@ static int16_t determine_virtual_surface_triplets( /* All triplets should be stored now. Sort them for search use and then determine the initial search indices for * each search sector for this search struct. */ - v_sort_ind(triplet_azidegs, triplet_order, num_triplets); - reorder_triplets(triplets, triplet_order, num_triplets); - determine_initial_search_indices(num_triplets, triplet_azidegs, initial_search_indices); + v_sort_ind( triplet_azidegs, triplet_order, num_triplets ); + reorder_triplets( triplets, triplet_order, num_triplets ); + determine_initial_search_indices( num_triplets, triplet_azidegs, initial_search_indices ); return num_triplets; } @@ -2619,28 +2619,28 @@ static void determine_initial_search_indices( float min_azideg_diff; float azideg_diff; - for (i = 0; i < VBAP_NUM_SEARCH_SECTORS; i++) + for ( i = 0; i < VBAP_NUM_SEARCH_SECTORS; i++ ) { sector_border_start_azideg = i * VBAP_SEARCH_SECTOR_SIZE; - sector_border_end_azideg = (i + 1) * VBAP_SEARCH_SECTOR_SIZE; - sector_reference_azideg = (sector_border_start_azideg + sector_border_end_azideg) / 2.0f; + sector_border_end_azideg = ( i + 1 ) * VBAP_SEARCH_SECTOR_SIZE; + sector_reference_azideg = ( sector_border_start_azideg + sector_border_end_azideg ) / 2.0f; best_index = 0; min_azideg_diff = 9999.9f; - for (j = 0; j < num_triplets; j++) + for ( j = 0; j < num_triplets; j++ ) { azideg_diff = sector_reference_azideg - triplet_azidegs[j]; - if (azideg_diff > 180.0f) + if ( azideg_diff > 180.0f ) { azideg_diff -= 360.0f; } - else if (azideg_diff < -180.0f) + else if ( azideg_diff < -180.0f ) { azideg_diff += 360.0f; } - azideg_diff = fabsf(azideg_diff); + azideg_diff = fabsf( azideg_diff ); - if (azideg_diff < min_azideg_diff) + if ( azideg_diff < min_azideg_diff ) { min_azideg_diff = azideg_diff; best_index = j; @@ -2662,13 +2662,13 @@ static void determine_initial_search_indices( #ifdef IVAS_FLOAT_FIXED static ivas_error determine_connections_fx( - const Word16 num_speaker_nodes, /* i : number of speaker nodes */ + const Word16 num_speaker_nodes, /* i : number of speaker nodes */ const VBAP_SPEAKER_NODE *speaker_node_data, /* i : speaker node data */ - Word16 connections[][2], /* o : vector of connections */ - const Word16 max_num_connections, /* i : max number of connections */ - Word16 *group1_count, /* o : number of connections in first group */ - Word16 *group2_start, /* o : start of second group of connections */ - Word16 *group2_count /* o : number of connections in second group */ + Word16 connections[][2], /* o : vector of connections */ + const Word16 max_num_connections, /* i : max number of connections */ + Word16 *group1_count, /* o : number of connections in first group */ + Word16 *group2_start, /* o : start of second group of connections */ + Word16 *group2_count /* o : number of connections in second group */ ) { Word16 num_non_crossing_planes; @@ -2678,22 +2678,22 @@ static ivas_error determine_connections_fx( ivas_error error; - set32_fx(non_crossing_plane_elevation_deg_fx, 0, VBAP_MAX_PLANES); + set32_fx( non_crossing_plane_elevation_deg_fx, 0, VBAP_MAX_PLANES ); /* Reset connection data */ - FOR (c = 0; c < max_num_connections; c++) + FOR( c = 0; c < max_num_connections; c++ ) { connections[c][0] = VBAP_NOT_VALID_CONNECTION; move16(); } /* This function determines some prominent elevated planes, that are favoured in making node-node connections. */ - num_non_crossing_planes = determine_non_crossing_planes_fx(num_speaker_nodes, speaker_node_data, non_crossing_plane_elevation_deg_fx); + num_non_crossing_planes = determine_non_crossing_planes_fx( num_speaker_nodes, speaker_node_data, non_crossing_plane_elevation_deg_fx ); /* Process in different mode based on the grouping. It is enough to check for first node. */ - IF (EQ_16(speaker_node_data[0].group , SPEAKER_NODE_ALL)) + IF( EQ_16( speaker_node_data[0].group, SPEAKER_NODE_ALL ) ) { - IF ((error = formulate_half_sphere_connections_fx(speaker_node_data, num_speaker_nodes, SPEAKER_NODE_ALL, connections, &connection_write_index, max_num_connections, num_non_crossing_planes, non_crossing_plane_elevation_deg_fx)) != IVAS_ERR_OK) + IF( ( error = formulate_half_sphere_connections_fx( speaker_node_data, num_speaker_nodes, SPEAKER_NODE_ALL, connections, &connection_write_index, max_num_connections, num_non_crossing_planes, non_crossing_plane_elevation_deg_fx ) ) != IVAS_ERR_OK ) { return error; } @@ -2701,23 +2701,23 @@ static ivas_error determine_connections_fx( ELSE { /* The node-node connections are determined in three stages: bottom, horizontal, and top. */ - IF ((error = formulate_half_sphere_connections_fx(speaker_node_data, num_speaker_nodes, SPEAKER_NODE_BOTTOM_HALF, connections, &connection_write_index, max_num_connections, num_non_crossing_planes, non_crossing_plane_elevation_deg_fx)) != IVAS_ERR_OK) + IF( ( error = formulate_half_sphere_connections_fx( speaker_node_data, num_speaker_nodes, SPEAKER_NODE_BOTTOM_HALF, connections, &connection_write_index, max_num_connections, num_non_crossing_planes, non_crossing_plane_elevation_deg_fx ) ) != IVAS_ERR_OK ) { return error; } *group2_start = connection_write_index; move16(); - formulate_horizontal_connections_fx(speaker_node_data, num_speaker_nodes, connections, &connection_write_index); + formulate_horizontal_connections_fx( speaker_node_data, num_speaker_nodes, connections, &connection_write_index ); *group1_count = connection_write_index; move16(); - IF ((error = formulate_half_sphere_connections_fx(speaker_node_data, num_speaker_nodes, SPEAKER_NODE_TOP_HALF, connections, &connection_write_index, max_num_connections, num_non_crossing_planes, non_crossing_plane_elevation_deg_fx)) != IVAS_ERR_OK) + IF( ( error = formulate_half_sphere_connections_fx( speaker_node_data, num_speaker_nodes, SPEAKER_NODE_TOP_HALF, connections, &connection_write_index, max_num_connections, num_non_crossing_planes, non_crossing_plane_elevation_deg_fx ) ) != IVAS_ERR_OK ) { return error; } - *group2_count = sub(connection_write_index , *group2_start); + *group2_count = sub( connection_write_index, *group2_start ); } return IVAS_ERR_OK; @@ -2739,21 +2739,21 @@ static ivas_error determine_connections( float non_crossing_plane_elevation_deg[VBAP_MAX_PLANES]; ivas_error error; - set_f(non_crossing_plane_elevation_deg, 0.0f, VBAP_MAX_PLANES); + set_f( non_crossing_plane_elevation_deg, 0.0f, VBAP_MAX_PLANES ); /* Reset connection data */ - for (c = 0; c < max_num_connections; c++) + for ( c = 0; c < max_num_connections; c++ ) { connections[c][0] = VBAP_NOT_VALID_CONNECTION; } /* This function determines some prominent elevated planes, that are favoured in making node-node connections. */ - num_non_crossing_planes = determine_non_crossing_planes(num_speaker_nodes, speaker_node_data, non_crossing_plane_elevation_deg); + num_non_crossing_planes = determine_non_crossing_planes( num_speaker_nodes, speaker_node_data, non_crossing_plane_elevation_deg ); /* Process in different mode based on the grouping. It is enough to check for first node. */ - if (speaker_node_data[0].group == SPEAKER_NODE_ALL) + if ( speaker_node_data[0].group == SPEAKER_NODE_ALL ) { - if ((error = formulate_half_sphere_connections(speaker_node_data, num_speaker_nodes, SPEAKER_NODE_ALL, connections, &connection_write_index, max_num_connections, num_non_crossing_planes, non_crossing_plane_elevation_deg)) != IVAS_ERR_OK) + if ( ( error = formulate_half_sphere_connections( speaker_node_data, num_speaker_nodes, SPEAKER_NODE_ALL, connections, &connection_write_index, max_num_connections, num_non_crossing_planes, non_crossing_plane_elevation_deg ) ) != IVAS_ERR_OK ) { return error; } @@ -2761,16 +2761,16 @@ static ivas_error determine_connections( else { /* The node-node connections are determined in three stages: bottom, horizontal, and top. */ - if ((error = formulate_half_sphere_connections(speaker_node_data, num_speaker_nodes, SPEAKER_NODE_BOTTOM_HALF, connections, &connection_write_index, max_num_connections, num_non_crossing_planes, non_crossing_plane_elevation_deg)) != IVAS_ERR_OK) + if ( ( error = formulate_half_sphere_connections( speaker_node_data, num_speaker_nodes, SPEAKER_NODE_BOTTOM_HALF, connections, &connection_write_index, max_num_connections, num_non_crossing_planes, non_crossing_plane_elevation_deg ) ) != IVAS_ERR_OK ) { return error; } *group2_start = connection_write_index; - formulate_horizontal_connections(speaker_node_data, num_speaker_nodes, connections, &connection_write_index); + formulate_horizontal_connections( speaker_node_data, num_speaker_nodes, connections, &connection_write_index ); *group1_count = connection_write_index; - if ((error = formulate_half_sphere_connections(speaker_node_data, num_speaker_nodes, SPEAKER_NODE_TOP_HALF, connections, &connection_write_index, max_num_connections, num_non_crossing_planes, non_crossing_plane_elevation_deg)) != IVAS_ERR_OK) + if ( ( error = formulate_half_sphere_connections( speaker_node_data, num_speaker_nodes, SPEAKER_NODE_TOP_HALF, connections, &connection_write_index, max_num_connections, num_non_crossing_planes, non_crossing_plane_elevation_deg ) ) != IVAS_ERR_OK ) { return error; } @@ -2969,7 +2969,7 @@ static enum ConnectionClass determine_connection_class_fx( /*! r: type of connection */ static enum ConnectionClass determine_connection_class( const VBAP_SPEAKER_NODE *node_data, /* i : speaker node data */ - const Word16 num_speaker_nodes, /* i : number of speaker nodes */ + const Word16 num_speaker_nodes, /* i : number of speaker nodes */ const enum SpeakerNodeGroup group, /* i : speaker node group */ const int16_t chA, /* i : speaker node counter 1 */ const int16_t chB /* i : speaker node counter 2 */ @@ -2989,8 +2989,8 @@ static enum ConnectionClass determine_connection_class( /* Check if connection passes through origin. This is not desired. * When this happens, unit vectors point in opposite directions. */ - uvecdot = dotp(node_data[chA].unit_vec, node_data[chB].unit_vec, 3) + 1.0f; - if (uvecdot < VBAP_EPSILON && uvecdot > -VBAP_EPSILON) + uvecdot = dotp( node_data[chA].unit_vec, node_data[chB].unit_vec, 3 ) + 1.0f; + if ( uvecdot < VBAP_EPSILON && uvecdot > -VBAP_EPSILON ) { return CONNECTION_WITH_SPEAKER_NODE_BEHIND; } @@ -3002,43 +3002,43 @@ static enum ConnectionClass determine_connection_class( connection length AND at the same horizontal plane. These connections need to be weighted with a penalty (a special case, for example avoiding elevated L,R,C triplet) */ - for (ch = 0; ch < num_speaker_nodes; ch++) + for ( ch = 0; ch < num_speaker_nodes; ch++ ) { /* Select speaker_node only within TOP or BOTTOM sphere half, not being part of chA-chB pair */ - if ((group == node_data[ch].group) && (ch != chA) && (ch != chB)) + if ( ( group == node_data[ch].group ) && ( ch != chA ) && ( ch != chB ) ) { /* The following lines formulate the point on the chA-chB-connection that is nearest to the origo-ch-line */ p1 = node_data[chA].unit_vec; - for (k = 0; k < 3; k++) + for ( k = 0; k < 3; k++ ) { v1[k] = node_data[chB].unit_vec[k] - node_data[chA].unit_vec[k]; } v2 = node_data[ch].unit_vec; - v1v1 = dotp(v1, v1, 3); - v1v2 = dotp(v1, v2, 3); + v1v1 = dotp( v1, v1, 3 ); + v1v2 = dotp( v1, v2, 3 ); v2v2 = 1.0f; /* dotp(v2, v2) is always 1. */ - v1p1 = dotp(v1, p1, 3); - v2p1 = dotp(v2, p1, 3); - determinant = (v1v1) * (-v2v2) + (v1v2 * v1v2); + v1p1 = dotp( v1, p1, 3 ); + v2p1 = dotp( v2, p1, 3 ); + determinant = ( v1v1 ) * ( -v2v2 ) + ( v1v2 * v1v2 ); /* Norm distance = distance parameter on line chA-chB, determines point that is nearest to origo-ch line. Distance 0 means chA and distance 1 means chB. Can be outside this region as well.*/ - norm_distance_on_v1 = (1.0f / determinant) * ((v2v2) * (v1p1)+(-v1v2) * (v2p1)); + norm_distance_on_v1 = ( 1.0f / determinant ) * ( ( v2v2 ) * ( v1p1 ) + ( -v1v2 ) * ( v2p1 ) ); /* Continue only if the nearest point is between chA and chB */ - if (norm_distance_on_v1 > 0.0f && norm_distance_on_v1 < 1.0f) + if ( norm_distance_on_v1 > 0.0f && norm_distance_on_v1 < 1.0f ) { /* Formulate vTarget, that is an unit vector that goes through the determined point on chA-chB connection */ energy_sum = 0.0f; - for (k = 0; k < 3; k++) + for ( k = 0; k < 3; k++ ) { vTarget[k] = p1[k] + norm_distance_on_v1 * v1[k]; energy_sum += vTarget[k] * vTarget[k]; vec_diff[k] = vTarget[k] - v2[k]; } - eq_value = sqrtf(1.0f / energy_sum); - for (k = 0; k < 3; k++) + eq_value = sqrtf( 1.0f / energy_sum ); + for ( k = 0; k < 3; k++ ) { vTarget[k] *= eq_value; } @@ -3046,7 +3046,7 @@ static enum ConnectionClass determine_connection_class( /* A check if the angle between vTarget and node_data[ch].unit_vec is less than 1 degree. Essentially reveals if there is a speaker node too close "behind" the connection. Such connections should be rejected.*/ - if (dotp(vTarget, v2, 3) > 0.9998f) + if ( dotp( vTarget, v2, 3 ) > 0.9998f ) { return CONNECTION_WITH_SPEAKER_NODE_BEHIND; } @@ -3054,9 +3054,9 @@ static enum ConnectionClass determine_connection_class( /* A special case, mainly accounting for ELEVATED L,R,C speaker nodes. A triplet between these nodes is not desired if there is a top node, a penalty is implemented to take care of this. */ - if (sqrtf(v1v1) > 5.0f * sqrtf(dotp(vec_diff, vec_diff, 3))) + if ( sqrtf( v1v1 ) > 5.0f * sqrtf( dotp( vec_diff, vec_diff, 3 ) ) ) { - if (fabsf(node_data[chB].unit_vec[2] - node_data[chA].unit_vec[2]) < VBAP_EPSILON) + if ( fabsf( node_data[chB].unit_vec[2] - node_data[chA].unit_vec[2] ) < VBAP_EPSILON ) { return ELEVATED_PLANE_THIN_TRIANGLE_CONNECTION; } @@ -3138,7 +3138,7 @@ static void formulate_horizontal_connections( const VBAP_SPEAKER_NODE *speaker_node_data, /* i : speaker node data */ const int16_t num_speaker_nodes, /* i : number of speaker nodes */ int16_t connections[][2], /* o : vector of all connections */ - int16_t *connection_write_index) + int16_t *connection_write_index ) { int16_t ch; int16_t chCheck; @@ -3146,32 +3146,32 @@ static void formulate_horizontal_connections( float min_arc_diff; float arc_diff; - for (ch = 0; ch < num_speaker_nodes; ch++) + for ( ch = 0; ch < num_speaker_nodes; ch++ ) { /* Find next horizontal speaker node */ - if (speaker_node_data[ch].group == SPEAKER_NODE_HORIZONTAL) + if ( speaker_node_data[ch].group == SPEAKER_NODE_HORIZONTAL ) { next_index = -1; min_arc_diff = 9999.0f; - for (chCheck = 0; chCheck < num_speaker_nodes; chCheck++) + for ( chCheck = 0; chCheck < num_speaker_nodes; chCheck++ ) { - if ((ch != chCheck) && (speaker_node_data[chCheck].group == SPEAKER_NODE_HORIZONTAL)) + if ( ( ch != chCheck ) && ( speaker_node_data[chCheck].group == SPEAKER_NODE_HORIZONTAL ) ) { arc_diff = speaker_node_data[chCheck].azi_deg - speaker_node_data[ch].azi_deg; - while (arc_diff < 0.0f) + while ( arc_diff < 0.0f ) { arc_diff += 360.0f; } - if (arc_diff < min_arc_diff) + if ( arc_diff < min_arc_diff ) { min_arc_diff = arc_diff; next_index = chCheck; } - } + } } connections[*connection_write_index][0] = ch; connections[*connection_write_index][1] = next_index; - (*connection_write_index)++; + ( *connection_write_index )++; } } @@ -3222,14 +3222,14 @@ static int16_t check_plane_crossing( /* Find if the connection crosses a non-crossing plane, with 1-degree threshold. */ int16_t plane; - for (plane = 0; plane < num_non_crossing_planes; plane++) + for ( plane = 0; plane < num_non_crossing_planes; plane++ ) { - if ((ele1_deg > non_crossing_plane_elevation_deg[plane] + 1.0f) && (ele2_deg < non_crossing_plane_elevation_deg[plane] - 1.0f)) + if ( ( ele1_deg > non_crossing_plane_elevation_deg[plane] + 1.0f ) && ( ele2_deg < non_crossing_plane_elevation_deg[plane] - 1.0f ) ) { return 1; } - if ((ele2_deg > non_crossing_plane_elevation_deg[plane] + 1.0f) && (ele1_deg < non_crossing_plane_elevation_deg[plane] - 1.0f)) + if ( ( ele2_deg > non_crossing_plane_elevation_deg[plane] + 1.0f ) && ( ele1_deg < non_crossing_plane_elevation_deg[plane] - 1.0f ) ) { return 1; } @@ -3264,7 +3264,7 @@ static ivas_error get_half_sphere_connection_options_fx( FOR( node = 0; node < num_speaker_nodes; node++ ) { test(); - IF( EQ_16(speaker_node_data[node].group , group) || EQ_16( speaker_node_data[node].group, SPEAKER_NODE_HORIZONTAL ) ) + IF( EQ_16( speaker_node_data[node].group, group ) || EQ_16( speaker_node_data[node].group, SPEAKER_NODE_HORIZONTAL ) ) { max_num_connection_options = add( max_num_connection_options, index ); index = add( index, 1 ); @@ -3300,11 +3300,11 @@ static ivas_error get_half_sphere_connection_options_fx( { FOR( chB = chA + 1; chB < num_speaker_nodes; chB++ ) { - /* Second loudspeaker at the connection is at the half sphere, but so that first and second are not both horizontal. */ - test(); - test(); - IF( ( EQ_16( speaker_node_data[chB].group, group ) ) || ( EQ_16( speaker_node_data[chB].group, SPEAKER_NODE_HORIZONTAL ) && EQ_16( speaker_node_data[chA].group, group ) ) ) - { + /* Second loudspeaker at the connection is at the half sphere, but so that first and second are not both horizontal. */ + test(); + test(); + IF( ( EQ_16( speaker_node_data[chB].group, group ) ) || ( EQ_16( speaker_node_data[chB].group, SPEAKER_NODE_HORIZONTAL ) && EQ_16( speaker_node_data[chA].group, group ) ) ) + { Word16 ConnectionClass = determine_connection_class_fx( speaker_node_data, num_speaker_nodes, group, chA, chB ); Word32 unit_vec_dotp, unit_vec_dotp_sq, one_minus_unit_vec_dotp_sq, one_minus_unit_vec_dotp_sq_root; Word16 acos_val; @@ -3343,7 +3343,7 @@ static ivas_error get_half_sphere_connection_options_fx( } index = add( index, 1 ); } - } + } } } } @@ -3373,11 +3373,11 @@ static ivas_error get_half_sphere_connection_options_fx( res = BASOP_Util_Cmp_Mant32Exp( c_options[c_cmp].arc_weighted_fx, 31 - Q29, min_arc_weighted_fx_new, exp_min_arc_weighted_fx ); IF( EQ_16( res, -1 ) || EQ_16( res, 0 ) ) { - min_arc_weighted_fx_new = c_options[c_cmp].arc_weighted_fx; - move32(); - exp_min_arc_weighted_fx = sub( 31, Q29 ); - min_arc_index = c_cmp; - move16(); + min_arc_weighted_fx_new = c_options[c_cmp].arc_weighted_fx; + move32(); + exp_min_arc_weighted_fx = sub( 31, Q29 ); + min_arc_index = c_cmp; + move16(); } } c_options_reorder[c].chA = c_options[min_arc_index].chA; @@ -3416,9 +3416,9 @@ static ivas_error get_half_sphere_connection_options( ConnectionOption *c_options, *c_options_reorder; /* Count max num connection options at the half sphere */ - for (node = 0; node < num_speaker_nodes; node++) + for ( node = 0; node < num_speaker_nodes; node++ ) { - if (speaker_node_data[node].group == group || speaker_node_data[node].group == SPEAKER_NODE_HORIZONTAL) + if ( speaker_node_data[node].group == group || speaker_node_data[node].group == SPEAKER_NODE_HORIZONTAL ) { max_num_connection_options += index; index++; @@ -3426,12 +3426,12 @@ static ivas_error get_half_sphere_connection_options( } /* Init memory for connection options */ - if ((c_options = (ConnectionOption *)malloc(sizeof(ConnectionOption) * max_num_connection_options)) == NULL) + if ( ( c_options = (ConnectionOption *) malloc( sizeof( ConnectionOption ) * max_num_connection_options ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VBAP data\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VBAP data\n" ) ); } - for (c = 0; c < max_num_connection_options; c++) + for ( c = 0; c < max_num_connection_options; c++ ) { c_options[c].chA = -1; c_options[c].chB = -1; @@ -3441,36 +3441,36 @@ static ivas_error get_half_sphere_connection_options( /* Determine connection options for the half-sphere */ index = 0; - for (chA = 0; chA < num_speaker_nodes; chA++) + for ( chA = 0; chA < num_speaker_nodes; chA++ ) { /* First loudspeaker at the connection is at the half sphere */ - if (speaker_node_data[chA].group == group || speaker_node_data[chA].group == SPEAKER_NODE_HORIZONTAL) + if ( speaker_node_data[chA].group == group || speaker_node_data[chA].group == SPEAKER_NODE_HORIZONTAL ) { - for (chB = chA + 1; chB < num_speaker_nodes; chB++) + for ( chB = chA + 1; chB < num_speaker_nodes; chB++ ) { /* Second loudspeaker at the connection is at the half sphere, but so that first and second are not both horizontal. */ - if ((speaker_node_data[chB].group == group) || (speaker_node_data[chB].group == SPEAKER_NODE_HORIZONTAL && speaker_node_data[chA].group == group)) + if ( ( speaker_node_data[chB].group == group ) || ( speaker_node_data[chB].group == SPEAKER_NODE_HORIZONTAL && speaker_node_data[chA].group == group ) ) { - int16_t ConnectionClass = determine_connection_class(speaker_node_data, num_speaker_nodes, group, chA, chB); + int16_t ConnectionClass = determine_connection_class( speaker_node_data, num_speaker_nodes, group, chA, chB ); /* Connection is considered only if there is no speaker node behind it */ - if (ConnectionClass != CONNECTION_WITH_SPEAKER_NODE_BEHIND) + if ( ConnectionClass != CONNECTION_WITH_SPEAKER_NODE_BEHIND ) { /* Store connection information */ c_options[index].chA = chA; c_options[index].chB = chB; - c_options[index].arc = acosf(dotp(speaker_node_data[chA].unit_vec, speaker_node_data[chB].unit_vec, 3)); + c_options[index].arc = acosf( dotp( speaker_node_data[chA].unit_vec, speaker_node_data[chB].unit_vec, 3 ) ); c_options[index].arc_weighted = c_options[index].arc; /* A special case, mainly accounting for ELEVATED L,R,C speaker nodes. A triplet between these nodes is not desired if there is a top node, a penalty is implemented to take care of this. */ - if (ConnectionClass == ELEVATED_PLANE_THIN_TRIANGLE_CONNECTION) + if ( ConnectionClass == ELEVATED_PLANE_THIN_TRIANGLE_CONNECTION ) { c_options[index].arc_weighted *= 2.0f; } /* If the connection passes a pre-determined plane of speaker nodes, then add further penalty */ - if (check_plane_crossing(speaker_node_data[chA].ele_deg, speaker_node_data[chB].ele_deg, num_non_crossing_planes, non_crossing_plane_elevation_deg)) + if ( check_plane_crossing( speaker_node_data[chA].ele_deg, speaker_node_data[chB].ele_deg, num_non_crossing_planes, non_crossing_plane_elevation_deg ) ) { c_options[index].arc_weighted *= 2.0f; } @@ -3485,21 +3485,21 @@ static ivas_error get_half_sphere_connection_options( /* Init memory for reordered connection options and order by arc_weighted, * which informs of the preference order of the connections in case they cross */ - if ((c_options_reorder = (ConnectionOption *)malloc(sizeof(ConnectionOption) * (*num_connection_options))) == NULL) + if ( ( c_options_reorder = (ConnectionOption *) malloc( sizeof( ConnectionOption ) * ( *num_connection_options ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VBAP data\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VBAP data\n" ) ); } - for (c = 0; c < *num_connection_options; c++) + for ( c = 0; c < *num_connection_options; c++ ) { float min_arc_weighted; int16_t min_arc_index; min_arc_weighted = 1e20f; min_arc_index = -1; - for (c_cmp = 0; c_cmp < *num_connection_options; c_cmp++) + for ( c_cmp = 0; c_cmp < *num_connection_options; c_cmp++ ) { - if (c_options[c_cmp].arc_weighted <= min_arc_weighted) + if ( c_options[c_cmp].arc_weighted <= min_arc_weighted ) { min_arc_weighted = c_options[c_cmp].arc_weighted; min_arc_index = c_cmp; @@ -3514,7 +3514,7 @@ static ivas_error get_half_sphere_connection_options( /* Set reordered connections as output and free temporary data */ *connection_options_pr = c_options_reorder; - free(c_options); + free( c_options ); return IVAS_ERR_OK; } @@ -3718,7 +3718,7 @@ static ivas_error formulate_half_sphere_connections_fx( var2 = dotp_fixed( planeCrossingVec_fx, speaker_node_data[cmp_chB].unit_vec_fx, 3 ); move32(); - //final_exp_A, final_exp_B, exp_var1_sq, exp_var2_sq; + // final_exp_A, final_exp_B, exp_var1_sq, exp_var2_sq; var1_sq = Mpy_32_32( var1, var1 ); //(2 * (Q_planeCrossingVec - Q1) ) - Q31 var2_sq = Mpy_32_32( var2, var2 ); exp_var1_sq = shl( ( sub( Q31, sub( Q_planeCrossingVec, Q1 ) ) ), 1 ); @@ -3815,8 +3815,8 @@ static ivas_error formulate_half_sphere_connections( float cmp_arc; float normVal; float angleCmp; - float connection_arc[(VBAP_MAX_NUM_SPEAKER_NODES - 2) * 3]; - float connection_cross[(VBAP_MAX_NUM_SPEAKER_NODES - 2) * 3][3]; + float connection_arc[( VBAP_MAX_NUM_SPEAKER_NODES - 2 ) * 3]; + float connection_cross[( VBAP_MAX_NUM_SPEAKER_NODES - 2 ) * 3][3]; ConnectionOption *connection_options; int16_t num_connection_options; int16_t half_sphere_first_connection; @@ -3826,89 +3826,89 @@ static ivas_error formulate_half_sphere_connections( /* Obtain all connection options (i.e., channel pairs) at the half sphere. The function orders them * in terms of which connection to keep if two connections would cross each other. */ - if ((error = get_half_sphere_connection_options( - speaker_node_data, - group, - num_speaker_nodes, - num_non_crossing_planes, - non_crossing_plane_elevation_deg, - &connection_options, - &num_connection_options)) != IVAS_ERR_OK) + if ( ( error = get_half_sphere_connection_options( + speaker_node_data, + group, + num_speaker_nodes, + num_non_crossing_planes, + non_crossing_plane_elevation_deg, + &connection_options, + &num_connection_options ) ) != IVAS_ERR_OK ) { return error; } - set_f(connection_arc, 0.0f, max_num_connections); - for (c = 0; c < max_num_connections; c++) + set_f( connection_arc, 0.0f, max_num_connections ); + for ( c = 0; c < max_num_connections; c++ ) { - set_f(connection_cross[c], 0.0f, 3); + set_f( connection_cross[c], 0.0f, 3 ); } /* The following loop goes through all reasonable chA - chB pairs for the half-sphere */ c_opt = 0; - while (c_opt < num_connection_options && *connection_write_index < max_num_connections) + while ( c_opt < num_connection_options && *connection_write_index < max_num_connections ) { chA = connection_options[c_opt].chA; chB = connection_options[c_opt].chB; new_arc = connection_options[c_opt].arc; /* Cross-product is needed for later stages */ - vbap_crossp(speaker_node_data[chA].unit_vec, speaker_node_data[chB].unit_vec, new_cross); + vbap_crossp( speaker_node_data[chA].unit_vec, speaker_node_data[chB].unit_vec, new_cross ); /* Determine if new connection between chA and chB is valid */ new_connection_is_valid = 1; c = half_sphere_first_connection; - while ((c < *connection_write_index) && new_connection_is_valid) + while ( ( c < *connection_write_index ) && new_connection_is_valid ) { cmp_chA = connections[c][0]; cmp_chB = connections[c][1]; /* The connections are compared only if they don't involve same speaker nodes */ - if ((cmp_chA != chA) && (cmp_chA != chB) && (cmp_chB != chA) && (cmp_chB != chB)) + if ( ( cmp_chA != chA ) && ( cmp_chA != chB ) && ( cmp_chB != chA ) && ( cmp_chB != chB ) ) { /* The following lines determine if the connection chA-chB crosses with the connection cmp_chA-cmp_chB.*/ /* The connections, i.e., node-pairs determine a plane. The crossing can be determined by * studying the intersection of these planes. */ - vbap_crossp(connection_cross[c], new_cross, planeCrossingVec); + vbap_crossp( connection_cross[c], new_cross, planeCrossingVec ); tmpFloat = 1e-12f; cmp_arc = connection_arc[c]; - for (k = 0; k < 3; k++) + for ( k = 0; k < 3; k++ ) { tmpFloat += planeCrossingVec[k] * planeCrossingVec[k]; } - normVal = sqrtf(1.0f / tmpFloat); + normVal = sqrtf( 1.0f / tmpFloat ); - for (k = 0; k < 3; k++) + for ( k = 0; k < 3; k++ ) { planeCrossingVec[k] *= normVal; } /* If the plane intersection is between both connections, then the two connections cross. */ /* Study first if the crossing is between arc chA-chB */ - angleCmp = acosf(dotp(planeCrossingVec, speaker_node_data[chA].unit_vec, 3)); - angleCmp += acosf(dotp(planeCrossingVec, speaker_node_data[chB].unit_vec, 3)); + angleCmp = acosf( dotp( planeCrossingVec, speaker_node_data[chA].unit_vec, 3 ) ); + angleCmp += acosf( dotp( planeCrossingVec, speaker_node_data[chB].unit_vec, 3 ) ); within_first_arc = 0; - if (fabsf(new_arc - angleCmp) < 0.01f) + if ( fabsf( new_arc - angleCmp ) < 0.01f ) { within_first_arc = 1; } - else if (fabsf(new_arc - (2.0f * EVS_PI - angleCmp)) < 0.01f) + else if ( fabsf( new_arc - ( 2.0f * EVS_PI - angleCmp ) ) < 0.01f ) { within_first_arc = 1; /* In this case, the plane crossing vector is inverted. The inverse is another * plane-crossing vector, and detected to be between chA-chB connection.*/ - for (k = 0; k < 3; k++) + for ( k = 0; k < 3; k++ ) { planeCrossingVec[k] *= -1.0f; } } /* Study if the crossing is also between arc cmp_chA-cmp_chB */ - if (within_first_arc > 0) + if ( within_first_arc > 0 ) { - angleCmp = acosf(dotp(planeCrossingVec, speaker_node_data[cmp_chA].unit_vec, 3)); - angleCmp += acosf(dotp(planeCrossingVec, speaker_node_data[cmp_chB].unit_vec, 3)); - if (fabsf(cmp_arc - angleCmp) < 0.01f) + angleCmp = acosf( dotp( planeCrossingVec, speaker_node_data[cmp_chA].unit_vec, 3 ) ); + angleCmp += acosf( dotp( planeCrossingVec, speaker_node_data[cmp_chB].unit_vec, 3 ) ); + if ( fabsf( cmp_arc - angleCmp ) < 0.01f ) { /* A crossing is detected. The new connection is not valid, because * the connections were ordered in order of preference (arc_weighted) */ @@ -3920,7 +3920,7 @@ static ivas_error formulate_half_sphere_connections( } /* Store the new connection which has been confirmed valid */ - if (new_connection_is_valid > 0) + if ( new_connection_is_valid > 0 ) { connections[*connection_write_index][0] = chA; connections[*connection_write_index][1] = chB; @@ -3928,12 +3928,12 @@ static ivas_error formulate_half_sphere_connections( connection_cross[*connection_write_index][0] = new_cross[0]; connection_cross[*connection_write_index][1] = new_cross[1]; connection_cross[*connection_write_index][2] = new_cross[2]; - (*connection_write_index)++; + ( *connection_write_index )++; } c_opt++; } - free(connection_options); + free( connection_options ); return IVAS_ERR_OK; } @@ -4062,48 +4062,48 @@ static int16_t determine_non_crossing_planes( num_planes = 0; /* For each plane, check if a non-crossing plane should be determined */ - while (ele_check < 90.0f) + while ( ele_check < 90.0f ) { next_ele_check = 999.9f; /* Find next node elevation that is not in horizontal plane */ - for (ch = 0; ch < num_speaker_nodes; ch++) + for ( ch = 0; ch < num_speaker_nodes; ch++ ) { - if ((node_data[ch].group != SPEAKER_NODE_HORIZONTAL) && (node_data[ch].ele_deg > ele_check + VBAP_EPSILON) && (node_data[ch].ele_deg < next_ele_check - VBAP_EPSILON)) + if ( ( node_data[ch].group != SPEAKER_NODE_HORIZONTAL ) && ( node_data[ch].ele_deg > ele_check + VBAP_EPSILON ) && ( node_data[ch].ele_deg < next_ele_check - VBAP_EPSILON ) ) { next_ele_check = node_data[ch].ele_deg; } } ele_check = next_ele_check; - if (ele_check > 90.0f) + if ( ele_check > 90.0f ) { /* When no next node elevation found, break loop */ break; } max_gap = -9999.9f; - for (ch = 0; ch < num_speaker_nodes; ch++) + for ( ch = 0; ch < num_speaker_nodes; ch++ ) { /* Find gap to the next speaker node at the same plane */ - if (fabsf(node_data[ch].ele_deg - ele_check) < VBAP_EPSILON) + if ( fabsf( node_data[ch].ele_deg - ele_check ) < VBAP_EPSILON ) { gap_to_next_ls = 99999.9f; - for (ch_cmp = 0; ch_cmp < num_speaker_nodes; ch_cmp++) + for ( ch_cmp = 0; ch_cmp < num_speaker_nodes; ch_cmp++ ) { - if (ch_cmp != ch && fabsf(node_data[ch_cmp].ele_deg - ele_check) < VBAP_EPSILON) + if ( ch_cmp != ch && fabsf( node_data[ch_cmp].ele_deg - ele_check ) < VBAP_EPSILON ) { float gap = node_data[ch_cmp].azi_deg - node_data[ch].azi_deg; - while (gap < 0) + while ( gap < 0 ) { gap += 360.0f; } - if (gap < gap_to_next_ls) + if ( gap < gap_to_next_ls ) { gap_to_next_ls = gap; } } } /* Find maximum gap on that plane */ - if (gap_to_next_ls > max_gap) + if ( gap_to_next_ls > max_gap ) { max_gap = gap_to_next_ls; } @@ -4111,11 +4111,11 @@ static int16_t determine_non_crossing_planes( } /* If maximum gap is small enough, then a non-crossing plane is detected */ - if (max_gap < (VBAP_MAX_HORIZONTAL_GAP_FOR_PLANE_DETECTION + VBAP_EPSILON) && max_gap > 0.0f) + if ( max_gap < ( VBAP_MAX_HORIZONTAL_GAP_FOR_PLANE_DETECTION + VBAP_EPSILON ) && max_gap > 0.0f ) { non_crossing_plane_elevation_deg[num_planes] = ele_check; num_planes++; - if (num_planes == VBAP_MAX_PLANES) + if ( num_planes == VBAP_MAX_PLANES ) { /* Memory init limit. Does not happen with any real speaker node configuration. Triangulation succeeds even if number of non_crossing_planes are limited. */ @@ -4169,13 +4169,13 @@ static void reorder_triplets( int16_t c; /* First copy to temp array */ - for (c = 0; c < num_triplets; c++) + for ( c = 0; c < num_triplets; c++ ) { tempTriplets[c] = triplets[c]; } /* Then move back in sorted order */ - for (c = 0; c < num_triplets; c++) + for ( c = 0; c < num_triplets; c++ ) { triplets[c] = tempTriplets[target_order[c]]; } @@ -4183,4 +4183,4 @@ static void reorder_triplets( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 4aa4ba942..7abd83ab9 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -130,8 +130,8 @@ typedef struct AUDIO_CONFIG inConfig; IVAS_REND_InputId id; IVAS_REND_AudioBuffer inputBuffer; - float gain; /* Linear, not in dB */ - Word32 gain_fx; /* Linear, not in dB */ + float gain; /* Linear, not in dB */ + Word32 gain_fx; /* Linear, not in dB */ rendering_context ctx; Word32 numNewSamplesPerChannel; /* Used to keep track how much new audio was fed before rendering current frame */ } input_base; @@ -141,7 +141,7 @@ typedef struct AUDIO_CONFIG inConfig; IVAS_REND_InputId id; IVAS_REND_AudioBuffer inputBuffer; - float gain; /* Linear, not in dB */ + float gain; /* Linear, not in dB */ rendering_context ctx; int32_t numNewSamplesPerChannel; /* Used to keep track how much new audio was fed before rendering current frame */ } input_base; @@ -381,13 +381,12 @@ struct IVAS_REND static ivas_error initMasaExtRenderer( input_masa *inputMasa, const AUDIO_CONFIG outConfig ); static void freeMasaExtRenderer( MASA_EXT_REND_HANDLE *hMasaExtRendOut ); -#ifdef IVAS_FLOAT_FIXED //TOBE REMOVED +#ifdef IVAS_FLOAT_FIXED // TOBE REMOVED static void intermidiate_ext_dirac_render( - MASA_EXT_REND_HANDLE hMasaExtRend, /* i/o: MASA renderer structure */ - Word32 *output_f[], /* i/o: input/output signals in time domain */ - float *output_f_flt[], /* i/o: input/output signals in time domain */ - Word16 to_fix -); + MASA_EXT_REND_HANDLE hMasaExtRend, /* i/o: MASA renderer structure */ + Word32 *output_f[], /* i/o: input/output signals in time domain */ + float *output_f_flt[], /* i/o: input/output signals in time domain */ + Word16 to_fix ); #endif /*-------------------------------------------------------------------* * Local functions @@ -2135,14 +2134,14 @@ static IVAS_ISM_METADATA defaultObjectPosition( { IVAS_ISM_METADATA pos; - pos.azimuth_fx = 0; + pos.azimuth_fx = 0; pos.elevation_fx = 0; pos.radius_fx = ONE_IN_Q9; pos.spread_fx = 0; pos.gainFactor_fx = ONE_IN_Q31; pos.yaw_fx = 0; pos.pitch_fx = 0; -#if 0/*TODO: To be removed*/ +#if 0 /*TODO: To be removed*/ pos.azimuth = 0.0f; pos.elevation = 0.0f; pos.radius = 1.0f; @@ -2275,21 +2274,21 @@ static bool isIoConfigPairSupported( #ifdef IVAS_FLOAT_FIXED static ivas_error initIsmMasaRendering( input_ism *inputIsm, - const Word32 inSampleRate) + const Word32 inSampleRate ) { ivas_error error; - IF(inputIsm->tdRendWrapper.hBinRendererTd != NULL) + IF( inputIsm->tdRendWrapper.hBinRendererTd != NULL ) { - ivas_td_binaural_close_fx(&inputIsm->tdRendWrapper.hBinRendererTd); + ivas_td_binaural_close_fx( &inputIsm->tdRendWrapper.hBinRendererTd ); inputIsm->tdRendWrapper.hHrtfTD = NULL; } - ivas_rend_closeCrend(&inputIsm->crendWrapper); + ivas_rend_closeCrend( &inputIsm->crendWrapper ); - ivas_reverb_close(&inputIsm->hReverb); + ivas_reverb_close( &inputIsm->hReverb ); - IF((error = ivas_omasa_ana_open(&inputIsm->hOMasa, inSampleRate, inputIsm->total_num_objects)) != IVAS_ERR_OK) + IF( ( error = ivas_omasa_ana_open( &inputIsm->hOMasa, inSampleRate, inputIsm->total_num_objects ) ) != IVAS_ERR_OK ) { return error; } @@ -2303,7 +2302,7 @@ static ivas_error initIsmMasaRendering( { ivas_error error; - IF ( inputIsm->tdRendWrapper.hBinRendererTd != NULL ) + IF( inputIsm->tdRendWrapper.hBinRendererTd != NULL ) { #ifdef IVAS_FLOAT_FIXED ivas_td_binaural_close_fx( &inputIsm->tdRendWrapper.hBinRendererTd ); @@ -2317,7 +2316,7 @@ static ivas_error initIsmMasaRendering( ivas_reverb_close( &inputIsm->hReverb ); - IF ( ( error = ivas_omasa_ana_open( &inputIsm->hOMasa, inSampleRate, inputIsm->total_num_objects ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_omasa_ana_open( &inputIsm->hOMasa, inSampleRate, inputIsm->total_num_objects ) ) != IVAS_ERR_OK ) { return error; } @@ -2343,12 +2342,12 @@ static ivas_error setRendInputActiveIsm( rendCtx = inputIsm->base.ctx; outConfig = *rendCtx.pOutConfig; - IF ( !isIoConfigPairSupported( inConfig, outConfig ) ) + IF( !isIoConfigPairSupported( inConfig, outConfig ) ) { return IVAS_ERR_IO_CONFIG_PAIR_NOT_SUPPORTED; } - IF ( ( error = allocateInputBaseBufferData_fx( &inputIsm->bufferData_fx, MAX_BUFFER_LENGTH ) ) != IVAS_ERR_OK ) + IF( ( error = allocateInputBaseBufferData_fx( &inputIsm->bufferData_fx, MAX_BUFFER_LENGTH ) ) != IVAS_ERR_OK ) { return error; } @@ -2370,16 +2369,16 @@ static ivas_error setRendInputActiveIsm( error = IVAS_ERR_OK; - IF ( EQ_16(outConfig , IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR) ) + IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) ) { - IF ( ( error = ivas_rend_openCrend( &inputIsm->crendWrapper, IVAS_AUDIO_CONFIG_7_1_4, outConfig, hRendCfg, NULL, *rendCtx.pOutSampleRate ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_rend_openCrend( &inputIsm->crendWrapper, IVAS_AUDIO_CONFIG_7_1_4, outConfig, hRendCfg, NULL, *rendCtx.pOutSampleRate ) ) != IVAS_ERR_OK ) { return error; } } - ELSE IF ( EQ_16(outConfig , IVAS_AUDIO_CONFIG_MASA1) || EQ_16(outConfig , IVAS_AUDIO_CONFIG_MASA2) ) + ELSE IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_MASA1 ) || EQ_16( outConfig, IVAS_AUDIO_CONFIG_MASA2 ) ) { - IF ( ( error = initIsmMasaRendering( inputIsm, *rendCtx.pOutSampleRate ) ) != IVAS_ERR_OK ) + IF( ( error = initIsmMasaRendering( inputIsm, *rendCtx.pOutSampleRate ) ) != IVAS_ERR_OK ) { return error; } @@ -2413,9 +2412,9 @@ static ivas_error setRendInputActiveIsm( } } - IF ( EQ_16(outConfig , IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB) ) + IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { - IF ( ( error = ivas_reverb_open_fx( &( inputIsm->hReverb ), outConfig, NULL, inputIsm->tdRendWrapper.hBinRendererTd->HrFiltSet_p->lr_energy_and_iac_fx, hRendCfg, *rendCtx.pOutSampleRate ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_reverb_open_fx( &( inputIsm->hReverb ), outConfig, NULL, inputIsm->tdRendWrapper.hBinRendererTd->HrFiltSet_p->lr_energy_and_iac_fx, hRendCfg, *rendCtx.pOutSampleRate ) ) != IVAS_ERR_OK ) { return error; } @@ -3943,7 +3942,7 @@ static ivas_error initMcBinauralRendering( const AUDIO_CONFIG inConfig, const AUDIO_CONFIG outConfig, RENDER_CONFIG_DATA *hRendCfg, - UWord8 reconfigureFlag) + UWord8 reconfigureFlag ) { ivas_error error; Word32 binauralDelayNs; @@ -3953,16 +3952,16 @@ static ivas_error initMcBinauralRendering( /* Allocate TD binaural renderer for custom loudspeaker layouts (regardless of headrotation) or planar MC layouts with headrotation, CREND for the rest */ useTDRend = FALSE; - IF(NE_16(outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR)) + IF( NE_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) ) { test(); test(); - IF(EQ_16(inConfig, IVAS_AUDIO_CONFIG_LS_CUSTOM) && NE_16(outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB)) + IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && NE_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { useTDRend = TRUE; } - ELSE IF((EQ_16(inConfig, IVAS_AUDIO_CONFIG_5_1) || EQ_16(inConfig, IVAS_AUDIO_CONFIG_7_1)) && - (inputMc->base.ctx.pHeadRotData->headRotEnabled)) + ELSE IF( ( EQ_16( inConfig, IVAS_AUDIO_CONFIG_5_1 ) || EQ_16( inConfig, IVAS_AUDIO_CONFIG_7_1 ) ) && + ( inputMc->base.ctx.pHeadRotData->headRotEnabled ) ) { useTDRend = TRUE; } @@ -3970,33 +3969,33 @@ static ivas_error initMcBinauralRendering( /* if TD renderer was open and we need to use CREND, close it */ test(); - IF(!reconfigureFlag || (!useTDRend && inputMc->tdRendWrapper.hBinRendererTd != NULL)) + IF( !reconfigureFlag || ( !useTDRend && inputMc->tdRendWrapper.hBinRendererTd != NULL ) ) { - ivas_td_binaural_close_fx(&inputMc->tdRendWrapper.hBinRendererTd); + ivas_td_binaural_close_fx( &inputMc->tdRendWrapper.hBinRendererTd ); inputMc->tdRendWrapper.hHrtfTD = NULL; } /* if we need to use TD renderer and CREND was open, close it */ - IF(useTDRend) + IF( useTDRend ) { - ivas_rend_closeCrend(&inputMc->crendWrapper); + ivas_rend_closeCrend( &inputMc->crendWrapper ); } test(); test(); - IF(!reconfigureFlag || (!useTDRend && NE_16(outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB) && inputMc->hReverb != NULL)) + IF( !reconfigureFlag || ( !useTDRend && NE_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) && inputMc->hReverb != NULL ) ) { - ivas_reverb_close(&inputMc->hReverb); + ivas_reverb_close( &inputMc->hReverb ); } test(); test(); - IF(!reconfigureFlag || (EQ_16(inConfig, IVAS_AUDIO_CONFIG_LS_CUSTOM) && !inputMc->base.ctx.pHeadRotData->headRotEnabled)) + IF( !reconfigureFlag || ( EQ_16( inConfig, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && !inputMc->base.ctx.pHeadRotData->headRotEnabled ) ) { - IF(inputMc->efapInWrapper.hEfap != NULL) + IF( inputMc->efapInWrapper.hEfap != NULL ) { - efap_free_data(&inputMc->efapInWrapper.hEfap); + efap_free_data( &inputMc->efapInWrapper.hEfap ); } } @@ -4004,76 +4003,76 @@ static ivas_error initMcBinauralRendering( test(); test(); - IF(useTDRend && inputMc->tdRendWrapper.hBinRendererTd == NULL) + IF( useTDRend && inputMc->tdRendWrapper.hBinRendererTd == NULL ) { Word16 SrcInd[MAX_NUM_TDREND_CHANNELS]; Word16 num_src; - IF((error = ivas_td_binaural_open_ext_fx(&inputMc->tdRendWrapper, inConfig, hRendCfg, &inputMc->customLsInput, outSampleRate, SrcInd, &num_src)) != IVAS_ERR_OK) + IF( ( error = ivas_td_binaural_open_ext_fx( &inputMc->tdRendWrapper, inConfig, hRendCfg, &inputMc->customLsInput, outSampleRate, SrcInd, &num_src ) ) != IVAS_ERR_OK ) { return error; } Word16 nchan_rend = num_src; - IF(EQ_16(outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB) && inputMc->hReverb == NULL) + IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) && inputMc->hReverb == NULL ) { nchan_rend--; /* Skip LFE channel -- added to the others */ } - FOR(Word16 nS = 0; nS < nchan_rend; nS++) + FOR( Word16 nS = 0; nS < nchan_rend; nS++ ) { TDREND_SRC_t *Src_p = inputMc->tdRendWrapper.hBinRendererTd->Sources[SrcInd[nS]]; - IF(Src_p != NULL) + IF( Src_p != NULL ) { - IF(Src_p->SrcSpatial_p != NULL) + IF( Src_p->SrcSpatial_p != NULL ) { Src_p->SrcSpatial_p->q_Pos_p = 31; } - IF(inputMc->tdRendWrapper.hBinRendererTd->Sources[nS] != NULL) + IF( inputMc->tdRendWrapper.hBinRendererTd->Sources[nS] != NULL ) { TDREND_SRC_SPATIAL_t *SrcSpatial_p = inputMc->tdRendWrapper.hBinRendererTd->Sources[nS]->SrcSpatial_p; SrcSpatial_p->q_Pos_p = 31; + } } } - } - if (outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB && inputMc->hReverb == NULL) + if ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB && inputMc->hReverb == NULL ) { - IF((error = ivas_reverb_open_fx(&(inputMc->hReverb), outConfig, NULL, inputMc->tdRendWrapper.hBinRendererTd->HrFiltSet_p->lr_energy_and_iac_fx, hRendCfg, outSampleRate)) != IVAS_ERR_OK) + IF( ( error = ivas_reverb_open_fx( &( inputMc->hReverb ), outConfig, NULL, inputMc->tdRendWrapper.hBinRendererTd->HrFiltSet_p->lr_energy_and_iac_fx, hRendCfg, outSampleRate ) ) != IVAS_ERR_OK ) { return error; } } } - ELSE IF(!useTDRend && inputMc->crendWrapper == NULL) + ELSE IF( !useTDRend && inputMc->crendWrapper == NULL ) { /* open CREND */ - IF((error = ivas_rend_openCrend(&inputMc->crendWrapper, (EQ_16(inConfig, IVAS_AUDIO_CONFIG_LS_CUSTOM)) ? IVAS_AUDIO_CONFIG_7_1_4 : inConfig, outConfig, hRendCfg, NULL, outSampleRate)) != IVAS_ERR_OK) + IF( ( error = ivas_rend_openCrend( &inputMc->crendWrapper, ( EQ_16( inConfig, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) ? IVAS_AUDIO_CONFIG_7_1_4 : inConfig, outConfig, hRendCfg, NULL, outSampleRate ) ) != IVAS_ERR_OK ) { return error; } } /* Initialise the EFAP handle for rotation on input layout */ - IF(NE_16(inConfig, IVAS_AUDIO_CONFIG_LS_CUSTOM) && inputMc->base.ctx.pHeadRotData->headRotEnabled && inputMc->efapInWrapper.hEfap == NULL) + IF( NE_16( inConfig, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && inputMc->base.ctx.pHeadRotData->headRotEnabled && inputMc->efapInWrapper.hEfap == NULL ) { - IF((error = initEfap(&inputMc->efapInWrapper, inConfig, NULL)) != IVAS_ERR_OK) + IF( ( error = initEfap( &inputMc->efapInWrapper, inConfig, NULL ) ) != IVAS_ERR_OK ) { return error; } } /* determine binaural delay ( used for aligning LFE to output signal ) */ - binauralDelayNs = max((inputMc->crendWrapper != NULL) ? inputMc->crendWrapper->binaural_latency_ns : 0, inputMc->tdRendWrapper.binaural_latency_ns); + binauralDelayNs = max( ( inputMc->crendWrapper != NULL ) ? inputMc->crendWrapper->binaural_latency_ns : 0, inputMc->tdRendWrapper.binaural_latency_ns ); Word16 exp = 0; - Word16 var1 = BASOP_Util_Divide3232_Scale(*inputMc->base.ctx.pOutSampleRate, 1000000000, &exp); - Word32 var2 = L_shr_r(Mpy_32_32(binauralDelayNs, L_deposit_h(var1)), -exp);//31 + exp - inputMc->binauralDelaySmp = (Word16)var2; - //inputMc->binauralDelaySmp = (int16_t) roundf( (float) binauralDelayNs * *inputMc->base.ctx.pOutSampleRate / 1000000000.f ); + Word16 var1 = BASOP_Util_Divide3232_Scale( *inputMc->base.ctx.pOutSampleRate, 1000000000, &exp ); + Word32 var2 = L_shr_r( Mpy_32_32( binauralDelayNs, L_deposit_h( var1 ) ), -exp ); // 31 + exp + inputMc->binauralDelaySmp = (Word16) var2; + // inputMc->binauralDelaySmp = (int16_t) roundf( (float) binauralDelayNs * *inputMc->base.ctx.pOutSampleRate / 1000000000.f ); - IF(inputMc->binauralDelaySmp > MAX_BIN_DELAY_SAMPLES) + IF( inputMc->binauralDelaySmp > MAX_BIN_DELAY_SAMPLES ) { - return IVAS_ERROR(IVAS_ERR_WRONG_PARAMS, "Invalid delay for LFE binaural rendering!)"); + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Invalid delay for LFE binaural rendering!)" ); } return IVAS_ERR_OK; - } +} #else static ivas_error initMcBinauralRendering( input_mc *inputMc, @@ -4297,7 +4296,7 @@ static ivas_error initMcMasaRendering( return error; } #ifdef IVAS_FLOAT_FIXED -#if 0 /*Fixed to float conversion for ivas_mcmasa_ana_open (to be removed later)*/ +#if 0 /*Fixed to float conversion for ivas_mcmasa_ana_open (to be removed later)*/ MCMASA_ANA_HANDLE hMcMasa = inputMc->hMcMasa; Word16 i, j; //fixedToFloat_arrL( hMcMasa->ls_azimuth_fx, hMcMasa->ls_azimuth, Q22, MCMASA_MAX_ANA_CHANS ); @@ -4752,7 +4751,7 @@ static ivas_error initSbaPanGainsForMcOut( break; case IVAS_AUDIO_CONFIG_LS_CUSTOM: #ifdef IVAS_FLOAT_FIXED - ivas_ls_custom_setup( &hOutSetup, (LSSETUP_CUSTOM_STRUCT *)outSetupCustom ); + ivas_ls_custom_setup( &hOutSetup, (LSSETUP_CUSTOM_STRUCT *) outSetupCustom ); #else ivas_ls_custom_setup( &hOutSetup, outSetupCustom ); #endif @@ -5253,7 +5252,7 @@ static ivas_error setRendInputActiveMasa( inputMasa->metadataHasBeenFed = false; } -#if 1 /*TODO: To be removed later(fixed to float)*/ +#if 1 /*TODO: To be removed later(fixed to float)*/ IF( inputMasa->hMasaExtRend ) { IF( inputMasa->hMasaExtRend->hDiracDecBin ) @@ -5300,7 +5299,7 @@ ivas_error IVAS_REND_Open( const Word32 outputSampleRate, const AUDIO_CONFIG outConfig, const Word16 nonDiegeticPan, - const Word32 nonDiegeticPanGain,/*Q31*/ + const Word32 nonDiegeticPanGain, /*Q31*/ const Word16 num_subframes ) { Word16 i; @@ -5325,7 +5324,7 @@ ivas_error IVAS_REND_Open( } *phIvasRend = (IVAS_REND_HANDLE) malloc( sizeof( struct IVAS_REND ) ); - IF ( *phIvasRend == NULL ) + IF( *phIvasRend == NULL ) { return IVAS_ERR_FAILED_ALLOC; } @@ -5345,7 +5344,7 @@ ivas_error IVAS_REND_Open( return error; } - IF ( ( error = initLimiter( &hIvasRend->hLimiter, numOutChannels, outputSampleRate ) ) != IVAS_ERR_OK ) + IF( ( error = initLimiter( &hIvasRend->hLimiter, numOutChannels, outputSampleRate ) ) != IVAS_ERR_OK ) { return error; } @@ -5357,24 +5356,24 @@ ivas_error IVAS_REND_Open( } /* Initialize external orientation data */ - IF ( ( error = ivas_external_orientation_open( &( hIvasRend->hExternalOrientationData ), num_subframes ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_external_orientation_open( &( hIvasRend->hExternalOrientationData ), num_subframes ) ) != IVAS_ERR_OK ) { return error; } /* Initilize combined orientation data */ - IF ( ( error = ivas_combined_orientation_open( &( hIvasRend->hCombinedOrientationData ), outputSampleRate, num_subframes ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_combined_orientation_open( &( hIvasRend->hCombinedOrientationData ), outputSampleRate, num_subframes ) ) != IVAS_ERR_OK ) { return error; } /* Initialize EFAP */ - IF ( ( error = initEfap( &hIvasRend->efapOutWrapper, outConfig, &hIvasRend->customLsOut ) ) != IVAS_ERR_OK ) + IF( ( error = initEfap( &hIvasRend->efapOutWrapper, outConfig, &hIvasRend->customLsOut ) ) != IVAS_ERR_OK ) { return error; } /* Initialize inputs */ - FOR ( i = 0; i < RENDERER_MAX_ISM_INPUTS; ++i ) + FOR( i = 0; i < RENDERER_MAX_ISM_INPUTS; ++i ) { initRendInputBase_fx( &hIvasRend->inputsIsm[i].base, IVAS_AUDIO_CONFIG_INVALID, 0, getRendCtx( hIvasRend ), NULL, 0 ); hIvasRend->inputsIsm[i].crendWrapper = NULL; @@ -5389,7 +5388,7 @@ ivas_error IVAS_REND_Open( hIvasRend->inputsIsm[i].bufferData_fx = NULL; } - FOR ( i = 0; i < RENDERER_MAX_MC_INPUTS; ++i ) + FOR( i = 0; i < RENDERER_MAX_MC_INPUTS; ++i ) { initRendInputBase_fx( &hIvasRend->inputsMc[i].base, IVAS_AUDIO_CONFIG_INVALID, 0, getRendCtx( hIvasRend ), NULL, 0 ); @@ -5407,7 +5406,7 @@ ivas_error IVAS_REND_Open( hIvasRend->inputsMc[i].hMcMasa = NULL; } - FOR ( i = 0; i < RENDERER_MAX_SBA_INPUTS; ++i ) + FOR( i = 0; i < RENDERER_MAX_SBA_INPUTS; ++i ) { initRendInputBase_fx( &hIvasRend->inputsSba[i].base, IVAS_AUDIO_CONFIG_INVALID, 0, getRendCtx( hIvasRend ), NULL, 0 ); @@ -5419,7 +5418,7 @@ ivas_error IVAS_REND_Open( hIvasRend->inputsSba[i].hDirAC = NULL; } - FOR ( i = 0; i < RENDERER_MAX_MASA_INPUTS; ++i ) + FOR( i = 0; i < RENDERER_MAX_MASA_INPUTS; ++i ) { initRendInputBase( &hIvasRend->inputsMasa[i].base, IVAS_AUDIO_CONFIG_INVALID, 0, getRendCtx( hIvasRend ), NULL, 0 ); @@ -6394,22 +6393,22 @@ ivas_error IVAS_REND_ConfigureCustomInputLoudspeakerLayout( ivas_error error; /* Validate function arguments */ - IF (hIvasRend == NULL) + IF( hIvasRend == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } - IF((error = validateCustomLsLayout_fx(layout)) != IVAS_ERR_OK) + IF( ( error = validateCustomLsLayout_fx( layout ) ) != IVAS_ERR_OK ) { return error; } - IF ((error = getInputById(hIvasRend, inputId, (void **)&inputMc)) != IVAS_ERR_OK) + IF( ( error = getInputById( hIvasRend, inputId, (void **) &inputMc ) ) != IVAS_ERR_OK ) { return error; } - IF (inputMc->base.inConfig != IVAS_AUDIO_CONFIG_LS_CUSTOM) + IF( inputMc->base.inConfig != IVAS_AUDIO_CONFIG_LS_CUSTOM ) { /* Specifying details of custom speaker layout only makes sense if input config is set to custom speaker layout */ return IVAS_ERR_INVALID_INPUT_FORMAT; @@ -6418,24 +6417,24 @@ ivas_error IVAS_REND_ConfigureCustomInputLoudspeakerLayout( /* Re-initialize panning gains for the MC input, This includes re-initializing LFE handling * for the new input layout, which means custom LFE handling is overwritten, if previously * set for the MC input. */ - inputMc->customLsInput = makeCustomLsSetup(layout); + inputMc->customLsInput = makeCustomLsSetup( layout ); - inputMc->lfeRouting = defaultLfeRouting(inputMc->base.inConfig, inputMc->customLsInput, hIvasRend->outputConfig, *inputMc->base.ctx.pCustomLsOut); + inputMc->lfeRouting = defaultLfeRouting( inputMc->base.inConfig, inputMc->customLsInput, hIvasRend->outputConfig, *inputMc->base.ctx.pCustomLsOut ); - IF ((error = initEfap(&inputMc->efapInWrapper, inputMc->base.inConfig, &inputMc->customLsInput)) != IVAS_ERR_OK) + IF( ( error = initEfap( &inputMc->efapInWrapper, inputMc->base.inConfig, &inputMc->customLsInput ) ) != IVAS_ERR_OK ) { return error; } - IF (EQ_16(hIvasRend->outputConfig , IVAS_AUDIO_CONFIG_BINAURAL) || EQ_16(hIvasRend->outputConfig , IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR) || EQ_16(hIvasRend->outputConfig , IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB)) + IF( EQ_16( hIvasRend->outputConfig, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_16( hIvasRend->outputConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_16( hIvasRend->outputConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { - IF ((error = initMcBinauralRendering(inputMc, inputMc->base.inConfig, hIvasRend->outputConfig, hIvasRend->hRendererConfig, FALSE)) != IVAS_ERR_OK) + IF( ( error = initMcBinauralRendering( inputMc, inputMc->base.inConfig, hIvasRend->outputConfig, hIvasRend->hRendererConfig, FALSE ) ) != IVAS_ERR_OK ) { return error; } } - IF ((error = updateMcPanGains(inputMc, hIvasRend->outputConfig)) != IVAS_ERR_OK) + IF( ( error = updateMcPanGains( inputMc, hIvasRend->outputConfig ) ) != IVAS_ERR_OK ) { return error; } @@ -7281,19 +7280,19 @@ ivas_error IVAS_REND_FeedInputObjectMetadata( #ifdef IVAS_FLOAT_FIXED ivas_error IVAS_REND_FeedInputObjectMetadataToOMasa( IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ - const Word16 inputIndex, /* i : Index of the input */ + const Word16 inputIndex, /* i : Index of the input */ const IVAS_ISM_METADATA objectPosition /* i : object position struct */ ) { /* Validate function arguments */ - IF (hIvasRend == NULL) + IF( hIvasRend == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } /* Set position to OMasa struct */ - hIvasRend->inputsIsm->hOMasa->ism_azimuth_fx[inputIndex] = floatToFixed(objectPosition.azimuth, Q22); - hIvasRend->inputsIsm->hOMasa->ism_elevation_fx[inputIndex] = floatToFixed(objectPosition.elevation, Q22); + hIvasRend->inputsIsm->hOMasa->ism_azimuth_fx[inputIndex] = floatToFixed( objectPosition.azimuth, Q22 ); + hIvasRend->inputsIsm->hOMasa->ism_elevation_fx[inputIndex] = floatToFixed( objectPosition.elevation, Q22 ); return IVAS_ERR_OK; } @@ -7414,9 +7413,9 @@ ivas_error IVAS_REND_InitConfig( ivas_error error; bool rendererConfigEnabled; - rendererConfigEnabled = (getAudioConfigType(outAudioConfig) == IVAS_REND_AUDIO_CONFIG_TYPE_BINAURAL); + rendererConfigEnabled = ( getAudioConfigType( outAudioConfig ) == IVAS_REND_AUDIO_CONFIG_TYPE_BINAURAL ); - IF (rendererConfigEnabled) + IF( rendererConfigEnabled ) { hIvasRend->rendererConfigEnabled = 1; } @@ -7425,30 +7424,28 @@ ivas_error IVAS_REND_InitConfig( hIvasRend->rendererConfigEnabled = 0; } - IF (rendererConfigEnabled) - { - IF ((error = ivas_render_config_open(&(hIvasRend->hRendererConfig))) != IVAS_ERR_OK) - { + IF( rendererConfigEnabled ){ + IF( ( error = ivas_render_config_open( &( hIvasRend->hRendererConfig ) ) ) != IVAS_ERR_OK ){ return error; - } +} #ifdef IVAS_FLOAT_FIXED - IF((error = ivas_render_config_init_from_rom_fx(&hIvasRend->hRendererConfig)) != IVAS_ERR_OK) - { - return error; - } +IF( ( error = ivas_render_config_init_from_rom_fx( &hIvasRend->hRendererConfig ) ) != IVAS_ERR_OK ) +{ + return error; +} #else - IF ((error = ivas_render_config_init_from_rom(&hIvasRend->hRendererConfig)) != IVAS_ERR_OK) - { - return error; - } +IF( ( error = ivas_render_config_init_from_rom( &hIvasRend->hRendererConfig ) ) != IVAS_ERR_OK ) +{ + return error; +} #endif - } - ELSE - { - hIvasRend->hRendererConfig = NULL; - } +} +ELSE +{ + hIvasRend->hRendererConfig = NULL; +} - return IVAS_ERR_OK; +return IVAS_ERR_OK; } #else ivas_error IVAS_REND_InitConfig( @@ -7662,7 +7659,7 @@ ivas_error IVAS_REND_SetHeadRotation( IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ const IVAS_QUATERNION headRot, /* i : head orientations for next rendering call */ const IVAS_VECTOR3 Pos, /* i : listener positions for next rendering call */ - const Word16 sf_idx /* i : subframe index */ + const Word16 sf_idx /* i : subframe index */ ) { Word16 i; @@ -7670,12 +7667,12 @@ ivas_error IVAS_REND_SetHeadRotation( ivas_error error; /* Validate function arguments */ - IF (hIvasRend == NULL) + IF( hIvasRend == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } - IF (getAudioConfigType(hIvasRend->outputConfig) != IVAS_REND_AUDIO_CONFIG_TYPE_BINAURAL) + IF( getAudioConfigType( hIvasRend->outputConfig ) != IVAS_REND_AUDIO_CONFIG_TYPE_BINAURAL ) { /* Head rotation can be set only with binaural output */ return IVAS_ERR_INVALID_OUTPUT_FORMAT; @@ -7684,11 +7681,11 @@ ivas_error IVAS_REND_SetHeadRotation( hIvasRend->headRotData.headRotEnabled = 1; /* reconfigure binaural rendering to allocate the necessary renderers and free unused ones */ - FOR (i = 0; i < RENDERER_MAX_MC_INPUTS; ++i) + FOR( i = 0; i < RENDERER_MAX_MC_INPUTS; ++i ) { - IF (hIvasRend->inputsMc[i].base.inConfig != IVAS_AUDIO_CONFIG_INVALID) + IF( hIvasRend->inputsMc[i].base.inConfig != IVAS_AUDIO_CONFIG_INVALID ) { - IF ((error = initMcBinauralRendering(&hIvasRend->inputsMc[i], hIvasRend->inputsMc[i].base.inConfig, hIvasRend->outputConfig, hIvasRend->hRendererConfig, TRUE)) != IVAS_ERR_OK) + IF( ( error = initMcBinauralRendering( &hIvasRend->inputsMc[i], hIvasRend->inputsMc[i].base.inConfig, hIvasRend->outputConfig, hIvasRend->hRendererConfig, TRUE ) ) != IVAS_ERR_OK ) { return error; } @@ -7696,9 +7693,9 @@ ivas_error IVAS_REND_SetHeadRotation( } /* check for Euler angle signaling */ - IF(EQ_32(headRot.w_fx, -1610612736 /* -3.0f in Q29 */)) + IF( EQ_32( headRot.w_fx, -1610612736 /* -3.0f in Q29 */ ) ) { - Euler2Quat_fx(deg2rad_fx(headRot.x_fx), deg2rad_fx(headRot.y_fx), deg2rad_fx(headRot.z_fx), &rotQuat); + Euler2Quat_fx( deg2rad_fx( headRot.x_fx ), deg2rad_fx( headRot.y_fx ), deg2rad_fx( headRot.z_fx ), &rotQuat ); } ELSE { @@ -7706,24 +7703,24 @@ ivas_error IVAS_REND_SetHeadRotation( } Word32 updateRate_fx = 1677721600; // value is 200 in Q23 - rotQuat.w_fx = L_shl(rotQuat.w_fx, Q29 - rotQuat.q_fact); - rotQuat.x_fx = L_shl(rotQuat.x_fx, Q29 - rotQuat.q_fact); - rotQuat.y_fx = L_shl(rotQuat.y_fx, Q29 - rotQuat.q_fact); - rotQuat.z_fx = L_shl(rotQuat.z_fx, Q29 - rotQuat.q_fact); - hIvasRend->headRotData.hOrientationTracker->refRot.w_fx = L_shl(hIvasRend->headRotData.hOrientationTracker->refRot.w_fx, Q29 - hIvasRend->headRotData.hOrientationTracker->refRot.q_fact); - hIvasRend->headRotData.hOrientationTracker->refRot.x_fx = L_shl(hIvasRend->headRotData.hOrientationTracker->refRot.x_fx, Q29 - hIvasRend->headRotData.hOrientationTracker->refRot.q_fact); - hIvasRend->headRotData.hOrientationTracker->refRot.y_fx = L_shl(hIvasRend->headRotData.hOrientationTracker->refRot.y_fx, Q29 - hIvasRend->headRotData.hOrientationTracker->refRot.q_fact); - hIvasRend->headRotData.hOrientationTracker->refRot.z_fx = L_shl(hIvasRend->headRotData.hOrientationTracker->refRot.z_fx, Q29 - hIvasRend->headRotData.hOrientationTracker->refRot.q_fact); - hIvasRend->headRotData.hOrientationTracker->absAvgRot.w_fx = L_shl(hIvasRend->headRotData.hOrientationTracker->absAvgRot.w_fx, Q29 - hIvasRend->headRotData.hOrientationTracker->absAvgRot.q_fact); - hIvasRend->headRotData.hOrientationTracker->absAvgRot.x_fx = L_shl(hIvasRend->headRotData.hOrientationTracker->absAvgRot.x_fx, Q29 - hIvasRend->headRotData.hOrientationTracker->absAvgRot.q_fact); - hIvasRend->headRotData.hOrientationTracker->absAvgRot.y_fx = L_shl(hIvasRend->headRotData.hOrientationTracker->absAvgRot.y_fx, Q29 - hIvasRend->headRotData.hOrientationTracker->absAvgRot.q_fact); - hIvasRend->headRotData.hOrientationTracker->absAvgRot.z_fx = L_shl(hIvasRend->headRotData.hOrientationTracker->absAvgRot.z_fx, Q29 - hIvasRend->headRotData.hOrientationTracker->absAvgRot.q_fact); + rotQuat.w_fx = L_shl( rotQuat.w_fx, Q29 - rotQuat.q_fact ); + rotQuat.x_fx = L_shl( rotQuat.x_fx, Q29 - rotQuat.q_fact ); + rotQuat.y_fx = L_shl( rotQuat.y_fx, Q29 - rotQuat.q_fact ); + rotQuat.z_fx = L_shl( rotQuat.z_fx, Q29 - rotQuat.q_fact ); + hIvasRend->headRotData.hOrientationTracker->refRot.w_fx = L_shl( hIvasRend->headRotData.hOrientationTracker->refRot.w_fx, Q29 - hIvasRend->headRotData.hOrientationTracker->refRot.q_fact ); + hIvasRend->headRotData.hOrientationTracker->refRot.x_fx = L_shl( hIvasRend->headRotData.hOrientationTracker->refRot.x_fx, Q29 - hIvasRend->headRotData.hOrientationTracker->refRot.q_fact ); + hIvasRend->headRotData.hOrientationTracker->refRot.y_fx = L_shl( hIvasRend->headRotData.hOrientationTracker->refRot.y_fx, Q29 - hIvasRend->headRotData.hOrientationTracker->refRot.q_fact ); + hIvasRend->headRotData.hOrientationTracker->refRot.z_fx = L_shl( hIvasRend->headRotData.hOrientationTracker->refRot.z_fx, Q29 - hIvasRend->headRotData.hOrientationTracker->refRot.q_fact ); + hIvasRend->headRotData.hOrientationTracker->absAvgRot.w_fx = L_shl( hIvasRend->headRotData.hOrientationTracker->absAvgRot.w_fx, Q29 - hIvasRend->headRotData.hOrientationTracker->absAvgRot.q_fact ); + hIvasRend->headRotData.hOrientationTracker->absAvgRot.x_fx = L_shl( hIvasRend->headRotData.hOrientationTracker->absAvgRot.x_fx, Q29 - hIvasRend->headRotData.hOrientationTracker->absAvgRot.q_fact ); + hIvasRend->headRotData.hOrientationTracker->absAvgRot.y_fx = L_shl( hIvasRend->headRotData.hOrientationTracker->absAvgRot.y_fx, Q29 - hIvasRend->headRotData.hOrientationTracker->absAvgRot.q_fact ); + hIvasRend->headRotData.hOrientationTracker->absAvgRot.z_fx = L_shl( hIvasRend->headRotData.hOrientationTracker->absAvgRot.z_fx, Q29 - hIvasRend->headRotData.hOrientationTracker->absAvgRot.q_fact ); hIvasRend->headRotData.hOrientationTracker->refRot.q_fact = Q29; hIvasRend->headRotData.hOrientationTracker->absAvgRot.q_fact = Q29; rotQuat.q_fact = Q29; - IF((error = ivas_orient_trk_Process_fx(hIvasRend->headRotData.hOrientationTracker, rotQuat, updateRate_fx, &hIvasRend->headRotData.headPositions[sf_idx])) != IVAS_ERR_OK) + IF( ( error = ivas_orient_trk_Process_fx( hIvasRend->headRotData.hOrientationTracker, rotQuat, updateRate_fx, &hIvasRend->headRotData.headPositions[sf_idx] ) ) != IVAS_ERR_OK ) { return error; } @@ -7840,7 +7837,7 @@ ivas_error IVAS_REND_DisableHeadRotation( ivas_error error; /* Validate function arguments */ - IF (hIvasRend == NULL) + IF( hIvasRend == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } @@ -7848,13 +7845,13 @@ ivas_error IVAS_REND_DisableHeadRotation( hIvasRend->headRotData.headRotEnabled = 0; /* reconfigure binaural rendering to allocate the necessary renderers and free unused ones */ - IF (getAudioConfigType(hIvasRend->outputConfig) == IVAS_REND_AUDIO_CONFIG_TYPE_BINAURAL) + IF( getAudioConfigType( hIvasRend->outputConfig ) == IVAS_REND_AUDIO_CONFIG_TYPE_BINAURAL ) { - FOR (i = 0; i < RENDERER_MAX_MC_INPUTS; ++i) + FOR( i = 0; i < RENDERER_MAX_MC_INPUTS; ++i ) { - IF (hIvasRend->inputsMc[i].base.inConfig != IVAS_AUDIO_CONFIG_INVALID) + IF( hIvasRend->inputsMc[i].base.inConfig != IVAS_AUDIO_CONFIG_INVALID ) { - IF ((error = initMcBinauralRendering(&hIvasRend->inputsMc[i], hIvasRend->inputsMc[i].base.inConfig, hIvasRend->outputConfig, hIvasRend->hRendererConfig, TRUE)) != IVAS_ERR_OK) + IF( ( error = initMcBinauralRendering( &hIvasRend->inputsMc[i], hIvasRend->inputsMc[i].base.inConfig, hIvasRend->outputConfig, hIvasRend->hRendererConfig, TRUE ) ) != IVAS_ERR_OK ) { return error; @@ -8067,8 +8064,8 @@ ivas_error IVAS_REND_SetReferenceVector( #ifdef IVAS_FLOAT_FIXED ivas_error IVAS_REND_SetExternalOrientation( - IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ - IVAS_QUATERNION *orientation, /* i : external orientation data */ + IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ + IVAS_QUATERNION *orientation, /* i : external orientation data */ Word8 enableHeadRotation, /* i : flag to enable head rotation for this frame */ Word8 enableExternalOrientation, /* i : flag to enable external orientation for this frame */ Word8 enableRotationInterpolation, /* i : flag to interpolate rotations from current and previous frames */ @@ -8077,18 +8074,18 @@ ivas_error IVAS_REND_SetExternalOrientation( ) { /* Validate function arguments */ - IF (hIvasRend == NULL || hIvasRend->hExternalOrientationData == NULL) + IF( hIvasRend == NULL || hIvasRend->hExternalOrientationData == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } - IF (orientation == NULL) + IF( orientation == NULL ) { hIvasRend->hExternalOrientationData->enableExternalOrientation[sf_idx] = 0; } ELSE { - QuaternionInverse_fx(*orientation, &hIvasRend->hExternalOrientationData->Quaternions[sf_idx]); + QuaternionInverse_fx( *orientation, &hIvasRend->hExternalOrientationData->Quaternions[sf_idx] ); hIvasRend->hExternalOrientationData->enableHeadRotation[sf_idx] = enableHeadRotation; hIvasRend->hExternalOrientationData->enableExternalOrientation[sf_idx] = enableExternalOrientation; @@ -8963,31 +8960,31 @@ static ivas_error renderIsmToBinaural( Word16 exp = *outAudio.pq_fact; push_wmops( "renderIsmToBinaural" ); /* Metadata Delay to sync with audio delay converted from ms to 5ms (1000/50/4) subframe index */ - ism_md_subframe_update_ext = div_l(ismInput->ism_metadata_delay_ms_fx, (1000 / FRAMES_PER_SEC / MAX_PARAM_SPATIAL_SUBFRAMES)); + ism_md_subframe_update_ext = div_l( ismInput->ism_metadata_delay_ms_fx, ( 1000 / FRAMES_PER_SEC / MAX_PARAM_SPATIAL_SUBFRAMES ) ); copyBufferTo2dArray_fx( ismInput->base.inputBuffer, tmpTDRendBuffer ); FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) { - Scale_sig32(tmpTDRendBuffer[i], L_FRAME48k, sub(11, exp)); + Scale_sig32( tmpTDRendBuffer[i], L_FRAME48k, sub( 11, exp ) ); } - IF ( ( error = ivas_td_binaural_renderer_ext_fx( &ismInput->tdRendWrapper, ismInput->base.inConfig, NULL, ismInput->base.ctx.pCombinedOrientationData, &ismInput->currentPos, ismInput->hReverb, ism_md_subframe_update_ext, - *ismInput->base.ctx.pOutSampleRate, outAudio.config.numSamplesPerChannel, tmpTDRendBuffer , &exp) ) != IVAS_ERR_OK ) + IF( ( error = ivas_td_binaural_renderer_ext_fx( &ismInput->tdRendWrapper, ismInput->base.inConfig, NULL, ismInput->base.ctx.pCombinedOrientationData, &ismInput->currentPos, ismInput->hReverb, ism_md_subframe_update_ext, + *ismInput->base.ctx.pOutSampleRate, outAudio.config.numSamplesPerChannel, tmpTDRendBuffer, &exp ) ) != IVAS_ERR_OK ) { return error; } FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) { - Scale_sig32(tmpTDRendBuffer[i], L_FRAME48k, -sub(11, exp)); + Scale_sig32( tmpTDRendBuffer[i], L_FRAME48k, -sub( 11, exp ) ); } IF( ismInput->hReverb != NULL ) { - FOR ( i = 0; i < outAudio.config.numChannels; i++ ) + FOR( i = 0; i < outAudio.config.numChannels; i++ ) { - FOR ( Word16 j = 0; j < outAudio.config.numSamplesPerChannel; j++ ) - tmpTDRendBuffer[i][j] = L_shl( tmpTDRendBuffer[i][j], 2 ); + FOR( Word16 j = 0; j < outAudio.config.numSamplesPerChannel; j++ ) + tmpTDRendBuffer[i][j] = L_shl( tmpTDRendBuffer[i][j], 2 ); } } accumulate2dArrayToBuffer_fx( tmpTDRendBuffer, &outAudio ); @@ -9010,12 +9007,12 @@ static ivas_error renderIsmToBinaural( ism_md_subframe_update_ext = (int16_t) roundf( ismInput->ism_metadata_delay_ms / ( 1000 / FRAMES_PER_SEC / MAX_PARAM_SPATIAL_SUBFRAMES ) ); copyBufferTo2dArray( ismInput->base.inputBuffer, tmpTDRendBuffer ); #ifdef IVAS_FLOAT_FIXED - ismInput->currentPos.azimuth_fx = float_to_fix(ismInput->currentPos.azimuth, Q22); - ismInput->currentPos.elevation_fx = float_to_fix(ismInput->currentPos.elevation, Q22); - ismInput->currentPos.spread_fx = float_to_fix(ismInput->currentPos.spread, Q22); - ismInput->currentPos.yaw_fx = float_to_fix(ismInput->currentPos.yaw, Q22); - ismInput->currentPos.pitch_fx = float_to_fix(ismInput->currentPos.pitch, Q22); - ismInput->currentPos.radius_fx = float_to_fix(ismInput->currentPos.radius, Q9); + ismInput->currentPos.azimuth_fx = float_to_fix( ismInput->currentPos.azimuth, Q22 ); + ismInput->currentPos.elevation_fx = float_to_fix( ismInput->currentPos.elevation, Q22 ); + ismInput->currentPos.spread_fx = float_to_fix( ismInput->currentPos.spread, Q22 ); + ismInput->currentPos.yaw_fx = float_to_fix( ismInput->currentPos.yaw, Q22 ); + ismInput->currentPos.pitch_fx = float_to_fix( ismInput->currentPos.pitch, Q22 ); + ismInput->currentPos.radius_fx = float_to_fix( ismInput->currentPos.radius, Q9 ); #endif if ( ( error = ivas_td_binaural_renderer_ext( &ismInput->tdRendWrapper, ismInput->base.inConfig, NULL, ismInput->base.ctx.pCombinedOrientationData, &ismInput->currentPos, ismInput->hReverb, ism_md_subframe_update_ext, *ismInput->base.ctx.pOutSampleRate, outAudio.config.numSamplesPerChannel, tmpTDRendBuffer ) ) != IVAS_ERR_OK ) @@ -9886,7 +9883,7 @@ static ivas_error renderInputIsm( error = IVAS_ERR_OK; inAudio = ismInput->base.inputBuffer; - IF ( NE_32(ismInput->base.numNewSamplesPerChannel , outAudio.config.numSamplesPerChannel) ) + IF( NE_32( ismInput->base.numNewSamplesPerChannel, outAudio.config.numSamplesPerChannel ) ) { return IVAS_ERROR( IVAS_ERR_INVALID_BUFFER_SIZE, "Mismatch between the number of input samples vs number of requested output samples - currently not allowed" ); } @@ -9894,14 +9891,14 @@ static ivas_error renderInputIsm( /* Apply input gain to new audio */ - v_multc_fixed( inAudio.data_fx, ismInput->base.gain_fx, inAudio.data_fx, imult1616(inAudio.config.numSamplesPerChannel , inAudio.config.numChannels) ); + v_multc_fixed( inAudio.data_fx, ismInput->base.gain_fx, inAudio.data_fx, imult1616( inAudio.config.numSamplesPerChannel, inAudio.config.numChannels ) ); *outAudio.pq_fact -= 1; exp = *outAudio.pq_fact; /* set combined orientation subframe info to start info */ ivas_combined_orientation_set_to_start_index( *ismInput->base.ctx.pCombinedOrientationData ); - SWITCH ( getAudioConfigType( outConfig ) ) + SWITCH( getAudioConfigType( outConfig ) ) { case IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED: error = renderIsmToMc( ismInput, outAudio ); @@ -9929,7 +9926,7 @@ static ivas_error renderInputIsm( renderIsmToMasa( ismInput, outAudio, &exp ); FOR( Word16 block_m_idx = 0; block_m_idx < MAX_PARAM_SPATIAL_SUBFRAMES; block_m_idx++ ) { - ismInput->hOMasa->energy_e[block_m_idx]= 31- ismInput->hOMasa->energy_q; + ismInput->hOMasa->energy_e[block_m_idx] = 31 - ismInput->hOMasa->energy_q; } BREAK; default: @@ -9937,7 +9934,7 @@ static ivas_error renderInputIsm( } /* Check error here to keep switch statement more compact */ - IF ( error != IVAS_ERR_OK ) + IF( error != IVAS_ERR_OK ) { return error; } @@ -10101,7 +10098,7 @@ static ivas_error renderActiveInputsIsm( Word16 input_q = Q8; for ( i = 0, pCurrentInput = hIvasRend->inputsIsm; i < RENDERER_MAX_ISM_INPUTS; ++i, ++pCurrentInput ) { - IF ( pCurrentInput->base.inConfig == IVAS_AUDIO_CONFIG_INVALID ) + IF( pCurrentInput->base.inConfig == IVAS_AUDIO_CONFIG_INVALID ) { /* Skip inactive inputs */ continue; @@ -10112,13 +10109,13 @@ static ivas_error renderActiveInputsIsm( { return error; } - FOR(Word16 j = 0; j < outAudio.config.numSamplesPerChannel * outAudio.config.numChannels; ++j ) + FOR( Word16 j = 0; j < outAudio.config.numSamplesPerChannel * outAudio.config.numChannels; ++j ) { - outAudio.data_fx[j] = L_shl( outAudio.data_fx[j], sub( sub(input_q,1) , ( *outAudio.pq_fact ) ) ); + outAudio.data_fx[j] = L_shl( outAudio.data_fx[j], sub( sub( input_q, 1 ), ( *outAudio.pq_fact ) ) ); } - *outAudio.pq_fact = sub(input_q,1); + *outAudio.pq_fact = sub( input_q, 1 ); } -#if 0/*To be removed later when dependency on data is removed*/ +#if 0 /*To be removed later when dependency on data is removed*/ FOR( Word16 j = 0; j < outAudio.config.numSamplesPerChannel * outAudio.config.numChannels; ++j ) { outAudio.data[j] = fixedToFloat( outAudio.data_fx[j], input_q - 1 ); @@ -10341,7 +10338,7 @@ static ivas_error renderMcToBinaural( FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) { - Scale_sig32(tmpRendBuffer_fx[i], L_FRAME48k, sub(11, exp)); + Scale_sig32( tmpRendBuffer_fx[i], L_FRAME48k, sub( 11, exp ) ); } IF( ( error = ivas_td_binaural_renderer_ext_fx( &mcInput->tdRendWrapper, mcInput->base.inConfig, &mcInput->customLsInput, mcInput->base.ctx.pCombinedOrientationData, NULL, mcInput->hReverb, 0, *mcInput->base.ctx.pOutSampleRate, mcInput->base.inputBuffer.config.numSamplesPerChannel, tmpRendBuffer_fx, &exp ) ) != IVAS_ERR_OK ) @@ -10351,7 +10348,7 @@ static ivas_error renderMcToBinaural( FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) { - Scale_sig32(tmpRendBuffer_fx[i], L_FRAME48k, -sub(11, exp)); + Scale_sig32( tmpRendBuffer_fx[i], L_FRAME48k, -sub( 11, exp ) ); } } ELSE @@ -10546,7 +10543,7 @@ static ivas_error renderMcToBinauralRoom( FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) { - Scale_sig32(tmpRendBuffer[i], L_FRAME48k, sub(11, exp)); + Scale_sig32( tmpRendBuffer[i], L_FRAME48k, sub( 11, exp ) ); } IF( ( error = ivas_td_binaural_renderer_ext_fx( &mcInput->tdRendWrapper, mcInput->base.inConfig, &mcInput->customLsInput, mcInput->base.ctx.pCombinedOrientationData, NULL, mcInput->hReverb, @@ -10557,7 +10554,7 @@ static ivas_error renderMcToBinauralRoom( FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) { - Scale_sig32(tmpRendBuffer[i], L_FRAME48k, -sub(11, exp)); + Scale_sig32( tmpRendBuffer[i], L_FRAME48k, -sub( 11, exp ) ); } //*outAudio.pq_fact = exp; } @@ -11154,7 +11151,7 @@ static ivas_error renderActiveInputsMc( CONTINUE; } - *outAudio.pq_fact = Q8; + *outAudio.pq_fact = Q8; IF( ( error = renderInputMc( pCurrentInput, hIvasRend->outputConfig, outAudio ) ) != IVAS_ERR_OK ) { return error; @@ -11973,7 +11970,7 @@ static void renderMasaToMasa( scale_sig32( Chan_ImagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, scale_factor ); // Q17 } - Word16 q_add = sub(31 , add( scale_factor , q_cldfb_out )); + Word16 q_add = sub( 31, add( scale_factor, q_cldfb_out ) ); /* Compute channel energy for metadata processing */ FOR( band_m_idx = 0; band_m_idx < MASA_FREQUENCY_BANDS; band_m_idx++ ) { @@ -12042,7 +12039,7 @@ static void renderMasaToMasa( } ratioSum_fx = L_add( ratioSum_fx, inMeta->common_meta.diffuse_to_total_ratio_fx[sf][band] ); - IF( EQ_32(ratioSum_fx , 0 )) + IF( EQ_32( ratioSum_fx, 0 ) ) { FOR( dir = 0; dir < numDirs; dir++ ) { @@ -12050,7 +12047,7 @@ static void renderMasaToMasa( } inMeta->common_meta.diffuse_to_total_ratio_fx[sf][band] = ONE_IN_Q30; } - ELSE IF( NE_32(ratioSum_fx , ONE_IN_Q30) ) + ELSE IF( NE_32( ratioSum_fx, ONE_IN_Q30 ) ) { Word16 tmp_e = 0; move16(); @@ -12302,22 +12299,22 @@ static ivas_error renderInputMasa( copyMasaMetadataToDiracRenderer( &masaInput->masaMetadata, masaInput->hMasaExtRend->hSpatParamRendCom, maxBin ); #endif #ifdef IVAS_FLOAT_FIXED -#if 1 //TOBE REMOVED - intermidiate_ext_dirac_render(masaInput->hMasaExtRend, tmpBuffer_fx, tmpBuffer, 1); +#if 1 // TOBE REMOVED + intermidiate_ext_dirac_render( masaInput->hMasaExtRend, tmpBuffer_fx, tmpBuffer, 1 ); #endif - FOR ( ch = 0; ch < masaInput->hMasaExtRend->hDirACRend->hOutSetup.nchan_out_woLFE + masaInput->hMasaExtRend->hDirACRend->hOutSetup.num_lfe; ch++ ) + FOR( ch = 0; ch < masaInput->hMasaExtRend->hDirACRend->hOutSetup.nchan_out_woLFE + masaInput->hMasaExtRend->hDirACRend->hOutSetup.num_lfe; ch++ ) { masaInput->hMasaExtRend->cldfbAnaRend[0]->Q_cldfb_state = Q11; } ivas_masa_ext_dirac_render_fx( masaInput->hMasaExtRend, tmpBuffer_fx, num_subframes ); - FOR ( ch = 0; ch < masaInput->hMasaExtRend->hDirACRend->hOutSetup.nchan_out_woLFE + masaInput->hMasaExtRend->hDirACRend->hOutSetup.num_lfe; ch++ ) + FOR( ch = 0; ch < masaInput->hMasaExtRend->hDirACRend->hOutSetup.nchan_out_woLFE + masaInput->hMasaExtRend->hDirACRend->hOutSetup.num_lfe; ch++ ) { - scale_sig32(masaInput->hMasaExtRend->cldfbSynRend[ch]->cldfb_state_fx, masaInput->hMasaExtRend->cldfbSynRend[ch]->cldfb_size, sub(Q11, masaInput->hMasaExtRend->cldfbAnaRend[0]->Q_cldfb_state)); + scale_sig32( masaInput->hMasaExtRend->cldfbSynRend[ch]->cldfb_state_fx, masaInput->hMasaExtRend->cldfbSynRend[ch]->cldfb_size, sub( Q11, masaInput->hMasaExtRend->cldfbAnaRend[0]->Q_cldfb_state ) ); masaInput->hMasaExtRend->cldfbAnaRend[0]->Q_cldfb_state = Q11; } -#if 1 //TOBE REMOVED - intermidiate_ext_dirac_render(masaInput->hMasaExtRend, tmpBuffer_fx, tmpBuffer, 0); +#if 1 // TOBE REMOVED + intermidiate_ext_dirac_render( masaInput->hMasaExtRend, tmpBuffer_fx, tmpBuffer, 0 ); #endif #else ivas_masa_ext_dirac_render( masaInput->hMasaExtRend, tmpBuffer, num_subframes ); @@ -12775,16 +12772,16 @@ ivas_error IVAS_REND_SetTotalNumberOfObjects( #ifdef IVAS_FLOAT_FIXED ivas_error IVAS_REND_SetIsmMetadataDelay( IVAS_REND_HANDLE hIvasRend, /* i/o: IVAS renderer handle */ - const Word32 sync_md_delay /* i : ISM Metadata Delay in ms to sync with audio delay */ + const Word32 sync_md_delay /* i : ISM Metadata Delay in ms to sync with audio delay */ ) { Word16 i; - IF(hIvasRend == NULL) + IF( hIvasRend == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } - FOR(i = 0; i < RENDERER_MAX_ISM_INPUTS; ++i) + FOR( i = 0; i < RENDERER_MAX_ISM_INPUTS; ++i ) { hIvasRend->inputsIsm[i].ism_metadata_delay_ms_fx = sync_md_delay; } @@ -12933,18 +12930,18 @@ static ivas_error getSamplesInternal( *outAudio.pq_fact = 0; #endif }*/ - IF( NE_32( hIvasRend->inputsSba[0].base.inConfig, IVAS_AUDIO_CONFIG_INVALID ) || NE_32( hIvasRend->inputsMc[0].base.inConfig, IVAS_AUDIO_CONFIG_INVALID )|| NE_32( hIvasRend->inputsIsm[0].base.inConfig, IVAS_AUDIO_CONFIG_INVALID )) - { - Word32 limiter_thresold = L_lshl( IVAS_LIMITER_THRESHOLD, *outAudio.pq_fact ); - limitRendererOutput_fx( hIvasRend->hLimiter, outAudio.data_fx, outAudio.config.numSamplesPerChannel, limiter_thresold, *outAudio.pq_fact ); - } - ELSE - { - floatToFixed_arrL(outAudio.data, outAudio.data_fx, *outAudio.pq_fact, hIvasRend->hLimiter->num_channels * outAudio.config.numSamplesPerChannel); - Word32 limiter_thresold = L_lshl( IVAS_LIMITER_THRESHOLD, *outAudio.pq_fact ); - limitRendererOutput_fx( hIvasRend->hLimiter, outAudio.data_fx, outAudio.config.numSamplesPerChannel, limiter_thresold, *outAudio.pq_fact ); - fixedToFloat_arrL(outAudio.data_fx, outAudio.data, *outAudio.pq_fact, hIvasRend->hLimiter->num_channels * outAudio.config.numSamplesPerChannel); - } + IF( NE_32( hIvasRend->inputsSba[0].base.inConfig, IVAS_AUDIO_CONFIG_INVALID ) || NE_32( hIvasRend->inputsMc[0].base.inConfig, IVAS_AUDIO_CONFIG_INVALID ) || NE_32( hIvasRend->inputsIsm[0].base.inConfig, IVAS_AUDIO_CONFIG_INVALID ) ) + { + Word32 limiter_thresold = L_lshl( IVAS_LIMITER_THRESHOLD, *outAudio.pq_fact ); + limitRendererOutput_fx( hIvasRend->hLimiter, outAudio.data_fx, outAudio.config.numSamplesPerChannel, limiter_thresold, *outAudio.pq_fact ); + } + ELSE + { + floatToFixed_arrL( outAudio.data, outAudio.data_fx, *outAudio.pq_fact, hIvasRend->hLimiter->num_channels * outAudio.config.numSamplesPerChannel ); + Word32 limiter_thresold = L_lshl( IVAS_LIMITER_THRESHOLD, *outAudio.pq_fact ); + limitRendererOutput_fx( hIvasRend->hLimiter, outAudio.data_fx, outAudio.config.numSamplesPerChannel, limiter_thresold, *outAudio.pq_fact ); + fixedToFloat_arrL( outAudio.data_fx, outAudio.data, *outAudio.pq_fact, hIvasRend->hLimiter->num_channels * outAudio.config.numSamplesPerChannel ); + } /* update global cominbed orientation start index */ ivas_combined_orientation_update_start_index( hIvasRend->hCombinedOrientationData, outAudio.config.numSamplesPerChannel ); @@ -13881,7 +13878,7 @@ static ivas_error ivas_masa_ext_rend_dirac_rend_init( else { #ifdef IVAS_FLOAT_FIXED - IF ( ( hDirACRend->proto_frame_f_fx = (Word32 *) malloc( sizeof( Word32 ) * 2 * hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands ) ) == NULL ) + IF( ( hDirACRend->proto_frame_f_fx = (Word32 *) malloc( sizeof( Word32 ) * 2 * hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } @@ -14122,7 +14119,7 @@ static ivas_error ivas_masa_ext_rend_parambin_init( { FOR( k = 0; k < BINAURAL_CHANNELS + MAX_NUM_OBJECTS; k++ ) { -#if 1 /*To be removed later(floating buffer init)*/ +#if 1 /*To be removed later(floating buffer init)*/ set_zero( hDiracDecBin->processMtxRe[j][k], nBins ); set_zero( hDiracDecBin->processMtxIm[j][k], nBins ); #endif @@ -14132,21 +14129,21 @@ static ivas_error ivas_masa_ext_rend_parambin_init( FOR( k = 0; k < BINAURAL_CHANNELS; k++ ) { -#if 1 /*To be removed later(floating buffer init)*/ +#if 1 /*To be removed later(floating buffer init)*/ set_zero( hDiracDecBin->processMtxDecRe[j][k], nBins ); set_zero( hDiracDecBin->processMtxDecIm[j][k], nBins ); #endif set16_fx( hDiracDecBin->processMtxDecRe_fx[j][k], 0, nBins ); set16_fx( hDiracDecBin->processMtxDecIm_fx[j][k], 0, nBins ); } -#if 1 /*TODO:To be removed later(floating buffer init)*/ +#if 1 /*TODO:To be removed later(floating buffer init)*/ set_zero( hDiracDecBin->ChEnePrev[j], nBins ); set_zero( hDiracDecBin->ChEneOutPrev[j], nBins ); #endif set_zero_fx( hDiracDecBin->ChEnePrev_fx[j], nBins ); set_zero_fx( hDiracDecBin->ChEneOutPrev_fx[j], nBins ); } -#if 1 /*TODO:To be removed later(floating buffer init)*/ +#if 1 /*TODO:To be removed later(floating buffer init)*/ set_zero( hDiracDecBin->ChCrossRePrev, nBins ); set_zero( hDiracDecBin->ChCrossImPrev, nBins ); set_zero( hDiracDecBin->ChCrossReOutPrev, nBins ); @@ -14175,7 +14172,7 @@ static ivas_error ivas_masa_ext_rend_parambin_init( } /* No SPAR in external renderer so set directive diffuse field coherence tables to zero */ -#if 1 /*TODO: To be removed later(floating buffer init)*/ +#if 1 /*TODO: To be removed later(floating buffer init)*/ set_zero( hDiracDecBin->diffuseFieldCoherenceX, BINAURAL_COHERENCE_DIFFERENCE_BINS ); set_zero( hDiracDecBin->diffuseFieldCoherenceY, BINAURAL_COHERENCE_DIFFERENCE_BINS ); set_zero( hDiracDecBin->diffuseFieldCoherenceZ, BINAURAL_COHERENCE_DIFFERENCE_BINS ); @@ -14568,70 +14565,70 @@ static ivas_error initMasaExtRenderer( #ifdef IVAS_FLOAT_FIXED static void freeMasaExtRenderer( - MASA_EXT_REND_HANDLE *hMasaExtRendOut) + MASA_EXT_REND_HANDLE *hMasaExtRendOut ) { MASA_EXT_REND_HANDLE hMasaExtRend; Word16 i; - IF(hMasaExtRendOut == NULL || *hMasaExtRendOut == NULL) + IF( hMasaExtRendOut == NULL || *hMasaExtRendOut == NULL ) { return; } hMasaExtRend = *hMasaExtRendOut; - IF(hMasaExtRend->hDirACRend != NULL) + IF( hMasaExtRend->hDirACRend != NULL ) { - ivas_dirac_rend_close_fx(&hMasaExtRend->hDirACRend); + ivas_dirac_rend_close_fx( &hMasaExtRend->hDirACRend ); } - IF(hMasaExtRend->hSpatParamRendCom != NULL) + IF( hMasaExtRend->hSpatParamRendCom != NULL ) { - ivas_spat_hSpatParamRendCom_close_fx(&hMasaExtRend->hSpatParamRendCom); + ivas_spat_hSpatParamRendCom_close_fx( &hMasaExtRend->hSpatParamRendCom ); } - IF(hMasaExtRend->hDiracDecBin != NULL) + IF( hMasaExtRend->hDiracDecBin != NULL ) { - ivas_dirac_dec_close_binaural_data(&hMasaExtRend->hDiracDecBin); + ivas_dirac_dec_close_binaural_data( &hMasaExtRend->hDiracDecBin ); } - IF (hMasaExtRend->hReverb != NULL) + IF( hMasaExtRend->hReverb != NULL ) { - ivas_binaural_reverb_close_fx(&hMasaExtRend->hReverb); + ivas_binaural_reverb_close_fx( &hMasaExtRend->hReverb ); } - IF(hMasaExtRend->hHrtfParambin != NULL) + IF( hMasaExtRend->hHrtfParambin != NULL ) { - ivas_HRTF_parambin_binary_close_fx(&hMasaExtRend->hHrtfParambin); + ivas_HRTF_parambin_binary_close_fx( &hMasaExtRend->hHrtfParambin ); } - IF(hMasaExtRend->hVBAPdata != NULL) + IF( hMasaExtRend->hVBAPdata != NULL ) { - vbap_free_data_fx(&hMasaExtRend->hVBAPdata); + vbap_free_data_fx( &hMasaExtRend->hVBAPdata ); } - IF(hMasaExtRend->hoa_dec_mtx != NULL) + IF( hMasaExtRend->hoa_dec_mtx != NULL ) { - free(hMasaExtRend->hoa_dec_mtx); + free( hMasaExtRend->hoa_dec_mtx ); } - FOR(i = 0; i < MASA_MAX_TRANSPORT_CHANNELS; i++) + FOR( i = 0; i < MASA_MAX_TRANSPORT_CHANNELS; i++ ) { - IF(hMasaExtRend->cldfbAnaRend[i] != NULL) + IF( hMasaExtRend->cldfbAnaRend[i] != NULL ) { - deleteCldfb_ivas(&hMasaExtRend->cldfbAnaRend[i]); + deleteCldfb_ivas( &hMasaExtRend->cldfbAnaRend[i] ); } } - FOR(i = 0; i < MAX_OUTPUT_CHANNELS; i++) + FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) { - IF(hMasaExtRend->cldfbSynRend[i] != NULL) + IF( hMasaExtRend->cldfbSynRend[i] != NULL ) { - deleteCldfb_ivas(&hMasaExtRend->cldfbSynRend[i]); - } + deleteCldfb_ivas( &hMasaExtRend->cldfbSynRend[i] ); + } } - free(hMasaExtRend); + free( hMasaExtRend ); *hMasaExtRendOut = NULL; return; @@ -14734,10 +14731,9 @@ static void freeMasaExtRenderer( #ifdef IVAS_FLOAT_FIXED static void intermidiate_ext_dirac_render( MASA_EXT_REND_HANDLE hMasaExtRend, /* i/o: MASA renderer structure */ - Word32 *output_f[], /* i/o: input/output signals in time domain */ - float *output_f_flt[], /* i/o: input/output signals in time domain */ - Word16 to_fix -) + Word32 *output_f[], /* i/o: input/output signals in time domain */ + float *output_f_flt[], /* i/o: input/output signals in time domain */ + Word16 to_fix ) { SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; hSpatParamRendCom = hMasaExtRend->hSpatParamRendCom; @@ -14753,146 +14749,154 @@ static void intermidiate_ext_dirac_render( hSpatParamRendCom = hMasaExtRend->hSpatParamRendCom; nchan_transport = hMasaExtRend->nchan_input; DIRAC_OUTPUT_SYNTHESIS_STATE *h_dirac_output_synthesis_state; - + h_dirac_output_synthesis_state = &( hDirACRend->h_output_synthesis_psd_state ); subframe_idx = hSpatParamRendCom->subframes_rendered; DirAC_mem = hDirACRend->stack_mem; - if(to_fix) + if ( to_fix ) { DirAC_mem.reference_power_smooth_q = DirAC_mem.reference_power_q = Q31; q_cldfb = 11; - for(i = 0; i < MAX_OUTPUT_CHANNELS; i++) + for ( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) { - floatToFixed_arrL(output_f_flt[i], output_f[i], q_cldfb, L_FRAME48k); + floatToFixed_arrL( output_f_flt[i], output_f[i], q_cldfb, L_FRAME48k ); } - for(slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++){ - IF( EQ_16( hDirACRend->panningConf, DIRAC_PANNING_VBAP ) ) + for ( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) { - hDirACRend->h_output_synthesis_psd_state.direct_responses_q = 30; - floatToFixed_arrL32( hDirACRend->h_output_synthesis_psd_state.direct_responses, hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, hDirACRend->h_output_synthesis_psd_state.direct_responses_q, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); - } - else - { - if(hDirACRend->panningConf == DIRAC_PANNING_HOA3) + IF( EQ_16( hDirACRend->panningConf, DIRAC_PANNING_VBAP ) ) { - if (masa_band_mapping == NULL && hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD) - { hDirACRend->h_output_synthesis_psd_state.direct_responses_q = 30; floatToFixed_arrL32( hDirACRend->h_output_synthesis_psd_state.direct_responses, hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, hDirACRend->h_output_synthesis_psd_state.direct_responses_q, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); - } - else if (((hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD) && (masa_band_mapping != NULL)) || - hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD || hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO) - { - hDirACRend->h_output_synthesis_psd_state.direct_responses_q = 30; - floatToFixed_arrL32( hDirACRend->h_output_synthesis_psd_state.direct_responses, hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, hDirACRend->h_output_synthesis_psd_state.direct_responses_q, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); - } - ELSE IF( EQ_16( hDirACRend->panningConf, DIRAC_PANNING_VBAP ) ) /*VBAP*/ - { - hDirACRend->h_output_synthesis_psd_state.direct_responses_q = 30; - floatToFixed_arrL32( hDirACRend->h_output_synthesis_psd_state.direct_responses, hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, hDirACRend->h_output_synthesis_psd_state.direct_responses_q, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); - } - } - else if (hDirACRend->panningConf == DIRAC_PANNING_VBAP) /*VBAP*/ + else { - hDirACRend->h_output_synthesis_psd_state.direct_responses_q = 30; - floatToFixed_arrL32( hDirACRend->h_output_synthesis_psd_state.direct_responses, hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, hDirACRend->h_output_synthesis_psd_state.direct_responses_q, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); + if ( hDirACRend->panningConf == DIRAC_PANNING_HOA3 ) + { + if ( masa_band_mapping == NULL && hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) + { + hDirACRend->h_output_synthesis_psd_state.direct_responses_q = 30; + floatToFixed_arrL32( hDirACRend->h_output_synthesis_psd_state.direct_responses, hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, hDirACRend->h_output_synthesis_psd_state.direct_responses_q, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); + } + else if ( ( ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) && ( masa_band_mapping != NULL ) ) || + hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD || hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO ) + { + hDirACRend->h_output_synthesis_psd_state.direct_responses_q = 30; + floatToFixed_arrL32( hDirACRend->h_output_synthesis_psd_state.direct_responses, hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, hDirACRend->h_output_synthesis_psd_state.direct_responses_q, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); + } + ELSE IF( EQ_16( hDirACRend->panningConf, DIRAC_PANNING_VBAP ) ) /*VBAP*/ + { + hDirACRend->h_output_synthesis_psd_state.direct_responses_q = 30; + floatToFixed_arrL32( hDirACRend->h_output_synthesis_psd_state.direct_responses, hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, hDirACRend->h_output_synthesis_psd_state.direct_responses_q, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); + } + } + else if ( hDirACRend->panningConf == DIRAC_PANNING_VBAP ) /*VBAP*/ + { + hDirACRend->h_output_synthesis_psd_state.direct_responses_q = 30; + floatToFixed_arrL32( hDirACRend->h_output_synthesis_psd_state.direct_responses, hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, hDirACRend->h_output_synthesis_psd_state.direct_responses_q, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); + } } } + + if ( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth ) + { + hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth = L_get_q_buf1( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_len ); + floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_len ); } - - if(hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth){ - hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth = L_get_q_buf1(hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_len); - floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_len ); - } - - if(hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev){ - hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev = L_get_q_buf1(hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_len);; - floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_len ); + + if ( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev ) + { + hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev = L_get_q_buf1( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_len ); + ; + floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_len ); } - if(hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth){ - hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth = L_get_q_buf1( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth, hDirACRend->num_outputs_dir * hSpatParamRendCom->num_freq_bands ); - floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_len ); + if ( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth ) + { + hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth = L_get_q_buf1( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth, hDirACRend->num_outputs_dir * hSpatParamRendCom->num_freq_bands ); + floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_len ); } Word16 num_channels_dir = hDirACRend->num_outputs_dir; - + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS ) { num_channels_dir = hDirACRend->hOutSetup.nchan_out_woLFE; } - if(h_dirac_output_synthesis_state->cy_auto_diff_smooth){ - h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = L_get_q_buf( h_dirac_output_synthesis_state->cy_auto_diff_smooth, num_channels_dir * hSpatParamRendCom->num_freq_bands ); - floatToFixed_arrL( h_dirac_output_synthesis_state->cy_auto_diff_smooth, h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_len ); + if ( h_dirac_output_synthesis_state->cy_auto_diff_smooth ) + { + h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = L_get_q_buf( h_dirac_output_synthesis_state->cy_auto_diff_smooth, num_channels_dir * hSpatParamRendCom->num_freq_bands ); + floatToFixed_arrL( h_dirac_output_synthesis_state->cy_auto_diff_smooth, h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_len ); } - - if(hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev){ - hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev = L_get_q_buf1(hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_len);; - floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_len ); + + if ( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev ) + { + hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev = L_get_q_buf1( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_len ); + ; + floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_len ); } - + hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q = Q26; hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q = Q26; floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_len ); floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_len ); - if(hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev){ - hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev = L_get_q_buf1( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir ); - floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_len ); + if ( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev ) + { + hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev = L_get_q_buf1( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir ); + floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_len ); } - + floatToFixed_arrL32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_len ); if ( hDirACRend->proto_signal_decorr_on == 1 ) { - Word16 tmp_e; - f2me_buf(hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer, hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer_fx, &tmp_e, hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer_len ); - hDirACRend->h_freq_domain_decorr_ap_state->q_decorr_buffer = 31 - tmp_e; + Word16 tmp_e; + f2me_buf( hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer, hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer_fx, &tmp_e, hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer_len ); + hDirACRend->h_freq_domain_decorr_ap_state->q_decorr_buffer = 31 - tmp_e; } - - f2me_buf(hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx, &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len); + + f2me_buf( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx, &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len ); hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q = 31 - hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q; - FOR ( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) + FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) { /* CLDFB Analysis*/ - FOR ( ch = 0; ch < nchan_transport; ch++ ) + FOR( ch = 0; ch < nchan_transport; ch++ ) { - hMasaExtRend->cldfbAnaRend[ch]->Q_cldfb_state = Q11; + hMasaExtRend->cldfbAnaRend[ch]->Q_cldfb_state = Q11; } } - if(DirAC_mem.frame_dec_f) + if ( DirAC_mem.frame_dec_f ) { - //f2me_buf(DirAC_mem.frame_dec_f, DirAC_mem.frame_dec_f_fx, &hDirACRend->proto_frame_dec_f_q, DirAC_mem.frame_dec_f_len); + // f2me_buf(DirAC_mem.frame_dec_f, DirAC_mem.frame_dec_f_fx, &hDirACRend->proto_frame_dec_f_q, DirAC_mem.frame_dec_f_len); } hDirACRend->proto_frame_dec_f_q = 31 - hDirACRend->proto_frame_dec_f_q; - if(hDirACRend->h_output_synthesis_psd_state.proto_power_smooth){ + if ( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth ) + { hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q = L_get_q_buf1( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth, hDirACRend->num_protos_dir * hSpatParamRendCom->num_freq_bands ); hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q = L_get_q_buf1( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev, hDirACRend->num_protos_dir * hSpatParamRendCom->num_freq_bands ); floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_len ); floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_len ); } - + hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q = L_get_q_buf1( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_len ); floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_len ); - - if( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev != 0 ) + + if ( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev != 0 ) { hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q = L_get_q_buf1( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_len ); floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_len ); } - } else { FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ ) { hDirACRend->h_output_synthesis_psd_state.direct_power_factor[i] = fix_to_float( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i], hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q ); - hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor[i] = fix_to_float( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx[i], hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q); + hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor[i] = fix_to_float( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx[i], hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q ); } - IF(EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) + IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { - fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, hDirACRend->h_output_synthesis_psd_state.direct_responses, hDirACRend->h_output_synthesis_psd_state.direct_responses_q, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); + fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, hDirACRend->h_output_synthesis_psd_state.direct_responses, hDirACRend->h_output_synthesis_psd_state.direct_responses_q, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); } ELSE { @@ -14902,80 +14906,89 @@ static void intermidiate_ext_dirac_render( fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.direct_responses_square_fx, hDirACRend->h_output_synthesis_psd_state.direct_responses_square, hDirACRend->h_output_synthesis_psd_state.direct_responses_square_q, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); } } - - if(DirAC_mem.reference_power) + + if ( DirAC_mem.reference_power ) { - fixedToFloat_arrL(DirAC_mem.reference_power_fx, DirAC_mem.reference_power, DirAC_mem.reference_power_q, DirAC_mem.reference_power_len ); + fixedToFloat_arrL( DirAC_mem.reference_power_fx, DirAC_mem.reference_power, DirAC_mem.reference_power_q, DirAC_mem.reference_power_len ); } - if(hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev){ - fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_len ); + if ( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev ) + { + fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_len ); } - if(hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth){ - fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_len); + if ( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth ) + { + fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_len ); } - if(hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev){ - fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_len ); + if ( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev ) + { + fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_len ); } - if(hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth){ - fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_len ); + if ( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth ) + { + fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_len ); } - if(hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth){ - fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_len ); + if ( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth ) + { + fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_len ); } - if(hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev){ - fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_len ); + if ( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev ) + { + fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_len ); } - if(hDirACRend->h_output_synthesis_psd_state.gains_dir_prev){ - fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_len ); + if ( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev ) + { + fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_len ); } - if(hDirACRend->h_output_synthesis_psd_state.gains_diff_prev){ - fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_len ); + if ( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev ) + { + fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_len ); } - if(hDirACRend->h_output_synthesis_psd_state.proto_power_smooth){ - fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_len ); + if ( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth ) + { + fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_len ); } - fixedToFloat_arrL32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len); + fixedToFloat_arrL32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len ); if ( hDirACRend->proto_signal_decorr_on == 1 ) { - fixedToFloat_arrL32(hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer_fx, hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer, hDirACRend->h_freq_domain_decorr_ap_state->q_decorr_buffer, hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer_len); + fixedToFloat_arrL32( hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer_fx, hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer, hDirACRend->h_freq_domain_decorr_ap_state->q_decorr_buffer, hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer_len ); if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { - fixedToFloat_arrL(hDirACRend->h_freq_domain_decorr_ap_state->direct_energy_smooth_fx, hDirACRend->h_freq_domain_decorr_ap_state->direct_energy_smooth, hDirACRend->h_freq_domain_decorr_ap_state->q_direct_energy_smooth, hDirACRend->num_protos_diff * hDirACRend->h_freq_domain_decorr_ap_params->max_band_decorr); - fixedToFloat_arrL(hDirACRend->h_freq_domain_decorr_ap_state->reverb_energy_smooth_fx, hDirACRend->h_freq_domain_decorr_ap_state->reverb_energy_smooth, hDirACRend->h_freq_domain_decorr_ap_state->q_reverb_energy_smooth, hDirACRend->num_protos_diff * hDirACRend->h_freq_domain_decorr_ap_params->max_band_decorr); + fixedToFloat_arrL( hDirACRend->h_freq_domain_decorr_ap_state->direct_energy_smooth_fx, hDirACRend->h_freq_domain_decorr_ap_state->direct_energy_smooth, hDirACRend->h_freq_domain_decorr_ap_state->q_direct_energy_smooth, hDirACRend->num_protos_diff * hDirACRend->h_freq_domain_decorr_ap_params->max_band_decorr ); + fixedToFloat_arrL( hDirACRend->h_freq_domain_decorr_ap_state->reverb_energy_smooth_fx, hDirACRend->h_freq_domain_decorr_ap_state->reverb_energy_smooth, hDirACRend->h_freq_domain_decorr_ap_state->q_reverb_energy_smooth, hDirACRend->num_protos_diff * hDirACRend->h_freq_domain_decorr_ap_params->max_band_decorr ); } } - fixedToFloat_arrL32( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len); + fixedToFloat_arrL32( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len ); fixedToFloat_arrL32( hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f, hDirACRend->proto_frame_f_q, hDirACRend->proto_frame_f_len ); - //fixedToFloat_arrL32(DirAC_mem.frame_dec_f_fx, DirAC_mem.frame_dec_f, DirAC_mem.frame_dec_f_q, DirAC_mem.frame_dec_f_len); - - FOR ( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[hSpatParamRendCom->subframes_rendered]; slot_idx++ ) + // fixedToFloat_arrL32(DirAC_mem.frame_dec_f_fx, DirAC_mem.frame_dec_f, DirAC_mem.frame_dec_f_q, DirAC_mem.frame_dec_f_len); + + FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[hSpatParamRendCom->subframes_rendered]; slot_idx++ ) { /* CLDFB Analysis*/ - FOR ( ch = 0; ch < nchan_transport; ch++ ) + FOR( ch = 0; ch < nchan_transport; ch++ ) { - scale_sig32(hMasaExtRend->cldfbAnaRend[ch]->cldfb_state_fx, hMasaExtRend->cldfbAnaRend[ch]->cldfb_size, sub(Q11, hMasaExtRend->cldfbAnaRend[0]->Q_cldfb_state) ); + scale_sig32( hMasaExtRend->cldfbAnaRend[ch]->cldfb_state_fx, hMasaExtRend->cldfbAnaRend[ch]->cldfb_size, sub( Q11, hMasaExtRend->cldfbAnaRend[0]->Q_cldfb_state ) ); hMasaExtRend->cldfbAnaRend[ch]->Q_cldfb_state = Q11; } } - if(hDirACRend->h_output_synthesis_psd_state.proto_power_smooth){ - fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_len ); - fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_len ); + if ( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth ) + { + fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_len ); + fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_len ); } IF( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev != 0 ) { fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_len ); } - + for ( ch = 0; ch < hDirACRend->hOutSetup.nchan_out_woLFE + hDirACRend->hOutSetup.num_lfe; ch++ ) { - scale_sig32(hMasaExtRend->cldfbSynRend[ch]->cldfb_state_fx, hMasaExtRend->cldfbSynRend[ch]->cldfb_size, sub(Q11, hMasaExtRend->cldfbSynRend[0]->Q_cldfb_state) ); + scale_sig32( hMasaExtRend->cldfbSynRend[ch]->cldfb_state_fx, hMasaExtRend->cldfbSynRend[ch]->cldfb_size, sub( Q11, hMasaExtRend->cldfbSynRend[0]->Q_cldfb_state ) ); hMasaExtRend->cldfbSynRend[ch]->Q_cldfb_state = Q11; } - for(i = 0; i < MAX_OUTPUT_CHANNELS; i++) + for ( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) { - fixedToFloat_arrL(output_f[i], output_f_flt[i], hMasaExtRend->cldfbSynRend[0]->Q_cldfb_state, L_FRAME48k); + fixedToFloat_arrL( output_f[i], output_f_flt[i], hMasaExtRend->cldfbSynRend[0]->Q_cldfb_state, L_FRAME48k ); } } - } -#endif \ No newline at end of file +#endif diff --git a/lib_rend/lib_rend.h b/lib_rend/lib_rend.h index 08b14c4d6..f10e35e09 100644 --- a/lib_rend/lib_rend.h +++ b/lib_rend/lib_rend.h @@ -84,7 +84,7 @@ typedef struct Word16 *pq_fact; float *data; Word32 *data_fx; - Word16 Q_data; + Word16 Q_data; } IVAS_REND_AudioBuffer; #endif @@ -412,8 +412,6 @@ void IVAS_REND_Close( ); - - /* clang-format on */ #endif diff --git a/lib_util/audio_file_reader.c b/lib_util/audio_file_reader.c index 6911794ab..ff9a9b33b 100644 --- a/lib_util/audio_file_reader.c +++ b/lib_util/audio_file_reader.c @@ -75,7 +75,7 @@ static int8_t AudioFileReader_open_wav( /*! r: AudioFileReader handle */ ivas_error AudioFileReader_open( AudioFileReader **audioReader, /* o : AudioFileReader handle */ - const char *fileName /* i : path to wav/raw pcm file */ + const char *fileName /* i : path to wav/raw pcm file */ ) { AudioFileReader *self; diff --git a/lib_util/hrtf_file_reader.c b/lib_util/hrtf_file_reader.c index ac09d121b..e7f77bf2b 100644 --- a/lib_util/hrtf_file_reader.c +++ b/lib_util/hrtf_file_reader.c @@ -260,10 +260,10 @@ static void LoadBSplineBinaryITD( modelITD->elevKSeq_dyn = (float *) malloc( ( modelITD->elevDim3 - 2 ) * sizeof( float ) ); fread( modelITD->elevKSeq_dyn, sizeof( float ), modelITD->elevDim3 - 2, f_hrtf ); #ifdef IVAS_FLOAT_FIXED - modelITD->elevKSeq_dyn_fx = (Word32 *)malloc(sizeof(Word32)*(modelITD->elevDim3 - 2)); - for (int i = 0; i < modelITD->elevDim3 - 2; i++) + modelITD->elevKSeq_dyn_fx = (Word32 *) malloc( sizeof( Word32 ) * ( modelITD->elevDim3 - 2 ) ); + for ( int i = 0; i < modelITD->elevDim3 - 2; i++ ) { - modelITD->elevKSeq_dyn_fx[i] = float_to_fix(modelITD->elevKSeq_dyn[i], 22); + modelITD->elevKSeq_dyn_fx[i] = float_to_fix( modelITD->elevKSeq_dyn[i], 22 ); } #endif @@ -273,9 +273,9 @@ static void LoadBSplineBinaryITD( fread( modelITD->azimKSeq_dyn, sizeof( float ), ( modelITD->azimDim3 + 1 ) / 2 - 2, f_hrtf ); #ifdef IVAS_FLOAT_FIXED modelITD->azimKSeq_dyn_fx = (Word32 *) malloc( ( ( modelITD->azimDim3 + 1 ) / 2 - 2 ) * sizeof( Word32 ) ); /* basis functions are flipped around 180 deg, number of basis functions above/below is (N+1)/2 */ - for (int i = 0; i < ((modelITD->azimDim3 + 1) / 2 - 2); i++) + for ( int i = 0; i < ( ( modelITD->azimDim3 + 1 ) / 2 - 2 ); i++ ) { - modelITD->azimKSeq_dyn_fx[i] = float_to_fix(modelITD->azimKSeq_dyn[i], Q22); + modelITD->azimKSeq_dyn_fx[i] = float_to_fix( modelITD->azimKSeq_dyn[i], Q22 ); } #endif @@ -297,9 +297,9 @@ static void LoadBSplineBinaryITD( fread( modelITD->azimBsShape_dyn, sizeof( float ), tmp, f_hrtf ); #ifdef IVAS_FLOAT_FIXED modelITD->azimBsShape_dyn_fx = (Word32 *) malloc( tmp * sizeof( Word32 ) ); - for (int i = 0; i < tmp; i++) + for ( int i = 0; i < tmp; i++ ) { - modelITD->azimBsShape_dyn_fx[i] = float_to_fix(modelITD->azimBsShape_dyn[i], Q30); + modelITD->azimBsShape_dyn_fx[i] = float_to_fix( modelITD->azimBsShape_dyn[i], Q30 ); } #endif @@ -315,9 +315,9 @@ static void LoadBSplineBinaryITD( fread( modelITD->elevBsShape_dyn, sizeof( float ), tmp, f_hrtf ); #ifdef IVAS_FLOAT_FIXED modelITD->elevBsShape_dyn_fx = (Word32 *) malloc( tmp * sizeof( Word32 ) ); - for (int i = 0; i < tmp; i++) + for ( int i = 0; i < tmp; i++ ) { - modelITD->elevBsShape_dyn_fx[i] = float_to_fix(modelITD->elevBsShape_dyn[i], Q30); + modelITD->elevBsShape_dyn_fx[i] = float_to_fix( modelITD->elevBsShape_dyn[i], Q30 ); } #endif @@ -427,7 +427,7 @@ static ivas_error LoadBSplineBinary( fread( model->elevKSeq_dyn, sizeof( float ), model->elevDim3 - 2, f_hrtf ); #ifdef IVAS_FLOAT_FIXED model->elevKSeq_dyn_fx = (Word32 *) malloc( ( model->elevDim3 - 2 ) * sizeof( Word32 ) ); - for ( i = 0; i < (model->elevDim3 - 2); i++ ) + for ( i = 0; i < ( model->elevDim3 - 2 ); i++ ) { model->elevKSeq_dyn_fx[i] = float_to_fix( model->elevKSeq_dyn[i], Q22 ); } @@ -448,9 +448,9 @@ static ivas_error LoadBSplineBinary( fread( model->azimKSeq[i], sizeof( float ), ( model->azimDim3_dyn[i] + 1 ), f_hrtf ); #ifdef IVAS_FLOAT_FIXED model->azimKSeq_fx[i] = (Word32 *) malloc( ( model->azimDim3_dyn[i] + 1 ) * sizeof( Word32 ) ); - for (int j = 0; j < (model->azimDim3_dyn[i] + 1); j++) + for ( int j = 0; j < ( model->azimDim3_dyn[i] + 1 ); j++ ) { - model->azimKSeq_fx[i][j] = float_to_fix(model->azimKSeq[i][j], Q22); + model->azimKSeq_fx[i][j] = float_to_fix( model->azimKSeq[i][j], Q22 ); } #endif } @@ -486,9 +486,9 @@ static ivas_error LoadBSplineBinary( fread( model->azimBsShape_dyn[i], sizeof( float ), tmp, f_hrtf ); #ifdef IVAS_FLOAT_FIXED model->azimBsShape_dyn_fx[i] = (Word32 *) malloc( tmp * sizeof( Word32 ) ); - for (int j = 0; j < tmp; j++) + for ( int j = 0; j < tmp; j++ ) { - model->azimBsShape_dyn_fx[i][j] = float_to_fix(model->azimBsShape_dyn[i][j], Q30); + model->azimBsShape_dyn_fx[i][j] = float_to_fix( model->azimBsShape_dyn[i][j], Q30 ); } #endif fread( &model->azimSegSamples_dyn[i], sizeof( int16_t ), 1, f_hrtf ); @@ -506,10 +506,10 @@ static ivas_error LoadBSplineBinary( model->elevBsShape_dyn = (float *) malloc( tmp * sizeof( float ) ); fread( model->elevBsShape_dyn, sizeof( float ), tmp, f_hrtf ); #ifdef IVAS_FLOAT_FIXED - model->elevBsShape_dyn_fx = (Word32 *)malloc(tmp * sizeof(Word32)); + model->elevBsShape_dyn_fx = (Word32 *) malloc( tmp * sizeof( Word32 ) ); for ( i = 0; i < tmp; i++ ) { - model->elevBsShape_dyn_fx[i] = float_to_fix(model->elevBsShape_dyn[i], Q30); + model->elevBsShape_dyn_fx[i] = float_to_fix( model->elevBsShape_dyn[i], Q30 ); } #endif @@ -785,9 +785,9 @@ static void HRTF_energy_sections_precalc( pAlphaR += AlphaN; #ifdef IVAS_FLOAT_FIXED tmp_fx = *pAlphaL_fx; - *pEL_fx = L_add(*pEL_fx, L_shr(Mpy_32_32(tmp_fx, tmp_fx), 1)); /* one guard bit */ + *pEL_fx = L_add( *pEL_fx, L_shr( Mpy_32_32( tmp_fx, tmp_fx ), 1 ) ); /* one guard bit */ tmp_fx = *pAlphaR_fx; - *pER_fx = L_add(*pER_fx, L_shr(Mpy_32_32(tmp_fx, tmp_fx), 1)); /* one guard bit */ + *pER_fx = L_add( *pER_fx, L_shr( Mpy_32_32( tmp_fx, tmp_fx ), 1 ) ); /* one guard bit */ pAlphaL_fx += AlphaN; pAlphaR_fx += AlphaN; #endif @@ -803,8 +803,8 @@ static void HRTF_energy_sections_precalc( model->EL = (const float *) model->EL_dyn; model->ER = (const float *) model->ER_dyn; #ifdef IVAS_FLOAT_FIXED - model->EL_dyn_e = add(shl(model->AlphaL_e, 1), 1); // 2 * AlphaL_e + 1 (one guard bit) - model->ER_dyn_e = add(shl(model->AlphaR_e, 1), 1); // 2 * AlphaR_e + 1 (one guard bit) + model->EL_dyn_e = add( shl( model->AlphaL_e, 1 ), 1 ); // 2 * AlphaL_e + 1 (one guard bit) + model->ER_dyn_e = add( shl( model->AlphaR_e, 1 ), 1 ); // 2 * AlphaR_e + 1 (one guard bit) model->EL_fx = model->EL_dyn_fx; model->EL_e = model->EL_dyn_e; @@ -895,7 +895,7 @@ ivas_error dealloc_HRTF_binary( free( hHrtf->ModelParams.azimKSeq ); #ifdef IVAS_FLOAT_FIXED free( (void *) hHrtf->ModelParams.azimBsShape_fx ); /* void* cast needed to please both gcc and Visual studio compilers. Deallocating const float** should be fine and gcc agrees, but Visual studio complains. */ - FOR ( i = 0; i < hHrtf->ModelParams.elevDim3; i++ ) + FOR( i = 0; i < hHrtf->ModelParams.elevDim3; i++ ) { free( hHrtf->ModelParams.azimKSeq_fx[i] ); } @@ -1049,7 +1049,7 @@ static ivas_error create_HRTF_from_rawdata( for ( i = 0; i < ( *hHRTF )->max_num_ir; i++ ) { //( *hHRTF )->inv_diffuse_weight[i] = *( (float *) ( hrtf_data_rptr ) ); - ( *hHRTF )->inv_diffuse_weight_fx[i] = ( Word16 ) (* ( (float *) ( hrtf_data_rptr ) ) * ONE_IN_Q15); + ( *hHRTF )->inv_diffuse_weight_fx[i] = (Word16) ( *( (float *) ( hrtf_data_rptr ) ) * ONE_IN_Q15 ); hrtf_data_rptr += sizeof( float ); } @@ -1074,8 +1074,8 @@ static ivas_error create_HRTF_from_rawdata( for ( k = 0; k < ( *hHRTF )->num_iterations[i][j]; k++ ) { mem_size = ( *hHRTF )->pIndex_frequency_max[i][j][k] * sizeof( float ); - //memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); - for ( Word16 l = 0; l < (*hHRTF)->pIndex_frequency_max[i][j][k]; l++ ) + // memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); + for ( Word16 l = 0; l < ( *hHRTF )->pIndex_frequency_max[i][j][k]; l++ ) { float *tmp, temp_buf[1]; tmp = temp_buf; @@ -1083,12 +1083,12 @@ static ivas_error create_HRTF_from_rawdata( pOut_to_bin_wptr_fx[l] = (Word32) ( *tmp * ONE_IN_Q29 ); hrtf_data_rptr += sizeof( float ); } - //hrtf_data_rptr += mem_size; + // hrtf_data_rptr += mem_size; pOut_to_bin_wptr_fx += ( *hHRTF )->pIndex_frequency_max[i][j][k]; } } } - mem_size = max_total_num_fsamp_per_iteration * sizeof( float ); + mem_size = max_total_num_fsamp_per_iteration * sizeof( float ); /* coeff_im (the size depends on pIndex_frequency_max) */ for ( i = 0; i < ( *hHRTF )->max_num_ir; i++ ) @@ -1106,8 +1106,8 @@ static ivas_error create_HRTF_from_rawdata( for ( k = 0; k < ( *hHRTF )->num_iterations[i][j]; k++ ) { mem_size = ( *hHRTF )->pIndex_frequency_max[i][j][k] * sizeof( float ); - //memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); - for (Word16 l = 0; l < (*hHRTF)->pIndex_frequency_max[i][j][k]; l++) + // memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); + for ( Word16 l = 0; l < ( *hHRTF )->pIndex_frequency_max[i][j][k]; l++ ) { float *tmp, temp_buf[1]; tmp = temp_buf; @@ -1115,7 +1115,7 @@ static ivas_error create_HRTF_from_rawdata( pOut_to_bin_wptr_fx[l] = (Word32) ( *tmp * ONE_IN_Q29 ); hrtf_data_rptr += sizeof( float ); } - //hrtf_data_rptr += mem_size; + // hrtf_data_rptr += mem_size; pOut_to_bin_wptr_fx += ( *hHRTF )->pIndex_frequency_max[i][j][k]; } } @@ -1143,8 +1143,8 @@ static ivas_error create_HRTF_from_rawdata( for ( k = 0; k < ( *hHRTF )->num_iterations_diffuse[j]; k++ ) { mem_size = ( *hHRTF )->pIndex_frequency_max_diffuse[j][k] * sizeof( float ); - //memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); - for (Word16 l = 0; l < (*hHRTF)->pIndex_frequency_max_diffuse[j][k]; l++) + // memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); + for ( Word16 l = 0; l < ( *hHRTF )->pIndex_frequency_max_diffuse[j][k]; l++ ) { float *tmp, temp_buf[1]; tmp = temp_buf; @@ -1152,7 +1152,7 @@ static ivas_error create_HRTF_from_rawdata( pOut_to_bin_wptr_fx[l] = (Word32) ( *tmp * ONE_IN_Q29 ); hrtf_data_rptr += sizeof( float ); } - //hrtf_data_rptr += mem_size; + // hrtf_data_rptr += mem_size; pOut_to_bin_wptr_fx += ( *hHRTF )->pIndex_frequency_max_diffuse[j][k]; } } @@ -1173,8 +1173,8 @@ static ivas_error create_HRTF_from_rawdata( for ( k = 0; k < ( *hHRTF )->num_iterations_diffuse[j]; k++ ) { mem_size = ( *hHRTF )->pIndex_frequency_max_diffuse[j][k] * sizeof( float ); - //memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); - for ( Word16 l = 0; l < (*hHRTF)->pIndex_frequency_max_diffuse[j][k]; l++ ) + // memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); + for ( Word16 l = 0; l < ( *hHRTF )->pIndex_frequency_max_diffuse[j][k]; l++ ) { float *tmp, temp_buf[1]; tmp = temp_buf; @@ -1182,7 +1182,7 @@ static ivas_error create_HRTF_from_rawdata( pOut_to_bin_wptr_fx[l] = (Word32) ( *tmp * ONE_IN_Q29 ); hrtf_data_rptr += sizeof( float ); } - //hrtf_data_rptr += mem_size; + // hrtf_data_rptr += mem_size; pOut_to_bin_wptr_fx += ( *hHRTF )->pIndex_frequency_max_diffuse[j][k]; } } diff --git a/lib_util/ism_file_reader.c b/lib_util/ism_file_reader.c index 6fd11ed06..9127fe847 100644 --- a/lib_util/ism_file_reader.c +++ b/lib_util/ism_file_reader.c @@ -161,11 +161,11 @@ ivas_error IsmFileReader_readNextFrame( #ifdef IVAS_FLOAT_FIXED ismMetadata->azimuth_fx = floatToFixed( meta_prm[0], Q22 ); ismMetadata->elevation_fx = floatToFixed( meta_prm[1], Q22 ); - ismMetadata->radius_fx = (Word16)floatToFixed(meta_prm[2], Q9); - ismMetadata->spread_fx = floatToFixed(meta_prm[3], Q22); - ismMetadata->gainFactor_fx = floatToFixed(meta_prm[4], Q31); - ismMetadata->yaw_fx = floatToFixed(meta_prm[5], Q22); - ismMetadata->pitch_fx = floatToFixed(meta_prm[6], Q22); + ismMetadata->radius_fx = (Word16) floatToFixed( meta_prm[2], Q9 ); + ismMetadata->spread_fx = floatToFixed( meta_prm[3], Q22 ); + ismMetadata->gainFactor_fx = floatToFixed( meta_prm[4], Q31 ); + ismMetadata->yaw_fx = floatToFixed( meta_prm[5], Q22 ); + ismMetadata->pitch_fx = floatToFixed( meta_prm[6], Q22 ); #endif /* verify whether the read metadata values are in an expected range */ diff --git a/lib_util/masa_file_reader.c b/lib_util/masa_file_reader.c index a2dc9888c..1a6943825 100644 --- a/lib_util/masa_file_reader.c +++ b/lib_util/masa_file_reader.c @@ -200,7 +200,7 @@ ivas_error MasaFileReader_readNextFrame( { hMeta->directional_meta[i].energy_ratio[j][b] = ( (float) readOther[b] ) / UINT8_MAX; #ifdef IVAS_FLOAT_FIXED - hMeta->directional_meta[i].energy_ratio_fx[j][b] = (Word32) ( readOther[b] * ONE_IN_Q22 );//Q30 + hMeta->directional_meta[i].energy_ratio_fx[j][b] = (Word32) ( readOther[b] * ONE_IN_Q22 ); // Q30 #endif } @@ -215,7 +215,7 @@ ivas_error MasaFileReader_readNextFrame( { hMeta->directional_meta[i].spread_coherence[j][b] = ( (float) readOther[b] ) / UINT8_MAX; #ifdef IVAS_FLOAT_FIXED - hMeta->directional_meta[i].spread_coherence_fx[j][b] = (Word16) ( readOther[b] * ONE_IN_Q7 );//Q15 + hMeta->directional_meta[i].spread_coherence_fx[j][b] = (Word16) ( readOther[b] * ONE_IN_Q7 ); // Q15 #endif } diff --git a/lib_util/render_config_reader.c b/lib_util/render_config_reader.c index bb708094f..15cdfb1d7 100644 --- a/lib_util/render_config_reader.c +++ b/lib_util/render_config_reader.c @@ -57,7 +57,7 @@ #define ACOUSTIC_DSR_MIN ( 0.0f ) #define ACOUSTIC_DSR_MAX ( 1.0e+2f ) #define ACOUSTIC_DSR_EPSILON ( 1.0e-15f ) -#define ACOUSTIC_DSR_EPSILON_FX ( 1 ) +#define ACOUSTIC_DSR_EPSILON_FX ( 1 ) #define ACOUSTICPREDELAY_JOTREV_MIN ( SHORTEST_REV_DEL_LINE ) #define ACOUSTICPREDELAY_JOTREV_MAX ( SHORTEST_REV_DEL_LINE + 1.0f / (float) FRAMES_PER_SEC ) #define ACOUSTICPREDELAY_FDREV_MIN ( 1.0f / (float) ( 16 * FRAMES_PER_SEC ) ) @@ -65,13 +65,13 @@ #define INPUTPREDELAY_MIN ( 0.0f ) #define INPUTPREDELAY_MAX ( 1.0e+2f ) -#define ER_MIN_ROOM_DIMENSION ( 1.0f ) +#define ER_MIN_ROOM_DIMENSION ( 1.0f ) #define ER_MIN_ROOM_DIMENSION_FX ( 4194304 ) -#define ER_MAX_ROOM_DIMENSION ( 999.0f ) +#define ER_MAX_ROOM_DIMENSION ( 999.0f ) #define ER_MAX_ROOM_DIMENSION_FX ( 2095054848 ) -#define ER_MIN_ABS_COEFF ( 0.0f ) +#define ER_MIN_ABS_COEFF ( 0.0f ) #define ER_MIN_ABS_COEFF_FX ( 0 ) -#define ER_MAX_ABS_COEFF ( 1.0f ) +#define ER_MAX_ABS_COEFF ( 1.0f ) #define ER_MAX_ABS_COEFF_FX ( 1073741824 ) /*------------------------------------------------------------------------------------------* @@ -1186,7 +1186,6 @@ ivas_error RenderConfigReader_checkValues( } - if ( pRoom_acoustics->use_er == 1 ) { /* Room dimensions */ @@ -1300,7 +1299,6 @@ ivas_error RenderConfigReader_checkValues( } - if ( pRoom_acoustics->use_er == 1 ) { /* Room dimensions */ @@ -2580,8 +2578,7 @@ ivas_error RenderConfigReader_read( } free( pCombinedName ); } - else - if ( strcmp( item, "DIRECTIVITY" ) == 0 ) + else if ( strcmp( item, "DIRECTIVITY" ) == 0 ) { if ( read_txt_vector( pValue, 3, hRenderConfig->directivity ) ) { @@ -2726,9 +2723,9 @@ ivas_error RenderConfigReader_getAcousticEnvironment( pAcEnv->use_er = pRenderConfigReader->pAE[n].pEarlyReflections->use_er; /* ER activation flag */ pAcEnv->lowComplexity = pRenderConfigReader->pAE[n].pEarlyReflections->lowComplexity; /* Low complexity flag */ pAcEnv->dimensions = pRenderConfigReader->pAE[n].pEarlyReflections->dimensions; - pAcEnv->dimensions.x_fx = (Word32)(pRenderConfigReader->pAE[n].pEarlyReflections->dimensions.x * ONE_IN_Q22); - pAcEnv->dimensions.y_fx = (Word32)(pRenderConfigReader->pAE[n].pEarlyReflections->dimensions.y * ONE_IN_Q22); - pAcEnv->dimensions.z_fx = (Word32)(pRenderConfigReader->pAE[n].pEarlyReflections->dimensions.z * ONE_IN_Q22); + pAcEnv->dimensions.x_fx = (Word32) ( pRenderConfigReader->pAE[n].pEarlyReflections->dimensions.x * ONE_IN_Q22 ); + pAcEnv->dimensions.y_fx = (Word32) ( pRenderConfigReader->pAE[n].pEarlyReflections->dimensions.y * ONE_IN_Q22 ); + pAcEnv->dimensions.z_fx = (Word32) ( pRenderConfigReader->pAE[n].pEarlyReflections->dimensions.z * ONE_IN_Q22 ); /* Use default listener origin position if non provided */ if ( pRenderConfigReader->pAE[n].pEarlyReflections->pListenerOrigin == NULL ) { diff --git a/lib_util/rotation_file_reader.c b/lib_util/rotation_file_reader.c index cd548002a..f5a815377 100644 --- a/lib_util/rotation_file_reader.c +++ b/lib_util/rotation_file_reader.c @@ -128,10 +128,10 @@ ivas_error HeadRotationFileReading( pQuaternion->y = y; pQuaternion->z = z; #ifdef IVAS_FLOAT_FIXED - pQuaternion->w_fx = floatToFixed_32(w, Q31); - pQuaternion->x_fx = floatToFixed_32(x, Q31); - pQuaternion->y_fx = floatToFixed_32(y, Q31); - pQuaternion->z_fx = floatToFixed_32(z, Q31); + pQuaternion->w_fx = floatToFixed_32( w, Q31 ); + pQuaternion->x_fx = floatToFixed_32( x, Q31 ); + pQuaternion->y_fx = floatToFixed_32( y, Q31 ); + pQuaternion->z_fx = floatToFixed_32( z, Q31 ); pQuaternion->q_fact = Q31; #endif if ( pPos != NULL ) @@ -140,9 +140,9 @@ ivas_error HeadRotationFileReading( pPos->y = posy; pPos->z = posz; #ifdef IVAS_FLOAT_FIXED - pPos->x_fx = floatToFixed_32(posx, Q25); - pPos->y_fx = floatToFixed_32(posy, Q25); - pPos->z_fx = floatToFixed_32(posz, Q25); + pPos->x_fx = floatToFixed_32( posx, Q25 ); + pPos->y_fx = floatToFixed_32( posy, Q25 ); + pPos->z_fx = floatToFixed_32( posz, Q25 ); pPos->q_fact = Q25; #endif } diff --git a/lib_util/test_fft.h b/lib_util/test_fft.h index 2aad5a3ae..7a3567f89 100644 --- a/lib_util/test_fft.h +++ b/lib_util/test_fft.h @@ -35,7 +35,7 @@ #include "options.h" -void run_fft_unit_test(void); +void run_fft_unit_test( void ); #endif /* __TEST_FFT_H */ diff --git a/lib_util/test_mdct.c b/lib_util/test_mdct.c index 31308fb08..ec4e170bd 100644 --- a/lib_util/test_mdct.c +++ b/lib_util/test_mdct.c @@ -41,13 +41,13 @@ typedef int Word32; typedef short Word16; typedef short int16_t; -#define TYPE_MDCT (0) -#define TYPE_IMDCT (1) -#define TYPE_EDCT2 (2) -#define TYPE_NEG_EDCT2 (3) +#define TYPE_MDCT ( 0 ) +#define TYPE_IMDCT ( 1 ) +#define TYPE_EDCT2 ( 2 ) +#define TYPE_NEG_EDCT2 ( 3 ) -#define ALLOWED_DEVIATION (0.05) -#define Q31 (2147483647.0f) +#define ALLOWED_DEVIATION ( 0.05 ) +#define Q31 ( 2147483647.0f ) extern const int16_t ip_edct2_64[6]; extern const float w_edct2_64[80]; @@ -68,7 +68,7 @@ void edct2_fx( Word32 *a, Word16 *q, const Word16 *ip, - const Word16 *w); + const Word16 *w ); void ivas_mdct( const float *pIn, @@ -79,7 +79,7 @@ void ivas_mdct_fx( const Word32 *pIn, Word32 *pOut, const Word16 length, - Word16 *q_out); + Word16 *q_out ); void ivas_imdct( const float *pIn, @@ -90,135 +90,144 @@ void ivas_imdct_fx( const Word32 *pIn, Word32 *pOut, const Word16 length, - Word16 *q_out); + Word16 *q_out ); -void run_mdct_unit_test(void); +void run_mdct_unit_test( void ); -void populate_input_interleave(Word32 *in32, float *fIn, Word16 N); -void populate_input_interleave_16(Word16 *in16, float *fIn, Word16 N); +void populate_input_interleave( Word32 *in32, float *fIn, Word16 N ); +void populate_input_interleave_16( Word16 *in16, float *fIn, Word16 N ); -static float test_ivas_mdct_imdct(Word16 N, Word32 test_type) +static float test_ivas_mdct_imdct( Word16 N, Word32 test_type ) { - Word32 *in = calloc(2 * N, sizeof(in[0])); - Word16 *in16 = calloc(2 * N, sizeof(in16[0])); - float *fIn = calloc(2 * N, sizeof(fIn[0])); - Word32 *out = calloc(2 * N, sizeof(out[0])); - float *fOut = calloc(2 * N, sizeof(fOut[0])); - float max_deviation = 0.0f; - Word32 max_val_out = 0; - Word16 q_out = 0; - float div_fac = 1.0f; - - if ((in == NULL) || (fIn == NULL) || (out == NULL) || (fOut == NULL)) - { - printf("!!!!Malloc failed!!!!"); - exit(1); - } - - switch(test_type) - { - case (TYPE_MDCT): - { - populate_input_interleave(in, fIn, N); - ivas_mdct(fIn, fOut, N); - ivas_mdct_fx(in, out, N, &q_out); - break; - } - case (TYPE_IMDCT): - { - populate_input_interleave(in, fIn, N); - ivas_imdct(fIn, fOut, N); - ivas_imdct_fx(in, out, N, &q_out); - break; - } - case (TYPE_EDCT2): - { - populate_input_interleave_16(in16, fIn, N); - edct2(64, 1, fIn, fOut, ip_edct2_64, w_edct2_64); - edct2_fx(64, 1, in16, out, &q_out, ip_edct2_64, w_edct2_64_fx); - break; - } - case (TYPE_NEG_EDCT2): - { - populate_input_interleave_16(in16, fIn, N); - edct2(64, -1, fIn, fOut, ip_edct2_64, w_edct2_64); - edct2_fx(64, -1, in16, out, &q_out, ip_edct2_64, w_edct2_64_fx); - break; - } - } - if (q_out >= 0) - { - div_fac = (float)1.0f / (float)(1 << q_out); - } - else - { - div_fac = (float)(1 << (-q_out)); - } - - for(int i = 0; i < (N >> 1); i++) - { - float OutRe = fOut[2 * i + 0]; - float OutIm = fOut[2 * i + 1]; - float dev_val_real = (float)(fabs((OutRe / div_fac) - (float)(out[2 * i + 0]))); - float dev_val_imag = (float)(fabs((OutIm / div_fac) - (float)(out[2 * i + 1]))); - if (max_val_out < abs(out[2 * i + 0])) - max_val_out = abs(out[2 * i + 0]); - if (max_val_out < abs(out[2 * i + 1])) - max_val_out = abs(out[2 * i + 1]); - if (dev_val_real > max_deviation) - max_deviation = dev_val_real; - if (dev_val_imag > max_deviation) - max_deviation = dev_val_imag; - } - free( in ); - free( fIn ); - free( out ); - free( fOut ); - return (( max_deviation / max_val_out) * 100); -} + Word32 *in = calloc( 2 * N, sizeof( in[0] ) ); + Word16 *in16 = calloc( 2 * N, sizeof( in16[0] ) ); + float *fIn = calloc( 2 * N, sizeof( fIn[0] ) ); + Word32 *out = calloc( 2 * N, sizeof( out[0] ) ); + float *fOut = calloc( 2 * N, sizeof( fOut[0] ) ); + float max_deviation = 0.0f; + Word32 max_val_out = 0; + Word16 q_out = 0; + float div_fac = 1.0f; + + if ( ( in == NULL ) || ( fIn == NULL ) || ( out == NULL ) || ( fOut == NULL ) ) + { + printf( "!!!!Malloc failed!!!!" ); + exit( 1 ); + } -static void test_main(Word16 *imdct_lengths, Word16 num_lengths, Word16 test_type) -{ - char *test_name[]= {"IVAS MDCT", "IVAS IMDCT", "IVAS EDCT2", "IVAS NEG_EDCT2"}; - Word32 num_tests = 0, num_passed = 0, num_failed = 0; - printf("\033[0;33m"); - printf("============== Starting %s tests ================\n", test_name[test_type]); - for ( int i = num_lengths - 1; i >=0 ; i-- ) - { - float max_deviation = test_ivas_mdct_imdct( imdct_lengths[i], test_type); - num_tests++; - if (max_deviation < ALLOWED_DEVIATION) + switch ( test_type ) { - printf("\033[0;32m"); - printf("[PASSED] %s test of length %d\n", test_name[test_type], imdct_lengths[i]); - num_passed++; + case ( TYPE_MDCT ): + { + populate_input_interleave( in, fIn, N ); + ivas_mdct( fIn, fOut, N ); + ivas_mdct_fx( in, out, N, &q_out ); + break; + } + case ( TYPE_IMDCT ): + { + populate_input_interleave( in, fIn, N ); + ivas_imdct( fIn, fOut, N ); + ivas_imdct_fx( in, out, N, &q_out ); + break; + } + case ( TYPE_EDCT2 ): + { + populate_input_interleave_16( in16, fIn, N ); + edct2( 64, 1, fIn, fOut, ip_edct2_64, w_edct2_64 ); + edct2_fx( 64, 1, in16, out, &q_out, ip_edct2_64, w_edct2_64_fx ); + break; + } + case ( TYPE_NEG_EDCT2 ): + { + populate_input_interleave_16( in16, fIn, N ); + edct2( 64, -1, fIn, fOut, ip_edct2_64, w_edct2_64 ); + edct2_fx( 64, -1, in16, out, &q_out, ip_edct2_64, w_edct2_64_fx ); + break; + } + } + if ( q_out >= 0 ) + { + div_fac = (float) 1.0f / (float) ( 1 << q_out ); } else { - printf("\033[0;31m"); - printf("[FAILED] %s test of length %d Max_deviation = %.6f\n", test_name[test_type], imdct_lengths[i], max_deviation); - num_failed++; + div_fac = (float) ( 1 << ( -q_out ) ); + } + + for ( int i = 0; i < ( N >> 1 ); i++ ) + { + float OutRe = fOut[2 * i + 0]; + float OutIm = fOut[2 * i + 1]; + float dev_val_real = (float) ( fabs( ( OutRe / div_fac ) - (float) ( out[2 * i + 0] ) ) ); + float dev_val_imag = (float) ( fabs( ( OutIm / div_fac ) - (float) ( out[2 * i + 1] ) ) ); + if ( max_val_out < abs( out[2 * i + 0] ) ) + max_val_out = abs( out[2 * i + 0] ); + if ( max_val_out < abs( out[2 * i + 1] ) ) + max_val_out = abs( out[2 * i + 1] ); + if ( dev_val_real > max_deviation ) + max_deviation = dev_val_real; + if ( dev_val_imag > max_deviation ) + max_deviation = dev_val_imag; + } + free( in ); + free( fIn ); + free( out ); + free( fOut ); + return ( ( max_deviation / max_val_out ) * 100 ); +} + +static void test_main( Word16 *imdct_lengths, Word16 num_lengths, Word16 test_type ) +{ + char *test_name[] = { "IVAS MDCT", "IVAS IMDCT", "IVAS EDCT2", "IVAS NEG_EDCT2" }; + Word32 num_tests = 0, num_passed = 0, num_failed = 0; + printf( "\033[0;33m" ); + printf( "============== Starting %s tests ================\n", test_name[test_type] ); + for ( int i = num_lengths - 1; i >= 0; i-- ) + { + float max_deviation = test_ivas_mdct_imdct( imdct_lengths[i], test_type ); + num_tests++; + if ( max_deviation < ALLOWED_DEVIATION ) + { + printf( "\033[0;32m" ); + printf( "[PASSED] %s test of length %d\n", test_name[test_type], imdct_lengths[i] ); + num_passed++; + } + else + { + printf( "\033[0;31m" ); + printf( "[FAILED] %s test of length %d Max_deviation = %.6f\n", test_name[test_type], imdct_lengths[i], max_deviation ); + num_failed++; + } } - } - printf("\033[0;33m"); - printf("============== Completed %s tests ================\n\n", test_name[test_type]); - printf("Summary of %s unit tests:\n", test_name[test_type]); - printf("--------------------------\n"); - printf("Total tests: %d\n", num_tests); - printf("Passed: %d\n", num_passed); - printf("\033[0;31m"); - printf("Failed: %d\n\n", num_failed); - printf("\033[0m"); + printf( "\033[0;33m" ); + printf( "============== Completed %s tests ================\n\n", test_name[test_type] ); + printf( "Summary of %s unit tests:\n", test_name[test_type] ); + printf( "--------------------------\n" ); + printf( "Total tests: %d\n", num_tests ); + printf( "Passed: %d\n", num_passed ); + printf( "\033[0;31m" ); + printf( "Failed: %d\n\n", num_failed ); + printf( "\033[0m" ); } -void run_mdct_unit_test(void) -{ - Word16 ivas_mdct_lengths[] = {480, 320, 160,}; - Word16 ivas_imdct_lengths[] = {480, 320, 160, 80,}; - Word16 edct2_lengths[] = {64}; - test_main(&ivas_mdct_lengths[0], sizeof(ivas_mdct_lengths) / sizeof(ivas_mdct_lengths[0]), TYPE_MDCT); - test_main(&ivas_imdct_lengths[0], sizeof(ivas_imdct_lengths) / sizeof(ivas_imdct_lengths[0]), TYPE_IMDCT); - test_main(&edct2_lengths[0], 1, TYPE_EDCT2); - test_main(&edct2_lengths[0], 1, TYPE_NEG_EDCT2); - return; -} \ No newline at end of file +void run_mdct_unit_test( void ) +{ + Word16 ivas_mdct_lengths[] = { + 480, + 320, + 160, + }; + Word16 ivas_imdct_lengths[] = { + 480, + 320, + 160, + 80, + }; + Word16 edct2_lengths[] = { 64 }; + test_main( &ivas_mdct_lengths[0], sizeof( ivas_mdct_lengths ) / sizeof( ivas_mdct_lengths[0] ), TYPE_MDCT ); + test_main( &ivas_imdct_lengths[0], sizeof( ivas_imdct_lengths ) / sizeof( ivas_imdct_lengths[0] ), TYPE_IMDCT ); + test_main( &edct2_lengths[0], 1, TYPE_EDCT2 ); + test_main( &edct2_lengths[0], 1, TYPE_NEG_EDCT2 ); + return; +} -- GitLab